@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
|
@@ -1,22 +1,290 @@
|
|
|
1
1
|
const require_types = require("./types.cjs");
|
|
2
2
|
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_settle = require("./settle.cjs");
|
|
4
|
+
const require_sandbox = require("./sandbox.cjs");
|
|
5
|
+
const require_block_storage = require("./block-storage.cjs");
|
|
6
|
+
const require_readiness = require("./readiness.cjs");
|
|
7
|
+
const require_block_api = require("./block-api.cjs");
|
|
8
|
+
const require_block_state = require("./block-state.cjs");
|
|
9
|
+
const require_blocks = require("./blocks.cjs");
|
|
10
|
+
const require_sdk_types = require("./sdk-types.cjs");
|
|
11
|
+
const require_params_merge = require("./params-merge.cjs");
|
|
12
|
+
let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
|
|
13
|
+
let node_util = require("node:util");
|
|
3
14
|
let zod = require("zod");
|
|
4
15
|
// src/tools/block-params.ts
|
|
16
|
+
/** The most conflicting or differing paths a refusal of set_block_params names. */
|
|
17
|
+
const MAX_NAMED_PATHS = 20;
|
|
18
|
+
/** Where a refusal of set_block_params sends the agent. */
|
|
19
|
+
const USE_SET_BLOCK_DATA = "Write the block's data with set_block_data instead: read it with get_block_state, change it and write it back.";
|
|
20
|
+
const setBlockParamsInput = zod.z.object({
|
|
21
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
22
|
+
blockId: require_ids.blockIdInput.describe("Block ID"),
|
|
23
|
+
params: zod.z.unknown().optional().describe("The whole new params of the block's kind: the value get_block_params returned, changed. Not a patch. Give `params` or `update`, not both."),
|
|
24
|
+
update: zod.z.string().optional().describe("Instead of `params`: a JS expression evaluated in the server against the current params, available as `params`; its value is the whole new params. Example: `({ ...params, threshold: 2 })`."),
|
|
25
|
+
updateTimeout: zod.z.number().optional().describe(require_sandbox.expressionTimeoutText("the `update` expression", require_block_state.DEFAULT_EXPRESSION_TIMEOUT)),
|
|
26
|
+
wait: zod.z.boolean().optional().describe("Wait for the block's outputs to settle on the new data before answering (default true)."),
|
|
27
|
+
timeout: zod.z.number().optional().describe(`The longest wait in ms (default ${require_block_state.WRITE_WAIT_DEFAULT_MS}, at most ${require_block_state.WRITE_WAIT_MAX_MS}).`)
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Writes a block's configuration as its kind's params (D-040, Q-047, D-045). A block whose model
|
|
31
|
+
* declares `applyParams` puts the new params `p1` onto its current data itself. For any other
|
|
32
|
+
* block the new data is a three-way merge ({@link mergeThreeWay}): base `init(p0)` from the current
|
|
33
|
+
* params `p0 = templateParams(data)`, theirs `init(p1)` from the new params, ours the current data.
|
|
34
|
+
* Refused, with nothing written, when the block gives no params, its data waits for a migration,
|
|
35
|
+
* the kind rejects `p1`, the merge conflicts, or the new data does not give back the params of
|
|
36
|
+
* `init(p1)`.
|
|
37
|
+
*
|
|
38
|
+
* The write is {@link writeBlockData}'s: one at a time per block.
|
|
39
|
+
*/
|
|
40
|
+
async function writeBlockParams(project, author, input) {
|
|
41
|
+
const { blockId, params, update, updateTimeout } = input;
|
|
42
|
+
if (params === void 0 === (update === void 0)) return require_block_state.refuse(require_types.errorResult("Give either `params` or `update`. Nothing was changed.", "`params` is the whole new params; `update` is an expression computing them from the current ones."));
|
|
43
|
+
const computeNext = async (current, rawStorage) => {
|
|
44
|
+
let found;
|
|
45
|
+
try {
|
|
46
|
+
found = await project.getBlockParamsModel(blockId);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
const unsupported = require_block_api.unsupportedBlockApiResult(e);
|
|
49
|
+
if (unsupported) return require_block_state.refuse(unsupported);
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
return await mergeParams(found, blockId, current, require_block_storage.readStorageView(rawStorage).dataVersion, {
|
|
53
|
+
params,
|
|
54
|
+
update,
|
|
55
|
+
updateTimeout
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return await require_block_state.writeBlockData(project, author, {
|
|
59
|
+
blockId,
|
|
60
|
+
computeNext
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** The data set_block_params writes over `current` (at `dataVersion`), or why it writes none. */
|
|
64
|
+
async function mergeParams(model, blockId, current, dataVersion, input) {
|
|
65
|
+
if (!model.givesParams) return require_block_state.refuse(require_types.errorResult(`Block ${blockId} gives no params: this version of the block was built before blocks had them. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
66
|
+
if (dataVersion === void 0) return require_block_state.refuse(require_types.errorResult(`Block ${blockId} keeps no versioned data yet, so its params cannot be merged into it. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
67
|
+
if (typeof dataVersion !== "string") return require_block_state.refuse(require_types.errorResult(`Block ${blockId} keeps its data in the format of an early SDK release, so its params cannot be merged into it. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
68
|
+
const p0 = model.paramsOf({
|
|
69
|
+
dataVersion,
|
|
70
|
+
data: current
|
|
71
|
+
});
|
|
72
|
+
if (p0.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block's model could not derive its params from its data: ${p0.error.message}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
73
|
+
const p1 = await newParams(p0.value, input);
|
|
74
|
+
if (p1.kind === "refused") return p1;
|
|
75
|
+
if (model.appliesParams) return appliedParams(model, current, dataVersion, p1.params);
|
|
76
|
+
const base = model.dataOf(p0.value);
|
|
77
|
+
if (base.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block's model cannot build its data from its own current params: ${base.error.message}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
78
|
+
if (base.value.dataVersion !== dataVersion) return require_block_state.refuse(require_types.errorResult(`The block's data is at version ${dataVersion}; its model builds version ${base.value.dataVersion}, so the data waits for a migration. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
79
|
+
const theirs = model.dataOf(p1.params);
|
|
80
|
+
if (theirs.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block does not accept these params: ${theirs.error.message}. Nothing was changed.`, "get_block_params gives the current params; change them and send them whole."));
|
|
81
|
+
const { merged, conflicts } = require_params_merge.mergeThreeWay(base.value.data, theirs.value.data, current);
|
|
82
|
+
if (conflicts.length > 0) return require_block_state.refuse(require_types.errorResult(`The new params change parts of the block's data that also hold changes the params do not describe: ${named(conflicts)}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
83
|
+
const refused = givesParamsBack(model, theirs.value, {
|
|
84
|
+
dataVersion,
|
|
85
|
+
data: merged
|
|
86
|
+
}, (paths) => require_types.errorResult(`The block's data merged with the new params would not give these params back; they differ at ${paths}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
87
|
+
if (refused !== void 0) return refused;
|
|
88
|
+
return {
|
|
89
|
+
kind: "next",
|
|
90
|
+
next: merged
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The data a block that declares `applyParams` writes: `applyParams(current, p1)`, by the block's
|
|
95
|
+
* own model (D-045), which refuses params the kind rejects and data waiting for a migration.
|
|
96
|
+
* Refused too when the new data does not give back the params `init(p1)` gives.
|
|
97
|
+
*/
|
|
98
|
+
function appliedParams(model, current, dataVersion, p1) {
|
|
99
|
+
const next = model.applyParams({
|
|
100
|
+
dataVersion,
|
|
101
|
+
data: current
|
|
102
|
+
}, p1);
|
|
103
|
+
if (next.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block's applyParams could not put these params onto its data: ${next.error.message}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
104
|
+
const theirs = model.dataOf(p1);
|
|
105
|
+
if (theirs.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block's model cannot build its data from these params: ${theirs.error.message}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
106
|
+
const refused = givesParamsBack(model, theirs.value, next.value, (paths) => require_types.errorResult(`The block's applyParams does not give its params back: the data it builds from the current data and these params gives other params than these, at ${paths}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
107
|
+
if (refused !== void 0) return refused;
|
|
108
|
+
return {
|
|
109
|
+
kind: "next",
|
|
110
|
+
next: next.value.data
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Nothing when `next` gives back the params `theirs` (the data of the new params alone) gives;
|
|
115
|
+
* otherwise the refusal `differ` makes of the named paths where they differ, or one naming why
|
|
116
|
+
* params could not be derived.
|
|
117
|
+
*/
|
|
118
|
+
function givesParamsBack(model, theirs, next, differ) {
|
|
119
|
+
const wanted = model.paramsOf(theirs);
|
|
120
|
+
const got = model.paramsOf(next);
|
|
121
|
+
if (wanted.error !== void 0 || got.error !== void 0) return require_block_state.refuse(require_types.errorResult(`The block's model could not derive params from the new data: ${(wanted.error ?? got.error)?.message}. Nothing was changed.`, USE_SET_BLOCK_DATA));
|
|
122
|
+
if (!(0, node_util.isDeepStrictEqual)(wanted.value, got.value)) return require_block_state.refuse(differ(named(require_block_storage.diffValues(wanted.value, got.value, MAX_NAMED_PATHS).changes.map((c) => c.path))));
|
|
123
|
+
}
|
|
124
|
+
/** The new params: `params`, or the value of `update` over the current params `p0`. */
|
|
125
|
+
async function newParams(p0, input) {
|
|
126
|
+
if (input.update === void 0) return {
|
|
127
|
+
kind: "params",
|
|
128
|
+
params: input.params
|
|
129
|
+
};
|
|
130
|
+
let value;
|
|
131
|
+
try {
|
|
132
|
+
value = await require_sandbox.safeEval(input.update, { params: p0 }, input.updateTimeout ?? 5e3);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
return require_block_state.refuse(require_types.transformFailedResult(e, "Nothing was changed. The expression gets the current params as `params` and must return the whole new params, e.g. `({ ...params, key: 1 })`."));
|
|
135
|
+
}
|
|
136
|
+
if (value === void 0 || value === null) return require_block_state.refuse(require_types.errorResult("The `update` expression returned no value. Nothing was changed.", "Return the whole new params, e.g. `({ ...params, key: 1 })`."));
|
|
137
|
+
return {
|
|
138
|
+
kind: "params",
|
|
139
|
+
params: value
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** The first {@link MAX_NAMED_PATHS} of `paths`, and how many more there are. */
|
|
143
|
+
function named(paths) {
|
|
144
|
+
const shown = paths.slice(0, MAX_NAMED_PATHS).join(", ");
|
|
145
|
+
return paths.length > MAX_NAMED_PATHS ? `${shown} and ${paths.length - MAX_NAMED_PATHS} more` : shown;
|
|
146
|
+
}
|
|
147
|
+
const getBlockContractInput = zod.z.object({ spec: require_blocks.blockSpecInput.describe("The block, named as for add_block") });
|
|
148
|
+
function errorMessage(e) {
|
|
149
|
+
return e instanceof Error ? e.message : String(e);
|
|
150
|
+
}
|
|
151
|
+
/** Thrown by the block registry reader when the registry answered, but not with the file. */
|
|
152
|
+
function isRegistryReadError(e) {
|
|
153
|
+
return e instanceof Error && e.name === "RegistryReadError";
|
|
154
|
+
}
|
|
155
|
+
/** The size over which `get_block_contract` returns where the declaration is, not its text. */
|
|
156
|
+
const DECLARATION_CAP_BYTES = 16384;
|
|
157
|
+
const REGISTRY_HINT = "The registry could not be read; this says nothing about the kind. Try again.";
|
|
158
|
+
/**
|
|
159
|
+
* Returns the declaration of the kind the block in `input` implements, whose type argument of
|
|
160
|
+
* `kind` is what `params` of add_block accepts. A kind built before kinds carried a declaration
|
|
161
|
+
* agents read gets a note and where to look instead.
|
|
162
|
+
*/
|
|
163
|
+
async function getBlockContract(deps, input) {
|
|
164
|
+
const { spec } = input;
|
|
165
|
+
let blockPackSpec;
|
|
166
|
+
if (spec.type === "kind") try {
|
|
167
|
+
blockPackSpec = await deps.resolveKind(_milaboratories_pl_middle_layer.BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
return isRegistryReadError(e) ? require_types.errorResult(`Kind "${spec.kind}" was not resolved: ${errorMessage(e)}`, REGISTRY_HINT) : require_types.errorResult(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}`, "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.");
|
|
170
|
+
}
|
|
171
|
+
else blockPackSpec = spec;
|
|
172
|
+
let described;
|
|
173
|
+
try {
|
|
174
|
+
described = await deps.describeBlockPack(blockPackSpec);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return require_types.errorResult(`The block was not read: ${errorMessage(e)}`, isRegistryReadError(e) ? REGISTRY_HINT : void 0);
|
|
177
|
+
}
|
|
178
|
+
if (described.kind === void 0) return require_types.textResult({ notes: ["This block declares no kind, so add_block takes no params for it."] });
|
|
179
|
+
const declaredKind = described.declaredKind;
|
|
180
|
+
const identity = {
|
|
181
|
+
kind: described.kind,
|
|
182
|
+
...declaredKind !== void 0 && declaredKind !== described.kind ? { declaredKind } : {}
|
|
183
|
+
};
|
|
184
|
+
const declaration = described.declaration;
|
|
185
|
+
if (declaration === void 0) {
|
|
186
|
+
if (declaredKind === void 0) return require_types.textResult({
|
|
187
|
+
...identity,
|
|
188
|
+
notes: ["Kind declarations are read only for registry and dev blocks."]
|
|
189
|
+
});
|
|
190
|
+
const { legacyDeclarationUrl: url, homepage } = described;
|
|
191
|
+
return require_types.textResult({
|
|
192
|
+
...identity,
|
|
193
|
+
...url !== void 0 ? { declarationUrl: url } : {},
|
|
194
|
+
...homepage !== void 0 ? { homepage } : {},
|
|
195
|
+
notes: [`Kind ${declaredKind} has no ${_milaboratories_pl_middle_layer.KindContractFileName}: it was built before kinds carried a declaration agents can read. ` + (spec.type === "dev-v2" ? "Rebuilding the kind package with a current @milaboratories/ts-builder adds one." : "One comes with the next release of the block.") + (url !== void 0 ? " `declarationUrl` is its kind.d.ts, with every dependency inlined (tens of KB); the params are the type argument of `kind`." : "") + (homepage !== void 0 ? " The block's homepage is `homepage`." : "")]
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const bytes = Buffer.byteLength(declaration.text, "utf8");
|
|
199
|
+
if (bytes > 16384) return require_types.textResult({
|
|
200
|
+
...identity,
|
|
201
|
+
source: _milaboratories_pl_middle_layer.KindContractFileName,
|
|
202
|
+
declarationBytes: bytes,
|
|
203
|
+
declarationUrl: declaration.url,
|
|
204
|
+
notes: [`The declaration is ${bytes} bytes, over the ${DECLARATION_CAP_BYTES} this tool returns. Read it at \`declarationUrl\`.`]
|
|
205
|
+
});
|
|
206
|
+
return require_types.textResult({
|
|
207
|
+
...identity,
|
|
208
|
+
source: _milaboratories_pl_middle_layer.KindContractFileName,
|
|
209
|
+
declaration: declaration.text,
|
|
210
|
+
sdkTypes: require_sdk_types.SDK_TYPES
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** Default timeout of a `transform` of `get_block_params`, in milliseconds. */
|
|
214
|
+
const DEFAULT_TRANSFORM_TIMEOUT = 5e3;
|
|
215
|
+
/**
|
|
216
|
+
* The answer of `get_block_params`: the block's kind and params, or, with `transform`, the value
|
|
217
|
+
* of that expression evaluated in the sandbox against them (variables `kind` and `params`).
|
|
218
|
+
*/
|
|
219
|
+
async function blockParamsResult(initialization, transform, transformTimeout) {
|
|
220
|
+
if (!transform) return require_types.textResult(initialization, { hint: "Read part of the params with `transform`, e.g. `params.<key>`." });
|
|
221
|
+
try {
|
|
222
|
+
return require_types.textResult(await require_sandbox.safeEval(transform, {
|
|
223
|
+
kind: initialization.kind,
|
|
224
|
+
params: initialization.params
|
|
225
|
+
}, transformTimeout));
|
|
226
|
+
} catch (e) {
|
|
227
|
+
return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: kind, params.");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
5
230
|
function registerBlockParamsTools(server, ctx) {
|
|
6
231
|
server.registerTool("get_block_params", {
|
|
7
232
|
title: "Get Block Params",
|
|
8
233
|
annotations: require_types.hints.read,
|
|
9
|
-
description: "Get a block's configuration as the initialization params of its kind: what a project template stores for this block. The block's own model derives them from its current data. Pass the result as `params` of add_block, with a block of the same kind, to create a block configured the same way.
|
|
234
|
+
description: "Get a block's configuration as the initialization params of its kind: what a project template stores for this block. The block's own model derives them from its current data. Change them with set_block_params. Pass the result as `params` of add_block, with a block of the same kind, to create a block configured the same way. Params leave out view state (table filters, plot settings) and values that do not travel in a template, such as file handles and per-sample values. The kind may still accept them: set_block_params writes them, get_block_state shows them.\n\nReturns `{ kind, params }`. `kind` is absent for a block that declares none. Read part of large params with `transform`, e.g. `params.settings`.",
|
|
10
235
|
inputSchema: zod.z.object({
|
|
11
236
|
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
12
|
-
blockId: require_ids.blockIdInput.describe("Block ID")
|
|
237
|
+
blockId: require_ids.blockIdInput.describe("Block ID"),
|
|
238
|
+
transform: zod.z.string().optional().describe("JS expression evaluated server-side against the params. Available variables: `kind` (the block's kind), `params` (its params). Omit for `{ kind, params }`."),
|
|
239
|
+
transformTimeout: zod.z.number().optional().default(DEFAULT_TRANSFORM_TIMEOUT).describe(require_sandbox.expressionTimeoutText("transform evaluation", DEFAULT_TRANSFORM_TIMEOUT))
|
|
13
240
|
})
|
|
14
|
-
}, async ({ projectId, blockId }) => {
|
|
241
|
+
}, async ({ projectId, blockId, transform, transformTimeout }) => {
|
|
242
|
+
return await ctx.withProject(projectId, async (project) => {
|
|
243
|
+
const { error } = await require_readiness.findBlock(project, projectId, blockId);
|
|
244
|
+
if (error) return error;
|
|
245
|
+
return await blockParamsResult(await project.getBlockInitializationParams(blockId), transform, transformTimeout);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
server.registerTool("get_block_contract", {
|
|
249
|
+
title: "Get Block Contract",
|
|
250
|
+
annotations: require_types.hints.read,
|
|
251
|
+
description: `Get the params a block kind accepts at creation: the kind's TypeScript declaration (\`${_milaboratories_pl_middle_layer.KindContractFileName}\`), where \`params\` of add_block is the type argument of the exported \`kind\` (usually \`BlockParams\`). \`spec\` names the block as add_block does. This describes creation params only; the data of an existing block is read with get_block_state.
|
|
252
|
+
|
|
253
|
+
Returns \`{ kind, source, declaration, sdkTypes, notes? }\`. \`declaration\` is the whole file: the kind's own types, with the SDK types they use imported; \`sdkTypes\` declares the SDK types kinds use in short form. For a column or value id it names the form (PlRef object, GlobalPObjectId string, leaf PObjectId, any ColumnUniversalId, ColumnValueId) and the tool that gives it; ids go into params as written, the server never narrows one to its leaf. Over 16 KB, \`declaration\` is replaced by \`declarationBytes\` and \`declarationUrl\`. A kind published before kinds carried this declaration returns no \`declaration\`: a note says so, with \`declarationUrl\` of its published file and the block's \`homepage\` when it names one.`,
|
|
254
|
+
inputSchema: getBlockContractInput
|
|
255
|
+
}, async (input) => {
|
|
256
|
+
const ml = ctx.requireMl();
|
|
257
|
+
return await getBlockContract({
|
|
258
|
+
resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? require_blocks.centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
|
|
259
|
+
describeBlockPack: (spec) => ml.describeBlockPack(spec)
|
|
260
|
+
}, input);
|
|
261
|
+
});
|
|
262
|
+
server.registerTool("set_block_params", {
|
|
263
|
+
title: "Set Block Params",
|
|
264
|
+
annotations: require_types.hints.destructive,
|
|
265
|
+
description: "Configure a block through its kind's params, the values get_block_params returns. Send the whole new `params`, or `update`, an expression the server evaluates against the current params. A block that puts params onto its data itself does so; for any other, its model builds data from the new params and the server merges it into the current data. Either way what the params changed is written, the rest (view state such as table filters and plot settings) is kept. Elements of lists that carry an `id` follow their id in the merge. A write equal to the current data is skipped (`unchanged: true`). The write re-derives the block's args; the block's results, and those of blocks below it, become stale until they run again.\n\nRefused, with nothing changed, when the block is not on the current block API, gives no params, its data waits for a migration, the block rejects the params, the new params change a part of the data that also holds other changes, or the new data would not give the params back; the error names the paths. set_block_data writes the data directly then. Keys the kind accepts but its params leave out are written too and do not show in get_block_params afterwards: file handles (from get_file_handles), per-sample values, resource settings. Give files here when the kind accepts them; set_block_data only when it does not.\n\nBy default the call then waits (up to `timeout`) for the block's outputs to settle on the new data, as set_block_data does; a wait that runs out is not an error.\n\nResult: `{ ok, unchanged?, settled, waitedMs, readiness, outputs, outputsNote?, note? }`, as set_block_data gives them, without the changed paths.",
|
|
266
|
+
inputSchema: setBlockParamsInput
|
|
267
|
+
}, async ({ projectId, wait, timeout, ...input }, call) => {
|
|
15
268
|
return await ctx.withProject(projectId, async (project) => {
|
|
16
|
-
|
|
269
|
+
const outcome = await writeBlockParams(project, ctx.getAuthorMarker(), input);
|
|
270
|
+
if (outcome.kind === "refused") return outcome.result;
|
|
271
|
+
return require_types.textResult({
|
|
272
|
+
ok: true,
|
|
273
|
+
...outcome.unchanged ? { unchanged: true } : {},
|
|
274
|
+
...await require_block_state.settleAfterChange(project, input.blockId, {
|
|
275
|
+
wait: wait ?? true,
|
|
276
|
+
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),
|
|
277
|
+
call,
|
|
278
|
+
notePrerun: true
|
|
279
|
+
})
|
|
280
|
+
});
|
|
17
281
|
});
|
|
18
282
|
});
|
|
19
283
|
}
|
|
284
|
+
exports.DECLARATION_CAP_BYTES = DECLARATION_CAP_BYTES;
|
|
285
|
+
exports.blockParamsResult = blockParamsResult;
|
|
286
|
+
exports.getBlockContract = getBlockContract;
|
|
20
287
|
exports.registerBlockParamsTools = registerBlockParamsTools;
|
|
288
|
+
exports.writeBlockParams = writeBlockParams;
|
|
21
289
|
|
|
22
290
|
//# sourceMappingURL=block-params.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-params.cjs","names":["hints","z","projectIdInput","blockIdInput","textResult"],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n return textResult(await project.getBlockInitializationParams(blockId));\n });\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,yBAAyB,QAAuB,KAAwB;CACtF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EAMF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,UAAU;EAC3C,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,OAAOC,cAAAA,WAAW,MAAM,QAAQ,6BAA6B,OAAO,CAAC;EACvE,CAAC;CACH,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"block-params.cjs","names":["z","projectIdInput","blockIdInput","expressionTimeoutText","DEFAULT_EXPRESSION_TIMEOUT","WRITE_WAIT_DEFAULT_MS","WRITE_WAIT_MAX_MS","refuse","errorResult","unsupportedBlockApiResult","readStorageView","writeBlockData","mergeThreeWay","isDeepStrictEqual","diffValues","safeEval","transformFailedResult","blockSpecInput","BlockKindRef","textResult","KindContractFileName","SDK_TYPES","hints","findBlock","centralBlockRegistryUrl","settleAfterChange","clampWait","WRITE_WAIT_MIN_MS"],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport type { BlockId } from \"@milaboratories/pl-model-common\";\nimport type {\n BlockPackSpecAny,\n BlockParamsModel,\n DescribedBlockPack,\n VersionedBlockData,\n} from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, KindContractFileName } from \"@milaboratories/pl-middle-layer\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { blockSpecInput, centralBlockRegistryUrl } from \"./blocks\";\nimport { SDK_TYPES } from \"./sdk-types\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport { expressionTimeoutText, safeEval } from \"./sandbox\";\nimport type { AuthorMarker, ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult, transformFailedResult } from \"./types\";\nimport { findBlock } from \"./readiness\";\nimport {\n type BlockDataProject,\n type ComputeNext,\n DEFAULT_EXPRESSION_TIMEOUT,\n refuse,\n settleAfterChange,\n type WriteOutcome,\n type WriteRefused,\n WRITE_WAIT_DEFAULT_MS,\n WRITE_WAIT_MAX_MS,\n WRITE_WAIT_MIN_MS,\n writeBlockData,\n} from \"./block-state\";\nimport { type DataVersion, diffValues, readStorageView } from \"./block-storage\";\nimport { clampWait } from \"./settle\";\nimport { unsupportedBlockApiResult } from \"./block-api\";\nimport { mergeThreeWay } from \"./params-merge\";\n\n/** The most conflicting or differing paths a refusal of set_block_params names. */\nconst MAX_NAMED_PATHS = 20;\n\n/** Where a refusal of set_block_params sends the agent. */\nconst USE_SET_BLOCK_DATA =\n \"Write the block's data with set_block_data instead: read it with get_block_state, change it \" +\n \"and write it back.\";\n\n/** What {@link writeBlockParams} needs of a project; a `Project` of the middle layer has it. */\nexport type BlockParamsProject = BlockDataProject & {\n getBlockParamsModel(blockId: BlockId): Promise<BlockParamsModel>;\n};\n\nconst setBlockParamsInput = z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n params: z\n .unknown()\n .optional()\n .describe(\n \"The whole new params of the block's kind: the value get_block_params returned, changed. \" +\n \"Not a patch. Give `params` or `update`, not both.\",\n ),\n update: z\n .string()\n .optional()\n .describe(\n \"Instead of `params`: a JS expression evaluated in the server against the current params, \" +\n \"available as `params`; its value is the whole new params. \" +\n \"Example: `({ ...params, threshold: 2 })`.\",\n ),\n updateTimeout: z\n .number()\n .optional()\n .describe(expressionTimeoutText(\"the `update` expression\", DEFAULT_EXPRESSION_TIMEOUT)),\n wait: z\n .boolean()\n .optional()\n .describe(\n \"Wait for the block's outputs to settle on the new data before answering (default true).\",\n ),\n timeout: z\n .number()\n .optional()\n .describe(\n `The longest wait in ms (default ${WRITE_WAIT_DEFAULT_MS}, at most ${WRITE_WAIT_MAX_MS}).`,\n ),\n});\n\n/** Input of the `set_block_params` tool. */\nexport type SetBlockParamsInput = z.infer<typeof setBlockParamsInput>;\n\n/**\n * Writes a block's configuration as its kind's params (D-040, Q-047, D-045). A block whose model\n * declares `applyParams` puts the new params `p1` onto its current data itself. For any other\n * block the new data is a three-way merge ({@link mergeThreeWay}): base `init(p0)` from the current\n * params `p0 = templateParams(data)`, theirs `init(p1)` from the new params, ours the current data.\n * Refused, with nothing written, when the block gives no params, its data waits for a migration,\n * the kind rejects `p1`, the merge conflicts, or the new data does not give back the params of\n * `init(p1)`.\n *\n * The write is {@link writeBlockData}'s: one at a time per block.\n */\nexport async function writeBlockParams(\n project: BlockParamsProject,\n author: AuthorMarker,\n input: Omit<SetBlockParamsInput, \"projectId\" | \"wait\" | \"timeout\">,\n): Promise<WriteOutcome> {\n const { blockId, params, update, updateTimeout } = input;\n if ((params === undefined) === (update === undefined))\n return refuse(\n errorResult(\n \"Give either `params` or `update`. Nothing was changed.\",\n \"`params` is the whole new params; `update` is an expression computing them from the \" +\n \"current ones.\",\n ),\n );\n\n const computeNext: ComputeNext = async (current, rawStorage) => {\n let found: BlockParamsModel;\n try {\n found = await project.getBlockParamsModel(blockId);\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return refuse(unsupported);\n throw e;\n }\n return await mergeParams(found, blockId, current, readStorageView(rawStorage).dataVersion, {\n params,\n update,\n updateTimeout,\n });\n };\n return await writeBlockData(project, author, { blockId, computeNext });\n}\n\n/** The data set_block_params writes over `current` (at `dataVersion`), or why it writes none. */\nasync function mergeParams(\n model: BlockParamsModel,\n blockId: BlockId,\n current: unknown,\n dataVersion: DataVersion,\n input: Pick<SetBlockParamsInput, \"params\" | \"update\" | \"updateTimeout\">,\n): Promise<WriteRefused | { kind: \"next\"; next: unknown }> {\n if (!model.givesParams)\n return refuse(\n errorResult(\n `Block ${blockId} gives no params: this version of the block was built before blocks ` +\n \"had them. Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n if (dataVersion === undefined)\n return refuse(\n errorResult(\n `Block ${blockId} keeps no versioned data yet, so its params cannot be merged into it. ` +\n \"Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n if (typeof dataVersion !== \"string\")\n return refuse(\n errorResult(\n `Block ${blockId} keeps its data in the format of an early SDK release, so its params ` +\n \"cannot be merged into it. Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n\n const p0 = model.paramsOf({ dataVersion, data: current });\n if (p0.error !== undefined)\n return refuse(\n errorResult(\n `The block's model could not derive its params from its data: ${p0.error.message}. ` +\n \"Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n\n const p1 = await newParams(p0.value, input);\n if (p1.kind === \"refused\") return p1;\n\n if (model.appliesParams) return appliedParams(model, current, dataVersion, p1.params);\n\n const base = model.dataOf(p0.value);\n if (base.error !== undefined)\n return refuse(\n errorResult(\n \"The block's model cannot build its data from its own current params: \" +\n `${base.error.message}. Nothing was changed.`,\n USE_SET_BLOCK_DATA,\n ),\n );\n if (base.value.dataVersion !== dataVersion)\n return refuse(\n errorResult(\n `The block's data is at version ${dataVersion}; its model builds version ` +\n `${base.value.dataVersion}, so the data waits for a migration. Nothing was changed.`,\n USE_SET_BLOCK_DATA,\n ),\n );\n\n const theirs = model.dataOf(p1.params);\n if (theirs.error !== undefined)\n return refuse(\n errorResult(\n `The block does not accept these params: ${theirs.error.message}. Nothing was changed.`,\n \"get_block_params gives the current params; change them and send them whole.\",\n ),\n );\n\n const { merged, conflicts } = mergeThreeWay(base.value.data, theirs.value.data, current);\n if (conflicts.length > 0)\n return refuse(\n errorResult(\n \"The new params change parts of the block's data that also hold changes the params do \" +\n `not describe: ${named(conflicts)}. Nothing was changed.`,\n USE_SET_BLOCK_DATA,\n ),\n );\n\n // The merged data must give back what the new params alone give: otherwise the merge kept\n // something of the current data that overrides the new params.\n const refused = givesParamsBack(model, theirs.value, { dataVersion, data: merged }, (paths) =>\n errorResult(\n \"The block's data merged with the new params would not give these params back; they \" +\n `differ at ${paths}. Nothing was changed.`,\n USE_SET_BLOCK_DATA,\n ),\n );\n if (refused !== undefined) return refused;\n\n return { kind: \"next\", next: merged };\n}\n\n/**\n * The data a block that declares `applyParams` writes: `applyParams(current, p1)`, by the block's\n * own model (D-045), which refuses params the kind rejects and data waiting for a migration.\n * Refused too when the new data does not give back the params `init(p1)` gives.\n */\nfunction appliedParams(\n model: BlockParamsModel,\n current: unknown,\n dataVersion: string,\n p1: unknown,\n): WriteRefused | { kind: \"next\"; next: unknown } {\n const next = model.applyParams({ dataVersion, data: current }, p1);\n if (next.error !== undefined)\n return refuse(\n errorResult(\n `The block's applyParams could not put these params onto its data: ${next.error.message}. ` +\n \"Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n\n // The law the server keeps checking: params put onto any data project back as they do onto\n // the defaults. A block that breaks it would write data that does not say what was asked.\n const theirs = model.dataOf(p1);\n if (theirs.error !== undefined)\n return refuse(\n errorResult(\n `The block's model cannot build its data from these params: ${theirs.error.message}. ` +\n \"Nothing was changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n const refused = givesParamsBack(model, theirs.value, next.value, (paths) =>\n errorResult(\n \"The block's applyParams does not give its params back: the data it builds from the \" +\n `current data and these params gives other params than these, at ${paths}. Nothing was ` +\n \"changed.\",\n USE_SET_BLOCK_DATA,\n ),\n );\n if (refused !== undefined) return refused;\n\n return { kind: \"next\", next: next.value.data };\n}\n\n/**\n * Nothing when `next` gives back the params `theirs` (the data of the new params alone) gives;\n * otherwise the refusal `differ` makes of the named paths where they differ, or one naming why\n * params could not be derived.\n */\nfunction givesParamsBack(\n model: BlockParamsModel,\n theirs: VersionedBlockData,\n next: VersionedBlockData,\n differ: (paths: string) => ReturnType<typeof errorResult>,\n): WriteRefused | undefined {\n const wanted = model.paramsOf(theirs);\n const got = model.paramsOf(next);\n if (wanted.error !== undefined || got.error !== undefined)\n return refuse(\n errorResult(\n \"The block's model could not derive params from the new data: \" +\n `${(wanted.error ?? got.error)?.message}. Nothing was changed.`,\n USE_SET_BLOCK_DATA,\n ),\n );\n if (!isDeepStrictEqual(wanted.value, got.value))\n return refuse(\n differ(\n named(diffValues(wanted.value, got.value, MAX_NAMED_PATHS).changes.map((c) => c.path)),\n ),\n );\n return undefined;\n}\n\n/** The new params: `params`, or the value of `update` over the current params `p0`. */\nasync function newParams(\n p0: unknown,\n input: Pick<SetBlockParamsInput, \"params\" | \"update\" | \"updateTimeout\">,\n): Promise<WriteRefused | { kind: \"params\"; params: unknown }> {\n if (input.update === undefined) return { kind: \"params\", params: input.params };\n let value: unknown;\n try {\n value = await safeEval(\n input.update,\n { params: p0 },\n input.updateTimeout ?? DEFAULT_EXPRESSION_TIMEOUT,\n );\n } catch (e: unknown) {\n return refuse(\n transformFailedResult(\n e,\n \"Nothing was changed. The expression gets the current params as `params` and must \" +\n \"return the whole new params, e.g. `({ ...params, key: 1 })`.\",\n ),\n );\n }\n if (value === undefined || value === null)\n return refuse(\n errorResult(\n \"The `update` expression returned no value. Nothing was changed.\",\n \"Return the whole new params, e.g. `({ ...params, key: 1 })`.\",\n ),\n );\n return { kind: \"params\", params: value };\n}\n\n/** The first {@link MAX_NAMED_PATHS} of `paths`, and how many more there are. */\nfunction named(paths: string[]): string {\n const shown = paths.slice(0, MAX_NAMED_PATHS).join(\", \");\n return paths.length > MAX_NAMED_PATHS\n ? `${shown} and ${paths.length - MAX_NAMED_PATHS} more`\n : shown;\n}\n\nconst getBlockContractInput = z.object({\n spec: blockSpecInput.describe(\"The block, named as for add_block\"),\n});\n\n/** Input of the `get_block_contract` tool. */\nexport type GetBlockContractInput = z.infer<typeof getBlockContractInput>;\n\n/** What `get_block_contract` needs from the application. */\nexport type GetBlockContractDeps = {\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 describeBlockPack: (spec: BlockPackSpecAny) => Promise<DescribedBlockPack>;\n};\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\n/** Thrown by the block registry reader when the registry answered, but not with the file. */\nfunction isRegistryReadError(e: unknown): boolean {\n return e instanceof Error && e.name === \"RegistryReadError\";\n}\n\n/** The size over which `get_block_contract` returns where the declaration is, not its text. */\nexport const DECLARATION_CAP_BYTES = 16 * 1024;\n\nconst REGISTRY_HINT =\n \"The registry could not be read; this says nothing about the kind. Try again.\";\n\n/**\n * Returns the declaration of the kind the block in `input` implements, whose type argument of\n * `kind` is what `params` of add_block accepts. A kind built before kinds carried a declaration\n * agents read gets a note and where to look instead.\n */\nexport async function getBlockContract(deps: GetBlockContractDeps, input: GetBlockContractInput) {\n const { spec } = 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 isRegistryReadError(e)\n ? errorResult(`Kind \"${spec.kind}\" was not resolved: ${errorMessage(e)}`, REGISTRY_HINT)\n : errorResult(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}`,\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 let described: DescribedBlockPack;\n try {\n described = await deps.describeBlockPack(blockPackSpec);\n } catch (e: unknown) {\n return errorResult(\n `The block was not read: ${errorMessage(e)}`,\n isRegistryReadError(e) ? REGISTRY_HINT : undefined,\n );\n }\n\n if (described.kind === undefined)\n return textResult({\n notes: [\"This block declares no kind, so add_block takes no params for it.\"],\n });\n const declaredKind = described.declaredKind;\n const identity = {\n kind: described.kind,\n ...(declaredKind !== undefined && declaredKind !== described.kind ? { declaredKind } : {}),\n };\n const declaration = described.declaration;\n if (declaration === undefined) {\n if (declaredKind === undefined)\n return textResult({\n ...identity,\n notes: [\"Kind declarations are read only for registry and dev blocks.\"],\n });\n const { legacyDeclarationUrl: url, homepage } = described;\n return textResult({\n ...identity,\n ...(url !== undefined ? { declarationUrl: url } : {}),\n ...(homepage !== undefined ? { homepage } : {}),\n notes: [\n `Kind ${declaredKind} has no ${KindContractFileName}: it was built before kinds carried ` +\n \"a declaration agents can read. \" +\n (spec.type === \"dev-v2\"\n ? \"Rebuilding the kind package with a current @milaboratories/ts-builder adds one.\"\n : \"One comes with the next release of the block.\") +\n (url !== undefined\n ? \" `declarationUrl` is its kind.d.ts, with every dependency inlined (tens of KB); \" +\n \"the params are the type argument of `kind`.\"\n : \"\") +\n (homepage !== undefined ? \" The block's homepage is `homepage`.\" : \"\"),\n ],\n });\n }\n\n const bytes = Buffer.byteLength(declaration.text, \"utf8\");\n if (bytes > DECLARATION_CAP_BYTES)\n return textResult({\n ...identity,\n source: KindContractFileName,\n declarationBytes: bytes,\n declarationUrl: declaration.url,\n notes: [\n `The declaration is ${bytes} bytes, over the ${DECLARATION_CAP_BYTES} this tool ` +\n \"returns. Read it at `declarationUrl`.\",\n ],\n });\n\n return textResult({\n ...identity,\n source: KindContractFileName,\n declaration: declaration.text,\n sdkTypes: SDK_TYPES,\n });\n}\n\n/** Default timeout of a `transform` of `get_block_params`, in milliseconds. */\nconst DEFAULT_TRANSFORM_TIMEOUT = 5000;\n\n/**\n * The answer of `get_block_params`: the block's kind and params, or, with `transform`, the value\n * of that expression evaluated in the sandbox against them (variables `kind` and `params`).\n */\nexport async function blockParamsResult(\n initialization: { kind: BlockKindReference | undefined; params: unknown },\n transform: string | undefined,\n transformTimeout: number,\n) {\n if (!transform)\n return textResult(initialization, {\n hint: \"Read part of the params with `transform`, e.g. `params.<key>`.\",\n });\n try {\n return textResult(\n await safeEval(\n transform,\n { kind: initialization.kind, params: initialization.params },\n transformTimeout,\n ),\n );\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n \"Check your JS expression syntax. Available variables: kind, params.\",\n );\n }\n}\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Change them with set_block_params. Pass the result as `params` of add_block, with a \" +\n \"block of the same kind, to create a block configured the same way. Params leave out \" +\n \"view state (table filters, plot settings) and values that do not travel in a template, \" +\n \"such as file handles and per-sample values. The kind may still accept them: \" +\n \"set_block_params writes them, get_block_state shows them.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none. Read \" +\n \"part of large params with `transform`, e.g. `params.settings`.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against the params. Available variables: \" +\n \"`kind` (the block's kind), `params` (its params). Omit for `{ kind, params }`.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(DEFAULT_TRANSFORM_TIMEOUT)\n .describe(expressionTimeoutText(\"transform evaluation\", DEFAULT_TRANSFORM_TIMEOUT)),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n return await ctx.withProject(projectId, async (project) => {\n const { error } = await findBlock(project, projectId, blockId);\n if (error) return error;\n return await blockParamsResult(\n await project.getBlockInitializationParams(blockId),\n transform,\n transformTimeout,\n );\n });\n },\n );\n\n server.registerTool(\n \"get_block_contract\",\n {\n title: \"Get Block Contract\",\n annotations: hints.read,\n description:\n \"Get the params a block kind accepts at creation: the kind's TypeScript declaration \" +\n `(\\`${KindContractFileName}\\`), ` +\n \"where `params` of add_block is the type argument of the exported `kind` \" +\n \"(usually `BlockParams`). `spec` names the block as add_block does. This describes \" +\n \"creation params only; the data of an existing block is read with get_block_state.\\n\\n\" +\n \"Returns `{ kind, source, declaration, sdkTypes, notes? }`. `declaration` is the whole \" +\n \"file: the kind's own types, with the SDK types they use imported; `sdkTypes` declares \" +\n \"the SDK types kinds use in short form. For a column or value id it names the form (PlRef object, \" +\n \"GlobalPObjectId string, leaf PObjectId, any ColumnUniversalId, ColumnValueId) and the \" +\n \"tool that gives it; ids go into params as written, the server never narrows one to its \" +\n \"leaf. Over 16 KB, `declaration` is replaced by `declarationBytes` and `declarationUrl`. \" +\n \"A kind published before kinds carried this declaration returns no `declaration`: a \" +\n \"note says so, with `declarationUrl` of its published file and the block's `homepage` \" +\n \"when it names one.\",\n inputSchema: getBlockContractInput,\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await getBlockContract(\n {\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n describeBlockPack: (spec) => ml.describeBlockPack(spec),\n },\n input,\n );\n },\n );\n\n server.registerTool(\n \"set_block_params\",\n {\n title: \"Set Block Params\",\n annotations: hints.destructive,\n description:\n \"Configure a block through its kind's params, the values get_block_params returns. \" +\n \"Send the whole new `params`, or `update`, an expression the server evaluates against \" +\n \"the current params. A block that puts params onto its data itself does so; for any \" +\n \"other, its model builds data from the new params and the server merges it into the \" +\n \"current data. Either way what the params changed is written, the rest \" +\n \"(view state such as table filters and plot settings) is kept. Elements of lists that \" +\n \"carry an `id` follow their id in the merge. A write equal to the current data is skipped \" +\n \"(`unchanged: true`). The write re-derives the block's args; the block's results, and \" +\n \"those of blocks below it, become stale until they run again.\\n\\n\" +\n \"Refused, with nothing changed, when the block is not on the current block API, gives no \" +\n \"params, its data waits for a \" +\n \"migration, the block rejects the params, the new params change a part of the data that \" +\n \"also holds other changes, or the new data would not give the params back; the error \" +\n \"names the paths. set_block_data writes the data directly then. Keys the kind accepts \" +\n \"but its params leave out are written too and do not show in get_block_params \" +\n \"afterwards: file handles (from get_file_handles), per-sample values, resource \" +\n \"settings. Give files here when the kind accepts them; set_block_data only when it \" +\n \"does not.\\n\\n\" +\n \"By default the call then waits (up to `timeout`) for the block's outputs to settle on \" +\n \"the new data, as set_block_data does; a wait that runs out is not an error.\\n\\n\" +\n \"Result: `{ ok, unchanged?, settled, waitedMs, readiness, outputs, outputsNote?, \" +\n \"note? }`, \" +\n \"as set_block_data gives them, without the changed paths.\",\n inputSchema: setBlockParamsInput,\n },\n async ({ projectId, wait, timeout, ...input }, call) => {\n return await ctx.withProject(projectId, async (project) => {\n const author = ctx.getAuthorMarker();\n const outcome = await writeBlockParams(project, author, input);\n if (outcome.kind === \"refused\") return outcome.result;\n return textResult({\n ok: true,\n ...(outcome.unchanged ? { unchanged: true } : {}),\n ...(await settleAfterChange(project, input.blockId, {\n wait: wait ?? true,\n timeoutMs: clampWait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