Files
hapi/shared/src/conversationHistory.ts
T
KorenKritaandGitHub 021b5c194b feat(pi): complete RPC parity, native steer, and history controls (#1353)
* feat(pi): complete RPC interaction parity

* feat(pi): integrate native conversation history

* fix(pi): harden RPC lifecycle boundaries

* fix(pi): address review lifecycle and upload boundaries

* fix(pi): release history transaction on rollback deadline

* fix(pi): isolate preflight and timed-out mutations

* fix(pi): preserve retry and editor boundaries

* fix(pi): disable unavailable history synchronization

* fix(pi): gate fallback readiness on history baseline

* fix(pi): bind uploads and retire extension requests

* fix(pi): preserve canceled and legacy stream boundaries

* fix(pi): preserve native fork runtime state

* fix(pi): persist dialogs and preserve select values

* fix(pi): keep upload authorization path-stable

* feat(pi): preserve native steer semantics

Route ordinary sends during an active Pi main turn through native steer while keeping explicit queue delivery on the existing composer gestures. Persist the delivery contract across Hub replay and Web retries, and guard stale steer dispatch with streaming generations and ordered prompt fallback.

* fix(pi): queue deferred steer deliveries

Keep native steer only for the initial live emit. Reconnect replay, CLI backfill, clear-gate release, and mature delivery now downgrade turn-scoped steer intent to the durable HAPI queue without mutating stored provenance.

* fix(pi): retain abort guard through preflight miss

Treat an immediate no-active abort rejection as a possible async-preflight race. Keep the existing abort boundary alive so a late agent_start receives the compensating abort before queued work is released.

* fix(pi): queue stale steer retries

A failed send no longer reuses turn-scoped steer intent after its original Pi generation is lost. Text restoration, attachment retry, and legacy retry provenance all enter the durable HAPI queue while fresh ordinary sends retain native steer behavior.

* fix(pi): invalidate rejected abort generation

After a no-active preflight abort waits through late-start compensation, mark the target stream idle while the runtime mutation lease is still held. Waiting native steers therefore fall back instead of entering the aborted generation.

* fix(pi): queue idempotent steer retries

Track whether a localId insert created a new row. Initial inserts may retain live Pi steer, while duplicate-localId retries deliver a queue-safe view of the stored row without overwriting its original provenance.

* fix(pi): sync command-only history before fallback

Read the Pi append log before retiring a successful prompt that produced no agent lifecycle. Preserve FIFO history associations across missing entry events, and fail the wrapper closed if that mandatory synchronization cannot be completed.
2026-08-04 11:01:00 +08:00

71 lines
2.4 KiB
TypeScript

export type CapabilityState = 'unknown' | 'supported' | 'unsupported'
export type ConversationHistoryCapabilityStates = {
forkCurrent: CapabilityState
forkAtMessage: CapabilityState
rewindToMessage: CapabilityState
}
export type ConversationHistoryCapabilities = {
forkCurrent?: boolean
forkAtMessage?: boolean
rewindToMessage?: boolean
}
/** Only `supported` becomes true in session metadata; never optimistic. */
export function toConversationHistoryCapabilities(
states: ConversationHistoryCapabilityStates
): ConversationHistoryCapabilities | undefined {
const capabilities: ConversationHistoryCapabilities = {}
if (states.forkCurrent === 'supported') capabilities.forkCurrent = true
if (states.forkAtMessage === 'supported') capabilities.forkAtMessage = true
if (states.rewindToMessage === 'supported') capabilities.rewindToMessage = true
return Object.keys(capabilities).length > 0 ? capabilities : undefined
}
export function markUnsupported(
states: ConversationHistoryCapabilityStates,
key: keyof ConversationHistoryCapabilityStates
): ConversationHistoryCapabilityStates {
if (states[key] === 'unsupported') return states
return { ...states, [key]: 'unsupported' }
}
export function markSupported(
states: ConversationHistoryCapabilityStates,
key: keyof ConversationHistoryCapabilityStates
): ConversationHistoryCapabilityStates {
if (states[key] === 'unsupported') return states
return { ...states, [key]: 'supported' }
}
export const UNSUPPORTED_CONVERSATION_HISTORY: ConversationHistoryCapabilityStates = {
forkCurrent: 'unsupported',
forkAtMessage: 'unsupported',
rewindToMessage: 'unsupported'
}
export const CLAUDE_CONVERSATION_HISTORY: ConversationHistoryCapabilityStates = {
forkCurrent: 'supported',
forkAtMessage: 'unsupported',
rewindToMessage: 'unsupported'
}
export const CODEX_CONVERSATION_HISTORY_INITIAL: ConversationHistoryCapabilityStates = {
forkCurrent: 'unknown',
forkAtMessage: 'unknown',
rewindToMessage: 'unknown'
}
export const GROK_CONVERSATION_HISTORY_INITIAL: ConversationHistoryCapabilityStates = {
forkCurrent: 'unknown',
forkAtMessage: 'unknown',
rewindToMessage: 'unknown'
}
export const PI_CONVERSATION_HISTORY_INITIAL: ConversationHistoryCapabilityStates = {
forkCurrent: 'unknown',
forkAtMessage: 'unknown',
rewindToMessage: 'unknown'
}