@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.
Files changed (50) hide show
  1. package/README.md +252 -17
  2. package/dist/contracts.js +9865 -0
  3. package/dist/index.js +12976 -1787
  4. package/dist/public-catalog.v1.json +6915 -0
  5. package/dist-dts/catalog.d.ts +14 -0
  6. package/dist-dts/client.d.ts +51 -1
  7. package/dist-dts/contracts/action-pack.d.ts +464 -0
  8. package/dist-dts/contracts/action-registry.d.ts +91 -1
  9. package/dist-dts/contracts/action.d.ts +1408 -17
  10. package/dist-dts/contracts/agent-state.d.ts +386 -0
  11. package/dist-dts/contracts/approval.d.ts +224 -5
  12. package/dist-dts/contracts/assurance.d.ts +60 -0
  13. package/dist-dts/contracts/authority-graph.d.ts +294 -0
  14. package/dist-dts/contracts/authority-state.d.ts +17 -2
  15. package/dist-dts/contracts/authority.d.ts +31 -5
  16. package/dist-dts/contracts/billing.d.ts +32 -0
  17. package/dist-dts/contracts/calendar.d.ts +6 -6
  18. package/dist-dts/contracts/denial.d.ts +648 -0
  19. package/dist-dts/contracts/evidence.d.ts +73 -16
  20. package/dist-dts/contracts/execution.d.ts +449 -55
  21. package/dist-dts/contracts/identifiers.d.ts +16 -0
  22. package/dist-dts/contracts/index.d.ts +22 -0
  23. package/dist-dts/contracts/intent.d.ts +335 -0
  24. package/dist-dts/contracts/lineage.d.ts +218 -0
  25. package/dist-dts/contracts/local.d.ts +101 -0
  26. package/dist-dts/contracts/multi-principal.d.ts +292 -0
  27. package/dist-dts/contracts/multiparty.d.ts +169 -0
  28. package/dist-dts/contracts/obligation.d.ts +196 -0
  29. package/dist-dts/contracts/plan.d.ts +67 -0
  30. package/dist-dts/contracts/policy-simulation.d.ts +681 -0
  31. package/dist-dts/contracts/prerequisite.d.ts +147 -0
  32. package/dist-dts/contracts/protected-data.d.ts +67 -0
  33. package/dist-dts/contracts/receipt.d.ts +3126 -0
  34. package/dist-dts/contracts/resource-claims.d.ts +146 -0
  35. package/dist-dts/contracts/runtime.d.ts +111 -0
  36. package/dist-dts/contracts/safety-envelope.d.ts +287 -0
  37. package/dist-dts/contracts/sequence.d.ts +132 -0
  38. package/dist-dts/contracts/sources.d.ts +191 -0
  39. package/dist-dts/contracts/tools.d.ts +50 -5
  40. package/dist-dts/contracts/transaction.d.ts +360 -0
  41. package/dist-dts/contracts-entry.d.ts +1 -0
  42. package/dist-dts/embedded.d.ts +58 -0
  43. package/dist-dts/evidence/evidence.d.ts +25 -0
  44. package/dist-dts/evidence/receipt.d.ts +61 -0
  45. package/dist-dts/index.d.ts +5 -1
  46. package/dist-dts/lifecycle.d.ts +25 -0
  47. package/dist-dts/proposal.d.ts +16 -0
  48. package/dist-dts/receipts.d.ts +37 -0
  49. package/package.json +12 -6
  50. package/dist-dts/__tests__/client.test.d.ts +0 -1
