@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.
Files changed (208) hide show
  1. package/README.md +30 -37
  2. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  3. package/dist/agent-tables.cjs +116 -0
  4. package/dist/agent-tables.cjs.map +1 -0
  5. package/dist/agent-tables.js +115 -0
  6. package/dist/agent-tables.js.map +1 -0
  7. package/dist/instructions.cjs +16 -12
  8. package/dist/instructions.cjs.map +1 -1
  9. package/dist/instructions.js +16 -12
  10. package/dist/instructions.js.map +1 -1
  11. package/dist/package.cjs +1 -1
  12. package/dist/package.js +1 -1
  13. package/dist/project-holds.cjs +122 -0
  14. package/dist/project-holds.cjs.map +1 -0
  15. package/dist/project-holds.js +122 -0
  16. package/dist/project-holds.js.map +1 -0
  17. package/dist/project-list.cjs +16 -0
  18. package/dist/project-list.cjs.map +1 -0
  19. package/dist/project-list.js +16 -0
  20. package/dist/project-list.js.map +1 -0
  21. package/dist/server-log.cjs +48 -18
  22. package/dist/server-log.cjs.map +1 -1
  23. package/dist/server-log.js +48 -19
  24. package/dist/server-log.js.map +1 -1
  25. package/dist/server.cjs +71 -18
  26. package/dist/server.cjs.map +1 -1
  27. package/dist/server.d.ts +37 -24
  28. package/dist/server.d.ts.map +1 -1
  29. package/dist/server.js +71 -19
  30. package/dist/server.js.map +1 -1
  31. package/dist/tools/agent-tables.cjs +424 -0
  32. package/dist/tools/agent-tables.cjs.map +1 -0
  33. package/dist/tools/agent-tables.js +417 -0
  34. package/dist/tools/agent-tables.js.map +1 -0
  35. package/dist/tools/await.cjs +216 -72
  36. package/dist/tools/await.cjs.map +1 -1
  37. package/dist/tools/await.js +212 -74
  38. package/dist/tools/await.js.map +1 -1
  39. package/dist/tools/block-action-context.cjs +14 -9
  40. package/dist/tools/block-action-context.cjs.map +1 -1
  41. package/dist/tools/block-action-context.js +14 -9
  42. package/dist/tools/block-action-context.js.map +1 -1
  43. package/dist/tools/block-api.cjs +17 -2
  44. package/dist/tools/block-api.cjs.map +1 -1
  45. package/dist/tools/block-api.js +17 -3
  46. package/dist/tools/block-api.js.map +1 -1
  47. package/dist/tools/block-params.cjs +275 -6
  48. package/dist/tools/block-params.cjs.map +1 -1
  49. package/dist/tools/block-params.js +273 -8
  50. package/dist/tools/block-params.js.map +1 -1
  51. package/dist/tools/block-state.cjs +343 -57
  52. package/dist/tools/block-state.cjs.map +1 -1
  53. package/dist/tools/block-state.js +337 -61
  54. package/dist/tools/block-state.js.map +1 -1
  55. package/dist/tools/block-storage.cjs +153 -0
  56. package/dist/tools/block-storage.cjs.map +1 -0
  57. package/dist/tools/block-storage.js +147 -0
  58. package/dist/tools/block-storage.js.map +1 -0
  59. package/dist/tools/block-updates.cjs +405 -0
  60. package/dist/tools/block-updates.cjs.map +1 -0
  61. package/dist/tools/block-updates.js +397 -0
  62. package/dist/tools/block-updates.js.map +1 -0
  63. package/dist/tools/blocks.cjs +199 -76
  64. package/dist/tools/blocks.cjs.map +1 -1
  65. package/dist/tools/blocks.js +193 -76
  66. package/dist/tools/blocks.js.map +1 -1
  67. package/dist/tools/data-query.cjs +470 -101
  68. package/dist/tools/data-query.cjs.map +1 -1
  69. package/dist/tools/data-query.js +465 -106
  70. package/dist/tools/data-query.js.map +1 -1
  71. package/dist/tools/errors.cjs +21 -0
  72. package/dist/tools/errors.cjs.map +1 -0
  73. package/dist/tools/errors.js +20 -0
  74. package/dist/tools/errors.js.map +1 -0
  75. package/dist/tools/files.cjs +643 -0
  76. package/dist/tools/files.cjs.map +1 -0
  77. package/dist/tools/files.js +613 -0
  78. package/dist/tools/files.js.map +1 -0
  79. package/dist/tools/ids.cjs +72 -0
  80. package/dist/tools/ids.cjs.map +1 -1
  81. package/dist/tools/ids.js +63 -2
  82. package/dist/tools/ids.js.map +1 -1
  83. package/dist/tools/imports.cjs +195 -0
  84. package/dist/tools/imports.cjs.map +1 -0
  85. package/dist/tools/imports.js +186 -0
  86. package/dist/tools/imports.js.map +1 -0
  87. package/dist/tools/logs.cjs +111 -30
  88. package/dist/tools/logs.cjs.map +1 -1
  89. package/dist/tools/logs.js +108 -31
  90. package/dist/tools/logs.js.map +1 -1
  91. package/dist/tools/paging.cjs +27 -0
  92. package/dist/tools/paging.cjs.map +1 -0
  93. package/dist/tools/paging.js +26 -0
  94. package/dist/tools/paging.js.map +1 -0
  95. package/dist/tools/params-merge.cjs +106 -0
  96. package/dist/tools/params-merge.cjs.map +1 -0
  97. package/dist/tools/params-merge.js +106 -0
  98. package/dist/tools/params-merge.js.map +1 -0
  99. package/dist/tools/project-template.cjs +75 -0
  100. package/dist/tools/project-template.cjs.map +1 -0
  101. package/dist/tools/project-template.js +72 -0
  102. package/dist/tools/project-template.js.map +1 -0
  103. package/dist/tools/projects.cjs +68 -38
  104. package/dist/tools/projects.cjs.map +1 -1
  105. package/dist/tools/projects.js +69 -40
  106. package/dist/tools/projects.js.map +1 -1
  107. package/dist/tools/readiness.cjs +104 -0
  108. package/dist/tools/readiness.cjs.map +1 -0
  109. package/dist/tools/readiness.js +99 -0
  110. package/dist/tools/readiness.js.map +1 -0
  111. package/dist/tools/result-pool.cjs +260 -0
  112. package/dist/tools/result-pool.cjs.map +1 -0
  113. package/dist/tools/result-pool.js +252 -0
  114. package/dist/tools/result-pool.js.map +1 -0
  115. package/dist/tools/sandbox.cjs +112 -14
  116. package/dist/tools/sandbox.cjs.map +1 -1
  117. package/dist/tools/sandbox.js +110 -15
  118. package/dist/tools/sandbox.js.map +1 -1
  119. package/dist/tools/sdk-types.cjs +24 -0
  120. package/dist/tools/sdk-types.cjs.map +1 -0
  121. package/dist/tools/sdk-types.js +24 -0
  122. package/dist/tools/sdk-types.js.map +1 -0
  123. package/dist/tools/settle.cjs +155 -0
  124. package/dist/tools/settle.cjs.map +1 -0
  125. package/dist/tools/settle.js +148 -0
  126. package/dist/tools/settle.js.map +1 -0
  127. package/dist/tools/tokens.cjs +49 -8
  128. package/dist/tools/tokens.cjs.map +1 -1
  129. package/dist/tools/tokens.js +45 -9
  130. package/dist/tools/tokens.js.map +1 -1
  131. package/dist/tools/types.cjs +62 -11
  132. package/dist/tools/types.cjs.map +1 -1
  133. package/dist/tools/types.js +60 -12
  134. package/dist/tools/types.js.map +1 -1
  135. package/dist/tools/value-outline.cjs +119 -0
  136. package/dist/tools/value-outline.cjs.map +1 -0
  137. package/dist/tools/value-outline.js +117 -0
  138. package/dist/tools/value-outline.js.map +1 -0
  139. package/package.json +9 -8
  140. package/src/agent-tables.test.ts +246 -0
  141. package/src/agent-tables.ts +145 -0
  142. package/src/instructions.ts +16 -12
  143. package/src/project-holds.test.ts +362 -0
  144. package/src/project-holds.ts +207 -0
  145. package/src/project-list.test.ts +38 -0
  146. package/src/project-list.ts +25 -0
  147. package/src/server-log.test.ts +71 -6
  148. package/src/server-log.ts +58 -27
  149. package/src/server.logging.test.ts +46 -51
  150. package/src/server.test.ts +166 -22
  151. package/src/server.ts +97 -37
  152. package/src/tools/agent-tables.test.ts +650 -0
  153. package/src/tools/agent-tables.ts +673 -0
  154. package/src/tools/await.test.ts +287 -0
  155. package/src/tools/await.ts +393 -122
  156. package/src/tools/block-action-context.ts +17 -13
  157. package/src/tools/block-api.ts +19 -4
  158. package/src/tools/block-params.test.ts +828 -0
  159. package/src/tools/block-params.ts +626 -10
  160. package/src/tools/block-state.test.ts +480 -0
  161. package/src/tools/block-state.ts +678 -83
  162. package/src/tools/block-storage.test.ts +270 -0
  163. package/src/tools/block-storage.ts +195 -0
  164. package/src/tools/block-updates.test.ts +605 -0
  165. package/src/tools/block-updates.ts +751 -0
  166. package/src/tools/blocks.test.ts +169 -22
  167. package/src/tools/blocks.ts +354 -113
  168. package/src/tools/data-query.test.ts +641 -0
  169. package/src/tools/data-query.ts +839 -145
  170. package/src/tools/errors.test.ts +33 -0
  171. package/src/tools/errors.ts +23 -0
  172. package/src/tools/files.test.ts +842 -0
  173. package/src/tools/files.ts +990 -0
  174. package/src/tools/ids.test.ts +87 -0
  175. package/src/tools/ids.ts +89 -1
  176. package/src/tools/imports.ts +304 -0
  177. package/src/tools/logs.test.ts +70 -0
  178. package/src/tools/logs.ts +154 -44
  179. package/src/tools/paging.test.ts +39 -0
  180. package/src/tools/paging.ts +39 -0
  181. package/src/tools/params-merge.test.ts +274 -0
  182. package/src/tools/params-merge.ts +149 -0
  183. package/src/tools/project-template.test.ts +230 -0
  184. package/src/tools/project-template.ts +135 -0
  185. package/src/tools/projects.test.ts +122 -0
  186. package/src/tools/projects.ts +136 -48
  187. package/src/tools/readiness.test.ts +195 -0
  188. package/src/tools/readiness.ts +189 -0
  189. package/src/tools/result-pool.test.ts +377 -0
  190. package/src/tools/result-pool.ts +483 -0
  191. package/src/tools/sandbox.test.ts +128 -10
  192. package/src/tools/sandbox.ts +132 -18
  193. package/src/tools/sdk-types.ts +54 -0
  194. package/src/tools/settle.test.ts +340 -0
  195. package/src/tools/settle.ts +312 -0
  196. package/src/tools/tokens.ts +74 -9
  197. package/src/tools/types.ts +84 -12
  198. package/src/tools/value-outline.ts +143 -0
  199. package/dist/tools/screenshot.cjs +0 -44
  200. package/dist/tools/screenshot.cjs.map +0 -1
  201. package/dist/tools/screenshot.js +0 -44
  202. package/dist/tools/screenshot.js.map +0 -1
  203. package/dist/tools/ui-interaction.cjs +0 -140
  204. package/dist/tools/ui-interaction.cjs.map +0 -1
  205. package/dist/tools/ui-interaction.js +0 -140
  206. package/dist/tools/ui-interaction.js.map +0 -1
  207. package/src/tools/screenshot.ts +0 -61
  208. package/src/tools/ui-interaction.ts +0 -184
