(
init: ConfigServiceInit,
)
| 251 | } |
| 252 | |
| 253 | private async loadConfig( |
| 254 | init: ConfigServiceInit, |
| 255 | ): Promise<ConfigServiceState> { |
| 256 | const { |
| 257 | authConfig, |
| 258 | configPath, |
| 259 | apiClient, |
| 260 | injectedConfigOptions, |
| 261 | agentFileState, |
| 262 | } = init; |
| 263 | const { injected, additional } = this.getAdditionalBlocksFromOptions( |
| 264 | injectedConfigOptions, |
| 265 | agentFileState, |
| 266 | ); |
| 267 | |
| 268 | const result = await loadConfiguration( |
| 269 | authConfig, |
| 270 | configPath, |
| 271 | apiClient, |
| 272 | injected, |
| 273 | init.isHeadless, |
| 274 | ); |
| 275 | |
| 276 | const loadedConfig = result.config; |
| 277 | const merged = mergeUnrolledAssistants(loadedConfig, additional); |
| 278 | |
| 279 | const markdownRules = loadMarkdownRulesWithMetadata(); |
| 280 | if (markdownRules.length > 0) { |
| 281 | const existingRuleContents = new Set( |
| 282 | (merged.rules ?? []).map((r) => (typeof r === "string" ? r : r?.rule)), |
| 283 | ); |
| 284 | const newRules = markdownRules.filter( |
| 285 | (r) => !existingRuleContents.has(r.rule), |
| 286 | ); |
| 287 | merged.rules = [...(merged.rules ?? []), ...newRules]; |
| 288 | } |
| 289 | |
| 290 | const withModel = await this.addDefaultChatModelIfNone( |
| 291 | merged, |
| 292 | apiClient, |
| 293 | authConfig, |
| 294 | init.isHeadless, |
| 295 | ); |
| 296 | |
| 297 | // Config URI persistence is now handled by the streamlined loader |
| 298 | logger.debug("ConfigService initialized successfully"); |
| 299 | |
| 300 | const state = { |
| 301 | config: withModel, |
| 302 | configPath, |
| 303 | }; |
| 304 | this.setState(state); |
| 305 | |
| 306 | return state; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Initialize the config service |
no test coverage detected