feat(agent): rename InboxItemInfo to AgentMessage with an id; send returns it

Add a branded AgentMessageId assigned to each accepted send message and
returned from send/followup/steer/inject (was void). Rename the inbox
event payload InboxItemInfo to AgentMessage, carrying that id so a caller
can correlate a queued item with its enqueue/dequeue/discard events.
This commit is contained in:
Turtle
2026-07-23 20:45:29 +08:00
parent b63abe80d6
commit 3fd72f7c74
32 changed files with 242 additions and 170 deletions
@@ -1,7 +1,7 @@
import { describe, expect, it, vi } from 'vitest'
import { Context } from 'cordis'
import Loader from '@cordisjs/plugin-loader'
import AgentRegistry from '@deepseek-ai/dsh-agent'
import AgentRegistry, { AgentMessageId } from '@deepseek-ai/dsh-agent'
import type { Agent, AgentStatus, AliasSendOptions } from '@deepseek-ai/dsh-agent'
import CommandService from '@deepseek-ai/dsh-commands'
import GoalService from '@deepseek-ai/dsh-goal'
@@ -48,10 +48,10 @@ function stubAgent(id: string): { agent: Agent; session: Session } {
session,
ctx: new Context(),
get status() { return status },
send() {},
followup() {},
steer() {},
inject(content, options) { appendInjection(session, content, options) },
send: () => AgentMessageId('stub'),
followup: () => AgentMessageId('stub'),
steer: () => AgentMessageId('stub'),
inject(content, options) { appendInjection(session, content, options); return AgentMessageId('stub') },
cancel() { status = 'idle' },
whenIdle() { return Promise.resolve() },
}
@@ -488,7 +488,7 @@ describe('same-session goal driving', () => {
if (options?.source?.kind === 'goal' && (options.target ?? 'next-turn') === 'next-turn') {
throw new Error('queue rejected')
}
realSend(content, options)
return realSend(content, options)
})
test.ctx.goals.create(test.agent, { objective: 'handle queue failure' })
@@ -510,7 +510,7 @@ describe('same-session goal driving', () => {
test.ctx.goals.disarm(test.agent)
throw new Error('queue rejected after disarm')
}
realSend(content, options)
return realSend(content, options)
})
test.ctx.goals.create(test.agent, { objective: 'preserve the newer activation state' })
+6 -5
View File
@@ -1,6 +1,6 @@
import { describe, expect, it, vi } from 'vitest'
import { Context } from 'cordis'
import AgentRegistry, { agentEvents } from '@deepseek-ai/dsh-agent'
import AgentRegistry, { agentEvents, AgentMessageId } from '@deepseek-ai/dsh-agent'
import type { Agent, AgentStatus, AliasSendOptions } from '@deepseek-ai/dsh-agent'
import { HarnessError, type ContentBlock, type MessageSource } from '@deepseek-ai/dsh-llm'
import SessionStore, { Session, SessionId } from '@deepseek-ai/dsh-session'
@@ -64,12 +64,13 @@ function stubAgentForSession(session: Session): StubAgent {
session,
ctx: new Context(),
get status() { return status },
send() {},
followup() {},
steer() {},
send: () => AgentMessageId('stub'),
followup: () => AgentMessageId('stub'),
steer: () => AgentMessageId('stub'),
inject(content, options) {
if (shouldDefer) deferred.push({ content, options })
else appendInjection(session, content, options)
return AgentMessageId('stub')
},
cancel() {},
whenIdle() { return Promise.resolve() },
@@ -476,7 +477,7 @@ describe('GoalService mutations', () => {
let reject = true
stub.agent.inject = (content, options) => {
if (reject) throw new Error('injection rejected')
append(content, options)
return append(content, options)
}
ctx.agents.register(stub.agent)
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { Context } from 'cordis'
import Loader from '@cordisjs/plugin-loader'
import AgentRegistry, { agentEvents } from '@deepseek-ai/dsh-agent'
import AgentRegistry, { agentEvents, AgentMessageId } from '@deepseek-ai/dsh-agent'
import type { Agent, AgentStatus, AliasSendOptions } from '@deepseek-ai/dsh-agent'
import GoalService, { GoalId } from '@deepseek-ai/dsh-goal'
import type { GoalRef } from '@deepseek-ai/dsh-goal'
@@ -31,9 +31,9 @@ function stubAgent(rawId: string, supplied?: Session): StubAgent {
session,
get status() { return status },
ctx: new Context(),
send() {},
followup() {},
steer() {},
send: () => AgentMessageId('stub'),
followup: () => AgentMessageId('stub'),
steer: () => AgentMessageId('stub'),
inject(content: ContentBlock[], options?: AliasSendOptions) {
const source = options?.source ?? { kind: 'plugin', plugin: '' }
session.append('user/message', {
@@ -41,6 +41,7 @@ function stubAgent(rawId: string, supplied?: Session): StubAgent {
source,
...options?.meta === undefined ? {} : { meta: options.meta },
}, { surfaceOp: 'append' })
return AgentMessageId('stub')
},
cancel() {},
whenIdle() { return Promise.resolve() },