@ai-sdk/openai 3.0.29 → 3.0.31

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
@@ -2220,6 +2220,67 @@ var shellOutputSchema = lazySchema13(
2220
2220
  })
2221
2221
  )
2222
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
+ );
2223
2284
  var shell = createProviderToolFactoryWithOutputSchema6({
2224
2285
  id: "openai.shell",
2225
2286
  inputSchema: shellInputSchema,
@@ -2267,7 +2328,7 @@ var webSearchOutputSchema = lazySchema14(
2267
2328
  url: z15.string().nullish(),
2268
2329
  pattern: z15.string().nullish()
2269
2330
  })
2270
- ]),
2331
+ ]).optional(),
2271
2332
  sources: z15.array(
2272
2333
  z15.discriminatedUnion("type", [
2273
2334
  z15.object({ type: z15.literal("url"), url: z15.string() }),
@@ -2325,7 +2386,7 @@ var webSearchPreviewOutputSchema = lazySchema15(
2325
2386
  url: z16.string().nullish(),
2326
2387
  pattern: z16.string().nullish()
2327
2388
  })
2328
- ])
2389
+ ]).optional()
2329
2390
  })
2330
2391
  )
2331
2392
  );
@@ -2763,8 +2824,32 @@ async function convertToOpenAIResponsesInput({
2763
2824
  if (hasConversation) {
2764
2825
  break;
2765
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
+ }
2766
2851
  if (store) {
2767
- 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;
2768
2853
  input.push({ type: "item_reference", id: itemId });
2769
2854
  } else {
2770
2855
  warnings.push({
@@ -3139,6 +3224,25 @@ var openaiResponsesChunkSchema = lazySchema17(
3139
3224
  action: z19.object({
3140
3225
  commands: z19.array(z19.string())
3141
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
+ )
3142
3246
  })
3143
3247
  ])
3144
3248
  }),
@@ -3204,7 +3308,7 @@ var openaiResponsesChunkSchema = lazySchema17(
3204
3308
  url: z19.string().nullish(),
3205
3309
  pattern: z19.string().nullish()
3206
3310
  })
3207
- ])
3311
+ ]).nullish()
3208
3312
  }),
3209
3313
  z19.object({
3210
3314
  type: z19.literal("file_search_call"),
@@ -3318,6 +3422,25 @@ var openaiResponsesChunkSchema = lazySchema17(
3318
3422
  action: z19.object({
3319
3423
  commands: z19.array(z19.string())
3320
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
+ )
3321
3444
  })
3322
3445
  ])
3323
3446
  }),
@@ -3501,7 +3624,10 @@ var openaiResponsesResponseSchema = lazySchema17(
3501
3624
  sources: z19.array(
3502
3625
  z19.discriminatedUnion("type", [
3503
3626
  z19.object({ type: z19.literal("url"), url: z19.string() }),
3504
- z19.object({ type: z19.literal("api"), name: z19.string() })
3627
+ z19.object({
3628
+ type: z19.literal("api"),
3629
+ name: z19.string()
3630
+ })
3505
3631
  ])
3506
3632
  ).nullish()
3507
3633
  }),
@@ -3514,7 +3640,7 @@ var openaiResponsesResponseSchema = lazySchema17(
3514
3640
  url: z19.string().nullish(),
3515
3641
  pattern: z19.string().nullish()
3516
3642
  })
3517
- ])
3643
+ ]).nullish()
3518
3644
  }),
3519
3645
  z19.object({
3520
3646
  type: z19.literal("file_search_call"),
@@ -3663,6 +3789,25 @@ var openaiResponsesResponseSchema = lazySchema17(
3663
3789
  action: z19.object({
3664
3790
  commands: z19.array(z19.string())
3665
3791
  })
3792
+ }),
3793
+ z19.object({
3794
+ type: z19.literal("shell_call_output"),
3795
+ id: z19.string(),
3796
+ call_id: z19.string(),
3797
+ status: z19.enum(["in_progress", "completed", "incomplete"]),
3798
+ output: z19.array(
3799
+ z19.object({
3800
+ stdout: z19.string(),
3801
+ stderr: z19.string(),
3802
+ outcome: z19.discriminatedUnion("type", [
3803
+ z19.object({ type: z19.literal("timeout") }),
3804
+ z19.object({
3805
+ type: z19.literal("exit"),
3806
+ exit_code: z19.number()
3807
+ })
3808
+ ])
3809
+ })
3810
+ )
3666
3811
  })
3667
3812
  ])
