mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
* perf(native-chat): preserve historical tool rows while streaming * perf(native-chat): short-circuit identical rows and lock producer immutability Most folded rows come back as the input object, so compare identity before scanning fields and blocks. Add a regression test for the invariant the reuse cache depends on: ordering and folding never rewrite producer-owned messages or blocks, which reused rows alias.
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import type { AgentJournalRenderItem, AgentJournalSubmission } from './agent-session-journal-types'
|
|
import { agentJournalSubmissionKey } from './agent-session-journal-item-key'
|
|
import type { NativeChatMessage } from './native-chat-types'
|
|
import {
|
|
reconcileStructuredAgentSessionOutbox,
|
|
type StructuredAgentSessionOutboxEntry
|
|
} from './structured-agent-session-outbox'
|
|
import { projectStructuredItemsToNativeChat } from './structured-agent-session-projection'
|
|
|
|
export function projectStructuredAgentSessionMessages(
|
|
items: readonly AgentJournalRenderItem[],
|
|
outbox: readonly StructuredAgentSessionOutboxEntry[],
|
|
submissions: readonly AgentJournalSubmission[],
|
|
projectItems = projectStructuredItemsToNativeChat
|
|
): NativeChatMessage[] {
|
|
const optimistic = reconcileStructuredAgentSessionOutbox(outbox, submissions)
|
|
const journalled = new Set(items.map((item) => item.itemId))
|
|
return [
|
|
...projectItems(items),
|
|
...optimistic
|
|
.filter((entry) => !journalled.has(agentJournalSubmissionKey(entry.clientMessageId)))
|
|
.map((entry): NativeChatMessage => ({
|
|
id: agentJournalSubmissionKey(entry.clientMessageId),
|
|
role: 'user',
|
|
source: 'transcript',
|
|
timestamp: entry.queuedAt,
|
|
blocks: entry.body.blocks
|
|
}))
|
|
]
|
|
}
|