failsafe-llm-model-resolver 1.0.0 → 1.0.1
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/index.js +17 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -104,14 +104,28 @@ async function fetchGeminiModels(apiKey) {
|
|
|
104
104
|
// Gemini uses query-string key and a different envelope
|
|
105
105
|
const url = `https://generativelanguage.googleapis.com/v1beta/models?key=${encodeURIComponent(apiKey)}&pageSize=1000`;
|
|
106
106
|
const json = await httpGet(url);
|
|
107
|
-
// Shape: { models: [ { name: "models/gemini-…", … } ] }
|
|
108
|
-
//
|
|
107
|
+
// Shape: { models: [ { name: "models/gemini-…", supportedGenerationMethods: [...], … } ] }
|
|
108
|
+
//
|
|
109
|
+
// BUGFIX (was throwing ReferenceError on every real call): the previous
|
|
110
|
+
// version called .filter() AFTER .map() had already reduced each model
|
|
111
|
+
// object down to a bare id string - by the time the filter ran, the only
|
|
112
|
+
// thing it had to inspect was `id` (a string), yet it tried to read
|
|
113
|
+
// `m.supportedGenerationMethods` on a variable `m` that was never in scope
|
|
114
|
+
// in that callback. This wasn't just a typo to rename; the whole ordering
|
|
115
|
+
// was backwards. The fix: filter on the full model object FIRST (while
|
|
116
|
+
// supportedGenerationMethods is still available), THEN map down to the id
|
|
117
|
+
// string. No IIFE, no scope trick needed - the property we need is simply
|
|
118
|
+
// read before it's thrown away.
|
|
109
119
|
const list = (json.models || [])
|
|
120
|
+
.filter(m => {
|
|
121
|
+
const methods = m.supportedGenerationMethods || m.supported_actions || [];
|
|
122
|
+
return methods.some(x => /generateContent/i.test(x));
|
|
123
|
+
})
|
|
110
124
|
.map(m => {
|
|
111
125
|
const name = m.name || '';
|
|
126
|
+
// The ID used in generateContent is the part after "models/"
|
|
112
127
|
return name.startsWith('models/') ? name.slice(7) : name;
|
|
113
128
|
})
|
|
114
|
-
.filter(id => id && /generateContent/i.test((m => (m.supportedGenerationMethods || m.supported_actions || []).join(','))(m) || 'generateContent'))
|
|
115
129
|
.filter(Boolean);
|
|
116
130
|
return list;
|
|
117
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "failsafe-llm-model-resolver",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Self-healing, failsafe resolver for the current frontier model across xAI, Anthropic, Gemini, and OpenRouter. Live /models fetch + preference rules + env fallbacks so a network blip never kills a batch job.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|