@ai-sdk/openai 3.0.101 → 3.0.102

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.
@@ -3933,6 +3933,22 @@ var jsonValueSchema = z18.lazy(
3933
3933
  z18.record(z18.string(), jsonValueSchema.optional())
3934
3934
  ])
3935
3935
  );
3936
+ function isRecord(value) {
3937
+ return value != null && typeof value === "object" && !Array.isArray(value);
3938
+ }
3939
+ var openaiResponsesLocalShellCallSchema = z18.object({
3940
+ type: z18.literal("local_shell_call"),
3941
+ id: z18.string(),
3942
+ call_id: z18.string(),
3943
+ action: z18.object({
3944
+ type: z18.literal("exec"),
3945
+ command: z18.array(z18.string()),
3946
+ timeout_ms: z18.number().optional(),
3947
+ user: z18.string().optional(),
3948
+ working_directory: z18.string().optional(),
3949
+ env: z18.record(z18.string(), z18.string()).optional()
3950
+ })
3951
+ });
3936
3952
  var openaiResponsesNestedErrorChunkSchema = z18.object({
3937
3953
  type: z18.literal("error"),
3938
3954
  sequence_number: z18.number(),
@@ -3950,6 +3966,60 @@ var openaiResponsesErrorChunkSchema = z18.object({
3950
3966
  message: z18.string(),
3951
3967
  param: z18.string().nullish()
3952
3968
  });
3969
+ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
3970
+ "error",
3971
+ "response.apply_patch_call_operation_diff.delta",
3972
+ "response.apply_patch_call_operation_diff.done",
3973
+ "response.code_interpreter_call_code.delta",
3974
+ "response.code_interpreter_call_code.done",
3975
+ "response.completed",
3976
+ "response.created",
3977
+ "response.custom_tool_call_input.delta",
3978
+ "response.failed",
3979
+ "response.function_call_arguments.delta",
3980
+ "response.function_call_arguments.done",
3981
+ "response.image_generation_call.partial_image",
3982
+ "response.incomplete",
3983
+ "response.output_item.added",
3984
+ "response.output_item.done",
3985
+ "response.output_text.annotation.added",
3986
+ "response.output_text.delta",
3987
+ "response.reasoning_summary_part.added",
3988
+ "response.reasoning_summary_part.done",
3989
+ "response.reasoning_summary_text.delta"
3990
+ ]);
3991
+ var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
3992
+ "apply_patch_call",
3993
+ "code_interpreter_call",
3994
+ "computer_call",
3995
+ "custom_tool_call",
3996
+ "file_search_call",
3997
+ "function_call",
3998
+ "image_generation_call",
3999
+ "local_shell_call",
4000
+ "mcp_approval_request",
4001
+ "mcp_call",
4002
+ "mcp_list_tools",
4003
+ "message",
4004
+ "reasoning",
4005
+ "shell_call",
4006
+ "shell_call_output",
4007
+ "tool_search_call",
4008
+ "tool_search_output",
4009
+ "web_search_call"
4010
+ ]);
4011
+ function isModeledOpenAIResponsesChunk(value) {
4012
+ if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
4013
+ return false;
4014
+ }
4015
+ if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
4016
+ return true;
4017
+ }
4018
+ if (!isRecord(value.item) || typeof value.item.type !== "string") {
4019
+ return true;
4020
+ }
4021
+ return openaiResponsesModeledOutputItemTypes.has(value.item.type);
4022
+ }
3953
4023
  var openaiResponsesChunkSchema = lazySchema16(
3954
4024
  () => zodSchema16(
3955
4025
  z18.union([
@@ -4068,6 +4138,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4068
4138
  type: z18.literal("file_search_call"),
4069
4139
  id: z18.string()
4070
4140
  }),
4141
+ openaiResponsesLocalShellCallSchema,
4071
4142
  z18.object({
4072
4143
  type: z18.literal("image_generation_call"),
4073
4144
  id: z18.string()
@@ -4266,19 +4337,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4266
4337
  })
4267
4338
  ).nullish()
4268
4339
  }),
