ai 6.0.0-beta.82 → 6.0.0-beta.84
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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +45 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.0-beta.84
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [016b111]
|
|
8
|
+
- @ai-sdk/provider-utils@4.0.0-beta.28
|
|
9
|
+
- @ai-sdk/gateway@2.0.0-beta.46
|
|
10
|
+
|
|
11
|
+
## 6.0.0-beta.83
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- e1f6e8e: feat(ai): add Output.json()
|
|
16
|
+
|
|
3
17
|
## 6.0.0-beta.82
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -686,16 +686,24 @@ type PartialObject<ObjectType extends object> = {
|
|
|
686
686
|
};
|
|
687
687
|
|
|
688
688
|
interface Output<OUTPUT = any, PARTIAL = any> {
|
|
689
|
-
|
|
689
|
+
/**
|
|
690
|
+
* The response format to use for the model.
|
|
691
|
+
*/
|
|
690
692
|
responseFormat: PromiseLike<LanguageModelV3CallOptions['responseFormat']>;
|
|
691
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Parses the complete output of the model.
|
|
695
|
+
*/
|
|
696
|
+
parseCompleteOutput(options: {
|
|
692
697
|
text: string;
|
|
693
698
|
}, context: {
|
|
694
699
|
response: LanguageModelResponseMetadata;
|
|
695
700
|
usage: LanguageModelUsage;
|
|
696
701
|
finishReason: FinishReason;
|
|
697
702
|
}): Promise<OUTPUT>;
|
|
698
|
-
|
|
703
|
+
/**
|
|
704
|
+
* Parses the partial output of the model.
|
|
705
|
+
*/
|
|
706
|
+
parsePartialOutput(options: {
|
|
699
707
|
text: string;
|
|
700
708
|
}): Promise<{
|
|
701
709
|
partial: PARTIAL;
|
|
@@ -739,10 +747,18 @@ declare const array: <ELEMENT>({ element: inputElementSchema, }: {
|
|
|
739
747
|
declare const choice: <ELEMENT extends string>({ options: choiceOptions, }: {
|
|
740
748
|
options: Array<ELEMENT>;
|
|
741
749
|
}) => Output<ELEMENT, ELEMENT>;
|
|
750
|
+
/**
|
|
751
|
+
* Output specification for unstructured JSON generation.
|
|
752
|
+
* When the model generates a text response, it will return a JSON object.
|
|
753
|
+
*
|
|
754
|
+
* @returns An output specification for generating JSON.
|
|
755
|
+
*/
|
|
756
|
+
declare const json: () => Output<JSONValue$1, JSONValue$1>;
|
|
742
757
|
|
|
743
758
|
type output_Output<OUTPUT = any, PARTIAL = any> = Output<OUTPUT, PARTIAL>;
|
|
744
759
|
declare const output_array: typeof array;
|
|
745
760
|
declare const output_choice: typeof choice;
|
|
761
|
+
declare const output_json: typeof json;
|
|
746
762
|
declare const output_object: typeof object;
|
|
747
763
|
declare const output_text: typeof text;
|
|
748
764
|
declare namespace output {
|
|
@@ -750,6 +766,7 @@ declare namespace output {
|
|
|
750
766
|
output_Output as Output,
|
|
751
767
|
output_array as array,
|
|
752
768
|
output_choice as choice,
|
|
769
|
+
output_json as json,
|
|
753
770
|
output_object as object,
|
|
754
771
|
output_text as text,
|
|
755
772
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -686,16 +686,24 @@ type PartialObject<ObjectType extends object> = {
|
|
|
686
686
|
};
|
|
687
687
|
|
|
688
688
|
interface Output<OUTPUT = any, PARTIAL = any> {
|
|
689
|
-
|
|
689
|
+
/**
|
|
690
|
+
* The response format to use for the model.
|
|
691
|
+
*/
|
|
690
692
|
responseFormat: PromiseLike<LanguageModelV3CallOptions['responseFormat']>;
|
|
691
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Parses the complete output of the model.
|
|
695
|
+
*/
|
|
696
|
+
parseCompleteOutput(options: {
|
|
692
697
|
text: string;
|
|
693
698
|
}, context: {
|
|
694
699
|
response: LanguageModelResponseMetadata;
|
|
695
700
|
usage: LanguageModelUsage;
|
|
696
701
|
finishReason: FinishReason;
|
|
697
702
|
}): Promise<OUTPUT>;
|
|
698
|
-
|
|
703
|
+
/**
|
|
704
|
+
* Parses the partial output of the model.
|
|
705
|
+
*/
|
|
706
|
+
parsePartialOutput(options: {
|
|
699
707
|
text: string;
|
|
700
708
|
}): Promise<{
|
|
701
709
|
partial: PARTIAL;
|
|
@@ -739,10 +747,18 @@ declare const array: <ELEMENT>({ element: inputElementSchema, }: {
|
|
|
739
747
|
declare const choice: <ELEMENT extends string>({ options: choiceOptions, }: {
|
|
740
748
|
options: Array<ELEMENT>;
|
|
741
749
|
}) => Output<ELEMENT, ELEMENT>;
|
|
750
|
+
/**
|
|
751
|
+
* Output specification for unstructured JSON generation.
|
|
752
|
+
* When the model generates a text response, it will return a JSON object.
|
|
753
|
+
*
|
|
754
|
+
* @returns An output specification for generating JSON.
|
|
755
|
+
*/
|
|
756
|
+
declare const json: () => Output<JSONValue$1, JSONValue$1>;
|
|
742
757
|
|
|
743
758
|
type output_Output<OUTPUT = any, PARTIAL = any> = Output<OUTPUT, PARTIAL>;
|
|
744
759
|
declare const output_array: typeof array;
|
|
745
760
|
declare const output_choice: typeof choice;
|
|
761
|
+
declare const output_json: typeof json;
|
|
746
762
|
declare const output_object: typeof object;
|
|
747
763
|
declare const output_text: typeof text;
|
|
748
764
|
declare namespace output {
|
|
@@ -750,6 +766,7 @@ declare namespace output {
|
|
|
750
766
|
output_Output as Output,
|
|
751
767
|
output_array as array,
|
|
752
768
|
output_choice as choice,
|
|
769
|
+
output_json as json,
|
|
753
770
|
output_object as object,
|
|
754
771
|
output_text as text,
|
|
755
772
|
};
|
package/dist/index.js
CHANGED
|
@@ -877,7 +877,7 @@ function detectMediaType({
|
|
|
877
877
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
878
878
|
|
|
879
879
|
// src/version.ts
|
|
880
|
-
var VERSION = true ? "6.0.0-beta.
|
|
880
|
+
var VERSION = true ? "6.0.0-beta.84" : "0.0.0-test";
|
|
881
881
|
|
|
882
882
|
// src/util/download/download.ts
|
|
883
883
|
var download = async ({ url }) => {
|
|
@@ -3058,7 +3058,7 @@ async function generateText({
|
|
|
3058
3058
|
}));
|
|
3059
3059
|
let resolvedOutput;
|
|
3060
3060
|
if (lastStep.finishReason === "stop") {
|
|
3061
|
-
resolvedOutput = await (output == null ? void 0 : output.
|
|
3061
|
+
resolvedOutput = await (output == null ? void 0 : output.parseCompleteOutput(
|
|
3062
3062
|
{ text: lastStep.text },
|
|
3063
3063
|
{
|
|
3064
3064
|
response: lastStep.response,
|
|
@@ -5085,7 +5085,7 @@ function createOutputTransformStream(output) {
|
|
|
5085
5085
|
}
|
|
5086
5086
|
text2 += chunk.text;
|
|
5087
5087
|
textChunk += chunk.text;
|
|
5088
|
-
const result = await output.
|
|
5088
|
+
const result = await output.parsePartialOutput({ text: text2 });
|
|
5089
5089
|
if (result != null) {
|
|
5090
5090
|
const currentJson = JSON.stringify(result.partial);
|
|
5091
5091
|
if (currentJson !== lastPublishedJson) {
|
|
@@ -9181,18 +9181,18 @@ var output_exports = {};
|
|
|
9181
9181
|
__export(output_exports, {
|
|
9182
9182
|
array: () => array,
|
|
9183
9183
|
choice: () => choice,
|
|
9184
|
+
json: () => json,
|
|
9184
9185
|
object: () => object,
|
|
9185
9186
|
text: () => text
|
|
9186
9187
|
});
|
|
9187
9188
|
var import_provider27 = require("@ai-sdk/provider");
|
|
9188
9189
|
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
9189
9190
|
var text = () => ({
|
|
9190
|
-
type: "text",
|
|
9191
9191
|
responseFormat: Promise.resolve({ type: "text" }),
|
|
9192
|
-
async
|
|
9192
|
+
async parseCompleteOutput({ text: text2 }) {
|
|
9193
9193
|
return text2;
|
|
9194
9194
|
},
|
|
9195
|
-
async
|
|
9195
|
+
async parsePartialOutput({ text: text2 }) {
|
|
9196
9196
|
return { partial: text2 };
|
|
9197
9197
|
}
|
|
9198
9198
|
});
|
|
@@ -9201,12 +9201,11 @@ var object = ({
|
|
|
9201
9201
|
}) => {
|
|
9202
9202
|
const schema = (0, import_provider_utils29.asSchema)(inputSchema);
|
|
9203
9203
|
return {
|
|
9204
|
-
type: "object",
|
|
9205
9204
|
responseFormat: (0, import_provider_utils29.resolve)(schema.jsonSchema).then((jsonSchema2) => ({
|
|
9206
9205
|
type: "json",
|
|
9207
9206
|
schema: jsonSchema2
|
|
9208
9207
|
})),
|
|
9209
|
-
async
|
|
9208
|
+
async parseCompleteOutput({ text: text2 }, context) {
|
|
9210
9209
|
const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: text2 });
|
|
9211
9210
|
if (!parseResult.success) {
|
|
9212
9211
|
throw new NoObjectGeneratedError({
|
|
@@ -9234,7 +9233,7 @@ var object = ({
|
|
|
9234
9233
|
}
|
|
9235
9234
|
return validationResult.value;
|
|
9236
9235
|
},
|
|
9237
|
-
async
|
|
9236
|
+
async parsePartialOutput({ text: text2 }) {
|
|
9238
9237
|
const result = await parsePartialJson(text2);
|
|
9239
9238
|
switch (result.state) {
|
|
9240
9239
|
case "failed-parse":
|
|
@@ -9248,10 +9247,6 @@ var object = ({
|
|
|
9248
9247
|
partial: result.value
|
|
9249
9248
|
};
|
|
9250
9249
|
}
|
|
9251
|
-
default: {
|
|
9252
|
-
const _exhaustiveCheck = result.state;
|
|
9253
|
-
throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
|
|
9254
|
-
}
|
|
9255
9250
|
}
|
|
9256
9251
|
}
|
|
9257
9252
|
};
|
|
@@ -9261,7 +9256,6 @@ var array = ({
|
|
|
9261
9256
|
}) => {
|
|
9262
9257
|
const elementSchema = (0, import_provider_utils29.asSchema)(inputElementSchema);
|
|
9263
9258
|
return {
|
|
9264
|
-
type: "object",
|
|
9265
9259
|
// JSON schema that describes an array of elements:
|
|
9266
9260
|
responseFormat: (0, import_provider_utils29.resolve)(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
9267
9261
|
const { $schema, ...itemSchema } = jsonSchema2;
|
|
@@ -9278,7 +9272,7 @@ var array = ({
|
|
|
9278
9272
|
}
|
|
9279
9273
|
};
|
|
9280
9274
|
}),
|
|
9281
|
-
async
|
|
9275
|
+
async parseCompleteOutput({ text: text2 }, context) {
|
|
9282
9276
|
const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: text2 });
|
|
9283
9277
|
if (!parseResult.success) {
|
|
9284
9278
|
throw new NoObjectGeneratedError({
|
|
@@ -9322,7 +9316,7 @@ var array = ({
|
|
|
9322
9316
|
}
|
|
9323
9317
|
return outerValue.elements;
|
|
9324
9318
|
},
|
|
9325
|
-
async
|
|
9319
|
+
async parsePartialOutput({ text: text2 }) {
|
|
9326
9320
|
const result = await parsePartialJson(text2);
|
|
9327
9321
|
switch (result.state) {
|
|
9328
9322
|
case "failed-parse":
|
|
@@ -9348,10 +9342,6 @@ var array = ({
|
|
|
9348
9342
|
}
|
|
9349
9343
|
return { partial: parsedElements };
|
|
9350
9344
|
}
|
|
9351
|
-
default: {
|
|
9352
|
-
const _exhaustiveCheck = result.state;
|
|
9353
|
-
throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
|
|
9354
|
-
}
|
|
9355
9345
|
}
|
|
9356
9346
|
}
|
|
9357
9347
|
};
|
|
@@ -9360,7 +9350,6 @@ var choice = ({
|
|
|
9360
9350
|
options: choiceOptions
|
|
9361
9351
|
}) => {
|
|
9362
9352
|
return {
|
|
9363
|
-
type: "object",
|
|
9364
9353
|
// JSON schema that describes an enumeration:
|
|
9365
9354
|
responseFormat: Promise.resolve({
|
|
9366
9355
|
type: "json",
|
|
@@ -9374,7 +9363,7 @@ var choice = ({
|
|
|
9374
9363
|
additionalProperties: false
|
|
9375
9364
|
}
|
|
9376
9365
|
}),
|
|
9377
|
-
async
|
|
9366
|
+
async parseCompleteOutput({ text: text2 }, context) {
|
|
9378
9367
|
const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: text2 });
|
|
9379
9368
|
if (!parseResult.success) {
|
|
9380
9369
|
throw new NoObjectGeneratedError({
|
|
@@ -9402,7 +9391,7 @@ var choice = ({
|
|
|
9402
9391
|
}
|
|
9403
9392
|
return outerValue.result;
|
|
9404
9393
|
},
|
|
9405
|
-
async
|
|
9394
|
+
async parsePartialOutput({ text: text2 }) {
|
|
9406
9395
|
const result = await parsePartialJson(text2);
|
|
9407
9396
|
switch (result.state) {
|
|
9408
9397
|
case "failed-parse":
|
|
@@ -9424,9 +9413,39 @@ var choice = ({
|
|
|
9424
9413
|
return potentialMatches.length === 1 ? { partial: potentialMatches[0] } : void 0;
|
|
9425
9414
|
}
|
|
9426
9415
|
}
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9416
|
+
}
|
|
9417
|
+
}
|
|
9418
|
+
};
|
|
9419
|
+
};
|
|
9420
|
+
var json = () => {
|
|
9421
|
+
return {
|
|
9422
|
+
responseFormat: Promise.resolve({
|
|
9423
|
+
type: "json"
|
|
9424
|
+
}),
|
|
9425
|
+
async parseCompleteOutput({ text: text2 }, context) {
|
|
9426
|
+
const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: text2 });
|
|
9427
|
+
if (!parseResult.success) {
|
|
9428
|
+
throw new NoObjectGeneratedError({
|
|
9429
|
+
message: "No object generated: could not parse the response.",
|
|
9430
|
+
cause: parseResult.error,
|
|
9431
|
+
text: text2,
|
|
9432
|
+
response: context.response,
|
|
9433
|
+
usage: context.usage,
|
|
9434
|
+
finishReason: context.finishReason
|
|
9435
|
+
});
|
|
9436
|
+
}
|
|
9437
|
+
return parseResult.value;
|
|
9438
|
+
},
|
|
9439
|
+
async parsePartialOutput({ text: text2 }) {
|
|
9440
|
+
const result = await parsePartialJson(text2);
|
|
9441
|
+
switch (result.state) {
|
|
9442
|
+
case "failed-parse":
|
|
9443
|
+
case "undefined-input": {
|
|
9444
|
+
return void 0;
|
|
9445
|
+
}
|
|
9446
|
+
case "repaired-parse":
|
|
9447
|
+
case "successful-parse": {
|
|
9448
|
+
return result.value === void 0 ? void 0 : { partial: result.value };
|
|
9430
9449
|
}
|
|
9431
9450
|
}
|
|
9432
9451
|
}
|