@madgagarin/pi-agentrouter 1.0.0 → 1.0.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/index.ts +27 -7
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -27,10 +27,20 @@ export function saveConfig(cfg: AgentRouterConfig): void {
|
|
|
27
27
|
}
|
|
28
28
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2), "utf-8");
|
|
29
29
|
} catch {}
|
|
30
|
+
export function normalizeApiKey(key?: string): string {
|
|
31
|
+
if (!key) return "";
|
|
32
|
+
let clean = key.trim().replace(/^["']|["']$/g, "").trim();
|
|
33
|
+
if (clean.toLowerCase().startsWith("bearer ")) {
|
|
34
|
+
clean = clean.slice(7).trim();
|
|
35
|
+
}
|
|
36
|
+
if (clean.startsWith("sk-")) {
|
|
37
|
+
clean = clean.slice(3).trim();
|
|
38
|
+
}
|
|
39
|
+
return clean;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
const initialConfig = loadConfig();
|
|
33
|
-
let currentApiKey = process.env.AGENTROUTER_API_KEY || initialConfig.apiKey || "";
|
|
43
|
+
let currentApiKey = normalizeApiKey(process.env.AGENTROUTER_API_KEY || initialConfig.apiKey || "");
|
|
34
44
|
let minIntervalMs = initialConfig.minIntervalMs ?? 2500;
|
|
35
45
|
let lastRequestTime = 0;
|
|
36
46
|
|
|
@@ -59,6 +69,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
59
69
|
contextWindow: 1048576,
|
|
60
70
|
maxTokens: 131072,
|
|
61
71
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
72
|
+
compat: {
|
|
73
|
+
sendSessionAffinityHeaders: true,
|
|
74
|
+
},
|
|
62
75
|
},
|
|
63
76
|
],
|
|
64
77
|
});
|
|
@@ -80,6 +93,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
80
93
|
contextWindow: 524288,
|
|
81
94
|
maxTokens: 65536,
|
|
82
95
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
96
|
+
compat: {
|
|
97
|
+
forceAdaptiveThinking: true,
|
|
98
|
+
},
|
|
83
99
|
},
|
|
84
100
|
{
|
|
85
101
|
id: "claude-opus-5",
|
|
@@ -89,6 +105,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
89
105
|
contextWindow: 1048576,
|
|
90
106
|
maxTokens: 65536,
|
|
91
107
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
108
|
+
compat: {
|
|
109
|
+
forceAdaptiveThinking: true,
|
|
110
|
+
},
|
|
92
111
|
},
|
|
93
112
|
],
|
|
94
113
|
});
|
|
@@ -192,15 +211,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
192
211
|
const action = parts[0]?.toLowerCase();
|
|
193
212
|
|
|
194
213
|
if (action === "key" || action === "set-key") {
|
|
195
|
-
const
|
|
196
|
-
|
|
214
|
+
const rawKey = parts[1]?.trim();
|
|
215
|
+
const cleanKey = normalizeApiKey(rawKey);
|
|
216
|
+
if (!cleanKey || cleanKey.length < 5) {
|
|
197
217
|
ctx.ui.notify("Please provide a valid API key: /agentrouter key <your-key>", "error");
|
|
198
218
|
return;
|
|
199
219
|
}
|
|
200
|
-
currentApiKey =
|
|
201
|
-
saveConfig({ apiKey:
|
|
202
|
-
registerAgentRouterProviders(
|
|
203
|
-
ctx.ui.notify("AgentRouter API key updated successfully for all models.", "info");
|
|
220
|
+
currentApiKey = cleanKey;
|
|
221
|
+
saveConfig({ apiKey: cleanKey, minIntervalMs });
|
|
222
|
+
registerAgentRouterProviders(cleanKey);
|
|
223
|
+
ctx.ui.notify("AgentRouter API key updated and normalized successfully for all models.", "info");
|
|
204
224
|
return;
|
|
205
225
|
}
|
|
206
226
|
|
package/package.json
CHANGED