Files
archived-orca/src/shared/agent-session-provider-context.ts
T
Brennan Benson bb44f74d00 Keep native chat /clear in the same conversation (#26579)
* Keep clear in the same chat and reset its provider context

* Derive clear pauses only from journal membership and cover older rewind clients

* Point queued command rewind test at the structured hook

* Group queue consume errors and rewind replay assertions
2026-10-08 16:00:29 -07:00

42 lines
1.2 KiB
TypeScript

import type { AgentSessionRecord } from './agent-session-record'
export type AgentSessionProviderContextBoundary = {
operationId: string
afterFence: number
clearedAt: number
}
export function isAgentSessionProviderContextBoundary(
value: unknown
): value is AgentSessionProviderContextBoundary {
return (
typeof value === 'object' &&
value !== null &&
'operationId' in value &&
typeof value.operationId === 'string' &&
value.operationId.length > 0 &&
value.operationId.length <= 512 &&
'afterFence' in value &&
typeof value.afterFence === 'number' &&
Number.isSafeInteger(value.afterFence) &&
value.afterFence >= 0 &&
'clearedAt' in value &&
typeof value.clearedAt === 'number' &&
Number.isSafeInteger(value.clearedAt) &&
value.clearedAt >= 0
)
}
/** Clear resets the chain; the boundary identifies a fresh launch before its first proof. */
export function activeProviderContext(
record: Pick<AgentSessionRecord, 'providerHandleChain' | 'providerContextBoundary'>
) {
const handleChain = record.providerHandleChain
const head = handleChain.at(-1) ?? null
return {
handleChain,
head,
pendingClear: record.providerContextBoundary !== undefined && head === null
}
}