| 113 | } |
| 114 | |
| 115 | function resolveConfigValue<T>( |
| 116 | cfg: Record<string, unknown> | undefined, |
| 117 | key: string, |
| 118 | modelKey: string | undefined, |
| 119 | defaultValue: T, |
| 120 | ): T { |
| 121 | if (!cfg) return defaultValue; |
| 122 | const val = cfg[key]; |
| 123 | if (typeof val === typeof defaultValue) return val as T; |
| 124 | if (val && typeof val === "object") { |
| 125 | const obj = val as Record<string, T>; |
| 126 | if (modelKey && obj[modelKey] !== undefined) return obj[modelKey]; |
| 127 | if (modelKey) { |
| 128 | const bare = modelKey.split("/").slice(1).join("/"); |
| 129 | if (bare && obj[bare] !== undefined) return obj[bare]; |
| 130 | } |
| 131 | if (obj.default !== undefined) return obj.default; |
| 132 | } |
| 133 | return defaultValue; |
| 134 | } |
| 135 | |
| 136 | // Exported for test access. Production code reaches this via the |
| 137 | // "sidebar-snapshot" RPC handler registered below. |