@amaranthic/hernex 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +66 -2
- package/dist/ai.d.ts +11 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +11 -0
- package/dist/ai.js.map +1 -0
- package/dist/checkpoints/FileCheckpointStore.d.ts +95 -0
- package/dist/checkpoints/FileCheckpointStore.d.ts.map +1 -0
- package/dist/checkpoints/FileCheckpointStore.js +412 -0
- package/dist/checkpoints/FileCheckpointStore.js.map +1 -0
- package/dist/checkpoints/index.d.ts +7 -0
- package/dist/checkpoints/index.d.ts.map +1 -0
- package/dist/checkpoints/index.js +7 -0
- package/dist/checkpoints/index.js.map +1 -0
- package/dist/checkpoints/types.d.ts +157 -0
- package/dist/checkpoints/types.d.ts.map +1 -0
- package/dist/checkpoints/types.js +6 -0
- package/dist/checkpoints/types.js.map +1 -0
- package/dist/engine/AgentEngine.d.ts +156 -0
- package/dist/engine/AgentEngine.d.ts.map +1 -0
- package/dist/engine/AgentEngine.js +288 -0
- package/dist/engine/AgentEngine.js.map +1 -0
- package/dist/engine/engineConfig.d.ts +138 -0
- package/dist/engine/engineConfig.d.ts.map +1 -0
- package/dist/engine/engineConfig.js +6 -0
- package/dist/engine/engineConfig.js.map +1 -0
- package/dist/engine/eventQueue.d.ts +42 -0
- package/dist/engine/eventQueue.d.ts.map +1 -0
- package/dist/engine/eventQueue.js +93 -0
- package/dist/engine/eventQueue.js.map +1 -0
- package/dist/engine/index.d.ts +7 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +6 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/runTurn.d.ts +17 -0
- package/dist/engine/runTurn.d.ts.map +1 -0
- package/dist/engine/runTurn.js +684 -0
- package/dist/engine/runTurn.js.map +1 -0
- package/dist/errors.d.ts +142 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +174 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/checkpointEvents.d.ts +20 -0
- package/dist/events/checkpointEvents.d.ts.map +1 -0
- package/dist/events/checkpointEvents.js +6 -0
- package/dist/events/checkpointEvents.js.map +1 -0
- package/dist/events/errorEvents.d.ts +23 -0
- package/dist/events/errorEvents.d.ts.map +1 -0
- package/dist/events/errorEvents.js +6 -0
- package/dist/events/errorEvents.js.map +1 -0
- package/dist/events/index.d.ts +11 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +6 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/stepEvents.d.ts +68 -0
- package/dist/events/stepEvents.d.ts.map +1 -0
- package/dist/events/stepEvents.js +6 -0
- package/dist/events/stepEvents.js.map +1 -0
- package/dist/events/streamEvents.d.ts +41 -0
- package/dist/events/streamEvents.d.ts.map +1 -0
- package/dist/events/streamEvents.js +6 -0
- package/dist/events/streamEvents.js.map +1 -0
- package/dist/events/toolEvents.d.ts +62 -0
- package/dist/events/toolEvents.d.ts.map +1 -0
- package/dist/events/toolEvents.js +6 -0
- package/dist/events/toolEvents.js.map +1 -0
- package/dist/events/types.d.ts +37 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +6 -0
- package/dist/events/types.js.map +1 -0
- package/dist/hooks/composeAgentHooks.d.ts +14 -0
- package/dist/hooks/composeAgentHooks.d.ts.map +1 -0
- package/dist/hooks/composeAgentHooks.js +142 -0
- package/dist/hooks/composeAgentHooks.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/types.d.ts +133 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +6 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/model/ProviderRegistry.d.ts +62 -0
- package/dist/model/ProviderRegistry.d.ts.map +1 -0
- package/dist/model/ProviderRegistry.js +114 -0
- package/dist/model/ProviderRegistry.js.map +1 -0
- package/dist/model/providers/alibaba.d.ts +11 -0
- package/dist/model/providers/alibaba.d.ts.map +1 -0
- package/dist/model/providers/alibaba.js +16 -0
- package/dist/model/providers/alibaba.js.map +1 -0
- package/dist/model/providers/anthropic.d.ts +11 -0
- package/dist/model/providers/anthropic.d.ts.map +1 -0
- package/dist/model/providers/anthropic.js +16 -0
- package/dist/model/providers/anthropic.js.map +1 -0
- package/dist/model/providers/cohere.d.ts +11 -0
- package/dist/model/providers/cohere.d.ts.map +1 -0
- package/dist/model/providers/cohere.js +16 -0
- package/dist/model/providers/cohere.js.map +1 -0
- package/dist/model/providers/compatible.d.ts +11 -0
- package/dist/model/providers/compatible.d.ts.map +1 -0
- package/dist/model/providers/compatible.js +17 -0
- package/dist/model/providers/compatible.js.map +1 -0
- package/dist/model/providers/deepseek.d.ts +11 -0
- package/dist/model/providers/deepseek.d.ts.map +1 -0
- package/dist/model/providers/deepseek.js +16 -0
- package/dist/model/providers/deepseek.js.map +1 -0
- package/dist/model/providers/google.d.ts +11 -0
- package/dist/model/providers/google.d.ts.map +1 -0
- package/dist/model/providers/google.js +16 -0
- package/dist/model/providers/google.js.map +1 -0
- package/dist/model/providers/groq.d.ts +11 -0
- package/dist/model/providers/groq.d.ts.map +1 -0
- package/dist/model/providers/groq.js +16 -0
- package/dist/model/providers/groq.js.map +1 -0
- package/dist/model/providers/mistral.d.ts +11 -0
- package/dist/model/providers/mistral.d.ts.map +1 -0
- package/dist/model/providers/mistral.js +16 -0
- package/dist/model/providers/mistral.js.map +1 -0
- package/dist/model/providers/openai.d.ts +11 -0
- package/dist/model/providers/openai.d.ts.map +1 -0
- package/dist/model/providers/openai.js +16 -0
- package/dist/model/providers/openai.js.map +1 -0
- package/dist/model/providers/openrouter.d.ts +14 -0
- package/dist/model/providers/openrouter.d.ts.map +1 -0
- package/dist/model/providers/openrouter.js +20 -0
- package/dist/model/providers/openrouter.js.map +1 -0
- package/dist/model/providers/togetherai.d.ts +11 -0
- package/dist/model/providers/togetherai.d.ts.map +1 -0
- package/dist/model/providers/togetherai.js +16 -0
- package/dist/model/providers/togetherai.js.map +1 -0
- package/dist/model/providers/vercelGateway.d.ts +14 -0
- package/dist/model/providers/vercelGateway.d.ts.map +1 -0
- package/dist/model/providers/vercelGateway.js +19 -0
- package/dist/model/providers/vercelGateway.js.map +1 -0
- package/dist/model/providers/xai.d.ts +11 -0
- package/dist/model/providers/xai.d.ts.map +1 -0
- package/dist/model/providers/xai.js +16 -0
- package/dist/model/providers/xai.js.map +1 -0
- package/dist/model/resolveModel.d.ts +45 -0
- package/dist/model/resolveModel.d.ts.map +1 -0
- package/dist/model/resolveModel.js +109 -0
- package/dist/model/resolveModel.js.map +1 -0
- package/dist/model/types.d.ts +98 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +6 -0
- package/dist/model/types.js.map +1 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +41 -0
- package/dist/runtime.js.map +1 -0
- package/dist/storage/atomicFile.d.ts +28 -0
- package/dist/storage/atomicFile.d.ts.map +1 -0
- package/dist/storage/atomicFile.js +56 -0
- package/dist/storage/atomicFile.js.map +1 -0
- package/dist/storage/homeDirectory.d.ts +21 -0
- package/dist/storage/homeDirectory.d.ts.map +1 -0
- package/dist/storage/homeDirectory.js +36 -0
- package/dist/storage/homeDirectory.js.map +1 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +10 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/jsonl.d.ts +46 -0
- package/dist/storage/jsonl.d.ts.map +1 -0
- package/dist/storage/jsonl.js +121 -0
- package/dist/storage/jsonl.js.map +1 -0
- package/dist/storage/lock.d.ts +47 -0
- package/dist/storage/lock.d.ts.map +1 -0
- package/dist/storage/lock.js +126 -0
- package/dist/storage/lock.js.map +1 -0
- package/dist/storage/valueCodec.d.ts +68 -0
- package/dist/storage/valueCodec.d.ts.map +1 -0
- package/dist/storage/valueCodec.js +140 -0
- package/dist/storage/valueCodec.js.map +1 -0
- package/dist/tasks/TaskManager.d.ts +155 -0
- package/dist/tasks/TaskManager.d.ts.map +1 -0
- package/dist/tasks/TaskManager.js +774 -0
- package/dist/tasks/TaskManager.js.map +1 -0
- package/dist/tasks/index.d.ts +7 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +6 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/types.d.ts +160 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/types.js +8 -0
- package/dist/tasks/types.js.map +1 -0
- package/dist/threads/FileThreadStore.d.ts +118 -0
- package/dist/threads/FileThreadStore.d.ts.map +1 -0
- package/dist/threads/FileThreadStore.js +320 -0
- package/dist/threads/FileThreadStore.js.map +1 -0
- package/dist/threads/index.d.ts +7 -0
- package/dist/threads/index.d.ts.map +1 -0
- package/dist/threads/index.js +7 -0
- package/dist/threads/index.js.map +1 -0
- package/dist/threads/types.d.ts +230 -0
- package/dist/threads/types.d.ts.map +1 -0
- package/dist/threads/types.js +6 -0
- package/dist/threads/types.js.map +1 -0
- package/dist/tools/AgentTool.d.ts +38 -0
- package/dist/tools/AgentTool.d.ts.map +1 -0
- package/dist/tools/AgentTool.js +6 -0
- package/dist/tools/AgentTool.js.map +1 -0
- package/dist/tools/BashTool.d.ts +61 -0
- package/dist/tools/BashTool.d.ts.map +1 -0
- package/dist/tools/BashTool.js +142 -0
- package/dist/tools/BashTool.js.map +1 -0
- package/dist/tools/EditFileTool.d.ts +49 -0
- package/dist/tools/EditFileTool.d.ts.map +1 -0
- package/dist/tools/EditFileTool.js +114 -0
- package/dist/tools/EditFileTool.js.map +1 -0
- package/dist/tools/GlobTool.d.ts +48 -0
- package/dist/tools/GlobTool.d.ts.map +1 -0
- package/dist/tools/GlobTool.js +117 -0
- package/dist/tools/GlobTool.js.map +1 -0
- package/dist/tools/GrepTool.d.ts +73 -0
- package/dist/tools/GrepTool.d.ts.map +1 -0
- package/dist/tools/GrepTool.js +250 -0
- package/dist/tools/GrepTool.js.map +1 -0
- package/dist/tools/ReadFileTool.d.ts +51 -0
- package/dist/tools/ReadFileTool.d.ts.map +1 -0
- package/dist/tools/ReadFileTool.js +153 -0
- package/dist/tools/ReadFileTool.js.map +1 -0
- package/dist/tools/TaskManagerTool.d.ts +102 -0
- package/dist/tools/TaskManagerTool.d.ts.map +1 -0
- package/dist/tools/TaskManagerTool.js +130 -0
- package/dist/tools/TaskManagerTool.js.map +1 -0
- package/dist/tools/ToolExecutionContext.d.ts +61 -0
- package/dist/tools/ToolExecutionContext.d.ts.map +1 -0
- package/dist/tools/ToolExecutionContext.js +8 -0
- package/dist/tools/ToolExecutionContext.js.map +1 -0
- package/dist/tools/ToolRegistry.d.ts +82 -0
- package/dist/tools/ToolRegistry.d.ts.map +1 -0
- package/dist/tools/ToolRegistry.js +116 -0
- package/dist/tools/ToolRegistry.js.map +1 -0
- package/dist/tools/WriteFileTool.d.ts +46 -0
- package/dist/tools/WriteFileTool.d.ts.map +1 -0
- package/dist/tools/WriteFileTool.js +87 -0
- package/dist/tools/WriteFileTool.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal/bashEnvironment.d.ts +20 -0
- package/dist/tools/internal/bashEnvironment.d.ts.map +1 -0
- package/dist/tools/internal/bashEnvironment.js +65 -0
- package/dist/tools/internal/bashEnvironment.js.map +1 -0
- package/dist/tools/internal/pathGuard.d.ts +27 -0
- package/dist/tools/internal/pathGuard.d.ts.map +1 -0
- package/dist/tools/internal/pathGuard.js +99 -0
- package/dist/tools/internal/pathGuard.js.map +1 -0
- package/dist/tools/prompts.d.ts +33 -0
- package/dist/tools/prompts.d.ts.map +1 -0
- package/dist/tools/prompts.js +48 -0
- package/dist/tools/prompts.js.map +1 -0
- package/package.json +64 -4
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Autonomous multi-step turn runner for the agent engine microkernel.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import { streamText } from "../runtime.js";
|
|
6
|
+
import { AsyncEventQueue } from "./eventQueue.js";
|
|
7
|
+
/**
|
|
8
|
+
* Extracts normalized provider identifier from a model string if formatted as "provider/model_id".
|
|
9
|
+
*/
|
|
10
|
+
function getModelProvider(model) {
|
|
11
|
+
if (typeof model === "string") {
|
|
12
|
+
const slashIndex = model.indexOf("/");
|
|
13
|
+
if (slashIndex > 0) {
|
|
14
|
+
return model.slice(0, slashIndex).trim().toLowerCase();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts any unknown error into a normalized serializable ErrorInfo object.
|
|
21
|
+
*/
|
|
22
|
+
function toErrorInfo(error) {
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
return {
|
|
25
|
+
name: error.name,
|
|
26
|
+
message: error.message,
|
|
27
|
+
...(error.stack ? { stack: error.stack } : {}),
|
|
28
|
+
...(typeof error.code === "string"
|
|
29
|
+
? { code: error.code }
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
name: "Error",
|
|
35
|
+
message: String(error),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts any arbitrary value into pure serializable JSON-compatible data.
|
|
40
|
+
*/
|
|
41
|
+
function toJsonValue(value) {
|
|
42
|
+
if (value === null ||
|
|
43
|
+
typeof value === "boolean" ||
|
|
44
|
+
typeof value === "number" ||
|
|
45
|
+
typeof value === "string") {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(JSON.stringify(value));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return String(value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Combines multiple AbortSignal instances into a single signal.
|
|
57
|
+
*/
|
|
58
|
+
function combineAbortSignals(...signals) {
|
|
59
|
+
const activeSignals = signals.filter((s) => Boolean(s));
|
|
60
|
+
if (activeSignals.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
if (activeSignals.length === 1)
|
|
63
|
+
return activeSignals[0];
|
|
64
|
+
if (typeof AbortSignal.any === "function") {
|
|
65
|
+
return AbortSignal.any(activeSignals);
|
|
66
|
+
}
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
for (const signal of activeSignals) {
|
|
69
|
+
if (signal.aborted) {
|
|
70
|
+
controller.abort(signal.reason);
|
|
71
|
+
return controller.signal;
|
|
72
|
+
}
|
|
73
|
+
signal.addEventListener("abort", () => controller.abort(signal.reason), {
|
|
74
|
+
once: true,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return controller.signal;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Runs a single autonomous turn within the agent engine microkernel.
|
|
81
|
+
*
|
|
82
|
+
* @param config - The active engine configuration.
|
|
83
|
+
* @param options - Per-turn options including user prompt and overrides.
|
|
84
|
+
* @param conversationMessages - Mutable array of thread conversation messages.
|
|
85
|
+
* @returns An async generator yielding pure serializable `AgentEvent` objects.
|
|
86
|
+
*/
|
|
87
|
+
export async function* runTurn(config, options, conversationMessages) {
|
|
88
|
+
const turnIndex = options.turnIndex ?? 1;
|
|
89
|
+
const userPrompt = options.userPrompt;
|
|
90
|
+
const turnAbortController = new AbortController();
|
|
91
|
+
const effectiveSignal = combineAbortSignals(options.abortSignal, config.abortSignal, turnAbortController.signal);
|
|
92
|
+
const maxSteps = options.maxSteps ?? config.maxSteps ?? 25;
|
|
93
|
+
const reasoning = options.reasoning ?? config.reasoning;
|
|
94
|
+
// Persistence and Checkpoint invariants: if persist is false, checkpoint is strictly false
|
|
95
|
+
const isPersist = Boolean(config.persist ?? Boolean(config.threadStore));
|
|
96
|
+
const isCheckpointEnabled = isPersist && Boolean(config.checkpoint ?? Boolean(config.checkpointStore));
|
|
97
|
+
let totalPromptTokens = 0;
|
|
98
|
+
let totalCompletionTokens = 0;
|
|
99
|
+
let totalTokens = 0;
|
|
100
|
+
let totalReasoningTokens = 0;
|
|
101
|
+
const buildTotalUsage = () => {
|
|
102
|
+
const usage = {
|
|
103
|
+
promptTokens: totalPromptTokens,
|
|
104
|
+
completionTokens: totalCompletionTokens,
|
|
105
|
+
totalTokens,
|
|
106
|
+
};
|
|
107
|
+
if (totalReasoningTokens > 0) {
|
|
108
|
+
usage.reasoningTokens = totalReasoningTokens;
|
|
109
|
+
}
|
|
110
|
+
return usage;
|
|
111
|
+
};
|
|
112
|
+
let finishReason = "completed";
|
|
113
|
+
const initialHistoryLength = conversationMessages.length;
|
|
114
|
+
try {
|
|
115
|
+
// Partial credential override check
|
|
116
|
+
const hasPartialApiKey = options.apiKey !== undefined;
|
|
117
|
+
const hasPartialBaseUrl = options.baseUrl !== undefined;
|
|
118
|
+
if ((hasPartialApiKey && !hasPartialBaseUrl) ||
|
|
119
|
+
(!hasPartialApiKey && hasPartialBaseUrl)) {
|
|
120
|
+
throw new Error("Per-turn credential override is incomplete: both apiKey and baseUrl must be provided together.");
|
|
121
|
+
}
|
|
122
|
+
// Credential invariant check: ensure per-turn model cannot silently reuse another provider's credentials
|
|
123
|
+
if (options.model !== undefined) {
|
|
124
|
+
const isConfigString = typeof config.model === "string";
|
|
125
|
+
const isOverrideString = typeof options.model === "string";
|
|
126
|
+
if (!isConfigString || !isOverrideString) {
|
|
127
|
+
if (!options.apiKey || !options.baseUrl) {
|
|
128
|
+
throw new Error("Per-turn model override with LanguageModel instance requires explicit per-turn credentials (both apiKey and baseUrl).");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const configProvider = getModelProvider(config.model);
|
|
133
|
+
const overrideProvider = getModelProvider(options.model);
|
|
134
|
+
if (overrideProvider &&
|
|
135
|
+
configProvider &&
|
|
136
|
+
overrideProvider !== configProvider &&
|
|
137
|
+
(!options.apiKey || !options.baseUrl)) {
|
|
138
|
+
throw new Error(`Per-turn model override changed provider from "${configProvider}" to "${overrideProvider}", but explicit per-turn credentials (apiKey and baseUrl) were not supplied. Falling back across different providers is forbidden.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// 1. Emit 'turnStarted'
|
|
143
|
+
yield {
|
|
144
|
+
type: "turnStarted",
|
|
145
|
+
turnIndex,
|
|
146
|
+
userMessage: userPrompt,
|
|
147
|
+
};
|
|
148
|
+
if (config.threadStore) {
|
|
149
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
150
|
+
type: "turnStarted",
|
|
151
|
+
turnIndex,
|
|
152
|
+
userPrompt,
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
// 2. Call hooks.onBeforeTurn() -> await product decision
|
|
157
|
+
let effectiveUserPrompt = userPrompt;
|
|
158
|
+
let injectedInstructions = "";
|
|
159
|
+
if (config.hooks?.onBeforeTurn) {
|
|
160
|
+
const beforeTurnResult = await config.hooks.onBeforeTurn({
|
|
161
|
+
turnIndex,
|
|
162
|
+
userPrompt,
|
|
163
|
+
});
|
|
164
|
+
if (beforeTurnResult) {
|
|
165
|
+
if (beforeTurnResult.veto) {
|
|
166
|
+
finishReason = "vetoed";
|
|
167
|
+
yield {
|
|
168
|
+
type: "turnFinished",
|
|
169
|
+
turnIndex,
|
|
170
|
+
finishReason,
|
|
171
|
+
totalUsage: buildTotalUsage(),
|
|
172
|
+
};
|
|
173
|
+
if (config.threadStore) {
|
|
174
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
175
|
+
type: "turnFinished",
|
|
176
|
+
turnIndex,
|
|
177
|
+
finishReason,
|
|
178
|
+
timestamp: Date.now(),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (beforeTurnResult.userPrompt) {
|
|
184
|
+
effectiveUserPrompt = beforeTurnResult.userPrompt;
|
|
185
|
+
}
|
|
186
|
+
if (beforeTurnResult.injectedInstructions) {
|
|
187
|
+
injectedInstructions = beforeTurnResult.injectedInstructions;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Append user message to conversation history
|
|
192
|
+
const userMessage = {
|
|
193
|
+
role: "user",
|
|
194
|
+
content: effectiveUserPrompt,
|
|
195
|
+
};
|
|
196
|
+
conversationMessages.push(userMessage);
|
|
197
|
+
if (config.threadStore) {
|
|
198
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
199
|
+
type: "modelMessage",
|
|
200
|
+
message: userMessage,
|
|
201
|
+
timestamp: Date.now(),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// Combined instructions for this turn
|
|
205
|
+
const combinedInstructions = [config.instructions, injectedInstructions]
|
|
206
|
+
.filter((s) => Boolean(s && s.trim().length > 0))
|
|
207
|
+
.join("\n\n");
|
|
208
|
+
// 3. Step Loop (1 to maxSteps)
|
|
209
|
+
for (let stepIndex = 1; stepIndex <= maxSteps; stepIndex++) {
|
|
210
|
+
if (effectiveSignal?.aborted) {
|
|
211
|
+
finishReason = "interrupted";
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
yield {
|
|
215
|
+
type: "stepStarted",
|
|
216
|
+
stepIndex,
|
|
217
|
+
timestamp: Date.now(),
|
|
218
|
+
};
|
|
219
|
+
const sdkToolDefinitions = config.tools.toSdkToolDefinitions();
|
|
220
|
+
const hasTools = Object.keys(sdkToolDefinitions).length > 0;
|
|
221
|
+
const streamOptions = {
|
|
222
|
+
model: options.model ?? config.model,
|
|
223
|
+
apiKey: options.apiKey ?? config.apiKey,
|
|
224
|
+
baseUrl: options.baseUrl ?? config.baseUrl,
|
|
225
|
+
...(config.providerRegistry ? { providerRegistry: config.providerRegistry } : {}),
|
|
226
|
+
messages: conversationMessages,
|
|
227
|
+
...(combinedInstructions ? { instructions: combinedInstructions } : {}),
|
|
228
|
+
...(hasTools ? { tools: sdkToolDefinitions } : {}),
|
|
229
|
+
...(reasoning ? { reasoning } : {}),
|
|
230
|
+
...(effectiveSignal ? { abortSignal: effectiveSignal } : {}),
|
|
231
|
+
};
|
|
232
|
+
const proposedToolCalls = [];
|
|
233
|
+
const streamResult = streamText(streamOptions);
|
|
234
|
+
for await (const chunk of streamResult.stream) {
|
|
235
|
+
if (chunk.type === "text-delta") {
|
|
236
|
+
yield {
|
|
237
|
+
type: "tokenDelta",
|
|
238
|
+
text: chunk.text,
|
|
239
|
+
messageId: chunk.id,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
else if (chunk.type === "reasoning-delta") {
|
|
243
|
+
yield {
|
|
244
|
+
type: "thoughtDelta",
|
|
245
|
+
text: chunk.text,
|
|
246
|
+
messageId: chunk.id,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
else if (chunk.type === "tool-call") {
|
|
250
|
+
const toolCall = {
|
|
251
|
+
callId: chunk.toolCallId,
|
|
252
|
+
toolName: chunk.toolName,
|
|
253
|
+
parameters: chunk.input,
|
|
254
|
+
};
|
|
255
|
+
proposedToolCalls.push(toolCall);
|
|
256
|
+
yield {
|
|
257
|
+
type: "toolCallProposed",
|
|
258
|
+
callId: toolCall.callId,
|
|
259
|
+
toolName: toolCall.toolName,
|
|
260
|
+
parameters: toJsonValue(toolCall.parameters),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
else if (chunk.type === "error") {
|
|
264
|
+
const streamError = chunk.error instanceof Error
|
|
265
|
+
? chunk.error
|
|
266
|
+
: new Error(String(chunk.error));
|
|
267
|
+
yield {
|
|
268
|
+
type: "error",
|
|
269
|
+
origin: "model",
|
|
270
|
+
error: toErrorInfo(streamError),
|
|
271
|
+
isFatal: false,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const responseMessages = [
|
|
276
|
+
...(await streamResult.responseMessages),
|
|
277
|
+
];
|
|
278
|
+
const rawUsage = await streamResult.usage;
|
|
279
|
+
// Collect assistant response messages and step token metrics
|
|
280
|
+
conversationMessages.push(...responseMessages);
|
|
281
|
+
if (config.threadStore) {
|
|
282
|
+
for (const msg of responseMessages) {
|
|
283
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
284
|
+
type: "modelMessage",
|
|
285
|
+
message: msg,
|
|
286
|
+
timestamp: Date.now(),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const stepUsage = {
|
|
291
|
+
promptTokens: rawUsage.inputTokens ?? 0,
|
|
292
|
+
completionTokens: rawUsage.outputTokens ?? 0,
|
|
293
|
+
totalTokens: rawUsage.totalTokens ?? 0,
|
|
294
|
+
...(typeof rawUsage.outputTokenDetails?.reasoningTokens === "number"
|
|
295
|
+
? { reasoningTokens: rawUsage.outputTokenDetails.reasoningTokens }
|
|
296
|
+
: {}),
|
|
297
|
+
};
|
|
298
|
+
totalPromptTokens += stepUsage.promptTokens;
|
|
299
|
+
totalCompletionTokens += stepUsage.completionTokens;
|
|
300
|
+
totalTokens += stepUsage.totalTokens;
|
|
301
|
+
if (stepUsage.reasoningTokens) {
|
|
302
|
+
totalReasoningTokens += stepUsage.reasoningTokens;
|
|
303
|
+
}
|
|
304
|
+
// If the model called no tools, evaluate whether stopping is allowed
|
|
305
|
+
if (proposedToolCalls.length === 0) {
|
|
306
|
+
if (config.hooks?.onShouldStop) {
|
|
307
|
+
const stopDecision = await config.hooks.onShouldStop({
|
|
308
|
+
turnIndex,
|
|
309
|
+
finishReason: "completed",
|
|
310
|
+
transcript: conversationMessages,
|
|
311
|
+
});
|
|
312
|
+
if (!stopDecision.shouldStop) {
|
|
313
|
+
const reminderMessage = {
|
|
314
|
+
role: "user",
|
|
315
|
+
content: stopDecision.reminderPrompt,
|
|
316
|
+
};
|
|
317
|
+
conversationMessages.push(reminderMessage);
|
|
318
|
+
if (config.threadStore) {
|
|
319
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
320
|
+
type: "modelMessage",
|
|
321
|
+
message: reminderMessage,
|
|
322
|
+
timestamp: Date.now(),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
yield {
|
|
326
|
+
type: "stepFinished",
|
|
327
|
+
stepIndex,
|
|
328
|
+
usage: stepUsage,
|
|
329
|
+
};
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
yield {
|
|
334
|
+
type: "stepFinished",
|
|
335
|
+
stepIndex,
|
|
336
|
+
usage: stepUsage,
|
|
337
|
+
};
|
|
338
|
+
finishReason = "completed";
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
// Execute proposed tools
|
|
342
|
+
const toolResults = [];
|
|
343
|
+
for (const toolCall of proposedToolCalls) {
|
|
344
|
+
if (effectiveSignal?.aborted) {
|
|
345
|
+
finishReason = "interrupted";
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
const agentTool = config.tools.resolve(toolCall.toolName);
|
|
349
|
+
if (!agentTool) {
|
|
350
|
+
const missingErrorResult = {
|
|
351
|
+
isError: true,
|
|
352
|
+
error: `Tool "${toolCall.toolName}" is not registered in the tool registry.`,
|
|
353
|
+
};
|
|
354
|
+
yield {
|
|
355
|
+
type: "toolExecutionFinished",
|
|
356
|
+
callId: toolCall.callId,
|
|
357
|
+
toolName: toolCall.toolName,
|
|
358
|
+
result: toJsonValue(missingErrorResult),
|
|
359
|
+
isError: true,
|
|
360
|
+
durationMs: 0,
|
|
361
|
+
};
|
|
362
|
+
toolResults.push({
|
|
363
|
+
toolCallId: toolCall.callId,
|
|
364
|
+
toolName: toolCall.toolName,
|
|
365
|
+
result: missingErrorResult,
|
|
366
|
+
isError: true,
|
|
367
|
+
});
|
|
368
|
+
if (config.threadStore) {
|
|
369
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
370
|
+
type: "toolResult",
|
|
371
|
+
callId: toolCall.callId,
|
|
372
|
+
toolName: toolCall.toolName,
|
|
373
|
+
result: missingErrorResult,
|
|
374
|
+
isError: true,
|
|
375
|
+
timestamp: Date.now(),
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
// Validate tool input parameters before authorization
|
|
381
|
+
let parsedParameters;
|
|
382
|
+
try {
|
|
383
|
+
parsedParameters = agentTool.inputSchema.parse(toolCall.parameters);
|
|
384
|
+
}
|
|
385
|
+
catch (validationError) {
|
|
386
|
+
const schemaErrorResult = {
|
|
387
|
+
isError: true,
|
|
388
|
+
error: `Schema validation error for tool "${toolCall.toolName}": ${validationError instanceof Error ? validationError.message : String(validationError)}`,
|
|
389
|
+
};
|
|
390
|
+
yield {
|
|
391
|
+
type: "toolExecutionFinished",
|
|
392
|
+
callId: toolCall.callId,
|
|
393
|
+
toolName: toolCall.toolName,
|
|
394
|
+
result: toJsonValue(schemaErrorResult),
|
|
395
|
+
isError: true,
|
|
396
|
+
durationMs: 0,
|
|
397
|
+
};
|
|
398
|
+
toolResults.push({
|
|
399
|
+
toolCallId: toolCall.callId,
|
|
400
|
+
toolName: toolCall.toolName,
|
|
401
|
+
result: schemaErrorResult,
|
|
402
|
+
isError: true,
|
|
403
|
+
});
|
|
404
|
+
if (config.threadStore) {
|
|
405
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
406
|
+
type: "toolResult",
|
|
407
|
+
callId: toolCall.callId,
|
|
408
|
+
toolName: toolCall.toolName,
|
|
409
|
+
result: schemaErrorResult,
|
|
410
|
+
isError: true,
|
|
411
|
+
timestamp: Date.now(),
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
// Tool authorization check - FAIL CLOSED BY DEFAULT FOR ALL TOOLS
|
|
417
|
+
let isAllowed = false;
|
|
418
|
+
let denialReason = "Tool execution denied: no authorization policy configured. All tools fail closed by default.";
|
|
419
|
+
if (config.hooks?.onAuthorizeTool) {
|
|
420
|
+
try {
|
|
421
|
+
const decision = await config.hooks.onAuthorizeTool({
|
|
422
|
+
toolName: toolCall.toolName,
|
|
423
|
+
parameters: parsedParameters,
|
|
424
|
+
workingDirectory: config.workingDirectory,
|
|
425
|
+
});
|
|
426
|
+
if (decision.decision === "allow") {
|
|
427
|
+
isAllowed = true;
|
|
428
|
+
}
|
|
429
|
+
else if (decision.decision === "deny") {
|
|
430
|
+
isAllowed = false;
|
|
431
|
+
denialReason = decision.reason;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
catch (authError) {
|
|
435
|
+
isAllowed = false;
|
|
436
|
+
const authErrorInstance = authError instanceof Error ? authError : new Error(String(authError));
|
|
437
|
+
denialReason = `Authorization check failed: ${authErrorInstance.message}`;
|
|
438
|
+
yield {
|
|
439
|
+
type: "error",
|
|
440
|
+
origin: "hook",
|
|
441
|
+
error: toErrorInfo(authErrorInstance),
|
|
442
|
+
toolName: toolCall.toolName,
|
|
443
|
+
hookName: "onAuthorizeTool",
|
|
444
|
+
isFatal: false,
|
|
445
|
+
};
|
|
446
|
+
if (config.hooks?.onError) {
|
|
447
|
+
try {
|
|
448
|
+
await config.hooks.onError({
|
|
449
|
+
error: authErrorInstance,
|
|
450
|
+
origin: "hook",
|
|
451
|
+
toolName: toolCall.toolName,
|
|
452
|
+
hookName: "onAuthorizeTool",
|
|
453
|
+
turnIndex,
|
|
454
|
+
isFatal: false,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
// Do not recursively handle hook errors
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (!isAllowed) {
|
|
464
|
+
const denialResult = {
|
|
465
|
+
isError: true,
|
|
466
|
+
error: denialReason,
|
|
467
|
+
};
|
|
468
|
+
yield {
|
|
469
|
+
type: "toolExecutionFinished",
|
|
470
|
+
callId: toolCall.callId,
|
|
471
|
+
toolName: toolCall.toolName,
|
|
472
|
+
result: toJsonValue(denialResult),
|
|
473
|
+
isError: true,
|
|
474
|
+
durationMs: 0,
|
|
475
|
+
};
|
|
476
|
+
toolResults.push({
|
|
477
|
+
toolCallId: toolCall.callId,
|
|
478
|
+
toolName: toolCall.toolName,
|
|
479
|
+
result: denialResult,
|
|
480
|
+
isError: true,
|
|
481
|
+
});
|
|
482
|
+
if (config.threadStore) {
|
|
483
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
484
|
+
type: "toolResult",
|
|
485
|
+
callId: toolCall.callId,
|
|
486
|
+
toolName: toolCall.toolName,
|
|
487
|
+
result: denialResult,
|
|
488
|
+
isError: true,
|
|
489
|
+
timestamp: Date.now(),
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
// Execute authorized tool
|
|
495
|
+
const startTime = Date.now();
|
|
496
|
+
yield {
|
|
497
|
+
type: "toolExecutionStarted",
|
|
498
|
+
callId: toolCall.callId,
|
|
499
|
+
toolName: toolCall.toolName,
|
|
500
|
+
timestamp: startTime,
|
|
501
|
+
};
|
|
502
|
+
const progressQueue = new AsyncEventQueue();
|
|
503
|
+
const executionContext = {
|
|
504
|
+
threadId: config.threadId,
|
|
505
|
+
toolCallId: toolCall.callId,
|
|
506
|
+
workingDirectory: config.workingDirectory,
|
|
507
|
+
turnIndex,
|
|
508
|
+
abortSignal: effectiveSignal,
|
|
509
|
+
checkpointStore: config.checkpointStore,
|
|
510
|
+
isCheckpointEnabled,
|
|
511
|
+
taskManager: config.taskManager,
|
|
512
|
+
onCheckpointCreated: (evt) => {
|
|
513
|
+
const checkpointEvent = {
|
|
514
|
+
type: "checkpointCreated",
|
|
515
|
+
checkpointId: evt.checkpointId,
|
|
516
|
+
sequence: evt.sequence,
|
|
517
|
+
label: evt.label,
|
|
518
|
+
filesTouched: evt.filesTouched,
|
|
519
|
+
};
|
|
520
|
+
progressQueue.push(checkpointEvent);
|
|
521
|
+
},
|
|
522
|
+
emitProgress: (chunk) => {
|
|
523
|
+
progressQueue.push({
|
|
524
|
+
type: "toolExecutionDelta",
|
|
525
|
+
callId: toolCall.callId,
|
|
526
|
+
toolName: toolCall.toolName,
|
|
527
|
+
chunk,
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
let executionResult;
|
|
532
|
+
let isToolError = false;
|
|
533
|
+
const executionPromise = (async () => {
|
|
534
|
+
try {
|
|
535
|
+
return await agentTool.execute(parsedParameters, executionContext);
|
|
536
|
+
}
|
|
537
|
+
catch (execError) {
|
|
538
|
+
isToolError = true;
|
|
539
|
+
return {
|
|
540
|
+
isError: true,
|
|
541
|
+
error: execError instanceof Error
|
|
542
|
+
? execError.message
|
|
543
|
+
: String(execError),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
finally {
|
|
547
|
+
progressQueue.close();
|
|
548
|
+
}
|
|
549
|
+
})();
|
|
550
|
+
// Yield queued delta and checkpoint events as they arrive
|
|
551
|
+
for await (const progressEvent of progressQueue) {
|
|
552
|
+
yield progressEvent;
|
|
553
|
+
}
|
|
554
|
+
executionResult = await executionPromise;
|
|
555
|
+
if (executionResult !== null &&
|
|
556
|
+
typeof executionResult === "object" &&
|
|
557
|
+
"isError" in executionResult &&
|
|
558
|
+
executionResult.isError === true) {
|
|
559
|
+
isToolError = true;
|
|
560
|
+
}
|
|
561
|
+
const durationMs = Date.now() - startTime;
|
|
562
|
+
yield {
|
|
563
|
+
type: "toolExecutionFinished",
|
|
564
|
+
callId: toolCall.callId,
|
|
565
|
+
toolName: toolCall.toolName,
|
|
566
|
+
result: toJsonValue(executionResult),
|
|
567
|
+
isError: isToolError,
|
|
568
|
+
durationMs,
|
|
569
|
+
};
|
|
570
|
+
toolResults.push({
|
|
571
|
+
toolCallId: toolCall.callId,
|
|
572
|
+
toolName: toolCall.toolName,
|
|
573
|
+
result: executionResult,
|
|
574
|
+
isError: isToolError,
|
|
575
|
+
});
|
|
576
|
+
if (config.threadStore) {
|
|
577
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
578
|
+
type: "toolResult",
|
|
579
|
+
callId: toolCall.callId,
|
|
580
|
+
toolName: toolCall.toolName,
|
|
581
|
+
result: executionResult,
|
|
582
|
+
isError: isToolError,
|
|
583
|
+
timestamp: Date.now(),
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
// Append tool results message
|
|
588
|
+
conversationMessages.push({
|
|
589
|
+
role: "tool",
|
|
590
|
+
content: toolResults.map((tr) => ({
|
|
591
|
+
type: "tool-result",
|
|
592
|
+
toolCallId: tr.toolCallId,
|
|
593
|
+
toolName: tr.toolName,
|
|
594
|
+
output: typeof tr.result === "string"
|
|
595
|
+
? {
|
|
596
|
+
type: "text",
|
|
597
|
+
value: tr.result,
|
|
598
|
+
}
|
|
599
|
+
: {
|
|
600
|
+
type: "json",
|
|
601
|
+
value: toJsonValue(tr.result),
|
|
602
|
+
},
|
|
603
|
+
})),
|
|
604
|
+
});
|
|
605
|
+
// Emit stepFinished
|
|
606
|
+
yield {
|
|
607
|
+
type: "stepFinished",
|
|
608
|
+
stepIndex,
|
|
609
|
+
usage: stepUsage,
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
if (finishReason === "completed" && conversationMessages.length > initialHistoryLength) {
|
|
613
|
+
// Check if maxSteps was hit
|
|
614
|
+
const lastMessage = conversationMessages[conversationMessages.length - 1];
|
|
615
|
+
if (lastMessage?.role === "tool") {
|
|
616
|
+
finishReason = "maxSteps";
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
// 4. Conclude turn
|
|
620
|
+
yield {
|
|
621
|
+
type: "turnFinished",
|
|
622
|
+
turnIndex,
|
|
623
|
+
finishReason,
|
|
624
|
+
totalUsage: buildTotalUsage(),
|
|
625
|
+
};
|
|
626
|
+
if (config.threadStore) {
|
|
627
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
628
|
+
type: "turnFinished",
|
|
629
|
+
turnIndex,
|
|
630
|
+
finishReason,
|
|
631
|
+
timestamp: Date.now(),
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch (turnError) {
|
|
636
|
+
const errorInstance = turnError instanceof Error ? turnError : new Error(String(turnError));
|
|
637
|
+
// Rollback conversational messages added during failed turn
|
|
638
|
+
conversationMessages.length = initialHistoryLength;
|
|
639
|
+
finishReason = "error";
|
|
640
|
+
yield {
|
|
641
|
+
type: "error",
|
|
642
|
+
origin: "engine",
|
|
643
|
+
error: toErrorInfo(errorInstance),
|
|
644
|
+
isFatal: true,
|
|
645
|
+
};
|
|
646
|
+
if (config.hooks?.onError) {
|
|
647
|
+
await config.hooks.onError({
|
|
648
|
+
error: errorInstance,
|
|
649
|
+
origin: "engine",
|
|
650
|
+
turnIndex,
|
|
651
|
+
isFatal: true,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
yield {
|
|
655
|
+
type: "turnFinished",
|
|
656
|
+
turnIndex,
|
|
657
|
+
finishReason,
|
|
658
|
+
totalUsage: buildTotalUsage(),
|
|
659
|
+
};
|
|
660
|
+
if (config.threadStore) {
|
|
661
|
+
await config.threadStore.appendTranscript(config.threadId, {
|
|
662
|
+
type: "turnFinished",
|
|
663
|
+
turnIndex,
|
|
664
|
+
finishReason,
|
|
665
|
+
timestamp: Date.now(),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
if (config.hooks?.onAfterTurn) {
|
|
671
|
+
try {
|
|
672
|
+
await config.hooks.onAfterTurn({
|
|
673
|
+
turnIndex,
|
|
674
|
+
finishReason,
|
|
675
|
+
totalUsage: buildTotalUsage(),
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
catch {
|
|
679
|
+
// Collect cleanup error without masking primary turn outcome
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
//# sourceMappingURL=runTurn.js.map
|