4269
- z18.object({
4270
- type: z18.literal("local_shell_call"),
4271
- id: z18.string(),
4272
- call_id: z18.string(),
4273
- action: z18.object({
4274
- type: z18.literal("exec"),
4275
- command: z18.array(z18.string()),
4276
- timeout_ms: z18.number().optional(),
4277
- user: z18.string().optional(),
4278
- working_directory: z18.string().optional(),
4279
- env: z18.record(z18.string(), z18.string()).optional()
4280
- })
4281
- }),
4340
+ openaiResponsesLocalShellCallSchema,
4282
4341
  z18.object({
4283
4342
  type: z18.literal("computer_call"),
4284
4343
  id: z18.string(),
@@ -4405,6 +4464,14 @@ var openaiResponsesChunkSchema = lazySchema16(
4405
4464
  output_index: z18.number(),
4406
4465
  delta: z18.string()
4407
4466
  }),
4467
+ z18.object({
4468
+ // `name` is documented as required but omitted from live API events:
4469
+ // https://github.com/openai/openai-openapi/issues/545
4470
+ type: z18.literal("response.function_call_arguments.done"),
4471
+ item_id: z18.string(),
4472
+ output_index: z18.number(),
4473
+ arguments: z18.string()
4474
+ }),
4408
4475
  z18.object({
4409
4476
  type: z18.literal("response.custom_tool_call_input.delta"),
4410
4477
  item_id: z18.string(),
@@ -4491,7 +4558,9 @@ var openaiResponsesChunkSchema = lazySchema16(
4491
4558
  }),
4492
4559
  openaiResponsesNestedErrorChunkSchema,
4493
4560
  openaiResponsesErrorChunkSchema,
4494
- z18.object({ type: z18.string() }).loose().transform((value) => ({
4561
+ z18.object({ type: z18.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
4562
+ message: "Known response chunk failed schema validation"
4563
+ }).transform((value) => ({
4495
4564
  type: "unknown_chunk",
4496
4565
  message: value.type
4497
4566
  }))
@@ -4631,19 +4700,7 @@ var openaiResponsesResponseSchema = lazySchema16(
4631
4700
  id: z18.string(),
4632
4701
  result: z18.string()
4633
4702
  }),
4634
- z18.object({
4635
- type: z18.literal("local_shell_call"),
4636
- id: z18.string(),
4637
- call_id: z18.string(),
4638
- action: z18.object({
4639
- type: z18.literal("exec"),
4640
- command: z18.array(z18.string()),
4641
- timeout_ms: z18.number().optional(),
4642
- user: z18.string().optional(),
4643
- working_directory: z18.string().optional(),
4644
- env: z18.record(z18.string(), z18.string()).optional()
4645
- })
4646
- }),
4703
+ openaiResponsesLocalShellCallSchema,
4647
4704
  z18.object({
4648
4705
  type: z18.literal("function_call"),
4649
4706
  call_id: z18.string(),
@@ -6759,6 +6816,7 @@ var OpenAIResponsesLanguageModel = class {
6759
6816
  requestBodyValues: body,
6760
6817
  responseHeaders
6761
6818
  }) : chunk.error;
6819
+ encounteredStreamError = true;
6762
6820
  finishReason = { unified: "error", raw: void 0 };
6763
6821
  controller.enqueue({ type: "error", error });
6764
6822
  return;
@@ -7558,13 +7616,15 @@ var OpenAIResponsesLanguageModel = class {
7558
7616
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
7559
7617
  }
7560
7618
  } else if (isResponseFinishedChunk(value)) {
7561
- finishReason = {
7562
- unified: mapOpenAIResponseFinishReason({
7563
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7564
- hasFunctionCall
7565
- }),
7566
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7567
- };
7619
+ if (!encounteredStreamError) {
7620
+ finishReason = {
7621
+ unified: mapOpenAIResponseFinishReason({
7622
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7623
+ hasFunctionCall
7624
+ }),
7625
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7626
+ };
7627
+ }
7568
7628
  usage = value.response.usage;
7569
7629
  if (typeof value.response.service_tier === "string") {
7570
7630
  serviceTier = value.response.service_tier;