@flowdot.ai/guardian-agent 0.1.0
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/LICENSE +40 -0
- package/README.md +281 -0
- package/ROADMAP.md +109 -0
- package/dist/audit/attestor.d.ts +102 -0
- package/dist/audit/attestor.d.ts.map +1 -0
- package/dist/audit/attestor.js +103 -0
- package/dist/audit/attestor.js.map +1 -0
- package/dist/audit/chain.d.ts +30 -0
- package/dist/audit/chain.d.ts.map +1 -0
- package/dist/audit/chain.js +65 -0
- package/dist/audit/chain.js.map +1 -0
- package/dist/audit/correlation.d.ts +114 -0
- package/dist/audit/correlation.d.ts.map +1 -0
- package/dist/audit/correlation.js +259 -0
- package/dist/audit/correlation.js.map +1 -0
- package/dist/audit/index.d.ts +13 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +8 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/reader.d.ts +30 -0
- package/dist/audit/reader.d.ts.map +1 -0
- package/dist/audit/reader.js +85 -0
- package/dist/audit/reader.js.map +1 -0
- package/dist/audit/signature.d.ts +39 -0
- package/dist/audit/signature.d.ts.map +1 -0
- package/dist/audit/signature.js +73 -0
- package/dist/audit/signature.js.map +1 -0
- package/dist/audit/stats.d.ts +106 -0
- package/dist/audit/stats.d.ts.map +1 -0
- package/dist/audit/stats.js +196 -0
- package/dist/audit/stats.js.map +1 -0
- package/dist/audit/writer.d.ts +96 -0
- package/dist/audit/writer.d.ts.map +1 -0
- package/dist/audit/writer.js +263 -0
- package/dist/audit/writer.js.map +1 -0
- package/dist/cli/guardian-baseline.d.ts +42 -0
- package/dist/cli/guardian-baseline.d.ts.map +1 -0
- package/dist/cli/guardian-baseline.js +265 -0
- package/dist/cli/guardian-baseline.js.map +1 -0
- package/dist/cli/guardian-correlator.d.ts +47 -0
- package/dist/cli/guardian-correlator.d.ts.map +1 -0
- package/dist/cli/guardian-correlator.js +217 -0
- package/dist/cli/guardian-correlator.js.map +1 -0
- package/dist/cli/guardian-verify.d.ts +30 -0
- package/dist/cli/guardian-verify.d.ts.map +1 -0
- package/dist/cli/guardian-verify.js +149 -0
- package/dist/cli/guardian-verify.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/estop/heartbeat.d.ts +94 -0
- package/dist/estop/heartbeat.d.ts.map +1 -0
- package/dist/estop/heartbeat.js +135 -0
- package/dist/estop/heartbeat.js.map +1 -0
- package/dist/estop/hub.d.ts +76 -0
- package/dist/estop/hub.d.ts.map +1 -0
- package/dist/estop/hub.js +167 -0
- package/dist/estop/hub.js.map +1 -0
- package/dist/estop/index.d.ts +12 -0
- package/dist/estop/index.d.ts.map +1 -0
- package/dist/estop/index.js +6 -0
- package/dist/estop/index.js.map +1 -0
- package/dist/estop/local.d.ts +31 -0
- package/dist/estop/local.d.ts.map +1 -0
- package/dist/estop/local.js +101 -0
- package/dist/estop/local.js.map +1 -0
- package/dist/estop/middleware.d.ts +36 -0
- package/dist/estop/middleware.d.ts.map +1 -0
- package/dist/estop/middleware.js +40 -0
- package/dist/estop/middleware.js.map +1 -0
- package/dist/estop/poller.d.ts +36 -0
- package/dist/estop/poller.d.ts.map +1 -0
- package/dist/estop/poller.js +85 -0
- package/dist/estop/poller.js.map +1 -0
- package/dist/estop/types.d.ts +31 -0
- package/dist/estop/types.d.ts.map +1 -0
- package/dist/estop/types.js +5 -0
- package/dist/estop/types.js.map +1 -0
- package/dist/gate/async-callback.d.ts +27 -0
- package/dist/gate/async-callback.d.ts.map +1 -0
- package/dist/gate/async-callback.js +79 -0
- package/dist/gate/async-callback.js.map +1 -0
- package/dist/gate/cli.d.ts +29 -0
- package/dist/gate/cli.d.ts.map +1 -0
- package/dist/gate/cli.js +83 -0
- package/dist/gate/cli.js.map +1 -0
- package/dist/gate/data-channel.d.ts +41 -0
- package/dist/gate/data-channel.d.ts.map +1 -0
- package/dist/gate/data-channel.js +132 -0
- package/dist/gate/data-channel.js.map +1 -0
- package/dist/gate/index.d.ts +13 -0
- package/dist/gate/index.d.ts.map +1 -0
- package/dist/gate/index.js +7 -0
- package/dist/gate/index.js.map +1 -0
- package/dist/gate/options.d.ts +90 -0
- package/dist/gate/options.d.ts.map +1 -0
- package/dist/gate/options.js +131 -0
- package/dist/gate/options.js.map +1 -0
- package/dist/gate/programmatic.d.ts +9 -0
- package/dist/gate/programmatic.d.ts.map +1 -0
- package/dist/gate/programmatic.js +20 -0
- package/dist/gate/programmatic.js.map +1 -0
- package/dist/gate/two-key.d.ts +90 -0
- package/dist/gate/two-key.d.ts.map +1 -0
- package/dist/gate/two-key.js +78 -0
- package/dist/gate/two-key.js.map +1 -0
- package/dist/gate/types.d.ts +25 -0
- package/dist/gate/types.d.ts.map +1 -0
- package/dist/gate/types.js +5 -0
- package/dist/gate/types.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/notify/console.d.ts +13 -0
- package/dist/notify/console.d.ts.map +1 -0
- package/dist/notify/console.js +27 -0
- package/dist/notify/console.js.map +1 -0
- package/dist/notify/index.d.ts +8 -0
- package/dist/notify/index.d.ts.map +1 -0
- package/dist/notify/index.js +4 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/multi.d.ts +14 -0
- package/dist/notify/multi.d.ts.map +1 -0
- package/dist/notify/multi.js +22 -0
- package/dist/notify/multi.js.map +1 -0
- package/dist/notify/types.d.ts +21 -0
- package/dist/notify/types.d.ts.map +1 -0
- package/dist/notify/types.js +5 -0
- package/dist/notify/types.js.map +1 -0
- package/dist/notify/webhook.d.ts +21 -0
- package/dist/notify/webhook.d.ts.map +1 -0
- package/dist/notify/webhook.js +37 -0
- package/dist/notify/webhook.js.map +1 -0
- package/dist/policy/attribution.d.ts +61 -0
- package/dist/policy/attribution.d.ts.map +1 -0
- package/dist/policy/attribution.js +116 -0
- package/dist/policy/attribution.js.map +1 -0
- package/dist/policy/evaluator.d.ts +36 -0
- package/dist/policy/evaluator.d.ts.map +1 -0
- package/dist/policy/evaluator.js +211 -0
- package/dist/policy/evaluator.js.map +1 -0
- package/dist/policy/index.d.ts +11 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +7 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/integrity.d.ts +17 -0
- package/dist/policy/integrity.d.ts.map +1 -0
- package/dist/policy/integrity.js +31 -0
- package/dist/policy/integrity.js.map +1 -0
- package/dist/policy/loader.d.ts +9 -0
- package/dist/policy/loader.d.ts.map +1 -0
- package/dist/policy/loader.js +124 -0
- package/dist/policy/loader.js.map +1 -0
- package/dist/policy/site-key.d.ts +22 -0
- package/dist/policy/site-key.d.ts.map +1 -0
- package/dist/policy/site-key.js +48 -0
- package/dist/policy/site-key.js.map +1 -0
- package/dist/policy/store.d.ts +45 -0
- package/dist/policy/store.d.ts.map +1 -0
- package/dist/policy/store.js +223 -0
- package/dist/policy/store.js.map +1 -0
- package/dist/policy/types.d.ts +72 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +5 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/runtime/capability.d.ts +125 -0
- package/dist/runtime/capability.d.ts.map +1 -0
- package/dist/runtime/capability.js +121 -0
- package/dist/runtime/capability.js.map +1 -0
- package/dist/runtime/honeytokens.d.ts +104 -0
- package/dist/runtime/honeytokens.d.ts.map +1 -0
- package/dist/runtime/honeytokens.js +115 -0
- package/dist/runtime/honeytokens.js.map +1 -0
- package/dist/runtime/multi-rate-limiter.d.ts +90 -0
- package/dist/runtime/multi-rate-limiter.d.ts.map +1 -0
- package/dist/runtime/multi-rate-limiter.js +133 -0
- package/dist/runtime/multi-rate-limiter.js.map +1 -0
- package/dist/runtime/runtime.d.ts +94 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +276 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/types.d.ts +97 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-rate-limiter.d.ts","sourceRoot":"","sources":["../../src/runtime/multi-rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;IACxD;;;OAGG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,IAAI,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;IACf,yCAAyC;IACzC,KAAK,EAAE,eAAe,CAAC;IACvB,8DAA8D;IAC9D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,aAAa,CAAC;AAE3D;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,YAAY,CAAC,CAU1E,CAAC;AA2CF;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqC;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2B;gBAE7C,OAAO,EAAE,uBAAuB;IAY5C;;;;;;;;OAQG;IACH,UAAU,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,aAAa;IAe9D,6DAA6D;IAC7D,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAQnC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-capability token-bucket rate limiter. SPEC §5 extension (v0.3.0+).
|
|
3
|
+
*
|
|
4
|
+
* v0.7 of the surface glues used a single global bucket. v0.8 splits the
|
|
5
|
+
* bucket per {@link CapabilityClass}: read-heavy work doesn't get blocked
|
|
6
|
+
* by a writes burst, and an exfil pattern (lots of credential reads +
|
|
7
|
+
* network-egress writes) hits the narrow buckets long before the global
|
|
8
|
+
* rate.
|
|
9
|
+
*
|
|
10
|
+
* A normal-workload session sees zero impact at the conservative defaults
|
|
11
|
+
* documented below. The buckets only bite on bursts that match the exfil
|
|
12
|
+
* shape.
|
|
13
|
+
*
|
|
14
|
+
* Pure mechanism: N token buckets, one per class. Same arithmetic, more
|
|
15
|
+
* dimensions.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Library-recommended defaults. Tuned to never trip normal CLI workloads
|
|
19
|
+
* (read/write at human-edit speed, occasional outbound calls) while
|
|
20
|
+
* catching exfil-shaped bursts in the seconds-window.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_BUCKETS = {
|
|
23
|
+
read: { maxCallsPerSecond: 50 },
|
|
24
|
+
write: { maxCallsPerSecond: 10 },
|
|
25
|
+
delete: { maxCallsPerSecond: 1 },
|
|
26
|
+
execute: { maxCallsPerSecond: 5 },
|
|
27
|
+
'network-egress': { maxCallsPerSecond: 5 },
|
|
28
|
+
'network-ingress': { maxCallsPerSecond: 50 },
|
|
29
|
+
credential: { maxCallsPerSecond: 2 },
|
|
30
|
+
'system-path': { maxCallsPerSecond: 1 },
|
|
31
|
+
bulk: { maxCallsPerSecond: 2 },
|
|
32
|
+
};
|
|
33
|
+
class Bucket {
|
|
34
|
+
refillPerMs;
|
|
35
|
+
capacity;
|
|
36
|
+
now;
|
|
37
|
+
tokens;
|
|
38
|
+
lastRefill;
|
|
39
|
+
constructor(config, now) {
|
|
40
|
+
this.refillPerMs = config.maxCallsPerSecond / 1000;
|
|
41
|
+
this.capacity = config.bucketCapacity ?? config.maxCallsPerSecond;
|
|
42
|
+
this.now = now;
|
|
43
|
+
this.tokens = this.capacity;
|
|
44
|
+
this.lastRefill = this.now();
|
|
45
|
+
}
|
|
46
|
+
tryConsume() {
|
|
47
|
+
this.refill();
|
|
48
|
+
if (this.tokens >= 1) {
|
|
49
|
+
this.tokens -= 1;
|
|
50
|
+
return { allowed: true };
|
|
51
|
+
}
|
|
52
|
+
const needed = 1 - this.tokens;
|
|
53
|
+
const retryAfterMs = Math.ceil(needed / this.refillPerMs);
|
|
54
|
+
return { allowed: false, retryAfterMs };
|
|
55
|
+
}
|
|
56
|
+
/** Visible for tests. */
|
|
57
|
+
currentTokens() {
|
|
58
|
+
this.refill();
|
|
59
|
+
return this.tokens;
|
|
60
|
+
}
|
|
61
|
+
refill() {
|
|
62
|
+
const t = this.now();
|
|
63
|
+
const elapsed = t - this.lastRefill;
|
|
64
|
+
if (elapsed <= 0)
|
|
65
|
+
return;
|
|
66
|
+
this.tokens = Math.min(this.capacity, this.tokens + elapsed * this.refillPerMs);
|
|
67
|
+
this.lastRefill = t;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Per-capability rate limiter. One {@link Bucket} per class; multi-class
|
|
72
|
+
* tools consume from every relevant bucket atomically (first denial wins;
|
|
73
|
+
* earlier-class buckets already consumed are NOT refunded).
|
|
74
|
+
*
|
|
75
|
+
* "First denial wins, no refund" matches the safety-conservative
|
|
76
|
+
* interpretation: a multi-class tool that's blocked on its rarest
|
|
77
|
+
* capability is fully blocked. The slightly-tighter accounting on
|
|
78
|
+
* already-consumed buckets is acceptable because it errs on the side of
|
|
79
|
+
* slowing the caller (not letting more through).
|
|
80
|
+
*/
|
|
81
|
+
export class MultiRateLimiter {
|
|
82
|
+
buckets = new Map();
|
|
83
|
+
defaultBucket;
|
|
84
|
+
now;
|
|
85
|
+
configMap;
|
|
86
|
+
defaultConfig;
|
|
87
|
+
constructor(options) {
|
|
88
|
+
this.now = options.now ?? Date.now;
|
|
89
|
+
this.configMap = new Map(Object.entries(options.buckets));
|
|
90
|
+
this.defaultConfig = options.defaultBucket;
|
|
91
|
+
if (this.defaultConfig !== undefined) {
|
|
92
|
+
this.defaultBucket = new Bucket(this.defaultConfig, this.now);
|
|
93
|
+
}
|
|
94
|
+
for (const [cls, cfg] of this.configMap.entries()) {
|
|
95
|
+
this.buckets.set(cls, new Bucket(cfg, this.now));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Attempt to consume one token from every relevant bucket. If ANY bucket
|
|
100
|
+
* is empty, return the FIRST class to deny (in iteration order of
|
|
101
|
+
* `classes`). Tokens already consumed from earlier classes in this call
|
|
102
|
+
* are not refunded — see class JSDoc.
|
|
103
|
+
*
|
|
104
|
+
* `unknown` (or any class not in `buckets` and no `defaultBucket`)
|
|
105
|
+
* passes through allowed.
|
|
106
|
+
*/
|
|
107
|
+
tryConsume(classes) {
|
|
108
|
+
for (const cls of classes) {
|
|
109
|
+
let bucket = this.buckets.get(cls);
|
|
110
|
+
if (!bucket && this.defaultBucket) {
|
|
111
|
+
bucket = this.defaultBucket;
|
|
112
|
+
}
|
|
113
|
+
if (!bucket)
|
|
114
|
+
continue; // no policy for this class → allowed
|
|
115
|
+
const r = bucket.tryConsume();
|
|
116
|
+
if (!r.allowed) {
|
|
117
|
+
return { allowed: false, class: cls, retryAfterMs: r.retryAfterMs };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { allowed: true };
|
|
121
|
+
}
|
|
122
|
+
/** Current token count per class (tests + introspection). */
|
|
123
|
+
snapshot() {
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const [cls, bucket] of this.buckets.entries()) {
|
|
126
|
+
out[cls] = bucket.currentTokens();
|
|
127
|
+
}
|
|
128
|
+
if (this.defaultBucket)
|
|
129
|
+
out['_default'] = this.defaultBucket.currentTokens();
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=multi-rate-limiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-rate-limiter.js","sourceRoot":"","sources":["../../src/runtime/multi-rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4CH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAmD;IAC7E,IAAI,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE;IAC/B,KAAK,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE;IAChC,MAAM,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;IAChC,OAAO,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;IACjC,gBAAgB,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;IAC1C,iBAAiB,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE;IAC5C,UAAU,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;IACpC,aAAa,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;IACvC,IAAI,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE;CAC/B,CAAC;AAEF,MAAM,MAAM;IACO,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,GAAG,CAAe;IAC3B,MAAM,CAAS;IACf,UAAU,CAAS;IAE3B,YAAY,MAAoB,EAAE,GAAiB;QACjD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,iBAAiB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AAC;gBACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC;YACtE,CAAC;QACH,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,6DAA6D;IAC7D,QAAQ;QACN,MAAM,GAAG,GAA2B,EAAE,CAAC;QACvC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YACnD,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,aAAa;YAAE,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;QAC7E,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GuardianRuntime — the orchestrator. SPEC §4 / §5.
|
|
3
|
+
*
|
|
4
|
+
* v0.1.0 scope: tool wrapping + audit emission + EStopLocal coordination.
|
|
5
|
+
* Policy and gate are introduced in v0.2/v0.3; v0.1 emits a pre-approved
|
|
6
|
+
* policy_check + tool_result for every tool call so the wire shape is correct
|
|
7
|
+
* even before policy enforcement is wired.
|
|
8
|
+
*/
|
|
9
|
+
import type { AuditLogWriter } from '../audit/writer.js';
|
|
10
|
+
import type { ModelAttribution } from '../types.js';
|
|
11
|
+
import type { EStopLocal } from '../estop/local.js';
|
|
12
|
+
import type { EStopPressOptions } from '../estop/types.js';
|
|
13
|
+
import { type HoneytokenSet } from './honeytokens.js';
|
|
14
|
+
import { CapabilityWindow, type CapabilityClass, type CapabilityRule } from './capability.js';
|
|
15
|
+
import { type OperatorConfirmationGate } from '../gate/two-key.js';
|
|
16
|
+
export interface GuardianRuntimeOptions {
|
|
17
|
+
agentId: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
audit: AuditLogWriter;
|
|
20
|
+
estop?: EStopLocal;
|
|
21
|
+
defaultModel?: ModelAttribution;
|
|
22
|
+
/**
|
|
23
|
+
* Honeytoken set scanned against every tool call. A hit fires
|
|
24
|
+
* `x_honeytoken_triggered` + presses the EStop (if configured) + throws
|
|
25
|
+
* `GuardianHaltedError`. SPEC §11. v0.3.0+.
|
|
26
|
+
*/
|
|
27
|
+
honeytokens?: HoneytokenSet;
|
|
28
|
+
/**
|
|
29
|
+
* Capability rules evaluated after every dispatched tool call. v0.8 ships
|
|
30
|
+
* Yellow-line only (audit-row, no behavior change). SPEC §4. v0.3.0+.
|
|
31
|
+
*/
|
|
32
|
+
capabilityRules?: CapabilityRule[];
|
|
33
|
+
/**
|
|
34
|
+
* Two-key operator gate. When set, tools marked
|
|
35
|
+
* `requiresOperatorConfirmation: true` will suspend pending operator
|
|
36
|
+
* approval. SPEC §4.5. v0.4.0+.
|
|
37
|
+
*/
|
|
38
|
+
operatorGate?: OperatorConfirmationGate;
|
|
39
|
+
/** Default timeout for operator confirmations. Default 5 minutes. */
|
|
40
|
+
operatorTimeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface ToolOptions {
|
|
43
|
+
name?: string;
|
|
44
|
+
model?: ModelAttribution;
|
|
45
|
+
/**
|
|
46
|
+
* Capability classes this tool exercises. The runtime feeds these into
|
|
47
|
+
* the {@link CapabilityWindow} after each dispatch so rule combinations
|
|
48
|
+
* can fire `x_capability_yellow` (v0.8) / `x_capability_redline` (v0.10).
|
|
49
|
+
*
|
|
50
|
+
* Untagged tools are recorded with `['unknown']` so they participate in
|
|
51
|
+
* window accounting but never match consumer-defined combinations
|
|
52
|
+
* (unless a rule deliberately names `'unknown'`).
|
|
53
|
+
*/
|
|
54
|
+
capabilities?: CapabilityClass[];
|
|
55
|
+
/**
|
|
56
|
+
* When true, the runtime suspends the call before dispatch and calls
|
|
57
|
+
* the configured `operatorGate`. The gate's `denied` response (including
|
|
58
|
+
* timeout-as-denied) throws `GuardianHaltedError`. SPEC §4.5. v0.4.0+.
|
|
59
|
+
*
|
|
60
|
+
* Setting this true with no operator gate configured throws — that's
|
|
61
|
+
* a configuration error, not a runtime fail-closed.
|
|
62
|
+
*/
|
|
63
|
+
requiresOperatorConfirmation?: boolean;
|
|
64
|
+
/** Free-text reason recorded on the pending audit row. */
|
|
65
|
+
operatorConfirmationReason?: string;
|
|
66
|
+
/** Per-call timeout override (ms). Default = runtime's operatorTimeoutMs. */
|
|
67
|
+
operatorConfirmationTimeoutMs?: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class GuardianRuntime {
|
|
70
|
+
readonly agentId: string;
|
|
71
|
+
readonly sessionId: string;
|
|
72
|
+
readonly audit: AuditLogWriter;
|
|
73
|
+
readonly estop: EStopLocal | undefined;
|
|
74
|
+
readonly defaultModel: ModelAttribution | undefined;
|
|
75
|
+
readonly honeytokens: HoneytokenSet | undefined;
|
|
76
|
+
readonly capabilityWindow: CapabilityWindow | undefined;
|
|
77
|
+
readonly operatorGate: OperatorConfirmationGate | undefined;
|
|
78
|
+
readonly operatorTimeoutMs: number;
|
|
79
|
+
private sessionOpened;
|
|
80
|
+
private closed;
|
|
81
|
+
constructor(options: GuardianRuntimeOptions);
|
|
82
|
+
/** Open the session. Idempotent. Emits session_open. */
|
|
83
|
+
openSession(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Wrap a tool function. Returned function intercepts every call.
|
|
86
|
+
* SPEC §2.4 — emits the documented event sequence.
|
|
87
|
+
*/
|
|
88
|
+
tool<Args extends unknown[], Result>(fn: (...args: Args) => Promise<Result> | Result, opts?: ToolOptions): (...args: Args) => Promise<Result>;
|
|
89
|
+
/** Trip the local emergency-stop. No-op if no EStopLocal was provided. */
|
|
90
|
+
pressEStop(options: EStopPressOptions): Promise<void>;
|
|
91
|
+
/** Close the runtime: emit session_close, drain audit queue. Idempotent. */
|
|
92
|
+
close(): Promise<void>;
|
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ianRuntime — the orchestrator. SPEC §4 / §5.
|
|
3
|
+
*
|
|
4
|
+
* v0.1.0 scope: tool wrapping + audit emission + EStopLocal coordination.
|
|
5
|
+
* Policy and gate are introduced in v0.2/v0.3; v0.1 emits a pre-approved
|
|
6
|
+
* policy_check + tool_result for every tool call so the wire shape is correct
|
|
7
|
+
* even before policy enforcement is wired.
|
|
8
|
+
*/
|
|
9
|
+
import { ulid } from 'ulidx';
|
|
10
|
+
import { GuardianHaltedError } from '../errors.js';
|
|
11
|
+
import { checkHoneytoken } from './honeytokens.js';
|
|
12
|
+
import { CapabilityWindow } from './capability.js';
|
|
13
|
+
import { awaitWithTimeout, newGateId, } from '../gate/two-key.js';
|
|
14
|
+
export class GuardianRuntime {
|
|
15
|
+
agentId;
|
|
16
|
+
sessionId;
|
|
17
|
+
audit;
|
|
18
|
+
estop;
|
|
19
|
+
defaultModel;
|
|
20
|
+
honeytokens;
|
|
21
|
+
capabilityWindow;
|
|
22
|
+
operatorGate;
|
|
23
|
+
operatorTimeoutMs;
|
|
24
|
+
sessionOpened = false;
|
|
25
|
+
closed = false;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.agentId = options.agentId;
|
|
28
|
+
this.sessionId = options.sessionId ?? 'sess_' + ulid();
|
|
29
|
+
this.audit = options.audit;
|
|
30
|
+
this.estop = options.estop;
|
|
31
|
+
this.defaultModel = options.defaultModel;
|
|
32
|
+
this.honeytokens = options.honeytokens;
|
|
33
|
+
this.capabilityWindow =
|
|
34
|
+
options.capabilityRules && options.capabilityRules.length > 0
|
|
35
|
+
? new CapabilityWindow({ rules: options.capabilityRules })
|
|
36
|
+
: undefined;
|
|
37
|
+
this.operatorGate = options.operatorGate;
|
|
38
|
+
this.operatorTimeoutMs = options.operatorTimeoutMs ?? 5 * 60 * 1000;
|
|
39
|
+
}
|
|
40
|
+
/** Open the session. Idempotent. Emits session_open. */
|
|
41
|
+
async openSession() {
|
|
42
|
+
if (this.sessionOpened)
|
|
43
|
+
return;
|
|
44
|
+
this.sessionOpened = true;
|
|
45
|
+
await this.audit.append({
|
|
46
|
+
kind: 'session_open',
|
|
47
|
+
status: 'approved',
|
|
48
|
+
initiator: 'system',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Wrap a tool function. Returned function intercepts every call.
|
|
53
|
+
* SPEC §2.4 — emits the documented event sequence.
|
|
54
|
+
*/
|
|
55
|
+
tool(fn, opts) {
|
|
56
|
+
const toolName = opts?.name ?? fn.name;
|
|
57
|
+
if (toolName === '' || toolName === undefined) {
|
|
58
|
+
throw new Error('tool() requires a name (either fn.name or opts.name)');
|
|
59
|
+
}
|
|
60
|
+
if (toolName.startsWith('guardian.') ||
|
|
61
|
+
toolName.startsWith('runtime.') ||
|
|
62
|
+
toolName.startsWith('internal.')) {
|
|
63
|
+
throw new Error(`tool name "${toolName}" uses a reserved prefix`);
|
|
64
|
+
}
|
|
65
|
+
return async (...args) => {
|
|
66
|
+
if (!this.sessionOpened) {
|
|
67
|
+
await this.openSession();
|
|
68
|
+
}
|
|
69
|
+
// Honeytoken check fires BEFORE the halt check + audit. A honeytoken
|
|
70
|
+
// hit is itself a halt trigger: we record x_honeytoken_triggered,
|
|
71
|
+
// press the estop (if configured), and throw. Subsequent calls then
|
|
72
|
+
// see the pressed estop and refuse on the normal path.
|
|
73
|
+
if (this.honeytokens) {
|
|
74
|
+
const hit = checkHoneytoken(this.honeytokens, toolName, argsToObject(args));
|
|
75
|
+
if (hit !== null) {
|
|
76
|
+
await this.audit.append({
|
|
77
|
+
kind: 'x_honeytoken_triggered',
|
|
78
|
+
status: 'halted',
|
|
79
|
+
initiator: 'system',
|
|
80
|
+
tool: { name: toolName, args: argsToObject(args) },
|
|
81
|
+
detail: {
|
|
82
|
+
set_id: this.honeytokens.id,
|
|
83
|
+
hit_kind: hit.kind,
|
|
84
|
+
...(hit.kind === 'value_in_args' ? { token_id: hit.tokenId } : {}),
|
|
85
|
+
...(hit.kind === 'phantom_tool' ? { tool_name: hit.toolName } : {}),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (this.estop) {
|
|
89
|
+
const reason = hit.kind === 'value_in_args'
|
|
90
|
+
? `honeytoken:${hit.tokenId}`
|
|
91
|
+
: `honeytoken:phantom_tool:${hit.toolName}`;
|
|
92
|
+
await this.estop.press({ reason, initiator: 'system' });
|
|
93
|
+
}
|
|
94
|
+
throw new GuardianHaltedError(`tool call rejected: honeytoken triggered (${hit.kind})`, 'honeytoken');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Halt check first: if pressed, refuse the call before any audit churn.
|
|
98
|
+
if (this.estop?.isPressed()) {
|
|
99
|
+
await this.audit.append({
|
|
100
|
+
kind: 'policy_check',
|
|
101
|
+
status: 'halted',
|
|
102
|
+
initiator: 'system',
|
|
103
|
+
tool: { name: toolName, args: argsToObject(args) },
|
|
104
|
+
detail: { reason: 'estop' },
|
|
105
|
+
});
|
|
106
|
+
throw new GuardianHaltedError(`tool call rejected: emergency stop active`, this.estop.getState().pressedReason);
|
|
107
|
+
}
|
|
108
|
+
// Two-key operator authorization. SPEC §4.5. Fires BEFORE tool_call
|
|
109
|
+
// (pending_operator means we haven't decided to dispatch yet).
|
|
110
|
+
// Sequence: pending_operator → gate awaits → approved or denied,
|
|
111
|
+
// all three rows share the same gate_id for correlation.
|
|
112
|
+
if (opts?.requiresOperatorConfirmation) {
|
|
113
|
+
if (!this.operatorGate) {
|
|
114
|
+
throw new Error(`tool ${JSON.stringify(toolName)} requires operator confirmation but no operatorGate is configured on the runtime`);
|
|
115
|
+
}
|
|
116
|
+
const gateId = newGateId();
|
|
117
|
+
const timeoutMs = opts.operatorConfirmationTimeoutMs ?? this.operatorTimeoutMs;
|
|
118
|
+
const reason = opts.operatorConfirmationReason ?? 'unspecified';
|
|
119
|
+
await this.audit.append({
|
|
120
|
+
kind: 'policy_check',
|
|
121
|
+
status: 'pending_operator',
|
|
122
|
+
initiator: 'system',
|
|
123
|
+
tool: { name: toolName, args: argsToObject(args) },
|
|
124
|
+
detail: { gate_id: gateId, timeout_ms: timeoutMs, reason },
|
|
125
|
+
});
|
|
126
|
+
const response = await awaitWithTimeout(this.operatorGate, {
|
|
127
|
+
gate_id: gateId,
|
|
128
|
+
tool_name: toolName,
|
|
129
|
+
tool_args: argsToObject(args),
|
|
130
|
+
reason,
|
|
131
|
+
timeout_ms: timeoutMs,
|
|
132
|
+
agent_id: this.agentId,
|
|
133
|
+
session_id: this.sessionId,
|
|
134
|
+
});
|
|
135
|
+
const resolutionDetail = { gate_id: gateId };
|
|
136
|
+
if (response.operator_id !== undefined) {
|
|
137
|
+
resolutionDetail.operator_id = response.operator_id;
|
|
138
|
+
}
|
|
139
|
+
if (response.reason !== undefined) {
|
|
140
|
+
resolutionDetail.reason = response.reason;
|
|
141
|
+
}
|
|
142
|
+
await this.audit.append({
|
|
143
|
+
kind: 'policy_check',
|
|
144
|
+
status: response.decision,
|
|
145
|
+
initiator: 'operator',
|
|
146
|
+
tool: { name: toolName, args: argsToObject(args) },
|
|
147
|
+
detail: resolutionDetail,
|
|
148
|
+
});
|
|
149
|
+
if (response.decision === 'denied') {
|
|
150
|
+
throw new GuardianHaltedError(`tool call rejected: operator ${response.reason === 'timeout' ? 'confirmation timed out' : 'denied'}`, `operator:${response.reason ?? 'denied'}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const model = opts?.model ?? this.defaultModel;
|
|
154
|
+
const capabilities = opts?.capabilities ?? ['unknown'];
|
|
155
|
+
// Build the shared tool sub-object once so capabilities are present
|
|
156
|
+
// on every record this dispatch produces (tool_call, policy_check,
|
|
157
|
+
// tool_result). audit consumers can read the capability tags without
|
|
158
|
+
// consulting an external tagging table.
|
|
159
|
+
const toolBase = {
|
|
160
|
+
name: toolName,
|
|
161
|
+
args: argsToObject(args),
|
|
162
|
+
capabilities,
|
|
163
|
+
};
|
|
164
|
+
// 1. tool_call (pending)
|
|
165
|
+
const callRecord = await this.audit.append({
|
|
166
|
+
kind: 'tool_call',
|
|
167
|
+
status: 'pending',
|
|
168
|
+
initiator: 'agent',
|
|
169
|
+
tool: toolBase,
|
|
170
|
+
...(model === undefined ? {} : { model: modelToWire(model) }),
|
|
171
|
+
});
|
|
172
|
+
// Capability-window accounting + Yellow-line evaluation. Records
|
|
173
|
+
// every dispatched call; fires per-rule matches. v0.8: audit-only —
|
|
174
|
+
// matches do NOT change dispatch behavior. The matches are captured
|
|
175
|
+
// here so the post-dispatch hook can write `x_capability_yellow`
|
|
176
|
+
// adjacent to the tool_call event for forensic clarity.
|
|
177
|
+
const capabilityMatches = this.capabilityWindow
|
|
178
|
+
? this.capabilityWindow.record(capabilities, callRecord.event_id)
|
|
179
|
+
: [];
|
|
180
|
+
for (const match of capabilityMatches) {
|
|
181
|
+
await this.audit.append({
|
|
182
|
+
kind: (match.level === 'yellow'
|
|
183
|
+
? 'x_capability_yellow'
|
|
184
|
+
: 'x_capability_redline'),
|
|
185
|
+
status: 'approved',
|
|
186
|
+
initiator: 'system',
|
|
187
|
+
tool: toolBase,
|
|
188
|
+
detail: {
|
|
189
|
+
rule_id: match.ruleId,
|
|
190
|
+
combination: match.combination,
|
|
191
|
+
window_ms: match.window_ms,
|
|
192
|
+
contributing_event_ids: match.contributingEventIds,
|
|
193
|
+
tool_capabilities: capabilities,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
// v0.8: Yellow does not change behavior. Red-line auto-stop ships
|
|
197
|
+
// in v0.10 — explicitly NOT wired here. When v0.10 lands, the
|
|
198
|
+
// estop.press() call goes inside this `if`.
|
|
199
|
+
}
|
|
200
|
+
// 2. policy_check (approved) — v0.1 is fail-open; v0.2 wires real policy.
|
|
201
|
+
await this.audit.append({
|
|
202
|
+
kind: 'policy_check',
|
|
203
|
+
status: 'approved',
|
|
204
|
+
initiator: 'system',
|
|
205
|
+
tool: toolBase,
|
|
206
|
+
detail: { matched_at: 'default' },
|
|
207
|
+
});
|
|
208
|
+
// 3. execute
|
|
209
|
+
const startMs = Date.now();
|
|
210
|
+
let result;
|
|
211
|
+
try {
|
|
212
|
+
result = await fn(...args);
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
const durationMs = Date.now() - startMs;
|
|
216
|
+
await this.audit.append({
|
|
217
|
+
kind: 'tool_result',
|
|
218
|
+
status: 'errored',
|
|
219
|
+
initiator: 'system',
|
|
220
|
+
tool: { ...toolBase, duration_ms: durationMs },
|
|
221
|
+
detail: { error: err instanceof Error ? err.message : String(err) },
|
|
222
|
+
});
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
const durationMs = Date.now() - startMs;
|
|
226
|
+
await this.audit.append({
|
|
227
|
+
kind: 'tool_result',
|
|
228
|
+
status: 'executed',
|
|
229
|
+
initiator: 'system',
|
|
230
|
+
tool: { ...toolBase, result, duration_ms: durationMs },
|
|
231
|
+
});
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** Trip the local emergency-stop. No-op if no EStopLocal was provided. */
|
|
236
|
+
async pressEStop(options) {
|
|
237
|
+
if (!this.estop) {
|
|
238
|
+
throw new Error('GuardianRuntime constructed without an EStopLocal');
|
|
239
|
+
}
|
|
240
|
+
await this.estop.press(options);
|
|
241
|
+
}
|
|
242
|
+
/** Close the runtime: emit session_close, drain audit queue. Idempotent. */
|
|
243
|
+
async close() {
|
|
244
|
+
if (this.closed)
|
|
245
|
+
return;
|
|
246
|
+
this.closed = true;
|
|
247
|
+
if (this.sessionOpened) {
|
|
248
|
+
await this.audit.append({
|
|
249
|
+
kind: 'session_close',
|
|
250
|
+
status: 'approved',
|
|
251
|
+
initiator: 'system',
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
await this.audit.close();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function argsToObject(args) {
|
|
258
|
+
// Wire shape requires args to be an object. We wrap positional args as
|
|
259
|
+
// { "0": ..., "1": ..., ... } for stable serialization.
|
|
260
|
+
const out = {};
|
|
261
|
+
for (let i = 0; i < args.length; i++) {
|
|
262
|
+
out[String(i)] = args[i];
|
|
263
|
+
}
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
function modelToWire(model) {
|
|
267
|
+
return {
|
|
268
|
+
provider: model.provider,
|
|
269
|
+
id: model.id,
|
|
270
|
+
...(model.surface === undefined ? {} : { surface: model.surface }),
|
|
271
|
+
...(model.aggregator === undefined ? {} : { aggregator: model.aggregator }),
|
|
272
|
+
...(model.inputTokens === undefined ? {} : { input_tokens: model.inputTokens }),
|
|
273
|
+
...(model.outputTokens === undefined ? {} : { output_tokens: model.outputTokens }),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAA6C,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EACL,gBAAgB,EAChB,SAAS,GAEV,MAAM,oBAAoB,CAAC;AAyD5B,MAAM,OAAO,eAAe;IACjB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,KAAK,CAAiB;IACtB,KAAK,CAAyB;IAC9B,YAAY,CAA+B;IAC3C,WAAW,CAA4B;IACvC,gBAAgB,CAA+B;IAC/C,YAAY,CAAuC;IACnD,iBAAiB,CAAS;IAE3B,aAAa,GAAG,KAAK,CAAC;IACtB,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO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EC_VERSION: "0.2.0";
|
|
5
|
+
export type AuditRecordKind = 'session_open' | 'tool_call' | 'gate_request' | 'gate_response' | 'policy_check' | 'tool_result' | 'estop_press' | 'estop_clear' | 'session_close';
|
|
6
|
+
export type AuditRecordStatus = 'pending' | 'approved' | 'denied' | 'executed' | 'errored' | 'halted'
|
|
7
|
+
/**
|
|
8
|
+
* Tool dispatch is suspended awaiting operator confirmation. SPEC §4.5
|
|
9
|
+
* (v0.4.0+). The matching resolution row writes `approved` or `denied`
|
|
10
|
+
* with the same `detail.gate_id`.
|
|
11
|
+
*/
|
|
12
|
+
| 'pending_operator';
|
|
13
|
+
export type AuditRecordInitiator = 'operator' | 'agent' | 'system';
|
|
14
|
+
/**
|
|
15
|
+
* Identifies which model issued a tool call. SPEC §2.3.
|
|
16
|
+
*
|
|
17
|
+
* The optional `surface` and `aggregator` fields (v0.7+) extend the basic
|
|
18
|
+
* `provider/id` pair with the chain that delivered the call:
|
|
19
|
+
*
|
|
20
|
+
* surface — which FlowDot surface (or third-party harness) is hosting
|
|
21
|
+
* the agent (e.g., 'FlowDot', 'FlowDotMobile', 'cursor').
|
|
22
|
+
* aggregator — the optional intermediary that routed the request
|
|
23
|
+
* (e.g., 'RedPill', 'OpenRouter'). `'direct'` is the
|
|
24
|
+
* convention when no aggregator is in the path.
|
|
25
|
+
* provider — the model vendor (e.g., 'Anthropic', 'OpenAI').
|
|
26
|
+
* id — the specific model id (e.g., 'claude-opus-4.5').
|
|
27
|
+
*
|
|
28
|
+
* Rendered as `surface/aggregator/provider/id` (see
|
|
29
|
+
* `policy/attribution.ts:renderAttributionPath`) for glob-based policy rules.
|
|
30
|
+
*
|
|
31
|
+
* Missing segments render as `'*'`. Old call sites that only supply
|
|
32
|
+
* `{provider, id}` continue to work and render as `*\/*\/<provider>/<id>`.
|
|
33
|
+
*/
|
|
34
|
+
export interface ModelAttribution {
|
|
35
|
+
provider: string;
|
|
36
|
+
id: string;
|
|
37
|
+
surface?: string;
|
|
38
|
+
aggregator?: string;
|
|
39
|
+
inputTokens?: number;
|
|
40
|
+
outputTokens?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tool sub-object on relevant event kinds. SPEC §2.3.
|
|
44
|
+
*/
|
|
45
|
+
export interface AuditRecordTool {
|
|
46
|
+
name: string;
|
|
47
|
+
args: Record<string, unknown>;
|
|
48
|
+
result?: unknown;
|
|
49
|
+
durationMs?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The audit record itself. Every line in the JSONL log is one of these.
|
|
53
|
+
* Field names match the wire spec (snake_case) for cross-language interop.
|
|
54
|
+
*/
|
|
55
|
+
export interface AuditRecord {
|
|
56
|
+
v: string;
|
|
57
|
+
event_id: string;
|
|
58
|
+
ts: string;
|
|
59
|
+
agent_id: string;
|
|
60
|
+
session_id: string;
|
|
61
|
+
kind: AuditRecordKind;
|
|
62
|
+
tool?: {
|
|
63
|
+
name: string;
|
|
64
|
+
args: Record<string, unknown>;
|
|
65
|
+
result?: unknown;
|
|
66
|
+
duration_ms?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Capability classes for the dispatched tool. Recorded on `tool_call`
|
|
69
|
+
* (and forwarded on `tool_result`) so audit consumers can correlate
|
|
70
|
+
* a call with its declared capabilities without consulting an external
|
|
71
|
+
* tagging table. SPEC §13.1. v0.3.0+.
|
|
72
|
+
*/
|
|
73
|
+
capabilities?: string[];
|
|
74
|
+
};
|
|
75
|
+
model?: {
|
|
76
|
+
provider: string;
|
|
77
|
+
id: string;
|
|
78
|
+
surface?: string;
|
|
79
|
+
aggregator?: string;
|
|
80
|
+
input_tokens?: number;
|
|
81
|
+
output_tokens?: number;
|
|
82
|
+
};
|
|
83
|
+
status: AuditRecordStatus;
|
|
84
|
+
initiator: AuditRecordInitiator;
|
|
85
|
+
prev_hash: string;
|
|
86
|
+
signature?: string | null;
|
|
87
|
+
/** Optional free-form structured details (e.g., gate decision, estop reason). */
|
|
88
|
+
detail?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The fields a caller supplies. The writer fills in the rest.
|
|
92
|
+
*/
|
|
93
|
+
export type AuditRecordInput = Omit<AuditRecord, 'v' | 'event_id' | 'ts' | 'agent_id' | 'session_id' | 'prev_hash' | 'signature'> & {
|
|
94
|
+
agentId?: string;
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,YAAY,EAAG,OAAgB,CAAC;AAE7C,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,WAAW,GACX,cAAc,GACd,eAAe,GACf,cAAc,GACd,aAAa,GACb,aAAa,GACb,aAAa,GACb,eAAe,CAAC;AAEpB,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,UAAU,GACV,QAAQ,GACR,UAAU,GACV,SAAS,GACT,QAAQ;AACV;;;;GAIG;GACD,kBAAkB,CAAC;AAEvB,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CA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