import { Schema } from "effect"; import { Prompt, Response, Tool } from "effect/unstable/ai"; import { ModelResponseContent } from "../context/session.js"; import type { CompletedModelResponse } from "./model-response-builder.js"; export { ModelResponseContent }; /** @experimental A completed model response encoded as one durable operation result. */ export interface CompletedModelOperation { readonly operationId: string; readonly turn: number; readonly modelCallId: string; readonly modelAttemptId: string; readonly attempt: number; readonly sessionParentId: string | null; readonly replayFromHistory: boolean; readonly content: typeof ModelResponseContent.Encoded; readonly usage?: typeof Response.Usage.Encoded; readonly finishReason?: Response.FinishReason; readonly digest: string; } /** @experimental Schema for the JSON-only result recorded for one completed model operation. */ export declare const CompletedModelOperation: Schema.Struct<{ readonly operationId: Schema.String; readonly turn: Schema.Int; readonly modelCallId: Schema.String; readonly modelAttemptId: Schema.String; readonly attempt: Schema.Int; readonly sessionParentId: Schema.NullOr; readonly replayFromHistory: Schema.Boolean; readonly content: Schema.toEncoded; 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>>; }>]>>>; readonly usage: Schema.optionalKey>; readonly finishReason: Schema.optionalKey>; readonly digest: Schema.String; }>; /** @experimental Returns whether an unknown journal result is a completed model operation. */ export declare const isCompletedModelOperation: (input: I) => input is I & { readonly operationId: string; readonly turn: number; readonly modelCallId: string; readonly modelAttemptId: string; readonly attempt: number; readonly sessionParentId: string | null; readonly replayFromHistory: boolean; readonly content: readonly (Schema.Struct.ReadonlySide<{ 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>>; }, "Encoded"> | Schema.Struct.ReadonlySide<{ 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>>; }, "Encoded"> | { readonly type: "text"; readonly text: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "reasoning"; readonly text: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "tool-approval-request"; readonly approvalId: string; readonly toolCallId: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "file"; readonly mediaType: string; readonly data: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "source"; readonly sourceType: "document"; readonly id: string; readonly mediaType: string; readonly title: string; readonly fileName?: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "source"; readonly sourceType: "url"; readonly id: string; readonly url: string; readonly title: string; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "response-metadata"; readonly id: string | undefined; readonly modelId: string | undefined; readonly timestamp: string | undefined; readonly request: Schema.Struct.ReadonlySide<{ readonly method: Schema.Literals; readonly url: Schema.String; readonly urlParams: Schema.$Array>; readonly hash: Schema.UndefinedOr; readonly headers: Schema.$Record]>>; }, "Encoded"> | undefined; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; } | { readonly type: "finish"; readonly reason: "content-filter" | "error" | "length" | "other" | "pause" | "stop" | "tool-calls" | "unknown"; readonly "~effect/ai/Content/Part"?: "~effect/ai/Content/Part"; readonly metadata?: { readonly [x: string]: Schema.Json; } | undefined; readonly usage: Schema.Struct.ReadonlySide<{ 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>; }>; }, "Encoded">; readonly response?: Schema.Struct.ReadonlySide<{ readonly status: Schema.Number; readonly headers: Schema.$Record]>>; }, "Encoded"> | undefined; })[]; readonly usage?: Schema.Struct.ReadonlySide<{ readonly inputTokens: Schema.Struct<{ readonly uncached: Schema.UndefinedOr; readonly total: Schema.UndefinedOr; readonly cacheRead: Schema.UndefinedOr; readonly cacheWrite: Schema.UndefinedOr; }>; readonly outputTokens: Schema.Struct<{ readonly total: Schema.UndefinedOr; readonly text: Schema.UndefinedOr; readonly reasoning: Schema.UndefinedOr; }>; }, "Encoded">; readonly finishReason?: "content-filter" | "error" | "length" | "other" | "pause" | "stop" | "tool-calls" | "unknown"; readonly digest: string; }; /** @internal One validated part emitted while a model attempt is live or replayed. */ export interface AttemptPart { readonly _tag: "Part"; readonly messages: ReadonlyArray; readonly modelCallId: string; readonly modelAttemptId: string; readonly attempt: number; readonly part: Response.StreamPart>; } /** @internal The sole completion sentinel emitted after all validated model parts. */ export interface AttemptCompleted { readonly _tag: "Completed"; readonly messages: ReadonlyArray; readonly modelCallId: string; readonly modelAttemptId: string; readonly attempt: number; readonly sessionParentId: string | null; readonly replayFromHistory: boolean; readonly response: CompletedModelResponse>; } /** @internal Values crossing the durable model stream boundary. */ export type AttemptEvent = AttemptPart | AttemptCompleted;