(
catalog: ConnectionCatalogSnapshot,
input: { readonly connectionSlug?: string; readonly model?: string } = {},
)
| 172 | } |
| 173 | |
| 174 | export function resolveRuntimeHostCliTarget( |
| 175 | catalog: ConnectionCatalogSnapshot, |
| 176 | input: { readonly connectionSlug?: string; readonly model?: string } = {}, |
| 177 | ): RuntimeHostCliTarget { |
| 178 | const defaultTarget = catalog.defaultTarget; |
| 179 | const connection = input.connectionSlug |
| 180 | ? catalog.connections.find((candidate) => candidate.slug === input.connectionSlug) |
| 181 | : catalog.connections.find( |
| 182 | (candidate) => candidate.connectionId === defaultTarget?.connectionId, |
| 183 | ); |
| 184 | if (!connection || !connection.enabled) { |
| 185 | throw new Error( |
| 186 | input.connectionSlug |
| 187 | ? `Runtime Host model connection is unavailable: ${input.connectionSlug}` |
| 188 | : `${NO_REAL_CONNECTION_CODE}:missing_default_connection: Runtime Host has no default model connection`, |
| 189 | ); |
| 190 | } |
| 191 | const model = |
| 192 | input.model ?? |
| 193 | (connection.connectionId === defaultTarget?.connectionId |
| 194 | ? defaultTarget.modelId |
| 195 | : connection.enabledModelIds[0]); |
| 196 | if (!model || !connection.enabledModelIds.includes(model)) { |
| 197 | throw new Error(`Runtime Host model is unavailable for ${connection.slug}: ${model ?? ''}`); |
| 198 | } |
| 199 | return { connection, model }; |
| 200 | } |
no outgoing calls
no test coverage detected