UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

80 lines • 4.45 kB
/** * Schema of the brain's `egress_call` ledger (row CK9; custody design 4.5, 2.3, 4.2, 15.7). One row per dialed model * call with its admitted request and, once `ended`, its assembled message stored beside it in 96 KiB chunks (never the * event log: every streamed event carries the whole message so far), the step-cancelled marker (W14), and the * per-session device variants (`session/variants`, read by the route). Every value here is written by `ledger.ts` * through the host's admitted mutations; this module only names keys and converts rows to and from store values. */ import type { DeviceId, ProviderId } from "@earendil-works/pi-agent-core"; import type { StoreValue } from "@earendil-works/pi-agent-core/conformance"; import type { AssistantMessage, StopReason, Usage } from "@earendil-works/pi-ai"; import { type ProviderCallErrorCode, type ProviderCallKind } from "./wire.ts"; /** `dispatched` -> `ended` -> `closed` (by the step commit, W9); `superseded` and `cancelled` are final. */ export type EgressCallState = "dispatched" | "ended" | "superseded" | "cancelled" | "closed"; /** `callback-stream` providers run tools inside the stream, so every reissue of their step needs a user choice. */ export type EgressCallCapability = "callback-stream" | "stream"; /** `message`: the assembled message lives in `chunks` result chunks; the row keeps only its stop reason and usage. */ export type EgressCallResult = { readonly kind: "message"; readonly stopReason: StopReason; readonly usage: Usage; readonly chunks: number; } | { readonly kind: "error"; readonly code: ProviderCallErrorCode; readonly message: string; readonly retryable: boolean; readonly usage?: Usage; }; /** What `ended` records: the assembled message of a finished call, or the hand's refusal or failure. */ export type EgressCallEnd = { readonly kind: "message"; readonly message: AssistantMessage; } | Extract<EgressCallResult, { readonly kind: "error"; }>; export interface EgressCallRow { readonly callId: string; readonly sessionId: string; readonly call: ProviderCallKind; readonly route: "sealed" | "device"; readonly deviceId?: DeviceId; readonly providerId: ProviderId; readonly modelId: string; readonly epoch: number; readonly capability: EgressCallCapability; /** The stored request already carries this session's request hooks (4.5). */ readonly hooksApplied: boolean; readonly state: EgressCallState; readonly requestChunks: number; readonly result?: EgressCallResult; } /** Durable `session/variants[P][deviceId]` (4.2); `mismatches` counts per (device, step) and restarts on a new head. */ export interface VariantRecord { readonly headDigest: string; readonly liveAtMismatch: string | undefined; readonly mismatches: number; } export declare const REQUEST_CHUNK_BYTES: number; export declare const callKey: (callId: string) => string; export declare const requestPrefix: (callId: string) => string; export declare const requestChunkKey: (callId: string, index: number) => string; export declare const resultPrefix: (callId: string) => string; export declare const resultChunkKey: (callId: string, index: number) => string; export declare const stepIndexPrefix: (stepId: string) => string; export declare const stepIndexKey: (stepId: string, attempt: number) => string; export declare const cancelledKey: (stepId: string) => string; export declare const variantPrefix: (providerId: ProviderId) => string; export declare const variantKey: (providerId: ProviderId, deviceId: DeviceId) => string; /** Splits UTF-8 text into chunks of at most `REQUEST_CHUNK_BYTES` bytes, never inside a code point. */ export declare function splitUtf8(text: string): string[]; /** The stored message text is the ledger's own JSON; the shape check guards against a truncated or foreign chunk set. */ export declare function isStoredMessage(value: unknown): value is AssistantMessage; export declare function encodeCallRow(row: EgressCallRow): StoreValue; export declare function decodeCallRow(value: StoreValue | undefined): EgressCallRow | undefined; export interface StoredVariant extends VariantRecord { readonly stepId: string; } export declare function decodeVariant(value: StoreValue | undefined): StoredVariant | undefined; export declare const encodeVariant: (variant: StoredVariant) => StoreValue; //# sourceMappingURL=ledger-schema.d.ts.map