@@ -0,0 +1,58 @@
1
+ /**
2
+ * WO-019 — embedded approval primitives for partner apps (extends the WO-015
3
+ * SDK). A partner embeds Guardian authority by driving the human's approval
4
+ * surface through this client; the calls hit `/v1/embedded/approvals`, which
5
+ * runs the identical approval-service methods as the first-party route, so
6
+ * the decision semantics, receipts and evidence are identical.
7
+ *
8
+ * The partner supplies the human's own Guardian session token — the partner
9
+ * never handles agent credentials and cannot widen what the human may see or
10
+ * decide.
11
+ */
12
+ export type EmbeddedApprovalConfig = Readonly<{
13
+ /** e.g. https://guardian-api-staging.odingard.com */
14
+ baseUrl: string;
15
+ /** The human's Guardian session token presented through the partner app. */
16
+ sessionToken: string;
17
+ fetch?: typeof fetch;
18
+ }>;
19
+ export type EmbeddedApprovalSummary = Readonly<{
20
+ approvalId: string;
21
+ state: string;
22
+ version: number;
23
+ headline: string;
24
+ expiresAtEpochMs: number;
25
+ }>;
26
+ export type EmbeddedApprovalView = Readonly<{
27
+ display: unknown;
28
+ challenge: unknown | null;
29
+ }>;
30
+ export type EmbeddedDecisionResult = Readonly<{
31
+ receipt: unknown;
32
+ changed: boolean;
33
+ }>;
34
+ export type EmbeddedResult<T> = {
35
+ ok: true;
36
+ value: T;
37
+ } | {
38
+ ok: false;
39
+ reasonCode: string;
40
+ };
41
+ export declare function isHumanSessionToken(token: unknown): token is string;
42
+ export declare function createEmbeddedApprovalClient(config: EmbeddedApprovalConfig): {
43
+ listApprovals(): Promise<EmbeddedResult<{
44
+ approvals: readonly EmbeddedApprovalSummary[];
45
+ }>>;
46
+ viewApproval(approvalId: string): Promise<EmbeddedResult<EmbeddedApprovalView>>;
47
+ decideApproval(approvalId: string, input: {
48
+ expectedVersion: number;
49
+ decision: "approve" | "deny";
50
+ presentationDigest: string;
51
+ /** WO-019 step-up factor: tap (default), passkey, biometric, second-device. */
52
+ factor?: "tap" | "passkey" | "biometric" | "second-device";
53
+ }): Promise<EmbeddedResult<EmbeddedDecisionResult>>;
54
+ revokeApproval(approvalId: string, input: {
55
+ expectedVersion: number;
56
+ }): Promise<EmbeddedResult<EmbeddedDecisionResult>>;
57
+ };
58
+ export type EmbeddedApprovalClient = ReturnType<typeof createEmbeddedApprovalClient>;
@@ -0,0 +1,25 @@
1
+ import { type EvidenceEvent, type EvidenceChainContext, type EvidenceRecord, type EvidenceRecordCore } from "../contracts/index.js";
2
+ export type AppendEvidenceFailure = "MALFORMED_CHAIN" | "MALFORMED_DRAFT" | "CHAIN_INVALID" | "DUPLICATE_EVIDENCE_ID" | "APPEND_CONTEXT_MISMATCH" | "NON_MONOTONIC_EVENT_TIME" | "CHAIN_LIMIT_EXCEEDED";
3
+ export type AppendEvidenceResult = {
4
+ ok: true;
5
+ record: EvidenceRecord;
6
+ chain: EvidenceRecord[];
7
+ } | {
8
+ ok: false;
9
+ reasonCode: AppendEvidenceFailure;
10
+ };
11
+ export type EvidenceVerificationFailure = "MALFORMED_CHAIN" | "INVALID_GENESIS" | "DUPLICATE_EVIDENCE_ID" | "DUPLICATE_SEQUENCE" | "SEQUENCE_GAP" | "RECORD_REORDERED" | "CONTEXT_MISMATCH" | "ACTION_DIGEST_MISMATCH" | "INVALID_EVENT_ORDER" | "PAYLOAD_DIGEST_MISMATCH" | "BROKEN_LINK" | "NON_MONOTONIC_EVENT_TIME" | "RECORD_HASH_MISMATCH";
12
+ export type EvidenceVerificationResult = {
13
+ valid: true;
14
+ count: number;
15
+ lastRecordHash: string | null;
16
+ context: EvidenceChainContext | null;
17
+ } | {
18
+ valid: false;
19
+ reasonCode: EvidenceVerificationFailure;
20
+ recordIndex: number | null;
21
+ };
22
+ export declare function hashEvidencePayload(event: EvidenceEvent): string;
23
+ export declare function hashEvidenceRecordCore(core: EvidenceRecordCore): string;
24
+ export declare function verifyEvidenceChain(chainInput: unknown, expectedContextInput?: unknown): EvidenceVerificationResult;
25
+ export declare function appendEvidenceRecord(chainInput: unknown, draftInput: unknown): AppendEvidenceResult;
@@ -0,0 +1,61 @@
1
+ import { type ApprovalRecord, type CanonicalAction, type CapabilityClaims, type EvidenceRecord, type ExecutionRecord, type PortableAuthorityReceipt, type PortableReceiptBody, type ReceiptVerificationJwk } from "../contracts/index.js";
2
+ export type ReceiptSigner = Readonly<{
3
+ keyId: string;
4
+ verificationJwk: ReceiptVerificationJwk;
5
+ sign(body: PortableReceiptBody): PortableAuthorityReceipt;
6
+ }>;
7
+ /** Deterministic receipt key id: rkey_<first-16-hex of sha256(x)>. */
8
+ export declare function receiptKeyIdFromX(x: string): string;
9
+ /**
10
+ * Builds a receipt signer from an Ed25519 signing JWK (`{x, d}` as stored in
11
+ * the `receipt-signing-jwk` secret). Throws on malformed key material.
12
+ */
13
+ export declare function createReceiptSignerFromJwk(input: unknown): ReceiptSigner;
14
+ /** Generates an ephemeral signer — development and tests only. */
15
+ export declare function createEphemeralReceiptSigner(): ReceiptSigner;
16
+ export type BuildPortableReceiptInput = Readonly<{
17
+ receiptId: string;
18
+ issuedAtEpochMs: number;
19
+ /** The complete evidence chain for the request, in sequence order. */
20
+ chain: readonly EvidenceRecord[];
21
+ /**
22
+ * The canonical action the kernel evaluated (from the private
23
+ * materialized-action store). The chain binds it via its material digest.
24
+ */
25
+ action?: CanonicalAction | null;
26
+ /** Latest stored approval record, when the request required one. */
27
+ approval?: ApprovalRecord | null;
28
+ /** The issued capability's claims (never the token). */
29
+ capabilityClaims?: CapabilityClaims | null;
30
+ capabilityState?: "issued" | "used" | "expired" | "revoked" | null;
31
+ /** Latest execution ledger record, when execution was attempted. */
32
+ execution?: ExecutionRecord | null;
33
+ }>;
34
+ export type BuildPortableReceiptResult = {
35
+ ok: true;
36
+ body: PortableReceiptBody;
37
+ } | {
38
+ ok: false;
39
+ reasonCode: "CHAIN_INVALID" | "ACTION_UNAVAILABLE" | "DECISION_MISSING" | "APPROVAL_INCONSISTENT" | "CAPABILITY_INCONSISTENT" | "EXECUTION_INCONSISTENT";
40
+ };
41
+ export declare function buildPortableReceipt(input: BuildPortableReceiptInput): BuildPortableReceiptResult;
42
+ /** Recomputes the capability claims digest (same domain as the broker). */
43
+ export declare function capabilityClaimsDigest(claims: CapabilityClaims): string;
44
+ export type PortableReceiptVerificationFailure = "MALFORMED_RECEIPT" | "UNKNOWN_KEY" | "SIGNATURE_INVALID" | "EVIDENCE_CHAIN_INVALID" | "SUBJECT_MISMATCH" | "ACTION_MISMATCH" | "DECISION_MISMATCH" | "APPROVAL_MISMATCH" | "CAPABILITY_MISMATCH" | "EXECUTION_MISMATCH" | "EFFECT_MISMATCH" | "EVIDENCE_HEAD_MISMATCH";
45
+ export type PortableReceiptVerificationResult = {
46
+ valid: true;
47
+ subject: PortableReceiptBody["subject"];
48
+ decision: PortableReceiptBody["decision"]["decision"];
49
+ effect: PortableReceiptBody["effect"]["kind"];
50
+ } | {
51
+ valid: false;
52
+ reasonCode: PortableReceiptVerificationFailure;
53
+ };
54
+ /**
55
+ * Self-contained portable receipt verification. The caller supplies only the
56
+ * receipt and the published verification key set — no Guardian credential,
57
+ * database, or service is required. Every embedded object is re-digested and
58
+ * cross-checked against the embedded evidence chain, and the Ed25519 proof is
59
+ * verified over the canonical receipt body.
60
+ */
61
+ export declare function verifyPortableAuthorityReceipt(receiptInput: unknown, keysInput: unknown): PortableReceiptVerificationResult;
@@ -1 +1,5 @@
1
- export { createGuardianClient, type GuardianClient, type GuardianClientConfig, type GuardianRequestResult, type GuardianToolInvocation, type GuardianMcpInvocation, } from "./client.js";
1
+ export { createGuardianClient, type GuardianClient, type GuardianClientConfig, type GuardianGovernedInvocation, type GuardianInvocation, type GuardianRequestResult, type GuardianToolInvocation, type GuardianMcpInvocation, } from "./client.js";
2
+ export { createEmbeddedApprovalClient, isHumanSessionToken, type EmbeddedApprovalClient, type EmbeddedApprovalConfig, type EmbeddedApprovalSummary, type EmbeddedApprovalView, type EmbeddedDecisionResult, type EmbeddedResult, } from "./embedded.js";
3
+ export { classifyRequestResult, type GuardianDecision } from "./lifecycle.js";
4
+ export { fetchReceiptVerificationKeys, verifyReceiptOffline, verifyReceiptOnline, type ReceiptKeySetResult, type ReceiptVerification, } from "./receipts.js";
5
+ export { findAgentSystem, guardianCatalog, verticalsForAction, type GuardianCatalogAgentSystem, type GuardianCatalogVertical, type GuardianPublicCatalog, } from "./catalog.js";
@@ -0,0 +1,25 @@
1
+ import type { GuardianRequestResult } from "./client.js";
2
+ /**
3
+ * WO-042 — the single, fail-closed reading of a Guardian request result.
4
+ *
5
+ * ALLOW — a capability token was issued; `execute` redeems it.
6
+ * ASK — held for a human; keep `requestId`, then `claim(requestId)`
7
+ * after the human decides. The gateway reports a held ASK as
8
+ * `{ ok: false, reasonCode: "APPROVAL_REQUIRED", requestId }`.
9
+ * DENY — everything else, including ambiguity (ALLOW without a token),
10
+ * an unknown shape, or Guardian being unreachable.
11
+ */
12
+ export type GuardianDecision = {
13
+ decision: "ALLOW";
14
+ requestId: string;
15
+ capabilityToken: string;
16
+ } | {
17
+ decision: "ASK";
18
+ requestId: string;
19
+ reasonCode: string;
20
+ } | {
21
+ decision: "DENY";
22
+ reasonCode: string;
23
+ requestId?: string;
24
+ };
25
+ export declare function classifyRequestResult(result: GuardianRequestResult): GuardianDecision;
@@ -10,6 +10,21 @@ export declare const AgentActionProposalSchema: z.ZodObject<{
10
10
  merchantCategory: z.ZodOptional<z.ZodString>;
11
11
  recurring: z.ZodOptional<z.ZodBoolean>;
12
12
  taskId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "TaskId", "out">>;
13
+ intentId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "IntentId", "out">>;
14
+ planId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "PlanId", "out">>;
15
+ parentActionId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "RequestId", "out">>;
16
+ sourceEffectId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "AttemptId", "out">>;
17
+ compensatesTransactionId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
18
+ physicalFacts: z.ZodOptional<z.ZodObject<{
19
+ zone: z.ZodOptional<z.ZodString>;
20
+ speed: z.ZodOptional<z.ZodNumber>;
21
+ force: z.ZodOptional<z.ZodNumber>;
22
+ payload: z.ZodOptional<z.ZodNumber>;
23
+ atEpochMs: z.ZodOptional<z.ZodNumber>;
24
+ humanDistance: z.ZodOptional<z.ZodNumber>;
25
+ environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
26
+ supervised: z.ZodOptional<z.ZodBoolean>;
27
+ }, z.core.$strict>>;
13
28
  uses: z.ZodLiteral<1>;
14
29
  materialParameters: z.ZodPipe<z.ZodUnknown, z.ZodTransform<Readonly<Record<string, import("./contracts/canonical-json.js").CanonicalJsonValue>>, unknown>>;
15
30
  purpose: z.ZodString;
@@ -21,5 +36,6 @@ export declare const AgentActionProposalSchema: z.ZodObject<{
21
36
  }>;
22
37
  requestedAdapterId: z.core.$ZodBranded<z.ZodString, "AdapterId", "out">;
23
38
  requestedTtlMs: z.ZodNumber;
39
+ runtime: z.ZodOptional<z.ZodString>;
24
40
  }, z.core.$strict>;
