Merge pull request #34 from continuedev/load-config-yaml
Load-config-yaml
This commit is contained in:
commit
606a8d5b48
8 changed files with 372 additions and 77 deletions
110
src/CLIPlatformClient.ts
Normal file
110
src/CLIPlatformClient.ts
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
import {
|
||||
FQSN,
|
||||
PlatformClient,
|
||||
SecretResult,
|
||||
SecretType,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { DefaultApiInterface } from "@continuedev/sdk/dist/api";
|
||||
import * as dotenv from "dotenv";
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
|
||||
export class CLIPlatformClient implements PlatformClient {
|
||||
constructor(
|
||||
private orgScopeId: string | null,
|
||||
private readonly apiClient: DefaultApiInterface
|
||||
) {}
|
||||
|
||||
private findSecretInEnvFile(
|
||||
filePath: string,
|
||||
secretName: string
|
||||
): string | undefined {
|
||||
try {
|
||||
if (!fs.existsSync(filePath)) return undefined;
|
||||
|
||||
const envContent = fs.readFileSync(filePath, "utf8");
|
||||
const env = dotenv.parse(envContent);
|
||||
return env[secretName];
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Error reading .env file at ${filePath}: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private findSecretInLocalEnvFiles(fqsn: FQSN): SecretResult | undefined {
|
||||
// Check in priority order: ~/.continue/.env, <workspace>/.continue/.env, <workspace>/.env
|
||||
const workspaceDir = process.cwd();
|
||||
const envPaths = [
|
||||
path.join(os.homedir(), ".continue", ".env"),
|
||||
path.join(workspaceDir, ".continue", ".env"),
|
||||
path.join(workspaceDir, ".env"),
|
||||
];
|
||||
|
||||
for (const envPath of envPaths) {
|
||||
const secretValue = this.findSecretInEnvFile(envPath, fqsn.secretName);
|
||||
if (secretValue) {
|
||||
return {
|
||||
found: true,
|
||||
fqsn,
|
||||
value: secretValue,
|
||||
secretLocation: {
|
||||
secretName: fqsn.secretName,
|
||||
secretType: SecretType.LocalEnv,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async resolveFQSNs(fqsns: FQSN[]): Promise<(SecretResult | undefined)[]> {
|
||||
if (fqsns.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results: (SecretResult | undefined)[] = new Array(fqsns.length).fill(
|
||||
undefined
|
||||
);
|
||||
|
||||
// Try to resolve secrets through the API client first
|
||||
try {
|
||||
const apiResults: any = await this.apiClient.syncSecrets({
|
||||
syncSecretsRequest: {
|
||||
fqsns,
|
||||
orgScopeId: this.orgScopeId,
|
||||
},
|
||||
});
|
||||
|
||||
// Merge API results into our results array
|
||||
for (let i = 0; i < apiResults.length; i++) {
|
||||
if (apiResults[i]?.found) {
|
||||
results[i] = apiResults[i];
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Error resolving FQSNs through API: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
// For any secret that wasn't found via API, look in local .env files
|
||||
for (let i = 0; i < fqsns.length; i++) {
|
||||
if (!results[i]?.found) {
|
||||
const secretFromEnv = this.findSecretInLocalEnvFiles(fqsns[i]);
|
||||
if (secretFromEnv?.found) {
|
||||
results[i] = secretFromEnv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,13 +15,57 @@ import { env } from "../env.js";
|
|||
// Config file path
|
||||
const AUTH_CONFIG_PATH = path.join(os.homedir(), ".continue", "auth.json");
|
||||
|
||||
export interface AuthConfig {
|
||||
userId?: string;
|
||||
userEmail?: string;
|
||||
accessToken?: string;
|
||||
refreshToken?: string;
|
||||
expiresAt?: number;
|
||||
organizationId?: string | null;
|
||||
// Represents an authenticated user's configuration
|
||||
export interface AuthenticatedConfig {
|
||||
userId: string;
|
||||
userEmail: string;
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
expiresAt: number;
|
||||
organizationId: string | null; // null means personal organization
|
||||
}
|
||||
|
||||
// Represents configuration when using environment variable auth
|
||||
export interface EnvironmentAuthConfig {
|
||||
accessToken: string;
|
||||
organizationId: null; // Environment auth always uses personal organization
|
||||
}
|
||||
|
||||
// Union type representing the possible authentication states
|
||||
export type AuthConfig = AuthenticatedConfig | EnvironmentAuthConfig | null;
|
||||
|
||||
/**
|
||||
* Type guard to check if config is authenticated via file-based auth
|
||||
*/
|
||||
export function isAuthenticatedConfig(
|
||||
config: AuthConfig
|
||||
): config is AuthenticatedConfig {
|
||||
return config !== null && "userId" in config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if config is authenticated via environment variable
|
||||
*/
|
||||
export function isEnvironmentAuthConfig(
|
||||
config: AuthConfig
|
||||
): config is EnvironmentAuthConfig {
|
||||
return config !== null && !("userId" in config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the access token from any auth config type
|
||||
*/
|
||||
export function getAccessToken(config: AuthConfig): string | null {
|
||||
if (config === null) return null;
|
||||
return config.accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the organization ID from any auth config type
|
||||
*/
|
||||
export function getOrganizationId(config: AuthConfig): string | null {
|
||||
if (config === null) return null;
|
||||
return config.organizationId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,18 +82,40 @@ export function loadAuthConfig(): AuthConfig {
|
|||
|
||||
try {
|
||||
if (fs.existsSync(AUTH_CONFIG_PATH)) {
|
||||
return JSON.parse(fs.readFileSync(AUTH_CONFIG_PATH, "utf8"));
|
||||
const data = JSON.parse(fs.readFileSync(AUTH_CONFIG_PATH, "utf8"));
|
||||
|
||||
// Validate that we have all required fields for authenticated config
|
||||
if (
|
||||
data.userId &&
|
||||
data.userEmail &&
|
||||
data.accessToken &&
|
||||
data.refreshToken &&
|
||||
data.expiresAt
|
||||
) {
|
||||
return {
|
||||
userId: data.userId,
|
||||
userEmail: data.userEmail,
|
||||
accessToken: data.accessToken,
|
||||
refreshToken: data.refreshToken,
|
||||
expiresAt: data.expiresAt,
|
||||
organizationId: data.organizationId || null,
|
||||
};
|
||||
} else {
|
||||
console.warn("Invalid auth config found, ignoring.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error loading auth config: ${error}`);
|
||||
}
|
||||
return {};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the authentication configuration to disk
|
||||
*/
|
||||
export function saveAuthConfig(config: AuthConfig): void {
|
||||
export function saveAuthConfig(config: AuthenticatedConfig): void {
|
||||
// If using CONTINUE_API_KEY environment variable, don't save anything
|
||||
if (process.env.CONTINUE_API_KEY) {
|
||||
return;
|
||||
|
|
@ -72,21 +138,21 @@ export function saveAuthConfig(config: AuthConfig): void {
|
|||
* Checks if the user is authenticated and the token is valid
|
||||
*/
|
||||
export function isAuthenticated(): boolean {
|
||||
// If CONTINUE_API_KEY environment variable exists, user is authenticated
|
||||
if (process.env.CONTINUE_API_KEY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const config = loadAuthConfig();
|
||||
|
||||
if (!config.userId || !config.accessToken) {
|
||||
if (config === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if token is expired (if we have an expiration)
|
||||
if (config.expiresAt && Date.now() > config.expiresAt) {
|
||||
// Environment auth is always valid
|
||||
if (isEnvironmentAuthConfig(config)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if token is expired
|
||||
if (Date.now() > config.expiresAt) {
|
||||
// Try refreshing the token
|
||||
refreshToken(config.refreshToken || "").catch(() => {
|
||||
refreshToken(config.refreshToken).catch(() => {
|
||||
// If refresh fails, we're not authenticated
|
||||
return false;
|
||||
});
|
||||
|
|
@ -133,10 +199,13 @@ function getAuthUrlForTokenPage(useOnboarding: boolean = false): string {
|
|||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the access token using a refresh token
|
||||
*/
|
||||
async function refreshToken(refreshToken: string): Promise<AuthConfig> {
|
||||
async function refreshToken(
|
||||
refreshToken: string
|
||||
): Promise<AuthenticatedConfig> {
|
||||
try {
|
||||
// Load existing config to preserve organizationId and other fields
|
||||
const existingConfig = loadAuthConfig();
|
||||
|
|
@ -153,13 +222,16 @@ async function refreshToken(refreshToken: string): Promise<AuthConfig> {
|
|||
// Calculate token expiration (assuming 1 hour validity)
|
||||
const tokenExpiresAt = Date.now() + 60 * 60 * 1000;
|
||||
|
||||
const authConfig: AuthConfig = {
|
||||
...existingConfig, // Preserve existing fields like organizationId
|
||||
const authConfig: AuthenticatedConfig = {
|
||||
userId: user.id,
|
||||
userEmail: user.email,
|
||||
accessToken,
|
||||
refreshToken: newRefreshToken,
|
||||
expiresAt: tokenExpiresAt,
|
||||
// Preserve existing organizationId if it exists, otherwise set to null
|
||||
organizationId: isAuthenticatedConfig(existingConfig)
|
||||
? existingConfig.organizationId
|
||||
: null,
|
||||
};
|
||||
|
||||
// Save the config
|
||||
|
|
@ -188,6 +260,7 @@ export async function login(
|
|||
);
|
||||
return {
|
||||
accessToken: process.env.CONTINUE_API_KEY,
|
||||
organizationId: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -229,19 +302,31 @@ export async function ensureOrganization(
|
|||
isHeadless: boolean = false
|
||||
): Promise<AuthConfig> {
|
||||
// If using CONTINUE_API_KEY environment variable, don't require organization selection
|
||||
if (process.env.CONTINUE_API_KEY) {
|
||||
if (isEnvironmentAuthConfig(authConfig)) {
|
||||
return authConfig;
|
||||
}
|
||||
|
||||
// If already have organization ID (including null for personal), return as-is
|
||||
if (authConfig.organizationId !== undefined) {
|
||||
// If not authenticated, return as-is
|
||||
if (!isAuthenticatedConfig(authConfig)) {
|
||||
return authConfig;
|
||||
}
|
||||
|
||||
// TypeScript now knows authConfig is AuthenticatedConfig
|
||||
const authenticatedConfig = authConfig;
|
||||
|
||||
// If already have organization ID (including null for personal), return as-is
|
||||
if (authenticatedConfig.organizationId !== undefined) {
|
||||
return authenticatedConfig;
|
||||
}
|
||||
|
||||
// In headless mode, default to personal organization if none saved
|
||||
if (isHeadless) {
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
const updatedConfig: AuthenticatedConfig = {
|
||||
userId: authenticatedConfig.userId,
|
||||
userEmail: authenticatedConfig.userEmail,
|
||||
accessToken: authenticatedConfig.accessToken,
|
||||
refreshToken: authenticatedConfig.refreshToken,
|
||||
expiresAt: authenticatedConfig.expiresAt,
|
||||
organizationId: null, // Default to personal organization
|
||||
};
|
||||
saveAuthConfig(updatedConfig);
|
||||
|
|
@ -251,7 +336,7 @@ export async function ensureOrganization(
|
|||
// Need to select organization
|
||||
const apiClient = new DefaultApi(
|
||||
new Configuration({
|
||||
accessToken: authConfig.accessToken,
|
||||
accessToken: authenticatedConfig.accessToken,
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -260,8 +345,12 @@ export async function ensureOrganization(
|
|||
const organizations = resp.organizations;
|
||||
|
||||
if (organizations.length === 0) {
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
const updatedConfig: AuthenticatedConfig = {
|
||||
userId: authenticatedConfig.userId,
|
||||
userEmail: authenticatedConfig.userEmail,
|
||||
accessToken: authenticatedConfig.accessToken,
|
||||
refreshToken: authenticatedConfig.refreshToken,
|
||||
expiresAt: authenticatedConfig.expiresAt,
|
||||
organizationId: null,
|
||||
};
|
||||
saveAuthConfig(updatedConfig);
|
||||
|
|
@ -271,10 +360,13 @@ export async function ensureOrganization(
|
|||
// Automatically select the first organization if available, otherwise use personal
|
||||
const selectedOrg = organizations[0];
|
||||
const selectedOrgId = selectedOrg.id;
|
||||
const selectedOrgName = selectedOrg.name;
|
||||
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
const updatedConfig: AuthenticatedConfig = {
|
||||
userId: authenticatedConfig.userId,
|
||||
userEmail: authenticatedConfig.userEmail,
|
||||
accessToken: authenticatedConfig.accessToken,
|
||||
refreshToken: authenticatedConfig.refreshToken,
|
||||
expiresAt: authenticatedConfig.expiresAt,
|
||||
organizationId: selectedOrgId,
|
||||
};
|
||||
|
||||
|
|
@ -286,8 +378,12 @@ export async function ensureOrganization(
|
|||
error.response?.data?.message || error.message || error
|
||||
);
|
||||
console.info(chalk.yellow("Continuing without organization selection."));
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
const updatedConfig: AuthenticatedConfig = {
|
||||
userId: authenticatedConfig.userId,
|
||||
userEmail: authenticatedConfig.userEmail,
|
||||
accessToken: authenticatedConfig.accessToken,
|
||||
refreshToken: authenticatedConfig.refreshToken,
|
||||
expiresAt: authenticatedConfig.expiresAt,
|
||||
organizationId: null,
|
||||
};
|
||||
saveAuthConfig(updatedConfig);
|
||||
|
|
@ -301,14 +397,14 @@ export async function ensureOrganization(
|
|||
export async function listUserOrganizations(): Promise<
|
||||
{ id: string; name: string }[] | null
|
||||
> {
|
||||
const authConfig = loadAuthConfig();
|
||||
|
||||
// If using CONTINUE_API_KEY environment variable, organization switching is not supported
|
||||
if (process.env.CONTINUE_API_KEY) {
|
||||
if (isEnvironmentAuthConfig(authConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const authConfig = loadAuthConfig();
|
||||
|
||||
if (!authConfig.accessToken) {
|
||||
if (!isAuthenticatedConfig(authConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import chalk from "chalk";
|
||||
import { ChatCompletionMessageParam } from "openai/resources.mjs";
|
||||
import * as readlineSync from "readline-sync";
|
||||
import { initializeAssistant } from "../assistant.js";
|
||||
import { ensureAuthenticated } from "../auth/ensureAuth.js";
|
||||
import { ensureOrganization, loadAuthConfig } from "../auth/workos.js";
|
||||
import { initialize } from "../config.js";
|
||||
import { introMessage } from "../intro.js";
|
||||
import { configureLogger } from "../logger.js";
|
||||
import { loadSession, saveSession } from "../session.js";
|
||||
|
|
@ -34,7 +34,7 @@ async function initializeChat(options: ChatOptions) {
|
|||
);
|
||||
|
||||
// Initialize ContinueSDK and MCPService once
|
||||
const { config, llmApi, model, mcpService } = await initializeAssistant(
|
||||
const { config, llmApi, model, mcpService } = await initialize(
|
||||
authConfigWithOrg,
|
||||
options.config
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import { AssistantUnrolled } from "@continuedev/config-yaml";
|
||||
import {
|
||||
AssistantUnrolled,
|
||||
RegistryClient,
|
||||
unrollAssistant,
|
||||
} from "@continuedev/config-yaml";
|
||||
import {
|
||||
BaseLlmApi,
|
||||
constructLlmApi,
|
||||
|
|
@ -7,8 +11,16 @@ import {
|
|||
import {
|
||||
Configuration,
|
||||
DefaultApi,
|
||||
DefaultApiInterface,
|
||||
} from "@continuedev/sdk/dist/api/dist/index.js";
|
||||
import { AuthConfig } from "./auth/workos.js";
|
||||
import { dirname } from "node:path";
|
||||
import {
|
||||
AuthConfig,
|
||||
getAccessToken,
|
||||
getOrganizationId,
|
||||
} from "./auth/workos.js";
|
||||
import { CLIPlatformClient } from "./CLIPlatformClient.js";
|
||||
import { env } from "./env.js";
|
||||
import { MCPService } from "./mcp.js";
|
||||
|
||||
export function getLlmApi(
|
||||
|
|
@ -25,17 +37,20 @@ export function getLlmApi(
|
|||
);
|
||||
}
|
||||
|
||||
const accessToken = getAccessToken(authConfig);
|
||||
const organizationId = getOrganizationId(authConfig);
|
||||
|
||||
const config: LLMConfig =
|
||||
model.provider === "continue-proxy"
|
||||
? {
|
||||
provider: model.provider,
|
||||
requestOptions: model.requestOptions,
|
||||
apiBase: model.apiBase,
|
||||
apiKey: authConfig.accessToken,
|
||||
apiKey: accessToken ?? undefined,
|
||||
env: {
|
||||
apiKeyLocation: (model as any).apiKeyLocation,
|
||||
// envSecretLocations: model.env,
|
||||
orgScopeId: authConfig.organizationId ?? null,
|
||||
orgScopeId: organizationId,
|
||||
proxyUrl: undefined, // TODO
|
||||
},
|
||||
}
|
||||
|
|
@ -58,14 +73,45 @@ export function getLlmApi(
|
|||
return [llmApi, model.model];
|
||||
}
|
||||
|
||||
export async function loadAssistant(
|
||||
accessToken: string | undefined,
|
||||
async function loadConfigYaml(
|
||||
accessToken: string | null,
|
||||
filePath: string,
|
||||
organizationId: string | null,
|
||||
apiClient: DefaultApiInterface
|
||||
): Promise<AssistantUnrolled> {
|
||||
const unrollResult = await unrollAssistant(
|
||||
{ filePath, uriType: "file" },
|
||||
new RegistryClient({
|
||||
accessToken: accessToken ?? undefined,
|
||||
apiBase: env.apiBase,
|
||||
rootPath: dirname(filePath),
|
||||
}),
|
||||
{
|
||||
currentUserSlug: "",
|
||||
alwaysUseProxy: false,
|
||||
orgScopeId: organizationId,
|
||||
renderSecrets: true,
|
||||
platformClient: new CLIPlatformClient(organizationId, apiClient),
|
||||
onPremProxyUrl: null,
|
||||
}
|
||||
);
|
||||
|
||||
if (unrollResult.errors?.length || !unrollResult.config) {
|
||||
const errorDetails = unrollResult.errors?.join("\n") ?? "Unknown error";
|
||||
throw new Error(`Failed to load config file:\n${errorDetails}`);
|
||||
}
|
||||
|
||||
return unrollResult.config;
|
||||
}
|
||||
|
||||
export async function loadConfig(
|
||||
authConfig: AuthConfig,
|
||||
config: string | undefined,
|
||||
organizationId: string | undefined
|
||||
organizationId: string | null
|
||||
): Promise<AssistantUnrolled> {
|
||||
const apiClient = new DefaultApi(
|
||||
new Configuration({
|
||||
accessToken,
|
||||
accessToken: authConfig?.accessToken ?? undefined,
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -73,7 +119,7 @@ export async function loadAssistant(
|
|||
// Fall back to listing assistants and taking the first one
|
||||
const assistants = await apiClient.listAssistants({
|
||||
alwaysUseProxy: "false",
|
||||
organizationId,
|
||||
organizationId: organizationId ?? undefined,
|
||||
});
|
||||
|
||||
const result = assistants[0].configResult;
|
||||
|
|
@ -82,10 +128,20 @@ export async function loadAssistant(
|
|||
}
|
||||
|
||||
return result.config as AssistantUnrolled;
|
||||
} else if (config.startsWith(".") || config.startsWith("/")) {
|
||||
} else if (
|
||||
config.startsWith(".") ||
|
||||
config.startsWith("/") ||
|
||||
config.startsWith("~")
|
||||
) {
|
||||
// Load from file
|
||||
throw new Error("Loading from file is not supported yet.");
|
||||
// return loadAssistantFromFile(config);
|
||||
const configYaml = await loadConfigYaml(
|
||||
authConfig?.accessToken ?? null,
|
||||
config,
|
||||
organizationId,
|
||||
apiClient
|
||||
);
|
||||
|
||||
return configYaml;
|
||||
} else {
|
||||
// Load from slug
|
||||
const [ownerSlug, packageSlug] = config.split("/");
|
||||
|
|
@ -93,7 +149,7 @@ export async function loadAssistant(
|
|||
ownerSlug,
|
||||
packageSlug,
|
||||
alwaysUseProxy: "false",
|
||||
organizationId,
|
||||
organizationId: organizationId ?? undefined,
|
||||
});
|
||||
|
||||
const result = resp.configResult;
|
||||
|
|
@ -105,7 +161,7 @@ export async function loadAssistant(
|
|||
}
|
||||
}
|
||||
|
||||
export async function initializeAssistant(
|
||||
export async function initialize(
|
||||
authConfig: AuthConfig,
|
||||
configPath: string | undefined
|
||||
): Promise<{
|
||||
|
|
@ -114,11 +170,10 @@ export async function initializeAssistant(
|
|||
model: string;
|
||||
mcpService: MCPService;
|
||||
}> {
|
||||
const config = await loadAssistant(
|
||||
authConfig.accessToken,
|
||||
configPath,
|
||||
authConfig.organizationId ?? undefined
|
||||
);
|
||||
const accessToken = getAccessToken(authConfig);
|
||||
const organizationId = getOrganizationId(authConfig);
|
||||
|
||||
const config = await loadConfig(authConfig, configPath, organizationId);
|
||||
const [llmApi, model] = getLlmApi(config, authConfig);
|
||||
const mcpService = await MCPService.create(config);
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export function introMessage(
|
|||
console.info(chalk.cyan(CONTINUE_ASCII_ART));
|
||||
|
||||
console.info(`\n${chalk.bold.blue(`Agent: ${config.name}\n`)}`);
|
||||
console.info(`${chalk.yellow("Model:")} ${modelName}\n`);
|
||||
console.info(`${chalk.yellow("Model:")} ${modelName.split("/").pop()}\n`);
|
||||
|
||||
console.info(chalk.yellow("Tools:"));
|
||||
getAllTools().forEach((tool) => {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
import chalk from "chalk";
|
||||
import {
|
||||
isAuthenticated,
|
||||
isAuthenticatedConfig,
|
||||
loadAuthConfig,
|
||||
login,
|
||||
logout,
|
||||
} from "./auth/workos.js";
|
||||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
|
||||
export async function handleSlashCommands(
|
||||
input: string,
|
||||
|
|
@ -38,9 +39,15 @@ export async function handleSlashCommands(
|
|||
case "login":
|
||||
login()
|
||||
.then((config) => {
|
||||
console.info(
|
||||
chalk.green(`\nLogged in as ${config.userEmail || config.userId}`)
|
||||
);
|
||||
if (config && isAuthenticatedConfig(config)) {
|
||||
console.info(
|
||||
chalk.green(
|
||||
`\nLogged in as ${config.userEmail || config.userId}`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.info(chalk.green(`\nLogged in successfully`));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(chalk.red(`\nLogin failed: ${error.message}`));
|
||||
|
|
@ -60,10 +67,17 @@ export async function handleSlashCommands(
|
|||
case "whoami":
|
||||
if (isAuthenticated()) {
|
||||
const config = loadAuthConfig();
|
||||
return {
|
||||
exit: false,
|
||||
output: `Logged in as ${config.userEmail || config.userId}`,
|
||||
};
|
||||
if (config && isAuthenticatedConfig(config)) {
|
||||
return {
|
||||
exit: false,
|
||||
output: `Logged in as ${config.userEmail || config.userId}`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
exit: false,
|
||||
output: "Authenticated via environment variable",
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
exit: false,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import { Box, Text, useInput } from "ink";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { loadAuthConfig, listUserOrganizations } from "../auth/workos.js";
|
||||
import {
|
||||
getOrganizationId,
|
||||
listUserOrganizations,
|
||||
loadAuthConfig,
|
||||
} from "../auth/workos.js";
|
||||
|
||||
interface Organization {
|
||||
id: string;
|
||||
|
|
@ -26,8 +30,8 @@ const OrganizationSelector: React.FC<OrganizationSelectorProps> = ({
|
|||
const loadOrganizations = async () => {
|
||||
try {
|
||||
const authConfig = loadAuthConfig();
|
||||
setCurrentOrgId(authConfig.organizationId);
|
||||
|
||||
setCurrentOrgId(getOrganizationId(authConfig));
|
||||
|
||||
const organizations = await listUserOrganizations();
|
||||
if (organizations === null) {
|
||||
setError("Failed to load organizations");
|
||||
|
|
@ -128,7 +132,7 @@ const OrganizationSelector: React.FC<OrganizationSelectorProps> = ({
|
|||
{allOptions.map((option, index) => {
|
||||
const isSelected = index === selectedIndex;
|
||||
const isCurrent = option.isCurrent;
|
||||
|
||||
|
||||
return (
|
||||
<Box key={option.id || "personal"}>
|
||||
<Text
|
||||
|
|
@ -153,4 +157,4 @@ const OrganizationSelector: React.FC<OrganizationSelectorProps> = ({
|
|||
);
|
||||
};
|
||||
|
||||
export default OrganizationSelector;
|
||||
export default OrganizationSelector;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { AssistantUnrolled } from "@continuedev/config-yaml";
|
||||
import { BaseLlmApi } from "@continuedev/openai-adapters";
|
||||
import { useState } from "react";
|
||||
import { initializeAssistant } from "../../assistant.js";
|
||||
import { loadAuthConfig, saveAuthConfig } from "../../auth/workos.js";
|
||||
import {
|
||||
isAuthenticatedConfig,
|
||||
loadAuthConfig,
|
||||
saveAuthConfig,
|
||||
} from "../../auth/workos.js";
|
||||
import { initialize } from "../../config.js";
|
||||
import { introMessage } from "../../intro.js";
|
||||
import { MCPService } from "../../mcp.js";
|
||||
|
||||
|
|
@ -38,6 +42,18 @@ export function useOrganizationSelector({
|
|||
|
||||
// Update auth config
|
||||
const authConfig = loadAuthConfig();
|
||||
|
||||
// Only allow organization switching for authenticated users
|
||||
if (!isAuthenticatedConfig(authConfig)) {
|
||||
onMessage({
|
||||
role: "system",
|
||||
content:
|
||||
"Organization switching not available for environment variable auth",
|
||||
messageType: "system" as const,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
organizationId,
|
||||
|
|
@ -58,7 +74,7 @@ export function useOrganizationSelector({
|
|||
llmApi: newLlmApi,
|
||||
model: newModel,
|
||||
mcpService: newMcpService,
|
||||
} = await initializeAssistant(updatedConfig, configPath);
|
||||
} = await initialize(updatedConfig, configPath);
|
||||
|
||||
// Update assistant configuration
|
||||
onAssistantChange(config, newModel, newLlmApi, newMcpService);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue