ai 3.2.34 → 3.2.35
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 +68 -26
- package/dist/index.d.ts +68 -26
- package/dist/index.js +275 -187
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -8
- package/rsc/dist/rsc-server.mjs +33 -4
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -91,6 +91,7 @@ __export(streams_exports, {
|
|
91
91
|
generateId: () => generateId2,
|
92
92
|
generateObject: () => generateObject,
|
93
93
|
generateText: () => generateText,
|
94
|
+
jsonSchema: () => jsonSchema,
|
94
95
|
nanoid: () => nanoid,
|
95
96
|
parseComplexResponse: () => import_ui_utils6.parseComplexResponse,
|
96
97
|
parseStreamPart: () => import_ui_utils6.parseStreamPart,
|
@@ -104,7 +105,158 @@ __export(streams_exports, {
|
|
104
105
|
});
|
105
106
|
module.exports = __toCommonJS(streams_exports);
|
106
107
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
107
|
-
var
|
108
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
109
|
+
|
110
|
+
// core/telemetry/get-base-telemetry-attributes.ts
|
111
|
+
function getBaseTelemetryAttributes({
|
112
|
+
operationName,
|
113
|
+
model,
|
114
|
+
settings,
|
115
|
+
telemetry,
|
116
|
+
headers
|
117
|
+
}) {
|
118
|
+
var _a;
|
119
|
+
return {
|
120
|
+
"ai.model.provider": model.provider,
|
121
|
+
"ai.model.id": model.modelId,
|
122
|
+
// settings:
|
123
|
+
...Object.entries(settings).reduce((attributes, [key, value]) => {
|
124
|
+
attributes[`ai.settings.${key}`] = value;
|
125
|
+
return attributes;
|
126
|
+
}, {}),
|
127
|
+
// special telemetry information
|
128
|
+
"operation.name": operationName,
|
129
|
+
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
130
|
+
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
131
|
+
// add metadata as attributes:
|
132
|
+
...Object.entries((_a = telemetry == null ? void 0 : telemetry.metadata) != null ? _a : {}).reduce(
|
133
|
+
(attributes, [key, value]) => {
|
134
|
+
attributes[`ai.telemetry.metadata.${key}`] = value;
|
135
|
+
return attributes;
|
136
|
+
},
|
137
|
+
{}
|
138
|
+
),
|
139
|
+
// request headers
|
140
|
+
...Object.entries(headers != null ? headers : {}).reduce((attributes, [key, value]) => {
|
141
|
+
if (value !== void 0) {
|
142
|
+
attributes[`ai.request.headers.${key}`] = value;
|
143
|
+
}
|
144
|
+
return attributes;
|
145
|
+
}, {})
|
146
|
+
};
|
147
|
+
}
|
148
|
+
|
149
|
+
// core/telemetry/get-tracer.ts
|
150
|
+
var import_api = require("@opentelemetry/api");
|
151
|
+
|
152
|
+
// core/telemetry/noop-tracer.ts
|
153
|
+
var noopTracer = {
|
154
|
+
startSpan() {
|
155
|
+
return noopSpan;
|
156
|
+
},
|
157
|
+
startActiveSpan(name, arg1, arg2, arg3) {
|
158
|
+
if (typeof arg1 === "function") {
|
159
|
+
return arg1(noopSpan);
|
160
|
+
}
|
161
|
+
if (typeof arg2 === "function") {
|
162
|
+
return arg2(noopSpan);
|
163
|
+
}
|
164
|
+
if (typeof arg3 === "function") {
|
165
|
+
return arg3(noopSpan);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
};
|
169
|
+
var noopSpan = {
|
170
|
+
spanContext() {
|
171
|
+
return noopSpanContext;
|
172
|
+
},
|
173
|
+
setAttribute() {
|
174
|
+
return this;
|
175
|
+
},
|
176
|
+
setAttributes() {
|
177
|
+
return this;
|
178
|
+
},
|
179
|
+
addEvent() {
|
180
|
+
return this;
|
181
|
+
},
|
182
|
+
addLink() {
|
183
|
+
return this;
|
184
|
+
},
|
185
|
+
addLinks() {
|
186
|
+
return this;
|
187
|
+
},
|
188
|
+
setStatus() {
|
189
|
+
return this;
|
190
|
+
},
|
191
|
+
updateName() {
|
192
|
+
return this;
|
193
|
+
},
|
194
|
+
end() {
|
195
|
+
return this;
|
196
|
+
},
|
197
|
+
isRecording() {
|
198
|
+
return false;
|
199
|
+
},
|
200
|
+
recordException() {
|
201
|
+
return this;
|
202
|
+
}
|
203
|
+
};
|
204
|
+
var noopSpanContext = {
|
205
|
+
traceId: "",
|
206
|
+
spanId: "",
|
207
|
+
traceFlags: 0
|
208
|
+
};
|
209
|
+
|
210
|
+
// core/telemetry/get-tracer.ts
|
211
|
+
var testTracer = void 0;
|
212
|
+
function getTracer({ isEnabled }) {
|
213
|
+
if (!isEnabled) {
|
214
|
+
return noopTracer;
|
215
|
+
}
|
216
|
+
if (testTracer) {
|
217
|
+
return testTracer;
|
218
|
+
}
|
219
|
+
return import_api.trace.getTracer("ai");
|
220
|
+
}
|
221
|
+
|
222
|
+
// core/telemetry/record-span.ts
|
223
|
+
var import_api2 = require("@opentelemetry/api");
|
224
|
+
function recordSpan({
|
225
|
+
name,
|
226
|
+
tracer,
|
227
|
+
attributes,
|
228
|
+
fn,
|
229
|
+
endWhenDone = true
|
230
|
+
}) {
|
231
|
+
return tracer.startActiveSpan(name, { attributes }, async (span) => {
|
232
|
+
try {
|
233
|
+
const result = await fn(span);
|
234
|
+
if (endWhenDone) {
|
235
|
+
span.end();
|
236
|
+
}
|
237
|
+
return result;
|
238
|
+
} catch (error) {
|
239
|
+
try {
|
240
|
+
if (error instanceof Error) {
|
241
|
+
span.recordException({
|
242
|
+
name: error.name,
|
243
|
+
message: error.message,
|
244
|
+
stack: error.stack
|
245
|
+
});
|
246
|
+
span.setStatus({
|
247
|
+
code: import_api2.SpanStatusCode.ERROR,
|
248
|
+
message: error.message
|
249
|
+
});
|
250
|
+
} else {
|
251
|
+
span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
|
252
|
+
}
|
253
|
+
} finally {
|
254
|
+
span.end();
|
255
|
+
}
|
256
|
+
throw error;
|
257
|
+
}
|
258
|
+
});
|
259
|
+
}
|
108
260
|
|
109
261
|
// core/util/retry-with-exponential-backoff.ts
|
110
262
|
var import_provider = require("@ai-sdk/provider");
|
@@ -174,18 +326,69 @@ async function embed({
|
|
174
326
|
value,
|
175
327
|
maxRetries,
|
176
328
|
abortSignal,
|
177
|
-
headers
|
329
|
+
headers,
|
330
|
+
experimental_telemetry: telemetry
|
178
331
|
}) {
|
179
332
|
var _a;
|
180
|
-
const
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
333
|
+
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
334
|
+
operationName: "ai.embed",
|
335
|
+
model,
|
336
|
+
telemetry,
|
337
|
+
headers,
|
338
|
+
settings: { maxRetries }
|
339
|
+
});
|
340
|
+
const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
|
341
|
+
return recordSpan({
|
342
|
+
name: "ai.embed",
|
343
|
+
attributes: {
|
344
|
+
...baseTelemetryAttributes,
|
345
|
+
// specific settings that only make sense on the outer level:
|
346
|
+
"ai.value": JSON.stringify(value)
|
347
|
+
},
|
348
|
+
tracer,
|
349
|
+
fn: async (span) => {
|
350
|
+
const retry = retryWithExponentialBackoff({ maxRetries });
|
351
|
+
const { embedding, usage, rawResponse } = await retry(
|
352
|
+
() => (
|
353
|
+
// nested spans to align with the embedMany telemetry data:
|
354
|
+
recordSpan({
|
355
|
+
name: "ai.embed.doEmbed",
|
356
|
+
attributes: {
|
357
|
+
...baseTelemetryAttributes,
|
358
|
+
// specific settings that only make sense on the outer level:
|
359
|
+
"ai.values": [JSON.stringify(value)]
|
360
|
+
},
|
361
|
+
tracer,
|
362
|
+
fn: async (doEmbedSpan) => {
|
363
|
+
var _a2;
|
364
|
+
const modelResponse = await model.doEmbed({
|
365
|
+
values: [value],
|
366
|
+
abortSignal,
|
367
|
+
headers
|
368
|
+
});
|
369
|
+
const embedding2 = modelResponse.embeddings[0];
|
370
|
+
const usage2 = (_a2 = modelResponse.usage) != null ? _a2 : { tokens: NaN };
|
371
|
+
doEmbedSpan.setAttributes({
|
372
|
+
"ai.embeddings": modelResponse.embeddings.map(
|
373
|
+
(embedding3) => JSON.stringify(embedding3)
|
374
|
+
),
|
375
|
+
"ai.usage.tokens": usage2.tokens
|
376
|
+
});
|
377
|
+
return {
|
378
|
+
embedding: embedding2,
|
379
|
+
usage: usage2,
|
380
|
+
rawResponse: modelResponse.rawResponse
|
381
|
+
};
|
382
|
+
}
|
383
|
+
})
|
384
|
+
)
|
385
|
+
);
|
386
|
+
span.setAttributes({
|
387
|
+
"ai.embedding": JSON.stringify(embedding),
|
388
|
+
"ai.usage.tokens": usage.tokens
|
389
|
+
});
|
390
|
+
return new DefaultEmbedResult({ value, embedding, usage, rawResponse });
|
391
|
+
}
|
189
392
|
});
|
190
393
|
}
|
191
394
|
var DefaultEmbedResult = class {
|
@@ -252,7 +455,7 @@ var DefaultEmbedManyResult = class {
|
|
252
455
|
|
253
456
|
// core/generate-object/generate-object.ts
|
254
457
|
var import_provider5 = require("@ai-sdk/provider");
|
255
|
-
var
|
458
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
256
459
|
|
257
460
|
// core/util/detect-image-mimetype.ts
|
258
461
|
var mimeTypeSignatures = [
|
@@ -610,157 +813,6 @@ function prepareCallSettings({
|
|
610
813
|
};
|
611
814
|
}
|
612
815
|
|
613
|
-
// core/telemetry/get-base-telemetry-attributes.ts
|
614
|
-
function getBaseTelemetryAttributes({
|
615
|
-
operationName,
|
616
|
-
model,
|
617
|
-
settings,
|
618
|
-
telemetry,
|
619
|
-
headers
|
620
|
-
}) {
|
621
|
-
var _a;
|
622
|
-
return {
|
623
|
-
"ai.model.provider": model.provider,
|
624
|
-
"ai.model.id": model.modelId,
|
625
|
-
// settings:
|
626
|
-
...Object.entries(settings).reduce((attributes, [key, value]) => {
|
627
|
-
attributes[`ai.settings.${key}`] = value;
|
628
|
-
return attributes;
|
629
|
-
}, {}),
|
630
|
-
// special telemetry information
|
631
|
-
"operation.name": operationName,
|
632
|
-
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
633
|
-
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
634
|
-
// add metadata as attributes:
|
635
|
-
...Object.entries((_a = telemetry == null ? void 0 : telemetry.metadata) != null ? _a : {}).reduce(
|
636
|
-
(attributes, [key, value]) => {
|
637
|
-
attributes[`ai.telemetry.metadata.${key}`] = value;
|
638
|
-
return attributes;
|
639
|
-
},
|
640
|
-
{}
|
641
|
-
),
|
642
|
-
// request headers
|
643
|
-
...Object.entries(headers != null ? headers : {}).reduce((attributes, [key, value]) => {
|
644
|
-
if (value !== void 0) {
|
645
|
-
attributes[`ai.request.headers.${key}`] = value;
|
646
|
-
}
|
647
|
-
return attributes;
|
648
|
-
}, {})
|
649
|
-
};
|
650
|
-
}
|
651
|
-
|
652
|
-
// core/telemetry/get-tracer.ts
|
653
|
-
var import_api = require("@opentelemetry/api");
|
654
|
-
|
655
|
-
// core/telemetry/noop-tracer.ts
|
656
|
-
var noopTracer = {
|
657
|
-
startSpan() {
|
658
|
-
return noopSpan;
|
659
|
-
},
|
660
|
-
startActiveSpan(name, arg1, arg2, arg3) {
|
661
|
-
if (typeof arg1 === "function") {
|
662
|
-
return arg1(noopSpan);
|
663
|
-
}
|
664
|
-
if (typeof arg2 === "function") {
|
665
|
-
return arg2(noopSpan);
|
666
|
-
}
|
667
|
-
if (typeof arg3 === "function") {
|
668
|
-
return arg3(noopSpan);
|
669
|
-
}
|
670
|
-
}
|
671
|
-
};
|
672
|
-
var noopSpan = {
|
673
|
-
spanContext() {
|
674
|
-
return noopSpanContext;
|
675
|
-
},
|
676
|
-
setAttribute() {
|
677
|
-
return this;
|
678
|
-
},
|
679
|
-
setAttributes() {
|
680
|
-
return this;
|
681
|
-
},
|
682
|
-
addEvent() {
|
683
|
-
return this;
|
684
|
-
},
|
685
|
-
addLink() {
|
686
|
-
return this;
|
687
|
-
},
|
688
|
-
addLinks() {
|
689
|
-
return this;
|
690
|
-
},
|
691
|
-
setStatus() {
|
692
|
-
return this;
|
693
|
-
},
|
694
|
-
updateName() {
|
695
|
-
return this;
|
696
|
-
},
|
697
|
-
end() {
|
698
|
-
return this;
|
699
|
-
},
|
700
|
-
isRecording() {
|
701
|
-
return false;
|
702
|
-
},
|
703
|
-
recordException() {
|
704
|
-
return this;
|
705
|
-
}
|
706
|
-
};
|
707
|
-
var noopSpanContext = {
|
708
|
-
traceId: "",
|
709
|
-
spanId: "",
|
710
|
-
traceFlags: 0
|
711
|
-
};
|
712
|
-
|
713
|
-
// core/telemetry/get-tracer.ts
|
714
|
-
var testTracer = void 0;
|
715
|
-
function getTracer({ isEnabled }) {
|
716
|
-
if (!isEnabled) {
|
717
|
-
return noopTracer;
|
718
|
-
}
|
719
|
-
if (testTracer) {
|
720
|
-
return testTracer;
|
721
|
-
}
|
722
|
-
return import_api.trace.getTracer("ai");
|
723
|
-
}
|
724
|
-
|
725
|
-
// core/telemetry/record-span.ts
|
726
|
-
var import_api2 = require("@opentelemetry/api");
|
727
|
-
function recordSpan({
|
728
|
-
name,
|
729
|
-
tracer,
|
730
|
-
attributes,
|
731
|
-
fn,
|
732
|
-
endWhenDone = true
|
733
|
-
}) {
|
734
|
-
return tracer.startActiveSpan(name, { attributes }, async (span) => {
|
735
|
-
try {
|
736
|
-
const result = await fn(span);
|
737
|
-
if (endWhenDone) {
|
738
|
-
span.end();
|
739
|
-
}
|
740
|
-
return result;
|
741
|
-
} catch (error) {
|
742
|
-
try {
|
743
|
-
if (error instanceof Error) {
|
744
|
-
span.recordException({
|
745
|
-
name: error.name,
|
746
|
-
message: error.message,
|
747
|
-
stack: error.stack
|
748
|
-
});
|
749
|
-
span.setStatus({
|
750
|
-
code: import_api2.SpanStatusCode.ERROR,
|
751
|
-
message: error.message
|
752
|
-
});
|
753
|
-
} else {
|
754
|
-
span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
|
755
|
-
}
|
756
|
-
} finally {
|
757
|
-
span.end();
|
758
|
-
}
|
759
|
-
throw error;
|
760
|
-
}
|
761
|
-
});
|
762
|
-
}
|
763
|
-
|
764
816
|
// core/types/token-usage.ts
|
765
817
|
function calculateCompletionTokenUsage(usage) {
|
766
818
|
return {
|
@@ -770,12 +822,6 @@ function calculateCompletionTokenUsage(usage) {
|
|
770
822
|
};
|
771
823
|
}
|
772
824
|
|
773
|
-
// core/util/convert-zod-to-json-schema.ts
|
774
|
-
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
775
|
-
function convertZodToJSONSchema(zodSchema) {
|
776
|
-
return (0, import_zod_to_json_schema.default)(zodSchema);
|
777
|
-
}
|
778
|
-
|
779
825
|
// core/util/prepare-response-headers.ts
|
780
826
|
function prepareResponseHeaders(init, { contentType }) {
|
781
827
|
var _a;
|
@@ -786,6 +832,41 @@ function prepareResponseHeaders(init, { contentType }) {
|
|
786
832
|
return headers;
|
787
833
|
}
|
788
834
|
|
835
|
+
// core/util/schema.ts
|
836
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
837
|
+
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
838
|
+
var schemaSymbol = Symbol("vercel.ai.schema");
|
839
|
+
function jsonSchema(jsonSchema2, {
|
840
|
+
validate
|
841
|
+
} = {}) {
|
842
|
+
return {
|
843
|
+
[schemaSymbol]: true,
|
844
|
+
_type: void 0,
|
845
|
+
// should never be used directly
|
846
|
+
[import_provider_utils4.validatorSymbol]: true,
|
847
|
+
jsonSchema: jsonSchema2,
|
848
|
+
validate
|
849
|
+
};
|
850
|
+
}
|
851
|
+
function isSchema(value) {
|
852
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
853
|
+
}
|
854
|
+
function asSchema(schema) {
|
855
|
+
return isSchema(schema) ? schema : zodSchema(schema);
|
856
|
+
}
|
857
|
+
function zodSchema(zodSchema2) {
|
858
|
+
return jsonSchema(
|
859
|
+
// we assume that zodToJsonSchema will return a valid JSONSchema7:
|
860
|
+
(0, import_zod_to_json_schema.default)(zodSchema2),
|
861
|
+
{
|
862
|
+
validate: (value) => {
|
863
|
+
const result = zodSchema2.safeParse(value);
|
864
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
865
|
+
}
|
866
|
+
}
|
867
|
+
);
|
868
|
+
}
|
869
|
+
|
789
870
|
// core/generate-object/inject-json-schema-into-system.ts
|
790
871
|
var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
|
791
872
|
var DEFAULT_SCHEMA_SUFFIX = "You MUST answer with a JSON object that matches the JSON schema above.";
|
@@ -808,7 +889,7 @@ function injectJsonSchemaIntoSystem({
|
|
808
889
|
// core/generate-object/generate-object.ts
|
809
890
|
async function generateObject({
|
810
891
|
model,
|
811
|
-
schema,
|
892
|
+
schema: inputSchema,
|
812
893
|
mode,
|
813
894
|
system,
|
814
895
|
prompt,
|
@@ -827,7 +908,7 @@ async function generateObject({
|
|
827
908
|
headers,
|
828
909
|
settings: { ...settings, maxRetries }
|
829
910
|
});
|
830
|
-
const
|
911
|
+
const schema = asSchema(inputSchema);
|
831
912
|
const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
|
832
913
|
return recordSpan({
|
833
914
|
name: "ai.generateObject",
|
@@ -835,7 +916,7 @@ async function generateObject({
|
|
835
916
|
...baseTelemetryAttributes,
|
836
917
|
// specific settings that only make sense on the outer level:
|
837
918
|
"ai.prompt": JSON.stringify({ system, prompt, messages }),
|
838
|
-
"ai.settings.jsonSchema": JSON.stringify(jsonSchema),
|
919
|
+
"ai.settings.jsonSchema": JSON.stringify(schema.jsonSchema),
|
839
920
|
"ai.settings.mode": mode
|
840
921
|
},
|
841
922
|
tracer,
|
@@ -854,7 +935,10 @@ async function generateObject({
|
|
854
935
|
switch (mode) {
|
855
936
|
case "json": {
|
856
937
|
const validatedPrompt = getValidatedPrompt({
|
857
|
-
system: injectJsonSchemaIntoSystem({
|
938
|
+
system: injectJsonSchemaIntoSystem({
|
939
|
+
system,
|
940
|
+
schema: schema.jsonSchema
|
941
|
+
}),
|
858
942
|
prompt,
|
859
943
|
messages
|
860
944
|
});
|
@@ -926,7 +1010,7 @@ async function generateObject({
|
|
926
1010
|
type: "function",
|
927
1011
|
name: "json",
|
928
1012
|
description: "Respond with a JSON object.",
|
929
|
-
parameters: jsonSchema
|
1013
|
+
parameters: schema.jsonSchema
|
930
1014
|
}
|
931
1015
|
},
|
932
1016
|
...prepareCallSettings(settings),
|
@@ -968,7 +1052,7 @@ async function generateObject({
|
|
968
1052
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
969
1053
|
}
|
970
1054
|
}
|
971
|
-
const parseResult = (0,
|
1055
|
+
const parseResult = (0, import_provider_utils5.safeParseJSON)({ text: result, schema });
|
972
1056
|
if (!parseResult.success) {
|
973
1057
|
throw parseResult.error;
|
974
1058
|
}
|
@@ -1011,7 +1095,7 @@ var DefaultGenerateObjectResult = class {
|
|
1011
1095
|
var experimental_generateObject = generateObject;
|
1012
1096
|
|
1013
1097
|
// core/generate-object/stream-object.ts
|
1014
|
-
var
|
1098
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1015
1099
|
var import_ui_utils = require("@ai-sdk/ui-utils");
|
1016
1100
|
|
1017
1101
|
// core/util/async-iterable-stream.ts
|
@@ -1072,7 +1156,7 @@ var DelayedPromise = class {
|
|
1072
1156
|
// core/generate-object/stream-object.ts
|
1073
1157
|
async function streamObject({
|
1074
1158
|
model,
|
1075
|
-
schema,
|
1159
|
+
schema: inputSchema,
|
1076
1160
|
mode,
|
1077
1161
|
system,
|
1078
1162
|
prompt,
|
@@ -1084,7 +1168,7 @@ async function streamObject({
|
|
1084
1168
|
...settings
|
1085
1169
|
}) {
|
1086
1170
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1087
|
-
const
|
1171
|
+
const schema = asSchema(inputSchema);
|
1088
1172
|
if (mode === "auto" || mode == null) {
|
1089
1173
|
mode = model.defaultObjectGenerationMode;
|
1090
1174
|
}
|
@@ -1093,7 +1177,10 @@ async function streamObject({
|
|
1093
1177
|
switch (mode) {
|
1094
1178
|
case "json": {
|
1095
1179
|
const validatedPrompt = getValidatedPrompt({
|
1096
|
-
system: injectJsonSchemaIntoSystem({
|
1180
|
+
system: injectJsonSchemaIntoSystem({
|
1181
|
+
system,
|
1182
|
+
schema: schema.jsonSchema
|
1183
|
+
}),
|
1097
1184
|
prompt,
|
1098
1185
|
messages
|
1099
1186
|
});
|
@@ -1133,7 +1220,7 @@ async function streamObject({
|
|
1133
1220
|
type: "function",
|
1134
1221
|
name: "json",
|
1135
1222
|
description: "Respond with a JSON object.",
|
1136
|
-
parameters: jsonSchema
|
1223
|
+
parameters: schema.jsonSchema
|
1137
1224
|
}
|
1138
1225
|
},
|
1139
1226
|
...prepareCallSettings(settings),
|
@@ -1230,7 +1317,7 @@ var DefaultStreamObjectResult = class {
|
|
1230
1317
|
usage = calculateCompletionTokenUsage(chunk.usage);
|
1231
1318
|
controller.enqueue({ ...chunk, usage });
|
1232
1319
|
resolveUsage(usage);
|
1233
|
-
const validationResult = (0,
|
1320
|
+
const validationResult = (0, import_provider_utils6.safeValidateTypes)({
|
1234
1321
|
value: latestObject,
|
1235
1322
|
schema
|
1236
1323
|
});
|
@@ -1378,7 +1465,7 @@ function prepareToolsAndToolChoice({
|
|
1378
1465
|
type: "function",
|
1379
1466
|
name,
|
1380
1467
|
description: tool2.description,
|
1381
|
-
parameters:
|
1468
|
+
parameters: asSchema(tool2.parameters).jsonSchema
|
1382
1469
|
})),
|
1383
1470
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
1384
1471
|
};
|
@@ -1386,7 +1473,7 @@ function prepareToolsAndToolChoice({
|
|
1386
1473
|
|
1387
1474
|
// core/generate-text/tool-call.ts
|
1388
1475
|
var import_provider6 = require("@ai-sdk/provider");
|
1389
|
-
var
|
1476
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
1390
1477
|
function parseToolCall({
|
1391
1478
|
toolCall,
|
1392
1479
|
tools
|
@@ -1402,9 +1489,9 @@ function parseToolCall({
|
|
1402
1489
|
availableTools: Object.keys(tools)
|
1403
1490
|
});
|
1404
1491
|
}
|
1405
|
-
const parseResult = (0,
|
1492
|
+
const parseResult = (0, import_provider_utils7.safeParseJSON)({
|
1406
1493
|
text: toolCall.args,
|
1407
|
-
schema: tool2.parameters
|
1494
|
+
schema: asSchema(tool2.parameters)
|
1408
1495
|
});
|
1409
1496
|
if (parseResult.success === false) {
|
1410
1497
|
throw new import_provider6.InvalidToolArgumentsError({
|
@@ -3619,8 +3706,8 @@ var StreamingTextResponse = class extends Response {
|
|
3619
3706
|
};
|
3620
3707
|
|
3621
3708
|
// streams/index.ts
|
3622
|
-
var generateId2 =
|
3623
|
-
var nanoid =
|
3709
|
+
var generateId2 = import_provider_utils8.generateId;
|
3710
|
+
var nanoid = import_provider_utils8.generateId;
|
3624
3711
|
// Annotate the CommonJS export names for ESM import in node:
|
3625
3712
|
0 && (module.exports = {
|
3626
3713
|
AIStream,
|
@@ -3684,6 +3771,7 @@ var nanoid = import_provider_utils7.generateId;
|
|
3684
3771
|
generateId,
|
3685
3772
|
generateObject,
|
3686
3773
|
generateText,
|
3774
|
+
jsonSchema,
|
3687
3775
|
nanoid,
|
3688
3776
|
parseComplexResponse,
|
3689
3777
|
parseStreamPart,
|