@ai-sdk/openai 3.0.28 → 3.0.30

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
@@ -1867,15 +1867,20 @@ var OpenAIImageModel = class {
1867
1867
  },
1868
1868
  providerMetadata: {
1869
1869
  openai: {
1870
- images: response2.data.map((item) => {
1871
- var _a2, _b2, _c2, _d2, _e2;
1870
+ images: response2.data.map((item, index) => {
1871
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1872
1872
  return {
1873
1873
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1874
1874
  created: (_a2 = response2.created) != null ? _a2 : void 0,
1875
1875
  size: (_b2 = response2.size) != null ? _b2 : void 0,
1876
1876
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1877
1877
  background: (_d2 = response2.background) != null ? _d2 : void 0,
1878
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1878
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
1879
+ ...distributeTokenDetails(
1880
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
1881
+ index,
1882
+ response2.data.length
1883
+ )
1879
1884
  };
1880
1885
  })
1881
1886
  }
@@ -1918,15 +1923,20 @@ var OpenAIImageModel = class {
1918
1923
  },
1919
1924
  providerMetadata: {
1920
1925
  openai: {
1921
- images: response.data.map((item) => {
1922
- var _a2, _b2, _c2, _d2, _e2;
1926
+ images: response.data.map((item, index) => {
1927
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1923
1928
  return {
1924
1929
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1925
1930
  created: (_a2 = response.created) != null ? _a2 : void 0,
1926
1931
  size: (_b2 = response.size) != null ? _b2 : void 0,
1927
1932
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
1928
1933
  background: (_d2 = response.background) != null ? _d2 : void 0,
1929
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
1934
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
1935
+ ...distributeTokenDetails(
1936
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
1937
+ index,
1938
+ response.data.length
1939
+ )
1930
1940
  };
1931
1941
  })
1932
1942
  }
@@ -1934,6 +1944,23 @@ var OpenAIImageModel = class {
1934
1944
  };
1935
1945
  }
1936
1946
  };
1947
+ function distributeTokenDetails(details, index, total) {
1948
+ if (details == null) {
1949
+ return {};
1950
+ }
1951
+ const result = {};
1952
+ if (details.image_tokens != null) {
1953
+ const base = Math.floor(details.image_tokens / total);
1954
+ const remainder = details.image_tokens - base * (total - 1);
1955
+ result.imageTokens = index === total - 1 ? remainder : base;
1956
+ }
1957
+ if (details.text_tokens != null) {
1958
+ const base = Math.floor(details.text_tokens / total);
1959
+ const remainder = details.text_tokens - base * (total - 1);
1960
+ result.textTokens = index === total - 1 ? remainder : base;
1961
+ }
1962
+ return result;
1963
+ }
1937
1964
  async function fileToBlob(file) {
1938
1965
  if (!file) return void 0;
1939
1966
  if (file.type === "url") {
@@ -2193,6 +2220,67 @@ var shellOutputSchema = lazySchema13(
2193
2220
  })
2194
2221
  )
2195
2222
  );
2223
+ var shellSkillsSchema = z14.array(
2224
+ z14.discriminatedUnion("type", [
2225
+ z14.object({
2226
+ type: z14.literal("skillReference"),
2227
+ skillId: z14.string(),
2228
+ version: z14.string().optional()
2229
+ }),
2230
+ z14.object({
2231
+ type: z14.literal("inline"),
2232
+ name: z14.string(),
2233
+ description: z14.string(),
2234
+ source: z14.object({
2235
+ type: z14.literal("base64"),
2236
+ mediaType: z14.literal("application/zip"),
2237
+ data: z14.string()
2238
+ })
2239
+ })
2240
+ ])
2241
+ ).optional();
2242
+ var shellArgsSchema = lazySchema13(
2243
+ () => zodSchema13(
2244
+ z14.object({
2245
+ environment: z14.union([
2246
+ z14.object({
2247
+ type: z14.literal("containerAuto"),
2248
+ fileIds: z14.array(z14.string()).optional(),
2249
+ memoryLimit: z14.enum(["1g", "4g", "16g", "64g"]).optional(),
2250
+ networkPolicy: z14.discriminatedUnion("type", [
2251
+ z14.object({ type: z14.literal("disabled") }),
2252
+ z14.object({
2253
+ type: z14.literal("allowlist"),
2254
+ allowedDomains: z14.array(z14.string()),
2255
+ domainSecrets: z14.array(
2256
+ z14.object({
2257
+ domain: z14.string(),
2258
+ name: z14.string(),
2259
+ value: z14.string()
2260
+ })
2261
+ ).optional()
2262
+ })
2263
+ ]).optional(),
2264
+ skills: shellSkillsSchema
2265
+ }),
2266
+ z14.object({
2267
+ type: z14.literal("containerReference"),
2268
+ containerId: z14.string()
2269
+ }),
2270
+ z14.object({
2271
+ type: z14.literal("local").optional(),
2272
+ skills: z14.array(
2273
+ z14.object({
2274
+ name: z14.string(),
2275
+ description: z14.string(),
2276
+ path: z14.string()
2277
+ })
2278
+ ).optional()
2279
+ })
2280
+ ]).optional()
2281
+ })
2282
+ )
2283
+ );
2196
2284
  var shell = createProviderToolFactoryWithOutputSchema6({
2197
2285
  id: "openai.shell",
2198
2286
  inputSchema: shellInputSchema,
@@ -2736,8 +2824,32 @@ async function convertToOpenAIResponsesInput({
2736
2824
  if (hasConversation) {
2737
2825
  break;
2738
2826
  }
2827
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
2828
+ part.toolName
2829
+ );
2830
+ if (hasShellTool && resolvedResultToolName === "shell") {
2831
+ if (part.output.type === "json") {
2832
+ const parsedOutput = await validateTypes({
2833
+ value: part.output.value,
2834
+ schema: shellOutputSchema
2835
+ });
2836
+ input.push({
2837
+ type: "shell_call_output",
2838
+ call_id: part.toolCallId,
2839
+ output: parsedOutput.output.map((item) => ({
2840
+ stdout: item.stdout,
2841
+ stderr: item.stderr,
2842
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
2843
+ type: "exit",
2844
+ exit_code: item.outcome.exitCode
2845
+ }
2846
+ }))
2847
+ });
2848
+ }
2849
+ break;
2850
+ }
2739
2851
  if (store) {
2740
- const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2852
+ const itemId = (_j = (_i = (_h = part.providerOptions) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2741
2853
  input.push({ type: "item_reference", id: itemId });
2742
2854
  } else {
2743
2855
  warnings.push({
@@ -3112,6 +3224,25 @@ var openaiResponsesChunkSchema = lazySchema17(
3112
3224
  action: z19.object({
3113
3225
  commands: z19.array(z19.string())
3114
3226
  })
3227
+ }),
3228
+ z19.object({
3229
+ type: z19.literal("shell_call_output"),
3230
+ id: z19.string(),
3231
+ call_id: z19.string(),
3232
+ status: z19.enum(["in_progress", "completed", "incomplete"]),
3233
+ output: z19.array(
3234
+ z19.object({
3235
+ stdout: z19.string(),
3236
+ stderr: z19.string(),
3237
+ outcome: z19.discriminatedUnion("type", [
3238
+ z19.object({ type: z19.literal("timeout") }),
3239
+ z19.object({
3240
+ type: z19.literal("exit"),
3241
+ exit_code: z19.number()
3242
+ })
3243
+ ])
3244
+ })
3245
+ )
3115
3246
  })
3116
3247
  ])
3117
3248
  }),
@@ -3291,6 +3422,25 @@ var openaiResponsesChunkSchema = lazySchema17(
3291
3422
  action: z19.object({
3292
3423
  commands: z19.array(z19.string())
3293
3424
  })
3425
+ }),
3426
+ z19.object({
3427
+ type: z19.literal("shell_call_output"),
3428
+ id: z19.string(),
3429
+ call_id: z19.string(),
3430
+ status: z19.enum(["in_progress", "completed", "incomplete"]),
3431
+ output: z19.array(
3432
+ z19.object({
3433
+ stdout: z19.string(),
3434
+ stderr: z19.string(),
3435
+ outcome: z19.discriminatedUnion("type", [
3436
+ z19.object({ type: z19.literal("timeout") }),
3437
+ z19.object({
3438
+ type: z19.literal("exit"),
3439
+ exit_code: z19.number()
3440
+ })
3441
+ ])
3442
+ })
3443
+ )
3294
3444
  })
3295
3445
  ])
3296
3446
  }),
