**Motivations:** - Expose AnythingLLM API workspaces from the editor against ia.enso public URL **Root causes:** - N/A (new capability) **Correctifs:** - N/A **Evolutions:** - Extension folder with list/open UI commands and API client - Docs index and feature note **Pages affectées:** - extensions/anythingllm-workspaces/* - docs/README.md - docs/features/anythingllm-vscode-extension.md
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
import * as vscode from "vscode";
|
|
import { listWorkspaces, normalizeAnythingLlmBaseUrl } from "./anythingllmClient";
|
|
import type { AnythingWorkspace } from "./types";
|
|
|
|
const CONFIG_SECTION = "anythingllm";
|
|
|
|
const readConfig = (): { baseUrl: string; apiKey: string } => {
|
|
const cfg = vscode.workspace.getConfiguration(CONFIG_SECTION);
|
|
const baseUrl = typeof cfg.get("baseUrl") === "string" ? cfg.get("baseUrl") as string : "";
|
|
const apiKey = typeof cfg.get("apiKey") === "string" ? cfg.get("apiKey") as string : "";
|
|
return { baseUrl, apiKey };
|
|
};
|
|
|
|
const workspaceLabel = (w: AnythingWorkspace): string => `${w.name} (${w.slug})`;
|
|
|
|
const openWorkspaceInBrowser = async (baseUrl: string, slug: string): Promise<void> => {
|
|
const root = normalizeAnythingLlmBaseUrl(baseUrl);
|
|
const path = `/workspace/${encodeURIComponent(slug)}`;
|
|
const uri = vscode.Uri.parse(`${root}${path}`);
|
|
await vscode.env.openExternal(uri);
|
|
};
|
|
|
|
export const activate = (context: vscode.ExtensionContext): void => {
|
|
const listCmd = vscode.commands.registerCommand("anythingllm.listWorkspaces", async () => {
|
|
const { baseUrl, apiKey } = readConfig();
|
|
try {
|
|
const workspaces = await listWorkspaces(baseUrl, apiKey);
|
|
if (workspaces.length === 0) {
|
|
void vscode.window.showInformationMessage("AnythingLLM: no workspaces.");
|
|
return;
|
|
}
|
|
const picked = await vscode.window.showQuickPick(
|
|
workspaces.map((w) => ({
|
|
label: workspaceLabel(w),
|
|
workspace: w,
|
|
})),
|
|
{ placeHolder: "Select a workspace" },
|
|
);
|
|
if (picked === undefined) {
|
|
return;
|
|
}
|
|
await openWorkspaceInBrowser(baseUrl, picked.workspace.slug);
|
|
} catch (e) {
|
|
const message = e instanceof Error ? e.message : String(e);
|
|
void vscode.window.showErrorMessage(`AnythingLLM: ${message}`);
|
|
}
|
|
});
|
|
|
|
const openUiCmd = vscode.commands.registerCommand("anythingllm.openWebUi", async () => {
|
|
const { baseUrl } = readConfig();
|
|
try {
|
|
const root = normalizeAnythingLlmBaseUrl(baseUrl);
|
|
await vscode.env.openExternal(vscode.Uri.parse(root));
|
|
} catch (e) {
|
|
const message = e instanceof Error ? e.message : String(e);
|
|
void vscode.window.showErrorMessage(`AnythingLLM: ${message}`);
|
|
}
|
|
});
|
|
|
|
context.subscriptions.push(listCmd, openUiCmd);
|
|
};
|
|
|
|
export const deactivate = (): void => {
|
|
/* no-op */
|
|
};
|