@effect/ai 0.14.1 → 0.16.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.
Files changed (134) hide show
  1. package/AiEmbeddingModel/package.json +6 -0
  2. package/AiLanguageModel/package.json +6 -0
  3. package/AiTool/package.json +6 -0
  4. package/dist/cjs/AiChat.js +65 -86
  5. package/dist/cjs/AiChat.js.map +1 -1
  6. package/dist/cjs/{Embeddings.js → AiEmbeddingModel.js} +12 -12
  7. package/dist/cjs/AiEmbeddingModel.js.map +1 -0
  8. package/dist/cjs/AiError.js +8 -1
  9. package/dist/cjs/AiError.js.map +1 -1
  10. package/dist/cjs/AiInput.js +335 -248
  11. package/dist/cjs/AiInput.js.map +1 -1
  12. package/dist/cjs/AiLanguageModel.js +311 -0
  13. package/dist/cjs/AiLanguageModel.js.map +1 -0
  14. package/dist/cjs/AiModel.js +11 -5
  15. package/dist/cjs/AiModel.js.map +1 -1
  16. package/dist/cjs/AiPlan.js +10 -3
  17. package/dist/cjs/AiPlan.js.map +1 -1
  18. package/dist/cjs/AiResponse.js +481 -165
  19. package/dist/cjs/AiResponse.js.map +1 -1
  20. package/dist/cjs/AiTelemetry.js +10 -3
  21. package/dist/cjs/AiTelemetry.js.map +1 -1
  22. package/dist/cjs/AiTool.js +93 -0
  23. package/dist/cjs/AiTool.js.map +1 -0
  24. package/dist/cjs/AiToolkit.js +121 -98
  25. package/dist/cjs/AiToolkit.js.map +1 -1
  26. package/dist/cjs/Tokenizer.js +14 -16
  27. package/dist/cjs/Tokenizer.js.map +1 -1
  28. package/dist/cjs/index.js +7 -9
  29. package/dist/cjs/internal/aiPlan.js +6 -9
  30. package/dist/cjs/internal/aiPlan.js.map +1 -1
  31. package/dist/cjs/internal/common.js +22 -0
  32. package/dist/cjs/internal/common.js.map +1 -0
  33. package/dist/dts/AiChat.d.ts +58 -44
  34. package/dist/dts/AiChat.d.ts.map +1 -1
  35. package/dist/dts/{Embeddings.d.ts → AiEmbeddingModel.d.ts} +13 -14
  36. package/dist/dts/AiEmbeddingModel.d.ts.map +1 -0
  37. package/dist/dts/AiError.d.ts +4 -3
  38. package/dist/dts/AiError.d.ts.map +1 -1
  39. package/dist/dts/AiInput.d.ts +441 -146
  40. package/dist/dts/AiInput.d.ts.map +1 -1
  41. package/dist/dts/AiLanguageModel.d.ts +263 -0
  42. package/dist/dts/AiLanguageModel.d.ts.map +1 -0
  43. package/dist/dts/AiModel.d.ts +21 -20
  44. package/dist/dts/AiModel.d.ts.map +1 -1
  45. package/dist/dts/AiPlan.d.ts +90 -26
  46. package/dist/dts/AiPlan.d.ts.map +1 -1
  47. package/dist/dts/AiResponse.d.ts +711 -100
  48. package/dist/dts/AiResponse.d.ts.map +1 -1
  49. package/dist/dts/AiTelemetry.d.ts +175 -157
  50. package/dist/dts/AiTelemetry.d.ts.map +1 -1
  51. package/dist/dts/AiTool.d.ts +288 -0
  52. package/dist/dts/AiTool.d.ts.map +1 -0
  53. package/dist/dts/AiToolkit.d.ts +50 -111
  54. package/dist/dts/AiToolkit.d.ts.map +1 -1
  55. package/dist/dts/Tokenizer.d.ts +8 -6
  56. package/dist/dts/Tokenizer.d.ts.map +1 -1
  57. package/dist/dts/index.d.ts +8 -12
  58. package/dist/dts/index.d.ts.map +1 -1
  59. package/dist/dts/internal/common.d.ts +2 -0
  60. package/dist/dts/internal/common.d.ts.map +1 -0
  61. package/dist/esm/AiChat.js +62 -83
  62. package/dist/esm/AiChat.js.map +1 -1
  63. package/dist/esm/{Embeddings.js → AiEmbeddingModel.js} +10 -10
  64. package/dist/esm/AiEmbeddingModel.js.map +1 -0
  65. package/dist/esm/AiError.js +8 -1
  66. package/dist/esm/AiError.js.map +1 -1
  67. package/dist/esm/AiInput.js +316 -238
  68. package/dist/esm/AiInput.js.map +1 -1
  69. package/dist/esm/AiLanguageModel.js +300 -0
  70. package/dist/esm/AiLanguageModel.js.map +1 -0
  71. package/dist/esm/AiModel.js +11 -5
  72. package/dist/esm/AiModel.js.map +1 -1
  73. package/dist/esm/AiPlan.js +8 -2
  74. package/dist/esm/AiPlan.js.map +1 -1
  75. package/dist/esm/AiResponse.js +467 -162
  76. package/dist/esm/AiResponse.js.map +1 -1
  77. package/dist/esm/AiTelemetry.js +8 -2
  78. package/dist/esm/AiTelemetry.js.map +1 -1
  79. package/dist/esm/AiTool.js +82 -0
  80. package/dist/esm/AiTool.js.map +1 -0
  81. package/dist/esm/AiToolkit.js +118 -96
  82. package/dist/esm/AiToolkit.js.map +1 -1
  83. package/dist/esm/Tokenizer.js +14 -16
  84. package/dist/esm/Tokenizer.js.map +1 -1
  85. package/dist/esm/index.js +8 -12
  86. package/dist/esm/index.js.map +1 -1
  87. package/dist/esm/internal/aiPlan.js +4 -7
  88. package/dist/esm/internal/aiPlan.js.map +1 -1
  89. package/dist/esm/internal/common.js +14 -0
  90. package/dist/esm/internal/common.js.map +1 -0
  91. package/package.json +28 -36
  92. package/src/AiChat.ts +182 -207
  93. package/src/{Embeddings.ts → AiEmbeddingModel.ts} +19 -18
  94. package/src/AiError.ts +8 -1
  95. package/src/AiInput.ts +434 -313
  96. package/src/AiLanguageModel.ts +569 -0
  97. package/src/AiModel.ts +47 -29
  98. package/src/AiPlan.ts +102 -30
  99. package/src/AiResponse.ts +743 -187
  100. package/src/AiTelemetry.ts +214 -197
  101. package/src/AiTool.ts +496 -0
  102. package/src/AiToolkit.ts +200 -240
  103. package/src/Tokenizer.ts +18 -22
  104. package/src/index.ts +9 -14
  105. package/src/internal/aiPlan.ts +12 -14
  106. package/src/internal/common.ts +12 -0
  107. package/AiModels/package.json +0 -6
  108. package/AiRole/package.json +0 -6
  109. package/Completions/package.json +0 -6
  110. package/Embeddings/package.json +0 -6
  111. package/dist/cjs/AiModels.js +0 -54
  112. package/dist/cjs/AiModels.js.map +0 -1
  113. package/dist/cjs/AiRole.js +0 -106
  114. package/dist/cjs/AiRole.js.map +0 -1
  115. package/dist/cjs/Completions.js +0 -256
  116. package/dist/cjs/Completions.js.map +0 -1
  117. package/dist/cjs/Embeddings.js.map +0 -1
  118. package/dist/dts/AiModels.d.ts +0 -34
  119. package/dist/dts/AiModels.d.ts.map +0 -1
  120. package/dist/dts/AiRole.d.ts +0 -111
  121. package/dist/dts/AiRole.d.ts.map +0 -1
  122. package/dist/dts/Completions.d.ts +0 -128
  123. package/dist/dts/Completions.d.ts.map +0 -1
  124. package/dist/dts/Embeddings.d.ts.map +0 -1
  125. package/dist/esm/AiModels.js +0 -44
  126. package/dist/esm/AiModels.js.map +0 -1
  127. package/dist/esm/AiRole.js +0 -93
  128. package/dist/esm/AiRole.js.map +0 -1
  129. package/dist/esm/Completions.js +0 -245
  130. package/dist/esm/Completions.js.map +0 -1
  131. package/dist/esm/Embeddings.js.map +0 -1
  132. package/src/AiModels.ts +0 -77
  133. package/src/AiRole.ts +0 -122
  134. package/src/Completions.ts +0 -434
