talentos 1.4.4 → 1.4.5
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/agent/adapters.js +45 -14
- package/dist/agent/codex-policy.js +1 -0
- package/dist/agent/lease-hold.js +22 -0
- package/dist/agent/provider-failure.js +64 -0
- package/dist/agent/serve.js +70 -13
- package/dist/client.js +45 -4
- package/dist/commands/skills.js +8 -0
- package/dist/mcp-proxy.js +1 -5
- package/dist/upload-file.js +36 -14
- package/package.json +1 -1
package/dist/agent/adapters.js
CHANGED
|
@@ -14,6 +14,7 @@ import { CodexBoundaryError, probeCodexBoundary } from "./codex-probe.js";
|
|
|
14
14
|
import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
|
|
15
15
|
import { prepareOwnerLaunch } from "./native/launch.js";
|
|
16
16
|
import { readReceipts } from "./native/receipts.js";
|
|
17
|
+
import { classifyProviderFailure, matchFailureText, ProviderFailureError, } from "./provider-failure.js";
|
|
17
18
|
const CHILD_ENV = [
|
|
18
19
|
"HOME",
|
|
19
20
|
"PATH",
|
|
@@ -145,9 +146,9 @@ async function codexRoomCatalog(binary) {
|
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
/** Codex could not start its room tools, so the job fails with that reason. */
|
|
148
|
-
export class RoomToolsUnavailableError extends
|
|
149
|
+
export class RoomToolsUnavailableError extends ProviderFailureError {
|
|
149
150
|
constructor() {
|
|
150
|
-
super("Codex couldn't reach its room tools. Try again.");
|
|
151
|
+
super("room_tools", "Codex couldn't reach its room tools. Try again.");
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
export function readProviderEvent(provider, value) {
|
|
@@ -158,7 +159,10 @@ export function readProviderEvent(provider, value) {
|
|
|
158
159
|
if (provider === "claude_code") {
|
|
159
160
|
if (event.type === "result") {
|
|
160
161
|
if (event.is_error) {
|
|
161
|
-
return {
|
|
162
|
+
return {
|
|
163
|
+
failed: true,
|
|
164
|
+
failure: matchFailureText([event.result, event.api_error_status].join(" ")),
|
|
165
|
+
};
|
|
162
166
|
}
|
|
163
167
|
return {
|
|
164
168
|
...(typeof event.session_id === "string"
|
|
@@ -168,6 +172,10 @@ export function readProviderEvent(provider, value) {
|
|
|
168
172
|
};
|
|
169
173
|
}
|
|
170
174
|
const message = event.message;
|
|
175
|
+
// Claude Code tags an assistant turn it could not get from the API.
|
|
176
|
+
if (event.type === "assistant" && typeof event.error === "string") {
|
|
177
|
+
return { failure: matchFailureText(event.error) };
|
|
178
|
+
}
|
|
171
179
|
if (event.type === "assistant" &&
|
|
172
180
|
Array.isArray(message?.content) &&
|
|
173
181
|
message.content.some((part) => part.type === "tool_use")) {
|
|
@@ -180,7 +188,12 @@ export function readProviderEvent(provider, value) {
|
|
|
180
188
|
return { sessionId: event.thread_id };
|
|
181
189
|
}
|
|
182
190
|
if (event.type === "turn.failed" || event.type === "error") {
|
|
183
|
-
|
|
191
|
+
const error = event.error;
|
|
192
|
+
const text = error?.message ?? event.message;
|
|
193
|
+
return {
|
|
194
|
+
failed: true,
|
|
195
|
+
failure: typeof text === "string" ? matchFailureText(text) : undefined,
|
|
196
|
+
};
|
|
184
197
|
}
|
|
185
198
|
const item = event.item;
|
|
186
199
|
if (event.type === "item.completed" &&
|
|
@@ -311,8 +324,9 @@ export async function runProvider(input) {
|
|
|
311
324
|
.join(delimiter),
|
|
312
325
|
}
|
|
313
326
|
: childEnvironment(process.env, binary),
|
|
314
|
-
//
|
|
315
|
-
|
|
327
|
+
// stderr is matched to name a failure, never forwarded: it can hold login
|
|
328
|
+
// details.
|
|
329
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
316
330
|
detached: process.platform !== "win32",
|
|
317
331
|
});
|
|
318
332
|
const marked = new Set();
|
|
@@ -323,7 +337,7 @@ export async function runProvider(input) {
|
|
|
323
337
|
}
|
|
324
338
|
};
|
|
325
339
|
child.once("spawn", () => mark("spawn"));
|
|
326
|
-
// The last 8 kB is enough for
|
|
340
|
+
// The last 8 kB is enough for a provider's closing error line.
|
|
327
341
|
let stderrTail = "";
|
|
328
342
|
child.stderr?.on("data", (chunk) => {
|
|
329
343
|
stderrTail = (stderrTail + chunk.toString()).slice(-8192);
|
|
@@ -350,16 +364,20 @@ export async function runProvider(input) {
|
|
|
350
364
|
kill("SIGTERM");
|
|
351
365
|
killTimer ??= setTimeout(() => kill("SIGKILL"), 5000);
|
|
352
366
|
};
|
|
367
|
+
let spawnError;
|
|
353
368
|
const ended = new Promise((resolve) => {
|
|
354
|
-
child.once("error", () =>
|
|
355
|
-
|
|
369
|
+
child.once("error", (error) => {
|
|
370
|
+
spawnError = error.code;
|
|
371
|
+
resolve({ code: null, signal: null });
|
|
372
|
+
});
|
|
373
|
+
child.once("close", (code, signal) => resolve({ code, signal }));
|
|
356
374
|
});
|
|
357
375
|
signal.addEventListener("abort", stop, { once: true });
|
|
358
376
|
if (signal.aborted) {
|
|
359
377
|
stop();
|
|
360
378
|
}
|
|
361
379
|
try {
|
|
362
|
-
let text = "", failed = false, sawResult = false;
|
|
380
|
+
let text = "", failure, failed = false, sawResult = false;
|
|
363
381
|
if (!child.stdout) {
|
|
364
382
|
throw new Error("Provider output is unavailable.");
|
|
365
383
|
}
|
|
@@ -383,6 +401,10 @@ export async function runProvider(input) {
|
|
|
383
401
|
if (event.failed) {
|
|
384
402
|
failed = true;
|
|
385
403
|
}
|
|
404
|
+
// Sign-in outranks a limit when the provider reported both.
|
|
405
|
+
if (event.failure && failure !== "signed_out") {
|
|
406
|
+
failure = event.failure;
|
|
407
|
+
}
|
|
386
408
|
if (event.sessionId) {
|
|
387
409
|
await input.remember(event.sessionId);
|
|
388
410
|
}
|
|
@@ -398,12 +420,21 @@ export async function runProvider(input) {
|
|
|
398
420
|
sawResult = true;
|
|
399
421
|
}
|
|
400
422
|
}
|
|
401
|
-
const
|
|
402
|
-
if (code !== 0 &&
|
|
423
|
+
const exit = await ended;
|
|
424
|
+
if (exit.code !== 0 &&
|
|
425
|
+
!signal.aborted &&
|
|
426
|
+
ROOM_SERVER_FAILED.test(stderrTail)) {
|
|
403
427
|
throw new RoomToolsUnavailableError();
|
|
404
428
|
}
|
|
405
|
-
if (code !== 0 || failed || !sawResult || signal.aborted) {
|
|
406
|
-
throw new
|
|
429
|
+
if (exit.code !== 0 || failed || !sawResult || signal.aborted) {
|
|
430
|
+
throw new ProviderFailureError(signal.aborted
|
|
431
|
+
? "unknown"
|
|
432
|
+
: classifyProviderFailure({
|
|
433
|
+
...exit,
|
|
434
|
+
eventHint: failure,
|
|
435
|
+
spawnError,
|
|
436
|
+
stderrTail,
|
|
437
|
+
}), "Provider could not finish this turn. Check its login and quota.");
|
|
407
438
|
}
|
|
408
439
|
return { text: redactAgentOutput(text, [config.apiKey]) };
|
|
409
440
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// How long the CLI keeps a provider running while the server cannot be reached
|
|
2
|
+
// (a Convex push took the gateway away for 76 s and 78 s on staging,
|
|
3
|
+
// 2026-10-21). The server honours a lapsed lease for its own grace, then puts
|
|
4
|
+
// the job back in the queue and hands the same computer its own claim back at
|
|
5
|
+
// once, so a quiet gateway alone never costs the agent its job.
|
|
6
|
+
//
|
|
7
|
+
// Only the server's word ends a job early: a 409 on a renewal means another
|
|
8
|
+
// claim holds it. This is the backstop for a gateway that never comes back.
|
|
9
|
+
const SERVER_GRACE_MS = 150_000; // convex/externalAgents/jobLease.model.ts
|
|
10
|
+
const NATIVE_LEASE_MS = 30_000;
|
|
11
|
+
const ROOM_ONLY_HOLD_MS = 15 * 60_000;
|
|
12
|
+
// An owner job runs the owner's real setup on their computer, so it fails
|
|
13
|
+
// closed once the server has stopped counting it: after lease plus grace.
|
|
14
|
+
const NATIVE_HOLD_MS = NATIVE_LEASE_MS + SERVER_GRACE_MS - 5000;
|
|
15
|
+
export function holdMs(native) {
|
|
16
|
+
return native ? NATIVE_HOLD_MS : ROOM_ONLY_HOLD_MS;
|
|
17
|
+
}
|
|
18
|
+
// A missed renewal is retried every few seconds, not at the next 20 s beat.
|
|
19
|
+
const RETRY_MS = 3000;
|
|
20
|
+
export function renewDelayMs(beatMs, failedRenewals) {
|
|
21
|
+
return failedRenewals > 0 ? Math.min(beatMs, RETRY_MS) : beatMs;
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ProviderBinaryError } from "../provider-binary.js";
|
|
2
|
+
/**
|
|
3
|
+
* Why a provider (claude / codex) turn failed, read from what its process left
|
|
4
|
+
* behind. Only the enum leaves this computer: stderr and the provider's own
|
|
5
|
+
* error text can hold login details, so they are matched here and dropped.
|
|
6
|
+
* The server stores the value as fixed text (convex/externalAgents/jobs.ts
|
|
7
|
+
* failJob); `unknown` is the generic failure an old CLI always sent.
|
|
8
|
+
*/
|
|
9
|
+
export const PROVIDER_FAILURE_REASONS = [
|
|
10
|
+
"signed_out",
|
|
11
|
+
"usage_limit",
|
|
12
|
+
"missing_binary",
|
|
13
|
+
"crashed",
|
|
14
|
+
"unknown",
|
|
15
|
+
];
|
|
16
|
+
const SIGNED_OUT = /invalid api key|run \/login|codex login|not logged in|not signed in|log(?:ged)? in again|unauthori[sz]ed|(?:status|http|error|code)[ :]+401\b|authentication[_ ](?:failed|error)|oauth token (?:has )?expired|token[_ ](?:has )?expired|refresh token/iu;
|
|
17
|
+
const USAGE_LIMIT = /usage limit|hit your limit|limit reached|rate[_ ]limit|(?:status|http|error|code)[ :]+429\b|credit balance|quota|billing[_ ]error|out of credits|insufficient[_ ]credit/iu;
|
|
18
|
+
const CRASHED = /\bpanicked\b|segmentation fault|fatal error|out of memory|uncaught exception|^\s+at .+\(.+:\d+:\d+\)$/imu;
|
|
19
|
+
// 126 is "found but not executable"; 127 is the shell's "command not found".
|
|
20
|
+
const NOT_STARTED = new Set(["ENOENT", "EACCES", "ENOTDIR"]);
|
|
21
|
+
/**
|
|
22
|
+
* What a provider's own words say went wrong. The text is read here and
|
|
23
|
+
* dropped, so a caller holds a label, never the words.
|
|
24
|
+
*/
|
|
25
|
+
export function matchFailureText(text) {
|
|
26
|
+
if (SIGNED_OUT.test(text)) {
|
|
27
|
+
return "signed_out";
|
|
28
|
+
}
|
|
29
|
+
return USAGE_LIMIT.test(text) ? "usage_limit" : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Sign-in first: an expired login often prints a limit-looking line too. */
|
|
32
|
+
export function classifyProviderFailure(exit) {
|
|
33
|
+
if ((exit.spawnError && NOT_STARTED.has(exit.spawnError)) ||
|
|
34
|
+
exit.code === 126 ||
|
|
35
|
+
exit.code === 127) {
|
|
36
|
+
return "missing_binary";
|
|
37
|
+
}
|
|
38
|
+
const hints = [exit.eventHint, matchFailureText(exit.stderrTail)];
|
|
39
|
+
if (hints.includes("signed_out")) {
|
|
40
|
+
return "signed_out";
|
|
41
|
+
}
|
|
42
|
+
if (hints.includes("usage_limit")) {
|
|
43
|
+
return "usage_limit";
|
|
44
|
+
}
|
|
45
|
+
if (exit.signal || CRASHED.test(exit.stderrTail)) {
|
|
46
|
+
return "crashed";
|
|
47
|
+
}
|
|
48
|
+
return "unknown";
|
|
49
|
+
}
|
|
50
|
+
/** A failed provider turn, carrying the one reason the server is told. */
|
|
51
|
+
export class ProviderFailureError extends Error {
|
|
52
|
+
reason;
|
|
53
|
+
constructor(reason, message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.reason = reason;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The reason to send for a job that threw; absent keeps the generic failure. */
|
|
59
|
+
export function failureReasonOf(error) {
|
|
60
|
+
if (error instanceof ProviderFailureError) {
|
|
61
|
+
return error.reason;
|
|
62
|
+
}
|
|
63
|
+
return error instanceof ProviderBinaryError ? "missing_binary" : undefined;
|
|
64
|
+
}
|
package/dist/agent/serve.js
CHANGED
|
@@ -7,17 +7,19 @@ import { compareGatewayVersions } from "../gateway-version.js";
|
|
|
7
7
|
import { homeDir } from "../install.js";
|
|
8
8
|
import { RoomToolsUnavailableError, runProvider, } from "./adapters.js";
|
|
9
9
|
import { AgentGateway, GatewayError } from "./gateway.js";
|
|
10
|
+
import { holdMs, renewDelayMs } from "./lease-hold.js";
|
|
10
11
|
import { ApprovalBridge } from "./native/approvals.js";
|
|
11
12
|
import { NativeGate } from "./native/gate.js";
|
|
12
13
|
import { ROOM_ONLY_STATUS } from "./native/native-issue.js";
|
|
13
14
|
import { ProjectRequests } from "./native/project-requests.js";
|
|
14
15
|
import { mirrorOf } from "./native/projects.js";
|
|
16
|
+
import { failureReasonOf } from "./provider-failure.js";
|
|
15
17
|
import { SessionMap } from "./sessions.js";
|
|
16
18
|
const HEARTBEAT_MS = 20_000;
|
|
17
|
-
const LEASE_SAFETY_MS = 55_000;
|
|
18
19
|
// A native job holds a 30 s server lease and is re-derived on every renewal.
|
|
19
20
|
const NATIVE_RENEW_MS = 10_000;
|
|
20
|
-
|
|
21
|
+
// A launch waits this long for the server before it starts the provider anyway.
|
|
22
|
+
const START_WAIT_MS = 120_000;
|
|
21
23
|
const IDLE_MS = 30 * 60_000;
|
|
22
24
|
// The room-only reason stays up this long before progress lines resume.
|
|
23
25
|
const FALLBACK_HOLD_MS = 5000;
|
|
@@ -135,6 +137,40 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
135
137
|
post: (path, body) => gateway.request(path, body, signal),
|
|
136
138
|
})
|
|
137
139
|
: undefined;
|
|
140
|
+
const beat = (native) => options.lease?.beatMs ?? (native ? NATIVE_RENEW_MS : HEARTBEAT_MS);
|
|
141
|
+
const holdFor = (native) => options.lease?.holdMs ?? holdMs(native);
|
|
142
|
+
let failedRenewals = 0;
|
|
143
|
+
// The server is away: a 5xx or no answer at all, as during a Convex push.
|
|
144
|
+
const serverAway = (error) => !(error instanceof GatewayError) || error.status >= 500;
|
|
145
|
+
// A claim can land just before a push; the provider's room tools are
|
|
146
|
+
// listed once at its start, so wait for the server before launching it.
|
|
147
|
+
const waitForServer = async (job, cancel) => {
|
|
148
|
+
const until = Date.now() + (options.lease?.startWaitMs ?? START_WAIT_MS);
|
|
149
|
+
const step = options.lease?.stepMs ?? 1000;
|
|
150
|
+
for (let wait = step; !signal.aborted; wait = Math.min(wait * 2, step * 10)) {
|
|
151
|
+
try {
|
|
152
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/renew`, { leaseToken: job.leaseToken }, signal);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (error instanceof GatewayError && error.status === 409) {
|
|
157
|
+
cancel.abort();
|
|
158
|
+
}
|
|
159
|
+
failService(error);
|
|
160
|
+
if (!serverAway(error) || Date.now() >= until) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await delay(wait, undefined, {
|
|
165
|
+
signal: AbortSignal.any([signal, cancel.signal]),
|
|
166
|
+
}).catch(() => {
|
|
167
|
+
/* Shutdown or a lost claim interrupts the wait. */
|
|
168
|
+
});
|
|
169
|
+
if (cancel.signal.aborted) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
138
174
|
const heartbeatLoop = async () => {
|
|
139
175
|
while (!signal.aborted) {
|
|
140
176
|
const started = Date.now();
|
|
@@ -145,19 +181,24 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
145
181
|
? gateway
|
|
146
182
|
.request(`/agent-gateway/jobs/${leased.job.jobId}/renew`, { leaseToken: leased.job.leaseToken }, signal)
|
|
147
183
|
.then(() => {
|
|
148
|
-
|
|
184
|
+
failedRenewals = 0;
|
|
185
|
+
if (active === leased && !leased.answered) {
|
|
149
186
|
leased.deadline =
|
|
150
|
-
started +
|
|
151
|
-
(leased.job.native ? NATIVE_SAFETY_MS : LEASE_SAFETY_MS);
|
|
187
|
+
started + holdFor(Boolean(leased.job.native));
|
|
152
188
|
}
|
|
153
189
|
})
|
|
154
190
|
.catch((error) => {
|
|
155
191
|
if (active !== leased) {
|
|
156
192
|
return;
|
|
157
193
|
}
|
|
194
|
+
// Only the server's word ends the job: 409 is another
|
|
195
|
+
// claim. Anything else is a gateway that will be back.
|
|
158
196
|
if (error instanceof GatewayError && error.status === 409) {
|
|
159
197
|
leased.cancel.abort();
|
|
160
198
|
}
|
|
199
|
+
else {
|
|
200
|
+
failedRenewals++;
|
|
201
|
+
}
|
|
161
202
|
failService(error);
|
|
162
203
|
})
|
|
163
204
|
: Promise.resolve(),
|
|
@@ -166,7 +207,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
166
207
|
if (active?.job.native && active.owner && !gate.optedIn()) {
|
|
167
208
|
active.cancel.abort();
|
|
168
209
|
}
|
|
169
|
-
await delay(Math.max(1, (active?.job.native
|
|
210
|
+
await delay(Math.max(1, renewDelayMs(beat(Boolean(active?.job.native)), failedRenewals) -
|
|
170
211
|
(Date.now() - started)), undefined, { signal }).catch(() => {
|
|
171
212
|
/* Shutdown interrupts the timer. */
|
|
172
213
|
});
|
|
@@ -175,7 +216,8 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
175
216
|
let heartbeats;
|
|
176
217
|
let updateAfter = 0;
|
|
177
218
|
const watchdog = setInterval(() => {
|
|
178
|
-
|
|
219
|
+
// A made answer is never dropped for a quiet gateway; only a 409 ends it.
|
|
220
|
+
if (active && !active.answered && Date.now() >= active.deadline) {
|
|
179
221
|
active.cancel.abort();
|
|
180
222
|
}
|
|
181
223
|
}, 1000);
|
|
@@ -254,9 +296,9 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
254
296
|
const current = {
|
|
255
297
|
job,
|
|
256
298
|
cancel,
|
|
257
|
-
deadline: claimStartedAt +
|
|
258
|
-
(job.native ? NATIVE_SAFETY_MS : LEASE_SAFETY_MS),
|
|
299
|
+
deadline: claimStartedAt + holdFor(Boolean(job.native)),
|
|
259
300
|
owner: false,
|
|
301
|
+
answered: false,
|
|
260
302
|
};
|
|
261
303
|
active = current;
|
|
262
304
|
let lastStatusAt = 0;
|
|
@@ -266,6 +308,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
266
308
|
const receivedAt = performance.now();
|
|
267
309
|
const timings = {};
|
|
268
310
|
try {
|
|
311
|
+
await waitForServer(job, cancel);
|
|
269
312
|
// An owner job runs the owner's real setup only when the plane
|
|
270
313
|
// confirmed owner authority just now AND this computer is ready;
|
|
271
314
|
// anything less is the room-only profile, as before.
|
|
@@ -380,6 +423,10 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
380
423
|
.catch(failService);
|
|
381
424
|
},
|
|
382
425
|
});
|
|
426
|
+
// The answer is made: only the server saying another claim holds the
|
|
427
|
+
// job may drop it, never the quiet-gateway backstop. The server
|
|
428
|
+
// takes a late completion from this attempt until a newer claim.
|
|
429
|
+
current.answered = true;
|
|
383
430
|
// A transient delivery error retries this same completion. It must
|
|
384
431
|
// never become a new provider run or a duplicate final reply.
|
|
385
432
|
while (!(signal.aborted || cancel.signal.aborted)) {
|
|
@@ -399,14 +446,24 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
399
446
|
}
|
|
400
447
|
}
|
|
401
448
|
catch (error) {
|
|
402
|
-
if (!(signal.aborted ||
|
|
449
|
+
if (!(signal.aborted ||
|
|
450
|
+
cancel.signal.aborted ||
|
|
451
|
+
(error instanceof RoomToolsUnavailableError &&
|
|
452
|
+
(await gateway
|
|
453
|
+
.request(`/agent-gateway/jobs/${job.jobId}/renew`, { leaseToken: job.leaseToken }, signal)
|
|
454
|
+
.then(() => false)
|
|
455
|
+
.catch((probe) => {
|
|
456
|
+
if (probe instanceof GatewayError &&
|
|
457
|
+
probe.status === 409) {
|
|
458
|
+
cancel.abort();
|
|
459
|
+
}
|
|
460
|
+
return serverAway(probe) || cancel.signal.aborted;
|
|
461
|
+
}))))) {
|
|
403
462
|
await gateway
|
|
404
463
|
.request(`/agent-gateway/jobs/${job.jobId}/fail`, {
|
|
405
464
|
leaseToken: job.leaseToken,
|
|
406
465
|
// A fixed code; the server owns the room's wording.
|
|
407
|
-
|
|
408
|
-
? { reason: "room_tools" }
|
|
409
|
-
: {}),
|
|
466
|
+
reason: failureReasonOf(error),
|
|
410
467
|
}, signal)
|
|
411
468
|
.catch(failService);
|
|
412
469
|
}
|
package/dist/client.js
CHANGED
|
@@ -4,13 +4,27 @@ import { requireCredentials, resolveApiUrl, } from "./config.js";
|
|
|
4
4
|
const CLIENT_INFO = { name: "talentos-cli", version: "1.0.0" };
|
|
5
5
|
const UNAUTHORIZED_HINT = /\b401\b|unauthoriz/i;
|
|
6
6
|
const UNREACHABLE_HINT = /fetch failed|ECONNREFUSED|ENOTFOUND/i;
|
|
7
|
+
// A Convex push answers 5xx or drops connections for over a minute. The room
|
|
8
|
+
// tools are listed once, when a provider starts its turn, and a provider gives
|
|
9
|
+
// up on a server that does not list within its own startup timeout: Codex
|
|
10
|
+
// waits 30 s for tools/list (its "required MCP servers failed to initialize"
|
|
11
|
+
// error), so the waits here stay inside it, with room for the spawn and the
|
|
12
|
+
// initialize round trip. A longer outage is covered a layer up: the CLI waits
|
|
13
|
+
// for the server before it launches a provider, and takes a job back when the
|
|
14
|
+
// listing failed while the server was away (agent/serve.ts). A call is never
|
|
15
|
+
// retried: it may have landed.
|
|
16
|
+
export const PROVIDER_START_TIMEOUT_MS = 30_000;
|
|
17
|
+
export const LIST_RETRY_DELAYS_MS = [1000, 2000, 4000, 8000, 12_000];
|
|
18
|
+
const TRANSIENT_HINT = /fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|socket hang up|terminated/iu;
|
|
7
19
|
export const UNAUTHORIZED = "Not logged in or key revoked. Run `talentos login`.";
|
|
8
20
|
/** MCP client for the remote TalentOS server, one process-lived connection. */
|
|
9
21
|
export class AgentClient {
|
|
10
22
|
credentials;
|
|
11
23
|
client;
|
|
12
|
-
|
|
24
|
+
retryDelaysMs;
|
|
25
|
+
constructor(credentials, retryDelaysMs = LIST_RETRY_DELAYS_MS) {
|
|
13
26
|
this.credentials = credentials;
|
|
27
|
+
this.retryDelaysMs = retryDelaysMs;
|
|
14
28
|
}
|
|
15
29
|
async call(name, args) {
|
|
16
30
|
const client = await this.connect();
|
|
@@ -22,8 +36,10 @@ export class AgentClient {
|
|
|
22
36
|
return { text, data: result.structuredContent };
|
|
23
37
|
}
|
|
24
38
|
async listTools() {
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
return await this.whileServerIsAway(async () => {
|
|
40
|
+
const client = await this.connect();
|
|
41
|
+
return await withFriendlyErrors(() => client.listTools());
|
|
42
|
+
});
|
|
27
43
|
}
|
|
28
44
|
async callTool(params) {
|
|
29
45
|
const client = await this.connect();
|
|
@@ -34,6 +50,21 @@ export class AgentClient {
|
|
|
34
50
|
this.client = undefined;
|
|
35
51
|
await client?.close();
|
|
36
52
|
}
|
|
53
|
+
async whileServerIsAway(run) {
|
|
54
|
+
for (const wait of this.retryDelaysMs) {
|
|
55
|
+
try {
|
|
56
|
+
return await run();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!isTransient(error)) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
this.client = undefined;
|
|
63
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return await run();
|
|
67
|
+
}
|
|
37
68
|
async connect() {
|
|
38
69
|
if (this.client) {
|
|
39
70
|
return this.client;
|
|
@@ -62,6 +93,13 @@ export async function withClient(apiUrlOverride, run) {
|
|
|
62
93
|
await client.close();
|
|
63
94
|
}
|
|
64
95
|
}
|
|
96
|
+
function isTransient(error) {
|
|
97
|
+
const status = error?.code;
|
|
98
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
99
|
+
return ((typeof status === "number" && status >= 500) ||
|
|
100
|
+
TRANSIENT_HINT.test(message) ||
|
|
101
|
+
message.includes("Cannot reach TalentOS"));
|
|
102
|
+
}
|
|
65
103
|
function firstText(result) {
|
|
66
104
|
const block = result.content?.[0];
|
|
67
105
|
return block && block.type === "text" ? block.text : "";
|
|
@@ -71,7 +109,10 @@ async function withFriendlyErrors(run) {
|
|
|
71
109
|
return await run();
|
|
72
110
|
}
|
|
73
111
|
catch (error) {
|
|
74
|
-
|
|
112
|
+
// The HTTP status rides along so a caller can tell a server that is away.
|
|
113
|
+
throw Object.assign(new Error(describe(error)), {
|
|
114
|
+
code: error?.code,
|
|
115
|
+
});
|
|
75
116
|
}
|
|
76
117
|
}
|
|
77
118
|
function describe(error) {
|
package/dist/commands/skills.js
CHANGED
|
@@ -62,6 +62,14 @@ async function getSkill(parsed) {
|
|
|
62
62
|
throw new Error("Usage: talentos skills get <id|slug> [--out <dir>]");
|
|
63
63
|
}
|
|
64
64
|
const { text, data } = await withClient(parsed.options["api-url"], (client) => client.call("get_skill", { skillId }));
|
|
65
|
+
// A built-in guide (the canvas deck guide) is text only: no package files.
|
|
66
|
+
if (data === undefined) {
|
|
67
|
+
if (parsed.options.json || parsed.options.out !== undefined) {
|
|
68
|
+
throw new Error(`This guide has no package. Run \`talentos skills get ${skillId}\` without --out or --json to read it.`);
|
|
69
|
+
}
|
|
70
|
+
emit(text);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
65
73
|
if (parsed.options.json) {
|
|
66
74
|
emitJson(data);
|
|
67
75
|
return;
|
package/dist/mcp-proxy.js
CHANGED
|
@@ -62,11 +62,7 @@ ownerJobDir) {
|
|
|
62
62
|
}
|
|
63
63
|
async function runUpload(client, args, root) {
|
|
64
64
|
try {
|
|
65
|
-
const text = await uploadFile(client,
|
|
66
|
-
path: String(args.path ?? ""),
|
|
67
|
-
roomId: String(args.roomId ?? ""),
|
|
68
|
-
title: typeof args.title === "string" ? args.title : undefined,
|
|
69
|
-
}, root);
|
|
65
|
+
const text = await uploadFile(client, args, root);
|
|
70
66
|
return { content: [{ text, type: "text" }] };
|
|
71
67
|
}
|
|
72
68
|
catch (error) {
|
package/dist/upload-file.js
CHANGED
|
@@ -8,7 +8,11 @@ import { canonical, protectedPaths, protectedReason, } from "./agent/native/path
|
|
|
8
8
|
// The server caps and re-checks everything (type, size, names, content); this
|
|
9
9
|
// is the client's half of the boundary: only a regular file inside the folder
|
|
10
10
|
// the agent works in, and never a credential store, whatever the model asks.
|
|
11
|
-
|
|
11
|
+
// The size cap is the server's (it refuses at prepare, before any byte moves),
|
|
12
|
+
// so a cap change needs no CLI release. This ceiling is only the server's 2 GiB
|
|
13
|
+
// cap on an agent's open uploads, which no single file can pass: it spares
|
|
14
|
+
// hashing a 40 GB file for a minute just to be refused.
|
|
15
|
+
export const UPLOAD_BYTES_MAX = 2 * 1024 * 1024 * 1024;
|
|
12
16
|
const DENIED_SEGMENTS = new Set([
|
|
13
17
|
".aws",
|
|
14
18
|
".azure",
|
|
@@ -129,32 +133,50 @@ export async function openUploadSource(requested, root, home = homedir()) {
|
|
|
129
133
|
throw error;
|
|
130
134
|
}
|
|
131
135
|
}
|
|
136
|
+
const megabytes = (bytes) => (bytes / 1_000_000).toFixed(1);
|
|
132
137
|
// prepare -> stream the bytes straight to storage -> commit. Nothing about the
|
|
133
|
-
// file's contents passes through the model or an MCP argument.
|
|
138
|
+
// file's contents passes through the model or an MCP argument. Every other
|
|
139
|
+
// upload_file argument (roomId, title, artifactId, baseVersionId, and any the
|
|
140
|
+
// server adds later) goes to prepare_upload as given; the file's own name,
|
|
141
|
+
// hash and size come from the file and always win.
|
|
134
142
|
export async function uploadFile(client, args, root, fetchImpl = fetch, home = homedir()) {
|
|
135
|
-
const
|
|
143
|
+
const { path, ...forwarded } = args;
|
|
144
|
+
const source = await openUploadSource(String(path ?? ""), root, home);
|
|
136
145
|
try {
|
|
137
146
|
const prepared = await client.call("prepare_upload", {
|
|
147
|
+
...forwarded,
|
|
138
148
|
filename: source.name,
|
|
139
|
-
roomId: args.roomId,
|
|
140
149
|
sha256: source.sha256,
|
|
141
150
|
sizeBytes: source.size,
|
|
142
|
-
...(args.title ? { title: args.title } : {}),
|
|
143
151
|
});
|
|
144
152
|
if (prepared.data.status === "committed" || !prepared.data.uploadUrl) {
|
|
145
153
|
return prepared.text;
|
|
146
154
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"Content-Length": String(source.size),
|
|
152
|
-
"Content-Type": "application/octet-stream",
|
|
153
|
-
},
|
|
154
|
-
method: "POST",
|
|
155
|
+
let sent = 0;
|
|
156
|
+
const body = source.stream();
|
|
157
|
+
body.on("data", (chunk) => {
|
|
158
|
+
sent += chunk.length;
|
|
155
159
|
});
|
|
160
|
+
// Storage gives an upload URL about two minutes, so a large file on a
|
|
161
|
+
// slow line is cut off; say so in terms the agent can act on.
|
|
162
|
+
const failed = (status) => refuse(`The upload stopped after ${megabytes(sent)} of ${megabytes(source.size)} MB${status}. An upload has about two minutes: try again, and if it fails again, export a smaller file (lower bitrate or resolution).`);
|
|
163
|
+
let response;
|
|
164
|
+
try {
|
|
165
|
+
response = await fetchImpl(prepared.data.uploadUrl, {
|
|
166
|
+
body: Readable.toWeb(body),
|
|
167
|
+
duplex: "half",
|
|
168
|
+
headers: {
|
|
169
|
+
"Content-Length": String(source.size),
|
|
170
|
+
"Content-Type": "application/octet-stream",
|
|
171
|
+
},
|
|
172
|
+
method: "POST",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return failed("");
|
|
177
|
+
}
|
|
156
178
|
if (!response.ok) {
|
|
157
|
-
|
|
179
|
+
failed(` (${response.status})`);
|
|
158
180
|
}
|
|
159
181
|
const { storageId } = (await response.json());
|
|
160
182
|
if (!storageId) {
|
package/package.json
CHANGED