25
41
  export type AgentActionProposal = z.infer<typeof AgentActionProposalSchema>;
@@ -0,0 +1,37 @@
1
+ import { verifyPortableAuthorityReceipt } from "./evidence/receipt.js";
2
+ /**
3
+ * WO-042 — portable receipt verification for developers and auditors.
4
+ *
5
+ * Offline verification needs only the receipt and Guardian's published
6
+ * Ed25519 verification keys: no agent credential, account, plan or Guardian
7
+ * service is involved once the keys are in hand. It checks the
8
+ * `guardian-canonical-json.v1` signature over the receipt body and
9
+ * re-derives every embedded record against the receipt's evidence chain.
10
+ * Verification is never billable (GUA-REVENUE-001).
11
+ */
12
+ export type ReceiptVerification = ReturnType<typeof verifyPortableAuthorityReceipt>;
13
+ export type ReceiptKeySetResult = {
14
+ ok: true;
15
+ keys: unknown;
16
+ } | {
17
+ ok: false;
18
+ reasonCode: string;
19
+ };
20
+ type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
21
+ /** Fetch the published verification key set (public; no credential). */
22
+ export declare function fetchReceiptVerificationKeys(baseUrl: string, options?: {
23
+ fetch?: FetchLike;
24
+ }): Promise<ReceiptKeySetResult>;
25
+ /** Verify a receipt locally against a key set. Pure; no network. */
26
+ export declare function verifyReceiptOffline(receipt: unknown, keys: unknown): ReceiptVerification;
27
+ /** Ask a Guardian deployment to verify a receipt (public endpoint). */
28
+ export declare function verifyReceiptOnline(baseUrl: string, receipt: unknown, options?: {
29
+ fetch?: FetchLike;
30
+ }): Promise<{
31
+ ok: true;
32
+ result: Record<string, unknown>;
33
+ } | {
34
+ ok: false;
35
+ reasonCode: string;
36
+ }>;
37
+ export {};
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@odingard/guardian-sdk",
3
- "version": "0.1.0",
4
- "description": "Guardian agent SDK — request governed capabilities and execute consequential actions under human authority.",
3
+ "version": "0.2.0",
4
+ "description": "Guardian agent SDK — Human Authority Infrastructure for Autonomous AI. Request governed capabilities and execute consequential actions under human authority.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist-dts/index.d.ts",
10
10
  "default": "./dist/index.js"
