@yourgpt/llm-sdk 2.6.0-beta.3 → 2.6.0

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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -10
  3. package/dist/adapters/index.d.mts +11 -13
  4. package/dist/adapters/index.d.ts +11 -13
  5. package/dist/adapters/index.js +327 -100
  6. package/dist/adapters/index.mjs +327 -100
  7. package/dist/audio-K-Z3-Bce.d.mts +191 -0
  8. package/dist/audio-K-Z3-Bce.d.ts +191 -0
  9. package/dist/{base-BICaQaRS.d.mts → base-6LzczuCg.d.ts} +8 -1
  10. package/dist/{base-CpRPB8u8.d.ts → base-DySbTP8C.d.mts} +8 -1
  11. package/dist/decisions-CJzOt87t.d.mts +137 -0
  12. package/dist/decisions-CJzOt87t.d.ts +137 -0
  13. package/dist/fallback/index.d.mts +4 -4
  14. package/dist/fallback/index.d.ts +4 -4
  15. package/dist/http-BQxUT5A9.d.mts +9 -0
  16. package/dist/http-BQxUT5A9.d.ts +9 -0
  17. package/dist/index.d.mts +14 -8
  18. package/dist/index.d.ts +14 -8
  19. package/dist/index.js +599 -195
  20. package/dist/index.mjs +596 -196
  21. package/dist/providers/anthropic/index.d.mts +7 -4
  22. package/dist/providers/anthropic/index.d.ts +7 -4
  23. package/dist/providers/anthropic/index.js +383 -102
  24. package/dist/providers/anthropic/index.mjs +383 -102
  25. package/dist/providers/azure/index.d.mts +3 -3
  26. package/dist/providers/azure/index.d.ts +3 -3
  27. package/dist/providers/cloudflare/index.d.mts +11 -0
  28. package/dist/providers/cloudflare/index.d.ts +11 -0
  29. package/dist/providers/cloudflare/index.js +743 -0
  30. package/dist/providers/cloudflare/index.mjs +741 -0
  31. package/dist/providers/fireworks/index.d.mts +3 -3
  32. package/dist/providers/fireworks/index.d.ts +3 -3
  33. package/dist/providers/fireworks/index.js +108 -59
  34. package/dist/providers/fireworks/index.mjs +108 -59
  35. package/dist/providers/google/index.d.mts +3 -3
  36. package/dist/providers/google/index.d.ts +3 -3
  37. package/dist/providers/google/index.js +108 -59
  38. package/dist/providers/google/index.mjs +108 -59
  39. package/dist/providers/ollama/index.d.mts +4 -4
  40. package/dist/providers/ollama/index.d.ts +4 -4
  41. package/dist/providers/openai/index.d.mts +38 -6
  42. package/dist/providers/openai/index.d.ts +38 -6
  43. package/dist/providers/openai/index.js +1378 -84
  44. package/dist/providers/openai/index.mjs +1376 -85
  45. package/dist/providers/openrouter/index.d.mts +21 -4
  46. package/dist/providers/openrouter/index.d.ts +21 -4
  47. package/dist/providers/openrouter/index.js +967 -130
  48. package/dist/providers/openrouter/index.mjs +967 -131
  49. package/dist/providers/togetherai/index.d.mts +3 -3
  50. package/dist/providers/togetherai/index.d.ts +3 -3
  51. package/dist/providers/togetherai/index.js +108 -59
  52. package/dist/providers/togetherai/index.mjs +108 -59
  53. package/dist/providers/typesafe/index.d.mts +8 -0
  54. package/dist/providers/typesafe/index.d.ts +8 -0
  55. package/dist/providers/typesafe/index.js +735 -0
  56. package/dist/providers/typesafe/index.mjs +733 -0
  57. package/dist/providers/xai/index.d.mts +3 -3
  58. package/dist/providers/xai/index.d.ts +3 -3
  59. package/dist/providers/xai/index.js +108 -59
  60. package/dist/providers/xai/index.mjs +108 -59
  61. package/dist/{types-DCFqkJAy.d.ts → types-B0y6VZSQ.d.ts} +1 -1
  62. package/dist/{types-DHQEMFHA.d.mts → types-BXQMtaCX.d.ts} +17 -3
  63. package/dist/{types-C3RgRbEC.d.mts → types-BY6BVhFg.d.mts} +1 -1
  64. package/dist/{types-Dikj3En4.d.ts → types-C7_qVSSd.d.mts} +17 -3
  65. package/dist/{types-Dg1Bcg1k.d.mts → types-D7lzMMLu.d.mts} +13 -1
  66. package/dist/{types-Dg1Bcg1k.d.ts → types-D7lzMMLu.d.ts} +13 -1
  67. package/dist/yourgpt/index.d.mts +1 -1
  68. package/dist/yourgpt/index.d.ts +1 -1
  69. package/docs/decisions.md +174 -0
  70. package/docs/media.md +201 -0
  71. package/docs/multimodal-and-audio.md +9 -2
  72. package/package.json +34 -12
  73. package/dist/audio-BBSwnjo8.d.mts +0 -92
  74. package/dist/audio-BBSwnjo8.d.ts +0 -92
