@particle-academy/agent-integrations 0.37.0 → 0.39.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/grid.d.cts +87 -0
- package/dist/bridges/grid.d.ts +87 -0
- package/dist/bridges-grid.cjs +329 -0
- package/dist/bridges-grid.cjs.map +1 -0
- package/dist/bridges-grid.js +7 -0
- package/dist/bridges-grid.js.map +1 -0
- package/dist/chunk-MJ2S25ON.js +209 -0
- package/dist/chunk-MJ2S25ON.js.map +1 -0
- package/dist/{chunk-ABP2THQV.js → chunk-QYWPCRT2.js} +43 -13
- package/dist/chunk-QYWPCRT2.js.map +1 -0
- package/dist/components-shared-whiteboard.cjs +41 -11
- package/dist/components-shared-whiteboard.cjs.map +1 -1
- package/dist/components-shared-whiteboard.js +1 -1
- package/dist/index.cjs +268 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/styles.css +35 -1
- package/dist/styles.css.map +1 -1
- package/package.json +17 -5
- package/dist/chunk-ABP2THQV.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { T as ToolHost } from '../tool-host-EuYHYSSH.cjs';
|
|
2
|
+
import { B as Bridge } from '../types-NFGP769G.cjs';
|
|
3
|
+
import '../types-C58ZXs4K.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loose grid types — the public state shape of `@particle-academy/fancy-grid`,
|
|
7
|
+
* mirrored here rather than imported.
|
|
8
|
+
*
|
|
9
|
+
* Same reason the scene bridge mirrors fancy-3d's descriptor: a bridge must not
|
|
10
|
+
* drag its surface package into every consumer's tree. fancy-grid keeps
|
|
11
|
+
* TanStack Table and Virtual as PEERS specifically so nothing bundles them, and
|
|
12
|
+
* an `import type` here would still make fancy-grid a build-time dependency of
|
|
13
|
+
* agent-integrations. The state is four small JSON shapes; the coupling is not
|
|
14
|
+
* worth it.
|
|
15
|
+
*/
|
|
16
|
+
type GridSort = {
|
|
17
|
+
id: string;
|
|
18
|
+
desc: boolean;
|
|
19
|
+
};
|
|
20
|
+
type GridFilter = {
|
|
21
|
+
id: string;
|
|
22
|
+
value: string;
|
|
23
|
+
};
|
|
24
|
+
type GridPagination = {
|
|
25
|
+
pageIndex: number;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
};
|
|
28
|
+
type GridState = {
|
|
29
|
+
sorting?: GridSort[];
|
|
30
|
+
filters?: GridFilter[];
|
|
31
|
+
/** Keyed by row id — see the grid's `getRowId`. */
|
|
32
|
+
rowSelection?: Record<string, boolean>;
|
|
33
|
+
pagination?: GridPagination;
|
|
34
|
+
};
|
|
35
|
+
type GridBridgeAdapter = {
|
|
36
|
+
id: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
screenId?: string;
|
|
39
|
+
/** Controlled state — the same object the grid's `onStateChange` emits. */
|
|
40
|
+
getState: () => GridState;
|
|
41
|
+
setState: (next: GridState) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Column ids an agent may address. Supplied so a tool can REJECT an unknown
|
|
44
|
+
* column instead of writing a sort nothing applies — a silently ignored sort
|
|
45
|
+
* looks identical to a grid that simply is not sorted.
|
|
46
|
+
*/
|
|
47
|
+
getColumnIds?: () => string[];
|
|
48
|
+
/** Row ids currently on screen, for `grid_select_rows` validation. */
|
|
49
|
+
getRowIds?: () => string[];
|
|
50
|
+
/**
|
|
51
|
+
* Write one cell. Absent when the grid is read-only, in which case
|
|
52
|
+
* `grid_edit_cell` is not registered at all rather than failing at call time
|
|
53
|
+
* — an agent should discover the capability from the tool list.
|
|
54
|
+
*/
|
|
55
|
+
editCell?: (rowId: string, columnId: string, value: unknown) => void | Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
type GridBridgeOptions = {
|
|
58
|
+
adapter: GridBridgeAdapter;
|
|
59
|
+
agent?: {
|
|
60
|
+
id: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
color?: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Gate writes behind a human confirmation. `grid_edit_cell` is the only
|
|
66
|
+
* mutation that changes DATA rather than view state, so it is the one that
|
|
67
|
+
* matters here — sorting a grid is not a trust-but-verify action.
|
|
68
|
+
*/
|
|
69
|
+
pendingMode?: boolean;
|
|
70
|
+
onPending?: (staged: {
|
|
71
|
+
id: string;
|
|
72
|
+
label: string;
|
|
73
|
+
apply: () => void | Promise<void>;
|
|
74
|
+
}) => void;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* registerGridBridge — MCP access to a `fancy-grid` surface.
|
|
78
|
+
*
|
|
79
|
+
* `grid_sort`, `grid_filter`, `grid_select_rows` and `grid_edit_cell`, plus a
|
|
80
|
+
* read tool. View state (sort / filter / selection / page) goes through one
|
|
81
|
+
* `setState` channel because that is how the grid is controlled — a bridge that
|
|
82
|
+
* mutated pieces separately would drift from what the component actually
|
|
83
|
+
* accepts.
|
|
84
|
+
*/
|
|
85
|
+
declare function registerGridBridge(host: ToolHost, options: GridBridgeOptions): Bridge;
|
|
86
|
+
|
|
87
|
+
export { type GridBridgeAdapter, type GridBridgeOptions, type GridFilter, type GridPagination, type GridSort, type GridState, registerGridBridge };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { T as ToolHost } from '../tool-host-CWTOJEm2.js';
|
|
2
|
+
import { B as Bridge } from '../types-BKD6uf86.js';
|
|
3
|
+
import '../types-C58ZXs4K.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loose grid types — the public state shape of `@particle-academy/fancy-grid`,
|
|
7
|
+
* mirrored here rather than imported.
|
|
8
|
+
*
|
|
9
|
+
* Same reason the scene bridge mirrors fancy-3d's descriptor: a bridge must not
|
|
10
|
+
* drag its surface package into every consumer's tree. fancy-grid keeps
|
|
11
|
+
* TanStack Table and Virtual as PEERS specifically so nothing bundles them, and
|
|
12
|
+
* an `import type` here would still make fancy-grid a build-time dependency of
|
|
13
|
+
* agent-integrations. The state is four small JSON shapes; the coupling is not
|
|
14
|
+
* worth it.
|
|
15
|
+
*/
|
|
16
|
+
type GridSort = {
|
|
17
|
+
id: string;
|
|
18
|
+
desc: boolean;
|
|
19
|
+
};
|
|
20
|
+
type GridFilter = {
|
|
21
|
+
id: string;
|
|
22
|
+
value: string;
|
|
23
|
+
};
|
|
24
|
+
type GridPagination = {
|
|
25
|
+
pageIndex: number;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
};
|
|
28
|
+
type GridState = {
|
|
29
|
+
sorting?: GridSort[];
|
|
30
|
+
filters?: GridFilter[];
|
|
31
|
+
/** Keyed by row id — see the grid's `getRowId`. */
|
|
32
|
+
rowSelection?: Record<string, boolean>;
|
|
33
|
+
pagination?: GridPagination;
|
|
34
|
+
};
|
|
35
|
+
type GridBridgeAdapter = {
|
|
36
|
+
id: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
screenId?: string;
|
|
39
|
+
/** Controlled state — the same object the grid's `onStateChange` emits. */
|
|
40
|
+
getState: () => GridState;
|
|
41
|
+
setState: (next: GridState) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Column ids an agent may address. Supplied so a tool can REJECT an unknown
|
|
44
|
+
* column instead of writing a sort nothing applies — a silently ignored sort
|
|
45
|
+
* looks identical to a grid that simply is not sorted.
|
|
46
|
+
*/
|
|
47
|
+
getColumnIds?: () => string[];
|
|
48
|
+
/** Row ids currently on screen, for `grid_select_rows` validation. */
|
|
49
|
+
getRowIds?: () => string[];
|
|
50
|
+
/**
|
|
51
|
+
* Write one cell. Absent when the grid is read-only, in which case
|
|
52
|
+
* `grid_edit_cell` is not registered at all rather than failing at call time
|
|
53
|
+
* — an agent should discover the capability from the tool list.
|
|
54
|
+
*/
|
|
55
|
+
editCell?: (rowId: string, columnId: string, value: unknown) => void | Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
type GridBridgeOptions = {
|
|
58
|
+
adapter: GridBridgeAdapter;
|
|
59
|
+
agent?: {
|
|
60
|
+
id: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
color?: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Gate writes behind a human confirmation. `grid_edit_cell` is the only
|
|
66
|
+
* mutation that changes DATA rather than view state, so it is the one that
|
|
67
|
+
* matters here — sorting a grid is not a trust-but-verify action.
|
|
68
|
+
*/
|
|
69
|
+
pendingMode?: boolean;
|
|
70
|
+
onPending?: (staged: {
|
|
71
|
+
id: string;
|
|
72
|
+
label: string;
|
|
73
|
+
apply: () => void | Promise<void>;
|
|
74
|
+
}) => void;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* registerGridBridge — MCP access to a `fancy-grid` surface.
|
|
78
|
+
*
|
|
79
|
+
* `grid_sort`, `grid_filter`, `grid_select_rows` and `grid_edit_cell`, plus a
|
|
80
|
+
* read tool. View state (sort / filter / selection / page) goes through one
|
|
81
|
+
* `setState` channel because that is how the grid is controlled — a bridge that
|
|
82
|
+
* mutated pieces separately would drift from what the component actually
|
|
83
|
+
* accepts.
|
|
84
|
+
*/
|
|
85
|
+
declare function registerGridBridge(host: ToolHost, options: GridBridgeOptions): Bridge;
|
|
86
|
+
|
|
87
|
+
export { type GridBridgeAdapter, type GridBridgeOptions, type GridFilter, type GridPagination, type GridSort, type GridState, registerGridBridge };
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fancyAutoCommon = require('@particle-academy/fancy-auto-common');
|
|
4
|
+
|
|
5
|
+
// src/mcp/server.ts
|
|
6
|
+
function textResult(text, structured) {
|
|
7
|
+
return {
|
|
8
|
+
content: [{ type: "text", text }],
|
|
9
|
+
...structured !== void 0 ? { structuredContent: structured } : {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function errorResult(text) {
|
|
13
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/presence/wrap-tool-with-activity.ts
|
|
17
|
+
function wrapToolWithActivity(handler, options) {
|
|
18
|
+
return async (args) => {
|
|
19
|
+
const result = await handler(args);
|
|
20
|
+
if (result.isError) return result;
|
|
21
|
+
let target;
|
|
22
|
+
if (options.resolveTarget) {
|
|
23
|
+
target = options.resolveTarget({ toolName: options.toolName, args, result });
|
|
24
|
+
} else {
|
|
25
|
+
target = { kind: options.kind, screenId: options.screenId };
|
|
26
|
+
}
|
|
27
|
+
if (!target) return result;
|
|
28
|
+
fancyAutoCommon.emitActivity({
|
|
29
|
+
agentId: options.agent.id,
|
|
30
|
+
agentName: options.agent.name,
|
|
31
|
+
agentColor: options.agent.color,
|
|
32
|
+
target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },
|
|
33
|
+
action: options.toolName,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
meta: options.buildMeta ? options.buildMeta(result) : extractMeta(result),
|
|
36
|
+
ttlMs: options.ttlMs
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function extractMeta(result) {
|
|
42
|
+
const sc = result.structuredContent;
|
|
43
|
+
if (sc && typeof sc === "object" && !Array.isArray(sc)) {
|
|
44
|
+
return sc;
|
|
45
|
+
}
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/undo/undo-tools.ts
|
|
50
|
+
var installedHosts = /* @__PURE__ */ new WeakSet();
|
|
51
|
+
function ensureUndoToolsRegistered(host, options = {}) {
|
|
52
|
+
if (installedHosts.has(host)) return;
|
|
53
|
+
installedHosts.add(host);
|
|
54
|
+
registerUndoTools(host, options);
|
|
55
|
+
}
|
|
56
|
+
function registerUndoTools(host, options = {}) {
|
|
57
|
+
const defaultAgent = options.defaultAgentId ?? "agent";
|
|
58
|
+
const disposers = [];
|
|
59
|
+
const agentOf = (args) => typeof args?.agentId === "string" ? args.agentId : defaultAgent;
|
|
60
|
+
disposers.push(
|
|
61
|
+
host.registerTool(
|
|
62
|
+
{
|
|
63
|
+
name: "agent_undo",
|
|
64
|
+
description: "Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: { agentId: { type: "string" } },
|
|
68
|
+
additionalProperties: false
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
async (args) => {
|
|
72
|
+
const entry = await fancyAutoCommon.undoOne(agentOf(args));
|
|
73
|
+
if (!entry) return errorResult("Nothing to undo.");
|
|
74
|
+
return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
disposers.push(
|
|
79
|
+
host.registerTool(
|
|
80
|
+
{
|
|
81
|
+
name: "agent_redo",
|
|
82
|
+
description: "Redo the most recently undone action.",
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: { agentId: { type: "string" } },
|
|
86
|
+
additionalProperties: false
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
async (args) => {
|
|
90
|
+
const entry = await fancyAutoCommon.redoOne(agentOf(args));
|
|
91
|
+
if (!entry) return errorResult("Nothing to redo.");
|
|
92
|
+
return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
disposers.push(
|
|
97
|
+
host.registerTool(
|
|
98
|
+
{
|
|
99
|
+
name: "agent_history",
|
|
100
|
+
description: "List the agent's undo stack (oldest first). Useful for understanding what's reversible.",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: { agentId: { type: "string" } },
|
|
104
|
+
additionalProperties: false
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async (args) => {
|
|
108
|
+
const history = fancyAutoCommon.readHistory(agentOf(args)).map(serialize);
|
|
109
|
+
const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join("\n");
|
|
110
|
+
return textResult(text || "(empty)", history);
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
return () => disposers.forEach((d) => d());
|
|
115
|
+
}
|
|
116
|
+
function serialize(entry) {
|
|
117
|
+
return {
|
|
118
|
+
timestamp: entry.timestamp,
|
|
119
|
+
bridgeId: entry.bridgeId,
|
|
120
|
+
action: entry.action,
|
|
121
|
+
label: entry.label
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/bridges/grid.ts
|
|
126
|
+
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
127
|
+
function registerGridBridge(host, options) {
|
|
128
|
+
const { adapter } = options;
|
|
129
|
+
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
130
|
+
const disposers = [];
|
|
131
|
+
ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
|
|
132
|
+
const target = (part) => ({
|
|
133
|
+
kind: "grid",
|
|
134
|
+
screenId: adapter.screenId,
|
|
135
|
+
elementId: part ? `${adapter.id}:${part}` : adapter.id,
|
|
136
|
+
label: part ? `${adapter.title ?? adapter.id} \u2192 ${part}` : adapter.title ?? adapter.id
|
|
137
|
+
});
|
|
138
|
+
const reg = (name, description, properties, required, handler, isMutation, partFromArgs) => {
|
|
139
|
+
const wrapped = async (args) => {
|
|
140
|
+
try {
|
|
141
|
+
return await handler(args);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return errorResult(e instanceof Error ? e.message : String(e));
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const final = isMutation ? wrapToolWithActivity(wrapped, {
|
|
147
|
+
toolName: name,
|
|
148
|
+
agent,
|
|
149
|
+
kind: "grid",
|
|
150
|
+
screenId: adapter.screenId,
|
|
151
|
+
resolveTarget: ({ args }) => target(partFromArgs?.(args))
|
|
152
|
+
}) : wrapped;
|
|
153
|
+
disposers.push(
|
|
154
|
+
host.registerTool(
|
|
155
|
+
{
|
|
156
|
+
name,
|
|
157
|
+
description,
|
|
158
|
+
inputSchema: { type: "object", properties, required, additionalProperties: false }
|
|
159
|
+
},
|
|
160
|
+
final
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
const assertColumn = (id) => {
|
|
165
|
+
const known = adapter.getColumnIds?.();
|
|
166
|
+
if (known && !known.includes(id)) {
|
|
167
|
+
throw new Error(`Unknown column "${id}". Available: ${known.join(", ")}`);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const commit = (next, action, label, previous) => {
|
|
171
|
+
adapter.setState(next);
|
|
172
|
+
fancyAutoCommon.pushUndoEntry(agent.id, {
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
bridgeId: `grid:${adapter.id}`,
|
|
175
|
+
action,
|
|
176
|
+
label,
|
|
177
|
+
undo: () => adapter.setState(previous),
|
|
178
|
+
redo: () => adapter.setState(next)
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
reg(
|
|
182
|
+
"grid_get",
|
|
183
|
+
"Read the grid's view state \u2014 sorting, filters, selected row ids, pagination \u2014 plus the addressable column and row ids.",
|
|
184
|
+
{},
|
|
185
|
+
[],
|
|
186
|
+
() => {
|
|
187
|
+
const state = adapter.getState();
|
|
188
|
+
return textResult(
|
|
189
|
+
JSON.stringify(
|
|
190
|
+
{
|
|
191
|
+
id: adapter.id,
|
|
192
|
+
title: adapter.title,
|
|
193
|
+
sorting: state.sorting ?? [],
|
|
194
|
+
filters: state.filters ?? [],
|
|
195
|
+
selectedRowIds: Object.entries(state.rowSelection ?? {}).filter(([, on]) => on).map(([id]) => id),
|
|
196
|
+
pagination: state.pagination,
|
|
197
|
+
columnIds: adapter.getColumnIds?.() ?? null,
|
|
198
|
+
rowIds: adapter.getRowIds?.() ?? null,
|
|
199
|
+
editable: Boolean(adapter.editCell)
|
|
200
|
+
},
|
|
201
|
+
null,
|
|
202
|
+
2
|
|
203
|
+
)
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
false
|
|
207
|
+
);
|
|
208
|
+
reg(
|
|
209
|
+
"grid_sort",
|
|
210
|
+
"Sort the grid. Pass an empty array to clear sorting. Multiple entries sort by each in order.",
|
|
211
|
+
{
|
|
212
|
+
sorting: {
|
|
213
|
+
type: "array",
|
|
214
|
+
description: 'e.g. [{ "id": "createdAt", "desc": true }]',
|
|
215
|
+
items: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: { id: { type: "string" }, desc: { type: "boolean" } },
|
|
218
|
+
required: ["id"],
|
|
219
|
+
additionalProperties: false
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
["sorting"],
|
|
224
|
+
(args) => {
|
|
225
|
+
const raw = Array.isArray(args.sorting) ? args.sorting : [];
|
|
226
|
+
const sorting = raw.map((s) => {
|
|
227
|
+
assertColumn(String(s.id));
|
|
228
|
+
return { id: String(s.id), desc: Boolean(s.desc) };
|
|
229
|
+
});
|
|
230
|
+
const previous = adapter.getState();
|
|
231
|
+
commit({ ...previous, sorting }, "grid_sort", `Sorted by ${sorting.map((s) => s.id).join(", ") || "nothing"}`, previous);
|
|
232
|
+
return textResult(`Sorted by ${sorting.map((s) => `${s.id}${s.desc ? " desc" : ""}`).join(", ") || "nothing"}.`);
|
|
233
|
+
},
|
|
234
|
+
true,
|
|
235
|
+
(args) => Array.isArray(args.sorting) && args.sorting[0] ? String(args.sorting[0].id) : void 0
|
|
236
|
+
);
|
|
237
|
+
reg(
|
|
238
|
+
"grid_filter",
|
|
239
|
+
"Filter the grid. Pass an empty array to clear all filters.",
|
|
240
|
+
{
|
|
241
|
+
filters: {
|
|
242
|
+
type: "array",
|
|
243
|
+
description: 'e.g. [{ "id": "status", "value": "open" }]',
|
|
244
|
+
items: {
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: { id: { type: "string" }, value: { type: "string" } },
|
|
247
|
+
required: ["id", "value"],
|
|
248
|
+
additionalProperties: false
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
["filters"],
|
|
253
|
+
(args) => {
|
|
254
|
+
const raw = Array.isArray(args.filters) ? args.filters : [];
|
|
255
|
+
const filters = raw.map((f) => {
|
|
256
|
+
assertColumn(String(f.id));
|
|
257
|
+
return { id: String(f.id), value: String(f.value) };
|
|
258
|
+
});
|
|
259
|
+
const previous = adapter.getState();
|
|
260
|
+
commit({ ...previous, filters }, "grid_filter", `Filtered ${filters.map((f) => f.id).join(", ") || "cleared"}`, previous);
|
|
261
|
+
return textResult(`Filtering on ${filters.map((f) => `${f.id}=${f.value}`).join(", ") || "nothing"}.`);
|
|
262
|
+
},
|
|
263
|
+
true,
|
|
264
|
+
(args) => Array.isArray(args.filters) && args.filters[0] ? String(args.filters[0].id) : void 0
|
|
265
|
+
);
|
|
266
|
+
reg(
|
|
267
|
+
"grid_select_rows",
|
|
268
|
+
"Replace the grid's row selection with the given row ids. Pass an empty array to clear.",
|
|
269
|
+
{ rowIds: { type: "array", items: { type: "string" }, description: "Row ids, per the grid's getRowId." } },
|
|
270
|
+
["rowIds"],
|
|
271
|
+
(args) => {
|
|
272
|
+
const ids = Array.isArray(args.rowIds) ? args.rowIds.map(String) : [];
|
|
273
|
+
const known = adapter.getRowIds?.();
|
|
274
|
+
if (known) {
|
|
275
|
+
const missing = ids.filter((id) => !known.includes(id));
|
|
276
|
+
if (missing.length) {
|
|
277
|
+
throw new Error(`Row id(s) not on this page: ${missing.join(", ")}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const previous = adapter.getState();
|
|
281
|
+
const rowSelection = {};
|
|
282
|
+
for (const id of ids) rowSelection[id] = true;
|
|
283
|
+
commit({ ...previous, rowSelection }, "grid_select_rows", `Selected ${ids.length} row${ids.length === 1 ? "" : "s"}`, previous);
|
|
284
|
+
return textResult(`Selected ${ids.length} row${ids.length === 1 ? "" : "s"}.`);
|
|
285
|
+
},
|
|
286
|
+
true
|
|
287
|
+
);
|
|
288
|
+
if (adapter.editCell) {
|
|
289
|
+
reg(
|
|
290
|
+
"grid_edit_cell",
|
|
291
|
+
"Write one cell. This changes DATA, not just the view.",
|
|
292
|
+
{
|
|
293
|
+
rowId: { type: "string" },
|
|
294
|
+
columnId: { type: "string" },
|
|
295
|
+
value: { description: "New value. Any JSON scalar or object the column accepts." }
|
|
296
|
+
},
|
|
297
|
+
["rowId", "columnId"],
|
|
298
|
+
async (args) => {
|
|
299
|
+
const rowId = String(args.rowId);
|
|
300
|
+
const columnId = String(args.columnId);
|
|
301
|
+
assertColumn(columnId);
|
|
302
|
+
const apply = async () => {
|
|
303
|
+
await adapter.editCell?.(rowId, columnId, args.value);
|
|
304
|
+
};
|
|
305
|
+
if (options.pendingMode) {
|
|
306
|
+
const id = `grid-edit-${Date.now().toString(36)}`;
|
|
307
|
+
options.onPending?.({ id, label: `set ${columnId} on row ${rowId}`, apply });
|
|
308
|
+
return textResult(`Staged: set ${columnId} on row ${rowId}. Awaiting confirmation.`);
|
|
309
|
+
}
|
|
310
|
+
await apply();
|
|
311
|
+
return textResult(`Set ${columnId} on row ${rowId}.`);
|
|
312
|
+
},
|
|
313
|
+
true,
|
|
314
|
+
(args) => `${String(args.rowId)}:${String(args.columnId)}`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
id: `grid:${adapter.id}`,
|
|
319
|
+
title: adapter.title ?? adapter.id,
|
|
320
|
+
dispose: () => {
|
|
321
|
+
for (const d of disposers) d();
|
|
322
|
+
disposers.length = 0;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
exports.registerGridBridge = registerGridBridge;
|
|
328
|
+
//# sourceMappingURL=bridges-grid.cjs.map
|
|
329
|
+
//# sourceMappingURL=bridges-grid.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp/server.ts","../src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AAO,CAAA,IAAA,EAAO,QAAQ,CAAA,QAAA,EAAW,KAAK,CAAA,CAAA,EAAI,KAAA,EAAO,CAAA;AAC3E,UAAA,OAAO,UAAA,CAAW,CAAA,YAAA,EAAe,QAAQ,CAAA,QAAA,EAAW,KAAK,CAAA,wBAAA,CAA0B,CAAA;AAAA,QACrF;AAEA,QAAA,MAAM,KAAA,EAAM;AACZ,QAAA,OAAO,UAAA,CAAW,CAAA,IAAA,EAAO,QAAQ,CAAA,QAAA,EAAW,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA,MACtD,CAAA;AAAA,MACA,IAAA;AAAA,MACA,CAAC,IAAA,KAAS,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,KAAK,CAAC,CAAA,CAAA,EAAI,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,KAC1D;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,CAAA,KAAA,EAAQ,OAAA,CAAQ,EAAE,CAAA,CAAA;AAAA,IACtB,KAAA,EAAO,OAAA,CAAQ,KAAA,IAAS,OAAA,CAAQ,EAAA;AAAA,IAChC,SAAS,MAAM;AACb,MAAA,KAAA,MAAW,CAAA,IAAK,WAAW,CAAA,EAAE;AAC7B,MAAA,SAAA,CAAU,MAAA,GAAS,CAAA;AAAA,IACrB;AAAA,GACF;AACF","file":"bridges-grid.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, transport);\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, transport: Transport): 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, { transport });\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 /** Send an application notification to every client, or one attached transport. */\n notify(message: JsonRpcMessage, transport?: Transport): void {\n if (transport) transport.send(message);\n else this.broadcast(message);\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 * Build the `meta` broadcast to all relay peers. Defaults to the tool's full\n * `structuredContent`. Override to REDACT sensitive fields before fan-out —\n * e.g. the terminal bridge strips raw command/keystroke bytes so a command\n * line (or its secrets) is never broadcast verbatim to every peer.\n */\n buildMeta?: (result: CallToolResult) => Record<string, unknown> | undefined;\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: options.buildMeta ? options.buildMeta(result) : 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","import { 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 { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport type { AgentTarget } from \"../presence/types\";\n\n/**\n * Loose grid types — the public state shape of `@particle-academy/fancy-grid`,\n * mirrored here rather than imported.\n *\n * Same reason the scene bridge mirrors fancy-3d's descriptor: a bridge must not\n * drag its surface package into every consumer's tree. fancy-grid keeps\n * TanStack Table and Virtual as PEERS specifically so nothing bundles them, and\n * an `import type` here would still make fancy-grid a build-time dependency of\n * agent-integrations. The state is four small JSON shapes; the coupling is not\n * worth it.\n */\nexport type GridSort = { id: string; desc: boolean };\nexport type GridFilter = { id: string; value: string };\nexport type GridPagination = { pageIndex: number; pageSize: number };\n\nexport type GridState = {\n sorting?: GridSort[];\n filters?: GridFilter[];\n /** Keyed by row id — see the grid's `getRowId`. */\n rowSelection?: Record<string, boolean>;\n pagination?: GridPagination;\n};\n\nexport type GridBridgeAdapter = {\n id: string;\n title?: string;\n screenId?: string;\n /** Controlled state — the same object the grid's `onStateChange` emits. */\n getState: () => GridState;\n setState: (next: GridState) => void;\n /**\n * Column ids an agent may address. Supplied so a tool can REJECT an unknown\n * column instead of writing a sort nothing applies — a silently ignored sort\n * looks identical to a grid that simply is not sorted.\n */\n getColumnIds?: () => string[];\n /** Row ids currently on screen, for `grid_select_rows` validation. */\n getRowIds?: () => string[];\n /**\n * Write one cell. Absent when the grid is read-only, in which case\n * `grid_edit_cell` is not registered at all rather than failing at call time\n * — an agent should discover the capability from the tool list.\n */\n editCell?: (rowId: string, columnId: string, value: unknown) => void | Promise<void>;\n};\n\nexport type GridBridgeOptions = {\n adapter: GridBridgeAdapter;\n agent?: { id: string; name?: string; color?: string };\n /**\n * Gate writes behind a human confirmation. `grid_edit_cell` is the only\n * mutation that changes DATA rather than view state, so it is the one that\n * matters here — sorting a grid is not a trust-but-verify action.\n */\n pendingMode?: boolean;\n onPending?: (staged: { id: string; label: string; apply: () => void | Promise<void> }) => void;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\n/**\n * registerGridBridge — MCP access to a `fancy-grid` surface.\n *\n * `grid_sort`, `grid_filter`, `grid_select_rows` and `grid_edit_cell`, plus a\n * read tool. View state (sort / filter / selection / page) goes through one\n * `setState` channel because that is how the grid is controlled — a bridge that\n * mutated pieces separately would drift from what the component actually\n * accepts.\n */\nexport function registerGridBridge(host: ToolHost, options: GridBridgeOptions): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const disposers: Array<() => void> = [];\n\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n const target = (part?: string): AgentTarget => ({\n kind: \"grid\",\n screenId: adapter.screenId,\n elementId: part ? `${adapter.id}:${part}` : adapter.id,\n label: part ? `${adapter.title ?? adapter.id} → ${part}` : (adapter.title ?? adapter.id),\n });\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<ReturnType<typeof textResult>> | ReturnType<typeof textResult>,\n isMutation: boolean,\n partFromArgs?: (args: JsonObject) => string | undefined,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\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: \"grid\",\n screenId: adapter.screenId,\n resolveTarget: ({ args }) => target(partFromArgs?.(args)),\n })\n : wrapped;\n\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: { type: \"object\", properties: properties as never, required, additionalProperties: false },\n },\n final as never,\n ),\n );\n };\n\n /** Reject an unknown column rather than writing state nothing applies. */\n const assertColumn = (id: string): void => {\n const known = adapter.getColumnIds?.();\n if (known && !known.includes(id)) {\n throw new Error(`Unknown column \"${id}\". Available: ${known.join(\", \")}`);\n }\n };\n\n const commit = (next: GridState, action: string, label: string, previous: GridState): void => {\n adapter.setState(next);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: `grid:${adapter.id}`,\n action,\n label,\n undo: () => adapter.setState(previous),\n redo: () => adapter.setState(next),\n });\n };\n\n // ───────────── Read ─────────────\n\n reg(\n \"grid_get\",\n \"Read the grid's view state — sorting, filters, selected row ids, pagination — plus the addressable column and row ids.\",\n {},\n [],\n () => {\n const state = adapter.getState();\n return textResult(\n JSON.stringify(\n {\n id: adapter.id,\n title: adapter.title,\n sorting: state.sorting ?? [],\n filters: state.filters ?? [],\n selectedRowIds: Object.entries(state.rowSelection ?? {})\n .filter(([, on]) => on)\n .map(([id]) => id),\n pagination: state.pagination,\n columnIds: adapter.getColumnIds?.() ?? null,\n rowIds: adapter.getRowIds?.() ?? null,\n editable: Boolean(adapter.editCell),\n },\n null,\n 2,\n ),\n );\n },\n false,\n );\n\n // ───────────── View state ─────────────\n\n reg(\n \"grid_sort\",\n \"Sort the grid. Pass an empty array to clear sorting. Multiple entries sort by each in order.\",\n {\n sorting: {\n type: \"array\",\n description: 'e.g. [{ \"id\": \"createdAt\", \"desc\": true }]',\n items: {\n type: \"object\",\n properties: { id: { type: \"string\" }, desc: { type: \"boolean\" } },\n required: [\"id\"],\n additionalProperties: false,\n },\n },\n },\n [\"sorting\"],\n (args) => {\n const raw = Array.isArray(args.sorting) ? (args.sorting as GridSort[]) : [];\n const sorting = raw.map((s) => {\n assertColumn(String(s.id));\n return { id: String(s.id), desc: Boolean(s.desc) };\n });\n\n const previous = adapter.getState();\n commit({ ...previous, sorting }, \"grid_sort\", `Sorted by ${sorting.map((s) => s.id).join(\", \") || \"nothing\"}`, previous);\n return textResult(`Sorted by ${sorting.map((s) => `${s.id}${s.desc ? \" desc\" : \"\"}`).join(\", \") || \"nothing\"}.`);\n },\n true,\n (args) => (Array.isArray(args.sorting) && args.sorting[0] ? String((args.sorting[0] as GridSort).id) : undefined),\n );\n\n reg(\n \"grid_filter\",\n \"Filter the grid. Pass an empty array to clear all filters.\",\n {\n filters: {\n type: \"array\",\n description: 'e.g. [{ \"id\": \"status\", \"value\": \"open\" }]',\n items: {\n type: \"object\",\n properties: { id: { type: \"string\" }, value: { type: \"string\" } },\n required: [\"id\", \"value\"],\n additionalProperties: false,\n },\n },\n },\n [\"filters\"],\n (args) => {\n const raw = Array.isArray(args.filters) ? (args.filters as GridFilter[]) : [];\n const filters = raw.map((f) => {\n assertColumn(String(f.id));\n return { id: String(f.id), value: String(f.value) };\n });\n\n const previous = adapter.getState();\n commit({ ...previous, filters }, \"grid_filter\", `Filtered ${filters.map((f) => f.id).join(\", \") || \"cleared\"}`, previous);\n return textResult(`Filtering on ${filters.map((f) => `${f.id}=${f.value}`).join(\", \") || \"nothing\"}.`);\n },\n true,\n (args) => (Array.isArray(args.filters) && args.filters[0] ? String((args.filters[0] as GridFilter).id) : undefined),\n );\n\n reg(\n \"grid_select_rows\",\n \"Replace the grid's row selection with the given row ids. Pass an empty array to clear.\",\n { rowIds: { type: \"array\", items: { type: \"string\" }, description: \"Row ids, per the grid's getRowId.\" } },\n [\"rowIds\"],\n (args) => {\n const ids = Array.isArray(args.rowIds) ? args.rowIds.map(String) : [];\n const known = adapter.getRowIds?.();\n if (known) {\n const missing = ids.filter((id) => !known.includes(id));\n if (missing.length) {\n // Selecting a row that is not loaded looks like it worked and shows\n // nothing — worth an error rather than a silent no-op.\n throw new Error(`Row id(s) not on this page: ${missing.join(\", \")}`);\n }\n }\n\n const previous = adapter.getState();\n const rowSelection: Record<string, boolean> = {};\n for (const id of ids) rowSelection[id] = true;\n\n commit({ ...previous, rowSelection }, \"grid_select_rows\", `Selected ${ids.length} row${ids.length === 1 ? \"\" : \"s\"}`, previous);\n return textResult(`Selected ${ids.length} row${ids.length === 1 ? \"\" : \"s\"}.`);\n },\n true,\n );\n\n // ───────────── Data ─────────────\n\n if (adapter.editCell) {\n reg(\n \"grid_edit_cell\",\n \"Write one cell. This changes DATA, not just the view.\",\n {\n rowId: { type: \"string\" },\n columnId: { type: \"string\" },\n value: { description: \"New value. Any JSON scalar or object the column accepts.\" },\n },\n [\"rowId\", \"columnId\"],\n async (args) => {\n const rowId = String(args.rowId);\n const columnId = String(args.columnId);\n assertColumn(columnId);\n\n const apply = async () => {\n await adapter.editCell?.(rowId, columnId, args.value);\n };\n\n if (options.pendingMode) {\n // Trust-but-verify: the only tool here that changes stored data\n // stages instead of writing. Sorting a grid is not a destructive act;\n // editing a cell is.\n const id = `grid-edit-${Date.now().toString(36)}`;\n options.onPending?.({ id, label: `set ${columnId} on row ${rowId}`, apply });\n return textResult(`Staged: set ${columnId} on row ${rowId}. Awaiting confirmation.`);\n }\n\n await apply();\n return textResult(`Set ${columnId} on row ${rowId}.`);\n },\n true,\n (args) => `${String(args.rowId)}:${String(args.columnId)}`,\n );\n }\n\n return {\n id: `grid:${adapter.id}`,\n title: adapter.title ?? adapter.id,\n dispose: () => {\n for (const d of disposers) d();\n disposers.length = 0;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { registerGridBridge } from './chunk-MJ2S25ON.js';
|
|
2
|
+
import './chunk-CT3LRNH7.js';
|
|
3
|
+
import './chunk-2VENWGLZ.js';
|
|
4
|
+
import './chunk-C3TYI5TJ.js';
|
|
5
|
+
import './chunk-DF3PLL2E.js';
|
|
6
|
+
//# sourceMappingURL=bridges-grid.js.map
|
|
7
|
+
//# sourceMappingURL=bridges-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"bridges-grid.js"}
|