@mcowger/pi-plexus 1.2.3 → 1.2.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 CHANGED
@@ -98,7 +98,6 @@ You will be prompted for:
98
98
 
99
99
  - **Plexus base URL** — e.g. `https://plexus.example.com`
100
100
  - **Plexus API key**
101
- - **Default model** (optional)
102
101
 
103
102
  To force a model refresh:
104
103
 
@@ -106,6 +105,13 @@ To force a model refresh:
106
105
  /plexus refresh
107
106
  ```
108
107
 
108
+ Set the model Pi should use by default. With no model ID, Pi opens a selector; you can also pass the exact Plexus model ID directly:
109
+
110
+ ```
111
+ /plexus set-default-model
112
+ /plexus set-default-model claude-sonnet-4-5
113
+ ```
114
+
109
115
  Use `/login plexus` for setup and `/logout plexus` to remove stored credentials.
110
116
 
111
117
  ### OpenCode
@@ -157,7 +163,7 @@ export PLEXUS_API_KEY=your-api-key
157
163
 
158
164
  ```
159
165
  ~/.pi/agent/extensions/plexus/
160
- config.json # base URL and optional default model
166
+ config.json # base URL and optional default model (set via /plexus set-default-model)
161
167
  plexus-models-cache.json # last-fetched model list (startup cache)
162
168
  plexus-models-response.json # raw API response (diagnostics)
163
169
  plexus.log # extension activity log
package/dist/extension.js CHANGED
@@ -328,6 +328,13 @@ async function saveBaseUrl(baseUrl, defaultModel) {
328
328
  `, "utf8");
329
329
  cachedConfig = config;
330
330
  }
331
+ async function saveDefaultModel(defaultModel) {
332
+ await mkdir(getConfigDir(), { recursive: true });
333
+ const config = { ...getConfigSync(), defaultModel };
334
+ await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
335
+ `, "utf8");
336
+ cachedConfig = config;
337
+ }
331
338
  function getRawBaseUrl() {
332
339
  const config = getConfigSync();
333
340
  return resolveStringOption(process.env[ENV_API_URL]) ?? resolveStringOption(process.env[ENV_BASE_URL]) ?? resolveStringOption(config.baseUrl) ?? null;
@@ -458,6 +465,7 @@ function descriptorToPiModel(descriptor) {
458
465
  id: descriptor.id,
459
466
  name: descriptor.name,
460
467
  api: descriptor.preferredApi,
468
+ provider: descriptor.provider,
461
469
  baseUrl: descriptor.baseUrl,
462
470
  reasoning: descriptor.reasoning,
463
471
  input: descriptor.input,
@@ -498,23 +506,44 @@ function plexusExtension(pi) {
498
506
  log("session_start", { hasApiKey: !!apiKey, baseUrl });
499
507
  if (!apiKey || !baseUrl) {
500
508
  log("session_start: no auth configured, skipping refresh");
501
- await trySetDefaultModel(pi, startupModels);
509
+ await trySetDefaultModel(pi, startupModels, ctx);
502
510
  return;
503
511
  }
504
512
  await doRefresh(pi, apiKey, ctx, true);
505
513
  });
506
514
  pi.registerCommand("plexus", {
507
- description: "Plexus provider commands: refresh (setup: /login plexus)",
508
- getArgumentCompletions: () => [
509
- { value: "refresh", label: "refresh", description: "Refresh Plexus models from the API" }
510
- ],
515
+ description: "Plexus provider commands: refresh, set-default-model (setup: /login plexus)",
516
+ getArgumentCompletions: (prefix) => {
517
+ const subcommands = [
518
+ { value: "refresh", label: "refresh", description: "Refresh Plexus models from the API" },
519
+ { value: "set-default-model", label: "set-default-model", description: "Choose the model Pi should use by default" }
520
+ ];
521
+ if (!prefix.includes(" ")) {
522
+ return subcommands.filter((command) => command.value.startsWith(prefix));
523
+ }
524
+ const [subcommand, ...rest] = prefix.split(/\s+/);
525
+ if (subcommand !== "set-default-model")
526
+ return null;
527
+ const modelPrefix = rest.join(" ");
528
+ const choices = currentModels.map((model) => ({
529
+ value: model.id,
530
+ label: model.name === model.id ? model.id : `${model.name} (${model.id})`
531
+ }));
532
+ const filtered = choices.filter((choice) => choice.value.toLowerCase().startsWith(modelPrefix.toLowerCase()));
533
+ return filtered.length > 0 ? filtered : null;
534
+ },
511
535
  handler: async (args, ctx) => {
512
- const sub = args.trim().toLowerCase();
536
+ const trimmed = args.trim();
537
+ const sub = trimmed.toLowerCase();
513
538
  if (sub === "refresh" || sub === "") {
514
539
  await handleRefresh(pi, ctx);
515
540
  return;
516
541
  }
517
- ctx.ui.notify(`Unknown sub-command: "${args}". Use /login plexus for setup or /plexus refresh to refresh models.`, "warning");
542
+ if (sub === "set-default-model" || sub.startsWith("set-default-model ")) {
543
+ await handleSetDefaultModel(pi, ctx, trimmed.slice("set-default-model".length).trim());
544
+ return;
545
+ }
546
+ ctx.ui.notify(`Unknown sub-command: "${args}". Use /login plexus, /plexus refresh, or /plexus set-default-model.`, "warning");
518
547
  }
519
548
  });
520
549
  }
