cursor-agent-bridge 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -16
- package/dist/cli.mjs +828 -5
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +18 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{server-CuHDT_fJ.mjs → server-Bk7ol2lA.mjs} +275 -95
- package/dist/server-Bk7ol2lA.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/server-CuHDT_fJ.mjs.map +0 -1
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { startServer } from \"./server.js\";\n\nfunction readArg(name: string, fallback: string | undefined) {\n const index = process.argv.indexOf(name);\n return index >= 0 ? process.argv[index + 1] : fallback;\n}\n\nconst command =\n process.argv[2] && !process.argv[2]?.startsWith(\"-\")\n ? process.argv[2]\n : \"serve\";\n\nif (\n command === \"help\" ||\n process.argv.includes(\"--help\") ||\n process.argv.includes(\"-h\")\n) {\n console.log(`cursor-agent-bridge\n\nUsage:\n cursor-agent-bridge serve [--host 127.0.0.1] [--port 4646]\n\nEnvironment:\n HOST Listen host, default 127.0.0.1\n PORT Listen port, default 4646\n CURSOR_AGENT_PATH Cursor Agent CLI path, default agent\n`);\n process.exit(0);\n}\n\nif (command !== \"serve\") {\n console.error(`Unknown command: ${command}`);\n process.exit(1);\n}\n\nconst host = readArg(\"--host\", process.env.HOST) ?? \"127.0.0.1\";\nconst port = Number(readArg(\"--port\", process.env.PORT) ?? 4646);\n\nconst server = await startServer({\n host,\n port,\n ...(process.env.CURSOR_AGENT_PATH\n ? { agentPath: process.env.CURSOR_AGENT_PATH }\n : {}),\n});\nconsole.log(`cursor-agent-bridge listening on http://${host}:${port}`);\n\nfunction shutdown() {\n server.close(() => process.exit(0));\n}\n\nprocess.on(\"SIGINT\", shutdown);\nprocess.on(\"SIGTERM\", shutdown);\n"],"mappings":";;;AAIA,SAAS,QAAQ,MAAc,UAA8B;CAC3D,MAAM,QAAQ,QAAQ,KAAK,QAAQ,IAAI;CACvC,OAAO,SAAS,IAAI,QAAQ,KAAK,QAAQ,KAAK;AAChD;AAEA,MAAM,UACJ,QAAQ,KAAK,MAAM,CAAC,QAAQ,KAAK,EAAE,EAAE,WAAW,GAAG,IAC/C,QAAQ,KAAK,KACb;AAEN,IACE,YAAY,UACZ,QAAQ,KAAK,SAAS,QAAQ,KAC9B,QAAQ,KAAK,SAAS,IAAI,GAC1B;CACA,QAAQ,IAAI;;;;;;;;;CASb;CACC,QAAQ,KAAK,CAAC;AAChB;AAEA,IAAI,YAAY,SAAS;CACvB,QAAQ,MAAM,oBAAoB,SAAS;CAC3C,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,OAAO,QAAQ,UAAU,QAAQ,IAAI,IAAI,KAAK;AACpD,MAAM,OAAO,OAAO,QAAQ,UAAU,QAAQ,IAAI,IAAI,KAAK,IAAI;AAE/D,MAAM,SAAS,MAAM,YAAY;CAC/B;CACA;CACA,GAAI,QAAQ,IAAI,oBACZ,EAAE,WAAW,QAAQ,IAAI,kBAAkB,IAC3C,CAAC;AACP,CAAC;AACD,QAAQ,IAAI,2CAA2C,KAAK,GAAG,MAAM;AAErE,SAAS,WAAW;CAClB,OAAO,YAAY,QAAQ,KAAK,CAAC,CAAC;AACpC;AAEA,QAAQ,GAAG,UAAU,QAAQ;AAC7B,QAAQ,GAAG,WAAW,QAAQ"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["execFileAsync","packageJson.version","packageJson.version"],"sources":["../src/cli-args.ts","../src/codex-config.ts","../src/doctor.ts","../src/launch-agent.ts","../src/upgrade.ts","../src/cli.ts"],"sourcesContent":["export function readArg(name: string, fallback: string | undefined) {\n const index = process.argv.indexOf(name)\n if (index < 0) return fallback\n const value = process.argv[index + 1]\n if (!value || value.startsWith(\"-\"))\n throw new Error(`Missing value for ${name}`)\n return value\n}\n\nexport function parsePort(value: string | undefined, fallback: number) {\n if (value === undefined) return fallback\n const port = Number(value)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new Error(`Invalid port: ${value}`)\n }\n return port\n}\n\nexport function readHostAndPort(defaultHost = \"127.0.0.1\", defaultPort = 4646) {\n const host = readArg(\"--host\", process.env.HOST) ?? defaultHost\n const port = parsePort(readArg(\"--port\", process.env.PORT), defaultPort)\n return { host, port }\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\"\nimport { homedir } from \"node:os\"\nimport { dirname, join } from \"node:path\"\n\nexport const DEFAULT_CODEX_PROFILE = \"cursor\"\n\nexport type CodexConfigOptions = {\n host: string\n port: number\n profile?: string\n}\n\nexport type CodexConfigFields = {\n modelProvider?: string\n model?: string\n providerName?: string\n baseUrl?: string\n wireApi?: string\n}\n\nexport type CodexConfigCheckResult = {\n ok: boolean\n issues: string[]\n}\n\nexport type WriteCodexConfigResult = {\n path: string\n created: boolean\n updated: boolean\n}\n\nexport function resolveCodexConfigPath(\n profile = DEFAULT_CODEX_PROFILE,\n homeDir = homedir(),\n) {\n assertValidProfile(profile)\n return join(homeDir, \".codex\", `${profile}.config.toml`)\n}\n\nexport function buildBaseUrl(host: string, port: number) {\n return `http://${host}:${port}/v1`\n}\n\nexport function buildCodexConfigToml(options: CodexConfigOptions) {\n const profile = options.profile ?? DEFAULT_CODEX_PROFILE\n assertValidProfile(profile)\n const baseUrl = buildBaseUrl(options.host, options.port)\n return `model_provider = ${formatTomlString(profile)}\nmodel = \"auto\"\n\n[model_providers.${profile}]\nname = \"Cursor Agent Bridge\"\nbase_url = ${formatTomlString(baseUrl)}\nwire_api = \"responses\"\n`\n}\n\nexport function parseCodexConfig(\n content: string,\n profile = DEFAULT_CODEX_PROFILE,\n) {\n assertValidProfile(profile)\n const fields: CodexConfigFields = {}\n const providerSection = `model_providers.${profile}`\n let section = \"\"\n\n for (const rawLine of content.split(\"\\n\")) {\n const line = rawLine.trim()\n if (!line || line.startsWith(\"#\")) continue\n\n const sectionMatch = line.match(/^\\[(.+)\\]$/)\n if (sectionMatch) {\n section = sectionMatch[1] ?? \"\"\n continue\n }\n\n const assignment = line.match(/^([A-Za-z0-9_.-]+)\\s*=\\s*(.+)$/)\n if (!assignment) continue\n\n const key = assignment[1] ?? \"\"\n const value = parseTomlValue(assignment[2] ?? \"\")\n\n if (section === providerSection) {\n if (key === \"name\") fields.providerName = value\n if (key === \"base_url\") fields.baseUrl = value\n if (key === \"wire_api\") fields.wireApi = value\n continue\n }\n\n if (section) continue\n if (key === \"model_provider\") fields.modelProvider = value\n if (key === \"model\") fields.model = value\n }\n\n return fields\n}\n\nexport function checkCodexConfig(\n content: string,\n options: CodexConfigOptions,\n): CodexConfigCheckResult {\n const profile = options.profile ?? DEFAULT_CODEX_PROFILE\n const expectedBaseUrl = buildBaseUrl(options.host, options.port)\n const fields = parseCodexConfig(content, profile)\n const issues: string[] = []\n\n if (fields.modelProvider !== profile) {\n issues.push(\n `model_provider should be \"${profile}\"${\n fields.modelProvider\n ? `, found \"${fields.modelProvider}\"`\n : \", but it is missing\"\n }`,\n )\n }\n\n if (fields.baseUrl !== expectedBaseUrl) {\n issues.push(\n `base_url should be \"${expectedBaseUrl}\"${\n fields.baseUrl ? `, found \"${fields.baseUrl}\"` : \", but it is missing\"\n }`,\n )\n }\n\n if (fields.wireApi !== \"responses\") {\n issues.push(\n `wire_api should be \"responses\"${\n fields.wireApi ? `, found \"${fields.wireApi}\"` : \", but it is missing\"\n }`,\n )\n }\n\n return { ok: issues.length === 0, issues }\n}\n\nexport async function writeCodexConfig(\n options: CodexConfigOptions & {\n filePath: string\n force?: boolean\n },\n): Promise<WriteCodexConfigResult> {\n let existing: string | undefined\n\n try {\n existing = await readFile(options.filePath, \"utf8\")\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error\n }\n\n if (existing === undefined) {\n await mkdir(dirname(options.filePath), { recursive: true })\n await writeFile(options.filePath, buildCodexConfigToml(options), \"utf8\")\n return { path: options.filePath, created: true, updated: false }\n }\n\n const merged = mergeCodexConfig(existing, options)\n if (\"error\" in merged) throw new Error(merged.error)\n\n if (!merged.changed) {\n return { path: options.filePath, created: false, updated: false }\n }\n\n await writeFile(options.filePath, merged.content, \"utf8\")\n return { path: options.filePath, created: false, updated: true }\n}\n\nfunction mergeCodexConfig(\n existing: string,\n options: CodexConfigOptions & { force?: boolean },\n) {\n const profile = options.profile ?? DEFAULT_CODEX_PROFILE\n assertValidProfile(profile)\n const providerSection = `model_providers.${profile}`\n const expected = buildCodexConfigToml(options)\n const parsed = parseCodexConfig(existing, profile)\n\n if (\n parsed.modelProvider &&\n parsed.modelProvider !== profile &&\n !options.force\n ) {\n return {\n error: `model_provider is \"${parsed.modelProvider}\". Re-run with --force to switch it to \"${profile}\".`,\n }\n }\n\n const lines = existing.split(\"\\n\")\n const output: string[] = []\n let section = \"\"\n let inProviderSection = false\n let sawModelProvider = false\n let sawModel = false\n let sawProviderSection = false\n const handledProviderKeys = new Set<string>()\n\n for (const rawLine of lines) {\n const trimmed = rawLine.trim()\n const sectionMatch = trimmed.match(/^\\[(.+)\\]$/)\n if (sectionMatch) {\n if (inProviderSection) appendMissingProviderKeys()\n section = sectionMatch[1] ?? \"\"\n inProviderSection = section === providerSection\n if (inProviderSection) sawProviderSection = true\n output.push(rawLine)\n continue\n }\n\n const assignment = trimmed.match(/^([A-Za-z0-9_.-]+)\\s*=\\s*(.+)$/)\n if (!assignment) {\n output.push(rawLine)\n continue\n }\n\n const key = assignment[1] ?? \"\"\n\n if (!section) {\n if (key === \"model_provider\") {\n sawModelProvider = true\n output.push(`model_provider = ${formatTomlString(profile)}`)\n continue\n }\n if (key === \"model\") {\n sawModel = true\n if (parsed.model === undefined || options.force) {\n output.push('model = \"auto\"')\n } else {\n output.push(rawLine)\n }\n continue\n }\n }\n\n if (inProviderSection) {\n if (key === \"name\") {\n handledProviderKeys.add(\"name\")\n output.push('name = \"Cursor Agent Bridge\"')\n continue\n }\n if (key === \"base_url\") {\n handledProviderKeys.add(\"base_url\")\n output.push(\n `base_url = ${formatTomlString(buildBaseUrl(options.host, options.port))}`,\n )\n continue\n }\n if (key === \"wire_api\") {\n handledProviderKeys.add(\"wire_api\")\n output.push('wire_api = \"responses\"')\n continue\n }\n }\n\n output.push(rawLine)\n }\n\n if (inProviderSection) appendMissingProviderKeys()\n\n const missingTopLevel: string[] = []\n if (!sawModelProvider)\n missingTopLevel.push(`model_provider = ${formatTomlString(profile)}`)\n if (!sawModel) missingTopLevel.push('model = \"auto\"')\n\n let content = output.join(\"\\n\").trimEnd()\n if (missingTopLevel.length > 0) {\n content = `${missingTopLevel.join(\"\\n\")}\\n${content}`\n }\n\n if (!sawProviderSection) {\n const providerBlock = expected.split(\"\\n\").slice(3).join(\"\\n\")\n content = `${content}\\n\\n${providerBlock}\\n`\n }\n\n const changed = normalizeToml(content) !== normalizeToml(existing)\n return { content: `${content.trimEnd()}\\n`, changed }\n\n function appendMissingProviderKeys() {\n if (!handledProviderKeys.has(\"name\")) {\n output.push('name = \"Cursor Agent Bridge\"')\n }\n if (!handledProviderKeys.has(\"base_url\")) {\n output.push(\n `base_url = ${formatTomlString(buildBaseUrl(options.host, options.port))}`,\n )\n }\n if (!handledProviderKeys.has(\"wire_api\")) {\n output.push('wire_api = \"responses\"')\n }\n }\n}\n\nfunction assertValidProfile(profile: string) {\n if (/^[A-Za-z0-9_-]+$/.test(profile)) return\n throw new Error(\n \"Invalid Codex profile. Use only letters, numbers, underscores, or hyphens.\",\n )\n}\n\nfunction formatTomlString(value: string) {\n return `\"${value\n .replaceAll(\"\\\\\", \"\\\\\\\\\")\n .replaceAll('\"', '\\\\\"')\n .replaceAll(\"\\b\", \"\\\\b\")\n .replaceAll(\"\\t\", \"\\\\t\")\n .replaceAll(\"\\n\", \"\\\\n\")\n .replaceAll(\"\\f\", \"\\\\f\")\n .replaceAll(\"\\r\", \"\\\\r\")}\"`\n}\n\nfunction normalizeToml(content: string) {\n return content.replace(/\\r\\n/g, \"\\n\").trimEnd()\n}\n\nfunction parseTomlValue(raw: string) {\n const trimmed = stripInlineTomlComment(raw).trim()\n if (trimmed.startsWith('\"') && trimmed.endsWith('\"')) {\n return unescapeTomlString(trimmed.slice(1, -1))\n }\n if (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\")) {\n return trimmed.slice(1, -1)\n }\n return trimmed\n}\n\nfunction unescapeTomlString(value: string) {\n return value.replace(\n /\\\\([\"\\\\btnfr])/g,\n (_match, escaped: string) =>\n ({\n '\"': '\"',\n \"\\\\\": \"\\\\\",\n b: \"\\b\",\n t: \"\\t\",\n n: \"\\n\",\n f: \"\\f\",\n r: \"\\r\",\n })[escaped] ?? escaped,\n )\n}\n\nfunction stripInlineTomlComment(raw: string) {\n let quote: string | undefined\n for (let index = 0; index < raw.length; index += 1) {\n const char = raw[index]\n if ((char === '\"' || char === \"'\") && raw[index - 1] !== \"\\\\\") {\n quote = quote === char ? undefined : (quote ?? char)\n continue\n }\n\n if (!quote && char === \"#\") {\n return raw.slice(0, index)\n }\n }\n\n return raw\n}\n","import { execFile } from \"node:child_process\"\nimport { readFile } from \"node:fs/promises\"\nimport { promisify } from \"node:util\"\nimport packageJson from \"../package.json\" with { type: \"json\" }\nimport {\n checkCodexConfig,\n DEFAULT_CODEX_PROFILE,\n resolveCodexConfigPath,\n} from \"./codex-config.js\"\nimport { CursorRunner } from \"./cursor/runner.js\"\n\nconst execFileAsync = promisify(execFile)\n\nexport type DoctorCheck = {\n name: string\n ok: boolean\n message: string\n hint?: string\n}\n\nexport type ExecFileFn = (\n file: string,\n args?: readonly string[] | null,\n options?: { timeout?: number },\n) => Promise<unknown>\n\nexport type DoctorOptions = {\n host: string\n port: number\n agentPath?: string\n profile?: string\n nodeVersionRange?: string\n codexConfigPath?: string\n skipCodexConfig?: boolean\n runner?: CursorRunner\n fetchFn?: typeof fetch\n execFileFn?: ExecFileFn\n readFileFn?: typeof readFile\n}\n\nexport async function runDoctor(options: DoctorOptions) {\n const checks: DoctorCheck[] = []\n const fetchFn = options.fetchFn ?? fetch\n const execFileFn = options.execFileFn ?? execFileAsync\n const readFileFn = options.readFileFn ?? readFile\n const agentPath =\n options.agentPath ?? process.env.CURSOR_AGENT_PATH ?? \"agent\"\n const profile = options.profile ?? DEFAULT_CODEX_PROFILE\n const codexConfigPath =\n options.codexConfigPath ?? resolveCodexConfigPath(profile)\n\n checks.push(\n checkNodeVersion(options.nodeVersionRange ?? packageJson.engines.node),\n )\n checks.push({\n name: \"bridge-version\",\n ok: true,\n message: `cursor-agent-bridge ${packageJson.version}`,\n })\n\n const agentCheck = await checkAgentExecutable(agentPath, execFileFn)\n checks.push(agentCheck)\n\n if (agentCheck.ok) {\n checks.push(await checkAgentLogin(agentPath, options.runner))\n }\n\n checks.push(await checkBridgeHealth(options.host, options.port, fetchFn))\n\n if (!options.skipCodexConfig) {\n checks.push(\n await checkCodexConfigFile({\n codexConfigPath,\n host: options.host,\n port: options.port,\n profile,\n readFileFn,\n }),\n )\n }\n\n return {\n ok: checks.every((check) => check.ok),\n checks,\n }\n}\n\nexport function formatDoctorReport(result: {\n ok: boolean\n checks: DoctorCheck[]\n}) {\n const lines = result.checks.map((check) => {\n const prefix = check.ok ? \"✓\" : \"✗\"\n const hint = check.hint ? `\\n → ${check.hint}` : \"\"\n return `${prefix} ${check.name}: ${check.message}${hint}`\n })\n\n lines.push(\"\")\n lines.push(\n result.ok\n ? \"All checks passed. Codex can use Cursor Agent through the bridge.\"\n : \"Some checks failed. Fix the items above before starting Codex.\",\n )\n\n return `${lines.join(\"\\n\")}\\n`\n}\n\nfunction checkNodeVersion(requiredRange: string): DoctorCheck {\n const current = process.version.slice(1)\n const minimum = parseMinimumNodeVersion(requiredRange)\n const ok = compareNodeVersion(current, minimum) >= 0\n\n return ok\n ? {\n name: \"node-version\",\n ok,\n message: `Node ${current} satisfies ${requiredRange}`,\n }\n : {\n name: \"node-version\",\n ok,\n message: `Node ${current} does not satisfy ${requiredRange}`,\n hint: `Install Node ${minimum} or newer.`,\n }\n}\n\nasync function checkAgentExecutable(\n agentPath: string,\n execFileFn: ExecFileFn,\n): Promise<DoctorCheck> {\n try {\n await execFileFn(agentPath, [\"--help\"], { timeout: 5_000 })\n return {\n name: \"agent-cli\",\n ok: true,\n message: `Cursor Agent CLI found at ${agentPath}`,\n }\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Cursor Agent CLI not found\"\n return {\n name: \"agent-cli\",\n ok: false,\n message,\n hint: \"Install the Cursor Agent CLI and ensure `agent` is on PATH, or set CURSOR_AGENT_PATH.\",\n }\n }\n}\n\nasync function checkAgentLogin(\n agentPath: string,\n runner = new CursorRunner({ agentPath }),\n): Promise<DoctorCheck> {\n try {\n const models = await runner.listModels({\n refresh: true,\n })\n if (models.length === 0) {\n return {\n name: \"agent-login\",\n ok: false,\n message: \"Cursor Agent responded, but returned no models\",\n hint: \"Run `agent login` and confirm `agent --list-models` returns models.\",\n }\n }\n\n return {\n name: \"agent-login\",\n ok: true,\n message: `Cursor Agent is logged in (${models.length} models available)`,\n }\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Cursor Agent login check failed\"\n return {\n name: \"agent-login\",\n ok: false,\n message,\n hint: \"Run `agent login` and retry `cursor-agent-bridge doctor`.\",\n }\n }\n}\n\nasync function checkBridgeHealth(\n host: string,\n port: number,\n fetchFn: typeof fetch,\n): Promise<DoctorCheck> {\n const url = `http://${host}:${port}/health`\n try {\n const response = await fetchFn(url, { signal: AbortSignal.timeout(3_000) })\n if (!response.ok) {\n return {\n name: \"bridge-health\",\n ok: false,\n message: `${url} returned HTTP ${response.status}`,\n hint: \"Start the bridge with `cursor-agent-bridge serve` or `cursor-agent-bridge launch-agent install`.\",\n }\n }\n\n const payload = (await response.json()) as { version?: string }\n return {\n name: \"bridge-health\",\n ok: true,\n message: payload.version\n ? `Bridge is listening on ${url} (version ${payload.version})`\n : `Bridge is listening on ${url}`,\n }\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Bridge health check failed\"\n return {\n name: \"bridge-health\",\n ok: false,\n message,\n hint: \"Start the bridge with `cursor-agent-bridge serve` or `cursor-agent-bridge launch-agent install`.\",\n }\n }\n}\n\nasync function checkCodexConfigFile(options: {\n codexConfigPath: string\n host: string\n port: number\n profile: string\n readFileFn: typeof readFile\n}): Promise<DoctorCheck> {\n try {\n const content = await options.readFileFn(options.codexConfigPath, \"utf8\")\n const result = checkCodexConfig(content, {\n host: options.host,\n port: options.port,\n profile: options.profile,\n })\n\n if (result.ok) {\n return {\n name: \"codex-config\",\n ok: true,\n message: `Codex config looks correct at ${options.codexConfigPath}`,\n }\n }\n\n return {\n name: \"codex-config\",\n ok: false,\n message: result.issues.join(\"; \"),\n hint: \"Run `cursor-agent-bridge config write` or `cursor-agent-bridge config print`.\",\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return {\n name: \"codex-config\",\n ok: false,\n message: `Codex config not found at ${options.codexConfigPath}`,\n hint: \"Run `cursor-agent-bridge config write` to create it.\",\n }\n }\n\n const message =\n error instanceof Error ? error.message : \"Codex config check failed\"\n return {\n name: \"codex-config\",\n ok: false,\n message,\n hint: \"Verify the Codex config path and file permissions.\",\n }\n }\n}\n\nfunction parseMinimumNodeVersion(range: string) {\n const match = range.match(/(\\d+)\\.(\\d+)(?:\\.(\\d+))?/)\n if (!match) return \"0.0.0\"\n return `${match[1]}.${match[2]}.${match[3] ?? 0}`\n}\n\nfunction compareNodeVersion(left: string, right: string) {\n const toParts = (value: string) =>\n value.split(\".\").map((part) => Number.parseInt(part, 10) || 0)\n const [leftMajor = 0, leftMinor = 0, leftPatch = 0] = toParts(left)\n const [rightMajor = 0, rightMinor = 0, rightPatch = 0] = toParts(right)\n\n if (leftMajor !== rightMajor) return leftMajor - rightMajor\n if (leftMinor !== rightMinor) return leftMinor - rightMinor\n return leftPatch - rightPatch\n}\n","import { execFileSync } from \"node:child_process\"\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\"\nimport { homedir } from \"node:os\"\nimport { dirname, join, resolve } from \"node:path\"\n\nconst defaultLabel = \"com.xwartz.cursor-agent-bridge\"\nconst defaultLogDir = join(homedir(), \".codex\", \"logs\")\n\nexport type LaunchAgentOptions = {\n cliPath: string\n host?: string\n port?: number\n agentPath?: string\n label?: string\n}\n\nexport type LaunchAgentPaths = {\n label: string\n plistPath: string\n stdoutPath: string\n stderrPath: string\n}\n\nexport function getLaunchAgentPaths(label = defaultLabel): LaunchAgentPaths {\n return {\n label,\n plistPath: join(homedir(), \"Library\", \"LaunchAgents\", `${label}.plist`),\n stdoutPath: join(defaultLogDir, \"cursor-agent-bridge.log\"),\n stderrPath: join(defaultLogDir, \"cursor-agent-bridge.err.log\"),\n }\n}\n\nexport function createLaunchAgentPlist(options: LaunchAgentOptions) {\n const label = options.label ?? defaultLabel\n const host = options.host ?? \"127.0.0.1\"\n const port = options.port ?? 4646\n const paths = getLaunchAgentPaths(label)\n const args = [\n resolve(options.cliPath),\n \"serve\",\n \"--host\",\n host,\n \"--port\",\n String(port),\n ]\n const env: Record<string, string> = {\n PATH: [\n dirname(resolve(options.cliPath)),\n join(homedir(), \".local\", \"bin\"),\n \"/usr/local/bin\",\n \"/opt/homebrew/bin\",\n \"/usr/bin\",\n \"/bin\",\n \"/usr/sbin\",\n \"/sbin\",\n ].join(\":\"),\n }\n\n if (options.agentPath) {\n env.CURSOR_AGENT_PATH = options.agentPath\n }\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>Label</key>\n <string>${escapePlist(label)}</string>\n\n <key>ProgramArguments</key>\n <array>\n${args.map((arg) => ` <string>${escapePlist(arg)}</string>`).join(\"\\n\")}\n </array>\n\n <key>EnvironmentVariables</key>\n <dict>\n${Object.entries(env)\n .map(\n ([key, value]) =>\n ` <key>${escapePlist(key)}</key>\\n <string>${escapePlist(value)}</string>`,\n )\n .join(\"\\n\")}\n </dict>\n\n <key>RunAtLoad</key>\n <true/>\n\n <key>KeepAlive</key>\n <true/>\n\n <key>StandardOutPath</key>\n <string>${escapePlist(paths.stdoutPath)}</string>\n\n <key>StandardErrorPath</key>\n <string>${escapePlist(paths.stderrPath)}</string>\n</dict>\n</plist>\n`\n}\n\nexport function installLaunchAgent(options: LaunchAgentOptions) {\n ensureMacOS()\n const label = options.label ?? defaultLabel\n const paths = getLaunchAgentPaths(label)\n mkdirSync(dirname(paths.plistPath), { recursive: true })\n mkdirSync(defaultLogDir, { recursive: true })\n\n if (existsSync(paths.plistPath)) {\n bootout(paths.plistPath)\n }\n\n writeFileSync(paths.plistPath, createLaunchAgentPlist(options))\n chmodSync(paths.plistPath, 0o644)\n execFileSync(\"launchctl\", [\"bootstrap\", launchctlDomain(), paths.plistPath], {\n stdio: \"pipe\",\n })\n return paths\n}\n\nexport function uninstallLaunchAgent(label = defaultLabel) {\n ensureMacOS()\n const paths = getLaunchAgentPaths(label)\n bootout(paths.plistPath)\n rmSync(paths.plistPath, { force: true })\n return paths\n}\n\nexport function printLaunchAgentStatus(label = defaultLabel) {\n ensureMacOS()\n return execFileSync(\"launchctl\", [\"print\", `${launchctlDomain()}/${label}`], {\n encoding: \"utf8\",\n })\n}\n\nfunction bootout(plistPath: string) {\n try {\n execFileSync(\"launchctl\", [\"bootout\", launchctlDomain(), plistPath], {\n stdio: \"pipe\",\n })\n } catch {\n // It is fine if the service is not loaded yet.\n }\n}\n\nfunction launchctlDomain() {\n return `gui/${process.getuid?.() ?? execFileSync(\"id\", [\"-u\"], { encoding: \"utf8\" }).trim()}`\n}\n\nfunction ensureMacOS() {\n if (process.platform !== \"darwin\") {\n throw new Error(\"LaunchAgent management is only available on macOS.\")\n }\n}\n\nfunction escapePlist(value: string) {\n return value\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\")\n}\n","import { execFile, spawn } from \"node:child_process\"\nimport { existsSync } from \"node:fs\"\nimport { promisify } from \"node:util\"\nimport { getLaunchAgentPaths } from \"./launch-agent.js\"\n\nconst execFileAsync = promisify(execFile)\n\nexport const PACKAGE_NAME = \"cursor-agent-bridge\"\nexport const DEFAULT_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`\nconst REGISTRY_TIMEOUT_MS = 10_000\n\nexport type PackageManager = \"npm\" | \"pnpm\"\nexport type PackageManagerPreference = PackageManager | \"auto\"\n\nexport type ExecFileFn = (\n file: string,\n args?: readonly string[] | null,\n options?: { env?: NodeJS.ProcessEnv },\n) => Promise<unknown>\n\nexport type SpawnFn = (\n command: string,\n args: readonly string[],\n options: { stdio: \"inherit\"; env?: NodeJS.ProcessEnv },\n) => {\n on(event: \"error\", listener: (error: Error) => void): unknown\n on(event: \"close\", listener: (code: number | null) => void): unknown\n}\n\nexport type UpgradeOptions = {\n currentVersion: string\n checkOnly?: boolean\n target?: string\n manager?: PackageManagerPreference\n registryUrl?: string\n fetchFn?: typeof fetch\n spawnFn?: SpawnFn\n execFileFn?: ExecFileFn\n existsFn?: typeof existsSync\n log?: (...args: unknown[]) => void\n errorLog?: (...args: unknown[]) => void\n}\n\nexport function compareSemver(left: string, right: string): -1 | 0 | 1 {\n const toParts = (value: string) => {\n const [major = 0, minor = 0, patch = 0] = value\n .split(\".\")\n .map((part) => Number.parseInt(part, 10) || 0)\n return [major, minor, patch] as const\n }\n const [leftMajor, leftMinor, leftPatch] = toParts(left)\n const [rightMajor, rightMinor, rightPatch] = toParts(right)\n\n if (leftMajor !== rightMajor) {\n return leftMajor < rightMajor ? -1 : 1\n }\n if (leftMinor !== rightMinor) {\n return leftMinor < rightMinor ? -1 : 1\n }\n if (leftPatch !== rightPatch) {\n return leftPatch < rightPatch ? -1 : 1\n }\n return 0\n}\n\nexport async function fetchLatestVersion(options?: {\n registryUrl?: string\n fetchFn?: typeof fetch\n timeoutMs?: number\n}): Promise<string> {\n const registryUrl = options?.registryUrl ?? DEFAULT_REGISTRY_URL\n const fetchFn = options?.fetchFn ?? fetch\n const timeoutMs = options?.timeoutMs ?? REGISTRY_TIMEOUT_MS\n const controller = new AbortController()\n const timeout = setTimeout(() => controller.abort(), timeoutMs)\n\n try {\n const response = await fetchFn(registryUrl, { signal: controller.signal })\n if (!response.ok) {\n throw new Error(`Registry returned ${response.status}`)\n }\n\n const payload = (await response.json()) as { version?: string }\n if (!payload.version) {\n throw new Error(\"Registry response missing version\")\n }\n return payload.version\n } finally {\n clearTimeout(timeout)\n }\n}\n\nasync function commandExists(\n command: string,\n execFileFn: ExecFileFn,\n): Promise<boolean> {\n try {\n await execFileFn(\"which\", [command])\n return true\n } catch {\n return false\n }\n}\n\nexport async function detectPackageManager(\n preference: PackageManagerPreference,\n execFileFn: ExecFileFn = execFileAsync,\n): Promise<PackageManager> {\n if (preference === \"npm\") return \"npm\"\n if (preference === \"pnpm\") return \"pnpm\"\n\n if (!(await commandExists(\"pnpm\", execFileFn))) {\n return \"npm\"\n }\n\n try {\n await execFileFn(\"pnpm\", [\"list\", \"-g\", PACKAGE_NAME, \"--json\"], {\n env: process.env,\n })\n return \"pnpm\"\n } catch {\n return \"npm\"\n }\n}\n\nexport function buildInstallCommand(\n manager: PackageManager,\n target: string,\n): { command: string; args: string[] } {\n const versionSpec =\n target === \"latest\" ? \"@latest\" : `@${target.replace(/^@/, \"\")}`\n const packageSpec = `${PACKAGE_NAME}${versionSpec}`\n\n if (manager === \"pnpm\") {\n return { command: \"pnpm\", args: [\"add\", \"-g\", packageSpec] }\n }\n\n return { command: \"npm\", args: [\"install\", \"-g\", packageSpec] }\n}\n\nfunction printManualUpgradeHint(errorLog: (...args: unknown[]) => void) {\n errorLog(\"Upgrade manually:\")\n errorLog(` pnpm add -g ${PACKAGE_NAME}@latest`)\n errorLog(` npm install -g ${PACKAGE_NAME}@latest`)\n}\n\nasync function resolveTargetVersion(\n target: string,\n registryUrl: string,\n fetchFn: typeof fetch,\n): Promise<string> {\n if (target === \"latest\") {\n return fetchLatestVersion({ registryUrl, fetchFn })\n }\n return target.replace(/^@/, \"\")\n}\n\nasync function runInstall(\n manager: PackageManager,\n target: string,\n spawnFn: SpawnFn,\n): Promise<number> {\n const { command, args } = buildInstallCommand(manager, target)\n return new Promise((resolve, reject) => {\n const child = spawnFn(command, args, {\n stdio: \"inherit\",\n env: process.env,\n })\n\n child.on(\"error\", reject)\n child.on(\"close\", (code) => resolve(code ?? 1))\n })\n}\n\nexport async function runUpgrade(options: UpgradeOptions): Promise<number> {\n const log = options.log ?? console.log\n const errorLog = options.errorLog ?? console.error\n const checkOnly = options.checkOnly ?? false\n const target = options.target ?? \"latest\"\n const managerPreference = options.manager ?? \"auto\"\n const registryUrl = options.registryUrl ?? DEFAULT_REGISTRY_URL\n const fetchFn = options.fetchFn ?? fetch\n const spawnFn: SpawnFn =\n options.spawnFn ??\n ((command, args, spawnOptions) => spawn(command, args, spawnOptions))\n const execFileFn = options.execFileFn ?? execFileAsync\n const existsFn = options.existsFn ?? existsSync\n\n let targetVersion: string\n try {\n targetVersion = await resolveTargetVersion(target, registryUrl, fetchFn)\n } catch (error) {\n errorLog(\n `Failed to check for updates: ${error instanceof Error ? error.message : String(error)}`,\n )\n printManualUpgradeHint(errorLog)\n return 1\n }\n\n const comparison = compareSemver(options.currentVersion, targetVersion)\n if (comparison >= 0) {\n log(`${PACKAGE_NAME} is up to date (${options.currentVersion})`)\n return 0\n }\n\n if (checkOnly) {\n log(`Update available: ${options.currentVersion} -> ${targetVersion}`)\n return 1\n }\n\n let manager: PackageManager\n manager = await detectPackageManager(managerPreference, execFileFn)\n\n log(`Installing ${PACKAGE_NAME}@${targetVersion} via ${manager}...`)\n try {\n const exitCode = await runInstall(manager, target, spawnFn)\n if (exitCode !== 0) {\n errorLog(`${manager} install failed with exit code ${exitCode}`)\n printManualUpgradeHint(errorLog)\n return exitCode\n }\n } catch (error) {\n errorLog(\n `Install failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n printManualUpgradeHint(errorLog)\n return 1\n }\n\n log(`Installed ${PACKAGE_NAME}@${targetVersion}`)\n log(\"Run `cursor-agent-bridge --version` to verify the upgrade.\")\n\n const launchAgentPlist = getLaunchAgentPaths().plistPath\n if (existsFn(launchAgentPlist)) {\n log(\n \"LaunchAgent detected. Run `cursor-agent-bridge launch-agent install` to refresh the service.\",\n )\n }\n\n return 0\n}\n","#!/usr/bin/env node\n\nimport { readFile } from \"node:fs/promises\"\nimport packageJson from \"../package.json\" with { type: \"json\" }\nimport { toOpenAIModelList } from \"./adapter/models.js\"\nimport { readArg, readHostAndPort } from \"./cli-args.js\"\nimport {\n buildCodexConfigToml,\n checkCodexConfig,\n DEFAULT_CODEX_PROFILE,\n resolveCodexConfigPath,\n writeCodexConfig,\n} from \"./codex-config.js\"\nimport { CursorRunner } from \"./cursor/runner.js\"\nimport { formatDoctorReport, runDoctor } from \"./doctor.js\"\nimport {\n installLaunchAgent,\n printLaunchAgentStatus,\n uninstallLaunchAgent,\n} from \"./launch-agent.js\"\nimport { startServer } from \"./server.js\"\nimport { runUpgrade } from \"./upgrade.js\"\n\nconst command =\n process.argv[2] && !process.argv[2]?.startsWith(\"-\")\n ? process.argv[2]\n : \"serve\"\n\nif (\n command === \"help\" ||\n process.argv.includes(\"--help\") ||\n process.argv.includes(\"-h\")\n) {\n console.log(`cursor-agent-bridge\n\nUsage:\n cursor-agent-bridge serve [--host 127.0.0.1] [--port 4646]\n cursor-agent-bridge doctor [--host 127.0.0.1] [--port 4646] [--profile cursor] [--file ~/.codex/cursor.config.toml] [--skip-codex-config]\n cursor-agent-bridge config print [--host 127.0.0.1] [--port 4646] [--profile cursor]\n cursor-agent-bridge config check [--file ~/.codex/cursor.config.toml] [--host 127.0.0.1] [--port 4646] [--profile cursor]\n cursor-agent-bridge config write [--file ~/.codex/cursor.config.toml] [--host 127.0.0.1] [--port 4646] [--profile cursor] [--force]\n cursor-agent-bridge models [--json] [--refresh]\n cursor-agent-bridge launch-agent install [--host 127.0.0.1] [--port 4646] [--agent-path agent]\n cursor-agent-bridge launch-agent uninstall\n cursor-agent-bridge launch-agent status\n cursor-agent-bridge upgrade [--check] [--target latest] [--manager auto|npm|pnpm]\n\nEnvironment:\n HOST Listen host, default 127.0.0.1\n PORT Listen port, default 4646\n CURSOR_AGENT_PATH Cursor Agent CLI path, default agent\n`)\n process.exit(0)\n}\n\nif (command === \"version\" || process.argv.includes(\"--version\")) {\n console.log(packageJson.version)\n process.exit(0)\n}\n\nif (command === \"upgrade\") {\n const checkOnly = process.argv.includes(\"--check\")\n const target = readArg(\"--target\", \"latest\") ?? \"latest\"\n const manager = readArg(\"--manager\", \"auto\") ?? \"auto\"\n\n if (manager !== \"auto\" && manager !== \"npm\" && manager !== \"pnpm\") {\n console.error(\"Invalid --manager value. Use auto, npm, or pnpm.\")\n process.exit(1)\n }\n\n const exitCode = await runUpgrade({\n currentVersion: packageJson.version,\n checkOnly,\n target,\n manager,\n })\n process.exit(exitCode)\n}\n\nif (command === \"doctor\") {\n try {\n const { host, port } = readHostAndPort()\n const profile =\n readArg(\"--profile\", DEFAULT_CODEX_PROFILE) ?? DEFAULT_CODEX_PROFILE\n const codexConfigPath = readArg(\"--file\", undefined)\n const result = await runDoctor({\n host,\n port,\n profile,\n skipCodexConfig: process.argv.includes(\"--skip-codex-config\"),\n ...(process.env.CURSOR_AGENT_PATH\n ? { agentPath: process.env.CURSOR_AGENT_PATH }\n : {}),\n ...(codexConfigPath ? { codexConfigPath } : {}),\n })\n process.stdout.write(formatDoctorReport(result))\n process.exit(result.ok ? 0 : 1)\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n process.exit(1)\n }\n}\n\nif (command === \"config\") {\n const action = process.argv[3] ?? \"print\"\n try {\n const { host, port } = readHostAndPort()\n const profile =\n readArg(\"--profile\", DEFAULT_CODEX_PROFILE) ?? DEFAULT_CODEX_PROFILE\n const filePath =\n readArg(\"--file\", undefined) ?? resolveCodexConfigPath(profile)\n\n if (action === \"print\") {\n process.stdout.write(buildCodexConfigToml({ host, port, profile }))\n console.error(`Start Codex with: codex --profile ${profile}`)\n process.exit(0)\n }\n\n if (action === \"check\") {\n const content = await readFile(filePath, \"utf8\")\n const result = checkCodexConfig(content, { host, port, profile })\n if (result.ok) {\n console.log(`Codex config looks correct: ${filePath}`)\n process.exit(0)\n }\n\n for (const issue of result.issues) {\n console.error(issue)\n }\n process.exit(1)\n }\n\n if (action === \"write\") {\n const result = await writeCodexConfig({\n filePath,\n host,\n port,\n profile,\n force: process.argv.includes(\"--force\"),\n })\n\n if (result.created) {\n console.log(`Created Codex config at ${result.path}`)\n } else if (result.updated) {\n console.log(`Updated Codex config at ${result.path}`)\n } else {\n console.log(`Codex config already up to date at ${result.path}`)\n }\n\n console.log(`Start Codex with: codex --profile ${profile}`)\n process.exit(0)\n }\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n process.exit(1)\n }\n\n console.error(`Unknown config action: ${action}`)\n process.exit(1)\n}\n\nif (command === \"models\") {\n try {\n const runner = new CursorRunner({\n ...(process.env.CURSOR_AGENT_PATH\n ? { agentPath: process.env.CURSOR_AGENT_PATH }\n : {}),\n })\n const models = await runner.listModels({\n refresh: process.argv.includes(\"--refresh\"),\n })\n\n if (process.argv.includes(\"--json\")) {\n console.log(JSON.stringify(toOpenAIModelList(models), null, 2))\n process.exit(0)\n }\n\n for (const model of models) {\n console.log(model.id)\n }\n process.exit(0)\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n process.exit(1)\n }\n}\n\nif (command === \"launch-agent\") {\n const action = process.argv[3] ?? \"status\"\n try {\n if (action === \"install\") {\n const { host, port } = readHostAndPort()\n const agentPath = readArg(\"--agent-path\", process.env.CURSOR_AGENT_PATH)\n const paths = installLaunchAgent({\n cliPath: process.argv[1] ?? \"cursor-agent-bridge\",\n host,\n port,\n ...(agentPath ? { agentPath } : {}),\n })\n console.log(`Installed ${paths.label}`)\n console.log(paths.plistPath)\n process.exit(0)\n }\n\n if (action === \"uninstall\") {\n const paths = uninstallLaunchAgent()\n console.log(`Uninstalled ${paths.label}`)\n process.exit(0)\n }\n\n if (action === \"status\") {\n process.stdout.write(printLaunchAgentStatus())\n process.exit(0)\n }\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n process.exit(1)\n }\n\n console.error(`Unknown launch-agent action: ${action}`)\n process.exit(1)\n}\n\nif (command !== \"serve\") {\n console.error(`Unknown command: ${command}`)\n process.exit(1)\n}\n\nlet host: string\nlet port: number\ntry {\n const options = readHostAndPort()\n host = options.host\n port = options.port\n} catch (error) {\n console.error(error instanceof Error ? error.message : String(error))\n process.exit(1)\n}\n\nconst server = await startServer({\n host,\n port,\n ...(process.env.CURSOR_AGENT_PATH\n ? { agentPath: process.env.CURSOR_AGENT_PATH }\n : {}),\n})\nconsole.log(`cursor-agent-bridge listening on http://${host}:${port}`)\n\nfunction shutdown() {\n server.close(() => process.exit(0))\n}\n\nprocess.on(\"SIGINT\", shutdown)\nprocess.on(\"SIGTERM\", shutdown)\n"],"mappings":";;;;;;;;;AAAA,SAAgB,QAAQ,MAAc,UAA8B;CAClE,MAAM,QAAQ,QAAQ,KAAK,QAAQ,IAAI;CACvC,IAAI,QAAQ,GAAG,OAAO;CACtB,MAAM,QAAQ,QAAQ,KAAK,QAAQ;CACnC,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,GAChC,MAAM,IAAI,MAAM,qBAAqB,MAAM;CAC7C,OAAO;AACT;AAEA,SAAgB,UAAU,OAA2B,UAAkB;CACrE,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAChD,MAAM,IAAI,M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
|
2
1
|
import http from "node:http";
|
|
3
2
|
|
|
4
3
|
//#region src/types.d.ts
|
|
@@ -52,6 +51,7 @@ interface ServerConfig {
|
|
|
52
51
|
host?: string;
|
|
53
52
|
agentPath?: string;
|
|
54
53
|
defaultCwd?: string;
|
|
54
|
+
maxBodyBytes?: number;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region src/adapter/messages.d.ts
|
|
@@ -115,14 +115,29 @@ interface CursorRunnerOptions {
|
|
|
115
115
|
agentPath?: string;
|
|
116
116
|
defaultCwd?: string;
|
|
117
117
|
timeoutMs?: number;
|
|
118
|
+
modelListCacheMs?: number;
|
|
119
|
+
maxConcurrentRuns?: number;
|
|
120
|
+
yolo?: boolean;
|
|
118
121
|
}
|
|
119
|
-
declare class CursorRunner
|
|
122
|
+
declare class CursorRunner {
|
|
120
123
|
readonly agentPath: string;
|
|
121
124
|
readonly defaultCwd: string;
|
|
122
125
|
readonly timeoutMs: number;
|
|
126
|
+
readonly modelListCacheMs: number;
|
|
127
|
+
readonly maxConcurrentRuns: number;
|
|
128
|
+
readonly yolo: boolean;
|
|
129
|
+
private modelCache?;
|
|
130
|
+
private activeRuns;
|
|
131
|
+
private readonly runQueue;
|
|
132
|
+
private readonly activeChildren;
|
|
123
133
|
constructor(options?: CursorRunnerOptions);
|
|
124
|
-
listModels(
|
|
134
|
+
listModels(options?: {
|
|
135
|
+
refresh?: boolean;
|
|
136
|
+
}): Promise<BridgeModel[]>;
|
|
125
137
|
run(options: CursorRunOptions, events?: CursorRunEvents): Promise<CursorRunResult>;
|
|
138
|
+
abortAll(): void;
|
|
139
|
+
private acquireRunPermit;
|
|
140
|
+
private runWithPermit;
|
|
126
141
|
}
|
|
127
142
|
//#endregion
|
|
128
143
|
//#region src/server.d.ts
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/adapter/messages.ts","../src/adapter/models.ts","../src/cursor/runner.ts","../src/server.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/adapter/messages.ts","../src/adapter/models.ts","../src/cursor/runner.ts","../src/server.ts"],"mappings":";;;KAAY,QAAA;AAAA,UAEK,WAAA;EACf,IAAA,EAAM,QAAA;EACN,OAAA,WAEI,KAAK;IACH,IAAA;IACA,IAAA;IACA,UAAA;IACA,WAAA;EAAA;AAAA;AAAA,UAIS,qBAAA;EACf,KAAA;EACA,QAAA,EAAU,WAAW;EACrB,MAAA;EACA,WAAA;EACA,KAAA;EACA,UAAA;AAAA;AAAA,UAGe,gBAAA;EACf,KAAA;EACA,KAAA;EACA,YAAA;EACA,MAAA;EACA,WAAA;EACA,KAAA;EACA,iBAAA;AAAA;AAAA,UAGe,WAAA;EACf,EAAA;EACA,IAAI;AAAA;AAAA,UAGW,gBAAA;EACf,KAAA;EACA,MAAA;EACA,GAAA;EACA,MAAA,GAAS,WAAW;AAAA;AAAA,UAGL,eAAA;EACf,IAAA;EACA,KAAK;AAAA;AAAA,UAGU,eAAA;EACf,OAAA,IAAW,IAAA;EACX,OAAA,IAAW,KAAA;AAAA;AAAA,UAGI,YAAA;EACf,IAAA;EACA,IAAA;EACA,SAAA;EACA,UAAA;EACA,YAAA;AAAA;;;iBCjDc,gBAAA,CAAiB,QAAuB,EAAb,WAAW;AAAA,iBAuCtC,mBAAA,CAAoB,OAAA,EAAS,gBAAA,GAAmB,WAAW;AAAA,iBAyC3D,cAAA,CAAe,KAAyB;;;iBCzFxC,mBAAA,CAAoB,MAAA,WAAiB,WAAW;AAAA,iBAWhD,iBAAA,CAAkB,MAAA,EAAQ,WAAW;;;;;;;;;iBAarC,mBAAA,CAAoB,MAAA,EAAQ,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCjBtC,mBAAA;EACf,SAAA;EACA,UAAA;EACA,SAAA;EACA,gBAAA;EACA,iBAAA;EACA,IAAA;AAAA;AAAA,cAOW,YAAA;EAAA,SACF,SAAA;EAAA,SACA,UAAA;EAAA,SACA,SAAA;EAAA,SACA,gBAAA;EAAA,SACA,iBAAA;EAAA,SACA,IAAA;EAAA,QACD,UAAA;EAAA,QACA,UAAA;EAAA,iBACS,QAAA;EAAA,iBACA,cAAA;cAEL,OAAA,GAAS,mBAAA;EAgBf,UAAA,CACJ,OAAA;IAAW,OAAA;EAAA,IACV,OAAA,CAAQ,WAAA;EA4BL,GAAA,CACJ,OAAA,EAAS,gBAAA,EACT,MAAA,GAAQ,eAAA,GACP,OAAA,CAAQ,eAAA;EAUX,QAAA;EAAA,QAIQ,gBAAA;EAAA,QAmCA,aAAA;AAAA;;;iBC7FY,WAAA,CAAY,MAAA,GAAQ,YAAA,GAAiB,OAAA,CAAA,IAAA,CAAA,MAAA,QAAA,IAAA,CAAA,eAAA,SAAA,IAAA,CAAA,cAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as parseAgentModelList, c as messagesToPrompt, i as CursorRunner, l as normalizeModel, o as toCodexModelCatalog, s as toOpenAIModelList, t as startServer, u as responsesToMessages } from "./server-Bk7ol2lA.mjs";
|
|
2
2
|
export { CursorRunner, messagesToPrompt, normalizeModel, parseAgentModelList, responsesToMessages, startServer, toCodexModelCatalog, toOpenAIModelList };
|