@yourgpt/llm-sdk 2.5.1-beta.1 → 2.5.1-beta.2
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 +14 -139
- package/dist/adapters/index.mjs +14 -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 +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/fireworks/index.js +1 -0
- package/dist/providers/fireworks/index.mjs +1 -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 +3 -51
- package/dist/providers/google/index.mjs +3 -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 +3 -51
- package/dist/providers/openai/index.mjs +3 -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 +3 -51
- package/dist/providers/openrouter/index.mjs +3 -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 +3 -51
- package/dist/providers/togetherai/index.mjs +3 -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 +3 -51
- package/dist/providers/xai/index.mjs +3 -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",
|
|
@@ -579,14 +500,6 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
579
500
|
return this.client;
|
|
580
501
|
}
|
|
581
502
|
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
503
|
return request.providerToolOptions?.openai?.nativeToolSearch?.enabled === true && request.providerToolOptions.openai.nativeToolSearch.useResponsesApi !== false && Array.isArray(request.toolDefinitions) && request.toolDefinitions.length > 0;
|
|
591
504
|
}
|
|
592
505
|
buildResponsesInput(request) {
|
|
@@ -647,7 +560,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
647
560
|
strict: true,
|
|
648
561
|
defer_loading: tool.deferLoading === true
|
|
649
562
|
}));
|
|
650
|
-
return
|
|
563
|
+
return [{ type: "tool_search" }, ...nativeTools];
|
|
651
564
|
}
|
|
652
565
|
parseResponsesResult(response) {
|
|
653
566
|
const content = typeof response?.output_text === "string" ? response.output_text : "";
|
|
@@ -679,30 +592,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
679
592
|
const responsesTextFormat = toOpenAIResponsesTextFormat(
|
|
680
593
|
request.config?.responseFormat
|
|
681
594
|
);
|
|
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
595
|
const payload = {
|
|
695
596
|
model: request.config?.model || this.model,
|
|
696
597
|
instructions: request.systemPrompt,
|
|
697
598
|
input: this.buildResponsesInput(request),
|
|
698
|
-
tools:
|
|
599
|
+
tools: this.buildResponsesTools(request.toolDefinitions ?? []),
|
|
699
600
|
tool_choice: openaiToolOptions?.toolChoice === "required" ? "required" : openaiToolOptions?.toolChoice === "auto" ? "auto" : void 0,
|
|
700
601
|
parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
|
|
701
602
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
702
603
|
max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
703
604
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
704
|
-
...reasoning ? { reasoning } : {},
|
|
705
|
-
store: false,
|
|
706
605
|
stream: false
|
|
707
606
|
};
|
|
708
607
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -1349,58 +1248,36 @@ var AnthropicAdapter = class {
|
|
|
1349
1248
|
if (serverToolConfiguration) {
|
|
1350
1249
|
options.server_tool_configuration = serverToolConfiguration;
|
|
1351
1250
|
}
|
|
1352
|
-
const modelForThinking = request.config?.model || this.model;
|
|
1353
|
-
const thinkingTranslation = toAnthropicThinking(
|
|
1354
|
-
request.config?.reasoningEffort,
|
|
1355
|
-
modelForThinking
|
|
1356
|
-
);
|
|
1357
1251
|
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
1358
|
-
if (outputConfig
|
|
1359
|
-
options.output_config =
|
|
1360
|
-
...outputConfig ?? {},
|
|
1361
|
-
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
1362
|
-
};
|
|
1252
|
+
if (outputConfig) {
|
|
1253
|
+
options.output_config = outputConfig;
|
|
1363
1254
|
}
|
|
1364
|
-
if (
|
|
1365
|
-
options.thinking = thinkingTranslation.thinking;
|
|
1366
|
-
} else if (this.config.thinking?.type === "enabled") {
|
|
1255
|
+
if (this.config.thinking?.type === "enabled") {
|
|
1367
1256
|
options.thinking = {
|
|
1368
1257
|
type: "enabled",
|
|
1369
1258
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1370
1259
|
};
|
|
1371
1260
|
}
|
|
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 };
|
|
1261
|
+
return { options, messages };
|
|
1383
1262
|
}
|
|
1384
1263
|
/**
|
|
1385
1264
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1386
1265
|
*/
|
|
1387
1266
|
async complete(request) {
|
|
1388
1267
|
const client = await this.getClient();
|
|
1389
|
-
const { options
|
|
1268
|
+
const { options } = this.buildRequestOptions(request);
|
|
1390
1269
|
const nonStreamingOptions = {
|
|
1391
1270
|
...options,
|
|
1392
1271
|
stream: false
|
|
1393
1272
|
};
|
|
1394
1273
|
try {
|
|
1395
|
-
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1396
|
-
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1397
1274
|
logProviderPayload(
|
|
1398
1275
|
"anthropic",
|
|
1399
1276
|
"request payload",
|
|
1400
|
-
|
|
1277
|
+
nonStreamingOptions,
|
|
1401
1278
|
request.debug
|
|
1402
1279
|
);
|
|
1403
|
-
const response = await
|
|
1280
|
+
const response = await client.messages.create(nonStreamingOptions);
|
|
1404
1281
|
logProviderPayload(
|
|
1405
1282
|
"anthropic",
|
|
1406
1283
|
"response payload",
|
|
@@ -1435,19 +1312,17 @@ var AnthropicAdapter = class {
|
|
|
1435
1312
|
}
|
|
1436
1313
|
async *stream(request) {
|
|
1437
1314
|
const client = await this.getClient();
|
|
1438
|
-
const { options
|
|
1315
|
+
const { options } = this.buildRequestOptions(request);
|
|
1439
1316
|
const messageId = generateMessageId();
|
|
1440
1317
|
yield { type: "message:start", id: messageId };
|
|
1441
1318
|
try {
|
|
1442
|
-
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1443
|
-
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1444
1319
|
logProviderPayload(
|
|
1445
1320
|
"anthropic",
|
|
1446
1321
|
"request payload",
|
|
1447
|
-
|
|
1322
|
+
options,
|
|
1448
1323
|
request.debug
|
|
1449
1324
|
);
|
|
1450
|
-
const stream = await
|
|
1325
|
+
const stream = await client.messages.stream(options);
|
|
1451
1326
|
let currentToolUse = null;
|
|
1452
1327
|
let isInThinkingBlock = false;
|
|
1453
1328
|
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",
|
|
@@ -577,14 +498,6 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
577
498
|
return this.client;
|
|
578
499
|
}
|
|
579
500
|
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
501
|
return request.providerToolOptions?.openai?.nativeToolSearch?.enabled === true && request.providerToolOptions.openai.nativeToolSearch.useResponsesApi !== false && Array.isArray(request.toolDefinitions) && request.toolDefinitions.length > 0;
|
|
589
502
|
}
|
|
590
503
|
buildResponsesInput(request) {
|
|
@@ -645,7 +558,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
645
558
|
strict: true,
|
|
646
559
|
defer_loading: tool.deferLoading === true
|
|
647
560
|
}));
|
|
648
|
-
return
|
|
561
|
+
return [{ type: "tool_search" }, ...nativeTools];
|
|
649
562
|
}
|
|
650
563
|
parseResponsesResult(response) {
|
|
651
564
|
const content = typeof response?.output_text === "string" ? response.output_text : "";
|
|
@@ -677,30 +590,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
677
590
|
const responsesTextFormat = toOpenAIResponsesTextFormat(
|
|
678
591
|
request.config?.responseFormat
|
|
679
592
|
);
|
|
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
593
|
const payload = {
|
|
693
594
|
model: request.config?.model || this.model,
|
|
694
595
|
instructions: request.systemPrompt,
|
|
695
596
|
input: this.buildResponsesInput(request),
|
|
696
|
-
tools:
|
|
597
|
+
tools: this.buildResponsesTools(request.toolDefinitions ?? []),
|
|
697
598
|
tool_choice: openaiToolOptions?.toolChoice === "required" ? "required" : openaiToolOptions?.toolChoice === "auto" ? "auto" : void 0,
|
|
698
599
|
parallel_tool_calls: openaiToolOptions?.parallelToolCalls,
|
|
699
600
|
temperature: request.config?.temperature ?? this.config.temperature,
|
|
700
601
|
max_output_tokens: request.config?.maxTokens ?? this.config.maxTokens,
|
|
701
602
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
702
|
-
...reasoning ? { reasoning } : {},
|
|
703
|
-
store: false,
|
|
704
603
|
stream: false
|
|
705
604
|
};
|
|
706
605
|
logProviderPayload("openai", "request payload", payload, request.debug);
|
|
@@ -1347,58 +1246,36 @@ var AnthropicAdapter = class {
|
|
|
1347
1246
|
if (serverToolConfiguration) {
|
|
1348
1247
|
options.server_tool_configuration = serverToolConfiguration;
|
|
1349
1248
|
}
|
|
1350
|
-
const modelForThinking = request.config?.model || this.model;
|
|
1351
|
-
const thinkingTranslation = toAnthropicThinking(
|
|
1352
|
-
request.config?.reasoningEffort,
|
|
1353
|
-
modelForThinking
|
|
1354
|
-
);
|
|
1355
1249
|
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
1356
|
-
if (outputConfig
|
|
1357
|
-
options.output_config =
|
|
1358
|
-
...outputConfig ?? {},
|
|
1359
|
-
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
1360
|
-
};
|
|
1250
|
+
if (outputConfig) {
|
|
1251
|
+
options.output_config = outputConfig;
|
|
1361
1252
|
}
|
|
1362
|
-
if (
|
|
1363
|
-
options.thinking = thinkingTranslation.thinking;
|
|
1364
|
-
} else if (this.config.thinking?.type === "enabled") {
|
|
1253
|
+
if (this.config.thinking?.type === "enabled") {
|
|
1365
1254
|
options.thinking = {
|
|
1366
1255
|
type: "enabled",
|
|
1367
1256
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1368
1257
|
};
|
|
1369
1258
|
}
|
|
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 };
|
|
1259
|
+
return { options, messages };
|
|
1381
1260
|
}
|
|
1382
1261
|
/**
|
|
1383
1262
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1384
1263
|
*/
|
|
1385
1264
|
async complete(request) {
|
|
1386
1265
|
const client = await this.getClient();
|
|
1387
|
-
const { options
|
|
1266
|
+
const { options } = this.buildRequestOptions(request);
|
|
1388
1267
|
const nonStreamingOptions = {
|
|
1389
1268
|
...options,
|
|
1390
1269
|
stream: false
|
|
1391
1270
|
};
|
|
1392
1271
|
try {
|
|
1393
|
-
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1394
|
-
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1395
1272
|
logProviderPayload(
|
|
1396
1273
|
"anthropic",
|
|
1397
1274
|
"request payload",
|
|
1398
|
-
|
|
1275
|
+
nonStreamingOptions,
|
|
1399
1276
|
request.debug
|
|
1400
1277
|
);
|
|
1401
|
-
const response = await
|
|
1278
|
+
const response = await client.messages.create(nonStreamingOptions);
|
|
1402
1279
|
logProviderPayload(
|
|
1403
1280
|
"anthropic",
|
|
1404
1281
|
"response payload",
|
|
@@ -1433,19 +1310,17 @@ var AnthropicAdapter = class {
|
|
|
1433
1310
|
}
|
|
1434
1311
|
async *stream(request) {
|
|
1435
1312
|
const client = await this.getClient();
|
|
1436
|
-
const { options
|
|
1313
|
+
const { options } = this.buildRequestOptions(request);
|
|
1437
1314
|
const messageId = generateMessageId();
|
|
1438
1315
|
yield { type: "message:start", id: messageId };
|
|
1439
1316
|
try {
|
|
1440
|
-
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1441
|
-
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1442
1317
|
logProviderPayload(
|
|
1443
1318
|
"anthropic",
|
|
1444
1319
|
"request payload",
|
|
1445
|
-
|
|
1320
|
+
options,
|
|
1446
1321
|
request.debug
|
|
1447
1322
|
);
|
|
1448
|
-
const stream = await
|
|
1323
|
+
const stream = await client.messages.stream(options);
|
|
1449
1324
|
let currentToolUse = null;
|
|
1450
1325
|
let isInThinkingBlock = false;
|
|
1451
1326
|
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
|
/**
|