@ai-sdk/openai 3.0.77 → 3.0.78
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 +39 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +38 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +38 -5
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +18 -11
- package/package.json +1 -1
- package/src/responses/openai-responses-language-model.ts +61 -5
package/dist/internal/index.js
CHANGED
|
@@ -5835,11 +5835,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5835
5835
|
providerOptionsName,
|
|
5836
5836
|
isShellProviderExecuted
|
|
5837
5837
|
} = await this.getArgs(options);
|
|
5838
|
+
const url = this.config.url({
|
|
5839
|
+
path: "/responses",
|
|
5840
|
+
modelId: this.modelId
|
|
5841
|
+
});
|
|
5838
5842
|
const { responseHeaders, value: response } = await (0, import_provider_utils35.postJsonToApi)({
|
|
5839
|
-
url
|
|
5840
|
-
path: "/responses",
|
|
5841
|
-
modelId: this.modelId
|
|
5842
|
-
}),
|
|
5843
|
+
url,
|
|
5843
5844
|
headers: (0, import_provider_utils35.combineHeaders)(this.config.headers(), options.headers),
|
|
5844
5845
|
body: {
|
|
5845
5846
|
...body,
|
|
@@ -5881,8 +5882,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5881
5882
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5882
5883
|
}
|
|
5883
5884
|
if (!chunk.success) {
|
|
5885
|
+
const error = isOpenAIChatCompletionChunk(chunk.rawValue) ? createOpenAIResponsesChatCompletionsMismatchError({
|
|
5886
|
+
value: chunk.rawValue,
|
|
5887
|
+
cause: chunk.error,
|
|
5888
|
+
url,
|
|
5889
|
+
requestBodyValues: body,
|
|
5890
|
+
responseHeaders
|
|
5891
|
+
}) : chunk.error;
|
|
5884
5892
|
finishReason = { unified: "error", raw: void 0 };
|
|
5885
|
-
controller.enqueue({ type: "error", error
|
|
5893
|
+
controller.enqueue({ type: "error", error });
|
|
5886
5894
|
return;
|
|
5887
5895
|
}
|
|
5888
5896
|
const value = chunk.value;
|
|
@@ -6709,6 +6717,31 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6709
6717
|
function isTextDeltaChunk(chunk) {
|
|
6710
6718
|
return chunk.type === "response.output_text.delta";
|
|
6711
6719
|
}
|
|
6720
|
+
function isOpenAIChatCompletionChunk(value) {
|
|
6721
|
+
const chunk = asRecord(value);
|
|
6722
|
+
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|
|
6723
|
+
}
|
|
6724
|
+
function createOpenAIResponsesChatCompletionsMismatchError({
|
|
6725
|
+
value,
|
|
6726
|
+
cause,
|
|
6727
|
+
url,
|
|
6728
|
+
requestBodyValues,
|
|
6729
|
+
responseHeaders
|
|
6730
|
+
}) {
|
|
6731
|
+
return new import_provider8.APICallError({
|
|
6732
|
+
message: "Received a Chat Completions stream while using the OpenAI Responses API. The default OpenAI provider model uses the Responses API. If your custom baseURL targets a Chat Completions-compatible endpoint, use openai.chat('model-id') or createOpenAI(...).chat('model-id') instead. You can also use @ai-sdk/openai-compatible for OpenAI-compatible providers.",
|
|
6733
|
+
url,
|
|
6734
|
+
requestBodyValues,
|
|
6735
|
+
responseHeaders,
|
|
6736
|
+
responseBody: JSON.stringify(value),
|
|
6737
|
+
cause,
|
|
6738
|
+
data: value,
|
|
6739
|
+
isRetryable: false
|
|
6740
|
+
});
|
|
6741
|
+
}
|
|
6742
|
+
function asRecord(value) {
|
|
6743
|
+
return typeof value === "object" && value != null ? value : void 0;
|
|
6744
|
+
}
|
|
6712
6745
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
6713
6746
|
return chunk.type === "response.output_item.done";
|
|
6714
6747
|
}
|