@ai-sdk/openai 3.0.100 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.102
4
+
5
+ ### Patch Changes
6
+
7
+ - 087d7e2: Signal schema-invalid known Responses stream events and preserve the error finish reason.
8
+
9
+ ## 3.0.101
10
+
11
+ ### Patch Changes
12
+
13
+ - 313a441: Prevent negative text output token counts when providers report reasoning tokens. Perplexity reasoning tokens are now treated as separate from completion tokens.
14
+ - Updated dependencies [5642849]
15
+ - @ai-sdk/provider-utils@4.0.48
16
+
3
17
  ## 3.0.100
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -314,6 +314,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
314
314
  type: "response.output_item.added";
315
315
  output_index: number;
316
316
  item: {
317
+ type: "local_shell_call";
318
+ id: string;
319
+ call_id: string;
320
+ action: {
321
+ type: "exec";
322
+ command: string[];
323
+ timeout_ms?: number | undefined;
324
+ user?: string | undefined;
325
+ working_directory?: string | undefined;
326
+ env?: Record<string, string> | undefined;
327
+ };
328
+ } | {
317
329
  type: "message";
318
330
  id: string;
319
331
  phase?: "commentary" | "final_answer" | null | undefined;
@@ -431,6 +443,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
431
443
  type: "response.output_item.done";
432
444
  output_index: number;
433
445
  item: {
446
+ type: "local_shell_call";
447
+ id: string;
448
+ call_id: string;
449
+ action: {
450
+ type: "exec";
451
+ command: string[];
452
+ timeout_ms?: number | undefined;
453
+ user?: string | undefined;
454
+ working_directory?: string | undefined;
455
+ env?: Record<string, string> | undefined;
456
+ };
457
+ } | {
434
458
  type: "message";
435
459
  id: string;
436
460
  phase?: "commentary" | "final_answer" | null | undefined;
@@ -503,18 +527,6 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
503
527
  score: number;
504
528
  text: string;
505
529
  }[] | null | undefined;
506
- } | {
507
- type: "local_shell_call";
508
- id: string;
509
- call_id: string;
510
- action: {
511
- type: "exec";
512
- command: string[];
513
- timeout_ms?: number | undefined;
514
- user?: string | undefined;
515
- working_directory?: string | undefined;
516
- env?: Record<string, string> | undefined;
517
- };
518
530
  } | {
519
531
  type: "computer_call";
520
532
  id: string;
@@ -617,6 +629,11 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
617
629
  item_id: string;
618
630
  output_index: number;
619
631
  delta: string;
632
+ } | {
633
+ type: "response.function_call_arguments.done";
634
+ item_id: string;
635
+ output_index: number;
636
+ arguments: string;
620
637
  } | {
621
638
  type: "response.custom_tool_call_input.delta";
622
639
  item_id: string;
package/dist/index.d.ts CHANGED
@@ -314,6 +314,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
314
314
  type: "response.output_item.added";
315
315
  output_index: number;
316
316
  item: {
317
+ type: "local_shell_call";
318
+ id: string;
319
+ call_id: string;
320
+ action: {
321
+ type: "exec";
322
+ command: string[];
323
+ timeout_ms?: number | undefined;
324
+ user?: string | undefined;
325
+ working_directory?: string | undefined;
326
+ env?: Record<string, string> | undefined;
327
+ };
328
+ } | {
317
329
  type: "message";
318
330
  id: string;
319
331
  phase?: "commentary" | "final_answer" | null | undefined;
@@ -431,6 +443,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
431
443
  type: "response.output_item.done";
432
444
  output_index: number;
433
445
  item: {
446
+ type: "local_shell_call";
447
+ id: string;
448
+ call_id: string;
449
+ action: {
450
+ type: "exec";
451
+ command: string[];
452
+ timeout_ms?: number | undefined;
453
+ user?: string | undefined;
454
+ working_directory?: string | undefined;
455
+ env?: Record<string, string> | undefined;
456
+ };
457
+ } | {
434
458
  type: "message";
435
459
  id: string;
436
460
  phase?: "commentary" | "final_answer" | null | undefined;
@@ -503,18 +527,6 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
503
527
  score: number;
504
528
  text: string;
505
529
  }[] | null | undefined;
506
- } | {
507
- type: "local_shell_call";
508
- id: string;
509
- call_id: string;
510
- action: {
511
- type: "exec";
512
- command: string[];
513
- timeout_ms?: number | undefined;
514
- user?: string | undefined;
515
- working_directory?: string | undefined;
516
- env?: Record<string, string> | undefined;
517
- };
518
530
  } | {
519
531
  type: "computer_call";
520
532
  id: string;
@@ -617,6 +629,11 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
617
629
  item_id: string;
618
630
  output_index: number;
619
631
  delta: string;
632
+ } | {
633
+ type: "response.function_call_arguments.done";
634
+ item_id: string;
635
+ output_index: number;
636
+ arguments: string;
620
637
  } | {
621
638
  type: "response.custom_tool_call_input.delta";
622
639
  item_id: string;
package/dist/index.js CHANGED
@@ -244,7 +244,7 @@ function convertOpenAIChatUsage(usage) {
244
244
  },
245
245
  outputTokens: {
246
246
  total: completionTokens,
247
- text: completionTokens - reasoningTokens,
247
+ text: Math.max(0, completionTokens - reasoningTokens),
248
248
  reasoning: reasoningTokens
249
249
  },
250
250
  raw: usage
@@ -3942,6 +3942,22 @@ var jsonValueSchema2 = import_v422.z.lazy(
3942
3942
  import_v422.z.record(import_v422.z.string(), jsonValueSchema2.optional())
3943
3943
  ])
3944
3944
  );
