@orkestrel/tool 0.0.4 → 0.0.6
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 +195 -87
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +84 -24
- package/dist/src/core/index.d.ts +84 -24
- package/dist/src/core/index.js +195 -88
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +225 -160
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +68 -26
- package/dist/src/server/index.d.ts +68 -26
- package/dist/src/server/index.js +225 -162
- package/dist/src/server/index.js.map +1 -1
- package/package.json +20 -20
package/dist/src/core/index.js
CHANGED
|
@@ -559,12 +559,11 @@ var INFER_TOOL_DESCRIPTION = [
|
|
|
559
559
|
*/
|
|
560
560
|
var AgentToolError = class extends Error {
|
|
561
561
|
code;
|
|
562
|
-
context;
|
|
563
562
|
constructor(code, message, context) {
|
|
564
563
|
super(message);
|
|
565
564
|
this.name = "AgentToolError";
|
|
566
565
|
this.code = code;
|
|
567
|
-
this.context = context;
|
|
566
|
+
if (context !== void 0) this.context = context;
|
|
568
567
|
}
|
|
569
568
|
};
|
|
570
569
|
/**
|
|
@@ -1543,19 +1542,6 @@ function relationToolCode(error) {
|
|
|
1543
1542
|
* ```
|
|
1544
1543
|
*/
|
|
1545
1544
|
function expandInclude(paths, depth) {
|
|
1546
|
-
function merge(base, segments) {
|
|
1547
|
-
const [head, ...rest] = segments;
|
|
1548
|
-
const existing = base[head];
|
|
1549
|
-
if (rest.length === 0) return {
|
|
1550
|
-
...base,
|
|
1551
|
-
[head]: existing === void 0 ? true : existing
|
|
1552
|
-
};
|
|
1553
|
-
const nextBase = typeof existing === "object" ? existing : {};
|
|
1554
|
-
return {
|
|
1555
|
-
...base,
|
|
1556
|
-
[head]: merge(nextBase, rest)
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
1545
|
let include = {};
|
|
1560
1546
|
for (const path of paths ?? []) {
|
|
1561
1547
|
const segments = path.split(".");
|
|
@@ -1563,7 +1549,42 @@ function expandInclude(paths, depth) {
|
|
|
1563
1549
|
path,
|
|
1564
1550
|
depth
|
|
1565
1551
|
});
|
|
1566
|
-
|
|
1552
|
+
const ancestors = [];
|
|
1553
|
+
let branch = include;
|
|
1554
|
+
const last = segments.length - 1;
|
|
1555
|
+
for (let index = 0; index < last; index++) {
|
|
1556
|
+
const segment = segments[index];
|
|
1557
|
+
if (segment === void 0) throw new AgentToolError("TOOL", `malformed include path '${path}'`, {
|
|
1558
|
+
path,
|
|
1559
|
+
depth
|
|
1560
|
+
});
|
|
1561
|
+
ancestors.push(branch);
|
|
1562
|
+
const existing = branch[segment];
|
|
1563
|
+
branch = typeof existing === "object" ? existing : {};
|
|
1564
|
+
}
|
|
1565
|
+
const leaf = segments[last];
|
|
1566
|
+
if (leaf === void 0) throw new AgentToolError("TOOL", `malformed include path '${path}'`, {
|
|
1567
|
+
path,
|
|
1568
|
+
depth
|
|
1569
|
+
});
|
|
1570
|
+
const existing = branch[leaf];
|
|
1571
|
+
let merged = {
|
|
1572
|
+
...branch,
|
|
1573
|
+
[leaf]: existing === void 0 ? true : existing
|
|
1574
|
+
};
|
|
1575
|
+
for (let index = last - 1; index >= 0; index--) {
|
|
1576
|
+
const ancestor = ancestors[index];
|
|
1577
|
+
const segment = segments[index];
|
|
1578
|
+
if (ancestor === void 0 || segment === void 0) throw new AgentToolError("TOOL", `malformed include path '${path}'`, {
|
|
1579
|
+
path,
|
|
1580
|
+
depth
|
|
1581
|
+
});
|
|
1582
|
+
merged = {
|
|
1583
|
+
...ancestor,
|
|
1584
|
+
[segment]: merged
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
include = merged;
|
|
1567
1588
|
}
|
|
1568
1589
|
return include;
|
|
1569
1590
|
}
|
|
@@ -1591,7 +1612,11 @@ function relationManagerOf(managers, name) {
|
|
|
1591
1612
|
return manager;
|
|
1592
1613
|
}
|
|
1593
1614
|
const names = Object.keys(managers);
|
|
1594
|
-
|
|
1615
|
+
const [single] = names;
|
|
1616
|
+
if (names.length === 1 && single !== void 0) {
|
|
1617
|
+
const manager = managers[single];
|
|
1618
|
+
if (manager !== void 0) return manager;
|
|
1619
|
+
}
|
|
1595
1620
|
throw new AgentToolError("TOOL", "no relation manager resolved for the call", { managers: names });
|
|
1596
1621
|
}
|
|
1597
1622
|
/**
|
|
@@ -1819,6 +1844,105 @@ var DatabaseDefinitionStore = class {
|
|
|
1819
1844
|
}
|
|
1820
1845
|
};
|
|
1821
1846
|
//#endregion
|
|
1847
|
+
//#region src/core/databases/DatabaseResolver.ts
|
|
1848
|
+
/**
|
|
1849
|
+
* Resolve database definitions into cached live handles for database tools.
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```ts
|
|
1853
|
+
* import { DatabaseResolver } from '@orkestrel/tool'
|
|
1854
|
+
*
|
|
1855
|
+
* const resolver = new DatabaseResolver(handles, drivers, key, store)
|
|
1856
|
+
* const database = await resolver.resolve('shop')
|
|
1857
|
+
* ```
|
|
1858
|
+
*/
|
|
1859
|
+
var DatabaseResolver = class {
|
|
1860
|
+
#handles;
|
|
1861
|
+
#drivers;
|
|
1862
|
+
#key;
|
|
1863
|
+
#store;
|
|
1864
|
+
/**
|
|
1865
|
+
* Create a database resolver over the tool's live state and optional definition store.
|
|
1866
|
+
*
|
|
1867
|
+
* @param handles - Initial live database handles cached by id
|
|
1868
|
+
* @param drivers - Driver factories keyed by definition driver name
|
|
1869
|
+
* @param key - Key generator supplied to newly created databases
|
|
1870
|
+
* @param store - Optional persistent definition store
|
|
1871
|
+
*/
|
|
1872
|
+
constructor(handles, drivers, key, store) {
|
|
1873
|
+
this.#handles = new Map(handles);
|
|
1874
|
+
this.#drivers = drivers;
|
|
1875
|
+
this.#key = key;
|
|
1876
|
+
this.#store = store;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Determine whether a live database is cached by id.
|
|
1880
|
+
*
|
|
1881
|
+
* @param id - Database id
|
|
1882
|
+
* @returns Whether a live handle is cached
|
|
1883
|
+
*/
|
|
1884
|
+
has(id) {
|
|
1885
|
+
return this.#handles.has(id);
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Read a cached database without consulting the definition store.
|
|
1889
|
+
*
|
|
1890
|
+
* @param id - Database id
|
|
1891
|
+
* @returns The cached live database, or `undefined`
|
|
1892
|
+
*/
|
|
1893
|
+
get(id) {
|
|
1894
|
+
return this.#handles.get(id);
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Cache a live database by id.
|
|
1898
|
+
*
|
|
1899
|
+
* @param id - Database id
|
|
1900
|
+
* @param database - Live database handle
|
|
1901
|
+
* @returns Nothing
|
|
1902
|
+
*/
|
|
1903
|
+
set(id, database) {
|
|
1904
|
+
this.#handles.set(id, database);
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Remove a cached live database by id.
|
|
1908
|
+
*
|
|
1909
|
+
* @param id - Database id
|
|
1910
|
+
* @returns Nothing
|
|
1911
|
+
*/
|
|
1912
|
+
delete(id) {
|
|
1913
|
+
this.#handles.delete(id);
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Resolve a cached or stored database by id.
|
|
1917
|
+
*
|
|
1918
|
+
* @param id - Database definition id
|
|
1919
|
+
* @returns The cached or newly constructed live database
|
|
1920
|
+
*/
|
|
1921
|
+
async resolve(id) {
|
|
1922
|
+
const cached = this.#handles.get(id);
|
|
1923
|
+
if (cached !== void 0) return cached;
|
|
1924
|
+
if (this.#store !== void 0) {
|
|
1925
|
+
const definition = await this.#store.get(id);
|
|
1926
|
+
if (definition !== void 0) {
|
|
1927
|
+
const factory = this.#drivers[definition.driver];
|
|
1928
|
+
if (factory === void 0) throw new AgentToolError("TOOL", `unknown driver '${definition.driver}'`, {
|
|
1929
|
+
id,
|
|
1930
|
+
driver: definition.driver
|
|
1931
|
+
});
|
|
1932
|
+
const handle = createDatabase({
|
|
1933
|
+
driver: factory(),
|
|
1934
|
+
tables: expandTables(definition.tables),
|
|
1935
|
+
...definition.keys === void 0 ? {} : { keys: definition.keys },
|
|
1936
|
+
key: this.#key
|
|
1937
|
+
});
|
|
1938
|
+
this.set(id, handle);
|
|
1939
|
+
return handle;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
throw new AgentToolError("TOOL", `unknown database '${id}'`, { id });
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
//#endregion
|
|
1822
1946
|
//#region src/core/factories.ts
|
|
1823
1947
|
/**
|
|
1824
1948
|
* Wrap a registered tool as a {@link WorkflowFunction} (`@orkestrel/workflow`) — the OPT-IN
|
|
@@ -1934,7 +2058,9 @@ function createAgentFunction(agent, options) {
|
|
|
1934
2058
|
}));
|
|
1935
2059
|
}
|
|
1936
2060
|
const signal = controller.signal;
|
|
1937
|
-
const onAbort = ()
|
|
2061
|
+
const onAbort = { handleEvent() {
|
|
2062
|
+
agent.abort(signal.reason);
|
|
2063
|
+
} };
|
|
1938
2064
|
if (signal.aborted) agent.abort(signal.reason);
|
|
1939
2065
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
1940
2066
|
try {
|
|
@@ -2039,12 +2165,13 @@ function createWorkflowTool(definition, runner, options) {
|
|
|
2039
2165
|
const depth = options?.depth ?? 0;
|
|
2040
2166
|
const ancestry = options?.ancestry ?? [];
|
|
2041
2167
|
const store = options?.store;
|
|
2168
|
+
const parameters = schemaToParameters(steps.schema);
|
|
2042
2169
|
return createTool({
|
|
2043
2170
|
name: WORKFLOW_TOOL_NAME,
|
|
2044
2171
|
description: WORKFLOW_TOOL_DESCRIPTION,
|
|
2045
2172
|
summary: WORKFLOW_TOOL_SUMMARY,
|
|
2046
|
-
parameters:
|
|
2047
|
-
|
|
2173
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2174
|
+
async execute(args) {
|
|
2048
2175
|
let target;
|
|
2049
2176
|
if (Object.keys(args).length === 0) target = definition;
|
|
2050
2177
|
else if (Array.isArray(args.steps)) {
|
|
@@ -2128,8 +2255,8 @@ function createWorkspaceTool(options) {
|
|
|
2128
2255
|
name: options?.name ?? "workspace",
|
|
2129
2256
|
description: options?.description ?? WORKSPACE_TOOL_DESCRIPTION,
|
|
2130
2257
|
summary: WORKSPACE_TOOL_SUMMARY,
|
|
2131
|
-
parameters,
|
|
2132
|
-
execute
|
|
2258
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2259
|
+
execute(args) {
|
|
2133
2260
|
const op = contract.parse(args);
|
|
2134
2261
|
if (op === void 0) throw new WorkspaceError("TOOL", `unknown or malformed operation`, { args });
|
|
2135
2262
|
if (op.operation === "workspaces") {
|
|
@@ -2163,14 +2290,14 @@ function createWorkspaceTool(options) {
|
|
|
2163
2290
|
}));
|
|
2164
2291
|
case "has": return active?.has(op.path) ?? false;
|
|
2165
2292
|
case "search": return active?.search(op.query, {
|
|
2166
|
-
regex: op.regex,
|
|
2167
|
-
exact: op.exact,
|
|
2168
|
-
limit: op.limit
|
|
2293
|
+
...op.regex === void 0 ? {} : { regex: op.regex },
|
|
2294
|
+
...op.exact === void 0 ? {} : { exact: op.exact },
|
|
2295
|
+
...op.limit === void 0 ? {} : { limit: op.limit }
|
|
2169
2296
|
}) ?? [];
|
|
2170
2297
|
case "replace": return (active ?? manager.add()).replace(op.query, op.replacement, {
|
|
2171
|
-
regex: op.regex,
|
|
2172
|
-
exact: op.exact,
|
|
2173
|
-
limit: op.limit
|
|
2298
|
+
...op.regex === void 0 ? {} : { regex: op.regex },
|
|
2299
|
+
...op.exact === void 0 ? {} : { exact: op.exact },
|
|
2300
|
+
...op.limit === void 0 ? {} : { limit: op.limit }
|
|
2174
2301
|
});
|
|
2175
2302
|
case "write": {
|
|
2176
2303
|
const workspace = active ?? manager.add();
|
|
@@ -2270,8 +2397,8 @@ function createAgentTool(registry, options) {
|
|
|
2270
2397
|
name: options?.name ?? "agent",
|
|
2271
2398
|
description: options?.description ?? AGENT_TOOL_DESCRIPTION,
|
|
2272
2399
|
summary: AGENT_TOOL_SUMMARY,
|
|
2273
|
-
parameters,
|
|
2274
|
-
|
|
2400
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2401
|
+
async execute(args) {
|
|
2275
2402
|
const call = contract.parse(args);
|
|
2276
2403
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed agent-delegation call", { args });
|
|
2277
2404
|
const provider = call.provider ?? options?.provider;
|
|
@@ -2342,12 +2469,13 @@ function createAgentTool(registry, options) {
|
|
|
2342
2469
|
*/
|
|
2343
2470
|
function createDescribeTool(tools) {
|
|
2344
2471
|
const contract = createContract(describeToolShape);
|
|
2472
|
+
const parameters = schemaToParameters(contract.schema);
|
|
2345
2473
|
return createTool({
|
|
2346
2474
|
name: DESCRIBE_TOOL_NAME,
|
|
2347
2475
|
description: DESCRIBE_TOOL_DESCRIPTION,
|
|
2348
2476
|
summary: DESCRIBE_TOOL_SUMMARY,
|
|
2349
|
-
parameters:
|
|
2350
|
-
|
|
2477
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2478
|
+
async execute(args) {
|
|
2351
2479
|
const call = contract.parse(args);
|
|
2352
2480
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed describe call", { args });
|
|
2353
2481
|
const tool = tools.tool(call.name);
|
|
@@ -2397,8 +2525,8 @@ function createPromptTool(options) {
|
|
|
2397
2525
|
name: options.name ?? "ask",
|
|
2398
2526
|
description: options.description ?? PROMPT_TOOL_DESCRIPTION,
|
|
2399
2527
|
summary: PROMPT_TOOL_SUMMARY,
|
|
2400
|
-
parameters,
|
|
2401
|
-
|
|
2528
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2529
|
+
async execute(args) {
|
|
2402
2530
|
const call = contract.parse(args);
|
|
2403
2531
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed ask call", { args });
|
|
2404
2532
|
if ((call.form === "select" || call.form === "checkbox") && (call.choices ?? []).length === 0) throw new AgentToolError("TOOL", "select/checkbox requires at least one choice", {
|
|
@@ -2499,8 +2627,8 @@ function createAnswerTool(options) {
|
|
|
2499
2627
|
name: options.name ?? "answer",
|
|
2500
2628
|
description: options.description ?? ANSWER_TOOL_DESCRIPTION,
|
|
2501
2629
|
summary: ANSWER_TOOL_SUMMARY,
|
|
2502
|
-
parameters,
|
|
2503
|
-
|
|
2630
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2631
|
+
async execute(args) {
|
|
2504
2632
|
const call = contract.parse(args);
|
|
2505
2633
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed answer call", { args });
|
|
2506
2634
|
if (call.operation === "pending") return options.manager.pending(options.to).map((prompt) => ({
|
|
@@ -2632,40 +2760,17 @@ function createDatabaseTool(options = {}) {
|
|
|
2632
2760
|
const parameters = schemaToParameters(contract.schema);
|
|
2633
2761
|
const handles = new Map(Object.entries(options.databases ?? {}));
|
|
2634
2762
|
const definitions = /* @__PURE__ */ new Map();
|
|
2635
|
-
const drivers = options.drivers ?? { memory:
|
|
2763
|
+
const drivers = options.drivers ?? { memory: createMemoryDriver };
|
|
2636
2764
|
const key = options.key ?? generateUUID;
|
|
2637
2765
|
const cap = options.limit ?? 1e3;
|
|
2638
2766
|
const store = options.store;
|
|
2639
|
-
|
|
2640
|
-
const cached = handles.get(id);
|
|
2641
|
-
if (cached !== void 0) return cached;
|
|
2642
|
-
if (store !== void 0) {
|
|
2643
|
-
const definition = await store.get(id);
|
|
2644
|
-
if (definition !== void 0) {
|
|
2645
|
-
const factory = drivers[definition.driver];
|
|
2646
|
-
if (factory === void 0) throw new AgentToolError("TOOL", `unknown driver '${definition.driver}'`, {
|
|
2647
|
-
id,
|
|
2648
|
-
driver: definition.driver
|
|
2649
|
-
});
|
|
2650
|
-
const handle = createDatabase({
|
|
2651
|
-
driver: factory(),
|
|
2652
|
-
tables: expandTables(definition.tables),
|
|
2653
|
-
...definition.keys === void 0 ? {} : { keys: definition.keys },
|
|
2654
|
-
key
|
|
2655
|
-
});
|
|
2656
|
-
handles.set(id, handle);
|
|
2657
|
-
definitions.set(id, definition);
|
|
2658
|
-
return handle;
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
|
-
throw new AgentToolError("TOOL", `unknown database '${id}'`, { id });
|
|
2662
|
-
}
|
|
2767
|
+
const resolver = store === void 0 ? new DatabaseResolver(handles, drivers, key) : new DatabaseResolver(handles, drivers, key, store);
|
|
2663
2768
|
return createTool({
|
|
2664
2769
|
name: options.name ?? "database",
|
|
2665
2770
|
description: options.description ?? DATABASE_TOOL_DESCRIPTION,
|
|
2666
2771
|
summary: DATABASE_TOOL_SUMMARY,
|
|
2667
|
-
parameters,
|
|
2668
|
-
|
|
2772
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2773
|
+
async execute(args) {
|
|
2669
2774
|
const call = contract.parse(args);
|
|
2670
2775
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed database call", { args });
|
|
2671
2776
|
if (options.readonly === true && DATABASE_TOOL_MUTATIONS.has(call.operation)) throw new AgentToolError("TOOL", `operation '${call.operation}' is disabled in readonly mode`, { operation: call.operation });
|
|
@@ -2673,7 +2778,7 @@ function createDatabaseTool(options = {}) {
|
|
|
2673
2778
|
try {
|
|
2674
2779
|
switch (call.operation) {
|
|
2675
2780
|
case "create": {
|
|
2676
|
-
if (
|
|
2781
|
+
if (resolver.has(call.id) || store !== void 0 && await store.get(call.id) !== void 0) throw new AgentToolError("TOOL", `database '${call.id}' already exists`, { id: call.id });
|
|
2677
2782
|
const name = call.driver ?? "memory";
|
|
2678
2783
|
const factory = drivers[name];
|
|
2679
2784
|
if (factory === void 0) throw new AgentToolError("TOOL", `unknown driver '${name}'`, {
|
|
@@ -2688,7 +2793,7 @@ function createDatabaseTool(options = {}) {
|
|
|
2688
2793
|
...keys === void 0 ? {} : { keys },
|
|
2689
2794
|
key
|
|
2690
2795
|
});
|
|
2691
|
-
|
|
2796
|
+
resolver.set(call.id, handle);
|
|
2692
2797
|
const definition = {
|
|
2693
2798
|
id: call.id,
|
|
2694
2799
|
driver: name,
|
|
@@ -2703,7 +2808,7 @@ function createDatabaseTool(options = {}) {
|
|
|
2703
2808
|
};
|
|
2704
2809
|
}
|
|
2705
2810
|
case "tables": {
|
|
2706
|
-
const handle = await resolve(call.id);
|
|
2811
|
+
const handle = await resolver.resolve(call.id);
|
|
2707
2812
|
return { tables: Object.keys(handle.export()).map((name) => {
|
|
2708
2813
|
const table = handle.table(name);
|
|
2709
2814
|
return {
|
|
@@ -2714,14 +2819,14 @@ function createDatabaseTool(options = {}) {
|
|
|
2714
2819
|
}) };
|
|
2715
2820
|
}
|
|
2716
2821
|
case "get": {
|
|
2717
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2822
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2718
2823
|
const many = Array.isArray(call.key);
|
|
2719
2824
|
const keys = Array.isArray(call.key) ? call.key : [call.key];
|
|
2720
2825
|
const rows = await table.get(keys);
|
|
2721
2826
|
return many ? { rows } : { row: rows[0] };
|
|
2722
2827
|
}
|
|
2723
2828
|
case "records": {
|
|
2724
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2829
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2725
2830
|
const { criteria: probe, limit } = clampCriteria(criteriaOf(call.criteria), cap);
|
|
2726
2831
|
const rows = await table.records(probe, read);
|
|
2727
2832
|
const truncated = rows.length > limit;
|
|
@@ -2733,24 +2838,24 @@ function createDatabaseTool(options = {}) {
|
|
|
2733
2838
|
limit
|
|
2734
2839
|
};
|
|
2735
2840
|
}
|
|
2736
|
-
case "count": return { count: await (await resolve(call.id)).table(call.table).count(criteriaOf(call.criteria), read) };
|
|
2737
|
-
case "aggregate": return { value: await (await resolve(call.id)).table(call.table).aggregate(call.function, call.column, criteriaOf(call.criteria), read) };
|
|
2841
|
+
case "count": return { count: await (await resolver.resolve(call.id)).table(call.table).count(criteriaOf(call.criteria), read) };
|
|
2842
|
+
case "aggregate": return { value: await (await resolver.resolve(call.id)).table(call.table).aggregate(call.function, call.column, criteriaOf(call.criteria), read) };
|
|
2738
2843
|
case "add": {
|
|
2739
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2844
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2740
2845
|
const many = Array.isArray(call.row);
|
|
2741
2846
|
const rows = Array.isArray(call.row) ? call.row : [call.row];
|
|
2742
2847
|
const keys = await table.add(rows, read);
|
|
2743
2848
|
return many ? { keys } : { key: keys[0] };
|
|
2744
2849
|
}
|
|
2745
2850
|
case "set": {
|
|
2746
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2851
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2747
2852
|
const many = Array.isArray(call.row);
|
|
2748
2853
|
const rows = Array.isArray(call.row) ? call.row : [call.row];
|
|
2749
2854
|
const keys = await table.set(rows, read);
|
|
2750
2855
|
return many ? { keys } : { key: keys[0] };
|
|
2751
2856
|
}
|
|
2752
2857
|
case "update": {
|
|
2753
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2858
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2754
2859
|
const changes = call.changes;
|
|
2755
2860
|
const many = Array.isArray(call.key);
|
|
2756
2861
|
const keys = Array.isArray(call.key) ? call.key : [call.key];
|
|
@@ -2758,14 +2863,14 @@ function createDatabaseTool(options = {}) {
|
|
|
2758
2863
|
return many ? { updated } : { updated: updated[0] };
|
|
2759
2864
|
}
|
|
2760
2865
|
case "remove": {
|
|
2761
|
-
const table = (await resolve(call.id)).table(call.table);
|
|
2866
|
+
const table = (await resolver.resolve(call.id)).table(call.table);
|
|
2762
2867
|
const many = Array.isArray(call.key);
|
|
2763
2868
|
const keys = Array.isArray(call.key) ? call.key : [call.key];
|
|
2764
2869
|
const removed = await table.remove(keys, read);
|
|
2765
2870
|
return many ? { removed } : { removed: removed[0] };
|
|
2766
2871
|
}
|
|
2767
2872
|
case "migrate": {
|
|
2768
|
-
const handle = await resolve(call.id);
|
|
2873
|
+
const handle = await resolver.resolve(call.id);
|
|
2769
2874
|
const previous = handle.export();
|
|
2770
2875
|
const deployed = Object.entries(previous).map(([name, table]) => tableSchema(name, table));
|
|
2771
2876
|
const tables = call.tables;
|
|
@@ -2777,8 +2882,8 @@ function createDatabaseTool(options = {}) {
|
|
|
2777
2882
|
const declared = expandTables(tables);
|
|
2778
2883
|
const migrated = handle.import(declared, Object.keys(keys).length > 0 ? keys : void 0);
|
|
2779
2884
|
const migration = await migrated.migrate(deployed, read);
|
|
2780
|
-
|
|
2781
|
-
const tracked = definitions.get(call.id);
|
|
2885
|
+
resolver.set(call.id, migrated);
|
|
2886
|
+
const tracked = definitions.get(call.id) ?? (store === void 0 ? void 0 : await store.get(call.id));
|
|
2782
2887
|
if (tracked !== void 0) {
|
|
2783
2888
|
const updated = {
|
|
2784
2889
|
id: call.id,
|
|
@@ -2792,11 +2897,11 @@ function createDatabaseTool(options = {}) {
|
|
|
2792
2897
|
return { migration };
|
|
2793
2898
|
}
|
|
2794
2899
|
case "destroy": {
|
|
2795
|
-
const cached =
|
|
2900
|
+
const cached = resolver.get(call.id);
|
|
2796
2901
|
const persisted = store !== void 0 && cached === void 0 ? await store.get(call.id) !== void 0 : false;
|
|
2797
2902
|
if (cached !== void 0) {
|
|
2798
2903
|
await cached.close();
|
|
2799
|
-
|
|
2904
|
+
resolver.delete(call.id);
|
|
2800
2905
|
}
|
|
2801
2906
|
definitions.delete(call.id);
|
|
2802
2907
|
if (store !== void 0) await store.delete(call.id);
|
|
@@ -2876,8 +2981,8 @@ function createRelationTool(options) {
|
|
|
2876
2981
|
name: options.name ?? "relation",
|
|
2877
2982
|
description: options.description ?? RELATION_TOOL_DESCRIPTION,
|
|
2878
2983
|
summary: RELATION_TOOL_SUMMARY,
|
|
2879
|
-
parameters,
|
|
2880
|
-
|
|
2984
|
+
...parameters === void 0 ? {} : { parameters },
|
|
2985
|
+
async execute(args) {
|
|
2881
2986
|
const call = contract.parse(args);
|
|
2882
2987
|
if (call === void 0) throw new AgentToolError("TOOL", "malformed relation call", { args });
|
|
2883
2988
|
try {
|
|
@@ -3027,8 +3132,8 @@ function createInferTool(options) {
|
|
|
3027
3132
|
name: options?.name ?? "infer",
|
|
3028
3133
|
description: options?.description ?? INFER_TOOL_DESCRIPTION,
|
|
3029
3134
|
summary: INFER_TOOL_SUMMARY,
|
|
3030
|
-
parameters,
|
|
3031
|
-
|
|
3135
|
+
...parameters === void 0 ? {} : { parameters },
|
|
3136
|
+
async execute(args) {
|
|
3032
3137
|
const parsed = contract.parse(args);
|
|
3033
3138
|
if (parsed === void 0) throw new AgentToolError("TOOL", "malformed infer arguments", { args });
|
|
3034
3139
|
const schema = samplesToSchema(parsed.samples, {
|
|
@@ -3135,15 +3240,17 @@ function createEndpointTool(definition, options) {
|
|
|
3135
3240
|
if (!(options?.validate ?? true)) return createTool({
|
|
3136
3241
|
name: definition.name,
|
|
3137
3242
|
description: definition.description,
|
|
3138
|
-
parameters,
|
|
3139
|
-
execute
|
|
3243
|
+
...parameters === void 0 ? {} : { parameters },
|
|
3244
|
+
execute(args) {
|
|
3245
|
+
return definition.invoke(args);
|
|
3246
|
+
}
|
|
3140
3247
|
});
|
|
3141
3248
|
const contract = createContract(schemaToShape(objectSchema));
|
|
3142
3249
|
return createTool({
|
|
3143
3250
|
name: definition.name,
|
|
3144
3251
|
description: definition.description,
|
|
3145
|
-
parameters,
|
|
3146
|
-
execute
|
|
3252
|
+
...parameters === void 0 ? {} : { parameters },
|
|
3253
|
+
execute(args) {
|
|
3147
3254
|
const parsed = contract.parse(args);
|
|
3148
3255
|
if (parsed === void 0 || !isRecord(parsed)) throw new AgentToolError("TOOL", "malformed endpoint call arguments", {
|
|
3149
3256
|
name: definition.name,
|
|
@@ -3154,6 +3261,6 @@ function createEndpointTool(definition, options) {
|
|
|
3154
3261
|
});
|
|
3155
3262
|
}
|
|
3156
3263
|
//#endregion
|
|
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 };
|
|
3264
|
+
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, DatabaseResolver, 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 };
|
|
3158
3265
|
|
|
3159
3266
|
//# sourceMappingURL=index.js.map
|