@ai-sdk/openai 2.0.0-beta.4 → 2.0.0-beta.5

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.mjs CHANGED
@@ -1883,6 +1883,9 @@ var openaiTranscriptionResponseSchema = z12.object({
1883
1883
  });
1884
1884
 
1885
1885
  // src/responses/openai-responses-language-model.ts
1886
+ import {
1887
+ APICallError
1888
+ } from "@ai-sdk/provider";
1886
1889
  import {
1887
1890
  combineHeaders as combineHeaders6,
1888
1891
  createEventSourceResponseHandler as createEventSourceResponseHandler3,
@@ -2016,7 +2019,7 @@ async function convertToOpenAIResponsesMessages({
2016
2019
  const summaryParts = [];
2017
2020
  if (part.text.length > 0) {
2018
2021
  summaryParts.push({ type: "summary_text", text: part.text });
2019
- } else {
2022
+ } else if (existingReasoningMessage !== void 0) {
2020
2023
  warnings.push({
2021
2024
  type: "other",
2022
2025
  message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
@@ -2336,15 +2339,16 @@ var OpenAIResponsesLanguageModel = class {
2336
2339
  async doGenerate(options) {
2337
2340
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2338
2341
  const { args: body, warnings } = await this.getArgs(options);
2342
+ const url = this.config.url({
2343
+ path: "/responses",
2344
+ modelId: this.modelId
2345
+ });
2339
2346
  const {
2340
2347
  responseHeaders,
2341
2348
  value: response,
2342
2349
  rawValue: rawResponse
2343
2350
  } = await postJsonToApi5({
2344
- url: this.config.url({
2345
- path: "/responses",
2346
- modelId: this.modelId
2347
- }),
2351
+ url,
2348
2352
  headers: combineHeaders6(this.config.headers(), options.headers),
2349
2353
  body,
2350
2354
  failedResponseHandler: openaiFailedResponseHandler,
@@ -2352,6 +2356,10 @@ var OpenAIResponsesLanguageModel = class {
2352
2356
  z14.object({
2353
2357
  id: z14.string(),
2354
2358
  created_at: z14.number(),
2359
+ error: z14.object({
2360
+ code: z14.string(),
2361
+ message: z14.string()
2362
+ }).nullish(),
2355
2363
  model: z14.string(),
2356
2364
  output: z14.array(
2357
2365
  z14.discriminatedUnion("type", [
@@ -2410,6 +2418,17 @@ var OpenAIResponsesLanguageModel = class {
2410
2418
  abortSignal: options.abortSignal,
2411
2419
  fetch: this.config.fetch
2412
2420
  });
2421
+ if (response.error) {
2422
+ throw new APICallError({
2423
+ message: response.error.message,
2424
+ url,
2425
+ requestBodyValues: body,
2426
+ statusCode: 400,
2427
+ responseHeaders,
2428
+ responseBody: rawResponse,
2429
+ isRetryable: false
2430
+ });
2431
+ }
2413
2432
  const content = [];
2414
2433
  for (const part of response.output) {
2415
2434
  switch (part.type) {
@@ -2752,6 +2771,8 @@ var OpenAIResponsesLanguageModel = class {
2752
2771
  url: value.annotation.url,
2753
2772
  title: value.annotation.title
2754
2773
  });
2774
+ } else if (isErrorChunk(value)) {
2775
+ controller.enqueue({ type: "error", error: value });
2755
2776
  }
2756
2777
  },
2757
2778
  flush(controller) {
@@ -2784,6 +2805,13 @@ var textDeltaChunkSchema = z14.object({
2784
2805
  item_id: z14.string(),
2785
2806
  delta: z14.string()
2786
2807
  });
2808
+ var errorChunkSchema = z14.object({
2809
+ type: z14.literal("error"),
2810
+ code: z14.string(),
2811
+ message: z14.string(),
2812
+ param: z14.string().nullish(),
2813
+ sequence_number: z14.number()
2814
+ });
2787
2815
  var responseFinishedChunkSchema = z14.object({
2788
2816
  type: z14.enum(["response.completed", "response.incomplete"]),
2789
2817
  response: z14.object({
@@ -2904,7 +2932,8 @@ var openaiResponsesChunkSchema = z14.union([
2904
2932
  responseFunctionCallArgumentsDeltaSchema,
2905
2933
  responseAnnotationAddedSchema,
2906
2934
  responseReasoningSummaryTextDeltaSchema,
2907
- z14.object({ type: z14.string() }).passthrough()
2935
+ errorChunkSchema,
2936
+ z14.object({ type: z14.string() }).loose()
2908
2937
  // fallback for unknown chunks
2909
2938
  ]);
2910
2939
  function isTextDeltaChunk(chunk) {
@@ -2931,6 +2960,9 @@ function isResponseAnnotationAddedChunk(chunk) {
2931
2960
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2932
2961
  return chunk.type === "response.reasoning_summary_text.delta";
2933
2962
  }
2963
+ function isErrorChunk(chunk) {
2964
+ return chunk.type === "error";
2965
+ }
2934
2966
  function getResponsesModelConfig(modelId) {
2935
2967
  if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
2936
2968
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {