@madgagarin/pi-agentrouter 1.0.3 → 1.1.0

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 (3) hide show
  1. package/README.md +1 -1
  2. package/index.ts +24 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @madgagarin/pi-agentrouter
1
+ # pi-agentrouter
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@madgagarin/pi-agentrouter.svg?color=blue)](https://www.npmjs.com/package/@madgagarin/pi-agentrouter)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
package/index.ts CHANGED
@@ -31,14 +31,7 @@ export function saveConfig(cfg: AgentRouterConfig): void {
31
31
 
32
32
  export function normalizeApiKey(key?: string): string {
33
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;
34
+ return key.trim().replace(/^["']|["']$/g, "").trim();
42
35
  }
43
36
 
44
37
  const initialConfig = loadConfig();
@@ -117,8 +110,30 @@ export default function (pi: ExtensionAPI) {
117
110
 
118
111
  registerAgentRouterProviders(currentApiKey);
119
112
 
113
+ function updatePromptRewriteEnvForModel(model?: any): void {
114
+ if (isAgentRouter(model?.provider, model?.baseUrl)) {
115
+ process.env.PI_CACHE_OPTIMIZER_NO_PROMPT_REWRITE = "1";
116
+ } else {
117
+ delete process.env.PI_CACHE_OPTIMIZER_NO_PROMPT_REWRITE;
118
+ }
119
+ }
120
+
121
+ pi.on("session_start", async (_event, ctx) => {
122
+ updatePromptRewriteEnvForModel(ctx.model);
123
+ lastRequestTime = Date.now();
124
+ });
125
+
126
+ pi.on("model_select", async (event) => {
127
+ updatePromptRewriteEnvForModel(event.model);
128
+ });
129
+
130
+ pi.on("before_agent_start", async (_event, ctx) => {
131
+ updatePromptRewriteEnvForModel(ctx.model);
132
+ });
133
+
120
134
  pi.on("turn_start", async (_event, ctx) => {
121
135
  const model = ctx.model;
136
+ updatePromptRewriteEnvForModel(model);
122
137
  if (!isAgentRouter(model?.provider, (model as any)?.baseUrl)) {
123
138
  return;
124
139
  }
@@ -222,7 +237,7 @@ export default function (pi: ExtensionAPI) {
222
237
  currentApiKey = cleanKey;
223
238
  saveConfig({ apiKey: cleanKey, minIntervalMs });
224
239
  registerAgentRouterProviders(cleanKey);
225
- ctx.ui.notify("AgentRouter API key updated and normalized successfully for all models.", "info");
240
+ ctx.ui.notify("AgentRouter API key updated successfully for all models.", "info");
226
241
  return;
227
242
  }
228
243
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgagarin/pi-agentrouter",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
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"