8900 commited on
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +32 -5
setup-hf-config.mjs
CHANGED
|
@@ -305,26 +305,53 @@ function applyEnvPatches(config, tgToken) {
|
|
| 305 |
}
|
| 306 |
|
| 307 |
// Load base config
|
| 308 |
-
//
|
| 309 |
-
//
|
| 310 |
-
//
|
|
|
|
| 311 |
var config = null;
|
| 312 |
var mode = "";
|
|
|
|
| 313 |
|
|
|
|
| 314 |
if (fs.existsSync(TEMPLATE)) {
|
| 315 |
try {
|
| 316 |
-
|
| 317 |
-
|
| 318 |
} catch(e) {
|
| 319 |
log("Template unreadable (" + e.message + ")");
|
| 320 |
}
|
| 321 |
}
|
| 322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
if (!config) {
|
| 324 |
config = { gateway: {}, agents: { defaults: {} }, env: { vars: {} } };
|
| 325 |
mode = "fresh (no template found)";
|
| 326 |
}
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
// Apply env patches
|
| 329 |
config = applyEnvPatches(config, tgToken);
|
| 330 |
|
|
|
|
| 305 |
}
|
| 306 |
|
| 307 |
// Load base config
|
| 308 |
+
// Strategy: bucket config is the base (preserves Telegram bindings,
|
| 309 |
+
// devices, channels, user settings across restarts), BUT we always
|
| 310 |
+
// overwrite config.models from the Space repo template so provider
|
| 311 |
+
// definitions (urls, model lists, api adapters) are never stale.
|
| 312 |
var config = null;
|
| 313 |
var mode = "";
|
| 314 |
+
var templateModels = null;
|
| 315 |
|
| 316 |
+
// Always load template models block first
|
| 317 |
if (fs.existsSync(TEMPLATE)) {
|
| 318 |
try {
|
| 319 |
+
var tmpl = JSON.parse(fs.readFileSync(TEMPLATE, "utf-8").trim());
|
| 320 |
+
if (tmpl.models) templateModels = tmpl.models;
|
| 321 |
} catch(e) {
|
| 322 |
log("Template unreadable (" + e.message + ")");
|
| 323 |
}
|
| 324 |
}
|
| 325 |
|
| 326 |
+
// Try bucket config as base (preserves channels, devices, telegram)
|
| 327 |
+
if (fs.existsSync(CONFIG_PATH)) {
|
| 328 |
+
try {
|
| 329 |
+
config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8").trim());
|
| 330 |
+
mode = "bucket (user settings preserved)";
|
| 331 |
+
} catch(e) {
|
| 332 |
+
log("Bucket config unreadable (" + e.message + ") - using template");
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
// Fall back to template if no bucket config
|
| 337 |
+
if (!config && fs.existsSync(TEMPLATE)) {
|
| 338 |
+
try {
|
| 339 |
+
config = JSON.parse(fs.readFileSync(TEMPLATE, "utf-8").trim());
|
| 340 |
+
mode = "template (first boot)";
|
| 341 |
+
} catch(e) { /* handled above */ }
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
if (!config) {
|
| 345 |
config = { gateway: {}, agents: { defaults: {} }, env: { vars: {} } };
|
| 346 |
mode = "fresh (no template found)";
|
| 347 |
}
|
| 348 |
|
| 349 |
+
// Always overwrite models from template - never stale provider definitions
|
| 350 |
+
if (templateModels) {
|
| 351 |
+
config.models = templateModels;
|
| 352 |
+
log("Models block refreshed from template");
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
// Apply env patches
|
| 356 |
config = applyEnvPatches(config, tgToken);
|
| 357 |
|