Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(pet): 升级预设 ref 至 e1ff8c1,host reducer 输出工作状态细分档位

hairyf8a517b830b1f
diff --git a/packages/dsh-tauri-pet/src/host/reducer.test.ts b/packages/dsh-tauri-pet/src/host/reducer.test.ts
index 2029a347..6db0a956 100644
--- a/packages/dsh-tauri-pet/src/host/reducer.test.ts
+++ b/packages/dsh-tauri-pet/src/host/reducer.test.ts
@@ -39,26 +39,26 @@ describe('petSessionReducer (host)', () => {
expect(pushes[0].payload.status).toBeUndefined()
})
- it('turn/start 让 running=true、status=running', () => {
+ it('turn/start 让 running=true、status=running、workStatus=thinking', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
const last = pushes.at(-1)!
expect(last.action).toBe('update')
- expect(last.payload).toMatchObject({ id: 'a', running: true, status: 'running' })
+ expect(last.payload).toMatchObject({ id: 'a', running: true, status: 'running', workStatus: 'thinking' })
})
- it('assistant/chunk(reasoning-delta) 累积出 liveActivity=reasoning', () => {
+ it('assistant/chunk(reasoning-delta) 累积出 liveActivity=reasoning、workStatus=thinking', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
reducer.apply(peer(), ev('assistant/chunk', { turn: 1, step: 1, chunk: { type: 'reasoning-delta', text: '思考' } }, 2))
const last = pushes.at(-1)!
- expect(last.payload).toMatchObject({ running: true, status: 'running' })
+ expect(last.payload).toMatchObject({ running: true, status: 'running', workStatus: 'thinking' })
expect(last.payload.liveActivity).toMatchObject({ kind: 'reasoning', text: '思考' })
})
- it('tool/call 时 liveActivity 切换为工具名(携带 args),tool/result 后清空', () => {
+ it('tool/call 时 liveActivity 切换为工具名(携带 args)、workStatus=working,tool/result 后回 result', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
@@ -66,50 +66,66 @@ describe('petSessionReducer (host)', () => {
reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c1', name: 'pwsh', arguments: '{"command":"ls"}' }, 3))
const toolPush = pushes.at(-1)!
expect(toolPush.payload.liveActivity).toMatchObject({ kind: 'tool', name: 'pwsh', args: '{"command":"ls"}' })
- // tool/result 结束 c1,openTools 清空;reasoning 仍在 → 回到 reasoning。
+ expect(toolPush.payload).toMatchObject({ workStatus: 'working', toolActivity: 'commanding' })
+ // tool/result 结束 c1,openTools 清空;reasoning 仍在 → 回到 thinking 文案,档位切 result。
reducer.apply(peer(), ev('tool/result', { turn: 1, step: 1, message: { content: [{ type: 'text', text: 'ok' }] } }, 4))
const afterResult = pushes.at(-1)!
+ expect(afterResult.payload).toMatchObject({ workStatus: 'result' })
expect(afterResult.payload.liveActivity).toMatchObject({ kind: 'reasoning', text: '思考' })
})
- it('approval/asked 让展示为 waiting(phase=approval),approval/decided 后清除', () => {
+ it('tool/call 后仍有其他工具在跑 → workStatus 保持 working', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c1', name: 'grep', arguments: '{"pattern":"x"}' }, 2))
+ reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c2', name: 'read', arguments: '{"file_path":"a.ts"}' }, 3))
+ // 结束 c1 后 c2 仍在 openTools → 档位依旧 working(不落回 thinking/result)。
+ reducer.apply(peer(), ev('tool/result', { turn: 1, step: 1, message: { source: { callId: 'c1' } } }, 4))
+ const last = pushes.at(-1)!
+ expect(last.payload).toMatchObject({ workStatus: 'working', toolActivity: 'searching' })
+ })
+
+ it('approval/asked 让展示为 waiting(phase=approval, workStatus=waiting),approval/decided 后回 thinking', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
reducer.apply(peer(), ev('approval/asked', { id: 'ap1', toolName: 'plan_final_approval' }, 2))
const asked = pushes.at(-1)!
- expect(asked.payload).toMatchObject({ running: true, status: 'waiting', phase: 'approval' })
- // 相同 id 的 decided 清除等待态;running 仍在 → 回到 running。
+ expect(asked.payload).toMatchObject({ running: true, status: 'waiting', phase: 'approval', workStatus: 'waiting' })
+ // 相同 id 的 decided 清除等待态;running 仍在 → 回到 running(细分为 thinking,无工具在跑)。
reducer.apply(peer(), ev('approval/decided', { id: 'ap1' }, 3))
const decided = pushes.at(-1)!
expect(decided.payload.status).toBe('running')
expect(decided.payload.phase).toBeUndefined()
+ expect(decided.payload).toMatchObject({ workStatus: 'thinking' })
})
- it('user-question 工具调用让展示为 waiting(phase=user-question),user/message 应答后清除', () => {
+ it('user-question 工具调用让展示为 waiting(phase=user-question, workStatus=waiting),user/message 应答后清除', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'uq1', name: 'ask_user_question', arguments: '{}' }, 2))
const waiting = pushes.at(-1)!
- expect(waiting.payload).toMatchObject({ running: true, status: 'waiting', phase: 'user-question' })
- // 用户应答后(user/message)清除等待态。
+ expect(waiting.payload).toMatchObject({ running: true, status: 'waiting', phase: 'user-question', workStatus: 'waiting' })
+ // 用户应答后(user/message)清除等待态,问句工具仍在 openTools → 回 working。
reducer.apply(peer(), ev('user/message', { turn: 1, message: { role: 'user', content: [{ type: 'text', text: '继续' }] } }, 3))
const afterAnswer = pushes.at(-1)!
expect(afterAnswer.payload.status).toBe('running')
expect(afterAnswer.payload.phase).toBeUndefined()
+ expect(afterAnswer.payload).toMatchObject({ workStatus: 'working' })
})
- it('turn/end(blocked) 让展示为 waiting(phase=blocked)(等待用户处理非思考中)', () => {
+ it('turn/end(blocked) 让展示为 waiting(phase=blocked, workStatus=waiting)(等待用户处理非思考中)', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
reducer.apply(peer(), ev('turn/end', { turn: 1, reason: { kind: 'blocked' } }, 2))
const last = pushes.at(-1)!
- expect(last.payload).toMatchObject({ running: false, status: 'waiting', phase: 'blocked' })
+ expect(last.payload).toMatchObject({ running: false, status: 'waiting', phase: 'blocked', workStatus: 'waiting' })
})
- it('turn/end(completed) 把 running 翻回 false、status 清空', () => {
+ it('turn/end(completed) 把 running 翻回 false、粗 status 清空、workStatus=success(终态庆祝档)', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
@@ -118,10 +134,11 @@ describe('petSessionReducer (host)', () => {
const last = pushes.at(-1)!
expect(last.payload).toMatchObject({ id: 'a', running: false })
expect(last.payload.status).toBeUndefined()
+ expect(last.payload).toMatchObject({ workStatus: 'success' })
expect(last.payload.liveActivity).toBeUndefined()
})
- it('turn/end(error) 记录 lastAgentError → status=error', () => {
+ it('turn/end(error) 记录 lastAgentError → 粗 status=error、workStatus=error(终态失败档)', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
@@ -130,7 +147,60 @@ describe('petSessionReducer (host)', () => {
reason: { kind: 'error', error: { message: 'boom' } },
}, 2))
const last = pushes.at(-1)!
- expect(last.payload).toMatchObject({ running: false, status: 'error', lastAgentError: 'boom' })
+ expect(last.payload).toMatchObject({ running: false, status: 'error', lastAgentError: 'boom', workStatus: 'error' })
+ })
+
+ it('turn/end(max-tokens) 归为 workStatus=error(输出上限)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('turn/end', { turn: 1, reason: { kind: 'max-tokens' } }, 2))
+ const last = pushes.at(-1)!
+ expect(last.payload).toMatchObject({ workStatus: 'error', lastAgentError: 'max-tokens' })
+ })
+
+ it('turn/end(aborted) 清档:workStatus 为空(不残留上一档,防止一直 working 挂死)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c1', name: 'pwsh', arguments: '{}' }, 2))
+ reducer.apply(peer(), ev('turn/end', { turn: 1, reason: { kind: 'aborted' } }, 3))
+ const last = pushes.at(-1)!
+ expect(last.payload).toMatchObject({ running: false })
+ expect(last.payload.workStatus).toBeUndefined()
+ })
+
+ it('tool/result 的工具级错误不写入 lastAgentError(回合仍在跑时不得判 failed 收起气泡)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('tool/call', { turn: 1, step: 1, callId: 'c1', name: 'pwsh', arguments: '{}' }, 2))
+ // 工具执行失败(data.error),但回合未结束:不得污染 lastAgentError / 粗 status。
+ reducer.apply(peer(), ev('tool/result', {
+ turn: 1,
+ step: 1,
+ error: { name: 'EPERM', message: 'operation not permitted' },
+ }, 3))
+ const last = pushes.at(-1)!
+ expect(last.payload.lastAgentError).toBeUndefined()
+ expect(last.payload.status).toBe('running')
+ expect(last.payload).toMatchObject({ workStatus: 'result' })
+ })
+
+ it('新回合 turn/start 清除上一回合的 lastAgentError 残留(错误不跨回合)', () => {
+ const { reducer, pushes } = collect()
+ reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
+ reducer.apply(peer(), ev('turn/end', {
+ turn: 1,
+ reason: { kind: 'error', error: { message: 'boom' } },
+ }, 2))
+ expect(pushes.at(-1)!.payload).toMatchObject({ workStatus: 'error', lastAgentError: 'boom' })
+ // 用户继续对话 → 新回合:错误清除,档位回 thinking。
+ reducer.apply(peer(), ev('turn/start', { turn: 2 }, 3))
+ const next = pushes.at(-1)!
+ expect(next.payload.lastAgentError).toBeUndefined()
+ expect(next.payload).toMatchObject({ workStatus: 'thinking' })
})
it('展示态未变化时不重复转发(去重,防 #396 高频转发)', () => {
@@ -192,11 +262,20 @@ describe('petSessionReducer (host)', () => {
expect(last.payload.origin).toBe('subagent')
})
- it('filter 只对 foldable 事件转发:todo/write 等 log-only 事件不产生 update', () => {
+ it('todo/write 更新当前任务:task 首次写入才转发(供气泡 taskCopy 文案),重复相同不转发', () => {
const { reducer, pushes } = collect()
reducer.create(peer())
+ reducer.apply(peer(), ev('turn/start', { turn: 1 }, 1))
const before = pushes.length
- reducer.apply(peer(), ev('todo/write', { todos: [{ id: 't1', content: 'x' }] }, 1))
+ // 无 in_progress/pending 项:task 不变,不转发。
+ reducer.apply(peer(), ev('todo/write', { todos: [{ id: 't0', status: 'completed', content: 'x' }] }, 2))
expect(pushes.length).toBe(before)
+ // 出现 in_progress 任务:task 变化 → 转发(气泡显示「正在处理 xxx」)。
+ reducer.apply(peer(), ev('todo/write', { todos: [{ id: 't1', status: 'in_progress', content: '整理文档' }] }, 3))
+ const withTask = pushes.at(-1)!
+ expect(withTask.payload).toMatchObject({ task: '整理文档' })
+ // 相同任务再次写入:无变化,不重复转发。
+ reducer.apply(peer(), ev('todo/write', { todos: [{ id: 't1', status: 'in_progress', content: '整理文档' }] }, 4))
+ expect(pushes.length).toBe(before + 1)
})
})
diff --git a/packages/dsh-tauri-pet/src/host/reducer.ts b/packages/dsh-tauri-pet/src/host/reducer.ts
index 229c80ae..94928390 100644
--- a/packages/dsh-tauri-pet/src/host/reducer.ts
+++ b/packages/dsh-tauri-pet/src/host/reducer.ts
@@ -42,9 +42,39 @@ export interface PetSessionPeer {
running?: boolean
}
+/**
+ * 工作状态细分档位(对齐 dsh-pet src/shared/work-status.ts 的 6 档枚举;
+ * 索引 = config.jsonc animations.events.workStatus 数组索引,勿在中间插入新档)。
+ * 取代旧「粗档 status(error/waiting/running)」成为会话气泡与动画的权威驱动:
+ * - thinking:turn/start 或回合内思考(无工具在跑)
+ * - working:tool/call 工具调用中
+ * - result:tool/result 后整理(无其余工具在跑)
+ * - waiting:approval/asked、问句工具、turn/end blocked(等用户)
+ * - success:turn/end completed(终态档,播一次庆祝后回落)
+ * - error:turn/end error/max-tokens/timeout(终态档)
+ * 语义对齐 dsh-pet src/host/work-status.ts 的 reduceWorkStatus,并叠加
+ * dsh-dafeiyu companion-reducer 的累计态语义(openTools 有剩 → 保持 working)。
+ */
+export type PetWorkStatus = 'thinking' | 'working' | 'result' | 'waiting' | 'success' | 'error'
+
+/** 档位 → events.workStatus 数组索引(与 config.jsonc 顺序严格一致)。 */
+export const PET_WORK_STATUS_INDEX: Record<PetWorkStatus, number> = {
+ thinking: 0,
+ working: 1,
+ result: 2,
+ waiting: 3,
+ success: 4,
+ error: 5,
+}
+
+/** 工具活动分类(对齐 dsh-dafeiyu companion-reducer 的 toolActivity):气泡按分类选文案。 */
+export type PetToolActivity = 'searching' | 'editing' | 'testing' | 'commanding' | 'using-tool'
+
/**
* 桌宠展示态的字段子集(与客户端 projection.ts 的 PET_FORWARDED_FIELDS
* + PET_FORWARDED_ACTIVITY_FIELD='liveActivity' 对齐;origin 已加入)。
+ * workStatus/task/toolActivity 为细分档位新增字段:气泡文案(use-bubble.ts)
+ * 与动画切档(pet-config 的 PRESET_SESSION_ANIMATIONS)都以此为驱动。
*/
export interface PetSessionPayload {
id: string
@@ -61,6 +91,12 @@ export interface PetSessionPayload {
pendingInteraction?: unknown
pending?: readonly unknown[]
lastAgentError?: string
+ /** 细分工作状态档位(thinking/working/result/waiting/success/error)。 */
+ workStatus?: PetWorkStatus
+ /** 当前任务文本(todo/write 的 in_progress/pending 项),供气泡 taskCopy 文案。 */
+ task?: string
+ /** 当前工具活动分类(working 期间),供气泡 activityCopy 文案。 */
+ toolActivity?: PetToolActivity
liveActivity?: {
kind: string
text?: string
@@ -98,6 +134,12 @@ export interface PetSessionState {
waitingApprovalId?: string
/** 当前「等用户回答」的问句工具调用 id(来自 user-question tool/call)。 */
waitingCallId?: string
+ /** 细分工作状态档位(thinking/working/result/waiting/success/error;随事件变化)。 */
+ workStatus?: PetWorkStatus
+ /** 当前任务文本(todo/write 的 in_progress/pending 项 content,无则为空)。 */
+ task?: string
+ /** 当前工具活动分类(最近一次 working 工具名分类,供气泡 activityCopy 文案)。 */
+ toolActivity?: PetToolActivity
/** 首次写入时间戳,当前不用于去重(保留给未来生命周期)。 */
firstSeqAt: number
}
@@ -131,6 +173,9 @@ function payloadEqual(a: PetSessionPayload, b: PetSessionPayload): boolean {
&& Object.is(a.origin, b.origin)
&& Object.is(a.title, b.title)
&& Object.is(a.displayTitle, b.displayTitle)
+ && Object.is(a.workStatus, b.workStatus)
+ && Object.is(a.task, b.task)
+ && Object.is(a.toolActivity, b.toolActivity)
&& Object.is(a.liveActivity?.kind, b.liveActivity?.kind)
&& Object.is(a.liveActivity?.text, b.liveActivity?.text)
&& Object.is(a.liveActivity?.name, b.liveActivity?.name)
@@ -151,6 +196,7 @@ export function foldPetPayload(state: PetSessionState): PetSessionPayload {
? { kind: 'reasoning', text: state.reasoningTail }
: undefined
+ // 细分档位是权威(气泡/动画按它切档);粗 status 保留作兼容回退。
let status: string | undefined
if (state.lastAgentError)
status = 'error'
@@ -172,6 +218,9 @@ export function foldPetPayload(state: PetSessionState): PetSessionPayload {
phase: state.waitingKind,
running: state.running,
lastAgentError: state.lastAgentError,
+ workStatus: state.workStatus,
+ task: state.task,
+ toolActivity: state.toolActivity,
liveActivity,
}
}
@@ -245,6 +294,29 @@ function isUserQuestionTool(name?: string): boolean {
return hasUserNoun || hasNounFromUser || hasAsk || strong || submitsPlanForApproval
}
+/** 工具名 → 活动分类(对齐 dsh-dafeiyu companion-reducer 的 toolActivity + DSH 实际工具名 pwsh):气泡按分类选文案。 */
+export function toolActivityOf(name?: string): PetToolActivity {
+ const value = String(name || '').toLowerCase()
+ if (/search|grep|find|glob|web|read|fetch|open/.test(value))
+ return 'searching'
+ if (/write|edit|patch|replace|create|move|delete/.test(value))
+ return 'editing'
+ if (/test|check|lint|build|verify/.test(value))
+ return 'testing'
+ if (/shell|bash|exec|command|terminal|powershell|pwsh/.test(value))
+ return 'commanding'
+ return 'using-tool'
+}
+
+/** 从 todo/write 提取当前任务文本(in_progress 优先、其次 pending;与 dsh-dafeiyu 的 #todo 一致)。 */
+export function currentTaskFromTodo(data: Record<string, unknown>): string | undefined {
+ const todos = Array.isArray(data.todos) ? (data.todos as Array<{ status?: string, content?: string }>) : []
+ const current = todos.find(todo => todo?.status === 'in_progress')
+ ?? todos.find(todo => todo?.status === 'pending')
+ const content = String(current?.content ?? '').trim()
+ return content || undefined
+}
+
/** 一次会话增量事件的 reducer:返回变化后的 payload 或 null(未变化则不转发)。 */
export function reduceSessionEvent(
state: PetSessionState,
@@ -263,18 +335,28 @@ export function reduceSessionEvent(
state.waitingKind = undefined
state.waitingApprovalId = undefined
state.waitingCallId = undefined
+ // 新回合开始:清上一回合的终态错误与任务残留,避免「上一轮报错、本轮继续跑」
+ // 时 use-bubble 仍按 lastAgentError 判 failed 收起气泡。
+ state.lastAgentError = undefined
+ state.workStatus = 'thinking'
+ state.task = undefined
break
}
case 'step/start':
case 'assistant/chunk': {
state.stepActive = true
state.running = true
+ if (t === 'step/start' && !state.waitingKind && state.openTools.size === 0)
+ state.workStatus = 'thinking'
if (t === 'assistant/chunk') {
// StreamChunk 真实形状:reasoning-delta / text-delta 携带增量 text(非 chunk.content)。
const chunk = data.chunk as { type?: string, text?: string } | undefined
if (chunk?.type === 'reasoning-delta' && typeof chunk.text === 'string' && chunk.text) {
// 滚动尾部窗口:只保留最近的文本,新内容不断挤掉最早的,气泡即可实时滚动更新。
state.reasoningTail = (state.reasoningTail + chunk.text).slice(-PET_REASONING_TAIL_WINDOW)
+ // 回合内思考(无工具在跑)→ thinking:气泡显示「正在认真想下一步」。
+ if (!state.waitingKind && state.openTools.size === 0)
+ state.workStatus = 'thinking'
// reasoning 需要实时浮出(气泡「思考 · text」),但不逐 token 洪泛:仅当
// 尾部文本实际变化才折叠(下方 foldable 判定对 assistant/chunk 在本分支处理)。
return foldPetPayload(state)
@@ -294,6 +376,8 @@ export function reduceSessionEvent(
const text = blocks?.filter(b => b?.type === 'text' && typeof b.text === 'string').map(b => b.text).join('')
if (text)
state.assistantText = text.slice(-1000)
+ if (!state.waitingKind && state.openTools.size === 0)
+ state.workStatus = 'thinking'
break
}
case 'tool/call': {
@@ -307,6 +391,12 @@ export function reduceSessionEvent(
if (name && isUserQuestionTool(name)) {
state.waitingKind = 'user-question'
state.waitingCallId = tc.callId ?? name
+ state.workStatus = 'waiting'
+ }
+ else {
+ if (name)
+ state.toolActivity = toolActivityOf(name)
+ state.workStatus = 'working'
}
break
}
@@ -324,9 +414,18 @@ export function reduceSessionEvent(
else {
state.openTools.clear()
}
- const err = data.error as { name?: string } | undefined
- if (err?.name)
- state.lastAgentError = String(err.name)
+ // 注意:工具级失败(data.error)不写入 lastAgentError —— 那是回合级终态语义,
+ // 写入后 use-bubble 会把本会话判为 failed 并 4s 收起气泡,而回合仍在跑(对齐
+ // dsh-dafeiyu:tool/result 错误只发 toolError 提示,状态回 WORKING/THINKING,
+ // 不污染终态)。回合真正失败由 turn/end(error) 负责记录。
+ // 工具完成回整理(dsh-pet:tool/result → result 档);仍有工具在跑则保持 working。
+ if (state.openTools.size > 0) {
+ state.workStatus = 'working'
+ state.toolActivity = toolActivityOf(state.openTools.values().next().value?.name)
+ }
+ else {
+ state.workStatus = state.waitingKind ? 'waiting' : 'result'
+ }
break
}
case 'approval/asked': {
@@ -335,6 +434,7 @@ export function reduceSessionEvent(
state.waitingKind = 'approval'
state.waitingApprovalId = id
state.running = true
+ state.workStatus = 'waiting'
break
}
case 'approval/decided': {
@@ -342,6 +442,8 @@ export function reduceSessionEvent(
if (state.waitingApprovalId && id === state.waitingApprovalId) {
state.waitingApprovalId = undefined
state.waitingKind = undefined
+ // 审批通过后继续干活:还有工具在跑 → working;否则回思考。
+ state.workStatus = state.openTools.size > 0 ? 'working' : 'thinking'
}
else {
// 与当前记录不匹配:状态未变,不转发。
@@ -354,13 +456,24 @@ export function reduceSessionEvent(
// 避免把用户提示当成助手描述。展示 message 只来自 assistant/message。
state.running = true
state.turnActive = true
- // 若此前在等用户回答(问句工具),用户已应答 → 清除等待态。
+ // 若此前在等用户回答(问句工具),用户已应答 → 清除等待态,继续干活。
if (state.waitingCallId !== undefined) {
state.waitingKind = undefined
state.waitingCallId = undefined
+ state.workStatus = state.openTools.size > 0 ? 'working' : 'thinking'
}
break
}
+ case 'todo/write': {
+ // 任务清单更新:当前任务(in_progress/pending)作为气泡 taskCopy 文案来源。
+ const task = currentTaskFromTodo(data)
+ if (task !== state.task) {
+ state.task = task
+ // task 变化即转发(供气泡展示「正在处理 xxx」);其余字段不动。
+ return foldPetPayload(state)
+ }
+ return null
+ }
case 'session/title': {
// 会话标题日志事件:覆盖身份字段(title/displayTitle 取同一值;origin 由 peer 权威覆盖)。
const title = (data as { title?: string }).title
@@ -383,12 +496,29 @@ export function reduceSessionEvent(
if (reason?.kind === 'blocked') {
// 会话被阻塞等待用户处理:展示为「等待中」。
state.waitingKind = 'blocked'
+ state.workStatus = 'waiting'
}
else {
state.waitingKind = undefined
- if (reason?.kind === 'error' || reason?.kind === 'aborted') {
+ const kind = reason?.kind
+ if (kind === 'completed') {
+ // 回合完成(终态档):播一次庆祝动画;lastAgentError 清空(本轮无错)。
+ state.workStatus = 'success'
+ state.lastAgentError = undefined
+ }
+ else if (kind === 'error' || kind === 'max-tokens' || kind === 'timeout') {
+ // 失败/达上限(终态档):record error 信息供气泡展示失败详情。
+ state.workStatus = 'error'
const errBody = (data as { reason?: { error?: { message?: string } } }).reason
- state.lastAgentError = errBody?.error?.message ?? reason.kind
+ state.lastAgentError = errBody?.error?.message ?? kind
+ }
+ else {
+ // aborted 等:回合中断,清档回空闲(绝不残留上一档,防止「一直 working」挂死)。
+ state.workStatus = undefined
+ if (kind === 'error' || kind === 'aborted') {
+ const errBody = (data as { reason?: { error?: { message?: string } } }).reason
+ state.lastAgentError = errBody?.error?.message ?? kind
+ }
}
}
break
@@ -422,6 +552,7 @@ export function reduceSessionEvent(
* 避免逐 token 洪泛 —— 状态实时累积,但最多每 500ms 推送一次最新尾部。
* @param handle - 变化时回调 (action, payload)。
* @param opts - 可选注入时钟(默认 Date.now),供单测 hermetic 推进时间。
+ * @param opts.now - 时钟函数(ms),节流窗口判定用;默认 Date.now。
*/
export function createPetSessionReducer(
handle: (action: 'create' | 'update' | 'remove', payload: PetSessionPayload) => void,
diff --git a/src-tauri/resources/preset-pets.json b/src-tauri/resources/preset-pets.json
index 9c242b9f..e586434b 100644
--- a/src-tauri/resources/preset-pets.json
+++ b/src-tauri/resources/preset-pets.json
@@ -3,9 +3,9 @@
"id": "maid-deepseek-whale",
"name": "Maid DeepSeek Whale",
"desc": "一只小小的七比蓝头发的鲸鱼女仆Codex宠物,穿着海军蓝裙子,白色褶边,蓝眼睛,侧鳍和鲸鱼尾巴。",
- "image": "https://raw.githubusercontent.com/PC2005-cloud/dsh-pet/f0f772e9cda4074d1870c97afd01dc26b91e943c/dsh-pet/assets/preview/daiji-huxi-xiuxian.gif",
+ "image": "https://raw.githubusercontent.com/PC2005-cloud/dsh-pet/e1ff8c1e4001878cbb80441262d530e16541f138/dsh-pet/assets/preview/daiji-huxi-xiuxian.gif",
"repo": "https://github.com/PC2005-cloud/dsh-pet",
- "ref": "f0f772e9cda4074d1870c97afd01dc26b91e943c",
+ "ref": "e1ff8c1e4001878cbb80441262d530e16541f138",
"assets": "dsh-pet/assets",
"sizeMb": 113
}