claude-codex-proxy 1.0.5-beta.24 → 1.0.5-beta.26
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/package.json +1 -1
- package/src/middleware/sse.js +41 -10
- package/src/utils/logger.js +12 -0
package/package.json
CHANGED
package/src/middleware/sse.js
CHANGED
|
@@ -56,19 +56,47 @@ export function handleStreamError(res, error, model, startTime) {
|
|
|
56
56
|
const loggedModel = typeof model === 'string' && model.toLowerCase().startsWith('claude-')
|
|
57
57
|
? resolveModelRouting(model).upstreamModel
|
|
58
58
|
: model;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
const isStreamError = res.headersSent;
|
|
60
|
+
const logDetails = {
|
|
61
|
+
model: loggedModel,
|
|
62
|
+
transport: isStreamError ? 'sse' : 'http',
|
|
63
|
+
clientHttpStatus: isStreamError ? res.statusCode : status,
|
|
64
|
+
errorType,
|
|
65
|
+
retrySignal: errorType === 'overloaded_error',
|
|
66
|
+
errorName: error?.name,
|
|
67
|
+
errorCode: error?.code,
|
|
68
|
+
upstreamStatus: error?.upstreamStatus,
|
|
69
|
+
isUpstreamError: error?.isUpstreamError === true,
|
|
70
|
+
error: error?.message,
|
|
71
|
+
duration
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (isStreamError) {
|
|
75
|
+
const socketDestroyed = res.destroyed === true || res.socket?.destroyed === true;
|
|
76
|
+
const writableEnded = res.writableEnded === true;
|
|
77
|
+
const sseWriteAttempted = !socketDestroyed && !writableEnded;
|
|
78
|
+
let sseWriteBackpressure = false;
|
|
79
|
+
if (sseWriteAttempted) {
|
|
80
|
+
sseWriteBackpressure = !res.write(
|
|
81
|
+
`event: error\ndata: ${JSON.stringify({
|
|
82
|
+
type: 'error',
|
|
83
|
+
error: { type: errorType, message: getClientErrorMessage(error) }
|
|
84
|
+
})}\n\n`
|
|
85
|
+
);
|
|
86
|
+
res.end();
|
|
87
|
+
}
|
|
88
|
+
logger.response(status, {
|
|
89
|
+
...logDetails,
|
|
90
|
+
sseWriteAttempted,
|
|
91
|
+
sseWriteBackpressure,
|
|
92
|
+
socketDestroyed,
|
|
93
|
+
writableEnded
|
|
94
|
+
});
|
|
69
95
|
return;
|
|
70
96
|
}
|
|
71
97
|
|
|
98
|
+
logger.response(status, logDetails);
|
|
99
|
+
|
|
72
100
|
if (error.message.includes('AUTH_EXPIRED')) {
|
|
73
101
|
return res.status(401).json({
|
|
74
102
|
type: 'error',
|
|
@@ -115,6 +143,9 @@ function getErrorStatus(error) {
|
|
|
115
143
|
}
|
|
116
144
|
|
|
117
145
|
function getAnthropicErrorType(error, status) {
|
|
146
|
+
// Claude Code retries streamed overload errors by their Anthropic error type.
|
|
147
|
+
// HTTP status is already committed after SSE starts, so preserve 5xx semantics here.
|
|
148
|
+
if (status >= 500) return 'overloaded_error';
|
|
118
149
|
if (error?.anthropicErrorType) return error.anthropicErrorType;
|
|
119
150
|
if (status === 401) return 'authentication_error';
|
|
120
151
|
if (status === 429) return 'rate_limit_error';
|
package/src/utils/logger.js
CHANGED
|
@@ -174,6 +174,18 @@ class Logger extends EventEmitter {
|
|
|
174
174
|
if (details.inputTokens !== undefined) parts.push(`input_tokens=${details.inputTokens}`);
|
|
175
175
|
if (details.outputTokens !== undefined) parts.push(`output_tokens=${details.outputTokens}`);
|
|
176
176
|
if (details.cacheReadInputTokens !== undefined) parts.push(`cache_read_input_tokens=${details.cacheReadInputTokens}`);
|
|
177
|
+
if (details.transport) parts.push(`transport=${details.transport}`);
|
|
178
|
+
if (details.clientHttpStatus !== undefined) parts.push(`client_http_status=${details.clientHttpStatus}`);
|
|
179
|
+
if (details.errorType) parts.push(`error_type=${details.errorType}`);
|
|
180
|
+
if (details.retrySignal !== undefined) parts.push(`retry_signal=${details.retrySignal}`);
|
|
181
|
+
if (details.errorName) parts.push(`error_name=${details.errorName}`);
|
|
182
|
+
if (details.errorCode) parts.push(`error_code=${details.errorCode}`);
|
|
183
|
+
if (details.upstreamStatus !== undefined) parts.push(`upstream_status=${details.upstreamStatus}`);
|
|
184
|
+
if (details.isUpstreamError !== undefined) parts.push(`is_upstream_error=${details.isUpstreamError}`);
|
|
185
|
+
if (details.sseWriteAttempted !== undefined) parts.push(`sse_write_attempted=${details.sseWriteAttempted}`);
|
|
186
|
+
if (details.sseWriteBackpressure !== undefined) parts.push(`sse_write_backpressure=${details.sseWriteBackpressure}`);
|
|
187
|
+
if (details.socketDestroyed !== undefined) parts.push(`socket_destroyed=${details.socketDestroyed}`);
|
|
188
|
+
if (details.writableEnded !== undefined) parts.push(`writable_ended=${details.writableEnded}`);
|
|
177
189
|
if (details.duration) parts.push(`${details.duration}ms`);
|
|
178
190
|
if (details.error) parts.push(`error=${details.error}`);
|
|
179
191
|
|