@milaboratories/pl-mcp-server 54.0.0 → 55.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/README.md +15 -25
  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 +15 -12
  8. package/dist/instructions.cjs.map +1 -1
  9. package/dist/instructions.js +15 -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 +58 -8
  14. package/dist/project-holds.cjs.map +1 -1
  15. package/dist/project-holds.js +58 -8
  16. package/dist/project-holds.js.map +1 -1
  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 +40 -18
  22. package/dist/server-log.cjs.map +1 -1
  23. package/dist/server-log.js +40 -19
  24. package/dist/server-log.js.map +1 -1
  25. package/dist/server.cjs +48 -18
  26. package/dist/server.cjs.map +1 -1
  27. package/dist/server.d.ts +21 -20
  28. package/dist/server.d.ts.map +1 -1
  29. package/dist/server.js +48 -18
  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 -73
  36. package/dist/tools/await.cjs.map +1 -1
  37. package/dist/tools/await.js +212 -75
  38. package/dist/tools/await.js.map +1 -1
  39. package/dist/tools/block-action-context.cjs +3 -0
  40. package/dist/tools/block-action-context.cjs.map +1 -1
  41. package/dist/tools/block-action-context.js +3 -0
  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 +272 -4
  48. package/dist/tools/block-params.cjs.map +1 -1
  49. package/dist/tools/block-params.js +270 -6
  50. package/dist/tools/block-params.js.map +1 -1
  51. package/dist/tools/block-state.cjs +323 -42
  52. package/dist/tools/block-state.cjs.map +1 -1
  53. package/dist/tools/block-state.js +317 -46
  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 +183 -70
  64. package/dist/tools/blocks.cjs.map +1 -1
  65. package/dist/tools/blocks.js +177 -70
  66. package/dist/tools/blocks.js.map +1 -1
  67. package/dist/tools/data-query.cjs +451 -113
  68. package/dist/tools/data-query.cjs.map +1 -1
  69. package/dist/tools/data-query.js +446 -118
  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 +56 -0
  80. package/dist/tools/ids.cjs.map +1 -1
  81. package/dist/tools/ids.js +51 -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 +98 -19
  88. package/dist/tools/logs.cjs.map +1 -1
  89. package/dist/tools/logs.js +95 -20
  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 +66 -19
  104. package/dist/tools/projects.cjs.map +1 -1
  105. package/dist/tools/projects.js +66 -20
  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 +15 -12
  143. package/src/project-holds.test.ts +179 -0
  144. package/src/project-holds.ts +114 -12
  145. package/src/project-list.test.ts +38 -0
  146. package/src/project-list.ts +25 -0
  147. package/src/server-log.test.ts +54 -1
  148. package/src/server-log.ts +49 -27
  149. package/src/server.logging.test.ts +38 -46
  150. package/src/server.test.ts +151 -17
  151. package/src/server.ts +62 -34
  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 -123
  156. package/src/tools/block-action-context.ts +3 -0
  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 +623 -8
  160. package/src/tools/block-state.test.ts +480 -0
  161. package/src/tools/block-state.ts +659 -66
  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 +336 -105
  168. package/src/tools/data-query.test.ts +641 -0
  169. package/src/tools/data-query.ts +807 -157
  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 +67 -0
  176. package/src/tools/imports.ts +304 -0
  177. package/src/tools/logs.test.ts +70 -0
  178. package/src/tools/logs.ts +130 -21
  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 +135 -25
  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 +77 -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,260 @@
