From 3c5c8307a2d28e3e9f69e47db80085137d3d9f7b Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 29 Dec 2024 20:24:06 -0500 Subject: [PATCH 01/50] update config-yaml schema --- packages/config-yaml/package.json | 2 +- packages/config-yaml/src/index.ts | 1 + packages/config-yaml/src/schemas/index.ts | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/config-yaml/package.json b/packages/config-yaml/package.json index 3903c91d8..f92e6ff27 100644 --- a/packages/config-yaml/package.json +++ b/packages/config-yaml/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.0", + "version": "1.0.3", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/config-yaml/src/index.ts b/packages/config-yaml/src/index.ts index c229f147b..5056af49d 100644 --- a/packages/config-yaml/src/index.ts +++ b/packages/config-yaml/src/index.ts @@ -91,5 +91,6 @@ export function fillTemplateVariables( }); } +export { ConfigYaml, configYamlSchema } from "./schemas/index.js"; export type { ModelConfig } from "./schemas/models.js"; export { validateConfigYaml } from "./validation.js"; diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index a75566f96..03cfe8149 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -9,6 +9,9 @@ const packageSchema = z.object({ }); const toolSchema = z.object({ + name: z.string(), + description: z.string(), + policy: z.enum(["automatic", "allowed", "disabled"]).optional(), url: z.string(), apiKey: z.string().optional(), }); @@ -21,6 +24,13 @@ const mcpServerSchema = z.object({ env: z.record(z.string()).optional(), }); +const promptSchema = z.object({ + name: z.string(), + description: z.string().optional(), + type: z.enum(["slash-command", "context-provider"]).optional(), + prompt: z.string(), +}); + export const configYamlSchema = z.object({ name: z.string(), packages: z.array(packageSchema).optional(), @@ -29,6 +39,8 @@ export const configYamlSchema = z.object({ data: z.array(dataSchema).optional(), tools: z.array(toolSchema).optional(), mcpServers: z.array(mcpServerSchema).optional(), + rules: z.string().optional(), + prompts: z.array(promptSchema).optional(), }); export type ConfigYaml = z.infer; From 0a3763a03fd5c8600217ed10e30779214ed73a26 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 30 Dec 2024 13:36:17 -0500 Subject: [PATCH 02/50] load remote yaml from platform --- core/config/ConfigHandler.ts | 17 +++--- .../profile/ControlPlaneProfileLoader.ts | 1 + core/config/profile/LocalProfileLoader.ts | 1 + core/config/profile/PlatformProfileLoader.ts | 60 +++++++++++++++++++ core/config/profile/doLoadConfig.ts | 7 ++- core/config/yaml/loadYaml.ts | 31 +++++----- core/control-plane/client.ts | 23 +++++++ extensions/vscode/package-lock.json | 4 +- 8 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 core/config/profile/PlatformProfileLoader.ts diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 9ef3cc8d2..d37176b7c 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -19,8 +19,8 @@ import { LOCAL_ONBOARDING_CHAT_MODEL, ONBOARDING_LOCAL_MODEL_TITLE, } from "./onboarding.js"; -import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js"; import LocalProfileLoader from "./profile/LocalProfileLoader.js"; +import PlatformProfileLoader from "./profile/PlatformProfileLoader.js"; import { ProfileDescription, ProfileLifecycleManager, @@ -100,15 +100,16 @@ export class ConfigHandler { private async fetchControlPlaneProfiles() { // Get the profiles and create their lifecycle managers this.controlPlaneClient - .listWorkspaces() - .then(async (workspaces) => { + .listAssistants() + .then(async (assistants) => { this.profiles = this.profiles.filter( (profile) => profile.profileId === "local", ); - workspaces.forEach((workspace) => { - const profileLoader = new ControlPlaneProfileLoader( - workspace.id, - workspace.name, + assistants.forEach((assistant) => { + const profileLoader = new PlatformProfileLoader( + assistant.configYaml, + assistant.ownerSlug, + assistant.packageSlug, this.controlPlaneClient, this.ide, this.ideSettingsPromise, @@ -140,7 +141,7 @@ export class ConfigHandler { } }) .catch((e) => { - console.error(e); + console.error("Failed to list assistants: ", e); }); } diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 448dbdb42..47b40ac7b 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -53,6 +53,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { this.controlPlaneClient, this.writeLog, serializedConfig, + undefined, this.workspaceId, ); diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 0705c8745..c6ec59c1b 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -24,6 +24,7 @@ export default class LocalProfileLoader implements IProfileLoader { this.controlPlaneClient, this.writeLog, undefined, + undefined, ); } diff --git a/core/config/profile/PlatformProfileLoader.ts b/core/config/profile/PlatformProfileLoader.ts new file mode 100644 index 000000000..a168b1ea4 --- /dev/null +++ b/core/config/profile/PlatformProfileLoader.ts @@ -0,0 +1,60 @@ +import { ControlPlaneClient } from "../../control-plane/client.js"; +import { ContinueConfig, IDE, IdeSettings } from "../../index.js"; +import { ConfigResult } from "../load.js"; + +import { ConfigYaml } from "@continuedev/config-yaml/dist/schemas/index.js"; +import doLoadConfig from "./doLoadConfig.js"; +import { IProfileLoader } from "./IProfileLoader.js"; + +export default class PlatformProfileLoader implements IProfileLoader { + private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes + + readonly profileId: string; + profileTitle: string; + + constructor( + private configYaml: ConfigYaml, + private readonly ownerSlug: string, + private readonly packageSlug: string, + private readonly controlPlaneClient: ControlPlaneClient, + private readonly ide: IDE, + private ideSettingsPromise: Promise, + private writeLog: (message: string) => Promise, + private readonly onReload: () => void, + ) { + this.profileId = `${ownerSlug}/${packageSlug}`; + this.profileTitle = `${ownerSlug}/${packageSlug}`; + + setInterval(async () => { + const assistants = await this.controlPlaneClient.listAssistants(); + const newConfigYaml = assistants.find( + (assistant) => + assistant.packageSlug === this.packageSlug && + assistant.ownerSlug === this.ownerSlug, + )?.configYaml; + if (!newConfigYaml) { + return; + } + this.configYaml = newConfigYaml; + this.onReload(); + }, PlatformProfileLoader.RELOAD_INTERVAL); + } + + async doLoadConfig(): Promise> { + const results = await doLoadConfig( + this.ide, + this.ideSettingsPromise, + this.controlPlaneClient, + this.writeLog, + undefined, + this.configYaml, + ); + + return { + ...results, + errors: [], // Don't do config validation here, it happens in admin panel + }; + } + + setIsActive(isActive: boolean): void {} +} diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index a82dd896d..d3f0dd8c1 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -1,5 +1,6 @@ import fs from "fs"; +import { ConfigYaml } from "@continuedev/config-yaml/dist/schemas"; import { ContinueConfig, ContinueRcJson, @@ -25,6 +26,7 @@ export default async function doLoadConfig( controlPlaneClient: ControlPlaneClient, writeLog: (message: string) => Promise, overrideConfigJson: SerializedContinueConfig | undefined, + overrideConfigYaml: ConfigYaml | undefined, workspaceId?: string, ): Promise> { const workspaceConfigs = await getWorkspaceConfigs(ide); @@ -39,7 +41,7 @@ export default async function doLoadConfig( let errors: ConfigValidationError[] | undefined; let configLoadInterrupted = false; - if (fs.existsSync(configYamlPath)) { + if (fs.existsSync(configYamlPath) || overrideConfigYaml) { const result = await loadContinueConfigFromYaml( ide, workspaceConfigs.map((c) => JSON.stringify(c)), @@ -48,8 +50,7 @@ export default async function doLoadConfig( uniqueId, writeLog, workOsAccessToken, - undefined, - // overrideConfigYaml, TODO + overrideConfigYaml, ); newConfig = result.config; errors = result.errors; diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index ad33ea4d8..4a8335eae 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -1,5 +1,4 @@ import fs from "node:fs"; -import path from "path"; import { extendConfig, @@ -26,17 +25,13 @@ import { contextProviderClassFromName } from "../../context/providers/index"; import { allEmbeddingsProviders } from "../../indexing/allEmbeddingsProviders"; import FreeTrial from "../../llm/llms/FreeTrial"; import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider"; -import { - getConfigYamlPath, - getContinueDotEnv, - readAllGlobalPromptFiles, -} from "../../util/paths"; +import { getConfigYamlPath, getContinueDotEnv } from "../../util/paths"; import { getSystemPromptDotFile } from "../getSystemPromptDotFile"; import { ConfigValidationError } from "../validation.js"; -import { llmsFromModelConfig } from "./models"; -import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile"; +import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; +import { llmsFromModelConfig } from "./models"; export interface ConfigResult { config: T | undefined; @@ -60,12 +55,12 @@ function renderTemplateVars(configYaml: string): string { function loadConfigYaml( workspaceConfigs: string[], - ideSettings: IdeSettings, - ideType: IdeType, rawYaml: string, + overrideConfigYaml: ConfigYaml | undefined, ): ConfigResult { - const renderedYaml = renderTemplateVars(rawYaml); - let config = YAML.parse(renderedYaml) as ConfigYaml; + let config = + overrideConfigYaml ?? + (YAML.parse(renderTemplateVars(rawYaml)) as ConfigYaml); const errors = validateConfigYaml(config); if (errors?.some((error) => error.level === ValidationLevel.Error)) { @@ -283,16 +278,18 @@ export async function loadContinueConfigFromYaml( uniqueId: string, writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, - overrideConfigYaml: string | undefined, + overrideConfigYaml: ConfigYaml | undefined, ): Promise> { const configYamlPath = getConfigYamlPath(ideType); - const rawYaml = fs.readFileSync(configYamlPath, "utf-8"); + const rawYaml = + overrideConfigYaml === undefined + ? fs.readFileSync(configYamlPath, "utf-8") + : ""; const configYamlResult = await loadConfigYaml( workspaceConfigs, - ideSettings, - ideType, - overrideConfigYaml ?? rawYaml, + rawYaml, + overrideConfigYaml, ); if (!configYamlResult.config || configYamlResult.configLoadInterrupted) { diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index b84e24570..92645ab73 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -3,6 +3,7 @@ import fetch, { RequestInit, Response } from "node-fetch"; import { ModelDescription } from "../index.js"; +import { ConfigYaml } from "@continuedev/config-yaml/dist/schemas/index.js"; import { controlPlaneEnv } from "./env.js"; export interface ControlPlaneSessionInfo { @@ -85,6 +86,28 @@ export class ControlPlaneClient { } } + public async listAssistants(): Promise< + { + configYaml: ConfigYaml; + ownerSlug: string; + packageSlug: string; + }[] + > { + const userId = await this.userId; + if (!userId) { + return []; + } + + try { + const resp = await this.request("ide/list-assistants", { + method: "GET", + }); + return (await resp.json()) as any; + } catch (e) { + return []; + } + } + async getSettingsForWorkspace(workspaceId: string): Promise { const userId = await this.userId; if (!userId) { diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 8f5cad8a0..0a2dd8330 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.247", + "version": "0.9.248", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.247", + "version": "0.9.248", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", From 00f1218efb16b82e15e67baff3d6dd667a6f55c6 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 31 Dec 2024 18:18:15 -0500 Subject: [PATCH 03/50] make ContinueProxy work with platform --- .../profile/ControlPlaneProfileLoader.ts | 1 + core/config/profile/LocalProfileLoader.ts | 1 + core/config/profile/PlatformProfileLoader.ts | 9 +++ core/config/profile/doLoadConfig.ts | 3 + core/config/yaml/loadYaml.ts | 6 ++ core/config/yaml/models.ts | 55 ++++++++++++++++++- core/index.d.ts | 2 + core/llm/index.ts | 2 + core/llm/llms/stubs/ContinueProxy.ts | 33 ++++++++++- core/package-lock.json | 8 +-- core/package.json | 2 +- extensions/vscode/package-lock.json | 2 +- gui/package-lock.json | 2 +- gui/src/context/Auth.tsx | 16 +++--- packages/config-yaml/package.json | 2 +- packages/config-yaml/src/schemas/models.ts | 3 + packages/openai-adapters/src/apis/OpenAI.ts | 37 +++++++++++-- 17 files changed, 160 insertions(+), 24 deletions(-) diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 47b40ac7b..0ccea714e 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -54,6 +54,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader { this.writeLog, serializedConfig, undefined, + undefined, this.workspaceId, ); diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index c6ec59c1b..f54fe612c 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -25,6 +25,7 @@ export default class LocalProfileLoader implements IProfileLoader { this.writeLog, undefined, undefined, + undefined, ); } diff --git a/core/config/profile/PlatformProfileLoader.ts b/core/config/profile/PlatformProfileLoader.ts index a168b1ea4..16347e2b2 100644 --- a/core/config/profile/PlatformProfileLoader.ts +++ b/core/config/profile/PlatformProfileLoader.ts @@ -6,6 +6,11 @@ import { ConfigYaml } from "@continuedev/config-yaml/dist/schemas/index.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; +export interface PlatformConfigMetadata { + ownerSlug: string; + packageSlug: string; +} + export default class PlatformProfileLoader implements IProfileLoader { private static RELOAD_INTERVAL = 1000 * 60 * 15; // every 15 minutes @@ -48,6 +53,10 @@ export default class PlatformProfileLoader implements IProfileLoader { this.writeLog, undefined, this.configYaml, + { + ownerSlug: this.ownerSlug, + packageSlug: this.packageSlug, + }, ); return { diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index d3f0dd8c1..747a582cd 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -19,6 +19,7 @@ import { TTS } from "../../util/tts"; import { ConfigResult, loadFullConfigNode } from "../load"; import { ConfigValidationError } from "../validation"; import { loadContinueConfigFromYaml } from "../yaml/loadYaml"; +import { PlatformConfigMetadata } from "./PlatformProfileLoader"; export default async function doLoadConfig( ide: IDE, @@ -27,6 +28,7 @@ export default async function doLoadConfig( writeLog: (message: string) => Promise, overrideConfigJson: SerializedContinueConfig | undefined, overrideConfigYaml: ConfigYaml | undefined, + platformConfigMetadata: PlatformConfigMetadata | undefined, workspaceId?: string, ): Promise> { const workspaceConfigs = await getWorkspaceConfigs(ide); @@ -51,6 +53,7 @@ export default async function doLoadConfig( writeLog, workOsAccessToken, overrideConfigYaml, + platformConfigMetadata, ); newConfig = result.config; errors = result.errors; diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 4a8335eae..77b858630 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -31,6 +31,7 @@ import { ConfigValidationError } from "../validation.js"; import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile"; import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; +import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader"; import { llmsFromModelConfig } from "./models"; export interface ConfigResult { @@ -114,6 +115,7 @@ async function configYamlToContinueConfig( uniqueId: string, writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, + platformConfigMetadata: PlatformConfigMetadata | undefined, allowFreeTrial: boolean = true, ): Promise { const continueConfig: ContinueConfig = { @@ -141,6 +143,7 @@ async function configYamlToContinueConfig( uniqueId, ideSettings, writeLog, + platformConfigMetadata, ); continueConfig.models.push(...llms); } else if (model.roles?.includes("autocomplete")) { @@ -151,6 +154,7 @@ async function configYamlToContinueConfig( uniqueId, ideSettings, writeLog, + platformConfigMetadata, ); continueConfig.tabAutocompleteModels?.push(...llms); } @@ -279,6 +283,7 @@ export async function loadContinueConfigFromYaml( writeLog: (log: string) => Promise, workOsAccessToken: string | undefined, overrideConfigYaml: ConfigYaml | undefined, + platformConfigMetadata: PlatformConfigMetadata | undefined, ): Promise> { const configYamlPath = getConfigYamlPath(ideType); const rawYaml = @@ -307,6 +312,7 @@ export async function loadContinueConfigFromYaml( uniqueId, writeLog, workOsAccessToken, + platformConfigMetadata, ); const systemPromptDotFile = await getSystemPromptDotFile(ide); diff --git a/core/config/yaml/models.ts b/core/config/yaml/models.ts index d6eb6d3e0..bcb46ec7c 100644 --- a/core/config/yaml/models.ts +++ b/core/config/yaml/models.ts @@ -3,21 +3,68 @@ import { ModelConfig } from "@continuedev/config-yaml"; import { IDE, IdeSettings, LLMOptions } from "../.."; import { BaseLLM } from "../../llm"; import { LLMClasses } from "../../llm/llms"; +import ContinueProxy from "../../llm/llms/stubs/ContinueProxy"; +import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader"; const AUTODETECT = "AUTODETECT"; +const ALWAYS_LOCAL_PROVIDERS = [ + "ollama", + "lmstudio", + "llamafile", + "llama.cpp", + "msty", +]; + +function useContinueProxy( + model: ModelConfig, + platformConfigMetadata: PlatformConfigMetadata | undefined, +): boolean { + return ( + !!platformConfigMetadata && !ALWAYS_LOCAL_PROVIDERS.includes(model.provider) + ); +} + +function getModelClass( + model: ModelConfig, + platformConfigMetadata: PlatformConfigMetadata | undefined, +): (typeof LLMClasses)[number] | undefined { + if (useContinueProxy(model, platformConfigMetadata)) { + return ContinueProxy; + } + return LLMClasses.find((llm) => llm.providerName === model.provider); +} + +function getContinueProxyModelName( + ownerSlug: string, + packageSlug: string, + model: ModelConfig, +): string { + return `${ownerSlug}/${packageSlug}/${model.provider}/${model.model}`; +} + async function modelConfigToBaseLLM( model: ModelConfig, uniqueId: string, ideSettings: IdeSettings, writeLog: (log: string) => Promise, + platformConfigMetadata: PlatformConfigMetadata | undefined, ): Promise { - const cls = LLMClasses.find((llm) => llm.providerName === model.provider); + const cls = getModelClass(model, platformConfigMetadata); if (!cls) { return undefined; } + const usingContinueProxy = useContinueProxy(model, platformConfigMetadata); + const modelName = usingContinueProxy + ? getContinueProxyModelName( + platformConfigMetadata!.ownerSlug, + platformConfigMetadata!.packageSlug, + model, + ) + : model.model; + let options: LLMOptions = { ...model, completionOptions: { @@ -30,6 +77,7 @@ async function modelConfigToBaseLLM( writeLog, uniqueId, title: model.name, + model: modelName, }; const llm = new cls(options); @@ -43,6 +91,7 @@ async function autodetectModels( uniqueId: string, ideSettings: IdeSettings, writeLog: (log: string) => Promise, + platformConfigMetadata: PlatformConfigMetadata | undefined, ): Promise { try { const modelNames = await llm.listModels(); @@ -62,6 +111,7 @@ async function autodetectModels( uniqueId, ideSettings, writeLog, + platformConfigMetadata, ); }), ); @@ -78,12 +128,14 @@ export async function llmsFromModelConfig( uniqueId: string, ideSettings: IdeSettings, writeLog: (log: string) => Promise, + platformConfigMetadata: PlatformConfigMetadata | undefined, ): Promise { const baseLlm = await modelConfigToBaseLLM( model, uniqueId, ideSettings, writeLog, + platformConfigMetadata, ); if (!baseLlm) { return []; @@ -97,6 +149,7 @@ export async function llmsFromModelConfig( uniqueId, ideSettings, writeLog, + platformConfigMetadata, ); return models; } else { diff --git a/core/index.d.ts b/core/index.d.ts index d916a19f1..231132ae8 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -456,6 +456,7 @@ export interface LLMOptions { writeLog?: (str: string) => Promise; llmRequestHook?: (model: string, prompt: string) => any; apiKey?: string; + apiKeySecret?: string; aiGatewaySlug?: string; apiBase?: string; cacheBehavior?: CacheBehavior; @@ -875,6 +876,7 @@ export interface ModelDescription { provider: string; model: string; apiKey?: string; + apiKeySecret?: string; apiBase?: string; contextLength?: number; maxStopWords?: number; diff --git a/core/llm/index.ts b/core/llm/index.ts index 5c0253e86..9b1018da0 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -116,6 +116,7 @@ export abstract class BaseLLM implements ILLM { writeLog?: (str: string) => Promise; llmRequestHook?: (model: string, prompt: string) => any; apiKey?: string; + apiKeySecret?: string; apiBase?: string; cacheBehavior?: CacheBehavior; capabilities?: ModelCapability; @@ -193,6 +194,7 @@ export abstract class BaseLLM implements ILLM { this.writeLog = options.writeLog; this.llmRequestHook = options.llmRequestHook; this.apiKey = options.apiKey; + this.apiKeySecret = options.apiKeySecret; this.aiGatewaySlug = options.aiGatewaySlug; this.apiBase = options.apiBase; this.cacheBehavior = options.cacheBehavior; diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index c037ebd61..f98e2d739 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -2,7 +2,13 @@ import { ControlPlaneProxyInfo } from "../../../control-plane/analytics/IAnalyti import { Telemetry } from "../../../util/posthog.js"; import OpenAI from "../OpenAI.js"; -import type { Chunk, LLMOptions } from "../../../index.js"; +import { ChatCompletionCreateParams } from "@continuedev/openai-adapters"; +import type { + ChatMessage, + Chunk, + CompletionOptions, + LLMOptions, +} from "../../../index.js"; class ContinueProxy extends OpenAI { set controlPlaneProxyInfo(value: ControlPlaneProxyInfo) { @@ -10,11 +16,36 @@ class ContinueProxy extends OpenAI { this.apiBase = new URL("openai/v1/", value.controlPlaneProxyUrl).toString(); } + // The apiKey and apiBase are set to the values for the proxy, + // but we need to keep track of the actual values that the proxy will use + // to call whatever LLM API is chosen + private actualApiBase?: string; + private actualApiKey?: string; + + constructor(options: LLMOptions) { + super(options); + this.actualApiBase = options.apiBase; + this.actualApiKey = options.apiKey; + } + static providerName = "continue-proxy"; static defaultOptions: Partial = { useLegacyCompletionsEndpoint: false, }; + protected _convertArgs( + options: CompletionOptions, + messages: ChatMessage[], + ): ChatCompletionCreateParams { + const args: any = super._convertArgs(options, messages); + args.continueProperties = { + apiKey: this.actualApiKey, + apiBase: this.actualApiBase, + apiKeySecret: this.apiKeySecret, + }; + return args; + } + protected _getHeaders() { const headers: any = super._getHeaders(); headers["x-continue-unique-id"] = Telemetry.uniqueId; diff --git a/core/package-lock.json b/core/package-lock.json index 4117d99cf..1d2bac64c 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -13,7 +13,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.4", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", @@ -3037,9 +3037,9 @@ } }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.0.tgz", - "integrity": "sha512-NwagzzpnPLbMC3delzFSjWiFv5fp8ReFjdMQF0ko0Xg+U0Myja90k/J7JWGegF/SZMABxc/OJchElJFr58TwGA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.4.tgz", + "integrity": "sha512-hMU+Svgjj/7XM3ZsHJTB0mfLUSnt58cXszoV8gj5nj9jtqNhKhbkVaz4eKsFe0A//DAk/QwWolKykE/xYZyBVg==", "dependencies": { "yaml": "^2.6.1", "zod": "^3.23.8" diff --git a/core/package.json b/core/package.json index eb805363b..dfaf7a125 100644 --- a/core/package.json +++ b/core/package.json @@ -45,7 +45,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.4", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 0a2dd8330..de8ccf7c9 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -104,7 +104,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.4", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", diff --git a/gui/package-lock.json b/gui/package-lock.json index 9ff6fc72d..a1e4cbb66 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -107,7 +107,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.621.0", "@aws-sdk/credential-providers": "^3.620.1", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.4", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index c2ad174f2..b00c30929 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -1,21 +1,21 @@ +import { ProfileDescription } from "core/config/ProfileLifecycleManager"; +import { ControlPlaneSessionInfo } from "core/control-plane/client"; import React, { createContext, useContext, - useState, useEffect, useMemo, + useState, } from "react"; -import { ControlPlaneSessionInfo } from "core/control-plane/client"; import { useDispatch } from "react-redux"; +import AccountDialog from "../components/AccountDialog"; import ConfirmationDialog from "../components/dialogs/ConfirmationDialog"; -import { IdeMessengerContext } from "./IdeMessenger"; +import { useWebviewListener } from "../hooks/useWebviewListener"; +import { useAppSelector } from "../redux/hooks"; +import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; -import { ProfileDescription } from "core/config/ProfileLifecycleManager"; -import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; -import { useWebviewListener } from "../hooks/useWebviewListener"; -import AccountDialog from "../components/AccountDialog"; -import { useAppSelector } from "../redux/hooks"; +import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { session: ControlPlaneSessionInfo | undefined; diff --git a/packages/config-yaml/package.json b/packages/config-yaml/package.json index f92e6ff27..d3e096605 100644 --- a/packages/config-yaml/package.json +++ b/packages/config-yaml/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.3", + "version": "1.0.4", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 57415247d..89b740e57 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -46,6 +46,9 @@ export const modelSchema = z.object({ name: z.string(), provider: z.string(), model: z.string(), + apiKey: z.string().optional(), + apiBase: z.string().optional(), + apiKeySecret: z.string().optional(), roles: modelRolesSchema.array().optional(), defaultCompletionOptions: completionOptionsSchema.optional(), requestOptions: requestOptionsSchema.optional(), diff --git a/packages/openai-adapters/src/apis/OpenAI.ts b/packages/openai-adapters/src/apis/OpenAI.ts index db52a6758..aa059f7db 100644 --- a/packages/openai-adapters/src/apis/OpenAI.ts +++ b/packages/openai-adapters/src/apis/OpenAI.ts @@ -4,6 +4,7 @@ import { OpenAI } from "openai/index"; import { ChatCompletion, ChatCompletionChunk, + ChatCompletionCreateParams, ChatCompletionCreateParamsNonStreaming, ChatCompletionCreateParamsStreaming, Completion, @@ -34,22 +35,46 @@ export class OpenAIApi implements BaseLlmApi { }); } + modifyChatBody(body: T): T { + // o-series models + if (body.model.startsWith("o")) { + // a) use max_completion_tokens instead of max_tokens + body.max_completion_tokens = body.max_tokens; + body.max_tokens = undefined; + + // b) use "developer" message role rather than "system" + body.messages = body.messages.map((message) => { + if (message.role === "system") { + return { ...message, role: "developer" } as any; + } + return message; + }); + } + return body; + } + async chatCompletionNonStream( body: ChatCompletionCreateParamsNonStreaming, signal: AbortSignal, ): Promise { - const response = await this.openai.chat.completions.create(body, { - signal, - }); + const response = await this.openai.chat.completions.create( + this.modifyChatBody(body), + { + signal, + }, + ); return response; } async *chatCompletionStream( body: ChatCompletionCreateParamsStreaming, signal: AbortSignal, ): AsyncGenerator { - const response = await this.openai.chat.completions.create(body, { - signal, - }); + const response = await this.openai.chat.completions.create( + this.modifyChatBody(body), + { + signal, + }, + ); for await (const result of response) { yield result; } From 87f94b32330169b87993d5590221d5eac29265c2 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 31 Dec 2024 19:05:48 -0500 Subject: [PATCH 04/50] export LLMConfig type --- packages/openai-adapters/package.json | 2 +- packages/openai-adapters/src/index.ts | 1 + packages/openai-adapters/src/types.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/openai-adapters/package.json b/packages/openai-adapters/package.json index a3d0bf7d0..e075e8e9a 100644 --- a/packages/openai-adapters/package.json +++ b/packages/openai-adapters/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/openai-adapters", - "version": "1.0.10", + "version": "1.0.12", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index c3db18bcf..37f792265 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -101,3 +101,4 @@ export { // export export type { BaseLlmApi } from "./apis/base.js"; +export type { LLMConfig } from "./types.js"; diff --git a/packages/openai-adapters/src/types.ts b/packages/openai-adapters/src/types.ts index fbb21e2e0..4de096210 100644 --- a/packages/openai-adapters/src/types.ts +++ b/packages/openai-adapters/src/types.ts @@ -53,6 +53,7 @@ export const OpenAIConfigSchema = BasePlusConfig.extend({ z.literal("text-gen-webui"), z.literal("vllm"), z.literal("x-ai"), + z.literal("scaleway"), ]), }); export type OpenAIConfig = z.infer; From 5caf3e669175f87dae4dc47250dcd1a897d0ceec Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 31 Dec 2024 19:29:13 -0500 Subject: [PATCH 05/50] fix autocomplete through platform --- core/config/yaml/loadYaml.ts | 4 +++- core/llm/llms/OpenAI.ts | 8 ++++++++ core/llm/llms/stubs/ContinueProxy.ts | 25 ++++++++----------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 77b858630..2d79f826c 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -146,7 +146,9 @@ async function configYamlToContinueConfig( platformConfigMetadata, ); continueConfig.models.push(...llms); - } else if (model.roles?.includes("autocomplete")) { + } + + if (model.roles?.includes("autocomplete")) { // Autocomplete models array const llms = await llmsFromModelConfig( model, diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index aa7d81917..506069217 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -113,6 +113,10 @@ class OpenAI extends BaseLLM { }; } + protected extraBodyProperties(): Record { + return {}; + } + protected getMaxStopWords(): number { const url = new URL(this.apiBase!); @@ -271,6 +275,7 @@ class OpenAI extends BaseLLM { body: JSON.stringify({ ...args, stream: true, + ...this.extraBodyProperties(), }), signal, }); @@ -316,6 +321,7 @@ class OpenAI extends BaseLLM { // We call it toolCalls, they call it tool_calls tool_calls: m.toolCalls, tool_call_id: m.toolCallId, + ...this.extraBodyProperties(), })) as any; const response = await this.fetch(this._getEndpoint("chat/completions"), { method: "POST", @@ -359,6 +365,7 @@ class OpenAI extends BaseLLM { presence_penalty: options.presencePenalty, stop: options.stop, stream: true, + ...this.extraBodyProperties(), }), headers: { "Content-Type": "application/json", @@ -405,6 +412,7 @@ class OpenAI extends BaseLLM { body: JSON.stringify({ input: chunks, model: this.model, + ...this.extraBodyProperties(), }), headers: { Authorization: `Bearer ${this.apiKey}`, diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index f98e2d739..59d05b115 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -2,13 +2,7 @@ import { ControlPlaneProxyInfo } from "../../../control-plane/analytics/IAnalyti import { Telemetry } from "../../../util/posthog.js"; import OpenAI from "../OpenAI.js"; -import { ChatCompletionCreateParams } from "@continuedev/openai-adapters"; -import type { - ChatMessage, - Chunk, - CompletionOptions, - LLMOptions, -} from "../../../index.js"; +import type { Chunk, LLMOptions } from "../../../index.js"; class ContinueProxy extends OpenAI { set controlPlaneProxyInfo(value: ControlPlaneProxyInfo) { @@ -33,17 +27,14 @@ class ContinueProxy extends OpenAI { useLegacyCompletionsEndpoint: false, }; - protected _convertArgs( - options: CompletionOptions, - messages: ChatMessage[], - ): ChatCompletionCreateParams { - const args: any = super._convertArgs(options, messages); - args.continueProperties = { - apiKey: this.actualApiKey, - apiBase: this.actualApiBase, - apiKeySecret: this.apiKeySecret, + protected extraBodyProperties(): Record { + return { + continueProperties: { + apiKey: this.actualApiKey, + apiBase: this.actualApiBase, + apiKeySecret: this.apiKeySecret, + }, }; - return args; } protected _getHeaders() { From 8915a53321f6d738afeb920d769ceb2c75f1e156 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 2 Jan 2025 09:20:15 -0500 Subject: [PATCH 06/50] fix chat extra body properties --- core/llm/llms/OpenAI.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 506069217..59eb28575 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -321,12 +321,14 @@ class OpenAI extends BaseLLM { // We call it toolCalls, they call it tool_calls tool_calls: m.toolCalls, tool_call_id: m.toolCallId, - ...this.extraBodyProperties(), })) as any; const response = await this.fetch(this._getEndpoint("chat/completions"), { method: "POST", headers: this._getHeaders(), - body: JSON.stringify(body), + body: JSON.stringify({ + ...body, + ...this.extraBodyProperties(), + }), signal, }); From fcdc63efda1ff994edb5094031b5484b491741ef Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 5 Jan 2025 22:46:24 -0500 Subject: [PATCH 07/50] configJson to configYaml converter --- packages/config-yaml/package-lock.json | 19 ++- packages/config-yaml/package.json | 5 +- packages/config-yaml/src/converter.ts | 141 ++++++++++++++++++++++ packages/config-yaml/src/index.ts | 1 + packages/config-yaml/src/schemas/index.ts | 2 + 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 packages/config-yaml/src/converter.ts diff --git a/packages/config-yaml/package-lock.json b/packages/config-yaml/package-lock.json index 28126b962..b9399a7a6 100644 --- a/packages/config-yaml/package-lock.json +++ b/packages/config-yaml/package-lock.json @@ -1,14 +1,15 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.0", + "version": "1.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/config-yaml", - "version": "1.0.0", + "version": "1.0.7", "license": "Apache-2.0", "dependencies": { + "@continuedev/config-types": "file:../config-types", "yaml": "^2.6.1", "zod": "^3.23.8" }, @@ -18,6 +19,16 @@ "ts-node": "^10.9.2" } }, + "../config-types": { + "version": "1.0.13", + "license": "Apache-2.0", + "dependencies": { + "zod": "^3.23.8" + }, + "devDependencies": { + "typescript": "^5.5.2" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -575,6 +586,10 @@ "dev": true, "peer": true }, + "node_modules/@continuedev/config-types": { + "resolved": "../config-types", + "link": true + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/packages/config-yaml/package.json b/packages/config-yaml/package.json index d3e096605..101b25f06 100644 --- a/packages/config-yaml/package.json +++ b/packages/config-yaml/package.json @@ -1,6 +1,6 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.4", + "version": "1.0.8", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -13,7 +13,8 @@ "license": "Apache-2.0", "dependencies": { "yaml": "^2.6.1", - "zod": "^3.23.8" + "zod": "^3.23.8", + "@continuedev/config-types": "file:../config-types" }, "devDependencies": { "cross-env": "^7.0.3", diff --git a/packages/config-yaml/src/converter.ts b/packages/config-yaml/src/converter.ts new file mode 100644 index 000000000..d1a017efc --- /dev/null +++ b/packages/config-yaml/src/converter.ts @@ -0,0 +1,141 @@ +import { ConfigJson } from "@continuedev/config-types"; +import { ConfigYaml } from "./schemas/index.js"; +import { ModelRoles } from "./schemas/models.js"; + +type ModelYaml = NonNullable[number]; +type ContextYaml = NonNullable[number]; +type PromptYaml = NonNullable[number]; + +function convertModel( + m: ConfigJson["models"][number], + roles: ModelRoles[], +): ModelYaml { + return { + name: m.title, + provider: m.provider, + model: m.model, + apiKey: m.apiKey, + apiBase: m.apiBase, + roles, + requestOptions: m.requestOptions, + defaultCompletionOptions: m.completionOptions, + }; +} + +function convertEmbeddingsProvider( + m: NonNullable, +): ModelYaml { + return { + name: "Embeddings Model", + provider: m.provider, + model: m.model ?? "", + apiKey: m.apiKey, + apiBase: m.apiBase, + roles: ["embed"], + }; +} + +function convertReranker(m: NonNullable): ModelYaml { + return { + name: "Reranker", + provider: m.name, + model: m.params?.model ?? "", + apiKey: m.params?.apiKey, + apiBase: m.params?.apiBase, + roles: ["rerank"], + }; +} + +function convertContext(configJson: ConfigJson): ContextYaml[] { + const context: ContextYaml[] = + configJson.contextProviders?.map((ctx) => { + return { + uses: `builtin/${ctx.name}`, + with: ctx.params, + }; + }) ?? []; + + return context; +} + +function convertCustomCommand( + cmd: NonNullable[number], +): PromptYaml { + return { + name: cmd.name, + description: cmd.description, + prompt: (cmd as any).prompt, // The type is wrong in @continuedev/config-types + type: "slash-command", + }; +} + +function convertMcp(mcp: any): NonNullable[number] { + const { transport } = mcp; + const { command, args, env } = transport; + + return { + command, + args, + env, + name: "MCP Server", + }; +} + +function convertDoc(doc: NonNullable[number]): any { + // NonNullable[number] + return { + title: doc.title, + startUrl: doc.startUrl, + rootUrl: doc.rootUrl, + faviconUrl: doc.faviconUrl, + }; +} + +export function convertJsonToYamlConfig(configJson: ConfigJson): ConfigYaml { + // models + const models = configJson.models.map((m) => convertModel(m, ["chat"])); + const autocompleteModels = Array.isArray(configJson.tabAutocompleteModel) + ? configJson.tabAutocompleteModel + : configJson.tabAutocompleteModel + ? [configJson.tabAutocompleteModel] + : []; + models.push( + ...autocompleteModels.map((m) => convertModel(m, ["autocomplete"])), + ); + + if (configJson.embeddingsProvider) { + models.push(convertEmbeddingsProvider(configJson.embeddingsProvider)); + } + + if (configJson.reranker) { + models.push(convertReranker(configJson.reranker)); + } + + // context + const context = convertContext(configJson); + + // mcpServers + // Types for "experimental" don't exist + const mcpServers = ( + configJson as any + ).experimental?.modelContextProtocolServers?.map(convertMcp); + + // prompts + const prompts = configJson.customCommands?.map(convertCustomCommand); + + // docs + const docs = configJson.docs?.map(convertDoc); + + const configYaml: ConfigYaml = { + name: "Continue Config", + version: "0.0.1", + models, + context, + rules: configJson.systemMessage, + prompts, + mcpServers, + // docs + }; + + return configYaml; +} diff --git a/packages/config-yaml/src/index.ts b/packages/config-yaml/src/index.ts index 5056af49d..c2ebe8254 100644 --- a/packages/config-yaml/src/index.ts +++ b/packages/config-yaml/src/index.ts @@ -91,6 +91,7 @@ export function fillTemplateVariables( }); } +export { convertJsonToYamlConfig } from "./converter.js"; export { ConfigYaml, configYamlSchema } from "./schemas/index.js"; export type { ModelConfig } from "./schemas/models.js"; export { validateConfigYaml } from "./validation.js"; diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index 03cfe8149..407ee1eb1 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -6,6 +6,7 @@ import { modelSchema } from "./models.js"; const packageSchema = z.object({ uses: z.string(), with: z.any().optional(), + secrets: z.array(z.string()).optional(), }); const toolSchema = z.object({ @@ -33,6 +34,7 @@ const promptSchema = z.object({ export const configYamlSchema = z.object({ name: z.string(), + version: z.string(), packages: z.array(packageSchema).optional(), models: z.array(modelSchema).optional(), context: z.array(contextSchema).optional(), From af3e2f3154881db1b8703a5dfb8f855ba9b9c01a Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 5 Jan 2025 22:49:33 -0500 Subject: [PATCH 08/50] add docs to configYaml schema --- packages/config-yaml/src/converter.ts | 9 +++++---- packages/config-yaml/src/schemas/index.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/config-yaml/src/converter.ts b/packages/config-yaml/src/converter.ts index d1a017efc..14a60eecd 100644 --- a/packages/config-yaml/src/converter.ts +++ b/packages/config-yaml/src/converter.ts @@ -81,10 +81,11 @@ function convertMcp(mcp: any): NonNullable[number] { }; } -function convertDoc(doc: NonNullable[number]): any { - // NonNullable[number] +function convertDoc( + doc: NonNullable[number], +): NonNullable[number] { return { - title: doc.title, + name: doc.title, startUrl: doc.startUrl, rootUrl: doc.rootUrl, faviconUrl: doc.faviconUrl, @@ -134,7 +135,7 @@ export function convertJsonToYamlConfig(configJson: ConfigJson): ConfigYaml { rules: configJson.systemMessage, prompts, mcpServers, - // docs + docs, }; return configYaml; diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index 407ee1eb1..75018bb25 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -32,6 +32,13 @@ const promptSchema = z.object({ prompt: z.string(), }); +const docSchema = z.object({ + name: z.string(), + startUrl: z.string(), + rootUrl: z.string().optional(), + faviconUrl: z.string().optional(), +}); + export const configYamlSchema = z.object({ name: z.string(), version: z.string(), @@ -43,6 +50,7 @@ export const configYamlSchema = z.object({ mcpServers: z.array(mcpServerSchema).optional(), rules: z.string().optional(), prompts: z.array(promptSchema).optional(), + docs: z.array(docSchema).optional(), }); export type ConfigYaml = z.infer; From b01a97ebefa21bbf0c39455acd1bcc665b82fcd0 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 6 Jan 2025 16:09:42 -0800 Subject: [PATCH 09/50] useOnboarding in getControlPlaneSessionInfo --- core/control-plane/env.ts | 3 + core/core.ts | 7 ++- core/protocol/ide.ts | 2 +- .../vscode/src/extension/VsCodeExtension.ts | 2 +- .../vscode/src/extension/VsCodeMessenger.ts | 5 +- .../vscode/src/stubs/WorkOsAuthProvider.ts | 60 ++++++++++++------- gui/src/components/AccountDialog.tsx | 6 +- gui/src/context/Auth.tsx | 16 +++-- 8 files changed, 65 insertions(+), 36 deletions(-) diff --git a/core/control-plane/env.ts b/core/control-plane/env.ts index 4556ce90f..3c3697ee5 100644 --- a/core/control-plane/env.ts +++ b/core/control-plane/env.ts @@ -48,3 +48,6 @@ export const controlPlaneEnv = : process.env.CONTROL_PLANE_ENV === "staging" ? STAGING_ENV : PRODUCTION_ENV; + +export const USE_PLATFORM = + process.env.CONTROL_PLANE_ENV === "local" ? true : false; diff --git a/core/core.ts b/core/core.ts index 14389910c..b7da406ae 100644 --- a/core/core.ts +++ b/core/core.ts @@ -2,6 +2,7 @@ import path from "path"; import { fetchwithRequestOptions } from "@continuedev/fetch"; import ignore from "ignore"; +import * as URI from "uri-js"; import { v4 as uuidv4 } from "uuid"; import { CompletionProvider } from "./autocomplete/CompletionProvider"; @@ -40,10 +41,9 @@ import { getSymbolsForManyFiles } from "./util/treeSitter"; import { TTS } from "./util/tts"; import { type ContextItemId, type IDE, type IndexingProgressUpdate } from "."; -import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; - -import * as URI from "uri-js"; import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile"; +import { USE_PLATFORM } from "./control-plane/env"; +import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./protocol/messenger"; import { localPathToUri } from "./util/pathToUri"; @@ -102,6 +102,7 @@ export class Core { const ideSettingsPromise = messenger.request("getIdeSettings", undefined); const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", { silent: true, + useOnboarding: USE_PLATFORM, }); this.controlPlaneClient = new ControlPlaneClient(sessionInfoPromise); diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index 4df3cb95b..1f73f1082 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -91,7 +91,7 @@ export type ToIdeFromWebviewOrCoreProtocol = { getGitHubAuthToken: [GetGhTokenArgs, string | undefined]; getControlPlaneSessionInfo: [ - { silent: boolean }, + { silent: boolean; useOnboarding: boolean }, ControlPlaneSessionInfo | undefined, ]; logoutOfControlPlane: [undefined, void]; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 4ff02a736..19dfdb3be 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -301,7 +301,7 @@ export class VsCodeExtension { true, ); - const sessionInfo = await getControlPlaneSessionInfo(true); + const sessionInfo = await getControlPlaneSessionInfo(true, false); this.webviewProtocolPromise.then(async (webviewProtocol) => { void webviewProtocol.request("didChangeControlPlaneSessionInfo", { sessionInfo, diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 52238cc1e..6afb2bd1a 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -447,7 +447,10 @@ export class VsCodeMessenger { ide.getGitHubAuthToken(msg.data), ); this.onWebviewOrCore("getControlPlaneSessionInfo", async (msg) => { - return getControlPlaneSessionInfo(msg.data.silent); + return getControlPlaneSessionInfo( + msg.data.silent, + msg.data.useOnboarding, + ); }); this.onWebviewOrCore("logoutOfControlPlane", async (msg) => { const sessions = await this.workOsAuthProvider.getSessions(); diff --git a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts index 486b0df12..a784a2a1f 100644 --- a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts +++ b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts @@ -163,12 +163,6 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { } get ideRedirectUri() { - const publisher = this.context.extension.packageJSON.publisher; - const name = this.context.extension.packageJSON.name; - return `${env.uriScheme}://${publisher}.${name}`; - } - - get redirectUri() { if ( env.uriScheme === "vscode-insiders" || env.uriScheme === "vscode" || @@ -179,6 +173,18 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { url.pathname = `/auth/${env.uriScheme}-redirect`; return url.toString(); } + const publisher = this.context.extension.packageJSON.publisher; + const name = this.context.extension.packageJSON.name; + return `${env.uriScheme}://${publisher}.${name}`; + } + + public static useOnboardingUri: boolean = false; + get redirectUri() { + if (WorkOsAuthProvider.useOnboardingUri) { + const url = new URL(controlPlaneEnv.APP_URL); + url.pathname = `/onboarding/redirect/${env.uriScheme}`; + return url.toString(); + } return this.ideRedirectUri; } @@ -407,8 +413,9 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { try { return await Promise.race([ codeExchangePromise.promise, - new Promise((_, reject) => - setTimeout(() => reject("Cancelled"), 15 * 60 * 1_000), + new Promise( + (_, reject) => + setTimeout(() => reject("Cancelled"), 60 * 60 * 1_000), // 60min timeout ), promiseFromEvent( token.onCancellationRequested, @@ -488,20 +495,29 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { export async function getControlPlaneSessionInfo( silent: boolean, + useOnboarding: boolean, ): Promise { - const session = await authentication.getSession( - controlPlaneEnv.AUTH_TYPE, - [], - silent ? { silent: true } : { createIfNone: true }, - ); - if (!session) { - return undefined; + try { + if (useOnboarding) { + WorkOsAuthProvider.useOnboardingUri = true; + } + + const session = await authentication.getSession( + controlPlaneEnv.AUTH_TYPE, + [], + silent ? { silent: true } : { createIfNone: true }, + ); + if (!session) { + return undefined; + } + return { + accessToken: session.accessToken, + account: { + id: session.account.id, + label: session.account.label, + }, + }; + } finally { + WorkOsAuthProvider.useOnboardingUri = false; } - return { - accessToken: session.accessToken, - account: { - id: session.account.id, - label: session.account.label, - }, - }; } diff --git a/gui/src/components/AccountDialog.tsx b/gui/src/components/AccountDialog.tsx index c55520574..2b8e17ae4 100644 --- a/gui/src/components/AccountDialog.tsx +++ b/gui/src/components/AccountDialog.tsx @@ -1,6 +1,7 @@ import { Listbox, Transition } from "@headlessui/react"; import { ChevronUpDownIcon } from "@heroicons/react/24/outline"; import { Fragment, useContext } from "react"; +import { useDispatch } from "react-redux"; import styled from "styled-components"; import { Button, @@ -9,10 +10,9 @@ import { vscListActiveBackground, vscListActiveForeground, } from "."; -import { IdeMessengerContext } from "../context/IdeMessenger"; import { useAuth } from "../context/Auth"; +import { IdeMessengerContext } from "../context/IdeMessenger"; import { setSelectedProfileId } from "../redux/slices/sessionSlice"; -import { useDispatch } from "react-redux"; import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; const StyledListboxOption = styled(Listbox.Option)<{ selected: boolean }>` @@ -46,7 +46,7 @@ export default function AccountDialog() { Signed out - diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index b00c30929..ca5d4f207 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -20,7 +20,7 @@ import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { session: ControlPlaneSessionInfo | undefined; logout: () => void; - login: () => void; + login: (useOnboarding: boolean) => void; selectedProfile: ProfileDescription | undefined; profiles: ProfileDescription[]; controlServerBetaEnabled: boolean; @@ -49,9 +49,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ (state) => state.misc.lastControlServerBetaEnabledStatus, ); - const login = () => { + const login = (useOnboarding: boolean) => { ideMessenger - .request("getControlPlaneSessionInfo", { silent: false }) + .request("getControlPlaneSessionInfo", { + silent: false, + useOnboarding, + }) .then((result) => { if (result.status === "error") { return; @@ -102,12 +105,15 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }); useWebviewListener("signInToControlPlane", async () => { - login(); + login(false); }); useEffect(() => { ideMessenger - .request("getControlPlaneSessionInfo", { silent: true }) + .request("getControlPlaneSessionInfo", { + silent: true, + useOnboarding: false, + }) .then( (result) => result.status === "success" && setSession(result.content), ); From a57b5efa26bf8ff192cedc32403b636cfc9b65f7 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 7 Jan 2025 10:47:10 -0800 Subject: [PATCH 10/50] platform onboarding card --- core/control-plane/env.ts | 3 - core/control-plane/flags.ts | 1 + core/core.ts | 2 +- .../platform/PlatformOnboardingCard.tsx | 63 +++++++++++++++++++ .../OnboardingCard/platform/tabs/local.tsx | 26 ++++++++ .../OnboardingCard/platform/tabs/main.tsx | 46 ++++++++++++++ gui/src/pages/gui/Chat.tsx | 10 ++- 7 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 core/control-plane/flags.ts create mode 100644 gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx create mode 100644 gui/src/components/OnboardingCard/platform/tabs/local.tsx create mode 100644 gui/src/components/OnboardingCard/platform/tabs/main.tsx diff --git a/core/control-plane/env.ts b/core/control-plane/env.ts index 3c3697ee5..4556ce90f 100644 --- a/core/control-plane/env.ts +++ b/core/control-plane/env.ts @@ -48,6 +48,3 @@ export const controlPlaneEnv = : process.env.CONTROL_PLANE_ENV === "staging" ? STAGING_ENV : PRODUCTION_ENV; - -export const USE_PLATFORM = - process.env.CONTROL_PLANE_ENV === "local" ? true : false; diff --git a/core/control-plane/flags.ts b/core/control-plane/flags.ts new file mode 100644 index 000000000..3ea598e3b --- /dev/null +++ b/core/control-plane/flags.ts @@ -0,0 +1 @@ +export const USE_PLATFORM = true; diff --git a/core/core.ts b/core/core.ts index b7da406ae..c7bdcf02a 100644 --- a/core/core.ts +++ b/core/core.ts @@ -42,7 +42,7 @@ import { TTS } from "./util/tts"; import { type ContextItemId, type IDE, type IndexingProgressUpdate } from "."; import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile"; -import { USE_PLATFORM } from "./control-plane/env"; +import { USE_PLATFORM } from "./control-plane/flags"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./protocol/messenger"; import { localPathToUri } from "./util/pathToUri"; diff --git a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx new file mode 100644 index 000000000..360282e4a --- /dev/null +++ b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx @@ -0,0 +1,63 @@ +import { XMarkIcon } from "@heroicons/react/24/outline"; +import { useState } from "react"; +import styled from "styled-components"; +import { CloseButton, defaultBorderRadius, vscInputBackground } from "../.."; +import { getLocalStorage, setLocalStorage } from "../../../util/localStorage"; +import Alert from "../../gui/Alert"; +import { TabTitle } from "../components/OnboardingCardTabs"; +import { useOnboardingCard } from "../hooks"; +import OnboardingLocalTab from "../tabs/OnboardingLocalTab"; +import MainTab from "./tabs/main"; + +const StyledCard = styled.div` + margin: auto; + border-radius: ${defaultBorderRadius}; + background-color: ${vscInputBackground}; + box-shadow: + 0 20px 25px -5px rgb(0 0 0 / 0.1), + 0 8px 10px -6px rgb(0 0 0 / 0.1); +`; + +export interface OnboardingCardState { + show?: boolean; + activeTab?: TabTitle; +} + +export function PlatformOnboardingCard() { + const onboardingCard = useOnboardingCard(); + + if (getLocalStorage("onboardingStatus") === undefined) { + setLocalStorage("onboardingStatus", "Started"); + } + + const [currentTab, setCurrentTab] = useState<"main" | "local">("main"); + + return ( + + + + +
+
+ {currentTab === "main" ? ( + setCurrentTab("local")} /> + ) : ( +
+ + By choosing this option, Continue will be configured by a local{" "} + config.yaml file. If you're just looking to use + Ollama and still want to manage your configuration through + Continue, click{" "} + setCurrentTab("main")}> + here + + + + +
+ )} +
+
+
+ ); +} diff --git a/gui/src/components/OnboardingCard/platform/tabs/local.tsx b/gui/src/components/OnboardingCard/platform/tabs/local.tsx new file mode 100644 index 000000000..ae30085ec --- /dev/null +++ b/gui/src/components/OnboardingCard/platform/tabs/local.tsx @@ -0,0 +1,26 @@ +import { useAuth } from "../../../../context/Auth"; +import ContinueLogo from "../../../gui/ContinueLogo"; +import { useOnboardingCard } from "../../hooks"; + +export default function LocalTab() { + const onboardingCard = useOnboardingCard(); + const auth = useAuth(); + + return ( +
+
+ +
+ +

+ Log in to quickly build your first custom AI code assistant +

+ + {/*

+ To prevent abuse, we'll ask you to sign in to GitHub. +

*/} + +
+
+ ); +} diff --git a/gui/src/components/OnboardingCard/platform/tabs/main.tsx b/gui/src/components/OnboardingCard/platform/tabs/main.tsx new file mode 100644 index 000000000..4295dd18d --- /dev/null +++ b/gui/src/components/OnboardingCard/platform/tabs/main.tsx @@ -0,0 +1,46 @@ +import { ChevronRightIcon } from "@heroicons/react/24/outline"; +import { Button, ButtonSubtext } from "../../.."; +import { useAuth } from "../../../../context/Auth"; +import ContinueLogo from "../../../gui/ContinueLogo"; +import { useOnboardingCard } from "../../hooks"; + +export default function MainTab({ + onRemainLocal, +}: { + onRemainLocal: () => void; +}) { + const onboardingCard = useOnboardingCard(); + const auth = useAuth(); + + function onGetStarted() { + auth.login(true); + onboardingCard.close(); + } + + return ( +
+
+ +
+ +

+ Log in to quickly build your first custom AI code assistant +

+ +
+ + +
+ Or, remain local + +
+
+
+
+ ); +} diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index de8453445..4ab0d7997 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -6,6 +6,7 @@ import { } from "@heroicons/react/24/outline"; import { Editor, JSONContent } from "@tiptap/react"; import { InputModifiers, RangeInFileWithContents, ToolCallState } from "core"; +import { USE_PLATFORM } from "core/control-plane/flags"; import { streamResponse } from "core/llm/stream"; import { stripImages } from "core/util/messageContent"; import { usePostHog } from "posthog-js/react"; @@ -32,6 +33,7 @@ import { OnboardingCard, useOnboardingCard, } from "../../components/OnboardingCard"; +import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard"; import PageHeader from "../../components/PageHeader"; import StepContainer from "../../components/StepContainer"; import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons"; @@ -57,6 +59,7 @@ import { import { RootState } from "../../redux/store"; import { cancelStream } from "../../redux/thunks/cancelStream"; import { exitEditMode } from "../../redux/thunks/exitEditMode"; +import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { getFontSize, @@ -70,7 +73,6 @@ import ConfigErrorIndicator from "./ConfigError"; import { ToolCallDiv } from "./ToolCallDiv"; import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv"; import ToolOutput from "./ToolCallDiv/ToolOutput"; -import { loadLastSession } from "../../redux/thunks/session"; const StopButton = styled.div` background-color: ${vscBackground}; @@ -540,7 +542,11 @@ export function Chat() { <> {onboardingCard.show && (
- + {USE_PLATFORM ? ( + + ) : ( + + )}
)} From 3acffa445c071bc855df60383e8610eac3150615 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 7 Jan 2025 17:22:19 -0800 Subject: [PATCH 11/50] assistants toggle --- gui/package-lock.json | 8 +- gui/package.json | 2 +- gui/src/components/index.ts | 7 +- gui/src/components/mainInput/InputToolbar.tsx | 4 +- .../InputToolbar/PopoverTransition.tsx | 26 +++ .../InputToolbar/ToggleToolsButton.tsx | 21 +-- .../components/modelSelection/ModelSelect.tsx | 20 +-- .../platform/AssistantAndModelSelect.tsx | 162 ++++++++++++++++++ .../platform/AssistantSelect.tsx | 85 +++++++++ .../modelSelection/platform/ModelSelect.tsx | 121 +++++++++++++ .../modelSelection/platform/shared.tsx | 113 ++++++++++++ gui/src/context/Auth.tsx | 14 +- gui/src/redux/slices/configSlice.ts | 22 ++- gui/src/redux/slices/sessionSlice.ts | 43 ++++- 14 files changed, 602 insertions(+), 46 deletions(-) create mode 100644 gui/src/components/mainInput/InputToolbar/PopoverTransition.tsx create mode 100644 gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx create mode 100644 gui/src/components/modelSelection/platform/AssistantSelect.tsx create mode 100644 gui/src/components/modelSelection/platform/ModelSelect.tsx create mode 100644 gui/src/components/modelSelection/platform/shared.tsx diff --git a/gui/package-lock.json b/gui/package-lock.json index a1e4cbb66..a6d1a60d4 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -7,7 +7,7 @@ "name": "gui", "license": "Apache-2.0", "dependencies": { - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.7", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", @@ -546,9 +546,9 @@ "dev": true }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.0.tgz", - "integrity": "sha512-NwagzzpnPLbMC3delzFSjWiFv5fp8ReFjdMQF0ko0Xg+U0Myja90k/J7JWGegF/SZMABxc/OJchElJFr58TwGA==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.7.tgz", + "integrity": "sha512-qng9yj5m54b5UHfdTYBM+rEINWs+S+IOm/dzm/PMlmz3CmpRt3OiBZaHLl/iYRCSB4xeOqFKoBPird58sxQ8YA==", "dependencies": { "yaml": "^2.6.1", "zod": "^3.23.8" diff --git a/gui/package.json b/gui/package.json index d0150d999..3e6b910d7 100644 --- a/gui/package.json +++ b/gui/package.json @@ -15,7 +15,7 @@ "test:watch": "vitest" }, "dependencies": { - "@continuedev/config-yaml": "^1.0.0", + "@continuedev/config-yaml": "^1.0.7", "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index 95e178480..071900b51 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -1,4 +1,4 @@ -import styled, { keyframes } from "styled-components"; +import styled from "styled-components"; import { getFontSize, isJetBrains } from "../util"; export const VSC_INPUT_BACKGROUND_VAR = "--vscode-input-background"; @@ -298,11 +298,6 @@ export const HeaderButton = styled.button<{ padding: 2px; `; -export const Divider = styled.div` - height: 1px; - background-color: ${lightGray}; -`; - export const StyledActionButton = styled.div` display: flex; justify-content: space-between; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 93b437fdc..23e62f07e 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -1,5 +1,6 @@ import { AtSymbolIcon, PhotoIcon } from "@heroicons/react/24/outline"; import { InputModifiers } from "core"; +import { USE_PLATFORM } from "core/control-plane/flags"; import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect"; import { useRef } from "react"; import styled from "styled-components"; @@ -26,6 +27,7 @@ import { } from "../../util"; import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; +import AssistantAndModelSelect from "../modelSelection/platform/AssistantAndModelSelect"; import HoverItem from "./InputToolbar/HoverItem"; import ToggleToolsButton from "./InputToolbar/ToggleToolsButton"; @@ -114,7 +116,7 @@ function InputToolbar(props: InputToolbarProps) { className="find-widget-skip flex" >
- + {USE_PLATFORM ? : }
{props.toolbarOptions?.hideImageUpload || (supportsImages && ( diff --git a/gui/src/components/mainInput/InputToolbar/PopoverTransition.tsx b/gui/src/components/mainInput/InputToolbar/PopoverTransition.tsx new file mode 100644 index 000000000..24b64c27b --- /dev/null +++ b/gui/src/components/mainInput/InputToolbar/PopoverTransition.tsx @@ -0,0 +1,26 @@ +import { Transition } from "@headlessui/react"; + +export default function PopoverTransition({ + children, + show, + afterLeave, +}: { + children: React.ReactNode; + show?: boolean; + afterLeave?: () => void; +}) { + return ( + + {children} + + ); +} diff --git a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx b/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx index 9dae27363..cb6a05666 100644 --- a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx +++ b/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx @@ -1,4 +1,4 @@ -import { Listbox, Transition } from "@headlessui/react"; +import { Listbox } from "@headlessui/react"; import { EllipsisHorizontalCircleIcon as EllipsisHorizontalIcon, WrenchScrewdriverIcon as WrenchScrewdriverIconOutline, @@ -6,15 +6,14 @@ import { import { WrenchScrewdriverIcon as WrenchScrewdriverIconSolid } from "@heroicons/react/24/solid"; import { useEffect, useRef, useState } from "react"; import { useDispatch } from "react-redux"; -import styled from "styled-components"; -import { defaultBorderRadius, lightGray, vscForeground } from "../.."; +import { lightGray, vscForeground } from "../.."; +import { useAppSelector } from "../../../redux/hooks"; import { toggleUseTools } from "../../../redux/slices/uiSlice"; -import { getFontSize } from "../../../util"; +import { ToolTip } from "../../gui/Tooltip"; import InfoHover from "../../InfoHover"; import HoverItem from "./HoverItem"; +import PopoverTransition from "./PopoverTransition"; import ToolDropdownItem from "./ToolDropdownItem"; -import { useAppSelector } from "../../../redux/hooks"; -import { ToolTip } from "../../gui/Tooltip"; export default function ToolDropdown() { const buttonRef = useRef(null); @@ -87,14 +86,8 @@ export default function ToolDropdown() { > - setDropdownOpen(false)} > - + )} diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index c5edb5d7b..f70d2c96e 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -7,16 +7,16 @@ import { TrashIcon, } from "@heroicons/react/24/outline"; import { useContext, useEffect, useRef, useState } from "react"; -import { useDispatch, useSelector } from "react-redux"; +import { useDispatch } from "react-redux"; import styled from "styled-components"; -import { - defaultBorderRadius, - Divider, - lightGray, - vscInputBackground, -} from ".."; +import { defaultBorderRadius, lightGray, vscInputBackground } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; +import { useAppSelector } from "../../redux/hooks"; +import { + selectDefaultModel, + setDefaultModel, +} from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { getFontSize, @@ -24,11 +24,7 @@ import { isMetaEquivalentKeyPressed, } from "../../util"; import ConfirmationDialog from "../dialogs/ConfirmationDialog"; -import { useAppSelector } from "../../redux/hooks"; -import { - selectDefaultModel, - setDefaultModel, -} from "../../redux/slices/configSlice"; +import { Divider } from "./platform/shared"; interface ModelOptionProps { option: Option; diff --git a/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx b/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx new file mode 100644 index 000000000..955f770f9 --- /dev/null +++ b/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx @@ -0,0 +1,162 @@ +import { Popover } from "@headlessui/react"; +import { ChevronDownIcon } from "@heroicons/react/24/outline"; +import { useEffect, useRef, useState } from "react"; +import { useDispatch } from "react-redux"; +import styled from "styled-components"; +import { defaultBorderRadius, lightGray, vscInputBackground } from "../.."; +import AddModelForm from "../../../forms/AddModelForm"; +import { useAppSelector } from "../../../redux/hooks"; +import { + cycleDefaultModel, + selectDefaultModel, +} from "../../../redux/slices/configSlice"; +import { cycleSelectedProfileId } from "../../../redux/slices/sessionSlice"; +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; +import { getFontSize, isMetaEquivalentKeyPressed } from "../../../util"; +import PopoverTransition from "../../mainInput/InputToolbar/PopoverTransition"; +import { AssistantSelect } from "./AssistantSelect"; +import { ModelSelect, modelSelectTitle } from "./ModelSelect"; +import { MAX_HEIGHT_PX } from "./shared"; + +const StyledPopoverButton = styled(Popover.Button)` + font-family: inherit; + display: flex; + align-items: center; + gap: 2px; + border: none; + cursor: pointer; + font-size: ${getFontSize() - 2}px; + background: transparent; + color: ${lightGray}; + &:focus { + outline: none; + } +`; + +const StyledPopoverPanel = styled(Popover.Panel)<{ $showabove: boolean }>` + margin-top: 4px; + position: absolute; + padding: 0px; + cursor: default; + + display: flex; + flex-direction: row; + + border-radius: ${defaultBorderRadius}; + border: 0.5px solid ${lightGray}; + background-color: ${vscInputBackground}; + + ${(props) => (props.$showabove ? "bottom: 100%;" : "top: 100%;")} +`; + +function AssistantAndModelSelect() { + const dispatch = useDispatch(); + const defaultModel = useAppSelector(selectDefaultModel); + const [showAbove, setShowAbove] = useState(false); + const buttonRef = useRef(null); + const selectedProfileId = useAppSelector( + (store) => store.session.selectedProfileId, + ); + + useEffect(() => { + const handleResize = () => calculatePosition(); + window.addEventListener("resize", handleResize); + return () => window.removeEventListener("resize", handleResize); + }, []); + + function calculatePosition() { + if (!buttonRef.current) { + return; + } + const rect = buttonRef.current.getBoundingClientRect(); + const spaceBelow = window.innerHeight - rect.bottom; + const spaceAbove = rect.top; + const dropdownHeight = MAX_HEIGHT_PX; + + setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); + } + + function onClickAddModel(e) { + e.stopPropagation(); + e.preventDefault(); + + // Close the dropdown + if (buttonRef.current) { + buttonRef.current.click(); + } + dispatch(setShowDialog(true)); + dispatch( + setDialogMessage( + { + dispatch(setShowDialog(false)); + }} + />, + ), + ); + } + + useEffect(() => { + let lastToggleTime = 0; + const DEBOUNCE_MS = 500; + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "'" && isMetaEquivalentKeyPressed(event as any)) { + const now = Date.now(); + + if (event.shiftKey) { + dispatch(cycleDefaultModel("next")); + } else { + if (now - lastToggleTime >= DEBOUNCE_MS) { + dispatch(cycleSelectedProfileId()); + lastToggleTime = now; + } + } + } + }; + + window.addEventListener("keydown", handleKeyDown); + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, []); + + return ( + +
+ +
+ + {modelSelectTitle(defaultModel) || "Select model"}{" "} + +
+
+ + + + + + +
+
+ ); +} + +export default AssistantAndModelSelect; diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx new file mode 100644 index 000000000..cde44669a --- /dev/null +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -0,0 +1,85 @@ +import { + DocumentIcon, + PlusIcon, + SparklesIcon, +} from "@heroicons/react/24/outline"; +import { useContext } from "react"; +import { useDispatch } from "react-redux"; +import { lightGray } from "../.."; +import { useAuth } from "../../../context/Auth"; +import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { setSelectedProfileId } from "../../../redux/slices/sessionSlice"; +import { getFontSize, getMetaKeyLabel } from "../../../util"; +import { Divider, Option, OptionDiv } from "./shared"; + +interface AssistantSelectProps {} + +export function AssistantSelect(props: AssistantSelectProps) { + const ideMessenger = useContext(IdeMessengerContext); + const { profiles, selectedProfile } = useAuth(); + + const dispatch = useDispatch(); + + const changeProfileId = (id: string) => { + ideMessenger.post("didChangeSelectedProfile", { id }); + dispatch(setSelectedProfileId(id)); + }; + + function onNewAssistant() { + ideMessenger.post("openUrl", "https://app.continue.dev/new"); + } + + return ( +
+ {profiles.map((option, idx) => ( + + ))} + +
+ +
+ + New Assistant +
+
+ + + + + {getMetaKeyLabel()}' toggle assistant + +
+
+ ); +} diff --git a/gui/src/components/modelSelection/platform/ModelSelect.tsx b/gui/src/components/modelSelection/platform/ModelSelect.tsx new file mode 100644 index 000000000..4f1551b6f --- /dev/null +++ b/gui/src/components/modelSelection/platform/ModelSelect.tsx @@ -0,0 +1,121 @@ +import { CubeIcon, PlusIcon } from "@heroicons/react/24/outline"; +import { useContext, useEffect, useState } from "react"; +import { lightGray } from "../.."; +import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; +import { + selectDefaultModel, + setDefaultModel, +} from "../../../redux/slices/configSlice"; +import { getFontSize, getMetaKeyLabel } from "../../../util"; +import { Divider, Option, OptionDiv } from "./shared"; + +export interface ModelOption { + value: string; + title: string; + apiKey?: string; +} + +export function modelSelectTitle(model: any): string { + if (model?.title) return model?.title; + if (model?.model !== undefined && model?.model.trim() !== "") { + if (model?.class_name) { + return `${model?.class_name} - ${model?.model}`; + } + return model?.model; + } + return model?.class_name; +} + +interface ModelSelectProps { + selectedProfileId: string; + onClickAddModel: (e: any) => void; +} + +export function ModelSelect(props: ModelSelectProps) { + const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + const defaultModel = useAppSelector(selectDefaultModel); + const allModels = useAppSelector((state) => state.config.config.models); + const [options, setOptions] = useState([]); + const [sortedOptions, setSortedOptions] = useState([]); + + // Sort so that options without an API key are at the end + useEffect(() => { + const enabledOptions = options.filter((option) => option.apiKey !== ""); + const disabledOptions = options.filter((option) => option.apiKey === ""); + + const sorted = [...enabledOptions, ...disabledOptions]; + + setSortedOptions(sorted); + }, [options]); + + useEffect(() => { + setOptions( + allModels.map((model) => { + return { + value: model.title, + title: modelSelectTitle(model), + apiKey: model.apiKey, + }; + }), + ); + }, [allModels]); + + function onModelChange(modelTitle: string) { + if (modelTitle === defaultModel?.title) return; + dispatch(setDefaultModel({ title: modelTitle })); + } + + return ( +
+
+ {sortedOptions.map((option, idx) => ( + + ))} +
+ +
+ {props.selectedProfileId === "local" && ( + <> + +
+ + Add Chat model +
+
+ + )} + + + + + {getMetaKeyLabel()}⇧' toggle model + +
+
+ ); +} diff --git a/gui/src/components/modelSelection/platform/shared.tsx b/gui/src/components/modelSelection/platform/shared.tsx new file mode 100644 index 000000000..1d45fafd9 --- /dev/null +++ b/gui/src/components/modelSelection/platform/shared.tsx @@ -0,0 +1,113 @@ +import { Cog6ToothIcon } from "@heroicons/react/24/outline"; +import { useState } from "react"; +import styled from "styled-components"; +import { defaultBorderRadius, lightGray } from "../.."; + +export const OptionDiv = styled.div<{ + isDisabled?: boolean; + isSelected?: boolean; +}>` + border-radius: ${defaultBorderRadius}; + padding: 6px 12px; + + min-width: 0px; + + ${({ isDisabled, isSelected }) => + !isDisabled && + ` + cursor: pointer; + + &:hover { + background: ${lightGray}33; + } + + ${ + isSelected && + ` + background: ${lightGray}22; + ` + } + `} + + ${({ isDisabled }) => + isDisabled && + ` + opacity: 0.5; + `} +`; + +export const MAX_HEIGHT_PX = 300; + +export const Divider = styled.div` + height: 0.5px; + background-color: ${lightGray}; +`; + +interface ModelOptionProps { + children: React.ReactNode; + idx: number; + disabled: boolean; + selected: boolean; + showConfigure: boolean; + onConfigure: (e: any) => void; + onClick: () => void; +} + +const IconBase = styled.div<{ $hovered: boolean }>` + width: 1.2em; + height: 1.2em; + cursor: pointer; + padding: 4px; + border-radius: ${defaultBorderRadius}; + opacity: ${(props) => (props.$hovered ? 0.75 : 0)}; + visibility: ${(props) => (props.$hovered ? "visible" : "hidden")}; + + &:hover { + opacity: 1; + background-color: ${lightGray}33; + } +`; + +const StyledCog6ToothIcon = styled(IconBase).attrs({ as: Cog6ToothIcon })``; + +export function Option({ + onConfigure, + children, + idx, + disabled, + onClick, + showConfigure, + selected, +}: ModelOptionProps) { + const [hovered, setHovered] = useState(false); + + function handleOptionClick(e) { + if (disabled) { + e.preventDefault(); + e.stopPropagation(); + } + onClick(); + } + + return ( + setHovered(true)} + onMouseLeave={() => setHovered(false)} + isSelected={selected} + onClick={handleOptionClick} + > +
+
+ {children} +
+ {showConfigure && ( + + )} +
+
+
+
+ ); +} diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index ca5d4f207..19d70f589 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -13,6 +13,10 @@ import ConfirmationDialog from "../components/dialogs/ConfirmationDialog"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppSelector } from "../redux/hooks"; import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; +import { + selectAvailableProfiles, + setAvailableProfiles, +} from "../redux/slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import { IdeMessengerContext } from "./IdeMessenger"; @@ -34,7 +38,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ const [session, setSession] = useState( undefined, ); - const [profiles, setProfiles] = useState([]); + + const profiles = useAppSelector(selectAvailableProfiles); + const selectedProfileId = useAppSelector( (store) => store.session.selectedProfileId, ); @@ -151,14 +157,16 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ideMessenger .request("config/listProfiles", undefined) .then( - (result) => result.status === "success" && setProfiles(result.content), + (result) => + result.status === "success" && + dispatch(setAvailableProfiles(result.content)), ); }, []); useWebviewListener( "didChangeAvailableProfiles", async (data) => { - setProfiles(data.profiles); + dispatch(setAvailableProfiles(data.profiles)); }, [], ); diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index 35e530e47..64ab59817 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -74,6 +74,20 @@ export const configSlice = createSlice({ defaultModelTitle: payload.title, }; }, + cycleDefaultModel: (state, { payload }: PayloadAction<"next" | "prev">) => { + const currentIndex = state.config.models.findIndex( + (model) => model.title === state.defaultModelTitle, + ); + const nextIndex = + (currentIndex + + (payload === "next" ? 1 : -1) + + state.config.models.length) % + state.config.models.length; + return { + ...state, + defaultModelTitle: state.config.models[nextIndex].title, + }; + }, }, selectors: { selectDefaultModel: (state) => { @@ -93,8 +107,12 @@ export const configSlice = createSlice({ }, }); -export const { setDefaultModel, setConfigResult, setConfigError } = - configSlice.actions; +export const { + setDefaultModel, + cycleDefaultModel, + setConfigResult, + setConfigError, +} = configSlice.actions; export const { selectDefaultModel, diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 6f91202ba..05ab1c316 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -20,14 +20,15 @@ import { SessionMetadata, ToolCall, } from "core"; +import { ProfileDescription } from "core/config/ConfigHandler"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { incrementalParseJson } from "core/util/incrementalParseJson"; import { renderChatMessage } from "core/util/messageContent"; +import { findUriInDirs, getUriPathBasename } from "core/util/uri"; import { v4 as uuidv4 } from "uuid"; import { RootState } from "../store"; import { streamResponseThunk } from "../thunks/streamResponse"; import { findCurrentToolCall } from "../util"; -import { findUriInDirs, getUriPathBasename } from "core/util/uri"; // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. @@ -43,6 +44,7 @@ type SessionState = { title: string; id: string; selectedProfileId: string; + availableProfiles: ProfileDescription[]; streamAborter: AbortController; codeToEdit: CodeToEdit[]; curCheckpointIndex: number; @@ -82,6 +84,12 @@ const initialState: SessionState = { title: NEW_SESSION_TITLE, id: uuidv4(), selectedProfileId: "local", + availableProfiles: [ + { + id: "local", + title: "Local", + }, + ], curCheckpointIndex: 0, streamAborter: new AbortController(), codeToEdit: [], @@ -465,8 +473,28 @@ export const sessionSlice = createSlice({ selectedProfileId: payload, }; }, - setCurCheckpointIndex: (state, { payload }: PayloadAction) => { - state.curCheckpointIndex = payload; + cycleSelectedProfileId: (state) => { + const profileIds = state.availableProfiles.map((profile) => profile.id); + const curIndex = profileIds.indexOf(state.selectedProfileId); + const nextIndex = (curIndex + 1) % profileIds.length; + return { + ...state, + selectedProfileId: profileIds[nextIndex], + }; + }, + setAvailableProfiles: ( + state, + { payload }: PayloadAction, + ) => { + return { + ...state, + availableProfiles: payload, + selectedProfileId: payload.find( + (profile) => profile.id === state.selectedProfileId, + ) + ? state.selectedProfileId + : payload[0]?.id, + }; }, updateCurCheckpoint: ( state, @@ -475,6 +503,9 @@ export const sessionSlice = createSlice({ state.history[state.curCheckpointIndex].checkpoint[payload.filepath] = payload.content; }, + setCurCheckpointIndex: (state, { payload }: PayloadAction) => { + state.curCheckpointIndex = payload; + }, updateApplyState: (state, { payload }: PayloadAction) => { const applyState = state.codeBlockApplyStates.states.find( (state) => state.streamId === payload.streamId, @@ -577,6 +608,9 @@ export const sessionSlice = createSlice({ selectHasCodeToEdit: (state) => { return state.codeToEdit.length > 0; }, + selectAvailableProfiles: (state) => { + return state.availableProfiles; + }, }, extraReducers: (builder) => { addPassthroughCases(builder, [streamResponseThunk]); @@ -640,6 +674,8 @@ export const { removeCodeToEdit, setCalling, cancelToolCall, + cycleSelectedProfileId, + setAvailableProfiles, acceptToolCall, setToolGenerated, setToolCallOutput, @@ -655,6 +691,7 @@ export const { selectIsInEditMode, selectIsSingleRangeEditOrInsertion, selectHasCodeToEdit, + selectAvailableProfiles, } = sessionSlice.selectors; export default sessionSlice.reducer; From 1ed8174023e498597bb1c5b6644fe0927ac4a57b Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 7 Jan 2025 17:22:43 -0800 Subject: [PATCH 12/50] update launch.json --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index dfe474f40..cdb502c8c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,10 +20,10 @@ "outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"], "preLaunchTask": "vscode-extension:build", "env": { + // "CONTROL_PLANE_ENV": "local", "CONTINUE_GLOBAL_DIR": "${workspaceFolder}/extensions/.continue-debug" // "staging" for the preview deployment "CONTINUE_GLOBAL_DIR": "${workspaceFolder}/extensions/.continue-debug" // "local" for entirely local development of control plane/proxy - // "CONTROL_PLANE_ENV": "staging" } }, { From 80f1c11d8df2cfbd057a882302484fcebcad7484 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 7 Jan 2025 17:42:08 -0800 Subject: [PATCH 13/50] use thunks for cycling profile id --- .../platform/AssistantAndModelSelect.tsx | 11 +++++----- .../platform/AssistantSelect.tsx | 13 ++++-------- .../modelSelection/platform/shared.tsx | 2 +- gui/src/redux/slices/sessionSlice.ts | 10 --------- gui/src/redux/thunks/cycleProfile.ts | 21 +++++++++++++++++++ gui/src/redux/thunks/setProfileId.ts | 13 ++++++++++++ 6 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 gui/src/redux/thunks/cycleProfile.ts create mode 100644 gui/src/redux/thunks/setProfileId.ts diff --git a/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx b/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx index 955f770f9..7c1767f83 100644 --- a/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantAndModelSelect.tsx @@ -1,17 +1,16 @@ import { Popover } from "@headlessui/react"; import { ChevronDownIcon } from "@heroicons/react/24/outline"; import { useEffect, useRef, useState } from "react"; -import { useDispatch } from "react-redux"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscInputBackground } from "../.."; import AddModelForm from "../../../forms/AddModelForm"; -import { useAppSelector } from "../../../redux/hooks"; +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; import { cycleDefaultModel, selectDefaultModel, } from "../../../redux/slices/configSlice"; -import { cycleSelectedProfileId } from "../../../redux/slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; +import { cycleProfile } from "../../../redux/thunks/cycleProfile"; import { getFontSize, isMetaEquivalentKeyPressed } from "../../../util"; import PopoverTransition from "../../mainInput/InputToolbar/PopoverTransition"; import { AssistantSelect } from "./AssistantSelect"; @@ -50,7 +49,7 @@ const StyledPopoverPanel = styled(Popover.Panel)<{ $showabove: boolean }>` `; function AssistantAndModelSelect() { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const defaultModel = useAppSelector(selectDefaultModel); const [showAbove, setShowAbove] = useState(false); const buttonRef = useRef(null); @@ -76,7 +75,7 @@ function AssistantAndModelSelect() { setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); } - function onClickAddModel(e) { + function onClickAddModel(e: any) { e.stopPropagation(); e.preventDefault(); @@ -108,7 +107,7 @@ function AssistantAndModelSelect() { dispatch(cycleDefaultModel("next")); } else { if (now - lastToggleTime >= DEBOUNCE_MS) { - dispatch(cycleSelectedProfileId()); + dispatch(cycleProfile()); lastToggleTime = now; } } diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index cde44669a..292b71309 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -4,11 +4,11 @@ import { SparklesIcon, } from "@heroicons/react/24/outline"; import { useContext } from "react"; -import { useDispatch } from "react-redux"; import { lightGray } from "../.."; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; -import { setSelectedProfileId } from "../../../redux/slices/sessionSlice"; +import { useAppDispatch } from "../../../redux/hooks"; +import { setProfileId } from "../../../redux/thunks/setProfileId"; import { getFontSize, getMetaKeyLabel } from "../../../util"; import { Divider, Option, OptionDiv } from "./shared"; @@ -18,12 +18,7 @@ export function AssistantSelect(props: AssistantSelectProps) { const ideMessenger = useContext(IdeMessengerContext); const { profiles, selectedProfile } = useAuth(); - const dispatch = useDispatch(); - - const changeProfileId = (id: string) => { - ideMessenger.post("didChangeSelectedProfile", { id }); - dispatch(setSelectedProfileId(id)); - }; + const dispatch = useAppDispatch(); function onNewAssistant() { ideMessenger.post("openUrl", "https://app.continue.dev/new"); @@ -45,7 +40,7 @@ export function AssistantSelect(props: AssistantSelectProps) { profileId: option.id, }); }} - onClick={() => changeProfileId(option.id)} + onClick={() => dispatch(setProfileId(option.id))} >
{option.id === "local" ? ( diff --git a/gui/src/components/modelSelection/platform/shared.tsx b/gui/src/components/modelSelection/platform/shared.tsx index 1d45fafd9..7b2bcbf75 100644 --- a/gui/src/components/modelSelection/platform/shared.tsx +++ b/gui/src/components/modelSelection/platform/shared.tsx @@ -81,7 +81,7 @@ export function Option({ }: ModelOptionProps) { const [hovered, setHovered] = useState(false); - function handleOptionClick(e) { + function handleOptionClick(e: any) { if (disabled) { e.preventDefault(); e.stopPropagation(); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 64d75a9ef..3943d1b8f 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -485,15 +485,6 @@ export const sessionSlice = createSlice({ selectedProfileId: payload, }; }, - cycleSelectedProfileId: (state) => { - const profileIds = state.availableProfiles.map((profile) => profile.id); - const curIndex = profileIds.indexOf(state.selectedProfileId); - const nextIndex = (curIndex + 1) % profileIds.length; - return { - ...state, - selectedProfileId: profileIds[nextIndex], - }; - }, setAvailableProfiles: ( state, { payload }: PayloadAction, @@ -688,7 +679,6 @@ export const { removeCodeToEdit, setCalling, cancelToolCall, - cycleSelectedProfileId, setAvailableProfiles, acceptToolCall, setToolGenerated, diff --git a/gui/src/redux/thunks/cycleProfile.ts b/gui/src/redux/thunks/cycleProfile.ts new file mode 100644 index 000000000..0ee548c31 --- /dev/null +++ b/gui/src/redux/thunks/cycleProfile.ts @@ -0,0 +1,21 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { ThunkApiType } from "../store"; +import { setProfileId } from "./setProfileId"; + +export const cycleProfile = createAsyncThunk( + "profile/cycle", + async (_, { dispatch, getState, extra }) => { + const state = getState(); + const profileIds = state.session.availableProfiles.map( + (profile) => profile.id, + ); + const curIndex = profileIds.indexOf(state.session.selectedProfileId); + const nextIndex = (curIndex + 1) % profileIds.length; + const nextId = profileIds[nextIndex]; + dispatch(setProfileId(nextId)); + + extra.ideMessenger.post("didChangeSelectedProfile", { + id: nextId, + }); + }, +); diff --git a/gui/src/redux/thunks/setProfileId.ts b/gui/src/redux/thunks/setProfileId.ts new file mode 100644 index 000000000..6ec1020ce --- /dev/null +++ b/gui/src/redux/thunks/setProfileId.ts @@ -0,0 +1,13 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { setSelectedProfileId } from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; + +export const setProfileId = createAsyncThunk( + "profile/setId", + async (id, { dispatch, extra }) => { + dispatch(setSelectedProfileId(id)); + extra.ideMessenger.post("didChangeSelectedProfile", { + id, + }); + }, +); From e7007154a63112a3a528603fd0ed99196230430c Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 9 Jan 2025 14:01:34 -0800 Subject: [PATCH 14/50] remove unnecessary continue for teams popup --- gui/src/components/ProfileSwitcher.tsx | 8 ++------ gui/src/context/Auth.tsx | 3 --- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/gui/src/components/ProfileSwitcher.tsx b/gui/src/components/ProfileSwitcher.tsx index 3a5d620de..0cecdf815 100644 --- a/gui/src/components/ProfileSwitcher.tsx +++ b/gui/src/components/ProfileSwitcher.tsx @@ -7,7 +7,7 @@ import { UserCircleIcon as UserCircleIconSolid } from "@heroicons/react/24/solid import { ProfileDescription } from "core/config/ConfigHandler"; import { Fragment, useContext, useEffect, useState } from "react"; import ReactDOM from "react-dom"; -import { useDispatch, useSelector } from "react-redux"; +import { useDispatch } from "react-redux"; import styled from "styled-components"; import { defaultBorderRadius, @@ -21,11 +21,10 @@ import { import { useAuth } from "../context/Auth"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { useWebviewListener } from "../hooks/useWebviewListener"; +import { useAppSelector } from "../redux/hooks"; import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; -import { RootState } from "../redux/store"; import { getFontSize } from "../util"; import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; -import { useAppSelector } from "../redux/hooks"; const StyledListbox = styled(Listbox)` background-color: ${vscBackground}; @@ -148,9 +147,6 @@ function ProfileSwitcher() { const shouldShowPopup = !lastControlServerBetaEnabledStatus && enableControlServerBeta; - if (shouldShowPopup) { - ideMessenger.ide.showToast("info", "Continue for Teams enabled"); - } }); }, []); diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index 19d70f589..df6cf8ed7 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -135,9 +135,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ const shouldShowPopup = !lastControlServerBetaEnabledStatus && enableControlServerBeta; - if (shouldShowPopup) { - ideMessenger.ide.showToast("info", "Continue for Teams enabled"); - } }); }, []); From 4d638ee93b030f3cfd750f141de676205afa7fe1 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 10 Jan 2025 08:23:39 -0800 Subject: [PATCH 15/50] return a promise from login() --- .../OnboardingCard/platform/tabs/main.tsx | 7 +- gui/src/context/Auth.tsx | 66 ++++++++++--------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/gui/src/components/OnboardingCard/platform/tabs/main.tsx b/gui/src/components/OnboardingCard/platform/tabs/main.tsx index 4295dd18d..f6a14cb93 100644 --- a/gui/src/components/OnboardingCard/platform/tabs/main.tsx +++ b/gui/src/components/OnboardingCard/platform/tabs/main.tsx @@ -13,8 +13,11 @@ export default function MainTab({ const auth = useAuth(); function onGetStarted() { - auth.login(true); - onboardingCard.close(); + auth.login(true).then((success) => { + if (success) { + onboardingCard.close(); + } + }); } return ( diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index df6cf8ed7..361ee8e0c 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -24,7 +24,7 @@ import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { session: ControlPlaneSessionInfo | undefined; logout: () => void; - login: (useOnboarding: boolean) => void; + login: (useOnboarding: boolean) => Promise; selectedProfile: ProfileDescription | undefined; profiles: ProfileDescription[]; controlServerBetaEnabled: boolean; @@ -55,36 +55,42 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ (state) => state.misc.lastControlServerBetaEnabledStatus, ); - const login = (useOnboarding: boolean) => { - ideMessenger - .request("getControlPlaneSessionInfo", { - silent: false, - useOnboarding, - }) - .then((result) => { - if (result.status === "error") { - return; - } - const session = result.content; - setSession(session); + const login: AuthContextType["login"] = (useOnboarding: boolean) => { + return new Promise((resolve) => { + ideMessenger + .request("getControlPlaneSessionInfo", { + silent: false, + useOnboarding, + }) + .then((result) => { + if (result.status === "error") { + resolve(false); + return; + } - // If this is the first time the user has logged in, explain how profiles work - if (!getLocalStorage("shownProfilesIntroduction")) { - dispatch(setShowDialog(true)); - dispatch( - setDialogMessage( - {}} - />, - ), - ); - setLocalStorage("shownProfilesIntroduction", true); - } - }); + const session = result.content; + setSession(session); + + // If this is the first time the user has logged in, explain how profiles work + if (!getLocalStorage("shownProfilesIntroduction")) { + dispatch(setShowDialog(true)); + dispatch( + setDialogMessage( + {}} + />, + ), + ); + setLocalStorage("shownProfilesIntroduction", true); + } + + resolve(true); + }); + }); }; const logout = () => { From d629294a7186aa21b812322e92c592687d6864bb Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 11 Jan 2025 14:57:38 -0800 Subject: [PATCH 16/50] usePlatform flag based on ~/.continue/.use_platform --- core/config/ConfigHandler.ts | 134 ++++++++++++------ core/config/load.ts | 2 + core/control-plane/env.ts | 15 +- core/control-plane/flags.ts | 6 +- core/core.ts | 4 +- core/index.d.ts | 7 +- core/util/paths.ts | 4 +- extensions/vscode/package-lock.json | 4 +- gui/src/components/mainInput/InputToolbar.tsx | 7 +- gui/src/pages/gui/Chat.tsx | 5 +- gui/src/redux/selectors/index.ts | 5 + gui/src/redux/slices/configSlice.ts | 1 + 12 files changed, 135 insertions(+), 59 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 971c67bc9..cc4895048 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -14,18 +14,20 @@ import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; import { getConfigJsonPath } from "../util/paths.js"; +import { pathToFileURL } from "url"; +import { usePlatform } from "../control-plane/flags.js"; import { ConfigResult } from "./load.js"; import { LOCAL_ONBOARDING_CHAT_MODEL, ONBOARDING_LOCAL_MODEL_TITLE, } from "./onboarding.js"; +import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js"; import LocalProfileLoader from "./profile/LocalProfileLoader.js"; import PlatformProfileLoader from "./profile/PlatformProfileLoader.js"; import { ProfileDescription, ProfileLifecycleManager, } from "./ProfileLifecycleManager.js"; -import { pathToFileURL } from "url"; export type { ProfileDescription }; @@ -99,51 +101,97 @@ export class ConfigHandler { } private async fetchControlPlaneProfiles() { - // Get the profiles and create their lifecycle managers - this.controlPlaneClient - .listAssistants() - .then(async (assistants) => { - this.profiles = this.profiles.filter( - (profile) => profile.profileId === "local", - ); - assistants.forEach((assistant) => { - const profileLoader = new PlatformProfileLoader( - assistant.configYaml, - assistant.ownerSlug, - assistant.packageSlug, - this.controlPlaneClient, - this.ide, - this.ideSettingsPromise, - this.writeLog, - this.reloadConfig.bind(this), + if (usePlatform()) { + // Get the profiles and create their lifecycle managers + this.controlPlaneClient + .listAssistants() + .then(async (assistants) => { + this.profiles = this.profiles.filter( + (profile) => profile.profileId === "local", ); - this.profiles.push(new ProfileLifecycleManager(profileLoader)); + assistants.forEach((assistant) => { + const profileLoader = new PlatformProfileLoader( + assistant.configYaml, + assistant.ownerSlug, + assistant.packageSlug, + this.controlPlaneClient, + this.ide, + this.ideSettingsPromise, + this.writeLog, + this.reloadConfig.bind(this), + ); + this.profiles.push(new ProfileLifecycleManager(profileLoader)); + }); + + this.notifyProfileListeners( + this.profiles.map((profile) => profile.profileDescription), + ); + + // Check the last selected workspace, and reload if it isn't local + const workspaceId = await this.getWorkspaceId(); + const lastSelectedWorkspaceIds = + this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; + const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId]; + if (selectedWorkspaceId) { + this.selectedProfileId = selectedWorkspaceId; + await this.loadConfig(); + } else { + // Otherwise we stick with local profile, and record choice + lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId; + this.globalContext.update( + "lastSelectedProfileForWorkspace", + lastSelectedWorkspaceIds, + ); + } + }) + .catch((e) => { + console.error("Failed to list assistants: ", e); }); - - this.notifyProfileListeners( - this.profiles.map((profile) => profile.profileDescription), - ); - - // Check the last selected workspace, and reload if it isn't local - const workspaceId = await this.getWorkspaceId(); - const lastSelectedWorkspaceIds = - this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; - const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId]; - if (selectedWorkspaceId) { - this.selectedProfileId = selectedWorkspaceId; - await this.loadConfig(); - } else { - // Otherwise we stick with local profile, and record choice - lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId; - this.globalContext.update( - "lastSelectedProfileForWorkspace", - lastSelectedWorkspaceIds, + } else { + this.controlPlaneClient + .listWorkspaces() + .then(async (workspaces) => { + this.profiles = this.profiles.filter( + (profile) => profile.profileId === "local", ); - } - }) - .catch((e) => { - console.error("Failed to list assistants: ", e); - }); + workspaces.forEach((workspace) => { + const profileLoader = new ControlPlaneProfileLoader( + workspace.id, + workspace.name, + this.controlPlaneClient, + this.ide, + this.ideSettingsPromise, + this.writeLog, + this.reloadConfig.bind(this), + ); + this.profiles.push(new ProfileLifecycleManager(profileLoader)); + }); + + this.notifyProfileListeners( + this.profiles.map((profile) => profile.profileDescription), + ); + + // Check the last selected workspace, and reload if it isn't local + const workspaceId = await this.getWorkspaceId(); + const lastSelectedWorkspaceIds = + this.globalContext.get("lastSelectedProfileForWorkspace") ?? {}; + const selectedWorkspaceId = lastSelectedWorkspaceIds[workspaceId]; + if (selectedWorkspaceId) { + this.selectedProfileId = selectedWorkspaceId; + await this.loadConfig(); + } else { + // Otherwise we stick with local profile, and record choice + lastSelectedWorkspaceIds[workspaceId] = this.selectedProfileId; + this.globalContext.update( + "lastSelectedProfileForWorkspace", + lastSelectedWorkspaceIds, + ); + } + }) + .catch((e) => { + console.error(e); + }); + } } async setSelectedProfile(profileId: string) { diff --git a/core/config/load.ts b/core/config/load.ts index b7ce400eb..8243b9c38 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -63,6 +63,7 @@ import { getEsbuildBinaryPath, } from "../util/paths"; +import { usePlatform } from "../control-plane/flags"; import { defaultContextProvidersJetBrains, defaultContextProvidersVsCode, @@ -570,6 +571,7 @@ function finalToBrowserConfig( experimental: final.experimental, docs: final.docs, tools: final.tools, + usePlatform: usePlatform(), }; } diff --git a/core/control-plane/env.ts b/core/control-plane/env.ts index 4556ce90f..064d30a5c 100644 --- a/core/control-plane/env.ts +++ b/core/control-plane/env.ts @@ -1,3 +1,5 @@ +import { usePlatform } from "./flags"; + interface ControlPlaneEnv { DEFAULT_CONTROL_PLANE_PROXY_URL: string; CONTROL_PLANE_URL: string; @@ -34,6 +36,15 @@ const STAGING_ENV: ControlPlaneEnv = { APP_URL: "https://app-preview.continue.dev", }; +const TEST_ENV: ControlPlaneEnv = { + DEFAULT_CONTROL_PLANE_PROXY_URL: + "https://control-plane-api.continue-dev.tools/", + CONTROL_PLANE_URL: "https://control-plane-api.continue-dev.tools/", + AUTH_TYPE: WORKOS_ENV_ID_STAGING, + WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING, + APP_URL: "https://app-test.continue.dev", +}; + const LOCAL_ENV: ControlPlaneEnv = { DEFAULT_CONTROL_PLANE_PROXY_URL: "http://localhost:3001/", CONTROL_PLANE_URL: "http://localhost:3001/", @@ -47,4 +58,6 @@ export const controlPlaneEnv = ? LOCAL_ENV : process.env.CONTROL_PLANE_ENV === "staging" ? STAGING_ENV - : PRODUCTION_ENV; + : process.env.CONTROL_PLANE_ENV === "test" || usePlatform() + ? TEST_ENV + : PRODUCTION_ENV; diff --git a/core/control-plane/flags.ts b/core/control-plane/flags.ts index 3ea598e3b..fdb656e15 100644 --- a/core/control-plane/flags.ts +++ b/core/control-plane/flags.ts @@ -1 +1,5 @@ -export const USE_PLATFORM = true; +import { usePlatformPathExists } from "../util/paths"; + +export function usePlatform(): boolean { + return usePlatformPathExists(); +} diff --git a/core/core.ts b/core/core.ts index 770d68314..cc92f9d0b 100644 --- a/core/core.ts +++ b/core/core.ts @@ -44,7 +44,7 @@ import { getSymbolsForManyFiles } from "./util/treeSitter"; import { TTS } from "./util/tts"; import { type ContextItemId, type IDE, type IndexingProgressUpdate } from "."; -import { USE_PLATFORM } from "./control-plane/flags"; +import { usePlatform } from "./control-plane/flags"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./protocol/messenger"; @@ -103,7 +103,7 @@ export class Core { const ideSettingsPromise = messenger.request("getIdeSettings", undefined); const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", { silent: true, - useOnboarding: USE_PLATFORM, + useOnboarding: usePlatform(), }); this.controlPlaneClient = new ControlPlaneClient(sessionInfoPromise); diff --git a/core/index.d.ts b/core/index.d.ts index 1f01f8213..07b2d9ff6 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1200,6 +1200,7 @@ export interface BrowserSerializedContinueConfig { analytics?: AnalyticsConfig; docs?: SiteIndexingConfig[]; tools: Tool[]; + usePlatform: boolean; } // DOCS SUGGESTIONS AND PACKAGE INFO @@ -1237,9 +1238,9 @@ export type PackageDocsResult = { } & ( | { error: string; details?: never } | { details: PackageDetailsSuccess; error?: never } - ); +); export interface TerminalOptions { - reuseTerminal?: boolean, - terminalName?: string, + reuseTerminal?: boolean; + terminalName?: string; } diff --git a/core/util/paths.ts b/core/util/paths.ts index 8dd0cf84f..9f8c2beb8 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -301,8 +301,8 @@ export function getPathToRemoteConfig(remoteConfigServerUrl: string): string { return dir; } -export function internalBetaPathExists(): boolean { - const sPath = path.join(getContinueGlobalPath(), ".internal_beta"); +export function usePlatformPathExists(): boolean { + const sPath = path.join(getContinueGlobalPath(), ".use_platform"); return fs.existsSync(sPath); } diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 7aa72c8f7..eaf4fd970 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.250", + "version": "0.9.251", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.250", + "version": "0.9.251", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 23e62f07e..7ce52bec4 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -1,6 +1,5 @@ import { AtSymbolIcon, PhotoIcon } from "@heroicons/react/24/outline"; import { InputModifiers } from "core"; -import { USE_PLATFORM } from "core/control-plane/flags"; import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect"; import { useRef } from "react"; import styled from "styled-components"; @@ -11,7 +10,7 @@ import { vscInputBackground, } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectUseActiveFile } from "../../redux/selectors"; +import { selectUseActiveFile, selectUsePlatform } from "../../redux/selectors"; import { selectDefaultModel } from "../../redux/slices/configSlice"; import { selectHasCodeToEdit, @@ -98,6 +97,8 @@ function InputToolbar(props: InputToolbarProps) { modelSupportsTools(defaultModel.model, defaultModel.provider) && !props.toolbarOptions?.hideTools; + const usePlatform = useAppSelector(selectUsePlatform); + const supportsImages = defaultModel && modelSupportsImages( @@ -116,7 +117,7 @@ function InputToolbar(props: InputToolbarProps) { className="find-widget-skip flex" >
- {USE_PLATFORM ? : } + {usePlatform ? : }
{props.toolbarOptions?.hideImageUpload || (supportsImages && ( diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index df2932643..3f36adcef 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -6,7 +6,6 @@ import { } from "@heroicons/react/24/outline"; import { Editor, JSONContent } from "@tiptap/react"; import { InputModifiers, RangeInFileWithContents, ToolCallState } from "core"; -import { USE_PLATFORM } from "core/control-plane/flags"; import { streamResponse } from "core/llm/stream"; import { stripImages } from "core/util/messageContent"; import { usePostHog } from "posthog-js/react"; @@ -41,6 +40,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useTutorialCard } from "../../hooks/useTutorialCard"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { selectUsePlatform } from "../../redux/selectors"; import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall"; import { selectDefaultModel } from "../../redux/slices/configSlice"; import { submitEdit } from "../../redux/slices/editModeState"; @@ -217,6 +217,7 @@ export function Chat() { selectIsSingleRangeEditOrInsertion, ); const lastSessionId = useAppSelector((state) => state.session.lastSessionId); + const usePlatform = useAppSelector(selectUsePlatform); useEffect(() => { // Cmd + Backspace to delete current step @@ -541,7 +542,7 @@ export function Chat() { <> {onboardingCard.show && (
- {USE_PLATFORM ? ( + {usePlatform ? ( ) : ( diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts index 4ffd3d4af..737e865d3 100644 --- a/gui/src/redux/selectors/index.ts +++ b/gui/src/redux/selectors/index.ts @@ -42,3 +42,8 @@ export const selectUseActiveFile = createSelector( [(state: RootState) => state.config.config.experimental?.defaultContext], (defaultContext) => defaultContext?.includes("activeFile" as any), ); + +export const selectUsePlatform = createSelector( + [(state: RootState) => state.config.config.usePlatform], + (usePlatform) => usePlatform, +); diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index dc5da2222..5779f03d4 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -27,6 +27,7 @@ const initialState: ConfigState = { contextProviders: [], models: [], tools: [], + usePlatform: false, }, }; From acefabd698c700acf906b390bf29de2e9412cdd1 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 11 Jan 2025 15:31:06 -0800 Subject: [PATCH 17/50] make model/assistant selectors scrollable --- .../vscode/src/stubs/WorkOsAuthProvider.ts | 13 ++-- .../platform/AssistantSelect.tsx | 64 ++++++++++--------- .../modelSelection/platform/ModelSelect.tsx | 4 +- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts index a784a2a1f..a22c4934a 100644 --- a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts +++ b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts @@ -1,3 +1,7 @@ +import crypto from "crypto"; + +import { ControlPlaneSessionInfo } from "core/control-plane/client"; +import { controlPlaneEnv } from "core/control-plane/env"; import fetch from "node-fetch"; import { v4 as uuidv4 } from "uuid"; import { @@ -16,6 +20,7 @@ import { } from "vscode"; import { PromiseAdapter, promiseFromEvent } from "./promiseUtils"; +import { SecretStorage } from "./SecretStorage"; const AUTH_NAME = "Continue"; @@ -26,14 +31,6 @@ class UriEventHandler extends EventEmitter implements UriHandler { this.fire(uri); } } - -import { ControlPlaneSessionInfo } from "core/control-plane/client"; -import { controlPlaneEnv } from "core/control-plane/env"; - -import crypto from "crypto"; - -import { SecretStorage } from "./SecretStorage"; - // Function to generate a random string of specified length function generateRandomString(length: number): string { const possibleCharacters = diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 292b71309..c20332492 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -26,37 +26,41 @@ export function AssistantSelect(props: AssistantSelectProps) { return (
- {profiles.map((option, idx) => ( -