@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
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
import type { PoolColumn, PoolTable, PoolTableRefusal } from "@milaboratories/pl-middle-layer";
|
|
2
|
+
import {
|
|
3
|
+
Annotation,
|
|
4
|
+
isBooleanExpression,
|
|
5
|
+
readAnnotation,
|
|
6
|
+
type ColumnUniversalId,
|
|
7
|
+
type FilterSpec,
|
|
8
|
+
type FilterSpecLeaf,
|
|
9
|
+
type PTableColumnSpec,
|
|
10
|
+
type PTableDefV2,
|
|
11
|
+
type PTableHandle,
|
|
12
|
+
type PTableShape,
|
|
13
|
+
type ProjectId,
|
|
14
|
+
type SpecQuery,
|
|
15
|
+
type SpecQueryExpression,
|
|
16
|
+
} from "@milaboratories/pl-model-common";
|
|
17
|
+
import { filterSpecToSpecQueryExpr, type QueryColumnId } from "@platforma-sdk/model";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import type { AgentTables, HeldTable } from "../agent-tables";
|
|
20
|
+
import { columnIdInput, projectIdInput, pTableHandleInput } from "./ids";
|
|
21
|
+
import { regexText } from "./result-pool";
|
|
22
|
+
import type { ToolContext, ToolRegistrar } from "./types";
|
|
23
|
+
import { errorResult, hints, textResult } from "./types";
|
|
24
|
+
|
|
25
|
+
/** How long a table an agent built is kept after it was built or last read: three minutes. */
|
|
26
|
+
export const AGENT_TABLE_IDLE_MS = 180_000;
|
|
27
|
+
/** How many tables agents built the server keeps open; the least recently used goes first. */
|
|
28
|
+
export const MAX_AGENT_TABLES = 16;
|
|
29
|
+
/** The most columns, primary and secondary each, one `create_table` takes. */
|
|
30
|
+
export const MAX_TABLE_COLUMNS = 64;
|
|
31
|
+
/** The most nodes (leaves and `and`/`or`/`not`) one filter has. */
|
|
32
|
+
export const MAX_FILTER_NODES = 200;
|
|
33
|
+
/** The most sort keys one table has. */
|
|
34
|
+
export const MAX_SORT_KEYS = 16;
|
|
35
|
+
/** How long `create_table` waits for the row count before it answers without it. */
|
|
36
|
+
export const CREATE_TABLE_ROWS_TIMEOUT_MS = 20_000;
|
|
37
|
+
|
|
38
|
+
// The definition an agent gives
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A column of the table by its pool id, or one of its axes by name (and domain or context domain,
|
|
42
|
+
* when needed).
|
|
43
|
+
*/
|
|
44
|
+
export type TableColumnRef =
|
|
45
|
+
| { column: ColumnUniversalId }
|
|
46
|
+
| { axis: string; domain?: Record<string, string>; contextDomain?: Record<string, string> };
|
|
47
|
+
|
|
48
|
+
/** A leaf of a table filter: the `FilterSpec` leaves a query expression can express. */
|
|
49
|
+
export type TableFilterLeaf = Exclude<
|
|
50
|
+
FilterSpecLeaf<TableColumnRef>,
|
|
51
|
+
{ type: undefined | "topN" | "bottomN" | "ifNa" }
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
/** A table filter: the `FilterSpec` tree of table filters, its column references by id or name. */
|
|
55
|
+
export type TableFilter = FilterSpec<TableFilterLeaf>;
|
|
56
|
+
|
|
57
|
+
/** One sort key of a table. Default: ascending, missing values last. */
|
|
58
|
+
export type TableSortKey = TableColumnRef & { ascending?: boolean; nullsFirst?: boolean };
|
|
59
|
+
|
|
60
|
+
/** What `create_table` builds a table from. */
|
|
61
|
+
export interface TableRequest {
|
|
62
|
+
/** Pool column ids, joined by {@link join}. */
|
|
63
|
+
columns: ColumnUniversalId[];
|
|
64
|
+
/** Pool column ids joined onto the primary columns: every primary row stays. */
|
|
65
|
+
secondary?: ColumnUniversalId[];
|
|
66
|
+
join?: "inner" | "full";
|
|
67
|
+
filter?: TableFilter;
|
|
68
|
+
sort?: TableSortKey[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The schemas used more than once carry an `id`: the JSON Schema a client is sent then defines each
|
|
72
|
+
// once under `$defs` and refers to it, instead of repeating a reference at every leaf of the filter
|
|
73
|
+
// (12 kB of arguments for create_table otherwise).
|
|
74
|
+
|
|
75
|
+
const domainInput = z.record(z.string(), z.string());
|
|
76
|
+
|
|
77
|
+
/** A column id of `create_table`, as `columnIdInput` takes it. */
|
|
78
|
+
const tableColumnIdInput = columnIdInput.meta({ id: "ColumnId" });
|
|
79
|
+
|
|
80
|
+
const refInput: z.ZodType<TableColumnRef> = z
|
|
81
|
+
.union([
|
|
82
|
+
z.strictObject({ column: tableColumnIdInput }),
|
|
83
|
+
z.strictObject({
|
|
84
|
+
axis: z.string().min(1),
|
|
85
|
+
domain: domainInput.optional(),
|
|
86
|
+
contextDomain: domainInput.optional(),
|
|
87
|
+
}),
|
|
88
|
+
])
|
|
89
|
+
.meta({ id: "TableColumnRef" });
|
|
90
|
+
|
|
91
|
+
const leafInput = z.union([
|
|
92
|
+
z.strictObject({ type: z.enum(["isNA", "isNotNA"]), column: refInput }),
|
|
93
|
+
z.strictObject({
|
|
94
|
+
type: z.enum([
|
|
95
|
+
"patternEquals",
|
|
96
|
+
"patternNotEquals",
|
|
97
|
+
"patternContainSubsequence",
|
|
98
|
+
"patternNotContainSubsequence",
|
|
99
|
+
]),
|
|
100
|
+
column: refInput,
|
|
101
|
+
value: z.string(),
|
|
102
|
+
}),
|
|
103
|
+
z.strictObject({
|
|
104
|
+
type: z.literal("patternMatchesRegularExpression"),
|
|
105
|
+
column: refInput,
|
|
106
|
+
value: regexText("A `patternMatchesRegularExpression` value"),
|
|
107
|
+
}),
|
|
108
|
+
z.strictObject({
|
|
109
|
+
type: z.literal("patternFuzzyContainSubsequence"),
|
|
110
|
+
column: refInput,
|
|
111
|
+
value: z.string(),
|
|
112
|
+
maxEdits: z.number().int().min(0).optional(),
|
|
113
|
+
substitutionsOnly: z.boolean().optional(),
|
|
114
|
+
wildcard: z.string().optional(),
|
|
115
|
+
}),
|
|
116
|
+
z.strictObject({
|
|
117
|
+
type: z.enum(["inSet", "notInSet"]),
|
|
118
|
+
column: refInput,
|
|
119
|
+
value: z.array(z.string()),
|
|
120
|
+
}),
|
|
121
|
+
z.strictObject({
|
|
122
|
+
type: z.enum([
|
|
123
|
+
"equal",
|
|
124
|
+
"notEqual",
|
|
125
|
+
"lessThan",
|
|
126
|
+
"greaterThan",
|
|
127
|
+
"lessThanOrEqual",
|
|
128
|
+
"greaterThanOrEqual",
|
|
129
|
+
]),
|
|
130
|
+
column: refInput,
|
|
131
|
+
x: z.number(),
|
|
132
|
+
}),
|
|
133
|
+
z.strictObject({ type: z.literal("equalToColumn"), column: refInput, rhs: refInput }),
|
|
134
|
+
z.strictObject({
|
|
135
|
+
type: z.enum([
|
|
136
|
+
"lessThanColumn",
|
|
137
|
+
"greaterThanColumn",
|
|
138
|
+
"lessThanColumnOrEqual",
|
|
139
|
+
"greaterThanColumnOrEqual",
|
|
140
|
+
]),
|
|
141
|
+
column: refInput,
|
|
142
|
+
rhs: refInput,
|
|
143
|
+
minDiff: z.number().optional(),
|
|
144
|
+
}),
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
/** A table filter as an agent writes it. */
|
|
148
|
+
export const tableFilterInput: z.ZodType<TableFilter> = z
|
|
149
|
+
.lazy(() =>
|
|
150
|
+
z.union([
|
|
151
|
+
leafInput,
|
|
152
|
+
z.strictObject({ type: z.literal("not"), filter: tableFilterInput }),
|
|
153
|
+
z.strictObject({ type: z.enum(["and", "or"]), filters: z.array(tableFilterInput).min(1) }),
|
|
154
|
+
]),
|
|
155
|
+
)
|
|
156
|
+
.meta({ id: "TableFilter" });
|
|
157
|
+
|
|
158
|
+
const sortKeyFields = {
|
|
159
|
+
ascending: z.boolean().optional(),
|
|
160
|
+
nullsFirst: z.boolean().optional(),
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** The sort keys of a table as an agent writes them. */
|
|
164
|
+
export const tableSortInput: z.ZodType<TableSortKey[]> = z
|
|
165
|
+
.array(
|
|
166
|
+
z.union([
|
|
167
|
+
z.strictObject({ column: tableColumnIdInput, ...sortKeyFields }),
|
|
168
|
+
z.strictObject({
|
|
169
|
+
axis: z.string().min(1),
|
|
170
|
+
domain: domainInput.optional(),
|
|
171
|
+
contextDomain: domainInput.optional(),
|
|
172
|
+
...sortKeyFields,
|
|
173
|
+
}),
|
|
174
|
+
]),
|
|
175
|
+
)
|
|
176
|
+
.max(MAX_SORT_KEYS);
|
|
177
|
+
|
|
178
|
+
// From the request to the definition
|
|
179
|
+
|
|
180
|
+
/** A request `create_table` cannot build a table from: what is wrong, and how to fix it. */
|
|
181
|
+
export class TableRequestError extends Error {
|
|
182
|
+
constructor(
|
|
183
|
+
message: string,
|
|
184
|
+
readonly hint: string,
|
|
185
|
+
) {
|
|
186
|
+
super(message);
|
|
187
|
+
this.name = "TableRequestError";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The definition of a table, as {@link createTableDef} makes it. */
|
|
192
|
+
export interface TableDef {
|
|
193
|
+
def: PTableDefV2<ColumnUniversalId>;
|
|
194
|
+
/** The pool columns the table reads, primary first. */
|
|
195
|
+
columns: PoolColumn[];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The pool columns a table is built from, by id; `undefined` for an id that is no column of the pool. */
|
|
199
|
+
export type TableColumnLookup = (id: ColumnUniversalId) => PoolColumn | undefined;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The definition of the table `request` asks for over the pool columns `lookUp` finds, built the
|
|
203
|
+
* way a block's `createPTableDefV3` builds one: the primary columns inner- or full-joined,
|
|
204
|
+
* secondary columns outer-joined onto them, then the filter, then the sort. Each column is named
|
|
205
|
+
* by its id, discovered, filtered and overridden ids included: the middle layer builds the query an
|
|
206
|
+
* id stands for. A column reference names one of the table's columns by its id; an axis reference
|
|
207
|
+
* is a selector (name, and domain or context domain when given) the engine matches against the
|
|
208
|
+
* axes the join's rows are over, refusing one that matches no axis or several. Columns that share
|
|
209
|
+
* no axis to join on are refused by the engine too.
|
|
210
|
+
*
|
|
211
|
+
* @throws {TableRequestError} for a column not in the pool or named twice, a reference to a column
|
|
212
|
+
* not in the table, and a filter over the limits
|
|
213
|
+
*/
|
|
214
|
+
export function createTableDef(request: TableRequest, lookUp: TableColumnLookup): TableDef {
|
|
215
|
+
const primary = lookUpAll(request.columns, lookUp);
|
|
216
|
+
const secondary = lookUpAll(request.secondary ?? [], lookUp);
|
|
217
|
+
const unknown = [...primary.unknown, ...secondary.unknown];
|
|
218
|
+
if (unknown.length > 0)
|
|
219
|
+
throw new TableRequestError(
|
|
220
|
+
`No column ${unknown.join(", ")} in the result pool of the project.`,
|
|
221
|
+
"list_pool_columns lists the columns and their ids; copy a `columnId` whole. Ids follow " +
|
|
222
|
+
"current specs: list_pool_columns again.",
|
|
223
|
+
);
|
|
224
|
+
if (primary.found.length === 0)
|
|
225
|
+
throw new TableRequestError("`columns` is empty.", "Give at least one column id.");
|
|
226
|
+
const columns = [...primary.found, ...secondary.found];
|
|
227
|
+
const ids = columns.map((c) => c.columnId);
|
|
228
|
+
const twice = [...new Set(ids.filter((id, i) => ids.indexOf(id) !== i))];
|
|
229
|
+
if (twice.length > 0)
|
|
230
|
+
throw new TableRequestError(
|
|
231
|
+
`Column ${twice.join(", ")} is named twice.`,
|
|
232
|
+
"Name each column once, in `columns` or in `secondary`.",
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
let query: SpecQuery = {
|
|
236
|
+
type: (request.join ?? "inner") === "inner" ? "innerJoin" : "fullJoin",
|
|
237
|
+
entries: primary.found.map((c) => ({ entry: { type: "column", column: c.columnId } })),
|
|
238
|
+
};
|
|
239
|
+
if (secondary.found.length > 0)
|
|
240
|
+
query = {
|
|
241
|
+
type: "outerJoin",
|
|
242
|
+
primary: { entry: query },
|
|
243
|
+
secondary: secondary.found.map((c) => ({ entry: { type: "column", column: c.columnId } })),
|
|
244
|
+
};
|
|
245
|
+
const ref = (r: TableColumnRef) => queryRef(r, ids);
|
|
246
|
+
if (request.filter !== undefined) {
|
|
247
|
+
const nodes = countNodes(request.filter);
|
|
248
|
+
if (nodes > MAX_FILTER_NODES)
|
|
249
|
+
throw new TableRequestError(
|
|
250
|
+
`The filter has ${nodes} nodes; at most ${MAX_FILTER_NODES} are taken.`,
|
|
251
|
+
"Use `inSet` for a list of values, or a smaller filter.",
|
|
252
|
+
);
|
|
253
|
+
const predicate = filterSpecToSpecQueryExpr(mapFilter(request.filter, ref));
|
|
254
|
+
if (!isBooleanExpression(predicate))
|
|
255
|
+
throw new TableRequestError(
|
|
256
|
+
"The filter does not give true or false for a row.",
|
|
257
|
+
"Use comparisons, patterns, sets and `isNA`, combined with `and`, `or`, `not`.",
|
|
258
|
+
);
|
|
259
|
+
query = { type: "filter", input: query, predicate };
|
|
260
|
+
}
|
|
261
|
+
if (request.sort !== undefined && request.sort.length > 0)
|
|
262
|
+
query = {
|
|
263
|
+
type: "sort",
|
|
264
|
+
input: query,
|
|
265
|
+
sortBy: request.sort.map((key) => ({
|
|
266
|
+
expression: refExpression(ref(key)),
|
|
267
|
+
ascending: key.ascending ?? true,
|
|
268
|
+
nullsFirst: key.nullsFirst ?? false,
|
|
269
|
+
})),
|
|
270
|
+
};
|
|
271
|
+
return { def: { query }, columns };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function lookUpAll(ids: readonly ColumnUniversalId[], lookUp: TableColumnLookup) {
|
|
275
|
+
const found: PoolColumn[] = [];
|
|
276
|
+
const unknown: ColumnUniversalId[] = [];
|
|
277
|
+
for (const id of ids) {
|
|
278
|
+
const column = lookUp(id);
|
|
279
|
+
if (column === undefined) unknown.push(id);
|
|
280
|
+
else found.push(column);
|
|
281
|
+
}
|
|
282
|
+
return { found, unknown };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* A reference of a filter or sort as a query names it: a column of the table (`ids`, canonical as
|
|
287
|
+
* looked up; the reference's id is canonical as parsed), or an axis by its selector.
|
|
288
|
+
*/
|
|
289
|
+
function queryRef(ref: TableColumnRef, ids: readonly ColumnUniversalId[]): QueryColumnId {
|
|
290
|
+
if ("axis" in ref)
|
|
291
|
+
return {
|
|
292
|
+
type: "axis",
|
|
293
|
+
id: {
|
|
294
|
+
name: ref.axis,
|
|
295
|
+
...(ref.domain !== undefined ? { domain: ref.domain } : {}),
|
|
296
|
+
...(ref.contextDomain !== undefined ? { contextDomain: ref.contextDomain } : {}),
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
if (!ids.includes(ref.column))
|
|
300
|
+
throw new TableRequestError(
|
|
301
|
+
`Column ${ref.column} is not in the table: a filter or a sort reads only the table's ` +
|
|
302
|
+
"columns.",
|
|
303
|
+
"Add the column to `secondary` (or `columns`), and refer to it by the same id.",
|
|
304
|
+
);
|
|
305
|
+
return { type: "column", id: ref.column };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function columnText(c: PoolColumn): string {
|
|
309
|
+
const label = readAnnotation(c.spec, Annotation.Label);
|
|
310
|
+
return `${label ?? c.spec.name} ${c.columnId}`;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const JOIN_HINT =
|
|
314
|
+
"Columns join on their common axes: the same name, type and domain. list_pool_columns shows " +
|
|
315
|
+
"each column's axes; pick columns over the same axis, or build a table per group.";
|
|
316
|
+
|
|
317
|
+
function countNodes(filter: TableFilter): number {
|
|
318
|
+
switch (filter.type) {
|
|
319
|
+
case "not":
|
|
320
|
+
return 1 + countNodes(filter.filter);
|
|
321
|
+
case "and":
|
|
322
|
+
case "or":
|
|
323
|
+
return 1 + filter.filters.reduce((n, f) => n + countNodes(f), 0);
|
|
324
|
+
default:
|
|
325
|
+
return 1;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** `filter` with its column references made query references by `ref`. */
|
|
330
|
+
function mapFilter(
|
|
331
|
+
filter: TableFilter,
|
|
332
|
+
ref: (r: TableColumnRef) => QueryColumnId,
|
|
333
|
+
): FilterSpec<FilterSpecLeaf<QueryColumnId>> {
|
|
334
|
+
switch (filter.type) {
|
|
335
|
+
case "not":
|
|
336
|
+
return { type: "not", filter: mapFilter(filter.filter, ref) };
|
|
337
|
+
case "and":
|
|
338
|
+
case "or":
|
|
339
|
+
return { type: filter.type, filters: filter.filters.map((f) => mapFilter(f, ref)) };
|
|
340
|
+
default:
|
|
341
|
+
return mapLeaf(filter, ref);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function mapLeaf(
|
|
346
|
+
leaf: TableFilterLeaf,
|
|
347
|
+
ref: (r: TableColumnRef) => QueryColumnId,
|
|
348
|
+
): FilterSpecLeaf<QueryColumnId> {
|
|
349
|
+
if ("rhs" in leaf) return { ...leaf, column: ref(leaf.column), rhs: ref(leaf.rhs) };
|
|
350
|
+
return { ...leaf, column: ref(leaf.column) };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function refExpression(ref: QueryColumnId): SpecQueryExpression {
|
|
354
|
+
return ref.type === "axis"
|
|
355
|
+
? { type: "axisRef", value: ref.id }
|
|
356
|
+
: { type: "columnRef", value: ref.id };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// The tools
|
|
360
|
+
|
|
361
|
+
/** What `create_table` needs of a loaded project. */
|
|
362
|
+
export interface TableProject {
|
|
363
|
+
getPoolColumnsById(ids: readonly ColumnUniversalId[]): {
|
|
364
|
+
getValue(): Promise<(PoolColumn | undefined)[]>;
|
|
365
|
+
};
|
|
366
|
+
createPoolTable(def: PTableDefV2<ColumnUniversalId>): PoolTableComputable;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** The computable `Project.createPoolTable` returns, as `create_table` uses it. */
|
|
370
|
+
export interface PoolTableComputable extends HeldTable {
|
|
371
|
+
getValue(): Promise<PoolTable>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** What `create_table` uses of the PFrame driver. */
|
|
375
|
+
export interface TableDriver {
|
|
376
|
+
getSpec(handle: PTableHandle): Promise<PTableColumnSpec[]>;
|
|
377
|
+
getShape(handle: PTableHandle, signal?: AbortSignal): Promise<PTableShape>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** What {@link createTableResult} works with besides the project. */
|
|
381
|
+
export interface CreateTableDeps {
|
|
382
|
+
/** The PFrame driver of the middle layer the project is of. */
|
|
383
|
+
driver: TableDriver;
|
|
384
|
+
tables: AgentTables;
|
|
385
|
+
/** Default {@link CREATE_TABLE_ROWS_TIMEOUT_MS}. */
|
|
386
|
+
rowsTimeoutMs?: number;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** The title of a block, by id, for messages; the id when the project has no title for it. */
|
|
390
|
+
type BlockTitles = (blockId: string) => string;
|
|
391
|
+
|
|
392
|
+
/** Builds the table `request` asks for over the project's pool columns (`create_table`). */
|
|
393
|
+
export async function createTableResult(
|
|
394
|
+
project: TableProject,
|
|
395
|
+
projectId: ProjectId,
|
|
396
|
+
request: TableRequest,
|
|
397
|
+
deps: CreateTableDeps,
|
|
398
|
+
signal?: AbortSignal,
|
|
399
|
+
blockTitle: BlockTitles = (id) => id,
|
|
400
|
+
) {
|
|
401
|
+
const found = new Map<ColumnUniversalId, PoolColumn>();
|
|
402
|
+
try {
|
|
403
|
+
// Each id is looked up by itself, so a column the listing leaves out for having the same spec
|
|
404
|
+
// as another is found too.
|
|
405
|
+
await lookUpInto(project, [...request.columns, ...(request.secondary ?? [])], found);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
return errorResult(`Reading the result pool failed: ${errorMessage(err)}`);
|
|
408
|
+
}
|
|
409
|
+
let table: TableDef;
|
|
410
|
+
try {
|
|
411
|
+
table = createTableDef(request, (id) => found.get(id));
|
|
412
|
+
} catch (err) {
|
|
413
|
+
if (err instanceof TableRequestError) return errorResult(err.message, err.hint);
|
|
414
|
+
throw err;
|
|
415
|
+
}
|
|
416
|
+
const built = await buildTable(project, table.def, table.columns, blockTitle);
|
|
417
|
+
if (built.type === "error") return built.result;
|
|
418
|
+
const { handle } = built;
|
|
419
|
+
|
|
420
|
+
// A call that fails or is cancelled from here on leaves the table to its idle time.
|
|
421
|
+
const evicted = deps.tables.add(projectId, handle, built.table);
|
|
422
|
+
let spec: PTableColumnSpec[];
|
|
423
|
+
try {
|
|
424
|
+
spec = await deps.driver.getSpec(handle);
|
|
425
|
+
} catch (err) {
|
|
426
|
+
return errorResult(`Reading the columns of the new table failed: ${errorMessage(err)}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const timeout = AbortSignal.timeout(deps.rowsTimeoutMs ?? CREATE_TABLE_ROWS_TIMEOUT_MS);
|
|
430
|
+
let rows: number | null = null;
|
|
431
|
+
let rowsNote: string | undefined;
|
|
432
|
+
try {
|
|
433
|
+
rows = (
|
|
434
|
+
await deps.driver.getShape(
|
|
435
|
+
handle,
|
|
436
|
+
signal === undefined ? timeout : AbortSignal.any([signal, timeout]),
|
|
437
|
+
)
|
|
438
|
+
).rows;
|
|
439
|
+
} catch (err) {
|
|
440
|
+
if (signal?.aborted) return errorResult("Building the table was cancelled.");
|
|
441
|
+
rowsNote = timeout.aborted
|
|
442
|
+
? "Counting the rows took too long; the table is built as you read it: query_table " +
|
|
443
|
+
"reads it and gives `totalRows`."
|
|
444
|
+
: `Counting the rows failed: ${errorMessage(err)}`;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return textResult({
|
|
448
|
+
pTableHandle: handle,
|
|
449
|
+
rows,
|
|
450
|
+
...(rowsNote !== undefined ? { note: rowsNote } : {}),
|
|
451
|
+
expiresInSec: deps.tables.expiresInSec,
|
|
452
|
+
...(evicted.length > 0
|
|
453
|
+
? {
|
|
454
|
+
evicted,
|
|
455
|
+
evictedNote:
|
|
456
|
+
`At most ${MAX_AGENT_TABLES} tables stay open: the least recently used, listed in ` +
|
|
457
|
+
"`evicted`, were dropped.",
|
|
458
|
+
}
|
|
459
|
+
: {}),
|
|
460
|
+
columns: spec.map((s, index) => ({
|
|
461
|
+
index,
|
|
462
|
+
type: s.type,
|
|
463
|
+
name: s.spec.name,
|
|
464
|
+
label: readAnnotation(s.spec, Annotation.Label),
|
|
465
|
+
...(s.type === "column" ? { columnId: s.id } : {}),
|
|
466
|
+
})),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** What {@link buildTable} gives: the table and its handle, or the error to answer. */
|
|
471
|
+
type BuiltTable =
|
|
472
|
+
| { type: "ok"; table: PoolTableComputable; handle: PTableHandle }
|
|
473
|
+
| { type: "error"; result: ReturnType<typeof errorResult> };
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Builds the table `def` defines; a table the engine or the middle layer refuses is given back,
|
|
477
|
+
* and the error says why, naming `columns` with the titles of their blocks.
|
|
478
|
+
*/
|
|
479
|
+
async function buildTable(
|
|
480
|
+
project: TableProject,
|
|
481
|
+
def: PTableDefV2<ColumnUniversalId>,
|
|
482
|
+
columns: readonly PoolColumn[],
|
|
483
|
+
blockTitle: BlockTitles,
|
|
484
|
+
): Promise<BuiltTable> {
|
|
485
|
+
const table = project.createPoolTable(def);
|
|
486
|
+
let built: PoolTable;
|
|
487
|
+
try {
|
|
488
|
+
built = await table.getValue();
|
|
489
|
+
} catch (err) {
|
|
490
|
+
table.resetState();
|
|
491
|
+
return {
|
|
492
|
+
type: "error",
|
|
493
|
+
result: errorResult(
|
|
494
|
+
`The table could not be built: ${errorMessage(err)}`,
|
|
495
|
+
`Check the columns, and the axes the filter and sort name. ${JOIN_HINT}`,
|
|
496
|
+
),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
if (built.type === "refused") {
|
|
500
|
+
table.resetState();
|
|
501
|
+
return { type: "error", result: refusedResult(built.refused, columns, blockTitle) };
|
|
502
|
+
}
|
|
503
|
+
return { type: "ok", table, handle: built.handle };
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** Puts the pool columns `ids` stand for into `found`, by id; an unknown id is left out. */
|
|
507
|
+
async function lookUpInto(
|
|
508
|
+
project: TableProject,
|
|
509
|
+
ids: readonly ColumnUniversalId[],
|
|
510
|
+
found: Map<ColumnUniversalId, PoolColumn>,
|
|
511
|
+
): Promise<void> {
|
|
512
|
+
const missing = [...new Set(ids)].filter((id) => !found.has(id));
|
|
513
|
+
if (missing.length === 0) return;
|
|
514
|
+
const columns = await project.getPoolColumnsById(missing).getValue();
|
|
515
|
+
missing.forEach((id, i) => {
|
|
516
|
+
const column = columns[i];
|
|
517
|
+
if (column !== undefined) found.set(id, column);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** What `create_table` answers when the middle layer refused columns. */
|
|
522
|
+
function refusedResult(
|
|
523
|
+
refused: readonly PoolTableRefusal[],
|
|
524
|
+
columns: readonly PoolColumn[],
|
|
525
|
+
blockTitle: BlockTitles,
|
|
526
|
+
) {
|
|
527
|
+
const lines: string[] = [];
|
|
528
|
+
const hints = new Set<string>();
|
|
529
|
+
for (const r of refused) {
|
|
530
|
+
const column = columns.find((c) => c.columnId === r.columnId);
|
|
531
|
+
const block = column === undefined ? "its block" : `block ${blockTitle(column.producedBy)}`;
|
|
532
|
+
const name = column === undefined ? r.columnId : columnText(column);
|
|
533
|
+
switch (r.issue) {
|
|
534
|
+
case "unknown":
|
|
535
|
+
lines.push(`${name}: no longer in the result pool.`);
|
|
536
|
+
hints.add("list_pool_columns lists the columns there are now.");
|
|
537
|
+
break;
|
|
538
|
+
case "noData":
|
|
539
|
+
lines.push(
|
|
540
|
+
`${name}: has no data; ${block} has not run, or exports it from a pre-run only.`,
|
|
541
|
+
);
|
|
542
|
+
hints.add("Run the block (run_block), wait for it (await_block_done), then try again.");
|
|
543
|
+
break;
|
|
544
|
+
case "notReady":
|
|
545
|
+
lines.push(`${name}: still being calculated by ${block}.`);
|
|
546
|
+
hints.add("Wait for the block (await_block_done), then try again.");
|
|
547
|
+
break;
|
|
548
|
+
case "failed":
|
|
549
|
+
lines.push(`${name}: its data failed: ${r.message ?? "no message"}.`);
|
|
550
|
+
hints.add("get_block_logs and get_project_overview tell why the block failed.");
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return errorResult(
|
|
555
|
+
`No table was built: these columns cannot be read.\n${lines.join("\n")}`,
|
|
556
|
+
[...hints].join(" "),
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function errorMessage(err: unknown): string {
|
|
561
|
+
// A computable wraps what its body threw, taking the thrown value's message; the engine throws
|
|
562
|
+
// plain strings (a join it refuses, say), which have none: the string is the message then.
|
|
563
|
+
if (err instanceof Error && typeof err.cause === "string") return err.cause;
|
|
564
|
+
return err instanceof Error ? err.message : String(err);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const REF_TEXT =
|
|
568
|
+
'A reference is `{ column: "<columnId>" }` (a column of the table, by the id given in ' +
|
|
569
|
+
'`columns` or `secondary`) or `{ axis: "<axis name>", domain?: {…}, contextDomain?: {…} }`, ' +
|
|
570
|
+
"an axis the table's rows are over (a discovered column's rows are over the axes its linkers " +
|
|
571
|
+
"lead to); domain or contextDomain only when axes share the name.";
|
|
572
|
+
|
|
573
|
+
export function registerAgentTableTools(server: ToolRegistrar, ctx: ToolContext): void {
|
|
574
|
+
server.registerTool(
|
|
575
|
+
"create_table",
|
|
576
|
+
{
|
|
577
|
+
title: "Create Table",
|
|
578
|
+
annotations: hints.additive,
|
|
579
|
+
description:
|
|
580
|
+
"Build a temporary table from result-pool columns of a project (ids from " +
|
|
581
|
+
"list_pool_columns), to answer a question over large results: join columns of several " +
|
|
582
|
+
"blocks, filter and sort rows, then read it with query_table and throw it away. " +
|
|
583
|
+
"Result: `{ pTableHandle, rows, note?, expiresInSec, evicted?, columns: [{ index, type, " +
|
|
584
|
+
"name, label, columnId? }] }`; `rows` is null when counting took too long. `columns` " +
|
|
585
|
+
'are joined on their common axes (same name, type and domain), `join: "inner"` ' +
|
|
586
|
+
'(default: rows present in every column) or `"full"` (rows of any column); ' +
|
|
587
|
+
"`secondary` columns are added to every row the primary join gives, where they have a " +
|
|
588
|
+
"value. Columns must be ready: a block still running or not run is refused, saying " +
|
|
589
|
+
"which. The table is dropped after " +
|
|
590
|
+
`${AGENT_TABLE_IDLE_MS / 1000} s without a read, with drop_table, when the server ` +
|
|
591
|
+
`lets go of the project, or when more than ${MAX_AGENT_TABLES} are open (the least ` +
|
|
592
|
+
"recently used goes). query_table says `stale: true` when its source columns changed. " +
|
|
593
|
+
"A large table can slow the user's open tables while it builds.",
|
|
594
|
+
inputSchema: z.object({
|
|
595
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
596
|
+
columns: z
|
|
597
|
+
.array(tableColumnIdInput)
|
|
598
|
+
.min(1)
|
|
599
|
+
.max(MAX_TABLE_COLUMNS)
|
|
600
|
+
.describe(
|
|
601
|
+
"Column ids from list_pool_columns (discovered ids included, put them in " +
|
|
602
|
+
"`secondary` to keep their linker qualifications), or PlRef objects; joined by " +
|
|
603
|
+
"`join`.",
|
|
604
|
+
),
|
|
605
|
+
join: z
|
|
606
|
+
.enum(["inner", "full"])
|
|
607
|
+
.optional()
|
|
608
|
+
.describe("How `columns` are joined: `inner` (default) or `full`."),
|
|
609
|
+
secondary: z
|
|
610
|
+
.array(tableColumnIdInput)
|
|
611
|
+
.max(MAX_TABLE_COLUMNS)
|
|
612
|
+
.optional()
|
|
613
|
+
.describe(
|
|
614
|
+
"Column ids from list_pool_columns added to the rows of `columns` where they have a " +
|
|
615
|
+
"value (labels, annotations, discovered columns); they add no rows of their own.",
|
|
616
|
+
),
|
|
617
|
+
filter: tableFilterInput
|
|
618
|
+
.optional()
|
|
619
|
+
.describe(
|
|
620
|
+
"Rows to keep, a FilterSpec tree: leaves `{ type, column, … }` — `isNA`, " +
|
|
621
|
+
"`isNotNA`; `patternEquals`, `patternNotEquals`, `patternContainSubsequence`, " +
|
|
622
|
+
"`patternNotContainSubsequence`, `patternMatchesRegularExpression`, " +
|
|
623
|
+
"`patternFuzzyContainSubsequence` with `value`; `inSet`, `notInSet` with `value: " +
|
|
624
|
+
"[…]`; `equal`, `notEqual`, `lessThan`, `greaterThan`, `lessThanOrEqual`, " +
|
|
625
|
+
"`greaterThanOrEqual` with `x`; `equalToColumn`, `lessThanColumn`, " +
|
|
626
|
+
"`greaterThanColumn`, `lessThanColumnOrEqual`, `greaterThanColumnOrEqual` with " +
|
|
627
|
+
'`rhs` (another reference) and `minDiff?` — and nodes `{ type: "and" | "or", ' +
|
|
628
|
+
`filters: […] }\`, \`{ type: "not", filter }\`. ${REF_TEXT}`,
|
|
629
|
+
),
|
|
630
|
+
sort: tableSortInput
|
|
631
|
+
.optional()
|
|
632
|
+
.describe(
|
|
633
|
+
"Sort keys, first key first: a reference with `ascending?` (default true) and " +
|
|
634
|
+
`\`nullsFirst?\` (default false). ${REF_TEXT}`,
|
|
635
|
+
),
|
|
636
|
+
}),
|
|
637
|
+
},
|
|
638
|
+
async ({ projectId, ...request }, call) => {
|
|
639
|
+
return await ctx.withProject(projectId, async (project, ml) => {
|
|
640
|
+
const overview = await project.overview.getValue();
|
|
641
|
+
const titles = new Map<string, string>();
|
|
642
|
+
for (const b of overview?.blocks ?? []) titles.set(b.id, b.title ?? b.id);
|
|
643
|
+
return await createTableResult(
|
|
644
|
+
project,
|
|
645
|
+
projectId,
|
|
646
|
+
request,
|
|
647
|
+
// The driver of the middle layer the project is of, not the one the server has now.
|
|
648
|
+
{ driver: ml.internalDriverKit.pFrameDriver, tables: ctx.agentTables },
|
|
649
|
+
call?.mcpReq.signal,
|
|
650
|
+
(id) => titles.get(id) ?? id,
|
|
651
|
+
);
|
|
652
|
+
});
|
|
653
|
+
},
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
server.registerTool(
|
|
657
|
+
"drop_table",
|
|
658
|
+
{
|
|
659
|
+
title: "Drop Table",
|
|
660
|
+
// Idempotent, not destructive: it discards only a temporary table of the agent's own, which
|
|
661
|
+
// create_table builds again from the same arguments; nothing of the project changes.
|
|
662
|
+
annotations: hints.idempotent,
|
|
663
|
+
description:
|
|
664
|
+
"Drop a table made by create_table, freeing what it holds: `{ dropped }`. `dropped: " +
|
|
665
|
+
"false` for a handle that is not an open table (dropped or expired already); that is " +
|
|
666
|
+
"not an error. Tables also go on their own after a while without a read.",
|
|
667
|
+
inputSchema: z.object({
|
|
668
|
+
pTableHandle: pTableHandleInput.describe("Table handle from create_table."),
|
|
669
|
+
}),
|
|
670
|
+
},
|
|
671
|
+
async ({ pTableHandle }) => textResult({ dropped: ctx.agentTables.drop(pTableHandle) }),
|
|
672
|
+
);
|
|
673
|
+
}
|