Update files
This commit is contained in:
@@ -1171,10 +1171,33 @@ export class AgentManager {
|
||||
break;
|
||||
case "turn_failed":
|
||||
agent.lastError = event.error;
|
||||
for (const [requestId] of agent.pendingPermissions) {
|
||||
agent.pendingPermissions.delete(requestId);
|
||||
if (!options?.fromHistory) {
|
||||
this.dispatchStream(agent.id, {
|
||||
type: "permission_resolved",
|
||||
provider: event.provider,
|
||||
requestId,
|
||||
resolution: { behavior: "deny", message: "Turn failed" },
|
||||
});
|
||||
}
|
||||
}
|
||||
this.emitState(agent);
|
||||
break;
|
||||
case "turn_canceled":
|
||||
// Cancellation is not an error, just clear any previous error
|
||||
agent.lastError = undefined;
|
||||
for (const [requestId] of agent.pendingPermissions) {
|
||||
agent.pendingPermissions.delete(requestId);
|
||||
if (!options?.fromHistory) {
|
||||
this.dispatchStream(agent.id, {
|
||||
type: "permission_resolved",
|
||||
provider: event.provider,
|
||||
requestId,
|
||||
resolution: { behavior: "deny", message: "Interrupted" },
|
||||
});
|
||||
}
|
||||
}
|
||||
this.emitState(agent);
|
||||
break;
|
||||
case "permission_requested":
|
||||
agent.pendingPermissions.set(event.request.id, event.request);
|
||||
|
||||
@@ -625,6 +625,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.pendingInterruptPromise = this.interruptActiveTurn().catch((error) => {
|
||||
this.logger.warn({ err: error }, "Failed to interrupt during cancel");
|
||||
});
|
||||
this.flushPendingToolCalls();
|
||||
// Push turn_canceled before ending the queue so consumers get proper lifecycle signals
|
||||
queue.push({
|
||||
type: "turn_canceled",
|
||||
@@ -1084,6 +1085,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
// Only emit if not already emitted by requestCancel() (indicated by turnCancelRequested).
|
||||
const wasSuperseded = this.currentTurnId !== turnId;
|
||||
if (wasSuperseded && !completedNormally && !this.turnCancelRequested) {
|
||||
this.flushPendingToolCalls();
|
||||
queue.push({
|
||||
type: "turn_canceled",
|
||||
provider: "claude",
|
||||
@@ -1423,6 +1425,21 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.pushEvent({ type: "timeline", item, provider: "claude" });
|
||||
}
|
||||
|
||||
private flushPendingToolCalls() {
|
||||
for (const [id, entry] of this.toolUseCache) {
|
||||
if (entry.started) {
|
||||
this.pushToolCall({
|
||||
name: entry.name,
|
||||
status: "failed",
|
||||
callId: id,
|
||||
input: entry.input,
|
||||
error: { message: "Interrupted" },
|
||||
});
|
||||
}
|
||||
}
|
||||
this.toolUseCache.clear();
|
||||
}
|
||||
|
||||
private pushToolCall(
|
||||
data: Omit<ToolCallTimelineItem, "type">,
|
||||
target?: AgentTimelineItem[]
|
||||
|
||||
Reference in New Issue
Block a user