pi-cliproxyapi-autoconnect 1.2.2 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/index.ts +52 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -141,10 +141,15 @@ An Anthropic-compatible endpoint does not always expose a model list. If `/v1/mo
141
141
  ```text
142
142
  /cliproxy Show the current config, model count and last error
143
143
  /cliproxy refresh Refresh the model list immediately
144
+ /cliproxy clear Delete the saved config and its backup
144
145
  ```
145
146
 
147
+ The extension registers one top-level command, `/cliproxy`; `refresh` and `clear` are arguments. In the TUI, type `/cliproxy ` (with a trailing space) to see argument completions.
148
+
146
149
  The model catalog is cached for **5 minutes** by default: opening `/model` does not hit the upstream every time. `/cliproxy refresh` forces a refresh.
147
150
 
151
+ Running `/logout` only removes the credential from pi's `auth.json`; the saved `cliproxy.json` is intentionally kept so a later `/login` can reuse it. While signed out, `/cliproxy` reports that CLIProxy is not signed in instead of showing the old endpoint as active. Use `/cliproxy clear` if you want to remove the saved domain, endpoint and model cache as well.
152
+
148
153
  To reconfigure (new domain or key), run `/login` → `CLIProxy` again. If you switched to a completely different domain and the old models are still visible, run `/reload` so the plugin rebuilds the provider from the new config.
149
154
 
150
155
  ### Relationship to pi update commands
@@ -196,6 +201,7 @@ Notes:
196
201
  - Since 1.1.0, complete model metadata (`reasoning` / `input` / `cost` / `contextWindow` / `maxTokens`) is written directly to `cliproxy.json`, not just model IDs.
197
202
  - The previous version is saved as `cliproxy.json.bak` before each write, for manual recovery.
198
203
  - The plugin never writes the key to `cliproxy.json` and never prints it to logs.
204
+ - `/logout` removes the credential from `auth.json` but keeps `cliproxy.json`, so the saved endpoint and model cache can be reused after signing in again. While signed out, `/cliproxy` reports that CLIProxy is not signed in; run `/cliproxy clear` to delete the saved config.
199
205
  - The key prompt is **not masked** in pi's current TUI (pi renders `secret` and normal text prompts the same way). Be aware of your surroundings.
200
206
  - Removing the plugin does not remove credentials from `auth.json`. To clean up, run `/logout` in pi and select CLIProxy, or edit `auth.json` manually.
201
207
 
@@ -289,6 +295,17 @@ Run `/reload`, or restart pi after editing the plugin. The model list refreshes
289
295
 
290
296
  ## Changelog
291
297
 
298
+ ### 1.2.4
299
+
300
+ - Added argument completions for `/cliproxy`: typing `/cliproxy ` now suggests `refresh` and `clear` in the TUI.
301
+ - The extension still registers a single top-level command; subcommands remain arguments rather than separate slash commands.
302
+
303
+ ### 1.2.3
304
+
305
+ - `/cliproxy` now checks whether CLIProxy is actually signed in. After `/logout` it reports “not signed in” instead of displaying the previous endpoint and model count as if they were active.
306
+ - Added `/cliproxy clear` to delete `cliproxy.json` and its backup when the saved config should not be reused.
307
+ - `/cliproxy refresh` refuses to run while signed out.
308
+
292
309
  ### 1.2.2
293
310
 
294
311
  - Rewrote this README in English for the npm package page and the pi package gallery.
package/index.ts CHANGED
@@ -638,7 +638,7 @@ async function fetchOpenAIModels(baseUrl: string, apiKey: string, signal: AbortS
638
638
  headers: {
639
639
  Accept: "application/json",
640
640
  Authorization: `Bearer ${apiKey}`,
641
- "User-Agent": "pi-cliproxyapi-autoconnect/1.2.2",
641
+ "User-Agent": "pi-cliproxyapi-autoconnect/1.2.4",
642
642
  },
643
643
  signal: requestSignal,
644
644
  });
@@ -662,7 +662,7 @@ async function fetchGeminiModels(baseUrl: string, apiKey: string, signal: AbortS
662
662
  const { signal: requestSignal, cleanup } = abortSignalWithTimeout(signal, REQUEST_TIMEOUT_MS);
663
663
  try {
664
664
  const response = await fetch(url, {
665
- headers: { Accept: "application/json", "User-Agent": "pi-cliproxyapi-autoconnect/1.2.2" },
665
+ headers: { Accept: "application/json", "User-Agent": "pi-cliproxyapi-autoconnect/1.2.4" },
666
666
  signal: requestSignal,
667
667
  });
668
668
  if (!response.ok) {
@@ -703,7 +703,7 @@ async function fetchAnthropicModels(baseUrl: string, apiKey: string, signal: Abo
703
703
  // Anthropic's x-api-key header; sending both is harmless upstream.
704
704
  Authorization: `Bearer ${apiKey}`,
705
705
  "anthropic-version": "2023-06-01",
706
- "User-Agent": "pi-cliproxyapi-autoconnect/1.2.2",
706
+ "User-Agent": "pi-cliproxyapi-autoconnect/1.2.4",
707
707
  },
708
708
  signal: requestSignal,
709
709
  });
@@ -1254,10 +1254,58 @@ export default function (pi: ExtensionAPI): void {
1254
1254
  pi.registerProvider(buildProvider(readConfig()));
1255
1255
 
1256
1256
  pi.registerCommand("cliproxy", {
1257
- description: "Show CLIProxy config, or run /cliproxy refresh to refresh models",
1257
+ description: "Show CLIProxy config, refresh models, or clear the saved config",
1258
+ getArgumentCompletions: (argumentPrefix) => {
1259
+ const prefix = argumentPrefix.trim().toLowerCase();
1260
+ const items = [
1261
+ { value: "refresh", label: "refresh", description: "Refresh the CLIProxy model list" },
1262
+ { value: "clear", label: "clear", description: "Delete the saved CLIProxy config and backup" },
1263
+ ];
1264
+ const matches = items.filter((item) => item.value.startsWith(prefix));
1265
+ return matches.length > 0 ? matches : null;
1266
+ },
1258
1267
  handler: async (args, ctx) => {
1259
1268
  const subcommand = args.trim().toLowerCase();
1260
1269
  const config = readConfig();
1270
+ const signedIn = ctx.modelRegistry.getProviderAuthStatus(PROVIDER_ID).configured;
1271
+
1272
+ if (subcommand === "clear" || subcommand === "reset") {
1273
+ const backupPath = `${configPath()}.bak`;
1274
+ if (!config && !existsSync(backupPath)) {
1275
+ ctx.ui.notify("No saved CLIProxy config to clear.", "info");
1276
+ return;
1277
+ }
1278
+ const confirmed = await ctx.ui.confirm(
1279
+ "Delete saved CLIProxy config?",
1280
+ `This removes ${configPath()} and its backup. You will need to sign in again.`,
1281
+ );
1282
+ if (!confirmed) return;
1283
+ try {
1284
+ for (const path of [configPath(), backupPath]) {
1285
+ if (existsSync(path)) unlinkSync(path);
1286
+ }
1287
+ } catch (error) {
1288
+ ctx.ui.notify(
1289
+ `Failed to clear CLIProxy config: ${error instanceof Error ? error.message : String(error)}`,
1290
+ "error",
1291
+ );
1292
+ return;
1293
+ }
1294
+ lastRefreshError = undefined;
1295
+ ctx.ui.notify("CLIProxy config cleared. Run /login to configure it again.", "info");
1296
+ return;
1297
+ }
1298
+
1299
+ if (!signedIn) {
1300
+ const saved = config
1301
+ ? `\nA saved config remains at ${configPath()} and will be reused after you sign in.\nRemove it with /cliproxy clear.`
1302
+ : "";
1303
+ ctx.ui.notify(
1304
+ `CLIProxy is not signed in.\nRun /login -> "Sign in with an API key" -> CLIProxy.${saved}`,
1305
+ "warning",
1306
+ );
1307
+ return;
1308
+ }
1261
1309
 
1262
1310
  if (subcommand === "refresh") {
1263
1311
  if (!config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cliproxyapi-autoconnect",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "CLIProxyAPI auto-connect provider for pi: sign in with a bound domain and API key, automatically discover OpenAI/Gemini/Anthropic-compatible endpoints, and register models in /model.",
5
5
  "type": "module",
6
6
  "license": "MIT",