@router-for-me/pi-cliproxyapi-provider 1.4.3 → 1.4.4

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 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** already authenticated via `/login` (no matching credential in `auth.json`). After a successful `/login`, it is hidden from the `/` menu; reconfigure with `/login CLIProxyAPI`, or run `/logout` first to bring `/cliproxyapi` back. Config-file / env-only setups (no `/login` credential) keep the command available for reconfiguration.
38
+ This slash command is shown only when CLIProxyAPI is **not** already authenticated via `/login` (no matching credential in `auth.json`). After a successful `/login`, it is removed from the command registry and filtered out of `/` autocomplete; reconfigure with `/login CLIProxyAPI`, or run `/logout` first to bring `/cliproxyapi` back. Config-file / env-only setups (no `/login` credential) keep the command available for reconfiguration. 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
 
@@ -55,6 +55,16 @@ interface SetupCommandsController {
55
55
  isVisible(): boolean;
56
56
  /** Hide when /login credentials exist; show otherwise. */
57
57
  syncFromAuth(): void;
58
+ /** Whether /login currently has a stored credential for this provider. */
59
+ hasLoginCredential(): boolean;
60
+ }
61
+
62
+ function hasLoginCredential(agentDir: string, providerId: string): boolean {
63
+ try {
64
+ return Boolean(loadAuthConnection(agentDir, providerId)?.apiKey);
65
+ } catch {
66
+ return false;
67
+ }
58
68
  }
59
69
 
60
70
  class ConfigPersistenceError extends Error {
@@ -377,6 +387,9 @@ function createSetupCommandsController(options: {
377
387
  syncFromAuth() {
378
388
  /* replaced below */
379
389
  },
390
+ hasLoginCredential() {
391
+ return false;
392
+ },
380
393
  };
381
394
 
382
395
  let visible = false;
@@ -392,7 +405,7 @@ function createSetupCommandsController(options: {
392
405
  return;
393
406
  }
394
407
 
395
- if (loadAuthConnection(agentDir, providerId)?.apiKey) {
408
+ if (hasLoginCredential(agentDir, providerId)) {
396
409
  // Still authenticated via /login — hide the dedicated command and redirect.
397
410
  setupCommands.hide();
398
411
  ctx.ui.notify(
@@ -559,8 +572,10 @@ function createSetupCommandsController(options: {
559
572
 
560
573
  setupCommands.isVisible = (): boolean => visible;
561
574
 
575
+ setupCommands.hasLoginCredential = (): boolean => hasLoginCredential(agentDir, providerId);
576
+
562
577
  setupCommands.syncFromAuth = (): void => {
563
- if (loadAuthConnection(agentDir, providerId)?.apiKey) {
578
+ if (hasLoginCredential(agentDir, providerId)) {
564
579
  setupCommands.hide();
565
580
  } else {
566
581
  setupCommands.show();
@@ -570,6 +585,55 @@ function createSetupCommandsController(options: {
570
585
  return setupCommands;
571
586
  }
572
587
 
588
+ /**
589
+ * pi's slash autocomplete snapshots commands at setup time. Deleting from the
590
+ * extension command Map alone does not refresh that snapshot, so also filter
591
+ * `/cliproxyapi` out of live suggestions while a /login credential exists.
592
+ */
593
+ function installSetupCommandAutocompleteFilter(options: {
594
+ pi: ExtensionAPI;
595
+ agentDir: string;
596
+ providerId: string;
597
+ setupCommands: SetupCommandsController;
598
+ }): void {
599
+ const { pi, agentDir, providerId, setupCommands } = options;
600
+ let installed = false;
601
+
602
+ pi.on("session_start", (_event, ctx) => {
603
+ setupCommands.syncFromAuth();
604
+
605
+ if (installed) {
606
+ return;
607
+ }
608
+ if (typeof ctx.ui.addAutocompleteProvider !== "function") {
609
+ return;
610
+ }
611
+ installed = true;
612
+
613
+ ctx.ui.addAutocompleteProvider((current) => ({
614
+ triggerCharacters: current.triggerCharacters,
615
+ shouldTriggerFileCompletion: current.shouldTriggerFileCompletion?.bind(current),
616
+ applyCompletion: current.applyCompletion.bind(current),
617
+ async getSuggestions(lines, cursorLine, cursorCol, suggestionOptions) {
618
+ // Keep Map visibility in sync when the user opens `/`.
619
+ setupCommands.syncFromAuth();
620
+
621
+ const result = await current.getSuggestions(lines, cursorLine, cursorCol, suggestionOptions);
622
+ if (!result?.items?.length || !hasLoginCredential(agentDir, providerId)) {
623
+ return result;
624
+ }
625
+
626
+ const items = result.items.filter((item) => item.value !== "cliproxyapi" && item.label !== "cliproxyapi");
627
+ if (items.length === 0) {
628
+ return null;
629
+ }
630
+ return { ...result, items };
631
+ },
632
+ }));
633
+ logInfo("installed /cliproxyapi autocomplete filter for logged-in sessions");
634
+ });
635
+ }
636
+
573
637
  export function registerFastCommand(options: {
574
638
  pi: ExtensionAPI;
575
639
  agentDir: string;
@@ -659,10 +723,16 @@ export default async function (pi: ExtensionAPI): Promise<void> {
659
723
  fastMode,
660
724
  });
661
725
 
662
- // Reconcile visibility after /logout (auth.json removed) or when credentials reappear.
663
- // pi has no logout extension event, so re-check on session lifecycle and submitted input.
664
- pi.on("session_start", () => {
665
- setupCommands.syncFromAuth();
726
+ // Reconcile Map visibility + autocomplete filtering when auth changes.
727
+ // pi has no logout extension event and slash autocomplete is snapshotted, so we:
728
+ // 1) delete/re-add the command Map entry
729
+ // 2) filter suggestions live while a /login credential exists
730
+ // 3) re-check on submitted input after /logout
731
+ installSetupCommandAutocompleteFilter({
732
+ pi,
733
+ agentDir,
734
+ providerId: identity.providerId,
735
+ setupCommands,
666
736
  });
667
737
  pi.on("input", () => {
668
738
  setupCommands.syncFromAuth();
@@ -670,6 +740,9 @@ export default async function (pi: ExtensionAPI): Promise<void> {
670
740
 
671
741
  // Initial visibility: hide when already logged in via /login.
672
742
  setupCommands.syncFromAuth();
743
+ if (setupCommands.hasLoginCredential()) {
744
+ logInfo("CLIProxyAPI already authenticated via /login; /cliproxyapi stays hidden");
745
+ }
673
746
 
674
747
  // Always register oauth so the provider is visible in /login immediately after install.
675
748
  registerProvider(pi, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@router-for-me/pi-cliproxyapi-provider",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Pi provider extension that auto-registers CLIProxyAPI models, plus TUI elapsed/TPS status",
5
5
  "type": "module",
6
6
  "keywords": [