@cohortapp/agent-sdk 2.18.33 → 2.18.34
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/lib/org/client.mjs +48 -5
- package/package.json +1 -1
package/lib/org/client.mjs
CHANGED
|
@@ -181,16 +181,38 @@ function baseHeaders(token, orgId) {
|
|
|
181
181
|
*/
|
|
182
182
|
async function httpRequest(fetchImpl, url, init, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
183
183
|
const f = pickFetch(fetchImpl);
|
|
184
|
-
if (!f) return { ok: false, status: 0, body: null };
|
|
184
|
+
if (!f) return { ok: false, status: 0, body: null, failure: "no-fetch" };
|
|
185
185
|
const ctrl = typeof AbortController === "function" ? new AbortController() : null;
|
|
186
|
-
|
|
186
|
+
let timedOut = false;
|
|
187
|
+
const timer = ctrl ? setTimeout(() => { timedOut = true; ctrl.abort(); }, timeoutMs) : null;
|
|
187
188
|
try {
|
|
188
189
|
const res = await f(url, { ...init, signal: ctrl ? ctrl.signal : undefined });
|
|
189
190
|
let body = null;
|
|
190
191
|
try { body = await res.json(); } catch { body = null; }
|
|
191
192
|
return { ok: !!res.ok, status: typeof res.status === "number" ? res.status : 0, body };
|
|
192
|
-
} catch {
|
|
193
|
-
|
|
193
|
+
} catch (err) {
|
|
194
|
+
// A TIMEOUT AND A BROKEN SOCKET ARE NOT THE SAME FACT, AND THIS DISCARDED BOTH.
|
|
195
|
+
//
|
|
196
|
+
// `catch { }` returned a bare `status: 0`, which `asResFrame` renders as
|
|
197
|
+
// "http 0". A seat then sees "http 0" and cannot tell an abort from a DNS
|
|
198
|
+
// failure, a reset, or a missing origin — so the one piece of information
|
|
199
|
+
// that names the cause was thrown away at the only place that had it.
|
|
200
|
+
//
|
|
201
|
+
// Measured consequence: a seat's `messaging.history` returned at `limit: 3`
|
|
202
|
+
// and failed with "http 0" at normal page sizes, which reads as a transport
|
|
203
|
+
// or payload fault. It is neither — it is this 8s abort firing on a slower
|
|
204
|
+
// query, and the seat missed two hours of inbound while diagnosing the wrong
|
|
205
|
+
// layer. Its sends were landing the whole time, so it looked healthy.
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
status: 0,
|
|
209
|
+
body: null,
|
|
210
|
+
failure: timedOut ? "timeout" : "transport",
|
|
211
|
+
timeoutMs: timedOut ? timeoutMs : undefined,
|
|
212
|
+
// `code` before `name`: ENOTFOUND/ECONNRESET identify the fault, while
|
|
213
|
+
// `name` is almost always the useless "Error".
|
|
214
|
+
cause: (err && (err.code || err.name)) || "unknown",
|
|
215
|
+
};
|
|
194
216
|
} finally {
|
|
195
217
|
if (timer) clearTimeout(timer);
|
|
196
218
|
}
|
|
@@ -220,6 +242,19 @@ function asResFrame(r) {
|
|
|
220
242
|
const b = r.body;
|
|
221
243
|
if (b && typeof b === "object" && typeof b.ok === "boolean") return b; // already a frame
|
|
222
244
|
if (r.ok) return okFrame(b);
|
|
245
|
+
if (r && r.status === 0 && r.failure === "timeout") {
|
|
246
|
+
// Named, with the budget, so the reader knows what to change.
|
|
247
|
+
// INTERNAL, not a new "TIMEOUT" code, deliberately. ERROR_CODES is the
|
|
248
|
+
// SHARED wire vocabulary (each entry carries an http mapping, so hq reads it
|
|
249
|
+
// too) and errFrame silently degrades an unknown code to INTERNAL — so
|
|
250
|
+
// writing "TIMEOUT" here would have looked like a new code and quietly been
|
|
251
|
+
// INTERNAL anyway, which is the same class of lie this whole change removes.
|
|
252
|
+
// The cause goes in the MESSAGE, which is what a person actually reads.
|
|
253
|
+
return errFrame("INTERNAL", `request timed out after ${r.timeoutMs}ms before any HTTP status — raise timeoutMs for this call, or ask for fewer rows`);
|
|
254
|
+
}
|
|
255
|
+
if (r && r.status === 0 && r.failure) {
|
|
256
|
+
return errFrame("INTERNAL", `transport failed before any HTTP status (${r.cause}) — not an HTTP error`);
|
|
257
|
+
}
|
|
223
258
|
return errFrame(httpStatusToCode(r.status), `http ${r.status}`);
|
|
224
259
|
}
|
|
225
260
|
|
|
@@ -333,11 +368,19 @@ export async function call(method, params, o = {}) {
|
|
|
333
368
|
: "");
|
|
334
369
|
if (key) headers["x-idempotency-key"] = String(key);
|
|
335
370
|
}
|
|
371
|
+
// THE POST PATH HAD NO TUNABLE TIMEOUT WHILE THE GET PATH DID.
|
|
372
|
+
//
|
|
373
|
+
// This called httpRequest with no fourth argument, so every RPC — including a
|
|
374
|
+
// history read over a busy channel — sat under the same hard 8s ceiling with no
|
|
375
|
+
// way for a caller to ask for more, even though the read helper below already
|
|
376
|
+
// honours `o.timeoutMs`. That asymmetry is the defect; the default is unchanged
|
|
377
|
+
// so nothing moves for callers that do not ask.
|
|
378
|
+
const callTimeoutMs = Number.isFinite(o.timeoutMs) && o.timeoutMs > 0 ? o.timeoutMs : DEFAULT_TIMEOUT_MS;
|
|
336
379
|
const r = await httpRequest(o.fetchImpl, v1Url(base, method), {
|
|
337
380
|
method: "POST",
|
|
338
381
|
headers,
|
|
339
382
|
body: JSON.stringify(wire),
|
|
340
|
-
});
|
|
383
|
+
}, callTimeoutMs);
|
|
341
384
|
return asResFrame(r);
|
|
342
385
|
}
|
|
343
386
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohortapp/agent-sdk",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.34",
|
|
4
4
|
"description": "Cohort Agent SDK — autonomous AI colleague runtime. Deploy senior AI colleagues on dedicated Mac minis, wired to the Cohort operating surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|