@effect/ai 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Chat/package.json +6 -0
- package/EmbeddingModel/package.json +6 -0
- package/IdGenerator/package.json +6 -0
- package/LanguageModel/package.json +6 -0
- package/Model/package.json +6 -0
- package/Prompt/package.json +6 -0
- package/Response/package.json +6 -0
- package/Telemetry/package.json +6 -0
- package/Tool/package.json +6 -0
- package/Toolkit/package.json +6 -0
- package/dist/cjs/AiError.js +575 -11
- package/dist/cjs/AiError.js.map +1 -1
- package/dist/cjs/Chat.js +302 -0
- package/dist/cjs/Chat.js.map +1 -0
- package/dist/cjs/EmbeddingModel.js +184 -0
- package/dist/cjs/EmbeddingModel.js.map +1 -0
- package/dist/cjs/IdGenerator.js +255 -0
- package/dist/cjs/IdGenerator.js.map +1 -0
- package/dist/cjs/LanguageModel.js +584 -0
- package/dist/cjs/LanguageModel.js.map +1 -0
- package/dist/cjs/McpServer.js +12 -4
- package/dist/cjs/McpServer.js.map +1 -1
- package/dist/cjs/Model.js +118 -0
- package/dist/cjs/Model.js.map +1 -0
- package/dist/cjs/Prompt.js +649 -0
- package/dist/cjs/Prompt.js.map +1 -0
- package/dist/cjs/Response.js +635 -0
- package/dist/cjs/Response.js.map +1 -0
- package/dist/cjs/Telemetry.js +176 -0
- package/dist/cjs/Telemetry.js.map +1 -0
- package/dist/cjs/Tokenizer.js +87 -8
- package/dist/cjs/Tokenizer.js.map +1 -1
- package/dist/cjs/Tool.js +556 -0
- package/dist/cjs/Tool.js.map +1 -0
- package/dist/cjs/Toolkit.js +279 -0
- package/dist/cjs/Toolkit.js.map +1 -0
- package/dist/cjs/index.js +21 -19
- package/dist/dts/AiError.d.ts +577 -9
- package/dist/dts/AiError.d.ts.map +1 -1
- package/dist/dts/Chat.d.ts +356 -0
- package/dist/dts/Chat.d.ts.map +1 -0
- package/dist/dts/EmbeddingModel.d.ts +153 -0
- package/dist/dts/EmbeddingModel.d.ts.map +1 -0
- package/dist/dts/IdGenerator.d.ts +272 -0
- package/dist/dts/IdGenerator.d.ts.map +1 -0
- package/dist/dts/LanguageModel.d.ts +458 -0
- package/dist/dts/LanguageModel.d.ts.map +1 -0
- package/dist/dts/McpSchema.d.ts +25 -25
- package/dist/dts/McpServer.d.ts +6 -4
- package/dist/dts/McpServer.d.ts.map +1 -1
- package/dist/dts/Model.d.ts +124 -0
- package/dist/dts/Model.d.ts.map +1 -0
- package/dist/dts/Prompt.d.ts +1119 -0
- package/dist/dts/Prompt.d.ts.map +1 -0
- package/dist/dts/Response.d.ts +1519 -0
- package/dist/dts/Response.d.ts.map +1 -0
- package/dist/dts/Telemetry.d.ts +520 -0
- package/dist/dts/Telemetry.d.ts.map +1 -0
- package/dist/dts/Tokenizer.d.ts +131 -13
- package/dist/dts/Tokenizer.d.ts.map +1 -1
- package/dist/dts/Tool.d.ts +876 -0
- package/dist/dts/Tool.d.ts.map +1 -0
- package/dist/dts/Toolkit.d.ts +310 -0
- package/dist/dts/Toolkit.d.ts.map +1 -0
- package/dist/dts/index.d.ts +498 -13
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AiError.js +570 -10
- package/dist/esm/AiError.js.map +1 -1
- package/dist/esm/Chat.js +291 -0
- package/dist/esm/Chat.js.map +1 -0
- package/dist/esm/EmbeddingModel.js +173 -0
- package/dist/esm/EmbeddingModel.js.map +1 -0
- package/dist/esm/IdGenerator.js +245 -0
- package/dist/esm/IdGenerator.js.map +1 -0
- package/dist/esm/LanguageModel.js +572 -0
- package/dist/esm/LanguageModel.js.map +1 -0
- package/dist/esm/McpServer.js +12 -4
- package/dist/esm/McpServer.js.map +1 -1
- package/dist/esm/Model.js +108 -0
- package/dist/esm/Model.js.map +1 -0
- package/dist/esm/Prompt.js +633 -0
- package/dist/esm/Prompt.js.map +1 -0
- package/dist/esm/Response.js +619 -0
- package/dist/esm/Response.js.map +1 -0
- package/dist/esm/Telemetry.js +166 -0
- package/dist/esm/Telemetry.js.map +1 -0
- package/dist/esm/Tokenizer.js +87 -8
- package/dist/esm/Tokenizer.js.map +1 -1
- package/dist/esm/Tool.js +534 -0
- package/dist/esm/Tool.js.map +1 -0
- package/dist/esm/Toolkit.js +269 -0
- package/dist/esm/Toolkit.js.map +1 -0
- package/dist/esm/index.js +498 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +76 -68
- package/src/AiError.ts +739 -9
- package/src/Chat.ts +546 -0
- package/src/EmbeddingModel.ts +311 -0
- package/src/IdGenerator.ts +320 -0
- package/src/LanguageModel.ts +1074 -0
- package/src/McpServer.ts +337 -194
- package/src/Model.ts +155 -0
- package/src/Prompt.ts +1616 -0
- package/src/Response.ts +2131 -0
- package/src/Telemetry.ts +655 -0
- package/src/Tokenizer.ts +145 -24
- package/src/Tool.ts +1267 -0
- package/src/Toolkit.ts +516 -0
- package/src/index.ts +499 -13
- package/AiChat/package.json +0 -6
- package/AiEmbeddingModel/package.json +0 -6
- package/AiInput/package.json +0 -6
- package/AiLanguageModel/package.json +0 -6
- package/AiModel/package.json +0 -6
- package/AiResponse/package.json +0 -6
- package/AiTelemetry/package.json +0 -6
- package/AiTool/package.json +0 -6
- package/AiToolkit/package.json +0 -6
- package/dist/cjs/AiChat.js +0 -122
- package/dist/cjs/AiChat.js.map +0 -1
- package/dist/cjs/AiEmbeddingModel.js +0 -109
- package/dist/cjs/AiEmbeddingModel.js.map +0 -1
- package/dist/cjs/AiInput.js +0 -458
- package/dist/cjs/AiInput.js.map +0 -1
- package/dist/cjs/AiLanguageModel.js +0 -351
- package/dist/cjs/AiLanguageModel.js.map +0 -1
- package/dist/cjs/AiModel.js +0 -37
- package/dist/cjs/AiModel.js.map +0 -1
- package/dist/cjs/AiResponse.js +0 -681
- package/dist/cjs/AiResponse.js.map +0 -1
- package/dist/cjs/AiTelemetry.js +0 -58
- package/dist/cjs/AiTelemetry.js.map +0 -1
- package/dist/cjs/AiTool.js +0 -150
- package/dist/cjs/AiTool.js.map +0 -1
- package/dist/cjs/AiToolkit.js +0 -157
- package/dist/cjs/AiToolkit.js.map +0 -1
- package/dist/cjs/internal/common.js +0 -21
- package/dist/cjs/internal/common.js.map +0 -1
- package/dist/dts/AiChat.d.ts +0 -101
- package/dist/dts/AiChat.d.ts.map +0 -1
- package/dist/dts/AiEmbeddingModel.d.ts +0 -65
- package/dist/dts/AiEmbeddingModel.d.ts.map +0 -1
- package/dist/dts/AiInput.d.ts +0 -590
- package/dist/dts/AiInput.d.ts.map +0 -1
- package/dist/dts/AiLanguageModel.d.ts +0 -302
- package/dist/dts/AiLanguageModel.d.ts.map +0 -1
- package/dist/dts/AiModel.d.ts +0 -25
- package/dist/dts/AiModel.d.ts.map +0 -1
- package/dist/dts/AiResponse.d.ts +0 -863
- package/dist/dts/AiResponse.d.ts.map +0 -1
- package/dist/dts/AiTelemetry.d.ts +0 -242
- package/dist/dts/AiTelemetry.d.ts.map +0 -1
- package/dist/dts/AiTool.d.ts +0 -334
- package/dist/dts/AiTool.d.ts.map +0 -1
- package/dist/dts/AiToolkit.d.ts +0 -96
- package/dist/dts/AiToolkit.d.ts.map +0 -1
- package/dist/dts/internal/common.d.ts +0 -2
- package/dist/dts/internal/common.d.ts.map +0 -1
- package/dist/esm/AiChat.js +0 -111
- package/dist/esm/AiChat.js.map +0 -1
- package/dist/esm/AiEmbeddingModel.js +0 -98
- package/dist/esm/AiEmbeddingModel.js.map +0 -1
- package/dist/esm/AiInput.js +0 -433
- package/dist/esm/AiInput.js.map +0 -1
- package/dist/esm/AiLanguageModel.js +0 -340
- package/dist/esm/AiLanguageModel.js.map +0 -1
- package/dist/esm/AiModel.js +0 -29
- package/dist/esm/AiModel.js.map +0 -1
- package/dist/esm/AiResponse.js +0 -657
- package/dist/esm/AiResponse.js.map +0 -1
- package/dist/esm/AiTelemetry.js +0 -48
- package/dist/esm/AiTelemetry.js.map +0 -1
- package/dist/esm/AiTool.js +0 -134
- package/dist/esm/AiTool.js.map +0 -1
- package/dist/esm/AiToolkit.js +0 -147
- package/dist/esm/AiToolkit.js.map +0 -1
- package/dist/esm/internal/common.js +0 -14
- package/dist/esm/internal/common.js.map +0 -1
- package/src/AiChat.ts +0 -251
- package/src/AiEmbeddingModel.ts +0 -169
- package/src/AiInput.ts +0 -602
- package/src/AiLanguageModel.ts +0 -685
- package/src/AiModel.ts +0 -53
- package/src/AiResponse.ts +0 -986
- package/src/AiTelemetry.ts +0 -333
- package/src/AiTool.ts +0 -579
- package/src/AiToolkit.ts +0 -265
- package/src/internal/common.ts +0 -12
|
@@ -0,0 +1,1119 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import type * as Response from "./Response.js";
|
|
3
|
+
/**
|
|
4
|
+
* Schema for provider-specific options which can be attached to both content
|
|
5
|
+
* parts and messages, enabling provider-specific behavior.
|
|
6
|
+
*
|
|
7
|
+
* Provider-specific options are namespaced by provider and have the structure:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* {
|
|
11
|
+
* "<provider-specific-key>": {
|
|
12
|
+
* // Provider-specific options
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
* @category Models
|
|
19
|
+
*/
|
|
20
|
+
export declare const ProviderOptions: Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
21
|
+
/**
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
* @category Models
|
|
24
|
+
*/
|
|
25
|
+
export type ProviderOptions = typeof ProviderOptions.Type;
|
|
26
|
+
/**
|
|
27
|
+
* Unique identifier for Part instances.
|
|
28
|
+
*
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
* @category Type Ids
|
|
31
|
+
*/
|
|
32
|
+
export declare const PartTypeId = "~effect/ai/Prompt/Part";
|
|
33
|
+
/**
|
|
34
|
+
* Type-level representation of the Part identifier.
|
|
35
|
+
*
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
* @category Type Ids
|
|
38
|
+
*/
|
|
39
|
+
export type PartTypeId = typeof PartTypeId;
|
|
40
|
+
/**
|
|
41
|
+
* Type guard to check if a value is a Part.
|
|
42
|
+
*
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
* @category Guards
|
|
45
|
+
*/
|
|
46
|
+
export declare const isPart: (u: unknown) => u is Part;
|
|
47
|
+
/**
|
|
48
|
+
* Union type representing all possible content parts within messages.
|
|
49
|
+
*
|
|
50
|
+
* Parts are the building blocks of message content, supporting text, files,
|
|
51
|
+
* reasoning, tool calls, and tool results.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
* @category Models
|
|
55
|
+
*/
|
|
56
|
+
export type Part = TextPart | ReasoningPart | FilePart | ToolCallPart | ToolResultPart;
|
|
57
|
+
/**
|
|
58
|
+
* Encoded representation of a Part.
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category Models
|
|
62
|
+
*/
|
|
63
|
+
export type PartEncoded = TextPartEncoded | ReasoningPartEncoded | FilePartEncoded | ToolCallPartEncoded | ToolResultPartEncoded;
|
|
64
|
+
/**
|
|
65
|
+
* Base interface for all content parts.
|
|
66
|
+
*
|
|
67
|
+
* Provides common structure including type and provider options.
|
|
68
|
+
*
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category Models
|
|
71
|
+
*/
|
|
72
|
+
export interface BasePart<Type extends string, Options extends ProviderOptions> {
|
|
73
|
+
readonly [PartTypeId]: PartTypeId;
|
|
74
|
+
/**
|
|
75
|
+
* The type of this content part.
|
|
76
|
+
*/
|
|
77
|
+
readonly type: Type;
|
|
78
|
+
/**
|
|
79
|
+
* Provider-specific options for this part.
|
|
80
|
+
*/
|
|
81
|
+
readonly options: Options;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Base interface for encoded content parts.
|
|
85
|
+
*
|
|
86
|
+
* @since 1.0.0
|
|
87
|
+
* @category Models
|
|
88
|
+
*/
|
|
89
|
+
export interface BasePartEncoded<Type extends string, Options extends ProviderOptions> {
|
|
90
|
+
/**
|
|
91
|
+
* The type of this content part.
|
|
92
|
+
*/
|
|
93
|
+
readonly type: Type;
|
|
94
|
+
/**
|
|
95
|
+
* Provider-specific options for this part.
|
|
96
|
+
*/
|
|
97
|
+
readonly options?: Options | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new content part of the specified type.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { Prompt } from "@effect/ai"
|
|
105
|
+
*
|
|
106
|
+
* const textPart = Prompt.makePart("text", {
|
|
107
|
+
* text: "Hello, world!"
|
|
108
|
+
* })
|
|
109
|
+
*
|
|
110
|
+
* const filePart = Prompt.makePart("file", {
|
|
111
|
+
* mediaType: "image/png",
|
|
112
|
+
* fileName: "screenshot.png",
|
|
113
|
+
* data: new Uint8Array([1, 2, 3])
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @since 1.0.0
|
|
118
|
+
* @category Constructors
|
|
119
|
+
*/
|
|
120
|
+
export declare const makePart: <const Type extends Part["type"]>(
|
|
121
|
+
/**
|
|
122
|
+
* The type of part to create.
|
|
123
|
+
*/
|
|
124
|
+
type: Type,
|
|
125
|
+
/**
|
|
126
|
+
* Parameters specific to the part type being created.
|
|
127
|
+
*/
|
|
128
|
+
params: Omit<Extract<Part, {
|
|
129
|
+
type: Type;
|
|
130
|
+
}>, PartTypeId | "type" | "options"> & {
|
|
131
|
+
/**
|
|
132
|
+
* Optional provider-specific options for this part.
|
|
133
|
+
*/
|
|
134
|
+
readonly options?: Extract<Part, {
|
|
135
|
+
type: Type;
|
|
136
|
+
}>["options"] | undefined;
|
|
137
|
+
}) => Extract<Part, {
|
|
138
|
+
type: Type;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Content part representing plain text.
|
|
142
|
+
*
|
|
143
|
+
* The most basic content type used for textual information in messages.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { Prompt } from "@effect/ai"
|
|
148
|
+
*
|
|
149
|
+
* const textPart: Prompt.TextPart = Prompt.makePart("text", {
|
|
150
|
+
* text: "Hello, how can I help you today?",
|
|
151
|
+
* })
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @since 1.0.0
|
|
155
|
+
* @category Models
|
|
156
|
+
*/
|
|
157
|
+
export interface TextPart extends BasePart<"text", TextPartOptions> {
|
|
158
|
+
/**
|
|
159
|
+
* The text content.
|
|
160
|
+
*/
|
|
161
|
+
readonly text: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Encoded representation of text parts for serialization.
|
|
165
|
+
*
|
|
166
|
+
* @since 1.0.0
|
|
167
|
+
* @category Models
|
|
168
|
+
*/
|
|
169
|
+
export interface TextPartEncoded extends BasePartEncoded<"text", TextPartOptions> {
|
|
170
|
+
/**
|
|
171
|
+
* The text content.
|
|
172
|
+
*/
|
|
173
|
+
readonly text: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Represents provider-specific options that can be associated with a
|
|
177
|
+
* `TextPart` through module augmentation.
|
|
178
|
+
*
|
|
179
|
+
* @since 1.0.0
|
|
180
|
+
* @category ProviderOptions
|
|
181
|
+
*/
|
|
182
|
+
export interface TextPartOptions extends ProviderOptions {
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Schema for validation and encoding of text parts.
|
|
186
|
+
*
|
|
187
|
+
* @since 1.0.0
|
|
188
|
+
* @category Schemas
|
|
189
|
+
*/
|
|
190
|
+
export declare const TextPart: Schema.Schema<TextPart, TextPartEncoded>;
|
|
191
|
+
/**
|
|
192
|
+
* Content part representing reasoning or chain-of-thought.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* import { Prompt } from "@effect/ai"
|
|
197
|
+
*
|
|
198
|
+
* const reasoningPart: Prompt.ReasoningPart = Prompt.makePart("reasoning", {
|
|
199
|
+
* text: "Let me think step by step: First I need to understand the user's question...",
|
|
200
|
+
* })
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @since 1.0.0
|
|
204
|
+
* @category Models
|
|
205
|
+
*/
|
|
206
|
+
export interface ReasoningPart extends BasePart<"reasoning", ReasoningPartOptions> {
|
|
207
|
+
/**
|
|
208
|
+
* The reasoning or thought process text.
|
|
209
|
+
*/
|
|
210
|
+
readonly text: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Encoded representation of reasoning parts for serialization.
|
|
214
|
+
*
|
|
215
|
+
* @since 1.0.0
|
|
216
|
+
* @category Models
|
|
217
|
+
*/
|
|
218
|
+
export interface ReasoningPartEncoded extends BasePartEncoded<"reasoning", ReasoningPartOptions> {
|
|
219
|
+
/**
|
|
220
|
+
* The reasoning or thought process text.
|
|
221
|
+
*/
|
|
222
|
+
readonly text: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Represents provider-specific options that can be associated with a
|
|
226
|
+
* `ReasoningPart` through module augmentation.
|
|
227
|
+
*
|
|
228
|
+
* @since 1.0.0
|
|
229
|
+
* @category ProviderOptions
|
|
230
|
+
*/
|
|
231
|
+
export interface ReasoningPartOptions extends ProviderOptions {
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Schema for validation and encoding of reasoning parts.
|
|
235
|
+
*
|
|
236
|
+
* @since 1.0.0
|
|
237
|
+
* @category Schemas
|
|
238
|
+
*/
|
|
239
|
+
export declare const ReasoningPart: Schema.Schema<ReasoningPart, ReasoningPartEncoded>;
|
|
240
|
+
/**
|
|
241
|
+
* Content part representing a file attachment. Files can be provided as base64
|
|
242
|
+
* strings of data, byte arrays, or URLs.
|
|
243
|
+
*
|
|
244
|
+
* Supports various file types including images, documents, and binary data.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { Prompt } from "@effect/ai"
|
|
249
|
+
*
|
|
250
|
+
* const imagePart: Prompt.FilePart = Prompt.makePart("file", {
|
|
251
|
+
* mediaType: "image/jpeg",
|
|
252
|
+
* fileName: "photo.jpg",
|
|
253
|
+
* data: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
|
|
254
|
+
* })
|
|
255
|
+
*
|
|
256
|
+
* const documentPart: Prompt.FilePart = Prompt.makePart("file", {
|
|
257
|
+
* mediaType: "application/pdf",
|
|
258
|
+
* fileName: "report.pdf",
|
|
259
|
+
* data: new Uint8Array([1, 2, 3])
|
|
260
|
+
* })
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @since 1.0.0
|
|
264
|
+
* @category Models
|
|
265
|
+
*/
|
|
266
|
+
export interface FilePart extends BasePart<"file", FilePartOptions> {
|
|
267
|
+
/**
|
|
268
|
+
* MIME type of the file (e.g., "image/jpeg", "application/pdf").
|
|
269
|
+
*/
|
|
270
|
+
readonly mediaType: string;
|
|
271
|
+
/**
|
|
272
|
+
* Optional filename for the file.
|
|
273
|
+
*/
|
|
274
|
+
readonly fileName?: string | undefined;
|
|
275
|
+
/**
|
|
276
|
+
* File data as base64 string of data, a byte array, or a URL.
|
|
277
|
+
*/
|
|
278
|
+
readonly data: string | Uint8Array | URL;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Encoded representation of file parts for serialization.
|
|
282
|
+
*
|
|
283
|
+
* @since 1.0.0
|
|
284
|
+
* @category Models
|
|
285
|
+
*/
|
|
286
|
+
export interface FilePartEncoded extends BasePartEncoded<"file", FilePartOptions> {
|
|
287
|
+
/**
|
|
288
|
+
* MIME type of the file (e.g., "image/jpeg", "application/pdf").
|
|
289
|
+
*/
|
|
290
|
+
readonly mediaType: string;
|
|
291
|
+
/**
|
|
292
|
+
* Optional filename for the file.
|
|
293
|
+
*/
|
|
294
|
+
readonly fileName?: string | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* File data as base64 string of data, a byte array, or a URL.
|
|
297
|
+
*/
|
|
298
|
+
readonly data: string | Uint8Array | URL;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Represents provider-specific options that can be associated with a
|
|
302
|
+
* `FilePart` through module augmentation.
|
|
303
|
+
*
|
|
304
|
+
* @since 1.0.0
|
|
305
|
+
* @category ProviderOptions
|
|
306
|
+
*/
|
|
307
|
+
export interface FilePartOptions extends ProviderOptions {
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Schema for validation and encoding of file parts.
|
|
311
|
+
*
|
|
312
|
+
* @since 1.0.0
|
|
313
|
+
* @category Schemas
|
|
314
|
+
*/
|
|
315
|
+
export declare const FilePart: Schema.Schema<FilePart, FilePartEncoded>;
|
|
316
|
+
/**
|
|
317
|
+
* Content part representing a tool call request.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* import { Prompt } from "@effect/ai"
|
|
322
|
+
*
|
|
323
|
+
* const toolCallPart: Prompt.ToolCallPart = Prompt.makePart("tool-call", {
|
|
324
|
+
* id: "call_123",
|
|
325
|
+
* name: "get_weather",
|
|
326
|
+
* params: { city: "San Francisco", units: "celsius" },
|
|
327
|
+
* providerExecuted: false,
|
|
328
|
+
* })
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @since 1.0.0
|
|
332
|
+
* @category Models
|
|
333
|
+
*/
|
|
334
|
+
export interface ToolCallPart extends BasePart<"tool-call", ToolCallPartOptions> {
|
|
335
|
+
/**
|
|
336
|
+
* Unique identifier for this tool call.
|
|
337
|
+
*/
|
|
338
|
+
readonly id: string;
|
|
339
|
+
/**
|
|
340
|
+
* Name of the tool to invoke.
|
|
341
|
+
*/
|
|
342
|
+
readonly name: string;
|
|
343
|
+
/**
|
|
344
|
+
* Parameters to pass to the tool.
|
|
345
|
+
*/
|
|
346
|
+
readonly params: unknown;
|
|
347
|
+
/**
|
|
348
|
+
* Whether the tool was executed by the provider (true) or framework (false).
|
|
349
|
+
*/
|
|
350
|
+
readonly providerExecuted: boolean;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Encoded representation of tool call parts for serialization.
|
|
354
|
+
*
|
|
355
|
+
* @since 1.0.0
|
|
356
|
+
* @category Models
|
|
357
|
+
*/
|
|
358
|
+
export interface ToolCallPartEncoded extends BasePartEncoded<"tool-call", ToolCallPartOptions> {
|
|
359
|
+
/**
|
|
360
|
+
* Unique identifier for this tool call.
|
|
361
|
+
*/
|
|
362
|
+
readonly id: string;
|
|
363
|
+
/**
|
|
364
|
+
* Name of the tool to invoke.
|
|
365
|
+
*/
|
|
366
|
+
readonly name: string;
|
|
367
|
+
/**
|
|
368
|
+
* Parameters to pass to the tool.
|
|
369
|
+
*/
|
|
370
|
+
readonly params: unknown;
|
|
371
|
+
/**
|
|
372
|
+
* Whether the tool was executed by the provider (true) or framework (false).
|
|
373
|
+
*/
|
|
374
|
+
readonly providerExecuted?: boolean | undefined;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Represents provider-specific options that can be associated with a
|
|
378
|
+
* `ToolCallPart` through module augmentation.
|
|
379
|
+
*
|
|
380
|
+
* @since 1.0.0
|
|
381
|
+
* @category ProviderOptions
|
|
382
|
+
*/
|
|
383
|
+
export interface ToolCallPartOptions extends ProviderOptions {
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Schema for validation and encoding of tool call parts.
|
|
387
|
+
*
|
|
388
|
+
* @since 1.0.0
|
|
389
|
+
* @category Schemas
|
|
390
|
+
*/
|
|
391
|
+
export declare const ToolCallPart: Schema.Schema<ToolCallPart, ToolCallPartEncoded>;
|
|
392
|
+
/**
|
|
393
|
+
* Content part representing the result of a tool call.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* import { Prompt } from "@effect/ai"
|
|
398
|
+
*
|
|
399
|
+
* const toolResultPart: Prompt.ToolResultPart = Prompt.makePart("tool-result", {
|
|
400
|
+
* id: "call_123",
|
|
401
|
+
* name: "get_weather",
|
|
402
|
+
* result: {
|
|
403
|
+
* temperature: 22,
|
|
404
|
+
* condition: "sunny",
|
|
405
|
+
* humidity: 65
|
|
406
|
+
* }
|
|
407
|
+
* })
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @since 1.0.0
|
|
411
|
+
* @category Models
|
|
412
|
+
*/
|
|
413
|
+
export interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOptions> {
|
|
414
|
+
/**
|
|
415
|
+
* Unique identifier matching the original tool call.
|
|
416
|
+
*/
|
|
417
|
+
readonly id: string;
|
|
418
|
+
/**
|
|
419
|
+
* Name of the tool that was executed.
|
|
420
|
+
*/
|
|
421
|
+
readonly name: string;
|
|
422
|
+
/**
|
|
423
|
+
* The result returned by the tool execution.
|
|
424
|
+
*/
|
|
425
|
+
readonly result: unknown;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Encoded representation of tool result parts for serialization.
|
|
429
|
+
*
|
|
430
|
+
* @since 1.0.0
|
|
431
|
+
* @category Models
|
|
432
|
+
*/
|
|
433
|
+
export interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", ToolResultPartOptions> {
|
|
434
|
+
/**
|
|
435
|
+
* Unique identifier matching the original tool call.
|
|
436
|
+
*/
|
|
437
|
+
readonly id: string;
|
|
438
|
+
/**
|
|
439
|
+
* Name of the tool that was executed.
|
|
440
|
+
*/
|
|
441
|
+
readonly name: string;
|
|
442
|
+
/**
|
|
443
|
+
* The result returned by the tool execution.
|
|
444
|
+
*/
|
|
445
|
+
readonly result: unknown;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Represents provider-specific options that can be associated with a
|
|
449
|
+
* `ToolResultPart` through module augmentation.
|
|
450
|
+
*
|
|
451
|
+
* @since 1.0.0
|
|
452
|
+
* @category ProviderOptions
|
|
453
|
+
*/
|
|
454
|
+
export interface ToolResultPartOptions extends ProviderOptions {
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Schema for validation and encoding of tool result parts.
|
|
458
|
+
*
|
|
459
|
+
* @since 1.0.0
|
|
460
|
+
* @category Schemas
|
|
461
|
+
*/
|
|
462
|
+
export declare const ToolResultPart: Schema.Schema<ToolResultPart, ToolResultPartEncoded>;
|
|
463
|
+
/**
|
|
464
|
+
* Unique identifier for Message instances.
|
|
465
|
+
*
|
|
466
|
+
* @since 1.0.0
|
|
467
|
+
* @category Type Ids
|
|
468
|
+
*/
|
|
469
|
+
export declare const MessageTypeId = "~effect/ai/Prompt/Message";
|
|
470
|
+
/**
|
|
471
|
+
* Type-level representation of the Message identifier.
|
|
472
|
+
*
|
|
473
|
+
* @since 1.0.0
|
|
474
|
+
* @category Type Ids
|
|
475
|
+
*/
|
|
476
|
+
export type MessageTypeId = typeof MessageTypeId;
|
|
477
|
+
/**
|
|
478
|
+
* Type guard to check if a value is a Message.
|
|
479
|
+
*
|
|
480
|
+
* @since 1.0.0
|
|
481
|
+
* @category Guards
|
|
482
|
+
*/
|
|
483
|
+
export declare const isMessage: (u: unknown) => u is Message;
|
|
484
|
+
/**
|
|
485
|
+
* Base interface for all message types.
|
|
486
|
+
*
|
|
487
|
+
* Provides common structure including role and provider options.
|
|
488
|
+
*
|
|
489
|
+
* @since 1.0.0
|
|
490
|
+
* @category Models
|
|
491
|
+
*/
|
|
492
|
+
export interface BaseMessage<Role extends string, Options extends ProviderOptions> {
|
|
493
|
+
readonly [MessageTypeId]: MessageTypeId;
|
|
494
|
+
/**
|
|
495
|
+
* The role of the message participant.
|
|
496
|
+
*/
|
|
497
|
+
readonly role: Role;
|
|
498
|
+
/**
|
|
499
|
+
* Provider-specific options for this message.
|
|
500
|
+
*/
|
|
501
|
+
readonly options: Options;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Base interface for encoded message types.
|
|
505
|
+
*
|
|
506
|
+
* @template Role - String literal type for the message role
|
|
507
|
+
*
|
|
508
|
+
* @since 1.0.0
|
|
509
|
+
* @category Models
|
|
510
|
+
*/
|
|
511
|
+
export interface BaseMessageEncoded<Role extends string, Options extends ProviderOptions> {
|
|
512
|
+
/**
|
|
513
|
+
* The role of the message participant.
|
|
514
|
+
*/
|
|
515
|
+
readonly role: Role;
|
|
516
|
+
/**
|
|
517
|
+
* Provider-specific options for this message.
|
|
518
|
+
*/
|
|
519
|
+
readonly options?: Options | undefined;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Creates a new message with the specified role.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```ts
|
|
526
|
+
* import { Prompt } from "@effect/ai"
|
|
527
|
+
*
|
|
528
|
+
* const textPart = Prompt.makePart("text", {
|
|
529
|
+
* text: "Hello, world!"
|
|
530
|
+
* })
|
|
531
|
+
*
|
|
532
|
+
* const filePart = Prompt.makeMessage("user", {
|
|
533
|
+
* content: [textPart]
|
|
534
|
+
* })
|
|
535
|
+
* ```
|
|
536
|
+
*
|
|
537
|
+
* @since 1.0.0
|
|
538
|
+
* @category Constructors
|
|
539
|
+
*/
|
|
540
|
+
export declare const makeMessage: <const Role extends Message["role"]>(role: Role, params: Omit<Extract<Message, {
|
|
541
|
+
role: Role;
|
|
542
|
+
}>, MessageTypeId | "role" | "options"> & {
|
|
543
|
+
readonly options?: Extract<Message, {
|
|
544
|
+
role: Role;
|
|
545
|
+
}>["options"];
|
|
546
|
+
}) => Extract<Message, {
|
|
547
|
+
role: Role;
|
|
548
|
+
}>;
|
|
549
|
+
/**
|
|
550
|
+
* Message representing system instructions or context.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* import { Prompt } from "@effect/ai"
|
|
555
|
+
*
|
|
556
|
+
* const systemMessage: Prompt.SystemMessage = Prompt.makeMessage("system", {
|
|
557
|
+
* content: "You are a helpful assistant specialized in mathematics. " +
|
|
558
|
+
* "Always show your work step by step."
|
|
559
|
+
* })
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @since 1.0.0
|
|
563
|
+
* @category Models
|
|
564
|
+
*/
|
|
565
|
+
export interface SystemMessage extends BaseMessage<"system", SystemMessageOptions> {
|
|
566
|
+
/**
|
|
567
|
+
* The system instruction or context as plain text.
|
|
568
|
+
*/
|
|
569
|
+
readonly content: string;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Encoded representation of system messages for serialization.
|
|
573
|
+
*
|
|
574
|
+
* @since 1.0.0
|
|
575
|
+
* @category Models
|
|
576
|
+
*/
|
|
577
|
+
export interface SystemMessageEncoded extends BaseMessageEncoded<"system", SystemMessageOptions> {
|
|
578
|
+
/**
|
|
579
|
+
* The system instruction or context as plain text.
|
|
580
|
+
*/
|
|
581
|
+
readonly content: string;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Represents provider-specific options that can be associated with a
|
|
585
|
+
* `SystemMessage` through module augmentation.
|
|
586
|
+
*
|
|
587
|
+
* @since 1.0.0
|
|
588
|
+
* @category ProviderOptions
|
|
589
|
+
*/
|
|
590
|
+
export interface SystemMessageOptions extends ProviderOptions {
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Schema for validation and encoding of system messages.
|
|
594
|
+
*
|
|
595
|
+
* @since 1.0.0
|
|
596
|
+
* @category Schemas
|
|
597
|
+
*/
|
|
598
|
+
export declare const SystemMessage: Schema.Schema<SystemMessage, SystemMessageEncoded>;
|
|
599
|
+
/**
|
|
600
|
+
* Message representing user input or questions.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* import { Prompt } from "@effect/ai"
|
|
605
|
+
*
|
|
606
|
+
* const textUserMessage: Prompt.UserMessage = Prompt.makeMessage("user", {
|
|
607
|
+
* content: [
|
|
608
|
+
* Prompt.makePart("text", {
|
|
609
|
+
* text: "Can you analyze this image for me?"
|
|
610
|
+
* })
|
|
611
|
+
* ]
|
|
612
|
+
* })
|
|
613
|
+
*
|
|
614
|
+
* const multimodalUserMessage: Prompt.UserMessage = Prompt.makeMessage("user", {
|
|
615
|
+
* content: [
|
|
616
|
+
* Prompt.makePart("text", {
|
|
617
|
+
* text: "What do you see in this image?"
|
|
618
|
+
* }),
|
|
619
|
+
* Prompt.makePart("file", {
|
|
620
|
+
* mediaType: "image/jpeg",
|
|
621
|
+
* fileName: "vacation.jpg",
|
|
622
|
+
* data: "data:image/jpeg;base64,..."
|
|
623
|
+
* })
|
|
624
|
+
* ]
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
*
|
|
628
|
+
* @since 1.0.0
|
|
629
|
+
* @category Models
|
|
630
|
+
*/
|
|
631
|
+
export interface UserMessage extends BaseMessage<"user", UserMessageOptions> {
|
|
632
|
+
/**
|
|
633
|
+
* Array of content parts that make up the user's message.
|
|
634
|
+
*/
|
|
635
|
+
readonly content: ReadonlyArray<UserMessagePart>;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Union type of content parts allowed in user messages.
|
|
639
|
+
*
|
|
640
|
+
* @since 1.0.0
|
|
641
|
+
* @category Models
|
|
642
|
+
*/
|
|
643
|
+
export type UserMessagePart = TextPart | FilePart;
|
|
644
|
+
/**
|
|
645
|
+
* Encoded representation of user messages for serialization.
|
|
646
|
+
*
|
|
647
|
+
* @since 1.0.0
|
|
648
|
+
* @category Models
|
|
649
|
+
*/
|
|
650
|
+
export interface UserMessageEncoded extends BaseMessageEncoded<"user", UserMessageOptions> {
|
|
651
|
+
/**
|
|
652
|
+
* Array of content parts that make up the user's message.
|
|
653
|
+
*/
|
|
654
|
+
readonly content: ReadonlyArray<UserMessagePartEncoded>;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Union type of encoded content parts for user messages.
|
|
658
|
+
*
|
|
659
|
+
* @since 1.0.0
|
|
660
|
+
* @category Models
|
|
661
|
+
*/
|
|
662
|
+
export type UserMessagePartEncoded = TextPartEncoded | FilePartEncoded;
|
|
663
|
+
/**
|
|
664
|
+
* Represents provider-specific options that can be associated with a
|
|
665
|
+
* `UserMessage` through module augmentation.
|
|
666
|
+
*
|
|
667
|
+
* @since 1.0.0
|
|
668
|
+
* @category ProviderOptions
|
|
669
|
+
*/
|
|
670
|
+
export interface UserMessageOptions extends ProviderOptions {
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Schema for validation and encoding of user messages.
|
|
674
|
+
*
|
|
675
|
+
* @since 1.0.0
|
|
676
|
+
* @category Schemas
|
|
677
|
+
*/
|
|
678
|
+
export declare const UserMessage: Schema.Schema<UserMessage, UserMessageEncoded>;
|
|
679
|
+
/**
|
|
680
|
+
* Message representing large language model assistant responses.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```ts
|
|
684
|
+
* import { Prompt } from "@effect/ai"
|
|
685
|
+
*
|
|
686
|
+
* const assistantMessage: Prompt.AssistantMessage = Prompt.makeMessage("assistant", {
|
|
687
|
+
* content: [
|
|
688
|
+
* Prompt.makePart("text", {
|
|
689
|
+
* text: "The user is asking about the weather. I should use the weather tool."
|
|
690
|
+
* }),
|
|
691
|
+
* Prompt.makePart("tool-call", {
|
|
692
|
+
* id: "call_123",
|
|
693
|
+
* name: "get_weather",
|
|
694
|
+
* params: { city: "San Francisco" },
|
|
695
|
+
* providerExecuted: false
|
|
696
|
+
* }),
|
|
697
|
+
* Prompt.makePart("tool-result", {
|
|
698
|
+
* id: "call_123",
|
|
699
|
+
* name: "get_weather",
|
|
700
|
+
* result: { temperature: 72, condition: "sunny" }
|
|
701
|
+
* }),
|
|
702
|
+
* Prompt.makePart("text", {
|
|
703
|
+
* text: "The weather in San Francisco is currently 72°F and sunny."
|
|
704
|
+
* })
|
|
705
|
+
* ]
|
|
706
|
+
* })
|
|
707
|
+
* ```
|
|
708
|
+
*
|
|
709
|
+
* @since 1.0.0
|
|
710
|
+
* @category Models
|
|
711
|
+
*/
|
|
712
|
+
export interface AssistantMessage extends BaseMessage<"assistant", AssistantMessageOptions> {
|
|
713
|
+
/**
|
|
714
|
+
* Array of content parts that make up the assistant's response.
|
|
715
|
+
*/
|
|
716
|
+
readonly content: ReadonlyArray<AssistantMessagePart>;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Union type of content parts allowed in assistant messages.
|
|
720
|
+
*
|
|
721
|
+
* @since 1.0.0
|
|
722
|
+
* @category Models
|
|
723
|
+
*/
|
|
724
|
+
export type AssistantMessagePart = TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart;
|
|
725
|
+
/**
|
|
726
|
+
* Encoded representation of assistant messages for serialization.
|
|
727
|
+
*
|
|
728
|
+
* @since 1.0.0
|
|
729
|
+
* @category Models
|
|
730
|
+
*/
|
|
731
|
+
export interface AssistantMessageEncoded extends BaseMessageEncoded<"assistant", AssistantMessageOptions> {
|
|
732
|
+
readonly content: ReadonlyArray<AssistantMessagePartEncoded>;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Union type of encoded content parts for assistant messages.
|
|
736
|
+
*
|
|
737
|
+
* @since 1.0.0
|
|
738
|
+
* @category Models
|
|
739
|
+
*/
|
|
740
|
+
export type AssistantMessagePartEncoded = TextPartEncoded | FilePartEncoded | ReasoningPartEncoded | ToolCallPartEncoded | ToolResultPartEncoded;
|
|
741
|
+
/**
|
|
742
|
+
* Represents provider-specific options that can be associated with a
|
|
743
|
+
* `AssistantMessage` through module augmentation.
|
|
744
|
+
*
|
|
745
|
+
* @since 1.0.0
|
|
746
|
+
* @category ProviderOptions
|
|
747
|
+
*/
|
|
748
|
+
export interface AssistantMessageOptions extends ProviderOptions {
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Schema for validation and encoding of assistant messages.
|
|
752
|
+
*
|
|
753
|
+
* @since 1.0.0
|
|
754
|
+
* @category Schemas
|
|
755
|
+
*/
|
|
756
|
+
export declare const AssistantMessage: Schema.Schema<AssistantMessage, AssistantMessageEncoded>;
|
|
757
|
+
/**
|
|
758
|
+
* Message representing tool execution results.
|
|
759
|
+
*
|
|
760
|
+
* @example
|
|
761
|
+
* ```ts
|
|
762
|
+
* import { Prompt } from "@effect/ai"
|
|
763
|
+
*
|
|
764
|
+
* const toolMessage: Prompt.ToolMessage = Prompt.makeMessage("tool", {
|
|
765
|
+
* content: [
|
|
766
|
+
* Prompt.makePart("tool-result", {
|
|
767
|
+
* id: "call_123",
|
|
768
|
+
* name: "search_web",
|
|
769
|
+
* result: {
|
|
770
|
+
* query: "TypeScript best practices",
|
|
771
|
+
* results: [
|
|
772
|
+
* { title: "TypeScript Handbook", url: "https://..." },
|
|
773
|
+
* { title: "Effective TypeScript", url: "https://..." }
|
|
774
|
+
* ]
|
|
775
|
+
* }
|
|
776
|
+
* })
|
|
777
|
+
* ]
|
|
778
|
+
* })
|
|
779
|
+
* ```
|
|
780
|
+
*
|
|
781
|
+
* @since 1.0.0
|
|
782
|
+
* @category Models
|
|
783
|
+
*/
|
|
784
|
+
export interface ToolMessage extends BaseMessage<"tool", ToolMessageOptions> {
|
|
785
|
+
/**
|
|
786
|
+
* Array of tool result parts.
|
|
787
|
+
*/
|
|
788
|
+
readonly content: ReadonlyArray<ToolMessagePart>;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Union type of content parts allowed in tool messages.
|
|
792
|
+
*
|
|
793
|
+
* @since 1.0.0
|
|
794
|
+
* @category Models
|
|
795
|
+
*/
|
|
796
|
+
export type ToolMessagePart = ToolResultPart;
|
|
797
|
+
/**
|
|
798
|
+
* Encoded representation of tool messages for serialization.
|
|
799
|
+
*
|
|
800
|
+
* @since 1.0.0
|
|
801
|
+
* @category Models
|
|
802
|
+
*/
|
|
803
|
+
export interface ToolMessageEncoded extends BaseMessageEncoded<"tool", ToolMessageOptions> {
|
|
804
|
+
/**
|
|
805
|
+
* Array of tool result parts.
|
|
806
|
+
*/
|
|
807
|
+
readonly content: ReadonlyArray<ToolMessagePartEncoded>;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Union type of encoded content parts for tool messages.
|
|
811
|
+
*
|
|
812
|
+
* @since 1.0.0
|
|
813
|
+
* @category Models
|
|
814
|
+
*/
|
|
815
|
+
export type ToolMessagePartEncoded = ToolResultPartEncoded;
|
|
816
|
+
/**
|
|
817
|
+
* Represents provider-specific options that can be associated with a
|
|
818
|
+
* `ToolMessage` through module augmentation.
|
|
819
|
+
*
|
|
820
|
+
* @since 1.0.0
|
|
821
|
+
* @category ProviderOptions
|
|
822
|
+
*/
|
|
823
|
+
export interface ToolMessageOptions extends ProviderOptions {
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Schema for validation and encoding of tool messages.
|
|
827
|
+
*
|
|
828
|
+
* @since 1.0.0
|
|
829
|
+
* @category Schemas
|
|
830
|
+
*/
|
|
831
|
+
export declare const ToolMessage: Schema.Schema<ToolMessage, ToolMessageEncoded>;
|
|
832
|
+
/**
|
|
833
|
+
* A type representing all possible message types in a conversation.
|
|
834
|
+
*
|
|
835
|
+
* @since 1.0.0
|
|
836
|
+
* @category Models
|
|
837
|
+
*/
|
|
838
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
839
|
+
/**
|
|
840
|
+
* A type representing all possible encoded message types for serialization.
|
|
841
|
+
*
|
|
842
|
+
* @since 1.0.0
|
|
843
|
+
* @category Models
|
|
844
|
+
*/
|
|
845
|
+
export type MessageEncoded = SystemMessageEncoded | UserMessageEncoded | AssistantMessageEncoded | ToolMessageEncoded;
|
|
846
|
+
/**
|
|
847
|
+
* Schema for validation and encoding of messages.
|
|
848
|
+
*
|
|
849
|
+
* @since 1.0.0
|
|
850
|
+
* @category Schemas
|
|
851
|
+
*/
|
|
852
|
+
export declare const Message: Schema.Schema<Message, MessageEncoded>;
|
|
853
|
+
/**
|
|
854
|
+
* Unique identifier for Prompt instances.
|
|
855
|
+
*
|
|
856
|
+
* @since 1.0.0
|
|
857
|
+
* @category Type Ids
|
|
858
|
+
*/
|
|
859
|
+
export declare const TypeId = "~@effect/ai/Prompt";
|
|
860
|
+
/**
|
|
861
|
+
* Type-level representation of the Prompt identifier.
|
|
862
|
+
*
|
|
863
|
+
* @since 1.0.0
|
|
864
|
+
* @category Type Ids
|
|
865
|
+
*/
|
|
866
|
+
export type TypeId = typeof TypeId;
|
|
867
|
+
/**
|
|
868
|
+
* Type guard to check if a value is a Prompt.
|
|
869
|
+
*
|
|
870
|
+
* @since 1.0.0
|
|
871
|
+
* @category Guards
|
|
872
|
+
*/
|
|
873
|
+
export declare const isPrompt: (u: unknown) => u is Prompt;
|
|
874
|
+
/**
|
|
875
|
+
* A Prompt contains a sequence of messages that form the context of a
|
|
876
|
+
* conversation with a large language model.
|
|
877
|
+
*
|
|
878
|
+
* @since 1.0.0
|
|
879
|
+
* @category Models
|
|
880
|
+
*/
|
|
881
|
+
export interface Prompt {
|
|
882
|
+
readonly [TypeId]: TypeId;
|
|
883
|
+
/**
|
|
884
|
+
* Array of messages that make up the conversation.
|
|
885
|
+
*/
|
|
886
|
+
readonly content: ReadonlyArray<Message>;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Encoded representation of prompts for serialization.
|
|
890
|
+
*
|
|
891
|
+
* @since 1.0.0
|
|
892
|
+
* @category Models
|
|
893
|
+
*/
|
|
894
|
+
export interface PromptEncoded {
|
|
895
|
+
/**
|
|
896
|
+
* Array of messages that make up the conversation.
|
|
897
|
+
*/
|
|
898
|
+
readonly content: ReadonlyArray<MessageEncoded>;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Schema for validation and encoding of prompts.
|
|
902
|
+
*
|
|
903
|
+
* @since 1.0.0
|
|
904
|
+
* @category Schemas
|
|
905
|
+
*/
|
|
906
|
+
export declare const Prompt: Schema.Schema<Prompt, PromptEncoded>;
|
|
907
|
+
/**
|
|
908
|
+
* Schema for parsing a Prompt from JSON strings.
|
|
909
|
+
*
|
|
910
|
+
* @since 1.0.0
|
|
911
|
+
* @category Schemas
|
|
912
|
+
*/
|
|
913
|
+
export declare const FromJson: Schema.transform<Schema.SchemaClass<unknown, string, never>, Schema.Schema<Prompt, PromptEncoded, never>>;
|
|
914
|
+
/**
|
|
915
|
+
* Raw input types that can be converted into a Prompt.
|
|
916
|
+
*
|
|
917
|
+
* Supports various input formats for convenience, including simple strings,
|
|
918
|
+
* message arrays, response parts, and existing prompts.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```ts
|
|
922
|
+
* import { Prompt } from "@effect/ai"
|
|
923
|
+
*
|
|
924
|
+
* // String input - creates a user message
|
|
925
|
+
* const stringInput: Prompt.RawInput = "Hello, world!"
|
|
926
|
+
*
|
|
927
|
+
* // Message array input
|
|
928
|
+
* const messagesInput: Prompt.RawInput = [
|
|
929
|
+
* { role: "system", content: "You are helpful." },
|
|
930
|
+
* { role: "user", content: [{ type: "text", text: "Hi!" }] }
|
|
931
|
+
* ]
|
|
932
|
+
*
|
|
933
|
+
* // Existing prompt
|
|
934
|
+
* declare const existingPrompt: Prompt.Prompt
|
|
935
|
+
* const promptInput: Prompt.RawInput = existingPrompt
|
|
936
|
+
* ```
|
|
937
|
+
*
|
|
938
|
+
* @since 1.0.0
|
|
939
|
+
* @category Models
|
|
940
|
+
*/
|
|
941
|
+
export type RawInput = string | Iterable<MessageEncoded> | Prompt;
|
|
942
|
+
/**
|
|
943
|
+
* An empty prompt with no messages.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```ts
|
|
947
|
+
* import { Prompt } from "@effect/ai"
|
|
948
|
+
*
|
|
949
|
+
* const emptyPrompt = Prompt.empty
|
|
950
|
+
* console.log(emptyPrompt.content) // []
|
|
951
|
+
* ```
|
|
952
|
+
*
|
|
953
|
+
* @since 1.0.0
|
|
954
|
+
* @category Constructors
|
|
955
|
+
*/
|
|
956
|
+
export declare const empty: Prompt;
|
|
957
|
+
/**
|
|
958
|
+
* Creates a Prompt from an input.
|
|
959
|
+
*
|
|
960
|
+
* This is the primary constructor for creating prompts, supporting multiple
|
|
961
|
+
* input formats for convenience and flexibility.
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```ts
|
|
965
|
+
* import { Prompt } from "@effect/ai"
|
|
966
|
+
*
|
|
967
|
+
* // From string - creates a user message
|
|
968
|
+
* const textPrompt = Prompt.make("Hello, how are you?")
|
|
969
|
+
*
|
|
970
|
+
* // From messages array
|
|
971
|
+
* const structuredPrompt = Prompt.make([
|
|
972
|
+
* { role: "system", content: "You are a helpful assistant." },
|
|
973
|
+
* { role: "user", content: [{ type: "text", text: "Hi!" }] }
|
|
974
|
+
* ])
|
|
975
|
+
*
|
|
976
|
+
* // From existing prompt
|
|
977
|
+
* declare const existingPrompt: Prompt.Prompt
|
|
978
|
+
* const copiedPrompt = Prompt.make(existingPrompt)
|
|
979
|
+
* ```
|
|
980
|
+
*
|
|
981
|
+
* @since 1.0.0
|
|
982
|
+
* @category Constructors
|
|
983
|
+
*/
|
|
984
|
+
export declare const make: (input: RawInput) => Prompt;
|
|
985
|
+
/**
|
|
986
|
+
* Creates a Prompt from an array of messages.
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```ts
|
|
990
|
+
* import { Prompt } from "@effect/ai"
|
|
991
|
+
*
|
|
992
|
+
* const messages: ReadonlyArray<Prompt.Message> = [
|
|
993
|
+
* Prompt.makeMessage("system", {
|
|
994
|
+
* content: "You are a coding assistant."
|
|
995
|
+
* }),
|
|
996
|
+
* Prompt.makeMessage("user", {
|
|
997
|
+
* content: [Prompt.makePart("text", { text: "Help me with TypeScript" })]
|
|
998
|
+
* })
|
|
999
|
+
* ]
|
|
1000
|
+
*
|
|
1001
|
+
* const prompt = Prompt.fromMessages(messages)
|
|
1002
|
+
* ```
|
|
1003
|
+
*
|
|
1004
|
+
* @since 1.0.0
|
|
1005
|
+
* @category Constructors
|
|
1006
|
+
*/
|
|
1007
|
+
export declare const fromMessages: (messages: ReadonlyArray<Message>) => Prompt;
|
|
1008
|
+
/**
|
|
1009
|
+
* Creates a Prompt from the response parts of a previous interaction with a
|
|
1010
|
+
* large language model.
|
|
1011
|
+
*
|
|
1012
|
+
* Converts streaming or non-streaming AI response parts into a structured
|
|
1013
|
+
* prompt, typically for use in conversation history or further processing.
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```ts
|
|
1017
|
+
* import { Prompt, Response } from "@effect/ai"
|
|
1018
|
+
*
|
|
1019
|
+
* const responseParts: ReadonlyArray<Response.AnyPart> = [
|
|
1020
|
+
* Response.makePart("text", {
|
|
1021
|
+
* text: "Hello there!"
|
|
1022
|
+
* }),
|
|
1023
|
+
* Response.makePart("tool-call", {
|
|
1024
|
+
* id: "call_1",
|
|
1025
|
+
* name: "get_time",
|
|
1026
|
+
* params: {},
|
|
1027
|
+
* providerExecuted: false
|
|
1028
|
+
* }),
|
|
1029
|
+
* Response.makePart("tool-result", {
|
|
1030
|
+
* id: "call_1",
|
|
1031
|
+
* name: "get_time",
|
|
1032
|
+
* result: "10:30 AM",
|
|
1033
|
+
* encodedResult: "10:30 AM",
|
|
1034
|
+
* providerExecuted: false
|
|
1035
|
+
* })
|
|
1036
|
+
* ]
|
|
1037
|
+
*
|
|
1038
|
+
* const prompt = Prompt.fromResponseParts(responseParts)
|
|
1039
|
+
* // Creates an assistant message with the response content
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* @since 1.0.0
|
|
1043
|
+
* @category Constructors
|
|
1044
|
+
*/
|
|
1045
|
+
export declare const fromResponseParts: (parts: ReadonlyArray<Response.AnyPart>) => Prompt;
|
|
1046
|
+
/**
|
|
1047
|
+
* Merges two prompts by concatenating their messages.
|
|
1048
|
+
*
|
|
1049
|
+
* Creates a new prompt containing all messages from both prompts, maintaining
|
|
1050
|
+
* the order of messages within each prompt.
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```ts
|
|
1054
|
+
* import { Prompt } from "@effect/ai"
|
|
1055
|
+
*
|
|
1056
|
+
* const systemPrompt = Prompt.make([{
|
|
1057
|
+
* role: "system",
|
|
1058
|
+
* content: "You are a helpful assistant."
|
|
1059
|
+
* }])
|
|
1060
|
+
*
|
|
1061
|
+
* const userPrompt = Prompt.make("Hello, world!")
|
|
1062
|
+
*
|
|
1063
|
+
* const merged = Prompt.merge(systemPrompt, userPrompt)
|
|
1064
|
+
* ```
|
|
1065
|
+
*
|
|
1066
|
+
* @since 1.0.0
|
|
1067
|
+
* @category Combinators
|
|
1068
|
+
*/
|
|
1069
|
+
export declare const merge: {
|
|
1070
|
+
/**
|
|
1071
|
+
* Merges two prompts by concatenating their messages.
|
|
1072
|
+
*
|
|
1073
|
+
* Creates a new prompt containing all messages from both prompts, maintaining
|
|
1074
|
+
* the order of messages within each prompt.
|
|
1075
|
+
*
|
|
1076
|
+
* @example
|
|
1077
|
+
* ```ts
|
|
1078
|
+
* import { Prompt } from "@effect/ai"
|
|
1079
|
+
*
|
|
1080
|
+
* const systemPrompt = Prompt.make([{
|
|
1081
|
+
* role: "system",
|
|
1082
|
+
* content: "You are a helpful assistant."
|
|
1083
|
+
* }])
|
|
1084
|
+
*
|
|
1085
|
+
* const userPrompt = Prompt.make("Hello, world!")
|
|
1086
|
+
*
|
|
1087
|
+
* const merged = Prompt.merge(systemPrompt, userPrompt)
|
|
1088
|
+
* ```
|
|
1089
|
+
*
|
|
1090
|
+
* @since 1.0.0
|
|
1091
|
+
* @category Combinators
|
|
1092
|
+
*/
|
|
1093
|
+
(other: Prompt): (self: Prompt) => Prompt;
|
|
1094
|
+
/**
|
|
1095
|
+
* Merges two prompts by concatenating their messages.
|
|
1096
|
+
*
|
|
1097
|
+
* Creates a new prompt containing all messages from both prompts, maintaining
|
|
1098
|
+
* the order of messages within each prompt.
|
|
1099
|
+
*
|
|
1100
|
+
* @example
|
|
1101
|
+
* ```ts
|
|
1102
|
+
* import { Prompt } from "@effect/ai"
|
|
1103
|
+
*
|
|
1104
|
+
* const systemPrompt = Prompt.make([{
|
|
1105
|
+
* role: "system",
|
|
1106
|
+
* content: "You are a helpful assistant."
|
|
1107
|
+
* }])
|
|
1108
|
+
*
|
|
1109
|
+
* const userPrompt = Prompt.make("Hello, world!")
|
|
1110
|
+
*
|
|
1111
|
+
* const merged = Prompt.merge(systemPrompt, userPrompt)
|
|
1112
|
+
* ```
|
|
1113
|
+
*
|
|
1114
|
+
* @since 1.0.0
|
|
1115
|
+
* @category Combinators
|
|
1116
|
+
*/
|
|
1117
|
+
(self: Prompt, other: Prompt): Prompt;
|
|
1118
|
+
};
|
|
1119
|
+
//# sourceMappingURL=Prompt.d.ts.map
|