@@ -1,72 +1,517 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
- import * as Chunk from "effect/Chunk";
5
- import * as Data from "effect/Data";
4
+ import type * as Context from "effect/Context";
6
5
  import * as Effect from "effect/Effect";
7
6
  import * as Option from "effect/Option";
8
7
  import * as Schema from "effect/Schema";
9
8
  import { AiError } from "./AiError.js";
10
- import * as AiRole from "./AiRole.js";
9
+ import type * as AiTool from "./AiTool.js";
11
10
  /**
12
11
  * @since 1.0.0
13
- * @category type ids
12
+ * @category Type Ids
14
13
  */
15
14
  export declare const TypeId: unique symbol;
16
15
  /**
17
16
  * @since 1.0.0
18
- * @category type ids
17
+ * @category Type Ids
19
18
  */
20
19
  export type TypeId = typeof TypeId;
20
+ declare const AiResponse_base: Schema.Class<AiResponse, {
21
+ /**
22
+ * The parts of the response.
23
+ */
24
+ parts: Schema.Array$<Schema.suspend<TextPart | ReasoningPart | RedactedReasoningPart | ToolCallPart | MetadataPart | FinishPart, {
25
+ readonly _tag: "TextPart";
26
+ readonly text: string;
27
+ readonly annotations?: readonly ({
28
+ readonly _tag: "ContentSourceAnnotation";
29
+ readonly id: string;
30
+ readonly index: number;
31
+ readonly type: string;
32
+ readonly referencedContent: string;
33
+ readonly startIndex: number;
34
+ readonly endIndex: number;
35
+ } | {
36
+ readonly _tag: "FileAnnotation";
37
+ readonly id: string;
38
+ readonly index: number;
39
+ readonly type: string;
40
+ } | {
41
+ readonly _tag: "UrlAnnotation";
42
+ readonly startIndex: number;
43
+ readonly endIndex: number;
44
+ readonly url: string;
45
+ readonly title: string;
46
+ })[] | undefined;
47
+ } | {
48
+ readonly _tag: "ReasoningPart";
49
+ readonly reasoningText: string;
50
+ readonly signature?: string | undefined;
51
+ } | {
52
+ readonly _tag: "RedactedReasoningPart";
53
+ readonly redactedText: string;
54
+ } | {
55
+ readonly _tag: "ToolCallPart";
56
+ readonly name: string;
57
+ readonly id: string;
58
+ readonly params: unknown;
59
+ } | {
60
+ readonly _tag: "MetadataPart";
61
+ readonly model: string;
62
+ readonly id?: string | undefined;
63
+ readonly timestamp?: number | undefined;
64
+ } | {
65
+ readonly _tag: "FinishPart";
66
+ readonly usage: {
67
+ readonly inputTokens: number;
68
+ readonly outputTokens: number;
69
+ readonly totalTokens: number;
70
+ readonly reasoningTokens: number;
71
+ readonly cacheReadInputTokens: number;
72
+ readonly cacheWriteInputTokens: number;
73
+ };
74
+ readonly reason: "length" | "stop" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
75
+ readonly providerMetadata?: {
76
+ readonly [x: string]: {
77
+ readonly [x: string]: unknown;
78
+ };
79
+ } | undefined;
80
+ }, never>>;
81
+ }, Schema.Struct.Encoded<{
82
+ /**
83
+ * The parts of the response.
84
+ */
85
+ parts: Schema.Array$<Schema.suspend<TextPart | ReasoningPart | RedactedReasoningPart | ToolCallPart | MetadataPart | FinishPart, {
86
+ readonly _tag: "TextPart";
87
+ readonly text: string;
88
+ readonly annotations?: readonly ({
89
+ readonly _tag: "ContentSourceAnnotation";
90
+ readonly id: string;
91
+ readonly index: number;
92
+ readonly type: string;
93
+ readonly referencedContent: string;
94
+ readonly startIndex: number;
95
+ readonly endIndex: number;
96
+ } | {
97
+ readonly _tag: "FileAnnotation";
98
+ readonly id: string;
99
+ readonly index: number;
100
+ readonly type: string;
101
+ } | {
102
+ readonly _tag: "UrlAnnotation";
103
+ readonly startIndex: number;
104
+ readonly endIndex: number;
105
+ readonly url: string;
106
+ readonly title: string;
107
+ })[] | undefined;
108
+ } | {
109
+ readonly _tag: "ReasoningPart";
110
+ readonly reasoningText: string;
111
+ readonly signature?: string | undefined;
112
+ } | {
113
+ readonly _tag: "RedactedReasoningPart";
114
+ readonly redactedText: string;
115
+ } | {
116
+ readonly _tag: "ToolCallPart";
117
+ readonly name: string;
118
+ readonly id: string;
119
+ readonly params: unknown;
120
+ } | {
121
+ readonly _tag: "MetadataPart";
122
+ readonly model: string;
123
+ readonly id?: string | undefined;
124
+ readonly timestamp?: number | undefined;
125
+ } | {
126
+ readonly _tag: "FinishPart";
127
+ readonly usage: {
128
+ readonly inputTokens: number;
129
+ readonly outputTokens: number;
130
+ readonly totalTokens: number;
131
+ readonly reasoningTokens: number;
132
+ readonly cacheReadInputTokens: number;
133
+ readonly cacheWriteInputTokens: number;
134
+ };
135
+ readonly reason: "length" | "stop" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
136
+ readonly providerMetadata?: {
137
+ readonly [x: string]: {
138
+ readonly [x: string]: unknown;
139
+ };
140
+ } | undefined;
141
+ }, never>>;
142
+ }>, never, {
143
+ readonly parts: readonly (TextPart | ReasoningPart | RedactedReasoningPart | ToolCallPart | MetadataPart | FinishPart)[];
144
+ }, {}, {}>;
145
+ /**
146
+ * Represents a response received from a large language model.
147
+ *
148
+ * @since 1.0.0
149
+ * @category Models
150
+ */
151
+ export declare class AiResponse extends AiResponse_base {
152
+ /**
153
+ * @since 1.0.0
154
+ */
155
+ readonly [TypeId]: TypeId;
156
+ /**
157
+ * Returns the generated text content of the response.
158
+ */
159
+ get text(): string;
160
+ /**
161
+ * Returns the finish reason for the response, or `"unknown"` if the finish
162
+ * reason is not known.
163
+ */
164
+ get finishReason(): FinishReason;
165
+ /**
166
+ * Attempts to retrieve provider-specific response metadata.
167
+ */
168
+ getProviderMetadata<I, S>(tag: Context.Tag<I, S>): Option.Option<S>;
169
+ }
170
+ /**
171
+ * @since 1.0.0
172
+ * @category Models
173
+ */
174
+ export declare const FromJson: Schema.transform<Schema.SchemaClass<unknown, string, never>, typeof AiResponse>;
21
175
  /**
22
176
  * @since 1.0.0
23
- * @category parts
177
+ * @category Type Ids
178
+ */
179
+ export declare const StructuredResponseTypeId: unique symbol;
180
+ /**
181
+ * @since 1.0.0
182
+ * @category Type Ids
183
+ */
184
+ export type StructuredResponseTypeId = typeof StructuredResponseTypeId;
185
+ /**
186
+ * Represents a response generated by a large language model that includes
187
+ * structured output.
188
+ *
189
+ * @since 1.0.0
190
+ * @category Models
191
+ */
192
+ export declare class WithStructuredOutput<A> extends AiResponse {
193
+ /**
194
+ * @since 1.0.0
195
+ */
196
+ readonly [StructuredResponseTypeId]: StructuredResponseTypeId;
197
+ /**
198
+ * The identifier of the tool which generated the structured output.
199
+ */
200
+ readonly id: ToolCallId;
201
+ /**
202
+ * The name of the tool which generated the structured output.
203
+ */
204
+ readonly name: string;
205
+ /**
206
+ * The structured output generated by the model.
207
+ */
208
+ readonly value: A;
209
+ constructor(props: {
210
+ /**
211
+ * The identifier of the tool which generated the structured output.
212
+ */
213
+ readonly id: ToolCallId;
214
+ /**
215
+ * The name of the tool which generated the structured output.
216
+ */
217
+ readonly name: string;
218
+ /**
219
+ * The structured output generated by the model.
220
+ */
221
+ readonly value: A;
222
+ /**
223
+ * The parts of the response.
224
+ */
225
+ readonly parts: ReadonlyArray<Part>;
226
+ }, options?: Schema.MakeOptions);
227
+ }
228
+ /**
229
+ * @since 1.0.0
230
+ * @category Type Ids
231
+ */
232
+ export declare const WithToolCallResultsTypeId: unique symbol;
233
+ /**
234
+ * @since 1.0.0
235
+ * @category Type Ids
236
+ */
237
+ export type WithToolCallResultsTypeId = typeof WithToolCallResultsTypeId;
238
+ /**
239
+ * Represents a response generated by a large language model that includes
240
+ * tool call results.
241
+ *
242
+ * @since 1.0.0
243
+ * @category Models
244
+ */
245
+ export declare class WithToolCallResults<Tools extends AiTool.Any> extends AiResponse {
246
+ /**
247
+ * @since 1.0.0
248
+ */
249
+ readonly [WithToolCallResultsTypeId]: WithToolCallResultsTypeId;
250
+ /**
251
+ * The tool call results, represented as a mapping between the tool call
252
+ * identifier and the result of the tool call handler.
253
+ */
254
+ readonly results: ReadonlyMap<ToolCallId, AiTool.Success<Tools>>;
255
+ /**
256
+ * The encoded tool call results, suitable for incorporation into subsequent
257
+ * requests to the large language model.
258
+ */
259
+ readonly encodedResults: ReadonlyMap<ToolCallId, unknown>;
260
+ constructor(props: {
261
+ /**
262
+ * The tool call results, represented as a mapping between the tool call
263
+ * identifier and the result of the tool call handler.
264
+ */
265
+ readonly results: ReadonlyMap<ToolCallId, AiTool.Success<Tools>>;
266
+ /**
267
+ * The encoded tool call results, suitable for incorporation into subsequent
268
+ * requests to the large language model.
269
+ */
270
+ readonly encodedResults: ReadonlyMap<ToolCallId, unknown>;
271
+ /**
272
+ * The parts of the response.
273
+ */
274
+ readonly parts: ReadonlyArray<Part>;
275
+ }, options?: Schema.MakeOptions);
276
+ }
277
+ /**
278
+ * @since 1.0.0
279
+ * @category Type Ids
24
280
  */