@@ -3636,6 +3786,25 @@ var openaiResponsesResponseSchema = lazySchema17(
3636
3786
  action: z19.object({
3637
3787
  commands: z19.array(z19.string())
3638
3788
  })
3789
+ }),
3790
+ z19.object({
3791
+ type: z19.literal("shell_call_output"),
3792
+ id: z19.string(),
3793
+ call_id: z19.string(),
3794
+ status: z19.enum(["in_progress", "completed", "incomplete"]),
3795
+ output: z19.array(
3796
+ z19.object({
3797
+ stdout: z19.string(),
3798
+ stderr: z19.string(),
3799
+ outcome: z19.discriminatedUnion("type", [
3800
+ z19.object({ type: z19.literal("timeout") }),
3801
+ z19.object({
3802
+ type: z19.literal("exit"),
3803
+ exit_code: z19.number()
3804
+ })
3805
+ ])
3806
+ })
3807
+ )
3639
3808
  })
3640
3809
  ])
3641
3810
  ).optional(),
@@ -3931,8 +4100,15 @@ async function prepareResponsesTools({
3931
4100
  break;
3932
4101
  }
3933
4102
  case "openai.shell": {
4103
+ const args = await validateTypes2({
4104
+ value: tool.args,
4105
+ schema: shellArgsSchema
4106
+ });
3934
4107
  openaiTools2.push({
3935
- type: "shell"
4108
+ type: "shell",
4109
+ ...args.environment && {
4110
+ environment: mapShellEnvironment(args.environment)
4111
+ }
3936
4112
  });
3937
4113
  break;
3938
4114
  }
@@ -4062,6 +4238,52 @@ async function prepareResponsesTools({
4062
4238
  }
4063
4239
  }
4064
4240
  }
