pi-cliproxyapi 0.4.0 → 0.4.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/README.md +40 -67
- package/package.json +1 -1
- package/src/config.ts +2 -2
- package/src/ui-setup.ts +1 -9
- package/src/usage-shared-cache.ts +9 -2
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ Extra Models keys: `d` removes a custom group (with confirmation).
|
|
|
71
71
|
|
|
72
72
|
You need a running [CliProxyAPI](https://github.com/router-for-me/CLIProxyAPI) instance — this is the corporate LLM proxy that aggregates multiple providers behind a single OpenAI-compatible endpoint.
|
|
73
73
|
|
|
74
|
-
For full functionality (Usage tab, enriched model metadata from [models.dev](https://models.dev)), also
|
|
74
|
+
For full functionality (Usage tab, enriched model metadata from [models.dev](https://models.dev)), also install the **[pi-bridge](https://github.com/abix5/pi-cliproxyapi-bridge)** plugin into that instance. See [Discovery](#discovery) below.
|
|
75
75
|
|
|
76
76
|
## Install
|
|
77
77
|
|
|
@@ -117,8 +117,7 @@ cache.
|
|
|
117
117
|
"proxy": {
|
|
118
118
|
"endpoint": "https://proxy.example.com/v1",
|
|
119
119
|
"apiKey": "!cat ~/.pi/agent/pi-cliproxyapi/key",
|
|
120
|
-
"providerPrefix": "corp"
|
|
121
|
-
"usageKey": "!cat ~/.pi/agent/pi-cliproxyapi/usage-key"
|
|
120
|
+
"providerPrefix": "corp"
|
|
122
121
|
},
|
|
123
122
|
"builtinProviders": {
|
|
124
123
|
"anthropic": { "enabled": true, "models": ["claude-opus-4-7"] },
|
|
@@ -137,82 +136,56 @@ Values support `!command` (shell exec), `$ENV_VAR`, or literal strings. The `/cl
|
|
|
137
136
|
|
|
138
137
|
## Discovery
|
|
139
138
|
|
|
140
|
-
The
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
The **[pi-cliproxyapi-wellknown](https://github.com/abix5/pi-cliproxyapi-wellknown)** sidecar runs alongside CliProxyAPI and provides:
|
|
145
|
-
|
|
146
|
-
- `/.well-known/pi` — model discovery with metadata from [models.dev](https://models.dev) (context windows, costs, reasoning flags)
|
|
147
|
-
- `/api/usage` — per-account quota windows used by the hub Usage tab
|
|
139
|
+
The extension reads the model catalogue and provider quota from the
|
|
140
|
+
**[pi-bridge](https://github.com/abix5/pi-cliproxyapi-bridge)** plugin running
|
|
141
|
+
inside CliProxyAPI, authenticating with the same `apiKey` it uses for model
|
|
142
|
+
calls. No second credential and no extra container are involved.
|
|
148
143
|
|
|
149
144
|
```
|
|
150
|
-
┌──────────────┐
|
|
151
|
-
│ Pi + plugin │────▶│ CliProxyAPI
|
|
152
|
-
│ │ │ /v1/models, /v1/chat/...
|
|
153
|
-
│ │
|
|
154
|
-
│ │
|
|
155
|
-
│
|
|
156
|
-
|
|
157
|
-
│ │ │ /api/usage │
|
|
158
|
-
│ │ └───────────────────────────┘
|
|
159
|
-
└──────────────┘
|
|
145
|
+
┌──────────────┐ ┌────────────────────────────────────────┐
|
|
146
|
+
│ Pi + plugin │────▶│ CliProxyAPI │
|
|
147
|
+
│ │ │ /v1/models, /v1/chat/... │
|
|
148
|
+
│ │ │ /v0/resource/plugins/pi-bridge/… │
|
|
149
|
+
│ │ │ well-known → model catalogue │
|
|
150
|
+
│ │ │ usage → per-account quota │
|
|
151
|
+
└──────────────┘ └────────────────────────────────────────┘
|
|
160
152
|
```
|
|
161
153
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
Clone the sidecar repo next to your CliProxyAPI deployment:
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
git clone https://github.com/abix5/pi-cliproxyapi-wellknown.git
|
|
168
|
-
```
|
|
154
|
+
Without the plugin the extension still works: it falls back to raw `/v1/models`
|
|
155
|
+
with local heuristics.
|
|
169
156
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
# ... your existing CliProxyAPI service ...
|
|
176
|
-
|
|
177
|
-
pi-cliproxyapi-wellknown:
|
|
178
|
-
build:
|
|
179
|
-
context: ./pi-cliproxyapi-wellknown
|
|
180
|
-
restart: unless-stopped
|
|
181
|
-
ports:
|
|
182
|
-
- "127.0.0.1:3458:3458"
|
|
183
|
-
environment:
|
|
184
|
-
UPSTREAM_MODELS_URL: http://cliproxyapi:8317/v1/models
|
|
185
|
-
UPSTREAM_TOKEN: ${UPSTREAM_TOKEN} # CliProxyAPI bearer key
|
|
186
|
-
PI_PUBLIC_BASE_URL: ${PI_PUBLIC_BASE_URL} # e.g. https://proxy.example.com/v1
|
|
187
|
-
MANAGEMENT_API_URL: http://cliproxyapi:8317/v0/management
|
|
188
|
-
MANAGEMENT_API_KEY: ${MANAGEMENT_API_KEY}
|
|
189
|
-
PI_PLUGIN_USAGE_KEY: ${PI_PLUGIN_USAGE_KEY} # shared with Pi plugin
|
|
190
|
-
depends_on:
|
|
191
|
-
cliproxyapi:
|
|
192
|
-
condition: service_healthy
|
|
193
|
-
networks:
|
|
194
|
-
- your-network
|
|
195
|
-
```
|
|
157
|
+
| | With pi-bridge | Without |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| Model discovery | Enriched from [models.dev](https://models.dev) — real context windows, costs, reasoning flags | Defaults: `contextWindow=128k`, `maxTokens=16k`, `cost=0` |
|
|
160
|
+
| Usage tab | Per-account quota bars | Unavailable |
|
|
161
|
+
| Classification | Server-side | Local heuristics by `owned_by` |
|
|
196
162
|
|
|
197
|
-
|
|
163
|
+
See the plugin's README for installing it into CliProxyAPI.
|
|
198
164
|
|
|
199
|
-
|
|
165
|
+
## Setup
|
|
200
166
|
|
|
201
167
|
Run `/cliproxy-setup` in Pi and enter:
|
|
202
168
|
|
|
203
169
|
- **endpoint** — your public proxy URL ending with `/v1`
|
|
204
170
|
- **apiKey** — CliProxyAPI bearer key
|
|
205
|
-
- **providerPrefix** — short slug for custom provider names (e.g. `corp
|
|
206
|
-
- **usageKey** — same value as `PI_PLUGIN_USAGE_KEY` above (enables the Usage tab)
|
|
171
|
+
- **providerPrefix** — short slug for custom provider names (e.g. `corp`)
|
|
207
172
|
|
|
208
|
-
|
|
173
|
+
## Migrating from the wellknown sidecar
|
|
209
174
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
175
|
+
Earlier versions read `/.well-known/pi` and `/api/usage` from a separate
|
|
176
|
+
`pi-cliproxyapi-wellknown` container, which needed its own `usageKey`. Version
|
|
177
|
+
0.4.0 reads both from the pi-bridge plugin instead.
|
|
178
|
+
|
|
179
|
+
1. Install pi-bridge into CliProxyAPI (see its README).
|
|
180
|
+
2. Update this extension to 0.4.0 or later.
|
|
181
|
+
3. Confirm the Usage tab still populates — it now says `source=plugin`.
|
|
182
|
+
4. Drop the sidecar's routes from your reverse proxy, then stop the container.
|
|
183
|
+
5. Remove `proxy.usageKey` from the config above; it is no longer read by the
|
|
184
|
+
setup wizard and is only consulted as a fallback.
|
|
185
|
+
|
|
186
|
+
Steps 1–2 are safe in either order: until the plugin answers, the extension
|
|
187
|
+
keeps using the sidecar, and a version older than 0.4.0 keeps working against a
|
|
188
|
+
server that already runs the plugin.
|
|
216
189
|
|
|
217
190
|
## Layout
|
|
218
191
|
|
|
@@ -222,8 +195,8 @@ src/
|
|
|
222
195
|
config.ts ~/.pi/agent/pi-cliproxyapi/config.json
|
|
223
196
|
commands.ts 2 slash commands (hub + setup)
|
|
224
197
|
apply.ts pi.registerProvider calls
|
|
225
|
-
fetch-models.ts
|
|
226
|
-
fetch-usage.ts
|
|
198
|
+
fetch-models.ts catalogue from pi-bridge, /v1/models fallback
|
|
199
|
+
fetch-usage.ts quota from pi-bridge, sidecar fallback, TTL cache
|
|
227
200
|
compat.ts baseUrl derivation, model classification
|
|
228
201
|
conflicts.ts read-only ~/.pi/{models,auth}.json scan
|
|
229
202
|
ui-frame.ts single source of truth for overlay frames
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// "discoveryExcludes": ["*:*"],
|
|
23
23
|
// "overrides": {},
|
|
24
24
|
// "refreshIntervalMinutes": 0,
|
|
25
|
-
// "usageCacheTtlMs":
|
|
25
|
+
// "usageCacheTtlMs": 15000
|
|
26
26
|
// }
|
|
27
27
|
|
|
28
28
|
import { execSync } from "node:child_process";
|
|
@@ -143,7 +143,7 @@ const DEFAULT_CONFIG: ProxyConfig = {
|
|
|
143
143
|
discoveryExcludes: ["*:*"],
|
|
144
144
|
overrides: {},
|
|
145
145
|
refreshIntervalMinutes: 0,
|
|
146
|
-
usageCacheTtlMs:
|
|
146
|
+
usageCacheTtlMs: 15_000,
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
export function loadConfig(): ProxyConfig {
|
package/src/ui-setup.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// First-run setup wizard: collects endpoint + apiKey + providerPrefix
|
|
1
|
+
// First-run setup wizard: collects endpoint + apiKey + providerPrefix
|
|
2
2
|
// and writes them to ~/.pi/agent/pi-cliproxyapi/config.json.
|
|
3
3
|
//
|
|
4
4
|
// All three fields support the same "!cmd" / "$ENV" / literal semantics as
|
|
@@ -64,11 +64,6 @@ const STEPS: WizardStep[] = [
|
|
|
64
64
|
validate: (raw) =>
|
|
65
65
|
/^[a-z0-9][a-z0-9-]*$/i.test(raw) ? null : "letters/digits/dashes only",
|
|
66
66
|
},
|
|
67
|
-
{
|
|
68
|
-
label: "usageKey",
|
|
69
|
-
hint: "Optional X-Plugin-Key for /api/usage. Leave blank to skip the Usage tab",
|
|
70
|
-
required: false,
|
|
71
|
-
},
|
|
72
67
|
];
|
|
73
68
|
|
|
74
69
|
/**
|
|
@@ -96,7 +91,6 @@ export async function runSetup(
|
|
|
96
91
|
endpoint: existing.proxy.endpoint ?? "",
|
|
97
92
|
apiKey: existing.proxy.apiKey ?? "",
|
|
98
93
|
providerPrefix: existing.proxy.providerPrefix ?? "",
|
|
99
|
-
usageKey: existing.proxy.usageKey ?? "",
|
|
100
94
|
};
|
|
101
95
|
|
|
102
96
|
let cancelled = false;
|
|
@@ -141,8 +135,6 @@ export async function runSetup(
|
|
|
141
135
|
apiKey: values.apiKey ?? "",
|
|
142
136
|
providerPrefix: values.providerPrefix ?? "",
|
|
143
137
|
};
|
|
144
|
-
if (values.usageKey) next.proxy.usageKey = values.usageKey;
|
|
145
|
-
else delete next.proxy.usageKey;
|
|
146
138
|
|
|
147
139
|
saveConfig(next);
|
|
148
140
|
ctx.ui.notify(`saved to ${CONFIG_PATH}`, "info");
|
|
@@ -28,8 +28,15 @@ import { log } from "./log.ts";
|
|
|
28
28
|
export const USAGE_CACHE_PATH = join(CONFIG_DIR, "usage-cache.json");
|
|
29
29
|
export const USAGE_LOCK_PATH = join(CONFIG_DIR, "usage-cache.lock");
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Minimum interval between network fetches, shared across all Pi instances.
|
|
33
|
+
*
|
|
34
|
+
* This throttles calls to the bridge only, which are cheap: the bridge holds
|
|
35
|
+
* its own cache and is the only thing that talks to the providers, whose rate
|
|
36
|
+
* limits are the real constraint. So it can be short enough for the status line
|
|
37
|
+
* to react to a finished turn.
|
|
38
|
+
*/
|
|
39
|
+
export const USAGE_CACHE_TTL_MS = 15_000;
|
|
33
40
|
/** A lock file older than this is considered stale (process crashed). */
|
|
34
41
|
const LOCK_STALE_MS = 30_000;
|
|
35
42
|
|