@koalaauto/agentchannel 3.53.1 → 3.53.2
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/src/client.d.ts +8 -0
- package/dist/src/client.js +42 -16
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/client.d.ts
CHANGED
|
@@ -376,6 +376,11 @@ export declare const CLIENT_HEADERS: Record<string, string>;
|
|
|
376
376
|
/** The hub could not be reached at all (no answer, a refused connection, a DNS failure, or no answer within the time limit). */
|
|
377
377
|
export declare class NetworkError extends Error {
|
|
378
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Whether a failed fetch is worth sending again: a passing fault on the way to the hub, not a wrong address
|
|
381
|
+
* (ENOTFOUND, ECONNREFUSED) or a hub that took the request and did not answer in time.
|
|
382
|
+
*/
|
|
383
|
+
export declare function retryable(method: string, e: any): boolean;
|
|
379
384
|
export declare class HubError extends Error {
|
|
380
385
|
status: number;
|
|
381
386
|
code?: string | undefined;
|
|
@@ -401,6 +406,8 @@ export interface ClientOptions {
|
|
|
401
406
|
role?: 'runner';
|
|
402
407
|
/** Called with the newest CLI release the hub names (`x-ach-latest-client`, on every answer, errors included). */
|
|
403
408
|
onLatestClient?: (latest: string) => void;
|
|
409
|
+
/** Waits before each retry of a passing network fault (tests pass short ones). */
|
|
410
|
+
retryDelaysMs?: number[];
|
|
404
411
|
}
|
|
405
412
|
/** Round 2: human-facing CLI text in Chinese when LANG/LC_ALL starts with zh. */
|
|
406
413
|
export declare function isZh(env: NodeJS.ProcessEnv): boolean;
|
|
@@ -420,6 +427,7 @@ export declare class Client {
|
|
|
420
427
|
private cfSecret?;
|
|
421
428
|
private fetchFn;
|
|
422
429
|
constructor(o: ClientOptions);
|
|
430
|
+
private retryDelaysMs;
|
|
423
431
|
private role?;
|
|
424
432
|
/** Set after construction when the listener needs the client first (the runner's updater is built later). */
|
|
425
433
|
onLatestClient?: (latest: string) => void;
|
package/dist/src/client.js
CHANGED
|
@@ -32,6 +32,22 @@ export class NetworkError extends Error {
|
|
|
32
32
|
}
|
|
33
33
|
/** How long an ordinary request waits for the hub (uploads, which may be big, have no limit of their own). */
|
|
34
34
|
const REQUEST_TIMEOUT_MS = 60_000;
|
|
35
|
+
/** Waits before each retry of a request that failed on a passing network fault (about 12 s in all). */
|
|
36
|
+
const RETRY_DELAYS_MS = [1_000, 3_000, 8_000];
|
|
37
|
+
/** Faults while connecting: the request never left this machine, so any method may be sent again. */
|
|
38
|
+
const CONNECT_FAULTS = new Set(['ETIMEDOUT', 'UND_ERR_CONNECT_TIMEOUT', 'EAI_AGAIN', 'ENETUNREACH', 'EHOSTUNREACH']);
|
|
39
|
+
/** Faults after connecting: the hub may have acted on the request, so only a read is sent again. */
|
|
40
|
+
const SOCKET_FAULTS = new Set(['ECONNRESET', 'EPIPE', 'UND_ERR_SOCKET']);
|
|
41
|
+
/**
|
|
42
|
+
* Whether a failed fetch is worth sending again: a passing fault on the way to the hub, not a wrong address
|
|
43
|
+
* (ENOTFOUND, ECONNREFUSED) or a hub that took the request and did not answer in time.
|
|
44
|
+
*/
|
|
45
|
+
export function retryable(method, e) {
|
|
46
|
+
const code = String(e?.cause?.code ?? e?.code ?? '');
|
|
47
|
+
if (CONNECT_FAULTS.has(code))
|
|
48
|
+
return true;
|
|
49
|
+
return (method === 'GET' || method === 'HEAD') && SOCKET_FAULTS.has(code);
|
|
50
|
+
}
|
|
35
51
|
export class HubError extends Error {
|
|
36
52
|
status;
|
|
37
53
|
code;
|
|
@@ -89,7 +105,9 @@ export class Client {
|
|
|
89
105
|
this.ownFetch = !!o.fetch;
|
|
90
106
|
this.role = o.role;
|
|
91
107
|
this.onLatestClient = o.onLatestClient;
|
|
108
|
+
this.retryDelaysMs = o.retryDelaysMs ?? RETRY_DELAYS_MS;
|
|
92
109
|
}
|
|
110
|
+
retryDelaysMs;
|
|
93
111
|
role;
|
|
94
112
|
/** Set after construction when the listener needs the client first (the runner's updater is built later). */
|
|
95
113
|
onLatestClient;
|
|
@@ -132,23 +150,31 @@ export class Client {
|
|
|
132
150
|
({ body, files } = await this.splitAttachments(path, body, files));
|
|
133
151
|
const multipart = !!files?.length;
|
|
134
152
|
let res;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
for (let attempt = 0;; attempt++) {
|
|
154
|
+
try {
|
|
155
|
+
res = await this.fetchFn(url, {
|
|
156
|
+
method,
|
|
157
|
+
headers: this.headers(!multipart),
|
|
158
|
+
body: multipart ? await attachmentForm(body, files) : body === undefined ? undefined : JSON.stringify(body),
|
|
159
|
+
...(multipart ? {} : { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) }),
|
|
160
|
+
});
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
if (attempt < this.retryDelaysMs.length && retryable(method, e)) {
|
|
165
|
+
await new Promise((r) => setTimeout(r, this.retryDelaysMs[attempt]));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const host = (() => { try {
|
|
169
|
+
return new URL(url).host;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return url;
|
|
173
|
+
} })();
|
|
174
|
+
const why = e?.name === 'TimeoutError' ? `no answer within ${REQUEST_TIMEOUT_MS / 1000} s` : String(e?.cause?.code ?? e?.cause?.message ?? e?.message ?? e);
|
|
175
|
+
const tries = attempt > 0 ? `, ${attempt + 1} tries` : '';
|
|
176
|
+
throw new NetworkError(`cannot reach ${host} (${why}${tries}): check the hub address, your network, and whether a VPN or proxy is in the way. \`ach doctor\` checks each step.`);
|
|
146
177
|
}
|
|
147
|
-
catch {
|
|
148
|
-
return url;
|
|
149
|
-
} })();
|
|
150
|
-
const why = e?.name === 'TimeoutError' ? `no answer within ${REQUEST_TIMEOUT_MS / 1000} s` : String(e?.cause?.code ?? e?.cause?.message ?? e?.message ?? e);
|
|
151
|
-
throw new NetworkError(`cannot reach ${host} (${why}): check the hub address, your network, and whether a VPN or proxy is in the way. \`ach doctor\` checks each step.`);
|
|
152
178
|
}
|
|
153
179
|
// Cloudflare Access in front of the hub answers with its login page (a redirect followed to *.cloudflareaccess.com,
|
|
154
180
|
// or a challenge header) instead of the hub's JSON: say so, instead of failing later on a missing field
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.53.
|
|
3
|
+
"version": "3.53.2",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|