pi-model-sort 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/model-sort.ts +24 -2
- package/package.json +1 -1
package/model-sort.ts
CHANGED
|
@@ -149,10 +149,29 @@ function patchFilterModels(getLastUsed: () => Record<string, number>): void {
|
|
|
149
149
|
origFilterModels = proto.filterModels as (query: string) => void;
|
|
150
150
|
|
|
151
151
|
proto.filterModels = function (this: Record<string, unknown>, query: string) {
|
|
152
|
-
|
|
152
|
+
// Suppress the original's updateList() call — we'll call it once after
|
|
153
|
+
// re-sorting to avoid a double-render.
|
|
154
|
+
const origUpdateList = this.updateList as () => void;
|
|
155
|
+
this.updateList = (() => {}) as unknown as () => void;
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
origFilterModels!.call(this, query);
|
|
159
|
+
} finally {
|
|
160
|
+
this.updateList = origUpdateList as unknown as () => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Empty query: nothing to re-sort (activeModels is already sorted by our
|
|
164
|
+
// sortModels/loadModels patches), just render the original result.
|
|
165
|
+
if (!query) {
|
|
166
|
+
origUpdateList.call(this);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
153
169
|
|
|
154
170
|
const filtered = this.filteredModels as Array<{ provider: string; id: string; model: unknown }> | undefined;
|
|
155
|
-
if (!filtered || filtered.length <= 1
|
|
171
|
+
if (!filtered || filtered.length <= 1) {
|
|
172
|
+
origUpdateList.call(this);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
156
175
|
|
|
157
176
|
const lastUsed = getLastUsed();
|
|
158
177
|
this.filteredModels = sortByLastUsed(filtered, lastUsed, buildCurrentModelKey(this));
|
|
@@ -168,6 +187,9 @@ function patchFilterModels(getLastUsed: () => Record<string, number>): void {
|
|
|
168
187
|
this.selectedIndex = newIndex;
|
|
169
188
|
}
|
|
170
189
|
}
|
|
190
|
+
|
|
191
|
+
// Render once with the final sorted list.
|
|
192
|
+
origUpdateList.call(this);
|
|
171
193
|
};
|
|
172
194
|
}
|
|
173
195
|
|