feat: rebuild workspaces as the reference plugin

This commit is contained in:
LukeGus committed 2026-09-23 07:04:03 -05:00
1 parent d774df8b41
commit f217d8db89
79 files changed
+32995 -2184

No files matched your search

+3
View File
@@ -1,11 +1,14 @@
import type { PluginContext } from "@termix/plugin-sdk/backend";
import { setPluginSsh } from "./ssh.js";
import { setPluginServices } from "./services.js";
import { startAiService, stopAiService } from "./routes.js";
import { createCurrentAiRepository } from "../../../../src/backend/database/repositories/factory.js";
export async function activate(ctx: PluginContext) {
setPluginSsh(ctx.ssh);
ctx.disposables.add(() => setPluginSsh(null));
setPluginServices(ctx.services);
ctx.disposables.add(() => setPluginServices(null));
startAiService(ctx.http.router());
// Offered by reference, not copied: this hands over a resolver, so the key
+30
View File
@@ -0,0 +1,30 @@
import type { PluginServices } from "@termix/plugin-sdk/backend";
let current: PluginServices | null = null;
/** Set in activate, cleared on deactivate. */
export function setPluginServices(services: PluginServices | null): void {
current = services;
}
/** Another plugin's workspaces, as ctx.services.get("workspaces.saved") returns them. */
interface SavedWorkspaces {
list: () => Promise<Array<{ id: number; name: string; isDefault: boolean }>>;
}
/**
* The user's saved workspaces, or null when the workspaces plugin is off or
* the user may not use it. Optional: the assistant works without it.
*/
export async function listSavedWorkspaces(
userId: string,
): Promise<Array<{ id: number; name: string; isDefault: boolean }> | null> {
if (!current) return null;
try {
return await current
.get<SavedWorkspaces>("workspaces.saved", { userId })
.list();
} catch {
return null;
}
}
+4 -11
View File
@@ -7,9 +7,9 @@ import {
createCurrentHostRepository,
createCurrentNetworkTopologyRepository,
createCurrentSnippetRepository,
createCurrentWorkspaceRepository,
} from "../../../../../src/backend/database/repositories/factory.js";
import { num, objectSchema, type AiTool } from "./types.js";
import { listSavedWorkspaces } from "../services.js";
/**
* Read tools project explicit fields rather than spreading rows. Redaction runs
@@ -178,16 +178,9 @@ export const readTools: AiTool[] = [
category: "read",
parameters: objectSchema({}),
handler: async (_args, context) => {
const workspaces = await createCurrentWorkspaceRepository().listByUser(
context.userId,
);
return {
workspaces: workspaces.map((workspace: any) => ({
id: workspace.id,
name: workspace.name,
isDefault: workspace.isDefault ?? false,
})),
};
const workspaces = await listSavedWorkspaces(context.userId);
if (workspaces === null) return { workspaces: [], unavailable: true };
return { workspaces };
},
},
{