Merge pull request #4976 from continuedev/nate/continuedev/hub

implementation of hub client
This commit is contained in:
Nate Sesti 2025-04-04 18:40:04 -07:00 • committed by GitHub
commit 6e2301d628
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 4064 additions and 0 deletions

2
packages/hub/.npmignore Normal file
View file

@ -0,0 +1,2 @@
.env
test

View file

@ -0,0 +1,20 @@
import path from "path";
import { fileURLToPath } from "url";
export default {
transform: {
"\\.[jt]sx?$": ["ts-jest", { useESM: true }],
},
moduleNameMapper: {
"(.+)\\.js": "$1",
},
extensionsToTreatAsEsm: [".ts"],
preset: "ts-jest/presets/default-esm",
testTimeout: 10000,
testEnvironment: "node",
globals: {
__dirname: path.dirname(fileURLToPath(import.meta.url)),
__filename: path.resolve(fileURLToPath(import.meta.url)),
},
};

3831
packages/hub/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

24
packages/hub/package.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "@continuedev/hub",
"version": "0.0.4",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"build": "tsc"
},
"author": "Continue Dev, Inc.",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/config-yaml": "^1.0.70"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"cross-env": "^7.0.3",
"jest": "^29.7.0",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2"
}
}

View file

@ -0,0 +1,121 @@
import {
AssistantUnrolled,
ConfigResult,
FQSN,
FullSlug,
SecretResult,
} from "@continuedev/config-yaml";
import { IContinueHubClient } from "./IContinueHubClient.js";
interface ContinueHubClientOptions {
apiKey?: string;
apiBase?: string;
fetchOptions?: RequestInit;
}
export class ContinueHubClient implements IContinueHubClient {
private readonly apiKey?: string;
private readonly apiBase: string;
private readonly fetchOptions?: RequestInit;
constructor(options: ContinueHubClientOptions) {
this.apiKey = options.apiKey;
this.apiBase = options.apiBase ?? "https://api.continue.dev";
this.fetchOptions = options.fetchOptions;
}
private async request(path: string, init: RequestInit): Promise<Response> {
const url = new URL(path, this.apiBase).toString();
const finalInit: RequestInit = {
...this.fetchOptions,
...init,
headers: {
...this.fetchOptions?.headers,
...init.headers,
},
};
if (this.apiKey) {
finalInit.headers = {
...finalInit.headers,
Authorization: `Bearer ${this.apiKey}`,
};
}
const resp = await fetch(url, finalInit);
if (!resp.ok) {
throw new Error(
`Control plane request failed: ${resp.status} ${await resp.text()}`,
);
}
return resp;
}
async resolveFQSNs(
fqsns: FQSN[],
orgScopeId: string | null,
): Promise<(SecretResult | undefined)[]> {
const resp = await this.request("ide/sync-secrets", {
method: "POST",
body: JSON.stringify({ fqsns, orgScopeId }),
});
return (await resp.json()) as any;
}
async listAssistants(options: {
organizationId: string | null;
alwaysUseProxy?: boolean;
}): Promise<
{
configResult: ConfigResult<AssistantUnrolled>;
ownerSlug: string;
packageSlug: string;
iconUrl: string;
rawYaml: string;
}[]
> {
const organizationId = options.organizationId;
const alwaysUseProxy = options.alwaysUseProxy ?? false;
try {
const urlObj = new URL(
organizationId ? "ide/list-assistants" : "ide/list-assistants",
this.apiBase,
);
if (organizationId) {
urlObj.searchParams.set("organizationId", organizationId);
}
if (alwaysUseProxy) {
urlObj.searchParams.set("alwaysUseProxy", alwaysUseProxy.toString());
}
const url = urlObj.toString();
const resp = await this.request(url, {
method: "GET",
});
return (await resp.json()) as any;
} catch (e) {
return [];
}
}
async listAssistantFullSlugs(
organizationId: string | null,
): Promise<FullSlug[] | null> {
const url = organizationId
? `ide/list-assistant-full-slugs?organizationId=${organizationId}`
: "ide/list-assistant-full-slugs";
try {
const resp = await this.request(url, {
method: "GET",
});
const { fullSlugs } = (await resp.json()) as any;
return fullSlugs;
} catch (e) {
return null;
}
}
}

View file

@ -0,0 +1,41 @@
import {
AssistantUnrolled,
ConfigResult,
FQSN,
FullSlug,
SecretResult,
} from "@continuedev/config-yaml";
/**
* Interface for the Continue Hub client.
*/
export interface IContinueHubClient {
resolveFQSNs(
fqsns: FQSN[],
orgScopeId: string | null,
): Promise<(SecretResult | undefined)[]>;
/**
* Do a full reload of all assistants used in the organization by the user.
*/
listAssistants(options: {
organizationId: string | null;
alwaysUseProxy?: boolean;
}): Promise<
{
configResult: ConfigResult<AssistantUnrolled>;
ownerSlug: string;
packageSlug: string;
iconUrl: string;
rawYaml: string;
}[]
>;
/**
* Get the list of FullSlugs (ownerSlug/packageSlug@versionSlug) for all assistant uses in the organization for the user.
* Can be used to poll for changes to assistants and then full reload when needed.
*/
listAssistantFullSlugs(
organizationId: string | null,
): Promise<FullSlug[] | null>;
}

View file

@ -0,0 +1,2 @@
export * from "./ContinueHubClient.js";
export * from "./IContinueHubClient.js";

View file

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"useDefineForClassFields": true,
"lib": ["DOM", "ESNext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmitOnError": false,
"types": ["node", "jest"],
"outDir": "dist",
"declaration": true
// "sourceMap": true
},
"include": ["src/**/*"]
}