@ai-sdk/openai 4.0.1 → 4.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 +13 -0
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +33 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +6 -0
- package/package.json +2 -2
- package/src/responses/openai-responses-language-model.ts +55 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1ead90c: Return a helpful error when the Responses stream parser receives Chat Completions chunks.
|
|
8
|
+
|
|
9
|
+
## 4.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [6a436e3]
|
|
14
|
+
- @ai-sdk/provider-utils@5.0.1
|
|
15
|
+
|
|
3
16
|
## 4.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -6541,8 +6541,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6541
6541
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6542
6542
|
}
|
|
6543
6543
|
if (!chunk.success) {
|
|
6544
|
+
const error = isOpenAIChatCompletionChunk(chunk.rawValue) ? createOpenAIResponsesChatCompletionsMismatchError({
|
|
6545
|
+
value: chunk.rawValue,
|
|
6546
|
+
cause: chunk.error,
|
|
6547
|
+
url,
|
|
6548
|
+
requestBodyValues: body,
|
|
6549
|
+
responseHeaders
|
|
6550
|
+
}) : chunk.error;
|
|
6544
6551
|
finishReason = { unified: "error", raw: void 0 };
|
|
6545
|
-
controller.enqueue({ type: "error", error
|
|
6552
|
+
controller.enqueue({ type: "error", error });
|
|
6546
6553
|
return;
|
|
6547
6554
|
}
|
|
6548
6555
|
const value = chunk.value;
|
|
@@ -7399,6 +7406,31 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7399
7406
|
function isTextDeltaChunk(chunk) {
|
|
7400
7407
|
return chunk.type === "response.output_text.delta";
|
|
7401
7408
|
}
|
|
7409
|
+
function isOpenAIChatCompletionChunk(value) {
|
|
7410
|
+
const chunk = asRecord2(value);
|
|
7411
|
+
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|
|
7412
|
+
}
|
|
7413
|
+
function createOpenAIResponsesChatCompletionsMismatchError({
|
|
7414
|
+
value,
|
|
7415
|
+
cause,
|
|
7416
|
+
url,
|
|
7417
|
+
requestBodyValues,
|
|
7418
|
+
responseHeaders
|
|
7419
|
+
}) {
|
|
7420
|
+
return new APICallError2({
|
|
7421
|
+
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.",
|
|
7422
|
+
url,
|
|
7423
|
+
requestBodyValues,
|
|
7424
|
+
responseHeaders,
|
|
7425
|
+
responseBody: JSON.stringify(value),
|
|
7426
|
+
cause,
|
|
7427
|
+
data: value,
|
|
7428
|
+
isRetryable: false
|
|
7429
|
+
});
|
|
7430
|
+
}
|
|
7431
|
+
function asRecord2(value) {
|
|
7432
|
+
return typeof value === "object" && value != null ? value : void 0;
|
|
7433
|
+
}
|
|
7402
7434
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
7403
7435
|
return chunk.type === "response.output_item.done";
|
|
7404
7436
|
}
|
|
@@ -7961,7 +7993,7 @@ var OpenAISkills = class {
|
|
|
7961
7993
|
};
|
|
7962
7994
|
|
|
7963
7995
|
// src/version.ts
|
|
7964
|
-
var VERSION = true ? "4.0.
|
|
7996
|
+
var VERSION = true ? "4.0.3" : "0.0.0-test";
|
|
7965
7997
|
|
|
7966
7998
|
// src/openai-provider.ts
|
|
7967
7999
|
function createOpenAI(options = {}) {
|