@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.
- package/lib/client.js +131 -30
- package/lib/client.js.map +1 -1
- package/lib/index.js +98 -50
- package/lib/types/index.d.ts +7 -6
- package/lib/types/server/service.d.ts +45 -5
- package/lib/types/shared/config.d.ts +2 -0
- package/package.json +25 -25
- package/src/client/api.ts +5 -0
- package/src/client/icons.tsx +97 -0
- package/src/client/index.tsx +15 -20
- package/src/client/model-seat.tsx +17 -15
- package/src/client/settings-section.tsx +17 -38
- package/src/index.ts +11 -8
- package/src/server/catalog.ts +14 -3
- package/src/server/service.ts +87 -60
- package/src/shared/config.ts +32 -2
package/src/shared/config.ts
CHANGED
|
@@ -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
|
-
|
|
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 =
|
|
502
|
+
const root = source as {
|
|
473
503
|
models?: unknown
|
|
474
504
|
showQuickSwitch?: unknown
|
|
475
505
|
ignoreModelIdPrefix?: unknown
|