3945
+ function isRecord(value) {
3946
+ return value != null && typeof value === "object" && !Array.isArray(value);
3947
+ }
3948
+ var openaiResponsesLocalShellCallSchema = import_v422.z.object({
3949
+ type: import_v422.z.literal("local_shell_call"),
3950
+ id: import_v422.z.string(),
3951
+ call_id: import_v422.z.string(),
3952
+ action: import_v422.z.object({
3953
+ type: import_v422.z.literal("exec"),
3954
+ command: import_v422.z.array(import_v422.z.string()),
3955
+ timeout_ms: import_v422.z.number().optional(),
3956
+ user: import_v422.z.string().optional(),
3957
+ working_directory: import_v422.z.string().optional(),
3958
+ env: import_v422.z.record(import_v422.z.string(), import_v422.z.string()).optional()
3959
+ })
3960
+ });
3945
3961
  var openaiResponsesNestedErrorChunkSchema = import_v422.z.object({
3946
3962
  type: import_v422.z.literal("error"),
3947
3963
  sequence_number: import_v422.z.number(),
@@ -3959,6 +3975,60 @@ var openaiResponsesErrorChunkSchema = import_v422.z.object({
3959
3975
  message: import_v422.z.string(),
3960
3976
  param: import_v422.z.string().nullish()
3961
3977
  });
3978
+ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
3979
+ "error",
3980
+ "response.apply_patch_call_operation_diff.delta",
3981
+ "response.apply_patch_call_operation_diff.done",
3982
+ "response.code_interpreter_call_code.delta",
3983
+ "response.code_interpreter_call_code.done",
3984
+ "response.completed",
3985
+ "response.created",
3986
+ "response.custom_tool_call_input.delta",
3987
+ "response.failed",
3988
+ "response.function_call_arguments.delta",
3989
+ "response.function_call_arguments.done",
3990
+ "response.image_generation_call.partial_image",
3991
+ "response.incomplete",
3992
+ "response.output_item.added",
3993
+ "response.output_item.done",
3994
+ "response.output_text.annotation.added",
3995
+ "response.output_text.delta",
3996
+ "response.reasoning_summary_part.added",
3997
+ "response.reasoning_summary_part.done",
3998
+ "response.reasoning_summary_text.delta"
3999
+ ]);
4000
+ var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
4001
+ "apply_patch_call",
4002
+ "code_interpreter_call",
4003
+ "computer_call",
4004
+ "custom_tool_call",
4005
+ "file_search_call",
4006
+ "function_call",
4007
+ "image_generation_call",
4008
+ "local_shell_call",
4009
+ "mcp_approval_request",
4010
+ "mcp_call",
4011
+ "mcp_list_tools",
4012
+ "message",
4013
+ "reasoning",
4014
+ "shell_call",
4015
+ "shell_call_output",
4016
+ "tool_search_call",
4017
+ "tool_search_output",
4018
+ "web_search_call"
4019
+ ]);
4020
+ function isModeledOpenAIResponsesChunk(value) {
4021
+ if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
4022
+ return false;
4023
+ }
4024
+ if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
4025
+ return true;
4026
+ }
4027
+ if (!isRecord(value.item) || typeof value.item.type !== "string") {
4028
+ return true;
4029
+ }
4030
+ return openaiResponsesModeledOutputItemTypes.has(value.item.type);
4031
+ }
3962
4032
  var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
3963
4033
  () => (0, import_provider_utils28.zodSchema)(
3964
4034
  import_v422.z.union([
@@ -4077,6 +4147,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4077
4147
  type: import_v422.z.literal("file_search_call"),
4078
4148
  id: import_v422.z.string()
4079
4149
  }),
4150
+ openaiResponsesLocalShellCallSchema,
4080
4151
  import_v422.z.object({
4081
4152
  type: import_v422.z.literal("image_generation_call"),
4082
4153
  id: import_v422.z.string()
@@ -4275,19 +4346,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4275
4346
  })
4276
4347
  ).nullish()
4277
4348
  }),
