@auctra/sdk 0.3.5 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.1
4
+
5
+ **Stage 1.0 — SDK + Runtime convergence packaging**
6
+
7
+ - Modularize the client under `authority` / `action` / `evidence` modules (same public API as 0.6.0).
8
+ - Align with Stage 1.0 cloud surface: authorities, `action.evaluate` / `action.execute`, evidence verify.
9
+ - No public API break from 0.6.0.
10
+
11
+ ## 0.6.0
12
+
13
+ **Breaking — Authority Protocol public API (clean break, no legacy aliases)**
14
+
15
+ - Removed public `createDelegation()` and `evaluateAction()`.
16
+ - Canonical surface:
17
+ - `auctra.authority.issue()` / `verify()` / `delegate()` / `revoke()`
18
+ - `auctra.action.evaluate()` (dry-run) / `auctra.action.execute()` (enforce + evidence)
19
+ - `auctra.evidence.verify()`
20
+ - REST: prefer `/v1/authorities` and `/v1/actions/{evaluate,execute}`.
21
+ - `listAuthorities()` / `getAuthority()` replace `listDelegations()` / `getDelegation()`.
22
+
23
+ ## 0.5.0
24
+
25
+ - Introduced Authority Protocol compatibility wrappers (`authority.*`) alongside legacy methods.
26
+
3
27
  ## 0.3.5
4
28
 
5
29
  - Align `AUCTRA_SDK_VERSION` and the `x-auctra-sdk-version` request header with the published package version.
@@ -32,17 +56,14 @@
32
56
 
33
57
  ## 0.3.0
34
58
 
35
- - Extend `evaluateAction` with trust infrastructure fields: `claimedIntentId`, `parentActionId`, `actor`, and `action` (target, description, riskLevel, metadata).
59
+ - Extend action execution with trust infrastructure fields: `claimedIntentId`, `parentActionId`, `actor`, and `action` (target, description, riskLevel, metadata).
36
60
  - Return intelligence metadata on evaluation: authority validity, root intent validity, intent status, trust summary.
37
61
  - Add `listIntents`, `createIntent`, `getIntent`, `getAuthorityGraph`, `getActionEvaluation`, and `getRootIntentChain`.
38
62
 
39
63
  ## 0.2.1
40
64
 
41
65
  - Add complete response types for agents, delegations, action requests, policies, audit events, and API keys.
42
- - Add `getDelegation`, `createPolicy`, and `listApiKeys`.
43
66
  - Honor `Retry-After`, preserve caller cancellation, and validate client options.
44
- - Correct the REST example to use the API's snake_case contract.
45
- - Add package-level integration tests and npm provenance metadata.
46
67
  - Ship tested ESM and CommonJS entry points.
47
68
 
