yaml-flow 8.5.2 → 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.
@@ -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
  }
@@ -1142,6 +1146,119 @@ try {
1142
1146
  console.log(`[T4.run-cycle] ok: ${tc.name}`);
1143
1147
  }
1144
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
+
1145
1262
  }
1146
1263
 
1147
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.2/browser/compute-jsonata.js"></script>
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.2/browser/live-cards.js"></script>
15
- <script src="https://cdn.jsdelivr.net/npm/yaml-flow@8.5.2/browser/board-livecards-localstorage.js"></script>
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))),B=de("./jsonata-sync.cjs"),K=B;function P(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 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 B(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?P(e._sourcesData??{},r.slice(16)):P(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 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`):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 R(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),m=d(l.data),j=typeof l.visible=="string"?!!N(r,l.visible):true,I=typeof m.bind=="string"?m.bind:void 0,x=typeof m.maxRows=="number"?m.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 m=d(l),j=typeof m.bindTo=="string"?m.bindTo:"",I=typeof m.ref=="string"?m.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=R(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 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),g=atob(i);return Uint8Array.from(g,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function I(){let n=d(R(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function x(){let n=d(R(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(g=>{let u=d(g);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(R(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,R(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),k=Object.fromEntries(_.map(f=>[f,R(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),v=d(R(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),A=R(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(!m||typeof E!="string"){w[M]=null;continue}try{w[M]=m({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:k,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:"",g=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=g?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,_={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...g?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},C=Object.keys(_).length>0?{params:{cardId:o},body:_}:{params:{cardId:o}},k=R(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(k.records)?k.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 g=d($(t,o)),u=b(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 D(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: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(g,u),rendered_view:O(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($(t,o)),g=b(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=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(R(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),g=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),k={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:y,computed_values:C},v=[];for(let A of b(g.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,k),rendered_view:O(i,k)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=R(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=b(n.files).map(_=>{let C=d(_),k=String(C.file_name??C.fileName??C.name??"").trim(),v=String(C.content_type??C.contentType??"application/octet-stream");if(!k)throw new Error("file entry requires file_name");return c({cardId:o,fileName:k,contentType:v,bytes:j(C)}).file});p.forEach((_,C)=>{let k=i==="assistant"?`AI generated: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`:`file uploaded: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`;R(a.append({params:{cardId:o},body:{role:"system",text:k,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=R(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=D({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=$(t,o);}catch{y=null;}let _=t.set({body:i});R(_,"cardStore.set");let C;try{C=r.upsertCard({params:{cardId:o,restart:!0}}),R(C,"upsertCard");}catch(v){try{y&&t.set({body:y});}catch{}throw v}let k=null;try{k=r.cardRefreshedNotify({params:{cardId:o}}),R(k,"cardRefreshedNotify");}catch{k=null;}return {status:"success",data:{validation:g,card_saved:null,board_result:C,refresh_notify:k}}}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 R(i,"removeCard"),i}return {discoverSourceKinds:I,inspectBoardRuntimeStatus:x,inspectCardDefinitionAndRuntime:q,inspectChatMessagesOnCards:U,inspectFileContents:G,preflightValidateCandidateCardDefinition:D,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
@@ -287,7 +287,7 @@ interface BoardLiveCardsMcp {
287
287
  cardId: string;
288
288
  candidateCardContent: UnknownRecord;
289
289
  }): BoardLiveCardsMcpManageUpsertCardResult;
290
- manageDeprecate(args: {
290
+ manageRemoveCard(args: {
291
291
  cardId: string;
292
292
  }): unknown;
293
293
  }
@@ -287,7 +287,7 @@ interface BoardLiveCardsMcp {
287
287
  cardId: string;
288
288
  candidateCardContent: UnknownRecord;
289
289
  }): BoardLiveCardsMcpManageUpsertCardResult;
290
- manageDeprecate(args: {
290
+ manageRemoveCard(args: {
291
291
  cardId: string;
292
292
  }): unknown;
293
293
  }
@@ -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),B=de("./jsonata-sync.cjs"),K=B;function P(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 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 B(e).evaluate(t)}function le(e,r){return r.startsWith("fetched_sources.")?P(e._sourcesData??{},r.slice(16)):P(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 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`):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 R(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),m=d(l.data),j=typeof l.visible=="string"?!!N(r,l.visible):true,I=typeof m.bind=="string"?m.bind:void 0,x=typeof m.maxRows=="number"?m.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 m=d(l),j=typeof m.bindTo=="string"?m.bindTo:"",I=typeof m.ref=="string"?m.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=R(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 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),g=atob(i);return Uint8Array.from(g,u=>u.charCodeAt(0))}throw new Error("file entry requires bytes, text, or base64")}function I(){let n=d(R(s.describeTaskExecutorCapabilities({}),"describeTaskExecutorCapabilities"));return {version:n.version,commonSourceFields:d(n.commonSourceDefFields),sourceKinds:d(n.sourceKinds)}}function x(){let n=d(R(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(g=>{let u=d(g);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(R(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,R(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),k=Object.fromEntries(_.map(f=>[f,R(r.getOutputsDataObject({params:{key:f}}),`getOutputsDataObject(${f})`)])),v=d(R(r.getOutputsComputedValues({params:{key:o}}),"getOutputsComputedValues")),A=R(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(!m||typeof E!="string"){w[M]=null;continue}try{w[M]=m({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:k,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:"",g=n.allTurns===true,u=typeof n.tailTurnsBeforeId=="string"?n.tailTurnsBeforeId:"",p=g?void 0:n.lastUserTurns??(i?void 0:1),y=n.tail,_={...p===void 0?{}:{tailTurns:p},...i?{turnId:i}:{},...g?{allTurns:true}:{},...u?{tailTurnsBeforeId:u}:{}},C=Object.keys(_).length>0?{params:{cardId:o},body:_}:{params:{cardId:o}},k=R(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(k.records)?k.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 g=d($(t,o)),u=b(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 D(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: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(g,u),rendered_view:O(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($(t,o)),g=b(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=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(R(s.simulateCardCycle({body:{"card-content":n.candidateCardContent,"mock-requires":n.mockRequires}}),"simulateCardCycle")),i=d(n.candidateCardContent),g=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),k={card_data:d(i.card_data),requires:n.mockRequires,fetched_sources:y,computed_values:C},v=[];for(let A of b(g.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,k),rendered_view:O(i,k)}}}function ee(n){let o=String(n.cardId||"").trim();if(!o)throw new Error("manageReadCard requires cardId");let i=R(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=b(n.files).map(_=>{let C=d(_),k=String(C.file_name??C.fileName??C.name??"").trim(),v=String(C.content_type??C.contentType??"application/octet-stream");if(!k)throw new Error("file entry requires file_name");return c({cardId:o,fileName:k,contentType:v,bytes:j(C)}).file});p.forEach((_,C)=>{let k=i==="assistant"?`AI generated: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`:`file uploaded: ${String(_.name||"")} as ${String(_.stored_name||"")} #${C}`;R(a.append({params:{cardId:o},body:{role:"system",text:k,files:[],turn:u}}),"chatStore.append(system attachment message)");});let y=R(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=D({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=$(t,o);}catch{y=null;}let _=t.set({body:i});R(_,"cardStore.set");let C;try{C=r.upsertCard({params:{cardId:o,restart:!0}}),R(C,"upsertCard");}catch(v){try{y&&t.set({body:y});}catch{}throw v}let k=null;try{k=r.cardRefreshedNotify({params:{cardId:o}}),R(k,"cardRefreshedNotify");}catch{k=null;}return {status:"success",data:{validation:g,card_saved:null,board_result:C,refresh_notify:k}}}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 R(i,"removeCard"),i}return {discoverSourceKinds:I,inspectBoardRuntimeStatus:x,inspectCardDefinitionAndRuntime:q,inspectChatMessagesOnCards:U,inspectFileContents:G,preflightValidateCandidateCardDefinition:D,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