4278
- import_v422.z.object({
4279
- type: import_v422.z.literal("local_shell_call"),
4280
- id: import_v422.z.string(),
4281
- call_id: import_v422.z.string(),
4282
- action: import_v422.z.object({
4283
- type: import_v422.z.literal("exec"),
4284
- command: import_v422.z.array(import_v422.z.string()),
4285
- timeout_ms: import_v422.z.number().optional(),
4286
- user: import_v422.z.string().optional(),
4287
- working_directory: import_v422.z.string().optional(),
4288
- env: import_v422.z.record(import_v422.z.string(), import_v422.z.string()).optional()
4289
- })
4290
- }),
4349
+ openaiResponsesLocalShellCallSchema,
4291
4350
  import_v422.z.object({
4292
4351
  type: import_v422.z.literal("computer_call"),
4293
4352
  id: import_v422.z.string(),
@@ -4414,6 +4473,14 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4414
4473
  output_index: import_v422.z.number(),
4415
4474
  delta: import_v422.z.string()
4416
4475
  }),
4476
+ import_v422.z.object({
4477
+ // `name` is documented as required but omitted from live API events:
4478
+ // https://github.com/openai/openai-openapi/issues/545
4479
+ type: import_v422.z.literal("response.function_call_arguments.done"),
4480
+ item_id: import_v422.z.string(),
4481
+ output_index: import_v422.z.number(),
4482
+ arguments: import_v422.z.string()
4483
+ }),
4417
4484
  import_v422.z.object({
4418
4485
  type: import_v422.z.literal("response.custom_tool_call_input.delta"),
4419
4486
  item_id: import_v422.z.string(),
@@ -4500,7 +4567,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4500
4567
  }),
4501
4568
  openaiResponsesNestedErrorChunkSchema,
4502
4569
  openaiResponsesErrorChunkSchema,
4503
- import_v422.z.object({ type: import_v422.z.string() }).loose().transform((value) => ({
4570
+ import_v422.z.object({ type: import_v422.z.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
4571
+ message: "Known response chunk failed schema validation"
4572
+ }).transform((value) => ({
4504
4573
  type: "unknown_chunk",
4505
4574
  message: value.type
4506
4575
  }))
@@ -4640,19 +4709,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils28.lazySchema)(
4640
4709
  id: import_v422.z.string(),
4641
4710
  result: import_v422.z.string()
4642
4711
  }),
4643
- import_v422.z.object({
4644
- type: import_v422.z.literal("local_shell_call"),
4645
- id: import_v422.z.string(),
4646
- call_id: import_v422.z.string(),
4647
- action: import_v422.z.object({
4648
- type: import_v422.z.literal("exec"),
4649
- command: import_v422.z.array(import_v422.z.string()),
4650
- timeout_ms: import_v422.z.number().optional(),
4651
- user: import_v422.z.string().optional(),
4652
- working_directory: import_v422.z.string().optional(),
4653
- env: import_v422.z.record(import_v422.z.string(), import_v422.z.string()).optional()
4654
- })
4655
- }),
4712
+ openaiResponsesLocalShellCallSchema,
4656
4713
  import_v422.z.object({
4657
4714
  type: import_v422.z.literal("function_call"),
4658
4715
  call_id: import_v422.z.string(),
@@ -6411,6 +6468,7 @@ var OpenAIResponsesLanguageModel = class {
6411
6468
  requestBodyValues: body,
6412
6469
  responseHeaders
6413
6470
  }) : chunk.error;
6471
+ encounteredStreamError = true;
6414
6472
  finishReason = { unified: "error", raw: void 0 };
6415
6473
  controller.enqueue({ type: "error", error });
6416
6474
  return;
@@ -7210,13 +7268,15 @@ var OpenAIResponsesLanguageModel = class {
7210
7268
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
7211
7269
  }
7212
7270
  } else if (isResponseFinishedChunk(value)) {
7213
- finishReason = {
7214
- unified: mapOpenAIResponseFinishReason({
7215
- finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7216
- hasFunctionCall
7217
- }),
7218
- raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7219
- };
7271
+ if (!encounteredStreamError) {
7272
+ finishReason = {
7273
+ unified: mapOpenAIResponseFinishReason({
7274
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7275
+ hasFunctionCall
7276
+ }),
7277
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7278
+ };
7279
+ }
7220
7280
  usage = value.response.usage;
7221
7281
  if (typeof value.response.service_tier === "string") {
7222
7282
  serviceTier = value.response.service_tier;
@@ -7817,7 +7877,7 @@ var OpenAITranscriptionModel = class {
7817
7877
  };
7818
7878
 
7819
7879
  // src/version.ts
7820
- var VERSION = true ? "3.0.100" : "0.0.0-test";
7880
+ var VERSION = true ? "3.0.102" : "0.0.0-test";
7821
7881
 
7822
7882
  // src/openai-provider.ts
7823
7883
  function createOpenAI(options = {}) {