@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.
@@ -352,6 +352,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
352
352
  action: {
353
353
  commands: string[];
354
354
  };
355
+ } | {
356
+ type: "shell_call_output";
357
+ id: string;
358
+ call_id: string;
359
+ status: "completed" | "in_progress" | "incomplete";
360
+ output: {
361
+ stdout: string;
362
+ stderr: string;
363
+ outcome: {
364
+ type: "timeout";
365
+ } | {
366
+ type: "exit";
367
+ exit_code: number;
368
+ };
369
+ }[];
355
370
  };
356
371
  } | {
357
372
  type: "response.output_item.done";
@@ -498,6 +513,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
498
513
  action: {
499
514
  commands: string[];
500
515
  };
516
+ } | {
517
+ type: "shell_call_output";
518
+ id: string;
519
+ call_id: string;
520
+ status: "completed" | "in_progress" | "incomplete";
521
+ output: {
522
+ stdout: string;
523
+ stderr: string;
524
+ outcome: {
525
+ type: "timeout";
526
+ } | {
527
+ type: "exit";
528
+ exit_code: number;
529
+ };
530
+ }[];
501
531
  };
502
532
  } | {
503
533
  type: "response.function_call_arguments.delta";
@@ -352,6 +352,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
352
352
  action: {
353
353
  commands: string[];
354
354
  };
355
+ } | {
356
+ type: "shell_call_output";
357
+ id: string;
358
+ call_id: string;
359
+ status: "completed" | "in_progress" | "incomplete";
360
+ output: {
361
+ stdout: string;
362
+ stderr: string;
363
+ outcome: {
364
+ type: "timeout";
365
+ } | {
366
+ type: "exit";
367
+ exit_code: number;
368
+ };
369
+ }[];
355
370
  };
356
371
  } | {
357
372
  type: "response.output_item.done";
@@ -498,6 +513,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
498
513
  action: {
499
514
  commands: string[];
500
515
  };
516
+ } | {
517
+ type: "shell_call_output";
518
+ id: string;
519
+ call_id: string;
520
+ status: "completed" | "in_progress" | "incomplete";
521
+ output: {
522
+ stdout: string;
523
+ stderr: string;
524
+ outcome: {
525
+ type: "timeout";
526
+ } | {
527
+ type: "exit";
528
+ exit_code: number;
529
+ };
530
+ }[];
501
531
  };
