feat: support Codex goal slash command

This commit is contained in:
weishu
2026-05-15 22:15:17 +08:00
parent a099ae9199
commit 089ddad476
24 changed files with 808 additions and 6 deletions
+22 -3
View File
@@ -1,5 +1,6 @@
import type { AgentState } from '@/types/api'
import type { ChatBlock, NormalizedMessage, UsageData } from '@/chat/types'
import type { AgentEvent, ChatBlock, NormalizedMessage, UsageData } from '@/chat/types'
import type { ThreadGoal } from '@/types/api'
import { traceMessages, type TracedMessage } from '@/chat/tracer'
import { dedupeAgentEvents, foldApiErrorEvents } from '@/chat/reducerEvents'
import { collectTitleChanges, collectToolIdsFromMessages, ensureToolBlock, getPermissions } from '@/chat/reducerTools'
@@ -27,10 +28,23 @@ export type LatestUsage = {
timestamp: number
}
function getLatestThreadGoal(normalized: NormalizedMessage[]): ThreadGoal | null {
for (let i = normalized.length - 1; i >= 0; i--) {
const msg = normalized[i]
if (msg.role !== 'event') continue
const event = msg.content as AgentEvent
if (event.type === 'thread-goal-cleared') return null
if (event.type === 'thread-goal-updated') {
return (event as { goal?: ThreadGoal }).goal ?? null
}
}
return null
}
export function reduceChatBlocks(
normalized: NormalizedMessage[],
agentState: AgentState | null | undefined
): { blocks: ChatBlock[]; hasReadyEvent: boolean; latestUsage: LatestUsage | null } {
): { blocks: ChatBlock[]; hasReadyEvent: boolean; latestUsage: LatestUsage | null; latestGoal: ThreadGoal | null } {
const permissionsById = getPermissions(agentState)
const toolIdsInMessages = collectToolIdsFromMessages(normalized)
const titleChangesByToolUseId = collectTitleChanges(normalized)
@@ -116,5 +130,10 @@ export function reduceChatBlocks(
}
}
return { blocks: dedupeAgentEvents(foldApiErrorEvents(rootResult.blocks)), hasReadyEvent, latestUsage }
return {
blocks: dedupeAgentEvents(foldApiErrorEvents(rootResult.blocks)),
hasReadyEvent,
latestUsage,
latestGoal: getLatestThreadGoal(normalized)
}
}