pi-model-sort 0.1.3 → 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.
Files changed (2) hide show
  1. package/model-sort.ts +23 -5
  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
- origFilterModels!.call(this, query);
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 || !query) return;
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));
@@ -169,9 +188,8 @@ function patchFilterModels(getLastUsed: () => Record<string, number>): void {
169
188
  }
170
189
  }
171
190
 
172
- // Re-render the original filterModels already called updateList() before
173
- // we re-sorted, so the UI is stale until the next input event.
174
- (this.updateList as () => void)();
191
+ // Render once with the final sorted list.
192
+ origUpdateList.call(this);
175
193
  };
176
194
  }
177
195
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-model-sort",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Sort models in pi's /model selector by last usage — most recently used models appear first",
5
5
  "type": "module",
6
6
  "author": "Tom X Nguyen",