@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.
@@ -1859,15 +1859,20 @@ var OpenAIImageModel = class {
1859
1859
  },
1860
1860
  providerMetadata: {
1861
1861
  openai: {
1862
- images: response2.data.map((item) => {
1863
- var _a2, _b2, _c2, _d2, _e2;
1862
+ images: response2.data.map((item, index) => {
1863
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1864
1864
  return {
1865
1865
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1866
1866
  created: (_a2 = response2.created) != null ? _a2 : void 0,
1867
1867
  size: (_b2 = response2.size) != null ? _b2 : void 0,
1868
1868
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1869
1869
  background: (_d2 = response2.background) != null ? _d2 : void 0,
1870
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1870
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
1871
+ ...distributeTokenDetails(
1872
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
1873
+ index,
1874
+ response2.data.length
1875
+ )
1871
1876
  };
1872
1877
  })
1873
1878
  }
@@ -1910,15 +1915,20 @@ var OpenAIImageModel = class {
1910
1915
  },
1911
1916
  providerMetadata: {
1912
1917
  openai: {
1913
- images: response.data.map((item) => {
1914
- var _a2, _b2, _c2, _d2, _e2;
1918
+ images: response.data.map((item, index) => {
1919
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1915
1920
  return {
1916
1921
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1917
1922
  created: (_a2 = response.created) != null ? _a2 : void 0,
1918
1923
  size: (_b2 = response.size) != null ? _b2 : void 0,
1919
1924
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
1920
1925
  background: (_d2 = response.background) != null ? _d2 : void 0,
1921
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
1926
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
1927
+ ...distributeTokenDetails(
1928
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
1929
+ index,
1930
+ response.data.length
1931
+ )
1922
1932
  };
1923
1933
  })
1924
1934
  }
@@ -1926,6 +1936,23 @@ var OpenAIImageModel = class {
1926
1936
  };
1927
1937
  }
1928
1938
  };
1939
+ function distributeTokenDetails(details, index, total) {
1940
+ if (details == null) {
1941
+ return {};
1942
+ }
1943
+ const result = {};
1944
+ if (details.image_tokens != null) {
1945
+ const base = Math.floor(details.image_tokens / total);
1946
+ const remainder = details.image_tokens - base * (total - 1);
1947
+ result.imageTokens = index === total - 1 ? remainder : base;
1948
+ }
1949
+ if (details.text_tokens != null) {
1950
+ const base = Math.floor(details.text_tokens / total);
1951
+ const remainder = details.text_tokens - base * (total - 1);
1952
+ result.textTokens = index === total - 1 ? remainder : base;
1953
+ }
1954
+ return result;
1955
+ }
1929
1956
  async function fileToBlob(file) {
1930
1957
  if (!file) return void 0;
1931
1958
  if (file.type === "url") {
@@ -2474,6 +2501,67 @@ var shellOutputSchema = lazySchema13(
2474
2501
  })
2475
2502
  )
2476
2503
  );
2504
+ var shellSkillsSchema = z14.array(
2505
+ z14.discriminatedUnion("type", [
2506
+ z14.object({
2507
+ type: z14.literal("skillReference"),
2508
+ skillId: z14.string(),
2509
+ version: z14.string().optional()
2510
+ }),
2511
+ z14.object({
2512
+ type: z14.literal("inline"),
2513
+ name: z14.string(),
2514
+ description: z14.string(),
2515
+ source: z14.object({
2516
+ type: z14.literal("base64"),
2517
+ mediaType: z14.literal("application/zip"),
2518
+ data: z14.string()
2519
+ })
2520
+ })
2521
+ ])
2522
+ ).optional();
2523
+ var shellArgsSchema = lazySchema13(
2524
+ () => zodSchema13(
2525
+ z14.object({
2526
+ environment: z14.union([
2527
+ z14.object({
2528
+ type: z14.literal("containerAuto"),
2529
+ fileIds: z14.array(z14.string()).optional(),
2530
+ memoryLimit: z14.enum(["1g", "4g", "16g", "64g"]).optional(),
2531
+ networkPolicy: z14.discriminatedUnion("type", [
2532
+ z14.object({ type: z14.literal("disabled") }),
2533
+ z14.object({
2534
+ type: z14.literal("allowlist"),
2535
+ allowedDomains: z14.array(z14.string()),
2536
+ domainSecrets: z14.array(
2537
+ z14.object({
2538
+ domain: z14.string(),
2539
+ name: z14.string(),
2540
+ value: z14.string()
2541
+ })
2542
+ ).optional()
2543
+ })
2544
+ ]).optional(),
2545
+ skills: shellSkillsSchema
2546
+ }),
2547
+ z14.object({
2548
+ type: z14.literal("containerReference"),
2549
+ containerId: z14.string()
2550
+ }),
2551
+ z14.object({
2552
+ type: z14.literal("local").optional(),
2553
+ skills: z14.array(
2554
+ z14.object({
2555
+ name: z14.string(),
2556
+ description: z14.string(),
2557
+ path: z14.string()
2558
+ })
2559
+ ).optional()
2560
+ })
2561
+ ]).optional()
2562
+ })
2563
+ )
2564
+ );
2477
2565
  var shell = createProviderToolFactoryWithOutputSchema3({
2478
2566
  id: "openai.shell",
2479
2567
  inputSchema: shellInputSchema,
@@ -2680,8 +2768,32 @@ async function convertToOpenAIResponsesInput({
2680
2768
  if (hasConversation) {
2681
2769
  break;
2682
2770
  }
2771
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
2772
+ part.toolName
2773
+ );
2774
+ if (hasShellTool && resolvedResultToolName === "shell") {
2775
+ if (part.output.type === "json") {
2776
+ const parsedOutput = await validateTypes({
2777
+ value: part.output.value,
2778
+ schema: shellOutputSchema
2779
+ });
2780
+ input.push({
2781
+ type: "shell_call_output",
2782
+ call_id: part.toolCallId,
2783
+ output: parsedOutput.output.map((item) => ({
2784
+ stdout: item.stdout,
2785
+ stderr: item.stderr,
2786
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
2787
+ type: "exit",
2788
+ exit_code: item.outcome.exitCode
2789
+ }
2790
+ }))
2791
+ });
2792
+ }
2793
+ break;
2794
+ }
2683
2795
  if (store) {
2684
- const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2796
+ const itemId = (_j = (_i = (_h = part.providerOptions) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2685
2797
  input.push({ type: "item_reference", id: itemId });
2686
2798
  } else {
2687
2799
  warnings.push({
@@ -3056,6 +3168,25 @@ var openaiResponsesChunkSchema = lazySchema14(
3056
3168
  action: z16.object({
3057
3169
  commands: z16.array(z16.string())
3058
3170
  })
3171
+ }),
3172
+ z16.object({
3173
+ type: z16.literal("shell_call_output"),
3174
+ id: z16.string(),
3175
+ call_id: z16.string(),
3176
+ status: z16.enum(["in_progress", "completed", "incomplete"]),
3177
+ output: z16.array(
3178
+ z16.object({
3179
+ stdout: z16.string(),
3180
+ stderr: z16.string(),
3181
+ outcome: z16.discriminatedUnion("type", [
3182
+ z16.object({ type: z16.literal("timeout") }),
3183
+ z16.object({
3184
+ type: z16.literal("exit"),
3185
+ exit_code: z16.number()
3186
+ })
3187
+ ])
3188
+ })
3189
+ )
3059
3190
  })
3060
3191
  ])
3061
3192
  }),
@@ -3235,6 +3366,25 @@ var openaiResponsesChunkSchema = lazySchema14(
3235
3366
  action: z16.object({
3236
3367
  commands: z16.array(z16.string())
3237
3368
  })
3369
+ }),
3370
+ z16.object({
3371
+ type: z16.literal("shell_call_output"),
3372
+ id: z16.string(),
3373
+ call_id: z16.string(),
3374
+ status: z16.enum(["in_progress", "completed", "incomplete"]),
3375
+ output: z16.array(
3376
+ z16.object({
3377
+ stdout: z16.string(),
3378
+ stderr: z16.string(),
3379
+ outcome: z16.discriminatedUnion("type", [
3380
+ z16.object({ type: z16.literal("timeout") }),
3381
+ z16.object({
3382
+ type: z16.literal("exit"),
3383
+ exit_code: z16.number()
3384
+ })
3385
+ ])
3386
+ })
3387
+ )
3238
3388
  })
3239
3389
  ])
3240
3390
  }),