@@ -0,0 +1,397 @@
1
+ import { errorResult, hints, textResult } from "./types.js";
2
+ import { blockIdInput, projectIdInput } from "./ids.js";
3
+ import { page, pagingArgs } from "./paging.js";
4
+ import { clampWait, progressReporter, withDeadline } from "./settle.js";
5
+ import { clip } from "./tokens.js";
6
+ import { unknownBlockResult } from "./readiness.js";
7
+ import { readinessOf } from "./block-state.js";
8
+ import { applyBlockPack, updateBlockSpecInput } from "./blocks.js";
9
+ import { AWAIT_DEFAULT_MS, AWAIT_MAX_MS, AWAIT_MIN_MS } from "./await.js";
10
+ import { z } from "zod";
11
+ import { asBlockId } from "@milaboratories/pl-model-common";
12
+ /** The most characters of a registry URL, folder or pack URL in `from` and `to`. */
13
+ const UPDATE_SOURCE_CHARS = 300;
14
+ /**
15
+ * How long the update tools wait for the application's check of the registries for updates. The
16
+ * check runs in the background; until its answer is in, the overview offers no update for a
17
+ * block, as on a project just opened.
18
+ */
19
+ const UPDATE_CHECK_WAIT_MS = 15e3;
20
+ /** What the update tools say when the check of the registries is not in. */
21
+ const UPDATE_CHECK_PENDING_NOTE = "The application's check of the registries for updates has not finished: some blocks may have updates that are not shown yet. Call again in a moment.";
22
+ /**
23
+ * The project overview with the application's update check fresh: asks for a new check and
24
+ * waits for it, at most `timeoutMs` or until `signal`. `checked: false` when the check was not in
25
+ * by then: the updates the overview gives may then miss some.
26
+ */
27
+ async function overviewWithUpdates(project, timeoutMs, signal) {
28
+ if (await project.overview.getValue() === void 0) return {
29
+ overview: void 0,
30
+ checked: false
31
+ };
32
+ const checked = await withDeadline(timeoutMs, signal, (deadline) => new Promise((resolve) => {
33
+ if (deadline.aborted) return resolve(false);
34
+ deadline.addEventListener("abort", () => resolve(false), { once: true });
35
+ project.overview.refreshState().then(() => resolve(true), () => resolve(false));
36
+ }));
37
+ return {
38
+ overview: await project.overview.getValue(),
39
+ checked
40
+ };
41
+ }
42
+ /** Where `spec` comes from. */
43
+ function packSource(spec) {
44
+ switch (spec.type) {
45
+ case "from-registry-v2": return {
46
+ source: "registry",
47
+ registry: spec.registryUrl,
48
+ version: spec.id.version,
49
+ ...spec.channel !== void 0 ? { channel: spec.channel } : {}
50
+ };
51
+ case "from-registry-v1": return {
52
+ source: "registry",
53
+ registry: spec.registryUrl,
54
+ version: spec.id.version
55
+ };
56
+ case "dev-v1":
57
+ case "dev-v2": return {
58
+ source: "dev",
59
+ folder: spec.folder
60
+ };
61
+ case "from-pack-v2": return {
62
+ source: "pack",
63
+ packUrl: spec.packUrl
64
+ };
65
+ }
66
+ }
67
+ /** The version of a registry pack; `undefined` for a pack from a folder. */
68
+ function versionOf(spec) {
69
+ return spec.type === "from-registry-v1" || spec.type === "from-registry-v2" ? spec.id.version : void 0;
70
+ }
71
+ /** The updates of one block, from its overview entry alone. */
72
+ function blockUpdatesOf(block) {
73
+ const available = [];
74
+ for (const { type, update } of block.updateSuggestions) {
75
+ const version = versionOf(update);
76
+ if (version !== void 0) available.push({
77
+ version,
78
+ level: type,
79
+ spec: update
80
+ });
81
+ }
82
+ let recommended;
83
+ const main = block.updatedBlockPack;
84
+ if (main !== void 0) {
85
+ const version = versionOf(main);
86
+ const level = available.find((c) => c.version === version)?.level;
87
+ recommended = version !== void 0 && level !== void 0 ? {
88
+ version,
89
+ level,
90
+ spec: main
91
+ } : {
92
+ level: "rebuilt",
93
+ spec: main
94
+ };
95
+ }
96
+ const { versionLock, skipVersion } = block.settings;
97
+ return {
98
+ blockId: asBlockId(block.id),
99
+ label: block.title ?? block.label,
100
+ ...block.currentBlockPack !== void 0 ? { current: packSource(block.currentBlockPack) } : {},
101
+ ...recommended !== void 0 ? { recommended } : {},
102
+ available,
103
+ ...versionLock !== void 0 ? { versionLock } : {},
104
+ ...skipVersion !== void 0 ? { skipVersion } : {},
105
+ ...block.isIncompatibleWithRuntime === true ? { incompatible: true } : {}
106
+ };
107
+ }
108
+ /** Whether the block has anything to update to. */
109
+ function hasUpdate(updates) {
110
+ return updates.recommended !== void 0 || updates.available.length > 0;
111
+ }
112
+ /**
113
+ * The blocks of a project with their updates, filtered and paged (list_block_updates). Waits for
114
+ * the application's update check first (at most `updateCheckMs`); when it is not in, the answer
115
+ * says so (`updateCheck: "pending"`) rather than showing no updates.
116
+ */
117
+ async function listBlockUpdates(project, input, options = {}) {
118
+ const { overview, checked } = await overviewWithUpdates(project, options.updateCheckMs ?? 15e3, options.signal);
119
+ if (overview === void 0) return errorResult("Project overview not available yet. Try again.");
120
+ const wanted = input.blockIds === void 0 ? void 0 : new Set(input.blockIds);
121
+ const known = new Set(overview.blocks.map((b) => b.id));
122
+ const notFound = (input.blockIds ?? []).filter((id) => !known.has(id));
123
+ const selected = overview.blocks.filter((b) => wanted === void 0 || wanted.has(b.id)).map(blockUpdatesOf).filter((u) => input.all === true || hasUpdate(u));
124
+ const { items, ...paging } = page(selected, input.offset, input.limit ?? 50);
125
+ return textResult({
126
+ blocks: items,
127
+ ...paging,
128
+ ...notFound.length > 0 ? { notFound } : {},
129
+ ...checked ? {} : {
130
+ updateCheck: "pending",
131
+ note: UPDATE_CHECK_PENDING_NOTE
132
+ }
133
+ }, { hint: "Ask for fewer blocks: a smaller `limit` with `offset` to page, or `blockIds` for the blocks you need." });
134
+ }
135
+ /** Thrown in a block's turn (see {@link applyBlockPack}) when the call stopped while the block waited. */
136
+ var StoppedWhileWaiting = class extends Error {
137
+ stoppedBy;
138
+ constructor(stoppedBy) {
139
+ super(`update_blocks stopped (${stoppedBy}) before the block's turn`);
140
+ this.stoppedBy = stoppedBy;
141
+ }
142
+ };
143
+ /**
144
+ * Updates blocks of a project, one at a time, top to bottom, each through {@link applyBlockPack}.
145
+ * Each target is resolved from the project overview first, once the application's update check
146
+ * is in (see {@link overviewWithUpdates}); a target the block does not have fails that block
147
+ * only. While the update check is not in, `all: "recommended"` changes
148
+ * nothing and says so, and a block named with `recommended` or a release line is skipped. Stops
149
+ * starting blocks on `signal` or after `timeoutMs`, checked again when a block's turn
150
+ * starts: the blocks still waiting are `skipped`. Runs nothing.
151
+ */
152
+ async function updateBlocks(project, input, options) {
153
+ const start = Date.now();
154
+ const { projectId, updates, all } = input;
155
+ if (updates === void 0 === (all === void 0)) return errorResult("Give either `updates` or `all`, not both and not neither. Nothing was changed.", "updates: [{ blockId, to }] names the blocks; all: \"recommended\" takes every block with a recommended update.");
156
+ if (updates !== void 0) {
157
+ if (updates.length === 0) return errorResult("`updates` is empty. Nothing was changed.", "Name at least one block.");
158
+ const seen = /* @__PURE__ */ new Set();
159
+ for (const { blockId } of updates) {
160
+ if (seen.has(blockId)) return errorResult(`Block ${blockId} is named twice in \`updates\`. Nothing was changed.`, "Name each block once, with the one version to update it to.");
161
+ seen.add(blockId);
162
+ }
163
+ }
164
+ const { overview, checked } = await overviewWithUpdates(project, Math.min(options.updateCheckMs ?? 15e3, options.timeoutMs), options.signal);
165
+ if (overview === void 0) return errorResult("Project overview not available yet. Try again.");
166
+ const known = new Set(overview.blocks.map((b) => b.id));
167
+ const unknown = updates?.find((u) => !known.has(u.blockId));
168
+ if (unknown !== void 0) return unknownBlockResult(projectId, unknown.blockId, true);
169
+ if (!checked && all !== void 0) return errorResult("The application's check of the registries for updates has not finished, so which blocks have a recommended update is not known yet. Nothing was changed.", "Call update_blocks with all: \"recommended\" again in a moment.");
170
+ const targets = new Map(updates !== void 0 ? updates.map((u) => [u.blockId, u.to]) : overview.blocks.filter(isInUpdateAll).map((b) => [b.id, "recommended"]));
171
+ const plan = overview.blocks.flatMap((b) => {
172
+ const to = targets.get(b.id);
173
+ if (to === void 0) return [];
174
+ return [!checked && typeof to === "string" ? checkPending(b) : planUpdate(b, to)];
175
+ });
176
+ const total = plan.length;
177
+ let over = 0;
178
+ const report = (message) => options.onProgress?.(++over, total, message);
179
+ const stopNow = () => options.signal?.aborted ? "aborted" : Date.now() - start >= options.timeoutMs ? "timeout" : void 0;
180
+ let stoppedBy;
181
+ for (const step of plan) {
182
+ const { outcome, spec } = step;
183
+ if (spec === void 0) {
184
+ report(`${nameOf(outcome)}: ${outcome.status}`);
185
+ continue;
186
+ }
187
+ stoppedBy ??= stopNow();
188
+ if (stoppedBy !== void 0) {
189
+ outcome.status = "skipped";
190
+ outcome.reason = stoppedBy === "aborted" ? "The call was cancelled before this block's turn." : "The time ran out before this block's turn; call update_blocks again for it.";
191
+ report(`${nameOf(outcome)}: skipped`);
192
+ continue;
193
+ }
194
+ try {
195
+ const refused = await applyBlockPack(project, outcome.blockId, spec, {
196
+ resetArgs: false,
197
+ author: options.author(),
198
+ beforeWrite: () => {
199
+ const stop = stopNow();
200
+ if (stop !== void 0) throw new StoppedWhileWaiting(stop);
201
+ }
202
+ });
203
+ if (refused !== void 0) {
204
+ outcome.status = "failed";
205
+ outcome.reason = refused.content[0].text;
206
+ } else outcome.status = "done";
207
+ } catch (e) {
208
+ if (e instanceof StoppedWhileWaiting) {
209
+ stoppedBy = e.stoppedBy;
210
+ outcome.status = "skipped";
211
+ outcome.reason = stoppedBy === "aborted" ? "The call was cancelled while this block waited for an earlier change of it; it was not updated." : "The time ran out while this block waited for an earlier change of it; it was not updated. Call update_blocks again for it.";
212
+ } else {
213
+ outcome.status = "failed";
214
+ outcome.reason = `The block was not updated: ${e instanceof Error ? e.message : String(e)}`;
215
+ }
216
+ }
217
+ if (outcome.status === "done") {
218
+ const readiness = await readinessOf(project, outcome.blockId).catch(() => void 0);
219
+ if (readiness !== void 0) outcome.readiness = readiness;
220
+ }
221
+ report(`${nameOf(outcome)}: ${outcome.status}`);
222
+ }
223
+ const outcomes = plan.map((s) => s.outcome);
224
+ const count = (status) => outcomes.filter((o) => o.status === status).length;
225
+ return textResult({
226
+ blocks: outcomes.map(entryOf),
227
+ done: count("done"),
228
+ failed: count("failed"),
229
+ skipped: count("skipped"),
230
+ unchanged: count("unchanged"),
231
+ ...stoppedBy !== void 0 ? { stoppedBy } : {},
232
+ ...outcomes.length === 0 ? { note: "No block of the project has a recommended update." } : {}
233
+ }, { hint: "The updates were applied as far as they went; list_block_updates and get_block_state show the current state of each block." });
234
+ }
235
+ /** One outcome with its texts cut and its readiness summed up. */
236
+ function entryOf(outcome) {
237
+ const { readiness, label, from, to, reason, ...rest } = outcome;
238
+ return {
239
+ ...rest,
240
+ label: label === void 0 ? void 0 : clip(label, 80),
241
+ ...from !== void 0 ? { from: clipSource(from) } : {},
242
+ ...to !== void 0 ? { to: clipSource(to) } : {},
243
+ ...reason !== void 0 ? { reason: clip(reason, 300) } : {},
244
+ ...readiness !== void 0 ? { readiness: summaryOf(readiness) } : {}
245
+ };
246
+ }
247
+ function summaryOf(readiness) {
248
+ const blockers = readiness.blockers.slice(0, 3).map((b) => ({
249
+ ...b,
250
+ message: clip(b.message, 200)
251
+ }));
252
+ const more = readiness.blockers.length - blockers.length;
253
+ return {
254
+ status: readiness.status,
255
+ blockers,
256
+ ...more > 0 ? { moreBlockers: more } : {}
257
+ };
258
+ }
259
+ function clipSource(source) {
260
+ switch (source.source) {
261
+ case "registry": return {
262
+ ...source,
263
+ registry: clip(source.registry, UPDATE_SOURCE_CHARS)
264
+ };
265
+ case "dev": return {
266
+ ...source,
267
+ folder: clip(source.folder, UPDATE_SOURCE_CHARS)
268
+ };
269
+ case "pack": return {
270
+ ...source,
271
+ packUrl: clip(source.packUrl, UPDATE_SOURCE_CHARS)
272
+ };
273
+ }
274
+ }
275
+ function nameOf(outcome) {
276
+ return outcome.label === void 0 ? outcome.blockId : `"${outcome.label}" (${outcome.blockId})`;
277
+ }
278
+ /**
279
+ * Whether `all: "recommended"` takes the block, as the application's "Update All" does: a
280
+ * recommended update from a registry (a new release) of a block that works with this
281
+ * application. A dev block or a block from a local pack is offered its rebuild, not a release,
282
+ * and is left out. A version lock or a skipped version already leaves the recommendation out.
283
+ */
284
+ function isInUpdateAll(block) {
285
+ const type = block.updatedBlockPack?.type;
286
+ return (type === "from-registry-v1" || type === "from-registry-v2") && block.isIncompatibleWithRuntime !== true;
287
+ }
288
+ /** A block whose target needs the update check, which is not in: skipped. */
289
+ function checkPending(block) {
290
+ const updates = blockUpdatesOf(block);
291
+ return { outcome: {
292
+ blockId: updates.blockId,
293
+ label: updates.label,
294
+ ...updates.current !== void 0 ? { from: updates.current } : {},
295
+ status: "skipped",
296
+ reason: "The application's check of the registries for updates has not finished; call update_blocks again for this block in a moment."
297
+ } };
298
+ }
299
+ /**
300
+ * Resolves what one block is updated to, from its overview entry.
301
+ */
302
+ function planUpdate(block, to) {
303
+ const updates = blockUpdatesOf(block);
304
+ const outcome = {
305
+ blockId: updates.blockId,
306
+ label: updates.label,
307
+ ...updates.current !== void 0 ? { from: updates.current } : {},
308
+ status: "skipped"
309
+ };
310
+ const offered = () => updates.available.length === 0 ? "The registry offers no update for it." : `Available: ${updates.available.map((c) => `${c.level} ${c.version}`).join(", ")}.`;
311
+ let spec;
312
+ if (to === "recommended") {
313
+ if (updates.recommended === void 0) {
314
+ outcome.status = "unchanged";
315
+ outcome.reason = "The block has no recommended update" + (updates.versionLock !== void 0 ? ` (its versionLock is ${updates.versionLock})` : "") + `. ${offered()}`;
316
+ return { outcome };
317
+ }
318
+ spec = updates.recommended.spec;
319
+ } else if (typeof to === "string") {
320
+ const candidate = updates.available.find((c) => c.level === to);
321
+ if (candidate === void 0) {
322
+ outcome.status = "failed";
323
+ outcome.reason = `No ${to} update is available for this block. ${offered()}`;
324
+ return { outcome };
325
+ }
326
+ spec = candidate.spec;
327
+ } else spec = to;
328
+ outcome.to = packSource(spec);
329
+ if (isSameRegistryPack(block.currentBlockPack, spec)) {
330
+ outcome.status = "unchanged";
331
+ outcome.reason = "The block is already on this version.";
332
+ return { outcome };
333
+ }
334
+ return {
335
+ outcome,
336
+ spec
337
+ };
338
+ }
339
+ /** Whether two specs name the same version of the same registry block. */
340
+ function isSameRegistryPack(current, target) {
341
+ if (current?.type !== "from-registry-v2" || target.type !== "from-registry-v2") return false;
342
+ return current.registryUrl === target.registryUrl && current.id.organization === target.id.organization && current.id.name === target.id.name && current.id.version === target.id.version;
343
+ }
344
+ const updateTargetInput = z.union([z.enum([
345
+ "recommended",
346
+ "patch",
347
+ "minor",
348
+ "major"
349
+ ]), updateBlockSpecInput]);
350
+ function registerBlockUpdateTools(server, ctx) {
351
+ server.registerTool("list_block_updates", {
352
+ title: "List Block Updates",
353
+ annotations: hints.read,
354
+ description: "List the updates of a project's blocks, to upgrade a project. Per block: `current` (where its pack comes from: registry and version, or a local folder), `available` (every update its registry offers: the newest patch, minor and major version, each with the `spec` update_block takes) and `recommended` (the update the application suggests: the newest the block's `versionLock` allows, unless the user skipped it; `level: \"rebuilt\"` for a block from a local folder that holds a newer build). `incompatible: true`: the block's current version does not work with this application. Facts only: nothing is changed and no block is downloaded.\n\nBy default only blocks with an update are listed; `all: true` lists every block. update_blocks applies updates to a project's blocks; update_block moves one block to a given pack (a dev block after a rebuild, too).\n\nThe application checks the registries in the background; the call waits for that check, and when it is not in yet says so with `updateCheck: \"pending\"` and a `note`: some updates may not be shown yet, call again.\n\nResult: `{ blocks, total, offset, hasMore, notFound?, updateCheck?, note? }`, blocks in project order.",
355
+ inputSchema: z.object({
356
+ projectId: projectIdInput.describe("Project ID"),
357
+ blockIds: z.array(blockIdInput).optional().describe("Only these blocks; `notFound` lists the ids the project lacks."),
358
+ all: z.boolean().optional().describe("Also list blocks with nothing to update (default false)."),
359
+ ...pagingArgs("blocks", 50, 200)
360
+ })
361
+ }, async (input, call) => {
362
+ return await ctx.withProject(input.projectId, (project) => listBlockUpdates(project, input, { signal: call.mcpReq.signal }));
363
+ });
364
+ server.registerTool("update_blocks", {
365
+ title: "Update Blocks",
366
+ annotations: {
367
+ ...hints.destructive,
368
+ idempotentHint: false
369
+ },
370
+ description: `Upgrade blocks of a project to newer versions. \`updates\` names the blocks and what to move each to: \`recommended\`, the newest \`patch\`, \`minor\` or \`major\` version (list_block_updates shows them), or a block pack spec; or \`all: "recommended"\` takes every block with a recommended registry update, as the application's Update All: not dev blocks, blocks from a local pack, or incompatible blocks. Blocks are updated one at a time, top to bottom, the same way update_block updates one; their data is kept and migrated by the new version. A block whose target is not available or whose new pack is refused (it needs a newer application, or is on block API 1) fails with the reason and is left as it was; the others go on.
371
+
372
+ Updates run nothing: results of the old version stay until the block runs again. Each updated block comes back with its readiness: a new version may need data changes, and the readiness says what to fix (set_block_params, set_block_data) before run_block. The application's open views of an updated block reload.
373
+
374
+ The call stops at \`timeout\` (default ${AWAIT_DEFAULT_MS} ms, at most ${AWAIT_MAX_MS}) or when cancelled: the block being updated finishes, the blocks still waiting are \`skipped\`; call again for them. The call first waits for the application's check of the registries; when it is not in yet, all: "recommended" changes nothing and says so, and blocks named with \`recommended\` or a release line are \`skipped\`. Progress notifications count the blocks.
375
+
376
+ Result: \`{ blocks: [{ blockId, label, from, to, status, reason?, readiness? }], done, failed, skipped, unchanged, stoppedBy?, note? }\`; status is done, failed, skipped or unchanged (already on that version, or nothing recommended). Labels and reasons are cut short; \`readiness\` is the status and at most 3 blockers (get_block_state gives it in full).`,
377
+ inputSchema: z.object({
378
+ projectId: projectIdInput.describe("Project ID"),
379
+ updates: z.array(z.object({
380
+ blockId: blockIdInput.describe("Block ID"),
381
+ to: updateTargetInput.describe("What to update to: \"recommended\", \"patch\", \"minor\", \"major\", or a block pack spec.")
382
+ })).optional().describe("The blocks to update, each once. Give this or `all`."),
383
+ all: z.literal("recommended").optional().describe("Update every block with a recommended registry update, as Update All does. Give this or `updates`."),
384
+ timeout: z.number().optional().describe(`No block starts updating after this many ms (default ${AWAIT_DEFAULT_MS}, at most ${AWAIT_MAX_MS}).`)
385
+ })
386
+ }, async ({ timeout, ...input }, call) => {
387
+ return await ctx.withProject(input.projectId, (project) => updateBlocks(project, input, {
388
+ author: ctx.getAuthorMarker,
389
+ timeoutMs: clampWait(timeout, AWAIT_DEFAULT_MS, AWAIT_MIN_MS, AWAIT_MAX_MS),
390
+ signal: call.mcpReq.signal,
391
+ onProgress: progressReporter(call, "Updating blocks", 1)
392
+ }));
393
+ });
394
+ }
395
+ export { UPDATE_CHECK_PENDING_NOTE, UPDATE_CHECK_WAIT_MS, blockUpdatesOf, listBlockUpdates, overviewWithUpdates, packSource, registerBlockUpdateTools, updateBlocks, updateTargetInput };
396
+
397
+ //# sourceMappingURL=block-updates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-updates.js","names":[],"sources":["../../src/tools/block-updates.ts"],"sourcesContent":["import { asBlockId, type BlockId, type ProjectId } from \"@milaboratories/pl-model-common\";\nimport type {\n BlockPackSpec,\n BlockPackSpecAny,\n BlockStateOverview,\n VersionLock,\n} from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { AWAIT_DEFAULT_MS, AWAIT_MAX_MS, AWAIT_MIN_MS } from \"./await\";\nimport { readinessOf, type ReadinessProject } from \"./block-state\";\nimport { applyBlockPack, type BlockPackProject, updateBlockSpecInput } from \"./blocks\";\nimport { blockIdInput, projectIdInput } from \"./ids\";\nimport { page, pagingArgs } from \"./paging\";\nimport {\n type BlockStatus,\n type Readiness,\n type ReadinessBlocker,\n unknownBlockResult,\n} from \"./readiness\";\nimport { clampWait, progressReporter, withDeadline } from \"./settle\";\nimport { clip } from \"./tokens\";\nimport type { AuthorMarker, ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** How many blocks list_block_updates returns when the caller does not say. */\nexport const BLOCK_UPDATES_DEFAULT_LIMIT = 50;\n/** The most blocks one list_block_updates call returns. */\nexport const BLOCK_UPDATES_MAX_LIMIT = 200;\n\n/** The most characters of the reason of a block's outcome in the answer of update_blocks. */\nexport const UPDATE_REASON_CHARS = 300;\n\n/** The most characters of a block's label in the answer of update_blocks. */\nexport const UPDATE_LABEL_CHARS = 80;\n\n/** The most blockers of an updated block's readiness the answer of update_blocks lists. */\nexport const UPDATE_READINESS_BLOCKERS = 3;\n\n/** The most characters of one such blocker's message. */\nexport const UPDATE_BLOCKER_CHARS = 200;\n\n/** The most characters of a registry URL, folder or pack URL in `from` and `to`. */\nconst UPDATE_SOURCE_CHARS = 300;\n\n/** The release line of an update the registry offers, against the block's current version. */\nexport type UpdateLevel = \"major\" | \"minor\" | \"patch\";\n\n/**\n * Where a block pack comes from: a registry (with the version), a local dev folder, or a block\n * pack folder of an installed package.\n */\nexport type PackSource =\n | { source: \"registry\"; registry: string; version: string; channel?: string }\n | { source: \"dev\"; folder: string }\n | { source: \"pack\"; packUrl: string };\n\n/** One version a block can be updated to. */\nexport type UpdateCandidate = {\n version: string;\n level: UpdateLevel;\n /** The block pack spec to update to, as update_block takes it. */\n spec: BlockPackSpec;\n};\n\n/**\n * The update the application recommends: the newest the block's `versionLock` allows, or for a\n * block from a local folder, the newer build in that folder (`rebuilt`).\n */\nexport type RecommendedUpdate = UpdateCandidate | { level: \"rebuilt\"; spec: BlockPackSpec };\n\n/** The updates of one block, as list_block_updates gives them. */\nexport type BlockUpdates = {\n blockId: BlockId;\n label: string | undefined;\n /** Where the block's pack comes from now; absent while the pack is not loaded. */\n current?: PackSource;\n recommended?: RecommendedUpdate;\n /** Every update the registry offers, newest release line first. */\n available: UpdateCandidate[];\n versionLock?: VersionLock;\n /** Updates up to this version are not recommended (the user skipped them). */\n skipVersion?: string;\n /** The block does not work with this application version. */\n incompatible?: true;\n};\n\n/** What the update tools read of a block of the project overview. */\nexport type UpdatesOverviewBlock = Pick<\n BlockStateOverview,\n | \"id\"\n | \"title\"\n | \"label\"\n | \"currentBlockPack\"\n | \"updatedBlockPack\"\n | \"updateSuggestions\"\n | \"settings\"\n | \"isIncompatibleWithRuntime\"\n>;\n\n/** What the update tools read of a project. */\nexport type UpdatesProject = {\n overview: {\n getValue(): Promise<{ blocks: UpdatesOverviewBlock[] } | undefined>;\n /**\n * Resolves once every source of the overview was read again, the application's check of the\n * registries for updates included (a middle-layer `Computable`).\n */\n refreshState(): Promise<void>;\n };\n};\n\n/**\n * How long the update tools wait for the application's check of the registries for updates. The\n * check runs in the background; until its answer is in, the overview offers no update for a\n * block, as on a project just opened.\n */\nexport const UPDATE_CHECK_WAIT_MS = 15_000;\n\n/** What the update tools say when the check of the registries is not in. */\nexport const UPDATE_CHECK_PENDING_NOTE =\n \"The application's check of the registries for updates has not finished: some blocks may \" +\n \"have updates that are not shown yet. Call again in a moment.\";\n\n/**\n * The project overview with the application's update check fresh: asks for a new check and\n * waits for it, at most `timeoutMs` or until `signal`. `checked: false` when the check was not in\n * by then: the updates the overview gives may then miss some.\n */\nexport async function overviewWithUpdates(\n project: UpdatesProject,\n timeoutMs: number,\n signal?: AbortSignal,\n): Promise<{ overview: { blocks: UpdatesOverviewBlock[] } | undefined; checked: boolean }> {\n // Read once first: the overview knows its sources only once it was computed.\n const first = await project.overview.getValue();\n if (first === undefined) return { overview: undefined, checked: false };\n const checked = await withDeadline(\n timeoutMs,\n signal,\n (deadline) =>\n new Promise<boolean>((resolve) => {\n if (deadline.aborted) return resolve(false);\n deadline.addEventListener(\"abort\", () => resolve(false), { once: true });\n project.overview.refreshState().then(\n () => resolve(true),\n () => resolve(false),\n );\n }),\n );\n return { overview: await project.overview.getValue(), checked };\n}\n\n/** Where `spec` comes from. */\nexport function packSource(spec: BlockPackSpec): PackSource {\n switch (spec.type) {\n case \"from-registry-v2\":\n return {\n source: \"registry\",\n registry: spec.registryUrl,\n version: spec.id.version,\n ...(spec.channel !== undefined ? { channel: spec.channel } : {}),\n };\n case \"from-registry-v1\":\n return { source: \"registry\", registry: spec.registryUrl, version: spec.id.version };\n case \"dev-v1\":\n case \"dev-v2\":\n return { source: \"dev\", folder: spec.folder };\n case \"from-pack-v2\":\n return { source: \"pack\", packUrl: spec.packUrl };\n }\n}\n\n/** The version of a registry pack; `undefined` for a pack from a folder. */\nfunction versionOf(spec: BlockPackSpec): string | undefined {\n return spec.type === \"from-registry-v1\" || spec.type === \"from-registry-v2\"\n ? spec.id.version\n : undefined;\n}\n\n/** The updates of one block, from its overview entry alone. */\nexport function blockUpdatesOf(block: UpdatesOverviewBlock): BlockUpdates {\n const available: UpdateCandidate[] = [];\n for (const { type, update } of block.updateSuggestions) {\n const version = versionOf(update);\n if (version !== undefined) available.push({ version, level: type, spec: update });\n }\n\n let recommended: RecommendedUpdate | undefined;\n const main = block.updatedBlockPack;\n if (main !== undefined) {\n const version = versionOf(main);\n const level = available.find((c) => c.version === version)?.level;\n recommended =\n version !== undefined && level !== undefined\n ? { version, level, spec: main }\n : { level: \"rebuilt\", spec: main };\n }\n\n const { versionLock, skipVersion } = block.settings;\n return {\n blockId: asBlockId(block.id),\n label: block.title ?? block.label,\n ...(block.currentBlockPack !== undefined\n ? { current: packSource(block.currentBlockPack) }\n : {}),\n ...(recommended !== undefined ? { recommended } : {}),\n available,\n ...(versionLock !== undefined ? { versionLock } : {}),\n ...(skipVersion !== undefined ? { skipVersion } : {}),\n ...(block.isIncompatibleWithRuntime === true ? { incompatible: true } : {}),\n };\n}\n\n/** Whether the block has anything to update to. */\nfunction hasUpdate(updates: BlockUpdates): boolean {\n return updates.recommended !== undefined || updates.available.length > 0;\n}\n\n/** The input of list_block_updates. */\nexport type ListBlockUpdatesInput = {\n projectId: ProjectId;\n blockIds?: BlockId[];\n all?: boolean;\n limit?: number;\n offset?: number;\n};\n\n/**\n * The blocks of a project with their updates, filtered and paged (list_block_updates). Waits for\n * the application's update check first (at most `updateCheckMs`); when it is not in, the answer\n * says so (`updateCheck: \"pending\"`) rather than showing no updates.\n */\nexport async function listBlockUpdates(\n project: UpdatesProject,\n input: ListBlockUpdatesInput,\n options: { updateCheckMs?: number; signal?: AbortSignal } = {},\n) {\n const { overview, checked } = await overviewWithUpdates(\n project,\n options.updateCheckMs ?? UPDATE_CHECK_WAIT_MS,\n options.signal,\n );\n if (overview === undefined) return errorResult(\"Project overview not available yet. Try again.\");\n const wanted = input.blockIds === undefined ? undefined : new Set<string>(input.blockIds);\n const known = new Set(overview.blocks.map((b) => b.id));\n const notFound = (input.blockIds ?? []).filter((id) => !known.has(id));\n const selected = overview.blocks\n .filter((b) => wanted === undefined || wanted.has(b.id))\n .map(blockUpdatesOf)\n .filter((u) => input.all === true || hasUpdate(u));\n const { items, ...paging } = page(\n selected,\n input.offset,\n input.limit ?? BLOCK_UPDATES_DEFAULT_LIMIT,\n );\n return textResult(\n {\n blocks: items,\n ...paging,\n ...(notFound.length > 0 ? { notFound } : {}),\n ...(checked ? {} : { updateCheck: \"pending\", note: UPDATE_CHECK_PENDING_NOTE }),\n },\n {\n hint:\n \"Ask for fewer blocks: a smaller `limit` with `offset` to page, or `blockIds` for the \" +\n \"blocks you need.\",\n },\n );\n}\n\n/** The pack spec an update target names explicitly. */\nexport type UpdateSpec = z.infer<typeof updateBlockSpecInput>;\n\n/** What a block is updated to: the recommended update, the newest of a release line, or a pack. */\nexport type UpdateTarget = \"recommended\" | UpdateLevel | UpdateSpec;\n\n/** How the update of one block ended. */\nexport type UpdateStatus = \"done\" | \"failed\" | \"skipped\" | \"unchanged\";\n\n/** The outcome of one block of update_blocks. */\nexport type BlockUpdateOutcome = {\n blockId: BlockId;\n label: string | undefined;\n from?: PackSource;\n to?: PackSource;\n status: UpdateStatus;\n reason?: string;\n /** The block's readiness after the update: a new version may need its data changed. */\n readiness?: Readiness;\n};\n\n/**\n * An updated block's readiness as the answer of update_blocks gives it: its status and at most\n * {@link UPDATE_READINESS_BLOCKERS} blockers, or only its status in an answer cut to size.\n * get_block_state gives it in full.\n */\nexport type ReadinessSummary = {\n status: BlockStatus;\n blockers?: ReadinessBlocker[];\n /** How many blockers were left out. */\n moreBlockers?: number;\n};\n\n/** One block in the answer of update_blocks: its outcome with every text cut to a bound. */\nexport type BlockUpdateEntry = Omit<BlockUpdateOutcome, \"readiness\"> & {\n readiness?: ReadinessSummary;\n};\n\n/** The input of update_blocks. */\nexport type UpdateBlocksInput = {\n projectId: ProjectId;\n updates?: { blockId: BlockId; to: UpdateTarget }[];\n all?: \"recommended\";\n};\n\n/** What update_blocks needs of a project; a middle-layer `Project` has it. */\nexport type UpdateBlocksProject = UpdatesProject & BlockPackProject & ReadinessProject;\n\n/** How update_blocks runs. */\nexport type UpdateBlocksOptions = {\n /** The marker of the next write; one per block updated. */\n author: () => AuthorMarker;\n /**\n * No block starts updating after this long, a block waiting for an earlier change of it\n * included; the one under way finishes.\n */\n timeoutMs: number;\n /** The call was cancelled: no block starts updating after it, a waiting one included. */\n signal?: AbortSignal;\n /** Called after each block with how many of the `total` blocks are over. */\n onProgress?: (done: number, total: number, message: string) => void;\n /**\n * The longest wait for the application's update check (default {@link UPDATE_CHECK_WAIT_MS},\n * never past `timeoutMs`).\n */\n updateCheckMs?: number;\n};\n\n/** One block of the plan of update_blocks. */\ntype PlannedUpdate = {\n outcome: BlockUpdateOutcome;\n /** The pack to move to; `undefined` once the outcome is decided without an update. */\n spec?: BlockPackSpecAny;\n};\n\n/** Why update_blocks stopped starting blocks. */\ntype StopReason = \"timeout\" | \"aborted\";\n\n/** Thrown in a block's turn (see {@link applyBlockPack}) when the call stopped while the block waited. */\nclass StoppedWhileWaiting extends Error {\n constructor(readonly stoppedBy: StopReason) {\n super(`update_blocks stopped (${stoppedBy}) before the block's turn`);\n }\n}\n\n/**\n * Updates blocks of a project, one at a time, top to bottom, each through {@link applyBlockPack}.\n * Each target is resolved from the project overview first, once the application's update check\n * is in (see {@link overviewWithUpdates}); a target the block does not have fails that block\n * only. While the update check is not in, `all: \"recommended\"` changes\n * nothing and says so, and a block named with `recommended` or a release line is skipped. Stops\n * starting blocks on `signal` or after `timeoutMs`, checked again when a block's turn\n * starts: the blocks still waiting are `skipped`. Runs nothing.\n */\nexport async function updateBlocks(\n project: UpdateBlocksProject,\n input: UpdateBlocksInput,\n options: UpdateBlocksOptions,\n) {\n const start = Date.now();\n const { projectId, updates, all } = input;\n if ((updates === undefined) === (all === undefined))\n return errorResult(\n \"Give either `updates` or `all`, not both and not neither. Nothing was changed.\",\n 'updates: [{ blockId, to }] names the blocks; all: \"recommended\" takes every block with ' +\n \"a recommended update.\",\n );\n if (updates !== undefined) {\n if (updates.length === 0)\n return errorResult(\"`updates` is empty. Nothing was changed.\", \"Name at least one block.\");\n const seen = new Set<string>();\n for (const { blockId } of updates) {\n if (seen.has(blockId))\n return errorResult(\n `Block ${blockId} is named twice in \\`updates\\`. Nothing was changed.`,\n \"Name each block once, with the one version to update it to.\",\n );\n seen.add(blockId);\n }\n }\n\n const { overview, checked } = await overviewWithUpdates(\n project,\n Math.min(options.updateCheckMs ?? UPDATE_CHECK_WAIT_MS, options.timeoutMs),\n options.signal,\n );\n if (overview === undefined) return errorResult(\"Project overview not available yet. Try again.\");\n const known = new Set(overview.blocks.map((b) => b.id));\n const unknown = updates?.find((u) => !known.has(u.blockId));\n if (unknown !== undefined) return unknownBlockResult(projectId, unknown.blockId, true);\n if (!checked && all !== undefined)\n return errorResult(\n \"The application's check of the registries for updates has not finished, so which \" +\n \"blocks have a recommended update is not known yet. Nothing was changed.\",\n 'Call update_blocks with all: \"recommended\" again in a moment.',\n );\n\n const targets = new Map<string, UpdateTarget>(\n updates !== undefined\n ? updates.map((u) => [u.blockId, u.to])\n : overview.blocks.filter(isInUpdateAll).map((b) => [b.id, \"recommended\"]),\n );\n // Top to bottom, whatever order the caller named the blocks in.\n const plan = overview.blocks.flatMap((b): PlannedUpdate[] => {\n const to = targets.get(b.id);\n if (to === undefined) return [];\n return [!checked && typeof to === \"string\" ? checkPending(b) : planUpdate(b, to)];\n });\n\n const total = plan.length;\n let over = 0;\n const report = (message: string) => options.onProgress?.(++over, total, message);\n const stopNow = (): StopReason | undefined =>\n options.signal?.aborted\n ? \"aborted\"\n : Date.now() - start >= options.timeoutMs\n ? \"timeout\"\n : undefined;\n let stoppedBy: StopReason | undefined;\n for (const step of plan) {\n const { outcome, spec } = step;\n if (spec === undefined) {\n report(`${nameOf(outcome)}: ${outcome.status}`);\n continue;\n }\n stoppedBy ??= stopNow();\n if (stoppedBy !== undefined) {\n outcome.status = \"skipped\";\n outcome.reason =\n stoppedBy === \"aborted\"\n ? \"The call was cancelled before this block's turn.\"\n : \"The time ran out before this block's turn; call update_blocks again for it.\";\n report(`${nameOf(outcome)}: skipped`);\n continue;\n }\n try {\n const refused = await applyBlockPack(project, outcome.blockId, spec, {\n resetArgs: false,\n author: options.author(),\n // The block may have waited behind an earlier change of it: check again at its turn.\n beforeWrite: () => {\n const stop = stopNow();\n if (stop !== undefined) throw new StoppedWhileWaiting(stop);\n },\n });\n if (refused !== undefined) {\n outcome.status = \"failed\";\n outcome.reason = refused.content[0].text;\n } else {\n outcome.status = \"done\";\n }\n } catch (e: unknown) {\n if (e instanceof StoppedWhileWaiting) {\n stoppedBy = e.stoppedBy;\n outcome.status = \"skipped\";\n outcome.reason =\n stoppedBy === \"aborted\"\n ? \"The call was cancelled while this block waited for an earlier change of it; \" +\n \"it was not updated.\"\n : \"The time ran out while this block waited for an earlier change of it; it was \" +\n \"not updated. Call update_blocks again for it.\";\n } else {\n outcome.status = \"failed\";\n outcome.reason = `The block was not updated: ${e instanceof Error ? e.message : String(e)}`;\n }\n }\n if (outcome.status === \"done\") {\n // The block is updated by now: a failure to read it afterwards only leaves the readiness out.\n const readiness = await readinessOf(project, outcome.blockId).catch(() => undefined);\n if (readiness !== undefined) outcome.readiness = readiness;\n }\n report(`${nameOf(outcome)}: ${outcome.status}`);\n }\n\n const outcomes = plan.map((s) => s.outcome);\n const count = (status: UpdateStatus) => outcomes.filter((o) => o.status === status).length;\n return textResult(\n {\n blocks: outcomes.map(entryOf),\n done: count(\"done\"),\n failed: count(\"failed\"),\n skipped: count(\"skipped\"),\n unchanged: count(\"unchanged\"),\n ...(stoppedBy !== undefined ? { stoppedBy } : {}),\n ...(outcomes.length === 0\n ? { note: \"No block of the project has a recommended update.\" }\n : {}),\n },\n {\n hint:\n \"The updates were applied as far as they went; list_block_updates and get_block_state \" +\n \"show the current state of each block.\",\n },\n );\n}\n\n/** One outcome with its texts cut and its readiness summed up. */\nfunction entryOf(outcome: BlockUpdateOutcome): BlockUpdateEntry {\n const { readiness, label, from, to, reason, ...rest } = outcome;\n return {\n ...rest,\n label: label === undefined ? undefined : clip(label, UPDATE_LABEL_CHARS),\n ...(from !== undefined ? { from: clipSource(from) } : {}),\n ...(to !== undefined ? { to: clipSource(to) } : {}),\n ...(reason !== undefined ? { reason: clip(reason, UPDATE_REASON_CHARS) } : {}),\n ...(readiness !== undefined ? { readiness: summaryOf(readiness) } : {}),\n };\n}\n\nfunction summaryOf(readiness: Readiness): ReadinessSummary {\n const blockers = readiness.blockers\n .slice(0, UPDATE_READINESS_BLOCKERS)\n .map((b) => ({ ...b, message: clip(b.message, UPDATE_BLOCKER_CHARS) }));\n const more = readiness.blockers.length - blockers.length;\n return { status: readiness.status, blockers, ...(more > 0 ? { moreBlockers: more } : {}) };\n}\n\nfunction clipSource(source: PackSource): PackSource {\n switch (source.source) {\n case \"registry\":\n return { ...source, registry: clip(source.registry, UPDATE_SOURCE_CHARS) };\n case \"dev\":\n return { ...source, folder: clip(source.folder, UPDATE_SOURCE_CHARS) };\n case \"pack\":\n return { ...source, packUrl: clip(source.packUrl, UPDATE_SOURCE_CHARS) };\n }\n}\n\nfunction nameOf(outcome: BlockUpdateOutcome): string {\n return outcome.label === undefined ? outcome.blockId : `\"${outcome.label}\" (${outcome.blockId})`;\n}\n\n/**\n * Whether `all: \"recommended\"` takes the block, as the application's \"Update All\" does: a\n * recommended update from a registry (a new release) of a block that works with this\n * application. A dev block or a block from a local pack is offered its rebuild, not a release,\n * and is left out. A version lock or a skipped version already leaves the recommendation out.\n */\nfunction isInUpdateAll(block: UpdatesOverviewBlock): boolean {\n const type = block.updatedBlockPack?.type;\n return (\n (type === \"from-registry-v1\" || type === \"from-registry-v2\") &&\n block.isIncompatibleWithRuntime !== true\n );\n}\n\n/** A block whose target needs the update check, which is not in: skipped. */\nfunction checkPending(block: UpdatesOverviewBlock): PlannedUpdate {\n const updates = blockUpdatesOf(block);\n return {\n outcome: {\n blockId: updates.blockId,\n label: updates.label,\n ...(updates.current !== undefined ? { from: updates.current } : {}),\n status: \"skipped\",\n reason:\n \"The application's check of the registries for updates has not finished; call \" +\n \"update_blocks again for this block in a moment.\",\n },\n };\n}\n\n/**\n * Resolves what one block is updated to, from its overview entry.\n */\nfunction planUpdate(block: UpdatesOverviewBlock, to: UpdateTarget): PlannedUpdate {\n const updates = blockUpdatesOf(block);\n const outcome: BlockUpdateOutcome = {\n blockId: updates.blockId,\n label: updates.label,\n ...(updates.current !== undefined ? { from: updates.current } : {}),\n status: \"skipped\",\n };\n const offered = () =>\n updates.available.length === 0\n ? \"The registry offers no update for it.\"\n : `Available: ${updates.available.map((c) => `${c.level} ${c.version}`).join(\", \")}.`;\n\n let spec: BlockPackSpecAny;\n if (to === \"recommended\") {\n if (updates.recommended === undefined) {\n outcome.status = \"unchanged\";\n outcome.reason =\n \"The block has no recommended update\" +\n (updates.versionLock !== undefined ? ` (its versionLock is ${updates.versionLock})` : \"\") +\n `. ${offered()}`;\n return { outcome };\n }\n spec = updates.recommended.spec;\n } else if (typeof to === \"string\") {\n const candidate = updates.available.find((c) => c.level === to);\n if (candidate === undefined) {\n outcome.status = \"failed\";\n outcome.reason = `No ${to} update is available for this block. ${offered()}`;\n return { outcome };\n }\n spec = candidate.spec;\n } else {\n spec = to;\n }\n\n const target = packSource(spec);\n outcome.to = target;\n if (isSameRegistryPack(block.currentBlockPack, spec)) {\n outcome.status = \"unchanged\";\n outcome.reason = \"The block is already on this version.\";\n return { outcome };\n }\n return { outcome, spec };\n}\n\n/** Whether two specs name the same version of the same registry block. */\nfunction isSameRegistryPack(current: BlockPackSpec | undefined, target: BlockPackSpecAny): boolean {\n if (current?.type !== \"from-registry-v2\" || target.type !== \"from-registry-v2\") return false;\n return (\n current.registryUrl === target.registryUrl &&\n current.id.organization === target.id.organization &&\n current.id.name === target.id.name &&\n current.id.version === target.id.version\n );\n}\n\nexport const updateTargetInput = z.union([\n z.enum([\"recommended\", \"patch\", \"minor\", \"major\"]),\n updateBlockSpecInput,\n]);\n\nexport function registerBlockUpdateTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_block_updates\",\n {\n title: \"List Block Updates\",\n annotations: hints.read,\n description:\n \"List the updates of a project's blocks, to upgrade a project. Per block: `current` \" +\n \"(where its pack comes from: registry and version, or a local folder), `available` \" +\n \"(every update its registry offers: the newest patch, minor and major version, each \" +\n \"with the `spec` update_block takes) and `recommended` (the update the application \" +\n \"suggests: the newest the block's `versionLock` allows, unless the user skipped it; \" +\n '`level: \"rebuilt\"` for a block from a local folder that holds a newer build). ' +\n \"`incompatible: true`: the block's current version does not work with this application. \" +\n \"Facts only: nothing is changed and no block is downloaded.\\n\\n\" +\n \"By default only blocks with an update are listed; `all: true` lists every block. \" +\n \"update_blocks applies updates to a project's blocks; update_block moves one block to \" +\n \"a given pack (a dev block after a rebuild, too).\\n\\n\" +\n \"The application checks the registries in the background; the call waits for that \" +\n 'check, and when it is not in yet says so with `updateCheck: \"pending\"` and a `note`: ' +\n \"some updates may not be shown yet, call again.\\n\\n\" +\n \"Result: `{ blocks, total, offset, hasMore, notFound?, updateCheck?, note? }`, blocks \" +\n \"in project order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z\n .array(blockIdInput)\n .optional()\n .describe(\"Only these blocks; `notFound` lists the ids the project lacks.\"),\n all: z\n .boolean()\n .optional()\n .describe(\"Also list blocks with nothing to update (default false).\"),\n ...pagingArgs(\"blocks\", BLOCK_UPDATES_DEFAULT_LIMIT, BLOCK_UPDATES_MAX_LIMIT),\n }),\n },\n async (input, call) => {\n return await ctx.withProject(input.projectId, (project) =>\n listBlockUpdates(project, input, { signal: call.mcpReq.signal }),\n );\n },\n );\n\n server.registerTool(\n \"update_blocks\",\n {\n title: \"Update Blocks\",\n annotations: { ...hints.destructive, idempotentHint: false },\n description:\n \"Upgrade blocks of a project to newer versions. `updates` names the blocks and what \" +\n \"to move each to: `recommended`, the newest `patch`, `minor` or `major` version \" +\n '(list_block_updates shows them), or a block pack spec; or `all: \"recommended\"` takes ' +\n \"every block with a recommended registry update, as the application's Update All: not \" +\n \"dev blocks, blocks from a local pack, or incompatible blocks. Blocks are updated one at a \" +\n \"time, top to bottom, the same way update_block updates one; their data is kept and \" +\n \"migrated by the new version. A block whose target is not available or whose new pack \" +\n \"is refused (it needs a newer application, or is on block API 1) fails with the reason \" +\n \"and is left as it was; the others go on.\\n\\n\" +\n \"Updates run nothing: results of the old version stay until the block runs again. \" +\n \"Each updated block comes back with its readiness: a new version may need data \" +\n \"changes, and the readiness says what to fix (set_block_params, set_block_data) before \" +\n \"run_block. The application's open views of an updated block reload.\\n\\n\" +\n `The call stops at \\`timeout\\` (default ${AWAIT_DEFAULT_MS} ms, at most ${AWAIT_MAX_MS}) ` +\n \"or when cancelled: the block being updated finishes, the blocks still waiting are \" +\n \"`skipped`; call again for them. The call first waits for the application's check of \" +\n 'the registries; when it is not in yet, all: \"recommended\" changes nothing and says so, ' +\n \"and blocks named with `recommended` or a release line are `skipped`. Progress \" +\n \"notifications count the blocks.\\n\\n\" +\n \"Result: `{ blocks: [{ blockId, label, from, to, status, reason?, readiness? }], done, \" +\n \"failed, skipped, unchanged, stoppedBy?, note? }`; status is done, failed, \" +\n \"skipped or unchanged (already on that version, or nothing recommended). Labels and \" +\n \"reasons are cut short; `readiness` is the status and at most \" +\n `${UPDATE_READINESS_BLOCKERS} blockers (get_block_state gives it in full).`,\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n updates: z\n .array(\n z.object({\n blockId: blockIdInput.describe(\"Block ID\"),\n to: updateTargetInput.describe(\n 'What to update to: \"recommended\", \"patch\", \"minor\", \"major\", or a block pack spec.',\n ),\n }),\n )\n .optional()\n .describe(\"The blocks to update, each once. Give this or `all`.\"),\n all: z\n .literal(\"recommended\")\n .optional()\n .describe(\n \"Update every block with a recommended registry update, as Update All does. Give \" +\n \"this or `updates`.\",\n ),\n timeout: z\n .number()\n .optional()\n .describe(\n `No block starts updating after this many ms (default ${AWAIT_DEFAULT_MS}, at most ` +\n `${AWAIT_MAX_MS}).`,\n ),\n }),\n },\n async ({ timeout, ...input }, call) => {\n return await ctx.withProject(input.projectId, (project) =>\n updateBlocks(project, input, {\n author: ctx.getAuthorMarker,\n timeoutMs: clampWait(timeout, AWAIT_DEFAULT_MS, AWAIT_MIN_MS, AWAIT_MAX_MS),\n signal: call.mcpReq.signal,\n onProgress: progressReporter(call, \"Updating blocks\", 1),\n }),\n );\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,MAAM,sBAAsB;;;;;;AA0E5B,MAAa,uBAAuB;;AAGpC,MAAa,4BACX;;;;;;AAQF,e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