* Loads first available user assistant with fallback to default agent
( organizationId: string | null, apiClient: DefaultApiInterface, accessToken: string | null, injectBlocks: PackageIdentifier[], )
| 255 | * Loads first available user assistant with fallback to default agent |
| 256 | */ |
| 257 | async function loadUserAssistantWithFallback( |
| 258 | organizationId: string | null, |
| 259 | apiClient: DefaultApiInterface, |
| 260 | accessToken: string | null, |
| 261 | injectBlocks: PackageIdentifier[], |
| 262 | ): Promise<AssistantUnrolled> { |
| 263 | const assistants = await apiClient.listAssistants({ |
| 264 | alwaysUseProxy: "false", |
| 265 | organizationId: organizationId ?? undefined, |
| 266 | }); |
| 267 | |
| 268 | if (assistants.length > 0) { |
| 269 | const result = assistants[0].configResult; |
| 270 | if (!result.config) { |
| 271 | throw new Error(result.errors?.join("\n") ?? "Failed to load assistant."); |
| 272 | } |
| 273 | |
| 274 | const errors = result.errors; |
| 275 | if (errors?.some((e: any) => e.fatal)) { |
| 276 | throw new Error( |
| 277 | errors.map((e: any) => e.message).join("\n") ?? |
| 278 | "Failed to load assistant.", |
| 279 | ); |
| 280 | } |
| 281 | let apiConfig = result.config as AssistantUnrolled; |
| 282 | if (injectBlocks.length > 0) { |
| 283 | const injectedConfig = await unrollPackageIdentifiersAsConfigYaml( |
| 284 | injectBlocks, |
| 285 | accessToken, |
| 286 | organizationId, |
| 287 | apiClient, |
| 288 | ); |
| 289 | apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig); |
| 290 | } |
| 291 | |
| 292 | return apiConfig; |
| 293 | } |
| 294 | |
| 295 | // No user assistants, fall back to default agent |
| 296 | return await loadDefaultConfig( |
| 297 | organizationId, |
| 298 | apiClient, |
| 299 | accessToken, |
| 300 | injectBlocks, |
| 301 | ); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Loads default config.yaml from ~/.continue/config.yaml |
no test coverage detected