@milaboratories/pl-mcp-server 54.0.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 +15 -25
- 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 +15 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +15 -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 +58 -8
- package/dist/project-holds.cjs.map +1 -1
- package/dist/project-holds.js +58 -8
- package/dist/project-holds.js.map +1 -1
- 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 +40 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +40 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +48 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +21 -20
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +48 -18
- 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 -73
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -75
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +3 -0
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +3 -0
- 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 +272 -4
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +270 -6
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +323 -42
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +317 -46
- 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 +183 -70
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +177 -70
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +451 -113
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +446 -118
- 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 +56 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +51 -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 +98 -19
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +95 -20
- 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 +66 -19
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +66 -20
- 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 +15 -12
- package/src/project-holds.test.ts +179 -0
- package/src/project-holds.ts +114 -12
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +54 -1
- package/src/server-log.ts +49 -27
- package/src/server.logging.test.ts +38 -46
- package/src/server.test.ts +151 -17
- package/src/server.ts +62 -34
- 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 -123
- package/src/tools/block-action-context.ts +3 -0
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +623 -8
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +659 -66
- 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 +336 -105
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +807 -157
- 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 +67 -0
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +130 -21
- 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 +135 -25
- 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 +77 -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/blocks.cjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
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_settle = require("./settle.cjs");
|
|
5
|
+
const require_readiness = require("./readiness.cjs");
|
|
6
|
+
const require_errors = require("./errors.cjs");
|
|
3
7
|
const require_block_api = require("./block-api.cjs");
|
|
8
|
+
const require_block_state = require("./block-state.cjs");
|
|
4
9
|
let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
|
|
5
10
|
let zod = require("zod");
|
|
6
|
-
let
|
|
7
|
-
// src/tools/blocks.ts
|
|
11
|
+
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
8
12
|
/** Where a kind is resolved when the caller names no registry. */
|
|
9
13
|
function centralBlockRegistryUrl() {
|
|
10
14
|
if (_milaboratories_pl_middle_layer.CentralBlockRegistry.type !== "remote-v2") throw new Error("The central block registry is expected to be a v2 remote registry.");
|
|
@@ -13,45 +17,50 @@ function centralBlockRegistryUrl() {
|
|
|
13
17
|
function errorMessage(e) {
|
|
14
18
|
return e instanceof Error ? e.message : String(e);
|
|
15
19
|
}
|
|
20
|
+
/** The ways a tool input names a block: by kind, as an exact registry block, or a dev folder. */
|
|
21
|
+
const blockSpecInput = zod.z.union([
|
|
22
|
+
zod.z.object({
|
|
23
|
+
type: zod.z.literal("kind"),
|
|
24
|
+
kind: zod.z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
|
|
25
|
+
registryUrl: zod.z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
|
|
26
|
+
allowUnstable: zod.z.boolean().optional().describe("Also consider blocks not published to the stable channel")
|
|
27
|
+
}),
|
|
28
|
+
zod.z.object({
|
|
29
|
+
type: zod.z.literal("from-registry-v2"),
|
|
30
|
+
registryUrl: zod.z.string().describe("Registry URL"),
|
|
31
|
+
id: zod.z.object({
|
|
32
|
+
organization: zod.z.string(),
|
|
33
|
+
name: zod.z.string(),
|
|
34
|
+
version: zod.z.string()
|
|
35
|
+
})
|
|
36
|
+
}),
|
|
37
|
+
zod.z.object({
|
|
38
|
+
type: zod.z.literal("dev-v2"),
|
|
39
|
+
folder: zod.z.string().describe("Path to block folder")
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
16
42
|
const addBlockInput = zod.z.object({
|
|
17
43
|
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
18
44
|
label: zod.z.string().describe("Block label"),
|
|
19
|
-
spec:
|
|
20
|
-
zod.z.object({
|
|
21
|
-
type: zod.z.literal("kind"),
|
|
22
|
-
kind: zod.z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
|
|
23
|
-
registryUrl: zod.z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
|
|
24
|
-
allowUnstable: zod.z.boolean().optional().describe("Also consider blocks not published to the stable channel")
|
|
25
|
-
}),
|
|
26
|
-
zod.z.object({
|
|
27
|
-
type: zod.z.literal("from-registry-v2"),
|
|
28
|
-
registryUrl: zod.z.string().describe("Registry URL"),
|
|
29
|
-
id: zod.z.object({
|
|
30
|
-
organization: zod.z.string(),
|
|
31
|
-
name: zod.z.string(),
|
|
32
|
-
version: zod.z.string()
|
|
33
|
-
})
|
|
34
|
-
}),
|
|
35
|
-
zod.z.object({
|
|
36
|
-
type: zod.z.literal("dev-v2"),
|
|
37
|
-
folder: zod.z.string().describe("Path to block folder")
|
|
38
|
-
})
|
|
39
|
-
]).describe("Which block to add"),
|
|
45
|
+
spec: blockSpecInput.describe("Which block to add"),
|
|
40
46
|
params: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initialization params of the block's kind. Omit for the default state."),
|
|
41
47
|
blockIds: zod.z.record(zod.z.string(), require_ids.blockIdInput).optional().describe("Ids used inside `params` in place of block ids, each mapped to a block id of this project. Needed only when `params` do not already hold ids of this project."),
|
|
42
|
-
before: require_ids.blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)")
|
|
48
|
+
before: require_ids.blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)"),
|
|
49
|
+
wait: zod.z.boolean().optional().describe("Wait for the new block's outputs to settle before answering (default false)."),
|
|
50
|
+
timeout: zod.z.number().optional().describe(`The longest wait in ms with \`wait\` (default ${require_block_state.WRITE_WAIT_DEFAULT_MS}, at most ${require_block_state.WRITE_WAIT_MAX_MS}).`)
|
|
43
51
|
});
|
|
44
52
|
/**
|
|
45
53
|
* Adds the block the input describes, started from its params when it carries them. Every way the
|
|
46
54
|
* block can be refused comes back as an error result saying nothing was created.
|
|
47
55
|
*/
|
|
48
|
-
async function
|
|
56
|
+
async function addNewBlock(deps, input) {
|
|
49
57
|
const { label, spec, params, blockIds, before } = input;
|
|
58
|
+
const refuse = (message, hint) => ({ result: require_types.errorResult(message, hint) });
|
|
50
59
|
let blockPackSpec;
|
|
51
60
|
if (spec.type === "kind") try {
|
|
52
61
|
blockPackSpec = await deps.resolveKind(_milaboratories_pl_middle_layer.BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
|
|
53
62
|
} catch (e) {
|
|
54
|
-
return
|
|
63
|
+
return refuse(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`, "Check the kind name and version. Pass allowUnstable: true if the block is not published to the stable channel, or registryUrl if it lives in another registry.");
|
|
55
64
|
}
|
|
56
65
|
else blockPackSpec = spec;
|
|
57
66
|
try {
|
|
@@ -62,54 +71,135 @@ async function addBlock(deps, input) {
|
|
|
62
71
|
},
|
|
63
72
|
requireModelAPIVersion: require_block_api.SUPPORTED_BLOCK_API
|
|
64
73
|
});
|
|
65
|
-
return
|
|
74
|
+
return { blockId: (0, _milaboratories_pl_model_common.asBlockId)(blockId) };
|
|
75
|
+
} catch (e) {
|
|
76
|
+
const unsupported = require_block_api.unsupportedBlockApiResult(e);
|
|
77
|
+
if (unsupported) return { result: unsupported };
|
|
78
|
+
if (require_errors.isBlockInitParamsRejectedError(e)) return refuse(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_contract on the kind shows the params it accepts.");
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Runs a block, unless it cannot run: the readiness is computed first, and a block with blockers
|
|
84
|
+
* is refused with them, nothing started. The result names the blocks started, or says there was
|
|
85
|
+
* nothing to run (the block and the blocks above it are up to date).
|
|
86
|
+
*/
|
|
87
|
+
async function runBlockResult(project, projectId, blockId) {
|
|
88
|
+
const { block, error } = await require_readiness.findBlock(project, projectId, blockId, { nothingChanged: true });
|
|
89
|
+
if (error) return error;
|
|
90
|
+
const readiness = await require_block_state.readinessOf(project, blockId);
|
|
91
|
+
if (readiness !== void 0 && readiness.blockers.length > 0) return require_types.errorResult(`Block ${blockId} cannot run; nothing was started. ` + readiness.blockers.map((b) => `[${b.kind}${b.blockId !== void 0 ? ` ${b.blockId}` : ""}] ${b.message}`).join(" "), "Fix what the blockers name: set_block_params changes the block's params, set_block_data its data; get_block_state shows its readiness. A blocker of a block above is fixed on that block.");
|
|
92
|
+
const started = await project.runBlock(blockId);
|
|
93
|
+
if (Array.isArray(started) ? started.length === 0 : require_readiness.blockStatus(block) === "up-to-date") return require_types.textResult({
|
|
94
|
+
ok: true,
|
|
95
|
+
nothingToRun: true,
|
|
96
|
+
note: "The block and the blocks above it are up to date: nothing was started. Its results follow its current data; get_block_outputs reads them."
|
|
97
|
+
});
|
|
98
|
+
return require_types.textResult(Array.isArray(started) ? {
|
|
99
|
+
ok: true,
|
|
100
|
+
started
|
|
101
|
+
} : {
|
|
102
|
+
ok: true,
|
|
103
|
+
started: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** The block packs `update_block` and `update_blocks` move a block to: a registry block or a dev folder. */
|
|
107
|
+
const updateBlockSpecInput = zod.z.union([zod.z.object({
|
|
108
|
+
type: zod.z.literal("from-registry-v2"),
|
|
109
|
+
registryUrl: zod.z.string().describe("Registry URL"),
|
|
110
|
+
id: zod.z.object({
|
|
111
|
+
organization: zod.z.string(),
|
|
112
|
+
name: zod.z.string(),
|
|
113
|
+
version: zod.z.string()
|
|
114
|
+
}),
|
|
115
|
+
channel: zod.z.string().optional().describe("The registry channel the block follows for its updates; keep the one of the spec list_block_updates gives.")
|
|
116
|
+
}), zod.z.object({
|
|
117
|
+
type: zod.z.literal("dev-v2"),
|
|
118
|
+
folder: zod.z.string().describe("Path to block folder")
|
|
119
|
+
})]);
|
|
120
|
+
/**
|
|
121
|
+
* The one way this server moves a block to another block pack (`update_block`, `update_blocks`):
|
|
122
|
+
* in the block's turn among this server's changes of it ({@link oneAtATime}), asking the middle layer for a pack on the
|
|
123
|
+
* current block API. Answers the error result of the shared block API guard when the pack is
|
|
124
|
+
* refused for its block API (nothing is changed), `undefined` when the block was moved; any other
|
|
125
|
+
* failure is thrown.
|
|
126
|
+
*
|
|
127
|
+
* `beforeWrite` runs when the block's turn starts, right before the write: what it throws is
|
|
128
|
+
* thrown here and nothing is changed. A caller that waited for its turn checks there whether it
|
|
129
|
+
* still wants the write.
|
|
130
|
+
*/
|
|
131
|
+
async function applyBlockPack(project, blockId, spec, options) {
|
|
132
|
+
try {
|
|
133
|
+
await require_block_state.oneAtATime(project, blockId, async () => {
|
|
134
|
+
options.beforeWrite?.();
|
|
135
|
+
await project.updateBlockPack(blockId, spec, options.resetArgs, options.author, { requireModelAPIVersion: require_block_api.SUPPORTED_BLOCK_API });
|
|
136
|
+
});
|
|
66
137
|
} catch (e) {
|
|
67
138
|
const unsupported = require_block_api.unsupportedBlockApiResult(e);
|
|
68
139
|
if (unsupported) return unsupported;
|
|
69
|
-
if (e instanceof _milaboratories_pl_errors.BlockInitParamsRejectedError) return require_types.errorResult(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_params on a configured block of the same kind shows the expected shape.");
|
|
70
140
|
throw e;
|
|
71
141
|
}
|
|
72
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Moves a block to another block pack. Nothing is changed when the block is not in the project or
|
|
145
|
+
* the pack is refused (the shared block API guard included).
|
|
146
|
+
*/
|
|
147
|
+
async function updateBlockResult(project, input, author) {
|
|
148
|
+
const { projectId, blockId } = input;
|
|
149
|
+
const { error } = await require_readiness.findBlock(project, projectId, blockId, { nothingChanged: true });
|
|
150
|
+
if (error) return error;
|
|
151
|
+
return await applyBlockPack(project, blockId, input.spec, {
|
|
152
|
+
resetArgs: input.resetArgs ?? false,
|
|
153
|
+
author
|
|
154
|
+
}) ?? require_types.textResult({ ok: true });
|
|
155
|
+
}
|
|
73
156
|
function registerBlockTools(server, ctx) {
|
|
74
157
|
server.registerTool("add_block", {
|
|
75
158
|
title: "Add Block",
|
|
76
159
|
annotations: require_types.hints.additive,
|
|
77
|
-
description: "Add a block to a project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state.
|
|
160
|
+
description: "Add a block to a project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_contract shows the params a kind accepts, get_block_params the params of an existing block. Without params, configure the block afterwards: read its options outputs (get_block_outputs; references to results of blocks above come from there), then write them into its params with set_block_params, or into its data with set_block_data for what params do not cover. Params and data can name the same thing differently: read the data with get_block_state before writing it. A block offers results of blocks above only once they exist, and some blocks publish results only from their run: if an option is missing and the block above has not run, run it first (run_block, await_block_done).\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.\n\nResult: `{ blockId, readiness, settled, waitedMs, outputs, ... }`; `readiness` as get_block_state gives it: whether the block can run and, if not, the block's own messages on why. With `wait: true` the call waits for the outputs to settle; the first settle of a new block can take one refresh cycle (about 2 s). A wait that runs out is not an error: the block was added, and `settled: false` says what is still pending.",
|
|
78
161
|
inputSchema: addBlockInput
|
|
79
|
-
}, async (input) => {
|
|
162
|
+
}, async ({ wait, timeout, ...input }, call) => {
|
|
80
163
|
const ml = ctx.requireMl();
|
|
81
|
-
return await ctx.withProject(input.projectId, async (project) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
164
|
+
return await ctx.withProject(input.projectId, async (project) => {
|
|
165
|
+
if (input.before !== void 0) {
|
|
166
|
+
const { error } = await require_readiness.findBlock(project, input.projectId, input.before, { nothingChanged: true });
|
|
167
|
+
if (error) return error;
|
|
168
|
+
}
|
|
169
|
+
const added = await addNewBlock({
|
|
170
|
+
project,
|
|
171
|
+
resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
|
|
172
|
+
author: ctx.getAuthorMarker()
|
|
173
|
+
}, input);
|
|
174
|
+
if ("result" in added) return added.result;
|
|
175
|
+
return require_types.textResult({
|
|
176
|
+
blockId: added.blockId,
|
|
177
|
+
...await require_block_state.settleAfterChange(project, added.blockId, {
|
|
178
|
+
wait: wait ?? false,
|
|
179
|
+
timeoutMs: require_settle.clampWait(timeout, require_block_state.WRITE_WAIT_DEFAULT_MS, require_block_state.WRITE_WAIT_MIN_MS, require_block_state.WRITE_WAIT_MAX_MS),
|
|
180
|
+
call,
|
|
181
|
+
notePrerun: false
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
});
|
|
86
185
|
});
|
|
87
186
|
server.registerTool("update_block", {
|
|
88
187
|
title: "Update Block",
|
|
89
188
|
annotations: require_types.hints.destructive,
|
|
90
|
-
description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
|
|
189
|
+
description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it. Only block packs on the current block API are taken; on any error nothing is changed. To upgrade the blocks of a project to newer versions, use list_block_updates and update_blocks.",
|
|
91
190
|
inputSchema: zod.z.object({
|
|
92
191
|
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
93
192
|
blockId: require_ids.blockIdInput.describe("Block ID to update"),
|
|
94
|
-
spec:
|
|
95
|
-
|
|
96
|
-
registryUrl: zod.z.string().describe("Registry URL"),
|
|
97
|
-
id: zod.z.object({
|
|
98
|
-
organization: zod.z.string(),
|
|
99
|
-
name: zod.z.string(),
|
|
100
|
-
version: zod.z.string()
|
|
101
|
-
})
|
|
102
|
-
}), zod.z.object({
|
|
103
|
-
type: zod.z.literal("dev-v2"),
|
|
104
|
-
folder: zod.z.string().describe("Path to block folder")
|
|
105
|
-
})]).describe("Block pack specification"),
|
|
106
|
-
resetArgs: zod.z.boolean().optional().describe("Reset block arguments to initial values (default: false)")
|
|
193
|
+
spec: updateBlockSpecInput.describe("Block pack specification"),
|
|
194
|
+
resetArgs: zod.z.boolean().optional().describe("Start the block over from its initial state: its data and the data of its plugins are discarded (default: false, the data is kept and migrated).")
|
|
107
195
|
})
|
|
108
196
|
}, async ({ projectId, blockId, spec, resetArgs }) => {
|
|
109
|
-
return await ctx.withProject(projectId,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
197
|
+
return await ctx.withProject(projectId, (project) => updateBlockResult(project, {
|
|
198
|
+
projectId,
|
|
199
|
+
blockId,
|
|
200
|
+
spec,
|
|
201
|
+
resetArgs
|
|
202
|
+
}, ctx.getAuthorMarker()));
|
|
113
203
|
});
|
|
114
204
|
server.registerTool("remove_block", {
|
|
115
205
|
title: "Remove Block",
|
|
@@ -121,7 +211,9 @@ function registerBlockTools(server, ctx) {
|
|
|
121
211
|
})
|
|
122
212
|
}, async ({ projectId, blockId }) => {
|
|
123
213
|
return await ctx.withProject(projectId, async (project) => {
|
|
124
|
-
await
|
|
214
|
+
const { error } = await require_readiness.findBlock(project, projectId, blockId, { nothingChanged: true });
|
|
215
|
+
if (error) return error;
|
|
216
|
+
await require_block_state.oneAtATime(project, blockId, () => project.deleteBlock(blockId, ctx.getAuthorMarker()));
|
|
125
217
|
return require_types.textResult({ ok: true });
|
|
126
218
|
});
|
|
127
219
|
});
|
|
@@ -131,16 +223,13 @@ function registerBlockTools(server, ctx) {
|
|
|
131
223
|
...require_types.hints.additive,
|
|
132
224
|
destructiveHint: true
|
|
133
225
|
},
|
|
134
|
-
description: "Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.",
|
|
226
|
+
description: "Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.\n\nA block that cannot run (its readiness has blockers) is refused with the blockers, and nothing is started. Result: `{ ok, started }`, the ids of the blocks started (or `true` when the application does not say which), or `{ ok, nothingToRun: true }` when the block and the blocks above it are up to date. await_block_done waits for the run.",
|
|
135
227
|
inputSchema: zod.z.object({
|
|
136
228
|
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
137
229
|
blockId: require_ids.blockIdInput.describe("Block ID to run")
|
|
138
230
|
})
|
|
139
231
|
}, async ({ projectId, blockId }) => {
|
|
140
|
-
return await ctx.withProject(projectId,
|
|
141
|
-
await project.runBlock(blockId);
|
|
142
|
-
return require_types.textResult({ ok: true });
|
|
143
|
-
});
|
|
232
|
+
return await ctx.withProject(projectId, (project) => runBlockResult(project, projectId, blockId));
|
|
144
233
|
});
|
|
145
234
|
server.registerTool("stop_block", {
|
|
146
235
|
title: "Stop Block",
|
|
@@ -152,6 +241,8 @@ function registerBlockTools(server, ctx) {
|
|
|
152
241
|
})
|
|
153
242
|
}, async ({ projectId, blockId }) => {
|
|
154
243
|
return await ctx.withProject(projectId, async (project) => {
|
|
244
|
+
const { error } = await require_readiness.findBlock(project, projectId, blockId, { nothingChanged: true });
|
|
245
|
+
if (error) return error;
|
|
155
246
|
await project.stopBlock(blockId);
|
|
156
247
|
return require_types.textResult({ ok: true });
|
|
157
248
|
});
|
|
@@ -166,33 +257,47 @@ function registerBlockTools(server, ctx) {
|
|
|
166
257
|
})
|
|
167
258
|
}, async ({ projectId, blockIds }) => {
|
|
168
259
|
return await ctx.withProject(projectId, async (project) => {
|
|
169
|
-
await project.
|
|
260
|
+
const overview = await project.overview.getValue();
|
|
261
|
+
const known = new Set(overview?.blocks.map((b) => b.id));
|
|
262
|
+
const unknown = blockIds.find((id) => !known.has(id));
|
|
263
|
+
if (unknown !== void 0) return require_readiness.unknownBlockResult(projectId, unknown, true);
|
|
264
|
+
await project.reorderBlocks(blockIds, ctx.getAuthorMarker());
|
|
170
265
|
return require_types.textResult({ ok: true });
|
|
171
266
|
});
|
|
172
267
|
});
|
|
173
268
|
server.registerTool("list_available_blocks", {
|
|
174
269
|
title: "List Available Blocks",
|
|
175
270
|
annotations: require_types.hints.read,
|
|
176
|
-
description:
|
|
177
|
-
inputSchema: zod.z.object({
|
|
178
|
-
|
|
179
|
-
|
|
271
|
+
description: `List available blocks from configured registries, 100 at a time. Optional query to filter by name. Result: \`{ blocks, total, offset, hasMore }\`; page with \`offset\` and \`limit\`.`,
|
|
272
|
+
inputSchema: zod.z.object({
|
|
273
|
+
query: zod.z.string().optional().describe("Filter blocks by name (case-insensitive substring match)"),
|
|
274
|
+
...require_paging.pagingArgs("blocks", 100, 500)
|
|
275
|
+
})
|
|
276
|
+
}, async ({ query, limit, offset }) => {
|
|
277
|
+
if (!ctx.callbacks.listAvailableBlocks) return require_types.errorResult("Block listing is not available in this environment.", "The block list comes from the registries of the desktop application, and the application running this server did not provide block listing. add_block with a `kind` spec, and get_block_contract, resolve blocks without it.");
|
|
180
278
|
const blocks = await ctx.callbacks.listAvailableBlocks(query);
|
|
181
|
-
|
|
279
|
+
const { items, ...paging } = require_paging.page(blocks, offset, limit ?? 100);
|
|
280
|
+
return require_types.textResult({
|
|
281
|
+
blocks: items,
|
|
282
|
+
...paging
|
|
283
|
+
}, { hint: "Ask for fewer blocks: a smaller `limit` with `offset` to page, or `query` to narrow by name." });
|
|
182
284
|
});
|
|
183
285
|
server.registerTool("get_block_info", {
|
|
184
286
|
title: "Get Block Info",
|
|
185
287
|
annotations: require_types.hints.read,
|
|
186
288
|
description: "Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.",
|
|
187
289
|
inputSchema: zod.z.object({
|
|
188
|
-
|
|
290
|
+
registryId: zod.z.string().optional().describe("The registry id of the block, `registryId` from list_available_blocks"),
|
|
291
|
+
registryUrl: zod.z.string().optional().describe("Deprecated, accepted for one release: the old name of `registryId`. When both are given, `registryId` is used."),
|
|
189
292
|
organization: zod.z.string().describe("Organization name"),
|
|
190
293
|
name: zod.z.string().describe("Block package name"),
|
|
191
294
|
version: zod.z.string().describe("Block version")
|
|
192
295
|
})
|
|
193
|
-
}, async ({ registryUrl, organization, name, version }) => {
|
|
194
|
-
if (!ctx.callbacks.getBlockInfo) return require_types.errorResult("Block info is not available in this environment.", "
|
|
195
|
-
const
|
|
296
|
+
}, async ({ registryId, registryUrl, organization, name, version }) => {
|
|
297
|
+
if (!ctx.callbacks.getBlockInfo) return require_types.errorResult("Block info is not available in this environment.", "Block info comes from the registries of the desktop application, and this server is not running inside it. add_block with a `kind` spec, and get_block_contract, resolve blocks without it.");
|
|
298
|
+
const registry = registryId ?? registryUrl;
|
|
299
|
+
if (registry === void 0) return require_types.errorResult("Give `registryId`: the registry of the block.", "list_available_blocks gives each block's `registryId`.");
|
|
300
|
+
const info = await ctx.callbacks.getBlockInfo(registry, organization, name, version);
|
|
196
301
|
return require_types.textResult(info);
|
|
197
302
|
});
|
|
198
303
|
server.registerTool("select_block", {
|
|
@@ -205,11 +310,19 @@ function registerBlockTools(server, ctx) {
|
|
|
205
310
|
})
|
|
206
311
|
}, async ({ projectId, blockId }) => {
|
|
207
312
|
if (!ctx.callbacks.selectBlock) return require_types.errorResult("Failed to show the block: this server is not running inside the desktop application.");
|
|
313
|
+
const found = await ctx.withProject(projectId, async (project) => await require_readiness.findBlock(project, projectId, blockId));
|
|
314
|
+
if (found.error) return found.error;
|
|
208
315
|
await ctx.callbacks.selectBlock(projectId, blockId);
|
|
209
316
|
return require_types.textResult({ ok: true });
|
|
210
317
|
});
|
|
211
318
|
}
|
|
212
|
-
exports.
|
|
319
|
+
exports.addNewBlock = addNewBlock;
|
|
320
|
+
exports.applyBlockPack = applyBlockPack;
|
|
321
|
+
exports.blockSpecInput = blockSpecInput;
|
|
322
|
+
exports.centralBlockRegistryUrl = centralBlockRegistryUrl;
|
|
213
323
|
exports.registerBlockTools = registerBlockTools;
|
|
324
|
+
exports.runBlockResult = runBlockResult;
|
|
325
|
+
exports.updateBlockResult = updateBlockResult;
|
|
326
|
+
exports.updateBlockSpecInput = updateBlockSpecInput;
|
|
214
327
|
|
|
215
328
|
//# sourceMappingURL=blocks.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.cjs","names":["CentralBlockRegistry","z","projectIdInput","blockIdInput","BlockKindRef","errorResult","SUPPORTED_BLOCK_API","textResult","unsupportedBlockApiResult","BlockInitParamsRejectedError","hints"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { BlockPackSpecAny, Project } from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, CentralBlockRegistry } from \"@milaboratories/pl-middle-layer\";\nimport { BlockInitParamsRejectedError } from \"@milaboratories/pl-errors\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { AuthorMarker, ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from \"./block-api\";\n\n/** Where a kind is resolved when the caller names no registry. */\nfunction centralBlockRegistryUrl(): string {\n if (CentralBlockRegistry.type !== \"remote-v2\")\n throw new Error(\"The central block registry is expected to be a v2 remote registry.\");\n return CentralBlockRegistry.url;\n}\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\nconst addBlockInput = z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n label: z.string().describe(\"Block label\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"kind\"),\n kind: z\n .string()\n .describe(\n 'Block kind reference \"<package name>@<version or range>\", ' +\n 'e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\"',\n ),\n registryUrl: z\n .string()\n .optional()\n .describe(\"Registry to resolve the kind in (default: the central block registry)\"),\n allowUnstable: z\n .boolean()\n .optional()\n .describe(\"Also consider blocks not published to the stable channel\"),\n }),\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Which block to add\"),\n params: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Initialization params of the block's kind. Omit for the default state.\"),\n blockIds: z\n .record(z.string(), blockIdInput)\n .optional()\n .describe(\n \"Ids used inside `params` in place of block ids, each mapped to a block id of this \" +\n \"project. Needed only when `params` do not already hold ids of this project.\",\n ),\n before: blockIdInput\n .optional()\n .describe(\"ID of the block to insert the new block before (default: add at the end)\"),\n});\n\n/** Input of the `add_block` tool. */\nexport type AddBlockInput = z.infer<typeof addBlockInput>;\n\n/** What `add_block` needs from the application. */\nexport type AddBlockDeps = {\n project: Pick<Project, \"addBlock\">;\n /** Resolves a kind reference to the block implementing it; throws when there is none. */\n resolveKind: (\n kind: BlockKindReference,\n registryUrl: string | undefined,\n allowUnstable: boolean,\n ) => Promise<BlockPackSpecAny>;\n author: AuthorMarker;\n};\n\n/**\n * Adds the block the input describes, started from its params when it carries them. Every way the\n * block can be refused comes back as an error result saying nothing was created.\n */\nexport async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {\n const { label, spec, params, blockIds, before } = input;\n\n let blockPackSpec: BlockPackSpecAny;\n if (spec.type === \"kind\") {\n try {\n blockPackSpec = await deps.resolveKind(\n BlockKindRef.parse(spec.kind),\n spec.registryUrl,\n spec.allowUnstable ?? false,\n );\n } catch (e: unknown) {\n return errorResult(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,\n \"Check the kind name and version. Pass allowUnstable: true if the block is not \" +\n \"published to the stable channel, or registryUrl if it lives in another registry.\",\n );\n }\n } else {\n blockPackSpec = spec;\n }\n\n try {\n const blockId = await deps.project.addBlock(\n label,\n blockPackSpec,\n before,\n deps.author,\n undefined,\n {\n init: params === undefined ? undefined : { params, blockIds },\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n },\n );\n return textResult({ blockId });\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return unsupported;\n if (e instanceof BlockInitParamsRejectedError)\n return errorResult(\n `The block did not accept the params: ${e.reason}. Nothing was created.`,\n \"Fix the params and call add_block again. get_block_params on a configured block \" +\n \"of the same kind shows the expected shape.\",\n );\n throw e;\n }\n}\n\nexport function registerBlockTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n title: \"Add Block\",\n annotations: hints.additive,\n description:\n \"Add a block to a project, optionally configured from initialization params.\\n\\n\" +\n \"`spec` names the block: `kind` (a block kind reference, resolved to the newest block \" +\n \"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev \" +\n \"block folder).\\n\\n\" +\n \"`params` are the initialization params of the block's kind: the block's own model checks \" +\n \"them and builds its initial state from them. Without `params` the block starts in its \" +\n \"default state. get_block_params shows the params of an existing block.\\n\\n\" +\n \"References to other blocks inside `params` must hold real block ids of this project, \" +\n \"copied from tool results. Params copied from another project or a template hold other \" +\n \"ids: map each of them to a block of this project with `blockIds`.\\n\\n\" +\n \"Only blocks on the current block API can be added. On any error nothing is created.\",\n inputSchema: addBlockInput,\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await ctx.withProject(\n input.projectId,\n async (project) =>\n await addBlock(\n {\n project,\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n author: ctx.getAuthorMarker(),\n },\n input,\n ),\n );\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n title: \"Update Block\",\n annotations: hints.destructive,\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to update\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\"Reset block arguments to initial values (default: false)\"),\n }),\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.updateBlockPack(\n blockId,\n spec as BlockPackSpecAny,\n resetArgs ?? false,\n ctx.getAuthorMarker(),\n );\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n title: \"Remove Block\",\n annotations: hints.destructive,\n description:\n \"Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to remove\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.deleteBlock(blockId, ctx.getAuthorMarker());\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n title: \"Run Block\",\n // Starts work like an additive tool, but replaces results and stops blocks computing below.\n annotations: { ...hints.additive, destructiveHint: true },\n description:\n \"Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to run\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.runBlock(blockId);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n title: \"Stop Block\",\n annotations: hints.destructive,\n description: \"Stop the computation of a running block. Use run_block to start it again.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to stop\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n title: \"Reorder Blocks\",\n annotations: hints.destructive,\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z.array(blockIdInput).describe(\"All block IDs in the desired order\"),\n }),\n },\n async ({ projectId, blockIds }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.reorderBlocks(blockIds);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n title: \"List Available Blocks\",\n annotations: hints.read,\n description:\n \"List available blocks from configured registries. Optional query to filter by name.\",\n inputSchema: z.object({\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n }),\n },\n async ({ query }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block registry is not available.\",\n \"This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n return textResult(blocks);\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n title: \"Get Block Info\",\n annotations: hints.read,\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: z.object({\n registryUrl: z.string().describe(\"Registry URL (from list_available_blocks)\"),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n }),\n },\n async ({ registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n 'Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel',\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n title: \"Show Block in the Application\",\n annotations: hints.idempotent,\n description:\n \"Show a block to the user in the application: the application's window opens the block. \" +\n \"Use it only when the user asks to be shown something; working with blocks does not need it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to display\"),\n }),\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to show the block: this server is not running inside the desktop application.\",\n );\n }\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAWA,SAAS,0BAAkC;CACzC,IAAIA,gCAAAA,qBAAqB,SAAS,aAChC,MAAM,IAAI,MAAM,oEAAoE;CACtF,OAAOA,gCAAAA,qBAAqB;AAC9B;AAEA,SAAS,aAAa,GAAoB;CACxC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD;AAEA,MAAM,gBAAgBC,IAAAA,EAAE,OAAO;CAC7B,WAAWC,YAAAA,eAAe,SAAS,YAAY;CAC/C,OAAOD,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;CACxC,MAAMA,IAAAA,EACH,MAAM;EACLA,IAAAA,EAAE,OAAO;GACP,MAAMA,IAAAA,EAAE,QAAQ,MAAM;GACtB,MAAMA,IAAAA,EACH,OAAO,CAAC,CACR,SACC,iIAEF;GACF,aAAaA,IAAAA,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,uEAAuE;GACnF,eAAeA,IAAAA,EACZ,QAAQ,CAAC,CACT,SAAS,CAAC,CACV,SAAS,0DAA0D;EACxE,CAAC;EACDA,IAAAA,EAAE,OAAO;GACP,MAAMA,IAAAA,EAAE,QAAQ,kBAAkB;GAClC,aAAaA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GAC/C,IAAIA,IAAAA,EAAE,OAAO;IACX,cAAcA,IAAAA,EAAE,OAAO;IACvB,MAAMA,IAAAA,EAAE,OAAO;IACf,S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EAAE,OAAO,CAAC,CAAC,SAAS,oBAAoB;GAC9C,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,eAAe;EAC9C,CAAC;CACH,GACA,OAAO,EAAE,aAAa,cAAc,MAAM,cAAc;EACtD,IAAI,CAAC,IAAI,UAAU,cACjB,OAAOI,cAAAA,YACL,oDACA,2KACF;EAEF,MAAM,OAAO,MAAM,IAAI,UAAU,aAAa,aAAa,cAAc,MAAM,OAAO;EACtF,OAAOE,cAAAA,WAAW,IAAI;CACxB,CACF;CAEA,OAAO,aACL,gBACA;EACE,OAAO;EACP,aAAaG,cAAAA,MAAM;EACnB,aACE;EAEF,aAAaT,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAOE,cAAAA,YACL,sFACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOE,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"blocks.cjs","names":["CentralBlockRegistry","z","projectIdInput","blockIdInput","WRITE_WAIT_DEFAULT_MS","WRITE_WAIT_MAX_MS","errorResult","BlockKindRef","SUPPORTED_BLOCK_API","asBlockId","unsupportedBlockApiResult","isBlockInitParamsRejectedError","findBlock","readinessOf","blockStatus","textResult","oneAtATime","hints","settleAfterChange","clampWait","WRITE_WAIT_MIN_MS","unknownBlockResult","pagingArgs","page"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import { asBlockId, type BlockId, type ProjectId } from \"@milaboratories/pl-model-common\";\nimport type { BlockPackSpecAny, Project } from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, CentralBlockRegistry } from \"@milaboratories/pl-middle-layer\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { AuthorMarker, ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport {\n oneAtATime,\n readinessOf,\n type ReadinessProject,\n settleAfterChange,\n WRITE_WAIT_DEFAULT_MS,\n WRITE_WAIT_MAX_MS,\n WRITE_WAIT_MIN_MS,\n} from \"./block-state\";\nimport { blockStatus, type BlockLookupProject, findBlock, unknownBlockResult } from \"./readiness\";\nimport { clampWait } from \"./settle\";\nimport { page, pagingArgs } from \"./paging\";\nimport { isBlockInitParamsRejectedError } from \"./errors\";\nimport { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from \"./block-api\";\n\n/** How many blocks list_available_blocks returns when the caller does not say. */\nexport const AVAILABLE_BLOCKS_DEFAULT_LIMIT = 100;\n/** The most blocks one list_available_blocks call returns. */\nexport const AVAILABLE_BLOCKS_MAX_LIMIT = 500;\n\n/** Where a kind is resolved when the caller names no registry. */\nexport function centralBlockRegistryUrl(): string {\n if (CentralBlockRegistry.type !== \"remote-v2\")\n throw new Error(\"The central block registry is expected to be a v2 remote registry.\");\n return CentralBlockRegistry.url;\n}\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\n/** The ways a tool input names a block: by kind, as an exact registry block, or a dev folder. */\nexport const blockSpecInput = z.union([\n z.object({\n type: z.literal(\"kind\"),\n kind: z\n .string()\n .describe(\n 'Block kind reference \"<package name>@<version or range>\", ' +\n 'e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\"',\n ),\n registryUrl: z\n .string()\n .optional()\n .describe(\"Registry to resolve the kind in (default: the central block registry)\"),\n allowUnstable: z\n .boolean()\n .optional()\n .describe(\"Also consider blocks not published to the stable channel\"),\n }),\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n]);\n\nconst addBlockInput = z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n label: z.string().describe(\"Block label\"),\n spec: blockSpecInput.describe(\"Which block to add\"),\n params: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Initialization params of the block's kind. Omit for the default state.\"),\n blockIds: z\n .record(z.string(), blockIdInput)\n .optional()\n .describe(\n \"Ids used inside `params` in place of block ids, each mapped to a block id of this \" +\n \"project. Needed only when `params` do not already hold ids of this project.\",\n ),\n before: blockIdInput\n .optional()\n .describe(\"ID of the block to insert the new block before (default: add at the end)\"),\n wait: z\n .boolean()\n .optional()\n .describe(\"Wait for the new block's outputs to settle before answering (default false).\"),\n timeout: z\n .number()\n .optional()\n .describe(\n `The longest wait in ms with \\`wait\\` (default ${WRITE_WAIT_DEFAULT_MS}, at most ` +\n `${WRITE_WAIT_MAX_MS}).`,\n ),\n});\n\n/** Input of the `add_block` tool. */\nexport type AddBlockInput = z.infer<typeof addBlockInput>;\n\n/** What `add_block` needs from the application. */\nexport type AddBlockDeps = {\n project: Pick<Project, \"addBlock\">;\n /** Resolves a kind reference to the block implementing it; throws when there is none. */\n resolveKind: (\n kind: BlockKindReference,\n registryUrl: string | undefined,\n allowUnstable: boolean,\n ) => Promise<BlockPackSpecAny>;\n author: AuthorMarker;\n};\n\n/**\n * Adds the block the input describes, started from its params when it carries them. Every way the\n * block can be refused comes back as an error result saying nothing was created.\n */\nexport async function addNewBlock(\n deps: AddBlockDeps,\n input: Omit<AddBlockInput, \"wait\" | \"timeout\">,\n): Promise<{ blockId: BlockId } | { result: ReturnType<typeof errorResult> }> {\n const { label, spec, params, blockIds, before } = input;\n const refuse = (message: string, hint: string) => ({ result: errorResult(message, hint) });\n\n let blockPackSpec: BlockPackSpecAny;\n if (spec.type === \"kind\") {\n try {\n blockPackSpec = await deps.resolveKind(\n BlockKindRef.parse(spec.kind),\n spec.registryUrl,\n spec.allowUnstable ?? false,\n );\n } catch (e: unknown) {\n return refuse(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,\n \"Check the kind name and version. Pass allowUnstable: true if the block is not \" +\n \"published to the stable channel, or registryUrl if it lives in another registry.\",\n );\n }\n } else {\n blockPackSpec = spec;\n }\n\n try {\n const blockId = await deps.project.addBlock(\n label,\n blockPackSpec,\n before,\n deps.author,\n undefined,\n {\n init: params === undefined ? undefined : { params, blockIds },\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n },\n );\n return { blockId: asBlockId(blockId) };\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return { result: unsupported };\n if (isBlockInitParamsRejectedError(e))\n return refuse(\n `The block did not accept the params: ${e.reason}. Nothing was created.`,\n \"Fix the params and call add_block again. get_block_contract on the kind shows the \" +\n \"params it accepts.\",\n );\n throw e;\n }\n}\n\n/** What `run_block` needs of a project; a middle-layer `Project` has it. */\nexport type RunProject = ReadinessProject & {\n /**\n * Starts the block and the stale blocks above it; the middle layer answers with the ids of the\n * blocks it started (older middle layers answer nothing).\n */\n runBlock(blockId: BlockId): Promise<readonly BlockId[] | void>;\n};\n\n/**\n * Runs a block, unless it cannot run: the readiness is computed first, and a block with blockers\n * is refused with them, nothing started. The result names the blocks started, or says there was\n * nothing to run (the block and the blocks above it are up to date).\n */\nexport async function runBlockResult(project: RunProject, projectId: ProjectId, blockId: BlockId) {\n const { block, error } = await findBlock(project, projectId, blockId, { nothingChanged: true });\n if (error) return error;\n const readiness = await readinessOf(project, blockId);\n if (readiness !== undefined && readiness.blockers.length > 0)\n return errorResult(\n `Block ${blockId} cannot run; nothing was started. ` +\n readiness.blockers\n .map((b) => `[${b.kind}${b.blockId !== undefined ? ` ${b.blockId}` : \"\"}] ${b.message}`)\n .join(\" \"),\n \"Fix what the blockers name: set_block_params changes the block's params, \" +\n \"set_block_data its data; get_block_state shows its readiness. A blocker of a block \" +\n \"above is fixed on that block.\",\n );\n const started = await project.runBlock(blockId);\n const nothingToRun = Array.isArray(started)\n ? started.length === 0\n : blockStatus(block) === \"up-to-date\";\n if (nothingToRun)\n return textResult({\n ok: true,\n nothingToRun: true,\n note:\n \"The block and the blocks above it are up to date: nothing was started. Its results \" +\n \"follow its current data; get_block_outputs reads them.\",\n });\n return textResult(Array.isArray(started) ? { ok: true, started } : { ok: true, started: true });\n}\n\n/** The block packs `update_block` and `update_blocks` move a block to: a registry block or a dev folder. */\nexport const updateBlockSpecInput = z.union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n channel: z\n .string()\n .optional()\n .describe(\n \"The registry channel the block follows for its updates; keep the one of the spec \" +\n \"list_block_updates gives.\",\n ),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n]);\n\n/** What {@link applyBlockPack} needs of a project; a middle-layer `Project` has it. */\nexport type BlockPackProject = Pick<Project, \"updateBlockPack\">;\n\n/**\n * The one way this server moves a block to another block pack (`update_block`, `update_blocks`):\n * in the block's turn among this server's changes of it ({@link oneAtATime}), asking the middle layer for a pack on the\n * current block API. Answers the error result of the shared block API guard when the pack is\n * refused for its block API (nothing is changed), `undefined` when the block was moved; any other\n * failure is thrown.\n *\n * `beforeWrite` runs when the block's turn starts, right before the write: what it throws is\n * thrown here and nothing is changed. A caller that waited for its turn checks there whether it\n * still wants the write.\n */\nexport async function applyBlockPack(\n project: BlockPackProject,\n blockId: BlockId,\n spec: BlockPackSpecAny,\n options: { resetArgs: boolean; author: AuthorMarker; beforeWrite?: () => void },\n): Promise<ReturnType<typeof errorResult> | undefined> {\n try {\n await oneAtATime(project, blockId, async () => {\n options.beforeWrite?.();\n await project.updateBlockPack(blockId, spec, options.resetArgs, options.author, {\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n });\n });\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return unsupported;\n throw e;\n }\n return undefined;\n}\n\n/** What `update_block` needs of a project; a middle-layer `Project` has it. */\nexport type UpdateProject = BlockLookupProject<{ id: string }> & BlockPackProject;\n\n/**\n * Moves a block to another block pack. Nothing is changed when the block is not in the project or\n * the pack is refused (the shared block API guard included).\n */\nexport async function updateBlockResult(\n project: UpdateProject,\n input: { projectId: ProjectId; blockId: BlockId; spec: BlockPackSpecAny; resetArgs?: boolean },\n author: AuthorMarker,\n) {\n const { projectId, blockId } = input;\n const { error } = await findBlock(project, projectId, blockId, { nothingChanged: true });\n if (error) return error;\n const refused = await applyBlockPack(project, blockId, input.spec, {\n resetArgs: input.resetArgs ?? false,\n author,\n });\n return refused ?? textResult({ ok: true });\n}\n\nexport function registerBlockTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n title: \"Add Block\",\n annotations: hints.additive,\n description:\n \"Add a block to a project, optionally configured from initialization params.\\n\\n\" +\n \"`spec` names the block: `kind` (a block kind reference, resolved to the newest block \" +\n \"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev \" +\n \"block folder).\\n\\n\" +\n \"`params` are the initialization params of the block's kind: the block's own model checks \" +\n \"them and builds its initial state from them. Without `params` the block starts in its \" +\n \"default state. get_block_contract shows the params a kind accepts, get_block_params the \" +\n \"params of an existing block. Without params, configure the block afterwards: read its \" +\n \"options outputs (get_block_outputs; references to results of blocks above come from \" +\n \"there), then write them into its params with set_block_params, or into its data with \" +\n \"set_block_data for what params do not cover. Params and data can name the same thing \" +\n \"differently: read the data with get_block_state before writing it. A block offers results \" +\n \"of blocks above only once they exist, and some blocks publish results only from their \" +\n \"run: if an option is missing and the block above has not run, run it first (run_block, \" +\n \"await_block_done).\\n\\n\" +\n \"References to other blocks inside `params` must hold real block ids of this project, \" +\n \"copied from tool results. Params copied from another project or a template hold other \" +\n \"ids: map each of them to a block of this project with `blockIds`.\\n\\n\" +\n \"Only blocks on the current block API can be added. On any error nothing is created.\\n\\n\" +\n \"Result: `{ blockId, readiness, settled, waitedMs, outputs, ... }`; `readiness` as \" +\n \"get_block_state gives it: whether the block can run and, if not, the block's own \" +\n \"messages on why. With `wait: true` the call waits for the outputs to settle; the first \" +\n \"settle of a new block can take one refresh cycle (about 2 s). A wait that runs out is \" +\n \"not an error: the block was added, and `settled: false` says what is still pending.\",\n inputSchema: addBlockInput,\n },\n async ({ wait, timeout, ...input }, call) => {\n const ml = ctx.requireMl();\n return await ctx.withProject(input.projectId, async (project) => {\n if (input.before !== undefined) {\n const { error } = await findBlock(project, input.projectId, input.before, {\n nothingChanged: true,\n });\n if (error) return error;\n }\n const added = await addNewBlock(\n {\n project,\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n author: ctx.getAuthorMarker(),\n },\n input,\n );\n if (\"result\" in added) return added.result;\n return textResult({\n blockId: added.blockId,\n // No marker to wait for: the block's storage was created, not written by a call.\n ...(await settleAfterChange(project, added.blockId, {\n wait: wait ?? false,\n timeoutMs: clampWait(\n timeout,\n WRITE_WAIT_DEFAULT_MS,\n WRITE_WAIT_MIN_MS,\n WRITE_WAIT_MAX_MS,\n ),\n call,\n notePrerun: false,\n })),\n });\n });\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n title: \"Update Block\",\n annotations: hints.destructive,\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after \" +\n \"rebuilding a dev block to pick up changes without removing/re-adding it. Only block \" +\n \"packs on the current block API are taken; on any error nothing is changed. To upgrade \" +\n \"the blocks of a project to newer versions, use list_block_updates and update_blocks.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to update\"),\n spec: updateBlockSpecInput.describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\n \"Start the block over from its initial state: its data and the data of its plugins \" +\n \"are discarded (default: false, the data is kept and migrated).\",\n ),\n }),\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n return await ctx.withProject(projectId, (project) =>\n updateBlockResult(\n project,\n { projectId, blockId, spec: spec as BlockPackSpecAny, resetArgs },\n ctx.getAuthorMarker(),\n ),\n );\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n title: \"Remove Block\",\n annotations: hints.destructive,\n description:\n \"Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to remove\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n const { error } = await findBlock(project, projectId, blockId, { nothingChanged: true });\n if (error) return error;\n await oneAtATime(project, blockId, () =>\n project.deleteBlock(blockId, ctx.getAuthorMarker()),\n );\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n title: \"Run Block\",\n // Starts work like an additive tool, but replaces results and stops blocks computing below.\n annotations: { ...hints.additive, destructiveHint: true },\n description:\n \"Run a block. Stale upstream blocks are started automatically. A run replaces the \" +\n \"previous results of each block it starts; downstream blocks that are still computing \" +\n \"are stopped and their unfinished work is lost.\\n\\n\" +\n \"A block that cannot run (its readiness has blockers) is refused with the blockers, and \" +\n \"nothing is started. Result: `{ ok, started }`, the ids of the blocks started (or \" +\n \"`true` when the application does not say which), or `{ ok, nothingToRun: true }` when \" +\n \"the block and the blocks above it are up to date. await_block_done waits for the run.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to run\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, (project) =>\n runBlockResult(project, projectId, blockId),\n );\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n title: \"Stop Block\",\n annotations: hints.destructive,\n description: \"Stop the computation of a running block. Use run_block to start it again.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to stop\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n const { error } = await findBlock(project, projectId, blockId, { nothingChanged: true });\n if (error) return error;\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n title: \"Reorder Blocks\",\n annotations: hints.destructive,\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z.array(blockIdInput).describe(\"All block IDs in the desired order\"),\n }),\n },\n async ({ projectId, blockIds }) => {\n return await ctx.withProject(projectId, async (project) => {\n const overview = await project.overview.getValue();\n const known = new Set(overview?.blocks.map((b) => b.id));\n const unknown = blockIds.find((id) => !known.has(id));\n if (unknown !== undefined) return unknownBlockResult(projectId, unknown, true);\n await project.reorderBlocks(blockIds, ctx.getAuthorMarker());\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n title: \"List Available Blocks\",\n annotations: hints.read,\n description:\n \"List available blocks from configured registries, \" +\n `${AVAILABLE_BLOCKS_DEFAULT_LIMIT} at a time. Optional query to filter by name. ` +\n \"Result: `{ blocks, total, offset, hasMore }`; page with `offset` and `limit`.\",\n inputSchema: z.object({\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n ...pagingArgs(\"blocks\", AVAILABLE_BLOCKS_DEFAULT_LIMIT, AVAILABLE_BLOCKS_MAX_LIMIT),\n }),\n },\n async ({ query, limit, offset }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block listing is not available in this environment.\",\n \"The block list comes from the registries of the desktop application, and the \" +\n \"application running this server did not provide block listing. add_block with a \" +\n \"`kind` spec, and get_block_contract, resolve blocks without it.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n const { items, ...paging } = page(blocks, offset, limit ?? AVAILABLE_BLOCKS_DEFAULT_LIMIT);\n return textResult(\n { blocks: items, ...paging },\n {\n hint:\n \"Ask for fewer blocks: a smaller `limit` with `offset` to page, or `query` to narrow \" +\n \"by name.\",\n },\n );\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n title: \"Get Block Info\",\n annotations: hints.read,\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: z.object({\n registryId: z\n .string()\n .optional()\n .describe(\"The registry id of the block, `registryId` from list_available_blocks\"),\n registryUrl: z\n .string()\n .optional()\n .describe(\n \"Deprecated, accepted for one release: the old name of `registryId`. \" +\n \"When both are given, `registryId` is used.\",\n ),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n }),\n },\n async ({ registryId, registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n \"Block info comes from the registries of the desktop application, and this server \" +\n \"is not running inside it. add_block with a `kind` spec, and get_block_contract, \" +\n \"resolve blocks without it.\",\n );\n }\n const registry = registryId ?? registryUrl;\n if (registry === undefined) {\n return errorResult(\n \"Give `registryId`: the registry of the block.\",\n \"list_available_blocks gives each block's `registryId`.\",\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registry, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n title: \"Show Block in the Application\",\n annotations: hints.idempotent,\n description:\n \"Show a block to the user in the application: the application's window opens the block. \" +\n \"Use it only when the user asks to be shown something; working with blocks does not need it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to display\"),\n }),\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to show the block: this server is not running inside the desktop application.\",\n );\n }\n const found = await ctx.withProject(\n projectId,\n async (project) => await findBlock(project, projectId, blockId),\n );\n if (found.error) return found.error;\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;AA6BA,SAAgB,0BAAkC;CAChD,IAAIA,gCAAAA,qBAAqB,SAAS,aAChC,MAAM,IAAI,MAAM,oEAAoE;CACtF,OAAOA,gCAAAA,qBAAqB;AAC9B;AAEA,SAAS,aAAa,GAAoB;CACxC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD;;AAGA,MAAa,iBAAiBC,IAAAA,EAAE,MAAM;CACpCA,IAAAA,EAAE,OAAO;EACP,MAAMA,IAAAA,EAAE,QAAQ,MAAM;EACtB,MAAMA,IAAAA,EACH,OAAO,CAAC,CACR,SACC,iIAEF;EACF,aAAaA,IAAAA,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,uEAAuE;EACnF,eAAeA,IAAAA,EACZ,QAAQ,CAAC,CACT,SAAS,CAAC,CACV,SAAS,0DAA0D;CACxE,CAAC;CACDA,IAAAA,EAAE,OAAO;EACP,MAAMA,IAAAA,EAAE,QAAQ,kBAAkB;EAClC,aAAaA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;EAC/C,IAAIA,IAAAA,EAAE,OAAO;GACX,cAAcA,IAAAA,EAAE,OAAO;GACvB,MAAMA,IAAAA,EAAE,OAAO;GACf,SAASA,IAAAA,EAAE,OAAO;EACpB,CAAC;CACH,CAAC;CACDA,IAAAA,EAAE,OAAO;EACP,MAAMA,IAAAA,EAAE,QAAQ,QAAQ;EACxB,QAAQA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,sBAAsB;CACpD,CAAC;AACH,CAAC;AAED,MAAM,gBAAgBA,IAAAA,EAAE,OAAO;CAC7B,WAAWC,YAAAA,eAAe,SAAS,YAAY;CAC/C,OAAOD,IAAAA,EAAE,OAAO,CAAC,C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