@code-yeongyu/senpi-agent-core 2026.11.4-2 → 2026.11.5-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/agent-loop.js +14 -140
- package/dist/agent.d.ts +4 -0
- package/dist/agent.js +4 -0
- package/dist/conformance/index.d.ts +7 -0
- package/dist/conformance/index.js +4 -0
- package/dist/conformance/loop-core-manifest.d.ts +1 -1
- package/dist/conformance/loop-core-manifest.js +17 -0
- package/dist/conformance/registry.js +11 -17
- package/dist/egress/types.d.ts +102 -0
- package/dist/egress/types.js +7 -0
- package/dist/execution/canonical-digest.d.ts +10 -0
- package/dist/execution/canonical-digest.js +20 -0
- package/dist/execution/chain-count.d.ts +26 -0
- package/dist/execution/chain-count.js +45 -0
- package/dist/execution/coordinator-plan.d.ts +1 -2
- package/dist/execution/coordinator-plan.js +4 -17
- package/dist/execution/device-files-node.js +39 -1
- package/dist/execution/device-files.d.ts +30 -1
- package/dist/execution/device-files.js +38 -1
- package/dist/execution/ledger-types.d.ts +3 -1
- package/dist/execution/ledger.d.ts +9 -3
- package/dist/execution/ledger.js +8 -2
- package/dist/execution/loop-hook-host-hand.d.ts +33 -0
- package/dist/execution/loop-hook-host-hand.js +71 -0
- package/dist/execution/loop-hook-host-protocol.d.ts +46 -0
- package/dist/execution/loop-hook-host-protocol.js +47 -0
- package/dist/execution/loop-hook-host.d.ts +40 -0
- package/dist/execution/loop-hook-host.js +87 -0
- package/dist/execution/plane-session.d.ts +56 -0
- package/dist/execution/plane-session.js +178 -0
- package/dist/execution/plane.d.ts +5 -2
- package/dist/execution/plane.js +1 -1
- package/dist/execution/prepared/executor-body.d.ts +22 -0
- package/dist/execution/prepared/executor-body.js +73 -0
- package/dist/execution/prepared/executor-freeze.d.ts +17 -0
- package/dist/execution/prepared/executor-freeze.js +42 -0
- package/dist/execution/prepared/executor-pipeline.d.ts +11 -0
- package/dist/execution/prepared/executor-pipeline.js +26 -0
- package/dist/execution/prepared/executor-types.d.ts +131 -0
- package/dist/execution/prepared/executor-types.js +2 -0
- package/dist/execution/prepared/executor.d.ts +8 -0
- package/dist/execution/prepared/executor.js +261 -0
- package/dist/execution/prepared/memory-batch-store.d.ts +4 -0
- package/dist/execution/prepared/memory-batch-store.js +4 -0
- package/dist/execution/prepared/pipeline-prepared-batch.d.ts +27 -0
- package/dist/execution/prepared/pipeline-prepared-batch.js +175 -0
- package/dist/execution/prepared/pipeline-prepared.d.ts +10 -0
- package/dist/execution/prepared/pipeline-prepared.js +54 -0
- package/dist/execution/remote-device-files.js +33 -4
- package/dist/execution/remote-epoch-gate.d.ts +19 -0
- package/dist/execution/remote-epoch-gate.js +46 -0
- package/dist/execution/remote-epoch.d.ts +53 -0
- package/dist/execution/remote-epoch.js +74 -0
- package/dist/execution/remote-executor.d.ts +8 -1
- package/dist/execution/remote-executor.js +24 -6
- package/dist/execution/remote-file-call.js +1 -0
- package/dist/execution/remote-hand-ledger.d.ts +11 -3
- package/dist/execution/remote-hand-ledger.js +31 -15
- package/dist/execution/remote-link.d.ts +6 -1
- package/dist/execution/remote-link.js +50 -14
- package/dist/execution/remote-protocol.d.ts +30 -1
- package/dist/execution/remote-protocol.js +30 -0
- package/dist/execution/remote-tool-host.d.ts +12 -0
- package/dist/execution/remote-tool-host.js +3 -1
- package/dist/execution/testing/epoch-cases.d.ts +8 -0
- package/dist/execution/testing/epoch-cases.js +84 -0
- package/dist/execution/testing/epoch-harness.d.ts +47 -0
- package/dist/execution/testing/epoch-harness.js +172 -0
- package/dist/execution/testing/epoch-registry.d.ts +3 -0
- package/dist/execution/testing/epoch-registry.js +17 -0
- package/dist/execution/testing/hand-harness.d.ts +3 -0
- package/dist/execution/testing/hand-harness.js +27 -22
- package/dist/execution/testing/hand-registry.d.ts +3 -0
- package/dist/execution/testing/hand-registry.js +20 -0
- package/dist/execution/testing/kill-epoch.d.ts +9 -0
- package/dist/execution/testing/kill-epoch.js +71 -0
- package/dist/execution/testing/kill-hook.d.ts +14 -0
- package/dist/execution/testing/kill-hook.js +117 -0
- package/dist/execution/testing/multi-epoch-cases.d.ts +4 -0
- package/dist/execution/testing/multi-epoch-cases.js +29 -0
- package/dist/execution/tool-host.d.ts +13 -1
- package/dist/execution/tool-host.js +18 -1
- package/dist/harness/agent-harness.d.ts +6 -0
- package/dist/harness/execution/tool-host-call.d.ts +13 -0
- package/dist/harness/execution/tool-host-call.js +55 -0
- package/dist/harness/execution/tools.d.ts +2 -1
- package/dist/harness/execution/tools.js +32 -17
- package/dist/harness/runtime/drive/tools.js +1 -1
- package/dist/harness/runtime/harness.js +1 -0
- package/dist/harness/runtime/types.d.ts +1 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +14 -1
- package/dist/public-entry.d.ts +10 -0
- package/dist/public-entry.js +23 -0
- package/dist/step-commit.d.ts +24 -0
- package/dist/step-commit.js +24 -0
- package/dist/tool-name-alias.d.ts +1 -7
- package/dist/tool-name-alias.js +0 -17
- package/dist/types.d.ts +37 -1
- package/package.json +3 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createManualTimers } from "../../durable/testing/manual-timers.js";
|
|
2
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
3
|
+
import { createInProcessNetwork } from "../../transport/in-process-carrier.js";
|
|
4
|
+
import { localEndpoint } from "../../transport/local-endpoint.js";
|
|
5
|
+
import { createLoopHookHost, LoopHookRestartedError } from "../loop-hook-host.js";
|
|
6
|
+
import { serveLoopHooks } from "../loop-hook-host-hand.js";
|
|
7
|
+
/**
|
|
8
|
+
* KILL-HOOK (brain/hand split S33): the user's machine is killed around one forwarded hook call and its reply, then a new
|
|
9
|
+
* process starts on the same link. Each case declares what the loop host's turn sees: the hook result (and exactly one
|
|
10
|
+
* provider request carrying it), or a restarted call that is never run again and issues no provider request. These
|
|
11
|
+
* placements only exist where the hook host is engaged (a hosted loop, or any loop away from the user's machine); a
|
|
12
|
+
* fused or split-local session never forwards its hooks.
|
|
13
|
+
*/
|
|
14
|
+
const LANE = "loop-hooks:session";
|
|
15
|
+
const TICK_MS = 5;
|
|
16
|
+
const KILLS = [
|
|
17
|
+
{ at: "received", outcome: "result", runs: 1 },
|
|
18
|
+
{ at: "started", outcome: "restarted", runs: 0 },
|
|
19
|
+
{ at: "ran", outcome: "restarted", runs: 1 },
|
|
20
|
+
{ at: "replied", outcome: "result", runs: 1 },
|
|
21
|
+
{ at: "committed", outcome: "result", runs: 1 },
|
|
22
|
+
];
|
|
23
|
+
const WHERE = {
|
|
24
|
+
received: "after the hand received the hook call, before it started it",
|
|
25
|
+
started: "after the hand said it started the hooks, before they ran",
|
|
26
|
+
ran: "after the hooks ran, before the hand sent the reply",
|
|
27
|
+
replied: "after the hand sent the reply, before the loop host committed it",
|
|
28
|
+
committed: "after the loop host committed the reply, before the provider request",
|
|
29
|
+
};
|
|
30
|
+
const expectedOf = ({ at, outcome, runs }) => {
|
|
31
|
+
const result = outcome === "result"
|
|
32
|
+
? "the turn gets the hook result and issues exactly one provider request with it"
|
|
33
|
+
: "the call ends restarted (uncertain), is never sent again, and no provider request is issued";
|
|
34
|
+
return `cross-machine and hosted: kill ${WHERE[at]}; ${result}; the hooks ran ${runs === 0 ? "never" : "once"}`;
|
|
35
|
+
};
|
|
36
|
+
const drain = async () => {
|
|
37
|
+
for (let turn = 0; turn < 32; turn++)
|
|
38
|
+
await Promise.resolve();
|
|
39
|
+
};
|
|
40
|
+
async function runKillCase(adapters, kill, what) {
|
|
41
|
+
const timers = createManualTimers(1_000);
|
|
42
|
+
const network = createInProcessNetwork({ schedule: (deliver) => void timers.setTimer(deliver, 0) });
|
|
43
|
+
const loopSide = adapters.transport.createSide(timers);
|
|
44
|
+
const handSide = adapters.transport.createSide(timers);
|
|
45
|
+
const endpoint = localEndpoint(adapters.platform, "loop-hook-conformance", "/run/senpi-conformance");
|
|
46
|
+
network.listen(endpoint, handSide);
|
|
47
|
+
network.dial(endpoint, loopSide).connect();
|
|
48
|
+
const runs = [];
|
|
49
|
+
const requests = [];
|
|
50
|
+
const killed = Promise.withResolvers();
|
|
51
|
+
const startHand = (killAt) => serveLoopHooks({
|
|
52
|
+
transport: handSide,
|
|
53
|
+
lane: LANE,
|
|
54
|
+
run: async (event, payload) => {
|
|
55
|
+
runs.push(event);
|
|
56
|
+
return { context: `hook saw ${JSON.stringify(payload)}` };
|
|
57
|
+
},
|
|
58
|
+
onPoint: (point) => {
|
|
59
|
+
if (point !== killAt)
|
|
60
|
+
return;
|
|
61
|
+
killed.resolve();
|
|
62
|
+
throw new Error(`hand killed ${point}`);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const until = async (done, label) => {
|
|
66
|
+
const end = timers.now() + 600_000;
|
|
67
|
+
await drain();
|
|
68
|
+
while (!done() && timers.now() < end) {
|
|
69
|
+
await timers.advanceTo(timers.now() + TICK_MS);
|
|
70
|
+
await drain();
|
|
71
|
+
}
|
|
72
|
+
if (!done())
|
|
73
|
+
throw new Error(`${what}: ${label} not reached`);
|
|
74
|
+
};
|
|
75
|
+
let hand = startHand(kill.at === "committed" ? undefined : kill.at);
|
|
76
|
+
const host = createLoopHookHost({ transport: loopSide, lane: LANE });
|
|
77
|
+
let outcome;
|
|
78
|
+
host.run("before_agent_start", { prompt: "go" }).then(async (result) => {
|
|
79
|
+
if (kill.at === "committed") {
|
|
80
|
+
hand.close();
|
|
81
|
+
killed.resolve();
|
|
82
|
+
hand = startHand();
|
|
83
|
+
}
|
|
84
|
+
requests.push(result);
|
|
85
|
+
outcome = { result };
|
|
86
|
+
}, (error) => void (outcome = { error }));
|
|
87
|
+
let didKill = false;
|
|
88
|
+
void killed.promise.then(() => void (didKill = true));
|
|
89
|
+
await until(() => didKill, "the kill point fired");
|
|
90
|
+
if (kill.at !== "committed")
|
|
91
|
+
hand = startHand();
|
|
92
|
+
await until(() => outcome !== undefined, "the turn got the hook call's outcome");
|
|
93
|
+
// Let any second dispatch the restart could cause surface before the run count is checked.
|
|
94
|
+
for (let step = 0; step < 40; step++) {
|
|
95
|
+
await timers.advanceTo(timers.now() + TICK_MS);
|
|
96
|
+
await drain();
|
|
97
|
+
}
|
|
98
|
+
if (kill.outcome === "result") {
|
|
99
|
+
expectEqual(outcome !== undefined && "result" in outcome ? outcome.result : outcome, { context: 'hook saw {"prompt":"go"}' }, `${what}: the hook result`);
|
|
100
|
+
expectEqual(requests.length, 1, `${what}: provider requests`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
expectEqual(outcome !== undefined && "error" in outcome && outcome.error instanceof LoopHookRestartedError, true, `${what}: the call ended restarted`);
|
|
104
|
+
expectEqual(requests.length, 0, `${what}: provider requests`);
|
|
105
|
+
}
|
|
106
|
+
expectEqual(runs.length, kill.runs, `${what}: hook runs`);
|
|
107
|
+
expectEqual(host.waiting(), [], `${what}: nothing left waiting`);
|
|
108
|
+
}
|
|
109
|
+
const cases = KILLS.map((kill, index) => {
|
|
110
|
+
const id = `KILL-HOOK-${String(index + 1).padStart(2, "0")}`;
|
|
111
|
+
const declaration = { id, at: kill.at, expected: expectedOf(kill) };
|
|
112
|
+
const run = (adapters) => runKillCase(adapters, kill, `${id} (${kill.at})`);
|
|
113
|
+
return { declaration, run };
|
|
114
|
+
});
|
|
115
|
+
export const KILL_HOOK_DECLARATIONS = cases.map(({ declaration }) => declaration);
|
|
116
|
+
export const KILL_HOOK_CASES = new Map(cases.map(({ declaration, run }) => [declaration.id, run]));
|
|
117
|
+
//# sourceMappingURL=kill-hook.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import { type HandCaseAdapters } from "./hand-harness.ts";
|
|
3
|
+
export declare const MULTI_EPOCH_CASES: ReadonlyMap<string, CaseImplementation<HandCaseAdapters>>;
|
|
4
|
+
//# sourceMappingURL=multi-epoch-cases.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { texts } from "./epoch-cases.js";
|
|
3
|
+
import { openEpochRig } from "./epoch-harness.js";
|
|
4
|
+
import { call } from "./hand-harness.js";
|
|
5
|
+
const SCOPES = ["a", "b", "c"];
|
|
6
|
+
/** Z2: one session moves (its scope's floor rises); the other sessions' scopes on the same hand keep running. */
|
|
7
|
+
const oneSessionMoves = async (adapters) => {
|
|
8
|
+
const rig = await openEpochRig(adapters, {
|
|
9
|
+
brains: [
|
|
10
|
+
{ name: "brain-old", epoch: 1 },
|
|
11
|
+
{ name: "brain-new", epoch: 2 },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
for (const scope of SCOPES)
|
|
15
|
+
rig.setOwner(scope, "brain-old");
|
|
16
|
+
await rig.settle(Promise.all(SCOPES.map((scope) => rig.execute("brain-old", scope, [call(`${scope}1`)]))), "MULTI-EPOCH-01: every scope ran on the old owner");
|
|
17
|
+
rig.setOwner("a", "brain-new");
|
|
18
|
+
const moved = await rig.settle(rig.execute("brain-new", "a", [call("a2")]), "MULTI-EPOCH-01: scope a moved");
|
|
19
|
+
expectEqual(texts(moved), ["ran:a2"], "MULTI-EPOCH-01: the moved scope runs on its new owner");
|
|
20
|
+
const after = await rig.settle(Promise.all(SCOPES.map((scope) => rig.execute("brain-old", scope, [call(`${scope}3`)]))), "MULTI-EPOCH-01: the old owner's next calls");
|
|
21
|
+
expectEqual(after.map(texts), [["The hand refused this tool call: epoch_fenced"], ["ran:b3"], ["ran:c3"]], "MULTI-EPOCH-01: only the moved scope fences the old owner; the others run untouched");
|
|
22
|
+
for (const scope of ["b", "c"])
|
|
23
|
+
expectEqual(await rig.floor(scope), { epoch: 1, owner: "brain-old" }, `MULTI-EPOCH-01: scope ${scope}'s floor`);
|
|
24
|
+
expectEqual([...rig.bodies].sort(), ["a1", "a2", "b1", "b3", "c1", "c3"].map((id) => `${id.charAt(0)}:${id}`), "MULTI-EPOCH-01: every scope's calls ran once; the fenced one never ran");
|
|
25
|
+
};
|
|
26
|
+
export const MULTI_EPOCH_CASES = new Map([
|
|
27
|
+
["MULTI-EPOCH-01", oneSessionMoves],
|
|
28
|
+
]);
|
|
29
|
+
//# sourceMappingURL=multi-epoch-cases.js.map
|
|
@@ -12,7 +12,7 @@ export interface ToolHostCall {
|
|
|
12
12
|
readonly mode: ToolExecutionMode;
|
|
13
13
|
}
|
|
14
14
|
export interface ExecutionPipelineWitness {
|
|
15
|
-
readonly pipeline: "
|
|
15
|
+
readonly pipeline: "prepared";
|
|
16
16
|
readonly toolCallId: string;
|
|
17
17
|
}
|
|
18
18
|
export interface ToolHostResult {
|
|
@@ -34,6 +34,18 @@ export interface ToolHostOptions {
|
|
|
34
34
|
readonly assistantMessage: AssistantMessage;
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
/** The loop had a tool batch to run on its default pipeline but no `batchStoreFactory`; it refuses instead of guessing a store. */
|
|
38
|
+
export declare class BatchStoreMissingError extends Error {
|
|
39
|
+
readonly code = "batch_store_missing";
|
|
40
|
+
constructor();
|
|
41
|
+
}
|
|
42
|
+
/** The loop had a tool batch to run on its default pipeline but no `afterToolFreeze`; it refuses instead of dropping preflight facts. */
|
|
43
|
+
export declare class PreflightCarryMissingError extends Error {
|
|
44
|
+
readonly code = "preflight_carry_missing";
|
|
45
|
+
constructor();
|
|
46
|
+
}
|
|
47
|
+
/** The package entry's default `afterToolFreeze`: for hosts whose `beforeToolCall` binds nothing to the arguments object. */
|
|
48
|
+
export declare function noPreflightCarry(_prepared: unknown, _frozen: unknown): void;
|
|
37
49
|
export interface ToolHost {
|
|
38
50
|
execute(call: ToolHostCall, options: ToolHostOptions): Promise<ToolHostResult>;
|
|
39
51
|
}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/** The loop had a tool batch to run on its default pipeline but no `batchStoreFactory`; it refuses instead of guessing a store. */
|
|
2
|
+
export class BatchStoreMissingError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super("agent loop: no batchStoreFactory configured for the prepared pipeline; pass one (or a toolHost)");
|
|
5
|
+
this.code = "batch_store_missing";
|
|
6
|
+
this.name = "BatchStoreMissingError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** The loop had a tool batch to run on its default pipeline but no `afterToolFreeze`; it refuses instead of dropping preflight facts. */
|
|
10
|
+
export class PreflightCarryMissingError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("agent loop: no afterToolFreeze configured for the prepared pipeline; pass one (or a toolHost)");
|
|
13
|
+
this.code = "preflight_carry_missing";
|
|
14
|
+
this.name = "PreflightCarryMissingError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The package entry's default `afterToolFreeze`: for hosts whose `beforeToolCall` binds nothing to the arguments object. */
|
|
18
|
+
export function noPreflightCarry(_prepared, _frozen) { }
|
|
2
19
|
//# sourceMappingURL=tool-host.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonRepresentation } from "@earendil-works/chord";
|
|
2
2
|
import type { Api, AssistantMessage, AssistantMessageEvent, AssistantMessageFrame, DeferredHandle, ImageContent, Message, Model, Models, RetryPolicy, ToolResultMessage, Usage } from "@earendil-works/pi-ai";
|
|
3
|
+
import type { ExecutionPipelineWitness } from "../execution/tool-host.ts";
|
|
3
4
|
import type { AgentMessage, AgentToolResult, QueueMode, ThinkingLevel } from "../types.ts";
|
|
4
5
|
import type { BranchPreparation, BranchSummaryResult } from "./compaction/branch-summarization.ts";
|
|
5
6
|
import type { CompactionPreparation, CompactionSettings, CompactResult } from "./compaction/compaction.ts";
|
|
@@ -632,6 +633,11 @@ export interface AgentHarnessOptions<TContext extends object | undefined = objec
|
|
|
632
633
|
toolExecution?: "sequential" | "parallel";
|
|
633
634
|
toProviderMessages?: (messages: AgentMessage[], context: Context) => Message[] | Promise<Message[]>;
|
|
634
635
|
entryProjectors?: Record<string, EntryProjector>;
|
|
636
|
+
/**
|
|
637
|
+
* Receives `{ pipeline: "prepared", toolCallId }` for every tool call whose body runs, as `Agent.onExecutionPipeline`
|
|
638
|
+
* does. A callback that throws fails that tool call, as on `Agent`.
|
|
639
|
+
*/
|
|
640
|
+
onExecutionPipeline?: (witness: ExecutionPipelineWitness) => void | Promise<void>;
|
|
635
641
|
}
|
|
636
642
|
export interface AgentLane {
|
|
637
643
|
readonly name: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ExecutionPipelineWitness } from "../../execution/tool-host.ts";
|
|
2
|
+
import type { AgentToolCall, AgentToolResult } from "../../types.ts";
|
|
3
|
+
export type WitnessSink = (witness: ExecutionPipelineWitness) => Promise<void> | void;
|
|
4
|
+
/**
|
|
5
|
+
* Runs one cleared harness call's body on the in-process prepared ToolHost (S19c), as a one-call batch on its own
|
|
6
|
+
* in-memory ledger. The harness already prepared, validated and hooked the call, so the host passes its arguments
|
|
7
|
+
* through unchanged; `run` owns the harness's own signal, updates and error semantics.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runOnPreparedToolHost<T>(toolCall: AgentToolCall, scopeId: string, recordWitness: WitnessSink | undefined, run: (args: unknown) => Promise<{
|
|
10
|
+
readonly outcome: T;
|
|
11
|
+
readonly result: AgentToolResult<unknown>;
|
|
12
|
+
}>): Promise<T>;
|
|
13
|
+
//# sourceMappingURL=tool-host-call.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { openMemoryBatchStore } from "../../execution/prepared/memory-batch-store.js";
|
|
3
|
+
import { createPreparedToolHost } from "../../execution/prepared/pipeline-prepared.js";
|
|
4
|
+
import { noPreflightCarry } from "../../execution/tool-host.js";
|
|
5
|
+
const CLEARED_ARGUMENTS = Type.Unknown();
|
|
6
|
+
function issuingMessage(toolCall) {
|
|
7
|
+
return {
|
|
8
|
+
role: "assistant",
|
|
9
|
+
content: [toolCall],
|
|
10
|
+
api: "agent-harness",
|
|
11
|
+
provider: "agent-harness",
|
|
12
|
+
model: "agent-harness",
|
|
13
|
+
usage: {
|
|
14
|
+
input: 0,
|
|
15
|
+
output: 0,
|
|
16
|
+
cacheRead: 0,
|
|
17
|
+
cacheWrite: 0,
|
|
18
|
+
totalTokens: 0,
|
|
19
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
20
|
+
},
|
|
21
|
+
stopReason: "toolUse",
|
|
22
|
+
timestamp: Date.now(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Runs one cleared harness call's body on the in-process prepared ToolHost (S19c), as a one-call batch on its own
|
|
27
|
+
* in-memory ledger. The harness already prepared, validated and hooked the call, so the host passes its arguments
|
|
28
|
+
* through unchanged; `run` owns the harness's own signal, updates and error semantics.
|
|
29
|
+
*/
|
|
30
|
+
export async function runOnPreparedToolHost(toolCall, scopeId, recordWitness, run) {
|
|
31
|
+
let settled;
|
|
32
|
+
const body = {
|
|
33
|
+
name: toolCall.name,
|
|
34
|
+
label: toolCall.name,
|
|
35
|
+
description: toolCall.name,
|
|
36
|
+
parameters: CLEARED_ARGUMENTS,
|
|
37
|
+
execute: async (_toolCallId, args) => {
|
|
38
|
+
const { outcome, result } = await run(args);
|
|
39
|
+
settled = { outcome };
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
await createPreparedToolHost({ afterToolFreeze: noPreflightCarry, removedToolHints: {} }, openMemoryBatchStore).execute({ scope: { id: scopeId, root: "" }, calls: [toolCall], mode: "sequential" }, {
|
|
44
|
+
emit: () => undefined,
|
|
45
|
+
...(recordWitness === undefined ? {} : { recordWitness }),
|
|
46
|
+
local: {
|
|
47
|
+
context: { systemPrompt: "", messages: [], tools: [body] },
|
|
48
|
+
assistantMessage: issuingMessage(toolCall),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (settled === undefined)
|
|
52
|
+
throw new Error(`agent harness: the prepared host ran no body for ${toolCall.name}`);
|
|
53
|
+
return settled.outcome;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=tool-host-call.js.map
|
|
@@ -4,6 +4,7 @@ import { type Context } from "../context.ts";
|
|
|
4
4
|
import type { JsonValue } from "../session/types.ts";
|
|
5
5
|
import type { AgentHarnessTool, AgentHarnessToolInvocation, AgentHarnessToolUpdateCallback } from "../types.ts";
|
|
6
6
|
import type { Gate } from "./effect-gate.ts";
|
|
7
|
+
import { type WitnessSink } from "./tool-host-call.ts";
|
|
7
8
|
/** A tool call whose tool exists and whose prepared arguments passed validation. */
|
|
8
9
|
export interface PreparedToolCall<TContext extends object | undefined> {
|
|
9
10
|
toolCall: AgentToolCall;
|
|
@@ -57,7 +58,7 @@ export declare function prepareToolCall<TContext extends object | undefined>(cal
|
|
|
57
58
|
/** Apply an explicit hook decision and revalidate replacement arguments. */
|
|
58
59
|
export declare function applyBeforeToolDecision<TContext extends object | undefined>(prepared: PreparedToolCall<TContext>, decision: BeforeToolDecision | undefined): ClearedToolCall<TContext> | ImmediateToolOutcome;
|
|
59
60
|
/** Execute one cleared external tool effect, converting expected tool throws to error output. */
|
|
60
|
-
export declare function executeToolCall<TContext extends object | undefined>(call: ClearedToolCall<TContext>, gate: Gate, onUpdate: AgentHarnessToolUpdateCallback<unknown>, toolContext: TContext, invocation: AgentHarnessToolInvocation, context: Context): Promise<ExecutedToolCall>;
|
|
61
|
+
export declare function executeToolCall<TContext extends object | undefined>(call: ClearedToolCall<TContext>, gate: Gate, onUpdate: AgentHarnessToolUpdateCallback<unknown>, toolContext: TContext, invocation: AgentHarnessToolInvocation, context: Context, recordWitness?: WitnessSink): Promise<ExecutedToolCall>;
|
|
61
62
|
/** Apply an after-tool patch field by field. */
|
|
62
63
|
export declare function finalizeToolCall<TContext extends object | undefined>(call: ClearedToolCall<TContext>, executed: ExecutedToolCall, patch: AfterToolPatch | undefined): FinalizedToolCall;
|
|
63
64
|
/** Reconstruct the canonical tool result represented by a staged transcript message. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
2
2
|
import { withAbortSignal } from "../context.js";
|
|
3
|
+
import { runOnPreparedToolHost } from "./tool-host-call.js";
|
|
3
4
|
function createErrorToolResult(message) {
|
|
4
5
|
return {
|
|
5
6
|
content: [{ type: "text", text: message }],
|
|
@@ -53,27 +54,41 @@ export function applyBeforeToolDecision(prepared, decision) {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
/** Execute one cleared external tool effect, converting expected tool throws to error output. */
|
|
56
|
-
export function executeToolCall(call, gate, onUpdate, toolContext, invocation, context) {
|
|
57
|
+
export function executeToolCall(call, gate, onUpdate, toolContext, invocation, context, recordWitness) {
|
|
57
58
|
let acceptingUpdates = true;
|
|
58
59
|
return gate.admit(async () => {
|
|
59
60
|
const admittedContext = withAbortSignal(gate.signal, context);
|
|
60
61
|
admittedContext.abortSignal?.throwIfAborted();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
// The harness already prepared, validated and hooked this call, so the host gets only its identity and cleared
|
|
63
|
+
// arguments: a stream flag such as `incomplete` would make the host refuse it before the body runs.
|
|
64
|
+
const toolCall = {
|
|
65
|
+
type: "toolCall",
|
|
66
|
+
id: call.toolCall.id,
|
|
67
|
+
name: call.toolCall.name,
|
|
68
|
+
arguments: call.args,
|
|
69
|
+
};
|
|
70
|
+
// The body receives the host's frozen copy of the arguments (a JSON-value round trip): identical for the JSON
|
|
71
|
+
// arguments a tool takes; a non-JSON value (NaN, Infinity, -0, a Date) would not survive it.
|
|
72
|
+
return runOnPreparedToolHost(toolCall, invocation.invocationId, recordWitness, async (args) => {
|
|
73
|
+
let executed;
|
|
74
|
+
try {
|
|
75
|
+
const result = await call.tool.execute(call.toolCall.id, args, (partial, options) => {
|
|
76
|
+
if (acceptingUpdates)
|
|
77
|
+
onUpdate(partial, options);
|
|
78
|
+
}, toolContext, invocation, admittedContext);
|
|
79
|
+
executed = { result, isError: false };
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
executed = {
|
|
83
|
+
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
|
|
84
|
+
isError: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
acceptingUpdates = false;
|
|
89
|
+
}
|
|
90
|
+
return { outcome: executed, result: executed.result };
|
|
91
|
+
});
|
|
77
92
|
});
|
|
78
93
|
}
|
|
79
94
|
/** Apply an after-tool patch field by field. */
|
|
@@ -262,7 +262,7 @@ async function performToolInvocation(lane, drive, batch, call, cleared, toolCont
|
|
|
262
262
|
publishUpdate(partial);
|
|
263
263
|
if (options?.checkpoint === true)
|
|
264
264
|
progress.write(partial);
|
|
265
|
-
}, toolContext, capability.invocation, drive.context);
|
|
265
|
+
}, toolContext, capability.invocation, drive.context, lane.readConfig().onExecutionPipeline);
|
|
266
266
|
}
|
|
267
267
|
catch (error) {
|
|
268
268
|
capability.expire();
|
|
@@ -39,6 +39,7 @@ export class Harness {
|
|
|
39
39
|
systemPrompt: options.systemPrompt,
|
|
40
40
|
toProviderMessages: options.toProviderMessages ?? ((messages) => convertToLlm(messages)),
|
|
41
41
|
entryProjectors: options.entryProjectors ?? {},
|
|
42
|
+
...(options.onExecutionPipeline === undefined ? {} : { onExecutionPipeline: options.onExecutionPipeline }),
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
for (const [name, state] of restored)
|
|
@@ -23,6 +23,7 @@ export interface Config<TContext extends object | undefined> {
|
|
|
23
23
|
readonly systemPrompt: AgentHarnessOptions<TContext>["systemPrompt"];
|
|
24
24
|
readonly toProviderMessages: NonNullable<AgentHarnessOptions<TContext>["toProviderMessages"]>;
|
|
25
25
|
readonly entryProjectors: Readonly<NonNullable<AgentHarnessOptions<TContext>["entryProjectors"]>>;
|
|
26
|
+
readonly onExecutionPipeline?: AgentHarnessOptions<TContext>["onExecutionPipeline"];
|
|
26
27
|
}
|
|
27
28
|
/** The current durable state owned by one lane. */
|
|
28
29
|
export interface LaneState {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ export type { AttributeValue, ExactTelemetryAttributes, InferEventAttributes, In
|
|
|
3
3
|
export { createTypedSpanStarter, defineTelemetrySchema, InMemoryTelemetryContext, NOOP_TELEMETRY_CONTEXT, } from "@earendil-works/pi-telemetry";
|
|
4
4
|
export * from "./agent.ts";
|
|
5
5
|
export * from "./agent-loop.ts";
|
|
6
|
+
export * from "./egress/types.ts";
|
|
7
|
+
export { isStepCommitError, StepCommitError, type StepCommitFailure } from "./step-commit.ts";
|
|
8
|
+
export { Agent, agentLoop, agentLoopContinue, runAgentLoop, runAgentLoopContinue } from "./public-entry.ts";
|
|
6
9
|
export { createInternalAgentChannel, type InternalAgentChannel, type OrderedAgentRecord } from "./internal-events.ts";
|
|
7
10
|
export { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from "./assistant-terminal-state.ts";
|
|
8
11
|
export { createRemoteExecutor, type HandCall, type HandScope, type OpenHandScope, type RemoteExecutor, type RemoteExecutorOptions, } from "./execution/remote-executor.ts";
|
|
9
12
|
export { createHandLedger, type HandAdmission, type HandLedger, type HandLedgerOptions, } from "./execution/remote-hand-ledger.ts";
|
|
10
|
-
export { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, type RemoteAbort, type RemoteAck, type RemoteHandMessage, type RemoteFile, type RemoteHello, type RemoteInvoke, type RemoteRefused, type RemoteSettled, RemoteProtocolError, type RemoteTerminal, type RemoteTerminalReason, type RemoteToolResult, } from "./execution/remote-protocol.ts";
|
|
13
|
+
export { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, type RemoteAbort, type EpochRefusal, type RemoteAck, type RemoteHandMessage, type RemoteFile, type RemoteHello, type RemoteInvoke, type RemoteFloor, type RemoteFloorAck, type RemoteFloorRefused, type RemoteRefused, type RemoteSettled, RemoteProtocolError, type RemoteTerminal, type RemoteTerminalReason, type RemoteToolResult, } from "./execution/remote-protocol.ts";
|
|
11
14
|
export { createErrorToolResult, createToolResultMessage, emitToolExecutionEnd, emitToolExecutionUpdate, emitToolResultMessage, shouldTerminateToolBatch, } from "./execution/tool-outcome-events.ts";
|
|
12
15
|
export { createAdmissionLine } from "./durable/store-admission.ts";
|
|
13
16
|
export { createMemoryStoreMedium, openMemoryStore } from "./durable/store-memory.ts";
|
|
@@ -15,12 +18,23 @@ export { createBatchCoordinator } from "./execution/coordinator.ts";
|
|
|
15
18
|
export type { BatchExecutor, BatchPlan } from "./execution/coordinator-types.ts";
|
|
16
19
|
export { createExecutionLedger } from "./execution/ledger.ts";
|
|
17
20
|
export { authorize, createGrantVerifier, DEFAULT_WORKSPACE, type GrantRefusal, type GrantRow, type GrantSnapshot, type GrantVerdict, type GrantVerifier, type GrantVerifierOptions, HAND_CAPABILITY, type HandAuthority, type WorkspaceRoot, } from "./execution/grant-verify.ts";
|
|
18
|
-
export {
|
|
21
|
+
export { createHandEpochFence, EPOCH_FLOOR_MAX_STEP, type FloorRaise, HAND_SELF_SENDER, type HandEpochFence, type HandEpochFenceOptions, } from "./execution/remote-epoch.ts";
|
|
22
|
+
export { base64Length, DEVICE_FILE_OPS, type DeviceFileArgs, DeviceFileError, type DeviceFileErrorCode, type DeviceFileOp, type DeviceFileOptions, type DeviceRunRequest, type DeviceRunResult, type DeviceFileOutcome, type DeviceFiles, type DeviceFileStat, decodeBase64, decodeDeviceFileArgs, encodeBase64, FILE_CHANNEL, FILE_CHANNEL_MAX_BYTES, RUN_CHANNEL, fileOutcomeOf, } from "./execution/device-files.ts";
|
|
19
23
|
export { HELLO_WAIT_MS } from "./execution/remote-device-files.ts";
|
|
20
24
|
export { fileRefusal, fileResult } from "./execution/remote-file-call.ts";
|
|
21
25
|
export { createModelPlaneClient, decodeModelPlaneRequest, MODEL_PLANE, type ModelPlaneRequest, serveModelPlane, } from "./execution/plane-model.ts";
|
|
26
|
+
export { createLoopToolHost, createSessionPlaneClient, createSplitToolHost, decodeSessionPlaneRequest, loopSideToolNames, SESSION_PLANE, type SessionPlaneRequest, serveSessionPlane, } from "./execution/plane-session.ts";
|
|
27
|
+
export { admitChainCall, CHAIN_COUNT_LIMIT, CHAIN_ORIGIN, ChainCountLimitError, decodeChainCount, nextChainCount, } from "./execution/chain-count.ts";
|
|
22
28
|
export { decodePlaneMessage, encodePlaneMessage, type NestedRequest, type PlaneHandler, type PlaneMessage, PlaneRefusedError, } from "./execution/plane.ts";
|
|
29
|
+
export { createLoopHookHost, type LoopHookHost, type LoopHookHostOptions, LoopHookFailedError, LoopHookRestartedError, } from "./execution/loop-hook-host.ts";
|
|
30
|
+
export { type LoopHookHand, type LoopHookHandOptions, type LoopHookPoint, type LoopHookRunner, serveLoopHooks, } from "./execution/loop-hook-host-hand.ts";
|
|
23
31
|
export { createRemoteToolHost, type HandPlacement, type RemoteToolHostOptions } from "./execution/remote-tool-host.ts";
|
|
32
|
+
export { canonicalJson } from "./execution/canonical-digest.ts";
|
|
33
|
+
export { toStoreValue } from "./execution/prepared/executor-freeze.ts";
|
|
34
|
+
export type { ConsentClassifier } from "./execution/prepared/executor-types.ts";
|
|
35
|
+
export { openMemoryBatchStore } from "./execution/prepared/memory-batch-store.ts";
|
|
36
|
+
export { BatchStoreMissingError, noPreflightCarry, PreflightCarryMissingError } from "./execution/tool-host.ts";
|
|
37
|
+
export { createPreparedToolHost } from "./execution/prepared/pipeline-prepared.ts";
|
|
24
38
|
export { type CarrierLink, createInProcessNetwork, type InProcessNetwork } from "./transport/in-process-carrier.ts";
|
|
25
39
|
export { type LocalEndpoint, localEndpoint } from "./transport/local-endpoint.ts";
|
|
26
40
|
export { createReliableTransport, type ReliableTransportOptions } from "./transport/reliable-transport.ts";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,9 @@ export { uuidv7 } from "@earendil-works/pi-ai";
|
|
|
2
2
|
export { createTypedSpanStarter, defineTelemetrySchema, InMemoryTelemetryContext, NOOP_TELEMETRY_CONTEXT, } from "@earendil-works/pi-telemetry";
|
|
3
3
|
export * from "./agent.js";
|
|
4
4
|
export * from "./agent-loop.js";
|
|
5
|
+
export * from "./egress/types.js";
|
|
6
|
+
export { isStepCommitError, StepCommitError } from "./step-commit.js";
|
|
7
|
+
export { Agent, agentLoop, agentLoopContinue, runAgentLoop, runAgentLoopContinue } from "./public-entry.js";
|
|
5
8
|
export { createInternalAgentChannel } from "./internal-events.js";
|
|
6
9
|
export { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from "./assistant-terminal-state.js";
|
|
7
10
|
export { createRemoteExecutor, } from "./execution/remote-executor.js";
|
|
@@ -13,12 +16,22 @@ export { createMemoryStoreMedium, openMemoryStore } from "./durable/store-memory
|
|
|
13
16
|
export { createBatchCoordinator } from "./execution/coordinator.js";
|
|
14
17
|
export { createExecutionLedger } from "./execution/ledger.js";
|
|
15
18
|
export { authorize, createGrantVerifier, DEFAULT_WORKSPACE, HAND_CAPABILITY, } from "./execution/grant-verify.js";
|
|
16
|
-
export {
|
|
19
|
+
export { createHandEpochFence, EPOCH_FLOOR_MAX_STEP, HAND_SELF_SENDER, } from "./execution/remote-epoch.js";
|
|
20
|
+
export { base64Length, DEVICE_FILE_OPS, DeviceFileError, decodeBase64, decodeDeviceFileArgs, encodeBase64, FILE_CHANNEL, FILE_CHANNEL_MAX_BYTES, RUN_CHANNEL, fileOutcomeOf, } from "./execution/device-files.js";
|
|
17
21
|
export { HELLO_WAIT_MS } from "./execution/remote-device-files.js";
|
|
18
22
|
export { fileRefusal, fileResult } from "./execution/remote-file-call.js";
|
|
19
23
|
export { createModelPlaneClient, decodeModelPlaneRequest, MODEL_PLANE, serveModelPlane, } from "./execution/plane-model.js";
|
|
24
|
+
export { createLoopToolHost, createSessionPlaneClient, createSplitToolHost, decodeSessionPlaneRequest, loopSideToolNames, SESSION_PLANE, serveSessionPlane, } from "./execution/plane-session.js";
|
|
25
|
+
export { admitChainCall, CHAIN_COUNT_LIMIT, CHAIN_ORIGIN, ChainCountLimitError, decodeChainCount, nextChainCount, } from "./execution/chain-count.js";
|
|
20
26
|
export { decodePlaneMessage, encodePlaneMessage, PlaneRefusedError, } from "./execution/plane.js";
|
|
27
|
+
export { createLoopHookHost, LoopHookFailedError, LoopHookRestartedError, } from "./execution/loop-hook-host.js";
|
|
28
|
+
export { serveLoopHooks, } from "./execution/loop-hook-host-hand.js";
|
|
21
29
|
export { createRemoteToolHost } from "./execution/remote-tool-host.js";
|
|
30
|
+
export { canonicalJson } from "./execution/canonical-digest.js";
|
|
31
|
+
export { toStoreValue } from "./execution/prepared/executor-freeze.js";
|
|
32
|
+
export { openMemoryBatchStore } from "./execution/prepared/memory-batch-store.js";
|
|
33
|
+
export { BatchStoreMissingError, noPreflightCarry, PreflightCarryMissingError } from "./execution/tool-host.js";
|
|
34
|
+
export { createPreparedToolHost } from "./execution/prepared/pipeline-prepared.js";
|
|
22
35
|
export { createInProcessNetwork } from "./transport/in-process-carrier.js";
|
|
23
36
|
export { localEndpoint } from "./transport/local-endpoint.js";
|
|
24
37
|
export { createReliableTransport } from "./transport/reliable-transport.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Agent as LoopAgent, type AgentOptions } from "./agent.ts";
|
|
2
|
+
import { agentLoop as loopAgentLoop, agentLoopContinue as loopAgentLoopContinue, runAgentLoop as loopRunAgentLoop, runAgentLoopContinue as loopRunAgentLoopContinue } from "./agent-loop.ts";
|
|
3
|
+
export declare class Agent extends LoopAgent {
|
|
4
|
+
constructor(options: AgentOptions);
|
|
5
|
+
}
|
|
6
|
+
export declare const agentLoop: typeof loopAgentLoop;
|
|
7
|
+
export declare const agentLoopContinue: typeof loopAgentLoopContinue;
|
|
8
|
+
export declare const runAgentLoop: typeof loopRunAgentLoop;
|
|
9
|
+
export declare const runAgentLoopContinue: typeof loopRunAgentLoopContinue;
|
|
10
|
+
//# sourceMappingURL=public-entry.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Agent as LoopAgent } from "./agent.js";
|
|
2
|
+
import { agentLoop as loopAgentLoop, agentLoopContinue as loopAgentLoopContinue, runAgentLoop as loopRunAgentLoop, runAgentLoopContinue as loopRunAgentLoopContinue, } from "./agent-loop.js";
|
|
3
|
+
import { openMemoryBatchStore } from "./execution/prepared/memory-batch-store.js";
|
|
4
|
+
import { noPreflightCarry } from "./execution/tool-host.js";
|
|
5
|
+
// The package entry's loop and Agent: the loop core builds no store (senpi#4996), so the entry supplies a fresh in-memory
|
|
6
|
+
// store per batch unless the caller passes its own factory or ToolHost. External callers need no new argument.
|
|
7
|
+
function withBatchStore(config) {
|
|
8
|
+
return {
|
|
9
|
+
...config,
|
|
10
|
+
batchStoreFactory: config.batchStoreFactory ?? openMemoryBatchStore,
|
|
11
|
+
afterToolFreeze: config.afterToolFreeze ?? noPreflightCarry,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export class Agent extends LoopAgent {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super(withBatchStore(options));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const agentLoop = (prompts, context, config, signal, streamFn) => loopAgentLoop(prompts, context, withBatchStore(config), signal, streamFn);
|
|
20
|
+
export const agentLoopContinue = (context, config, signal, streamFn) => loopAgentLoopContinue(context, withBatchStore(config), signal, streamFn);
|
|
21
|
+
export const runAgentLoop = (prompts, context, config, emit, signal, streamFn) => loopRunAgentLoop(prompts, context, withBatchStore(config), emit, signal, streamFn);
|
|
22
|
+
export const runAgentLoopContinue = (context, config, emit, signal, streamFn) => loopRunAgentLoopContinue(context, withBatchStore(config), emit, signal, streamFn);
|
|
23
|
+
//# sourceMappingURL=public-entry.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The durable step commit a hosted brain host installs through `AgentLoopConfig.commitStep`.
|
|
3
|
+
*
|
|
4
|
+
* Fused and split-local assemblies never set `commitStep` and never construct a `StepCommitError`;
|
|
5
|
+
* only a hosted host's commit implementation (and its conformance harness) does. The error is branded
|
|
6
|
+
* with a registry symbol so a value built by a second copy of this package (version skew, a bundler
|
|
7
|
+
* duplicate) is still recognised: callers check it with `isStepCommitError`, never `instanceof`.
|
|
8
|
+
*/
|
|
9
|
+
export type StepCommitFailure = "already_committed" | "fenced" | "generation" | "epoch_unverified" | "storage_unavailable" | "ambiguous_unresolved";
|
|
10
|
+
declare const STEP_COMMIT_BRAND: unique symbol;
|
|
11
|
+
/** A hosted step commit failed; the step's message is not durable and must not be acted on. */
|
|
12
|
+
export declare class StepCommitError extends Error {
|
|
13
|
+
readonly name: "StepCommitError";
|
|
14
|
+
readonly [STEP_COMMIT_BRAND]: true;
|
|
15
|
+
readonly stepId: string;
|
|
16
|
+
readonly code: StepCommitFailure;
|
|
17
|
+
constructor(stepId: string, code: StepCommitFailure, options?: {
|
|
18
|
+
readonly cause?: unknown;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** True for a `StepCommitError` from any copy of this package; false for look-alikes without the brand. */
|
|
22
|
+
export declare function isStepCommitError(value: unknown): value is StepCommitError;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=step-commit.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The durable step commit a hosted brain host installs through `AgentLoopConfig.commitStep`.
|
|
3
|
+
*
|
|
4
|
+
* Fused and split-local assemblies never set `commitStep` and never construct a `StepCommitError`;
|
|
5
|
+
* only a hosted host's commit implementation (and its conformance harness) does. The error is branded
|
|
6
|
+
* with a registry symbol so a value built by a second copy of this package (version skew, a bundler
|
|
7
|
+
* duplicate) is still recognised: callers check it with `isStepCommitError`, never `instanceof`.
|
|
8
|
+
*/
|
|
9
|
+
const STEP_COMMIT_BRAND = Symbol.for("senpi.StepCommitError");
|
|
10
|
+
/** A hosted step commit failed; the step's message is not durable and must not be acted on. */
|
|
11
|
+
export class StepCommitError extends Error {
|
|
12
|
+
constructor(stepId, code, options) {
|
|
13
|
+
super(`step commit failed: ${code}`, options);
|
|
14
|
+
this.name = "StepCommitError";
|
|
15
|
+
this.stepId = stepId;
|
|
16
|
+
this.code = code;
|
|
17
|
+
Object.defineProperty(this, STEP_COMMIT_BRAND, { value: true, enumerable: false, writable: false });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** True for a `StepCommitError` from any copy of this package; false for look-alikes without the brand. */
|
|
21
|
+
export function isStepCommitError(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && Reflect.get(value, STEP_COMMIT_BRAND) === true;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=step-commit.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentToolResult } from "./types.ts";
|
|
2
2
|
/**
|
|
3
3
|
* A model can call a tool by a name it was never registered under: recased,
|
|
4
4
|
* under a gateway namespace (`mcp__<id>__<Name>`, any case), or without the
|
|
@@ -7,11 +7,5 @@ import type { AgentContext, AgentLoopConfig, AgentTool, AgentToolCall, AgentTool
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function resolveToolNameAlias(requested: string, available: Iterable<string>): string | undefined;
|
|
9
9
|
export declare function toolNameCorrectionNotice(requested: string, resolved: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Find the tool a call will run, resolving an unknown name through the host
|
|
12
|
-
* resolver and then the alias rule. Runs before `tool_execution_start` so every
|
|
13
|
-
* event names the tool that executes, never the name the model mistyped.
|
|
14
|
-
*/
|
|
15
|
-
export declare function resolveCallTool(currentContext: AgentContext, toolCall: AgentToolCall, config: AgentLoopConfig): Promise<AgentTool | undefined>;
|
|
16
10
|
export declare function withToolNameCorrection(result: AgentToolResult<unknown>, requestedName: string, resolvedName: string): AgentToolResult<unknown>;
|
|
17
11
|
//# sourceMappingURL=tool-name-alias.d.ts.map
|
package/dist/tool-name-alias.js
CHANGED
|
@@ -11,23 +11,6 @@ export function resolveToolNameAlias(requested, available) {
|
|
|
11
11
|
export function toolNameCorrectionNotice(requested, resolved) {
|
|
12
12
|
return `[auto-corrected] no tool is named "${requested}"; ran "${resolved}". Call tools by their exact listed name.`;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Find the tool a call will run, resolving an unknown name through the host
|
|
16
|
-
* resolver and then the alias rule. Runs before `tool_execution_start` so every
|
|
17
|
-
* event names the tool that executes, never the name the model mistyped.
|
|
18
|
-
*/
|
|
19
|
-
export async function resolveCallTool(currentContext, toolCall, config) {
|
|
20
|
-
if (toolCall.incomplete === true)
|
|
21
|
-
return undefined;
|
|
22
|
-
const exact = currentContext.tools?.find((candidate) => candidate.name === toolCall.name);
|
|
23
|
-
if (exact)
|
|
24
|
-
return exact;
|
|
25
|
-
const resolved = await config.resolveUnknownToolCall?.(toolCall.name, currentContext);
|
|
26
|
-
if (resolved)
|
|
27
|
-
return resolved;
|
|
28
|
-
const aliasedName = resolveToolNameAlias(toolCall.name, (currentContext.tools ?? []).map((candidate) => candidate.name));
|
|
29
|
-
return currentContext.tools?.find((candidate) => candidate.name === aliasedName);
|
|
30
|
-
}
|
|
31
14
|
export function withToolNameCorrection(result, requestedName, resolvedName) {
|
|
32
15
|
return {
|
|
33
16
|
...result,
|