claudish 7.17.1 → 7.18.1
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/dist/index.js +363 -652
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -460,6 +460,69 @@ var require_main = __commonJS((exports, module) => {
|
|
|
460
460
|
module.exports = DotenvModule;
|
|
461
461
|
});
|
|
462
462
|
|
|
463
|
+
// src/config-override.ts
|
|
464
|
+
var exports_config_override = {};
|
|
465
|
+
__export(exports_config_override, {
|
|
466
|
+
setConfigFileOverride: () => setConfigFileOverride,
|
|
467
|
+
planConfigOverride: () => planConfigOverride,
|
|
468
|
+
getConfigFileOverride: () => getConfigFileOverride,
|
|
469
|
+
activeOpConfigPaths: () => activeOpConfigPaths,
|
|
470
|
+
activeGlobalConfigFile: () => activeGlobalConfigFile
|
|
471
|
+
});
|
|
472
|
+
function setConfigFileOverride(path) {
|
|
473
|
+
overridePath = path;
|
|
474
|
+
}
|
|
475
|
+
function getConfigFileOverride() {
|
|
476
|
+
return overridePath;
|
|
477
|
+
}
|
|
478
|
+
function activeGlobalConfigFile(realGlobal) {
|
|
479
|
+
return overridePath ?? realGlobal;
|
|
480
|
+
}
|
|
481
|
+
function activeOpConfigPaths(defaults) {
|
|
482
|
+
if (overridePath === null)
|
|
483
|
+
return defaults;
|
|
484
|
+
const file = overridePath;
|
|
485
|
+
return {
|
|
486
|
+
global: () => file,
|
|
487
|
+
project: () => SUPPRESSED_PROJECT_CONFIG
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function planConfigOverride(argv, env, deps) {
|
|
491
|
+
const flag = scanConfigFlag(argv);
|
|
492
|
+
let path;
|
|
493
|
+
if (flag) {
|
|
494
|
+
if (!flag.value || flag.value.startsWith("-")) {
|
|
495
|
+
return { kind: "error", message: "[claudish] --config requires a file path" };
|
|
496
|
+
}
|
|
497
|
+
path = flag.value;
|
|
498
|
+
} else {
|
|
499
|
+
path = env.CLAUDISH_CONFIG || undefined;
|
|
500
|
+
}
|
|
501
|
+
if (!path)
|
|
502
|
+
return { kind: "none" };
|
|
503
|
+
const resolved = deps.resolve(path);
|
|
504
|
+
if (!deps.exists(resolved)) {
|
|
505
|
+
return { kind: "error", message: `[claudish] --config file not found: ${resolved}` };
|
|
506
|
+
}
|
|
507
|
+
const rest = argv.slice();
|
|
508
|
+
if (flag)
|
|
509
|
+
rest.splice(flag.dropAt, flag.dropCount);
|
|
510
|
+
return { kind: "apply", path: resolved, argv: rest, fromFlag: flag !== null };
|
|
511
|
+
}
|
|
512
|
+
function scanConfigFlag(argv) {
|
|
513
|
+
for (let i = 0;i < argv.length; i++) {
|
|
514
|
+
const a = argv[i];
|
|
515
|
+
if (a === "--config") {
|
|
516
|
+
return { value: argv[i + 1], dropAt: i, dropCount: argv[i + 1] === undefined ? 1 : 2 };
|
|
517
|
+
}
|
|
518
|
+
if (a.startsWith("--config=")) {
|
|
519
|
+
return { value: a.slice("--config=".length), dropAt: i, dropCount: 1 };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
var SUPPRESSED_PROJECT_CONFIG = "", overridePath = null;
|
|
525
|
+
|
|
463
526
|
// src/providers/onepassword-config.ts
|
|
464
527
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
465
528
|
import { homedir } from "os";
|
|
@@ -482,6 +545,9 @@ function readRawConfig(path) {
|
|
|
482
545
|
}
|
|
483
546
|
function mutateConfig(scope, paths, mutate) {
|
|
484
547
|
const path = pathFor(scope, paths);
|
|
548
|
+
if (path === "") {
|
|
549
|
+
throw new Error("Cannot save to project scope while --config/CLAUDISH_CONFIG is active \u2014 " + "the override file is the only config for this run. Save to global scope " + "(which writes to the override file), or re-run without --config.");
|
|
550
|
+
}
|
|
485
551
|
const cfg = readRawConfig(path);
|
|
486
552
|
mutate(cfg);
|
|
487
553
|
writeFileSync(path, `${JSON.stringify(cfg, null, 2)}
|
|
@@ -572,16 +638,20 @@ function addOnepasswordEnvironment(id, scope, paths = defaultOpConfigPaths) {
|
|
|
572
638
|
function removeOnepasswordEnvironment(id, scope, paths = defaultOpConfigPaths) {
|
|
573
639
|
removeFromStringList(scope, "onepasswordEnvironments", id, paths);
|
|
574
640
|
}
|
|
575
|
-
var defaultOpConfigPaths;
|
|
641
|
+
var realOpConfigPaths, defaultOpConfigPaths;
|
|
576
642
|
var init_onepassword_config = __esm(() => {
|
|
577
|
-
|
|
643
|
+
realOpConfigPaths = {
|
|
578
644
|
global: () => join(homedir(), ".claudish", "config.json"),
|
|
579
645
|
project: () => join(process.cwd(), ".claudish.json")
|
|
580
646
|
};
|
|
647
|
+
defaultOpConfigPaths = {
|
|
648
|
+
global: () => activeOpConfigPaths(realOpConfigPaths).global(),
|
|
649
|
+
project: () => activeOpConfigPaths(realOpConfigPaths).project()
|
|
650
|
+
};
|
|
581
651
|
});
|
|
582
652
|
|
|
583
653
|
// src/version.ts
|
|
584
|
-
var VERSION = "7.
|
|
654
|
+
var VERSION = "7.18.1";
|
|
585
655
|
|
|
586
656
|
// src/logger.ts
|
|
587
657
|
var exports_logger = {};
|
|
@@ -685,7 +755,7 @@ function redactDeep(val, key) {
|
|
|
685
755
|
return val;
|
|
686
756
|
}
|
|
687
757
|
function isStructuralLogWorthy(msg) {
|
|
688
|
-
return msg.startsWith("[SSE:") || msg.startsWith("[Proxy]") || msg.startsWith("[Fallback]") || msg.startsWith("[Streaming] ===") || msg.startsWith("[Streaming] Chunk:") || msg.startsWith("[Streaming] Received") || msg.startsWith("[Streaming] Text-based tool calls") || msg.startsWith("[Streaming] Final usage") || msg.startsWith("[Streaming] Sending") || msg.startsWith("[AnthropicSSE] Stream complete") || msg.startsWith("[AnthropicSSE] Tool use:") || msg.includes("Response status:") || msg.includes("Error") || msg.includes("error") || msg.includes("[Auto-route]");
|
|
758
|
+
return msg.startsWith("[SSE:") || msg.startsWith("[Suppressed]") || msg.startsWith("[Proxy]") || msg.startsWith("[Fallback]") || msg.startsWith("[Streaming] ===") || msg.startsWith("[Streaming] Chunk:") || msg.startsWith("[Streaming] Received") || msg.startsWith("[Streaming] Text-based tool calls") || msg.startsWith("[Streaming] Final usage") || msg.startsWith("[Streaming] Sending") || msg.startsWith("[AnthropicSSE] Stream complete") || msg.startsWith("[AnthropicSSE] Tool use:") || msg.includes("Response status:") || msg.includes("Error") || msg.includes("error") || msg.includes("[Auto-route]");
|
|
689
759
|
}
|
|
690
760
|
function redactLogLine(message, timestamp) {
|
|
691
761
|
if (message.startsWith("[SSE:")) {
|
|
@@ -3942,6 +4012,8 @@ function resetSdkClientCache() {
|
|
|
3942
4012
|
}
|
|
3943
4013
|
function isTransientSdkError(err) {
|
|
3944
4014
|
const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
|
|
4015
|
+
if (msg.includes("denied authorization"))
|
|
4016
|
+
return false;
|
|
3945
4017
|
return msg.includes("ipc operation failed") || msg.includes("ipc operation") || msg.includes("-4") || msg.includes("denied") || msg.includes("broken pipe") || msg.includes("connection") || msg.includes("invalid client id") || msg.includes("invalid client") || msg.includes("invalid session") || msg.includes("session expired") || msg.includes("session not found") || msg.includes("unauthorized") || msg.includes("token expired") || msg.includes("not authenticated");
|
|
3946
4018
|
}
|
|
3947
4019
|
function runSdkExclusive(op, label = "op:sdk-op", meta) {
|
|
@@ -4285,7 +4357,7 @@ function readConfigRaw() {
|
|
|
4285
4357
|
if (testSeams?.config)
|
|
4286
4358
|
return testSeams.config;
|
|
4287
4359
|
try {
|
|
4288
|
-
const configPath = join5(homedir5(), ".claudish", "config.json");
|
|
4360
|
+
const configPath = activeGlobalConfigFile(join5(homedir5(), ".claudish", "config.json"));
|
|
4289
4361
|
if (!existsSync4(configPath))
|
|
4290
4362
|
return {};
|
|
4291
4363
|
return JSON.parse(readFileSync3(configPath, "utf-8"));
|
|
@@ -27498,6 +27570,7 @@ __export(exports_profile_config, {
|
|
|
27498
27570
|
setProfile: () => setProfile,
|
|
27499
27571
|
setEndpoint: () => setEndpoint,
|
|
27500
27572
|
setDefaultProfile: () => setDefaultProfile,
|
|
27573
|
+
setConfigFileOverride: () => setConfigFileOverride,
|
|
27501
27574
|
setApiKey: () => setApiKey,
|
|
27502
27575
|
saveLocalConfig: () => saveLocalConfig,
|
|
27503
27576
|
saveConfig: () => saveConfig,
|
|
@@ -27524,23 +27597,29 @@ __export(exports_profile_config, {
|
|
|
27524
27597
|
deleteProfile: () => deleteProfile,
|
|
27525
27598
|
createProfile: () => createProfile,
|
|
27526
27599
|
configExistsForScope: () => configExistsForScope,
|
|
27527
|
-
configExists: () => configExists
|
|
27600
|
+
configExists: () => configExists,
|
|
27601
|
+
activeConfigFile: () => activeConfigFile
|
|
27528
27602
|
});
|
|
27529
27603
|
import { existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync7 } from "fs";
|
|
27530
27604
|
import { homedir as homedir8 } from "os";
|
|
27531
27605
|
import { dirname as dirname3, join as join8, parse as parse6 } from "path";
|
|
27606
|
+
function activeConfigFile() {
|
|
27607
|
+
return activeGlobalConfigFile(CONFIG_FILE);
|
|
27608
|
+
}
|
|
27532
27609
|
function ensureConfigDir() {
|
|
27533
27610
|
if (!existsSync6(CONFIG_DIR)) {
|
|
27534
27611
|
mkdirSync6(CONFIG_DIR, { recursive: true });
|
|
27535
27612
|
}
|
|
27536
27613
|
}
|
|
27537
27614
|
function loadConfig() {
|
|
27538
|
-
|
|
27539
|
-
if (!
|
|
27615
|
+
const activeFile = activeConfigFile();
|
|
27616
|
+
if (!getConfigFileOverride())
|
|
27617
|
+
ensureConfigDir();
|
|
27618
|
+
if (!existsSync6(activeFile)) {
|
|
27540
27619
|
return { ...DEFAULT_CONFIG };
|
|
27541
27620
|
}
|
|
27542
27621
|
try {
|
|
27543
|
-
const content = readFileSync5(
|
|
27622
|
+
const content = readFileSync5(activeFile, "utf-8");
|
|
27544
27623
|
const config2 = JSON.parse(content);
|
|
27545
27624
|
const merged = {
|
|
27546
27625
|
version: config2.version || DEFAULT_CONFIG.version,
|
|
@@ -27593,8 +27672,9 @@ function loadConfig() {
|
|
|
27593
27672
|
}
|
|
27594
27673
|
}
|
|
27595
27674
|
function saveConfig(config2) {
|
|
27596
|
-
|
|
27597
|
-
|
|
27675
|
+
if (!getConfigFileOverride())
|
|
27676
|
+
ensureConfigDir();
|
|
27677
|
+
writeFileSync7(activeConfigFile(), JSON.stringify(config2, null, 2), "utf-8");
|
|
27598
27678
|
}
|
|
27599
27679
|
function configExists() {
|
|
27600
27680
|
return existsSync6(CONFIG_FILE);
|
|
@@ -27625,6 +27705,8 @@ function isProjectDirectory() {
|
|
|
27625
27705
|
return [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".claudish.json"].some((f) => existsSync6(join8(cwd, f)));
|
|
27626
27706
|
}
|
|
27627
27707
|
function loadLocalConfig() {
|
|
27708
|
+
if (getConfigFileOverride())
|
|
27709
|
+
return null;
|
|
27628
27710
|
const localPath = getLocalConfigPath();
|
|
27629
27711
|
if (!existsSync6(localPath)) {
|
|
27630
27712
|
return null;
|
|
@@ -28615,535 +28697,6 @@ var init_provider_definitions = __esm(() => {
|
|
|
28615
28697
|
];
|
|
28616
28698
|
});
|
|
28617
28699
|
|
|
28618
|
-
// ../../node_modules/.bun/@hono+node-server@1.19.6+86bafc9754e56507/node_modules/@hono/node-server/dist/index.mjs
|
|
28619
|
-
import { createServer as createServerHTTP } from "http";
|
|
28620
|
-
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
|
|
28621
|
-
import { Http2ServerRequest } from "http2";
|
|
28622
|
-
import { Readable } from "stream";
|
|
28623
|
-
import crypto from "crypto";
|
|
28624
|
-
async function readWithoutBlocking(readPromise) {
|
|
28625
|
-
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(undefined))]);
|
|
28626
|
-
}
|
|
28627
|
-
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
28628
|
-
const cancel = (error46) => {
|
|
28629
|
-
reader.cancel(error46).catch(() => {});
|
|
28630
|
-
};
|
|
28631
|
-
writable.on("close", cancel);
|
|
28632
|
-
writable.on("error", cancel);
|
|
28633
|
-
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
28634
|
-
return reader.closed.finally(() => {
|
|
28635
|
-
writable.off("close", cancel);
|
|
28636
|
-
writable.off("error", cancel);
|
|
28637
|
-
});
|
|
28638
|
-
function handleStreamError(error46) {
|
|
28639
|
-
if (error46) {
|
|
28640
|
-
writable.destroy(error46);
|
|
28641
|
-
}
|
|
28642
|
-
}
|
|
28643
|
-
function onDrain() {
|
|
28644
|
-
reader.read().then(flow, handleStreamError);
|
|
28645
|
-
}
|
|
28646
|
-
function flow({ done, value }) {
|
|
28647
|
-
try {
|
|
28648
|
-
if (done) {
|
|
28649
|
-
writable.end();
|
|
28650
|
-
} else if (!writable.write(value)) {
|
|
28651
|
-
writable.once("drain", onDrain);
|
|
28652
|
-
} else {
|
|
28653
|
-
return reader.read().then(flow, handleStreamError);
|
|
28654
|
-
}
|
|
28655
|
-
} catch (e) {
|
|
28656
|
-
handleStreamError(e);
|
|
28657
|
-
}
|
|
28658
|
-
}
|
|
28659
|
-
}
|
|
28660
|
-
function writeFromReadableStream(stream, writable) {
|
|
28661
|
-
if (stream.locked) {
|
|
28662
|
-
throw new TypeError("ReadableStream is locked.");
|
|
28663
|
-
} else if (writable.destroyed) {
|
|
28664
|
-
return;
|
|
28665
|
-
}
|
|
28666
|
-
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
28667
|
-
}
|
|
28668
|
-
var RequestError, toRequestError = (e) => {
|
|
28669
|
-
if (e instanceof RequestError) {
|
|
28670
|
-
return e;
|
|
28671
|
-
}
|
|
28672
|
-
return new RequestError(e.message, { cause: e });
|
|
28673
|
-
}, GlobalRequest, Request2, newHeadersFromIncoming = (incoming) => {
|
|
28674
|
-
const headerRecord = [];
|
|
28675
|
-
const rawHeaders = incoming.rawHeaders;
|
|
28676
|
-
for (let i = 0;i < rawHeaders.length; i += 2) {
|
|
28677
|
-
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
28678
|
-
if (key.charCodeAt(0) !== 58) {
|
|
28679
|
-
headerRecord.push([key, value]);
|
|
28680
|
-
}
|
|
28681
|
-
}
|
|
28682
|
-
return new Headers(headerRecord);
|
|
28683
|
-
}, wrapBodyStream, newRequestFromIncoming = (method, url2, headers, incoming, abortController) => {
|
|
28684
|
-
const init = {
|
|
28685
|
-
method,
|
|
28686
|
-
headers,
|
|
28687
|
-
signal: abortController.signal
|
|
28688
|
-
};
|
|
28689
|
-
if (method === "TRACE") {
|
|
28690
|
-
init.method = "GET";
|
|
28691
|
-
const req = new Request2(url2, init);
|
|
28692
|
-
Object.defineProperty(req, "method", {
|
|
28693
|
-
get() {
|
|
28694
|
-
return "TRACE";
|
|
28695
|
-
}
|
|
28696
|
-
});
|
|
28697
|
-
return req;
|
|
28698
|
-
}
|
|
28699
|
-
if (!(method === "GET" || method === "HEAD")) {
|
|
28700
|
-
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
28701
|
-
init.body = new ReadableStream({
|
|
28702
|
-
start(controller) {
|
|
28703
|
-
controller.enqueue(incoming.rawBody);
|
|
28704
|
-
controller.close();
|
|
28705
|
-
}
|
|
28706
|
-
});
|
|
28707
|
-
} else if (incoming[wrapBodyStream]) {
|
|
28708
|
-
let reader;
|
|
28709
|
-
init.body = new ReadableStream({
|
|
28710
|
-
async pull(controller) {
|
|
28711
|
-
try {
|
|
28712
|
-
reader ||= Readable.toWeb(incoming).getReader();
|
|
28713
|
-
const { done, value } = await reader.read();
|
|
28714
|
-
if (done) {
|
|
28715
|
-
controller.close();
|
|
28716
|
-
} else {
|
|
28717
|
-
controller.enqueue(value);
|
|
28718
|
-
}
|
|
28719
|
-
} catch (error46) {
|
|
28720
|
-
controller.error(error46);
|
|
28721
|
-
}
|
|
28722
|
-
}
|
|
28723
|
-
});
|
|
28724
|
-
} else {
|
|
28725
|
-
init.body = Readable.toWeb(incoming);
|
|
28726
|
-
}
|
|
28727
|
-
}
|
|
28728
|
-
return new Request2(url2, init);
|
|
28729
|
-
}, getRequestCache, requestCache, incomingKey, urlKey, headersKey, abortControllerKey, getAbortController, requestPrototype, newRequest = (incoming, defaultHostname) => {
|
|
28730
|
-
const req = Object.create(requestPrototype);
|
|
28731
|
-
req[incomingKey] = incoming;
|
|
28732
|
-
const incomingUrl = incoming.url || "";
|
|
28733
|
-
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
28734
|
-
if (incoming instanceof Http2ServerRequest) {
|
|
28735
|
-
throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
28736
|
-
}
|
|
28737
|
-
try {
|
|
28738
|
-
const url22 = new URL(incomingUrl);
|
|
28739
|
-
req[urlKey] = url22.href;
|
|
28740
|
-
} catch (e) {
|
|
28741
|
-
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
28742
|
-
}
|
|
28743
|
-
return req;
|
|
28744
|
-
}
|
|
28745
|
-
const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
28746
|
-
if (!host) {
|
|
28747
|
-
throw new RequestError("Missing host header");
|
|
28748
|
-
}
|
|
28749
|
-
let scheme;
|
|
28750
|
-
if (incoming instanceof Http2ServerRequest) {
|
|
28751
|
-
scheme = incoming.scheme;
|
|
28752
|
-
if (!(scheme === "http" || scheme === "https")) {
|
|
28753
|
-
throw new RequestError("Unsupported scheme");
|
|
28754
|
-
}
|
|
28755
|
-
} else {
|
|
28756
|
-
scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
28757
|
-
}
|
|
28758
|
-
const url2 = new URL(`${scheme}://${host}${incomingUrl}`);
|
|
28759
|
-
if (url2.hostname.length !== host.length && url2.hostname !== host.replace(/:\d+$/, "")) {
|
|
28760
|
-
throw new RequestError("Invalid host header");
|
|
28761
|
-
}
|
|
28762
|
-
req[urlKey] = url2.href;
|
|
28763
|
-
return req;
|
|
28764
|
-
}, responseCache, getResponseCache, cacheKey, GlobalResponse, Response2, buildOutgoingHttpHeaders = (headers) => {
|
|
28765
|
-
const res = {};
|
|
28766
|
-
if (!(headers instanceof Headers)) {
|
|
28767
|
-
headers = new Headers(headers ?? undefined);
|
|
28768
|
-
}
|
|
28769
|
-
const cookies = [];
|
|
28770
|
-
for (const [k, v] of headers) {
|
|
28771
|
-
if (k === "set-cookie") {
|
|
28772
|
-
cookies.push(v);
|
|
28773
|
-
} else {
|
|
28774
|
-
res[k] = v;
|
|
28775
|
-
}
|
|
28776
|
-
}
|
|
28777
|
-
if (cookies.length > 0) {
|
|
28778
|
-
res["set-cookie"] = cookies;
|
|
28779
|
-
}
|
|
28780
|
-
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
28781
|
-
return res;
|
|
28782
|
-
}, X_ALREADY_SENT = "x-hono-already-sent", webFetch, outgoingEnded, handleRequestError = () => new Response(null, {
|
|
28783
|
-
status: 400
|
|
28784
|
-
}), handleFetchError = (e) => new Response(null, {
|
|
28785
|
-
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
28786
|
-
}), handleResponseError = (e, outgoing) => {
|
|
28787
|
-
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
28788
|
-
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
28789
|
-
console.info("The user aborted a request.");
|
|
28790
|
-
} else {
|
|
28791
|
-
console.error(e);
|
|
28792
|
-
if (!outgoing.headersSent) {
|
|
28793
|
-
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
28794
|
-
}
|
|
28795
|
-
outgoing.end(`Error: ${err.message}`);
|
|
28796
|
-
outgoing.destroy(err);
|
|
28797
|
-
}
|
|
28798
|
-
}, flushHeaders = (outgoing) => {
|
|
28799
|
-
if ("flushHeaders" in outgoing && outgoing.writable) {
|
|
28800
|
-
outgoing.flushHeaders();
|
|
28801
|
-
}
|
|
28802
|
-
}, responseViaCache = async (res, outgoing) => {
|
|
28803
|
-
let [status, body, header] = res[cacheKey];
|
|
28804
|
-
if (header instanceof Headers) {
|
|
28805
|
-
header = buildOutgoingHttpHeaders(header);
|
|
28806
|
-
}
|
|
28807
|
-
if (typeof body === "string") {
|
|
28808
|
-
header["Content-Length"] = Buffer.byteLength(body);
|
|
28809
|
-
} else if (body instanceof Uint8Array) {
|
|
28810
|
-
header["Content-Length"] = body.byteLength;
|
|
28811
|
-
} else if (body instanceof Blob) {
|
|
28812
|
-
header["Content-Length"] = body.size;
|
|
28813
|
-
}
|
|
28814
|
-
outgoing.writeHead(status, header);
|
|
28815
|
-
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
28816
|
-
outgoing.end(body);
|
|
28817
|
-
} else if (body instanceof Blob) {
|
|
28818
|
-
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
28819
|
-
} else {
|
|
28820
|
-
flushHeaders(outgoing);
|
|
28821
|
-
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
28822
|
-
}
|
|
28823
|
-
outgoing[outgoingEnded]?.();
|
|
28824
|
-
}, isPromise = (res) => typeof res.then === "function", responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
28825
|
-
if (isPromise(res)) {
|
|
28826
|
-
if (options.errorHandler) {
|
|
28827
|
-
try {
|
|
28828
|
-
res = await res;
|
|
28829
|
-
} catch (err) {
|
|
28830
|
-
const errRes = await options.errorHandler(err);
|
|
28831
|
-
if (!errRes) {
|
|
28832
|
-
return;
|
|
28833
|
-
}
|
|
28834
|
-
res = errRes;
|
|
28835
|
-
}
|
|
28836
|
-
} else {
|
|
28837
|
-
res = await res.catch(handleFetchError);
|
|
28838
|
-
}
|
|
28839
|
-
}
|
|
28840
|
-
if (cacheKey in res) {
|
|
28841
|
-
return responseViaCache(res, outgoing);
|
|
28842
|
-
}
|
|
28843
|
-
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
28844
|
-
if (res.body) {
|
|
28845
|
-
const reader = res.body.getReader();
|
|
28846
|
-
const values = [];
|
|
28847
|
-
let done = false;
|
|
28848
|
-
let currentReadPromise = undefined;
|
|
28849
|
-
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
28850
|
-
let maxReadCount = 2;
|
|
28851
|
-
for (let i = 0;i < maxReadCount; i++) {
|
|
28852
|
-
currentReadPromise ||= reader.read();
|
|
28853
|
-
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
28854
|
-
console.error(e);
|
|
28855
|
-
done = true;
|
|
28856
|
-
});
|
|
28857
|
-
if (!chunk) {
|
|
28858
|
-
if (i === 1) {
|
|
28859
|
-
await new Promise((resolve) => setTimeout(resolve));
|
|
28860
|
-
maxReadCount = 3;
|
|
28861
|
-
continue;
|
|
28862
|
-
}
|
|
28863
|
-
break;
|
|
28864
|
-
}
|
|
28865
|
-
currentReadPromise = undefined;
|
|
28866
|
-
if (chunk.value) {
|
|
28867
|
-
values.push(chunk.value);
|
|
28868
|
-
}
|
|
28869
|
-
if (chunk.done) {
|
|
28870
|
-
done = true;
|
|
28871
|
-
break;
|
|
28872
|
-
}
|
|
28873
|
-
}
|
|
28874
|
-
if (done && !("content-length" in resHeaderRecord)) {
|
|
28875
|
-
resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
28876
|
-
}
|
|
28877
|
-
}
|
|
28878
|
-
outgoing.writeHead(res.status, resHeaderRecord);
|
|
28879
|
-
values.forEach((value) => {
|
|
28880
|
-
outgoing.write(value);
|
|
28881
|
-
});
|
|
28882
|
-
if (done) {
|
|
28883
|
-
outgoing.end();
|
|
28884
|
-
} else {
|
|
28885
|
-
if (values.length === 0) {
|
|
28886
|
-
flushHeaders(outgoing);
|
|
28887
|
-
}
|
|
28888
|
-
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
28889
|
-
}
|
|
28890
|
-
} else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
|
|
28891
|
-
outgoing.writeHead(res.status, resHeaderRecord);
|
|
28892
|
-
outgoing.end();
|
|
28893
|
-
}
|
|
28894
|
-
outgoing[outgoingEnded]?.();
|
|
28895
|
-
}, getRequestListener = (fetchCallback, options = {}) => {
|
|
28896
|
-
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
28897
|
-
if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
|
|
28898
|
-
Object.defineProperty(global, "Request", {
|
|
28899
|
-
value: Request2
|
|
28900
|
-
});
|
|
28901
|
-
Object.defineProperty(global, "Response", {
|
|
28902
|
-
value: Response2
|
|
28903
|
-
});
|
|
28904
|
-
}
|
|
28905
|
-
return async (incoming, outgoing) => {
|
|
28906
|
-
let res, req;
|
|
28907
|
-
try {
|
|
28908
|
-
req = newRequest(incoming, options.hostname);
|
|
28909
|
-
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
28910
|
-
if (!incomingEnded) {
|
|
28911
|
-
incoming[wrapBodyStream] = true;
|
|
28912
|
-
incoming.on("end", () => {
|
|
28913
|
-
incomingEnded = true;
|
|
28914
|
-
});
|
|
28915
|
-
if (incoming instanceof Http2ServerRequest2) {
|
|
28916
|
-
outgoing[outgoingEnded] = () => {
|
|
28917
|
-
if (!incomingEnded) {
|
|
28918
|
-
setTimeout(() => {
|
|
28919
|
-
if (!incomingEnded) {
|
|
28920
|
-
setTimeout(() => {
|
|
28921
|
-
incoming.destroy();
|
|
28922
|
-
outgoing.destroy();
|
|
28923
|
-
});
|
|
28924
|
-
}
|
|
28925
|
-
});
|
|
28926
|
-
}
|
|
28927
|
-
};
|
|
28928
|
-
}
|
|
28929
|
-
}
|
|
28930
|
-
outgoing.on("close", () => {
|
|
28931
|
-
const abortController = req[abortControllerKey];
|
|
28932
|
-
if (abortController) {
|
|
28933
|
-
if (incoming.errored) {
|
|
28934
|
-
req[abortControllerKey].abort(incoming.errored.toString());
|
|
28935
|
-
} else if (!outgoing.writableFinished) {
|
|
28936
|
-
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
28937
|
-
}
|
|
28938
|
-
}
|
|
28939
|
-
if (!incomingEnded) {
|
|
28940
|
-
setTimeout(() => {
|
|
28941
|
-
if (!incomingEnded) {
|
|
28942
|
-
setTimeout(() => {
|
|
28943
|
-
incoming.destroy();
|
|
28944
|
-
});
|
|
28945
|
-
}
|
|
28946
|
-
});
|
|
28947
|
-
}
|
|
28948
|
-
});
|
|
28949
|
-
res = fetchCallback(req, { incoming, outgoing });
|
|
28950
|
-
if (cacheKey in res) {
|
|
28951
|
-
return responseViaCache(res, outgoing);
|
|
28952
|
-
}
|
|
28953
|
-
} catch (e) {
|
|
28954
|
-
if (!res) {
|
|
28955
|
-
if (options.errorHandler) {
|
|
28956
|
-
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
28957
|
-
if (!res) {
|
|
28958
|
-
return;
|
|
28959
|
-
}
|
|
28960
|
-
} else if (!req) {
|
|
28961
|
-
res = handleRequestError();
|
|
28962
|
-
} else {
|
|
28963
|
-
res = handleFetchError(e);
|
|
28964
|
-
}
|
|
28965
|
-
} else {
|
|
28966
|
-
return handleResponseError(e, outgoing);
|
|
28967
|
-
}
|
|
28968
|
-
}
|
|
28969
|
-
try {
|
|
28970
|
-
return await responseViaResponseObject(res, outgoing, options);
|
|
28971
|
-
} catch (e) {
|
|
28972
|
-
return handleResponseError(e, outgoing);
|
|
28973
|
-
}
|
|
28974
|
-
};
|
|
28975
|
-
}, createAdaptorServer = (options) => {
|
|
28976
|
-
const fetchCallback = options.fetch;
|
|
28977
|
-
const requestListener = getRequestListener(fetchCallback, {
|
|
28978
|
-
hostname: options.hostname,
|
|
28979
|
-
overrideGlobalObjects: options.overrideGlobalObjects,
|
|
28980
|
-
autoCleanupIncoming: options.autoCleanupIncoming
|
|
28981
|
-
});
|
|
28982
|
-
const createServer2 = options.createServer || createServerHTTP;
|
|
28983
|
-
const server = createServer2(options.serverOptions || {}, requestListener);
|
|
28984
|
-
return server;
|
|
28985
|
-
}, serve = (options, listeningListener) => {
|
|
28986
|
-
const server = createAdaptorServer(options);
|
|
28987
|
-
server.listen(options?.port ?? 3000, options.hostname, () => {
|
|
28988
|
-
const serverInfo = server.address();
|
|
28989
|
-
listeningListener && listeningListener(serverInfo);
|
|
28990
|
-
});
|
|
28991
|
-
return server;
|
|
28992
|
-
};
|
|
28993
|
-
var init_dist = __esm(() => {
|
|
28994
|
-
RequestError = class extends Error {
|
|
28995
|
-
constructor(message, options) {
|
|
28996
|
-
super(message, options);
|
|
28997
|
-
this.name = "RequestError";
|
|
28998
|
-
}
|
|
28999
|
-
};
|
|
29000
|
-
GlobalRequest = global.Request;
|
|
29001
|
-
Request2 = class extends GlobalRequest {
|
|
29002
|
-
constructor(input, options) {
|
|
29003
|
-
if (typeof input === "object" && getRequestCache in input) {
|
|
29004
|
-
input = input[getRequestCache]();
|
|
29005
|
-
}
|
|
29006
|
-
if (typeof options?.body?.getReader !== "undefined") {
|
|
29007
|
-
options.duplex ??= "half";
|
|
29008
|
-
}
|
|
29009
|
-
super(input, options);
|
|
29010
|
-
}
|
|
29011
|
-
};
|
|
29012
|
-
wrapBodyStream = Symbol("wrapBodyStream");
|
|
29013
|
-
getRequestCache = Symbol("getRequestCache");
|
|
29014
|
-
requestCache = Symbol("requestCache");
|
|
29015
|
-
incomingKey = Symbol("incomingKey");
|
|
29016
|
-
urlKey = Symbol("urlKey");
|
|
29017
|
-
headersKey = Symbol("headersKey");
|
|
29018
|
-
abortControllerKey = Symbol("abortControllerKey");
|
|
29019
|
-
getAbortController = Symbol("getAbortController");
|
|
29020
|
-
requestPrototype = {
|
|
29021
|
-
get method() {
|
|
29022
|
-
return this[incomingKey].method || "GET";
|
|
29023
|
-
},
|
|
29024
|
-
get url() {
|
|
29025
|
-
return this[urlKey];
|
|
29026
|
-
},
|
|
29027
|
-
get headers() {
|
|
29028
|
-
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
29029
|
-
},
|
|
29030
|
-
[getAbortController]() {
|
|
29031
|
-
this[getRequestCache]();
|
|
29032
|
-
return this[abortControllerKey];
|
|
29033
|
-
},
|
|
29034
|
-
[getRequestCache]() {
|
|
29035
|
-
this[abortControllerKey] ||= new AbortController;
|
|
29036
|
-
return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
|
|
29037
|
-
}
|
|
29038
|
-
};
|
|
29039
|
-
[
|
|
29040
|
-
"body",
|
|
29041
|
-
"bodyUsed",
|
|
29042
|
-
"cache",
|
|
29043
|
-
"credentials",
|
|
29044
|
-
"destination",
|
|
29045
|
-
"integrity",
|
|
29046
|
-
"mode",
|
|
29047
|
-
"redirect",
|
|
29048
|
-
"referrer",
|
|
29049
|
-
"referrerPolicy",
|
|
29050
|
-
"signal",
|
|
29051
|
-
"keepalive"
|
|
29052
|
-
].forEach((k) => {
|
|
29053
|
-
Object.defineProperty(requestPrototype, k, {
|
|
29054
|
-
get() {
|
|
29055
|
-
return this[getRequestCache]()[k];
|
|
29056
|
-
}
|
|
29057
|
-
});
|
|
29058
|
-
});
|
|
29059
|
-
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
29060
|
-
Object.defineProperty(requestPrototype, k, {
|
|
29061
|
-
value: function() {
|
|
29062
|
-
return this[getRequestCache]()[k]();
|
|
29063
|
-
}
|
|
29064
|
-
});
|
|
29065
|
-
});
|
|
29066
|
-
Object.setPrototypeOf(requestPrototype, Request2.prototype);
|
|
29067
|
-
responseCache = Symbol("responseCache");
|
|
29068
|
-
getResponseCache = Symbol("getResponseCache");
|
|
29069
|
-
cacheKey = Symbol("cache");
|
|
29070
|
-
GlobalResponse = global.Response;
|
|
29071
|
-
Response2 = class _Response {
|
|
29072
|
-
#body;
|
|
29073
|
-
#init;
|
|
29074
|
-
[getResponseCache]() {
|
|
29075
|
-
delete this[cacheKey];
|
|
29076
|
-
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
29077
|
-
}
|
|
29078
|
-
constructor(body, init) {
|
|
29079
|
-
let headers;
|
|
29080
|
-
this.#body = body;
|
|
29081
|
-
if (init instanceof _Response) {
|
|
29082
|
-
const cachedGlobalResponse = init[responseCache];
|
|
29083
|
-
if (cachedGlobalResponse) {
|
|
29084
|
-
this.#init = cachedGlobalResponse;
|
|
29085
|
-
this[getResponseCache]();
|
|
29086
|
-
return;
|
|
29087
|
-
} else {
|
|
29088
|
-
this.#init = init.#init;
|
|
29089
|
-
headers = new Headers(init.#init.headers);
|
|
29090
|
-
}
|
|
29091
|
-
} else {
|
|
29092
|
-
this.#init = init;
|
|
29093
|
-
}
|
|
29094
|
-
if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
|
|
29095
|
-
headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
29096
|
-
this[cacheKey] = [init?.status || 200, body, headers];
|
|
29097
|
-
}
|
|
29098
|
-
}
|
|
29099
|
-
get headers() {
|
|
29100
|
-
const cache = this[cacheKey];
|
|
29101
|
-
if (cache) {
|
|
29102
|
-
if (!(cache[2] instanceof Headers)) {
|
|
29103
|
-
cache[2] = new Headers(cache[2]);
|
|
29104
|
-
}
|
|
29105
|
-
return cache[2];
|
|
29106
|
-
}
|
|
29107
|
-
return this[getResponseCache]().headers;
|
|
29108
|
-
}
|
|
29109
|
-
get status() {
|
|
29110
|
-
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
29111
|
-
}
|
|
29112
|
-
get ok() {
|
|
29113
|
-
const status = this.status;
|
|
29114
|
-
return status >= 200 && status < 300;
|
|
29115
|
-
}
|
|
29116
|
-
};
|
|
29117
|
-
["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
|
|
29118
|
-
Object.defineProperty(Response2.prototype, k, {
|
|
29119
|
-
get() {
|
|
29120
|
-
return this[getResponseCache]()[k];
|
|
29121
|
-
}
|
|
29122
|
-
});
|
|
29123
|
-
});
|
|
29124
|
-
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
29125
|
-
Object.defineProperty(Response2.prototype, k, {
|
|
29126
|
-
value: function() {
|
|
29127
|
-
return this[getResponseCache]()[k]();
|
|
29128
|
-
}
|
|
29129
|
-
});
|
|
29130
|
-
});
|
|
29131
|
-
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
29132
|
-
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
29133
|
-
webFetch = global.fetch;
|
|
29134
|
-
if (typeof global.crypto === "undefined") {
|
|
29135
|
-
global.crypto = crypto;
|
|
29136
|
-
}
|
|
29137
|
-
global.fetch = (info, init) => {
|
|
29138
|
-
init = {
|
|
29139
|
-
compress: false,
|
|
29140
|
-
...init
|
|
29141
|
-
};
|
|
29142
|
-
return webFetch(info, init);
|
|
29143
|
-
};
|
|
29144
|
-
outgoingEnded = Symbol("outgoingEnded");
|
|
29145
|
-
});
|
|
29146
|
-
|
|
29147
28700
|
// ../../node_modules/.bun/hono@4.10.6/node_modules/hono/dist/compose.js
|
|
29148
28701
|
var compose = (middleware, onError, onNotFound) => {
|
|
29149
28702
|
return (context, next) => {
|
|
@@ -29303,15 +28856,15 @@ var splitPath = (path) => {
|
|
|
29303
28856
|
}
|
|
29304
28857
|
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
29305
28858
|
if (match) {
|
|
29306
|
-
const
|
|
29307
|
-
if (!patternCache[
|
|
28859
|
+
const cacheKey = `${label}#${next}`;
|
|
28860
|
+
if (!patternCache[cacheKey]) {
|
|
29308
28861
|
if (match[2]) {
|
|
29309
|
-
patternCache[
|
|
28862
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
29310
28863
|
} else {
|
|
29311
|
-
patternCache[
|
|
28864
|
+
patternCache[cacheKey] = [label, match[1], true];
|
|
29312
28865
|
}
|
|
29313
28866
|
}
|
|
29314
|
-
return patternCache[
|
|
28867
|
+
return patternCache[cacheKey];
|
|
29315
28868
|
}
|
|
29316
28869
|
return null;
|
|
29317
28870
|
}, tryDecode = (str, decoder) => {
|
|
@@ -30726,7 +30279,7 @@ var init_hono = __esm(() => {
|
|
|
30726
30279
|
});
|
|
30727
30280
|
|
|
30728
30281
|
// ../../node_modules/.bun/hono@4.10.6/node_modules/hono/dist/index.js
|
|
30729
|
-
var
|
|
30282
|
+
var init_dist = __esm(() => {
|
|
30730
30283
|
init_hono();
|
|
30731
30284
|
});
|
|
30732
30285
|
|
|
@@ -33899,6 +33452,7 @@ class ApiKeyCredentialProvider {
|
|
|
33899
33452
|
staticHeaders;
|
|
33900
33453
|
publicKeyFallback;
|
|
33901
33454
|
oauthFallback;
|
|
33455
|
+
declaredKey;
|
|
33902
33456
|
cachedKey;
|
|
33903
33457
|
resolving;
|
|
33904
33458
|
constructor(descriptor) {
|
|
@@ -33909,9 +33463,17 @@ class ApiKeyCredentialProvider {
|
|
|
33909
33463
|
this.staticHeaders = descriptor.staticHeaders ?? {};
|
|
33910
33464
|
this.publicKeyFallback = descriptor.publicKeyFallback;
|
|
33911
33465
|
this.oauthFallback = descriptor.oauthFallback;
|
|
33466
|
+
this.declaredKey = descriptor.declaredKey;
|
|
33912
33467
|
}
|
|
33913
33468
|
resolveFromEnvConfig() {
|
|
33914
|
-
return process.env[this.envVar] || this.aliases.map((a) => process.env[a]).find((v) => !!v) || getApiKey(this.envVar);
|
|
33469
|
+
return process.env[this.envVar] || this.aliases.map((a) => process.env[a]).find((v) => !!v) || getApiKey(this.envVar) || this.resolveDeclared();
|
|
33470
|
+
}
|
|
33471
|
+
resolveDeclared() {
|
|
33472
|
+
try {
|
|
33473
|
+
return this.declaredKey?.() || undefined;
|
|
33474
|
+
} catch {
|
|
33475
|
+
return;
|
|
33476
|
+
}
|
|
33915
33477
|
}
|
|
33916
33478
|
hasOauthFallbackFile() {
|
|
33917
33479
|
if (!this.oauthFallback)
|
|
@@ -35780,7 +35342,8 @@ class CredentialAuthority {
|
|
|
35780
35342
|
catalogName: descriptor.name,
|
|
35781
35343
|
envVar: descriptor.envVar,
|
|
35782
35344
|
aliases: descriptor.aliases,
|
|
35783
|
-
authScheme: descriptor.authScheme === "x-api-key" ? "x-api-key" : "bearer"
|
|
35345
|
+
authScheme: descriptor.authScheme === "x-api-key" ? "x-api-key" : "bearer",
|
|
35346
|
+
declaredKey: descriptor.declaredKey
|
|
35784
35347
|
}), [descriptor.name]);
|
|
35785
35348
|
}
|
|
35786
35349
|
async isAvailable(name, opts) {
|
|
@@ -37549,9 +37112,15 @@ function statusToErrorType(status) {
|
|
|
37549
37112
|
return "api_error";
|
|
37550
37113
|
}
|
|
37551
37114
|
}
|
|
37115
|
+
function sanitizeErrorMessage(message, maxLength = MAX_ERROR_MESSAGE_LENGTH) {
|
|
37116
|
+
const flattened = String(message ?? "").replace(ANSI_ESCAPE, "").replace(CONTROL_CHARS, " ").replace(/\s+/g, " ").trim();
|
|
37117
|
+
if (flattened.length <= maxLength)
|
|
37118
|
+
return flattened;
|
|
37119
|
+
return `${flattened.slice(0, maxLength - 1).trimEnd()}\u2026`;
|
|
37120
|
+
}
|
|
37552
37121
|
function wrapAnthropicError(status, message, errorType, upstreamStatus) {
|
|
37553
37122
|
const type = errorType || statusToErrorType(status);
|
|
37554
|
-
const error46 = { type, message };
|
|
37123
|
+
const error46 = { type, message: sanitizeErrorMessage(message) };
|
|
37555
37124
|
if (upstreamStatus !== undefined)
|
|
37556
37125
|
error46.upstream_status = upstreamStatus;
|
|
37557
37126
|
return { type: "error", error: error46 };
|
|
@@ -37615,15 +37184,23 @@ function buildSurfacedErrorMessage(opts) {
|
|
|
37615
37184
|
}
|
|
37616
37185
|
function ensureAnthropicErrorFormat(status, body) {
|
|
37617
37186
|
if (body?.type === "error" && typeof body?.error?.type === "string" && typeof body?.error?.message === "string") {
|
|
37618
|
-
return body;
|
|
37187
|
+
return { ...body, error: { ...body.error, message: sanitizeErrorMessage(body.error.message) } };
|
|
37619
37188
|
}
|
|
37620
37189
|
if (typeof body?.error?.type === "string" && typeof body?.error?.message === "string") {
|
|
37621
|
-
return {
|
|
37190
|
+
return {
|
|
37191
|
+
type: "error",
|
|
37192
|
+
error: { ...body.error, message: sanitizeErrorMessage(body.error.message) }
|
|
37193
|
+
};
|
|
37622
37194
|
}
|
|
37623
37195
|
const message = body?.error?.message || body?.message || body?.error || (typeof body === "string" ? body : JSON.stringify(body));
|
|
37624
37196
|
const errorType = body?.error?.type || body?.type || body?.code;
|
|
37625
37197
|
return wrapAnthropicError(status, String(message), errorType);
|
|
37626
37198
|
}
|
|
37199
|
+
var MAX_ERROR_MESSAGE_LENGTH = 600, ANSI_ESCAPE, CONTROL_CHARS;
|
|
37200
|
+
var init_anthropic_error = __esm(() => {
|
|
37201
|
+
ANSI_ESCAPE = /\x1B\[[0-?]*[ -/]*[@-~]|\x1B[@-Z\\-_]/g;
|
|
37202
|
+
CONTROL_CHARS = /[\x00-\x1F\x7F]/g;
|
|
37203
|
+
});
|
|
37627
37204
|
|
|
37628
37205
|
// src/handlers/shared/connection-error.ts
|
|
37629
37206
|
function findConnectionCode(error46) {
|
|
@@ -37638,8 +37215,18 @@ function findConnectionCode(error46) {
|
|
|
37638
37215
|
const msg = String(error46?.message ?? error46 ?? "");
|
|
37639
37216
|
if (/getaddrinfo|ENOTFOUND|EAI_AGAIN|nodename nor servname/i.test(msg))
|
|
37640
37217
|
return "ENOTFOUND";
|
|
37218
|
+
if (BUN_CONNECT_MESSAGE.test(msg))
|
|
37219
|
+
return "ConnectionRefused";
|
|
37641
37220
|
return null;
|
|
37642
37221
|
}
|
|
37222
|
+
function isLoopback(endpoint) {
|
|
37223
|
+
try {
|
|
37224
|
+
const { hostname: hostname4 } = new URL(endpoint);
|
|
37225
|
+
return /^(localhost|127\.\d+\.\d+\.\d+|0\.0\.0\.0|\[?::1\]?)$/i.test(hostname4);
|
|
37226
|
+
} catch {
|
|
37227
|
+
return false;
|
|
37228
|
+
}
|
|
37229
|
+
}
|
|
37643
37230
|
function classifyConnectionError(error46) {
|
|
37644
37231
|
const code = findConnectionCode(error46);
|
|
37645
37232
|
if (!code)
|
|
@@ -37659,12 +37246,15 @@ function buildConnectionErrorMessage(kind, displayName, endpoint) {
|
|
|
37659
37246
|
case "dns":
|
|
37660
37247
|
return `Cannot resolve ${host} for ${displayName}. This is a DNS/network problem on your machine \u2014 check your internet connection, VPN, or DNS resolver (e.g. Tailscale MagicDNS) \u2014 not ${displayName}.`;
|
|
37661
37248
|
case "refused":
|
|
37662
|
-
|
|
37249
|
+
if (isLoopback(endpoint)) {
|
|
37250
|
+
return `Cannot connect to ${displayName} at ${endpoint}. Make sure the server is running.`;
|
|
37251
|
+
}
|
|
37252
|
+
return `Cannot reach ${host} for ${displayName}. This is a network problem on your machine \u2014 check your internet connection, VPN, or DNS resolver (e.g. Tailscale MagicDNS) \u2014 not ${displayName}.`;
|
|
37663
37253
|
case "unreachable":
|
|
37664
37254
|
return `Cannot reach ${displayName} at ${endpoint}. Check your network connection.`;
|
|
37665
37255
|
}
|
|
37666
37256
|
}
|
|
37667
|
-
var CODE_KIND;
|
|
37257
|
+
var CODE_KIND, BUN_CONNECT_MESSAGE;
|
|
37668
37258
|
var init_connection_error = __esm(() => {
|
|
37669
37259
|
CODE_KIND = {
|
|
37670
37260
|
ENOTFOUND: "dns",
|
|
@@ -37676,8 +37266,13 @@ var init_connection_error = __esm(() => {
|
|
|
37676
37266
|
EHOSTUNREACH: "unreachable",
|
|
37677
37267
|
EPIPE: "unreachable",
|
|
37678
37268
|
UND_ERR_CONNECT_TIMEOUT: "unreachable",
|
|
37679
|
-
UND_ERR_SOCKET: "unreachable"
|
|
37269
|
+
UND_ERR_SOCKET: "unreachable",
|
|
37270
|
+
ConnectionRefused: "refused",
|
|
37271
|
+
ConnectionClosed: "unreachable",
|
|
37272
|
+
FailedToOpenSocket: "unreachable",
|
|
37273
|
+
ERR_SOCKET_CLOSED: "unreachable"
|
|
37680
37274
|
};
|
|
37275
|
+
BUN_CONNECT_MESSAGE = /unable to connect\. is the computer able to access the url\?/i;
|
|
37681
37276
|
});
|
|
37682
37277
|
|
|
37683
37278
|
// src/handlers/shared/stream-parsers/anthropic-sse.ts
|
|
@@ -38643,6 +38238,7 @@ data: ${JSON.stringify(data)}
|
|
|
38643
38238
|
var init_openai_responses_sse = __esm(() => {
|
|
38644
38239
|
init_reasoning_cache();
|
|
38645
38240
|
init_logger();
|
|
38241
|
+
init_anthropic_error();
|
|
38646
38242
|
});
|
|
38647
38243
|
|
|
38648
38244
|
// src/handlers/shared/token-tracker.ts
|
|
@@ -38985,7 +38581,7 @@ class ComposedHandler {
|
|
|
38985
38581
|
isInteractive: this.isInteractive,
|
|
38986
38582
|
authType: "oauth"
|
|
38987
38583
|
});
|
|
38988
|
-
return c.json(
|
|
38584
|
+
return c.json(wrapAnthropicError(401, err.message, "authentication_error"), 401);
|
|
38989
38585
|
}
|
|
38990
38586
|
}
|
|
38991
38587
|
if (this.provider.getContextWindow) {
|
|
@@ -39051,7 +38647,7 @@ class ComposedHandler {
|
|
|
39051
38647
|
invocation_mode: this.options.invocationMode ?? "auto-route"
|
|
39052
38648
|
});
|
|
39053
38649
|
} catch {}
|
|
39054
|
-
return c.json(wrapAnthropicError(
|
|
38650
|
+
return c.json(wrapAnthropicError(400, msg, "connection_error"), 400);
|
|
39055
38651
|
}
|
|
39056
38652
|
throw error46;
|
|
39057
38653
|
}
|
|
@@ -39388,6 +38984,7 @@ var init_composed_handler = __esm(() => {
|
|
|
39388
38984
|
init_stats();
|
|
39389
38985
|
init_telemetry();
|
|
39390
38986
|
init_transform();
|
|
38987
|
+
init_anthropic_error();
|
|
39391
38988
|
init_connection_error();
|
|
39392
38989
|
init_openai_compat();
|
|
39393
38990
|
init_anthropic_sse();
|
|
@@ -40344,6 +39941,7 @@ var init_native_handler = __esm(() => {
|
|
|
40344
39941
|
init_logger();
|
|
40345
39942
|
init_profile_config();
|
|
40346
39943
|
init_native_handler_advisor();
|
|
39944
|
+
init_anthropic_error();
|
|
40347
39945
|
});
|
|
40348
39946
|
|
|
40349
39947
|
// src/providers/api-key-map.ts
|
|
@@ -40737,8 +40335,8 @@ function cacheSetFailure(key, reason) {
|
|
|
40737
40335
|
function cacheSetRanked(key, ranked) {
|
|
40738
40336
|
_cache.set(key, { ranked, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
40739
40337
|
}
|
|
40740
|
-
async function discoverViaOpenAIModels(endpoint, headers,
|
|
40741
|
-
const cached2 = cacheGet(
|
|
40338
|
+
async function discoverViaOpenAIModels(endpoint, headers, cacheKey) {
|
|
40339
|
+
const cached2 = cacheGet(cacheKey.key, cacheKey.exclude);
|
|
40742
40340
|
if (cached2 !== undefined)
|
|
40743
40341
|
return cached2;
|
|
40744
40342
|
let response;
|
|
@@ -40750,14 +40348,14 @@ async function discoverViaOpenAIModels(endpoint, headers, cacheKey2) {
|
|
|
40750
40348
|
});
|
|
40751
40349
|
} catch (e) {
|
|
40752
40350
|
const reason = classifyFetchError(e, endpoint);
|
|
40753
|
-
log(`[probe-discovery${
|
|
40754
|
-
cacheSetFailure(
|
|
40351
|
+
log(`[probe-discovery${cacheKey.displayName ? `:${cacheKey.displayName}` : ""}] fetch failed: ${reason}`);
|
|
40352
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40755
40353
|
return { model: null, reason };
|
|
40756
40354
|
}
|
|
40757
40355
|
if (!response.ok) {
|
|
40758
40356
|
const reason = `HTTP ${response.status} from ${endpoint}`;
|
|
40759
|
-
log(`[probe-discovery${
|
|
40760
|
-
cacheSetFailure(
|
|
40357
|
+
log(`[probe-discovery${cacheKey.displayName ? `:${cacheKey.displayName}` : ""}] ${reason}`);
|
|
40358
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40761
40359
|
return { model: null, reason };
|
|
40762
40360
|
}
|
|
40763
40361
|
let body;
|
|
@@ -40765,7 +40363,7 @@ async function discoverViaOpenAIModels(endpoint, headers, cacheKey2) {
|
|
|
40765
40363
|
body = await response.json();
|
|
40766
40364
|
} catch {
|
|
40767
40365
|
const reason = "invalid /v1/models response (not JSON)";
|
|
40768
|
-
cacheSetFailure(
|
|
40366
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40769
40367
|
return { model: null, reason };
|
|
40770
40368
|
}
|
|
40771
40369
|
const ids = extractModelIds(body);
|
|
@@ -40773,17 +40371,17 @@ async function discoverViaOpenAIModels(endpoint, headers, cacheKey2) {
|
|
|
40773
40371
|
const url2 = tryParseUrl(endpoint);
|
|
40774
40372
|
const host = url2?.host ?? endpoint;
|
|
40775
40373
|
const reason = `${host} reachable but no models loaded \u2014 load a model in the server UI`;
|
|
40776
|
-
cacheSetFailure(
|
|
40374
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40777
40375
|
return { model: null, reason };
|
|
40778
40376
|
}
|
|
40779
40377
|
const ranked = rankProbeCandidates(ids);
|
|
40780
40378
|
if (ranked.length === 0) {
|
|
40781
40379
|
const reason = `no chat-capable model among ${ids.length} listed`;
|
|
40782
|
-
cacheSetFailure(
|
|
40380
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40783
40381
|
return { model: null, reason };
|
|
40784
40382
|
}
|
|
40785
|
-
cacheSetRanked(
|
|
40786
|
-
const pick2 = ranked.find((m) => !
|
|
40383
|
+
cacheSetRanked(cacheKey.key, ranked);
|
|
40384
|
+
const pick2 = ranked.find((m) => !cacheKey.exclude?.has(m));
|
|
40787
40385
|
if (!pick2) {
|
|
40788
40386
|
return {
|
|
40789
40387
|
model: null,
|
|
@@ -40833,8 +40431,8 @@ function extractModelIds(body) {
|
|
|
40833
40431
|
}
|
|
40834
40432
|
return [];
|
|
40835
40433
|
}
|
|
40836
|
-
async function discoverViaOllama(baseUrl,
|
|
40837
|
-
const cached2 = cacheGet(
|
|
40434
|
+
async function discoverViaOllama(baseUrl, cacheKey) {
|
|
40435
|
+
const cached2 = cacheGet(cacheKey.key, cacheKey.exclude);
|
|
40838
40436
|
if (cached2 !== undefined)
|
|
40839
40437
|
return cached2;
|
|
40840
40438
|
let connectionError;
|
|
@@ -40855,7 +40453,7 @@ async function discoverViaOllama(baseUrl, cacheKey2) {
|
|
|
40855
40453
|
const candidates = allRaw.filter((m) => isChatCapable(m.name));
|
|
40856
40454
|
if (candidates.length === 0) {
|
|
40857
40455
|
const reason = connectionError ?? (allRaw.length === 0 ? `no models on ${baseUrl} (pull one: ollama pull llama3.2)` : `only embedding/non-chat models on ${baseUrl}`);
|
|
40858
|
-
cacheSetFailure(
|
|
40456
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40859
40457
|
return { model: null, reason };
|
|
40860
40458
|
}
|
|
40861
40459
|
const sized = candidates.filter((m) => typeof m.size === "number");
|
|
@@ -40867,11 +40465,11 @@ async function discoverViaOllama(baseUrl, cacheKey2) {
|
|
|
40867
40465
|
}
|
|
40868
40466
|
if (ranked.length === 0) {
|
|
40869
40467
|
const reason = "no chat-capable model on Ollama endpoint";
|
|
40870
|
-
cacheSetFailure(
|
|
40468
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40871
40469
|
return { model: null, reason };
|
|
40872
40470
|
}
|
|
40873
|
-
cacheSetRanked(
|
|
40874
|
-
const pick2 = ranked.find((m) => !
|
|
40471
|
+
cacheSetRanked(cacheKey.key, ranked);
|
|
40472
|
+
const pick2 = ranked.find((m) => !cacheKey.exclude?.has(m));
|
|
40875
40473
|
if (!pick2) {
|
|
40876
40474
|
return {
|
|
40877
40475
|
model: null,
|
|
@@ -40880,8 +40478,8 @@ async function discoverViaOllama(baseUrl, cacheKey2) {
|
|
|
40880
40478
|
}
|
|
40881
40479
|
return { model: pick2 };
|
|
40882
40480
|
}
|
|
40883
|
-
async function discoverViaLMStudio(baseUrl, headers,
|
|
40884
|
-
const cached2 = cacheGet(
|
|
40481
|
+
async function discoverViaLMStudio(baseUrl, headers, cacheKey) {
|
|
40482
|
+
const cached2 = cacheGet(cacheKey.key, cacheKey.exclude);
|
|
40885
40483
|
if (cached2 !== undefined)
|
|
40886
40484
|
return cached2;
|
|
40887
40485
|
let response;
|
|
@@ -40892,17 +40490,17 @@ async function discoverViaLMStudio(baseUrl, headers, cacheKey2) {
|
|
|
40892
40490
|
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
40893
40491
|
});
|
|
40894
40492
|
} catch (e) {
|
|
40895
|
-
return discoverViaOpenAIModels(`${baseUrl}/v1/models`, headers,
|
|
40493
|
+
return discoverViaOpenAIModels(`${baseUrl}/v1/models`, headers, cacheKey);
|
|
40896
40494
|
}
|
|
40897
40495
|
if (!response.ok) {
|
|
40898
|
-
return discoverViaOpenAIModels(`${baseUrl}/v1/models`, headers,
|
|
40496
|
+
return discoverViaOpenAIModels(`${baseUrl}/v1/models`, headers, cacheKey);
|
|
40899
40497
|
}
|
|
40900
40498
|
let body;
|
|
40901
40499
|
try {
|
|
40902
40500
|
body = await response.json();
|
|
40903
40501
|
} catch {
|
|
40904
40502
|
const reason = "invalid /api/v0/models response (not JSON)";
|
|
40905
|
-
cacheSetFailure(
|
|
40503
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40906
40504
|
return { model: null, reason };
|
|
40907
40505
|
}
|
|
40908
40506
|
const models = extractLMStudioModels(body);
|
|
@@ -40910,7 +40508,7 @@ async function discoverViaLMStudio(baseUrl, headers, cacheKey2) {
|
|
|
40910
40508
|
const url2 = tryParseUrl(baseUrl);
|
|
40911
40509
|
const host = url2?.host ?? baseUrl;
|
|
40912
40510
|
const reason = `${host} reachable but no models present \u2014 download one in the LM Studio UI`;
|
|
40913
|
-
cacheSetFailure(
|
|
40511
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40914
40512
|
return { model: null, reason };
|
|
40915
40513
|
}
|
|
40916
40514
|
const chatModels = models.filter((m) => isChatCapable(m.id) && m.type !== "embeddings" && m.type !== "embedding");
|
|
@@ -40924,11 +40522,11 @@ async function discoverViaLMStudio(baseUrl, headers, cacheKey2) {
|
|
|
40924
40522
|
const url2 = tryParseUrl(baseUrl);
|
|
40925
40523
|
const host = url2?.host ?? baseUrl;
|
|
40926
40524
|
const reason = `${host} has ${models.length} model(s) but none are chat-capable`;
|
|
40927
|
-
cacheSetFailure(
|
|
40525
|
+
cacheSetFailure(cacheKey.key, reason);
|
|
40928
40526
|
return { model: null, reason };
|
|
40929
40527
|
}
|
|
40930
|
-
cacheSetRanked(
|
|
40931
|
-
const pick2 = ranked.find((m) => !
|
|
40528
|
+
cacheSetRanked(cacheKey.key, ranked);
|
|
40529
|
+
const pick2 = ranked.find((m) => !cacheKey.exclude?.has(m));
|
|
40932
40530
|
if (!pick2) {
|
|
40933
40531
|
return {
|
|
40934
40532
|
model: null,
|
|
@@ -41109,7 +40707,8 @@ function loadCustomEndpoints(config2) {
|
|
|
41109
40707
|
credentials.registerApiKeyProvider({
|
|
41110
40708
|
name: def.name,
|
|
41111
40709
|
envVar: def.apiKeyEnvVar,
|
|
41112
|
-
authScheme: def.authScheme === "x-api-key" ? "x-api-key" : "bearer"
|
|
40710
|
+
authScheme: def.authScheme === "x-api-key" ? "x-api-key" : "bearer",
|
|
40711
|
+
declaredKey: () => resolveDeclaredEndpointKey(validated)
|
|
41113
40712
|
});
|
|
41114
40713
|
result.registered++;
|
|
41115
40714
|
} catch (err) {
|
|
@@ -41267,6 +40866,14 @@ function resolveCustomEndpointApiKey(ep) {
|
|
|
41267
40866
|
}
|
|
41268
40867
|
return literal3;
|
|
41269
40868
|
}
|
|
40869
|
+
function resolveDeclaredEndpointKey(ep) {
|
|
40870
|
+
const declared = ep.apiKey?.trim();
|
|
40871
|
+
if (!declared)
|
|
40872
|
+
return;
|
|
40873
|
+
if (declared.startsWith("op://"))
|
|
40874
|
+
return;
|
|
40875
|
+
return resolveCustomEndpointApiKey(ep) || undefined;
|
|
40876
|
+
}
|
|
41270
40877
|
function stripTrailingSlash(url2) {
|
|
41271
40878
|
return url2.replace(/\/+$/, "");
|
|
41272
40879
|
}
|
|
@@ -41382,6 +40989,12 @@ var init_ollama_api_format = __esm(() => {
|
|
|
41382
40989
|
import { existsSync as existsSync15, readFileSync as readFileSync12 } from "fs";
|
|
41383
40990
|
import { homedir as homedir18 } from "os";
|
|
41384
40991
|
import { join as join18, resolve } from "path";
|
|
40992
|
+
function activeConfigPath() {
|
|
40993
|
+
return activeGlobalConfigFile(join18(homedir18(), ".claudish", "config.json"));
|
|
40994
|
+
}
|
|
40995
|
+
function configLayerLabel() {
|
|
40996
|
+
return getConfigFileOverride() ? activeConfigPath() : "~/.claudish/config.json";
|
|
40997
|
+
}
|
|
41385
40998
|
function maskKey(key) {
|
|
41386
40999
|
if (!key)
|
|
41387
41000
|
return null;
|
|
@@ -41401,7 +41014,7 @@ function resolveApiKeyProvenance(envVar, aliases) {
|
|
|
41401
41014
|
});
|
|
41402
41015
|
const configValue = readConfigKey(envVar);
|
|
41403
41016
|
layers.push({
|
|
41404
|
-
source:
|
|
41017
|
+
source: configLayerLabel(),
|
|
41405
41018
|
maskedValue: maskKey(configValue),
|
|
41406
41019
|
isActive: false
|
|
41407
41020
|
});
|
|
@@ -41427,7 +41040,7 @@ function resolveApiKeyProvenance(envVar, aliases) {
|
|
|
41427
41040
|
layers[0].isActive = true;
|
|
41428
41041
|
layers[2].isActive = false;
|
|
41429
41042
|
} else if (configValue && configValue === runtimeValue) {
|
|
41430
|
-
effectiveSource =
|
|
41043
|
+
effectiveSource = configLayerLabel();
|
|
41431
41044
|
layers[1].isActive = true;
|
|
41432
41045
|
layers[2].isActive = false;
|
|
41433
41046
|
} else if (isOpHydratedVar(runtimeVar)) {
|
|
@@ -41468,7 +41081,7 @@ function readDotenvKey(envVars) {
|
|
|
41468
41081
|
}
|
|
41469
41082
|
function readConfigKey(envVar) {
|
|
41470
41083
|
try {
|
|
41471
|
-
const configPath =
|
|
41084
|
+
const configPath = activeConfigPath();
|
|
41472
41085
|
if (!existsSync15(configPath))
|
|
41473
41086
|
return null;
|
|
41474
41087
|
const cfg = JSON.parse(readFileSync12(configPath, "utf-8"));
|
|
@@ -43327,21 +42940,21 @@ class LocalTransport {
|
|
|
43327
42940
|
return headers;
|
|
43328
42941
|
}
|
|
43329
42942
|
async discoverProbeModel(exclude) {
|
|
43330
|
-
const
|
|
42943
|
+
const cacheKey = {
|
|
43331
42944
|
key: `${this.config.name}:${this.config.baseUrl}`,
|
|
43332
42945
|
displayName: this.displayName,
|
|
43333
42946
|
exclude
|
|
43334
42947
|
};
|
|
43335
42948
|
if (this.config.name === "ollama") {
|
|
43336
42949
|
return discoverViaOllama(this.config.baseUrl, {
|
|
43337
|
-
...
|
|
42950
|
+
...cacheKey,
|
|
43338
42951
|
key: `ollama:${this.config.baseUrl}`
|
|
43339
42952
|
});
|
|
43340
42953
|
}
|
|
43341
42954
|
if (this.config.name === "lmstudio") {
|
|
43342
|
-
return discoverViaLMStudio(this.config.baseUrl, await this.getHeaders(),
|
|
42955
|
+
return discoverViaLMStudio(this.config.baseUrl, await this.getHeaders(), cacheKey);
|
|
43343
42956
|
}
|
|
43344
|
-
return discoverViaOpenAIModels(`${this.config.baseUrl}/v1/models`, await this.getHeaders(),
|
|
42957
|
+
return discoverViaOpenAIModels(`${this.config.baseUrl}/v1/models`, await this.getHeaders(), cacheKey);
|
|
43345
42958
|
}
|
|
43346
42959
|
getRequestInit() {
|
|
43347
42960
|
return {
|
|
@@ -43904,7 +43517,7 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
43904
43517
|
log(`[Proxy] Registered ${customEpResult.registered} custom endpoint(s) from config`);
|
|
43905
43518
|
}
|
|
43906
43519
|
for (const err of customEpResult.errors) {
|
|
43907
|
-
|
|
43520
|
+
logStderr(`customEndpoints['${err.name}'] failed validation: ${err.message}`);
|
|
43908
43521
|
}
|
|
43909
43522
|
} catch (err) {
|
|
43910
43523
|
log(`[Proxy] customEndpoints load skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -43992,9 +43605,10 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
43992
43605
|
const resolution = resolveModelProvider(targetModel);
|
|
43993
43606
|
if (resolution.wasAutoRouted && resolution.autoRouteMessage) {
|
|
43994
43607
|
if (!options.quiet) {
|
|
43995
|
-
|
|
43608
|
+
logStderr(`[Auto-route] ${resolution.autoRouteMessage}`);
|
|
43609
|
+
} else {
|
|
43610
|
+
log(`[Auto-route] ${resolution.autoRouteMessage}`);
|
|
43996
43611
|
}
|
|
43997
|
-
log(`[Auto-route] ${resolution.autoRouteMessage}`);
|
|
43998
43612
|
}
|
|
43999
43613
|
if (resolution.category === "openrouter") {
|
|
44000
43614
|
if (resolution.wasAutoRouted && resolution.fullModelId) {
|
|
@@ -44013,7 +43627,7 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
44013
43627
|
let apiKey = "";
|
|
44014
43628
|
if (resolved.provider.apiKeyEnvVar) {
|
|
44015
43629
|
if (!credentials.get(resolved.provider.name)) {
|
|
44016
|
-
|
|
43630
|
+
logStderr(`[Proxy] No credential provider registered for "${resolved.provider.name}" \u2014 treating as missing credential (authority registration gap)`);
|
|
44017
43631
|
log(`[Proxy] Credential authority has no provider registered under "${resolved.provider.name}"`);
|
|
44018
43632
|
return null;
|
|
44019
43633
|
}
|
|
@@ -44105,9 +43719,9 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
44105
43719
|
{
|
|
44106
43720
|
const parsedForFallback = parseModelSpec(target);
|
|
44107
43721
|
if (!parsedForFallback.isExplicitProvider && parsedForFallback.provider !== "native-anthropic" && !isPoeModel(target)) {
|
|
44108
|
-
const
|
|
44109
|
-
if (fallbackHandlerCache.has(
|
|
44110
|
-
return fallbackHandlerCache.get(
|
|
43722
|
+
const cacheKey = `fallback:${target}`;
|
|
43723
|
+
if (fallbackHandlerCache.has(cacheKey)) {
|
|
43724
|
+
return fallbackHandlerCache.get(cacheKey);
|
|
44111
43725
|
}
|
|
44112
43726
|
await ensureCatalogReady("openrouter", 5000);
|
|
44113
43727
|
const plan = await route(parsedForFallback.model, effectiveRoutingRules);
|
|
@@ -44127,7 +43741,7 @@ async function createProxyServer(port, _openrouterApiKey, model, monitorMode = f
|
|
|
44127
43741
|
}
|
|
44128
43742
|
if (candidates.length > 0) {
|
|
44129
43743
|
const resultHandler = candidates.length > 1 ? new FallbackHandler(candidates) : candidates[0].handler;
|
|
44130
|
-
fallbackHandlerCache.set(
|
|
43744
|
+
fallbackHandlerCache.set(cacheKey, resultHandler);
|
|
44131
43745
|
if (!options.quiet && candidates.length > 1) {
|
|
44132
43746
|
logStderr(`[Route] ${candidates.length} providers for ${parsedForFallback.model}: ${candidates.map((c) => c.name).join(" \u2192 ")}`);
|
|
44133
43747
|
}
|
|
@@ -44171,6 +43785,11 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
44171
43785
|
};
|
|
44172
43786
|
const app = new Hono2;
|
|
44173
43787
|
app.use("*", cors());
|
|
43788
|
+
app.onError((err, c) => {
|
|
43789
|
+
logStderr(`[Proxy] Unhandled error on ${c.req.method} ${c.req.path}: ${err?.message ?? err}`);
|
|
43790
|
+
log(`[Proxy] Unhandled error stack: ${err?.stack ?? "(no stack)"}`);
|
|
43791
|
+
return c.json(wrapAnthropicError(500, `Proxy error: ${err?.message ?? String(err)}`), 500);
|
|
43792
|
+
});
|
|
44174
43793
|
app.get("/", (c) => c.json({
|
|
44175
43794
|
status: "ok",
|
|
44176
43795
|
message: "Claudish Proxy",
|
|
@@ -44250,7 +43869,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
44250
43869
|
const body = await c.req.json();
|
|
44251
43870
|
log(`[RequestMeta] model=${body.model} output_config=${JSON.stringify(body.output_config) ?? "(none)"} metadata=${JSON.stringify(body.metadata) ?? "(none)"} anthropic-beta=${c.req.header("anthropic-beta") ?? "(none)"}`);
|
|
44252
43871
|
const handler = await getHandlerForRequest(body.model);
|
|
44253
|
-
return handler.handle(c, body);
|
|
43872
|
+
return await handler.handle(c, body);
|
|
44254
43873
|
} catch (e) {
|
|
44255
43874
|
log(`[Proxy] Error: ${e}`);
|
|
44256
43875
|
if (e instanceof RoutingError) {
|
|
@@ -44259,9 +43878,13 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
44259
43878
|
return c.json(wrapAnthropicError(500, String(e)), 500);
|
|
44260
43879
|
}
|
|
44261
43880
|
});
|
|
44262
|
-
const server = serve({
|
|
44263
|
-
|
|
44264
|
-
|
|
43881
|
+
const server = Bun.serve({
|
|
43882
|
+
fetch: app.fetch,
|
|
43883
|
+
port,
|
|
43884
|
+
hostname: "127.0.0.1",
|
|
43885
|
+
idleTimeout: 255
|
|
43886
|
+
});
|
|
43887
|
+
const resolvedPort = server.port ?? port;
|
|
44265
43888
|
log(`[Proxy] Server started on port ${resolvedPort}`);
|
|
44266
43889
|
warmPricingCache().catch(() => {});
|
|
44267
43890
|
warmRecommendedModels().catch(() => {});
|
|
@@ -44270,7 +43893,7 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
44270
43893
|
port: resolvedPort,
|
|
44271
43894
|
url: `http://127.0.0.1:${resolvedPort}`,
|
|
44272
43895
|
shutdown: async () => {
|
|
44273
|
-
|
|
43896
|
+
await server.stop(true);
|
|
44274
43897
|
},
|
|
44275
43898
|
invalidateHandlerCache: (providerSlug) => {
|
|
44276
43899
|
if (!providerSlug) {
|
|
@@ -44293,7 +43916,6 @@ ${plan.hint}` : `[Route] ${plan.reason}`;
|
|
|
44293
43916
|
var RoutingError;
|
|
44294
43917
|
var init_proxy_server = __esm(() => {
|
|
44295
43918
|
init_dist();
|
|
44296
|
-
init_dist2();
|
|
44297
43919
|
init_cors();
|
|
44298
43920
|
init_local_adapter();
|
|
44299
43921
|
init_openrouter_api_format();
|
|
@@ -44301,6 +43923,7 @@ var init_proxy_server = __esm(() => {
|
|
|
44301
43923
|
init_composed_handler();
|
|
44302
43924
|
init_fallback_handler();
|
|
44303
43925
|
init_native_handler();
|
|
43926
|
+
init_anthropic_error();
|
|
44304
43927
|
init_logger();
|
|
44305
43928
|
init_model_loader();
|
|
44306
43929
|
init_profile_config();
|
|
@@ -45730,7 +45353,7 @@ var init_mcp_server = __esm(() => {
|
|
|
45730
45353
|
init_proxy_server();
|
|
45731
45354
|
init_team_orchestrator();
|
|
45732
45355
|
import_dotenv2 = __toESM(require_main(), 1);
|
|
45733
|
-
import_dotenv2.config();
|
|
45356
|
+
import_dotenv2.config({ quiet: true });
|
|
45734
45357
|
__filename2 = fileURLToPath(import.meta.url);
|
|
45735
45358
|
__dirname2 = dirname5(__filename2);
|
|
45736
45359
|
CLAUDISH_CACHE_DIR = join21(homedir20(), ".claudish");
|
|
@@ -46142,7 +45765,7 @@ function isUnicodeSupported() {
|
|
|
46142
45765
|
return Boolean(process3.env["WT_SESSION"]) || Boolean(process3.env["TERMINUS_SUBLIME"]) || process3.env["ConEmuTask"] === "{cmd::Cmder}" || process3.env["TERM_PROGRAM"] === "Terminus-Sublime" || process3.env["TERM_PROGRAM"] === "vscode" || process3.env["TERM"] === "xterm-256color" || process3.env["TERM"] === "alacritty" || process3.env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
|
|
46143
45766
|
}
|
|
46144
45767
|
var common, specialMainSymbols, specialFallbackSymbols, mainSymbols, fallbackSymbols, shouldUseMain, figures, dist_default, replacements;
|
|
46145
|
-
var
|
|
45768
|
+
var init_dist2 = __esm(() => {
|
|
46146
45769
|
common = {
|
|
46147
45770
|
circleQuestionMark: "(?)",
|
|
46148
45771
|
questionMarkPrefix: "(?)",
|
|
@@ -46429,7 +46052,7 @@ var init_dist3 = __esm(() => {
|
|
|
46429
46052
|
import { styleText } from "util";
|
|
46430
46053
|
var defaultTheme;
|
|
46431
46054
|
var init_theme = __esm(() => {
|
|
46432
|
-
|
|
46055
|
+
init_dist2();
|
|
46433
46056
|
defaultTheme = {
|
|
46434
46057
|
prefix: {
|
|
46435
46058
|
idle: styleText("blue", "?"),
|
|
@@ -47472,7 +47095,7 @@ var ESC = "\x1B[", cursorLeft, cursorHide, cursorShow, cursorUp = (rows = 1) =>
|
|
|
47472
47095
|
}
|
|
47473
47096
|
return `${ESC}${x + 1}G`;
|
|
47474
47097
|
}, eraseLine, eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + eraseLine + cursorLeft : "";
|
|
47475
|
-
var
|
|
47098
|
+
var init_dist3 = __esm(() => {
|
|
47476
47099
|
cursorLeft = ESC + "G";
|
|
47477
47100
|
cursorHide = ESC + "?25l";
|
|
47478
47101
|
cursorShow = ESC + "?25h";
|
|
@@ -47545,7 +47168,7 @@ var height = (content) => content.split(`
|
|
|
47545
47168
|
`).pop() ?? "";
|
|
47546
47169
|
var init_screen_manager = __esm(() => {
|
|
47547
47170
|
init_utils();
|
|
47548
|
-
|
|
47171
|
+
init_dist3();
|
|
47549
47172
|
});
|
|
47550
47173
|
|
|
47551
47174
|
// ../../node_modules/.bun/@inquirer+core@11.0.1+04f2146be16c61ef/node_modules/@inquirer/core/dist/lib/promise-polyfill.js
|
|
@@ -47678,11 +47301,11 @@ class Separator {
|
|
|
47678
47301
|
}
|
|
47679
47302
|
}
|
|
47680
47303
|
var init_Separator = __esm(() => {
|
|
47681
|
-
|
|
47304
|
+
init_dist2();
|
|
47682
47305
|
});
|
|
47683
47306
|
|
|
47684
47307
|
// ../../node_modules/.bun/@inquirer+core@11.0.1+04f2146be16c61ef/node_modules/@inquirer/core/dist/index.js
|
|
47685
|
-
var
|
|
47308
|
+
var init_dist4 = __esm(() => {
|
|
47686
47309
|
init_use_prefix();
|
|
47687
47310
|
init_use_state();
|
|
47688
47311
|
init_use_effect();
|
|
@@ -47742,11 +47365,11 @@ function normalizeChoices(choices) {
|
|
|
47742
47365
|
});
|
|
47743
47366
|
}
|
|
47744
47367
|
var checkboxTheme, dist_default2;
|
|
47745
|
-
var
|
|
47746
|
-
init_dist5();
|
|
47368
|
+
var init_dist5 = __esm(() => {
|
|
47747
47369
|
init_dist4();
|
|
47748
47370
|
init_dist3();
|
|
47749
|
-
|
|
47371
|
+
init_dist2();
|
|
47372
|
+
init_dist4();
|
|
47750
47373
|
checkboxTheme = {
|
|
47751
47374
|
icon: {
|
|
47752
47375
|
checked: styleText3("green", dist_default.circleFilled),
|
|
@@ -57387,7 +57010,7 @@ class ExternalEditor {
|
|
|
57387
57010
|
}
|
|
57388
57011
|
}
|
|
57389
57012
|
var import_chardet, import_iconv_lite;
|
|
57390
|
-
var
|
|
57013
|
+
var init_dist6 = __esm(() => {
|
|
57391
57014
|
init_CreateFileError();
|
|
57392
57015
|
init_LaunchEditorError();
|
|
57393
57016
|
init_ReadFileError();
|
|
@@ -57398,9 +57021,9 @@ var init_dist7 = __esm(() => {
|
|
|
57398
57021
|
|
|
57399
57022
|
// ../../node_modules/.bun/@inquirer+editor@5.0.1+04f2146be16c61ef/node_modules/@inquirer/editor/dist/index.js
|
|
57400
57023
|
var editorTheme, dist_default3;
|
|
57401
|
-
var
|
|
57402
|
-
|
|
57403
|
-
|
|
57024
|
+
var init_dist7 = __esm(() => {
|
|
57025
|
+
init_dist6();
|
|
57026
|
+
init_dist4();
|
|
57404
57027
|
editorTheme = {
|
|
57405
57028
|
validationFailureMode: "keep"
|
|
57406
57029
|
};
|
|
@@ -57483,8 +57106,8 @@ function boolToString(value) {
|
|
|
57483
57106
|
return value ? "Yes" : "No";
|
|
57484
57107
|
}
|
|
57485
57108
|
var dist_default4;
|
|
57486
|
-
var
|
|
57487
|
-
|
|
57109
|
+
var init_dist8 = __esm(() => {
|
|
57110
|
+
init_dist4();
|
|
57488
57111
|
dist_default4 = createPrompt((config3, done) => {
|
|
57489
57112
|
const { transformer = boolToString } = config3;
|
|
57490
57113
|
const [status, setStatus] = useState("idle");
|
|
@@ -57522,8 +57145,8 @@ var init_dist9 = __esm(() => {
|
|
|
57522
57145
|
|
|
57523
57146
|
// ../../node_modules/.bun/@inquirer+input@5.0.1+04f2146be16c61ef/node_modules/@inquirer/input/dist/index.js
|
|
57524
57147
|
var inputTheme, dist_default5;
|
|
57525
|
-
var
|
|
57526
|
-
|
|
57148
|
+
var init_dist9 = __esm(() => {
|
|
57149
|
+
init_dist4();
|
|
57527
57150
|
inputTheme = {
|
|
57528
57151
|
validationFailureMode: "keep"
|
|
57529
57152
|
};
|
|
@@ -57627,8 +57250,8 @@ function validateNumber(value, { min, max, step }) {
|
|
|
57627
57250
|
return true;
|
|
57628
57251
|
}
|
|
57629
57252
|
var dist_default6;
|
|
57630
|
-
var
|
|
57631
|
-
|
|
57253
|
+
var init_dist10 = __esm(() => {
|
|
57254
|
+
init_dist4();
|
|
57632
57255
|
dist_default6 = createPrompt((config3, done) => {
|
|
57633
57256
|
const { validate: validate2 = () => true, min = -Infinity, max = Infinity, step = 1, required: required2 = false } = config3;
|
|
57634
57257
|
const theme = makeTheme(config3.theme);
|
|
@@ -57711,8 +57334,8 @@ function normalizeChoices2(choices) {
|
|
|
57711
57334
|
});
|
|
57712
57335
|
}
|
|
57713
57336
|
var helpChoice, dist_default7;
|
|
57714
|
-
var
|
|
57715
|
-
|
|
57337
|
+
var init_dist11 = __esm(() => {
|
|
57338
|
+
init_dist4();
|
|
57716
57339
|
helpChoice = {
|
|
57717
57340
|
key: "h",
|
|
57718
57341
|
name: "Help, list all options",
|
|
@@ -57835,8 +57458,8 @@ function getSelectedChoice(input, choices) {
|
|
|
57835
57458
|
return selectedChoice ? [selectedChoice, choices.indexOf(selectedChoice)] : [undefined, undefined];
|
|
57836
57459
|
}
|
|
57837
57460
|
var numberRegex, dist_default8;
|
|
57838
|
-
var
|
|
57839
|
-
|
|
57461
|
+
var init_dist12 = __esm(() => {
|
|
57462
|
+
init_dist4();
|
|
57840
57463
|
numberRegex = /\d+/;
|
|
57841
57464
|
dist_default8 = createPrompt((config3, done) => {
|
|
57842
57465
|
const { loop = true } = config3;
|
|
@@ -57914,9 +57537,9 @@ var init_dist13 = __esm(() => {
|
|
|
57914
57537
|
|
|
57915
57538
|
// ../../node_modules/.bun/@inquirer+password@5.0.1+04f2146be16c61ef/node_modules/@inquirer/password/dist/index.js
|
|
57916
57539
|
var dist_default9;
|
|
57917
|
-
var
|
|
57918
|
-
init_dist5();
|
|
57540
|
+
var init_dist13 = __esm(() => {
|
|
57919
57541
|
init_dist4();
|
|
57542
|
+
init_dist3();
|
|
57920
57543
|
dist_default9 = createPrompt((config3, done) => {
|
|
57921
57544
|
const { validate: validate2 = () => true } = config3;
|
|
57922
57545
|
const theme = makeTheme(config3.theme);
|
|
@@ -57997,9 +57620,9 @@ function normalizeChoices4(choices) {
|
|
|
57997
57620
|
});
|
|
57998
57621
|
}
|
|
57999
57622
|
var searchTheme, dist_default10;
|
|
58000
|
-
var
|
|
58001
|
-
|
|
58002
|
-
|
|
57623
|
+
var init_dist14 = __esm(() => {
|
|
57624
|
+
init_dist4();
|
|
57625
|
+
init_dist2();
|
|
58003
57626
|
searchTheme = {
|
|
58004
57627
|
icon: { cursor: dist_default.pointer },
|
|
58005
57628
|
style: {
|
|
@@ -58165,10 +57788,10 @@ function normalizeChoices5(choices) {
|
|
|
58165
57788
|
});
|
|
58166
57789
|
}
|
|
58167
57790
|
var selectTheme, dist_default11;
|
|
58168
|
-
var
|
|
58169
|
-
init_dist5();
|
|
57791
|
+
var init_dist15 = __esm(() => {
|
|
58170
57792
|
init_dist4();
|
|
58171
57793
|
init_dist3();
|
|
57794
|
+
init_dist2();
|
|
58172
57795
|
selectTheme = {
|
|
58173
57796
|
icon: { cursor: dist_default.pointer },
|
|
58174
57797
|
style: {
|
|
@@ -58311,8 +57934,9 @@ __export(exports_dist, {
|
|
|
58311
57934
|
checkbox: () => dist_default2,
|
|
58312
57935
|
Separator: () => Separator
|
|
58313
57936
|
});
|
|
58314
|
-
var
|
|
58315
|
-
|
|
57937
|
+
var init_dist16 = __esm(() => {
|
|
57938
|
+
init_dist5();
|
|
57939
|
+
init_dist7();
|
|
58316
57940
|
init_dist8();
|
|
58317
57941
|
init_dist9();
|
|
58318
57942
|
init_dist10();
|
|
@@ -58321,7 +57945,6 @@ var init_dist17 = __esm(() => {
|
|
|
58321
57945
|
init_dist13();
|
|
58322
57946
|
init_dist14();
|
|
58323
57947
|
init_dist15();
|
|
58324
|
-
init_dist16();
|
|
58325
57948
|
});
|
|
58326
57949
|
|
|
58327
57950
|
// src/auth/auth-commands.ts
|
|
@@ -58387,7 +58010,7 @@ async function logoutCommand(providerArg) {
|
|
|
58387
58010
|
}
|
|
58388
58011
|
var AUTH_PROVIDERS;
|
|
58389
58012
|
var init_auth_commands = __esm(() => {
|
|
58390
|
-
|
|
58013
|
+
init_dist16();
|
|
58391
58014
|
init_codex_oauth();
|
|
58392
58015
|
init_gemini_oauth();
|
|
58393
58016
|
init_kimi_oauth();
|
|
@@ -58424,7 +58047,7 @@ __export(exports_quota_command, {
|
|
|
58424
58047
|
});
|
|
58425
58048
|
async function quotaCommand(provider) {
|
|
58426
58049
|
if (!provider) {
|
|
58427
|
-
const { select } = await Promise.resolve().then(() => (
|
|
58050
|
+
const { select } = await Promise.resolve().then(() => (init_dist16(), exports_dist));
|
|
58428
58051
|
const choices = QUOTA_ADAPTERS.map((a) => ({
|
|
58429
58052
|
name: `${a.name} \u2014 ${a.isAvailable() ? "logged in" : "not logged in"}`,
|
|
58430
58053
|
value: a
|
|
@@ -59312,8 +58935,8 @@ async function selectModel(options = {}) {
|
|
|
59312
58935
|
pickerProviders = toPickerProviders(await getInteractiveProviderChoices());
|
|
59313
58936
|
}
|
|
59314
58937
|
const loadRemoteModels = async (providerSlug, searchTerm) => {
|
|
59315
|
-
const
|
|
59316
|
-
const cached2 = remoteQueryCache.get(
|
|
58938
|
+
const cacheKey = `${providerSlug || "__all__"}::${searchTerm}`;
|
|
58939
|
+
const cached2 = remoteQueryCache.get(cacheKey);
|
|
59317
58940
|
if (cached2) {
|
|
59318
58941
|
return cached2;
|
|
59319
58942
|
}
|
|
@@ -59326,7 +58949,7 @@ async function selectModel(options = {}) {
|
|
|
59326
58949
|
return [];
|
|
59327
58950
|
}
|
|
59328
58951
|
})();
|
|
59329
|
-
remoteQueryCache.set(
|
|
58952
|
+
remoteQueryCache.set(cacheKey, request);
|
|
59330
58953
|
return request;
|
|
59331
58954
|
};
|
|
59332
58955
|
const ac = new AbortController;
|
|
@@ -59665,7 +59288,7 @@ async function confirmAction(message) {
|
|
|
59665
59288
|
}
|
|
59666
59289
|
var pickerProviderToFirebaseSlug, LOCAL_OR_USER_DEPLOYED, PROVIDER_FILTER_ALIASES, ALL_PROVIDER_CHOICES, PROVIDER_MODEL_PREFIX;
|
|
59667
59290
|
var init_model_selector = __esm(() => {
|
|
59668
|
-
|
|
59291
|
+
init_dist16();
|
|
59669
59292
|
init_authority();
|
|
59670
59293
|
init_model_loader();
|
|
59671
59294
|
init_model_catalog2();
|
|
@@ -63769,6 +63392,10 @@ ${h("OPTIONS")}
|
|
|
63769
63392
|
${green("--profile")} ${yellow("<name>")} Use named profile for model mapping (default profile if omitted)
|
|
63770
63393
|
${green("--default-provider")} ${yellow("<name>")} Fallback provider for bare model names (builtin or customEndpoints key)
|
|
63771
63394
|
${dim("Precedence: this flag > CLAUDISH_DEFAULT_PROVIDER env > config.json")}
|
|
63395
|
+
${green("--config")} ${yellow("<file>")} Use THIS config file for the run, fully replacing the machine
|
|
63396
|
+
${dim("global (~/.claudish/config.json) AND project (.claudish.json).")}
|
|
63397
|
+
${dim("A file naming no op:// source never touches 1Password (no prompt).")}
|
|
63398
|
+
${dim("Env vars still resolve first. Env: CLAUDISH_CONFIG")}
|
|
63772
63399
|
${green("--op")} ${yellow("<op://glob>")} Load API keys from a 1Password item glob (SDK-based, no op CLI)
|
|
63773
63400
|
${green("--op")} ${yellow("<glob>")} ${green("--list")} Preview which fields the glob would import (names only, no values)
|
|
63774
63401
|
${green("--op-env")} ${yellow("<id>")} Load env vars from a 1Password Environment (highest priority)
|
|
@@ -64997,7 +64624,7 @@ ${BOLD3}Examples:${RESET3}
|
|
|
64997
64624
|
}
|
|
64998
64625
|
var RESET3 = "\x1B[0m", BOLD3 = "\x1B[1m", DIM3 = "\x1B[2m", GREEN3 = "\x1B[32m", YELLOW2 = "\x1B[33m", CYAN3 = "\x1B[36m", MAGENTA2 = "\x1B[35m";
|
|
64999
64626
|
var init_profile_commands = __esm(() => {
|
|
65000
|
-
|
|
64627
|
+
init_dist16();
|
|
65001
64628
|
init_model_selector();
|
|
65002
64629
|
init_profile_config();
|
|
65003
64630
|
});
|
|
@@ -70121,8 +69748,8 @@ function App({ requestLogin } = {}) {
|
|
|
70121
69748
|
setOpFieldCursor(0);
|
|
70122
69749
|
setOpFilter("");
|
|
70123
69750
|
setMode("pick_op_field");
|
|
70124
|
-
const
|
|
70125
|
-
const cached2 = opFieldsCache.current.get(
|
|
69751
|
+
const cacheKey = `${vaultId}:${itemId}`;
|
|
69752
|
+
const cached2 = opFieldsCache.current.get(cacheKey);
|
|
70126
69753
|
if (cached2) {
|
|
70127
69754
|
setOpFields(cached2);
|
|
70128
69755
|
setStatusMsg(`1Password: ${cached2.length} field${cached2.length === 1 ? "" : "s"} (cached).`);
|
|
@@ -70134,7 +69761,7 @@ function App({ requestLogin } = {}) {
|
|
|
70134
69761
|
try {
|
|
70135
69762
|
const auth = await acquireOpAuth();
|
|
70136
69763
|
const fields = await withSdkRetry(() => discoverItemFieldsById(vaultId, itemId, vaultTitle, itemTitle, { auth }), "tui:load-fields");
|
|
70137
|
-
opFieldsCache.current.set(
|
|
69764
|
+
opFieldsCache.current.set(cacheKey, fields);
|
|
70138
69765
|
setOpFields(fields);
|
|
70139
69766
|
setStatusMsg(`1Password: ${fields.length} field${fields.length === 1 ? "" : "s"}.`);
|
|
70140
69767
|
} catch (err) {
|
|
@@ -71451,6 +71078,56 @@ var init_tui = __esm(() => {
|
|
|
71451
71078
|
}
|
|
71452
71079
|
});
|
|
71453
71080
|
|
|
71081
|
+
// src/terminal-isolation.ts
|
|
71082
|
+
import { format } from "util";
|
|
71083
|
+
function beginTerminalIsolation(onSuppressed) {
|
|
71084
|
+
if (active)
|
|
71085
|
+
return () => {};
|
|
71086
|
+
active = true;
|
|
71087
|
+
const emit2 = (source, text) => {
|
|
71088
|
+
if (routing)
|
|
71089
|
+
return;
|
|
71090
|
+
routing = true;
|
|
71091
|
+
try {
|
|
71092
|
+
onSuppressed({ source, text });
|
|
71093
|
+
} catch {} finally {
|
|
71094
|
+
routing = false;
|
|
71095
|
+
}
|
|
71096
|
+
};
|
|
71097
|
+
const originalConsole = {};
|
|
71098
|
+
for (const method of CONSOLE_METHODS) {
|
|
71099
|
+
originalConsole[method] = console[method];
|
|
71100
|
+
console[method] = (...args) => {
|
|
71101
|
+
emit2(`console.${method}`, format(...args));
|
|
71102
|
+
};
|
|
71103
|
+
}
|
|
71104
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
71105
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
71106
|
+
const makeWrite = (source) => (chunk, encoding, callback) => {
|
|
71107
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
71108
|
+
emit2(source, typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8"));
|
|
71109
|
+
if (typeof done === "function")
|
|
71110
|
+
done(null);
|
|
71111
|
+
return true;
|
|
71112
|
+
};
|
|
71113
|
+
process.stdout.write = makeWrite("stdout");
|
|
71114
|
+
process.stderr.write = makeWrite("stderr");
|
|
71115
|
+
return function restore() {
|
|
71116
|
+
if (!active)
|
|
71117
|
+
return;
|
|
71118
|
+
for (const method of CONSOLE_METHODS) {
|
|
71119
|
+
console[method] = originalConsole[method];
|
|
71120
|
+
}
|
|
71121
|
+
process.stdout.write = originalStdoutWrite;
|
|
71122
|
+
process.stderr.write = originalStderrWrite;
|
|
71123
|
+
active = false;
|
|
71124
|
+
};
|
|
71125
|
+
}
|
|
71126
|
+
var CONSOLE_METHODS, active = false, routing = false;
|
|
71127
|
+
var init_terminal_isolation = __esm(() => {
|
|
71128
|
+
CONSOLE_METHODS = ["log", "error", "warn", "info", "debug", "trace", "dir"];
|
|
71129
|
+
});
|
|
71130
|
+
|
|
71454
71131
|
// src/claude-runner.ts
|
|
71455
71132
|
var exports_claude_runner = {};
|
|
71456
71133
|
__export(exports_claude_runner, {
|
|
@@ -71474,6 +71151,12 @@ import {
|
|
|
71474
71151
|
import { homedir as homedir24, tmpdir as tmpdir2 } from "os";
|
|
71475
71152
|
import { join as join25 } from "path";
|
|
71476
71153
|
import { isatty } from "tty";
|
|
71154
|
+
function releaseTerminalIsolation() {
|
|
71155
|
+
if (!restoreTerminal)
|
|
71156
|
+
return;
|
|
71157
|
+
restoreTerminal();
|
|
71158
|
+
restoreTerminal = null;
|
|
71159
|
+
}
|
|
71477
71160
|
function hasNativeAnthropicMapping(config3) {
|
|
71478
71161
|
const models = [
|
|
71479
71162
|
config3.model,
|
|
@@ -71832,6 +71515,11 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
71832
71515
|
stdio,
|
|
71833
71516
|
shell: needsShell
|
|
71834
71517
|
});
|
|
71518
|
+
if (config3.interactive) {
|
|
71519
|
+
restoreTerminal = beginTerminalIsolation((entry) => {
|
|
71520
|
+
logStderr(`[Suppressed] ${entry.source}: ${entry.text.trimEnd()}`);
|
|
71521
|
+
});
|
|
71522
|
+
}
|
|
71835
71523
|
if (ttyFd !== undefined) {
|
|
71836
71524
|
const fdToClose = ttyFd;
|
|
71837
71525
|
proc.on("spawn", () => {
|
|
@@ -71847,6 +71535,7 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
71847
71535
|
resolve3(code ?? 1);
|
|
71848
71536
|
});
|
|
71849
71537
|
});
|
|
71538
|
+
releaseTerminalIsolation();
|
|
71850
71539
|
try {
|
|
71851
71540
|
unlinkSync9(tempSettingsPath);
|
|
71852
71541
|
} catch {}
|
|
@@ -71856,6 +71545,7 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
71856
71545
|
const signals2 = isWindows2() ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
71857
71546
|
for (const signal of signals2) {
|
|
71858
71547
|
process.on(signal, () => {
|
|
71548
|
+
releaseTerminalIsolation();
|
|
71859
71549
|
if (!quiet) {
|
|
71860
71550
|
console.error(`
|
|
71861
71551
|
[claudish] Received ${signal}, shutting down...`);
|
|
@@ -71944,12 +71634,15 @@ async function checkClaudeInstalled() {
|
|
|
71944
71634
|
const binary = await findClaudeBinary();
|
|
71945
71635
|
return binary !== null;
|
|
71946
71636
|
}
|
|
71637
|
+
var restoreTerminal = null;
|
|
71947
71638
|
var init_claude_runner = __esm(() => {
|
|
71948
71639
|
init_model_catalog();
|
|
71949
71640
|
init_config();
|
|
71641
|
+
init_logger();
|
|
71950
71642
|
init_model_parser();
|
|
71951
71643
|
init_routing_rules();
|
|
71952
71644
|
init_telemetry();
|
|
71645
|
+
init_terminal_isolation();
|
|
71953
71646
|
});
|
|
71954
71647
|
|
|
71955
71648
|
// src/diag-output.ts
|
|
@@ -72451,8 +72144,8 @@ var init_team_grid = __esm(() => {
|
|
|
72451
72144
|
init_op_source();
|
|
72452
72145
|
init_startup_trace();
|
|
72453
72146
|
var import_dotenv3 = __toESM(require_main(), 1);
|
|
72454
|
-
import { readFileSync as readFileSync23 } from "fs";
|
|
72455
|
-
import { join as join28 } from "path";
|
|
72147
|
+
import { existsSync as existsSync25, readFileSync as readFileSync23 } from "fs";
|
|
72148
|
+
import { join as join28, resolve as resolve3 } from "path";
|
|
72456
72149
|
import_dotenv3.config({ quiet: true });
|
|
72457
72150
|
function classifyStartupKind() {
|
|
72458
72151
|
const argv = process.argv.slice(2);
|
|
@@ -72547,6 +72240,24 @@ async function applyOpImport() {
|
|
|
72547
72240
|
}
|
|
72548
72241
|
process.argv = [...head, ...rebuilt];
|
|
72549
72242
|
}
|
|
72243
|
+
async function applyConfigOverride() {
|
|
72244
|
+
const { planConfigOverride: planConfigOverride2, setConfigFileOverride: setConfigFileOverride2 } = await Promise.resolve().then(() => exports_config_override);
|
|
72245
|
+
const plan = planConfigOverride2(process.argv.slice(2), process.env, {
|
|
72246
|
+
resolve: resolve3,
|
|
72247
|
+
exists: existsSync25
|
|
72248
|
+
});
|
|
72249
|
+
if (plan.kind === "none")
|
|
72250
|
+
return;
|
|
72251
|
+
if (plan.kind === "error") {
|
|
72252
|
+
console.error(plan.message);
|
|
72253
|
+
process.exit(1);
|
|
72254
|
+
}
|
|
72255
|
+
if (plan.fromFlag)
|
|
72256
|
+
process.argv = [...process.argv.slice(0, 2), ...plan.argv];
|
|
72257
|
+
setConfigFileOverride2(plan.path);
|
|
72258
|
+
process.env.CLAUDISH_CONFIG = plan.path;
|
|
72259
|
+
}
|
|
72260
|
+
await traceSpan("startup:config-override", () => applyConfigOverride());
|
|
72550
72261
|
await traceSpan("startup:op-env-flags", () => applyOpEnvironment());
|
|
72551
72262
|
await traceSpan("startup:op-import-flag", () => applyOpImport());
|
|
72552
72263
|
var isMcpMode = process.argv.includes("--mcp");
|
|
@@ -72734,11 +72445,11 @@ Team Status`);
|
|
|
72734
72445
|
You can disable it anytime with: --no-auto-approve
|
|
72735
72446
|
|
|
72736
72447
|
`);
|
|
72737
|
-
const answer = await new Promise((
|
|
72448
|
+
const answer = await new Promise((resolve4) => {
|
|
72738
72449
|
const rl = createInterface2({ input: process.stdin, output: process.stderr });
|
|
72739
72450
|
rl.question("Enable auto-approve? [Y/n] ", (ans) => {
|
|
72740
72451
|
rl.close();
|
|
72741
|
-
|
|
72452
|
+
resolve4(ans.trim().toLowerCase());
|
|
72742
72453
|
});
|
|
72743
72454
|
});
|
|
72744
72455
|
const declined = answer === "n" || answer === "no";
|