3668
3813
  ).optional(),
@@ -3958,8 +4103,15 @@ async function prepareResponsesTools({
3958
4103
  break;
3959
4104
  }
3960
4105
  case "openai.shell": {
4106
+ const args = await validateTypes2({
4107
+ value: tool.args,
4108
+ schema: shellArgsSchema
4109
+ });
3961
4110
  openaiTools2.push({
3962
- type: "shell"
4111
+ type: "shell",
4112
+ ...args.environment && {
4113
+ environment: mapShellEnvironment(args.environment)
4114
+ }
3963
4115
  });
3964
4116
  break;
3965
4117
  }
@@ -4089,6 +4241,52 @@ async function prepareResponsesTools({
4089
4241
  }
4090
4242
  }
4091
4243
  }
4244
+ function mapShellEnvironment(environment) {
4245
+ if (environment.type === "containerReference") {
4246
+ const env2 = environment;
4247
+ return {
4248
+ type: "container_reference",
4249
+ container_id: env2.containerId
4250
+ };
4251
+ }
4252
+ if (environment.type === "containerAuto") {
4253
+ const env2 = environment;
4254
+ return {
4255
+ type: "container_auto",
4256
+ file_ids: env2.fileIds,
4257
+ memory_limit: env2.memoryLimit,
4258
+ network_policy: env2.networkPolicy == null ? void 0 : env2.networkPolicy.type === "disabled" ? { type: "disabled" } : {
4259
+ type: "allowlist",
4260
+ allowed_domains: env2.networkPolicy.allowedDomains,
4261
+ domain_secrets: env2.networkPolicy.domainSecrets
4262
+ },
4263
+ skills: mapShellSkills(env2.skills)
4264
+ };
4265
+ }
4266
+ const env = environment;
4267
+ return {
4268
+ type: "local",
4269
+ skills: env.skills
4270
+ };
4271
+ }
4272
+ function mapShellSkills(skills) {
4273
+ return skills == null ? void 0 : skills.map(
4274
+ (skill) => skill.type === "skillReference" ? {
4275
+ type: "skill_reference",
4276
+ skill_id: skill.skillId,
4277
+ version: skill.version
4278
+ } : {
4279
+ type: "inline",
4280
+ name: skill.name,
4281
+ description: skill.description,
4282
+ source: {
4283
+ type: "base64",
4284
+ media_type: skill.source.mediaType,
4285
+ data: skill.source.data
4286
+ }
4287
+ }
4288
+ );
4289
+ }
4092
4290
 
4093
4291
  // src/responses/openai-responses-language-model.ts
