@milaboratories/pl-mcp-server 53.1.0 → 54.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/dist/instructions.cjs +3 -2
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +3 -2
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +72 -0
- package/dist/project-holds.cjs.map +1 -0
- package/dist/project-holds.js +72 -0
- package/dist/project-holds.js.map +1 -0
- package/dist/server-log.cjs +8 -0
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +8 -0
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +29 -6
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +19 -7
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +29 -7
- package/dist/server.js.map +1 -1
- package/dist/tools/await.cjs +59 -58
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +59 -58
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +11 -9
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +11 -9
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-params.cjs +4 -3
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +4 -3
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +46 -41
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +46 -41
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/blocks.cjs +30 -20
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +30 -20
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +111 -80
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +113 -82
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/ids.cjs +16 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +13 -1
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/logs.cjs +28 -26
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +28 -26
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/projects.cjs +10 -27
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +11 -28
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +5 -5
- package/src/instructions.ts +3 -2
- package/src/project-holds.test.ts +183 -0
- package/src/project-holds.ts +105 -0
- package/src/server-log.test.ts +17 -5
- package/src/server-log.ts +9 -0
- package/src/server.logging.test.ts +8 -5
- package/src/server.test.ts +15 -5
- package/src/server.ts +42 -10
- package/src/tools/await.ts +94 -93
- package/src/tools/block-action-context.ts +14 -13
- package/src/tools/block-params.ts +4 -3
- package/src/tools/block-state.ts +58 -56
- package/src/tools/blocks.ts +47 -37
- package/src/tools/data-query.ts +148 -104
- package/src/tools/ids.ts +22 -1
- package/src/tools/logs.ts +41 -40
- package/src/tools/projects.ts +20 -42
- package/src/tools/types.ts +8 -1
package/dist/tools/await.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"await.cjs","names":["hints","z","projectIdInput","blockIdInput","errorResult","isTimeoutError","timedOutResult","deriveDataFromStorage","safeEval","textResult","transformFailedResult","summarizeOutputs"],"sources":["../../src/tools/await.ts"],"sourcesContent":["import { isTimeoutError } from \"@milaboratories/pl-middle-layer\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, timedOutResult, transformFailedResult } from \"./types\";\n\nexport function registerAwaitTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"await_block_done\",\n {\n title: \"Wait for Block\",\n annotations: hints.read,\n description:\n \"Wait for a block to finish computation and outputs to stabilize. \" +\n \"Returns block status, data, and concise output summary with token estimates. \" +\n \"Use `transform` to extract specific data server-side on completion.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to wait for\"),\n timeout: z.number().optional().default(120000).describe(\"Timeout in ms (default 120000)\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side when block completes. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs), `block` (status info). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, timeout, transform, transformTimeout }) => {\n
|
|
1
|
+
{"version":3,"file":"await.cjs","names":["hints","z","projectIdInput","blockIdInput","errorResult","isTimeoutError","timedOutResult","deriveDataFromStorage","safeEval","textResult","transformFailedResult","summarizeOutputs"],"sources":["../../src/tools/await.ts"],"sourcesContent":["import { isTimeoutError } from \"@milaboratories/pl-middle-layer\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, timedOutResult, transformFailedResult } from \"./types\";\n\nexport function registerAwaitTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"await_block_done\",\n {\n title: \"Wait for Block\",\n annotations: hints.read,\n description:\n \"Wait for a block to finish computation and outputs to stabilize. \" +\n \"Returns block status, data, and concise output summary with token estimates. \" +\n \"Use `transform` to extract specific data server-side on completion.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to wait for\"),\n timeout: z.number().optional().default(120000).describe(\"Timeout in ms (default 120000)\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side when block completes. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs), `block` (status info). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, timeout, transform, transformTimeout }) => {\n return await ctx.withProject(projectId, async (project) => {\n const deadline = Date.now() + timeout;\n\n while (Date.now() < deadline) {\n const overview = await project.overview.getValue();\n if (!overview) continue;\n const block = overview.blocks.find((b) => b.id === blockId);\n if (!block)\n return errorResult(\n `Block ${blockId} not found in project ${projectId}.`,\n \"Use get_project_overview to list all block IDs in this project.\",\n );\n\n // Terminal error states — return immediately\n if (block.calculationStatus === \"Limbo\") {\n return errorResult(\n \"Block entered Limbo state (upstream failed or was stopped).\",\n \"Check upstream blocks with get_project_overview. Fix or re-run the failed upstream, then retry.\",\n );\n }\n\n if (block.calculationStatus === \"NotCalculated\") {\n return errorResult(\n \"Block has not been started.\",\n \"Use run_block to start it first, then call await_block_done.\",\n );\n }\n\n if (block.calculationStatus === \"Done\") {\n // Await stable block state with remaining time budget\n const remaining = Math.max(deadline - Date.now(), 1000);\n let state;\n try {\n state = await project\n .getBlockState(blockId)\n .awaitStableValue(AbortSignal.timeout(remaining));\n } catch (e: unknown) {\n if (isTimeoutError(e)) {\n return timedOutResult({\n status: \"Done\",\n note: \"Computation done but outputs did not stabilize in time. Retry with a longer timeout.\",\n });\n }\n return errorResult(\n `Failed to get block state: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n\n const data = deriveDataFromStorage(state.blockStorage);\n\n const blockInfo = {\n id: block.id,\n title: block.title ?? block.label,\n calculationStatus: block.calculationStatus,\n canRun: block.canRun,\n stale: block.stale,\n outputErrors: block.outputErrors,\n };\n\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n {\n data,\n outputs: state.outputs,\n block: blockInfo,\n },\n transformTimeout,\n );\n return textResult({ status: \"Done\", block: blockInfo, result });\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n \"Check your JS expression syntax. Available variables: data, outputs, block.\",\n );\n }\n }\n\n return textResult({\n status: \"Done\",\n block: blockInfo,\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n }\n\n // Still running — wait up to 5s for overview to change, then re-poll.\n // Minimum 500ms delay to avoid busy-looping if awaitChange resolves immediately.\n const pollStart = Date.now();\n try {\n const result = await project.overview.getFullValue();\n await project.overview.awaitChange(AbortSignal.timeout(5000), result.uTag);\n } catch {\n // timeout or abort — just re-poll\n }\n const elapsed = Date.now() - pollStart;\n if (elapsed < 500) {\n await new Promise((r) => setTimeout(r, 500 - elapsed));\n }\n }\n\n // Timed out while running\n const overview = await project.overview.getValue();\n const block = overview?.blocks.find((b) => b.id === blockId);\n return timedOutResult({\n status: block?.calculationStatus ?? \"Unknown\",\n hint: \"The block is still running. Call await_block_done again with a longer timeout.\",\n });\n });\n },\n );\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,mBAAmB,QAAuB,KAAwB;CAChF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EAGF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,sBAAsB;GACrD,SAASF,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,IAAM,CAAC,CAAC,SAAS,gCAAgC;GACxF,WAAWA,IAAAA,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,uLAGF;GACF,kBAAkBA,IAAAA,EACf,OAAO,CAAC,CACR,SAAS,CAAC,CACV,QAAQ,GAAI,CAAC,CACb,SAAS,wDAAwD;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,SAAS,WAAW,uBAAuB;EACtE,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,MAAM,WAAW,KAAK,IAAI,IAAI;GAE9B,OAAO,KAAK,IAAI,IAAI,UAAU;IAC5B,MAAM,WAAW,MAAM,QAAQ,SAAS,SAAS;IACjD,IAAI,CAAC,UAAU;IACf,MAAM,QAAQ,SAAS,OAAO,MAAM,MAAM,EAAE,OAAO,OAAO;IAC1D,IAAI,CAAC,OACH,OAAOG,cAAAA,YACL,SAAS,QAAQ,wBAAwB,UAAU,IACnD,iEACF;IAGF,IAAI,MAAM,sBAAsB,SAC9B,OAAOA,cAAAA,YACL,+DACA,iGACF;IAGF,IAAI,MAAM,sBAAsB,iBAC9B,OAAOA,cAAAA,YACL,+BACA,8DACF;IAGF,IAAI,MAAM,sBAAsB,QAAQ;KAEtC,MAAM,YAAY,KAAK,IAAI,WAAW,KAAK,IAAI,GAAG,GAAI;KACtD,IAAI;KACJ,IAAI;MACF,QAAQ,MAAM,QACX,cAAc,OAAO,CAAC,CACtB,iBAAiB,YAAY,QAAQ,SAAS,CAAC;KACpD,SAAS,GAAY;MACnB,KAAA,GAAIC,gCAAAA,eAAAA,CAAe,CAAC,GAClB,OAAOC,cAAAA,eAAe;OACpB,QAAQ;OACR,MAAM;MACR,CAAC;MAEH,OAAOF,cAAAA,YACL,8BAA8B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,GACzE;KACF;KAEA,MAAM,QAAA,GAAOG,qBAAAA,sBAAAA,CAAsB,MAAM,YAAY;KAErD,MAAM,YAAY;MAChB,IAAI,MAAM;MACV,OAAO,MAAM,SAAS,MAAM;MAC5B,mBAAmB,MAAM;MACzB,QAAQ,MAAM;MACd,OAAO,MAAM;MACb,cAAc,MAAM;KACtB;KAEA,IAAI,WACF,IAAI;MACF,MAAM,SAAS,MAAMC,gBAAAA,SACnB,WACA;OACE;OACA,SAAS,MAAM;OACf,OAAO;MACT,GACA,gBACF;MACA,OAAOC,cAAAA,WAAW;OAAE,QAAQ;OAAQ,OAAO;OAAW;MAAO,CAAC;KAChE,SAAS,GAAY;MACnB,OAAOC,cAAAA,sBACL,GACA,6EACF;KACF;KAGF,OAAOD,cAAAA,WAAW;MAChB,QAAQ;MACR,OAAO;MACP;MACA,SAASE,eAAAA,iBAAiB,MAAM,OAA8C;KAChF,CAAC;IACH;IAIA,MAAM,YAAY,KAAK,IAAI;IAC3B,IAAI;KACF,MAAM,SAAS,MAAM,QAAQ,SAAS,aAAa;KACnD,MAAM,QAAQ,SAAS,YAAY,YAAY,QAAQ,GAAI,GAAG,OAAO,IAAI;IAC3E,QAAQ,CAER;IACA,MAAM,UAAU,KAAK,IAAI,IAAI;IAC7B,IAAI,UAAU,KACZ,MAAM,IAAI,SAAS,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;GAEzD;GAIA,MAAM,SAAQ,MADS,QAAQ,SAAS,SAAS,EAAA,EACzB,OAAO,MAAM,MAAM,EAAE,OAAO,OAAO;GAC3D,OAAOL,cAAAA,eAAe;IACpB,QAAQ,OAAO,qBAAqB;IACpC,MAAM;GACR,CAAC;EACH,CAAC;CACH,CACF;AACF"}
|
package/dist/tools/await.js
CHANGED
|
@@ -2,8 +2,8 @@ import { errorResult, hints, textResult, timedOutResult, transformFailedResult }
|
|
|
2
2
|
import { blockIdInput, projectIdInput } from "./ids.js";
|
|
3
3
|
import { summarizeOutputs } from "./tokens.js";
|
|
4
4
|
import { safeEval } from "./sandbox.js";
|
|
5
|
-
import { z } from "zod";
|
|
6
5
|
import { isTimeoutError } from "@milaboratories/pl-middle-layer";
|
|
6
|
+
import { z } from "zod";
|
|
7
7
|
import { deriveDataFromStorage } from "@platforma-sdk/model";
|
|
8
8
|
// src/tools/await.ts
|
|
9
9
|
function registerAwaitTools(server, ctx) {
|
|
@@ -19,69 +19,70 @@ function registerAwaitTools(server, ctx) {
|
|
|
19
19
|
transformTimeout: z.number().optional().default(5e3).describe("Timeout in ms for transform evaluation (default 5000).")
|
|
20
20
|
})
|
|
21
21
|
}, async ({ projectId, blockId, timeout, transform, transformTimeout }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
22
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
23
|
+
const deadline = Date.now() + timeout;
|
|
24
|
+
while (Date.now() < deadline) {
|
|
25
|
+
const overview = await project.overview.getValue();
|
|
26
|
+
if (!overview) continue;
|
|
27
|
+
const block = overview.blocks.find((b) => b.id === blockId);
|
|
28
|
+
if (!block) return errorResult(`Block ${blockId} not found in project ${projectId}.`, "Use get_project_overview to list all block IDs in this project.");
|
|
29
|
+
if (block.calculationStatus === "Limbo") return errorResult("Block entered Limbo state (upstream failed or was stopped).", "Check upstream blocks with get_project_overview. Fix or re-run the failed upstream, then retry.");
|
|
30
|
+
if (block.calculationStatus === "NotCalculated") return errorResult("Block has not been started.", "Use run_block to start it first, then call await_block_done.");
|
|
31
|
+
if (block.calculationStatus === "Done") {
|
|
32
|
+
const remaining = Math.max(deadline - Date.now(), 1e3);
|
|
33
|
+
let state;
|
|
34
|
+
try {
|
|
35
|
+
state = await project.getBlockState(blockId).awaitStableValue(AbortSignal.timeout(remaining));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (isTimeoutError(e)) return timedOutResult({
|
|
38
|
+
status: "Done",
|
|
39
|
+
note: "Computation done but outputs did not stabilize in time. Retry with a longer timeout."
|
|
40
|
+
});
|
|
41
|
+
return errorResult(`Failed to get block state: ${e instanceof Error ? e.message : String(e)}`);
|
|
42
|
+
}
|
|
43
|
+
const data = deriveDataFromStorage(state.blockStorage);
|
|
44
|
+
const blockInfo = {
|
|
45
|
+
id: block.id,
|
|
46
|
+
title: block.title ?? block.label,
|
|
47
|
+
calculationStatus: block.calculationStatus,
|
|
48
|
+
canRun: block.canRun,
|
|
49
|
+
stale: block.stale,
|
|
50
|
+
outputErrors: block.outputErrors
|
|
51
|
+
};
|
|
52
|
+
if (transform) try {
|
|
53
|
+
const result = await safeEval(transform, {
|
|
54
|
+
data,
|
|
55
|
+
outputs: state.outputs,
|
|
56
|
+
block: blockInfo
|
|
57
|
+
}, transformTimeout);
|
|
58
|
+
return textResult({
|
|
59
|
+
status: "Done",
|
|
60
|
+
block: blockInfo,
|
|
61
|
+
result
|
|
62
|
+
});
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs, block.");
|
|
65
|
+
}
|
|
58
66
|
return textResult({
|
|
59
67
|
status: "Done",
|
|
60
68
|
block: blockInfo,
|
|
61
|
-
|
|
69
|
+
data,
|
|
70
|
+
outputs: summarizeOutputs(state.outputs)
|
|
62
71
|
});
|
|
63
|
-
} catch (e) {
|
|
64
|
-
return transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs, block.");
|
|
65
72
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const pollStart = Date.now();
|
|
74
|
+
try {
|
|
75
|
+
const result = await project.overview.getFullValue();
|
|
76
|
+
await project.overview.awaitChange(AbortSignal.timeout(5e3), result.uTag);
|
|
77
|
+
} catch {}
|
|
78
|
+
const elapsed = Date.now() - pollStart;
|
|
79
|
+
if (elapsed < 500) await new Promise((r) => setTimeout(r, 500 - elapsed));
|
|
72
80
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
const elapsed = Date.now() - pollStart;
|
|
79
|
-
if (elapsed < 500) await new Promise((r) => setTimeout(r, 500 - elapsed));
|
|
80
|
-
}
|
|
81
|
-
const block = (await project.overview.getValue())?.blocks.find((b) => b.id === blockId);
|
|
82
|
-
return timedOutResult({
|
|
83
|
-
status: block?.calculationStatus ?? "Unknown",
|
|
84
|
-
hint: "The block is still running. Call await_block_done again with a longer timeout."
|
|
81
|
+
const block = (await project.overview.getValue())?.blocks.find((b) => b.id === blockId);
|
|
82
|
+
return timedOutResult({
|
|
83
|
+
status: block?.calculationStatus ?? "Unknown",
|
|
84
|
+
hint: "The block is still running. Call await_block_done again with a longer timeout."
|
|
85
|
+
});
|
|
85
86
|
});
|
|
86
87
|
});
|
|
87
88
|
}
|
package/dist/tools/await.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"await.js","names":[],"sources":["../../src/tools/await.ts"],"sourcesContent":["import { isTimeoutError } from \"@milaboratories/pl-middle-layer\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, timedOutResult, transformFailedResult } from \"./types\";\n\nexport function registerAwaitTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"await_block_done\",\n {\n title: \"Wait for Block\",\n annotations: hints.read,\n description:\n \"Wait for a block to finish computation and outputs to stabilize. \" +\n \"Returns block status, data, and concise output summary with token estimates. \" +\n \"Use `transform` to extract specific data server-side on completion.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to wait for\"),\n timeout: z.number().optional().default(120000).describe(\"Timeout in ms (default 120000)\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side when block completes. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs), `block` (status info). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, timeout, transform, transformTimeout }) => {\n
|
|
1
|
+
{"version":3,"file":"await.js","names":[],"sources":["../../src/tools/await.ts"],"sourcesContent":["import { isTimeoutError } from \"@milaboratories/pl-middle-layer\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, timedOutResult, transformFailedResult } from \"./types\";\n\nexport function registerAwaitTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"await_block_done\",\n {\n title: \"Wait for Block\",\n annotations: hints.read,\n description:\n \"Wait for a block to finish computation and outputs to stabilize. \" +\n \"Returns block status, data, and concise output summary with token estimates. \" +\n \"Use `transform` to extract specific data server-side on completion.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to wait for\"),\n timeout: z.number().optional().default(120000).describe(\"Timeout in ms (default 120000)\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side when block completes. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs), `block` (status info). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, timeout, transform, transformTimeout }) => {\n return await ctx.withProject(projectId, async (project) => {\n const deadline = Date.now() + timeout;\n\n while (Date.now() < deadline) {\n const overview = await project.overview.getValue();\n if (!overview) continue;\n const block = overview.blocks.find((b) => b.id === blockId);\n if (!block)\n return errorResult(\n `Block ${blockId} not found in project ${projectId}.`,\n \"Use get_project_overview to list all block IDs in this project.\",\n );\n\n // Terminal error states — return immediately\n if (block.calculationStatus === \"Limbo\") {\n return errorResult(\n \"Block entered Limbo state (upstream failed or was stopped).\",\n \"Check upstream blocks with get_project_overview. Fix or re-run the failed upstream, then retry.\",\n );\n }\n\n if (block.calculationStatus === \"NotCalculated\") {\n return errorResult(\n \"Block has not been started.\",\n \"Use run_block to start it first, then call await_block_done.\",\n );\n }\n\n if (block.calculationStatus === \"Done\") {\n // Await stable block state with remaining time budget\n const remaining = Math.max(deadline - Date.now(), 1000);\n let state;\n try {\n state = await project\n .getBlockState(blockId)\n .awaitStableValue(AbortSignal.timeout(remaining));\n } catch (e: unknown) {\n if (isTimeoutError(e)) {\n return timedOutResult({\n status: \"Done\",\n note: \"Computation done but outputs did not stabilize in time. Retry with a longer timeout.\",\n });\n }\n return errorResult(\n `Failed to get block state: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n\n const data = deriveDataFromStorage(state.blockStorage);\n\n const blockInfo = {\n id: block.id,\n title: block.title ?? block.label,\n calculationStatus: block.calculationStatus,\n canRun: block.canRun,\n stale: block.stale,\n outputErrors: block.outputErrors,\n };\n\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n {\n data,\n outputs: state.outputs,\n block: blockInfo,\n },\n transformTimeout,\n );\n return textResult({ status: \"Done\", block: blockInfo, result });\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n \"Check your JS expression syntax. Available variables: data, outputs, block.\",\n );\n }\n }\n\n return textResult({\n status: \"Done\",\n block: blockInfo,\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n }\n\n // Still running — wait up to 5s for overview to change, then re-poll.\n // Minimum 500ms delay to avoid busy-looping if awaitChange resolves immediately.\n const pollStart = Date.now();\n try {\n const result = await project.overview.getFullValue();\n await project.overview.awaitChange(AbortSignal.timeout(5000), result.uTag);\n } catch {\n // timeout or abort — just re-poll\n }\n const elapsed = Date.now() - pollStart;\n if (elapsed < 500) {\n await new Promise((r) => setTimeout(r, 500 - elapsed));\n }\n }\n\n // Timed out while running\n const overview = await project.overview.getValue();\n const block = overview?.blocks.find((b) => b.id === blockId);\n return timedOutResult({\n status: block?.calculationStatus ?? \"Unknown\",\n hint: \"The block is still running. Call await_block_done again with a longer timeout.\",\n });\n });\n },\n );\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,mBAAmB,QAAuB,KAAwB;CAChF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAGF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,sBAAsB;GACrD,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,IAAM,CAAC,CAAC,SAAS,gCAAgC;GACxF,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,uLAGF;GACF,kBAAkB,EACf,OAAO,CAAC,CACR,SAAS,CAAC,CACV,QAAQ,GAAI,CAAC,CACb,SAAS,wDAAwD;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,SAAS,WAAW,uBAAuB;EACtE,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,MAAM,WAAW,KAAK,IAAI,IAAI;GAE9B,OAAO,KAAK,IAAI,IAAI,UAAU;IAC5B,MAAM,WAAW,MAAM,QAAQ,SAAS,SAAS;IACjD,IAAI,CAAC,UAAU;IACf,MAAM,QAAQ,SAAS,OAAO,MAAM,MAAM,EAAE,OAAO,OAAO;IAC1D,IAAI,CAAC,OACH,OAAO,YACL,SAAS,QAAQ,wBAAwB,UAAU,IACnD,iEACF;IAGF,IAAI,MAAM,sBAAsB,SAC9B,OAAO,YACL,+DACA,iGACF;IAGF,IAAI,MAAM,sBAAsB,iBAC9B,OAAO,YACL,+BACA,8DACF;IAGF,IAAI,MAAM,sBAAsB,QAAQ;KAEtC,MAAM,YAAY,KAAK,IAAI,WAAW,KAAK,IAAI,GAAG,GAAI;KACtD,IAAI;KACJ,IAAI;MACF,QAAQ,MAAM,QACX,cAAc,OAAO,CAAC,CACtB,iBAAiB,YAAY,QAAQ,SAAS,CAAC;KACpD,SAAS,GAAY;MACnB,IAAI,eAAe,CAAC,GAClB,OAAO,eAAe;OACpB,QAAQ;OACR,MAAM;MACR,CAAC;MAEH,OAAO,YACL,8BAA8B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,GACzE;KACF;KAEA,MAAM,OAAO,sBAAsB,MAAM,YAAY;KAErD,MAAM,YAAY;MAChB,IAAI,MAAM;MACV,OAAO,MAAM,SAAS,MAAM;MAC5B,mBAAmB,MAAM;MACzB,QAAQ,MAAM;MACd,OAAO,MAAM;MACb,cAAc,MAAM;KACtB;KAEA,IAAI,WACF,IAAI;MACF,MAAM,SAAS,MAAM,SACnB,WACA;OACE;OACA,SAAS,MAAM;OACf,OAAO;MACT,GACA,gBACF;MACA,OAAO,WAAW;OAAE,QAAQ;OAAQ,OAAO;OAAW;MAAO,CAAC;KAChE,SAAS,GAAY;MACnB,OAAO,sBACL,GACA,6EACF;KACF;KAGF,OAAO,WAAW;MAChB,QAAQ;MACR,OAAO;MACP;MACA,SAAS,iBAAiB,MAAM,OAA8C;KAChF,CAAC;IACH;IAIA,MAAM,YAAY,KAAK,IAAI;IAC3B,IAAI;KACF,MAAM,SAAS,MAAM,QAAQ,SAAS,aAAa;KACnD,MAAM,QAAQ,SAAS,YAAY,YAAY,QAAQ,GAAI,GAAG,OAAO,IAAI;IAC3E,QAAQ,CAER;IACA,MAAM,UAAU,KAAK,IAAI,IAAI;IAC7B,IAAI,UAAU,KACZ,MAAM,IAAI,SAAS,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;GAEzD;GAIA,MAAM,SAAQ,MADS,QAAQ,SAAS,SAAS,EAAA,EACzB,OAAO,MAAM,MAAM,EAAE,OAAO,OAAO;GAC3D,OAAO,eAAe;IACpB,QAAQ,OAAO,qBAAqB;IACpC,MAAM;GACR,CAAC;EACH,CAAC;CACH,CACF;AACF"}
|
|
@@ -31,7 +31,7 @@ function registerBlockActionContextTools(server, ctx) {
|
|
|
31
31
|
annotations: require_types.hints.read,
|
|
32
32
|
description: "Get the block action context tree of a block run: one node per template render, each with its baggage (name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order (namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, value) and its child renders. Use it to see which step a block is in or where it waits. The result is cut to maxDepth levels and the latest maxTransitions per node; a node with childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. Reads the current state; call again to refresh.",
|
|
33
33
|
inputSchema: zod.z.object({
|
|
34
|
-
projectId: require_ids.projectIdInput.describe("Project ID
|
|
34
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
35
35
|
blockId: require_ids.blockIdInput.describe("Block ID"),
|
|
36
36
|
mode: zod.z.enum(["prod", "staging"]).optional().describe("Which render of the block: 'prod' (default) or 'staging'"),
|
|
37
37
|
contextId: zod.z.string().optional().describe("Return the subtree of this action context instead of the root"),
|
|
@@ -39,14 +39,16 @@ function registerBlockActionContextTools(server, ctx) {
|
|
|
39
39
|
maxTransitions: zod.z.number().int().min(0).optional().default(20).describe("Latest transitions to include per node (default 20)")
|
|
40
40
|
})
|
|
41
41
|
}, async ({ projectId, blockId, mode, contextId, maxDepth, maxTransitions }) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
43
|
+
const tree = await project.getBlockActionContext(blockId, mode ?? "prod");
|
|
44
|
+
if (tree === void 0) return require_types.errorResult("Block has no action context tree: it was not rendered yet, or the backend does not support block action context.");
|
|
45
|
+
const node = contextId === void 0 ? tree : findBlockActionContextNode(tree, contextId);
|
|
46
|
+
if (node === void 0) return require_types.errorResult(`Action context ${contextId} is not in the action context tree of the block. Call without contextId to see the tree.`);
|
|
47
|
+
return require_types.textResult(limitBlockActionContextTree(node, {
|
|
48
|
+
maxDepth,
|
|
49
|
+
maxTransitions
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
exports.findBlockActionContextNode = findBlockActionContextNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-action-context.cjs","names":["hints","z","projectIdInput","blockIdInput","errorResult","textResult"],"sources":["../../src/tools/block-action-context.ts"],"sourcesContent":["import type { BlockActionContextNode } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** An action context tree node as the tool returns it: cut to the requested depth and history. */\nexport type LimitedBlockActionContextNode = Omit<BlockActionContextNode, \"children\"> & {\n children: LimitedBlockActionContextNode[];\n /** Older transitions left out of this node. */\n transitionsOmitted?: number;\n /** Child renders left out below the depth limit. Request this node by contextId to see them. */\n childrenOmitted?: number;\n};\n\n/** Options of {@link limitBlockActionContextTree}. */\nexport type BlockActionContextTreeLimits = {\n /** Levels of children to include under the returned node. 0 returns the node only. */\n maxDepth: number;\n /** The latest transitions to keep per node. */\n maxTransitions: number;\n};\n\n/** Finds the node with the context ID in the tree, or undefined. */\nexport function findBlockActionContextNode(\n tree: BlockActionContextNode,\n contextId: string,\n): BlockActionContextNode | undefined {\n if (tree.contextId === contextId) return tree;\n for (const child of tree.children) {\n const found = findBlockActionContextNode(child, contextId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** Cuts an action context tree to maxDepth levels of children and the latest maxTransitions per node. */\nexport function limitBlockActionContextTree(\n node: BlockActionContextNode,\n limits: BlockActionContextTreeLimits,\n): LimitedBlockActionContextNode {\n const transitionsOmitted = Math.max(0, node.transitions.length - limits.maxTransitions);\n const limited: LimitedBlockActionContextNode = {\n ...node,\n transitions: node.transitions.slice(transitionsOmitted),\n children:\n limits.maxDepth > 0\n ? node.children.map((child) =>\n limitBlockActionContextTree(child, { ...limits, maxDepth: limits.maxDepth - 1 }),\n )\n : [],\n };\n if (transitionsOmitted > 0) limited.transitionsOmitted = transitionsOmitted;\n if (limits.maxDepth <= 0 && node.children.length > 0)\n limited.childrenOmitted = node.children.length;\n return limited;\n}\n\nexport function registerBlockActionContextTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_action_context\",\n {\n title: \"Get Block Action Context\",\n annotations: hints.read,\n description:\n \"Get the block action context tree of a block run: one node per template render, each with its baggage \" +\n \"(name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order \" +\n \"(namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, \" +\n \"value) and its child renders. Use it to see which step a block is in or where it waits. \" +\n \"The result is cut to maxDepth levels and the latest maxTransitions per node; a node with \" +\n \"childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. \" +\n \"Reads the current state; call again to refresh.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID
|
|
1
|
+
{"version":3,"file":"block-action-context.cjs","names":["hints","z","projectIdInput","blockIdInput","errorResult","textResult"],"sources":["../../src/tools/block-action-context.ts"],"sourcesContent":["import type { BlockActionContextNode } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** An action context tree node as the tool returns it: cut to the requested depth and history. */\nexport type LimitedBlockActionContextNode = Omit<BlockActionContextNode, \"children\"> & {\n children: LimitedBlockActionContextNode[];\n /** Older transitions left out of this node. */\n transitionsOmitted?: number;\n /** Child renders left out below the depth limit. Request this node by contextId to see them. */\n childrenOmitted?: number;\n};\n\n/** Options of {@link limitBlockActionContextTree}. */\nexport type BlockActionContextTreeLimits = {\n /** Levels of children to include under the returned node. 0 returns the node only. */\n maxDepth: number;\n /** The latest transitions to keep per node. */\n maxTransitions: number;\n};\n\n/** Finds the node with the context ID in the tree, or undefined. */\nexport function findBlockActionContextNode(\n tree: BlockActionContextNode,\n contextId: string,\n): BlockActionContextNode | undefined {\n if (tree.contextId === contextId) return tree;\n for (const child of tree.children) {\n const found = findBlockActionContextNode(child, contextId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** Cuts an action context tree to maxDepth levels of children and the latest maxTransitions per node. */\nexport function limitBlockActionContextTree(\n node: BlockActionContextNode,\n limits: BlockActionContextTreeLimits,\n): LimitedBlockActionContextNode {\n const transitionsOmitted = Math.max(0, node.transitions.length - limits.maxTransitions);\n const limited: LimitedBlockActionContextNode = {\n ...node,\n transitions: node.transitions.slice(transitionsOmitted),\n children:\n limits.maxDepth > 0\n ? node.children.map((child) =>\n limitBlockActionContextTree(child, { ...limits, maxDepth: limits.maxDepth - 1 }),\n )\n : [],\n };\n if (transitionsOmitted > 0) limited.transitionsOmitted = transitionsOmitted;\n if (limits.maxDepth <= 0 && node.children.length > 0)\n limited.childrenOmitted = node.children.length;\n return limited;\n}\n\nexport function registerBlockActionContextTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_action_context\",\n {\n title: \"Get Block Action Context\",\n annotations: hints.read,\n description:\n \"Get the block action context tree of a block run: one node per template render, each with its baggage \" +\n \"(name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order \" +\n \"(namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, \" +\n \"value) and its child renders. Use it to see which step a block is in or where it waits. \" +\n \"The result is cut to maxDepth levels and the latest maxTransitions per node; a node with \" +\n \"childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. \" +\n \"Reads the current state; call again to refresh.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n mode: z\n .enum([\"prod\", \"staging\"])\n .optional()\n .describe(\"Which render of the block: 'prod' (default) or 'staging'\"),\n contextId: z\n .string()\n .optional()\n .describe(\"Return the subtree of this action context instead of the root\"),\n maxDepth: z\n .number()\n .int()\n .min(0)\n .optional()\n .default(3)\n .describe(\"Levels of child renders to include (default 3)\"),\n maxTransitions: z\n .number()\n .int()\n .min(0)\n .optional()\n .default(20)\n .describe(\"Latest transitions to include per node (default 20)\"),\n }),\n },\n async ({ projectId, blockId, mode, contextId, maxDepth, maxTransitions }) => {\n return await ctx.withProject(projectId, async (project) => {\n const tree = await project.getBlockActionContext(blockId, mode ?? \"prod\");\n if (tree === undefined)\n return errorResult(\n \"Block has no action context tree: it was not rendered yet, or the backend does not support block action context.\",\n );\n\n const node = contextId === undefined ? tree : findBlockActionContextNode(tree, contextId);\n if (node === undefined)\n return errorResult(\n `Action context ${contextId} is not in the action context tree of the block. Call without contextId to see the tree.`,\n );\n\n return textResult(limitBlockActionContextTree(node, { maxDepth, maxTransitions }));\n });\n },\n );\n}\n"],"mappings":";;;;;AAwBA,SAAgB,2BACd,MACA,WACoC;CACpC,IAAI,KAAK,cAAc,WAAW,OAAO;CACzC,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,2BAA2B,OAAO,SAAS;EACzD,IAAI,UAAU,KAAA,GAAW,OAAO;CAClC;AAEF;;AAGA,SAAgB,4BACd,MACA,QAC+B;CAC/B,MAAM,qBAAqB,KAAK,IAAI,GAAG,KAAK,YAAY,SAAS,OAAO,cAAc;CACtF,MAAM,UAAyC;EAC7C,GAAG;EACH,aAAa,KAAK,YAAY,MAAM,kBAAkB;EACtD,UACE,OAAO,WAAW,IACd,KAAK,SAAS,KAAK,UACjB,4BAA4B,OAAO;GAAE,GAAG;GAAQ,UAAU,OAAO,WAAW;EAAE,CAAC,CACjF,IACA,CAAC;CACT;CACA,IAAI,qBAAqB,GAAG,QAAQ,qBAAqB;CACzD,IAAI,OAAO,YAAY,KAAK,KAAK,SAAS,SAAS,GACjD,QAAQ,kBAAkB,KAAK,SAAS;CAC1C,OAAO;AACT;AAEA,SAAgB,gCAAgC,QAAuB,KAAwB;CAC7F,OAAO,aACL,4BACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EAOF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,UAAU;GACzC,MAAMF,IAAAA,EACH,KAAK,CAAC,QAAQ,SAAS,CAAC,CAAC,CACzB,SAAS,CAAC,CACV,SAAS,0DAA0D;GACtE,WAAWA,IAAAA,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,+DAA+D;GAC3E,UAAUA,IAAAA,EACP,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,CAAC,CAAC,CACV,SAAS,gDAAgD;GAC5D,gBAAgBA,IAAAA,EACb,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,EAAE,CAAC,CACX,SAAS,qDAAqD;EACnE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,MAAM,WAAW,UAAU,qBAAqB;EAC3E,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,MAAM,OAAO,MAAM,QAAQ,sBAAsB,SAAS,QAAQ,MAAM;GACxE,IAAI,SAAS,KAAA,GACX,OAAOG,cAAAA,YACL,kHACF;GAEF,MAAM,OAAO,cAAc,KAAA,IAAY,OAAO,2BAA2B,MAAM,SAAS;GACxF,IAAI,SAAS,KAAA,GACX,OAAOA,cAAAA,YACL,kBAAkB,UAAU,yFAC9B;GAEF,OAAOC,cAAAA,WAAW,4BAA4B,MAAM;IAAE;IAAU;GAAe,CAAC,CAAC;EACnF,CAAC;CACH,CACF;AACF"}
|
|
@@ -31,7 +31,7 @@ function registerBlockActionContextTools(server, ctx) {
|
|
|
31
31
|
annotations: hints.read,
|
|
32
32
|
description: "Get the block action context tree of a block run: one node per template render, each with its baggage (name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order (namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, value) and its child renders. Use it to see which step a block is in or where it waits. The result is cut to maxDepth levels and the latest maxTransitions per node; a node with childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. Reads the current state; call again to refresh.",
|
|
33
33
|
inputSchema: z.object({
|
|
34
|
-
projectId: projectIdInput.describe("Project ID
|
|
34
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
35
35
|
blockId: blockIdInput.describe("Block ID"),
|
|
36
36
|
mode: z.enum(["prod", "staging"]).optional().describe("Which render of the block: 'prod' (default) or 'staging'"),
|
|
37
37
|
contextId: z.string().optional().describe("Return the subtree of this action context instead of the root"),
|
|
@@ -39,14 +39,16 @@ function registerBlockActionContextTools(server, ctx) {
|
|
|
39
39
|
maxTransitions: z.number().int().min(0).optional().default(20).describe("Latest transitions to include per node (default 20)")
|
|
40
40
|
})
|
|
41
41
|
}, async ({ projectId, blockId, mode, contextId, maxDepth, maxTransitions }) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
43
|
+
const tree = await project.getBlockActionContext(blockId, mode ?? "prod");
|
|
44
|
+
if (tree === void 0) return errorResult("Block has no action context tree: it was not rendered yet, or the backend does not support block action context.");
|
|
45
|
+
const node = contextId === void 0 ? tree : findBlockActionContextNode(tree, contextId);
|
|
46
|
+
if (node === void 0) return errorResult(`Action context ${contextId} is not in the action context tree of the block. Call without contextId to see the tree.`);
|
|
47
|
+
return textResult(limitBlockActionContextTree(node, {
|
|
48
|
+
maxDepth,
|
|
49
|
+
maxTransitions
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
export { findBlockActionContextNode, limitBlockActionContextTree, registerBlockActionContextTools };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-action-context.js","names":[],"sources":["../../src/tools/block-action-context.ts"],"sourcesContent":["import type { BlockActionContextNode } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** An action context tree node as the tool returns it: cut to the requested depth and history. */\nexport type LimitedBlockActionContextNode = Omit<BlockActionContextNode, \"children\"> & {\n children: LimitedBlockActionContextNode[];\n /** Older transitions left out of this node. */\n transitionsOmitted?: number;\n /** Child renders left out below the depth limit. Request this node by contextId to see them. */\n childrenOmitted?: number;\n};\n\n/** Options of {@link limitBlockActionContextTree}. */\nexport type BlockActionContextTreeLimits = {\n /** Levels of children to include under the returned node. 0 returns the node only. */\n maxDepth: number;\n /** The latest transitions to keep per node. */\n maxTransitions: number;\n};\n\n/** Finds the node with the context ID in the tree, or undefined. */\nexport function findBlockActionContextNode(\n tree: BlockActionContextNode,\n contextId: string,\n): BlockActionContextNode | undefined {\n if (tree.contextId === contextId) return tree;\n for (const child of tree.children) {\n const found = findBlockActionContextNode(child, contextId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** Cuts an action context tree to maxDepth levels of children and the latest maxTransitions per node. */\nexport function limitBlockActionContextTree(\n node: BlockActionContextNode,\n limits: BlockActionContextTreeLimits,\n): LimitedBlockActionContextNode {\n const transitionsOmitted = Math.max(0, node.transitions.length - limits.maxTransitions);\n const limited: LimitedBlockActionContextNode = {\n ...node,\n transitions: node.transitions.slice(transitionsOmitted),\n children:\n limits.maxDepth > 0\n ? node.children.map((child) =>\n limitBlockActionContextTree(child, { ...limits, maxDepth: limits.maxDepth - 1 }),\n )\n : [],\n };\n if (transitionsOmitted > 0) limited.transitionsOmitted = transitionsOmitted;\n if (limits.maxDepth <= 0 && node.children.length > 0)\n limited.childrenOmitted = node.children.length;\n return limited;\n}\n\nexport function registerBlockActionContextTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_action_context\",\n {\n title: \"Get Block Action Context\",\n annotations: hints.read,\n description:\n \"Get the block action context tree of a block run: one node per template render, each with its baggage \" +\n \"(name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order \" +\n \"(namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, \" +\n \"value) and its child renders. Use it to see which step a block is in or where it waits. \" +\n \"The result is cut to maxDepth levels and the latest maxTransitions per node; a node with \" +\n \"childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. \" +\n \"Reads the current state; call again to refresh.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID
|
|
1
|
+
{"version":3,"file":"block-action-context.js","names":[],"sources":["../../src/tools/block-action-context.ts"],"sourcesContent":["import type { BlockActionContextNode } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** An action context tree node as the tool returns it: cut to the requested depth and history. */\nexport type LimitedBlockActionContextNode = Omit<BlockActionContextNode, \"children\"> & {\n children: LimitedBlockActionContextNode[];\n /** Older transitions left out of this node. */\n transitionsOmitted?: number;\n /** Child renders left out below the depth limit. Request this node by contextId to see them. */\n childrenOmitted?: number;\n};\n\n/** Options of {@link limitBlockActionContextTree}. */\nexport type BlockActionContextTreeLimits = {\n /** Levels of children to include under the returned node. 0 returns the node only. */\n maxDepth: number;\n /** The latest transitions to keep per node. */\n maxTransitions: number;\n};\n\n/** Finds the node with the context ID in the tree, or undefined. */\nexport function findBlockActionContextNode(\n tree: BlockActionContextNode,\n contextId: string,\n): BlockActionContextNode | undefined {\n if (tree.contextId === contextId) return tree;\n for (const child of tree.children) {\n const found = findBlockActionContextNode(child, contextId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** Cuts an action context tree to maxDepth levels of children and the latest maxTransitions per node. */\nexport function limitBlockActionContextTree(\n node: BlockActionContextNode,\n limits: BlockActionContextTreeLimits,\n): LimitedBlockActionContextNode {\n const transitionsOmitted = Math.max(0, node.transitions.length - limits.maxTransitions);\n const limited: LimitedBlockActionContextNode = {\n ...node,\n transitions: node.transitions.slice(transitionsOmitted),\n children:\n limits.maxDepth > 0\n ? node.children.map((child) =>\n limitBlockActionContextTree(child, { ...limits, maxDepth: limits.maxDepth - 1 }),\n )\n : [],\n };\n if (transitionsOmitted > 0) limited.transitionsOmitted = transitionsOmitted;\n if (limits.maxDepth <= 0 && node.children.length > 0)\n limited.childrenOmitted = node.children.length;\n return limited;\n}\n\nexport function registerBlockActionContextTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_action_context\",\n {\n title: \"Get Block Action Context\",\n annotations: hints.read,\n description:\n \"Get the block action context tree of a block run: one node per template render, each with its baggage \" +\n \"(name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order \" +\n \"(namespace, reporting resource, state, detail, reason), its readings (namespace, resource, key, \" +\n \"value) and its child renders. Use it to see which step a block is in or where it waits. \" +\n \"The result is cut to maxDepth levels and the latest maxTransitions per node; a node with \" +\n \"childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. \" +\n \"Reads the current state; call again to refresh.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n mode: z\n .enum([\"prod\", \"staging\"])\n .optional()\n .describe(\"Which render of the block: 'prod' (default) or 'staging'\"),\n contextId: z\n .string()\n .optional()\n .describe(\"Return the subtree of this action context instead of the root\"),\n maxDepth: z\n .number()\n .int()\n .min(0)\n .optional()\n .default(3)\n .describe(\"Levels of child renders to include (default 3)\"),\n maxTransitions: z\n .number()\n .int()\n .min(0)\n .optional()\n .default(20)\n .describe(\"Latest transitions to include per node (default 20)\"),\n }),\n },\n async ({ projectId, blockId, mode, contextId, maxDepth, maxTransitions }) => {\n return await ctx.withProject(projectId, async (project) => {\n const tree = await project.getBlockActionContext(blockId, mode ?? \"prod\");\n if (tree === undefined)\n return errorResult(\n \"Block has no action context tree: it was not rendered yet, or the backend does not support block action context.\",\n );\n\n const node = contextId === undefined ? tree : findBlockActionContextNode(tree, contextId);\n if (node === undefined)\n return errorResult(\n `Action context ${contextId} is not in the action context tree of the block. Call without contextId to see the tree.`,\n );\n\n return textResult(limitBlockActionContextTree(node, { maxDepth, maxTransitions }));\n });\n },\n );\n}\n"],"mappings":";;;;;AAwBA,SAAgB,2BACd,MACA,WACoC;CACpC,IAAI,KAAK,cAAc,WAAW,OAAO;CACzC,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,2BAA2B,OAAO,SAAS;EACzD,IAAI,UAAU,KAAA,GAAW,OAAO;CAClC;AAEF;;AAGA,SAAgB,4BACd,MACA,QAC+B;CAC/B,MAAM,qBAAqB,KAAK,IAAI,GAAG,KAAK,YAAY,SAAS,OAAO,cAAc;CACtF,MAAM,UAAyC;EAC7C,GAAG;EACH,aAAa,KAAK,YAAY,MAAM,kBAAkB;EACtD,UACE,OAAO,WAAW,IACd,KAAK,SAAS,KAAK,UACjB,4BAA4B,OAAO;GAAE,GAAG;GAAQ,UAAU,OAAO,WAAW;EAAE,CAAC,CACjF,IACA,CAAC;CACT;CACA,IAAI,qBAAqB,GAAG,QAAQ,qBAAqB;CACzD,IAAI,OAAO,YAAY,KAAK,KAAK,SAAS,SAAS,GACjD,QAAQ,kBAAkB,KAAK,SAAS;CAC1C,OAAO;AACT;AAEA,SAAgB,gCAAgC,QAAuB,KAAwB;CAC7F,OAAO,aACL,4BACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAOF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;GACzC,MAAM,EACH,KAAK,CAAC,QAAQ,SAAS,CAAC,CAAC,CACzB,SAAS,CAAC,CACV,SAAS,0DAA0D;GACtE,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,+DAA+D;GAC3E,UAAU,EACP,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,CAAC,CAAC,CACV,SAAS,gDAAgD;GAC5D,gBAAgB,EACb,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,EAAE,CAAC,CACX,SAAS,qDAAqD;EACnE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,MAAM,WAAW,UAAU,qBAAqB;EAC3E,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,MAAM,OAAO,MAAM,QAAQ,sBAAsB,SAAS,QAAQ,MAAM;GACxE,IAAI,SAAS,KAAA,GACX,OAAO,YACL,kHACF;GAEF,MAAM,OAAO,cAAc,KAAA,IAAY,OAAO,2BAA2B,MAAM,SAAS;GACxF,IAAI,SAAS,KAAA,GACX,OAAO,YACL,kBAAkB,UAAU,yFAC9B;GAEF,OAAO,WAAW,4BAA4B,MAAM;IAAE;IAAU;GAAe,CAAC,CAAC;EACnF,CAAC;CACH,CACF;AACF"}
|
|
@@ -8,12 +8,13 @@ function registerBlockParamsTools(server, ctx) {
|
|
|
8
8
|
annotations: require_types.hints.read,
|
|
9
9
|
description: "Get a block's configuration as the initialization params of its kind: what a project template stores for this block. The block's own model derives them from its current data. Pass the result as `params` of add_block, with a block of the same kind, to create a block configured the same way. Read-only: params usually leave out view state, so to change an existing block use get_block_state and set_block_data.\n\nReturns `{ kind, params }`. `kind` is absent for a block that declares none.",
|
|
10
10
|
inputSchema: zod.z.object({
|
|
11
|
-
projectId: require_ids.projectIdInput.describe("Project ID
|
|
11
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
12
12
|
blockId: require_ids.blockIdInput.describe("Block ID")
|
|
13
13
|
})
|
|
14
14
|
}, async ({ projectId, blockId }) => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
16
|
+
return require_types.textResult(await project.getBlockInitializationParams(blockId));
|
|
17
|
+
});
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
exports.registerBlockParamsTools = registerBlockParamsTools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-params.cjs","names":["hints","z","projectIdInput","blockIdInput","textResult"],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID
|
|
1
|
+
{"version":3,"file":"block-params.cjs","names":["hints","z","projectIdInput","blockIdInput","textResult"],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n return textResult(await project.getBlockInitializationParams(blockId));\n });\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,yBAAyB,QAAuB,KAAwB;CACtF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EAMF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,UAAU;EAC3C,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,OAAOC,cAAAA,WAAW,MAAM,QAAQ,6BAA6B,OAAO,CAAC;EACvE,CAAC;CACH,CACF;AACF"}
|
|
@@ -8,12 +8,13 @@ function registerBlockParamsTools(server, ctx) {
|
|
|
8
8
|
annotations: hints.read,
|
|
9
9
|
description: "Get a block's configuration as the initialization params of its kind: what a project template stores for this block. The block's own model derives them from its current data. Pass the result as `params` of add_block, with a block of the same kind, to create a block configured the same way. Read-only: params usually leave out view state, so to change an existing block use get_block_state and set_block_data.\n\nReturns `{ kind, params }`. `kind` is absent for a block that declares none.",
|
|
10
10
|
inputSchema: z.object({
|
|
11
|
-
projectId: projectIdInput.describe("Project ID
|
|
11
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
12
12
|
blockId: blockIdInput.describe("Block ID")
|
|
13
13
|
})
|
|
14
14
|
}, async ({ projectId, blockId }) => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
16
|
+
return textResult(await project.getBlockInitializationParams(blockId));
|
|
17
|
+
});
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
export { registerBlockParamsTools };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-params.js","names":[],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID
|
|
1
|
+
{"version":3,"file":"block-params.js","names":[],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n return textResult(await project.getBlockInitializationParams(blockId));\n });\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,yBAAyB,QAAuB,KAAwB;CACtF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAMF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;EAC3C,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,OAAO,WAAW,MAAM,QAAQ,6BAA6B,OAAO,CAAC;EACvE,CAAC;CACH,CACF;AACF"}
|
|
@@ -11,23 +11,25 @@ function registerBlockStateTools(server, ctx) {
|
|
|
11
11
|
title: "Get Project Overview",
|
|
12
12
|
annotations: require_types.hints.read,
|
|
13
13
|
description: "Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)",
|
|
14
|
-
inputSchema: zod.z.object({ projectId: require_ids.projectIdInput.describe("Project ID
|
|
14
|
+
inputSchema: zod.z.object({ projectId: require_ids.projectIdInput.describe("Project ID") })
|
|
15
15
|
}, async ({ projectId }) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
17
|
+
const overview = await project.overview.getValue();
|
|
18
|
+
if (!overview) return require_types.errorResult("Project overview not available yet.");
|
|
19
|
+
return require_types.textResult({
|
|
20
|
+
label: overview.meta.label,
|
|
21
|
+
blocks: overview.blocks.map((b) => ({
|
|
22
|
+
id: b.id,
|
|
23
|
+
title: b.title ?? b.label,
|
|
24
|
+
calculationStatus: b.calculationStatus,
|
|
25
|
+
canRun: b.canRun,
|
|
26
|
+
stale: b.stale,
|
|
27
|
+
inputsValid: b.inputsValid,
|
|
28
|
+
outputErrors: b.outputErrors,
|
|
29
|
+
upstreams: b.upstreams,
|
|
30
|
+
downstreams: b.downstreams
|
|
31
|
+
}))
|
|
32
|
+
});
|
|
31
33
|
});
|
|
32
34
|
});
|
|
33
35
|
server.registerTool("get_block_state", {
|
|
@@ -41,20 +43,22 @@ function registerBlockStateTools(server, ctx) {
|
|
|
41
43
|
transformTimeout: zod.z.number().optional().default(5e3).describe("Timeout in ms for transform evaluation (default 5000).")
|
|
42
44
|
})
|
|
43
45
|
}, async ({ projectId, blockId, transform, transformTimeout }) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
47
|
+
const state = await project.getBlockState(blockId).getValue();
|
|
48
|
+
const data = (0, _platforma_sdk_model.deriveDataFromStorage)(state.blockStorage);
|
|
49
|
+
if (transform) try {
|
|
50
|
+
const result = await require_sandbox.safeEval(transform, {
|
|
51
|
+
data,
|
|
52
|
+
outputs: state.outputs
|
|
53
|
+
}, transformTimeout);
|
|
54
|
+
return require_types.textResult(result);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs.");
|
|
57
|
+
}
|
|
58
|
+
return require_types.textResult({
|
|
48
59
|
data,
|
|
49
|
-
outputs: state.outputs
|
|
50
|
-
}
|
|
51
|
-
return require_types.textResult(result);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs.");
|
|
54
|
-
}
|
|
55
|
-
return require_types.textResult({
|
|
56
|
-
data,
|
|
57
|
-
outputs: require_tokens.summarizeOutputs(state.outputs)
|
|
60
|
+
outputs: require_tokens.summarizeOutputs(state.outputs)
|
|
61
|
+
});
|
|
58
62
|
});
|
|
59
63
|
});
|
|
60
64
|
server.registerTool("set_block_data", {
|
|
@@ -67,18 +71,19 @@ function registerBlockStateTools(server, ctx) {
|
|
|
67
71
|
data: zod.z.record(zod.z.string(), zod.z.unknown()).describe("Block data object")
|
|
68
72
|
})
|
|
69
73
|
}, async ({ projectId, blockId, data }) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
75
|
+
const value = data.args ?? data;
|
|
76
|
+
try {
|
|
77
|
+
await project.mutateBlockStorage(blockId, {
|
|
78
|
+
operation: "update-block-data",
|
|
79
|
+
value
|
|
80
|
+
}, ctx.getAuthorMarker());
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e instanceof _milaboratories_pl_errors.ModelAPIVersionMismatchError) await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());
|
|
83
|
+
else throw e;
|
|
84
|
+
}
|
|
85
|
+
return require_types.textResult({ ok: true });
|
|
86
|
+
});
|
|
82
87
|
});
|
|
83
88
|
}
|
|
84
89
|
exports.registerBlockStateTools = registerBlockStateTools;
|