MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / createGraph

Function createGraph

src/core/tools/graph.ts:38–84  ·  view source on GitHub ↗
(gateway: GatewayClient, input: CreateGraphInput)

Source from the content-addressed store, hash-verified

36 && node.cfg?.name === 'onLoad'
37 && Object.keys(node.props || {}).length === 0
38 && Object.keys(node.inputs || {}).length === 0
39 && JSON.stringify(node.outputs) === JSON.stringify({ output: [] });
40}
41
42function validateVariableDefinitions(variables: NonNullable<CreateGraphInput['variables']>): string | undefined {
43 const ids = new Set<string>();
44 for (const variable of variables) {
45 if (!/^[a-zA-Z0-9]+$/.test(variable.id)) return `变量 ID ${variable.id} 必须是纯字母数字`;
46 if (ids.has(variable.id)) return `变量 ID ${variable.id} 重复`;
47 if (typeof variable.value !== variable.type) return `变量 ${variable.id} 的初始值类型必须是 ${variable.type}`;
48 if (variable.name !== undefined && !variable.name.trim()) return `变量 ${variable.id} 的显示名称不能为空`;
49 ids.add(variable.id);
50 }
51 return undefined;
52}
53
54async function deleteGraphConfirmed(gateway: GatewayClient, id: string): Promise<void> {
55 try {
56 await gateway.callApi('deleteGraph', { id }, 10000);
57 } catch (deleteError) {
58 const graphList = await gateway.callApi<Array<{ id: string }>>('getGraphList', {}, 10000);
59 if (!Array.isArray(graphList) || graphList.some((graph) => graph.id === id)) throw deleteError;
60 }
61}
62
63export async function getGraphs(gateway: GatewayClient): Promise<ToolResponse<GraphSummary[]>> {
64 try {
65 const graphs = await gateway.callApi<Array<{ id: string; enable?: boolean; userData?: { name?: string; lastUpdateTime?: number }; createTime?: number }>>('getGraphList', {}, 10000);
66 const graphList = Array.isArray(graphs) ? graphs : [];
67 return {
68 success: true,
69 data: graphList.map((graph) => ({
70 id: graph.id,
71 name: graph.userData?.name || graph.id,
72 enable: graph.enable ?? false,
73 createTime: graph.createTime,
74 updateTime: graph.userData?.lastUpdateTime,
75 })),
76 };
77 } catch (error) {
78 return { success: false, error: `获取规则列表失败: ${error}` };
79 }
80}
81
82export async function getGraph(gateway: GatewayClient, id: string): Promise<ToolResponse<Graph>> {
83 try {
84 // 网关的 getGraph 只返回 {id, nodes},名称与启用状态在规则列表里;两次请求同时发
85 const [graph, graphList] = await Promise.all([
86 gateway.callApi<Graph>('getGraph', { id }, 10000),
87 gateway.callApi<Array<{

Callers 2

createCoreToolsFunction · 0.90
registerGraphToolsFunction · 0.85

Calls 3

layoutNodesFunction · 0.90
validateGraphFunction · 0.90
callApiMethod · 0.45

Tested by

no test coverage detected