Files
orca/src/preload/api/native-chat-api.ts
T
OrcaWinandOrcaWin 0efc842028 [comment audit] Shorten preload comments (#32257)
* chore: audit preload root comments and track repository coverage

* docs: track repository comment audit coverage

* chore: keep comment audit tracker local

* chore: shorten preload API contract comments

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 02:16:59 -07:00

71 lines
2.1 KiB
TypeScript

import type {
AgentType,
NativeChatMessage,
NativeChatTurnLifecycle
} from '../../shared/native-chat-types'
// notFound marks a not-yet-on-disk miss (retry-worthy) vs a real read/parse error (#8401).
export type NativeChatReadSessionResult =
| {
messages: NativeChatMessage[]
lifecycle?: NativeChatTurnLifecycle
}
| { error: string; notFound?: true }
export type NativeChatAppendedMessages = NativeChatMessage[]
export type NativeChatSubscriptionFrame =
| {
type: 'snapshot'
messages: NativeChatMessage[]
hasMore: boolean
error?: string
lifecycle?: NativeChatTurnLifecycle
/** No transcript yet; do not treat this frame as settled session history. */
pending?: boolean
}
| {
type: 'replacement'
messages: NativeChatMessage[]
hasMore: boolean
lifecycle?: NativeChatTurnLifecycle
}
| {
type: 'appended'
messages: NativeChatMessage[]
lifecycle?: NativeChatTurnLifecycle
}
export type NativeChatAppendedPayload = {
subscriptionId: string
frame: NativeChatSubscriptionFrame
}
export type NativeChatSubscribeArgs = {
/** Unique per caller to isolate live panes sharing a renderer. */
subscriptionId: string
agent: AgentType
sessionId: string
/** Authoritative transcript path from the agent hook (providerSession). */
transcriptPath?: string
/** First snapshot size; later readSession calls grow this for pagination. */
limit?: number
}
export type NativeChatApi = {
/** Reads the latest limit turns; the hook-reported transcriptPath takes precedence over ID globbing. */
readSession: (
agent: AgentType,
sessionId: string,
limit?: number,
transcriptPath?: string
) => Promise<NativeChatReadSessionResult>
/** First frame is a bounded snapshot; later frames contain only appended messages. */
subscribe: (
args: NativeChatSubscribeArgs,
onFrame: (frame: NativeChatSubscriptionFrame) => void
) => () => void
/** A local structured chat's last failed naming output; null when none or not local. */
getConversationNameFailureOutput: (sessionId: string) => Promise<string | null>
}