| 1 | import { |
| 2 | AssistantUnrolled, |
| 3 | ConfigResult, |
| 4 | PackageIdentifier, |
| 5 | RegistryClient, |
| 6 | unrollAssistantFromContent, |
| 7 | } from "@continuedev/config-yaml"; |
| 8 | import { IDE } from "../.."; |
| 9 | import { ControlPlaneClient } from "../../control-plane/client"; |
| 10 | import { LocalPlatformClient } from "./LocalPlatformClient"; |
| 11 | |
| 12 | // This is a certain approach to unrolling local YAML where it |
| 13 | // 1. creates an assistant out of all local blocks |
| 14 | // 2. unrolls it like a local assistant |
| 15 | export async function unrollLocalYamlBlocks( |
| 16 | packageIdentifiers: PackageIdentifier[], |
| 17 | ide: IDE, |
| 18 | registryClient: RegistryClient, |
| 19 | orgScopeId: string | null, |
| 20 | controlPlaneClient: ControlPlaneClient, |
| 21 | ): Promise<ConfigResult<AssistantUnrolled>> { |
| 22 | try { |
| 23 | const unrollResult = await unrollAssistantFromContent( |
| 24 | { |
| 25 | uriType: "file", |
| 26 | fileUri: "", |
| 27 | }, |
| 28 | "name: FILLER\nschema: v1\nversion: 0.0.1", |
| 29 | registryClient, |
| 30 | { |
| 31 | currentUserSlug: "", |
| 32 | onPremProxyUrl: null, |
| 33 | orgScopeId, |
| 34 | platformClient: new LocalPlatformClient( |
| 35 | orgScopeId, |
| 36 | controlPlaneClient, |
| 37 | ide, |
| 38 | ), |
| 39 | renderSecrets: true, |
| 40 | injectBlocks: packageIdentifiers, |
| 41 | }, |
| 42 | ); |
| 43 | const config = |
| 44 | "config" in unrollResult ? unrollResult.config : unrollResult; |
| 45 | const errors = "errors" in unrollResult ? unrollResult.errors : []; |
| 46 | return { |
| 47 | config, |
| 48 | errors, |
| 49 | configLoadInterrupted: false, |
| 50 | }; |
| 51 | } catch (error) { |
| 52 | let message = "An unknown error occurred while loading local YAML blocks"; |
| 53 | if (error instanceof Error) { |
| 54 | message += ": " + error.message; |
| 55 | } |
| 56 | return { |
| 57 | config: undefined, |
| 58 | errors: [{ message, fatal: false }], |
| 59 | configLoadInterrupted: false, |
| 60 | }; |
| 61 | } |
| 62 | } |