@cygnuxlabs/tracekit 1.6.0 → 1.7.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/README.md +4 -1
- package/dist/v2/adapters/gate.js +8 -5
- package/dist/v2/client.d.ts +1 -1
- package/dist/v2/client.js +93 -33
- package/dist/v2/rpc_schema.d.ts +1 -1
- package/dist/v2/rpc_schema.js +5 -2
- package/dist/verify/index.d.ts +2 -2
- package/dist/verify/index.js +2 -2
- package/dist/verify.html +3 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -53,7 +53,10 @@ await client.close(); // waits for what is i
|
|
|
53
53
|
|
|
54
54
|
- **Signer:** `$TRACEKIT_SIGNER` names a Unix socket, `tcp://127.0.0.1:port` (with `$TRACEKIT_SIGNER_TOKEN`; both sides
|
|
55
55
|
prove they hold it, it never goes on the wire) or `https://host:port` (`$TRACEKIT_SIGNER_TOKEN_FILE`: a bearer token
|
|
56
|
-
re-read per call; `$TRACEKIT_SIGNER_CERT`/`_KEY`: mTLS;
|
|
56
|
+
re-read per call, else `$TRACEKIT_API_KEY`: the token itself; `$TRACEKIT_SIGNER_CERT`/`_KEY`: mTLS;
|
|
57
|
+
`$TRACEKIT_SIGNER_CA`: the signer's CA). An event call (decide, complete, observe, state_write, model_event) the
|
|
58
|
+
signer refuses with a rate limit or an outage is sent again within the call's timeout
|
|
59
|
+
([remote clients](../../docs/remote-ingest.md#calling-the-signer-over-http)). In system mode the
|
|
57
60
|
signer named by the root-owned `/etc/tracekit/client.json` is used and a different `$TRACEKIT_SIGNER` is refused.
|
|
58
61
|
Otherwise the same-user dev signer is found, or started with `tracekit up --json`: `$TRACEKIT_PYTHON -m tracekit` if
|
|
59
62
|
set, else a pip-installed `tracekit` on PATH, else the Python bundled in this platform's
|
package/dist/v2/adapters/gate.js
CHANGED
|
@@ -32,12 +32,15 @@ export const refusal = (ruleIds, reason) => BLOCKED + (ruleIds.join(", ") || "de
|
|
|
32
32
|
export const failure = (e) => (e instanceof Error ? `${e.name}: ${e.message}` : String(e)).slice(0, 4096);
|
|
33
33
|
/** The run's approvals by tool call id: requested, approved, rejected or expired. */
|
|
34
34
|
export async function approvalStates(run) {
|
|
35
|
-
// lean: the first page of approval_list (the signer's default limit); follow `cursor` if runs hold more
|
|
36
|
-
const { approvals } = await run.client.call("approval_list", { run_id: run.runId });
|
|
37
35
|
const states = new Map();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
let cursor;
|
|
37
|
+
do { // every page: a call approved after the first page's worth would stay waiting
|
|
38
|
+
const page = await run.client.call("approval_list", { run_id: run.runId, ...(cursor ? { cursor } : {}) });
|
|
39
|
+
for (const a of page.approvals)
|
|
40
|
+
if (!states.has(a.tool_call_id))
|
|
41
|
+
states.set(a.tool_call_id, a.state);
|
|
42
|
+
cursor = page.next_cursor;
|
|
43
|
+
} while (cursor);
|
|
41
44
|
return states;
|
|
42
45
|
}
|
|
43
46
|
export class Gate {
|
package/dist/v2/client.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ declare class Conn {
|
|
|
33
33
|
send(frame: Frame): Promise<Frame>;
|
|
34
34
|
}
|
|
35
35
|
/** A connection to the signer at `path` (a Unix socket or tcp://host:port) and its hello, after the version check. */
|
|
36
|
-
export declare function connect(path: string, token?: string): Promise<{
|
|
36
|
+
export declare function connect(path: string, token?: string, timeoutMs?: number): Promise<{
|
|
37
37
|
conn: Conn;
|
|
38
38
|
hello: Frame;
|
|
39
39
|
}>;
|
package/dist/v2/client.js
CHANGED
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The signer is the Unix socket in $TRACEKIT_SIGNER, `tcp://host:port` with $TRACEKIT_SIGNER_TOKEN (the loopback dev
|
|
11
11
|
* transport, mutual HMAC proof of the token), or an `https://host:port` URL (each call is one POST /v2/rpc;
|
|
12
|
-
* $TRACEKIT_SIGNER_TOKEN_FILE names a bearer token file re-read per call, $
|
|
13
|
-
* certificate for mTLS, $TRACEKIT_SIGNER_CA the signer's CA). In system mode the
|
|
14
|
-
* /etc/tracekit/client.json names, and a $TRACEKIT_SIGNER naming another is refused.
|
|
15
|
-
* signer of the runtime dir is used, started with `tracekit up --json` (found as src/v2/launcher.ts says) when none answers.
|
|
12
|
+
* $TRACEKIT_SIGNER_TOKEN_FILE names a bearer token file re-read per call, else $TRACEKIT_API_KEY is the token itself;
|
|
13
|
+
* $TRACEKIT_SIGNER_CERT/_KEY a client certificate for mTLS, $TRACEKIT_SIGNER_CA the signer's CA). In system mode the
|
|
14
|
+
* signer is the one the root-owned /etc/tracekit/client.json names, and a $TRACEKIT_SIGNER naming another is refused.
|
|
15
|
+
* Without either, the same-user dev signer of the runtime dir is used, started with `tracekit up --json` (found as src/v2/launcher.ts says) when none answers.
|
|
16
16
|
* Requests go out in order on one connection and are answered in order; `approval_wait` gets a connection of its own.
|
|
17
17
|
* Every request is validated against the RPC contract before it is sent. Calls that change state carry a `request_id`
|
|
18
18
|
* and are resent with it when the connection drops. Event calls carry this client's `stream` and a `client_seq` per run;
|
|
19
|
-
* a run's events go out one at a time, each once the one before it is answered, so they reach the signer in order.
|
|
20
|
-
*
|
|
19
|
+
* a run's events go out one at a time, each once the one before it is answered, so they reach the signer in order. An
|
|
20
|
+
* event call the signer refuses with `quota_exceeded` (a rate or count limit: one with `retry_after_ms`) or
|
|
21
|
+
* `unavailable` is sent again as it was, within the call's timeout (retryWait); no other call is. The client writes
|
|
22
|
+
* nothing to disk.
|
|
21
23
|
*/
|
|
22
24
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23
25
|
import { execFile } from "node:child_process";
|
|
@@ -27,6 +29,7 @@ import { Agent, request } from "node:https";
|
|
|
27
29
|
import { createConnection } from "node:net";
|
|
28
30
|
import { homedir } from "node:os";
|
|
29
31
|
import { basename, extname, join } from "node:path";
|
|
32
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
30
33
|
import { TracekitAgents } from "./adapters/openai-agents.js";
|
|
31
34
|
import { tracekitAI } from "./adapters/vercel-ai.js";
|
|
32
35
|
import { argsDigest } from "./jcs.js";
|
|
@@ -37,10 +40,13 @@ export { RPC_VERSION };
|
|
|
37
40
|
export { argsDigest, canonicalize, digest, strictParse, StrictJSONError } from "./jcs.js";
|
|
38
41
|
export const SYSTEM_CONFIG = "/etc/tracekit/client.json";
|
|
39
42
|
const CONNECT_TIMEOUT_MS = 2000;
|
|
40
|
-
const RETRIES = 3;
|
|
43
|
+
const RETRIES = 3; // tries of a call while its connection is lost; apart, while the signer refuses an event call (retryWait)
|
|
44
|
+
const BACKOFF_MS = 100, BACKOFF_CAP_MS = 2000; // the wait before an event call's second try, doubled for each next
|
|
41
45
|
export class SignerUnavailable extends Error {
|
|
42
46
|
name = "SignerUnavailable";
|
|
43
47
|
}
|
|
48
|
+
class TimeoutUnavailable extends SignerUnavailable {
|
|
49
|
+
}
|
|
44
50
|
/** The signer answered but does not speak this client's protocol version. It is left running. */
|
|
45
51
|
export class Incompatible extends Error {
|
|
46
52
|
older;
|
|
@@ -64,6 +70,19 @@ export class RPCError extends Error {
|
|
|
64
70
|
}
|
|
65
71
|
class ConnectionLost extends Error {
|
|
66
72
|
}
|
|
73
|
+
/** Milliseconds to wait before sending a call of `schema` again after its `tries`th try was refused with `e`; null: not
|
|
74
|
+
* again. Only an event call (one with a client_seq): the signer refuses a client_seq it already recorded before it
|
|
75
|
+
* writes anything, even after a restart or a write whose outcome it couldn't tell, so a retry is recorded once or
|
|
76
|
+
* refused (then the call rejects with that `unavailable`, as without a retry); any other call's request_id is
|
|
77
|
+
* remembered in memory only (tracekit/sdk/client.py _retry_wait). A quota_exceeded without retry_after_ms is a size
|
|
78
|
+
* limit the same request never fits. */
|
|
79
|
+
function retryWait(schema, e, tries) {
|
|
80
|
+
const limited = e.code === "quota_exceeded" && typeof e.retry_after_ms === "number";
|
|
81
|
+
if (!("client_seq" in schema.properties) || !(limited || e.code === "unavailable"))
|
|
82
|
+
return null;
|
|
83
|
+
const backoff = Math.min(BACKOFF_CAP_MS, BACKOFF_MS * 2 ** (tries - 1)) * (0.5 + Math.random() / 2); // jitter
|
|
84
|
+
return Math.max(typeof e.retry_after_ms === "number" ? e.retry_after_ms : 0, backoff);
|
|
85
|
+
}
|
|
67
86
|
const newId = () => randomUUID().replaceAll("-", "");
|
|
68
87
|
const hmac = (token, label, nonce) => createHmac("sha256", token).update(`${label}\n${nonce}`).digest("hex");
|
|
69
88
|
function warn(message) {
|
|
@@ -74,7 +93,7 @@ function withTimeout(p, ms, onTimeout) {
|
|
|
74
93
|
const t = new Promise((_, reject) => {
|
|
75
94
|
timer = setTimeout(() => {
|
|
76
95
|
onTimeout();
|
|
77
|
-
reject(new
|
|
96
|
+
reject(new TimeoutUnavailable(`no answer from the signer within ${ms / 1000}s`));
|
|
78
97
|
}, ms);
|
|
79
98
|
});
|
|
80
99
|
return Promise.race([p, t]).finally(() => clearTimeout(timer));
|
|
@@ -130,9 +149,9 @@ class Conn {
|
|
|
130
149
|
});
|
|
131
150
|
}
|
|
132
151
|
}
|
|
133
|
-
function open(sock) {
|
|
152
|
+
function open(sock, timeoutMs = CONNECT_TIMEOUT_MS) {
|
|
134
153
|
return new Promise((resolve, reject) => {
|
|
135
|
-
sock.setTimeout(
|
|
154
|
+
sock.setTimeout(timeoutMs, () => sock.destroy(new Error("connect timed out")));
|
|
136
155
|
sock.once("connect", () => {
|
|
137
156
|
sock.setTimeout(0);
|
|
138
157
|
resolve(sock);
|
|
@@ -148,7 +167,8 @@ function check(hello, where) {
|
|
|
148
167
|
"Stop it with `tracekit down`, or replace it with `tracekit up --replace`", Array.isArray(proto) && proto.length === 2 && typeof proto[1] === "number" && proto[1] < RPC_VERSION);
|
|
149
168
|
}
|
|
150
169
|
/** A connection to the signer at `path` (a Unix socket or tcp://host:port) and its hello, after the version check. */
|
|
151
|
-
export async function connect(path, token) {
|
|
170
|
+
export async function connect(path, token, timeoutMs = CONNECT_TIMEOUT_MS) {
|
|
171
|
+
const deadline = Date.now() + timeoutMs, leftMs = () => Math.max(deadline - Date.now(), 1);
|
|
152
172
|
let conn, hello;
|
|
153
173
|
try {
|
|
154
174
|
if (path.startsWith("tcp://")) {
|
|
@@ -158,10 +178,10 @@ export async function connect(path, token) {
|
|
|
158
178
|
token ||= process.env.TRACEKIT_SIGNER_TOKEN;
|
|
159
179
|
if (!token)
|
|
160
180
|
throw new SignerUnavailable(`${path}: tcp:// signers need TRACEKIT_SIGNER_TOKEN`);
|
|
161
|
-
conn = new Conn(await open(createConnection({ host, port: Number(hostPort.slice(k + 1)) })));
|
|
181
|
+
conn = new Conn(await open(createConnection({ host, port: Number(hostPort.slice(k + 1)) }), leftMs()));
|
|
162
182
|
// the signer proves it holds the token over our nonce before we prove it over its own (transport/tcp_dev.py)
|
|
163
183
|
const nonce = randomBytes(16).toString("hex");
|
|
164
|
-
const reply = await withTimeout(conn.send({ method: "hello", nonce }),
|
|
184
|
+
const reply = await withTimeout(conn.send({ method: "hello", nonce }), leftMs(), () => conn.sock.destroy());
|
|
165
185
|
const proof = Buffer.from(String(reply.proof)), want = Buffer.from(hmac(token, "signer", nonce));
|
|
166
186
|
if (proof.length !== want.length || !timingSafeEqual(proof, want))
|
|
167
187
|
throw new Error("dev token proof mismatch");
|
|
@@ -170,19 +190,20 @@ export async function connect(path, token) {
|
|
|
170
190
|
conn.write({ proof: hmac(token, "client", reply.nonce) });
|
|
171
191
|
}
|
|
172
192
|
else if (process.platform !== "win32") {
|
|
173
|
-
conn = new Conn(await open(createConnection(path)));
|
|
193
|
+
conn = new Conn(await open(createConnection(path), leftMs()));
|
|
174
194
|
}
|
|
175
195
|
else {
|
|
176
196
|
throw new SignerUnavailable(`this platform has no Unix sockets: name the signer tcp://host:port, not ${path}`);
|
|
177
197
|
}
|
|
178
198
|
const c = conn;
|
|
179
|
-
hello = await withTimeout(c.send({ method: "hello" }),
|
|
199
|
+
hello = await withTimeout(c.send({ method: "hello" }), leftMs(), () => c.sock.destroy());
|
|
180
200
|
}
|
|
181
201
|
catch (e) {
|
|
182
202
|
conn?.sock.destroy();
|
|
183
203
|
if (e instanceof SignerUnavailable && !conn)
|
|
184
204
|
throw e;
|
|
185
|
-
|
|
205
|
+
const msg = `no signer answering at ${path}: ${e.message}`;
|
|
206
|
+
throw e instanceof TimeoutUnavailable && timeoutMs < CONNECT_TIMEOUT_MS ? new TimeoutUnavailable(msg) : new SignerUnavailable(msg);
|
|
186
207
|
}
|
|
187
208
|
try {
|
|
188
209
|
check(hello, path);
|
|
@@ -288,18 +309,24 @@ class Https {
|
|
|
288
309
|
this.agent = new Agent({ keepAlive: true, ca: file(env.TRACEKIT_SIGNER_CA), cert: file(cert),
|
|
289
310
|
key: cert ? file(env.TRACEKIT_SIGNER_KEY || cert) : undefined });
|
|
290
311
|
}
|
|
291
|
-
/** The answer frame
|
|
312
|
+
/** The answer frame, read from the body whatever the HTTP status. The client doesn't ask for error statuses
|
|
313
|
+
* (Tracekit-Errors), so a proxy in front sees 200 for a refusal and acts on none (no retry of a 503, no host ejected).
|
|
314
|
+
* ConnectionLost when the request may not have arrived, SignerUnavailable on a timeout. */
|
|
292
315
|
post(frame, timeoutMs) {
|
|
293
316
|
const body = JSON.stringify(frame), tokenFile = process.env.TRACEKIT_SIGNER_TOKEN_FILE;
|
|
317
|
+
const apiKey = process.env.TRACEKIT_API_KEY?.trim();
|
|
294
318
|
const headers = { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) };
|
|
295
|
-
if (tokenFile) {
|
|
319
|
+
if (tokenFile) { // wins over an API key: it is re-read per call, so a rotated token is picked up
|
|
296
320
|
try {
|
|
297
|
-
headers.Authorization = "Bearer " + readFileSync(tokenFile, "utf8").trim();
|
|
321
|
+
headers.Authorization = "Bearer " + readFileSync(tokenFile, "utf8").trim();
|
|
298
322
|
}
|
|
299
323
|
catch (e) {
|
|
300
324
|
throw new SignerUnavailable(`cannot read the signer token file: ${e.message}`);
|
|
301
325
|
}
|
|
302
326
|
}
|
|
327
|
+
else if (apiKey) {
|
|
328
|
+
headers.Authorization = "Bearer " + apiKey;
|
|
329
|
+
}
|
|
303
330
|
return new Promise((resolve, reject) => {
|
|
304
331
|
const req = request(routeUrl(this.url, frame), { method: "POST", agent: this.agent, headers, timeout: timeoutMs }, (res) => {
|
|
305
332
|
let data = "";
|
|
@@ -319,7 +346,7 @@ class Https {
|
|
|
319
346
|
});
|
|
320
347
|
});
|
|
321
348
|
req.on("timeout", () => {
|
|
322
|
-
reject(new
|
|
349
|
+
reject(new TimeoutUnavailable(`no answer from the signer within ${timeoutMs / 1000}s`));
|
|
323
350
|
req.destroy();
|
|
324
351
|
});
|
|
325
352
|
req.on("error", () => reject(new ConnectionLost()));
|
|
@@ -327,6 +354,7 @@ class Https {
|
|
|
327
354
|
});
|
|
328
355
|
}
|
|
329
356
|
async rpc(frame, timeoutMs) {
|
|
357
|
+
const deadline = Date.now() + timeoutMs;
|
|
330
358
|
if (!this.hello) {
|
|
331
359
|
const hello = await this.post({ method: "hello" }, timeoutMs);
|
|
332
360
|
if (hello.error)
|
|
@@ -334,7 +362,10 @@ class Https {
|
|
|
334
362
|
check(hello, this.url.origin);
|
|
335
363
|
this.hello = hello;
|
|
336
364
|
}
|
|
337
|
-
|
|
365
|
+
const rem = deadline - Date.now();
|
|
366
|
+
if (rem <= 0)
|
|
367
|
+
throw new TimeoutUnavailable(`no answer from the signer within ${timeoutMs / 1000}s`);
|
|
368
|
+
return this.post(frame, rem);
|
|
338
369
|
}
|
|
339
370
|
}
|
|
340
371
|
/** Methods take the request object of an RPC and return its response, or reject with RPCError (a refusal),
|
|
@@ -426,9 +457,15 @@ export class Client {
|
|
|
426
457
|
throw e;
|
|
427
458
|
}
|
|
428
459
|
}
|
|
460
|
+
// tries: the signer's refusals of an event call (retryWait), counted apart from lost connections
|
|
461
|
+
let losses = 0, tries = 0, outage = null;
|
|
429
462
|
try {
|
|
430
|
-
|
|
431
|
-
const left =
|
|
463
|
+
while (losses < RETRIES) {
|
|
464
|
+
const left = deadline - Date.now();
|
|
465
|
+
if (left <= 0) {
|
|
466
|
+
frame();
|
|
467
|
+
throw new SignerUnavailable(`no answer from the signer within ${timeout / 1000}s`);
|
|
468
|
+
}
|
|
432
469
|
let reply;
|
|
433
470
|
try {
|
|
434
471
|
if (this.https) {
|
|
@@ -439,22 +476,40 @@ export class Client {
|
|
|
439
476
|
reply = await this.poll(frame(), left);
|
|
440
477
|
}
|
|
441
478
|
else {
|
|
442
|
-
const conn = await this.connection();
|
|
443
|
-
|
|
479
|
+
const conn = await withTimeout(this.connection(), left, () => { });
|
|
480
|
+
const rem = deadline - Date.now();
|
|
481
|
+
if (rem <= 0) {
|
|
482
|
+
frame();
|
|
483
|
+
throw new SignerUnavailable(`no answer from the signer within ${timeout / 1000}s`);
|
|
484
|
+
}
|
|
485
|
+
reply = await withTimeout(conn.send(frame()), rem, () => conn.sock.destroy());
|
|
444
486
|
}
|
|
445
487
|
}
|
|
446
488
|
catch (e) {
|
|
447
|
-
if (e instanceof ConnectionLost)
|
|
489
|
+
if (e instanceof ConnectionLost) {
|
|
490
|
+
losses++;
|
|
448
491
|
continue;
|
|
492
|
+
}
|
|
449
493
|
if (e instanceof SignerUnavailable)
|
|
450
494
|
frame(); // used up: the signer's client_counter_gap covers a call it never saw
|
|
495
|
+
if (e instanceof TimeoutUnavailable)
|
|
496
|
+
throw new SignerUnavailable(`no answer from the signer within ${timeout / 1000}s`);
|
|
451
497
|
throw e;
|
|
452
498
|
}
|
|
453
499
|
if (reply.error) {
|
|
454
|
-
const e = reply.error;
|
|
500
|
+
const e = reply.error, err = new RPCError(e.code, e.message ?? "", e.retry_after_ms);
|
|
455
501
|
if (["run_closed", "unknown_run"].includes(e.code))
|
|
456
502
|
this.seqs.delete(req.run_id); // no more events for it
|
|
457
|
-
|
|
503
|
+
// the try the signer answered unavailable was written after all: that answer stands (the caller's outage path)
|
|
504
|
+
if (outage && e.code === "client_seq_reused")
|
|
505
|
+
throw outage;
|
|
506
|
+
const wait = retryWait(schema, e, ++tries);
|
|
507
|
+
if (wait === null || tries === RETRIES || Date.now() + wait >= deadline)
|
|
508
|
+
throw err;
|
|
509
|
+
if (e.code === "unavailable")
|
|
510
|
+
outage = err;
|
|
511
|
+
await sleep(wait); // then the same request: its request_id, stream and client_seq
|
|
512
|
+
continue;
|
|
458
513
|
}
|
|
459
514
|
if (method === "close_run")
|
|
460
515
|
this.seqs.delete(req.run_id);
|
|
@@ -489,9 +544,13 @@ export class Client {
|
|
|
489
544
|
}
|
|
490
545
|
/** One request on a connection of its own, closed after the answer. */
|
|
491
546
|
async poll(frame, timeout) {
|
|
492
|
-
const
|
|
547
|
+
const deadline = Date.now() + timeout;
|
|
548
|
+
const { conn } = await this.dial(Math.min(CONNECT_TIMEOUT_MS, timeout));
|
|
493
549
|
try {
|
|
494
|
-
|
|
550
|
+
const rem = deadline - Date.now();
|
|
551
|
+
if (rem <= 0)
|
|
552
|
+
throw new TimeoutUnavailable(`no answer from the signer within ${timeout / 1000}s`);
|
|
553
|
+
return await withTimeout(conn.send(frame), rem, () => { });
|
|
495
554
|
}
|
|
496
555
|
finally {
|
|
497
556
|
conn.sock.destroy();
|
|
@@ -511,10 +570,10 @@ export class Client {
|
|
|
511
570
|
}
|
|
512
571
|
return this.conn;
|
|
513
572
|
}
|
|
514
|
-
async dial() {
|
|
573
|
+
async dial(timeoutMs = CONNECT_TIMEOUT_MS) {
|
|
515
574
|
let c;
|
|
516
575
|
if (this.signer) {
|
|
517
|
-
c = await connect(this.signer);
|
|
576
|
+
c = await connect(this.signer, undefined, Math.min(CONNECT_TIMEOUT_MS, timeoutMs));
|
|
518
577
|
}
|
|
519
578
|
else {
|
|
520
579
|
const d = devRuntimeDir();
|
|
@@ -616,7 +675,8 @@ export class RunHandle {
|
|
|
616
675
|
if (closed !== this.runId)
|
|
617
676
|
return Promise.resolve(); // renewed already
|
|
618
677
|
this.renewing ??= (async () => {
|
|
619
|
-
|
|
678
|
+
// a later run of the process's agent, whose model may still hold what the closed run read
|
|
679
|
+
const agent = { agent: { name: this.renewAs }, continues: true };
|
|
620
680
|
let r;
|
|
621
681
|
try { // linked to the closed run while it is still closing
|
|
622
682
|
r = await this.client.call("register_run", { ...agent, parent: { run_id: this.runId, run_token: this.runToken } });
|
package/dist/v2/rpc_schema.d.ts
CHANGED
package/dist/v2/rpc_schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const RPC_VERSION =
|
|
1
|
+
export const RPC_VERSION = 26;
|
|
2
2
|
export const REQUESTS = {
|
|
3
|
-
"register_run": { "type": "object", "additionalProperties": false, "required": ["request_id", "agent"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "tenant": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "principal": { "type": "string", "maxLength": 256 }, "principal_token": { "type": "string", "maxLength": 16384 }, "source": { "const": "migrated" }, "analyzes": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "replay_of": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "investigation": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "parent": { "type": "object", "additionalProperties": false, "required": ["run_id", "run_token"], "properties": { "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 } } }, "caller": { "type": "string", "maxLength": 256, "pattern": "^[a-z0-9_]+:[^\\n]+(?![\\s\\S])" }, "box": { "type": "object", "additionalProperties": false, "required": ["id", "image_digest", "allow"], "properties": { "id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "image_digest": { "type": "string", "maxLength": 71, "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])" }, "channel": { "const": "agent" }, "allow": { "type": "array", "maxItems": 256, "items": { "type": "string", "maxLength": 261, "minLength": 1, "pattern": "^[A-Za-z0-9.*:\\[\\]_-]+(?![\\s\\S])" } } } }, "agent": { "type": "object", "additionalProperties": false, "required": ["name"], "properties": { "name": { "type": "string", "maxLength": 128, "minLength": 1 }, "version": { "type": "string", "maxLength": 64 } } } } },
|
|
3
|
+
"register_run": { "type": "object", "additionalProperties": false, "required": ["request_id", "agent"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "tenant": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "principal": { "type": "string", "maxLength": 256 }, "principal_token": { "type": "string", "maxLength": 16384 }, "source": { "const": "migrated" }, "analyzes": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "replay_of": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "investigation": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "parent": { "type": "object", "additionalProperties": false, "required": ["run_id", "run_token"], "properties": { "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 } } }, "caller": { "type": "string", "maxLength": 256, "pattern": "^[a-z0-9_]+:[^\\n]+(?![\\s\\S])" }, "box": { "type": "object", "additionalProperties": false, "required": ["id", "image_digest", "allow"], "properties": { "id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "image_digest": { "type": "string", "maxLength": 71, "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])" }, "channel": { "const": "agent" }, "allow": { "type": "array", "maxItems": 256, "items": { "type": "string", "maxLength": 261, "minLength": 1, "pattern": "^[A-Za-z0-9.*:\\[\\]_-]+(?![\\s\\S])" } } } }, "continues": { "const": true }, "agent": { "type": "object", "additionalProperties": false, "required": ["name"], "properties": { "name": { "type": "string", "maxLength": 128, "minLength": 1 }, "version": { "type": "string", "maxLength": 64 } } } } },
|
|
4
4
|
"decide": { "type": "object", "additionalProperties": false, "required": ["request_id", "run_id", "run_token", "stream", "client_seq", "tool_call_id", "tool", "args_source", "args"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 }, "stream": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "client_seq": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "caller": { "type": "string", "maxLength": 256, "pattern": "^[a-z0-9_]+:[^\\n]+(?![\\s\\S])" }, "tool_call_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "attempt": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "tool": { "type": "string", "maxLength": 256, "minLength": 1 }, "tool_class_hint": { "type": "string", "maxLength": 64 }, "args_source": { "enum": ["raw", "parsed", "coerced"] }, "args": {} }, "if": { "properties": { "args_source": { "const": "raw" } } }, "then": { "properties": { "args": { "type": "string", "maxLength": 1048576 } } } },
|
|
5
5
|
"complete": { "type": "object", "additionalProperties": false, "required": ["request_id", "run_id", "run_token", "stream", "client_seq", "tool_call_id", "decision_id", "args_digest", "status"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 }, "stream": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "client_seq": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "caller": { "type": "string", "maxLength": 256, "pattern": "^[a-z0-9_]+:[^\\n]+(?![\\s\\S])" }, "tool_call_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "attempt": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "decision_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "args_digest": { "type": "string", "maxLength": 71, "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])" }, "status": { "enum": ["ok", "error"] }, "result": {}, "error": { "type": "string", "maxLength": 4096 }, "redacted": { "const": true }, "redaction": { "type": "object", "additionalProperties": false, "required": [], "properties": { "rules": { "type": "array", "maxItems": 32, "items": { "type": "string", "maxLength": 64 } }, "count": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 } } } } },
|
|
6
6
|
"observe": { "type": "object", "additionalProperties": false, "required": ["request_id", "run_id", "run_token", "stream", "client_seq", "source", "trust", "value"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 }, "stream": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "client_seq": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "caller": { "type": "string", "maxLength": 256, "pattern": "^[a-z0-9_]+:[^\\n]+(?![\\s\\S])" }, "source": { "type": "string", "maxLength": 256, "minLength": 1 }, "trust": { "enum": ["trusted", "untrusted"] }, "value": {} } },
|
|
@@ -50,4 +50,7 @@ export const REQUESTS = {
|
|
|
50
50
|
"grant_issue": { "type": "object", "additionalProperties": false, "required": ["request_id", "run_id", "intent", "caveats", "limits", "expires_at"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "approval_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "intent": { "type": "string", "maxLength": 64, "pattern": "^[a-z][a-z0-9_.-]{0,63}(?![\\s\\S])" }, "caveats": { "type": "array", "maxItems": 16, "items": { "type": "object", "additionalProperties": false, "required": ["field", "op", "value"], "properties": { "field": { "type": "string", "maxLength": 64, "pattern": "^[a-z][a-z0-9_]*(?![\\s\\S])" }, "op": { "enum": ["==", "<=", ">=", "<", ">", "in"] }, "value": {} } } }, "limits": { "type": "array", "minItems": 1, "maxItems": 4, "items": { "type": "object", "additionalProperties": false, "required": ["op", "max"], "properties": { "op": { "enum": ["sum", "count"] }, "field": { "type": "string", "maxLength": 64, "pattern": "^[a-z][a-z0-9_]*(?![\\s\\S])" }, "max": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 } } } }, "expires_at": { "type": "string", "maxLength": 27, "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{6}Z(?![\\s\\S])" }, "description": { "type": "string", "maxLength": 512 }, "tools": { "type": "array", "maxItems": 16, "items": { "type": "string", "maxLength": 256, "minLength": 1 } } } },
|
|
51
51
|
"grant_list": { "type": "object", "additionalProperties": false, "required": [], "properties": { "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" } } },
|
|
52
52
|
"grant_revoke": { "type": "object", "additionalProperties": false, "required": ["request_id", "grant_id"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "grant_id": { "type": "string", "maxLength": 18, "pattern": "^g-[0-9a-f]{16}(?![\\s\\S])" }, "reason": { "type": "string", "maxLength": 1024 } } },
|
|
53
|
+
"export_run": { "type": "object", "additionalProperties": false, "required": ["run_id"], "properties": { "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "offset": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "digest": { "type": "string", "maxLength": 71, "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])" } } },
|
|
54
|
+
"call_state": { "type": "object", "additionalProperties": false, "required": ["run_id", "run_token", "tool_call_id"], "properties": { "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 }, "tool_call_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "args_digest": { "type": "string", "maxLength": 71, "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])" } } },
|
|
55
|
+
"call_claim": { "type": "object", "additionalProperties": false, "required": ["request_id", "run_id", "run_token", "tool_call_id", "attempt", "answers"], "properties": { "request_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "run_token": { "type": "string", "maxLength": 1024, "minLength": 1 }, "tool_call_id": { "type": "string", "maxLength": 128, "minLength": 1, "pattern": "^[A-Za-z0-9._:-]+(?![\\s\\S])" }, "attempt": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }, "answers": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 } } },
|
|
53
56
|
};
|
package/dist/verify/index.d.ts
CHANGED
|
@@ -23,10 +23,10 @@ import { type Floats } from "./jcs.js";
|
|
|
23
23
|
export { MAX_ENTRIES, MAX_ENTRY, MAX_TOTAL, Unusable, readZip } from "./zip.js";
|
|
24
24
|
export { StrictJSONError, canonicalize, strictParse, strictParseBytes } from "./jcs.js";
|
|
25
25
|
/** This verifier's release (the package's). */
|
|
26
|
-
export declare const VERSION = "1.
|
|
26
|
+
export declare const VERSION = "1.7.2";
|
|
27
27
|
/** The newest bundle format version this verifier reads: the reference's VERSIONS' newest row (tracekit/bundle_v2.py),
|
|
28
28
|
* or VERSION when later (tracekit/verify/v2.py READS); a bundle needing a later one is UNVERIFIABLE. */
|
|
29
|
-
export declare const READS = "1.
|
|
29
|
+
export declare const READS = "1.7.2";
|
|
30
30
|
export declare const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
|
|
31
31
|
/** The integrity of a trust config that can't be used: nothing in the bundle was checked. */
|
|
32
32
|
export declare const TRUST_UNUSABLE = "UNVERIFIABLE (the trust file can't be used)";
|
package/dist/verify/index.js
CHANGED
|
@@ -28,10 +28,10 @@ import VERSIONS_JSON from "./versions.json" with { type: "json" };
|
|
|
28
28
|
export { MAX_ENTRIES, MAX_ENTRY, MAX_TOTAL, Unusable, readZip } from "./zip.js";
|
|
29
29
|
export { StrictJSONError, canonicalize, strictParse, strictParseBytes } from "./jcs.js";
|
|
30
30
|
/** This verifier's release (the package's). */
|
|
31
|
-
export const VERSION = "1.
|
|
31
|
+
export const VERSION = "1.7.2";
|
|
32
32
|
/** The newest bundle format version this verifier reads: the reference's VERSIONS' newest row (tracekit/bundle_v2.py),
|
|
33
33
|
* or VERSION when later (tracekit/verify/v2.py READS); a bundle needing a later one is UNVERIFIABLE. */
|
|
34
|
-
export const READS = "1.
|
|
34
|
+
export const READS = "1.7.2";
|
|
35
35
|
/** The browser verifier of the latest release (docs/RELEASING.md). */
|
|
36
36
|
const PAGE = "https://cygnux-labs.github.io/Tracekit/verify/";
|
|
37
37
|
export const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
|
package/dist/verify.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-
|
|
6
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-fKKId3VhcyLpJ12e3TqFGi3PoBYJBX2d/X8HQ4OPOww='; style-src 'sha256-41aEPfNKIK0vxFn3JTgv68G+SOVBoDbHT4QPLHGL360='; worker-src blob:; connect-src 'none'">
|
|
7
7
|
<title>tracekit verify</title>
|
|
8
8
|
<style>
|
|
9
9
|
:root {
|
|
@@ -1189,10 +1189,10 @@ const VERSIONS_JSON = {"1.1.0":{"types":["input.observed","content.accessed","co
|
|
|
1189
1189
|
|
|
1190
1190
|
|
|
1191
1191
|
/** This verifier's release (the package's). */
|
|
1192
|
-
const VERSION = "1.
|
|
1192
|
+
const VERSION = "1.7.2";
|
|
1193
1193
|
/** The newest bundle format version this verifier reads: the reference's VERSIONS' newest row (tracekit/bundle_v2.py),
|
|
1194
1194
|
* or VERSION when later (tracekit/verify/v2.py READS); a bundle needing a later one is UNVERIFIABLE. */
|
|
1195
|
-
const READS = "1.
|
|
1195
|
+
const READS = "1.7.2";
|
|
1196
1196
|
/** The browser verifier of the latest release (docs/RELEASING.md). */
|
|
1197
1197
|
const PAGE = "https://cygnux-labs.github.io/Tracekit/verify/";
|
|
1198
1198
|
const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cygnuxlabs/tracekit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "Tracekit for TypeScript/JavaScript agents: a native client of the Tracekit signer: policy-gated tool calls and signed evidence, no runtime dependencies.",
|
|
5
5
|
"keywords": ["ai-agents", "agent-security", "audit-log", "tamper-evident", "guardrails", "mcp", "openai-agents",
|
|
6
6
|
"vercel-ai", "claude-agent-sdk", "observability", "provenance", "llm"],
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"test": "npm run build && node --test test/*.test.mjs"
|
|
28
28
|
},
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"@cygnuxlabs/tracekit-signer-darwin-arm64": "1.
|
|
31
|
-
"@cygnuxlabs/tracekit-signer-linux-x64-gnu": "1.
|
|
32
|
-
"@cygnuxlabs/tracekit-signer-linux-arm64-gnu": "1.
|
|
33
|
-
"@cygnuxlabs/tracekit-signer-win32-x64": "1.
|
|
30
|
+
"@cygnuxlabs/tracekit-signer-darwin-arm64": "1.7.2",
|
|
31
|
+
"@cygnuxlabs/tracekit-signer-linux-x64-gnu": "1.7.2",
|
|
32
|
+
"@cygnuxlabs/tracekit-signer-linux-arm64-gnu": "1.7.2",
|
|
33
|
+
"@cygnuxlabs/tracekit-signer-win32-x64": "1.7.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": { "@openai/agents": ">=0.20.0", "ai": ">=7.0.0", "@anthropic-ai/claude-agent-sdk": ">=0.3.0" },
|
|
36
36
|
"peerDependenciesMeta": {
|