@zenning/openai 2.2.0 → 2.3.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.
package/dist/index.mjs CHANGED
@@ -2462,6 +2462,11 @@ var localShellCallItem = z16.object({
2462
2462
  env: z16.record(z16.string(), z16.string()).optional()
2463
2463
  })
2464
2464
  });
2465
+ var sourceExecutionFileCodeInterpreterItem = z16.object({
2466
+ containerId: z16.string(),
2467
+ fileId: z16.string(),
2468
+ filename: z16.string()
2469
+ });
2465
2470
  var imageGenerationCallItem = z16.object({
2466
2471
  type: z16.literal("image_generation_call"),
2467
2472
  id: z16.string(),
@@ -2687,7 +2692,7 @@ var OpenAIResponsesLanguageModel = class {
2687
2692
  };
2688
2693
  }
2689
2694
  async doGenerate(options) {
2690
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2695
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
2691
2696
  const {
2692
2697
  args: body,
2693
2698
  warnings,
@@ -2697,6 +2702,7 @@ var OpenAIResponsesLanguageModel = class {
2697
2702
  path: "/responses",
2698
2703
  modelId: this.modelId
2699
2704
  });
2705
+ const providerKey = this.config.provider.replace(".responses", "");
2700
2706
  const {
2701
2707
  responseHeaders,
2702
2708
  value: response,
@@ -2745,7 +2751,12 @@ var OpenAIResponsesLanguageModel = class {
2745
2751
  quote: z16.string().nullish()
2746
2752
  }),
2747
2753
  z16.object({
2748
- type: z16.literal("container_file_citation")
2754
+ type: z16.literal("container_file_citation"),
2755
+ container_id: z16.string(),
2756
+ end_index: z16.number(),
2757
+ file_id: z16.string(),
2758
+ filename: z16.string(),
2759
+ start_index: z16.number()
2749
2760
  })
2750
2761
  ])
2751
2762
  )
@@ -2867,7 +2878,8 @@ var OpenAIResponsesLanguageModel = class {
2867
2878
  text: contentPart.text,
2868
2879
  providerMetadata: {
2869
2880
  openai: {
2870
- itemId: part.id
2881
+ itemId: part.id,
2882
+ annotations: contentPart.annotations
2871
2883
  }
2872
2884
  }
2873
2885
  });
@@ -2892,6 +2904,19 @@ var OpenAIResponsesLanguageModel = class {
2892
2904
  startIndex: (_m = annotation.start_index) != null ? _m : void 0,
2893
2905
  endIndex: (_n = annotation.end_index) != null ? _n : void 0
2894
2906
  });
2907
+ } else if (annotation.type === "container_file_citation") {
2908
+ content.push({
2909
+ type: "source",
2910
+ sourceType: "executionFile",
2911
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
2912
+ providerMetadata: {
2913
+ [providerKey]: {
2914
+ containerId: annotation.container_id,
2915
+ fileId: annotation.file_id,
2916
+ filename: annotation.filename
2917
+ }
2918
+ }
2919
+ });
2895
2920
  }
2896
2921
  }
2897
2922
  }
@@ -2963,13 +2988,13 @@ var OpenAIResponsesLanguageModel = class {
2963
2988
  toolName: "file_search",
2964
2989
  result: {
2965
2990
  queries: part.queries,
2966
- results: (_p = (_o = part.results) == null ? void 0 : _o.map((result) => ({
2991
+ results: (_s = (_r = part.results) == null ? void 0 : _r.map((result) => ({
2967
2992
  attributes: result.attributes,
2968
2993
  fileId: result.file_id,
2969
2994
  filename: result.filename,
2970
2995
  score: result.score,
2971
2996
  text: result.text
2972
- }))) != null ? _p : null
2997
+ }))) != null ? _s : null
2973
2998
  },
2974
2999
  providerExecuted: true
2975
3000
  });
