@victor-software-house/pi-openai-proxy 0.2.1 → 0.2.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.
- package/README.md +12 -5
- package/extensions/proxy.ts +23 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -231,15 +231,22 @@ pi install npm:@victor-software-house/pi-openai-proxy
|
|
|
231
231
|
|
|
232
232
|
`/proxy` (or `/proxy config`) opens an interactive settings panel where you can configure the bind address, port, auth token, remote images, body size limit, and upstream timeout. Changes are saved to `~/.pi/agent/proxy-config.json` immediately. Restart the proxy to apply changes.
|
|
233
233
|
|
|
234
|
-
###
|
|
234
|
+
### Standalone (background) mode
|
|
235
|
+
|
|
236
|
+
For a proxy that outlives pi sessions, run the binary directly:
|
|
235
237
|
|
|
236
238
|
```bash
|
|
237
|
-
|
|
238
|
-
|
|
239
|
+
# Foreground
|
|
240
|
+
pi-openai-proxy
|
|
239
241
|
|
|
240
|
-
|
|
242
|
+
# Background
|
|
243
|
+
pi-openai-proxy &
|
|
244
|
+
|
|
245
|
+
# With custom port
|
|
246
|
+
PI_PROXY_PORT=8080 pi-openai-proxy &
|
|
247
|
+
```
|
|
241
248
|
|
|
242
|
-
The
|
|
249
|
+
The extension detects externally running instances and shows their status via `/proxy status` without trying to manage them.
|
|
243
250
|
|
|
244
251
|
## Architecture
|
|
245
252
|
|
package/extensions/proxy.ts
CHANGED
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
* /proxy path Show config file location
|
|
12
12
|
* /proxy reset Restore default settings
|
|
13
13
|
* /proxy help Usage line
|
|
14
|
-
*
|
|
15
|
-
* Flag:
|
|
16
|
-
* --proxy Auto-start on session start
|
|
17
14
|
*/
|
|
18
15
|
|
|
19
16
|
import {
|
|
@@ -156,23 +153,11 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
156
153
|
return `http://${config.host}:${String(config.port)}`;
|
|
157
154
|
}
|
|
158
155
|
|
|
159
|
-
// --- Flag ---
|
|
160
|
-
|
|
161
|
-
pi.registerFlag("proxy", {
|
|
162
|
-
description: "Start the OpenAI proxy on session start",
|
|
163
|
-
type: "boolean",
|
|
164
|
-
default: false,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
156
|
// --- Lifecycle ---
|
|
168
157
|
|
|
169
158
|
pi.on("session_start", async (_event, ctx) => {
|
|
170
159
|
config = loadConfig();
|
|
171
|
-
|
|
172
|
-
await startProxy(ctx);
|
|
173
|
-
} else {
|
|
174
|
-
await refreshStatus(ctx);
|
|
175
|
-
}
|
|
160
|
+
await refreshStatus(ctx);
|
|
176
161
|
});
|
|
177
162
|
|
|
178
163
|
pi.on("session_shutdown", async () => {
|
|
@@ -359,10 +344,12 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
359
344
|
|
|
360
345
|
async function showConfig(ctx: ExtensionContext): Promise<void> {
|
|
361
346
|
config = loadConfig();
|
|
347
|
+
const authDisplay =
|
|
348
|
+
config.authToken.length > 0 ? `enabled (token: ${config.authToken})` : "disabled";
|
|
362
349
|
const lines = [
|
|
363
350
|
`host: ${config.host}`,
|
|
364
351
|
`port: ${String(config.port)}`,
|
|
365
|
-
`auth: ${
|
|
352
|
+
`auth: ${authDisplay}`,
|
|
366
353
|
`remote images: ${String(config.remoteImages)}`,
|
|
367
354
|
`max body: ${String(config.maxBodySizeMb)} MB`,
|
|
368
355
|
`upstream timeout: ${String(config.upstreamTimeoutSec)}s`,
|
|
@@ -391,6 +378,8 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
391
378
|
|
|
392
379
|
// --- Settings panel ---
|
|
393
380
|
|
|
381
|
+
let lastGeneratedToken = "";
|
|
382
|
+
|
|
394
383
|
function buildSettingItems(): SettingItem[] {
|
|
395
384
|
return [
|
|
396
385
|
{
|
|
@@ -410,7 +399,10 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
410
399
|
{
|
|
411
400
|
id: "authToken",
|
|
412
401
|
label: "Proxy auth",
|
|
413
|
-
description:
|
|
402
|
+
description:
|
|
403
|
+
config.authToken.length > 0
|
|
404
|
+
? `Token: ${config.authToken.slice(0, 8)}... (use /proxy show to copy)`
|
|
405
|
+
: "Require bearer token for all requests",
|
|
414
406
|
currentValue: config.authToken.length > 0 ? "enabled" : "disabled",
|
|
415
407
|
values: ["disabled", "enabled"],
|
|
416
408
|
},
|
|
@@ -447,17 +439,21 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
447
439
|
config = { ...config, port: clampInt(Number.parseInt(value, 10), 1, 65535, config.port) };
|
|
448
440
|
break;
|
|
449
441
|
case "authToken":
|
|
450
|
-
// Toggle: "enabled" keeps current token or
|
|
442
|
+
// Toggle: "enabled" keeps current token or generates one; "disabled" clears
|
|
451
443
|
if (value === "disabled") {
|
|
452
444
|
config = { ...config, authToken: "" };
|
|
453
445
|
} else if (config.authToken.length === 0) {
|
|
454
446
|
// Generate a random token on first enable
|
|
455
447
|
const bytes = new Uint8Array(16);
|
|
456
448
|
crypto.getRandomValues(bytes);
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
.
|
|
460
|
-
|
|
449
|
+
config = {
|
|
450
|
+
...config,
|
|
451
|
+
authToken: Array.from(bytes)
|
|
452
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
453
|
+
.join(""),
|
|
454
|
+
};
|
|
455
|
+
// Stash token so the caller can notify the user
|
|
456
|
+
lastGeneratedToken = config.authToken;
|
|
461
457
|
}
|
|
462
458
|
break;
|
|
463
459
|
case "remoteImages":
|
|
@@ -493,7 +489,11 @@ export default function proxyExtension(pi: ExtensionAPI): void {
|
|
|
493
489
|
10,
|
|
494
490
|
getSettingsListTheme(),
|
|
495
491
|
(id, newValue) => {
|
|
492
|
+
lastGeneratedToken = "";
|
|
496
493
|
applySetting(id, newValue);
|
|
494
|
+
if (lastGeneratedToken.length > 0) {
|
|
495
|
+
ctx.ui.notify(`Auth token: ${lastGeneratedToken}`, "info");
|
|
496
|
+
}
|
|
497
497
|
current = build();
|
|
498
498
|
tui.requestRender();
|
|
499
499
|
},
|