@@ -533,7 +562,7 @@ function createPlexusLoginProvider(pi) {
533
562
  throw new Error("Plexus API key is required.");
534
563
  await saveBaseUrl(baseUrl);
535
564
  callbacks.onProgress?.("Refreshing Plexus models...");
536
- await doRefresh(pi, apiKey, null, false);
565
+ await doRefresh(pi, apiKey, null, true);
537
566
  return {
538
567
  access: apiKey,
539
568
  refresh: apiKey,
@@ -552,7 +581,7 @@ function createPlexusLoginProvider(pi) {
552
581
  if (!baseUrl)
553
582
  return models;
554
583
  const apiBase = baseUrl.trim().replace(/\/+$/, "").endsWith("/v1") ? baseUrl.trim().replace(/\/+$/, "") : `${baseUrl.trim().replace(/\/+$/, "")}/v1`;
555
- return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: apiBase } : model);
584
+ return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: adjustBaseUrl(apiBase, model.api) } : model);
556
585
  }
557
586
  };
558
587
  }
@@ -565,6 +594,30 @@ async function handleRefresh(pi, ctx) {
565
594
  ctx.ui.notify("Refreshing Plexus models\u2026", "info");
566
595
  await doRefresh(pi, apiKey, ctx, true);
567
596
  }
597
+ async function handleSetDefaultModel(pi, ctx, requestedModelId) {
598
+ let modelId = requestedModelId;
599
+ if (!modelId) {
600
+ if (currentModels.length === 0) {
601
+ ctx.ui.notify("No Plexus models are available. Run /plexus refresh first.", "warning");
602
+ return;
603
+ }
604
+ const choices = currentModels.map((model2) => model2.name === model2.id ? model2.id : `${model2.name} (${model2.id})`);
605
+ const selected = await ctx.ui.select("Select the Plexus default model:", choices);
606
+ if (!selected)
607
+ return;
608
+ const selectedIndex = choices.indexOf(selected);
609
+ modelId = currentModels[selectedIndex]?.id ?? "";
610
+ }
611
+ const model = currentModels.find((candidate) => candidate.id === modelId);
612
+ if (!model) {
613
+ ctx.ui.notify(`Plexus model not found: "${modelId}". Run /plexus refresh and choose a model from the available list.`, "error");
614
+ return;
615
+ }
616
+ await saveDefaultModel(model.id);
617
+ const registryModel = ctx.modelRegistry.find(PROVIDER_NAME, model.id) ?? model;
618
+ const active = await pi.setModel(registryModel);
619
+ ctx.ui.notify(active ? `Default Plexus model set to ${model.id}.` : `Default Plexus model set to ${model.id}; it will be selected when Plexus authentication is available.`, active ? "info" : "warning");
620
+ }
568
621
  async function doRefresh(pi, apiKey, ctx, setDefault) {
569
622
  const modelsUrl = getModelsUrl();
570
623
  const baseUrl = getBaseUrl();
@@ -592,7 +645,7 @@ async function doRefresh(pi, apiKey, ctx, setDefault) {
592
645
  if (ctx)
593
646
  ctx.ui.notify(`Refreshed ${piModels.length} Plexus models`, "info");
594
647
  if (setDefault)
595
- await trySetDefaultModel(pi, piModels);
648
+ await trySetDefaultModel(pi, piModels, ctx);
596
649
  } catch (error) {
597
650
  log("doRefresh: failed", { error: String(error) });
598
651
  if (ctx) {
@@ -600,7 +653,7 @@ async function doRefresh(pi, apiKey, ctx, setDefault) {
600
653
  }
601
654
  }
602
655
  }
603
- async function trySetDefaultModel(pi, models) {
656
+ async function trySetDefaultModel(pi, models, ctx) {
604
657
  const defaultModelId = getDefaultModel();
605
658
  if (!defaultModelId)
606
659
  return;
@@ -609,7 +662,8 @@ async function trySetDefaultModel(pi, models) {
609
662
  log("trySetDefaultModel: model not found", { defaultModelId });
610
663
  return;
611
664
  }
612
- const ok = await pi.setModel(model);
665
+ const registryModel = ctx?.modelRegistry.find(PROVIDER_NAME, defaultModelId) ?? model;
666
+ const ok = await pi.setModel(registryModel);
613
667
  log("trySetDefaultModel", { defaultModelId, ok });
614
668
  }
615
669
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [