Prompt
Defines prompts sent to AI language models.
A prompt is an ordered list of messages. Messages can use roles such as system, user, assistant, and tool, and their content can be split into typed parts such as text, files, reasoning, tool calls, tool results, and approval messages. This module helps build prompts, combine them, and convert raw input or response parts into the shared prompt shape.
Combinators
appendSystem
Signature
declare const appendSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
};Concatenates a prompt with additional raw input by concatenating messages.
Details
The returned prompt contains all messages from the original prompt followed by the provided raw input, preserving message order.
Signature
declare const concat: {
(input: RawInput): (self: Prompt) => Prompt;
(self: Prompt, input: RawInput): Prompt;
};prependSystem
Creates a new prompt with a leading system message. If the prompt already has a system message, the new message uses the provided content prepended to the first existing system message's content; the original messages remain after it.
Signature
declare const prependSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
};Creates a new prompt from the specified prompt with the system message set to the specified text content.
Gotchas
This method removes and replaces any previous system message from the prompt.
Signature
declare const setSystem: {
(content: string): (self: Prompt) => Prompt;
(self: Prompt, content: string): Prompt;
};Constructors
assistantMessage
Constructs a new assistant message.
When to use
Use to add assistant-role prompt history or model responses.
Details
This is the role-specific wrapper around makeMessage("assistant", params).
Signature
declare function assistantMessage(
params: MessageConstructorParams<AssistantMessage>,
): AssistantMessage;An empty prompt with no messages.
Signature
declare const empty: Prompt;Constructs a FilePart for prompt file attachments.
When to use
Use to create the file-attachment part of a prompt from typed file part parameters.
See
makePartfor the generic part constructor
Signature
declare function filePart(params: PartConstructorParams<FilePart>): FilePart;fromMessages
Creates a Prompt from an array of messages.
Signature
declare function fromMessages(messages: readonly Array<Message>): PromptfromResponseParts
Creates a Prompt from response parts by folding completed text and reasoning streams into assistant parts, placing tool calls and approval requests in an assistant message, and placing non-preliminary tool results in a tool message using their encoded results.
Signature
declare function fromResponseParts(parts: readonly Array<AnyPart>): PromptCreates a Prompt from an input.
Details
This is the primary constructor for creating prompts, supporting multiple input formats for convenience and flexibility.
Signature
declare function make(input: RawInput): Prompt;makeMessage
Creates a new message with the specified role.
Signature
declare function makeMessage<Role extends "tool" | "user" | "assistant" | "system">(
role: Role,
params: Omit<
| Extract<
SystemMessage,
{
role: Role;
}
>
| Extract<
UserMessage,
{
role: Role;
}
>
| Extract<
AssistantMessage,
{
role: Role;
}
>
| Extract<
ToolMessage,
{
role: Role;
}
>,
"role" | "options" | "~effect/ai/Prompt/Message"
> & {
readonly options?:
| Extract<
SystemMessage,
{
role: Role;
}
>
| Extract<
UserMessage,
{
role: Role;
}
>
| Extract<
AssistantMessage,
{
role: Role;
}
>
| Extract<
ToolMessage,
{
role: Role;
}
>["options"];
},
):
| Extract<
SystemMessage,
{
role: Role;
}
>
| Extract<
UserMessage,
{
role: Role;
}
>
| Extract<
AssistantMessage,
{
role: Role;
}
>
| Extract<
ToolMessage,
{
role: Role;
}
>;Creates a new content part of the specified type.
Signature
declare function makePart<
Type extends
| "tool-approval-request"
| "file"
| "text"
| "reasoning"
| "tool-call"
| "tool-result"
| "tool-approval-response",
>(
type: Type,
params: Omit<
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
ToolCallPart,
{
type: Type;
}
>
| Extract<
ToolResultPart,
{
type: Type;
}
>
| Extract<
ToolApprovalResponsePart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>,
"type" | "~effect/ai/Prompt/Part" | "options"
> & {
readonly options?:
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
ToolCallPart,
{
type: Type;
}
>
| Extract<
ToolResultPart,
{
type: Type;
}
>
| Extract<
ToolApprovalResponsePart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>["options"];
},
):
| Extract<
TextPart,
{
type: Type;
}
>
| Extract<
ReasoningPart,
{
type: Type;
}
>
| Extract<
FilePart,
{
type: Type;
}
>
| Extract<
ToolCallPart,
{
type: Type;
}
>
| Extract<
ToolResultPart,
{
type: Type;
}
>
| Extract<
ToolApprovalResponsePart,
{
type: Type;
}
>
| Extract<
ToolApprovalRequestPart,
{
type: Type;
}
>;reasoningPart
Constructs a new reasoning part.
Signature
declare function reasoningPart(params: PartConstructorParams<ReasoningPart>): ReasoningPart;systemMessage
Constructs a new system message.
Signature
declare function systemMessage(params: MessageConstructorParams<SystemMessage>): SystemMessage;Constructs a new text part.
Signature
declare function textPart(params: PartConstructorParams<TextPart>): TextPart;toolApprovalRequestPart
Constructs a new tool approval request part.
Signature
declare function toolApprovalRequestPart(
params: PartConstructorParams<ToolApprovalRequestPart>,
): ToolApprovalRequestPart;toolApprovalResponsePart
Constructs a new tool approval response part.
Signature
declare function toolApprovalResponsePart(
params: PartConstructorParams<ToolApprovalResponsePart>,
): ToolApprovalResponsePart;toolCallPart
Constructs a new tool call part.
Signature
declare function toolCallPart(params: PartConstructorParams<ToolCallPart>): ToolCallPart;toolMessage
Constructs a new tool message.
Signature
declare function toolMessage(params: MessageConstructorParams<ToolMessage>): ToolMessage;toolResultPart
Constructs a new tool result part.
Signature
declare function toolResultPart(params: PartConstructorParams<ToolResultPart>): ToolResultPart;userMessage
Constructs a new user message.
Signature
declare function userMessage(params: MessageConstructorParams<UserMessage>): UserMessage;Guards
Type guard to check if a value is a Message.
Signature
declare function isMessage(u: unknown): u is Message;Type guard to check if a value is a Part.
Signature
declare function isPart(u: unknown): u is Part;Type guard to check if a value is a Prompt.
Signature
declare function isPrompt(u: unknown): u is Prompt;Models
AssistantMessage interface
Message representing large language model assistant responses.
Signature
interface AssistantMessage extends BaseMessage<"assistant", AssistantMessageOptions> {
readonly content: readonly Array<AssistantMessagePart>;
}AssistantMessageEncoded interface
Encoded representation of assistant messages for serialization.
Signature
interface AssistantMessageEncoded extends BaseMessageEncoded<"assistant", AssistantMessageOptions> {
readonly content: string | readonly Array<AssistantMessagePartEncoded>;
}AssistantMessagePart type
Union type of content parts allowed in assistant messages.
Signature
type AssistantMessagePart =
| TextPart
| FilePart
| ReasoningPart
| ToolCallPart
| ToolResultPart
| ToolApprovalRequestPart;AssistantMessagePartEncoded type
Union type of encoded content parts for assistant messages.
Signature
type AssistantMessagePartEncoded =
| TextPartEncoded
| FilePartEncoded
| ReasoningPartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalRequestPartEncoded;BaseMessage interface
Base interface for all message types.
Details
It provides the common structure shared by all messages, including the role and provider options.
Signature
interface BaseMessage<Role extends string, Options extends ProviderOptions> {
readonly "~effect/ai/Prompt/Message": "~effect/ai/Prompt/Message";
readonly options: Options;
readonly role: Role;
}BaseMessageEncoded interface
Base interface for encoded message types.
Signature
interface BaseMessageEncoded<Role extends string, Options extends ProviderOptions> {
readonly options?: Options;
readonly role: Role;
}Base interface for all content parts.
Details
It provides the common structure shared by all content parts, including the part type and provider options.
Signature
interface BasePart<Type extends string, Options extends ProviderOptions> {
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
readonly options: Options;
readonly type: Type;
}BasePartEncoded interface
Base interface for encoded content parts.
Signature
interface BasePartEncoded<Type extends string, Options extends ProviderOptions> {
readonly options?: Options;
readonly type: Type;
}Content part representing a file attachment.
Details
Files can be provided as base64 data strings, byte arrays, or URLs, and can represent images, documents, or other binary data.
Signature
interface FilePart extends BasePart<"file", FilePartOptions> {
readonly data: string | Uint8Array<ArrayBufferLike> | URL;
readonly fileName?: string;
readonly mediaType: string;
}FilePartEncoded interface
Encoded representation of file parts for serialization.
Signature
interface FilePartEncoded extends BasePartEncoded<"file", FilePartOptions> {
readonly data: string | Uint8Array<ArrayBufferLike> | URL;
readonly fileName?: string;
readonly mediaType: string;
}A type representing all possible message types in a conversation.
Signature
type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;MessageEncoded type
A type representing all possible encoded message types for serialization.
Signature
type MessageEncoded =
| SystemMessageEncoded
| UserMessageEncoded
| AssistantMessageEncoded
| ToolMessageEncoded;Union type representing all possible content parts within messages.
Details
Parts are the building blocks of message content, supporting text, files, reasoning, tool calls, tool results, tool approval responses, and tool approval requests.
Signature
type Part =
| TextPart
| ReasoningPart
| FilePart
| ToolCallPart
| ToolResultPart
| ToolApprovalResponsePart
| ToolApprovalRequestPart;PartEncoded type
Encoded representation of a Part.
Signature
type PartEncoded =
| TextPartEncoded
| ReasoningPartEncoded
| FilePartEncoded
| ToolCallPartEncoded
| ToolResultPartEncoded
| ToolApprovalResponsePartEncoded
| ToolApprovalRequestPartEncoded;A Prompt contains a sequence of messages that form the context of a conversation with a large language model.
Signature
interface Prompt extends Pipeable {
readonly "~effect/unstable/ai/Prompt": "~effect/unstable/ai/Prompt";
readonly content: readonly Array<Message>;
}PromptEncoded interface
Encoded representation of prompts for serialization.
Signature
interface PromptEncoded {
readonly content: readonly Array<MessageEncoded>;
}Raw input accepted by make: a string, an iterable of encoded messages, or an existing Prompt.
Signature
type RawInput = string | Iterable<MessageEncoded> | Prompt;ReasoningPart interface
Content part carrying reasoning text in an assistant message, such as a provider-supplied reasoning summary or explanation.
Signature
interface ReasoningPart extends BasePart<"reasoning", ReasoningPartOptions> {
readonly text: string;
}ReasoningPartEncoded interface
Encoded representation of reasoning parts for serialization.
Signature
interface ReasoningPartEncoded extends BasePartEncoded<"reasoning", ReasoningPartOptions> {
readonly text: string;
}SystemMessage interface
Message representing system instructions or context.
Signature
interface SystemMessage extends BaseMessage<"system", SystemMessageOptions> {
readonly content: string;
}SystemMessageEncoded interface
Encoded representation of system messages for serialization.
Signature
interface SystemMessageEncoded extends BaseMessageEncoded<"system", SystemMessageOptions> {
readonly content: string;
}Content part representing plain text.
Details
Text parts are the basic content type used for textual information in messages.
Signature
interface TextPart extends BasePart<"text", TextPartOptions> {
readonly text: string;
}TextPartEncoded interface
Encoded representation of text parts for serialization.
Signature
interface TextPartEncoded extends BasePartEncoded<"text", TextPartOptions> {
readonly text: string;
}ToolApprovalRequestPart interface
Content part representing a tool approval request from the framework.
Details
Tool approval request parts are stored in assistant messages when a tool requires user approval before execution. The user responds with a ToolApprovalResponsePart in a tool message.
Signature
interface ToolApprovalRequestPart extends BasePart<
"tool-approval-request",
ToolApprovalRequestPartOptions
> {
readonly approvalId: string;
readonly toolCallId: string;
}ToolApprovalRequestPartEncoded interface
Encoded representation of tool approval request parts for serialization.
Signature
interface ToolApprovalRequestPartEncoded extends BasePartEncoded<
"tool-approval-request",
ToolApprovalRequestPartOptions
> {
readonly approvalId: string;
readonly toolCallId: string;
}ToolApprovalResponsePart interface
Content part representing a user's response to a tool approval request.
When to use
Use when tool messages must approve or deny tool execution for tools with the needsApproval property set.
Signature
interface ToolApprovalResponsePart extends BasePart<
"tool-approval-response",
ToolApprovalResponsePartOptions
> {
readonly approvalId: string;
readonly approved: boolean;
readonly reason?: string;
}ToolApprovalResponsePartEncoded interface
Encoded representation of tool approval response parts for serialization.
Signature
interface ToolApprovalResponsePartEncoded extends BasePartEncoded<
"tool-approval-response",
ToolApprovalResponsePartOptions
> {
readonly approvalId: string;
readonly approved: boolean;
readonly reason?: string;
}ToolCallPart interface
Content part representing a tool call request.
Signature
interface ToolCallPart extends BasePart<"tool-call", ToolCallPartOptions> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted: boolean;
}ToolCallPartEncoded interface
Encoded representation of tool call parts for serialization.
Signature
interface ToolCallPartEncoded extends BasePartEncoded<"tool-call", ToolCallPartOptions> {
readonly id: string;
readonly name: string;
readonly params: unknown;
readonly providerExecuted?: boolean;
}ToolMessage interface
Message carrying tool-side content, including tool execution results and responses to tool approval requests.
Signature
interface ToolMessage extends BaseMessage<"tool", ToolMessageOptions> {
readonly content: readonly Array<ToolMessagePart>;
}ToolMessageEncoded interface
Encoded representation of tool messages for serialization.
Signature
interface ToolMessageEncoded extends BaseMessageEncoded<"tool", ToolMessageOptions> {
readonly content: readonly Array<ToolMessagePartEncoded>;
}ToolMessagePart type
Union type of content parts allowed in tool messages.
Signature
type ToolMessagePart = ToolResultPart | ToolApprovalResponsePart;ToolMessagePartEncoded type
Union type of encoded content parts for tool messages.
Signature
type ToolMessagePartEncoded = ToolResultPartEncoded | ToolApprovalResponsePartEncoded;ToolResultPart interface
Content part representing the result of a tool call.
Signature
interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOptions> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly providerExecuted: boolean;
readonly result: unknown;
}ToolResultPartEncoded interface
Encoded representation of tool result parts for serialization.
Signature
interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", ToolResultPartOptions> {
readonly id: string;
readonly isFailure: boolean;
readonly name: string;
readonly providerExecuted?: boolean;
readonly result: unknown;
}UserMessage interface
Message representing user input or questions.
Signature
interface UserMessage extends BaseMessage<"user", UserMessageOptions> {
readonly content: readonly Array<UserMessagePart>;
}UserMessageEncoded interface
Encoded representation of user messages for serialization.
Signature
interface UserMessageEncoded extends BaseMessageEncoded<"user", UserMessageOptions> {
readonly content: string | readonly Array<UserMessagePartEncoded>;
}UserMessagePart type
Union type of content parts allowed in user messages.
Signature
type UserMessagePart = TextPart | FilePart;UserMessagePartEncoded type
Union type of encoded content parts for user messages.
Signature
type UserMessagePartEncoded = TextPartEncoded | FilePartEncoded;Options
AssistantMessageOptions interface
Represents provider-specific options that can be associated with a AssistantMessage through module augmentation.
Signature
interface AssistantMessageOptions extends ProviderOptions {
[key: string]: Json;
}FilePartOptions interface
Represents provider-specific options that can be associated with a FilePart through module augmentation.
Signature
interface FilePartOptions extends ProviderOptions {
[key: string]: Json;
}ProviderOptions
Schema for provider-specific options that can be attached to content parts and messages.
Details
Provider-specific options are keyed by provider-specific names, and each value is JSON or null.
Signature
declare const ProviderOptions: Schema.$Record<
Schema.String,
Schema.NullOr<Schema.Codec<Schema.Json>>
>;ProviderOptions type
Type of provider-specific options that can be attached to prompt messages and content parts.
Signature
type ProviderOptions = typeof ProviderOptions.Type;ReasoningPartOptions interface
Represents provider-specific options that can be associated with a ReasoningPart through module augmentation.
Signature
interface ReasoningPartOptions extends ProviderOptions {
[key: string]: Json;
}SystemMessageOptions interface
Represents provider-specific options that can be associated with a SystemMessage through module augmentation.
Signature
interface SystemMessageOptions extends ProviderOptions {
[key: string]: Json;
}TextPartOptions interface
Represents provider-specific options that can be associated with a TextPart through module augmentation.
Signature
interface TextPartOptions extends ProviderOptions {
[key: string]: Json;
}ToolApprovalRequestPartOptions interface
Represents provider-specific options that can be associated with a ToolApprovalRequestPart through module augmentation.
Signature
interface ToolApprovalRequestPartOptions extends ProviderOptions {
[key: string]: Json;
}ToolApprovalResponsePartOptions interface
Represents provider-specific options that can be associated with a ToolApprovalResponsePart through module augmentation.
Signature
interface ToolApprovalResponsePartOptions extends ProviderOptions {
[key: string]: Json;
}ToolCallPartOptions interface
Represents provider-specific options that can be associated with a ToolCallPart through module augmentation.
Signature
interface ToolCallPartOptions extends ProviderOptions {
[key: string]: Json;
}ToolMessageOptions interface
Represents provider-specific options that can be associated with a ToolMessage through module augmentation.
Signature
interface ToolMessageOptions extends ProviderOptions {
[key: string]: Json;
}ToolResultPartOptions interface
Represents provider-specific options that can be associated with a ToolResultPart through module augmentation.
Signature
interface ToolResultPartOptions extends ProviderOptions {
[key: string]: Json;
}UserMessageOptions interface
Represents provider-specific options that can be associated with a UserMessage through module augmentation.
Signature
interface UserMessageOptions extends ProviderOptions {
[key: string]: Json;
}Schemas
AssistantMessage
Schema for validation and encoding of assistant messages.
Details
Assistant content can be a string decoded through ContentFromString or an array of text, file, reasoning, tool-call, tool-result, and tool-approval-request parts.
Signature
declare const AssistantMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: Union<readonly [decodeTo<NonEmptyArray<toType<Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>>>, String, never, never>, $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly data: Union<readonly [..., ..., ...]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly type: Literal<"file">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>]>>]>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"assistant">;
}>AssistantMessagePart
Schema for validation and encoding of assistant message content parts.
Signature
declare const AssistantMessagePart: Union<
readonly [
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly text: String;
readonly type: Literal<"text">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly type: Literal<"file">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>,
]
>;ContentFromString
Schema that decodes a string into content containing a single TextPart and, when encoding, emits the text value of the first part.
Signature
declare const ContentFromString: Schema.decodeTo<
Schema.NonEmptyArray<
Schema.toType<
Schema.Struct<{
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<
Schema.Literal<"~effect/ai/Prompt/Part">
>;
readonly options: Schema.withDecodingDefault<
Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>
>;
readonly text: Schema.String;
readonly type: Schema.Literal<"text">;
}>
>
>,
Schema.String
>;Schema for validation and encoding of file parts.
Signature
declare const FilePart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly type: Literal<"file">;
}>;Schema for validation and encoding of messages.
Signature
declare const Message: Codec<Message, MessageEncoded, never, never>;Schema for validation and encoding of content parts.
Signature
declare const Part: Union<
readonly [
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly text: String;
readonly type: Literal<"text">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly type: Literal<"file">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>,
]
>;Schema for AI prompt instances.
Signature
declare const Prompt: Codec<Prompt, PromptEncoded, never, never>;ReasoningPart
Schema for validation and encoding of reasoning parts.
Signature
declare const ReasoningPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"reasoning">;
}>;SystemMessage
Schema for validation and encoding of system messages.
Signature
declare const SystemMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<
Literal<"~effect/ai/Prompt/Message">
>;
readonly content: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"system">;
}>;Schema for validation and encoding of text parts.
Signature
declare const TextPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly text: String;
readonly type: Literal<"text">;
}>;ToolApprovalRequestPart
Schema for validation and encoding of tool approval request parts.
Signature
declare const ToolApprovalRequestPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly toolCallId: String;
readonly type: Literal<"tool-approval-request">;
}>;ToolApprovalResponsePart
Schema for validation and encoding of tool approval response parts.
Signature
declare const ToolApprovalResponsePart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>;ToolCallPart
Schema for validation and encoding of tool call parts.
Signature
declare const ToolCallPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly params: Unknown;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly type: Literal<"tool-call">;
}>;ToolMessage
Schema for validation and encoding of tool messages.
Signature
declare const ToolMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<..., ..., ..., ...>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<..., ..., ..., ...>>>>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>]>>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"tool">;
}>ToolMessagePart
Schema for validation and encoding of tool message content parts.
Signature
declare const ToolMessagePart: Union<
readonly [
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly approvalId: String;
readonly approved: Boolean;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly reason: optional<String>;
readonly type: Literal<"tool-approval-response">;
}>,
]
>;ToolResultPart
Schema for validation and encoding of tool result parts.
Signature
declare const ToolResultPart: Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly id: String;
readonly isFailure: Boolean;
readonly name: String;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly providerExecuted: withDecodingDefault<Boolean>;
readonly result: Unknown;
readonly type: Literal<"tool-result">;
}>;UserMessage
Schema for validation and encoding of user messages.
Signature
declare const UserMessage: Struct<{
readonly "~effect/ai/Prompt/Message": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Message">>;
readonly content: Union<readonly [decodeTo<NonEmptyArray<toType<Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>>>, String, never, never>, $Array<Union<readonly [Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly text: String;
readonly type: Literal<"text">;
}>, Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<...>>;
readonly data: Union<readonly [..., ..., ...]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<$Record<..., ...>>;
readonly type: Literal<"file">;
}>]>>]>;
readonly options: withDecodingDefault<$Record<String, NullOr<Codec<Json, Json, never, never>>>>;
readonly role: Literal<"user">;
}>UserMessagePart
Schema for validation and encoding of user message content parts.
Signature
declare const UserMessagePart: Union<
readonly [
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly text: String;
readonly type: Literal<"text">;
}>,
Struct<{
readonly "~effect/ai/Prompt/Part": withDecodingDefaultKey<Literal<"~effect/ai/Prompt/Part">>;
readonly data: Union<readonly [String, Uint8Array, URL]>;
readonly fileName: optional<String>;
readonly mediaType: String;
readonly options: withDecodingDefault<
$Record<String, NullOr<Codec<Json, Json, never, never>>>
>;
readonly type: Literal<"file">;
}>,
]
>;Utility Types
MessageConstructorParams type
A utility type for specifying the parameters required to construct a specific message for a prompt.
Signature
type MessageConstructorParams<M extends Message> = Omit<
M,
typeof MessageTypeId | "role" | "options"
> & {
readonly options?: Part["options"];
};PartConstructorParams type
A utility type for specifying the parameters required to construct a specific part of a prompt.
Signature
type PartConstructorParams<P extends Part> = Omit<P, typeof PartTypeId | "type" | "options"> & {
readonly options?: Part["options"];
};
Creates a new prompt with a leading system message. If the prompt already has a system message, the new message uses the provided content appended to the first existing system message's content; the original messages remain after it.