@@ -3580,6 +3730,25 @@ var openaiResponsesResponseSchema = lazySchema14(
3580
3730
  action: z16.object({
3581
3731
  commands: z16.array(z16.string())
3582
3732
  })
3733
+ }),
3734
+ z16.object({
3735
+ type: z16.literal("shell_call_output"),
3736
+ id: z16.string(),
3737
+ call_id: z16.string(),
3738
+ status: z16.enum(["in_progress", "completed", "incomplete"]),
3739
+ output: z16.array(
3740
+ z16.object({
3741
+ stdout: z16.string(),
3742
+ stderr: z16.string(),
3743
+ outcome: z16.discriminatedUnion("type", [
3744
+ z16.object({ type: z16.literal("timeout") }),
3745
+ z16.object({
3746
+ type: z16.literal("exit"),
3747
+ exit_code: z16.number()
3748
+ })
3749
+ ])
3750
+ })
3751
+ )
3583
3752
  })
3584
3753
  ])
3585
3754
  ).optional(),
@@ -4191,8 +4360,15 @@ async function prepareResponsesTools({
4191
4360
  break;
4192
4361
  }
4193
4362
  case "openai.shell": {
4363
+ const args = await validateTypes2({
4364
+ value: tool.args,
4365
+ schema: shellArgsSchema
4366
+ });
4194
4367
  openaiTools.push({
4195
- type: "shell"
4368
+ type: "shell",
4369
+ ...args.environment && {
4370
+ environment: mapShellEnvironment(args.environment)
4371
+ }
4196
4372
  });
4197
4373
  break;
4198
4374
  }
@@ -4322,6 +4498,52 @@ async function prepareResponsesTools({
4322
4498
  }
4323
4499
  }
4324
4500
  }
