attenu-guard 0.3.1 → 0.5.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/CHANGELOG.md +282 -0
- package/dist/cjs/adapters/langgraph.d.ts +214 -3
- package/dist/cjs/adapters/langgraph.d.ts.map +1 -1
- package/dist/cjs/adapters/langgraph.js +588 -12
- package/dist/cjs/adapters/langgraph.js.map +1 -1
- package/dist/cjs/audit.d.ts +38 -1
- package/dist/cjs/audit.d.ts.map +1 -1
- package/dist/cjs/audit.js +52 -8
- package/dist/cjs/audit.js.map +1 -1
- package/dist/cjs/chain.d.ts +32 -0
- package/dist/cjs/chain.d.ts.map +1 -1
- package/dist/cjs/chain.js +0 -0
- package/dist/cjs/chain.js.map +1 -1
- package/dist/cjs/evidence.d.ts +38 -3
- package/dist/cjs/evidence.d.ts.map +1 -1
- package/dist/cjs/evidence.js +523 -13
- package/dist/cjs/evidence.js.map +1 -1
- package/dist/cjs/guard.d.ts +163 -9
- package/dist/cjs/guard.d.ts.map +1 -1
- package/dist/cjs/guard.js +444 -26
- package/dist/cjs/guard.js.map +1 -1
- package/dist/cjs/index.d.ts +10 -7
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +21 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/params.d.ts +52 -0
- package/dist/cjs/params.d.ts.map +1 -0
- package/dist/cjs/params.js +97 -0
- package/dist/cjs/params.js.map +1 -0
- package/dist/cjs/reasons.d.ts +89 -1
- package/dist/cjs/reasons.d.ts.map +1 -1
- package/dist/cjs/reasons.js +99 -3
- package/dist/cjs/reasons.js.map +1 -1
- package/dist/cjs/version.d.ts +10 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +13 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/adapters/langgraph.d.ts +214 -3
- package/dist/esm/adapters/langgraph.d.ts.map +1 -1
- package/dist/esm/adapters/langgraph.js +586 -11
- package/dist/esm/adapters/langgraph.js.map +1 -1
- package/dist/esm/audit.d.ts +38 -1
- package/dist/esm/audit.d.ts.map +1 -1
- package/dist/esm/audit.js +51 -8
- package/dist/esm/audit.js.map +1 -1
- package/dist/esm/chain.d.ts +32 -0
- package/dist/esm/chain.d.ts.map +1 -1
- package/dist/esm/chain.js +0 -0
- package/dist/esm/chain.js.map +1 -1
- package/dist/esm/evidence.d.ts +38 -3
- package/dist/esm/evidence.d.ts.map +1 -1
- package/dist/esm/evidence.js +523 -13
- package/dist/esm/evidence.js.map +1 -1
- package/dist/esm/guard.d.ts +163 -9
- package/dist/esm/guard.d.ts.map +1 -1
- package/dist/esm/guard.js +411 -27
- package/dist/esm/guard.js.map +1 -1
- package/dist/esm/index.d.ts +10 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/params.d.ts +52 -0
- package/dist/esm/params.d.ts.map +1 -0
- package/dist/esm/params.js +92 -0
- package/dist/esm/params.js.map +1 -0
- package/dist/esm/reasons.d.ts +89 -1
- package/dist/esm/reasons.d.ts.map +1 -1
- package/dist/esm/reasons.js +97 -2
- package/dist/esm/reasons.js.map +1 -1
- package/dist/esm/version.d.ts +10 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +10 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +1 -1
package/dist/cjs/reasons.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* the Python library's `attenu_guard.reasons` value for value.
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.Decision = exports.Reason = exports.DISPOSITIONS = exports.Disposition = exports.ReasonCode = void 0;
|
|
14
|
+
exports.Decision = exports.Reason = exports.CompletionResult = exports.BODY_STATES = exports.BodyState = exports.CAPTURES = exports.Capture = exports.DISPOSITIONS = exports.Disposition = exports.ReasonCode = void 0;
|
|
15
15
|
/**
|
|
16
16
|
* Stable string constants for machine-readable denial reasons. Never rename an
|
|
17
17
|
* existing value; add new ones instead.
|
|
@@ -37,6 +37,14 @@ exports.ReasonCode = {
|
|
|
37
37
|
CHAIN_CEILING: "chain_ceiling",
|
|
38
38
|
/** The principal holds no authority at all in this chain. */
|
|
39
39
|
NO_AUTHORITY: "no_authority",
|
|
40
|
+
// 0.9.0 execution-binding transition (schema_version=2 chains only — see guard.ts):
|
|
41
|
+
/** `check` refused: the node already called `complete()`. */
|
|
42
|
+
NODE_FINALIZED: "node_finalized",
|
|
43
|
+
/**
|
|
44
|
+
* The CSPRNG failed while allocating `callId`; fail-closed — the call is denied and
|
|
45
|
+
* nothing is written.
|
|
46
|
+
*/
|
|
47
|
+
CALL_ID_UNAVAILABLE: "call_id_unavailable",
|
|
40
48
|
};
|
|
41
49
|
/**
|
|
42
50
|
* WHY a denied scope was not in the node's authority — the ledger's answer to
|
|
@@ -54,6 +62,74 @@ exports.Disposition = {
|
|
|
54
62
|
OUT_OF_AUTHORITY: "out_of_authority",
|
|
55
63
|
};
|
|
56
64
|
exports.DISPOSITIONS = new Set(Object.values(exports.Disposition));
|
|
65
|
+
/**
|
|
66
|
+
* What the adapter's code path WILL observe for a given `check`ed call (0.9.0 execution binding)
|
|
67
|
+
* — recorded on the `allow` entry alongside `adapter` (module/version/hookPath). Describes
|
|
68
|
+
* observation CAPABILITY only, never a claim of quality: a verifier routes a call into
|
|
69
|
+
* observed/unobserved reporting from this label, never trusts it as evidence on its own.
|
|
70
|
+
*/
|
|
71
|
+
exports.Capture = {
|
|
72
|
+
/** The adapter's wrapper calls the body itself, synchronously. */
|
|
73
|
+
WRAPPER_SYNC: "wrapper_sync",
|
|
74
|
+
/** ... and awaits it. */
|
|
75
|
+
WRAPPER_ASYNC: "wrapper_async",
|
|
76
|
+
/** The framework itself calls back after the body runs. */
|
|
77
|
+
FRAMEWORK_POST_HOOK: "framework_post_hook",
|
|
78
|
+
/** The adapter sees the call authorized but never observes it finish. */
|
|
79
|
+
PRE_HOOK_ONLY: "pre_hook_only",
|
|
80
|
+
};
|
|
81
|
+
exports.CAPTURES = new Set(Object.values(exports.Capture));
|
|
82
|
+
/**
|
|
83
|
+
* The `outcome` record's observation of how a body-owning wrapper's call ended (0.9.0 execution
|
|
84
|
+
* binding, docs/execution-binding spec section 3) — an OBSERVATION, not a judgment about the
|
|
85
|
+
* world. There is no `executed`/`blocked`/`timeout`/`cancelled` at this layer; each of those
|
|
86
|
+
* words claims knowledge a wrapper does not always have. Adapters emitting into a richer outcome
|
|
87
|
+
* vocabulary own that mapping.
|
|
88
|
+
*/
|
|
89
|
+
exports.BodyState = {
|
|
90
|
+
/** The body returned to the wrapper. */
|
|
91
|
+
RETURNED: "returned",
|
|
92
|
+
/** It raised (`errorCode` required, from the exception's class/constructor name). */
|
|
93
|
+
RAISED: "raised",
|
|
94
|
+
/** The wrapper stopped observing while the body may still run. */
|
|
95
|
+
ABANDONED: "abandoned",
|
|
96
|
+
/** The wrapper returned a generator/stream/future it does not itself consume. */
|
|
97
|
+
DEFERRED: "deferred",
|
|
98
|
+
};
|
|
99
|
+
exports.BODY_STATES = new Set(Object.values(exports.BodyState));
|
|
100
|
+
/**
|
|
101
|
+
* `Guard.complete()`'s return value on a `schemaVersion: 2` chain ONLY (0.9.0, docs/
|
|
102
|
+
* execution-binding spec section 1): whether the node was actually finalized, and — when it
|
|
103
|
+
* refused because calls are still pending an outcome — the `callId`s it is waiting on. On a
|
|
104
|
+
* `schemaVersion: 1` chain (the default), `complete()` returns a plain `boolean`,
|
|
105
|
+
* byte-and-type IDENTICAL to every release before 0.9.0 — v1 never gained pending-call
|
|
106
|
+
* awareness, so there is nothing new for it to report and no reason to change its return type
|
|
107
|
+
* (mirrors attenu-guard Python's merge-gate fix restoring this exact split).
|
|
108
|
+
*
|
|
109
|
+
* Python's v2 return value is bool-coercible via `__bool__`, so `if guard.complete():` keeps
|
|
110
|
+
* reading naturally there. JavaScript has no such hook for `if` — `ToBoolean` on any object is
|
|
111
|
+
* unconditionally `true`, so on v2 an `if (guard.complete())` check cannot be bridged to `false`
|
|
112
|
+
* no matter what this class defines, and neither can `assert.equal`/`assert.strictEqual` from
|
|
113
|
+
* `node:assert/strict` (no coercion at all). What CAN be bridged: `valueOf()` returns
|
|
114
|
+
* `.completed`, so contexts that genuinely coerce via `==`/`!=` (loose equality), template
|
|
115
|
+
* literals, and arithmetic still read as a boolean. On v2, read `.completed` explicitly wherever
|
|
116
|
+
* you would have written `if (guard.complete())`.
|
|
117
|
+
*/
|
|
118
|
+
class CompletionResult {
|
|
119
|
+
completed;
|
|
120
|
+
pendingCallIds;
|
|
121
|
+
constructor(completed, pendingCallIds = []) {
|
|
122
|
+
this.completed = completed;
|
|
123
|
+
this.pendingCallIds = pendingCallIds;
|
|
124
|
+
}
|
|
125
|
+
valueOf() {
|
|
126
|
+
return this.completed;
|
|
127
|
+
}
|
|
128
|
+
toString() {
|
|
129
|
+
return String(this.completed);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.CompletionResult = CompletionResult;
|
|
57
133
|
/** One specific cause of a denial. */
|
|
58
134
|
class Reason {
|
|
59
135
|
code;
|
|
@@ -107,10 +183,18 @@ class Decision {
|
|
|
107
183
|
allowed;
|
|
108
184
|
reasons;
|
|
109
185
|
determiningNode;
|
|
110
|
-
|
|
186
|
+
callId;
|
|
187
|
+
constructor(allowed, reasons = [], determiningNode = null,
|
|
188
|
+
/**
|
|
189
|
+
* 0.9.0 execution binding: set only on a `schemaVersion: 2` chain (`Guard.check` /
|
|
190
|
+
* `Guard.recordDenial`); `null` on schema-version-1 chains and on any `Decision` built
|
|
191
|
+
* outside a `Guard` transition (`wouldAllow`, tests).
|
|
192
|
+
*/
|
|
193
|
+
callId = null) {
|
|
111
194
|
this.allowed = allowed;
|
|
112
195
|
this.reasons = reasons;
|
|
113
196
|
this.determiningNode = determiningNode;
|
|
197
|
+
this.callId = callId;
|
|
114
198
|
}
|
|
115
199
|
/** A single human-readable line — for logs, CLIs and error messages. */
|
|
116
200
|
explain() {
|
|
@@ -120,12 +204,24 @@ class Decision {
|
|
|
120
204
|
return "denied";
|
|
121
205
|
return "denied: " + this.reasons.map((r) => r.toString()).join("; ");
|
|
122
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* `callId` is included only when set (a `schemaVersion: 2` chain's `check`/`recordDenial`) — a
|
|
209
|
+
* v1 Decision's serialized shape stays byte-and-key identical to every release before 0.9.0,
|
|
210
|
+
* never gaining a `call_id: null` key it never had.
|
|
211
|
+
*/
|
|
123
212
|
toDict() {
|
|
124
|
-
|
|
213
|
+
const d = {
|
|
125
214
|
allowed: this.allowed,
|
|
126
215
|
reasons: this.reasons.map((r) => r.toDict()),
|
|
127
216
|
determining_node: this.determiningNode,
|
|
128
217
|
};
|
|
218
|
+
if (this.callId !== null)
|
|
219
|
+
d["call_id"] = this.callId;
|
|
220
|
+
return d;
|
|
221
|
+
}
|
|
222
|
+
/** A copy of this Decision with `callId` set — mirrors Python's `dataclasses.replace`. */
|
|
223
|
+
withCallId(callId) {
|
|
224
|
+
return new Decision(this.allowed, this.reasons, this.determiningNode, callId);
|
|
129
225
|
}
|
|
130
226
|
static allow(node = null) {
|
|
131
227
|
return new Decision(true, [], node);
|
package/dist/cjs/reasons.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasons.js","sourceRoot":"","sources":["../../src/reasons.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAIH;;;GAGG;AACU,QAAA,UAAU,GAAG;IACxB,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;IAClC,SAAS,EAAE,WAAW;IACtB,4EAA4E;IAC5E,kBAAkB,EAAE,oBAAoB;IACxC,8EAA8E;IAC9E,wEAAwE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U,CAAC,MAAqB;QAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAsB,IAAI;QACrC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAmC,EAAE,OAAsB,IAAI;QACzE,MAAM,IAAI,GAAG,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzE,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;CACF;AAhDD,4BAgDC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* version.ts — the package version, as its own leaf module.
|
|
3
|
+
*
|
|
4
|
+
* guard.ts needs this (to attribute a guard-supplied `adapter.version` on a bare `check()` with
|
|
5
|
+
* no wrapper — see the "Execution binding" section of guard.ts's module doc comment) and is
|
|
6
|
+
* itself imported BY index.ts, so index.ts cannot be the source: `guard.ts -> index.ts ->
|
|
7
|
+
* guard.ts` would be circular. A one-constant leaf module has nothing to be circular with.
|
|
8
|
+
*/
|
|
9
|
+
export declare const VERSION = "0.5.0";
|
|
10
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* version.ts — the package version, as its own leaf module.
|
|
6
|
+
*
|
|
7
|
+
* guard.ts needs this (to attribute a guard-supplied `adapter.version` on a bare `check()` with
|
|
8
|
+
* no wrapper — see the "Execution binding" section of guard.ts's module doc comment) and is
|
|
9
|
+
* itself imported BY index.ts, so index.ts cannot be the source: `guard.ts -> index.ts ->
|
|
10
|
+
* guard.ts` would be circular. A one-constant leaf module has nothing to be circular with.
|
|
11
|
+
*/
|
|
12
|
+
exports.VERSION = "0.5.0";
|
|
13
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACU,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -35,6 +35,85 @@
|
|
|
35
35
|
* this adapter does not prescribe which. It guarantees only that the tool body
|
|
36
36
|
* never executes on a denial.
|
|
37
37
|
*
|
|
38
|
+
* ## Execution binding (0.9.0, reference wiring for this adapter)
|
|
39
|
+
*
|
|
40
|
+
* When `guard`'s chain was issued with `schemaVersion: 2` (see `Guard.issue`), `guardNode` also
|
|
41
|
+
* passes `capture`/`adapter`/`authorizedParams` to `check` and calls `guard.recordOutcome` once
|
|
42
|
+
* the wrapped callable finishes — `Capture.WRAPPER_ASYNC` when `fn` is a genuine `async function`
|
|
43
|
+
* (`fn.constructor.name === "AsyncFunction"`, the same test Python's `inspect.iscoroutinefunction`
|
|
44
|
+
* makes), `Capture.WRAPPER_SYNC` otherwise. `authorizedParams`/`invokedParams` are
|
|
45
|
+
* `{args: [...]}` built from exactly what the wrapped callable is called with — JavaScript has no
|
|
46
|
+
* separate `kwargs`, so unlike the Python adapter's `{args, kwargs}` this carries only `args`; a
|
|
47
|
+
* LangGraph.js node in any case receives one state object, not Python's `(*args, **kwargs)`. They
|
|
48
|
+
* are unchanged between the two observations here, since this decorator itself never mutates
|
|
49
|
+
* them; a framework that DOES mutate arguments between authorization and invocation is where a
|
|
50
|
+
* real substitution would become visible. On a `schemaVersion: 1` chain (the default), this
|
|
51
|
+
* adapter behaves exactly as it did before 0.9.0: no `capture`/`authorizedParams`, no
|
|
52
|
+
* `recordOutcome` call. Every other framework adapter is unchanged in this release.
|
|
53
|
+
*
|
|
54
|
+
* ## Adversarial review: the Python batch-1/batch-2 defect classes, checked against this
|
|
55
|
+
* adapter specifically (not assumed absent by analogy)
|
|
56
|
+
*
|
|
57
|
+
* The Python `attenu-guard` adapters went through two rounds of adversarial review that found
|
|
58
|
+
* several defect classes across their (many) framework adapters. This TS package ships exactly
|
|
59
|
+
* ONE adapter surface (this file — verified against `package.json`'s own `exports` map, which
|
|
60
|
+
* declares nothing besides `.` and `./adapters/langgraph`), so each class was checked against
|
|
61
|
+
* THIS adapter specifically, not inherited by assumption:
|
|
62
|
+
*
|
|
63
|
+
* - **Composable middleware / sibling short-circuit or retry** (a sibling wrapper positioned
|
|
64
|
+
* closer to the tool body than this one, able to fabricate or repeat what it observes) — NOT
|
|
65
|
+
* APPLICABLE. Verified directly against pinned `@langchain/core@1.2.9` and
|
|
66
|
+
* `@langchain/langgraph@1.4.13` (installed and grepped, not read off documentation): zero
|
|
67
|
+
* `"middleware"` hits anywhere near tool invocation in either package, and
|
|
68
|
+
* `ToolNode.prototype.runTool` (`dist/prebuilt/tool_node.js`) calls `tool.invoke(toolCall,
|
|
69
|
+
* runtime)` directly — `guardTool`'s `Proxy` IS what gets called, nothing sits between it and
|
|
70
|
+
* `ToolNode`. Neither framework has a composable per-call hook chain the way LangChain-Python's
|
|
71
|
+
* `create_agent(middleware=[...])` or AG2's `FunctionTool.register()` do.
|
|
72
|
+
* - **Double authorization via a second, independent gate** (e.g. Python's `claude_sdk`
|
|
73
|
+
* adapter's `can_use_tool` calling `authorize()` a second time for the same call) — NOT
|
|
74
|
+
* APPLICABLE. There is no second entry point here: `guardNode`/`guardTool` are each the ONLY
|
|
75
|
+
* caller-facing wrapper for their call, and there is nothing in either framework analogous to
|
|
76
|
+
* a second permission callback for a call this adapter already gated.
|
|
77
|
+
* - **Snapshot double-evaluation / narrow-projection commitment** — NOT APPLICABLE in the
|
|
78
|
+
* double-evaluation shape (`snapshotParams`/`snapshotToolParams` already compute ONE snapshot,
|
|
79
|
+
* reused unchanged for both `authorizedParams` and `invokedParams`), but a DIFFERENT,
|
|
80
|
+
* TS-specific gap in the same family was found and fixed — see `freeze()`'s own doc comment
|
|
81
|
+
* above and the CHANGELOG.
|
|
82
|
+
* - **Correlation-key collision across hooks** (e.g. Python's `claude_sdk` `tool_use_id`
|
|
83
|
+
* collision) — NOT APPLICABLE. `guard.recordOutcome` is called synchronously inside the same
|
|
84
|
+
* closure that owns the whole call, from `authorize()`'s own returned `Decision.callId` — no
|
|
85
|
+
* external pending-map keyed by a framework-supplied correlation id exists to collide on.
|
|
86
|
+
* - **Lazy-result detection gaps** (e.g. Python's `smolagents` adapter missing a coroutine or a
|
|
87
|
+
* `concurrent.futures.Future`) — `isDeferredResult` catches generators (an object with its own
|
|
88
|
+
* `.next` AND `[Symbol.iterator]` — "self-iterating", the shape a native generator has, but
|
|
89
|
+
* deliberately NOT the shape a plain `Array`/`Set`/`Map` has, since those implement
|
|
90
|
+
* `[Symbol.iterator]` too without an own `.next`, and their contents are already fully
|
|
91
|
+
* computed), a genuine ASYNC ITERABLE (anything implementing a callable
|
|
92
|
+
* `[Symbol.asyncIterator]`, self-iterating async generators included — see the RELEASE-GATE
|
|
93
|
+
* CORRECTION on this function's own body for why this does NOT require an own `.next` the way
|
|
94
|
+
* the sync branch does), and anything thenable. A plain (non-`async`) function that manually
|
|
95
|
+
* returns a bare `Promise` is also caught correctly, via the thenable check, in the sync
|
|
96
|
+
* branch of both wrappers. This is NOT a claim of covering "the whole lazy-result landscape" —
|
|
97
|
+
* only what this function's own checks actually implement, listed above; a class implementing
|
|
98
|
+
* some OTHER deferred-consumption protocol this function does not check for would not be
|
|
99
|
+
* caught.
|
|
100
|
+
* - **Lost-terminal-event / "fires unconditionally" false claims** (e.g. Python's `strands`
|
|
101
|
+
* adapter's before-hook interrupt paths) — NOT APPLICABLE. There is no external, multi-phase
|
|
102
|
+
* hook-dispatch loop for an event to be lost across; one wrapper function's own `try`/`catch`
|
|
103
|
+
* (or `await`ed async path) owns authorize-through-`recordOutcome` for the whole call
|
|
104
|
+
* synchronously. Structurally this adapter was already closest to Python's own `langgraph.py`
|
|
105
|
+
* reference wiring, not any of the adapters that needed this class of fix.
|
|
106
|
+
* - **Unbounded correlation cache** (Python's `claude_sdk` `_recentVerdicts`) — NOT APPLICABLE,
|
|
107
|
+
* for the same reason as the correlation-collision point above: no cache or pending-map exists
|
|
108
|
+
* in this adapter to bound.
|
|
109
|
+
* - **Wrong dependency declaration** (Python's `semantic-kernel` `protobuf` lesson: check what
|
|
110
|
+
* the RESOLVED version actually requires, not what is assumed) — checked: `src/` imports only
|
|
111
|
+
* `@langchain/langgraph` (lazily, in `isLangGraphAvailable()`); it never imports
|
|
112
|
+
* `@langchain/core` at all (only this file's own tests do, to build fixtures). `package.json`
|
|
113
|
+
* declares zero `dependencies` and no `peerDependencies` — matching the README's own "zero
|
|
114
|
+
* runtime dependencies" claim — and both `@langchain/core`/`@langchain/langgraph` are correctly
|
|
115
|
+
* `devDependencies`-only. Nothing this package's `src/` needs at runtime is undeclared.
|
|
116
|
+
*
|
|
38
117
|
* ## Delegation
|
|
39
118
|
*
|
|
40
119
|
* Handing work to a sub-agent is the delegation moment. `delegateTo` mints the
|
|
@@ -51,8 +130,9 @@
|
|
|
51
130
|
*/
|
|
52
131
|
import { type Guard } from "../guard.js";
|
|
53
132
|
import type { Authority } from "../authority.js";
|
|
133
|
+
import type { Json } from "../canonical.js";
|
|
54
134
|
import type { Context } from "../ceilings.js";
|
|
55
|
-
import type
|
|
135
|
+
import { type Decision } from "../reasons.js";
|
|
56
136
|
/** Options shared by every guarded wrapper. */
|
|
57
137
|
export interface GuardOptions {
|
|
58
138
|
/**
|
|
@@ -74,6 +154,129 @@ export type GuardedNode<F extends (...args: any[]) => any> = F & {
|
|
|
74
154
|
readonly toolScope: string;
|
|
75
155
|
readonly unwrapped: F;
|
|
76
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* A private, freeze()-only sentinel for "could not be represented as a JSON leaf" — a Proxy, an
|
|
159
|
+
* accessor property, a genuine cycle, a boxed primitive, a TypedArray, a function, or anything
|
|
160
|
+
* else this module does not know how to rebuild as plain JSON. NEVER a JSON-representable
|
|
161
|
+
* value (a string, `null`, …): a second release-gate finding showed a literal string sentinel
|
|
162
|
+
* (`"<accessor>"`) genuinely COLLIDES — a real getter-bearing object and a plain object holding
|
|
163
|
+
* the literal string `"<accessor>"` produced the IDENTICAL `authorizedParamsHash`, an
|
|
164
|
+
* evidence-integrity ambiguity in a supposedly cryptographic commitment (two materially
|
|
165
|
+
* different inputs, one commitment). A fresh, private `Symbol` cannot equal any real call
|
|
166
|
+
* argument, so it cannot collide with one — and it makes the SAME degradation apply uniformly
|
|
167
|
+
* everywhere this function cannot represent something, rather than inventing a new
|
|
168
|
+
* JSON-shaped sentinel (with its own collision risk) per case.
|
|
169
|
+
*
|
|
170
|
+
* Declared as `Json` even though a `Symbol` is not one — a deliberate escape from that type's
|
|
171
|
+
* nominal domain, not an oversight: `canonical.ts`'s own JCS `serialize()` already runtime-checks
|
|
172
|
+
* `typeof` for exactly this reason (its switch handles `"undefined"`/`"bigint"`/`"symbol"`/
|
|
173
|
+
* `"function"` despite `CJson`'s declared type not admitting any of them either), because the
|
|
174
|
+
* type system cannot fully describe this module's actual runtime domain. Once this sentinel
|
|
175
|
+
* reaches `params.ts`'s `commit()` — inside a plain object or array, same as any other frozen
|
|
176
|
+
* leaf — `canonicalBytes` hits that `"symbol"` case, throws `UnsupportedTypeError`, and `commit()`
|
|
177
|
+
* turns that into `paramsHashReason: "unsupported"` for the WHOLE params value, never a partial
|
|
178
|
+
* or per-field one: there is no such thing as "this one nested field is unsupported," only
|
|
179
|
+
* "this whole call's arguments are, or are not, representable."
|
|
180
|
+
*
|
|
181
|
+
* Exported for the same reason `freeze` itself is: not part of this adapter's semantic
|
|
182
|
+
* contract, but its own tests need to assert directly that a given leaf became this exact
|
|
183
|
+
* sentinel (by identity — nothing else can equal it) rather than inferring it indirectly.
|
|
184
|
+
*/
|
|
185
|
+
export declare const FREEZE_UNSUPPORTED: Json;
|
|
186
|
+
/**
|
|
187
|
+
* A genuinely immutable, fully decoupled rebuild of `value` — the ONE, UNCONDITIONAL sanitizer
|
|
188
|
+
* every snapshot in this adapter goes through. Safe JSON-primitive leaves
|
|
189
|
+
* (`string`/`number`/`boolean`/`null`) pass through verbatim; plain objects and arrays are
|
|
190
|
+
* rebuilt fresh, recursively, by inspecting their REAL own property descriptors directly
|
|
191
|
+
* (`Object.getOwnPropertyDescriptor`), never by invoking anything the value itself controls (a
|
|
192
|
+
* getter, an iterator, a copy protocol, a Proxy trap, a `toString`/`valueOf`/`Symbol.toPrimitive`
|
|
193
|
+
* override); anything this function cannot represent becomes `UNSUPPORTED` (above) — never a
|
|
194
|
+
* string, never the live object.
|
|
195
|
+
*
|
|
196
|
+
* RELEASE-GATE CORRECTION (CRITICAL): this used to run ONLY as a fallback, after
|
|
197
|
+
* `structuredClone` had already been tried and had THROWN — the previous revision of this
|
|
198
|
+
* comment documented that carefully, but never asked whether `structuredClone` SUCCEEDING was
|
|
199
|
+
* itself a sufficient guarantee. It is not, on three counts, each reproduced directly before
|
|
200
|
+
* that fix: (1) a circular object clones successfully — `structuredClone` handles cycles
|
|
201
|
+
* natively — so this function never ran on it at all, and the circularity later reached
|
|
202
|
+
* `params.ts`'s own cycle-guard-less hash walk and crashed with `RangeError`; (2) a sparse
|
|
203
|
+
* array clones successfully too, bypassing this function's own densification; (3) a
|
|
204
|
+
* `SharedArrayBuffer` clones to a DISTINCT wrapper object sharing the SAME underlying memory —
|
|
205
|
+
* a "successful" clone that is not independent at all. Fixed by making this function the ONLY
|
|
206
|
+
* snapshot path, unconditionally — `structuredClone` is not called anywhere in this adapter.
|
|
207
|
+
*
|
|
208
|
+
* A SECOND release-gate pass then found that "pure introspection" was not fully true either —
|
|
209
|
+
* three more code-execution paths, all reproduced directly before this fix:
|
|
210
|
+
*
|
|
211
|
+
* 1. A `Proxy` is not inert under reflection. `Object.getPrototypeOf`, `Object.keys`
|
|
212
|
+
* (`[[OwnPropertyKeys]]` + a `[[GetOwnProperty]]` per key to check enumerability), and
|
|
213
|
+
* `Object.getOwnPropertyDescriptor` are each real, user-definable traps — reproduced
|
|
214
|
+
* directly: walking an ordinary handler-tracked Proxy through the OLD version of this
|
|
215
|
+
* function fired four separate traps before authorization was ever decided. `Array.isArray`
|
|
216
|
+
* is worse: called on a REVOKED Proxy, it throws `TypeError` outright (its spec algorithm,
|
|
217
|
+
* `IsArray`, unwraps `[[ProxyTarget]]`, which does not exist on a revoked handle) —
|
|
218
|
+
* reproduced directly. Fixed: `require("node:util").types.isProxy(value)` recognizes a
|
|
219
|
+
* Proxy — live OR revoked — via an internal engine slot, invoking NOTHING (verified
|
|
220
|
+
* directly: zero trap calls, no throw on a revoked handle either) — checked FIRST, before
|
|
221
|
+
* `Array.isArray` or any other reflection, and routed straight to `UNSUPPORTED`.
|
|
222
|
+
* 2. The bottom fallback used `String(value)` for anything not a plain object/array — a boxed
|
|
223
|
+
* primitive (`new Number(...)`) with a hostile `Symbol.toPrimitive`, or a `TypedArray` with
|
|
224
|
+
* a hostile own `toString`, each ran attacker code exactly once per snapshot, reproduced
|
|
225
|
+
* directly both ways — BEFORE `Guard.check` had decided allow or deny. The same is true, in
|
|
226
|
+
* principle, of ANY object-typed exotic value (a function's own `.toString` is just as
|
|
227
|
+
* overridable) — there is no way to distinguish "safe to stringify" from "hostile" by
|
|
228
|
+
* inspection alone, so none of them are stringified any more. Fixed: every value that is
|
|
229
|
+
* not a safe JSON primitive and not a plain object/array — a Proxy, a boxed primitive, a
|
|
230
|
+
* TypedArray/`ArrayBuffer`/`SharedArrayBuffer`/`DataView`, a `Map`/`Set`/`Date`/`RegExp`, a
|
|
231
|
+
* function, a `Symbol`, a `BigInt`, anything else — becomes `UNSUPPORTED` (never `String()`,
|
|
232
|
+
* never any other protocol) — see the confirmed-good note above: stringification itself
|
|
233
|
+
* was never unsafe as a RESULT (a `SharedArrayBuffer` never retained live memory as a
|
|
234
|
+
* string), the defect was invoking attacker-controlled code to PRODUCE that string before
|
|
235
|
+
* authorization ran, and `UNSUPPORTED` avoids that entirely rather than picking a "safer"
|
|
236
|
+
* string.
|
|
237
|
+
* 3. Any OTHER reflection failure — an exotic value this pass did not specifically anticipate,
|
|
238
|
+
* still throwing from `Object.getPrototypeOf`/`Object.keys`/`Object.getOwnPropertyDescriptor`
|
|
239
|
+
* despite the Proxy check above — must degrade the same way, not propagate an exception out
|
|
240
|
+
* of a snapshot taken before authorization. The whole reflective walk (everything past the
|
|
241
|
+
* Proxy/primitive fast paths) runs inside one `try`/`catch`; any throw there becomes
|
|
242
|
+
* `UNSUPPORTED` too.
|
|
243
|
+
*
|
|
244
|
+
* `active` is the PATH-ACTIVE cycle guard: the set of containers on the CURRENT recursion path,
|
|
245
|
+
* passed as a NEW `Set` at each recursive call rather than mutated in place and shared across
|
|
246
|
+
* sibling branches (an earlier revision DID share one mutable `WeakSet` across the whole call,
|
|
247
|
+
* which meant a DAG's repeated reference — the SAME object appearing twice as sibling values,
|
|
248
|
+
* never as its own ancestor — was wrongly flagged on its second occurrence; reproduced directly
|
|
249
|
+
* before that fix too). A genuine cycle's own leaf value is `UNSUPPORTED`, not a literal string
|
|
250
|
+
* `"<circular>"` — audited for the same collision class as `"<accessor>"` below, and it has the
|
|
251
|
+
* identical problem: a self-referential object and a plain object holding the literal string
|
|
252
|
+
* `"<circular>"` would otherwise produce the same commitment. There is no position-based reason
|
|
253
|
+
* a cycle's collision is any less real than an accessor's, so it gets the same fix.
|
|
254
|
+
*
|
|
255
|
+
* The property-descriptor walk ALSO closes a separate, protocol-driven gap: the previous
|
|
256
|
+
* revision used `Array.from`/`.map()` (which invoke `[Symbol.iterator]()` — a hostile array's
|
|
257
|
+
* own override can yield ANYTHING regardless of its real indexed properties; reproduced
|
|
258
|
+
* directly: `[1, , 3]` with a hostile iterator froze as `[999]`) and `Object.entries()` (which
|
|
259
|
+
* reads each property's VALUE directly, invoking a getter if one is defined there — reproduced
|
|
260
|
+
* directly: a getter with a side effect was observed three times across the old clone-attempt/
|
|
261
|
+
* freeze/body sequence, and the committed snapshot was the SECOND of three observations, not the
|
|
262
|
+
* first). `Object.getOwnPropertyDescriptor` and a `.length`-bounded index loop are pure
|
|
263
|
+
* introspection — they never invoke user code — and an accessor property (`.get`/`.set` present)
|
|
264
|
+
* becomes `UNSUPPORTED` rather than read at all: a getter can have arbitrary side effects, throw,
|
|
265
|
+
* or return something different on every call, so there is no single "correct" observation of it
|
|
266
|
+
* to commit, and (release-gate correction) the earlier `"<accessor>"` string sentinel this
|
|
267
|
+
* function used instead genuinely collided — reproduced directly: a real getter-bearing object
|
|
268
|
+
* and a plain object holding the literal string `"<accessor>"` produced the identical
|
|
269
|
+
* `authorizedParamsHash`. Both now degrade the same commitment to `unsupported` via `UNSUPPORTED`
|
|
270
|
+
* (see its own doc comment above), never a JSON-representable stand-in.
|
|
271
|
+
*
|
|
272
|
+
* Exported — not part of this adapter's semantic contract (it is an internal sanitizer, not a
|
|
273
|
+
* feature callers configure), but its own aliasing-safety invariant is worth a direct unit
|
|
274
|
+
* test in isolation, the same way every Python adapter's `_freeze()` is imported directly by
|
|
275
|
+
* its own tests: the audit log never exposes the raw snapshot value it produces (only its
|
|
276
|
+
* hash — see `params.ts`'s own doc comment), so "does this alias a live mutable object" is
|
|
277
|
+
* not otherwise observable from outside this module.
|
|
278
|
+
*/
|
|
279
|
+
export declare function freeze(value: unknown, active?: ReadonlySet<unknown>): Json;
|
|
77
280
|
/**
|
|
78
281
|
* Wrap a callable so every call is authorized through `guard` first.
|
|
79
282
|
*
|
|
@@ -81,7 +284,9 @@ export type GuardedNode<F extends (...args: any[]) => any> = F & {
|
|
|
81
284
|
* `guard.check(toolScope, {context, tool})`. On a denial this throws
|
|
82
285
|
* `AuthorityDenied` and the wrapped callable is NEVER invoked. Otherwise it
|
|
83
286
|
* calls through with the original arguments and returns the result unchanged —
|
|
84
|
-
* including a promise, which is passed along untouched.
|
|
287
|
+
* including a promise, which is passed along untouched. On a `schemaVersion: 2`
|
|
288
|
+
* guard, also binds the call's outcome via `guard.recordOutcome` — see the
|
|
289
|
+
* module doc comment's "Execution binding" section.
|
|
85
290
|
*
|
|
86
291
|
* Use the Guard for the SPECIFIC agent this callable belongs to, not the
|
|
87
292
|
* orchestrator's broader one, so a denial reflects that node's real, narrowed
|
|
@@ -125,7 +330,13 @@ export interface GuardToolOptions extends GuardOptions {
|
|
|
125
330
|
* The context function receives the raw invoke arguments. `ToolNode` passes a
|
|
126
331
|
* tool call object, so the arguments the model proposed are at `input.args`;
|
|
127
332
|
* a direct `tool.invoke({...})` passes them at the top level. `toolArgs` below
|
|
128
|
-
* reads either shape
|
|
333
|
+
* reads either shape — and, on a `schemaVersion: 2` guard, feeds a single
|
|
334
|
+
* IMMUTABLE snapshot taken BEFORE `tool.invoke` runs, reused for both
|
|
335
|
+
* `authorizedParams` and `invokedParams`: this adapter's closest analogue of "the
|
|
336
|
+
* exact tool-call JSON object" the execution-binding spec names (see the module
|
|
337
|
+
* doc comment's "Execution binding" section; this is the one construct in this
|
|
338
|
+
* adapter that wraps a tool BODY, so it is the reference wiring for
|
|
339
|
+
* `recordOutcome`, mirroring `guardNode` above).
|
|
129
340
|
*/
|
|
130
341
|
export declare function guardTool<T extends ToolLike>(guard: Guard, tool: T, options?: GuardToolOptions): T;
|
|
131
342
|
/** Marker properties, so a caller can tell a guarded tool from a bare one. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langgraph.d.ts","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"langg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