@aliou/pi-neuralwatt 0.7.3 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-neuralwatt",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -46,6 +46,11 @@ function registerNeuralwattProvider(
46
46
  const { includeLegacyModelIds, includeHiddenModels } =
47
47
  configLoader.getConfig();
48
48
 
49
+ const publicModels = getNeuralwattModels({ includeLegacyModelIds });
50
+ const resolvedHiddenModels = includeHiddenModels
51
+ ? dedupeHiddenModels(hiddenModels, publicModels)
52
+ : [];
53
+
49
54
  const config: Parameters<ExtensionAPI["registerProvider"]>[1] = {
50
55
  baseUrl: "https://api.neuralwatt.com/v1",
51
56
  apiKey: "$NEURALWATT_API_KEY",
@@ -55,10 +60,7 @@ function registerNeuralwattProvider(
55
60
  Referer: "https://pi.dev",
56
61
  "X-Title": "npm:@aliou/pi-neuralwatt",
57
62
  },
58
- models: [
59
- ...getNeuralwattModels({ includeLegacyModelIds }),
60
- ...(includeHiddenModels ? hiddenModels : []),
61
- ],
63
+ models: [...publicModels, ...resolvedHiddenModels],
62
64
  };
63
65
 
64
66
  const provider = getApiProvider("openai-completions");
@@ -73,6 +75,23 @@ function registerNeuralwattProvider(
73
75
  pi.registerProvider("neuralwatt", config);
74
76
  }
75
77
 
78
+ /**
79
+ * Drop any hidden model whose ID collides with a public or legacy model.
80
+ *
81
+ * Models can graduate from hidden (authenticated /v1/models only) to public
82
+ * (unauthenticated list). When that happens, a stale on-disk cache may still
83
+ * list the now-public ID, which would register it twice and make Pi treat the
84
+ * scoped model as ambiguous ("No models match pattern"). Dedupe against the
85
+ * public list so a stale cache can never shadow a public model.
86
+ */
87
+ function dedupeHiddenModels(
88
+ hiddenModels: ProviderModelConfig[],
89
+ publicModels: ProviderModelConfig[],
90
+ ): ProviderModelConfig[] {
91
+ const publicIds = new Set(publicModels.map((m) => m.id));
92
+ return hiddenModels.filter((m) => !publicIds.has(m.id));
93
+ }
94
+
76
95
  export default async function (pi: ExtensionAPI) {
77
96
  await configLoader.load();
78
97
 
@@ -254,14 +273,14 @@ export default async function (pi: ExtensionAPI) {
254
273
  ctx.modelRegistry.authStorage,
255
274
  hiddenModelsAbort.signal,
256
275
  );
257
- // Persist for the next startup so scoped models resolve without warnings
258
- // on Pi's subsequent launches.
259
- if (fetched.length > 0) {
260
- hiddenModels = fetched;
261
- await writeHiddenModelsCache(hiddenModels);
262
- if (!hiddenModelsAbort.signal.aborted) {
263
- registerNeuralwattProvider(pi, handleSseQuota, hiddenModels);
264
- }
276
+ // Persist for the next startup so scoped models resolve without
277
+ // warnings on Pi's subsequent launches. Always write the cache (even
278
+ // when empty) and re-register, so graduated or removed hidden models
279
+ // are purged from both the cache and the provider's model list.
280
+ hiddenModels = fetched;
281
+ await writeHiddenModelsCache(hiddenModels);
282
+ if (!hiddenModelsAbort.signal.aborted) {
283
+ registerNeuralwattProvider(pi, handleSseQuota, hiddenModels);
265
284
  }
266
285
  }
267
286