4501
+ function mapShellEnvironment(environment) {
4502
+ if (environment.type === "containerReference") {
4503
+ const env2 = environment;
4504
+ return {
4505
+ type: "container_reference",
4506
+ container_id: env2.containerId
4507
+ };
4508
+ }
4509
+ if (environment.type === "containerAuto") {
4510
+ const env2 = environment;
4511
+ return {
4512
+ type: "container_auto",
4513
+ file_ids: env2.fileIds,
4514
+ memory_limit: env2.memoryLimit,
4515
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
4516
+ type: "allowlist",
4517
+ allowed_domains: env2.networkPolicy.allowedDomains,
4518
+ domain_secrets: env2.networkPolicy.domainSecrets
4519
+ },
4520
+ skills: mapShellSkills(env2.skills)
4521
+ };
4522
+ }
4523
+ const env = environment;
4524
+ return {
4525
+ type: "local",
4526
+ skills: env.skills
4527
+ };
4528
+ }
4529
+ function mapShellSkills(skills) {
4530
+ return skills == null ? void 0 : skills.map(
4531
+ (skill) => skill.type === "skillReference" ? {
4532
+ type: "skill_reference",
4533
+ skill_id: skill.skillId,
4534
+ version: skill.version
4535
+ } : {
4536
+ type: "inline",
4537
+ name: skill.name,
4538
+ description: skill.description,
4539
+ source: {
4540
+ type: "base64",
4541
+ media_type: skill.source.mediaType,
4542
+ data: skill.source.data
4543
+ }
4544
+ }
4545
+ );
4546
+ }
4325
4547
 
4326
4548
  // src/responses/openai-responses-language-model.ts
