(initOptions: ServiceInitOptions = {})
| 60 | * Handles onboarding internally for TUI mode unless skipOnboarding is true |
| 61 | */ |
| 62 | export async function initializeServices(initOptions: ServiceInitOptions = {}) { |
| 63 | logger.debug("Initializing service registry"); |
| 64 | |
| 65 | const commandOptions = initOptions.options || {}; |
| 66 | |
| 67 | // Configure beta tools based on command options |
| 68 | if (commandOptions.betaUploadArtifactTool) { |
| 69 | setBetaUploadArtifactToolEnabled(true); |
| 70 | } |
| 71 | if (commandOptions.betaSubagentTool) { |
| 72 | setBetaSubagentToolEnabled(true); |
| 73 | } |
| 74 | // Handle onboarding for TUI mode (headless: false) unless explicitly skipped |
| 75 | if (!initOptions.headless && !initOptions.skipOnboarding) { |
| 76 | await initializeWithOnboarding(null, commandOptions.config); |
| 77 | } |
| 78 | |
| 79 | // Handle ANTHROPIC_API_KEY in headless mode when no config path is provided |
| 80 | if ( |
| 81 | initOptions.headless && |
| 82 | !commandOptions.config && |
| 83 | process.env.ANTHROPIC_API_KEY |
| 84 | ) { |
| 85 | const { createOrUpdateConfig } = await import("../onboarding.js"); |
| 86 | const { env } = await import("../env.js"); |
| 87 | const path = await import("path"); |
| 88 | |
| 89 | const CONFIG_PATH = path.join(env.continueHome, "config.yaml"); |
| 90 | await createOrUpdateConfig(process.env.ANTHROPIC_API_KEY); |
| 91 | |
| 92 | // Update options to use the created config |
| 93 | commandOptions.config = CONFIG_PATH; |
| 94 | } |
| 95 | |
| 96 | serviceContainer.register( |
| 97 | SERVICE_NAMES.AUTH, |
| 98 | async () => { |
| 99 | return await authService.initialize(); |
| 100 | }, |
| 101 | [], // No dependencies |
| 102 | ); |
| 103 | |
| 104 | serviceContainer.register( |
| 105 | SERVICE_NAMES.API_CLIENT, |
| 106 | async () => { |
| 107 | const authState = await serviceContainer.get<AuthServiceState>( |
| 108 | SERVICE_NAMES.AUTH, |
| 109 | ); |
| 110 | return apiClientService.initialize(authState.authConfig); |
| 111 | }, |
| 112 | [SERVICE_NAMES.AUTH], // Depends on auth |
| 113 | ); |
| 114 | |
| 115 | serviceContainer.register( |
| 116 | SERVICE_NAMES.AGENT_FILE, |
| 117 | async () => { |
| 118 | const [authState, apiClientState] = await Promise.all([ |
| 119 | serviceContainer.get<AuthServiceState>(SERVICE_NAMES.AUTH), |
no test coverage detected