* Internal implementation
(
options: ContinueClientOptions,
)
| 92 | * Internal implementation |
| 93 | */ |
| 94 | static async from( |
| 95 | options: ContinueClientOptions, |
| 96 | ): Promise<ContinueClientBase | ContinueClient> { |
| 97 | const baseURL = options.baseURL || "https://api.continue.dev/"; |
| 98 | |
| 99 | const continueClient = new DefaultApi( |
| 100 | new Configuration({ |
| 101 | basePath: baseURL, |
| 102 | accessToken: options.apiKey |
| 103 | ? async () => options.apiKey as string |
| 104 | : undefined, |
| 105 | }), |
| 106 | ); |
| 107 | |
| 108 | if (!options.assistant) { |
| 109 | return { api: continueClient }; |
| 110 | } |
| 111 | |
| 112 | const { ownerSlug, packageSlug } = decodePackageSlug(options.assistant); |
| 113 | if (!ownerSlug || !packageSlug) { |
| 114 | throw new Error( |
| 115 | `Invalid assistant identifier: ${options.assistant}. Expected format: owner-slug/package-slug`, |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | const assistants = await continueClient.listAssistants({ |
| 120 | organizationId: options.organizationId, |
| 121 | alwaysUseProxy: "true", |
| 122 | }); |
| 123 | |
| 124 | const assistantRes = assistants.find( |
| 125 | (a) => a.ownerSlug === ownerSlug && a.packageSlug === packageSlug, |
| 126 | ); |
| 127 | |
| 128 | if (!assistantRes) { |
| 129 | throw new Error(`Assistant ${options.assistant} not found`); |
| 130 | } |
| 131 | |
| 132 | const assistant = new Assistant(assistantRes.configResult.config); |
| 133 | |
| 134 | const client = createOpenAIClient({ |
| 135 | models: assistant.config.models, |
| 136 | organizationId: options.organizationId || null, |
| 137 | apiKey: options.apiKey, |
| 138 | baseURL: baseURL, |
| 139 | }); |
| 140 | |
| 141 | return { |
| 142 | api: continueClient, |
| 143 | client, |
| 144 | assistant, |
| 145 | }; |
| 146 | } |
| 147 | } |