25
281
  export declare const PartTypeId: unique symbol;
26
282
  /**
27
283
  * @since 1.0.0
28
- * @category parts
284
+ * @category Type Ids
29
285
  */
30
286
  export type PartTypeId = typeof PartTypeId;
31
- declare const TextPart_base: Schema.TaggedClass<TextPart, "Text", {
32
- readonly _tag: Schema.tag<"Text">;
287
+ declare const ContentSourceAnnotation_base: Schema.TaggedClass<ContentSourceAnnotation, "ContentSourceAnnotation", {
288
+ readonly _tag: Schema.tag<"ContentSourceAnnotation">;
33
289
  } & {
34
- content: typeof Schema.String;
290
+ /**
291
+ * The identifier for the content source.
292
+ */
293
+ id: typeof Schema.String;
294
+ /**
295
+ * The index of the content source in the list of sources provided in the
296
+ * model request parameters.
297
+ */
298
+ index: typeof Schema.Int;
299
+ /**
300
+ * The provider-specific type of the file annotation.
301
+ *
302
+ * For example, when using Anthropic the type may be `char_location`,
303
+ * `page_location`, or `content_block_location`.
304
+ */
305
+ type: typeof Schema.String;
306
+ /**
307
+ * The content used from the content source in the message generated by the
308
+ * model.
309
+ */
310
+ referencedContent: typeof Schema.String;
311
+ /**
312
+ * The index of the first character of the content referenced by the content
313
+ * source in the message generated by the model.
314
+ */
315
+ startIndex: typeof Schema.Int;
316
+ /**
317
+ * The index of the last character of the content referenced by the content
318
+ * source in the message generated by the model.
319
+ */
320
+ endIndex: typeof Schema.Int;
35
321
  }>;
36
322
  /**
323
+ * Represents a content source that was used to generate a model response.
324
+ *
37
325
  * @since 1.0.0
38
- * @category parts
326
+ * @category Models
327
+ */
328
+ export declare class ContentSourceAnnotation extends ContentSourceAnnotation_base {
329
+ }
330
+ declare const FileAnnotation_base: Schema.TaggedClass<FileAnnotation, "FileAnnotation", {
331
+ readonly _tag: Schema.tag<"FileAnnotation">;
332
+ } & {
333
+ /**
334
+ * The identifier for the file.
335
+ */
336
+ id: typeof Schema.String;
337
+ /**
338
+ * The provider-specific type of the file annotation.
339
+ *
340
+ * For example, when using OpenAi the type may be `file_citation` or
341
+ * `file_path`.
342
+ */
343
+ type: typeof Schema.String;
344
+ /**
345
+ * The index of the file in the list of files provided in the model request
346
+ * parameters.
347
+ */
348
+ index: typeof Schema.Int;
349
+ }>;
350
+ /**
351
+ * Represents a file that was used to generate a model response.
352
+ *
353
+ * @since 1.0.0
354
+ * @category Models
355
+ */
356
+ export declare class FileAnnotation extends FileAnnotation_base {
357
+ }
358
+ declare const UrlAnnotation_base: Schema.TaggedClass<UrlAnnotation, "UrlAnnotation", {
359
+ readonly _tag: Schema.tag<"UrlAnnotation">;
360
+ } & {
361
+ /**
362
+ * The URL of the web resource.
363
+ */
364
+ url: typeof Schema.String;
365
+ /**
366
+ * The title of the web resource.
367
+ */
368
+ title: typeof Schema.String;
369
+ /**
370
+ * The index of the first character of the content referenced by the web
371
+ * resource in the message generated by the model.
372
+ */
373
+ startIndex: typeof Schema.Int;
374
+ /**
375
+ * The index of the last character of the content referenced by the web
376
+ * resource in the message generated by the model.
377
+ */
378
+ endIndex: typeof Schema.Int;
379
+ }>;
380
+ /**
381
+ * Represents a web resource that was used to generate a model response.
382
+ *
383
+ * @since 1.0.0
384
+ * @category Models
385
+ */
386
+ export declare class UrlAnnotation extends UrlAnnotation_base {
387
+ }
388
+ /**
389
+ * Represents annotations that were used to support the message generated by
390
+ * a model.
391
+ *
392
+ * @since 1.0.0
393
+ * @category Models
394
+ */
395
+ export declare const Annotation: Schema.Union<[
396
+ typeof ContentSourceAnnotation,
397
+ typeof FileAnnotation,
398
+ typeof UrlAnnotation
399
+ ]>;
400
+ /**
401
+ * @since 1.0.0
402
+ * @category Models
403
+ */
404
+ export type Annotation = typeof Annotation.Type;
405
+ declare const TextPart_base: Schema.TaggedClass<TextPart, "TextPart", {
406
+ readonly _tag: Schema.tag<"TextPart">;
407
+ } & {
408
+ /**
409
+ * The text content generated by the model.
410
+ */
411
+ text: typeof Schema.String;
412
+ /**
413
+ * The annotations used to support the text generated by the model.
414
+ */
415
+ annotations: Schema.optionalWith<Schema.Array$<Schema.Union<[typeof ContentSourceAnnotation, typeof FileAnnotation, typeof UrlAnnotation]>>, {
416
+ default: () => never[];
417
+ }>;
418
+ }>;
419
+ /**
420
+ * Represents part of the text generated by the model.
421
+ *
422
+ * @since 1.0.0
423
+ * @category Models
39
424
  */
40
425
  export declare class TextPart extends TextPart_base {
41
426
  /**
42
427
  * @since 1.0.0
43
428
  */
44
429
  readonly [PartTypeId]: PartTypeId;
430
+ }
431
+ declare const ReasoningPart_base: Schema.TaggedClass<ReasoningPart, "ReasoningPart", {
432
+ readonly _tag: Schema.tag<"ReasoningPart">;
433
+ } & {
434
+ /**
435
+ * The reasoning content that the model used to return the output.
436
+ */
437
+ reasoningText: typeof Schema.String;
438
+ /**
439
+ * An optional signature which verifies that the reasoning text was generated
440
+ * by the model.
441
+ */
442
+ signature: Schema.optional<typeof Schema.String>;
443
+ }>;
444
+ /**
445
+ * Represents part of the reasoning carried out by the model to generate a
446
+ * response.
447
+ *
448
+ * @since 1.0.0
449
+ * @category Models
450
+ */
451
+ export declare class ReasoningPart extends ReasoningPart_base {
452
+ /**
453
+ * @since 1.0.0
454
+ */
455
+ readonly [PartTypeId]: PartTypeId;
456
+ }
457
+ declare const RedactedReasoningPart_base: Schema.TaggedClass<RedactedReasoningPart, "RedactedReasoningPart", {
458
+ readonly _tag: Schema.tag<"RedactedReasoningPart">;
459
+ } & {
460
+ /**
461
+ * The content in the reasoning that was encrypted by the model provider for
462
+ * safety reasons.
463
+ */
464
+ redactedText: typeof Schema.String;
465
+ }>;
466
+ /**
467
+ * Represents part of the reasoning carried out by the model to generate a
468
+ * response which needed to be encrypted by the model provider for safety
469
+ * reasons.
470
+ *
471
+ * @since 1.0.0
472
+ * @category Models
473
+ */
474
+ export declare class RedactedReasoningPart extends RedactedReasoningPart_base {
45
475
  /**
46
476
  * @since 1.0.0
47
477
  */
48
- static fromContent(content: string): TextPart;
478
+ readonly [PartTypeId]: PartTypeId;
49
479
  }
50
480
  /**
481
+ * Represents the identifier generated by a model when a tool call is requested.
482
+ *
51
483
  * @since 1.0.0
52
- * @category parts
484
+ * @category Models
53
485
  */
54
- export declare const ToolCallId: Schema.brand<typeof Schema.String, "ToolCallId">;
486
+ export declare const ToolCallId: Schema.brand<typeof Schema.String, "@effect/ai/ToolCallId">;
55
487
  /**
56
488
  * @since 1.0.0
57
- * @category parts
489
+ * @category Models
58
490
  */
59
491
  export type ToolCallId = typeof ToolCallId.Type;
60
- declare const ToolCallPart_base: Schema.TaggedClass<ToolCallPart, "ToolCall", {
61
- readonly _tag: Schema.tag<"ToolCall">;
492
+ declare const ToolCallPart_base: Schema.TaggedClass<ToolCallPart, "ToolCallPart", {
493
+ readonly _tag: Schema.tag<"ToolCallPart">;
62
494
  } & {
63
- id: Schema.brand<typeof Schema.String, "ToolCallId">;
495
+ /**
496
+ * The identifier generated by a model when requesting a tool call.
497
+ */
498
+ id: Schema.brand<typeof Schema.String, "@effect/ai/ToolCallId">;
499
+ /**
500
+ * The name of the tool to call.
501
+ */
64
502
  name: typeof Schema.String;
503
+ /**
504
+ * The arguments to call the tool with as a JSON-serializable object that
505
+ * matches the tool call input schema.
506
+ */
65
507
  params: typeof Schema.Unknown;
66
508
  }>;
67
509
  /**
510
+ * Represents a request by a model to call a specific tool that it has been
511
+ * provided with.
512
+ *
68
513
  * @since 1.0.0
69
- * @category parts
514
+ * @category Models
70
515
  */
71
516
  export declare class ToolCallPart extends ToolCallPart_base {
72
517
  /**
@@ -74,6 +519,10 @@ export declare class ToolCallPart extends ToolCallPart_base {
74
519
  */
75
520
  readonly [PartTypeId]: PartTypeId;
76
521
  /**
522
+ * Converts a raw tool call into a `ToolCallPart` by parsing tool call
523
+ * parameters as a JSON string. If your tool call parameters are already
524
+ * parsed, use `ToolCallPart.fromUnknown`.
525
+ *
77
526
  * @since 1.0.0
78
527
  */
79
528
  static fromJson({ id, name, params }: {
@@ -82,6 +531,10 @@ export declare class ToolCallPart extends ToolCallPart_base {
82
531
  readonly params: string;
83
532
  }): Effect.Effect<ToolCallPart, AiError>;
84
533
  /**
534
+ * Converts a raw tool call into a `ToolCallPart` assuming that the tool call
535
+ * parameters have already been parsed. If your tool call parameters have not
536
+ * already been parsed, use `ToolCallPart.fromJson`.
537
+ *
85
538
  * @since 1.0.0
86
539
  */
87
540
  static fromUnknown({ id, name, params }: {
@@ -90,146 +543,304 @@ export declare class ToolCallPart extends ToolCallPart_base {
90
543
  readonly params: unknown;
91
544
  }): ToolCallPart;
92
545
  }
93
- declare const ImageUrlPart_base: Schema.TaggedClass<ImageUrlPart, "ImageUrl", {
94
- readonly _tag: Schema.tag<"ImageUrl">;
546
+ declare const MetadataPart_base: Schema.TaggedClass<MetadataPart, "MetadataPart", {
547
+ readonly _tag: Schema.tag<"MetadataPart">;
95
548
  } & {
96
- url: typeof Schema.String;
549
+ /**
550
+ * The unique identifier for the response. Each chunk of the response should
551
+ * have the same identifier.
552
+ */
553
+ id: Schema.optional<typeof Schema.String>;
554
+ /**
555
+ * The model that was used to generate the response.
556
+ */
557
+ model: typeof Schema.String;
558
+ /**
559
+ * The Unix timestamp of when the model began generated the response.
560
+ */
561
+ timestamp: Schema.optional<typeof Schema.DateFromNumber>;
97
562
  }>;
98
563
  /**
564
+ * Represents the initial response metadata generated by a model when responding
565
+ * to a request.
566
+ *
99
567
  * @since 1.0.0
100
- * @category parts
568
+ * @categor Models
101
569
  */
102
- export declare class ImageUrlPart extends ImageUrlPart_base {
570
+ export declare class MetadataPart extends MetadataPart_base {
103
571
  /**
104
572
  * @since 1.0.0
105
573
  */
106
574
  readonly [PartTypeId]: PartTypeId;
107
575
  }
108
576
  /**
577
+ * Represents the reason why a model finished generation of a response.
578
+ *
579
+ * Possible finish reasons:
580
+ * - `"stop"`: The model generated a stop sequence.
581
+ * - `"length"`: The model exceeded its token budget.
582
+ * - `"content-filter"`: The model generated content which violated a content filter.
583
+ * - `"tool-calls"`: The model triggered a tool call.
584
+ * - `"error"`: The model encountered an error.
585
+ * - `"other"`: The model stopped for a reason not supported by this protocol.
586
+ * - `"unknown"`: The model did not specify a finish reason.
587
+ *
109
588
  * @since 1.0.0
110
- * @category parts
111
- */
112
- export type Part = TextPart | ToolCallPart | ImageUrlPart;
113
- /**
114
- * @since 1.0.0
115
- * @category parts
589
+ * @category Models
116
590
  */
117
- export declare const Part: Schema.Union<[
118
- typeof TextPart,
119
- typeof ToolCallPart,
120
- typeof ImageUrlPart
591
+ export declare const FinishReason: Schema.Literal<[
592
+ "stop",
593
+ "length",
594
+ "content-filter",
595
+ "tool-calls",
596
+ "error",
597
+ "other",
598
+ "unknown"
121
599
  ]>;
122
- declare const AiResponse_base: Schema.Class<AiResponse, {
123
- role: Schema.Union<[typeof AiRole.User, typeof AiRole.UserWithName, typeof AiRole.Model]>;
124
- parts: Schema.Chunk<Schema.Union<[typeof TextPart, typeof ToolCallPart, typeof ImageUrlPart]>>;
125
- }, Schema.Struct.Encoded<{
126
- role: Schema.Union<[typeof AiRole.User, typeof AiRole.UserWithName, typeof AiRole.Model]>;
127
- parts: Schema.Chunk<Schema.Union<[typeof TextPart, typeof ToolCallPart, typeof ImageUrlPart]>>;
128
- }>, never, {
129
- readonly role: AiRole.User | AiRole.UserWithName | AiRole.Model;
130
- } & {
131
- readonly parts: Chunk.Chunk<TextPart | ToolCallPart | ImageUrlPart>;
132
- }, {}, {}>;
133
600
  /**
134
601
  * @since 1.0.0
135
- * @category models
602
+ * @category Models
136
603
  */
137
- export declare class AiResponse extends AiResponse_base {
604
+ export type FinishReason = typeof FinishReason.Type;
605
+ declare const Usage_base: Schema.Class<Usage, {
138
606
  /**
139
- * @since 1.0.0
607
+ * The number of tokens sent in the request to the model.
140
608
  */
141
- readonly [TypeId]: TypeId;
609
+ inputTokens: typeof Schema.Number;
142
610
  /**
143
- * @since 1.0.0
611
+ * The number of tokens that the model generated for the request.
144
612
  */
145
- static is(u: unknown): u is AiResponse;
613
+ outputTokens: typeof Schema.Number;
146
614
  /**
147
- * @since 1.0.0
615
+ * The total of number of input tokens and output tokens generated by the
616
+ * model.
148
617
  */
149
- static readonly empty: AiResponse;
618
+ totalTokens: typeof Schema.Number;
150
619
  /**
151
- * @since 1.0.0
620
+ * The number of reasoning tokens that the model used to generate the output
621
+ * for the request.
152
622
  */
153
- static fromText(options: {
154
- role: AiRole.AiRole;
155
- content: string;
156
- }): AiResponse;
623
+ reasoningTokens: typeof Schema.Number;
157
624
  /**
158
- * @since 1.0.0
625
+ * The number of input tokens read from the prompt cache for the request.
159
626
  */
160
- get text(): string;
627
+ cacheReadInputTokens: typeof Schema.Number;
161
628
  /**
162
- * @since 1.0.0
629
+ * The number of input tokens written to the prompt cache for the request.
163
630
  */
164
- get imageUrl(): Option.Option<string>;
631
+ cacheWriteInputTokens: typeof Schema.Number;
632
+ }, Schema.Struct.Encoded<{
165
633
  /**
166
- * @since 1.0.0
634
+ * The number of tokens sent in the request to the model.
167
635
  */
168
- withToolCallsJson(calls: Iterable<{
169
- readonly id: string;
170
- readonly name: string;
171
- readonly params: string;
172
- }>): Effect.Effect<AiResponse, AiError>;
636
+ inputTokens: typeof Schema.Number;
173
637
  /**
174
- * @since 1.0.0
638
+ * The number of tokens that the model generated for the request.
175
639
  */
176
- withToolCallsUnknown(calls: Iterable<{
177
- readonly id: string;
178
- readonly name: string;
179
- readonly params: unknown;
180
- }>): AiResponse;
640
+ outputTokens: typeof Schema.Number;
181
641
  /**
182
- * @since 1.0.0
642
+ * The total of number of input tokens and output tokens generated by the
643
+ * model.
183
644
  */
184
- concat(that: AiResponse): AiResponse;
185
- }
186
- /**
187
- * @since 1.0.0
188
- * @category tools
189
- */
190
- export declare const WithResolvedTypeId: unique symbol;
645
+ totalTokens: typeof Schema.Number;
646
+ /**
647
+ * The number of reasoning tokens that the model used to generate the output
648
+ * for the request.
649
+ */
650
+ reasoningTokens: typeof Schema.Number;
651
+ /**
652
+ * The number of input tokens read from the prompt cache for the request.
653
+ */
654
+ cacheReadInputTokens: typeof Schema.Number;
655
+ /**
656
+ * The number of input tokens written to the prompt cache for the request.
657
+ */
658
+ cacheWriteInputTokens: typeof Schema.Number;
659
+ }>, never, {
660
+ readonly inputTokens: number;
661
+ } & {
662
+ readonly outputTokens: number;
663
+ } & {
664
+ readonly totalTokens: number;
665
+ } & {
666
+ readonly reasoningTokens: number;
667
+ } & {
668
+ readonly cacheReadInputTokens: number;
669
+ } & {
670
+ readonly cacheWriteInputTokens: number;
671
+ }, {}, {}>;
191
672
  /**
673
+ * Represents information about the number of tokens used by the model to
674
+ * generate a response.
675
+ *
192
676
  * @since 1.0.0
193
- * @category tools
677
+ * @category Models
194
678
  */
195
- export type WithResolvedTypeId = typeof WithResolvedTypeId;
679
+ export declare class Usage extends Usage_base {
680
+ }
196
681
  /**
682
+ * Represents additional provider-specific metadata that was returned by the
683
+ * model. Specific providers will use module augmentation to add their own
684
+ * specific provider metadata.
685
+ *
686
+ * The outer record is keyed by provider name, while the inner record is keyed
687
+ * by the names of the provider-specific metadata properties.
688
+ *
689
+ * For example:
690
+ *
691
+ * ```ts
692
+ * const providerMeta = {
693
+ * "amazon-bedrock": {
694
+ * // Provider specific metadata
695
+ * }
696
+ * }
697
+ * ```
698
+ *
197
699
  * @since 1.0.0
198
- * @category tools
700
+ * @category Models
199
701
  */
200
- export declare class WithResolved<A> extends Data.Class<{
201
- readonly response: AiResponse;
202
- readonly resolved: ReadonlyMap<ToolCallId, A>;
203
- readonly encoded: ReadonlyMap<ToolCallId, unknown>;
204
- }> {
702
+ export interface ProviderMetadata {
703
+ }
704
+ declare const FinishPart_base: Schema.TaggedClass<FinishPart, "FinishPart", {
705
+ readonly _tag: Schema.tag<"FinishPart">;
706
+ } & {
205
707
  /**
206
- * @since 1.0.0
708
+ * The usage information for the response.
207
709
  */
208
- readonly [WithResolvedTypeId]: WithResolvedTypeId;
710
+ usage: typeof Usage;
209
711
  /**
210
- * @since 1.0.0
712
+ * The reason the model finished generating a response.
713
+ */
714
+ reason: Schema.Literal<["stop", "length", "content-filter", "tool-calls", "error", "other", "unknown"]>;
715
+ /**
716
+ * Provider-specific metadata associated with the response.
211
717
  */
212
- static is<A>(u: unknown): u is WithResolved<A>;
718
+ providerMetadata: Schema.optionalWith<Schema.Record$<typeof Schema.String, Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>, {
719
+ default: () => {};
720
+ }>;
721
+ }>;
722
+ /**
723
+ * Represents the final part of a response generated by a large language model.
724
+ *
725
+ * Contains useful information such as tokens used as part of the interaction
726
+ * with the model.
727
+ *
728
+ * @since 1.0.0
729
+ * @category Models
730
+ */
731
+ export declare class FinishPart extends FinishPart_base {
213
732
  /**
214
733
  * @since 1.0.0
215
734
  */
216
- static readonly empty: WithResolved<never>;
735
+ readonly [PartTypeId]: PartTypeId;
736
+ }
737
+ /**
738
+ * Represents an single part of a response received from a large language model.
739
+ *
740
+ * @since 1.0.0
741
+ * @category Models
742
+ */
743
+ export declare const Part: Schema.Union<[
744
+ typeof TextPart,
745
+ typeof ReasoningPart,
746
+ typeof RedactedReasoningPart,
747
+ typeof ToolCallPart,
748
+ typeof MetadataPart,
749
+ typeof FinishPart
750
+ ]>;
751
+ /**
752
+ * @since 1.0.0
753
+ * @category Models
754
+ */
755
+ export type Part = typeof Part.Type;
756
+ /**
757
+ * @since 1.0.0
758
+ * @category Guards
759
+ */
760
+ export declare const is: (u: unknown) => u is AiResponse;
761
+ /**
762
+ * @since 1.0.0
763
+ * @category Guards
764
+ */
765
+ export declare const isPart: (u: unknown) => u is Part;
766
+ /**
767
+ * @since 1.0.0
768
+ * @category Guards
769
+ */
770
+ export declare const isStructured: (u: unknown) => u is WithStructuredOutput<any>;
771
+ /**
772
+ * @since 1.0.0
773
+ * @category Guards
774
+ */
775
+ export declare const hasToolCallResults: (u: unknown) => u is WithToolCallResults<any>;
776
+ /**
777
+ * @since 1.0.0
778
+ * @category Constructors
779
+ */
780
+ export declare const empty: AiResponse;
781
+ /**
782
+ * Combines two responses into a single response.
783
+ *
784
+ * @since 1.0.0
785
+ * @category Combination
786
+ */
787
+ export declare const merge: {
217
788
  /**
789
+ * Combines two responses into a single response.
790
+ *
218
791
  * @since 1.0.0
792
+ * @category Combination
219
793
  */
220
- get values(): Array<A>;
794
+ (other: AiResponse): (self: AiResponse) => AiResponse;
221
795
  /**
796
+ * Combines two responses into a single response.
797
+ *
222
798
  * @since 1.0.0
799
+ * @category Combination
223
800
  */
224
- get value(): Option.Option<A>;
801
+ (self: AiResponse, other: AiResponse): AiResponse;
802
+ };
803
+ /**
804
+ * Adds the specified tool calls to the provided `AiResponse`.
805
+ *
806
+ * **NOTE**: With this method, the tool call parameters will be parsed as a
807
+ * JSON string. If your tool call parameters are already parsed, use
808
+ * `AiResponse.withToolCallsUnknown`.
809
+ *
810
+ * @since 1.0.0
811
+ * @category Combination
812
+ */
813
+ export declare const withToolCallsJson: {
225
814
  /**
815
+ * Adds the specified tool calls to the provided `AiResponse`.
816
+ *
817
+ * **NOTE**: With this method, the tool call parameters will be parsed as a
818
+ * JSON string. If your tool call parameters are already parsed, use
819
+ * `AiResponse.withToolCallsUnknown`.
820
+ *
226
821
  * @since 1.0.0
822
+ * @category Combination
227
823
  */
228
- get unsafeValue(): A;
824
+ (toolCalls: Iterable<{
825
+ readonly id: string;
826
+ readonly name: string;
827
+ readonly params: string;
828
+ }>): (self: AiResponse) => Effect.Effect<AiResponse, AiError>;
229
829
  /**
830
+ * Adds the specified tool calls to the provided `AiResponse`.
831
+ *
832
+ * **NOTE**: With this method, the tool call parameters will be parsed as a
833
+ * JSON string. If your tool call parameters are already parsed, use
834
+ * `AiResponse.withToolCallsUnknown`.
835
+ *
230
836
  * @since 1.0.0
837
+ * @category Combination
231
838
  */
232
- concat<B>(that: WithResolved<B>): WithResolved<A | B>;
233
- }
839
+ (self: AiResponse, toolCalls: Iterable<{
840
+ readonly id: string;
841
+ readonly name: string;
842
+ readonly params: string;
843
+ }>): Effect.Effect<AiResponse, AiError>;
844
+ };
234
845
  export {};
235
846
  //# sourceMappingURL=AiResponse.d.ts.map