Response
The Response module provides data structures to represent responses from large language models.
This module defines the complete structure of AI model responses, including various content parts for text, reasoning, tool calls, files, and metadata, supporting both streaming and non-streaming responses.
Constructors
documentSourcePart
Signature
declare function documentSourcePart(
params: ConstructorParams<DocumentSourcePart>,
): DocumentSourcePart;Constructs a new error part.
Signature
declare function errorPart(params: ConstructorParams<ErrorPart>): ErrorPart;Constructs a new file part.
Signature
declare function filePart(params: ConstructorParams<FilePart>): FilePart;finishPart
Constructs a new finish part.
Signature
declare function finishPart(params: ConstructorParams<FinishPart>): FinishPart;Creates a new response content part of the specified type.
Signature
declare function makePart<
Type extends
| "error"
| "text"
| "reasoning"
| "file"
| "tool-call"
| "tool-result"
| "text-start"
| "text-delta"
| "text-end"
| "reasoning-start"
| "reasoning-delta"
| "reasoning-end"
| "tool-params-start"
| "tool-params-delta"
| "tool-params-end"
| "source"
| "response-metadata"
| "finish",
>(
type: Type,
params: Omit<
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>,
"type" | "~effect/ai/Content/Part" | "metadata"
> & {
readonly metadata?:
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>["metadata"];
},
):
| Extract<
TextStartPart,
{
type: Type;
}
>
| Extract<
TextDeltaPart,
{
type: Type;
}
>
| Extract<
TextEndPart,
{
type: Type;
}
>
| Extract<
ReasoningStartPart,
{
type: Type;
}
>
| Extract<
ReasoningDeltaPart,
{
type: Type;
}
>
| Extract<
ReasoningEndPart,
{
type: Type;
}
>
| Extract<
ToolParamsStartPart,
{
type: Type;
}
>
| Extract<
ToolParamsDeltaPart,
{
type: Type;
}
>
| Extract<
ToolParamsEndPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
DocumentSourcePart,
{
type: Type;
}
>
| Extract<
UrlSourcePart,
{
type: Type;
}
>
| Extract<
ResponseMetadataPart,
{
type: Type;
}
>
| Extract<
FinishPart,
{
type: Type;
}
>
| Extract<
ErrorPart,
{
type: Type;
}
>
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
ToolCallPart<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultSuccess<any, any>,
{
type: Type;
}
>
| Extract<
ToolResultFailure<any, any>,
{
type: Type;
}
>;reasoningDeltaPart
Constructs a new reasoning delta part.
Signature
declare function reasoningDeltaPart(
params: ConstructorParams<ReasoningDeltaPart>,
): ReasoningDeltaPart;reasoningEndPart
Constructs a new reasoning end part.
Signature
declare function reasoningEndPart(params: ConstructorParams<ReasoningEndPart>): ReasoningEndPart;reasoningPart
Constructs a new reasoning part.
Signature
declare function reasoningPart(params: ConstructorParams<ReasoningPart>): ReasoningPart;reasoningStartPart
Constructs a new reasoning start part.
Signature
declare function reasoningStartPart(
params: ConstructorParams<ReasoningStartPart>,
): ReasoningStartPart;responseMetadataPart
Constructs a new response metadata part.
Signature
declare function responseMetadataPart(
params: ConstructorParams<ResponseMetadataPart>,
): ResponseMetadataPart;textDeltaPart
Constructs a new text delta part.
Signature
declare function textDeltaPart(params: ConstructorParams<TextDeltaPart>): TextDeltaPart;textEndPart
Constructs a new text end part.
Signature
declare function textEndPart(params: ConstructorParams<TextEndPart>): TextEndPart;Constructs a new text part.
Signature
declare function textPart(params: ConstructorParams<TextPart>): TextPart;textStartPart
Constructs a new text start part.
Signature
declare function textStartPart(params: ConstructorParams<TextStartPart>): TextStartPart;toolCallPart
Constructs a new tool call part.
Signature
declare function toolCallPart<Name extends string, Params>(
params: ConstructorParams<ToolCallPart<Name, Params>>,
): ToolCallPart<Name, Params>;toolParamsDeltaPart
Constructs a new tool params delta part.
Signature
declare function toolParamsDeltaPart(
params: ConstructorParams<ToolParamsDeltaPart>,
): ToolParamsDeltaPart;toolParamsEndPart
Constructs a new tool params end part.
Signature
declare function toolParamsEndPart(params: ConstructorParams<ToolParamsEndPart>): ToolParamsEndPart;toolParamsStartPart
Constructs a new tool params start part.
Signature
declare function toolParamsStartPart(
params: ConstructorParams<ToolParamsStartPart>,
): ToolParamsStartPart;toolResultPart
Constructs a new tool result part.
Signature
declare function toolResultPart<Params extends ConstructorParams<ToolResultPart<string, any, any>>>(
params: Params,
): Params extends {
readonly isFailure: false;
readonly name: Name;
readonly result: Success;
}
? ToolResultPart<Name, Success, never>
: Params extends {
readonly isFailure: true;
readonly name: Name;
readonly result: Failure;
}
? ToolResultPart<Name, never, Failure>
: never;urlSourcePart
Constructs a new URL source part.
Signature
declare function urlSourcePart(params: ConstructorParams<UrlSourcePart>): UrlSourcePart;Guards
Models
Union type for all response parts with tool-specific typing.
Signature
type AllParts<Tools extends Record<string, Tool.Any>> =
| TextPart
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;AllPartsEncoded type
Encoded representation of all response parts for serialization.
Signature
type AllPartsEncoded =
| TextPartEncoded
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;Union type representing all possible response content parts.
Signature
type AnyPart =
| TextPart
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallPart<any, any>
| ToolResultPart<any, any, any>
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;AnyPartEncoded type
Encoded representation of all possible response content parts for serialization.
Signature
type AnyPartEncoded =
| TextPartEncoded
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;Base interface for all response content parts.
Provides common structure including type identifier and optional metadata.
Signature
interface BasePart<Type extends string, Metadata extends ProviderMetadata> {
readonly "~effect/ai/Content/Part": "~effect/ai/Content/Part";
readonly metadata: Metadata;
readonly type: Type;
}BasePartEncoded interface
Base interface for encoded response content parts.
Signature
interface BasePartEncoded<Type extends string, Metadata extends ProviderMetadata> {
readonly metadata?: Metadata;
readonly type: Type;
}BaseToolResult interface
The base fields of a tool result part.
Signature
interface BaseToolResult<Name extends string> extends BasePart<
"tool-result",
ToolResultPartMetadata
> {
readonly encodedResult: unknown;
readonly id: string;
readonly name: Name;
readonly providerExecuted: boolean;
readonly providerName?: string;
}DocumentSourcePart interface
Response part representing a document source reference.
Used to reference documents that were used in generating the response.
Signature
interface DocumentSourcePart extends BasePart<"source", DocumentSourcePartMetadata> {
readonly fileName?: string;
readonly id: string;
readonly mediaType: string;
readonly sourceType: "document";
readonly title: string;
}DocumentSourcePartEncoded interface
Encoded representation of document source parts for serialization.
Signature
interface DocumentSourcePartEncoded extends BasePartEncoded<"source", DocumentSourcePartMetadata> {
readonly fileName?: string;
readonly id: string;
readonly mediaType: string;
readonly sourceType: "document";
readonly title: string;
}Response part indicating that an error occurred generating the response.
Signature
interface ErrorPart extends BasePart<"error", ErrorPartMetadata> {
readonly error: unknown;
}Example
import { Response } from "@effect/ai"
const errorPart: Response.ErrorPart = Response.makePart("error", {
error: new Error("boom"),
})ErrorPartEncoded interface
Encoded representation of error parts for serialization.
Signature
interface ErrorPartEncoded extends BasePartEncoded<"error", ErrorPartMetadata> {
readonly error: unknown;
}Response part representing a file attachment.
Supports various file types including images, documents, and binary data.
Signature
interface FilePart extends BasePart<"file", FilePartMetadata> {
readonly data: Uint8Array;
readonly mediaType: string;
}Example
import { Response } from "@effect/ai"
const imagePart: Response.FilePart = Response.makePart("file", {
mediaType: "image/jpeg",
data: new Uint8Array([1, 2, 3]),
})FilePartEncoded interface
Encoded representation of file parts for serialization.
Signature
interface FilePartEncoded extends BasePartEncoded<"file", FilePartMetadata> {
readonly data: string;
readonly mediaType: string;
}FinishPart interface
Response part indicating the completion of a response generation.
Signature
interface FinishPart extends BasePart<"finish", FinishPartMetadata> {
readonly reason: [
"stop",
"length",
"content-filter",
"tool-calls",
"error",
"pause",
"other",
"unknown",
];
readonly usage: Usage;
}Example
import { Response } from "@effect/ai"
const finishPart: Response.FinishPart = Response.makePart("finish", {
reason: "stop",
usage: {
inputTokens: 50,
outputTokens: 25,
totalTokens: 75,
},
})FinishPartEncoded interface
Encoded representation of finish parts for serialization.
Signature
interface FinishPartEncoded extends BasePartEncoded<"finish", FinishPartMetadata> {
readonly reason: [
"stop",
"length",
"content-filter",
"tool-calls",
"error",
"pause",
"other",
"unknown",
];
readonly usage: {
readonly cachedInputTokens?: number;
readonly inputTokens: number | undefined;
readonly outputTokens: number | undefined;
readonly reasoningTokens?: number;
readonly totalTokens: number | undefined;
};
}FinishReason
Represents the reason why a model finished generation of a response.
Possible finish reasons: - "stop": The model generated a stop sequence. - "length": The model exceeded its token budget. - "content-filter": The model generated content which violated a content filter. - "tool-calls": The model triggered a tool call. - "error": The model encountered an error. - "pause": The model requested to pause execution. - "other": The model stopped for a reason not supported by this protocol. - "unknown": The model did not specify a finish reason.
Signature
declare const FinishReason: Schema.Literal<
["stop", "length", "content-filter", "tool-calls", "error", "pause", "other", "unknown"]
>;FinishReason type
Signature
type FinishReason = typeof FinishReason.Type;A type for representing non-streaming response parts with tool-specific typing.
Signature
type Part<Tools extends Record<string, Tool.Any>> =
| TextPart
| ReasoningPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart;PartEncoded type
Encoded representation of non-streaming response parts for serialization.
Signature
type PartEncoded =
| TextPartEncoded
| ReasoningPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded;ProviderMetadata type
Signature
type ProviderMetadata = typeof ProviderMetadata.Type;ReasoningDeltaPart interface
Response part containing incremental reasoning content to be added to the existing chunk of reasoning text with the same unique identifier.
Signature
interface ReasoningDeltaPart extends BasePart<"reasoning-delta", ReasoningDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}ReasoningDeltaPartEncoded interface
Encoded representation of reasoning delta parts for serialization.
Signature
interface ReasoningDeltaPartEncoded extends BasePartEncoded<
"reasoning-delta",
ReasoningDeltaPartMetadata
> {
readonly delta: string;
readonly id: string;
}ReasoningEndPart interface
Response part indicating the end of streaming reasoning content.
Marks the completion of a chunk of reasoning content.
Signature
interface ReasoningEndPart extends BasePart<"reasoning-end", ReasoningEndPartMetadata> {
readonly id: string;
}ReasoningEndPartEncoded interface
Encoded representation of reasoning end parts for serialization.
Signature
interface ReasoningEndPartEncoded extends BasePartEncoded<
"reasoning-end",
ReasoningEndPartMetadata
> {
readonly id: string;
}ReasoningPart interface
Response part representing reasoning or chain-of-thought content.
Contains the internal reasoning process or explanation from the large language model.
Signature
interface ReasoningPart extends BasePart<"reasoning", ReasoningPartMetadata> {
readonly text: string;
}Example
import { Response } from "@effect/ai"
const reasoningPart: Response.ReasoningPart = Response.makePart("reasoning", {
text: "Let me think step by step: First I need to analyze the user's question...",
})ReasoningPartEncoded interface
Encoded representation of reasoning parts for serialization.
Signature
interface ReasoningPartEncoded extends BasePartEncoded<"reasoning", ReasoningPartMetadata> {
readonly text: string;
}ReasoningStartPart interface
Response part indicating the start of streaming reasoning content.
Marks the beginning of a reasoning chunk with a unique identifier.
Signature
interface ReasoningStartPart extends BasePart<"reasoning-start", ReasoningStartPartMetadata> {
readonly id: string;
}ReasoningStartPartEncoded interface
Encoded representation of reasoning start parts for serialization.
Signature
interface ReasoningStartPartEncoded extends BasePartEncoded<
"reasoning-start",
ReasoningStartPartMetadata
> {
readonly id: string;
}ResponseMetadataPart interface
Response part containing metadata about the large language model response.
Signature
interface ResponseMetadataPart extends BasePart<"response-metadata", ResponseMetadataPartMetadata> {
readonly id: Option<string>;
readonly modelId: Option<string>;
readonly timestamp: Option<Utc>;
}Example
import { Response } from "@effect/ai"
import { Option, DateTime } from "effect"
const metadataPart: Response.ResponseMetadataPart = Response.makePart("response-metadata", {
id: Option.some("resp_123"),
modelId: Option.some("gpt-4"),
timestamp: Option.some(DateTime.unsafeNow()),
})ResponseMetadataPartEncoded interface
Encoded representation of response metadata parts for serialization.
Signature
interface ResponseMetadataPartEncoded extends BasePartEncoded<
"response-metadata",
ResponseMetadataPartMetadata
> {
readonly id?: string;
readonly modelId?: string;
readonly timestamp?: string;
}StreamPart type
A type for representing streaming response parts with tool-specific typing.
Signature
type StreamPart<Tools extends Record<string, Tool.Any>> =
| TextStartPart
| TextDeltaPart
| TextEndPart
| ReasoningStartPart
| ReasoningDeltaPart
| ReasoningEndPart
| ToolParamsStartPart
| ToolParamsDeltaPart
| ToolParamsEndPart
| ToolCallParts<Tools>
| ToolResultParts<Tools>
| FilePart
| DocumentSourcePart
| UrlSourcePart
| ResponseMetadataPart
| FinishPart
| ErrorPart;StreamPartEncoded type
Encoded representation of streaming response parts for serialization.
Signature
type StreamPartEncoded =
| TextStartPartEncoded
| TextDeltaPartEncoded
| TextEndPartEncoded
| ReasoningStartPartEncoded
| ReasoningDeltaPartEncoded
| ReasoningEndPartEncoded
| ToolParamsStartPartEncoded
| ToolParamsDeltaPartEncoded
| ToolParamsEndPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| FilePartEncoded
| DocumentSourcePartEncoded
| UrlSourcePartEncoded
| ResponseMetadataPartEncoded
| FinishPartEncoded
| ErrorPartEncoded;TextDeltaPart interface
Response part containing incremental text content to be added to the existing text chunk with the same unique identifier.
Signature
interface TextDeltaPart extends BasePart<"text-delta", TextDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}TextDeltaPartEncoded interface
Encoded representation of text delta parts for serialization.
Signature
interface TextDeltaPartEncoded extends BasePartEncoded<"text-delta", TextDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}TextEndPart interface
Response part indicating the end of streaming text content.
Marks the completion of a text chunk.
Signature
interface TextEndPart extends BasePart<"text-end", TextEndPartMetadata> {
readonly id: string;
}TextEndPartEncoded interface
Encoded representation of text end parts for serialization.
Signature
interface TextEndPartEncoded extends BasePartEncoded<"text-end", TextEndPartMetadata> {
readonly id: string;
}Response part representing plain text content.
Signature
interface TextPart extends BasePart<"text", TextPartMetadata> {
readonly text: string;
}Example
import { Response } from "@effect/ai"
const textPart: Response.TextPart = Response.makePart("text", {
text: "The answer to your question is 42.",
})TextPartEncoded interface
Encoded representation of text parts for serialization.
Signature
interface TextPartEncoded extends BasePartEncoded<"text", TextPartMetadata> {
readonly text: string;
}TextStartPart interface
Response part indicating the start of streaming text content.
Marks the beginning of a text chunk with a unique identifier.
Signature
interface TextStartPart extends BasePart<"text-start", TextStartPartMetadata> {
readonly id: string;
}TextStartPartEncoded interface
Encoded representation of text start parts for serialization.
Signature
interface TextStartPartEncoded extends BasePartEncoded<"text-start", TextStartPartMetadata> {
readonly id: string;
}ToolCallPart interface
Response part representing a tool call request.
Signature
interface ToolCallPart<Name extends string, Params> extends BasePart<
"tool-call",
ToolCallPartMetadata
> {
readonly id: string;
readonly name: Name;
readonly params: Params;
readonly providerExecuted: boolean;
readonly providerName?: string;
}Example
import { Response } from "@effect/ai"
import { Schema } from "effect"
const weatherParams = Schema.Struct({
city: Schema.String,
units: Schema.optional(Schema.Literal("celsius", "fahrenheit")),
})
const toolCallPart: Response.ToolCallPart<"get_weather", typeof weatherParams.fields> =
Response.makePart("tool-call", {
id: "call_123",
name: "get_weather",
params: { city: "San Francisco", units: "celsius" },
providerExecuted: false,
})ToolCallPartEncoded interface
Encoded representation of tool call parts for serialization.
Signature
interface ToolCallPartEncoded extends BasePartEncoded<"tool-call", ToolCallPartMetadata> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted?: boolean;
readonly providerName?: string;
}ToolParamsDeltaPart interface
Response part containing incremental tool parameter content.
Represents a chunk of tool parameters being streamed, containing the incremental JSON content that forms the tool parameters.
Signature
interface ToolParamsDeltaPart extends BasePart<"tool-params-delta", ToolParamsDeltaPartMetadata> {
readonly delta: string;
readonly id: string;
}ToolParamsDeltaPartEncoded interface
Encoded representation of tool params delta parts for serialization.
Signature
interface ToolParamsDeltaPartEncoded extends BasePartEncoded<
"tool-params-delta",
ToolParamsDeltaPartMetadata
> {
readonly delta: string;
readonly id: string;
}ToolParamsEndPart interface
Response part indicating the end of streaming tool parameters.
Marks the completion of a tool parameter stream, indicating that all parameter data has been sent and the tool call is ready to be executed.
Signature
interface ToolParamsEndPart extends BasePart<"tool-params-end", ToolParamsEndPartMetadata> {
readonly id: string;
}ToolParamsEndPartEncoded interface
Encoded representation of tool params end parts for serialization.
Signature
interface ToolParamsEndPartEncoded extends BasePartEncoded<
"tool-params-end",
ToolParamsEndPartMetadata
> {
readonly id: string;
}ToolParamsStartPart interface
Response part indicating the start of streaming tool parameters.
Marks the beginning of tool parameter streaming with metadata about the tool call.
Signature
interface ToolParamsStartPart extends BasePart<"tool-params-start", ToolParamsStartPartMetadata> {
readonly id: string;
readonly name: string;
readonly providerExecuted: boolean;
readonly providerName?: string;
}ToolParamsStartPartEncoded interface
Encoded representation of tool params start parts for serialization.
Signature
interface ToolParamsStartPartEncoded extends BasePartEncoded<
"tool-params-start",
ToolParamsStartPartMetadata
> {
readonly id: string;
readonly name: string;
readonly providerExecuted?: boolean;
readonly providerName?: string;
}ToolResultFailure interface
Represents a failed tool call result.
Signature
interface ToolResultFailure<Name extends string, Failure> extends BaseToolResult<Name> {
readonly isFailure: true;
readonly result: Failure;
}ToolResultPart type
Response part representing the result of a tool call.
Signature
type ToolResultPart<Name extends string, Success, Failure> =
| ToolResultSuccess<Name, Success>
| ToolResultFailure<Name, Failure>;Example
import { Either } from "effect"
import { Response } from "@effect/ai"
interface WeatherData {
temperature: number
condition: string
humidity: number
}
const toolResultPart: Response.ToolResultPart<"get_weather", WeatherData, never> =
Response.toolResultPart({
id: "call_123",
name: "get_weather",
isFailure: false,
result: {
temperature: 22,
condition: "sunny",
humidity: 65,
},
encodedResult: {
temperature: 22,
condition: "sunny",
humidity: 65,
},
providerExecuted: false,
})ToolResultPartEncoded interface
Encoded representation of tool result parts for serialization.
Signature
interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", ToolResultPartMetadata> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly providerExecuted?: boolean;
readonly providerName?: string;
readonly result: unknown;
}ToolResultSuccess interface
Represents a successful tool call result.
Signature
interface ToolResultSuccess<Name extends string, Success> extends BaseToolResult<Name> {
readonly isFailure: false;
readonly result: Success;
}UrlSourcePart interface
Response part representing a URL source reference.
Used to reference web URLs that were used in generating the response.
Signature
interface UrlSourcePart extends BasePart<"source", UrlSourcePartMetadata> {
readonly id: string;
readonly sourceType: "url";
readonly title: string;
readonly url: URL;
}UrlSourcePartEncoded interface
Encoded representation of URL source parts for serialization.
Signature
interface UrlSourcePartEncoded extends BasePartEncoded<"source", UrlSourcePartMetadata> {
readonly id: string;
readonly sourceType: "url";
readonly title: string;
readonly url: string;
}Represents usage information for a request to a large language model provider.
If the model provider returns additional usage information than what is specified here, you can generally find that information under the provider metadata of the finish part of the response.
Signature
declare class Usage extends {
readonly cachedInputTokens?: number;
readonly inputTokens: number | undefined;
readonly outputTokens: number | undefined;
readonly reasoningTokens?: number;
readonly totalTokens: number | undefined;
} {
constructor(...args: [props: {
readonly cachedInputTokens?: number;
readonly inputTokens: number | undefined;
readonly outputTokens: number | undefined;
readonly reasoningTokens?: number;
readonly totalTokens: number | undefined;
}, options?: MakeOptions]);
}ProviderOptions
DocumentSourcePartMetadata interface
Represents provider-specific metadata that can be associated with a DocumentSourcePart through module augmentation.
Signature
interface DocumentSourcePartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ErrorPartMetadata interface
Represents provider-specific metadata that can be associated with a ErrorPart through module augmentation.
Signature
interface ErrorPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}FilePartMetadata interface
Represents provider-specific metadata that can be associated with a FilePart through module augmentation.
Signature
interface FilePartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}FinishPartMetadata interface
Represents provider-specific metadata that can be associated with a FinishPart through module augmentation.
Signature
interface FinishPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ReasoningDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningDeltaPart through module augmentation.
Signature
interface ReasoningDeltaPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ReasoningEndPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningEndPart through module augmentation.
Signature
interface ReasoningEndPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ReasoningPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningPart through module augmentation.
Signature
interface ReasoningPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ReasoningStartPartMetadata interface
Represents provider-specific metadata that can be associated with a ReasoningStartPart through module augmentation.
Signature
interface ReasoningStartPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ResponseMetadataPartMetadata interface
Represents provider-specific metadata that can be associated with a ResponseMetadataPart through module augmentation.
Signature
interface ResponseMetadataPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}TextDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a TextDeltaPart through module augmentation.
Signature
interface TextDeltaPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}TextEndPartMetadata interface
Represents provider-specific metadata that can be associated with a TextEndPart through module augmentation.
Signature
interface TextEndPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}TextPartMetadata interface
Represents provider-specific metadata that can be associated with a TextPart through module augmentation.
Signature
interface TextPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}TextStartPartMetadata interface
Represents provider-specific metadata that can be associated with a TextStartPart through module augmentation.
Signature
interface TextStartPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ToolCallPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolCallPart through module augmentation.
Signature
interface ToolCallPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ToolParamsDeltaPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsDeltaPart through module augmentation.
Signature
interface ToolParamsDeltaPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ToolParamsEndPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsEndPart through module augmentation.
Signature
interface ToolParamsEndPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ToolParamsStartPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolParamsStartPart through module augmentation.
Signature
interface ToolParamsStartPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}ToolResultPartMetadata interface
Represents provider-specific metadata that can be associated with a ToolResultPart through module augmentation.
Signature
interface ToolResultPartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}UrlSourcePartMetadata interface
Represents provider-specific metadata that can be associated with a UrlSourcePart through module augmentation.
Signature
interface UrlSourcePartMetadata extends ProviderMetadata {
[key: string]: unknown;
[key: number]: unknown;
[key: symbol]: unknown;
}Schemas
Creates a Schema for all response parts based on a toolkit.
Generates a schema that includes all possible response parts, with tool call and tool result parts dynamically created based on the provided toolkit.
Signature
declare const AllParts: <T extends WithHandler<any> | Any>(toolkit: T) => any;Example
import { Response, Tool, Toolkit } from "@effect/ai"
import { Schema } from "effect"
const myToolkit = Toolkit.make(
Tool.make("GetWeather", {
parameters: { city: Schema.String },
success: Schema.Struct({ temperature: Schema.Number }),
}),
)
const allPartsSchema = Response.AllParts(myToolkit)DocumentSourcePart
Schema for validation and encoding of document source parts.
Signature
declare const DocumentSourcePart: any;Schema for validation and encoding of error parts.
Signature
declare const ErrorPart: any;Schema for validation and encoding of file parts.
Signature
declare const FilePart: any;FinishPart
Schema for validation and encoding of finish parts.
Signature
declare const FinishPart: any;Creates a Schema for non-streaming response parts based on a toolkit.
Signature
declare const Part: <T extends WithHandler<any> | Any>(toolkit: T) => any;ProviderMetadata
Schema for provider-specific metadata which can be attached to response parts.
Provider-specific metadata is namespaced by provider and has the structure:
Signature
declare const ProviderMetadata: $Record<Key, Constraint>;Example
{
"<provider-specific-key>": {
// Provider-specific metadata
}
}ReasoningDeltaPart
Schema for validation and encoding of reasoning delta parts.
Signature
declare const ReasoningDeltaPart: any;ReasoningEndPart
Schema for validation and encoding of reasoning end parts.
Signature
declare const ReasoningEndPart: any;ReasoningPart
Schema for validation and encoding of reasoning parts.
Signature
declare const ReasoningPart: any;ReasoningStartPart
Schema for validation and encoding of reasoning start parts.
Signature
declare const ReasoningStartPart: any;ResponseMetadataPart
Schema for validation and encoding of response metadata parts.
Signature
declare const ResponseMetadataPart: any;StreamPart
Creates a Schema for streaming response parts based on a toolkit.
Signature
declare const StreamPart: <T extends WithHandler<any> | Any>(toolkit: T) => any;TextDeltaPart
Schema for validation and encoding of text delta parts.
Signature
declare const TextDeltaPart: any;TextEndPart
Schema for validation and encoding of text end parts.
Signature
declare const TextEndPart: any;Schema for validation and encoding of text parts.
Signature
declare const TextPart: any;TextStartPart
Schema for validation and encoding of text start parts.
Signature
declare const TextStartPart: any;ToolCallPart
Creates a Schema for tool call parts with specific tool name and parameters.
Signature
declare const ToolCallPart: <Name extends string, Params extends AnyParametersSchema>(
name: Name,
params: Params,
) => any;ToolParamsDeltaPart
Schema for validation and encoding of tool params delta parts.
Signature
declare const ToolParamsDeltaPart: any;ToolParamsEndPart
Schema for validation and encoding of tool params end parts.
Signature
declare const ToolParamsEndPart: any;ToolParamsStartPart
Schema for validation and encoding of tool params start parts.
Signature
declare const ToolParamsStartPart: any;ToolResultPart
Creates a Schema for tool result parts with specific tool name and result type.
Signature
declare const ToolResultPart: <Name extends string, Success extends Any, Failure extends All>(
name: Name,
success: Success,
failure: Failure,
) => any;UrlSourcePart
Schema for validation and encoding of url source parts.
Signature
declare const UrlSourcePart: any;Type Ids
PartTypeId
Unique identifier for Response Part instances.
Signature
declare const PartTypeId: "~effect/ai/Content/Part";PartTypeId type
Type-level representation of the Response Part identifier.
Signature
type PartTypeId = typeof PartTypeId;Utility Types
ConstructorParams type
A utility type for specifying the parameters required to construct a specific response part.
Signature
type ConstructorParams<Part extends AnyPart> = Omit<
Part,
PartTypeId | "type" | "sourceType" | "metadata"
> & {
readonly metadata?: Part["metadata"];
};ToolCallParts type
Utility type that extracts tool call parts from a set of tools.
Signature
type ToolCallParts<Tools extends Record<string, Tool.Any>> = {
[Name in keyof Tools]: Name extends string
? ToolCallPart<Name, Tool.Parameters<Tools[Name]>>
: never;
}[keyof Tools];ToolResultParts type
Utility type that extracts tool result parts from a set of tools.
Signature
type ToolResultParts<Tools extends Record<string, Tool.Any>> = {
[Name in keyof Tools]: Name extends string
? ToolResultPart<Name, Tool.Success<Tools[Name]>, Tool.Failure<Tools[Name]>>
: never;
}[keyof Tools];
Constructs a new document source part.