* Loads an assistant by slug from the Continue platform
( slug: string, accessToken: string | null, organizationId: string | null, apiClient: DefaultApiInterface, injectBlocks: PackageIdentifier[], )
| 450 | * Loads an assistant by slug from the Continue platform |
| 451 | */ |
| 452 | async function loadAssistantSlug( |
| 453 | slug: string, |
| 454 | accessToken: string | null, |
| 455 | organizationId: string | null, |
| 456 | apiClient: DefaultApiInterface, |
| 457 | injectBlocks: PackageIdentifier[], |
| 458 | ): Promise<AssistantUnrolled> { |
| 459 | const [ownerSlug, packageSlug] = slug.split("/"); |
| 460 | if (!ownerSlug || !packageSlug) { |
| 461 | throw new Error( |
| 462 | `Invalid assistant slug format. Expected "owner/package", got: ${slug}`, |
| 463 | ); |
| 464 | } |
| 465 | // Unroll locally if not logged in |
| 466 | if (!(apiClient as any).configuration.accessToken) { |
| 467 | return await unrollAssistantWithConfig( |
| 468 | { |
| 469 | uriType: "slug", |
| 470 | fullSlug: { ownerSlug, packageSlug, versionSlug: "latest" }, |
| 471 | }, |
| 472 | accessToken ?? null, |
| 473 | organizationId, |
| 474 | apiClient, |
| 475 | injectBlocks, |
| 476 | ); |
| 477 | } |
| 478 | |
| 479 | const resp = await apiClient.getAssistant({ |
| 480 | ownerSlug, |
| 481 | packageSlug, |
| 482 | alwaysUseProxy: "false", |
| 483 | organizationId: organizationId ?? undefined, |
| 484 | }); |
| 485 | |
| 486 | const result = resp.configResult; |
| 487 | const errors = result.errors; |
| 488 | if (errors?.some((e: any) => e.fatal)) { |
| 489 | throw new Error( |
| 490 | errors.map((e: any) => e.message).join("\n") ?? |
| 491 | "Failed to load assistant.", |
| 492 | ); |
| 493 | } |
| 494 | let apiConfig = result.config as AssistantUnrolled; |
| 495 | if (injectBlocks.length > 0) { |
| 496 | const injectedConfig = await unrollPackageIdentifiersAsConfigYaml( |
| 497 | injectBlocks, |
| 498 | accessToken, |
| 499 | organizationId, |
| 500 | apiClient, |
| 501 | ); |
| 502 | apiConfig = mergeUnrolledAssistants(apiConfig, injectedConfig); |
| 503 | } |
| 504 | |
| 505 | return apiConfig; |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Determines if a config path is a file path vs assistant slug |
no test coverage detected