@tekmidian/pai 0.39.0 → 0.39.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.
@@ -167,7 +167,8 @@ function defaultWorkersConfig() {
167
167
  pane: { ...DEFAULT_PANE },
168
168
  logDir: DEFAULT_LOG_DIR,
169
169
  routing: { ...DEFAULT_ROUTING2, order: [] },
170
- tree: { ...DEFAULT_TREE }
170
+ tree: { ...DEFAULT_TREE },
171
+ fallback: null
171
172
  };
172
173
  }
173
174
  var WorkersConfigError = class extends Error {
@@ -413,6 +414,39 @@ function parseWorkersConfig(raw) {
413
414
  const active = w.active === void 0 || w.active === null ? null : str(w.active);
414
415
  if (active !== null && active !== "auto" && !(active in providers)) {
415
416
  }
417
+ let fallback = null;
418
+ if (w.fallback !== void 0 && w.fallback !== null) {
419
+ if (typeof w.fallback !== "object" || Array.isArray(w.fallback)) {
420
+ bad(".fallback", "must be an object (written by `pai worker fallback on`)");
421
+ }
422
+ const f = w.fallback;
423
+ const provider = str(f.provider);
424
+ if (!provider) bad(".fallback.provider", "is required");
425
+ const savedRaw = f.saved;
426
+ if (typeof savedRaw !== "object" || savedRaw === null || Array.isArray(savedRaw)) {
427
+ bad(".fallback.saved", "must be an object");
428
+ }
429
+ const s = savedRaw;
430
+ if (typeof s.env !== "object" || s.env === null || Array.isArray(s.env)) {
431
+ bad(".fallback.saved.env", "must be an object of env key \u2192 previous value or null");
432
+ }
433
+ const env = {};
434
+ for (const [k, v] of Object.entries(s.env)) {
435
+ env[k] = v === null || typeof v === "string" ? v : null;
436
+ }
437
+ if (s.model !== null && s.model !== void 0 && typeof s.model !== "string") {
438
+ bad(".fallback.saved.model", "must be a string or null");
439
+ }
440
+ fallback = {
441
+ provider,
442
+ saved: {
443
+ env,
444
+ model: typeof s.model === "string" ? s.model : null,
445
+ envExisted: s.envExisted === true
446
+ },
447
+ on: str(f.on) || (/* @__PURE__ */ new Date(0)).toISOString()
448
+ };
449
+ }
416
450
  return {
417
451
  enabled: w.enabled === void 0 ? d.enabled : w.enabled === true,
418
452
  active,
@@ -422,11 +456,12 @@ function parseWorkersConfig(raw) {
422
456
  pane,
423
457
  logDir: str(w.logDir) || d.logDir,
424
458
  routing,
425
- tree
459
+ tree,
460
+ fallback
426
461
  };
427
462
  }
428
- function readWorkersSection() {
429
- const raw = readJsonStrict(CONFIG_FILE, "~/.config/pai/config.json");
463
+ function readWorkersSection(path = CONFIG_FILE) {
464
+ const raw = readJsonStrict(path, "~/.config/pai/config.json");
430
465
  return { raw, workers: parseWorkersConfig(raw.workers) };
431
466
  }
432
467
  function expandHome(p) {