feat: local block loading for hub assistants
This commit is contained in:
parent
81671b295c
commit
05d86030de
4 changed files with 158 additions and 57 deletions
62
core/config/yaml/loadLocalYamlBlocks.ts
Normal file
62
core/config/yaml/loadLocalYamlBlocks.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import {
|
||||
AssistantUnrolled,
|
||||
ConfigResult,
|
||||
PackageIdentifier,
|
||||
RegistryClient,
|
||||
unrollAssistantFromContent,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { IDE } from "../..";
|
||||
import { ControlPlaneClient } from "../../control-plane/client";
|
||||
import { LocalPlatformClient } from "./LocalPlatformClient";
|
||||
|
||||
// This is a certain approach to unrolling local YAML where it
|
||||
// 1. creates an assistant out of all local blocks
|
||||
// 2. unrolls it like a local assistant
|
||||
export async function unrollLocalYamlBlocks(
|
||||
packageIdentifiers: PackageIdentifier[],
|
||||
ide: IDE,
|
||||
registryClient: RegistryClient,
|
||||
orgScopeId: string | null,
|
||||
controlPlaneClient: ControlPlaneClient,
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
try {
|
||||
const unrollResult = await unrollAssistantFromContent(
|
||||
{
|
||||
uriType: "file",
|
||||
filePath: "",
|
||||
},
|
||||
"name: FILLER\nschema: v1\nversion: 0.0.1",
|
||||
registryClient,
|
||||
{
|
||||
currentUserSlug: "",
|
||||
onPremProxyUrl: null,
|
||||
orgScopeId,
|
||||
platformClient: new LocalPlatformClient(
|
||||
orgScopeId,
|
||||
controlPlaneClient,
|
||||
ide,
|
||||
),
|
||||
renderSecrets: true,
|
||||
injectBlocks: packageIdentifiers,
|
||||
},
|
||||
);
|
||||
const config =
|
||||
"config" in unrollResult ? unrollResult.config : unrollResult;
|
||||
const errors = "errors" in unrollResult ? unrollResult.errors : [];
|
||||
return {
|
||||
config,
|
||||
errors,
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
} catch (error) {
|
||||
let message = "An unknown error occurred while loading local YAML blocks";
|
||||
if (error instanceof Error) {
|
||||
message += ": " + error.message;
|
||||
}
|
||||
return {
|
||||
config: undefined,
|
||||
errors: [{ message, fatal: false }],
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,10 @@ import {
|
|||
ConfigResult,
|
||||
ConfigValidationError,
|
||||
isAssistantUnrolledNonNullable,
|
||||
MCPServer,
|
||||
mergeUnrolledAssistants,
|
||||
ModelRole,
|
||||
PackageIdentifier,
|
||||
RegistryClient,
|
||||
Rule,
|
||||
TEMPLATE_VAR_REGEX,
|
||||
unrollAssistant,
|
||||
validateConfigYaml,
|
||||
|
|
@ -17,13 +16,11 @@ import { dirname } from "node:path";
|
|||
|
||||
import {
|
||||
ContinueConfig,
|
||||
ExperimentalMCPOptions,
|
||||
IContextProvider,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
IdeSettings,
|
||||
ILLMLogger,
|
||||
RuleWithSource,
|
||||
} from "../..";
|
||||
import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton";
|
||||
import DocsContextProvider from "../../context/providers/DocsContextProvider";
|
||||
|
|
@ -41,39 +38,13 @@ import { getControlPlaneEnvSync } from "../../control-plane/env";
|
|||
import { getToolsForIde } from "../../tools";
|
||||
import { getCleanUriPath } from "../../util/uri";
|
||||
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
|
||||
import { unrollLocalYamlBlocks } from "./loadLocalYamlBlocks";
|
||||
import { LocalPlatformClient } from "./LocalPlatformClient";
|
||||
import { llmsFromModelConfig } from "./models";
|
||||
|
||||
function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource {
|
||||
if (typeof rule === "string") {
|
||||
return {
|
||||
rule: rule,
|
||||
source: "rules-block",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
source: "rules-block",
|
||||
rule: rule.rule,
|
||||
globs: rule.globs,
|
||||
name: rule.name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function convertYamlMcpToContinueMcp(
|
||||
server: MCPServer,
|
||||
): ExperimentalMCPOptions {
|
||||
return {
|
||||
transport: {
|
||||
type: "stdio",
|
||||
command: server.command,
|
||||
args: server.args ?? [],
|
||||
env: server.env,
|
||||
cwd: server.cwd,
|
||||
} as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union)
|
||||
timeout: server.connectionTimeout,
|
||||
};
|
||||
}
|
||||
import {
|
||||
convertYamlMcpToContinueMcp,
|
||||
convertYamlRuleToContinueRule,
|
||||
} from "./yamlToContinueConfig";
|
||||
|
||||
async function loadConfigYaml(options: {
|
||||
overrideConfigYaml: AssistantUnrolled | undefined;
|
||||
|
|
@ -93,46 +64,65 @@ async function loadConfigYaml(options: {
|
|||
} = options;
|
||||
|
||||
// Add local .continue blocks
|
||||
const allLocalBlocks: PackageIdentifier[] = [];
|
||||
for (const blockType of BLOCK_TYPES) {
|
||||
const localBlockPromises = BLOCK_TYPES.map(async (blockType) => {
|
||||
const localBlocks = await getAllDotContinueDefinitionFiles(
|
||||
ide,
|
||||
{ includeGlobal: true, includeWorkspace: true, fileExtType: "yaml" },
|
||||
blockType,
|
||||
);
|
||||
allLocalBlocks.push(
|
||||
...localBlocks.map((b) => ({
|
||||
uriType: "file" as const,
|
||||
filePath: b.path,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
const rootPath =
|
||||
packageIdentifier.uriType === "file"
|
||||
? dirname(getCleanUriPath(packageIdentifier.filePath))
|
||||
: undefined;
|
||||
return localBlocks.map((b) => ({
|
||||
uriType: "file" as const,
|
||||
filePath: b.path,
|
||||
}));
|
||||
});
|
||||
const localPackageIdentifiers: PackageIdentifier[] = (
|
||||
await Promise.all(localBlockPromises)
|
||||
).flat();
|
||||
|
||||
// logger.info(
|
||||
// `Loading config.yaml from ${JSON.stringify(packageIdentifier)} with root path ${rootPath}`,
|
||||
// );
|
||||
|
||||
// Registry client is only used if local blocks are present, but logic same for hub/local assistants
|
||||
const getRegistryClient = async () => {
|
||||
const rootPath =
|
||||
packageIdentifier.uriType === "file"
|
||||
? dirname(getCleanUriPath(packageIdentifier.filePath))
|
||||
: undefined;
|
||||
return new RegistryClient({
|
||||
accessToken: await controlPlaneClient.getAccessToken(),
|
||||
apiBase: getControlPlaneEnvSync(ideSettings.continueTestEnvironment)
|
||||
.CONTROL_PLANE_URL,
|
||||
rootPath,
|
||||
});
|
||||
};
|
||||
|
||||
const errors: ConfigValidationError[] = [];
|
||||
|
||||
let config: AssistantUnrolled | undefined;
|
||||
|
||||
if (overrideConfigYaml) {
|
||||
config = overrideConfigYaml;
|
||||
if (localPackageIdentifiers.length > 0) {
|
||||
const unrolledLocal = await unrollLocalYamlBlocks(
|
||||
localPackageIdentifiers,
|
||||
ide,
|
||||
await getRegistryClient(),
|
||||
orgScopeId,
|
||||
controlPlaneClient,
|
||||
);
|
||||
if (unrolledLocal.errors) {
|
||||
errors.push(...unrolledLocal.errors);
|
||||
}
|
||||
if (unrolledLocal.config) {
|
||||
config = mergeUnrolledAssistants(config, unrolledLocal.config);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// This is how we allow use of blocks locally
|
||||
const unrollResult = await unrollAssistant(
|
||||
packageIdentifier,
|
||||
new RegistryClient({
|
||||
accessToken: await controlPlaneClient.getAccessToken(),
|
||||
apiBase: getControlPlaneEnvSync(ideSettings.continueTestEnvironment)
|
||||
.CONTROL_PLANE_URL,
|
||||
rootPath,
|
||||
}),
|
||||
await getRegistryClient(),
|
||||
{
|
||||
renderSecrets: true,
|
||||
currentUserSlug: "",
|
||||
|
|
@ -143,7 +133,7 @@ async function loadConfigYaml(options: {
|
|||
controlPlaneClient,
|
||||
ide,
|
||||
),
|
||||
injectBlocks: allLocalBlocks,
|
||||
injectBlocks: localPackageIdentifiers,
|
||||
},
|
||||
);
|
||||
config = unrollResult.config;
|
||||
|
|
|
|||
33
core/config/yaml/yamlToContinueConfig.ts
Normal file
33
core/config/yaml/yamlToContinueConfig.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { MCPServer, Rule } from "@continuedev/config-yaml";
|
||||
import { ExperimentalMCPOptions, RuleWithSource } from "../..";
|
||||
|
||||
export function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource {
|
||||
if (typeof rule === "string") {
|
||||
return {
|
||||
rule: rule,
|
||||
source: "rules-block",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
source: "rules-block",
|
||||
rule: rule.rule,
|
||||
globs: rule.globs,
|
||||
name: rule.name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function convertYamlMcpToContinueMcp(
|
||||
server: MCPServer,
|
||||
): ExperimentalMCPOptions {
|
||||
return {
|
||||
transport: {
|
||||
type: "stdio",
|
||||
command: server.command,
|
||||
args: server.args ?? [],
|
||||
env: server.env,
|
||||
cwd: server.cwd,
|
||||
} as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union)
|
||||
timeout: server.connectionTimeout,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { ConfigYaml } from "../schemas/index.js";
|
||||
import { AssistantUnrolled, ConfigYaml } from "../schemas/index.js";
|
||||
|
||||
export function mergePackages(
|
||||
current: ConfigYaml,
|
||||
|
|
@ -15,3 +15,19 @@ export function mergePackages(
|
|||
docs: [...(current.docs ?? []), ...(incoming.docs ?? [])],
|
||||
};
|
||||
}
|
||||
|
||||
export function mergeUnrolledAssistants(
|
||||
current: AssistantUnrolled,
|
||||
incoming: AssistantUnrolled,
|
||||
): AssistantUnrolled {
|
||||
return {
|
||||
...current,
|
||||
rules: [...(current.rules ?? []), ...(incoming.rules ?? [])],
|
||||
models: [...(current.models ?? []), ...(incoming.models ?? [])],
|
||||
docs: [...(current.docs ?? []), ...(incoming.docs ?? [])],
|
||||
context: [...(current.context ?? []), ...(incoming.context ?? [])],
|
||||
data: [...(current.data ?? []), ...(incoming.data ?? [])],
|
||||
mcpServers: [...(current.mcpServers ?? []), ...(incoming.mcpServers ?? [])],
|
||||
prompts: [...(current.prompts ?? []), ...(incoming.prompts ?? [])],
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue