@auctra/sdk 0.6.0 → 0.6.2

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.
@@ -0,0 +1,195 @@
1
+ import type { ActionEvaluation, ActionRequest, Agent, ApiKeySummary, ArtifactVerification, AuditChainVerification, AuditEvent, AuthorityGraph, AuthoritySummary, AuctraClientOptions, CreateAgentInput, CreateAuthorityEdgeInput, CreateCustomActionTypeInput, CreateIntentInput, CreatePolicyInput, CustomActionType, DecisionEvidence, DecisionEvidencePayload, DelegateAuthorityInput, Delegation, EvaluateActionInput, EvaluateActionResponse, Intent, IntentDetail, IntentStatus, IssueAuthorityInput, MandateEvidence, MandatePayload, Policy, PolicySimulation, RequestOptions, RiskLevel, RootIntentChain, UpdateAgentStatusInput, UpdateIntentInput } from "./types.js";
2
+ export declare class Auctra {
3
+ private readonly apiKey;
4
+ private readonly baseUrl;
5
+ private readonly timeoutMs;
6
+ private readonly maxRetries;
7
+ private readonly fetchImpl;
8
+ constructor(options: AuctraClientOptions);
9
+ private request;
10
+ private executeOrEvaluateAction;
11
+ private issueAuthorityRequest;
12
+ /**
13
+ * Authority Protocol — issue, verify, delegate (subset), revoke.
14
+ * There is no legacy createDelegation() surface.
15
+ */
16
+ get authority(): {
17
+ issue: (input: IssueAuthorityInput) => Promise<{
18
+ authority: AuthoritySummary;
19
+ authority_id: string;
20
+ delegation: Delegation;
21
+ }>;
22
+ verify: (payload: Record<string, unknown>, artifact: Record<string, unknown>) => Promise<{
23
+ valid: boolean;
24
+ hashValid: boolean;
25
+ signatureValid: boolean;
26
+ expired: boolean;
27
+ status: string;
28
+ issuer: string;
29
+ subject: string;
30
+ capabilities: string[];
31
+ constraints: Record<string, unknown>;
32
+ expiresAt: string;
33
+ protocolVersion: string;
34
+ }>;
35
+ delegate: (input: DelegateAuthorityInput) => Promise<{
36
+ authority: AuthoritySummary;
37
+ authority_id: string;
38
+ delegation: Delegation;
39
+ }>;
40
+ revoke: (authorityId: string) => Promise<{
41
+ ok: true;
42
+ }>;
43
+ };
44
+ /**
45
+ * Action Protocol — evaluate (dry-run) vs execute (enforce + evidence).
46
+ * There is no legacy evaluateAction() surface.
47
+ */
48
+ get action(): {
49
+ evaluate: (input: EvaluateActionInput, options?: RequestOptions) => Promise<EvaluateActionResponse>;
50
+ execute: (input: EvaluateActionInput, options?: RequestOptions) => Promise<EvaluateActionResponse>;
51
+ };
52
+ get evidence(): {
53
+ verify: (payload: DecisionEvidencePayload, evidence: DecisionEvidence) => Promise<ArtifactVerification>;
54
+ };
55
+ verifyMandate(payload: MandatePayload, evidence: MandateEvidence): Promise<ArtifactVerification>;
56
+ listIntents(): Promise<{
57
+ intents: Intent[];
58
+ }>;
59
+ createIntent(input: CreateIntentInput): Promise<{
60
+ intent: {
61
+ id: string;
62
+ title: string;
63
+ status: string;
64
+ };
65
+ }>;
66
+ getIntent(intentId: string): Promise<{
67
+ intent: IntentDetail;
68
+ }>;
69
+ updateIntentStatus(intentId: string, status: Exclude<IntentStatus, "expired">): Promise<{
70
+ intent: {
71
+ id: string;
72
+ title: string;
73
+ status: IntentStatus;
74
+ };
75
+ }>;
76
+ updateIntent(intentId: string, input: UpdateIntentInput): Promise<{
77
+ intent: {
78
+ id: string;
79
+ title: string;
80
+ status: IntentStatus;
81
+ description?: string | null;
82
+ intent_type?: string | null;
83
+ risk_level?: RiskLevel;
84
+ max_risk_level?: RiskLevel;
85
+ expires_at?: string | null;
86
+ };
87
+ }>;
88
+ getAuthorityGraph(): Promise<{
89
+ authority_graph: AuthorityGraph;
90
+ }>;
91
+ createAuthorityEdge(input: CreateAuthorityEdgeInput): Promise<{
92
+ edge: {
93
+ id: string;
94
+ };
95
+ }>;
96
+ getActionEvaluation(actionRequestId: string): Promise<{
97
+ evaluation: ActionEvaluation;
98
+ }>;
99
+ getRootIntentChain(actionRequestId: string): Promise<{
100
+ root_intent_chain: RootIntentChain;
101
+ }>;
102
+ listAgents(): Promise<{
103
+ agents: Agent[];
104
+ }>;
105
+ getAgent(agentId: string): Promise<{
106
+ agent: Agent;
107
+ }>;
108
+ createAgent(input: CreateAgentInput): Promise<{
109
+ agent: Agent;
110
+ }>;
111
+ updateAgentStatus(agentId: string, input: UpdateAgentStatusInput): Promise<{
112
+ agent: {
113
+ id: string;
114
+ name: string;
115
+ status: Agent["status"];
116
+ };
117
+ }>;
118
+ deleteAgent(agentId: string): Promise<{
119
+ ok: true;
120
+ }>;
121
+ listAuthorities(): Promise<{
122
+ delegations: Delegation[];
123
+ authorities?: AuthoritySummary[];
124
+ }>;
125
+ getAuthority(authorityId: string): Promise<{
126
+ delegation: Delegation;
127
+ }>;
128
+ listActionRequests(): Promise<{
129
+ action_requests: ActionRequest[];
130
+ }>;
131
+ approveActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
132
+ ok: true;
133
+ decision: "approved" | "rejected" | "escalated";
134
+ action_decision: "allowed" | "blocked" | "require_approval";
135
+ reason: string;
136
+ }>;
137
+ rejectActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
138
+ ok: true;
139
+ decision: "approved" | "rejected" | "escalated";
140
+ action_decision: "allowed" | "blocked" | "require_approval";
141
+ reason: string;
142
+ }>;
143
+ escalateActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
144
+ ok: true;
145
+ decision: "approved" | "rejected" | "escalated";
146
+ action_decision: "allowed" | "blocked" | "require_approval";
147
+ reason: string;
148
+ }>;
149
+ private resolveActionRequest;
150
+ listPolicies(): Promise<{
151
+ policies: Policy[];
152
+ }>;
153
+ createPolicy(input: CreatePolicyInput): Promise<{
154
+ policy: Pick<Policy, "id" | "name" | "status" | "created_at">;
155
+ }>;
156
+ simulatePolicy(policyId: string, input?: {
157
+ limit?: number;
158
+ since?: string;
159
+ }): Promise<{
160
+ simulation: PolicySimulation;
161
+ meta: {
162
+ simulated_at: string;
163
+ sample_size: number;
164
+ changed_count: number;
165
+ unchanged_count: number;
166
+ };
167
+ }>;
168
+ publishPolicy(policyId: string, input?: {
169
+ force?: boolean;
170
+ }): Promise<{
171
+ ok: true;
172
+ policyId: string;
173
+ simulation: Record<string, unknown>;
174
+ }>;
175
+ listActionTypes(): Promise<{
176
+ action_types: CustomActionType[];
177
+ }>;
178
+ listCustomActionTypes(): Promise<{
179
+ action_types: CustomActionType[];
180
+ }>;
181
+ createCustomActionType(input: CreateCustomActionTypeInput): Promise<{
182
+ action_type: Pick<CustomActionType, "id" | "label" | "policy_type" | "source" | "created_at">;
183
+ }>;
184
+ listAuditEvents(): Promise<{
185
+ audit_events: AuditEvent[];
186
+ }>;
187
+ getAuditEvent(auditEventId: string): Promise<{
188
+ audit_event: AuditEvent;
189
+ }>;
190
+ verifyAuditChain(): Promise<AuditChainVerification>;
191
+ listApiKeys(): Promise<{
192
+ api_keys: ApiKeySummary[];
193
+ }>;
194
+ }
195
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEb,KAAK,EACL,aAAa,EACb,oBAAoB,EACpB,sBAAsB,EACtB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,EACtB,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAA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Q,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAIzE,eAAe,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC;IAIhE,qBAAqB,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC;IAItE,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC;QACxE,WAAW,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,OAAO,GAAG,aAAa,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAC;KAC/F,CAAC;IAWI,eAAe,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAI1D,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,UAAU,CAAA;KAAE,CAAC;IAIzE,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAInD,WAAW,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;CAG5D"}
@@ -0,0 +1,351 @@
1
+ /** @auctra/sdk — Authority Protocol client (Stage 1.0 modular layout). */
2
+ import { AuctraApiError, retryDelay, wait } from "./artifacts.js";
3
+ import { AUCTRA_SDK_VERSION, DEFAULT_BASE_URL } from "./types.js";
4
+ export class Auctra {
5
+ apiKey;
6
+ baseUrl;
7
+ timeoutMs;
8
+ maxRetries;
9
+ fetchImpl;
10
+ constructor(options) {
11
+ if (!options.apiKey.trim())
12
+ throw new Error("apiKey is required");
13
+ if (options.timeoutMs !== undefined && options.timeoutMs <= 0) {
14
+ throw new Error("timeoutMs must be greater than zero");
15
+ }
16
+ if (options.maxRetries !== undefined &&
17
+ (!Number.isInteger(options.maxRetries) || options.maxRetries < 0)) {
18
+ throw new Error("maxRetries must be a non-negative integer");
19
+ }
20
+ this.apiKey = options.apiKey;
21
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
22
+ this.timeoutMs = options.timeoutMs ?? 10_000;
23
+ this.maxRetries = options.maxRetries ?? 2;
24
+ this.fetchImpl = options.fetch ?? globalThis.fetch;
25
+ if (!this.fetchImpl)
26
+ throw new Error("A fetch implementation is required");
27
+ }
28
+ async request(method, path, body, options = {}) {
29
+ const retryableRequest = method === "GET" || Boolean(options.idempotencyKey);
30
+ let lastError;
31
+ for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
32
+ if (options.signal?.aborted)
33
+ throw options.signal.reason;
34
+ const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
35
+ const signal = options.signal
36
+ ? AbortSignal.any([options.signal, timeoutSignal])
37
+ : timeoutSignal;
38
+ let response;
39
+ try {
40
+ response = await this.fetchImpl(`${this.baseUrl}${path}`, {
41
+ method,
42
+ signal,
43
+ headers: {
44
+ ...(body !== undefined ? { "content-type": "application/json" } : {}),
45
+ ...(options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}),
46
+ authorization: `Bearer ${this.apiKey}`,
47
+ "x-auctra-sdk-version": AUCTRA_SDK_VERSION,
48
+ },
49
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
50
+ });
51
+ const data = (await response.json().catch(() => ({})));
52
+ if (response.ok)
53
+ return data;
54
+ if (retryableRequest &&
55
+ (response.status === 429 || response.status >= 500) &&
56
+ attempt < this.maxRetries) {
57
+ await wait(retryDelay(response, attempt), options.signal);
58
+ continue;
59
+ }
60
+ throw new AuctraApiError(typeof data.error === "string" ? data.error : `Auctra API error (${response.status})`, {
61
+ status: response.status,
62
+ code: typeof data.code === "string" ? data.code : undefined,
63
+ details: data.details,
64
+ requestId: response.headers.get("x-request-id") ?? undefined,
65
+ });
66
+ }
67
+ catch (error) {
68
+ lastError = error;
69
+ if (options.signal?.aborted)
70
+ throw options.signal.reason;
71
+ if (error instanceof AuctraApiError || !retryableRequest || attempt >= this.maxRetries) {
72
+ throw error;
73
+ }
74
+ await wait(retryDelay(response, attempt), options.signal);
75
+ }
76
+ }
77
+ throw lastError;
78
+ }
79
+ async executeOrEvaluateAction(input, options, mode) {
80
+ const idempotencyKey = mode === "execute" ? (options.idempotencyKey ?? crypto.randomUUID()) : options.idempotencyKey;
81
+ const path = mode === "execute" ? "/v1/actions/execute" : "/v1/actions/evaluate";
82
+ return this.request("POST", path, {
83
+ agent_id: input.agentId,
84
+ action_type: input.actionType,
85
+ payload: input.payload ?? {},
86
+ claimed_intent_id: input.claimedIntentId,
87
+ intent_anchor_token: input.intentAnchorToken,
88
+ parent_action_id: input.parentActionId,
89
+ dry_run: mode === "evaluate",
90
+ actor: input.actor
91
+ ? {
92
+ id: input.actor.id,
93
+ type: input.actor.type,
94
+ name: input.actor.name,
95
+ }
96
+ : undefined,
97
+ action: input.action
98
+ ? {
99
+ target: input.action.target,
100
+ description: input.action.description,
101
+ risk_level: input.action.riskLevel,
102
+ metadata: input.action.metadata,
103
+ }
104
+ : undefined,
105
+ }, mode === "execute" ? { ...options, idempotencyKey } : options);
106
+ }
107
+ async issueAuthorityRequest(input) {
108
+ const response = await this.request("POST", "/v1/authorities", {
109
+ agent_id: input.subject,
110
+ action_types: input.capabilities,
111
+ valid_until: input.expiresAt,
112
+ max_amount: input.constraints?.maxAmount,
113
+ max_count: input.constraints?.maxCount,
114
+ environment: input.constraints?.environment,
115
+ currency: input.constraints?.currency,
116
+ delegator_user_id: input.delegatorUserId ?? input.issuer,
117
+ parent_authority_id: input.parentAuthorityId,
118
+ max_delegation_depth: input.delegation?.maxDepth,
119
+ max_actions_per_window: input.maxActionsPerWindow
120
+ ? {
121
+ count: input.maxActionsPerWindow.count,
122
+ window_seconds: input.maxActionsPerWindow.windowSeconds,
123
+ action_type: input.maxActionsPerWindow.actionType,
124
+ }
125
+ : undefined,
126
+ max_amount_per_window: input.maxAmountPerWindow
127
+ ? {
128
+ amount: input.maxAmountPerWindow.amount,
129
+ window_seconds: input.maxAmountPerWindow.windowSeconds,
130
+ }
131
+ : undefined,
132
+ });
133
+ const authorityId = response.authority_id ?? response.delegation.id;
134
+ const authority = response.authority ?? {
135
+ id: authorityId,
136
+ protocol_version: "0.1",
137
+ status: response.delegation.status,
138
+ payload_hash: "",
139
+ signed: false,
140
+ parent_authority_id: input.parentAuthorityId ?? null,
141
+ capabilities: input.capabilities,
142
+ };
143
+ return {
144
+ authority,
145
+ authority_id: authorityId,
146
+ delegation: response.delegation,
147
+ };
148
+ }
149
+ /**
150
+ * Authority Protocol — issue, verify, delegate (subset), revoke.
151
+ * There is no legacy createDelegation() surface.
152
+ */
153
+ get authority() {
154
+ return {
155
+ issue: (input) => this.issueAuthorityRequest(input),
156
+ verify: (payload, artifact) => this.request("POST", "/v1/authorities/verify", { payload, artifact }),
157
+ delegate: (input) => this.issueAuthorityRequest({
158
+ ...input,
159
+ parentAuthorityId: input.parent,
160
+ }),
161
+ revoke: (authorityId) => this.request("POST", `/v1/authorities/${encodeURIComponent(authorityId)}/revoke`, {}),
162
+ };
163
+ }
164
+ /**
165
+ * Action Protocol — evaluate (dry-run) vs execute (enforce + evidence).
166
+ * There is no legacy evaluateAction() surface.
167
+ */
168
+ get action() {
169
+ return {
170
+ evaluate: (input, options = {}) => this.executeOrEvaluateAction(input, options, "evaluate"),
171
+ execute: (input, options = {}) => this.executeOrEvaluateAction(input, options, "execute"),
172
+ };
173
+ }
174
+ get evidence() {
175
+ return {
176
+ verify: (payload, evidence) => this.request("POST", "/v1/evidence/verify", { payload, evidence }),
177
+ };
178
+ }
179
+ async verifyMandate(payload, evidence) {
180
+ return this.request("POST", "/v1/mandates/verify", { payload, evidence });
181
+ }
182
+ async listIntents() {
183
+ return this.request("GET", "/v1/intents");
184
+ }
185
+ async createIntent(input) {
186
+ return this.request("POST", "/v1/intents", {
187
+ title: input.title,
188
+ description: input.description,
189
+ intent_type: input.intentType,
190
+ risk_level: input.riskLevel,
191
+ max_risk_level: input.maxRiskLevel,
192
+ expires_at: input.expiresAt,
193
+ allowed_action_types: input.allowedActionTypes,
194
+ target_pattern: input.targetPattern,
195
+ resource_allowlist: input.resourceAllowlist,
196
+ });
197
+ }
198
+ async getIntent(intentId) {
199
+ return this.request("GET", `/v1/intents/${encodeURIComponent(intentId)}`);
200
+ }
201
+ async updateIntentStatus(intentId, status) {
202
+ return this.updateIntent(intentId, { status });
203
+ }
204
+ async updateIntent(intentId, input) {
205
+ return this.request("PATCH", `/v1/intents/${encodeURIComponent(intentId)}`, {
206
+ status: input.status,
207
+ title: input.title,
208
+ description: input.description,
209
+ intent_type: input.intentType,
210
+ risk_level: input.riskLevel,
211
+ max_risk_level: input.maxRiskLevel,
212
+ expires_at: input.expiresAt,
213
+ });
214
+ }
215
+ async getAuthorityGraph() {
216
+ return this.request("GET", "/v1/authority/graph");
217
+ }
218
+ async createAuthorityEdge(input) {
219
+ return this.request("POST", "/v1/authority/edges", {
220
+ from_actor_id: input.fromActorId,
221
+ from_actor_type: input.fromActorType,
222
+ to_actor_id: input.toActorId,
223
+ to_actor_type: input.toActorType,
224
+ authority_scope: input.authorityScope,
225
+ conditions: input.conditions,
226
+ max_risk_level: input.maxRiskLevel,
227
+ expires_at: input.expiresAt,
228
+ });
229
+ }
230
+ async getActionEvaluation(actionRequestId) {
231
+ return this.request("GET", `/v1/action-requests/${encodeURIComponent(actionRequestId)}/evaluation`);
232
+ }
233
+ async getRootIntentChain(actionRequestId) {
234
+ return this.request("GET", `/v1/action-requests/${encodeURIComponent(actionRequestId)}/root-intent`);
235
+ }
236
+ async listAgents() {
237
+ return this.request("GET", "/v1/agents");
238
+ }
239
+ async getAgent(agentId) {
240
+ return this.request("GET", `/v1/agents/${encodeURIComponent(agentId)}`);
241
+ }
242
+ async createAgent(input) {
243
+ return this.request("POST", "/v1/agents", {
244
+ name: input.name,
245
+ model_provider: input.modelProvider,
246
+ model_name: input.modelName,
247
+ description: input.description,
248
+ environment: input.environment,
249
+ authority_level: input.authorityLevel,
250
+ sponsor_user_id: input.sponsorUserId,
251
+ });
252
+ }
253
+ async updateAgentStatus(agentId, input) {
254
+ return this.request("PATCH", `/v1/agents/${encodeURIComponent(agentId)}`, {
255
+ status: input.status,
256
+ reason: input.reason,
257
+ revoke_delegations: input.revokeDelegations,
258
+ restore_delegations: input.restoreDelegations,
259
+ });
260
+ }
261
+ async deleteAgent(agentId) {
262
+ return this.request("DELETE", `/v1/agents/${encodeURIComponent(agentId)}`);
263
+ }
264
+ async listAuthorities() {
265
+ return this.request("GET", "/v1/authorities");
266
+ }
267
+ async getAuthority(authorityId) {
268
+ return this.request("GET", `/v1/authorities/${encodeURIComponent(authorityId)}`);
269
+ }
270
+ async listActionRequests() {
271
+ return this.request("GET", "/v1/action-requests");
272
+ }
273
+ async approveActionRequest(actionRequestId, approverUserId, reason) {
274
+ return this.resolveActionRequest(actionRequestId, "approve", approverUserId, reason);
275
+ }
276
+ async rejectActionRequest(actionRequestId, approverUserId, reason) {
277
+ return this.resolveActionRequest(actionRequestId, "reject", approverUserId, reason);
278
+ }
279
+ async escalateActionRequest(actionRequestId, approverUserId, reason) {
280
+ return this.resolveActionRequest(actionRequestId, "escalate", approverUserId, reason);
281
+ }
282
+ async resolveActionRequest(actionRequestId, action, approverUserId, reason) {
283
+ return this.request("POST", `/v1/action-requests/${encodeURIComponent(actionRequestId)}/${action}`, { reason, approver_user_id: approverUserId });
284
+ }
285
+ async listPolicies() {
286
+ return this.request("GET", "/v1/policies");
287
+ }
288
+ async createPolicy(input) {
289
+ return this.request("POST", "/v1/policies", {
290
+ name: input.name,
291
+ description: input.description,
292
+ policy_type: input.policyType,
293
+ status: input.status,
294
+ priority: input.priority,
295
+ action_type: input.actionType,
296
+ amount_greater_than: input.amountGreaterThan,
297
+ resource_sensitivity: input.resourceSensitivity,
298
+ external_recipient: input.externalRecipient,
299
+ environment: input.environment,
300
+ decision: input.decision,
301
+ approver_role: input.approverRole,
302
+ max_actions_per_window: input.maxActionsPerWindow
303
+ ? {
304
+ count: input.maxActionsPerWindow.count,
305
+ window_seconds: input.maxActionsPerWindow.windowSeconds,
306
+ action_type: input.maxActionsPerWindow.actionType,
307
+ }
308
+ : undefined,
309
+ max_amount_per_window: input.maxAmountPerWindow
310
+ ? {
311
+ amount: input.maxAmountPerWindow.amount,
312
+ window_seconds: input.maxAmountPerWindow.windowSeconds,
313
+ }
314
+ : undefined,
315
+ });
316
+ }
317
+ async simulatePolicy(policyId, input = {}) {
318
+ return this.request("POST", `/v1/policies/${encodeURIComponent(policyId)}/simulate`, input);
319
+ }
320
+ async publishPolicy(policyId, input = {}) {
321
+ return this.request("POST", `/v1/policies/${encodeURIComponent(policyId)}/publish`, input);
322
+ }
323
+ async listActionTypes() {
324
+ return this.listCustomActionTypes();
325
+ }
326
+ async listCustomActionTypes() {
327
+ return this.request("GET", "/v1/action-types");
328
+ }
329
+ async createCustomActionType(input) {
330
+ return this.request("POST", "/v1/action-types", {
331
+ id: input.id,
332
+ label: input.label,
333
+ description: input.description,
334
+ category: input.category,
335
+ policy_type: input.policyType,
336
+ payload_schema: input.payloadSchema ?? {},
337
+ });
338
+ }
339
+ async listAuditEvents() {
340
+ return this.request("GET", "/v1/audit-events");
341
+ }
342
+ async getAuditEvent(auditEventId) {
343
+ return this.request("GET", `/v1/audit-events/${encodeURIComponent(auditEventId)}`);
344
+ }
345
+ async verifyAuditChain() {
346
+ return this.request("GET", "/v1/audit-events/verify");
347
+ }
348
+ async listApiKeys() {
349
+ return this.request("GET", "/v1/api-keys");
350
+ }
351
+ }
@@ -0,0 +1,4 @@
1
+ /** Evidence verification surface. */
2
+ export type { ArtifactVerification, DecisionEvidence, DecisionEvidencePayload, MandateEvidence, MandatePayload, } from "./types.js";
3
+ export { verifyDecisionArtifact, verifyMandateArtifact } from "./artifacts.js";
4
+ //# sourceMappingURL=evidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../../src/evidence.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ export { verifyDecisionArtifact, verifyMandateArtifact } from "./artifacts.js";