@@ -1,7 +1,7 @@
1
- import { L as LanguageModel } from '../../types-Dg1Bcg1k.mjs';
2
- import { X as XAIProviderConfig, A as AIProvider } from '../../types-DHQEMFHA.mjs';
1
+ import { L as LanguageModel } from '../../types-D7lzMMLu.mjs';
2
+ import { X as XAIProviderConfig, A as AIProvider } from '../../types-C7_qVSSd.mjs';
3
3
  import 'zod';
4
- import '../../base-BICaQaRS.mjs';
4
+ import '../../base-DySbTP8C.mjs';
5
5
 
6
6
  /**
7
7
  * xAI Provider - Modern Pattern
@@ -1,7 +1,7 @@
1
- import { L as LanguageModel } from '../../types-Dg1Bcg1k.js';
2
- import { X as XAIProviderConfig, A as AIProvider } from '../../types-Dikj3En4.js';
1
+ import { L as LanguageModel } from '../../types-D7lzMMLu.js';
2
+ import { X as XAIProviderConfig, A as AIProvider } from '../../types-BXQMtaCX.js';
3
3
  import 'zod';
4
- import '../../base-CpRPB8u8.js';
4
+ import '../../base-6LzczuCg.js';
5
5
 
6
6
  /**
7
7
  * xAI Provider - Modern Pattern
@@ -113,6 +113,19 @@ function capabilities(model) {
113
113
  const supportsNone = major === 5 && minor >= 1 && !chat || /^gpt-6-(?:sol|luna)(?:-\d{4}-\d{2}-\d{2})?$/i.test(model);
114
114
  return { major, minor, reasoning, supportsNone };
115
115
  }
116
+ function filterOpenAIResponseInclude(model, include, options = {}) {
117
+ const c = capabilities(model);
118
+ let result = include;
119
+ if (options.parameterPolicy !== "passthrough" && c.reasoning && !(options.reasoningEffort === "none" && c.supportsNone) && include.includes("message.output_text.logprobs")) {
120
+ result = include.filter(
121
+ (value) => value !== "message.output_text.logprobs"
122
+ );
123
+ (options.onWarning ?? console.warn)(
124
+ `[llm-sdk] ${model}: omitted message.output_text.logprobs because reasoning is enabled.`
125
+ );
126
+ }
127
+ return result.length ? result : void 0;
128
+ }
116
129
  function requiresOpenAIResponses(model, baseUrl, options = {}) {
117
130
  if (options.parameterPolicy === "passthrough") return false;
118
131
  const c = capabilities(model);
@@ -274,6 +287,7 @@ function toOpenAIResponseFormat(rf) {
274
287
  };
275
288
  }
276
289
  function toOpenAIResponsesTextFormat(rf) {
290
+ if (rf?.type === "json_object") return { type: "json_object" };
277
291
  if (!rf || rf.type !== "json_schema") return void 0;
278
292
  return {
279
293
  type: "json_schema",
@@ -617,6 +631,63 @@ function formatMessagesForXAI(messages) {
617
631
  });
618
632
  }
619
633
 
634
+ // src/core/provider-error.ts
635
+ function invalidProviderResponse(message) {
636
+ return Object.assign(new Error(message), {
637
+ name: "InvalidProviderResponseError",
638
+ status: 502,
639
+ code: "INVALID_PROVIDER_RESPONSE"
640
+ });
641
+ }
642
+ function providerErrorEvent(error, code) {
643
+ const details = error ?? {};
644
+ const event = {
645
+ type: "error",
646
+ message: error instanceof Error ? error.message : String(error),
647
+ code,
648
+ ...typeof details.status === "number" ? { status: details.status } : {},
649
+ ...typeof details.code === "string" ? { providerCode: details.code } : {},
650
+ ...typeof details.param === "string" ? { param: details.param } : {},
651
+ ...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
652
+ };
653
+ Object.defineProperty(event, "cause", { value: error, enumerable: false });
654
+ return event;
655
+ }
656
+ function throwIfAborted(signal) {
657
+ if (!signal?.aborted) return;
658
+ const error = new Error("The operation was aborted");
659
+ error.name = "AbortError";
660
+ throw error;
661
+ }
662
+
663
+ // src/core/tool-validation.ts
664
+ function parseToolArguments(value) {
665
+ let args = value;
666
+ if (typeof value === "string") {
667
+ try {
668
+ args = JSON.parse(value || "{}");
669
+ } catch {
670
+ throw invalidProviderResponse("Tool arguments are not valid JSON");
671
+ }
672
+ }
673
+ if (args === null || typeof args !== "object" || Array.isArray(args))
674
+ throw invalidProviderResponse("Tool arguments must be a JSON object");
675
+ return args;
676
+ }
677
+ function validateToolCalls(calls) {
678
+ const ids = /* @__PURE__ */ new Set();
679
+ for (const call of calls) {
680
+ if (!call || typeof call.id !== "string" || !call.id || typeof call.name !== "string" || !call.name || ids.has(call.id))
681
+ throw invalidProviderResponse(
682
+ "Tool calls have missing or duplicate identities"
683
+ );
684
+ ids.add(call.id);
685
+ if (typeof call.args === "string")
686
+ throw invalidProviderResponse("Parsed tool arguments must be an object");
687
+ parseToolArguments(call.args);
688
+ }
689
+ }
690
+
620
691
  // src/core/openai-responses.ts
