AiResponse.ts overview
Since v1.0.0
Exports Grouped by Category
- Combination
- Constructors
- Guards
- Models
- AiResponse (class)
- Annotation
- Annotation (type alias)
- ContentSourceAnnotation (class)
- FileAnnotation (class)
- FinishPart (class)
- FinishReason
- FinishReason (type alias)
- FromJson
- Part
- Part (type alias)
- ProviderMetadata (interface)
- ReasoningPart (class)
- RedactedReasoningPart (class)
- TextPart (class)
- ToolCallId
- ToolCallId (type alias)
- ToolCallPart (class)
- UrlAnnotation (class)
- Usage (class)
- WithStructuredOutput (class)
- WithToolCallResults (class)
- Type Ids
- utils
Combination
merge
Combines two responses into a single response.
Signature
declare const merge: {
(other: AiResponse): (self: AiResponse) => AiResponse
(self: AiResponse, other: AiResponse): AiResponse
}
Since v1.0.0
withToolCallsJson
Adds the specified tool calls to the provided AiResponse
.
NOTE: With this method, the tool call parameters will be parsed as a JSON string. If your tool call parameters are already parsed, use AiResponse.withToolCallsUnknown
.
Signature
declare const withToolCallsJson: {
(
toolCalls: Iterable<{ readonly id: string; readonly name: string; readonly params: string }>
): (self: AiResponse) => Effect.Effect<AiResponse, AiError>
(
self: AiResponse,
toolCalls: Iterable<{ readonly id: string; readonly name: string; readonly params: string }>
): Effect.Effect<AiResponse, AiError>
}
Since v1.0.0
Constructors
empty
Signature
declare const empty: AiResponse
Since v1.0.0
Guards
hasToolCallResults
Signature
declare const hasToolCallResults: (u: unknown) => u is WithToolCallResults<any>
Since v1.0.0
is
Signature
declare const is: (u: unknown) => u is AiResponse
Since v1.0.0
isPart
Signature
declare const isPart: (u: unknown) => u is Part
Since v1.0.0
isStructured
Signature
declare const isStructured: (u: unknown) => u is WithStructuredOutput<any>
Since v1.0.0
Models
AiResponse (class)
Represents a response received from a large language model.
Signature
declare class AiResponse
Since v1.0.0
getProviderMetadata (method)
Attempts to retrieve provider-specific response metadata.
Signature
declare const getProviderMetadata: <I, S>(tag: Context.Tag<I, S>) => Option.Option<S>
[TypeId] (property)
Signature
readonly [TypeId]: unique symbol
Since v1.0.0
Annotation
Represents annotations that were used to support the message generated by a model.
Signature
declare const Annotation: Schema.Union<[typeof ContentSourceAnnotation, typeof FileAnnotation, typeof UrlAnnotation]>
Since v1.0.0
Annotation (type alias)
Signature
type Annotation = typeof Annotation.Type
Since v1.0.0
ContentSourceAnnotation (class)
Represents a content source that was used to generate a model response.
Signature
declare class ContentSourceAnnotation
Since v1.0.0
FileAnnotation (class)
Represents a file that was used to generate a model response.
Signature
declare class FileAnnotation
Since v1.0.0
FinishPart (class)
Represents the final part of a response generated by a large language model.
Contains useful information such as tokens used as part of the interaction with the model.
Signature
declare class FinishPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0
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."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", "other", "unknown"]
>
Since v1.0.0
FinishReason (type alias)
Signature
type FinishReason = typeof FinishReason.Type
Since v1.0.0
FromJson
Signature
declare const FromJson: Schema.transform<Schema.SchemaClass<unknown, string, never>, typeof AiResponse>
Since v1.0.0
Part
Represents an single part of a response received from a large language model.
Signature
declare const Part: Schema.Union<
[
typeof TextPart,
typeof ReasoningPart,
typeof RedactedReasoningPart,
typeof ToolCallPart,
typeof MetadataPart,
typeof FinishPart
]
>
Since v1.0.0
Part (type alias)
Signature
type Part = typeof Part.Type
Since v1.0.0
ProviderMetadata (interface)
Represents additional provider-specific metadata that was returned by the model. Specific providers will use module augmentation to add their own specific provider metadata.
The outer record is keyed by provider name, while the inner record is keyed by the names of the provider-specific metadata properties.
For example:
const providerMeta = {
"amazon-bedrock": {
// Provider specific metadata
}
}
Signature
export interface ProviderMetadata {}
Since v1.0.0
ReasoningPart (class)
Represents part of the reasoning carried out by the model to generate a response.
Signature
declare class ReasoningPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0
RedactedReasoningPart (class)
Represents part of the reasoning carried out by the model to generate a response which needed to be encrypted by the model provider for safety reasons.
Signature
declare class RedactedReasoningPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0
TextPart (class)
Represents part of the text generated by the model.
Signature
declare class TextPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0
ToolCallId
Represents the identifier generated by a model when a tool call is requested.
Signature
declare const ToolCallId: Schema.brand<typeof Schema.String, "@effect/ai/ToolCallId">
Since v1.0.0
ToolCallId (type alias)
Signature
type ToolCallId = typeof ToolCallId.Type
Since v1.0.0
ToolCallPart (class)
Represents a request by a model to call a specific tool that it has been provided with.
Signature
declare class ToolCallPart
Since v1.0.0
fromJson (static method)
Converts a raw tool call into a ToolCallPart
by parsing tool call parameters as a JSON string. If your tool call parameters are already parsed, use ToolCallPart.fromUnknown
.
Signature
declare const fromJson: ({
id,
name,
params
}: {
readonly id: string
readonly name: string
readonly params: string
}) => Effect.Effect<ToolCallPart, AiError>
Since v1.0.0
fromUnknown (static method)
Converts a raw tool call into a ToolCallPart
assuming that the tool call parameters have already been parsed. If your tool call parameters have not already been parsed, use ToolCallPart.fromJson
.
Signature
declare const fromUnknown: ({
id,
name,
params
}: {
readonly id: string
readonly name: string
readonly params: unknown
}) => ToolCallPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0
UrlAnnotation (class)
Represents a web resource that was used to generate a model response.
Signature
declare class UrlAnnotation
Since v1.0.0
Usage (class)
Represents information about the number of tokens used by the model to generate a response.
Signature
declare class Usage
Since v1.0.0
WithStructuredOutput (class)
Represents a response generated by a large language model that includes structured output.
Signature
declare class WithStructuredOutput<A> {
constructor(
props: {
/**
* The identifier of the tool which generated the structured output.
*/
readonly id: ToolCallId
/**
* The name of the tool which generated the structured output.
*/
readonly name: string
/**
* The structured output generated by the model.
*/
readonly value: A
/**
* The parts of the response.
*/
readonly parts: ReadonlyArray<Part>
},
options?: Schema.MakeOptions
)
}
Since v1.0.0
[StructuredResponseTypeId] (property)
Signature
readonly [StructuredResponseTypeId]: unique symbol
Since v1.0.0
id (property)
The identifier of the tool which generated the structured output.
Signature
readonly id: string & Brand<"@effect/ai/ToolCallId">
name (property)
The name of the tool which generated the structured output.
Signature
readonly name: string
value (property)
The structured output generated by the model.
Signature
readonly value: A
WithToolCallResults (class)
Represents a response generated by a large language model that includes tool call results.
Signature
declare class WithToolCallResults<Tools> {
constructor(
props: {
/**
* The tool call results, represented as a mapping between the tool call
* identifier and the result of the tool call handler.
*/
readonly results: ReadonlyMap<ToolCallId, AiTool.Success<Tools>>
/**
* The encoded tool call results, suitable for incorporation into subsequent
* requests to the large language model.
*/
readonly encodedResults: ReadonlyMap<ToolCallId, unknown>
/**
* The parts of the response.
*/
readonly parts: ReadonlyArray<Part>
},
options?: Schema.MakeOptions
)
}
Since v1.0.0
[WithToolCallResultsTypeId] (property)
Signature
readonly [WithToolCallResultsTypeId]: unique symbol
Since v1.0.0
results (property)
The tool call results, represented as a mapping between the tool call identifier and the result of the tool call handler.
Signature
readonly results: ReadonlyMap<string & Brand<"@effect/ai/ToolCallId">, AiTool.Success<Tools>>
encodedResults (property)
The encoded tool call results, suitable for incorporation into subsequent requests to the large language model.
Signature
readonly encodedResults: ReadonlyMap<string & Brand<"@effect/ai/ToolCallId">, unknown>
Type Ids
PartTypeId
Signature
declare const PartTypeId: unique symbol
Since v1.0.0
PartTypeId (type alias)
Signature
type PartTypeId = typeof PartTypeId
Since v1.0.0
StructuredResponseTypeId
Signature
declare const StructuredResponseTypeId: unique symbol
Since v1.0.0
StructuredResponseTypeId (type alias)
Signature
type StructuredResponseTypeId = typeof StructuredResponseTypeId
Since v1.0.0
TypeId
Signature
declare const TypeId: unique symbol
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v1.0.0
WithToolCallResultsTypeId
Signature
declare const WithToolCallResultsTypeId: unique symbol
Since v1.0.0
WithToolCallResultsTypeId (type alias)
Signature
type WithToolCallResultsTypeId = typeof WithToolCallResultsTypeId
Since v1.0.0
utils
MetadataPart (class)
Represents the initial response metadata generated by a model when responding to a request.
Signature
declare class MetadataPart
Since v1.0.0
[PartTypeId] (property)
Signature
readonly [PartTypeId]: unique symbol
Since v1.0.0