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