import { Context, Effect, Layer, Schema } from "effect"; import { Prompt, Response, Tool } from "effect/unstable/ai"; import { CompactionCommit, Event as ModelTelemetryEvent } from "../model/model-telemetry.js"; /** @experimental Opaque session entry id. */ export type EntryId = string; /** @experimental Host-defined metadata carried by session entries. */ export type Metadata = Readonly>; /** @experimental Common fields for session entries. */ export type BaseEntry = { readonly id: EntryId; readonly parentId: EntryId | null; readonly metadata?: Metadata; }; /** @experimental A verbatim conversation message. */ export type MessageEntry = BaseEntry & { readonly _tag: "Message"; readonly message: Prompt.Message; }; export declare const ModelResponseContent: Schema.$Array; readonly text: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"reasoning">; readonly text: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"tool-approval-request">; readonly approvalId: Schema.String; readonly toolCallId: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"file">; readonly mediaType: Schema.String; readonly data: Schema.Uint8ArrayFromBase64; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"source">; readonly sourceType: Schema.tag<"document">; readonly id: Schema.String; readonly mediaType: Schema.String; readonly title: Schema.String; readonly fileName: Schema.optionalKey; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"source">; readonly sourceType: Schema.tag<"url">; readonly id: Schema.String; readonly url: Schema.URLFromString; readonly title: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"response-metadata">; readonly id: Schema.UndefinedOr; readonly modelId: Schema.UndefinedOr; readonly timestamp: Schema.UndefinedOr; readonly request: Schema.UndefinedOr; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"finish">; readonly reason: Schema.Literals<["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]>; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; readonly usage: Schema.Struct<{ readonly inputTokens: Schema.Struct<{ readonly uncached: Schema.optionalKey>; readonly total: Schema.optionalKey>; readonly cacheRead: Schema.optionalKey>; readonly cacheWrite: Schema.optionalKey>; }>; readonly outputTokens: Schema.Struct<{ readonly total: Schema.optionalKey>; readonly text: Schema.optionalKey>; readonly reasoning: Schema.optionalKey>; }>; }>; readonly response: Schema.optionalKey]>>; }>>>; }>, Schema.Struct<{ readonly type: Schema.Literal<"tool-call">; readonly id: Schema.String; readonly name: Schema.String; readonly params: Schema.Unknown; readonly providerExecuted: Schema.Boolean; readonly metadata: Schema.$Record>>; }>, Schema.Struct<{ readonly type: Schema.Literal<"tool-result">; readonly id: Schema.String; readonly name: Schema.String; readonly isFailure: Schema.Boolean; readonly result: Schema.Unknown; readonly encodedResult: Schema.Unknown; readonly providerExecuted: Schema.Boolean; readonly preliminary: Schema.Boolean; readonly metadata: Schema.$Record>>; }>]>>; export type ModelResponseEntry = BaseEntry & { readonly _tag: "ModelResponse"; readonly content: ReadonlyArray>>; }; /** @experimental A model-requested tool call. */ export type ToolCallEntry = BaseEntry & { readonly _tag: "ToolCall"; readonly part: Prompt.ToolCallPart; }; /** @experimental A tool execution result. */ export type ToolResultEntry = BaseEntry & { readonly _tag: "ToolResult"; readonly part: Prompt.ToolResultPart; }; /** @experimental Recalled or persisted memory context. */ export type MemoryEntry = BaseEntry & { readonly _tag: "Memory"; readonly items: ReadonlyArray; }; /** @experimental An activated skill body. */ export type SkillEntry = BaseEntry & { readonly _tag: "Skill"; readonly name: string; readonly body: string; }; /** @experimental Live steering input preserved as a prompt message. */ export type SteeringEntry = BaseEntry & { readonly _tag: "Steering"; readonly message: Prompt.Message; }; /** @experimental A self-contained conversation projection imported by a durable handoff. */ export type HandoffEntry = BaseEntry & { readonly _tag: "Handoff"; readonly handoffId: string; readonly target: string; readonly projectedHistory: Prompt.Prompt; }; /** @experimental An exact point-in-time compaction projection. */ export type CompactionEntry = BaseEntry & { readonly _tag: "Compaction"; readonly projectedHistory: Prompt.Prompt; readonly telemetry: ReadonlyArray; readonly compactionCommit?: CompactionCommit; readonly summary?: string; }; /** @experimental A summary of an abandoned branch. */ export type BranchSummaryEntry = BaseEntry & { readonly _tag: "BranchSummary"; readonly summary: string; }; /** @experimental Closed union of session entries. */ export type Entry = MessageEntry | ModelResponseEntry | ToolCallEntry | ToolResultEntry | MemoryEntry | SkillEntry | SteeringEntry | HandoffEntry | CompactionEntry | BranchSummaryEntry; type AppendEntryInput = Item extends CompactionEntry ? never : Omit; /** @experimental Session entry input appended by a store implementation. */ export type AppendInput = AppendEntryInput; /** * @experimental Durable wire form of a Session entry. * * Session is the authority for model-facing history, so a store that persists entries needs one * shared encoding rather than each backend inventing its own. Entry ids and parent links are stored * as columns by the owning store; only the tag-specific payload is encoded here. */ export declare const EntryPayload: Schema.Union>; readonly message: Schema.Codec; }>, Schema.TaggedStruct<"ModelResponse", { readonly metadata: Schema.optionalKey>; readonly content: Schema.$Array; readonly text: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"reasoning">; readonly text: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"tool-approval-request">; readonly approvalId: Schema.String; readonly toolCallId: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"file">; readonly mediaType: Schema.String; readonly data: Schema.Uint8ArrayFromBase64; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"source">; readonly sourceType: Schema.tag<"document">; readonly id: Schema.String; readonly mediaType: Schema.String; readonly title: Schema.String; readonly fileName: Schema.optionalKey; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"source">; readonly sourceType: Schema.tag<"url">; readonly id: Schema.String; readonly url: Schema.URLFromString; readonly title: Schema.String; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"response-metadata">; readonly id: Schema.UndefinedOr; readonly modelId: Schema.UndefinedOr; readonly timestamp: Schema.UndefinedOr; readonly request: Schema.UndefinedOr; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; }>, Schema.Struct<{ readonly type: Schema.tag<"finish">; readonly reason: Schema.Literals<["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]>; readonly "~effect/ai/Content/Part": Schema.withDecodingDefaultKey>; readonly metadata: Schema.withDecodingDefault>>; readonly usage: Schema.Struct<{ readonly inputTokens: Schema.Struct<{ readonly uncached: Schema.optionalKey>; readonly total: Schema.optionalKey>; readonly cacheRead: Schema.optionalKey>; readonly cacheWrite: Schema.optionalKey>; }>; readonly outputTokens: Schema.Struct<{ readonly total: Schema.optionalKey>; readonly text: Schema.optionalKey>; readonly reasoning: Schema.optionalKey>; }>; }>; readonly response: Schema.optionalKey]>>; }>>>; }>, Schema.Struct<{ readonly type: Schema.Literal<"tool-call">; readonly id: Schema.String; readonly name: Schema.String; readonly params: Schema.Unknown; readonly providerExecuted: Schema.Boolean; readonly metadata: Schema.$Record>>; }>, Schema.Struct<{ readonly type: Schema.Literal<"tool-result">; readonly id: Schema.String; readonly name: Schema.String; readonly isFailure: Schema.Boolean; readonly result: Schema.Unknown; readonly encodedResult: Schema.Unknown; readonly providerExecuted: Schema.Boolean; readonly preliminary: Schema.Boolean; readonly metadata: Schema.$Record>>; }>]>>; }>, Schema.TaggedStruct<"ToolCall", { readonly metadata: Schema.optionalKey>; readonly part: Schema.Struct<{ readonly type: Schema.Literal<"tool-call">; readonly id: Schema.String; readonly name: Schema.String; readonly params: Schema.Unknown; readonly providerExecuted: Schema.withDecodingDefault; readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey>; readonly options: Schema.withDecodingDefault>>>; }>; }>, Schema.TaggedStruct<"ToolResult", { readonly metadata: Schema.optionalKey>; readonly part: Schema.Struct<{ readonly type: Schema.Literal<"tool-result">; readonly id: Schema.String; readonly name: Schema.String; readonly isFailure: Schema.Boolean; readonly result: Schema.Unknown; readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey>; readonly options: Schema.withDecodingDefault>>>; }>; }>, Schema.TaggedStruct<"Memory", { readonly metadata: Schema.optionalKey>; readonly items: Schema.$Array; }>, Schema.TaggedStruct<"Skill", { readonly metadata: Schema.optionalKey>; readonly name: Schema.String; readonly body: Schema.String; }>, Schema.TaggedStruct<"Steering", { readonly metadata: Schema.optionalKey>; readonly message: Schema.Codec; }>, Schema.TaggedStruct<"Handoff", { readonly metadata: Schema.optionalKey>; readonly handoffId: Schema.String; readonly target: Schema.String; readonly projectedHistory: Schema.Codec; }>, Schema.TaggedStruct<"Compaction", { readonly metadata: Schema.optionalKey>; readonly projectedHistory: Schema.Codec; readonly telemetry: Schema.$Array; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly purpose: Schema.Literals; readonly provider: Schema.optionalKey; readonly model: Schema.optionalKey; readonly compactionId: Schema.optionalKey; readonly startedAt: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelAttemptStarted">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly modelAttemptId: Schema.String; readonly attempt: Schema.Int; readonly provider: Schema.optionalKey; readonly model: Schema.optionalKey; readonly registrationKey: Schema.optionalKey; readonly candidate: Schema.optionalKey; readonly startedAt: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelAttemptFirstOutput">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly modelAttemptId: Schema.String; readonly attempt: Schema.Int; readonly kind: Schema.Literals; readonly at: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelAttemptCompleted">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly modelAttemptId: Schema.String; readonly attempt: Schema.Int; readonly completedAt: Schema.Finite; readonly usage: typeof Response.Usage; readonly usageAt: Schema.Finite; readonly finishReason: Schema.Literals<["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]>; readonly provider: Schema.optionalKey; readonly model: Schema.optionalKey; readonly registrationKey: Schema.optionalKey; readonly candidate: Schema.optionalKey; readonly requestId: Schema.optionalKey; readonly responseModel: Schema.optionalKey; readonly serviceTier: Schema.optionalKey; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelAttemptFailed">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly modelAttemptId: Schema.String; readonly attempt: Schema.Int; readonly failedAt: Schema.Finite; readonly category: Schema.Literals; readonly classification: Schema.Literals; readonly disposition: Schema.Literals; readonly provider: Schema.optionalKey; readonly model: Schema.optionalKey; readonly registrationKey: Schema.optionalKey; readonly candidate: Schema.optionalKey; readonly providerUsage: Schema.optionalKey; readonly outputTokens: Schema.optionalKey; readonly totalTokens: Schema.optionalKey; }>>; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelRetryScheduled">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly attempt: Schema.Int; readonly reason: Schema.Literals; readonly category: Schema.Literals; readonly delayMillis: Schema.Finite; readonly at: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelFallbackScheduled">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly attempt: Schema.Int; readonly fromCandidate: Schema.Int; readonly fromProvider: Schema.String; readonly fromModel: Schema.String; readonly fromRegistrationKey: Schema.optionalKey; readonly toCandidate: Schema.Int; readonly toProvider: Schema.String; readonly toModel: Schema.String; readonly toRegistrationKey: Schema.optionalKey; readonly category: Schema.Literals; readonly at: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelCallCompleted">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly purpose: Schema.Literals; readonly attempts: Schema.Int; readonly completedAt: Schema.Finite; readonly usage: Schema.optionalKey; readonly failedAttemptUsage: Schema.optionalKey; readonly outputTokens: Schema.optionalKey; readonly totalTokens: Schema.optionalKey; }>>; readonly finishReason: Schema.optionalKey>; }>, Schema.Struct<{ readonly _tag: Schema.tag<"ModelCallFailed">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly modelCallId: Schema.String; readonly purpose: Schema.Literals; readonly attempts: Schema.Int; readonly failedAt: Schema.Finite; readonly category: Schema.Literals; readonly classification: Schema.Literals; readonly failedAttemptUsage: Schema.optionalKey; readonly outputTokens: Schema.optionalKey; readonly totalTokens: Schema.optionalKey; }>>; }>, Schema.Struct<{ readonly _tag: Schema.tag<"CompactionStarted">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly compactionId: Schema.String; readonly trigger: Schema.Literals; readonly startedAt: Schema.Finite; readonly contextTokensBefore: Schema.optionalKey; readonly entriesBefore: Schema.optionalKey; }>, Schema.Struct<{ readonly _tag: Schema.tag<"CompactionSkipped">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly compactionId: Schema.String; readonly skippedAt: Schema.Finite; }>, Schema.Struct<{ readonly _tag: Schema.tag<"CompactionApplied">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly compactionId: Schema.String; readonly checkpointId: Schema.String; readonly kind: Schema.Literals; readonly appliedAt: Schema.Finite; readonly commit: Schema.Struct<{ readonly compactionId: Schema.String; readonly checkpointId: Schema.String; readonly summaryModelCallId: Schema.optionalKey; readonly contextTokensBefore: Schema.optionalKey; readonly contextTokensAfter: Schema.optionalKey; readonly entriesBefore: Schema.optionalKey; readonly entriesAfter: Schema.optionalKey; }>; }>, Schema.Struct<{ readonly _tag: Schema.tag<"CompactionFailed">; readonly deliveryId: Schema.String; readonly turn: Schema.Finite; readonly compactionId: Schema.String; readonly failedAt: Schema.Finite; }>]>>; readonly compactionCommit: Schema.optionalKey; readonly contextTokensBefore: Schema.optionalKey; readonly contextTokensAfter: Schema.optionalKey; readonly entriesBefore: Schema.optionalKey; readonly entriesAfter: Schema.optionalKey; }>>; readonly summary: Schema.optionalKey; }>, Schema.TaggedStruct<"BranchSummary", { readonly metadata: Schema.optionalKey>; readonly summary: Schema.String; }>]>; /** @experimental */ export type EntryPayload = typeof EntryPayload.Type; declare const SessionStoreError_base: Schema.Class, import("effect/Cause").YieldableError>; /** @experimental Session store operation failure. */ export declare class SessionStoreError extends SessionStoreError_base { } declare const SessionConflict_base: Schema.Class; readonly message: Schema.String; }>, import("effect/Cause").YieldableError>; /** @experimental Session append conflict with the active path or entry identity. */ export declare class SessionConflict extends SessionConflict_base { } type AppendOptionsBase = { readonly ownerToken?: string; }; /** @experimental Expected active leaf for a store-assigned Session entry identity. */ export type GeneratedAppendOptions = AppendOptionsBase & { readonly id?: never; readonly expectedLeafId?: EntryId | null; }; /** @experimental Exact identity and parent for an idempotent normal Session append. */ export type StableAppendOptions = AppendOptionsBase & { readonly id: EntryId; readonly expectedLeafId: EntryId | null; }; /** @experimental Identity, expected active leaf, and host write-ownership token for a normal Session append. */ export type AppendOptions = GeneratedAppendOptions | StableAppendOptions; /** @experimental Exact idempotent projection. Atomically persist projection, telemetry, and commit; remote failure is ambiguous. */ export interface PreparedCheckpoint { readonly id: EntryId; readonly parentId: EntryId | null; readonly projectedHistory: Prompt.Prompt; readonly telemetry: ReadonlyArray; readonly compactionCommit?: CompactionCommit; readonly summary?: string; readonly ownerToken?: string; } /** @experimental Authoritative result of an idempotent checkpoint append. */ export interface CheckpointAppend { readonly _tag: "Appended" | "AlreadyPresent"; readonly checkpoint: CompactionEntry; readonly leafId: EntryId; } /** @experimental Session event-log service boundary. */ export interface Interface { readonly reserveEntryId: Effect.Effect; readonly append: (entry: AppendInput, options?: AppendOptions) => Effect.Effect; /** @experimental Atomically persists projection, telemetry, and commit. Remote failure is ambiguous; retry exactly. */ readonly appendCheckpoint: (checkpoint: PreparedCheckpoint) => Effect.Effect; readonly path: (leaf?: EntryId) => Effect.Effect, SessionStoreError>; readonly setLeaf: (id: EntryId | null) => Effect.Effect; readonly leaf: Effect.Effect; } declare const SessionStore_base: Context.ServiceClass; /** @experimental */ export declare class SessionStore extends SessionStore_base { } /** @experimental Canonical exact checkpoint equivalence, excluding the write-owner token. */ export declare const checkpointMatches: { (prepared: PreparedCheckpoint): (entry: CompactionEntry) => boolean; (entry: CompactionEntry, prepared: PreparedCheckpoint): boolean; }; export { ContextInvalid, buildContext, buildMemoryContext, unresolvedToolCalls, validateContext, } from "./session-projection.js"; /** @experimental Ref-backed non-durable session store. */ export declare const layerMemory: Layer.Layer; /** @experimental */ export declare const layerTest: (implementation: Interface) => Layer.Layer;