import { readFile } from "node:fs/promises"; export const PLUGIN_ID = "idea.cline-demo"; export const ADAPTER_ID = "cline-sdk"; export const VERSION = "0.1.0"; export const SDK_VERSION = "0.2.0"; export const NODE_VERSION = "24.15.0"; export const MAX_VALUE = 1024 * 1024; export const MAX_FRAME = 8 * MAX_VALUE; export const CAPABILITIES = ["streaming", "resume", "cancel", "hostTools", "probe"]; export class AdapterError extends Error { constructor(code, message) { super(message); this.code = code; } } export const invalid = () => new AdapterError("invalidRequest", "Invalid adapter request."); export function object(value) { if (!value || typeof value !== "object" || Array.isArray(value)) throw invalid(); return value; } export function string(value) { if (typeof value !== "string" || !value || value.includes("\0")) throw invalid(); return value; } export function bounded(value, maximum = MAX_VALUE) { if (Buffer.byteLength(JSON.stringify(value), "utf8") > maximum) throw invalid(); return value; } export function validateConfig(config, secrets) { object(config); object(secrets); bounded(config); bounded(secrets); if (Object.keys(config).some((key) => !["model", "endpoint"].includes(key)) || Object.keys(secrets).some((key) => key !== "apiKey") || typeof config.model !== "string" || !config.model.trim() || typeof config.endpoint !== "string" || (secrets.apiKey !== undefined && (typeof secrets.apiKey !== "string" || !secrets.apiKey))) { throw new AdapterError("invalidProfileConfig", "Invalid Cline profile configuration."); } let url; try { url = new URL(config.endpoint); } catch { throw invalid(); } if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) { throw new AdapterError("invalidProfileConfig", "Invalid provider endpoint."); } } export async function verifyRuntime() { if (process.versions.node !== NODE_VERSION) { throw new AdapterError("notReady", "Cline demo requires Node.js 24.15.0."); } const entry = import.meta.resolve("@cline/sdk"); const pkg = JSON.parse(await readFile(new URL("../package.json", entry), "utf8")); if (pkg.version !== SDK_VERSION) throw new AdapterError("notReady", "Cline SDK version is incompatible."); }