@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.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 (59) hide show
  1. package/dist/adapters/index.d.mts +4 -4
  2. package/dist/adapters/index.d.ts +4 -4
  3. package/dist/adapters/index.js +156 -13
  4. package/dist/adapters/index.mjs +156 -13
  5. package/dist/base-C58Dsr9p.d.ts +259 -0
  6. package/dist/base-tNgbBaSo.d.mts +259 -0
  7. package/dist/fallback/index.d.mts +4 -4
  8. package/dist/fallback/index.d.ts +4 -4
  9. package/dist/index.d.mts +8 -7
  10. package/dist/index.d.ts +8 -7
  11. package/dist/index.js +12 -0
  12. package/dist/index.mjs +12 -0
  13. package/dist/providers/anthropic/index.d.mts +3 -3
  14. package/dist/providers/anthropic/index.d.ts +3 -3
  15. package/dist/providers/anthropic/index.js +271 -195
  16. package/dist/providers/anthropic/index.mjs +271 -195
  17. package/dist/providers/azure/index.d.mts +3 -3
  18. package/dist/providers/azure/index.d.ts +3 -3
  19. package/dist/providers/azure/index.js +49 -1
  20. package/dist/providers/azure/index.mjs +49 -1
  21. package/dist/providers/fireworks/index.d.mts +1 -1
  22. package/dist/providers/fireworks/index.d.ts +1 -1
  23. package/dist/providers/fireworks/index.js +56 -0
  24. package/dist/providers/fireworks/index.mjs +56 -0
  25. package/dist/providers/google/index.d.mts +3 -3
  26. package/dist/providers/google/index.d.ts +3 -3
  27. package/dist/providers/google/index.js +252 -205
  28. package/dist/providers/google/index.mjs +252 -205
  29. package/dist/providers/ollama/index.d.mts +4 -4
  30. package/dist/providers/ollama/index.d.ts +4 -4
  31. package/dist/providers/ollama/index.js +10 -2
  32. package/dist/providers/ollama/index.mjs +10 -2
  33. package/dist/providers/openai/index.d.mts +3 -3
  34. package/dist/providers/openai/index.d.ts +3 -3
  35. package/dist/providers/openai/index.js +267 -214
  36. package/dist/providers/openai/index.mjs +267 -214
  37. package/dist/providers/openrouter/index.d.mts +3 -3
  38. package/dist/providers/openrouter/index.d.ts +3 -3
  39. package/dist/providers/openrouter/index.js +257 -204
  40. package/dist/providers/openrouter/index.mjs +257 -204
  41. package/dist/providers/togetherai/index.d.mts +3 -3
  42. package/dist/providers/togetherai/index.d.ts +3 -3
  43. package/dist/providers/togetherai/index.js +257 -204
  44. package/dist/providers/togetherai/index.mjs +257 -204
  45. package/dist/providers/xai/index.d.mts +3 -3
  46. package/dist/providers/xai/index.d.ts +3 -3
  47. package/dist/providers/xai/index.js +256 -208
  48. package/dist/providers/xai/index.mjs +256 -208
  49. package/dist/{types-D4YfrQJR.d.mts → types-B6dhnguR.d.mts} +1 -1
  50. package/dist/{types-DRqxMIjF.d.mts → types-BQ31QIsA.d.ts} +2 -1
  51. package/dist/{types-BctsnC3g.d.ts → types-BSSiJW2o.d.mts} +2 -1
  52. package/dist/{base-D-U61JaB.d.mts → types-BkQCSiIt.d.mts} +388 -213
  53. package/dist/{base-iGi9Va6Z.d.ts → types-BkQCSiIt.d.ts} +388 -213
  54. package/dist/{types-38yolWJn.d.ts → types-CCxPmkmK.d.ts} +1 -1
  55. package/dist/yourgpt/index.d.mts +1 -1
  56. package/dist/yourgpt/index.d.ts +1 -1
  57. package/package.json +1 -1
  58. package/dist/types-CR8mi9I0.d.mts +0 -417
  59. package/dist/types-CR8mi9I0.d.ts +0 -417
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter, W as WebSearchConfig, C as ChatCompletionRequest, S as StreamEvent, o as CompletionResult } from '../base-D-U61JaB.mjs';
2
- export { e as AdapterFactory, B as AnthropicContentBlock, E as OpenAIContentBlock, y as attachmentToAnthropicDocument, x as attachmentToAnthropicImage, z as attachmentToOpenAIImage, p as formatMessages, r as formatMessagesForAnthropic, s as formatMessagesForOpenAI, q as formatTools, v as hasImageAttachments, w as hasMediaAttachments, t as messageToAnthropicContent, u as messageToOpenAIContent } from '../base-D-U61JaB.mjs';
3
- import { d as OllamaModelOptions } from '../types-DRqxMIjF.mjs';
4
- import '../types-CR8mi9I0.mjs';
1
+ import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-tNgbBaSo.mjs';
2
+ export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-tNgbBaSo.mjs';
3
+ import { W as WebSearchConfig, g as StreamEvent } from '../types-BkQCSiIt.mjs';
4
+ import { d as OllamaModelOptions } from '../types-BSSiJW2o.mjs';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter, W as WebSearchConfig, C as ChatCompletionRequest, S as StreamEvent, o as CompletionResult } from '../base-iGi9Va6Z.js';
2
- export { e as AdapterFactory, B as AnthropicContentBlock, E as OpenAIContentBlock, y as attachmentToAnthropicDocument, x as attachmentToAnthropicImage, z as attachmentToOpenAIImage, p as formatMessages, r as formatMessagesForAnthropic, s as formatMessagesForOpenAI, q as formatTools, v as hasImageAttachments, w as hasMediaAttachments, t as messageToAnthropicContent, u as messageToOpenAIContent } from '../base-iGi9Va6Z.js';
3
- import { d as OllamaModelOptions } from '../types-BctsnC3g.js';
4
- import '../types-CR8mi9I0.js';
1
+ import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-C58Dsr9p.js';
2
+ export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-C58Dsr9p.js';
3
+ import { W as WebSearchConfig, g as StreamEvent } from '../types-BkQCSiIt.js';
4
+ import { d as OllamaModelOptions } from '../types-BQ31QIsA.js';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -114,6 +114,109 @@ function normalizeObjectJsonSchema(schema) {
114
114
  }
