From bda748eb7eb284a3321267530de7cdf8546844f7 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 15 Jul 2025 00:26:39 -0700 Subject: [PATCH] refactor to loadAssistant function --- src/index.ts | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2806078ef..5448d1730 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { constructLlmApi, LLMConfig, } from "@continuedev/openai-adapters"; -import { Assistant, ContinueClient } from "@continuedev/sdk"; +import { Assistant } from "@continuedev/sdk"; import chalk from "chalk"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; import * as readlineSync from "readline-sync"; @@ -75,6 +75,15 @@ function getLlmApi( return [llmApi, model.model]; } +async function loadAssistant( + accessToken: string | undefined, + configPath: string +): Promise { + const continueSdk = await initializeContinueSDK(accessToken, configPath); + + return continueSdk.assistant; +} + async function chat() { const isAuthenticated = await ensureAuthenticated(true); @@ -114,28 +123,12 @@ async function chat() { // } // Initialize ContinueSDK and MCPService once - let assistant: ContinueClient["assistant"]; - let model: string; - let llmApi: BaseLlmApi; - let mcpService: MCPService; - - try { - const continueSdk = await initializeContinueSDK( - authConfig.accessToken, - args.configPath - ); - - assistant = continueSdk.assistant; - [llmApi, model] = getLlmApi(assistant, authConfig); - - mcpService = await MCPService.create(assistant.config); - } catch (error) { - console.error( - chalk.red(`Error loading assistant ${args.configPath}:`), - error - ); - throw error; - } + const assistant = await loadAssistant( + authConfig.accessToken, + args.configPath + ); + const [llmApi, model] = getLlmApi(assistant, authConfig); + const mcpService = await MCPService.create(assistant.config); // If not in headless mode, start the TUI chat (default) if (!args.isHeadless) {