mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
All agent/* and agent-loop/config-start-failed events take one payload object carrying the agent subject; waterfall/serial payloads require a signal and keep next as the final argument. PreStepContext and RequestFailureContext are unfolded into payloads and retired. goal/changed follows the same shape so agentEvents keeps its listener error containment. ReactLoopAgent builds its scope carrier once in the constructor. Regenerates scope resolvers, tool-cordis api catalog, and docs catalogs; updates all affected listeners, tests, and the core-data-structures docs (en + zh).
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
/** Package-owned agent lifecycle invariants. @module @deepseek-ai/dsh-agent/invariant */
|
|
|
|
import type { Context } from 'cordis'
|
|
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
|
import type { Agent, AgentStatus } from '@deepseek-ai/dsh-agent'
|
|
|
|
const PACKAGE_NAME = '@deepseek-ai/dsh-agent'
|
|
|
|
/** Cordis companion plugin name. */
|
|
export const name = 'agent-invariant'
|
|
/** Services required before the companion can register. */
|
|
export const inject = ['invariants']
|
|
|
|
/** Install the agent contribution into its child registration fiber. */
|
|
const install: InvariantInstaller = (ctx, fail) => {
|
|
const lastStatus = new WeakMap<Agent, AgentStatus>()
|
|
ctx.on('agent/status', ({ agent, status }) => {
|
|
const previous = lastStatus.get(agent)
|
|
if (previous === status) {
|
|
fail(`agent/status repeated ${status} (no-op transition)`)
|
|
}
|
|
lastStatus.set(agent, status)
|
|
}, { global: true })
|
|
}
|
|
|
|
/**
|
|
* Register the agent invariant companion.
|
|
* @param ctx - Cordis context carrying the invariant service.
|
|
* @returns the installed registration's disposer after setup succeeds.
|
|
*/
|
|
export const apply = (ctx: Context): Promise<() => void> =>
|
|
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|