@auctra/sdk 0.2.0 → 0.2.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 +14 -0
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/cjs/index.js +201 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.d.ts +234 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/{index.js → esm/index.js} +80 -27
- package/package.json +18 -8
- package/src/index.ts +414 -0
- package/dist/index.d.ts +0 -129
- package/dist/index.d.ts.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Add complete response types for agents, delegations, action requests, policies, audit events, and API keys.
|
|
6
|
+
- Add `getDelegation`, `createPolicy`, and `listApiKeys`.
|
|
7
|
+
- Honor `Retry-After`, preserve caller cancellation, and validate client options.
|
|
8
|
+
- Correct the REST example to use the API's snake_case contract.
|
|
9
|
+
- Add package-level integration tests and npm provenance metadata.
|
|
10
|
+
- Ship tested ESM and CommonJS entry points.
|
|
11
|
+
|
|
12
|
+
## 0.2.0
|
|
13
|
+
|
|
14
|
+
- Add bounded retries, request deadlines, idempotent evaluation, and structured API errors.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Auctra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ Evaluate every agent action against delegated authority and org policies before
|
|
|
16
16
|
npm install @auctra/sdk
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
Both ESM (`import`) and CommonJS (`require`) entry points are included.
|
|
20
|
+
|
|
19
21
|
## Quick start
|
|
20
22
|
|
|
21
23
|
```typescript
|
|
@@ -60,7 +62,9 @@ if (decision.decision === "allowed") {
|
|
|
60
62
|
| `evaluateAction(input, options)` | Idempotently check authority before an agent acts |
|
|
61
63
|
| `listAgents()` | List registered agents |
|
|
62
64
|
| `createAgent(input)` | Register a new agent |
|
|
65
|
+
| `getAgent(id)` | Get one registered agent |
|
|
63
66
|
| `listDelegations()` | List authority delegations |
|
|
67
|
+
| `getDelegation(id)` | Get one authority delegation |
|
|
64
68
|
| `createDelegation(input)` | Grant bounded authority |
|
|
65
69
|
| `revokeDelegation(id)` | Revoke a delegation |
|
|
66
70
|
| `listActionRequests()` | List recent evaluations |
|
|
@@ -68,7 +72,9 @@ if (decision.decision === "allowed") {
|
|
|
68
72
|
| `rejectActionRequest(id, approverUserId)` | Reject as an accountable reviewer |
|
|
69
73
|
| `escalateActionRequest(id, approverUserId)` | Escalate as an accountable reviewer |
|
|
70
74
|
| `listPolicies()` | List org policies |
|
|
75
|
+
| `createPolicy(input)` | Create an org policy |
|
|
71
76
|
| `listAuditEvents()` | List audit ledger events |
|
|
77
|
+
| `listApiKeys()` | List API key metadata |
|
|
72
78
|
|
|
73
79
|
## REST API (curl)
|
|
74
80
|
|
|
@@ -78,8 +84,8 @@ curl -X POST https://console.auctra.tech/v1/action-requests/evaluate \
|
|
|
78
84
|
-H "Idempotency-Key: $(uuidgen)" \
|
|
79
85
|
-H "Content-Type: application/json" \
|
|
80
86
|
-d '{
|
|
81
|
-
"
|
|
82
|
-
"
|
|
87
|
+
"agent_id": "your-agent-uuid",
|
|
88
|
+
"action_type": "send_payment",
|
|
83
89
|
"payload": { "amount": 100, "currency": "USD" }
|
|
84
90
|
}'
|
|
85
91
|
```
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auctra = exports.AuctraApiError = exports.AUCTRA_SDK_VERSION = void 0;
|
|
4
|
+
exports.AUCTRA_SDK_VERSION = "0.2.1";
|
|
5
|
+
class AuctraApiError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
code;
|
|
8
|
+
details;
|
|
9
|
+
requestId;
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "AuctraApiError";
|
|
13
|
+
this.status = options.status;
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.details = options.details;
|
|
16
|
+
this.requestId = options.requestId;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuctraApiError = AuctraApiError;
|
|
20
|
+
function retryDelay(response, attempt) {
|
|
21
|
+
const retryAfter = response?.headers.get("retry-after");
|
|
22
|
+
if (retryAfter) {
|
|
23
|
+
const seconds = Number(retryAfter);
|
|
24
|
+
if (Number.isFinite(seconds))
|
|
25
|
+
return Math.min(30_000, Math.max(0, seconds * 1_000));
|
|
26
|
+
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
27
|
+
if (Number.isFinite(dateDelay))
|
|
28
|
+
return Math.min(30_000, Math.max(0, dateDelay));
|
|
29
|
+
}
|
|
30
|
+
return Math.min(5_000, 150 * 2 ** attempt);
|
|
31
|
+
}
|
|
32
|
+
function wait(ms, signal) {
|
|
33
|
+
if (signal?.aborted)
|
|
34
|
+
return Promise.reject(signal.reason);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const timeout = setTimeout(resolve, ms);
|
|
37
|
+
signal?.addEventListener("abort", () => {
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
reject(signal.reason);
|
|
40
|
+
}, { once: true });
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
class Auctra {
|
|
44
|
+
apiKey;
|
|
45
|
+
baseUrl;
|
|
46
|
+
timeoutMs;
|
|
47
|
+
maxRetries;
|
|
48
|
+
fetchImpl;
|
|
49
|
+
constructor(options) {
|
|
50
|
+
if (!options.apiKey.trim())
|
|
51
|
+
throw new Error("apiKey is required");
|
|
52
|
+
if (options.timeoutMs !== undefined && options.timeoutMs <= 0) {
|
|
53
|
+
throw new Error("timeoutMs must be greater than zero");
|
|
54
|
+
}
|
|
55
|
+
if (options.maxRetries !== undefined &&
|
|
56
|
+
(!Number.isInteger(options.maxRetries) || options.maxRetries < 0)) {
|
|
57
|
+
throw new Error("maxRetries must be a non-negative integer");
|
|
58
|
+
}
|
|
59
|
+
this.apiKey = options.apiKey;
|
|
60
|
+
this.baseUrl = (options.baseUrl ?? "https://console.auctra.tech").replace(/\/$/, "");
|
|
61
|
+
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
62
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
63
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
64
|
+
if (!this.fetchImpl)
|
|
65
|
+
throw new Error("A fetch implementation is required");
|
|
66
|
+
}
|
|
67
|
+
async request(method, path, body, options = {}) {
|
|
68
|
+
const retryableRequest = method === "GET" || Boolean(options.idempotencyKey);
|
|
69
|
+
let lastError;
|
|
70
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
|
|
71
|
+
if (options.signal?.aborted)
|
|
72
|
+
throw options.signal.reason;
|
|
73
|
+
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
74
|
+
const signal = options.signal
|
|
75
|
+
? AbortSignal.any([options.signal, timeoutSignal])
|
|
76
|
+
: timeoutSignal;
|
|
77
|
+
let response;
|
|
78
|
+
try {
|
|
79
|
+
response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
80
|
+
method,
|
|
81
|
+
signal,
|
|
82
|
+
headers: {
|
|
83
|
+
...(body !== undefined ? { "content-type": "application/json" } : {}),
|
|
84
|
+
...(options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}),
|
|
85
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
86
|
+
"x-auctra-sdk-version": exports.AUCTRA_SDK_VERSION,
|
|
87
|
+
},
|
|
88
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
89
|
+
});
|
|
90
|
+
const data = (await response.json().catch(() => ({})));
|
|
91
|
+
if (response.ok)
|
|
92
|
+
return data;
|
|
93
|
+
if (retryableRequest &&
|
|
94
|
+
(response.status === 429 || response.status >= 500) &&
|
|
95
|
+
attempt < this.maxRetries) {
|
|
96
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
throw new AuctraApiError(typeof data.error === "string" ? data.error : `Auctra API error (${response.status})`, {
|
|
100
|
+
status: response.status,
|
|
101
|
+
code: typeof data.code === "string" ? data.code : undefined,
|
|
102
|
+
details: data.details,
|
|
103
|
+
requestId: response.headers.get("x-request-id") ?? undefined,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
lastError = error;
|
|
108
|
+
if (options.signal?.aborted)
|
|
109
|
+
throw options.signal.reason;
|
|
110
|
+
if (error instanceof AuctraApiError || !retryableRequest || attempt >= this.maxRetries) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw lastError;
|
|
117
|
+
}
|
|
118
|
+
async evaluateAction(input, options = {}) {
|
|
119
|
+
const idempotencyKey = options.idempotencyKey ?? crypto.randomUUID();
|
|
120
|
+
return this.request("POST", "/v1/action-requests/evaluate", { agent_id: input.agentId, action_type: input.actionType, payload: input.payload ?? {} }, { ...options, idempotencyKey });
|
|
121
|
+
}
|
|
122
|
+
async listAgents() {
|
|
123
|
+
return this.request("GET", "/v1/agents");
|
|
124
|
+
}
|
|
125
|
+
async getAgent(agentId) {
|
|
126
|
+
return this.request("GET", `/v1/agents/${encodeURIComponent(agentId)}`);
|
|
127
|
+
}
|
|
128
|
+
async createAgent(input) {
|
|
129
|
+
return this.request("POST", "/v1/agents", {
|
|
130
|
+
name: input.name,
|
|
131
|
+
model_provider: input.modelProvider,
|
|
132
|
+
model_name: input.modelName,
|
|
133
|
+
description: input.description,
|
|
134
|
+
environment: input.environment,
|
|
135
|
+
authority_level: input.authorityLevel,
|
|
136
|
+
sponsor_user_id: input.sponsorUserId,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async listDelegations() {
|
|
140
|
+
return this.request("GET", "/v1/delegations");
|
|
141
|
+
}
|
|
142
|
+
async getDelegation(delegationId) {
|
|
143
|
+
return this.request("GET", `/v1/delegations/${encodeURIComponent(delegationId)}`);
|
|
144
|
+
}
|
|
145
|
+
async createDelegation(input) {
|
|
146
|
+
return this.request("POST", "/v1/delegations", {
|
|
147
|
+
agent_id: input.agentId,
|
|
148
|
+
action_types: input.actionTypes,
|
|
149
|
+
valid_until: input.validUntil,
|
|
150
|
+
max_amount: input.maxAmount,
|
|
151
|
+
max_count: input.maxCount,
|
|
152
|
+
environment: input.environment,
|
|
153
|
+
currency: input.currency,
|
|
154
|
+
delegator_user_id: input.delegatorUserId,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async revokeDelegation(delegationId) {
|
|
158
|
+
return this.request("POST", `/v1/delegations/${encodeURIComponent(delegationId)}/revoke`, {});
|
|
159
|
+
}
|
|
160
|
+
async listActionRequests() {
|
|
161
|
+
return this.request("GET", "/v1/action-requests");
|
|
162
|
+
}
|
|
163
|
+
async approveActionRequest(actionRequestId, approverUserId, reason) {
|
|
164
|
+
return this.resolveActionRequest(actionRequestId, "approve", approverUserId, reason);
|
|
165
|
+
}
|
|
166
|
+
async rejectActionRequest(actionRequestId, approverUserId, reason) {
|
|
167
|
+
return this.resolveActionRequest(actionRequestId, "reject", approverUserId, reason);
|
|
168
|
+
}
|
|
169
|
+
async escalateActionRequest(actionRequestId, approverUserId, reason) {
|
|
170
|
+
return this.resolveActionRequest(actionRequestId, "escalate", approverUserId, reason);
|
|
171
|
+
}
|
|
172
|
+
async resolveActionRequest(actionRequestId, action, approverUserId, reason) {
|
|
173
|
+
return this.request("POST", `/v1/action-requests/${encodeURIComponent(actionRequestId)}/${action}`, { reason, approver_user_id: approverUserId });
|
|
174
|
+
}
|
|
175
|
+
async listPolicies() {
|
|
176
|
+
return this.request("GET", "/v1/policies");
|
|
177
|
+
}
|
|
178
|
+
async createPolicy(input) {
|
|
179
|
+
return this.request("POST", "/v1/policies", {
|
|
180
|
+
name: input.name,
|
|
181
|
+
description: input.description,
|
|
182
|
+
policy_type: input.policyType,
|
|
183
|
+
status: input.status,
|
|
184
|
+
priority: input.priority,
|
|
185
|
+
action_type: input.actionType,
|
|
186
|
+
amount_greater_than: input.amountGreaterThan,
|
|
187
|
+
resource_sensitivity: input.resourceSensitivity,
|
|
188
|
+
external_recipient: input.externalRecipient,
|
|
189
|
+
environment: input.environment,
|
|
190
|
+
decision: input.decision,
|
|
191
|
+
approver_role: input.approverRole,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
async listAuditEvents() {
|
|
195
|
+
return this.request("GET", "/v1/audit-events");
|
|
196
|
+
}
|
|
197
|
+
async listApiKeys() {
|
|
198
|
+
return this.request("GET", "/v1/api-keys");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.Auctra = Auctra;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
export declare const AUCTRA_SDK_VERSION = "0.2.1";
|
|
2
|
+
export type AgentEnvironment = "dev" | "staging" | "production";
|
|
3
|
+
export type AuthorityLevel = "low" | "medium" | "high" | "critical";
|
|
4
|
+
export type Decision = "allowed" | "blocked" | "require_approval";
|
|
5
|
+
export type PolicyType = "spending" | "data_access" | "communication" | "approval";
|
|
6
|
+
export type EvaluateActionInput = {
|
|
7
|
+
agentId: string;
|
|
8
|
+
actionType: string;
|
|
9
|
+
payload?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export type EvaluateActionResponse = {
|
|
12
|
+
decision: Decision;
|
|
13
|
+
risk_score: number;
|
|
14
|
+
reason: string;
|
|
15
|
+
delegation_id: string | null;
|
|
16
|
+
delegator: string | null;
|
|
17
|
+
sponsor: string;
|
|
18
|
+
matched_policies: string[];
|
|
19
|
+
action_request_id: string;
|
|
20
|
+
};
|
|
21
|
+
export type RequestOptions = {
|
|
22
|
+
idempotencyKey?: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
};
|
|
25
|
+
export type AuctraClientOptions = {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
maxRetries?: number;
|
|
30
|
+
fetch?: typeof fetch;
|
|
31
|
+
};
|
|
32
|
+
export type Agent = {
|
|
33
|
+
id: string;
|
|
34
|
+
identity_id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description: string | null;
|
|
37
|
+
model_provider: "openai" | "anthropic" | "gemini" | "local";
|
|
38
|
+
model_name: string;
|
|
39
|
+
environment: AgentEnvironment;
|
|
40
|
+
authority_level: AuthorityLevel;
|
|
41
|
+
status: "active" | "suspended" | "restricted" | "compromised";
|
|
42
|
+
trust_rating: number;
|
|
43
|
+
sponsor: {
|
|
44
|
+
id: string;
|
|
45
|
+
full_name: string;
|
|
46
|
+
email: string;
|
|
47
|
+
};
|
|
48
|
+
created_at: string;
|
|
49
|
+
};
|
|
50
|
+
export type CreateAgentInput = {
|
|
51
|
+
name: string;
|
|
52
|
+
modelProvider: Agent["model_provider"];
|
|
53
|
+
modelName: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
environment?: AgentEnvironment;
|
|
56
|
+
authorityLevel?: AuthorityLevel;
|
|
57
|
+
sponsorUserId?: string;
|
|
58
|
+
};
|
|
59
|
+
export type Delegation = {
|
|
60
|
+
id: string;
|
|
61
|
+
agent: {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
delegator: {
|
|
66
|
+
id: string;
|
|
67
|
+
full_name: string;
|
|
68
|
+
email: string;
|
|
69
|
+
};
|
|
70
|
+
scope: {
|
|
71
|
+
action_types: string[];
|
|
72
|
+
};
|
|
73
|
+
limits: {
|
|
74
|
+
max_amount?: number;
|
|
75
|
+
max_count?: number;
|
|
76
|
+
currency?: string;
|
|
77
|
+
environment?: AgentEnvironment;
|
|
78
|
+
};
|
|
79
|
+
valid_from: string;
|
|
80
|
+
valid_until: string;
|
|
81
|
+
status: "active" | "revoked" | "expired";
|
|
82
|
+
is_active: boolean;
|
|
83
|
+
created_at: string;
|
|
84
|
+
};
|
|
85
|
+
export type CreateDelegationInput = {
|
|
86
|
+
agentId: string;
|
|
87
|
+
actionTypes: string[];
|
|
88
|
+
validUntil: string;
|
|
89
|
+
maxAmount?: number;
|
|
90
|
+
maxCount?: number;
|
|
91
|
+
environment?: AgentEnvironment;
|
|
92
|
+
currency?: string;
|
|
93
|
+
delegatorUserId?: string;
|
|
94
|
+
};
|
|
95
|
+
export type ActionRequest = {
|
|
96
|
+
id: string;
|
|
97
|
+
agent_name: string;
|
|
98
|
+
action_type: string;
|
|
99
|
+
action_summary: string;
|
|
100
|
+
payload: Record<string, unknown>;
|
|
101
|
+
decision: string;
|
|
102
|
+
decision_reason: string | null;
|
|
103
|
+
risk_score: number;
|
|
104
|
+
delegation_id: string | null;
|
|
105
|
+
policy_ids: string[];
|
|
106
|
+
pending_approval_id: string | null;
|
|
107
|
+
created_at: string;
|
|
108
|
+
decided_at: string | null;
|
|
109
|
+
};
|
|
110
|
+
export type Policy = {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
description: string | null;
|
|
114
|
+
policy_type: PolicyType;
|
|
115
|
+
status: "active" | "draft" | "archived";
|
|
116
|
+
priority: number;
|
|
117
|
+
conditions: Record<string, unknown>;
|
|
118
|
+
actions: Record<string, unknown>;
|
|
119
|
+
created_at: string;
|
|
120
|
+
};
|
|
121
|
+
export type CreatePolicyInput = {
|
|
122
|
+
name: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
policyType: PolicyType;
|
|
125
|
+
status?: "active" | "draft";
|
|
126
|
+
priority?: number;
|
|
127
|
+
actionType?: string;
|
|
128
|
+
amountGreaterThan?: number;
|
|
129
|
+
resourceSensitivity?: "public" | "internal" | "confidential" | "pii";
|
|
130
|
+
externalRecipient?: boolean;
|
|
131
|
+
environment?: AgentEnvironment;
|
|
132
|
+
decision: "block" | "require_approval";
|
|
133
|
+
approverRole?: "owner" | "admin" | "reviewer";
|
|
134
|
+
};
|
|
135
|
+
export type AuditEvent = {
|
|
136
|
+
id: string;
|
|
137
|
+
event_type: string;
|
|
138
|
+
event_summary: string;
|
|
139
|
+
decision: string | null;
|
|
140
|
+
decision_reason: string | null;
|
|
141
|
+
authority_valid_at_action: boolean | null;
|
|
142
|
+
actor_name: string;
|
|
143
|
+
approver_name: string | null;
|
|
144
|
+
policy_applied: string | null;
|
|
145
|
+
delegation_id: string | null;
|
|
146
|
+
hash: string | null;
|
|
147
|
+
previous_hash: string | null;
|
|
148
|
+
created_at: string;
|
|
149
|
+
};
|
|
150
|
+
export type ApiKeySummary = {
|
|
151
|
+
id: string;
|
|
152
|
+
name: string;
|
|
153
|
+
key_prefix: string;
|
|
154
|
+
environment: "development" | "production";
|
|
155
|
+
permissions: string[];
|
|
156
|
+
status: "active" | "revoked";
|
|
157
|
+
last_used_at: string | null;
|
|
158
|
+
created_at: string;
|
|
159
|
+
};
|
|
160
|
+
export declare class AuctraApiError extends Error {
|
|
161
|
+
readonly status: number;
|
|
162
|
+
readonly code?: string;
|
|
163
|
+
readonly details?: unknown;
|
|
164
|
+
readonly requestId?: string;
|
|
165
|
+
constructor(message: string, options: {
|
|
166
|
+
status: number;
|
|
167
|
+
code?: string;
|
|
168
|
+
details?: unknown;
|
|
169
|
+
requestId?: string;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export declare class Auctra {
|
|
173
|
+
private readonly apiKey;
|
|
174
|
+
private readonly baseUrl;
|
|
175
|
+
private readonly timeoutMs;
|
|
176
|
+
private readonly maxRetries;
|
|
177
|
+
private readonly fetchImpl;
|
|
178
|
+
constructor(options: AuctraClientOptions);
|
|
179
|
+
private request;
|
|
180
|
+
evaluateAction(input: EvaluateActionInput, options?: RequestOptions): Promise<EvaluateActionResponse>;
|
|
181
|
+
listAgents(): Promise<{
|
|
182
|
+
agents: Agent[];
|
|
183
|
+
}>;
|
|
184
|
+
getAgent(agentId: string): Promise<{
|
|
185
|
+
agent: Agent;
|
|
186
|
+
}>;
|
|
187
|
+
createAgent(input: CreateAgentInput): Promise<{
|
|
188
|
+
agent: Agent;
|
|
189
|
+
}>;
|
|
190
|
+
listDelegations(): Promise<{
|
|
191
|
+
delegations: Delegation[];
|
|
192
|
+
}>;
|
|
193
|
+
getDelegation(delegationId: string): Promise<{
|
|
194
|
+
delegation: Delegation;
|
|
195
|
+
}>;
|
|
196
|
+
createDelegation(input: CreateDelegationInput): Promise<{
|
|
197
|
+
delegation: Delegation;
|
|
198
|
+
}>;
|
|
199
|
+
revokeDelegation(delegationId: string): Promise<{
|
|
200
|
+
ok: true;
|
|
201
|
+
}>;
|
|
202
|
+
listActionRequests(): Promise<{
|
|
203
|
+
action_requests: ActionRequest[];
|
|
204
|
+
}>;
|
|
205
|
+
approveActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
|
|
206
|
+
ok: true;
|
|
207
|
+
decision: string;
|
|
208
|
+
reason: string;
|
|
209
|
+
}>;
|
|
210
|
+
rejectActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
|
|
211
|
+
ok: true;
|
|
212
|
+
decision: string;
|
|
213
|
+
reason: string;
|
|
214
|
+
}>;
|
|
215
|
+
escalateActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<{
|
|
216
|
+
ok: true;
|
|
217
|
+
decision: string;
|
|
218
|
+
reason: string;
|
|
219
|
+
}>;
|
|
220
|
+
private resolveActionRequest;
|
|
221
|
+
listPolicies(): Promise<{
|
|
222
|
+
policies: Policy[];
|
|
223
|
+
}>;
|
|
224
|
+
createPolicy(input: CreatePolicyInput): Promise<{
|
|
225
|
+
policy: Pick<Policy, "id" | "name" | "status" | "created_at">;
|
|
226
|
+
}>;
|
|
227
|
+
listAuditEvents(): Promise<{
|
|
228
|
+
audit_events: AuditEvent[];
|
|
229
|
+
}>;
|
|
230
|
+
listApiKeys(): Promise<{
|
|
231
|
+
api_keys: ApiKeySummary[];
|
|
232
|
+
}>;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AACpE,MA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AAE,IAAI,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAA;KAAE,CAAC;IAiBvE,eAAe,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAI1D,WAAW,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;CAG5D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const AUCTRA_SDK_VERSION = "0.2.1";
|
|
1
2
|
export class AuctraApiError extends Error {
|
|
2
3
|
status;
|
|
3
4
|
code;
|
|
@@ -12,6 +13,29 @@ export class AuctraApiError extends Error {
|
|
|
12
13
|
this.requestId = options.requestId;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
16
|
+
function retryDelay(response, attempt) {
|
|
17
|
+
const retryAfter = response?.headers.get("retry-after");
|
|
18
|
+
if (retryAfter) {
|
|
19
|
+
const seconds = Number(retryAfter);
|
|
20
|
+
if (Number.isFinite(seconds))
|
|
21
|
+
return Math.min(30_000, Math.max(0, seconds * 1_000));
|
|
22
|
+
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
23
|
+
if (Number.isFinite(dateDelay))
|
|
24
|
+
return Math.min(30_000, Math.max(0, dateDelay));
|
|
25
|
+
}
|
|
26
|
+
return Math.min(5_000, 150 * 2 ** attempt);
|
|
27
|
+
}
|
|
28
|
+
function wait(ms, signal) {
|
|
29
|
+
if (signal?.aborted)
|
|
30
|
+
return Promise.reject(signal.reason);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const timeout = setTimeout(resolve, ms);
|
|
33
|
+
signal?.addEventListener("abort", () => {
|
|
34
|
+
clearTimeout(timeout);
|
|
35
|
+
reject(signal.reason);
|
|
36
|
+
}, { once: true });
|
|
37
|
+
});
|
|
38
|
+
}
|
|
15
39
|
export class Auctra {
|
|
16
40
|
apiKey;
|
|
17
41
|
baseUrl;
|
|
@@ -19,6 +43,15 @@ export class Auctra {
|
|
|
19
43
|
maxRetries;
|
|
20
44
|
fetchImpl;
|
|
21
45
|
constructor(options) {
|
|
46
|
+
if (!options.apiKey.trim())
|
|
47
|
+
throw new Error("apiKey is required");
|
|
48
|
+
if (options.timeoutMs !== undefined && options.timeoutMs <= 0) {
|
|
49
|
+
throw new Error("timeoutMs must be greater than zero");
|
|
50
|
+
}
|
|
51
|
+
if (options.maxRetries !== undefined &&
|
|
52
|
+
(!Number.isInteger(options.maxRetries) || options.maxRetries < 0)) {
|
|
53
|
+
throw new Error("maxRetries must be a non-negative integer");
|
|
54
|
+
}
|
|
22
55
|
this.apiKey = options.apiKey;
|
|
23
56
|
this.baseUrl = (options.baseUrl ?? "https://console.auctra.tech").replace(/\/$/, "");
|
|
24
57
|
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
@@ -31,28 +64,32 @@ export class Auctra {
|
|
|
31
64
|
const retryableRequest = method === "GET" || Boolean(options.idempotencyKey);
|
|
32
65
|
let lastError;
|
|
33
66
|
for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
|
|
67
|
+
if (options.signal?.aborted)
|
|
68
|
+
throw options.signal.reason;
|
|
34
69
|
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
35
70
|
const signal = options.signal
|
|
36
71
|
? AbortSignal.any([options.signal, timeoutSignal])
|
|
37
72
|
: timeoutSignal;
|
|
73
|
+
let response;
|
|
38
74
|
try {
|
|
39
|
-
|
|
75
|
+
response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
40
76
|
method,
|
|
41
77
|
signal,
|
|
42
78
|
headers: {
|
|
43
|
-
...(body ? { "content-type": "application/json" } : {}),
|
|
79
|
+
...(body !== undefined ? { "content-type": "application/json" } : {}),
|
|
44
80
|
...(options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}),
|
|
45
81
|
authorization: `Bearer ${this.apiKey}`,
|
|
46
|
-
"x-auctra-sdk-version":
|
|
82
|
+
"x-auctra-sdk-version": AUCTRA_SDK_VERSION,
|
|
47
83
|
},
|
|
48
|
-
...(body ? { body: JSON.stringify(body) } : {}),
|
|
84
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
49
85
|
});
|
|
50
86
|
const data = (await response.json().catch(() => ({})));
|
|
51
87
|
if (response.ok)
|
|
52
88
|
return data;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
89
|
+
if (retryableRequest &&
|
|
90
|
+
(response.status === 429 || response.status >= 500) &&
|
|
91
|
+
attempt < this.maxRetries) {
|
|
92
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
56
93
|
continue;
|
|
57
94
|
}
|
|
58
95
|
throw new AuctraApiError(typeof data.error === "string" ? data.error : `Auctra API error (${response.status})`, {
|
|
@@ -64,27 +101,25 @@ export class Auctra {
|
|
|
64
101
|
}
|
|
65
102
|
catch (error) {
|
|
66
103
|
lastError = error;
|
|
104
|
+
if (options.signal?.aborted)
|
|
105
|
+
throw options.signal.reason;
|
|
67
106
|
if (error instanceof AuctraApiError || !retryableRequest || attempt >= this.maxRetries) {
|
|
68
107
|
throw error;
|
|
69
108
|
}
|
|
70
|
-
await
|
|
109
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
71
110
|
}
|
|
72
111
|
}
|
|
73
112
|
throw lastError;
|
|
74
113
|
}
|
|
75
114
|
async evaluateAction(input, options = {}) {
|
|
76
115
|
const idempotencyKey = options.idempotencyKey ?? crypto.randomUUID();
|
|
77
|
-
return this.request("POST", "/v1/action-requests/evaluate", {
|
|
78
|
-
agent_id: input.agentId,
|
|
79
|
-
action_type: input.actionType,
|
|
80
|
-
payload: input.payload ?? {},
|
|
81
|
-
}, { ...options, idempotencyKey });
|
|
116
|
+
return this.request("POST", "/v1/action-requests/evaluate", { agent_id: input.agentId, action_type: input.actionType, payload: input.payload ?? {} }, { ...options, idempotencyKey });
|
|
82
117
|
}
|
|
83
118
|
async listAgents() {
|
|
84
119
|
return this.request("GET", "/v1/agents");
|
|
85
120
|
}
|
|
86
121
|
async getAgent(agentId) {
|
|
87
|
-
return this.request("GET", `/v1/agents/${agentId}`);
|
|
122
|
+
return this.request("GET", `/v1/agents/${encodeURIComponent(agentId)}`);
|
|
88
123
|
}
|
|
89
124
|
async createAgent(input) {
|
|
90
125
|
return this.request("POST", "/v1/agents", {
|
|
@@ -100,44 +135,62 @@ export class Auctra {
|
|
|
100
135
|
async listDelegations() {
|
|
101
136
|
return this.request("GET", "/v1/delegations");
|
|
102
137
|
}
|
|
138
|
+
async getDelegation(delegationId) {
|
|
139
|
+
return this.request("GET", `/v1/delegations/${encodeURIComponent(delegationId)}`);
|
|
140
|
+
}
|
|
103
141
|
async createDelegation(input) {
|
|
104
142
|
return this.request("POST", "/v1/delegations", {
|
|
105
143
|
agent_id: input.agentId,
|
|
106
144
|
action_types: input.actionTypes,
|
|
107
145
|
valid_until: input.validUntil,
|
|
108
146
|
max_amount: input.maxAmount,
|
|
147
|
+
max_count: input.maxCount,
|
|
148
|
+
environment: input.environment,
|
|
109
149
|
currency: input.currency,
|
|
110
150
|
delegator_user_id: input.delegatorUserId,
|
|
111
151
|
});
|
|
112
152
|
}
|
|
113
153
|
async revokeDelegation(delegationId) {
|
|
114
|
-
return this.request("POST", `/v1/delegations/${delegationId}/revoke`, {});
|
|
154
|
+
return this.request("POST", `/v1/delegations/${encodeURIComponent(delegationId)}/revoke`, {});
|
|
115
155
|
}
|
|
116
156
|
async listActionRequests() {
|
|
117
157
|
return this.request("GET", "/v1/action-requests");
|
|
118
158
|
}
|
|
119
159
|
async approveActionRequest(actionRequestId, approverUserId, reason) {
|
|
120
|
-
return this.
|
|
121
|
-
reason,
|
|
122
|
-
approver_user_id: approverUserId,
|
|
123
|
-
});
|
|
160
|
+
return this.resolveActionRequest(actionRequestId, "approve", approverUserId, reason);
|
|
124
161
|
}
|
|
125
162
|
async rejectActionRequest(actionRequestId, approverUserId, reason) {
|
|
126
|
-
return this.
|
|
127
|
-
reason,
|
|
128
|
-
approver_user_id: approverUserId,
|
|
129
|
-
});
|
|
163
|
+
return this.resolveActionRequest(actionRequestId, "reject", approverUserId, reason);
|
|
130
164
|
}
|
|
131
165
|
async escalateActionRequest(actionRequestId, approverUserId, reason) {
|
|
132
|
-
return this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
});
|
|
166
|
+
return this.resolveActionRequest(actionRequestId, "escalate", approverUserId, reason);
|
|
167
|
+
}
|
|
168
|
+
async resolveActionRequest(actionRequestId, action, approverUserId, reason) {
|
|
169
|
+
return this.request("POST", `/v1/action-requests/${encodeURIComponent(actionRequestId)}/${action}`, { reason, approver_user_id: approverUserId });
|
|
136
170
|
}
|
|
137
171
|
async listPolicies() {
|
|
138
172
|
return this.request("GET", "/v1/policies");
|
|
139
173
|
}
|
|
174
|
+
async createPolicy(input) {
|
|
175
|
+
return this.request("POST", "/v1/policies", {
|
|
176
|
+
name: input.name,
|
|
177
|
+
description: input.description,
|
|
178
|
+
policy_type: input.policyType,
|
|
179
|
+
status: input.status,
|
|
180
|
+
priority: input.priority,
|
|
181
|
+
action_type: input.actionType,
|
|
182
|
+
amount_greater_than: input.amountGreaterThan,
|
|
183
|
+
resource_sensitivity: input.resourceSensitivity,
|
|
184
|
+
external_recipient: input.externalRecipient,
|
|
185
|
+
environment: input.environment,
|
|
186
|
+
decision: input.decision,
|
|
187
|
+
approver_role: input.approverRole,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
140
190
|
async listAuditEvents() {
|
|
141
191
|
return this.request("GET", "/v1/audit-events");
|
|
142
192
|
}
|
|
193
|
+
async listApiKeys() {
|
|
194
|
+
return this.request("GET", "/v1/api-keys");
|
|
195
|
+
}
|
|
143
196
|
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auctra/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Authority delegation SDK for AI agents — evaluate agent actions against delegated authority and org policies",
|
|
5
5
|
"homepage": "https://auctra.tech/docs",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/Matik103/auctra/issues"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "./dist/cjs/index.js",
|
|
12
|
+
"module": "./dist/esm/index.js",
|
|
13
|
+
"types": "./dist/esm/index.d.ts",
|
|
12
14
|
"exports": {
|
|
13
15
|
".": {
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"import": "./dist/index.js"
|
|
16
|
+
"types": "./dist/esm/index.d.ts",
|
|
17
|
+
"import": "./dist/esm/index.js",
|
|
18
|
+
"require": "./dist/cjs/index.js"
|
|
16
19
|
}
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist",
|
|
20
|
-
"
|
|
23
|
+
"src",
|
|
24
|
+
"README.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"LICENSE"
|
|
21
27
|
],
|
|
22
28
|
"scripts": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
29
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
30
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/finalize-build.mjs",
|
|
31
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
32
|
+
"check": "npm run test && npm pack --dry-run",
|
|
33
|
+
"publish:local": "npm publish --access public --provenance=false",
|
|
34
|
+
"prepublishOnly": "npm run check"
|
|
25
35
|
},
|
|
26
36
|
"repository": {
|
|
27
37
|
"type": "git",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
export const AUCTRA_SDK_VERSION = "0.2.1";
|
|
2
|
+
|
|
3
|
+
export type AgentEnvironment = "dev" | "staging" | "production";
|
|
4
|
+
export type AuthorityLevel = "low" | "medium" | "high" | "critical";
|
|
5
|
+
export type Decision = "allowed" | "blocked" | "require_approval";
|
|
6
|
+
export type PolicyType = "spending" | "data_access" | "communication" | "approval";
|
|
7
|
+
|
|
8
|
+
export type EvaluateActionInput = {
|
|
9
|
+
agentId: string;
|
|
10
|
+
actionType: string;
|
|
11
|
+
payload?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type EvaluateActionResponse = {
|
|
15
|
+
decision: Decision;
|
|
16
|
+
risk_score: number;
|
|
17
|
+
reason: string;
|
|
18
|
+
delegation_id: string | null;
|
|
19
|
+
delegator: string | null;
|
|
20
|
+
sponsor: string;
|
|
21
|
+
matched_policies: string[];
|
|
22
|
+
action_request_id: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type RequestOptions = {
|
|
26
|
+
idempotencyKey?: string;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type AuctraClientOptions = {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type Agent = {
|
|
39
|
+
id: string;
|
|
40
|
+
identity_id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string | null;
|
|
43
|
+
model_provider: "openai" | "anthropic" | "gemini" | "local";
|
|
44
|
+
model_name: string;
|
|
45
|
+
environment: AgentEnvironment;
|
|
46
|
+
authority_level: AuthorityLevel;
|
|
47
|
+
status: "active" | "suspended" | "restricted" | "compromised";
|
|
48
|
+
trust_rating: number;
|
|
49
|
+
sponsor: { id: string; full_name: string; email: string };
|
|
50
|
+
created_at: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type CreateAgentInput = {
|
|
54
|
+
name: string;
|
|
55
|
+
modelProvider: Agent["model_provider"];
|
|
56
|
+
modelName: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
environment?: AgentEnvironment;
|
|
59
|
+
authorityLevel?: AuthorityLevel;
|
|
60
|
+
sponsorUserId?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type Delegation = {
|
|
64
|
+
id: string;
|
|
65
|
+
agent: { id: string; name: string };
|
|
66
|
+
delegator: { id: string; full_name: string; email: string };
|
|
67
|
+
scope: { action_types: string[] };
|
|
68
|
+
limits: {
|
|
69
|
+
max_amount?: number;
|
|
70
|
+
max_count?: number;
|
|
71
|
+
currency?: string;
|
|
72
|
+
environment?: AgentEnvironment;
|
|
73
|
+
};
|
|
74
|
+
valid_from: string;
|
|
75
|
+
valid_until: string;
|
|
76
|
+
status: "active" | "revoked" | "expired";
|
|
77
|
+
is_active: boolean;
|
|
78
|
+
created_at: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type CreateDelegationInput = {
|
|
82
|
+
agentId: string;
|
|
83
|
+
actionTypes: string[];
|
|
84
|
+
validUntil: string;
|
|
85
|
+
maxAmount?: number;
|
|
86
|
+
maxCount?: number;
|
|
87
|
+
environment?: AgentEnvironment;
|
|
88
|
+
currency?: string;
|
|
89
|
+
delegatorUserId?: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type ActionRequest = {
|
|
93
|
+
id: string;
|
|
94
|
+
agent_name: string;
|
|
95
|
+
action_type: string;
|
|
96
|
+
action_summary: string;
|
|
97
|
+
payload: Record<string, unknown>;
|
|
98
|
+
decision: string;
|
|
99
|
+
decision_reason: string | null;
|
|
100
|
+
risk_score: number;
|
|
101
|
+
delegation_id: string | null;
|
|
102
|
+
policy_ids: string[];
|
|
103
|
+
pending_approval_id: string | null;
|
|
104
|
+
created_at: string;
|
|
105
|
+
decided_at: string | null;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type Policy = {
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
description: string | null;
|
|
112
|
+
policy_type: PolicyType;
|
|
113
|
+
status: "active" | "draft" | "archived";
|
|
114
|
+
priority: number;
|
|
115
|
+
conditions: Record<string, unknown>;
|
|
116
|
+
actions: Record<string, unknown>;
|
|
117
|
+
created_at: string;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type CreatePolicyInput = {
|
|
121
|
+
name: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
policyType: PolicyType;
|
|
124
|
+
status?: "active" | "draft";
|
|
125
|
+
priority?: number;
|
|
126
|
+
actionType?: string;
|
|
127
|
+
amountGreaterThan?: number;
|
|
128
|
+
resourceSensitivity?: "public" | "internal" | "confidential" | "pii";
|
|
129
|
+
externalRecipient?: boolean;
|
|
130
|
+
environment?: AgentEnvironment;
|
|
131
|
+
decision: "block" | "require_approval";
|
|
132
|
+
approverRole?: "owner" | "admin" | "reviewer";
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type AuditEvent = {
|
|
136
|
+
id: string;
|
|
137
|
+
event_type: string;
|
|
138
|
+
event_summary: string;
|
|
139
|
+
decision: string | null;
|
|
140
|
+
decision_reason: string | null;
|
|
141
|
+
authority_valid_at_action: boolean | null;
|
|
142
|
+
actor_name: string;
|
|
143
|
+
approver_name: string | null;
|
|
144
|
+
policy_applied: string | null;
|
|
145
|
+
delegation_id: string | null;
|
|
146
|
+
hash: string | null;
|
|
147
|
+
previous_hash: string | null;
|
|
148
|
+
created_at: string;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type ApiKeySummary = {
|
|
152
|
+
id: string;
|
|
153
|
+
name: string;
|
|
154
|
+
key_prefix: string;
|
|
155
|
+
environment: "development" | "production";
|
|
156
|
+
permissions: string[];
|
|
157
|
+
status: "active" | "revoked";
|
|
158
|
+
last_used_at: string | null;
|
|
159
|
+
created_at: string;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export class AuctraApiError extends Error {
|
|
163
|
+
readonly status: number;
|
|
164
|
+
readonly code?: string;
|
|
165
|
+
readonly details?: unknown;
|
|
166
|
+
readonly requestId?: string;
|
|
167
|
+
|
|
168
|
+
constructor(
|
|
169
|
+
message: string,
|
|
170
|
+
options: { status: number; code?: string; details?: unknown; requestId?: string },
|
|
171
|
+
) {
|
|
172
|
+
super(message);
|
|
173
|
+
this.name = "AuctraApiError";
|
|
174
|
+
this.status = options.status;
|
|
175
|
+
this.code = options.code;
|
|
176
|
+
this.details = options.details;
|
|
177
|
+
this.requestId = options.requestId;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function retryDelay(response: Response | undefined, attempt: number) {
|
|
182
|
+
const retryAfter = response?.headers.get("retry-after");
|
|
183
|
+
if (retryAfter) {
|
|
184
|
+
const seconds = Number(retryAfter);
|
|
185
|
+
if (Number.isFinite(seconds)) return Math.min(30_000, Math.max(0, seconds * 1_000));
|
|
186
|
+
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
187
|
+
if (Number.isFinite(dateDelay)) return Math.min(30_000, Math.max(0, dateDelay));
|
|
188
|
+
}
|
|
189
|
+
return Math.min(5_000, 150 * 2 ** attempt);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function wait(ms: number, signal?: AbortSignal) {
|
|
193
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
194
|
+
return new Promise<void>((resolve, reject) => {
|
|
195
|
+
const timeout = setTimeout(resolve, ms);
|
|
196
|
+
signal?.addEventListener(
|
|
197
|
+
"abort",
|
|
198
|
+
() => {
|
|
199
|
+
clearTimeout(timeout);
|
|
200
|
+
reject(signal.reason);
|
|
201
|
+
},
|
|
202
|
+
{ once: true },
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export class Auctra {
|
|
208
|
+
private readonly apiKey: string;
|
|
209
|
+
private readonly baseUrl: string;
|
|
210
|
+
private readonly timeoutMs: number;
|
|
211
|
+
private readonly maxRetries: number;
|
|
212
|
+
private readonly fetchImpl: typeof fetch;
|
|
213
|
+
|
|
214
|
+
constructor(options: AuctraClientOptions) {
|
|
215
|
+
if (!options.apiKey.trim()) throw new Error("apiKey is required");
|
|
216
|
+
if (options.timeoutMs !== undefined && options.timeoutMs <= 0) {
|
|
217
|
+
throw new Error("timeoutMs must be greater than zero");
|
|
218
|
+
}
|
|
219
|
+
if (
|
|
220
|
+
options.maxRetries !== undefined &&
|
|
221
|
+
(!Number.isInteger(options.maxRetries) || options.maxRetries < 0)
|
|
222
|
+
) {
|
|
223
|
+
throw new Error("maxRetries must be a non-negative integer");
|
|
224
|
+
}
|
|
225
|
+
this.apiKey = options.apiKey;
|
|
226
|
+
this.baseUrl = (options.baseUrl ?? "https://console.auctra.tech").replace(/\/$/, "");
|
|
227
|
+
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
228
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
229
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
230
|
+
if (!this.fetchImpl) throw new Error("A fetch implementation is required");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private async request<T>(
|
|
234
|
+
method: string,
|
|
235
|
+
path: string,
|
|
236
|
+
body?: unknown,
|
|
237
|
+
options: RequestOptions = {},
|
|
238
|
+
): Promise<T> {
|
|
239
|
+
const retryableRequest = method === "GET" || Boolean(options.idempotencyKey);
|
|
240
|
+
let lastError: unknown;
|
|
241
|
+
|
|
242
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
|
|
243
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
244
|
+
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
245
|
+
const signal = options.signal
|
|
246
|
+
? AbortSignal.any([options.signal, timeoutSignal])
|
|
247
|
+
: timeoutSignal;
|
|
248
|
+
let response: Response | undefined;
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
252
|
+
method,
|
|
253
|
+
signal,
|
|
254
|
+
headers: {
|
|
255
|
+
...(body !== undefined ? { "content-type": "application/json" } : {}),
|
|
256
|
+
...(options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}),
|
|
257
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
258
|
+
"x-auctra-sdk-version": AUCTRA_SDK_VERSION,
|
|
259
|
+
},
|
|
260
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const data = (await response.json().catch(() => ({}))) as Record<string, unknown>;
|
|
264
|
+
if (response.ok) return data as T;
|
|
265
|
+
|
|
266
|
+
if (
|
|
267
|
+
retryableRequest &&
|
|
268
|
+
(response.status === 429 || response.status >= 500) &&
|
|
269
|
+
attempt < this.maxRetries
|
|
270
|
+
) {
|
|
271
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
throw new AuctraApiError(
|
|
276
|
+
typeof data.error === "string" ? data.error : `Auctra API error (${response.status})`,
|
|
277
|
+
{
|
|
278
|
+
status: response.status,
|
|
279
|
+
code: typeof data.code === "string" ? data.code : undefined,
|
|
280
|
+
details: data.details,
|
|
281
|
+
requestId: response.headers.get("x-request-id") ?? undefined,
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
lastError = error;
|
|
286
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
287
|
+
if (error instanceof AuctraApiError || !retryableRequest || attempt >= this.maxRetries) {
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
await wait(retryDelay(response, attempt), options.signal);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
throw lastError;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async evaluateAction(
|
|
298
|
+
input: EvaluateActionInput,
|
|
299
|
+
options: RequestOptions = {},
|
|
300
|
+
): Promise<EvaluateActionResponse> {
|
|
301
|
+
const idempotencyKey = options.idempotencyKey ?? crypto.randomUUID();
|
|
302
|
+
return this.request(
|
|
303
|
+
"POST",
|
|
304
|
+
"/v1/action-requests/evaluate",
|
|
305
|
+
{ agent_id: input.agentId, action_type: input.actionType, payload: input.payload ?? {} },
|
|
306
|
+
{ ...options, idempotencyKey },
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async listAgents(): Promise<{ agents: Agent[] }> {
|
|
311
|
+
return this.request("GET", "/v1/agents");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async getAgent(agentId: string): Promise<{ agent: Agent }> {
|
|
315
|
+
return this.request("GET", `/v1/agents/${encodeURIComponent(agentId)}`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async createAgent(input: CreateAgentInput): Promise<{ agent: Agent }> {
|
|
319
|
+
return this.request("POST", "/v1/agents", {
|
|
320
|
+
name: input.name,
|
|
321
|
+
model_provider: input.modelProvider,
|
|
322
|
+
model_name: input.modelName,
|
|
323
|
+
description: input.description,
|
|
324
|
+
environment: input.environment,
|
|
325
|
+
authority_level: input.authorityLevel,
|
|
326
|
+
sponsor_user_id: input.sponsorUserId,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async listDelegations(): Promise<{ delegations: Delegation[] }> {
|
|
331
|
+
return this.request("GET", "/v1/delegations");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async getDelegation(delegationId: string): Promise<{ delegation: Delegation }> {
|
|
335
|
+
return this.request("GET", `/v1/delegations/${encodeURIComponent(delegationId)}`);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async createDelegation(input: CreateDelegationInput): Promise<{ delegation: Delegation }> {
|
|
339
|
+
return this.request("POST", "/v1/delegations", {
|
|
340
|
+
agent_id: input.agentId,
|
|
341
|
+
action_types: input.actionTypes,
|
|
342
|
+
valid_until: input.validUntil,
|
|
343
|
+
max_amount: input.maxAmount,
|
|
344
|
+
max_count: input.maxCount,
|
|
345
|
+
environment: input.environment,
|
|
346
|
+
currency: input.currency,
|
|
347
|
+
delegator_user_id: input.delegatorUserId,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async revokeDelegation(delegationId: string): Promise<{ ok: true }> {
|
|
352
|
+
return this.request("POST", `/v1/delegations/${encodeURIComponent(delegationId)}/revoke`, {});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async listActionRequests(): Promise<{ action_requests: ActionRequest[] }> {
|
|
356
|
+
return this.request("GET", "/v1/action-requests");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async approveActionRequest(actionRequestId: string, approverUserId: string, reason?: string) {
|
|
360
|
+
return this.resolveActionRequest(actionRequestId, "approve", approverUserId, reason);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async rejectActionRequest(actionRequestId: string, approverUserId: string, reason?: string) {
|
|
364
|
+
return this.resolveActionRequest(actionRequestId, "reject", approverUserId, reason);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async escalateActionRequest(actionRequestId: string, approverUserId: string, reason?: string) {
|
|
368
|
+
return this.resolveActionRequest(actionRequestId, "escalate", approverUserId, reason);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private async resolveActionRequest(
|
|
372
|
+
actionRequestId: string,
|
|
373
|
+
action: "approve" | "reject" | "escalate",
|
|
374
|
+
approverUserId: string,
|
|
375
|
+
reason?: string,
|
|
376
|
+
): Promise<{ ok: true; decision: string; reason: string }> {
|
|
377
|
+
return this.request(
|
|
378
|
+
"POST",
|
|
379
|
+
`/v1/action-requests/${encodeURIComponent(actionRequestId)}/${action}`,
|
|
380
|
+
{ reason, approver_user_id: approverUserId },
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async listPolicies(): Promise<{ policies: Policy[] }> {
|
|
385
|
+
return this.request("GET", "/v1/policies");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async createPolicy(
|
|
389
|
+
input: CreatePolicyInput,
|
|
390
|
+
): Promise<{ policy: Pick<Policy, "id" | "name" | "status" | "created_at"> }> {
|
|
391
|
+
return this.request("POST", "/v1/policies", {
|
|
392
|
+
name: input.name,
|
|
393
|
+
description: input.description,
|
|
394
|
+
policy_type: input.policyType,
|
|
395
|
+
status: input.status,
|
|
396
|
+
priority: input.priority,
|
|
397
|
+
action_type: input.actionType,
|
|
398
|
+
amount_greater_than: input.amountGreaterThan,
|
|
399
|
+
resource_sensitivity: input.resourceSensitivity,
|
|
400
|
+
external_recipient: input.externalRecipient,
|
|
401
|
+
environment: input.environment,
|
|
402
|
+
decision: input.decision,
|
|
403
|
+
approver_role: input.approverRole,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async listAuditEvents(): Promise<{ audit_events: AuditEvent[] }> {
|
|
408
|
+
return this.request("GET", "/v1/audit-events");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async listApiKeys(): Promise<{ api_keys: ApiKeySummary[] }> {
|
|
412
|
+
return this.request("GET", "/v1/api-keys");
|
|
413
|
+
}
|
|
414
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
export type EvaluateActionInput = {
|
|
2
|
-
agentId: string;
|
|
3
|
-
actionType: string;
|
|
4
|
-
payload?: Record<string, unknown>;
|
|
5
|
-
};
|
|
6
|
-
export type EvaluateActionResponse = {
|
|
7
|
-
decision: "allowed" | "blocked" | "require_approval";
|
|
8
|
-
risk_score: number;
|
|
9
|
-
reason: string;
|
|
10
|
-
delegation_id: string | null;
|
|
11
|
-
delegator: string | null;
|
|
12
|
-
sponsor: string;
|
|
13
|
-
matched_policies: string[];
|
|
14
|
-
action_request_id: string;
|
|
15
|
-
};
|
|
16
|
-
export type AuctraClientOptions = {
|
|
17
|
-
apiKey: string;
|
|
18
|
-
baseUrl?: string;
|
|
19
|
-
timeoutMs?: number;
|
|
20
|
-
maxRetries?: number;
|
|
21
|
-
fetch?: typeof fetch;
|
|
22
|
-
};
|
|
23
|
-
export type Agent = {
|
|
24
|
-
id: string;
|
|
25
|
-
identity_id: string;
|
|
26
|
-
name: string;
|
|
27
|
-
description: string | null;
|
|
28
|
-
model_provider: string;
|
|
29
|
-
model_name: string;
|
|
30
|
-
environment: "dev" | "staging" | "production";
|
|
31
|
-
authority_level: "low" | "medium" | "high" | "critical";
|
|
32
|
-
status: "active" | "suspended" | "restricted" | "compromised";
|
|
33
|
-
trust_rating: number;
|
|
34
|
-
sponsor: {
|
|
35
|
-
id: string;
|
|
36
|
-
full_name: string;
|
|
37
|
-
email: string;
|
|
38
|
-
};
|
|
39
|
-
created_at: string;
|
|
40
|
-
};
|
|
41
|
-
export type Delegation = {
|
|
42
|
-
id: string;
|
|
43
|
-
agent: {
|
|
44
|
-
id: string;
|
|
45
|
-
name: string;
|
|
46
|
-
};
|
|
47
|
-
delegator: {
|
|
48
|
-
id: string;
|
|
49
|
-
full_name: string;
|
|
50
|
-
email: string;
|
|
51
|
-
};
|
|
52
|
-
scope: {
|
|
53
|
-
action_types: string[];
|
|
54
|
-
};
|
|
55
|
-
limits: {
|
|
56
|
-
max_amount?: number;
|
|
57
|
-
currency?: string;
|
|
58
|
-
};
|
|
59
|
-
valid_from: string;
|
|
60
|
-
valid_until: string;
|
|
61
|
-
status: "active" | "revoked" | "expired";
|
|
62
|
-
is_active: boolean;
|
|
63
|
-
created_at: string;
|
|
64
|
-
};
|
|
65
|
-
export declare class AuctraApiError extends Error {
|
|
66
|
-
readonly status: number;
|
|
67
|
-
readonly code?: string;
|
|
68
|
-
readonly details?: unknown;
|
|
69
|
-
readonly requestId?: string;
|
|
70
|
-
constructor(message: string, options: {
|
|
71
|
-
status: number;
|
|
72
|
-
code?: string;
|
|
73
|
-
details?: unknown;
|
|
74
|
-
requestId?: string;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export declare class Auctra {
|
|
78
|
-
private apiKey;
|
|
79
|
-
private baseUrl;
|
|
80
|
-
private timeoutMs;
|
|
81
|
-
private maxRetries;
|
|
82
|
-
private fetchImpl;
|
|
83
|
-
constructor(options: AuctraClientOptions);
|
|
84
|
-
private request;
|
|
85
|
-
evaluateAction(input: EvaluateActionInput, options?: {
|
|
86
|
-
idempotencyKey?: string;
|
|
87
|
-
signal?: AbortSignal;
|
|
88
|
-
}): Promise<EvaluateActionResponse>;
|
|
89
|
-
listAgents(): Promise<{
|
|
90
|
-
agents: Agent[];
|
|
91
|
-
}>;
|
|
92
|
-
getAgent(agentId: string): Promise<{
|
|
93
|
-
agent: Agent;
|
|
94
|
-
}>;
|
|
95
|
-
createAgent(input: {
|
|
96
|
-
name: string;
|
|
97
|
-
modelProvider: string;
|
|
98
|
-
modelName: string;
|
|
99
|
-
description?: string;
|
|
100
|
-
environment?: string;
|
|
101
|
-
authorityLevel?: string;
|
|
102
|
-
sponsorUserId?: string;
|
|
103
|
-
}): Promise<unknown>;
|
|
104
|
-
listDelegations(): Promise<{
|
|
105
|
-
delegations: Delegation[];
|
|
106
|
-
}>;
|
|
107
|
-
createDelegation(input: {
|
|
108
|
-
agentId: string;
|
|
109
|
-
actionTypes: string[];
|
|
110
|
-
validUntil: string;
|
|
111
|
-
maxAmount?: number;
|
|
112
|
-
currency?: string;
|
|
113
|
-
delegatorUserId?: string;
|
|
114
|
-
}): Promise<unknown>;
|
|
115
|
-
revokeDelegation(delegationId: string): Promise<unknown>;
|
|
116
|
-
listActionRequests(): Promise<{
|
|
117
|
-
action_requests: unknown[];
|
|
118
|
-
}>;
|
|
119
|
-
approveActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<unknown>;
|
|
120
|
-
rejectActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<unknown>;
|
|
121
|
-
escalateActionRequest(actionRequestId: string, approverUserId: string, reason?: string): Promise<unknown>;
|
|
122
|
-
listPolicies(): Promise<{
|
|
123
|
-
policies: unknown[];
|
|
124
|
-
}>;
|
|
125
|
-
listAuditEvents(): Promise<{
|
|
126
|
-
audit_events: unknown[];
|
|
127
|
-
}>;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,SAAS,GAAG,SAAS,GAAG,kBAAkB,CAAC;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,KAAK,GAAG,SAAS,GAAG,YAAY,CAAC;IAC9C,eAAe,EAAE,K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