( server: McpServer, gatewayManager: GatewayManager )
| 22 | graphHash, |
| 23 | buildTextContext, |
| 24 | textToNodes, |
| 25 | checkGraphLayout, |
| 26 | } from "../../core/index.js"; |
| 27 | import type { Graph, GraphNode } from "../../core/index.js"; |
| 28 | import { |
| 29 | ResponseFormatSchema, |
| 30 | textResult, |
| 31 | jsonResult, |
| 32 | errorResult, |
| 33 | handleError, |
| 34 | formatGraphListMarkdown, |
| 35 | shapeGraphOutput, |
| 36 | compactIssues, |
| 37 | } from "../utils.js"; |
| 38 | import { GraphDraftStore } from "./graphDraft.js"; |
| 39 | |
| 40 | const GraphVariableSchema = z.discriminatedUnion("type", [ |
| 41 | z.object({ id: z.string().regex(/^[a-zA-Z0-9]+$/, "id 必须是纯字母数字"), type: z.literal("number"), value: z.number(), name: z.string().trim().min(1).optional() }), |
| 42 | z.object({ id: z.string().regex(/^[a-zA-Z0-9]+$/, "id 必须是纯字母数字"), type: z.literal("string"), value: z.string(), name: z.string().trim().min(1).optional() }), |
| 43 | ]); |
| 44 | |
| 45 | const GraphNodeSchema = z.object({ |
| 46 | id: z.string().regex(/^[0-9a-zA-Z]+$/, "节点 ID 只能包含字母和数字"), |
| 47 | type: z.string().min(1), |
| 48 | cfg: z.record(z.unknown()), |
| 49 | props: z.record(z.unknown()), |
| 50 | inputs: z.record(z.unknown()), |
| 51 | outputs: z.record(z.array(z.string())), |
| 52 | }); |
| 53 | |
| 54 | const GraphMergeSchema = z.object({ |
| 55 | id: z.string().min(1).describe("要局部修改的节点 ID"), |
| 56 | props: z.record(z.unknown()).optional().describe("浅合并到 props;值为 null 删除该键"), |
| 57 | cfg: z.record(z.unknown()).optional().describe("浅合并到 cfg;值为 null 删除该键"), |
| 58 | outputs: z.record(z.array(z.string())).optional().describe("按端口整体替换 outputs"), |
| 59 | inputs: z.record(z.unknown()).optional().describe("浅合并到 inputs;值为 null 删除该键"), |
| 60 | }); |
| 61 | |
| 62 | const GRAPH_FULL_HINT = "请改用 detail=summary,或用 node_ids 只取需要的节点"; |
| 63 | |
| 64 | const PositionsSchema = z.record(z.object({ |
| 65 | x: z.number(), |
| 66 | y: z.number(), |
| 67 | width: z.number().positive().optional(), |
| 68 | height: z.number().positive().optional(), |
| 69 | })); |
| 70 | |
| 71 | const LayoutOptionsSchema = z.object({ |
| 72 | mode: z.enum(["incremental", "full"]).optional().describe("incremental(默认)只摆放没有坐标的卡片;full 全图重排"), |
| 73 | pinned: z.array(z.string()).optional().describe("full 模式下保持不动的节点"), |
| 74 | }); |
| 75 | const VALIDATE_HINT = "错误过多,请先修复前面的错误后重新校验"; |
| 76 | |
| 77 | /** 缺少 cfg 时补一个默认 cfg,便于只传 {id, nodes} 校验 */ |
| 78 | function withDefaultCfg(graph: { id: string; nodes: unknown[]; cfg?: unknown }): Graph { |
| 79 | const cfg = (graph.cfg && typeof graph.cfg === "object" ? graph.cfg : { |
| 80 | id: graph.id, |
| 81 | enable: true, |
no test coverage detected