@execlave/sdk 1.7.0 → 1.8.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/README.md +16 -14
- package/dist/bypassReporter.d.ts +132 -0
- package/dist/bypassReporter.d.ts.map +1 -0
- package/dist/bypassReporter.js +275 -0
- package/dist/bypassReporter.js.map +1 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +77 -1
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/crewai.js +10 -0
- package/dist/integrations/crewai.js.map +1 -1
- package/dist/integrations/langchain.d.ts +1 -0
- package/dist/integrations/langchain.d.ts.map +1 -1
- package/dist/integrations/langchain.js +12 -0
- package/dist/integrations/langchain.js.map +1 -1
- package/dist/integrations/openai-agents.d.ts +2 -1
- package/dist/integrations/openai-agents.d.ts.map +1 -1
- package/dist/integrations/openai-agents.js +52 -11
- package/dist/integrations/openai-agents.js.map +1 -1
- package/dist/trace.d.ts +12 -1
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +15 -11
- package/dist/trace.js.map +1 -1
- package/dist/types.d.ts +34 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,20 +78,22 @@ await exe.shutdown();
|
|
|
78
78
|
|
|
79
79
|
## Configuration
|
|
80
80
|
|
|
81
|
-
| Option
|
|
82
|
-
|
|
|
83
|
-
| `apiKey`
|
|
84
|
-
| `baseUrl`
|
|
85
|
-
| `environment`
|
|
86
|
-
| `asyncMode`
|
|
87
|
-
| `batchSize`
|
|
88
|
-
| `flushIntervalMs`
|
|
89
|
-
| `debug`
|
|
90
|
-
| `enableControlChannel`
|
|
91
|
-
| `pollIntervalMs`
|
|
92
|
-
| `enableInjectionScan`
|
|
93
|
-
| `enforcementOnOutage`
|
|
94
|
-
| `
|
|
81
|
+
| Option | Type | Default | Description |
|
|
82
|
+
| -------------------------- | ----------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| `apiKey` | `string` | `EXECLAVE_API_KEY` env | API key (`exe_prod_xxx`) |
|
|
84
|
+
| `baseUrl` | `string` | `https://api.execlave.com` | Execlave API URL |
|
|
85
|
+
| `environment` | `string` | `production` | Deployment environment |
|
|
86
|
+
| `asyncMode` | `boolean` | `true` | Buffer traces for background flush |
|
|
87
|
+
| `batchSize` | `number` | `100` | Max traces per flush batch |
|
|
88
|
+
| `flushIntervalMs` | `number` | `10000` | Background flush interval |
|
|
89
|
+
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
90
|
+
| `enableControlChannel` | `boolean` | `true` | Poll agent status for kill-switch |
|
|
91
|
+
| `pollIntervalMs` | `number` | `15000` | Status poll interval |
|
|
92
|
+
| `enableInjectionScan` | `boolean` | `true` | Client-side injection scoring; tags traces with metadata. **Does NOT block LLM calls** — use a `block`-mode injection policy + `enforcePolicy()` to block. |
|
|
93
|
+
| `enforcementOnOutage` | `string` | `fail_open` | Behavior when enforcement API is unreachable: `fail_open` allows the call, `fail_closed` raises `EnforcementUnavailableError`. |
|
|
94
|
+
| `onEnforcementBypassed` | `(event) => void` | -- | Called once for every call that ran without a server enforcement decision (network error, 5xx, circuit breaker open, or plan limit under fail-open). |
|
|
95
|
+
| `reportBypassesToPlatform` | `boolean` | `true` | Also record each ungoverned window (coalesced per agent and reason) in your organisation's audit log as `enforcement.bypassed`. Set `false` to keep only the local callback. Requires 1.8.0+ and a platform that supports it. |
|
|
96
|
+
| `policyCacheTtlMs` | `number` | `60000` | TTL for cached policy decisions |
|
|
95
97
|
|
|
96
98
|
## API Reference
|
|
97
99
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports enforcement-bypass windows to the platform.
|
|
3
|
+
*
|
|
4
|
+
* The SDK defaults to `fail_open`: when the governance plane is unreachable, or
|
|
5
|
+
* the plan quota is exhausted, an action proceeds with no server enforcement
|
|
6
|
+
* decision. `onEnforcementBypassed` surfaces that locally, but until it was also
|
|
7
|
+
* sent to the server the platform's audit trail could not tell "all calls
|
|
8
|
+
* governed" from "the SDK lost contact for two hours" — no bypass record read as
|
|
9
|
+
* fully governed.
|
|
10
|
+
*
|
|
11
|
+
* Design: docs/superpowers/specs/2026-09-21-sdk-bypass-reporting-design.md
|
|
12
|
+
*
|
|
13
|
+
* - Bypasses are COALESCED into windows keyed by (agentId, reason). A per-call
|
|
14
|
+
* record would put thousands of rows a minute into a per-org hash chain.
|
|
15
|
+
* - Only CLOSED windows are sent, so a window is immutable once reported. A
|
|
16
|
+
* window closes on recovery (a governed decision for the agent), after an idle
|
|
17
|
+
* gap, or at a maximum duration — a long outage is many records, not one
|
|
18
|
+
* unbounded, mutable one.
|
|
19
|
+
* - Nothing here is on the enforcement path. Recording is synchronous and cheap;
|
|
20
|
+
* sending happens from a timer, and every method swallows its own errors.
|
|
21
|
+
* - Evidence is kept until the server acknowledges it, retried with backoff, and
|
|
22
|
+
* the buffer is bounded. When it overflows the oldest window is dropped and the
|
|
23
|
+
* LOSS is reported too, so the trail says "N bypasses were not reported"
|
|
24
|
+
* instead of staying silent.
|
|
25
|
+
*/
|
|
26
|
+
export type BypassReason = 'circuit_breaker_open' | 'network_error' | 'server_error' | 'plan_limit_exceeded';
|
|
27
|
+
/** What the SDK observed at one bypass. Timestamps are taken by the reporter. */
|
|
28
|
+
export interface BypassObservation {
|
|
29
|
+
reason: BypassReason;
|
|
30
|
+
/** The `fail_open_*` string — same vocabulary as `EnforceResult.source`. */
|
|
31
|
+
source: string;
|
|
32
|
+
agentId: string;
|
|
33
|
+
message?: string;
|
|
34
|
+
status?: number;
|
|
35
|
+
consecutiveFailures?: number;
|
|
36
|
+
}
|
|
37
|
+
/** One coalesced window, exactly as the server's schema expects it. */
|
|
38
|
+
export interface BypassWindow {
|
|
39
|
+
windowId: string;
|
|
40
|
+
agentId: string;
|
|
41
|
+
reason: BypassReason;
|
|
42
|
+
source: string;
|
|
43
|
+
/** Client clock. The server stores it as the SDK's claim. */
|
|
44
|
+
firstAt: string;
|
|
45
|
+
lastAt: string;
|
|
46
|
+
count: number;
|
|
47
|
+
status?: number;
|
|
48
|
+
message?: string;
|
|
49
|
+
consecutiveFailures?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface DroppedBypassReports {
|
|
52
|
+
dropId: string;
|
|
53
|
+
windows: number;
|
|
54
|
+
bypasses: number;
|
|
55
|
+
since?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface BypassReportBody {
|
|
58
|
+
sdk: {
|
|
59
|
+
name: string;
|
|
60
|
+
language: 'js';
|
|
61
|
+
version: string;
|
|
62
|
+
};
|
|
63
|
+
sentAt: string;
|
|
64
|
+
windows: BypassWindow[];
|
|
65
|
+
dropped?: DroppedBypassReports;
|
|
66
|
+
}
|
|
67
|
+
export interface BypassReporterOptions {
|
|
68
|
+
/** Resolves with the HTTP status; rejects on a network failure. */
|
|
69
|
+
send: (body: BypassReportBody) => Promise<{
|
|
70
|
+
status: number;
|
|
71
|
+
}>;
|
|
72
|
+
sdk: {
|
|
73
|
+
name: string;
|
|
74
|
+
language: 'js';
|
|
75
|
+
version: string;
|
|
76
|
+
};
|
|
77
|
+
/** No bypass for this long closes a window. Default 60 s. */
|
|
78
|
+
idleMs?: number;
|
|
79
|
+
/** A window never spans longer than this. Default 15 min. */
|
|
80
|
+
maxDurationMs?: number;
|
|
81
|
+
/** Closed windows held awaiting acknowledgement. Default 500. */
|
|
82
|
+
maxBufferedWindows?: number;
|
|
83
|
+
now?: () => number;
|
|
84
|
+
uuid?: () => string;
|
|
85
|
+
log?: (message: string) => void;
|
|
86
|
+
}
|
|
87
|
+
export declare class BypassWindowReporter {
|
|
88
|
+
private readonly send;
|
|
89
|
+
private readonly sdk;
|
|
90
|
+
private readonly idleMs;
|
|
91
|
+
private readonly maxDurationMs;
|
|
92
|
+
private readonly maxBuffered;
|
|
93
|
+
private readonly now;
|
|
94
|
+
private readonly uuid;
|
|
95
|
+
private readonly log;
|
|
96
|
+
private open;
|
|
97
|
+
private closed;
|
|
98
|
+
private liveDrop;
|
|
99
|
+
private pendingDrop;
|
|
100
|
+
private inflight;
|
|
101
|
+
private failures;
|
|
102
|
+
private nextAttemptAt;
|
|
103
|
+
constructor(opts: BypassReporterOptions);
|
|
104
|
+
/** Record one bypass. Synchronous, cheap, never throws. */
|
|
105
|
+
record(obs: BypassObservation): void;
|
|
106
|
+
/** The agent got a governed decision from the server: its windows are over. */
|
|
107
|
+
recover(agentId: string): void;
|
|
108
|
+
/** Close windows that have gone idle. Called from the timer. */
|
|
109
|
+
tick(): void;
|
|
110
|
+
/** True when there is anything closed (or a loss) waiting to be acknowledged. */
|
|
111
|
+
get hasPending(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Send everything closed until the server has acknowledged it, or a request
|
|
114
|
+
* fails. `force` skips the retry backoff (shutdown). Never throws.
|
|
115
|
+
*/
|
|
116
|
+
flush(opts?: {
|
|
117
|
+
force?: boolean;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Shutdown: close every open window and make a bounded, best-effort attempt to
|
|
121
|
+
* deliver. Gives up at the deadline rather than hanging process exit on an
|
|
122
|
+
* endpoint that is down — which is exactly when there is something to report.
|
|
123
|
+
*/
|
|
124
|
+
drain(opts: {
|
|
125
|
+
timeoutMs: number;
|
|
126
|
+
}): Promise<void>;
|
|
127
|
+
private close;
|
|
128
|
+
private run;
|
|
129
|
+
private acknowledge;
|
|
130
|
+
private fail;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=bypassReporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bypassReporter.d.ts","sourceRoot":"","sources":["../src/bypassReporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,MAAM,YAAY,GACpB,sBAAsB,GAC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E,IAAI,IAAI,IAAI;IAWZ,iFAAiF;IACjF,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD;;;;OAIG;IACG,KAAK,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBvD,OAAO,CAAC,KAAK;YAkBC,GAAG;IA8CjB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,IAAI;CAMb"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reports enforcement-bypass windows to the platform.
|
|
4
|
+
*
|
|
5
|
+
* The SDK defaults to `fail_open`: when the governance plane is unreachable, or
|
|
6
|
+
* the plan quota is exhausted, an action proceeds with no server enforcement
|
|
7
|
+
* decision. `onEnforcementBypassed` surfaces that locally, but until it was also
|
|
8
|
+
* sent to the server the platform's audit trail could not tell "all calls
|
|
9
|
+
* governed" from "the SDK lost contact for two hours" — no bypass record read as
|
|
10
|
+
* fully governed.
|
|
11
|
+
*
|
|
12
|
+
* Design: docs/superpowers/specs/2026-09-21-sdk-bypass-reporting-design.md
|
|
13
|
+
*
|
|
14
|
+
* - Bypasses are COALESCED into windows keyed by (agentId, reason). A per-call
|
|
15
|
+
* record would put thousands of rows a minute into a per-org hash chain.
|
|
16
|
+
* - Only CLOSED windows are sent, so a window is immutable once reported. A
|
|
17
|
+
* window closes on recovery (a governed decision for the agent), after an idle
|
|
18
|
+
* gap, or at a maximum duration — a long outage is many records, not one
|
|
19
|
+
* unbounded, mutable one.
|
|
20
|
+
* - Nothing here is on the enforcement path. Recording is synchronous and cheap;
|
|
21
|
+
* sending happens from a timer, and every method swallows its own errors.
|
|
22
|
+
* - Evidence is kept until the server acknowledges it, retried with backoff, and
|
|
23
|
+
* the buffer is bounded. When it overflows the oldest window is dropped and the
|
|
24
|
+
* LOSS is reported too, so the trail says "N bypasses were not reported"
|
|
25
|
+
* instead of staying silent.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.BypassWindowReporter = void 0;
|
|
29
|
+
// Bounds mirror the server's schema (backend/src/schema/sdkBypass.ts). A field
|
|
30
|
+
// over its limit would get the WHOLE report rejected, so it is truncated here.
|
|
31
|
+
const MAX_AGENT_ID = 256;
|
|
32
|
+
const MAX_SOURCE = 64;
|
|
33
|
+
const MAX_MESSAGE = 500;
|
|
34
|
+
const MAX_WINDOWS_PER_REQUEST = 100;
|
|
35
|
+
const MAX_COUNT = 1000000000;
|
|
36
|
+
// The server requires min length 1 for these; an empty value would get the
|
|
37
|
+
// whole report rejected.
|
|
38
|
+
const UNKNOWN = 'unknown';
|
|
39
|
+
// Postgres text/jsonb cannot store NUL or a lone UTF-16 surrogate. One such
|
|
40
|
+
// character makes the server's audit write fail, which reads as a retryable 5xx,
|
|
41
|
+
// so the window would be retried for ever and never recorded.
|
|
42
|
+
const REPLACEMENT = String.fromCharCode(0xfffd);
|
|
43
|
+
const UNSTORABLE = /\u0000|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
44
|
+
/** Cut to `max` UTF-16 units without leaving half an emoji, then make it storable. */
|
|
45
|
+
function sanitize(value, max) {
|
|
46
|
+
let out = value.slice(0, max);
|
|
47
|
+
const last = out.charCodeAt(out.length - 1);
|
|
48
|
+
if (out.length < value.length && last >= 0xd800 && last <= 0xdbff)
|
|
49
|
+
out = out.slice(0, -1);
|
|
50
|
+
return out.replace(UNSTORABLE, REPLACEMENT);
|
|
51
|
+
}
|
|
52
|
+
const BACKOFF_BASE_MS = 10000;
|
|
53
|
+
const BACKOFF_MAX_MS = 5 * 60000;
|
|
54
|
+
/**
|
|
55
|
+
* Statuses that mean "this body will never be accepted": resending is a loop, so
|
|
56
|
+
* the batch is discarded (and logged). Everything else — 5xx, 429, 408, auth
|
|
57
|
+
* errors, and 404 from a backend that does not have the endpoint yet — is kept
|
|
58
|
+
* and retried: the buffer is bounded, and the evidence is worth more than a
|
|
59
|
+
* request every few minutes.
|
|
60
|
+
*/
|
|
61
|
+
const NON_RETRYABLE = new Set([400, 413, 422]);
|
|
62
|
+
class BypassWindowReporter {
|
|
63
|
+
constructor(opts) {
|
|
64
|
+
this.open = new Map();
|
|
65
|
+
this.closed = [];
|
|
66
|
+
// Loss accounting. `pendingDrop` is the block currently awaiting acknowledgement:
|
|
67
|
+
// immutable, so a retry after a lost response reuses the same dropId and the
|
|
68
|
+
// server can recognise it. Drops that happen meanwhile accumulate in `liveDrop`.
|
|
69
|
+
this.liveDrop = {
|
|
70
|
+
windows: 0,
|
|
71
|
+
bypasses: 0,
|
|
72
|
+
};
|
|
73
|
+
this.pendingDrop = null;
|
|
74
|
+
this.inflight = null;
|
|
75
|
+
this.failures = 0;
|
|
76
|
+
this.nextAttemptAt = 0;
|
|
77
|
+
this.send = opts.send;
|
|
78
|
+
this.sdk = opts.sdk;
|
|
79
|
+
this.idleMs = opts.idleMs ?? 60000;
|
|
80
|
+
this.maxDurationMs = opts.maxDurationMs ?? 15 * 60000;
|
|
81
|
+
this.maxBuffered = opts.maxBufferedWindows ?? 500;
|
|
82
|
+
this.now = opts.now ?? Date.now;
|
|
83
|
+
this.uuid = opts.uuid ?? (() => require('crypto').randomUUID());
|
|
84
|
+
this.log = opts.log ?? (() => undefined);
|
|
85
|
+
}
|
|
86
|
+
/** Record one bypass. Synchronous, cheap, never throws. */
|
|
87
|
+
record(obs) {
|
|
88
|
+
try {
|
|
89
|
+
const t = this.now();
|
|
90
|
+
const agentId = sanitize(obs.agentId, MAX_AGENT_ID) || UNKNOWN;
|
|
91
|
+
const source = sanitize(obs.source, MAX_SOURCE) || UNKNOWN;
|
|
92
|
+
const key = `${agentId}\u0000${obs.reason}`;
|
|
93
|
+
const existing = this.open.get(key);
|
|
94
|
+
if (existing &&
|
|
95
|
+
(t - existing.lastMs >= this.idleMs || t - existing.firstMs >= this.maxDurationMs)) {
|
|
96
|
+
this.close(key);
|
|
97
|
+
}
|
|
98
|
+
const w = this.open.get(key);
|
|
99
|
+
if (w) {
|
|
100
|
+
w.count = Math.min(w.count + 1, MAX_COUNT);
|
|
101
|
+
w.lastMs = t;
|
|
102
|
+
w.lastAt = new Date(t).toISOString();
|
|
103
|
+
w.source = source;
|
|
104
|
+
if (obs.message !== undefined)
|
|
105
|
+
w.message = sanitize(obs.message, MAX_MESSAGE);
|
|
106
|
+
if (obs.status !== undefined)
|
|
107
|
+
w.status = obs.status;
|
|
108
|
+
if (obs.consecutiveFailures !== undefined)
|
|
109
|
+
w.consecutiveFailures = obs.consecutiveFailures;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const at = new Date(t).toISOString();
|
|
113
|
+
this.open.set(key, {
|
|
114
|
+
windowId: this.uuid(),
|
|
115
|
+
agentId,
|
|
116
|
+
reason: obs.reason,
|
|
117
|
+
source,
|
|
118
|
+
firstAt: at,
|
|
119
|
+
lastAt: at,
|
|
120
|
+
firstMs: t,
|
|
121
|
+
lastMs: t,
|
|
122
|
+
count: 1,
|
|
123
|
+
...(obs.status !== undefined ? { status: obs.status } : {}),
|
|
124
|
+
...(obs.message !== undefined ? { message: sanitize(obs.message, MAX_MESSAGE) } : {}),
|
|
125
|
+
...(obs.consecutiveFailures !== undefined
|
|
126
|
+
? { consecutiveFailures: obs.consecutiveFailures }
|
|
127
|
+
: {}),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
this.log(`bypass record failed: ${err.message}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** The agent got a governed decision from the server: its windows are over. */
|
|
135
|
+
recover(agentId) {
|
|
136
|
+
try {
|
|
137
|
+
const id = sanitize(agentId, MAX_AGENT_ID) || UNKNOWN;
|
|
138
|
+
for (const key of [...this.open.keys()]) {
|
|
139
|
+
if (key.startsWith(`${id}\u0000`))
|
|
140
|
+
this.close(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
this.log(`bypass recover failed: ${err.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Close windows that have gone idle. Called from the timer. */
|
|
148
|
+
tick() {
|
|
149
|
+
try {
|
|
150
|
+
const t = this.now();
|
|
151
|
+
for (const [key, w] of [...this.open]) {
|
|
152
|
+
if (t - w.lastMs >= this.idleMs || t - w.firstMs >= this.maxDurationMs)
|
|
153
|
+
this.close(key);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
this.log(`bypass tick failed: ${err.message}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** True when there is anything closed (or a loss) waiting to be acknowledged. */
|
|
161
|
+
get hasPending() {
|
|
162
|
+
return this.closed.length > 0 || this.pendingDrop !== null || this.liveDrop.windows > 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Send everything closed until the server has acknowledged it, or a request
|
|
166
|
+
* fails. `force` skips the retry backoff (shutdown). Never throws.
|
|
167
|
+
*/
|
|
168
|
+
flush(opts = {}) {
|
|
169
|
+
if (this.inflight)
|
|
170
|
+
return this.inflight;
|
|
171
|
+
this.inflight = this.run(opts.force === true).finally(() => {
|
|
172
|
+
this.inflight = null;
|
|
173
|
+
});
|
|
174
|
+
return this.inflight;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Shutdown: close every open window and make a bounded, best-effort attempt to
|
|
178
|
+
* deliver. Gives up at the deadline rather than hanging process exit on an
|
|
179
|
+
* endpoint that is down — which is exactly when there is something to report.
|
|
180
|
+
*/
|
|
181
|
+
async drain(opts) {
|
|
182
|
+
try {
|
|
183
|
+
for (const key of [...this.open.keys()])
|
|
184
|
+
this.close(key);
|
|
185
|
+
let timer;
|
|
186
|
+
const deadline = new Promise((resolve) => {
|
|
187
|
+
timer = setTimeout(resolve, opts.timeoutMs);
|
|
188
|
+
});
|
|
189
|
+
try {
|
|
190
|
+
await Promise.race([this.flush({ force: true }), deadline]);
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
if (timer)
|
|
194
|
+
clearTimeout(timer);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
this.log(`bypass drain failed: ${err.message}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
close(key) {
|
|
202
|
+
const w = this.open.get(key);
|
|
203
|
+
if (!w)
|
|
204
|
+
return;
|
|
205
|
+
this.open.delete(key);
|
|
206
|
+
const { firstMs: _f, lastMs: _l, ...window } = w;
|
|
207
|
+
this.closed.push(window);
|
|
208
|
+
// Bounded: never let an outage grow memory without limit. The oldest goes
|
|
209
|
+
// first, and the loss is counted so it can be reported.
|
|
210
|
+
while (this.closed.length > this.maxBuffered) {
|
|
211
|
+
const dropped = this.closed.shift();
|
|
212
|
+
this.liveDrop.windows += 1;
|
|
213
|
+
this.liveDrop.bypasses += dropped.count;
|
|
214
|
+
if (this.liveDrop.since === undefined)
|
|
215
|
+
this.liveDrop.since = dropped.firstAt;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async run(force) {
|
|
219
|
+
try {
|
|
220
|
+
while (this.hasPending) {
|
|
221
|
+
if (!force && this.now() < this.nextAttemptAt)
|
|
222
|
+
return;
|
|
223
|
+
if (!this.pendingDrop && this.liveDrop.windows > 0) {
|
|
224
|
+
this.pendingDrop = { dropId: this.uuid(), ...this.liveDrop };
|
|
225
|
+
this.liveDrop = { windows: 0, bypasses: 0 };
|
|
226
|
+
}
|
|
227
|
+
const windows = this.closed.slice(0, MAX_WINDOWS_PER_REQUEST);
|
|
228
|
+
const body = {
|
|
229
|
+
sdk: this.sdk,
|
|
230
|
+
sentAt: new Date(this.now()).toISOString(),
|
|
231
|
+
windows,
|
|
232
|
+
...(this.pendingDrop ? { dropped: this.pendingDrop } : {}),
|
|
233
|
+
};
|
|
234
|
+
let status;
|
|
235
|
+
try {
|
|
236
|
+
status = (await this.send(body)).status;
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
this.fail(`bypass report failed: ${err.message}`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (status >= 200 && status < 300) {
|
|
243
|
+
this.failures = 0;
|
|
244
|
+
this.nextAttemptAt = 0;
|
|
245
|
+
this.acknowledge(windows);
|
|
246
|
+
}
|
|
247
|
+
else if (NON_RETRYABLE.has(status)) {
|
|
248
|
+
// The body will never be accepted; resending is a loop.
|
|
249
|
+
this.log(`bypass report rejected (HTTP ${status}); discarding ${windows.length} window(s)`);
|
|
250
|
+
this.acknowledge(windows);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.fail(`bypass report failed (HTTP ${status})`);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
this.fail(`bypass report failed: ${err.message}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
acknowledge(sent) {
|
|
263
|
+
const ids = new Set(sent.map((w) => w.windowId));
|
|
264
|
+
this.closed = this.closed.filter((w) => !ids.has(w.windowId));
|
|
265
|
+
this.pendingDrop = null;
|
|
266
|
+
}
|
|
267
|
+
fail(message) {
|
|
268
|
+
this.failures += 1;
|
|
269
|
+
this.nextAttemptAt =
|
|
270
|
+
this.now() + Math.min(BACKOFF_BASE_MS * 2 ** (this.failures - 1), BACKOFF_MAX_MS);
|
|
271
|
+
this.log(message);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
exports.BypassWindowReporter = BypassWindowReporter;
|
|
275
|
+
//# sourceMappingURL=bypassReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bypassReporter.js","sourceRo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AAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAEO,IAAI,CAAC,OAAe;QAC1B,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,aAAa;YAChB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QACpF,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;CACF;AAlOD,oDAkOC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -80,6 +80,8 @@ export declare class Execlave {
|
|
|
80
80
|
private _enforcementOnOutage;
|
|
81
81
|
private _planLimitBehavior;
|
|
82
82
|
private _onEnforcementBypassed?;
|
|
83
|
+
private _bypassReporter;
|
|
84
|
+
private _bypassTimer;
|
|
83
85
|
private _heartbeatIntervalMs;
|
|
84
86
|
private _stampIdentity;
|
|
85
87
|
constructor(config?: ExeclaveConfig);
|
|
@@ -170,6 +172,20 @@ export declare class Execlave {
|
|
|
170
172
|
checkAgentStatus(agentId?: string): Promise<string>;
|
|
171
173
|
/** Flush all buffered traces to the API. */
|
|
172
174
|
flush(): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Record a later observation about a trace whose effect was unconfirmed.
|
|
177
|
+
*
|
|
178
|
+
* Appends to the trace's resolution ledger; it never rewrites the original
|
|
179
|
+
* outcome, which is what keeps "what did we know at the time" answerable.
|
|
180
|
+
*/
|
|
181
|
+
resolveTrace(traceId: string, params: {
|
|
182
|
+
resolvedStatus: 'success' | 'error' | 'timeout';
|
|
183
|
+
basis: 'read_back' | 'callback' | 'manual' | 'reconciliation';
|
|
184
|
+
effectRef?: string;
|
|
185
|
+
acknowledgementId?: string;
|
|
186
|
+
detail?: string;
|
|
187
|
+
observedAt?: string;
|
|
188
|
+
}): Promise<void>;
|
|
173
189
|
/**
|
|
174
190
|
* Pre-execution policy enforcement.
|
|
175
191
|
*
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAchC,OAAO,KAAK,EACV,cAAc,EAEd,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,YAAY,EACZ,YAAY,EAEZ,oBAAoB,EACpB,aAAa,EAGb,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,WAAW,EAEZ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAchC,OAAO,KAAK,EACV,cAAc,EAEd,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,YAAY,EACZ,YAAY,EAEZ,oBAAoB,EACpB,aAAa,EAGb,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,WAAW,EAEZ,MAAM,SAAS,CAAC;AA0BjB;;;;GAIG;AACH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CA6BrE;AAyDD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OA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