@milaboratories/pl-mcp-server 54.0.0 → 55.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -25
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +15 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +15 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +58 -8
- package/dist/project-holds.cjs.map +1 -1
- package/dist/project-holds.js +58 -8
- package/dist/project-holds.js.map +1 -1
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +40 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +40 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +48 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +21 -20
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +48 -18
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -73
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -75
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +3 -0
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +3 -0
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +272 -4
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +270 -6
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +323 -42
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +317 -46
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +183 -70
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +177 -70
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +451 -113
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +446 -118
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +56 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +51 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +98 -19
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +95 -20
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +66 -19
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +66 -20
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +15 -12
- package/src/project-holds.test.ts +179 -0
- package/src/project-holds.ts +114 -12
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +54 -1
- package/src/server-log.ts +49 -27
- package/src/server.logging.test.ts +38 -46
- package/src/server.test.ts +151 -17
- package/src/server.ts +62 -34
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -123
- package/src/tools/block-action-context.ts +3 -0
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +623 -8
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +659 -66
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +336 -105
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +807 -157
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +67 -0
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +130 -21
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +135 -25
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +77 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const require_types = require("./types.cjs");
|
|
2
2
|
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_tokens = require("./tokens.cjs");
|
|
3
4
|
const require_sandbox = require("./sandbox.cjs");
|
|
5
|
+
const require_block_storage = require("./block-storage.cjs");
|
|
6
|
+
const require_readiness = require("./readiness.cjs");
|
|
7
|
+
let _milaboratories_helpers = require("@milaboratories/helpers");
|
|
4
8
|
let zod = require("zod");
|
|
5
9
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
6
10
|
// src/tools/data-query.ts
|
|
@@ -11,7 +15,7 @@ const HEX_HASH_RE = /^[a-f0-9]{64}$/;
|
|
|
11
15
|
* call on it.
|
|
12
16
|
*/
|
|
13
17
|
function staleHandleResult(kind, handle, err) {
|
|
14
|
-
return require_types.errorResult(`${kind} handle ${handle} is not valid: ${err.message}`, "Handles stop working some time after the last call on their project. Call get_block_outputs again for a fresh handle.");
|
|
18
|
+
return require_types.errorResult(`${kind} handle ${handle} is not valid: ${err.message}`, "Handles stop working some time after the last call on their project. " + (kind === "PTable" ? "Call get_block_outputs again for a fresh handle, or create_table again for a table of your own (those also go when dropped or not read for a while)." : "Call get_block_outputs again for a fresh handle."));
|
|
15
19
|
}
|
|
16
20
|
/** Whether `err` is the driver's answer to a handle it does not know (any more). */
|
|
17
21
|
function isUnknownHandleError(err) {
|
|
@@ -28,11 +32,11 @@ async function resolveHandle(handle, driver, maxColumns, cache) {
|
|
|
28
32
|
const summary = {
|
|
29
33
|
_type: "PTable",
|
|
30
34
|
handle,
|
|
31
|
-
rows: (await driver.getShape(handle)).rows,
|
|
32
35
|
columnCount: spec.length,
|
|
33
36
|
columns: spec.slice(0, maxColumns).map((s, idx) => ({
|
|
34
37
|
index: idx,
|
|
35
38
|
type: s.type,
|
|
39
|
+
...s.type === "column" ? { columnId: s.id } : {},
|
|
36
40
|
name: s.spec.name,
|
|
37
41
|
valueType: s.type === "column" ? s.spec.valueType : s.spec.type,
|
|
38
42
|
label: (0, _milaboratories_pl_model_common.readAnnotation)(s.spec, _milaboratories_pl_model_common.Annotation.Label)
|
|
@@ -52,6 +56,7 @@ async function resolveHandle(handle, driver, maxColumns, cache) {
|
|
|
52
56
|
handle,
|
|
53
57
|
columnCount: columns.length,
|
|
54
58
|
columns: columns.slice(0, maxColumns).map((c) => ({
|
|
59
|
+
columnId: c.columnId,
|
|
55
60
|
name: c.spec.name,
|
|
56
61
|
valueType: c.spec.valueType,
|
|
57
62
|
label: (0, _milaboratories_pl_model_common.readAnnotation)(c.spec, _milaboratories_pl_model_common.Annotation.Label)
|
|
@@ -69,157 +74,490 @@ async function resolveHandle(handle, driver, maxColumns, cache) {
|
|
|
69
74
|
}
|
|
70
75
|
/**
|
|
71
76
|
* Recursively walk a value tree, replacing 64-char hex handles
|
|
72
|
-
* with PFrame/PTable summaries (column specs
|
|
77
|
+
* with PFrame/PTable summaries (column specs).
|
|
73
78
|
*/
|
|
74
79
|
async function resolveHandlesInValue(value, driver, maxColumns, cache) {
|
|
75
80
|
if (value === null || value === void 0) return value;
|
|
76
81
|
if (typeof value === "string") return HEX_HASH_RE.test(value) ? resolveHandle(value, driver, maxColumns, cache) : value;
|
|
77
82
|
if (typeof value !== "object") return value;
|
|
78
83
|
if (Array.isArray(value)) return Promise.all(value.map((v) => resolveHandlesInValue(v, driver, maxColumns, cache)));
|
|
79
|
-
const
|
|
80
|
-
for (const [k, v] of Object.entries(value))
|
|
81
|
-
return
|
|
84
|
+
const entries = [];
|
|
85
|
+
for (const [k, v] of Object.entries(value)) entries.push([k, await resolveHandlesInValue(v, driver, maxColumns, cache)]);
|
|
86
|
+
return Object.fromEntries(entries);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Replaces every PFrame or PTable summary of `outputs` (output key → resolved value) whose handle
|
|
90
|
+
* an earlier one already summed up with `{ sameAs: "<path>" }`, the path to that first summary in
|
|
91
|
+
* `outputs`, written as a JavaScript accessor: `main.table`, `list[0]`, `["a key"].x`. Outputs are
|
|
92
|
+
* walked in their order, values depth-first. A block often gives the same table in two outputs
|
|
93
|
+
* (D-025): each summary is then given once, and every repeat names the one it repeats.
|
|
94
|
+
*/
|
|
95
|
+
function dedupeHandleSummaries(outputs) {
|
|
96
|
+
const firstSeen = /* @__PURE__ */ new Map();
|
|
97
|
+
const walk = (value, path) => {
|
|
98
|
+
if (typeof value !== "object" || value === null) return value;
|
|
99
|
+
if (Array.isArray(value)) return value.map((v, i) => walk(v, `${path}[${i}]`));
|
|
100
|
+
const record = Object.fromEntries(Object.entries(value));
|
|
101
|
+
const handle = record.handle;
|
|
102
|
+
if ((record._type === "PTable" || record._type === "PFrame") && typeof handle === "string") {
|
|
103
|
+
const first = firstSeen.get(handle);
|
|
104
|
+
if (first !== void 0) return { sameAs: first };
|
|
105
|
+
firstSeen.set(handle, path);
|
|
106
|
+
return record;
|
|
107
|
+
}
|
|
108
|
+
return Object.fromEntries(Object.entries(record).map(([k, v]) => [k, walk(v, `${path}${propertyAccessor(k)}`)]));
|
|
109
|
+
};
|
|
110
|
+
return Object.fromEntries(Object.entries(outputs).map(([key, v]) => [key, walk(v, JS_IDENTIFIER.test(key) ? key : propertyAccessor(key))]));
|
|
82
111
|
}
|
|
83
|
-
/**
|
|
112
|
+
/** A name JavaScript accepts after a dot. */
|
|
113
|
+
const JS_IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
114
|
+
/** How JavaScript reads property `key`: `.key`, or `["key"]` for a key that is not a plain name. */
|
|
115
|
+
function propertyAccessor(key) {
|
|
116
|
+
return JS_IDENTIFIER.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Converts a PTableVector column to a JSON-serializable array using the SDK helper. Binary values,
|
|
120
|
+
* which the helper does not read, are given by their size, `{bytes: N}`; NA as `null`.
|
|
121
|
+
*/
|
|
84
122
|
function vectorToJson(vector, rows) {
|
|
85
123
|
const result = [];
|
|
86
|
-
for (let i = 0; i < rows; i++)
|
|
124
|
+
for (let i = 0; i < rows; i++) if (vector.type === _milaboratories_pl_model_common.ValueType.Bytes) {
|
|
125
|
+
const value = vector.data[i];
|
|
126
|
+
result.push((0, _milaboratories_pl_model_common.isValueNA)(vector, i) || !(value instanceof Uint8Array) ? null : { bytes: value.length });
|
|
127
|
+
} else result.push((0, _milaboratories_pl_model_common.pTableValue)(vector, i));
|
|
87
128
|
return result;
|
|
88
129
|
}
|
|
130
|
+
const MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
131
|
+
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
132
|
+
/**
|
|
133
|
+
* The value at `row` of `vector`, or null for NA. A Long outside the safe integer range is its
|
|
134
|
+
* exact decimal text: `pTableValue` rounds it to a number, and a value's id is built from its text.
|
|
135
|
+
*/
|
|
136
|
+
function exactValue(vector, row) {
|
|
137
|
+
const raw = vector.data[row];
|
|
138
|
+
if (typeof raw === "bigint" && !(0, _milaboratories_pl_model_common.isValueNA)(vector, row)) return raw >= MIN_SAFE_BIGINT && raw <= MAX_SAFE_BIGINT ? Number(raw) : raw.toString();
|
|
139
|
+
return (0, _milaboratories_pl_model_common.pTableValue)(vector, row, { na: null });
|
|
140
|
+
}
|
|
141
|
+
/** The most rows one `query_table` call returns. */
|
|
142
|
+
const QUERY_MAX_ROWS = 1e4;
|
|
143
|
+
/** The most columns one `list_columns` page has. */
|
|
144
|
+
const LIST_COLUMNS_MAX = 1e3;
|
|
145
|
+
/** The most values one `get_column_values` call asks the driver for. */
|
|
146
|
+
const COLUMN_VALUES_MAX = 1e4;
|
|
147
|
+
function clampInt(v, fallback, min, max) {
|
|
148
|
+
if (v === void 0 || !Number.isFinite(v)) return fallback;
|
|
149
|
+
return (0, _milaboratories_helpers.clamp)(Math.floor(v), min, max);
|
|
150
|
+
}
|
|
151
|
+
/** The columns of a PFrame, filtered and paged (`list_columns`). */
|
|
152
|
+
async function listColumnsResult(driver, pFrameHandle, options) {
|
|
153
|
+
let columns;
|
|
154
|
+
try {
|
|
155
|
+
columns = await driver.listColumns(pFrameHandle);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
if (isUnknownHandleError(err)) return staleHandleResult("PFrame", pFrameHandle, err);
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
const needle = options.name?.toLowerCase();
|
|
161
|
+
const matching = columns.filter((c) => {
|
|
162
|
+
if (options.valueType !== void 0 && c.spec.valueType !== options.valueType) return false;
|
|
163
|
+
if (needle !== void 0) {
|
|
164
|
+
const label = (0, _milaboratories_pl_model_common.readAnnotation)(c.spec, _milaboratories_pl_model_common.Annotation.Label) ?? "";
|
|
165
|
+
if (!c.spec.name.toLowerCase().includes(needle) && !label.toLowerCase().includes(needle)) return false;
|
|
166
|
+
}
|
|
167
|
+
for (const [key, value] of Object.entries(options.annotations ?? {})) if (require_block_storage.ownValue(c.spec.annotations ?? {}, key) !== value) return false;
|
|
168
|
+
return true;
|
|
169
|
+
});
|
|
170
|
+
const offset = clampInt(options.offset, 0, 0, Number.MAX_SAFE_INTEGER);
|
|
171
|
+
const limit = clampInt(options.limit, 100, 1, LIST_COLUMNS_MAX);
|
|
172
|
+
const page = matching.slice(offset, offset + limit);
|
|
173
|
+
const end = offset + page.length;
|
|
174
|
+
const full = options.detail === "full";
|
|
175
|
+
return require_types.textResult({
|
|
176
|
+
total: matching.length,
|
|
177
|
+
...matching.length !== columns.length ? { inFrame: columns.length } : {},
|
|
178
|
+
offset,
|
|
179
|
+
hasMore: end < matching.length,
|
|
180
|
+
...end < matching.length ? { nextOffset: end } : {},
|
|
181
|
+
columns: page.map((c) => ({
|
|
182
|
+
columnId: c.columnId,
|
|
183
|
+
name: c.spec.name,
|
|
184
|
+
valueType: c.spec.valueType,
|
|
185
|
+
label: (0, _milaboratories_pl_model_common.readAnnotation)(c.spec, _milaboratories_pl_model_common.Annotation.Label),
|
|
186
|
+
...full ? {
|
|
187
|
+
visibility: (0, _milaboratories_pl_model_common.readAnnotation)(c.spec, _milaboratories_pl_model_common.Annotation.Table.Visibility),
|
|
188
|
+
domain: c.spec.domain,
|
|
189
|
+
annotations: c.spec.annotations,
|
|
190
|
+
axes: c.spec.axesSpec.map((a) => ({
|
|
191
|
+
name: a.name,
|
|
192
|
+
type: a.type,
|
|
193
|
+
domain: a.domain,
|
|
194
|
+
label: (0, _milaboratories_pl_model_common.readAnnotation)(a, _milaboratories_pl_model_common.Annotation.Label)
|
|
195
|
+
}))
|
|
196
|
+
} : { axes: c.spec.axesSpec.map((a) => a.name) }
|
|
197
|
+
}))
|
|
198
|
+
}, { hint: "Ask for fewer columns: a smaller `limit`, `detail: \"brief\"`, or a `name` filter." });
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The column of a PFrame an agent's column id names: listed under exactly that id, or under the
|
|
202
|
+
* same id written another way (escaped, other spacing or key order at its top level, a PlRef for a
|
|
203
|
+
* global id). Ids of older block APIs are not `ColumnUniversalId`s: they match only as listed.
|
|
204
|
+
*/
|
|
205
|
+
function findFrameColumn(listed, written) {
|
|
206
|
+
const exact = listed.find((c) => c.columnId === written);
|
|
207
|
+
if (exact !== void 0) return exact;
|
|
208
|
+
const canonical = require_ids.columnIdFromAgent(written);
|
|
209
|
+
if (canonical === void 0) return void 0;
|
|
210
|
+
return listed.find((c) => require_ids.columnIdFromAgent(c.columnId) === canonical);
|
|
211
|
+
}
|
|
212
|
+
/** The distinct values of a column, or of one of its axes, in a PFrame (`get_column_values`). */
|
|
213
|
+
async function columnValuesResult(driver, input, signal) {
|
|
214
|
+
const handle = input.pFrameHandle;
|
|
215
|
+
let listed;
|
|
216
|
+
try {
|
|
217
|
+
listed = await driver.listColumns(handle);
|
|
218
|
+
} catch (err) {
|
|
219
|
+
if (isUnknownHandleError(err)) return staleHandleResult("PFrame", input.pFrameHandle, err);
|
|
220
|
+
throw err;
|
|
221
|
+
}
|
|
222
|
+
const column = findFrameColumn(listed, input.columnId);
|
|
223
|
+
if (column === void 0) return require_types.errorResult(`Column ${input.columnId} is not in PFrame ${input.pFrameHandle}.`, "list_columns on the PFrame gives the ids of its columns; ids can change when a block runs again: list again.");
|
|
224
|
+
const { columnId, spec } = column;
|
|
225
|
+
let axisSpec;
|
|
226
|
+
if (input.axis !== void 0) {
|
|
227
|
+
const axes = spec.axesSpec;
|
|
228
|
+
axisSpec = typeof input.axis === "number" ? axes[input.axis] : axes.find((a) => a.name === input.axis);
|
|
229
|
+
if (axisSpec === void 0) return require_types.errorResult(`The column has no axis ${JSON.stringify(input.axis)}.`, `Its axes: ${axes.map((a, i) => `${i}: ${a.name}`).join(", ")}.`);
|
|
230
|
+
}
|
|
231
|
+
const valueType = axisSpec !== void 0 ? axisSpec.type : spec.valueType;
|
|
232
|
+
if (input.search !== void 0 && valueType !== "String") return require_types.errorResult(`\`search\` works on string values; these are ${valueType}.`, "Leave out `search`.");
|
|
233
|
+
const axisId = axisSpec !== void 0 ? (0, _milaboratories_pl_model_common.getAxisId)(axisSpec) : void 0;
|
|
234
|
+
const filters = input.search === void 0 || input.search === "" ? [] : [{
|
|
235
|
+
type: "bySingleColumnV2",
|
|
236
|
+
column: axisId !== void 0 ? {
|
|
237
|
+
type: "axis",
|
|
238
|
+
id: axisId
|
|
239
|
+
} : {
|
|
240
|
+
type: "column",
|
|
241
|
+
id: columnId
|
|
242
|
+
},
|
|
243
|
+
predicate: {
|
|
244
|
+
operator: "StringIContains",
|
|
245
|
+
substring: input.search
|
|
246
|
+
}
|
|
247
|
+
}];
|
|
248
|
+
const limit = clampInt(input.limit, 100, 1, COLUMN_VALUES_MAX);
|
|
249
|
+
let response;
|
|
250
|
+
try {
|
|
251
|
+
response = await driver.getUniqueValues(handle, {
|
|
252
|
+
columnId,
|
|
253
|
+
...axisId !== void 0 ? { axis: axisId } : {},
|
|
254
|
+
filters,
|
|
255
|
+
limit
|
|
256
|
+
}, signal);
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (isUnknownHandleError(err)) return staleHandleResult("PFrame", input.pFrameHandle, err);
|
|
259
|
+
if (signal?.aborted) return require_types.errorResult("Reading the values was stopped: it took too long or the request was cancelled.", "Narrow it with `search`, or ask for a smaller `limit`.");
|
|
260
|
+
return require_types.errorResult(`Reading the values failed: ${errorMessage(err)}`);
|
|
261
|
+
}
|
|
262
|
+
const values = [];
|
|
263
|
+
let naDropped = 0;
|
|
264
|
+
for (let i = 0; i < response.values.data.length; i++) {
|
|
265
|
+
const v = exactValue(response.values, i);
|
|
266
|
+
if (v === null) naDropped++;
|
|
267
|
+
else values.push(v);
|
|
268
|
+
}
|
|
269
|
+
const valueIds = axisSpec === void 0 && (0, _milaboratories_pl_model_common.isGlobalPObjectId)(columnId) ? (0, _milaboratories_pl_model_common.createColumnValueIds)({
|
|
270
|
+
column: columnId,
|
|
271
|
+
values: values.map(String)
|
|
272
|
+
}) : void 0;
|
|
273
|
+
return require_types.textResult({
|
|
274
|
+
columnId,
|
|
275
|
+
...axisSpec !== void 0 ? { axis: axisSpec.name } : {},
|
|
276
|
+
valueType,
|
|
277
|
+
count: values.length,
|
|
278
|
+
overflow: response.overflow,
|
|
279
|
+
...naDropped > 0 ? { naDropped } : {},
|
|
280
|
+
values,
|
|
281
|
+
...valueIds !== void 0 ? { valueIds } : {}
|
|
282
|
+
}, { hint: "Ask for fewer values: a smaller `limit`, or `search`." });
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The distinct values of a column of the result pool, or of one of its axes (`get_column_values`
|
|
286
|
+
* with `projectId`): read from a frame built over the column alone and released after. Its
|
|
287
|
+
* `valueIds` name the column by its pool id, and come, as for a frame, only for a block's export
|
|
288
|
+
* itself: a discovered pool column gets none.
|
|
289
|
+
*/
|
|
290
|
+
async function poolColumnValuesResult(project, projectId, driver, input, signal) {
|
|
291
|
+
const id = require_ids.columnIdFromAgent(input.columnId);
|
|
292
|
+
if (id === void 0) return require_types.errorResult(`${input.columnId} is not a column id of the result pool.`, "Copy `columnId` whole from list_pool_columns.");
|
|
293
|
+
const frame = project.createPoolFrame([id]);
|
|
294
|
+
try {
|
|
295
|
+
let built;
|
|
296
|
+
try {
|
|
297
|
+
built = await frame.getValue();
|
|
298
|
+
} catch (err) {
|
|
299
|
+
return require_types.errorResult(`Reading column ${id} failed: ${errorMessage(err)}`);
|
|
300
|
+
}
|
|
301
|
+
if (built.type === "refused") return poolColumnRefusedResult(built.refused, projectId);
|
|
302
|
+
return await columnValuesResult(driver, {
|
|
303
|
+
...input,
|
|
304
|
+
pFrameHandle: built.handle,
|
|
305
|
+
columnId: id
|
|
306
|
+
}, signal);
|
|
307
|
+
} finally {
|
|
308
|
+
frame.resetState();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** Why the values of pool columns cannot be read, by the issue the middle layer names. */
|
|
312
|
+
function poolColumnRefusedResult(refused, projectId) {
|
|
313
|
+
const lines = [];
|
|
314
|
+
const hints = /* @__PURE__ */ new Set();
|
|
315
|
+
for (const r of refused) switch (r.issue) {
|
|
316
|
+
case "unknown":
|
|
317
|
+
lines.push(`${r.columnId}: not in the result pool of project ${projectId}.`);
|
|
318
|
+
hints.add("Ids follow current specs: list_pool_columns again.");
|
|
319
|
+
break;
|
|
320
|
+
case "noData":
|
|
321
|
+
lines.push(`${r.columnId}: has no data; its block has not run, or exports it from a pre-run only.`);
|
|
322
|
+
hints.add("Run the block (run_block), wait for it (await_block_done), then try again.");
|
|
323
|
+
break;
|
|
324
|
+
case "notReady":
|
|
325
|
+
lines.push(`${r.columnId}: still being calculated by its block.`);
|
|
326
|
+
hints.add("Wait for the block (await_block_done), then try again.");
|
|
327
|
+
break;
|
|
328
|
+
case "failed":
|
|
329
|
+
lines.push(`${r.columnId}: its data failed: ${r.message ?? "no message"}.`);
|
|
330
|
+
hints.add("get_block_logs and get_project_overview tell why the block failed.");
|
|
331
|
+
break;
|
|
332
|
+
case "filtered":
|
|
333
|
+
lines.push(`${r.columnId}: filters an axis; its values would be the whole column's.`);
|
|
334
|
+
hints.add("Read the values of the column it filters, its `source`.");
|
|
335
|
+
}
|
|
336
|
+
return require_types.errorResult(`The values cannot be read.\n${lines.join("\n")}`, [...hints].join(" "));
|
|
337
|
+
}
|
|
338
|
+
const STALE_TABLE_NOTE = "The columns this table was built from changed since (a block ran again, or the project changed): call create_table again for current data.";
|
|
339
|
+
/**
|
|
340
|
+
* Rows of a PTable (`query_table`). `agentTable`: the table is one an agent built with
|
|
341
|
+
* create_table; the answer says so when it is stale, and the hints name create_table.
|
|
342
|
+
*/
|
|
343
|
+
async function queryTableResult(driver, input, signal, agentTable) {
|
|
344
|
+
const { pTableHandle, columns, transform, transformTimeout } = input;
|
|
345
|
+
const handle = pTableHandle;
|
|
346
|
+
const isAgentTable = agentTable !== void 0;
|
|
347
|
+
const staleFlag = agentTable?.stale === true ? {
|
|
348
|
+
stale: true,
|
|
349
|
+
staleNote: STALE_TABLE_NOTE
|
|
350
|
+
} : {};
|
|
351
|
+
let spec;
|
|
352
|
+
let totalRows;
|
|
353
|
+
try {
|
|
354
|
+
spec = await driver.getSpec(handle);
|
|
355
|
+
totalRows = (await driver.getShape(handle, signal)).rows;
|
|
356
|
+
} catch (err) {
|
|
357
|
+
if (isUnknownHandleError(err)) return staleHandleResult("PTable", pTableHandle, err);
|
|
358
|
+
if (signal?.aborted) return require_types.errorResult(`Reading the size of the table failed: ${errorMessage(err)}`, "The read took too long or was cancelled: try again, or ask for a smaller table.");
|
|
359
|
+
throw err;
|
|
360
|
+
}
|
|
361
|
+
if (columns !== void 0 && columns.length === 0) return require_types.errorResult("`columns` is empty: there is nothing to read.", "Leave `columns` out to read every column, or name the indices of the ones you need.");
|
|
362
|
+
const columnIndices = columns ?? spec.map((_, i) => i);
|
|
363
|
+
const outOfRange = columnIndices.filter((i) => !Number.isInteger(i) || i < 0 || i >= spec.length);
|
|
364
|
+
if (outOfRange.length > 0) return require_types.errorResult(`No columns ${outOfRange.join(", ")}: the table has columns 0 to ${spec.length - 1}.`, isAgentTable ? "create_table listed the table's columns with their indices." : "get_block_outputs lists the table's columns with their indices.");
|
|
365
|
+
const offset = clampInt(input.offset, 0, 0, Number.MAX_SAFE_INTEGER);
|
|
366
|
+
const effectiveLimit = clampInt(input.limit, 50, 0, QUERY_MAX_ROWS);
|
|
367
|
+
const length = Math.max(0, Math.min(effectiveLimit, totalRows - offset));
|
|
368
|
+
const range = {
|
|
369
|
+
offset,
|
|
370
|
+
length
|
|
371
|
+
};
|
|
372
|
+
let vectors;
|
|
373
|
+
try {
|
|
374
|
+
vectors = length === 0 ? [] : await driver.getData(handle, columnIndices, range, signal);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (isUnknownHandleError(err)) return staleHandleResult("PTable", pTableHandle, err);
|
|
377
|
+
return require_types.errorResult(`Reading rows ${offset} to ${offset + length} of columns [${columnIndices.join(", ")}] failed: ${errorMessage(err)}`, signal?.aborted ? "The read took too long or was cancelled: ask for fewer rows or columns." : isAgentTable ? "Ask for fewer rows or columns; if a block it reads ran again, call create_table again." : "Ask for fewer rows or columns; if the block ran again, get_block_outputs gives a fresh handle.");
|
|
378
|
+
}
|
|
379
|
+
const actualRows = vectors.length > 0 ? vectors[0].data.length : 0;
|
|
380
|
+
const columnVectors = vectors.map((v) => vectorToJson(v, actualRows));
|
|
381
|
+
const rows = [];
|
|
382
|
+
for (let r = 0; r < actualRows; r++) rows.push(columnVectors.map((col) => col[r]));
|
|
383
|
+
const columnHeaders = columnIndices.map((idx) => {
|
|
384
|
+
const s = spec[idx];
|
|
385
|
+
return {
|
|
386
|
+
index: idx,
|
|
387
|
+
type: s.type,
|
|
388
|
+
...s.type === "column" ? { columnId: s.id } : {},
|
|
389
|
+
name: s.spec.name,
|
|
390
|
+
label: (0, _milaboratories_pl_model_common.readAnnotation)(s.spec, _milaboratories_pl_model_common.Annotation.Label)
|
|
391
|
+
};
|
|
392
|
+
});
|
|
393
|
+
const bytesColumns = columnIndices.filter((_, i) => vectors[i]?.type === _milaboratories_pl_model_common.ValueType.Bytes);
|
|
394
|
+
const bytesNote = bytesColumns.length > 0 ? { note: `Columns ${bytesColumns.join(", ")} hold binary values; they are given by their size, \`{bytes: N}\`.` } : {};
|
|
395
|
+
const hasMore = offset + actualRows < totalRows;
|
|
396
|
+
if (transform) try {
|
|
397
|
+
const result = await require_sandbox.safeEval(transform, {
|
|
398
|
+
rows,
|
|
399
|
+
columns: columnHeaders,
|
|
400
|
+
offset,
|
|
401
|
+
rowCount: actualRows,
|
|
402
|
+
totalRows
|
|
403
|
+
}, transformTimeout);
|
|
404
|
+
return require_types.textResult(result);
|
|
405
|
+
} catch (e) {
|
|
406
|
+
return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: rows, columns, offset, rowCount, totalRows.");
|
|
407
|
+
}
|
|
408
|
+
return require_types.textResult({
|
|
409
|
+
...staleFlag,
|
|
410
|
+
offset,
|
|
411
|
+
rowCount: actualRows,
|
|
412
|
+
totalRows,
|
|
413
|
+
hasMore,
|
|
414
|
+
...hasMore ? { nextOffset: offset + actualRows } : {},
|
|
415
|
+
...bytesNote,
|
|
416
|
+
columns: columnHeaders,
|
|
417
|
+
rows
|
|
418
|
+
}, { hint: "Ask for fewer rows (`limit`) or columns (`columns`), or use `transform`." });
|
|
419
|
+
}
|
|
420
|
+
/** The most characters of the error text of one output named in `keys`; it is cut in the middle. */
|
|
421
|
+
const NAMED_OUTPUT_ERROR_CHARS = require_types.RESULT_CHAR_LIMIT / 2;
|
|
422
|
+
/**
|
|
423
|
+
* The outputs of a block for `get_block_outputs`: `{ calculationStatus, stale, note?, outputs }`,
|
|
424
|
+
* `outputs` output key → value, PFrame and PTable handles summed up (once per handle). An output
|
|
425
|
+
* that failed, or has no value, gives its `status` instead; a failed output named in `keys` also
|
|
426
|
+
* its error text, one not named a note saying how to read it. `note` says when the results are
|
|
427
|
+
* from an earlier configuration.
|
|
428
|
+
*/
|
|
429
|
+
async function blockOutputsResult(outputs, driver, options) {
|
|
430
|
+
const all = Object.keys(outputs);
|
|
431
|
+
if (options.keys !== void 0) {
|
|
432
|
+
const unknown = options.keys.filter((k) => !Object.hasOwn(outputs, k));
|
|
433
|
+
if (unknown.length > 0) return require_types.errorResult(`The block has no outputs ${unknown.join(", ")}.`, `Its outputs: ${all.join(", ") || "none"}.`);
|
|
434
|
+
}
|
|
435
|
+
const keys = options.keys ?? all;
|
|
436
|
+
const selected = Object.fromEntries(keys.map((k) => [k, outputs[k]]));
|
|
437
|
+
const summaries = new Map(require_tokens.summarizeOutputs(selected).map((s) => [s.key, s]));
|
|
438
|
+
const cache = /* @__PURE__ */ new Map();
|
|
439
|
+
const result = {};
|
|
440
|
+
for (const key of keys) {
|
|
441
|
+
const output = selected[key];
|
|
442
|
+
const summary = summaries.get(key);
|
|
443
|
+
if (summary === void 0 || !summary.hasValue) {
|
|
444
|
+
const status = summary?.status ?? "error";
|
|
445
|
+
const error = status === "error" ? require_tokens.outputErrorText(output) : void 0;
|
|
446
|
+
result[key] = error === void 0 ? { status } : options.keys !== void 0 ? {
|
|
447
|
+
status,
|
|
448
|
+
error: require_tokens.clipMiddle(error, NAMED_OUTPUT_ERROR_CHARS)
|
|
449
|
+
} : {
|
|
450
|
+
status,
|
|
451
|
+
note: require_tokens.failedOutputsNote(1, key)
|
|
452
|
+
};
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
result[key] = await resolveHandlesInValue((0, _milaboratories_helpers.isPlainObject)(output) ? output.value : void 0, driver, options.maxColumns, cache);
|
|
456
|
+
}
|
|
457
|
+
const { calculationStatus, stale } = options.block;
|
|
458
|
+
return require_types.textResult({
|
|
459
|
+
calculationStatus,
|
|
460
|
+
stale,
|
|
461
|
+
...calculationStatus === "Done" && stale ? { note: require_readiness.STALE_RESULTS_NOTE } : {},
|
|
462
|
+
outputs: dedupeHandleSummaries(result)
|
|
463
|
+
}, { hint: "Ask for fewer outputs (`keys`), a smaller `maxColumns`, or read one output with get_block_state `transform`, e.g. `outputs.<key>?.value`." });
|
|
464
|
+
}
|
|
465
|
+
function errorMessage(err) {
|
|
466
|
+
if (err instanceof Error) {
|
|
467
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
468
|
+
return `${err.message}${cause}`;
|
|
469
|
+
}
|
|
470
|
+
return String(err);
|
|
471
|
+
}
|
|
89
472
|
function registerDataQueryTools(server, ctx) {
|
|
473
|
+
const driver = () => ctx.requireMl().internalDriverKit.pFrameDriver;
|
|
90
474
|
server.registerTool("get_block_outputs", {
|
|
91
475
|
title: "Get Block Outputs",
|
|
92
476
|
annotations: require_types.hints.read,
|
|
93
|
-
description: "Get block output values
|
|
477
|
+
description: "Get block output values: `{ calculationStatus, stale, note?, outputs }`, `outputs` a JSON map, output key → value. `stale: true` with `calculationStatus` Done means the results are from an earlier configuration (`note` says so); run_block runs it again. PFrame/PTable handles are resolved inline to summaries with column specs (with `columnId`, for get_column_values); query_table counts rows; a handle already summed up earlier appears as `{ sameAs: \"<path>\" }`, the path to its summary in this result written as a JS accessor (`main.table`, `list[0]`). An output that failed or has no value gives `{ status }` instead (error or pending); a failed one named in `keys` adds its `error` text. Use this to discover block results and available data before querying tables.",
|
|
94
478
|
inputSchema: zod.z.object({
|
|
95
479
|
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
96
480
|
blockId: require_ids.blockIdInput.describe("Block ID"),
|
|
481
|
+
keys: zod.z.array(zod.z.string()).optional().describe("Only these outputs (default: all). get_block_state lists the output keys."),
|
|
97
482
|
maxColumns: zod.z.number().optional().default(30).describe("Max columns to show per PFrame/PTable summary (default 30).")
|
|
98
483
|
})
|
|
99
|
-
}, async ({ projectId, blockId, maxColumns }) => {
|
|
484
|
+
}, async ({ projectId, blockId, keys, maxColumns }) => {
|
|
100
485
|
return await ctx.withProject(projectId, async (project) => {
|
|
486
|
+
const { block, error } = await require_readiness.findBlock(project, projectId, blockId);
|
|
487
|
+
if (error) return error;
|
|
101
488
|
const state = await project.getBlockState(blockId).getValue();
|
|
102
489
|
if (!state.outputs) return require_types.errorResult("Block has no outputs yet.", "The block may not have been run. Use get_project_overview to check its calculationStatus, then run_block if needed.");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (!output?.ok || output.value == null) {
|
|
109
|
-
result[key] = { ok: output?.ok ?? false };
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
result[key] = await resolveHandlesInValue(output.value, driver, maxColumns, cache);
|
|
113
|
-
}
|
|
114
|
-
return require_types.textResult(result);
|
|
490
|
+
return await blockOutputsResult(state.outputs, driver(), {
|
|
491
|
+
block,
|
|
492
|
+
keys,
|
|
493
|
+
maxColumns
|
|
494
|
+
});
|
|
115
495
|
});
|
|
116
496
|
});
|
|
117
497
|
server.registerTool("list_columns", {
|
|
118
498
|
title: "List Columns",
|
|
119
499
|
annotations: require_types.hints.read,
|
|
120
|
-
description: "List
|
|
500
|
+
description: "List the columns of a PFrame, a page at a time: `{ total, offset, hasMore, nextOffset?, columns: [{ columnId, name, valueType, label, axes }] }`. Filter by `name` (part of the name or label), `valueType` or `annotations`; `detail: \"full\"` adds domains, annotations and axis specs. `columnId` is the column's id as a block or table refers to it. Use get_block_outputs first to find the PFrame handle; get_column_values reads a column's values and their `valueIds` by its `columnId`.",
|
|
121
501
|
inputSchema: zod.z.object({
|
|
122
502
|
projectId: require_ids.projectIdInput.describe("Project the handle came from"),
|
|
123
|
-
pFrameHandle: require_ids.pFrameHandleInput.describe("PFrame handle (64-char hex hash from get_block_outputs)")
|
|
503
|
+
pFrameHandle: require_ids.pFrameHandleInput.describe("PFrame handle (64-char hex hash from get_block_outputs)"),
|
|
504
|
+
name: zod.z.string().optional().describe("Only columns whose name or label contains this (case-insensitive)."),
|
|
505
|
+
valueType: zod.z.string().optional().describe("Only columns of this value type: Int, Long, Float, Double, String…"),
|
|
506
|
+
annotations: zod.z.record(zod.z.string(), zod.z.string()).optional().describe("Only columns with these annotation values, e.g. `{\"pl7.app/isAnchor\": \"true\"}`."),
|
|
507
|
+
detail: zod.z.enum(["brief", "full"]).optional().describe("`brief` (default): ids, names, labels, axis names; `full`: whole specs."),
|
|
508
|
+
offset: zod.z.number().optional().describe("Columns to skip (default 0)."),
|
|
509
|
+
limit: zod.z.number().optional().describe(`Columns per page (default 100, at most ${LIST_COLUMNS_MAX}).`)
|
|
124
510
|
})
|
|
125
|
-
}, async ({ projectId, pFrameHandle }) => {
|
|
126
|
-
return await ctx.withProject(projectId,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
})));
|
|
147
|
-
});
|
|
511
|
+
}, async ({ projectId, pFrameHandle, ...options }) => {
|
|
512
|
+
return await ctx.withProject(projectId, () => listColumnsResult(driver(), pFrameHandle, options));
|
|
513
|
+
});
|
|
514
|
+
server.registerTool("get_column_values", {
|
|
515
|
+
title: "Get Column Values",
|
|
516
|
+
annotations: require_types.hints.read,
|
|
517
|
+
description: "Get the distinct values of a column of a PFrame, or of one of its axes: the choices a block offers for a value of its data (a sample, a chain, a gene…). Result: `{ columnId, axis?, valueType, count, overflow, naDropped?, values, valueIds? }`; `valueIds` holds the ColumnValueId of each value, in the same order: copy it into a block that picks values. `valueIds` come only for a block's export itself, the columns a block can use; a column local to one block, a filtered, overridden or discovered column, or an axis, gives none. `overflow: true` means there are more than `limit` values. Missing values (NA) are left out. Column ids come from list_columns or the PFrame summaries of get_block_outputs; values of a pool column come by its `columnId` from list_pool_columns, without `pFrameHandle`.",
|
|
518
|
+
inputSchema: zod.z.object({
|
|
519
|
+
projectId: require_ids.projectIdInput.describe("Project the handle came from, or of the result-pool column."),
|
|
520
|
+
pFrameHandle: require_ids.pFrameHandleInput.optional().describe("PFrame handle (64-char hex hash from get_block_outputs); omit for a pool column."),
|
|
521
|
+
columnId: require_ids.frameColumnIdInput.describe("Column id, from list_columns, or from list_pool_columns without `pFrameHandle`."),
|
|
522
|
+
axis: zod.z.union([zod.z.number(), zod.z.string()]).optional().describe("An axis of the column, by index or name: its values instead of the column's."),
|
|
523
|
+
search: zod.z.string().optional().describe("Only values that contain this text (case-insensitive; string values only)."),
|
|
524
|
+
limit: zod.z.number().optional().describe(`The most values to return (default 100, at most ${COLUMN_VALUES_MAX}).`)
|
|
525
|
+
})
|
|
526
|
+
}, async ({ pFrameHandle, projectId, ...input }, call) => {
|
|
527
|
+
const signal = require_types.readSignal(call?.mcpReq.signal);
|
|
528
|
+
return await ctx.withProject(projectId, (project) => pFrameHandle === void 0 ? poolColumnValuesResult(project, projectId, driver(), input, signal) : columnValuesResult(driver(), {
|
|
529
|
+
...input,
|
|
530
|
+
pFrameHandle
|
|
531
|
+
}, signal));
|
|
148
532
|
});
|
|
149
533
|
server.registerTool("query_table", {
|
|
150
534
|
title: "Query Table",
|
|
151
535
|
annotations: require_types.hints.read,
|
|
152
|
-
description:
|
|
536
|
+
description: `Query data from a PTable. Returns rows as arrays of values, with \`columns: [{ index, type, columnId?, name, label }]\` (\`columnId\` on columns, not axes), \`totalRows\`, \`hasMore\` and \`nextOffset\` for the next page. At most ${QUERY_MAX_ROWS} rows per call. The handle comes from get_block_outputs, or from create_table for a table of your own; for such a table \`stale: true\` says its source columns changed since it was built (not given with \`transform\`). Use \`transform\` to process results server-side and return only what you need.`,
|
|
153
537
|
inputSchema: zod.z.object({
|
|
154
538
|
projectId: require_ids.projectIdInput.describe("Project the handle came from"),
|
|
155
|
-
pTableHandle: require_ids.pTableHandleInput.describe("PTable handle (64-char hex hash from get_block_outputs)"),
|
|
156
|
-
columns: zod.z.array(zod.z.number()).optional().describe("Column indices to retrieve (default: all).
|
|
539
|
+
pTableHandle: require_ids.pTableHandleInput.describe("PTable handle (64-char hex hash from get_block_outputs or create_table)"),
|
|
540
|
+
columns: zod.z.array(zod.z.number()).optional().describe("Column indices to retrieve (default: all; not empty). get_block_outputs and create_table list column indices. Binary columns give each value's size, `{bytes: N}`."),
|
|
157
541
|
offset: zod.z.number().optional().default(0).describe("Row offset (default 0)"),
|
|
158
|
-
limit: zod.z.number().optional().default(50).describe(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
transformTimeout: zod.z.number().optional().default(5e3).describe("Timeout in ms for transform evaluation (default 5000).")
|
|
542
|
+
limit: zod.z.number().optional().default(50).describe(`Number of rows to return (default 50, at most ${QUERY_MAX_ROWS}).`),
|
|
543
|
+
transform: zod.z.string().optional().describe("JS expression evaluated server-side against query results. Available variables: `rows` (array of row arrays), `columns` (column headers), `offset`, `rowCount`, `totalRows`. Example: `rows.map(r => r[0])` — extract first column only."),
|
|
544
|
+
transformTimeout: zod.z.number().optional().default(5e3).describe(require_sandbox.expressionTimeoutText("transform evaluation", 5e3))
|
|
162
545
|
})
|
|
163
|
-
}, async (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
let spec;
|
|
168
|
-
try {
|
|
169
|
-
spec = await pFrameDriver.getSpec(handle);
|
|
170
|
-
} catch (err) {
|
|
171
|
-
if (isUnknownHandleError(err)) return staleHandleResult("PTable", pTableHandle, err);
|
|
172
|
-
throw err;
|
|
173
|
-
}
|
|
174
|
-
const range = {
|
|
175
|
-
offset,
|
|
176
|
-
length: Math.min(limit, maxLimit)
|
|
177
|
-
};
|
|
178
|
-
const columnIndices = columns ?? spec.map((_, i) => i);
|
|
179
|
-
let vectors;
|
|
180
|
-
try {
|
|
181
|
-
vectors = await pFrameDriver.getData(handle, columnIndices, range);
|
|
182
|
-
} catch (err) {
|
|
183
|
-
if (isUnknownHandleError(err)) return staleHandleResult("PTable", pTableHandle, err);
|
|
184
|
-
return require_types.textResult({
|
|
185
|
-
error: `getData failed: ${err}`,
|
|
186
|
-
columnIndices,
|
|
187
|
-
range
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const actualRows = vectors.length > 0 ? vectors[0].data.length : 0;
|
|
191
|
-
const columnVectors = vectors.map((v) => vectorToJson(v, actualRows));
|
|
192
|
-
const rows = [];
|
|
193
|
-
for (let r = 0; r < actualRows; r++) rows.push(columnVectors.map((col) => col[r]));
|
|
194
|
-
const columnHeaders = columnIndices.map((idx) => {
|
|
195
|
-
const s = spec[idx];
|
|
196
|
-
return {
|
|
197
|
-
index: idx,
|
|
198
|
-
type: s.type,
|
|
199
|
-
name: s.type === "column" ? s.spec.name : s.spec.name,
|
|
200
|
-
label: (0, _milaboratories_pl_model_common.readAnnotation)(s.spec, _milaboratories_pl_model_common.Annotation.Label)
|
|
201
|
-
};
|
|
202
|
-
});
|
|
203
|
-
if (transform) try {
|
|
204
|
-
const result = await require_sandbox.safeEval(transform, {
|
|
205
|
-
rows,
|
|
206
|
-
columns: columnHeaders,
|
|
207
|
-
offset,
|
|
208
|
-
rowCount: actualRows
|
|
209
|
-
}, transformTimeout);
|
|
210
|
-
return require_types.textResult(result);
|
|
211
|
-
} catch (e) {
|
|
212
|
-
return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: rows, columns, offset, rowCount.");
|
|
213
|
-
}
|
|
214
|
-
return require_types.textResult({
|
|
215
|
-
offset,
|
|
216
|
-
rowCount: actualRows,
|
|
217
|
-
columns: columnHeaders,
|
|
218
|
-
rows
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
|
546
|
+
}, async (input, call) => await ctx.withProject(input.projectId, async (_project, ml) => {
|
|
547
|
+
const table = ctx.agentTables.use(input.pTableHandle);
|
|
548
|
+
return await queryTableResult(ml.internalDriverKit.pFrameDriver, input, require_types.readSignal(call?.mcpReq.signal), table === void 0 ? void 0 : { stale: table.stale });
|
|
549
|
+
}));
|
|
222
550
|
}
|
|
551
|
+
exports.COLUMN_VALUES_MAX = COLUMN_VALUES_MAX;
|
|
552
|
+
exports.LIST_COLUMNS_MAX = LIST_COLUMNS_MAX;
|
|
553
|
+
exports.NAMED_OUTPUT_ERROR_CHARS = NAMED_OUTPUT_ERROR_CHARS;
|
|
554
|
+
exports.QUERY_MAX_ROWS = QUERY_MAX_ROWS;
|
|
555
|
+
exports.blockOutputsResult = blockOutputsResult;
|
|
556
|
+
exports.columnValuesResult = columnValuesResult;
|
|
557
|
+
exports.dedupeHandleSummaries = dedupeHandleSummaries;
|
|
558
|
+
exports.listColumnsResult = listColumnsResult;
|
|
559
|
+
exports.poolColumnValuesResult = poolColumnValuesResult;
|
|
560
|
+
exports.queryTableResult = queryTableResult;
|
|
223
561
|
exports.registerDataQueryTools = registerDataQueryTools;
|
|
224
562
|
|
|
225
563
|
//# sourceMappingURL=data-query.cjs.map
|