mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-08 07:17:39 +00:00
feat: support Codex goal slash command
This commit is contained in:
+22
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user