48
69
  ## 0.2.0
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@auctra/sdk.svg)](https://www.npmjs.com/package/@auctra/sdk)
4
4
 
5
- Official TypeScript SDK for [Auctra](https://auctra.tech) — authority infrastructure for AI agents.
6
-
7
- Evaluate every agent action against delegated authority and org policies **before** execution.
5
+ Official TypeScript SDK for [Auctra](https://auctra.tech) — **Authority Protocol** for autonomous actors.
8
6
 
9
7
  | Resource | URL |
10
8
  | -------------------------- | ------------------------------------------------------------- |
@@ -20,11 +18,23 @@ Evaluate every agent action against delegated authority and org policies **befor
20
18
  npm install @auctra/sdk
21
19
  ```
22
20
 
23
- Both ESM (`import`) and CommonJS (`require`) entry points are included.
21
+ ## Canonical API (v0.6+)
22
+
23
+ ```text
24
+ auctra.authority.issue()
25
+ auctra.authority.verify()
26
+ auctra.authority.delegate()
27
+ auctra.authority.revoke()
24
28
 
25
- ## Quick start — evaluateAction
29
+ auctra.action.evaluate() # dry-run Decision
30
+ auctra.action.execute() # enforce + Evidence
31
+
32
+ auctra.evidence.verify()
33
+ ```
26
34
 
27
- Copy-paste this before any consequential agent side effect (payments, refunds, prod changes, CRM writes):
35
+ There is **no** public `createDelegation()` or `evaluateAction()`.
36
+
37
+ ## Quick start
28
38
 
29
39
  ```typescript
30
40
  import { Auctra } from "@auctra/sdk";
@@ -35,129 +45,56 @@ const auctra = new Auctra({
35
45
  maxRetries: 2,
36
46
  });
37
47
 
38
- const decision = await auctra.evaluateAction(
48
+ const agentId = "your-agent-uuid";
49
+ const expiresAt = new Date(Date.now() + 30 * 864e5).toISOString();
50
+
51
+ const { authority } = await auctra.authority.issue({
52
+ subject: agentId,
53
+ capabilities: ["send_payment"],
54
+ constraints: { maxAmount: 1200, currency: "USD" },
55
+ expiresAt,
56
+ });
57
+
58
+ // Dry-run
59
+ await auctra.action.evaluate({
60
+ agentId,
61
+ actionType: "send_payment",
62
+ payload: { amount: 500, currency: "USD" },
63
+ });
64
+
65
+ // Production enforcement path
66
+ const decision = await auctra.action.execute(
39
67
  {
40
- agentId: "your-agent-uuid",
68
+ agentId,
41
69
  actionType: "send_payment",
42
- payload: { amount: 1200, currency: "USD" },
70
+ payload: { amount: 500, currency: "USD" },
43
71
  },
44
72
  { idempotencyKey: crypto.randomUUID() },
45
73
  );
46
74
 
47
75
  if (decision.decision === "allowed") {
48
- // proceed with action
76
+ // proceed
49
77
  } else if (decision.decision === "require_approval") {
50
- // pause for human review in console.auctra.tech/console/reviews
51
78
  console.log(decision.reason, decision.action_request_id);
52
79
  } else {
53
80
  throw new Error(decision.reason);
54
81
  }
55
82
  ```
56
83
 
57
- ### Trust infrastructure (0.3.5+)
58
-
59
- Declare why an action is happening and trace it back to human-approved intent:
84
+ ### Delegate (Child ⊆ Parent)
60
85
 
61
86
  ```typescript
62
- const intent = await auctra.createIntent({
63
- title: "Renew SaaS contracts under $500/month for Q3",
64
- description: "Procurement agent may renew eligible vendor subscriptions.",
87
+ const child = await auctra.authority.delegate({
88
+ parent: authority.id,
89
+ subject: "logistics-agent-uuid",
90
+ capabilities: ["send_payment"],
91
+ constraints: { maxAmount: 300, currency: "USD" },
92
+ expiresAt,
65
93
  });
66
-
67
- const decision = await auctra.evaluateAction({
68
- agentId: "your-agent-uuid",
69
- actionType: "send_payment",
70
- claimedIntentId: intent.intent.id,
71
- intentAnchorToken: intent.intent.anchor_token,
72
- action: {
73
- target: "vendor:slack",
74
- description: "Renew Slack Team plan",
75
- riskLevel: "medium",
76
- },
77
- payload: { amount: 420, currency: "USD" },
78
- });
79
-
80
- console.log(decision.intelligence?.trust_summary);
81
- ```
82
-
83
- ### Production control behavior
84
-
85
- - Anchored intents require the matching `intentAnchorToken`; token possession never bypasses expiry, risk, action-type, target, or resource bounds.
86
- - Count and monetary velocity limits are reserved atomically before a decision. Reuse the same idempotency key for retries of the same business action.
87
- - Custom action types use lowercase namespaced IDs such as `healthcare.ehr.modify_prescription` and recursively validated JSON payload schemas. Breaking schemas should use a new namespaced action ID.
88
- - Proposed policies can be replayed against up to 10,000 recorded actions in the console before publication.
89
- - Restricting an agent quarantines its delegations; reactivation can restore only those quarantined grants. Emergency fleet control is available in the console.
90
-
91
- ## Get an API key
92
-
93
- 1. [Sign up](https://console.auctra.tech/auth/signup) and create an organization
94
- 2. Register an agent and delegate scoped authority
95
- 3. Open [API Keys](https://console.auctra.tech/console/api-keys) → **Create API key**
96
- 4. Use a key with `write` permission for `evaluateAction`
97
-
98
- ## API
99
-
100
- | Method | Description |
101
- | ------------------------------------------- | --------------------------------------------------------------- |
102
- | `evaluateAction(input, options)` | Idempotently check authority + trust trace before an agent acts |
103
- | `listIntents()` | List human-approved intents |
104
- | `createIntent(input)` | Declare a new intent |
105
- | `updateIntent(id, input)` | Update intent metadata or lifecycle status |
106
- | `updateIntentStatus(id, status)` | Change intent lifecycle status |
107
- | `getIntent(id)` | Get intent detail and linked actions |
108
- | `getAuthorityGraph()` | Fetch authority graph nodes and edges |
109
- | `createAuthorityEdge(input)` | Add a validated authority edge |
110
- | `getActionEvaluation(actionRequestId)` | Get decision record for an action |
111
- | `getRootIntentChain(actionRequestId)` | Get root human intent chain (trust trace) |
112
- | `listAgents()` | List registered agents |
113
- | `createAgent(input)` | Register a new agent |
114
- | `updateAgentStatus(id, input)` | Restrict, suspend, reactivate, or mark an agent compromised |
115
- | `deleteAgent(id)` | Remove an agent with no evaluated actions |
116
- | `getAgent(id)` | Get one registered agent |
117
- | `listDelegations()` | List authority delegations |
118
- | `getDelegation(id)` | Get one authority delegation |
119
- | `createDelegation(input)` | Grant bounded authority |
120
- | `revokeDelegation(id)` | Revoke a delegation |
121
- | `listActionRequests()` | List recent evaluations |
122
- | `approveActionRequest(id, approverUserId)` | Approve as an accountable reviewer |
123
- | `rejectActionRequest(id, approverUserId)` | Reject as an accountable reviewer |
124
- | `escalateActionRequest(id, approverUserId)` | Escalate as an accountable reviewer |
125
- | `listPolicies()` | List org policies |
126
- | `createPolicy(input)` | Create an org policy |
127
- | `listAuditEvents()` | List audit ledger events |
128
- | `listApiKeys()` | List API key metadata |
129
-
130
- ## REST API (curl)
131
-
132
- ```bash
133
- curl -X POST https://console.auctra.tech/v1/action-requests/evaluate \
134
- -H "Authorization: Bearer YOUR_API_KEY" \
135
- -H "Idempotency-Key: $(uuidgen)" \
136
- -H "Content-Type: application/json" \
137
- -d '{
138
- "agent_id": "your-agent-uuid",
139
- "action_type": "send_payment",
140
- "payload": { "amount": 100, "currency": "USD" }
141
- }'
142
94
  ```
143
95
 
144
- The SDK applies bounded retries only to reads and idempotent evaluations. API failures throw
145
- `AuctraApiError` with `status`, optional structured `details`, and the server `requestId`.
146
-
147
- The machine-readable OpenAPI 3.1 contract is available at
148
- `https://console.auctra.tech/v1/openapi.json`.
149
-
150
- ## Integration guides (blog)
151
-
152
- Stack-specific walkthroughs with console steps:
153
-
154
- | Stack | Guide |
155
- | ----------------- | ---------------------------------------------------------------- |
156
- | LangChain + MCP | https://auctra.tech/blog/langchain-mcp-authority-integration |
157
- | OpenAI Agents SDK | https://auctra.tech/blog/openai-agents-sdk-authority-integration |
158
- | Vercel AI SDK | https://auctra.tech/blog/vercel-ai-sdk-evaluate-action-hook |
159
- | Stripe payments | https://auctra.tech/blog/stripe-agent-payments-authority-layer |
96
+ Scope escalation is rejected by the protocol/runtime.
160
97
 
161
- ## License
98
+ ## Docs
162
99
 
163
- MIT
100
+ See https://auctra.tech/docs and `docs/AUTHORITY_PROTOCOL_ARCHITECTURE.md`.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuctraApiError = void 0;
4
+ exports.retryDelay = retryDelay;
5
+ exports.wait = wait;
6
+ exports.verifyMandateArtifact = verifyMandateArtifact;
7
+ exports.verifyDecisionArtifact = verifyDecisionArtifact;
8
+ /** @auctra/sdk — Authority Protocol client (Stage 1.0 modular layout). */
9
+ const node_crypto_1 = require("node:crypto");
10
+ class AuctraApiError extends Error {
11
+ status;
12
+ code;
13
+ details;
14
+ requestId;
15
+ constructor(message, options) {
16
+ super(message);
17
+ this.name = "AuctraApiError";
18
+ this.status = options.status;
19
+ this.code = options.code;
20
+ this.details = options.details;
21
+ this.requestId = options.requestId;
22
+ }
23
+ }
24
+ exports.AuctraApiError = AuctraApiError;
25
+ function retryDelay(response, attempt) {
26
+ const retryAfter = response?.headers.get("retry-after");
27
+ if (retryAfter) {
28
+ const seconds = Number(retryAfter);
29
+ if (Number.isFinite(seconds))
30
+ return Math.min(30_000, Math.max(0, seconds * 1_000));
31
+ const dateDelay = Date.parse(retryAfter) - Date.now();
32
+ if (Number.isFinite(dateDelay))
33
+ return Math.min(30_000, Math.max(0, dateDelay));
34
+ }
35
+ return Math.min(5_000, 150 * 2 ** attempt);
36
+ }
37
+ function wait(ms, signal) {
38
+ if (signal?.aborted)
39
+ return Promise.reject(signal.reason);
40
+ return new Promise((resolve, reject) => {
41
+ const timeout = setTimeout(resolve, ms);
42
+ signal?.addEventListener("abort", () => {
43
+ clearTimeout(timeout);
44
+ reject(signal.reason);
45
+ }, { once: true });
46
+ });
47
+ }
48
+ function canonicalizeJson(value) {
49
+ if (Array.isArray(value))
50
+ return value.map(canonicalizeJson);
51
+ if (value && typeof value === "object" && !(value instanceof Date)) {
52
+ return Object.fromEntries(Object.entries(value)
53
+ .filter(([, child]) => child !== undefined)
54
+ .sort(([left], [right]) => left.localeCompare(right))
55
+ .map(([key, child]) => [key, canonicalizeJson(child)]));
56
+ }
57
+ if (value instanceof Date)
58
+ return value.toISOString();
59
+ return value;
60
+ }
61
+ function hashJson(value) {
62
+ return (0, node_crypto_1.createHash)("sha256")
63
+ .update(JSON.stringify(canonicalizeJson(value)))
64
+ .digest("hex");
65
+ }
66
+ function verifyEd25519(input) {
67
+ if (!input.publicKeyPem)
68
+ return false;
69
+ if (input.signature.alg !== "Ed25519")
70
+ return false;
71
+ return (0, node_crypto_1.verify)(null, Buffer.from(JSON.stringify(canonicalizeJson(input.payload))), typeof input.publicKeyPem === "string"
72
+ ? (0, node_crypto_1.createPublicKey)(input.publicKeyPem)
73
+ : input.publicKeyPem, Buffer.from(input.signature.value, "base64url"));
74
+ }
75
+ function verifyMandateArtifact(input) {
76
+ const expectedHash = hashJson(input.payload);
77
+ if (input.evidence.format !== "auctra-mandate.v0.1") {
78
+ return { valid: false, hashValid: false, signatureValid: false };
79
+ }
80
+ if (!input.evidence.signed) {
81
+ const hashValid = input.evidence.payload_hash === expectedHash;
82
+ return { valid: hashValid, hashValid, signatureValid: false };
83
+ }
84
+ const hashValid = input.evidence.payload_hash === expectedHash;
85
+ const signatureValid = hashValid &&
86
+ verifyEd25519({
87
+ payload: input.payload,
88
+ signature: input.evidence.signature,
89
+ publicKeyPem: input.publicKeyPem,
90
+ });
91
+ return { valid: hashValid && signatureValid, hashValid, signatureValid };
92
+ }
93
+ function verifyDecisionArtifact(input) {
94
+ const expectedHash = hashJson(input.payload);
95
+ if (input.evidence.format !== "auctra-evidence.v0.1") {
96
+ return { valid: false, hashValid: false, signatureValid: false };
97
+ }
98
+ if (!input.evidence.signed) {
99
+ const hashValid = input.evidence.payload_hash === expectedHash;
100
+ return { valid: hashValid, hashValid, signatureValid: false };
101
+ }
102
+ const hashValid = input.evidence.payload_hash === expectedHash;
103
+ const signatureValid = hashValid &&
104
+ verifyEd25519({
105
+ payload: input.payload,
106
+ signature: input.evidence.signature,
107
+ publicKeyPem: input.publicKeyPem,
108
+ });
109
+ return { valid: hashValid && signatureValid, hashValid, signatureValid };
110
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });