@yourgpt/llm-sdk 2.5.1-beta.1 → 2.5.1-beta.3
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 +1 -19
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +15 -139
- package/dist/adapters/index.mjs +15 -139
- package/dist/{base-Cxq3ni0t.d.ts → base-C58Dsr9p.d.ts} +1 -5
- package/dist/{base-BYQKp9TW.d.mts → base-tNgbBaSo.d.mts} +1 -5
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +8 -60
- package/dist/index.d.ts +8 -60
- package/dist/index.js +0 -59
- package/dist/index.mjs +0 -59
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +10 -91
- package/dist/providers/anthropic/index.mjs +10 -91
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +1 -0
- package/dist/providers/azure/index.mjs +1 -0
- package/dist/providers/fireworks/index.d.mts +67 -2
- package/dist/providers/fireworks/index.d.ts +67 -2
- package/dist/providers/fireworks/index.js +721 -1
- package/dist/providers/fireworks/index.mjs +719 -1
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +4 -51
- package/dist/providers/google/index.mjs +4 -51
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +1 -0
- package/dist/providers/ollama/index.mjs +1 -0
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +4 -51
- package/dist/providers/openai/index.mjs +4 -51
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +4 -51
- package/dist/providers/openrouter/index.mjs +4 -51
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +4 -51
- package/dist/providers/togetherai/index.mjs +4 -51
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +4 -51
- package/dist/providers/xai/index.mjs +4 -51
- package/dist/{types-mwMhCwOq.d.mts → types-B6dhnguR.d.mts} +1 -1
- package/dist/{types-TMilS-Dz.d.ts → types-BQ31QIsA.d.ts} +2 -2
- package/dist/{types-BvkiJ1dd.d.mts → types-BSSiJW2o.d.mts} +2 -2
- package/dist/{types-D774b0dg.d.mts → types-BkQCSiIt.d.mts} +2 -57
- package/dist/{types-D774b0dg.d.ts → types-BkQCSiIt.d.ts} +2 -57
- package/dist/{types-ChORafYS.d.ts → types-CCxPmkmK.d.ts} +1 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,24 +114,6 @@ const runtime = createRuntime({
|
|
|
114
114
|
|
|
115
115
|
When `search.enabled` is on, deferred tools can be discovered through a hidden `search_tools` server tool. Matching tools are loaded into the next loop iteration instead of sending every deferred tool definition up front.
|
|
116
116
|
|
|
117
|
-
## Structured output, MCP, and reasoning effort
|
|
118
|
-
|
|
119
|
-
Pass `responseFormat`, `mcpServers`, and `reasoningEffort` on any `generateText()` / `streamText()` / `runtime.chat()` / `runtime.response()` call:
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
const result = await runtime.response({
|
|
123
|
-
prompt: "Extract FAQs from this conversation.",
|
|
124
|
-
mcpServers: [{ label: "kb", url: "https://kb.example.com/sse" }],
|
|
125
|
-
reasoningEffort: "high",
|
|
126
|
-
responseFormat: {
|
|
127
|
-
type: "json_schema",
|
|
128
|
-
json_schema: { name, schema, strict: true },
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
OpenAI routes through `/v1/responses` automatically when MCP or reasoning is set; Anthropic uses the `mcp-client-2025-11-20` beta and adaptive thinking on Claude 4.6/4.7. See the [Structured Output guide](https://copilot-sdk.yourgpt.ai/docs/llm-sdk/structured-output) for the full per-provider mapping.
|
|
134
|
-
|
|
135
117
|
## Documentation
|
|
136
118
|
|
|
137
119
|
Visit **[copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)** for full documentation:
|
|
@@ -139,7 +121,7 @@ Visit **[copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)** for full docu
|
|
|
139
121
|
- [All Providers](https://copilot-sdk.yourgpt.ai/docs/providers) - OpenAI, Anthropic, Google, xAI
|
|
140
122
|
- [Server Setup](https://copilot-sdk.yourgpt.ai/docs/server) - Runtime, streaming, tools
|
|
141
123
|
- [Tools](https://copilot-sdk.yourgpt.ai/docs/tools) - Server-side and client-side tools
|
|
142
|
-
- [LLM SDK Reference](https://copilot-sdk.yourgpt.ai/docs/llm-sdk) - streamText, generateText
|
|
124
|
+
- [LLM SDK Reference](https://copilot-sdk.yourgpt.ai/docs/llm-sdk) - streamText, generateText
|
|
143
125
|
|
|
144
126
|
## License
|
|
145
127
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-
|
|
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-
|
|
3
|
-
import { W as WebSearchConfig,
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
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
|
/**
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-
|
|
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-
|
|
3
|
-
import { W as WebSearchConfig,
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
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
|
/**
|
package/dist/adapters/index.js
CHANGED
|
@@ -145,6 +145,7 @@ function stripSchemaKeys(schema, keysToDrop, options = {}) {
|
|
|
145
145
|
function toOpenAIResponseFormat(rf) {
|
|
146
146
|
if (!rf) return void 0;
|
|
147
147
|
if (rf.type === "json_object") return { type: "json_object" };
|
|
148
|
+
if (rf.type !== "json_schema" || !rf.json_schema) return void 0;
|
|
148
149
|
return {
|
|
149
150
|
type: "json_schema",
|
|
150
151
|
json_schema: {
|
|
@@ -215,89 +216,9 @@ function toGeminiSchema(rf) {
|
|
|
215
216
|
function toOllamaFormat(rf) {
|
|
216
217
|
if (!rf) return void 0;
|
|
217
218
|
if (rf.type === "json_object") return "json";
|
|
219
|
+
if (rf.type !== "json_schema" || !rf.json_schema) return void 0;
|
|
218
220
|
return rf.json_schema.schema;
|
|
219
221
|
}
|
|
220
|
-
function toOpenAIResponsesMcpTools(mcpServers) {
|
|
221
|
-
if (!mcpServers || mcpServers.length === 0) return [];
|
|
222
|
-
return mcpServers.map((mcp) => ({
|
|
223
|
-
type: "mcp",
|
|
224
|
-
server_label: mcp.label,
|
|
225
|
-
server_url: mcp.url,
|
|
226
|
-
...mcp.headers ? { headers: mcp.headers } : {},
|
|
227
|
-
...mcp.allowedTools ? { allowed_tools: mcp.allowedTools } : {},
|
|
228
|
-
require_approval: mcp.requireApproval ?? "never"
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
function toAnthropicMcp(mcpServers) {
|
|
232
|
-
if (!mcpServers || mcpServers.length === 0) {
|
|
233
|
-
return { mcpServers: [], tools: [], betas: [] };
|
|
234
|
-
}
|
|
235
|
-
const serverEntries = [];
|
|
236
|
-
const toolEntries = [];
|
|
237
|
-
for (const mcp of mcpServers) {
|
|
238
|
-
const authHeader = mcp.headers?.Authorization ?? mcp.headers?.authorization;
|
|
239
|
-
const token = authHeader?.replace(/^Bearer\s+/i, "");
|
|
240
|
-
serverEntries.push({
|
|
241
|
-
type: "url",
|
|
242
|
-
url: mcp.url,
|
|
243
|
-
name: mcp.label,
|
|
244
|
-
...token ? { authorization_token: token } : {}
|
|
245
|
-
});
|
|
246
|
-
if (mcp.allowedTools && mcp.allowedTools.length > 0) {
|
|
247
|
-
toolEntries.push({
|
|
248
|
-
type: "mcp_toolset",
|
|
249
|
-
mcp_server_name: mcp.label,
|
|
250
|
-
configs: Object.fromEntries(
|
|
251
|
-
mcp.allowedTools.map((toolName) => [toolName, {}])
|
|
252
|
-
)
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
mcpServers: serverEntries,
|
|
258
|
-
tools: toolEntries,
|
|
259
|
-
betas: ["mcp-client-2025-11-20"]
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
function isStringEffort(effort) {
|
|
263
|
-
return typeof effort === "string" && (effort === "minimal" || effort === "low" || effort === "medium" || effort === "high");
|
|
264
|
-
}
|
|
265
|
-
function toOpenAIReasoning(effort) {
|
|
266
|
-
if (!effort) return void 0;
|
|
267
|
-
if (typeof effort === "object" && "raw" in effort) return effort.raw;
|
|
268
|
-
if (typeof effort === "object" && "budgetTokens" in effort) {
|
|
269
|
-
const budget = effort.budgetTokens;
|
|
270
|
-
const mapped = budget >= 16e3 ? "high" : budget >= 8e3 ? "medium" : "low";
|
|
271
|
-
return { effort: mapped, summary: "auto" };
|
|
272
|
-
}
|
|
273
|
-
if (isStringEffort(effort)) {
|
|
274
|
-
return { effort, summary: "auto" };
|
|
275
|
-
}
|
|
276
|
-
return void 0;
|
|
277
|
-
}
|
|
278
|
-
var ANTHROPIC_ADAPTIVE_MODELS = /(claude-opus-4-7|claude-opus-4-6|claude-sonnet-4-6)/i;
|
|
279
|
-
function toAnthropicThinking(effort, modelId) {
|
|
280
|
-
if (!effort) return {};
|
|
281
|
-
if (typeof effort === "object" && "raw" in effort) {
|
|
282
|
-
return { thinking: effort.raw };
|
|
283
|
-
}
|
|
284
|
-
const isAdaptive = !!modelId && ANTHROPIC_ADAPTIVE_MODELS.test(modelId);
|
|
285
|
-
if (typeof effort === "object" && "budgetTokens" in effort) {
|
|
286
|
-
return {
|
|
287
|
-
thinking: { type: "enabled", budget_tokens: effort.budgetTokens }
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
if (!isStringEffort(effort)) return {};
|
|
291
|
-
if (isAdaptive) {
|
|
292
|
-
const mapped = effort === "minimal" ? "low" : effort;
|
|
293
|
-
return {
|
|
294
|
-
thinking: { type: "adaptive" },
|
|
295
|
-
outputConfigEffort: mapped
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
const budget = effort === "high" ? 16e3 : effort === "medium" ? 8e3 : effort === "low" ? 4e3 : 2048;
|
|
299
|
-
return { thinking: { type: "enabled", budget_tokens: budget } };
|
|
300
|
-
}
|
|
301
222
|
function formatTools(actions) {
|
|
302
223
|
return actions.map((action) => ({
|
|
303
224
|
type: "function",
|
|
@@ -566,6 +487,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
566
487
|
if (baseUrl.includes("generativelanguage.googleapis.com")) return "google";
|
|
567
488
|
if (baseUrl.includes("x.ai")) return "xai";
|
|
568
489
|
if (baseUrl.includes("azure")) return "azure";
|
|
490
|
+
if (baseUrl.includes("fireworks.ai")) return "fireworks";
|
|
569
491
|
return "openai";
|
|
570
492
|
}
|
|
571
493
|
async getClient() {
|
|
@@ -579,14 +501,6 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
579
501
|
return this.client;
|
|
580
502
|
}
|
|
581
503
|
shouldUseResponsesApi(request) {
|
|
582
|
-
if (request.config?.mcpServers && request.config.mcpServers.length > 0 || request.config?.reasoningEffort !== void 0) {
|
|
583
|
-
if (this.provider !== "openai" && this.provider !== "azure") {
|
|
584
|
-
throw new Error(
|
|
585
|
-
`[llm-sdk] Provider "${this.provider}" does not support MCP servers or per-request reasoning effort. Use OpenAI or Anthropic for these features.`
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
return true;
|
|
589
|
-
}
|
|
590
504
|
return request.providerToolOptions?.openai?.nativeToolSearch?.enabled === true && request.providerToolOptions.openai.nativeToolSearch.useResponsesApi !== false && Array.isArray(request.toolDefinitions) && request.toolDefinitions.length > 0;
|
|
591
505
|
}
|
|
592
506
|
buildResponsesInput(request) {
|
|
@@ -647,7 +561,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
647
561
|
strict: true,
|
|
648
562
|
defer_loading: tool.deferLoading === true
|
|
649
563
|
}));
|
|
650
|
-
return
|
|
564
|
+
return [{ type: "tool_search" }, ...nativeTools];
|
|
651
565
|
}
|
|
652
566
|
parseResponsesResult(response) {
|
|
653
567
|
const content = typeof response?.output_text === "string" ? response.output_text : "";
|
|
@@ -679,30 +593,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
679
593
|
const responsesTextFormat = toOpenAIResponsesTextFormat(
|
|
680
594
|
request.config?.responseFormat
|
|
681
595
|
);
|
|
682
|
-
const mcpTools = toOpenAIResponsesMcpTools(request.config?.mcpServers);
|
|
683
|
-
const modelId = request.config?.model || this.model;
|
|
684
|
-
const reasoning = isOpenAIReasoningModel(modelId) ? toOpenAIReasoning(request.config?.reasoningEffort) : void 0;
|
|
685
|
-
if (request.config?.reasoningEffort && !isOpenAIReasoningModel(modelId)) {
|
|
686
|
-
console.warn(
|
|
687
|
-
`[llm-sdk] openai/${modelId} is not a reasoning model; \`reasoningEffort\` is ignored. Use o1/o3/o4/gpt-5.x for reasoning.`
|
|
688
|
-
);
|
|
689
|
-
}
|
|
690
|
-
const functionTools = this.buildResponsesTools(
|
|
691
|
-
request.toolDefinitions ?? []
|
|
692
|
-
);
|
|
693
|
-
const tools = [...functionTools, ...mcpTools];
|
|
694
596
|
const payload = {
|
|
695
597
|
model: request.config?.model || this.model,
|
|
696
598
|
instructions: request.systemPrompt,
|
|
697
599
|
input: this.buildResponsesInput(request),
|
|
698
|
-
tools:
|
|
600
|
+
tools: this.buildResponsesTools(request.toolDefinitions ?? []),
|
|
699
601
|
tool_choice: openaiToolOptions?.toolChoice === "required" ? "required" : openaiToolOptions?.toolChoice === "auto" ? "auto" : void 0,
|
|
700
602
|
parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
|
|
701
603
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
702
604
|
max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
703
605
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
704
|
-
...reasoning ? { reasoning } : {},
|
|
705
|
-
store: false,
|
|
706
606
|
stream: false
|
|
707
607
|
};
|
|
708
608
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -1349,58 +1249,36 @@ var AnthropicAdapter = class {
|
|
|
1349
1249
|
if (serverToolConfiguration) {
|
|
1350
1250
|
options.server_tool_configuration = serverToolConfiguration;
|
|
1351
1251
|
}
|
|
1352
|
-
const modelForThinking = request.config?.model || this.model;
|
|
1353
|
-
const thinkingTranslation = toAnthropicThinking(
|
|
1354
|
-
request.config?.reasoningEffort,
|
|
1355
|
-
modelForThinking
|
|
1356
|
-
);
|
|
1357
1252
|
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
1358
|
-
if (outputConfig
|
|
1359
|
-
options.output_config =
|
|
1360
|
-
...outputConfig ?? {},
|
|
1361
|
-
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
1362
|
-
};
|
|
1253
|
+
if (outputConfig) {
|
|
1254
|
+
options.output_config = outputConfig;
|
|
1363
1255
|
}
|
|
1364
|
-
if (
|
|
1365
|
-
options.thinking = thinkingTranslation.thinking;
|
|
1366
|
-
} else if (this.config.thinking?.type === "enabled") {
|
|
1256
|
+
if (this.config.thinking?.type === "enabled") {
|
|
1367
1257
|
options.thinking = {
|
|
1368
1258
|
type: "enabled",
|
|
1369
1259
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1370
1260
|
};
|
|
1371
1261
|
}
|
|
1372
|
-
|
|
1373
|
-
const betas = [];
|
|
1374
|
-
if (mcp.mcpServers.length > 0) {
|
|
1375
|
-
options.mcp_servers = mcp.mcpServers;
|
|
1376
|
-
betas.push(...mcp.betas);
|
|
1377
|
-
if (mcp.tools.length > 0) {
|
|
1378
|
-
const existingTools = Array.isArray(options.tools) ? options.tools : [];
|
|
1379
|
-
options.tools = [...existingTools, ...mcp.tools];
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
return { options, messages, betas };
|
|
1262
|
+
return { options, messages };
|
|
1383
1263
|
}
|
|
1384
1264
|
/**
|
|
1385
1265
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1386
1266
|
*/
|
|
1387
1267
|
async complete(request) {
|
|
1388
1268
|
const client = await this.getClient();
|
|
1389
|
-
const { options
|
|
1269
|
+
const { options } = this.buildRequestOptions(request);
|
|
1390
1270
|
const nonStreamingOptions = {
|
|
1391
1271
|
...options,
|
|
1392
1272
|
stream: false
|
|
1393
1273
|
};
|
|
1394
1274
|
try {
|
|
1395
|
-
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1396
|
-
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1397
1275
|
logProviderPayload(
|
|
1398
1276
|
"anthropic",
|
|
1399
1277
|
"request payload",
|
|
1400
|
-
|
|
1278
|
+
nonStreamingOptions,
|
|
1401
1279
|
request.debug
|
|
1402
1280
|
);
|
|
1403
|
-
const response = await
|
|
1281
|
+
const response = await client.messages.create(nonStreamingOptions);
|
|
1404
1282
|
logProviderPayload(
|
|
1405
1283
|
"anthropic",
|
|
1406
1284
|
"response payload",
|
|
@@ -1435,19 +1313,17 @@ var AnthropicAdapter = class {
|
|
|
1435
1313
|
}
|
|
1436
1314
|
async *stream(request) {
|
|
1437
1315
|
const client = await this.getClient();
|
|
1438
|
-
const { options
|
|
1316
|
+
const { options } = this.buildRequestOptions(request);
|
|
1439
1317
|
const messageId = generateMessageId();
|
|
1440
1318
|
yield { type: "message:start", id: messageId };
|
|
1441
1319
|
try {
|
|
1442
|
-
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1443
|
-
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1444
1320
|
logProviderPayload(
|
|
1445
1321
|
"anthropic",
|
|
1446
1322
|
"request payload",
|
|
1447
|
-
|
|
1323
|
+
options,
|
|
1448
1324
|
request.debug
|
|
1449
1325
|
);
|
|
1450
|
-
const stream = await
|
|
1326
|
+
const stream = await client.messages.stream(options);
|
|
1451
1327
|
let currentToolUse = null;
|
|
1452
1328
|
let isInThinkingBlock = false;
|
|
1453
1329
|
const collectedCitations = [];
|
package/dist/adapters/index.mjs
CHANGED
|
@@ -143,6 +143,7 @@ function stripSchemaKeys(schema, keysToDrop, options = {}) {
|
|
|
143
143
|
function toOpenAIResponseFormat(rf) {
|
|
144
144
|
if (!rf) return void 0;
|
|
145
145
|
if (rf.type === "json_object") return { type: "json_object" };
|
|
146
|
+
if (rf.type !== "json_schema" || !rf.json_schema) return void 0;
|
|
146
147
|
return {
|
|
147
148
|
type: "json_schema",
|
|
148
149
|
json_schema: {
|
|
@@ -213,89 +214,9 @@ function toGeminiSchema(rf) {
|
|
|
213
214
|
function toOllamaFormat(rf) {
|
|
214
215
|
if (!rf) return void 0;
|
|
215
216
|
if (rf.type === "json_object") return "json";
|
|
217
|
+
if (rf.type !== "json_schema" || !rf.json_schema) return void 0;
|
|
216
218
|
return rf.json_schema.schema;
|
|
217
219
|
}
|
|
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
|
-
}
|
|
299
220
|
function formatTools(actions) {
|
|
300
221
|
return actions.map((action) => ({
|
|
301
222
|
type: "function",
|
|
@@ -564,6 +485,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
564
485
|
if (baseUrl.includes("generativelanguage.googleapis.com")) return "google";
|
|
565
486
|
if (baseUrl.includes("x.ai")) return "xai";
|
|
566
487
|
if (baseUrl.includes("azure")) return "azure";
|
|
488
|
+
if (baseUrl.includes("fireworks.ai")) return "fireworks";
|
|
567
489
|
return "openai";
|
|
568
490
|
}
|
|
569
491
|
async getClient() {
|
|
@@ -577,14 +499,6 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
577
499
|
return this.client;
|
|
578
500
|
}
|
|
579
501
|
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
|
-
}
|
|
588
502
|
return request.providerToolOptions?.openai?.nativeToolSearch?.enabled === true && request.providerToolOptions.openai.nativeToolSearch.useResponsesApi !== false && Array.isArray(request.toolDefinitions) && request.toolDefinitions.length > 0;
|
|
589
503
|
}
|
|
590
504
|
buildResponsesInput(request) {
|
|
@@ -645,7 +559,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
645
559
|
strict: true,
|
|
646
560
|
defer_loading: tool.deferLoading === true
|
|
647
561
|
}));
|
|
648
|
-
return
|
|
562
|
+
return [{ type: "tool_search" }, ...nativeTools];
|
|
649
563
|
}
|
|
650
564
|
parseResponsesResult(response) {
|
|
651
565
|
const content = typeof response?.output_text === "string" ? response.output_text : "";
|
|
@@ -677,30 +591,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
677
591
|
const responsesTextFormat = toOpenAIResponsesTextFormat(
|
|
678
592
|
request.config?.responseFormat
|
|
679
593
|
);
|
|
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];
|
|
692
594
|
const payload = {
|
|
693
595
|
model: request.config?.model || this.model,
|
|
694
596
|
instructions: request.systemPrompt,
|
|
695
597
|
input: this.buildResponsesInput(request),
|
|
696
|
-
tools:
|
|
598
|
+
tools: this.buildResponsesTools(request.toolDefinitions ?? []),
|
|
697
599
|
tool_choice: openaiToolOptions?.toolChoice === "required" ? "required" : openaiToolOptions?.toolChoice === "auto" ? "auto" : void 0,
|
|
698
600
|
parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
|
|
699
601
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
700
602
|
max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
701
603
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
702
|
-
...reasoning ? { reasoning } : {},
|
|
703
|
-
store: false,
|
|
704
604
|
stream: false
|
|
705
605
|
};
|
|
706
606
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -1347,58 +1247,36 @@ var AnthropicAdapter = class {
|
|
|
1347
1247
|
if (serverToolConfiguration) {
|
|
1348
1248
|
options.server_tool_configuration = serverToolConfiguration;
|
|
1349
1249
|
}
|
|
1350
|
-
const modelForThinking = request.config?.model || this.model;
|
|
1351
|
-
const thinkingTranslation = toAnthropicThinking(
|
|
1352
|
-
request.config?.reasoningEffort,
|
|
1353
|
-
modelForThinking
|
|
1354
|
-
);
|
|
1355
1250
|
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
1356
|
-
if (outputConfig
|
|
1357
|
-
options.output_config =
|
|
1358
|
-
...outputConfig ?? {},
|
|
1359
|
-
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
1360
|
-
};
|
|
1251
|
+
if (outputConfig) {
|
|
1252
|
+
options.output_config = outputConfig;
|
|
1361
1253
|
}
|
|
1362
|
-
if (
|
|
1363
|
-
options.thinking = thinkingTranslation.thinking;
|
|
1364
|
-
} else if (this.config.thinking?.type === "enabled") {
|
|
1254
|
+
if (this.config.thinking?.type === "enabled") {
|
|
1365
1255
|
options.thinking = {
|
|
1366
1256
|
type: "enabled",
|
|
1367
1257
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1368
1258
|
};
|
|
1369
1259
|
}
|
|
1370
|
-
|
|
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 };
|
|
1260
|
+
return { options, messages };
|
|
1381
1261
|
}
|
|
1382
1262
|
/**
|
|
1383
1263
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1384
1264
|
*/
|
|
1385
1265
|
async complete(request) {
|
|
1386
1266
|
const client = await this.getClient();
|
|
1387
|
-
const { options
|
|
1267
|
+
const { options } = this.buildRequestOptions(request);
|
|
1388
1268
|
const nonStreamingOptions = {
|
|
1389
1269
|
...options,
|
|
1390
1270
|
stream: false
|
|
1391
1271
|
};
|
|
1392
1272
|
try {
|
|
1393
|
-
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1394
|
-
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1395
1273
|
logProviderPayload(
|
|
1396
1274
|
"anthropic",
|
|
1397
1275
|
"request payload",
|
|
1398
|
-
|
|
1276
|
+
nonStreamingOptions,
|
|
1399
1277
|
request.debug
|
|
1400
1278
|
);
|
|
1401
|
-
const response = await
|
|
1279
|
+
const response = await client.messages.create(nonStreamingOptions);
|
|
1402
1280
|
logProviderPayload(
|
|
1403
1281
|
"anthropic",
|
|
1404
1282
|
"response payload",
|
|
@@ -1433,19 +1311,17 @@ var AnthropicAdapter = class {
|
|
|
1433
1311
|
}
|
|
1434
1312
|
async *stream(request) {
|
|
1435
1313
|
const client = await this.getClient();
|
|
1436
|
-
const { options
|
|
1314
|
+
const { options } = this.buildRequestOptions(request);
|
|
1437
1315
|
const messageId = generateMessageId();
|
|
1438
1316
|
yield { type: "message:start", id: messageId };
|
|
1439
1317
|
try {
|
|
1440
|
-
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1441
|
-
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1442
1318
|
logProviderPayload(
|
|
1443
1319
|
"anthropic",
|
|
1444
1320
|
"request payload",
|
|
1445
|
-
|
|
1321
|
+
options,
|
|
1446
1322
|
request.debug
|
|
1447
1323
|
);
|
|
1448
|
-
const stream = await
|
|
1324
|
+
const stream = await client.messages.stream(options);
|
|
1449
1325
|
let currentToolUse = null;
|
|
1450
1326
|
let isInThinkingBlock = false;
|
|
1451
1327
|
const collectedCitations = [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, X as LLMConfig, a6 as MessageAttachment } from './types-BkQCSiIt.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Request-level LLM configuration overrides
|
|
@@ -8,10 +8,6 @@ interface RequestLLMConfig {
|
|
|
8
8
|
temperature?: number;
|
|
9
9
|
maxTokens?: number;
|
|
10
10
|
responseFormat?: ResponseFormat;
|
|
11
|
-
/** MCP servers exposed to the model for this request (provider-translated). */
|
|
12
|
-
mcpServers?: McpServerConfig[];
|
|
13
|
-
/** Reasoning/thinking effort knob (provider-translated). */
|
|
14
|
-
reasoningEffort?: ReasoningEffort;
|
|
15
11
|
}
|
|
16
12
|
/**
|
|
17
13
|
* Chat completion request
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, X as LLMConfig, a6 as MessageAttachment } from './types-BkQCSiIt.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Request-level LLM configuration overrides
|
|
@@ -8,10 +8,6 @@ interface RequestLLMConfig {
|
|
|
8
8
|
temperature?: number;
|
|
9
9
|
maxTokens?: number;
|
|
10
10
|
responseFormat?: ResponseFormat;
|
|
11
|
-
/** MCP servers exposed to the model for this request (provider-translated). */
|
|
12
|
-
mcpServers?: McpServerConfig[];
|
|
13
|
-
/** Reasoning/thinking effort knob (provider-translated). */
|
|
14
|
-
reasoningEffort?: ReasoningEffort;
|
|
15
11
|
}
|
|
16
12
|
/**
|
|
17
13
|
* Chat completion request
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-tNgbBaSo.mjs';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-B6dhnguR.mjs';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-B6dhnguR.mjs';
|
|
4
|
+
import '../types-BkQCSiIt.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/fallback/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-C58Dsr9p.js';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-CCxPmkmK.js';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-CCxPmkmK.js';
|
|
4
|
+
import '../types-BkQCSiIt.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|