@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
|
@@ -10,6 +10,7 @@ import type { ConversationStoreInterface } from '@orkestrel/agent';
|
|
|
10
10
|
import type { DatabaseErrorCode } from '@orkestrel/database';
|
|
11
11
|
import type { DatabaseInterface } from '@orkestrel/database';
|
|
12
12
|
import type { DriverInterface } from '@orkestrel/database';
|
|
13
|
+
import type { Guard } from '@orkestrel/contract';
|
|
13
14
|
import type { Include } from '@orkestrel/relation';
|
|
14
15
|
import type { IndexMap } from '@orkestrel/database';
|
|
15
16
|
import { JSONShape } from '@orkestrel/contract';
|
|
@@ -1800,7 +1801,7 @@ export declare function isAgentFunction(value: unknown): value is AgentFunction;
|
|
|
1800
1801
|
* @param value - The value to inspect
|
|
1801
1802
|
* @returns True if `value` is `'string'`, `'integer'`, `'number'`, or `'boolean'`; false otherwise
|
|
1802
1803
|
*/
|
|
1803
|
-
export declare
|
|
1804
|
+
export declare const isColumnPrimitive: Guard<ColumnPrimitive>;
|
|
1804
1805
|
|
|
1805
1806
|
/**
|
|
1806
1807
|
* Narrows an unknown value to a {@link ColumnSpec}.
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { ConversationStoreInterface } from '@orkestrel/agent';
|
|
|
10
10
|
import type { DatabaseErrorCode } from '@orkestrel/database';
|
|
11
11
|
import type { DatabaseInterface } from '@orkestrel/database';
|
|
12
12
|
import type { DriverInterface } from '@orkestrel/database';
|
|
13
|
+
import type { Guard } from '@orkestrel/contract';
|
|
13
14
|
import type { Include } from '@orkestrel/relation';
|
|
14
15
|
import type { IndexMap } from '@orkestrel/database';
|
|
15
16
|
import { JSONShape } from '@orkestrel/contract';
|
|
@@ -1800,7 +1801,7 @@ export declare function isAgentFunction(value: unknown): value is AgentFunction;
|
|
|
1800
1801
|
* @param value - The value to inspect
|
|
1801
1802
|
* @returns True if `value` is `'string'`, `'integer'`, `'number'`, or `'boolean'`; false otherwise
|
|
1802
1803
|
*/
|
|
1803
|
-
export declare
|
|
1804
|
+
export declare const isColumnPrimitive: Guard<ColumnPrimitive>;
|
|
1804
1805
|
|
|
1805
1806
|
/**
|
|
1806
1807
|
* Narrows an unknown value to a {@link ColumnSpec}.
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayShape, attempt, booleanShape, cloneJSONRecord, createContract, integerShape, isFiniteNumber, isNonEmptyString, isRecord, isString, jsonShape, literalShape, numberShape, objectShape, optionalShape, parseJSONValue, rawShape, recordShape, samplesToSchema, schemaToObject, schemaToParameters, schemaToShape, stringShape, unionShape } from "@orkestrel/contract";
|
|
1
|
+
import { arrayShape, attempt, booleanShape, cloneJSONRecord, createContract, integerShape, isArray, isBoolean, isError, isFiniteNumber, isFunction, isInstance, isNonEmptyString, isNumber, isObject, isRecord, isString, jsonShape, literalOf, literalShape, numberShape, objectShape, optionalShape, parseJSONValue, rawShape, recordShape, samplesToSchema, schemaToObject, schemaToParameters, schemaToShape, stringShape, unionShape } from "@orkestrel/contract";
|
|
2
2
|
import { MAX_TIMER_MS, createWorkflowContract } from "@orkestrel/workflow";
|
|
3
3
|
import { isTerminalError } from "@orkestrel/terminal";
|
|
4
4
|
import { createDatabase, createMemoryDriver, isDatabaseError } from "@orkestrel/database";
|
|
@@ -632,7 +632,7 @@ var ToolboxError = class extends Error {
|
|
|
632
632
|
* ```
|
|
633
633
|
*/
|
|
634
634
|
function isToolboxError(value) {
|
|
635
|
-
return value
|
|
635
|
+
return isInstance(value, ToolboxError);
|
|
636
636
|
}
|
|
637
637
|
//#endregion
|
|
638
638
|
//#region src/core/validators.ts
|
|
@@ -644,7 +644,7 @@ function isToolboxError(value) {
|
|
|
644
644
|
*/
|
|
645
645
|
function isWorkflowLineage(value) {
|
|
646
646
|
const inspected = attempt(() => {
|
|
647
|
-
if (!
|
|
647
|
+
if (!isArray(value)) return false;
|
|
648
648
|
const seen = /* @__PURE__ */ new Set();
|
|
649
649
|
for (const [index, tag] of value.entries()) {
|
|
650
650
|
if (!isString(tag)) return false;
|
|
@@ -664,7 +664,7 @@ function isWorkflowLineage(value) {
|
|
|
664
664
|
*/
|
|
665
665
|
function isAgentFunction(value) {
|
|
666
666
|
const inspected = attempt(() => {
|
|
667
|
-
if (
|
|
667
|
+
if (!isFunction(value) || !Object.isFrozen(value)) return false;
|
|
668
668
|
const category = Reflect.getOwnPropertyDescriptor(value, "category");
|
|
669
669
|
const lineage = Reflect.getOwnPropertyDescriptor(value, "lineage");
|
|
670
670
|
return category?.value === "agent" && lineage !== void 0 && "value" in lineage && Object.isFrozen(lineage.value) && isWorkflowLineage(lineage.value);
|
|
@@ -680,7 +680,7 @@ function isAgentFunction(value) {
|
|
|
680
680
|
function isColumnSpec(value) {
|
|
681
681
|
if (isColumnPrimitive(value)) return true;
|
|
682
682
|
if (!isRecord(value)) return false;
|
|
683
|
-
return isColumnPrimitive(value.primitive) && (value.optional === void 0 ||
|
|
683
|
+
return isColumnPrimitive(value.primitive) && (value.optional === void 0 || isBoolean(value.optional));
|
|
684
684
|
}
|
|
685
685
|
/**
|
|
686
686
|
* Narrows an unknown value to a {@link ColumnPrimitive}.
|
|
@@ -688,9 +688,7 @@ function isColumnSpec(value) {
|
|
|
688
688
|
* @param value - The value to inspect
|
|
689
689
|
* @returns True if `value` is `'string'`, `'integer'`, `'number'`, or `'boolean'`; false otherwise
|
|
690
690
|
*/
|
|
691
|
-
|
|
692
|
-
return value === "string" || value === "integer" || value === "number" || value === "boolean";
|
|
693
|
-
}
|
|
691
|
+
var isColumnPrimitive = literalOf("string", "integer", "number", "boolean");
|
|
694
692
|
/**
|
|
695
693
|
* Narrows an unknown value to a {@link DatabaseDefinition} — a non-empty `id` and `driver`, a
|
|
696
694
|
* `tables` record whose every value is `{ columns: record of valid ColumnSpec }`, plus optional
|
|
@@ -717,9 +715,9 @@ function isDatabaseDefinition(value) {
|
|
|
717
715
|
if (value.indexes !== void 0) {
|
|
718
716
|
if (!isRecord(value.indexes)) return false;
|
|
719
717
|
for (const groups of Object.values(value.indexes)) {
|
|
720
|
-
if (!
|
|
718
|
+
if (!isArray(groups)) return false;
|
|
721
719
|
for (const group of groups) {
|
|
722
|
-
if (!
|
|
720
|
+
if (!isArray(group) || group.length === 0) return false;
|
|
723
721
|
for (const column of group) if (!isNonEmptyString(column)) return false;
|
|
724
722
|
}
|
|
725
723
|
}
|
|
@@ -1575,7 +1573,7 @@ function expandInclude(paths, depth) {
|
|
|
1575
1573
|
});
|
|
1576
1574
|
ancestors.push(branch);
|
|
1577
1575
|
const existing = branch[segment];
|
|
1578
|
-
branch =
|
|
1576
|
+
branch = isObject(existing) ? existing : {};
|
|
1579
1577
|
}
|
|
1580
1578
|
const leaf = segments[last];
|
|
1581
1579
|
if (leaf === void 0) throw new ToolboxError("TOOL", `malformed include path '${path}'`, {
|
|
@@ -2210,7 +2208,7 @@ function createWorkflowFunctions(runner, options) {
|
|
|
2210
2208
|
const composed = {};
|
|
2211
2209
|
Object.setPrototypeOf(composed, null);
|
|
2212
2210
|
for (const [name, fn] of Object.entries(functions)) {
|
|
2213
|
-
if (
|
|
2211
|
+
if (!isFunction(fn)) throw new ToolboxError("TOOL", `workflow function '${name}' is not callable`, { function: name });
|
|
2214
2212
|
if (isAgentFunction(fn)) throw new ToolboxError("TOOL", `agent function '${name}' must be supplied through agents`, { function: name });
|
|
2215
2213
|
composed[name] = fn;
|
|
2216
2214
|
}
|
|
@@ -2339,7 +2337,7 @@ function createWorkflowTool(definition, runner, options) {
|
|
|
2339
2337
|
const owned = cloned.value;
|
|
2340
2338
|
let target;
|
|
2341
2339
|
if (Object.keys(owned).length === 0) target = definition;
|
|
2342
|
-
else if (
|
|
2340
|
+
else if (isArray(owned.steps)) {
|
|
2343
2341
|
const flat = steps.parse(owned);
|
|
2344
2342
|
target = flat === void 0 ? void 0 : expandSteps(flat);
|
|
2345
2343
|
} else {
|
|
@@ -2898,7 +2896,7 @@ function createDatabaseDefinitionStore(driver = createMemoryDriver()) {
|
|
|
2898
2896
|
* ```
|
|
2899
2897
|
*/
|
|
2900
2898
|
function createDatabaseTool(options = {}) {
|
|
2901
|
-
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 });
|
|
2899
|
+
if (options.timeout !== void 0 && (options.timeout < 0 || !isNumber(options.timeout) || !Number.isSafeInteger(options.timeout))) throw new ToolboxError("TOOL", "database timeout must be a nonnegative safe integer", { timeout: options.timeout });
|
|
2902
2900
|
const contract = createContract(databaseToolShape);
|
|
2903
2901
|
const parameters = schemaToParameters(contract.schema);
|
|
2904
2902
|
const handles = new Map(Object.entries(options.databases ?? {}));
|
|
@@ -2968,8 +2966,8 @@ function createDatabaseTool(options = {}) {
|
|
|
2968
2966
|
}
|
|
2969
2967
|
case "get": {
|
|
2970
2968
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2971
|
-
const many =
|
|
2972
|
-
const keys =
|
|
2969
|
+
const many = isArray(call.key);
|
|
2970
|
+
const keys = isArray(call.key) ? call.key : [call.key];
|
|
2973
2971
|
const rows = await table.get(keys);
|
|
2974
2972
|
return many ? { rows } : { row: rows[0] };
|
|
2975
2973
|
}
|
|
@@ -2990,30 +2988,30 @@ function createDatabaseTool(options = {}) {
|
|
|
2990
2988
|
case "aggregate": return { value: await (await resolver.resolve(call.id)).table(call.table).aggregate(call.function, call.column, normalizeQuery(call.query), read) };
|
|
2991
2989
|
case "add": {
|
|
2992
2990
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2993
|
-
const many =
|
|
2994
|
-
const rows =
|
|
2991
|
+
const many = isArray(call.row);
|
|
2992
|
+
const rows = isArray(call.row) ? call.row : [call.row];
|
|
2995
2993
|
const keys = await table.add(rows, read);
|
|
2996
2994
|
return many ? { keys } : { key: keys[0] };
|
|
2997
2995
|
}
|
|
2998
2996
|
case "set": {
|
|
2999
2997
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3000
|
-
const many =
|
|
3001
|
-
const rows =
|
|
2998
|
+
const many = isArray(call.row);
|
|
2999
|
+
const rows = isArray(call.row) ? call.row : [call.row];
|
|
3002
3000
|
const keys = await table.set(rows, read);
|
|
3003
3001
|
return many ? { keys } : { key: keys[0] };
|
|
3004
3002
|
}
|
|
3005
3003
|
case "update": {
|
|
3006
3004
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3007
3005
|
const changes = call.changes;
|
|
3008
|
-
const many =
|
|
3009
|
-
const keys =
|
|
3006
|
+
const many = isArray(call.key);
|
|
3007
|
+
const keys = isArray(call.key) ? call.key : [call.key];
|
|
3010
3008
|
const updated = await table.update(keys, changes, read);
|
|
3011
3009
|
return many ? { updated } : { updated: updated[0] };
|
|
3012
3010
|
}
|
|
3013
3011
|
case "remove": {
|
|
3014
3012
|
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
3015
|
-
const many =
|
|
3016
|
-
const keys =
|
|
3013
|
+
const many = isArray(call.key);
|
|
3014
|
+
const keys = isArray(call.key) ? call.key : [call.key];
|
|
3017
3015
|
const removed = await table.remove(keys, read);
|
|
3018
3016
|
return many ? { removed } : { removed: removed[0] };
|
|
3019
3017
|
}
|
|
@@ -3035,7 +3033,7 @@ function createDatabaseTool(options = {}) {
|
|
|
3035
3033
|
if (isToolboxError(error)) throw error;
|
|
3036
3034
|
const code = inferDatabaseCode(error);
|
|
3037
3035
|
if (code === void 0) throw error;
|
|
3038
|
-
throw new ToolboxError("DATABASE", error
|
|
3036
|
+
throw new ToolboxError("DATABASE", isError(error) ? error.message : String(error), {
|
|
3039
3037
|
code,
|
|
3040
3038
|
operation: call.operation,
|
|
3041
3039
|
id: call.id,
|
|
@@ -3114,7 +3112,7 @@ function createRelationTool(options) {
|
|
|
3114
3112
|
switch (call.operation) {
|
|
3115
3113
|
case "load": {
|
|
3116
3114
|
const include = expandInclude(call.include, depth);
|
|
3117
|
-
if (
|
|
3115
|
+
if (isString(call.key) || isNumber(call.key)) return { row: await model.load(call.key, include) };
|
|
3118
3116
|
return { rows: await model.load(call.key, include) };
|
|
3119
3117
|
}
|
|
3120
3118
|
case "find": {
|
|
@@ -3157,7 +3155,7 @@ function createRelationTool(options) {
|
|
|
3157
3155
|
} catch (error) {
|
|
3158
3156
|
if (isToolboxError(error)) throw error;
|
|
3159
3157
|
const relation = inferRelationCode(error);
|
|
3160
|
-
if (relation !== void 0) throw new ToolboxError("RELATION", error
|
|
3158
|
+
if (relation !== void 0) throw new ToolboxError("RELATION", isError(error) ? error.message : String(error), {
|
|
3161
3159
|
code: relation,
|
|
3162
3160
|
operation: call.operation,
|
|
3163
3161
|
model: call.model,
|
|
@@ -3165,7 +3163,7 @@ function createRelationTool(options) {
|
|
|
3165
3163
|
});
|
|
3166
3164
|
const database = inferDatabaseCode(error);
|
|
3167
3165
|
if (database === void 0) throw error;
|
|
3168
|
-
throw new ToolboxError("DATABASE", error
|
|
3166
|
+
throw new ToolboxError("DATABASE", isError(error) ? error.message : String(error), {
|
|
3169
3167
|
code: database,
|
|
3170
3168
|
operation: call.operation
|
|
3171
3169
|
});
|