@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
package/dist/src/core/index.cjs
CHANGED
|
@@ -591,7 +591,7 @@ var INFER_TOOL_DESCRIPTION = [
|
|
|
591
591
|
* @remarks
|
|
592
592
|
* Carries a machine-readable `code` (see {@link import('./types.js').ToolboxErrorCode}) and
|
|
593
593
|
* an optional `context` bag for structured diagnostics. They are readable through an in-process
|
|
594
|
-
* catch, including around a direct `tool.execute(args)` call. The `ToolManagerInterface`
|
|
594
|
+
* catch, including around a direct `tool.execute(args, context)` call. The `ToolManagerInterface`
|
|
595
595
|
* (`@orkestrel/tool`) instead flattens every throw to the canonical tool result's top-level
|
|
596
596
|
* `error` message string under AGENTS' “narrow untrusted input with guards” rule.
|
|
597
597
|
*
|
|
@@ -2059,7 +2059,9 @@ var DatabaseResolver = class {
|
|
|
2059
2059
|
* (`{ publish: createToolFunction(tools, 'publish') }`); the pure workflow runner has no
|
|
2060
2060
|
* knowledge of tools itself. The returned function executes `name` against `tools` with the
|
|
2061
2061
|
* task's `controller.input` as the call arguments. The adapter resolves the live tool, calls its
|
|
2062
|
-
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`.
|
|
2062
|
+
* `execute` method directly, and deep-gates the returned unknown through `parseJSONValue`. The
|
|
2063
|
+
* execution context it passes carries the task's own `controller.signal`, so a handler that
|
|
2064
|
+
* reads `context.signal` observes the caller's cancellation.
|
|
2063
2065
|
* Genuine execution throws retain identity. An unregistered name or non-JSON return throws this
|
|
2064
2066
|
* package's typed `TOOL` `ToolboxError`.
|
|
2065
2067
|
*
|
|
@@ -2084,7 +2086,7 @@ function createToolFunction(tools, name) {
|
|
|
2084
2086
|
return async (controller) => {
|
|
2085
2087
|
const tool = tools.tool(name);
|
|
2086
2088
|
if (tool === void 0) throw new ToolboxError("TOOL", `tool '${name}' is not registered`, { tool: name });
|
|
2087
|
-
const result = (0, _orkestrel_contract.parseJSONValue)(await tool.execute(controller.input));
|
|
2089
|
+
const result = (0, _orkestrel_contract.parseJSONValue)(await tool.execute(controller.input, { signal: controller.signal }));
|
|
2088
2090
|
if (result === void 0) throw new ToolboxError("TOOL", `tool '${name}' returned a non-JSON value`, { tool: name });
|
|
2089
2091
|
return result;
|
|
2090
2092
|
};
|
|
@@ -2886,11 +2888,14 @@ function createDatabaseDefinitionStore(driver = (0, _orkestrel_database.createMe
|
|
|
2886
2888
|
* import { createDatabaseTool } from '@src/core'
|
|
2887
2889
|
*
|
|
2888
2890
|
* const tool = createDatabaseTool()
|
|
2889
|
-
* await tool.execute(
|
|
2890
|
-
*
|
|
2891
|
-
*
|
|
2892
|
-
*
|
|
2893
|
-
* }
|
|
2891
|
+
* await tool.execute(
|
|
2892
|
+
* {
|
|
2893
|
+
* operation: 'create',
|
|
2894
|
+
* id: 'shop',
|
|
2895
|
+
* tables: { products: { columns: { name: 'string', price: 'number' } } },
|
|
2896
|
+
* },
|
|
2897
|
+
* { signal: new AbortController().signal },
|
|
2898
|
+
* )
|
|
2894
2899
|
* ```
|
|
2895
2900
|
*/
|
|
2896
2901
|
function createDatabaseTool(options = {}) {
|
|
@@ -3086,7 +3091,10 @@ function createDatabaseTool(options = {}) {
|
|
|
3086
3091
|
* import { createRelationTool } from '@src/core'
|
|
3087
3092
|
*
|
|
3088
3093
|
* const tool = createRelationTool({ managers: { shop: manager } })
|
|
3089
|
-
* await tool.execute(
|
|
3094
|
+
* await tool.execute(
|
|
3095
|
+
* { operation: 'load', model: 'accounts', key: 'acc1', include: ['contacts'] },
|
|
3096
|
+
* { signal: new AbortController().signal },
|
|
3097
|
+
* )
|
|
3090
3098
|
* ```
|
|
3091
3099
|
*/
|
|
3092
3100
|
function createRelationTool(options) {
|
|
@@ -3305,8 +3313,10 @@ function createInferTool(options) {
|
|
|
3305
3313
|
* never asserted, and a key outside the closed inferred schema is silently dropped rather than
|
|
3306
3314
|
* rejected (see {@link import('./types.js').EndpointToolOptions.validate}). With
|
|
3307
3315
|
* `validate: false`, the tool's `execute` passes through the model-supplied `args` to
|
|
3308
|
-
* `definition.execute` without re-validation — the raw-passthrough opt-out.
|
|
3309
|
-
*
|
|
3316
|
+
* `definition.execute` without re-validation — the raw-passthrough opt-out. The execution context
|
|
3317
|
+
* the tool's `execute` receives reaches `definition.execute` unchanged whichever way `args` are
|
|
3318
|
+
* handled, so a handler that reads `context.signal` observes the caller's cancellation. Either way,
|
|
3319
|
+
* the definition's return flows back as the tool call's plain result; a throw propagates uncaught,
|
|
3310
3320
|
* isolated by the `ToolManagerInterface` (`@orkestrel/tool`) into the canonical error envelope
|
|
3311
3321
|
* — never caught or re-wrapped here.
|
|
3312
3322
|
*
|
|
@@ -3359,8 +3369,8 @@ function createEndpointTool(definition, options) {
|
|
|
3359
3369
|
name: definition.name,
|
|
3360
3370
|
description: definition.description,
|
|
3361
3371
|
...parameters === void 0 ? {} : { parameters },
|
|
3362
|
-
execute(args) {
|
|
3363
|
-
return definition.execute(args);
|
|
3372
|
+
execute(args, context) {
|
|
3373
|
+
return definition.execute(args, context);
|
|
3364
3374
|
}
|
|
3365
3375
|
});
|
|
3366
3376
|
const contract = (0, _orkestrel_contract.createContract)((0, _orkestrel_contract.schemaToShape)(objectSchema));
|
|
@@ -3368,13 +3378,13 @@ function createEndpointTool(definition, options) {
|
|
|
3368
3378
|
name: definition.name,
|
|
3369
3379
|
description: definition.description,
|
|
3370
3380
|
...parameters === void 0 ? {} : { parameters },
|
|
3371
|
-
execute(args) {
|
|
3381
|
+
execute(args, context) {
|
|
3372
3382
|
const parsed = contract.parse(args);
|
|
3373
3383
|
if (parsed === void 0 || !(0, _orkestrel_contract.isRecord)(parsed)) throw new ToolboxError("TOOL", "malformed endpoint call arguments", {
|
|
3374
3384
|
name: definition.name,
|
|
3375
3385
|
faults: contract.explain(args)
|
|
3376
3386
|
});
|
|
3377
|
-
return definition.execute(parsed);
|
|
3387
|
+
return definition.execute(parsed, context);
|
|
3378
3388
|
}
|
|
3379
3389
|
});
|
|
3380
3390
|
}
|