@particle-academy/agent-integrations 0.26.0 → 0.28.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/dist/bridges/artboard.d.cts +3 -3
- package/dist/bridges/artboard.d.ts +3 -3
- package/dist/bridges/catalog.d.cts +3 -3
- package/dist/bridges/catalog.d.ts +3 -3
- package/dist/bridges/charts.d.cts +3 -3
- package/dist/bridges/charts.d.ts +3 -3
- package/dist/bridges/cms.d.cts +50 -0
- package/dist/bridges/cms.d.ts +50 -0
- package/dist/bridges/code.d.cts +3 -3
- package/dist/bridges/code.d.ts +3 -3
- package/dist/bridges/doc.d.cts +68 -0
- package/dist/bridges/doc.d.ts +68 -0
- package/dist/bridges/features.d.cts +3 -3
- package/dist/bridges/features.d.ts +3 -3
- package/dist/bridges/files.d.cts +3 -3
- package/dist/bridges/files.d.ts +3 -3
- package/dist/bridges/flow.d.cts +3 -3
- package/dist/bridges/flow.d.ts +3 -3
- package/dist/bridges/forms.d.cts +3 -3
- package/dist/bridges/forms.d.ts +3 -3
- package/dist/bridges/map.d.cts +3 -3
- package/dist/bridges/map.d.ts +3 -3
- package/dist/bridges/scene.d.cts +3 -3
- package/dist/bridges/scene.d.ts +3 -3
- package/dist/bridges/screens.d.cts +3 -3
- package/dist/bridges/screens.d.ts +3 -3
- package/dist/bridges/sheets.d.cts +3 -3
- package/dist/bridges/sheets.d.ts +3 -3
- package/dist/bridges/slides.d.cts +3 -3
- package/dist/bridges/slides.d.ts +3 -3
- package/dist/bridges/terminal.d.cts +3 -3
- package/dist/bridges/terminal.d.ts +3 -3
- package/dist/bridges/whiteboard.d.cts +3 -3
- package/dist/bridges/whiteboard.d.ts +3 -3
- package/dist/bridges-artboard.js +1 -1
- package/dist/bridges-catalog.js +2 -2
- package/dist/bridges-charts.js +2 -2
- package/dist/bridges-cms.cjs +437 -0
- package/dist/bridges-cms.cjs.map +1 -0
- package/dist/bridges-cms.js +8 -0
- package/dist/bridges-cms.js.map +1 -0
- package/dist/bridges-code.js +2 -2
- package/dist/bridges-doc.cjs +364 -0
- package/dist/bridges-doc.cjs.map +1 -0
- package/dist/bridges-doc.js +7 -0
- package/dist/bridges-doc.js.map +1 -0
- package/dist/bridges-features.js +2 -2
- package/dist/bridges-files.js +2 -2
- package/dist/bridges-flow.js +1 -1
- package/dist/bridges-forms.js +2 -2
- package/dist/bridges-map.js +2 -2
- package/dist/bridges-scene.js +2 -2
- package/dist/bridges-screens.js +2 -2
- package/dist/bridges-sheets.js +2 -2
- package/dist/bridges-slides.js +2 -2
- package/dist/bridges-terminal.js +2 -2
- package/dist/bridges-whiteboard.js +2 -2
- package/dist/{chunk-HKQBG2HZ.js → chunk-5KLUYF4D.js} +3 -3
- package/dist/{chunk-HKQBG2HZ.js.map → chunk-5KLUYF4D.js.map} +1 -1
- package/dist/{chunk-YMX7G3XM.js → chunk-66WOHZZJ.js} +3 -3
- package/dist/{chunk-YMX7G3XM.js.map → chunk-66WOHZZJ.js.map} +1 -1
- package/dist/chunk-A57CRGEK.js +79 -0
- package/dist/chunk-A57CRGEK.js.map +1 -0
- package/dist/{chunk-XQZGB4FP.js → chunk-AAD3Z5E7.js} +3 -3
- package/dist/{chunk-XQZGB4FP.js.map → chunk-AAD3Z5E7.js.map} +1 -1
- package/dist/{chunk-3QJSOS7G.js → chunk-AAMQOXZC.js} +3 -3
- package/dist/{chunk-3QJSOS7G.js.map → chunk-AAMQOXZC.js.map} +1 -1
- package/dist/{chunk-EP3G4LYW.js → chunk-AROVENCE.js} +3 -3
- package/dist/{chunk-EP3G4LYW.js.map → chunk-AROVENCE.js.map} +1 -1
- package/dist/chunk-FF5F526J.js +245 -0
- package/dist/chunk-FF5F526J.js.map +1 -0
- package/dist/{chunk-57KAMBAR.js → chunk-HWVVS6HE.js} +3 -3
- package/dist/{chunk-57KAMBAR.js.map → chunk-HWVVS6HE.js.map} +1 -1
- package/dist/{chunk-FUI7KXE7.js → chunk-KMSRG5KH.js} +35 -2
- package/dist/chunk-KMSRG5KH.js.map +1 -0
- package/dist/{chunk-QDF37J3V.js → chunk-NN3ELTVO.js} +3 -3
- package/dist/{chunk-QDF37J3V.js.map → chunk-NN3ELTVO.js.map} +1 -1
- package/dist/{chunk-775LJJTJ.js → chunk-PCW2EK5G.js} +3 -3
- package/dist/{chunk-775LJJTJ.js.map → chunk-PCW2EK5G.js.map} +1 -1
- package/dist/{chunk-46H4C5AP.js → chunk-QDD4WHIV.js} +3 -3
- package/dist/{chunk-46H4C5AP.js.map → chunk-QDD4WHIV.js.map} +1 -1
- package/dist/{chunk-V5BXBX7U.js → chunk-QRDVJW6Q.js} +3 -3
- package/dist/{chunk-V5BXBX7U.js.map → chunk-QRDVJW6Q.js.map} +1 -1
- package/dist/{chunk-267JS64O.js → chunk-VFKO2VUR.js} +3 -3
- package/dist/{chunk-267JS64O.js.map → chunk-VFKO2VUR.js.map} +1 -1
- package/dist/{chunk-CLFDQ2BW.js → chunk-XMMCSQ4I.js} +3 -3
- package/dist/{chunk-CLFDQ2BW.js.map → chunk-XMMCSQ4I.js.map} +1 -1
- package/dist/{chunk-K3S6WSHZ.js → chunk-YGD2VTUM.js} +3 -3
- package/dist/{chunk-K3S6WSHZ.js.map → chunk-YGD2VTUM.js.map} +1 -1
- package/dist/{chunk-NKRSLCS7.js → chunk-ZX6UQURN.js} +3 -3
- package/dist/{chunk-NKRSLCS7.js.map → chunk-ZX6UQURN.js.map} +1 -1
- package/dist/components-shared-whiteboard.cjs +32 -0
- package/dist/components-shared-whiteboard.cjs.map +1 -1
- package/dist/components-shared-whiteboard.js +4 -4
- package/dist/index.cjs +376 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +54 -29
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.cts +5 -5
- package/dist/mcp/index.d.ts +5 -5
- package/dist/presence/index.d.cts +1 -1
- package/dist/presence/index.d.ts +1 -1
- package/dist/{server-BsSwfemr.d.cts → server-Dr3j48CU.d.cts} +2 -2
- package/dist/{server-Du3-IGqM.d.ts → server-FFZpYPyM.d.ts} +2 -2
- package/dist/sharing/index.d.cts +4 -3
- package/dist/sharing/index.d.ts +4 -3
- package/dist/sharing.cjs +32 -0
- package/dist/sharing.cjs.map +1 -1
- package/dist/sharing.js +2 -1
- package/dist/sheets-adapter.d.cts +3 -3
- package/dist/sheets-adapter.d.ts +3 -3
- package/dist/{tool-host-C8JMMGYq.d.ts → tool-host-C_Vh17J_.d.ts} +1 -1
- package/dist/{tool-host-BQuUygLF.d.cts → tool-host-IDecPrF1.d.cts} +1 -1
- package/dist/{types-CCSBGW9T.d.cts → types-B0rmWyoR.d.cts} +1 -1
- package/dist/{types-aOQLTW0E.d.cts → types-BDI_g5UG.d.cts} +1 -1
- package/dist/{types-aOQLTW0E.d.ts → types-BDI_g5UG.d.ts} +1 -1
- package/dist/{types-DIVNcIQO.d.ts → types-CBoQhR8L.d.ts} +1 -1
- package/dist/undo/index.d.cts +2 -2
- package/dist/undo/index.d.ts +2 -2
- package/package.json +23 -2
- package/dist/chunk-FUI7KXE7.js.map +0 -1
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyAutoCommon = require('@particle-academy/fancy-auto-common');
|
|
4
|
+
var fancyDocCommons = require('@particle-academy/fancy-doc-commons');
|
|
5
|
+
|
|
6
|
+
// src/mcp/server.ts
|
|
7
|
+
function textResult(text, structured) {
|
|
8
|
+
return {
|
|
9
|
+
content: [{ type: "text", text }],
|
|
10
|
+
...structured !== void 0 ? { structuredContent: structured } : {}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function errorResult(text) {
|
|
14
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/presence/wrap-tool-with-activity.ts
|
|
18
|
+
function wrapToolWithActivity(handler, options) {
|
|
19
|
+
return async (args) => {
|
|
20
|
+
const result = await handler(args);
|
|
21
|
+
if (result.isError) return result;
|
|
22
|
+
let target;
|
|
23
|
+
if (options.resolveTarget) {
|
|
24
|
+
target = options.resolveTarget({ toolName: options.toolName, args, result });
|
|
25
|
+
} else {
|
|
26
|
+
target = { kind: options.kind, screenId: options.screenId };
|
|
27
|
+
}
|
|
28
|
+
if (!target) return result;
|
|
29
|
+
fancyAutoCommon.emitActivity({
|
|
30
|
+
agentId: options.agent.id,
|
|
31
|
+
agentName: options.agent.name,
|
|
32
|
+
agentColor: options.agent.color,
|
|
33
|
+
target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },
|
|
34
|
+
action: options.toolName,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
meta: extractMeta(result),
|
|
37
|
+
ttlMs: options.ttlMs
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function extractMeta(result) {
|
|
43
|
+
const sc = result.structuredContent;
|
|
44
|
+
if (sc && typeof sc === "object" && !Array.isArray(sc)) {
|
|
45
|
+
return sc;
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/undo/undo-tools.ts
|
|
51
|
+
var installedHosts = /* @__PURE__ */ new WeakSet();
|
|
52
|
+
function ensureUndoToolsRegistered(host, options = {}) {
|
|
53
|
+
if (installedHosts.has(host)) return;
|
|
54
|
+
installedHosts.add(host);
|
|
55
|
+
registerUndoTools(host, options);
|
|
56
|
+
}
|
|
57
|
+
function registerUndoTools(host, options = {}) {
|
|
58
|
+
const defaultAgent = options.defaultAgentId ?? "agent";
|
|
59
|
+
const disposers = [];
|
|
60
|
+
const agentOf = (args) => typeof args?.agentId === "string" ? args.agentId : defaultAgent;
|
|
61
|
+
disposers.push(
|
|
62
|
+
host.registerTool(
|
|
63
|
+
{
|
|
64
|
+
name: "agent_undo",
|
|
65
|
+
description: "Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: { agentId: { type: "string" } },
|
|
69
|
+
additionalProperties: false
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
async (args) => {
|
|
73
|
+
const entry = await fancyAutoCommon.undoOne(agentOf(args));
|
|
74
|
+
if (!entry) return errorResult("Nothing to undo.");
|
|
75
|
+
return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
disposers.push(
|
|
80
|
+
host.registerTool(
|
|
81
|
+
{
|
|
82
|
+
name: "agent_redo",
|
|
83
|
+
description: "Redo the most recently undone action.",
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: { agentId: { type: "string" } },
|
|
87
|
+
additionalProperties: false
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
async (args) => {
|
|
91
|
+
const entry = await fancyAutoCommon.redoOne(agentOf(args));
|
|
92
|
+
if (!entry) return errorResult("Nothing to redo.");
|
|
93
|
+
return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
disposers.push(
|
|
98
|
+
host.registerTool(
|
|
99
|
+
{
|
|
100
|
+
name: "agent_history",
|
|
101
|
+
description: "List the agent's undo stack (oldest first). Useful for understanding what's reversible.",
|
|
102
|
+
inputSchema: {
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: { agentId: { type: "string" } },
|
|
105
|
+
additionalProperties: false
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async (args) => {
|
|
109
|
+
const history = fancyAutoCommon.readHistory(agentOf(args)).map(serialize);
|
|
110
|
+
const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join("\n");
|
|
111
|
+
return textResult(text || "(empty)", history);
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
return () => disposers.forEach((d) => d());
|
|
116
|
+
}
|
|
117
|
+
function serialize(entry) {
|
|
118
|
+
return {
|
|
119
|
+
timestamp: entry.timestamp,
|
|
120
|
+
bridgeId: entry.bridgeId,
|
|
121
|
+
action: entry.action,
|
|
122
|
+
label: entry.label
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
126
|
+
function registerDocBridge(host, options) {
|
|
127
|
+
const { adapter, surface } = options;
|
|
128
|
+
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
129
|
+
const reducer = options.reducer ?? fancyDocCommons.treeReducer();
|
|
130
|
+
const stage = options.stagePolicy ?? fancyDocCommons.autoApply;
|
|
131
|
+
const makeNode = options.makeNode ?? (({ id, type, parent, order }, props) => ({ id, type, parent, order, props }));
|
|
132
|
+
const describeNode = options.describeNode ?? ((n) => ({ id: n.id, type: n.type, parent: n.parent, props: Object.keys(n.props ?? {}) }));
|
|
133
|
+
const disposers = [];
|
|
134
|
+
ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
|
|
135
|
+
let idSeq = 0;
|
|
136
|
+
const mintId = () => adapter.newId?.() ?? `${surface}-${idSeq += 1}`;
|
|
137
|
+
const target = (elementId) => ({ kind: surface, screenId: adapter.screenId, elementId });
|
|
138
|
+
const pending = /* @__PURE__ */ new Map();
|
|
139
|
+
function commit(op, label, targetId) {
|
|
140
|
+
const prev = adapter.get();
|
|
141
|
+
const next = reducer.reduce(prev, op);
|
|
142
|
+
adapter.set(next);
|
|
143
|
+
fancyAutoCommon.pushUndoEntry(agent.id, {
|
|
144
|
+
timestamp: Date.now(),
|
|
145
|
+
bridgeId: surface,
|
|
146
|
+
action: label,
|
|
147
|
+
label,
|
|
148
|
+
undo: () => adapter.set(prev),
|
|
149
|
+
redo: () => adapter.set(next)
|
|
150
|
+
});
|
|
151
|
+
return { ok: true, id: targetId };
|
|
152
|
+
}
|
|
153
|
+
function submit(op, label, targetId) {
|
|
154
|
+
if (stage(op) === "confirm") {
|
|
155
|
+
const id = `${surface}-pending-${idSeq += 1}`;
|
|
156
|
+
pending.set(id, { op, label, targetId });
|
|
157
|
+
options.onPending?.({ id, op, label });
|
|
158
|
+
return { staged: true, id };
|
|
159
|
+
}
|
|
160
|
+
commit(op, label, targetId);
|
|
161
|
+
return { staged: false, id: targetId };
|
|
162
|
+
}
|
|
163
|
+
const reg = (verb, description, properties, required, handler, isMutation, resolveTarget) => {
|
|
164
|
+
const name = `${surface}_${verb}`;
|
|
165
|
+
const wrapped = async (args) => {
|
|
166
|
+
try {
|
|
167
|
+
const { _text, ...structured } = await handler(args);
|
|
168
|
+
return textResult(typeof _text === "string" ? _text : name, structured);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return errorResult(e instanceof Error ? e.message : String(e));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const final = isMutation ? wrapToolWithActivity(wrapped, {
|
|
174
|
+
toolName: name,
|
|
175
|
+
agent,
|
|
176
|
+
kind: surface,
|
|
177
|
+
screenId: adapter.screenId,
|
|
178
|
+
resolveTarget: ({ args, result }) => {
|
|
179
|
+
if (result.structuredContent?.staged) return null;
|
|
180
|
+
return resolveTarget?.(args, result.structuredContent ?? {}) ?? target();
|
|
181
|
+
}
|
|
182
|
+
}) : wrapped;
|
|
183
|
+
disposers.push(
|
|
184
|
+
host.registerTool(
|
|
185
|
+
{ name, description, inputSchema: { type: "object", properties, required, additionalProperties: false } },
|
|
186
|
+
final
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
reg(
|
|
191
|
+
"describe",
|
|
192
|
+
`Summarize the ${surface} document: node count, roots, and the active surface. Call before reading or writing.`,
|
|
193
|
+
{},
|
|
194
|
+
[],
|
|
195
|
+
() => {
|
|
196
|
+
const tree = adapter.get();
|
|
197
|
+
const ids = Object.keys(tree.nodes);
|
|
198
|
+
return { nodeCount: ids.length, roots: fancyDocCommons.childrenOf(tree, null).map((n) => n.id), _text: `${ids.length} nodes` };
|
|
199
|
+
},
|
|
200
|
+
false
|
|
201
|
+
);
|
|
202
|
+
reg(
|
|
203
|
+
"get",
|
|
204
|
+
`Get the whole ${surface} document tree as JSON.`,
|
|
205
|
+
{},
|
|
206
|
+
[],
|
|
207
|
+
() => ({ tree: adapter.get(), _text: "full tree" }),
|
|
208
|
+
false
|
|
209
|
+
);
|
|
210
|
+
reg(
|
|
211
|
+
"list",
|
|
212
|
+
"List nodes (optionally the children of `parent`), in order.",
|
|
213
|
+
{ parent: { type: ["string", "null"], description: "Parent id, or null/omitted for roots." } },
|
|
214
|
+
[],
|
|
215
|
+
(args) => {
|
|
216
|
+
const tree = adapter.get();
|
|
217
|
+
const parent = typeof args.parent === "string" ? args.parent : null;
|
|
218
|
+
return { nodes: fancyDocCommons.childrenOf(tree, parent).map(describeNode), _text: `children of ${parent ?? "root"}` };
|
|
219
|
+
},
|
|
220
|
+
false
|
|
221
|
+
);
|
|
222
|
+
reg(
|
|
223
|
+
"get_node",
|
|
224
|
+
"Get one node by id.",
|
|
225
|
+
{ id: { type: "string" } },
|
|
226
|
+
["id"],
|
|
227
|
+
(args) => {
|
|
228
|
+
const node = adapter.get().nodes[String(args.id)];
|
|
229
|
+
if (!node) throw new Error(`No node ${args.id}`);
|
|
230
|
+
return { node, _text: `node ${node.id}` };
|
|
231
|
+
},
|
|
232
|
+
false
|
|
233
|
+
);
|
|
234
|
+
reg(
|
|
235
|
+
"add",
|
|
236
|
+
"Insert a node. Returns its id. Appends under `parent` (or roots) unless `order` is given.",
|
|
237
|
+
{
|
|
238
|
+
type: { type: "string", description: "Node type discriminant." },
|
|
239
|
+
parent: { type: ["string", "null"], description: "Parent id, or null for a root." },
|
|
240
|
+
props: { type: "object", description: "JSON props bag." },
|
|
241
|
+
order: { type: "string", description: "Fractional order key (default: append)." }
|
|
242
|
+
},
|
|
243
|
+
["type"],
|
|
244
|
+
(args) => {
|
|
245
|
+
const tree = adapter.get();
|
|
246
|
+
const parent = typeof args.parent === "string" ? args.parent : null;
|
|
247
|
+
const id = mintId();
|
|
248
|
+
const order = typeof args.order === "string" ? args.order : fancyDocCommons.appendOrder(tree, parent);
|
|
249
|
+
const props = args.props && typeof args.props === "object" ? args.props : {};
|
|
250
|
+
const node = makeNode({ id, type: String(args.type), parent, order }, props);
|
|
251
|
+
const res = submit({ t: "insert", node }, `add ${args.type} ${id}`, id);
|
|
252
|
+
return { ...res, _text: res.staged ? `staged add ${id}` : `added ${id}` };
|
|
253
|
+
},
|
|
254
|
+
true,
|
|
255
|
+
(_args, result) => target(result.id)
|
|
256
|
+
);
|
|
257
|
+
reg(
|
|
258
|
+
"update",
|
|
259
|
+
"Merge a props patch into a node.",
|
|
260
|
+
{ id: { type: "string" }, patch: { type: "object" } },
|
|
261
|
+
["id", "patch"],
|
|
262
|
+
(args) => {
|
|
263
|
+
const id = String(args.id);
|
|
264
|
+
if (!adapter.get().nodes[id]) throw new Error(`No node ${id}`);
|
|
265
|
+
const patch = args.patch && typeof args.patch === "object" ? args.patch : {};
|
|
266
|
+
const res = submit({ t: "set_props", id, patch }, `update ${id}`, id);
|
|
267
|
+
return { ...res, id, _text: res.staged ? `staged update ${id}` : `updated ${id}` };
|
|
268
|
+
},
|
|
269
|
+
true,
|
|
270
|
+
(args) => target(String(args.id))
|
|
271
|
+
);
|
|
272
|
+
reg(
|
|
273
|
+
"remove",
|
|
274
|
+
"Remove a node and its subtree.",
|
|
275
|
+
{ id: { type: "string" } },
|
|
276
|
+
["id"],
|
|
277
|
+
(args) => {
|
|
278
|
+
const id = String(args.id);
|
|
279
|
+
const tree = adapter.get();
|
|
280
|
+
if (!tree.nodes[id]) throw new Error(`No node ${id}`);
|
|
281
|
+
const count = fancyDocCommons.descendantsOf(tree, id).length + 1;
|
|
282
|
+
const res = submit({ t: "remove", id }, `remove ${id} (${count} node${count === 1 ? "" : "s"})`, id);
|
|
283
|
+
return { ...res, id, removed: count, _text: res.staged ? `staged remove ${id}` : `removed ${id}` };
|
|
284
|
+
},
|
|
285
|
+
true,
|
|
286
|
+
(args) => target(String(args.id))
|
|
287
|
+
);
|
|
288
|
+
reg(
|
|
289
|
+
"move",
|
|
290
|
+
"Reparent + reorder a node.",
|
|
291
|
+
{ id: { type: "string" }, parent: { type: ["string", "null"] }, order: { type: "string", description: "Fractional order key (default: append under the new parent)." } },
|
|
292
|
+
["id"],
|
|
293
|
+
(args) => {
|
|
294
|
+
const id = String(args.id);
|
|
295
|
+
const tree = adapter.get();
|
|
296
|
+
if (!tree.nodes[id]) throw new Error(`No node ${id}`);
|
|
297
|
+
const parent = args.parent === null ? null : typeof args.parent === "string" ? args.parent : tree.nodes[id].parent;
|
|
298
|
+
const order = typeof args.order === "string" ? args.order : fancyDocCommons.appendOrder(tree, parent);
|
|
299
|
+
const res = submit({ t: "move", id, parent, order }, `move ${id}`, id);
|
|
300
|
+
return { ...res, id, _text: res.staged ? `staged move ${id}` : `moved ${id}` };
|
|
301
|
+
},
|
|
302
|
+
true,
|
|
303
|
+
(args) => target(String(args.id))
|
|
304
|
+
);
|
|
305
|
+
for (const t of options.opTools ?? []) {
|
|
306
|
+
reg(
|
|
307
|
+
t.verb,
|
|
308
|
+
t.description,
|
|
309
|
+
t.properties,
|
|
310
|
+
t.required,
|
|
311
|
+
(args) => {
|
|
312
|
+
const built = t.build(args, adapter.get());
|
|
313
|
+
if (built && typeof built === "object" && "error" in built) throw new Error(built.error);
|
|
314
|
+
const tid = t.targetId?.(args);
|
|
315
|
+
const res = submit(built, `${t.verb} ${tid ?? ""}`.trim(), tid);
|
|
316
|
+
return { ...res, id: tid, _text: res.staged ? `staged ${t.verb}` : t.verb };
|
|
317
|
+
},
|
|
318
|
+
true,
|
|
319
|
+
(args) => target(t.targetId?.(args))
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
reg(
|
|
323
|
+
"confirm",
|
|
324
|
+
"Apply a staged op by its pending id (from a staged mutation).",
|
|
325
|
+
{ id: { type: "string" } },
|
|
326
|
+
["id"],
|
|
327
|
+
(args) => {
|
|
328
|
+
const id = String(args.id);
|
|
329
|
+
const p = pending.get(id);
|
|
330
|
+
if (!p) throw new Error(`No pending op ${id}`);
|
|
331
|
+
pending.delete(id);
|
|
332
|
+
commit(p.op, p.label, p.targetId);
|
|
333
|
+
return { ok: true, applied: p.label, id: p.targetId, _text: `applied ${p.label}` };
|
|
334
|
+
},
|
|
335
|
+
true,
|
|
336
|
+
(_args, result) => target(result.id)
|
|
337
|
+
);
|
|
338
|
+
reg(
|
|
339
|
+
"reject",
|
|
340
|
+
"Discard a staged op by its pending id.",
|
|
341
|
+
{ id: { type: "string" } },
|
|
342
|
+
["id"],
|
|
343
|
+
(args) => {
|
|
344
|
+
const id = String(args.id);
|
|
345
|
+
const p = pending.get(id);
|
|
346
|
+
if (!p) throw new Error(`No pending op ${id}`);
|
|
347
|
+
pending.delete(id);
|
|
348
|
+
return { ok: true, rejected: p.label, _text: `rejected ${p.label}` };
|
|
349
|
+
},
|
|
350
|
+
false
|
|
351
|
+
);
|
|
352
|
+
return {
|
|
353
|
+
id: surface,
|
|
354
|
+
title: surface,
|
|
355
|
+
dispose: () => {
|
|
356
|
+
for (const d of disposers) d();
|
|
357
|
+
pending.clear();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function cmsReducer() {
|
|
362
|
+
const base = fancyDocCommons.treeReducer();
|
|
363
|
+
return {
|
|
364
|
+
reduce(doc, op) {
|
|
365
|
+
if (op.t === "set_style") {
|
|
366
|
+
const node = doc.nodes[op.id];
|
|
367
|
+
if (!node) return doc;
|
|
368
|
+
return { nodes: { ...doc.nodes, [op.id]: { ...node, style: { ...node.style, base: { ...node.style.base, ...op.patch } } } } };
|
|
369
|
+
}
|
|
370
|
+
if (op.t === "set_layout") {
|
|
371
|
+
const node = doc.nodes[op.id];
|
|
372
|
+
if (!node) return doc;
|
|
373
|
+
return { nodes: { ...doc.nodes, [op.id]: { ...node, layout: op.layout } } };
|
|
374
|
+
}
|
|
375
|
+
return base.reduce(doc, op);
|
|
376
|
+
},
|
|
377
|
+
invert(doc, op) {
|
|
378
|
+
if (op.t === "set_style") {
|
|
379
|
+
const node = doc.nodes[op.id];
|
|
380
|
+
if (!node) return [];
|
|
381
|
+
const prev = {};
|
|
382
|
+
for (const k in op.patch) prev[k] = node.style.base[k];
|
|
383
|
+
return [{ t: "set_style", id: op.id, patch: prev }];
|
|
384
|
+
}
|
|
385
|
+
if (op.t === "set_layout") {
|
|
386
|
+
const node = doc.nodes[op.id];
|
|
387
|
+
if (!node) return [];
|
|
388
|
+
return [{ t: "set_layout", id: op.id, layout: node.layout }];
|
|
389
|
+
}
|
|
390
|
+
return base.invert(doc, op);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function registerCmsBridge(host, options) {
|
|
395
|
+
return registerDocBridge(host, {
|
|
396
|
+
adapter: options.adapter,
|
|
397
|
+
surface: "cms",
|
|
398
|
+
agent: options.agent,
|
|
399
|
+
reducer: cmsReducer(),
|
|
400
|
+
stagePolicy: options.stagePolicy,
|
|
401
|
+
onPending: options.onPending,
|
|
402
|
+
// New nodes get an empty base style so they satisfy StyledNode.
|
|
403
|
+
makeNode: ({ id, type, parent, order }, props) => ({ id, type, parent, order, props, style: { base: {} } }),
|
|
404
|
+
describeNode: (n) => ({ id: n.id, type: n.type, parent: n.parent, layout: n.layout }),
|
|
405
|
+
opTools: [
|
|
406
|
+
{
|
|
407
|
+
verb: "set_style",
|
|
408
|
+
description: "Merge a StyleProps patch into a node's base style (color, background, padding, fontSize, gap, \u2026).",
|
|
409
|
+
properties: { id: { type: "string" }, patch: { type: "object", description: "Partial StyleProps." } },
|
|
410
|
+
required: ["id", "patch"],
|
|
411
|
+
build: (args, tree) => {
|
|
412
|
+
const id = String(args.id);
|
|
413
|
+
if (!tree.nodes[id]) return { error: `No node ${id}` };
|
|
414
|
+
return { t: "set_style", id, patch: args.patch && typeof args.patch === "object" ? args.patch : {} };
|
|
415
|
+
},
|
|
416
|
+
targetId: (args) => String(args.id)
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
verb: "set_layout",
|
|
420
|
+
description: "Set a container node's layout mode (free | stack | grid).",
|
|
421
|
+
properties: { id: { type: "string" }, layout: { type: "string", enum: ["free", "stack", "grid"] } },
|
|
422
|
+
required: ["id"],
|
|
423
|
+
build: (args, tree) => {
|
|
424
|
+
const id = String(args.id);
|
|
425
|
+
if (!tree.nodes[id]) return { error: `No node ${id}` };
|
|
426
|
+
return { t: "set_layout", id, layout: args.layout };
|
|
427
|
+
},
|
|
428
|
+
targetId: (args) => String(args.id)
|
|
429
|
+
}
|
|
430
|
+
]
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
exports.cmsReducer = cmsReducer;
|
|
435
|
+
exports.registerCmsBridge = registerCmsBridge;
|
|
436
|
+
//# sourceMappingURL=bridges-cms.cjs.map
|
|
437
|
+
//# sourceMappingURL=bridges-cms.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp/server.ts","../src/presence/wrap-tool-with-activity.ts","../src/undo/undo-tools.ts","../src/bridges/doc.ts","../src/bridges/cms.ts"],"names":["emitActivity","undoOne","redoOne","readHistory","treeReducer","autoApply","pushUndoEntry","childrenOf","appendOrder","descendantsOf"],"mappings":";;;;;;AAgLO,SAAS,UAAA,CAAW,MAAc,UAAA,EAAkC;AACzE,EAAA,OAAO;AAAA,IACL,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,CAAA;AAAA,IAChC,GAAI,UAAA,KAAe,MAAA,GAAY,EAAE,iBAAA,EAAmB,UAAA,KAAe;AAAC,GACtE;AACF;AAEO,SAAS,YAAY,IAAA,EAA8B;AACxD,EAAA,OAAO,EAAE,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ,IAAA,EAAM,CAAA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EAAI,EAAE,IAAA,EAAM,UAAS,EAAG,MAAA,EAAQ,EAAE,IAAA,EAAM,UAAU,IAAA,EAAM,CAAC,QAAQ,OAAA,EAAS,MAAM,GAAE,EAAE;AAAA,QAClG,QAAA,EAAU,CAAC,IAAI,CAAA;AAAA,QACf,KAAA,EAAO,CAAC,IAAA,EAAM,IAAA,KAAS;AACrB,UAAA,MAAM,EAAA,GAAK,MAAA,CAAO,IAAA,CAAK,EAAE,CAAA;AACzB,UAAA,IAAI,CAAC,IAAA,CAAK,KAAA,CAAM,EAAE,CAAA,SAAU,EAAE,KAAA,EAAO,CAAA,QAAA,EAAW,EAAE,CAAA,CAAA,EAAG;AACrD,UAAA,OAAO,EAAE,CAAA,EAAG,YAAA,EAAc,EAAA,EAAI,MAAA,EAAQ,KAAK,MAAA,EAAiC;AAAA,QAC9E,CAAA;AAAA,QACA,QAAA,EAAU,CAAC,IAAA,KAAS,MAAA,CAAO,KAAK,EAAE;AAAA;AACpC;AACF,GACD,CAAA;AACH","file":"bridges-cms.cjs","sourcesContent":["import {\n type CallToolResult,\n type JsonObject,\n type JsonRpcMessage,\n type JsonRpcRequest,\n type JsonRpcId,\n type RegisteredTool,\n type ServerCapabilities,\n type ServerInfo,\n type ToolDefinition,\n type ToolHandler,\n JSONRPC_INTERNAL_ERROR,\n JSONRPC_INVALID_PARAMS,\n JSONRPC_METHOD_NOT_FOUND,\n MCP_PROTOCOL_VERSION,\n} from \"./types\";\nimport { ToolRegistry } from \"./tool-host\";\n\nexport type McpServerOptions = {\n info: ServerInfo;\n /** Defaults to { tools: { listChanged: true } } */\n capabilities?: ServerCapabilities;\n /** Free-text instructions surfaced to clients during initialize. */\n instructions?: string;\n};\n\nexport type Transport = {\n /** Called by the server when it has a message to deliver to the client. */\n send: (message: JsonRpcMessage) => void;\n /** Called by the server when it's torn down so the transport can clean up. */\n close?: () => void;\n};\n\n/**\n * MicroMcpServer — protocol-level MCP server, transport-agnostic.\n *\n * Use it like:\n *\n * const server = new MicroMcpServer({ info: { name: \"session\", version: \"0.1\" } });\n * server.registerTool({ name: \"...\", inputSchema: { type: \"object\" } }, async (args) => ({...}));\n * const transport = new InProcessTransport();\n * server.attach(transport);\n * transport.deliver({ ... }); // client → server frames\n *\n * The same server can serve multiple transports (e.g. an in-process agent\n * AND a relayed external client) by attaching each one.\n */\nexport class MicroMcpServer extends ToolRegistry {\n private transports = new Set<Transport>();\n private notifyListChangedScheduled = false;\n\n readonly info: ServerInfo;\n readonly capabilities: ServerCapabilities;\n readonly instructions?: string;\n\n constructor(options: McpServerOptions) {\n super();\n this.info = options.info;\n this.capabilities = options.capabilities ?? { tools: { listChanged: true } };\n this.instructions = options.instructions;\n }\n\n attach(transport: Transport): () => void {\n this.transports.add(transport);\n return () => this.detach(transport);\n }\n\n detach(transport: Transport): void {\n if (this.transports.delete(transport)) {\n transport.close?.();\n }\n }\n\n unregisterTool(name: string): void {\n if (this.tools.delete(name)) {\n this.scheduleListChangedNotification();\n }\n }\n\n protected onToolsChanged(): void {\n this.scheduleListChangedNotification();\n }\n\n /**\n * Receive a JSON-RPC frame from a client (called by the transport).\n * The transport is responsible for sending the response back.\n */\n async receive(transport: Transport, message: JsonRpcMessage): Promise<void> {\n if (!(\"method\" in message)) return; // It's a response, not a request — ignore.\n\n const isNotification = !(\"id\" in message);\n if (isNotification) {\n // Notifications are fire-and-forget. We ignore unknown methods.\n return;\n }\n\n const request = message as JsonRpcRequest;\n try {\n const result = await this.handle(request);\n transport.send({ jsonrpc: \"2.0\", id: request.id, result });\n } catch (err) {\n transport.send({\n jsonrpc: \"2.0\",\n id: request.id,\n error: this.toRpcError(err),\n });\n }\n }\n\n private async handle(request: JsonRpcRequest): Promise<any> {\n const { method, params } = request;\n switch (method) {\n case \"initialize\":\n return {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities: this.capabilities,\n serverInfo: this.info,\n ...(this.instructions ? { instructions: this.instructions } : {}),\n };\n\n case \"tools/list\":\n return { tools: this.listTools() };\n\n case \"tools/call\": {\n const name = params?.name;\n const args = (params?.arguments ?? {}) as JsonObject;\n if (typeof name !== \"string\") {\n throw rpcError(JSONRPC_INVALID_PARAMS, \"tools/call requires `name`\");\n }\n const tool = this.tools.get(name);\n if (!tool) {\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unknown tool: ${name}`);\n }\n const result = await tool.handler(args);\n return result satisfies CallToolResult;\n }\n\n case \"ping\":\n return {};\n\n default:\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);\n }\n }\n\n private scheduleListChangedNotification(): void {\n if (this.notifyListChangedScheduled) return;\n this.notifyListChangedScheduled = true;\n queueMicrotask(() => {\n this.notifyListChangedScheduled = false;\n this.broadcast({ jsonrpc: \"2.0\", method: \"notifications/tools/list_changed\" });\n });\n }\n\n private broadcast(message: JsonRpcMessage): void {\n for (const t of this.transports) t.send(message);\n }\n\n private toRpcError(err: unknown): { code: number; message: string; data?: any } {\n if (err && typeof err === \"object\" && \"code\" in err && \"message\" in err) {\n return err as any;\n }\n return {\n code: JSONRPC_INTERNAL_ERROR,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nexport function rpcError(code: number, message: string, data?: any) {\n return { code, message, ...(data !== undefined ? { data } : {}) };\n}\n\n/**\n * Helper to build a CallToolResult from a string or structured value.\n */\nexport function textResult(text: string, structured?: any): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n ...(structured !== undefined ? { structuredContent: structured } : {}),\n };\n}\n\nexport function errorResult(text: string): CallToolResult {\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n// Internal helper so the JsonRpcId import isn't dropped by tsup\ntype _KeepIdImport = JsonRpcId;\n","import type { CallToolResult } from \"../mcp/types\";\nimport { emitActivity } from \"./registry\";\nimport type { AgentTarget } from \"./types\";\n\nexport type ActivityAgent = { id: string; name?: string; color?: string };\n\nexport type ActivityResolverContext<TArgs = Record<string, unknown>> = {\n /** Tool name as registered. */\n toolName: string;\n /** Arguments the tool was called with. */\n args: TArgs;\n /** The CallToolResult the underlying handler produced. */\n result: CallToolResult;\n};\n\n/**\n * Resolves an `AgentTarget` for an executed tool. Bridges declare one of\n * these per registration so the wrapper knows which surface / element /\n * screen the activity belongs to.\n *\n * The resolver runs AFTER the tool handler so it can inspect the result\n * (e.g. read a newly-created item id from `structuredContent`).\n */\nexport type ActivityTargetResolver<TArgs = Record<string, unknown>> = (\n ctx: ActivityResolverContext<TArgs>,\n) => AgentTarget | null;\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n) => Promise<CallToolResult> | CallToolResult;\n\n/**\n * wrapToolWithActivity — decorate a bridge tool handler so every successful\n * call emits an `AgentActivityEvent`. Returns a new handler with the same shape.\n *\n * Usage in a bridge:\n *\n * server.registerTool(\n * definition,\n * wrapToolWithActivity(\n * handler,\n * { agent, kind: \"whiteboard\", resolveTarget: ({ args }) => ({\n * kind: \"whiteboard\", elementId: args.id as string,\n * }) },\n * ),\n * );\n */\nexport function wrapToolWithActivity<TArgs = Record<string, unknown>>(\n handler: ToolHandler<TArgs>,\n options: {\n toolName: string;\n agent: ActivityAgent;\n /** Optional fancy-screens screen id this bridge is scoped to. */\n screenId?: string;\n /** Default target kind if the resolver returns one without `kind`. */\n kind: AgentTarget[\"kind\"];\n /** Per-call resolver. Return `null` to skip emitting (e.g. for read-only tools). */\n resolveTarget?: ActivityTargetResolver<TArgs>;\n /** Optional ttl override. */\n ttlMs?: number;\n },\n): ToolHandler<TArgs> {\n return async (args) => {\n const result = await handler(args);\n if (result.isError) return result;\n\n let target: AgentTarget | null;\n if (options.resolveTarget) {\n target = options.resolveTarget({ toolName: options.toolName, args, result });\n } else {\n target = { kind: options.kind, screenId: options.screenId };\n }\n if (!target) return result;\n\n emitActivity({\n agentId: options.agent.id,\n agentName: options.agent.name,\n agentColor: options.agent.color,\n target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },\n action: options.toolName,\n timestamp: Date.now(),\n meta: extractMeta(result),\n ttlMs: options.ttlMs,\n });\n return result;\n };\n}\n\nfunction extractMeta(result: CallToolResult): Record<string, unknown> | undefined {\n const sc = result.structuredContent;\n if (sc && typeof sc === \"object\" && !Array.isArray(sc)) {\n return sc as Record<string, unknown>;\n }\n return undefined;\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport { readHistory, redoOne, undoOne } from \"./undo-stack\";\n\nexport type UndoToolsOptions = {\n /** Default agent id when the caller doesn't pass one. */\n defaultAgentId?: string;\n};\n\n/**\n * Idempotent tracker so multiple bridges on the same server only register\n * agent_undo / agent_redo / agent_history once.\n */\nconst installedHosts = new WeakSet<ToolHost>();\n\n/**\n * ensureUndoToolsRegistered — bridges call this on construction. Safe to\n * call repeatedly with the same server; subsequent calls are no-ops.\n */\nexport function ensureUndoToolsRegistered(host: ToolHost, options: UndoToolsOptions = {}): void {\n if (installedHosts.has(host)) return;\n installedHosts.add(host);\n registerUndoTools(host, options);\n}\n\n/**\n * registerUndoTools — add agent_undo / agent_redo / agent_history to the\n * server. Returns a disposer that unregisters all three.\n */\nexport function registerUndoTools(host: ToolHost, options: UndoToolsOptions = {}): () => void {\n const defaultAgent = options.defaultAgentId ?? \"agent\";\n const disposers: Array<() => void> = [];\n const agentOf = (args: any): string =>\n typeof args?.agentId === \"string\" ? args.agentId : defaultAgent;\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_undo\",\n description: \"Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await undoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to undo.\");\n return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_redo\",\n description: \"Redo the most recently undone action.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await redoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to redo.\");\n return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_history\",\n description: \"List the agent's undo stack (oldest first). Useful for understanding what's reversible.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const history = readHistory(agentOf(args)).map(serialize);\n const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join(\"\\n\");\n return textResult(text || \"(empty)\", history);\n },\n ),\n );\n\n return () => disposers.forEach((d) => d());\n}\n\nfunction serialize(entry: import(\"./undo-stack\").UndoEntry) {\n return {\n timestamp: entry.timestamp,\n bridgeId: entry.bridgeId,\n action: entry.action,\n label: entry.label,\n };\n}\n","/**\n * registerDocBridge — a GENERIC MCP bridge over a `@particle-academy/fancy-doc-commons`\n * `DocTree`. Give it an adapter (`{ get, set }`) and it generates, from the shared\n * op-spine, a full Human+ surface: uniform read tools + the canonical node op tools\n * (add / update / remove / move) under one verb lexicon, with **undo derived from\n * the reducer**, agent-activity broadcasts, unconditional `agent_undo/redo/history`,\n * and an optional **staged-write** (confirm / reject) channel — replacing the ~500-line\n * bespoke bridges (whiteboard/flow/artboard/…) with one builder. A surface adds its\n * domain ops (e.g. cms `set_style`) via `opTools` + a matching reducer.\n */\nimport { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport {\n treeReducer,\n childrenOf,\n descendantsOf,\n appendOrder,\n autoApply,\n type DocTree,\n type DocNode,\n type TreeOp,\n type DocReducer,\n type StagePolicy,\n} from \"@particle-academy/fancy-doc-commons\";\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\n/** Host-provided access to the document tree. */\nexport interface DocAdapter<N extends DocNode> {\n /** Read the current tree. */\n get(): DocTree<N>;\n /** Replace the tree — host wires this to its `onChange` / `setState`. */\n set(next: DocTree<N>): void;\n /** Optional fancy-screens screen id, for presence scoping. */\n screenId?: string;\n /** Mint a fresh, unique node id. Default: `<surface>-<n>`. */\n newId?(): string;\n}\n\n/**\n * A domain op tool beyond the built-in add/update/remove/move — lets a surface\n * expose its own ops (e.g. cms `set_style`) through the same undo + activity path.\n */\nexport interface DocOpTool<N extends DocNode, TOp> {\n /** Verb, prefixed with the surface (e.g. `set_style` → `cms_set_style`). */\n verb: string;\n description: string;\n properties: Record<string, unknown>;\n required: string[];\n /** Build the op from the args (or return `{ error }`). */\n build(args: JsonObject, tree: DocTree<N>): TOp | { error: string };\n /** Node id this op targets (for the activity target + undo label). */\n targetId?(args: JsonObject): string | undefined;\n}\n\nexport interface DocBridgeOptions<N extends DocNode, TOp = TreeOp<N>> {\n adapter: DocAdapter<N>;\n /** Tool-name prefix + activity kind (e.g. `\"cms\"` → `cms_add`, kind `\"cms\"`). */\n surface: string;\n agent?: { id: string; name?: string; color?: string };\n /** Reducer for reduce + invert. Default: the substrate `treeReducer<N>()`. */\n reducer?: DocReducer<DocTree<N>, TOp>;\n /** Build a full node from the core fields + props (fill surface defaults, e.g. `style`). */\n makeNode?: (core: { id: string; type: string; parent: string | null; order: string }, props: Record<string, unknown>) => N;\n /** Domain op tools beyond the built-ins. */\n opTools?: DocOpTool<N, TOp>[];\n /** Decide auto-apply vs. confirm per op. Default: everything auto-applies. */\n stagePolicy?: StagePolicy<TOp>;\n /** Fired when an op is staged pending human confirmation. */\n onPending?: (staged: { id: string; op: TOp; label: string }) => void;\n /** Summarize a node for describe/list. Default: id/type/parent + prop keys. */\n describeNode?: (node: N) => Record<string, unknown>;\n}\n\n/** Register the generic doc-surface bridge. Returns a {@link Bridge}. */\nexport function registerDocBridge<N extends DocNode, TOp = TreeOp<N>>(\n host: ToolHost,\n options: DocBridgeOptions<N, TOp>,\n): Bridge {\n const { adapter, surface } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const reducer = (options.reducer ?? (treeReducer<N>() as unknown as DocReducer<DocTree<N>, TOp>));\n const stage = options.stagePolicy ?? (autoApply as StagePolicy<TOp>);\n const makeNode =\n options.makeNode ?? (({ id, type, parent, order }, props) => ({ id, type, parent, order, props }) as N);\n const describeNode =\n options.describeNode ?? ((n: N) => ({ id: n.id, type: n.type, parent: n.parent, props: Object.keys(n.props ?? {}) }));\n const disposers: Array<() => void> = [];\n\n // agent_undo / agent_redo / agent_history — always present (undo derives from\n // the reducer, so every doc surface gets working undo for free).\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n let idSeq = 0;\n const mintId = () => adapter.newId?.() ?? `${surface}-${(idSeq += 1)}`;\n const target = (elementId?: string): AgentTarget => ({ kind: surface, screenId: adapter.screenId, elementId });\n\n // Staged ops awaiting confirmation.\n const pending = new Map<string, { op: TOp; label: string; targetId?: string }>();\n\n /** Apply an op immediately: reduce → set → push a snapshot-based undo entry. */\n function commit(op: TOp, label: string, targetId?: string): Record<string, unknown> {\n const prev = adapter.get();\n const next = reducer.reduce(prev, op);\n adapter.set(next);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: surface,\n action: label,\n label,\n undo: () => adapter.set(prev),\n redo: () => adapter.set(next),\n });\n return { ok: true, id: targetId };\n }\n\n /** Auto-apply, or stage for confirmation per the stage policy. */\n function submit(op: TOp, label: string, targetId?: string): { staged: boolean; id?: string } {\n if (stage(op) === \"confirm\") {\n const id = `${surface}-pending-${(idSeq += 1)}`;\n pending.set(id, { op, label, targetId });\n options.onPending?.({ id, op, label });\n return { staged: true, id };\n }\n commit(op, label, targetId);\n return { staged: false, id: targetId };\n }\n\n const reg = (\n verb: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Record<string, unknown> | Promise<Record<string, unknown>>,\n isMutation: boolean,\n resolveTarget?: (args: JsonObject, result: Record<string, unknown>) => AgentTarget | null,\n ): void => {\n const name = `${surface}_${verb}`;\n const wrapped = async (args: JsonObject) => {\n try {\n // `_text` is the human-facing line; the rest is structuredContent.\n const { _text, ...structured } = await handler(args);\n return textResult(typeof _text === \"string\" ? _text : name, structured);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent,\n kind: surface,\n screenId: adapter.screenId,\n resolveTarget: ({ args, result }) => {\n if ((result.structuredContent as JsonObject | undefined)?.staged) return null;\n return resolveTarget?.(args, (result.structuredContent as JsonObject) ?? {}) ?? target();\n },\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n { name, description, inputSchema: { type: \"object\", properties: properties as never, required, additionalProperties: false } },\n final as never,\n ),\n );\n };\n\n // ── Read tools ──────────────────────────────────────────────────────────\n reg(\n \"describe\",\n `Summarize the ${surface} document: node count, roots, and the active surface. Call before reading or writing.`,\n {},\n [],\n () => {\n const tree = adapter.get();\n const ids = Object.keys(tree.nodes);\n return { nodeCount: ids.length, roots: childrenOf(tree, null).map((n) => n.id), _text: `${ids.length} nodes` };\n },\n false,\n );\n reg(\n \"get\",\n `Get the whole ${surface} document tree as JSON.`,\n {},\n [],\n () => ({ tree: adapter.get(), _text: \"full tree\" }),\n false,\n );\n reg(\n \"list\",\n \"List nodes (optionally the children of `parent`), in order.\",\n { parent: { type: [\"string\", \"null\"], description: \"Parent id, or null/omitted for roots.\" } },\n [],\n (args) => {\n const tree = adapter.get();\n const parent = typeof args.parent === \"string\" ? args.parent : null;\n return { nodes: childrenOf(tree, parent).map(describeNode), _text: `children of ${parent ?? \"root\"}` };\n },\n false,\n );\n reg(\n \"get_node\",\n \"Get one node by id.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const node = adapter.get().nodes[String(args.id)];\n if (!node) throw new Error(`No node ${args.id}`);\n return { node, _text: `node ${node.id}` };\n },\n false,\n );\n\n // ── Canonical op tools ──────────────────────────────────────────────────\n reg(\n \"add\",\n \"Insert a node. Returns its id. Appends under `parent` (or roots) unless `order` is given.\",\n {\n type: { type: \"string\", description: \"Node type discriminant.\" },\n parent: { type: [\"string\", \"null\"], description: \"Parent id, or null for a root.\" },\n props: { type: \"object\", description: \"JSON props bag.\" },\n order: { type: \"string\", description: \"Fractional order key (default: append).\" },\n },\n [\"type\"],\n (args) => {\n const tree = adapter.get();\n const parent = typeof args.parent === \"string\" ? args.parent : null;\n const id = mintId();\n const order = typeof args.order === \"string\" ? args.order : appendOrder(tree, parent);\n const props = (args.props && typeof args.props === \"object\" ? args.props : {}) as Record<string, unknown>;\n const node = makeNode({ id, type: String(args.type), parent, order }, props);\n const res = submit({ t: \"insert\", node } as unknown as TOp, `add ${args.type} ${id}`, id);\n return { ...res, _text: res.staged ? `staged add ${id}` : `added ${id}` };\n },\n true,\n (_args, result) => target(result.id as string | undefined),\n );\n reg(\n \"update\",\n \"Merge a props patch into a node.\",\n { id: { type: \"string\" }, patch: { type: \"object\" } },\n [\"id\", \"patch\"],\n (args) => {\n const id = String(args.id);\n if (!adapter.get().nodes[id]) throw new Error(`No node ${id}`);\n const patch = (args.patch && typeof args.patch === \"object\" ? args.patch : {}) as Record<string, unknown>;\n const res = submit({ t: \"set_props\", id, patch } as unknown as TOp, `update ${id}`, id);\n return { ...res, id, _text: res.staged ? `staged update ${id}` : `updated ${id}` };\n },\n true,\n (args) => target(String(args.id)),\n );\n reg(\n \"remove\",\n \"Remove a node and its subtree.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n const tree = adapter.get();\n if (!tree.nodes[id]) throw new Error(`No node ${id}`);\n const count = descendantsOf(tree, id).length + 1;\n const res = submit({ t: \"remove\", id } as unknown as TOp, `remove ${id} (${count} node${count === 1 ? \"\" : \"s\"})`, id);\n return { ...res, id, removed: count, _text: res.staged ? `staged remove ${id}` : `removed ${id}` };\n },\n true,\n (args) => target(String(args.id)),\n );\n reg(\n \"move\",\n \"Reparent + reorder a node.\",\n { id: { type: \"string\" }, parent: { type: [\"string\", \"null\"] }, order: { type: \"string\", description: \"Fractional order key (default: append under the new parent).\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n const tree = adapter.get();\n if (!tree.nodes[id]) throw new Error(`No node ${id}`);\n const parent = args.parent === null ? null : typeof args.parent === \"string\" ? args.parent : tree.nodes[id]!.parent;\n const order = typeof args.order === \"string\" ? args.order : appendOrder(tree, parent);\n const res = submit({ t: \"move\", id, parent, order } as unknown as TOp, `move ${id}`, id);\n return { ...res, id, _text: res.staged ? `staged move ${id}` : `moved ${id}` };\n },\n true,\n (args) => target(String(args.id)),\n );\n\n // ── Domain op tools ─────────────────────────────────────────────────────\n for (const t of options.opTools ?? []) {\n reg(\n t.verb,\n t.description,\n t.properties,\n t.required,\n (args) => {\n const built = t.build(args, adapter.get());\n if (built && typeof built === \"object\" && \"error\" in built) throw new Error((built as { error: string }).error);\n const tid = t.targetId?.(args);\n const res = submit(built as TOp, `${t.verb} ${tid ?? \"\"}`.trim(), tid);\n return { ...res, id: tid, _text: res.staged ? `staged ${t.verb}` : t.verb };\n },\n true,\n (args) => target(t.targetId?.(args)),\n );\n }\n\n // ── Staged-write confirm / reject ───────────────────────────────────────\n reg(\n \"confirm\",\n \"Apply a staged op by its pending id (from a staged mutation).\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n const p = pending.get(id);\n if (!p) throw new Error(`No pending op ${id}`);\n pending.delete(id);\n commit(p.op, p.label, p.targetId);\n return { ok: true, applied: p.label, id: p.targetId, _text: `applied ${p.label}` };\n },\n true,\n (_args, result) => target(result.id as string | undefined),\n );\n reg(\n \"reject\",\n \"Discard a staged op by its pending id.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n const p = pending.get(id);\n if (!p) throw new Error(`No pending op ${id}`);\n pending.delete(id);\n return { ok: true, rejected: p.label, _text: `rejected ${p.label}` };\n },\n false,\n );\n\n return {\n id: surface,\n title: surface,\n dispose: () => {\n for (const d of disposers) d();\n pending.clear();\n },\n };\n}\n","/**\n * registerCmsBridge — the greenfield CMS agent bridge, built entirely on\n * {@link registerDocBridge}. cms had NO bridge before (its op-spine was\n * agent-ready but unwired); this is the §8-decided \"build registerCmsBridge on\n * registerDocBridge BEFORE deprecating ScreenSchema\" step.\n *\n * A CMS page is a `DocTree<StyledNode>` (fancy-doc-commons): the generic bridge\n * supplies `cms_describe/get/list/get_node` + `cms_add/update/remove/move` +\n * undo/activity/staging for free; this layer adds the two domain ops a page\n * needs — `cms_set_style` (per-node base StyleProps) and `cms_set_layout` — and a\n * reducer that handles them alongside the substrate tree ops.\n */\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { Bridge } from \"./types\";\nimport { registerDocBridge, type DocAdapter } from \"./doc\";\nimport {\n treeReducer,\n type DocReducer,\n type DocTree,\n type LayoutMode,\n type StyledNode,\n type StyleProps,\n type TreeOp,\n type StagePolicy,\n} from \"@particle-academy/fancy-doc-commons\";\n\n/** The CMS op union: the substrate tree ops + per-node style/layout. */\nexport type CmsOp =\n | TreeOp<StyledNode>\n | { t: \"set_style\"; id: string; patch: Partial<StyleProps> }\n | { t: \"set_layout\"; id: string; layout?: LayoutMode };\n\n/** A pure reducer over a `DocTree<StyledNode>` handling tree ops + style/layout. */\nexport function cmsReducer(): DocReducer<DocTree<StyledNode>, CmsOp> {\n const base = treeReducer<StyledNode>();\n return {\n reduce(doc, op) {\n if (op.t === \"set_style\") {\n const node = doc.nodes[op.id];\n if (!node) return doc;\n return { nodes: { ...doc.nodes, [op.id]: { ...node, style: { ...node.style, base: { ...node.style.base, ...op.patch } } } } };\n }\n if (op.t === \"set_layout\") {\n const node = doc.nodes[op.id];\n if (!node) return doc;\n return { nodes: { ...doc.nodes, [op.id]: { ...node, layout: op.layout } } };\n }\n return base.reduce(doc, op);\n },\n invert(doc, op) {\n if (op.t === \"set_style\") {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const prev: Partial<StyleProps> = {};\n for (const k in op.patch) (prev as Record<string, unknown>)[k as keyof StyleProps] = node.style.base[k as keyof StyleProps];\n return [{ t: \"set_style\", id: op.id, patch: prev }];\n }\n if (op.t === \"set_layout\") {\n const node = doc.nodes[op.id];\n if (!node) return [];\n return [{ t: \"set_layout\", id: op.id, layout: node.layout }];\n }\n return base.invert(doc, op) as CmsOp[];\n },\n };\n}\n\nexport interface CmsBridgeOptions {\n adapter: DocAdapter<StyledNode>;\n agent?: { id: string; name?: string; color?: string };\n /** Auto-apply vs. confirm per op (trust-but-verify). Default: auto. */\n stagePolicy?: StagePolicy<CmsOp>;\n onPending?: (staged: { id: string; op: CmsOp; label: string }) => void;\n}\n\n/** Register the CMS bridge (prefix `cms_`) over a `DocTree<StyledNode>`. */\nexport function registerCmsBridge(host: ToolHost, options: CmsBridgeOptions): Bridge {\n return registerDocBridge<StyledNode, CmsOp>(host, {\n adapter: options.adapter,\n surface: \"cms\",\n agent: options.agent,\n reducer: cmsReducer(),\n stagePolicy: options.stagePolicy,\n onPending: options.onPending,\n // New nodes get an empty base style so they satisfy StyledNode.\n makeNode: ({ id, type, parent, order }, props) => ({ id, type, parent, order, props, style: { base: {} } }),\n describeNode: (n) => ({ id: n.id, type: n.type, parent: n.parent, layout: n.layout }),\n opTools: [\n {\n verb: \"set_style\",\n description: \"Merge a StyleProps patch into a node's base style (color, background, padding, fontSize, gap, …).\",\n properties: { id: { type: \"string\" }, patch: { type: \"object\", description: \"Partial StyleProps.\" } },\n required: [\"id\", \"patch\"],\n build: (args, tree) => {\n const id = String(args.id);\n if (!tree.nodes[id]) return { error: `No node ${id}` };\n return { t: \"set_style\", id, patch: (args.patch && typeof args.patch === \"object\" ? args.patch : {}) as Partial<StyleProps> };\n },\n targetId: (args) => String(args.id),\n },\n {\n verb: \"set_layout\",\n description: \"Set a container node's layout mode (free | stack | grid).\",\n properties: { id: { type: \"string\" }, layout: { type: \"string\", enum: [\"free\", \"stack\", \"grid\"] } },\n required: [\"id\"],\n build: (args, tree) => {\n const id = String(args.id);\n if (!tree.nodes[id]) return { error: `No node ${id}` };\n return { t: \"set_layout\", id, layout: args.layout as LayoutMode | undefined };\n },\n targetId: (args) => String(args.id),\n },\n ],\n });\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { cmsReducer, registerCmsBridge } from './chunk-A57CRGEK.js';
|
|
2
|
+
import './chunk-FF5F526J.js';
|
|
3
|
+
import './chunk-ULJL53DL.js';
|
|
4
|
+
import './chunk-KJ5AOOV7.js';
|
|
5
|
+
import './chunk-C3TYI5TJ.js';
|
|
6
|
+
import './chunk-4KAIV6OD.js';
|
|
7
|
+
//# sourceMappingURL=bridges-cms.js.map
|
|
8
|
+
//# sourceMappingURL=bridges-cms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"bridges-cms.js"}
|
package/dist/bridges-code.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { registerCodeBridge } from './chunk-
|
|
2
|
-
import './chunk-KJ5AOOV7.js';
|
|
1
|
+
export { registerCodeBridge } from './chunk-NN3ELTVO.js';
|
|
3
2
|
import './chunk-ULJL53DL.js';
|
|
3
|
+
import './chunk-KJ5AOOV7.js';
|
|
4
4
|
import './chunk-C3TYI5TJ.js';
|
|
5
5
|
import './chunk-4KAIV6OD.js';
|
|
6
6
|
//# sourceMappingURL=bridges-code.js.map
|