621
692
  function resolveOpenAITransport(defaults, overrides) {
622
693
  return {
@@ -723,35 +794,6 @@ function getResponseReplay(metadata) {
723
794
  return responseReplayMetadata(metadata)?.openai?.response?.output;
724
795
  }
725
796
 
726
- // src/core/provider-error.ts
727
- function invalidProviderResponse(message) {
728
- return Object.assign(new Error(message), {
729
- name: "InvalidProviderResponseError",
730
- status: 502,
731
- code: "INVALID_PROVIDER_RESPONSE"
732
- });
733
- }
734
- function providerErrorEvent(error, code) {
735
- const details = error ?? {};
736
- const event = {
737
- type: "error",
738
- message: error instanceof Error ? error.message : String(error),
739
- code,
740
- ...typeof details.status === "number" ? { status: details.status } : {},
741
- ...typeof details.code === "string" ? { providerCode: details.code } : {},
742
- ...typeof details.param === "string" ? { param: details.param } : {},
743
- ...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
744
- };
745
- Object.defineProperty(event, "cause", { value: error, enumerable: false });
746
- return event;
747
- }
748
- function throwIfAborted(signal) {
749
- if (!signal?.aborted) return;
750
- const error = new Error("The operation was aborted");
751
- error.name = "AbortError";
752
- throw error;
753
- }
754
-
755
797
  // src/core/utils.ts
756
798
  function generateId(prefix = "id") {
757
799
  return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
@@ -759,9 +801,6 @@ function generateId(prefix = "id") {
759
801
  function generateMessageId() {
760
802
  return generateId("msg");
761
803
  }
762
- function generateToolCallId() {
763
- return generateId("call");
764
- }
765
804
 
766
805
  // src/adapters/openai.ts
767
806
  var OpenAIAdapter = class _OpenAIAdapter {
@@ -785,6 +824,8 @@ var OpenAIAdapter = class _OpenAIAdapter {
785
824
  apiKey: this.config.apiKey,
786
825
  baseURL: this.config.baseUrl,
787
826
  organization: this.config.organization,
827
+ project: this.config.project,
828
+ timeout: this.config.timeout,
788
829
  defaultHeaders: this.config.headers
789
830
  });
790
831
  }
@@ -1066,6 +1107,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
1066
1107
  request.config?.responseFormat
1067
1108
  );
1068
1109
  const modelIdForPayload = request.config?.model || this.model;
1110
+ const include = filterOpenAIResponseInclude(
1111
+ modelIdForPayload,
1112
+ [
1113
+ .../* @__PURE__ */ new Set([
1114
+ ...options?.include ?? [],
1115
+ ...options?.store === false ? ["reasoning.encrypted_content"] : []
1116
+ ])
1117
+ ],
1118
+ this.parameterOptions(request)
1119
+ );
1069
1120
  const payload = {
1070
1121
  model: modelIdForPayload,
1071
1122
  instructions: request.systemPrompt,
@@ -1089,14 +1140,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
1089
1140
  ...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {},
1090
1141
  ...options?.promptCacheOptions !== void 0 ? { prompt_cache_options: options.promptCacheOptions } : {},
1091
1142
  ...options?.promptCacheRetention !== void 0 ? { prompt_cache_retention: options.promptCacheRetention } : {},
1092
- ...options?.store === false || options?.include ? {
1093
- include: [
1094
- .../* @__PURE__ */ new Set([
1095
- ...options?.include ?? [],
1096
- ...options?.store === false ? ["reasoning.encrypted_content"] : []
1097
- ])
1098
- ]
1099
- } : {},
1143
+ ...include ? { include } : {},
1100
1144
  ...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
1101
1145
  stream
1102
1146
  };
@@ -1467,15 +1511,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
1467
1511
  }
1468
1512
  throwIfAborted(request.signal);
1469
1513
  if (!finishReason)
1470
- throw new Error("OpenAI stream ended without a finish reason");
1514
+ throw invalidProviderResponse(
1515
+ "OpenAI stream ended without a finish reason"
1516
+ );
1471
1517
  if (toolCalls.size && !["tool_calls", "function_call"].includes(finishReason)) {
1472
- throw new Error("OpenAI stream ended with incomplete tool calls");
1473
- }
1474
- for (const call of toolCalls.values()) {
1475
- if (!call.id || !call.name)
1476
- throw new Error("OpenAI stream contains an incomplete tool call");
1477
- JSON.parse(call.arguments || "{}");
1518
+ throw invalidProviderResponse(
1519
+ "OpenAI stream ended with incomplete tool calls"
1520
+ );
1478
1521
  }
1522
+ validateToolCalls(
1523
+ [...toolCalls.values()].map((call) => ({
1524
+ ...call,
1525
+ args: parseToolArguments(call.arguments)
1526
+ }))
1527
+ );
1479
1528
  for (const call of toolCalls.values()) {
1480
1529
  yield {
1481
1530
  type: "action:start",
@@ -1559,20 +1608,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
1559
1608
  logProviderPayload("openai", "response payload", response, request.debug);
1560
1609
  const choice = response.choices?.[0];
1561
1610
  const message = choice?.message;
1611
+ const toolCalls = (message?.tool_calls ?? []).map((toolCall) => ({
1612
+ id: toolCall.id,
1613
+ name: toolCall.function?.name,
1614
+ args: parseToolArguments(toolCall.function?.arguments ?? "{}"),
1615
+ ...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
1616
+ }));
1617
+ validateToolCalls(toolCalls);
1618
+ if (toolCalls.length && choice?.finish_reason && !["tool_calls", "function_call"].includes(choice.finish_reason))
1619
+ throw invalidProviderResponse(
1620
+ "OpenAI response ended with incomplete tool calls"
1621
+ );
1562
1622
  return {
1563
1623
  content: message?.content ?? "",
1564
- toolCalls: message?.tool_calls?.map((toolCall) => ({
1565
- id: toolCall.id ?? generateToolCallId(),
1566
- name: toolCall.function?.name ?? "",
1567
- args: (() => {
1568
- try {
1569
- return JSON.parse(toolCall.function?.arguments ?? "{}");
1570
- } catch {
1571
- return {};
1572
- }
1573
- })(),
1574
- ...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
1575
- })) ?? [],
1624
+ toolCalls,
1576
1625
  usage: response.usage ? {
1577
1626
  promptTokens: response.usage.prompt_tokens,
1578
1627
  completionTokens: response.usage.completion_tokens,
@@ -111,6 +111,19 @@ function capabilities(model) {
111
111
  const supportsNone = major === 5 && minor >= 1 && !chat || /^gpt-6-(?:sol|luna)(?:-\d{4}-\d{2}-\d{2})?$/i.test(model);
112
112
  return { major, minor, reasoning, supportsNone };
113
113
  }
114
+ function filterOpenAIResponseInclude(model, include, options = {}) {
115
+ const c = capabilities(model);
116
+ let result = include;
117
+ if (options.parameterPolicy !== "passthrough" && c.reasoning && !(options.reasoningEffort === "none" && c.supportsNone) && include.includes("message.output_text.logprobs")) {
118
+ result = include.filter(
119
+ (value) => value !== "message.output_text.logprobs"
120
+ );
121
+ (options.onWarning ?? console.warn)(
122
+ `[llm-sdk] ${model}: omitted message.output_text.logprobs because reasoning is enabled.`
123
+ );
124
+ }
125
+ return result.length ? result : void 0;
126
+ }
114
127
  function requiresOpenAIResponses(model, baseUrl, options = {}) {
115
128
  if (options.parameterPolicy === "passthrough") return false;
116
129
  const c = capabilities(model);
@@ -272,6 +285,7 @@ function toOpenAIResponseFormat(rf) {
272
285
  };
273
286
  }
274
287
  function toOpenAIResponsesTextFormat(rf) {
288
+ if (rf?.type === "json_object") return { type: "json_object" };
275
289
  if (!rf || rf.type !== "json_schema") return void 0;
276
290
  return {
277
291
  type: "json_schema",
@@ -615,6 +629,63 @@ function formatMessagesForXAI(messages) {
615
629
  });
616
630
  }
617
631
 
632
+ // src/core/provider-error.ts
633
+ function invalidProviderResponse(message) {
634
+ return Object.assign(new Error(message), {
635
+ name: "InvalidProviderResponseError",
636
+ status: 502,
637
+ code: "INVALID_PROVIDER_RESPONSE"
638
+ });
639
+ }
640
+ function providerErrorEvent(error, code) {
641
+ const details = error ?? {};
642
+ const event = {
643
+ type: "error",
644
+ message: error instanceof Error ? error.message : String(error),
645
+ code,
646
+ ...typeof details.status === "number" ? { status: details.status } : {},
647
+ ...typeof details.code === "string" ? { providerCode: details.code } : {},
648
+ ...typeof details.param === "string" ? { param: details.param } : {},
649
+ ...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
650
+ };
651
+ Object.defineProperty(event, "cause", { value: error, enumerable: false });
652
+ return event;
653
+ }
654
+ function throwIfAborted(signal) {
655
+ if (!signal?.aborted) return;
656
+ const error = new Error("The operation was aborted");
657
+ error.name = "AbortError";
658
+ throw error;
659
+ }
660
+
661
+ // src/core/tool-validation.ts
662
+ function parseToolArguments(value) {
663
+ let args = value;
664
+ if (typeof value === "string") {
665
+ try {
666
+ args = JSON.parse(value || "{}");
667
+ } catch {
668
+ throw invalidProviderResponse("Tool arguments are not valid JSON");
669
+ }
670
+ }
671
+ if (args === null || typeof args !== "object" || Array.isArray(args))
672
+ throw invalidProviderResponse("Tool arguments must be a JSON object");
673
+ return args;
674
+ }
675
+ function validateToolCalls(calls) {
676
+ const ids = /* @__PURE__ */ new Set();
677
+ for (const call of calls) {
678
+ if (!call || typeof call.id !== "string" || !call.id || typeof call.name !== "string" || !call.name || ids.has(call.id))
679
+ throw invalidProviderResponse(
680
+ "Tool calls have missing or duplicate identities"
681
+ );
682
+ ids.add(call.id);
683
+ if (typeof call.args === "string")
684
+ throw invalidProviderResponse("Parsed tool arguments must be an object");
685
+ parseToolArguments(call.args);
686
+ }
687
+ }
688
+
618
689
  // src/core/openai-responses.ts
619
690
  function resolveOpenAITransport(defaults, overrides) {
620
691
  return {
@@ -721,35 +792,6 @@ function getResponseReplay(metadata) {
721
792
  return responseReplayMetadata(metadata)?.openai?.response?.output;
722
793
  }
723
794
 
724
- // src/core/provider-error.ts
725
- function invalidProviderResponse(message) {
726
- return Object.assign(new Error(message), {
727
- name: "InvalidProviderResponseError",
728
- status: 502,
729
- code: "INVALID_PROVIDER_RESPONSE"
730
- });
731
- }
732
- function providerErrorEvent(error, code) {
733
- const details = error ?? {};
734
- const event = {
735
- type: "error",
736
- message: error instanceof Error ? error.message : String(error),
737
- code,
738
- ...typeof details.status === "number" ? { status: details.status } : {},
739
- ...typeof details.code === "string" ? { providerCode: details.code } : {},
740
- ...typeof details.param === "string" ? { param: details.param } : {},
741
- ...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
742
- };
743
- Object.defineProperty(event, "cause", { value: error, enumerable: false });
744
- return event;
745
- }
746
- function throwIfAborted(signal) {
747
- if (!signal?.aborted) return;
748
- const error = new Error("The operation was aborted");
749
- error.name = "AbortError";
750
- throw error;
751
- }
752
-
753
795
  // src/core/utils.ts
754
796
  function generateId(prefix = "id") {
755
797
  return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
@@ -757,9 +799,6 @@ function generateId(prefix = "id") {
757
799
  function generateMessageId() {
758
800
  return generateId("msg");
759
801
  }
760
- function generateToolCallId() {
761
- return generateId("call");
762
- }
763
802
 
764
803
  // src/adapters/openai.ts
765
804
  var OpenAIAdapter = class _OpenAIAdapter {
@@ -783,6 +822,8 @@ var OpenAIAdapter = class _OpenAIAdapter {
783
822
  apiKey: this.config.apiKey,
784
823
  baseURL: this.config.baseUrl,
785
824
  organization: this.config.organization,
825
+ project: this.config.project,
826
+ timeout: this.config.timeout,
786
827
  defaultHeaders: this.config.headers
787
828
  });
788
829
  }
@@ -1064,6 +1105,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
1064
1105
  request.config?.responseFormat
1065
1106
  );
1066
1107
  const modelIdForPayload = request.config?.model || this.model;
1108
+ const include = filterOpenAIResponseInclude(
1109
+ modelIdForPayload,
1110
+ [
1111
+ .../* @__PURE__ */ new Set([
1112
+ ...options?.include ?? [],
1113
+ ...options?.store === false ? ["reasoning.encrypted_content"] : []
1114
+ ])
1115
+ ],
1116
+ this.parameterOptions(request)
1117
+ );
1067
1118
  const payload = {
1068
1119
  model: modelIdForPayload,
1069
1120
  instructions: request.systemPrompt,
@@ -1087,14 +1138,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
1087
1138
  ...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {},
1088
1139
  ...options?.promptCacheOptions !== void 0 ? { prompt_cache_options: options.promptCacheOptions } : {},
1089
1140
  ...options?.promptCacheRetention !== void 0 ? { prompt_cache_retention: options.promptCacheRetention } : {},
1090
- ...options?.store === false || options?.include ? {
1091
- include: [
1092
- .../* @__PURE__ */ new Set([
1093
- ...options?.include ?? [],
1094
- ...options?.store === false ? ["reasoning.encrypted_content"] : []
1095
- ])
1096
- ]
1097
- } : {},
1141
+ ...include ? { include } : {},
1098
1142
  ...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
1099
1143
  stream
1100
1144
  };
@@ -1465,15 +1509,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
1465
1509
  }
1466
1510
  throwIfAborted(request.signal);
1467
1511
  if (!finishReason)
1468
- throw new Error("OpenAI stream ended without a finish reason");
1512
+ throw invalidProviderResponse(
1513
+ "OpenAI stream ended without a finish reason"
1514
+ );
1469
1515
  if (toolCalls.size && !["tool_calls", "function_call"].includes(finishReason)) {
1470
- throw new Error("OpenAI stream ended with incomplete tool calls");
1471
- }
1472
- for (const call of toolCalls.values()) {
1473
- if (!call.id || !call.name)
1474
- throw new Error("OpenAI stream contains an incomplete tool call");
1475
- JSON.parse(call.arguments || "{}");
1516
+ throw invalidProviderResponse(
1517
+ "OpenAI stream ended with incomplete tool calls"
1518
+ );
1476
1519
  }
1520
+ validateToolCalls(
1521
+ [...toolCalls.values()].map((call) => ({
1522
+ ...call,
1523
+ args: parseToolArguments(call.arguments)
1524
+ }))
1525
+ );
1477
1526
  for (const call of toolCalls.values()) {
1478
1527
  yield {
1479
1528
  type: "action:start",
@@ -1557,20 +1606,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
1557
1606
  logProviderPayload("openai", "response payload", response, request.debug);
1558
1607
  const choice = response.choices?.[0];
1559
1608
  const message = choice?.message;
1609
+ const toolCalls = (message?.tool_calls ?? []).map((toolCall) => ({
1610
+ id: toolCall.id,
1611
+ name: toolCall.function?.name,
1612
+ args: parseToolArguments(toolCall.function?.arguments ?? "{}"),
1613
+ ...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
1614
+ }));
1615
+ validateToolCalls(toolCalls);
1616
+ if (toolCalls.length && choice?.finish_reason && !["tool_calls", "function_call"].includes(choice.finish_reason))
1617
+ throw invalidProviderResponse(
1618
+ "OpenAI response ended with incomplete tool calls"
1619
+ );
1560
1620
  return {
1561
1621
  content: message?.content ?? "",
1562
- toolCalls: message?.tool_calls?.map((toolCall) => ({
1563
- id: toolCall.id ?? generateToolCallId(),
1564
- name: toolCall.function?.name ?? "",
1565
- args: (() => {
1566
- try {
1567
- return JSON.parse(toolCall.function?.arguments ?? "{}");
1568
- } catch {
1569
- return {};
1570
- }
1571
- })(),
1572
- ...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
1573
- })) ?? [],
1622
+ toolCalls,
1574
1623
  usage: response.usage ? {
1575
1624
  promptTokens: response.usage.prompt_tokens,
1576
1625
  completionTokens: response.usage.completion_tokens,
@@ -1,4 +1,4 @@
1
- import { L as LLMAdapter } from './base-CpRPB8u8.js';
1
+ import { L as LLMAdapter } from './base-6LzczuCg.js';
2
2
 
3
3
  /**
4
4
  * Fallback Chain & Routing Strategy Types
@@ -1,5 +1,17 @@
1
- import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-Dg1Bcg1k.mjs';
2
- import { L as LLMAdapter } from './base-BICaQaRS.mjs';
1
+ import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-D7lzMMLu.js';
2
+ import { L as LLMAdapter } from './base-6LzczuCg.js';
3
+
4
+ type AnthropicThinking = {
5
+ type: "enabled";
6
+ budgetTokens?: number;
7
+ } | {
8
+ type: "adaptive";
9
+ display?: "summarized" | "omitted";
10
+ } | {
11
+ type: "disabled";
12
+ } | {
13
+ type: "between_tools";
14
+ };
3
15
 
4
16
  /**
5
17
  * Provider formatter interface
@@ -263,6 +275,8 @@ interface OpenAIProviderConfig extends BaseProviderConfig, OpenAIParameterOption
263
275
  * Anthropic provider configuration
264
276
  */
265
277
  interface AnthropicProviderConfig extends BaseProviderConfig {
278
+ thinking?: AnthropicThinking;
279
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
266
280
  /** Extended thinking budget in tokens (minimum 1024) */
267
281
  thinkingBudget?: number;
268
282
  /** Enable prompt caching */
@@ -345,4 +359,4 @@ interface OllamaProviderConfig extends BaseProviderConfig {
345
359
  options?: OllamaModelOptions;
346
360
  }
347
361
 
348
- export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n };
362
+ export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n, AnthropicThinking as o };
@@ -1,4 +1,4 @@
1
- import { L as LLMAdapter } from './base-BICaQaRS.mjs';
1
+ import { L as LLMAdapter } from './base-DySbTP8C.mjs';
2
2
 
3
3
  /**
4
4
  * Fallback Chain & Routing Strategy Types
@@ -1,5 +1,17 @@
1
- import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-Dg1Bcg1k.js';
2
- import { L as LLMAdapter } from './base-CpRPB8u8.js';
1
+ import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-D7lzMMLu.mjs';
2
+ import { L as LLMAdapter } from './base-DySbTP8C.mjs';
3
+
4
+ type AnthropicThinking = {
5
+ type: "enabled";
6
+ budgetTokens?: number;
7
+ } | {
8
+ type: "adaptive";
9
+ display?: "summarized" | "omitted";
10
+ } | {
11
+ type: "disabled";
12
+ } | {
13
+ type: "between_tools";
14
+ };
3
15
 
4
16
  /**
5
17
  * Provider formatter interface
@@ -263,6 +275,8 @@ interface OpenAIProviderConfig extends BaseProviderConfig, OpenAIParameterOption
263
275
  * Anthropic provider configuration
264
276
  */
265
277
  interface AnthropicProviderConfig extends BaseProviderConfig {
278
+ thinking?: AnthropicThinking;
279
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
266
280
  /** Extended thinking budget in tokens (minimum 1024) */
267
281
  thinkingBudget?: number;
268
282
  /** Enable prompt caching */
@@ -345,4 +359,4 @@ interface OllamaProviderConfig extends BaseProviderConfig {
345
359
  options?: OllamaModelOptions;
346
360
  }
347
361
 
348
- export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n };
362
+ export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n, AnthropicThinking as o };
@@ -812,6 +812,8 @@ interface DoGenerateParams {
812
812
  * Result from model.doGenerate()
813
813
  */
814
814
  interface DoGenerateResult {
815
+ /** Provider-supplied reasoning text or summary, when available. */
816
+ reasoningText?: string;
815
817
  /** Provider state retained for continuation and inspection. */
816
818
  providerMetadata?: ProviderMetadata;
817
819
  /** Generated text content */
@@ -840,7 +842,10 @@ interface TokenUsage {
840
842
  /**
841
843
  * Stream chunk from model.doStream()
842
844
  */
843
- type StreamChunk = TextDeltaChunk | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
845
+ type StreamChunk = TextDeltaChunk | {
846
+ type: "reasoning-delta";
847
+ text: string;
848
+ } | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
844
849
  interface TextDeltaChunk {
845
850
  type: "text-delta";
846
851
  text: string;
@@ -899,6 +904,8 @@ interface GenerateTextParams {
899
904
  * Result from generateText()
900
905
  */
901
906
  interface GenerateTextResult {
907
+ /** Provider-supplied reasoning text or summary, when available. */
908
+ reasoningText?: string;
902
909
  /** Provider state retained for continuation and inspection. */
903
910
  providerMetadata?: ProviderMetadata;
904
911
  /** Final text output */
@@ -922,6 +929,8 @@ interface GenerateTextResult {
922
929
  * A single step in the generation process
923
930
  */
924
931
  interface GenerateStep {
932
+ /** Provider-supplied reasoning text or summary, when available. */
933
+ reasoningText?: string;
925
934
  /** Provider state retained for continuation and inspection. */
926
935
  providerMetadata?: ProviderMetadata;
927
936
  /** Text generated in this step */
@@ -967,6 +976,9 @@ interface StreamTextResult {
967
976
  * Stream part for fullStream
968
977
  */
969
978
  type StreamPart = {
979
+ type: "reasoning-delta";
980
+ text: string;
981
+ } | {
970
982
  type: "text-delta";
971
983
  text: string;
972
984
  } | {
@@ -812,6 +812,8 @@ interface DoGenerateParams {
812
812
  * Result from model.doGenerate()
813
813
  */
814
814
  interface DoGenerateResult {
815
+ /** Provider-supplied reasoning text or summary, when available. */
816
+ reasoningText?: string;
815
817
  /** Provider state retained for continuation and inspection. */
816
818
  providerMetadata?: ProviderMetadata;
817
819
  /** Generated text content */
@@ -840,7 +842,10 @@ interface TokenUsage {
840
842
  /**
841
843
  * Stream chunk from model.doStream()
842
844
  */
843
- type StreamChunk = TextDeltaChunk | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
845
+ type StreamChunk = TextDeltaChunk | {
846
+ type: "reasoning-delta";
847
+ text: string;
848
+ } | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
844
849
  interface TextDeltaChunk {
845
850
  type: "text-delta";
846
851
  text: string;
@@ -899,6 +904,8 @@ interface GenerateTextParams {
899
904
  * Result from generateText()
900
905
  */
901
906
  interface GenerateTextResult {
907
+ /** Provider-supplied reasoning text or summary, when available. */
908
+ reasoningText?: string;
902
909
  /** Provider state retained for continuation and inspection. */
903
910
  providerMetadata?: ProviderMetadata;
904
911
  /** Final text output */
@@ -922,6 +929,8 @@ interface GenerateTextResult {
922
929
  * A single step in the generation process
923
930
  */
924
931
  interface GenerateStep {
932
+ /** Provider-supplied reasoning text or summary, when available. */
933
+ reasoningText?: string;
925
934
  /** Provider state retained for continuation and inspection. */
926
935
  providerMetadata?: ProviderMetadata;
927
936
  /** Text generated in this step */
@@ -967,6 +976,9 @@ interface StreamTextResult {
967
976
  * Stream part for fullStream
968
977
  */
969
978
  type StreamPart = {
979
+ type: "reasoning-delta";
980
+ text: string;
981
+ } | {
970
982
  type: "text-delta";
971
983
  text: string;
972
984
  } | {