@decionis/agentsafe 0.7.0 → 0.9.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 +6 -1
- package/dist/Cli.js +13 -3
- package/dist/Cli.js.map +1 -1
- package/dist/acceptance/AcceptancePlan.d.ts +109 -0
- package/dist/acceptance/AcceptancePlan.d.ts.map +1 -0
- package/dist/acceptance/AcceptancePlan.js +128 -0
- package/dist/acceptance/AcceptancePlan.js.map +1 -0
- package/dist/acceptance/AcceptanceReport.d.ts +596 -0
- package/dist/acceptance/AcceptanceReport.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceReport.js +361 -0
- package/dist/acceptance/AcceptanceReport.js.map +1 -0
- package/dist/acceptance/AcceptanceRun.d.ts +118 -0
- package/dist/acceptance/AcceptanceRun.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceRun.js +419 -0
- package/dist/acceptance/AcceptanceRun.js.map +1 -0
- package/dist/acceptance/Coverage.d.ts +12 -0
- package/dist/acceptance/Coverage.d.ts.map +1 -0
- package/dist/acceptance/Coverage.js +48 -0
- package/dist/acceptance/Coverage.js.map +1 -0
- package/dist/acceptance/OutageDoubles.d.ts +34 -0
- package/dist/acceptance/OutageDoubles.d.ts.map +1 -0
- package/dist/acceptance/OutageDoubles.js +67 -0
- package/dist/acceptance/OutageDoubles.js.map +1 -0
- package/dist/acceptance/ZoneProbes.d.ts +368 -0
- package/dist/acceptance/ZoneProbes.d.ts.map +1 -0
- package/dist/acceptance/ZoneProbes.js +488 -0
- package/dist/acceptance/ZoneProbes.js.map +1 -0
- package/dist/adapters/JcsDigest.d.ts +6 -5
- package/dist/adapters/JcsDigest.d.ts.map +1 -1
- package/dist/adapters/JcsDigest.js +9 -8
- package/dist/adapters/JcsDigest.js.map +1 -1
- package/dist/cli/Accept.d.ts +9 -0
- package/dist/cli/Accept.d.ts.map +1 -0
- package/dist/cli/Accept.js +209 -0
- package/dist/cli/Accept.js.map +1 -0
- package/dist/cli/Actions.d.ts +6 -4
- package/dist/cli/Actions.d.ts.map +1 -1
- package/dist/cli/Actions.js +33 -7
- package/dist/cli/Actions.js.map +1 -1
- package/dist/cli/Commands.d.ts +1 -1
- package/dist/cli/Commands.d.ts.map +1 -1
- package/dist/cli/Commands.js +5 -0
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/ConfigCommand.d.ts.map +1 -1
- package/dist/cli/ConfigCommand.js +5 -0
- package/dist/cli/ConfigCommand.js.map +1 -1
- package/dist/cli/Doctor.d.ts.map +1 -1
- package/dist/cli/Doctor.js +67 -1
- package/dist/cli/Doctor.js.map +1 -1
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +6 -1
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Identity.d.ts +13 -1
- package/dist/cli/Identity.d.ts.map +1 -1
- package/dist/cli/Identity.js +25 -2
- package/dist/cli/Identity.js.map +1 -1
- package/dist/cli/Status.d.ts +23 -0
- package/dist/cli/Status.d.ts.map +1 -1
- package/dist/cli/Status.js +80 -18
- package/dist/cli/Status.js.map +1 -1
- package/dist/cli/VerifyAcceptance.d.ts +38 -0
- package/dist/cli/VerifyAcceptance.d.ts.map +1 -0
- package/dist/cli/VerifyAcceptance.js +143 -0
- package/dist/cli/VerifyAcceptance.js.map +1 -0
- package/dist/config/ExecutorConfig.d.ts +6 -1
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/egress/ZoneHttpClient.d.ts +3 -0
- package/dist/egress/ZoneHttpClient.d.ts.map +1 -0
- package/dist/egress/ZoneHttpClient.js +72 -0
- package/dist/egress/ZoneHttpClient.js.map +1 -0
- package/dist/exposure/DecionisExposureLedger.d.ts +44 -0
- package/dist/exposure/DecionisExposureLedger.d.ts.map +1 -0
- package/dist/exposure/DecionisExposureLedger.js +175 -0
- package/dist/exposure/DecionisExposureLedger.js.map +1 -0
- package/dist/exposure/ExposureDeclaration.d.ts +68 -0
- package/dist/exposure/ExposureDeclaration.d.ts.map +1 -0
- package/dist/exposure/ExposureDeclaration.js +120 -0
- package/dist/exposure/ExposureDeclaration.js.map +1 -0
- package/dist/exposure/ExposureFacts.d.ts +61 -0
- package/dist/exposure/ExposureFacts.d.ts.map +1 -0
- package/dist/exposure/ExposureFacts.js +220 -0
- package/dist/exposure/ExposureFacts.js.map +1 -0
- package/dist/exposure/ExposureGate.d.ts +144 -0
- package/dist/exposure/ExposureGate.d.ts.map +1 -0
- package/dist/exposure/ExposureGate.js +446 -0
- package/dist/exposure/ExposureGate.js.map +1 -0
- package/dist/exposure/ExposureLedger.d.ts +93 -0
- package/dist/exposure/ExposureLedger.d.ts.map +1 -0
- package/dist/exposure/ExposureLedger.js +24 -0
- package/dist/exposure/ExposureLedger.js.map +1 -0
- package/dist/gateway/AttemptStore.d.ts +83 -0
- package/dist/gateway/AttemptStore.d.ts.map +1 -0
- package/dist/gateway/AttemptStore.js +229 -0
- package/dist/gateway/AttemptStore.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts +29 -3
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +32 -5
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +229 -17
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +1045 -81
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +186 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +219 -5
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/GatewayManifest.d.ts +18 -0
- package/dist/gateway/GatewayManifest.d.ts.map +1 -0
- package/dist/gateway/GatewayManifest.js +42 -0
- package/dist/gateway/GatewayManifest.js.map +1 -0
- package/dist/gateway/GatewayMetrics.d.ts +12 -4
- package/dist/gateway/GatewayMetrics.d.ts.map +1 -1
- package/dist/gateway/GatewayMetrics.js +5 -0
- package/dist/gateway/GatewayMetrics.js.map +1 -1
- package/dist/gateway/GatewayReport.d.ts +34 -1
- package/dist/gateway/GatewayReport.d.ts.map +1 -1
- package/dist/gateway/GatewayReport.js +11 -0
- package/dist/gateway/GatewayReport.js.map +1 -1
- package/dist/gateway/HoldStore.d.ts +89 -0
- package/dist/gateway/HoldStore.d.ts.map +1 -0
- package/dist/gateway/HoldStore.js +280 -0
- package/dist/gateway/HoldStore.js.map +1 -0
- package/dist/gateway/InterceptedRequest.d.ts +10 -0
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +20 -0
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/RouteTable.d.ts +33 -5
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +76 -1
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/ShadowLedger.d.ts +11 -0
- package/dist/gateway/ShadowLedger.d.ts.map +1 -1
- package/dist/gateway/ShadowLedger.js +11 -0
- package/dist/gateway/ShadowLedger.js.map +1 -1
- package/dist/gateway/TargetEffect.d.ts +74 -0
- package/dist/gateway/TargetEffect.d.ts.map +1 -0
- package/dist/gateway/TargetEffect.js +95 -0
- package/dist/gateway/TargetEffect.js.map +1 -0
- package/dist/gateway/TargetReader.d.ts +70 -0
- package/dist/gateway/TargetReader.d.ts.map +1 -0
- package/dist/gateway/TargetReader.js +106 -0
- package/dist/gateway/TargetReader.js.map +1 -0
- package/dist/gateway/Upstream.d.ts +15 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +24 -2
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +3 -2
- package/dist/hosted/TenantHost.d.ts.map +1 -1
- package/dist/hosted/TenantHost.js +7 -1
- package/dist/hosted/TenantHost.js.map +1 -1
- package/dist/hosted/TenantRegistry.d.ts +8 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -1
- package/dist/hosted/TenantRegistry.js +14 -1
- package/dist/hosted/TenantRegistry.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +7 -0
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +57 -1
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/outcomes/OutcomeEvidence.d.ts +4 -4
- package/dist/posture/ActionSpaceDrift.d.ts +40 -0
- package/dist/posture/ActionSpaceDrift.d.ts.map +1 -0
- package/dist/posture/ActionSpaceDrift.js +67 -0
- package/dist/posture/ActionSpaceDrift.js.map +1 -0
- package/dist/posture/DeploymentFingerprint.d.ts +88 -0
- package/dist/posture/DeploymentFingerprint.d.ts.map +1 -0
- package/dist/posture/DeploymentFingerprint.js +78 -0
- package/dist/posture/DeploymentFingerprint.js.map +1 -0
- package/dist/secrets/SecretStore.d.ts +6 -1
- package/dist/secrets/SecretStore.d.ts.map +1 -1
- package/dist/secrets/SecretStore.js.map +1 -1
- package/dist/service/EscalationResolver.d.ts +6 -6
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +8 -4
- package/dist/service/EscalationResolver.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ActionManifestDocument } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import type { RouteTable } from "./RouteTable.js";
|
|
3
|
+
/** The family name a gateway's own route actions go by in an action manifest. */
|
|
4
|
+
export declare const GATEWAY_FAMILY = "gateway";
|
|
5
|
+
/**
|
|
6
|
+
* The action space a gateway with this route table loads, as one
|
|
7
|
+
* `agent-safe.actions/1` document: what `agentsafe actions manifest --gateway`
|
|
8
|
+
* writes for the same configuration, and what the gateway's fingerprint
|
|
9
|
+
* digests. The profile's writes are described exactly as `--api <profile>`
|
|
10
|
+
* describes them, so a release held to that manifest matches a gateway that
|
|
11
|
+
* governs by the profile alone. Every other action a row governs (an explicit
|
|
12
|
+
* route's, or the derived `http.<method>` of the rest) is one entry of the
|
|
13
|
+
* gateway's own family, admitted against the HTTP parameters and naming each
|
|
14
|
+
* method and path that produces it. A route that names one of the profile's
|
|
15
|
+
* actions adds no entry: the action is the unit a release covers.
|
|
16
|
+
*/
|
|
17
|
+
export declare function gatewayManifest(routes: RouteTable): ActionManifestDocument;
|
|
18
|
+
//# sourceMappingURL=GatewayManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayManifest.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayManifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,iFAAiF;AACjF,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,sBAAsB,CAuB1E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ActionManifest, } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import { HttpParametersSchema } from "./ForwardHandler.js";
|
|
3
|
+
/** The family name a gateway's own route actions go by in an action manifest. */
|
|
4
|
+
export const GATEWAY_FAMILY = "gateway";
|
|
5
|
+
/**
|
|
6
|
+
* The action space a gateway with this route table loads, as one
|
|
7
|
+
* `agent-safe.actions/1` document: what `agentsafe actions manifest --gateway`
|
|
8
|
+
* writes for the same configuration, and what the gateway's fingerprint
|
|
9
|
+
* digests. The profile's writes are described exactly as `--api <profile>`
|
|
10
|
+
* describes them, so a release held to that manifest matches a gateway that
|
|
11
|
+
* governs by the profile alone. Every other action a row governs (an explicit
|
|
12
|
+
* route's, or the derived `http.<method>` of the rest) is one entry of the
|
|
13
|
+
* gateway's own family, admitted against the HTTP parameters and naming each
|
|
14
|
+
* method and path that produces it. A route that names one of the profile's
|
|
15
|
+
* actions adds no entry: the action is the unit a release covers.
|
|
16
|
+
*/
|
|
17
|
+
export function gatewayManifest(routes) {
|
|
18
|
+
const profile = routes.profile;
|
|
19
|
+
const entries = profile === null ? [] : ActionManifest.fromApiProfile(profile, HttpParametersSchema);
|
|
20
|
+
const described = new Set(entries.map((entry) => entry.action));
|
|
21
|
+
const targets = new Map();
|
|
22
|
+
for (const row of routes.rows()) {
|
|
23
|
+
if (row.action === null || described.has(row.action))
|
|
24
|
+
continue;
|
|
25
|
+
const named = targets.get(row.action) ?? new Set();
|
|
26
|
+
for (const method of row.methods)
|
|
27
|
+
named.add(`${method} ${row.path}`);
|
|
28
|
+
targets.set(row.action, named);
|
|
29
|
+
}
|
|
30
|
+
const parameters = ActionManifest.parametersJsonSchema(HttpParametersSchema);
|
|
31
|
+
for (const [action, named] of targets) {
|
|
32
|
+
entries.push({
|
|
33
|
+
action,
|
|
34
|
+
source: { kind: "registry", family: GATEWAY_FAMILY },
|
|
35
|
+
parameters,
|
|
36
|
+
targets: [...named].sort(),
|
|
37
|
+
effect_type: null,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return ActionManifest.document(entries);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=GatewayManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayManifest.js","sourceRoot":"","sources":["../../src/gateway/GatewayManifest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,iFAAiF;AACjF,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkB;IAChD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/B,MAAM,OAAO,GACX,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAA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
1
|
import { Metrics, type Counter, type Gauge } from "../incident/Metrics.js";
|
|
2
2
|
/**
|
|
3
|
-
* The gateway's families. Label values are verdicts, states, codes and the
|
|
4
|
-
* action names the configuration itself produced,
|
|
5
|
-
* sent, so the cardinality is the configuration's and
|
|
6
|
-
* through a label. A latency is a running sum and a count, which is what a
|
|
3
|
+
* The gateway's families. Label values are verdicts, states, codes, and the
|
|
4
|
+
* action names and fingerprint digest the configuration itself produced,
|
|
5
|
+
* never anything a caller sent, so the cardinality is the configuration's and
|
|
6
|
+
* no value can leak through a label. A latency is a running sum and a count, which is what a
|
|
7
7
|
* scraper needs to compute a rate and a mean between two scrapes.
|
|
8
8
|
*/
|
|
9
9
|
export interface GatewayMetrics {
|
|
@@ -18,7 +18,15 @@ export interface GatewayMetrics {
|
|
|
18
18
|
readonly authorityErrors: Counter;
|
|
19
19
|
readonly indeterminate: Counter;
|
|
20
20
|
readonly ungoverned: Counter;
|
|
21
|
+
readonly effects: Counter;
|
|
22
|
+
readonly refusalObservations: Counter;
|
|
23
|
+
/** Money releases by what the exposure ledger said, and how their reservations ended. */
|
|
24
|
+
readonly exposure: Counter;
|
|
21
25
|
readonly held: Gauge;
|
|
26
|
+
/** 1, labelled with the digest of what this gateway is; the label changes only with a rebuild. */
|
|
27
|
+
readonly fingerprint: Gauge;
|
|
28
|
+
/** 1 while the last decision that named one came from a release checked against another action space. */
|
|
29
|
+
readonly actionSpaceDrift: Gauge;
|
|
22
30
|
observeAuthorityLatency(ms: number): void;
|
|
23
31
|
observeForwardLatency(ms: number): void;
|
|
24
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayMetrics.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAA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;IAC9B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,kGAAkG;IAClG,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAC5B,yGAAyG;IACzG,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;IACjC,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AAWD,wBAAgB,cAAc,CAAC,QAAQ,GAAE,OAAuB,GAAG,cAAc,CAuEhF"}
|
|
@@ -20,7 +20,12 @@ export function gatewayMetrics(registry = new Metrics()) {
|
|
|
20
20
|
authorityErrors: registry.counter("agentsafe_authority_errors", "Fail-closed authority outcomes, by reason code.", ["code"]),
|
|
21
21
|
indeterminate: registry.counter("agentsafe_execution_indeterminate", "Executions whose upstream outcome is unknown."),
|
|
22
22
|
ungoverned: registry.counter("agentsafe_ungoverned_forwards", "Requests forwarded under an explicit fail-open policy while the authority was unavailable."),
|
|
23
|
+
effects: registry.counter("agentsafe_effects", "Forwarded writes by what was read back of their effect: CONFIRMED, UNKNOWN or PENDING.", ["effect"]),
|
|
24
|
+
refusalObservations: registry.counter("agentsafe_refusal_observations", "Refused writes whose target was read again: UNCHANGED, CHANGED or UNREADABLE.", ["outcome"]),
|
|
25
|
+
exposure: registry.counter("agentsafe_exposure", "Money releases checked against cumulative limits, by outcome: WITHIN_LIMIT, EXCEEDED, UNAVAILABLE, UNGOVERNED, SETTLE_FAILED, RELEASE_FAILED and the rest.", ["outcome"]),
|
|
23
26
|
held: registry.gauge("agentsafe_escalations_held", "Escalations held for a human answer."),
|
|
27
|
+
fingerprint: registry.gauge("agentsafe_deployment_fingerprint", "The deployment fingerprint of this gateway, as its digest label.", ["digest"]),
|
|
28
|
+
actionSpaceDrift: registry.gauge("agentsafe_action_space_drift", "1 while the release that last decided was checked against another action space than this gateway loaded."),
|
|
24
29
|
observeAuthorityLatency: latency(registry, "agentsafe_authority_latency_ms", "Milliseconds spent waiting for the authority"),
|
|
25
30
|
observeForwardLatency: latency(registry, "agentsafe_forward_latency_ms", "Milliseconds spent waiting for the upstream"),
|
|
26
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayMetrics.js","sourceRoot":"","sources":["../../src/gateway/GatewayMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"GatewayMetrics.js","sourceRoot":"","sources":["../../src/gateway/GatewayMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,wBAAwB,CAAC;AAkC3E,SAAS,OAAO,CAAC,QAAiB,EAAE,IAAY,EAAE,IAAY;IAC5D,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,QAAQ,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC;IACjE,OAAO,CAAC,EAAE,EAAE,EAAE;QACZ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACrC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,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B,EACpB,4JAA4J,EAC5J,CAAC,SAAS,CAAC,CACZ;QACD,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,4BAA4B,EAAE,sCAAsC,CAAC;QAC1F,WAAW,EAAE,QAAQ,CAAC,KAAK,CACzB,kCAAkC,EAClC,kEAAkE,EAClE,CAAC,QAAQ,CAAC,CACX;QACD,gBAAgB,EAAE,QAAQ,CAAC,KAAK,CAC9B,8BAA8B,EAC9B,0GAA0G,CAC3G;QACD,uBAAuB,EAAE,OAAO,CAC9B,QAAQ,EACR,gCAAgC,EAChC,8CAA8C,CAC/C;QACD,qBAAqB,EAAE,OAAO,CAC5B,QAAQ,EACR,8BAA8B,EAC9B,6CAA6C,CAC9C;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -7,10 +7,31 @@
|
|
|
7
7
|
import { type ShadowReport } from "./ShadowLedger.js";
|
|
8
8
|
export type GatewayState = "ALLOW" | "BLOCK" | "ESCALATE" | "SHADOW" | "AUTHORITY_UNAVAILABLE" | "EXECUTION_FAILED" | "EXECUTION_INDETERMINATE" | "ERROR"
|
|
9
9
|
/** The gateway's own refusal of a request for its subject: no authority was asked. */
|
|
10
|
-
| "REFUSED"
|
|
10
|
+
| "REFUSED"
|
|
11
|
+
/** An allowed payment a cumulative limit refused after the claim: nothing was sent. */
|
|
12
|
+
| "EXPOSURE_EXCEEDED"
|
|
13
|
+
/** An allowed payment the exposure ledger could not be asked about: nothing was sent. */
|
|
14
|
+
| "EXPOSURE_UNAVAILABLE";
|
|
11
15
|
export type ExecutionDisposition = "FORWARDED" | "NOT_FORWARDED" | "HELD" | "PASSTHROUGH" | "FORWARDED_UNGOVERNED" | "FAILED" | "INDETERMINATE"
|
|
12
16
|
/** A read reached the upstream and its answer was not relayed. */
|
|
13
17
|
| "WITHHELD";
|
|
18
|
+
/**
|
|
19
|
+
* What a route that releases money found in the exposure ledger: within
|
|
20
|
+
* every covering limit, no limit covering it, a limit exceeded, the ledger
|
|
21
|
+
* unavailable (or, under an explicit fail-open, forwarded ungoverned), or,
|
|
22
|
+
* in shadow, facts the request did not state. Limit keys and codes only:
|
|
23
|
+
* never an amount or a subject.
|
|
24
|
+
*/
|
|
25
|
+
export interface ExposureReport {
|
|
26
|
+
readonly status: "WITHIN_LIMIT" | "NOT_APPLICABLE" | "EXCEEDED" | "UNAVAILABLE" | "UNGOVERNED" | "UNREADABLE";
|
|
27
|
+
readonly reason_codes: readonly string[];
|
|
28
|
+
/** The limits reserved against, or the one exceeded. */
|
|
29
|
+
readonly limits: readonly string[];
|
|
30
|
+
/** Limits that cover the action but whose subject the route does not state. */
|
|
31
|
+
readonly unstated: readonly string[];
|
|
32
|
+
/** What became of the reservations once the upstream answered; null before then, or in shadow. */
|
|
33
|
+
readonly settlement: "SETTLED" | "RELEASED" | "KEPT" | "NONE" | "FAILED" | null;
|
|
34
|
+
}
|
|
14
35
|
export interface InterceptionReport {
|
|
15
36
|
readonly event: "INTERCEPTED";
|
|
16
37
|
readonly at: string;
|
|
@@ -31,6 +52,18 @@ export interface InterceptionReport {
|
|
|
31
52
|
readonly finalization: string | null;
|
|
32
53
|
readonly latency_ms: number;
|
|
33
54
|
readonly authority_ms: number | null;
|
|
55
|
+
/**
|
|
56
|
+
* A forwarded write's effect, as the gateway read it back: `CONFIRMED`
|
|
57
|
+
* when the read after it states what the call asked, `UNKNOWN` when it
|
|
58
|
+
* states something else, and `PENDING`, with why, when nothing was read.
|
|
59
|
+
* Present only for a write the upstream accepted in enforcement.
|
|
60
|
+
*/
|
|
61
|
+
readonly effect?: {
|
|
62
|
+
readonly confirmation: "CONFIRMED" | "UNKNOWN" | "PENDING";
|
|
63
|
+
readonly reason_codes: readonly string[];
|
|
64
|
+
};
|
|
65
|
+
/** A route that releases money: what the exposure ledger said. */
|
|
66
|
+
readonly exposure?: ExposureReport;
|
|
34
67
|
}
|
|
35
68
|
export interface StartedReport {
|
|
36
69
|
readonly event: "GATEWAY_STARTED";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayReport.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayReport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,OAAO,GACP,UAAU,GACV,QAAQ,GACR,uBAAuB,GACvB,kBAAkB,GAClB,yBAAyB,GACzB,OAAO;AACT,sFAAsF;GACpF,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"GatewayReport.d.ts","sourceRoot":"","sources":["../../src/gateway/GatewayReport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,OAAO,GACP,UAAU,GACV,QAAQ,GACR,uBAAuB,GACvB,kBAAkB,GAClB,yBAAyB,GACzB,OAAO;AACT,sFAAsF;GACpF,SAAS;AACX,uFAAuF;GACrF,mBAAmB;AACrB,yFAAyF;GACvF,sBAAsB,CAAC;AAE3B,MAAM,MAAM,oBAAoB,GAC5B,WAAW,GACX,eAAe,GACf,MAAM,GACN,aAAa,GACb,sBAAsB,GACtB,QAAQ,GACR,eAAe;AACjB,kEAAkE;GAChE,UAAU,CAAC;AAEf;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EACb,cAAc,GAAG,gBAAgB,GAAG,UAAU,GAAG,aAAa,GAAG,YAAY,GAAG,YAAY,CAAC;IAC/F,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,kGAAkG;IAClG,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,UA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zB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAyHjF;AAED,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAExD"}
|
|
@@ -19,6 +19,8 @@ const COLORS = {
|
|
|
19
19
|
EXECUTION_INDETERMINATE: `${ESC}[35m`,
|
|
20
20
|
ERROR: `${ESC}[35m`,
|
|
21
21
|
REFUSED: `${ESC}[31m`,
|
|
22
|
+
EXPOSURE_EXCEEDED: `${ESC}[31m`,
|
|
23
|
+
EXPOSURE_UNAVAILABLE: `${ESC}[35m`,
|
|
22
24
|
};
|
|
23
25
|
/** The label a state prints under, spaced for reading. */
|
|
24
26
|
export function stateLabel(state) {
|
|
@@ -113,6 +115,15 @@ export function renderHuman(report, options) {
|
|
|
113
115
|
(report.state === "AUTHORITY_UNAVAILABLE" ? "none (authority unreachable)" : "none"), width), row("Reason", reason, width), row("Execution", `${executionLabel(report.execution)}${report.upstream_status === null ? "" : ` (${report.upstream_status})`}`, width));
|
|
114
116
|
}
|
|
115
117
|
lines.push(row("Dossier", report.dossier_id ?? "none", width));
|
|
118
|
+
if (report.effect !== undefined) {
|
|
119
|
+
const why = report.effect.reason_codes[0];
|
|
120
|
+
lines.push(row("Effect", `${report.effect.confirmation}${why === undefined ? "" : ` (${why})`}`, width));
|
|
121
|
+
}
|
|
122
|
+
if (report.exposure !== undefined) {
|
|
123
|
+
const why = report.exposure.reason_codes[0];
|
|
124
|
+
const ended = report.exposure.settlement;
|
|
125
|
+
lines.push(row("Exposure", `${report.exposure.status}${why === undefined ? "" : ` (${why})`}${ended === null || ended === "NONE" ? "" : `, ${ended}`}`, width));
|
|
126
|
+
}
|
|
116
127
|
if (report.finalization !== null)
|
|
117
128
|
lines.push(row("Finalized", report.finalization, width));
|
|
118
129
|
lines.push(row("Latency", `${report.latency_ms}ms`, width), "");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatewayReport.js","sourceRoot":"","sources":["../../src/gateway/GatewayReport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,kBAAkB,EAAqB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"GatewayReport.js","sourceRoot":"","sources":["../../src/gateway/GatewayReport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,kBAAkB,EAAqB,MAAM,mBAAmB,CAAC;AA6J1E,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AACpC,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;AAC1B,MAAM,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC;AACzB,MAAM,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC;AACxB,MAAM,MAAM,GAA2C;IACrD,KAAK,EAAE,GAAG,GAAG,MAAM;IACnB,KAAK,EAAE,GAAG,GAAG,MAAM;IACnB,QAAQ,EAAE,GAAG,GAAG,MAAM;IACtB,MAAM,EAAE,GAAG,GAAG,MAAM;IACpB,qBAAqB,EAAE,GAAG,GAAG,MAAM;IACnC,gBAAgB,EAAE,GAAG,GAAG,MAAM;IAC9B,uBAAuB,EAAE,GAAG,GAAG,MAAM;IACrC,KAAK,EAAE,GAAG,GAAG,MAAM;IACnB,OAAO,EAAE,GAAG,GAAG,MAAM;IACrB,iBAAiB,EAAE,GAAG,GAAG,MAAM;IAC/B,oBAAoB,EAAE,GAAG,GAAG,MAAM;CACnC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAC,KAAmB;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,SAA+B;IAC5D,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,K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
|
1
|
+
import type { CapturedIntent, DecisionGate } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import type { EscalationHandoff } from "../service/EscalationResolver.js";
|
|
3
|
+
import type { InterceptedRequest } from "./InterceptedRequest.js";
|
|
4
|
+
/** One held request: everything a resume needs to ask the authority again and forward it once. */
|
|
5
|
+
export interface HeldEscalation {
|
|
6
|
+
readonly captured: CapturedIntent;
|
|
7
|
+
readonly request: InterceptedRequest;
|
|
8
|
+
readonly decision: DecisionGate;
|
|
9
|
+
readonly handoff: EscalationHandoff | null;
|
|
10
|
+
readonly heldAt: string;
|
|
11
|
+
readonly expiresAt: number;
|
|
12
|
+
/** SHA-256 of the resume token handed to the caller whose request was held; the token itself is not kept. */
|
|
13
|
+
readonly resumeDigest: Buffer;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Where a gateway keeps the requests it holds. A hold is put once, read by
|
|
17
|
+
* the caller holding its resume token, and taken once: `claim` removes it
|
|
18
|
+
* and returns it to exactly one caller, so a request is forwarded at most
|
|
19
|
+
* once by this store; the authority's single-use grant is the backstop.
|
|
20
|
+
*/
|
|
21
|
+
export interface HoldStore {
|
|
22
|
+
/** False when the store is full: the request is held in name only and cannot be resumed. */
|
|
23
|
+
put(intentId: string, entry: HeldEscalation): boolean;
|
|
24
|
+
/** The live hold under an id; an expired one is removed and is absent. */
|
|
25
|
+
get(intentId: string): HeldEscalation | undefined;
|
|
26
|
+
/** Removes the hold and returns it, to one caller only. */
|
|
27
|
+
claim(intentId: string): HeldEscalation | undefined;
|
|
28
|
+
delete(intentId: string): void;
|
|
29
|
+
/** Removes expired holds; returns how many are live. */
|
|
30
|
+
sweep(): number;
|
|
31
|
+
/** Forgets what this process holds in memory; a durable store keeps its holds for the next process. */
|
|
32
|
+
close(): void;
|
|
33
|
+
}
|
|
34
|
+
/** The most holds one gateway keeps. */
|
|
35
|
+
export declare const MAX_HELD = 1000;
|
|
36
|
+
/** Holds in this process's memory: lost on restart, and seen only by this replica. */
|
|
37
|
+
export declare class MemoryHoldStore implements HoldStore {
|
|
38
|
+
private readonly clock;
|
|
39
|
+
private readonly held;
|
|
40
|
+
constructor(clock: () => number);
|
|
41
|
+
put(intentId: string, entry: HeldEscalation): boolean;
|
|
42
|
+
get(intentId: string): HeldEscalation | undefined;
|
|
43
|
+
claim(intentId: string): HeldEscalation | undefined;
|
|
44
|
+
delete(intentId: string): void;
|
|
45
|
+
sweep(): number;
|
|
46
|
+
close(): void;
|
|
47
|
+
}
|
|
48
|
+
/** Why a durable hold store cannot be used: the code, never the key or a path's contents. */
|
|
49
|
+
export declare class HoldStoreError extends Error {
|
|
50
|
+
readonly code: "HOLD_KEY_UNREADABLE" | "HOLD_KEY_INVALID" | "HOLD_DIR_UNUSABLE";
|
|
51
|
+
constructor(code: "HOLD_KEY_UNREADABLE" | "HOLD_KEY_INVALID" | "HOLD_DIR_UNUSABLE");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Holds as files in a directory every replica of a gateway mounts: any
|
|
55
|
+
* replica can resume a hold, and a restart or a reload loses none. Each file
|
|
56
|
+
* is sealed with AES-256-GCM under a key read from a mounted file; the
|
|
57
|
+
* associated data binds it to its scope (the tenant) and its intent id, so a
|
|
58
|
+
* file copied to another tenant's directory or renamed to another intent does
|
|
59
|
+
* not open. File names are digests of the intent id, never the id itself.
|
|
60
|
+
*
|
|
61
|
+
* A claim renames the file to a name only the claimant knows; the rename
|
|
62
|
+
* succeeds for one caller and fails for every other, on one host or across
|
|
63
|
+
* hosts sharing the directory.
|
|
64
|
+
*/
|
|
65
|
+
export declare class FileHoldStore implements HoldStore {
|
|
66
|
+
private readonly dir;
|
|
67
|
+
private readonly scope;
|
|
68
|
+
private readonly clock;
|
|
69
|
+
private readonly key;
|
|
70
|
+
constructor(dir: string, keyFile: string, scope: string, clock: () => number);
|
|
71
|
+
/** The key: 32 bytes, written base64 or base64url (whitespace ignored), or hex. */
|
|
72
|
+
static readKey(keyFile: string): Buffer;
|
|
73
|
+
put(intentId: string, entry: HeldEscalation): boolean;
|
|
74
|
+
get(intentId: string): HeldEscalation | undefined;
|
|
75
|
+
claim(intentId: string): HeldEscalation | undefined;
|
|
76
|
+
delete(intentId: string): void;
|
|
77
|
+
sweep(): number;
|
|
78
|
+
close(): void;
|
|
79
|
+
/** A hold's file, opened and checked; expired, unreadable or forged files are removed. */
|
|
80
|
+
private open;
|
|
81
|
+
private unseal;
|
|
82
|
+
private aad;
|
|
83
|
+
private path;
|
|
84
|
+
private static expiresAt;
|
|
85
|
+
private static olderThan;
|
|
86
|
+
private static encode;
|
|
87
|
+
private static decode;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=HoldStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HoldStore.d.ts","sourceRoot":"","sources":["../../src/gateway/HoldStore.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,kGAAkG;AAClG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,6GAA6G;IAC7G,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,4FAA4F;IAC5F,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,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GAAG,CAAS;gBAGV,GAAG,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACE,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM;IAWtC,mFAAmF;WACrE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAcvC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO;IAkCrD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIjD,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAenD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI9B,KAAK,IAAI,MAAM;IA0Bf,KAAK,IAAI,IAAI;IAIpB,0FAA0F;IAC1F,OAAO,CAAC,IAAI;IAeZ,OAAO,CAAC,MAAM;IAuBd,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,SAAS;IAQxB,OAAO,CAAC,MAAM,CAAC,MAAM;IAYrB,OAAO,CAAC,MAAM,CAAC,MAAM;CAOtB"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { closeSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeSync, } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
/** The most holds one gateway keeps. */
|
|
5
|
+
export const MAX_HELD = 1_000;
|
|
6
|
+
/** Holds in this process's memory: lost on restart, and seen only by this replica. */
|
|
7
|
+
export class MemoryHoldStore {
|
|
8
|
+
clock;
|
|
9
|
+
held = new Map();
|
|
10
|
+
constructor(clock) {
|
|
11
|
+
this.clock = clock;
|
|
12
|
+
}
|
|
13
|
+
put(intentId, entry) {
|
|
14
|
+
this.sweep();
|
|
15
|
+
if (this.held.size >= MAX_HELD)
|
|
16
|
+
return false;
|
|
17
|
+
this.held.set(intentId, entry);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
get(intentId) {
|
|
21
|
+
this.sweep();
|
|
22
|
+
return this.held.get(intentId);
|
|
23
|
+
}
|
|
24
|
+
claim(intentId) {
|
|
25
|
+
const entry = this.get(intentId);
|
|
26
|
+
if (entry !== undefined)
|
|
27
|
+
this.held.delete(intentId);
|
|
28
|
+
return entry;
|
|
29
|
+
}
|
|
30
|
+
delete(intentId) {
|
|
31
|
+
this.held.delete(intentId);
|
|
32
|
+
}
|
|
33
|
+
sweep() {
|
|
34
|
+
const now = this.clock();
|
|
35
|
+
for (const [id, entry] of this.held) {
|
|
36
|
+
if (entry.expiresAt <= now)
|
|
37
|
+
this.held.delete(id);
|
|
38
|
+
}
|
|
39
|
+
return this.held.size;
|
|
40
|
+
}
|
|
41
|
+
close() {
|
|
42
|
+
this.held.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Why a durable hold store cannot be used: the code, never the key or a path's contents. */
|
|
46
|
+
export class HoldStoreError extends Error {
|
|
47
|
+
code;
|
|
48
|
+
constructor(code) {
|
|
49
|
+
super(code);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.name = "HoldStoreError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const FORMAT = "agentsafe.hold/1";
|
|
55
|
+
const SUFFIX = ".hold";
|
|
56
|
+
/** A claimed hold's file, left only if the claiming process died before removing it. */
|
|
57
|
+
const CLAIMED = ".claimed";
|
|
58
|
+
const TEMPORARY = ".tmp";
|
|
59
|
+
/** How long a claimed or half-written file may stay before a sweep removes it. */
|
|
60
|
+
const ORPHAN_MS = 10 * 60_000;
|
|
61
|
+
/**
|
|
62
|
+
* Holds as files in a directory every replica of a gateway mounts: any
|
|
63
|
+
* replica can resume a hold, and a restart or a reload loses none. Each file
|
|
64
|
+
* is sealed with AES-256-GCM under a key read from a mounted file; the
|
|
65
|
+
* associated data binds it to its scope (the tenant) and its intent id, so a
|
|
66
|
+
* file copied to another tenant's directory or renamed to another intent does
|
|
67
|
+
* not open. File names are digests of the intent id, never the id itself.
|
|
68
|
+
*
|
|
69
|
+
* A claim renames the file to a name only the claimant knows; the rename
|
|
70
|
+
* succeeds for one caller and fails for every other, on one host or across
|
|
71
|
+
* hosts sharing the directory.
|
|
72
|
+
*/
|
|
73
|
+
export class FileHoldStore {
|
|
74
|
+
dir;
|
|
75
|
+
scope;
|
|
76
|
+
clock;
|
|
77
|
+
key;
|
|
78
|
+
constructor(dir, keyFile, scope, clock) {
|
|
79
|
+
this.dir = dir;
|
|
80
|
+
this.scope = scope;
|
|
81
|
+
this.clock = clock;
|
|
82
|
+
this.key = FileHoldStore.readKey(keyFile);
|
|
83
|
+
try {
|
|
84
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
85
|
+
statSync(dir);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw new HoldStoreError("HOLD_DIR_UNUSABLE");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The key: 32 bytes, written base64 or base64url (whitespace ignored), or hex. */
|
|
92
|
+
static readKey(keyFile) {
|
|
93
|
+
let text;
|
|
94
|
+
try {
|
|
95
|
+
text = readFileSync(keyFile, "utf8").trim();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new HoldStoreError("HOLD_KEY_UNREADABLE");
|
|
99
|
+
}
|
|
100
|
+
const key = /^[0-9a-f]{64}$/i.test(text)
|
|
101
|
+
? Buffer.from(text, "hex")
|
|
102
|
+
: Buffer.from(text.replace(/\s+/g, ""), "base64url");
|
|
103
|
+
if (key.length !== 32)
|
|
104
|
+
throw new HoldStoreError("HOLD_KEY_INVALID");
|
|
105
|
+
return key;
|
|
106
|
+
}
|
|
107
|
+
put(intentId, entry) {
|
|
108
|
+
if (this.sweep() >= MAX_HELD)
|
|
109
|
+
return false;
|
|
110
|
+
const iv = randomBytes(12);
|
|
111
|
+
const cipher = createCipheriv("aes-256-gcm", this.key, iv);
|
|
112
|
+
cipher.setAAD(this.aad(intentId, entry.expiresAt));
|
|
113
|
+
const data = Buffer.concat([
|
|
114
|
+
cipher.update(JSON.stringify(FileHoldStore.encode(entry)), "utf8"),
|
|
115
|
+
cipher.final(),
|
|
116
|
+
]);
|
|
117
|
+
const sealed = {
|
|
118
|
+
format: FORMAT,
|
|
119
|
+
expiresAt: entry.expiresAt,
|
|
120
|
+
iv: iv.toString("base64url"),
|
|
121
|
+
tag: cipher.getAuthTag().toString("base64url"),
|
|
122
|
+
data: data.toString("base64url"),
|
|
123
|
+
};
|
|
124
|
+
const path = this.path(intentId);
|
|
125
|
+
const temporary = `${path}.${randomBytes(6).toString("hex")}${TEMPORARY}`;
|
|
126
|
+
try {
|
|
127
|
+
const fd = openSync(temporary, "wx", 0o600);
|
|
128
|
+
try {
|
|
129
|
+
writeSync(fd, JSON.stringify(sealed));
|
|
130
|
+
fsyncSync(fd);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
closeSync(fd);
|
|
134
|
+
}
|
|
135
|
+
renameSync(temporary, path);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
rmSync(temporary, { force: true });
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
get(intentId) {
|
|
144
|
+
return this.open(intentId, this.path(intentId), true);
|
|
145
|
+
}
|
|
146
|
+
claim(intentId) {
|
|
147
|
+
const path = this.path(intentId);
|
|
148
|
+
const claimed = `${path}.${randomBytes(6).toString("hex")}${CLAIMED}`;
|
|
149
|
+
try {
|
|
150
|
+
renameSync(path, claimed);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return this.open(intentId, claimed, false);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
rmSync(claimed, { force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
delete(intentId) {
|
|
163
|
+
rmSync(this.path(intentId), { force: true });
|
|
164
|
+
}
|
|
165
|
+
sweep() {
|
|
166
|
+
const now = this.clock();
|
|
167
|
+
let live = 0;
|
|
168
|
+
let names;
|
|
169
|
+
try {
|
|
170
|
+
names = readdirSync(this.dir);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
for (const name of names) {
|
|
176
|
+
const path = join(this.dir, name);
|
|
177
|
+
if (name.endsWith(CLAIMED) || name.endsWith(TEMPORARY)) {
|
|
178
|
+
if (FileHoldStore.olderThan(path, now - ORPHAN_MS))
|
|
179
|
+
rmSync(path, { force: true });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (!name.endsWith(SUFFIX))
|
|
183
|
+
continue;
|
|
184
|
+
const expiresAt = FileHoldStore.expiresAt(path);
|
|
185
|
+
if (expiresAt === null || expiresAt <= now) {
|
|
186
|
+
rmSync(path, { force: true });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
live += 1;
|
|
190
|
+
}
|
|
191
|
+
return live;
|
|
192
|
+
}
|
|
193
|
+
close() {
|
|
194
|
+
// The holds are the next process's to resume.
|
|
195
|
+
}
|
|
196
|
+
/** A hold's file, opened and checked; expired, unreadable or forged files are removed. */
|
|
197
|
+
open(intentId, path, removeBad) {
|
|
198
|
+
let sealed;
|
|
199
|
+
try {
|
|
200
|
+
sealed = JSON.parse(readFileSync(path, "utf8"));
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
const entry = this.unseal(intentId, sealed);
|
|
206
|
+
if (entry === null || entry.expiresAt <= this.clock()) {
|
|
207
|
+
if (removeBad)
|
|
208
|
+
rmSync(path, { force: true });
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
return entry;
|
|
212
|
+
}
|
|
213
|
+
unseal(intentId, sealed) {
|
|
214
|
+
if (sealed?.format !== FORMAT || typeof sealed.expiresAt !== "number")
|
|
215
|
+
return null;
|
|
216
|
+
try {
|
|
217
|
+
const decipher = createDecipheriv("aes-256-gcm", this.key, Buffer.from(sealed.iv, "base64url"));
|
|
218
|
+
decipher.setAAD(this.aad(intentId, sealed.expiresAt));
|
|
219
|
+
decipher.setAuthTag(Buffer.from(sealed.tag, "base64url"));
|
|
220
|
+
const plain = Buffer.concat([
|
|
221
|
+
decipher.update(Buffer.from(sealed.data, "base64url")),
|
|
222
|
+
decipher.final(),
|
|
223
|
+
]).toString("utf8");
|
|
224
|
+
const entry = FileHoldStore.decode(JSON.parse(plain));
|
|
225
|
+
return entry.expiresAt === sealed.expiresAt && entry.captured.intent.intentId === intentId
|
|
226
|
+
? entry
|
|
227
|
+
: null;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
aad(intentId, expiresAt) {
|
|
234
|
+
return Buffer.from(`${FORMAT}\u0000${this.scope}\u0000${intentId}\u0000${expiresAt}`, "utf8");
|
|
235
|
+
}
|
|
236
|
+
path(intentId) {
|
|
237
|
+
const name = createHash("sha256")
|
|
238
|
+
.update(`${this.scope}\u0000${intentId}`, "utf8")
|
|
239
|
+
.digest("hex");
|
|
240
|
+
return join(this.dir, `${name}${SUFFIX}`);
|
|
241
|
+
}
|
|
242
|
+
static expiresAt(path) {
|
|
243
|
+
try {
|
|
244
|
+
const sealed = JSON.parse(readFileSync(path, "utf8"));
|
|
245
|
+
return sealed.format === FORMAT && typeof sealed.expiresAt === "number"
|
|
246
|
+
? sealed.expiresAt
|
|
247
|
+
: null;
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
static olderThan(path, cutoff) {
|
|
254
|
+
try {
|
|
255
|
+
return statSync(path).mtimeMs < cutoff;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
static encode(entry) {
|
|
262
|
+
return {
|
|
263
|
+
captured: entry.captured,
|
|
264
|
+
request: { ...entry.request, body: entry.request.body.toString("base64") },
|
|
265
|
+
decision: entry.decision,
|
|
266
|
+
handoff: entry.handoff,
|
|
267
|
+
heldAt: entry.heldAt,
|
|
268
|
+
expiresAt: entry.expiresAt,
|
|
269
|
+
resumeDigest: entry.resumeDigest.toString("base64"),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
static decode(encoded) {
|
|
273
|
+
return {
|
|
274
|
+
...encoded,
|
|
275
|
+
request: { ...encoded.request, body: Buffer.from(encoded.request.body, "base64") },
|
|
276
|
+
resumeDigest: Buffer.from(encoded.resumeDigest, "base64"),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=HoldStore.js.map
|