502
532
  } | {
503
533
  type: "response.function_call_arguments.delta";
@@ -1879,15 +1879,20 @@ var OpenAIImageModel = class {
1879
1879
  },
1880
1880
  providerMetadata: {
1881
1881
  openai: {
1882
- images: response2.data.map((item) => {
1883
- var _a2, _b2, _c2, _d2, _e2;
1882
+ images: response2.data.map((item, index) => {
1883
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1884
1884
  return {
1885
1885
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1886
1886
  created: (_a2 = response2.created) != null ? _a2 : void 0,
1887
1887
  size: (_b2 = response2.size) != null ? _b2 : void 0,
1888
1888
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1889
1889
  background: (_d2 = response2.background) != null ? _d2 : void 0,
1890
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1890
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
1891
+ ...distributeTokenDetails(
1892
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
1893
+ index,
1894
+ response2.data.length
1895
+ )
1891
1896
  };
1892
1897
  })
1893
1898
  }
@@ -1930,15 +1935,20 @@ var OpenAIImageModel = class {
1930
1935
  },
1931
1936
  providerMetadata: {
1932
1937
  openai: {
1933
- images: response.data.map((item) => {
1934
- var _a2, _b2, _c2, _d2, _e2;
1938
+ images: response.data.map((item, index) => {
1939
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1935
1940
  return {
1936
1941
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1937
1942
  created: (_a2 = response.created) != null ? _a2 : void 0,
1938
1943
  size: (_b2 = response.size) != null ? _b2 : void 0,
1939
1944
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
1940
1945
  background: (_d2 = response.background) != null ? _d2 : void 0,
1941
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
1946
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
1947
+ ...distributeTokenDetails(
1948
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
1949
+ index,
1950
+ response.data.length
1951
+ )
1942
1952
  };
1943
1953
  })
1944
1954
  }
@@ -1946,6 +1956,23 @@ var OpenAIImageModel = class {
1946
1956
  };
1947
1957
  }
1948
1958
  };
1959
+ function distributeTokenDetails(details, index, total) {
1960
+ if (details == null) {
1961
+ return {};
1962
+ }
1963
+ const result = {};
1964
+ if (details.image_tokens != null) {
1965
+ const base = Math.floor(details.image_tokens / total);
1966
+ const remainder = details.image_tokens - base * (total - 1);
1967
+ result.imageTokens = index === total - 1 ? remainder : base;
1968
+ }
1969
+ if (details.text_tokens != null) {
1970
+ const base = Math.floor(details.text_tokens / total);
1971
+ const remainder = details.text_tokens - base * (total - 1);
1972
+ result.textTokens = index === total - 1 ? remainder : base;
1973
+ }
1974
+ return result;
1975
+ }
1949
1976
  async function fileToBlob(file) {
1950
1977
  if (!file) return void 0;
1951
1978
  if (file.type === "url") {
@@ -2453,6 +2480,67 @@ var shellOutputSchema = (0, import_provider_utils21.lazySchema)(
2453
2480
  })
2454
2481
  )
2455
2482
  );
2483
+ var shellSkillsSchema = import_v414.z.array(
2484
+ import_v414.z.discriminatedUnion("type", [
2485
+ import_v414.z.object({
2486
+ type: import_v414.z.literal("skillReference"),
2487
+ skillId: import_v414.z.string(),
2488
+ version: import_v414.z.string().optional()
2489
+ }),
2490
+ import_v414.z.object({
2491
+ type: import_v414.z.literal("inline"),
2492
+ name: import_v414.z.string(),
2493
+ description: import_v414.z.string(),
2494
+ source: import_v414.z.object({
2495
+ type: import_v414.z.literal("base64"),
2496
+ mediaType: import_v414.z.literal("application/zip"),
2497
+ data: import_v414.z.string()
2498
+ })
2499
+ })
2500
+ ])
2501
+ ).optional();
2502
+ var shellArgsSchema = (0, import_provider_utils21.lazySchema)(
2503
+ () => (0, import_provider_utils21.zodSchema)(
2504
+ import_v414.z.object({
2505
+ environment: import_v414.z.union([
2506
+ import_v414.z.object({
2507
+ type: import_v414.z.literal("containerAuto"),
2508
+ fileIds: import_v414.z.array(import_v414.z.string()).optional(),
2509
+ memoryLimit: import_v414.z.enum(["1g", "4g", "16g", "64g"]).optional(),
2510
+ networkPolicy: import_v414.z.discriminatedUnion("type", [
2511
+ import_v414.z.object({ type: import_v414.z.literal("disabled") }),
2512
+ import_v414.z.object({
2513
+ type: import_v414.z.literal("allowlist"),
2514
+ allowedDomains: import_v414.z.array(import_v414.z.string()),
2515
+ domainSecrets: import_v414.z.array(
2516
+ import_v414.z.object({
2517
+ domain: import_v414.z.string(),
2518
+ name: import_v414.z.string(),
2519
+ value: import_v414.z.string()
2520
+ })
2521
+ ).optional()
2522
+ })
2523
+ ]).optional(),
2524
+ skills: shellSkillsSchema
2525
+ }),
2526
+ import_v414.z.object({
2527
+ type: import_v414.z.literal("containerReference"),
2528
+ containerId: import_v414.z.string()
2529
+ }),
2530
+ import_v414.z.object({
2531
+ type: import_v414.z.literal("local").optional(),
2532
+ skills: import_v414.z.array(
2533
+ import_v414.z.object({
2534
+ name: import_v414.z.string(),
2535
+ description: import_v414.z.string(),
2536
+ path: import_v414.z.string()
2537
+ })
2538
+ ).optional()
2539
+ })
2540
+ ]).optional()
2541
+ })
2542
+ )
2543
+ );
2456
2544
  var shell = (0, import_provider_utils21.createProviderToolFactoryWithOutputSchema)({
2457
2545
  id: "openai.shell",
2458
2546
  inputSchema: shellInputSchema,
@@ -2659,8 +2747,32 @@ async function convertToOpenAIResponsesInput({
2659
2747
  if (hasConversation) {
2660
2748
  break;
2661
2749
  }
2750
+ const resolvedResultToolName = toolNameMapping.toProviderToolName(
2751
+ part.toolName
2752
+ );
2753
+ if (hasShellTool && resolvedResultToolName === "shell") {
2754
+ if (part.output.type === "json") {
2755
+ const parsedOutput = await (0, import_provider_utils22.validateTypes)({
2756
+ value: part.output.value,
2757
+ schema: shellOutputSchema
2758
+ });
2759
+ input.push({
2760
+ type: "shell_call_output",
2761
+ call_id: part.toolCallId,
2762
+ output: parsedOutput.output.map((item) => ({
2763
+ stdout: item.stdout,
2764
+ stderr: item.stderr,
2765
+ outcome: item.outcome.type === "timeout" ? { type: "timeout" } : {
2766
+ type: "exit",
2767
+ exit_code: item.outcome.exitCode
2768
+ }
2769
+ }))
2770
+ });
2771
+ }
2772
+ break;
2773
+ }
2662
2774
  if (store) {
2663
- const itemId = (_j = (_i = (_h = part.providerMetadata) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2775
+ const itemId = (_j = (_i = (_h = part.providerOptions) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.itemId) != null ? _j : part.toolCallId;
2664
2776
  input.push({ type: "item_reference", id: itemId });
2665
2777
  } else {
2666
2778
  warnings.push({
@@ -3035,6 +3147,25 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3035
3147
  action: import_v416.z.object({
3036
3148
  commands: import_v416.z.array(import_v416.z.string())
3037
3149
  })
3150
+ }),
3151
+ import_v416.z.object({
3152
+ type: import_v416.z.literal("shell_call_output"),
3153
+ id: import_v416.z.string(),
3154
+ call_id: import_v416.z.string(),
3155
+ status: import_v416.z.enum(["in_progress", "completed", "incomplete"]),
3156
+ output: import_v416.z.array(
3157
+ import_v416.z.object({
3158
+ stdout: import_v416.z.string(),
3159
+ stderr: import_v416.z.string(),
3160
+ outcome: import_v416.z.discriminatedUnion("type", [
3161
+ import_v416.z.object({ type: import_v416.z.literal("timeout") }),
3162
+ import_v416.z.object({
3163
+ type: import_v416.z.literal("exit"),
3164
+ exit_code: import_v416.z.number()
3165
+ })
3166
+ ])
3167
+ })
3168
+ )
3038
3169
  })
3039
3170
  ])
3040
3171
  }),
@@ -3214,6 +3345,25 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3214
3345
  action: import_v416.z.object({
3215
3346
  commands: import_v416.z.array(import_v416.z.string())
3216
3347
  })
3348
+ }),
3349
+ import_v416.z.object({
3350
+ type: import_v416.z.literal("shell_call_output"),
3351
+ id: import_v416.z.string(),
3352
+ call_id: import_v416.z.string(),
3353
+ status: import_v416.z.enum(["in_progress", "completed", "incomplete"]),
3354
+ output: import_v416.z.array(
3355
+ import_v416.z.object({
3356
+ stdout: import_v416.z.string(),
3357
+ stderr: import_v416.z.string(),
3358
+ outcome: import_v416.z.discriminatedUnion("type", [
3359
+ import_v416.z.object({ type: import_v416.z.literal("timeout") }),
3360
+ import_v416.z.object({
3361
+ type: import_v416.z.literal("exit"),
3362
+ exit_code: import_v416.z.number()
3363
+ })
3364
+ ])
3365
+ })
3366
+ )
3217
3367
  })
3218
3368
  ])
3219
3369
  }),
@@ -3559,6 +3709,25 @@ var openaiResponsesResponseSchema = (0, import_provider_utils23.lazySchema)(
3559
3709
  action: import_v416.z.object({
3560
3710
  commands: import_v416.z.array(import_v416.z.string())
3561
3711
  })
3712
+ }),
3713
+ import_v416.z.object({
3714
+ type: import_v416.z.literal("shell_call_output"),
3715
+ id: import_v416.z.string(),
3716
+ call_id: import_v416.z.string(),
3717
+ status: import_v416.z.enum(["in_progress", "completed", "incomplete"]),
3718
+ output: import_v416.z.array(
3719
+ import_v416.z.object({
3720
+ stdout: import_v416.z.string(),
3721
+ stderr: import_v416.z.string(),
3722
+ outcome: import_v416.z.discriminatedUnion("type", [
3723
+ import_v416.z.object({ type: import_v416.z.literal("timeout") }),
3724
+ import_v416.z.object({
3725
+ type: import_v416.z.literal("exit"),
3726
+ exit_code: import_v416.z.number()
3727
+ })
3728
+ ])
3729
+ })
3730
+ )
3562
3731
  })
3563
3732
  ])
