@code-yeongyu/senpi 0.74.0 → 2026.5.13-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.
- package/CHANGELOG.md +9 -1
- package/README.md +4 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +3 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/extensions/builtin/anthropic-web-search/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-web-search/index.js +25 -14
- package/dist/core/extensions/builtin/anthropic-web-search/index.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/preview-format.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-apply-patch/preview-format.js +56 -7
- package/dist/core/extensions/builtin/gpt-apply-patch/preview-format.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts +7 -3
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +12 -4
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -0
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/continuation/runtime.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/continuation/runtime.js +7 -10
- package/dist/core/extensions/builtin/todotools/continuation/runtime.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/index.d.ts +2 -2
- package/dist/core/extensions/builtin/todotools/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/index.js +2 -2
- package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/settings.d.ts +6 -0
- package/dist/core/extensions/builtin/todotools/settings.d.ts.map +1 -0
- package/dist/core/extensions/builtin/todotools/settings.js +58 -0
- package/dist/core/extensions/builtin/todotools/settings.js.map +1 -0
- package/dist/core/extensions/builtin/todotools/system-messages.d.ts +34 -0
- package/dist/core/extensions/builtin/todotools/system-messages.d.ts.map +1 -0
- package/dist/core/extensions/builtin/todotools/system-messages.js +82 -0
- package/dist/core/extensions/builtin/todotools/system-messages.js.map +1 -0
- package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/tools/todoread.js +3 -1
- package/dist/core/extensions/builtin/todotools/tools/todoread.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/tools/todowrite.js +3 -1
- package/dist/core/extensions/builtin/todotools/tools/todowrite.js.map +1 -1
- package/dist/core/keybindings.d.ts +5 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +10 -3
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +8 -3
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/resource-loader.d.ts +8 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +168 -17
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +11 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +11 -3
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/favorite-models-selector.d.ts +10 -4
- package/dist/modes/interactive/components/favorite-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/favorite-models-selector.js +56 -78
- package/dist/modes/interactive/components/favorite-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-favorites.d.ts +10 -0
- package/dist/modes/interactive/components/model-favorites.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-favorites.js +53 -0
- package/dist/modes/interactive/components/model-favorites.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +9 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +52 -10
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +4 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +83 -94
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/models.md +26 -1
- package/docs/settings.md +14 -0
- package/package.json +7 -10
- package/dist/core/extensions/builtin/agent-system/agent-types.d.ts +0 -25
- package/dist/core/extensions/builtin/agent-system/agent-types.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/agent-types.js +0 -38
- package/dist/core/extensions/builtin/agent-system/agent-types.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/builtin-agents.d.ts +0 -3
- package/dist/core/extensions/builtin/agent-system/builtin-agents.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/builtin-agents.js +0 -32
- package/dist/core/extensions/builtin/agent-system/builtin-agents.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/index.d.ts +0 -3
- package/dist/core/extensions/builtin/agent-system/index.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/index.js +0 -42
- package/dist/core/extensions/builtin/agent-system/index.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/loader.d.ts +0 -4
- package/dist/core/extensions/builtin/agent-system/loader.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/loader.js +0 -59
- package/dist/core/extensions/builtin/agent-system/loader.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/permission.d.ts +0 -11
- package/dist/core/extensions/builtin/agent-system/permission.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/permission.js +0 -24
- package/dist/core/extensions/builtin/agent-system/permission.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/registry.d.ts +0 -10
- package/dist/core/extensions/builtin/agent-system/registry.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/registry.js +0 -50
- package/dist/core/extensions/builtin/agent-system/registry.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/types.d.ts +0 -9
- package/dist/core/extensions/builtin/agent-system/types.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/types.js +0 -2
- package/dist/core/extensions/builtin/agent-system/types.js.map +0 -1
- package/dist/core/extensions/builtin/agent-system/wildcard.d.ts +0 -4
- package/dist/core/extensions/builtin/agent-system/wildcard.d.ts.map +0 -1
- package/dist/core/extensions/builtin/agent-system/wildcard.js +0 -58
- package/dist/core/extensions/builtin/agent-system/wildcard.js.map +0 -1
- package/dist/core/extensions/builtin/anthropic-web-fetch/index.d.ts +0 -7
- package/dist/core/extensions/builtin/anthropic-web-fetch/index.d.ts.map +0 -1
- package/dist/core/extensions/builtin/anthropic-web-fetch/index.js +0 -112
- package/dist/core/extensions/builtin/anthropic-web-fetch/index.js.map +0 -1
|
@@ -1,56 +1,9 @@
|
|
|
1
|
+
import { modelsAreEqual } from "@earendil-works/pi-ai";
|
|
1
2
|
import { Container, fuzzyFilter, getKeybindings, Input, Key, matchesKey, Spacer, Text, } from "@earendil-works/pi-tui";
|
|
2
3
|
import { theme } from "../theme/theme.js";
|
|
3
4
|
import { DynamicBorder } from "./dynamic-border.js";
|
|
4
5
|
import { keyText } from "./keybinding-hints.js";
|
|
5
|
-
|
|
6
|
-
return favoriteIds === null || favoriteIds.includes(id);
|
|
7
|
-
}
|
|
8
|
-
function toggleFavorite(favoriteIds, id) {
|
|
9
|
-
if (favoriteIds === null)
|
|
10
|
-
return [id]; // First toggle: start with only this one
|
|
11
|
-
const index = favoriteIds.indexOf(id);
|
|
12
|
-
if (index >= 0)
|
|
13
|
-
return [...favoriteIds.slice(0, index), ...favoriteIds.slice(index + 1)];
|
|
14
|
-
return [...favoriteIds, id];
|
|
15
|
-
}
|
|
16
|
-
function favoriteAll(favoriteIds, allIds, targetIds) {
|
|
17
|
-
if (favoriteIds === null)
|
|
18
|
-
return null; // Already all favorite
|
|
19
|
-
const targets = targetIds ?? allIds;
|
|
20
|
-
const result = [...favoriteIds];
|
|
21
|
-
for (const id of targets) {
|
|
22
|
-
if (!result.includes(id))
|
|
23
|
-
result.push(id);
|
|
24
|
-
}
|
|
25
|
-
return result.length === allIds.length ? null : result;
|
|
26
|
-
}
|
|
27
|
-
function clearAll(favoriteIds, allIds, targetIds) {
|
|
28
|
-
if (favoriteIds === null) {
|
|
29
|
-
return targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];
|
|
30
|
-
}
|
|
31
|
-
const targets = new Set(targetIds ?? favoriteIds);
|
|
32
|
-
return favoriteIds.filter((id) => !targets.has(id));
|
|
33
|
-
}
|
|
34
|
-
function move(favoriteIds, id, delta) {
|
|
35
|
-
if (favoriteIds === null)
|
|
36
|
-
return null;
|
|
37
|
-
const list = [...favoriteIds];
|
|
38
|
-
const index = list.indexOf(id);
|
|
39
|
-
if (index < 0)
|
|
40
|
-
return list;
|
|
41
|
-
const newIndex = index + delta;
|
|
42
|
-
if (newIndex < 0 || newIndex >= list.length)
|
|
43
|
-
return list;
|
|
44
|
-
const result = [...list];
|
|
45
|
-
[result[index], result[newIndex]] = [result[newIndex], result[index]];
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
function getSortedIds(favoriteIds, allIds) {
|
|
49
|
-
if (favoriteIds === null)
|
|
50
|
-
return allIds;
|
|
51
|
-
const favoriteSet = new Set(favoriteIds);
|
|
52
|
-
return [...favoriteIds, ...allIds.filter((id) => !favoriteSet.has(id))];
|
|
53
|
-
}
|
|
6
|
+
import { clearFavoriteModels, favoriteModels, getModelFullId, getSortedFavoriteModelIds, isFavoriteModel, moveFavoriteModel, toggleFavoriteModel, } from "./model-favorites.js";
|
|
54
7
|
function getModelSearchText(item) {
|
|
55
8
|
return `${item.fullId} ${item.model.id} ${item.model.name} ${item.model.provider}`;
|
|
56
9
|
}
|
|
@@ -65,6 +18,7 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
65
18
|
filteredItems = [];
|
|
66
19
|
selectedIndex = 0;
|
|
67
20
|
searchInput;
|
|
21
|
+
currentModel;
|
|
68
22
|
// Focusable implementation - propagate to searchInput for IME cursor positioning
|
|
69
23
|
_focused = false;
|
|
70
24
|
get focused() {
|
|
@@ -76,14 +30,16 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
76
30
|
}
|
|
77
31
|
listContainer;
|
|
78
32
|
footerText;
|
|
33
|
+
secondaryFooterText;
|
|
79
34
|
callbacks;
|
|
80
35
|
maxVisible = 8;
|
|
81
36
|
isDirty = false;
|
|
82
37
|
constructor(config, callbacks) {
|
|
83
38
|
super();
|
|
84
39
|
this.callbacks = callbacks;
|
|
40
|
+
this.currentModel = config.currentModel;
|
|
85
41
|
for (const model of config.allModels) {
|
|
86
|
-
const fullId =
|
|
42
|
+
const fullId = getModelFullId(model);
|
|
87
43
|
this.modelsById.set(fullId, model);
|
|
88
44
|
this.allIds.push(fullId);
|
|
89
45
|
}
|
|
@@ -93,7 +49,7 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
93
49
|
this.addChild(new DynamicBorder());
|
|
94
50
|
this.addChild(new Spacer(1));
|
|
95
51
|
this.addChild(new Text(theme.fg("accent", theme.bold("Favorite Models")), 0, 0));
|
|
96
|
-
this.addChild(new Text(theme.fg("muted",
|
|
52
|
+
this.addChild(new Text(theme.fg("muted", `${keyText("tui.select.confirm")} selects. ${keyText("app.models.toggleFavorite")} toggles favorite. ${keyText("app.models.save")} saves.`), 0, 0));
|
|
97
53
|
this.addChild(new Spacer(1));
|
|
98
54
|
// Search input
|
|
99
55
|
this.searchInput = new Input();
|
|
@@ -106,20 +62,22 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
106
62
|
this.addChild(new Spacer(1));
|
|
107
63
|
this.footerText = new Text(this.getFooterText(), 0, 0);
|
|
108
64
|
this.addChild(this.footerText);
|
|
65
|
+
this.secondaryFooterText = new Text(this.getSecondaryFooterText(), 0, 0);
|
|
66
|
+
this.addChild(this.secondaryFooterText);
|
|
109
67
|
this.addChild(new DynamicBorder());
|
|
110
68
|
this.updateList();
|
|
111
69
|
}
|
|
112
70
|
buildItems() {
|
|
113
71
|
// Filter out IDs that no longer have a corresponding model (e.g., after logout)
|
|
114
72
|
const items = [];
|
|
115
|
-
for (const id of
|
|
73
|
+
for (const id of getSortedFavoriteModelIds(this.favoriteIds, this.allIds)) {
|
|
116
74
|
const model = this.modelsById.get(id);
|
|
117
75
|
if (!model)
|
|
118
76
|
continue;
|
|
119
77
|
items.push({
|
|
120
78
|
fullId: id,
|
|
121
79
|
model,
|
|
122
|
-
favorite:
|
|
80
|
+
favorite: isFavoriteModel(this.favoriteIds, id),
|
|
123
81
|
});
|
|
124
82
|
}
|
|
125
83
|
return items;
|
|
@@ -129,25 +87,35 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
129
87
|
const allFavorite = this.favoriteIds === null;
|
|
130
88
|
const countText = allFavorite ? "all favorites" : `${favoriteCount}/${this.allIds.length} favorites`;
|
|
131
89
|
const parts = [
|
|
132
|
-
`${keyText("tui.select.confirm")}
|
|
133
|
-
`${keyText("app.models.
|
|
134
|
-
`${keyText("app.models.clearAll")} clear`,
|
|
135
|
-
`${keyText("app.models.toggleProvider")} provider`,
|
|
136
|
-
`${keyText("app.models.reorderUp")}/${keyText("app.models.reorderDown")} reorder`,
|
|
90
|
+
`${keyText("tui.select.confirm")} select`,
|
|
91
|
+
`${keyText("app.models.toggleFavorite")} favorite`,
|
|
137
92
|
`${keyText("app.models.save")} save`,
|
|
138
93
|
countText,
|
|
139
94
|
];
|
|
140
95
|
return this.isDirty
|
|
141
|
-
? theme.fg("dim", ` ${parts.join(" · ")} `) + theme.fg("warning", "
|
|
96
|
+
? theme.fg("dim", ` ${parts.join(" · ")} `) + theme.fg("warning", "unsaved")
|
|
142
97
|
: theme.fg("dim", ` ${parts.join(" · ")}`);
|
|
143
98
|
}
|
|
144
|
-
|
|
99
|
+
getSecondaryFooterText() {
|
|
100
|
+
const parts = [
|
|
101
|
+
`${keyText("app.models.enableAll")} all`,
|
|
102
|
+
`${keyText("app.models.clearAll")} clear`,
|
|
103
|
+
`${keyText("app.models.toggleProvider")} provider`,
|
|
104
|
+
`${keyText("app.models.reorderUp")}/${keyText("app.models.reorderDown")} order`,
|
|
105
|
+
];
|
|
106
|
+
return theme.fg("dim", ` ${parts.join(" · ")}`);
|
|
107
|
+
}
|
|
108
|
+
refresh(preferredSelectedId) {
|
|
145
109
|
const query = this.searchInput.getValue();
|
|
110
|
+
const selectedId = preferredSelectedId ?? this.filteredItems[this.selectedIndex]?.fullId;
|
|
146
111
|
const items = this.buildItems();
|
|
147
112
|
this.filteredItems = query ? fuzzyFilter(items, query, getModelSearchText) : items;
|
|
148
|
-
|
|
113
|
+
const selectedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;
|
|
114
|
+
this.selectedIndex =
|
|
115
|
+
selectedIndex >= 0 ? selectedIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));
|
|
149
116
|
this.updateList();
|
|
150
117
|
this.footerText.setText(this.getFooterText());
|
|
118
|
+
this.secondaryFooterText.setText(this.getSecondaryFooterText());
|
|
151
119
|
}
|
|
152
120
|
notifyChange() {
|
|
153
121
|
this.callbacks.onChange(this.favoriteIds === null ? null : [...this.favoriteIds]);
|
|
@@ -160,17 +128,17 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
160
128
|
}
|
|
161
129
|
const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible));
|
|
162
130
|
const endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);
|
|
163
|
-
const allFavorite = this.favoriteIds === null;
|
|
164
131
|
for (let i = startIndex; i < endIndex; i++) {
|
|
165
132
|
const item = this.filteredItems[i];
|
|
166
133
|
if (!item)
|
|
167
134
|
continue;
|
|
168
135
|
const isSelected = i === this.selectedIndex;
|
|
169
136
|
const prefix = isSelected ? theme.fg("accent", "→ ") : " ";
|
|
137
|
+
const favoriteMarker = item.favorite ? theme.fg("success", "*") : theme.fg("dim", "-");
|
|
170
138
|
const modelText = isSelected ? theme.fg("accent", item.model.id) : item.model.id;
|
|
171
139
|
const providerBadge = theme.fg("muted", ` [${item.model.provider}]`);
|
|
172
|
-
const
|
|
173
|
-
this.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${
|
|
140
|
+
const currentMarker = this.currentModel && modelsAreEqual(this.currentModel, item.model) ? theme.fg("success", " ✓") : "";
|
|
141
|
+
this.listContainer.addChild(new Text(`${prefix}${favoriteMarker} ${modelText}${providerBadge}${currentMarker}`, 0, 0));
|
|
174
142
|
}
|
|
175
143
|
// Add scroll indicator if needed
|
|
176
144
|
if (startIndex > 0 || endIndex < this.filteredItems.length) {
|
|
@@ -208,47 +176,57 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
208
176
|
if (this.favoriteIds === null)
|
|
209
177
|
return;
|
|
210
178
|
const item = this.filteredItems[this.selectedIndex];
|
|
211
|
-
if (item &&
|
|
179
|
+
if (item && isFavoriteModel(this.favoriteIds, item.fullId)) {
|
|
212
180
|
const delta = reorderUp ? -1 : 1;
|
|
213
181
|
const currentIndex = this.favoriteIds.indexOf(item.fullId);
|
|
214
182
|
const newIndex = currentIndex + delta;
|
|
215
183
|
// Only move if within bounds
|
|
216
184
|
if (newIndex >= 0 && newIndex < this.favoriteIds.length) {
|
|
217
|
-
this.favoriteIds =
|
|
185
|
+
this.favoriteIds = moveFavoriteModel(this.favoriteIds, item.fullId, delta);
|
|
218
186
|
this.isDirty = true;
|
|
219
187
|
this.selectedIndex += delta;
|
|
220
|
-
this.refresh();
|
|
188
|
+
this.refresh(item.fullId);
|
|
221
189
|
this.notifyChange();
|
|
222
190
|
}
|
|
223
191
|
}
|
|
224
192
|
return;
|
|
225
193
|
}
|
|
226
|
-
//
|
|
194
|
+
// Select on Enter
|
|
227
195
|
if (kb.matches(data, "tui.select.confirm")) {
|
|
228
196
|
const item = this.filteredItems[this.selectedIndex];
|
|
229
197
|
if (item) {
|
|
230
|
-
this.
|
|
198
|
+
this.callbacks.onSelect(item.model);
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Toggle favorite status for the selected model
|
|
203
|
+
if (kb.matches(data, "app.models.toggleFavorite")) {
|
|
204
|
+
const item = this.filteredItems[this.selectedIndex];
|
|
205
|
+
if (item) {
|
|
206
|
+
this.favoriteIds = toggleFavoriteModel(this.favoriteIds, this.allIds, item.fullId);
|
|
231
207
|
this.isDirty = true;
|
|
232
|
-
this.refresh();
|
|
208
|
+
this.refresh(item.fullId);
|
|
233
209
|
this.notifyChange();
|
|
234
210
|
}
|
|
235
211
|
return;
|
|
236
212
|
}
|
|
237
213
|
// Favorite all (filtered if search active, otherwise all)
|
|
238
214
|
if (kb.matches(data, "app.models.enableAll")) {
|
|
215
|
+
const item = this.filteredItems[this.selectedIndex];
|
|
239
216
|
const targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;
|
|
240
|
-
this.favoriteIds =
|
|
217
|
+
this.favoriteIds = favoriteModels(this.favoriteIds, this.allIds, targetIds);
|
|
241
218
|
this.isDirty = true;
|
|
242
|
-
this.refresh();
|
|
219
|
+
this.refresh(item?.fullId);
|
|
243
220
|
this.notifyChange();
|
|
244
221
|
return;
|
|
245
222
|
}
|
|
246
223
|
// Clear all (filtered if search active, otherwise all)
|
|
247
224
|
if (kb.matches(data, "app.models.clearAll")) {
|
|
225
|
+
const item = this.filteredItems[this.selectedIndex];
|
|
248
226
|
const targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;
|
|
249
|
-
this.favoriteIds =
|
|
227
|
+
this.favoriteIds = clearFavoriteModels(this.favoriteIds, this.allIds, targetIds);
|
|
250
228
|
this.isDirty = true;
|
|
251
|
-
this.refresh();
|
|
229
|
+
this.refresh(item?.fullId);
|
|
252
230
|
this.notifyChange();
|
|
253
231
|
return;
|
|
254
232
|
}
|
|
@@ -258,12 +236,12 @@ export class FavoriteModelsSelectorComponent extends Container {
|
|
|
258
236
|
if (item) {
|
|
259
237
|
const provider = item.model.provider;
|
|
260
238
|
const providerIds = this.allIds.filter((id) => this.modelsById.get(id)?.provider === provider);
|
|
261
|
-
const allFavorite = providerIds.every((id) =>
|
|
239
|
+
const allFavorite = providerIds.every((id) => isFavoriteModel(this.favoriteIds, id));
|
|
262
240
|
this.favoriteIds = allFavorite
|
|
263
|
-
?
|
|
264
|
-
:
|
|
241
|
+
? clearFavoriteModels(this.favoriteIds, this.allIds, providerIds)
|
|
242
|
+
: favoriteModels(this.favoriteIds, this.allIds, providerIds);
|
|
265
243
|
this.isDirty = true;
|
|
266
|
-
this.refresh();
|
|
244
|
+
this.refresh(item.fullId);
|
|
267
245
|
this.notifyChange();
|
|
268
246
|
}
|
|
269
247
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"favorite-models-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/favorite-models-selector.ts"],"names":[],"mappings":"AACA,OAAO,EACN,SAAS,EAET,WAAW,EACX,cAAc,EACd,KAAK,EACL,GAAG,EACH,UAAU,EACV,MAAM,EACN,IAAI,GACJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAKhD,SAAS,UAAU,CAAC,WAAwB,EAAE,EAAU,EAAW;IAClE,OAAO,WAAW,KAAK,IAAI,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAAA,CACxD;AA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C,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;YAC9C,OAAO;QACR,CAAC;QAED,2CAA2C;QAC3C,IAAI,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACjC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC3B,CAAC;YACD,OAAO;QACR,CAAC;QAED,kBAAkB;QAClB,IAAI,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QAED,uCAAuC;QACvC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IAAA,CACf;IAED,cAAc,GAAU;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import type { Model } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tKey,\n\tmatchesKey,\n\tSpacer,\n\tText,\n} from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\nimport { keyText } from \"./keybinding-hints.js\";\n\n// FavoriteIds: null = all favorite, string[] = explicit ordered list\ntype FavoriteIds = string[] | null;\n\nfunction isFavorite(favoriteIds: FavoriteIds, id: string): boolean {\n\treturn favoriteIds === null || favoriteIds.includes(id);\n}\n\nfunction toggleFavorite(favoriteIds: FavoriteIds, id: string): FavoriteIds {\n\tif (favoriteIds === null) return [id]; // First toggle: start with only this one\n\tconst index = favoriteIds.indexOf(id);\n\tif (index >= 0) return [...favoriteIds.slice(0, index), ...favoriteIds.slice(index + 1)];\n\treturn [...favoriteIds, id];\n}\n\nfunction favoriteAll(favoriteIds: FavoriteIds, allIds: string[], targetIds?: string[]): FavoriteIds {\n\tif (favoriteIds === null) return null; // Already all favorite\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...favoriteIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length ? null : result;\n}\n\nfunction clearAll(favoriteIds: FavoriteIds, allIds: string[], targetIds?: string[]): FavoriteIds {\n\tif (favoriteIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? favoriteIds);\n\treturn favoriteIds.filter((id) => !targets.has(id));\n}\n\nfunction move(favoriteIds: FavoriteIds, id: string, delta: number): FavoriteIds {\n\tif (favoriteIds === null) return null;\n\tconst list = [...favoriteIds];\n\tconst index = list.indexOf(id);\n\tif (index < 0) return list;\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= list.length) return list;\n\tconst result = [...list];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nfunction getSortedIds(favoriteIds: FavoriteIds, allIds: string[]): string[] {\n\tif (favoriteIds === null) return allIds;\n\tconst favoriteSet = new Set(favoriteIds);\n\treturn [...favoriteIds, ...allIds.filter((id) => !favoriteSet.has(id))];\n}\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<any>;\n\tfavorite: boolean;\n}\n\nfunction getModelSearchText(item: ModelItem): string {\n\treturn `${item.fullId} ${item.model.id} ${item.model.name} ${item.model.provider}`;\n}\n\nexport interface FavoriteModelsConfig {\n\tallModels: Model<any>[];\n\tfavoriteModelIds: string[] | null;\n}\n\nexport interface FavoriteModelsCallbacks {\n\t/** Called whenever the favorite model set or order changes (session-only, no persist) */\n\tonChange: (favoriteModelIds: string[] | null) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (favoriteModelIds: string[] | null) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for managing favorite models for Ctrl+P cycling.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class FavoriteModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<any>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate favoriteIds: FavoriteIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate callbacks: FavoriteModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\n\tconstructor(config: FavoriteModelsConfig, callbacks: FavoriteModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.favoriteIds = config.favoriteModelIds === null ? null : [...config.favoriteModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(\"Favorite Models\")), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"muted\", `Session-only. ${keyText(\"app.models.save\")} to save to settings.`), 0, 0),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\t// Filter out IDs that no longer have a corresponding model (e.g., after logout)\n\t\tconst items: ModelItem[] = [];\n\t\tfor (const id of getSortedIds(this.favoriteIds, this.allIds)) {\n\t\t\tconst model = this.modelsById.get(id);\n\t\t\tif (!model) continue;\n\t\t\titems.push({\n\t\t\t\tfullId: id,\n\t\t\t\tmodel,\n\t\t\t\tfavorite: isFavorite(this.favoriteIds, id),\n\t\t\t});\n\t\t}\n\t\treturn items;\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst favoriteCount = this.favoriteIds?.length ?? this.allIds.length;\n\t\tconst allFavorite = this.favoriteIds === null;\n\t\tconst countText = allFavorite ? \"all favorites\" : `${favoriteCount}/${this.allIds.length} favorites`;\n\t\tconst parts = [\n\t\t\t`${keyText(\"tui.select.confirm\")} toggle`,\n\t\t\t`${keyText(\"app.models.enableAll\")} favorite all`,\n\t\t\t`${keyText(\"app.models.clearAll\")} clear`,\n\t\t\t`${keyText(\"app.models.toggleProvider\")} provider`,\n\t\t\t`${keyText(\"app.models.reorderUp\")}/${keyText(\"app.models.reorderDown\")} reorder`,\n\t\t\t`${keyText(\"app.models.save\")} save`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", \"(unsaved)\")\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query ? fuzzyFilter(items, query, getModelSearchText) : items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.favoriteIds === null ? null : [...this.favoriteIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tconst allFavorite = this.favoriteIds === null;\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i];\n\t\t\tif (!item) continue;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", item.model.id) : item.model.id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", ` [${item.model.provider}]`);\n\t\t\tconst status = allFavorite ? \"\" : item.favorite ? theme.fg(\"success\", \" ✓\") : theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tif (selected) {\n\t\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder favorite models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.favoriteIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isFavorite(this.favoriteIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.favoriteIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.favoriteIds.length) {\n\t\t\t\t\tthis.favoriteIds = move(this.favoriteIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.favoriteIds = toggleFavorite(this.favoriteIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Favorite all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.favoriteIds = favoriteAll(this.favoriteIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.favoriteIds = clearAll(this.favoriteIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)?.provider === provider);\n\t\t\t\tconst allFavorite = providerIds.every((id) => isFavorite(this.favoriteIds, id));\n\t\t\t\tthis.favoriteIds = allFavorite\n\t\t\t\t\t? clearAll(this.favoriteIds, this.allIds, providerIds)\n\t\t\t\t\t: favoriteAll(this.favoriteIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.favoriteIds === null ? null : [...this.favoriteIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel\n\t\tif (matchesKey(data, Key.escape)) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"favorite-models-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/favorite-models-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACN,SAAS,EAET,WAAW,EACX,cAAc,EACd,KAAK,EACL,GAAG,EACH,UAAU,EACV,MAAM,EACN,IAAI,GACJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EACN,mBAAmB,EAEnB,cAAc,EACd,cAAc,EACd,yBAAyB,EACzB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAQ9B,SAAS,kBAA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,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import { type Model, modelsAreEqual } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tKey,\n\tmatchesKey,\n\tSpacer,\n\tText,\n} from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\nimport { keyText } from \"./keybinding-hints.js\";\nimport {\n\tclearFavoriteModels,\n\ttype FavoriteModelIds,\n\tfavoriteModels,\n\tgetModelFullId,\n\tgetSortedFavoriteModelIds,\n\tisFavoriteModel,\n\tmoveFavoriteModel,\n\ttoggleFavoriteModel,\n} from \"./model-favorites.js\";\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<any>;\n\tfavorite: boolean;\n}\n\nfunction getModelSearchText(item: ModelItem): string {\n\treturn `${item.fullId} ${item.model.id} ${item.model.name} ${item.model.provider}`;\n}\n\nexport interface FavoriteModelsConfig {\n\tallModels: Model<any>[];\n\tfavoriteModelIds: FavoriteModelIds;\n\tcurrentModel?: Model<any>;\n}\n\nexport interface FavoriteModelsCallbacks {\n\t/** Called whenever the favorite model set or order changes (session-only, no persist) */\n\tonChange: (favoriteModelIds: FavoriteModelIds) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (favoriteModelIds: FavoriteModelIds) => void | Promise<void>;\n\tonSelect: (model: Model<any>) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for managing favorite models for Ctrl+P cycling.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class FavoriteModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<any>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate favoriteIds: FavoriteModelIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\tprivate currentModel?: Model<any>;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate secondaryFooterText: Text;\n\tprivate callbacks: FavoriteModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\n\tconstructor(config: FavoriteModelsConfig, callbacks: FavoriteModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\t\tthis.currentModel = config.currentModel;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = getModelFullId(model);\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.favoriteIds = config.favoriteModelIds === null ? null : [...config.favoriteModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(\"Favorite Models\")), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`${keyText(\"tui.select.confirm\")} selects. ${keyText(\"app.models.toggleFavorite\")} toggles favorite. ${keyText(\"app.models.save\")} saves.`,\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\t\tthis.secondaryFooterText = new Text(this.getSecondaryFooterText(), 0, 0);\n\t\tthis.addChild(this.secondaryFooterText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\t// Filter out IDs that no longer have a corresponding model (e.g., after logout)\n\t\tconst items: ModelItem[] = [];\n\t\tfor (const id of getSortedFavoriteModelIds(this.favoriteIds, this.allIds)) {\n\t\t\tconst model = this.modelsById.get(id);\n\t\t\tif (!model) continue;\n\t\t\titems.push({\n\t\t\t\tfullId: id,\n\t\t\t\tmodel,\n\t\t\t\tfavorite: isFavoriteModel(this.favoriteIds, id),\n\t\t\t});\n\t\t}\n\t\treturn items;\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst favoriteCount = this.favoriteIds?.length ?? this.allIds.length;\n\t\tconst allFavorite = this.favoriteIds === null;\n\t\tconst countText = allFavorite ? \"all favorites\" : `${favoriteCount}/${this.allIds.length} favorites`;\n\t\tconst parts = [\n\t\t\t`${keyText(\"tui.select.confirm\")} select`,\n\t\t\t`${keyText(\"app.models.toggleFavorite\")} favorite`,\n\t\t\t`${keyText(\"app.models.save\")} save`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", \"unsaved\")\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate getSecondaryFooterText(): string {\n\t\tconst parts = [\n\t\t\t`${keyText(\"app.models.enableAll\")} all`,\n\t\t\t`${keyText(\"app.models.clearAll\")} clear`,\n\t\t\t`${keyText(\"app.models.toggleProvider\")} provider`,\n\t\t\t`${keyText(\"app.models.reorderUp\")}/${keyText(\"app.models.reorderDown\")} order`,\n\t\t];\n\t\treturn theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(preferredSelectedId?: string): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst selectedId = preferredSelectedId ?? this.filteredItems[this.selectedIndex]?.fullId;\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query ? fuzzyFilter(items, query, getModelSearchText) : items;\n\t\tconst selectedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;\n\t\tthis.selectedIndex =\n\t\t\tselectedIndex >= 0 ? selectedIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t\tthis.secondaryFooterText.setText(this.getSecondaryFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.favoriteIds === null ? null : [...this.favoriteIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i];\n\t\t\tif (!item) continue;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst favoriteMarker = item.favorite ? theme.fg(\"success\", \"*\") : theme.fg(\"dim\", \"-\");\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", item.model.id) : item.model.id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", ` [${item.model.provider}]`);\n\t\t\tconst currentMarker =\n\t\t\t\tthis.currentModel && modelsAreEqual(this.currentModel, item.model) ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(`${prefix}${favoriteMarker} ${modelText}${providerBadge}${currentMarker}`, 0, 0),\n\t\t\t);\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tif (selected) {\n\t\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder favorite models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.favoriteIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isFavoriteModel(this.favoriteIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.favoriteIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.favoriteIds.length) {\n\t\t\t\t\tthis.favoriteIds = moveFavoriteModel(this.favoriteIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh(item.fullId);\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Select on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.callbacks.onSelect(item.model);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle favorite status for the selected model\n\t\tif (kb.matches(data, \"app.models.toggleFavorite\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.favoriteIds = toggleFavoriteModel(this.favoriteIds, this.allIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh(item.fullId);\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Favorite all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.favoriteIds = favoriteModels(this.favoriteIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh(item?.fullId);\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.favoriteIds = clearFavoriteModels(this.favoriteIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh(item?.fullId);\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)?.provider === provider);\n\t\t\t\tconst allFavorite = providerIds.every((id) => isFavoriteModel(this.favoriteIds, id));\n\t\t\t\tthis.favoriteIds = allFavorite\n\t\t\t\t\t? clearFavoriteModels(this.favoriteIds, this.allIds, providerIds)\n\t\t\t\t\t: favoriteModels(this.favoriteIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh(item.fullId);\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.favoriteIds === null ? null : [...this.favoriteIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel\n\t\tif (matchesKey(data, Key.escape)) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Model } from "@earendil-works/pi-ai";
|
|
2
|
+
export type FavoriteModelIds = string[] | null;
|
|
3
|
+
export declare function getModelFullId(model: Model<any>): string;
|
|
4
|
+
export declare function isFavoriteModel(favoriteIds: FavoriteModelIds, id: string): boolean;
|
|
5
|
+
export declare function toggleFavoriteModel(favoriteIds: FavoriteModelIds, allIds: string[], id: string): FavoriteModelIds;
|
|
6
|
+
export declare function favoriteModels(favoriteIds: FavoriteModelIds, allIds: string[], targetIds?: string[]): FavoriteModelIds;
|
|
7
|
+
export declare function clearFavoriteModels(favoriteIds: FavoriteModelIds, allIds: string[], targetIds?: string[]): FavoriteModelIds;
|
|
8
|
+
export declare function moveFavoriteModel(favoriteIds: FavoriteModelIds, id: string, delta: number): FavoriteModelIds;
|
|
9
|
+
export declare function getSortedFavoriteModelIds(favoriteIds: FavoriteModelIds, allIds: string[]): string[];
|
|
10
|
+
//# sourceMappingURL=model-favorites.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-favorites.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/model-favorites.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;AAE/C,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAExD;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAElF;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,gBAAgB,CAOjH;AAED,wBAAgB,cAAc,CAC7B,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,GAClB,gBAAgB,CAQlB;AAED,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,GAClB,gBAAgB,CAMlB;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAS5G;AAED,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAInG","sourcesContent":["import type { Model } from \"@earendil-works/pi-ai\";\n\nexport type FavoriteModelIds = string[] | null;\n\nexport function getModelFullId(model: Model<any>): string {\n\treturn `${model.provider}/${model.id}`;\n}\n\nexport function isFavoriteModel(favoriteIds: FavoriteModelIds, id: string): boolean {\n\treturn favoriteIds === null || favoriteIds.includes(id);\n}\n\nexport function toggleFavoriteModel(favoriteIds: FavoriteModelIds, allIds: string[], id: string): FavoriteModelIds {\n\tif (favoriteIds === null) {\n\t\treturn allIds.filter((candidateId) => candidateId !== id);\n\t}\n\tconst index = favoriteIds.indexOf(id);\n\tif (index >= 0) return [...favoriteIds.slice(0, index), ...favoriteIds.slice(index + 1)];\n\treturn [...favoriteIds, id];\n}\n\nexport function favoriteModels(\n\tfavoriteIds: FavoriteModelIds,\n\tallIds: string[],\n\ttargetIds?: string[],\n): FavoriteModelIds {\n\tif (favoriteIds === null) return null;\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...favoriteIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length ? null : result;\n}\n\nexport function clearFavoriteModels(\n\tfavoriteIds: FavoriteModelIds,\n\tallIds: string[],\n\ttargetIds?: string[],\n): FavoriteModelIds {\n\tif (favoriteIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? favoriteIds);\n\treturn favoriteIds.filter((id) => !targets.has(id));\n}\n\nexport function moveFavoriteModel(favoriteIds: FavoriteModelIds, id: string, delta: number): FavoriteModelIds {\n\tif (favoriteIds === null) return null;\n\tconst index = favoriteIds.indexOf(id);\n\tif (index < 0) return [...favoriteIds];\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= favoriteIds.length) return [...favoriteIds];\n\tconst result = [...favoriteIds];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nexport function getSortedFavoriteModelIds(favoriteIds: FavoriteModelIds, allIds: string[]): string[] {\n\tif (favoriteIds === null) return allIds;\n\tconst favoriteSet = new Set(favoriteIds);\n\treturn [...favoriteIds, ...allIds.filter((id) => !favoriteSet.has(id))];\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function getModelFullId(model) {
|
|
2
|
+
return `${model.provider}/${model.id}`;
|
|
3
|
+
}
|
|
4
|
+
export function isFavoriteModel(favoriteIds, id) {
|
|
5
|
+
return favoriteIds === null || favoriteIds.includes(id);
|
|
6
|
+
}
|
|
7
|
+
export function toggleFavoriteModel(favoriteIds, allIds, id) {
|
|
8
|
+
if (favoriteIds === null) {
|
|
9
|
+
return allIds.filter((candidateId) => candidateId !== id);
|
|
10
|
+
}
|
|
11
|
+
const index = favoriteIds.indexOf(id);
|
|
12
|
+
if (index >= 0)
|
|
13
|
+
return [...favoriteIds.slice(0, index), ...favoriteIds.slice(index + 1)];
|
|
14
|
+
return [...favoriteIds, id];
|
|
15
|
+
}
|
|
16
|
+
export function favoriteModels(favoriteIds, allIds, targetIds) {
|
|
17
|
+
if (favoriteIds === null)
|
|
18
|
+
return null;
|
|
19
|
+
const targets = targetIds ?? allIds;
|
|
20
|
+
const result = [...favoriteIds];
|
|
21
|
+
for (const id of targets) {
|
|
22
|
+
if (!result.includes(id))
|
|
23
|
+
result.push(id);
|
|
24
|
+
}
|
|
25
|
+
return result.length === allIds.length ? null : result;
|
|
26
|
+
}
|
|
27
|
+
export function clearFavoriteModels(favoriteIds, allIds, targetIds) {
|
|
28
|
+
if (favoriteIds === null) {
|
|
29
|
+
return targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];
|
|
30
|
+
}
|
|
31
|
+
const targets = new Set(targetIds ?? favoriteIds);
|
|
32
|
+
return favoriteIds.filter((id) => !targets.has(id));
|
|
33
|
+
}
|
|
34
|
+
export function moveFavoriteModel(favoriteIds, id, delta) {
|
|
35
|
+
if (favoriteIds === null)
|
|
36
|
+
return null;
|
|
37
|
+
const index = favoriteIds.indexOf(id);
|
|
38
|
+
if (index < 0)
|
|
39
|
+
return [...favoriteIds];
|
|
40
|
+
const newIndex = index + delta;
|
|
41
|
+
if (newIndex < 0 || newIndex >= favoriteIds.length)
|
|
42
|
+
return [...favoriteIds];
|
|
43
|
+
const result = [...favoriteIds];
|
|
44
|
+
[result[index], result[newIndex]] = [result[newIndex], result[index]];
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
export function getSortedFavoriteModelIds(favoriteIds, allIds) {
|
|
48
|
+
if (favoriteIds === null)
|
|
49
|
+
return allIds;
|
|
50
|
+
const favoriteSet = new Set(favoriteIds);
|
|
51
|
+
return [...favoriteIds, ...allIds.filter((id) => !favoriteSet.has(id))];
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=model-favorites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-favorites.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/model-favorites.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,cAAc,CAAC,KAAiB,EAAU;IACzD,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;AAAA,CACvC;AAED,MAAM,UAAU,eAAe,CAAC,WAA6B,EAAE,EAAU,EAAW;IACnF,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C;IACzC,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAAA,CACxE","sourcesContent":["import type { Model } from \"@earendil-works/pi-ai\";\n\nexport type FavoriteModelIds = string[] | null;\n\nexport function getModelFullId(model: Model<any>): string {\n\treturn `${model.provider}/${model.id}`;\n}\n\nexport function isFavoriteModel(favoriteIds: FavoriteModelIds, id: string): boolean {\n\treturn favoriteIds === null || favoriteIds.includes(id);\n}\n\nexport function toggleFavoriteModel(favoriteIds: FavoriteModelIds, allIds: string[], id: string): FavoriteModelIds {\n\tif (favoriteIds === null) {\n\t\treturn allIds.filter((candidateId) => candidateId !== id);\n\t}\n\tconst index = favoriteIds.indexOf(id);\n\tif (index >= 0) return [...favoriteIds.slice(0, index), ...favoriteIds.slice(index + 1)];\n\treturn [...favoriteIds, id];\n}\n\nexport function favoriteModels(\n\tfavoriteIds: FavoriteModelIds,\n\tallIds: string[],\n\ttargetIds?: string[],\n): FavoriteModelIds {\n\tif (favoriteIds === null) return null;\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...favoriteIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length ? null : result;\n}\n\nexport function clearFavoriteModels(\n\tfavoriteIds: FavoriteModelIds,\n\tallIds: string[],\n\ttargetIds?: string[],\n): FavoriteModelIds {\n\tif (favoriteIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? favoriteIds);\n\treturn favoriteIds.filter((id) => !targets.has(id));\n}\n\nexport function moveFavoriteModel(favoriteIds: FavoriteModelIds, id: string, delta: number): FavoriteModelIds {\n\tif (favoriteIds === null) return null;\n\tconst index = favoriteIds.indexOf(id);\n\tif (index < 0) return [...favoriteIds];\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= favoriteIds.length) return [...favoriteIds];\n\tconst result = [...favoriteIds];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nexport function getSortedFavoriteModelIds(favoriteIds: FavoriteModelIds, allIds: string[]): string[] {\n\tif (favoriteIds === null) return allIds;\n\tconst favoriteSet = new Set(favoriteIds);\n\treturn [...favoriteIds, ...allIds.filter((id) => !favoriteSet.has(id))];\n}\n"]}
|
|
@@ -2,11 +2,16 @@ import { type Model } from "@earendil-works/pi-ai";
|
|
|
2
2
|
import { Container, type Focusable, Input, type TUI } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { ModelRegistry } from "../../../core/model-registry.js";
|
|
4
4
|
import type { SettingsManager } from "../../../core/settings-manager.js";
|
|
5
|
+
import { type FavoriteModelIds } from "./model-favorites.js";
|
|
5
6
|
interface ScopedModelItem {
|
|
6
7
|
model: Model<any>;
|
|
7
8
|
thinkingLevel?: string;
|
|
8
9
|
}
|
|
9
10
|
type ModelSelectorTui = Pick<TUI, "requestRender">;
|
|
11
|
+
export interface ModelSelectorFavoriteOptions {
|
|
12
|
+
favoriteModelIds?: FavoriteModelIds;
|
|
13
|
+
onFavoriteChange?: (favoriteModelIds: FavoriteModelIds, allModels: Model<any>[], toggledModel: Model<any>) => void | Promise<void>;
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* Component that renders a model selector with search
|
|
12
17
|
*/
|
|
@@ -26,13 +31,15 @@ export declare class ModelSelectorComponent extends Container implements Focusab
|
|
|
26
31
|
private modelRegistry;
|
|
27
32
|
private onSelectCallback;
|
|
28
33
|
private onCancelCallback;
|
|
34
|
+
private favoriteIds;
|
|
35
|
+
private onFavoriteChangeCallback?;
|
|
29
36
|
private errorMessage?;
|
|
30
37
|
private tui;
|
|
31
38
|
private scopedModels;
|
|
32
39
|
private scope;
|
|
33
40
|
private scopeText?;
|
|
34
41
|
private scopeHintText?;
|
|
35
|
-
constructor(tui: ModelSelectorTui, currentModel: Model<any> | undefined, settingsManager: SettingsManager, modelRegistry: ModelRegistry, scopedModels: ReadonlyArray<ScopedModelItem>, onSelect: (model: Model<any>) => void, onCancel: () => void, initialSearchInput?: string);
|
|
42
|
+
constructor(tui: ModelSelectorTui, currentModel: Model<any> | undefined, settingsManager: SettingsManager, modelRegistry: ModelRegistry, scopedModels: ReadonlyArray<ScopedModelItem>, onSelect: (model: Model<any>) => void, onCancel: () => void, initialSearchInput?: string, favorites?: ModelSelectorFavoriteOptions);
|
|
36
43
|
private loadModels;
|
|
37
44
|
private sortModels;
|
|
38
45
|
private getScopeText;
|
|
@@ -42,6 +49,7 @@ export declare class ModelSelectorComponent extends Container implements Focusab
|
|
|
42
49
|
private updateList;
|
|
43
50
|
handleInput(keyData: string): void;
|
|
44
51
|
private handleSelect;
|
|
52
|
+
private handleToggleFavorite;
|
|
45
53
|
getSearchInput(): Input;
|
|
46
54
|
}
|
|
47
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/model-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAGd,KAAK,EAGL,KAAK,GAAG,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAezE,UAAU,eAAe;IACxB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,KAAK,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAEnD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,SAAS;IACzE,OAAO,CAA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CAwCjC;IAED,OAAO,CAAC,YAAY;IAMpB,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import { type Model, modelsAreEqual } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@earendil-works/pi-tui\";\nimport type { ModelRegistry } from \"../../../core/model-registry.js\";\nimport type { SettingsManager } from \"../../../core/settings-manager.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\n\ninterface ModelItem {\n\tprovider: string;\n\tid: string;\n\tmodel: Model<any>;\n}\n\nfunction getModelSearchText({ id, provider, model }: ModelItem): string {\n\treturn `${provider}/${id} ${id} ${model.name} ${provider}`;\n}\n\ninterface ScopedModelItem {\n\tmodel: Model<any>;\n\tthinkingLevel?: string;\n}\n\ntype ModelScope = \"all\" | \"narrowed\";\ntype ModelSelectorTui = Pick<TUI, \"requestRender\">;\n\n/**\n * Component that renders a model selector with search\n */\nexport class ModelSelectorComponent extends Container implements Focusable {\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate allModels: ModelItem[] = [];\n\tprivate scopedModelItems: ModelItem[] = [];\n\tprivate activeModels: ModelItem[] = [];\n\tprivate filteredModels: ModelItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate currentModel?: Model<any>;\n\tprivate settingsManager: SettingsManager;\n\tprivate modelRegistry: ModelRegistry;\n\tprivate onSelectCallback: (model: Model<any>) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate errorMessage?: string;\n\tprivate tui: ModelSelectorTui;\n\tprivate scopedModels: ReadonlyArray<ScopedModelItem>;\n\tprivate scope: ModelScope = \"all\";\n\tprivate scopeText?: Text;\n\tprivate scopeHintText?: Text;\n\n\tconstructor(\n\t\ttui: ModelSelectorTui,\n\t\tcurrentModel: Model<any> | undefined,\n\t\tsettingsManager: SettingsManager,\n\t\tmodelRegistry: ModelRegistry,\n\t\tscopedModels: ReadonlyArray<ScopedModelItem>,\n\t\tonSelect: (model: Model<any>) => void,\n\t\tonCancel: () => void,\n\t\tinitialSearchInput?: string,\n\t) {\n\t\tsuper();\n\n\t\tthis.tui = tui;\n\t\tthis.currentModel = currentModel;\n\t\tthis.settingsManager = settingsManager;\n\t\tthis.modelRegistry = modelRegistry;\n\t\tthis.scopedModels = scopedModels;\n\t\tthis.scope = scopedModels.length > 0 ? \"narrowed\" : \"all\";\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add hint about model filtering\n\t\tif (scopedModels.length > 0) {\n\t\t\tthis.scopeText = new Text(this.getScopeText(), 0, 0);\n\t\t\tthis.addChild(this.scopeText);\n\t\t\tthis.scopeHintText = new Text(this.getScopeHintText(), 0, 0);\n\t\t\tthis.addChild(this.scopeHintText);\n\t\t} else {\n\t\t\tconst hintText = \"Only showing models from configured providers. Use /login to add providers.\";\n\t\t\tthis.addChild(new Text(theme.fg(\"warning\", hintText), 0, 0));\n\t\t}\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create search input\n\t\tthis.searchInput = new Input();\n\t\tif (initialSearchInput) {\n\t\t\tthis.searchInput.setValue(initialSearchInput);\n\t\t}\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\t// Enter on search input selects the first filtered item\n\t\t\tif (this.filteredModels[this.selectedIndex]) {\n\t\t\t\tthis.handleSelect(this.filteredModels[this.selectedIndex].model);\n\t\t\t}\n\t\t};\n\t\tthis.addChild(this.searchInput);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create list container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Load models and do initial render\n\t\tthis.loadModels().then(() => {\n\t\t\tif (initialSearchInput) {\n\t\t\t\tthis.filterModels(initialSearchInput);\n\t\t\t} else {\n\t\t\t\tthis.updateList();\n\t\t\t}\n\t\t\t// Request re-render after models are loaded\n\t\t\tthis.tui.requestRender();\n\t\t});\n\t}\n\n\tprivate async loadModels(): Promise<void> {\n\t\tlet models: ModelItem[];\n\n\t\t// Refresh to pick up any changes to models.json\n\t\tthis.modelRegistry.refresh();\n\n\t\t// Check for models.json errors\n\t\tconst loadError = this.modelRegistry.getError();\n\t\tif (loadError) {\n\t\t\tthis.errorMessage = loadError;\n\t\t}\n\n\t\t// Load available models (built-in models still work even if models.json failed)\n\t\ttry {\n\t\t\tconst availableModels = await this.modelRegistry.getAvailable();\n\t\t\tmodels = availableModels.map((model: Model<any>) => ({\n\t\t\t\tprovider: model.provider,\n\t\t\t\tid: model.id,\n\t\t\t\tmodel,\n\t\t\t}));\n\t\t} catch (error) {\n\t\t\tthis.allModels = [];\n\t\t\tthis.scopedModelItems = [];\n\t\t\tthis.activeModels = [];\n\t\t\tthis.filteredModels = [];\n\t\t\tthis.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.allModels = this.sortModels(models);\n\t\tconst modelsById = new Map(models.map((model) => [`${model.provider}/${model.id}`, model]));\n\t\tthis.scopedModels = this.scopedModels.map((scoped) => {\n\t\t\tconst refreshed = this.modelRegistry.find(scoped.model.provider, scoped.model.id);\n\t\t\treturn refreshed ? { ...scoped, model: refreshed } : scoped;\n\t\t});\n\t\tthis.scopedModelItems = this.scopedModels.flatMap((scoped) => {\n\t\t\tconst refreshed = modelsById.get(`${scoped.model.provider}/${scoped.model.id}`);\n\t\t\treturn refreshed ? [refreshed] : [];\n\t\t});\n\t\tthis.activeModels = this.scope === \"narrowed\" ? this.scopedModelItems : this.allModels;\n\t\tthis.filteredModels = this.activeModels;\n\t\tconst currentIndex = this.filteredModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex =\n\t\t\tcurrentIndex >= 0 ? currentIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t}\n\n\tprivate sortModels(models: ModelItem[]): ModelItem[] {\n\t\tconst sorted = [...models];\n\t\t// Sort: current model first, then by provider\n\t\tsorted.sort((a, b) => {\n\t\t\tconst aIsCurrent = modelsAreEqual(this.currentModel, a.model);\n\t\t\tconst bIsCurrent = modelsAreEqual(this.currentModel, b.model);\n\t\t\tif (aIsCurrent && !bIsCurrent) return -1;\n\t\t\tif (!aIsCurrent && bIsCurrent) return 1;\n\t\t\treturn a.provider.localeCompare(b.provider);\n\t\t});\n\t\treturn sorted;\n\t}\n\n\tprivate getScopeText(): string {\n\t\tconst allText = this.scope === \"all\" ? theme.fg(\"accent\", \"all\") : theme.fg(\"muted\", \"all\");\n\t\tconst narrowedText = this.scope === \"narrowed\" ? theme.fg(\"accent\", \"narrowed\") : theme.fg(\"muted\", \"narrowed\");\n\t\treturn `${theme.fg(\"muted\", \"Catalog: \")}${allText}${theme.fg(\"muted\", \" | \")}${narrowedText}`;\n\t}\n\n\tprivate getScopeHintText(): string {\n\t\treturn keyHint(\"tui.input.tab\", \"catalog\") + theme.fg(\"muted\", \" (all/narrowed)\");\n\t}\n\n\tprivate setScope(scope: ModelScope): void {\n\t\tif (this.scope === scope) return;\n\t\tthis.scope = scope;\n\t\tthis.activeModels = this.scope === \"narrowed\" ? this.scopedModelItems : this.allModels;\n\t\tconst currentIndex = this.activeModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex = currentIndex >= 0 ? currentIndex : 0;\n\t\tthis.filterModels(this.searchInput.getValue());\n\t\tif (this.scopeText) {\n\t\t\tthis.scopeText.setText(this.getScopeText());\n\t\t}\n\t}\n\n\tprivate filterModels(query: string): void {\n\t\tthis.filteredModels = query ? fuzzyFilter(this.activeModels, query, getModelSearchText) : this.activeModels;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tconst maxVisible = 10;\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(maxVisible / 2), this.filteredModels.length - maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + maxVisible, this.filteredModels.length);\n\n\t\t// Show visible slice of filtered models\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredModels[i];\n\t\t\tif (!item) continue;\n\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst isCurrent = modelsAreEqual(this.currentModel, item.model);\n\n\t\t\tlet line = \"\";\n\t\t\tif (isSelected) {\n\t\t\t\tconst prefix = theme.fg(\"accent\", \"→ \");\n\t\t\t\tconst modelText = `${item.id}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${prefix + theme.fg(\"accent\", modelText)} ${providerBadge}${checkmark}`;\n\t\t\t} else {\n\t\t\t\tconst modelText = ` ${item.id}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${modelText} ${providerBadge}${checkmark}`;\n\t\t\t}\n\n\t\t\tthis.listContainer.addChild(new Text(line, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredModels.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredModels.length})`);\n\t\t\tthis.listContainer.addChild(new Text(scrollInfo, 0, 0));\n\t\t}\n\n\t\t// Show error message or \"no results\" if empty\n\t\tif (this.errorMessage) {\n\t\t\t// Show error in red\n\t\t\tconst errorLines = this.errorMessage.split(\"\\n\");\n\t\t\tfor (const line of errorLines) {\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"error\", line), 0, 0));\n\t\t\t}\n\t\t} else if (this.filteredModels.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredModels[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\tif (this.scopedModelItems.length > 0) {\n\t\t\t\tconst nextScope: ModelScope = this.scope === \"all\" ? \"narrowed\" : \"all\";\n\t\t\t\tthis.setScope(nextScope);\n\t\t\t\tif (this.scopeHintText) {\n\t\t\t\t\tthis.scopeHintText.setText(this.getScopeHintText());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t// Up arrow - wrap to bottom when at top\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Down arrow - wrap to top when at bottom\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tconst selectedModel = this.filteredModels[this.selectedIndex];\n\t\t\tif (selectedModel) {\n\t\t\t\tthis.handleSelect(selectedModel.model);\n\t\t\t}\n\t\t}\n\t\t// Escape or Ctrl+C\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterModels(this.searchInput.getValue());\n\t\t}\n\t}\n\n\tprivate handleSelect(model: Model<any>): void {\n\t\t// Save as new default\n\t\tthis.settingsManager.setDefaultModelAndProvider(model.provider, model.id);\n\t\tthis.onSelectCallback(model);\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/model-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAGd,KAAK,EAGL,KAAK,GAAG,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAIzE,OAAO,EAAE,KAAK,gBAAgB,EAAwD,MAAM,sBAAsB,CAAC;AAanH,UAAU,eAAe;IACxB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,KAAK,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAEnD,MAAM,WAAW,4BAA4B;IAC5C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gBA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AAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EACrC,QAAQ,EAAE,MAAM,IAAI,EACpB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,SAAS,CAAC,EAAE,4BAA4B,EAyExC;YAEa,UAAU;IA+CxB,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,UAAU;IA4DlB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CA4CjC;IAED,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,oBAAoB;IAuB5B,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import { type Model, modelsAreEqual } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@earendil-works/pi-tui\";\nimport type { ModelRegistry } from \"../../../core/model-registry.js\";\nimport type { SettingsManager } from \"../../../core/settings-manager.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\nimport { type FavoriteModelIds, getModelFullId, isFavoriteModel, toggleFavoriteModel } from \"./model-favorites.js\";\n\ninterface ModelItem {\n\tfullId: string;\n\tprovider: string;\n\tid: string;\n\tmodel: Model<any>;\n}\n\nfunction getModelSearchText({ fullId, id, provider, model }: ModelItem): string {\n\treturn `${fullId} ${provider}/${id} ${id} ${model.name} ${provider}`;\n}\n\ninterface ScopedModelItem {\n\tmodel: Model<any>;\n\tthinkingLevel?: string;\n}\n\ntype ModelScope = \"all\" | \"narrowed\";\ntype ModelSelectorTui = Pick<TUI, \"requestRender\">;\n\nexport interface ModelSelectorFavoriteOptions {\n\tfavoriteModelIds?: FavoriteModelIds;\n\tonFavoriteChange?: (\n\t\tfavoriteModelIds: FavoriteModelIds,\n\t\tallModels: Model<any>[],\n\t\ttoggledModel: Model<any>,\n\t) => void | Promise<void>;\n}\n\n/**\n * Component that renders a model selector with search\n */\nexport class ModelSelectorComponent extends Container implements Focusable {\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate allModels: ModelItem[] = [];\n\tprivate scopedModelItems: ModelItem[] = [];\n\tprivate activeModels: ModelItem[] = [];\n\tprivate filteredModels: ModelItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate currentModel?: Model<any>;\n\tprivate settingsManager: SettingsManager;\n\tprivate modelRegistry: ModelRegistry;\n\tprivate onSelectCallback: (model: Model<any>) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate favoriteIds: FavoriteModelIds = [];\n\tprivate onFavoriteChangeCallback?: ModelSelectorFavoriteOptions[\"onFavoriteChange\"];\n\tprivate errorMessage?: string;\n\tprivate tui: ModelSelectorTui;\n\tprivate scopedModels: ReadonlyArray<ScopedModelItem>;\n\tprivate scope: ModelScope = \"all\";\n\tprivate scopeText?: Text;\n\tprivate scopeHintText?: Text;\n\n\tconstructor(\n\t\ttui: ModelSelectorTui,\n\t\tcurrentModel: Model<any> | undefined,\n\t\tsettingsManager: SettingsManager,\n\t\tmodelRegistry: ModelRegistry,\n\t\tscopedModels: ReadonlyArray<ScopedModelItem>,\n\t\tonSelect: (model: Model<any>) => void,\n\t\tonCancel: () => void,\n\t\tinitialSearchInput?: string,\n\t\tfavorites?: ModelSelectorFavoriteOptions,\n\t) {\n\t\tsuper();\n\n\t\tthis.tui = tui;\n\t\tthis.currentModel = currentModel;\n\t\tthis.settingsManager = settingsManager;\n\t\tthis.modelRegistry = modelRegistry;\n\t\tthis.scopedModels = scopedModels;\n\t\tthis.scope = scopedModels.length > 0 ? \"narrowed\" : \"all\";\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\t\tthis.favoriteIds = favorites?.favoriteModelIds === null ? null : [...(favorites?.favoriteModelIds ?? [])];\n\t\tthis.onFavoriteChangeCallback = favorites?.onFavoriteChange;\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add hint about model filtering\n\t\tif (scopedModels.length > 0) {\n\t\t\tthis.scopeText = new Text(this.getScopeText(), 0, 0);\n\t\t\tthis.addChild(this.scopeText);\n\t\t\tthis.scopeHintText = new Text(this.getScopeHintText(), 0, 0);\n\t\t\tthis.addChild(this.scopeHintText);\n\t\t} else {\n\t\t\tconst hintText = \"Only showing models from configured providers. Use /login to add providers.\";\n\t\t\tthis.addChild(new Text(theme.fg(\"warning\", hintText), 0, 0));\n\t\t}\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\t`${keyHint(\"tui.select.confirm\", \"select\")} ${keyHint(\"app.models.toggleFavorite\", \"favorite\")}`,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create search input\n\t\tthis.searchInput = new Input();\n\t\tif (initialSearchInput) {\n\t\t\tthis.searchInput.setValue(initialSearchInput);\n\t\t}\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\t// Enter on search input selects the first filtered item\n\t\t\tif (this.filteredModels[this.selectedIndex]) {\n\t\t\t\tthis.handleSelect(this.filteredModels[this.selectedIndex].model);\n\t\t\t}\n\t\t};\n\t\tthis.addChild(this.searchInput);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create list container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Load models and do initial render\n\t\tthis.loadModels().then(() => {\n\t\t\tif (initialSearchInput) {\n\t\t\t\tthis.filterModels(initialSearchInput);\n\t\t\t} else {\n\t\t\t\tthis.updateList();\n\t\t\t}\n\t\t\t// Request re-render after models are loaded\n\t\t\tthis.tui.requestRender();\n\t\t});\n\t}\n\n\tprivate async loadModels(): Promise<void> {\n\t\tlet models: ModelItem[];\n\n\t\t// Refresh to pick up any changes to models.json\n\t\tthis.modelRegistry.refresh();\n\n\t\t// Check for models.json errors\n\t\tconst loadError = this.modelRegistry.getError();\n\t\tif (loadError) {\n\t\t\tthis.errorMessage = loadError;\n\t\t}\n\n\t\t// Load available models (built-in models still work even if models.json failed)\n\t\ttry {\n\t\t\tconst availableModels = this.modelRegistry.getAvailable();\n\t\t\tmodels = availableModels.map((model: Model<any>) => ({\n\t\t\t\tfullId: getModelFullId(model),\n\t\t\t\tprovider: model.provider,\n\t\t\t\tid: model.id,\n\t\t\t\tmodel,\n\t\t\t}));\n\t\t} catch (error) {\n\t\t\tthis.allModels = [];\n\t\t\tthis.scopedModelItems = [];\n\t\t\tthis.activeModels = [];\n\t\t\tthis.filteredModels = [];\n\t\t\tthis.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.allModels = this.sortModels(models);\n\t\tconst modelsById = new Map(models.map((model) => [model.fullId, model]));\n\t\tthis.scopedModels = this.scopedModels.map((scoped) => {\n\t\t\tconst refreshed = this.modelRegistry.find(scoped.model.provider, scoped.model.id);\n\t\t\treturn refreshed ? { ...scoped, model: refreshed } : scoped;\n\t\t});\n\t\tthis.scopedModelItems = this.scopedModels.flatMap((scoped) => {\n\t\t\tconst refreshed = modelsById.get(`${scoped.model.provider}/${scoped.model.id}`);\n\t\t\treturn refreshed ? [refreshed] : [];\n\t\t});\n\t\tthis.activeModels = this.scope === \"narrowed\" ? this.scopedModelItems : this.allModels;\n\t\tthis.filteredModels = this.activeModels;\n\t\tconst currentIndex = this.filteredModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex =\n\t\t\tcurrentIndex >= 0 ? currentIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t}\n\n\tprivate sortModels(models: ModelItem[]): ModelItem[] {\n\t\tconst sorted = [...models];\n\t\t// Sort: current model first, then favorites, then by provider/model.\n\t\tsorted.sort((a, b) => {\n\t\t\tconst aIsCurrent = modelsAreEqual(this.currentModel, a.model);\n\t\t\tconst bIsCurrent = modelsAreEqual(this.currentModel, b.model);\n\t\t\tif (aIsCurrent && !bIsCurrent) return -1;\n\t\t\tif (!aIsCurrent && bIsCurrent) return 1;\n\t\t\tconst aIsFavorite = isFavoriteModel(this.favoriteIds, a.fullId);\n\t\t\tconst bIsFavorite = isFavoriteModel(this.favoriteIds, b.fullId);\n\t\t\tif (aIsFavorite && !bIsFavorite) return -1;\n\t\t\tif (!aIsFavorite && bIsFavorite) return 1;\n\t\t\tconst providerCompare = a.provider.localeCompare(b.provider);\n\t\t\tif (providerCompare !== 0) return providerCompare;\n\t\t\treturn a.id.localeCompare(b.id);\n\t\t});\n\t\treturn sorted;\n\t}\n\n\tprivate getScopeText(): string {\n\t\tconst allText = this.scope === \"all\" ? theme.fg(\"accent\", \"all\") : theme.fg(\"muted\", \"all\");\n\t\tconst narrowedText = this.scope === \"narrowed\" ? theme.fg(\"accent\", \"narrowed\") : theme.fg(\"muted\", \"narrowed\");\n\t\treturn `${theme.fg(\"muted\", \"Catalog: \")}${allText}${theme.fg(\"muted\", \" | \")}${narrowedText}`;\n\t}\n\n\tprivate getScopeHintText(): string {\n\t\treturn keyHint(\"tui.input.tab\", \"catalog\") + theme.fg(\"muted\", \" (all/narrowed)\");\n\t}\n\n\tprivate setScope(scope: ModelScope): void {\n\t\tif (this.scope === scope) return;\n\t\tthis.scope = scope;\n\t\tthis.activeModels = this.scope === \"narrowed\" ? this.scopedModelItems : this.allModels;\n\t\tconst currentIndex = this.activeModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));\n\t\tthis.selectedIndex = currentIndex >= 0 ? currentIndex : 0;\n\t\tthis.filterModels(this.searchInput.getValue());\n\t\tif (this.scopeText) {\n\t\t\tthis.scopeText.setText(this.getScopeText());\n\t\t}\n\t}\n\n\tprivate filterModels(query: string): void {\n\t\tthis.filteredModels = query ? fuzzyFilter(this.activeModels, query, getModelSearchText) : this.activeModels;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tconst maxVisible = 10;\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(maxVisible / 2), this.filteredModels.length - maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + maxVisible, this.filteredModels.length);\n\n\t\t// Show visible slice of filtered models\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredModels[i];\n\t\t\tif (!item) continue;\n\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst isCurrent = modelsAreEqual(this.currentModel, item.model);\n\t\t\tconst favoriteMarker = isFavoriteModel(this.favoriteIds, item.fullId)\n\t\t\t\t? theme.fg(\"success\", \"* \")\n\t\t\t\t: theme.fg(\"dim\", \" \");\n\n\t\t\tlet line = \"\";\n\t\t\tif (isSelected) {\n\t\t\t\tconst prefix = theme.fg(\"accent\", \"→ \");\n\t\t\t\tconst modelText = `${favoriteMarker}${theme.fg(\"accent\", item.id)}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${prefix}${modelText} ${providerBadge}${checkmark}`;\n\t\t\t} else {\n\t\t\t\tconst modelText = ` ${favoriteMarker}${item.id}`;\n\t\t\t\tconst providerBadge = theme.fg(\"muted\", `[${item.provider}]`);\n\t\t\t\tconst checkmark = isCurrent ? theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\t\tline = `${modelText} ${providerBadge}${checkmark}`;\n\t\t\t}\n\n\t\t\tthis.listContainer.addChild(new Text(line, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredModels.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredModels.length})`);\n\t\t\tthis.listContainer.addChild(new Text(scrollInfo, 0, 0));\n\t\t}\n\n\t\t// Show error message or \"no results\" if empty\n\t\tif (this.errorMessage) {\n\t\t\t// Show error in red\n\t\t\tconst errorLines = this.errorMessage.split(\"\\n\");\n\t\t\tfor (const line of errorLines) {\n\t\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"error\", line), 0, 0));\n\t\t\t}\n\t\t} else if (this.filteredModels.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredModels[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\tif (this.scopedModelItems.length > 0) {\n\t\t\t\tconst nextScope: ModelScope = this.scope === \"all\" ? \"narrowed\" : \"all\";\n\t\t\t\tthis.setScope(nextScope);\n\t\t\t\tif (this.scopeHintText) {\n\t\t\t\t\tthis.scopeHintText.setText(this.getScopeHintText());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t// Up arrow - wrap to bottom when at top\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Down arrow - wrap to top when at bottom\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tif (this.filteredModels.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tconst selectedModel = this.filteredModels[this.selectedIndex];\n\t\t\tif (selectedModel) {\n\t\t\t\tthis.handleSelect(selectedModel.model);\n\t\t\t}\n\t\t}\n\t\t// Toggle favorite for selected model\n\t\telse if (kb.matches(keyData, \"app.models.toggleFavorite\")) {\n\t\t\tthis.handleToggleFavorite();\n\t\t}\n\t\t// Escape or Ctrl+C\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterModels(this.searchInput.getValue());\n\t\t}\n\t}\n\n\tprivate handleSelect(model: Model<any>): void {\n\t\t// Save as new default\n\t\tthis.settingsManager.setDefaultModelAndProvider(model.provider, model.id);\n\t\tthis.onSelectCallback(model);\n\t}\n\n\tprivate handleToggleFavorite(): void {\n\t\tconst selectedModel = this.filteredModels[this.selectedIndex];\n\t\tif (!selectedModel) return;\n\n\t\tconst allModelIds = this.allModels.map((model) => model.fullId);\n\t\tthis.favoriteIds = toggleFavoriteModel(this.favoriteIds, allModelIds, selectedModel.fullId);\n\t\tthis.allModels = this.sortModels(this.allModels);\n\t\tthis.activeModels = this.scope === \"narrowed\" ? this.scopedModelItems : this.allModels;\n\t\tthis.filterModels(this.searchInput.getValue());\n\t\tconst selectedIndex = this.filteredModels.findIndex((item) => item.fullId === selectedModel.fullId);\n\t\tif (selectedIndex >= 0) {\n\t\t\tthis.selectedIndex = selectedIndex;\n\t\t\tthis.updateList();\n\t\t}\n\t\tconst nextFavoriteIds = this.favoriteIds === null ? null : [...this.favoriteIds];\n\t\tvoid this.onFavoriteChangeCallback?.(\n\t\t\tnextFavoriteIds,\n\t\t\tthis.allModels.map((item) => item.model),\n\t\t\tselectedModel.model,\n\t\t);\n\t\tthis.tui.requestRender();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
|