**Motivations:** - Clone or load repos under /home/ncantu/code with AnythingLLM workspace ensure/create from the editor **Root causes:** - N/A (new capability) **Correctifs:** - N/A **Evolutions:** - services/repos-devtools-server: POST /repos-clone, GET /repos-list, POST /repos-load (Bearer REPOS_DEVTOOLS_TOKEN) - Extension: Webview panel, slash commands, workspaceEnsure + POST /api/v1/workspace/new - Docs: feature note and index links **Pages affectées:** - services/repos-devtools-server/* - extensions/anythingllm-workspaces/* - docs/README.md - docs/features/repos-devtools-server-and-dev-panel.md - docs/features/anythingllm-vscode-extension.md
28 lines
855 B
TypeScript
28 lines
855 B
TypeScript
import { createWorkspace, listWorkspaces } from "./anythingllmClient";
|
|
import type { AnythingWorkspace } from "./types";
|
|
|
|
export interface EnsuredWorkspace {
|
|
readonly workspace: AnythingWorkspace;
|
|
readonly created: boolean;
|
|
}
|
|
|
|
export const ensureWorkspaceForRepoName = async (
|
|
baseUrl: string,
|
|
apiKey: string,
|
|
repoName: string,
|
|
): Promise<EnsuredWorkspace> => {
|
|
const key = repoName.trim();
|
|
if (key.length === 0) {
|
|
throw new Error("repo/workspace name is empty");
|
|
}
|
|
const all = await listWorkspaces(baseUrl, apiKey);
|
|
const byName = all.find((w) => w.name === key);
|
|
const bySlug = all.find((w) => w.slug === key);
|
|
const found = byName ?? bySlug;
|
|
if (found) {
|
|
return { workspace: found, created: false };
|
|
}
|
|
const created = await createWorkspace(baseUrl, apiKey, key);
|
|
return { workspace: created, created: true };
|
|
};
|