Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/continuedev/continue into d…
Browse files Browse the repository at this point in the history
…allin/docsapalooza
  • Loading branch information
RomneyDa committed Jan 22, 2025
2 parents c637b7b + aaf1a60 commit 6ca5063
Show file tree
Hide file tree
Showing 59 changed files with 1,373 additions and 367 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"internalConsoleOptions": "openOnSessionStart",
"cwd": "${workspaceFolder}/binary",
"env": {
// "CONTROL_PLANE_ENV": "test",
"CONTINUE_DEVELOPMENT": "true",
"CONTINUE_GLOBAL_DIR": "${workspaceFolder}/extensions/.continue-debug"
}
Expand Down
2 changes: 1 addition & 1 deletion binary/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 38 additions & 4 deletions binary/src/IpcMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,46 @@ class IPCMessengerBase<
response &&
typeof response[Symbol.asyncIterator] === "function"
) {
for await (const update of response) {
this.send(msg.messageType, update, msg.messageId);
let next = await response.next();
while (!next.done) {
this.send(
msg.messageType,
{
done: false,
content: next.value,
status: "success",
},
msg.messageId,
);
next = await response.next();
}
this.send(msg.messageType, { done: true }, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: next.value,
status: "success",
},
msg.messageId,
);
} else {
this.send(msg.messageType, response, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: response,
status: "success",
},
msg.messageId,
);
}
} catch (e: any) {
this.send(
msg.messageType,
{ done: true, error: e.message, status: "error" },
msg.messageId,
);

console.warn(`Error running handler for "${msg.messageType}": `, e);
this._onErrorHandlers.forEach((handler) => {
handler(e);
Expand All @@ -62,6 +94,7 @@ class IPCMessengerBase<
}

private _unfinishedLine: string | undefined = undefined;

protected _handleData(data: Buffer) {
const d = data.toString();
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
Expand Down Expand Up @@ -169,6 +202,7 @@ export class IpcMessenger<
process.exit(1);
});
}

_sendMsg(msg: Message) {
const d = JSON.stringify(msg);
// console.log("[info] Sending message: ", d);
Expand Down
42 changes: 38 additions & 4 deletions binary/src/TcpMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,46 @@ export class TcpMessenger<
response &&
typeof response[Symbol.asyncIterator] === "function"
) {
for await (const update of response) {
this.send(msg.messageType, update, msg.messageId);
let next = await response.next();
while (!next.done) {
this.send(
msg.messageType,
{
done: false,
content: next.value,
status: "success",
},
msg.messageId,
);
next = await response.next();
}
this.send(msg.messageType, { done: true }, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: next.value,
status: "success",
},
msg.messageId,
);
} else {
this.send(msg.messageType, response || {}, msg.messageId);
this.send(
msg.messageType,
{
done: true,
content: response,
status: "success",
},
msg.messageId,
);
}
} catch (e: any) {
this.send(
msg.messageType,
{ done: true, error: e.message, status: "error" },
msg.messageId,
);

console.warn(`Error running handler for "${msg.messageType}": `, e);
this._onErrorHandlers.forEach((handler) => {
handler(e);
Expand All @@ -98,6 +130,7 @@ export class TcpMessenger<
}

private _unfinishedLine: string | undefined = undefined;

private _handleData(data: Buffer) {
const d = data.toString();
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
Expand Down Expand Up @@ -151,6 +184,7 @@ export class TcpMessenger<
data,
});
}

