-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* show connection tree * ui to analyze connections * fix token counting in vscode llms * tweak pr descr
- Loading branch information
Showing
7 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as vscode from "vscode" | ||
import { ExtensionState } from "./state" | ||
import { MODEL_PROVIDERS } from "../../core/src/constants" | ||
import { YAMLStringify } from "../../core/src/yaml" | ||
import { APIType } from "../../core/src/host" | ||
|
||
class ConnectionInfoTreeData { | ||
provider: string | ||
apiType?: APIType | ||
} | ||
|
||
class ConnectionInfoTreeDataProvider | ||
implements vscode.TreeDataProvider<ConnectionInfoTreeData> | ||
{ | ||
constructor(readonly state: ExtensionState) { | ||
const { context } = state | ||
const { subscriptions } = context | ||
subscriptions.push( | ||
vscode.workspace.onDidChangeConfiguration(() => { | ||
this.refresh() | ||
}) | ||
) | ||
const watcher = vscode.workspace.createFileSystemWatcher("./.env") | ||
watcher.onDidChange(() => this.refresh()) | ||
watcher.onDidDelete(() => this.refresh()) | ||
subscriptions.push(watcher) | ||
} | ||
|
||
async getTreeItem( | ||
element: ConnectionInfoTreeData | ||
): Promise<vscode.TreeItem> { | ||
const item = new vscode.TreeItem(element.provider) | ||
const res = | ||
await this.state.host.server.client.getLanguageModelConfiguration( | ||
element.provider + ":*", | ||
{ token: false } | ||
) | ||
if (res) { | ||
item.description = res.base || "?" | ||
item.tooltip = YAMLStringify(res) | ||
item.command = <vscode.Command>{ | ||
command: "vscode.open", | ||
arguments: [this.state.host.toUri("./.env")], | ||
} | ||
} else { | ||
item.description = "not configured" | ||
item.command = <vscode.Command>{ | ||
command: "genaiscript.connection.configure", | ||
arguments: [element.provider, element.apiType], | ||
} | ||
} | ||
|
||
return item | ||
} | ||
getChildren( | ||
element?: ConnectionInfoTreeData | ||
): vscode.ProviderResult<ConnectionInfoTreeData[]> { | ||
if (!element) return MODEL_PROVIDERS.map(({ id }) => ({ provider: id })) | ||
return undefined | ||
} | ||
|
||
private _onDidChangeTreeData: vscode.EventEmitter< | ||
void | ConnectionInfoTreeData | ConnectionInfoTreeData[] | ||
> = new vscode.EventEmitter< | ||
void | ConnectionInfoTreeData | ConnectionInfoTreeData[] | ||
>() | ||
readonly onDidChangeTreeData: vscode.Event< | ||
void | ConnectionInfoTreeData | ConnectionInfoTreeData[] | ||
> = this._onDidChangeTreeData.event | ||
|
||
refresh( | ||
treeItem?: ConnectionInfoTreeData | ConnectionInfoTreeData[] | ||
): void { | ||
this._onDidChangeTreeData.fire(treeItem) | ||
} | ||
} | ||
|
||
export function activateConnectionInfoTree(state: ExtensionState) { | ||
const { context } = state | ||
const { subscriptions } = context | ||
const treeDataProvider = new ConnectionInfoTreeDataProvider(state) | ||
const treeView = vscode.window.createTreeView("genaiscript.connections", { | ||
treeDataProvider, | ||
}) | ||
subscriptions.push(treeView) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters