mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 11:24:37 +00:00
* refactor(mobile): give relay and encryption concrete owners * refactor(mobile): organize session and review feature owners * refactor(mobile): organize RPC and host ownership * test(mobile): point render fixtures at concrete owners * refactor(mobile): use explicit type-only owner imports
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import type { AgentSessionSubscribeEvent } from '../../../src/shared/agent-session/agent-session-wire'
|
|
import type { StructuredAgentSessionLiveSubscribe } from '../../../src/shared/agent-session/structured-agent-session-live-read'
|
|
import type { RpcClient } from '../transport/rpc/rpc-client-contract'
|
|
|
|
function isSubscribeEvent(value: unknown): value is AgentSessionSubscribeEvent {
|
|
if (typeof value !== 'object' || value === null || !('type' in value)) {
|
|
return false
|
|
}
|
|
const type = value.type
|
|
return type === 'snapshot' || type === 'batch' || type === 'reset' || type === 'end'
|
|
}
|
|
|
|
// Subscribe after the hold settles even on refusal: older hosts can start on the next send, so their transcript must remain visible.
|
|
export function subscribeTranscriptAfterHold(
|
|
client: RpcClient,
|
|
held: Promise<unknown>,
|
|
isEnded: () => boolean
|
|
): StructuredAgentSessionLiveSubscribe {
|
|
return async (params, onEvent, onError) => {
|
|
await held.catch(() => undefined)
|
|
if (isEnded()) {
|
|
return { unsubscribe: () => {} }
|
|
}
|
|
const close = client.subscribe('agentSession.subscribe', params, (raw) => {
|
|
if (typeof raw === 'object' && raw !== null && 'type' in raw && raw.type === 'error') {
|
|
// A stream's error frame carries the host's error, refusal and all, under `error`.
|
|
onError('error' in raw && raw.error !== undefined ? raw.error : raw)
|
|
return
|
|
}
|
|
if (isSubscribeEvent(raw)) {
|
|
onEvent(raw)
|
|
}
|
|
})
|
|
return { unsubscribe: close }
|
|
}
|
|
}
|