@milaboratories/pl-mcp-server 53.1.0 → 55.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 +30 -37
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +16 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +16 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +122 -0
- package/dist/project-holds.cjs.map +1 -0
- package/dist/project-holds.js +122 -0
- package/dist/project-holds.js.map +1 -0
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +48 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +48 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +71 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +37 -24
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +71 -19
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -72
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -74
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +14 -9
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +14 -9
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +275 -6
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +273 -8
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +343 -57
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +337 -61
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +199 -76
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +193 -76
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +470 -101
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +465 -106
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +72 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +63 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +111 -30
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +108 -31
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +68 -38
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +69 -40
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +16 -12
- package/src/project-holds.test.ts +362 -0
- package/src/project-holds.ts +207 -0
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +71 -6
- package/src/server-log.ts +58 -27
- package/src/server.logging.test.ts +46 -51
- package/src/server.test.ts +166 -22
- package/src/server.ts +97 -37
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -122
- package/src/tools/block-action-context.ts +17 -13
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +626 -10
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +678 -83
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +354 -113
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +839 -145
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +89 -1
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +154 -44
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +136 -48
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +84 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
package/dist/tools/projects.cjs
CHANGED
|
@@ -1,68 +1,98 @@
|
|
|
1
1
|
const require_types = require("./types.cjs");
|
|
2
2
|
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_paging = require("./paging.cjs");
|
|
4
|
+
const require_project_template = require("./project-template.cjs");
|
|
5
|
+
let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
|
|
3
6
|
let zod = require("zod");
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Deletes a project, unless it is in use: by a holder that is not this server (an agent of
|
|
9
|
+
* another server, the user in the application), or by another call of this server still running
|
|
10
|
+
* on it (an agent of this server). This server's kept hold does not count: it ends with the
|
|
11
|
+
* delete. The check of this server's calls is made inside the middle layer's check, where no
|
|
12
|
+
* acquire comes in between, and once before it for a call that has not got its hold yet.
|
|
13
|
+
*/
|
|
14
|
+
async function deleteProject(deps, projectId) {
|
|
15
|
+
const entry = await deps.resolveProject(projectId);
|
|
16
|
+
const inUse = () => require_types.errorResult(`Project ${projectId} was not deleted: it is still in use by another agent or by the user in the application.`);
|
|
17
|
+
if (deps.callsInFlight(entry.id) > 0) return inUse();
|
|
18
|
+
try {
|
|
19
|
+
await deps.deleteProject(entry.id, { refuseIfHeldBy: (holder) => holder !== deps.projectHolder || deps.callsInFlight(entry.id) > 0 });
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (!(0, _milaboratories_pl_middle_layer.isProjectInUseError)(e)) throw e;
|
|
22
|
+
return inUse();
|
|
23
|
+
}
|
|
24
|
+
await deps.onDeleted?.(projectId);
|
|
25
|
+
return require_types.textResult({ ok: true });
|
|
26
|
+
}
|
|
5
27
|
function registerProjectTools(server, ctx) {
|
|
6
28
|
server.registerTool("list_projects", {
|
|
7
29
|
title: "List Projects",
|
|
8
30
|
annotations: require_types.hints.read,
|
|
9
|
-
description:
|
|
10
|
-
|
|
31
|
+
description: `List projects with their IDs, labels, and creation and modification times, 100 at a time. Result: \`{ projects, total, offset, hasMore }\`; page with \`offset\` and \`limit\`, or narrow with \`nameContains\`.`,
|
|
32
|
+
inputSchema: zod.z.object({
|
|
33
|
+
...require_paging.pagingArgs("projects", 100, 500),
|
|
34
|
+
nameContains: zod.z.string().optional().describe("Only projects whose label contains this text (case-insensitive).")
|
|
35
|
+
})
|
|
36
|
+
}, async ({ limit, offset, nameContains }) => {
|
|
11
37
|
const ml = ctx.requireMl();
|
|
12
38
|
await ml.projectList.refreshState();
|
|
13
39
|
const projects = await ml.projectList.awaitStableValue();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
const needle = nameContains?.toLowerCase();
|
|
41
|
+
const matching = needle === void 0 ? projects : projects.filter((p) => p.meta.label.toLowerCase().includes(needle));
|
|
42
|
+
const { items, ...paging } = require_paging.page(matching, offset, limit ?? 100);
|
|
43
|
+
return require_types.textResult({
|
|
44
|
+
projects: items.map((p) => ({
|
|
45
|
+
projectId: p.id,
|
|
46
|
+
label: p.meta.label,
|
|
47
|
+
created: p.created.toISOString(),
|
|
48
|
+
lastModified: p.lastModified.toISOString()
|
|
49
|
+
})),
|
|
50
|
+
...paging
|
|
51
|
+
}, { hint: "Ask for fewer projects: a smaller `limit` with `offset` to page, or `nameContains` to narrow by label." });
|
|
21
52
|
});
|
|
22
53
|
server.registerTool("create_project", {
|
|
23
54
|
title: "Create Project",
|
|
24
55
|
annotations: require_types.hints.additive,
|
|
25
|
-
description: "Create a new, empty project and return its ID.
|
|
56
|
+
description: "Create a new, empty project and return its ID.",
|
|
26
57
|
inputSchema: zod.z.object({ label: zod.z.string().describe("Project name") })
|
|
27
58
|
}, async ({ label }) => {
|
|
28
59
|
const projectId = await ctx.requireMl().createProject({ label });
|
|
29
60
|
await ctx.callbacks.onProjectCreated?.(projectId);
|
|
30
61
|
return require_types.textResult({ projectId });
|
|
31
62
|
});
|
|
32
|
-
server.registerTool("open_project", {
|
|
33
|
-
title: "Open Project",
|
|
34
|
-
annotations: require_types.hints.idempotent,
|
|
35
|
-
description: "Open a project for editing. Required before working with blocks.",
|
|
36
|
-
inputSchema: zod.z.object({ projectId: require_ids.projectIdInput.describe("Project ID from list_projects or create_project") })
|
|
37
|
-
}, async ({ projectId }) => {
|
|
38
|
-
const entry = await ctx.resolveProject(projectId);
|
|
39
|
-
await ctx.requireMl().openProject(entry.id);
|
|
40
|
-
await ctx.callbacks.onProjectOpened?.(projectId);
|
|
41
|
-
return require_types.textResult({ ok: true });
|
|
42
|
-
});
|
|
43
|
-
server.registerTool("close_project", {
|
|
44
|
-
title: "Close Project",
|
|
45
|
-
annotations: require_types.hints.idempotent,
|
|
46
|
-
description: "Close an opened project, releasing its resources in the application. Nothing is deleted.",
|
|
47
|
-
inputSchema: zod.z.object({ projectId: require_ids.projectIdInput.describe("Project ID") })
|
|
48
|
-
}, async ({ projectId }) => {
|
|
49
|
-
const entry = await ctx.resolveProject(projectId);
|
|
50
|
-
await ctx.requireMl().closeProject(entry.id);
|
|
51
|
-
await ctx.callbacks.onProjectClosed?.(projectId);
|
|
52
|
-
return require_types.textResult({ ok: true });
|
|
53
|
-
});
|
|
54
63
|
server.registerTool("delete_project", {
|
|
55
64
|
title: "Delete Project",
|
|
56
65
|
annotations: require_types.hints.destructive,
|
|
57
|
-
description: "Delete a project permanently.
|
|
66
|
+
description: "Delete a project permanently, with all its blocks and results. Refused while the project is in use by another agent (another call working on it, through this server or another) or by the user in the application.",
|
|
58
67
|
inputSchema: zod.z.object({ projectId: require_ids.projectIdInput.describe("Project ID") })
|
|
59
68
|
}, async ({ projectId }) => {
|
|
60
|
-
const
|
|
61
|
-
await
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const ml = ctx.requireMl();
|
|
70
|
+
return await deleteProject({
|
|
71
|
+
resolveProject: (id) => ctx.resolveProject(id),
|
|
72
|
+
deleteProject: (id, ops) => ml.deleteProject(id, ops),
|
|
73
|
+
projectHolder: ctx.projectHolder,
|
|
74
|
+
callsInFlight: (id) => ctx.callsInFlight(id),
|
|
75
|
+
onDeleted: ctx.callbacks.onProjectDeleted
|
|
76
|
+
}, projectId);
|
|
77
|
+
});
|
|
78
|
+
server.registerTool("export_project_template", {
|
|
79
|
+
title: "Export Project Template",
|
|
80
|
+
annotations: require_types.hints.additive,
|
|
81
|
+
description: "Export a project as a template file, to hand it over or reproduce it elsewhere: writes the `template-v1` YAML the application's Export Project as Template… writes, unchanged, to `savePath`, a new file (an existing one is never overwritten), so the application's import reads it. All or nothing: when any block cannot be written, nothing is written and the error names every such block (id, label, reason). read_file reads the file.\n\nReturns `{ path, bytes, fileHandlesTotal, offset, hasMore, fileHandles }`: a page of the file handles the params hold, each with `blockId`, `paramsPath`, `handle`, and the file it names (`localPath`, or `storage` and `storagePath`). Page on without `savePath`. Handles work only on the desktop that made them; on another, replace each with a handle of the file there (get_file_handles).",
|
|
82
|
+
inputSchema: zod.z.object({
|
|
83
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
84
|
+
savePath: zod.z.string().optional().describe("Absolute path of the new file to write. Omit to list the file handles only."),
|
|
85
|
+
...require_paging.pagingArgs("file handles", 50, 100)
|
|
86
|
+
})
|
|
87
|
+
}, async (input) => {
|
|
88
|
+
const ml = ctx.requireMl();
|
|
89
|
+
return await require_project_template.exportProjectTemplate({
|
|
90
|
+
resolveProject: (id) => ctx.resolveProject(id),
|
|
91
|
+
exportProjectAsTemplate: (id) => ml.exportProjectAsTemplate(id)
|
|
92
|
+
}, input);
|
|
64
93
|
});
|
|
65
94
|
}
|
|
95
|
+
exports.deleteProject = deleteProject;
|
|
66
96
|
exports.registerProjectTools = registerProjectTools;
|
|
67
97
|
|
|
68
98
|
//# sourceMappingURL=projects.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.cjs","names":["hints","textResult","z","projectIdInput"],"sources":["../../src/tools/projects.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerProjectTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_projects\",\n {\n title: \"List Projects\",\n annotations: hints.read,\n description: \"List all projects with their IDs, labels, and status\",\n },\n async () => {\n const ml = ctx.requireMl();\n await ml.projectList.refreshState();\n const projects = await ml.projectList.awaitStableValue();\n return textResult(\n projects.map((p) => ({\n projectId: p.id,\n label: p.meta.label,\n opened: p.opened,\n created: p.created.toISOString(),\n lastModified: p.lastModified.toISOString(),\n })),\n );\n },\n );\n\n server.registerTool(\n \"create_project\",\n {\n title: \"Create Project\",\n annotations: hints.additive,\n description:\n \"Create a new, empty project and return its ID. Call open_project before adding blocks to it.\",\n inputSchema: z.object({ label: z.string().describe(\"Project name\") }),\n },\n async ({ label }) => {\n const projectId = await ctx.requireMl().createProject({ label });\n await ctx.callbacks.onProjectCreated?.(projectId);\n return textResult({ projectId });\n },\n );\n\n server.registerTool(\n \"open_project\",\n {\n title: \"Open Project\",\n annotations: hints.idempotent,\n description: \"Open a project for editing. Required before working with blocks.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID from list_projects or create_project\"),\n }),\n },\n async ({ projectId }) => {\n const entry = await ctx.resolveProject(projectId);\n await ctx.requireMl().openProject(entry.id);\n await ctx.callbacks.onProjectOpened?.(projectId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"close_project\",\n {\n title: \"Close Project\",\n annotations: hints.idempotent,\n description:\n \"Close an opened project, releasing its resources in the application. Nothing is deleted.\",\n inputSchema: z.object({ projectId: projectIdInput.describe(\"Project ID\") }),\n },\n async ({ projectId }) => {\n const entry = await ctx.resolveProject(projectId);\n await ctx.requireMl().closeProject(entry.id);\n await ctx.callbacks.onProjectClosed?.(projectId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"delete_project\",\n {\n title: \"Delete Project\",\n annotations: hints.destructive,\n description: \"Delete a project permanently. The project must be closed first.\",\n inputSchema: z.object({ projectId: projectIdInput.describe(\"Project ID\") }),\n },\n async ({ projectId }) => {\n const entry = await ctx.resolveProject(projectId);\n await ctx.requireMl().deleteProject(entry.id);\n await ctx.callbacks.onProjectDeleted?.(projectId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,qBAAqB,QAAuB,KAAwB;CAClF,OAAO,aACL,iBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aAAa;CACf,GACA,YAAY;EACV,MAAM,KAAK,IAAI,UAAU;EACzB,MAAM,GAAG,YAAY,aAAa;EAClC,MAAM,WAAW,MAAM,GAAG,YAAY,iBAAiB;EACvD,OAAOC,cAAAA,WACL,SAAS,KAAK,OAAO;GACnB,WAAW,EAAE;GACb,OAAO,EAAE,KAAK;GACd,QAAQ,EAAE;GACV,SAAS,EAAE,QAAQ,YAAY;GAC/B,cAAc,EAAE,aAAa,YAAY;EAC3C,EAAE,CACJ;CACF,CACF;CAEA,OAAO,aACL,kBACA;EACE,OAAO;EACP,aAAaD,cAAAA,MAAM;EACnB,aACE;EACF,aAAaE,IAAAA,EAAE,OAAO,EAAE,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc,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AC,CAAC,cAAc,MAAM,EAAE;EAC5C,MAAM,IAAI,UAAU,mBAAmB,SAAS;EAChD,OAAOF,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"projects.cjs","names":["errorResult","isProjectInUseError","textResult","hints","z","pagingArgs","page","projectIdInput","exportProjectTemplate"],"sources":["../../src/tools/projects.ts"],"sourcesContent":["import type { ProjectHolder, ProjectId } from \"@milaboratories/pl-middle-layer\";\nimport { isProjectInUseError } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { page, pagingArgs } from \"./paging\";\nimport {\n exportProjectTemplate,\n TEMPLATE_HANDLES_DEFAULT,\n TEMPLATE_HANDLES_MAX,\n} from \"./project-template\";\n\n/** How many projects list_projects returns when the caller does not say. */\nexport const LIST_PROJECTS_DEFAULT_LIMIT = 100;\n/** The most projects one list_projects call returns. */\nexport const LIST_PROJECTS_MAX_LIMIT = 500;\n\n/** What {@link deleteProject} needs: the middle layer's delete and this server's holds. */\nexport type DeleteProjectDeps = {\n resolveProject: (projectId: ProjectId) => Promise<{ id: ProjectId }>;\n deleteProject: (\n id: ProjectId,\n ops: { refuseIfHeldBy: (holder: ProjectHolder) => boolean },\n ) => Promise<void>;\n /** The holder of this server's holds. */\n projectHolder: ProjectHolder;\n /** How many calls of this server are in flight on the project (the delete is not one). */\n callsInFlight: (id: ProjectId) => number;\n onDeleted?: (projectId: ProjectId) => void | Promise<void>;\n};\n\n/**\n * Deletes a project, unless it is in use: by a holder that is not this server (an agent of\n * another server, the user in the application), or by another call of this server still running\n * on it (an agent of this server). This server's kept hold does not count: it ends with the\n * delete. The check of this server's calls is made inside the middle layer's check, where no\n * acquire comes in between, and once before it for a call that has not got its hold yet.\n */\nexport async function deleteProject(deps: DeleteProjectDeps, projectId: ProjectId) {\n const entry = await deps.resolveProject(projectId);\n const inUse = () =>\n errorResult(\n `Project ${projectId} was not deleted: it is still in use by another agent or by the ` +\n \"user in the application.\",\n );\n if (deps.callsInFlight(entry.id) > 0) return inUse();\n try {\n await deps.deleteProject(entry.id, {\n refuseIfHeldBy: (holder) => holder !== deps.projectHolder || deps.callsInFlight(entry.id) > 0,\n });\n } catch (e: unknown) {\n if (!isProjectInUseError(e)) throw e;\n return inUse();\n }\n await deps.onDeleted?.(projectId);\n return textResult({ ok: true });\n}\n\nexport function registerProjectTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_projects\",\n {\n title: \"List Projects\",\n annotations: hints.read,\n description:\n \"List projects with their IDs, labels, and creation and modification times, \" +\n `${LIST_PROJECTS_DEFAULT_LIMIT} at a time. Result: \\`{ projects, total, offset, hasMore }\\`; ` +\n \"page with `offset` and `limit`, or narrow with `nameContains`.\",\n inputSchema: z.object({\n ...pagingArgs(\"projects\", LIST_PROJECTS_DEFAULT_LIMIT, LIST_PROJECTS_MAX_LIMIT),\n nameContains: z\n .string()\n .optional()\n .describe(\"Only projects whose label contains this text (case-insensitive).\"),\n }),\n },\n async ({ limit, offset, nameContains }) => {\n const ml = ctx.requireMl();\n await ml.projectList.refreshState();\n const projects = await ml.projectList.awaitStableValue();\n const needle = nameContains?.toLowerCase();\n const matching =\n needle === undefined\n ? projects\n : projects.filter((p) => p.meta.label.toLowerCase().includes(needle));\n const { items, ...paging } = page(matching, offset, limit ?? LIST_PROJECTS_DEFAULT_LIMIT);\n return textResult(\n {\n projects: items.map((p) => ({\n projectId: p.id,\n label: p.meta.label,\n created: p.created.toISOString(),\n lastModified: p.lastModified.toISOString(),\n })),\n ...paging,\n },\n {\n hint:\n \"Ask for fewer projects: a smaller `limit` with `offset` to page, or `nameContains` \" +\n \"to narrow by label.\",\n },\n );\n },\n );\n\n server.registerTool(\n \"create_project\",\n {\n title: \"Create Project\",\n annotations: hints.additive,\n description: \"Create a new, empty project and return its ID.\",\n inputSchema: z.object({ label: z.string().describe(\"Project name\") }),\n },\n async ({ label }) => {\n const projectId = await ctx.requireMl().createProject({ label });\n await ctx.callbacks.onProjectCreated?.(projectId);\n return textResult({ projectId });\n },\n );\n\n server.registerTool(\n \"delete_project\",\n {\n title: \"Delete Project\",\n annotations: hints.destructive,\n description:\n \"Delete a project permanently, with all its blocks and results. Refused while the project \" +\n \"is in use by another agent (another call working on it, through this server or \" +\n \"another) or by the user in the application.\",\n inputSchema: z.object({ projectId: projectIdInput.describe(\"Project ID\") }),\n },\n async ({ projectId }) => {\n const ml = ctx.requireMl();\n return await deleteProject(\n {\n resolveProject: (id) => ctx.resolveProject(id),\n deleteProject: (id, ops) => ml.deleteProject(id, ops),\n projectHolder: ctx.projectHolder,\n callsInFlight: (id) => ctx.callsInFlight(id),\n onDeleted: ctx.callbacks.onProjectDeleted,\n },\n projectId,\n );\n },\n );\n\n server.registerTool(\n \"export_project_template\",\n {\n title: \"Export Project Template\",\n annotations: hints.additive,\n description:\n \"Export a project as a template file, to hand it over or reproduce it elsewhere: writes \" +\n \"the `template-v1` YAML the application's Export Project as Template… writes, unchanged, \" +\n \"to `savePath`, a new file (an existing one is never overwritten), so the application's \" +\n \"import reads it. All or nothing: when any block cannot be written, nothing is written \" +\n \"and the error names every such block (id, label, reason). read_file reads the file.\\n\\n\" +\n \"Returns `{ path, bytes, fileHandlesTotal, offset, hasMore, fileHandles }`: a page of the \" +\n \"file handles the params hold, each with `blockId`, `paramsPath`, `handle`, and the file \" +\n \"it names (`localPath`, or `storage` and `storagePath`). Page on without `savePath`. \" +\n \"Handles work only on the desktop that made them; on another, replace each with a handle \" +\n \"of the file there (get_file_handles).\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n savePath: z\n .string()\n .optional()\n .describe(\"Absolute path of the new file to write. Omit to list the file handles only.\"),\n ...pagingArgs(\"file handles\", TEMPLATE_HANDLES_DEFAULT, TEMPLATE_HANDLES_MAX),\n }),\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await exportProjectTemplate(\n {\n resolveProject: (id) => ctx.resolveProject(id),\n exportProjectAsTemplate: (id) => ml.exportProjectAsTemplate(id),\n },\n input,\n );\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,eAAsB,cAAc,MAAyB,WAAsB;CACjF,MAAM,QAAQ,MAAM,KAAK,eAAe,SAAS;CACjD,MAAM,cACJA,cAAAA,YACE,WAAW,UAAU,yFAEvB;CACF,IAAI,KAAK,cAAc,MAAM,EAAE,IAAI,GAAG,OAAO,MAAM;CACnD,IAAI;EACF,MAAM,KAAK,cAAc,MAAM,IAAI,EACjC,iBAAiB,WAAW,WAAW,KAAK,iBAAiB,KAAK,cAAc,MAAM,EAAE,IAAI,EAC9F,CAAC;CACH,SAAS,GAAY;EACnB,IAAI,EAAA,GAACC,gCAAAA,oBAAAA,CAAoB,CAAC,GAAG,MAAM;EACnC,OAAO,MAAM;CACf;CACA,MAAM,KAAK,YAAY,SAAS;CAChC,OAAOC,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;AAChC;AAEA,SAAgB,qBAAqB,QAAuB,KAAwB;CAClF,OAAO,aACL,iBACA;EACE,OAAO;EACP,aAAaC,cAAAA,MAAM;EACnB,aACE;EAGF,aAAaC,IAAAA,EAAE,OAAO;GACpB,GAAGC,eAAAA,WAAW,YAAA,KAAA,GAAgE;GAC9E,cAAcD,IAAAA,EACX,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,kEAAkE;EAChF,CAAC;CACH,GACA,OAAO,EAAE,OAAO,QAAQ,mBAAmB;EACzC,MAAM,KAAK,IAAI,UAAU;EACzB,MAAM,GAAG,YAAY,aAAa;EAClC,MAAM,WAAW,MAAM,GAAG,YAAY,iBAAiB;EACvD,MAAM,SAAS,cAAc,YAAY;EACzC,MAAM,WACJ,WAAW,KAAA,IACP,WACA,SAAS,QAAQ,MAAM,EAAE,KAAK,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC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AAe,SAAS,YAAY;GAC/C,UAAUH,IAAAA,EACP,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,6EAA6E;GACzF,GAAGC,eAAAA,WAAW,gBAAA,IAAA,GAA8D;EAC9E,CAAC;CACH,GACA,OAAO,UAAU;EACf,MAAM,KAAK,IAAI,UAAU;EACzB,OAAO,MAAMG,yBAAAA,sBACX;GACE,iBAAiB,OAAO,IAAI,eAAe,EAAE;GAC7C,0BAA0B,OAAO,GAAG,wBAAwB,EAAE;EAChE,GACA,KACF;CACF,CACF;AACF"}
|
package/dist/tools/projects.js
CHANGED
|
@@ -1,68 +1,97 @@
|
|
|
1
|
-
import { hints, textResult } from "./types.js";
|
|
1
|
+
import { errorResult, hints, textResult } from "./types.js";
|
|
2
2
|
import { projectIdInput } from "./ids.js";
|
|
3
|
+
import { page, pagingArgs } from "./paging.js";
|
|
4
|
+
import { exportProjectTemplate } from "./project-template.js";
|
|
5
|
+
import { isProjectInUseError } from "@milaboratories/pl-middle-layer";
|
|
3
6
|
import { z } from "zod";
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Deletes a project, unless it is in use: by a holder that is not this server (an agent of
|
|
9
|
+
* another server, the user in the application), or by another call of this server still running
|
|
10
|
+
* on it (an agent of this server). This server's kept hold does not count: it ends with the
|
|
11
|
+
* delete. The check of this server's calls is made inside the middle layer's check, where no
|
|
12
|
+
* acquire comes in between, and once before it for a call that has not got its hold yet.
|
|
13
|
+
*/
|
|
14
|
+
async function deleteProject(deps, projectId) {
|
|
15
|
+
const entry = await deps.resolveProject(projectId);
|
|
16
|
+
const inUse = () => errorResult(`Project ${projectId} was not deleted: it is still in use by another agent or by the user in the application.`);
|
|
17
|
+
if (deps.callsInFlight(entry.id) > 0) return inUse();
|
|
18
|
+
try {
|
|
19
|
+
await deps.deleteProject(entry.id, { refuseIfHeldBy: (holder) => holder !== deps.projectHolder || deps.callsInFlight(entry.id) > 0 });
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (!isProjectInUseError(e)) throw e;
|
|
22
|
+
return inUse();
|
|
23
|
+
}
|
|
24
|
+
await deps.onDeleted?.(projectId);
|
|
25
|
+
return textResult({ ok: true });
|
|
26
|
+
}
|
|
5
27
|
function registerProjectTools(server, ctx) {
|
|
6
28
|
server.registerTool("list_projects", {
|
|
7
29
|
title: "List Projects",
|
|
8
30
|
annotations: hints.read,
|
|
9
|
-
description:
|
|
10
|
-
|
|
31
|
+
description: `List projects with their IDs, labels, and creation and modification times, 100 at a time. Result: \`{ projects, total, offset, hasMore }\`; page with \`offset\` and \`limit\`, or narrow with \`nameContains\`.`,
|
|
32
|
+
inputSchema: z.object({
|
|
33
|
+
...pagingArgs("projects", 100, 500),
|
|
34
|
+
nameContains: z.string().optional().describe("Only projects whose label contains this text (case-insensitive).")
|
|
35
|
+
})
|
|
36
|
+
}, async ({ limit, offset, nameContains }) => {
|
|
11
37
|
const ml = ctx.requireMl();
|
|
12
38
|
await ml.projectList.refreshState();
|
|
13
39
|
const projects = await ml.projectList.awaitStableValue();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
const needle = nameContains?.toLowerCase();
|
|
41
|
+
const matching = needle === void 0 ? projects : projects.filter((p) => p.meta.label.toLowerCase().includes(needle));
|
|
42
|
+
const { items, ...paging } = page(matching, offset, limit ?? 100);
|
|
43
|
+
return textResult({
|
|
44
|
+
projects: items.map((p) => ({
|
|
45
|
+
projectId: p.id,
|
|
46
|
+
label: p.meta.label,
|
|
47
|
+
created: p.created.toISOString(),
|
|
48
|
+
lastModified: p.lastModified.toISOString()
|
|
49
|
+
})),
|
|
50
|
+
...paging
|
|
51
|
+
}, { hint: "Ask for fewer projects: a smaller `limit` with `offset` to page, or `nameContains` to narrow by label." });
|
|
21
52
|
});
|
|
22
53
|
server.registerTool("create_project", {
|
|
23
54
|
title: "Create Project",
|
|
24
55
|
annotations: hints.additive,
|
|
25
|
-
description: "Create a new, empty project and return its ID.
|
|
56
|
+
description: "Create a new, empty project and return its ID.",
|
|
26
57
|
inputSchema: z.object({ label: z.string().describe("Project name") })
|
|
27
58
|
}, async ({ label }) => {
|
|
28
59
|
const projectId = await ctx.requireMl().createProject({ label });
|
|
29
60
|
await ctx.callbacks.onProjectCreated?.(projectId);
|
|
30
61
|
return textResult({ projectId });
|
|
31
62
|
});
|
|
32
|
-
server.registerTool("open_project", {
|
|
33
|
-
title: "Open Project",
|
|
34
|
-
annotations: hints.idempotent,
|
|
35
|
-
description: "Open a project for editing. Required before working with blocks.",
|
|
36
|
-
inputSchema: z.object({ projectId: projectIdInput.describe("Project ID from list_projects or create_project") })
|
|
37
|
-
}, async ({ projectId }) => {
|
|
38
|
-
const entry = await ctx.resolveProject(projectId);
|
|
39
|
-
await ctx.requireMl().openProject(entry.id);
|
|
40
|
-
await ctx.callbacks.onProjectOpened?.(projectId);
|
|
41
|
-
return textResult({ ok: true });
|
|
42
|
-
});
|
|
43
|
-
server.registerTool("close_project", {
|
|
44
|
-
title: "Close Project",
|
|
45
|
-
annotations: hints.idempotent,
|
|
46
|
-
description: "Close an opened project, releasing its resources in the application. Nothing is deleted.",
|
|
47
|
-
inputSchema: z.object({ projectId: projectIdInput.describe("Project ID") })
|
|
48
|
-
}, async ({ projectId }) => {
|
|
49
|
-
const entry = await ctx.resolveProject(projectId);
|
|
50
|
-
await ctx.requireMl().closeProject(entry.id);
|
|
51
|
-
await ctx.callbacks.onProjectClosed?.(projectId);
|
|
52
|
-
return textResult({ ok: true });
|
|
53
|
-
});
|
|
54
63
|
server.registerTool("delete_project", {
|
|
55
64
|
title: "Delete Project",
|
|
56
65
|
annotations: hints.destructive,
|
|
57
|
-
description: "Delete a project permanently.
|
|
66
|
+
description: "Delete a project permanently, with all its blocks and results. Refused while the project is in use by another agent (another call working on it, through this server or another) or by the user in the application.",
|
|
58
67
|
inputSchema: z.object({ projectId: projectIdInput.describe("Project ID") })
|
|
59
68
|
}, async ({ projectId }) => {
|
|
60
|
-
const
|
|
61
|
-
await
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const ml = ctx.requireMl();
|
|
70
|
+
return await deleteProject({
|
|
71
|
+
resolveProject: (id) => ctx.resolveProject(id),
|
|
72
|
+
deleteProject: (id, ops) => ml.deleteProject(id, ops),
|
|
73
|
+
projectHolder: ctx.projectHolder,
|
|
74
|
+
callsInFlight: (id) => ctx.callsInFlight(id),
|
|
75
|
+
onDeleted: ctx.callbacks.onProjectDeleted
|
|
76
|
+
}, projectId);
|
|
77
|
+
});
|
|
78
|
+
server.registerTool("export_project_template", {
|
|
79
|
+
title: "Export Project Template",
|
|
80
|
+
annotations: hints.additive,
|
|
81
|
+
description: "Export a project as a template file, to hand it over or reproduce it elsewhere: writes the `template-v1` YAML the application's Export Project as Template… writes, unchanged, to `savePath`, a new file (an existing one is never overwritten), so the application's import reads it. All or nothing: when any block cannot be written, nothing is written and the error names every such block (id, label, reason). read_file reads the file.\n\nReturns `{ path, bytes, fileHandlesTotal, offset, hasMore, fileHandles }`: a page of the file handles the params hold, each with `blockId`, `paramsPath`, `handle`, and the file it names (`localPath`, or `storage` and `storagePath`). Page on without `savePath`. Handles work only on the desktop that made them; on another, replace each with a handle of the file there (get_file_handles).",
|
|
82
|
+
inputSchema: z.object({
|
|
83
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
84
|
+
savePath: z.string().optional().describe("Absolute path of the new file to write. Omit to list the file handles only."),
|
|
85
|
+
...pagingArgs("file handles", 50, 100)
|
|
86
|
+
})
|
|
87
|
+
}, async (input) => {
|
|
88
|
+
const ml = ctx.requireMl();
|
|
89
|
+
return await exportProjectTemplate({
|
|
90
|
+
resolveProject: (id) => ctx.resolveProject(id),
|
|
91
|
+
exportProjectAsTemplate: (id) => ml.exportProjectAsTemplate(id)
|
|
92
|
+
}, input);
|
|
64
93
|
});
|
|
65
94
|
}
|
|
66
|
-
export { registerProjectTools };
|
|
95
|
+
export { deleteProject, registerProjectTools };
|
|
67
96
|
|
|
68
97
|
//# sourceMappingURL=projects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","names":[],"sources":["../../src/tools/projects.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerProjectTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_projects\",\n {\n title: \"List Projects\",\n annotations: hints.read,\n description
|
|
1
|
+
{"version":3,"file":"projects.js","names":[],"sources":["../../src/tools/projects.ts"],"sourcesContent":["import type { ProjectHolder, ProjectId } from \"@milaboratories/pl-middle-layer\";\nimport { isProjectInUseError } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { page, pagingArgs } from \"./paging\";\nimport {\n exportProjectTemplate,\n TEMPLATE_HANDLES_DEFAULT,\n TEMPLATE_HANDLES_MAX,\n} from \"./project-template\";\n\n/** How many projects list_projects returns when the caller does not say. */\nexport const LIST_PROJECTS_DEFAULT_LIMIT = 100;\n/** The most projects one list_projects call returns. */\nexport const LIST_PROJECTS_MAX_LIMIT = 500;\n\n/** What {@link deleteProject} needs: the middle layer's delete and this server's holds. */\nexport type DeleteProjectDeps = {\n resolveProject: (projectId: ProjectId) => Promise<{ id: ProjectId }>;\n deleteProject: (\n id: ProjectId,\n ops: { refuseIfHeldBy: (holder: ProjectHolder) => boolean },\n ) => Promise<void>;\n /** The holder of this server's holds. */\n projectHolder: ProjectHolder;\n /** How many calls of this server are in flight on the project (the delete is not one). */\n callsInFlight: (id: ProjectId) => number;\n onDeleted?: (projectId: ProjectId) => void | Promise<void>;\n};\n\n/**\n * Deletes a project, unless it is in use: by a holder that is not this server (an agent of\n * another server, the user in the application), or by another call of this server still running\n * on it (an agent of this server). This server's kept hold does not count: it ends with the\n * delete. The check of this server's calls is made inside the middle layer's check, where no\n * acquire comes in between, and once before it for a call that has not got its hold yet.\n */\nexport async function deleteProject(deps: DeleteProjectDeps, projectId: ProjectId) {\n const entry = await deps.resolveProject(projectId);\n const inUse = () =>\n errorResult(\n `Project ${projectId} was not deleted: it is still in use by another agent or by the ` +\n \"user in the application.\",\n );\n if (deps.callsInFlight(entry.id) > 0) return inUse();\n try {\n await deps.deleteProject(entry.id, {\n refuseIfHeldBy: (holder) => holder !== deps.projectHolder || deps.callsInFlight(entry.id) > 0,\n });\n } catch (e: unknown) {\n if (!isProjectInUseError(e)) throw e;\n return inUse();\n }\n await deps.onDeleted?.(projectId);\n return textResult({ ok: true });\n}\n\nexport function registerProjectTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_projects\",\n {\n title: \"List Projects\",\n annotations: hints.read,\n description:\n \"List projects with their IDs, labels, and creation and modification times, \" +\n `${LIST_PROJECTS_DEFAULT_LIMIT} at a time. Result: \\`{ projects, total, offset, hasMore }\\`; ` +\n \"page with `offset` and `limit`, or narrow with `nameContains`.\",\n inputSchema: z.object({\n ...pagingArgs(\"projects\", LIST_PROJECTS_DEFAULT_LIMIT, LIST_PROJECTS_MAX_LIMIT),\n nameContains: z\n .string()\n .optional()\n .describe(\"Only projects whose label contains this text (case-insensitive).\"),\n }),\n },\n async ({ limit, offset, nameContains }) => {\n const ml = ctx.requireMl();\n await ml.projectList.refreshState();\n const projects = await ml.projectList.awaitStableValue();\n const needle = nameContains?.toLowerCase();\n const matching =\n needle === undefined\n ? projects\n : projects.filter((p) => p.meta.label.toLowerCase().includes(needle));\n const { items, ...paging } = page(matching, offset, limit ?? LIST_PROJECTS_DEFAULT_LIMIT);\n return textResult(\n {\n projects: items.map((p) => ({\n projectId: p.id,\n label: p.meta.label,\n created: p.created.toISOString(),\n lastModified: p.lastModified.toISOString(),\n })),\n ...paging,\n },\n {\n hint:\n \"Ask for fewer projects: a smaller `limit` with `offset` to page, or `nameContains` \" +\n \"to narrow by label.\",\n },\n );\n },\n );\n\n server.registerTool(\n \"create_project\",\n {\n title: \"Create Project\",\n annotations: hints.additive,\n description: \"Create a new, empty project and return its ID.\",\n inputSchema: z.object({ label: z.string().describe(\"Project name\") }),\n },\n async ({ label }) => {\n const projectId = await ctx.requireMl().createProject({ label });\n await ctx.callbacks.onProjectCreated?.(projectId);\n return textResult({ projectId });\n },\n );\n\n server.registerTool(\n \"delete_project\",\n {\n title: \"Delete Project\",\n annotations: hints.destructive,\n description:\n \"Delete a project permanently, with all its blocks and results. Refused while the project \" +\n \"is in use by another agent (another call working on it, through this server or \" +\n \"another) or by the user in the application.\",\n inputSchema: z.object({ projectId: projectIdInput.describe(\"Project ID\") }),\n },\n async ({ projectId }) => {\n const ml = ctx.requireMl();\n return await deleteProject(\n {\n resolveProject: (id) => ctx.resolveProject(id),\n deleteProject: (id, ops) => ml.deleteProject(id, ops),\n projectHolder: ctx.projectHolder,\n callsInFlight: (id) => ctx.callsInFlight(id),\n onDeleted: ctx.callbacks.onProjectDeleted,\n },\n projectId,\n );\n },\n );\n\n server.registerTool(\n \"export_project_template\",\n {\n title: \"Export Project Template\",\n annotations: hints.additive,\n description:\n \"Export a project as a template file, to hand it over or reproduce it elsewhere: writes \" +\n \"the `template-v1` YAML the application's Export Project as Template… writes, unchanged, \" +\n \"to `savePath`, a new file (an existing one is never overwritten), so the application's \" +\n \"import reads it. All or nothing: when any block cannot be written, nothing is written \" +\n \"and the error names every such block (id, label, reason). read_file reads the file.\\n\\n\" +\n \"Returns `{ path, bytes, fileHandlesTotal, offset, hasMore, fileHandles }`: a page of the \" +\n \"file handles the params hold, each with `blockId`, `paramsPath`, `handle`, and the file \" +\n \"it names (`localPath`, or `storage` and `storagePath`). Page on without `savePath`. \" +\n \"Handles work only on the desktop that made them; on another, replace each with a handle \" +\n \"of the file there (get_file_handles).\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n savePath: z\n .string()\n .optional()\n .describe(\"Absolute path of the new file to write. Omit to list the file handles only.\"),\n ...pagingArgs(\"file handles\", TEMPLATE_HANDLES_DEFAULT, TEMPLATE_HANDLES_MAX),\n }),\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await exportProjectTemplate(\n {\n resolveProject: (id) => ctx.resolveProject(id),\n exportProjectAsTemplate: (id) => ml.exportProjectAsTemplate(id),\n },\n input,\n );\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,eAAsB,cAAc,MAAyB,WAAsB;CACjF,MAAM,QAAQ,MAAM,KAAK,eAAe,SAAS;CACjD,MAAM,cACJ,YACE,WAAW,UAAU,yFAEvB;CACF,IAAI,KAAK,cAAc,MAAM,EAAE,IAAI,GAAG,OAAO,MAAM;CACnD,IAAI;EACF,MAAM,KAAK,cAAc,MAAM,IAAI,EACjC,iBAAiB,WAAW,WAAW,KAAK,iBAAiB,KAAK,cAAc,MAAM,EAAE,IAAI,EAC9F,CAAC;CACH,SAAS,GAAY;EACnB,IAAI,CAAC,oBAAoB,CAAC,GAAG,MAAM;EACnC,OAAO,MAAM;CACf;CACA,MAAM,KAAK,YAAY,SAAS;CAChC,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;AAChC;AAEA,SAAgB,qBAAqB,QAAuB,KAAwB;CAClF,OAAO,aACL,iBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAGF,aAAa,EAAE,OAAO;GACpB,GAAG,WAAW,YAAA,KAAA,GAAgE;GAC9E,cAAc,EACX,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,kEAAkE;EAChF,CAAC;CACH,GACA,OAAO,EAAE,OAAO,QAAQ,mBAAmB;EACzC,MAAM,KAAK,IAAI,UAAU;EACzB,MAAM,GAAG,YAAY,aAAa;EAClC,MAAM,WAAW,MAAM,GAAG,YAAY,iBAAiB;EACvD,MAAM,SAAS,cAAc,YAAY;EACzC,MAAM,WACJ,WAAW,KAAA,IACP,WACA,SAAS,Q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O,CAAC,CACR,SAAS,CAAC,CACV,SAAS,6EAA6E;GACzF,GAAG,WAAW,gBAAA,IAAA,GAA8D;EAC9E,CAAC;CACH,GACA,OAAO,UAAU;EACf,MAAM,KAAK,IAAI,UAAU;EACzB,OAAO,MAAM,sBACX;GACE,iBAAiB,OAAO,IAAI,eAAe,EAAE;GAC7C,0BAA0B,OAAO,GAAG,wBAAwB,EAAE;EAChE,GACA,KACF;CACF,CACF;AACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const require_types = require("./types.cjs");
|
|
2
|
+
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
3
|
+
// src/tools/readiness.ts
|
|
4
|
+
function blockStatus(b) {
|
|
5
|
+
if (b.calculationStatus === "Running") return "running";
|
|
6
|
+
if (b.calculationStatus === "Limbo") return "limbo";
|
|
7
|
+
if (b.calculationStatus === "Done" && !b.stale) return b.outputErrors ? "failed" : "up-to-date";
|
|
8
|
+
return b.canRun ? "ready" : "blocked";
|
|
9
|
+
}
|
|
10
|
+
/** What a block's results are when its data, or the data of a block above, changed after its run. */
|
|
11
|
+
const STALE_RESULTS_NOTE = "The results are from an earlier configuration: the block's data, or the data of a block above, changed after its last run. run_block runs it again.";
|
|
12
|
+
/**
|
|
13
|
+
* `{ stale: true, note }` for a block whose run is over but whose results no longer follow its
|
|
14
|
+
* data ({@link STALE_RESULTS_NOTE}); nothing for any other block.
|
|
15
|
+
*/
|
|
16
|
+
function staleResults(b) {
|
|
17
|
+
return b.calculationStatus === "Done" && b.stale ? {
|
|
18
|
+
stale: true,
|
|
19
|
+
note: STALE_RESULTS_NOTE
|
|
20
|
+
} : {};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the readiness of `block` from its overview entry, the overview entries of the blocks
|
|
24
|
+
* above, and what its model makes of its current data (`model`, from the middle layer's
|
|
25
|
+
* `getBlockReadiness`; `undefined` while it has none).
|
|
26
|
+
*/
|
|
27
|
+
function buildReadiness(block, blocks, model) {
|
|
28
|
+
const byId = new Map(blocks.map((b) => [b.id, b]));
|
|
29
|
+
const name = (id) => {
|
|
30
|
+
const b = byId.get(id);
|
|
31
|
+
const title = b?.title ?? b?.label;
|
|
32
|
+
return title === void 0 ? id : `"${title}" (${id})`;
|
|
33
|
+
};
|
|
34
|
+
const blockers = [];
|
|
35
|
+
const warnings = [];
|
|
36
|
+
const warn = (message) => {
|
|
37
|
+
if (!warnings.includes(message)) warnings.push(message);
|
|
38
|
+
};
|
|
39
|
+
if (model !== void 0) {
|
|
40
|
+
if (model.args.type === "absent") blockers.push({
|
|
41
|
+
kind: "args",
|
|
42
|
+
message: model.args.error
|
|
43
|
+
});
|
|
44
|
+
else for (const issue of model.args.issues) if (issue.severity === "error") blockers.push({
|
|
45
|
+
kind: "args",
|
|
46
|
+
message: issue.message
|
|
47
|
+
});
|
|
48
|
+
else warn(issue.message);
|
|
49
|
+
for (const ref of model.missingReferences) blockers.push({
|
|
50
|
+
kind: "missing-reference",
|
|
51
|
+
blockId: ref.blockId,
|
|
52
|
+
message: ref.reason === "unknown-block" ? `The data refers to block ${ref.blockId}, which is not in the project.` : `The data refers to block ${name(ref.blockId)}, which is not above this block.`
|
|
53
|
+
});
|
|
54
|
+
} else if (block.missingReference) blockers.push({
|
|
55
|
+
kind: "missing-reference",
|
|
56
|
+
message: "The data refers to a block that is not in the project or not above this block."
|
|
57
|
+
});
|
|
58
|
+
for (const id of block.upstreams) {
|
|
59
|
+
const upstream = byId.get(id);
|
|
60
|
+
if (upstream !== void 0 && blockStatus(upstream) === "blocked") blockers.push({
|
|
61
|
+
kind: "upstream",
|
|
62
|
+
blockId: (0, _milaboratories_pl_model_common.asBlockId)(id),
|
|
63
|
+
message: `Block ${name(id)} above cannot run; get_block_state on it says why.`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const readiness = {
|
|
67
|
+
status: blockStatus(block),
|
|
68
|
+
blockers,
|
|
69
|
+
warnings
|
|
70
|
+
};
|
|
71
|
+
if (model !== void 0) {
|
|
72
|
+
const { prerun } = model;
|
|
73
|
+
readiness.prerun = prerun.type;
|
|
74
|
+
if (prerun.type === "blocked" || prerun.type === "failed") readiness.prerunReason = prerun.error;
|
|
75
|
+
else if (prerun.type === "skipped") readiness.prerunReason = "The block's model gives no pre-run args for this data.";
|
|
76
|
+
if (prerun.type !== "failed") {
|
|
77
|
+
for (const issue of prerun.issues) if (issue.severity !== "error") warn(issue.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return readiness;
|
|
81
|
+
}
|
|
82
|
+
/** The error of a tool given a block id the project does not have. */
|
|
83
|
+
function unknownBlockResult(projectId, blockId, nothingChanged = false) {
|
|
84
|
+
return require_types.errorResult(`Block ${blockId} is not in project ${projectId}.${nothingChanged ? " Nothing was changed." : ""}`, "Use get_project_overview to list the block ids of the project.");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Finds a block in the project overview. A block the project does not have, or a project whose
|
|
88
|
+
* overview is not ready, comes back as the error result to return.
|
|
89
|
+
*/
|
|
90
|
+
async function findBlock(project, projectId, blockId, options = {}) {
|
|
91
|
+
const overview = await project.overview.getValue();
|
|
92
|
+
if (overview === void 0) return { error: require_types.errorResult("Project overview not available yet. Try again.") };
|
|
93
|
+
const block = overview.blocks.find((b) => b.id === blockId);
|
|
94
|
+
if (block === void 0) return { error: unknownBlockResult(projectId, blockId, options.nothingChanged) };
|
|
95
|
+
return { block };
|
|
96
|
+
}
|
|
97
|
+
exports.STALE_RESULTS_NOTE = STALE_RESULTS_NOTE;
|
|
98
|
+
exports.blockStatus = blockStatus;
|
|
99
|
+
exports.buildReadiness = buildReadiness;
|
|
100
|
+
exports.findBlock = findBlock;
|
|
101
|
+
exports.staleResults = staleResults;
|
|
102
|
+
exports.unknownBlockResult = unknownBlockResult;
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=readiness.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readiness.cjs","names":["asBlockId","errorResult"],"sources":["../../src/tools/readiness.ts"],"sourcesContent":["import { asBlockId, type BlockId, type ProjectId } from \"@milaboratories/pl-model-common\";\nimport type { BlockReadiness, BlockStateOverview } from \"@milaboratories/pl-middle-layer\";\nimport { errorResult } from \"./types\";\n\n/**\n * Where a block stands, from the stored fields of its overview entry only (nothing is run):\n * `running`, `limbo` (its results are from before an upstream changed: an upstream failed, was\n * stopped or ran again), `failed` (the last run, of the current configuration, ended with errors\n * in its outputs), `up-to-date` (results match the configuration), `ready` (can run now),\n * `blocked` (cannot run: its inputs or an upstream are not valid, or a reference is missing).\n * A stale block whose outputs failed is `ready` or `blocked`: the failure is of an older\n * configuration.\n */\nexport type BlockStatus = \"running\" | \"limbo\" | \"failed\" | \"up-to-date\" | \"ready\" | \"blocked\";\n\nexport function blockStatus(\n b: Pick<BlockStateOverview, \"calculationStatus\" | \"stale\" | \"canRun\" | \"outputErrors\">,\n): BlockStatus {\n if (b.calculationStatus === \"Running\") return \"running\";\n if (b.calculationStatus === \"Limbo\") return \"limbo\";\n if (b.calculationStatus === \"Done\" && !b.stale) return b.outputErrors ? \"failed\" : \"up-to-date\";\n return b.canRun ? \"ready\" : \"blocked\";\n}\n\n/** What a block's results are when its data, or the data of a block above, changed after its run. */\nexport const STALE_RESULTS_NOTE =\n \"The results are from an earlier configuration: the block's data, or the data of a block \" +\n \"above, changed after its last run. run_block runs it again.\";\n\n/**\n * `{ stale: true, note }` for a block whose run is over but whose results no longer follow its\n * data ({@link STALE_RESULTS_NOTE}); nothing for any other block.\n */\nexport function staleResults(\n b: Pick<BlockStateOverview, \"calculationStatus\" | \"stale\">,\n): { stale: true; note: string } | Record<string, never> {\n return b.calculationStatus === \"Done\" && b.stale ? { stale: true, note: STALE_RESULTS_NOTE } : {};\n}\n\n/** One thing that keeps a block from running. */\nexport type ReadinessBlocker = {\n /**\n * `args`: the block's own model refuses its data (the message is the model's);\n * `missing-reference`: the data refers to a block that is not in the project or not above;\n * `upstream`: a block above cannot run.\n */\n kind: \"args\" | \"missing-reference\" | \"upstream\";\n message: string;\n /** The block a `missing-reference` or `upstream` blocker is about. */\n blockId?: BlockId;\n};\n\n/**\n * Whether a block can run, and why not, as per-block tools return it. The messages come from the\n * block's own model (its `args()`, `argsIssues()`, `prerunArgs()` and `prerunArgsIssues()`) and\n * from stored facts of the project (references, the state of the blocks above); the server adds\n * no judgement of its own about the data.\n */\nexport type Readiness = {\n status: BlockStatus;\n blockers: ReadinessBlocker[];\n /** Warnings the block's model found in its data; they do not keep it from running. */\n warnings: string[];\n /**\n * Whether the block's pre-run (the part of the workflow that runs on every change of the data,\n * before run_block) runs on the current data: `staged`; `skipped` (the model gives no pre-run\n * args), `blocked` (the model found errors) or `failed` (the model threw) mean the pre-run\n * outputs still show an earlier configuration. Absent when the block has no model readiness.\n */\n prerun?: \"staged\" | \"skipped\" | \"blocked\" | \"failed\";\n /** Why the pre-run does not run on the current data, in the model's words where it has them. */\n prerunReason?: string;\n};\n\n/** What {@link buildReadiness} reads of a block of the project overview. */\nexport type ReadinessOverviewBlock = Pick<\n BlockStateOverview,\n | \"id\"\n | \"calculationStatus\"\n | \"stale\"\n | \"canRun\"\n | \"outputErrors\"\n | \"missingReference\"\n | \"upstreams\"\n> & { title?: string; label?: string };\n\n/**\n * Builds the readiness of `block` from its overview entry, the overview entries of the blocks\n * above, and what its model makes of its current data (`model`, from the middle layer's\n * `getBlockReadiness`; `undefined` while it has none).\n */\nexport function buildReadiness(\n block: ReadinessOverviewBlock,\n blocks: readonly ReadinessOverviewBlock[],\n model: BlockReadiness | undefined,\n): Readiness {\n const byId = new Map(blocks.map((b) => [b.id, b]));\n const name = (id: string) => {\n const b = byId.get(id);\n const title = b?.title ?? b?.label;\n return title === undefined ? id : `\"${title}\" (${id})`;\n };\n\n const blockers: ReadinessBlocker[] = [];\n const warnings: string[] = [];\n const warn = (message: string) => {\n if (!warnings.includes(message)) warnings.push(message);\n };\n\n if (model !== undefined) {\n if (model.args.type === \"absent\") blockers.push({ kind: \"args\", message: model.args.error });\n else\n for (const issue of model.args.issues)\n if (issue.severity === \"error\") blockers.push({ kind: \"args\", message: issue.message });\n else warn(issue.message);\n\n for (const ref of model.missingReferences)\n blockers.push({\n kind: \"missing-reference\",\n blockId: ref.blockId,\n message:\n ref.reason === \"unknown-block\"\n ? `The data refers to block ${ref.blockId}, which is not in the project.`\n : `The data refers to block ${name(ref.blockId)}, which is not above this block.`,\n });\n } else if (block.missingReference) {\n blockers.push({\n kind: \"missing-reference\",\n message: \"The data refers to a block that is not in the project or not above this block.\",\n });\n }\n\n for (const id of block.upstreams) {\n const upstream = byId.get(id);\n if (upstream !== undefined && blockStatus(upstream) === \"blocked\")\n blockers.push({\n kind: \"upstream\",\n blockId: asBlockId(id),\n message: `Block ${name(id)} above cannot run; get_block_state on it says why.`,\n });\n }\n\n const readiness: Readiness = { status: blockStatus(block), blockers, warnings };\n if (model !== undefined) {\n const { prerun } = model;\n readiness.prerun = prerun.type;\n if (prerun.type === \"blocked\" || prerun.type === \"failed\")\n readiness.prerunReason = prerun.error;\n else if (prerun.type === \"skipped\")\n readiness.prerunReason = \"The block's model gives no pre-run args for this data.\";\n if (prerun.type !== \"failed\")\n for (const issue of prerun.issues) if (issue.severity !== \"error\") warn(issue.message);\n }\n return readiness;\n}\n\n/** The error of a tool given a block id the project does not have. */\nexport function unknownBlockResult(projectId: ProjectId, blockId: BlockId, nothingChanged = false) {\n return errorResult(\n `Block ${blockId} is not in project ${projectId}.${nothingChanged ? \" Nothing was changed.\" : \"\"}`,\n \"Use get_project_overview to list the block ids of the project.\",\n );\n}\n\n/** What {@link findBlock} needs of a project. */\nexport type BlockLookupProject<B extends { id: string }> = {\n overview: { getValue(): Promise<{ blocks: B[] } | undefined> };\n};\n\n/**\n * Finds a block in the project overview. A block the project does not have, or a project whose\n * overview is not ready, comes back as the error result to return.\n */\nexport async function findBlock<B extends { id: string }>(\n project: BlockLookupProject<B>,\n projectId: ProjectId,\n blockId: BlockId,\n options: { nothingChanged?: boolean } = {},\n): Promise<{ block: B; error?: undefined } | { block?: undefined; error: ToolErrorResult }> {\n const overview = await project.overview.getValue();\n if (overview === undefined)\n return { error: errorResult(\"Project overview not available yet. Try again.\") };\n const block = overview.blocks.find((b) => b.id === blockId);\n if (block === undefined)\n return { error: unknownBlockResult(projectId, blockId, options.nothingChanged) };\n return { block };\n}\n\ntype ToolErrorResult = ReturnType<typeof errorResult>;\n"],"mappings":";;;AAeA,SAAgB,YACd,GACa;CACb,IAAI,EAAE,sBAAsB,WAAW,OAAO;CAC9C,IAAI,EAAE,sBAAsB,SAAS,OAAO;CAC5C,IAAI,EAAE,sBAAsB,UAAU,CAAC,EAAE,OAAO,OAAO,EAAE,eAAe,WAAW;CACnF,OAAO,EAAE,SAAS,UAAU;AAC9B;;AAGA,MAAa,qBACX;;;;;AAOF,SAAgB,aACd,GACuD;CACvD,OAAO,EAAE,sBAAsB,UAAU,EAAE,QAAQ;EAAE,OAAO;EAAM,MAAM;CAAmB,IAAI,CAAC;AAClG;;;;;;AAsDA,SAAgB,eACd,OACA,QACA,OACW;CACX,MAAM,OAAO,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CACjD,MAAM,QAAQ,OAAe;EAC3B,MAAM,IAAI,KAAK,IAAI,EAAE;EACrB,MAAM,QAAQ,GAAG,SAAS,GAAG;EAC7B,OAAO,UAAU,KAAA,IAAY,KAAK,IAAI,MAAM,KAAK,GAAG;CACtD;CAEA,MAAM,WAA+B,CAAC;CACtC,MAAM,WAAqB,CAAC;CAC5B,MAAM,QAAQ,YAAoB;EAChC,IAAI,CAAC,SAAS,SAAS,OAAO,GAAG,SAAS,KAAK,OAAO;CACxD;CAEA,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,MAAM,KAAK,SAAS,UAAU,SAAS,KAAK;GAAE,MAAM;GAAQ,SAAS,MAAM,KAAK;EAAM,CAAC;OAEzF,KAAK,MAAM,SAAS,MAAM,KAAK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,QAAQ,SAAS,SAAS;CACjD,IAAI,aAAa,KAAA,GACf,OAAO,EAAE,OAAOA,cAAAA,YAAY,gDAAgD,EAAE;CAChF,MAAM,QAAQ,SAAS,OAAO,MAAM,MAAM,EAAE,OAAO,OAAO;CAC1D,IAAI,UAAU,KAAA,GACZ,OAAO,EAAE,OAAO,mBAAmB,WAAW,SAAS,QAAQ,cAAc,EAAE;CACjF,OAAO,EAAE,MAAM;AACjB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { errorResult } from "./types.js";
|
|
2
|
+
import { asBlockId } from "@milaboratories/pl-model-common";
|
|
3
|
+
// src/tools/readiness.ts
|
|
4
|
+
function blockStatus(b) {
|
|
5
|
+
if (b.calculationStatus === "Running") return "running";
|
|
6
|
+
if (b.calculationStatus === "Limbo") return "limbo";
|
|
7
|
+
if (b.calculationStatus === "Done" && !b.stale) return b.outputErrors ? "failed" : "up-to-date";
|
|
8
|
+
return b.canRun ? "ready" : "blocked";
|
|
9
|
+
}
|
|
10
|
+
/** What a block's results are when its data, or the data of a block above, changed after its run. */
|
|
11
|
+
const STALE_RESULTS_NOTE = "The results are from an earlier configuration: the block's data, or the data of a block above, changed after its last run. run_block runs it again.";
|
|
12
|
+
/**
|
|
13
|
+
* `{ stale: true, note }` for a block whose run is over but whose results no longer follow its
|
|
14
|
+
* data ({@link STALE_RESULTS_NOTE}); nothing for any other block.
|
|
15
|
+
*/
|
|
16
|
+
function staleResults(b) {
|
|
17
|
+
return b.calculationStatus === "Done" && b.stale ? {
|
|
18
|
+
stale: true,
|
|
19
|
+
note: STALE_RESULTS_NOTE
|
|
20
|
+
} : {};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the readiness of `block` from its overview entry, the overview entries of the blocks
|
|
24
|
+
* above, and what its model makes of its current data (`model`, from the middle layer's
|
|
25
|
+
* `getBlockReadiness`; `undefined` while it has none).
|
|
26
|
+
*/
|
|
27
|
+
function buildReadiness(block, blocks, model) {
|
|
28
|
+
const byId = new Map(blocks.map((b) => [b.id, b]));
|
|
29
|
+
const name = (id) => {
|
|
30
|
+
const b = byId.get(id);
|
|
31
|
+
const title = b?.title ?? b?.label;
|
|
32
|
+
return title === void 0 ? id : `"${title}" (${id})`;
|
|
33
|
+
};
|
|
34
|
+
const blockers = [];
|
|
35
|
+
const warnings = [];
|
|
36
|
+
const warn = (message) => {
|
|
37
|
+
if (!warnings.includes(message)) warnings.push(message);
|
|
38
|
+
};
|
|
39
|
+
if (model !== void 0) {
|
|
40
|
+
if (model.args.type === "absent") blockers.push({
|
|
41
|
+
kind: "args",
|
|
42
|
+
message: model.args.error
|
|
43
|
+
});
|
|
44
|
+
else for (const issue of model.args.issues) if (issue.severity === "error") blockers.push({
|
|
45
|
+
kind: "args",
|
|
46
|
+
message: issue.message
|
|
47
|
+
});
|
|
48
|
+
else warn(issue.message);
|
|
49
|
+
for (const ref of model.missingReferences) blockers.push({
|
|
50
|
+
kind: "missing-reference",
|
|
51
|
+
blockId: ref.blockId,
|
|
52
|
+
message: ref.reason === "unknown-block" ? `The data refers to block ${ref.blockId}, which is not in the project.` : `The data refers to block ${name(ref.blockId)}, which is not above this block.`
|
|
53
|
+
});
|
|
54
|
+
} else if (block.missingReference) blockers.push({
|
|
55
|
+
kind: "missing-reference",
|
|
56
|
+
message: "The data refers to a block that is not in the project or not above this block."
|
|
57
|
+
});
|
|
58
|
+
for (const id of block.upstreams) {
|
|
59
|
+
const upstream = byId.get(id);
|
|
60
|
+
if (upstream !== void 0 && blockStatus(upstream) === "blocked") blockers.push({
|
|
61
|
+
kind: "upstream",
|
|
62
|
+
blockId: asBlockId(id),
|
|
63
|
+
message: `Block ${name(id)} above cannot run; get_block_state on it says why.`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const readiness = {
|
|
67
|
+
status: blockStatus(block),
|
|
68
|
+
blockers,
|
|
69
|
+
warnings
|
|
70
|
+
};
|
|
71
|
+
if (model !== void 0) {
|
|
72
|
+
const { prerun } = model;
|
|
73
|
+
readiness.prerun = prerun.type;
|
|
74
|
+
if (prerun.type === "blocked" || prerun.type === "failed") readiness.prerunReason = prerun.error;
|
|
75
|
+
else if (prerun.type === "skipped") readiness.prerunReason = "The block's model gives no pre-run args for this data.";
|
|
76
|
+
if (prerun.type !== "failed") {
|
|
77
|
+
for (const issue of prerun.issues) if (issue.severity !== "error") warn(issue.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return readiness;
|
|
81
|
+
}
|
|
82
|
+
/** The error of a tool given a block id the project does not have. */
|
|
83
|
+
function unknownBlockResult(projectId, blockId, nothingChanged = false) {
|
|
84
|
+
return errorResult(`Block ${blockId} is not in project ${projectId}.${nothingChanged ? " Nothing was changed." : ""}`, "Use get_project_overview to list the block ids of the project.");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Finds a block in the project overview. A block the project does not have, or a project whose
|
|
88
|
+
* overview is not ready, comes back as the error result to return.
|
|
89
|
+
*/
|
|
90
|
+
async function findBlock(project, projectId, blockId, options = {}) {
|
|
91
|
+
const overview = await project.overview.getValue();
|
|
92
|
+
if (overview === void 0) return { error: errorResult("Project overview not available yet. Try again.") };
|
|
93
|
+
const block = overview.blocks.find((b) => b.id === blockId);
|
|
94
|
+
if (block === void 0) return { error: unknownBlockResult(projectId, blockId, options.nothingChanged) };
|
|
95
|
+
return { block };
|
|
96
|
+
}
|
|
97
|
+
export { STALE_RESULTS_NOTE, blockStatus, buildReadiness, findBlock, staleResults, unknownBlockResult };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=readiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readiness.js","names":[],"sources":["../../src/tools/readiness.ts"],"sourcesContent":["import { asBlockId, type BlockId, type ProjectId } from \"@milaboratories/pl-model-common\";\nimport type { BlockReadiness, BlockStateOverview } from \"@milaboratories/pl-middle-layer\";\nimport { errorResult } from \"./types\";\n\n/**\n * Where a block stands, from the stored fields of its overview entry only (nothing is run):\n * `running`, `limbo` (its results are from before an upstream changed: an upstream failed, was\n * stopped or ran again), `failed` (the last run, of the current configuration, ended with errors\n * in its outputs), `up-to-date` (results match the configuration), `ready` (can run now),\n * `blocked` (cannot run: its inputs or an upstream are not valid, or a reference is missing).\n * A stale block whose outputs failed is `ready` or `blocked`: the failure is of an older\n * configuration.\n */\nexport type BlockStatus = \"running\" | \"limbo\" | \"failed\" | \"up-to-date\" | \"ready\" | \"blocked\";\n\nexport function blockStatus(\n b: Pick<BlockStateOverview, \"calculationStatus\" | \"stale\" | \"canRun\" | \"outputErrors\">,\n): BlockStatus {\n if (b.calculationStatus === \"Running\") return \"running\";\n if (b.calculationStatus === \"Limbo\") return \"limbo\";\n if (b.calculationStatus === \"Done\" && !b.stale) return b.outputErrors ? \"failed\" : \"up-to-date\";\n return b.canRun ? \"ready\" : \"blocked\";\n}\n\n/** What a block's results are when its data, or the data of a block above, changed after its run. */\nexport const STALE_RESULTS_NOTE =\n \"The results are from an earlier configuration: the block's data, or the data of a block \" +\n \"above, changed after its last run. run_block runs it again.\";\n\n/**\n * `{ stale: true, note }` for a block whose run is over but whose results no longer follow its\n * data ({@link STALE_RESULTS_NOTE}); nothing for any other block.\n */\nexport function staleResults(\n b: Pick<BlockStateOverview, \"calculationStatus\" | \"stale\">,\n): { stale: true; note: string } | Record<string, never> {\n return b.calculationStatus === \"Done\" && b.stale ? { stale: true, note: STALE_RESULTS_NOTE } : {};\n}\n\n/** One thing that keeps a block from running. */\nexport type ReadinessBlocker = {\n /**\n * `args`: the block's own model refuses its data (the message is the model's);\n * `missing-reference`: the data refers to a block that is not in the project or not above;\n * `upstream`: a block above cannot run.\n */\n kind: \"args\" | \"missing-reference\" | \"upstream\";\n message: string;\n /** The block a `missing-reference` or `upstream` blocker is about. */\n blockId?: BlockId;\n};\n\n/**\n * Whether a block can run, and why not, as per-block tools return it. The messages come from the\n * block's own model (its `args()`, `argsIssues()`, `prerunArgs()` and `prerunArgsIssues()`) and\n * from stored facts of the project (references, the state of the blocks above); the server adds\n * no judgement of its own about the data.\n */\nexport type Readiness = {\n status: BlockStatus;\n blockers: ReadinessBlocker[];\n /** Warnings the block's model found in its data; they do not keep it from running. */\n warnings: string[];\n /**\n * Whether the block's pre-run (the part of the workflow that runs on every change of the data,\n * before run_block) runs on the current data: `staged`; `skipped` (the model gives no pre-run\n * args), `blocked` (the model found errors) or `failed` (the model threw) mean the pre-run\n * outputs still show an earlier configuration. Absent when the block has no model readiness.\n */\n prerun?: \"staged\" | \"skipped\" | \"blocked\" | \"failed\";\n /** Why the pre-run does not run on the current data, in the model's words where it has them. */\n prerunReason?: string;\n};\n\n/** What {@link buildReadiness} reads of a block of the project overview. */\nexport type ReadinessOverviewBlock = Pick<\n BlockStateOverview,\n | \"id\"\n | \"calculationStatus\"\n | \"stale\"\n | \"canRun\"\n | \"outputErrors\"\n | \"missingReference\"\n | \"upstreams\"\n> & { title?: string; label?: string };\n\n/**\n * Builds the readiness of `block` from its overview entry, the overview entries of the blocks\n * above, and what its model makes of its current data (`model`, from the middle layer's\n * `getBlockReadiness`; `undefined` while it has none).\n */\nexport function buildReadiness(\n block: ReadinessOverviewBlock,\n blocks: readonly ReadinessOverviewBlock[],\n model: BlockReadiness | undefined,\n): Readiness {\n const byId = new Map(blocks.map((b) => [b.id, b]));\n const name = (id: string) => {\n const b = byId.get(id);\n const title = b?.title ?? b?.label;\n return title === undefined ? id : `\"${title}\" (${id})`;\n };\n\n const blockers: ReadinessBlocker[] = [];\n const warnings: string[] = [];\n const warn = (message: string) => {\n if (!warnings.includes(message)) warnings.push(message);\n };\n\n if (model !== undefined) {\n if (model.args.type === \"absent\") blockers.push({ kind: \"args\", message: model.args.error });\n else\n for (const issue of model.args.issues)\n if (issue.severity === \"error\") blockers.push({ kind: \"args\", message: issue.message });\n else warn(issue.message);\n\n for (const ref of model.missingReferences)\n blockers.push({\n kind: \"missing-reference\",\n blockId: ref.blockId,\n message:\n ref.reason === \"unknown-block\"\n ? `The data refers to block ${ref.blockId}, which is not in the project.`\n : `The data refers to block ${name(ref.blockId)}, which is not above this block.`,\n });\n } else if (block.missingReference) {\n blockers.push({\n kind: \"missing-reference\",\n message: \"The data refers to a block that is not in the project or not above this block.\",\n });\n }\n\n for (const id of block.upstreams) {\n const upstream = byId.get(id);\n if (upstream !== undefined && blockStatus(upstream) === \"blocked\")\n blockers.push({\n kind: \"upstream\",\n blockId: asBlockId(id),\n message: `Block ${name(id)} above cannot run; get_block_state on it says why.`,\n });\n }\n\n const readiness: Readiness = { status: blockStatus(block), blockers, warnings };\n if (model !== undefined) {\n const { prerun } = model;\n readiness.prerun = prerun.type;\n if (prerun.type === \"blocked\" || prerun.type === \"failed\")\n readiness.prerunReason = prerun.error;\n else if (prerun.type === \"skipped\")\n readiness.prerunReason = \"The block's model gives no pre-run args for this data.\";\n if (prerun.type !== \"failed\")\n for (const issue of prerun.issues) if (issue.severity !== \"error\") warn(issue.message);\n }\n return readiness;\n}\n\n/** The error of a tool given a block id the project does not have. */\nexport function unknownBlockResult(projectId: ProjectId, blockId: BlockId, nothingChanged = false) {\n return errorResult(\n `Block ${blockId} is not in project ${projectId}.${nothingChanged ? \" Nothing was changed.\" : \"\"}`,\n \"Use get_project_overview to list the block ids of the project.\",\n );\n}\n\n/** What {@link findBlock} needs of a project. */\nexport type BlockLookupProject<B extends { id: string }> = {\n overview: { getValue(): Promise<{ blocks: B[] } | undefined> };\n};\n\n/**\n * Finds a block in the project overview. A block the project does not have, or a project whose\n * overview is not ready, comes back as the error result to return.\n */\nexport async function findBlock<B extends { id: string }>(\n project: BlockLookupProject<B>,\n projectId: ProjectId,\n blockId: BlockId,\n options: { nothingChanged?: boolean } = {},\n): Promise<{ block: B; error?: undefined } | { block?: undefined; error: ToolErrorResult }> {\n const overview = await project.overview.getValue();\n if (overview === undefined)\n return { error: errorResult(\"Project overview not available yet. Try again.\") };\n const block = overview.blocks.find((b) => b.id === blockId);\n if (block === undefined)\n return { error: unknownBlockResult(projectId, blockId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