request<T extends keyof FromProtocol>(
messageType: T,
data: FromProtocol[T][0],
Expand Down
48 changes: 33 additions & 15 deletions core/config/ConfigHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import Ollama from "../llm/llms/Ollama.js";
import { GlobalContext } from "../util/GlobalContext.js";
import { getConfigJsonPath } from "../util/paths.js";

import { ConfigResult } from "@continuedev/config-yaml";
import { ConfigResult, ConfigYaml } from "@continuedev/config-yaml";
import * as YAML from "yaml";
import { controlPlaneEnv } from "../control-plane/env.js";
import { usePlatform } from "../control-plane/flags.js";
import { localPathToUri } from "../util/pathToUri.js";
import {
LOCAL_ONBOARDING_CHAT_MODEL,
ONBOARDING_LOCAL_MODEL_TITLE,
Expand All @@ -28,7 +30,7 @@ import {
ProfileDescription,
ProfileLifecycleManager,
} from "./ProfileLifecycleManager.js";
import { localPathToUri } from "../util/pathToUri.js";
import { clientRenderHelper } from "./yaml/clientRender.js";

export type { ProfileDescription };

Expand Down Expand Up @@ -109,19 +111,35 @@ export class ConfigHandler {
this.profiles = this.profiles.filter(
(profile) => profile.profileDescription.id === "local",
);
assistants.forEach((assistant) => {
const profileLoader = new PlatformProfileLoader(
assistant.configResult,
assistant.ownerSlug,
assistant.packageSlug,
this.controlPlaneClient,
this.ide,
this.ideSettingsPromise,
this.writeLog,
this.reloadConfig.bind(this),
);
this.profiles.push(new ProfileLifecycleManager(profileLoader));
});
await Promise.all(
assistants.map(async (assistant) => {
let renderedConfig: ConfigYaml | undefined = undefined;
if (assistant.configResult.config) {
renderedConfig = await clientRenderHelper(
YAML.stringify(assistant.configResult.config),
this.ide,
this.controlPlaneClient,
);
}

const profileLoader = new PlatformProfileLoader(
{ ...assistant.configResult, config: renderedConfig },
assistant.ownerSlug,
assistant.packageSlug,
this.controlPlaneClient,
this.ide,
this.ideSettingsPromise,
this.writeLog,
this.reloadConfig.bind(this),
);
this.profiles = [
...this.profiles.filter(
(profile) => profile.profileDescription.id === "local",
),
new ProfileLifecycleManager(profileLoader),
];
}),
);

this.notifyProfileListeners(
this.profiles.map((profile) => profile.profileDescription),
Expand Down
18 changes: 15 additions & 3 deletions core/config/profile/PlatformProfileLoader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ClientConfigYaml } from "@continuedev/config-yaml/dist/schemas/index.js";
import { ConfigYaml } from "@continuedev/config-yaml/dist/schemas/index.js";
import * as YAML from "yaml";

import { ControlPlaneClient } from "../../control-plane/client.js";
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";

import { ConfigResult } from "@continuedev/config-yaml";
import { ProfileDescription } from "../ProfileLifecycleManager.js";
import { clientRenderHelper } from "../yaml/clientRender.js";
import doLoadConfig from "./doLoadConfig.js";
import { IProfileLoader } from "./IProfileLoader.js";

Expand All @@ -24,7 +26,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
description: ProfileDescription;

constructor(
private configResult: ConfigResult<ClientConfigYaml>,
private configResult: ConfigResult<ConfigYaml>,
private readonly ownerSlug: string,
private readonly packageSlug: string,
private readonly controlPlaneClient: ControlPlaneClient,
Expand All @@ -49,8 +51,18 @@ export default class PlatformProfileLoader implements IProfileLoader {
if (!newConfigResult) {
return;
}

let renderedConfig: ConfigYaml | undefined = undefined;
if (newConfigResult.config) {
renderedConfig = await clientRenderHelper(
YAML.stringify(newConfigResult.config),
this.ide,
this.controlPlaneClient,
);
}

this.configResult = {
config: newConfigResult.config,
config: renderedConfig,
errors: newConfigResult.errors,
configLoadInterrupted: false,
};
Expand Down
9 changes: 6 additions & 3 deletions core/config/profile/doLoadConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import fs from "fs";

import { ConfigResult, ConfigValidationError } from "@continuedev/config-yaml";
import { ClientConfigYaml } from "@continuedev/config-yaml/dist/schemas";
import {
ConfigResult,
ConfigValidationError,
ConfigYaml,
} from "@continuedev/config-yaml";
import {
ContinueConfig,
ContinueRcJson,
Expand All @@ -27,7 +30,7 @@ export default async function doLoadConfig(
controlPlaneClient: ControlPlaneClient,
writeLog: (message: string) => Promise<void>,
overrideConfigJson: SerializedContinueConfig | undefined,
overrideConfigYaml: ClientConfigYaml | undefined,
overrideConfigYaml: ConfigYaml | undefined,
platformConfigMetadata: PlatformConfigMetadata | undefined,
workspaceId?: string,
): Promise<ConfigResult<ContinueConfig>> {
Expand Down
40 changes: 40 additions & 0 deletions core/config/yaml/clientRender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
clientRender,
PlatformClient,
SecretStore,
} from "@continuedev/config-yaml";

import { IDE } from "../..";
import { ControlPlaneClient } from "../../control-plane/client";

export async function clientRenderHelper(
unrolledAssistant: string,
ide: IDE,
controlPlaneClient: ControlPlaneClient,
) {
const ideSecretStore: SecretStore = {
get: async function (secretName: string): Promise<string | undefined> {
const results = await ide.readSecrets([secretName]);
return results[secretName];
},
set: async function (
secretName: string,
secretValue: string,
): Promise<void> {
return await ide.writeSecrets({
[secretName]: secretValue,
});
},
};

const platformClient: PlatformClient = {
resolveFQSNs: controlPlaneClient.resolveFQSNs.bind(controlPlaneClient),
};

const userId = await controlPlaneClient.userId;
return await clientRender(
unrolledAssistant,
ideSecretStore,
userId ? platformClient : undefined,
);
}
Loading

0 comments on commit 6ca5063

Please sign in to comment.