ai 3.1.27 → 3.1.28
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 +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
@@ -628,12 +628,16 @@ type ObjectStreamPart<T> = ObjectStreamInputPart | {
|
|
628
628
|
The result of a `streamObject` call that contains the partial object stream and additional information.
|
629
629
|
*/
|
630
630
|
declare class StreamObjectResult<T> {
|
631
|
-
readonly originalStream
|
631
|
+
private readonly originalStream;
|
632
632
|
/**
|
633
633
|
Warnings from the model provider (e.g. unsupported settings)
|
634
634
|
*/
|
635
635
|
readonly warnings: CallWarning[] | undefined;
|
636
636
|
/**
|
637
|
+
The generated object (typed according to the schema). Resolved when the response is finished.
|
638
|
+
*/
|
639
|
+
readonly object: Promise<T>;
|
640
|
+
/**
|
637
641
|
The token usage of the generated response. Resolved when the response is finished.
|
638
642
|
*/
|
639
643
|
readonly usage: Promise<TokenUsage>;
|
@@ -646,12 +650,13 @@ declare class StreamObjectResult<T> {
|
|
646
650
|
*/
|
647
651
|
headers?: Record<string, string>;
|
648
652
|
};
|
649
|
-
constructor({ stream, warnings, rawResponse, }: {
|
653
|
+
constructor({ stream, warnings, rawResponse, schema, }: {
|
650
654
|
stream: ReadableStream<string | ObjectStreamInputPart>;
|
651
655
|
warnings: CallWarning[] | undefined;
|
652
656
|
rawResponse?: {
|
653
657
|
headers?: Record<string, string>;
|
654
658
|
};
|
659
|
+
schema: z.Schema<T>;
|
655
660
|
});
|
656
661
|
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
657
662
|
get fullStream(): AsyncIterableStream<ObjectStreamPart<T>>;
|
package/dist/index.d.ts
CHANGED
@@ -628,12 +628,16 @@ type ObjectStreamPart<T> = ObjectStreamInputPart | {
|
|
628
628
|
The result of a `streamObject` call that contains the partial object stream and additional information.
|
629
629
|
*/
|
630
630
|
declare class StreamObjectResult<T> {
|
631
|
-
readonly originalStream
|
631
|
+
private readonly originalStream;
|
632
632
|
/**
|
633
633
|
Warnings from the model provider (e.g. unsupported settings)
|
634
634
|
*/
|
635
635
|
readonly warnings: CallWarning[] | undefined;
|
636
636
|
/**
|
637
|
+
The generated object (typed according to the schema). Resolved when the response is finished.
|
638
|
+
*/
|
639
|
+
readonly object: Promise<T>;
|
640
|
+
/**
|
637
641
|
The token usage of the generated response. Resolved when the response is finished.
|
638
642
|
*/
|
639
643
|
readonly usage: Promise<TokenUsage>;
|
@@ -646,12 +650,13 @@ declare class StreamObjectResult<T> {
|
|
646
650
|
*/
|
647
651
|
headers?: Record<string, string>;
|
648
652
|
};
|
649
|
-
constructor({ stream, warnings, rawResponse, }: {
|
653
|
+
constructor({ stream, warnings, rawResponse, schema, }: {
|
650
654
|
stream: ReadableStream<string | ObjectStreamInputPart>;
|
651
655
|
warnings: CallWarning[] | undefined;
|
652
656
|
rawResponse?: {
|
653
657
|
headers?: Record<string, string>;
|
654
658
|
};
|
659
|
+
schema: z.Schema<T>;
|
655
660
|
});
|
656
661
|
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
657
662
|
get fullStream(): AsyncIterableStream<ObjectStreamPart<T>>;
|
package/dist/index.js
CHANGED
@@ -1080,6 +1080,7 @@ function parsePartialJson(jsonText) {
|
|
1080
1080
|
}
|
1081
1081
|
|
1082
1082
|
// core/generate-object/stream-object.ts
|
1083
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1083
1084
|
async function streamObject({
|
1084
1085
|
model,
|
1085
1086
|
schema,
|
@@ -1203,17 +1204,25 @@ async function streamObject({
|
|
1203
1204
|
return new StreamObjectResult({
|
1204
1205
|
stream: result.stream.pipeThrough(new TransformStream(transformer)),
|
1205
1206
|
warnings: result.warnings,
|
1206
|
-
rawResponse: result.rawResponse
|
1207
|
+
rawResponse: result.rawResponse,
|
1208
|
+
schema
|
1207
1209
|
});
|
1208
1210
|
}
|
1209
1211
|
var StreamObjectResult = class {
|
1210
1212
|
constructor({
|
1211
1213
|
stream,
|
1212
1214
|
warnings,
|
1213
|
-
rawResponse
|
1215
|
+
rawResponse,
|
1216
|
+
schema
|
1214
1217
|
}) {
|
1215
1218
|
this.warnings = warnings;
|
1216
1219
|
this.rawResponse = rawResponse;
|
1220
|
+
let resolveObject;
|
1221
|
+
let rejectObject;
|
1222
|
+
this.object = new Promise((resolve, reject) => {
|
1223
|
+
resolveObject = resolve;
|
1224
|
+
rejectObject = reject;
|
1225
|
+
});
|
1217
1226
|
let resolveUsage;
|
1218
1227
|
this.usage = new Promise((resolve) => {
|
1219
1228
|
resolveUsage = resolve;
|
@@ -1238,11 +1247,17 @@ var StreamObjectResult = class {
|
|
1238
1247
|
switch (chunk.type) {
|
1239
1248
|
case "finish": {
|
1240
1249
|
usage = calculateTokenUsage(chunk.usage);
|
1241
|
-
controller.enqueue({
|
1242
|
-
...chunk,
|
1243
|
-
usage
|
1244
|
-
});
|
1250
|
+
controller.enqueue({ ...chunk, usage });
|
1245
1251
|
resolveUsage(usage);
|
1252
|
+
const validationResult = (0, import_provider_utils4.safeValidateTypes)({
|
1253
|
+
value: latestObject,
|
1254
|
+
schema
|
1255
|
+
});
|
1256
|
+
if (validationResult.success) {
|
1257
|
+
resolveObject(validationResult.value);
|
1258
|
+
} else {
|
1259
|
+
rejectObject(validationResult.error);
|
1260
|
+
}
|
1246
1261
|
break;
|
1247
1262
|
}
|
1248
1263
|
default: {
|
@@ -1313,7 +1328,7 @@ function prepareToolsAndToolChoice({
|
|
1313
1328
|
|
1314
1329
|
// core/generate-text/tool-call.ts
|
1315
1330
|
var import_provider6 = require("@ai-sdk/provider");
|
1316
|
-
var
|
1331
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
1317
1332
|
function parseToolCall({
|
1318
1333
|
toolCall,
|
1319
1334
|
tools
|
@@ -1329,7 +1344,7 @@ function parseToolCall({
|
|
1329
1344
|
availableTools: Object.keys(tools)
|
1330
1345
|
});
|
1331
1346
|
}
|
1332
|
-
const parseResult = (0,
|
1347
|
+
const parseResult = (0, import_provider_utils5.safeParseJSON)({
|
1333
1348
|
text: toolCall.args,
|
1334
1349
|
schema: tool2.parameters
|
1335
1350
|
});
|