@fonlan/dsh-model-router 0.3.6 → 0.3.8

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.
@@ -463,13 +463,43 @@ export function setOrder(
463
463
  return { models: next, changed: true }
464
464
  }
465
465
 
466
+ /**
467
+ * Dereference one config field as the loader may hand it over.
468
+ *
469
+ * dsh >= 0.1.7 owns plugin configuration as entry config, and every field the
470
+ * `Config` schema marks `.volatile()` arrives as a stable REFERENCE
471
+ * (`{ get() }`, schemastery's `Volatile<T>`) instead of a plain value — a
472
+ * reference serializes to `{}`. Reading such a field raw silently yields
473
+ * `models: {}`, `modelSort: 'custom'`, an empty `modelOrder` and no
474
+ * `recentlyUsed`: the stored document is dropped, and the next persist
475
+ * overwrites it with catalog defaults. Plain values pass through unchanged, so
476
+ * this is safe for the write paths and for callers that already hold a
477
+ * resolved document.
478
+ */
479
+ function derefField<T>(value: T): T {
480
+ if (value !== null && typeof value === 'object' && typeof (value as { get?: unknown }).get === 'function') {
481
+ return (value as unknown as { get(): T }).get()
482
+ }
483
+ return value
484
+ }
485
+
486
+ /** Dereference every own field of a config object (per-field volatile refs). */
487
+ export function derefConfig(value: unknown): unknown {
488
+ const root = derefField(value)
489
+ if (root === null || typeof root !== 'object' || Array.isArray(root)) return root
490
+ const out: Record<string, unknown> = {}
491
+ for (const [key, field] of Object.entries(root as Record<string, unknown>)) out[key] = derefField(field)
492
+ return out
493
+ }
494
+
466
495
  /** Shape-validate an unknown value as a RouterConfigShape (lenient). */
467
496
  export function normalizeConfig(value: unknown): RouterConfigShape {
468
497
  const models: Record<string, RouterModelConfig> = {}
469
- if (typeof value !== 'object' || value === null) {
498
+ const source = derefConfig(value)
499
+ if (typeof source !== 'object' || source === null) {
470
500
  return { models, showQuickSwitch: true, ignoreModelIdPrefix: true, modelSort: 'custom', modelOrder: [], recentlyUsed: {} }
471
501
  }
472
- const root = value as {
502
+ const root = source as {
473
503
  models?: unknown
474
504
  showQuickSwitch?: unknown
475
505
  ignoreModelIdPrefix?: unknown