Merge branch 'main' into fix-trial-fim-import

This commit is contained in:
Nate Sesti 2025-06-02 13:54:18 -07:00 • committed by GitHub
commit a44cd3aeed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 2177 additions and 11 deletions

View file

@ -408,6 +408,7 @@ jobs:
run: |
cd core
npm test
npm run vitest
env:
IGNORE_API_KEY_TESTS: ${{ github.event.pull_request.head.repo.fork == true || github.actor == 'dependabot[bot]' }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

View file

@ -0,0 +1,233 @@
import { FQSN, SecretResult, SecretType } from "@continuedev/config-yaml";
import {
afterEach,
beforeEach,
describe,
expect,
Mock,
test,
vi,
} from "vitest";
import { IDE } from "../..";
import { ControlPlaneClient } from "../../control-plane/client";
import { LocalPlatformClient } from "./LocalPlatformClient";
vi.mock("../../util/paths", { spy: true });
describe("LocalPlatformClient", () => {
const testFQSN: FQSN = {
packageSlugs: [
{
ownerSlug: "test-owner-slug",
packageSlug: "test-package-slug",
},
],
secretName: "TEST_CONTINUE_SECRET_KEY",
};
const testFQSN2: FQSN = {
packageSlugs: [
{
ownerSlug: "test-owner-slug-2",
packageSlug: "test-package-slug-2",
},
],
secretName: "TEST_WORKSPACE_SECRET_KEY",
};
const testResolvedFQSN: SecretResult = {
found: true,
fqsn: testFQSN,
secretLocation: {
secretName: testFQSN.secretName,
secretType: SecretType.Organization,
orgSlug: "test-org-slug",
},
};
let testControlPlaneClient: ControlPlaneClient;
let testIde: IDE;
beforeEach(
/**dynamic import before each test for test isolation */
async () => {
const testFixtures = await import("../../test/fixtures");
testControlPlaneClient = testFixtures.testControlPlaneClient;
testIde = testFixtures.testIde;
},
);
let secretValue: string;
let envKeyValues: Record<string, unknown>;
let envKeyValuesString: string;
beforeEach(
/**generate unique env key value pairs for each test */
() => {
secretValue = Math.floor(Math.random() * 100) + "";
envKeyValues = {
TEST_CONTINUE_SECRET_KEY: secretValue,
TEST_WORKSPACE_SECRET_KEY: secretValue + "-workspace",
};
envKeyValuesString = Object.entries(envKeyValues)
.map(([key, value]) => `${key}=${value}`)
.join("\n");
},
);
afterEach(() => {
vi.resetAllMocks();
vi.restoreAllMocks();
vi.resetModules(); // clear dynamic imported module cache
});
test("should not be able to resolve FQSNs if they do not exist", async () => {
const localPlatformClient = new LocalPlatformClient(
null,
testControlPlaneClient,
testIde,
);
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]);
expect(resolvedFQSNs.length).toBeGreaterThan(0);
expect(resolvedFQSNs[0]?.found).toBe(false);
});
test("should be able to resolve FQSNs if they exist", async () => {
testControlPlaneClient.resolveFQSNs = vi.fn(async () => [testResolvedFQSN]);
const localPlatformClient = new LocalPlatformClient(
null,
testControlPlaneClient,
testIde,
);
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]);
expect(testControlPlaneClient.resolveFQSNs).toHaveBeenCalled();
expect(resolvedFQSNs).toEqual([testResolvedFQSN]);
expect(resolvedFQSNs[0]?.found).toBe(true);
});
describe("searches for secrets in local .env files", () => {
let getContinueDotEnv: Mock;
beforeEach(async () => {
const utilPaths = await import("../../util/paths");
getContinueDotEnv = vi.fn(() => envKeyValues);
utilPaths.getContinueDotEnv = getContinueDotEnv;
});
test("should be able to get secrets from ~/.continue/.env files", async () => {
const localPlatformClient = new LocalPlatformClient(
null,
testControlPlaneClient,
testIde,
);
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]);
expect(getContinueDotEnv).toHaveBeenCalled();
expect(resolvedFQSNs.length).toBe(1);
expect(
(resolvedFQSNs[0] as SecretResult & { value: unknown })?.value,
).toBe(secretValue);
console.log("debug1 resolved fqsn", resolvedFQSNs);
});
});
describe("should be able to get secrets from workspace .env files", () => {
test("should get secrets from <workspace>/.continue/.env and <workspace>/.env", async () => {
const originalIdeFileExists = testIde.fileExists;
testIde.fileExists = vi.fn(async (fileUri: string) =>
fileUri.includes(".env") ? true : originalIdeFileExists(fileUri),
);
const originalIdeReadFile = testIde.readFile;
const randomValueForContinueDirDotEnv =
"continue-dir-" + Math.floor(Math.random() * 100);
const randomValueForWorkspaceDotEnv =
"dotenv-" + Math.floor(Math.random() * 100);
testIde.readFile = vi.fn(async (fileUri: string) => {
// fileUri should contain .continue/.env and not .env
if (fileUri.match(/.*\.continue\/\.env.*/gi)?.length) {
return (
envKeyValuesString.split("\n")[0] + randomValueForContinueDirDotEnv
);
}
// filUri should contain .env and not .continue/.env
else if (fileUri.match(/.*(?<!\.continue\/)\.env.*/gi)?.length) {
return (
envKeyValuesString.split("\n")[1] + randomValueForWorkspaceDotEnv
);
}
return originalIdeReadFile(fileUri);
});
const localPlatformClient = new LocalPlatformClient(
null,
testControlPlaneClient,
testIde,
);
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([
testFQSN,
testFQSN2,
]);
// both the secrets should be present as they are retrieved from different files
expect(resolvedFQSNs.length).toBe(2);
const continueDirSecretValue = (
resolvedFQSNs[0] as SecretResult & { value: unknown }
)?.value;
const dotEnvSecretValue = (
resolvedFQSNs[1] as SecretResult & { value: unknown }
)?.value;
expect(continueDirSecretValue).toContain(secretValue);
expect(continueDirSecretValue).toContain(randomValueForContinueDirDotEnv);
expect(dotEnvSecretValue).toContain(secretValue + "-workspace");
expect(dotEnvSecretValue).toContain(randomValueForWorkspaceDotEnv);
});
test("should first get secrets from <workspace>/.continue/.env and then <workspace>/.env", async () => {
const originalIdeFileExists = testIde.fileExists;
testIde.fileExists = vi.fn(async (fileUri: string) =>
fileUri.includes(".env") ? true : originalIdeFileExists(fileUri),
);
const randomValueForContinueDirDotEnv =
"continue-dir-" + Math.floor(Math.random() * 100);
const randomValueForWorkspaceDotEnv =
"dotenv-" + Math.floor(Math.random() * 100);
const originalIdeReadFile = testIde.readFile;
testIde.readFile = vi.fn(async (fileUri: string) => {
// fileUri should contain .continue/.env and not .env
if (fileUri.match(/.*\.continue\/\.env.*/gi)?.length) {
return (
envKeyValuesString.split("\n")[0] + randomValueForContinueDirDotEnv
);
}
// filUri should contain .env and not .continue/.env
else if (fileUri.match(/.*(?<!\.continue\/)\.env.*/gi)?.length) {
return (
envKeyValuesString.split("\n")[0] + randomValueForWorkspaceDotEnv
);
}
return originalIdeReadFile(fileUri);
});
const localPlatformClient = new LocalPlatformClient(
null,
testControlPlaneClient,
testIde,
);
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]);
expect(resolvedFQSNs.length).toBe(1);
expect(
(resolvedFQSNs[0] as SecretResult & { value: unknown })?.value,
).toContain(secretValue);
// we check that workspace <workspace>.continue/.env does not override the <workspace>/.env secret
expect(
(resolvedFQSNs[0] as SecretResult & { value: unknown })?.value,
).toContain(randomValueForContinueDirDotEnv);
expect(
(resolvedFQSNs[0] as SecretResult & { value: unknown })?.value,
).not.toContain(randomValueForWorkspaceDotEnv);
});
});
});

