mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 14:15:24 +00:00
feat: convert network-topology to a full plugin (B1)
This commit is contained in:
1 parent
95abe24798
commit
fdedca39fd
51 files changed
+30321
-814
No files matched your search
@@ -28,3 +28,26 @@ export async function listSavedWorkspaces(
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Another plugin's graph, as ctx.services.get("network-topology.graph") returns it. */
|
||||
interface NetworkTopologyGraph {
|
||||
get: () => Promise<unknown | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The user's saved network topology, or null when the network-topology
|
||||
* plugin is off or the user may not use it. Optional: the tool disappears
|
||||
* without it.
|
||||
*/
|
||||
export async function getNetworkTopology(
|
||||
userId: string,
|
||||
): Promise<unknown | null> {
|
||||
if (!current) return null;
|
||||
try {
|
||||
return await current
|
||||
.get<NetworkTopologyGraph>("network-topology.graph", { userId })
|
||||
.get();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,10 @@ import {
|
||||
createCurrentFleetRepository,
|
||||
createCurrentHomepageItemRepository,
|
||||
createCurrentHostRepository,
|
||||
createCurrentNetworkTopologyRepository,
|
||||
createCurrentSnippetRepository,
|
||||
} from "../../../../../src/backend/database/repositories/factory.js";
|
||||
import { num, objectSchema, type AiTool } from "./types.js";
|
||||
import { listSavedWorkspaces } from "../services.js";
|
||||
import { listSavedWorkspaces, getNetworkTopology } from "../services.js";
|
||||
|
||||
/**
|
||||
* Read tools project explicit fields rather than spreading rows. Redaction runs
|
||||
@@ -260,12 +259,9 @@ export const readTools: AiTool[] = [
|
||||
category: "read",
|
||||
parameters: objectSchema({}),
|
||||
handler: async (_args, context) => {
|
||||
const topology =
|
||||
await createCurrentNetworkTopologyRepository().findByUserId(
|
||||
context.userId,
|
||||
);
|
||||
if (!topology) return { topology: null };
|
||||
return { topology: (topology as any).data ?? null };
|
||||
const topology = await getNetworkTopology(context.userId);
|
||||
if (topology === null) return { topology: null, unavailable: true };
|
||||
return { topology };
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user