4094
4292
  function extractApprovalRequestIdToToolCallIdMapping(prompt) {
@@ -4134,7 +4332,7 @@ var OpenAIResponsesLanguageModel = class {
4134
4332
  toolChoice,
4135
4333
  responseFormat
4136
4334
  }) {
4137
- var _a, _b, _c, _d, _e, _f;
4335
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4138
4336
  const warnings = [];
4139
4337
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4140
4338
  if (topK != null) {
@@ -4338,6 +4536,10 @@ var OpenAIResponsesLanguageModel = class {
4338
4536
  tools,
4339
4537
  toolChoice
4340
4538
  });
4539
+ const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
4540
+ (tool) => tool.type === "provider" && tool.id === "openai.shell"
4541
+ )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
4542
+ const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
4341
4543
  return {
4342
4544
  webSearchToolName,
4343
4545
  args: {
@@ -4348,7 +4550,8 @@ var OpenAIResponsesLanguageModel = class {
4348
4550
  warnings: [...warnings, ...toolWarnings],
4349
4551
  store,
4350
4552
  toolNameMapping,
4351
- providerOptionsName
4553
+ providerOptionsName,
4554
+ isShellProviderExecuted
4352
4555
  };
4353
4556
  }
4354
4557
  async doGenerate(options) {
@@ -4358,7 +4561,8 @@ var OpenAIResponsesLanguageModel = class {
4358
4561
  warnings,
4359
4562
  webSearchToolName,
4360
4563
  toolNameMapping,
4361
- providerOptionsName
4564
+ providerOptionsName,
4565
+ isShellProviderExecuted
4362
4566
  } = await this.getArgs(options);
4363
4567
  const url = this.config.url({
4364
4568
  path: "/responses",
@@ -4458,6 +4662,7 @@ var OpenAIResponsesLanguageModel = class {
4458
4662
  commands: part.action.commands
4459
4663
  }
4460
4664
  }),
4665
+ ...isShellProviderExecuted && { providerExecuted: true },
4461
4666
  providerMetadata: {
4462
4667
  [providerOptionsName]: {
4463
4668
  itemId: part.id
@@ -4466,6 +4671,24 @@ var OpenAIResponsesLanguageModel = class {
4466
4671
  });
4467
4672
  break;
4468
4673
  }
4674
+ case "shell_call_output": {
4675
+ content.push({
4676
+ type: "tool-result",
4677
+ toolCallId: part.call_id,
4678
+ toolName: toolNameMapping.toCustomToolName("shell"),
4679
+ result: {
4680
+ output: part.output.map((item) => ({
4681
+ stdout: item.stdout,
4682
+ stderr: item.stderr,
4683
+ outcome: item.outcome.type === "exit" ? {
4684
+ type: "exit",
4685
+ exitCode: item.outcome.exit_code
4686
+ } : { type: "timeout" }
4687
+ }))
4688
+ }
4689
+ });
4690
+ break;
4691
+ }
4469
4692
  case "message": {
4470
4693
  for (const contentPart of part.content) {
4471
4694
  if (((_c = (_b = options.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.logprobs) && contentPart.logprobs) {
@@ -4755,7 +4978,8 @@ var OpenAIResponsesLanguageModel = class {
4755
4978
  webSearchToolName,
4756
4979
  toolNameMapping,
4757
4980
  store,
4758
- providerOptionsName
4981
+ providerOptionsName,
4982
+ isShellProviderExecuted
4759
4983
  } = await this.getArgs(options);
4760
4984
  const { responseHeaders, value: response } = await postJsonToApi5({
4761
4985
  url: this.config.url({
@@ -4934,6 +5158,7 @@ var OpenAIResponsesLanguageModel = class {
4934
5158
  toolName: toolNameMapping.toCustomToolName("shell"),
4935
5159
  toolCallId: value.item.call_id
4936
5160
  };
5161
+ } else if (value.item.type === "shell_call_output") {
4937
5162
  } else if (value.item.type === "message") {
4938
5163
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
4939
5164
  controller.enqueue({
@@ -5187,10 +5412,31 @@ var OpenAIResponsesLanguageModel = class {
5187
5412
  commands: value.item.action.commands
5188
5413
  }
5189
5414
  }),
5415
+ ...isShellProviderExecuted && {
5416
+ providerExecuted: true
5417
+ },
5190
5418
  providerMetadata: {
5191
5419
  [providerOptionsName]: { itemId: value.item.id }
5192
5420
  }
5193
5421
  });
5422
+ } else if (value.item.type === "shell_call_output") {
5423
+ controller.enqueue({
5424
+ type: "tool-result",
5425
+ toolCallId: value.item.call_id,
5426
+ toolName: toolNameMapping.toCustomToolName("shell"),
5427
+ result: {
5428
+ output: value.item.output.map(
5429
+ (item) => ({
5430
+ stdout: item.stdout,
5431
+ stderr: item.stderr,
5432
+ outcome: item.outcome.type === "exit" ? {
5433
+ type: "exit",
5434
+ exitCode: item.outcome.exit_code
5435
+ } : { type: "timeout" }
5436
+ })
5437
+ )
5438
+ }
5439
+ });
5194
5440
  } else if (value.item.type === "reasoning") {
5195
5441
  const activeReasoningPart = activeReasoning[value.item.id];
5196
5442
  const summaryPartIndices = Object.entries(
@@ -5507,6 +5753,9 @@ function isErrorChunk(chunk) {
5507
5753
  }
5508
5754
  function mapWebSearchOutput(action) {
5509
5755
  var _a;
5756
+ if (action == null) {
5757
+ return {};
5758
+ }
5510
5759
  switch (action.type) {
5511
5760
  case "search":
5512
5761
  return {
@@ -5895,7 +6144,7 @@ var OpenAITranscriptionModel = class {
5895
6144
  };
5896
6145
 
5897
6146
  // src/version.ts
5898
- var VERSION = true ? "3.0.29" : "0.0.0-test";
6147
+ var VERSION = true ? "3.0.31" : "0.0.0-test";
5899
6148
 
5900
6149
  // src/openai-provider.ts
5901
6150
  function createOpenAI(options = {}) {