@odingard/guardian-sdk 0.1.0 → 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.
- package/README.md +252 -17
- package/dist/contracts.js +9865 -0
- package/dist/index.js +12976 -1787
- package/dist/public-catalog.v1.json +6915 -0
- package/dist-dts/catalog.d.ts +14 -0
- package/dist-dts/client.d.ts +51 -1
- package/dist-dts/contracts/action-pack.d.ts +464 -0
- package/dist-dts/contracts/action-registry.d.ts +91 -1
- package/dist-dts/contracts/action.d.ts +1408 -17
- package/dist-dts/contracts/agent-state.d.ts +386 -0
- package/dist-dts/contracts/approval.d.ts +224 -5
- package/dist-dts/contracts/assurance.d.ts +60 -0
- package/dist-dts/contracts/authority-graph.d.ts +294 -0
- package/dist-dts/contracts/authority-state.d.ts +17 -2
- package/dist-dts/contracts/authority.d.ts +31 -5
- package/dist-dts/contracts/billing.d.ts +32 -0
- package/dist-dts/contracts/calendar.d.ts +6 -6
- package/dist-dts/contracts/denial.d.ts +648 -0
- package/dist-dts/contracts/evidence.d.ts +73 -16
- package/dist-dts/contracts/execution.d.ts +449 -55
- package/dist-dts/contracts/identifiers.d.ts +16 -0
- package/dist-dts/contracts/index.d.ts +22 -0
- package/dist-dts/contracts/intent.d.ts +335 -0
- package/dist-dts/contracts/lineage.d.ts +218 -0
- package/dist-dts/contracts/local.d.ts +101 -0
- package/dist-dts/contracts/multi-principal.d.ts +292 -0
- package/dist-dts/contracts/multiparty.d.ts +169 -0
- package/dist-dts/contracts/obligation.d.ts +196 -0
- package/dist-dts/contracts/plan.d.ts +67 -0
- package/dist-dts/contracts/policy-simulation.d.ts +681 -0
- package/dist-dts/contracts/prerequisite.d.ts +147 -0
- package/dist-dts/contracts/protected-data.d.ts +67 -0
- package/dist-dts/contracts/receipt.d.ts +3126 -0
- package/dist-dts/contracts/resource-claims.d.ts +146 -0
- package/dist-dts/contracts/runtime.d.ts +111 -0
- package/dist-dts/contracts/safety-envelope.d.ts +287 -0
- package/dist-dts/contracts/sequence.d.ts +132 -0
- package/dist-dts/contracts/sources.d.ts +191 -0
- package/dist-dts/contracts/tools.d.ts +50 -5
- package/dist-dts/contracts/transaction.d.ts +360 -0
- package/dist-dts/contracts-entry.d.ts +1 -0
- package/dist-dts/embedded.d.ts +58 -0
- package/dist-dts/evidence/evidence.d.ts +25 -0
- package/dist-dts/evidence/receipt.d.ts +61 -0
- package/dist-dts/index.d.ts +5 -1
- package/dist-dts/lifecycle.d.ts +25 -0
- package/dist-dts/proposal.d.ts +16 -0
- package/dist-dts/receipts.d.ts +37 -0
- package/package.json +12 -6
- package/dist-dts/__tests__/client.test.d.ts +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-027: guardian.sources.v1 — authority sources and policy-source
|
|
4
|
+
* precedence (GUA-AUTHORITY-OS-001 §31–33).
|
|
5
|
+
*
|
|
6
|
+
* An authority source is a registered pack of constraints contributed by a
|
|
7
|
+
* party whose authority intersects with the principal's: a human, family,
|
|
8
|
+
* resource owner, organization, counterparty, jurisdiction, safety policy,
|
|
9
|
+
* provider, or device policy. Precedence is deterministic intersection —
|
|
10
|
+
* the strongest restriction wins per dimension and the result can only
|
|
11
|
+
* NARROW the principal's authority, never enlarge it (§32). Packs from
|
|
12
|
+
* mandatory kinds (jurisdiction, safety_policy, or any pack flagged
|
|
13
|
+
* mandatory) require trusted provenance and versioning: an unprovenanced,
|
|
14
|
+
* stale, or unsigned pack fails closed and is never applied (§33).
|
|
15
|
+
*/
|
|
16
|
+
export declare const SOURCES_CONTRACT_SCHEMA = "guardian.sources.v1";
|
|
17
|
+
export declare const AuthoritySourceKindSchema: z.ZodEnum<{
|
|
18
|
+
human: "human";
|
|
19
|
+
counterparty: "counterparty";
|
|
20
|
+
family: "family";
|
|
21
|
+
resource_owner: "resource_owner";
|
|
22
|
+
organization: "organization";
|
|
23
|
+
jurisdiction: "jurisdiction";
|
|
24
|
+
safety_policy: "safety_policy";
|
|
25
|
+
provider: "provider";
|
|
26
|
+
device_policy: "device_policy";
|
|
27
|
+
}>;
|
|
28
|
+
export type AuthoritySourceKind = z.infer<typeof AuthoritySourceKindSchema>;
|
|
29
|
+
/** Source kinds whose packs are mandatory-rule packs under §33. */
|
|
30
|
+
export declare const MANDATORY_SOURCE_KINDS: readonly AuthoritySourceKind[];
|
|
31
|
+
export declare const SourceProvenanceSchema: z.ZodObject<{
|
|
32
|
+
issuer: z.ZodString;
|
|
33
|
+
version: z.ZodNumber;
|
|
34
|
+
registeredAtEpochMs: z.ZodNumber;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type SourceProvenance = z.infer<typeof SourceProvenanceSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Declarative constraints one source contributes. Every field narrows in
|
|
39
|
+
* exactly one direction under intersection; absent means unconstrained on
|
|
40
|
+
* that dimension.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SourceConstraintsSchema: z.ZodObject<{
|
|
43
|
+
allowedActions: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ActionType", "out">>>;
|
|
44
|
+
deniedActions: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ActionType", "out">>>;
|
|
45
|
+
allowedResources: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ResourceRef", "out">>>;
|
|
46
|
+
allowedInterfaces: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
47
|
+
mcp: "mcp";
|
|
48
|
+
rest: "rest";
|
|
49
|
+
internal: "internal";
|
|
50
|
+
}>>>;
|
|
51
|
+
maxValueCents: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
maxUses: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
minRuntimeLevel: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
T0_UNKNOWN: "T0_UNKNOWN";
|
|
55
|
+
T1_IDENTIFIED: "T1_IDENTIFIED";
|
|
56
|
+
T2_VERIFIED: "T2_VERIFIED";
|
|
57
|
+
T3_ATTESTED: "T3_ATTESTED";
|
|
58
|
+
T4_HARDWARE_BACKED: "T4_HARDWARE_BACKED";
|
|
59
|
+
}>>;
|
|
60
|
+
minAssuranceLevel: z.ZodOptional<z.ZodEnum<{
|
|
61
|
+
G2_CREDENTIAL_MEDIATED: "G2_CREDENTIAL_MEDIATED";
|
|
62
|
+
G1_POLICY_MEDIATED: "G1_POLICY_MEDIATED";
|
|
63
|
+
G3_RUNTIME_CONTAINED: "G3_RUNTIME_CONTAINED";
|
|
64
|
+
G0_OBSERVED: "G0_OBSERVED";
|
|
65
|
+
G4_COUNTERPARTY_INTERLOCKED: "G4_COUNTERPARTY_INTERLOCKED";
|
|
66
|
+
}>>;
|
|
67
|
+
requiredApprovals: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
export type SourceConstraints = z.infer<typeof SourceConstraintsSchema>;
|
|
70
|
+
export declare const SourceSignatureSchema: z.ZodObject<{
|
|
71
|
+
algorithm: z.ZodLiteral<"ed25519">;
|
|
72
|
+
value: z.ZodString;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
export type SourceSignature = z.infer<typeof SourceSignatureSchema>;
|
|
75
|
+
export declare const AuthoritySourcePackSchema: z.ZodObject<{
|
|
76
|
+
schema: z.ZodLiteral<"guardian.sources.v1">;
|
|
77
|
+
sourceId: z.ZodString;
|
|
78
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
79
|
+
kind: z.ZodEnum<{
|
|
80
|
+
human: "human";
|
|
81
|
+
counterparty: "counterparty";
|
|
82
|
+
family: "family";
|
|
83
|
+
resource_owner: "resource_owner";
|
|
84
|
+
organization: "organization";
|
|
85
|
+
jurisdiction: "jurisdiction";
|
|
86
|
+
safety_policy: "safety_policy";
|
|
87
|
+
provider: "provider";
|
|
88
|
+
device_policy: "device_policy";
|
|
89
|
+
}>;
|
|
90
|
+
mandatory: z.ZodOptional<z.ZodBoolean>;
|
|
91
|
+
provenance: z.ZodObject<{
|
|
92
|
+
issuer: z.ZodString;
|
|
93
|
+
version: z.ZodNumber;
|
|
94
|
+
registeredAtEpochMs: z.ZodNumber;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
constraints: z.ZodObject<{
|
|
97
|
+
allowedActions: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ActionType", "out">>>;
|
|
98
|
+
deniedActions: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ActionType", "out">>>;
|
|
99
|
+
allowedResources: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "ResourceRef", "out">>>;
|
|
100
|
+
allowedInterfaces: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
101
|
+
mcp: "mcp";
|
|
102
|
+
rest: "rest";
|
|
103
|
+
internal: "internal";
|
|
104
|
+
}>>>;
|
|
105
|
+
maxValueCents: z.ZodOptional<z.ZodNumber>;
|
|
106
|
+
maxUses: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
minRuntimeLevel: z.ZodOptional<z.ZodEnum<{
|
|
108
|
+
T0_UNKNOWN: "T0_UNKNOWN";
|
|
109
|
+
T1_IDENTIFIED: "T1_IDENTIFIED";
|
|
110
|
+
T2_VERIFIED: "T2_VERIFIED";
|
|
111
|
+
T3_ATTESTED: "T3_ATTESTED";
|
|
112
|
+
T4_HARDWARE_BACKED: "T4_HARDWARE_BACKED";
|
|
113
|
+
}>>;
|
|
114
|
+
minAssuranceLevel: z.ZodOptional<z.ZodEnum<{
|
|
115
|
+
G2_CREDENTIAL_MEDIATED: "G2_CREDENTIAL_MEDIATED";
|
|
116
|
+
G1_POLICY_MEDIATED: "G1_POLICY_MEDIATED";
|
|
117
|
+
G3_RUNTIME_CONTAINED: "G3_RUNTIME_CONTAINED";
|
|
118
|
+
G0_OBSERVED: "G0_OBSERVED";
|
|
119
|
+
G4_COUNTERPARTY_INTERLOCKED: "G4_COUNTERPARTY_INTERLOCKED";
|
|
120
|
+
}>>;
|
|
121
|
+
requiredApprovals: z.ZodOptional<z.ZodNumber>;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
status: z.ZodEnum<{
|
|
124
|
+
active: "active";
|
|
125
|
+
revoked: "revoked";
|
|
126
|
+
}>;
|
|
127
|
+
version: z.ZodNumber;
|
|
128
|
+
signature: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
algorithm: z.ZodLiteral<"ed25519">;
|
|
130
|
+
value: z.ZodString;
|
|
131
|
+
}, z.core.$strict>>;
|
|
132
|
+
createdAtEpochMs: z.ZodNumber;
|
|
133
|
+
updatedAtEpochMs: z.ZodNumber;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
export type AuthoritySourcePack = z.infer<typeof AuthoritySourcePackSchema>;
|
|
136
|
+
/** Deployment trust policy: which issuers may contribute packs and how they sign. */
|
|
137
|
+
export declare const SourceTrustPolicySchema: z.ZodObject<{
|
|
138
|
+
trustedIssuers: z.ZodArray<z.ZodObject<{
|
|
139
|
+
issuer: z.ZodString;
|
|
140
|
+
publicKeyPem: z.ZodOptional<z.ZodString>;
|
|
141
|
+
minVersion: z.ZodOptional<z.ZodNumber>;
|
|
142
|
+
}, z.core.$strict>>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
export type SourceTrustPolicy = z.infer<typeof SourceTrustPolicySchema>;
|
|
145
|
+
export declare function isMandatorySource(pack: AuthoritySourcePack): boolean;
|
|
146
|
+
/** The canonical digest a pack signature covers (everything except the signature). */
|
|
147
|
+
export declare function sourcePackSigningDigest(pack: Pick<AuthoritySourcePack, "schema" | "sourceId" | "tenantId" | "kind" | "mandatory" | "provenance" | "constraints" | "version">): string;
|
|
148
|
+
export declare function verifySourceSignature(pack: AuthoritySourcePack, publicKeyPem: string): boolean;
|
|
149
|
+
export type ProvenanceCheck = {
|
|
150
|
+
ok: true;
|
|
151
|
+
} | {
|
|
152
|
+
ok: false;
|
|
153
|
+
reason: "UNTRUSTED_ISSUER" | "STALE_VERSION" | "UNSIGNED_SOURCE" | "INVALID_SIGNATURE";
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* §33 — trusted provenance + versioning. A pack is established only when its
|
|
157
|
+
* issuer is trusted, its provenance version meets the issuer floor, and its
|
|
158
|
+
* signature verifies against the issuer's configured key. A mandatory pack
|
|
159
|
+
* with no verifiable signature (or no issuer key at all) fails closed.
|
|
160
|
+
*/
|
|
161
|
+
export declare function verifySourceProvenance(pack: AuthoritySourcePack, trustPolicy: SourceTrustPolicy): ProvenanceCheck;
|
|
162
|
+
/**
|
|
163
|
+
* §32 — deterministic intersection: the strongest restriction wins per
|
|
164
|
+
* dimension. The result can never exceed what any contributing pack allows.
|
|
165
|
+
*/
|
|
166
|
+
export declare function intersectSourceConstraints(packs: readonly Pick<AuthoritySourcePack, "constraints">[]): SourceConstraints;
|
|
167
|
+
export type AppliedAuthoritySources = Readonly<{
|
|
168
|
+
applied: readonly string[];
|
|
169
|
+
rejected: readonly Readonly<{
|
|
170
|
+
sourceId: string;
|
|
171
|
+
reason: string;
|
|
172
|
+
}>[];
|
|
173
|
+
constraints: SourceConstraints;
|
|
174
|
+
}>;
|
|
175
|
+
export type AuthoritySourcesOutcome = {
|
|
176
|
+
ok: true;
|
|
177
|
+
sources: AppliedAuthoritySources;
|
|
178
|
+
} | {
|
|
179
|
+
ok: false;
|
|
180
|
+
reasonCode: string;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Establish and apply declared source packs. Tenant-mismatched, revoked,
|
|
184
|
+
* malformed, or unprovenanced packs are never applied; a mandatory pack that
|
|
185
|
+
* cannot be established fails the whole evaluation closed.
|
|
186
|
+
*/
|
|
187
|
+
export declare function applyAuthoritySources(input: {
|
|
188
|
+
packs: readonly AuthoritySourcePack[];
|
|
189
|
+
trustPolicy: SourceTrustPolicy;
|
|
190
|
+
tenantId: string;
|
|
191
|
+
}): AuthoritySourcesOutcome;
|
|
@@ -23,9 +23,10 @@ export declare const TOOL_DESCRIPTION_MAX_LENGTH = 512;
|
|
|
23
23
|
export declare const ToolNameSchema: z.ZodString;
|
|
24
24
|
export type ToolName = z.infer<typeof ToolNameSchema>;
|
|
25
25
|
/** A catalog entry: a named tool that renders to one allowlisted https call. */
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const ToolHttpDescriptorSchema: z.ZodObject<{
|
|
27
27
|
name: z.ZodString;
|
|
28
28
|
description: z.ZodOptional<z.ZodString>;
|
|
29
|
+
transport: z.ZodOptional<z.ZodLiteral<"http">>;
|
|
29
30
|
method: z.ZodEnum<{
|
|
30
31
|
GET: "GET";
|
|
31
32
|
HEAD: "HEAD";
|
|
@@ -36,14 +37,53 @@ export declare const ToolDescriptorSchema: z.ZodObject<{
|
|
|
36
37
|
}>;
|
|
37
38
|
url: z.ZodString;
|
|
38
39
|
}, z.core.$strict>;
|
|
40
|
+
export type ToolHttpDescriptor = z.infer<typeof ToolHttpDescriptorSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* WO-021 — a `record` catalog entry: the tool's implementation lives
|
|
43
|
+
* in-host inside the tool-server runtime (framework adapters — Vercel AI,
|
|
44
|
+
* LangChain — register the impl host-side). There is no URL: the invocation
|
|
45
|
+
* never leaves the host, so no endpoint-allowlist leg exists. The governed
|
|
46
|
+
* flow is propose → ALLOW → local run → redeem+record → receipt; the impl
|
|
47
|
+
* runs exactly once, at commit, never before the decision and never again
|
|
48
|
+
* on a failed execute.
|
|
49
|
+
*/
|
|
50
|
+
export declare const ToolRecordDescriptorSchema: z.ZodObject<{
|
|
51
|
+
name: z.ZodString;
|
|
52
|
+
description: z.ZodOptional<z.ZodString>;
|
|
53
|
+
transport: z.ZodLiteral<"record">;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
export type ToolRecordDescriptor = z.infer<typeof ToolRecordDescriptorSchema>;
|
|
56
|
+
export declare const ToolDescriptorSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
description: z.ZodOptional<z.ZodString>;
|
|
59
|
+
transport: z.ZodLiteral<"record">;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
name: z.ZodString;
|
|
62
|
+
description: z.ZodOptional<z.ZodString>;
|
|
63
|
+
transport: z.ZodOptional<z.ZodLiteral<"http">>;
|
|
64
|
+
method: z.ZodEnum<{
|
|
65
|
+
GET: "GET";
|
|
66
|
+
HEAD: "HEAD";
|
|
67
|
+
POST: "POST";
|
|
68
|
+
PUT: "PUT";
|
|
69
|
+
PATCH: "PATCH";
|
|
70
|
+
DELETE: "DELETE";
|
|
71
|
+
}>;
|
|
72
|
+
url: z.ZodString;
|
|
73
|
+
}, z.core.$strict>]>;
|
|
39
74
|
export type ToolDescriptor = z.infer<typeof ToolDescriptorSchema>;
|
|
40
75
|
/** The tool-server catalog stored on a provider "tool" connection record. */
|
|
41
76
|
export declare const ToolServerCatalogSchema: z.ZodObject<{
|
|
42
77
|
serverName: z.ZodString;
|
|
43
78
|
serverVersion: z.ZodString;
|
|
44
|
-
tools: z.ZodArray<z.ZodObject<{
|
|
79
|
+
tools: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
80
|
+
name: z.ZodString;
|
|
81
|
+
description: z.ZodOptional<z.ZodString>;
|
|
82
|
+
transport: z.ZodLiteral<"record">;
|
|
83
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
84
|
name: z.ZodString;
|
|
46
85
|
description: z.ZodOptional<z.ZodString>;
|
|
86
|
+
transport: z.ZodOptional<z.ZodLiteral<"http">>;
|
|
47
87
|
method: z.ZodEnum<{
|
|
48
88
|
GET: "GET";
|
|
49
89
|
HEAD: "HEAD";
|
|
@@ -53,7 +93,7 @@ export declare const ToolServerCatalogSchema: z.ZodObject<{
|
|
|
53
93
|
DELETE: "DELETE";
|
|
54
94
|
}>;
|
|
55
95
|
url: z.ZodString;
|
|
56
|
-
}, z.core.$strict>>;
|
|
96
|
+
}, z.core.$strict>]>>;
|
|
57
97
|
}, z.core.$strict>;
|
|
58
98
|
export type ToolServerCatalog = z.infer<typeof ToolServerCatalogSchema>;
|
|
59
99
|
/** Bounded canonical JSON object (cycles, prototypes and depth are rejected). */
|
|
@@ -74,9 +114,14 @@ export type ToolInvokeParametersV1 = z.infer<typeof ToolInvokeParametersV1Schema
|
|
|
74
114
|
export declare const McpInstallParametersV1Schema: z.ZodObject<{
|
|
75
115
|
schema: z.ZodLiteral<"odingard.guardian.mcp.install.v1">;
|
|
76
116
|
connectionId: z.core.$ZodBranded<z.ZodString, "ConnectionId", "out">;
|
|
77
|
-
tool: z.ZodObject<{
|
|
117
|
+
tool: z.ZodUnion<readonly [z.ZodObject<{
|
|
118
|
+
name: z.ZodString;
|
|
119
|
+
description: z.ZodOptional<z.ZodString>;
|
|
120
|
+
transport: z.ZodLiteral<"record">;
|
|
121
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
122
|
name: z.ZodString;
|
|
79
123
|
description: z.ZodOptional<z.ZodString>;
|
|
124
|
+
transport: z.ZodOptional<z.ZodLiteral<"http">>;
|
|
80
125
|
method: z.ZodEnum<{
|
|
81
126
|
GET: "GET";
|
|
82
127
|
HEAD: "HEAD";
|
|
@@ -86,7 +131,7 @@ export declare const McpInstallParametersV1Schema: z.ZodObject<{
|
|
|
86
131
|
DELETE: "DELETE";
|
|
87
132
|
}>;
|
|
88
133
|
url: z.ZodString;
|
|
89
|
-
}, z.core.$strict>;
|
|
134
|
+
}, z.core.$strict>]>;
|
|
90
135
|
}, z.core.$strict>;
|
|
91
136
|
export type McpInstallParametersV1 = z.infer<typeof McpInstallParametersV1Schema>;
|
|
92
137
|
/** mcp.enable enables a catalog tool for the requesting agent. */
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* WO-028: guardian.transaction.v1 — deterministic transaction authority
|
|
4
|
+
* (GUA-AUTHORITY-OS-001 §34–37, §79, §81).
|
|
5
|
+
*
|
|
6
|
+
* A transaction is the recorded lifecycle of one consequential action:
|
|
7
|
+
* PROPOSE → PREPARE → AUTHORIZE → LOCK → COMMIT → VERIFY → SETTLE, entered
|
|
8
|
+
* only when the action or its governing intent declares it. Every stage is
|
|
9
|
+
* a recorded transition bound to the canonical action digest; a skipped or
|
|
10
|
+
* out-of-order stage fails closed.
|
|
11
|
+
*
|
|
12
|
+
* The evaluator in this file is pure and deterministic. It never enlarges
|
|
13
|
+
* authority: it records what the authority path already decided, and a
|
|
14
|
+
* compensating action is a NEW governed action through the same
|
|
15
|
+
* ALLOW/ASK/DENY path — compensation never bypasses ASK. A transaction
|
|
16
|
+
* whose provider outcome is unconfirmed records UNKNOWN or MISMATCH; an
|
|
17
|
+
* unconfirmed effect is never reported SETTLED.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TRANSACTION_CONTRACT_SCHEMA = "guardian.transaction.v1";
|
|
20
|
+
export declare const TransactionStageSchema: z.ZodEnum<{
|
|
21
|
+
PROPOSE: "PROPOSE";
|
|
22
|
+
PREPARE: "PREPARE";
|
|
23
|
+
AUTHORIZE: "AUTHORIZE";
|
|
24
|
+
LOCK: "LOCK";
|
|
25
|
+
COMMIT: "COMMIT";
|
|
26
|
+
VERIFY: "VERIFY";
|
|
27
|
+
SETTLE: "SETTLE";
|
|
28
|
+
}>;
|
|
29
|
+
export type TransactionStage = z.infer<typeof TransactionStageSchema>;
|
|
30
|
+
/** The one canonical stage order (§34). */
|
|
31
|
+
export declare const CANONICAL_TRANSACTION_STAGES: readonly TransactionStage[];
|
|
32
|
+
export declare const TransactionStateSchema: z.ZodEnum<{
|
|
33
|
+
AUTHORIZED: "AUTHORIZED";
|
|
34
|
+
PROPOSED: "PROPOSED";
|
|
35
|
+
PREPARED: "PREPARED";
|
|
36
|
+
LOCKED: "LOCKED";
|
|
37
|
+
COMMITTING: "COMMITTING";
|
|
38
|
+
COMMITTED: "COMMITTED";
|
|
39
|
+
VERIFIED: "VERIFIED";
|
|
40
|
+
SETTLED: "SETTLED";
|
|
41
|
+
DENIED: "DENIED";
|
|
42
|
+
EXPIRED: "EXPIRED";
|
|
43
|
+
REVOKED: "REVOKED";
|
|
44
|
+
UNKNOWN: "UNKNOWN";
|
|
45
|
+
MISMATCH: "MISMATCH";
|
|
46
|
+
FAILED: "FAILED";
|
|
47
|
+
CANCELLED: "CANCELLED";
|
|
48
|
+
COMPENSATING: "COMPENSATING";
|
|
49
|
+
COMPENSATED: "COMPENSATED";
|
|
50
|
+
}>;
|
|
51
|
+
export type TransactionState = z.infer<typeof TransactionStateSchema>;
|
|
52
|
+
/** States from which the transaction can never move again. */
|
|
53
|
+
export declare const TERMINAL_TRANSACTION_STATES: readonly TransactionState[];
|
|
54
|
+
export declare function isTerminalTransactionState(state: TransactionState): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The declared lifecycle of a transaction: a strictly-increasing
|
|
57
|
+
* subsequence of the canonical stage order that must contain PROPOSE.
|
|
58
|
+
* Declared on the action definition and/or the governing intent; the
|
|
59
|
+
* effective declaration is the union in canonical order — declaration
|
|
60
|
+
* only ever adds recorded obligations, it cannot remove a stage the
|
|
61
|
+
* other declaration required.
|
|
62
|
+
*/
|
|
63
|
+
export declare const TransactionDeclarationSchema: z.ZodObject<{
|
|
64
|
+
schema: z.ZodLiteral<"guardian.transaction.v1">;
|
|
65
|
+
stages: z.ZodArray<z.ZodEnum<{
|
|
66
|
+
PROPOSE: "PROPOSE";
|
|
67
|
+
PREPARE: "PREPARE";
|
|
68
|
+
AUTHORIZE: "AUTHORIZE";
|
|
69
|
+
LOCK: "LOCK";
|
|
70
|
+
COMMIT: "COMMIT";
|
|
71
|
+
VERIFY: "VERIFY";
|
|
72
|
+
SETTLE: "SETTLE";
|
|
73
|
+
}>>;
|
|
74
|
+
deadlineMs: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
export type TransactionDeclaration = z.infer<typeof TransactionDeclarationSchema>;
|
|
77
|
+
export declare function transactionDeclarationDigest(declaration: TransactionDeclaration): string;
|
|
78
|
+
/**
|
|
79
|
+
* Union of two declared lifecycles in canonical order (declaration only
|
|
80
|
+
* ever enlarges the recorded obligation set, never shrinks it). The
|
|
81
|
+
* tighter deadline wins. Returns undefined when neither declares.
|
|
82
|
+
*/
|
|
83
|
+
export declare function effectiveTransactionDeclaration(declaredA: TransactionDeclaration | undefined, declaredB: TransactionDeclaration | undefined): TransactionDeclaration | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Every consequential adapter declares its idempotency posture. The
|
|
86
|
+
* declaration is data on the adapter record — it is required, never
|
|
87
|
+
* inferred. A retry always binds to the recorded execution attempt's
|
|
88
|
+
* idempotency key (the effect key); a retry can never carry a fresh key
|
|
89
|
+
* that would silently produce a second effect.
|
|
90
|
+
*/
|
|
91
|
+
export declare const AdapterIdempotencyDeclarationSchema: z.ZodObject<{
|
|
92
|
+
support: z.ZodEnum<{
|
|
93
|
+
none: "none";
|
|
94
|
+
keyed: "keyed";
|
|
95
|
+
"provider-native": "provider-native";
|
|
96
|
+
}>;
|
|
97
|
+
duplicateEffect: z.ZodEnum<{
|
|
98
|
+
"return-existing": "return-existing";
|
|
99
|
+
reject: "reject";
|
|
100
|
+
unsafe: "unsafe";
|
|
101
|
+
}>;
|
|
102
|
+
retry: z.ZodEnum<{
|
|
103
|
+
"same-attempt-key": "same-attempt-key";
|
|
104
|
+
"fresh-authority": "fresh-authority";
|
|
105
|
+
}>;
|
|
106
|
+
reconciliation: z.ZodEnum<{
|
|
107
|
+
none: "none";
|
|
108
|
+
readback: "readback";
|
|
109
|
+
callback: "callback";
|
|
110
|
+
manual: "manual";
|
|
111
|
+
}>;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
export type AdapterIdempotencyDeclaration = z.infer<typeof AdapterIdempotencyDeclarationSchema>;
|
|
114
|
+
/**
|
|
115
|
+
* Bound into the canonical action of a compensating action: which
|
|
116
|
+
* recorded transaction this action compensates. The action still goes
|
|
117
|
+
* through the full authority path — this binding only declares the
|
|
118
|
+
* relationship.
|
|
119
|
+
*/
|
|
120
|
+
export declare const TransactionCompensationBindingSchema: z.ZodObject<{
|
|
121
|
+
transactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
export type TransactionCompensationBinding = z.infer<typeof TransactionCompensationBindingSchema>;
|
|
124
|
+
export declare const TransactionStageRecordSchema: z.ZodObject<{
|
|
125
|
+
stage: z.ZodEnum<{
|
|
126
|
+
PROPOSE: "PROPOSE";
|
|
127
|
+
PREPARE: "PREPARE";
|
|
128
|
+
AUTHORIZE: "AUTHORIZE";
|
|
129
|
+
LOCK: "LOCK";
|
|
130
|
+
COMMIT: "COMMIT";
|
|
131
|
+
VERIFY: "VERIFY";
|
|
132
|
+
SETTLE: "SETTLE";
|
|
133
|
+
}>;
|
|
134
|
+
atEpochMs: z.ZodNumber;
|
|
135
|
+
binding: z.ZodNullable<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>;
|
|
137
|
+
export type TransactionStageRecord = z.infer<typeof TransactionStageRecordSchema>;
|
|
138
|
+
/** How a revocation mid-transaction resolves (§81). */
|
|
139
|
+
export declare const TransactionResolutionSchema: z.ZodEnum<{
|
|
140
|
+
cancel: "cancel";
|
|
141
|
+
settle: "settle";
|
|
142
|
+
hold: "hold";
|
|
143
|
+
}>;
|
|
144
|
+
export type TransactionResolution = z.infer<typeof TransactionResolutionSchema>;
|
|
145
|
+
export declare const TransactionRecordSchema: z.ZodObject<{
|
|
146
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
147
|
+
schema: z.ZodLiteral<"guardian.transaction.v1">;
|
|
148
|
+
transactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
|
|
149
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
150
|
+
principalId: z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">;
|
|
151
|
+
agentId: z.core.$ZodBranded<z.ZodString, "AgentId", "out">;
|
|
152
|
+
requestId: z.core.$ZodBranded<z.ZodString, "RequestId", "out">;
|
|
153
|
+
correlationId: z.core.$ZodBranded<z.ZodString, "CorrelationId", "out">;
|
|
154
|
+
action: z.core.$ZodBranded<z.ZodString, "ActionType", "out">;
|
|
155
|
+
actionDigest: z.ZodString;
|
|
156
|
+
declaration: z.ZodObject<{
|
|
157
|
+
schema: z.ZodLiteral<"guardian.transaction.v1">;
|
|
158
|
+
stages: z.ZodArray<z.ZodEnum<{
|
|
159
|
+
PROPOSE: "PROPOSE";
|
|
160
|
+
PREPARE: "PREPARE";
|
|
161
|
+
AUTHORIZE: "AUTHORIZE";
|
|
162
|
+
LOCK: "LOCK";
|
|
163
|
+
COMMIT: "COMMIT";
|
|
164
|
+
VERIFY: "VERIFY";
|
|
165
|
+
SETTLE: "SETTLE";
|
|
166
|
+
}>>;
|
|
167
|
+
deadlineMs: z.ZodOptional<z.ZodNumber>;
|
|
168
|
+
}, z.core.$strict>;
|
|
169
|
+
declarationDigest: z.ZodString;
|
|
170
|
+
recordedStages: z.ZodArray<z.ZodObject<{
|
|
171
|
+
stage: z.ZodEnum<{
|
|
172
|
+
PROPOSE: "PROPOSE";
|
|
173
|
+
PREPARE: "PREPARE";
|
|
174
|
+
AUTHORIZE: "AUTHORIZE";
|
|
175
|
+
LOCK: "LOCK";
|
|
176
|
+
COMMIT: "COMMIT";
|
|
177
|
+
VERIFY: "VERIFY";
|
|
178
|
+
SETTLE: "SETTLE";
|
|
179
|
+
}>;
|
|
180
|
+
atEpochMs: z.ZodNumber;
|
|
181
|
+
binding: z.ZodNullable<z.ZodString>;
|
|
182
|
+
}, z.core.$strict>>;
|
|
183
|
+
state: z.ZodEnum<{
|
|
184
|
+
AUTHORIZED: "AUTHORIZED";
|
|
185
|
+
PROPOSED: "PROPOSED";
|
|
186
|
+
PREPARED: "PREPARED";
|
|
187
|
+
LOCKED: "LOCKED";
|
|
188
|
+
COMMITTING: "COMMITTING";
|
|
189
|
+
COMMITTED: "COMMITTED";
|
|
190
|
+
VERIFIED: "VERIFIED";
|
|
191
|
+
SETTLED: "SETTLED";
|
|
192
|
+
DENIED: "DENIED";
|
|
193
|
+
EXPIRED: "EXPIRED";
|
|
194
|
+
REVOKED: "REVOKED";
|
|
195
|
+
UNKNOWN: "UNKNOWN";
|
|
196
|
+
MISMATCH: "MISMATCH";
|
|
197
|
+
FAILED: "FAILED";
|
|
198
|
+
CANCELLED: "CANCELLED";
|
|
199
|
+
COMPENSATING: "COMPENSATING";
|
|
200
|
+
COMPENSATED: "COMPENSATED";
|
|
201
|
+
}>;
|
|
202
|
+
resolution: z.ZodNullable<z.ZodEnum<{
|
|
203
|
+
cancel: "cancel";
|
|
204
|
+
settle: "settle";
|
|
205
|
+
hold: "hold";
|
|
206
|
+
}>>;
|
|
207
|
+
attemptId: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "AttemptId", "out">>;
|
|
208
|
+
capabilityId: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">>;
|
|
209
|
+
idempotencyKey: z.ZodNullable<z.ZodString>;
|
|
210
|
+
compensationOf: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
|
|
211
|
+
compensationBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
|
|
212
|
+
terminalReason: z.ZodNullable<z.ZodString>;
|
|
213
|
+
expiresAtEpochMs: z.ZodNullable<z.ZodNumber>;
|
|
214
|
+
version: z.ZodNumber;
|
|
215
|
+
createdAtEpochMs: z.ZodNumber;
|
|
216
|
+
updatedAtEpochMs: z.ZodNumber;
|
|
217
|
+
}, z.core.$strict>;
|
|
218
|
+
export type TransactionRecord = z.infer<typeof TransactionRecordSchema>;
|
|
219
|
+
/** Deterministic transaction id: one transaction per request. */
|
|
220
|
+
export declare function transactionIdForRequest(requestId: string): string;
|
|
221
|
+
/**
|
|
222
|
+
* §36 — whether a transaction's effect may be compensated: a landed (or
|
|
223
|
+
* possibly-landed) effect only; pre-commit states cancel instead.
|
|
224
|
+
*/
|
|
225
|
+
export declare function isCompensatableTransaction(record: TransactionRecord): boolean;
|
|
226
|
+
export declare const TransactionCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
227
|
+
expectedVersion: z.ZodNumber;
|
|
228
|
+
kind: z.ZodLiteral<"record-stage">;
|
|
229
|
+
stage: z.ZodEnum<{
|
|
230
|
+
PROPOSE: "PROPOSE";
|
|
231
|
+
PREPARE: "PREPARE";
|
|
232
|
+
AUTHORIZE: "AUTHORIZE";
|
|
233
|
+
LOCK: "LOCK";
|
|
234
|
+
COMMIT: "COMMIT";
|
|
235
|
+
VERIFY: "VERIFY";
|
|
236
|
+
SETTLE: "SETTLE";
|
|
237
|
+
}>;
|
|
238
|
+
binding: z.ZodNullable<z.ZodString>;
|
|
239
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
240
|
+
expectedVersion: z.ZodNumber;
|
|
241
|
+
kind: z.ZodLiteral<"deny">;
|
|
242
|
+
reason: z.ZodString;
|
|
243
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
244
|
+
expectedVersion: z.ZodNumber;
|
|
245
|
+
kind: z.ZodLiteral<"cancel">;
|
|
246
|
+
reason: z.ZodString;
|
|
247
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
248
|
+
expectedVersion: z.ZodNumber;
|
|
249
|
+
kind: z.ZodLiteral<"expire">;
|
|
250
|
+
reason: z.ZodString;
|
|
251
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
252
|
+
expectedVersion: z.ZodNumber;
|
|
253
|
+
kind: z.ZodLiteral<"revoke">;
|
|
254
|
+
reason: z.ZodString;
|
|
255
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
256
|
+
expectedVersion: z.ZodNumber;
|
|
257
|
+
kind: z.ZodLiteral<"fail">;
|
|
258
|
+
reason: z.ZodString;
|
|
259
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
260
|
+
expectedVersion: z.ZodNumber;
|
|
261
|
+
kind: z.ZodLiteral<"bind-attempt">;
|
|
262
|
+
attemptId: z.core.$ZodBranded<z.ZodString, "AttemptId", "out">;
|
|
263
|
+
capabilityId: z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">;
|
|
264
|
+
idempotencyKey: z.ZodString;
|
|
265
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
266
|
+
expectedVersion: z.ZodNumber;
|
|
267
|
+
kind: z.ZodLiteral<"commit-confirmed">;
|
|
268
|
+
binding: z.ZodNullable<z.ZodString>;
|
|
269
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
270
|
+
expectedVersion: z.ZodNumber;
|
|
271
|
+
kind: z.ZodLiteral<"outcome">;
|
|
272
|
+
outcome: z.ZodEnum<{
|
|
273
|
+
unknown: "unknown";
|
|
274
|
+
verified: "verified";
|
|
275
|
+
mismatch: "mismatch";
|
|
276
|
+
"commit-rejected": "commit-rejected";
|
|
277
|
+
aborted: "aborted";
|
|
278
|
+
}>;
|
|
279
|
+
binding: z.ZodNullable<z.ZodString>;
|
|
280
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
281
|
+
expectedVersion: z.ZodNumber;
|
|
282
|
+
kind: z.ZodLiteral<"compensate">;
|
|
283
|
+
compensationTransactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
|
|
284
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
285
|
+
expectedVersion: z.ZodNumber;
|
|
286
|
+
kind: z.ZodLiteral<"compensated">;
|
|
287
|
+
}, z.core.$strict>], "kind">;
|
|
288
|
+
export type TransactionCommand = z.infer<typeof TransactionCommandSchema>;
|
|
289
|
+
/** A transaction command without its optimistic-concurrency version. */
|
|
290
|
+
export type TransactionCommandInput = {
|
|
291
|
+
[K in TransactionCommand["kind"]]: Omit<Extract<TransactionCommand, {
|
|
292
|
+
kind: K;
|
|
293
|
+
}>, "expectedVersion">;
|
|
294
|
+
}[TransactionCommand["kind"]];
|
|
295
|
+
export type TransactionTransitionResult = Readonly<{
|
|
296
|
+
ok: true;
|
|
297
|
+
record: TransactionRecord;
|
|
298
|
+
}> | Readonly<{
|
|
299
|
+
ok: false;
|
|
300
|
+
reasonCode: "MALFORMED_RECORD" | "MALFORMED_COMMAND" | "STALE_VERSION" | "TRANSACTION_EXPIRED" | "SKIPPED_STAGE" | "INVALID_TRANSITION";
|
|
301
|
+
}>;
|
|
302
|
+
/** The next declared stage not yet recorded, or null. */
|
|
303
|
+
export declare function nextDeclaredTransactionStage(record: TransactionRecord): TransactionStage | null;
|
|
304
|
+
/** §81: how a revocation resolves from a given pre-revocation state. */
|
|
305
|
+
export declare function revocationResolutionForState(state: TransactionState): TransactionResolution;
|
|
306
|
+
export declare function transitionTransaction(recordInput: unknown, commandInput: unknown, nowEpochMs: number): TransactionTransitionResult;
|
|
307
|
+
/**
|
|
308
|
+
* Create a transaction record in PROPOSED with PROPOSE already recorded
|
|
309
|
+
* and bound to the canonical action digest.
|
|
310
|
+
*/
|
|
311
|
+
export declare function proposeTransaction(input: {
|
|
312
|
+
tenantId: string;
|
|
313
|
+
principalId: string;
|
|
314
|
+
agentId: string;
|
|
315
|
+
requestId: string;
|
|
316
|
+
correlationId: string;
|
|
317
|
+
action: string;
|
|
318
|
+
actionDigest: string;
|
|
319
|
+
declaration: TransactionDeclaration;
|
|
320
|
+
compensationOf?: string;
|
|
321
|
+
atEpochMs: number;
|
|
322
|
+
}): TransactionRecord;
|
|
323
|
+
/**
|
|
324
|
+
* The injected port the gateway and execution paths record through.
|
|
325
|
+
* Implementations persist TransactionRecord rows plus a stage-transition
|
|
326
|
+
* audit; the pure evaluator above is the only writer of state. Every
|
|
327
|
+
* method returns null on failure — callers fail closed.
|
|
328
|
+
*/
|
|
329
|
+
export interface TransactionTracker {
|
|
330
|
+
/**
|
|
331
|
+
* Idempotent create keyed on the request-derived transaction id:
|
|
332
|
+
* returns the record (creating it PROPOSED when absent), the existing
|
|
333
|
+
* record when the same action digest is replayed, and null when a
|
|
334
|
+
* record for the id exists with a different digest or the store
|
|
335
|
+
* fails.
|
|
336
|
+
*/
|
|
337
|
+
propose(input: {
|
|
338
|
+
tenantId: string;
|
|
339
|
+
principalId: string;
|
|
340
|
+
agentId: string;
|
|
341
|
+
requestId: string;
|
|
342
|
+
correlationId: string;
|
|
343
|
+
action: string;
|
|
344
|
+
actionDigest: string;
|
|
345
|
+
declaration: TransactionDeclaration;
|
|
346
|
+
compensationOf?: string;
|
|
347
|
+
atEpochMs: number;
|
|
348
|
+
}): Promise<TransactionRecord | null>;
|
|
349
|
+
/** Apply one command through the evaluator with CAS semantics. */
|
|
350
|
+
transition(input: {
|
|
351
|
+
tenantId: string;
|
|
352
|
+
transactionId: string;
|
|
353
|
+
command: TransactionCommand;
|
|
354
|
+
atEpochMs: number;
|
|
355
|
+
}): Promise<TransactionRecord | null>;
|
|
356
|
+
get(input: {
|
|
357
|
+
tenantId: string;
|
|
358
|
+
transactionId: string;
|
|
359
|
+
}): Promise<TransactionRecord | null>;
|
|
360
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./contracts/index.js";
|