mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* refactor(agent-session): split subscribe params and read failure text into their own modules Both host files sit at the 300-line budget, so the append negotiation that follows needs room. Pure moves: SubscribeParams keeps its exact schema (now z.object + sessionId instead of OptionsParams.extend, which is equivalent) and is re-exported from the params module; stream failure text moves beside the other read-refusal classification. * perf(agent-session): stream running tool output heads as appends A running tool call re-sends its whole output head (up to 16KB) on every revision, and keeps re-sending the saturated head after it stops growing. Streams that also ask for toolOutputAppend (host advertises agent-session.tool-output-append.v1) now get only the head's new text under the same shared sender/reader rules and self-healing refusal as reply appends. - The live read negotiates the exact subscribe capabilities object instead of a boolean; mobile asks for tool output appends when advertised. - Hosts with only text-append.v1 drop the unknown key, so clients ask only when the new capability is advertised and both ends track the same bases. - Text-only streams keep the 8-base limit already-shipped readers evict at. - A host that refuses the capabilities param (an older build after a downgrade) makes the next open go without appends instead of failing forever. * perf(native-chat): ask remote hosts for streamed text appends on desktop Desktop chats on a paired or SSH-managed orcad received every streamed reply checkpoint whole: about 9x the reply's bytes at the Claude/Codex checkpoint cadence, and O(N^2) for ACP/JSONL providers that rewrite each 60ms window. The desktop read now asks environment hosts for reply and tool-output appends when they advertise them, reusing the shared reader that rebuilds whole items before the reducer. Local IPC reads are unchanged and still subscribe in the same turn. The support read runs once per chat run, overlapping hydration.
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import type { AgentJournalRenderItem } from './journal/agent-session-journal-types'
|
|
import type { AgentSessionSubscribeEvent } from './agent-session-wire'
|
|
import type { AgentSessionTextAppendItem } from './agent-session-text-append'
|
|
import {
|
|
startStructuredAgentSessionLiveRead,
|
|
type StructuredAgentSessionLiveSubscribe
|
|
} from './structured-agent-session-live-read'
|
|
|
|
function reply(text: string, revision: number): AgentJournalRenderItem {
|
|
return {
|
|
itemId: 'reply-1',
|
|
revision,
|
|
sequence: 4,
|
|
observedAt: 1000,
|
|
body: { kind: 'message', role: 'assistant', blocks: [{ type: 'text', text }] }
|
|
}
|
|
}
|
|
|
|
function appended(revision: number, from: number, text: string): AgentSessionTextAppendItem {
|
|
return { ...reply('', revision), textAppend: { from, text } }
|
|
}
|
|
|
|
function batch(sequence: number, items: AgentJournalRenderItem[]): AgentSessionSubscribeEvent {
|
|
return {
|
|
type: 'batch',
|
|
sessionId: 'session-1',
|
|
batch: { cursor: { epoch: 'epoch-1', sequence }, items, removedItemIds: [], submissions: [] }
|
|
}
|
|
}
|
|
|
|
describe('structured agent session live read with text appends', () => {
|
|
it('drops a stream whose append does not match and resumes without appends', async () => {
|
|
const opened: { params: unknown; emit: (event: AgentSessionSubscribeEvent) => void }[] = []
|
|
const unsubscribed: number[] = []
|
|
const subscribe: StructuredAgentSessionLiveSubscribe = async (params, onEvent) => {
|
|
const index = opened.push({ params, emit: onEvent }) - 1
|
|
return { unsubscribe: () => unsubscribed.push(index) }
|
|
}
|
|
const applied: AgentSessionSubscribeEvent[] = []
|
|
const read = startStructuredAgentSessionLiveRead({
|
|
applyEvent: (event) => applied.push(event),
|
|
applyError: () => {},
|
|
getCursor: () => ({ epoch: 'epoch-1', sequence: 4 }),
|
|
onContactLost: () => {},
|
|
onHistoryReadInvalidated: () => {},
|
|
sessionId: 'session-1',
|
|
subscribe,
|
|
textAppend: Promise.resolve({ textAppend: 1 }),
|
|
readCurrentRequests: vi.fn(),
|
|
subscribeRetryNow: () => () => {}
|
|
})
|
|
await vi.waitFor(() => expect(opened).toHaveLength(1))
|
|
expect(opened[0]?.params).toEqual({
|
|
sessionId: 'session-1',
|
|
cursor: { epoch: 'epoch-1', sequence: 4 },
|
|
capabilities: { textAppend: 1 }
|
|
})
|
|
opened[0]?.emit(batch(4, [reply('Hel', 1)]))
|
|
opened[0]?.emit(batch(5, [appended(2, 7, 'lo')]))
|
|
|
|
await vi.waitFor(() => expect(opened).toHaveLength(2))
|
|
expect(opened[1]?.params).toEqual({
|
|
sessionId: 'session-1',
|
|
cursor: { epoch: 'epoch-1', sequence: 4 }
|
|
})
|
|
expect(unsubscribed).toEqual([0])
|
|
expect(applied).toEqual([batch(4, [reply('Hel', 1)])])
|
|
read.dispose()
|
|
})
|
|
})
|