@orkestrel/toolbox 0.0.13 → 0.0.14
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 +25 -15
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +33 -15
- package/dist/src/core/index.d.ts +33 -15
- package/dist/src/core/index.js +25 -15
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -9
|
@@ -29,6 +29,7 @@ import { StringShape } from '@orkestrel/contract';
|
|
|
29
29
|
import type { TableInterface } from '@orkestrel/database';
|
|
30
30
|
import type { TableMap } from '@orkestrel/database';
|
|
31
31
|
import type { TerminalManagerInterface } from '@orkestrel/terminal';
|
|
32
|
+
import type { ToolContext } from '@orkestrel/tool';
|
|
32
33
|
import type { ToolInterface } from '@orkestrel/tool';
|
|
33
34
|
import type { ToolManagerInterface } from '@orkestrel/tool';
|
|
34
35
|
import { UnionShape } from '@orkestrel/contract';
|
|
@@ -571,11 +572,14 @@ export declare function createDatabaseDefinitionStore(driver?: DriverInterface):
|
|
|
571
572
|
* import { createDatabaseTool } from '@src/core'
|
|
572
573
|
*
|
|
573
574
|
* const tool = createDatabaseTool()
|
|
574
|
-
* await tool.execute(
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* }
|
|
575
|
+
* await tool.execute(
|
|
576
|
+
* {
|
|
577
|
+
* operation: 'create',
|
|
578
|
+
* id: 'shop',
|
|
579
|
+
* tables: { products: { columns: { name: 'string', price: 'number' } } },
|
|
580
|
+
* },
|
|
581
|
+
* { signal: new AbortController().signal },
|
|
582
|
+
* )
|
|
579
583
|
* ```
|
|
580
584
|
*/
|
|
581
585
|
export declare function createDatabaseTool(options?: DatabaseToolOptions): ToolInterface;
|
|
@@ -638,8 +642,10 @@ export declare function createDescribeTool(tools: ToolManagerInterface): ToolInt
|
|
|
638
642
|
* never asserted, and a key outside the closed inferred schema is silently dropped rather than
|
|
639
643
|
* rejected (see {@link import('./types.js').EndpointToolOptions.validate}). With
|
|
640
644
|
* `validate: false`, the tool's `execute` passes through the model-supplied `args` to
|
|
641
|
-
* `definition.execute` without re-validation — the raw-passthrough opt-out.
|
|
642
|
-
*
|
|
645
|
+
* `definition.execute` without re-validation — the raw-passthrough opt-out. The execution context
|
|
646
|
+
* the tool's `execute` receives reaches `definition.execute` unchanged whichever way `args` are
|
|
647
|
+
* handled, so a handler that reads `context.signal` observes the caller's cancellation. Either way,
|
|
648
|
+
* the definition's return flows back as the tool call's plain result; a throw propagates uncaught,
|
|
643
649
|
* isolated by the `ToolManagerInterface` (`@orkestrel/tool`) into the canonical error envelope
|
|
644
650
|
* — never caught or re-wrapped here.
|
|
645
651
|
*
|
|
@@ -862,7 +868,10 @@ export declare function createPromptTool(options: PromptToolOptions): ToolInterf
|
|
|
862
868
|
* import { createRelationTool } from '@src/core'
|
|
863
869
|
*
|
|
864
870
|
* const tool = createRelationTool({ managers: { shop: manager } })
|
|
865
|
-
* await tool.execute(
|
|
871
|
+
* await tool.execute(
|
|
872
|
+
* { operation: 'load', model: 'accounts', key: 'acc1', include: ['contacts'] },
|
|
873
|
+
* { signal: new AbortController().signal },
|
|
874
|
+
* )
|
|
866
875
|
* ```
|
|
867
876
|
*/
|
|
868
877
|
export declare function createRelationTool(options: RelationToolOptions): ToolInterface;
|
|
@@ -876,7 +885,9 @@ export declare function createRelationTool(options: RelationToolOptions): ToolIn
|
|
|
876
885
|
* (`{ publish: createToolFunction(tools, 'publish') }`); the pure workflow runner has no
|
|
877
886
|
* knowledge of tools itself. The returned function executes `name` against `tools` with the
|
|
878
887
|
* task's `controller.input` as the call arguments. The adapter resolves the live tool, calls its
|
|
879
|
-
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`.
|
|
888
|
+
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`. The
|
|
889
|
+
* execution context it passes carries the task's own `controller.signal`, so a handler that
|
|
890
|
+
* reads `context.signal` observes the caller's cancellation.
|
|
880
891
|
* Genuine execution throws retain identity. An unregistered name or non-JSON return throws this
|
|
881
892
|
* package's typed `TOOL` `ToolboxError`.
|
|
882
893
|
*
|
|
@@ -1561,12 +1572,19 @@ export declare interface EndpointDefinition {
|
|
|
1561
1572
|
|
|
1562
1573
|
/**
|
|
1563
1574
|
* Represents the handler {@link EndpointDefinition.execute} implements — it mirrors
|
|
1564
|
-
* `@orkestrel/tool`'s `ToolOptions.execute` signature exactly
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1575
|
+
* `@orkestrel/tool`'s `ToolOptions.execute` signature exactly, so
|
|
1576
|
+
* {@link import('./factories.js').createEndpointTool} forwards the execution context it receives
|
|
1577
|
+
* to the handler unchanged and a handler that reads `context.signal` observes the caller's
|
|
1578
|
+
* cancellation.
|
|
1579
|
+
*
|
|
1580
|
+
* @remarks
|
|
1581
|
+
* The mirrored signature is the same `Readonly<Record<string, unknown>>` argument, the same
|
|
1582
|
+
* `ToolContext` second parameter, and the same `Promise<unknown> | unknown` return. A handler that
|
|
1583
|
+
* declares `args` alone still satisfies the type, the way a function declaring fewer parameters
|
|
1584
|
+
* than its contract does, so an endpoint definition written against the argument alone keeps
|
|
1585
|
+
* typechecking and reads no signal.
|
|
1568
1586
|
*/
|
|
1569
|
-
export declare type EndpointHandler = (args: Readonly<Record<string, unknown
|
|
1587
|
+
export declare type EndpointHandler = (args: Readonly<Record<string, unknown>>, context: ToolContext) => Promise<unknown> | unknown;
|
|
1570
1588
|
|
|
1571
1589
|
/**
|
|
1572
1590
|
* Represents the construction-time tuning for {@link import('./factories.js').createEndpointTool} —
|
|
@@ -2349,7 +2367,7 @@ timeout: OptionalShape<NumberShape>;
|
|
|
2349
2367
|
* @remarks
|
|
2350
2368
|
* Carries a machine-readable `code` (see {@link import('./types.js').ToolboxErrorCode}) and
|
|
2351
2369
|
* an optional `context` bag for structured diagnostics. They are readable through an in-process
|
|
2352
|
-
* catch, including around a direct `tool.execute(args)` call. The `ToolManagerInterface`
|
|
2370
|
+
* catch, including around a direct `tool.execute(args, context)` call. The `ToolManagerInterface`
|
|
2353
2371
|
* (`@orkestrel/tool`) instead flattens every throw to the canonical tool result's top-level
|
|
2354
2372
|
* `error` message string under AGENTS' “narrow untrusted input with guards” rule.
|
|
2355
2373
|
*
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { StringShape } from '@orkestrel/contract';
|
|
|
29
29
|
import type { TableInterface } from '@orkestrel/database';
|
|
30
30
|
import type { TableMap } from '@orkestrel/database';
|
|
31
31
|
import type { TerminalManagerInterface } from '@orkestrel/terminal';
|
|
32
|
+
import type { ToolContext } from '@orkestrel/tool';
|
|
32
33
|
import type { ToolInterface } from '@orkestrel/tool';
|
|
33
34
|
import type { ToolManagerInterface } from '@orkestrel/tool';
|
|
34
35
|
import { UnionShape } from '@orkestrel/contract';
|
|
@@ -571,11 +572,14 @@ export declare function createDatabaseDefinitionStore(driver?: DriverInterface):
|
|
|
571
572
|
* import { createDatabaseTool } from '@src/core'
|
|
572
573
|
*
|
|
573
574
|
* const tool = createDatabaseTool()
|
|
574
|
-
* await tool.execute(
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* }
|
|
575
|
+
* await tool.execute(
|
|
576
|
+
* {
|
|
577
|
+
* operation: 'create',
|
|
578
|
+
* id: 'shop',
|
|
579
|
+
* tables: { products: { columns: { name: 'string', price: 'number' } } },
|
|
580
|
+
* },
|
|
581
|
+
* { signal: new AbortController().signal },
|
|
582
|
+
* )
|
|
579
583
|
* ```
|
|
580
584
|
*/
|
|
581
585
|
export declare function createDatabaseTool(options?: DatabaseToolOptions): ToolInterface;
|
|
@@ -638,8 +642,10 @@ export declare function createDescribeTool(tools: ToolManagerInterface): ToolInt
|
|
|
638
642
|
* never asserted, and a key outside the closed inferred schema is silently dropped rather than
|
|
639
643
|
* rejected (see {@link import('./types.js').EndpointToolOptions.validate}). With
|
|
640
644
|
* `validate: false`, the tool's `execute` passes through the model-supplied `args` to
|
|
641
|
-
* `definition.execute` without re-validation — the raw-passthrough opt-out.
|
|
642
|
-
*
|
|
645
|
+
* `definition.execute` without re-validation — the raw-passthrough opt-out. The execution context
|
|
646
|
+
* the tool's `execute` receives reaches `definition.execute` unchanged whichever way `args` are
|
|
647
|
+
* handled, so a handler that reads `context.signal` observes the caller's cancellation. Either way,
|
|
648
|
+
* the definition's return flows back as the tool call's plain result; a throw propagates uncaught,
|
|
643
649
|
* isolated by the `ToolManagerInterface` (`@orkestrel/tool`) into the canonical error envelope
|
|
644
650
|
* — never caught or re-wrapped here.
|
|
645
651
|
*
|
|
@@ -862,7 +868,10 @@ export declare function createPromptTool(options: PromptToolOptions): ToolInterf
|
|
|
862
868
|
* import { createRelationTool } from '@src/core'
|
|
863
869
|
*
|
|
864
870
|
* const tool = createRelationTool({ managers: { shop: manager } })
|
|
865
|
-
* await tool.execute(
|
|
871
|
+
* await tool.execute(
|
|
872
|
+
* { operation: 'load', model: 'accounts', key: 'acc1', include: ['contacts'] },
|
|
873
|
+
* { signal: new AbortController().signal },
|
|
874
|
+
* )
|
|
866
875
|
* ```
|
|
867
876
|
*/
|
|
868
877
|
export declare function createRelationTool(options: RelationToolOptions): ToolInterface;
|
|
@@ -876,7 +885,9 @@ export declare function createRelationTool(options: RelationToolOptions): ToolIn
|
|
|
876
885
|
* (`{ publish: createToolFunction(tools, 'publish') }`); the pure workflow runner has no
|
|
877
886
|
* knowledge of tools itself. The returned function executes `name` against `tools` with the
|
|
878
887
|
* task's `controller.input` as the call arguments. The adapter resolves the live tool, calls its
|
|
879
|
-
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`.
|
|
888
|
+
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`. The
|
|
889
|
+
* execution context it passes carries the task's own `controller.signal`, so a handler that
|
|
890
|
+
* reads `context.signal` observes the caller's cancellation.
|
|
880
891
|
* Genuine execution throws retain identity. An unregistered name or non-JSON return throws this
|
|
881
892
|
* package's typed `TOOL` `ToolboxError`.
|
|
882
893
|
*
|
|
@@ -1561,12 +1572,19 @@ export declare interface EndpointDefinition {
|
|
|
1561
1572
|
|
|
1562
1573
|
/**
|
|
1563
1574
|
* Represents the handler {@link EndpointDefinition.execute} implements — it mirrors
|
|
1564
|
-
* `@orkestrel/tool`'s `ToolOptions.execute` signature exactly
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1575
|
+
* `@orkestrel/tool`'s `ToolOptions.execute` signature exactly, so
|
|
1576
|
+
* {@link import('./factories.js').createEndpointTool} forwards the execution context it receives
|
|
1577
|
+
* to the handler unchanged and a handler that reads `context.signal` observes the caller's
|
|
1578
|
+
* cancellation.
|
|
1579
|
+
*
|
|
1580
|
+
* @remarks
|
|
1581
|
+
* The mirrored signature is the same `Readonly<Record<string, unknown>>` argument, the same
|
|
1582
|
+
* `ToolContext` second parameter, and the same `Promise<unknown> | unknown` return. A handler that
|
|
1583
|
+
* declares `args` alone still satisfies the type, the way a function declaring fewer parameters
|
|
1584
|
+
* than its contract does, so an endpoint definition written against the argument alone keeps
|
|
1585
|
+
* typechecking and reads no signal.
|
|
1568
1586
|
*/
|
|
1569
|
-
export declare type EndpointHandler = (args: Readonly<Record<string, unknown
|
|
1587
|
+
export declare type EndpointHandler = (args: Readonly<Record<string, unknown>>, context: ToolContext) => Promise<unknown> | unknown;
|
|
1570
1588
|
|
|
1571
1589
|
/**
|
|
1572
1590
|
* Represents the construction-time tuning for {@link import('./factories.js').createEndpointTool} —
|
|
@@ -2349,7 +2367,7 @@ timeout: OptionalShape<NumberShape>;
|
|
|
2349
2367
|
* @remarks
|
|
2350
2368
|
* Carries a machine-readable `code` (see {@link import('./types.js').ToolboxErrorCode}) and
|
|
2351
2369
|
* an optional `context` bag for structured diagnostics. They are readable through an in-process
|
|
2352
|
-
* catch, including around a direct `tool.execute(args)` call. The `ToolManagerInterface`
|
|
2370
|
+
* catch, including around a direct `tool.execute(args, context)` call. The `ToolManagerInterface`
|
|
2353
2371
|
* (`@orkestrel/tool`) instead flattens every throw to the canonical tool result's top-level
|
|
2354
2372
|
* `error` message string under AGENTS' “narrow untrusted input with guards” rule.
|
|
2355
2373
|
*
|
package/dist/src/core/index.js
CHANGED
|
@@ -590,7 +590,7 @@ var INFER_TOOL_DESCRIPTION = [
|
|
|
590
590
|
* @remarks
|
|
591
591
|
* Carries a machine-readable `code` (see {@link import('./types.js').ToolboxErrorCode}) and
|
|
592
592
|
* an optional `context` bag for structured diagnostics. They are readable through an in-process
|
|
593
|
-
* catch, including around a direct `tool.execute(args)` call. The `ToolManagerInterface`
|
|
593
|
+
* catch, including around a direct `tool.execute(args, context)` call. The `ToolManagerInterface`
|
|
594
594
|
* (`@orkestrel/tool`) instead flattens every throw to the canonical tool result's top-level
|
|
595
595
|
* `error` message string under AGENTS' “narrow untrusted input with guards” rule.
|
|
596
596
|
*
|
|
@@ -2058,7 +2058,9 @@ var DatabaseResolver = class {
|
|
|
2058
2058
|
* (`{ publish: createToolFunction(tools, 'publish') }`); the pure workflow runner has no
|
|
2059
2059
|
* knowledge of tools itself. The returned function executes `name` against `tools` with the
|
|
2060
2060
|
* task's `controller.input` as the call arguments. The adapter resolves the live tool, calls its
|
|
2061
|
-
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`.
|
|
2061
|
+
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`. The
|
|
2062
|
+
* execution context it passes carries the task's own `controller.signal`, so a handler that
|
|
2063
|
+
* reads `context.signal` observes the caller's cancellation.
|
|
2062
2064
|
* Genuine execution throws retain identity. An unregistered name or non-JSON return throws this
|
|
2063
2065
|
* package's typed `TOOL` `ToolboxError`.
|
|
2064
2066
|
*
|
|
@@ -2083,7 +2085,7 @@ function createToolFunction(tools, name) {
|
|
|
2083
2085
|
return async (controller) => {
|
|
2084
2086
|
const tool = tools.tool(name);
|
|
2085
2087
|
if (tool === void 0) throw new ToolboxError("TOOL", `tool '${name}' is not registered`, { tool: name });
|
|
2086
|
-
const result = parseJSONValue(await tool.execute(controller.input));
|
|
2088
|
+
const result = parseJSONValue(await tool.execute(controller.input, { signal: controller.signal }));
|
|
2087
2089
|
if (result === void 0) throw new ToolboxError("TOOL", `tool '${name}' returned a non-JSON value`, { tool: name });
|
|
2088
2090
|
return result;
|
|
2089
2091
|
};
|
|
@@ -2885,11 +2887,14 @@ function createDatabaseDefinitionStore(driver = createMemoryDriver()) {
|
|
|
2885
2887
|
* import { createDatabaseTool } from '@src/core'
|
|
2886
2888
|
*
|
|
2887
2889
|
* const tool = createDatabaseTool()
|
|
2888
|
-
* await tool.execute(
|
|
2889
|
-
*
|
|
2890
|
-
*
|
|
2891
|
-
*
|
|
2892
|
-
* }
|
|
2890
|
+
* await tool.execute(
|
|
2891
|
+
* {
|
|
2892
|
+
* operation: 'create',
|
|
2893
|
+
* id: 'shop',
|
|
2894
|
+
* tables: { products: { columns: { name: 'string', price: 'number' } } },
|
|
2895
|
+
* },
|
|
2896
|
+
* { signal: new AbortController().signal },
|
|
2897
|
+
* )
|
|
2893
2898
|
* ```
|
|
2894
2899
|
*/
|
|
2895
2900
|
function createDatabaseTool(options = {}) {
|
|
@@ -3085,7 +3090,10 @@ function createDatabaseTool(options = {}) {
|
|
|
3085
3090
|
* import { createRelationTool } from '@src/core'
|
|
3086
3091
|
*
|
|
3087
3092
|
* const tool = createRelationTool({ managers: { shop: manager } })
|
|
3088
|
-
* await tool.execute(
|
|
3093
|
+
* await tool.execute(
|
|
3094
|
+
* { operation: 'load', model: 'accounts', key: 'acc1', include: ['contacts'] },
|
|
3095
|
+
* { signal: new AbortController().signal },
|
|
3096
|
+
* )
|
|
3089
3097
|
* ```
|
|
3090
3098
|
*/
|
|
3091
3099
|
function createRelationTool(options) {
|
|
@@ -3304,8 +3312,10 @@ function createInferTool(options) {
|
|
|
3304
3312
|
* never asserted, and a key outside the closed inferred schema is silently dropped rather than
|
|
3305
3313
|
* rejected (see {@link import('./types.js').EndpointToolOptions.validate}). With
|
|
3306
3314
|
* `validate: false`, the tool's `execute` passes through the model-supplied `args` to
|
|
3307
|
-
* `definition.execute` without re-validation — the raw-passthrough opt-out.
|
|
3308
|
-
*
|
|
3315
|
+
* `definition.execute` without re-validation — the raw-passthrough opt-out. The execution context
|
|
3316
|
+
* the tool's `execute` receives reaches `definition.execute` unchanged whichever way `args` are
|
|
3317
|
+
* handled, so a handler that reads `context.signal` observes the caller's cancellation. Either way,
|
|
3318
|
+
* the definition's return flows back as the tool call's plain result; a throw propagates uncaught,
|
|
3309
3319
|
* isolated by the `ToolManagerInterface` (`@orkestrel/tool`) into the canonical error envelope
|
|
3310
3320
|
* — never caught or re-wrapped here.
|
|
3311
3321
|
*
|
|
@@ -3358,8 +3368,8 @@ function createEndpointTool(definition, options) {
|
|
|
3358
3368
|
name: definition.name,
|
|
3359
3369
|
description: definition.description,
|
|
3360
3370
|
...parameters === void 0 ? {} : { parameters },
|
|
3361
|
-
execute(args) {
|
|
3362
|
-
return definition.execute(args);
|
|
3371
|
+
execute(args, context) {
|
|
3372
|
+
return definition.execute(args, context);
|
|
3363
3373
|
}
|
|
3364
3374
|
});
|
|
3365
3375
|
const contract = createContract(schemaToShape(objectSchema));
|
|
@@ -3367,13 +3377,13 @@ function createEndpointTool(definition, options) {
|
|
|
3367
3377
|
name: definition.name,
|
|
3368
3378
|
description: definition.description,
|
|
3369
3379
|
...parameters === void 0 ? {} : { parameters },
|
|
3370
|
-
execute(args) {
|
|
3380
|
+
execute(args, context) {
|
|
3371
3381
|
const parsed = contract.parse(args);
|
|
3372
3382
|
if (parsed === void 0 || !isRecord(parsed)) throw new ToolboxError("TOOL", "malformed endpoint call arguments", {
|
|
3373
3383
|
name: definition.name,
|
|
3374
3384
|
faults: contract.explain(args)
|
|
3375
3385
|
});
|
|
3376
|
-
return definition.execute(parsed);
|
|
3386
|
+
return definition.execute(parsed, context);
|
|
3377
3387
|
}
|
|
3378
3388
|
});
|
|
3379
3389
|
}
|