@bman654/clodex 2.1.0 → 2.1.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/cli.js +45 -14
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -211,7 +211,7 @@ import { join } from "path";
|
|
|
211
211
|
// package.json
|
|
212
212
|
var package_default = {
|
|
213
213
|
name: "@bman654/clodex",
|
|
214
|
-
version: "2.1.
|
|
214
|
+
version: "2.1.1",
|
|
215
215
|
publishConfig: {
|
|
216
216
|
access: "public"
|
|
217
217
|
},
|
|
@@ -2537,6 +2537,12 @@ function numericRetryAfterSeconds(inner) {
|
|
|
2537
2537
|
}
|
|
2538
2538
|
return void 0;
|
|
2539
2539
|
}
|
|
2540
|
+
function boundedTransportCode(data) {
|
|
2541
|
+
if (!data || typeof data !== "object") return void 0;
|
|
2542
|
+
const error = data.error;
|
|
2543
|
+
if (!error || typeof error !== "object") return void 0;
|
|
2544
|
+
return error.code === "websocket_transport_error" ? "websocket_transport_error" : void 0;
|
|
2545
|
+
}
|
|
2540
2546
|
function sdkUpstreamErrorDetails(err) {
|
|
2541
2547
|
const retry = RetryError.isInstance(err) ? err : void 0;
|
|
2542
2548
|
const inner = retry?.lastError ?? err;
|
|
@@ -2555,7 +2561,8 @@ function sdkUpstreamErrorDetails(err) {
|
|
|
2555
2561
|
errorContent: errorContent || inner.message,
|
|
2556
2562
|
isRetryable: inner.isRetryable,
|
|
2557
2563
|
attemptCount: retry?.errors.length ?? 1,
|
|
2558
|
-
...retryAfterSeconds !== void 0 ? { retryAfterSeconds } : {}
|
|
2564
|
+
...retryAfterSeconds !== void 0 ? { retryAfterSeconds } : {},
|
|
2565
|
+
transportCode: boundedTransportCode(inner.data)
|
|
2559
2566
|
};
|
|
2560
2567
|
}
|
|
2561
2568
|
function isContextLengthExceededError(err, formattedMessage = "") {
|
|
@@ -5080,7 +5087,9 @@ function writeInferenceResponseLifecycleLog(path, entry) {
|
|
|
5080
5087
|
...cacheReadInputTokens !== void 0 ? { cacheReadInputTokens } : {},
|
|
5081
5088
|
...entry.lastPartType ? { lastPartType: compactLogValue(entry.lastPartType, 100) } : {},
|
|
5082
5089
|
...entry.errorType ? { errorType: compactLogValue(entry.errorType, 200) } : {},
|
|
5090
|
+
...entry.errorCode ? { errorCode: compactLogValue(entry.errorCode, 100) } : {},
|
|
5083
5091
|
...entry.errorSignature ? { errorSignature: compactLogValue(entry.errorSignature, 100) } : {},
|
|
5092
|
+
...entry.failureSource ? { failureSource: entry.failureSource } : {},
|
|
5084
5093
|
...entry.terminationSource ? { terminationSource: entry.terminationSource } : {}
|
|
5085
5094
|
}));
|
|
5086
5095
|
}
|
|
@@ -8748,11 +8757,16 @@ function createTranslationLifecycle(logPath, requestId, claudeSessionId, modelId
|
|
|
8748
8757
|
clearInterval(timer);
|
|
8749
8758
|
write("translation_cancelled", snapshot(Date.now()));
|
|
8750
8759
|
},
|
|
8751
|
-
fail(errorType, errorSignature) {
|
|
8760
|
+
fail(errorType, errorSignature, errorCode) {
|
|
8752
8761
|
if (stopped) return;
|
|
8753
8762
|
stopped = true;
|
|
8754
8763
|
clearInterval(timer);
|
|
8755
|
-
write("translation_failed", {
|
|
8764
|
+
write("translation_failed", {
|
|
8765
|
+
...snapshot(Date.now()),
|
|
8766
|
+
errorType,
|
|
8767
|
+
errorSignature,
|
|
8768
|
+
errorCode
|
|
8769
|
+
});
|
|
8756
8770
|
}
|
|
8757
8771
|
};
|
|
8758
8772
|
}
|
|
@@ -9139,7 +9153,8 @@ async function startProxyCatalog(routes, defaultAliasId, debug = false, inferenc
|
|
|
9139
9153
|
}
|
|
9140
9154
|
translationLifecycle?.fail(
|
|
9141
9155
|
err instanceof Error ? err.name : "UpstreamError",
|
|
9142
|
-
sdkTranslationErrorSignature(err)
|
|
9156
|
+
sdkTranslationErrorSignature(err),
|
|
9157
|
+
details?.transportCode
|
|
9143
9158
|
);
|
|
9144
9159
|
const contextLengthExceeded = upstreamStatus === 400 && isContextLengthExceededError(err, message);
|
|
9145
9160
|
const clientMessage = contextLengthExceeded ? anthropicPromptTooLongMessage(
|
|
@@ -10697,7 +10712,7 @@ function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorize
|
|
|
10697
10712
|
upstream.end(rawBody);
|
|
10698
10713
|
});
|
|
10699
10714
|
}
|
|
10700
|
-
function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown = () => false) {
|
|
10715
|
+
function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http.request, lifecycle, isLocalShutdown = () => false) {
|
|
10701
10716
|
return new Promise((resolve2) => {
|
|
10702
10717
|
const startedAt = Date.now();
|
|
10703
10718
|
let lastActivityAt = startedAt;
|
|
@@ -10775,7 +10790,7 @@ function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown
|
|
|
10775
10790
|
upstream?.destroy(new Error("Client disconnected"));
|
|
10776
10791
|
resolve2();
|
|
10777
10792
|
});
|
|
10778
|
-
const failAdapterRequest = (err) => {
|
|
10793
|
+
const failAdapterRequest = (err, failureSource) => {
|
|
10779
10794
|
if (clientDisconnected) {
|
|
10780
10795
|
resolve2();
|
|
10781
10796
|
return;
|
|
@@ -10792,13 +10807,15 @@ function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown
|
|
|
10792
10807
|
bytes,
|
|
10793
10808
|
chunks,
|
|
10794
10809
|
errorType: err.name,
|
|
10810
|
+
errorCode: err.code,
|
|
10811
|
+
failureSource,
|
|
10795
10812
|
terminationSource: "upstream_failure"
|
|
10796
10813
|
});
|
|
10797
10814
|
if (!res.headersSent) res.writeHead(502, { "Content-Type": "text/plain" });
|
|
10798
10815
|
res.end(`Relay adapter unreachable: ${err.message}`);
|
|
10799
10816
|
resolve2();
|
|
10800
10817
|
};
|
|
10801
|
-
upstream =
|
|
10818
|
+
upstream = adapterRequest({
|
|
10802
10819
|
hostname: "127.0.0.1",
|
|
10803
10820
|
port: adapter.port,
|
|
10804
10821
|
method: "POST",
|
|
@@ -10830,7 +10847,7 @@ function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown
|
|
|
10830
10847
|
chunks += 1;
|
|
10831
10848
|
});
|
|
10832
10849
|
copyResponse(upstreamRes, res, void 0, lifecycle ? (usage) => writeLifecycle("response_usage", usage) : void 0);
|
|
10833
|
-
const failAdapterResponse = (err) => {
|
|
10850
|
+
const failAdapterResponse = (err, failureSource) => {
|
|
10834
10851
|
if (clientDisconnected) {
|
|
10835
10852
|
resolve2();
|
|
10836
10853
|
return;
|
|
@@ -10848,6 +10865,8 @@ function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown
|
|
|
10848
10865
|
bytes,
|
|
10849
10866
|
chunks,
|
|
10850
10867
|
errorType: err.name,
|
|
10868
|
+
errorCode: err.code,
|
|
10869
|
+
failureSource,
|
|
10851
10870
|
terminationSource: "upstream_failure"
|
|
10852
10871
|
});
|
|
10853
10872
|
if (!res.writableEnded) res.destroy(err);
|
|
@@ -10858,16 +10877,27 @@ function forwardToAdapter(req, res, rawBody, adapter, lifecycle, isLocalShutdown
|
|
|
10858
10877
|
lastActivityAt = Date.now();
|
|
10859
10878
|
resolve2();
|
|
10860
10879
|
});
|
|
10861
|
-
upstreamRes.once("error", failAdapterResponse);
|
|
10862
|
-
upstreamRes.once("aborted", () => failAdapterResponse(
|
|
10880
|
+
upstreamRes.once("error", (err) => failAdapterResponse(err, "adapter_response_error"));
|
|
10881
|
+
upstreamRes.once("aborted", () => failAdapterResponse(
|
|
10882
|
+
new Error("Relay adapter response aborted"),
|
|
10883
|
+
"adapter_response_aborted"
|
|
10884
|
+
));
|
|
10863
10885
|
upstreamRes.once("close", () => {
|
|
10864
|
-
if (!upstreamRes.complete)
|
|
10886
|
+
if (!upstreamRes.complete) {
|
|
10887
|
+
failAdapterResponse(
|
|
10888
|
+
new Error("Relay adapter response closed before completion"),
|
|
10889
|
+
"adapter_response_close"
|
|
10890
|
+
);
|
|
10891
|
+
}
|
|
10865
10892
|
});
|
|
10866
10893
|
});
|
|
10867
|
-
upstream.once("error", failAdapterRequest);
|
|
10894
|
+
upstream.once("error", (err) => failAdapterRequest(err, "adapter_request_error"));
|
|
10868
10895
|
upstream.once("close", () => {
|
|
10869
10896
|
if (!headersReceived && !failed) {
|
|
10870
|
-
failAdapterRequest(
|
|
10897
|
+
failAdapterRequest(
|
|
10898
|
+
new Error("Relay adapter connection closed before a response"),
|
|
10899
|
+
"adapter_request_close"
|
|
10900
|
+
);
|
|
10871
10901
|
}
|
|
10872
10902
|
});
|
|
10873
10903
|
upstream.end(rawBody);
|
|
@@ -11019,6 +11049,7 @@ async function startHttpProxy(options) {
|
|
|
11019
11049
|
res,
|
|
11020
11050
|
adapterBody,
|
|
11021
11051
|
adapter,
|
|
11052
|
+
options.adapterRequest,
|
|
11022
11053
|
messagesEndpoint === "messages" && options.inferenceLogPath ? {
|
|
11023
11054
|
logPath: options.inferenceLogPath,
|
|
11024
11055
|
requestId,
|