fix(core): close turn cancellation contract gaps

This commit is contained in:
Tianyi Cui
2026-07-21 12:14:53 +08:00
parent 81cdebc531
commit c6e1d35a99
23 changed files with 185 additions and 168 deletions
+3 -3
View File
@@ -7,7 +7,7 @@
*/
import type { Context } from 'cordis'
import { agentEvents, normalizeAgentCancelCause } from '@deepseek-ai/dsh-agent'
import { agentEvents } from '@deepseek-ai/dsh-agent'
import type { AgentCancelCause, AgentOptions, AgentStatus, HookContext, InjectOptions, SendOptions } from '@deepseek-ai/dsh-agent'
import type { Agent } from '@deepseek-ai/dsh-agent'
import { deepFreeze, errorChain } from '@deepseek-ai/dsh-llm'
@@ -325,7 +325,7 @@ export class ReactLoopAgent implements Agent {
}
cancel(cause?: AgentCancelCause): void {
const normalized = normalizeAgentCancelCause(cause ?? { kind: 'user' })
const reason = cause ?? { kind: 'user' }
const cancellation = this.turnCancellation
const preRun = cancellation === undefined && (this.#inbox.hasQueued || this.#inbox.hasSteering)
if (preRun) {
@@ -334,7 +334,7 @@ export class ReactLoopAgent implements Agent {
// Clear work already present before abort observers run. A replacement
// synchronously enqueued by an observer belongs to the next turn.
this.#inbox.clear()
cancellation?.request(normalized)
cancellation?.request(reason)
}
/**