@orkestrel/tool 0.0.2 → 0.0.3
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/dist/src/core/index.cjs +1279 -0
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +907 -30
- package/dist/src/core/index.d.ts +907 -30
- package/dist/src/core/index.js +1235 -2
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -7
package/dist/src/core/index.d.ts
CHANGED
|
@@ -2,14 +2,32 @@ import { AgentInterface } from '@orkestrel/agent';
|
|
|
2
2
|
import { AgentRegistryInterface } from '@orkestrel/agent';
|
|
3
3
|
import { ArrayShape } from '@orkestrel/contract';
|
|
4
4
|
import { BooleanShape } from '@orkestrel/contract';
|
|
5
|
+
import { ColumnSchema } from '@orkestrel/database';
|
|
6
|
+
import { Condition } from '@orkestrel/database';
|
|
7
|
+
import { Connector } from '@orkestrel/database';
|
|
5
8
|
import { ContractInterface } from '@orkestrel/contract';
|
|
9
|
+
import { ContractShape } from '@orkestrel/contract';
|
|
6
10
|
import { ConversationStoreInterface } from '@orkestrel/agent';
|
|
11
|
+
import { Criteria } from '@orkestrel/database';
|
|
12
|
+
import { DatabaseErrorCode } from '@orkestrel/database';
|
|
13
|
+
import { DatabaseInterface } from '@orkestrel/database';
|
|
14
|
+
import { Direction } from '@orkestrel/database';
|
|
15
|
+
import { DriverInterface } from '@orkestrel/database';
|
|
16
|
+
import { Include } from '@orkestrel/relation';
|
|
17
|
+
import { JSONShape } from '@orkestrel/contract';
|
|
18
|
+
import { KeyFunction } from '@orkestrel/database';
|
|
7
19
|
import { LiteralShape } from '@orkestrel/contract';
|
|
20
|
+
import { ModelInterface } from '@orkestrel/relation';
|
|
8
21
|
import { NumberShape } from '@orkestrel/contract';
|
|
9
22
|
import { ObjectShape } from '@orkestrel/contract';
|
|
10
23
|
import { OptionalShape } from '@orkestrel/contract';
|
|
11
24
|
import { PromptType } from '@orkestrel/terminal';
|
|
25
|
+
import { RelationErrorCode } from '@orkestrel/relation';
|
|
26
|
+
import { RelationManagerInterface } from '@orkestrel/relation';
|
|
12
27
|
import { StringShape } from '@orkestrel/contract';
|
|
28
|
+
import { TableInterface } from '@orkestrel/database';
|
|
29
|
+
import { TableSchema } from '@orkestrel/database';
|
|
30
|
+
import { TablesShape } from '@orkestrel/database';
|
|
13
31
|
import { TerminalManagerInterface } from '@orkestrel/terminal';
|
|
14
32
|
import { ToolInterface } from '@orkestrel/agent';
|
|
15
33
|
import { ToolManagerInterface } from '@orkestrel/agent';
|
|
@@ -119,6 +137,9 @@ export declare interface AgentToolArguments {
|
|
|
119
137
|
* (`DEADLOCK`), a prompt that expired before it was answered (`EXPIRE`), or an answer that
|
|
120
138
|
* failed to apply (`ANSWER`) — the last three thrown by
|
|
121
139
|
* {@link import('./factories.js').createPromptTool} / {@link import('./factories.js').createAnswerTool}.
|
|
140
|
+
* The upcoming database / relation tools (SRC-1's later units) will throw it too: a typed
|
|
141
|
+
* `@orkestrel/database` failure re-surfaces as `DATABASE`, a typed `@orkestrel/relation` failure
|
|
142
|
+
* as `RELATION` — each carrying the package's own granular error code in `context`.
|
|
122
143
|
*
|
|
123
144
|
* @remarks
|
|
124
145
|
* Carries a machine-readable `code` (see {@link import('./types.js').AgentToolErrorCode}) and
|
|
@@ -160,8 +181,12 @@ export declare class AgentToolError extends Error {
|
|
|
160
181
|
* `ANSWER` — {@link import('./factories.js').createAnswerTool}'s answer call failed to apply
|
|
161
182
|
* (an unknown prompt id, a rejected value, or the terminal itself unknown —
|
|
162
183
|
* `TerminalAnswerResult.error`, `@orkestrel/terminal`).
|
|
184
|
+
* `DATABASE` — a typed `@orkestrel/database` failure (`DatabaseError`), re-surfaced with the
|
|
185
|
+
* granular {@link import('@orkestrel/database').DatabaseErrorCode} carried in `context`.
|
|
186
|
+
* `RELATION` — a typed `@orkestrel/relation` failure (`RelationError`), re-surfaced with the
|
|
187
|
+
* granular {@link import('@orkestrel/relation').RelationErrorCode} carried in `context`.
|
|
163
188
|
*/
|
|
164
|
-
export declare type AgentToolErrorCode = 'TOOL' | 'DEPTH' | 'DEADLOCK' | 'EXPIRE' | 'ANSWER';
|
|
189
|
+
export declare type AgentToolErrorCode = 'TOOL' | 'DEPTH' | 'DEADLOCK' | 'EXPIRE' | 'ANSWER' | 'DATABASE' | 'RELATION';
|
|
165
190
|
|
|
166
191
|
/**
|
|
167
192
|
* Options for {@link import('./factories.js').createAgentTool} — the sub-agent delegation
|
|
@@ -219,7 +244,7 @@ export declare const agentToolShape: ObjectShape<{
|
|
|
219
244
|
provider: OptionalShape<StringShape>;
|
|
220
245
|
tools: OptionalShape<ArrayShape<StringShape>>;
|
|
221
246
|
system: OptionalShape<StringShape>;
|
|
222
|
-
}>;
|
|
247
|
+
}, false>;
|
|
223
248
|
|
|
224
249
|
export declare const ANSWER_TOOL_DESCRIPTION: string;
|
|
225
250
|
|
|
@@ -273,11 +298,42 @@ export declare interface AnswerToolOptions {
|
|
|
273
298
|
*/
|
|
274
299
|
export declare const answerToolShape: UnionShape<[ ObjectShape<{
|
|
275
300
|
operation: LiteralShape<readonly ["pending"]>;
|
|
276
|
-
}>, ObjectShape<{
|
|
301
|
+
}, false>, ObjectShape<{
|
|
277
302
|
operation: LiteralShape<readonly ["answer"]>;
|
|
278
303
|
id: StringShape;
|
|
279
304
|
value: UnionShape<[ StringShape, BooleanShape, ArrayShape<StringShape>]>;
|
|
280
|
-
}>]>;
|
|
305
|
+
}, false>]>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Clamp a `'records'` call's criteria to a row cap, and build the PROBE criteria the caller reads
|
|
309
|
+
* with — the pure leaf {@link import('./factories.js').createDatabaseTool}'s `'records'` operation
|
|
310
|
+
* uses to detect truncation without a separate `count` round trip.
|
|
311
|
+
*
|
|
312
|
+
* @remarks
|
|
313
|
+
* The effective limit is `min(criteria?.limit ?? cap, cap)`, floored at `0` (so a caller can never
|
|
314
|
+
* exceed the configured cap by supplying a larger `criteria.limit`). The returned probe criteria
|
|
315
|
+
* requests ONE MORE row than the effective limit (`limit: effective + 1`) — if storage returns
|
|
316
|
+
* that many, the caller knows the true result was truncated (`rows.length > effective`) and slices
|
|
317
|
+
* back down to `effective` before returning.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* import { clampCriteria } from '@src/core'
|
|
322
|
+
*
|
|
323
|
+
* const { criteria, limit } = clampCriteria(undefined, 100)
|
|
324
|
+
* // limit === 100, criteria.limit === 101 — a probe fetching one extra row
|
|
325
|
+
* const rows = await table.records(criteria)
|
|
326
|
+
* const truncated = rows.length > limit // true when storage had more than `limit` rows
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* @param criteria - The live criteria to clamp (or `undefined`)
|
|
330
|
+
* @param cap - The row-count ceiling
|
|
331
|
+
* @returns The PROBE criteria (`limit` bumped by one) and the effective `limit`
|
|
332
|
+
*/
|
|
333
|
+
export declare function clampCriteria(criteria: Criteria | undefined, cap: number): Readonly<{
|
|
334
|
+
criteria: Criteria;
|
|
335
|
+
limit: number;
|
|
336
|
+
}>;
|
|
281
337
|
|
|
282
338
|
/**
|
|
283
339
|
* Normalize an LLM-supplied answer `value` to the type {@link PromptType} `form` expects, so a
|
|
@@ -301,6 +357,33 @@ export declare const answerToolShape: UnionShape<[ ObjectShape<{
|
|
|
301
357
|
*/
|
|
302
358
|
export declare function coerceAnswer(form: PromptType, value: unknown): string | boolean | readonly string[];
|
|
303
359
|
|
|
360
|
+
/** One column's declared type — a primitive shorthand, or `integer` for a whole-number `number`. */
|
|
361
|
+
export declare type ColumnKind = 'string' | 'integer' | 'number' | 'boolean';
|
|
362
|
+
|
|
363
|
+
/** A {@link import('./types.js').ColumnKind} literal — the leaf {@link columnSpecShape} wraps. */
|
|
364
|
+
export declare const columnKindShape: LiteralShape<readonly ["string", "integer", "number", "boolean"]>;
|
|
365
|
+
|
|
366
|
+
/** Map a column NAME + its live `@orkestrel/database` `ContractShape` to a {@link ColumnSchema} — the leaf {@link tableSchema} maps over. */
|
|
367
|
+
export declare function columnSchema(name: string, shape: ContractShape): ColumnSchema;
|
|
368
|
+
|
|
369
|
+
/** Compile one {@link ColumnSpec} into its `@orkestrel/database` column shape — the per-column leaf {@link expandTables} maps over. */
|
|
370
|
+
export declare function columnShape(spec: ColumnSpec): ContractShape;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* One table column's spec — either a bare {@link ColumnKind} shorthand, or `{ type, optional }`
|
|
374
|
+
* when the column may be absent from a row.
|
|
375
|
+
*/
|
|
376
|
+
export declare type ColumnSpec = ColumnKind | Readonly<{
|
|
377
|
+
type: ColumnKind;
|
|
378
|
+
optional?: boolean;
|
|
379
|
+
}>;
|
|
380
|
+
|
|
381
|
+
/** A {@link import('./types.js').ColumnSpec} — a bare {@link columnKindShape}, or `{ type, optional }`. */
|
|
382
|
+
export declare const columnSpecShape: UnionShape<[ LiteralShape<readonly ["string", "integer", "number", "boolean"]>, ObjectShape<{
|
|
383
|
+
type: LiteralShape<readonly ["string", "integer", "number", "boolean"]>;
|
|
384
|
+
optional: OptionalShape<BooleanShape>;
|
|
385
|
+
}, false>]>;
|
|
386
|
+
|
|
304
387
|
/**
|
|
305
388
|
* Complete a {@link WorkflowDraft} into a strict {@link WorkflowDefinition} — synthesize any
|
|
306
389
|
* MISSING `id` deterministically + positionally, and default any MISSING `name` to its
|
|
@@ -343,6 +426,14 @@ export declare function completePhaseDraft(phase: PhaseDraft, index: number): Wo
|
|
|
343
426
|
*/
|
|
344
427
|
export declare function completeTaskDraft(task: TaskDraft, phaseId: string, index: number): WorkflowDefinition['phases'][number]['tasks'][number];
|
|
345
428
|
|
|
429
|
+
/** One SERIALIZED WHERE condition — `values` is ALWAYS an array, even for a single-value operator. */
|
|
430
|
+
export declare const conditionShape: ObjectShape<{
|
|
431
|
+
column: StringShape;
|
|
432
|
+
operator: LiteralShape<readonly ["equals", "not", "above", "below", "from", "to", "between", "like", "glob", "starts", "ends", "any", "none", "absent", "present"]>;
|
|
433
|
+
values: ArrayShape<JSONShape>;
|
|
434
|
+
connector: OptionalShape<LiteralShape<readonly ["and", "or"]>>;
|
|
435
|
+
}, false>;
|
|
436
|
+
|
|
346
437
|
/**
|
|
347
438
|
* Wrap a live `AgentInterface` (`@orkestrel/agent`) as a {@link WorkflowFunction}
|
|
348
439
|
* (`@orkestrel/workflow`) — the OPT-IN adapter that runs the agent to a settled result, folding
|
|
@@ -465,6 +556,87 @@ export declare function createAgentTool(registry: AgentRegistryInterface, option
|
|
|
465
556
|
*/
|
|
466
557
|
export declare function createAnswerTool(options: AnswerToolOptions): ToolInterface;
|
|
467
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Create a {@link DefinitionStoreInterface} backed by one table of the `@orkestrel/database`
|
|
561
|
+
* layer — the driver-pluggable twin of {@link createMemoryDefinitionStore}, storing each
|
|
562
|
+
* database's definition as one opaque JSON column.
|
|
563
|
+
*
|
|
564
|
+
* @param driver - The {@link DriverInterface} backing the table (default an in-memory driver)
|
|
565
|
+
* @returns A {@link DefinitionStoreInterface}
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts
|
|
569
|
+
* import { createDatabaseDefinitionStore } from '@src/core'
|
|
570
|
+
*
|
|
571
|
+
* const store = createDatabaseDefinitionStore() // in-memory by default
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
export declare function createDatabaseDefinitionStore(driver?: DriverInterface): DefinitionStoreInterface;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Build an LLM-callable database tool — create, query, and mutate `@orkestrel/database`
|
|
578
|
+
* databases through one `operation`-discriminated call (AGENTS §14, matching
|
|
579
|
+
* {@link createWorkspaceTool}'s single-tool-many-operations shape).
|
|
580
|
+
*
|
|
581
|
+
* @remarks
|
|
582
|
+
* The universal tool-handler contract (AGENTS §14): validates the call args against
|
|
583
|
+
* {@link import('./shapers.js').databaseToolShape}, dispatches to the matching operation, and
|
|
584
|
+
* RETURNS a plain result on success. A database is resolved lazily and cached for the tool's
|
|
585
|
+
* lifetime — `'create'` mints one from `tables` ({@link import('./helpers.js').expandTables}) and
|
|
586
|
+
* a registered `driver` key ({@link import('./types.js').DatabaseToolOptions.drivers}, default
|
|
587
|
+
* `{ memory: () => createMemoryDriver() }`); any other operation addressing an uncached id falls
|
|
588
|
+
* back to {@link import('./types.js').DatabaseToolOptions.store} (an unknown id throws a typed
|
|
589
|
+
* `TOOL` {@link import('./errors.js').AgentToolError}). When a `store` is configured, `'create'`
|
|
590
|
+
* persists the new {@link import('./types.js').DatabaseDefinition} and `'destroy'` deletes it.
|
|
591
|
+
*
|
|
592
|
+
* `'migrate'` re-declares a LIVE handle's tables via `DatabaseInterface.import` (the SAME driver
|
|
593
|
+
* and storage, a NEW typed view) and calls its `migrate` against the OLD deployed schema —
|
|
594
|
+
* derived from the handle's OWN `export()` (via {@link import('./helpers.js').tableSchema}), so it
|
|
595
|
+
* works for any handle, config-tracked or caller-supplied via
|
|
596
|
+
* {@link import('./types.js').DatabaseToolOptions.databases}. `'records'` clamps its `criteria` to
|
|
597
|
+
* {@link import('./types.js').DatabaseToolOptions.limit} (default
|
|
598
|
+
* {@link import('./constants.js').DATABASE_TOOL_LIMIT}) via
|
|
599
|
+
* {@link import('./helpers.js').clampCriteria}, reporting `truncated` when storage held more rows
|
|
600
|
+
* than the cap. Every operation's `criteria` is normalized via
|
|
601
|
+
* {@link import('./helpers.js').criteriaOf} (defaults an omitted condition `connector` to `'and'`).
|
|
602
|
+
* When {@link import('./types.js').DatabaseToolOptions.readonly} is `true`, every mutating
|
|
603
|
+
* operation throws a typed `TOOL` `AgentToolError` before doing anything. When
|
|
604
|
+
* {@link import('./types.js').DatabaseToolOptions.timeout} is set, every `@orkestrel/database` call
|
|
605
|
+
* this tool makes is given a fresh `AbortSignal.timeout(timeout)`. A typed `@orkestrel/database`
|
|
606
|
+
* failure (`DatabaseError`) re-surfaces as a typed `DATABASE` `AgentToolError` carrying the
|
|
607
|
+
* original {@link import('@orkestrel/database').DatabaseErrorCode} in `context.code`
|
|
608
|
+
* ({@link import('./helpers.js').databaseToolCode}); an `AgentToolError` thrown by this tool's own
|
|
609
|
+
* guards passes through unwrapped.
|
|
610
|
+
*
|
|
611
|
+
* A lazily re-minted database over the DEFAULT in-memory driver yields an EMPTY database — only
|
|
612
|
+
* the {@link import('./types.js').DatabaseDefinition} schema persists in `store`, never rows;
|
|
613
|
+
* durable rows need a persistent driver factory registered in
|
|
614
|
+
* {@link import('./types.js').DatabaseToolOptions.drivers}. `'destroy'` closes whatever handle is
|
|
615
|
+
* cached for the id, including an embedder-supplied
|
|
616
|
+
* {@link import('./types.js').DatabaseToolOptions.databases} handle — the embedder relinquishes
|
|
617
|
+
* that handle's lifecycle to this tool for any id it wires in. This tool assumes the
|
|
618
|
+
* single-writer, non-reentrant model `@orkestrel/database` itself assumes — concurrent calls
|
|
619
|
+
* against one id are NOT serialized by this tool. `'get'` is uncapped by
|
|
620
|
+
* {@link import('./types.js').DatabaseToolOptions.limit} (bounded only by the caller's `key` array
|
|
621
|
+
* size), unlike `'records'` / `'find'` / `'links'`.
|
|
622
|
+
*
|
|
623
|
+
* @param options - The tool's configuration (see {@link import('./types.js').DatabaseToolOptions})
|
|
624
|
+
* @returns A `ToolInterface` (named {@link import('./constants.js').DATABASE_TOOL_NAME} by default)
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```ts
|
|
628
|
+
* import { createDatabaseTool } from '@src/core'
|
|
629
|
+
*
|
|
630
|
+
* const tool = createDatabaseTool()
|
|
631
|
+
* await tool.execute({
|
|
632
|
+
* operation: 'create',
|
|
633
|
+
* id: 'shop',
|
|
634
|
+
* tables: { products: { columns: { name: 'string', price: 'number' } } },
|
|
635
|
+
* })
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
export declare function createDatabaseTool(options?: DatabaseToolOptions): ToolInterface;
|
|
639
|
+
|
|
468
640
|
/**
|
|
469
641
|
* Build an LLM-callable tool that returns the FULL `description` of another registered tool by
|
|
470
642
|
* name — the counterpart to the lean `summary` the other tools in this package advertise
|
|
@@ -501,6 +673,22 @@ export declare function createAnswerTool(options: AnswerToolOptions): ToolInterf
|
|
|
501
673
|
*/
|
|
502
674
|
export declare function createDescribeTool(tools: ToolManagerInterface): ToolInterface;
|
|
503
675
|
|
|
676
|
+
/**
|
|
677
|
+
* Create the in-memory {@link DefinitionStoreInterface} — a process-lifetime `Map` of database
|
|
678
|
+
* definitions, the DEFAULT store the upcoming database / relation tools will persist their
|
|
679
|
+
* `DatabaseDefinition` configs through.
|
|
680
|
+
*
|
|
681
|
+
* @returns A {@link DefinitionStoreInterface}
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* import { createMemoryDefinitionStore } from '@src/core'
|
|
686
|
+
*
|
|
687
|
+
* const store = createMemoryDefinitionStore()
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
export declare function createMemoryDefinitionStore(): DefinitionStoreInterface;
|
|
691
|
+
|
|
504
692
|
/**
|
|
505
693
|
* Build an LLM-callable prompt tool — the ASK side of the terminal seam. Asks
|
|
506
694
|
* {@link import('./types.js').PromptToolOptions.to} a question and BLOCKS until it answers,
|
|
@@ -537,6 +725,55 @@ export declare function createDescribeTool(tools: ToolManagerInterface): ToolInt
|
|
|
537
725
|
*/
|
|
538
726
|
export declare function createPromptTool(options: PromptToolOptions): ToolInterface;
|
|
539
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Build an LLM-callable relation tool — traverse and edit `@orkestrel/relation` relationships
|
|
730
|
+
* through one `operation`-discriminated call (AGENTS §14, matching {@link createDatabaseTool}'s
|
|
731
|
+
* single-tool-many-operations shape).
|
|
732
|
+
*
|
|
733
|
+
* @remarks
|
|
734
|
+
* The universal tool-handler contract (AGENTS §14): validates the call args against
|
|
735
|
+
* {@link import('./shapers.js').relationToolShape}, resolves the addressed
|
|
736
|
+
* {@link import('@orkestrel/relation').RelationManagerInterface} — an explicit `manager` field
|
|
737
|
+
* must match a key of {@link import('./types.js').RelationToolOptions.managers}, an OMITTED one
|
|
738
|
+
* resolves to the SOLE registered manager, either miss throwing a typed `TOOL`
|
|
739
|
+
* {@link import('./errors.js').AgentToolError}
|
|
740
|
+
* ({@link import('./helpers.js').relationManagerOf}) — then resolves `model` against it
|
|
741
|
+
* ({@link import('./helpers.js').relationModelOf}, same typed-`TOOL`-on-miss shape), and
|
|
742
|
+
* dispatches to the matched operation, RETURNING a plain result on success.
|
|
743
|
+
*
|
|
744
|
+
* `'load'` / `'find'` expand the call's FLAT dot-path `include` list into a live
|
|
745
|
+
* `@orkestrel/relation` `Include` tree via {@link import('./helpers.js').expandInclude}, capped
|
|
746
|
+
* at {@link import('./types.js').RelationToolOptions.depth} (default
|
|
747
|
+
* {@link import('./constants.js').RELATION_TOOL_DEPTH}) — a path exceeding the cap, or carrying an
|
|
748
|
+
* empty segment, throws a typed `TOOL` error. `'load'` dispatches on whether `key` is an array
|
|
749
|
+
* (positional many-key form, AGENTS §9.2) or a single key. `'find'` and `'links'` clamp their
|
|
750
|
+
* result to {@link import('./types.js').RelationToolOptions.limit} (default
|
|
751
|
+
* {@link import('./constants.js').RELATION_TOOL_LIMIT}) — `'find'` probes one row past the
|
|
752
|
+
* effective limit (mirroring {@link import('./helpers.js').clampCriteria}'s idiom) to report
|
|
753
|
+
* `truncated`; `'links'` (which has no upstream pagination) fetches the FULL linked-key list and
|
|
754
|
+
* slices/truncates it the same way. `'link'` / `'unlink'` write / remove one `through` junction
|
|
755
|
+
* row.
|
|
756
|
+
*
|
|
757
|
+
* A typed `@orkestrel/relation` failure (`RelationError`) re-surfaces as a typed `RELATION`
|
|
758
|
+
* `AgentToolError` carrying the original {@link import('@orkestrel/relation').RelationErrorCode}
|
|
759
|
+
* in `context.code`; a typed `@orkestrel/database` failure underneath it (`DatabaseError`)
|
|
760
|
+
* re-surfaces as a typed `DATABASE` `AgentToolError`, mirroring {@link createDatabaseTool}'s error
|
|
761
|
+
* mapping; an `AgentToolError` thrown by this tool's own guards (malformed args, an unknown
|
|
762
|
+
* manager/model) passes through unwrapped.
|
|
763
|
+
*
|
|
764
|
+
* @param options - The tool's configuration (see {@link import('./types.js').RelationToolOptions})
|
|
765
|
+
* @returns A `ToolInterface` (named {@link import('./constants.js').RELATION_TOOL_NAME} by default)
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```ts
|
|
769
|
+
* import { createRelationTool } from '@src/core'
|
|
770
|
+
*
|
|
771
|
+
* const tool = createRelationTool({ managers: { shop: manager } })
|
|
772
|
+
* await tool.execute({ operation: 'load', model: 'accounts', key: 'acc1', include: ['contacts'] })
|
|
773
|
+
* ```
|
|
774
|
+
*/
|
|
775
|
+
export declare function createRelationTool(options: RelationToolOptions): ToolInterface;
|
|
776
|
+
|
|
540
777
|
/**
|
|
541
778
|
* Wrap a registered tool as a {@link WorkflowFunction} (`@orkestrel/workflow`) — the OPT-IN
|
|
542
779
|
* adapter that lets a `function`-form task run a `@orkestrel/agent` tool BY NAME.
|
|
@@ -712,6 +949,355 @@ export declare function createWorkflowTool(definition: WorkflowDefinition, runne
|
|
|
712
949
|
*/
|
|
713
950
|
export declare function createWorkspaceTool(options?: WorkspaceToolOptions): ToolInterface;
|
|
714
951
|
|
|
952
|
+
/**
|
|
953
|
+
* Normalize the database tool's parsed SERIALIZED criteria into a live `@orkestrel/database`
|
|
954
|
+
* {@link Criteria} — default each condition's OMITTED `connector` to `'and'`.
|
|
955
|
+
*
|
|
956
|
+
* @remarks
|
|
957
|
+
* The wire form ({@link import('./shapers.js').databaseToolShape}) lets a caller drop `connector`
|
|
958
|
+
* on the last condition (it has nothing to join FORWARD to); the compiled `Condition` a live
|
|
959
|
+
* `@orkestrel/database` table call accepts always carries one, so this fills the gap. `order` /
|
|
960
|
+
* `limit` / `offset` pass through unchanged. Pure and total.
|
|
961
|
+
*
|
|
962
|
+
* @param criteria - The parsed criteria (or `undefined`)
|
|
963
|
+
* @returns The equivalent live `Criteria`, or `undefined` when `criteria` is `undefined`
|
|
964
|
+
*/
|
|
965
|
+
export declare function criteriaOf(criteria: Readonly<{
|
|
966
|
+
conditions?: readonly Readonly<{
|
|
967
|
+
column: string;
|
|
968
|
+
operator: Condition['operator'];
|
|
969
|
+
values: readonly unknown[];
|
|
970
|
+
connector?: Connector;
|
|
971
|
+
}>[];
|
|
972
|
+
order?: readonly Readonly<{
|
|
973
|
+
column: string;
|
|
974
|
+
direction: Direction;
|
|
975
|
+
}>[];
|
|
976
|
+
limit?: number;
|
|
977
|
+
offset?: number;
|
|
978
|
+
}> | undefined): Criteria | undefined;
|
|
979
|
+
|
|
980
|
+
/** The SERIALIZED criteria form — conditions, order, and pagination. */
|
|
981
|
+
export declare const criteriaShape: ObjectShape<{
|
|
982
|
+
conditions: OptionalShape<ArrayShape<ObjectShape<{
|
|
983
|
+
column: StringShape;
|
|
984
|
+
operator: LiteralShape<readonly ["equals", "not", "above", "below", "from", "to", "between", "like", "glob", "starts", "ends", "any", "none", "absent", "present"]>;
|
|
985
|
+
values: ArrayShape<JSONShape>;
|
|
986
|
+
connector: OptionalShape<LiteralShape<readonly ["and", "or"]>>;
|
|
987
|
+
}, false>>>;
|
|
988
|
+
order: OptionalShape<ArrayShape<ObjectShape<{
|
|
989
|
+
column: StringShape;
|
|
990
|
+
direction: LiteralShape<readonly ["ascending", "descending"]>;
|
|
991
|
+
}, false>>>;
|
|
992
|
+
limit: OptionalShape<NumberShape>;
|
|
993
|
+
offset: OptionalShape<NumberShape>;
|
|
994
|
+
}, false>;
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* The DESCRIPTION the upcoming database tool will advertise — a multi-line guide that teaches a
|
|
998
|
+
* small model the operation list, the SERIALIZED criteria form, and the {@link import('./types.js').TableSpec}
|
|
999
|
+
* column DSL.
|
|
1000
|
+
*
|
|
1001
|
+
* @remarks
|
|
1002
|
+
* The criteria form is deliberately SERIALIZED (never fluent) — every condition is a flat object
|
|
1003
|
+
* `{ column, operator, values, connector? }` where `values` is ALWAYS an array, even for a
|
|
1004
|
+
* single-value operator (`{ column: 'age', operator: 'from', values: [18] }`), so a small model
|
|
1005
|
+
* never has to chain method calls or guess whether a value is scalar or a list.
|
|
1006
|
+
*/
|
|
1007
|
+
export declare const DATABASE_TOOL_DESCRIPTION: string;
|
|
1008
|
+
|
|
1009
|
+
/** The default cap on rows a `records` / `remove` call returns (or acts on) when the caller omits `criteria.limit` — the upcoming database tool's default row ceiling. */
|
|
1010
|
+
export declare const DATABASE_TOOL_LIMIT = 1000;
|
|
1011
|
+
|
|
1012
|
+
/** The database tool's mutating operations — disabled by `DatabaseToolOptions.readonly`. */
|
|
1013
|
+
export declare const DATABASE_TOOL_MUTATIONS: Set<string>;
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* The name the upcoming `createDatabaseTool` factory will advertise by default — the key a model
|
|
1017
|
+
* calls and the `ToolManagerInterface` (`@orkestrel/agent`) registers under.
|
|
1018
|
+
*
|
|
1019
|
+
* @remarks
|
|
1020
|
+
* SRC-1 of a 3-unit spine: this unit lands the persistence + schema foundation
|
|
1021
|
+
* ({@link import('./types.js').DatabaseDefinition}, {@link import('./types.js').DefinitionStoreInterface},
|
|
1022
|
+
* {@link import('./helpers.js').expandTables}); `createDatabaseTool` itself is built in a later unit.
|
|
1023
|
+
*/
|
|
1024
|
+
export declare const DATABASE_TOOL_NAME = "database";
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* The lean {@link import('@orkestrel/agent').ToolInterface.summary} the upcoming database tool
|
|
1028
|
+
* will advertise in place of {@link DATABASE_TOOL_DESCRIPTION}.
|
|
1029
|
+
*/
|
|
1030
|
+
export declare const DATABASE_TOOL_SUMMARY = "Create and query a database \u2014 one operation per call (create, tables, get, records, count, aggregate, add, set, update, remove, migrate, destroy), chosen by the 'operation' field. Call describe('database') for the full operation list, the criteria form, and the column DSL.";
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* One database's CONFIG-ONLY definition — `id` + `driver` + {@link TableSpec} (+ optional `keys`),
|
|
1034
|
+
* the pure-JSON blueprint the upcoming database / relation tools build a live database from.
|
|
1035
|
+
*
|
|
1036
|
+
* @remarks
|
|
1037
|
+
* A `DatabaseDefinition` is NEVER a live handle — it is the durable, serializable config a
|
|
1038
|
+
* {@link DefinitionStoreInterface} persists and a tool factory turns into a real
|
|
1039
|
+
* `@orkestrel/database` `DatabaseInterface` (via `createDatabase` + {@link import('./helpers.js').expandTables})
|
|
1040
|
+
* on demand. `keys`, when present, maps a table name to its primary-key column (omitted ⇒ the
|
|
1041
|
+
* driver's default primary key).
|
|
1042
|
+
*/
|
|
1043
|
+
export declare interface DatabaseDefinition {
|
|
1044
|
+
readonly id: string;
|
|
1045
|
+
readonly driver: string;
|
|
1046
|
+
readonly tables: TableSpec;
|
|
1047
|
+
readonly keys?: Readonly<Record<string, string>>;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/** One opaque persisted row — the shape a `TableInterface<DatabaseDefinitionRow>`-backed store reads/writes; `definition` is narrowed with {@link import('./helpers.js').isDatabaseDefinition} on read. */
|
|
1051
|
+
export declare interface DatabaseDefinitionRow {
|
|
1052
|
+
readonly id: string;
|
|
1053
|
+
readonly definition: unknown;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* A {@link DefinitionStoreInterface} backed by one table of the `@orkestrel/database` layer — a
|
|
1058
|
+
* database's durable CONFIG state IS a row, so persistence reduces to keyed point-access
|
|
1059
|
+
* (`get` / `set` / `delete`) over a {@link TableInterface}, the driver-pluggable twin of the
|
|
1060
|
+
* plain-`Map` {@link import('./MemoryDefinitionStore.js').MemoryDefinitionStore}.
|
|
1061
|
+
*
|
|
1062
|
+
* @remarks
|
|
1063
|
+
* The store is driver-agnostic: it holds a single {@link TableInterface} whose backend (memory,
|
|
1064
|
+
* JSON, SQLite, IndexedDB) is chosen by whoever builds it (the factories), so a JSON / SQLite /
|
|
1065
|
+
* IndexedDB backend swaps in WITHOUT touching a consumer — the same seam as
|
|
1066
|
+
* {@link import('./MemoryDefinitionStore.js').MemoryDefinitionStore}. The driver defaults to
|
|
1067
|
+
* memory ({@link import('../factories.js').createDatabaseDefinitionStore} passes
|
|
1068
|
+
* `createMemoryDriver()`), so it ALSO works in memory out of the box; you opt into the durable
|
|
1069
|
+
* plumbing by passing a JSON / SQLite / IndexedDB driver.
|
|
1070
|
+
*
|
|
1071
|
+
* The {@link DatabaseDefinition} is stored as ONE OPAQUE JSON COLUMN — the table is a row of
|
|
1072
|
+
* `{ id; definition }` ({@link DatabaseDefinitionRow}). The definition is already a COMPLETE,
|
|
1073
|
+
* self-contained, pure-JSON CONFIG payload (never a live handle), so storing it whole is lossless
|
|
1074
|
+
* AND keeps the row type flat (`definition` reads back as `unknown`).
|
|
1075
|
+
*
|
|
1076
|
+
* - **`set(definition)` upserts under the definition's OWN `id`** (no separate id param) — it
|
|
1077
|
+
* writes the row `{ id: definition.id, definition }`.
|
|
1078
|
+
* - **`get(id)` resolves the stored definition for an id**, narrowing the opaque JSON column back
|
|
1079
|
+
* to a {@link DatabaseDefinition} ({@link import('../helpers.js').isDatabaseDefinition} — the
|
|
1080
|
+
* AGENTS §14 boundary narrow for an untrusted storage read), or `undefined` if none is stored
|
|
1081
|
+
* or the stored blob is malformed.
|
|
1082
|
+
* - **`delete(id)` drops a definition by id**; an absent id is a no-op (no throw).
|
|
1083
|
+
*
|
|
1084
|
+
* The public surface is EXACTLY `get` / `set` / `delete` — no extra members (the §22 method
|
|
1085
|
+
* bijection with {@link DefinitionStoreInterface}).
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```ts
|
|
1089
|
+
* import { createDatabaseDefinitionStore, createMemoryDriver } from '@src/core'
|
|
1090
|
+
*
|
|
1091
|
+
* const store = createDatabaseDefinitionStore(createMemoryDriver()) // a durable driver swaps in here
|
|
1092
|
+
* await store.set({ id: 'shop', driver: 'memory', tables: {} }) // persist the config (one JSON column)
|
|
1093
|
+
* const definition = await store.get('shop')
|
|
1094
|
+
* await store.delete('shop')
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
export declare class DatabaseDefinitionStore implements DefinitionStoreInterface {
|
|
1098
|
+
#private;
|
|
1099
|
+
/**
|
|
1100
|
+
* Wrap a table as a definition store.
|
|
1101
|
+
*
|
|
1102
|
+
* @param table - The {@link TableInterface} holding the definitions — its row is the
|
|
1103
|
+
* {@link DatabaseDefinitionRow} `{ id; definition }` shape (the definition one opaque JSON column)
|
|
1104
|
+
*/
|
|
1105
|
+
constructor(table: TableInterface<DatabaseDefinitionRow>);
|
|
1106
|
+
/** Resolve the persisted definition for `id`, narrowing the opaque JSON column back to a `DatabaseDefinition`. */
|
|
1107
|
+
get(id: string): Promise<DatabaseDefinition | undefined>;
|
|
1108
|
+
/** Insert or replace under the definition's OWN `id` (no separate id param) — the row is `{ id, definition }`. */
|
|
1109
|
+
set(definition: DatabaseDefinition): Promise<void>;
|
|
1110
|
+
/** Drop a definition by id; an absent id is a no-op (no throw). */
|
|
1111
|
+
delete(id: string): Promise<void>;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Map a caught error to the {@link AgentToolErrorCode} the upcoming database tool should throw
|
|
1116
|
+
* with — the pure classification step of that factory's error handling, mirroring
|
|
1117
|
+
* {@link terminalToolCode}'s idiom for `@orkestrel/database`.
|
|
1118
|
+
*
|
|
1119
|
+
* @param error - The value caught from a `@orkestrel/database` table operation
|
|
1120
|
+
* @returns The granular {@link DatabaseErrorCode}, or `undefined` if `error` is not a `DatabaseError`
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function databaseToolCode(error: unknown): DatabaseErrorCode | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for {@link import('./factories.js').createDatabaseTool} — SRC-2 of the 3-unit database
|
|
1126
|
+
* / relation spine, built over the SRC-1 foundation ({@link DatabaseDefinition},
|
|
1127
|
+
* {@link DefinitionStoreInterface}, {@link import('./helpers.js').expandTables}).
|
|
1128
|
+
*
|
|
1129
|
+
* @remarks
|
|
1130
|
+
* - `databases` — live `DatabaseInterface` handles to seed the tool's cache with (e.g. a
|
|
1131
|
+
* caller-constructed database it should manage alongside store-backed ones); keyed by the id a
|
|
1132
|
+
* call's `id` field addresses.
|
|
1133
|
+
* - `store` — the {@link DefinitionStoreInterface} the `'create'` / `'migrate'` operations persist
|
|
1134
|
+
* their {@link DatabaseDefinition} CONFIG through, and `'destroy'` deletes from; also the source
|
|
1135
|
+
* `'get'`/every other operation resolves an id from when it isn't already cached. Omitted means
|
|
1136
|
+
* no persistence — a database created without a store lives only for the tool's lifetime.
|
|
1137
|
+
* - `drivers` — registry of driver-name to `() => DriverInterface` factories a `'create'` call's
|
|
1138
|
+
* `driver` field (or a persisted definition's `driver`) resolves against. Defaults to
|
|
1139
|
+
* `{ memory: () => createMemoryDriver() }` (`@orkestrel/database`).
|
|
1140
|
+
* - `key` — the `KeyFunction` (`@orkestrel/database`) every minted database is constructed with,
|
|
1141
|
+
* used when a written row lacks its primary key. Defaults to `generateUUID`.
|
|
1142
|
+
* - `limit` — the row cap `'records'` / `'remove'` — via {@link import('./helpers.js').clampCriteria}
|
|
1143
|
+
* — enforce when a call's `criteria.limit` is omitted or exceeds it. Defaults to
|
|
1144
|
+
* {@link import('./constants.js').DATABASE_TOOL_LIMIT}.
|
|
1145
|
+
* - `timeout` — milliseconds; when set, every `@orkestrel/database` call this tool makes is given
|
|
1146
|
+
* a fresh `AbortSignal.timeout(timeout)` per tool call.
|
|
1147
|
+
* - `readonly` — when `true`, every mutating operation (`'create'` / `'add'` / `'set'` /
|
|
1148
|
+
* `'update'` / `'remove'` / `'migrate'` / `'destroy'`) throws a typed `TOOL`
|
|
1149
|
+
* {@link import('./errors.js').AgentToolError} before doing anything.
|
|
1150
|
+
* - `name` / `description` — advertised tool overrides; default to
|
|
1151
|
+
* {@link import('./constants.js').DATABASE_TOOL_NAME} / {@link import('./constants.js').DATABASE_TOOL_DESCRIPTION}.
|
|
1152
|
+
*/
|
|
1153
|
+
export declare interface DatabaseToolOptions {
|
|
1154
|
+
readonly name?: string;
|
|
1155
|
+
readonly description?: string;
|
|
1156
|
+
readonly databases?: Readonly<Record<string, DatabaseInterface>>;
|
|
1157
|
+
readonly store?: DefinitionStoreInterface;
|
|
1158
|
+
readonly drivers?: Readonly<Record<string, () => DriverInterface>>;
|
|
1159
|
+
readonly key?: KeyFunction;
|
|
1160
|
+
readonly limit?: number;
|
|
1161
|
+
readonly timeout?: number;
|
|
1162
|
+
readonly readonly?: boolean;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* The shape of {@link import('./factories.js').createDatabaseTool}'s call arguments —
|
|
1167
|
+
* discriminated by `operation` into the 12 database operations (`'create'` / `'tables'` /
|
|
1168
|
+
* `'get'` / `'records'` / `'count'` / `'aggregate'` / `'add'` / `'set'` / `'update'` /
|
|
1169
|
+
* `'remove'` / `'migrate'` / `'destroy'`).
|
|
1170
|
+
*
|
|
1171
|
+
* @remarks
|
|
1172
|
+
* Every arm carries `id` (the database id). `'create'` / `'migrate'` carry `tables` (the
|
|
1173
|
+
* {@link import('./types.js').TableSpec} column DSL, compiled via
|
|
1174
|
+
* {@link import('./helpers.js').expandTables}); `'get'` / `'update'` / `'remove'` carry `key`
|
|
1175
|
+
* (one key or an array of keys, positional); `'add'` / `'set'` carry `row` (one row or an array of
|
|
1176
|
+
* rows); `'update'` also carries `changes` (a loose partial row); `'records'` / `'count'` /
|
|
1177
|
+
* `'aggregate'` carry an optional `criteria` (the SERIALIZED form — `values` is ALWAYS an array,
|
|
1178
|
+
* even for a single-value operator, so a caller never chains method calls or guesses arity).
|
|
1179
|
+
*/
|
|
1180
|
+
export declare const databaseToolShape: UnionShape<[ ObjectShape<{
|
|
1181
|
+
operation: LiteralShape<readonly ["create"]>;
|
|
1182
|
+
id: StringShape;
|
|
1183
|
+
tables: ObjectShape<Record<never, never>, ObjectShape<{
|
|
1184
|
+
columns: ObjectShape<Record<never, never>, UnionShape<[ LiteralShape<readonly ["string", "integer", "number", "boolean"]>, ObjectShape<{
|
|
1185
|
+
type: LiteralShape<readonly ["string", "integer", "number", "boolean"]>;
|
|
1186
|
+
optional: OptionalShape<BooleanShape>;
|
|
1187
|
+
}, false>]>>;
|
|
1188
|
+
}, false>>;
|
|
1189
|
+
driver: OptionalShape<StringShape>;
|
|
1190
|
+
keys: OptionalShape<ObjectShape<Record<never, never>, StringShape>>;
|
|
1191
|
+
}, false>, ObjectShape<{
|
|
1192
|
+
operation: LiteralShape<readonly ["tables"]>;
|
|
1193
|
+
id: StringShape;
|
|
1194
|
+
}, false>, ObjectShape<{
|
|
1195
|
+
operation: LiteralShape<readonly ["get"]>;
|
|
1196
|
+
id: StringShape;
|
|
1197
|
+
table: StringShape;
|
|
1198
|
+
key: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1199
|
+
}, false>, ObjectShape<{
|
|
1200
|
+
operation: LiteralShape<readonly ["records"]>;
|
|
1201
|
+
id: StringShape;
|
|
1202
|
+
table: StringShape;
|
|
1203
|
+
criteria: OptionalShape<ObjectShape<{
|
|
1204
|
+
conditions: OptionalShape<ArrayShape<ObjectShape<{
|
|
1205
|
+
column: StringShape;
|
|
1206
|
+
operator: LiteralShape<readonly ["equals", "not", "above", "below", "from", "to", "between", "like", "glob", "starts", "ends", "any", "none", "absent", "present"]>;
|
|
1207
|
+
values: ArrayShape<JSONShape>;
|
|
1208
|
+
connector: OptionalShape<LiteralShape<readonly ["and", "or"]>>;
|
|
1209
|
+
}, false>>>;
|
|
1210
|
+
order: OptionalShape<ArrayShape<ObjectShape<{
|
|
1211
|
+
column: StringShape;
|
|
1212
|
+
direction: LiteralShape<readonly ["ascending", "descending"]>;
|
|
1213
|
+
}, false>>>;
|
|
1214
|
+
limit: OptionalShape<NumberShape>;
|
|
1215
|
+
offset: OptionalShape<NumberShape>;
|
|
1216
|
+
}, false>>;
|
|
1217
|
+
}, false>, ObjectShape<{
|
|
1218
|
+
operation: LiteralShape<readonly ["count"]>;
|
|
1219
|
+
id: StringShape;
|
|
1220
|
+
table: StringShape;
|
|
1221
|
+
criteria: OptionalShape<ObjectShape<{
|
|
1222
|
+
conditions: OptionalShape<ArrayShape<ObjectShape<{
|
|
1223
|
+
column: StringShape;
|
|
1224
|
+
operator: LiteralShape<readonly ["equals", "not", "above", "below", "from", "to", "between", "like", "glob", "starts", "ends", "any", "none", "absent", "present"]>;
|
|
1225
|
+
values: ArrayShape<JSONShape>;
|
|
1226
|
+
connector: OptionalShape<LiteralShape<readonly ["and", "or"]>>;
|
|
1227
|
+
}, false>>>;
|
|
1228
|
+
order: OptionalShape<ArrayShape<ObjectShape<{
|
|
1229
|
+
column: StringShape;
|
|
1230
|
+
direction: LiteralShape<readonly ["ascending", "descending"]>;
|
|
1231
|
+
}, false>>>;
|
|
1232
|
+
limit: OptionalShape<NumberShape>;
|
|
1233
|
+
offset: OptionalShape<NumberShape>;
|
|
1234
|
+
}, false>>;
|
|
1235
|
+
}, false>, ObjectShape<{
|
|
1236
|
+
operation: LiteralShape<readonly ["aggregate"]>;
|
|
1237
|
+
id: StringShape;
|
|
1238
|
+
table: StringShape;
|
|
1239
|
+
function: LiteralShape<readonly ["count", "sum", "average", "minimum", "maximum"]>;
|
|
1240
|
+
column: StringShape;
|
|
1241
|
+
criteria: OptionalShape<ObjectShape<{
|
|
1242
|
+
conditions: OptionalShape<ArrayShape<ObjectShape<{
|
|
1243
|
+
column: StringShape;
|
|
1244
|
+
operator: LiteralShape<readonly ["equals", "not", "above", "below", "from", "to", "between", "like", "glob", "starts", "ends", "any", "none", "absent", "present"]>;
|
|
1245
|
+
values: ArrayShape<JSONShape>;
|
|
1246
|
+
connector: OptionalShape<LiteralShape<readonly ["and", "or"]>>;
|
|
1247
|
+
}, false>>>;
|
|
1248
|
+
order: OptionalShape<ArrayShape<ObjectShape<{
|
|
1249
|
+
column: StringShape;
|
|
1250
|
+
direction: LiteralShape<readonly ["ascending", "descending"]>;
|
|
1251
|
+
}, false>>>;
|
|
1252
|
+
limit: OptionalShape<NumberShape>;
|
|
1253
|
+
offset: OptionalShape<NumberShape>;
|
|
1254
|
+
}, false>>;
|
|
1255
|
+
}, false>, ObjectShape<{
|
|
1256
|
+
operation: LiteralShape<readonly ["add"]>;
|
|
1257
|
+
id: StringShape;
|
|
1258
|
+
table: StringShape;
|
|
1259
|
+
row: UnionShape<[ ArrayShape<ObjectShape<Record<never, never>, JSONShape>>, ObjectShape<Record<never, never>, JSONShape>]>;
|
|
1260
|
+
}, false>, ObjectShape<{
|
|
1261
|
+
operation: LiteralShape<readonly ["set"]>;
|
|
1262
|
+
id: StringShape;
|
|
1263
|
+
table: StringShape;
|
|
1264
|
+
row: UnionShape<[ ArrayShape<ObjectShape<Record<never, never>, JSONShape>>, ObjectShape<Record<never, never>, JSONShape>]>;
|
|
1265
|
+
}, false>, ObjectShape<{
|
|
1266
|
+
operation: LiteralShape<readonly ["update"]>;
|
|
1267
|
+
id: StringShape;
|
|
1268
|
+
table: StringShape;
|
|
1269
|
+
key: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1270
|
+
changes: ObjectShape<Record<never, never>, JSONShape>;
|
|
1271
|
+
}, false>, ObjectShape<{
|
|
1272
|
+
operation: LiteralShape<readonly ["remove"]>;
|
|
1273
|
+
id: StringShape;
|
|
1274
|
+
table: StringShape;
|
|
1275
|
+
key: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1276
|
+
}, false>, ObjectShape<{
|
|
1277
|
+
operation: LiteralShape<readonly ["migrate"]>;
|
|
1278
|
+
id: StringShape;
|
|
1279
|
+
tables: ObjectShape<Record<never, never>, ObjectShape<{
|
|
1280
|
+
columns: ObjectShape<Record<never, never>, UnionShape<[ LiteralShape<readonly ["string", "integer", "number", "boolean"]>, ObjectShape<{
|
|
1281
|
+
type: LiteralShape<readonly ["string", "integer", "number", "boolean"]>;
|
|
1282
|
+
optional: OptionalShape<BooleanShape>;
|
|
1283
|
+
}, false>]>>;
|
|
1284
|
+
}, false>>;
|
|
1285
|
+
}, false>, ObjectShape<{
|
|
1286
|
+
operation: LiteralShape<readonly ["destroy"]>;
|
|
1287
|
+
id: StringShape;
|
|
1288
|
+
}, false>]>;
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* The point-access persistence seam (AGENTS §5 — Stores) for {@link DatabaseDefinition} configs —
|
|
1292
|
+
* the twin of `@orkestrel/terminal`'s `TerminalStoreInterface`, storing a database's CONFIG-ONLY
|
|
1293
|
+
* blueprint (never a live handle). Every primitive is async; `delete` of an absent id is a no-op.
|
|
1294
|
+
*/
|
|
1295
|
+
export declare interface DefinitionStoreInterface {
|
|
1296
|
+
get(id: string): Promise<DatabaseDefinition | undefined>;
|
|
1297
|
+
set(definition: DatabaseDefinition): Promise<void>;
|
|
1298
|
+
delete(id: string): Promise<void>;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
715
1301
|
/**
|
|
716
1302
|
* The DESCRIPTION {@link import('./factories.js').createDescribeTool} advertises.
|
|
717
1303
|
*
|
|
@@ -761,7 +1347,33 @@ export declare interface DescribeToolArguments {
|
|
|
761
1347
|
*/
|
|
762
1348
|
export declare const describeToolShape: ObjectShape<{
|
|
763
1349
|
name: StringShape;
|
|
764
|
-
}>;
|
|
1350
|
+
}, false>;
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Expand the relation tool's FLAT dot-path `include` list into a live `@orkestrel/relation`
|
|
1354
|
+
* {@link Include} tree — the pure leaf {@link import('./factories.js').createRelationTool} calls
|
|
1355
|
+
* before a `'load'` / `'find'` call.
|
|
1356
|
+
*
|
|
1357
|
+
* @remarks
|
|
1358
|
+
* Each path splits on `'.'` into a chain of relation names, deep-merged into one nested
|
|
1359
|
+
* `Include` object with a leaf `true`. A longer path SUBSUMES a shorter sibling's bare `true` —
|
|
1360
|
+
* `'contacts'` followed by `'contacts.account'` yields `{ contacts: { account: true } }`, never
|
|
1361
|
+
* overwriting the deeper chain. An EMPTY segment (`''`, from a leading/trailing/doubled `.`) or a
|
|
1362
|
+
* path whose segment count exceeds `depth` throws a typed `TOOL` {@link AgentToolError}.
|
|
1363
|
+
*
|
|
1364
|
+
* @param paths - The flat dot-path `include` list (or `undefined` — yields `{}`)
|
|
1365
|
+
* @param depth - The max segment count a single path may reach
|
|
1366
|
+
* @returns The equivalent nested {@link Include}
|
|
1367
|
+
*
|
|
1368
|
+
* @example
|
|
1369
|
+
* ```ts
|
|
1370
|
+
* import { expandInclude } from '@src/core'
|
|
1371
|
+
*
|
|
1372
|
+
* expandInclude(['contacts', 'contacts.account'], 3)
|
|
1373
|
+
* // { contacts: { account: true } }
|
|
1374
|
+
* ```
|
|
1375
|
+
*/
|
|
1376
|
+
export declare function expandInclude(paths: readonly string[] | undefined, depth: number): Include;
|
|
765
1377
|
|
|
766
1378
|
/**
|
|
767
1379
|
* Expand a flat {@link WorkflowSteps} blob into a strict {@link WorkflowDefinition} — each step
|
|
@@ -782,6 +1394,20 @@ export declare const describeToolShape: ObjectShape<{
|
|
|
782
1394
|
*/
|
|
783
1395
|
export declare function expandSteps(flat: WorkflowSteps): WorkflowDefinition;
|
|
784
1396
|
|
|
1397
|
+
/**
|
|
1398
|
+
* Compile a {@link TableSpec} into the `@orkestrel/database` {@link TablesShape} it configures —
|
|
1399
|
+
* each {@link ColumnSpec} maps to the matching primitive shaper (`'string'` → `stringShape()`,
|
|
1400
|
+
* `'integer'` → `integerShape()`, `'number'` → `numberShape()`, `'boolean'` → `booleanShape()`),
|
|
1401
|
+
* wrapped in `optionalShape` when the column declares `optional: true`. Total, pure.
|
|
1402
|
+
*
|
|
1403
|
+
* @param spec - The small-model-facing table layout
|
|
1404
|
+
* @returns The compiled `TablesShape` a `@orkestrel/database` `createDatabase` call accepts
|
|
1405
|
+
*/
|
|
1406
|
+
export declare function expandTables(spec: TableSpec): TablesShape;
|
|
1407
|
+
|
|
1408
|
+
/** Flat dot-path relation include list, expanded via {@link import('./helpers.js').expandInclude}. */
|
|
1409
|
+
export declare const includeShape: OptionalShape<ArrayShape<StringShape>>;
|
|
1410
|
+
|
|
785
1411
|
/**
|
|
786
1412
|
* Type guard narrowing an unknown caught value to an {@link AgentToolError}.
|
|
787
1413
|
*
|
|
@@ -801,6 +1427,29 @@ export declare function expandSteps(flat: WorkflowSteps): WorkflowDefinition;
|
|
|
801
1427
|
*/
|
|
802
1428
|
export declare function isAgentToolError(value: unknown): value is AgentToolError;
|
|
803
1429
|
|
|
1430
|
+
/** Narrow an unknown value to a {@link import('./types.js').ColumnKind}. */
|
|
1431
|
+
export declare function isColumnKind(value: unknown): value is ColumnKind;
|
|
1432
|
+
|
|
1433
|
+
/** Narrow an unknown value to a {@link ColumnSpec} — a valid {@link import('./types.js').ColumnKind} shorthand, or `{ type, optional }` with a valid `type`. */
|
|
1434
|
+
export declare function isColumnSpec(value: unknown): value is ColumnSpec;
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Narrow an unknown value to a {@link DatabaseDefinition} — a non-empty `id` + `driver`, a
|
|
1438
|
+
* `tables` record whose every value is `{ columns: record of valid ColumnSpec }`, and an optional
|
|
1439
|
+
* `keys` record of strings. The boundary guard a {@link import('./types.js').DefinitionStoreInterface}
|
|
1440
|
+
* applies to an untrusted persisted blob before trusting it as a definition (never an `as`).
|
|
1441
|
+
*/
|
|
1442
|
+
export declare function isDatabaseDefinition(value: unknown): value is DatabaseDefinition;
|
|
1443
|
+
|
|
1444
|
+
/** One key value — a string or number; the array form (multiple keys, positional) resolves FIRST per AGENTS §9.2. */
|
|
1445
|
+
export declare const keyShape: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1446
|
+
|
|
1447
|
+
/** Map one {@link import('./types.js').ColumnKind} to its primitive `@orkestrel/database` shape — the leaf {@link columnShape} wraps. */
|
|
1448
|
+
export declare function kindShape(kind: ColumnKind): ContractShape;
|
|
1449
|
+
|
|
1450
|
+
/** Which registered relation manager to address — omitted resolves to the sole registered manager. */
|
|
1451
|
+
export declare const managerShape: OptionalShape<StringShape>;
|
|
1452
|
+
|
|
804
1453
|
/**
|
|
805
1454
|
* The maximum nesting depth a workflow → agent → workflow chain may reach — the bound
|
|
806
1455
|
* {@link import('./factories.js').createAgentFunction} and
|
|
@@ -815,6 +1464,51 @@ export declare function isAgentToolError(value: unknown): value is AgentToolErro
|
|
|
815
1464
|
*/
|
|
816
1465
|
export declare const MAX_WORKFLOW_DEPTH = 8;
|
|
817
1466
|
|
|
1467
|
+
/**
|
|
1468
|
+
* The in-memory {@link DefinitionStoreInterface} — a process-lifetime `Map` of
|
|
1469
|
+
* {@link DatabaseDefinition}s keyed by database id, the DEFAULT store
|
|
1470
|
+
* {@link import('../factories.js').createMemoryDefinitionStore} builds. The EXACT twin of
|
|
1471
|
+
* {@link import('./DatabaseDefinitionStore.js').DatabaseDefinitionStore}.
|
|
1472
|
+
*
|
|
1473
|
+
* @remarks
|
|
1474
|
+
* A plain `Map<string, DatabaseDefinition>` (AGENTS §21 — the definition is already pure,
|
|
1475
|
+
* self-contained CONFIG-only JSON, so no encoding is needed for the memory tier). There is NO
|
|
1476
|
+
* idle-TTL and NO eviction: a persisted definition lives until an explicit `delete`. A durable
|
|
1477
|
+
* backend (JSON / SQLite / IndexedDB) swaps in through the SAME interface without touching a
|
|
1478
|
+
* consumer — its driver-pluggable twin is
|
|
1479
|
+
* {@link import('./DatabaseDefinitionStore.js').DatabaseDefinitionStore} (the definition as one
|
|
1480
|
+
* opaque JSON column).
|
|
1481
|
+
*
|
|
1482
|
+
* - **`get` resolves the persisted definition for an id**, or `undefined` if none is stored.
|
|
1483
|
+
* - **`set` inserts / replaces under the definition's OWN `id`** (no separate id param).
|
|
1484
|
+
* - **`delete` drops a definition by id**; an absent id is a no-op (no throw).
|
|
1485
|
+
*
|
|
1486
|
+
* The public surface is EXACTLY `get` / `set` / `delete` — no extra members (the §22 method
|
|
1487
|
+
* bijection with {@link DefinitionStoreInterface}).
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* ```ts
|
|
1491
|
+
* import { createMemoryDefinitionStore } from '@src/core'
|
|
1492
|
+
*
|
|
1493
|
+
* const store = createMemoryDefinitionStore()
|
|
1494
|
+
* await store.set({ id: 'shop', driver: 'memory', tables: {} })
|
|
1495
|
+
* const definition = await store.get('shop')
|
|
1496
|
+
* await store.delete('shop')
|
|
1497
|
+
* ```
|
|
1498
|
+
*/
|
|
1499
|
+
export declare class MemoryDefinitionStore implements DefinitionStoreInterface {
|
|
1500
|
+
#private;
|
|
1501
|
+
get(id: string): Promise<DatabaseDefinition | undefined>;
|
|
1502
|
+
set(definition: DatabaseDefinition): Promise<void>;
|
|
1503
|
+
delete(id: string): Promise<void>;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
/** One sort term. */
|
|
1507
|
+
export declare const orderShape: ObjectShape<{
|
|
1508
|
+
column: StringShape;
|
|
1509
|
+
direction: LiteralShape<readonly ["ascending", "descending"]>;
|
|
1510
|
+
}, false>;
|
|
1511
|
+
|
|
818
1512
|
/** A draft phase — a `PhaseDefinition` (`@orkestrel/workflow`) with OPTIONAL `id` / `name` and {@link TaskDraft} tasks. */
|
|
819
1513
|
export declare interface PhaseDraft {
|
|
820
1514
|
readonly id?: string;
|
|
@@ -842,10 +1536,10 @@ export declare const phaseDraftShape: ObjectShape<{
|
|
|
842
1536
|
run: OptionalShape<StringShape>;
|
|
843
1537
|
retries: OptionalShape<NumberShape>;
|
|
844
1538
|
timeout: OptionalShape<NumberShape>;
|
|
845
|
-
}>>;
|
|
1539
|
+
}, false>>;
|
|
846
1540
|
concurrency: OptionalShape<NumberShape>;
|
|
847
1541
|
bail: OptionalShape<LiteralShape<readonly [true, false]>>;
|
|
848
|
-
}>;
|
|
1542
|
+
}, false>;
|
|
849
1543
|
|
|
850
1544
|
export declare const PROMPT_TOOL_DESCRIPTION: string;
|
|
851
1545
|
|
|
@@ -912,7 +1606,7 @@ export declare const promptToolShape: ObjectShape<{
|
|
|
912
1606
|
name: StringShape;
|
|
913
1607
|
value: StringShape;
|
|
914
1608
|
description: OptionalShape<StringShape>;
|
|
915
|
-
}>>>;
|
|
1609
|
+
}, boolean | ContractShape>>>;
|
|
916
1610
|
mask: OptionalShape<StringShape>;
|
|
917
1611
|
min: OptionalShape<NumberShape>;
|
|
918
1612
|
max: OptionalShape<NumberShape>;
|
|
@@ -926,9 +1620,160 @@ export declare const promptToolShape: ObjectShape<{
|
|
|
926
1620
|
numeric: OptionalShape<BooleanShape>;
|
|
927
1621
|
integer: OptionalShape<BooleanShape>;
|
|
928
1622
|
alphanumeric: OptionalShape<BooleanShape>;
|
|
929
|
-
}>>;
|
|
1623
|
+
}, boolean | ContractShape>>;
|
|
930
1624
|
timeout: OptionalShape<NumberShape>;
|
|
931
|
-
}>;
|
|
1625
|
+
}, false>;
|
|
1626
|
+
|
|
1627
|
+
/** The default cap on how many `include` path segments deep a `load` / `find` call may traverse — the relation tool's default include-depth ceiling. */
|
|
1628
|
+
export declare const RELATION_TOOL_DEPTH = 3;
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* The DESCRIPTION the relation tool advertises — a multi-line guide that teaches a small model
|
|
1632
|
+
* the operation list and the flat dot-path `include` syntax.
|
|
1633
|
+
*
|
|
1634
|
+
* @remarks
|
|
1635
|
+
* An include path is a FLAT dot-separated string (`'contacts.account'`), never a nested object —
|
|
1636
|
+
* the same small-model ergonomic lever the other tools in this package use for flat args.
|
|
1637
|
+
*/
|
|
1638
|
+
export declare const RELATION_TOOL_DESCRIPTION: string;
|
|
1639
|
+
|
|
1640
|
+
/** The default cap on rows a `find` / `links` call returns when the caller omits `limit` — the relation tool's default row ceiling. */
|
|
1641
|
+
export declare const RELATION_TOOL_LIMIT = 1000;
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* The name `createRelationTool` advertises by default — the key a model calls and the
|
|
1645
|
+
* `ToolManagerInterface` (`@orkestrel/agent`) registers under.
|
|
1646
|
+
*/
|
|
1647
|
+
export declare const RELATION_TOOL_NAME = "relation";
|
|
1648
|
+
|
|
1649
|
+
/**
|
|
1650
|
+
* The lean {@link import('@orkestrel/agent').ToolInterface.summary} the relation tool advertises
|
|
1651
|
+
* in place of {@link RELATION_TOOL_DESCRIPTION}.
|
|
1652
|
+
*/
|
|
1653
|
+
export declare const RELATION_TOOL_SUMMARY = "Traverse and edit relationships between database rows \u2014 one operation per call (load, find, link, unlink, links), chosen by the 'operation' field. Call describe('relation') for the include-path syntax.";
|
|
1654
|
+
|
|
1655
|
+
/** One key value — a string or number; the array form (multiple keys, positional) resolves FIRST per AGENTS §9.2. */
|
|
1656
|
+
export declare const relationKeyShape: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Resolve which registered {@link RelationManagerInterface} a relation-tool call addresses — the
|
|
1660
|
+
* pure manager-resolution leaf {@link import('./factories.js').createRelationTool} calls on
|
|
1661
|
+
* every operation.
|
|
1662
|
+
*
|
|
1663
|
+
* @remarks
|
|
1664
|
+
* An explicit `name` must match a key of `managers` (a miss throws a typed `TOOL`
|
|
1665
|
+
* {@link AgentToolError} naming the registered managers). An OMITTED `name` resolves to the sole
|
|
1666
|
+
* registered manager when exactly one is registered, else throws the same typed error.
|
|
1667
|
+
*
|
|
1668
|
+
* @param managers - The tool's registered `RelationManagerInterface` map
|
|
1669
|
+
* @param name - The call's optional `manager` field
|
|
1670
|
+
* @returns The resolved {@link RelationManagerInterface}
|
|
1671
|
+
*/
|
|
1672
|
+
export declare function relationManagerOf(managers: Readonly<Record<string, RelationManagerInterface>>, name: string | undefined): RelationManagerInterface;
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Resolve a `model` name against a live {@link RelationManagerInterface} — the pure model-lookup
|
|
1676
|
+
* leaf {@link import('./factories.js').createRelationTool} calls on every operation, mirroring
|
|
1677
|
+
* {@link relationManagerOf}'s guard shape.
|
|
1678
|
+
*
|
|
1679
|
+
* @param manager - The resolved {@link RelationManagerInterface}
|
|
1680
|
+
* @param name - The call's `model` field
|
|
1681
|
+
* @returns The model's {@link ModelInterface}
|
|
1682
|
+
*/
|
|
1683
|
+
export declare function relationModelOf(manager: RelationManagerInterface, name: string): ModelInterface;
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
* Map a caught error to the {@link AgentToolErrorCode} the upcoming relation tool should throw
|
|
1687
|
+
* with — the pure classification step of that factory's error handling, mirroring
|
|
1688
|
+
* {@link terminalToolCode}'s idiom for `@orkestrel/relation`.
|
|
1689
|
+
*
|
|
1690
|
+
* @param error - The value caught from a `@orkestrel/relation` operation
|
|
1691
|
+
* @returns The granular {@link RelationErrorCode}, or `undefined` if `error` is not a `RelationError`
|
|
1692
|
+
*/
|
|
1693
|
+
export declare function relationToolCode(error: unknown): RelationErrorCode | undefined;
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Options for {@link import('./factories.js').createRelationTool} — SRC-3 (the final unit) of
|
|
1697
|
+
* the 3-unit database / relation spine.
|
|
1698
|
+
*
|
|
1699
|
+
* @remarks
|
|
1700
|
+
* - `managers` — the live `RelationManagerInterface` (`@orkestrel/relation`) registry a call's
|
|
1701
|
+
* optional `manager` field addresses by name; REQUIRED (unlike the database tool's lazily
|
|
1702
|
+
* resolved handles, a relation manager's relations are declared up front and cannot be minted
|
|
1703
|
+
* on demand from a tool call). A call that omits `manager` resolves to the SOLE registered
|
|
1704
|
+
* manager when exactly one is registered, else throws a typed `TOOL`
|
|
1705
|
+
* {@link import('./errors.js').AgentToolError} naming the registered manager keys.
|
|
1706
|
+
* - `limit` — the row cap `'find'` / `'links'` enforce when a call's `limit` is omitted or
|
|
1707
|
+
* exceeds it. Defaults to {@link import('./constants.js').RELATION_TOOL_LIMIT}.
|
|
1708
|
+
* - `depth` — the max dot-path segment count `'load'` / `'find'`'s `include` paths may reach
|
|
1709
|
+
* ({@link import('./helpers.js').expandInclude}). Defaults to
|
|
1710
|
+
* {@link import('./constants.js').RELATION_TOOL_DEPTH}.
|
|
1711
|
+
* - `name` / `description` — advertised tool overrides; default to
|
|
1712
|
+
* {@link import('./constants.js').RELATION_TOOL_NAME} / {@link import('./constants.js').RELATION_TOOL_DESCRIPTION}.
|
|
1713
|
+
*/
|
|
1714
|
+
export declare interface RelationToolOptions {
|
|
1715
|
+
readonly name?: string;
|
|
1716
|
+
readonly description?: string;
|
|
1717
|
+
readonly managers: Readonly<Record<string, RelationManagerInterface>>;
|
|
1718
|
+
readonly limit?: number;
|
|
1719
|
+
readonly depth?: number;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* The shape of {@link import('./factories.js').createRelationTool}'s call arguments —
|
|
1724
|
+
* discriminated by `operation` into the 5 relation operations (`'load'` / `'find'` / `'link'` /
|
|
1725
|
+
* `'unlink'` / `'links'`).
|
|
1726
|
+
*
|
|
1727
|
+
* @remarks
|
|
1728
|
+
* `'load'` fetches one or more rows (positional key/array) with `include` attached. `'find'`
|
|
1729
|
+
* fetches rows (pagination / sort only) with `include` attached. `'link'` / `'unlink'` write /
|
|
1730
|
+
* remove a `through` junction row; `'links'` lists a `through` relation's linked keys.
|
|
1731
|
+
*/
|
|
1732
|
+
export declare const relationToolShape: UnionShape<[ ObjectShape<{
|
|
1733
|
+
operation: LiteralShape<readonly ["load"]>;
|
|
1734
|
+
manager: OptionalShape<StringShape>;
|
|
1735
|
+
model: StringShape;
|
|
1736
|
+
key: UnionShape<[ ArrayShape<UnionShape<[ StringShape, NumberShape]>>, StringShape, NumberShape]>;
|
|
1737
|
+
include: OptionalShape<ArrayShape<StringShape>>;
|
|
1738
|
+
}, false>, ObjectShape<{
|
|
1739
|
+
operation: LiteralShape<readonly ["find"]>;
|
|
1740
|
+
manager: OptionalShape<StringShape>;
|
|
1741
|
+
model: StringShape;
|
|
1742
|
+
include: OptionalShape<ArrayShape<StringShape>>;
|
|
1743
|
+
limit: OptionalShape<NumberShape>;
|
|
1744
|
+
offset: OptionalShape<NumberShape>;
|
|
1745
|
+
sort: OptionalShape<StringShape>;
|
|
1746
|
+
direction: OptionalShape<LiteralShape<readonly ["ascending", "descending"]>>;
|
|
1747
|
+
}, false>, ObjectShape<{
|
|
1748
|
+
operation: LiteralShape<readonly ["link"]>;
|
|
1749
|
+
manager: OptionalShape<StringShape>;
|
|
1750
|
+
model: StringShape;
|
|
1751
|
+
key: UnionShape<[ StringShape, NumberShape]>;
|
|
1752
|
+
relation: StringShape;
|
|
1753
|
+
target: UnionShape<[ StringShape, NumberShape]>;
|
|
1754
|
+
}, false>, ObjectShape<{
|
|
1755
|
+
operation: LiteralShape<readonly ["unlink"]>;
|
|
1756
|
+
manager: OptionalShape<StringShape>;
|
|
1757
|
+
model: StringShape;
|
|
1758
|
+
key: UnionShape<[ StringShape, NumberShape]>;
|
|
1759
|
+
relation: StringShape;
|
|
1760
|
+
target: UnionShape<[ StringShape, NumberShape]>;
|
|
1761
|
+
}, false>, ObjectShape<{
|
|
1762
|
+
operation: LiteralShape<readonly ["links"]>;
|
|
1763
|
+
manager: OptionalShape<StringShape>;
|
|
1764
|
+
model: StringShape;
|
|
1765
|
+
key: UnionShape<[ StringShape, NumberShape]>;
|
|
1766
|
+
relation: StringShape;
|
|
1767
|
+
}, false>]>;
|
|
1768
|
+
|
|
1769
|
+
/** A loose row — a flat object of column name to JSON value; the array form (multiple rows) resolves FIRST per AGENTS §9.2. */
|
|
1770
|
+
export declare const rowShape: ObjectShape<Record<never, never>, JSONShape>;
|
|
1771
|
+
|
|
1772
|
+
/** One or many loose rows — the array form resolves FIRST per AGENTS §9.2. */
|
|
1773
|
+
export declare const rowsShape: UnionShape<[ ArrayShape<ObjectShape<Record<never, never>, JSONShape>>, ObjectShape<Record<never, never>, JSONShape>]>;
|
|
1774
|
+
|
|
1775
|
+
/** A single row key (not an array) — used by `'link'` / `'unlink'` / `'links'`, which address exactly one owning row. */
|
|
1776
|
+
export declare const singleKeyShape: UnionShape<[ StringShape, NumberShape]>;
|
|
932
1777
|
|
|
933
1778
|
/**
|
|
934
1779
|
* The shape of ONE flat step — `{ name }` — the building block of {@link workflowStepsShape}.
|
|
@@ -939,7 +1784,39 @@ export declare const promptToolShape: ObjectShape<{
|
|
|
939
1784
|
*/
|
|
940
1785
|
export declare const stepShape: ObjectShape<{
|
|
941
1786
|
name: StringShape;
|
|
942
|
-
}>;
|
|
1787
|
+
}, false>;
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Build one {@link TableSchema} from a table NAME and its `@orkestrel/database` `TableExport` —
|
|
1791
|
+
* the "deployed" schema shape `DatabaseInterface.migrate` diffs against, derived from a LIVE
|
|
1792
|
+
* handle's `export()` rather than a re-declared {@link TableSpec}, so it works for ANY handle
|
|
1793
|
+
* (config-tracked or caller-supplied).
|
|
1794
|
+
*
|
|
1795
|
+
* @param name - The table name
|
|
1796
|
+
* @param table - The table's `TableExport` (`{ key, columns }`, `@orkestrel/database`)
|
|
1797
|
+
* @returns The equivalent {@link TableSchema} (`indexes` empty — this package declares none)
|
|
1798
|
+
*/
|
|
1799
|
+
export declare function tableSchema(name: string, table: Readonly<{
|
|
1800
|
+
key: string;
|
|
1801
|
+
columns: Readonly<Record<string, ContractShape>>;
|
|
1802
|
+
}>): TableSchema;
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* A database's table layout — one entry per table, each a flat map of column name to
|
|
1806
|
+
* {@link ColumnSpec}. The small-model-facing DSL {@link import('./helpers.js').expandTables}
|
|
1807
|
+
* compiles into an `@orkestrel/database` `TablesShape`.
|
|
1808
|
+
*/
|
|
1809
|
+
export declare type TableSpec = Readonly<Record<string, Readonly<{
|
|
1810
|
+
columns: Readonly<Record<string, ColumnSpec>>;
|
|
1811
|
+
}>>>;
|
|
1812
|
+
|
|
1813
|
+
/** A {@link import('./types.js').TableSpec} — table name to `{ columns }`, each column a {@link columnSpecShape}. */
|
|
1814
|
+
export declare const tableSpecShape: ObjectShape<Record<never, never>, ObjectShape<{
|
|
1815
|
+
columns: ObjectShape<Record<never, never>, UnionShape<[ LiteralShape<readonly ["string", "integer", "number", "boolean"]>, ObjectShape<{
|
|
1816
|
+
type: LiteralShape<readonly ["string", "integer", "number", "boolean"]>;
|
|
1817
|
+
optional: OptionalShape<BooleanShape>;
|
|
1818
|
+
}, false>]>>;
|
|
1819
|
+
}, false>>;
|
|
943
1820
|
|
|
944
1821
|
/**
|
|
945
1822
|
* A draft task — a `TaskDefinition` (`@orkestrel/workflow`) with OPTIONAL `id` / `name`.
|
|
@@ -972,7 +1849,7 @@ export declare const taskDraftShape: ObjectShape<{
|
|
|
972
1849
|
run: OptionalShape<StringShape>;
|
|
973
1850
|
retries: OptionalShape<NumberShape>;
|
|
974
1851
|
timeout: OptionalShape<NumberShape>;
|
|
975
|
-
}>;
|
|
1852
|
+
}, false>;
|
|
976
1853
|
|
|
977
1854
|
/**
|
|
978
1855
|
* Map a caught error to the {@link AgentToolErrorCode} the terminal-tool factory should throw
|
|
@@ -1086,12 +1963,12 @@ export declare const workflowDraftShape: ObjectShape<{
|
|
|
1086
1963
|
run: OptionalShape<StringShape>;
|
|
1087
1964
|
retries: OptionalShape<NumberShape>;
|
|
1088
1965
|
timeout: OptionalShape<NumberShape>;
|
|
1089
|
-
}>>;
|
|
1966
|
+
}, false>>;
|
|
1090
1967
|
concurrency: OptionalShape<NumberShape>;
|
|
1091
1968
|
bail: OptionalShape<LiteralShape<readonly [true, false]>>;
|
|
1092
|
-
}>>;
|
|
1969
|
+
}, false>>;
|
|
1093
1970
|
bail: OptionalShape<LiteralShape<readonly [true, false]>>;
|
|
1094
|
-
}>;
|
|
1971
|
+
}, false>;
|
|
1095
1972
|
|
|
1096
1973
|
/**
|
|
1097
1974
|
* One flat step — `{ name }` — the building block of a {@link WorkflowSteps} blob.
|
|
@@ -1136,8 +2013,8 @@ export declare const workflowStepsShape: ObjectShape<{
|
|
|
1136
2013
|
name: OptionalShape<StringShape>;
|
|
1137
2014
|
steps: ArrayShape<ObjectShape<{
|
|
1138
2015
|
name: StringShape;
|
|
1139
|
-
}>>;
|
|
1140
|
-
}>;
|
|
2016
|
+
}, false>>;
|
|
2017
|
+
}, false>;
|
|
1141
2018
|
|
|
1142
2019
|
/**
|
|
1143
2020
|
* The ancestry identifier of a workflow in a run chain — `workflow:<id>`.
|
|
@@ -1392,29 +2269,29 @@ export declare interface WorkspaceToolOptions {
|
|
|
1392
2269
|
export declare const workspaceToolShape: UnionShape<[ ObjectShape<{
|
|
1393
2270
|
operation: LiteralShape<readonly ["read"]>;
|
|
1394
2271
|
path: StringShape;
|
|
1395
|
-
}>, ObjectShape<{
|
|
2272
|
+
}, false>, ObjectShape<{
|
|
1396
2273
|
operation: LiteralShape<readonly ["list"]>;
|
|
1397
|
-
}>, ObjectShape<{
|
|
2274
|
+
}, false>, ObjectShape<{
|
|
1398
2275
|
operation: LiteralShape<readonly ["has"]>;
|
|
1399
2276
|
path: StringShape;
|
|
1400
|
-
}>, ObjectShape<{
|
|
2277
|
+
}, false>, ObjectShape<{
|
|
1401
2278
|
operation: LiteralShape<readonly ["search"]>;
|
|
1402
2279
|
query: StringShape;
|
|
1403
2280
|
regex: OptionalShape<BooleanShape>;
|
|
1404
2281
|
exact: OptionalShape<BooleanShape>;
|
|
1405
2282
|
limit: OptionalShape<NumberShape>;
|
|
1406
|
-
}>, ObjectShape<{
|
|
2283
|
+
}, false>, ObjectShape<{
|
|
1407
2284
|
operation: LiteralShape<readonly ["replace"]>;
|
|
1408
2285
|
query: StringShape;
|
|
1409
2286
|
replacement: StringShape;
|
|
1410
2287
|
regex: OptionalShape<BooleanShape>;
|
|
1411
2288
|
exact: OptionalShape<BooleanShape>;
|
|
1412
2289
|
limit: OptionalShape<NumberShape>;
|
|
1413
|
-
}>, ObjectShape<{
|
|
2290
|
+
}, false>, ObjectShape<{
|
|
1414
2291
|
operation: LiteralShape<readonly ["write"]>;
|
|
1415
2292
|
path: StringShape;
|
|
1416
2293
|
content: StringShape;
|
|
1417
|
-
}>, ObjectShape<{
|
|
2294
|
+
}, false>, ObjectShape<{
|
|
1418
2295
|
operation: LiteralShape<readonly ["splice"]>;
|
|
1419
2296
|
path: StringShape;
|
|
1420
2297
|
content: StringShape;
|
|
@@ -1422,26 +2299,26 @@ export declare const workspaceToolShape: UnionShape<[ ObjectShape<{
|
|
|
1422
2299
|
fromColumn: NumberShape;
|
|
1423
2300
|
toLine: NumberShape;
|
|
1424
2301
|
toColumn: NumberShape;
|
|
1425
|
-
}>, ObjectShape<{
|
|
2302
|
+
}, false>, ObjectShape<{
|
|
1426
2303
|
operation: LiteralShape<readonly ["prepend"]>;
|
|
1427
2304
|
path: StringShape;
|
|
1428
2305
|
content: StringShape;
|
|
1429
|
-
}>, ObjectShape<{
|
|
2306
|
+
}, false>, ObjectShape<{
|
|
1430
2307
|
operation: LiteralShape<readonly ["append"]>;
|
|
1431
2308
|
path: StringShape;
|
|
1432
2309
|
content: StringShape;
|
|
1433
|
-
}>, ObjectShape<{
|
|
2310
|
+
}, false>, ObjectShape<{
|
|
1434
2311
|
operation: LiteralShape<readonly ["move"]>;
|
|
1435
2312
|
from: StringShape;
|
|
1436
2313
|
to: StringShape;
|
|
1437
|
-
}>, ObjectShape<{
|
|
2314
|
+
}, false>, ObjectShape<{
|
|
1438
2315
|
operation: LiteralShape<readonly ["remove"]>;
|
|
1439
2316
|
path: StringShape;
|
|
1440
|
-
}>, ObjectShape<{
|
|
2317
|
+
}, false>, ObjectShape<{
|
|
1441
2318
|
operation: LiteralShape<readonly ["workspaces"]>;
|
|
1442
|
-
}>, ObjectShape<{
|
|
2319
|
+
}, false>, ObjectShape<{
|
|
1443
2320
|
operation: LiteralShape<readonly ["switch"]>;
|
|
1444
2321
|
id: StringShape;
|
|
1445
|
-
}>]>;
|
|
2322
|
+
}, false>]>;
|
|
1446
2323
|
|
|
1447
2324
|
export { }
|