@zenning/openai 1.5.0 → 1.6.0

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.
@@ -2705,55 +2705,31 @@ var OpenAIResponsesLanguageModel = class {
2705
2705
  }
2706
2706
  const reasoningSummary = (_b = (_a15 = response.output.find((item) => item.type === "reasoning")) == null ? void 0 : _a15.summary) != null ? _b : null;
2707
2707
  const allAnnotations = outputTextElements.flatMap((content) => content.annotations);
2708
- console.log("\u{1F4CB} Processing annotations in doGenerate:", JSON.stringify({
2709
- msg: "ai-sdk: content annotations",
2710
- count: allAnnotations.length,
2711
- annotations: allAnnotations
2712
- }, null, 2));
2713
2708
  return {
2714
2709
  text: outputTextElements.map((content) => content.text).join("\n"),
2715
2710
  sources: outputTextElements.flatMap(
2716
2711
  (content) => content.annotations.map((annotation) => {
2717
- var _a16, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j, _k, _l;
2718
- console.log("\u{1F517} Processing annotation for source:", JSON.stringify(annotation, null, 2));
2719
- try {
2720
- if (annotation.type === "url_citation") {
2721
- const urlSource = {
2722
- sourceType: "url",
2723
- id: (_c2 = (_b2 = (_a16 = this.config).generateId) == null ? void 0 : _b2.call(_a16)) != null ? _c2 : generateId2(),
2724
- url: annotation.url,
2725
- title: annotation.title
2726
- };
2727
- console.log("\u2705 Created URL source:", JSON.stringify(urlSource, null, 2));
2728
- return urlSource;
2729
- } else if (annotation.type === "file_citation") {
2730
- const urlSource = {
2731
- sourceType: "url",
2732
- id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : generateId2(),
2733
- url: `file://${annotation.file_id}`,
2734
- title: annotation.quote || annotation.filename || "Document"
2735
- };
2736
- console.log("\u{1F4C4} Created URL source for file citation:", JSON.stringify(urlSource, null, 2));
2737
- return urlSource;
2738
- } else {
2739
- console.log("\u26A0\uFE0F Unknown annotation type in doGenerate:", annotation.type);
2740
- return {
2741
- sourceType: "url",
2742
- id: (_i = (_h = (_g2 = this.config).generateId) == null ? void 0 : _h.call(_g2)) != null ? _i : generateId2(),
2743
- url: "",
2744
- title: "Unknown Source"
2745
- };
2746
- }
2747
- } catch (error) {
2748
- console.error("\u274C Error creating source in doGenerate:", {
2749
- annotation,
2750
- error: error instanceof Error ? error.message : String(error)
2751
- });
2712
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i;
2713
+ if (annotation.type === "url_citation") {
2714
+ return {
2715
+ sourceType: "url",
2716
+ id: (_c2 = (_b2 = (_a16 = this.config).generateId) == null ? void 0 : _b2.call(_a16)) != null ? _c2 : generateId2(),
2717
+ url: annotation.url,
2718
+ title: annotation.title
2719
+ };
2720
+ } else if (annotation.type === "file_citation") {
2752
2721
  return {
2753
2722
  sourceType: "url",
2754
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
2723
+ id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : generateId2(),
2724
+ url: `file://${annotation.file_id}`,
2725
+ title: annotation.quote || annotation.filename || "Document"
2726
+ };
2727
+ } else {
2728
+ return {
2729
+ sourceType: "url",
2730
+ id: (_i = (_h = (_g2 = this.config).generateId) == null ? void 0 : _h.call(_g2)) != null ? _i : generateId2(),
2755
2731
  url: "",
2756
- title: "Error Source"
2732
+ title: "Unknown Source"
2757
2733
  };
2758
2734
  }
2759
2735
  })
@@ -2798,16 +2774,10 @@ var OpenAIResponsesLanguageModel = class {
2798
2774
  };
2799
2775
  }
2800
2776
  async doStream(options) {
2801
- console.log("\u{1F680} Starting doStream with options:", JSON.stringify({
2802
- modelId: this.modelId,
2803
- hasAbortSignal: !!options.abortSignal
2804
- }, null, 2));
2805
2777
  const { args: body, warnings } = this.getArgs(options);
2806
- console.log("\u{1F4E4} Request body:", JSON.stringify(body, null, 2));
2807
2778
  let response;
2808
2779
  let responseHeaders;
2809
2780
  try {
2810
- console.log("\u{1F4E1} Making API request...");
2811
2781
  const result = await postJsonToApi6({
2812
2782
  url: this.config.url({
2813
2783
  path: "/responses",
@@ -2827,7 +2797,6 @@ var OpenAIResponsesLanguageModel = class {
2827
2797
  });
2828
2798
  response = result.value;
2829
2799
  responseHeaders = result.responseHeaders;
2830
- console.log("\u2705 API request successful, starting stream processing");
2831
2800
  } catch (error) {
2832
2801
  console.error("\u274C API request failed:", error);
2833
2802
  throw error;
@@ -2845,9 +2814,8 @@ var OpenAIResponsesLanguageModel = class {
2845
2814
  stream: response.pipeThrough(
2846
2815
  new TransformStream({
2847
2816
  transform(chunk, controller) {
2848
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2817
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2849
2818
  try {
2850
- console.log("\u{1F4E6} Processing chunk:", JSON.stringify(chunk, null, 2));
2851
2819
  if (!chunk.success) {
2852
2820
  console.error("\u274C Chunk parsing failed:", chunk.error);
2853
2821
  finishReason = "error";
@@ -2855,9 +2823,7 @@ var OpenAIResponsesLanguageModel = class {
2855
2823
  return;
2856
2824
  }
2857
2825
  const value = chunk.value;
2858
- console.log("\u{1F4E5} Chunk value type:", value.type);
2859
2826
  if (isResponseOutputItemAddedChunk(value)) {
2860
- console.log("\u{1F4DD} Output item added:", JSON.stringify(value, null, 2));
2861
2827
  if (value.item.type === "function_call") {
2862
2828
  ongoingToolCalls[value.output_index] = {
2863
2829
  toolName: value.item.name,
@@ -2920,7 +2886,6 @@ var OpenAIResponsesLanguageModel = class {
2920
2886
  });
2921
2887
  }
2922
2888
  } else if (isResponseCreatedChunk(value)) {
2923
- console.log("\u{1F680} Response created:", JSON.stringify(value, null, 2));
2924
2889
  responseId = value.response.id;
2925
2890
  controller.enqueue({
2926
2891
  type: "response-metadata",
@@ -2929,19 +2894,16 @@ var OpenAIResponsesLanguageModel = class {
2929
2894
  modelId: value.response.model
2930
2895
  });
2931
2896
  } else if (isTextDeltaChunk(value)) {
2932
- console.log("\u{1F4DD} Text delta chunk:", JSON.stringify(value, null, 2));
2933
2897
  controller.enqueue({
2934
2898
  type: "text-delta",
2935
2899
  textDelta: value.delta
2936
2900
  });
2937
2901
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2938
- console.log("\u{1F9E0} Reasoning summary delta:", JSON.stringify(value, null, 2));
2939
2902
  controller.enqueue({
2940
2903
  type: "reasoning",
2941
2904
  textDelta: value.delta
2942
2905
  });
2943
2906
  } else if (isResponseOutputItemDoneChunk(value)) {
2944
- console.log("\u2705 Output item done:", JSON.stringify(value, null, 2));
2945
2907
  if (value.item.type === "function_call") {
2946
2908
  ongoingToolCalls[value.output_index] = void 0;
2947
2909
  hasToolCalls = true;
@@ -2973,115 +2935,67 @@ var OpenAIResponsesLanguageModel = class {
2973
2935
  args: ""
2974
2936
  });
2975
2937
  } else if (value.item.type === "file_search_call") {
2976
- console.log("\u{1F4C1} File search call completed:", JSON.stringify({
2977
- id: value.item.id,
2978
- status: value.item.status,
2979
- queries: value.item.queries,
2980
- resultsCount: ((_a15 = value.item.results) == null ? void 0 : _a15.length) || 0
2981
- }, null, 2));
2982
2938
  ongoingToolCalls[value.output_index] = void 0;
2983
2939
  hasToolCalls = true;
2984
- try {
2985
- controller.enqueue({
2986
- type: "tool-call",
2987
- toolCallType: "function",
2988
- toolCallId: value.item.id,
2989
- toolName: "file_search",
2990
- args: JSON.stringify({
2991
- queries: value.item.queries,
2992
- results: value.item.results
2993
- })
2994
- });
2995
- console.log("\u2705 File search tool call enqueued successfully");
2996
- } catch (error) {
2997
- console.error("\u274C Error enqueuing file search tool call:", error);
2998
- }
2940
+ controller.enqueue({
2941
+ type: "tool-call",
2942
+ toolCallType: "function",
2943
+ toolCallId: value.item.id,
2944
+ toolName: "file_search",
2945
+ args: JSON.stringify({
2946
+ queries: value.item.queries,
2947
+ results: value.item.results
2948
+ })
2949
+ });
2999
2950
  }
3000
2951
  } else if (isResponseFinishedChunk(value)) {
3001
- console.log("\u{1F3C1} Response finished:", JSON.stringify(value, null, 2));
3002
2952
  finishReason = mapOpenAIResponseFinishReason({
3003
- finishReason: (_b = value.response.incomplete_details) == null ? void 0 : _b.reason,
2953
+ finishReason: (_a15 = value.response.incomplete_details) == null ? void 0 : _a15.reason,
3004
2954
  hasToolCalls
3005
2955
  });
3006
2956
  promptTokens = value.response.usage.input_tokens;
3007
2957
  completionTokens = value.response.usage.output_tokens;
3008
- cachedPromptTokens = (_d = (_c = value.response.usage.input_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : cachedPromptTokens;
3009
- reasoningTokens = (_f = (_e = value.response.usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : reasoningTokens;
2958
+ cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
2959
+ reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
3010
2960
  } else if (isResponseAnnotationAddedChunk(value)) {
3011
- console.log("\u{1F50D} Processing annotation chunk:", JSON.stringify({
3012
- type: value.type,
3013
- annotation: value.annotation
3014
- }, null, 2));
3015
2961
  try {
3016
- console.log("\u{1F50D} Annotation processing - step 1: Validating annotation structure");
3017
- if (!value.annotation || typeof value.annotation !== "object") {
3018
- throw new Error("Invalid annotation structure");
3019
- }
3020
- console.log("\u{1F50D} Annotation processing - step 2: Checking annotation type");
3021
2962
  if (value.annotation.type === "url_citation") {
3022
- console.log("\u{1F310} Processing URL citation");
3023
2963
  const urlSource = {
3024
2964
  sourceType: "url",
3025
- id: (_i = (_h = (_g = self.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2(),
2965
+ id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
3026
2966
  url: String(value.annotation.url || ""),
3027
2967
  title: String(value.annotation.title || "Web Source")
3028
2968
  };
3029
- console.log("\u2705 Created URL source:", JSON.stringify(urlSource, null, 2));
3030
- console.log("\u{1F50D} Annotation processing - step 3: Enqueuing URL source");
3031
2969
  controller.enqueue({
3032
2970
  type: "source",
3033
2971
  source: urlSource
3034
2972
  });
3035
- console.log("\u2705 URL source enqueued successfully");
3036
2973
  } else if (value.annotation.type === "file_citation") {
3037
- console.log("\u{1F4C4} Processing FILE citation - using URL format for v4 compatibility");
3038
- console.log("\u{1F4C4} File citation raw data:", JSON.stringify(value.annotation, null, 2));
3039
2974
  const urlSource = {
3040
2975
  sourceType: "url",
3041
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
2976
+ id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId2(),
3042
2977
  url: `file://${value.annotation.file_id}`,
3043
2978
  title: String(value.annotation.quote || value.annotation.filename || "Document")
3044
2979
  };
3045
- console.log("\u{1F4C4} Created URL source for file citation:", JSON.stringify(urlSource, null, 2));
3046
- console.log("\u{1F50D} Annotation processing - step 3: Enqueuing URL source");
3047
2980
  controller.enqueue({
3048
2981
  type: "source",
3049
2982
  source: urlSource
3050
2983
  });
3051
- console.log("\u2705 File citation URL source enqueued successfully");
3052
- } else {
3053
- console.log("\u26A0\uFE0F Unknown annotation type:", value.annotation.type);
3054
2984
  }
3055
2985
  } catch (error) {
3056
- console.error("\u274C CRITICAL ERROR in annotation processing:", {
3057
- step: "annotation processing",
3058
- annotation: value.annotation,
3059
- error: error instanceof Error ? error.message : String(error),
3060
- stack: error instanceof Error ? error.stack : void 0
3061
- });
3062
- console.log("\u{1F6E1}\uFE0F Continuing stream without this annotation to prevent total failure");
2986
+ console.error("\u274C Error processing annotation:", error);
3063
2987
  }
3064
2988
  } else if (isResponseInProgressChunk(value)) {
3065
- console.log("\u23F3 Response in progress (ignored):", value.type);
3066
2989
  } else if (isResponseContentPartAddedChunk(value)) {
3067
- console.log("\u{1F4DD} Content part added (ignored):", value.type);
3068
2990
  } else if (isResponseOutputTextDoneChunk(value)) {
3069
- console.log("\u2705 Output text done (ignored):", value.type);
3070
2991
  } else if (isResponseContentPartDoneChunk(value)) {
3071
- console.log("\u2705 Content part done (ignored):", value.type);
3072
2992
  } else if (isResponseFileSearchCallInProgressChunk(value)) {
3073
- console.log("\u{1F50D} File search in progress (ignored):", value.type);
3074
2993
  } else if (isResponseFileSearchCallSearchingChunk(value)) {
3075
- console.log("\u{1F50D} File search searching (ignored):", value.type);
3076
2994
  } else if (isResponseFileSearchCallCompletedChunk(value)) {
3077
- console.log("\u2705 File search completed (ignored):", value.type);
3078
2995
  } else if (isResponseFileSearchCallQueryAddedChunk(value)) {
3079
- console.log("\u{1F50D} File search query added (ignored):", value.type, "Query:", value.query);
3080
2996
  } else if (isResponseFileSearchCallResultAddedChunk(value)) {
3081
- console.log("\u{1F4C4} File search result added (ignored):", value.type);
3082
- console.log("\u{1F4C4} File search result details:", JSON.stringify(value.result, null, 2));
3083
2997
  } else {
3084
- console.log("\u2753 Unhandled chunk type:", value.type, JSON.stringify(value, null, 2));
2998
+ console.log("\u2753 Unhandled chunk type:", value.type);
3085
2999
  }
3086
3000
  } catch (error) {
3087
3001
  console.error("\u{1F4A5} FATAL ERROR in chunk processing:", {
@@ -3183,6 +3097,9 @@ var responseOutputItemDoneSchema = z12.object({
3183
3097
  })
3184
3098
  ]).nullish()
3185
3099
  }),
3100
+ z12.object({
3101
+ type: z12.literal("code_interpreter_call")
3102
+ }),
3186
3103
  z12.object({
3187
3104
  type: z12.literal("computer_call"),
3188
3105
  id: z12.string(),
@@ -3442,7 +3359,17 @@ function getResponsesModelConfig(modelId) {
3442
3359
  var openaiResponsesProviderOptionsSchema = z12.object({
3443
3360
  metadata: z12.any().nullish(),
3444
3361
  parallelToolCalls: z12.boolean().nullish(),
3445
- include: z12.array(z12.string()).nullish(),
3362
+ include: z12.array(
3363
+ z12.enum([
3364
+ "file_search_call.results",
3365
+ "code_interpreter_call.output",
3366
+ "web_search_call.results",
3367
+ "message.input_image.image_url",
3368
+ "computer_call_output.output.image_url",
3369
+ "reasoning.encrypted_content",
3370
+ "message.output_text.logprobs"
3371
+ ])
3372
+ ).nullish(),
3446
3373
  previousResponseId: z12.string().nullish(),
3447
3374
  forceNoTemperature: z12.boolean().nullish(),
3448
3375
  store: z12.boolean().nullish(),