3564
3733
  ).optional(),
@@ -4144,8 +4313,15 @@ async function prepareResponsesTools({
4144
4313
  break;
4145
4314
  }
4146
4315
  case "openai.shell": {
4316
+ const args = await (0, import_provider_utils31.validateTypes)({
4317
+ value: tool.args,
4318
+ schema: shellArgsSchema
4319
+ });
4147
4320
  openaiTools.push({
4148
- type: "shell"
4321
+ type: "shell",
4322
+ ...args.environment && {
4323
+ environment: mapShellEnvironment(args.environment)
4324
+ }
4149
4325
  });
4150
4326
  break;
4151
4327
  }
@@ -4275,6 +4451,52 @@ async function prepareResponsesTools({
4275
4451
  }
4276
4452
  }
4277
4453
  }
4454
+ function mapShellEnvironment(environment) {
4455
+ if (environment.type === "containerReference") {
4456
+ const env2 = environment;
4457
+ return {
4458
+ type: "container_reference",
4459
+ container_id: env2.containerId
4460
+ };
4461
+ }
4462
+ if (environment.type === "containerAuto") {
4463
+ const env2 = environment;
4464
+ return {
4465
+ type: "container_auto",
4466
+ file_ids: env2.fileIds,
4467
+ memory_limit: env2.memoryLimit,
4468
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
4469
+ type: "allowlist",
4470
+ allowed_domains: env2.networkPolicy.allowedDomains,
4471
+ domain_secrets: env2.networkPolicy.domainSecrets
4472
+ },
4473
+ skills: mapShellSkills(env2.skills)
4474
+ };
4475
+ }
4476
+ const env = environment;
4477
+ return {
4478
+ type: "local",
4479
+ skills: env.skills
4480
+ };
4481
+ }
4482
+ function mapShellSkills(skills) {
4483
+ return skills == null ? void 0 : skills.map(
4484
+ (skill) => skill.type === "skillReference" ? {
4485
+ type: "skill_reference",
4486
+ skill_id: skill.skillId,
4487
+ version: skill.version
4488
+ } : {
4489
+ type: "inline",
4490
+ name: skill.name,
4491
+ description: skill.description,
4492
+ source: {
4493
+ type: "base64",
4494
+ media_type: skill.source.mediaType,
4495
+ data: skill.source.data
4496
+ }
4497
+ }
4498
+ );
4499
+ }
4278
4500
 
