Merge upstream continuedev/continue main into continue-fork
Resolve conflicts preserving the fork's removals (Hub/Mission Control/ control-plane/continue-proxy/MDM) while integrating upstream changes: - core/llm/toolSupport.ts(.test.ts): drop reintroduced continue-proxy entry - core/config/ConfigHandler.ts: keep upstream 'configs' file type + Promise.all, use fork's LocalProfileLoader signature (no controlPlaneClient) - core/core.ts: keep upstream models/fetch handler; drop mdm/setLicenseKey handler (control-plane/mdm was removed by the fork) - core/package-lock.json, binary/package-lock.json: regenerated via npm install Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
c21843805e
41 changed files with 7901 additions and 68077 deletions
64410
binary/package-lock.json
generated
64410
binary/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
import { ModelDescription, SerializedContinueConfig } from "core";
|
||||
// import Mock from "core/llm/llms/Mock.js";
|
||||
import { IDE } from "core/index.js";
|
||||
import { FromIdeProtocol, ToIdeProtocol } from "core/protocol/index.js";
|
||||
import { IMessenger } from "core/protocol/messenger";
|
||||
import FileSystemIde from "core/util/filesystem";
|
||||
|
|
@ -15,7 +15,115 @@ import {
|
|||
CoreBinaryTcpMessenger,
|
||||
} from "../src/IpcMessenger";
|
||||
|
||||
// jest.setTimeout(100_000);
|
||||
/**
|
||||
* Handles IDE messages from the binary subprocess, responding with plain data
|
||||
* matching the Kotlin CoreMessenger format: { messageType, data, messageId }.
|
||||
*
|
||||
* This bypasses the JS _handleLine auto-wrapper which would double-wrap
|
||||
* responses in { done, content, status }.
|
||||
*/
|
||||
class BinaryIdeHandler {
|
||||
private ide: IDE;
|
||||
private subprocess: ChildProcessWithoutNullStreams;
|
||||
private handlers: Record<string, (data: any) => Promise<any> | any> = {};
|
||||
private unfinishedLine: string | undefined;
|
||||
|
||||
constructor(subprocess: ChildProcessWithoutNullStreams, ide: IDE) {
|
||||
this.ide = ide;
|
||||
this.subprocess = subprocess;
|
||||
this.registerHandlers();
|
||||
|
||||
// Listen on stdout alongside CoreBinaryMessenger (EventEmitter allows multiple listeners)
|
||||
// Use setEncoding so split multibyte UTF-8 characters are decoded correctly
|
||||
subprocess.stdout.setEncoding("utf8");
|
||||
subprocess.stdout.on("data", (data: string) => this.handleData(data));
|
||||
}
|
||||
|
||||
private registerHandlers() {
|
||||
const ide = this.ide;
|
||||
const h = this.handlers;
|
||||
h["getIdeInfo"] = () => ide.getIdeInfo();
|
||||
h["getIdeSettings"] = () => ide.getIdeSettings();
|
||||
h["getControlPlaneSessionInfo"] = () => undefined;
|
||||
h["getWorkspaceDirs"] = () => ide.getWorkspaceDirs();
|
||||
h["readFile"] = (d) => ide.readFile(d.filepath);
|
||||
h["writeFile"] = (d) => ide.writeFile(d.path, d.contents);
|
||||
h["fileExists"] = (d) => ide.fileExists(d.filepath);
|
||||
h["showLines"] = (d) => ide.showLines(d.filepath, d.startLine, d.endLine);
|
||||
h["openFile"] = (d) => ide.openFile(d.path);
|
||||
h["openUrl"] = (d) => ide.openUrl(d.url);
|
||||
h["runCommand"] = (d) => ide.runCommand(d.command);
|
||||
h["saveFile"] = (d) => ide.saveFile(d.filepath);
|
||||
h["readRangeInFile"] = (d) => ide.readRangeInFile(d.filepath, d.range);
|
||||
h["getFileStats"] = (d) => ide.getFileStats(d.files);
|
||||
h["getGitRootPath"] = (d) => ide.getGitRootPath(d.dir);
|
||||
h["listDir"] = (d) => ide.listDir(d.dir);
|
||||
h["getRepoName"] = (d) => ide.getRepoName(d.dir);
|
||||
h["getTags"] = (d) => ide.getTags(d);
|
||||
h["isTelemetryEnabled"] = () => ide.isTelemetryEnabled();
|
||||
h["isWorkspaceRemote"] = () => false;
|
||||
h["getUniqueId"] = () => ide.getUniqueId();
|
||||
h["getDiff"] = (d) => ide.getDiff(d.includeUnstaged);
|
||||
h["getTerminalContents"] = () => ide.getTerminalContents();
|
||||
h["getOpenFiles"] = () => ide.getOpenFiles();
|
||||
h["getCurrentFile"] = () => ide.getCurrentFile();
|
||||
h["getPinnedFiles"] = () => ide.getPinnedFiles();
|
||||
h["getSearchResults"] = (d) => ide.getSearchResults(d.query, d.maxResults);
|
||||
h["getFileResults"] = (d) => ide.getFileResults(d.pattern);
|
||||
h["getProblems"] = (d) => ide.getProblems(d.filepath);
|
||||
h["getBranch"] = (d) => ide.getBranch(d.dir);
|
||||
h["subprocess"] = (d) => ide.subprocess(d.command, d.cwd);
|
||||
h["getDebugLocals"] = (d) => ide.getDebugLocals(d.threadIndex);
|
||||
h["getAvailableThreads"] = () => ide.getAvailableThreads();
|
||||
h["getTopLevelCallStackSources"] = (d) =>
|
||||
ide.getTopLevelCallStackSources(d.threadIndex, d.stackDepth);
|
||||
h["showToast"] = () => {};
|
||||
h["readSecrets"] = (d) => ide.readSecrets(d.keys);
|
||||
h["writeSecrets"] = (d) => ide.writeSecrets(d.secrets);
|
||||
h["removeFile"] = (d) => ide.removeFile(d.path);
|
||||
}
|
||||
|
||||
private handleData(data: string) {
|
||||
const d = data;
|
||||
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
|
||||
if (lines.length === 0) return;
|
||||
|
||||
if (this.unfinishedLine) {
|
||||
lines[0] = this.unfinishedLine + lines[0];
|
||||
this.unfinishedLine = undefined;
|
||||
}
|
||||
if (!d.endsWith("\r\n")) {
|
||||
this.unfinishedLine = lines.pop();
|
||||
}
|
||||
lines.forEach((line) => this.handleLine(line));
|
||||
}
|
||||
|
||||
private async handleLine(line: string) {
|
||||
let msg: { messageType: string; messageId: string; data?: any };
|
||||
try {
|
||||
msg = JSON.parse(line);
|
||||
} catch {
|
||||
return; // not JSON, ignore
|
||||
}
|
||||
|
||||
const handler = this.handlers[msg.messageType];
|
||||
if (!handler) return; // not an IDE message, let CoreBinaryMessenger handle it
|
||||
|
||||
try {
|
||||
const result = await handler(msg.data);
|
||||
this.respond(msg.messageType, result, msg.messageId);
|
||||
} catch (e) {
|
||||
this.respond(msg.messageType, undefined, msg.messageId);
|
||||
}
|
||||
}
|
||||
|
||||
private respond(messageType: string, data: any, messageId: string) {
|
||||
const response = JSON.stringify({ messageType, data, messageId });
|
||||
this.subprocess.stdin.write(response + "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
jest.setTimeout(30_000);
|
||||
|
||||
const USE_TCP = false;
|
||||
|
||||
|
|
@ -122,6 +230,11 @@ describe("Test Suite", () => {
|
|||
console.error("Error spawning subprocess:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
subprocess.stderr.on("data", (data: Buffer) => {
|
||||
console.error(`[stderr] ${data.toString()}`);
|
||||
});
|
||||
|
||||
messenger = new CoreBinaryMessenger<ToIdeProtocol, FromIdeProtocol>(
|
||||
subprocess,
|
||||
);
|
||||
|
|
@ -132,7 +245,9 @@ describe("Test Suite", () => {
|
|||
fs.mkdirSync(testDir);
|
||||
}
|
||||
const ide = new FileSystemIde(testDir);
|
||||
// const reverseIde = new ReverseMessageIde(messenger.on.bind(messenger), ide);
|
||||
if (!USE_TCP && subprocess) {
|
||||
new BinaryIdeHandler(subprocess, ide);
|
||||
}
|
||||
|
||||
// Wait for core to set itself up
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
|
@ -151,8 +266,15 @@ describe("Test Suite", () => {
|
|||
}
|
||||
});
|
||||
|
||||
// Binary responses are wrapped in { done, content, status } by _handleLine.
|
||||
// This helper unwraps them, matching how the Kotlin CoreMessenger reads responses.
|
||||
async function request(messageType: string, data: any): Promise<any> {
|
||||
const resp = await messenger.request(messageType as any, data);
|
||||
return resp?.content !== undefined ? resp.content : resp;
|
||||
}
|
||||
|
||||
it("should respond to ping with pong", async () => {
|
||||
const resp = await messenger.request("ping", "ping");
|
||||
const resp = await request("ping", "ping");
|
||||
expect(resp).toBe("pong");
|
||||
});
|
||||
|
||||
|
|
@ -160,19 +282,9 @@ describe("Test Suite", () => {
|
|||
expect(fs.existsSync(CONTINUE_GLOBAL_DIR)).toBe(true);
|
||||
|
||||
// Many of the files are only created when trying to load the config
|
||||
const config = await messenger.request(
|
||||
"config/getSerializedProfileInfo",
|
||||
undefined,
|
||||
);
|
||||
await request("config/getSerializedProfileInfo", undefined);
|
||||
|
||||
const expectedFiles = [
|
||||
"config.json",
|
||||
"config.ts",
|
||||
"package.json",
|
||||
"logs/core.log",
|
||||
"index/autocompleteCache.sqlite",
|
||||
"types/core/index.d.ts",
|
||||
];
|
||||
const expectedFiles = ["logs/core.log", "index/autocompleteCache.sqlite"];
|
||||
|
||||
const missingFiles = expectedFiles.filter((file) => {
|
||||
const filePath = path.join(CONTINUE_GLOBAL_DIR, file);
|
||||
|
|
@ -186,38 +298,36 @@ describe("Test Suite", () => {
|
|||
});
|
||||
|
||||
it("should return valid config object", async () => {
|
||||
const { result } = await messenger.request(
|
||||
const { result } = await request(
|
||||
"config/getSerializedProfileInfo",
|
||||
undefined,
|
||||
);
|
||||
const { config } = result;
|
||||
expect(config).toHaveProperty("models");
|
||||
expect(config).toHaveProperty("embeddingsProvider");
|
||||
expect(config).toHaveProperty("modelsByRole");
|
||||
expect(config).toHaveProperty("contextProviders");
|
||||
expect(config).toHaveProperty("slashCommands");
|
||||
});
|
||||
|
||||
it("should properly handle history requests", async () => {
|
||||
const sessionId = "test-session-id";
|
||||
await messenger.request("history/save", {
|
||||
await request("history/save", {
|
||||
history: [],
|
||||
sessionId,
|
||||
title: "test-title",
|
||||
|
||||
workspaceDirectory: "test-workspace-directory",
|
||||
});
|
||||
const sessions = await messenger.request("history/list", {});
|
||||
const sessions = await request("history/list", {});
|
||||
expect(sessions.length).toBeGreaterThan(0);
|
||||
|
||||
const session = await messenger.request("history/load", {
|
||||
const session = await request("history/load", {
|
||||
id: sessionId,
|
||||
});
|
||||
expect(session).toHaveProperty("history");
|
||||
|
||||
await messenger.request("history/delete", {
|
||||
await request("history/delete", {
|
||||
id: sessionId,
|
||||
});
|
||||
const sessionsAfterDelete = await messenger.request("history/list", {});
|
||||
const sessionsAfterDelete = await request("history/list", {});
|
||||
expect(sessionsAfterDelete.length).toBe(sessions.length - 1);
|
||||
});
|
||||
|
||||
|
|
@ -228,12 +338,10 @@ describe("Test Suite", () => {
|
|||
model: "gpt-3.5-turbo",
|
||||
underlyingProviderName: "openai",
|
||||
};
|
||||
await messenger.request("config/addModel", {
|
||||
model,
|
||||
});
|
||||
await request("config/addModel", { model });
|
||||
const {
|
||||
result: { config },
|
||||
} = await messenger.request("config/getSerializedProfileInfo", undefined);
|
||||
} = await request("config/getSerializedProfileInfo", undefined);
|
||||
|
||||
expect(
|
||||
config!.modelsByRole.chat.some(
|
||||
|
|
@ -241,10 +349,10 @@ describe("Test Suite", () => {
|
|||
),
|
||||
).toBe(true);
|
||||
|
||||
await messenger.request("config/deleteModel", { title: model.title });
|
||||
await request("config/deleteModel", { title: model.title });
|
||||
const {
|
||||
result: { config: configAfterDelete },
|
||||
} = await messenger.request("config/getSerializedProfileInfo", undefined);
|
||||
} = await request("config/getSerializedProfileInfo", undefined);
|
||||
expect(
|
||||
configAfterDelete!.modelsByRole.chat.some(
|
||||
(m: ModelDescription) => m.title === model.title,
|
||||
|
|
@ -259,11 +367,9 @@ describe("Test Suite", () => {
|
|||
model: "gpt-3.5-turbo",
|
||||
underlyingProviderName: "mock",
|
||||
};
|
||||
await messenger.request("config/addModel", {
|
||||
model,
|
||||
});
|
||||
await request("config/addModel", { model });
|
||||
|
||||
const resp = await messenger.request("llm/complete", {
|
||||
const resp = await request("llm/complete", {
|
||||
prompt: "Say 'Hello' and nothing else",
|
||||
completionOptions: {},
|
||||
title: "Test Model",
|
||||
|
|
|
|||
|
|
@ -169,17 +169,15 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
if (options.includeWorkspace) {
|
||||
const assistantFiles = await getAllDotContinueDefinitionFiles(
|
||||
this.ide,
|
||||
{ ...options, fileExtType: "yaml" },
|
||||
"assistants",
|
||||
);
|
||||
const agentFiles = await getAllDotContinueDefinitionFiles(
|
||||
this.ide,
|
||||
{ ...options, fileExtType: "yaml" },
|
||||
"agents",
|
||||
);
|
||||
const profiles = [...assistantFiles, ...agentFiles].map((assistant) => {
|
||||
const yamlOptions = { ...options, fileExtType: "yaml" } as const;
|
||||
const allFiles = (
|
||||
await Promise.all([
|
||||
getAllDotContinueDefinitionFiles(this.ide, yamlOptions, "assistants"),
|
||||
getAllDotContinueDefinitionFiles(this.ide, yamlOptions, "agents"),
|
||||
getAllDotContinueDefinitionFiles(this.ide, yamlOptions, "configs"),
|
||||
])
|
||||
).flat();
|
||||
const profiles = allFiles.map((assistant) => {
|
||||
return new LocalProfileLoader(this.ide, this.llmLogger, assistant);
|
||||
});
|
||||
const localAssistantProfiles = profiles.map(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export function isContinueConfigRelatedUri(uri: string): boolean {
|
|||
(uri.endsWith(".yaml") ||
|
||||
uri.endsWith(".yml") ||
|
||||
uri.endsWith(".json"))) ||
|
||||
[...BLOCK_TYPES, "agents", "assistants"].some((blockType) =>
|
||||
[...BLOCK_TYPES, "agents", "assistants", "configs"].some((blockType) =>
|
||||
uri.includes(`.continue/${blockType}`),
|
||||
)
|
||||
);
|
||||
|
|
@ -38,7 +38,8 @@ export function isContinueAgentConfigFile(uri: string): boolean {
|
|||
const normalizedUri = URI.normalize(uri);
|
||||
return (
|
||||
normalizedUri.includes(`/.continue/agents/`) ||
|
||||
normalizedUri.includes(`/.continue/assistants/`)
|
||||
normalizedUri.includes(`/.continue/assistants/`) ||
|
||||
normalizedUri.includes(`/.continue/configs/`)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,14 +70,20 @@ export function addModel(
|
|||
config.models = [];
|
||||
}
|
||||
|
||||
const capabilities: string[] = [];
|
||||
if (model.capabilities?.tools) capabilities.push("tool_use");
|
||||
if (model.capabilities?.uploadImage) capabilities.push("image_input");
|
||||
|
||||
const desc: ModelConfig = {
|
||||
name: model.title,
|
||||
provider: model.provider,
|
||||
model: model.model,
|
||||
apiKey: model.apiKey,
|
||||
apiBase: model.apiBase,
|
||||
contextLength: model.contextLength,
|
||||
maxStopWords: model.maxStopWords,
|
||||
defaultCompletionOptions: model.completionOptions,
|
||||
...(capabilities.length > 0 ? { capabilities } : {}),
|
||||
};
|
||||
config.models.push(desc);
|
||||
return config;
|
||||
|
|
|
|||
14
core/core.ts
14
core/core.ts
|
|
@ -15,6 +15,7 @@ import { CodebaseIndexer } from "./indexing/CodebaseIndexer";
|
|||
import DocsService from "./indexing/docs/DocsService";
|
||||
import { countTokens } from "./llm/countTokens";
|
||||
import Lemonade from "./llm/llms/Lemonade";
|
||||
import { fetchModels } from "./llm/fetchModels";
|
||||
import Ollama from "./llm/llms/Ollama";
|
||||
import { EditAggregator } from "./nextEdit/context/aggregateEdits";
|
||||
import { createNewPromptFileV2 } from "./promptFiles/createNewPromptFile";
|
||||
|
|
@ -1131,6 +1132,19 @@ export class Core {
|
|||
on("process/killTerminalProcess", async ({ data: { toolCallId } }) => {
|
||||
await killTerminalProcess(toolCallId);
|
||||
});
|
||||
|
||||
on("models/fetch", async (msg) => {
|
||||
try {
|
||||
return await fetchModels(
|
||||
msg.data.provider,
|
||||
msg.data.apiKey,
|
||||
msg.data.apiBase,
|
||||
);
|
||||
} catch (error: any) {
|
||||
void this.ide.showToast("error", error.message);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async handleToolCall(toolCall: ToolCall) {
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1717,6 +1717,7 @@ export interface JSONModelDescription {
|
|||
maxStopWords?: number;
|
||||
template?: TemplateType;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
capabilities?: ModelCapability;
|
||||
systemMessage?: string;
|
||||
requestOptions?: RequestOptions;
|
||||
cacheBehavior?: CacheBehavior;
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ const MODEL_SUPPORTS_IMAGES: RegExp[] = [
|
|||
/pixtral/,
|
||||
/llama-?3\.2/,
|
||||
/llama-?4/, // might use something like /llama-?(?:[4-9](?:\.\d+)?|\d{2,}(?:\.\d+)?)/ for forward compat, if needed
|
||||
/\bgemma-?3(?!n)/, // gemma3 supports vision, but gemma3n doesn't!
|
||||
/\bgemma-?[34](?!n)/, // gemma3/gemma4 support vision, but gemma3n doesn't!
|
||||
/\b(pali|med)gemma/,
|
||||
/qwen(.*)vl/,
|
||||
/mistral-small/,
|
||||
|
|
|
|||
258
core/llm/fetchModels.ts
Normal file
258
core/llm/fetchModels.ts
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
import { LLMClasses, llmFromProviderAndOptions } from "./llms/index.js";
|
||||
|
||||
export interface FetchedModel {
|
||||
name: string;
|
||||
modelId?: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
contextLength?: number;
|
||||
maxTokens?: number;
|
||||
supportsTools?: boolean;
|
||||
}
|
||||
|
||||
const OLLAMA_EXCLUDED_CAPABILITIES = ["vision", "audio", "embedding"];
|
||||
|
||||
const OLLAMA_ICON_MAP: Record<string, string> = {
|
||||
llama: "meta.png",
|
||||
codellama: "meta.png",
|
||||
"phind-codellama": "meta.png",
|
||||
deepseek: "deepseek.png",
|
||||
deepcoder: "deepseek.png",
|
||||
deepscaler: "deepseek.png",
|
||||
mistral: "mistral.png",
|
||||
mixtral: "mistral.png",
|
||||
codestral: "mistral.png",
|
||||
devstral: "mistral.png",
|
||||
magistral: "mistral.png",
|
||||
mathstral: "mistral.png",
|
||||
ministral: "mistral.png",
|
||||
gemma: "gemini.png",
|
||||
codegemma: "gemini.png",
|
||||
"gemini-": "gemini.png",
|
||||
qwen: "qwen.png",
|
||||
codeqwen: "qwen.png",
|
||||
qwq: "qwen.png",
|
||||
command: "cohere.png",
|
||||
aya: "cohere.png",
|
||||
granite: "ibm.png",
|
||||
nemotron: "nvidia.png",
|
||||
kimi: "moonshot.png",
|
||||
glm: "zai.svg",
|
||||
codegeex: "zai.svg",
|
||||
wizardcoder: "wizardlm.png",
|
||||
wizardlm: "wizardlm.png",
|
||||
"wizard-": "wizardlm.png",
|
||||
olmo: "allenai.png",
|
||||
tulu: "allenai.png",
|
||||
firefunction: "fireworks.png",
|
||||
"gpt-oss": "openai.png",
|
||||
};
|
||||
|
||||
function getOllamaIcon(modelName: string): string {
|
||||
if (OLLAMA_ICON_MAP[modelName]) {
|
||||
return OLLAMA_ICON_MAP[modelName];
|
||||
}
|
||||
let bestMatch = "";
|
||||
for (const prefix of Object.keys(OLLAMA_ICON_MAP)) {
|
||||
if (modelName.startsWith(prefix) && prefix.length > bestMatch.length) {
|
||||
bestMatch = prefix;
|
||||
}
|
||||
}
|
||||
return bestMatch ? OLLAMA_ICON_MAP[bestMatch] : "ollama.png";
|
||||
}
|
||||
|
||||
async function fetchOllamaModels(): Promise<FetchedModel[]> {
|
||||
try {
|
||||
const response = await fetch("https://ollama.com/library");
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch Ollama library: ${response.status}`);
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const models: FetchedModel[] = [];
|
||||
const items = html.split("x-test-model class=");
|
||||
const seen = new Set<string>();
|
||||
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const nameMatch = item.match(/href="\/library\/([^"]+)"/);
|
||||
if (!nameMatch) continue;
|
||||
const name = nameMatch[1];
|
||||
if (seen.has(name)) continue;
|
||||
|
||||
const capabilities: string[] = [];
|
||||
const capRegex = /x-test-capability[^>]*>([^<]+)</g;
|
||||
let capMatch;
|
||||
while ((capMatch = capRegex.exec(item)) !== null) {
|
||||
capabilities.push(capMatch[1].trim().toLowerCase());
|
||||
}
|
||||
if (
|
||||
capabilities.some((cap) => OLLAMA_EXCLUDED_CAPABILITIES.includes(cap))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const sizes: string[] = [];
|
||||
const sizeRegex = /x-test-size[^>]*>([^<]+)</g;
|
||||
let sizeMatch;
|
||||
while ((sizeMatch = sizeRegex.exec(item)) !== null) {
|
||||
sizes.push(sizeMatch[1].trim());
|
||||
}
|
||||
|
||||
const descMatch = item.match(/<p class="max-w-lg[^"]*">([^<]+)</);
|
||||
const sizeLabel = sizes.length > 0 ? ` (${sizes.join(", ")})` : "";
|
||||
const description = descMatch
|
||||
? descMatch[1].trim()
|
||||
: `Ollama model: ${name}${sizeLabel}`;
|
||||
|
||||
seen.add(name);
|
||||
models.push({
|
||||
name,
|
||||
description,
|
||||
icon: getOllamaIcon(name),
|
||||
supportsTools: capabilities.includes("tools"),
|
||||
});
|
||||
}
|
||||
|
||||
return models;
|
||||
} catch (error) {
|
||||
console.error("Error fetching Ollama library models:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchOpenRouterModels(): Promise<FetchedModel[]> {
|
||||
try {
|
||||
const response = await fetch("https://openrouter.ai/api/v1/models");
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch OpenRouter models: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.data || !Array.isArray(data.data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return data.data
|
||||
.filter((m: any) => m.id && m.name)
|
||||
.map((m: any) => ({
|
||||
name: m.name,
|
||||
modelId: m.id,
|
||||
icon: "openrouter.png",
|
||||
contextLength: m.context_length,
|
||||
maxTokens: m.top_provider?.max_completion_tokens,
|
||||
supportsTools: (m.supported_parameters ?? []).includes("tools"),
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("Error fetching OpenRouter models:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchAnthropicModels(apiKey?: string): Promise<FetchedModel[]> {
|
||||
const response = await fetch(
|
||||
"https://api.anthropic.com/v1/models?limit=100",
|
||||
{
|
||||
headers: {
|
||||
"x-api-key": apiKey ?? "",
|
||||
"anthropic-version": "2023-06-01",
|
||||
},
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch Anthropic models: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return (data.data ?? []).map((m: any) => ({
|
||||
name: m.display_name ?? m.id,
|
||||
modelId: m.id,
|
||||
icon: "anthropic.png",
|
||||
contextLength: m.max_input_tokens,
|
||||
maxTokens: m.max_tokens,
|
||||
supportsTools: true,
|
||||
}));
|
||||
}
|
||||
|
||||
async function fetchGeminiModels(
|
||||
apiKey?: string,
|
||||
apiBase?: string,
|
||||
): Promise<FetchedModel[]> {
|
||||
const base = apiBase || "https://generativelanguage.googleapis.com/v1beta/";
|
||||
const url = new URL("models", base);
|
||||
url.searchParams.set("key", apiKey ?? "");
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch Gemini models: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return (data.models ?? [])
|
||||
.filter((m: any) => {
|
||||
const id: string = m.name?.replace("models/", "") ?? "";
|
||||
const methods: string[] = m.supportedGenerationMethods ?? [];
|
||||
return (
|
||||
!id.startsWith("gemini-2.0") &&
|
||||
!id.startsWith("gemma-") && // Gemma models are supported through Ollama, not the Gemini API
|
||||
!id.startsWith("nano-banana") &&
|
||||
!id.startsWith("lyria") &&
|
||||
methods.includes("generateContent") &&
|
||||
!methods.includes("embedContent") &&
|
||||
!methods.includes("predict") &&
|
||||
!methods.includes("predictLongRunning") &&
|
||||
!methods.includes("bidiGenerateContent") &&
|
||||
!id.includes("tts") &&
|
||||
!id.includes("image") &&
|
||||
!id.includes("robotics") &&
|
||||
!id.includes("computer-use")
|
||||
);
|
||||
})
|
||||
.map((m: any) => ({
|
||||
name: m.displayName ?? m.name?.replace("models/", ""),
|
||||
modelId: m.name?.replace("models/", ""),
|
||||
icon: "gemini.png",
|
||||
contextLength: m.inputTokenLimit,
|
||||
maxTokens: m.outputTokenLimit,
|
||||
supportsTools: true,
|
||||
}));
|
||||
}
|
||||
|
||||
async function fetchProviderModelsViaListModels(
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
apiBase?: string,
|
||||
): Promise<FetchedModel[]> {
|
||||
try {
|
||||
const cls = LLMClasses.find((llm) => llm.providerName === provider);
|
||||
const defaultApiBase = cls?.defaultOptions?.apiBase;
|
||||
|
||||
const llm = llmFromProviderAndOptions(provider, {
|
||||
apiKey,
|
||||
apiBase: apiBase || defaultApiBase,
|
||||
model: "",
|
||||
});
|
||||
const modelIds = await llm.listModels();
|
||||
return modelIds.map((id) => ({ name: id }));
|
||||
} catch (error: any) {
|
||||
throw new Error(
|
||||
`Failed to fetch models for ${provider}: ${error?.message ?? error}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchModels(
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
apiBase?: string,
|
||||
): Promise<FetchedModel[]> {
|
||||
switch (provider) {
|
||||
case "ollama":
|
||||
return fetchOllamaModels();
|
||||
case "openrouter":
|
||||
return fetchOpenRouterModels();
|
||||
case "anthropic":
|
||||
return fetchAnthropicModels(apiKey);
|
||||
case "gemini":
|
||||
return fetchGeminiModels(apiKey, apiBase);
|
||||
default:
|
||||
return fetchProviderModelsViaListModels(provider, apiKey, apiBase);
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +105,12 @@ describe("BaseLLM", () => {
|
|||
baseLLM.model = "google/gemma-3-270m";
|
||||
expect(baseLLM.supportsImages()).toBe(true);
|
||||
|
||||
baseLLM.model = "gemma4:31b";
|
||||
expect(baseLLM.supportsImages()).toBe(true);
|
||||
|
||||
baseLLM.model = "google/gemma-4-31b-it";
|
||||
expect(baseLLM.supportsImages()).toBe(true);
|
||||
|
||||
baseLLM.model = "foo/paligemma-custom-100";
|
||||
expect(baseLLM.supportsImages()).toBe(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -1025,7 +1025,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
this.providerName === "openai" &&
|
||||
this._llmOptions.useResponsesApi !== false &&
|
||||
typeof (this as any)._streamResponses === "function" &&
|
||||
(this as any).isOSeriesOrGpt5Model(options.model)
|
||||
(this as any).isOSeriesOrGpt5PlusModel(options.model)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,30 +5,38 @@ describe("OpenAI", () => {
|
|||
const openai = new OpenAI({
|
||||
model: "o3-mini",
|
||||
});
|
||||
expect(openai.isOSeriesOrGpt5Model("o4-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o3-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o1-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o1")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o3")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o4-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o3-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o1-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o1")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o3")).toBeTruthy();
|
||||
|
||||
// artificially correct samples for future models
|
||||
expect(openai.isOSeriesOrGpt5Model("o5-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o6")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o77")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5Model("o54-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o5-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o6")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o77")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("o54-mini")).toBeTruthy();
|
||||
|
||||
// gpt-5+ models
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-5")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-5.4")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-5.4-mini")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-5.4-pro")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-6")).toBeTruthy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-7-turbo")).toBeTruthy();
|
||||
});
|
||||
test("should identify incorrect o-series models", () => {
|
||||
const openai = new OpenAI({
|
||||
model: "o3-mini",
|
||||
});
|
||||
expect(openai.isOSeriesOrGpt5Model("gpt-o4-mini")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5Model("gpt-4.5")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5Model("gpt-4.1")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-o4-mini")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-4.5")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("gpt-4.1")).toBeFalsy();
|
||||
|
||||
// artificially wrong samples
|
||||
expect(openai.isOSeriesOrGpt5Model("os1")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5Model("so1")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5Model("ao31")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5Model("1os")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("os1")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("so1")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("ao31")).toBeFalsy();
|
||||
expect(openai.isOSeriesOrGpt5PlusModel("1os")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ class OpenAI extends BaseLLM {
|
|||
return model;
|
||||
}
|
||||
|
||||
public isOSeriesOrGpt5Model(model?: string): boolean {
|
||||
return !!model && (!!model.match(/^o[0-9]+/) || model.includes("gpt-5"));
|
||||
public isOSeriesOrGpt5PlusModel(model?: string): boolean {
|
||||
return !!model && (!!model.match(/^o[0-9]+/) || !!model.match(/gpt-[5-9]/));
|
||||
}
|
||||
|
||||
private isFireworksAiModel(model?: string): boolean {
|
||||
|
|
@ -284,7 +284,7 @@ class OpenAI extends BaseLLM {
|
|||
finalOptions.stop = options.stop?.slice(0, this.getMaxStopWords());
|
||||
|
||||
// OpenAI o1-preview and o1-mini or o3-mini:
|
||||
if (this.isOSeriesOrGpt5Model(options.model)) {
|
||||
if (this.isOSeriesOrGpt5PlusModel(options.model)) {
|
||||
// a) use max_completion_tokens instead of max_tokens
|
||||
finalOptions.max_completion_tokens = options.maxTokens;
|
||||
finalOptions.max_tokens = undefined;
|
||||
|
|
@ -400,7 +400,7 @@ class OpenAI extends BaseLLM {
|
|||
) {
|
||||
if (!this.apiBase) {
|
||||
throw new Error(
|
||||
"No API base URL provided. Please set the 'apiBase' option in config.json",
|
||||
"No API base URL provided. Please set the 'apiBase' option in config.yaml",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -440,7 +440,7 @@ class OpenAI extends BaseLLM {
|
|||
body.stop = body.stop?.slice(0, this.getMaxStopWords());
|
||||
|
||||
// OpenAI o1-preview and o1-mini or o3-mini:
|
||||
if (this.isOSeriesOrGpt5Model(body.model)) {
|
||||
if (this.isOSeriesOrGpt5PlusModel(body.model)) {
|
||||
// a) use max_completion_tokens instead of max_tokens
|
||||
body.max_completion_tokens = body.max_tokens;
|
||||
body.max_tokens = undefined;
|
||||
|
|
@ -573,7 +573,7 @@ class OpenAI extends BaseLLM {
|
|||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
if (!this.isOSeriesOrGpt5Model(options.model)) {
|
||||
if (!this.isOSeriesOrGpt5PlusModel(options.model)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -624,7 +624,7 @@ class OpenAI extends BaseLLM {
|
|||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
): Promise<ChatMessage | ChatMessage[]> {
|
||||
if (!this.isOSeriesOrGpt5Model(options.model)) {
|
||||
if (!this.isOSeriesOrGpt5PlusModel(options.model)) {
|
||||
// Minimal draft: only handle supported models for now
|
||||
return { role: "assistant", content: "" };
|
||||
}
|
||||
|
|
@ -694,13 +694,14 @@ class OpenAI extends BaseLLM {
|
|||
});
|
||||
|
||||
const data = await response.json();
|
||||
return data.data.map((m: any) => m.id);
|
||||
const models = Array.isArray(data) ? data : (data.data ?? []);
|
||||
return models.map((m: any) => m.id);
|
||||
}
|
||||
|
||||
private _getEmbedEndpoint() {
|
||||
if (!this.apiBase) {
|
||||
throw new Error(
|
||||
"No API base URL provided. Please set the 'apiBase' option in config.json",
|
||||
"No API base URL provided. Please set the 'apiBase' option in config.yaml",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { ChatCompletionCreateParams } from "openai/resources/index";
|
||||
|
||||
import { OPENROUTER_HEADERS } from "@continuedev/openai-adapters";
|
||||
|
||||
import { LLMOptions } from "../../index.js";
|
||||
import { osModelsEditPrompt } from "../templates/edit.js";
|
||||
|
||||
|
|
@ -18,6 +20,19 @@ class OpenRouter extends OpenAI {
|
|||
useLegacyCompletionsEndpoint: false,
|
||||
};
|
||||
|
||||
constructor(options: LLMOptions) {
|
||||
super({
|
||||
...options,
|
||||
requestOptions: {
|
||||
...options.requestOptions,
|
||||
headers: {
|
||||
...OPENROUTER_HEADERS,
|
||||
...options.requestOptions?.headers,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private isAnthropicModel(model?: string): boolean {
|
||||
if (!model) return false;
|
||||
const modelLower = model.toLowerCase();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ describe("PROVIDER_TOOL_SUPPORT", () => {
|
|||
it("should return true for Gemma models", () => {
|
||||
expect(supportsFn("gemma")).toBe(true);
|
||||
expect(supportsFn("gemma3")).toBe(true);
|
||||
expect(supportsFn("gemma4")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return undefined for unsupported models", () => {
|
||||
|
|
@ -54,6 +55,7 @@ describe("PROVIDER_TOOL_SUPPORT", () => {
|
|||
expect(supportsFn("GPT-4-turbo")).toBe(true);
|
||||
expect(supportsFn("O3-preview")).toBe(true);
|
||||
expect(supportsFn("Gemma3")).toBe(true);
|
||||
expect(supportsFn("Gemma4")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,28 +13,16 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
},
|
||||
azure: (model) => {
|
||||
const lower = model.toLowerCase();
|
||||
if (
|
||||
lower.startsWith("gpt-4") ||
|
||||
lower.startsWith("gpt-5") ||
|
||||
lower.startsWith("gpt-4.1") ||
|
||||
lower.startsWith("o1") ||
|
||||
lower.startsWith("o3") ||
|
||||
lower.startsWith("o4")
|
||||
)
|
||||
return true;
|
||||
if (lower.match(/^gpt-[4-9]/) || lower.match(/^o[1-9]/)) return true;
|
||||
return false;
|
||||
},
|
||||
openai: (model) => {
|
||||
const lower = model.toLowerCase();
|
||||
// https://platform.openai.com/docs/guides/function-calling#models-supporting-function-calling
|
||||
if (
|
||||
lower.startsWith("gpt-4") ||
|
||||
lower.startsWith("gpt-5") ||
|
||||
lower.startsWith("o1") ||
|
||||
lower.startsWith("o3") ||
|
||||
lower.startsWith("o4") ||
|
||||
lower.startsWith("codex") ||
|
||||
lower.startsWith("gpt-4.1")
|
||||
lower.match(/^gpt-[4-9]/) ||
|
||||
lower.match(/^o[1-9]/) ||
|
||||
lower.startsWith("codex")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -91,8 +79,9 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
},
|
||||
xAI: (model) => {
|
||||
const lowerCaseModel = model.toLowerCase();
|
||||
return ["grok-3", "grok-4", "grok-4-1", "grok-code"].some((val) =>
|
||||
lowerCaseModel.includes(val),
|
||||
return (
|
||||
!!lowerCaseModel.match(/grok-[3-9]/) ||
|
||||
lowerCaseModel.includes("grok-code")
|
||||
);
|
||||
},
|
||||
bedrock: (model) => {
|
||||
|
|
@ -260,6 +249,10 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
|
||||
return false;
|
||||
},
|
||||
inception: (model) => {
|
||||
const lower = model.toLowerCase();
|
||||
return lower.startsWith("mercury-2");
|
||||
},
|
||||
deepseek: (model) => {
|
||||
// https://api-docs.deepseek.com/quick_start/pricing
|
||||
// https://api-docs.deepseek.com/guides/function_calling
|
||||
|
|
@ -315,19 +308,14 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
}
|
||||
|
||||
const supportedPrefixes = [
|
||||
"openai/gpt-3.5",
|
||||
"openai/gpt-4",
|
||||
"openai/gpt-5",
|
||||
"openai/o1",
|
||||
"openai/o3",
|
||||
"openai/o4",
|
||||
"openai/gpt-",
|
||||
"openai/codex",
|
||||
"openai/gpt-oss",
|
||||
"anthropic/claude",
|
||||
"microsoft/phi-3",
|
||||
"google/gemini-flash-1.5",
|
||||
"google/gemini-2",
|
||||
"google/gemini-3",
|
||||
"google/gemma-4",
|
||||
"google/gemini-pro",
|
||||
"x-ai/grok",
|
||||
"qwen/qwen3",
|
||||
|
|
@ -360,6 +348,11 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
}
|
||||
}
|
||||
|
||||
// OpenAI o-series (o1, o3, o4, ...)
|
||||
if (baseModel.match(/^openai\/o[1-9]/)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const specificModels = [
|
||||
"qwen/qwq-32b",
|
||||
"qwen/qwen-2.5-72b-instruct",
|
||||
|
|
@ -396,13 +389,7 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
|
||||
// Check for common tool-supporting model patterns
|
||||
const toolSupportingPatterns = [
|
||||
"gpt-4",
|
||||
"gpt-5",
|
||||
"o1",
|
||||
"o3",
|
||||
"o4",
|
||||
"claude-3",
|
||||
"claude-4",
|
||||
"claude",
|
||||
"sonnet",
|
||||
"opus",
|
||||
"haiku",
|
||||
|
|
@ -419,11 +406,15 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"deepseek",
|
||||
];
|
||||
|
||||
return toolSupportingPatterns.some((pattern) => lower.includes(pattern));
|
||||
return (
|
||||
toolSupportingPatterns.some((pattern) => lower.includes(pattern)) ||
|
||||
!!lower.match(/gpt-[4-9]/) ||
|
||||
!!lower.match(/\bo[1-9]\b/)
|
||||
);
|
||||
},
|
||||
zAI: (model) => {
|
||||
const lower = model.toLowerCase();
|
||||
return lower.startsWith("glm-4") || lower.startsWith("glm-5");
|
||||
return !!lower.match(/^glm-[4-9]/);
|
||||
},
|
||||
moonshot: (model) => {
|
||||
// support moonshot models
|
||||
|
|
@ -503,14 +494,14 @@ export function isRecommendedAgentModel(modelName: string): boolean {
|
|||
[/deepseek/, /r1|reasoner/],
|
||||
[/gemini/, /2\.5/, /pro/],
|
||||
[/gemini/, /3\.1-pro|3-flash-preview/],
|
||||
[/gpt/, /-5|5\.1|5\.2/],
|
||||
[/gpt-[5-9]/],
|
||||
[/gpt-4\.1/],
|
||||
[/codex/],
|
||||
[/claude/, /sonnet/, /3\.7|3-7|-4/],
|
||||
[/claude/, /opus/, /-4/],
|
||||
[/claude/, /sonnet/, /3\.7|3-7|(?<!\d)-[4-9]/],
|
||||
[/claude/, /opus/, /(?<!\d)-[4-9]/],
|
||||
[/grok-code/],
|
||||
[/grok-4-1|grok-4\.1/],
|
||||
[/claude/, /4-5/],
|
||||
[/grok-[4-9][\.-]\d/],
|
||||
[/claude/, /[4-9]-[5-9]/],
|
||||
];
|
||||
for (const combo of recs) {
|
||||
if (combo.every((regex) => modelName.toLowerCase().match(regex))) {
|
||||
|
|
|
|||
10187
core/package-lock.json
generated
10187
core/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -57,6 +57,7 @@ export enum OnboardingModes {
|
|||
export interface ListHistoryOptions {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
workspaceDirectory?: string;
|
||||
}
|
||||
|
||||
export type ToCoreFromIdeOrWebviewProtocol = {
|
||||
|
|
@ -331,4 +332,17 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"process/isBackgrounded": [{ toolCallId: string }, boolean];
|
||||
"process/killTerminalProcess": [{ toolCallId: string }, void];
|
||||
"mdm/setLicenseKey": [{ licenseKey: string }, boolean];
|
||||
"models/fetch": [
|
||||
{ provider: string; apiKey?: string; apiBase?: string },
|
||||
{
|
||||
name: string;
|
||||
modelId?: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
popular?: boolean;
|
||||
contextLength?: number;
|
||||
maxTokens?: number;
|
||||
supportsTools?: boolean;
|
||||
}[],
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"process/markAsBackgrounded",
|
||||
"process/isBackgrounded",
|
||||
"process/killTerminalProcess",
|
||||
"models/fetch",
|
||||
];
|
||||
|
||||
// Message types to pass through from core to webview
|
||||
|
|
|
|||
|
|
@ -27,8 +27,10 @@ class LoggerClass {
|
|||
}),
|
||||
]
|
||||
: []),
|
||||
// Normal console.log behavior
|
||||
new winston.transports.Console(),
|
||||
// Use stderr to avoid corrupting IPC stdout stream in the binary
|
||||
new winston.transports.Console({
|
||||
stderrLevels: ["error", "warn", "info", "debug"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,87 @@ describe("Full session lifecycle", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Workspace directory filtering", () => {
|
||||
beforeAll(() => {
|
||||
historyManager.clearAll();
|
||||
historyManager.save({
|
||||
history: [],
|
||||
title: "Project A session 1",
|
||||
workspaceDirectory: "/home/user/project-a",
|
||||
sessionId: "ws-a-1",
|
||||
});
|
||||
historyManager.save({
|
||||
history: [],
|
||||
title: "Project B session 1",
|
||||
workspaceDirectory: "/home/user/project-b",
|
||||
sessionId: "ws-b-1",
|
||||
});
|
||||
historyManager.save({
|
||||
history: [],
|
||||
title: "Project A session 2",
|
||||
workspaceDirectory: "/home/user/project-a",
|
||||
sessionId: "ws-a-2",
|
||||
});
|
||||
historyManager.save({
|
||||
history: [],
|
||||
title: "No workspace",
|
||||
workspaceDirectory: "",
|
||||
sessionId: "ws-none",
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
historyManager.clearAll();
|
||||
});
|
||||
|
||||
test("Filter sessions by workspace directory", () => {
|
||||
const sessions = historyManager.list({
|
||||
workspaceDirectory: "/home/user/project-a",
|
||||
});
|
||||
expect(sessions.length).toBe(2);
|
||||
expect(
|
||||
sessions.every((s) => s.workspaceDirectory === "/home/user/project-a"),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("Omitting workspace returns all sessions", () => {
|
||||
const sessions = historyManager.list({});
|
||||
expect(sessions.length).toBe(4);
|
||||
});
|
||||
|
||||
test("Workspace filter is case-insensitive", () => {
|
||||
const sessions = historyManager.list({
|
||||
workspaceDirectory: "/HOME/USER/PROJECT-A",
|
||||
});
|
||||
expect(sessions.length).toBe(2);
|
||||
});
|
||||
|
||||
test("Non-matching workspace returns empty list", () => {
|
||||
const sessions = historyManager.list({
|
||||
workspaceDirectory: "/home/user/nonexistent",
|
||||
});
|
||||
expect(sessions.length).toBe(0);
|
||||
});
|
||||
|
||||
test("Workspace filter works with limit", () => {
|
||||
const sessions = historyManager.list({
|
||||
workspaceDirectory: "/home/user/project-a",
|
||||
limit: 1,
|
||||
});
|
||||
expect(sessions.length).toBe(1);
|
||||
});
|
||||
|
||||
test("Workspace filter works with limit and offset", () => {
|
||||
const sessions = historyManager.list({
|
||||
workspaceDirectory: "/home/user/project-a",
|
||||
limit: 1,
|
||||
offset: 1,
|
||||
});
|
||||
expect(sessions.length).toBe(1);
|
||||
expect(sessions[0].sessionId).toBe("ws-a-1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Many sessions created", () => {
|
||||
test("Create 100 sessions and list all", () => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,16 @@ export class HistoryManager {
|
|||
})
|
||||
.reverse();
|
||||
|
||||
// Filter by workspace directory if provided
|
||||
if (options.workspaceDirectory) {
|
||||
const target = options.workspaceDirectory.toLowerCase();
|
||||
sessions = sessions.filter(
|
||||
(session) =>
|
||||
typeof session.workspaceDirectory === "string" &&
|
||||
session.workspaceDirectory.toLowerCase() === target,
|
||||
);
|
||||
}
|
||||
|
||||
// Apply limit and offset
|
||||
if (options.limit) {
|
||||
const offset = options.offset || 0;
|
||||
|
|
|
|||
|
|
@ -53,9 +53,9 @@ If you prefer to use an open-weight model, then the Gemma family of Models from
|
|||
schema: v1
|
||||
|
||||
models:
|
||||
- name: "Gemma 3 27B"
|
||||
- name: "Gemma 4"
|
||||
provider: "ollama"
|
||||
model: "gemma3:27b"
|
||||
model: "gemma4"
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Together">
|
||||
|
|
|
|||
47
extensions/cli/package-lock.json
generated
47
extensions/cli/package-lock.json
generated
|
|
@ -5573,6 +5573,16 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
"version": "8.40.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.40.0.tgz",
|
||||
|
|
@ -10433,36 +10443,35 @@
|
|||
}
|
||||
},
|
||||
"node_modules/happy-dom": {
|
||||
"version": "20.0.2",
|
||||
"resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.0.2.tgz",
|
||||
"integrity": "sha512-pYOyu624+6HDbY+qkjILpQGnpvZOusItCk+rvF5/V+6NkcgTKnbOldpIy22tBnxoaLtlM9nXgoqAcW29/B7CIw==",
|
||||
"version": "20.8.9",
|
||||
"resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.8.9.tgz",
|
||||
"integrity": "sha512-Tz23LR9T9jOGVZm2x1EPdXqwA37G/owYMxRwU0E4miurAtFsPMQ1d2Jc2okUaSjZqAFz2oEn3FLXC5a0a+siyA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/node": ">=20.0.0",
|
||||
"@types/whatwg-mimetype": "^3.0.2",
|
||||
"whatwg-mimetype": "^3.0.0"
|
||||
"@types/ws": "^8.18.1",
|
||||
"entities": "^7.0.1",
|
||||
"whatwg-mimetype": "^3.0.0",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/happy-dom/node_modules/@types/node": {
|
||||
"version": "20.19.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.11.tgz",
|
||||
"integrity": "sha512-uug3FEEGv0r+jrecvUUpbY8lLisvIjg6AAic6a2bSP5OEOLeJsDSnvhCDov7ipFFMXS3orMpzlmi0ZcuGkBbow==",
|
||||
"node_modules/happy-dom/node_modules/entities": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
|
||||
"integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=0.12"
|
||||
},
|
||||
"node_modules/happy-dom/node_modules/undici-types": {
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/has-bigints": {
|
||||
"version": "1.1.0",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
pluginGroup=com.github.continuedev.continueintellijextension
|
||||
pluginVersion=1.0.67
|
||||
pluginVersion=1.0.68
|
||||
platformVersion=2024.1
|
||||
kotlin.stdlib.default.dependency=false
|
||||
org.gradle.configuration-cache=true
|
||||
|
|
|
|||
|
|
@ -153,7 +153,8 @@ class MessageTypes {
|
|||
"isItemTooBig",
|
||||
"process/markAsBackgrounded",
|
||||
"process/isBackgrounded",
|
||||
"process/killTerminalProcess"
|
||||
"process/killTerminalProcess",
|
||||
"models/fetch"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "1.3.38",
|
||||
"version": "1.3.39",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ interface ModelSelectionListboxProps {
|
|||
setSelectedProvider: (val: DisplayInfo) => void;
|
||||
topOptions?: DisplayInfo[];
|
||||
otherOptions?: DisplayInfo[];
|
||||
otherOptionsLabel?: string;
|
||||
searchPlaceholder?: string;
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ function ModelSelectionListbox({
|
|||
setSelectedProvider,
|
||||
topOptions = [],
|
||||
otherOptions = [],
|
||||
otherOptionsLabel = "Additional providers",
|
||||
searchPlaceholder = "Search models...",
|
||||
}: ModelSelectionListboxProps) {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
|
|
@ -197,7 +199,7 @@ function ModelSelectionListbox({
|
|||
{filteredOtherOptions.length > 0 && (
|
||||
<div className="py-1">
|
||||
<div className="text-description-muted px-3 py-1 text-xs font-medium uppercase tracking-wider">
|
||||
Additional providers
|
||||
{otherOptionsLabel}
|
||||
</div>
|
||||
{filteredOtherOptions.map((option, index) => (
|
||||
<ListboxOption
|
||||
|
|
|
|||
|
|
@ -1,20 +1,25 @@
|
|||
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
ArrowPathIcon,
|
||||
ArrowTopRightOnSquareIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useCallback, useContext, useEffect, useState } from "react";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import { Button, Input, StyledActionButton } from "../components";
|
||||
import Alert from "../components/gui/Alert";
|
||||
import ModelSelectionListbox from "../components/modelSelection/ModelSelectionListbox";
|
||||
import { ModelProviderTags } from "../components/modelSelection/utils";
|
||||
import { useAuth } from "../context/Auth";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { completionParamsInputs } from "../pages/AddNewModel/configs/completionParamsInputs";
|
||||
import { DisplayInfo } from "../pages/AddNewModel/configs/models";
|
||||
import {
|
||||
initializeOpenRouterModels,
|
||||
fetchProviderModels,
|
||||
initializeDynamicModels,
|
||||
} from "../pages/AddNewModel/configs/fetchProviderModels";
|
||||
import { DisplayInfo, ModelPackage } from "../pages/AddNewModel/configs/models";
|
||||
import {
|
||||
ProviderInfo,
|
||||
providers,
|
||||
} from "../pages/AddNewModel/configs/providers";
|
||||
import { useAppDispatch } from "../redux/hooks";
|
||||
import { updateSelectedModelByRole } from "../redux/thunks/updateSelectedModelByRole";
|
||||
|
||||
interface AddModelFormProps {
|
||||
onDone: () => void;
|
||||
|
|
@ -29,7 +34,6 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
const [selectedProvider, setSelectedProvider] = useState<ProviderInfo>(
|
||||
providers["openai"]!,
|
||||
);
|
||||
const dispatch = useAppDispatch();
|
||||
const { selectedProfile } = useAuth();
|
||||
const [selectedModel, setSelectedModel] = useState(
|
||||
selectedProvider.packages[0],
|
||||
|
|
@ -37,11 +41,43 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
const formMethods = useForm();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
// Initialize OpenRouter models from API on component mount
|
||||
const [fetchedModelsList, setFetchedModelsList] = useState<ModelPackage[]>(
|
||||
[],
|
||||
);
|
||||
const [isFetchingModels, setIsFetchingModels] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
void initializeOpenRouterModels();
|
||||
void initializeDynamicModels(ideMessenger);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setFetchedModelsList([]);
|
||||
}, [selectedProvider]);
|
||||
|
||||
const handleFetchModels = useCallback(async () => {
|
||||
const apiKey = formMethods.watch("apiKey");
|
||||
const apiBase = formMethods.watch("apiBase");
|
||||
if (!apiKey) return;
|
||||
|
||||
const providerAtFetchTime = selectedProvider.provider;
|
||||
setIsFetchingModels(true);
|
||||
try {
|
||||
const models = await fetchProviderModels(
|
||||
ideMessenger,
|
||||
providerAtFetchTime,
|
||||
apiKey,
|
||||
apiBase,
|
||||
);
|
||||
setFetchedModelsList((prev) =>
|
||||
selectedProvider.provider === providerAtFetchTime ? models : prev,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch models:", error);
|
||||
} finally {
|
||||
setIsFetchingModels(false);
|
||||
}
|
||||
}, [ideMessenger, selectedProvider, formMethods]);
|
||||
|
||||
const popularProviderTitles = [
|
||||
providers["openai"]?.title || "",
|
||||
providers["anthropic"]?.title || "",
|
||||
|
|
@ -88,6 +124,9 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
|
||||
useEffect(() => {
|
||||
setSelectedModel(selectedProvider.packages[0]);
|
||||
if (!selectedProvider.tags?.includes(ModelProviderTags.RequiresApiKey)) {
|
||||
formMethods.setValue("apiKey", "");
|
||||
}
|
||||
}, [selectedProvider]);
|
||||
|
||||
const requiresSkPrefix =
|
||||
|
|
@ -127,14 +166,15 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
profileId: "local",
|
||||
});
|
||||
|
||||
void dispatch(
|
||||
updateSelectedModelByRole({
|
||||
selectedProfile,
|
||||
if (selectedProfile) {
|
||||
ideMessenger.post("config/updateSelectedModel", {
|
||||
profileId: selectedProfile.id,
|
||||
role: "chat",
|
||||
modelTitle: model.title,
|
||||
}),
|
||||
);
|
||||
title: model.title,
|
||||
});
|
||||
}
|
||||
|
||||
formMethods.setValue("apiKey", "");
|
||||
onDone();
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +235,27 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
)}
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="block text-sm font-medium">Model</label>
|
||||
<button
|
||||
type="button"
|
||||
title="Use entered API key to fetch available models"
|
||||
className={`cursor-pointer border-none bg-transparent p-0 ${
|
||||
apiKeyValue &&
|
||||
apiKeyValue.length > 0 &&
|
||||
selectedProvider.provider !== "ollama" &&
|
||||
selectedProvider.provider !== "openrouter"
|
||||
? `text-description-muted hover:text-foreground`
|
||||
: "invisible"
|
||||
}`}
|
||||
onClick={handleFetchModels}
|
||||
disabled={isFetchingModels}
|
||||
>
|
||||
<ArrowPathIcon
|
||||
className={`h-3.5 w-3.5 ${isFetchingModels ? "animate-spin" : ""}`}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedModel}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
|
|
@ -204,19 +264,49 @@ export function AddModelForm({ onDone }: AddModelFormProps) {
|
|||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages ?? [];
|
||||
const match = options.find(
|
||||
const allOptions = [...options, ...fetchedModelsList];
|
||||
const match = allOptions.find(
|
||||
(option) => option.title === val.title,
|
||||
);
|
||||
if (match) {
|
||||
setSelectedModel(match);
|
||||
}
|
||||
}}
|
||||
topOptions={
|
||||
Object.entries(providers).find(
|
||||
topOptions={(() => {
|
||||
const providerInfo = Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages
|
||||
)?.[1];
|
||||
return (
|
||||
providerInfo?.popularPackages ?? providerInfo?.packages
|
||||
);
|
||||
})()}
|
||||
otherOptions={(() => {
|
||||
const providerInfo = Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1];
|
||||
const staticOther = providerInfo?.popularPackages
|
||||
? providerInfo.packages.filter(
|
||||
(p) =>
|
||||
!new Set(
|
||||
providerInfo.popularPackages!.map((pp) => pp.title),
|
||||
).has(p.title),
|
||||
)
|
||||
: undefined;
|
||||
// Merge dynamically fetched models (deduplicated)
|
||||
if (fetchedModelsList.length > 0) {
|
||||
const existingTitles = new Set(
|
||||
(providerInfo?.packages ?? []).map((p) => p.title),
|
||||
);
|
||||
const newModels = fetchedModelsList.filter(
|
||||
(m) => !existingTitles.has(m.title),
|
||||
);
|
||||
return [...(staticOther ?? []), ...newModels];
|
||||
}
|
||||
return staticOther;
|
||||
})()}
|
||||
otherOptionsLabel="Additional models"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
144
gui/src/pages/AddNewModel/configs/fetchProviderModels.ts
Normal file
144
gui/src/pages/AddNewModel/configs/fetchProviderModels.ts
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import { ModelProviderTags } from "../../../components/modelSelection/utils";
|
||||
import { IIdeMessenger } from "../../../context/IdeMessenger";
|
||||
import { ModelPackage } from "./models";
|
||||
import { models } from "./models";
|
||||
import { ollamaStaticModels, providers } from "./providers";
|
||||
|
||||
interface FetchedModel {
|
||||
name: string;
|
||||
modelId?: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
contextLength?: number;
|
||||
maxTokens?: number;
|
||||
supportsTools?: boolean;
|
||||
}
|
||||
|
||||
function modelParams(model: FetchedModel): Record<string, any> {
|
||||
const params: Record<string, any> = {};
|
||||
if (model.contextLength) params.contextLength = model.contextLength;
|
||||
if (model.maxTokens) {
|
||||
params.completionOptions = { maxTokens: model.maxTokens };
|
||||
}
|
||||
if (model.supportsTools) {
|
||||
params.capabilities = { tools: true };
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
function toOllamaPackage(model: FetchedModel): ModelPackage {
|
||||
return {
|
||||
title: model.name,
|
||||
description: model.description || model.name,
|
||||
refUrl: `https://ollama.com/library/${model.name}`,
|
||||
params: {
|
||||
title: model.name,
|
||||
model: model.name,
|
||||
...(model.supportsTools ? { capabilities: { tools: true } } : {}),
|
||||
},
|
||||
isOpenSource: true,
|
||||
tags: [ModelProviderTags.Local, ModelProviderTags.OpenSource],
|
||||
providerOptions: ["ollama"],
|
||||
icon: model.icon ?? "ollama.png",
|
||||
};
|
||||
}
|
||||
|
||||
function toOpenRouterPackage(model: FetchedModel): ModelPackage {
|
||||
const id = model.modelId ?? model.name;
|
||||
return {
|
||||
title: model.name,
|
||||
description: model.name,
|
||||
refUrl: `https://openrouter.ai/models/${id}`,
|
||||
params: {
|
||||
title: model.name,
|
||||
model: id,
|
||||
...modelParams(model),
|
||||
},
|
||||
isOpenSource: false,
|
||||
tags: [ModelProviderTags.RequiresApiKey],
|
||||
providerOptions: ["openrouter"],
|
||||
icon: model.icon ?? "openrouter.png",
|
||||
};
|
||||
}
|
||||
|
||||
function toGenericPackage(model: FetchedModel, provider: string): ModelPackage {
|
||||
const id = model.modelId ?? model.name;
|
||||
return {
|
||||
title: model.name,
|
||||
description: model.name,
|
||||
params: {
|
||||
title: model.name,
|
||||
model: id,
|
||||
...modelParams(model),
|
||||
},
|
||||
isOpenSource: false,
|
||||
providerOptions: [provider],
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchModels(
|
||||
ideMessenger: IIdeMessenger,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
apiBase?: string,
|
||||
): Promise<FetchedModel[]> {
|
||||
const response = await ideMessenger.request("models/fetch", {
|
||||
provider,
|
||||
apiKey,
|
||||
apiBase,
|
||||
});
|
||||
if (response.status === "error" || !response.content) {
|
||||
return [];
|
||||
}
|
||||
return response.content.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
export async function fetchProviderModels(
|
||||
ideMessenger: IIdeMessenger,
|
||||
provider: string,
|
||||
apiKey: string,
|
||||
apiBase?: string,
|
||||
): Promise<ModelPackage[]> {
|
||||
const models = await fetchModels(ideMessenger, provider, apiKey, apiBase);
|
||||
return models.map((m) => toGenericPackage(m, provider));
|
||||
}
|
||||
|
||||
export async function initializeDynamicModels(ideMessenger: IIdeMessenger) {
|
||||
const ollamaAutodetect = {
|
||||
...models.AUTODETECT,
|
||||
params: { ...models.AUTODETECT.params, title: "Ollama" },
|
||||
};
|
||||
|
||||
if (providers.ollama) {
|
||||
providers.ollama.popularPackages = [
|
||||
ollamaAutodetect,
|
||||
...ollamaStaticModels,
|
||||
];
|
||||
|
||||
try {
|
||||
const fetched = await fetchModels(ideMessenger, "ollama");
|
||||
const fetchedPkgs = fetched.map(toOllamaPackage);
|
||||
const popularTitles = new Set(
|
||||
providers.ollama.popularPackages.map((p) => p.title),
|
||||
);
|
||||
const additional = fetchedPkgs.filter((p) => !popularTitles.has(p.title));
|
||||
providers.ollama.packages = [
|
||||
...providers.ollama.popularPackages,
|
||||
...additional,
|
||||
];
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize Ollama models:", error);
|
||||
providers.ollama.packages = [...providers.ollama.popularPackages];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const fetched = await fetchModels(ideMessenger, "openrouter");
|
||||
const packages = fetched.map(toOpenRouterPackage);
|
||||
if (packages.length > 0 && providers.openrouter) {
|
||||
providers.openrouter.packages = packages;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize OpenRouter models:", error);
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ export interface ModelPackage {
|
|||
params: {
|
||||
model: ILLM["model"];
|
||||
templateMessages?: ILLM["templateMessages"];
|
||||
contextLength: ILLM["contextLength"];
|
||||
contextLength?: ILLM["contextLength"];
|
||||
stopTokens?: string[];
|
||||
promptTemplates?: ILLM["promptTemplates"];
|
||||
replace?: [string, string][];
|
||||
|
|
@ -2226,6 +2226,48 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
gpt5_4Pro: {
|
||||
title: "GPT-5.4 Pro",
|
||||
description:
|
||||
"OpenAI's smartest model with increased compute for more precise responses.",
|
||||
params: {
|
||||
model: "gpt-5.4-pro",
|
||||
contextLength: 1_050_000,
|
||||
completionOptions: { maxTokens: 128_000 },
|
||||
title: "GPT-5.4 Pro",
|
||||
},
|
||||
providerOptions: ["openai"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
gpt5_4: {
|
||||
title: "GPT-5.4",
|
||||
description:
|
||||
"OpenAI's high-intelligence flagship model with 1M context window.",
|
||||
params: {
|
||||
model: "gpt-5.4",
|
||||
contextLength: 1_050_000,
|
||||
completionOptions: { maxTokens: 128_000 },
|
||||
title: "GPT-5.4",
|
||||
},
|
||||
providerOptions: ["openai"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
gpt5_4Mini: {
|
||||
title: "GPT-5.4 Mini",
|
||||
description:
|
||||
"OpenAI's strongest mini model for coding, computer use, and high-volume workloads.",
|
||||
params: {
|
||||
model: "gpt-5.4-mini",
|
||||
contextLength: 400_000,
|
||||
completionOptions: { maxTokens: 128_000 },
|
||||
title: "GPT-5.4 Mini",
|
||||
},
|
||||
providerOptions: ["openai"],
|
||||
icon: "openai.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
codexMini: {
|
||||
title: "Codex Mini",
|
||||
description:
|
||||
|
|
@ -2424,6 +2466,19 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
},
|
||||
isOpenSource: true,
|
||||
},
|
||||
gemma4: {
|
||||
title: "Gemma 4",
|
||||
description:
|
||||
"Gemma 4 is a multimodal open model from Google, supporting text, image, tool use, and up to 128k context.",
|
||||
params: {
|
||||
title: "Gemma 4",
|
||||
model: "gemma4",
|
||||
contextLength: 128_000,
|
||||
},
|
||||
icon: "gemini.png",
|
||||
providerOptions: ["ollama"],
|
||||
isOpenSource: true,
|
||||
},
|
||||
phi3mini: {
|
||||
title: "Microsoft Phi 3 mini",
|
||||
description:
|
||||
|
|
@ -3256,4 +3311,20 @@ export const models: { [key: string]: ModelPackage } = {
|
|||
icon: "mimo.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
|
||||
// Inception Labs models
|
||||
mercury2: {
|
||||
title: "Mercury 2",
|
||||
description:
|
||||
"Inception Labs' fastest reasoning LLM with 128k context, tool calling, and structured outputs.",
|
||||
refUrl: "https://docs.inceptionlabs.ai/",
|
||||
params: {
|
||||
title: "Mercury 2",
|
||||
model: "mercury-2",
|
||||
contextLength: 128_000,
|
||||
},
|
||||
providerOptions: ["inception"],
|
||||
icon: "inception.png",
|
||||
isOpenSource: false,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
import { ModelProviderTags } from "../../../components/modelSelection/utils";
|
||||
import { ModelPackage } from "./models";
|
||||
|
||||
interface OpenRouterModel {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
context_length: number;
|
||||
hugging_face_id: string;
|
||||
}
|
||||
|
||||
function convertOpenRouterModelToPackage(model: OpenRouterModel): ModelPackage {
|
||||
return {
|
||||
title: model.name,
|
||||
description: model.description,
|
||||
refUrl: `https://openrouter.ai/models/${model.id}`,
|
||||
params: {
|
||||
title: model.name,
|
||||
model: model.id,
|
||||
contextLength: model.context_length,
|
||||
},
|
||||
isOpenSource: !!model.hugging_face_id,
|
||||
tags: [ModelProviderTags.RequiresApiKey],
|
||||
providerOptions: ["openrouter"],
|
||||
icon: "openrouter.png",
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchOpenRouterModelsFromAPI(): Promise<OpenRouterModel[]> {
|
||||
const OPENROUTER_API_URL = "https://openrouter.ai/api/v1/models";
|
||||
|
||||
try {
|
||||
const response = await fetch(OPENROUTER_API_URL);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch OpenRouter models: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.data || !Array.isArray(data.data)) {
|
||||
console.warn("Invalid OpenRouter models data structure from API");
|
||||
return [];
|
||||
}
|
||||
|
||||
return data.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching OpenRouter models from API:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOpenRouterModelsList(): Promise<ModelPackage[]> {
|
||||
const models: { [key: string]: ModelPackage } = {};
|
||||
|
||||
const apiModels = await fetchOpenRouterModelsFromAPI();
|
||||
|
||||
apiModels.forEach((model: OpenRouterModel) => {
|
||||
if (!model.id || !model.name) {
|
||||
console.warn("Skipping model with missing id or name", model);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a unique key from the model id (replace slashes and dots with underscores)
|
||||
const key = model.id.replace(/[\/.]/g, "_");
|
||||
|
||||
try {
|
||||
models[key] = convertOpenRouterModelToPackage(model);
|
||||
} catch (error) {
|
||||
console.error(`Failed to convert model ${model.id}:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
return Object.values(models);
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ import { ModelProviderTags } from "../../../components/modelSelection/utils";
|
|||
import { completionParamsInputs } from "./completionParamsInputs";
|
||||
import type { ModelPackage } from "./models";
|
||||
import { models } from "./models";
|
||||
import { getOpenRouterModelsList } from "./openRouterModel";
|
||||
|
||||
export interface InputDescriptor {
|
||||
inputType: HTMLInputTypeAttribute;
|
||||
|
|
@ -28,6 +27,7 @@ export interface ProviderInfo {
|
|||
longDescription?: string;
|
||||
tags?: ModelProviderTags[];
|
||||
packages: ModelPackage[];
|
||||
popularPackages?: ModelPackage[];
|
||||
params?: any;
|
||||
collectInputFor?: InputDescriptor[];
|
||||
refPage?: string;
|
||||
|
|
@ -41,38 +41,9 @@ const openSourceModels = Object.values(models).filter(
|
|||
({ isOpenSource }) => isOpenSource,
|
||||
);
|
||||
|
||||
// Initialize OpenRouter models placeholder with a loading placeholder
|
||||
const OPENROUTER_LOADING_PLACEHOLDER: ModelPackage = {
|
||||
title: "Loading models...",
|
||||
description: "Fetching available models from OpenRouter",
|
||||
params: {
|
||||
model: "placeholder",
|
||||
contextLength: 0,
|
||||
},
|
||||
isOpenSource: false,
|
||||
};
|
||||
|
||||
let openRouterModelsList: ModelPackage[] = [OPENROUTER_LOADING_PLACEHOLDER];
|
||||
|
||||
/**
|
||||
* Initialize OpenRouter models by fetching from the API
|
||||
* This should be called once when the component mounts
|
||||
*/
|
||||
export async function initializeOpenRouterModels() {
|
||||
try {
|
||||
const models = await getOpenRouterModelsList();
|
||||
if (models.length > 0) {
|
||||
openRouterModelsList = models;
|
||||
// Update the providers object with the fetched models
|
||||
if (providers.openrouter) {
|
||||
providers.openrouter.packages = openRouterModelsList;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize OpenRouter models:", error);
|
||||
// Keep placeholder on error so the UI doesn't break
|
||||
}
|
||||
}
|
||||
export const ollamaStaticModels = Object.values(models).filter(
|
||||
({ providerOptions }) => providerOptions?.includes("ollama"),
|
||||
);
|
||||
|
||||
export const apiBaseInput: InputDescriptor = {
|
||||
inputType: "text",
|
||||
|
|
@ -145,12 +116,15 @@ export const providers: Partial<Record<string, ProviderInfo>> = {
|
|||
openai: {
|
||||
title: "OpenAI",
|
||||
provider: "openai",
|
||||
description: "Use gpt-5.1, gpt-5, gpt-4, or any other OpenAI model",
|
||||
description: "Use gpt-5.4, gpt-5, or any other OpenAI model",
|
||||
longDescription:
|
||||
"Use gpt-5.1, gpt-5, gpt-4, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.",
|
||||
"Use gpt-5.4, gpt-5, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.",
|
||||
icon: "openai.png",
|
||||
tags: [ModelProviderTags.RequiresApiKey],
|
||||
packages: [
|
||||
models.gpt5_4Pro,
|
||||
models.gpt5_4,
|
||||
models.gpt5_4Mini,
|
||||
models.gpt5_2,
|
||||
models.gpt5_1,
|
||||
models.gpt5,
|
||||
|
|
@ -240,7 +214,14 @@ export const providers: Partial<Record<string, ProviderInfo>> = {
|
|||
},
|
||||
...completionParamsInputsConfigs,
|
||||
],
|
||||
packages: openRouterModelsList,
|
||||
packages: [
|
||||
{
|
||||
title: "Loading models...",
|
||||
description: "Fetching available models from OpenRouter",
|
||||
params: { model: "placeholder" },
|
||||
isOpenSource: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
moonshot: {
|
||||
|
|
@ -502,7 +483,7 @@ Select the \`GPT-4o\` model below to complete your provider configuration, but n
|
|||
title: "Ollama",
|
||||
},
|
||||
},
|
||||
...openSourceModels,
|
||||
...ollamaStaticModels,
|
||||
],
|
||||
collectInputFor: [
|
||||
...completionParamsInputsConfigs,
|
||||
|
|
@ -608,6 +589,28 @@ Select the \`GPT-4o\` model below to complete your provider configuration, but n
|
|||
],
|
||||
apiKeyUrl: "https://platform.minimax.io",
|
||||
},
|
||||
inception: {
|
||||
title: "Inception Labs",
|
||||
provider: "inception",
|
||||
icon: "inception.png",
|
||||
description:
|
||||
"Inception Labs provides Mercury 2, a fast diffusion model with 128k context and tool calling.",
|
||||
longDescription:
|
||||
"To get started with Inception Labs, obtain an API key from the [Inception Labs platform](https://platform.inceptionlabs.ai/). Mercury 2 is OpenAI-compatible and supports chat, tool calling, and structured outputs.",
|
||||
tags: [ModelProviderTags.RequiresApiKey],
|
||||
collectInputFor: [
|
||||
{
|
||||
inputType: "text",
|
||||
key: "apiKey",
|
||||
label: "API Key",
|
||||
placeholder: "Enter your Inception Labs API key",
|
||||
required: true,
|
||||
},
|
||||
...completionParamsInputsConfigs,
|
||||
],
|
||||
packages: [models.mercury2],
|
||||
apiKeyUrl: "https://platform.inceptionlabs.ai/",
|
||||
},
|
||||
deepseek: {
|
||||
title: "DeepSeek",
|
||||
provider: "deepseek",
|
||||
|
|
|
|||
6
packages/config-yaml/package-lock.json
generated
6
packages/config-yaml/package-lock.json
generated
|
|
@ -3476,9 +3476,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
"version": "4.7.8",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
|
||||
"integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
|
||||
"version": "4.7.9",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz",
|
||||
"integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
7
packages/continue-sdk/package-lock.json
generated
7
packages/continue-sdk/package-lock.json
generated
|
|
@ -1057,9 +1057,10 @@
|
|||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||
},
|
||||
"node_modules/express/node_modules/path-to-regexp": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
||||
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ=="
|
||||
"version": "0.1.13",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz",
|
||||
"integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-safe-stringify": {
|
||||
"version": "2.1.1",
|
||||
|
|
|
|||
6
packages/fetch/package-lock.json
generated
6
packages/fetch/package-lock.json
generated
|
|
@ -3003,9 +3003,9 @@
|
|||
"license": "ISC"
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
"version": "4.7.8",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
|
||||
"integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
|
||||
"version": "4.7.9",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz",
|
||||
"integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
6
packages/llm-info/package-lock.json
generated
6
packages/llm-info/package-lock.json
generated
|
|
@ -1931,9 +1931,9 @@
|
|||
"license": "ISC"
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
"version": "4.7.8",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
|
||||
"integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
|
||||
"version": "4.7.9",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz",
|
||||
"integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Bedrock } from "./providers/bedrock.js";
|
|||
import { Cohere } from "./providers/cohere.js";
|
||||
import { CometAPI } from "./providers/cometapi.js";
|
||||
import { Gemini } from "./providers/gemini.js";
|
||||
import { Inception } from "./providers/inception.js";
|
||||
import { MiniMax } from "./providers/minimax.js";
|
||||
import { Mistral } from "./providers/mistral.js";
|
||||
import { Ollama } from "./providers/ollama.js";
|
||||
|
|
@ -26,6 +27,7 @@ export const allModelProviders: ModelProvider[] = [
|
|||
Bedrock,
|
||||
Cohere,
|
||||
CometAPI,
|
||||
Inception,
|
||||
MiniMax,
|
||||
xAI,
|
||||
zAI,
|
||||
|
|
|
|||
32
packages/llm-info/src/providers/inception.ts
Normal file
32
packages/llm-info/src/providers/inception.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { ModelProvider } from "../types.js";
|
||||
|
||||
export const Inception: ModelProvider = {
|
||||
models: [
|
||||
{
|
||||
model: "mercury-2",
|
||||
displayName: "Mercury 2",
|
||||
contextLength: 128000,
|
||||
description:
|
||||
"Inception Labs' fastest reasoning diffusion model and their most powerful model, with tool calling and structured outputs support.",
|
||||
regex: /mercury-2/i,
|
||||
recommendedFor: ["chat"],
|
||||
},
|
||||
{
|
||||
model: "mercury-edit-2",
|
||||
displayName: "Mercury Edit 2",
|
||||
contextLength: 32000,
|
||||
description:
|
||||
"Inception Labs' code editing model for autocomplete, apply edit, and next edit suggestions.",
|
||||
regex: /mercury-edit-2/i,
|
||||
recommendedFor: ["autocomplete"],
|
||||
},
|
||||
{
|
||||
model: "mercury-coder-small",
|
||||
displayName: "Mercury Coder Small",
|
||||
contextLength: 32000,
|
||||
regex: /mercury-coder-small/i,
|
||||
},
|
||||
],
|
||||
id: "inception",
|
||||
displayName: "Inception Labs",
|
||||
};
|
||||
|
|
@ -10,9 +10,10 @@ export interface OpenRouterConfig extends OpenAIConfig {
|
|||
|
||||
// TODO: Extract detailed error info from OpenRouter's error.metadata.raw to surface better messages
|
||||
|
||||
const OPENROUTER_HEADERS: Record<string, string> = {
|
||||
export const OPENROUTER_HEADERS: Record<string, string> = {
|
||||
"HTTP-Referer": "https://www.continue.dev/",
|
||||
"X-Title": "Continue",
|
||||
"X-OpenRouter-Title": "Continue",
|
||||
"X-OpenRouter-Categories": "ide-extension",
|
||||
};
|
||||
|
||||
export class OpenRouterApi extends OpenAIApi {
|
||||
|
|
|
|||
|
|
@ -241,4 +241,5 @@ export {
|
|||
} from "./apis/AnthropicUtils.js";
|
||||
|
||||
export { isResponsesModel } from "./apis/openaiResponses.js";
|
||||
export { OPENROUTER_HEADERS } from "./apis/OpenRouter.js";
|
||||
export { extractBase64FromDataUrl, parseDataUrl } from "./util/url.js";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue