@auctra/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +41 -4
- package/dist/cjs/index.js +247 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.d.ts +355 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +242 -0
- package/package.json +18 -8
- package/src/index.ts +569 -0
- package/dist/index.d.ts +0 -129
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -143
package/dist/index.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
export class AuctraApiError extends Error {
|
|
2
|
-
status;
|
|
3
|
-
code;
|
|
4
|
-
details;
|
|
5
|
-
requestId;
|
|
6
|
-
constructor(message, options) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "AuctraApiError";
|
|
9
|
-
this.status = options.status;
|
|
10
|
-
this.code = options.code;
|
|
11
|
-
this.details = options.details;
|
|
12
|
-
this.requestId = options.requestId;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export class Auctra {
|
|
16
|
-
apiKey;
|
|
17
|
-
baseUrl;
|
|
18
|
-
timeoutMs;
|
|
19
|
-
maxRetries;
|
|
20
|
-
fetchImpl;
|
|
21
|
-
constructor(options) {
|
|
22
|
-
this.apiKey = options.apiKey;
|
|
23
|
-
this.baseUrl = (options.baseUrl ?? "https://console.auctra.tech").replace(/\/$/, "");
|
|
24
|
-
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
25
|
-
this.maxRetries = options.maxRetries ?? 2;
|
|
26
|
-
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
27
|
-
if (!this.fetchImpl)
|
|
28
|
-
throw new Error("A fetch implementation is required");
|
|
29
|
-
}
|
|
30
|
-
async request(method, path, body, options = {}) {
|
|
31
|
-
const retryableRequest = method === "GET" || Boolean(options.idempotencyKey);
|
|
32
|
-
let lastError;
|
|
33
|
-
for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
|
|
34
|
-
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
35
|
-
const signal = options.signal
|
|
36
|
-
? AbortSignal.any([options.signal, timeoutSignal])
|
|
37
|
-
: timeoutSignal;
|
|
38
|
-
try {
|
|
39
|
-
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
40
|
-
method,
|
|
41
|
-
signal,
|
|
42
|
-
headers: {
|
|
43
|
-
...(body ? { "content-type": "application/json" } : {}),
|
|
44
|
-
...(options.idempotencyKey ? { "idempotency-key": options.idempotencyKey } : {}),
|
|
45
|
-
authorization: `Bearer ${this.apiKey}`,
|
|
46
|
-
"x-auctra-sdk-version": "0.2",
|
|
47
|
-
},
|
|
48
|
-
...(body ? { body: JSON.stringify(body) } : {}),
|
|
49
|
-
});
|
|
50
|
-
const data = (await response.json().catch(() => ({})));
|
|
51
|
-
if (response.ok)
|
|
52
|
-
return data;
|
|
53
|
-
const retryableResponse = response.status === 429 || response.status >= 500;
|
|
54
|
-
if (retryableRequest && retryableResponse && attempt < this.maxRetries) {
|
|
55
|
-
await new Promise((resolve) => setTimeout(resolve, 150 * 2 ** attempt));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
throw new AuctraApiError(typeof data.error === "string" ? data.error : `Auctra API error (${response.status})`, {
|
|
59
|
-
status: response.status,
|
|
60
|
-
code: typeof data.code === "string" ? data.code : undefined,
|
|
61
|
-
details: data.details,
|
|
62
|
-
requestId: response.headers.get("x-request-id") ?? undefined,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
lastError = error;
|
|
67
|
-
if (error instanceof AuctraApiError || !retryableRequest || attempt >= this.maxRetries) {
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
await new Promise((resolve) => setTimeout(resolve, 150 * 2 ** attempt));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
throw lastError;
|
|
74
|
-
}
|
|
75
|
-
async evaluateAction(input, options = {}) {
|
|
76
|
-
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 });
|
|
82
|
-
}
|
|
83
|
-
async listAgents() {
|
|
84
|
-
return this.request("GET", "/v1/agents");
|
|
85
|
-
}
|
|
86
|
-
async getAgent(agentId) {
|
|
87
|
-
return this.request("GET", `/v1/agents/${agentId}`);
|
|
88
|
-
}
|
|
89
|
-
async createAgent(input) {
|
|
90
|
-
return this.request("POST", "/v1/agents", {
|
|
91
|
-
name: input.name,
|
|
92
|
-
model_provider: input.modelProvider,
|
|
93
|
-
model_name: input.modelName,
|
|
94
|
-
description: input.description,
|
|
95
|
-
environment: input.environment,
|
|
96
|
-
authority_level: input.authorityLevel,
|
|
97
|
-
sponsor_user_id: input.sponsorUserId,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
async listDelegations() {
|
|
101
|
-
return this.request("GET", "/v1/delegations");
|
|
102
|
-
}
|
|
103
|
-
async createDelegation(input) {
|
|
104
|
-
return this.request("POST", "/v1/delegations", {
|
|
105
|
-
agent_id: input.agentId,
|
|
106
|
-
action_types: input.actionTypes,
|
|
107
|
-
valid_until: input.validUntil,
|
|
108
|
-
max_amount: input.maxAmount,
|
|
109
|
-
currency: input.currency,
|
|
110
|
-
delegator_user_id: input.delegatorUserId,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
async revokeDelegation(delegationId) {
|
|
114
|
-
return this.request("POST", `/v1/delegations/${delegationId}/revoke`, {});
|
|
115
|
-
}
|
|
116
|
-
async listActionRequests() {
|
|
117
|
-
return this.request("GET", "/v1/action-requests");
|
|
118
|
-
}
|
|
119
|
-
async approveActionRequest(actionRequestId, approverUserId, reason) {
|
|
120
|
-
return this.request("POST", `/v1/action-requests/${actionRequestId}/approve`, {
|
|
121
|
-
reason,
|
|
122
|
-
approver_user_id: approverUserId,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
async rejectActionRequest(actionRequestId, approverUserId, reason) {
|
|
126
|
-
return this.request("POST", `/v1/action-requests/${actionRequestId}/reject`, {
|
|
127
|
-
reason,
|
|
128
|
-
approver_user_id: approverUserId,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
async escalateActionRequest(actionRequestId, approverUserId, reason) {
|
|
132
|
-
return this.request("POST", `/v1/action-requests/${actionRequestId}/escalate`, {
|
|
133
|
-
reason,
|
|
134
|
-
approver_user_id: approverUserId,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async listPolicies() {
|
|
138
|
-
return this.request("GET", "/v1/policies");
|
|
139
|
-
}
|
|
140
|
-
async listAuditEvents() {
|
|
141
|
-
return this.request("GET", "/v1/audit-events");
|
|
142
|
-
}
|
|
143
|
-
}
|