@zenning/openai 1.4.7 → 1.4.9

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.js CHANGED
@@ -2652,16 +2652,14 @@ var OpenAIResponsesLanguageModel = class {
2652
2652
  console.log("\u2705 Created URL source:", JSON.stringify(urlSource, null, 2));
2653
2653
  return urlSource;
2654
2654
  } else if (annotation.type === "file_citation") {
2655
- const documentSource = {
2656
- sourceType: "document",
2655
+ const urlSource = {
2656
+ sourceType: "url",
2657
2657
  id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : (0, import_provider_utils9.generateId)(),
2658
- mediaType: "text/plain",
2659
- title: annotation.quote || annotation.filename || "Document",
2660
- filename: annotation.filename,
2661
- quote: annotation.quote
2658
+ url: `file://${annotation.file_id}`,
2659
+ title: annotation.quote || annotation.filename || "Document"
2662
2660
  };
2663
- console.log("\u{1F4C4} Created document source:", JSON.stringify(documentSource, null, 2));
2664
- return documentSource;
2661
+ console.log("\u{1F4C4} Created URL source for file citation:", JSON.stringify(urlSource, null, 2));
2662
+ return urlSource;
2665
2663
  } else {
2666
2664
  console.log("\u26A0\uFE0F Unknown annotation type in doGenerate:", annotation.type);
2667
2665
  return {
@@ -2772,7 +2770,7 @@ var OpenAIResponsesLanguageModel = class {
2772
2770
  stream: response.pipeThrough(
2773
2771
  new TransformStream({
2774
2772
  transform(chunk, controller) {
2775
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2773
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2776
2774
  try {
2777
2775
  console.log("\u{1F4E6} Processing chunk:", JSON.stringify(chunk, null, 2));
2778
2776
  if (!chunk.success) {
@@ -2900,72 +2898,93 @@ var OpenAIResponsesLanguageModel = class {
2900
2898
  args: ""
2901
2899
  });
2902
2900
  } else if (value.item.type === "file_search_call") {
2901
+ console.log("\u{1F4C1} File search call completed:", JSON.stringify({
2902
+ id: value.item.id,
2903
+ status: value.item.status,
2904
+ queries: value.item.queries,
2905
+ resultsCount: ((_a15 = value.item.results) == null ? void 0 : _a15.length) || 0
2906
+ }, null, 2));
2903
2907
  ongoingToolCalls[value.output_index] = void 0;
2904
2908
  hasToolCalls = true;
2905
- controller.enqueue({
2906
- type: "tool-call",
2907
- toolCallType: "function",
2908
- toolCallId: value.item.id,
2909
- toolName: "file_search",
2910
- args: JSON.stringify({
2911
- queries: value.item.queries,
2912
- results: value.item.results
2913
- })
2914
- });
2909
+ try {
2910
+ controller.enqueue({
2911
+ type: "tool-call",
2912
+ toolCallType: "function",
2913
+ toolCallId: value.item.id,
2914
+ toolName: "file_search",
2915
+ args: JSON.stringify({
2916
+ queries: value.item.queries,
2917
+ results: value.item.results
2918
+ })
2919
+ });
2920
+ console.log("\u2705 File search tool call enqueued successfully");
2921
+ } catch (error) {
2922
+ console.error("\u274C Error enqueuing file search tool call:", error);
2923
+ }
2915
2924
  }
2916
2925
  } else if (isResponseFinishedChunk(value)) {
2917
2926
  console.log("\u{1F3C1} Response finished:", JSON.stringify(value, null, 2));
2918
2927
  finishReason = mapOpenAIResponseFinishReason({
2919
- finishReason: (_a15 = value.response.incomplete_details) == null ? void 0 : _a15.reason,
2928
+ finishReason: (_b = value.response.incomplete_details) == null ? void 0 : _b.reason,
2920
2929
  hasToolCalls
2921
2930
  });
2922
2931
  promptTokens = value.response.usage.input_tokens;
2923
2932
  completionTokens = value.response.usage.output_tokens;
2924
- cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
2925
- reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
2933
+ cachedPromptTokens = (_d = (_c = value.response.usage.input_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : cachedPromptTokens;
2934
+ reasoningTokens = (_f = (_e = value.response.usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : reasoningTokens;
2926
2935
  } else if (isResponseAnnotationAddedChunk(value)) {
2927
2936
  console.log("\u{1F50D} Processing annotation chunk:", JSON.stringify({
2928
2937
  type: value.type,
2929
2938
  annotation: value.annotation
2930
2939
  }, null, 2));
2931
2940
  try {
2941
+ console.log("\u{1F50D} Annotation processing - step 1: Validating annotation structure");
2942
+ if (!value.annotation || typeof value.annotation !== "object") {
2943
+ throw new Error("Invalid annotation structure");
2944
+ }
2945
+ console.log("\u{1F50D} Annotation processing - step 2: Checking annotation type");
2932
2946
  if (value.annotation.type === "url_citation") {
2947
+ console.log("\u{1F310} Processing URL citation");
2933
2948
  const urlSource = {
2934
2949
  sourceType: "url",
2935
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils9.generateId)(),
2936
- url: value.annotation.url,
2937
- title: value.annotation.title
2950
+ id: (_i = (_h = (_g = self.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils9.generateId)(),
2951
+ url: String(value.annotation.url || ""),
2952
+ title: String(value.annotation.title || "Web Source")
2938
2953
  };
2939
- console.log("\u2705 Creating URL source:", JSON.stringify(urlSource, null, 2));
2954
+ console.log("\u2705 Created URL source:", JSON.stringify(urlSource, null, 2));
2955
+ console.log("\u{1F50D} Annotation processing - step 3: Enqueuing URL source");
2940
2956
  controller.enqueue({
2941
2957
  type: "source",
2942
2958
  source: urlSource
2943
2959
  });
2944
2960
  console.log("\u2705 URL source enqueued successfully");
2945
2961
  } else if (value.annotation.type === "file_citation") {
2946
- const documentSource = {
2947
- sourceType: "document",
2948
- id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils9.generateId)(),
2949
- mediaType: "text/plain",
2950
- title: value.annotation.quote || value.annotation.filename || "Document",
2951
- filename: value.annotation.filename,
2952
- quote: value.annotation.quote
2962
+ console.log("\u{1F4C4} Processing FILE citation - using URL format for v4 compatibility");
2963
+ console.log("\u{1F4C4} File citation raw data:", JSON.stringify(value.annotation, null, 2));
2964
+ const urlSource = {
2965
+ sourceType: "url",
2966
+ id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils9.generateId)(),
2967
+ url: `file://${value.annotation.file_id}`,
2968
+ title: String(value.annotation.quote || value.annotation.filename || "Document")
2953
2969
  };
2954
- console.log("\u{1F4C4} Creating document source:", JSON.stringify(documentSource, null, 2));
2970
+ console.log("\u{1F4C4} Created URL source for file citation:", JSON.stringify(urlSource, null, 2));
2971
+ console.log("\u{1F50D} Annotation processing - step 3: Enqueuing URL source");
2955
2972
  controller.enqueue({
2956
2973
  type: "source",
2957
- source: documentSource
2974
+ source: urlSource
2958
2975
  });
2959
- console.log("\u2705 Document source enqueued successfully");
2976
+ console.log("\u2705 File citation URL source enqueued successfully");
2960
2977
  } else {
2961
2978
  console.log("\u26A0\uFE0F Unknown annotation type:", value.annotation.type);
2962
2979
  }
2963
2980
  } catch (error) {
2964
- console.error("\u274C Error processing annotation:", {
2981
+ console.error("\u274C CRITICAL ERROR in annotation processing:", {
2982
+ step: "annotation processing",
2965
2983
  annotation: value.annotation,
2966
2984
  error: error instanceof Error ? error.message : String(error),
2967
2985
  stack: error instanceof Error ? error.stack : void 0
2968
2986
  });
2987
+ console.log("\u{1F6E1}\uFE0F Continuing stream without this annotation to prevent total failure");
2969
2988
  }
2970
2989
  } else if (isResponseInProgressChunk(value)) {
2971
2990
  console.log("\u23F3 Response in progress (ignored):", value.type);
@@ -2975,6 +2994,17 @@ var OpenAIResponsesLanguageModel = class {
2975
2994
  console.log("\u2705 Output text done (ignored):", value.type);
2976
2995
  } else if (isResponseContentPartDoneChunk(value)) {
2977
2996
  console.log("\u2705 Content part done (ignored):", value.type);
2997
+ } else if (isResponseFileSearchCallInProgressChunk(value)) {
2998
+ console.log("\u{1F50D} File search in progress (ignored):", value.type);
2999
+ } else if (isResponseFileSearchCallSearchingChunk(value)) {
3000
+ console.log("\u{1F50D} File search searching (ignored):", value.type);
3001
+ } else if (isResponseFileSearchCallCompletedChunk(value)) {
3002
+ console.log("\u2705 File search completed (ignored):", value.type);
3003
+ } else if (isResponseFileSearchCallQueryAddedChunk(value)) {
3004
+ console.log("\u{1F50D} File search query added (ignored):", value.type, "Query:", value.query);
3005
+ } else if (isResponseFileSearchCallResultAddedChunk(value)) {
3006
+ console.log("\u{1F4C4} File search result added (ignored):", value.type);
3007
+ console.log("\u{1F4C4} File search result details:", JSON.stringify(value.result, null, 2));
2978
3008
  } else {
2979
3009
  console.log("\u2753 Unhandled chunk type:", value.type, JSON.stringify(value, null, 2));
2980
3010
  }
@@ -3209,6 +3239,38 @@ var responseContentPartDoneChunkSchema = import_zod11.z.object({
3209
3239
  content_index: import_zod11.z.number(),
3210
3240
  part: import_zod11.z.any()
3211
3241
  });
3242
+ var responseFileSearchCallInProgressChunkSchema = import_zod11.z.object({
3243
+ type: import_zod11.z.literal("response.file_search_call.in_progress"),
3244
+ sequence_number: import_zod11.z.number(),
3245
+ output_index: import_zod11.z.number(),
3246
+ item_id: import_zod11.z.string()
3247
+ });
3248
+ var responseFileSearchCallSearchingChunkSchema = import_zod11.z.object({
3249
+ type: import_zod11.z.literal("response.file_search_call.searching"),
3250
+ sequence_number: import_zod11.z.number(),
3251
+ output_index: import_zod11.z.number(),
3252
+ item_id: import_zod11.z.string()
3253
+ });
3254
+ var responseFileSearchCallCompletedChunkSchema = import_zod11.z.object({
3255
+ type: import_zod11.z.literal("response.file_search_call.completed"),
3256
+ sequence_number: import_zod11.z.number(),
3257
+ output_index: import_zod11.z.number(),
3258
+ item_id: import_zod11.z.string()
3259
+ });
3260
+ var responseFileSearchCallQueryAddedChunkSchema = import_zod11.z.object({
3261
+ type: import_zod11.z.literal("response.file_search_call.query.added"),
3262
+ sequence_number: import_zod11.z.number(),
3263
+ output_index: import_zod11.z.number(),
3264
+ item_id: import_zod11.z.string(),
3265
+ query: import_zod11.z.string()
3266
+ });
3267
+ var responseFileSearchCallResultAddedChunkSchema = import_zod11.z.object({
3268
+ type: import_zod11.z.literal("response.file_search_call.result.added"),
3269
+ sequence_number: import_zod11.z.number(),
3270
+ output_index: import_zod11.z.number(),
3271
+ item_id: import_zod11.z.string(),
3272
+ result: import_zod11.z.any()
3273
+ });
3212
3274
  var openaiResponsesChunkSchema = import_zod11.z.union([
3213
3275
  textDeltaChunkSchema,
3214
3276
  responseFinishedChunkSchema,
@@ -3222,6 +3284,11 @@ var openaiResponsesChunkSchema = import_zod11.z.union([
3222
3284
  responseContentPartAddedChunkSchema,
3223
3285
  responseOutputTextDoneChunkSchema,
3224
3286
  responseContentPartDoneChunkSchema,
3287
+ responseFileSearchCallInProgressChunkSchema,
3288
+ responseFileSearchCallSearchingChunkSchema,
3289
+ responseFileSearchCallCompletedChunkSchema,
3290
+ responseFileSearchCallQueryAddedChunkSchema,
3291
+ responseFileSearchCallResultAddedChunkSchema,
3225
3292
  import_zod11.z.object({ type: import_zod11.z.string() }).passthrough()
3226
3293
  // fallback for unknown chunks
3227
3294
  ]);
@@ -3261,6 +3328,21 @@ function isResponseOutputTextDoneChunk(chunk) {
3261
3328
  function isResponseContentPartDoneChunk(chunk) {
3262
3329
  return chunk.type === "response.content_part.done";
3263
3330
  }
3331
+ function isResponseFileSearchCallInProgressChunk(chunk) {
3332
+ return chunk.type === "response.file_search_call.in_progress";
3333
+ }
3334
+ function isResponseFileSearchCallSearchingChunk(chunk) {
3335
+ return chunk.type === "response.file_search_call.searching";
3336
+ }
3337
+ function isResponseFileSearchCallCompletedChunk(chunk) {
3338
+ return chunk.type === "response.file_search_call.completed";
3339
+ }
3340
+ function isResponseFileSearchCallQueryAddedChunk(chunk) {
3341
+ return chunk.type === "response.file_search_call.query.added";
3342
+ }
3343
+ function isResponseFileSearchCallResultAddedChunk(chunk) {
3344
+ return chunk.type === "response.file_search_call.result.added";
3345
+ }
3264
3346
  function getResponsesModelConfig(modelId) {
3265
3347
  if (modelId.startsWith("o")) {
3266
3348
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {