@crewhaus/tool-orchestrator 0.2.0 → 0.2.1
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/index.d.ts +23 -1
- package/dist/index.js +29 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* call is read-only AND not destructive. Any single negation falls
|
|
13
13
|
* through to serial. Unknown tool names also go serial (fail-closed).
|
|
14
14
|
*
|
|
15
|
+
* A tool whose per-call safety can't be captured by static flags (e.g.
|
|
16
|
+
* `Task`, whose safety depends on which sub-agent it spawns) may instead
|
|
17
|
+
* ship a `concurrencyClassifier(input, catalog)`; when present it decides
|
|
18
|
+
* per invocation and overrides the static flags. `partitionToolCalls`
|
|
19
|
+
* takes the sibling `catalog` so those classifiers can resolve what they
|
|
20
|
+
* need — see {@link isCallConcurrencySafe}.
|
|
21
|
+
*
|
|
15
22
|
* The returned shape `{ concurrent: ToolUseBlock[][], serial: ToolUseBlock[] }`
|
|
16
23
|
* deliberately drops interleaving information between batch and serial
|
|
17
24
|
* groups. The runtime executes all concurrent batches first via
|
|
@@ -44,10 +51,25 @@ export type ToolLookup = ToolCatalog | ((name: string) => RegisteredTool | undef
|
|
|
44
51
|
* read-only contract — destructive flag is the killswitch.
|
|
45
52
|
*/
|
|
46
53
|
export declare function isConcurrencySafe(tool: RegisteredTool): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Per-CALL concurrency safety. Most tools decide this from their static
|
|
56
|
+
* flags via {@link isConcurrencySafe}, but some (notably `Task`) can only
|
|
57
|
+
* decide per invocation — a sub-agent dispatch is parallel-safe iff the
|
|
58
|
+
* specific sub-agent it spawns is itself read-only. Such a tool ships a
|
|
59
|
+
* `concurrencyClassifier(input, catalog)`; when present it wins over the
|
|
60
|
+
* static flags. The classifier is treated fail-closed: a missing tool, a
|
|
61
|
+
* throw, or a `false` return all route the call serial.
|
|
62
|
+
*
|
|
63
|
+
* `catalog` is the sibling tool set the classifier may need (Task uses it
|
|
64
|
+
* to resolve the child's effective tool catalog). Callers that can't
|
|
65
|
+
* supply it pass `[]`, which keeps classifier-based tools serial — the
|
|
66
|
+
* pre-existing behavior — while leaving flag-based tools unaffected.
|
|
67
|
+
*/
|
|
68
|
+
export declare function isCallConcurrencySafe(call: ToolUseBlock, tool: RegisteredTool | undefined, catalog: ReadonlyArray<RegisteredTool>): boolean;
|
|
47
69
|
/**
|
|
48
70
|
* Walk `calls` in order, grouping consecutive concurrency-safe calls
|
|
49
71
|
* into the same batch. A non-safe call breaks the run and is appended
|
|
50
72
|
* to `serial`. The order of returned concurrent batches mirrors the
|
|
51
73
|
* order in which they appeared in `calls`.
|
|
52
74
|
*/
|
|
53
|
-
export declare function partitionToolCalls(calls: ReadonlyArray<ToolUseBlock>, lookup: ToolLookup): ToolPartition;
|
|
75
|
+
export declare function partitionToolCalls(calls: ReadonlyArray<ToolUseBlock>, lookup: ToolLookup, catalog?: ReadonlyArray<RegisteredTool>): ToolPartition;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,33 @@
|
|
|
7
7
|
export function isConcurrencySafe(tool) {
|
|
8
8
|
return tool.concurrencySafe && tool.readOnly && !tool.destructive;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Per-CALL concurrency safety. Most tools decide this from their static
|
|
12
|
+
* flags via {@link isConcurrencySafe}, but some (notably `Task`) can only
|
|
13
|
+
* decide per invocation — a sub-agent dispatch is parallel-safe iff the
|
|
14
|
+
* specific sub-agent it spawns is itself read-only. Such a tool ships a
|
|
15
|
+
* `concurrencyClassifier(input, catalog)`; when present it wins over the
|
|
16
|
+
* static flags. The classifier is treated fail-closed: a missing tool, a
|
|
17
|
+
* throw, or a `false` return all route the call serial.
|
|
18
|
+
*
|
|
19
|
+
* `catalog` is the sibling tool set the classifier may need (Task uses it
|
|
20
|
+
* to resolve the child's effective tool catalog). Callers that can't
|
|
21
|
+
* supply it pass `[]`, which keeps classifier-based tools serial — the
|
|
22
|
+
* pre-existing behavior — while leaving flag-based tools unaffected.
|
|
23
|
+
*/
|
|
24
|
+
export function isCallConcurrencySafe(call, tool, catalog) {
|
|
25
|
+
if (tool === undefined)
|
|
26
|
+
return false;
|
|
27
|
+
if (tool.concurrencyClassifier !== undefined) {
|
|
28
|
+
try {
|
|
29
|
+
return tool.concurrencyClassifier(call.input, catalog);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return isConcurrencySafe(tool);
|
|
36
|
+
}
|
|
10
37
|
function asLookup(lookup) {
|
|
11
38
|
if (typeof lookup === "function")
|
|
12
39
|
return lookup;
|
|
@@ -18,14 +45,14 @@ function asLookup(lookup) {
|
|
|
18
45
|
* to `serial`. The order of returned concurrent batches mirrors the
|
|
19
46
|
* order in which they appeared in `calls`.
|
|
20
47
|
*/
|
|
21
|
-
export function partitionToolCalls(calls, lookup) {
|
|
48
|
+
export function partitionToolCalls(calls, lookup, catalog = []) {
|
|
22
49
|
const get = asLookup(lookup);
|
|
23
50
|
const concurrent = [];
|
|
24
51
|
const serial = [];
|
|
25
52
|
let currentBatch = null;
|
|
26
53
|
for (const call of calls) {
|
|
27
54
|
const tool = get(call.name);
|
|
28
|
-
const safe = tool
|
|
55
|
+
const safe = isCallConcurrencySafe(call, tool, catalog);
|
|
29
56
|
if (safe) {
|
|
30
57
|
if (currentBatch === null) {
|
|
31
58
|
currentBatch = [call];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-orchestrator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Partition tool_use blocks into concurrent batches and serial calls based on catalog metadata",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"test": "bun test src"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@crewhaus/errors": "0.2.
|
|
19
|
-
"@crewhaus/tool-catalog": "0.2.
|
|
20
|
-
"@crewhaus/turn-state-machine": "0.2.
|
|
18
|
+
"@crewhaus/errors": "0.2.1",
|
|
19
|
+
"@crewhaus/tool-catalog": "0.2.1",
|
|
20
|
+
"@crewhaus/turn-state-machine": "0.2.1"
|
|
21
21
|
},
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"author": {
|