1
+ const require_types = require("./types.cjs");
2
+ const require_ids = require("./ids.cjs");
3
+ const require_paging = require("./paging.cjs");
4
+ const require_sandbox = require("./sandbox.cjs");
5
+ const require_readiness = require("./readiness.cjs");
6
+ let zod = require("zod");
7
+ let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
8
+ /** A regular expression the pattern of a selector must compile to. */
9
+ function regexText(what) {
10
+ return zod.z.string().superRefine((value, ctx) => {
11
+ try {
12
+ new RegExp(value);
13
+ } catch (err) {
14
+ ctx.addIssue({
15
+ code: "custom",
16
+ message: `${what} is not a valid regular expression: ${err instanceof Error ? err.message : String(err)}`
17
+ });
18
+ }
19
+ });
20
+ }
21
+ const stringMatcher = zod.z.union([zod.z.strictObject({
22
+ type: zod.z.literal("exact"),
23
+ value: zod.z.string()
24
+ }), zod.z.strictObject({
25
+ type: zod.z.literal("regex"),
26
+ value: regexText("A `regex` matcher")
27
+ })]).meta({ id: "StringMatcher" });
28
+ /** A plain string is a regular expression, as in the SDK. */
29
+ const relaxedMatchers = zod.z.union([
30
+ regexText("A plain-string matcher"),
31
+ stringMatcher,
32
+ zod.z.array(zod.z.union([regexText("A plain-string matcher"), stringMatcher]))
33
+ ]).meta({ id: "RelaxedStringMatchers" });
34
+ const relaxedRecord = zod.z.record(zod.z.string(), relaxedMatchers);
35
+ const valueType = zod.z.enum(_milaboratories_pl_model_common.ValueType).meta({ id: "ValueType" });
36
+ const axisValueType = zod.z.enum([
37
+ "Int",
38
+ "Long",
39
+ "String"
40
+ ]);
41
+ const relaxedAxisSelector = zod.z.strictObject({
42
+ name: relaxedMatchers.optional(),
43
+ type: zod.z.union([axisValueType, zod.z.array(axisValueType)]).optional(),
44
+ domain: relaxedRecord.optional(),
45
+ contextDomain: relaxedRecord.optional(),
46
+ annotations: relaxedRecord.optional()
47
+ }).meta({ id: "RelaxedAxisSelector" });
48
+ const relaxedColumnSelector = zod.z.strictObject({
49
+ name: relaxedMatchers.optional(),
50
+ type: zod.z.union([valueType, zod.z.array(valueType)]).optional(),
51
+ domain: relaxedRecord.optional(),
52
+ contextDomain: relaxedRecord.optional(),
53
+ annotations: relaxedRecord.optional(),
54
+ axes: zod.z.array(relaxedAxisSelector).optional(),
55
+ partialAxesMatch: zod.z.boolean().optional()
56
+ }).meta({ id: "RelaxedColumnSelector" });
57
+ /** `ColumnSelector`: one selector or several, any of which may match. */
58
+ const columnSelectorInput = zod.z.union([relaxedColumnSelector, zod.z.array(relaxedColumnSelector)]).meta({ id: "ColumnSelector" });
59
+ /**
60
+ * An anchor of `ColumnsCollection.discover`: the id of a column of the pool (its `columnId` as
61
+ * list_pool_columns lists it without anchors, or its PlRef object), or a selector that matches one
62
+ * column.
63
+ */
64
+ const poolAnchorInput = zod.z.union([
65
+ zod.z.string(),
66
+ require_ids.plRefObject,
67
+ relaxedColumnSelector
68
+ ]).transform((raw, ctx) => {
69
+ if (typeof raw !== "string" && !(0, _milaboratories_pl_model_common.isPlRef)(raw)) return raw;
70
+ const id = require_ids.columnIdFromAgent(raw);
71
+ if (id !== void 0 && (0, _milaboratories_pl_model_common.isPObjectId)(id)) return id;
72
+ ctx.addIssue({
73
+ code: "custom",
74
+ message: "an anchor is a `columnId` that list_pool_columns gives without anchors, its `ref`, or a selector"
75
+ });
76
+ return zod.z.NEVER;
77
+ });
78
+ /** The `include` / `exclude` pair of `ColumnsCollection.filter`. */
79
+ const poolSelectorInput = zod.z.strictObject({
80
+ include: columnSelectorInput.optional(),
81
+ exclude: columnSelectorInput.optional()
82
+ });
83
+ const POOL_NOT_COMPLETE_NOTE = "Some blocks in view are still being calculated: more columns may appear when they finish.";
84
+ /** The titles of the project's blocks by id, or the error result to return. */
85
+ async function blockTitles(project, projectId, blockId) {
86
+ const overview = await project.overview.getValue();
87
+ if (overview === void 0) return { error: require_types.errorResult("Project overview not available yet. Try again.") };
88
+ if (blockId !== void 0) {
89
+ const { error } = await require_readiness.findBlock(project, projectId, blockId);
90
+ if (error) return { error };
91
+ }
92
+ const titles = /* @__PURE__ */ new Map();
93
+ for (const b of overview.blocks) if (b.title !== void 0) titles.set(b.id, b.title);
94
+ return { titles };
95
+ }
96
+ /** Reads the pool columns, or the error result to return. */
97
+ async function readPool(project, projectId, input) {
98
+ const { titles, error } = await blockTitles(project, projectId, input.blockId);
99
+ if (error !== void 0) return { error };
100
+ try {
101
+ return {
102
+ pool: await project.getPoolColumns({
103
+ viewAs: input.blockId,
104
+ include: input.selector?.include,
105
+ exclude: input.selector?.exclude,
106
+ anchors: input.anchors,
107
+ mode: input.mode,
108
+ maxHops: input.maxHops
109
+ }).getValue(),
110
+ titles
111
+ };
112
+ } catch (err) {
113
+ const message = err instanceof Error ? err.message : String(err);
114
+ return { error: input.anchors !== void 0 ? require_types.errorResult(`The anchors or the selector were not accepted: ${message}`, "An anchor selector must match exactly one column, and two anchors not the same one.") : input.selector !== void 0 ? require_types.errorResult(`The selector was not accepted: ${message}`, "Check the selector against the ColumnSelector type of the SDK; a plain string is a regular expression.") : require_types.errorResult(`Reading the result pool failed: ${message}`) };
115
+ }
116
+ }
117
+ function axisEntry(a, full) {
118
+ return {
119
+ name: a.name,
120
+ type: a.type,
121
+ ...a.domain !== void 0 && Object.keys(a.domain).length > 0 ? { domain: a.domain } : {},
122
+ ...(0, _milaboratories_pl_model_common.readAnnotation)(a, _milaboratories_pl_model_common.Annotation.Label) !== void 0 ? { label: (0, _milaboratories_pl_model_common.readAnnotation)(a, _milaboratories_pl_model_common.Annotation.Label) } : {},
123
+ ...full && a.annotations !== void 0 ? { annotations: a.annotations } : {}
124
+ };
125
+ }
126
+ function nonEmpty(r) {
127
+ return r !== void 0 && Object.keys(r).length > 0 ? r : void 0;
128
+ }
129
+ /** One column as the pool tools show it. */
130
+ function poolColumnEntry(c, titles, full) {
131
+ const spec = c.spec;
132
+ const label = (0, _milaboratories_pl_model_common.readAnnotation)(spec, _milaboratories_pl_model_common.Annotation.Label);
133
+ const title = titles.get(c.producedBy);
134
+ const domain = nonEmpty(spec.domain);
135
+ const contextDomain = nonEmpty(spec.contextDomain);
136
+ return {
137
+ columnId: c.columnId,
138
+ ...c.ref !== void 0 ? { ref: c.ref } : {},
139
+ ...c.path !== void 0 ? { path: c.path } : {},
140
+ exportName: c.exportName,
141
+ producedBy: {
142
+ blockId: c.producedBy,
143
+ ...title !== void 0 ? { label: title } : {}
144
+ },
145
+ name: spec.name,
146
+ ...label !== void 0 ? { label } : {},
147
+ valueType: spec.valueType,
148
+ axes: spec.axesSpec.map((a) => axisEntry(a, full)),
149
+ ...domain !== void 0 ? { domain } : {},
150
+ ...contextDomain !== void 0 ? { contextDomain } : {},
151
+ ...full && spec.annotations !== void 0 ? { annotations: spec.annotations } : {}
152
+ };
153
+ }
154
+ /** The result-pool columns of a project, filtered and paged (`list_pool_columns`). */
155
+ async function listPoolColumnsResult(project, projectId, input) {
156
+ const read = await readPool(project, projectId, input);
157
+ if (read.error) return read.error;
158
+ const { pool, titles } = read;
159
+ const matching = pool.columns;
160
+ const offset = input.offset ?? 0;
161
+ const limit = input.limit ?? 50;
162
+ const pageItems = matching.slice(offset, offset + limit);
163
+ const end = offset + pageItems.length;
164
+ const full = input.detail === "full";
165
+ return require_types.textResult({
166
+ total: matching.length,
167
+ offset,
168
+ hasMore: end < matching.length,
169
+ ...end < matching.length ? { nextOffset: end } : {},
170
+ ...pool.isComplete ? {} : {
171
+ isComplete: false,
172
+ note: POOL_NOT_COMPLETE_NOTE
173
+ },
174
+ columns: pageItems.map((c) => poolColumnEntry(c, titles, full))
175
+ }, { hint: "Ask for fewer columns: a smaller `limit`, `detail: \"summary\"` or a `selector`." });
176
+ }
177
+ /** Default timeout of a `transform` of `get_pool_column`, in milliseconds. */
178
+ const DEFAULT_TRANSFORM_TIMEOUT = 5e3;
179
+ const POOL_COLUMN_TRANSFORM_VARIABLES = "`spec`, `columnId`, `ref`, `path`, `exportName`, `producedBy`";
180
+ /**
181
+ * One column of the result pool with its whole spec (`get_pool_column`), or, with `transform`, the
182
+ * value of that expression evaluated in the sandbox against it (variables `spec`, `columnId`, `ref`,
183
+ * `path`, `exportName` and `producedBy`).
184
+ */
185
+ async function poolColumnResult(project, projectId, input) {
186
+ const { titles, error } = await blockTitles(project, projectId, input.blockId);
187
+ if (error !== void 0) return error;
188
+ const [column] = await project.getPoolColumnsById([input.columnId], input.blockId).getValue();
189
+ if (column === void 0) return require_types.errorResult(`Column ${input.columnId} is not in the result pool of project ${projectId}` + (input.blockId !== void 0 ? ` as block ${input.blockId} sees it.` : "."), "list_pool_columns lists the column ids of the pool" + (input.blockId !== void 0 ? "; a block sees only its own columns and those of the blocks above it" : "") + "; ids follow current specs: list_pool_columns again.");
190
+ const title = titles.get(column.producedBy);
191
+ const producedBy = {
192
+ blockId: column.producedBy,
193
+ ...title !== void 0 ? { label: title } : {}
194
+ };
195
+ if (input.transform) try {
196
+ return require_types.textResult(await require_sandbox.safeEval(input.transform, {
197
+ spec: column.spec,
198
+ columnId: column.columnId,
199
+ ref: column.ref,
200
+ path: column.path,
201
+ exportName: column.exportName,
202
+ producedBy
203
+ }, input.transformTimeout ?? DEFAULT_TRANSFORM_TIMEOUT));
204
+ } catch (e) {
205
+ return require_types.transformFailedResult(e, `Check your JS expression syntax. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES}.`);
206
+ }
207
+ return require_types.textResult({
208
+ columnId: column.columnId,
209
+ ...column.ref !== void 0 ? { ref: column.ref } : {},
210
+ ...column.path !== void 0 ? { path: column.path } : {},
211
+ exportName: column.exportName,
212
+ producedBy,
213
+ spec: column.spec
214
+ }, { hint: "Read part of the spec with `transform`, e.g. `spec.annotations`, `spec.domain` or `spec.axesSpec[0]`." });
215
+ }
216
+ const WHAT_THE_POOL_IS = "The result pool is the set of columns that blocks export for blocks below them: a block sees the columns of the blocks above it and its own.";
217
+ function registerResultPoolTools(server, ctx) {
218
+ server.registerTool("list_pool_columns", {
219
+ title: "List Result Pool Columns",
220
+ annotations: require_types.hints.read,
221
+ description: `${WHAT_THE_POOL_IS} List those columns with their specs, a page at a time: \`{ total, offset, hasMore, nextOffset?, isComplete?, columns: [{ columnId, ref?, path?, exportName, producedBy: { blockId, label? }, name, label?, valueType, axes: [{ name, type, domain?, label? }], domain?, contextDomain?, annotations? }] }\` (annotations with \`detail: "full"\`). With \`blockId\`, the pool as that block sees it; without, every block's columns. Use it to see what data a project has, and to write or check the column selector of a block's model: \`selector\` takes \`{ include?, exclude? }\` exactly as a model passes them to \`ColumnsCollection(["result_pool"]).filter(…)\`; the result is what the selector matches here. \`anchors\` lists the columns reachable from those columns, through linker columns too, with discovered ids and the linker ids in \`path\`; \`ref\` is the object form of a leaf's \`columnId\`; \`exportName\` is the name its block exports the column under. Specs only, no values. A block's choices are in its own option outputs (get_block_outputs); a column's \`ref\`, or its \`columnId\` when it has a \`ref\`, fits a block field of that form (get_block_contract).`,
222
+ inputSchema: zod.z.object({
223
+ projectId: require_ids.projectIdInput.describe("Project ID"),
224
+ blockId: require_ids.blockIdInput.optional().describe("See the pool as this block does: its own columns and those of blocks above."),
225
+ selector: poolSelectorInput.optional().describe("`{ include?, exclude? }` of `ColumnsCollection.filter`: a `ColumnSelector` each (one selector or an array, any of which may match). A selector has `name`, `type`, `domain`, `contextDomain`, `annotations`, `axes`, `partialAxesMatch`; a matcher is `{ type: \"exact\" | \"regex\", value }`; a plain string is a regex found anywhere in the value, case-sensitive (`^…$` for all of it). E.g. by label `{ include: { annotations: { \"pl7.app/label\": \"Score\" } } }`; by type and axis `{ include: { type: \"Double\", axes: [{ name: \"pl7.app/sampleId\" }] } }`."),
226
+ anchors: zod.z.record(zod.z.string(), poolAnchorInput).optional().describe("Name → anchor column: its `columnId` (as listed without anchors), its `ref`, or a selector matching one column. Lists what `ColumnsCollection.discover({ anchors })` finds from them; `selector` narrows it."),
227
+ mode: zod.z.enum([
228
+ "enrichment",
229
+ "related",
230
+ "exact"
231
+ ]).optional().describe("With `anchors`, how axes may match theirs: `enrichment` (default), `related` (widest) or `exact`."),
232
+ maxHops: zod.z.number().int().min(0).max(8).optional().describe("With `anchors`, the most linker columns on the way (default 4)."),
233
+ detail: zod.z.enum(["summary", "full"]).optional().describe("`summary` (default): no annotations; `full`: column and axis annotations."),
234
+ ...require_paging.pagingArgs("columns", 50, 200)
235
+ })
236
+ }, async ({ projectId, ...input }) => await ctx.withProject(projectId, (project) => listPoolColumnsResult(project, projectId, input)));
237
+ server.registerTool("get_pool_column", {
238
+ title: "Get Result Pool Column",
239
+ annotations: require_types.hints.read,
240
+ description: "Get one column of the result pool with its whole spec: `{ columnId, ref?, path?, exportName, producedBy: { blockId, label? }, spec }`, the spec with every domain and annotation of the column and its axes. Column ids come from list_pool_columns. Specs only, no values: get_column_values reads them. Read part of a large spec with `transform`, e.g. `spec.annotations`.",
241
+ inputSchema: zod.z.object({
242
+ projectId: require_ids.projectIdInput.describe("Project ID"),
243
+ columnId: require_ids.columnIdInput.describe("Column id from list_pool_columns, or a PlRef object."),
244
+ blockId: require_ids.blockIdInput.optional().describe("Look the column up as this block sees the pool (default: every block's)."),
245
+ transform: zod.z.string().optional().describe(`JS expression evaluated server-side against the column. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES} (\`{ blockId, label? }\`). Omit for the whole answer.`),
246
+ transformTimeout: zod.z.number().optional().default(DEFAULT_TRANSFORM_TIMEOUT).describe(require_sandbox.expressionTimeoutText("transform evaluation", DEFAULT_TRANSFORM_TIMEOUT))
247
+ })
248
+ }, async ({ projectId, ...input }) => await ctx.withProject(projectId, (project) => poolColumnResult(project, projectId, input)));
249
+ }
250
+ exports.WHAT_THE_POOL_IS = WHAT_THE_POOL_IS;
251
+ exports.columnSelectorInput = columnSelectorInput;
252
+ exports.listPoolColumnsResult = listPoolColumnsResult;
253
+ exports.poolAnchorInput = poolAnchorInput;
254
+ exports.poolColumnEntry = poolColumnEntry;
255
+ exports.poolColumnResult = poolColumnResult;
256
+ exports.poolSelectorInput = poolSelectorInput;
257
+ exports.regexText = regexText;
258
+ exports.registerResultPoolTools = registerResultPoolTools;
259
+
260
+ //# sourceMappingURL=result-pool.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-pool.cjs","names":["z","ValueType","plRefObject","isPlRef","columnIdFromAgent","isPObjectId","errorResult","findBlock","readAnnotation","Annotation","textResult","safeEval","transformFailedResult","hints","projectIdInput","blockIdInput","pagingArgs","columnIdInput","expressionTimeoutText"],"sources":["../../src/tools/result-pool.ts"],"sourcesContent":["import type {\n BlockStateOverview,\n PoolColumn,\n PoolColumns,\n PoolColumnsQuery,\n} from \"@milaboratories/pl-middle-layer\";\nimport {\n Annotation,\n isPlRef,\n isPObjectId,\n readAnnotation,\n ValueType,\n type AnchorEntry,\n type AxisSpec,\n type BlockId,\n type ColumnSelector,\n type ColumnUniversalId,\n type MatchingMode,\n type ProjectId,\n type RelaxedAxisSelector,\n type RelaxedColumnSelector,\n type StringMatcher,\n} from \"@milaboratories/pl-model-common\";\nimport { z } from \"zod\";\nimport { blockIdInput, columnIdFromAgent, columnIdInput, plRefObject, projectIdInput } from \"./ids\";\nimport { pagingArgs } from \"./paging\";\nimport { findBlock, type BlockLookupProject } from \"./readiness\";\nimport { expressionTimeoutText, safeEval } from \"./sandbox\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult, transformFailedResult } from \"./types\";\n\n/** Default page of {@link listPoolColumnsResult}. */\nexport const POOL_COLUMNS_DEFAULT = 50;\n/** Largest page of {@link listPoolColumnsResult}. */\nexport const POOL_COLUMNS_MAX = 200;\n\n// Selectors, in the forms block models pass them. Typed against the SDK's types, so a schema that\n// drifts from them does not compile.\n//\n// The schemas used more than once carry an `id`: the JSON Schema a client is sent then defines each\n// once under `$defs` and refers to it, instead of repeating it at every use (40 kB of arguments for\n// list_pool_columns otherwise). The id is the name of the SDK type the schema stands for.\n\n/** A regular expression the pattern of a selector must compile to. */\nexport function regexText(what: string) {\n return z.string().superRefine((value, ctx) => {\n try {\n new RegExp(value);\n } catch (err) {\n ctx.addIssue({\n code: \"custom\",\n message: `${what} is not a valid regular expression: ${err instanceof Error ? err.message : String(err)}`,\n });\n }\n });\n}\n\nconst stringMatcher: z.ZodType<StringMatcher> = z\n .union([\n z.strictObject({ type: z.literal(\"exact\"), value: z.string() }),\n z.strictObject({ type: z.literal(\"regex\"), value: regexText(\"A `regex` matcher\") }),\n ])\n .meta({ id: \"StringMatcher\" });\n\n/** A plain string is a regular expression, as in the SDK. */\nconst relaxedMatchers = z\n .union([\n regexText(\"A plain-string matcher\"),\n stringMatcher,\n z.array(z.union([regexText(\"A plain-string matcher\"), stringMatcher])),\n ])\n .meta({ id: \"RelaxedStringMatchers\" });\n\nconst relaxedRecord = z.record(z.string(), relaxedMatchers);\nconst valueType = z.enum(ValueType).meta({ id: \"ValueType\" });\nconst axisValueType = z.enum([\"Int\", \"Long\", \"String\"]);\n\nconst relaxedAxisSelector: z.ZodType<RelaxedAxisSelector> = z\n .strictObject({\n name: relaxedMatchers.optional(),\n type: z.union([axisValueType, z.array(axisValueType)]).optional(),\n domain: relaxedRecord.optional(),\n contextDomain: relaxedRecord.optional(),\n annotations: relaxedRecord.optional(),\n })\n .meta({ id: \"RelaxedAxisSelector\" });\n\nconst relaxedColumnSelector: z.ZodType<RelaxedColumnSelector> = z\n .strictObject({\n name: relaxedMatchers.optional(),\n type: z.union([valueType, z.array(valueType)]).optional(),\n domain: relaxedRecord.optional(),\n contextDomain: relaxedRecord.optional(),\n annotations: relaxedRecord.optional(),\n axes: z.array(relaxedAxisSelector).optional(),\n partialAxesMatch: z.boolean().optional(),\n })\n .meta({ id: \"RelaxedColumnSelector\" });\n\n/** `ColumnSelector`: one selector or several, any of which may match. */\nexport const columnSelectorInput: z.ZodType<ColumnSelector> = z\n .union([relaxedColumnSelector, z.array(relaxedColumnSelector)])\n .meta({ id: \"ColumnSelector\" });\n\n/**\n * An anchor of `ColumnsCollection.discover`: the id of a column of the pool (its `columnId` as\n * list_pool_columns lists it without anchors, or its PlRef object), or a selector that matches one\n * column.\n */\nexport const poolAnchorInput = z\n .union([z.string(), plRefObject, relaxedColumnSelector])\n .transform((raw, ctx): AnchorEntry => {\n if (typeof raw !== \"string\" && !isPlRef(raw)) return raw;\n const id = columnIdFromAgent(raw);\n if (id !== undefined && isPObjectId(id)) return id;\n ctx.addIssue({\n code: \"custom\",\n message:\n \"an anchor is a `columnId` that list_pool_columns gives without anchors, its `ref`, \" +\n \"or a selector\",\n });\n return z.NEVER;\n });\n\n/** The `include` / `exclude` pair of `ColumnsCollection.filter`. */\nexport const poolSelectorInput = z.strictObject({\n include: columnSelectorInput.optional(),\n exclude: columnSelectorInput.optional(),\n});\n\n// Results\n\n/** What the pool tools need of a project: its overview (block titles) and its pool columns. */\nexport type PoolProject = BlockLookupProject<Pick<BlockStateOverview, \"id\" | \"title\">> & {\n getPoolColumns(query: PoolColumnsQuery): { getValue(): Promise<PoolColumns> };\n getPoolColumnsById(\n ids: readonly ColumnUniversalId[],\n viewAs?: BlockId,\n ): { getValue(): Promise<(PoolColumn | undefined)[]> };\n};\n\n/** Which part of the pool a tool reads, and how it is filtered. */\nexport type PoolListInput = {\n blockId?: BlockId;\n selector?: { include?: ColumnSelector; exclude?: ColumnSelector };\n /** Columns to discover from: the pool lists what is reachable from them, with discovered ids. */\n anchors?: Record<string, AnchorEntry>;\n mode?: MatchingMode;\n maxHops?: number;\n detail?: \"summary\" | \"full\";\n limit?: number;\n offset?: number;\n};\n\nconst POOL_NOT_COMPLETE_NOTE =\n \"Some blocks in view are still being calculated: more columns may appear when they finish.\";\n\n/** The titles of the project's blocks by id, or the error result to return. */\nasync function blockTitles(\n project: PoolProject,\n projectId: ProjectId,\n blockId: BlockId | undefined,\n): Promise<\n | { titles: Map<string, string>; error?: undefined }\n | { titles?: undefined; error: ReturnType<typeof errorResult> }\n> {\n const overview = await project.overview.getValue();\n if (overview === undefined)\n return { error: errorResult(\"Project overview not available yet. Try again.\") };\n if (blockId !== undefined) {\n const { error } = await findBlock(project, projectId, blockId);\n if (error) return { error };\n }\n const titles = new Map<string, string>();\n for (const b of overview.blocks) if (b.title !== undefined) titles.set(b.id, b.title);\n return { titles };\n}\n\n/** Reads the pool columns, or the error result to return. */\nasync function readPool(\n project: PoolProject,\n projectId: ProjectId,\n input: Pick<PoolListInput, \"blockId\" | \"selector\" | \"anchors\" | \"mode\" | \"maxHops\">,\n): Promise<\n | { pool: PoolColumns; titles: Map<string, string>; error?: undefined }\n | { error: ReturnType<typeof errorResult> }\n> {\n const { titles, error } = await blockTitles(project, projectId, input.blockId);\n if (error !== undefined) return { error };\n try {\n const pool = await project\n .getPoolColumns({\n viewAs: input.blockId,\n include: input.selector?.include,\n exclude: input.selector?.exclude,\n anchors: input.anchors,\n mode: input.mode,\n maxHops: input.maxHops,\n })\n .getValue();\n return { pool, titles };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n error:\n input.anchors !== undefined\n ? errorResult(\n `The anchors or the selector were not accepted: ${message}`,\n \"An anchor selector must match exactly one column, and two anchors not the same one.\",\n )\n : input.selector !== undefined\n ? errorResult(\n `The selector was not accepted: ${message}`,\n \"Check the selector against the ColumnSelector type of the SDK; a plain string is a regular expression.\",\n )\n : errorResult(`Reading the result pool failed: ${message}`),\n };\n }\n}\n\nfunction axisEntry(a: AxisSpec, full: boolean) {\n return {\n name: a.name,\n type: a.type,\n ...(a.domain !== undefined && Object.keys(a.domain).length > 0 ? { domain: a.domain } : {}),\n ...(readAnnotation(a, Annotation.Label) !== undefined\n ? { label: readAnnotation(a, Annotation.Label) }\n : {}),\n ...(full && a.annotations !== undefined ? { annotations: a.annotations } : {}),\n };\n}\n\nfunction nonEmpty(r: Record<string, string> | undefined): Record<string, string> | undefined {\n return r !== undefined && Object.keys(r).length > 0 ? r : undefined;\n}\n\n/** One column as the pool tools show it. */\nexport function poolColumnEntry(c: PoolColumn, titles: Map<string, string>, full: boolean) {\n const spec = c.spec;\n const label = readAnnotation(spec, Annotation.Label);\n const title = titles.get(c.producedBy);\n const domain = nonEmpty(spec.domain);\n const contextDomain = nonEmpty(spec.contextDomain);\n return {\n columnId: c.columnId,\n ...(c.ref !== undefined ? { ref: c.ref } : {}),\n ...(c.path !== undefined ? { path: c.path } : {}),\n exportName: c.exportName,\n producedBy: { blockId: c.producedBy, ...(title !== undefined ? { label: title } : {}) },\n name: spec.name,\n ...(label !== undefined ? { label } : {}),\n valueType: spec.valueType,\n axes: spec.axesSpec.map((a) => axisEntry(a, full)),\n ...(domain !== undefined ? { domain } : {}),\n ...(contextDomain !== undefined ? { contextDomain } : {}),\n ...(full && spec.annotations !== undefined ? { annotations: spec.annotations } : {}),\n };\n}\n\n/** The result-pool columns of a project, filtered and paged (`list_pool_columns`). */\nexport async function listPoolColumnsResult(\n project: PoolProject,\n projectId: ProjectId,\n input: PoolListInput,\n) {\n const read = await readPool(project, projectId, input);\n if (read.error) return read.error;\n const { pool, titles } = read;\n const matching = pool.columns;\n const offset = input.offset ?? 0;\n const limit = input.limit ?? POOL_COLUMNS_DEFAULT;\n const pageItems = matching.slice(offset, offset + limit);\n const end = offset + pageItems.length;\n const full = input.detail === \"full\";\n return textResult(\n {\n total: matching.length,\n offset,\n hasMore: end < matching.length,\n ...(end < matching.length ? { nextOffset: end } : {}),\n ...(pool.isComplete ? {} : { isComplete: false, note: POOL_NOT_COMPLETE_NOTE }),\n columns: pageItems.map((c) => poolColumnEntry(c, titles, full)),\n },\n {\n hint: 'Ask for fewer columns: a smaller `limit`, `detail: \"summary\"` or a `selector`.',\n },\n );\n}\n\n/** Default timeout of a `transform` of `get_pool_column`, in milliseconds. */\nconst DEFAULT_TRANSFORM_TIMEOUT = 5000;\n\nconst POOL_COLUMN_TRANSFORM_VARIABLES =\n \"`spec`, `columnId`, `ref`, `path`, `exportName`, `producedBy`\";\n\n/**\n * One column of the result pool with its whole spec (`get_pool_column`), or, with `transform`, the\n * value of that expression evaluated in the sandbox against it (variables `spec`, `columnId`, `ref`,\n * `path`, `exportName` and `producedBy`).\n */\nexport async function poolColumnResult(\n project: PoolProject,\n projectId: ProjectId,\n input: {\n columnId: ColumnUniversalId;\n blockId?: BlockId;\n transform?: string;\n transformTimeout?: number;\n },\n) {\n const { titles, error } = await blockTitles(project, projectId, input.blockId);\n if (error !== undefined) return error;\n const [column] = await project.getPoolColumnsById([input.columnId], input.blockId).getValue();\n if (column === undefined)\n return errorResult(\n `Column ${input.columnId} is not in the result pool of project ${projectId}` +\n (input.blockId !== undefined ? ` as block ${input.blockId} sees it.` : \".\"),\n \"list_pool_columns lists the column ids of the pool\" +\n (input.blockId !== undefined\n ? \"; a block sees only its own columns and those of the blocks above it\"\n : \"\") +\n \"; ids follow current specs: list_pool_columns again.\",\n );\n const title = titles.get(column.producedBy);\n const producedBy = {\n blockId: column.producedBy,\n ...(title !== undefined ? { label: title } : {}),\n };\n if (input.transform) {\n try {\n return textResult(\n await safeEval(\n input.transform,\n {\n spec: column.spec,\n columnId: column.columnId,\n ref: column.ref,\n path: column.path,\n exportName: column.exportName,\n producedBy,\n },\n input.transformTimeout ?? DEFAULT_TRANSFORM_TIMEOUT,\n ),\n );\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n `Check your JS expression syntax. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES}.`,\n );\n }\n }\n return textResult(\n {\n columnId: column.columnId,\n ...(column.ref !== undefined ? { ref: column.ref } : {}),\n ...(column.path !== undefined ? { path: column.path } : {}),\n exportName: column.exportName,\n producedBy,\n spec: column.spec,\n },\n {\n hint:\n \"Read part of the spec with `transform`, e.g. `spec.annotations`, `spec.domain` or \" +\n \"`spec.axesSpec[0]`.\",\n },\n );\n}\n\n// Tools\n\nexport const WHAT_THE_POOL_IS =\n \"The result pool is the set of columns that blocks export for blocks below them: a block sees \" +\n \"the columns of the blocks above it and its own.\";\n\nexport function registerResultPoolTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_pool_columns\",\n {\n title: \"List Result Pool Columns\",\n annotations: hints.read,\n description:\n `${WHAT_THE_POOL_IS} List those columns with their specs, a page at a time: \\`{ total, ` +\n \"offset, hasMore, nextOffset?, isComplete?, columns: [{ columnId, ref?, path?, \" +\n \"exportName, producedBy: { blockId, label? }, name, label?, valueType, axes: [{ name, \" +\n \"type, domain?, label? }], \" +\n 'domain?, contextDomain?, annotations? }] }` (annotations with `detail: \"full\"`). ' +\n \"With `blockId`, the pool as that block sees it; without, every block's columns. \" +\n \"Use it to see what data a project has, and to write or check the column selector of a \" +\n \"block's model: `selector` takes `{ include?, exclude? }` exactly as a model passes them \" +\n 'to `ColumnsCollection([\"result_pool\"]).filter(…)`; the result is what the ' +\n \"selector matches here. `anchors` lists the columns reachable from those columns, through \" +\n \"linker columns too, with discovered ids and the linker ids in `path`; `ref` is the \" +\n \"object form of a leaf's `columnId`; `exportName` is the name its block exports the \" +\n \"column under. Specs only, no values. A block's choices are in its own option outputs \" +\n \"(get_block_outputs); a column's `ref`, or its `columnId` when it has a `ref`, fits a \" +\n \"block field of that form (get_block_contract).\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput\n .optional()\n .describe(\"See the pool as this block does: its own columns and those of blocks above.\"),\n selector: poolSelectorInput\n .optional()\n .describe(\n \"`{ include?, exclude? }` of `ColumnsCollection.filter`: a `ColumnSelector` each \" +\n \"(one selector or an array, any of which may match). A selector has `name`, \" +\n \"`type`, `domain`, `contextDomain`, `annotations`, `axes`, `partialAxesMatch`; a \" +\n 'matcher is `{ type: \"exact\" | \"regex\", value }`; a plain string is a regex found ' +\n \"anywhere in the value, case-sensitive (`^…$` for all of it). E.g. by label \" +\n '`{ include: { annotations: { \"pl7.app/label\": \"Score\" } } }`; by type and axis ' +\n '`{ include: { type: \"Double\", axes: [{ name: \"pl7.app/sampleId\" }] } }`.',\n ),\n anchors: z\n .record(z.string(), poolAnchorInput)\n .optional()\n .describe(\n \"Name → anchor column: its `columnId` (as listed without anchors), its `ref`, or a \" +\n \"selector matching one column. Lists what `ColumnsCollection.discover({ anchors })` \" +\n \"finds from them; `selector` narrows it.\",\n ),\n mode: z\n .enum([\"enrichment\", \"related\", \"exact\"])\n .optional()\n .describe(\n \"With `anchors`, how axes may match theirs: `enrichment` (default), `related` \" +\n \"(widest) or `exact`.\",\n ),\n maxHops: z\n .number()\n .int()\n .min(0)\n .max(8)\n .optional()\n .describe(\"With `anchors`, the most linker columns on the way (default 4).\"),\n detail: z\n .enum([\"summary\", \"full\"])\n .optional()\n .describe(\"`summary` (default): no annotations; `full`: column and axis annotations.\"),\n ...pagingArgs(\"columns\", POOL_COLUMNS_DEFAULT, POOL_COLUMNS_MAX),\n }),\n },\n async ({ projectId, ...input }) =>\n await ctx.withProject(projectId, (project) =>\n listPoolColumnsResult(project, projectId, input),\n ),\n );\n\n server.registerTool(\n \"get_pool_column\",\n {\n title: \"Get Result Pool Column\",\n annotations: hints.read,\n description:\n \"Get one column of the result pool with its whole spec: `{ columnId, ref?, path?, \" +\n \"exportName, producedBy: { blockId, label? }, spec }`, the spec with every \" +\n \"domain and annotation of the column and its axes. Column ids come from \" +\n \"list_pool_columns. Specs only, no values: get_column_values reads them. \" +\n \"Read part of a large spec with `transform`, e.g. `spec.annotations`.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n columnId: columnIdInput.describe(\"Column id from list_pool_columns, or a PlRef object.\"),\n blockId: blockIdInput\n .optional()\n .describe(\"Look the column up as this block sees the pool (default: every block's).\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against the column. Available variables: \" +\n `${POOL_COLUMN_TRANSFORM_VARIABLES} (\\`{ blockId, label? }\\`). Omit for the whole ` +\n \"answer.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(DEFAULT_TRANSFORM_TIMEOUT)\n .describe(expressionTimeoutText(\"transform evaluation\", DEFAULT_TRANSFORM_TIMEOUT)),\n }),\n },\n async ({ projectId, ...input }) =>\n await ctx.withProject(projectId, (project) => poolColumnResult(project, projectId, input)),\n );\n}\n"],"mappings":";;;;;;;;AA4CA,SAAgB,UAAU,MAAc;CACtC,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,aAAa,OAAO,QAAQ;EAC5C,IAAI;GACF,IAAI,OAAO,KAAK;EAClB,SAAS,KAAK;GACZ,IAAI,SAAS;IACX,MAAM;IACN,SAAS,GAAG,KAAK,sCAAsC,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;GACxG,CAAC;EACH;CAC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;EACjE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,GAAG,YACrB,MAAM,IAAI,YAAY,YAAY,YAChC,sBAAsB,SAAS,WAAW,KAAK,CACjD,CACJ;CAEA,OAAO,aACL,mBACA;EACE,OAAO;EACP,aAAaH,cAAAA,MAAM;EACnB,aACE;EAKF,aAAab,IAAAA,EAAE,OAAO;GACpB,WAAWc,YAAAA,eAAe,SAAS,YAAY;GAC/C,UAAUG,YAAAA,cAAc,SAAS,sDAAsD;GACvF,SAASF,YAAAA,aACN,SAAS,CAAC,CACV,SAAS,0EAA0E;GACtF,WAAWf,IAAAA,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,gFACK,gCAAgC,uDAEvC;GACF,kBAAkBA,IAAAA,EACf,OAAO,CAAC,CACR,SAAS,CAAC,CACV,QAAQ,yBAAyB,CAAC,CAClC,SAASkB,gBAAAA,sBAAsB,wBAAwB,yBAAyB,CAAC;EACtF,CAAC;CACH,GACA,OAAO,EAAE,WAAW,GAAG,YACrB,MAAM,IAAI,YAAY,YAAY,YAAY,iBAAiB,SAAS,WAAW,KAAK,CAAC,CAC7F;AACF"}
@@ -0,0 +1,252 @@
1
+ import { errorResult, hints, textResult, transformFailedResult } from "./types.js";
2
+ import { blockIdInput, columnIdFromAgent, columnIdInput, plRefObject, projectIdInput } from "./ids.js";
3
+ import { pagingArgs } from "./paging.js";
4
+ import { expressionTimeoutText, safeEval } from "./sandbox.js";
5
+ import { findBlock } from "./readiness.js";
6
+ import { z } from "zod";
7
+ import { Annotation, ValueType, isPObjectId, isPlRef, readAnnotation } from "@milaboratories/pl-model-common";
8
+ /** A regular expression the pattern of a selector must compile to. */
9
+ function regexText(what) {
10
+ return z.string().superRefine((value, ctx) => {
11
+ try {
12
+ new RegExp(value);
13
+ } catch (err) {
14
+ ctx.addIssue({
15
+ code: "custom",
16
+ message: `${what} is not a valid regular expression: ${err instanceof Error ? err.message : String(err)}`
17
+ });
18
+ }
19
+ });
20
+ }
21
+ const stringMatcher = z.union([z.strictObject({
22
+ type: z.literal("exact"),
23
+ value: z.string()
24
+ }), z.strictObject({
25
+ type: z.literal("regex"),
26
+ value: regexText("A `regex` matcher")
27
+ })]).meta({ id: "StringMatcher" });
28
+ /** A plain string is a regular expression, as in the SDK. */
29
+ const relaxedMatchers = z.union([
30
+ regexText("A plain-string matcher"),
31
+ stringMatcher,
32
+ z.array(z.union([regexText("A plain-string matcher"), stringMatcher]))
33
+ ]).meta({ id: "RelaxedStringMatchers" });
34
+ const relaxedRecord = z.record(z.string(), relaxedMatchers);
35
+ const valueType = z.enum(ValueType).meta({ id: "ValueType" });
36
+ const axisValueType = z.enum([
37
+ "Int",
38
+ "Long",
39
+ "String"
40
+ ]);
41
+ const relaxedAxisSelector = z.strictObject({
42
+ name: relaxedMatchers.optional(),
43
+ type: z.union([axisValueType, z.array(axisValueType)]).optional(),
44
+ domain: relaxedRecord.optional(),
45
+ contextDomain: relaxedRecord.optional(),
46
+ annotations: relaxedRecord.optional()
47
+ }).meta({ id: "RelaxedAxisSelector" });
48
+ const relaxedColumnSelector = z.strictObject({
49
+ name: relaxedMatchers.optional(),
50
+ type: z.union([valueType, z.array(valueType)]).optional(),
51
+ domain: relaxedRecord.optional(),
52
+ contextDomain: relaxedRecord.optional(),
53
+ annotations: relaxedRecord.optional(),
54
+ axes: z.array(relaxedAxisSelector).optional(),
55
+ partialAxesMatch: z.boolean().optional()
56
+ }).meta({ id: "RelaxedColumnSelector" });
57
+ /** `ColumnSelector`: one selector or several, any of which may match. */
58
+ const columnSelectorInput = z.union([relaxedColumnSelector, z.array(relaxedColumnSelector)]).meta({ id: "ColumnSelector" });
59
+ /**
60
+ * An anchor of `ColumnsCollection.discover`: the id of a column of the pool (its `columnId` as
61
+ * list_pool_columns lists it without anchors, or its PlRef object), or a selector that matches one
62
+ * column.
63
+ */
64
+ const poolAnchorInput = z.union([
65
+ z.string(),
66
+ plRefObject,
67
+ relaxedColumnSelector
68
+ ]).transform((raw, ctx) => {
69
+ if (typeof raw !== "string" && !isPlRef(raw)) return raw;
70
+ const id = columnIdFromAgent(raw);
71
+ if (id !== void 0 && isPObjectId(id)) return id;
72
+ ctx.addIssue({
73
+ code: "custom",
74
+ message: "an anchor is a `columnId` that list_pool_columns gives without anchors, its `ref`, or a selector"
75
+ });
76
+ return z.NEVER;
77
+ });
78
+ /** The `include` / `exclude` pair of `ColumnsCollection.filter`. */
79
+ const poolSelectorInput = z.strictObject({
80
+ include: columnSelectorInput.optional(),
81
+ exclude: columnSelectorInput.optional()
82
+ });
83
+ const POOL_NOT_COMPLETE_NOTE = "Some blocks in view are still being calculated: more columns may appear when they finish.";
84
+ /** The titles of the project's blocks by id, or the error result to return. */
85
+ async function blockTitles(project, projectId, blockId) {
86
+ const overview = await project.overview.getValue();
87
+ if (overview === void 0) return { error: errorResult("Project overview not available yet. Try again.") };
88
+ if (blockId !== void 0) {
89
+ const { error } = await findBlock(project, projectId, blockId);
90
+ if (error) return { error };
91
+ }
92
+ const titles = /* @__PURE__ */ new Map();
93
+ for (const b of overview.blocks) if (b.title !== void 0) titles.set(b.id, b.title);
94
+ return { titles };
95
+ }
96
+ /** Reads the pool columns, or the error result to return. */
97
+ async function readPool(project, projectId, input) {
98
+ const { titles, error } = await blockTitles(project, projectId, input.blockId);
99
+ if (error !== void 0) return { error };
100
+ try {
101
+ return {
102
+ pool: await project.getPoolColumns({
103
+ viewAs: input.blockId,
104
+ include: input.selector?.include,
105
+ exclude: input.selector?.exclude,
106
+ anchors: input.anchors,
107
+ mode: input.mode,
108
+ maxHops: input.maxHops
109
+ }).getValue(),
110
+ titles
111
+ };
112
+ } catch (err) {
113
+ const message = err instanceof Error ? err.message : String(err);
114
+ return { error: input.anchors !== void 0 ? errorResult(`The anchors or the selector were not accepted: ${message}`, "An anchor selector must match exactly one column, and two anchors not the same one.") : input.selector !== void 0 ? errorResult(`The selector was not accepted: ${message}`, "Check the selector against the ColumnSelector type of the SDK; a plain string is a regular expression.") : errorResult(`Reading the result pool failed: ${message}`) };
115
+ }
116
+ }
117
+ function axisEntry(a, full) {
118
+ return {
119
+ name: a.name,
120
+ type: a.type,
121
+ ...a.domain !== void 0 && Object.keys(a.domain).length > 0 ? { domain: a.domain } : {},
122
+ ...readAnnotation(a, Annotation.Label) !== void 0 ? { label: readAnnotation(a, Annotation.Label) } : {},
123
+ ...full && a.annotations !== void 0 ? { annotations: a.annotations } : {}
124
+ };
125
+ }
126
+ function nonEmpty(r) {
127
+ return r !== void 0 && Object.keys(r).length > 0 ? r : void 0;
128
+ }
129
+ /** One column as the pool tools show it. */
130
+ function poolColumnEntry(c, titles, full) {
131
+ const spec = c.spec;
132
+ const label = readAnnotation(spec, Annotation.Label);
133
+ const title = titles.get(c.producedBy);
134
+ const domain = nonEmpty(spec.domain);
135
+ const contextDomain = nonEmpty(spec.contextDomain);
136
+ return {
137
+ columnId: c.columnId,
138
+ ...c.ref !== void 0 ? { ref: c.ref } : {},
139
+ ...c.path !== void 0 ? { path: c.path } : {},
140
+ exportName: c.exportName,
141
+ producedBy: {
142
+ blockId: c.producedBy,
143
+ ...title !== void 0 ? { label: title } : {}
144
+ },
145
+ name: spec.name,
146
+ ...label !== void 0 ? { label } : {},
147
+ valueType: spec.valueType,
148
+ axes: spec.axesSpec.map((a) => axisEntry(a, full)),
149
+ ...domain !== void 0 ? { domain } : {},
150
+ ...contextDomain !== void 0 ? { contextDomain } : {},
151
+ ...full && spec.annotations !== void 0 ? { annotations: spec.annotations } : {}
152
+ };
153
+ }
154
+ /** The result-pool columns of a project, filtered and paged (`list_pool_columns`). */
155
+ async function listPoolColumnsResult(project, projectId, input) {
156
+ const read = await readPool(project, projectId, input);
157
+ if (read.error) return read.error;
158
+ const { pool, titles } = read;
159
+ const matching = pool.columns;
160
+ const offset = input.offset ?? 0;
161
+ const limit = input.limit ?? 50;
162
+ const pageItems = matching.slice(offset, offset + limit);
163
+ const end = offset + pageItems.length;
164
+ const full = input.detail === "full";
165
+ return textResult({
166
+ total: matching.length,
167
+ offset,
168
+ hasMore: end < matching.length,
169
+ ...end < matching.length ? { nextOffset: end } : {},
170
+ ...pool.isComplete ? {} : {
171
+ isComplete: false,
172
+ note: POOL_NOT_COMPLETE_NOTE
173
+ },
174
+ columns: pageItems.map((c) => poolColumnEntry(c, titles, full))
175
+ }, { hint: "Ask for fewer columns: a smaller `limit`, `detail: \"summary\"` or a `selector`." });
176
+ }
177
+ /** Default timeout of a `transform` of `get_pool_column`, in milliseconds. */
178
+ const DEFAULT_TRANSFORM_TIMEOUT = 5e3;
179
+ const POOL_COLUMN_TRANSFORM_VARIABLES = "`spec`, `columnId`, `ref`, `path`, `exportName`, `producedBy`";
180
+ /**
181
+ * One column of the result pool with its whole spec (`get_pool_column`), or, with `transform`, the
182
+ * value of that expression evaluated in the sandbox against it (variables `spec`, `columnId`, `ref`,
183
+ * `path`, `exportName` and `producedBy`).
184
+ */
185
+ async function poolColumnResult(project, projectId, input) {
186
+ const { titles, error } = await blockTitles(project, projectId, input.blockId);
187
+ if (error !== void 0) return error;
188
+ const [column] = await project.getPoolColumnsById([input.columnId], input.blockId).getValue();
189
+ if (column === void 0) return errorResult(`Column ${input.columnId} is not in the result pool of project ${projectId}` + (input.blockId !== void 0 ? ` as block ${input.blockId} sees it.` : "."), "list_pool_columns lists the column ids of the pool" + (input.blockId !== void 0 ? "; a block sees only its own columns and those of the blocks above it" : "") + "; ids follow current specs: list_pool_columns again.");
190
+ const title = titles.get(column.producedBy);
191
+ const producedBy = {
192
+ blockId: column.producedBy,
193
+ ...title !== void 0 ? { label: title } : {}
194
+ };
195
+ if (input.transform) try {
196
+ return textResult(await safeEval(input.transform, {
197
+ spec: column.spec,
198
+ columnId: column.columnId,
199
+ ref: column.ref,
200
+ path: column.path,
201
+ exportName: column.exportName,
202
+ producedBy
203
+ }, input.transformTimeout ?? DEFAULT_TRANSFORM_TIMEOUT));
204
+ } catch (e) {
205
+ return transformFailedResult(e, `Check your JS expression syntax. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES}.`);
206
+ }
207
+ return textResult({
208
+ columnId: column.columnId,
209
+ ...column.ref !== void 0 ? { ref: column.ref } : {},
210
+ ...column.path !== void 0 ? { path: column.path } : {},
211
+ exportName: column.exportName,
212
+ producedBy,
213
+ spec: column.spec
214
+ }, { hint: "Read part of the spec with `transform`, e.g. `spec.annotations`, `spec.domain` or `spec.axesSpec[0]`." });
215
+ }
216
+ const WHAT_THE_POOL_IS = "The result pool is the set of columns that blocks export for blocks below them: a block sees the columns of the blocks above it and its own.";
217
+ function registerResultPoolTools(server, ctx) {
218
+ server.registerTool("list_pool_columns", {
219
+ title: "List Result Pool Columns",
220
+ annotations: hints.read,
221
+ description: `${WHAT_THE_POOL_IS} List those columns with their specs, a page at a time: \`{ total, offset, hasMore, nextOffset?, isComplete?, columns: [{ columnId, ref?, path?, exportName, producedBy: { blockId, label? }, name, label?, valueType, axes: [{ name, type, domain?, label? }], domain?, contextDomain?, annotations? }] }\` (annotations with \`detail: "full"\`). With \`blockId\`, the pool as that block sees it; without, every block's columns. Use it to see what data a project has, and to write or check the column selector of a block's model: \`selector\` takes \`{ include?, exclude? }\` exactly as a model passes them to \`ColumnsCollection(["result_pool"]).filter(…)\`; the result is what the selector matches here. \`anchors\` lists the columns reachable from those columns, through linker columns too, with discovered ids and the linker ids in \`path\`; \`ref\` is the object form of a leaf's \`columnId\`; \`exportName\` is the name its block exports the column under. Specs only, no values. A block's choices are in its own option outputs (get_block_outputs); a column's \`ref\`, or its \`columnId\` when it has a \`ref\`, fits a block field of that form (get_block_contract).`,
222
+ inputSchema: z.object({
223
+ projectId: projectIdInput.describe("Project ID"),
224
+ blockId: blockIdInput.optional().describe("See the pool as this block does: its own columns and those of blocks above."),
225
+ selector: poolSelectorInput.optional().describe("`{ include?, exclude? }` of `ColumnsCollection.filter`: a `ColumnSelector` each (one selector or an array, any of which may match). A selector has `name`, `type`, `domain`, `contextDomain`, `annotations`, `axes`, `partialAxesMatch`; a matcher is `{ type: \"exact\" | \"regex\", value }`; a plain string is a regex found anywhere in the value, case-sensitive (`^…$` for all of it). E.g. by label `{ include: { annotations: { \"pl7.app/label\": \"Score\" } } }`; by type and axis `{ include: { type: \"Double\", axes: [{ name: \"pl7.app/sampleId\" }] } }`."),
226
+ anchors: z.record(z.string(), poolAnchorInput).optional().describe("Name → anchor column: its `columnId` (as listed without anchors), its `ref`, or a selector matching one column. Lists what `ColumnsCollection.discover({ anchors })` finds from them; `selector` narrows it."),
227
+ mode: z.enum([
228
+ "enrichment",
229
+ "related",
230
+ "exact"
231
+ ]).optional().describe("With `anchors`, how axes may match theirs: `enrichment` (default), `related` (widest) or `exact`."),
232
+ maxHops: z.number().int().min(0).max(8).optional().describe("With `anchors`, the most linker columns on the way (default 4)."),
233
+ detail: z.enum(["summary", "full"]).optional().describe("`summary` (default): no annotations; `full`: column and axis annotations."),
234
+ ...pagingArgs("columns", 50, 200)
235
+ })
236
+ }, async ({ projectId, ...input }) => await ctx.withProject(projectId, (project) => listPoolColumnsResult(project, projectId, input)));
237
+ server.registerTool("get_pool_column", {
238
+ title: "Get Result Pool Column",
239
+ annotations: hints.read,
240
+ description: "Get one column of the result pool with its whole spec: `{ columnId, ref?, path?, exportName, producedBy: { blockId, label? }, spec }`, the spec with every domain and annotation of the column and its axes. Column ids come from list_pool_columns. Specs only, no values: get_column_values reads them. Read part of a large spec with `transform`, e.g. `spec.annotations`.",
241
+ inputSchema: z.object({
242
+ projectId: projectIdInput.describe("Project ID"),
243
+ columnId: columnIdInput.describe("Column id from list_pool_columns, or a PlRef object."),
244
+ blockId: blockIdInput.optional().describe("Look the column up as this block sees the pool (default: every block's)."),
245
+ transform: z.string().optional().describe(`JS expression evaluated server-side against the column. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES} (\`{ blockId, label? }\`). Omit for the whole answer.`),
246
+ transformTimeout: z.number().optional().default(DEFAULT_TRANSFORM_TIMEOUT).describe(expressionTimeoutText("transform evaluation", DEFAULT_TRANSFORM_TIMEOUT))
247
+ })
248
+ }, async ({ projectId, ...input }) => await ctx.withProject(projectId, (project) => poolColumnResult(project, projectId, input)));
249
+ }
250
+ export { WHAT_THE_POOL_IS, columnSelectorInput, listPoolColumnsResult, poolAnchorInput, poolColumnEntry, poolColumnResult, poolSelectorInput, regexText, registerResultPoolTools };
251
+
252
+ //# sourceMappingURL=result-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-pool.js","names":[],"sources":["../../src/tools/result-pool.ts"],"sourcesContent":["import type {\n BlockStateOverview,\n PoolColumn,\n PoolColumns,\n PoolColumnsQuery,\n} from \"@milaboratories/pl-middle-layer\";\nimport {\n Annotation,\n isPlRef,\n isPObjectId,\n readAnnotation,\n ValueType,\n type AnchorEntry,\n type AxisSpec,\n type BlockId,\n type ColumnSelector,\n type ColumnUniversalId,\n type MatchingMode,\n type ProjectId,\n type RelaxedAxisSelector,\n type RelaxedColumnSelector,\n type StringMatcher,\n} from \"@milaboratories/pl-model-common\";\nimport { z } from \"zod\";\nimport { blockIdInput, columnIdFromAgent, columnIdInput, plRefObject, projectIdInput } from \"./ids\";\nimport { pagingArgs } from \"./paging\";\nimport { findBlock, type BlockLookupProject } from \"./readiness\";\nimport { expressionTimeoutText, safeEval } from \"./sandbox\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult, transformFailedResult } from \"./types\";\n\n/** Default page of {@link listPoolColumnsResult}. */\nexport const POOL_COLUMNS_DEFAULT = 50;\n/** Largest page of {@link listPoolColumnsResult}. */\nexport const POOL_COLUMNS_MAX = 200;\n\n// Selectors, in the forms block models pass them. Typed against the SDK's types, so a schema that\n// drifts from them does not compile.\n//\n// The schemas used more than once carry an `id`: the JSON Schema a client is sent then defines each\n// once under `$defs` and refers to it, instead of repeating it at every use (40 kB of arguments for\n// list_pool_columns otherwise). The id is the name of the SDK type the schema stands for.\n\n/** A regular expression the pattern of a selector must compile to. */\nexport function regexText(what: string) {\n return z.string().superRefine((value, ctx) => {\n try {\n new RegExp(value);\n } catch (err) {\n ctx.addIssue({\n code: \"custom\",\n message: `${what} is not a valid regular expression: ${err instanceof Error ? err.message : String(err)}`,\n });\n }\n });\n}\n\nconst stringMatcher: z.ZodType<StringMatcher> = z\n .union([\n z.strictObject({ type: z.literal(\"exact\"), value: z.string() }),\n z.strictObject({ type: z.literal(\"regex\"), value: regexText(\"A `regex` matcher\") }),\n ])\n .meta({ id: \"StringMatcher\" });\n\n/** A plain string is a regular expression, as in the SDK. */\nconst relaxedMatchers = z\n .union([\n regexText(\"A plain-string matcher\"),\n stringMatcher,\n z.array(z.union([regexText(\"A plain-string matcher\"), stringMatcher])),\n ])\n .meta({ id: \"RelaxedStringMatchers\" });\n\nconst relaxedRecord = z.record(z.string(), relaxedMatchers);\nconst valueType = z.enum(ValueType).meta({ id: \"ValueType\" });\nconst axisValueType = z.enum([\"Int\", \"Long\", \"String\"]);\n\nconst relaxedAxisSelector: z.ZodType<RelaxedAxisSelector> = z\n .strictObject({\n name: relaxedMatchers.optional(),\n type: z.union([axisValueType, z.array(axisValueType)]).optional(),\n domain: relaxedRecord.optional(),\n contextDomain: relaxedRecord.optional(),\n annotations: relaxedRecord.optional(),\n })\n .meta({ id: \"RelaxedAxisSelector\" });\n\nconst relaxedColumnSelector: z.ZodType<RelaxedColumnSelector> = z\n .strictObject({\n name: relaxedMatchers.optional(),\n type: z.union([valueType, z.array(valueType)]).optional(),\n domain: relaxedRecord.optional(),\n contextDomain: relaxedRecord.optional(),\n annotations: relaxedRecord.optional(),\n axes: z.array(relaxedAxisSelector).optional(),\n partialAxesMatch: z.boolean().optional(),\n })\n .meta({ id: \"RelaxedColumnSelector\" });\n\n/** `ColumnSelector`: one selector or several, any of which may match. */\nexport const columnSelectorInput: z.ZodType<ColumnSelector> = z\n .union([relaxedColumnSelector, z.array(relaxedColumnSelector)])\n .meta({ id: \"ColumnSelector\" });\n\n/**\n * An anchor of `ColumnsCollection.discover`: the id of a column of the pool (its `columnId` as\n * list_pool_columns lists it without anchors, or its PlRef object), or a selector that matches one\n * column.\n */\nexport const poolAnchorInput = z\n .union([z.string(), plRefObject, relaxedColumnSelector])\n .transform((raw, ctx): AnchorEntry => {\n if (typeof raw !== \"string\" && !isPlRef(raw)) return raw;\n const id = columnIdFromAgent(raw);\n if (id !== undefined && isPObjectId(id)) return id;\n ctx.addIssue({\n code: \"custom\",\n message:\n \"an anchor is a `columnId` that list_pool_columns gives without anchors, its `ref`, \" +\n \"or a selector\",\n });\n return z.NEVER;\n });\n\n/** The `include` / `exclude` pair of `ColumnsCollection.filter`. */\nexport const poolSelectorInput = z.strictObject({\n include: columnSelectorInput.optional(),\n exclude: columnSelectorInput.optional(),\n});\n\n// Results\n\n/** What the pool tools need of a project: its overview (block titles) and its pool columns. */\nexport type PoolProject = BlockLookupProject<Pick<BlockStateOverview, \"id\" | \"title\">> & {\n getPoolColumns(query: PoolColumnsQuery): { getValue(): Promise<PoolColumns> };\n getPoolColumnsById(\n ids: readonly ColumnUniversalId[],\n viewAs?: BlockId,\n ): { getValue(): Promise<(PoolColumn | undefined)[]> };\n};\n\n/** Which part of the pool a tool reads, and how it is filtered. */\nexport type PoolListInput = {\n blockId?: BlockId;\n selector?: { include?: ColumnSelector; exclude?: ColumnSelector };\n /** Columns to discover from: the pool lists what is reachable from them, with discovered ids. */\n anchors?: Record<string, AnchorEntry>;\n mode?: MatchingMode;\n maxHops?: number;\n detail?: \"summary\" | \"full\";\n limit?: number;\n offset?: number;\n};\n\nconst POOL_NOT_COMPLETE_NOTE =\n \"Some blocks in view are still being calculated: more columns may appear when they finish.\";\n\n/** The titles of the project's blocks by id, or the error result to return. */\nasync function blockTitles(\n project: PoolProject,\n projectId: ProjectId,\n blockId: BlockId | undefined,\n): Promise<\n | { titles: Map<string, string>; error?: undefined }\n | { titles?: undefined; error: ReturnType<typeof errorResult> }\n> {\n const overview = await project.overview.getValue();\n if (overview === undefined)\n return { error: errorResult(\"Project overview not available yet. Try again.\") };\n if (blockId !== undefined) {\n const { error } = await findBlock(project, projectId, blockId);\n if (error) return { error };\n }\n const titles = new Map<string, string>();\n for (const b of overview.blocks) if (b.title !== undefined) titles.set(b.id, b.title);\n return { titles };\n}\n\n/** Reads the pool columns, or the error result to return. */\nasync function readPool(\n project: PoolProject,\n projectId: ProjectId,\n input: Pick<PoolListInput, \"blockId\" | \"selector\" | \"anchors\" | \"mode\" | \"maxHops\">,\n): Promise<\n | { pool: PoolColumns; titles: Map<string, string>; error?: undefined }\n | { error: ReturnType<typeof errorResult> }\n> {\n const { titles, error } = await blockTitles(project, projectId, input.blockId);\n if (error !== undefined) return { error };\n try {\n const pool = await project\n .getPoolColumns({\n viewAs: input.blockId,\n include: input.selector?.include,\n exclude: input.selector?.exclude,\n anchors: input.anchors,\n mode: input.mode,\n maxHops: input.maxHops,\n })\n .getValue();\n return { pool, titles };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n error:\n input.anchors !== undefined\n ? errorResult(\n `The anchors or the selector were not accepted: ${message}`,\n \"An anchor selector must match exactly one column, and two anchors not the same one.\",\n )\n : input.selector !== undefined\n ? errorResult(\n `The selector was not accepted: ${message}`,\n \"Check the selector against the ColumnSelector type of the SDK; a plain string is a regular expression.\",\n )\n : errorResult(`Reading the result pool failed: ${message}`),\n };\n }\n}\n\nfunction axisEntry(a: AxisSpec, full: boolean) {\n return {\n name: a.name,\n type: a.type,\n ...(a.domain !== undefined && Object.keys(a.domain).length > 0 ? { domain: a.domain } : {}),\n ...(readAnnotation(a, Annotation.Label) !== undefined\n ? { label: readAnnotation(a, Annotation.Label) }\n : {}),\n ...(full && a.annotations !== undefined ? { annotations: a.annotations } : {}),\n };\n}\n\nfunction nonEmpty(r: Record<string, string> | undefined): Record<string, string> | undefined {\n return r !== undefined && Object.keys(r).length > 0 ? r : undefined;\n}\n\n/** One column as the pool tools show it. */\nexport function poolColumnEntry(c: PoolColumn, titles: Map<string, string>, full: boolean) {\n const spec = c.spec;\n const label = readAnnotation(spec, Annotation.Label);\n const title = titles.get(c.producedBy);\n const domain = nonEmpty(spec.domain);\n const contextDomain = nonEmpty(spec.contextDomain);\n return {\n columnId: c.columnId,\n ...(c.ref !== undefined ? { ref: c.ref } : {}),\n ...(c.path !== undefined ? { path: c.path } : {}),\n exportName: c.exportName,\n producedBy: { blockId: c.producedBy, ...(title !== undefined ? { label: title } : {}) },\n name: spec.name,\n ...(label !== undefined ? { label } : {}),\n valueType: spec.valueType,\n axes: spec.axesSpec.map((a) => axisEntry(a, full)),\n ...(domain !== undefined ? { domain } : {}),\n ...(contextDomain !== undefined ? { contextDomain } : {}),\n ...(full && spec.annotations !== undefined ? { annotations: spec.annotations } : {}),\n };\n}\n\n/** The result-pool columns of a project, filtered and paged (`list_pool_columns`). */\nexport async function listPoolColumnsResult(\n project: PoolProject,\n projectId: ProjectId,\n input: PoolListInput,\n) {\n const read = await readPool(project, projectId, input);\n if (read.error) return read.error;\n const { pool, titles } = read;\n const matching = pool.columns;\n const offset = input.offset ?? 0;\n const limit = input.limit ?? POOL_COLUMNS_DEFAULT;\n const pageItems = matching.slice(offset, offset + limit);\n const end = offset + pageItems.length;\n const full = input.detail === \"full\";\n return textResult(\n {\n total: matching.length,\n offset,\n hasMore: end < matching.length,\n ...(end < matching.length ? { nextOffset: end } : {}),\n ...(pool.isComplete ? {} : { isComplete: false, note: POOL_NOT_COMPLETE_NOTE }),\n columns: pageItems.map((c) => poolColumnEntry(c, titles, full)),\n },\n {\n hint: 'Ask for fewer columns: a smaller `limit`, `detail: \"summary\"` or a `selector`.',\n },\n );\n}\n\n/** Default timeout of a `transform` of `get_pool_column`, in milliseconds. */\nconst DEFAULT_TRANSFORM_TIMEOUT = 5000;\n\nconst POOL_COLUMN_TRANSFORM_VARIABLES =\n \"`spec`, `columnId`, `ref`, `path`, `exportName`, `producedBy`\";\n\n/**\n * One column of the result pool with its whole spec (`get_pool_column`), or, with `transform`, the\n * value of that expression evaluated in the sandbox against it (variables `spec`, `columnId`, `ref`,\n * `path`, `exportName` and `producedBy`).\n */\nexport async function poolColumnResult(\n project: PoolProject,\n projectId: ProjectId,\n input: {\n columnId: ColumnUniversalId;\n blockId?: BlockId;\n transform?: string;\n transformTimeout?: number;\n },\n) {\n const { titles, error } = await blockTitles(project, projectId, input.blockId);\n if (error !== undefined) return error;\n const [column] = await project.getPoolColumnsById([input.columnId], input.blockId).getValue();\n if (column === undefined)\n return errorResult(\n `Column ${input.columnId} is not in the result pool of project ${projectId}` +\n (input.blockId !== undefined ? ` as block ${input.blockId} sees it.` : \".\"),\n \"list_pool_columns lists the column ids of the pool\" +\n (input.blockId !== undefined\n ? \"; a block sees only its own columns and those of the blocks above it\"\n : \"\") +\n \"; ids follow current specs: list_pool_columns again.\",\n );\n const title = titles.get(column.producedBy);\n const producedBy = {\n blockId: column.producedBy,\n ...(title !== undefined ? { label: title } : {}),\n };\n if (input.transform) {\n try {\n return textResult(\n await safeEval(\n input.transform,\n {\n spec: column.spec,\n columnId: column.columnId,\n ref: column.ref,\n path: column.path,\n exportName: column.exportName,\n producedBy,\n },\n input.transformTimeout ?? DEFAULT_TRANSFORM_TIMEOUT,\n ),\n );\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n `Check your JS expression syntax. Available variables: ${POOL_COLUMN_TRANSFORM_VARIABLES}.`,\n );\n }\n }\n return textResult(\n {\n columnId: column.columnId,\n ...(column.ref !== undefined ? { ref: column.ref } : {}),\n ...(column.path !== undefined ? { path: column.path } : {}),\n exportName: column.exportName,\n producedBy,\n spec: column.spec,\n },\n {\n hint:\n \"Read part of the spec with `transform`, e.g. `spec.annotations`, `spec.domain` or \" +\n \"`spec.axesSpec[0]`.\",\n },\n );\n}\n\n// Tools\n\nexport const WHAT_THE_POOL_IS =\n \"The result pool is the set of columns that blocks export for blocks below them: a block sees \" +\n \"the columns of the blocks above it and its own.\";\n\nexport function registerResultPoolTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"list_pool_columns\",\n {\n title: \"List Result Pool Columns\",\n annotations: hints.read,\n description:\n `${WHAT_THE_POOL_IS} List those columns with their specs, a page at a time: \\`{ total, ` +\n \"offset, hasMore, nextOffset?, isComplete?, columns: [{ columnId, ref?, path?, \" +\n \"exportName, producedBy: { blockId, label? }, name, label?, valueType, axes: [{ name, \" +\n \"type, domain?, label? }], \" +\n 'domain?, contextDomain?, annotations? }] }` (annotations with `detail: \"full\"`). ' +\n \"With `blockId`, the pool as that block sees it; without, every block's columns. \" +\n \"Use it to see what data a project has, and to write or check the column selector of a \" +\n \"block's model: `selector` takes `{ include?, exclude? }` exactly as a model passes them \" +\n 'to `ColumnsCollection([\"result_pool\"]).filter(…)`; the result is what the ' +\n \"selector matches here. `anchors` lists the columns reachable from those columns, through \" +\n \"linker columns too, with discovered ids and the linker ids in `path`; `ref` is the \" +\n \"object form of a leaf's `columnId`; `exportName` is the name its block exports the \" +\n \"column under. Specs only, no values. A block's choices are in its own option outputs \" +\n \"(get_block_outputs); a column's `ref`, or its `columnId` when it has a `ref`, fits a \" +\n \"block field of that form (get_block_contract).\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput\n .optional()\n .describe(\"See the pool as this block does: its own columns and those of blocks above.\"),\n selector: poolSelectorInput\n .optional()\n .describe(\n \"`{ include?, exclude? }` of `ColumnsCollection.filter`: a `ColumnSelector` each \" +\n \"(one selector or an array, any of which may match). A selector has `name`, \" +\n \"`type`, `domain`, `contextDomain`, `annotations`, `axes`, `partialAxesMatch`; a \" +\n 'matcher is `{ type: \"exact\" | \"regex\", value }`; a plain string is a regex found ' +\n \"anywhere in the value, case-sensitive (`^…$` for all of it). E.g. by label \" +\n '`{ include: { annotations: { \"pl7.app/label\": \"Score\" } } }`; by type and axis ' +\n '`{ include: { type: \"Double\", axes: [{ name: \"pl7.app/sampleId\" }] } }`.',\n ),\n anchors: z\n .record(z.string(), poolAnchorInput)\n .optional()\n .describe(\n \"Name → anchor column: its `columnId` (as listed without anchors), its `ref`, or a \" +\n \"selector matching one column. Lists what `ColumnsCollection.discover({ anchors })` \" +\n \"finds from them; `selector` narrows it.\",\n ),\n mode: z\n .enum([\"enrichment\", \"related\", \"exact\"])\n .optional()\n .describe(\n \"With `anchors`, how axes may match theirs: `enrichment` (default), `related` \" +\n \"(widest) or `exact`.\",\n ),\n maxHops: z\n .number()\n .int()\n .min(0)\n .max(8)\n .optional()\n .describe(\"With `anchors`, the most linker columns on the way (default 4).\"),\n detail: z\n .enum([\"summary\", \"full\"])\n .optional()\n .describe(\"`summary` (default): no annotations; `full`: column and axis annotations.\"),\n ...pagingArgs(\"columns\", POOL_COLUMNS_DEFAULT, POOL_COLUMNS_MAX),\n }),\n },\n async ({ projectId, ...input }) =>\n await ctx.withProject(projectId, (project) =>\n listPoolColumnsResult(project, projectId, input),\n ),\n );\n\n server.registerTool(\n \"get_pool_column\",\n {\n title: \"Get Result Pool Column\",\n annotations: hints.read,\n description:\n \"Get one column of the result pool with its whole spec: `{ columnId, ref?, path?, \" +\n \"exportName, producedBy: { blockId, label? }, spec }`, the spec with every \" +\n \"domain and annotation of the column and its axes. Column ids come from \" +\n \"list_pool_columns. Specs only, no values: get_column_values reads them. \" +\n \"Read part of a large spec with `transform`, e.g. `spec.annotations`.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n columnId: columnIdInput.describe(\"Column id from list_pool_columns, or a PlRef object.\"),\n blockId: blockIdInput\n .optional()\n .describe(\"Look the column up as this block sees the pool (default: every block's).\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against the column. Available variables: \" +\n `${POOL_COLUMN_TRANSFORM_VARIABLES} (\\`{ blockId, label? }\\`). Omit for the whole ` +\n \"answer.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(DEFAULT_TRANSFORM_TIMEOUT)\n .describe(expressionTimeoutText(\"transform evaluation\", DEFAULT_TRANSFORM_TIMEOUT)),\n }),\n },\n async ({ projectId, ...input }) =>\n await ctx.withProject(projectId, (project) => poolColumnResult(project, projectId, input)),\n );\n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