@decionis/agent-safe-pipeline 0.1.3 → 0.2.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.
Files changed (104) hide show
  1. package/README.md +477 -16
  2. package/dist/Index.d.ts +9 -0
  3. package/dist/Index.d.ts.map +1 -1
  4. package/dist/Index.js +8 -0
  5. package/dist/Index.js.map +1 -1
  6. package/dist/approval/PresenceApprovalCoordinator.d.ts +25 -0
  7. package/dist/approval/PresenceApprovalCoordinator.d.ts.map +1 -1
  8. package/dist/approval/PresenceApprovalCoordinator.js +54 -6
  9. package/dist/approval/PresenceApprovalCoordinator.js.map +1 -1
  10. package/dist/audit/AuditRecorder.d.ts +122 -0
  11. package/dist/audit/AuditRecorder.d.ts.map +1 -0
  12. package/dist/audit/AuditRecorder.js +312 -0
  13. package/dist/audit/AuditRecorder.js.map +1 -0
  14. package/dist/decision/CreateGate.d.ts +123 -0
  15. package/dist/decision/CreateGate.d.ts.map +1 -0
  16. package/dist/decision/CreateGate.js +211 -0
  17. package/dist/decision/CreateGate.js.map +1 -0
  18. package/dist/decision/DecionisGate.d.ts +109 -3
  19. package/dist/decision/DecionisGate.d.ts.map +1 -1
  20. package/dist/decision/DecionisGate.js +823 -46
  21. package/dist/decision/DecionisGate.js.map +1 -1
  22. package/dist/decision/DecisionAuthority.d.ts +76 -1
  23. package/dist/decision/DecisionAuthority.d.ts.map +1 -1
  24. package/dist/decision/DecisionAuthority.js.map +1 -1
  25. package/dist/decision/FixtureDecisionAuthority.d.ts +27 -1
  26. package/dist/decision/FixtureDecisionAuthority.d.ts.map +1 -1
  27. package/dist/decision/FixtureDecisionAuthority.js +47 -0
  28. package/dist/decision/FixtureDecisionAuthority.js.map +1 -1
  29. package/dist/decision/ImmutableGateDecision.d.ts.map +1 -1
  30. package/dist/decision/ImmutableGateDecision.js +26 -0
  31. package/dist/decision/ImmutableGateDecision.js.map +1 -1
  32. package/dist/decision/Provision.d.ts +33 -0
  33. package/dist/decision/Provision.d.ts.map +1 -0
  34. package/dist/decision/Provision.js +116 -0
  35. package/dist/decision/Provision.js.map +1 -0
  36. package/dist/decision/ShadowGate.d.ts +31 -0
  37. package/dist/decision/ShadowGate.d.ts.map +1 -0
  38. package/dist/decision/ShadowGate.js +79 -0
  39. package/dist/decision/ShadowGate.js.map +1 -0
  40. package/dist/execution/ActionRegistry.d.ts +66 -0
  41. package/dist/execution/ActionRegistry.d.ts.map +1 -1
  42. package/dist/execution/ActionRegistry.js +110 -1
  43. package/dist/execution/ActionRegistry.js.map +1 -1
  44. package/dist/execution/AuthorizationVerifier.d.ts +149 -1
  45. package/dist/execution/AuthorizationVerifier.d.ts.map +1 -1
  46. package/dist/execution/AuthorizationVerifier.js +302 -27
  47. package/dist/execution/AuthorizationVerifier.js.map +1 -1
  48. package/dist/execution/SafeExecutor.d.ts +102 -7
  49. package/dist/execution/SafeExecutor.d.ts.map +1 -1
  50. package/dist/execution/SafeExecutor.js +288 -17
  51. package/dist/execution/SafeExecutor.js.map +1 -1
  52. package/dist/http/ClientIdentification.d.ts +22 -0
  53. package/dist/http/ClientIdentification.d.ts.map +1 -0
  54. package/dist/http/ClientIdentification.js +44 -0
  55. package/dist/http/ClientIdentification.js.map +1 -0
  56. package/dist/http/Credential.d.ts +17 -0
  57. package/dist/http/Credential.d.ts.map +1 -0
  58. package/dist/http/Credential.js +5 -0
  59. package/dist/http/Credential.js.map +1 -0
  60. package/dist/http/StoredCredentials.d.ts +34 -0
  61. package/dist/http/StoredCredentials.d.ts.map +1 -0
  62. package/dist/http/StoredCredentials.js +85 -0
  63. package/dist/http/StoredCredentials.js.map +1 -0
  64. package/dist/intent/CanonicalIntentHasher.d.ts +1 -1
  65. package/dist/intent/CanonicalIntentHasher.d.ts.map +1 -1
  66. package/dist/intent/CanonicalIntentHasher.js +9 -2
  67. package/dist/intent/CanonicalIntentHasher.js.map +1 -1
  68. package/dist/intent/ExecutionIntent.d.ts +26 -2
  69. package/dist/intent/ExecutionIntent.d.ts.map +1 -1
  70. package/dist/intent/ExecutionIntent.js +11 -0
  71. package/dist/intent/ExecutionIntent.js.map +1 -1
  72. package/dist/intent/IntentCapture.d.ts +5 -0
  73. package/dist/intent/IntentCapture.d.ts.map +1 -1
  74. package/dist/intent/IntentCapture.js +15 -1
  75. package/dist/intent/IntentCapture.js.map +1 -1
  76. package/dist/report/DecisionReport.d.ts +22 -0
  77. package/dist/report/DecisionReport.d.ts.map +1 -0
  78. package/dist/report/DecisionReport.js +37 -0
  79. package/dist/report/DecisionReport.js.map +1 -0
  80. package/dist/report/DossierReport.d.ts +43 -0
  81. package/dist/report/DossierReport.d.ts.map +1 -0
  82. package/dist/report/DossierReport.js +130 -0
  83. package/dist/report/DossierReport.js.map +1 -0
  84. package/dist/report/HostedOutcome.d.ts +18 -0
  85. package/dist/report/HostedOutcome.d.ts.map +1 -0
  86. package/dist/report/HostedOutcome.js +24 -0
  87. package/dist/report/HostedOutcome.js.map +1 -0
  88. package/dist/shadow/ShadowPipeline.d.ts +75 -5
  89. package/dist/shadow/ShadowPipeline.d.ts.map +1 -1
  90. package/dist/shadow/ShadowPipeline.js +157 -7
  91. package/dist/shadow/ShadowPipeline.js.map +1 -1
  92. package/dist/testing/Index.d.ts +12 -0
  93. package/dist/testing/Index.d.ts.map +1 -0
  94. package/dist/testing/Index.js +12 -0
  95. package/dist/testing/Index.js.map +1 -0
  96. package/dist/testing/LocalAuthority.d.ts +292 -0
  97. package/dist/testing/LocalAuthority.d.ts.map +1 -0
  98. package/dist/testing/LocalAuthority.js +1124 -0
  99. package/dist/testing/LocalAuthority.js.map +1 -0
  100. package/dist/testing/LocalPresence.d.ts +210 -0
  101. package/dist/testing/LocalPresence.d.ts.map +1 -0
  102. package/dist/testing/LocalPresence.js +473 -0
  103. package/dist/testing/LocalPresence.js.map +1 -0
  104. package/package.json +40 -4
