@ai-sdk/openai 2.0.16 → 2.0.17

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
@@ -426,7 +426,23 @@ var webSearchPreviewArgsSchema = z4.object({
426
426
  var webSearchPreview = createProviderDefinedToolFactory2({
427
427
  id: "openai.web_search_preview",
428
428
  name: "web_search_preview",
429
- inputSchema: z4.object({})
429
+ inputSchema: z4.object({
430
+ action: z4.discriminatedUnion("type", [
431
+ z4.object({
432
+ type: z4.literal("search"),
433
+ query: z4.string()
434
+ }),
435
+ z4.object({
436
+ type: z4.literal("open_page"),
437
+ url: z4.string()
438
+ }),
439
+ z4.object({
440
+ type: z4.literal("find"),
441
+ url: z4.string(),
442
+ pattern: z4.string()
443
+ })
444
+ ]).nullish()
445
+ })
430
446
  });
431
447
 
432
448
  // src/chat/openai-chat-prepare-tools.ts
@@ -2150,6 +2166,26 @@ function prepareResponsesTools({
2150
2166
  }
2151
2167
 
2152
2168
  // src/responses/openai-responses-language-model.ts
2169
+ var webSearchCallItem = z13.object({
2170
+ type: z13.literal("web_search_call"),
2171
+ id: z13.string(),
2172
+ status: z13.string(),
2173
+ action: z13.discriminatedUnion("type", [
2174
+ z13.object({
2175
+ type: z13.literal("search"),
2176
+ query: z13.string()
2177
+ }),
2178
+ z13.object({
2179
+ type: z13.literal("open_page"),
2180
+ url: z13.string()
2181
+ }),
2182
+ z13.object({
2183
+ type: z13.literal("find"),
2184
+ url: z13.string(),
2185
+ pattern: z13.string()
2186
+ })
2187
+ ]).nullish()
2188
+ });
2153
2189
  var TOP_LOGPROBS_MAX = 20;
2154
2190
  var LOGPROBS_SCHEMA = z13.array(
2155
2191
  z13.object({
@@ -2345,7 +2381,7 @@ var OpenAIResponsesLanguageModel = class {
2345
2381
  };
2346
2382
  }
2347
2383
  async doGenerate(options) {
2348
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2384
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2349
2385
  const { args: body, warnings } = await this.getArgs(options);
2350
2386
  const url = this.config.url({
2351
2387
  path: "/responses",
@@ -2408,15 +2444,7 @@ var OpenAIResponsesLanguageModel = class {
2408
2444
  arguments: z13.string(),
2409
2445
  id: z13.string()
2410
2446
  }),
2411
- z13.object({
2412
- type: z13.literal("web_search_call"),
2413
- id: z13.string(),
2414
- status: z13.string().optional(),
2415
- action: z13.object({
2416
- type: z13.literal("search"),
2417
- query: z13.string().optional()
2418
- }).nullish()
2419
- }),
2447
+ webSearchCallItem,
2420
2448
  z13.object({
2421
2449
  type: z13.literal("computer_call"),
2422
2450
  id: z13.string(),
@@ -2547,17 +2575,14 @@ var OpenAIResponsesLanguageModel = class {
2547
2575
  type: "tool-call",
2548
2576
  toolCallId: part.id,
2549
2577
  toolName: "web_search_preview",
2550
- input: (_k = (_j = part.action) == null ? void 0 : _j.query) != null ? _k : "",
2578
+ input: JSON.stringify({ action: part.action }),
2551
2579
  providerExecuted: true
2552
2580
  });
2553
2581
  content.push({
2554
2582
  type: "tool-result",
2555
2583
  toolCallId: part.id,
2556
2584
  toolName: "web_search_preview",
2557
- result: {
2558
- status: part.status || "completed",
2559
- ...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
2560
- },
2585
+ result: { status: part.status },
2561
2586
  providerExecuted: true
2562
2587
  });
2563
2588
  break;
@@ -2615,15 +2640,15 @@ var OpenAIResponsesLanguageModel = class {
2615
2640
  return {
2616
2641
  content,
2617
2642
  finishReason: mapOpenAIResponseFinishReason({
2618
- finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
2643
+ finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
2619
2644
  hasToolCalls: content.some((part) => part.type === "tool-call")
2620
2645
  }),
2621
2646
  usage: {
2622
2647
  inputTokens: response.usage.input_tokens,
2623
2648
  outputTokens: response.usage.output_tokens,
2624
2649
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2625
- reasoningTokens: (_o = (_n = response.usage.output_tokens_details) == null ? void 0 : _n.reasoning_tokens) != null ? _o : void 0,
2626
- cachedInputTokens: (_q = (_p = response.usage.input_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
2650
+ reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
2651
+ cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
2627
2652
  },
2628
2653
  request: { body },
2629
2654
  response: {
@@ -2675,7 +2700,7 @@ var OpenAIResponsesLanguageModel = class {
2675
2700
  controller.enqueue({ type: "stream-start", warnings });
2676
2701
  },
2677
2702
  transform(chunk, controller) {
2678
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2703
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2679
2704
  if (options.includeRawChunks) {
2680
2705
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2681
2706
  }
@@ -2782,20 +2807,14 @@ var OpenAIResponsesLanguageModel = class {
2782
2807
  type: "tool-call",
2783
2808
  toolCallId: value.item.id,
2784
2809
  toolName: "web_search_preview",
2785
- input: (_c = (_b = value.item.action) == null ? void 0 : _b.query) != null ? _c : "",
2810
+ input: JSON.stringify({ action: value.item.action }),
2786
2811
  providerExecuted: true
2787
2812
  });
2788
2813
  controller.enqueue({
2789
2814
  type: "tool-result",
2790
2815
  toolCallId: value.item.id,
2791
2816
  toolName: "web_search_preview",
2792
- result: {
2793
- type: "web_search_tool_result",
2794
- status: value.item.status || "completed",
2795
- ...((_d = value.item.action) == null ? void 0 : _d.query) && {
2796
- query: value.item.action.query
2797
- }
2798
- },
2817
+ result: { status: value.item.status },
2799
2818
  providerExecuted: true
2800
2819
  });
2801
2820
  } else if (value.item.type === "computer_call") {
@@ -2862,7 +2881,7 @@ var OpenAIResponsesLanguageModel = class {
2862
2881
  providerMetadata: {
2863
2882
  openai: {
2864
2883
  itemId: value.item.id,
2865
- reasoningEncryptedContent: (_e = value.item.encrypted_content) != null ? _e : null
2884
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2866
2885
  }
2867
2886
  }
2868
2887
  });
@@ -2897,7 +2916,7 @@ var OpenAIResponsesLanguageModel = class {
2897
2916
  }
2898
2917
  } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2899
2918
  if (value.summary_index > 0) {
2900
- (_f = activeReasoning[value.item_id]) == null ? void 0 : _f.summaryParts.push(
2919
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2901
2920
  value.summary_index
2902
2921
  );
2903
2922
  controller.enqueue({
@@ -2906,7 +2925,7 @@ var OpenAIResponsesLanguageModel = class {
2906
2925
  providerMetadata: {
2907
2926
  openai: {
2908
2927
  itemId: value.item_id,
2909
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
2928
+ reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2910
2929
  }
2911
2930
  }
2912
2931
  });
@@ -2924,20 +2943,20 @@ var OpenAIResponsesLanguageModel = class {
2924
2943
  });
2925
2944
  } else if (isResponseFinishedChunk(value)) {
2926
2945
  finishReason = mapOpenAIResponseFinishReason({
2927
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
2946
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2928
2947
  hasToolCalls
2929
2948
  });
2930
2949
  usage.inputTokens = value.response.usage.input_tokens;
2931
2950
  usage.outputTokens = value.response.usage.output_tokens;
2932
2951
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2933
- usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
2934
- usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
2952
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2953
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2935
2954
  } else if (isResponseAnnotationAddedChunk(value)) {
2936
2955
  if (value.annotation.type === "url_citation") {
2937
2956
  controller.enqueue({
2938
2957
  type: "source",
2939
2958
  sourceType: "url",
2940
- id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
2959
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
2941
2960
  url: value.annotation.url,
2942
2961
  title: value.annotation.title
2943
2962
  });
@@ -2945,7 +2964,7 @@ var OpenAIResponsesLanguageModel = class {
2945
2964
  controller.enqueue({
2946
2965
  type: "source",
2947
2966
  sourceType: "document",
2948
- id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
2967
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
2949
2968
  mediaType: "text/plain",
2950
2969
  title: value.annotation.quote,
2951
2970
  filename: value.annotation.file_id
@@ -3085,15 +3104,7 @@ var responseOutputItemDoneSchema = z13.object({
3085
3104
  arguments: z13.string(),
3086
3105
  status: z13.literal("completed")
3087
3106
  }),
3088
- z13.object({
3089
- type: z13.literal("web_search_call"),
3090
- id: z13.string(),
3091
- status: z13.literal("completed"),
3092
- action: z13.object({
3093
- type: z13.literal("search"),
3094
- query: z13.string().optional()
3095
- }).nullish()
3096
- }),
3107
+ webSearchCallItem,
3097
3108
  z13.object({
3098
3109
  type: z13.literal("computer_call"),
3099
3110
  id: z13.string(),