@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.1
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/README.md +19 -1
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +293 -23
- package/dist/adapters/index.mjs +293 -23
- package/dist/base-BYQKp9TW.d.mts +263 -0
- package/dist/base-Cxq3ni0t.d.ts +263 -0
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +61 -8
- package/dist/index.d.ts +61 -8
- package/dist/index.js +71 -0
- package/dist/index.mjs +71 -0
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +360 -203
- package/dist/providers/anthropic/index.mjs +360 -203
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +49 -1
- package/dist/providers/azure/index.mjs +49 -1
- package/dist/providers/fireworks/index.d.mts +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/fireworks/index.js +56 -0
- package/dist/providers/fireworks/index.mjs +56 -0
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +303 -207
- package/dist/providers/google/index.mjs +303 -207
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +10 -2
- package/dist/providers/ollama/index.mjs +10 -2
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +318 -216
- package/dist/providers/openai/index.mjs +318 -216
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +308 -206
- package/dist/providers/openrouter/index.mjs +308 -206
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +308 -206
- package/dist/providers/togetherai/index.mjs +308 -206
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +307 -210
- package/dist/providers/xai/index.mjs +307 -210
- package/dist/{types-BctsnC3g.d.ts → types-BvkiJ1dd.d.mts} +2 -1
- package/dist/{types-38yolWJn.d.ts → types-ChORafYS.d.ts} +1 -1
- package/dist/types-D774b0dg.d.mts +1018 -0
- package/dist/types-D774b0dg.d.ts +1018 -0
- package/dist/{types-DRqxMIjF.d.mts → types-TMilS-Dz.d.ts} +2 -1
- package/dist/{types-D4YfrQJR.d.mts → types-mwMhCwOq.d.mts} +1 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/base-D-U61JaB.d.mts +0 -788
- package/dist/base-iGi9Va6Z.d.ts +0 -788
- package/dist/types-CR8mi9I0.d.mts +0 -417
- package/dist/types-CR8mi9I0.d.ts +0 -417
package/dist/adapters/index.mjs
CHANGED
|
@@ -112,6 +112,190 @@ 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
|
+
}
|
|
218
|
+
function toOpenAIResponsesMcpTools(mcpServers) {
|
|
219
|
+
if (!mcpServers || mcpServers.length === 0) return [];
|
|
220
|
+
return mcpServers.map((mcp) => ({
|
|
221
|
+
type: "mcp",
|
|
222
|
+
server_label: mcp.label,
|
|
223
|
+
server_url: mcp.url,
|
|
224
|
+
...mcp.headers ? { headers: mcp.headers } : {},
|
|
225
|
+
...mcp.allowedTools ? { allowed_tools: mcp.allowedTools } : {},
|
|
226
|
+
require_approval: mcp.requireApproval ?? "never"
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
function toAnthropicMcp(mcpServers) {
|
|
230
|
+
if (!mcpServers || mcpServers.length === 0) {
|
|
231
|
+
return { mcpServers: [], tools: [], betas: [] };
|
|
232
|
+
}
|
|
233
|
+
const serverEntries = [];
|
|
234
|
+
const toolEntries = [];
|
|
235
|
+
for (const mcp of mcpServers) {
|
|
236
|
+
const authHeader = mcp.headers?.Authorization ?? mcp.headers?.authorization;
|
|
237
|
+
const token = authHeader?.replace(/^Bearer\s+/i, "");
|
|
238
|
+
serverEntries.push({
|
|
239
|
+
type: "url",
|
|
240
|
+
url: mcp.url,
|
|
241
|
+
name: mcp.label,
|
|
242
|
+
...token ? { authorization_token: token } : {}
|
|
243
|
+
});
|
|
244
|
+
if (mcp.allowedTools && mcp.allowedTools.length > 0) {
|
|
245
|
+
toolEntries.push({
|
|
246
|
+
type: "mcp_toolset",
|
|
247
|
+
mcp_server_name: mcp.label,
|
|
248
|
+
configs: Object.fromEntries(
|
|
249
|
+
mcp.allowedTools.map((toolName) => [toolName, {}])
|
|
250
|
+
)
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
mcpServers: serverEntries,
|
|
256
|
+
tools: toolEntries,
|
|
257
|
+
betas: ["mcp-client-2025-11-20"]
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function isStringEffort(effort) {
|
|
261
|
+
return typeof effort === "string" && (effort === "minimal" || effort === "low" || effort === "medium" || effort === "high");
|
|
262
|
+
}
|
|
263
|
+
function toOpenAIReasoning(effort) {
|
|
264
|
+
if (!effort) return void 0;
|
|
265
|
+
if (typeof effort === "object" && "raw" in effort) return effort.raw;
|
|
266
|
+
if (typeof effort === "object" && "budgetTokens" in effort) {
|
|
267
|
+
const budget = effort.budgetTokens;
|
|
268
|
+
const mapped = budget >= 16e3 ? "high" : budget >= 8e3 ? "medium" : "low";
|
|
269
|
+
return { effort: mapped, summary: "auto" };
|
|
270
|
+
}
|
|
271
|
+
if (isStringEffort(effort)) {
|
|
272
|
+
return { effort, summary: "auto" };
|
|
273
|
+
}
|
|
274
|
+
return void 0;
|
|
275
|
+
}
|
|
276
|
+
var ANTHROPIC_ADAPTIVE_MODELS = /(claude-opus-4-7|claude-opus-4-6|claude-sonnet-4-6)/i;
|
|
277
|
+
function toAnthropicThinking(effort, modelId) {
|
|
278
|
+
if (!effort) return {};
|
|
279
|
+
if (typeof effort === "object" && "raw" in effort) {
|
|
280
|
+
return { thinking: effort.raw };
|
|
281
|
+
}
|
|
282
|
+
const isAdaptive = !!modelId && ANTHROPIC_ADAPTIVE_MODELS.test(modelId);
|
|
283
|
+
if (typeof effort === "object" && "budgetTokens" in effort) {
|
|
284
|
+
return {
|
|
285
|
+
thinking: { type: "enabled", budget_tokens: effort.budgetTokens }
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (!isStringEffort(effort)) return {};
|
|
289
|
+
if (isAdaptive) {
|
|
290
|
+
const mapped = effort === "minimal" ? "low" : effort;
|
|
291
|
+
return {
|
|
292
|
+
thinking: { type: "adaptive" },
|
|
293
|
+
outputConfigEffort: mapped
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const budget = effort === "high" ? 16e3 : effort === "medium" ? 8e3 : effort === "low" ? 4e3 : 2048;
|
|
297
|
+
return { thinking: { type: "enabled", budget_tokens: budget } };
|
|
298
|
+
}
|
|
115
299
|
function formatTools(actions) {
|
|
116
300
|
return actions.map((action) => ({
|
|
117
301
|
type: "function",
|
|
@@ -393,6 +577,14 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
393
577
|
return this.client;
|
|
394
578
|
}
|
|
395
579
|
shouldUseResponsesApi(request) {
|
|
580
|
+
if (request.config?.mcpServers && request.config.mcpServers.length > 0 || request.config?.reasoningEffort !== void 0) {
|
|
581
|
+
if (this.provider !== "openai" && this.provider !== "azure") {
|
|
582
|
+
throw new Error(
|
|
583
|
+
`[llm-sdk] Provider "${this.provider}" does not support MCP servers or per-request reasoning effort. Use OpenAI or Anthropic for these features.`
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
396
588
|
return request.providerToolOptions?.openai?.nativeToolSearch?.enabled === true && request.providerToolOptions.openai.nativeToolSearch.useResponsesApi !== false && Array.isArray(request.toolDefinitions) && request.toolDefinitions.length > 0;
|
|
397
589
|
}
|
|
398
590
|
buildResponsesInput(request) {
|
|
@@ -453,7 +645,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
453
645
|
strict: true,
|
|
454
646
|
defer_loading: tool.deferLoading === true
|
|
455
647
|
}));
|
|
456
|
-
return [{ type: "tool_search" }, ...nativeTools];
|
|
648
|
+
return nativeTools.length > 0 ? [{ type: "tool_search" }, ...nativeTools] : [];
|
|
457
649
|
}
|
|
458
650
|
parseResponsesResult(response) {
|
|
459
651
|
const content = typeof response?.output_text === "string" ? response.output_text : "";
|
|
@@ -482,15 +674,33 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
482
674
|
async completeWithResponses(request) {
|
|
483
675
|
const client = await this.getClient();
|
|
484
676
|
const openaiToolOptions = request.providerToolOptions?.openai;
|
|
677
|
+
const responsesTextFormat = toOpenAIResponsesTextFormat(
|
|
678
|
+
request.config?.responseFormat
|
|
679
|
+
);
|
|
680
|
+
const mcpTools = toOpenAIResponsesMcpTools(request.config?.mcpServers);
|
|
681
|
+
const modelId = request.config?.model || this.model;
|
|
682
|
+
const reasoning = isOpenAIReasoningModel(modelId) ? toOpenAIReasoning(request.config?.reasoningEffort) : void 0;
|
|
683
|
+
if (request.config?.reasoningEffort && !isOpenAIReasoningModel(modelId)) {
|
|
684
|
+
console.warn(
|
|
685
|
+
`[llm-sdk] openai/${modelId} is not a reasoning model; \`reasoningEffort\` is ignored. Use o1/o3/o4/gpt-5.x for reasoning.`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
const functionTools = this.buildResponsesTools(
|
|
689
|
+
request.toolDefinitions ?? []
|
|
690
|
+
);
|
|
691
|
+
const tools = [...functionTools, ...mcpTools];
|
|
485
692
|
const payload = {
|
|
486
693
|
model: request.config?.model || this.model,
|
|
487
694
|
instructions: request.systemPrompt,
|
|
488
695
|
input: this.buildResponsesInput(request),
|
|
489
|
-
tools:
|
|
696
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
490
697
|
tool_choice: openaiToolOptions?.toolChoice === "required" ? "required" : openaiToolOptions?.toolChoice === "auto" ? "auto" : void 0,
|
|
491
698
|
parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
|
|
492
699
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
493
700
|
max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
701
|
+
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
702
|
+
...reasoning ? { reasoning } : {},
|
|
703
|
+
store: false,
|
|
494
704
|
stream: false
|
|
495
705
|
};
|
|
496
706
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -612,14 +822,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
612
822
|
name: openaiToolOptions.toolChoice.name
|
|
613
823
|
}
|
|
614
824
|
} : openaiToolOptions?.toolChoice;
|
|
825
|
+
const modelIdForPayload = request.config?.model || this.model;
|
|
615
826
|
const payload = {
|
|
616
|
-
model:
|
|
827
|
+
model: modelIdForPayload,
|
|
617
828
|
messages,
|
|
618
829
|
tools: tools.length > 0 ? tools : void 0,
|
|
619
830
|
tool_choice: tools.length > 0 ? toolChoice : void 0,
|
|
620
831
|
parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
|
|
621
|
-
|
|
622
|
-
|
|
832
|
+
...buildOpenAITokenParams(
|
|
833
|
+
modelIdForPayload,
|
|
834
|
+
request.config?.maxTokens ?? this.config.maxTokens,
|
|
835
|
+
request.config?.temperature ?? this.config.temperature
|
|
836
|
+
),
|
|
837
|
+
response_format: toOpenAIResponseFormat(request.config?.responseFormat),
|
|
623
838
|
stream: true,
|
|
624
839
|
stream_options: { include_usage: true }
|
|
625
840
|
};
|
|
@@ -761,14 +976,19 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
761
976
|
name: openaiToolOptions.toolChoice.name
|
|
762
977
|
}
|
|
763
978
|
} : openaiToolOptions?.toolChoice;
|
|
979
|
+
const modelIdForCompletePayload = request.config?.model || this.model;
|
|
764
980
|
const payload = {
|
|
765
|
-
model:
|
|
981
|
+
model: modelIdForCompletePayload,
|
|
766
982
|
messages,
|
|
767
983
|
tools: tools.length > 0 ? tools : void 0,
|
|
768
984
|
tool_choice: tools.length > 0 ? toolChoice : void 0,
|
|
769
985
|
parallel_tool_calls: tools.length > 0 ? openaiToolOptions?.parallelToolCalls : void 0,
|
|
770
|
-
|
|
771
|
-
|
|
986
|
+
...buildOpenAITokenParams(
|
|
987
|
+
modelIdForCompletePayload,
|
|
988
|
+
request.config?.maxTokens ?? this.config.maxTokens,
|
|
989
|
+
request.config?.temperature ?? this.config.temperature
|
|
990
|
+
),
|
|
991
|
+
response_format: toOpenAIResponseFormat(request.config?.responseFormat),
|
|
772
992
|
stream: false
|
|
773
993
|
};
|
|
774
994
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -1044,7 +1264,9 @@ var AnthropicAdapter = class {
|
|
|
1044
1264
|
* Build common request options for both streaming and non-streaming
|
|
1045
1265
|
*/
|
|
1046
1266
|
buildRequestOptions(request) {
|
|
1047
|
-
const
|
|
1267
|
+
const responseFormat = request.config?.responseFormat;
|
|
1268
|
+
const jsonObjectSuffix = responseFormat?.type === "json_object" ? "\n\nRespond with a single JSON object and no other text." : "";
|
|
1269
|
+
const systemMessage = (request.systemPrompt || "") + jsonObjectSuffix;
|
|
1048
1270
|
let messages;
|
|
1049
1271
|
if (request.rawMessages && request.rawMessages.length > 0) {
|
|
1050
1272
|
messages = this.convertToAnthropicMessages(request.rawMessages);
|
|
@@ -1125,32 +1347,58 @@ var AnthropicAdapter = class {
|
|
|
1125
1347
|
if (serverToolConfiguration) {
|
|
1126
1348
|
options.server_tool_configuration = serverToolConfiguration;
|
|
1127
1349
|
}
|
|
1128
|
-
|
|
1350
|
+
const modelForThinking = request.config?.model || this.model;
|
|
1351
|
+
const thinkingTranslation = toAnthropicThinking(
|
|
1352
|
+
request.config?.reasoningEffort,
|
|
1353
|
+
modelForThinking
|
|
1354
|
+
);
|
|
1355
|
+
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
1356
|
+
if (outputConfig || thinkingTranslation.outputConfigEffort) {
|
|
1357
|
+
options.output_config = {
|
|
1358
|
+
...outputConfig ?? {},
|
|
1359
|
+
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
if (thinkingTranslation.thinking) {
|
|
1363
|
+
options.thinking = thinkingTranslation.thinking;
|
|
1364
|
+
} else if (this.config.thinking?.type === "enabled") {
|
|
1129
1365
|
options.thinking = {
|
|
1130
1366
|
type: "enabled",
|
|
1131
1367
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1132
1368
|
};
|
|
1133
1369
|
}
|
|
1134
|
-
|
|
1370
|
+
const mcp = toAnthropicMcp(request.config?.mcpServers);
|
|
1371
|
+
const betas = [];
|
|
1372
|
+
if (mcp.mcpServers.length > 0) {
|
|
1373
|
+
options.mcp_servers = mcp.mcpServers;
|
|
1374
|
+
betas.push(...mcp.betas);
|
|
1375
|
+
if (mcp.tools.length > 0) {
|
|
1376
|
+
const existingTools = Array.isArray(options.tools) ? options.tools : [];
|
|
1377
|
+
options.tools = [...existingTools, ...mcp.tools];
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
return { options, messages, betas };
|
|
1135
1381
|
}
|
|
1136
1382
|
/**
|
|
1137
1383
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1138
1384
|
*/
|
|
1139
1385
|
async complete(request) {
|
|
1140
1386
|
const client = await this.getClient();
|
|
1141
|
-
const { options } = this.buildRequestOptions(request);
|
|
1387
|
+
const { options, betas } = this.buildRequestOptions(request);
|
|
1142
1388
|
const nonStreamingOptions = {
|
|
1143
1389
|
...options,
|
|
1144
1390
|
stream: false
|
|
1145
1391
|
};
|
|
1146
1392
|
try {
|
|
1393
|
+
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1394
|
+
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1147
1395
|
logProviderPayload(
|
|
1148
1396
|
"anthropic",
|
|
1149
1397
|
"request payload",
|
|
1150
|
-
|
|
1398
|
+
finalOptions,
|
|
1151
1399
|
request.debug
|
|
1152
1400
|
);
|
|
1153
|
-
const response = await
|
|
1401
|
+
const response = await messagesApi.create(finalOptions);
|
|
1154
1402
|
logProviderPayload(
|
|
1155
1403
|
"anthropic",
|
|
1156
1404
|
"response payload",
|
|
@@ -1185,17 +1433,19 @@ var AnthropicAdapter = class {
|
|
|
1185
1433
|
}
|
|
1186
1434
|
async *stream(request) {
|
|
1187
1435
|
const client = await this.getClient();
|
|
1188
|
-
const { options } = this.buildRequestOptions(request);
|
|
1436
|
+
const { options, betas } = this.buildRequestOptions(request);
|
|
1189
1437
|
const messageId = generateMessageId();
|
|
1190
1438
|
yield { type: "message:start", id: messageId };
|
|
1191
1439
|
try {
|
|
1440
|
+
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1441
|
+
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1192
1442
|
logProviderPayload(
|
|
1193
1443
|
"anthropic",
|
|
1194
1444
|
"request payload",
|
|
1195
|
-
|
|
1445
|
+
finalOptions,
|
|
1196
1446
|
request.debug
|
|
1197
1447
|
);
|
|
1198
|
-
const stream = await
|
|
1448
|
+
const stream = await streamApi.stream(finalOptions);
|
|
1199
1449
|
let currentToolUse = null;
|
|
1200
1450
|
let isInThinkingBlock = false;
|
|
1201
1451
|
const collectedCitations = [];
|
|
@@ -1485,12 +1735,14 @@ var OllamaAdapter = class {
|
|
|
1485
1735
|
if (this.config.options) {
|
|
1486
1736
|
Object.assign(ollamaOptions, this.config.options);
|
|
1487
1737
|
}
|
|
1738
|
+
const ollamaFormat = toOllamaFormat(request.config?.responseFormat);
|
|
1488
1739
|
const payload = {
|
|
1489
1740
|
model: request.config?.model || this.model,
|
|
1490
1741
|
messages,
|
|
1491
1742
|
tools,
|
|
1492
1743
|
stream: true,
|
|
1493
|
-
options: ollamaOptions
|
|
1744
|
+
options: ollamaOptions,
|
|
1745
|
+
...ollamaFormat !== void 0 ? { format: ollamaFormat } : {}
|
|
1494
1746
|
};
|
|
1495
1747
|
logProviderPayload("ollama", "request payload", payload, request.debug);
|
|
1496
1748
|
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
|
@@ -1781,6 +2033,12 @@ var GoogleAdapter = class {
|
|
|
1781
2033
|
}
|
|
1782
2034
|
const messageId = generateMessageId();
|
|
1783
2035
|
yield { type: "message:start", id: messageId };
|
|
2036
|
+
const responseFormat = request.config?.responseFormat;
|
|
2037
|
+
const geminiSchema = toGeminiSchema(responseFormat);
|
|
2038
|
+
const responseFormatGenConfig = responseFormat ? {
|
|
2039
|
+
responseMimeType: "application/json",
|
|
2040
|
+
...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
|
|
2041
|
+
} : {};
|
|
1784
2042
|
try {
|
|
1785
2043
|
logProviderPayload(
|
|
1786
2044
|
"google",
|
|
@@ -1792,7 +2050,8 @@ var GoogleAdapter = class {
|
|
|
1792
2050
|
tools: toolsArray.length > 0 ? toolsArray : void 0,
|
|
1793
2051
|
generationConfig: {
|
|
1794
2052
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
1795
|
-
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
|
|
2053
|
+
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2054
|
+
...responseFormatGenConfig
|
|
1796
2055
|
},
|
|
1797
2056
|
messageParts: mergedContents[mergedContents.length - 1]?.parts
|
|
1798
2057
|
},
|
|
@@ -1805,7 +2064,8 @@ var GoogleAdapter = class {
|
|
|
1805
2064
|
tools: toolsArray.length > 0 ? toolsArray : void 0,
|
|
1806
2065
|
generationConfig: {
|
|
1807
2066
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
1808
|
-
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
|
|
2067
|
+
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2068
|
+
...responseFormatGenConfig
|
|
1809
2069
|
}
|
|
1810
2070
|
});
|
|
1811
2071
|
const lastMessage = mergedContents[mergedContents.length - 1];
|
|
@@ -1972,6 +2232,12 @@ var GoogleAdapter = class {
|
|
|
1972
2232
|
}
|
|
1973
2233
|
}
|
|
1974
2234
|
const tools = formatToolsForGemini(request.actions);
|
|
2235
|
+
const responseFormat = request.config?.responseFormat;
|
|
2236
|
+
const geminiSchema = toGeminiSchema(responseFormat);
|
|
2237
|
+
const responseFormatGenConfig = responseFormat ? {
|
|
2238
|
+
responseMimeType: "application/json",
|
|
2239
|
+
...geminiSchema ? { responseJsonSchema: geminiSchema } : {}
|
|
2240
|
+
} : {};
|
|
1975
2241
|
const payload = {
|
|
1976
2242
|
model: modelId,
|
|
1977
2243
|
history: mergedContents.slice(0, -1),
|
|
@@ -1979,7 +2245,8 @@ var GoogleAdapter = class {
|
|
|
1979
2245
|
tools: tools ? [tools] : void 0,
|
|
1980
2246
|
generationConfig: {
|
|
1981
2247
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
1982
|
-
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
|
|
2248
|
+
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2249
|
+
...responseFormatGenConfig
|
|
1983
2250
|
},
|
|
1984
2251
|
messageParts: mergedContents[mergedContents.length - 1]?.parts
|
|
1985
2252
|
};
|
|
@@ -1990,7 +2257,8 @@ var GoogleAdapter = class {
|
|
|
1990
2257
|
tools: tools ? [tools] : void 0,
|
|
1991
2258
|
generationConfig: {
|
|
1992
2259
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
1993
|
-
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
|
|
2260
|
+
maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2261
|
+
...responseFormatGenConfig
|
|
1994
2262
|
}
|
|
1995
2263
|
});
|
|
1996
2264
|
const lastMessage = mergedContents[mergedContents.length - 1];
|
|
@@ -2129,6 +2397,7 @@ var AzureAdapter = class {
|
|
|
2129
2397
|
tools,
|
|
2130
2398
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
2131
2399
|
max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2400
|
+
response_format: toOpenAIResponseFormat(request.config?.responseFormat),
|
|
2132
2401
|
stream: true
|
|
2133
2402
|
};
|
|
2134
2403
|
logProviderPayload("azure", "request payload", payload, request.debug);
|
|
@@ -2228,7 +2497,8 @@ var AzureAdapter = class {
|
|
|
2228
2497
|
messages,
|
|
2229
2498
|
tools,
|
|
2230
2499
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
2231
|
-
max_tokens: request.config?.maxTokens ?? this.config.maxTokens
|
|
2500
|
+
max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
2501
|
+
response_format: toOpenAIResponseFormat(request.config?.responseFormat)
|
|
2232
2502
|
};
|
|
2233
2503
|
logProviderPayload("azure", "request payload", payload, request.debug);
|
|
2234
2504
|
const response = await client.chat.completions.create(payload);
|