yaml-flow 8.5.1 → 8.5.3
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/browser/asset-integrity.json +3 -3
- package/cli/bundled/board-live-cards-cli.mjs +8 -8
- package/examples/board/demo-shell-with-server.html +2 -2
- package/examples/board/doc.html +2 -2
- package/examples/board/server/README-mcp-api.md +14 -4
- package/examples/board/test/server-http-mcp-test.js +132 -0
- package/examples/board-local/demo-shell-localstorage.html +3 -3
- package/lib/board-live-cards-mcp.cjs +1 -1
- package/lib/board-live-cards-mcp.d.cts +1 -1
- package/lib/board-live-cards-mcp.d.ts +1 -1
- package/lib/board-live-cards-mcp.js +1 -1
- package/lib/board-live-cards-node.cjs +11 -11
- package/lib/board-live-cards-node.js +11 -11
- package/lib/board-live-cards-public.cjs +2 -2
- package/lib/board-live-cards-public.js +2 -2
- package/lib/board-live-cards-server-runtime.cjs +4 -4
- package/lib/board-live-cards-server-runtime.js +4 -4
- package/lib/server-runtime/index.cjs +4 -4
- package/lib/server-runtime/index.js +4 -4
- package/package.json +1 -1
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
20
20
|
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
|
|
21
21
|
<script src="https://cdn.jsdelivr.net/npm/leader-line/leader-line.min.js"></script>
|
|
22
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
23
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/live-cards.js"></script>
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/board-livecards-client.js"></script>
|
|
24
24
|
</head>
|
|
25
25
|
<body class="bg-light">
|
|
26
26
|
<div class="container-fluid py-3">
|
package/examples/board/doc.html
CHANGED
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
38
38
|
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
|
|
39
39
|
<script src="https://cdn.jsdelivr.net/npm/leader-line/leader-line.min.js"></script>
|
|
40
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
41
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/live-cards.js"></script>
|
|
41
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/board-livecards-client.js"></script>
|
|
42
42
|
</head>
|
|
43
43
|
<body class="bg-light">
|
|
44
44
|
<div class="container-fluid py-3">
|
|
@@ -262,9 +262,9 @@ Validates, stores, and registers a card definition. Triggers a board restart for
|
|
|
262
262
|
|
|
263
263
|
---
|
|
264
264
|
|
|
265
|
-
### `manage.
|
|
265
|
+
### `manage.remove-card`
|
|
266
266
|
|
|
267
|
-
Removes a card from the board.
|
|
267
|
+
Removes a card from both the live board runtime and persistent card storage.
|
|
268
268
|
|
|
269
269
|
**Args:**
|
|
270
270
|
|
|
@@ -272,11 +272,21 @@ Removes a card from the board.
|
|
|
272
272
|
|---|---|---|
|
|
273
273
|
| `card_id` | string | yes |
|
|
274
274
|
|
|
275
|
-
**Returns:** the
|
|
275
|
+
**Returns:** the card removal result. On success:
|
|
276
276
|
```json
|
|
277
|
-
{
|
|
277
|
+
{
|
|
278
|
+
"status": "success",
|
|
279
|
+
"data": {
|
|
280
|
+
"board_result": { "status": "success" },
|
|
281
|
+
"store_result": { "status": "success", "data": { "count": 1 } }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
278
284
|
```
|
|
279
285
|
|
|
286
|
+
> **Behavior notes:**
|
|
287
|
+
> - The card is fully removed from persistent storage. `readAll` will not return it after removal.
|
|
288
|
+
> - Re-upserting a card with the same `card_id` after removal creates a fresh card with no prior state.
|
|
289
|
+
|
|
280
290
|
---
|
|
281
291
|
|
|
282
292
|
### `manage.upload-card-file`
|
|
@@ -90,6 +90,7 @@ const NS = {
|
|
|
90
90
|
statusGeneration: 0,
|
|
91
91
|
computedValues: {},
|
|
92
92
|
chatEvents: [],
|
|
93
|
+
boardEvents: [], // { kind, cardId, at }
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
function applyFrame(payload) {
|
|
@@ -122,6 +123,9 @@ function applyFrame(payload) {
|
|
|
122
123
|
if (n && n.kind === 'computed_values' && n.cardId) {
|
|
123
124
|
NS.computedValues[n.cardId] = n.values;
|
|
124
125
|
}
|
|
126
|
+
if (n && (n.kind === 'card_removed' || n.kind === 'card_refreshed') && n.cardId) {
|
|
127
|
+
NS.boardEvents.push({ kind: n.kind, cardId: n.cardId, at: Date.now() });
|
|
128
|
+
}
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
}
|
|
@@ -1115,6 +1119,21 @@ try {
|
|
|
1115
1119
|
assert(Array.isArray(body.provides_outputs?.positions) && body.provides_outputs.positions.length === 2, 'T4 run-cycle portfolio-value subset length mismatch');
|
|
1116
1120
|
},
|
|
1117
1121
|
},
|
|
1122
|
+
{
|
|
1123
|
+
name: 'market-prices with live source simulation',
|
|
1124
|
+
card: marketCard,
|
|
1125
|
+
mockRequires: { holdings: baseHoldings.slice(0, 3) },
|
|
1126
|
+
verify: (body) => {
|
|
1127
|
+
const quoteRows = body.provides_outputs?.quotes?.quoteResponse?.result;
|
|
1128
|
+
assert(Array.isArray(quoteRows) && quoteRows.length === 3, 'T4 run-cycle market-prices provides result length mismatch');
|
|
1129
|
+
assert(typeof quoteRows[0]?.symbol === 'string' && quoteRows[0].symbol.length > 0, 'T4 run-cycle market-prices provides symbol missing');
|
|
1130
|
+
|
|
1131
|
+
const resolvedRows = body.rendered_view?.elements?.[0]?.resolved;
|
|
1132
|
+
assert(Array.isArray(resolvedRows) && resolvedRows.length === 3, 'T4 run-cycle market-prices rendered resolved length mismatch');
|
|
1133
|
+
assert(typeof resolvedRows[0]?.ticker === 'string' && resolvedRows[0].ticker.length > 0, 'T4 run-cycle market-prices rendered ticker missing');
|
|
1134
|
+
assert(typeof resolvedRows[0]?.price === 'number', 'T4 run-cycle market-prices rendered price missing');
|
|
1135
|
+
},
|
|
1136
|
+
},
|
|
1118
1137
|
];
|
|
1119
1138
|
for (const tc of runCycleSuccessCases) {
|
|
1120
1139
|
const body = expectPreflightSuccess(await httpMcp('preflight.run-one-cycle-with-candidate-card', {
|
|
@@ -1127,6 +1146,119 @@ try {
|
|
|
1127
1146
|
console.log(`[T4.run-cycle] ok: ${tc.name}`);
|
|
1128
1147
|
}
|
|
1129
1148
|
|
|
1149
|
+
// ── T4.remove-card ────────────────────────────────────────────────────────
|
|
1150
|
+
console.log('\n[T4.remove-card] testing manage.remove-card lifecycle');
|
|
1151
|
+
|
|
1152
|
+
const T4_REMOVE_CARD_ID = 'card-t4-remove-test';
|
|
1153
|
+
const T4_REMOVE_CARD_V1 = {
|
|
1154
|
+
id: T4_REMOVE_CARD_ID,
|
|
1155
|
+
card_data: { label: 'v1', color: 'blue' },
|
|
1156
|
+
};
|
|
1157
|
+
const T4_REMOVE_CARD_V2 = {
|
|
1158
|
+
id: T4_REMOVE_CARD_ID,
|
|
1159
|
+
card_data: { label: 'v2', color: 'red' },
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
// (a) upsert the card and wait for it to appear in board-runtime-status
|
|
1163
|
+
const t4UpsertV1Res = await httpMcp('manage.upsert-card', {
|
|
1164
|
+
card_id: T4_REMOVE_CARD_ID,
|
|
1165
|
+
candidate_card_content: T4_REMOVE_CARD_V1,
|
|
1166
|
+
});
|
|
1167
|
+
assert(t4UpsertV1Res.status === 200, `T4.remove-card v1 upsert returned ${t4UpsertV1Res.status}`);
|
|
1168
|
+
const t4UpsertV1Data = expectMcpSuccess(t4UpsertV1Res, 'T4.remove-card v1 upsert');
|
|
1169
|
+
assert(t4UpsertV1Data?.board_result?.status === 'success', 'T4.remove-card v1 upsert board_result expected success');
|
|
1170
|
+
console.log('[T4.remove-card] ok: v1 card upserted');
|
|
1171
|
+
|
|
1172
|
+
// (a) check board-runtime-status includes the new card
|
|
1173
|
+
const t4StatusBeforeRemove = expectMcpSuccess(
|
|
1174
|
+
await httpMcp('inspect.board-runtime-status', {}),
|
|
1175
|
+
'T4.remove-card board-runtime-status before remove',
|
|
1176
|
+
);
|
|
1177
|
+
const t4CardsBefore = Array.isArray(t4StatusBeforeRemove?.cards) ? t4StatusBeforeRemove.cards : [];
|
|
1178
|
+
assert(t4CardsBefore.some(c => c['card-id'] === T4_REMOVE_CARD_ID), 'T4.remove-card: card not found in board-runtime-status before remove');
|
|
1179
|
+
const t4CardCountBefore = t4StatusBeforeRemove?.summary?.card_count ?? 0;
|
|
1180
|
+
console.log(`[T4.remove-card] ok: board-runtime-status has ${t4CardCountBefore} cards before remove (includes ${T4_REMOVE_CARD_ID})`);
|
|
1181
|
+
|
|
1182
|
+
// (b) remove the card — should remove from board and store
|
|
1183
|
+
const t4BoardEventsBefore = NS.boardEvents.length;
|
|
1184
|
+
const t4RemoveRes = await httpMcp('manage.remove-card', { card_id: T4_REMOVE_CARD_ID });
|
|
1185
|
+
assert(t4RemoveRes.status === 200, `T4.remove-card remove returned ${t4RemoveRes.status}`);
|
|
1186
|
+
const t4RemoveData = expectMcpSuccess(t4RemoveRes, 'T4.remove-card remove');
|
|
1187
|
+
assert(t4RemoveData?.board_result?.status === 'success', 'T4.remove-card board_result expected success');
|
|
1188
|
+
assert(t4RemoveData?.store_result?.status === 'success', 'T4.remove-card store_result expected success');
|
|
1189
|
+
console.log('[T4.remove-card] ok: manage.remove-card returned success for both board and store');
|
|
1190
|
+
|
|
1191
|
+
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
1192
|
+
|
|
1193
|
+
// (c) wait for card_removed SSE notification
|
|
1194
|
+
const t4CardRemovedEvent = await waitUntil(
|
|
1195
|
+
() => NS.boardEvents.slice(t4BoardEventsBefore).find(e => e.kind === 'card_removed' && e.cardId === T4_REMOVE_CARD_ID) || false,
|
|
1196
|
+
10_000,
|
|
1197
|
+
`card_removed SSE notification for ${T4_REMOVE_CARD_ID}`,
|
|
1198
|
+
);
|
|
1199
|
+
assert(t4CardRemovedEvent && t4CardRemovedEvent.kind === 'card_removed', 'T4.remove-card: card_removed SSE event not received');
|
|
1200
|
+
assert(t4CardRemovedEvent.cardId === T4_REMOVE_CARD_ID, 'T4.remove-card: card_removed SSE cardId mismatch');
|
|
1201
|
+
console.log(`[T4.remove-card] ok: card_removed SSE notification received for ${T4_REMOVE_CARD_ID}`);
|
|
1202
|
+
|
|
1203
|
+
// (a) verify card is gone from board-runtime-status
|
|
1204
|
+
const t4StatusAfterRemove = expectMcpSuccess(
|
|
1205
|
+
await httpMcp('inspect.board-runtime-status', {}),
|
|
1206
|
+
'T4.remove-card board-runtime-status after remove',
|
|
1207
|
+
);
|
|
1208
|
+
const t4CardsAfter = Array.isArray(t4StatusAfterRemove?.cards) ? t4StatusAfterRemove.cards : [];
|
|
1209
|
+
assert(!t4CardsAfter.some(c => c['card-id'] === T4_REMOVE_CARD_ID), 'T4.remove-card: card still present in board-runtime-status after remove');
|
|
1210
|
+
const t4CardCountAfter = t4StatusAfterRemove?.summary?.card_count ?? 0;
|
|
1211
|
+
assert(t4CardCountAfter === t4CardCountBefore - 1, `T4.remove-card: card_count expected ${t4CardCountBefore - 1}, got ${t4CardCountAfter}`);
|
|
1212
|
+
console.log(`[T4.remove-card] ok: card absent from board-runtime-status after remove (count: ${t4CardCountBefore} → ${t4CardCountAfter})`);
|
|
1213
|
+
|
|
1214
|
+
// (d) upsert a different card content under the same id
|
|
1215
|
+
const t4BoardEventsBeforeV2 = NS.boardEvents.length;
|
|
1216
|
+
const t4UpsertV2Res = await httpMcp('manage.upsert-card', {
|
|
1217
|
+
card_id: T4_REMOVE_CARD_ID,
|
|
1218
|
+
candidate_card_content: T4_REMOVE_CARD_V2,
|
|
1219
|
+
});
|
|
1220
|
+
assert(t4UpsertV2Res.status === 200, `T4.remove-card v2 upsert returned ${t4UpsertV2Res.status}`);
|
|
1221
|
+
const t4UpsertV2Data = expectMcpSuccess(t4UpsertV2Res, 'T4.remove-card v2 upsert');
|
|
1222
|
+
assert(t4UpsertV2Data?.board_result?.status === 'success', 'T4.remove-card v2 upsert board_result expected success');
|
|
1223
|
+
console.log('[T4.remove-card] ok: v2 card upserted under same id');
|
|
1224
|
+
|
|
1225
|
+
// (c) wait for card_refreshed SSE notification confirming v2 is live
|
|
1226
|
+
const t4CardRefreshedEvent = await waitUntil(
|
|
1227
|
+
() => NS.boardEvents.slice(t4BoardEventsBeforeV2).find(e => e.kind === 'card_refreshed' && e.cardId === T4_REMOVE_CARD_ID) || false,
|
|
1228
|
+
10_000,
|
|
1229
|
+
`card_refreshed SSE notification for ${T4_REMOVE_CARD_ID} after v2 upsert`,
|
|
1230
|
+
);
|
|
1231
|
+
assert(t4CardRefreshedEvent && t4CardRefreshedEvent.kind === 'card_refreshed', 'T4.remove-card: card_refreshed SSE event not received after v2 upsert');
|
|
1232
|
+
console.log(`[T4.remove-card] ok: card_refreshed SSE notification received for v2 of ${T4_REMOVE_CARD_ID}`);
|
|
1233
|
+
|
|
1234
|
+
await waitForAllCompleted(30_000, 'T4 remove-card re-upsert completion');
|
|
1235
|
+
|
|
1236
|
+
// (e) verify board-runtime-status shows the card again, and inspect returns v2 card_data
|
|
1237
|
+
const t4StatusAfterV2 = expectMcpSuccess(
|
|
1238
|
+
await httpMcp('inspect.board-runtime-status', {}),
|
|
1239
|
+
'T4.remove-card board-runtime-status after v2 upsert',
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
const t4CardsAfterV2 = Array.isArray(t4StatusAfterV2?.cards) ? t4StatusAfterV2.cards : [];
|
|
1243
|
+
assert(t4CardsAfterV2.some(c => c['card-id'] === T4_REMOVE_CARD_ID), 'T4.remove-card: v2 card missing from board-runtime-status');
|
|
1244
|
+
const t4CardCountAfterV2 = t4StatusAfterV2?.summary?.card_count ?? 0;
|
|
1245
|
+
assert(t4CardCountAfterV2 === t4CardCountBefore, `T4.remove-card: card_count after v2 upsert expected ${t4CardCountBefore}, got ${t4CardCountAfterV2}`);
|
|
1246
|
+
console.log('[T4.remove-card] ok: v2 card present in board-runtime-status');
|
|
1247
|
+
|
|
1248
|
+
const t4InspectV2Data = expectMcpSuccess(
|
|
1249
|
+
await httpMcp('inspect.card-definition-and-runtime', { card_id: T4_REMOVE_CARD_ID }),
|
|
1250
|
+
'T4.remove-card inspect v2',
|
|
1251
|
+
);
|
|
1252
|
+
assert(t4InspectV2Data?.cardId === T4_REMOVE_CARD_ID, 'T4.remove-card inspect v2 cardId mismatch');
|
|
1253
|
+
const t4V2CardData = t4InspectV2Data?.card_definition_and_static_data?.card_data ?? null;
|
|
1254
|
+
assert(t4V2CardData?.label === 'v2', `T4.remove-card inspect v2 label expected "v2", got "${t4V2CardData?.label}"`);
|
|
1255
|
+
assert(t4V2CardData?.color === 'red', `T4.remove-card inspect v2 color expected "red", got "${t4V2CardData?.color}"`);
|
|
1256
|
+
console.log('[T4.remove-card] ok: inspect.card-definition-and-runtime reflects v2 card_data after re-upsert');
|
|
1257
|
+
|
|
1258
|
+
// clean up
|
|
1259
|
+
await httpMcp('manage.remove-card', { card_id: T4_REMOVE_CARD_ID });
|
|
1260
|
+
console.log('[T4.remove-card] cleanup done');
|
|
1261
|
+
|
|
1130
1262
|
}
|
|
1131
1263
|
|
|
1132
1264
|
console.log('\n=== All smoke checks passed ===\n');
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
<title>Example Board Demo (LocalStorage Runtime)</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="../../browser/favicon.svg" />
|
|
8
8
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/compute-jsonata.js"></script>
|
|
10
10
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
11
11
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
12
12
|
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
|
|
13
13
|
<script src="https://cdn.jsdelivr.net/npm/leader-line/leader-line.min.js"></script>
|
|
14
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
15
|
-
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/live-cards.js"></script>
|
|
15
|
+
<script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.3/browser/board-livecards-localstorage.js"></script>
|
|
16
16
|
</head>
|
|
17
17
|
<body class="bg-light">
|
|
18
18
|
<div class="container-fluid py-3">
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var module$1=require('module');require('ajv-formats');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var ae=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('board-live-cards-mcp.cjs', document.baseURI).href)));ae("./jsonata-sync.cjs");var de=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('board-live-cards-mcp.cjs', document.baseURI).href))),L=de("./jsonata-sync.cjs"),V=L;function D(e,r){if(!r||!e)return;let s=r.split("."),t=e;for(let a=0;a<s.length;a++){if(t==null)return;t=t[s[a]];}return t}function K(e,r,s){let t=r.split("."),a=e;for(let c=0;c<t.length-1;c++)(a[t[c]]==null||typeof a[t[c]]!="object")&&(a[t[c]]={}),a=a[t[c]];a[t[t.length-1]]=s;}async function ce(e,r){if(!e?.compute?.length)return e;e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values};for(let a of e.compute)try{let c=await L(a.expr).evaluate(t);K(e.computed_values,a.bindTo,c),t.computed_values=e.computed_values;}catch{}return e}function ue(e,r){if(!e?.compute?.length)return {ok:true,node:e};e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values},a=[];for(let c of e.compute)try{let l=V(c.expr).evaluate(t);K(e.computed_values,c.bindTo,l),t.computed_values=e.computed_values;}catch(l){let m=l instanceof Error?l.message:String(l);a.push({bindTo:c.bindTo,error:m});}return a.length>0?{ok:true,node:e,errors:a}:{ok:true,node:e}}async function pe(e,r,s){let t={...s??{},card_data:r.card_data??{},requires:r.requires??{},fetched_sources:r._sourcesData??{},computed_values:r.computed_values??{}};return L(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?D(e._sourcesData??{},r.slice(16)):D(e,r)}var P=new Set(["metric","table","editable-table","chart","form","filter","list","notes","todo","alert","narrative","badge","text","markdown","ref","custom","actions"]),fe=new Set(["id","meta","requires","provides","view","card_data","compute","source_defs"]);function me(e){let r=[];if(!e||typeof e!="object"||Array.isArray(e))return {ok:false,errors:["Node must be a non-null object"]};let s=e;(typeof s.id!="string"||!s.id)&&r.push("id: required, must be a non-empty string");for(let t of Object.keys(s))fe.has(t)||r.push(`Unknown top-level key: "${t}"`);if((s.card_data==null||typeof s.card_data!="object"||Array.isArray(s.card_data))&&r.push("card_data: required, must be an object"),s.meta!=null)if(typeof s.meta!="object"||Array.isArray(s.meta))r.push("meta: must be an object");else {let t=s.meta;t.title!=null&&typeof t.title!="string"&&r.push("meta.title: must be a string"),t.tags!=null&&!Array.isArray(t.tags)&&r.push("meta.tags: must be an array");}if(s.requires!=null&&!Array.isArray(s.requires)&&r.push("requires: must be an array of strings"),s.provides!=null&&(Array.isArray(s.provides)?s.provides.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`provides[${a}]: must be an object with bindTo and ref`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`provides[${a}]: missing required "bindTo" string`),(typeof c.ref!="string"||!c.ref)&&r.push(`provides[${a}]: missing required "ref" string`);}}):r.push("provides: must be an array of { bindTo, ref } bindings")),s.compute!=null&&(Array.isArray(s.compute)?s.compute.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`compute[${a}]: must be a compute step object`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`compute[${a}]: missing required "bindTo" property`),(typeof c.expr!="string"||!c.expr)&&r.push(`compute[${a}]: missing required "expr" string (JSONata expression)`);}}):r.push("compute: must be an array of compute steps")),s.source_defs!=null)if(!Array.isArray(s.source_defs))r.push("source_defs: must be an array");else {let t=new Set,a=new Set;s.source_defs.forEach((c,l)=>{if(!c||typeof c!="object"||Array.isArray(c))r.push(`source_defs[${l}]: must be an object`);else {let m=c;typeof m.bindTo!="string"||!m.bindTo?r.push(`source_defs[${l}]: missing required "bindTo" property`):(t.has(m.bindTo)&&r.push(`source_defs[${l}]: bindTo "${m.bindTo}" is not unique across source_defs`),t.add(m.bindTo)),typeof m.outputFile!="string"||!m.outputFile?r.push(`source_defs[${l}]: missing required "outputFile" property`):(a.has(m.outputFile)&&r.push(`source_defs[${l}]: outputFile "${m.outputFile}" is not unique across source_defs`),a.add(m.outputFile)),m.optionalForCompletionGating!=null&&typeof m.optionalForCompletionGating!="boolean"&&r.push(`source_defs[${l}]: optionalForCompletionGating must be a boolean`);}});}if(s.view!=null)if(typeof s.view!="object"||Array.isArray(s.view))r.push("view: must be an object");else {let t=s.view;!Array.isArray(t.elements)||t.elements.length===0?r.push("view.elements: required, must be a non-empty array"):t.elements.forEach((a,c)=>{if(!a||typeof a!="object"){r.push(`view.elements[${c}]: must be an object`);return}!a.kind||typeof a.kind!="string"?r.push(`view.elements[${c}].kind: required, must be a string`):P.has(a.kind)||r.push(`view.elements[${c}].kind: unknown kind "${a.kind}". Valid: ${[...P].join(", ")}`),a.data!=null&&(typeof a.data!="object"||Array.isArray(a.data))&&r.push(`view.elements[${c}].data: must be an object`);}),t.layout!=null&&(typeof t.layout!="object"||Array.isArray(t.layout))&&r.push("view.layout: must be an object"),t.features!=null&&(typeof t.features!="object"||Array.isArray(t.features))&&r.push("view.features: must be an object");}return {ok:r.length===0,errors:r}}async function ge(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return Promise.all(e.map(async t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=await L(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}}))}function ye(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return e.map(t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=V(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}})}var z={run:ce,runSync:ue,eval:pe,resolve:le,validate:me,enrichSources:ge,enrichSourcesSync:ye};function _(e,r){if(e?.status==="success")return Object.prototype.hasOwnProperty.call(e,"data")?e.data:void 0;throw e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function we(e,r){if(e?.status==="success"&&Object.prototype.hasOwnProperty.call(e,"data"))return e.data;throw e?.status==="success"?new Error(`${r} returned success without data`):e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function d(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function C(e){return Array.isArray(e)?e:[]}function O(e,r){if(typeof r!="string"||r.length===0)return;let s=e,t=r;t.startsWith("fetched_sources.")&&(s=d(e).fetched_sources,t=t.slice(16));for(let a of t.split(".")){if(s==null||typeof s!="object")return;s=s[a];}return s}function F(e,r){let s=d(e.view),t=C(s.elements);return {layout:s.layout,features:s.features,elements:t.map((a,c)=>{let l=d(a),m=d(l.data),q=typeof l.visible=="string"?!!O(r,l.visible):true,S=typeof m.bind=="string"?m.bind:void 0,I=S?O(r,S):void 0,x={id:typeof l.id=="string"&&l.id?l.id:`element-${c}`,kind:l.kind,label:l.label,visible:q};return S&&(x.bind=S),Array.isArray(m.columns)&&(x.columns=m.columns),typeof m.maxRows=="number"&&(x.maxRows=m.maxRows),I!==void 0&&(x.resolved=Array.isArray(I)&&typeof x.maxRows=="number"?I.slice(0,x.maxRows):I),x})}}function W(e,r){let s=typeof e.id=="string"&&e.id?e.id:"card",t=C(e.provides),a=t.length>0?t:[{bindTo:s,ref:"card_data"}],c={};for(let l of a){let m=d(l),q=typeof m.bindTo=="string"?m.bindTo:"",S=typeof m.ref=="string"?m.ref:"";if(!q||!S)continue;let I=O(r,S);I!==void 0&&(c[q]=I);}return c}function be(e){if(typeof e!="string"||!e.trim())return null;let r=/^(file uploaded|AI generated|AI geneterated):\s*.*?#(\d+)\s*$/i.exec(e.trim());if(!r)return null;let s=Number.parseInt(r[2],10);return !Number.isInteger(s)||s<0?null:s}function Ce(e){return {"card-content":e}}function M(e,r){let s=_(e.get({params:{id:r}}),"cardStore.get"),t=Array.isArray(s?.cards)?s.cards:[];if(t.length===0)throw new Error(`Card "${r}" not found`);return t[0]}function $e(e){let{board:r,nonCore:s,cardStore:t,chatStore:a,uploadCardFile:c,buildFileDownloadUrl:l,readFetchedSourceJsonByRef:m}=e;function q(n){if(Array.isArray(n.bytes))return new Uint8Array(n.bytes.map(o=>Math.max(0,Math.min(255,Number(o)||0))));if(typeof n.text=="string")return new TextEncoder().encode(n.text);if(typeof n.base64=="string"){let o=String(n.base64).replace(/-/g,"+").replace(/_/g,"/"),i=o+"=".repeat((4-o.length%4)%4),g=atob(i);return Uint8Array.from(g,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function S(){let n=d(_(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function I(){let n=d(_(r.status({}),"status")),o=d(n.summary),i=C(n.cards);return {meta:d(n.meta),summary:{card_count:typeof o.card_count=="number"?o.card_count:0,completed:typeof o.completed=="number"?o.completed:0,eligible:typeof o.eligible=="number"?o.eligible:0,pending:typeof o.pending=="number"?o.pending:0,blocked:typeof o.blocked=="number"?o.blocked:0,in_progress:typeof o.in_progress=="number"?o.in_progress:0,failed:typeof o.failed=="number"?o.failed:0,unresolved:typeof o.unresolved=="number"?o.unresolved:0},cards:i.map(g=>{let u=d(g);return {"card-id":typeof u.name=="string"?u.name:null,status:u.status??null,error:u.error??null,requires:C(u.requires),requires_satisfied:C(u.requires_satisfied),requires_missing:C(u.requires_missing),provides_declared:C(u.provides_declared),provides_runtime:C(u.provides_runtime)}})}}function x(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectCardDefinitionAndRuntime requires cardId");let i=d(_(r.status({}),"status")),u=C(i.cards).map(d).find(f=>f.name===o);if(!u)throw new Error(`card "${o}" not found in board status`);let p=d(M(t,o)),y=C(u.requires_satisfied).filter(f=>typeof f=="string"&&!!f),v=C(u.provides_runtime).filter(f=>typeof f=="string"&&!!f),w=Object.fromEntries(y.map(f=>[f,_(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),h=Object.fromEntries(v.map(f=>[f,_(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),R=d(_(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),b=_(r.getOutputsFetchedSources({params:{key:o}}),"getOutputsFetchedSources"),j=C(p.source_defs).map(d),A={};for(let f of j)typeof f.bindTo=="string"&&typeof f.outputFile=="string"&&(A[f.outputFile]=f.bindTo);let k={};for(let[f,T]of Object.entries(b)){let E=A[f]??f;if(!m||typeof T!="string"){k[E]=null;continue}try{k[E]=m({cardId:o,ref:T});}catch{k[E]=null;}}let $={card_data:d(p.card_data),requires:w,fetched_sources:k,computed_values:R};return {cardId:o,card_status_in_board:u,card_definition_and_static_data:p,refs_for_fetched_source_files:b,runtime_data:{requires:w,provides:h,computed_values:R,rendered_view:F(p,$)}}}function J(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectChatMessagesOnCards requires cardId");let i=typeof n.turnId=="string"?n.turnId:"",g=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=g?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,v={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...g?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},w=Object.keys(v).length>0?{params:{cardId:o},body:v}:{params:{cardId:o}},h=_(a.readAll(w),"chatStore.readAll"),R=d(M(t,o)),b=C(d(R.card_data).files).map((k,$)=>({idx:$,stored_name:d(k).stored_name})).filter(k=>typeof k.stored_name=="string"&&k.stored_name.length>0),A=(Array.isArray(h.records)?h.records:[]).map(k=>{let f=d(k.payload),T={...k},E=typeof k?.role=="string"?k.role:typeof f.role=="string"?String(f.role):"",oe=typeof k?.text=="string"?k.text:typeof f.text=="string"?String(f.text):"";if(E==="system"){let B=be(oe);if(B!==null&&b.some(U=>U.idx===B)){let U=`Retrieve using inspect-file-contents --card-id ${o} --file-idx ${B}`;T.retrieval_hint=U,Object.keys(f).length>0&&typeof k.role!="string"&&(T.payload={...f,retrieval_hint:U});}}return T});return {cardId:o,messages:typeof y=="number"&&y>=0?A.slice(-y):A}}function G(n){let o=String(n.cardId||"").trim(),i=Number(n.fileIdx);if(!o)throw new Error("inspectFileContents requires cardId");if(!Number.isInteger(i)||i<0)throw new Error("inspectFileContents requires fileIdx to be a non-negative integer");let g=d(M(t,o)),u=C(d(g.card_data).files).map(d);if(i>=u.length)throw new Error(`attachment index ${i} is out of range for card "${o}"`);let p=u[i],y=typeof p.stored_name=="string"?p.stored_name:null;return {cardId:o,fileIdx:i,downloadUrl:l({cardId:o,fileIdx:i,storedName:y}),...typeof p.name=="string"?{name:p.name}:{},...typeof p.stored_name=="string"?{stored_name:p.stored_name}:{},...typeof p.mime_type=="string"?{mime_type:p.mime_type}:{},...typeof p.size=="number"?{size:p.size}:{},...typeof p.uploaded_at=="string"?{uploaded_at:p.uploaded_at}:{}}}function N(n){return s.validateCardPreflight({body:Ce(n.candidateCardContent)})}function H(n){if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightMaterializeCandidateCard requires mockRequires");if(!n.mockFetchedSources||typeof n.mockFetchedSources!="object"||Array.isArray(n.mockFetchedSources))throw new Error("preflightMaterializeCandidateCard requires mockFetchedSources");let o=s.evalCardCompute({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires,"mock-fetched-sources":n.mockFetchedSources}});if(o.status!=="success")return o;let i=d(we(o,"evalCardCompute")),g=d(n.candidateCardContent),u={card_data:d(g.card_data),requires:d(n.mockRequires),fetched_sources:d(n.mockFetchedSources),computed_values:d(i.computed_values)};return {status:"success",data:{cardId:typeof i.cardId=="string"?i.cardId:typeof g.id=="string"?g.id:"(unknown)",ok:i.ok===true,computed_values:d(i.computed_values),errors:C(i.errors).map(p=>{let y=d(p);return {bindTo:typeof y.bindTo=="string"?y.bindTo:"",error:typeof y.error=="string"?y.error:""}}),provides_outputs:W(g,u),rendered_view:F(g,u)}}}function Y(n){return s.probeSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function Q(n){return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function X(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("preflightRunSingleSourceInLiveCard requires cardId");if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightRunSingleSourceInLiveCard requires mockRequires");let i=d(M(t,o)),g=C(i.source_defs).filter(p=>!!p&&typeof p=="object"&&!Array.isArray(p)),u={};if(n.sourceIdx>=0&&n.sourceIdx<g.length){let p=g[n.sourceIdx],y=z.enrichSourcesSync([p],{card_data:d(i.card_data),requires:n.mockRequires});Array.isArray(y)&&y.length>0&&(u=d(y[0]._projections));}return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":i,"mock-requires":n.mockRequires,"mock-projections":u}})}function Z(n){let o=d(_(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),g=d(o.validation),u=C(o.source_probes),p=C(o.projection_errors),y=C(o.compute_errors),v=d(o.computed_values),w={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:{},computed_values:v},h=[];for(let R of C(g.issues))typeof R=="string"&&R&&h.push(R);for(let R of u){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"source",A=typeof b.error=="string"?b.error:"";A&&h.push(`${j}: ${A}`);}for(let R of p){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"source",A=typeof b.key=="string"?b.key:"projection",k=typeof b.error=="string"?b.error:"projection failed";h.push(`${j}.${A}: ${k}`);}for(let R of y){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"compute",A=typeof b.error=="string"?b.error:"compute failed";h.push(`${j}: ${A}`);}return {status:"success",data:{cardId:typeof o.cardId=="string"?o.cardId:"(unknown)",ok:o.ok===true,issues:h,provides_outputs:W(i,w),rendered_view:F(i,w)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=_(t.get({params:{id:o}}),"cardStore.get");return Array.isArray(i.cards)?i.cards:[]}function re(n){let o=String(n.cardId||"").trim(),i=String(n.role||"").trim(),g=typeof n.text=="string"?n.text:"",u=typeof n.turn=="string"?n.turn:"";if(!o)throw new Error("manageAddChatEntryAndAnyAttachments requires cardId");if(!i)throw new Error("manageAddChatEntryAndAnyAttachments requires role");let p=C(n.files).map(v=>{let w=d(v),h=String(w.file_name??w.fileName??w.name??"").trim(),R=String(w.content_type??w.contentType??"application/octet-stream");if(!h)throw new Error("file entry requires file_name");return c({cardId:o,fileName:h,contentType:R,bytes:q(w)}).file});p.forEach((v,w)=>{let h=i==="assistant"?`AI generated: ${String(v.name||"")} as ${String(v.stored_name||"")} #${w}`:`file uploaded: ${String(v.name||"")} as ${String(v.stored_name||"")} #${w}`;_(a.append({params:{cardId:o},body:{role:"system",text:h,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=_(a.append({params:{cardId:o},body:{role:i,text:g,files:p,turn:u}}),"chatStore.append");return {status:"success",data:{cardId:o,id:String(y.id),role:i,turn:u,files:p}}}function te(n){let o=String(n.cardId||"").trim(),i=d(n.candidateCardContent);if(!o)throw new Error("manageUpsertCard requires cardId");if(typeof i.id!="string"||!i.id.trim())throw new Error("candidateCardContent.id must be a non-empty string");if(i.id!==o)throw new Error(`candidateCardContent.id must match cardId (${o})`);let g=N({candidateCardContent:i}),u=d(g),p=d(u.data);if(u.status!=="success"||p.isValid!==true)return {status:"fail",step:"validate",validation:g};let y=null;try{y=M(t,o);}catch{y=null;}let v=t.set({body:i});_(v,"cardStore.set");let w;try{w=r.upsertCard({params:{cardId:o,restart:!0}}),_(w,"upsertCard");}catch(R){try{y&&t.set({body:y});}catch{}throw R}let h=null;try{h=r.cardRefreshedNotify({params:{cardId:o}}),_(h,"cardRefreshedNotify");}catch{h=null;}return {status:"success",data:{validation:g,card_saved:null,board_result:w,refresh_notify:h}}}function ne(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageDeprecate requires cardId");let i=r.removeCard({params:{id:o}});return _(i,"removeCard"),i}return {discoverSourceKinds:S,inspectBoardRuntimeStatus:I,inspectCardDefinitionAndRuntime:x,inspectChatMessagesOnCards:J,inspectFileContents:G,preflightValidateCandidateCardDefinition:N,preflightMaterializeCandidateCard:H,preflightProbeSingleSourceInCandidateCard:Y,preflightRunSingleSourceInCandidateCard:Q,preflightRunSingleSourceInLiveCard:X,preflightRunOneCycleWithCandidateCard:Z,manageReadCard:ee,manageAddChatEntryAndAnyAttachments:re,manageUpsertCard:te,manageDeprecate:ne}}exports.createBoardLiveCardsMcp=$e;//# sourceMappingURL=board-live-cards-mcp.cjs.map
|
|
1
|
+
'use strict';var module$1=require('module');require('ajv-formats');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var ae=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('board-live-cards-mcp.cjs', document.baseURI).href)));ae("./jsonata-sync.cjs");var de=module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('board-live-cards-mcp.cjs', document.baseURI).href))),B=de("./jsonata-sync.cjs"),K=B;function D(e,r){if(!r||!e)return;let s=r.split("."),t=e;for(let a=0;a<s.length;a++){if(t==null)return;t=t[s[a]];}return t}function z(e,r,s){let t=r.split("."),a=e;for(let c=0;c<t.length-1;c++)(a[t[c]]==null||typeof a[t[c]]!="object")&&(a[t[c]]={}),a=a[t[c]];a[t[t.length-1]]=s;}async function ce(e,r){if(!e?.compute?.length)return e;e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values};for(let a of e.compute)try{let c=await B(a.expr).evaluate(t);z(e.computed_values,a.bindTo,c),t.computed_values=e.computed_values;}catch{}return e}function ue(e,r){if(!e?.compute?.length)return {ok:true,node:e};e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values},a=[];for(let c of e.compute)try{let l=K(c.expr).evaluate(t);z(e.computed_values,c.bindTo,l),t.computed_values=e.computed_values;}catch(l){let g=l instanceof Error?l.message:String(l);a.push({bindTo:c.bindTo,error:g});}return a.length>0?{ok:true,node:e,errors:a}:{ok:true,node:e}}async function pe(e,r,s){let t={...s??{},card_data:r.card_data??{},requires:r.requires??{},fetched_sources:r._sourcesData??{},computed_values:r.computed_values??{}};return B(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?D(e._sourcesData??{},r.slice(16)):D(e,r)}var V=new Set(["metric","table","editable-table","chart","form","filter","list","notes","todo","alert","narrative","badge","text","markdown","ref","custom","actions"]),fe=new Set(["id","meta","requires","provides","view","card_data","compute","source_defs"]);function me(e){let r=[];if(!e||typeof e!="object"||Array.isArray(e))return {ok:false,errors:["Node must be a non-null object"]};let s=e;(typeof s.id!="string"||!s.id)&&r.push("id: required, must be a non-empty string");for(let t of Object.keys(s))fe.has(t)||r.push(`Unknown top-level key: "${t}"`);if((s.card_data==null||typeof s.card_data!="object"||Array.isArray(s.card_data))&&r.push("card_data: required, must be an object"),s.meta!=null)if(typeof s.meta!="object"||Array.isArray(s.meta))r.push("meta: must be an object");else {let t=s.meta;t.title!=null&&typeof t.title!="string"&&r.push("meta.title: must be a string"),t.tags!=null&&!Array.isArray(t.tags)&&r.push("meta.tags: must be an array");}if(s.requires!=null&&!Array.isArray(s.requires)&&r.push("requires: must be an array of strings"),s.provides!=null&&(Array.isArray(s.provides)?s.provides.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`provides[${a}]: must be an object with bindTo and ref`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`provides[${a}]: missing required "bindTo" string`),(typeof c.ref!="string"||!c.ref)&&r.push(`provides[${a}]: missing required "ref" string`);}}):r.push("provides: must be an array of { bindTo, ref } bindings")),s.compute!=null&&(Array.isArray(s.compute)?s.compute.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`compute[${a}]: must be a compute step object`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`compute[${a}]: missing required "bindTo" property`),(typeof c.expr!="string"||!c.expr)&&r.push(`compute[${a}]: missing required "expr" string (JSONata expression)`);}}):r.push("compute: must be an array of compute steps")),s.source_defs!=null)if(!Array.isArray(s.source_defs))r.push("source_defs: must be an array");else {let t=new Set,a=new Set;s.source_defs.forEach((c,l)=>{if(!c||typeof c!="object"||Array.isArray(c))r.push(`source_defs[${l}]: must be an object`);else {let g=c;typeof g.bindTo!="string"||!g.bindTo?r.push(`source_defs[${l}]: missing required "bindTo" property`):(t.has(g.bindTo)&&r.push(`source_defs[${l}]: bindTo "${g.bindTo}" is not unique across source_defs`),t.add(g.bindTo)),typeof g.outputFile!="string"||!g.outputFile?r.push(`source_defs[${l}]: missing required "outputFile" property`):(a.has(g.outputFile)&&r.push(`source_defs[${l}]: outputFile "${g.outputFile}" is not unique across source_defs`),a.add(g.outputFile)),g.optionalForCompletionGating!=null&&typeof g.optionalForCompletionGating!="boolean"&&r.push(`source_defs[${l}]: optionalForCompletionGating must be a boolean`);}});}if(s.view!=null)if(typeof s.view!="object"||Array.isArray(s.view))r.push("view: must be an object");else {let t=s.view;!Array.isArray(t.elements)||t.elements.length===0?r.push("view.elements: required, must be a non-empty array"):t.elements.forEach((a,c)=>{if(!a||typeof a!="object"){r.push(`view.elements[${c}]: must be an object`);return}!a.kind||typeof a.kind!="string"?r.push(`view.elements[${c}].kind: required, must be a string`):V.has(a.kind)||r.push(`view.elements[${c}].kind: unknown kind "${a.kind}". Valid: ${[...V].join(", ")}`),a.data!=null&&(typeof a.data!="object"||Array.isArray(a.data))&&r.push(`view.elements[${c}].data: must be an object`);}),t.layout!=null&&(typeof t.layout!="object"||Array.isArray(t.layout))&&r.push("view.layout: must be an object"),t.features!=null&&(typeof t.features!="object"||Array.isArray(t.features))&&r.push("view.features: must be an object");}return {ok:r.length===0,errors:r}}async function ge(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return Promise.all(e.map(async t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=await B(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}}))}function ye(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return e.map(t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=K(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}})}var W={run:ce,runSync:ue,eval:pe,resolve:le,validate:me,enrichSources:ge,enrichSourcesSync:ye};function k(e,r){if(e?.status==="success")return Object.prototype.hasOwnProperty.call(e,"data")?e.data:void 0;throw e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function we(e,r){if(e?.status==="success"&&Object.prototype.hasOwnProperty.call(e,"data"))return e.data;throw e?.status==="success"?new Error(`${r} returned success without data`):e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function d(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function b(e){return Array.isArray(e)?e:[]}function N(e,r){if(typeof r!="string"||r.length===0)return;let s=e,t=r;t.startsWith("fetched_sources.")&&(s=d(e).fetched_sources,t=t.slice(16));for(let a of t.split(".")){if(s==null||typeof s!="object")return;s=s[a];}return s}function O(e,r){let s=d(e.view),t=b(s.elements);return {layout:s.layout,features:s.features,elements:t.map((a,c)=>{let l=d(a),g=d(l.data),j=typeof l.visible=="string"?!!N(r,l.visible):true,I=typeof g.bind=="string"?g.bind:void 0,x=typeof g.maxRows=="number"?g.maxRows:void 0,q=I?N(r,I):void 0,U={id:typeof l.id=="string"&&l.id?l.id:`element-${c}`,kind:l.kind,label:l.label,visible:j};return q!==void 0&&(U.resolved=Array.isArray(q)&&typeof x=="number"?q.slice(0,x):q),U})}}function J(e,r){let s=typeof e.id=="string"&&e.id?e.id:"card",t=b(e.provides),a=t.length>0?t:[{bindTo:s,ref:"card_data"}],c={};for(let l of a){let g=d(l),j=typeof g.bindTo=="string"?g.bindTo:"",I=typeof g.ref=="string"?g.ref:"";if(!j||!I)continue;let x=N(r,I);x!==void 0&&(c[j]=x);}return c}function be(e){if(typeof e!="string"||!e.trim())return null;let r=/^(file uploaded|AI generated|AI geneterated):\s*.*?#(\d+)\s*$/i.exec(e.trim());if(!r)return null;let s=Number.parseInt(r[2],10);return !Number.isInteger(s)||s<0?null:s}function Ce(e){return {"card-content":e}}function $(e,r){let s=k(e.get({params:{id:r}}),"cardStore.get"),t=Array.isArray(s?.cards)?s.cards:[];if(t.length===0)throw new Error(`Card "${r}" not found`);return t[0]}function $e(e){let{board:r,nonCore:s,cardStore:t,chatStore:a,uploadCardFile:c,buildFileDownloadUrl:l,readFetchedSourceJsonByRef:g}=e;function j(n){if(Array.isArray(n.bytes))return new Uint8Array(n.bytes.map(o=>Math.max(0,Math.min(255,Number(o)||0))));if(typeof n.text=="string")return new TextEncoder().encode(n.text);if(typeof n.base64=="string"){let o=String(n.base64).replace(/-/g,"+").replace(/_/g,"/"),i=o+"=".repeat((4-o.length%4)%4),m=atob(i);return Uint8Array.from(m,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function I(){let n=d(k(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function x(){let n=d(k(r.status({}),"status")),o=d(n.summary),i=b(n.cards);return {meta:d(n.meta),summary:{card_count:typeof o.card_count=="number"?o.card_count:0,completed:typeof o.completed=="number"?o.completed:0,eligible:typeof o.eligible=="number"?o.eligible:0,pending:typeof o.pending=="number"?o.pending:0,blocked:typeof o.blocked=="number"?o.blocked:0,in_progress:typeof o.in_progress=="number"?o.in_progress:0,failed:typeof o.failed=="number"?o.failed:0,unresolved:typeof o.unresolved=="number"?o.unresolved:0},cards:i.map(m=>{let u=d(m);return {"card-id":typeof u.name=="string"?u.name:null,status:u.status??null,error:u.error??null,requires:b(u.requires),requires_satisfied:b(u.requires_satisfied),requires_missing:b(u.requires_missing),provides_declared:b(u.provides_declared),provides_runtime:b(u.provides_runtime)}})}}function q(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectCardDefinitionAndRuntime requires cardId");let i=d(k(r.status({}),"status")),u=b(i.cards).map(d).find(f=>f.name===o);if(!u)throw new Error(`card "${o}" not found in board status`);let p=d($(t,o)),y=b(u.requires_satisfied).filter(f=>typeof f=="string"&&!!f),_=b(u.provides_runtime).filter(f=>typeof f=="string"&&!!f),C=Object.fromEntries(y.map(f=>[f,k(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),R=Object.fromEntries(_.map(f=>[f,k(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),v=d(k(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),A=k(r.getOutputsFetchedSources({params:{key:o}}),"getOutputsFetchedSources"),h=b(p.source_defs).map(d),S={};for(let f of h)typeof f.bindTo=="string"&&typeof f.outputFile=="string"&&(S[f.outputFile]=f.bindTo);let w={};for(let[f,E]of Object.entries(A)){let M=S[f]??f;if(!g||typeof E!="string"){w[M]=null;continue}try{w[M]=g({cardId:o,ref:E});}catch{w[M]=null;}}let T={card_data:d(p.card_data),requires:C,fetched_sources:w,computed_values:v};return {cardId:o,card_status_in_board:u,card_definition_and_static_data:p,refs_for_fetched_source_files:A,runtime_data:{requires:C,provides:R,computed_values:v,rendered_view:O(p,T)}}}function U(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectChatMessagesOnCards requires cardId");let i=typeof n.turnId=="string"?n.turnId:"",m=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=m?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,_={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...m?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},C=Object.keys(_).length>0?{params:{cardId:o},body:_}:{params:{cardId:o}},R=k(a.readAll(C),"chatStore.readAll"),v=d($(t,o)),A=b(d(v.card_data).files).map((w,T)=>({idx:T,stored_name:d(w).stored_name})).filter(w=>typeof w.stored_name=="string"&&w.stored_name.length>0),S=(Array.isArray(R.records)?R.records:[]).map(w=>{let f=d(w.payload),E={...w},M=typeof w?.role=="string"?w.role:typeof f.role=="string"?String(f.role):"",oe=typeof w?.text=="string"?w.text:typeof f.text=="string"?String(f.text):"";if(M==="system"){let F=be(oe);if(F!==null&&A.some(L=>L.idx===F)){let L=`Retrieve using inspect-file-contents --card-id ${o} --file-idx ${F}`;E.retrieval_hint=L,Object.keys(f).length>0&&typeof w.role!="string"&&(E.payload={...f,retrieval_hint:L});}}return E});return {cardId:o,messages:typeof y=="number"&&y>=0?S.slice(-y):S}}function G(n){let o=String(n.cardId||"").trim(),i=Number(n.fileIdx);if(!o)throw new Error("inspectFileContents requires cardId");if(!Number.isInteger(i)||i<0)throw new Error("inspectFileContents requires fileIdx to be a non-negative integer");let m=d($(t,o)),u=b(d(m.card_data).files).map(d);if(i>=u.length)throw new Error(`attachment index ${i} is out of range for card "${o}"`);let p=u[i],y=typeof p.stored_name=="string"?p.stored_name:null;return {cardId:o,fileIdx:i,downloadUrl:l({cardId:o,fileIdx:i,storedName:y}),...typeof p.name=="string"?{name:p.name}:{},...typeof p.stored_name=="string"?{stored_name:p.stored_name}:{},...typeof p.mime_type=="string"?{mime_type:p.mime_type}:{},...typeof p.size=="number"?{size:p.size}:{},...typeof p.uploaded_at=="string"?{uploaded_at:p.uploaded_at}:{}}}function P(n){return s.validateCardPreflight({body:Ce(n.candidateCardContent)})}function H(n){if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightMaterializeCandidateCard requires mockRequires");if(!n.mockFetchedSources||typeof n.mockFetchedSources!="object"||Array.isArray(n.mockFetchedSources))throw new Error("preflightMaterializeCandidateCard requires mockFetchedSources");let o=s.evalCardCompute({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires,"mock-fetched-sources":n.mockFetchedSources}});if(o.status!=="success")return o;let i=d(we(o,"evalCardCompute")),m=d(n.candidateCardContent),u={card_data:d(m.card_data),requires:d(n.mockRequires),fetched_sources:d(n.mockFetchedSources),computed_values:d(i.computed_values)};return {status:"success",data:{cardId:typeof i.cardId=="string"?i.cardId:typeof m.id=="string"?m.id:"(unknown)",ok:i.ok===true,computed_values:d(i.computed_values),errors:b(i.errors).map(p=>{let y=d(p);return {bindTo:typeof y.bindTo=="string"?y.bindTo:"",error:typeof y.error=="string"?y.error:""}}),provides_outputs:J(m,u),rendered_view:O(m,u)}}}function Y(n){return s.probeSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function Q(n){return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function X(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("preflightRunSingleSourceInLiveCard requires cardId");if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightRunSingleSourceInLiveCard requires mockRequires");let i=d($(t,o)),m=b(i.source_defs).filter(p=>!!p&&typeof p=="object"&&!Array.isArray(p)),u={};if(n.sourceIdx>=0&&n.sourceIdx<m.length){let p=m[n.sourceIdx],y=W.enrichSourcesSync([p],{card_data:d(i.card_data),requires:n.mockRequires});Array.isArray(y)&&y.length>0&&(u=d(y[0]._projections));}return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":i,"mock-requires":n.mockRequires,"mock-projections":u}})}function Z(n){let o=d(k(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),m=d(o.validation),u=b(o.source_probes),p=b(o.projection_errors),y=d(o.fetched_sources),_=b(o.compute_errors),C=d(o.computed_values),R={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:y,computed_values:C},v=[];for(let A of b(m.issues))typeof A=="string"&&A&&v.push(A);for(let A of u){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"source",w=typeof h.error=="string"?h.error:"";w&&v.push(`${S}: ${w}`);}for(let A of p){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"source",w=typeof h.key=="string"?h.key:"projection",T=typeof h.error=="string"?h.error:"projection failed";v.push(`${S}.${w}: ${T}`);}for(let A of _){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"compute",w=typeof h.error=="string"?h.error:"compute failed";v.push(`${S}: ${w}`);}return {status:"success",data:{cardId:typeof o.cardId=="string"?o.cardId:"(unknown)",ok:o.ok===true,issues:v,provides_outputs:J(i,R),rendered_view:O(i,R)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=k(t.get({params:{id:o}}),"cardStore.get");return Array.isArray(i.cards)?i.cards:[]}function re(n){let o=String(n.cardId||"").trim(),i=String(n.role||"").trim(),m=typeof n.text=="string"?n.text:"",u=typeof n.turn=="string"?n.turn:"";if(!o)throw new Error("manageAddChatEntryAndAnyAttachments requires cardId");if(!i)throw new Error("manageAddChatEntryAndAnyAttachments requires role");let p=b(n.files).map(_=>{let C=d(_),R=String(C.file_name??C.fileName??C.name??"").trim(),v=String(C.content_type??C.contentType??"application/octet-stream");if(!R)throw new Error("file entry requires file_name");return c({cardId:o,fileName:R,contentType:v,bytes:j(C)}).file});p.forEach((_,C)=>{let R=i==="assistant"?`AI generated: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`:`file uploaded: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`;k(a.append({params:{cardId:o},body:{role:"system",text:R,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=k(a.append({params:{cardId:o},body:{role:i,text:m,files:p,turn:u}}),"chatStore.append");return {status:"success",data:{cardId:o,id:String(y.id),role:i,turn:u,files:p}}}function te(n){let o=String(n.cardId||"").trim(),i=d(n.candidateCardContent);if(!o)throw new Error("manageUpsertCard requires cardId");if(typeof i.id!="string"||!i.id.trim())throw new Error("candidateCardContent.id must be a non-empty string");if(i.id!==o)throw new Error(`candidateCardContent.id must match cardId (${o})`);let m=P({candidateCardContent:i}),u=d(m),p=d(u.data);if(u.status!=="success"||p.isValid!==true)return {status:"fail",step:"validate",validation:m};let y=null;try{y=$(t,o);}catch{y=null;}let _=t.set({body:i});k(_,"cardStore.set");let C;try{C=r.upsertCard({params:{cardId:o,restart:!0}}),k(C,"upsertCard");}catch(v){try{y&&t.set({body:y});}catch{}throw v}let R=null;try{R=r.cardRefreshedNotify({params:{cardId:o}}),k(R,"cardRefreshedNotify");}catch{R=null;}return {status:"success",data:{validation:m,card_saved:null,board_result:C,refresh_notify:R}}}function ne(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageRemoveCard requires cardId");let i=r.removeCard({params:{id:o}});k(i,"removeCard");let m=t.del({params:{id:o}});return k(m,"cardStore.del"),{status:"success",data:{board_result:i,store_result:m}}}return {discoverSourceKinds:I,inspectBoardRuntimeStatus:x,inspectCardDefinitionAndRuntime:q,inspectChatMessagesOnCards:U,inspectFileContents:G,preflightValidateCandidateCardDefinition:P,preflightMaterializeCandidateCard:H,preflightProbeSingleSourceInCandidateCard:Y,preflightRunSingleSourceInCandidateCard:Q,preflightRunSingleSourceInLiveCard:X,preflightRunOneCycleWithCandidateCard:Z,manageReadCard:ee,manageAddChatEntryAndAnyAttachments:re,manageUpsertCard:te,manageRemoveCard:ne}}exports.createBoardLiveCardsMcp=$e;//# sourceMappingURL=board-live-cards-mcp.cjs.map
|
|
2
2
|
//# sourceMappingURL=board-live-cards-mcp.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createRequire}from'module';import'ajv-formats';var ae=createRequire(import.meta.url);ae("./jsonata-sync.cjs");var de=createRequire(import.meta.url),L=de("./jsonata-sync.cjs"),V=L;function D(e,r){if(!r||!e)return;let s=r.split("."),t=e;for(let a=0;a<s.length;a++){if(t==null)return;t=t[s[a]];}return t}function K(e,r,s){let t=r.split("."),a=e;for(let c=0;c<t.length-1;c++)(a[t[c]]==null||typeof a[t[c]]!="object")&&(a[t[c]]={}),a=a[t[c]];a[t[t.length-1]]=s;}async function ce(e,r){if(!e?.compute?.length)return e;e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values};for(let a of e.compute)try{let c=await L(a.expr).evaluate(t);K(e.computed_values,a.bindTo,c),t.computed_values=e.computed_values;}catch{}return e}function ue(e,r){if(!e?.compute?.length)return {ok:true,node:e};e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values},a=[];for(let c of e.compute)try{let l=V(c.expr).evaluate(t);K(e.computed_values,c.bindTo,l),t.computed_values=e.computed_values;}catch(l){let m=l instanceof Error?l.message:String(l);a.push({bindTo:c.bindTo,error:m});}return a.length>0?{ok:true,node:e,errors:a}:{ok:true,node:e}}async function pe(e,r,s){let t={...s??{},card_data:r.card_data??{},requires:r.requires??{},fetched_sources:r._sourcesData??{},computed_values:r.computed_values??{}};return L(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?D(e._sourcesData??{},r.slice(16)):D(e,r)}var P=new Set(["metric","table","editable-table","chart","form","filter","list","notes","todo","alert","narrative","badge","text","markdown","ref","custom","actions"]),fe=new Set(["id","meta","requires","provides","view","card_data","compute","source_defs"]);function me(e){let r=[];if(!e||typeof e!="object"||Array.isArray(e))return {ok:false,errors:["Node must be a non-null object"]};let s=e;(typeof s.id!="string"||!s.id)&&r.push("id: required, must be a non-empty string");for(let t of Object.keys(s))fe.has(t)||r.push(`Unknown top-level key: "${t}"`);if((s.card_data==null||typeof s.card_data!="object"||Array.isArray(s.card_data))&&r.push("card_data: required, must be an object"),s.meta!=null)if(typeof s.meta!="object"||Array.isArray(s.meta))r.push("meta: must be an object");else {let t=s.meta;t.title!=null&&typeof t.title!="string"&&r.push("meta.title: must be a string"),t.tags!=null&&!Array.isArray(t.tags)&&r.push("meta.tags: must be an array");}if(s.requires!=null&&!Array.isArray(s.requires)&&r.push("requires: must be an array of strings"),s.provides!=null&&(Array.isArray(s.provides)?s.provides.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`provides[${a}]: must be an object with bindTo and ref`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`provides[${a}]: missing required "bindTo" string`),(typeof c.ref!="string"||!c.ref)&&r.push(`provides[${a}]: missing required "ref" string`);}}):r.push("provides: must be an array of { bindTo, ref } bindings")),s.compute!=null&&(Array.isArray(s.compute)?s.compute.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`compute[${a}]: must be a compute step object`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`compute[${a}]: missing required "bindTo" property`),(typeof c.expr!="string"||!c.expr)&&r.push(`compute[${a}]: missing required "expr" string (JSONata expression)`);}}):r.push("compute: must be an array of compute steps")),s.source_defs!=null)if(!Array.isArray(s.source_defs))r.push("source_defs: must be an array");else {let t=new Set,a=new Set;s.source_defs.forEach((c,l)=>{if(!c||typeof c!="object"||Array.isArray(c))r.push(`source_defs[${l}]: must be an object`);else {let m=c;typeof m.bindTo!="string"||!m.bindTo?r.push(`source_defs[${l}]: missing required "bindTo" property`):(t.has(m.bindTo)&&r.push(`source_defs[${l}]: bindTo "${m.bindTo}" is not unique across source_defs`),t.add(m.bindTo)),typeof m.outputFile!="string"||!m.outputFile?r.push(`source_defs[${l}]: missing required "outputFile" property`):(a.has(m.outputFile)&&r.push(`source_defs[${l}]: outputFile "${m.outputFile}" is not unique across source_defs`),a.add(m.outputFile)),m.optionalForCompletionGating!=null&&typeof m.optionalForCompletionGating!="boolean"&&r.push(`source_defs[${l}]: optionalForCompletionGating must be a boolean`);}});}if(s.view!=null)if(typeof s.view!="object"||Array.isArray(s.view))r.push("view: must be an object");else {let t=s.view;!Array.isArray(t.elements)||t.elements.length===0?r.push("view.elements: required, must be a non-empty array"):t.elements.forEach((a,c)=>{if(!a||typeof a!="object"){r.push(`view.elements[${c}]: must be an object`);return}!a.kind||typeof a.kind!="string"?r.push(`view.elements[${c}].kind: required, must be a string`):P.has(a.kind)||r.push(`view.elements[${c}].kind: unknown kind "${a.kind}". Valid: ${[...P].join(", ")}`),a.data!=null&&(typeof a.data!="object"||Array.isArray(a.data))&&r.push(`view.elements[${c}].data: must be an object`);}),t.layout!=null&&(typeof t.layout!="object"||Array.isArray(t.layout))&&r.push("view.layout: must be an object"),t.features!=null&&(typeof t.features!="object"||Array.isArray(t.features))&&r.push("view.features: must be an object");}return {ok:r.length===0,errors:r}}async function ge(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return Promise.all(e.map(async t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=await L(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}}))}function ye(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return e.map(t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=V(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}})}var z={run:ce,runSync:ue,eval:pe,resolve:le,validate:me,enrichSources:ge,enrichSourcesSync:ye};function _(e,r){if(e?.status==="success")return Object.prototype.hasOwnProperty.call(e,"data")?e.data:void 0;throw e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function we(e,r){if(e?.status==="success"&&Object.prototype.hasOwnProperty.call(e,"data"))return e.data;throw e?.status==="success"?new Error(`${r} returned success without data`):e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function d(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function C(e){return Array.isArray(e)?e:[]}function O(e,r){if(typeof r!="string"||r.length===0)return;let s=e,t=r;t.startsWith("fetched_sources.")&&(s=d(e).fetched_sources,t=t.slice(16));for(let a of t.split(".")){if(s==null||typeof s!="object")return;s=s[a];}return s}function F(e,r){let s=d(e.view),t=C(s.elements);return {layout:s.layout,features:s.features,elements:t.map((a,c)=>{let l=d(a),m=d(l.data),q=typeof l.visible=="string"?!!O(r,l.visible):true,S=typeof m.bind=="string"?m.bind:void 0,I=S?O(r,S):void 0,x={id:typeof l.id=="string"&&l.id?l.id:`element-${c}`,kind:l.kind,label:l.label,visible:q};return S&&(x.bind=S),Array.isArray(m.columns)&&(x.columns=m.columns),typeof m.maxRows=="number"&&(x.maxRows=m.maxRows),I!==void 0&&(x.resolved=Array.isArray(I)&&typeof x.maxRows=="number"?I.slice(0,x.maxRows):I),x})}}function W(e,r){let s=typeof e.id=="string"&&e.id?e.id:"card",t=C(e.provides),a=t.length>0?t:[{bindTo:s,ref:"card_data"}],c={};for(let l of a){let m=d(l),q=typeof m.bindTo=="string"?m.bindTo:"",S=typeof m.ref=="string"?m.ref:"";if(!q||!S)continue;let I=O(r,S);I!==void 0&&(c[q]=I);}return c}function be(e){if(typeof e!="string"||!e.trim())return null;let r=/^(file uploaded|AI generated|AI geneterated):\s*.*?#(\d+)\s*$/i.exec(e.trim());if(!r)return null;let s=Number.parseInt(r[2],10);return !Number.isInteger(s)||s<0?null:s}function Ce(e){return {"card-content":e}}function M(e,r){let s=_(e.get({params:{id:r}}),"cardStore.get"),t=Array.isArray(s?.cards)?s.cards:[];if(t.length===0)throw new Error(`Card "${r}" not found`);return t[0]}function $e(e){let{board:r,nonCore:s,cardStore:t,chatStore:a,uploadCardFile:c,buildFileDownloadUrl:l,readFetchedSourceJsonByRef:m}=e;function q(n){if(Array.isArray(n.bytes))return new Uint8Array(n.bytes.map(o=>Math.max(0,Math.min(255,Number(o)||0))));if(typeof n.text=="string")return new TextEncoder().encode(n.text);if(typeof n.base64=="string"){let o=String(n.base64).replace(/-/g,"+").replace(/_/g,"/"),i=o+"=".repeat((4-o.length%4)%4),g=atob(i);return Uint8Array.from(g,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function S(){let n=d(_(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function I(){let n=d(_(r.status({}),"status")),o=d(n.summary),i=C(n.cards);return {meta:d(n.meta),summary:{card_count:typeof o.card_count=="number"?o.card_count:0,completed:typeof o.completed=="number"?o.completed:0,eligible:typeof o.eligible=="number"?o.eligible:0,pending:typeof o.pending=="number"?o.pending:0,blocked:typeof o.blocked=="number"?o.blocked:0,in_progress:typeof o.in_progress=="number"?o.in_progress:0,failed:typeof o.failed=="number"?o.failed:0,unresolved:typeof o.unresolved=="number"?o.unresolved:0},cards:i.map(g=>{let u=d(g);return {"card-id":typeof u.name=="string"?u.name:null,status:u.status??null,error:u.error??null,requires:C(u.requires),requires_satisfied:C(u.requires_satisfied),requires_missing:C(u.requires_missing),provides_declared:C(u.provides_declared),provides_runtime:C(u.provides_runtime)}})}}function x(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectCardDefinitionAndRuntime requires cardId");let i=d(_(r.status({}),"status")),u=C(i.cards).map(d).find(f=>f.name===o);if(!u)throw new Error(`card "${o}" not found in board status`);let p=d(M(t,o)),y=C(u.requires_satisfied).filter(f=>typeof f=="string"&&!!f),v=C(u.provides_runtime).filter(f=>typeof f=="string"&&!!f),w=Object.fromEntries(y.map(f=>[f,_(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),h=Object.fromEntries(v.map(f=>[f,_(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),R=d(_(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),b=_(r.getOutputsFetchedSources({params:{key:o}}),"getOutputsFetchedSources"),j=C(p.source_defs).map(d),A={};for(let f of j)typeof f.bindTo=="string"&&typeof f.outputFile=="string"&&(A[f.outputFile]=f.bindTo);let k={};for(let[f,T]of Object.entries(b)){let E=A[f]??f;if(!m||typeof T!="string"){k[E]=null;continue}try{k[E]=m({cardId:o,ref:T});}catch{k[E]=null;}}let $={card_data:d(p.card_data),requires:w,fetched_sources:k,computed_values:R};return {cardId:o,card_status_in_board:u,card_definition_and_static_data:p,refs_for_fetched_source_files:b,runtime_data:{requires:w,provides:h,computed_values:R,rendered_view:F(p,$)}}}function J(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectChatMessagesOnCards requires cardId");let i=typeof n.turnId=="string"?n.turnId:"",g=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=g?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,v={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...g?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},w=Object.keys(v).length>0?{params:{cardId:o},body:v}:{params:{cardId:o}},h=_(a.readAll(w),"chatStore.readAll"),R=d(M(t,o)),b=C(d(R.card_data).files).map((k,$)=>({idx:$,stored_name:d(k).stored_name})).filter(k=>typeof k.stored_name=="string"&&k.stored_name.length>0),A=(Array.isArray(h.records)?h.records:[]).map(k=>{let f=d(k.payload),T={...k},E=typeof k?.role=="string"?k.role:typeof f.role=="string"?String(f.role):"",oe=typeof k?.text=="string"?k.text:typeof f.text=="string"?String(f.text):"";if(E==="system"){let B=be(oe);if(B!==null&&b.some(U=>U.idx===B)){let U=`Retrieve using inspect-file-contents --card-id ${o} --file-idx ${B}`;T.retrieval_hint=U,Object.keys(f).length>0&&typeof k.role!="string"&&(T.payload={...f,retrieval_hint:U});}}return T});return {cardId:o,messages:typeof y=="number"&&y>=0?A.slice(-y):A}}function G(n){let o=String(n.cardId||"").trim(),i=Number(n.fileIdx);if(!o)throw new Error("inspectFileContents requires cardId");if(!Number.isInteger(i)||i<0)throw new Error("inspectFileContents requires fileIdx to be a non-negative integer");let g=d(M(t,o)),u=C(d(g.card_data).files).map(d);if(i>=u.length)throw new Error(`attachment index ${i} is out of range for card "${o}"`);let p=u[i],y=typeof p.stored_name=="string"?p.stored_name:null;return {cardId:o,fileIdx:i,downloadUrl:l({cardId:o,fileIdx:i,storedName:y}),...typeof p.name=="string"?{name:p.name}:{},...typeof p.stored_name=="string"?{stored_name:p.stored_name}:{},...typeof p.mime_type=="string"?{mime_type:p.mime_type}:{},...typeof p.size=="number"?{size:p.size}:{},...typeof p.uploaded_at=="string"?{uploaded_at:p.uploaded_at}:{}}}function N(n){return s.validateCardPreflight({body:Ce(n.candidateCardContent)})}function H(n){if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightMaterializeCandidateCard requires mockRequires");if(!n.mockFetchedSources||typeof n.mockFetchedSources!="object"||Array.isArray(n.mockFetchedSources))throw new Error("preflightMaterializeCandidateCard requires mockFetchedSources");let o=s.evalCardCompute({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires,"mock-fetched-sources":n.mockFetchedSources}});if(o.status!=="success")return o;let i=d(we(o,"evalCardCompute")),g=d(n.candidateCardContent),u={card_data:d(g.card_data),requires:d(n.mockRequires),fetched_sources:d(n.mockFetchedSources),computed_values:d(i.computed_values)};return {status:"success",data:{cardId:typeof i.cardId=="string"?i.cardId:typeof g.id=="string"?g.id:"(unknown)",ok:i.ok===true,computed_values:d(i.computed_values),errors:C(i.errors).map(p=>{let y=d(p);return {bindTo:typeof y.bindTo=="string"?y.bindTo:"",error:typeof y.error=="string"?y.error:""}}),provides_outputs:W(g,u),rendered_view:F(g,u)}}}function Y(n){return s.probeSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function Q(n){return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function X(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("preflightRunSingleSourceInLiveCard requires cardId");if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightRunSingleSourceInLiveCard requires mockRequires");let i=d(M(t,o)),g=C(i.source_defs).filter(p=>!!p&&typeof p=="object"&&!Array.isArray(p)),u={};if(n.sourceIdx>=0&&n.sourceIdx<g.length){let p=g[n.sourceIdx],y=z.enrichSourcesSync([p],{card_data:d(i.card_data),requires:n.mockRequires});Array.isArray(y)&&y.length>0&&(u=d(y[0]._projections));}return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":i,"mock-requires":n.mockRequires,"mock-projections":u}})}function Z(n){let o=d(_(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),g=d(o.validation),u=C(o.source_probes),p=C(o.projection_errors),y=C(o.compute_errors),v=d(o.computed_values),w={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:{},computed_values:v},h=[];for(let R of C(g.issues))typeof R=="string"&&R&&h.push(R);for(let R of u){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"source",A=typeof b.error=="string"?b.error:"";A&&h.push(`${j}: ${A}`);}for(let R of p){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"source",A=typeof b.key=="string"?b.key:"projection",k=typeof b.error=="string"?b.error:"projection failed";h.push(`${j}.${A}: ${k}`);}for(let R of y){let b=d(R),j=typeof b.bindTo=="string"?b.bindTo:"compute",A=typeof b.error=="string"?b.error:"compute failed";h.push(`${j}: ${A}`);}return {status:"success",data:{cardId:typeof o.cardId=="string"?o.cardId:"(unknown)",ok:o.ok===true,issues:h,provides_outputs:W(i,w),rendered_view:F(i,w)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=_(t.get({params:{id:o}}),"cardStore.get");return Array.isArray(i.cards)?i.cards:[]}function re(n){let o=String(n.cardId||"").trim(),i=String(n.role||"").trim(),g=typeof n.text=="string"?n.text:"",u=typeof n.turn=="string"?n.turn:"";if(!o)throw new Error("manageAddChatEntryAndAnyAttachments requires cardId");if(!i)throw new Error("manageAddChatEntryAndAnyAttachments requires role");let p=C(n.files).map(v=>{let w=d(v),h=String(w.file_name??w.fileName??w.name??"").trim(),R=String(w.content_type??w.contentType??"application/octet-stream");if(!h)throw new Error("file entry requires file_name");return c({cardId:o,fileName:h,contentType:R,bytes:q(w)}).file});p.forEach((v,w)=>{let h=i==="assistant"?`AI generated: ${String(v.name||"")} as ${String(v.stored_name||"")} #${w}`:`file uploaded: ${String(v.name||"")} as ${String(v.stored_name||"")} #${w}`;_(a.append({params:{cardId:o},body:{role:"system",text:h,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=_(a.append({params:{cardId:o},body:{role:i,text:g,files:p,turn:u}}),"chatStore.append");return {status:"success",data:{cardId:o,id:String(y.id),role:i,turn:u,files:p}}}function te(n){let o=String(n.cardId||"").trim(),i=d(n.candidateCardContent);if(!o)throw new Error("manageUpsertCard requires cardId");if(typeof i.id!="string"||!i.id.trim())throw new Error("candidateCardContent.id must be a non-empty string");if(i.id!==o)throw new Error(`candidateCardContent.id must match cardId (${o})`);let g=N({candidateCardContent:i}),u=d(g),p=d(u.data);if(u.status!=="success"||p.isValid!==true)return {status:"fail",step:"validate",validation:g};let y=null;try{y=M(t,o);}catch{y=null;}let v=t.set({body:i});_(v,"cardStore.set");let w;try{w=r.upsertCard({params:{cardId:o,restart:!0}}),_(w,"upsertCard");}catch(R){try{y&&t.set({body:y});}catch{}throw R}let h=null;try{h=r.cardRefreshedNotify({params:{cardId:o}}),_(h,"cardRefreshedNotify");}catch{h=null;}return {status:"success",data:{validation:g,card_saved:null,board_result:w,refresh_notify:h}}}function ne(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageDeprecate requires cardId");let i=r.removeCard({params:{id:o}});return _(i,"removeCard"),i}return {discoverSourceKinds:S,inspectBoardRuntimeStatus:I,inspectCardDefinitionAndRuntime:x,inspectChatMessagesOnCards:J,inspectFileContents:G,preflightValidateCandidateCardDefinition:N,preflightMaterializeCandidateCard:H,preflightProbeSingleSourceInCandidateCard:Y,preflightRunSingleSourceInCandidateCard:Q,preflightRunSingleSourceInLiveCard:X,preflightRunOneCycleWithCandidateCard:Z,manageReadCard:ee,manageAddChatEntryAndAnyAttachments:re,manageUpsertCard:te,manageDeprecate:ne}}export{$e as createBoardLiveCardsMcp};//# sourceMappingURL=board-live-cards-mcp.js.map
|
|
1
|
+
import {createRequire}from'module';import'ajv-formats';var ae=createRequire(import.meta.url);ae("./jsonata-sync.cjs");var de=createRequire(import.meta.url),B=de("./jsonata-sync.cjs"),K=B;function D(e,r){if(!r||!e)return;let s=r.split("."),t=e;for(let a=0;a<s.length;a++){if(t==null)return;t=t[s[a]];}return t}function z(e,r,s){let t=r.split("."),a=e;for(let c=0;c<t.length-1;c++)(a[t[c]]==null||typeof a[t[c]]!="object")&&(a[t[c]]={}),a=a[t[c]];a[t[t.length-1]]=s;}async function ce(e,r){if(!e?.compute?.length)return e;e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values};for(let a of e.compute)try{let c=await B(a.expr).evaluate(t);z(e.computed_values,a.bindTo,c),t.computed_values=e.computed_values;}catch{}return e}function ue(e,r){if(!e?.compute?.length)return {ok:true,node:e};e.card_data||(e.card_data={}),e.computed_values={},e._sourcesData=r?.sourcesData??{};let s=e.requires??{},t={card_data:e.card_data,requires:s,expects_data:s,fetched_sources:e._sourcesData,data:e.computed_values,computed_values:e.computed_values},a=[];for(let c of e.compute)try{let l=K(c.expr).evaluate(t);z(e.computed_values,c.bindTo,l),t.computed_values=e.computed_values;}catch(l){let g=l instanceof Error?l.message:String(l);a.push({bindTo:c.bindTo,error:g});}return a.length>0?{ok:true,node:e,errors:a}:{ok:true,node:e}}async function pe(e,r,s){let t={...s??{},card_data:r.card_data??{},requires:r.requires??{},fetched_sources:r._sourcesData??{},computed_values:r.computed_values??{}};return B(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?D(e._sourcesData??{},r.slice(16)):D(e,r)}var V=new Set(["metric","table","editable-table","chart","form","filter","list","notes","todo","alert","narrative","badge","text","markdown","ref","custom","actions"]),fe=new Set(["id","meta","requires","provides","view","card_data","compute","source_defs"]);function me(e){let r=[];if(!e||typeof e!="object"||Array.isArray(e))return {ok:false,errors:["Node must be a non-null object"]};let s=e;(typeof s.id!="string"||!s.id)&&r.push("id: required, must be a non-empty string");for(let t of Object.keys(s))fe.has(t)||r.push(`Unknown top-level key: "${t}"`);if((s.card_data==null||typeof s.card_data!="object"||Array.isArray(s.card_data))&&r.push("card_data: required, must be an object"),s.meta!=null)if(typeof s.meta!="object"||Array.isArray(s.meta))r.push("meta: must be an object");else {let t=s.meta;t.title!=null&&typeof t.title!="string"&&r.push("meta.title: must be a string"),t.tags!=null&&!Array.isArray(t.tags)&&r.push("meta.tags: must be an array");}if(s.requires!=null&&!Array.isArray(s.requires)&&r.push("requires: must be an array of strings"),s.provides!=null&&(Array.isArray(s.provides)?s.provides.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`provides[${a}]: must be an object with bindTo and ref`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`provides[${a}]: missing required "bindTo" string`),(typeof c.ref!="string"||!c.ref)&&r.push(`provides[${a}]: missing required "ref" string`);}}):r.push("provides: must be an array of { bindTo, ref } bindings")),s.compute!=null&&(Array.isArray(s.compute)?s.compute.forEach((t,a)=>{if(!t||typeof t!="object"||Array.isArray(t))r.push(`compute[${a}]: must be a compute step object`);else {let c=t;(typeof c.bindTo!="string"||!c.bindTo)&&r.push(`compute[${a}]: missing required "bindTo" property`),(typeof c.expr!="string"||!c.expr)&&r.push(`compute[${a}]: missing required "expr" string (JSONata expression)`);}}):r.push("compute: must be an array of compute steps")),s.source_defs!=null)if(!Array.isArray(s.source_defs))r.push("source_defs: must be an array");else {let t=new Set,a=new Set;s.source_defs.forEach((c,l)=>{if(!c||typeof c!="object"||Array.isArray(c))r.push(`source_defs[${l}]: must be an object`);else {let g=c;typeof g.bindTo!="string"||!g.bindTo?r.push(`source_defs[${l}]: missing required "bindTo" property`):(t.has(g.bindTo)&&r.push(`source_defs[${l}]: bindTo "${g.bindTo}" is not unique across source_defs`),t.add(g.bindTo)),typeof g.outputFile!="string"||!g.outputFile?r.push(`source_defs[${l}]: missing required "outputFile" property`):(a.has(g.outputFile)&&r.push(`source_defs[${l}]: outputFile "${g.outputFile}" is not unique across source_defs`),a.add(g.outputFile)),g.optionalForCompletionGating!=null&&typeof g.optionalForCompletionGating!="boolean"&&r.push(`source_defs[${l}]: optionalForCompletionGating must be a boolean`);}});}if(s.view!=null)if(typeof s.view!="object"||Array.isArray(s.view))r.push("view: must be an object");else {let t=s.view;!Array.isArray(t.elements)||t.elements.length===0?r.push("view.elements: required, must be a non-empty array"):t.elements.forEach((a,c)=>{if(!a||typeof a!="object"){r.push(`view.elements[${c}]: must be an object`);return}!a.kind||typeof a.kind!="string"?r.push(`view.elements[${c}].kind: required, must be a string`):V.has(a.kind)||r.push(`view.elements[${c}].kind: unknown kind "${a.kind}". Valid: ${[...V].join(", ")}`),a.data!=null&&(typeof a.data!="object"||Array.isArray(a.data))&&r.push(`view.elements[${c}].data: must be an object`);}),t.layout!=null&&(typeof t.layout!="object"||Array.isArray(t.layout))&&r.push("view.layout: must be an object"),t.features!=null&&(typeof t.features!="object"||Array.isArray(t.features))&&r.push("view.features: must be an object");}return {ok:r.length===0,errors:r}}async function ge(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return Promise.all(e.map(async t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=await B(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}}))}function ye(e,r){if(!e||e.length===0)return [];let s={card_data:r.card_data??{},requires:r.requires??{}};return e.map(t=>{let a={};if(t.projections&&typeof t.projections=="object"&&!Array.isArray(t.projections)){for(let[c,l]of Object.entries(t.projections))if(typeof l=="string"&&l.trim().length>0)try{a[c]=K(l).evaluate(s);}catch{a[c]=void 0;}}return {...t,_projections:a}})}var W={run:ce,runSync:ue,eval:pe,resolve:le,validate:me,enrichSources:ge,enrichSourcesSync:ye};function k(e,r){if(e?.status==="success")return Object.prototype.hasOwnProperty.call(e,"data")?e.data:void 0;throw e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function we(e,r){if(e?.status==="success"&&Object.prototype.hasOwnProperty.call(e,"data"))return e.data;throw e?.status==="success"?new Error(`${r} returned success without data`):e?.status==="fail"||e?.status==="error"?new Error(e.error||`${r} failed`):new Error(`${r} returned an unexpected response`)}function d(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function b(e){return Array.isArray(e)?e:[]}function N(e,r){if(typeof r!="string"||r.length===0)return;let s=e,t=r;t.startsWith("fetched_sources.")&&(s=d(e).fetched_sources,t=t.slice(16));for(let a of t.split(".")){if(s==null||typeof s!="object")return;s=s[a];}return s}function O(e,r){let s=d(e.view),t=b(s.elements);return {layout:s.layout,features:s.features,elements:t.map((a,c)=>{let l=d(a),g=d(l.data),j=typeof l.visible=="string"?!!N(r,l.visible):true,I=typeof g.bind=="string"?g.bind:void 0,x=typeof g.maxRows=="number"?g.maxRows:void 0,q=I?N(r,I):void 0,U={id:typeof l.id=="string"&&l.id?l.id:`element-${c}`,kind:l.kind,label:l.label,visible:j};return q!==void 0&&(U.resolved=Array.isArray(q)&&typeof x=="number"?q.slice(0,x):q),U})}}function J(e,r){let s=typeof e.id=="string"&&e.id?e.id:"card",t=b(e.provides),a=t.length>0?t:[{bindTo:s,ref:"card_data"}],c={};for(let l of a){let g=d(l),j=typeof g.bindTo=="string"?g.bindTo:"",I=typeof g.ref=="string"?g.ref:"";if(!j||!I)continue;let x=N(r,I);x!==void 0&&(c[j]=x);}return c}function be(e){if(typeof e!="string"||!e.trim())return null;let r=/^(file uploaded|AI generated|AI geneterated):\s*.*?#(\d+)\s*$/i.exec(e.trim());if(!r)return null;let s=Number.parseInt(r[2],10);return !Number.isInteger(s)||s<0?null:s}function Ce(e){return {"card-content":e}}function $(e,r){let s=k(e.get({params:{id:r}}),"cardStore.get"),t=Array.isArray(s?.cards)?s.cards:[];if(t.length===0)throw new Error(`Card "${r}" not found`);return t[0]}function $e(e){let{board:r,nonCore:s,cardStore:t,chatStore:a,uploadCardFile:c,buildFileDownloadUrl:l,readFetchedSourceJsonByRef:g}=e;function j(n){if(Array.isArray(n.bytes))return new Uint8Array(n.bytes.map(o=>Math.max(0,Math.min(255,Number(o)||0))));if(typeof n.text=="string")return new TextEncoder().encode(n.text);if(typeof n.base64=="string"){let o=String(n.base64).replace(/-/g,"+").replace(/_/g,"/"),i=o+"=".repeat((4-o.length%4)%4),m=atob(i);return Uint8Array.from(m,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function I(){let n=d(k(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function x(){let n=d(k(r.status({}),"status")),o=d(n.summary),i=b(n.cards);return {meta:d(n.meta),summary:{card_count:typeof o.card_count=="number"?o.card_count:0,completed:typeof o.completed=="number"?o.completed:0,eligible:typeof o.eligible=="number"?o.eligible:0,pending:typeof o.pending=="number"?o.pending:0,blocked:typeof o.blocked=="number"?o.blocked:0,in_progress:typeof o.in_progress=="number"?o.in_progress:0,failed:typeof o.failed=="number"?o.failed:0,unresolved:typeof o.unresolved=="number"?o.unresolved:0},cards:i.map(m=>{let u=d(m);return {"card-id":typeof u.name=="string"?u.name:null,status:u.status??null,error:u.error??null,requires:b(u.requires),requires_satisfied:b(u.requires_satisfied),requires_missing:b(u.requires_missing),provides_declared:b(u.provides_declared),provides_runtime:b(u.provides_runtime)}})}}function q(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectCardDefinitionAndRuntime requires cardId");let i=d(k(r.status({}),"status")),u=b(i.cards).map(d).find(f=>f.name===o);if(!u)throw new Error(`card "${o}" not found in board status`);let p=d($(t,o)),y=b(u.requires_satisfied).filter(f=>typeof f=="string"&&!!f),_=b(u.provides_runtime).filter(f=>typeof f=="string"&&!!f),C=Object.fromEntries(y.map(f=>[f,k(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),R=Object.fromEntries(_.map(f=>[f,k(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),v=d(k(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),A=k(r.getOutputsFetchedSources({params:{key:o}}),"getOutputsFetchedSources"),h=b(p.source_defs).map(d),S={};for(let f of h)typeof f.bindTo=="string"&&typeof f.outputFile=="string"&&(S[f.outputFile]=f.bindTo);let w={};for(let[f,E]of Object.entries(A)){let M=S[f]??f;if(!g||typeof E!="string"){w[M]=null;continue}try{w[M]=g({cardId:o,ref:E});}catch{w[M]=null;}}let T={card_data:d(p.card_data),requires:C,fetched_sources:w,computed_values:v};return {cardId:o,card_status_in_board:u,card_definition_and_static_data:p,refs_for_fetched_source_files:A,runtime_data:{requires:C,provides:R,computed_values:v,rendered_view:O(p,T)}}}function U(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("inspectChatMessagesOnCards requires cardId");let i=typeof n.turnId=="string"?n.turnId:"",m=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=m?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,_={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...m?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},C=Object.keys(_).length>0?{params:{cardId:o},body:_}:{params:{cardId:o}},R=k(a.readAll(C),"chatStore.readAll"),v=d($(t,o)),A=b(d(v.card_data).files).map((w,T)=>({idx:T,stored_name:d(w).stored_name})).filter(w=>typeof w.stored_name=="string"&&w.stored_name.length>0),S=(Array.isArray(R.records)?R.records:[]).map(w=>{let f=d(w.payload),E={...w},M=typeof w?.role=="string"?w.role:typeof f.role=="string"?String(f.role):"",oe=typeof w?.text=="string"?w.text:typeof f.text=="string"?String(f.text):"";if(M==="system"){let F=be(oe);if(F!==null&&A.some(L=>L.idx===F)){let L=`Retrieve using inspect-file-contents --card-id ${o} --file-idx ${F}`;E.retrieval_hint=L,Object.keys(f).length>0&&typeof w.role!="string"&&(E.payload={...f,retrieval_hint:L});}}return E});return {cardId:o,messages:typeof y=="number"&&y>=0?S.slice(-y):S}}function G(n){let o=String(n.cardId||"").trim(),i=Number(n.fileIdx);if(!o)throw new Error("inspectFileContents requires cardId");if(!Number.isInteger(i)||i<0)throw new Error("inspectFileContents requires fileIdx to be a non-negative integer");let m=d($(t,o)),u=b(d(m.card_data).files).map(d);if(i>=u.length)throw new Error(`attachment index ${i} is out of range for card "${o}"`);let p=u[i],y=typeof p.stored_name=="string"?p.stored_name:null;return {cardId:o,fileIdx:i,downloadUrl:l({cardId:o,fileIdx:i,storedName:y}),...typeof p.name=="string"?{name:p.name}:{},...typeof p.stored_name=="string"?{stored_name:p.stored_name}:{},...typeof p.mime_type=="string"?{mime_type:p.mime_type}:{},...typeof p.size=="number"?{size:p.size}:{},...typeof p.uploaded_at=="string"?{uploaded_at:p.uploaded_at}:{}}}function P(n){return s.validateCardPreflight({body:Ce(n.candidateCardContent)})}function H(n){if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightMaterializeCandidateCard requires mockRequires");if(!n.mockFetchedSources||typeof n.mockFetchedSources!="object"||Array.isArray(n.mockFetchedSources))throw new Error("preflightMaterializeCandidateCard requires mockFetchedSources");let o=s.evalCardCompute({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires,"mock-fetched-sources":n.mockFetchedSources}});if(o.status!=="success")return o;let i=d(we(o,"evalCardCompute")),m=d(n.candidateCardContent),u={card_data:d(m.card_data),requires:d(n.mockRequires),fetched_sources:d(n.mockFetchedSources),computed_values:d(i.computed_values)};return {status:"success",data:{cardId:typeof i.cardId=="string"?i.cardId:typeof m.id=="string"?m.id:"(unknown)",ok:i.ok===true,computed_values:d(i.computed_values),errors:b(i.errors).map(p=>{let y=d(p);return {bindTo:typeof y.bindTo=="string"?y.bindTo:"",error:typeof y.error=="string"?y.error:""}}),provides_outputs:J(m,u),rendered_view:O(m,u)}}}function Y(n){return s.probeSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function Q(n){return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":n.candidateCardContent,"mock-projections":n.mockProjections}})}function X(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("preflightRunSingleSourceInLiveCard requires cardId");if(!n.mockRequires||typeof n.mockRequires!="object"||Array.isArray(n.mockRequires))throw new Error("preflightRunSingleSourceInLiveCard requires mockRequires");let i=d($(t,o)),m=b(i.source_defs).filter(p=>!!p&&typeof p=="object"&&!Array.isArray(p)),u={};if(n.sourceIdx>=0&&n.sourceIdx<m.length){let p=m[n.sourceIdx],y=W.enrichSourcesSync([p],{card_data:d(i.card_data),requires:n.mockRequires});Array.isArray(y)&&y.length>0&&(u=d(y[0]._projections));}return s.runSourcePreflight({params:{sourceIdx:n.sourceIdx},body:{"card-content":i,"mock-requires":n.mockRequires,"mock-projections":u}})}function Z(n){let o=d(k(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),m=d(o.validation),u=b(o.source_probes),p=b(o.projection_errors),y=d(o.fetched_sources),_=b(o.compute_errors),C=d(o.computed_values),R={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:y,computed_values:C},v=[];for(let A of b(m.issues))typeof A=="string"&&A&&v.push(A);for(let A of u){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"source",w=typeof h.error=="string"?h.error:"";w&&v.push(`${S}: ${w}`);}for(let A of p){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"source",w=typeof h.key=="string"?h.key:"projection",T=typeof h.error=="string"?h.error:"projection failed";v.push(`${S}.${w}: ${T}`);}for(let A of _){let h=d(A),S=typeof h.bindTo=="string"?h.bindTo:"compute",w=typeof h.error=="string"?h.error:"compute failed";v.push(`${S}: ${w}`);}return {status:"success",data:{cardId:typeof o.cardId=="string"?o.cardId:"(unknown)",ok:o.ok===true,issues:v,provides_outputs:J(i,R),rendered_view:O(i,R)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=k(t.get({params:{id:o}}),"cardStore.get");return Array.isArray(i.cards)?i.cards:[]}function re(n){let o=String(n.cardId||"").trim(),i=String(n.role||"").trim(),m=typeof n.text=="string"?n.text:"",u=typeof n.turn=="string"?n.turn:"";if(!o)throw new Error("manageAddChatEntryAndAnyAttachments requires cardId");if(!i)throw new Error("manageAddChatEntryAndAnyAttachments requires role");let p=b(n.files).map(_=>{let C=d(_),R=String(C.file_name??C.fileName??C.name??"").trim(),v=String(C.content_type??C.contentType??"application/octet-stream");if(!R)throw new Error("file entry requires file_name");return c({cardId:o,fileName:R,contentType:v,bytes:j(C)}).file});p.forEach((_,C)=>{let R=i==="assistant"?`AI generated: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`:`file uploaded: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`;k(a.append({params:{cardId:o},body:{role:"system",text:R,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=k(a.append({params:{cardId:o},body:{role:i,text:m,files:p,turn:u}}),"chatStore.append");return {status:"success",data:{cardId:o,id:String(y.id),role:i,turn:u,files:p}}}function te(n){let o=String(n.cardId||"").trim(),i=d(n.candidateCardContent);if(!o)throw new Error("manageUpsertCard requires cardId");if(typeof i.id!="string"||!i.id.trim())throw new Error("candidateCardContent.id must be a non-empty string");if(i.id!==o)throw new Error(`candidateCardContent.id must match cardId (${o})`);let m=P({candidateCardContent:i}),u=d(m),p=d(u.data);if(u.status!=="success"||p.isValid!==true)return {status:"fail",step:"validate",validation:m};let y=null;try{y=$(t,o);}catch{y=null;}let _=t.set({body:i});k(_,"cardStore.set");let C;try{C=r.upsertCard({params:{cardId:o,restart:!0}}),k(C,"upsertCard");}catch(v){try{y&&t.set({body:y});}catch{}throw v}let R=null;try{R=r.cardRefreshedNotify({params:{cardId:o}}),k(R,"cardRefreshedNotify");}catch{R=null;}return {status:"success",data:{validation:m,card_saved:null,board_result:C,refresh_notify:R}}}function ne(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageRemoveCard requires cardId");let i=r.removeCard({params:{id:o}});k(i,"removeCard");let m=t.del({params:{id:o}});return k(m,"cardStore.del"),{status:"success",data:{board_result:i,store_result:m}}}return {discoverSourceKinds:I,inspectBoardRuntimeStatus:x,inspectCardDefinitionAndRuntime:q,inspectChatMessagesOnCards:U,inspectFileContents:G,preflightValidateCandidateCardDefinition:P,preflightMaterializeCandidateCard:H,preflightProbeSingleSourceInCandidateCard:Y,preflightRunSingleSourceInCandidateCard:Q,preflightRunSingleSourceInLiveCard:X,preflightRunOneCycleWithCandidateCard:Z,manageReadCard:ee,manageAddChatEntryAndAnyAttachments:re,manageUpsertCard:te,manageRemoveCard:ne}}export{$e as createBoardLiveCardsMcp};//# sourceMappingURL=board-live-cards-mcp.js.map
|
|
2
2
|
//# sourceMappingURL=board-live-cards-mcp.js.map
|