@monotykamary/pi-opencode-provider 1.0.5 → 1.0.6
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/AGENTS.md +1 -0
- package/README.md +11 -3
- package/deprecated-models.json +1 -0
- package/index.ts +34 -1
- package/models.json +540 -389
- package/package.json +1 -1
- package/scripts/update-models.js +63 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monotykamary/pi-opencode-provider",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Opencode provider extension for pi - Access GPT, Claude, Gemini, GLM, MiniMax, Kimi and more through the opencode.ai API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
package/scripts/update-models.js
CHANGED
|
@@ -151,6 +151,67 @@ ${tableRows}`;
|
|
|
151
151
|
console.log(` Updated README.md with ${models.length} models`);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
// Grace period for delisted models: update-models.js moves models the API no
|
|
155
|
+
// longer lists into deprecated-models.json (stamped with deprecatedAt) instead
|
|
156
|
+
// of dropping them; the runtime appends them back so sessions and saved model
|
|
157
|
+
// settings keep working, and after 14 days they are evicted permanently.
|
|
158
|
+
const DEPRECATED_MODEL_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Reconcile deprecated-models.json against the freshly fetched model list.
|
|
162
|
+
* - in old models.json but not the API: moved into the deprecated file
|
|
163
|
+
* (deprecatedAt = now; preserved on repeat runs so the grace clock is not reset)
|
|
164
|
+
* - back in the API: resurrected (dropped from the deprecated file)
|
|
165
|
+
* - deprecatedAt older than 14 days: evicted permanently
|
|
166
|
+
* Must run BEFORE the new models.json is written; it reads the old file itself.
|
|
167
|
+
*/
|
|
168
|
+
function updateDeprecatedModels(modelsJsonPath, newModels) {
|
|
169
|
+
const deprecatedPath = path.join(path.dirname(modelsJsonPath), 'deprecated-models.json');
|
|
170
|
+
|
|
171
|
+
let oldModels = [];
|
|
172
|
+
try {
|
|
173
|
+
const parsed = JSON.parse(fs.readFileSync(modelsJsonPath, 'utf8'));
|
|
174
|
+
if (Array.isArray(parsed)) oldModels = parsed;
|
|
175
|
+
} catch { /* first run: no previous models.json */ }
|
|
176
|
+
|
|
177
|
+
let deprecated = {};
|
|
178
|
+
try {
|
|
179
|
+
const parsed = JSON.parse(fs.readFileSync(deprecatedPath, 'utf8'));
|
|
180
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) deprecated = parsed;
|
|
181
|
+
} catch { /* no graveyard yet */ }
|
|
182
|
+
|
|
183
|
+
const currentIds = new Set(newModels.map(m => m.id));
|
|
184
|
+
const now = new Date().toISOString();
|
|
185
|
+
const added = [];
|
|
186
|
+
const resurrected = [];
|
|
187
|
+
const evicted = [];
|
|
188
|
+
|
|
189
|
+
for (const old of oldModels) {
|
|
190
|
+
if (old && old.id && !currentIds.has(old.id) && !deprecated[old.id]) {
|
|
191
|
+
deprecated[old.id] = { ...old, deprecatedAt: now };
|
|
192
|
+
added.push(old.id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (const [id, entry] of Object.entries(deprecated)) {
|
|
197
|
+
if (currentIds.has(id)) {
|
|
198
|
+
delete deprecated[id];
|
|
199
|
+
resurrected.push(id);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const removedAt = Date.parse(entry && entry.deprecatedAt ? entry.deprecatedAt : '');
|
|
203
|
+
if (Number.isNaN(removedAt) || Date.now() - removedAt > DEPRECATED_MODEL_TTL_MS) {
|
|
204
|
+
delete deprecated[id];
|
|
205
|
+
evicted.push(id);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (added.length > 0 || resurrected.length > 0 || evicted.length > 0) {
|
|
210
|
+
fs.writeFileSync(deprecatedPath, JSON.stringify(deprecated, null, 2) + '\n');
|
|
211
|
+
console.log('Updated deprecated-models.json ' + JSON.stringify({ added, resurrected, evicted }));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
154
215
|
async function main() {
|
|
155
216
|
console.log('Fetching models from API...');
|
|
156
217
|
|
|
@@ -174,6 +235,8 @@ async function main() {
|
|
|
174
235
|
// Convert to Pi-native format and save to models.json
|
|
175
236
|
const models = apiModels.map(convertModel);
|
|
176
237
|
const modelsPath = path.join(process.cwd(), 'models.json');
|
|
238
|
+
// Move delisted models to deprecated-models.json BEFORE models.json is overwritten
|
|
239
|
+
updateDeprecatedModels(modelsPath, models);
|
|
177
240
|
fs.writeFileSync(modelsPath, JSON.stringify(models, null, 2) + '\n');
|
|
178
241
|
console.log(` Saved ${models.length} models to models.json`);
|
|
179
242
|
|