4241
+ function mapShellEnvironment(environment) {
4242
+ if (environment.type === "containerReference") {
4243
+ const env2 = environment;
4244
+ return {
4245
+ type: "container_reference",
4246
+ container_id: env2.containerId
4247
+ };
4248
+ }
4249
+ if (environment.type === "containerAuto") {
4250
+ const env2 = environment;
4251
+ return {
4252
+ type: "container_auto",
4253
+ file_ids: env2.fileIds,
4254
+ memory_limit: env2.memoryLimit,
4255
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
4256
+ type: "allowlist",
4257
+ allowed_domains: env2.networkPolicy.allowedDomains,
4258
+ domain_secrets: env2.networkPolicy.domainSecrets
4259
+ },
4260
+ skills: mapShellSkills(env2.skills)
4261
+ };
4262
+ }
4263
+ const env = environment;
4264
+ return {
4265
+ type: "local",
4266
+ skills: env.skills
4267
+ };
4268
+ }
4269
+ function mapShellSkills(skills) {
4270
+ return skills == null ? void 0 : skills.map(
4271
+ (skill) => skill.type === "skillReference" ? {
4272
+ type: "skill_reference",
4273
+ skill_id: skill.skillId,
4274
+ version: skill.version
4275
+ } : {
4276
+ type: "inline",
4277
+ name: skill.name,
4278
+ description: skill.description,
4279
+ source: {
4280
+ type: "base64",
4281
+ media_type: skill.source.mediaType,
4282
+ data: skill.source.data
4283
+ }
4284
+ }
4285
+ );
4286
+ }
4065
4287
 
4066
4288
  // src/responses/openai-responses-language-model.ts