4279
4501
  // src/responses/openai-responses-language-model.ts
4280
4502
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
@@ -4320,7 +4542,7 @@ var OpenAIResponsesLanguageModel = class {
4320
4542
  toolChoice,
4321
4543
  responseFormat
4322
4544
  }) {
4323
- var _a, _b, _c, _d, _e, _f;
4545
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4324
4546
  const warnings = [];
4325
4547
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4326
4548
  if (topK != null) {
@@ -4524,6 +4746,10 @@ var OpenAIResponsesLanguageModel = class {
4524
4746
  tools,
4525
4747
  toolChoice
4526
4748
  });
4749
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
4750
+ (tool) => tool.type === "provider" && tool.id === "openai.shell"
4751
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
4752
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
4527
4753
  return {
4528
4754
  webSearchToolName,
4529
4755
  args: {
@@ -4534,7 +4760,8 @@ var OpenAIResponsesLanguageModel = class {
4534
4760
  warnings: [...warnings, ...toolWarnings],
4535
4761
  store,
4536
4762
  toolNameMapping,
4537
- providerOptionsName
4763
+ providerOptionsName,
4764
+ isShellProviderExecuted
4538
4765
  };
4539
4766
  }
4540
4767
  async doGenerate(options) {
@@ -4544,7 +4771,8 @@ var OpenAIResponsesLanguageModel = class {
4544
4771
  warnings,
4545
4772
  webSearchToolName,
4546
4773
  toolNameMapping,
4547
- providerOptionsName
4774
+ providerOptionsName,
4775
+ isShellProviderExecuted
4548
4776
  } = await this.getArgs(options);
4549
4777
  const url = this.config.url({
4550
4778
  path: "/responses",
@@ -4644,6 +4872,7 @@ var OpenAIResponsesLanguageModel = class {
4644
4872
  commands: part.action.commands
4645
4873
  }
4646
4874
  }),
4875
+ ...isShellProviderExecuted && { providerExecuted: true },
4647
4876
  providerMetadata: {
4648
4877
  [providerOptionsName]: {
4649
4878
  itemId: part.id
@@ -4652,6 +4881,24 @@ var OpenAIResponsesLanguageModel = class {
4652
4881
  });
4653
4882
  break;
4654
4883
  }
4884
+ case "shell_call_output": {
4885
+ content.push({
4886
+ type: "tool-result",
4887
+ toolCallId: part.call_id,
4888
+ toolName: toolNameMapping.toCustomToolName("shell"),
4889
+ result: {
4890
+ output: part.output.map((item) => ({
4891
+ stdout: item.stdout,
4892
+ stderr: item.stderr,
4893
+ outcome: item.outcome.type === "exit" ? {
4894
+ type: "exit",
4895
+ exitCode: item.outcome.exit_code
4896
+ } : { type: "timeout" }
4897
+ }))
4898
+ }
4899
+ });
4900
+ break;
4901
+ }
4655
4902
  case "message": {
4656
4903
  for (const contentPart of part.content) {
4657
4904
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -4941,7 +5188,8 @@ var OpenAIResponsesLanguageModel = class {
4941
5188
  webSearchToolName,
4942
5189
  toolNameMapping,
4943
5190
  store,
4944
- providerOptionsName
5191
+ providerOptionsName,
5192
+ isShellProviderExecuted
4945
5193
  } = await this.getArgs(options);
4946
5194
  const { responseHeaders, value: response } = await (0, import_provider_utils32.postJsonToApi)({
4947
5195
  url: this.config.url({
@@ -5120,6 +5368,7 @@ var OpenAIResponsesLanguageModel = class {
5120
5368
  toolName: toolNameMapping.toCustomToolName("shell"),
5121
5369
  toolCallId: value.item.call_id
5122
5370
  };
5371
+ } else if (value.item.type === "shell_call_output") {
5123
5372
  } else if (value.item.type === "message") {
5124
5373
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
5125
5374
  controller.enqueue({
@@ -5373,10 +5622,31 @@ var OpenAIResponsesLanguageModel = class {
5373
5622
  commands: value.item.action.commands
5374
5623
  }
5375
5624
  }),
5625
+ ...isShellProviderExecuted && {
5626
+ providerExecuted: true
5627
+ },
5376
5628
  providerMetadata: {
5377
5629
  [providerOptionsName]: { itemId: value.item.id }
5378
5630
  }
5379
5631
  });
5632
+ } else if (value.item.type === "shell_call_output") {
5633
+ controller.enqueue({
5634
+ type: "tool-result",
5635
+ toolCallId: value.item.call_id,
5636
+ toolName: toolNameMapping.toCustomToolName("shell"),
5637
+ result: {
5638
+ output: value.item.output.map(
5639
+ (item) => ({
5640
+ stdout: item.stdout,
5641
+ stderr: item.stderr,
5642
+ outcome: item.outcome.type === "exit" ? {
5643
+ type: "exit",
5644
+ exitCode: item.outcome.exit_code
5645
+ } : { type: "timeout" }
5646
+ })
5647
+ )
5648
+ }
5649
+ });
5380
5650
  } else if (value.item.type === "reasoning") {
5381
5651
  const activeReasoningPart = activeReasoning[value.item.id];
5382
5652
  const summaryPartIndices = Object.entries(