@orkestrel/toolbox 0.0.14 → 0.0.16
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 -27
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +2 -1
- package/dist/src/core/index.d.ts +2 -1
- package/dist/src/core/index.js +26 -28
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +4 -8
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +5 -9
- package/dist/src/server/index.js.map +1 -1
- package/package.json +20 -20
package/dist/src/core/index.cjs
CHANGED
|
@@ -633,7 +633,7 @@ var ToolboxError = class extends Error {
|
|
|
633
633
|
* ```
|
|
634
634
|
*/
|
|
635
635
|
function isToolboxError(value) {
|
|
636
|
-
return value
|
|
636
|
+
return (0, _orkestrel_contract.isInstance)(value, ToolboxError);
|
|
637
637
|
}
|
|
638
638
|
//#endregion
|
|
639
639
|
//#region src/core/validators.ts
|
|
@@ -645,7 +645,7 @@ function isToolboxError(value) {
|
|
|
645
645
|
*/
|
|
646
646
|
function isWorkflowLineage(value) {
|
|
647
647
|
const inspected = (0, _orkestrel_contract.attempt)(() => {
|
|
648
|
-
if (!
|
|
648
|
+
if (!(0, _orkestrel_contract.isArray)(value)) return false;
|
|
649
649
|
const seen = /* @__PURE__ */ new Set();
|
|
650
650
|
for (const [index, tag] of value.entries()) {
|
|
651
651
|
if (!(0, _orkestrel_contract.isString)(tag)) return false;
|
|
@@ -665,7 +665,7 @@ function isWorkflowLineage(value) {
|
|
|
665
665
|
*/
|
|
666
666
|
function isAgentFunction(value) {
|
|
667
667
|
const inspected = (0, _orkestrel_contract.attempt)(() => {
|
|
668
|
-
if (
|
|
668
|
+
if (!(0, _orkestrel_contract.isFunction)(value) || !Object.isFrozen(value)) return false;
|
|
669
669
|
const category = Reflect.getOwnPropertyDescriptor(value, "category");
|
|
670
670
|
const lineage = Reflect.getOwnPropertyDescriptor(value, "lineage");
|
|
671
671
|
return category?.value === "agent" && lineage !== void 0 && "value" in lineage && Object.isFrozen(lineage.value) && isWorkflowLineage(lineage.value);
|
|
@@ -681,7 +681,7 @@ function isAgentFunction(value) {
|
|
|
681
681
|
function isColumnSpec(value) {
|
|
682
682
|
if (isColumnPrimitive(value)) return true;
|
|
683
683
|
if (!(0, _orkestrel_contract.isRecord)(value)) return false;
|
|
684
|
-
return isColumnPrimitive(value.primitive) && (value.optional === void 0 ||
|
|
684
|
+
return isColumnPrimitive(value.primitive) && (value.optional === void 0 || (0, _orkestrel_contract.isBoolean)(value.optional));
|
|
685
685
|
}
|
|
686
686
|
/**
|
|
687
687
|
* Narrows an unknown value to a {@link ColumnPrimitive}.
|
|
@@ -689,9 +689,7 @@ function isColumnSpec(value) {
|
|
|
689
689
|
* @param value - The value to inspect
|
|
690
690
|
* @returns True if `value` is `'string'`, `'integer'`, `'number'`, or `'boolean'`; false otherwise
|
|
691
691
|
*/
|
|
692
|
-
|
|
693
|
-
return value === "string" || value === "integer" || value === "number" || value === "boolean";
|
|
694
|
-
}
|
|
692
|
+
var isColumnPrimitive = (0, _orkestrel_contract.literalOf)("string", "integer", "number", "boolean");
|
|
695
693
|
/**
|
|
696
694
|
* Narrows an unknown value to a {@link DatabaseDefinition} — a non-empty `id` and `driver`, a
|
|
697
695
|
* `tables` record whose every value is `{ columns: record of valid ColumnSpec }`, plus optional
|
|
@@ -718,9 +716,9 @@ function isDatabaseDefinition(value) {
|
|
|
718
716
|
if (value.indexes !== void 0) {
|
|
719
717
|
if (!(0, _orkestrel_contract.isRecord)(value.indexes)) return false;
|
|
720
718
|
for (const groups of Object.values(value.indexes)) {
|
|
721
|
-
if (!
|
|
719
|
+
if (!(0, _orkestrel_contract.isArray)(groups)) return false;
|
|
722
720
|
for (const group of groups) {
|
|
723
|
-
if (!
|
|
721
|
+
if (!(0, _orkestrel_contract.isArray)(group) || group.length === 0) return false;
|
|
724
722
|
for (const column of group) if (!(0, _orkestrel_contract.isNonEmptyString)(column)) return false;
|
|
725
723
|
}
|
|
726
724
|
}
|
|
@@ -1576,7 +1574,7 @@ function expandInclude(paths, depth) {
|
|
|
1576
1574
|
});
|
|
1577
1575
|
ancestors.push(branch);
|
|
1578
1576
|
const existing = branch[segment];
|
|
1579
|
-
branch =
|
|
1577
|
+
branch = (0, _orkestrel_contract.isObject)(existing) ? existing : {};
|
|
1580
1578
|
}
|
|
1581
1579
|
const leaf = segments[last];
|
|
1582
1580
|
if (leaf === void 0) throw new ToolboxError("TOOL", `malformed include path '${path}'`, {
|
|
@@ -2211,7 +2209,7 @@ function createWorkflowFunctions(runner, options) {
|
|
|
2211
2209
|
const composed = {};
|
|
2212
2210
|
Object.setPrototypeOf(composed, null);
|
|
2213
2211
|
for (const [name, fn] of Object.entries(functions)) {
|
|
2214
|
-
if (
|
|
2212
|
+
if (!(0, _orkestrel_contract.isFunction)(fn)) throw new ToolboxError("TOOL", `workflow function '${name}' is not callable`, { function: name });
|
|
2215
2213
|
if (isAgentFunction(fn)) throw new ToolboxError("TOOL", `agent function '${name}' must be supplied through agents`, { function: name });
|
|
2216
2214
|
composed[name] = fn;
|
|
2217
2215
|
}
|
|
@@ -2340,7 +2338,7 @@ function createWorkflowTool(definition, runner, options) {
|
|
|
2340
2338
|
const owned = cloned.value;
|
|
2341
2339
|
let target;
|
|
2342
2340
|
if (Object.keys(owned).length === 0) target = definition;
|
|
2343
|
-
else if (
|
|
2341
|
+
else if ((0, _orkestrel_contract.isArray)(owned.steps)) {
|
|
2344
2342
|
const flat = steps.parse(owned);
|
|
2345
2343
|
target = flat === void 0 ? void 0 : expandSteps(flat);
|
|
2346
2344
|
} else {
|
|
@@ -2899,7 +2897,7 @@ function createDatabaseDefinitionStore(driver = (0, _orkestrel_database.createMe
|
|
|
2899
2897
|
* ```
|
|
2900
2898
|
*/
|
|
2901
2899
|
function createDatabaseTool(options = {}) {
|
|
2902
|
-
if (options.timeout !== void 0 && (options.timeout < 0 || !Number.isSafeInteger(options.timeout))) throw new ToolboxError("TOOL", "database timeout must be a nonnegative safe integer", { timeout: options.timeout });
|
|
2900
|
+
if (options.timeout !== void 0 && (options.timeout < 0 || !(0, _orkestrel_contract.isNumber)(options.timeout) || !Number.isSafeInteger(options.timeout))) throw new ToolboxError("TOOL", "database timeout must be a nonnegative safe integer", { timeout: options.timeout });
|
|
2903
2901
|
const contract = (0, _orkestrel_contract.createContract)(databaseToolShape);
|
|
2904
2902
|
const parameters = (0, _orkestrel_contract.schemaToParameters)(contract.schema);
|
|
2905
2903
|
const handles = new Map(Object.entries(options.databases ?? {}));
|
|
@@ -2969,8 +2967,8 @@ function createDatabaseTool(options = {}) {
|
|
|
2969
2967
|
}
|
|
2970
2968
|
case "get": {
|
|
2971
2969
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2972
|
-
const many =
|
|
2973
|
-
const keys =
|
|
2970
|
+
const many = (0, _orkestrel_contract.isArray)(call.key);
|
|
2971
|
+
const keys = (0, _orkestrel_contract.isArray)(call.key) ? call.key : [call.key];
|
|
2974
2972
|
const rows = await table.get(keys);
|
|
2975
2973
|
return many ? { rows } : { row: rows[0] };
|
|
2976
2974
|
}
|
|
@@ -2991,30 +2989,30 @@ function createDatabaseTool(options = {}) {
|
|
|
2991
2989
|
case "aggregate": return { value: await (await resolver.resolve(call.id)).table(call.table).aggregate(call.function, call.column, normalizeQuery(call.query), read) };
|
|
2992
2990
|
case "add": {
|
|
2993
2991
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2994
|
-
const many =
|
|
2995
|
-
const rows =
|
|
2992
|
+
const many = (0, _orkestrel_contract.isArray)(call.row);
|
|
2993
|
+
const rows = (0, _orkestrel_contract.isArray)(call.row) ? call.row : [call.row];
|
|
2996
2994
|
const keys = await table.add(rows, read);
|
|
2997
2995
|
return many ? { keys } : { key: keys[0] };
|
|
2998
2996
|
}
|
|
2999
2997
|
case "set": {
|
|
3000
2998
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3001
|
-
const many =
|
|
3002
|
-
const rows =
|
|
2999
|
+
const many = (0, _orkestrel_contract.isArray)(call.row);
|
|
3000
|
+
const rows = (0, _orkestrel_contract.isArray)(call.row) ? call.row : [call.row];
|
|
3003
3001
|
const keys = await table.set(rows, read);
|
|
3004
3002
|
return many ? { keys } : { key: keys[0] };
|
|
3005
3003
|
}
|
|
3006
3004
|
case "update": {
|
|
3007
3005
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3008
3006
|
const changes = call.changes;
|
|
3009
|
-
const many =
|
|
3010
|
-
const keys =
|
|
3007
|
+
const many = (0, _orkestrel_contract.isArray)(call.key);
|
|
3008
|
+
const keys = (0, _orkestrel_contract.isArray)(call.key) ? call.key : [call.key];
|
|
3011
3009
|
const updated = await table.update(keys, changes, read);
|
|
3012
3010
|
return many ? { updated } : { updated: updated[0] };
|
|
3013
3011
|
}
|
|
3014
3012
|
case "remove": {
|
|
3015
3013
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3016
|
-
const many =
|
|
3017
|
-
const keys =
|
|
3014
|
+
const many = (0, _orkestrel_contract.isArray)(call.key);
|
|
3015
|
+
const keys = (0, _orkestrel_contract.isArray)(call.key) ? call.key : [call.key];
|
|
3018
3016
|
const removed = await table.remove(keys, read);
|
|
3019
3017
|
return many ? { removed } : { removed: removed[0] };
|
|
3020
3018
|
}
|
|
@@ -3036,7 +3034,7 @@ function createDatabaseTool(options = {}) {
|
|
|
3036
3034
|
if (isToolboxError(error)) throw error;
|
|
3037
3035
|
const code = inferDatabaseCode(error);
|
|
3038
3036
|
if (code === void 0) throw error;
|
|
3039
|
-
throw new ToolboxError("DATABASE", error
|
|
3037
|
+
throw new ToolboxError("DATABASE", (0, _orkestrel_contract.isError)(error) ? error.message : String(error), {
|
|
3040
3038
|
code,
|
|
3041
3039
|
operation: call.operation,
|
|
3042
3040
|
id: call.id,
|
|
@@ -3115,7 +3113,7 @@ function createRelationTool(options) {
|
|
|
3115
3113
|
switch (call.operation) {
|
|
3116
3114
|
case "load": {
|
|
3117
3115
|
const include = expandInclude(call.include, depth);
|
|
3118
|
-
if (
|
|
3116
|
+
if ((0, _orkestrel_contract.isString)(call.key) || (0, _orkestrel_contract.isNumber)(call.key)) return { row: await model.load(call.key, include) };
|
|
3119
3117
|
return { rows: await model.load(call.key, include) };
|
|
3120
3118
|
}
|
|
3121
3119
|
case "find": {
|
|
@@ -3158,7 +3156,7 @@ function createRelationTool(options) {
|
|
|
3158
3156
|
} catch (error) {
|
|
3159
3157
|
if (isToolboxError(error)) throw error;
|
|
3160
3158
|
const relation = inferRelationCode(error);
|
|
3161
|
-
if (relation !== void 0) throw new ToolboxError("RELATION", error
|
|
3159
|
+
if (relation !== void 0) throw new ToolboxError("RELATION", (0, _orkestrel_contract.isError)(error) ? error.message : String(error), {
|
|
3162
3160
|
code: relation,
|
|
3163
3161
|
operation: call.operation,
|
|
3164
3162
|
model: call.model,
|
|
@@ -3166,7 +3164,7 @@ function createRelationTool(options) {
|
|
|
3166
3164
|
});
|
|
3167
3165
|
const database = inferDatabaseCode(error);
|
|
3168
3166
|
if (database === void 0) throw error;
|
|
3169
|
-
throw new ToolboxError("DATABASE", error
|
|
3167
|
+
throw new ToolboxError("DATABASE", (0, _orkestrel_contract.isError)(error) ? error.message : String(error), {
|
|
3170
3168
|
code: database,
|
|
3171
3169
|
operation: call.operation
|
|
3172
3170
|
});
|