@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
package/src/AiInput.ts
DELETED
|
@@ -1,602 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 1.0.0
|
|
3
|
-
*/
|
|
4
|
-
import { dual } from "effect/Function"
|
|
5
|
-
import * as Predicate from "effect/Predicate"
|
|
6
|
-
import * as Schema from "effect/Schema"
|
|
7
|
-
import * as AiResponse from "./AiResponse.js"
|
|
8
|
-
import * as InternalCommon from "./internal/common.js"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
* @category Type Ids
|
|
13
|
-
*/
|
|
14
|
-
export const TypeId = Symbol.for("@effect/ai/AiInput")
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @since 1.0.0
|
|
18
|
-
* @category Type Ids
|
|
19
|
-
*/
|
|
20
|
-
export type TypeId = typeof TypeId
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Represents input to a large language model.
|
|
24
|
-
*
|
|
25
|
-
* @since 1.0.0
|
|
26
|
-
* @category Models
|
|
27
|
-
*/
|
|
28
|
-
export class AiInput extends Schema.Class<AiInput>(
|
|
29
|
-
"@effect/ai/AiInput"
|
|
30
|
-
)({
|
|
31
|
-
messages: Schema.Array(Schema.suspend(() => Message))
|
|
32
|
-
}) {
|
|
33
|
-
/**
|
|
34
|
-
* @since 1.0.0
|
|
35
|
-
*/
|
|
36
|
-
readonly [TypeId]: TypeId = TypeId
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @since 1.0.0
|
|
41
|
-
* @category Models
|
|
42
|
-
*/
|
|
43
|
-
export const FromJson = Schema.parseJson(AiInput)
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Represents raw input types that can be converted into an `AiInput`.
|
|
47
|
-
*
|
|
48
|
-
* @since 1.0.0
|
|
49
|
-
* @category Models
|
|
50
|
-
*/
|
|
51
|
-
export type Raw =
|
|
52
|
-
| string
|
|
53
|
-
| Message
|
|
54
|
-
| Iterable<Message>
|
|
55
|
-
| AiInput
|
|
56
|
-
| AiResponse.AiResponse
|
|
57
|
-
| AiResponse.WithStructuredOutput<any>
|
|
58
|
-
| AiResponse.WithToolCallResults<any>
|
|
59
|
-
|
|
60
|
-
// =============================================================================
|
|
61
|
-
// Message
|
|
62
|
-
// =============================================================================
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @since 1.0.0
|
|
66
|
-
* @category Type Ids
|
|
67
|
-
*/
|
|
68
|
-
export const MessageTypeId = Symbol.for("@effect/ai/AiInput/Message")
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
* @category Type Ids
|
|
73
|
-
*/
|
|
74
|
-
export type MessageTypeId = typeof MessageTypeId
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @since 1.0.0
|
|
78
|
-
* @category Models
|
|
79
|
-
*/
|
|
80
|
-
export class UserMessage extends Schema.TaggedClass<UserMessage>(
|
|
81
|
-
"@effect/ai/AiInput/Message/UserMessage"
|
|
82
|
-
)("UserMessage", {
|
|
83
|
-
parts: Schema.Array(Schema.suspend(() => UserMessagePart)),
|
|
84
|
-
userName: Schema.optional(Schema.String)
|
|
85
|
-
}) {
|
|
86
|
-
/**
|
|
87
|
-
* @since 1.0.0
|
|
88
|
-
*/
|
|
89
|
-
readonly [MessageTypeId]: MessageTypeId = MessageTypeId
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @since 1.0.0
|
|
94
|
-
* @category Models
|
|
95
|
-
*/
|
|
96
|
-
export class AssistantMessage extends Schema.TaggedClass<AssistantMessage>(
|
|
97
|
-
"@effect/ai/AiInput/Message/AssistantMessage"
|
|
98
|
-
)("AssistantMessage", {
|
|
99
|
-
parts: Schema.Array(Schema.suspend(() => AssistantMessagePart))
|
|
100
|
-
}) {
|
|
101
|
-
/**
|
|
102
|
-
* @since 1.0.0
|
|
103
|
-
*/
|
|
104
|
-
readonly [MessageTypeId]: MessageTypeId = MessageTypeId
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @since 1.0.0
|
|
109
|
-
* @category Models
|
|
110
|
-
*/
|
|
111
|
-
export class ToolMessage extends Schema.TaggedClass<ToolMessage>(
|
|
112
|
-
"@effect/ai/AiInput/Message/ToolMessage"
|
|
113
|
-
)("ToolMessage", {
|
|
114
|
-
parts: Schema.Array(Schema.suspend(() => ToolMessagePart))
|
|
115
|
-
}) {
|
|
116
|
-
/**
|
|
117
|
-
* @since 1.0.0
|
|
118
|
-
*/
|
|
119
|
-
readonly [MessageTypeId]: MessageTypeId = MessageTypeId
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @since 1.0.0
|
|
124
|
-
* @category Models
|
|
125
|
-
*/
|
|
126
|
-
export const Message: Schema.Union<[
|
|
127
|
-
typeof UserMessage,
|
|
128
|
-
typeof AssistantMessage,
|
|
129
|
-
typeof ToolMessage
|
|
130
|
-
]> = Schema.Union(
|
|
131
|
-
UserMessage,
|
|
132
|
-
AssistantMessage,
|
|
133
|
-
ToolMessage
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @since 1.0.0
|
|
138
|
-
* @category Models
|
|
139
|
-
*/
|
|
140
|
-
export type Message = typeof Message.Type
|
|
141
|
-
|
|
142
|
-
// =============================================================================
|
|
143
|
-
// Part
|
|
144
|
-
// =============================================================================
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @since 1.0.0
|
|
148
|
-
* @category Type Ids
|
|
149
|
-
*/
|
|
150
|
-
export const PartTypeId = Symbol.for("@effect/ai/AiInput/Message/Part")
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @since 1.0.0
|
|
154
|
-
* @category Type Ids
|
|
155
|
-
*/
|
|
156
|
-
export type PartTypeId = typeof PartTypeId
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Represents a text part of a message.
|
|
160
|
-
*
|
|
161
|
-
* @since 1.0.0
|
|
162
|
-
* @category Models
|
|
163
|
-
*/
|
|
164
|
-
export class TextPart extends Schema.TaggedClass<TextPart>(
|
|
165
|
-
"@effect/ai/AiInput/TextPart"
|
|
166
|
-
)("TextPart", {
|
|
167
|
-
/**
|
|
168
|
-
* The text content.
|
|
169
|
-
*/
|
|
170
|
-
text: Schema.String
|
|
171
|
-
}) {
|
|
172
|
-
/**
|
|
173
|
-
* @since 1.0.0
|
|
174
|
-
*/
|
|
175
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Represents an image part of a message with binary image data.
|
|
180
|
-
*
|
|
181
|
-
* @since 1.0.0
|
|
182
|
-
* @category Models
|
|
183
|
-
*/
|
|
184
|
-
export class ImagePart extends Schema.TaggedClass<ImagePart>(
|
|
185
|
-
"@effect/ai/AiInput/ImagePart"
|
|
186
|
-
)("ImagePart", {
|
|
187
|
-
/**
|
|
188
|
-
* The binary image data.
|
|
189
|
-
*/
|
|
190
|
-
data: Schema.Uint8ArrayFromBase64,
|
|
191
|
-
/**
|
|
192
|
-
* The optional MIME type for the image.
|
|
193
|
-
*/
|
|
194
|
-
mediaType: Schema.optional(Schema.String)
|
|
195
|
-
}) {
|
|
196
|
-
/**
|
|
197
|
-
* @since 1.0.0
|
|
198
|
-
*/
|
|
199
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Represents an image part of a message with a URL pointing to the image.
|
|
204
|
-
*
|
|
205
|
-
* @since 1.0.0
|
|
206
|
-
* @category Models
|
|
207
|
-
*/
|
|
208
|
-
export class ImageUrlPart extends Schema.TaggedClass<ImageUrlPart>(
|
|
209
|
-
"@effect/ai/AiInput/ImageUrlPart"
|
|
210
|
-
)("ImageUrlPart", {
|
|
211
|
-
/**
|
|
212
|
-
* The URL that points to the image.
|
|
213
|
-
*/
|
|
214
|
-
url: Schema.URL
|
|
215
|
-
}) {
|
|
216
|
-
/**
|
|
217
|
-
* @since 1.0.0
|
|
218
|
-
*/
|
|
219
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Represents a file part of a message with binary file data.
|
|
224
|
-
*
|
|
225
|
-
* @since 1.0.0
|
|
226
|
-
* @category Models
|
|
227
|
-
*/
|
|
228
|
-
export class FilePart extends Schema.TaggedClass<FilePart>(
|
|
229
|
-
"@effect/ai/AiInput/FilePart"
|
|
230
|
-
)("FilePart", {
|
|
231
|
-
/**
|
|
232
|
-
* The binary file data.
|
|
233
|
-
*/
|
|
234
|
-
data: Schema.Uint8ArrayFromBase64,
|
|
235
|
-
/**
|
|
236
|
-
* The optional name of the file.
|
|
237
|
-
*/
|
|
238
|
-
name: Schema.optional(Schema.String),
|
|
239
|
-
/**
|
|
240
|
-
* The optional MIME type for the image.
|
|
241
|
-
*/
|
|
242
|
-
mediaType: Schema.optional(Schema.String)
|
|
243
|
-
}) {
|
|
244
|
-
/**
|
|
245
|
-
* @since 1.0.0
|
|
246
|
-
*/
|
|
247
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Represents a file part of a message with a URL pointing to the file.
|
|
252
|
-
*
|
|
253
|
-
* @since 1.0.0
|
|
254
|
-
* @category Models
|
|
255
|
-
*/
|
|
256
|
-
export class FileUrlPart extends Schema.TaggedClass<FileUrlPart>(
|
|
257
|
-
"@effect/ai/AiInput/FileUrlPart"
|
|
258
|
-
)("FileUrlPart", {
|
|
259
|
-
/**
|
|
260
|
-
* The URL that points to the file.
|
|
261
|
-
*/
|
|
262
|
-
url: Schema.URL
|
|
263
|
-
}) {
|
|
264
|
-
/**
|
|
265
|
-
* @since 1.0.0
|
|
266
|
-
*/
|
|
267
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Represents a part of a message containing reasoning that the model used to
|
|
272
|
-
* generate its output.
|
|
273
|
-
*
|
|
274
|
-
* @since 1.0.0
|
|
275
|
-
* @category Models
|
|
276
|
-
*/
|
|
277
|
-
export class ReasoningPart extends Schema.TaggedClass<ReasoningPart>(
|
|
278
|
-
"@effect/ai/AiInput/ReasoningPart"
|
|
279
|
-
)("ReasoningPart", {
|
|
280
|
-
/**
|
|
281
|
-
* The reasoning text that the model used to return the output.
|
|
282
|
-
*/
|
|
283
|
-
reasoningText: Schema.String,
|
|
284
|
-
/**
|
|
285
|
-
* An optional signature which verifies that the reasoning text was generated
|
|
286
|
-
* by the model.
|
|
287
|
-
*/
|
|
288
|
-
signature: Schema.optional(Schema.String)
|
|
289
|
-
}) {
|
|
290
|
-
/**
|
|
291
|
-
* @since 1.0.0
|
|
292
|
-
*/
|
|
293
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Represents a part of a message containing content in the model's reasoning
|
|
298
|
-
* that was encrypted by the model provider for safety reasons.
|
|
299
|
-
*
|
|
300
|
-
* @since 1.0.0
|
|
301
|
-
* @category Models
|
|
302
|
-
*/
|
|
303
|
-
export class RedactedReasoningPart extends Schema.TaggedClass<RedactedReasoningPart>(
|
|
304
|
-
"@effect/ai/AiInput/RedactedReasoningPart"
|
|
305
|
-
)("RedactedReasoningPart", {
|
|
306
|
-
/**
|
|
307
|
-
* The content in the reasoning that was encrypted by the model provider for
|
|
308
|
-
* safety reasons.
|
|
309
|
-
*/
|
|
310
|
-
redactedText: Schema.String
|
|
311
|
-
}) {
|
|
312
|
-
/**
|
|
313
|
-
* @since 1.0.0
|
|
314
|
-
*/
|
|
315
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Represents the identifier generated by a model when a tool call is requested.
|
|
320
|
-
*
|
|
321
|
-
* @since 1.0.0
|
|
322
|
-
* @category Models
|
|
323
|
-
*/
|
|
324
|
-
export const ToolCallId: Schema.brand<typeof Schema.String, "@effect/ai/ToolCallId"> = InternalCommon.ToolCallId
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* @since 1.0.0
|
|
328
|
-
* @category Models
|
|
329
|
-
*/
|
|
330
|
-
export type ToolCallId = typeof ToolCallId.Type
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Represents a part of a message containing a tool call that the model has
|
|
334
|
-
* requested invocation of.
|
|
335
|
-
*
|
|
336
|
-
* @since 1.0.0
|
|
337
|
-
* @category Models
|
|
338
|
-
*/
|
|
339
|
-
export class ToolCallPart extends Schema.TaggedClass<ToolCallPart>(
|
|
340
|
-
"@effect/ai/AiInput/ToolCallPart"
|
|
341
|
-
)("ToolCallPart", {
|
|
342
|
-
/**
|
|
343
|
-
* The identifier generated by a model when requesting a tool call.
|
|
344
|
-
*/
|
|
345
|
-
id: ToolCallId,
|
|
346
|
-
/**
|
|
347
|
-
* The name of the tool to call.
|
|
348
|
-
*/
|
|
349
|
-
name: Schema.String,
|
|
350
|
-
/**
|
|
351
|
-
* The arguments to call the tool with as a JSON-serializable object that
|
|
352
|
-
* matches the tool call input schema.
|
|
353
|
-
*/
|
|
354
|
-
params: Schema.Unknown
|
|
355
|
-
}) {
|
|
356
|
-
/**
|
|
357
|
-
* @since 1.0.0
|
|
358
|
-
*/
|
|
359
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
360
|
-
|
|
361
|
-
constructor(props: any, options?: Schema.MakeOptions) {
|
|
362
|
-
super(props, options)
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Represents a part of a message containing the results of tool calls that the
|
|
368
|
-
* model requested invocation of.
|
|
369
|
-
*
|
|
370
|
-
* @since 1.0.0
|
|
371
|
-
* @category Models
|
|
372
|
-
*/
|
|
373
|
-
export class ToolCallResultPart extends Schema.TaggedClass<ToolCallResultPart>(
|
|
374
|
-
"@effect/ai/AiInput/ToolCallResultPart"
|
|
375
|
-
)("ToolCallResultPart", {
|
|
376
|
-
/**
|
|
377
|
-
* The identifier generated by a model when requesting a tool call.
|
|
378
|
-
*/
|
|
379
|
-
id: ToolCallId,
|
|
380
|
-
/**
|
|
381
|
-
* The name of the tool that was called.
|
|
382
|
-
*/
|
|
383
|
-
name: Schema.String,
|
|
384
|
-
/**
|
|
385
|
-
* The result of the tool call as a JSON-serializable object.
|
|
386
|
-
*/
|
|
387
|
-
result: Schema.Unknown
|
|
388
|
-
}) {
|
|
389
|
-
/**
|
|
390
|
-
* @since 1.0.0
|
|
391
|
-
*/
|
|
392
|
-
readonly [PartTypeId]: PartTypeId = PartTypeId
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* The valid parts of a user message.
|
|
397
|
-
*
|
|
398
|
-
* @since 1.0.0
|
|
399
|
-
* @category Models
|
|
400
|
-
*/
|
|
401
|
-
export const UserMessagePart: Schema.Union<[
|
|
402
|
-
typeof TextPart,
|
|
403
|
-
typeof ImagePart,
|
|
404
|
-
typeof ImageUrlPart,
|
|
405
|
-
typeof FilePart,
|
|
406
|
-
typeof FileUrlPart
|
|
407
|
-
]> = Schema.Union(
|
|
408
|
-
TextPart,
|
|
409
|
-
ImagePart,
|
|
410
|
-
ImageUrlPart,
|
|
411
|
-
FilePart,
|
|
412
|
-
FileUrlPart
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* @since 1.0.0
|
|
417
|
-
* @category Models
|
|
418
|
-
*/
|
|
419
|
-
export type UserMessagePart = typeof UserMessagePart.Type
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* The valid parts of an assistant message.
|
|
423
|
-
*
|
|
424
|
-
* @since 1.0.0
|
|
425
|
-
* @category Models
|
|
426
|
-
*/
|
|
427
|
-
export const AssistantMessagePart: Schema.Union<[
|
|
428
|
-
typeof TextPart,
|
|
429
|
-
typeof ReasoningPart,
|
|
430
|
-
typeof RedactedReasoningPart,
|
|
431
|
-
typeof ToolCallPart
|
|
432
|
-
]> = Schema.Union(
|
|
433
|
-
TextPart,
|
|
434
|
-
ReasoningPart,
|
|
435
|
-
RedactedReasoningPart,
|
|
436
|
-
ToolCallPart
|
|
437
|
-
)
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* @since 1.0.0
|
|
441
|
-
* @category Models
|
|
442
|
-
*/
|
|
443
|
-
export type AssistantMessagePart = typeof AssistantMessagePart.Type
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* The valid parts of a tool message.
|
|
447
|
-
*
|
|
448
|
-
* @since 1.0.0
|
|
449
|
-
* @category Models
|
|
450
|
-
*/
|
|
451
|
-
export const ToolMessagePart: typeof ToolCallResultPart = ToolCallResultPart
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* @since 1.0.0
|
|
455
|
-
* @category Models
|
|
456
|
-
*/
|
|
457
|
-
export type ToolMessagePart = typeof ToolMessagePart.Type
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* @since 1.0.0
|
|
461
|
-
* @category Guards
|
|
462
|
-
*/
|
|
463
|
-
export const is = (u: unknown): u is AiInput => Predicate.hasProperty(u, TypeId)
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* @since 1.0.0
|
|
467
|
-
* @category Guards
|
|
468
|
-
*/
|
|
469
|
-
export const isMessage = (u: unknown): u is Message => Predicate.hasProperty(u, MessageTypeId)
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* @since 1.0.0
|
|
473
|
-
* @category Guards
|
|
474
|
-
*/
|
|
475
|
-
export const isPart = (u: unknown): u is UserMessagePart | AssistantMessagePart | ToolMessagePart =>
|
|
476
|
-
Predicate.hasProperty(u, PartTypeId)
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* @since 1.0.0
|
|
480
|
-
* @category Constructors
|
|
481
|
-
*/
|
|
482
|
-
export const empty: AiInput = new AiInput({ messages: [] })
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Constructs a new `AiInput` from raw user input.
|
|
486
|
-
*
|
|
487
|
-
* @since 1.0.0
|
|
488
|
-
* @category Constructors
|
|
489
|
-
*/
|
|
490
|
-
export const make = (input: Raw): AiInput => {
|
|
491
|
-
if (Predicate.isString(input)) {
|
|
492
|
-
const textPart = new TextPart({ text: input })
|
|
493
|
-
const message = new UserMessage({ parts: [textPart] })
|
|
494
|
-
return new AiInput({ messages: [message] })
|
|
495
|
-
}
|
|
496
|
-
if (isMessage(input)) {
|
|
497
|
-
return new AiInput({ messages: [input] })
|
|
498
|
-
}
|
|
499
|
-
if (Predicate.isIterable(input)) {
|
|
500
|
-
return new AiInput({ messages: Array.from(input) })
|
|
501
|
-
}
|
|
502
|
-
if (is(input)) {
|
|
503
|
-
return input
|
|
504
|
-
}
|
|
505
|
-
if (AiResponse.isStructured(input)) {
|
|
506
|
-
const assistantMessages = fromResponse(input).messages
|
|
507
|
-
const toolPart = new ToolCallResultPart({
|
|
508
|
-
id: input.id,
|
|
509
|
-
name: input.name,
|
|
510
|
-
result: input.value
|
|
511
|
-
})
|
|
512
|
-
const toolMessage = new ToolMessage({ parts: [toolPart] })
|
|
513
|
-
return new AiInput({ messages: [...assistantMessages, toolMessage] })
|
|
514
|
-
}
|
|
515
|
-
if (AiResponse.hasToolCallResults(input)) {
|
|
516
|
-
const assistantMessages = fromResponse(input).messages
|
|
517
|
-
const toolParts: Array<ToolCallResultPart> = []
|
|
518
|
-
for (const [id, { name, result }] of input.encodedResults) {
|
|
519
|
-
toolParts.push(new ToolCallResultPart({ id, name, result }))
|
|
520
|
-
}
|
|
521
|
-
const toolMessage = new ToolMessage({ parts: toolParts })
|
|
522
|
-
return new AiInput({ messages: [...assistantMessages, toolMessage] })
|
|
523
|
-
}
|
|
524
|
-
return fromResponse(input)
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const EXCLUDED_RESPONSE_PARTS: Array<AiResponse.Part["_tag"]> = [
|
|
528
|
-
"MetadataPart",
|
|
529
|
-
"ReasoningPart",
|
|
530
|
-
"RedactedReasoningPart",
|
|
531
|
-
"FinishPart"
|
|
532
|
-
]
|
|
533
|
-
|
|
534
|
-
const validResponseParts = (part: AiResponse.Part): part is AiResponse.TextPart | AiResponse.ToolCallPart =>
|
|
535
|
-
!EXCLUDED_RESPONSE_PARTS.includes(part._tag)
|
|
536
|
-
|
|
537
|
-
const fromResponse = (
|
|
538
|
-
response: AiResponse.AiResponse
|
|
539
|
-
): AiInput => {
|
|
540
|
-
if (response.parts.length === 0) {
|
|
541
|
-
return empty
|
|
542
|
-
}
|
|
543
|
-
const parts = response.parts
|
|
544
|
-
.filter(validResponseParts)
|
|
545
|
-
.map((part) =>
|
|
546
|
-
part._tag === "TextPart"
|
|
547
|
-
? new TextPart({ text: part.text })
|
|
548
|
-
: new ToolCallPart({
|
|
549
|
-
id: part.id,
|
|
550
|
-
name: part.name,
|
|
551
|
-
params: part.params
|
|
552
|
-
})
|
|
553
|
-
)
|
|
554
|
-
const message = new AssistantMessage({ parts })
|
|
555
|
-
return new AiInput({ messages: [message] })
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
560
|
-
* creating a new `AiInput` with the messages from both.
|
|
561
|
-
*
|
|
562
|
-
* @since 1.0.0
|
|
563
|
-
* @category Combination
|
|
564
|
-
*/
|
|
565
|
-
export const concat: {
|
|
566
|
-
/**
|
|
567
|
-
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
568
|
-
* creating a new `AiInput` with the messages from both.
|
|
569
|
-
*
|
|
570
|
-
* @since 1.0.0
|
|
571
|
-
* @category Combination
|
|
572
|
-
*/
|
|
573
|
-
(other: AiInput): (self: AiInput) => AiInput
|
|
574
|
-
/**
|
|
575
|
-
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
576
|
-
* creating a new `AiInput` with the messages from both.
|
|
577
|
-
*
|
|
578
|
-
* @since 1.0.0
|
|
579
|
-
* @category Combination
|
|
580
|
-
*/
|
|
581
|
-
(self: AiInput, other: AiInput): AiInput
|
|
582
|
-
} = dual<
|
|
583
|
-
/**
|
|
584
|
-
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
585
|
-
* creating a new `AiInput` with the messages from both.
|
|
586
|
-
*
|
|
587
|
-
* @since 1.0.0
|
|
588
|
-
* @category Combination
|
|
589
|
-
*/
|
|
590
|
-
(other: AiInput) => (self: AiInput) => AiInput,
|
|
591
|
-
/**
|
|
592
|
-
* Concatenates the messages of one `AiInput` onto the messages of another,
|
|
593
|
-
* creating a new `AiInput` with the messages from both.
|
|
594
|
-
*
|
|
595
|
-
* @since 1.0.0
|
|
596
|
-
* @category Combination
|
|
597
|
-
*/
|
|
598
|
-
(self: AiInput, other: AiInput) => AiInput
|
|
599
|
-
>(2, (self, other) =>
|
|
600
|
-
AiInput.make({
|
|
601
|
-
messages: [...self.messages, ...other.messages]
|
|
602
|
-
}))
|