@milaboratories/pl-mcp-server 53.1.0 → 55.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -37
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +16 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +16 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +122 -0
- package/dist/project-holds.cjs.map +1 -0
- package/dist/project-holds.js +122 -0
- package/dist/project-holds.js.map +1 -0
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +48 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +48 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +71 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +37 -24
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +71 -19
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -72
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -74
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +14 -9
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +14 -9
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +275 -6
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +273 -8
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +343 -57
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +337 -61
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +199 -76
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +193 -76
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +470 -101
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +465 -106
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +72 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +63 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +111 -30
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +108 -31
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +68 -38
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +69 -40
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +16 -12
- package/src/project-holds.test.ts +362 -0
- package/src/project-holds.ts +207 -0
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +71 -6
- package/src/server-log.ts +58 -27
- package/src/server.logging.test.ts +46 -51
- package/src/server.test.ts +166 -22
- package/src/server.ts +97 -37
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -122
- package/src/tools/block-action-context.ts +17 -13
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +626 -10
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +678 -83
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +354 -113
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +839 -145
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +89 -1
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +154 -44
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +136 -48
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +84 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
import { asBlockId, type BlockId, type ProjectId } from "@milaboratories/pl-model-common";
|
|
2
|
+
import type {
|
|
3
|
+
BlockPackSpec,
|
|
4
|
+
BlockPackSpecAny,
|
|
5
|
+
BlockStateOverview,
|
|
6
|
+
VersionLock,
|
|
7
|
+
} from "@milaboratories/pl-middle-layer";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { AWAIT_DEFAULT_MS, AWAIT_MAX_MS, AWAIT_MIN_MS } from "./await";
|
|
10
|
+
import { readinessOf, type ReadinessProject } from "./block-state";
|
|
11
|
+
import { applyBlockPack, type BlockPackProject, updateBlockSpecInput } from "./blocks";
|
|
12
|
+
import { blockIdInput, projectIdInput } from "./ids";
|
|
13
|
+
import { page, pagingArgs } from "./paging";
|
|
14
|
+
import {
|
|
15
|
+
type BlockStatus,
|
|
16
|
+
type Readiness,
|
|
17
|
+
type ReadinessBlocker,
|
|
18
|
+
unknownBlockResult,
|
|
19
|
+
} from "./readiness";
|
|
20
|
+
import { clampWait, progressReporter, withDeadline } from "./settle";
|
|
21
|
+
import { clip } from "./tokens";
|
|
22
|
+
import type { AuthorMarker, ToolContext, ToolRegistrar } from "./types";
|
|
23
|
+
import { errorResult, hints, textResult } from "./types";
|
|
24
|
+
|
|
25
|
+
/** How many blocks list_block_updates returns when the caller does not say. */
|
|
26
|
+
export const BLOCK_UPDATES_DEFAULT_LIMIT = 50;
|
|
27
|
+
/** The most blocks one list_block_updates call returns. */
|
|
28
|
+
export const BLOCK_UPDATES_MAX_LIMIT = 200;
|
|
29
|
+
|
|
30
|
+
/** The most characters of the reason of a block's outcome in the answer of update_blocks. */
|
|
31
|
+
export const UPDATE_REASON_CHARS = 300;
|
|
32
|
+
|
|
33
|
+
/** The most characters of a block's label in the answer of update_blocks. */
|
|
34
|
+
export const UPDATE_LABEL_CHARS = 80;
|
|
35
|
+
|
|
36
|
+
/** The most blockers of an updated block's readiness the answer of update_blocks lists. */
|
|
37
|
+
export const UPDATE_READINESS_BLOCKERS = 3;
|
|
38
|
+
|
|
39
|
+
/** The most characters of one such blocker's message. */
|
|
40
|
+
export const UPDATE_BLOCKER_CHARS = 200;
|
|
41
|
+
|
|
42
|
+
/** The most characters of a registry URL, folder or pack URL in `from` and `to`. */
|
|
43
|
+
const UPDATE_SOURCE_CHARS = 300;
|
|
44
|
+
|
|
45
|
+
/** The release line of an update the registry offers, against the block's current version. */
|
|
46
|
+
export type UpdateLevel = "major" | "minor" | "patch";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Where a block pack comes from: a registry (with the version), a local dev folder, or a block
|
|
50
|
+
* pack folder of an installed package.
|
|
51
|
+
*/
|
|
52
|
+
export type PackSource =
|
|
53
|
+
| { source: "registry"; registry: string; version: string; channel?: string }
|
|
54
|
+
| { source: "dev"; folder: string }
|
|
55
|
+
| { source: "pack"; packUrl: string };
|
|
56
|
+
|
|
57
|
+
/** One version a block can be updated to. */
|
|
58
|
+
export type UpdateCandidate = {
|
|
59
|
+
version: string;
|
|
60
|
+
level: UpdateLevel;
|
|
61
|
+
/** The block pack spec to update to, as update_block takes it. */
|
|
62
|
+
spec: BlockPackSpec;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The update the application recommends: the newest the block's `versionLock` allows, or for a
|
|
67
|
+
* block from a local folder, the newer build in that folder (`rebuilt`).
|
|
68
|
+
*/
|
|
69
|
+
export type RecommendedUpdate = UpdateCandidate | { level: "rebuilt"; spec: BlockPackSpec };
|
|
70
|
+
|
|
71
|
+
/** The updates of one block, as list_block_updates gives them. */
|
|
72
|
+
export type BlockUpdates = {
|
|
73
|
+
blockId: BlockId;
|
|
74
|
+
label: string | undefined;
|
|
75
|
+
/** Where the block's pack comes from now; absent while the pack is not loaded. */
|
|
76
|
+
current?: PackSource;
|
|
77
|
+
recommended?: RecommendedUpdate;
|
|
78
|
+
/** Every update the registry offers, newest release line first. */
|
|
79
|
+
available: UpdateCandidate[];
|
|
80
|
+
versionLock?: VersionLock;
|
|
81
|
+
/** Updates up to this version are not recommended (the user skipped them). */
|
|
82
|
+
skipVersion?: string;
|
|
83
|
+
/** The block does not work with this application version. */
|
|
84
|
+
incompatible?: true;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** What the update tools read of a block of the project overview. */
|
|
88
|
+
export type UpdatesOverviewBlock = Pick<
|
|
89
|
+
BlockStateOverview,
|
|
90
|
+
| "id"
|
|
91
|
+
| "title"
|
|
92
|
+
| "label"
|
|
93
|
+
| "currentBlockPack"
|
|
94
|
+
| "updatedBlockPack"
|
|
95
|
+
| "updateSuggestions"
|
|
96
|
+
| "settings"
|
|
97
|
+
| "isIncompatibleWithRuntime"
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
/** What the update tools read of a project. */
|
|
101
|
+
export type UpdatesProject = {
|
|
102
|
+
overview: {
|
|
103
|
+
getValue(): Promise<{ blocks: UpdatesOverviewBlock[] } | undefined>;
|
|
104
|
+
/**
|
|
105
|
+
* Resolves once every source of the overview was read again, the application's check of the
|
|
106
|
+
* registries for updates included (a middle-layer `Computable`).
|
|
107
|
+
*/
|
|
108
|
+
refreshState(): Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* How long the update tools wait for the application's check of the registries for updates. The
|
|
114
|
+
* check runs in the background; until its answer is in, the overview offers no update for a
|
|
115
|
+
* block, as on a project just opened.
|
|
116
|
+
*/
|
|
117
|
+
export const UPDATE_CHECK_WAIT_MS = 15_000;
|
|
118
|
+
|
|
119
|
+
/** What the update tools say when the check of the registries is not in. */
|
|
120
|
+
export const UPDATE_CHECK_PENDING_NOTE =
|
|
121
|
+
"The application's check of the registries for updates has not finished: some blocks may " +
|
|
122
|
+
"have updates that are not shown yet. Call again in a moment.";
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The project overview with the application's update check fresh: asks for a new check and
|
|
126
|
+
* waits for it, at most `timeoutMs` or until `signal`. `checked: false` when the check was not in
|
|
127
|
+
* by then: the updates the overview gives may then miss some.
|
|
128
|
+
*/
|
|
129
|
+
export async function overviewWithUpdates(
|
|
130
|
+
project: UpdatesProject,
|
|
131
|
+
timeoutMs: number,
|
|
132
|
+
signal?: AbortSignal,
|
|
133
|
+
): Promise<{ overview: { blocks: UpdatesOverviewBlock[] } | undefined; checked: boolean }> {
|
|
134
|
+
// Read once first: the overview knows its sources only once it was computed.
|
|
135
|
+
const first = await project.overview.getValue();
|
|
136
|
+
if (first === undefined) return { overview: undefined, checked: false };
|
|
137
|
+
const checked = await withDeadline(
|
|
138
|
+
timeoutMs,
|
|
139
|
+
signal,
|
|
140
|
+
(deadline) =>
|
|
141
|
+
new Promise<boolean>((resolve) => {
|
|
142
|
+
if (deadline.aborted) return resolve(false);
|
|
143
|
+
deadline.addEventListener("abort", () => resolve(false), { once: true });
|
|
144
|
+
project.overview.refreshState().then(
|
|
145
|
+
() => resolve(true),
|
|
146
|
+
() => resolve(false),
|
|
147
|
+
);
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
return { overview: await project.overview.getValue(), checked };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Where `spec` comes from. */
|
|
154
|
+
export function packSource(spec: BlockPackSpec): PackSource {
|
|
155
|
+
switch (spec.type) {
|
|
156
|
+
case "from-registry-v2":
|
|
157
|
+
return {
|
|
158
|
+
source: "registry",
|
|
159
|
+
registry: spec.registryUrl,
|
|
160
|
+
version: spec.id.version,
|
|
161
|
+
...(spec.channel !== undefined ? { channel: spec.channel } : {}),
|
|
162
|
+
};
|
|
163
|
+
case "from-registry-v1":
|
|
164
|
+
return { source: "registry", registry: spec.registryUrl, version: spec.id.version };
|
|
165
|
+
case "dev-v1":
|
|
166
|
+
case "dev-v2":
|
|
167
|
+
return { source: "dev", folder: spec.folder };
|
|
168
|
+
case "from-pack-v2":
|
|
169
|
+
return { source: "pack", packUrl: spec.packUrl };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The version of a registry pack; `undefined` for a pack from a folder. */
|
|
174
|
+
function versionOf(spec: BlockPackSpec): string | undefined {
|
|
175
|
+
return spec.type === "from-registry-v1" || spec.type === "from-registry-v2"
|
|
176
|
+
? spec.id.version
|
|
177
|
+
: undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The updates of one block, from its overview entry alone. */
|
|
181
|
+
export function blockUpdatesOf(block: UpdatesOverviewBlock): BlockUpdates {
|
|
182
|
+
const available: UpdateCandidate[] = [];
|
|
183
|
+
for (const { type, update } of block.updateSuggestions) {
|
|
184
|
+
const version = versionOf(update);
|
|
185
|
+
if (version !== undefined) available.push({ version, level: type, spec: update });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let recommended: RecommendedUpdate | undefined;
|
|
189
|
+
const main = block.updatedBlockPack;
|
|
190
|
+
if (main !== undefined) {
|
|
191
|
+
const version = versionOf(main);
|
|
192
|
+
const level = available.find((c) => c.version === version)?.level;
|
|
193
|
+
recommended =
|
|
194
|
+
version !== undefined && level !== undefined
|
|
195
|
+
? { version, level, spec: main }
|
|
196
|
+
: { level: "rebuilt", spec: main };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const { versionLock, skipVersion } = block.settings;
|
|
200
|
+
return {
|
|
201
|
+
blockId: asBlockId(block.id),
|
|
202
|
+
label: block.title ?? block.label,
|
|
203
|
+
...(block.currentBlockPack !== undefined
|
|
204
|
+
? { current: packSource(block.currentBlockPack) }
|
|
205
|
+
: {}),
|
|
206
|
+
...(recommended !== undefined ? { recommended } : {}),
|
|
207
|
+
available,
|
|
208
|
+
...(versionLock !== undefined ? { versionLock } : {}),
|
|
209
|
+
...(skipVersion !== undefined ? { skipVersion } : {}),
|
|
210
|
+
...(block.isIncompatibleWithRuntime === true ? { incompatible: true } : {}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Whether the block has anything to update to. */
|
|
215
|
+
function hasUpdate(updates: BlockUpdates): boolean {
|
|
216
|
+
return updates.recommended !== undefined || updates.available.length > 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The input of list_block_updates. */
|
|
220
|
+
export type ListBlockUpdatesInput = {
|
|
221
|
+
projectId: ProjectId;
|
|
222
|
+
blockIds?: BlockId[];
|
|
223
|
+
all?: boolean;
|
|
224
|
+
limit?: number;
|
|
225
|
+
offset?: number;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The blocks of a project with their updates, filtered and paged (list_block_updates). Waits for
|
|
230
|
+
* the application's update check first (at most `updateCheckMs`); when it is not in, the answer
|
|
231
|
+
* says so (`updateCheck: "pending"`) rather than showing no updates.
|
|
232
|
+
*/
|
|
233
|
+
export async function listBlockUpdates(
|
|
234
|
+
project: UpdatesProject,
|
|
235
|
+
input: ListBlockUpdatesInput,
|
|
236
|
+
options: { updateCheckMs?: number; signal?: AbortSignal } = {},
|
|
237
|
+
) {
|
|
238
|
+
const { overview, checked } = await overviewWithUpdates(
|
|
239
|
+
project,
|
|
240
|
+
options.updateCheckMs ?? UPDATE_CHECK_WAIT_MS,
|
|
241
|
+
options.signal,
|
|
242
|
+
);
|
|
243
|
+
if (overview === undefined) return errorResult("Project overview not available yet. Try again.");
|
|
244
|
+
const wanted = input.blockIds === undefined ? undefined : new Set<string>(input.blockIds);
|
|
245
|
+
const known = new Set(overview.blocks.map((b) => b.id));
|
|
246
|
+
const notFound = (input.blockIds ?? []).filter((id) => !known.has(id));
|
|
247
|
+
const selected = overview.blocks
|
|
248
|
+
.filter((b) => wanted === undefined || wanted.has(b.id))
|
|
249
|
+
.map(blockUpdatesOf)
|
|
250
|
+
.filter((u) => input.all === true || hasUpdate(u));
|
|
251
|
+
const { items, ...paging } = page(
|
|
252
|
+
selected,
|
|
253
|
+
input.offset,
|
|
254
|
+
input.limit ?? BLOCK_UPDATES_DEFAULT_LIMIT,
|
|
255
|
+
);
|
|
256
|
+
return textResult(
|
|
257
|
+
{
|
|
258
|
+
blocks: items,
|
|
259
|
+
...paging,
|
|
260
|
+
...(notFound.length > 0 ? { notFound } : {}),
|
|
261
|
+
...(checked ? {} : { updateCheck: "pending", note: UPDATE_CHECK_PENDING_NOTE }),
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
hint:
|
|
265
|
+
"Ask for fewer blocks: a smaller `limit` with `offset` to page, or `blockIds` for the " +
|
|
266
|
+
"blocks you need.",
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The pack spec an update target names explicitly. */
|
|
272
|
+
export type UpdateSpec = z.infer<typeof updateBlockSpecInput>;
|
|
273
|
+
|
|
274
|
+
/** What a block is updated to: the recommended update, the newest of a release line, or a pack. */
|
|
275
|
+
export type UpdateTarget = "recommended" | UpdateLevel | UpdateSpec;
|
|
276
|
+
|
|
277
|
+
/** How the update of one block ended. */
|
|
278
|
+
export type UpdateStatus = "done" | "failed" | "skipped" | "unchanged";
|
|
279
|
+
|
|
280
|
+
/** The outcome of one block of update_blocks. */
|
|
281
|
+
export type BlockUpdateOutcome = {
|
|
282
|
+
blockId: BlockId;
|
|
283
|
+
label: string | undefined;
|
|
284
|
+
from?: PackSource;
|
|
285
|
+
to?: PackSource;
|
|
286
|
+
status: UpdateStatus;
|
|
287
|
+
reason?: string;
|
|
288
|
+
/** The block's readiness after the update: a new version may need its data changed. */
|
|
289
|
+
readiness?: Readiness;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* An updated block's readiness as the answer of update_blocks gives it: its status and at most
|
|
294
|
+
* {@link UPDATE_READINESS_BLOCKERS} blockers, or only its status in an answer cut to size.
|
|
295
|
+
* get_block_state gives it in full.
|
|
296
|
+
*/
|
|
297
|
+
export type ReadinessSummary = {
|
|
298
|
+
status: BlockStatus;
|
|
299
|
+
blockers?: ReadinessBlocker[];
|
|
300
|
+
/** How many blockers were left out. */
|
|
301
|
+
moreBlockers?: number;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/** One block in the answer of update_blocks: its outcome with every text cut to a bound. */
|
|
305
|
+
export type BlockUpdateEntry = Omit<BlockUpdateOutcome, "readiness"> & {
|
|
306
|
+
readiness?: ReadinessSummary;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
/** The input of update_blocks. */
|
|
310
|
+
export type UpdateBlocksInput = {
|
|
311
|
+
projectId: ProjectId;
|
|
312
|
+
updates?: { blockId: BlockId; to: UpdateTarget }[];
|
|
313
|
+
all?: "recommended";
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/** What update_blocks needs of a project; a middle-layer `Project` has it. */
|
|
317
|
+
export type UpdateBlocksProject = UpdatesProject & BlockPackProject & ReadinessProject;
|
|
318
|
+
|
|
319
|
+
/** How update_blocks runs. */
|
|
320
|
+
export type UpdateBlocksOptions = {
|
|
321
|
+
/** The marker of the next write; one per block updated. */
|
|
322
|
+
author: () => AuthorMarker;
|
|
323
|
+
/**
|
|
324
|
+
* No block starts updating after this long, a block waiting for an earlier change of it
|
|
325
|
+
* included; the one under way finishes.
|
|
326
|
+
*/
|
|
327
|
+
timeoutMs: number;
|
|
328
|
+
/** The call was cancelled: no block starts updating after it, a waiting one included. */
|
|
329
|
+
signal?: AbortSignal;
|
|
330
|
+
/** Called after each block with how many of the `total` blocks are over. */
|
|
331
|
+
onProgress?: (done: number, total: number, message: string) => void;
|
|
332
|
+
/**
|
|
333
|
+
* The longest wait for the application's update check (default {@link UPDATE_CHECK_WAIT_MS},
|
|
334
|
+
* never past `timeoutMs`).
|
|
335
|
+
*/
|
|
336
|
+
updateCheckMs?: number;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
/** One block of the plan of update_blocks. */
|
|
340
|
+
type PlannedUpdate = {
|
|
341
|
+
outcome: BlockUpdateOutcome;
|
|
342
|
+
/** The pack to move to; `undefined` once the outcome is decided without an update. */
|
|
343
|
+
spec?: BlockPackSpecAny;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/** Why update_blocks stopped starting blocks. */
|
|
347
|
+
type StopReason = "timeout" | "aborted";
|
|
348
|
+
|
|
349
|
+
/** Thrown in a block's turn (see {@link applyBlockPack}) when the call stopped while the block waited. */
|
|
350
|
+
class StoppedWhileWaiting extends Error {
|
|
351
|
+
constructor(readonly stoppedBy: StopReason) {
|
|
352
|
+
super(`update_blocks stopped (${stoppedBy}) before the block's turn`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Updates blocks of a project, one at a time, top to bottom, each through {@link applyBlockPack}.
|
|
358
|
+
* Each target is resolved from the project overview first, once the application's update check
|
|
359
|
+
* is in (see {@link overviewWithUpdates}); a target the block does not have fails that block
|
|
360
|
+
* only. While the update check is not in, `all: "recommended"` changes
|
|
361
|
+
* nothing and says so, and a block named with `recommended` or a release line is skipped. Stops
|
|
362
|
+
* starting blocks on `signal` or after `timeoutMs`, checked again when a block's turn
|
|
363
|
+
* starts: the blocks still waiting are `skipped`. Runs nothing.
|
|
364
|
+
*/
|
|
365
|
+
export async function updateBlocks(
|
|
366
|
+
project: UpdateBlocksProject,
|
|
367
|
+
input: UpdateBlocksInput,
|
|
368
|
+
options: UpdateBlocksOptions,
|
|
369
|
+
) {
|
|
370
|
+
const start = Date.now();
|
|
371
|
+
const { projectId, updates, all } = input;
|
|
372
|
+
if ((updates === undefined) === (all === undefined))
|
|
373
|
+
return errorResult(
|
|
374
|
+
"Give either `updates` or `all`, not both and not neither. Nothing was changed.",
|
|
375
|
+
'updates: [{ blockId, to }] names the blocks; all: "recommended" takes every block with ' +
|
|
376
|
+
"a recommended update.",
|
|
377
|
+
);
|
|
378
|
+
if (updates !== undefined) {
|
|
379
|
+
if (updates.length === 0)
|
|
380
|
+
return errorResult("`updates` is empty. Nothing was changed.", "Name at least one block.");
|
|
381
|
+
const seen = new Set<string>();
|
|
382
|
+
for (const { blockId } of updates) {
|
|
383
|
+
if (seen.has(blockId))
|
|
384
|
+
return errorResult(
|
|
385
|
+
`Block ${blockId} is named twice in \`updates\`. Nothing was changed.`,
|
|
386
|
+
"Name each block once, with the one version to update it to.",
|
|
387
|
+
);
|
|
388
|
+
seen.add(blockId);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const { overview, checked } = await overviewWithUpdates(
|
|
393
|
+
project,
|
|
394
|
+
Math.min(options.updateCheckMs ?? UPDATE_CHECK_WAIT_MS, options.timeoutMs),
|
|
395
|
+
options.signal,
|
|
396
|
+
);
|
|
397
|
+
if (overview === undefined) return errorResult("Project overview not available yet. Try again.");
|
|
398
|
+
const known = new Set(overview.blocks.map((b) => b.id));
|
|
399
|
+
const unknown = updates?.find((u) => !known.has(u.blockId));
|
|
400
|
+
if (unknown !== undefined) return unknownBlockResult(projectId, unknown.blockId, true);
|
|
401
|
+
if (!checked && all !== undefined)
|
|
402
|
+
return errorResult(
|
|
403
|
+
"The application's check of the registries for updates has not finished, so which " +
|
|
404
|
+
"blocks have a recommended update is not known yet. Nothing was changed.",
|
|
405
|
+
'Call update_blocks with all: "recommended" again in a moment.',
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
const targets = new Map<string, UpdateTarget>(
|
|
409
|
+
updates !== undefined
|
|
410
|
+
? updates.map((u) => [u.blockId, u.to])
|
|
411
|
+
: overview.blocks.filter(isInUpdateAll).map((b) => [b.id, "recommended"]),
|
|
412
|
+
);
|
|
413
|
+
// Top to bottom, whatever order the caller named the blocks in.
|
|
414
|
+
const plan = overview.blocks.flatMap((b): PlannedUpdate[] => {
|
|
415
|
+
const to = targets.get(b.id);
|
|
416
|
+
if (to === undefined) return [];
|
|
417
|
+
return [!checked && typeof to === "string" ? checkPending(b) : planUpdate(b, to)];
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
const total = plan.length;
|
|
421
|
+
let over = 0;
|
|
422
|
+
const report = (message: string) => options.onProgress?.(++over, total, message);
|
|
423
|
+
const stopNow = (): StopReason | undefined =>
|
|
424
|
+
options.signal?.aborted
|
|
425
|
+
? "aborted"
|
|
426
|
+
: Date.now() - start >= options.timeoutMs
|
|
427
|
+
? "timeout"
|
|
428
|
+
: undefined;
|
|
429
|
+
let stoppedBy: StopReason | undefined;
|
|
430
|
+
for (const step of plan) {
|
|
431
|
+
const { outcome, spec } = step;
|
|
432
|
+
if (spec === undefined) {
|
|
433
|
+
report(`${nameOf(outcome)}: ${outcome.status}`);
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
stoppedBy ??= stopNow();
|
|
437
|
+
if (stoppedBy !== undefined) {
|
|
438
|
+
outcome.status = "skipped";
|
|
439
|
+
outcome.reason =
|
|
440
|
+
stoppedBy === "aborted"
|
|
441
|
+
? "The call was cancelled before this block's turn."
|
|
442
|
+
: "The time ran out before this block's turn; call update_blocks again for it.";
|
|
443
|
+
report(`${nameOf(outcome)}: skipped`);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
const refused = await applyBlockPack(project, outcome.blockId, spec, {
|
|
448
|
+
resetArgs: false,
|
|
449
|
+
author: options.author(),
|
|
450
|
+
// The block may have waited behind an earlier change of it: check again at its turn.
|
|
451
|
+
beforeWrite: () => {
|
|
452
|
+
const stop = stopNow();
|
|
453
|
+
if (stop !== undefined) throw new StoppedWhileWaiting(stop);
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
if (refused !== undefined) {
|
|
457
|
+
outcome.status = "failed";
|
|
458
|
+
outcome.reason = refused.content[0].text;
|
|
459
|
+
} else {
|
|
460
|
+
outcome.status = "done";
|
|
461
|
+
}
|
|
462
|
+
} catch (e: unknown) {
|
|
463
|
+
if (e instanceof StoppedWhileWaiting) {
|
|
464
|
+
stoppedBy = e.stoppedBy;
|
|
465
|
+
outcome.status = "skipped";
|
|
466
|
+
outcome.reason =
|
|
467
|
+
stoppedBy === "aborted"
|
|
468
|
+
? "The call was cancelled while this block waited for an earlier change of it; " +
|
|
469
|
+
"it was not updated."
|
|
470
|
+
: "The time ran out while this block waited for an earlier change of it; it was " +
|
|
471
|
+
"not updated. Call update_blocks again for it.";
|
|
472
|
+
} else {
|
|
473
|
+
outcome.status = "failed";
|
|
474
|
+
outcome.reason = `The block was not updated: ${e instanceof Error ? e.message : String(e)}`;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (outcome.status === "done") {
|
|
478
|
+
// The block is updated by now: a failure to read it afterwards only leaves the readiness out.
|
|
479
|
+
const readiness = await readinessOf(project, outcome.blockId).catch(() => undefined);
|
|
480
|
+
if (readiness !== undefined) outcome.readiness = readiness;
|
|
481
|
+
}
|
|
482
|
+
report(`${nameOf(outcome)}: ${outcome.status}`);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const outcomes = plan.map((s) => s.outcome);
|
|
486
|
+
const count = (status: UpdateStatus) => outcomes.filter((o) => o.status === status).length;
|
|
487
|
+
return textResult(
|
|
488
|
+
{
|
|
489
|
+
blocks: outcomes.map(entryOf),
|
|
490
|
+
done: count("done"),
|
|
491
|
+
failed: count("failed"),
|
|
492
|
+
skipped: count("skipped"),
|
|
493
|
+
unchanged: count("unchanged"),
|
|
494
|
+
...(stoppedBy !== undefined ? { stoppedBy } : {}),
|
|
495
|
+
...(outcomes.length === 0
|
|
496
|
+
? { note: "No block of the project has a recommended update." }
|
|
497
|
+
: {}),
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
hint:
|
|
501
|
+
"The updates were applied as far as they went; list_block_updates and get_block_state " +
|
|
502
|
+
"show the current state of each block.",
|
|
503
|
+
},
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** One outcome with its texts cut and its readiness summed up. */
|
|
508
|
+
function entryOf(outcome: BlockUpdateOutcome): BlockUpdateEntry {
|
|
509
|
+
const { readiness, label, from, to, reason, ...rest } = outcome;
|
|
510
|
+
return {
|
|
511
|
+
...rest,
|
|
512
|
+
label: label === undefined ? undefined : clip(label, UPDATE_LABEL_CHARS),
|
|
513
|
+
...(from !== undefined ? { from: clipSource(from) } : {}),
|
|
514
|
+
...(to !== undefined ? { to: clipSource(to) } : {}),
|
|
515
|
+
...(reason !== undefined ? { reason: clip(reason, UPDATE_REASON_CHARS) } : {}),
|
|
516
|
+
...(readiness !== undefined ? { readiness: summaryOf(readiness) } : {}),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function summaryOf(readiness: Readiness): ReadinessSummary {
|
|
521
|
+
const blockers = readiness.blockers
|
|
522
|
+
.slice(0, UPDATE_READINESS_BLOCKERS)
|
|
523
|
+
.map((b) => ({ ...b, message: clip(b.message, UPDATE_BLOCKER_CHARS) }));
|
|
524
|
+
const more = readiness.blockers.length - blockers.length;
|
|
525
|
+
return { status: readiness.status, blockers, ...(more > 0 ? { moreBlockers: more } : {}) };
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function clipSource(source: PackSource): PackSource {
|
|
529
|
+
switch (source.source) {
|
|
530
|
+
case "registry":
|
|
531
|
+
return { ...source, registry: clip(source.registry, UPDATE_SOURCE_CHARS) };
|
|
532
|
+
case "dev":
|
|
533
|
+
return { ...source, folder: clip(source.folder, UPDATE_SOURCE_CHARS) };
|
|
534
|
+
case "pack":
|
|
535
|
+
return { ...source, packUrl: clip(source.packUrl, UPDATE_SOURCE_CHARS) };
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function nameOf(outcome: BlockUpdateOutcome): string {
|
|
540
|
+
return outcome.label === undefined ? outcome.blockId : `"${outcome.label}" (${outcome.blockId})`;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Whether `all: "recommended"` takes the block, as the application's "Update All" does: a
|
|
545
|
+
* recommended update from a registry (a new release) of a block that works with this
|
|
546
|
+
* application. A dev block or a block from a local pack is offered its rebuild, not a release,
|
|
547
|
+
* and is left out. A version lock or a skipped version already leaves the recommendation out.
|
|
548
|
+
*/
|
|
549
|
+
function isInUpdateAll(block: UpdatesOverviewBlock): boolean {
|
|
550
|
+
const type = block.updatedBlockPack?.type;
|
|
551
|
+
return (
|
|
552
|
+
(type === "from-registry-v1" || type === "from-registry-v2") &&
|
|
553
|
+
block.isIncompatibleWithRuntime !== true
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** A block whose target needs the update check, which is not in: skipped. */
|
|
558
|
+
function checkPending(block: UpdatesOverviewBlock): PlannedUpdate {
|
|
559
|
+
const updates = blockUpdatesOf(block);
|
|
560
|
+
return {
|
|
561
|
+
outcome: {
|
|
562
|
+
blockId: updates.blockId,
|
|
563
|
+
label: updates.label,
|
|
564
|
+
...(updates.current !== undefined ? { from: updates.current } : {}),
|
|
565
|
+
status: "skipped",
|
|
566
|
+
reason:
|
|
567
|
+
"The application's check of the registries for updates has not finished; call " +
|
|
568
|
+
"update_blocks again for this block in a moment.",
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Resolves what one block is updated to, from its overview entry.
|
|
575
|
+
*/
|
|
576
|
+
function planUpdate(block: UpdatesOverviewBlock, to: UpdateTarget): PlannedUpdate {
|
|
577
|
+
const updates = blockUpdatesOf(block);
|
|
578
|
+
const outcome: BlockUpdateOutcome = {
|
|
579
|
+
blockId: updates.blockId,
|
|
580
|
+
label: updates.label,
|
|
581
|
+
...(updates.current !== undefined ? { from: updates.current } : {}),
|
|
582
|
+
status: "skipped",
|
|
583
|
+
};
|
|
584
|
+
const offered = () =>
|
|
585
|
+
updates.available.length === 0
|
|
586
|
+
? "The registry offers no update for it."
|
|
587
|
+
: `Available: ${updates.available.map((c) => `${c.level} ${c.version}`).join(", ")}.`;
|
|
588
|
+
|
|
589
|
+
let spec: BlockPackSpecAny;
|
|
590
|
+
if (to === "recommended") {
|
|
591
|
+
if (updates.recommended === undefined) {
|
|
592
|
+
outcome.status = "unchanged";
|
|
593
|
+
outcome.reason =
|
|
594
|
+
"The block has no recommended update" +
|
|
595
|
+
(updates.versionLock !== undefined ? ` (its versionLock is ${updates.versionLock})` : "") +
|
|
596
|
+
`. ${offered()}`;
|
|
597
|
+
return { outcome };
|
|
598
|
+
}
|
|
599
|
+
spec = updates.recommended.spec;
|
|
600
|
+
} else if (typeof to === "string") {
|
|
601
|
+
const candidate = updates.available.find((c) => c.level === to);
|
|
602
|
+
if (candidate === undefined) {
|
|
603
|
+
outcome.status = "failed";
|
|
604
|
+
outcome.reason = `No ${to} update is available for this block. ${offered()}`;
|
|
605
|
+
return { outcome };
|
|
606
|
+
}
|
|
607
|
+
spec = candidate.spec;
|
|
608
|
+
} else {
|
|
609
|
+
spec = to;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const target = packSource(spec);
|
|
613
|
+
outcome.to = target;
|
|
614
|
+
if (isSameRegistryPack(block.currentBlockPack, spec)) {
|
|
615
|
+
outcome.status = "unchanged";
|
|
616
|
+
outcome.reason = "The block is already on this version.";
|
|
617
|
+
return { outcome };
|
|
618
|
+
}
|
|
619
|
+
return { outcome, spec };
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Whether two specs name the same version of the same registry block. */
|
|
623
|
+
function isSameRegistryPack(current: BlockPackSpec | undefined, target: BlockPackSpecAny): boolean {
|
|
624
|
+
if (current?.type !== "from-registry-v2" || target.type !== "from-registry-v2") return false;
|
|
625
|
+
return (
|
|
626
|
+
current.registryUrl === target.registryUrl &&
|
|
627
|
+
current.id.organization === target.id.organization &&
|
|
628
|
+
current.id.name === target.id.name &&
|
|
629
|
+
current.id.version === target.id.version
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export const updateTargetInput = z.union([
|
|
634
|
+
z.enum(["recommended", "patch", "minor", "major"]),
|
|
635
|
+
updateBlockSpecInput,
|
|
636
|
+
]);
|
|
637
|
+
|
|
638
|
+
export function registerBlockUpdateTools(server: ToolRegistrar, ctx: ToolContext): void {
|
|
639
|
+
server.registerTool(
|
|
640
|
+
"list_block_updates",
|
|
641
|
+
{
|
|
642
|
+
title: "List Block Updates",
|
|
643
|
+
annotations: hints.read,
|
|
644
|
+
description:
|
|
645
|
+
"List the updates of a project's blocks, to upgrade a project. Per block: `current` " +
|
|
646
|
+
"(where its pack comes from: registry and version, or a local folder), `available` " +
|
|
647
|
+
"(every update its registry offers: the newest patch, minor and major version, each " +
|
|
648
|
+
"with the `spec` update_block takes) and `recommended` (the update the application " +
|
|
649
|
+
"suggests: the newest the block's `versionLock` allows, unless the user skipped it; " +
|
|
650
|
+
'`level: "rebuilt"` for a block from a local folder that holds a newer build). ' +
|
|
651
|
+
"`incompatible: true`: the block's current version does not work with this application. " +
|
|
652
|
+
"Facts only: nothing is changed and no block is downloaded.\n\n" +
|
|
653
|
+
"By default only blocks with an update are listed; `all: true` lists every block. " +
|
|
654
|
+
"update_blocks applies updates to a project's blocks; update_block moves one block to " +
|
|
655
|
+
"a given pack (a dev block after a rebuild, too).\n\n" +
|
|
656
|
+
"The application checks the registries in the background; the call waits for that " +
|
|
657
|
+
'check, and when it is not in yet says so with `updateCheck: "pending"` and a `note`: ' +
|
|
658
|
+
"some updates may not be shown yet, call again.\n\n" +
|
|
659
|
+
"Result: `{ blocks, total, offset, hasMore, notFound?, updateCheck?, note? }`, blocks " +
|
|
660
|
+
"in project order.",
|
|
661
|
+
inputSchema: z.object({
|
|
662
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
663
|
+
blockIds: z
|
|
664
|
+
.array(blockIdInput)
|
|
665
|
+
.optional()
|
|
666
|
+
.describe("Only these blocks; `notFound` lists the ids the project lacks."),
|
|
667
|
+
all: z
|
|
668
|
+
.boolean()
|
|
669
|
+
.optional()
|
|
670
|
+
.describe("Also list blocks with nothing to update (default false)."),
|
|
671
|
+
...pagingArgs("blocks", BLOCK_UPDATES_DEFAULT_LIMIT, BLOCK_UPDATES_MAX_LIMIT),
|
|
672
|
+
}),
|
|
673
|
+
},
|
|
674
|
+
async (input, call) => {
|
|
675
|
+
return await ctx.withProject(input.projectId, (project) =>
|
|
676
|
+
listBlockUpdates(project, input, { signal: call.mcpReq.signal }),
|
|
677
|
+
);
|
|
678
|
+
},
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
server.registerTool(
|
|
682
|
+
"update_blocks",
|
|
683
|
+
{
|
|
684
|
+
title: "Update Blocks",
|
|
685
|
+
annotations: { ...hints.destructive, idempotentHint: false },
|
|
686
|
+
description:
|
|
687
|
+
"Upgrade blocks of a project to newer versions. `updates` names the blocks and what " +
|
|
688
|
+
"to move each to: `recommended`, the newest `patch`, `minor` or `major` version " +
|
|
689
|
+
'(list_block_updates shows them), or a block pack spec; or `all: "recommended"` takes ' +
|
|
690
|
+
"every block with a recommended registry update, as the application's Update All: not " +
|
|
691
|
+
"dev blocks, blocks from a local pack, or incompatible blocks. Blocks are updated one at a " +
|
|
692
|
+
"time, top to bottom, the same way update_block updates one; their data is kept and " +
|
|
693
|
+
"migrated by the new version. A block whose target is not available or whose new pack " +
|
|
694
|
+
"is refused (it needs a newer application, or is on block API 1) fails with the reason " +
|
|
695
|
+
"and is left as it was; the others go on.\n\n" +
|
|
696
|
+
"Updates run nothing: results of the old version stay until the block runs again. " +
|
|
697
|
+
"Each updated block comes back with its readiness: a new version may need data " +
|
|
698
|
+
"changes, and the readiness says what to fix (set_block_params, set_block_data) before " +
|
|
699
|
+
"run_block. The application's open views of an updated block reload.\n\n" +
|
|
700
|
+
`The call stops at \`timeout\` (default ${AWAIT_DEFAULT_MS} ms, at most ${AWAIT_MAX_MS}) ` +
|
|
701
|
+
"or when cancelled: the block being updated finishes, the blocks still waiting are " +
|
|
702
|
+
"`skipped`; call again for them. The call first waits for the application's check of " +
|
|
703
|
+
'the registries; when it is not in yet, all: "recommended" changes nothing and says so, ' +
|
|
704
|
+
"and blocks named with `recommended` or a release line are `skipped`. Progress " +
|
|
705
|
+
"notifications count the blocks.\n\n" +
|
|
706
|
+
"Result: `{ blocks: [{ blockId, label, from, to, status, reason?, readiness? }], done, " +
|
|
707
|
+
"failed, skipped, unchanged, stoppedBy?, note? }`; status is done, failed, " +
|
|
708
|
+
"skipped or unchanged (already on that version, or nothing recommended). Labels and " +
|
|
709
|
+
"reasons are cut short; `readiness` is the status and at most " +
|
|
710
|
+
`${UPDATE_READINESS_BLOCKERS} blockers (get_block_state gives it in full).`,
|
|
711
|
+
inputSchema: z.object({
|
|
712
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
713
|
+
updates: z
|
|
714
|
+
.array(
|
|
715
|
+
z.object({
|
|
716
|
+
blockId: blockIdInput.describe("Block ID"),
|
|
717
|
+
to: updateTargetInput.describe(
|
|
718
|
+
'What to update to: "recommended", "patch", "minor", "major", or a block pack spec.',
|
|
719
|
+
),
|
|
720
|
+
}),
|
|
721
|
+
)
|
|
722
|
+
.optional()
|
|
723
|
+
.describe("The blocks to update, each once. Give this or `all`."),
|
|
724
|
+
all: z
|
|
725
|
+
.literal("recommended")
|
|
726
|
+
.optional()
|
|
727
|
+
.describe(
|
|
728
|
+
"Update every block with a recommended registry update, as Update All does. Give " +
|
|
729
|
+
"this or `updates`.",
|
|
730
|
+
),
|
|
731
|
+
timeout: z
|
|
732
|
+
.number()
|
|
733
|
+
.optional()
|
|
734
|
+
.describe(
|
|
735
|
+
`No block starts updating after this many ms (default ${AWAIT_DEFAULT_MS}, at most ` +
|
|
736
|
+
`${AWAIT_MAX_MS}).`,
|
|
737
|
+
),
|
|
738
|
+
}),
|
|
739
|
+
},
|
|
740
|
+
async ({ timeout, ...input }, call) => {
|
|
741
|
+
return await ctx.withProject(input.projectId, (project) =>
|
|
742
|
+
updateBlocks(project, input, {
|
|
743
|
+
author: ctx.getAuthorMarker,
|
|
744
|
+
timeoutMs: clampWait(timeout, AWAIT_DEFAULT_MS, AWAIT_MIN_MS, AWAIT_MAX_MS),
|
|
745
|
+
signal: call.mcpReq.signal,
|
|
746
|
+
onProgress: progressReporter(call, "Updating blocks", 1),
|
|
747
|
+
}),
|
|
748
|
+
);
|
|
749
|
+
},
|
|
750
|
+
);
|
|
751
|
+
}
|