@router-for-me/pi-cliproxyapi-provider 1.4.4 → 1.4.5
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 +5 -7
- package/extensions/index.ts +54 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ This plugin needs both **baseUrl** and **apiKey**. pi's built-in `/login` only s
|
|
|
35
35
|
/cliproxyapi
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
This slash command is shown only when CLIProxyAPI is **not
|
|
38
|
+
This slash command is shown only when CLIProxyAPI is **not yet configured** (no usable credentials from env, `cliproxyapi.json`, or `/login` auth). After a successful `/login` or `/cliproxyapi` setup, it is removed from the command registry and filtered out of `/` autocomplete. Reconfigure with `/login CLIProxyAPI`, or clear credentials (`/logout` and/or remove `cliproxyapi.json` / env) to bring `/cliproxyapi` back. Restart pi or run `/reload` after upgrading so the new visibility logic is loaded.
|
|
39
39
|
|
|
40
40
|
### Or use /login shortcuts (skip the menu)
|
|
41
41
|
|
|
@@ -189,14 +189,12 @@ Disable just this helper via `pi config` if you only want the CLIProxyAPI provid
|
|
|
189
189
|
## Failure behavior
|
|
190
190
|
|
|
191
191
|
- Before setup / without credentials: provider still appears in `/login`; `/cliproxyapi` is shown; no models are listed yet.
|
|
192
|
-
- After successful `/login`: `/cliproxyapi` is hidden; reconfigure via `/login CLIProxyAPI
|
|
193
|
-
- After successful `/cliproxyapi` (config-only, no `auth.json` login): `/cliproxyapi` stays available for reconfiguration.
|
|
192
|
+
- After successful `/login` or `/cliproxyapi`: `/cliproxyapi` is hidden; reconfigure via `/login CLIProxyAPI` or by clearing stored credentials/config.
|
|
194
193
|
- If an `auth.json` credential exists and `/cliproxyapi` is invoked somehow, it asks you to use `/login CLIProxyAPI` or run `/logout` first so the old credential cannot override the new key.
|
|
195
|
-
- The built-in `/logout` command removes only the matching `auth.json` credential; environment variables and `cliproxyapi.json` are unchanged.
|
|
196
|
-
- If a models request returns **HTTP 401**
|
|
197
|
-
- If CPA is unreachable during startup (non-401), a warning is logged; setup stays available via `/cliproxyapi` (when not logged in) or `/login`.
|
|
194
|
+
- The built-in `/logout` command removes only the matching `auth.json` credential; environment variables and `cliproxyapi.json` are unchanged. `/cliproxyapi` reappears only when no connection source remains (after logout **and** config/env are cleared), or when model loading fails with a reconfiguration prompt.
|
|
195
|
+
- If a models request returns **HTTP 401** or CPA is unreachable during startup, `/cliproxyapi` is shown again so credentials can be fixed.
|
|
198
196
|
- Login/setup final step validates credentials by requesting models:
|
|
199
|
-
- HTTP 200 (including empty catalog) → credentials are persisted; `/
|
|
197
|
+
- HTTP 200 (including empty catalog) → credentials are persisted; `/cliproxyapi` is hidden
|
|
200
198
|
- non-200 / network / invalid baseUrl → nothing is persisted; re-enter baseUrl + API key
|
|
201
199
|
- If CPA returns HTTP 200 with zero usable models: login still succeeds; re-run setup later after models become available.
|
|
202
200
|
- If the selected model does not provide a non-empty `service_tiers` array: the request is left unchanged; `/fast` still updates the global preference and warns when enabling it.
|
package/extensions/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* skip the API-key vs account selector and go straight to multi-field prompts
|
|
7
7
|
* (pi only supports multi-field prompts on the account/OAuth path).
|
|
8
8
|
* 2. Preferred shortcuts: `/login CLIProxyAPI`, `/login cliproxyapi`,
|
|
9
|
-
* or the dedicated `/cliproxyapi` command (hidden
|
|
9
|
+
* or the dedicated `/cliproxyapi` command (hidden once configured).
|
|
10
10
|
* 3. Setup prompts for baseUrl + apiKey.
|
|
11
11
|
* 4. Final login step validates credentials via /v1/models?client_version=pi
|
|
12
12
|
* (HTTP 200 = success even if the catalog is empty; otherwise re-prompt).
|
|
@@ -53,10 +53,13 @@ interface SetupCommandsController {
|
|
|
53
53
|
show(): void;
|
|
54
54
|
hide(): void;
|
|
55
55
|
isVisible(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Hide when CLIProxyAPI is already configured (env / cliproxyapi.json / auth.json).
|
|
58
|
+
* Show when no connection is available. Pass forceShow after 401 so the user can fix credentials.
|
|
59
|
+
*/
|
|
60
|
+
syncVisibility(options?: { forceShow?: boolean }): void;
|
|
61
|
+
/** Whether any connection source currently provides credentials. */
|
|
62
|
+
isConfigured(): boolean;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
function hasLoginCredential(agentDir: string, providerId: string): boolean {
|
|
@@ -67,6 +70,14 @@ function hasLoginCredential(agentDir: string, providerId: string): boolean {
|
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
function isProviderConfigured(agentDir: string, providerId: string): boolean {
|
|
74
|
+
try {
|
|
75
|
+
return resolveConnection(agentDir, providerId) !== null;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
class ConfigPersistenceError extends Error {
|
|
71
82
|
constructor(cause: unknown) {
|
|
72
83
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -247,7 +258,7 @@ function createOAuthHandlers(options: {
|
|
|
247
258
|
fastMode,
|
|
248
259
|
});
|
|
249
260
|
|
|
250
|
-
// /login succeeded — dedicated setup is unnecessary until
|
|
261
|
+
// /login succeeded — dedicated setup is unnecessary until config is cleared.
|
|
251
262
|
setupCommands.hide();
|
|
252
263
|
logInfo(`login ok: registered ${result.modelCount} models from ${result.modelsUrl}`);
|
|
253
264
|
return buildOAuthCredentials(baseUrlInput, apiKey);
|
|
@@ -260,7 +271,7 @@ function createOAuthHandlers(options: {
|
|
|
260
271
|
}
|
|
261
272
|
// Auth failures should keep the setup command available for reconfiguration.
|
|
262
273
|
if (isUnauthorizedModelsError(error)) {
|
|
263
|
-
setupCommands.
|
|
274
|
+
setupCommands.syncVisibility({ forceShow: true });
|
|
264
275
|
}
|
|
265
276
|
callbacks.onProgress?.(`Login validation failed: ${message}\nPlease re-enter base URL and API key.`);
|
|
266
277
|
// Keep last baseUrl as the next default so retyping is easier.
|
|
@@ -384,10 +395,10 @@ function createSetupCommandsController(options: {
|
|
|
384
395
|
isVisible() {
|
|
385
396
|
return false;
|
|
386
397
|
},
|
|
387
|
-
|
|
398
|
+
syncVisibility() {
|
|
388
399
|
/* replaced below */
|
|
389
400
|
},
|
|
390
|
-
|
|
401
|
+
isConfigured() {
|
|
391
402
|
return false;
|
|
392
403
|
},
|
|
393
404
|
};
|
|
@@ -465,6 +476,8 @@ function createSetupCommandsController(options: {
|
|
|
465
476
|
registerConfiguredApiKey: true,
|
|
466
477
|
});
|
|
467
478
|
|
|
479
|
+
// Config saved — hide dedicated setup until credentials are cleared.
|
|
480
|
+
setupCommands.hide();
|
|
468
481
|
logInfo(`command setup ok: registered ${result.modelCount} models from ${result.modelsUrl}`);
|
|
469
482
|
ctx.ui.notify(`CLIProxyAPI configured: ${result.modelCount} models from ${result.modelsUrl}`, "info");
|
|
470
483
|
return;
|
|
@@ -476,7 +489,7 @@ function createSetupCommandsController(options: {
|
|
|
476
489
|
return;
|
|
477
490
|
}
|
|
478
491
|
if (isUnauthorizedModelsError(error)) {
|
|
479
|
-
setupCommands.
|
|
492
|
+
setupCommands.syncVisibility({ forceShow: true });
|
|
480
493
|
}
|
|
481
494
|
ctx.ui.notify(`CLIProxyAPI validation failed: ${message}. Please re-enter base URL and API key.`, "error");
|
|
482
495
|
}
|
|
@@ -567,15 +580,19 @@ function createSetupCommandsController(options: {
|
|
|
567
580
|
}
|
|
568
581
|
commandMap.delete("cliproxyapi");
|
|
569
582
|
visible = false;
|
|
570
|
-
logInfo("setup command hidden (CLIProxyAPI already
|
|
583
|
+
logInfo("setup command hidden (CLIProxyAPI already configured)");
|
|
571
584
|
};
|
|
572
585
|
|
|
573
586
|
setupCommands.isVisible = (): boolean => visible;
|
|
574
587
|
|
|
575
|
-
setupCommands.
|
|
588
|
+
setupCommands.isConfigured = (): boolean => isProviderConfigured(agentDir, providerId);
|
|
576
589
|
|
|
577
|
-
setupCommands.
|
|
578
|
-
if (
|
|
590
|
+
setupCommands.syncVisibility = (options?: { forceShow?: boolean }): void => {
|
|
591
|
+
if (options?.forceShow) {
|
|
592
|
+
setupCommands.show();
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (isProviderConfigured(agentDir, providerId)) {
|
|
579
596
|
setupCommands.hide();
|
|
580
597
|
} else {
|
|
581
598
|
setupCommands.show();
|
|
@@ -588,7 +605,7 @@ function createSetupCommandsController(options: {
|
|
|
588
605
|
/**
|
|
589
606
|
* pi's slash autocomplete snapshots commands at setup time. Deleting from the
|
|
590
607
|
* extension command Map alone does not refresh that snapshot, so also filter
|
|
591
|
-
* `/cliproxyapi` out of live suggestions while
|
|
608
|
+
* `/cliproxyapi` out of live suggestions while the provider is configured.
|
|
592
609
|
*/
|
|
593
610
|
function installSetupCommandAutocompleteFilter(options: {
|
|
594
611
|
pi: ExtensionAPI;
|
|
@@ -600,7 +617,7 @@ function installSetupCommandAutocompleteFilter(options: {
|
|
|
600
617
|
let installed = false;
|
|
601
618
|
|
|
602
619
|
pi.on("session_start", (_event, ctx) => {
|
|
603
|
-
setupCommands.
|
|
620
|
+
setupCommands.syncVisibility();
|
|
604
621
|
|
|
605
622
|
if (installed) {
|
|
606
623
|
return;
|
|
@@ -616,10 +633,10 @@ function installSetupCommandAutocompleteFilter(options: {
|
|
|
616
633
|
applyCompletion: current.applyCompletion.bind(current),
|
|
617
634
|
async getSuggestions(lines, cursorLine, cursorCol, suggestionOptions) {
|
|
618
635
|
// Keep Map visibility in sync when the user opens `/`.
|
|
619
|
-
setupCommands.
|
|
636
|
+
setupCommands.syncVisibility();
|
|
620
637
|
|
|
621
638
|
const result = await current.getSuggestions(lines, cursorLine, cursorCol, suggestionOptions);
|
|
622
|
-
if (!result?.items?.length || !
|
|
639
|
+
if (!result?.items?.length || !isProviderConfigured(agentDir, providerId)) {
|
|
623
640
|
return result;
|
|
624
641
|
}
|
|
625
642
|
|
|
@@ -630,7 +647,7 @@ function installSetupCommandAutocompleteFilter(options: {
|
|
|
630
647
|
return { ...result, items };
|
|
631
648
|
},
|
|
632
649
|
}));
|
|
633
|
-
logInfo("installed /cliproxyapi autocomplete filter for
|
|
650
|
+
logInfo("installed /cliproxyapi autocomplete filter for configured sessions");
|
|
634
651
|
});
|
|
635
652
|
}
|
|
636
653
|
|
|
@@ -723,11 +740,11 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
723
740
|
fastMode,
|
|
724
741
|
});
|
|
725
742
|
|
|
726
|
-
// Reconcile Map visibility + autocomplete filtering when
|
|
743
|
+
// Reconcile Map visibility + autocomplete filtering when configuration changes.
|
|
727
744
|
// pi has no logout extension event and slash autocomplete is snapshotted, so we:
|
|
728
745
|
// 1) delete/re-add the command Map entry
|
|
729
|
-
// 2) filter suggestions live while
|
|
730
|
-
// 3) re-check on submitted input after /logout
|
|
746
|
+
// 2) filter suggestions live while any connection source is configured
|
|
747
|
+
// 3) re-check on submitted input after /logout or config edits
|
|
731
748
|
installSetupCommandAutocompleteFilter({
|
|
732
749
|
pi,
|
|
733
750
|
agentDir,
|
|
@@ -735,13 +752,13 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
735
752
|
setupCommands,
|
|
736
753
|
});
|
|
737
754
|
pi.on("input", () => {
|
|
738
|
-
setupCommands.
|
|
755
|
+
setupCommands.syncVisibility();
|
|
739
756
|
});
|
|
740
757
|
|
|
741
|
-
// Initial visibility: hide when already
|
|
742
|
-
setupCommands.
|
|
743
|
-
if (setupCommands.
|
|
744
|
-
logInfo("CLIProxyAPI already
|
|
758
|
+
// Initial visibility: hide when already configured via env / config / /login.
|
|
759
|
+
setupCommands.syncVisibility();
|
|
760
|
+
if (setupCommands.isConfigured()) {
|
|
761
|
+
logInfo("CLIProxyAPI already configured; /cliproxyapi stays hidden");
|
|
745
762
|
}
|
|
746
763
|
|
|
747
764
|
// Always register oauth so the provider is visible in /login immediately after install.
|
|
@@ -758,7 +775,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
758
775
|
|
|
759
776
|
const connection = resolveConnection(agentDir, identity.providerId);
|
|
760
777
|
if (!connection) {
|
|
761
|
-
setupCommands.
|
|
778
|
+
setupCommands.syncVisibility();
|
|
762
779
|
logInfo(
|
|
763
780
|
`not configured yet. Prefer /cliproxyapi or /login ${identity.providerName}. ` +
|
|
764
781
|
`Menu path: /login → Sign in with an account → ${identity.providerName}. ` +
|
|
@@ -773,7 +790,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
773
790
|
// Prefer OAuth-only registration when /login already stored credentials so
|
|
774
791
|
// `/login <provider>` jumps straight into the multi-field flow. Fall back to
|
|
775
792
|
// ambient apiKey only for config-file / env setups without auth.json.
|
|
776
|
-
const hasStoredLogin =
|
|
793
|
+
const hasStoredLogin = hasLoginCredential(agentDir, identity.providerId);
|
|
777
794
|
registerProvider(pi, {
|
|
778
795
|
providerId: identity.providerId,
|
|
779
796
|
providerName: identity.providerName,
|
|
@@ -786,26 +803,19 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
786
803
|
setupCommands,
|
|
787
804
|
fastMode,
|
|
788
805
|
});
|
|
789
|
-
//
|
|
790
|
-
setupCommands.
|
|
806
|
+
// Configured successfully — keep /cliproxyapi hidden.
|
|
807
|
+
setupCommands.hide();
|
|
791
808
|
} catch (error) {
|
|
792
809
|
const message = error instanceof Error ? error.message : String(error);
|
|
793
810
|
if (isUnauthorizedModelsError(error)) {
|
|
794
|
-
// 401 →
|
|
795
|
-
setupCommands.
|
|
796
|
-
logWarn(
|
|
797
|
-
`models request unauthorized (${message}). ` +
|
|
798
|
-
(setupCommands.isVisible()
|
|
799
|
-
? "Setup command available: /cliproxyapi."
|
|
800
|
-
: `Use /login ${identity.providerName} or /logout then /cliproxyapi.`),
|
|
801
|
-
);
|
|
811
|
+
// 401 → show setup so the user can fix baseUrl/key.
|
|
812
|
+
setupCommands.syncVisibility({ forceShow: true });
|
|
813
|
+
logWarn(`models request unauthorized (${message}). Setup command available: /cliproxyapi or /login.`);
|
|
802
814
|
} else {
|
|
803
|
-
// Other failures (network, etc.): still offer setup
|
|
804
|
-
setupCommands.
|
|
815
|
+
// Other failures (network, etc.): still offer setup for reconfiguration.
|
|
816
|
+
setupCommands.syncVisibility({ forceShow: true });
|
|
805
817
|
logWarn(
|
|
806
|
-
`failed to load models (${message}). Provider remains available via
|
|
807
|
-
(setupCommands.isVisible() ? "/cliproxyapi or " : "") +
|
|
808
|
-
`/login for reconfiguration.`,
|
|
818
|
+
`failed to load models (${message}). Provider remains available via /cliproxyapi or /login for reconfiguration.`,
|
|
809
819
|
);
|
|
810
820
|
}
|
|
811
821
|
}
|
package/package.json
CHANGED