4067
4289
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
@@ -4107,7 +4329,7 @@ var OpenAIResponsesLanguageModel = class {
4107
4329
  toolChoice,
4108
4330
  responseFormat
4109
4331
  }) {
4110
- var _a, _b, _c, _d, _e, _f;
4332
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4111
4333
  const warnings = [];
4112
4334
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4113
4335
  if (topK != null) {
@@ -4311,6 +4533,10 @@ var OpenAIResponsesLanguageModel = class {
4311
4533
  tools,
4312
4534
  toolChoice
4313
4535
  });
4536
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
4537
+ (tool) => tool.type === "provider" && tool.id === "openai.shell"
4538
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
4539
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
4314
4540
  return {
4315
4541
  webSearchToolName,
4316
4542
  args: {
@@ -4321,7 +4547,8 @@ var OpenAIResponsesLanguageModel = class {
4321
4547
  warnings: [...warnings, ...toolWarnings],
4322
4548
  store,
4323
4549
  toolNameMapping,
4324
- providerOptionsName
4550
+ providerOptionsName,
4551
+ isShellProviderExecuted
4325
4552
  };
4326
4553
  }
4327
4554
  async doGenerate(options) {
@@ -4331,7 +4558,8 @@ var OpenAIResponsesLanguageModel = class {
4331
4558
  warnings,
4332
4559
  webSearchToolName,
4333
4560
  toolNameMapping,
4334
- providerOptionsName
4561
+ providerOptionsName,
4562
+ isShellProviderExecuted
4335
4563
  } = await this.getArgs(options);
4336
4564
  const url = this.config.url({
4337
4565
  path: "/responses",
@@ -4431,6 +4659,7 @@ var OpenAIResponsesLanguageModel = class {
4431
4659
  commands: part.action.commands
4432
4660
  }
4433
4661
  }),
4662
+ ...isShellProviderExecuted && { providerExecuted: true },
4434
4663
  providerMetadata: {
4435
4664
  [providerOptionsName]: {
4436
4665
  itemId: part.id
@@ -4439,6 +4668,24 @@ var OpenAIResponsesLanguageModel = class {
4439
4668
  });
4440
4669
  break;
4441
4670
  }
4671
+ case "shell_call_output": {
4672
+ content.push({
4673
+ type: "tool-result",
4674
+ toolCallId: part.call_id,
4675
+ toolName: toolNameMapping.toCustomToolName("shell"),
4676
+ result: {
4677
+ output: part.output.map((item) => ({
4678
+ stdout: item.stdout,
4679
+ stderr: item.stderr,
4680
+ outcome: item.outcome.type === "exit" ? {
4681
+ type: "exit",
4682
+ exitCode: item.outcome.exit_code
4683
+ } : { type: "timeout" }
4684
+ }))
4685
+ }
4686
+ });
4687
+ break;
4688
+ }
4442
4689
  case "message": {
4443
4690
  for (const contentPart of part.content) {
4444
4691
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -4728,7 +4975,8 @@ var OpenAIResponsesLanguageModel = class {
4728
4975
  webSearchToolName,
4729
4976
  toolNameMapping,
4730
4977
  store,
4731
- providerOptionsName
4978
+ providerOptionsName,
4979
+ isShellProviderExecuted
4732
4980
  } = await this.getArgs(options);
4733
4981
  const { responseHeaders, value: response } = await postJsonToApi5({
4734
4982
  url: this.config.url({
@@ -4907,6 +5155,7 @@ var OpenAIResponsesLanguageModel = class {
4907
5155
  toolName: toolNameMapping.toCustomToolName("shell"),
4908
5156
  toolCallId: value.item.call_id
4909
5157
  };
5158
+ } else if (value.item.type === "shell_call_output") {
4910
5159
  } else if (value.item.type === "message") {
4911
5160
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
4912
5161
  controller.enqueue({
@@ -5160,10 +5409,31 @@ var OpenAIResponsesLanguageModel = class {
5160
5409
  commands: value.item.action.commands
5161
5410
  }
5162
5411
  }),
5412
+ ...isShellProviderExecuted && {
5413
+ providerExecuted: true
5414
+ },
5163
5415
  providerMetadata: {
5164
5416
  [providerOptionsName]: { itemId: value.item.id }
5165
5417
  }
5166
5418
  });
5419
+ } else if (value.item.type === "shell_call_output") {
5420
+ controller.enqueue({
5421
+ type: "tool-result",
5422
+ toolCallId: value.item.call_id,
5423
+ toolName: toolNameMapping.toCustomToolName("shell"),
5424
+ result: {
5425
+ output: value.item.output.map(
5426
+ (item) => ({
5427
+ stdout: item.stdout,
5428
+ stderr: item.stderr,
5429
+ outcome: item.outcome.type === "exit" ? {
5430
+ type: "exit",
5431
+ exitCode: item.outcome.exit_code
5432
+ } : { type: "timeout" }
5433
+ })
5434
+ )
5435
+ }
5436
+ });
5167
5437
  } else if (value.item.type === "reasoning") {
5168
5438
  const activeReasoningPart = activeReasoning[value.item.id];
5169
5439
  const summaryPartIndices = Object.entries(
@@ -5868,7 +6138,7 @@ var OpenAITranscriptionModel = class {
5868
6138
  };
5869
6139
 
5870
6140
  // src/version.ts
5871
- var VERSION = true ? "3.0.28" : "0.0.0-test";
6141
+ var VERSION = true ? "3.0.30" : "0.0.0-test";
5872
6142
 
5873
6143
  // src/openai-provider.ts
5874
6144
  function createOpenAI(options = {}) {