11
- }
11
+ },
12
+ "./contracts": {
13
+ "types": "./dist-dts/contracts-entry.d.ts",
14
+ "default": "./dist/contracts.js"
15
+ },
16
+ "./catalog.json": "./dist/public-catalog.v1.json"
12
17
  },
13
18
  "files": [
14
19
  "dist",
@@ -20,9 +25,10 @@
20
25
  "access": "public"
21
26
  },
22
27
  "scripts": {
23
- "build": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node22 --external:zod --outfile=dist/index.js && tsc -p tsconfig.build.json",
28
+ "build": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node22 --external:zod --outfile=dist/index.js && esbuild src/contracts-entry.ts --bundle --platform=node --format=esm --target=node22 --external:zod --outfile=dist/contracts.js && cp src/catalog/public-catalog.v1.json dist/ && tsc -p tsconfig.build.json",
29
+ "typecheck": "tsc -p tsconfig.json",
24
30
  "test": "vitest run",
25
- "prepublishOnly": "npm run build"
31
+ "prepublishOnly": "npm run build && npm test"
26
32
  },
27
33
  "dependencies": {
28
34
  "zod": "4.6.5"
@@ -34,7 +40,7 @@
34
40
  "vitest": "3.2.4"
35
41
  },
36
42
  "engines": {
37
- "node": ">=20"
43
+ "node": ">=22"
38
44
  },
39
45
  "keywords": [
40
46
  "guardian",
@@ -1 +0,0 @@
1
- export {};