@ai-sdk/openai 2.0.13 → 2.0.14

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
@@ -2345,7 +2345,7 @@ var OpenAIResponsesLanguageModel = class {
2345
2345
  };
2346
2346
  }
2347
2347
  async doGenerate(options) {
2348
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2348
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2349
2349
  const { args: body, warnings } = await this.getArgs(options);
2350
2350
  const url = this.config.url({
2351
2351
  path: "/responses",
@@ -2381,13 +2381,22 @@ var OpenAIResponsesLanguageModel = class {
2381
2381
  text: z13.string(),
2382
2382
  logprobs: LOGPROBS_SCHEMA.nullish(),
2383
2383
  annotations: z13.array(
2384
- z13.object({
2385
- type: z13.literal("url_citation"),
2386
- start_index: z13.number(),
2387
- end_index: z13.number(),
2388
- url: z13.string(),
2389
- title: z13.string()
2390
- })
2384
+ z13.discriminatedUnion("type", [
2385
+ z13.object({
2386
+ type: z13.literal("url_citation"),
2387
+ start_index: z13.number(),
2388
+ end_index: z13.number(),
2389
+ url: z13.string(),
2390
+ title: z13.string()
2391
+ }),
2392
+ z13.object({
2393
+ type: z13.literal("file_citation"),
2394
+ start_index: z13.number(),
2395
+ end_index: z13.number(),
2396
+ file_id: z13.string(),
2397
+ quote: z13.string()
2398
+ })
2399
+ ])
2391
2400
  )
2392
2401
  })
2393
2402
  )
@@ -2493,13 +2502,24 @@ var OpenAIResponsesLanguageModel = class {
2493
2502
  }
2494
2503
  });
2495
2504
  for (const annotation of contentPart.annotations) {
2496
- content.push({
2497
- type: "source",
2498
- sourceType: "url",
2499
- id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId2(),
2500
- url: annotation.url,
2501
- title: annotation.title
2502
- });
2505
+ if (annotation.type === "url_citation") {
2506
+ content.push({
2507
+ type: "source",
2508
+ sourceType: "url",
2509
+ id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId2(),
2510
+ url: annotation.url,
2511
+ title: annotation.title
2512
+ });
2513
+ } else if (annotation.type === "file_citation") {
2514
+ content.push({
2515
+ type: "source",
2516
+ sourceType: "document",
2517
+ id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2(),
2518
+ mediaType: "text/plain",
2519
+ title: annotation.quote,
2520
+ filename: annotation.file_id
2521
+ });
2522
+ }
2503
2523
  }
2504
2524
  }
2505
2525
  break;
@@ -2588,15 +2608,15 @@ var OpenAIResponsesLanguageModel = class {
2588
2608
  return {
2589
2609
  content,
2590
2610
  finishReason: mapOpenAIResponseFinishReason({
2591
- finishReason: (_g = response.incomplete_details) == null ? void 0 : _g.reason,
2611
+ finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
2592
2612
  hasToolCalls: content.some((part) => part.type === "tool-call")
2593
2613
  }),
2594
2614
  usage: {
2595
2615
  inputTokens: response.usage.input_tokens,
2596
2616
  outputTokens: response.usage.output_tokens,
2597
2617
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2598
- reasoningTokens: (_i = (_h = response.usage.output_tokens_details) == null ? void 0 : _h.reasoning_tokens) != null ? _i : void 0,
2599
- cachedInputTokens: (_k = (_j = response.usage.input_tokens_details) == null ? void 0 : _j.cached_tokens) != null ? _k : void 0
2618
+ reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
2619
+ cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
2600
2620
  },
2601
2621
  request: { body },
2602
2622
  response: {
@@ -2648,7 +2668,7 @@ var OpenAIResponsesLanguageModel = class {
2648
2668
  controller.enqueue({ type: "stream-start", warnings });
2649
2669
  },
2650
2670
  transform(chunk, controller) {
2651
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2671
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2652
2672
  if (options.includeRawChunks) {
2653
2673
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2654
2674
  }
@@ -2903,13 +2923,24 @@ var OpenAIResponsesLanguageModel = class {
2903
2923
  usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2904
2924
  usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2905
2925
  } else if (isResponseAnnotationAddedChunk(value)) {
2906
- controller.enqueue({
2907
- type: "source",
2908
- sourceType: "url",
2909
- id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
2910
- url: value.annotation.url,
2911
- title: value.annotation.title
2912
- });
2926
+ if (value.annotation.type === "url_citation") {
2927
+ controller.enqueue({
2928
+ type: "source",
2929
+ sourceType: "url",
2930
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
2931
+ url: value.annotation.url,
2932
+ title: value.annotation.title
2933
+ });
2934
+ } else if (value.annotation.type === "file_citation") {
2935
+ controller.enqueue({
2936
+ type: "source",
2937
+ sourceType: "document",
2938
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
2939
+ mediaType: "text/plain",
2940
+ title: value.annotation.quote,
2941
+ filename: value.annotation.file_id
2942
+ });
2943
+ }
2913
2944
  } else if (isErrorChunk(value)) {
2914
2945
  controller.enqueue({ type: "error", error: value });
2915
2946
  }
@@ -3076,11 +3107,18 @@ var responseFunctionCallArgumentsDeltaSchema = z13.object({
3076
3107
  });
3077
3108
  var responseAnnotationAddedSchema = z13.object({
3078
3109
  type: z13.literal("response.output_text.annotation.added"),
3079
- annotation: z13.object({
3080
- type: z13.literal("url_citation"),
3081
- url: z13.string(),
3082
- title: z13.string()
3083
- })
3110
+ annotation: z13.discriminatedUnion("type", [
3111
+ z13.object({
3112
+ type: z13.literal("url_citation"),
3113
+ url: z13.string(),
3114
+ title: z13.string()
3115
+ }),
3116
+ z13.object({
3117
+ type: z13.literal("file_citation"),
3118
+ file_id: z13.string(),
3119
+ quote: z13.string()
3120
+ })
3121
+ ])
3084
3122
  });
3085
3123
  var responseReasoningSummaryPartAddedSchema = z13.object({
3086
3124
  type: z13.literal("response.reasoning_summary_part.added"),