logisheets-logician 1.11.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 +89 -0
- package/dist/agent/loop.d.ts +101 -0
- package/dist/agent/loop.js +260 -0
- package/dist/conversation.d.ts +105 -0
- package/dist/conversation.js +10 -0
- package/dist/craft-interactions-api.d.ts +81 -0
- package/dist/craft-interactions-api.js +25 -0
- package/dist/craft-interactions-core.d.ts +14 -0
- package/dist/craft-interactions-core.js +33 -0
- package/dist/crafts/manifest.d.ts +39 -0
- package/dist/crafts/manifest.js +10 -0
- package/dist/crafts/skill-tools.d.ts +33 -0
- package/dist/crafts/skill-tools.js +146 -0
- package/dist/crafts/store.d.ts +47 -0
- package/dist/crafts/store.js +69 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/index.node.js +5065 -0
- package/dist/projection.d.ts +129 -0
- package/dist/projection.js +249 -0
- package/dist/storage.d.ts +99 -0
- package/dist/storage.js +223 -0
- package/dist/tool.d.ts +137 -0
- package/dist/tool.js +57 -0
- package/dist/tools/block-ops.d.ts +30 -0
- package/dist/tools/block-ops.js +97 -0
- package/dist/tools/builder.d.ts +206 -0
- package/dist/tools/builder.js +1502 -0
- package/dist/tools/cells.d.ts +58 -0
- package/dist/tools/cells.js +263 -0
- package/dist/tools/comments.d.ts +54 -0
- package/dist/tools/comments.js +234 -0
- package/dist/tools/craft-interactions.d.ts +22 -0
- package/dist/tools/craft-interactions.js +454 -0
- package/dist/tools/edit.d.ts +55 -0
- package/dist/tools/edit.js +356 -0
- package/dist/tools/format.d.ts +58 -0
- package/dist/tools/format.js +208 -0
- package/dist/tools/history.d.ts +13 -0
- package/dist/tools/history.js +39 -0
- package/dist/tools/inspect.d.ts +93 -0
- package/dist/tools/inspect.js +488 -0
- package/dist/tools/links.d.ts +30 -0
- package/dist/tools/links.js +122 -0
- package/dist/tools/structure.d.ts +62 -0
- package/dist/tools/structure.js +174 -0
- package/dist/tools/taxonomy.d.ts +32 -0
- package/dist/tools/taxonomy.js +93 -0
- package/package.json +53 -0
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool — a single capability that the LLM can invoke.
|
|
3
|
+
*
|
|
4
|
+
* Design notes:
|
|
5
|
+
* - `name` / `description` / `inputSchema` are what get serialized into the
|
|
6
|
+
* LLM request's `tools` array (Anthropic / OpenAI compatible shape).
|
|
7
|
+
* - `handler` is the local executor. It receives the validated input plus a
|
|
8
|
+
* `ToolContext` that carries the workbook handle and any UI hooks.
|
|
9
|
+
* - `confirmation` lets a tool opt into a user-confirmation step before the
|
|
10
|
+
* handler runs — important for any write that touches the workbook.
|
|
11
|
+
* - Tools are grouped under a `namespace` (e.g. "block", "craft.what_if")
|
|
12
|
+
* so the final tool name exposed to the LLM is `${namespace}__${name}`.
|
|
13
|
+
* This keeps capabilities from different crafts from colliding.
|
|
14
|
+
*/
|
|
15
|
+
import type { Client } from 'logisheets-web/pure';
|
|
16
|
+
import type { CraftInteractionsApi } from './craft-interactions-api.js';
|
|
17
|
+
/**
|
|
18
|
+
* Workbook client surface used by tool handlers. We re-export the `Client`
|
|
19
|
+
* type from `logisheets-web` so hosts can import it from a single place,
|
|
20
|
+
* and so a future headless adapter (logisheets-node) — which implements the
|
|
21
|
+
* same interface — can be plugged in without changes to tool code.
|
|
22
|
+
*/
|
|
23
|
+
export type WorkbookClient = Client;
|
|
24
|
+
/** JSON Schema draft-07 subset; kept loose on purpose. */
|
|
25
|
+
export type JSONSchemaType = 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
26
|
+
export type JSONSchema = {
|
|
27
|
+
/** A single type or a union (e.g. ['string', 'null'] for nullable). */
|
|
28
|
+
type?: JSONSchemaType | readonly JSONSchemaType[];
|
|
29
|
+
description?: string;
|
|
30
|
+
properties?: Record<string, JSONSchema>;
|
|
31
|
+
required?: readonly string[];
|
|
32
|
+
items?: JSONSchema;
|
|
33
|
+
enum?: readonly (string | number)[];
|
|
34
|
+
default?: unknown;
|
|
35
|
+
minItems?: number;
|
|
36
|
+
maxItems?: number;
|
|
37
|
+
minimum?: number;
|
|
38
|
+
maximum?: number;
|
|
39
|
+
[k: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
/** Confirmation policy for a tool invocation. */
|
|
42
|
+
export type ConfirmationPolicy = 'never' | 'once' | 'always' | 'destructive';
|
|
43
|
+
/** Hint to the model (and to the scheduler) about cost. */
|
|
44
|
+
export type ToolCost = 'cheap' | 'normal' | 'expensive';
|
|
45
|
+
/**
|
|
46
|
+
* Scoped read/write access to a craft's persisted state (the opaque per-document
|
|
47
|
+
* JSON a craft owns via the host's AppData). Present on the ToolContext only for
|
|
48
|
+
* craft-skill tools, scoped to that craft — so a tool can operate the craft's
|
|
49
|
+
* stateful feature (a game board, a saved config) and stay consistent with the
|
|
50
|
+
* craft's own persistence. The schema is the craft's business (it JSON-encodes
|
|
51
|
+
* it itself), exactly like `window.getCraftState()`/`setCraftState()` in a craft.
|
|
52
|
+
*/
|
|
53
|
+
export interface CraftStateAccess {
|
|
54
|
+
get(): string | undefined;
|
|
55
|
+
set(json: string): void;
|
|
56
|
+
}
|
|
57
|
+
/** Context passed to every tool handler. */
|
|
58
|
+
export interface ToolContext {
|
|
59
|
+
/** The active LogiSheets workbook client. */
|
|
60
|
+
workbook: WorkbookClient;
|
|
61
|
+
/** Abort signal — fires if the user cancels the in-flight turn. */
|
|
62
|
+
signal: AbortSignal;
|
|
63
|
+
/** Ask the user to confirm an action; returns true if approved. */
|
|
64
|
+
confirm: (message: string, detail?: unknown) => Promise<boolean>;
|
|
65
|
+
/** Emit a progress / log line into the chat transcript. */
|
|
66
|
+
log: (msg: string) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Persisted state of the craft this tool belongs to, scoped to that craft.
|
|
69
|
+
* Present only for craft-skill tools whose host wired a craftState provider;
|
|
70
|
+
* undefined for the built-in tools and headless hosts. A craft tool that
|
|
71
|
+
* needs it should degrade gracefully when it is absent.
|
|
72
|
+
*/
|
|
73
|
+
craftState?: CraftStateAccess;
|
|
74
|
+
/**
|
|
75
|
+
* Craft-defined cell-overlay widgets (radio / multi-select / point /
|
|
76
|
+
* percent / slider). Optional: present only when the host has craft
|
|
77
|
+
* interactions (browser app). Absent in headless hosts — craft-
|
|
78
|
+
* interaction tools detect this and return a "not available" result
|
|
79
|
+
* rather than throwing.
|
|
80
|
+
*/
|
|
81
|
+
craftInteractions?: CraftInteractionsApi;
|
|
82
|
+
}
|
|
83
|
+
/** Structured result returned by a handler. */
|
|
84
|
+
export interface ToolResult<T = unknown> {
|
|
85
|
+
/** Payload shown back to the LLM as `tool_result.content`. */
|
|
86
|
+
data: T;
|
|
87
|
+
/** Optional human-readable summary rendered into the chat UI. */
|
|
88
|
+
display?: string;
|
|
89
|
+
/** Set when the user declined a confirmation. */
|
|
90
|
+
canceled?: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface Tool<Input = unknown, Output = unknown> {
|
|
93
|
+
namespace: string;
|
|
94
|
+
/** Tool name within the namespace. snake_case. No "__". */
|
|
95
|
+
name: string;
|
|
96
|
+
/** One-line description; the model uses this to decide when to call. */
|
|
97
|
+
description: string;
|
|
98
|
+
/** JSON Schema for the `input` argument. */
|
|
99
|
+
inputSchema: JSONSchema;
|
|
100
|
+
/** Whether this tool mutates workbook state. */
|
|
101
|
+
mutates: boolean;
|
|
102
|
+
/** Confirmation policy; defaults to 'never' for reads, 'always' for writes. */
|
|
103
|
+
confirmation?: ConfirmationPolicy;
|
|
104
|
+
/** Cost hint; defaults to 'normal'. */
|
|
105
|
+
cost?: ToolCost;
|
|
106
|
+
/**
|
|
107
|
+
* Multi-level category path for organizing tools into a tree (e.g.
|
|
108
|
+
* ['Data', 'Write'] or ['Structure', 'Sheets']). Purely organizational —
|
|
109
|
+
* NOT part of the LLM-facing id (`namespace__name`). Optional: when absent,
|
|
110
|
+
* a built-in default taxonomy is used (see tools/taxonomy.ts). A craft tool
|
|
111
|
+
* may set it to slot itself into the tree.
|
|
112
|
+
*/
|
|
113
|
+
category?: readonly string[];
|
|
114
|
+
/** Execute the tool. Throw to signal an error to the LLM. */
|
|
115
|
+
handler: (input: Input, ctx: ToolContext) => Promise<ToolResult<Output>>;
|
|
116
|
+
}
|
|
117
|
+
/** Fully-qualified tool id as exposed to the LLM. */
|
|
118
|
+
export declare function toolId(t: Pick<Tool, 'namespace' | 'name'>): string;
|
|
119
|
+
/** Serialize a tool into the Anthropic `tools` array shape. */
|
|
120
|
+
export declare function toLlmTool(t: Tool): {
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
input_schema: JSONSchema;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* In-memory tool registry. Hosts populate this at startup (or lazily) and
|
|
127
|
+
* pass it to the Agent loop, which dispatches by fully-qualified id.
|
|
128
|
+
*/
|
|
129
|
+
export declare class ToolRegistry {
|
|
130
|
+
private tools;
|
|
131
|
+
register(tool: Tool): void;
|
|
132
|
+
registerMany(tools: ReadonlyArray<Tool>): void;
|
|
133
|
+
unregister(id: string): void;
|
|
134
|
+
get(id: string): Tool | undefined;
|
|
135
|
+
list(): Tool[];
|
|
136
|
+
toLlmTools(): ReturnType<typeof toLlmTool>[];
|
|
137
|
+
}
|
package/dist/tool.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool — a single capability that the LLM can invoke.
|
|
3
|
+
*
|
|
4
|
+
* Design notes:
|
|
5
|
+
* - `name` / `description` / `inputSchema` are what get serialized into the
|
|
6
|
+
* LLM request's `tools` array (Anthropic / OpenAI compatible shape).
|
|
7
|
+
* - `handler` is the local executor. It receives the validated input plus a
|
|
8
|
+
* `ToolContext` that carries the workbook handle and any UI hooks.
|
|
9
|
+
* - `confirmation` lets a tool opt into a user-confirmation step before the
|
|
10
|
+
* handler runs — important for any write that touches the workbook.
|
|
11
|
+
* - Tools are grouped under a `namespace` (e.g. "block", "craft.what_if")
|
|
12
|
+
* so the final tool name exposed to the LLM is `${namespace}__${name}`.
|
|
13
|
+
* This keeps capabilities from different crafts from colliding.
|
|
14
|
+
*/
|
|
15
|
+
/** Fully-qualified tool id as exposed to the LLM. */
|
|
16
|
+
export function toolId(t) {
|
|
17
|
+
return `${t.namespace}__${t.name}`;
|
|
18
|
+
}
|
|
19
|
+
/** Serialize a tool into the Anthropic `tools` array shape. */
|
|
20
|
+
export function toLlmTool(t) {
|
|
21
|
+
return {
|
|
22
|
+
name: toolId(t),
|
|
23
|
+
description: t.description,
|
|
24
|
+
input_schema: { type: 'object', ...t.inputSchema },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* In-memory tool registry. Hosts populate this at startup (or lazily) and
|
|
29
|
+
* pass it to the Agent loop, which dispatches by fully-qualified id.
|
|
30
|
+
*/
|
|
31
|
+
export class ToolRegistry {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.tools = new Map();
|
|
34
|
+
}
|
|
35
|
+
register(tool) {
|
|
36
|
+
const id = toolId(tool);
|
|
37
|
+
if (this.tools.has(id))
|
|
38
|
+
throw new Error(`Tool already registered: ${id}`);
|
|
39
|
+
this.tools.set(id, tool);
|
|
40
|
+
}
|
|
41
|
+
registerMany(tools) {
|
|
42
|
+
for (const t of tools)
|
|
43
|
+
this.register(t);
|
|
44
|
+
}
|
|
45
|
+
unregister(id) {
|
|
46
|
+
this.tools.delete(id);
|
|
47
|
+
}
|
|
48
|
+
get(id) {
|
|
49
|
+
return this.tools.get(id);
|
|
50
|
+
}
|
|
51
|
+
list() {
|
|
52
|
+
return [...this.tools.values()];
|
|
53
|
+
}
|
|
54
|
+
toLlmTools() {
|
|
55
|
+
return this.list().map(toLlmTool);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced block ops — move, resize, and remove whole blocks. Blocks are
|
|
3
|
+
* addressed by numeric blockId (from create_block's result or list_blocks'
|
|
4
|
+
* block_id field). Row/column edits inside a block live in the build tools
|
|
5
|
+
* (add_block_rows / delete_block_rows).
|
|
6
|
+
*/
|
|
7
|
+
import type { Tool } from '../tool.js';
|
|
8
|
+
export declare const moveBlock: Tool<{
|
|
9
|
+
sheetIdx: number;
|
|
10
|
+
blockId: number;
|
|
11
|
+
newMasterRow: number;
|
|
12
|
+
newMasterCol: number;
|
|
13
|
+
}, {
|
|
14
|
+
ok: true;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const resizeBlock: Tool<{
|
|
17
|
+
sheetIdx: number;
|
|
18
|
+
blockId: number;
|
|
19
|
+
newRowCnt?: number;
|
|
20
|
+
newColCnt?: number;
|
|
21
|
+
}, {
|
|
22
|
+
ok: true;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const removeBlock: Tool<{
|
|
25
|
+
sheetIdx: number;
|
|
26
|
+
blockId: number;
|
|
27
|
+
}, {
|
|
28
|
+
ok: true;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const BLOCK_OPS_TOOLS: Tool[];
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced block ops — move, resize, and remove whole blocks. Blocks are
|
|
3
|
+
* addressed by numeric blockId (from create_block's result or list_blocks'
|
|
4
|
+
* block_id field). Row/column edits inside a block live in the build tools
|
|
5
|
+
* (add_block_rows / delete_block_rows).
|
|
6
|
+
*/
|
|
7
|
+
import { isErrorMessage } from 'logisheets-web/pure';
|
|
8
|
+
function asClient(ctx) {
|
|
9
|
+
return ctx.workbook;
|
|
10
|
+
}
|
|
11
|
+
async function commit(client, payload, label) {
|
|
12
|
+
const tx = { payloads: [payload], undoable: true, temp: false };
|
|
13
|
+
const r = await client.handleTransaction({ transaction: tx });
|
|
14
|
+
if (isErrorMessage(r))
|
|
15
|
+
throw new Error(`${label}: ${r.msg}`);
|
|
16
|
+
if (r.status.type === 'err')
|
|
17
|
+
throw new Error(`${label}: status code ${r.status.value}`);
|
|
18
|
+
}
|
|
19
|
+
export const moveBlock = {
|
|
20
|
+
namespace: 'build',
|
|
21
|
+
name: 'move_block',
|
|
22
|
+
description: 'Move a whole block so its top-left (master) cell lands at a new zero-based (row, col). Get blockId from list_blocks or create_block.',
|
|
23
|
+
mutates: true,
|
|
24
|
+
confirmation: 'always',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
properties: {
|
|
27
|
+
sheetIdx: { type: 'integer' },
|
|
28
|
+
blockId: { type: 'integer' },
|
|
29
|
+
newMasterRow: { type: 'integer', description: 'New top-left row (zero-based).' },
|
|
30
|
+
newMasterCol: { type: 'integer', description: 'New top-left column (zero-based).' },
|
|
31
|
+
},
|
|
32
|
+
required: ['sheetIdx', 'blockId', 'newMasterRow', 'newMasterCol'],
|
|
33
|
+
},
|
|
34
|
+
handler: async (input, ctx) => {
|
|
35
|
+
await commit(asClient(ctx), {
|
|
36
|
+
type: 'moveBlock',
|
|
37
|
+
value: {
|
|
38
|
+
sheetIdx: input.sheetIdx,
|
|
39
|
+
id: input.blockId,
|
|
40
|
+
newMasterRow: input.newMasterRow,
|
|
41
|
+
newMasterCol: input.newMasterCol,
|
|
42
|
+
},
|
|
43
|
+
}, 'move_block');
|
|
44
|
+
return { data: { ok: true }, display: `Moved block ${input.blockId}` };
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export const resizeBlock = {
|
|
48
|
+
namespace: 'build',
|
|
49
|
+
name: 'resize_block',
|
|
50
|
+
description: 'Resize a block to a new row and/or column count (omit one to leave that dimension unchanged). Get blockId from list_blocks.',
|
|
51
|
+
mutates: true,
|
|
52
|
+
confirmation: 'always',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
properties: {
|
|
55
|
+
sheetIdx: { type: 'integer' },
|
|
56
|
+
blockId: { type: 'integer' },
|
|
57
|
+
newRowCnt: { type: 'integer', description: 'New number of rows.' },
|
|
58
|
+
newColCnt: { type: 'integer', description: 'New number of columns.' },
|
|
59
|
+
},
|
|
60
|
+
required: ['sheetIdx', 'blockId'],
|
|
61
|
+
},
|
|
62
|
+
handler: async (input, ctx) => {
|
|
63
|
+
await commit(asClient(ctx), {
|
|
64
|
+
type: 'resizeBlock',
|
|
65
|
+
value: {
|
|
66
|
+
sheetIdx: input.sheetIdx,
|
|
67
|
+
id: input.blockId,
|
|
68
|
+
newRowCnt: input.newRowCnt,
|
|
69
|
+
newColCnt: input.newColCnt,
|
|
70
|
+
},
|
|
71
|
+
}, 'resize_block');
|
|
72
|
+
return { data: { ok: true }, display: `Resized block ${input.blockId}` };
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
export const removeBlock = {
|
|
76
|
+
namespace: 'build',
|
|
77
|
+
name: 'remove_block',
|
|
78
|
+
description: 'Remove a whole block (its schema and cells) by blockId. Get blockId from list_blocks.',
|
|
79
|
+
mutates: true,
|
|
80
|
+
confirmation: 'destructive',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
properties: {
|
|
83
|
+
sheetIdx: { type: 'integer' },
|
|
84
|
+
blockId: { type: 'integer' },
|
|
85
|
+
},
|
|
86
|
+
required: ['sheetIdx', 'blockId'],
|
|
87
|
+
},
|
|
88
|
+
handler: async (input, ctx) => {
|
|
89
|
+
await commit(asClient(ctx), { type: 'removeBlock', value: { sheetIdx: input.sheetIdx, id: input.blockId } }, 'remove_block');
|
|
90
|
+
return { data: { ok: true }, display: `Removed block ${input.blockId}` };
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
export const BLOCK_OPS_TOOLS = [
|
|
94
|
+
moveBlock,
|
|
95
|
+
resizeBlock,
|
|
96
|
+
removeBlock,
|
|
97
|
+
];
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder tools — let the LLM construct block-shaped models in a workbook
|
|
3
|
+
* from a natural-language description.
|
|
4
|
+
*
|
|
5
|
+
* Surface (10 tools, block-only — no raw (sheet,row,col) writes):
|
|
6
|
+
* Structure : create_sheet, create_block, add_block_rows, delete_block_rows
|
|
7
|
+
* Rules : set_field_rule, define_enum_set
|
|
8
|
+
* Reflection : list_blocks, describe_block, eval_formula
|
|
9
|
+
* Safety : checkpoint / restore (one tool, two ops)
|
|
10
|
+
*
|
|
11
|
+
* Handlers below are intentionally thin — they describe the contract.
|
|
12
|
+
* Real implementations will dispatch to the workbook client + block manager.
|
|
13
|
+
*/
|
|
14
|
+
import type { Tool } from '../tool.js';
|
|
15
|
+
declare const FIELD_TYPE_ENUM: readonly ["string", "number", "boolean", "enum", "date", "datetime"];
|
|
16
|
+
export declare const createSheet: Tool<{
|
|
17
|
+
name: string;
|
|
18
|
+
}, {
|
|
19
|
+
sheet_idx: number;
|
|
20
|
+
}>;
|
|
21
|
+
interface CreateBlockInput {
|
|
22
|
+
sheet: string;
|
|
23
|
+
name: string;
|
|
24
|
+
position: {
|
|
25
|
+
row: number;
|
|
26
|
+
col: number;
|
|
27
|
+
};
|
|
28
|
+
fields: ReadonlyArray<{
|
|
29
|
+
name: string;
|
|
30
|
+
field_type?: (typeof FIELD_TYPE_ENUM)[number];
|
|
31
|
+
num_fmt?: string;
|
|
32
|
+
enum_id?: string;
|
|
33
|
+
user_editable?: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
initial_rows?: ReadonlyArray<{
|
|
36
|
+
key: string;
|
|
37
|
+
values?: Record<string, unknown>;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
export declare const createBlock: Tool<CreateBlockInput, {
|
|
41
|
+
block_id: number;
|
|
42
|
+
}>;
|
|
43
|
+
interface AddBlockRowsInput {
|
|
44
|
+
block: string;
|
|
45
|
+
rows: ReadonlyArray<{
|
|
46
|
+
key: string;
|
|
47
|
+
values?: Record<string, unknown>;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export declare const addBlockRows: Tool<AddBlockRowsInput, {
|
|
51
|
+
added: number;
|
|
52
|
+
}>;
|
|
53
|
+
interface DeleteBlockRowsInput {
|
|
54
|
+
block: string;
|
|
55
|
+
keys: ReadonlyArray<string>;
|
|
56
|
+
}
|
|
57
|
+
export declare const deleteBlockRows: Tool<DeleteBlockRowsInput, {
|
|
58
|
+
removed: number;
|
|
59
|
+
}>;
|
|
60
|
+
interface SetFieldRuleInput {
|
|
61
|
+
block: string;
|
|
62
|
+
field: string;
|
|
63
|
+
value_formula?: string | null;
|
|
64
|
+
validation?: string | null;
|
|
65
|
+
editability?: string | null;
|
|
66
|
+
}
|
|
67
|
+
export declare const setFieldRule: Tool<SetFieldRuleInput, {
|
|
68
|
+
applied: string[];
|
|
69
|
+
}>;
|
|
70
|
+
interface EnumVariantInput {
|
|
71
|
+
id: string;
|
|
72
|
+
label: string;
|
|
73
|
+
/** Hex color (#RRGGBB). Auto-assigned from a palette if omitted. */
|
|
74
|
+
color?: string;
|
|
75
|
+
}
|
|
76
|
+
interface DefineEnumSetInput {
|
|
77
|
+
id: string;
|
|
78
|
+
name?: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
variants: ReadonlyArray<EnumVariantInput>;
|
|
81
|
+
}
|
|
82
|
+
interface DefineEnumSetOutput {
|
|
83
|
+
enum_id: string;
|
|
84
|
+
variant_count: number;
|
|
85
|
+
/** echoed variant id list so AI's next call (e.g. create_block with
|
|
86
|
+
* field_type='enum') has the canonical id strings handy. */
|
|
87
|
+
variant_ids: string[];
|
|
88
|
+
}
|
|
89
|
+
export declare const defineEnumSet: Tool<DefineEnumSetInput, DefineEnumSetOutput>;
|
|
90
|
+
/** Watson-session enum registry. Mirror of what's in the host's
|
|
91
|
+
* enumSetManager when available, plus a fallback for headless. Read by
|
|
92
|
+
* the create_block handler when a field declares `field_type: 'enum'`
|
|
93
|
+
* so it can auto-inject a variant whitelist validation. */
|
|
94
|
+
export declare const _enumSetCache: Map<string, {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
variants: ReadonlyArray<{
|
|
99
|
+
id: string;
|
|
100
|
+
value: string;
|
|
101
|
+
color: string;
|
|
102
|
+
}>;
|
|
103
|
+
}>;
|
|
104
|
+
interface ListBlocksInput {
|
|
105
|
+
sheet?: string;
|
|
106
|
+
}
|
|
107
|
+
interface BlockSummary {
|
|
108
|
+
name: string;
|
|
109
|
+
/** Numeric block id — pass to move_block / resize_block / remove_block. */
|
|
110
|
+
block_id: number;
|
|
111
|
+
position: {
|
|
112
|
+
row: number;
|
|
113
|
+
col: number;
|
|
114
|
+
};
|
|
115
|
+
row_count: number;
|
|
116
|
+
col_count: number;
|
|
117
|
+
}
|
|
118
|
+
interface SheetBlockGroup {
|
|
119
|
+
sheet_name: string;
|
|
120
|
+
sheet_idx: number;
|
|
121
|
+
blocks: BlockSummary[];
|
|
122
|
+
/**
|
|
123
|
+
* Suggested (row, col) for the next new block on this sheet, assuming
|
|
124
|
+
* blocks don't share rows (one block per row range). A one-row gap
|
|
125
|
+
* is reserved after the bottom-most block for readability. Use this
|
|
126
|
+
* as the `position` argument to `create_block`. For an empty sheet
|
|
127
|
+
* this is (0, 0).
|
|
128
|
+
*/
|
|
129
|
+
next_block_start: {
|
|
130
|
+
row: number;
|
|
131
|
+
col: number;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export declare const listBlocks: Tool<ListBlocksInput, SheetBlockGroup[]>;
|
|
135
|
+
interface DescribeBlockInput {
|
|
136
|
+
name: string;
|
|
137
|
+
include_rows?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface FieldDescription {
|
|
140
|
+
name: string;
|
|
141
|
+
/** 0-based column index within the block. */
|
|
142
|
+
position: number;
|
|
143
|
+
/** Engine-computed cell value (raw template, no placeholder
|
|
144
|
+
* expansion). `null` for free-form fields. */
|
|
145
|
+
value_formula: string | null;
|
|
146
|
+
/** Per-row boolean rule — host UI renders a warning marker when
|
|
147
|
+
* it evaluates false. `null` if not declared. */
|
|
148
|
+
validation: string | null;
|
|
149
|
+
/** Per-row boolean rule — host permission patch gates writes
|
|
150
|
+
* when it evaluates false. `null` if not declared. */
|
|
151
|
+
editability: string | null;
|
|
152
|
+
}
|
|
153
|
+
interface DescribeBlockOutput {
|
|
154
|
+
block: string;
|
|
155
|
+
sheet: string;
|
|
156
|
+
sheet_idx: number;
|
|
157
|
+
position: {
|
|
158
|
+
row: number;
|
|
159
|
+
col: number;
|
|
160
|
+
};
|
|
161
|
+
row_count: number;
|
|
162
|
+
col_count: number;
|
|
163
|
+
fields: FieldDescription[];
|
|
164
|
+
/** Row keys in block-row order. Always present (cheap). */
|
|
165
|
+
keys: string[];
|
|
166
|
+
/** Only when `include_rows=true`. Each entry maps every field name
|
|
167
|
+
* to that cell's current value (string / number / boolean) or
|
|
168
|
+
* null when empty. Formula errors surface as `"#ERR:..."` strings. */
|
|
169
|
+
rows?: Array<{
|
|
170
|
+
key: string;
|
|
171
|
+
values: Record<string, string | number | boolean | null>;
|
|
172
|
+
}>;
|
|
173
|
+
}
|
|
174
|
+
export declare const describeBlock: Tool<DescribeBlockInput, DescribeBlockOutput>;
|
|
175
|
+
interface EvalFormulaInput {
|
|
176
|
+
expr: string;
|
|
177
|
+
}
|
|
178
|
+
interface EvalFormulaOutput {
|
|
179
|
+
/** Discriminated tag — `'empty'` when the formula returned an empty cell. */
|
|
180
|
+
type: 'str' | 'number' | 'bool' | 'error' | 'empty';
|
|
181
|
+
/** Coerced JSON value. Empty cells get `null`. Errors get the
|
|
182
|
+
* engine's error code as a string. */
|
|
183
|
+
value: string | number | boolean | null;
|
|
184
|
+
}
|
|
185
|
+
export declare const evalFormula: Tool<EvalFormulaInput, EvalFormulaOutput>;
|
|
186
|
+
interface CheckpointInput {
|
|
187
|
+
op: 'save' | 'restore' | 'delete' | 'list';
|
|
188
|
+
/** Required for save / restore / delete. Ignored for list. */
|
|
189
|
+
label?: string;
|
|
190
|
+
/** Human-readable note; only meaningful for save, echoed back by list. */
|
|
191
|
+
description?: string;
|
|
192
|
+
}
|
|
193
|
+
interface CheckpointOutput {
|
|
194
|
+
op: 'save' | 'restore' | 'delete' | 'list';
|
|
195
|
+
/** For save: total checkpoint count after the save.
|
|
196
|
+
* For delete: true if the label existed. */
|
|
197
|
+
result?: number | boolean;
|
|
198
|
+
/** For list: enumerated checkpoints (newest first). */
|
|
199
|
+
checkpoints?: ReadonlyArray<{
|
|
200
|
+
label: string;
|
|
201
|
+
description?: string;
|
|
202
|
+
}>;
|
|
203
|
+
}
|
|
204
|
+
export declare const checkpoint: Tool<CheckpointInput, CheckpointOutput>;
|
|
205
|
+
export declare const BUILDER_TOOLS: Tool[];
|
|
206
|
+
export {};
|