4327
4549
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
@@ -4367,7 +4589,7 @@ var OpenAIResponsesLanguageModel = class {
4367
4589
  toolChoice,
4368
4590
  responseFormat
4369
4591
  }) {
4370
- var _a, _b, _c, _d, _e, _f;
4592
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4371
4593
  const warnings = [];
4372
4594
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4373
4595
  if (topK != null) {
@@ -4571,6 +4793,10 @@ var OpenAIResponsesLanguageModel = class {
4571
4793
  tools,
4572
4794
  toolChoice
4573
4795
  });
4796
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
4797
+ (tool) => tool.type === "provider" && tool.id === "openai.shell"
4798
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
4799
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
4574
4800
  return {
4575
4801
  webSearchToolName,
4576
4802
  args: {
@@ -4581,7 +4807,8 @@ var OpenAIResponsesLanguageModel = class {
4581
4807
  warnings: [...warnings, ...toolWarnings],
4582
4808
  store,
4583
4809
  toolNameMapping,
4584
- providerOptionsName
4810
+ providerOptionsName,
4811
+ isShellProviderExecuted
4585
4812
  };
4586
4813
  }
4587
4814
  async doGenerate(options) {
@@ -4591,7 +4818,8 @@ var OpenAIResponsesLanguageModel = class {
4591
4818
  warnings,
4592
4819
  webSearchToolName,
4593
4820
  toolNameMapping,
4594
- providerOptionsName
4821
+ providerOptionsName,
4822
+ isShellProviderExecuted
4595
4823
  } = await this.getArgs(options);
4596
4824
  const url = this.config.url({
4597
4825
  path: "/responses",
@@ -4691,6 +4919,7 @@ var OpenAIResponsesLanguageModel = class {
4691
4919
  commands: part.action.commands
4692
4920
  }
4693
4921
  }),
4922
+ ...isShellProviderExecuted && { providerExecuted: true },
4694
4923
  providerMetadata: {
4695
4924
  [providerOptionsName]: {
4696
4925
  itemId: part.id
@@ -4699,6 +4928,24 @@ var OpenAIResponsesLanguageModel = class {
4699
4928
  });
4700
4929
  break;
4701
4930
  }
4931
+ case "shell_call_output": {
4932
+ content.push({
4933
+ type: "tool-result",
4934
+ toolCallId: part.call_id,
4935
+ toolName: toolNameMapping.toCustomToolName("shell"),
4936
+ result: {
4937
+ output: part.output.map((item) => ({
4938
+ stdout: item.stdout,
4939
+ stderr: item.stderr,
4940
+ outcome: item.outcome.type === "exit" ? {
4941
+ type: "exit",
4942
+ exitCode: item.outcome.exit_code
4943
+ } : { type: "timeout" }
4944
+ }))
4945
+ }
4946
+ });
4947
+ break;
4948
+ }
4702
4949
  case "message": {
4703
4950
  for (const contentPart of part.content) {
4704
4951
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -4988,7 +5235,8 @@ var OpenAIResponsesLanguageModel = class {
4988
5235
  webSearchToolName,
4989
5236
  toolNameMapping,
4990
5237
  store,
4991
- providerOptionsName
5238
+ providerOptionsName,
5239
+ isShellProviderExecuted
4992
5240
  } = await this.getArgs(options);
4993
5241
  const { responseHeaders, value: response } = await postJsonToApi6({
4994
5242
  url: this.config.url({
@@ -5167,6 +5415,7 @@ var OpenAIResponsesLanguageModel = class {
5167
5415
  toolName: toolNameMapping.toCustomToolName("shell"),
5168
5416
  toolCallId: value.item.call_id
5169
5417
  };
5418
+ } else if (value.item.type === "shell_call_output") {
5170
5419
  } else if (value.item.type === "message") {
5171
5420
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
5172
5421
  controller.enqueue({
@@ -5420,10 +5669,31 @@ var OpenAIResponsesLanguageModel = class {
5420
5669
  commands: value.item.action.commands
5421
5670
  }
5422
5671
  }),
5672
+ ...isShellProviderExecuted && {
5673
+ providerExecuted: true
5674
+ },
5423
5675
  providerMetadata: {
5424
5676
  [providerOptionsName]: { itemId: value.item.id }
5425
5677
  }
5426
5678
  });
5679
+ } else if (value.item.type === "shell_call_output") {
5680
+ controller.enqueue({
5681
+ type: "tool-result",
5682
+ toolCallId: value.item.call_id,
5683
+ toolName: toolNameMapping.toCustomToolName("shell"),
5684
+ result: {
5685
+ output: value.item.output.map(
5686
+ (item) => ({
5687
+ stdout: item.stdout,
5688
+ stderr: item.stderr,
5689
+ outcome: item.outcome.type === "exit" ? {
5690
+ type: "exit",
5691
+ exitCode: item.outcome.exit_code
5692
+ } : { type: "timeout" }
5693
+ })
5694
+ )
5695
+ }
5696
+ });
5427
5697
  } else if (value.item.type === "reasoning") {
5428
5698
  const activeReasoningPart = activeReasoning[value.item.id];
5429
5699
  const summaryPartIndices = Object.entries(