ai 3.1.1 → 3.1.2
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/dist/index.d.mts +31 -4
- package/dist/index.d.ts +31 -4
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
@@ -303,7 +303,16 @@ The schema of the object that the model should generate.
|
|
303
303
|
*/
|
304
304
|
schema: z.Schema<T>;
|
305
305
|
/**
|
306
|
-
The mode to use for object generation.
|
306
|
+
The mode to use for object generation.
|
307
|
+
|
308
|
+
The Zod schema is converted in a JSON schema and used in one of the following ways
|
309
|
+
|
310
|
+
- 'auto': The provider will choose the best mode for the model.
|
311
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
312
|
+
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
|
313
|
+
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
|
314
|
+
|
315
|
+
Please note that most providers do not support all modes.
|
307
316
|
|
308
317
|
Default and recommended: 'auto' (best mode for the model).
|
309
318
|
*/
|
@@ -423,10 +432,19 @@ The schema of the object that the model should generate.
|
|
423
432
|
*/
|
424
433
|
schema: z.Schema<T>;
|
425
434
|
/**
|
426
|
-
The mode to use for object generation.
|
435
|
+
The mode to use for object generation.
|
436
|
+
|
437
|
+
The Zod schema is converted in a JSON schema and used in one of the following ways
|
438
|
+
|
439
|
+
- 'auto': The provider will choose the best mode for the model.
|
440
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
441
|
+
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
|
442
|
+
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
|
443
|
+
|
444
|
+
Please note that most providers do not support all modes.
|
427
445
|
|
428
446
|
Default and recommended: 'auto' (best mode for the model).
|
429
|
-
|
447
|
+
*/
|
430
448
|
mode?: 'auto' | 'json' | 'tool' | 'grammar';
|
431
449
|
}): Promise<StreamObjectResult<T>>;
|
432
450
|
type ObjectStreamPartInput = {
|
@@ -764,7 +782,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
764
782
|
A result object for accessing different stream types and additional information.
|
765
783
|
*/
|
766
784
|
declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
767
|
-
private
|
785
|
+
private originalStream;
|
768
786
|
/**
|
769
787
|
Warnings from the model provider (e.g. unsupported settings)
|
770
788
|
*/
|
@@ -786,6 +804,15 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
786
804
|
};
|
787
805
|
});
|
788
806
|
/**
|
807
|
+
Split out a new stream from the original stream.
|
808
|
+
The original stream is replaced to allow for further splitting,
|
809
|
+
since we do not know how many times the stream will be split.
|
810
|
+
|
811
|
+
Note: this leads to buffering the stream content on the server.
|
812
|
+
However, the LLM results are expected to be small enough to not cause issues.
|
813
|
+
*/
|
814
|
+
private teeStream;
|
815
|
+
/**
|
789
816
|
A text stream that returns only the generated text deltas. You can use it
|
790
817
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
791
818
|
stream will throw the error.
|
package/dist/index.d.ts
CHANGED
@@ -303,7 +303,16 @@ The schema of the object that the model should generate.
|
|
303
303
|
*/
|
304
304
|
schema: z.Schema<T>;
|
305
305
|
/**
|
306
|
-
The mode to use for object generation.
|
306
|
+
The mode to use for object generation.
|
307
|
+
|
308
|
+
The Zod schema is converted in a JSON schema and used in one of the following ways
|
309
|
+
|
310
|
+
- 'auto': The provider will choose the best mode for the model.
|
311
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
312
|
+
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
|
313
|
+
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
|
314
|
+
|
315
|
+
Please note that most providers do not support all modes.
|
307
316
|
|
308
317
|
Default and recommended: 'auto' (best mode for the model).
|
309
318
|
*/
|
@@ -423,10 +432,19 @@ The schema of the object that the model should generate.
|
|
423
432
|
*/
|
424
433
|
schema: z.Schema<T>;
|
425
434
|
/**
|
426
|
-
The mode to use for object generation.
|
435
|
+
The mode to use for object generation.
|
436
|
+
|
437
|
+
The Zod schema is converted in a JSON schema and used in one of the following ways
|
438
|
+
|
439
|
+
- 'auto': The provider will choose the best mode for the model.
|
440
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
441
|
+
- 'json': The JSON schema and a instruction is injected into the prompt. If the provider supports JSON mode, it is enabled.
|
442
|
+
- 'grammar': The provider is instructed to converted the JSON schema into a provider specific grammar and use it to select the output tokens.
|
443
|
+
|
444
|
+
Please note that most providers do not support all modes.
|
427
445
|
|
428
446
|
Default and recommended: 'auto' (best mode for the model).
|
429
|
-
|
447
|
+
*/
|
430
448
|
mode?: 'auto' | 'json' | 'tool' | 'grammar';
|
431
449
|
}): Promise<StreamObjectResult<T>>;
|
432
450
|
type ObjectStreamPartInput = {
|
@@ -764,7 +782,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
764
782
|
A result object for accessing different stream types and additional information.
|
765
783
|
*/
|
766
784
|
declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
767
|
-
private
|
785
|
+
private originalStream;
|
768
786
|
/**
|
769
787
|
Warnings from the model provider (e.g. unsupported settings)
|
770
788
|
*/
|
@@ -786,6 +804,15 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
786
804
|
};
|
787
805
|
});
|
788
806
|
/**
|
807
|
+
Split out a new stream from the original stream.
|
808
|
+
The original stream is replaced to allow for further splitting,
|
809
|
+
since we do not know how many times the stream will be split.
|
810
|
+
|
811
|
+
Note: this leads to buffering the stream content on the server.
|
812
|
+
However, the LLM results are expected to be small enough to not cause issues.
|
813
|
+
*/
|
814
|
+
private teeStream;
|
815
|
+
/**
|
789
816
|
A text stream that returns only the generated text deltas. You can use it
|
790
817
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
791
818
|
stream will throw the error.
|
package/dist/index.js
CHANGED
@@ -1491,12 +1491,25 @@ var StreamTextResult = class {
|
|
1491
1491
|
this.rawResponse = rawResponse;
|
1492
1492
|
}
|
1493
1493
|
/**
|
1494
|
+
Split out a new stream from the original stream.
|
1495
|
+
The original stream is replaced to allow for further splitting,
|
1496
|
+
since we do not know how many times the stream will be split.
|
1497
|
+
|
1498
|
+
Note: this leads to buffering the stream content on the server.
|
1499
|
+
However, the LLM results are expected to be small enough to not cause issues.
|
1500
|
+
*/
|
1501
|
+
teeStream() {
|
1502
|
+
const [stream1, stream2] = this.originalStream.tee();
|
1503
|
+
this.originalStream = stream2;
|
1504
|
+
return stream1;
|
1505
|
+
}
|
1506
|
+
/**
|
1494
1507
|
A text stream that returns only the generated text deltas. You can use it
|
1495
1508
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
1496
1509
|
stream will throw the error.
|
1497
1510
|
*/
|
1498
1511
|
get textStream() {
|
1499
|
-
return createAsyncIterableStream(this.
|
1512
|
+
return createAsyncIterableStream(this.teeStream(), {
|
1500
1513
|
transform(chunk, controller) {
|
1501
1514
|
if (chunk.type === "text-delta") {
|
1502
1515
|
if (chunk.textDelta.length > 0) {
|
@@ -1515,7 +1528,7 @@ var StreamTextResult = class {
|
|
1515
1528
|
stream will throw the error.
|
1516
1529
|
*/
|
1517
1530
|
get fullStream() {
|
1518
|
-
return createAsyncIterableStream(this.
|
1531
|
+
return createAsyncIterableStream(this.teeStream(), {
|
1519
1532
|
transform(chunk, controller) {
|
1520
1533
|
if (chunk.type === "text-delta") {
|
1521
1534
|
if (chunk.textDelta.length > 0) {
|