@@ -0,0 +1,312 @@
1
+ import { randomUUID } from "node:crypto";
2
+ const DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
3
+ const AUDIT_AUTHORITIES = new Set([
4
+ "AUTHORITATIVE",
5
+ "OBSERVATIONAL",
6
+ "NON_AUTHORITATIVE",
7
+ ]);
8
+ const AUDIT_VERDICTS = new Set(["ALLOW", "ESCALATE", "BLOCK"]);
9
+ const RESTRICTED_METADATA_KEY = /authorization|credential|password|secret|token|parameters|context|provider[_-]?result/i;
10
+ const MAX_METADATA_DEPTH = 4;
11
+ const MAX_METADATA_ENTRIES = 50;
12
+ const MAX_METADATA_ARRAY = 20;
13
+ const MAX_METADATA_STRING = 500;
14
+ const MAX_METADATA_BYTES = 4 * 1024;
15
+ /**
16
+ * Emits immutable, redacted lifecycle records through one bounded sink call.
17
+ * Sink failures are converted to `false`; the recorder never retries because
18
+ * retries could reorder evidence or couple provider execution to sink health.
19
+ */
20
+ export class AuditRecorder {
21
+ options;
22
+ timeoutMs;
23
+ failurePolicy;
24
+ metadataAllowlist;
25
+ clock;
26
+ createId;
27
+ constructor(options) {
28
+ this.options = options;
29
+ this.timeoutMs = Math.min(Math.max(options.timeoutMs ?? 100, 1), 5_000);
30
+ this.failurePolicy = options.failurePolicy ?? "BEST_EFFORT";
31
+ this.metadataAllowlist = new Set(options.metadataAllowlist ?? []);
32
+ this.clock = options.clock ?? (() => new Date());
33
+ this.createId = options.createId ?? randomUUID;
34
+ if (this.metadataAllowlist.size > MAX_METADATA_ENTRIES) {
35
+ throw new Error("AUDIT_METADATA_ALLOWLIST_TOO_LARGE");
36
+ }
37
+ for (const key of this.metadataAllowlist)
38
+ AuditRecorder.assertIdentifier(key);
39
+ }
40
+ get requiresDeliveryBeforeExecution() {
41
+ return this.failurePolicy === "REQUIRE_BEFORE_EXECUTION";
42
+ }
43
+ async record(input) {
44
+ try {
45
+ const event = this.event(input);
46
+ const delivered = await new Promise((resolve) => {
47
+ let settled = false;
48
+ const settle = (result) => {
49
+ if (settled)
50
+ return;
51
+ settled = true;
52
+ clearTimeout(timeout);
53
+ resolve(result);
54
+ };
55
+ const timeout = setTimeout(() => settle(false), this.timeoutMs);
56
+ void Promise.resolve()
57
+ .then(async () => await this.options.sink.write(event))
58
+ .then(() => settle(true), () => settle(false));
59
+ });
60
+ return delivered;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ event(input) {
67
+ AuditRecorder.assertIdentifier(input.captured.intent.intentId);
68
+ AuditRecorder.assertDigest(input.captured.intentHash);
69
+ if (input.durationMs !== undefined &&
70
+ (!Number.isFinite(input.durationMs) || input.durationMs < 0)) {
71
+ throw new Error("AUDIT_DURATION_INVALID");
72
+ }
73
+ const reasonCodes = input.reasonCodes ?? input.decision?.reasonCodes ?? [];
74
+ if (reasonCodes.length > 50)
75
+ throw new Error("AUDIT_REASON_CODES_TOO_MANY");
76
+ for (const reasonCode of reasonCodes) {
77
+ AuditRecorder.assertIdentifier(reasonCode);
78
+ }
79
+ const authority = input.authority ?? AuditRecorder.defaultAuthority(input.eventType);
80
+ if (!AUDIT_AUTHORITIES.has(authority))
81
+ throw new Error("AUDIT_AUTHORITY_INVALID");
82
+ if (input.eventType === "SHADOW_EVALUATED" && authority !== "OBSERVATIONAL") {
83
+ throw new Error("AUDIT_SHADOW_MUST_BE_OBSERVATIONAL");
84
+ }
85
+ const verdict = input.verdict ?? input.decision?.verdict ?? null;
86
+ if (verdict !== null && !AUDIT_VERDICTS.has(verdict)) {
87
+ throw new Error("AUDIT_VERDICT_INVALID");
88
+ }
89
+ const decisionId = input.decisionId ?? input.decision?.decisionId;
90
+ const dossierId = input.dossierId ?? input.decision?.dossierId ?? undefined;
91
+ const grantId = input.grantId ?? input.authorization?.grantId;
92
+ // Observational evidence must never correlate to an execution grant.
93
+ if (authority === "OBSERVATIONAL" && (grantId !== undefined || input.authorization)) {
94
+ throw new Error("AUDIT_OBSERVATIONAL_GRANT_FORBIDDEN");
95
+ }
96
+ if (decisionId !== undefined)
97
+ AuditRecorder.assertIdentifier(decisionId);
98
+ if (dossierId !== undefined)
99
+ AuditRecorder.assertIdentifier(dossierId);
100
+ if (grantId !== undefined)
101
+ AuditRecorder.assertIdentifier(grantId);
102
+ if (input.captured.intent.correlationId !== undefined) {
103
+ AuditRecorder.assertIdentifier(input.captured.intent.correlationId);
104
+ }
105
+ const evaluation = input.decision
106
+ ? this.evaluation(input.captured, input.decision, input.evaluation)
107
+ : null;
108
+ const event = {
109
+ schemaVersion: "agent-safe.audit/1",
110
+ eventId: this.boundedId(this.createId()),
111
+ occurredAt: this.validDate(this.clock()).toISOString(),
112
+ eventType: input.eventType,
113
+ authority,
114
+ correlation: {
115
+ intentId: input.captured.intent.intentId,
116
+ intentHash: input.captured.intentHash,
117
+ ...(input.captured.intent.correlationId === undefined
118
+ ? {}
119
+ : { correlationId: input.captured.intent.correlationId }),
120
+ ...(decisionId === undefined ? {} : { decisionId }),
121
+ ...(dossierId === undefined ? {} : { dossierId }),
122
+ ...(grantId === undefined ? {} : { grantId }),
123
+ },
124
+ evaluation,
125
+ verdict,
126
+ reasonCodes: [...reasonCodes],
127
+ durationMs: input.durationMs === undefined ? null : Math.round(input.durationMs * 1_000) / 1_000,
128
+ metadata: this.metadata(input.metadata),
129
+ };
130
+ return AuditRecorder.deepFreeze(event);
131
+ }
132
+ evaluation(captured, decision, evidence) {
133
+ const evaluationId = evidence?.evaluationId ?? decision.decisionId;
134
+ const materialInputDigest = evidence?.materialInputDigest ?? captured.intentHash;
135
+ const evidenceReference = evidence?.evidenceReference ?? decision.dossierId;
136
+ AuditRecorder.assertIdentifier(evaluationId);
137
+ AuditRecorder.assertDigest(materialInputDigest);
138
+ if (evidenceReference !== null)
139
+ AuditRecorder.assertIdentifier(evidenceReference);
140
+ let policy = null;
141
+ if (evidence?.policy !== undefined) {
142
+ AuditRecorder.assertIdentifier(evidence.policy.policyId);
143
+ AuditRecorder.assertIdentifier(evidence.policy.revisionId);
144
+ if (/^(?:current|latest)$/i.test(evidence.policy.revisionId)) {
145
+ throw new Error("AUDIT_POLICY_REVISION_MUTABLE_ALIAS");
146
+ }
147
+ if (evidence.policy.version !== undefined) {
148
+ AuditRecorder.assertIdentifier(evidence.policy.version);
149
+ }
150
+ AuditRecorder.assertDigest(evidence.policy.digest);
151
+ policy = { ...evidence.policy };
152
+ }
153
+ return {
154
+ evaluationId,
155
+ materialInputDigest,
156
+ policy,
157
+ evidenceReference,
158
+ };
159
+ }
160
+ metadata(input) {
161
+ if (input === undefined)
162
+ return Object.freeze({});
163
+ const output = {};
164
+ for (const [key, value] of Object.entries(input)) {
165
+ if (!this.metadataAllowlist.has(key) || RESTRICTED_METADATA_KEY.test(key))
166
+ continue;
167
+ const redacted = this.options.redactMetadata === undefined ? value : this.options.redactMetadata(key, value);
168
+ if (redacted !== undefined)
169
+ output[key] = this.copyJson(redacted, 0, { entries: 0 });
170
+ }
171
+ if (Buffer.byteLength(JSON.stringify(output), "utf8") > MAX_METADATA_BYTES) {
172
+ throw new Error("AUDIT_METADATA_TOO_LARGE");
173
+ }
174
+ return AuditRecorder.deepFreeze(output);
175
+ }
176
+ copyJson(value, depth, count) {
177
+ if (depth > MAX_METADATA_DEPTH)
178
+ throw new Error("AUDIT_METADATA_TOO_DEEP");
179
+ if (typeof value === "string") {
180
+ if (value.length > MAX_METADATA_STRING)
181
+ throw new Error("AUDIT_METADATA_STRING_TOO_LONG");
182
+ return value;
183
+ }
184
+ if (typeof value === "number" && !Number.isFinite(value)) {
185
+ throw new Error("AUDIT_METADATA_NUMBER_INVALID");
186
+ }
187
+ if (value === null || typeof value !== "object")
188
+ return value;
189
+ if (Array.isArray(value)) {
190
+ if (value.length > MAX_METADATA_ARRAY)
191
+ throw new Error("AUDIT_METADATA_ARRAY_TOO_LONG");
192
+ return value.map((entry) => {
193
+ count.entries += 1;
194
+ if (count.entries > MAX_METADATA_ENTRIES)
195
+ throw new Error("AUDIT_METADATA_TOO_COMPLEX");
196
+ return this.copyJson(entry, depth + 1, count);
197
+ });
198
+ }
199
+ const prototype = Object.getPrototypeOf(value);
200
+ if (prototype !== Object.prototype && prototype !== null) {
201
+ throw new Error("AUDIT_METADATA_OBJECT_INVALID");
202
+ }
203
+ const copy = {};
204
+ for (const [key, entry] of Object.entries(value)) {
205
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
206
+ throw new Error("AUDIT_METADATA_KEY_INVALID");
207
+ }
208
+ count.entries += 1;
209
+ if (count.entries > MAX_METADATA_ENTRIES)
210
+ throw new Error("AUDIT_METADATA_TOO_COMPLEX");
211
+ copy[key] = this.copyJson(entry, depth + 1, count);
212
+ }
213
+ return copy;
214
+ }
215
+ boundedId(value) {
216
+ AuditRecorder.assertIdentifier(value);
217
+ return value;
218
+ }
219
+ validDate(value) {
220
+ if (!(value instanceof Date) || !Number.isFinite(value.valueOf())) {
221
+ throw new Error("AUDIT_CLOCK_INVALID");
222
+ }
223
+ return value;
224
+ }
225
+ static defaultAuthority(eventType) {
226
+ if (eventType === "INTENT_CAPTURED")
227
+ return "NON_AUTHORITATIVE";
228
+ if (eventType === "SHADOW_EVALUATED")
229
+ return "OBSERVATIONAL";
230
+ if (eventType === "PRESENCE_ESCALATED" || eventType === "PRESENCE_RESOLVED") {
231
+ return "NON_AUTHORITATIVE";
232
+ }
233
+ return "AUTHORITATIVE";
234
+ }
235
+ static assertIdentifier(value) {
236
+ if (!isBoundedIdentifier(value))
237
+ throw new Error("AUDIT_IDENTIFIER_INVALID");
238
+ }
239
+ static assertDigest(value) {
240
+ if (!DIGEST_PATTERN.test(value))
241
+ throw new Error("AUDIT_DIGEST_INVALID");
242
+ }
243
+ static deepFreeze(value) {
244
+ if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
245
+ Object.freeze(value);
246
+ for (const child of Object.values(value)) {
247
+ AuditRecorder.deepFreeze(child);
248
+ }
249
+ }
250
+ return value;
251
+ }
252
+ }
253
+ /** Resolves historical policy evidence by its pinned revision, never by a mutable alias. */
254
+ export class AuditPolicyRevisionVerifier {
255
+ resolver;
256
+ timeoutMs;
257
+ constructor(resolver, timeoutMs = 1_000) {
258
+ this.resolver = resolver;
259
+ this.timeoutMs = Math.min(Math.max(timeoutMs, 1), 15_000);
260
+ }
261
+ async verify(event) {
262
+ const reference = event.evaluation?.policy;
263
+ if (reference === null || reference === undefined) {
264
+ return { status: "NOT_REFERENCED", artifact: null };
265
+ }
266
+ const resolved = await new Promise((resolve) => {
267
+ let settled = false;
268
+ const settle = (value) => {
269
+ if (settled)
270
+ return;
271
+ settled = true;
272
+ clearTimeout(timeout);
273
+ resolve(value);
274
+ };
275
+ const timeout = setTimeout(() => settle(undefined), this.timeoutMs);
276
+ void Promise.resolve()
277
+ .then(async () => await this.resolver.resolve(reference.policyId, reference.revisionId))
278
+ .then((artifact) => settle(artifact), () => settle(undefined));
279
+ });
280
+ if (resolved === undefined)
281
+ return { status: "UNAVAILABLE", artifact: null };
282
+ if (resolved === null)
283
+ return { status: "MISSING", artifact: null };
284
+ if (resolved.policyId !== reference.policyId || resolved.revisionId !== reference.revisionId) {
285
+ return { status: "IDENTITY_MISMATCH", artifact: null };
286
+ }
287
+ if (resolved.digest !== reference.digest) {
288
+ return { status: "DIGEST_MISMATCH", artifact: null };
289
+ }
290
+ if (!isBoundedIdentifier(resolved.artifactReference) ||
291
+ !isBoundedIdentifier(resolved.policyId) ||
292
+ !isBoundedIdentifier(resolved.revisionId) ||
293
+ !DIGEST_PATTERN.test(resolved.digest)) {
294
+ return { status: "UNAVAILABLE", artifact: null };
295
+ }
296
+ return {
297
+ status: "VERIFIED",
298
+ artifact: Object.freeze({ ...resolved }),
299
+ };
300
+ }
301
+ }
302
+ function isBoundedIdentifier(value) {
303
+ if (value.length < 1 || value.length > 200)
304
+ return false;
305
+ for (let index = 0; index < value.length; index += 1) {
306
+ const codeUnit = value.charCodeAt(index);
307
+ if (codeUnit <= 0x1f || codeUnit === 0x7f)
308
+ return false;
309
+ }
310
+ return true;
311
+ }
312
+ //# sourceMappingURL=AuditRecorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditRecorder.js","sourceRoot":"","sources":["../../src/audit/AuditRecorder.ts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YAChD,CAAC,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACvC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC;YACzC,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EACrC,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QACnD,CAAC;QACD,OAAO;YACL,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC;SACzC,CAAC;IACJ,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IACzD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,QAAQ,IAAI,IAAI,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { type AuthorizationVerifier } from "../execution/AuthorizationVerifier.js";
2
+ import type { ClientSource } from "../http/ClientIdentification.js";
3
+ import { type CredentialFiles } from "../http/StoredCredentials.js";
4
+ import type { DecisionAuthority, DecisionEvaluationMode } from "./DecisionAuthority.js";
5
+ import { type SignedDossierSummary } from "../report/DossierReport.js";
6
+ import { type ProvisionOptions, type ProvisionedWorkspace } from "./Provision.js";
7
+ export type GateMode = "LOCAL" | DecisionEvaluationMode;
8
+ /** An authority and the verifier that can claim the grants it issues. */
9
+ export interface AuthorityPair {
10
+ readonly authority: DecisionAuthority;
11
+ readonly verifier: AuthorizationVerifier;
12
+ }
13
+ export interface SelectedGate extends AuthorityPair {
14
+ readonly mode: GateMode;
15
+ /**
16
+ * The tenant a captured intent must name. In a hosted mode this is the
17
+ * key's own organization, because Decionis binds every intent to it; in
18
+ * `LOCAL` mode it is the `tenantId` the caller passed.
19
+ */
20
+ readonly tenantId: string;
21
+ }
22
+ export interface CreateGateOptions {
23
+ /**
24
+ * The pair that runs when no key is set. It keeps governing execution in
25
+ * `SHADOW` mode, and in `ENFORCEMENT` mode its authority can only tighten
26
+ * the hosted decision.
27
+ */
28
+ readonly local: AuthorityPair;
29
+ /** The tenant used when no key is set. */
30
+ readonly tenantId: string;
31
+ /** Defaults to `process.env`. */
32
+ readonly env?: Readonly<Record<string, string | undefined>>;
33
+ readonly fetch?: typeof fetch;
34
+ /** Carried in the `User-Agent` of hosted calls only; never sent without a key. */
35
+ readonly source?: ClientSource;
36
+ }
37
+ /**
38
+ * Selects the gate from the environment.
39
+ *
40
+ * `DECIONIS_API_KEY` unset: returns `local` itself, the same authority and
41
+ * verifier objects, with no client constructed and no network call. A caller
42
+ * that sets nothing gets exactly what it gets today.
43
+ *
44
+ * `DECIONIS_API_KEY` set: `DecionisGate` runs beside `local` through
45
+ * `ShadowGate`, in `DECIONIS_MODE` (`SHADOW` by default, `ENFORCEMENT` on
46
+ * request). `DECIONIS_TENANT_ID` is then required, because Decionis binds
47
+ * every intent to the key's own organization and refuses any other tenant.
48
+ * `DECIONIS_API_URL`, `DECIONIS_TIMEOUT_MS` and `DECIONIS_ALLOW_INSECURE_LOOPBACK`
49
+ * configure the connection the way the trusted executor's do.
50
+ */
51
+ export declare function createGate(options: CreateGateOptions): SelectedGate;
52
+ export type HostedCredentialSource = "environment" | "stored" | "provisioned";
53
+ /** Where the hosted key came from, for the run to say so; null when the gate is local. */
54
+ export interface HostedCredentials {
55
+ readonly source: HostedCredentialSource;
56
+ readonly tenantId: string;
57
+ readonly endpoint: string;
58
+ /** The file the key is kept in, when it is kept. */
59
+ readonly path: string | null;
60
+ readonly provisional: boolean;
61
+ /** How a person claims a provisioned workspace, as the authority stated it. */
62
+ readonly claim: Readonly<Record<string, unknown>> | null;
63
+ }
64
+ export interface HostedGate extends SelectedGate {
65
+ readonly credentials: HostedCredentials | null;
66
+ /**
67
+ * Fetches a dossier this gate's key minted and summarizes its proof; null
68
+ * when the gate is local. The key stays inside the closure.
69
+ */
70
+ readonly fetchDossier: ((dossierId: string) => Promise<{
71
+ readonly summary: SignedDossierSummary;
72
+ readonly body: unknown;
73
+ }>) | null;
74
+ }
75
+ export interface CreateHostedGateOptions extends CreateGateOptions, ResolveHostedCredentialsOptions {
76
+ }
77
+ /** Whether `DECIONIS_HOSTED` asks for the hosted gate. */
78
+ export declare function hostedRequested(env: Readonly<Record<string, string | undefined>>): boolean;
79
+ export interface ResolveHostedCredentialsOptions {
80
+ readonly env?: Readonly<Record<string, string | undefined>>;
81
+ readonly fetch?: typeof fetch;
82
+ readonly source?: ClientSource;
83
+ /**
84
+ * Where a provisioned key is kept between runs, so a second run reuses the
85
+ * workspace instead of minting another: the user's `agentsafe` credential
86
+ * file by default; `false` keeps nothing.
87
+ */
88
+ readonly store?: {
89
+ readonly home?: string;
90
+ readonly files?: CredentialFiles;
91
+ } | false;
92
+ /** Mints the workspace; the authority's own route by default. */
93
+ readonly provision?: (options: ProvisionOptions) => Promise<ProvisionedWorkspace>;
94
+ /** Where the one-time note about a provisioned workspace goes; standard error by default. */
95
+ readonly notice?: (line: string) => void;
96
+ }
97
+ /** The credentials a hosted run uses, and the environment overlay that carries them. */
98
+ export interface ResolvedHostedCredentials {
99
+ readonly credentials: HostedCredentials;
100
+ /** The key, for the one place that must hold it: the environment of the gate or process. */
101
+ readonly apiKey: string;
102
+ readonly env: Readonly<Record<string, string | undefined>>;
103
+ }
104
+ /**
105
+ * Where a hosted run's key comes from, in order: the environment, the
106
+ * credential this user keeps for this authority, and when there is none and
107
+ * `DECIONIS_HOSTED` asks, a free provisional workspace minted now, kept for
108
+ * the next run and named on standard error once. Null when nothing asks for
109
+ * the hosted path at all.
110
+ */
111
+ export declare function resolveHostedCredentials(options?: ResolveHostedCredentialsOptions): Promise<ResolvedHostedCredentials | null>;
112
+ /**
113
+ * The gate `createGate` selects, with one more way onto Decionis: a single
114
+ * variable. `DECIONIS_HOSTED=1` with no key means the key this user already
115
+ * keeps for this authority, and when there is none, a free provisional
116
+ * workspace minted now, kept for the next run, and named on standard error
117
+ * once. A key in the environment still wins, and no variable at all is
118
+ * still the local pair. A provisional key evaluates in `SHADOW` only:
119
+ * recorded beside the local verdict, with a signed dossier, never governing
120
+ * execution; an owned key set in the environment takes the mode asked for.
121
+ */
122
+ export declare function createHostedGate(options: CreateHostedGateOptions): Promise<HostedGate>;
123
+ //# sourceMappingURL=CreateGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateGate.d.ts","sourceRoot":"","sources":["../../src/decision/CreateGate.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAsB,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,sBAAsB,CAAC;AAExD,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;CAC1C;AAED,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,QAAQ,CAA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