@madgagarin/pi-agentrouter 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/index.ts +20 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -29,8 +29,20 @@ export function saveConfig(cfg: AgentRouterConfig): void {
29
29
  } catch {}
30
30
  }
31
31
 
32
+ export function normalizeApiKey(key?: string): string {
33
+ if (!key) return "";
34
+ let clean = key.trim().replace(/^["']|["']$/g, "").trim();
35
+ if (clean.toLowerCase().startsWith("bearer ")) {
36
+ clean = clean.slice(7).trim();
37
+ }
38
+ if (clean.startsWith("sk-")) {
39
+ clean = clean.slice(3).trim();
40
+ }
41
+ return clean;
42
+ }
43
+
32
44
  const initialConfig = loadConfig();
33
- let currentApiKey = process.env.AGENTROUTER_API_KEY || initialConfig.apiKey || "";
45
+ let currentApiKey = normalizeApiKey(process.env.AGENTROUTER_API_KEY || initialConfig.apiKey || "");
34
46
  let minIntervalMs = initialConfig.minIntervalMs ?? 2500;
35
47
  let lastRequestTime = 0;
36
48
 
@@ -201,15 +213,16 @@ export default function (pi: ExtensionAPI) {
201
213
  const action = parts[0]?.toLowerCase();
202
214
 
203
215
  if (action === "key" || action === "set-key") {
204
- const newKey = parts[1]?.trim();
205
- if (!newKey || newKey.length < 5) {
216
+ const rawKey = parts[1]?.trim();
217
+ const cleanKey = normalizeApiKey(rawKey);
218
+ if (!cleanKey || cleanKey.length < 5) {
206
219
  ctx.ui.notify("Please provide a valid API key: /agentrouter key <your-key>", "error");
207
220
  return;
208
221
  }
209
- currentApiKey = newKey;
210
- saveConfig({ apiKey: newKey, minIntervalMs });
211
- registerAgentRouterProviders(newKey);
212
- ctx.ui.notify("AgentRouter API key updated successfully for all models.", "info");
222
+ currentApiKey = cleanKey;
223
+ saveConfig({ apiKey: cleanKey, minIntervalMs });
224
+ registerAgentRouterProviders(cleanKey);
225
+ ctx.ui.notify("AgentRouter API key updated and normalized successfully for all models.", "info");
213
226
  return;
214
227
  }
215
228
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgagarin/pi-agentrouter",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Pi coding agent extension for AgentRouter (GPT-5.6 Sol & Claude Opus 5) with rate-limit pacing and caching.",
5
5
  "publishConfig": {
6
6
  "access": "public"