@victor-software-house/pi-openai-proxy 4.2.0 → 4.2.2

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 (2) hide show
  1. package/extensions/proxy.ts +30 -56
  2. package/package.json +1 -1
@@ -552,70 +552,44 @@ export default function proxyExtension(pi: ExtensionAPI): void {
552
552
  ): Component {
553
553
  const models = getAvailableModels();
554
554
  const selected = new Set(config.customModels);
555
- let selectedIndex = 0;
556
555
 
557
- function toggle(canonicalId: string): void {
558
- if (selected.has(canonicalId)) {
559
- selected.delete(canonicalId);
560
- } else {
561
- selected.add(canonicalId);
562
- }
563
- config = { ...config, customModels: [...selected] };
564
- saveConfigToFile(config);
565
- config = loadConfigFromFile();
566
- }
567
-
568
- return {
569
- render(width: number): string[] {
570
- const lines: string[] = [];
571
- lines.push(" Select models (Space: toggle, Esc: done)");
572
- lines.push("");
556
+ const items: SettingItem[] = models.map((m) => {
557
+ const canonical = `${m.provider}/${m.id}`;
558
+ return {
559
+ id: canonical,
560
+ label: canonical,
561
+ currentValue: selected.has(canonical) ? "[x]" : "[ ]",
562
+ values: ["[x]", "[ ]"],
563
+ };
564
+ });
573
565
 
574
- if (models.length === 0) {
575
- lines.push(" No models available (no auth configured)");
576
- return lines;
577
- }
578
-
579
- const maxVisible = 15;
580
- const start = Math.max(
581
- 0,
582
- Math.min(selectedIndex - Math.floor(maxVisible / 2), models.length - maxVisible),
583
- );
584
- const end = Math.min(start + maxVisible, models.length);
585
-
586
- for (let i = start; i < end; i++) {
587
- const m = models[i];
588
- if (m === undefined) continue;
589
- const canonical = `${m.provider}/${m.id}`;
590
- const check = selected.has(canonical) ? "[x]" : "[ ]";
591
- const cursor = i === selectedIndex ? "> " : " ";
592
- const line = `${cursor}${check} ${canonical}`;
593
- const truncated = line.length > width ? line.slice(0, width - 1) : line;
594
- lines.push(truncated);
566
+ const list = new SettingsList(
567
+ items,
568
+ Math.min(items.length + 2, 20),
569
+ getSettingsListTheme(),
570
+ (id: string, newValue: string) => {
571
+ if (newValue === "[x]") {
572
+ selected.add(id);
573
+ } else {
574
+ selected.delete(id);
595
575
  }
576
+ config = { ...config, customModels: [...selected] };
577
+ saveConfigToFile(config);
578
+ config = loadConfigFromFile();
579
+ },
580
+ () => done(`${String(selected.size)} selected`),
581
+ { enableSearch: true },
582
+ );
596
583
 
597
- lines.push("");
598
- lines.push(` ${String(selected.size)} of ${String(models.length)} selected`);
599
- return lines;
584
+ return {
585
+ render(width: number): string[] {
586
+ return list.render(width);
600
587
  },
601
588
  invalidate(): void {
602
- // no-op
589
+ list.invalidate();
603
590
  },
604
591
  handleInput(data: string): void {
605
- if (data === "\x1B" || data === "q") {
606
- done(`${String(selected.size)} selected`);
607
- return;
608
- }
609
- if (data === "\x1B[A" && selectedIndex > 0) {
610
- selectedIndex--;
611
- } else if (data === "\x1B[B" && selectedIndex < models.length - 1) {
612
- selectedIndex++;
613
- } else if (data === " " || data === "\r") {
614
- const m = models[selectedIndex];
615
- if (m !== undefined) {
616
- toggle(`${m.provider}/${m.id}`);
617
- }
618
- }
592
+ list.handleInput(data);
619
593
  },
620
594
  };
621
595
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@victor-software-house/pi-openai-proxy",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "OpenAI-compatible HTTP proxy for pi's multi-provider model registry",
5
5
  "license": "MIT",
6
6
  "author": "Victor Software House",