@ai-sdk/openai-compatible 1.0.2 → 1.0.3
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 +6 -0
- package/dist/index.js +27 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
@@ -374,7 +374,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
374
374
|
};
|
375
375
|
}
|
376
376
|
async doGenerate(options) {
|
377
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
377
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
378
378
|
const { args, warnings } = await this.getArgs({ ...options });
|
379
379
|
const body = JSON.stringify(args);
|
380
380
|
const {
|
@@ -401,7 +401,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
401
401
|
if (text != null && text.length > 0) {
|
402
402
|
content.push({ type: "text", text });
|
403
403
|
}
|
404
|
-
const reasoning = choice.message.reasoning_content;
|
404
|
+
const reasoning = (_a = choice.message.reasoning_content) != null ? _a : choice.message.reasoning;
|
405
405
|
if (reasoning != null && reasoning.length > 0) {
|
406
406
|
content.push({
|
407
407
|
type: "reasoning",
|
@@ -412,7 +412,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
412
412
|
for (const toolCall of choice.message.tool_calls) {
|
413
413
|
content.push({
|
414
414
|
type: "tool-call",
|
415
|
-
toolCallId: (
|
415
|
+
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils.generateId)(),
|
416
416
|
toolName: toolCall.function.name,
|
417
417
|
input: toolCall.function.arguments
|
418
418
|
});
|
@@ -420,11 +420,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
420
420
|
}
|
421
421
|
const providerMetadata = {
|
422
422
|
[this.providerOptionsName]: {},
|
423
|
-
...await ((
|
423
|
+
...await ((_d = (_c = this.config.metadataExtractor) == null ? void 0 : _c.extractMetadata) == null ? void 0 : _d.call(_c, {
|
424
424
|
parsedBody: rawResponse
|
425
425
|
}))
|
426
426
|
};
|
427
|
-
const completionTokenDetails = (
|
427
|
+
const completionTokenDetails = (_e = responseBody.usage) == null ? void 0 : _e.completion_tokens_details;
|
428
428
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
429
429
|
providerMetadata[this.providerOptionsName].acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
430
430
|
}
|
@@ -435,11 +435,11 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
435
435
|
content,
|
436
436
|
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
437
437
|
usage: {
|
438
|
-
inputTokens: (
|
439
|
-
outputTokens: (
|
440
|
-
totalTokens: (
|
441
|
-
reasoningTokens: (
|
442
|
-
cachedInputTokens: (
|
438
|
+
inputTokens: (_g = (_f = responseBody.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : void 0,
|
439
|
+
outputTokens: (_i = (_h = responseBody.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : void 0,
|
440
|
+
totalTokens: (_k = (_j = responseBody.usage) == null ? void 0 : _j.total_tokens) != null ? _k : void 0,
|
441
|
+
reasoningTokens: (_n = (_m = (_l = responseBody.usage) == null ? void 0 : _l.completion_tokens_details) == null ? void 0 : _m.reasoning_tokens) != null ? _n : void 0,
|
442
|
+
cachedInputTokens: (_q = (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
|
443
443
|
},
|
444
444
|
providerMetadata,
|
445
445
|
request: { body },
|
@@ -502,7 +502,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
502
502
|
},
|
503
503
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
504
504
|
transform(chunk, controller) {
|
505
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
505
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
506
506
|
if (options.includeRawChunks) {
|
507
507
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
508
508
|
}
|
@@ -559,7 +559,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
559
559
|
return;
|
560
560
|
}
|
561
561
|
const delta = choice.delta;
|
562
|
-
|
562
|
+
const reasoningContent = (_a2 = delta.reasoning_content) != null ? _a2 : delta.reasoning;
|
563
|
+
if (reasoningContent) {
|
563
564
|
if (!isActiveReasoning) {
|
564
565
|
controller.enqueue({
|
565
566
|
type: "reasoning-start",
|
@@ -570,7 +571,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
570
571
|
controller.enqueue({
|
571
572
|
type: "reasoning-delta",
|
572
573
|
id: "reasoning-0",
|
573
|
-
delta:
|
574
|
+
delta: reasoningContent
|
574
575
|
});
|
575
576
|
}
|
576
577
|
if (delta.content) {
|
@@ -594,7 +595,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
594
595
|
message: `Expected 'id' to be a string.`
|
595
596
|
});
|
596
597
|
}
|
597
|
-
if (((
|
598
|
+
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
598
599
|
throw new import_provider3.InvalidResponseDataError({
|
599
600
|
data: toolCallDelta,
|
600
601
|
message: `Expected 'function.name' to be a string.`
|
@@ -610,12 +611,12 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
610
611
|
type: "function",
|
611
612
|
function: {
|
612
613
|
name: toolCallDelta.function.name,
|
613
|
-
arguments: (
|
614
|
+
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
614
615
|
},
|
615
616
|
hasFinished: false
|
616
617
|
};
|
617
618
|
const toolCall2 = toolCalls[index];
|
618
|
-
if (((
|
619
|
+
if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
|
619
620
|
if (toolCall2.function.arguments.length > 0) {
|
620
621
|
controller.enqueue({
|
621
622
|
type: "tool-input-start",
|
@@ -630,7 +631,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
630
631
|
});
|
631
632
|
controller.enqueue({
|
632
633
|
type: "tool-call",
|
633
|
-
toolCallId: (
|
634
|
+
toolCallId: (_f = toolCall2.id) != null ? _f : (0, import_provider_utils.generateId)(),
|
634
635
|
toolName: toolCall2.function.name,
|
635
636
|
input: toolCall2.function.arguments
|
636
637
|
});
|
@@ -643,22 +644,22 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
643
644
|
if (toolCall.hasFinished) {
|
644
645
|
continue;
|
645
646
|
}
|
646
|
-
if (((
|
647
|
-
toolCall.function.arguments += (
|
647
|
+
if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
|
648
|
+
toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
|
648
649
|
}
|
649
650
|
controller.enqueue({
|
650
651
|
type: "tool-input-delta",
|
651
652
|
id: toolCall.id,
|
652
|
-
delta: (
|
653
|
+
delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
|
653
654
|
});
|
654
|
-
if (((
|
655
|
+
if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && (0, import_provider_utils.isParsableJson)(toolCall.function.arguments)) {
|
655
656
|
controller.enqueue({
|
656
657
|
type: "tool-input-end",
|
657
658
|
id: toolCall.id
|
658
659
|
});
|
659
660
|
controller.enqueue({
|
660
661
|
type: "tool-call",
|
661
|
-
toolCallId: (
|
662
|
+
toolCallId: (_m = toolCall.id) != null ? _m : (0, import_provider_utils.generateId)(),
|
662
663
|
toolName: toolCall.function.name,
|
663
664
|
input: toolCall.function.arguments
|
664
665
|
});
|
@@ -742,6 +743,7 @@ var OpenAICompatibleChatResponseSchema = import_v43.z.object({
|
|
742
743
|
role: import_v43.z.literal("assistant").nullish(),
|
743
744
|
content: import_v43.z.string().nullish(),
|
744
745
|
reasoning_content: import_v43.z.string().nullish(),
|
746
|
+
reasoning: import_v43.z.string().nullish(),
|
745
747
|
tool_calls: import_v43.z.array(
|
746
748
|
import_v43.z.object({
|
747
749
|
id: import_v43.z.string().nullish(),
|
@@ -767,7 +769,10 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_v43.z.union(
|
|
767
769
|
delta: import_v43.z.object({
|
768
770
|
role: import_v43.z.enum(["assistant"]).nullish(),
|
769
771
|
content: import_v43.z.string().nullish(),
|
772
|
+
// Most openai-compatible models set `reasoning_content`, but some
|
773
|
+
// providers serving `gpt-oss` set `reasoning`. See #7866
|
770
774
|
reasoning_content: import_v43.z.string().nullish(),
|
775
|
+
reasoning: import_v43.z.string().nullish(),
|
771
776
|
tool_calls: import_v43.z.array(
|
772
777
|
import_v43.z.object({
|
773
778
|
index: import_v43.z.number(),
|