@orkestrel/tool 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/core/index.cjs +340 -0
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +265 -0
- package/dist/src/core/index.d.ts +265 -0
- package/dist/src/core/index.js +336 -2
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.d.cts +125 -3
- package/dist/src/server/index.d.ts +125 -3
- package/package.json +7 -5
- package/dist/src/server/constants.d.ts +0 -12
- package/dist/src/server/factories.d.ts +0 -44
- package/dist/src/server/types.d.ts +0 -60
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayShape, booleanShape, createContract, integerShape, isNonEmptyString, isRecord, isString, jsonShape, literalShape, numberShape, objectShape, optionalShape, rawShape, recordShape, schemaToParameters, stringShape, unionShape } from "@orkestrel/contract";
|
|
1
|
+
import { arrayShape, booleanShape, createContract, integerShape, isNonEmptyString, isRecord, isString, jsonShape, literalShape, numberShape, objectShape, optionalShape, rawShape, recordShape, samplesToSchema, schemaToObject, schemaToParameters, schemaToShape, stringShape, unionShape } from "@orkestrel/contract";
|
|
2
2
|
import { isTerminalError } from "@orkestrel/terminal";
|
|
3
3
|
import { createDatabase, createMemoryDriver, generateUUID, isDatabaseError, shapeToColumnType } from "@orkestrel/database";
|
|
4
4
|
import { isRelationError } from "@orkestrel/relation";
|
|
@@ -424,6 +424,108 @@ var RELATION_TOOL_DESCRIPTION = [
|
|
|
424
424
|
var RELATION_TOOL_LIMIT = 1e3;
|
|
425
425
|
/** The default cap on how many `include` path segments deep a `load` / `find` call may traverse — the relation tool's default include-depth ceiling. */
|
|
426
426
|
var RELATION_TOOL_DEPTH = 3;
|
|
427
|
+
/**
|
|
428
|
+
* The name {@link import('./factories.js').createInferTool} advertises by default — the key a
|
|
429
|
+
* model calls and the `ToolManagerInterface` (`@orkestrel/agent`) registers under.
|
|
430
|
+
*/
|
|
431
|
+
var INFER_TOOL_NAME = "infer";
|
|
432
|
+
/**
|
|
433
|
+
* The lean {@link import('@orkestrel/agent').ToolInterface.summary} {@link import('./factories.js').createInferTool}
|
|
434
|
+
* advertises in place of {@link INFER_TOOL_DESCRIPTION} — a `ToolManagerInterface.definitions()`
|
|
435
|
+
* (`@orkestrel/agent`) advertises `summary ?? description`, so this one-sentence text stands in
|
|
436
|
+
* for the full teaching description; the full text stays retrievable via
|
|
437
|
+
* {@link import('./factories.js').createDescribeTool}.
|
|
438
|
+
*/
|
|
439
|
+
var INFER_TOOL_SUMMARY = "Infer a JSON Schema (as advertised tool parameters) from one or more example values. Call describe('infer') for the required fields.";
|
|
440
|
+
var INFER_TOOL_DESCRIPTION = [
|
|
441
|
+
"Infer a JSON Schema from example values, returned in the same shape a tool advertises its parameters.",
|
|
442
|
+
"",
|
|
443
|
+
"Required:",
|
|
444
|
+
" samples - an array of at least one example value to infer the schema from.",
|
|
445
|
+
"Optional:",
|
|
446
|
+
" format - infer string formats (date-time, email, ...) from the samples. Defaults to false.",
|
|
447
|
+
" enum - infer enum constraints from repeated literal values across the samples. Defaults to false.",
|
|
448
|
+
" candidates - values to check against the freshly inferred schema. When present, the result",
|
|
449
|
+
" is wrapped as { parameters, checks } instead of the bare parameters record, one",
|
|
450
|
+
" check per candidate (same index). Every check has the uniform shape",
|
|
451
|
+
" { index, valid, coercible, faults? }. `valid` is a STRICT verdict (no coercion)",
|
|
452
|
+
" — e.g. the number 7 is NOT valid against a string slot. `coercible` answers a",
|
|
453
|
+
" separate question: would the SAME value be accepted by an endpoint tool call,",
|
|
454
|
+
" whose enforcement NORMALIZES args (7 coerces to '7')? So 7 against a string slot",
|
|
455
|
+
" yields { valid: false, coercible: true, faults: [] } — a strict mismatch that",
|
|
456
|
+
" normalization would silently accept, so faults is EMPTY. `faults` only ever",
|
|
457
|
+
" populates for a non-coercible mismatch (a wrong type normalization cannot fix,",
|
|
458
|
+
" a missing required key, an out-of-enum value); checks never throw, regardless of",
|
|
459
|
+
" candidate shape.",
|
|
460
|
+
"Example (no candidates):",
|
|
461
|
+
` in: ${JSON.stringify({ samples: [{
|
|
462
|
+
id: 1,
|
|
463
|
+
name: "Ada"
|
|
464
|
+
}, {
|
|
465
|
+
id: 2,
|
|
466
|
+
name: "Bob"
|
|
467
|
+
}] })}`,
|
|
468
|
+
` out: ${JSON.stringify({
|
|
469
|
+
type: "object",
|
|
470
|
+
properties: {
|
|
471
|
+
id: { type: "integer" },
|
|
472
|
+
name: { type: "string" }
|
|
473
|
+
},
|
|
474
|
+
required: ["id", "name"],
|
|
475
|
+
additionalProperties: false
|
|
476
|
+
})}`,
|
|
477
|
+
"Example (with candidates):",
|
|
478
|
+
` in: ${JSON.stringify({
|
|
479
|
+
samples: [{
|
|
480
|
+
id: 1,
|
|
481
|
+
name: "Ada"
|
|
482
|
+
}],
|
|
483
|
+
candidates: [
|
|
484
|
+
{
|
|
485
|
+
id: 3,
|
|
486
|
+
name: "Cy"
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
id: "x",
|
|
490
|
+
name: "Cy"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
id: 1,
|
|
494
|
+
name: 7
|
|
495
|
+
}
|
|
496
|
+
]
|
|
497
|
+
})}`,
|
|
498
|
+
` out: ${JSON.stringify({
|
|
499
|
+
parameters: {
|
|
500
|
+
type: "object",
|
|
501
|
+
properties: {
|
|
502
|
+
id: { type: "integer" },
|
|
503
|
+
name: { type: "string" }
|
|
504
|
+
},
|
|
505
|
+
required: ["id", "name"],
|
|
506
|
+
additionalProperties: false
|
|
507
|
+
},
|
|
508
|
+
checks: [
|
|
509
|
+
{
|
|
510
|
+
index: 0,
|
|
511
|
+
valid: true,
|
|
512
|
+
coercible: true
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
index: 1,
|
|
516
|
+
valid: false,
|
|
517
|
+
coercible: false,
|
|
518
|
+
faults: "<structured faults>"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
index: 2,
|
|
522
|
+
valid: false,
|
|
523
|
+
coercible: true,
|
|
524
|
+
faults: []
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
})}`
|
|
528
|
+
].join("\n");
|
|
427
529
|
//#endregion
|
|
428
530
|
//#region src/core/errors.ts
|
|
429
531
|
/**
|
|
@@ -1105,6 +1207,28 @@ var relationToolShape = unionShape(objectShape({
|
|
|
1105
1207
|
description: "The \"through\" relation name."
|
|
1106
1208
|
})
|
|
1107
1209
|
}));
|
|
1210
|
+
/**
|
|
1211
|
+
* The shape of {@link import('./factories.js').createInferTool}'s call arguments — one or more
|
|
1212
|
+
* example `samples` to infer a JSON Schema from, plus per-call `format` / `enum` toggles and an
|
|
1213
|
+
* optional `candidates` array to check against the inferred schema.
|
|
1214
|
+
*
|
|
1215
|
+
* @remarks
|
|
1216
|
+
* `samples` requires at least one element (`min: 1`) — an empty array parses to `undefined`,
|
|
1217
|
+
* surfaced by the handler as a typed `TOOL` {@link import('./errors.js').AgentToolError}. When
|
|
1218
|
+
* `candidates` is present (any array, including empty), the handler compiles a contract from the
|
|
1219
|
+
* freshly inferred schema and checks each candidate against it with a STRICT guard (`.is`, no
|
|
1220
|
+
* coercion) — the opposite of {@link import('./factories.js').createEndpointTool}'s NORMALIZING
|
|
1221
|
+
* `.parse` enforcement.
|
|
1222
|
+
*/
|
|
1223
|
+
var inferToolShape = objectShape({
|
|
1224
|
+
samples: arrayShape(jsonShape(), {
|
|
1225
|
+
min: 1,
|
|
1226
|
+
description: "The example values to infer a JSON Schema from (at least one)."
|
|
1227
|
+
}),
|
|
1228
|
+
format: optionalShape(booleanShape({ description: "Infer string formats (date-time, email, ...) from the samples. Defaults to false." })),
|
|
1229
|
+
enum: optionalShape(booleanShape({ description: "Infer enum constraints from repeated literal values. Defaults to false." })),
|
|
1230
|
+
candidates: optionalShape(arrayShape(jsonShape(), { description: "Optional values to check against the freshly inferred schema. When present, the tool returns a per-candidate verdict (strict — no coercion) alongside the inferred parameters." }))
|
|
1231
|
+
});
|
|
1108
1232
|
//#endregion
|
|
1109
1233
|
//#region src/core/helpers.ts
|
|
1110
1234
|
/**
|
|
@@ -2819,7 +2943,217 @@ function createRelationTool(options) {
|
|
|
2819
2943
|
}
|
|
2820
2944
|
});
|
|
2821
2945
|
}
|
|
2946
|
+
/**
|
|
2947
|
+
* Build a standalone LLM-callable tool that infers a JSON Schema from example values — the
|
|
2948
|
+
* utility half of the "existing API/DB → MCP tool" bridge (the other half,
|
|
2949
|
+
* {@link createEndpointTool}, wraps one CONCRETE endpoint).
|
|
2950
|
+
*
|
|
2951
|
+
* @remarks
|
|
2952
|
+
* The universal tool-handler contract (AGENTS §14): validates the call args against
|
|
2953
|
+
* {@link import('./shapers.js').inferToolShape} (`samples` non-empty, `format` / `enum` optional
|
|
2954
|
+
* booleans, `candidates` an optional array), infers a schema via `@orkestrel/contract`'s
|
|
2955
|
+
* `samplesToSchema`, wraps a non-object root as `{ value: <schema> }` via `schemaToObject` (mirrors
|
|
2956
|
+
* the tool-parameters convention every other `create*Tool` factory advertises), and RETURNS the
|
|
2957
|
+
* resulting parameters record. An empty `samples` array fails `inferToolShape`'s `min: 1` bound —
|
|
2958
|
+
* `contract.parse` returns `undefined` and the handler throws a typed `TOOL`
|
|
2959
|
+
* {@link import('./errors.js').AgentToolError}.
|
|
2960
|
+
*
|
|
2961
|
+
* When `candidates` is ABSENT, the return is the bare parameters record — unchanged from before
|
|
2962
|
+
* this array existed. When `candidates` is PRESENT (any array, including empty), the handler
|
|
2963
|
+
* compiles a SEPARATE per-call contract from the RAW inferred schema (via `@orkestrel/contract`'s
|
|
2964
|
+
* `schemaToShape`, NOT the `schemaToObject`-wrapped parameters — a bare-value sample checks a
|
|
2965
|
+
* bare-value candidate) and returns `{ parameters, checks }`, one check per candidate at the same
|
|
2966
|
+
* index. Every entry has a UNIFORM shape — `{ index, valid, coercible }`, with `faults` added ONLY
|
|
2967
|
+
* when `valid` is `false`: `valid` is the STRICT guard verdict (`checker.is(candidate)`), the
|
|
2968
|
+
* OPPOSITE of {@link createEndpointTool}'s enforcement, which coerces (`7` becomes `'7'` for a
|
|
2969
|
+
* string slot) — here a conformance report answers "does this value conform AS-IS": `7` against a
|
|
2970
|
+
* string slot is `valid: false`, full stop. `coercible` answers a SEPARATE question — "would the
|
|
2971
|
+
* NORMALIZING parse accept this value", i.e. would {@link createEndpointTool}'s default enforcement
|
|
2972
|
+
* admit it (`checker.parse(candidate) !== undefined`) — computed for every candidate regardless of
|
|
2973
|
+
* `valid`; by the house parse/guard round-trip guarantee (AGENTS §14), a `valid: true` entry is
|
|
2974
|
+
* ALWAYS also `coercible: true`. `@orkestrel/contract` 0.0.7's `explain` mirrors the normalizing
|
|
2975
|
+
* `parse`'s leniency, not `is`'s strictness — so a strictly-invalid but coercible candidate (`7`
|
|
2976
|
+
* against a string slot) yields `{ valid: false, coercible: true, faults: [] }`: EMPTY faults, since
|
|
2977
|
+
* the mismatch the normalizing parse would silently fix is not one `explain` reports. `faults`
|
|
2978
|
+
* therefore only ever populates for a NON-coercible mismatch — a wrong type the parse can't coerce
|
|
2979
|
+
* (a boolean in a string slot), a missing required key, or an out-of-enum value — where
|
|
2980
|
+
* `coercible: false`. `checker.is` / `.parse` / `.explain` are all total over JSON-safe input — a
|
|
2981
|
+
* JSON-safe hostile candidate (a `__proto__`-carrying object, deeply nested data) reaches all three
|
|
2982
|
+
* and yields a bounded, non-throwing per-candidate verdict; a NON-JSON-safe candidate (e.g. a
|
|
2983
|
+
* throwing-getter `Proxy`) never reaches the checker at all — it fails the OUTER `args` parse
|
|
2984
|
+
* against {@link import('./shapers.js').inferToolShape} and rejects the WHOLE call with the same
|
|
2985
|
+
* `TOOL` {@link import('./errors.js').AgentToolError} a malformed `samples`/`format`/`enum` throws,
|
|
2986
|
+
* with no per-candidate verdict produced.
|
|
2987
|
+
*
|
|
2988
|
+
* @param options - Advertised `name` / `description` overrides (see
|
|
2989
|
+
* {@link import('./types.js').InferToolOptions})
|
|
2990
|
+
* @returns A `ToolInterface` (named {@link import('./constants.js').INFER_TOOL_NAME} by default)
|
|
2991
|
+
*
|
|
2992
|
+
* @example
|
|
2993
|
+
* ```ts
|
|
2994
|
+
* import { createInferTool } from '@src/core'
|
|
2995
|
+
* import { createToolManager } from '@orkestrel/agent'
|
|
2996
|
+
*
|
|
2997
|
+
* const tool = createInferTool()
|
|
2998
|
+
* const tools = createToolManager()
|
|
2999
|
+
* tools.add(tool)
|
|
3000
|
+
*
|
|
3001
|
+
* const result = await tools.execute({
|
|
3002
|
+
* id: 'call-1',
|
|
3003
|
+
* name: 'infer',
|
|
3004
|
+
* arguments: { samples: [{ id: 1, name: 'Ada' }, { id: 2, name: 'Bob' }] },
|
|
3005
|
+
* })
|
|
3006
|
+
* // result.value -> { type: 'object', properties: { id: {...}, name: {...} }, ... }
|
|
3007
|
+
*
|
|
3008
|
+
* // with candidates, the result is wrapped with per-candidate verdicts
|
|
3009
|
+
* const checked = await tools.execute({
|
|
3010
|
+
* id: 'call-2',
|
|
3011
|
+
* name: 'infer',
|
|
3012
|
+
* arguments: {
|
|
3013
|
+
* samples: [{ id: 1, name: 'Ada' }],
|
|
3014
|
+
* candidates: [{ id: 2, name: 'Bob' }, { id: 'x', name: 'Cy' }],
|
|
3015
|
+
* },
|
|
3016
|
+
* })
|
|
3017
|
+
* // checked.value -> { parameters: {...}, checks: [
|
|
3018
|
+
* // { index: 0, valid: true, coercible: true },
|
|
3019
|
+
* // { index: 1, valid: false, coercible: false, faults: [...] },
|
|
3020
|
+
* // ] }
|
|
3021
|
+
* ```
|
|
3022
|
+
*/
|
|
3023
|
+
function createInferTool(options) {
|
|
3024
|
+
const contract = createContract(inferToolShape);
|
|
3025
|
+
const parameters = schemaToParameters(contract.schema);
|
|
3026
|
+
return createTool({
|
|
3027
|
+
name: options?.name ?? "infer",
|
|
3028
|
+
description: options?.description ?? INFER_TOOL_DESCRIPTION,
|
|
3029
|
+
summary: INFER_TOOL_SUMMARY,
|
|
3030
|
+
parameters,
|
|
3031
|
+
execute: async (args) => {
|
|
3032
|
+
const parsed = contract.parse(args);
|
|
3033
|
+
if (parsed === void 0) throw new AgentToolError("TOOL", "malformed infer arguments", { args });
|
|
3034
|
+
const schema = samplesToSchema(parsed.samples, {
|
|
3035
|
+
format: parsed.format ?? false,
|
|
3036
|
+
enum: parsed.enum ?? false
|
|
3037
|
+
});
|
|
3038
|
+
const result = schemaToParameters(schemaToObject(schema));
|
|
3039
|
+
if (result === void 0) throw new AgentToolError("TOOL", "could not infer a schema", { args });
|
|
3040
|
+
if (parsed.candidates === void 0) return result;
|
|
3041
|
+
const checker = createContract(schemaToShape(schema));
|
|
3042
|
+
return {
|
|
3043
|
+
parameters: result,
|
|
3044
|
+
checks: parsed.candidates.map((candidate, index) => {
|
|
3045
|
+
const valid = checker.is(candidate);
|
|
3046
|
+
const coercible = checker.parse(candidate) !== void 0;
|
|
3047
|
+
return valid ? {
|
|
3048
|
+
index,
|
|
3049
|
+
valid,
|
|
3050
|
+
coercible
|
|
3051
|
+
} : {
|
|
3052
|
+
index,
|
|
3053
|
+
valid,
|
|
3054
|
+
coercible,
|
|
3055
|
+
faults: checker.explain(candidate)
|
|
3056
|
+
};
|
|
3057
|
+
})
|
|
3058
|
+
};
|
|
3059
|
+
}
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Wrap one CONCRETE endpoint ({@link import('./types.js').EndpointDefinition}) as an LLM-callable
|
|
3064
|
+
* `ToolInterface` — the endpoint half of the "existing API/DB → MCP tool" bridge (the other half,
|
|
3065
|
+
* {@link createInferTool}, is a standalone inference utility).
|
|
3066
|
+
*
|
|
3067
|
+
* @remarks
|
|
3068
|
+
* `parameters` is inferred ONCE at construction from `definition.samples` via
|
|
3069
|
+
* `@orkestrel/contract`'s `samplesToSchema` (tuned by {@link import('./types.js').EndpointToolOptions}'s
|
|
3070
|
+
* `format` / `enum`), wrapping a non-object root as `{ value: <schema> }` via `schemaToObject` —
|
|
3071
|
+
* the SAME object-rooted schema is both the ADVERTISED `parameters` and, by default
|
|
3072
|
+
* ({@link import('./types.js').EndpointToolOptions.validate} `true`), the ENFORCED contract:
|
|
3073
|
+
* `@orkestrel/contract` 0.0.7's `schemaToShape` compiles it ONCE (via `createContract`) into a
|
|
3074
|
+
* `ContractInterface` whose `.parse` runs on every call's `args` before `definition.invoke` — a
|
|
3075
|
+
* NORMALIZING parse, not a strict type check: a scalar is COERCED to its inferred type where the
|
|
3076
|
+
* house parsers coerce (a number to/from a numeric string, a boolean from `'1'`/`'0'`/`'true'`/
|
|
3077
|
+
* `'false'`/`1`/`0`), so `definition.invoke` receives the COERCED value (e.g. `7` sent for a
|
|
3078
|
+
* string slot arrives as `'7'`), not the raw call value. A call whose `args` fails to parse into
|
|
3079
|
+
* a record — a required key missing, or a value not coercible to its slot's type — THROWS a
|
|
3080
|
+
* typed `TOOL` {@link import('./errors.js').AgentToolError} carrying the compiled contract's
|
|
3081
|
+
* structured `explain` faults, and `definition.invoke` is never called. `format` annotations are
|
|
3082
|
+
* NEVER asserted, and a key outside the closed inferred schema is SILENTLY DROPPED rather than
|
|
3083
|
+
* rejected (see {@link import('./types.js').EndpointToolOptions.validate}). With
|
|
3084
|
+
* `validate: false`, `execute` PASSES THROUGH the model-supplied `args` to `definition.invoke`
|
|
3085
|
+
* WITHOUT re-validation — the pre-0.0.7 behavior, preserved as an explicit opt-out. Either way,
|
|
3086
|
+
* `invoke`'s return flows back as the tool call's plain result; a throw PROPAGATES uncaught,
|
|
3087
|
+
* isolated by the `ToolManagerInterface` (`@orkestrel/agent`) into the canonical error envelope
|
|
3088
|
+
* (AGENTS §14) — never caught or re-wrapped here.
|
|
3089
|
+
*
|
|
3090
|
+
* @param definition - The endpoint's identity, non-empty samples, and local handler (see
|
|
3091
|
+
* {@link import('./types.js').EndpointDefinition})
|
|
3092
|
+
* @param options - Construction-time inference tuning + the validate opt-out (see
|
|
3093
|
+
* {@link import('./types.js').EndpointToolOptions})
|
|
3094
|
+
* @returns A `ToolInterface` named `definition.name`
|
|
3095
|
+
*
|
|
3096
|
+
* @example
|
|
3097
|
+
* ```ts
|
|
3098
|
+
* import { createEndpointTool } from '@src/core'
|
|
3099
|
+
* import { createToolManager } from '@orkestrel/agent'
|
|
3100
|
+
*
|
|
3101
|
+
* const tool = createEndpointTool({
|
|
3102
|
+
* name: 'lookupUser',
|
|
3103
|
+
* description: 'Look up a user by id.',
|
|
3104
|
+
* samples: [{ id: '1', name: 'Ada' }, { id: '2', name: 'Bob' }],
|
|
3105
|
+
* invoke: (args) => ({ id: args.id, name: 'Ada' }),
|
|
3106
|
+
* })
|
|
3107
|
+
* const tools = createToolManager()
|
|
3108
|
+
* tools.add(tool)
|
|
3109
|
+
*
|
|
3110
|
+
* // conforming args (all required keys present) parse and reach `invoke`
|
|
3111
|
+
* const result = await tools.execute({
|
|
3112
|
+
* id: 'call-1',
|
|
3113
|
+
* name: 'lookupUser',
|
|
3114
|
+
* arguments: { id: '1', name: 'Ada' },
|
|
3115
|
+
* })
|
|
3116
|
+
* // result.value -> { id: '1', name: 'Ada' }
|
|
3117
|
+
*
|
|
3118
|
+
* // a nonconforming call (id is not coercible to the required string) is rejected before
|
|
3119
|
+
* // `invoke` runs
|
|
3120
|
+
* const rejected = await tools.execute({
|
|
3121
|
+
* id: 'call-2',
|
|
3122
|
+
* name: 'lookupUser',
|
|
3123
|
+
* arguments: { id: true, name: 'Ada' },
|
|
3124
|
+
* })
|
|
3125
|
+
* // rejected.error -> the TOOL AgentToolError message
|
|
3126
|
+
* ```
|
|
3127
|
+
*/
|
|
3128
|
+
function createEndpointTool(definition, options) {
|
|
3129
|
+
if (definition.samples.length === 0) throw new AgentToolError("TOOL", "endpoint requires at least one sample", { name: definition.name });
|
|
3130
|
+
const objectSchema = schemaToObject(samplesToSchema(definition.samples, {
|
|
3131
|
+
format: options?.format ?? false,
|
|
3132
|
+
enum: options?.enum ?? false
|
|
3133
|
+
}));
|
|
3134
|
+
const parameters = schemaToParameters(objectSchema);
|
|
3135
|
+
if (!(options?.validate ?? true)) return createTool({
|
|
3136
|
+
name: definition.name,
|
|
3137
|
+
description: definition.description,
|
|
3138
|
+
parameters,
|
|
3139
|
+
execute: (args) => definition.invoke(args)
|
|
3140
|
+
});
|
|
3141
|
+
const contract = createContract(schemaToShape(objectSchema));
|
|
3142
|
+
return createTool({
|
|
3143
|
+
name: definition.name,
|
|
3144
|
+
description: definition.description,
|
|
3145
|
+
parameters,
|
|
3146
|
+
execute: (args) => {
|
|
3147
|
+
const parsed = contract.parse(args);
|
|
3148
|
+
if (parsed === void 0 || !isRecord(parsed)) throw new AgentToolError("TOOL", "malformed endpoint call arguments", {
|
|
3149
|
+
name: definition.name,
|
|
3150
|
+
faults: contract.explain(args)
|
|
3151
|
+
});
|
|
3152
|
+
return definition.invoke(parsed);
|
|
3153
|
+
}
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
2822
3156
|
//#endregion
|
|
2823
|
-
export { AGENT_TOOL_DEPTH, AGENT_TOOL_DESCRIPTION, AGENT_TOOL_NAME, AGENT_TOOL_SUMMARY, ANSWER_TOOL_DESCRIPTION, ANSWER_TOOL_NAME, ANSWER_TOOL_SUMMARY, AgentToolError, DATABASE_TOOL_DESCRIPTION, DATABASE_TOOL_LIMIT, DATABASE_TOOL_MUTATIONS, DATABASE_TOOL_NAME, DATABASE_TOOL_SUMMARY, DESCRIBE_TOOL_DESCRIPTION, DESCRIBE_TOOL_NAME, DESCRIBE_TOOL_SUMMARY, DatabaseDefinitionStore, MAX_WORKFLOW_DEPTH, MemoryDefinitionStore, PROMPT_TOOL_DESCRIPTION, PROMPT_TOOL_NAME, PROMPT_TOOL_SUMMARY, RELATION_TOOL_DEPTH, RELATION_TOOL_DESCRIPTION, RELATION_TOOL_LIMIT, RELATION_TOOL_NAME, RELATION_TOOL_SUMMARY, WORKFLOW_TOOL_DESCRIPTION, WORKFLOW_TOOL_FLAT_EXAMPLE, WORKFLOW_TOOL_NAME, WORKFLOW_TOOL_NESTED_EXAMPLE, WORKFLOW_TOOL_SUMMARY, WORKSPACE_TOOL_DESCRIPTION, WORKSPACE_TOOL_EXAMPLE, WORKSPACE_TOOL_NAME, WORKSPACE_TOOL_SUMMARY, agentTag, agentToolShape, answerToolShape, clampCriteria, coerceAnswer, columnKindShape, columnSchema, columnShape, columnSpecShape, completeDraft, completePhaseDraft, completeTaskDraft, conditionShape, createAgentFunction, createAgentTool, createAnswerTool, createDatabaseDefinitionStore, createDatabaseTool, createDescribeTool, createMemoryDefinitionStore, createPromptTool, createRelationTool, createToolFunction, createWorkflowDraftContract, createWorkflowTool, createWorkspaceTool, criteriaOf, criteriaShape, databaseToolCode, databaseToolShape, describeToolShape, expandInclude, expandSteps, expandTables, includeShape, isAgentToolError, isColumnKind, isColumnSpec, isDatabaseDefinition, keyShape, kindShape, managerShape, orderShape, phaseDraftShape, promptToolShape, relationKeyShape, relationManagerOf, relationModelOf, relationToolCode, relationToolShape, rowShape, rowsShape, singleKeyShape, stepShape, tableSchema, tableSpecShape, taskDraftShape, terminalToolCode, workflowDraftShape, workflowStepsShape, workflowTag, workflowToolSummary, workspaceToolShape };
|
|
3157
|
+
export { AGENT_TOOL_DEPTH, AGENT_TOOL_DESCRIPTION, AGENT_TOOL_NAME, AGENT_TOOL_SUMMARY, ANSWER_TOOL_DESCRIPTION, ANSWER_TOOL_NAME, ANSWER_TOOL_SUMMARY, AgentToolError, DATABASE_TOOL_DESCRIPTION, DATABASE_TOOL_LIMIT, DATABASE_TOOL_MUTATIONS, DATABASE_TOOL_NAME, DATABASE_TOOL_SUMMARY, DESCRIBE_TOOL_DESCRIPTION, DESCRIBE_TOOL_NAME, DESCRIBE_TOOL_SUMMARY, DatabaseDefinitionStore, INFER_TOOL_DESCRIPTION, INFER_TOOL_NAME, INFER_TOOL_SUMMARY, MAX_WORKFLOW_DEPTH, MemoryDefinitionStore, PROMPT_TOOL_DESCRIPTION, PROMPT_TOOL_NAME, PROMPT_TOOL_SUMMARY, RELATION_TOOL_DEPTH, RELATION_TOOL_DESCRIPTION, RELATION_TOOL_LIMIT, RELATION_TOOL_NAME, RELATION_TOOL_SUMMARY, WORKFLOW_TOOL_DESCRIPTION, WORKFLOW_TOOL_FLAT_EXAMPLE, WORKFLOW_TOOL_NAME, WORKFLOW_TOOL_NESTED_EXAMPLE, WORKFLOW_TOOL_SUMMARY, WORKSPACE_TOOL_DESCRIPTION, WORKSPACE_TOOL_EXAMPLE, WORKSPACE_TOOL_NAME, WORKSPACE_TOOL_SUMMARY, agentTag, agentToolShape, answerToolShape, clampCriteria, coerceAnswer, columnKindShape, columnSchema, columnShape, columnSpecShape, completeDraft, completePhaseDraft, completeTaskDraft, conditionShape, createAgentFunction, createAgentTool, createAnswerTool, createDatabaseDefinitionStore, createDatabaseTool, createDescribeTool, createEndpointTool, createInferTool, createMemoryDefinitionStore, createPromptTool, createRelationTool, createToolFunction, createWorkflowDraftContract, createWorkflowTool, createWorkspaceTool, criteriaOf, criteriaShape, databaseToolCode, databaseToolShape, describeToolShape, expandInclude, expandSteps, expandTables, includeShape, inferToolShape, isAgentToolError, isColumnKind, isColumnSpec, isDatabaseDefinition, keyShape, kindShape, managerShape, orderShape, phaseDraftShape, promptToolShape, relationKeyShape, relationManagerOf, relationModelOf, relationToolCode, relationToolShape, rowShape, rowsShape, singleKeyShape, stepShape, tableSchema, tableSpecShape, taskDraftShape, terminalToolCode, workflowDraftShape, workflowStepsShape, workflowTag, workflowToolSummary, workspaceToolShape };
|
|
2824
3158
|
|
|
2825
3159
|
//# sourceMappingURL=index.js.map
|