@ashx-j/lunr-ai 0.2.26 → 0.2.27
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/LICENSE +22 -0
- package/README.md +90 -84
- package/dist/api/anthropic-claude-code-bridge.d.ts.map +1 -1
- package/dist/api/anthropic-claude-code-bridge.js +29 -9
- package/dist/api/anthropic-claude-code-bridge.js.map +1 -1
- package/dist/auth/helpers.d.ts.map +1 -1
- package/dist/auth/helpers.js +2 -2
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/dist/auth/oauth/anthropic.js +3 -4
- package/dist/auth/oauth/anthropic.js.map +1 -1
- package/dist/utils/claude-code-assets.d.ts +8 -0
- package/dist/utils/claude-code-assets.d.ts.map +1 -0
- package/dist/utils/claude-code-assets.js +16 -0
- package/dist/utils/claude-code-assets.js.map +1 -0
- package/package.json +1 -1
- package/vendor/hermes-claude-subscription-directsdk/lunr_bridge.py +26 -2
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
3
|
import { calculateCost } from "../models.js";
|
|
4
|
+
import { getClaudeCodeWorkerPath } from "../utils/claude-code-assets.js";
|
|
5
5
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
6
|
-
const
|
|
6
|
+
const SAFE_ERRORS = {
|
|
7
|
+
context_overflow: "Claude Code prompt is too long for the context window.",
|
|
8
|
+
timeout: "Claude Code request timed out.",
|
|
9
|
+
rate_limit: "Claude Code rate limit reached. Please retry your request.",
|
|
10
|
+
overloaded: "Claude Code service overloaded. Please retry your request.",
|
|
11
|
+
transient: "Claude Code service unavailable. Please retry your request.",
|
|
12
|
+
incomplete: "Claude Code stream ended before message_stop. Please retry your request.",
|
|
13
|
+
};
|
|
14
|
+
class ClaudeCodeRequestError extends Error {
|
|
15
|
+
constructor(category) {
|
|
16
|
+
super(typeof category === "string" && Object.hasOwn(SAFE_ERRORS, category)
|
|
17
|
+
? SAFE_ERRORS[category]
|
|
18
|
+
: "Claude Code request failed. Run /login anthropic to check setup and Claude Code version 2.1.263.");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
const MAX_RECORD = 64 * 1024 * 1024;
|
|
8
22
|
const CONFLICTS = [
|
|
9
23
|
"ANTHROPIC_API_KEY",
|
|
@@ -305,6 +319,7 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
305
319
|
nativeCleanup ??= stopNative(nativePid);
|
|
306
320
|
return nativeCleanup;
|
|
307
321
|
};
|
|
322
|
+
let timedOut = false;
|
|
308
323
|
let timer;
|
|
309
324
|
let abortTimer;
|
|
310
325
|
let started = false;
|
|
@@ -332,7 +347,7 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
332
347
|
}
|
|
333
348
|
: undefined;
|
|
334
349
|
const requestId = randomUUID();
|
|
335
|
-
child = spawn(connection.python, ["-s", "-B", "-u",
|
|
350
|
+
child = spawn(connection.python, ["-s", "-B", "-u", getClaudeCodeWorkerPath("lunr_bridge.py")], {
|
|
336
351
|
stdio: ["pipe", "pipe", "pipe"],
|
|
337
352
|
windowsHide: true,
|
|
338
353
|
env,
|
|
@@ -360,7 +375,6 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
360
375
|
throw new Error("Claude Code request exceeds size limit");
|
|
361
376
|
worker.stdin.write(`${payload}\n`);
|
|
362
377
|
let cancelSent = false;
|
|
363
|
-
let timedOut = false;
|
|
364
378
|
const abort = () => {
|
|
365
379
|
if (cancelSent)
|
|
366
380
|
return;
|
|
@@ -517,7 +531,7 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
517
531
|
else if (event.type === "cancelled" && cancelSent) {
|
|
518
532
|
}
|
|
519
533
|
else if (event.type === "error" || event.type === "cancelled")
|
|
520
|
-
throw new
|
|
534
|
+
throw new ClaudeCodeRequestError(event.type === "error" ? event.category : undefined);
|
|
521
535
|
else
|
|
522
536
|
throw new Error("Unknown Claude Code bridge event");
|
|
523
537
|
}
|
|
@@ -543,8 +557,10 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
543
557
|
finally {
|
|
544
558
|
options.signal?.removeEventListener("abort", abort);
|
|
545
559
|
}
|
|
546
|
-
if (
|
|
547
|
-
throw new
|
|
560
|
+
if (timedOut)
|
|
561
|
+
throw new ClaudeCodeRequestError("timeout");
|
|
562
|
+
if (options.signal?.aborted)
|
|
563
|
+
throw new Error("Claude Code request cancelled");
|
|
548
564
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
549
565
|
}
|
|
550
566
|
catch (error) {
|
|
@@ -560,8 +576,12 @@ export function streamClaudeCode(model, context, options = {}) {
|
|
|
560
576
|
: undefined;
|
|
561
577
|
output.errorMessage = options.signal?.aborted
|
|
562
578
|
? "Claude Code request cancelled"
|
|
563
|
-
:
|
|
564
|
-
|
|
579
|
+
: timedOut
|
|
580
|
+
? SAFE_ERRORS.timeout
|
|
581
|
+
: error instanceof ClaudeCodeRequestError
|
|
582
|
+
? error.message
|
|
583
|
+
: (detail ??
|
|
584
|
+
"Claude Code request failed. Run /login anthropic to check setup and Claude Code version 2.1.263.");
|
|
565
585
|
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
566
586
|
}
|
|
567
587
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-claude-code-bridge.js","sourceRoot":"","sources":["../../src/api/anthropic-claude-code-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAW7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B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,KAAK,CAAC,QAAQ,KAAK,IAAI;oBAAE,MAAM,cAAc,EAAE,CAAC;gBACjE,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;oBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YAC3C,CAAC;QACF,CAAC;IAAA,CACD,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { fileURLToPath } from \"node:url\";\nimport type { ExternalClaudeCodeCredential } from \"../auth/types.ts\";\nimport { calculateCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\n\nconst WORKER = fileURLToPath(\n\tnew URL(\"../../vendor/hermes-claude-subscription-directsdk/lunr_bridge.py\", import.meta.url),\n);\nconst MAX_RECORD = 64 * 1024 * 1024;\nconst CONFLICTS = [\n\t\"ANTHROPIC_API_KEY\",\n\t\"ANTHROPIC_AUTH_TOKEN\",\n\t\"ANTHROPIC_OAUTH_TOKEN\",\n\t\"ANTHROPIC_BASE_URL\",\n\t\"ANTHROPIC_FOUNDRY_API_KEY\",\n\t\"CLAUDE_CODE_USE_BEDROCK\",\n\t\"CLAUDE_CODE_USE_VERTEX\",\n\t\"CLAUDE_CODE_USE_FOUNDRY\",\n\t\"CLAUDE_CODE_EXTRA_BODY\",\n] as const;\nconst ENV_ALLOWLIST = [\n\t\"PATH\",\n\t\"HOME\",\n\t\"USERPROFILE\",\n\t\"APPDATA\",\n\t\"LOCALAPPDATA\",\n\t\"PROGRAMDATA\",\n\t\"SYSTEMROOT\",\n\t\"SYSTEMDRIVE\",\n\t\"COMSPEC\",\n\t\"PATHEXT\",\n\t\"TEMP\",\n\t\"TMP\",\n\t\"LANG\",\n\t\"LC_ALL\",\n\t\"HTTP_PROXY\",\n\t\"HTTPS_PROXY\",\n\t\"NO_PROXY\",\n\t\"http_proxy\",\n\t\"https_proxy\",\n\t\"no_proxy\",\n] as const;\n\nexport function claudeCodeEnvironment(configDir?: string, strict = true): Record<string, string> {\n\tconst conflicting = CONFLICTS.filter((name) => {\n\t\tconst value = process.env[name];\n\t\treturn (\n\t\t\tvalue &&\n\t\t\t((name !== \"CLAUDE_CODE_USE_BEDROCK\" &&\n\t\t\t\tname !== \"CLAUDE_CODE_USE_VERTEX\" &&\n\t\t\t\tname !== \"CLAUDE_CODE_USE_FOUNDRY\") ||\n\t\t\t\t![\"0\", \"false\", \"no\", \"off\"].includes(value.toLowerCase()))\n\t\t);\n\t});\n\tif (strict && conflicting.length)\n\t\tthrow new Error(`Claude Code subscription refuses conflicting environment variables: ${conflicting.join(\", \")}`);\n\tif (process.env.NODE_TLS_REJECT_UNAUTHORIZED === \"0\")\n\t\tthrow new Error(\"Claude Code subscription requires TLS certificate verification\");\n\tconst env = Object.fromEntries(\n\t\tENV_ALLOWLIST.flatMap((name) => (process.env[name] ? [[name, process.env[name]]] : [])),\n\t);\n\tif (configDir) env.CLAUDE_SUBSCRIPTION_DIRECTSDK_CONFIG_DIR = configDir;\n\treturn env;\n}\n\nfunction contentHash(content: AssistantMessage[\"content\"]): string {\n\treturn createHash(\"sha256\").update(JSON.stringify(content)).digest(\"hex\");\n}\n\nfunction history(\n\tcontext: Context,\n\tmodel: Model<Api>,\n\tconnection: ExternalClaudeCodeCredential,\n): { messages: unknown[]; tools: unknown[] } {\n\tconst messages: Record<string, unknown>[] = context.systemPrompt\n\t\t? [{ role: \"system\", content: context.systemPrompt }]\n\t\t: [];\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof message.content === \"string\"\n\t\t\t\t\t\t? message.content\n\t\t\t\t\t\t: message.content.map((block) =>\n\t\t\t\t\t\t\t\tblock.type === \"text\"\n\t\t\t\t\t\t\t\t\t? { type: \"text\", text: block.text }\n\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\t\t\t\t\timage_url: { url: `data:${block.mimeType};base64,${block.data}` },\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tconst text = message.content\n\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t.map((block) => block.text)\n\t\t\t\t.join(\"\");\n\t\t\tconst calls = message.content\n\t\t\t\t.filter((block): block is ToolCall => block.type === \"toolCall\")\n\t\t\t\t.map((block) => ({\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: block.name, arguments: JSON.stringify(block.arguments) },\n\t\t\t\t}));\n\t\t\tconst projection = {\n\t\t\t\tcontent: text.trim(),\n\t\t\t\ttool_calls: calls.map((call) => ({\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.function.name,\n\t\t\t\t\tinput: JSON.parse(call.function.arguments),\n\t\t\t\t})),\n\t\t\t};\n\t\t\tconst carrier =\n\t\t\t\tmessage.provider === \"anthropic\" &&\n\t\t\t\tmessage.model === model.id &&\n\t\t\t\tmessage.claudeCodeCarrier?.version === 1 &&\n\t\t\t\tconnection.accountFingerprint &&\n\t\t\t\tmessage.claudeCodeCarrier.accountFingerprint === connection.accountFingerprint &&\n\t\t\t\tmessage.claudeCodeCarrier.contentHash === contentHash(message.content) &&\n\t\t\t\tJSON.stringify(message.claudeCodeCarrier.projection) === JSON.stringify(projection)\n\t\t\t\t\t? [{ type: \"claude-subscription-directsdk-experimental.native_assistant\", ...message.claudeCodeCarrier }]\n\t\t\t\t\t: [];\n\t\t\tmessages.push({ role: \"assistant\", content: text, tool_calls: calls, reasoning_details: carrier });\n\t\t} else {\n\t\t\tif (message.content.some((block) => block.type !== \"text\"))\n\t\t\t\tthrow new Error(\"Claude Code subscription supports text tool results only\");\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t\tcontent: message.content.map((block) => (block.type === \"text\" ? block.text : \"\")).join(\"\"),\n\t\t\t\tis_error: message.isError,\n\t\t\t});\n\t\t}\n\t}\n\tconst tools = (context.tools ?? []).map((tool) => ({\n\t\ttype: \"function\",\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t},\n\t}));\n\treturn { messages, tools };\n}\n\nfunction validateOptions(model: Model<Api>, options: StreamOptions | SimpleStreamOptions): void {\n\tif (!options.externalClaudeCode)\n\t\tthrow new Error(\"Claude Code subscription setup is required. Run /login anthropic.\");\n\tif (\n\t\toptions.apiKey ||\n\t\tObject.keys(options.headers ?? {}).length ||\n\t\toptions.onPayload ||\n\t\toptions.onResponse ||\n\t\toptions.env ||\n\t\toptions.metadata ||\n\t\t(options.transport && options.transport !== \"auto\") ||\n\t\toptions.maxRetries ||\n\t\t(options.maxRetryDelayMs !== undefined && options.maxRetryDelayMs !== 60_000) ||\n\t\toptions.websocketConnectTimeoutMs ||\n\t\tmodel.baseUrl !== \"https://api.anthropic.com\"\n\t) {\n\t\tthrow new Error(\"Claude Code subscription does not support API keys, alternate endpoints, or request mutations\");\n\t}\n\tconst anthro = options as StreamOptions & {\n\t\ttoolChoice?: unknown;\n\t\tclient?: unknown;\n\t\textraBody?: unknown;\n\t\tthinkingBudgetTokens?: unknown;\n\t\tstopSequences?: unknown;\n\t\tthinkingEnabled?: boolean;\n\t\teffort?: string;\n\t\tthinkingDisplay?: unknown;\n\t\tinterleavedThinking?: unknown;\n\t};\n\tif (\n\t\t(anthro.toolChoice && anthro.toolChoice !== \"auto\") ||\n\t\tanthro.client ||\n\t\tanthro.extraBody ||\n\t\tanthro.thinkingBudgetTokens ||\n\t\tanthro.stopSequences ||\n\t\tanthro.thinkingDisplay !== undefined ||\n\t\tanthro.interleavedThinking !== undefined\n\t) {\n\t\tthrow new Error(\"Claude Code subscription does not support forced tools or native request overrides\");\n\t}\n\tif (options.temperature !== undefined)\n\t\tthrow new Error(\"Claude Code subscription does not support sampling overrides\");\n}\n\ntype WorkerEvent = { v: 1; requestId: string; type: string; text?: unknown; pid?: unknown; response?: unknown };\n\nfunction parseWorkerRecord(line: string, requestId: string): WorkerEvent {\n\tif (Buffer.byteLength(line) > MAX_RECORD) throw new Error(\"Claude Code bridge record exceeds size limit\");\n\tconst value: unknown = JSON.parse(line);\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"v\" in value) ||\n\t\tvalue.v !== 1 ||\n\t\t!(\"requestId\" in value) ||\n\t\tvalue.requestId !== requestId ||\n\t\t!(\"type\" in value) ||\n\t\ttypeof value.type !== \"string\"\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code bridge record\");\n\t}\n\treturn value as WorkerEvent;\n}\n\nexport async function stopNative(pid: number): Promise<void> {\n\tif (!Number.isSafeInteger(pid) || pid < 1) return;\n\tif (process.platform === \"win32\") {\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst killer = spawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], { stdio: \"ignore\", windowsHide: true });\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tkiller.kill();\n\t\t\t\tresolve();\n\t\t\t}, 3000);\n\t\t\tkiller.once(\"error\", () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t\tkiller.once(\"close\", () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t} else {\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t/* Already exited. */\n\t\t}\n\t}\n}\n\nfunction validatedCompletion(\n\tvalue: unknown,\n\tmodel: Model<Api>,\n\ttext: string,\n\tthinking: string,\n): {\n\tcontent: AssistantMessage[\"content\"];\n\tcarrier: AssistantMessage[\"claudeCodeCarrier\"];\n\tusage: Usage;\n\tresponseId: string;\n\treason: \"stop\" | \"length\" | \"toolUse\";\n} {\n\tif (!value || typeof value !== \"object\" || !(\"choices\" in value) || !Array.isArray(value.choices))\n\t\tthrow new Error(\"Invalid native completion\");\n\tconst response = value as Record<string, unknown> & {\n\t\tchoices: { finish_reason: unknown; message: Record<string, unknown> }[];\n\t\tusage: Record<string, unknown>;\n\t};\n\tconst choice = response.choices[0];\n\tif (\n\t\t!choice ||\n\t\t![\"stop\", \"length\", \"tool_calls\"].includes(String(choice.finish_reason)) ||\n\t\t(typeof choice.message?.content !== \"string\" && choice.message?.content !== null) ||\n\t\t(choice.message.content ?? \"\") !== text ||\n\t\t(choice.message.reasoning_content ?? \"\") !== thinking\n\t)\n\t\tthrow new Error(\"Native completion differs from streamed content\");\n\tconst rawCalls = choice.message.tool_calls ?? [];\n\tif (!Array.isArray(rawCalls)) throw new Error(\"Invalid native tool calls\");\n\tconst calls: ToolCall[] = rawCalls.map((call) => {\n\t\tif (\n\t\t\t!call ||\n\t\t\ttypeof call !== \"object\" ||\n\t\t\ttypeof call.id !== \"string\" ||\n\t\t\ttypeof call.function?.name !== \"string\" ||\n\t\t\ttypeof call.function?.arguments !== \"string\"\n\t\t)\n\t\t\tthrow new Error(\"Invalid native tool call\");\n\t\tconst args: unknown = JSON.parse(call.function.arguments);\n\t\tif (!args || typeof args !== \"object\" || Array.isArray(args)) throw new Error(\"Invalid native tool arguments\");\n\t\treturn { type: \"toolCall\", id: call.id, name: call.function.name, arguments: args as Record<string, unknown> };\n\t});\n\tconst native = response.usage;\n\tif (\n\t\t!native ||\n\t\ttypeof native.native_admission !== \"object\" ||\n\t\tnative.native_admission === null ||\n\t\t(native.native_admission as { upstream_requests?: unknown }).upstream_requests !== 1\n\t)\n\t\tthrow new Error(\"Native one-request admission not verified\");\n\tif (\n\t\t!native ||\n\t\t!Number.isFinite(native.prompt_tokens) ||\n\t\t!Number.isFinite(native.completion_tokens) ||\n\t\t!Number.isFinite(native.cache_creation_input_tokens) ||\n\t\t!(\"prompt_tokens_details\" in native)\n\t)\n\t\tthrow new Error(\"Missing native usage\");\n\tconst cached = (native.prompt_tokens_details as { cached_tokens?: unknown }).cached_tokens;\n\tif (!Number.isFinite(cached)) throw new Error(\"Missing native cache usage\");\n\tconst usage: Usage = {\n\t\tinput: Number(native.prompt_tokens) - Number(cached) - Number(native.cache_creation_input_tokens),\n\t\toutput: Number(native.completion_tokens),\n\t\tcacheRead: Number(cached),\n\t\tcacheWrite: Number(native.cache_creation_input_tokens),\n\t\ttotalTokens: Number(native.total_tokens),\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n\tif (usage.input < 0 || usage.output < 0) throw new Error(\"Invalid native usage\");\n\tcalculateCost(model, usage);\n\tconst details = choice.message.reasoning_details;\n\tconst carrier = Array.isArray(details)\n\t\t? details.find((entry) => entry?.type === \"claude-subscription-directsdk-experimental.native_assistant\")\n\t\t: undefined;\n\tconst projection = {\n\t\tcontent: text.trim(),\n\t\ttool_calls: calls.map((call) => ({ id: call.id, name: call.name, input: call.arguments })),\n\t};\n\tif (\n\t\t!carrier ||\n\t\tcarrier.version !== 1 ||\n\t\t!Array.isArray(carrier.messages) ||\n\t\tJSON.stringify(carrier.projection) !== JSON.stringify(projection)\n\t)\n\t\tthrow new Error(\"Invalid native replay carrier\");\n\treturn {\n\t\tcontent: [...(text ? [{ type: \"text\" as const, text }] : []), ...calls],\n\t\tcarrier: { version: 1, messages: carrier.messages, projection },\n\t\tusage,\n\t\tresponseId: String(response.id ?? \"\"),\n\t\treason: choice.finish_reason === \"tool_calls\" ? \"toolUse\" : choice.finish_reason === \"length\" ? \"length\" : \"stop\",\n\t};\n}\n\nexport function streamClaudeCode(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions: StreamOptions | SimpleStreamOptions = {},\n): AssistantMessageEventStream {\n\tconst stream = new AssistantMessageEventStream();\n\tconst output: AssistantMessage = {\n\t\trole: \"assistant\",\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tcontent: [],\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\tvoid (async () => {\n\t\tlet child: ChildProcessWithoutNullStreams | undefined;\n\t\tlet nativePid: number | undefined;\n\t\tlet nativeCleanup: Promise<void> | undefined;\n\t\tconst stopNativeOnce = () => {\n\t\t\tif (nativePid === undefined) return Promise.resolve();\n\t\t\tnativeCleanup ??= stopNative(nativePid);\n\t\t\treturn nativeCleanup;\n\t\t};\n\t\tlet timer: NodeJS.Timeout | undefined;\n\t\tlet abortTimer: NodeJS.Timeout | undefined;\n\t\tlet started = false;\n\t\tlet complete = false;\n\t\tlet buffer = \"\";\n\t\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\t\tlet text = \"\";\n\t\tlet thinking = \"\";\n\t\tlet activeIndex = -1;\n\t\tlet activeType: \"text\" | \"thinking\" | undefined;\n\t\ttry {\n\t\t\tvalidateOptions(model, options);\n\t\t\tif (options.signal?.aborted) throw new Error(\"Claude Code request cancelled\");\n\t\t\tconst connection = options.externalClaudeCode!;\n\t\t\tconst env = claudeCodeEnvironment(connection.configDir);\n\t\t\tconst input = history(context, model, connection);\n\t\t\tconst anthropicOptions = options as StreamOptions & { thinkingEnabled?: boolean; effort?: string };\n\t\t\tconst reasoning =\n\t\t\t\t\"reasoning\" in options && options.reasoning\n\t\t\t\t\t? { enabled: true, effort: options.reasoning }\n\t\t\t\t\t: anthropicOptions.thinkingEnabled !== undefined || anthropicOptions.effort\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tenabled: anthropicOptions.thinkingEnabled ?? true,\n\t\t\t\t\t\t\t\t...(anthropicOptions.effort ? { effort: anthropicOptions.effort } : {}),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined;\n\t\t\tconst requestId = randomUUID();\n\t\t\tchild = spawn(connection.python, [\"-s\", \"-B\", \"-u\", WORKER], {\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t\tenv,\n\t\t\t});\n\t\t\tconst worker = child;\n\t\t\tworker.stderr.resume();\n\t\t\tworker.stdin.on(\"error\", () => {});\n\t\t\tconst idleMs = Math.min(300_000, Math.max(1000, options.timeoutMs ?? 180_000));\n\t\t\tconst record = {\n\t\t\t\tv: 1,\n\t\t\t\trequestId,\n\t\t\t\ttype: \"start\",\n\t\t\t\tcommand: connection.command,\n\t\t\t\tenv,\n\t\t\t\tmodel: model.id,\n\t\t\t\t...input,\n\t\t\t\textraBody: {\n\t\t\t\t\t...(options.maxTokens ? { max_tokens: options.maxTokens } : {}),\n\t\t\t\t\t...(reasoning ? { reasoning } : {}),\n\t\t\t\t},\n\t\t\t\ttimeout: Math.round(idleMs / 1000),\n\t\t\t};\n\t\t\tconst payload = JSON.stringify(record);\n\t\t\tif (Buffer.byteLength(payload) > MAX_RECORD) throw new Error(\"Claude Code request exceeds size limit\");\n\t\t\tworker.stdin.write(`${payload}\\n`);\n\t\t\tlet cancelSent = false;\n\t\t\tlet timedOut = false;\n\t\t\tconst abort = () => {\n\t\t\t\tif (cancelSent) return;\n\t\t\t\tcancelSent = true;\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\tworker.stdin.write(`${JSON.stringify({ v: 1, requestId, type: \"cancel\" })}\\n`);\n\t\t\t\tabortTimer = setTimeout(() => {\n\t\t\t\t\tvoid stopNativeOnce().then(() => worker.kill());\n\t\t\t\t}, 2500);\n\t\t\t};\n\t\t\tconst resetDeadline = () => {\n\t\t\t\tif (cancelSent) return;\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tabort();\n\t\t\t\t}, idleMs);\n\t\t\t};\n\t\t\ttimer = setTimeout(\n\t\t\t\t() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tabort();\n\t\t\t\t},\n\t\t\t\tMath.min(30_000, idleMs),\n\t\t\t);\n\t\t\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\tif (options.signal?.aborted) abort();\n\t\t\ttry {\n\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\tworker.on(\"error\", reject);\n\t\t\t\t\tworker.stdout.on(\"data\", (data: Buffer) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuffer += decoder.decode(data, { stream: true });\n\t\t\t\t\t\t\tif (Buffer.byteLength(buffer) > MAX_RECORD)\n\t\t\t\t\t\t\t\tthrow new Error(\"Claude Code bridge record exceeds size limit\");\n\t\t\t\t\t\t\tfor (let newline = buffer.indexOf(\"\\n\"); newline >= 0; newline = buffer.indexOf(\"\\n\")) {\n\t\t\t\t\t\t\t\tconst event = parseWorkerRecord(buffer.slice(0, newline), requestId);\n\t\t\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\t\t\tif (event.type === \"ready\" || event.type === \"replay_progress\") resetDeadline();\n\t\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\t\tevent.type === \"native_started\" &&\n\t\t\t\t\t\t\t\t\tNumber.isSafeInteger(event.pid) &&\n\t\t\t\t\t\t\t\t\tNumber(event.pid) > 0\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnativePid = Number(event.pid);\n\t\t\t\t\t\t\t\t\tresetDeadline();\n\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\tcancelSent &&\n\t\t\t\t\t\t\t\t\t[\"start\", \"text_delta\", \"thinking_delta\", \"complete\"].includes(event.type)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\telse if (event.type === \"start\") {\n\t\t\t\t\t\t\t\t\tif (started) throw new Error(\"Duplicate Claude Code stream start\");\n\t\t\t\t\t\t\t\t\tstarted = true;\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\t\t\t\t} else if (event.type === \"text_delta\" || event.type === \"thinking_delta\") {\n\t\t\t\t\t\t\t\t\tif (!started || complete || typeof event.text !== \"string\")\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\"Invalid Claude Code stream delta\");\n\t\t\t\t\t\t\t\t\tresetDeadline();\n\t\t\t\t\t\t\t\t\tconst kind = event.type === \"text_delta\" ? \"text\" : \"thinking\";\n\t\t\t\t\t\t\t\t\tif (activeType !== kind) {\n\t\t\t\t\t\t\t\t\t\tif (activeType === \"text\")\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { text: string }).text,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tif (activeType === \"thinking\")\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { thinking: string }).thinking,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tactiveIndex = output.content.length;\n\t\t\t\t\t\t\t\t\t\tactiveType = kind;\n\t\t\t\t\t\t\t\t\t\tif (kind === \"text\") {\n\t\t\t\t\t\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: activeIndex, partial: output });\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: activeIndex, partial: output });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst block = output.content[activeIndex];\n\t\t\t\t\t\t\t\t\tif (kind === \"text\" && block?.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\ttext += event.text;\n\t\t\t\t\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tdelta: event.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (kind === \"thinking\" && block?.type === \"thinking\") {\n\t\t\t\t\t\t\t\t\t\tthinking += event.text;\n\t\t\t\t\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tdelta: event.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (event.type === \"complete\") {\n\t\t\t\t\t\t\t\t\tif (!started || complete) throw new Error(\"Invalid Claude Code completion order\");\n\t\t\t\t\t\t\t\t\tconst result = validatedCompletion(event.response, model, text, thinking);\n\t\t\t\t\t\t\t\t\tcomplete = true;\n\t\t\t\t\t\t\t\t\tif (activeType === \"text\")\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { text: string }).text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (activeType === \"thinking\")\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { thinking: string }).thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\toutput.content = [\n\t\t\t\t\t\t\t\t\t\t...output.content.filter((block) => block.type !== \"toolCall\"),\n\t\t\t\t\t\t\t\t\t\t...result.content.filter((block) => block.type === \"toolCall\"),\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\toutput.claudeCodeCarrier = result.carrier && {\n\t\t\t\t\t\t\t\t\t\t...result.carrier,\n\t\t\t\t\t\t\t\t\t\tcontentHash: contentHash(output.content),\n\t\t\t\t\t\t\t\t\t\taccountFingerprint: connection.accountFingerprint,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\toutput.responseId = result.responseId;\n\t\t\t\t\t\t\t\t\toutput.usage = result.usage;\n\t\t\t\t\t\t\t\t\toutput.stopReason = result.reason;\n\t\t\t\t\t\t\t\t\tfor (let index = 0; index < output.content.length; index++) {\n\t\t\t\t\t\t\t\t\t\tconst block = output.content[index];\n\t\t\t\t\t\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: index, partial: output });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: index,\n\t\t\t\t\t\t\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (event.type === \"cancelled\" && cancelSent) {\n\t\t\t\t\t\t\t\t} else if (event.type === \"error\" || event.type === \"cancelled\")\n\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t\"Claude Code request failed. Check subscription setup and native CLI compatibility.\",\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\telse throw new Error(\"Unknown Claude Code bridge event\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tworker.on(\"close\", () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tdecoder.decode();\n\t\t\t\t\t\t\tif (complete || cancelSent) resolve();\n\t\t\t\t\t\t\telse reject(new Error(\"Claude Code bridge exited without a validated completion\"));\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t\tif (options.signal?.aborted || timedOut) throw new Error(\"Claude Code request cancelled or timed out\");\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t} catch (error) {\n\t\t\toutput.content = [];\n\t\t\toutput.claudeCodeCarrier = undefined;\n\t\t\toutput.stopReason = options.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\tconst detail =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t(error.message.startsWith(\"Claude Code subscription setup is required\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription does not support\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription refuses conflicting\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription requires TLS\"))\n\t\t\t\t\t? error.message\n\t\t\t\t\t: undefined;\n\t\t\toutput.errorMessage = options.signal?.aborted\n\t\t\t\t? \"Claude Code request cancelled\"\n\t\t\t\t: (detail ??\n\t\t\t\t\t\"Claude Code request failed. Run /login anthropic to check setup and Claude Code version 2.1.263.\");\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\t\tif (child) {\n\t\t\t\tif (!complete || child.exitCode === null) await stopNativeOnce();\n\t\t\t\tif (child.exitCode === null) child.kill();\n\t\t\t}\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"anthropic-claude-code-bridge.js","sourceRoot":"","sources":["../../src/api/anthropic-claude-code-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAW7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE,MAAM,WAAW,GAAG;IACnB,gBAAgB,EAA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,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO;gBAC5C,CAAC,CAAC,+BAA+B;gBACjC,CAAC,CAAC,QAAQ;oBACT,CAAC,CAAC,WAAW,CAAC,OAAO;oBACrB,CAAC,CAAC,KAAK,YAAY,sBAAsB;wBACxC,CAAC,CAAC,KAAK,CAAC,OAAO;wBACf,CAAC,CAAC,CAAC,MAAM;4BACR,kGAAkG,CAAC,CAAC;YACxG,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;gBAAS,CAAC;YACV,IAAI,KAAK;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,UAAU;gBAAE,YAAY,CAAC,UAAU,CAAC,CAAC;YACzC,IAAI,KAAK,EAAE,CAAC;gBACX,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;oBAAE,MAAM,cAAc,EAAE,CAAC;gBACjE,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;oBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YAC3C,CAAC;QACF,CAAC;IAAA,CACD,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport { createHash, randomUUID } from \"node:crypto\";\nimport type { ExternalClaudeCodeCredential } from \"../auth/types.ts\";\nimport { calculateCost } from \"../models.ts\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport { getClaudeCodeWorkerPath } from \"../utils/claude-code-assets.ts\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.ts\";\n\nconst SAFE_ERRORS = {\n\tcontext_overflow: \"Claude Code prompt is too long for the context window.\",\n\ttimeout: \"Claude Code request timed out.\",\n\trate_limit: \"Claude Code rate limit reached. Please retry your request.\",\n\toverloaded: \"Claude Code service overloaded. Please retry your request.\",\n\ttransient: \"Claude Code service unavailable. Please retry your request.\",\n\tincomplete: \"Claude Code stream ended before message_stop. Please retry your request.\",\n} as const;\n\nclass ClaudeCodeRequestError extends Error {\n\tconstructor(category: unknown) {\n\t\tsuper(\n\t\t\ttypeof category === \"string\" && Object.hasOwn(SAFE_ERRORS, category)\n\t\t\t\t? SAFE_ERRORS[category as keyof typeof SAFE_ERRORS]\n\t\t\t\t: \"Claude Code request failed. Run /login anthropic to check setup and Claude Code version 2.1.263.\",\n\t\t);\n\t}\n}\n\nconst MAX_RECORD = 64 * 1024 * 1024;\nconst CONFLICTS = [\n\t\"ANTHROPIC_API_KEY\",\n\t\"ANTHROPIC_AUTH_TOKEN\",\n\t\"ANTHROPIC_OAUTH_TOKEN\",\n\t\"ANTHROPIC_BASE_URL\",\n\t\"ANTHROPIC_FOUNDRY_API_KEY\",\n\t\"CLAUDE_CODE_USE_BEDROCK\",\n\t\"CLAUDE_CODE_USE_VERTEX\",\n\t\"CLAUDE_CODE_USE_FOUNDRY\",\n\t\"CLAUDE_CODE_EXTRA_BODY\",\n] as const;\nconst ENV_ALLOWLIST = [\n\t\"PATH\",\n\t\"HOME\",\n\t\"USERPROFILE\",\n\t\"APPDATA\",\n\t\"LOCALAPPDATA\",\n\t\"PROGRAMDATA\",\n\t\"SYSTEMROOT\",\n\t\"SYSTEMDRIVE\",\n\t\"COMSPEC\",\n\t\"PATHEXT\",\n\t\"TEMP\",\n\t\"TMP\",\n\t\"LANG\",\n\t\"LC_ALL\",\n\t\"HTTP_PROXY\",\n\t\"HTTPS_PROXY\",\n\t\"NO_PROXY\",\n\t\"http_proxy\",\n\t\"https_proxy\",\n\t\"no_proxy\",\n] as const;\n\nexport function claudeCodeEnvironment(configDir?: string, strict = true): Record<string, string> {\n\tconst conflicting = CONFLICTS.filter((name) => {\n\t\tconst value = process.env[name];\n\t\treturn (\n\t\t\tvalue &&\n\t\t\t((name !== \"CLAUDE_CODE_USE_BEDROCK\" &&\n\t\t\t\tname !== \"CLAUDE_CODE_USE_VERTEX\" &&\n\t\t\t\tname !== \"CLAUDE_CODE_USE_FOUNDRY\") ||\n\t\t\t\t![\"0\", \"false\", \"no\", \"off\"].includes(value.toLowerCase()))\n\t\t);\n\t});\n\tif (strict && conflicting.length)\n\t\tthrow new Error(`Claude Code subscription refuses conflicting environment variables: ${conflicting.join(\", \")}`);\n\tif (process.env.NODE_TLS_REJECT_UNAUTHORIZED === \"0\")\n\t\tthrow new Error(\"Claude Code subscription requires TLS certificate verification\");\n\tconst env = Object.fromEntries(\n\t\tENV_ALLOWLIST.flatMap((name) => (process.env[name] ? [[name, process.env[name]]] : [])),\n\t);\n\tif (configDir) env.CLAUDE_SUBSCRIPTION_DIRECTSDK_CONFIG_DIR = configDir;\n\treturn env;\n}\n\nfunction contentHash(content: AssistantMessage[\"content\"]): string {\n\treturn createHash(\"sha256\").update(JSON.stringify(content)).digest(\"hex\");\n}\n\nfunction history(\n\tcontext: Context,\n\tmodel: Model<Api>,\n\tconnection: ExternalClaudeCodeCredential,\n): { messages: unknown[]; tools: unknown[] } {\n\tconst messages: Record<string, unknown>[] = context.systemPrompt\n\t\t? [{ role: \"system\", content: context.systemPrompt }]\n\t\t: [];\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof message.content === \"string\"\n\t\t\t\t\t\t? message.content\n\t\t\t\t\t\t: message.content.map((block) =>\n\t\t\t\t\t\t\t\tblock.type === \"text\"\n\t\t\t\t\t\t\t\t\t? { type: \"text\", text: block.text }\n\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\ttype: \"image_url\",\n\t\t\t\t\t\t\t\t\t\t\timage_url: { url: `data:${block.mimeType};base64,${block.data}` },\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tconst text = message.content\n\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t.map((block) => block.text)\n\t\t\t\t.join(\"\");\n\t\t\tconst calls = message.content\n\t\t\t\t.filter((block): block is ToolCall => block.type === \"toolCall\")\n\t\t\t\t.map((block) => ({\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: { name: block.name, arguments: JSON.stringify(block.arguments) },\n\t\t\t\t}));\n\t\t\tconst projection = {\n\t\t\t\tcontent: text.trim(),\n\t\t\t\ttool_calls: calls.map((call) => ({\n\t\t\t\t\tid: call.id,\n\t\t\t\t\tname: call.function.name,\n\t\t\t\t\tinput: JSON.parse(call.function.arguments),\n\t\t\t\t})),\n\t\t\t};\n\t\t\tconst carrier =\n\t\t\t\tmessage.provider === \"anthropic\" &&\n\t\t\t\tmessage.model === model.id &&\n\t\t\t\tmessage.claudeCodeCarrier?.version === 1 &&\n\t\t\t\tconnection.accountFingerprint &&\n\t\t\t\tmessage.claudeCodeCarrier.accountFingerprint === connection.accountFingerprint &&\n\t\t\t\tmessage.claudeCodeCarrier.contentHash === contentHash(message.content) &&\n\t\t\t\tJSON.stringify(message.claudeCodeCarrier.projection) === JSON.stringify(projection)\n\t\t\t\t\t? [{ type: \"claude-subscription-directsdk-experimental.native_assistant\", ...message.claudeCodeCarrier }]\n\t\t\t\t\t: [];\n\t\t\tmessages.push({ role: \"assistant\", content: text, tool_calls: calls, reasoning_details: carrier });\n\t\t} else {\n\t\t\tif (message.content.some((block) => block.type !== \"text\"))\n\t\t\t\tthrow new Error(\"Claude Code subscription supports text tool results only\");\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t\tcontent: message.content.map((block) => (block.type === \"text\" ? block.text : \"\")).join(\"\"),\n\t\t\t\tis_error: message.isError,\n\t\t\t});\n\t\t}\n\t}\n\tconst tools = (context.tools ?? []).map((tool) => ({\n\t\ttype: \"function\",\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t},\n\t}));\n\treturn { messages, tools };\n}\n\nfunction validateOptions(model: Model<Api>, options: StreamOptions | SimpleStreamOptions): void {\n\tif (!options.externalClaudeCode)\n\t\tthrow new Error(\"Claude Code subscription setup is required. Run /login anthropic.\");\n\tif (\n\t\toptions.apiKey ||\n\t\tObject.keys(options.headers ?? {}).length ||\n\t\toptions.onPayload ||\n\t\toptions.onResponse ||\n\t\toptions.env ||\n\t\toptions.metadata ||\n\t\t(options.transport && options.transport !== \"auto\") ||\n\t\toptions.maxRetries ||\n\t\t(options.maxRetryDelayMs !== undefined && options.maxRetryDelayMs !== 60_000) ||\n\t\toptions.websocketConnectTimeoutMs ||\n\t\tmodel.baseUrl !== \"https://api.anthropic.com\"\n\t) {\n\t\tthrow new Error(\"Claude Code subscription does not support API keys, alternate endpoints, or request mutations\");\n\t}\n\tconst anthro = options as StreamOptions & {\n\t\ttoolChoice?: unknown;\n\t\tclient?: unknown;\n\t\textraBody?: unknown;\n\t\tthinkingBudgetTokens?: unknown;\n\t\tstopSequences?: unknown;\n\t\tthinkingEnabled?: boolean;\n\t\teffort?: string;\n\t\tthinkingDisplay?: unknown;\n\t\tinterleavedThinking?: unknown;\n\t};\n\tif (\n\t\t(anthro.toolChoice && anthro.toolChoice !== \"auto\") ||\n\t\tanthro.client ||\n\t\tanthro.extraBody ||\n\t\tanthro.thinkingBudgetTokens ||\n\t\tanthro.stopSequences ||\n\t\tanthro.thinkingDisplay !== undefined ||\n\t\tanthro.interleavedThinking !== undefined\n\t) {\n\t\tthrow new Error(\"Claude Code subscription does not support forced tools or native request overrides\");\n\t}\n\tif (options.temperature !== undefined)\n\t\tthrow new Error(\"Claude Code subscription does not support sampling overrides\");\n}\n\ntype WorkerEvent = {\n\tv: 1;\n\trequestId: string;\n\ttype: string;\n\ttext?: unknown;\n\tpid?: unknown;\n\tresponse?: unknown;\n\tcategory?: unknown;\n};\n\nfunction parseWorkerRecord(line: string, requestId: string): WorkerEvent {\n\tif (Buffer.byteLength(line) > MAX_RECORD) throw new Error(\"Claude Code bridge record exceeds size limit\");\n\tconst value: unknown = JSON.parse(line);\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"v\" in value) ||\n\t\tvalue.v !== 1 ||\n\t\t!(\"requestId\" in value) ||\n\t\tvalue.requestId !== requestId ||\n\t\t!(\"type\" in value) ||\n\t\ttypeof value.type !== \"string\"\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code bridge record\");\n\t}\n\treturn value as WorkerEvent;\n}\n\nexport async function stopNative(pid: number): Promise<void> {\n\tif (!Number.isSafeInteger(pid) || pid < 1) return;\n\tif (process.platform === \"win32\") {\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst killer = spawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], { stdio: \"ignore\", windowsHide: true });\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tkiller.kill();\n\t\t\t\tresolve();\n\t\t\t}, 3000);\n\t\t\tkiller.once(\"error\", () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t\tkiller.once(\"close\", () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t} else {\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t/* Already exited. */\n\t\t}\n\t}\n}\n\nfunction validatedCompletion(\n\tvalue: unknown,\n\tmodel: Model<Api>,\n\ttext: string,\n\tthinking: string,\n): {\n\tcontent: AssistantMessage[\"content\"];\n\tcarrier: AssistantMessage[\"claudeCodeCarrier\"];\n\tusage: Usage;\n\tresponseId: string;\n\treason: \"stop\" | \"length\" | \"toolUse\";\n} {\n\tif (!value || typeof value !== \"object\" || !(\"choices\" in value) || !Array.isArray(value.choices))\n\t\tthrow new Error(\"Invalid native completion\");\n\tconst response = value as Record<string, unknown> & {\n\t\tchoices: { finish_reason: unknown; message: Record<string, unknown> }[];\n\t\tusage: Record<string, unknown>;\n\t};\n\tconst choice = response.choices[0];\n\tif (\n\t\t!choice ||\n\t\t![\"stop\", \"length\", \"tool_calls\"].includes(String(choice.finish_reason)) ||\n\t\t(typeof choice.message?.content !== \"string\" && choice.message?.content !== null) ||\n\t\t(choice.message.content ?? \"\") !== text ||\n\t\t(choice.message.reasoning_content ?? \"\") !== thinking\n\t)\n\t\tthrow new Error(\"Native completion differs from streamed content\");\n\tconst rawCalls = choice.message.tool_calls ?? [];\n\tif (!Array.isArray(rawCalls)) throw new Error(\"Invalid native tool calls\");\n\tconst calls: ToolCall[] = rawCalls.map((call) => {\n\t\tif (\n\t\t\t!call ||\n\t\t\ttypeof call !== \"object\" ||\n\t\t\ttypeof call.id !== \"string\" ||\n\t\t\ttypeof call.function?.name !== \"string\" ||\n\t\t\ttypeof call.function?.arguments !== \"string\"\n\t\t)\n\t\t\tthrow new Error(\"Invalid native tool call\");\n\t\tconst args: unknown = JSON.parse(call.function.arguments);\n\t\tif (!args || typeof args !== \"object\" || Array.isArray(args)) throw new Error(\"Invalid native tool arguments\");\n\t\treturn { type: \"toolCall\", id: call.id, name: call.function.name, arguments: args as Record<string, unknown> };\n\t});\n\tconst native = response.usage;\n\tif (\n\t\t!native ||\n\t\ttypeof native.native_admission !== \"object\" ||\n\t\tnative.native_admission === null ||\n\t\t(native.native_admission as { upstream_requests?: unknown }).upstream_requests !== 1\n\t)\n\t\tthrow new Error(\"Native one-request admission not verified\");\n\tif (\n\t\t!native ||\n\t\t!Number.isFinite(native.prompt_tokens) ||\n\t\t!Number.isFinite(native.completion_tokens) ||\n\t\t!Number.isFinite(native.cache_creation_input_tokens) ||\n\t\t!(\"prompt_tokens_details\" in native)\n\t)\n\t\tthrow new Error(\"Missing native usage\");\n\tconst cached = (native.prompt_tokens_details as { cached_tokens?: unknown }).cached_tokens;\n\tif (!Number.isFinite(cached)) throw new Error(\"Missing native cache usage\");\n\tconst usage: Usage = {\n\t\tinput: Number(native.prompt_tokens) - Number(cached) - Number(native.cache_creation_input_tokens),\n\t\toutput: Number(native.completion_tokens),\n\t\tcacheRead: Number(cached),\n\t\tcacheWrite: Number(native.cache_creation_input_tokens),\n\t\ttotalTokens: Number(native.total_tokens),\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n\tif (usage.input < 0 || usage.output < 0) throw new Error(\"Invalid native usage\");\n\tcalculateCost(model, usage);\n\tconst details = choice.message.reasoning_details;\n\tconst carrier = Array.isArray(details)\n\t\t? details.find((entry) => entry?.type === \"claude-subscription-directsdk-experimental.native_assistant\")\n\t\t: undefined;\n\tconst projection = {\n\t\tcontent: text.trim(),\n\t\ttool_calls: calls.map((call) => ({ id: call.id, name: call.name, input: call.arguments })),\n\t};\n\tif (\n\t\t!carrier ||\n\t\tcarrier.version !== 1 ||\n\t\t!Array.isArray(carrier.messages) ||\n\t\tJSON.stringify(carrier.projection) !== JSON.stringify(projection)\n\t)\n\t\tthrow new Error(\"Invalid native replay carrier\");\n\treturn {\n\t\tcontent: [...(text ? [{ type: \"text\" as const, text }] : []), ...calls],\n\t\tcarrier: { version: 1, messages: carrier.messages, projection },\n\t\tusage,\n\t\tresponseId: String(response.id ?? \"\"),\n\t\treason: choice.finish_reason === \"tool_calls\" ? \"toolUse\" : choice.finish_reason === \"length\" ? \"length\" : \"stop\",\n\t};\n}\n\nexport function streamClaudeCode(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions: StreamOptions | SimpleStreamOptions = {},\n): AssistantMessageEventStream {\n\tconst stream = new AssistantMessageEventStream();\n\tconst output: AssistantMessage = {\n\t\trole: \"assistant\",\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tcontent: [],\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\tvoid (async () => {\n\t\tlet child: ChildProcessWithoutNullStreams | undefined;\n\t\tlet nativePid: number | undefined;\n\t\tlet nativeCleanup: Promise<void> | undefined;\n\t\tconst stopNativeOnce = () => {\n\t\t\tif (nativePid === undefined) return Promise.resolve();\n\t\t\tnativeCleanup ??= stopNative(nativePid);\n\t\t\treturn nativeCleanup;\n\t\t};\n\t\tlet timedOut = false;\n\t\tlet timer: NodeJS.Timeout | undefined;\n\t\tlet abortTimer: NodeJS.Timeout | undefined;\n\t\tlet started = false;\n\t\tlet complete = false;\n\t\tlet buffer = \"\";\n\t\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\t\tlet text = \"\";\n\t\tlet thinking = \"\";\n\t\tlet activeIndex = -1;\n\t\tlet activeType: \"text\" | \"thinking\" | undefined;\n\t\ttry {\n\t\t\tvalidateOptions(model, options);\n\t\t\tif (options.signal?.aborted) throw new Error(\"Claude Code request cancelled\");\n\t\t\tconst connection = options.externalClaudeCode!;\n\t\t\tconst env = claudeCodeEnvironment(connection.configDir);\n\t\t\tconst input = history(context, model, connection);\n\t\t\tconst anthropicOptions = options as StreamOptions & { thinkingEnabled?: boolean; effort?: string };\n\t\t\tconst reasoning =\n\t\t\t\t\"reasoning\" in options && options.reasoning\n\t\t\t\t\t? { enabled: true, effort: options.reasoning }\n\t\t\t\t\t: anthropicOptions.thinkingEnabled !== undefined || anthropicOptions.effort\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tenabled: anthropicOptions.thinkingEnabled ?? true,\n\t\t\t\t\t\t\t\t...(anthropicOptions.effort ? { effort: anthropicOptions.effort } : {}),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined;\n\t\t\tconst requestId = randomUUID();\n\t\t\tchild = spawn(connection.python, [\"-s\", \"-B\", \"-u\", getClaudeCodeWorkerPath(\"lunr_bridge.py\")], {\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t\tenv,\n\t\t\t});\n\t\t\tconst worker = child;\n\t\t\tworker.stderr.resume();\n\t\t\tworker.stdin.on(\"error\", () => {});\n\t\t\tconst idleMs = Math.min(300_000, Math.max(1000, options.timeoutMs ?? 180_000));\n\t\t\tconst record = {\n\t\t\t\tv: 1,\n\t\t\t\trequestId,\n\t\t\t\ttype: \"start\",\n\t\t\t\tcommand: connection.command,\n\t\t\t\tenv,\n\t\t\t\tmodel: model.id,\n\t\t\t\t...input,\n\t\t\t\textraBody: {\n\t\t\t\t\t...(options.maxTokens ? { max_tokens: options.maxTokens } : {}),\n\t\t\t\t\t...(reasoning ? { reasoning } : {}),\n\t\t\t\t},\n\t\t\t\ttimeout: Math.round(idleMs / 1000),\n\t\t\t};\n\t\t\tconst payload = JSON.stringify(record);\n\t\t\tif (Buffer.byteLength(payload) > MAX_RECORD) throw new Error(\"Claude Code request exceeds size limit\");\n\t\t\tworker.stdin.write(`${payload}\\n`);\n\t\t\tlet cancelSent = false;\n\t\t\tconst abort = () => {\n\t\t\t\tif (cancelSent) return;\n\t\t\t\tcancelSent = true;\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\tworker.stdin.write(`${JSON.stringify({ v: 1, requestId, type: \"cancel\" })}\\n`);\n\t\t\t\tabortTimer = setTimeout(() => {\n\t\t\t\t\tvoid stopNativeOnce().then(() => worker.kill());\n\t\t\t\t}, 2500);\n\t\t\t};\n\t\t\tconst resetDeadline = () => {\n\t\t\t\tif (cancelSent) return;\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tabort();\n\t\t\t\t}, idleMs);\n\t\t\t};\n\t\t\ttimer = setTimeout(\n\t\t\t\t() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tabort();\n\t\t\t\t},\n\t\t\t\tMath.min(30_000, idleMs),\n\t\t\t);\n\t\t\toptions.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\tif (options.signal?.aborted) abort();\n\t\t\ttry {\n\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\tworker.on(\"error\", reject);\n\t\t\t\t\tworker.stdout.on(\"data\", (data: Buffer) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tbuffer += decoder.decode(data, { stream: true });\n\t\t\t\t\t\t\tif (Buffer.byteLength(buffer) > MAX_RECORD)\n\t\t\t\t\t\t\t\tthrow new Error(\"Claude Code bridge record exceeds size limit\");\n\t\t\t\t\t\t\tfor (let newline = buffer.indexOf(\"\\n\"); newline >= 0; newline = buffer.indexOf(\"\\n\")) {\n\t\t\t\t\t\t\t\tconst event = parseWorkerRecord(buffer.slice(0, newline), requestId);\n\t\t\t\t\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\t\t\t\t\tif (event.type === \"ready\" || event.type === \"replay_progress\") resetDeadline();\n\t\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\t\tevent.type === \"native_started\" &&\n\t\t\t\t\t\t\t\t\tNumber.isSafeInteger(event.pid) &&\n\t\t\t\t\t\t\t\t\tNumber(event.pid) > 0\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnativePid = Number(event.pid);\n\t\t\t\t\t\t\t\t\tresetDeadline();\n\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\tcancelSent &&\n\t\t\t\t\t\t\t\t\t[\"start\", \"text_delta\", \"thinking_delta\", \"complete\"].includes(event.type)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\telse if (event.type === \"start\") {\n\t\t\t\t\t\t\t\t\tif (started) throw new Error(\"Duplicate Claude Code stream start\");\n\t\t\t\t\t\t\t\t\tstarted = true;\n\t\t\t\t\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\t\t\t\t} else if (event.type === \"text_delta\" || event.type === \"thinking_delta\") {\n\t\t\t\t\t\t\t\t\tif (!started || complete || typeof event.text !== \"string\")\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\"Invalid Claude Code stream delta\");\n\t\t\t\t\t\t\t\t\tresetDeadline();\n\t\t\t\t\t\t\t\t\tconst kind = event.type === \"text_delta\" ? \"text\" : \"thinking\";\n\t\t\t\t\t\t\t\t\tif (activeType !== kind) {\n\t\t\t\t\t\t\t\t\t\tif (activeType === \"text\")\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { text: string }).text,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tif (activeType === \"thinking\")\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { thinking: string }).thinking,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tactiveIndex = output.content.length;\n\t\t\t\t\t\t\t\t\t\tactiveType = kind;\n\t\t\t\t\t\t\t\t\t\tif (kind === \"text\") {\n\t\t\t\t\t\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: activeIndex, partial: output });\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: activeIndex, partial: output });\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst block = output.content[activeIndex];\n\t\t\t\t\t\t\t\t\tif (kind === \"text\" && block?.type === \"text\") {\n\t\t\t\t\t\t\t\t\t\ttext += event.text;\n\t\t\t\t\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tdelta: event.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (kind === \"thinking\" && block?.type === \"thinking\") {\n\t\t\t\t\t\t\t\t\t\tthinking += event.text;\n\t\t\t\t\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tdelta: event.text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (event.type === \"complete\") {\n\t\t\t\t\t\t\t\t\tif (!started || complete) throw new Error(\"Invalid Claude Code completion order\");\n\t\t\t\t\t\t\t\t\tconst result = validatedCompletion(event.response, model, text, thinking);\n\t\t\t\t\t\t\t\t\tcomplete = true;\n\t\t\t\t\t\t\t\t\tif (activeType === \"text\")\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { text: string }).text,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tif (activeType === \"thinking\")\n\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\t\t\t\t\tcontentIndex: activeIndex,\n\t\t\t\t\t\t\t\t\t\t\tcontent: (output.content[activeIndex] as { thinking: string }).thinking,\n\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\toutput.content = [\n\t\t\t\t\t\t\t\t\t\t...output.content.filter((block) => block.type !== \"toolCall\"),\n\t\t\t\t\t\t\t\t\t\t...result.content.filter((block) => block.type === \"toolCall\"),\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\toutput.claudeCodeCarrier = result.carrier && {\n\t\t\t\t\t\t\t\t\t\t...result.carrier,\n\t\t\t\t\t\t\t\t\t\tcontentHash: contentHash(output.content),\n\t\t\t\t\t\t\t\t\t\taccountFingerprint: connection.accountFingerprint,\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\toutput.responseId = result.responseId;\n\t\t\t\t\t\t\t\t\toutput.usage = result.usage;\n\t\t\t\t\t\t\t\t\toutput.stopReason = result.reason;\n\t\t\t\t\t\t\t\t\tfor (let index = 0; index < output.content.length; index++) {\n\t\t\t\t\t\t\t\t\t\tconst block = output.content[index];\n\t\t\t\t\t\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: index, partial: output });\n\t\t\t\t\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\t\t\t\t\t\t\tcontentIndex: index,\n\t\t\t\t\t\t\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (event.type === \"cancelled\" && cancelSent) {\n\t\t\t\t\t\t\t\t} else if (event.type === \"error\" || event.type === \"cancelled\")\n\t\t\t\t\t\t\t\t\tthrow new ClaudeCodeRequestError(event.type === \"error\" ? event.category : undefined);\n\t\t\t\t\t\t\t\telse throw new Error(\"Unknown Claude Code bridge event\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tworker.on(\"close\", () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tdecoder.decode();\n\t\t\t\t\t\t\tif (complete || cancelSent) resolve();\n\t\t\t\t\t\t\telse reject(new Error(\"Claude Code bridge exited without a validated completion\"));\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t\tif (timedOut) throw new ClaudeCodeRequestError(\"timeout\");\n\t\t\tif (options.signal?.aborted) throw new Error(\"Claude Code request cancelled\");\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t} catch (error) {\n\t\t\toutput.content = [];\n\t\t\toutput.claudeCodeCarrier = undefined;\n\t\t\toutput.stopReason = options.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\tconst detail =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t(error.message.startsWith(\"Claude Code subscription setup is required\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription does not support\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription refuses conflicting\") ||\n\t\t\t\t\terror.message.startsWith(\"Claude Code subscription requires TLS\"))\n\t\t\t\t\t? error.message\n\t\t\t\t\t: undefined;\n\t\t\toutput.errorMessage = options.signal?.aborted\n\t\t\t\t? \"Claude Code request cancelled\"\n\t\t\t\t: timedOut\n\t\t\t\t\t? SAFE_ERRORS.timeout\n\t\t\t\t\t: error instanceof ClaudeCodeRequestError\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: (detail ??\n\t\t\t\t\t\t\t\"Claude Code request failed. Run /login anthropic to check setup and Claude Code version 2.1.263.\");\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\tif (abortTimer) clearTimeout(abortTimer);\n\t\t\tif (child) {\n\t\t\t\tif (!complete || child.exitCode === null) await stopNativeOnce();\n\t\t\t\tif (child.exitCode === null) child.kill();\n\t\t\t}\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAiBlF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;CAAE,GAAG,SAAS,CAajH","sourcesContent":["import type { ApiKeyAuth, OAuthAuth } from \"./types.ts\";\n\n/**\n * Standard api-key auth: a stored credential key wins, otherwise the first\n * set env var resolves. Includes a `login` that prompts for the key.\n * Providers with non-standard resolution (provider env, ambient files, IAM)\n * write their own `ApiKeyAuth`.\n */\nexport function envApiKeyAuth(name: string, envVars: readonly string[]): ApiKeyAuth {\n\treturn {\n\t\tname,\n\t\tlogin: async (interaction) => {\n\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: `Enter ${name}` });\n\t\t\treturn { type: \"api_key\", key };\n\t\t},\n\t\tresolve: async ({ ctx, credential }) => {\n\t\t\tif (credential?.key)\n\t\t\t\treturn { auth: { apiKey: credential.key }, env: credential.env, source: \"stored credential\" };\n\t\t\tfor (const envVar of envVars) {\n\t\t\t\tconst value = await ctx.env(envVar);\n\t\t\t\tif (value) return { auth: { apiKey: value }, env: credential?.env, source: envVar };\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\n/**\n * Wraps a dynamically imported `OAuthAuth` so provider definitions can\n * advertise OAuth without importing the implementation. The flow loads on\n * first `login`/`refresh`/`toAuth` call; callers keep Node-only flow code out\n * of bundles by loading through a bundler-opaque dynamic import (variable\n * specifier, see the bedrock lazy wrapper).\n */\nexport function lazyOAuth(input: { name: string; loginLabel?: string; load: () => Promise<OAuthAuth> }): OAuthAuth {\n\tlet promise: Promise<OAuthAuth> | undefined;\n\tconst loaded = () => {\n\t\tpromise ??= input.load();\n\t\treturn promise;\n\t};\n\treturn {\n\t\tname: input.name,\n\t\tloginLabel: input.loginLabel,\n\t\tlogin: async (interaction) => (await loaded()).login(interaction),\n\t\trefresh: async (credential, signal) => (await loaded()).refresh(credential, signal),\n\t\ttoAuth: async (credential) => (await loaded()).toAuth(credential),\n\t};\n}\n"]}
|
package/dist/auth/helpers.js
CHANGED
|
@@ -13,11 +13,11 @@ export function envApiKeyAuth(name, envVars) {
|
|
|
13
13
|
},
|
|
14
14
|
resolve: async ({ ctx, credential }) => {
|
|
15
15
|
if (credential?.key)
|
|
16
|
-
return { auth: { apiKey: credential.key }, source: "stored credential" };
|
|
16
|
+
return { auth: { apiKey: credential.key }, env: credential.env, source: "stored credential" };
|
|
17
17
|
for (const envVar of envVars) {
|
|
18
18
|
const value = await ctx.env(envVar);
|
|
19
19
|
if (value)
|
|
20
|
-
return { auth: { apiKey: value }, source: envVar };
|
|
20
|
+
return { auth: { apiKey: value }, env: credential?.env, source: envVar };
|
|
21
21
|
}
|
|
22
22
|
return undefined;
|
|
23
23
|
},
|
package/dist/auth/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAA0B,EAAc;IACnF,OAAO;QACN,IAAI;QACJ,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,IAAI,EAAE,EAAE,CAAC,CAAC;YACnF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;QAAA,CAChC;QACD,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;YACvC,IAAI,UAAU,EAAE,GAAG;
|
|
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A,CACf,CAAC;IACF,OAAO;QACN,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC;QACjE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC;QACnF,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;KACjE,CAAC;AAAA,CACF","sourcesContent":["import type { ApiKeyAuth, OAuthAuth } from \"./types.ts\";\n\n/**\n * Standard api-key auth: a stored credential key wins, otherwise the first\n * set env var resolves. Includes a `login` that prompts for the key.\n * Providers with non-standard resolution (provider env, ambient files, IAM)\n * write their own `ApiKeyAuth`.\n */\nexport function envApiKeyAuth(name: string, envVars: readonly string[]): ApiKeyAuth {\n\treturn {\n\t\tname,\n\t\tlogin: async (interaction) => {\n\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: `Enter ${name}` });\n\t\t\treturn { type: \"api_key\", key };\n\t\t},\n\t\tresolve: async ({ ctx, credential }) => {\n\t\t\tif (credential?.key)\n\t\t\t\treturn { auth: { apiKey: credential.key }, env: credential.env, source: \"stored credential\" };\n\t\t\tfor (const envVar of envVars) {\n\t\t\t\tconst value = await ctx.env(envVar);\n\t\t\t\tif (value) return { auth: { apiKey: value }, env: credential?.env, source: envVar };\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\n/**\n * Wraps a dynamically imported `OAuthAuth` so provider definitions can\n * advertise OAuth without importing the implementation. The flow loads on\n * first `login`/`refresh`/`toAuth` call; callers keep Node-only flow code out\n * of bundles by loading through a bundler-opaque dynamic import (variable\n * specifier, see the bedrock lazy wrapper).\n */\nexport function lazyOAuth(input: { name: string; loginLabel?: string; load: () => Promise<OAuthAuth> }): OAuthAuth {\n\tlet promise: Promise<OAuthAuth> | undefined;\n\tconst loaded = () => {\n\t\tpromise ??= input.load();\n\t\treturn promise;\n\t};\n\treturn {\n\t\tname: input.name,\n\t\tloginLabel: input.loginLabel,\n\t\tlogin: async (interaction) => (await loaded()).login(interaction),\n\t\trefresh: async (credential, signal) => (await loaded()).refresh(credential, signal),\n\t\ttoAuth: async (credential) => (await loaded()).toAuth(credential),\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/anthropic.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAiD,SAAS,EAAE,MAAM,aAAa,CAAC;AAO5F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnE;AA2OD,eAAO,MAAM,cAAc,EAAE,SAU5B,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { access, constants } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { delimiter, isAbsolute, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { claudeCodeEnvironment, stopNative } from \"../../api/anthropic-claude-code-bridge.ts\";\nimport type { AuthInteraction, ExternalClaudeCodeCredential, OAuthAuth } from \"../types.ts\";\n\nconst SETUP_WORKER = fileURLToPath(\n\tnew URL(\"../../../vendor/hermes-claude-subscription-directsdk/lunr_setup_bridge.py\", import.meta.url),\n);\nconst VERSION = \"2.1.263\";\n\nexport function isQualifiedClaudeCodeVersion(value: string): boolean {\n\treturn new RegExp(`^${VERSION.replaceAll(\".\", \"\\\\.\")}(?:\\\\s|$)`).test(value);\n}\n\nasync function run(command: string, args: string[], input?: string, timeout = 25_000): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(command, args, {\n\t\t\tstdio: [\"pipe\", \"pipe\", \"ignore\"],\n\t\t\twindowsHide: true,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tenv: claudeCodeEnvironment(undefined, false),\n\t\t});\n\t\tlet output = \"\";\n\t\tlet timedOut = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tvoid stopNative(child.pid ?? 0).finally(() => {\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout.destroy();\n\t\t\t\tchild.stdin.destroy();\n\t\t\t\treject(new Error(\"Dependency check timed out\"));\n\t\t\t});\n\t\t}, timeout);\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\t\toutput += chunk.toString(\"utf8\");\n\t\t\tif (output.length > 64 * 1024) child.kill();\n\t\t});\n\t\tchild.stdin.on(\"error\", () => {});\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code) => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (timedOut) return;\n\t\t\tif (code !== 0) reject(new Error(\"Dependency check failed\"));\n\t\t\telse resolve(output.trim());\n\t\t});\n\t\tchild.stdin.end(input);\n\t});\n}\n\nasync function executable(name: string): Promise<string | undefined> {\n\tconst suffixes = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tconst directories = isAbsolute(name)\n\t\t? [\"\"]\n\t\t: [...(process.env.PATH ?? \"\").split(delimiter), join(homedir(), \".local\", \"bin\")];\n\tfor (const directory of directories) {\n\t\tfor (const suffix of suffixes) {\n\t\t\tconst candidate = directory ? join(directory, `${name}${suffix}`) : `${name}${suffix}`;\n\t\t\ttry {\n\t\t\t\tawait access(candidate, constants.X_OK);\n\t\t\t\treturn candidate;\n\t\t\t} catch {\n\t\t\t\t/* Next location. */\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function pythonInterpreter(): Promise<string | undefined> {\n\tfor (const name of [\"python3\", \"python\"]) {\n\t\tconst path = await executable(name);\n\t\tif (!path) continue;\n\t\ttry {\n\t\t\tconst version = await run(path, [\"--version\"]);\n\t\t\tconst match = /^Python (\\d+)\\.(\\d+)/.exec(version);\n\t\t\tif (match && (Number(match[1]) > 3 || (Number(match[1]) === 3 && Number(match[2]) >= 10))) return path;\n\t\t} catch {\n\t\t\t/* Try another interpreter. */\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function install(command: string, args: string[], interaction: AuthInteraction): Promise<void> {\n\tconst confirm = await interaction.prompt({\n\t\ttype: \"select\",\n\t\tmessage: `Run ${command} ${args.join(\" \")}? This downloads software and changes your user-level system installation.`,\n\t\toptions: [\n\t\t\t{ id: \"yes\", label: \"Install\" },\n\t\t\t{ id: \"no\", label: \"Cancel\" },\n\t\t],\n\t});\n\tif (confirm !== \"yes\") throw new Error(\"Anthropic subscription setup cancelled\");\n\tinteraction.notify({ type: \"progress\", message: \"Running the confirmed installer...\" });\n\tawait run(command, args, undefined, 300_000);\n}\n\nasync function setupProbe(python: string, command: string, type: \"status\" | \"discover\" | \"version\"): Promise<unknown> {\n\tconst requestId = randomUUID();\n\tconst line = await run(\n\t\tpython,\n\t\t[\"-s\", \"-B\", \"-u\", SETUP_WORKER],\n\t\t`${JSON.stringify({ v: 1, requestId, type, command, env: claudeCodeEnvironment(undefined, false) })}\\n`,\n\t\t55_000,\n\t);\n\tconst record: unknown = JSON.parse(line);\n\tif (\n\t\t!record ||\n\t\ttypeof record !== \"object\" ||\n\t\t!(\"v\" in record) ||\n\t\trecord.v !== 1 ||\n\t\t!(\"requestId\" in record) ||\n\t\trecord.requestId !== requestId ||\n\t\t!(\"type\" in record) ||\n\t\trecord.type !== \"result\" ||\n\t\t!(\"result\" in record)\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code setup response\");\n\t}\n\treturn record.result;\n}\n\nasync function login(interaction: AuthInteraction): Promise<ExternalClaudeCodeCredential> {\n\tinteraction.notify({\n\t\ttype: \"info\",\n\t\tmessage:\n\t\t\t\"Claude Code handles subscription authentication and one generation per lunR request. lunR still owns tools, permissions, history, compaction, and subagents. Python 3.10+ and Claude Code are required. No credentials are copied into lunR.\",\n\t});\n\tlet python = await pythonInterpreter();\n\tif (!python) {\n\t\tinteraction.notify({\n\t\t\ttype: \"info\",\n\t\t\tmessage:\n\t\t\t\t\"Install Python 3.10+ from https://www.python.org/downloads/ . This is a separate operating-system installation, not part of lunR.\",\n\t\t});\n\t\tconst packageManager =\n\t\t\tprocess.platform === \"darwin\"\n\t\t\t\t? await executable(\"brew\")\n\t\t\t\t: process.platform === \"linux\"\n\t\t\t\t\t? ((await executable(\"apt-get\")) ?? (await executable(\"dnf\")))\n\t\t\t\t\t: undefined;\n\t\tconst installer =\n\t\t\tprocess.platform === \"win32\"\n\t\t\t\t? { command: \"winget\", args: [\"install\", \"--id\", \"Python.Python.3.13\", \"-e\"] }\n\t\t\t\t: packageManager?.endsWith(\"apt-get\")\n\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t: packageManager?.endsWith(\"dnf\")\n\t\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t\t: packageManager\n\t\t\t\t\t\t\t? { command: packageManager, args: [\"install\", \"python@3.13\"] }\n\t\t\t\t\t\t\t: undefined;\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage:\n\t\t\t\t\"Python 3.10+ is missing. A system installer may request administrator access and change your machine.\",\n\t\t\toptions: [\n\t\t\t\t...(installer\n\t\t\t\t\t? [{ id: \"install\", label: `Install through ${installer.command} ${installer.args.join(\" \")}` }]\n\t\t\t\t\t: []),\n\t\t\t\t{ id: \"cancel\", label: \"Cancel and install Python yourself\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\" && installer) await install(installer.command, installer.args, interaction);\n\t\telse throw new Error(\"Install Python 3.10+ and retry /login anthropic\");\n\t\tpython = await pythonInterpreter();\n\t\tif (!python)\n\t\t\tthrow new Error(\"Python installation finished but the interpreter is not on PATH. Restart lunR and retry.\");\n\t}\n\tlet command = await executable(\"claude\");\n\tif (!command) {\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code is missing. Installation changes your user-level system and may require a new PATH.\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"install\", label: \"Install Claude Code\" },\n\t\t\t\t{ id: \"existing\", label: \"Use existing executable\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\") {\n\t\t\tif (process.platform === \"win32\")\n\t\t\t\tawait install(\n\t\t\t\t\t\"powershell\",\n\t\t\t\t\t[\"-NoProfile\", \"-Command\", \"irm https://claude.ai/install.ps1 | iex\"],\n\t\t\t\t\tinteraction,\n\t\t\t\t);\n\t\t\telse await install(\"sh\", [\"-c\", \"curl -fsSL https://claude.ai/install.sh | bash\"], interaction);\n\t\t\tcommand = await executable(\"claude\");\n\t\t} else if (choice === \"existing\") {\n\t\t\tconst path = await interaction.prompt({ type: \"text\", message: \"Absolute path to Claude Code executable:\" });\n\t\t\tif (!isAbsolute(path)) throw new Error(\"Claude Code path must be absolute\");\n\t\t\tcommand = await executable(path);\n\t\t} else throw new Error(\"Anthropic subscription setup cancelled\");\n\t}\n\tif (!command) throw new Error(\"Claude Code executable not found. Restart lunR after installation and retry.\");\n\tconst version = (await setupProbe(python, command, \"version\")) as string;\n\tif (!isQualifiedClaudeCodeVersion(version))\n\t\tthrow new Error(\n\t\t\t`Claude Code ${VERSION} is the only qualified version. Found ${version.slice(0, 40)}. Subscription requests are disabled until this version is qualified.`,\n\t\t);\n\tlet status = (await setupProbe(python, command, \"status\")) as {\n\t\tlogged_in?: boolean;\n\t\tplan?: string;\n\t\taccountFingerprint?: string;\n\t};\n\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\")) {\n\t\tif (!interaction.handoff)\n\t\t\tthrow new Error(\n\t\t\t\t`Run \"${command}\" auth login in a terminal, select a Claude subscription, then retry /login anthropic`,\n\t\t\t);\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code needs a subscription login. Hand the terminal to Claude Code now?\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"login\", label: \"Run Claude Code login\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice !== \"login\") throw new Error(\"Anthropic subscription setup cancelled\");\n\t\tawait interaction.handoff(\n\t\t\tpython,\n\t\t\t[\"-s\", \"-B\", \"-u\", SETUP_WORKER, \"auth-login\", command],\n\t\t\tclaudeCodeEnvironment(undefined, false),\n\t\t);\n\t\tstatus = (await setupProbe(python, command, \"status\")) as typeof status;\n\t\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\"))\n\t\t\tthrow new Error(\"Claude Code is not signed into a Claude subscription\");\n\t}\n\tconst discovered = await setupProbe(python, command, \"discover\");\n\tif (\n\t\t!Array.isArray(discovered) ||\n\t\t!discovered.length ||\n\t\tdiscovered.some((row) => !row || typeof row.id !== \"string\" || row.upstream_requests !== 0)\n\t) {\n\t\tthrow new Error(\"Claude Code model discovery did not verify zero Messages requests. Setup not saved.\");\n\t}\n\treturn {\n\t\ttype: \"external_claude_code\",\n\t\tversion: 1,\n\t\tmanager: \"claude-code\",\n\t\tcommand,\n\t\tpython,\n\t\taccountFingerprint: status.accountFingerprint ?? randomUUID(),\n\t\troutes: discovered.map((row) => row.id),\n\t};\n}\n\nexport const anthropicOAuth: OAuthAuth = {\n\tname: \"Anthropic subscription through Claude Code\",\n\tloginLabel: \"Connect Claude Pro/Max through Claude Code\",\n\tlogin,\n\trefresh: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n\ttoAuth: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/anthropic.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAiD,SAAS,EAAE,MAAM,aAAa,CAAC;AAI5F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnE;AA2OD,eAAO,MAAM,cAAc,EAAE,SAU5B,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { access, constants } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { delimiter, isAbsolute, join } from \"node:path\";\nimport { claudeCodeEnvironment, stopNative } from \"../../api/anthropic-claude-code-bridge.ts\";\nimport { getClaudeCodeWorkerPath } from \"../../utils/claude-code-assets.ts\";\nimport type { AuthInteraction, ExternalClaudeCodeCredential, OAuthAuth } from \"../types.ts\";\n\nconst VERSION = \"2.1.263\";\n\nexport function isQualifiedClaudeCodeVersion(value: string): boolean {\n\treturn new RegExp(`^${VERSION.replaceAll(\".\", \"\\\\.\")}(?:\\\\s|$)`).test(value);\n}\n\nasync function run(command: string, args: string[], input?: string, timeout = 25_000): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(command, args, {\n\t\t\tstdio: [\"pipe\", \"pipe\", \"ignore\"],\n\t\t\twindowsHide: true,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tenv: claudeCodeEnvironment(undefined, false),\n\t\t});\n\t\tlet output = \"\";\n\t\tlet timedOut = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tvoid stopNative(child.pid ?? 0).finally(() => {\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout.destroy();\n\t\t\t\tchild.stdin.destroy();\n\t\t\t\treject(new Error(\"Dependency check timed out\"));\n\t\t\t});\n\t\t}, timeout);\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\t\toutput += chunk.toString(\"utf8\");\n\t\t\tif (output.length > 64 * 1024) child.kill();\n\t\t});\n\t\tchild.stdin.on(\"error\", () => {});\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code) => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (timedOut) return;\n\t\t\tif (code !== 0) reject(new Error(\"Dependency check failed\"));\n\t\t\telse resolve(output.trim());\n\t\t});\n\t\tchild.stdin.end(input);\n\t});\n}\n\nasync function executable(name: string): Promise<string | undefined> {\n\tconst suffixes = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tconst directories = isAbsolute(name)\n\t\t? [\"\"]\n\t\t: [...(process.env.PATH ?? \"\").split(delimiter), join(homedir(), \".local\", \"bin\")];\n\tfor (const directory of directories) {\n\t\tfor (const suffix of suffixes) {\n\t\t\tconst candidate = directory ? join(directory, `${name}${suffix}`) : `${name}${suffix}`;\n\t\t\ttry {\n\t\t\t\tawait access(candidate, constants.X_OK);\n\t\t\t\treturn candidate;\n\t\t\t} catch {\n\t\t\t\t/* Next location. */\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function pythonInterpreter(): Promise<string | undefined> {\n\tfor (const name of [\"python3\", \"python\"]) {\n\t\tconst path = await executable(name);\n\t\tif (!path) continue;\n\t\ttry {\n\t\t\tconst version = await run(path, [\"--version\"]);\n\t\t\tconst match = /^Python (\\d+)\\.(\\d+)/.exec(version);\n\t\t\tif (match && (Number(match[1]) > 3 || (Number(match[1]) === 3 && Number(match[2]) >= 10))) return path;\n\t\t} catch {\n\t\t\t/* Try another interpreter. */\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function install(command: string, args: string[], interaction: AuthInteraction): Promise<void> {\n\tconst confirm = await interaction.prompt({\n\t\ttype: \"select\",\n\t\tmessage: `Run ${command} ${args.join(\" \")}? This downloads software and changes your user-level system installation.`,\n\t\toptions: [\n\t\t\t{ id: \"yes\", label: \"Install\" },\n\t\t\t{ id: \"no\", label: \"Cancel\" },\n\t\t],\n\t});\n\tif (confirm !== \"yes\") throw new Error(\"Anthropic subscription setup cancelled\");\n\tinteraction.notify({ type: \"progress\", message: \"Running the confirmed installer...\" });\n\tawait run(command, args, undefined, 300_000);\n}\n\nasync function setupProbe(python: string, command: string, type: \"status\" | \"discover\" | \"version\"): Promise<unknown> {\n\tconst requestId = randomUUID();\n\tconst line = await run(\n\t\tpython,\n\t\t[\"-s\", \"-B\", \"-u\", getClaudeCodeWorkerPath(\"lunr_setup_bridge.py\")],\n\t\t`${JSON.stringify({ v: 1, requestId, type, command, env: claudeCodeEnvironment(undefined, false) })}\\n`,\n\t\t55_000,\n\t);\n\tconst record: unknown = JSON.parse(line);\n\tif (\n\t\t!record ||\n\t\ttypeof record !== \"object\" ||\n\t\t!(\"v\" in record) ||\n\t\trecord.v !== 1 ||\n\t\t!(\"requestId\" in record) ||\n\t\trecord.requestId !== requestId ||\n\t\t!(\"type\" in record) ||\n\t\trecord.type !== \"result\" ||\n\t\t!(\"result\" in record)\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code setup response\");\n\t}\n\treturn record.result;\n}\n\nasync function login(interaction: AuthInteraction): Promise<ExternalClaudeCodeCredential> {\n\tinteraction.notify({\n\t\ttype: \"info\",\n\t\tmessage:\n\t\t\t\"Claude Code handles subscription authentication and one generation per lunR request. lunR still owns tools, permissions, history, compaction, and subagents. Python 3.10+ and Claude Code are required. No credentials are copied into lunR.\",\n\t});\n\tlet python = await pythonInterpreter();\n\tif (!python) {\n\t\tinteraction.notify({\n\t\t\ttype: \"info\",\n\t\t\tmessage:\n\t\t\t\t\"Install Python 3.10+ from https://www.python.org/downloads/ . This is a separate operating-system installation, not part of lunR.\",\n\t\t});\n\t\tconst packageManager =\n\t\t\tprocess.platform === \"darwin\"\n\t\t\t\t? await executable(\"brew\")\n\t\t\t\t: process.platform === \"linux\"\n\t\t\t\t\t? ((await executable(\"apt-get\")) ?? (await executable(\"dnf\")))\n\t\t\t\t\t: undefined;\n\t\tconst installer =\n\t\t\tprocess.platform === \"win32\"\n\t\t\t\t? { command: \"winget\", args: [\"install\", \"--id\", \"Python.Python.3.13\", \"-e\"] }\n\t\t\t\t: packageManager?.endsWith(\"apt-get\")\n\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t: packageManager?.endsWith(\"dnf\")\n\t\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t\t: packageManager\n\t\t\t\t\t\t\t? { command: packageManager, args: [\"install\", \"python@3.13\"] }\n\t\t\t\t\t\t\t: undefined;\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage:\n\t\t\t\t\"Python 3.10+ is missing. A system installer may request administrator access and change your machine.\",\n\t\t\toptions: [\n\t\t\t\t...(installer\n\t\t\t\t\t? [{ id: \"install\", label: `Install through ${installer.command} ${installer.args.join(\" \")}` }]\n\t\t\t\t\t: []),\n\t\t\t\t{ id: \"cancel\", label: \"Cancel and install Python yourself\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\" && installer) await install(installer.command, installer.args, interaction);\n\t\telse throw new Error(\"Install Python 3.10+ and retry /login anthropic\");\n\t\tpython = await pythonInterpreter();\n\t\tif (!python)\n\t\t\tthrow new Error(\"Python installation finished but the interpreter is not on PATH. Restart lunR and retry.\");\n\t}\n\tlet command = await executable(\"claude\");\n\tif (!command) {\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code is missing. Installation changes your user-level system and may require a new PATH.\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"install\", label: \"Install Claude Code\" },\n\t\t\t\t{ id: \"existing\", label: \"Use existing executable\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\") {\n\t\t\tif (process.platform === \"win32\")\n\t\t\t\tawait install(\n\t\t\t\t\t\"powershell\",\n\t\t\t\t\t[\"-NoProfile\", \"-Command\", \"irm https://claude.ai/install.ps1 | iex\"],\n\t\t\t\t\tinteraction,\n\t\t\t\t);\n\t\t\telse await install(\"sh\", [\"-c\", \"curl -fsSL https://claude.ai/install.sh | bash\"], interaction);\n\t\t\tcommand = await executable(\"claude\");\n\t\t} else if (choice === \"existing\") {\n\t\t\tconst path = await interaction.prompt({ type: \"text\", message: \"Absolute path to Claude Code executable:\" });\n\t\t\tif (!isAbsolute(path)) throw new Error(\"Claude Code path must be absolute\");\n\t\t\tcommand = await executable(path);\n\t\t} else throw new Error(\"Anthropic subscription setup cancelled\");\n\t}\n\tif (!command) throw new Error(\"Claude Code executable not found. Restart lunR after installation and retry.\");\n\tconst version = (await setupProbe(python, command, \"version\")) as string;\n\tif (!isQualifiedClaudeCodeVersion(version))\n\t\tthrow new Error(\n\t\t\t`Claude Code ${VERSION} is the only qualified version. Found ${version.slice(0, 40)}. Subscription requests are disabled until this version is qualified.`,\n\t\t);\n\tlet status = (await setupProbe(python, command, \"status\")) as {\n\t\tlogged_in?: boolean;\n\t\tplan?: string;\n\t\taccountFingerprint?: string;\n\t};\n\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\")) {\n\t\tif (!interaction.handoff)\n\t\t\tthrow new Error(\n\t\t\t\t`Run \"${command}\" auth login in a terminal, select a Claude subscription, then retry /login anthropic`,\n\t\t\t);\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code needs a subscription login. Hand the terminal to Claude Code now?\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"login\", label: \"Run Claude Code login\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice !== \"login\") throw new Error(\"Anthropic subscription setup cancelled\");\n\t\tawait interaction.handoff(\n\t\t\tpython,\n\t\t\t[\"-s\", \"-B\", \"-u\", getClaudeCodeWorkerPath(\"lunr_setup_bridge.py\"), \"auth-login\", command],\n\t\t\tclaudeCodeEnvironment(undefined, false),\n\t\t);\n\t\tstatus = (await setupProbe(python, command, \"status\")) as typeof status;\n\t\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\"))\n\t\t\tthrow new Error(\"Claude Code is not signed into a Claude subscription\");\n\t}\n\tconst discovered = await setupProbe(python, command, \"discover\");\n\tif (\n\t\t!Array.isArray(discovered) ||\n\t\t!discovered.length ||\n\t\tdiscovered.some((row) => !row || typeof row.id !== \"string\" || row.upstream_requests !== 0)\n\t) {\n\t\tthrow new Error(\"Claude Code model discovery did not verify zero Messages requests. Setup not saved.\");\n\t}\n\treturn {\n\t\ttype: \"external_claude_code\",\n\t\tversion: 1,\n\t\tmanager: \"claude-code\",\n\t\tcommand,\n\t\tpython,\n\t\taccountFingerprint: status.accountFingerprint ?? randomUUID(),\n\t\troutes: discovered.map((row) => row.id),\n\t};\n}\n\nexport const anthropicOAuth: OAuthAuth = {\n\tname: \"Anthropic subscription through Claude Code\",\n\tloginLabel: \"Connect Claude Pro/Max through Claude Code\",\n\tlogin,\n\trefresh: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n\ttoAuth: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n};\n"]}
|
|
@@ -3,9 +3,8 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { access, constants } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { delimiter, isAbsolute, join } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
6
|
import { claudeCodeEnvironment, stopNative } from "../../api/anthropic-claude-code-bridge.js";
|
|
8
|
-
|
|
7
|
+
import { getClaudeCodeWorkerPath } from "../../utils/claude-code-assets.js";
|
|
9
8
|
const VERSION = "2.1.263";
|
|
10
9
|
export function isQualifiedClaudeCodeVersion(value) {
|
|
11
10
|
return new RegExp(`^${VERSION.replaceAll(".", "\\.")}(?:\\s|$)`).test(value);
|
|
@@ -100,7 +99,7 @@ async function install(command, args, interaction) {
|
|
|
100
99
|
}
|
|
101
100
|
async function setupProbe(python, command, type) {
|
|
102
101
|
const requestId = randomUUID();
|
|
103
|
-
const line = await run(python, ["-s", "-B", "-u",
|
|
102
|
+
const line = await run(python, ["-s", "-B", "-u", getClaudeCodeWorkerPath("lunr_setup_bridge.py")], `${JSON.stringify({ v: 1, requestId, type, command, env: claudeCodeEnvironment(undefined, false) })}\n`, 55_000);
|
|
104
103
|
const record = JSON.parse(line);
|
|
105
104
|
if (!record ||
|
|
106
105
|
typeof record !== "object" ||
|
|
@@ -204,7 +203,7 @@ async function login(interaction) {
|
|
|
204
203
|
});
|
|
205
204
|
if (choice !== "login")
|
|
206
205
|
throw new Error("Anthropic subscription setup cancelled");
|
|
207
|
-
await interaction.handoff(python, ["-s", "-B", "-u",
|
|
206
|
+
await interaction.handoff(python, ["-s", "-B", "-u", getClaudeCodeWorkerPath("lunr_setup_bridge.py"), "auth-login", command], claudeCodeEnvironment(undefined, false));
|
|
208
207
|
status = (await setupProbe(python, command, "status"));
|
|
209
208
|
if (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? ""))
|
|
210
209
|
throw new Error("Claude Code is not signed into a Claude subscription");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/auth/oauth/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,E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E,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAAA,CACxF;IACD,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAAA,CACxF;CACD,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { access, constants } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { delimiter, isAbsolute, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { claudeCodeEnvironment, stopNative } from \"../../api/anthropic-claude-code-bridge.ts\";\nimport type { AuthInteraction, ExternalClaudeCodeCredential, OAuthAuth } from \"../types.ts\";\n\nconst SETUP_WORKER = fileURLToPath(\n\tnew URL(\"../../../vendor/hermes-claude-subscription-directsdk/lunr_setup_bridge.py\", import.meta.url),\n);\nconst VERSION = \"2.1.263\";\n\nexport function isQualifiedClaudeCodeVersion(value: string): boolean {\n\treturn new RegExp(`^${VERSION.replaceAll(\".\", \"\\\\.\")}(?:\\\\s|$)`).test(value);\n}\n\nasync function run(command: string, args: string[], input?: string, timeout = 25_000): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(command, args, {\n\t\t\tstdio: [\"pipe\", \"pipe\", \"ignore\"],\n\t\t\twindowsHide: true,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tenv: claudeCodeEnvironment(undefined, false),\n\t\t});\n\t\tlet output = \"\";\n\t\tlet timedOut = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tvoid stopNative(child.pid ?? 0).finally(() => {\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout.destroy();\n\t\t\t\tchild.stdin.destroy();\n\t\t\t\treject(new Error(\"Dependency check timed out\"));\n\t\t\t});\n\t\t}, timeout);\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\t\toutput += chunk.toString(\"utf8\");\n\t\t\tif (output.length > 64 * 1024) child.kill();\n\t\t});\n\t\tchild.stdin.on(\"error\", () => {});\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code) => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (timedOut) return;\n\t\t\tif (code !== 0) reject(new Error(\"Dependency check failed\"));\n\t\t\telse resolve(output.trim());\n\t\t});\n\t\tchild.stdin.end(input);\n\t});\n}\n\nasync function executable(name: string): Promise<string | undefined> {\n\tconst suffixes = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tconst directories = isAbsolute(name)\n\t\t? [\"\"]\n\t\t: [...(process.env.PATH ?? \"\").split(delimiter), join(homedir(), \".local\", \"bin\")];\n\tfor (const directory of directories) {\n\t\tfor (const suffix of suffixes) {\n\t\t\tconst candidate = directory ? join(directory, `${name}${suffix}`) : `${name}${suffix}`;\n\t\t\ttry {\n\t\t\t\tawait access(candidate, constants.X_OK);\n\t\t\t\treturn candidate;\n\t\t\t} catch {\n\t\t\t\t/* Next location. */\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function pythonInterpreter(): Promise<string | undefined> {\n\tfor (const name of [\"python3\", \"python\"]) {\n\t\tconst path = await executable(name);\n\t\tif (!path) continue;\n\t\ttry {\n\t\t\tconst version = await run(path, [\"--version\"]);\n\t\t\tconst match = /^Python (\\d+)\\.(\\d+)/.exec(version);\n\t\t\tif (match && (Number(match[1]) > 3 || (Number(match[1]) === 3 && Number(match[2]) >= 10))) return path;\n\t\t} catch {\n\t\t\t/* Try another interpreter. */\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function install(command: string, args: string[], interaction: AuthInteraction): Promise<void> {\n\tconst confirm = await interaction.prompt({\n\t\ttype: \"select\",\n\t\tmessage: `Run ${command} ${args.join(\" \")}? This downloads software and changes your user-level system installation.`,\n\t\toptions: [\n\t\t\t{ id: \"yes\", label: \"Install\" },\n\t\t\t{ id: \"no\", label: \"Cancel\" },\n\t\t],\n\t});\n\tif (confirm !== \"yes\") throw new Error(\"Anthropic subscription setup cancelled\");\n\tinteraction.notify({ type: \"progress\", message: \"Running the confirmed installer...\" });\n\tawait run(command, args, undefined, 300_000);\n}\n\nasync function setupProbe(python: string, command: string, type: \"status\" | \"discover\" | \"version\"): Promise<unknown> {\n\tconst requestId = randomUUID();\n\tconst line = await run(\n\t\tpython,\n\t\t[\"-s\", \"-B\", \"-u\", SETUP_WORKER],\n\t\t`${JSON.stringify({ v: 1, requestId, type, command, env: claudeCodeEnvironment(undefined, false) })}\\n`,\n\t\t55_000,\n\t);\n\tconst record: unknown = JSON.parse(line);\n\tif (\n\t\t!record ||\n\t\ttypeof record !== \"object\" ||\n\t\t!(\"v\" in record) ||\n\t\trecord.v !== 1 ||\n\t\t!(\"requestId\" in record) ||\n\t\trecord.requestId !== requestId ||\n\t\t!(\"type\" in record) ||\n\t\trecord.type !== \"result\" ||\n\t\t!(\"result\" in record)\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code setup response\");\n\t}\n\treturn record.result;\n}\n\nasync function login(interaction: AuthInteraction): Promise<ExternalClaudeCodeCredential> {\n\tinteraction.notify({\n\t\ttype: \"info\",\n\t\tmessage:\n\t\t\t\"Claude Code handles subscription authentication and one generation per lunR request. lunR still owns tools, permissions, history, compaction, and subagents. Python 3.10+ and Claude Code are required. No credentials are copied into lunR.\",\n\t});\n\tlet python = await pythonInterpreter();\n\tif (!python) {\n\t\tinteraction.notify({\n\t\t\ttype: \"info\",\n\t\t\tmessage:\n\t\t\t\t\"Install Python 3.10+ from https://www.python.org/downloads/ . This is a separate operating-system installation, not part of lunR.\",\n\t\t});\n\t\tconst packageManager =\n\t\t\tprocess.platform === \"darwin\"\n\t\t\t\t? await executable(\"brew\")\n\t\t\t\t: process.platform === \"linux\"\n\t\t\t\t\t? ((await executable(\"apt-get\")) ?? (await executable(\"dnf\")))\n\t\t\t\t\t: undefined;\n\t\tconst installer =\n\t\t\tprocess.platform === \"win32\"\n\t\t\t\t? { command: \"winget\", args: [\"install\", \"--id\", \"Python.Python.3.13\", \"-e\"] }\n\t\t\t\t: packageManager?.endsWith(\"apt-get\")\n\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t: packageManager?.endsWith(\"dnf\")\n\t\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t\t: packageManager\n\t\t\t\t\t\t\t? { command: packageManager, args: [\"install\", \"python@3.13\"] }\n\t\t\t\t\t\t\t: undefined;\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage:\n\t\t\t\t\"Python 3.10+ is missing. A system installer may request administrator access and change your machine.\",\n\t\t\toptions: [\n\t\t\t\t...(installer\n\t\t\t\t\t? [{ id: \"install\", label: `Install through ${installer.command} ${installer.args.join(\" \")}` }]\n\t\t\t\t\t: []),\n\t\t\t\t{ id: \"cancel\", label: \"Cancel and install Python yourself\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\" && installer) await install(installer.command, installer.args, interaction);\n\t\telse throw new Error(\"Install Python 3.10+ and retry /login anthropic\");\n\t\tpython = await pythonInterpreter();\n\t\tif (!python)\n\t\t\tthrow new Error(\"Python installation finished but the interpreter is not on PATH. Restart lunR and retry.\");\n\t}\n\tlet command = await executable(\"claude\");\n\tif (!command) {\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code is missing. Installation changes your user-level system and may require a new PATH.\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"install\", label: \"Install Claude Code\" },\n\t\t\t\t{ id: \"existing\", label: \"Use existing executable\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\") {\n\t\t\tif (process.platform === \"win32\")\n\t\t\t\tawait install(\n\t\t\t\t\t\"powershell\",\n\t\t\t\t\t[\"-NoProfile\", \"-Command\", \"irm https://claude.ai/install.ps1 | iex\"],\n\t\t\t\t\tinteraction,\n\t\t\t\t);\n\t\t\telse await install(\"sh\", [\"-c\", \"curl -fsSL https://claude.ai/install.sh | bash\"], interaction);\n\t\t\tcommand = await executable(\"claude\");\n\t\t} else if (choice === \"existing\") {\n\t\t\tconst path = await interaction.prompt({ type: \"text\", message: \"Absolute path to Claude Code executable:\" });\n\t\t\tif (!isAbsolute(path)) throw new Error(\"Claude Code path must be absolute\");\n\t\t\tcommand = await executable(path);\n\t\t} else throw new Error(\"Anthropic subscription setup cancelled\");\n\t}\n\tif (!command) throw new Error(\"Claude Code executable not found. Restart lunR after installation and retry.\");\n\tconst version = (await setupProbe(python, command, \"version\")) as string;\n\tif (!isQualifiedClaudeCodeVersion(version))\n\t\tthrow new Error(\n\t\t\t`Claude Code ${VERSION} is the only qualified version. Found ${version.slice(0, 40)}. Subscription requests are disabled until this version is qualified.`,\n\t\t);\n\tlet status = (await setupProbe(python, command, \"status\")) as {\n\t\tlogged_in?: boolean;\n\t\tplan?: string;\n\t\taccountFingerprint?: string;\n\t};\n\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\")) {\n\t\tif (!interaction.handoff)\n\t\t\tthrow new Error(\n\t\t\t\t`Run \"${command}\" auth login in a terminal, select a Claude subscription, then retry /login anthropic`,\n\t\t\t);\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code needs a subscription login. Hand the terminal to Claude Code now?\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"login\", label: \"Run Claude Code login\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice !== \"login\") throw new Error(\"Anthropic subscription setup cancelled\");\n\t\tawait interaction.handoff(\n\t\t\tpython,\n\t\t\t[\"-s\", \"-B\", \"-u\", SETUP_WORKER, \"auth-login\", command],\n\t\t\tclaudeCodeEnvironment(undefined, false),\n\t\t);\n\t\tstatus = (await setupProbe(python, command, \"status\")) as typeof status;\n\t\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\"))\n\t\t\tthrow new Error(\"Claude Code is not signed into a Claude subscription\");\n\t}\n\tconst discovered = await setupProbe(python, command, \"discover\");\n\tif (\n\t\t!Array.isArray(discovered) ||\n\t\t!discovered.length ||\n\t\tdiscovered.some((row) => !row || typeof row.id !== \"string\" || row.upstream_requests !== 0)\n\t) {\n\t\tthrow new Error(\"Claude Code model discovery did not verify zero Messages requests. Setup not saved.\");\n\t}\n\treturn {\n\t\ttype: \"external_claude_code\",\n\t\tversion: 1,\n\t\tmanager: \"claude-code\",\n\t\tcommand,\n\t\tpython,\n\t\taccountFingerprint: status.accountFingerprint ?? randomUUID(),\n\t\troutes: discovered.map((row) => row.id),\n\t};\n}\n\nexport const anthropicOAuth: OAuthAuth = {\n\tname: \"Anthropic subscription through Claude Code\",\n\tloginLabel: \"Connect Claude Pro/Max through Claude Code\",\n\tlogin,\n\trefresh: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n\ttoAuth: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/auth/oauth/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM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AA,CACxF;CACD,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { access, constants } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { delimiter, isAbsolute, join } from \"node:path\";\nimport { claudeCodeEnvironment, stopNative } from \"../../api/anthropic-claude-code-bridge.ts\";\nimport { getClaudeCodeWorkerPath } from \"../../utils/claude-code-assets.ts\";\nimport type { AuthInteraction, ExternalClaudeCodeCredential, OAuthAuth } from \"../types.ts\";\n\nconst VERSION = \"2.1.263\";\n\nexport function isQualifiedClaudeCodeVersion(value: string): boolean {\n\treturn new RegExp(`^${VERSION.replaceAll(\".\", \"\\\\.\")}(?:\\\\s|$)`).test(value);\n}\n\nasync function run(command: string, args: string[], input?: string, timeout = 25_000): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(command, args, {\n\t\t\tstdio: [\"pipe\", \"pipe\", \"ignore\"],\n\t\t\twindowsHide: true,\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tenv: claudeCodeEnvironment(undefined, false),\n\t\t});\n\t\tlet output = \"\";\n\t\tlet timedOut = false;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tvoid stopNative(child.pid ?? 0).finally(() => {\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout.destroy();\n\t\t\t\tchild.stdin.destroy();\n\t\t\t\treject(new Error(\"Dependency check timed out\"));\n\t\t\t});\n\t\t}, timeout);\n\t\tchild.stdout.on(\"data\", (chunk: Buffer) => {\n\t\t\toutput += chunk.toString(\"utf8\");\n\t\t\tif (output.length > 64 * 1024) child.kill();\n\t\t});\n\t\tchild.stdin.on(\"error\", () => {});\n\t\tchild.on(\"error\", reject);\n\t\tchild.on(\"close\", (code) => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (timedOut) return;\n\t\t\tif (code !== 0) reject(new Error(\"Dependency check failed\"));\n\t\t\telse resolve(output.trim());\n\t\t});\n\t\tchild.stdin.end(input);\n\t});\n}\n\nasync function executable(name: string): Promise<string | undefined> {\n\tconst suffixes = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tconst directories = isAbsolute(name)\n\t\t? [\"\"]\n\t\t: [...(process.env.PATH ?? \"\").split(delimiter), join(homedir(), \".local\", \"bin\")];\n\tfor (const directory of directories) {\n\t\tfor (const suffix of suffixes) {\n\t\t\tconst candidate = directory ? join(directory, `${name}${suffix}`) : `${name}${suffix}`;\n\t\t\ttry {\n\t\t\t\tawait access(candidate, constants.X_OK);\n\t\t\t\treturn candidate;\n\t\t\t} catch {\n\t\t\t\t/* Next location. */\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function pythonInterpreter(): Promise<string | undefined> {\n\tfor (const name of [\"python3\", \"python\"]) {\n\t\tconst path = await executable(name);\n\t\tif (!path) continue;\n\t\ttry {\n\t\t\tconst version = await run(path, [\"--version\"]);\n\t\t\tconst match = /^Python (\\d+)\\.(\\d+)/.exec(version);\n\t\t\tif (match && (Number(match[1]) > 3 || (Number(match[1]) === 3 && Number(match[2]) >= 10))) return path;\n\t\t} catch {\n\t\t\t/* Try another interpreter. */\n\t\t}\n\t}\n\treturn undefined;\n}\n\nasync function install(command: string, args: string[], interaction: AuthInteraction): Promise<void> {\n\tconst confirm = await interaction.prompt({\n\t\ttype: \"select\",\n\t\tmessage: `Run ${command} ${args.join(\" \")}? This downloads software and changes your user-level system installation.`,\n\t\toptions: [\n\t\t\t{ id: \"yes\", label: \"Install\" },\n\t\t\t{ id: \"no\", label: \"Cancel\" },\n\t\t],\n\t});\n\tif (confirm !== \"yes\") throw new Error(\"Anthropic subscription setup cancelled\");\n\tinteraction.notify({ type: \"progress\", message: \"Running the confirmed installer...\" });\n\tawait run(command, args, undefined, 300_000);\n}\n\nasync function setupProbe(python: string, command: string, type: \"status\" | \"discover\" | \"version\"): Promise<unknown> {\n\tconst requestId = randomUUID();\n\tconst line = await run(\n\t\tpython,\n\t\t[\"-s\", \"-B\", \"-u\", getClaudeCodeWorkerPath(\"lunr_setup_bridge.py\")],\n\t\t`${JSON.stringify({ v: 1, requestId, type, command, env: claudeCodeEnvironment(undefined, false) })}\\n`,\n\t\t55_000,\n\t);\n\tconst record: unknown = JSON.parse(line);\n\tif (\n\t\t!record ||\n\t\ttypeof record !== \"object\" ||\n\t\t!(\"v\" in record) ||\n\t\trecord.v !== 1 ||\n\t\t!(\"requestId\" in record) ||\n\t\trecord.requestId !== requestId ||\n\t\t!(\"type\" in record) ||\n\t\trecord.type !== \"result\" ||\n\t\t!(\"result\" in record)\n\t) {\n\t\tthrow new Error(\"Invalid Claude Code setup response\");\n\t}\n\treturn record.result;\n}\n\nasync function login(interaction: AuthInteraction): Promise<ExternalClaudeCodeCredential> {\n\tinteraction.notify({\n\t\ttype: \"info\",\n\t\tmessage:\n\t\t\t\"Claude Code handles subscription authentication and one generation per lunR request. lunR still owns tools, permissions, history, compaction, and subagents. Python 3.10+ and Claude Code are required. No credentials are copied into lunR.\",\n\t});\n\tlet python = await pythonInterpreter();\n\tif (!python) {\n\t\tinteraction.notify({\n\t\t\ttype: \"info\",\n\t\t\tmessage:\n\t\t\t\t\"Install Python 3.10+ from https://www.python.org/downloads/ . This is a separate operating-system installation, not part of lunR.\",\n\t\t});\n\t\tconst packageManager =\n\t\t\tprocess.platform === \"darwin\"\n\t\t\t\t? await executable(\"brew\")\n\t\t\t\t: process.platform === \"linux\"\n\t\t\t\t\t? ((await executable(\"apt-get\")) ?? (await executable(\"dnf\")))\n\t\t\t\t\t: undefined;\n\t\tconst installer =\n\t\t\tprocess.platform === \"win32\"\n\t\t\t\t? { command: \"winget\", args: [\"install\", \"--id\", \"Python.Python.3.13\", \"-e\"] }\n\t\t\t\t: packageManager?.endsWith(\"apt-get\")\n\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t: packageManager?.endsWith(\"dnf\")\n\t\t\t\t\t\t? { command: \"sudo\", args: [packageManager, \"install\", \"-y\", \"python3\"] }\n\t\t\t\t\t\t: packageManager\n\t\t\t\t\t\t\t? { command: packageManager, args: [\"install\", \"python@3.13\"] }\n\t\t\t\t\t\t\t: undefined;\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage:\n\t\t\t\t\"Python 3.10+ is missing. A system installer may request administrator access and change your machine.\",\n\t\t\toptions: [\n\t\t\t\t...(installer\n\t\t\t\t\t? [{ id: \"install\", label: `Install through ${installer.command} ${installer.args.join(\" \")}` }]\n\t\t\t\t\t: []),\n\t\t\t\t{ id: \"cancel\", label: \"Cancel and install Python yourself\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\" && installer) await install(installer.command, installer.args, interaction);\n\t\telse throw new Error(\"Install Python 3.10+ and retry /login anthropic\");\n\t\tpython = await pythonInterpreter();\n\t\tif (!python)\n\t\t\tthrow new Error(\"Python installation finished but the interpreter is not on PATH. Restart lunR and retry.\");\n\t}\n\tlet command = await executable(\"claude\");\n\tif (!command) {\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code is missing. Installation changes your user-level system and may require a new PATH.\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"install\", label: \"Install Claude Code\" },\n\t\t\t\t{ id: \"existing\", label: \"Use existing executable\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice === \"install\") {\n\t\t\tif (process.platform === \"win32\")\n\t\t\t\tawait install(\n\t\t\t\t\t\"powershell\",\n\t\t\t\t\t[\"-NoProfile\", \"-Command\", \"irm https://claude.ai/install.ps1 | iex\"],\n\t\t\t\t\tinteraction,\n\t\t\t\t);\n\t\t\telse await install(\"sh\", [\"-c\", \"curl -fsSL https://claude.ai/install.sh | bash\"], interaction);\n\t\t\tcommand = await executable(\"claude\");\n\t\t} else if (choice === \"existing\") {\n\t\t\tconst path = await interaction.prompt({ type: \"text\", message: \"Absolute path to Claude Code executable:\" });\n\t\t\tif (!isAbsolute(path)) throw new Error(\"Claude Code path must be absolute\");\n\t\t\tcommand = await executable(path);\n\t\t} else throw new Error(\"Anthropic subscription setup cancelled\");\n\t}\n\tif (!command) throw new Error(\"Claude Code executable not found. Restart lunR after installation and retry.\");\n\tconst version = (await setupProbe(python, command, \"version\")) as string;\n\tif (!isQualifiedClaudeCodeVersion(version))\n\t\tthrow new Error(\n\t\t\t`Claude Code ${VERSION} is the only qualified version. Found ${version.slice(0, 40)}. Subscription requests are disabled until this version is qualified.`,\n\t\t);\n\tlet status = (await setupProbe(python, command, \"status\")) as {\n\t\tlogged_in?: boolean;\n\t\tplan?: string;\n\t\taccountFingerprint?: string;\n\t};\n\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\")) {\n\t\tif (!interaction.handoff)\n\t\t\tthrow new Error(\n\t\t\t\t`Run \"${command}\" auth login in a terminal, select a Claude subscription, then retry /login anthropic`,\n\t\t\t);\n\t\tconst choice = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Claude Code needs a subscription login. Hand the terminal to Claude Code now?\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"login\", label: \"Run Claude Code login\" },\n\t\t\t\t{ id: \"cancel\", label: \"Cancel\" },\n\t\t\t],\n\t\t});\n\t\tif (choice !== \"login\") throw new Error(\"Anthropic subscription setup cancelled\");\n\t\tawait interaction.handoff(\n\t\t\tpython,\n\t\t\t[\"-s\", \"-B\", \"-u\", getClaudeCodeWorkerPath(\"lunr_setup_bridge.py\"), \"auth-login\", command],\n\t\t\tclaudeCodeEnvironment(undefined, false),\n\t\t);\n\t\tstatus = (await setupProbe(python, command, \"status\")) as typeof status;\n\t\tif (!status.logged_in || !/Claude (Pro|Max|Team|Enterprise)/i.test(status.plan ?? \"\"))\n\t\t\tthrow new Error(\"Claude Code is not signed into a Claude subscription\");\n\t}\n\tconst discovered = await setupProbe(python, command, \"discover\");\n\tif (\n\t\t!Array.isArray(discovered) ||\n\t\t!discovered.length ||\n\t\tdiscovered.some((row) => !row || typeof row.id !== \"string\" || row.upstream_requests !== 0)\n\t) {\n\t\tthrow new Error(\"Claude Code model discovery did not verify zero Messages requests. Setup not saved.\");\n\t}\n\treturn {\n\t\ttype: \"external_claude_code\",\n\t\tversion: 1,\n\t\tmanager: \"claude-code\",\n\t\tcommand,\n\t\tpython,\n\t\taccountFingerprint: status.accountFingerprint ?? randomUUID(),\n\t\troutes: discovered.map((row) => row.id),\n\t};\n}\n\nexport const anthropicOAuth: OAuthAuth = {\n\tname: \"Anthropic subscription through Claude Code\",\n\tloginLabel: \"Connect Claude Pro/Max through Claude Code\",\n\tlogin,\n\trefresh: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n\ttoAuth: async () => {\n\t\tthrow new Error(\"Legacy Anthropic OAuth tokens are unsupported. Run /login anthropic.\");\n\t},\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ClaudeCodeWorker = "lunr_bridge.py" | "lunr_setup_bridge.py";
|
|
2
|
+
/** External Python needs physical files, including when JavaScript lives in Bun's virtual filesystem. */
|
|
3
|
+
export declare function getClaudeCodeWorkerPath(worker: ClaudeCodeWorker, runtime?: {
|
|
4
|
+
moduleUrl: string;
|
|
5
|
+
execPath: string;
|
|
6
|
+
}): string;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=claude-code-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code-assets.d.ts","sourceRoot":"","sources":["../../src/utils/claude-code-assets.ts"],"names":[],"mappings":"AAIA,KAAK,gBAAgB,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;AAElE,yGAAyG;AACzG,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,gBAAgB,EACxB,OAAO;;;CAA6D,GAClE,MAAM,CAYR","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\ntype ClaudeCodeWorker = \"lunr_bridge.py\" | \"lunr_setup_bridge.py\";\n\n/** External Python needs physical files, including when JavaScript lives in Bun's virtual filesystem. */\nexport function getClaudeCodeWorkerPath(\n\tworker: ClaudeCodeWorker,\n\truntime = { moduleUrl: import.meta.url, execPath: process.execPath },\n): string {\n\tconst compiled = /\\$bunfs|~BUN|%7EBUN/i.test(runtime.moduleUrl);\n\tconst directory = compiled\n\t\t? join(dirname(runtime.execPath), \"vendor\", \"hermes-claude-subscription-directsdk\")\n\t\t: fileURLToPath(new URL(\"../../vendor/hermes-claude-subscription-directsdk/\", runtime.moduleUrl));\n\tconst path = join(directory, worker);\n\tif (!existsSync(path)) {\n\t\tthrow new Error(\n\t\t\t\"Claude Code subscription worker is missing. Reinstall the complete lunR package or extract the complete standalone archive.\",\n\t\t);\n\t}\n\treturn path;\n}\n"]}
|