@milaboratories/pl-mcp-server 53.1.0 → 55.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -37
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +16 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +16 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +122 -0
- package/dist/project-holds.cjs.map +1 -0
- package/dist/project-holds.js +122 -0
- package/dist/project-holds.js.map +1 -0
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +48 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +48 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +71 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +37 -24
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +71 -19
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -72
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -74
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +14 -9
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +14 -9
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +275 -6
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +273 -8
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +343 -57
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +337 -61
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +199 -76
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +193 -76
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +470 -101
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +465 -106
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +72 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +63 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +111 -30
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +108 -31
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +68 -38
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +69 -40
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +16 -12
- package/src/project-holds.test.ts +362 -0
- package/src/project-holds.ts +207 -0
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +71 -6
- package/src/server-log.ts +58 -27
- package/src/server.logging.test.ts +46 -51
- package/src/server.test.ts +166 -22
- package/src/server.ts +97 -37
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -122
- package/src/tools/block-action-context.ts +17 -13
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +626 -10
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +678 -83
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +354 -113
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +839 -145
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +89 -1
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +154 -44
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +136 -48
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +84 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
const require_types = require("./types.cjs");
|
|
2
|
+
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_result_pool = require("./result-pool.cjs");
|
|
4
|
+
let zod = require("zod");
|
|
5
|
+
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
6
|
+
let _platforma_sdk_model = require("@platforma-sdk/model");
|
|
7
|
+
// src/tools/agent-tables.ts
|
|
8
|
+
/** How long a table an agent built is kept after it was built or last read: three minutes. */
|
|
9
|
+
const AGENT_TABLE_IDLE_MS = 18e4;
|
|
10
|
+
/** How long `create_table` waits for the row count before it answers without it. */
|
|
11
|
+
const CREATE_TABLE_ROWS_TIMEOUT_MS = 2e4;
|
|
12
|
+
const domainInput = zod.z.record(zod.z.string(), zod.z.string());
|
|
13
|
+
/** A column id of `create_table`, as `columnIdInput` takes it. */
|
|
14
|
+
const tableColumnIdInput = require_ids.columnIdInput.meta({ id: "ColumnId" });
|
|
15
|
+
const refInput = zod.z.union([zod.z.strictObject({ column: tableColumnIdInput }), zod.z.strictObject({
|
|
16
|
+
axis: zod.z.string().min(1),
|
|
17
|
+
domain: domainInput.optional(),
|
|
18
|
+
contextDomain: domainInput.optional()
|
|
19
|
+
})]).meta({ id: "TableColumnRef" });
|
|
20
|
+
const leafInput = zod.z.union([
|
|
21
|
+
zod.z.strictObject({
|
|
22
|
+
type: zod.z.enum(["isNA", "isNotNA"]),
|
|
23
|
+
column: refInput
|
|
24
|
+
}),
|
|
25
|
+
zod.z.strictObject({
|
|
26
|
+
type: zod.z.enum([
|
|
27
|
+
"patternEquals",
|
|
28
|
+
"patternNotEquals",
|
|
29
|
+
"patternContainSubsequence",
|
|
30
|
+
"patternNotContainSubsequence"
|
|
31
|
+
]),
|
|
32
|
+
column: refInput,
|
|
33
|
+
value: zod.z.string()
|
|
34
|
+
}),
|
|
35
|
+
zod.z.strictObject({
|
|
36
|
+
type: zod.z.literal("patternMatchesRegularExpression"),
|
|
37
|
+
column: refInput,
|
|
38
|
+
value: require_result_pool.regexText("A `patternMatchesRegularExpression` value")
|
|
39
|
+
}),
|
|
40
|
+
zod.z.strictObject({
|
|
41
|
+
type: zod.z.literal("patternFuzzyContainSubsequence"),
|
|
42
|
+
column: refInput,
|
|
43
|
+
value: zod.z.string(),
|
|
44
|
+
maxEdits: zod.z.number().int().min(0).optional(),
|
|
45
|
+
substitutionsOnly: zod.z.boolean().optional(),
|
|
46
|
+
wildcard: zod.z.string().optional()
|
|
47
|
+
}),
|
|
48
|
+
zod.z.strictObject({
|
|
49
|
+
type: zod.z.enum(["inSet", "notInSet"]),
|
|
50
|
+
column: refInput,
|
|
51
|
+
value: zod.z.array(zod.z.string())
|
|
52
|
+
}),
|
|
53
|
+
zod.z.strictObject({
|
|
54
|
+
type: zod.z.enum([
|
|
55
|
+
"equal",
|
|
56
|
+
"notEqual",
|
|
57
|
+
"lessThan",
|
|
58
|
+
"greaterThan",
|
|
59
|
+
"lessThanOrEqual",
|
|
60
|
+
"greaterThanOrEqual"
|
|
61
|
+
]),
|
|
62
|
+
column: refInput,
|
|
63
|
+
x: zod.z.number()
|
|
64
|
+
}),
|
|
65
|
+
zod.z.strictObject({
|
|
66
|
+
type: zod.z.literal("equalToColumn"),
|
|
67
|
+
column: refInput,
|
|
68
|
+
rhs: refInput
|
|
69
|
+
}),
|
|
70
|
+
zod.z.strictObject({
|
|
71
|
+
type: zod.z.enum([
|
|
72
|
+
"lessThanColumn",
|
|
73
|
+
"greaterThanColumn",
|
|
74
|
+
"lessThanColumnOrEqual",
|
|
75
|
+
"greaterThanColumnOrEqual"
|
|
76
|
+
]),
|
|
77
|
+
column: refInput,
|
|
78
|
+
rhs: refInput,
|
|
79
|
+
minDiff: zod.z.number().optional()
|
|
80
|
+
})
|
|
81
|
+
]);
|
|
82
|
+
/** A table filter as an agent writes it. */
|
|
83
|
+
const tableFilterInput = zod.z.lazy(() => zod.z.union([
|
|
84
|
+
leafInput,
|
|
85
|
+
zod.z.strictObject({
|
|
86
|
+
type: zod.z.literal("not"),
|
|
87
|
+
filter: tableFilterInput
|
|
88
|
+
}),
|
|
89
|
+
zod.z.strictObject({
|
|
90
|
+
type: zod.z.enum(["and", "or"]),
|
|
91
|
+
filters: zod.z.array(tableFilterInput).min(1)
|
|
92
|
+
})
|
|
93
|
+
])).meta({ id: "TableFilter" });
|
|
94
|
+
const sortKeyFields = {
|
|
95
|
+
ascending: zod.z.boolean().optional(),
|
|
96
|
+
nullsFirst: zod.z.boolean().optional()
|
|
97
|
+
};
|
|
98
|
+
/** The sort keys of a table as an agent writes them. */
|
|
99
|
+
const tableSortInput = zod.z.array(zod.z.union([zod.z.strictObject({
|
|
100
|
+
column: tableColumnIdInput,
|
|
101
|
+
...sortKeyFields
|
|
102
|
+
}), zod.z.strictObject({
|
|
103
|
+
axis: zod.z.string().min(1),
|
|
104
|
+
domain: domainInput.optional(),
|
|
105
|
+
contextDomain: domainInput.optional(),
|
|
106
|
+
...sortKeyFields
|
|
107
|
+
})])).max(16);
|
|
108
|
+
/** A request `create_table` cannot build a table from: what is wrong, and how to fix it. */
|
|
109
|
+
var TableRequestError = class extends Error {
|
|
110
|
+
hint;
|
|
111
|
+
constructor(message, hint) {
|
|
112
|
+
super(message);
|
|
113
|
+
this.hint = hint;
|
|
114
|
+
this.name = "TableRequestError";
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The definition of the table `request` asks for over the pool columns `lookUp` finds, built the
|
|
119
|
+
* way a block's `createPTableDefV3` builds one: the primary columns inner- or full-joined,
|
|
120
|
+
* secondary columns outer-joined onto them, then the filter, then the sort. Each column is named
|
|
121
|
+
* by its id, discovered, filtered and overridden ids included: the middle layer builds the query an
|
|
122
|
+
* id stands for. A column reference names one of the table's columns by its id; an axis reference
|
|
123
|
+
* is a selector (name, and domain or context domain when given) the engine matches against the
|
|
124
|
+
* axes the join's rows are over, refusing one that matches no axis or several. Columns that share
|
|
125
|
+
* no axis to join on are refused by the engine too.
|
|
126
|
+
*
|
|
127
|
+
* @throws {TableRequestError} for a column not in the pool or named twice, a reference to a column
|
|
128
|
+
* not in the table, and a filter over the limits
|
|
129
|
+
*/
|
|
130
|
+
function createTableDef(request, lookUp) {
|
|
131
|
+
const primary = lookUpAll(request.columns, lookUp);
|
|
132
|
+
const secondary = lookUpAll(request.secondary ?? [], lookUp);
|
|
133
|
+
const unknown = [...primary.unknown, ...secondary.unknown];
|
|
134
|
+
if (unknown.length > 0) throw new TableRequestError(`No column ${unknown.join(", ")} in the result pool of the project.`, "list_pool_columns lists the columns and their ids; copy a `columnId` whole. Ids follow current specs: list_pool_columns again.");
|
|
135
|
+
if (primary.found.length === 0) throw new TableRequestError("`columns` is empty.", "Give at least one column id.");
|
|
136
|
+
const columns = [...primary.found, ...secondary.found];
|
|
137
|
+
const ids = columns.map((c) => c.columnId);
|
|
138
|
+
const twice = [...new Set(ids.filter((id, i) => ids.indexOf(id) !== i))];
|
|
139
|
+
if (twice.length > 0) throw new TableRequestError(`Column ${twice.join(", ")} is named twice.`, "Name each column once, in `columns` or in `secondary`.");
|
|
140
|
+
let query = {
|
|
141
|
+
type: (request.join ?? "inner") === "inner" ? "innerJoin" : "fullJoin",
|
|
142
|
+
entries: primary.found.map((c) => ({ entry: {
|
|
143
|
+
type: "column",
|
|
144
|
+
column: c.columnId
|
|
145
|
+
} }))
|
|
146
|
+
};
|
|
147
|
+
if (secondary.found.length > 0) query = {
|
|
148
|
+
type: "outerJoin",
|
|
149
|
+
primary: { entry: query },
|
|
150
|
+
secondary: secondary.found.map((c) => ({ entry: {
|
|
151
|
+
type: "column",
|
|
152
|
+
column: c.columnId
|
|
153
|
+
} }))
|
|
154
|
+
};
|
|
155
|
+
const ref = (r) => queryRef(r, ids);
|
|
156
|
+
if (request.filter !== void 0) {
|
|
157
|
+
const nodes = countNodes(request.filter);
|
|
158
|
+
if (nodes > 200) throw new TableRequestError(`The filter has ${nodes} nodes; at most 200 are taken.`, "Use `inSet` for a list of values, or a smaller filter.");
|
|
159
|
+
const predicate = (0, _platforma_sdk_model.filterSpecToSpecQueryExpr)(mapFilter(request.filter, ref));
|
|
160
|
+
if (!(0, _milaboratories_pl_model_common.isBooleanExpression)(predicate)) throw new TableRequestError("The filter does not give true or false for a row.", "Use comparisons, patterns, sets and `isNA`, combined with `and`, `or`, `not`.");
|
|
161
|
+
query = {
|
|
162
|
+
type: "filter",
|
|
163
|
+
input: query,
|
|
164
|
+
predicate
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (request.sort !== void 0 && request.sort.length > 0) query = {
|
|
168
|
+
type: "sort",
|
|
169
|
+
input: query,
|
|
170
|
+
sortBy: request.sort.map((key) => ({
|
|
171
|
+
expression: refExpression(ref(key)),
|
|
172
|
+
ascending: key.ascending ?? true,
|
|
173
|
+
nullsFirst: key.nullsFirst ?? false
|
|
174
|
+
}))
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
def: { query },
|
|
178
|
+
columns
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function lookUpAll(ids, lookUp) {
|
|
182
|
+
const found = [];
|
|
183
|
+
const unknown = [];
|
|
184
|
+
for (const id of ids) {
|
|
185
|
+
const column = lookUp(id);
|
|
186
|
+
if (column === void 0) unknown.push(id);
|
|
187
|
+
else found.push(column);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
found,
|
|
191
|
+
unknown
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* A reference of a filter or sort as a query names it: a column of the table (`ids`, canonical as
|
|
196
|
+
* looked up; the reference's id is canonical as parsed), or an axis by its selector.
|
|
197
|
+
*/
|
|
198
|
+
function queryRef(ref, ids) {
|
|
199
|
+
if ("axis" in ref) return {
|
|
200
|
+
type: "axis",
|
|
201
|
+
id: {
|
|
202
|
+
name: ref.axis,
|
|
203
|
+
...ref.domain !== void 0 ? { domain: ref.domain } : {},
|
|
204
|
+
...ref.contextDomain !== void 0 ? { contextDomain: ref.contextDomain } : {}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
if (!ids.includes(ref.column)) throw new TableRequestError(`Column ${ref.column} is not in the table: a filter or a sort reads only the table's columns.`, "Add the column to `secondary` (or `columns`), and refer to it by the same id.");
|
|
208
|
+
return {
|
|
209
|
+
type: "column",
|
|
210
|
+
id: ref.column
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function columnText(c) {
|
|
214
|
+
return `${(0, _milaboratories_pl_model_common.readAnnotation)(c.spec, _milaboratories_pl_model_common.Annotation.Label) ?? c.spec.name} ${c.columnId}`;
|
|
215
|
+
}
|
|
216
|
+
const JOIN_HINT = "Columns join on their common axes: the same name, type and domain. list_pool_columns shows each column's axes; pick columns over the same axis, or build a table per group.";
|
|
217
|
+
function countNodes(filter) {
|
|
218
|
+
switch (filter.type) {
|
|
219
|
+
case "not": return 1 + countNodes(filter.filter);
|
|
220
|
+
case "and":
|
|
221
|
+
case "or": return 1 + filter.filters.reduce((n, f) => n + countNodes(f), 0);
|
|
222
|
+
default: return 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** `filter` with its column references made query references by `ref`. */
|
|
226
|
+
function mapFilter(filter, ref) {
|
|
227
|
+
switch (filter.type) {
|
|
228
|
+
case "not": return {
|
|
229
|
+
type: "not",
|
|
230
|
+
filter: mapFilter(filter.filter, ref)
|
|
231
|
+
};
|
|
232
|
+
case "and":
|
|
233
|
+
case "or": return {
|
|
234
|
+
type: filter.type,
|
|
235
|
+
filters: filter.filters.map((f) => mapFilter(f, ref))
|
|
236
|
+
};
|
|
237
|
+
default: return mapLeaf(filter, ref);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function mapLeaf(leaf, ref) {
|
|
241
|
+
if ("rhs" in leaf) return {
|
|
242
|
+
...leaf,
|
|
243
|
+
column: ref(leaf.column),
|
|
244
|
+
rhs: ref(leaf.rhs)
|
|
245
|
+
};
|
|
246
|
+
return {
|
|
247
|
+
...leaf,
|
|
248
|
+
column: ref(leaf.column)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function refExpression(ref) {
|
|
252
|
+
return ref.type === "axis" ? {
|
|
253
|
+
type: "axisRef",
|
|
254
|
+
value: ref.id
|
|
255
|
+
} : {
|
|
256
|
+
type: "columnRef",
|
|
257
|
+
value: ref.id
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Builds the table `request` asks for over the project's pool columns (`create_table`). */
|
|
261
|
+
async function createTableResult(project, projectId, request, deps, signal, blockTitle = (id) => id) {
|
|
262
|
+
const found = /* @__PURE__ */ new Map();
|
|
263
|
+
try {
|
|
264
|
+
await lookUpInto(project, [...request.columns, ...request.secondary ?? []], found);
|
|
265
|
+
} catch (err) {
|
|
266
|
+
return require_types.errorResult(`Reading the result pool failed: ${errorMessage(err)}`);
|
|
267
|
+
}
|
|
268
|
+
let table;
|
|
269
|
+
try {
|
|
270
|
+
table = createTableDef(request, (id) => found.get(id));
|
|
271
|
+
} catch (err) {
|
|
272
|
+
if (err instanceof TableRequestError) return require_types.errorResult(err.message, err.hint);
|
|
273
|
+
throw err;
|
|
274
|
+
}
|
|
275
|
+
const built = await buildTable(project, table.def, table.columns, blockTitle);
|
|
276
|
+
if (built.type === "error") return built.result;
|
|
277
|
+
const { handle } = built;
|
|
278
|
+
const evicted = deps.tables.add(projectId, handle, built.table);
|
|
279
|
+
let spec;
|
|
280
|
+
try {
|
|
281
|
+
spec = await deps.driver.getSpec(handle);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
return require_types.errorResult(`Reading the columns of the new table failed: ${errorMessage(err)}`);
|
|
284
|
+
}
|
|
285
|
+
const timeout = AbortSignal.timeout(deps.rowsTimeoutMs ?? 2e4);
|
|
286
|
+
let rows = null;
|
|
287
|
+
let rowsNote;
|
|
288
|
+
try {
|
|
289
|
+
rows = (await deps.driver.getShape(handle, signal === void 0 ? timeout : AbortSignal.any([signal, timeout]))).rows;
|
|
290
|
+
} catch (err) {
|
|
291
|
+
if (signal?.aborted) return require_types.errorResult("Building the table was cancelled.");
|
|
292
|
+
rowsNote = timeout.aborted ? "Counting the rows took too long; the table is built as you read it: query_table reads it and gives `totalRows`." : `Counting the rows failed: ${errorMessage(err)}`;
|
|
293
|
+
}
|
|
294
|
+
return require_types.textResult({
|
|
295
|
+
pTableHandle: handle,
|
|
296
|
+
rows,
|
|
297
|
+
...rowsNote !== void 0 ? { note: rowsNote } : {},
|
|
298
|
+
expiresInSec: deps.tables.expiresInSec,
|
|
299
|
+
...evicted.length > 0 ? {
|
|
300
|
+
evicted,
|
|
301
|
+
evictedNote: `At most 16 tables stay open: the least recently used, listed in \`evicted\`, were dropped.`
|
|
302
|
+
} : {},
|
|
303
|
+
columns: spec.map((s, index) => ({
|
|
304
|
+
index,
|
|
305
|
+
type: s.type,
|
|
306
|
+
name: s.spec.name,
|
|
307
|
+
label: (0, _milaboratories_pl_model_common.readAnnotation)(s.spec, _milaboratories_pl_model_common.Annotation.Label),
|
|
308
|
+
...s.type === "column" ? { columnId: s.id } : {}
|
|
309
|
+
}))
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Builds the table `def` defines; a table the engine or the middle layer refuses is given back,
|
|
314
|
+
* and the error says why, naming `columns` with the titles of their blocks.
|
|
315
|
+
*/
|
|
316
|
+
async function buildTable(project, def, columns, blockTitle) {
|
|
317
|
+
const table = project.createPoolTable(def);
|
|
318
|
+
let built;
|
|
319
|
+
try {
|
|
320
|
+
built = await table.getValue();
|
|
321
|
+
} catch (err) {
|
|
322
|
+
table.resetState();
|
|
323
|
+
return {
|
|
324
|
+
type: "error",
|
|
325
|
+
result: require_types.errorResult(`The table could not be built: ${errorMessage(err)}`, `Check the columns, and the axes the filter and sort name. ${JOIN_HINT}`)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (built.type === "refused") {
|
|
329
|
+
table.resetState();
|
|
330
|
+
return {
|
|
331
|
+
type: "error",
|
|
332
|
+
result: refusedResult(built.refused, columns, blockTitle)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
type: "ok",
|
|
337
|
+
table,
|
|
338
|
+
handle: built.handle
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/** Puts the pool columns `ids` stand for into `found`, by id; an unknown id is left out. */
|
|
342
|
+
async function lookUpInto(project, ids, found) {
|
|
343
|
+
const missing = [...new Set(ids)].filter((id) => !found.has(id));
|
|
344
|
+
if (missing.length === 0) return;
|
|
345
|
+
const columns = await project.getPoolColumnsById(missing).getValue();
|
|
346
|
+
missing.forEach((id, i) => {
|
|
347
|
+
const column = columns[i];
|
|
348
|
+
if (column !== void 0) found.set(id, column);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/** What `create_table` answers when the middle layer refused columns. */
|
|
352
|
+
function refusedResult(refused, columns, blockTitle) {
|
|
353
|
+
const lines = [];
|
|
354
|
+
const hints = /* @__PURE__ */ new Set();
|
|
355
|
+
for (const r of refused) {
|
|
356
|
+
const column = columns.find((c) => c.columnId === r.columnId);
|
|
357
|
+
const block = column === void 0 ? "its block" : `block ${blockTitle(column.producedBy)}`;
|
|
358
|
+
const name = column === void 0 ? r.columnId : columnText(column);
|
|
359
|
+
switch (r.issue) {
|
|
360
|
+
case "unknown":
|
|
361
|
+
lines.push(`${name}: no longer in the result pool.`);
|
|
362
|
+
hints.add("list_pool_columns lists the columns there are now.");
|
|
363
|
+
break;
|
|
364
|
+
case "noData":
|
|
365
|
+
lines.push(`${name}: has no data; ${block} has not run, or exports it from a pre-run only.`);
|
|
366
|
+
hints.add("Run the block (run_block), wait for it (await_block_done), then try again.");
|
|
367
|
+
break;
|
|
368
|
+
case "notReady":
|
|
369
|
+
lines.push(`${name}: still being calculated by ${block}.`);
|
|
370
|
+
hints.add("Wait for the block (await_block_done), then try again.");
|
|
371
|
+
break;
|
|
372
|
+
case "failed":
|
|
373
|
+
lines.push(`${name}: its data failed: ${r.message ?? "no message"}.`);
|
|
374
|
+
hints.add("get_block_logs and get_project_overview tell why the block failed.");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return require_types.errorResult(`No table was built: these columns cannot be read.\n${lines.join("\n")}`, [...hints].join(" "));
|
|
378
|
+
}
|
|
379
|
+
function errorMessage(err) {
|
|
380
|
+
if (err instanceof Error && typeof err.cause === "string") return err.cause;
|
|
381
|
+
return err instanceof Error ? err.message : String(err);
|
|
382
|
+
}
|
|
383
|
+
const REF_TEXT = "A reference is `{ column: \"<columnId>\" }` (a column of the table, by the id given in `columns` or `secondary`) or `{ axis: \"<axis name>\", domain?: {…}, contextDomain?: {…} }`, an axis the table's rows are over (a discovered column's rows are over the axes its linkers lead to); domain or contextDomain only when axes share the name.";
|
|
384
|
+
function registerAgentTableTools(server, ctx) {
|
|
385
|
+
server.registerTool("create_table", {
|
|
386
|
+
title: "Create Table",
|
|
387
|
+
annotations: require_types.hints.additive,
|
|
388
|
+
description: `Build a temporary table from result-pool columns of a project (ids from list_pool_columns), to answer a question over large results: join columns of several blocks, filter and sort rows, then read it with query_table and throw it away. Result: \`{ pTableHandle, rows, note?, expiresInSec, evicted?, columns: [{ index, type, name, label, columnId? }] }\`; \`rows\` is null when counting took too long. \`columns\` are joined on their common axes (same name, type and domain), \`join: "inner"\` (default: rows present in every column) or \`"full"\` (rows of any column); \`secondary\` columns are added to every row the primary join gives, where they have a value. Columns must be ready: a block still running or not run is refused, saying which. The table is dropped after ${AGENT_TABLE_IDLE_MS / 1e3} s without a read, with drop_table, when the server lets go of the project, or when more than 16 are open (the least recently used goes). query_table says \`stale: true\` when its source columns changed. A large table can slow the user's open tables while it builds.`,
|
|
389
|
+
inputSchema: zod.z.object({
|
|
390
|
+
projectId: require_ids.projectIdInput.describe("Project ID"),
|
|
391
|
+
columns: zod.z.array(tableColumnIdInput).min(1).max(64).describe("Column ids from list_pool_columns (discovered ids included, put them in `secondary` to keep their linker qualifications), or PlRef objects; joined by `join`."),
|
|
392
|
+
join: zod.z.enum(["inner", "full"]).optional().describe("How `columns` are joined: `inner` (default) or `full`."),
|
|
393
|
+
secondary: zod.z.array(tableColumnIdInput).max(64).optional().describe("Column ids from list_pool_columns added to the rows of `columns` where they have a value (labels, annotations, discovered columns); they add no rows of their own."),
|
|
394
|
+
filter: tableFilterInput.optional().describe(`Rows to keep, a FilterSpec tree: leaves \`{ type, column, … }\` — \`isNA\`, \`isNotNA\`; \`patternEquals\`, \`patternNotEquals\`, \`patternContainSubsequence\`, \`patternNotContainSubsequence\`, \`patternMatchesRegularExpression\`, \`patternFuzzyContainSubsequence\` with \`value\`; \`inSet\`, \`notInSet\` with \`value: […]\`; \`equal\`, \`notEqual\`, \`lessThan\`, \`greaterThan\`, \`lessThanOrEqual\`, \`greaterThanOrEqual\` with \`x\`; \`equalToColumn\`, \`lessThanColumn\`, \`greaterThanColumn\`, \`lessThanColumnOrEqual\`, \`greaterThanColumnOrEqual\` with \`rhs\` (another reference) and \`minDiff?\` — and nodes \`{ type: "and" | "or", filters: […] }\`, \`{ type: "not", filter }\`. ${REF_TEXT}`),
|
|
395
|
+
sort: tableSortInput.optional().describe(`Sort keys, first key first: a reference with \`ascending?\` (default true) and \`nullsFirst?\` (default false). ${REF_TEXT}`)
|
|
396
|
+
})
|
|
397
|
+
}, async ({ projectId, ...request }, call) => {
|
|
398
|
+
return await ctx.withProject(projectId, async (project, ml) => {
|
|
399
|
+
const overview = await project.overview.getValue();
|
|
400
|
+
const titles = /* @__PURE__ */ new Map();
|
|
401
|
+
for (const b of overview?.blocks ?? []) titles.set(b.id, b.title ?? b.id);
|
|
402
|
+
return await createTableResult(project, projectId, request, {
|
|
403
|
+
driver: ml.internalDriverKit.pFrameDriver,
|
|
404
|
+
tables: ctx.agentTables
|
|
405
|
+
}, call?.mcpReq.signal, (id) => titles.get(id) ?? id);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
server.registerTool("drop_table", {
|
|
409
|
+
title: "Drop Table",
|
|
410
|
+
annotations: require_types.hints.idempotent,
|
|
411
|
+
description: "Drop a table made by create_table, freeing what it holds: `{ dropped }`. `dropped: false` for a handle that is not an open table (dropped or expired already); that is not an error. Tables also go on their own after a while without a read.",
|
|
412
|
+
inputSchema: zod.z.object({ pTableHandle: require_ids.pTableHandleInput.describe("Table handle from create_table.") })
|
|
413
|
+
}, async ({ pTableHandle }) => require_types.textResult({ dropped: ctx.agentTables.drop(pTableHandle) }));
|
|
414
|
+
}
|
|
415
|
+
exports.AGENT_TABLE_IDLE_MS = AGENT_TABLE_IDLE_MS;
|
|
416
|
+
exports.CREATE_TABLE_ROWS_TIMEOUT_MS = CREATE_TABLE_ROWS_TIMEOUT_MS;
|
|
417
|
+
exports.TableRequestError = TableRequestError;
|
|
418
|
+
exports.createTableDef = createTableDef;
|
|
419
|
+
exports.createTableResult = createTableResult;
|
|
420
|
+
exports.registerAgentTableTools = registerAgentTableTools;
|
|
421
|
+
exports.tableFilterInput = tableFilterInput;
|
|
422
|
+
exports.tableSortInput = tableSortInput;
|
|
423
|
+
|
|
424
|
+
//# sourceMappingURL=agent-tables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tables.cjs","names":["z","columnIdInput","regexText","filterSpecToSpecQueryExpr","isBooleanExpression","readAnnotation","Annotation","errorResult","textResult","hints","projectIdInput","pTableHandleInput"],"sources":["../../src/tools/agent-tables.ts"],"sourcesContent":["import type { PoolColumn, PoolTable, PoolTableRefusal } from \"@milaboratories/pl-middle-layer\";\nimport {\n Annotation,\n isBooleanExpression,\n readAnnotation,\n type ColumnUniversalId,\n type FilterSpec,\n type FilterSpecLeaf,\n type PTableColumnSpec,\n type PTableDefV2,\n type PTableHandle,\n type PTableShape,\n type ProjectId,\n type SpecQuery,\n type SpecQueryExpression,\n} from \"@milaboratories/pl-model-common\";\nimport { filterSpecToSpecQueryExpr, type QueryColumnId } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport type { AgentTables, HeldTable } from \"../agent-tables\";\nimport { columnIdInput, projectIdInput, pTableHandleInput } from \"./ids\";\nimport { regexText } from \"./result-pool\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\n/** How long a table an agent built is kept after it was built or last read: three minutes. */\nexport const AGENT_TABLE_IDLE_MS = 180_000;\n/** How many tables agents built the server keeps open; the least recently used goes first. */\nexport const MAX_AGENT_TABLES = 16;\n/** The most columns, primary and secondary each, one `create_table` takes. */\nexport const MAX_TABLE_COLUMNS = 64;\n/** The most nodes (leaves and `and`/`or`/`not`) one filter has. */\nexport const MAX_FILTER_NODES = 200;\n/** The most sort keys one table has. */\nexport const MAX_SORT_KEYS = 16;\n/** How long `create_table` waits for the row count before it answers without it. */\nexport const CREATE_TABLE_ROWS_TIMEOUT_MS = 20_000;\n\n// The definition an agent gives\n\n/**\n * A column of the table by its pool id, or one of its axes by name (and domain or context domain,\n * when needed).\n */\nexport type TableColumnRef =\n | { column: ColumnUniversalId }\n | { axis: string; domain?: Record<string, string>; contextDomain?: Record<string, string> };\n\n/** A leaf of a table filter: the `FilterSpec` leaves a query expression can express. */\nexport type TableFilterLeaf = Exclude<\n FilterSpecLeaf<TableColumnRef>,\n { type: undefined | \"topN\" | \"bottomN\" | \"ifNa\" }\n>;\n\n/** A table filter: the `FilterSpec` tree of table filters, its column references by id or name. */\nexport type TableFilter = FilterSpec<TableFilterLeaf>;\n\n/** One sort key of a table. Default: ascending, missing values last. */\nexport type TableSortKey = TableColumnRef & { ascending?: boolean; nullsFirst?: boolean };\n\n/** What `create_table` builds a table from. */\nexport interface TableRequest {\n /** Pool column ids, joined by {@link join}. */\n columns: ColumnUniversalId[];\n /** Pool column ids joined onto the primary columns: every primary row stays. */\n secondary?: ColumnUniversalId[];\n join?: \"inner\" | \"full\";\n filter?: TableFilter;\n sort?: TableSortKey[];\n}\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 a reference at every leaf of the filter\n// (12 kB of arguments for create_table otherwise).\n\nconst domainInput = z.record(z.string(), z.string());\n\n/** A column id of `create_table`, as `columnIdInput` takes it. */\nconst tableColumnIdInput = columnIdInput.meta({ id: \"ColumnId\" });\n\nconst refInput: z.ZodType<TableColumnRef> = z\n .union([\n z.strictObject({ column: tableColumnIdInput }),\n z.strictObject({\n axis: z.string().min(1),\n domain: domainInput.optional(),\n contextDomain: domainInput.optional(),\n }),\n ])\n .meta({ id: \"TableColumnRef\" });\n\nconst leafInput = z.union([\n z.strictObject({ type: z.enum([\"isNA\", \"isNotNA\"]), column: refInput }),\n z.strictObject({\n type: z.enum([\n \"patternEquals\",\n \"patternNotEquals\",\n \"patternContainSubsequence\",\n \"patternNotContainSubsequence\",\n ]),\n column: refInput,\n value: z.string(),\n }),\n z.strictObject({\n type: z.literal(\"patternMatchesRegularExpression\"),\n column: refInput,\n value: regexText(\"A `patternMatchesRegularExpression` value\"),\n }),\n z.strictObject({\n type: z.literal(\"patternFuzzyContainSubsequence\"),\n column: refInput,\n value: z.string(),\n maxEdits: z.number().int().min(0).optional(),\n substitutionsOnly: z.boolean().optional(),\n wildcard: z.string().optional(),\n }),\n z.strictObject({\n type: z.enum([\"inSet\", \"notInSet\"]),\n column: refInput,\n value: z.array(z.string()),\n }),\n z.strictObject({\n type: z.enum([\n \"equal\",\n \"notEqual\",\n \"lessThan\",\n \"greaterThan\",\n \"lessThanOrEqual\",\n \"greaterThanOrEqual\",\n ]),\n column: refInput,\n x: z.number(),\n }),\n z.strictObject({ type: z.literal(\"equalToColumn\"), column: refInput, rhs: refInput }),\n z.strictObject({\n type: z.enum([\n \"lessThanColumn\",\n \"greaterThanColumn\",\n \"lessThanColumnOrEqual\",\n \"greaterThanColumnOrEqual\",\n ]),\n column: refInput,\n rhs: refInput,\n minDiff: z.number().optional(),\n }),\n]);\n\n/** A table filter as an agent writes it. */\nexport const tableFilterInput: z.ZodType<TableFilter> = z\n .lazy(() =>\n z.union([\n leafInput,\n z.strictObject({ type: z.literal(\"not\"), filter: tableFilterInput }),\n z.strictObject({ type: z.enum([\"and\", \"or\"]), filters: z.array(tableFilterInput).min(1) }),\n ]),\n )\n .meta({ id: \"TableFilter\" });\n\nconst sortKeyFields = {\n ascending: z.boolean().optional(),\n nullsFirst: z.boolean().optional(),\n};\n\n/** The sort keys of a table as an agent writes them. */\nexport const tableSortInput: z.ZodType<TableSortKey[]> = z\n .array(\n z.union([\n z.strictObject({ column: tableColumnIdInput, ...sortKeyFields }),\n z.strictObject({\n axis: z.string().min(1),\n domain: domainInput.optional(),\n contextDomain: domainInput.optional(),\n ...sortKeyFields,\n }),\n ]),\n )\n .max(MAX_SORT_KEYS);\n\n// From the request to the definition\n\n/** A request `create_table` cannot build a table from: what is wrong, and how to fix it. */\nexport class TableRequestError extends Error {\n constructor(\n message: string,\n readonly hint: string,\n ) {\n super(message);\n this.name = \"TableRequestError\";\n }\n}\n\n/** The definition of a table, as {@link createTableDef} makes it. */\nexport interface TableDef {\n def: PTableDefV2<ColumnUniversalId>;\n /** The pool columns the table reads, primary first. */\n columns: PoolColumn[];\n}\n\n/** The pool columns a table is built from, by id; `undefined` for an id that is no column of the pool. */\nexport type TableColumnLookup = (id: ColumnUniversalId) => PoolColumn | undefined;\n\n/**\n * The definition of the table `request` asks for over the pool columns `lookUp` finds, built the\n * way a block's `createPTableDefV3` builds one: the primary columns inner- or full-joined,\n * secondary columns outer-joined onto them, then the filter, then the sort. Each column is named\n * by its id, discovered, filtered and overridden ids included: the middle layer builds the query an\n * id stands for. A column reference names one of the table's columns by its id; an axis reference\n * is a selector (name, and domain or context domain when given) the engine matches against the\n * axes the join's rows are over, refusing one that matches no axis or several. Columns that share\n * no axis to join on are refused by the engine too.\n *\n * @throws {TableRequestError} for a column not in the pool or named twice, a reference to a column\n * not in the table, and a filter over the limits\n */\nexport function createTableDef(request: TableRequest, lookUp: TableColumnLookup): TableDef {\n const primary = lookUpAll(request.columns, lookUp);\n const secondary = lookUpAll(request.secondary ?? [], lookUp);\n const unknown = [...primary.unknown, ...secondary.unknown];\n if (unknown.length > 0)\n throw new TableRequestError(\n `No column ${unknown.join(\", \")} in the result pool of the project.`,\n \"list_pool_columns lists the columns and their ids; copy a `columnId` whole. Ids follow \" +\n \"current specs: list_pool_columns again.\",\n );\n if (primary.found.length === 0)\n throw new TableRequestError(\"`columns` is empty.\", \"Give at least one column id.\");\n const columns = [...primary.found, ...secondary.found];\n const ids = columns.map((c) => c.columnId);\n const twice = [...new Set(ids.filter((id, i) => ids.indexOf(id) !== i))];\n if (twice.length > 0)\n throw new TableRequestError(\n `Column ${twice.join(\", \")} is named twice.`,\n \"Name each column once, in `columns` or in `secondary`.\",\n );\n\n let query: SpecQuery = {\n type: (request.join ?? \"inner\") === \"inner\" ? \"innerJoin\" : \"fullJoin\",\n entries: primary.found.map((c) => ({ entry: { type: \"column\", column: c.columnId } })),\n };\n if (secondary.found.length > 0)\n query = {\n type: \"outerJoin\",\n primary: { entry: query },\n secondary: secondary.found.map((c) => ({ entry: { type: \"column\", column: c.columnId } })),\n };\n const ref = (r: TableColumnRef) => queryRef(r, ids);\n if (request.filter !== undefined) {\n const nodes = countNodes(request.filter);\n if (nodes > MAX_FILTER_NODES)\n throw new TableRequestError(\n `The filter has ${nodes} nodes; at most ${MAX_FILTER_NODES} are taken.`,\n \"Use `inSet` for a list of values, or a smaller filter.\",\n );\n const predicate = filterSpecToSpecQueryExpr(mapFilter(request.filter, ref));\n if (!isBooleanExpression(predicate))\n throw new TableRequestError(\n \"The filter does not give true or false for a row.\",\n \"Use comparisons, patterns, sets and `isNA`, combined with `and`, `or`, `not`.\",\n );\n query = { type: \"filter\", input: query, predicate };\n }\n if (request.sort !== undefined && request.sort.length > 0)\n query = {\n type: \"sort\",\n input: query,\n sortBy: request.sort.map((key) => ({\n expression: refExpression(ref(key)),\n ascending: key.ascending ?? true,\n nullsFirst: key.nullsFirst ?? false,\n })),\n };\n return { def: { query }, columns };\n}\n\nfunction lookUpAll(ids: readonly ColumnUniversalId[], lookUp: TableColumnLookup) {\n const found: PoolColumn[] = [];\n const unknown: ColumnUniversalId[] = [];\n for (const id of ids) {\n const column = lookUp(id);\n if (column === undefined) unknown.push(id);\n else found.push(column);\n }\n return { found, unknown };\n}\n\n/**\n * A reference of a filter or sort as a query names it: a column of the table (`ids`, canonical as\n * looked up; the reference's id is canonical as parsed), or an axis by its selector.\n */\nfunction queryRef(ref: TableColumnRef, ids: readonly ColumnUniversalId[]): QueryColumnId {\n if (\"axis\" in ref)\n return {\n type: \"axis\",\n id: {\n name: ref.axis,\n ...(ref.domain !== undefined ? { domain: ref.domain } : {}),\n ...(ref.contextDomain !== undefined ? { contextDomain: ref.contextDomain } : {}),\n },\n };\n if (!ids.includes(ref.column))\n throw new TableRequestError(\n `Column ${ref.column} is not in the table: a filter or a sort reads only the table's ` +\n \"columns.\",\n \"Add the column to `secondary` (or `columns`), and refer to it by the same id.\",\n );\n return { type: \"column\", id: ref.column };\n}\n\nfunction columnText(c: PoolColumn): string {\n const label = readAnnotation(c.spec, Annotation.Label);\n return `${label ?? c.spec.name} ${c.columnId}`;\n}\n\nconst JOIN_HINT =\n \"Columns join on their common axes: the same name, type and domain. list_pool_columns shows \" +\n \"each column's axes; pick columns over the same axis, or build a table per group.\";\n\nfunction countNodes(filter: TableFilter): number {\n switch (filter.type) {\n case \"not\":\n return 1 + countNodes(filter.filter);\n case \"and\":\n case \"or\":\n return 1 + filter.filters.reduce((n, f) => n + countNodes(f), 0);\n default:\n return 1;\n }\n}\n\n/** `filter` with its column references made query references by `ref`. */\nfunction mapFilter(\n filter: TableFilter,\n ref: (r: TableColumnRef) => QueryColumnId,\n): FilterSpec<FilterSpecLeaf<QueryColumnId>> {\n switch (filter.type) {\n case \"not\":\n return { type: \"not\", filter: mapFilter(filter.filter, ref) };\n case \"and\":\n case \"or\":\n return { type: filter.type, filters: filter.filters.map((f) => mapFilter(f, ref)) };\n default:\n return mapLeaf(filter, ref);\n }\n}\n\nfunction mapLeaf(\n leaf: TableFilterLeaf,\n ref: (r: TableColumnRef) => QueryColumnId,\n): FilterSpecLeaf<QueryColumnId> {\n if (\"rhs\" in leaf) return { ...leaf, column: ref(leaf.column), rhs: ref(leaf.rhs) };\n return { ...leaf, column: ref(leaf.column) };\n}\n\nfunction refExpression(ref: QueryColumnId): SpecQueryExpression {\n return ref.type === \"axis\"\n ? { type: \"axisRef\", value: ref.id }\n : { type: \"columnRef\", value: ref.id };\n}\n\n// The tools\n\n/** What `create_table` needs of a loaded project. */\nexport interface TableProject {\n getPoolColumnsById(ids: readonly ColumnUniversalId[]): {\n getValue(): Promise<(PoolColumn | undefined)[]>;\n };\n createPoolTable(def: PTableDefV2<ColumnUniversalId>): PoolTableComputable;\n}\n\n/** The computable `Project.createPoolTable` returns, as `create_table` uses it. */\nexport interface PoolTableComputable extends HeldTable {\n getValue(): Promise<PoolTable>;\n}\n\n/** What `create_table` uses of the PFrame driver. */\nexport interface TableDriver {\n getSpec(handle: PTableHandle): Promise<PTableColumnSpec[]>;\n getShape(handle: PTableHandle, signal?: AbortSignal): Promise<PTableShape>;\n}\n\n/** What {@link createTableResult} works with besides the project. */\nexport interface CreateTableDeps {\n /** The PFrame driver of the middle layer the project is of. */\n driver: TableDriver;\n tables: AgentTables;\n /** Default {@link CREATE_TABLE_ROWS_TIMEOUT_MS}. */\n rowsTimeoutMs?: number;\n}\n\n/** The title of a block, by id, for messages; the id when the project has no title for it. */\ntype BlockTitles = (blockId: string) => string;\n\n/** Builds the table `request` asks for over the project's pool columns (`create_table`). */\nexport async function createTableResult(\n project: TableProject,\n projectId: ProjectId,\n request: TableRequest,\n deps: CreateTableDeps,\n signal?: AbortSignal,\n blockTitle: BlockTitles = (id) => id,\n) {\n const found = new Map<ColumnUniversalId, PoolColumn>();\n try {\n // Each id is looked up by itself, so a column the listing leaves out for having the same spec\n // as another is found too.\n await lookUpInto(project, [...request.columns, ...(request.secondary ?? [])], found);\n } catch (err) {\n return errorResult(`Reading the result pool failed: ${errorMessage(err)}`);\n }\n let table: TableDef;\n try {\n table = createTableDef(request, (id) => found.get(id));\n } catch (err) {\n if (err instanceof TableRequestError) return errorResult(err.message, err.hint);\n throw err;\n }\n const built = await buildTable(project, table.def, table.columns, blockTitle);\n if (built.type === \"error\") return built.result;\n const { handle } = built;\n\n // A call that fails or is cancelled from here on leaves the table to its idle time.\n const evicted = deps.tables.add(projectId, handle, built.table);\n let spec: PTableColumnSpec[];\n try {\n spec = await deps.driver.getSpec(handle);\n } catch (err) {\n return errorResult(`Reading the columns of the new table failed: ${errorMessage(err)}`);\n }\n\n const timeout = AbortSignal.timeout(deps.rowsTimeoutMs ?? CREATE_TABLE_ROWS_TIMEOUT_MS);\n let rows: number | null = null;\n let rowsNote: string | undefined;\n try {\n rows = (\n await deps.driver.getShape(\n handle,\n signal === undefined ? timeout : AbortSignal.any([signal, timeout]),\n )\n ).rows;\n } catch (err) {\n if (signal?.aborted) return errorResult(\"Building the table was cancelled.\");\n rowsNote = timeout.aborted\n ? \"Counting the rows took too long; the table is built as you read it: query_table \" +\n \"reads it and gives `totalRows`.\"\n : `Counting the rows failed: ${errorMessage(err)}`;\n }\n\n return textResult({\n pTableHandle: handle,\n rows,\n ...(rowsNote !== undefined ? { note: rowsNote } : {}),\n expiresInSec: deps.tables.expiresInSec,\n ...(evicted.length > 0\n ? {\n evicted,\n evictedNote:\n `At most ${MAX_AGENT_TABLES} tables stay open: the least recently used, listed in ` +\n \"`evicted`, were dropped.\",\n }\n : {}),\n columns: spec.map((s, index) => ({\n index,\n type: s.type,\n name: s.spec.name,\n label: readAnnotation(s.spec, Annotation.Label),\n ...(s.type === \"column\" ? { columnId: s.id } : {}),\n })),\n });\n}\n\n/** What {@link buildTable} gives: the table and its handle, or the error to answer. */\ntype BuiltTable =\n | { type: \"ok\"; table: PoolTableComputable; handle: PTableHandle }\n | { type: \"error\"; result: ReturnType<typeof errorResult> };\n\n/**\n * Builds the table `def` defines; a table the engine or the middle layer refuses is given back,\n * and the error says why, naming `columns` with the titles of their blocks.\n */\nasync function buildTable(\n project: TableProject,\n def: PTableDefV2<ColumnUniversalId>,\n columns: readonly PoolColumn[],\n blockTitle: BlockTitles,\n): Promise<BuiltTable> {\n const table = project.createPoolTable(def);\n let built: PoolTable;\n try {\n built = await table.getValue();\n } catch (err) {\n table.resetState();\n return {\n type: \"error\",\n result: errorResult(\n `The table could not be built: ${errorMessage(err)}`,\n `Check the columns, and the axes the filter and sort name. ${JOIN_HINT}`,\n ),\n };\n }\n if (built.type === \"refused\") {\n table.resetState();\n return { type: \"error\", result: refusedResult(built.refused, columns, blockTitle) };\n }\n return { type: \"ok\", table, handle: built.handle };\n}\n\n/** Puts the pool columns `ids` stand for into `found`, by id; an unknown id is left out. */\nasync function lookUpInto(\n project: TableProject,\n ids: readonly ColumnUniversalId[],\n found: Map<ColumnUniversalId, PoolColumn>,\n): Promise<void> {\n const missing = [...new Set(ids)].filter((id) => !found.has(id));\n if (missing.length === 0) return;\n const columns = await project.getPoolColumnsById(missing).getValue();\n missing.forEach((id, i) => {\n const column = columns[i];\n if (column !== undefined) found.set(id, column);\n });\n}\n\n/** What `create_table` answers when the middle layer refused columns. */\nfunction refusedResult(\n refused: readonly PoolTableRefusal[],\n columns: readonly PoolColumn[],\n blockTitle: BlockTitles,\n) {\n const lines: string[] = [];\n const hints = new Set<string>();\n for (const r of refused) {\n const column = columns.find((c) => c.columnId === r.columnId);\n const block = column === undefined ? \"its block\" : `block ${blockTitle(column.producedBy)}`;\n const name = column === undefined ? r.columnId : columnText(column);\n switch (r.issue) {\n case \"unknown\":\n lines.push(`${name}: no longer in the result pool.`);\n hints.add(\"list_pool_columns lists the columns there are now.\");\n break;\n case \"noData\":\n lines.push(\n `${name}: has no data; ${block} has not run, or exports it from a pre-run only.`,\n );\n hints.add(\"Run the block (run_block), wait for it (await_block_done), then try again.\");\n break;\n case \"notReady\":\n lines.push(`${name}: still being calculated by ${block}.`);\n hints.add(\"Wait for the block (await_block_done), then try again.\");\n break;\n case \"failed\":\n lines.push(`${name}: its data failed: ${r.message ?? \"no message\"}.`);\n hints.add(\"get_block_logs and get_project_overview tell why the block failed.\");\n break;\n }\n }\n return errorResult(\n `No table was built: these columns cannot be read.\\n${lines.join(\"\\n\")}`,\n [...hints].join(\" \"),\n );\n}\n\nfunction errorMessage(err: unknown): string {\n // A computable wraps what its body threw, taking the thrown value's message; the engine throws\n // plain strings (a join it refuses, say), which have none: the string is the message then.\n if (err instanceof Error && typeof err.cause === \"string\") return err.cause;\n return err instanceof Error ? err.message : String(err);\n}\n\nconst REF_TEXT =\n 'A reference is `{ column: \"<columnId>\" }` (a column of the table, by the id given in ' +\n '`columns` or `secondary`) or `{ axis: \"<axis name>\", domain?: {…}, contextDomain?: {…} }`, ' +\n \"an axis the table's rows are over (a discovered column's rows are over the axes its linkers \" +\n \"lead to); domain or contextDomain only when axes share the name.\";\n\nexport function registerAgentTableTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"create_table\",\n {\n title: \"Create Table\",\n annotations: hints.additive,\n description:\n \"Build a temporary table from result-pool columns of a project (ids from \" +\n \"list_pool_columns), to answer a question over large results: join columns of several \" +\n \"blocks, filter and sort rows, then read it with query_table and throw it away. \" +\n \"Result: `{ pTableHandle, rows, note?, expiresInSec, evicted?, columns: [{ index, type, \" +\n \"name, label, columnId? }] }`; `rows` is null when counting took too long. `columns` \" +\n 'are joined on their common axes (same name, type and domain), `join: \"inner\"` ' +\n '(default: rows present in every column) or `\"full\"` (rows of any column); ' +\n \"`secondary` columns are added to every row the primary join gives, where they have a \" +\n \"value. Columns must be ready: a block still running or not run is refused, saying \" +\n \"which. The table is dropped after \" +\n `${AGENT_TABLE_IDLE_MS / 1000} s without a read, with drop_table, when the server ` +\n `lets go of the project, or when more than ${MAX_AGENT_TABLES} are open (the least ` +\n \"recently used goes). query_table says `stale: true` when its source columns changed. \" +\n \"A large table can slow the user's open tables while it builds.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n columns: z\n .array(tableColumnIdInput)\n .min(1)\n .max(MAX_TABLE_COLUMNS)\n .describe(\n \"Column ids from list_pool_columns (discovered ids included, put them in \" +\n \"`secondary` to keep their linker qualifications), or PlRef objects; joined by \" +\n \"`join`.\",\n ),\n join: z\n .enum([\"inner\", \"full\"])\n .optional()\n .describe(\"How `columns` are joined: `inner` (default) or `full`.\"),\n secondary: z\n .array(tableColumnIdInput)\n .max(MAX_TABLE_COLUMNS)\n .optional()\n .describe(\n \"Column ids from list_pool_columns added to the rows of `columns` where they have a \" +\n \"value (labels, annotations, discovered columns); they add no rows of their own.\",\n ),\n filter: tableFilterInput\n .optional()\n .describe(\n \"Rows to keep, a FilterSpec tree: leaves `{ type, column, … }` — `isNA`, \" +\n \"`isNotNA`; `patternEquals`, `patternNotEquals`, `patternContainSubsequence`, \" +\n \"`patternNotContainSubsequence`, `patternMatchesRegularExpression`, \" +\n \"`patternFuzzyContainSubsequence` with `value`; `inSet`, `notInSet` with `value: \" +\n \"[…]`; `equal`, `notEqual`, `lessThan`, `greaterThan`, `lessThanOrEqual`, \" +\n \"`greaterThanOrEqual` with `x`; `equalToColumn`, `lessThanColumn`, \" +\n \"`greaterThanColumn`, `lessThanColumnOrEqual`, `greaterThanColumnOrEqual` with \" +\n '`rhs` (another reference) and `minDiff?` — and nodes `{ type: \"and\" | \"or\", ' +\n `filters: […] }\\`, \\`{ type: \"not\", filter }\\`. ${REF_TEXT}`,\n ),\n sort: tableSortInput\n .optional()\n .describe(\n \"Sort keys, first key first: a reference with `ascending?` (default true) and \" +\n `\\`nullsFirst?\\` (default false). ${REF_TEXT}`,\n ),\n }),\n },\n async ({ projectId, ...request }, call) => {\n return await ctx.withProject(projectId, async (project, ml) => {\n const overview = await project.overview.getValue();\n const titles = new Map<string, string>();\n for (const b of overview?.blocks ?? []) titles.set(b.id, b.title ?? b.id);\n return await createTableResult(\n project,\n projectId,\n request,\n // The driver of the middle layer the project is of, not the one the server has now.\n { driver: ml.internalDriverKit.pFrameDriver, tables: ctx.agentTables },\n call?.mcpReq.signal,\n (id) => titles.get(id) ?? id,\n );\n });\n },\n );\n\n server.registerTool(\n \"drop_table\",\n {\n title: \"Drop Table\",\n // Idempotent, not destructive: it discards only a temporary table of the agent's own, which\n // create_table builds again from the same arguments; nothing of the project changes.\n annotations: hints.idempotent,\n description:\n \"Drop a table made by create_table, freeing what it holds: `{ dropped }`. `dropped: \" +\n \"false` for a handle that is not an open table (dropped or expired already); that is \" +\n \"not an error. Tables also go on their own after a while without a read.\",\n inputSchema: z.object({\n pTableHandle: pTableHandleInput.describe(\"Table handle from create_table.\"),\n }),\n },\n async ({ pTableHandle }) => textResult({ dropped: ctx.agentTables.drop(pTableHandle) }),\n );\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,sBAAsB;;AAUnC,MAAa,+BAA+B;AAuC5C,MAAM,cAAcA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,OAAO,CAAC;;AAGnD,MAAM,qBAAqBC,YAAAA,cAAc,KAAK,EAAE,IAAI,WAAW,CAAC;AAEhE,MAAM,WAAsCD,IAAAA,EACzC,MAAM,CACLA,IAAAA,EAAE,aAAa,EAAE,QAAQ,mBAAmB,CAA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