View file

@ -17,12 +17,16 @@ export class LocalPlatformClient implements PlatformClient {
private readonly ide: IDE,
) {}
/**
* searches for the first valid secret file in order of ~/.continue/.env, <workspace>/.continue/.env, <workspace>/.env
*/
private async findSecretInEnvFiles(
fqsn: FQSN,
): Promise<SecretResult | undefined> {
const secretValue =
this.findSecretInLocalEnvFile(fqsn) ??
(await this.findSecretInWorkspaceEnvFiles(fqsn));
(await this.findSecretInWorkspaceEnvFiles(fqsn, true)) ??
(await this.findSecretInWorkspaceEnvFiles(fqsn, false));
if (secretValue) {
return {
@ -52,12 +56,16 @@ export class LocalPlatformClient implements PlatformClient {
private async findSecretInWorkspaceEnvFiles(
fqsn: FQSN,
insideContinue: boolean,
): Promise<string | undefined> {
try {
const workspaceDirs = await this.ide.getWorkspaceDirs();
for (const folder of workspaceDirs) {
const envFilePath = joinPathsToUri(folder, ".env");
const envFilePath = joinPathsToUri(
folder,
insideContinue ? ".continue" : "",
".env",
);
try {
const fileExists = await this.ide.fileExists(envFilePath);
if (fileExists) {

View file

@ -29,4 +29,7 @@ export default {
globalSetup: "<rootDir>/test/jest.global-setup.ts",
setupFilesAfterEnv: ["<rootDir>/test/jest.setup-after-env.js"],
maxWorkers: 1, // equivalent to CLI --runInBand
modulePathIgnorePatterns: [
"<rootDir>/config/yaml/LocalPlatformClient.test.ts",
],
};

View file

@ -78,6 +78,13 @@ export class NextEditProvider {
if (llm instanceof OpenAI) {
llm.useLegacyCompletionsEndpoint = true;
}
// TODO: Resolve import error with TRIAL_FIM_MODEL
// else if (
// llm.providerName === "free-trial" &&
// llm.model !== TRIAL_FIM_MODEL
// ) {
// llm.model = TRIAL_FIM_MODEL;
// }
return llm;
}

1766
core/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@
"description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js",
"scripts": {
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"vitest": "vitest run LocalPlatformClient",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage && open ./coverage/lcov-report/index.html",
"tsc:check": "tsc -p ./ --noEmit",
"build:npm": "tsc -p ./tsconfig.npm.json",
@ -41,7 +42,8 @@
"onnxruntime-common": "1.14.0",
"onnxruntime-web": "1.14.0",
"ts-jest": "^29.1.1",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"vitest": "^3.1.4"
},
"dependencies": {
"@aws-sdk/client-bedrock-runtime": "^3.779.0",

5
core/vitest.config.ts Normal file
View file

@ -0,0 +1,5 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {},
});

View file

@ -12,6 +12,18 @@ Morph provides a fast apply model that helps you quickly and accurately apply co
- uses: morphllm/morph-v0
with:
MORPH_API_KEY: ${{ secrets.MORPH_API_KEY }}
```
or
```yaml title="config.yaml"
- name: Morph Fast Apply
provider: openai
model: morph-v2
apiKey: <YOUR_MORPH_API_KEY>
apiBase: https://api.morphllm.com/v1/
roles:
- apply
promptTemplates:
apply: "<code>{{{ original_code }}}</code>\n<update>{{{ new_code }}}</update>"
```
</TabItem>
<TabItem value="json" label="JSON">
@ -21,10 +33,10 @@ Morph provides a fast apply model that helps you quickly and accurately apply co
{
"title": "Morph Fast Apply",
"provider": "openai",
"model": "morph-v0",
"model": "morph-v2",
"apiKey": "<YOUR_MORPH_API_KEY>",
"apiBase": "https://api.morphllm.com/v1/",
"roles": ["apply", "chat"],
"roles": ["apply"],
"promptTemplates": {
"apply": "<code>{{{ original_code }}}</code>\n<update>{{{ new_code }}}</update>"
}
@ -34,3 +46,67 @@ Morph provides a fast apply model that helps you quickly and accurately apply co
```
</TabItem>
</Tabs>
## Embeddings model
We recommend configuring **morph-embedding-v2** as your embeddings model.
<Tabs groupId="config-example">
<TabItem value="yaml" label="YAML">
```yaml title="config.yaml"
models:
- name: Morph Embeddings
provider: openai
model: morph-embedding-v2
apiKey: <YOUR_MORPH_API_KEY>
apiBase: https://api.morphllm.com/v1/
roles:
- embed
```
</TabItem>
<TabItem value="json" label="JSON">
```json title="config.json"
{
"embeddingsProvider": {
"provider": "openai",
"model": "morph-embedding-v2",
"apiKey": "<YOUR_MORPH_API_KEY>",
"apiBase": "https://api.morphllm.com/v1/"
}
}
```
</TabItem>
</Tabs>
## Reranking model
We recommend configuring **morph-rerank-v2** as your reranking model.
<Tabs groupId="config-example">
<TabItem value="yaml" label="YAML">
```yaml title="config.yaml"
models:
- name: Morph Reranker
provider: cohere
model: morph-rerank-v2
apiKey: <YOUR_MORPH_API_KEY>
apiBase: https://api.morphllm.com/v1/
roles:
- rerank
```
</TabItem>
<TabItem value="json" label="JSON">
```json title="config.json"
{
"reranker": {
"name": "cohere",
"params": {
"model": "morph-rerank-v2",
"apiKey": "<YOUR_MORPH_API_KEY>",
"apiBase": "https://api.morphllm.com/v1/"
}
}
}
```
</TabItem>
</Tabs>

View file

@ -16,8 +16,8 @@
"noEmitOnError": false,
"types": ["node", "jest"],
"outDir": "dist",
"declaration": true
// "sourceMap": true
"declaration": true,
"sourceMap": true
},
"include": ["src/**/*"]
}

View file

@ -4,6 +4,27 @@ export const Anthropic: ModelProvider = {
id: "anthropic",
displayName: "Anthropic",
models: [
{
model: "claude-sonnet-4-20250514",
displayName: "Claude 4 Sonnet",
contextLength: 200000,
maxCompletionTokens: 8192,
description:
"Most intelligent model with the highest level of intelligence and capability.",
// Sometimes written as claude-4-sonnet, other times as claude-sonnet-4
regex: /claude-(?:4-sonnet|sonnet-4).*/i,
recommendedFor: ["chat"],
},
{
model: "claude-opus-4-20250514",
displayName: "Claude 4 Opus",
contextLength: 200000,
maxCompletionTokens: 8192,
description:
"Most intelligent model with the highest level of intelligence and capability.",
regex: /claude-(?:4-opus|opus-4).*/i,
recommendedFor: ["chat"],
},
{
model: "claude-3-5-sonnet-latest",
displayName: "Claude 3.5 Sonnet",

View file

@ -5,12 +5,13 @@ import { chatChunk, customFetch } from "../util.js";
import { OpenAIApi } from "./OpenAI.js";
import { FimCreateParamsStreaming } from "./base.js";
export const DEEPSEEK_API_BASE = "https://api.deepseek.com/";
export class DeepSeekApi extends OpenAIApi {
apiBase: string = "https://api.deepseek.com/";
constructor(config: DeepseekConfig) {
super({
...config,
provider: "openai",
apiBase: config.apiBase ?? DEEPSEEK_API_BASE,
});
}

View file

@ -5,12 +5,13 @@ import { chatChunk, customFetch } from "../util.js";
import { OpenAIApi } from "./OpenAI.js";
import { FimCreateParamsStreaming } from "./base.js";
export const INCEPTION_API_BASE = "https://api.inceptionlabs.ai/v1/";
export class InceptionApi extends OpenAIApi {
apiBase: string = "https://api.inceptionlabs.ai/v1/";
constructor(config: InceptionConfig) {
super({
...config,
provider: "openai",
apiBase: config.apiBase ?? INCEPTION_API_BASE,
});
}

View file

@ -1,5 +1,9 @@
import { ModelConfig } from "@continuedev/config-yaml";
import * as dotenv from "dotenv";
import { DEEPSEEK_API_BASE } from "../apis/DeepSeek.js";
import { INCEPTION_API_BASE } from "../apis/Inception.js";
import { OpenAIApi } from "../apis/OpenAI.js";
import { constructLlmApi } from "../index.js";
import { getLlmApi, testChat, testCompletion, testEmbed } from "./util.js";
dotenv.config();
@ -109,3 +113,43 @@ TESTS.forEach((config) => {
testConfig({ name: config.model, ...config });
});
});
describe("Configuration", () => {
it("should configure DeepSeek OpenAI client with correct apiBase and apiKey", () => {
const deepseek = constructLlmApi({
provider: "deepseek",
apiKey: "sk-xxx",
});
expect((deepseek as OpenAIApi).openai.baseURL).toBe(DEEPSEEK_API_BASE);
expect((deepseek as OpenAIApi).openai.apiKey).toBe("sk-xxx");
const deepseek2 = constructLlmApi({
provider: "deepseek",
apiKey: "sk-xxx",
apiBase: "https://api.example.com",
});
expect((deepseek2 as OpenAIApi).openai.baseURL).toBe(
"https://api.example.com",
);
});
it("should configure Inception OpenAI client with correct apiBase and apiKey", () => {
const inception = constructLlmApi({
provider: "inception",
apiKey: "sk-xxx",
});
expect((inception as OpenAIApi).openai.baseURL).toBe(INCEPTION_API_BASE);
expect((inception as OpenAIApi).openai.apiKey).toBe("sk-xxx");
const inception2 = constructLlmApi({
provider: "inception",
apiKey: "sk-xxx",
apiBase: "https://api.example.com",
});
expect((inception2 as OpenAIApi).openai.baseURL).toBe(
"https://api.example.com",
);
});
});