@@ -3011,15 +3036,15 @@ var OpenAIResponsesLanguageModel = class {
3011
3036
  return {
3012
3037
  content,
3013
3038
  finishReason: mapOpenAIResponseFinishReason({
3014
- finishReason: (_q = response.incomplete_details) == null ? void 0 : _q.reason,
3039
+ finishReason: (_t = response.incomplete_details) == null ? void 0 : _t.reason,
3015
3040
  hasFunctionCall
3016
3041
  }),
3017
3042
  usage: {
3018
3043
  inputTokens: response.usage.input_tokens,
3019
3044
  outputTokens: response.usage.output_tokens,
3020
3045
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
3021
- reasoningTokens: (_s = (_r = response.usage.output_tokens_details) == null ? void 0 : _r.reasoning_tokens) != null ? _s : void 0,
3022
- cachedInputTokens: (_u = (_t = response.usage.input_tokens_details) == null ? void 0 : _t.cached_tokens) != null ? _u : void 0
3046
+ reasoningTokens: (_v = (_u = response.usage.output_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : void 0,
3047
+ cachedInputTokens: (_x = (_w = response.usage.input_tokens_details) == null ? void 0 : _w.cached_tokens) != null ? _x : void 0
3023
3048
  },
3024
3049
  request: { body },
3025
3050
  response: {
@@ -3066,6 +3091,7 @@ var OpenAIResponsesLanguageModel = class {
3066
3091
  const logprobs = [];
3067
3092
  let responseId = null;
3068
3093
  const ongoingToolCalls = {};
3094
+ const ongoingAnnotations = [];
3069
3095
  let hasFunctionCall = false;
3070
3096
  const activeReasoning = {};
3071
3097
  let serviceTier;
@@ -3076,7 +3102,7 @@ var OpenAIResponsesLanguageModel = class {
3076
3102
  controller.enqueue({ type: "stream-start", warnings });
3077
3103
  },
3078
3104
  transform(chunk, controller) {
3079
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
3105
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
3080
3106
  if (options.includeRawChunks) {
3081
3107
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3082
3108
  }
@@ -3152,6 +3178,7 @@ var OpenAIResponsesLanguageModel = class {
3152
3178
  providerExecuted: true
3153
3179
  });
3154
3180
  } else if (value.item.type === "message") {
3181
+ ongoingAnnotations.splice(0, ongoingAnnotations.length);
3155
3182
  controller.enqueue({
3156
3183
  type: "text-start",
3157
3184
  id: value.item.id,
@@ -3177,7 +3204,7 @@ var OpenAIResponsesLanguageModel = class {
3177
3204
  }
3178
3205
  });
3179
3206
  }
3180
- } else if (isResponseOutputItemDoneChunk(value)) {
3207
+ } else if (isResponseOutputItemDoneChunk(value) && value.item.type !== "message") {
3181
3208
  if (value.item.type === "function_call") {
3182
3209
  ongoingToolCalls[value.output_index] = void 0;
3183
3210
  hasFunctionCall = true;
@@ -3298,11 +3325,6 @@ var OpenAIResponsesLanguageModel = class {
3298
3325
  openai: { itemId: value.item.id }
3299
3326
  }
3300
3327
  });
3301
- } else if (value.item.type === "message") {
3302
- controller.enqueue({
3303
- type: "text-end",
3304
- id: value.item.id
3305
- });
3306
3328
  } else if (isResponseOutputItemDoneReasoningChunk(value)) {
3307
3329
  const activeReasoningPart = activeReasoning[value.item.id];
3308
3330
  for (const summaryIndex of activeReasoningPart.summaryParts) {
@@ -3431,6 +3453,7 @@ var OpenAIResponsesLanguageModel = class {
3431
3453
  serviceTier = value.response.service_tier;
3432
3454
  }
3433
3455
  } else if (isResponseAnnotationAddedChunk(value)) {
3456
+ ongoingAnnotations.push(value.annotation);
3434
3457
  if (value.annotation.type === "url_citation") {
3435
3458
  controller.enqueue({
3436
3459
  type: "source",
@@ -3451,7 +3474,31 @@ var OpenAIResponsesLanguageModel = class {
3451
3474
  startIndex: (_x = value.annotation.start_index) != null ? _x : void 0,
3452
3475
  endIndex: (_y = value.annotation.end_index) != null ? _y : void 0
3453
3476
  });
3477
+ } else if (value.annotation.type === "container_file_citation") {
3478
+ controller.enqueue({
3479
+ type: "source",
3480
+ sourceType: "executionFile",
3481
+ id: (_B = (_A = (_z = self.config).generateId) == null ? void 0 : _A.call(_z)) != null ? _B : generateId2(),
3482
+ providerMetadata: {
3483
+ openai: {
3484
+ containerId: value.annotation.container_id,
3485
+ fileId: value.annotation.file_id,
3486
+ filename: value.annotation.filename
3487
+ }
3488
+ }
3489
+ });
3454
3490
  }
3491
+ } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "message") {
3492
+ controller.enqueue({
3493
+ type: "text-end",
3494
+ id: value.item.id,
3495
+ providerMetadata: {
3496
+ openai: {
3497
+ itemId: value.item.id,
3498
+ annotations: ongoingAnnotations
3499
+ }
3500
+ }
3501
+ });
3455
3502
  } else if (isErrorChunk(value)) {
3456
3503
  controller.enqueue({ type: "error", error: value });
3457
3504
  }
@@ -3648,6 +3695,14 @@ var responseAnnotationAddedSchema = z16.object({
3648
3695
  start_index: z16.number().nullish(),
3649
3696
  end_index: z16.number().nullish(),
3650
3697
  quote: z16.string().nullish()
3698
+ }),
3699
+ z16.object({
3700
+ type: z16.literal("container_file_citation"),
3701
+ container_id: z16.string(),
3702
+ end_index: z16.number(),
3703
+ file_id: z16.string(),
3704
+ filename: z16.string(),
3705
+ start_index: z16.number()
3651
3706
  })
3652
3707
  ])
3653
3708
  });
@@ -3799,6 +3854,15 @@ var openaiResponsesProviderOptionsSchema = z16.object({
3799
3854
  textVerbosity: z16.enum(["low", "medium", "high"]).nullish(),
3800
3855
  user: z16.string().nullish()
3801
3856
  });
3857
+ var openaiResponsesTextUIPartProviderMetadataSchema = z16.object({
3858
+ openai: z16.object({
3859
+ itemId: z16.string(),
3860
+ annotations: z16.array(responseAnnotationAddedSchema.shape.annotation)
3861
+ })
3862
+ });
3863
+ var openaiSourceExecutionFileProviderMetadataSchema = z16.object({
3864
+ openai: sourceExecutionFileCodeInterpreterItem
3865
+ });
3802
3866
 
3803
3867
  // src/speech/openai-speech-model.ts
3804
3868
  import {
@@ -4144,7 +4208,7 @@ var openaiTranscriptionResponseSchema = z19.object({
4144
4208
  });
4145
4209
 
4146
4210
  // src/version.ts
4147
- var VERSION = true ? "2.2.0" : "0.0.0-test";
4211
+ var VERSION = true ? "2.3.0" : "0.0.0-test";
4148
4212
 
4149
4213
  // src/openai-provider.ts
4150
4214
  function createOpenAI(options = {}) {