115
115
  return normalized;
116
116
  }
117
+ function isOpenAIReasoningModel(modelId) {
118
+ if (!modelId) return false;
119
+ return /^(o1|o3|o4|gpt-5)/i.test(modelId);
120
+ }
121
+ function buildOpenAITokenParams(modelId, maxTokens, temperature) {
122
+ if (isOpenAIReasoningModel(modelId)) {
123
+ return { max_completion_tokens: maxTokens };
124
+ }
125
+ return { max_tokens: maxTokens, temperature };
126
+ }
127
+ function stripSchemaKeys(schema, keysToDrop, options = {}) {
128
+ if (Array.isArray(schema)) {
129
+ return schema.map((item) => stripSchemaKeys(item, keysToDrop, options));
130
+ }
131
+ if (!schema || typeof schema !== "object") return schema;
132
+ const out = {};
133
+ for (const [key, value] of Object.entries(
134
+ schema
135
+ )) {
136
+ if (keysToDrop.has(key)) continue;
137
+ const renamed = options.renameKeys?.[key] ?? key;
138
+ out[renamed] = stripSchemaKeys(value, keysToDrop, options);
139
+ }
140
+ if (options.forceAdditionalPropertiesFalse && out.type === "object") {
141
+ out.additionalProperties = false;
142
+ }
143
+ return out;
144
+ }
145
+ function toOpenAIResponseFormat(rf) {
146
+ if (!rf) return void 0;
147
+ if (rf.type === "json_object") return { type: "json_object" };
148
+ return {
149
+ type: "json_schema",
150
+ json_schema: {
151
+ name: rf.json_schema.name,
152
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
153
+ strict: rf.json_schema.strict ?? true
154
+ }
155
+ };
156
+ }
157
+ function toOpenAIResponsesTextFormat(rf) {
158
+ if (!rf || rf.type !== "json_schema") return void 0;
159
+ return {
160
+ type: "json_schema",
161
+ name: rf.json_schema.name,
162
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
163
+ strict: rf.json_schema.strict ?? true
164
+ };
165
+ }
166
+ var ANTHROPIC_UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
167
+ "minimum",
168
+ "maximum",
169
+ "exclusiveMinimum",
170
+ "exclusiveMaximum",
171
+ "multipleOf",
172
+ "minLength",
173
+ "maxLength",
174
+ "minItems",
175
+ "maxItems",
176
+ "minProperties",
177
+ "maxProperties",
178
+ "pattern",
179
+ "$schema"
180
+ ]);
181
+ function toAnthropicOutputConfig(rf) {
182
+ if (!rf || rf.type !== "json_schema") return void 0;
183
+ const schema = stripSchemaKeys(
184
+ rf.json_schema.schema,
185
+ ANTHROPIC_UNSUPPORTED_KEYS,
186
+ {
187
+ forceAdditionalPropertiesFalse: true,
188
+ renameKeys: { oneOf: "anyOf" }
189
+ }
190
+ );
191
+ return {
192
+ format: {
193
+ type: "json_schema",
194
+ schema
195
+ }
196
+ };
197
+ }
198
+ var GEMINI_UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
199
+ "oneOf",
200
+ "anyOf",
201
+ "$ref",
202
+ "$defs",
203
+ "definitions",
204
+ "pattern",
205
+ "$schema",
206
+ "additionalProperties"
207
+ ]);
208
+ function toGeminiSchema(rf) {
209
+ if (!rf || rf.type !== "json_schema") return void 0;
210
+ return stripSchemaKeys(
211
+ rf.json_schema.schema,
212
+ GEMINI_UNSUPPORTED_KEYS
213
+ );
214
+ }
215
+ function toOllamaFormat(rf) {
216
+ if (!rf) return void 0;
217
+ if (rf.type === "json_object") return "json";
218
+ return rf.json_schema.schema;
219
+ }
117
220
  function formatTools(actions) {
118
221
  return actions.map((action) => ({
119
222
  type: "function",
@@ -484,6 +587,9 @@ var OpenAIAdapter = class _OpenAIAdapter {
484
587
  async completeWithResponses(request) {
485
588
  const client = await this.getClient();
486
589
  const openaiToolOptions = request.providerToolOptions?.openai;
590
+ const responsesTextFormat = toOpenAIResponsesTextFormat(
591
+ request.config?.responseFormat
592
+ );
487
593
  const payload = {
488
594
  model: request.config?.model || this.model,
489
595
  instructions: request.systemPrompt,
@@ -493,6 +599,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
493
599
  parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
494
600
  temperature: request.config?.temperature ?? this.config.temperature,
495
601
  max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
602
+ ...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
496
603
  stream: false
497
604
  };
498
605
  logProviderPayload("openai", "request payload", payload, request.debug);
@@ -614,14 +721,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
614
721
  name: openaiToolOptions.toolChoice.name
615
722
  }
616
723
  } : openaiToolOptions?.toolChoice;
724
+ const modelIdForPayload = request.config?.model || this.model;
617
725
  const payload = {
618
- model: request.config?.model || this.model,
726
+ model: modelIdForPayload,
619
727
  messages,
620
728
  tools: tools.length > 0 ? tools : void 0,
621
729
  tool_choice: tools.length > 0 ? toolChoice : void 0,
622
730
  parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
623
- temperature: request.config?.temperature ?? this.config.temperature,
624
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
731
+ ...buildOpenAITokenParams(
732
+ modelIdForPayload,
733
+ request.config?.maxTokens ?? this.config.maxTokens,
734
+ request.config?.temperature ?? this.config.temperature
735
+ ),
736
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
625
737
  stream: true,
626
738
  stream_options: { include_usage: true }
627
739
  };
@@ -763,14 +875,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
763
875
  name: openaiToolOptions.toolChoice.name
764
876
  }
765
877
  } : openaiToolOptions?.toolChoice;
878
+ const modelIdForCompletePayload = request.config?.model || this.model;
766
879
  const payload = {
767
- model: request.config?.model || this.model,
880
+ model: modelIdForCompletePayload,
768
881
  messages,
769
882
  tools: tools.length > 0 ? tools : void 0,
770
883
  tool_choice: tools.length > 0 ? toolChoice : void 0,
771
884
  parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
772
- temperature: request.config?.temperature ?? this.config.temperature,
773
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
885
+ ...buildOpenAITokenParams(
886
+ modelIdForCompletePayload,
887
+ request.config?.maxTokens ?? this.config.maxTokens,
888
+ request.config?.temperature ?? this.config.temperature
889
+ ),
890
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
774
891
  stream: false
775
892
  };
776
893
  logProviderPayload("openai", "request payload", payload, request.debug);
@@ -1046,7 +1163,9 @@ var AnthropicAdapter = class {
1046
1163
  * Build common request options for both streaming and non-streaming
1047
1164
  */
1048
1165
  buildRequestOptions(request) {
1049
- const systemMessage = request.systemPrompt || "";
1166
+ const responseFormat = request.config?.responseFormat;
1167
+ const jsonObjectSuffix = responseFormat?.type === "json_object" ? "\n\nRespond with a single JSON object and no other text." : "";
1168
+ const systemMessage = (request.systemPrompt || "") + jsonObjectSuffix;
1050
1169
  let messages;
1051
1170
  if (request.rawMessages && request.rawMessages.length > 0) {
1052
1171
  messages = this.convertToAnthropicMessages(request.rawMessages);
@@ -1127,6 +1246,10 @@ var AnthropicAdapter = class {
1127
1246
  if (serverToolConfiguration) {
1128
1247
  options.server_tool_configuration = serverToolConfiguration;
1129
1248
  }
1249
+ const outputConfig = toAnthropicOutputConfig(responseFormat);
1250
+ if (outputConfig) {
1251
+ options.output_config = outputConfig;
1252
+ }
1130
1253
  if (this.config.thinking?.type === "enabled") {
1131
1254
  options.thinking = {
1132
1255
  type: "enabled",
@@ -1487,12 +1610,14 @@ var OllamaAdapter = class {
1487
1610
  if (this.config.options) {
1488
1611
  Object.assign(ollamaOptions, this.config.options);
1489
1612
  }
1613
+ const ollamaFormat = toOllamaFormat(request.config?.responseFormat);
1490
1614
  const payload = {
1491
1615
  model: request.config?.model || this.model,
1492
1616
  messages,
1493
1617
  tools,
1494
1618
  stream: true,
1495
- options: ollamaOptions
1619
+ options: ollamaOptions,
1620
+ ...ollamaFormat !== void 0 ? { format: ollamaFormat } : {}
1496
1621
  };
1497
1622
  logProviderPayload("ollama", "request payload", payload, request.debug);
1498
1623
  const response = await fetch(`${this.baseUrl}/api/chat`, {
@@ -1783,6 +1908,12 @@ var GoogleAdapter = class {
1783
1908
  }
1784
1909
  const messageId = generateMessageId();
1785
1910
  yield { type: "message:start", id: messageId };
1911
+ const responseFormat = request.config?.responseFormat;
1912
+ const geminiSchema = toGeminiSchema(responseFormat);
1913
+ const responseFormatGenConfig = responseFormat ? {
1914
+ responseMimeType: "application/json",
1915
+ ...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
1916
+ } : {};
1786
1917
  try {
1787
1918
  logProviderPayload(
1788
1919
  "google",
@@ -1794,7 +1925,8 @@ var GoogleAdapter = class {
1794
1925
  tools: toolsArray.length > 0 ? toolsArray : void 0,
1795
1926
  generationConfig: {
1796
1927
  temperature: request.config?.temperature ?? this.config.temperature,
1797
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
1928
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
1929
+ ...responseFormatGenConfig
1798
1930
  },
1799
1931
  messageParts: mergedContents[mergedContents.length - 1]?.parts
1800
1932
  },
@@ -1807,7 +1939,8 @@ var GoogleAdapter = class {
1807
1939
  tools: toolsArray.length > 0 ? toolsArray : void 0,
1808
1940
  generationConfig: {
1809
1941
  temperature: request.config?.temperature ?? this.config.temperature,
1810
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
1942
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
1943
+ ...responseFormatGenConfig
1811
1944
  }
1812
1945
  });
1813
1946
  const lastMessage = mergedContents[mergedContents.length - 1];
@@ -1974,6 +2107,12 @@ var GoogleAdapter = class {
1974
2107
  }
1975
2108
  }
1976
2109
  const tools = formatToolsForGemini(request.actions);
2110
+ const responseFormat = request.config?.responseFormat;
2111
+ const geminiSchema = toGeminiSchema(responseFormat);
2112
+ const responseFormatGenConfig = responseFormat ? {
2113
+ responseMimeType: "application/json",
2114
+ ...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
2115
+ } : {};
1977
2116
  const payload = {
1978
2117
  model: modelId,
1979
2118
  history: mergedContents.slice(0, -1),
@@ -1981,7 +2120,8 @@ var GoogleAdapter = class {
1981
2120
  tools: tools ? [tools] : void 0,
1982
2121
  generationConfig: {
1983
2122
  temperature: request.config?.temperature ?? this.config.temperature,
1984
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
2123
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
2124
+ ...responseFormatGenConfig
1985
2125
  },
1986
2126
  messageParts: mergedContents[mergedContents.length - 1]?.parts
1987
2127
  };
@@ -1992,7 +2132,8 @@ var GoogleAdapter = class {
1992
2132
  tools: tools ? [tools] : void 0,
1993
2133
  generationConfig: {
1994
2134
  temperature: request.config?.temperature ?? this.config.temperature,
1995
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
2135
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
2136
+ ...responseFormatGenConfig
1996
2137
  }
1997
2138
  });
1998
2139
  const lastMessage = mergedContents[mergedContents.length - 1];
@@ -2131,6 +2272,7 @@ var AzureAdapter = class {
2131
2272
  tools,
2132
2273
  temperature: request.config?.temperature ?? this.config.temperature,
2133
2274
  max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
2275
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
2134
2276
  stream: true
2135
2277
  };
2136
2278
  logProviderPayload("azure", "request payload", payload, request.debug);
@@ -2230,7 +2372,8 @@ var AzureAdapter = class {
2230
2372
  messages,
2231
2373
  tools,
2232
2374
  temperature: request.config?.temperature ?? this.config.temperature,
2233
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens
2375
+ max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
2376
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat)
2234
2377
  };
2235
2378
  logProviderPayload("azure", "request payload", payload, request.debug);
2236
2379
  const response = await client.chat.completions.create(payload);
@@ -112,6 +112,109 @@ function normalizeObjectJsonSchema(schema) {
112
112
  }
113
113
  return normalized;
114
114
  }
115
+ function isOpenAIReasoningModel(modelId) {
116
+ if (!modelId) return false;
117
+ return /^(o1|o3|o4|gpt-5)/i.test(modelId);
118
+ }
119
+ function buildOpenAITokenParams(modelId, maxTokens, temperature) {
120
+ if (isOpenAIReasoningModel(modelId)) {
121
+ return { max_completion_tokens: maxTokens };
122
+ }
123
+ return { max_tokens: maxTokens, temperature };
124
+ }
125
+ function stripSchemaKeys(schema, keysToDrop, options = {}) {
126
+ if (Array.isArray(schema)) {
127
+ return schema.map((item) => stripSchemaKeys(item, keysToDrop, options));
128
+ }
129
+ if (!schema || typeof schema !== "object") return schema;
130
+ const out = {};
131
+ for (const [key, value] of Object.entries(
132
+ schema
133
+ )) {
134
+ if (keysToDrop.has(key)) continue;
135
+ const renamed = options.renameKeys?.[key] ?? key;
136
+ out[renamed] = stripSchemaKeys(value, keysToDrop, options);
137
+ }
138
+ if (options.forceAdditionalPropertiesFalse && out.type === "object") {
139
+ out.additionalProperties = false;
140
+ }
141
+ return out;
142
+ }
143
+ function toOpenAIResponseFormat(rf) {
144
+ if (!rf) return void 0;
145
+ if (rf.type === "json_object") return { type: "json_object" };
146
+ return {
147
+ type: "json_schema",
148
+ json_schema: {
149
+ name: rf.json_schema.name,
150
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
151
+ strict: rf.json_schema.strict ?? true
152
+ }
153
+ };
154
+ }
155
+ function toOpenAIResponsesTextFormat(rf) {
156
+ if (!rf || rf.type !== "json_schema") return void 0;
157
+ return {
158
+ type: "json_schema",
159
+ name: rf.json_schema.name,
160
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
161
+ strict: rf.json_schema.strict ?? true
162
+ };
163
+ }
164
+ var ANTHROPIC_UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
165
+ "minimum",
166
+ "maximum",
167
+ "exclusiveMinimum",
168
+ "exclusiveMaximum",
169
+ "multipleOf",
170
+ "minLength",
171
+ "maxLength",
172
+ "minItems",
173
+ "maxItems",
174
+ "minProperties",
175
+ "maxProperties",
176
+ "pattern",
177
+ "$schema"
178
+ ]);
179
+ function toAnthropicOutputConfig(rf) {
180
+ if (!rf || rf.type !== "json_schema") return void 0;
181
+ const schema = stripSchemaKeys(
182
+ rf.json_schema.schema,
183
+ ANTHROPIC_UNSUPPORTED_KEYS,
184
+ {
185
+ forceAdditionalPropertiesFalse: true,
186
+ renameKeys: { oneOf: "anyOf" }
187
+ }
188
+ );
189
+ return {
190
+ format: {
191
+ type: "json_schema",
192
+ schema
193
+ }
194
+ };
195
+ }
196
+ var GEMINI_UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
197
+ "oneOf",
198
+ "anyOf",
199
+ "$ref",
200
+ "$defs",
201
+ "definitions",
202
+ "pattern",
203
+ "$schema",
204
+ "additionalProperties"
205
+ ]);
206
+ function toGeminiSchema(rf) {
207
+ if (!rf || rf.type !== "json_schema") return void 0;
208
+ return stripSchemaKeys(
209
+ rf.json_schema.schema,
210
+ GEMINI_UNSUPPORTED_KEYS
211
+ );
212
+ }
213
+ function toOllamaFormat(rf) {
214
+ if (!rf) return void 0;
215
+ if (rf.type === "json_object") return "json";
216
+ return rf.json_schema.schema;
217
+ }
115
218
  function formatTools(actions) {
116
219
  return actions.map((action) => ({
117
220
  type: "function",
@@ -482,6 +585,9 @@ var OpenAIAdapter = class _OpenAIAdapter {
482
585
  async completeWithResponses(request) {
483
586
  const client = await this.getClient();
484
587
  const openaiToolOptions = request.providerToolOptions?.openai;
588
+ const responsesTextFormat = toOpenAIResponsesTextFormat(
589
+ request.config?.responseFormat
590
+ );
485
591
  const payload = {
486
592
  model: request.config?.model || this.model,
487
593
  instructions: request.systemPrompt,
@@ -491,6 +597,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
491
597
  parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
492
598
  temperature: request.config?.temperature ?? this.config.temperature,
493
599
  max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
600
+ ...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
494
601
  stream: false
495
602
  };
496
603
  logProviderPayload("openai", "request payload", payload, request.debug);
@@ -612,14 +719,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
612
719
  name: openaiToolOptions.toolChoice.name
613
720
  }
614
721
  } : openaiToolOptions?.toolChoice;
722
+ const modelIdForPayload = request.config?.model || this.model;
615
723
  const payload = {
616
- model: request.config?.model || this.model,
724
+ model: modelIdForPayload,
617
725
  messages,
618
726
  tools: tools.length > 0 ? tools : void 0,
619
727
  tool_choice: tools.length > 0 ? toolChoice : void 0,
620
728
  parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
621
- temperature: request.config?.temperature ?? this.config.temperature,
622
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
729
+ ...buildOpenAITokenParams(
730
+ modelIdForPayload,
731
+ request.config?.maxTokens ?? this.config.maxTokens,
732
+ request.config?.temperature ?? this.config.temperature
733
+ ),
734
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
623
735
  stream: true,
624
736
  stream_options: { include_usage: true }
625
737
  };
@@ -761,14 +873,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
761
873
  name: openaiToolOptions.toolChoice.name
762
874
  }
763
875
  } : openaiToolOptions?.toolChoice;
876
+ const modelIdForCompletePayload = request.config?.model || this.model;
764
877
  const payload = {
765
- model: request.config?.model || this.model,
878
+ model: modelIdForCompletePayload,
766
879
  messages,
767
880
  tools: tools.length > 0 ? tools : void 0,
768
881
  tool_choice: tools.length > 0 ? toolChoice : void 0,
769
882
  parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
770
- temperature: request.config?.temperature ?? this.config.temperature,
771
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
883
+ ...buildOpenAITokenParams(
884
+ modelIdForCompletePayload,
885
+ request.config?.maxTokens ?? this.config.maxTokens,
886
+ request.config?.temperature ?? this.config.temperature
887
+ ),
888
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
772
889
  stream: false
773
890
  };
774
891
  logProviderPayload("openai", "request payload", payload, request.debug);
@@ -1044,7 +1161,9 @@ var AnthropicAdapter = class {
1044
1161
  * Build common request options for both streaming and non-streaming
1045
1162
  */
1046
1163
  buildRequestOptions(request) {
1047
- const systemMessage = request.systemPrompt || "";
1164
+ const responseFormat = request.config?.responseFormat;
1165
+ const jsonObjectSuffix = responseFormat?.type === "json_object" ? "\n\nRespond with a single JSON object and no other text." : "";
1166
+ const systemMessage = (request.systemPrompt || "") + jsonObjectSuffix;
1048
1167
  let messages;
1049
1168
  if (request.rawMessages && request.rawMessages.length > 0) {
1050
1169
  messages = this.convertToAnthropicMessages(request.rawMessages);
@@ -1125,6 +1244,10 @@ var AnthropicAdapter = class {
1125
1244
  if (serverToolConfiguration) {
1126
1245
  options.server_tool_configuration = serverToolConfiguration;
1127
1246
  }
1247
+ const outputConfig = toAnthropicOutputConfig(responseFormat);
1248
+ if (outputConfig) {
1249
+ options.output_config = outputConfig;
1250
+ }
1128
1251
  if (this.config.thinking?.type === "enabled") {
1129
1252
  options.thinking = {
1130
1253
  type: "enabled",
@@ -1485,12 +1608,14 @@ var OllamaAdapter = class {
1485
1608
  if (this.config.options) {
1486
1609
  Object.assign(ollamaOptions, this.config.options);
1487
1610
  }
1611
+ const ollamaFormat = toOllamaFormat(request.config?.responseFormat);
1488
1612
  const payload = {
1489
1613
  model: request.config?.model || this.model,
1490
1614
  messages,
1491
1615
  tools,
1492
1616
  stream: true,
1493
- options: ollamaOptions
1617
+ options: ollamaOptions,
1618
+ ...ollamaFormat !== void 0 ? { format: ollamaFormat } : {}
1494
1619
  };
1495
1620
  logProviderPayload("ollama", "request payload", payload, request.debug);
1496
1621
  const response = await fetch(`${this.baseUrl}/api/chat`, {
@@ -1781,6 +1906,12 @@ var GoogleAdapter = class {
1781
1906
  }
1782
1907
  const messageId = generateMessageId();
1783
1908
  yield { type: "message:start", id: messageId };
1909
+ const responseFormat = request.config?.responseFormat;
1910
+ const geminiSchema = toGeminiSchema(responseFormat);
1911
+ const responseFormatGenConfig = responseFormat ? {
1912
+ responseMimeType: "application/json",
1913
+ ...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
1914
+ } : {};
1784
1915
  try {
1785
1916
  logProviderPayload(
1786
1917
  "google",
@@ -1792,7 +1923,8 @@ var GoogleAdapter = class {
1792
1923
  tools: toolsArray.length > 0 ? toolsArray : void 0,
1793
1924
  generationConfig: {
1794
1925
  temperature: request.config?.temperature ?? this.config.temperature,
1795
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
1926
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
1927
+ ...responseFormatGenConfig
1796
1928
  },
1797
1929
  messageParts: mergedContents[mergedContents.length - 1]?.parts
1798
1930
  },
@@ -1805,7 +1937,8 @@ var GoogleAdapter = class {
1805
1937
  tools: toolsArray.length > 0 ? toolsArray : void 0,
1806
1938
  generationConfig: {
1807
1939
  temperature: request.config?.temperature ?? this.config.temperature,
1808
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
1940
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
1941
+ ...responseFormatGenConfig
1809
1942
  }
1810
1943
  });
1811
1944
  const lastMessage = mergedContents[mergedContents.length - 1];
@@ -1972,6 +2105,12 @@ var GoogleAdapter = class {
1972
2105
  }
1973
2106
  }
1974
2107
  const tools = formatToolsForGemini(request.actions);
2108
+ const responseFormat = request.config?.responseFormat;
2109
+ const geminiSchema = toGeminiSchema(responseFormat);
2110
+ const responseFormatGenConfig = responseFormat ? {
2111
+ responseMimeType: "application/json",
2112
+ ...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
2113
+ } : {};
1975
2114
  const payload = {
1976
2115
  model: modelId,
1977
2116
  history: mergedContents.slice(0, -1),
@@ -1979,7 +2118,8 @@ var GoogleAdapter = class {
1979
2118
  tools: tools ? [tools] : void 0,
1980
2119
  generationConfig: {
1981
2120
  temperature: request.config?.temperature ?? this.config.temperature,
1982
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
2121
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
2122
+ ...responseFormatGenConfig
1983
2123
  },
1984
2124
  messageParts: mergedContents[mergedContents.length - 1]?.parts
1985
2125
  };
@@ -1990,7 +2130,8 @@ var GoogleAdapter = class {
1990
2130
  tools: tools ? [tools] : void 0,
1991
2131
  generationConfig: {
1992
2132
  temperature: request.config?.temperature ?? this.config.temperature,
1993
- maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
2133
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
2134
+ ...responseFormatGenConfig
1994
2135
  }
1995
2136
  });
1996
2137
  const lastMessage = mergedContents[mergedContents.length - 1];
@@ -2129,6 +2270,7 @@ var AzureAdapter = class {
2129
2270
  tools,
2130
2271
  temperature: request.config?.temperature ?? this.config.temperature,
2131
2272
  max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
2273
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
2132
2274
  stream: true
2133
2275
  };
2134
2276
  logProviderPayload("azure", "request payload", payload, request.debug);
@@ -2228,7 +2370,8 @@ var AzureAdapter = class {
2228
2370
  messages,
2229
2371
  tools,
2230
2372
  temperature: request.config?.temperature ?? this.config.temperature,
2231
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens
2373
+ max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
2374
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat)
2232
2375
  };
2233
2376
  logProviderPayload("azure", "request payload", payload, request.debug);
2234
2377
  const response = await client.chat.completions.create(payload);