@dsnbyte/pi-cheaper-inference 0.1.0 → 0.1.1

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
@@ -2,14 +2,14 @@
2
2
 
3
3
  A Pi extension that adds the Cheaper Inference provider with API key login and a curated model picker.
4
4
 
5
- [Cheaper Inference](https://www.cheaperinference.com/) is an inference API provider offering unified access to models from multiple upstream providers. `pi-cheaper-inference` integrates it into Pi so you can authenticate with your API key, choose the models you want with `/cheaper-models`, and use them in Pi via `/model`.
5
+ [Cheaper Inference](https://www.cheaperinference.com/) is an inference API provider offering unified access to models from multiple upstream providers. `pi-cheaper-inference` integrates it into Pi so you can authenticate with your API key, choose the models you want with `/cheaper-inference-models`, and use them in Pi via `/model`.
6
6
 
7
7
  ## Features
8
8
 
9
9
  - **API Key Authentication**: Sign in via `/login` or the `CHEAPER_INFERENCE_API_KEY` environment variable.
10
10
  - **Interactive Model Picker**: Search and filter available models, inspect pricing and capabilities, and toggle the ones you want.
11
11
  - **Persistent Selection**: Saves your chosen models across Pi sessions.
12
- - **Live Registration**: Updates Pi's `/model` list as soon as you close `/cheaper-models`.
12
+ - **Live Registration**: Updates Pi's `/model` list as soon as you close `/cheaper-inference-models`.
13
13
 
14
14
  ## Installation
15
15
 
@@ -41,18 +41,19 @@ export CHEAPER_INFERENCE_API_KEY=ci_live_your_key
41
41
  Open the model selector inside an active Pi session:
42
42
 
43
43
  ```text
44
- /cheaper-models
44
+ /cheaper-inference-models
45
45
  ```
46
46
 
47
47
  In the interactive picker:
48
48
 
49
49
  - **Type** to filter models by ID, owner, or provider.
50
50
  - **Up / Down / PgUp / PgDn / Home / End** to move through the list.
51
- - **Space / Enter** to toggle whether a model is included.
51
+ - **Space** to toggle whether a model is included.
52
+ - **Enter** to activate the highlighted model, set it as the active model, save, and close.
52
53
  - **Ctrl+R** (or **F5**) to manually refresh the model list from the provider.
53
54
  - **Esc** to save your selection and update `/model`.
54
55
 
55
- You can also run `/cheaper-models refresh` to force an immediate catalog refresh when opening the menu.
56
+ You can also run `/cheaper-inference-models refresh` to force an immediate catalog refresh when opening the menu.
56
57
 
57
58
  After selecting models, switch to any of them with `/model`.
58
59
 
@@ -255,12 +255,17 @@ function formatKeyHint(th: Theme, key: string, desc: string): string {
255
255
  return th.fg("accent", key) + th.fg("dim", ` ${desc}`);
256
256
  }
257
257
 
258
+ interface PickerResult {
259
+ selected: Set<string>;
260
+ activateModelId?: string;
261
+ }
262
+
258
263
  class ModelPickerComponent implements Component {
259
264
  private catalog: CatalogModel[];
260
265
  private selected: Set<string>;
261
266
  private tui: TUI;
262
267
  private theme: Theme;
263
- private onDone: (result: Set<string> | undefined) => void;
268
+ private onDone: (result: PickerResult | undefined) => void;
264
269
  private onRefresh?: (signal: AbortSignal) => Promise<CatalogModel[]>;
265
270
  private cursorIndex = 0;
266
271
  private scrollTop = 0;
@@ -277,7 +282,7 @@ class ModelPickerComponent implements Component {
277
282
  selectedIds: Set<string>,
278
283
  tui: TUI,
279
284
  theme: Theme,
280
- onDone: (result: Set<string> | undefined) => void,
285
+ onDone: (result: PickerResult | undefined) => void,
281
286
  onRefresh?: (signal: AbortSignal) => Promise<CatalogModel[]>,
282
287
  ) {
283
288
  this.catalog = catalog;
@@ -299,7 +304,7 @@ class ModelPickerComponent implements Component {
299
304
  );
300
305
  }
301
306
 
302
- private close(result: Set<string> | undefined): void {
307
+ private close(result: PickerResult | undefined): void {
303
308
  this.closed = true;
304
309
  this.refreshController?.abort();
305
310
  this.onDone(result);
@@ -423,6 +428,7 @@ class ModelPickerComponent implements Component {
423
428
  const hints = [
424
429
  formatKeyHint(th, "↑↓", "move"),
425
430
  formatKeyHint(th, "space", "toggle"),
431
+ formatKeyHint(th, "enter", "use & close"),
426
432
  formatKeyHint(th, "type", "to search"),
427
433
  formatKeyHint(th, "ctrl+r", this.isRefreshing ? "refreshing" : "refresh"),
428
434
  formatKeyHint(th, "esc", "save & close"),
@@ -439,7 +445,7 @@ class ModelPickerComponent implements Component {
439
445
  const filtered = this.getFiltered();
440
446
 
441
447
  if (matchesKey(data, "escape")) {
442
- this.close(new Set(this.selected));
448
+ this.close({ selected: new Set(this.selected) });
443
449
  return;
444
450
  }
445
451
 
@@ -455,13 +461,16 @@ class ModelPickerComponent implements Component {
455
461
 
456
462
  this.statusMessage = undefined;
457
463
 
458
- if (
459
- matchesKey(data, "space") ||
460
- data === " " ||
461
- matchesKey(data, "enter") ||
462
- data === "\r" ||
463
- data === "\n"
464
- ) {
464
+ if (matchesKey(data, "enter") || data === "\r" || data === "\n") {
465
+ const model = filtered[this.cursorIndex];
466
+ if (model) {
467
+ this.selected.add(model.id);
468
+ this.close({ selected: new Set(this.selected), activateModelId: model.id });
469
+ }
470
+ return;
471
+ }
472
+
473
+ if (matchesKey(data, "space") || data === " ") {
465
474
  const model = filtered[this.cursorIndex];
466
475
  if (model) {
467
476
  if (this.selected.has(model.id)) {
@@ -571,7 +580,7 @@ export default function cheaperInferenceExtension(pi: ExtensionAPI, options?: Ch
571
580
 
572
581
  registerProvider(savedConfig.models);
573
582
 
574
- pi.registerCommand("cheaper-models", {
583
+ pi.registerCommand("cheaper-inference-models", {
575
584
  description: "Choose which Cheaper Inference models appear in the model list",
576
585
  getArgumentCompletions: (prefix: string) => {
577
586
  const normalized = prefix.trim().toLowerCase();
@@ -630,7 +639,7 @@ export default function cheaperInferenceExtension(pi: ExtensionAPI, options?: Ch
630
639
  return;
631
640
  }
632
641
 
633
- const nextSelected = await ctx.ui.custom<Set<string> | undefined>((tui, theme, _kb, done) => {
642
+ const pickerResult = await ctx.ui.custom<PickerResult | undefined>((tui, theme, _kb, done) => {
634
643
  return new ModelPickerComponent(catalog, selectedIds, tui, theme, done, async (signal) => {
635
644
  const refreshed = await fetchAndCacheCatalog(apiKey, signal);
636
645
  catalog = refreshed;
@@ -638,7 +647,7 @@ export default function cheaperInferenceExtension(pi: ExtensionAPI, options?: Ch
638
647
  });
639
648
  });
640
649
 
641
- if (!nextSelected) {
650
+ if (!pickerResult) {
642
651
  return;
643
652
  }
644
653
 
@@ -646,7 +655,7 @@ export default function cheaperInferenceExtension(pi: ExtensionAPI, options?: Ch
646
655
  const previousById = new Map(savedConfig.models.map((m) => [m.id, m]));
647
656
  const nextModels: ProviderModelConfig[] = [];
648
657
 
649
- for (const id of Array.from(nextSelected).sort()) {
658
+ for (const id of Array.from(pickerResult.selected).sort()) {
650
659
  const catalogModel = catalogById.get(id);
651
660
  if (catalogModel) {
652
661
  nextModels.push(toPiModel(catalogModel));
@@ -661,6 +670,31 @@ export default function cheaperInferenceExtension(pi: ExtensionAPI, options?: Ch
661
670
  savedConfig = { models: nextModels };
662
671
  saveConfig(configFile, savedConfig);
663
672
  registerProvider(nextModels);
673
+
674
+ if (pickerResult.activateModelId) {
675
+ const model = ctx.modelRegistry.find(PROVIDER_ID, pickerResult.activateModelId);
676
+ if (model) {
677
+ const success = await pi.setModel(model);
678
+ if (success) {
679
+ ctx.ui.notify(
680
+ `Active model set to ${pickerResult.activateModelId} (${nextModels.length} Cheaper Inference model(s) in /model).`,
681
+ "info",
682
+ );
683
+ return;
684
+ }
685
+ ctx.ui.notify(
686
+ `Saved ${nextModels.length} Cheaper Inference model(s), but could not activate ${pickerResult.activateModelId}.`,
687
+ "warning",
688
+ );
689
+ return;
690
+ }
691
+ ctx.ui.notify(
692
+ `Saved ${nextModels.length} Cheaper Inference model(s), but ${pickerResult.activateModelId} was not found in model registry.`,
693
+ "warning",
694
+ );
695
+ return;
696
+ }
697
+
664
698
  ctx.ui.notify(`${nextModels.length} Cheaper Inference model(s) available in /model.`, "info");
665
699
  },
666
700
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsnbyte/pi-cheaper-inference",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Pi extension that adds the Cheaper Inference provider with API key login and a curated model picker",
5
5
  "type": "module",
6
6
  "author": "dsnbyte",