@wrongstack/providers 0.264.0 → 0.265.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/dist/index.js +23 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -537,8 +537,11 @@ function normalizeGemini(stop) {
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// src/tool-format/to-anthropic.ts
|
|
540
|
+
var _cache = /* @__PURE__ */ new WeakMap();
|
|
540
541
|
function toolsToAnthropic(tools) {
|
|
541
|
-
|
|
542
|
+
const hit = _cache.get(tools);
|
|
543
|
+
if (hit) return hit;
|
|
544
|
+
const result = tools.map((t) => ({
|
|
542
545
|
name: t.name,
|
|
543
546
|
description: t.description,
|
|
544
547
|
input_schema: t.inputSchema ?? {
|
|
@@ -546,6 +549,8 @@ function toolsToAnthropic(tools) {
|
|
|
546
549
|
properties: {}
|
|
547
550
|
}
|
|
548
551
|
}));
|
|
552
|
+
_cache.set(tools, result);
|
|
553
|
+
return result;
|
|
549
554
|
}
|
|
550
555
|
|
|
551
556
|
// src/stream-debug-state.ts
|
|
@@ -1196,18 +1201,23 @@ async function* parseGoogleStream(body, fallbackModel) {
|
|
|
1196
1201
|
init_tool_input();
|
|
1197
1202
|
|
|
1198
1203
|
// src/tool-format/to-openai.ts
|
|
1204
|
+
var _cache2 = /* @__PURE__ */ new WeakMap();
|
|
1199
1205
|
function toolsToOpenAI(tools) {
|
|
1200
|
-
|
|
1206
|
+
const hit = _cache2.get(tools);
|
|
1207
|
+
if (hit) return hit;
|
|
1208
|
+
const result = tools.map((t) => ({
|
|
1201
1209
|
type: "function",
|
|
1202
1210
|
function: {
|
|
1203
1211
|
name: t.name,
|
|
1204
|
-
description: t.description,
|
|
1212
|
+
description: t.description ?? "",
|
|
1205
1213
|
parameters: t.inputSchema ?? {
|
|
1206
1214
|
type: "object",
|
|
1207
1215
|
properties: {}
|
|
1208
1216
|
}
|
|
1209
1217
|
}
|
|
1210
1218
|
}));
|
|
1219
|
+
_cache2.set(tools, result);
|
|
1220
|
+
return result;
|
|
1211
1221
|
}
|
|
1212
1222
|
function messagesToOpenAI(system, messages, opts = {}) {
|
|
1213
1223
|
const emptyContentMode = opts.emptyToolCallContent ?? "empty_string";
|
|
@@ -2442,10 +2452,17 @@ async function buildProviderFactoriesFromRegistry(opts) {
|
|
|
2442
2452
|
}
|
|
2443
2453
|
return factories;
|
|
2444
2454
|
}
|
|
2455
|
+
function resolveActiveKey(cfg) {
|
|
2456
|
+
if (Array.isArray(cfg.apiKeys) && cfg.apiKeys.length > 0) {
|
|
2457
|
+
const active = cfg.activeKey ? cfg.apiKeys.find((k) => k.label === cfg.activeKey) : void 0;
|
|
2458
|
+
return (active ?? cfg.apiKeys[0])?.apiKey;
|
|
2459
|
+
}
|
|
2460
|
+
return cfg.apiKey && cfg.apiKey.length > 0 ? cfg.apiKey : void 0;
|
|
2461
|
+
}
|
|
2445
2462
|
function makeProvider(p, cfg) {
|
|
2446
2463
|
const family = cfg.family ?? p.family;
|
|
2447
2464
|
const envVars = cfg.envVars && cfg.envVars.length > 0 ? cfg.envVars : p.envVars;
|
|
2448
|
-
const apiKey = cfg
|
|
2465
|
+
const apiKey = resolveActiveKey(cfg) ?? readFromEnv(envVars);
|
|
2449
2466
|
if (!apiKey && family !== "unsupported") {
|
|
2450
2467
|
throw new Error(
|
|
2451
2468
|
`Provider "${p.id}" requires an API key. Set ${envVars.join(" or ") || "apiKey in config"} or run \`wstack auth ${p.id}\`.`
|
|
@@ -2510,7 +2527,8 @@ function readFromEnv(vars) {
|
|
|
2510
2527
|
return void 0;
|
|
2511
2528
|
}
|
|
2512
2529
|
function requireKey(cfg) {
|
|
2513
|
-
|
|
2530
|
+
const key = resolveActiveKey(cfg);
|
|
2531
|
+
if (key) return key;
|
|
2514
2532
|
throw new Error("Provider config requires apiKey (or set the corresponding env var).");
|
|
2515
2533
|
}
|
|
2516
2534
|
function validateQuirks(providerId, quirks) {
|