callman-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/client/api.d.ts +109 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +180 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/errors.d.ts +27 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +98 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/http.d.ts +34 -0
- package/dist/client/http.d.ts.map +1 -0
- package/dist/client/http.js +121 -0
- package/dist/client/http.js.map +1 -0
- package/dist/client/types.d.ts +327 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +5 -0
- package/dist/client/types.js.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +69 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +35 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +91 -0
- package/dist/context.js.map +1 -0
- package/dist/domain/diagram/build.d.ts +260 -0
- package/dist/domain/diagram/build.d.ts.map +1 -0
- package/dist/domain/diagram/build.js +160 -0
- package/dist/domain/diagram/build.js.map +1 -0
- package/dist/domain/diagram/layout.d.ts +17 -0
- package/dist/domain/diagram/layout.d.ts.map +1 -0
- package/dist/domain/diagram/layout.js +61 -0
- package/dist/domain/diagram/layout.js.map +1 -0
- package/dist/domain/diagram/patch.d.ts +330 -0
- package/dist/domain/diagram/patch.d.ts.map +1 -0
- package/dist/domain/diagram/patch.js +176 -0
- package/dist/domain/diagram/patch.js.map +1 -0
- package/dist/domain/diagram/summarize.d.ts +41 -0
- package/dist/domain/diagram/summarize.d.ts.map +1 -0
- package/dist/domain/diagram/summarize.js +47 -0
- package/dist/domain/diagram/summarize.js.map +1 -0
- package/dist/domain/importDetect.d.ts +6 -0
- package/dist/domain/importDetect.d.ts.map +1 -0
- package/dist/domain/importDetect.js +32 -0
- package/dist/domain/importDetect.js.map +1 -0
- package/dist/domain/requestShape.d.ts +796 -0
- package/dist/domain/requestShape.d.ts.map +1 -0
- package/dist/domain/requestShape.js +250 -0
- package/dist/domain/requestShape.js.map +1 -0
- package/dist/domain/resolve.d.ts +30 -0
- package/dist/domain/resolve.d.ts.map +1 -0
- package/dist/domain/resolve.js +56 -0
- package/dist/domain/resolve.js.map +1 -0
- package/dist/domain/scenario/build.d.ts +270 -0
- package/dist/domain/scenario/build.d.ts.map +1 -0
- package/dist/domain/scenario/build.js +135 -0
- package/dist/domain/scenario/build.js.map +1 -0
- package/dist/domain/scenario/summarize.d.ts +206 -0
- package/dist/domain/scenario/summarize.d.ts.map +1 -0
- package/dist/domain/scenario/summarize.js +138 -0
- package/dist/domain/scenario/summarize.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cache.d.ts +12 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +40 -0
- package/dist/lib/cache.js.map +1 -0
- package/dist/lib/ids.d.ts +5 -0
- package/dist/lib/ids.d.ts.map +1 -0
- package/dist/lib/ids.js +19 -0
- package/dist/lib/ids.js.map +1 -0
- package/dist/lib/log.d.ts +10 -0
- package/dist/lib/log.d.ts.map +1 -0
- package/dist/lib/log.js +25 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/mask.d.ts +24 -0
- package/dist/lib/mask.d.ts.map +1 -0
- package/dist/lib/mask.js +63 -0
- package/dist/lib/mask.js.map +1 -0
- package/dist/lib/pagination.d.ts +21 -0
- package/dist/lib/pagination.d.ts.map +1 -0
- package/dist/lib/pagination.js +40 -0
- package/dist/lib/pagination.js.map +1 -0
- package/dist/lib/truncate.d.ts +25 -0
- package/dist/lib/truncate.d.ts.map +1 -0
- package/dist/lib/truncate.js +45 -0
- package/dist/lib/truncate.js.map +1 -0
- package/dist/main.d.ts +9 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +12 -0
- package/dist/main.js.map +1 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +72 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/docs/diagramSchema.d.ts +2 -0
- package/dist/resources/docs/diagramSchema.d.ts.map +1 -0
- package/dist/resources/docs/diagramSchema.js +65 -0
- package/dist/resources/docs/diagramSchema.js.map +1 -0
- package/dist/resources/docs/overview.d.ts +2 -0
- package/dist/resources/docs/overview.d.ts.map +1 -0
- package/dist/resources/docs/overview.js +46 -0
- package/dist/resources/docs/overview.js.map +1 -0
- package/dist/resources/docs/requestSchema.d.ts +2 -0
- package/dist/resources/docs/requestSchema.d.ts.map +1 -0
- package/dist/resources/docs/requestSchema.js +70 -0
- package/dist/resources/docs/requestSchema.js.map +1 -0
- package/dist/resources/generated/aiPacks.d.ts +3 -0
- package/dist/resources/generated/aiPacks.d.ts.map +1 -0
- package/dist/resources/generated/aiPacks.js +11 -0
- package/dist/resources/generated/aiPacks.js.map +1 -0
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +114 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/run/executeCollection.d.ts +19 -0
- package/dist/run/executeCollection.d.ts.map +1 -0
- package/dist/run/executeCollection.js +89 -0
- package/dist/run/executeCollection.js.map +1 -0
- package/dist/run/loadBundle.d.ts +9 -0
- package/dist/run/loadBundle.d.ts.map +1 -0
- package/dist/run/loadBundle.js +242 -0
- package/dist/run/loadBundle.js.map +1 -0
- package/dist/run/resolveTemplate.d.ts +2 -0
- package/dist/run/resolveTemplate.d.ts.map +1 -0
- package/dist/run/resolveTemplate.js +12 -0
- package/dist/run/resolveTemplate.js.map +1 -0
- package/dist/run/summarize.d.ts +73 -0
- package/dist/run/summarize.d.ts.map +1 -0
- package/dist/run/summarize.js +69 -0
- package/dist/run/summarize.js.map +1 -0
- package/dist/run/types.d.ts +46 -0
- package/dist/run/types.d.ts.map +1 -0
- package/dist/run/types.js +2 -0
- package/dist/run/types.js.map +1 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/catalog.d.ts +18 -0
- package/dist/tools/catalog.d.ts.map +1 -0
- package/dist/tools/catalog.js +66 -0
- package/dist/tools/catalog.js.map +1 -0
- package/dist/tools/collections.d.ts +4 -0
- package/dist/tools/collections.d.ts.map +1 -0
- package/dist/tools/collections.js +201 -0
- package/dist/tools/collections.js.map +1 -0
- package/dist/tools/diagrams.d.ts +4 -0
- package/dist/tools/diagrams.d.ts.map +1 -0
- package/dist/tools/diagrams.js +226 -0
- package/dist/tools/diagrams.js.map +1 -0
- package/dist/tools/environments.d.ts +4 -0
- package/dist/tools/environments.d.ts.map +1 -0
- package/dist/tools/environments.js +150 -0
- package/dist/tools/environments.js.map +1 -0
- package/dist/tools/import.d.ts +6 -0
- package/dist/tools/import.d.ts.map +1 -0
- package/dist/tools/import.js +144 -0
- package/dist/tools/import.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +26 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lookups.d.ts +33 -0
- package/dist/tools/lookups.d.ts.map +1 -0
- package/dist/tools/lookups.js +132 -0
- package/dist/tools/lookups.js.map +1 -0
- package/dist/tools/meta.d.ts +4 -0
- package/dist/tools/meta.d.ts.map +1 -0
- package/dist/tools/meta.js +78 -0
- package/dist/tools/meta.js.map +1 -0
- package/dist/tools/requests.d.ts +4 -0
- package/dist/tools/requests.d.ts.map +1 -0
- package/dist/tools/requests.js +247 -0
- package/dist/tools/requests.js.map +1 -0
- package/dist/tools/run.d.ts +4 -0
- package/dist/tools/run.d.ts.map +1 -0
- package/dist/tools/run.js +167 -0
- package/dist/tools/run.js.map +1 -0
- package/dist/tools/scenarios.d.ts +4 -0
- package/dist/tools/scenarios.d.ts.map +1 -0
- package/dist/tools/scenarios.js +242 -0
- package/dist/tools/scenarios.js.map +1 -0
- package/dist/tools/shared.d.ts +20 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +74 -0
- package/dist/tools/shared.js.map +1 -0
- package/dist/tools/workspaces.d.ts +4 -0
- package/dist/tools/workspaces.d.ts.map +1 -0
- package/dist/tools/workspaces.js +80 -0
- package/dist/tools/workspaces.js.map +1 -0
- package/dist-cjs/client/api.js +183 -0
- package/dist-cjs/client/errors.js +104 -0
- package/dist-cjs/client/http.js +124 -0
- package/dist-cjs/client/types.js +5 -0
- package/dist-cjs/config.js +73 -0
- package/dist-cjs/context.js +94 -0
- package/dist-cjs/domain/diagram/build.js +164 -0
- package/dist-cjs/domain/diagram/layout.js +98 -0
- package/dist-cjs/domain/diagram/patch.js +179 -0
- package/dist-cjs/domain/diagram/summarize.js +52 -0
- package/dist-cjs/domain/importDetect.js +40 -0
- package/dist-cjs/domain/requestShape.js +260 -0
- package/dist-cjs/domain/resolve.js +63 -0
- package/dist-cjs/domain/scenario/build.js +140 -0
- package/dist-cjs/domain/scenario/summarize.js +144 -0
- package/dist-cjs/lib/cache.js +43 -0
- package/dist-cjs/lib/ids.js +24 -0
- package/dist-cjs/lib/log.js +28 -0
- package/dist-cjs/lib/mask.js +72 -0
- package/dist-cjs/lib/pagination.js +48 -0
- package/dist-cjs/lib/truncate.js +52 -0
- package/dist-cjs/main.js +31 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/prompts/index.js +75 -0
- package/dist-cjs/resources/docs/diagramSchema.js +67 -0
- package/dist-cjs/resources/docs/overview.js +48 -0
- package/dist-cjs/resources/docs/requestSchema.js +72 -0
- package/dist-cjs/resources/generated/aiPacks.js +13 -0
- package/dist-cjs/resources/index.js +117 -0
- package/dist-cjs/run/executeCollection.js +93 -0
- package/dist-cjs/run/loadBundle.js +246 -0
- package/dist-cjs/run/resolveTemplate.js +15 -0
- package/dist-cjs/run/summarize.js +73 -0
- package/dist-cjs/run/types.js +2 -0
- package/dist-cjs/server.js +28 -0
- package/dist-cjs/tools/catalog.js +69 -0
- package/dist-cjs/tools/collections.js +204 -0
- package/dist-cjs/tools/diagrams.js +229 -0
- package/dist-cjs/tools/environments.js +153 -0
- package/dist-cjs/tools/import.js +147 -0
- package/dist-cjs/tools/index.js +31 -0
- package/dist-cjs/tools/lookups.js +149 -0
- package/dist-cjs/tools/meta.js +81 -0
- package/dist-cjs/tools/requests.js +250 -0
- package/dist-cjs/tools/run.js +203 -0
- package/dist-cjs/tools/scenarios.js +245 -0
- package/dist-cjs/tools/shared.js +81 -0
- package/dist-cjs/tools/workspaces.js +83 -0
- package/package.json +80 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDiagramDocument = exports.suggestComponentTypes = exports.diagramInputSchema = exports.diagramEdgeInputSchema = exports.diagramNodeInputSchema = exports.EDGE_SEMANTICS_INPUT = void 0;
|
|
4
|
+
const callman_core_1 = require("callman-core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const errors_js_1 = require("../../client/errors.js");
|
|
7
|
+
const ids_js_1 = require("../../lib/ids.js");
|
|
8
|
+
// From the COMPACT diagram a model writes (typed nodes with labels, edges
|
|
9
|
+
// with a meaning) to the DiagramDocument the Diagram Studio renders. Ids are
|
|
10
|
+
// short and stable (n1…, e1…), component types are checked against the
|
|
11
|
+
// shared catalog (unknown → suggestions, never a silent blank shape), edge
|
|
12
|
+
// meaning becomes the studio's notation (sync / async / fallback / bus), and
|
|
13
|
+
// the result is validated with the same parser the backend and desktop use.
|
|
14
|
+
exports.EDGE_SEMANTICS_INPUT = ["sync", "async", "fallback", "bus"];
|
|
15
|
+
exports.diagramNodeInputSchema = zod_1.z.object({
|
|
16
|
+
id: zod_1.z.string().min(1).max(64).optional().describe("Stable id (n1, api, db…); generated when omitted"),
|
|
17
|
+
type: zod_1.z.string().min(1).max(80).describe("Component type from callman://diagram/components, e.g. net.service, db.postgres, aws.lambda, flow.process"),
|
|
18
|
+
label: zod_1.z.string().max(200).optional(),
|
|
19
|
+
parent: zod_1.z.string().max(64).optional().describe("Id of a container node (net.zone, flow.frame…) this node sits inside"),
|
|
20
|
+
position: zod_1.z.object({ x: zod_1.z.number(), y: zod_1.z.number() }).optional(),
|
|
21
|
+
size: zod_1.z.object({ width: zod_1.z.number().positive(), height: zod_1.z.number().positive() }).optional(),
|
|
22
|
+
style: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
23
|
+
data: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
24
|
+
});
|
|
25
|
+
exports.diagramEdgeInputSchema = zod_1.z.object({
|
|
26
|
+
id: zod_1.z.string().min(1).max(64).optional(),
|
|
27
|
+
source: zod_1.z.string().min(1).max(64),
|
|
28
|
+
target: zod_1.z.string().min(1).max(64),
|
|
29
|
+
label: zod_1.z.string().max(200).optional(),
|
|
30
|
+
semantic: zod_1.z.enum(exports.EDGE_SEMANTICS_INPUT).optional().describe("sync (default) = request/response, async = event, fallback = retry/optional, bus = message bus"),
|
|
31
|
+
routing: zod_1.z.enum(["orthogonal", "straight", "curved"]).optional(),
|
|
32
|
+
markerEnd: zod_1.z.enum(["none", "classic", "classicThin", "open", "block", "diamond", "oval"]).optional(),
|
|
33
|
+
});
|
|
34
|
+
exports.diagramInputSchema = zod_1.z.object({
|
|
35
|
+
title: zod_1.z.string().min(1).max(200),
|
|
36
|
+
nodes: zod_1.z.array(exports.diagramNodeInputSchema).min(1).max(500),
|
|
37
|
+
edges: zod_1.z.array(exports.diagramEdgeInputSchema).max(2000).default([]),
|
|
38
|
+
canvas: zod_1.z.object({ background: zod_1.z.enum(["grid", "dots", "blank"]).optional(), gridSize: zod_1.z.number().int().positive().optional() }).optional(),
|
|
39
|
+
});
|
|
40
|
+
const suggestComponentTypes = (type, limit = 5) => {
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
const out = [];
|
|
43
|
+
const push = (candidate) => {
|
|
44
|
+
if (!seen.has(candidate) && out.length < limit) {
|
|
45
|
+
seen.add(candidate);
|
|
46
|
+
out.push(candidate);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
for (const entry of (0, callman_core_1.searchDiagramComponents)(type))
|
|
50
|
+
push(entry.type);
|
|
51
|
+
// A typo usually sits at the END of the last segment ("db.postgresqlx"):
|
|
52
|
+
// shrink it until something in the catalog contains it.
|
|
53
|
+
const tail = (type.split(".").pop() ?? type).toLowerCase();
|
|
54
|
+
for (let length = tail.length; length >= 3 && out.length < limit; length -= 1) {
|
|
55
|
+
const needle = tail.slice(0, length);
|
|
56
|
+
for (const entry of callman_core_1.DIAGRAM_COMPONENT_CATALOG) {
|
|
57
|
+
const haystack = [entry.type, entry.label, ...(entry.aliases ?? [])].join(" ").toLowerCase();
|
|
58
|
+
if (haystack.includes(needle))
|
|
59
|
+
push(entry.type);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Still nothing: offer the same namespace ("db.*", "aws.*").
|
|
63
|
+
const namespace = type.includes(".") ? `${type.split(".")[0].toLowerCase()}.` : null;
|
|
64
|
+
if (namespace) {
|
|
65
|
+
for (const entry of callman_core_1.DIAGRAM_COMPONENT_CATALOG)
|
|
66
|
+
if (entry.type.toLowerCase().startsWith(namespace))
|
|
67
|
+
push(entry.type);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
};
|
|
71
|
+
exports.suggestComponentTypes = suggestComponentTypes;
|
|
72
|
+
const buildDiagramDocument = (input, options = {}) => {
|
|
73
|
+
const strict = options.strictTypes !== false;
|
|
74
|
+
const warnings = [];
|
|
75
|
+
const nextNodeId = (0, ids_js_1.sequentialIds)("n", input.nodes.map((node) => node.id).filter((id) => Boolean(id)));
|
|
76
|
+
const nextEdgeId = (0, ids_js_1.sequentialIds)("e", input.edges.map((edge) => edge.id).filter((id) => Boolean(id)));
|
|
77
|
+
// Ids first so parents/edges can reference nodes declared later.
|
|
78
|
+
const ids = input.nodes.map((node) => node.id ?? nextNodeId());
|
|
79
|
+
const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
80
|
+
if (duplicates.length > 0) {
|
|
81
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DUPLICATE_NODE_ID", `Duplicate node ids: ${[...new Set(duplicates)].join(", ")}`);
|
|
82
|
+
}
|
|
83
|
+
const idSet = new Set(ids);
|
|
84
|
+
const unknown = [];
|
|
85
|
+
const typeOf = new Map();
|
|
86
|
+
const nodes = input.nodes.map((node, index) => {
|
|
87
|
+
const id = ids[index];
|
|
88
|
+
let type = node.type.trim();
|
|
89
|
+
const known = (0, callman_core_1.getDiagramComponent)(type);
|
|
90
|
+
if (!known) {
|
|
91
|
+
const suggestions = (0, exports.suggestComponentTypes)(type);
|
|
92
|
+
if (strict)
|
|
93
|
+
unknown.push({ type, suggestions });
|
|
94
|
+
else {
|
|
95
|
+
warnings.push(`Unknown component type "${type}" on ${id} → drawn as a rectangle (suggestions: ${suggestions.join(", ") || "none"})`);
|
|
96
|
+
type = "rect";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const def = (0, callman_core_1.getDiagramComponent)(type);
|
|
100
|
+
typeOf.set(id, type);
|
|
101
|
+
if (node.parent && !idSet.has(node.parent)) {
|
|
102
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_PARENT_NOT_FOUND", `Node ${id} references parent "${node.parent}" which is not in nodes.`);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
id,
|
|
106
|
+
type,
|
|
107
|
+
position: node.position ?? { x: 0, y: 0 },
|
|
108
|
+
size: node.size ?? def?.defaultSize ?? { width: 140, height: 60 },
|
|
109
|
+
...(node.label !== undefined || !known ? { label: node.label ?? node.type } : def?.defaultLabel ? { label: def.defaultLabel } : {}),
|
|
110
|
+
...(node.parent ? { parentId: node.parent } : {}),
|
|
111
|
+
...(node.style ? { style: node.style } : {}),
|
|
112
|
+
...(node.data ? { data: node.data } : {}),
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
if (unknown.length > 0) {
|
|
116
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_UNKNOWN_COMPONENT_TYPE", `Unknown component type(s): ${unknown.map((entry) => entry.type).join(", ")}. Read callman://diagram/components for the catalog, or pass strictTypes:false to draw them as rectangles.`, { unknownTypes: unknown });
|
|
117
|
+
}
|
|
118
|
+
const edgeIds = new Set();
|
|
119
|
+
const edges = input.edges.map((edge) => {
|
|
120
|
+
const id = edge.id ?? nextEdgeId();
|
|
121
|
+
if (edgeIds.has(id))
|
|
122
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DUPLICATE_EDGE_ID", `Duplicate edge id: ${id}`);
|
|
123
|
+
edgeIds.add(id);
|
|
124
|
+
for (const endpoint of [edge.source, edge.target]) {
|
|
125
|
+
if (!idSet.has(endpoint)) {
|
|
126
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_EDGE_ENDPOINT_NOT_FOUND", `Edge ${id} references "${endpoint}" which is not a node id.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let semantic = edge.semantic;
|
|
130
|
+
// A fresh edge into a broker reads as a bus line — the studio's own rule.
|
|
131
|
+
if (!semantic && ((0, callman_core_1.isBusComponentType)(typeOf.get(edge.source)) || (0, callman_core_1.isBusComponentType)(typeOf.get(edge.target)))) {
|
|
132
|
+
semantic = "bus";
|
|
133
|
+
}
|
|
134
|
+
const style = semantic ? (0, callman_core_1.semanticStyle)(semantic) : undefined;
|
|
135
|
+
return {
|
|
136
|
+
id,
|
|
137
|
+
source: edge.source,
|
|
138
|
+
target: edge.target,
|
|
139
|
+
...(edge.label ? { label: edge.label } : {}),
|
|
140
|
+
routing: edge.routing ?? "orthogonal",
|
|
141
|
+
markerEnd: edge.markerEnd ?? "classicThin",
|
|
142
|
+
...(style && !(0, callman_core_1.isDefaultEdgeStyle)(style) ? { style } : semantic === "sync" ? { style } : {}),
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
const timestamp = options.createdAt ?? (0, callman_core_1.nowIso)();
|
|
146
|
+
const document = (0, callman_core_1.normalizeDiagramStyles)({
|
|
147
|
+
schemaVersion: callman_core_1.SCHEMA_VERSION,
|
|
148
|
+
id: options.existingId ?? `doc_${Math.random().toString(36).slice(2, 10)}`,
|
|
149
|
+
meta: { title: input.title.trim(), createdAt: timestamp, updatedAt: (0, callman_core_1.nowIso)() },
|
|
150
|
+
canvas: { background: input.canvas?.background ?? "dots", gridSize: input.canvas?.gridSize ?? 16 },
|
|
151
|
+
nodes,
|
|
152
|
+
edges,
|
|
153
|
+
});
|
|
154
|
+
const parsed = (0, callman_core_1.safeParseDiagramDocument)(document);
|
|
155
|
+
if (!parsed.ok) {
|
|
156
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DOCUMENT_INVALID", `The diagram document is invalid: ${parsed.errors.join("; ")}`, { errors: parsed.errors });
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
document: parsed.document,
|
|
160
|
+
warnings,
|
|
161
|
+
unpositionedNodeIds: input.nodes.filter((node) => !node.position).map((_node, index) => ids[index]),
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
exports.buildDiagramDocument = buildDiagramDocument;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.placeNewNodes = exports.layoutDocument = void 0;
|
|
37
|
+
const callman_core_1 = require("callman-core");
|
|
38
|
+
let defaultEngine = null;
|
|
39
|
+
const loadElk = () => {
|
|
40
|
+
defaultEngine ??= Promise.resolve().then(() => __importStar(require("elkjs/lib/elk.bundled.js"))).then((module) => {
|
|
41
|
+
const ElkCtor = (module.default ?? module);
|
|
42
|
+
const elk = new ElkCtor();
|
|
43
|
+
return { layout: (graph) => elk.layout(graph) };
|
|
44
|
+
});
|
|
45
|
+
return defaultEngine;
|
|
46
|
+
};
|
|
47
|
+
const layoutDocument = async (doc, options = {}) => {
|
|
48
|
+
const algorithm = options.algorithm ?? "layered";
|
|
49
|
+
const direction = options.direction ?? "DOWN";
|
|
50
|
+
try {
|
|
51
|
+
const engine = options.engine ?? (await loadElk());
|
|
52
|
+
const graph = (0, callman_core_1.buildHierarchicalElkGraph)(doc, algorithm, { direction });
|
|
53
|
+
const result = await engine.layout(graph);
|
|
54
|
+
const layout = (0, callman_core_1.applyHierarchicalElkResult)(result);
|
|
55
|
+
return { document: touch((0, callman_core_1.applyDetailedLayout)(doc, layout)), engine: "elk" };
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return {
|
|
59
|
+
document: touch((0, callman_core_1.gridLayout)(doc)),
|
|
60
|
+
engine: "grid",
|
|
61
|
+
warning: `Automatic layout fell back to a grid: ${error instanceof Error ? error.message : String(error)}`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.layoutDocument = layoutDocument;
|
|
66
|
+
// Place ONLY the given nodes (new ones from a patch) below the current
|
|
67
|
+
// bounding box, in rows — nothing that already has a position moves.
|
|
68
|
+
const placeNewNodes = (doc, nodeIds, gap = 40) => {
|
|
69
|
+
const wanted = new Set(nodeIds);
|
|
70
|
+
if (wanted.size === 0)
|
|
71
|
+
return doc;
|
|
72
|
+
const placed = doc.nodes.filter((node) => !wanted.has(node.id) && !node.parentId);
|
|
73
|
+
const maxY = placed.reduce((max, node) => Math.max(max, node.position.y + node.size.height), 0);
|
|
74
|
+
const minX = placed.reduce((min, node) => Math.min(min, node.position.x), placed.length > 0 ? Infinity : 0);
|
|
75
|
+
let cursorX = Number.isFinite(minX) ? minX : 0;
|
|
76
|
+
let cursorY = placed.length > 0 ? maxY + gap * 2 : 0;
|
|
77
|
+
let rowHeight = 0;
|
|
78
|
+
const rowLimit = 1200;
|
|
79
|
+
const nodes = doc.nodes.map((node) => {
|
|
80
|
+
if (!wanted.has(node.id))
|
|
81
|
+
return node;
|
|
82
|
+
if (cursorX + node.size.width > rowLimit && cursorX > 0) {
|
|
83
|
+
cursorX = Number.isFinite(minX) ? minX : 0;
|
|
84
|
+
cursorY += rowHeight + gap;
|
|
85
|
+
rowHeight = 0;
|
|
86
|
+
}
|
|
87
|
+
const positioned = { ...node, position: { x: cursorX, y: cursorY } };
|
|
88
|
+
cursorX += node.size.width + gap;
|
|
89
|
+
rowHeight = Math.max(rowHeight, node.size.height);
|
|
90
|
+
return positioned;
|
|
91
|
+
});
|
|
92
|
+
return touch({ ...doc, nodes });
|
|
93
|
+
};
|
|
94
|
+
exports.placeNewNodes = placeNewNodes;
|
|
95
|
+
const touch = (doc) => ({
|
|
96
|
+
...doc,
|
|
97
|
+
meta: { ...doc.meta, updatedAt: new Date().toISOString() },
|
|
98
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDiagramPatch = exports.diagramPatchOpSchema = void 0;
|
|
4
|
+
const callman_core_1 = require("callman-core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const errors_js_1 = require("../../client/errors.js");
|
|
7
|
+
const ids_js_1 = require("../../lib/ids.js");
|
|
8
|
+
const build_js_1 = require("./build.js");
|
|
9
|
+
// Incremental edits to a stored diagram — the model sends operations, not a
|
|
10
|
+
// 200-node document. Removing a node drops the edges attached to it.
|
|
11
|
+
exports.diagramPatchOpSchema = zod_1.z.discriminatedUnion("op", [
|
|
12
|
+
zod_1.z.object({ op: zod_1.z.literal("addNode"), node: build_js_1.diagramNodeInputSchema }),
|
|
13
|
+
zod_1.z.object({
|
|
14
|
+
op: zod_1.z.literal("updateNode"),
|
|
15
|
+
id: zod_1.z.string().min(1),
|
|
16
|
+
changes: build_js_1.diagramNodeInputSchema.partial().omit({ id: true }),
|
|
17
|
+
}),
|
|
18
|
+
zod_1.z.object({ op: zod_1.z.literal("removeNode"), id: zod_1.z.string().min(1) }),
|
|
19
|
+
zod_1.z.object({ op: zod_1.z.literal("addEdge"), edge: build_js_1.diagramEdgeInputSchema }),
|
|
20
|
+
zod_1.z.object({
|
|
21
|
+
op: zod_1.z.literal("updateEdge"),
|
|
22
|
+
id: zod_1.z.string().min(1),
|
|
23
|
+
changes: build_js_1.diagramEdgeInputSchema.partial().omit({ id: true }),
|
|
24
|
+
}),
|
|
25
|
+
zod_1.z.object({ op: zod_1.z.literal("removeEdge"), id: zod_1.z.string().min(1) }),
|
|
26
|
+
zod_1.z.object({ op: zod_1.z.literal("setTitle"), title: zod_1.z.string().min(1).max(200) }),
|
|
27
|
+
]);
|
|
28
|
+
const applyDiagramPatch = (doc, ops, options = {}) => {
|
|
29
|
+
const strict = options.strictTypes !== false;
|
|
30
|
+
const nodes = new Map(doc.nodes.map((node) => [node.id, { ...node }]));
|
|
31
|
+
const edges = new Map(doc.edges.map((edge) => [edge.id, { ...edge }]));
|
|
32
|
+
let title = doc.meta.title;
|
|
33
|
+
const addedNodeIds = [];
|
|
34
|
+
const removedNodeIds = [];
|
|
35
|
+
const removedEdgeIds = [];
|
|
36
|
+
const warnings = [];
|
|
37
|
+
const nextNodeId = (0, ids_js_1.sequentialIds)("n", nodes.keys());
|
|
38
|
+
const nextEdgeId = (0, ids_js_1.sequentialIds)("e", edges.keys());
|
|
39
|
+
const resolveType = (type, id) => {
|
|
40
|
+
if ((0, callman_core_1.getDiagramComponent)(type))
|
|
41
|
+
return type;
|
|
42
|
+
const suggestions = (0, build_js_1.suggestComponentTypes)(type);
|
|
43
|
+
if (strict) {
|
|
44
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_UNKNOWN_COMPONENT_TYPE", `Unknown component type "${type}" on ${id}.`, {
|
|
45
|
+
unknownTypes: [{ type, suggestions }],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
warnings.push(`Unknown component type "${type}" on ${id} → rect (suggestions: ${suggestions.join(", ") || "none"})`);
|
|
49
|
+
return "rect";
|
|
50
|
+
};
|
|
51
|
+
for (const op of ops) {
|
|
52
|
+
switch (op.op) {
|
|
53
|
+
case "setTitle":
|
|
54
|
+
title = op.title.trim();
|
|
55
|
+
break;
|
|
56
|
+
case "addNode": {
|
|
57
|
+
const id = op.node.id ?? nextNodeId();
|
|
58
|
+
if (nodes.has(id))
|
|
59
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DUPLICATE_NODE_ID", `A node with id "${id}" already exists.`);
|
|
60
|
+
if (op.node.parent && !nodes.has(op.node.parent)) {
|
|
61
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_PARENT_NOT_FOUND", `Parent "${op.node.parent}" does not exist.`);
|
|
62
|
+
}
|
|
63
|
+
const type = resolveType(op.node.type, id);
|
|
64
|
+
const def = (0, callman_core_1.getDiagramComponent)(type);
|
|
65
|
+
nodes.set(id, {
|
|
66
|
+
id,
|
|
67
|
+
type,
|
|
68
|
+
position: op.node.position ?? { x: 0, y: 0 },
|
|
69
|
+
size: op.node.size ?? def?.defaultSize ?? { width: 140, height: 60 },
|
|
70
|
+
label: op.node.label ?? (type === "rect" && op.node.type !== "rect" ? op.node.type : def?.defaultLabel),
|
|
71
|
+
...(op.node.parent ? { parentId: op.node.parent } : {}),
|
|
72
|
+
...(op.node.style ? { style: op.node.style } : {}),
|
|
73
|
+
...(op.node.data ? { data: op.node.data } : {}),
|
|
74
|
+
});
|
|
75
|
+
if (!op.node.position)
|
|
76
|
+
addedNodeIds.push(id);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "updateNode": {
|
|
80
|
+
const node = nodes.get(op.id);
|
|
81
|
+
if (!node)
|
|
82
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_NODE_NOT_FOUND", `Node "${op.id}" does not exist.`);
|
|
83
|
+
const changes = op.changes;
|
|
84
|
+
if (changes.parent !== undefined && changes.parent && !nodes.has(changes.parent)) {
|
|
85
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_PARENT_NOT_FOUND", `Parent "${changes.parent}" does not exist.`);
|
|
86
|
+
}
|
|
87
|
+
nodes.set(op.id, {
|
|
88
|
+
...node,
|
|
89
|
+
...(changes.type !== undefined ? { type: resolveType(changes.type, op.id) } : {}),
|
|
90
|
+
...(changes.label !== undefined ? { label: changes.label } : {}),
|
|
91
|
+
...(changes.position !== undefined ? { position: changes.position } : {}),
|
|
92
|
+
...(changes.size !== undefined ? { size: changes.size } : {}),
|
|
93
|
+
...(changes.parent !== undefined ? { parentId: changes.parent || undefined } : {}),
|
|
94
|
+
...(changes.style !== undefined ? { style: changes.style } : {}),
|
|
95
|
+
...(changes.data !== undefined ? { data: changes.data } : {}),
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "removeNode": {
|
|
100
|
+
if (!nodes.delete(op.id))
|
|
101
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_NODE_NOT_FOUND", `Node "${op.id}" does not exist.`);
|
|
102
|
+
removedNodeIds.push(op.id);
|
|
103
|
+
for (const [edgeId, edge] of [...edges]) {
|
|
104
|
+
if (edge.source === op.id || edge.target === op.id) {
|
|
105
|
+
edges.delete(edgeId);
|
|
106
|
+
removedEdgeIds.push(edgeId);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Children of a removed container become top-level.
|
|
110
|
+
for (const node of nodes.values())
|
|
111
|
+
if (node.parentId === op.id)
|
|
112
|
+
delete node.parentId;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "addEdge": {
|
|
116
|
+
const id = op.edge.id ?? nextEdgeId();
|
|
117
|
+
if (edges.has(id))
|
|
118
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DUPLICATE_EDGE_ID", `An edge with id "${id}" already exists.`);
|
|
119
|
+
for (const endpoint of [op.edge.source, op.edge.target]) {
|
|
120
|
+
if (!nodes.has(endpoint) && !edges.has(endpoint)) {
|
|
121
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_EDGE_ENDPOINT_NOT_FOUND", `Edge endpoint "${endpoint}" does not exist.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const semantic = op.edge.semantic ??
|
|
125
|
+
((0, callman_core_1.isBusComponentType)(nodes.get(op.edge.source)?.type) || (0, callman_core_1.isBusComponentType)(nodes.get(op.edge.target)?.type) ? "bus" : undefined);
|
|
126
|
+
edges.set(id, {
|
|
127
|
+
id,
|
|
128
|
+
source: op.edge.source,
|
|
129
|
+
target: op.edge.target,
|
|
130
|
+
...(op.edge.label ? { label: op.edge.label } : {}),
|
|
131
|
+
routing: op.edge.routing ?? "orthogonal",
|
|
132
|
+
markerEnd: op.edge.markerEnd ?? "classicThin",
|
|
133
|
+
...(semantic ? { style: (0, callman_core_1.semanticStyle)(semantic) } : {}),
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "updateEdge": {
|
|
138
|
+
const edge = edges.get(op.id);
|
|
139
|
+
if (!edge)
|
|
140
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_EDGE_NOT_FOUND", `Edge "${op.id}" does not exist.`);
|
|
141
|
+
const changes = op.changes;
|
|
142
|
+
const next = {
|
|
143
|
+
...edge,
|
|
144
|
+
...(changes.source !== undefined ? { source: changes.source } : {}),
|
|
145
|
+
...(changes.target !== undefined ? { target: changes.target } : {}),
|
|
146
|
+
...(changes.label !== undefined ? { label: changes.label } : {}),
|
|
147
|
+
...(changes.routing !== undefined ? { routing: changes.routing } : {}),
|
|
148
|
+
...(changes.markerEnd !== undefined ? { markerEnd: changes.markerEnd } : {}),
|
|
149
|
+
...(changes.semantic !== undefined ? { style: (0, callman_core_1.semanticStyle)(changes.semantic) } : {}),
|
|
150
|
+
};
|
|
151
|
+
for (const endpoint of [next.source, next.target]) {
|
|
152
|
+
if (endpoint && !nodes.has(endpoint) && !edges.has(endpoint)) {
|
|
153
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_EDGE_ENDPOINT_NOT_FOUND", `Edge endpoint "${endpoint}" does not exist.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
edges.set(op.id, next);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "removeEdge": {
|
|
160
|
+
if (!edges.delete(op.id))
|
|
161
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_EDGE_NOT_FOUND", `Edge "${op.id}" does not exist.`);
|
|
162
|
+
removedEdgeIds.push(op.id);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const document = (0, callman_core_1.normalizeDiagramStyles)({
|
|
168
|
+
...doc,
|
|
169
|
+
meta: { ...doc.meta, title, updatedAt: new Date().toISOString() },
|
|
170
|
+
nodes: [...nodes.values()],
|
|
171
|
+
edges: [...edges.values()],
|
|
172
|
+
});
|
|
173
|
+
const parsed = (0, callman_core_1.safeParseDiagramDocument)(document);
|
|
174
|
+
if (!parsed.ok) {
|
|
175
|
+
throw new errors_js_1.ToolInputError("DIAGRAM_DOCUMENT_INVALID", `The patched document is invalid: ${parsed.errors.join("; ")}`, { errors: parsed.errors });
|
|
176
|
+
}
|
|
177
|
+
return { document: parsed.document, addedNodeIds, removedNodeIds, removedEdgeIds, warnings };
|
|
178
|
+
};
|
|
179
|
+
exports.applyDiagramPatch = applyDiagramPatch;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diagramFullView = exports.diagramGraphView = exports.diagramListView = void 0;
|
|
4
|
+
const callman_core_1 = require("callman-core");
|
|
5
|
+
const truncate_js_1 = require("../../lib/truncate.js");
|
|
6
|
+
// Compact views of a stored diagram: the list row, the graph (what is
|
|
7
|
+
// connected to what, with the edge meaning read back from its style) and
|
|
8
|
+
// the full document behind a size gate.
|
|
9
|
+
const diagramListView = (diagram) => {
|
|
10
|
+
const parsed = (0, callman_core_1.safeParseDiagramDocument)(diagram.document);
|
|
11
|
+
return {
|
|
12
|
+
id: diagram.id,
|
|
13
|
+
name: diagram.name,
|
|
14
|
+
canEdit: diagram.canEdit,
|
|
15
|
+
owner: diagram.owner?.email ?? diagram.owner?.displayName ?? null,
|
|
16
|
+
sharedWorkspaceIds: diagram.sharedWorkspaceIds ?? [],
|
|
17
|
+
editorCount: (diagram.editorIds ?? []).length,
|
|
18
|
+
nodeCount: parsed.ok ? parsed.document.nodes.length : null,
|
|
19
|
+
edgeCount: parsed.ok ? parsed.document.edges.length : null,
|
|
20
|
+
updatedAt: diagram.updatedAt ?? null,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.diagramListView = diagramListView;
|
|
24
|
+
const diagramGraphView = (doc) => ({
|
|
25
|
+
title: doc.meta.title,
|
|
26
|
+
nodes: doc.nodes.map((node) => ({
|
|
27
|
+
id: node.id,
|
|
28
|
+
type: node.type,
|
|
29
|
+
label: node.label ?? null,
|
|
30
|
+
...(node.parentId ? { parent: node.parentId } : {}),
|
|
31
|
+
})),
|
|
32
|
+
edges: doc.edges.map((edge) => ({
|
|
33
|
+
id: edge.id,
|
|
34
|
+
source: edge.source ?? null,
|
|
35
|
+
target: edge.target ?? null,
|
|
36
|
+
label: edge.label ?? null,
|
|
37
|
+
semantic: (0, callman_core_1.semanticFromStyle)(edge.style),
|
|
38
|
+
})),
|
|
39
|
+
});
|
|
40
|
+
exports.diagramGraphView = diagramGraphView;
|
|
41
|
+
const diagramFullView = (doc) => {
|
|
42
|
+
const size = (0, truncate_js_1.byteLength)(doc);
|
|
43
|
+
if (size <= truncate_js_1.LIMITS.DIAGRAM_FULL)
|
|
44
|
+
return { document: doc, truncated: false, bytes: size };
|
|
45
|
+
return {
|
|
46
|
+
document: null,
|
|
47
|
+
truncated: true,
|
|
48
|
+
bytes: size,
|
|
49
|
+
note: `The document is ${size} bytes (limit ${truncate_js_1.LIMITS.DIAGRAM_FULL}). Use view:"graph" or patch_diagram for edits.`,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
exports.diagramFullView = diagramFullView;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.documentPayload = exports.SERVER_DOCUMENT_FORMATS = exports.detectImport = exports.parseYaml = void 0;
|
|
7
|
+
const callman_core_1 = require("callman-core");
|
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
+
const errors_js_1 = require("../client/errors.js");
|
|
10
|
+
// Format detection for `import_content` — core's detector (the same one the
|
|
11
|
+
// desktop's drop-to-import uses) with js-yaml supplied for OpenAPI / Insomnia
|
|
12
|
+
// v5 YAML documents.
|
|
13
|
+
const parseYaml = (text) => js_yaml_1.default.load(text);
|
|
14
|
+
exports.parseYaml = parseYaml;
|
|
15
|
+
const detectImport = (fileName, content) => (0, callman_core_1.detectImportFormat)(fileName ?? "", content, { parseYaml: exports.parseYaml });
|
|
16
|
+
exports.detectImport = detectImport;
|
|
17
|
+
// Formats the server parses from a whole document (sent as-is).
|
|
18
|
+
exports.SERVER_DOCUMENT_FORMATS = new Set(["postman", "openapi", "insomnia", "bruno", "internal"]);
|
|
19
|
+
// The document as the server's parser wants it: JSON documents parsed, YAML
|
|
20
|
+
// documents (OpenAPI / Bruno) forwarded as text — the backend accepts both.
|
|
21
|
+
const documentPayload = (format, content) => {
|
|
22
|
+
const trimmed = content.trimStart();
|
|
23
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(content);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new errors_js_1.ToolInputError("IMPORT_INVALID_JSON", "The content looks like JSON but does not parse.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (format === "openapi" || format === "bruno")
|
|
32
|
+
return content;
|
|
33
|
+
try {
|
|
34
|
+
return js_yaml_1.default.load(content);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new errors_js_1.ToolInputError("IMPORT_INVALID_DOCUMENT", "The content is neither valid JSON nor valid YAML.");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.documentPayload = documentPayload;
|