roe-typescript 0.1.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/LICENSE +201 -0
- package/README.md +189 -0
- package/dist/api/agents.d.ts +87 -0
- package/dist/api/agents.js +263 -0
- package/dist/auth.d.ts +6 -0
- package/dist/auth.js +11 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +18 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +43 -0
- package/dist/exceptions.d.ts +25 -0
- package/dist/exceptions.js +73 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/integration_test.js +686 -0
- package/dist/models/agent.d.ts +78 -0
- package/dist/models/agent.js +40 -0
- package/dist/models/file.d.ts +30 -0
- package/dist/models/file.js +85 -0
- package/dist/models/job.d.ts +37 -0
- package/dist/models/job.js +133 -0
- package/dist/models/responses.d.ts +71 -0
- package/dist/models/responses.js +36 -0
- package/dist/models/user.d.ts +6 -0
- package/dist/models/user.js +1 -0
- package/dist/src/api/agents.js +269 -0
- package/dist/src/auth.js +15 -0
- package/dist/src/client.js +22 -0
- package/dist/src/config.js +47 -0
- package/dist/src/exceptions.js +86 -0
- package/dist/src/models/agent.js +45 -0
- package/dist/src/models/file.js +92 -0
- package/dist/src/models/job.js +138 -0
- package/dist/src/models/responses.js +42 -0
- package/dist/src/models/user.js +2 -0
- package/dist/src/utils/fileDetection.js +46 -0
- package/dist/src/utils/httpClient.js +236 -0
- package/dist/src/utils/pagination.js +18 -0
- package/dist/utils/fileDetection.d.ts +11 -0
- package/dist/utils/fileDetection.js +38 -0
- package/dist/utils/httpClient.d.ts +30 -0
- package/dist/utils/httpClient.js +229 -0
- package/dist/utils/pagination.d.ts +3 -0
- package/dist/utils/pagination.js +14 -0
- package/package.json +36 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { PaginationHelper } from "../utils/pagination";
|
|
2
|
+
import { isUuidString } from "../utils/fileDetection";
|
|
3
|
+
import { BadRequestError, RoeAPIException } from "../exceptions";
|
|
4
|
+
import { AgentVersionWithApi, BaseAgentWithApi, } from "../models/agent";
|
|
5
|
+
import { Job, JobBatch } from "../models/job";
|
|
6
|
+
/**
|
|
7
|
+
* Validates that a value is a valid UUID string.
|
|
8
|
+
* @throws BadRequestError if the value is not a valid UUID
|
|
9
|
+
*/
|
|
10
|
+
function validateUuid(value, fieldName) {
|
|
11
|
+
if (!isUuidString(value)) {
|
|
12
|
+
throw new BadRequestError(`Invalid ${fieldName}: "${value}" is not a valid UUID`, 400);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class AgentVersionsAPI {
|
|
16
|
+
constructor(agentsApi) {
|
|
17
|
+
this.agentsApi = agentsApi;
|
|
18
|
+
}
|
|
19
|
+
get http() {
|
|
20
|
+
return this.agentsApi.httpClient;
|
|
21
|
+
}
|
|
22
|
+
async list(agentId) {
|
|
23
|
+
validateUuid(agentId, "agentId");
|
|
24
|
+
const data = await this.http.get(`/v1/agents/${agentId}/versions/`);
|
|
25
|
+
return data.map((v) => this.wrap(v));
|
|
26
|
+
}
|
|
27
|
+
async retrieve(agentId, versionId, getSupportsEval) {
|
|
28
|
+
validateUuid(agentId, "agentId");
|
|
29
|
+
validateUuid(versionId, "versionId");
|
|
30
|
+
const params = getSupportsEval === undefined ? undefined : { get_supports_eval: String(getSupportsEval).toLowerCase() };
|
|
31
|
+
const data = await this.http.get(`/v1/agents/${agentId}/versions/${versionId}/`, params);
|
|
32
|
+
return this.wrap(data);
|
|
33
|
+
}
|
|
34
|
+
async retrieveCurrent(agentId) {
|
|
35
|
+
validateUuid(agentId, "agentId");
|
|
36
|
+
const data = await this.http.get(`/v1/agents/${agentId}/versions/current/`);
|
|
37
|
+
return this.wrap(data);
|
|
38
|
+
}
|
|
39
|
+
async create(params) {
|
|
40
|
+
validateUuid(params.agentId, "agentId");
|
|
41
|
+
const payload = {
|
|
42
|
+
input_definitions: params.inputDefinitions ?? [],
|
|
43
|
+
engine_config: params.engineConfig ?? {},
|
|
44
|
+
};
|
|
45
|
+
if (params.versionName !== undefined)
|
|
46
|
+
payload.version_name = params.versionName;
|
|
47
|
+
if (params.description !== undefined)
|
|
48
|
+
payload.description = params.description;
|
|
49
|
+
const data = await this.http.post({
|
|
50
|
+
url: `/v1/agents/${params.agentId}/versions/`,
|
|
51
|
+
json: payload,
|
|
52
|
+
});
|
|
53
|
+
return this.retrieve(params.agentId, data.id);
|
|
54
|
+
}
|
|
55
|
+
async update(agentId, versionId, updates) {
|
|
56
|
+
validateUuid(agentId, "agentId");
|
|
57
|
+
validateUuid(versionId, "versionId");
|
|
58
|
+
const payload = {};
|
|
59
|
+
if (updates.versionName !== undefined)
|
|
60
|
+
payload.version_name = updates.versionName;
|
|
61
|
+
if (updates.description !== undefined)
|
|
62
|
+
payload.description = updates.description;
|
|
63
|
+
await this.http.put(`/v1/agents/${agentId}/versions/${versionId}/`, payload);
|
|
64
|
+
}
|
|
65
|
+
async delete(agentId, versionId) {
|
|
66
|
+
validateUuid(agentId, "agentId");
|
|
67
|
+
validateUuid(versionId, "versionId");
|
|
68
|
+
await this.http.delete(`/v1/agents/${agentId}/versions/${versionId}/`);
|
|
69
|
+
}
|
|
70
|
+
wrap(data) {
|
|
71
|
+
const obj = new AgentVersionWithApi(data);
|
|
72
|
+
obj.setAgentsApi(this.agentsApi);
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class AgentJobsAPI {
|
|
77
|
+
constructor(agentsApi) {
|
|
78
|
+
this.agentsApi = agentsApi;
|
|
79
|
+
}
|
|
80
|
+
get http() {
|
|
81
|
+
return this.agentsApi.httpClient;
|
|
82
|
+
}
|
|
83
|
+
async retrieveStatus(jobId) {
|
|
84
|
+
validateUuid(jobId, "jobId");
|
|
85
|
+
return this.http.get(`/v1/agents/jobs/${jobId}/status/`);
|
|
86
|
+
}
|
|
87
|
+
async retrieveResult(jobId) {
|
|
88
|
+
validateUuid(jobId, "jobId");
|
|
89
|
+
return this.http.get(`/v1/agents/jobs/${jobId}/result/`);
|
|
90
|
+
}
|
|
91
|
+
async retrieveStatusMany(jobIds) {
|
|
92
|
+
const results = [];
|
|
93
|
+
for (const chunk of this.iterChunks(jobIds, AgentJobsAPI.MAX_BATCH_SIZE)) {
|
|
94
|
+
if (!chunk.length)
|
|
95
|
+
continue;
|
|
96
|
+
const data = await this.http.post({
|
|
97
|
+
url: "/v1/agents/jobs/statuses/",
|
|
98
|
+
json: { job_ids: chunk },
|
|
99
|
+
});
|
|
100
|
+
results.push(...data);
|
|
101
|
+
}
|
|
102
|
+
return results;
|
|
103
|
+
}
|
|
104
|
+
async retrieveResultMany(jobIds) {
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const chunk of this.iterChunks(jobIds, AgentJobsAPI.MAX_BATCH_SIZE)) {
|
|
107
|
+
if (!chunk.length)
|
|
108
|
+
continue;
|
|
109
|
+
const data = await this.http.post({
|
|
110
|
+
url: "/v1/agents/jobs/results/",
|
|
111
|
+
json: { job_ids: chunk },
|
|
112
|
+
});
|
|
113
|
+
results.push(...data);
|
|
114
|
+
}
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
async downloadReference(jobId, resourceId, asAttachment = false) {
|
|
118
|
+
validateUuid(jobId, "jobId");
|
|
119
|
+
validateUuid(resourceId, "resourceId");
|
|
120
|
+
const params = asAttachment ? { download: "true" } : undefined;
|
|
121
|
+
return this.http.getBytes(`/v1/agents/jobs/${jobId}/references/${resourceId}/`, params);
|
|
122
|
+
}
|
|
123
|
+
async deleteData(jobId) {
|
|
124
|
+
validateUuid(jobId, "jobId");
|
|
125
|
+
return this.http.post({
|
|
126
|
+
url: `/v1/agents/jobs/${jobId}/delete-data/`,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
*iterChunks(items, size) {
|
|
130
|
+
for (let i = 0; i < items.length; i += size) {
|
|
131
|
+
yield items.slice(i, i + size);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
AgentJobsAPI.MAX_BATCH_SIZE = 1000;
|
|
136
|
+
export class AgentsAPI {
|
|
137
|
+
constructor(config, httpClient) {
|
|
138
|
+
this.config = config;
|
|
139
|
+
this.httpClient = httpClient;
|
|
140
|
+
this.versions = new AgentVersionsAPI(this);
|
|
141
|
+
this.jobs = new AgentJobsAPI(this);
|
|
142
|
+
}
|
|
143
|
+
wrapBase(data) {
|
|
144
|
+
const obj = new BaseAgentWithApi(data);
|
|
145
|
+
obj.setAgentsApi(this);
|
|
146
|
+
return obj;
|
|
147
|
+
}
|
|
148
|
+
async list(params) {
|
|
149
|
+
const query = PaginationHelper.buildQueryParams(this.config.organizationId, params?.page, params?.pageSize);
|
|
150
|
+
const resp = await this.httpClient.get("/v1/agents/", query);
|
|
151
|
+
const wrapped = resp.results.map((a) => this.wrapBase(a));
|
|
152
|
+
return { ...resp, results: wrapped };
|
|
153
|
+
}
|
|
154
|
+
async retrieve(agentId) {
|
|
155
|
+
validateUuid(agentId, "agentId");
|
|
156
|
+
const data = await this.httpClient.get(`/v1/agents/${agentId}/`);
|
|
157
|
+
return this.wrapBase(data);
|
|
158
|
+
}
|
|
159
|
+
async create(params) {
|
|
160
|
+
const payload = {
|
|
161
|
+
name: params.name,
|
|
162
|
+
engine_class_id: params.engineClassId,
|
|
163
|
+
organization_id: this.config.organizationId,
|
|
164
|
+
input_definitions: params.inputDefinitions ?? [],
|
|
165
|
+
engine_config: params.engineConfig ?? {},
|
|
166
|
+
};
|
|
167
|
+
if (params.versionName !== undefined)
|
|
168
|
+
payload.version_name = params.versionName;
|
|
169
|
+
if (params.description !== undefined)
|
|
170
|
+
payload.description = params.description;
|
|
171
|
+
const data = await this.httpClient.post({ url: "/v1/agents/", json: payload });
|
|
172
|
+
return this.wrapBase(data);
|
|
173
|
+
}
|
|
174
|
+
async update(agentId, updates) {
|
|
175
|
+
validateUuid(agentId, "agentId");
|
|
176
|
+
const payload = {};
|
|
177
|
+
if (updates.name !== undefined)
|
|
178
|
+
payload.name = updates.name;
|
|
179
|
+
if (updates.disableCache !== undefined)
|
|
180
|
+
payload.disable_cache = updates.disableCache;
|
|
181
|
+
if (updates.cacheFailedJobs !== undefined)
|
|
182
|
+
payload.cache_failed_jobs = updates.cacheFailedJobs;
|
|
183
|
+
const data = await this.httpClient.put(`/v1/agents/${agentId}/`, payload);
|
|
184
|
+
return this.wrapBase(data);
|
|
185
|
+
}
|
|
186
|
+
async delete(agentId) {
|
|
187
|
+
validateUuid(agentId, "agentId");
|
|
188
|
+
await this.httpClient.delete(`/v1/agents/${agentId}/`);
|
|
189
|
+
}
|
|
190
|
+
async duplicate(agentId) {
|
|
191
|
+
validateUuid(agentId, "agentId");
|
|
192
|
+
const data = await this.httpClient.post({
|
|
193
|
+
url: `/v1/agents/${agentId}/duplicate/`,
|
|
194
|
+
});
|
|
195
|
+
return this.wrapBase(data.base_agent);
|
|
196
|
+
}
|
|
197
|
+
async run(params) {
|
|
198
|
+
validateUuid(params.agentId, "agentId");
|
|
199
|
+
const response = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${params.agentId}/async/`, params.inputs);
|
|
200
|
+
// Handle both string response and object response formats
|
|
201
|
+
const jobId = typeof response === "string" ? response : response?.job_id;
|
|
202
|
+
if (!jobId || typeof jobId !== "string") {
|
|
203
|
+
throw new RoeAPIException(`Invalid job ID returned from API: ${JSON.stringify(response)}`);
|
|
204
|
+
}
|
|
205
|
+
if (!isUuidString(jobId)) {
|
|
206
|
+
throw new RoeAPIException(`Invalid job ID format returned from API: ${jobId}`);
|
|
207
|
+
}
|
|
208
|
+
return new Job({ agentsApi: this, jobId, timeoutSeconds: params.timeoutSeconds });
|
|
209
|
+
}
|
|
210
|
+
async runMany(params) {
|
|
211
|
+
validateUuid(params.agentId, "agentId");
|
|
212
|
+
const allJobIds = [];
|
|
213
|
+
for (const chunk of this.iterChunks(params.batchInputs, AgentsAPI.MAX_BATCH_SIZE)) {
|
|
214
|
+
if (!chunk.length)
|
|
215
|
+
continue;
|
|
216
|
+
const resp = await this.httpClient.post({
|
|
217
|
+
url: `/v1/agents/run/${params.agentId}/async/many/`,
|
|
218
|
+
json: { inputs: chunk },
|
|
219
|
+
});
|
|
220
|
+
// Validate each returned job ID
|
|
221
|
+
for (const jobId of resp) {
|
|
222
|
+
if (!jobId || typeof jobId !== "string") {
|
|
223
|
+
throw new RoeAPIException(`Invalid job ID returned from batch API: ${JSON.stringify(jobId)}`);
|
|
224
|
+
}
|
|
225
|
+
if (!isUuidString(jobId)) {
|
|
226
|
+
throw new RoeAPIException(`Invalid job ID format returned from batch API: ${jobId}`);
|
|
227
|
+
}
|
|
228
|
+
allJobIds.push(jobId);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return new JobBatch({ agentsApi: this, jobIds: allJobIds, timeoutSeconds: params.timeoutSeconds });
|
|
232
|
+
}
|
|
233
|
+
async runSync(agentId, inputs) {
|
|
234
|
+
validateUuid(agentId, "agentId");
|
|
235
|
+
const resp = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${agentId}/`, inputs);
|
|
236
|
+
return resp;
|
|
237
|
+
}
|
|
238
|
+
async runVersion(params) {
|
|
239
|
+
validateUuid(params.agentId, "agentId");
|
|
240
|
+
validateUuid(params.versionId, "versionId");
|
|
241
|
+
const response = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${params.agentId}/versions/${params.versionId}/async/`, params.inputs);
|
|
242
|
+
// Handle both string response and object response formats
|
|
243
|
+
const jobId = typeof response === "string" ? response : response?.job_id;
|
|
244
|
+
if (!jobId || typeof jobId !== "string") {
|
|
245
|
+
throw new RoeAPIException(`Invalid job ID returned from API: ${JSON.stringify(response)}`);
|
|
246
|
+
}
|
|
247
|
+
if (!isUuidString(jobId)) {
|
|
248
|
+
throw new RoeAPIException(`Invalid job ID format returned from API: ${jobId}`);
|
|
249
|
+
}
|
|
250
|
+
return new Job({ agentsApi: this, jobId, timeoutSeconds: params.timeoutSeconds });
|
|
251
|
+
}
|
|
252
|
+
async runVersionSync(agentId, versionId, inputs) {
|
|
253
|
+
validateUuid(agentId, "agentId");
|
|
254
|
+
validateUuid(versionId, "versionId");
|
|
255
|
+
return this.httpClient.postWithDynamicInputs(`/v1/agents/run/${agentId}/versions/${versionId}/`, inputs);
|
|
256
|
+
}
|
|
257
|
+
*iterChunks(items, size) {
|
|
258
|
+
for (let i = 0; i < items.length; i += size) {
|
|
259
|
+
yield items.slice(i, i + size);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
AgentsAPI.MAX_BATCH_SIZE = 1000;
|
package/dist/auth.d.ts
ADDED
package/dist/auth.js
ADDED
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AgentsAPI } from "./api/agents";
|
|
2
|
+
import { RoeAuth } from "./auth";
|
|
3
|
+
import { RoeConfig, RoeConfigInput } from "./config";
|
|
4
|
+
import { RoeHTTPClient } from "./utils/httpClient";
|
|
5
|
+
export declare class RoeClient {
|
|
6
|
+
readonly config: RoeConfig;
|
|
7
|
+
readonly auth: RoeAuth;
|
|
8
|
+
readonly httpClient: RoeHTTPClient;
|
|
9
|
+
private readonly _agents;
|
|
10
|
+
constructor(input?: RoeConfigInput);
|
|
11
|
+
get agents(): AgentsAPI;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentsAPI } from "./api/agents";
|
|
2
|
+
import { RoeAuth } from "./auth";
|
|
3
|
+
import { RoeConfig } from "./config";
|
|
4
|
+
import { RoeHTTPClient } from "./utils/httpClient";
|
|
5
|
+
export class RoeClient {
|
|
6
|
+
constructor(input = {}) {
|
|
7
|
+
this.config = RoeConfig.fromEnv(input);
|
|
8
|
+
this.auth = new RoeAuth(this.config);
|
|
9
|
+
this.httpClient = new RoeHTTPClient(this.config, this.auth);
|
|
10
|
+
this._agents = new AgentsAPI(this.config, this.httpClient);
|
|
11
|
+
}
|
|
12
|
+
get agents() {
|
|
13
|
+
return this._agents;
|
|
14
|
+
}
|
|
15
|
+
close() {
|
|
16
|
+
this.httpClient.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type RoeConfigInput = {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
organizationId?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
timeoutSeconds?: number;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class RoeConfig {
|
|
10
|
+
readonly apiKey: string;
|
|
11
|
+
readonly organizationId: string;
|
|
12
|
+
readonly baseUrl: string;
|
|
13
|
+
readonly timeoutMs: number;
|
|
14
|
+
readonly maxRetries: number;
|
|
15
|
+
private constructor();
|
|
16
|
+
static fromEnv(input?: RoeConfigInput): RoeConfig;
|
|
17
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class RoeConfig {
|
|
2
|
+
constructor(opts) {
|
|
3
|
+
this.apiKey = opts.apiKey;
|
|
4
|
+
this.organizationId = opts.organizationId;
|
|
5
|
+
this.baseUrl = opts.baseUrl;
|
|
6
|
+
this.timeoutMs = opts.timeoutMs;
|
|
7
|
+
this.maxRetries = opts.maxRetries;
|
|
8
|
+
}
|
|
9
|
+
static fromEnv(input = {}) {
|
|
10
|
+
const apiKey = input.apiKey ?? process.env.ROE_API_KEY;
|
|
11
|
+
const organizationId = input.organizationId ?? process.env.ROE_ORGANIZATION_ID;
|
|
12
|
+
const baseUrl = input.baseUrl ?? process.env.ROE_BASE_URL ?? "https://api.roe-ai.com";
|
|
13
|
+
// Parse ROE_TIMEOUT with NaN check to avoid poisoning timeoutMs
|
|
14
|
+
const timeoutSecondsEnvRaw = process.env.ROE_TIMEOUT ? Number(process.env.ROE_TIMEOUT) : undefined;
|
|
15
|
+
const timeoutSecondsEnv = timeoutSecondsEnvRaw !== undefined && !Number.isNaN(timeoutSecondsEnvRaw)
|
|
16
|
+
? timeoutSecondsEnvRaw
|
|
17
|
+
: undefined;
|
|
18
|
+
const timeoutMs = input.timeoutMs ??
|
|
19
|
+
(input.timeoutSeconds !== undefined
|
|
20
|
+
? input.timeoutSeconds * 1000
|
|
21
|
+
: timeoutSecondsEnv !== undefined
|
|
22
|
+
? timeoutSecondsEnv * 1000
|
|
23
|
+
: 60000);
|
|
24
|
+
const envMaxRetries = process.env.ROE_MAX_RETRIES;
|
|
25
|
+
const parsedEnvMaxRetries = envMaxRetries !== undefined && !Number.isNaN(Number(envMaxRetries))
|
|
26
|
+
? Number(envMaxRetries)
|
|
27
|
+
: undefined;
|
|
28
|
+
const maxRetries = input.maxRetries ?? parsedEnvMaxRetries ?? 3;
|
|
29
|
+
if (!apiKey) {
|
|
30
|
+
throw new Error("API key is required. Provide it in constructor or set ROE_API_KEY.");
|
|
31
|
+
}
|
|
32
|
+
if (!organizationId) {
|
|
33
|
+
throw new Error("Organization ID is required. Provide it in constructor or set ROE_ORGANIZATION_ID.");
|
|
34
|
+
}
|
|
35
|
+
return new RoeConfig({
|
|
36
|
+
apiKey,
|
|
37
|
+
organizationId,
|
|
38
|
+
baseUrl,
|
|
39
|
+
timeoutMs,
|
|
40
|
+
maxRetries,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class RoeAPIException extends Error {
|
|
2
|
+
readonly statusCode?: number;
|
|
3
|
+
readonly response?: Record<string, unknown> | null;
|
|
4
|
+
constructor(message: string, statusCode?: number, response?: Record<string, unknown> | null);
|
|
5
|
+
}
|
|
6
|
+
export declare class BadRequestError extends RoeAPIException {
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthenticationError extends RoeAPIException {
|
|
9
|
+
}
|
|
10
|
+
export declare class InsufficientCreditsError extends RoeAPIException {
|
|
11
|
+
}
|
|
12
|
+
export declare class ForbiddenError extends RoeAPIException {
|
|
13
|
+
}
|
|
14
|
+
export declare class NotFoundError extends RoeAPIException {
|
|
15
|
+
}
|
|
16
|
+
export declare class RateLimitError extends RoeAPIException {
|
|
17
|
+
}
|
|
18
|
+
export declare class ServerError extends RoeAPIException {
|
|
19
|
+
}
|
|
20
|
+
export declare function getExceptionForStatusCode(status: number): typeof RoeAPIException;
|
|
21
|
+
/**
|
|
22
|
+
* Extracts error message from various API response formats.
|
|
23
|
+
* Handles: { detail: string }, { error: string }, { message: string }, or raw string.
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractErrorMessage(data: unknown, statusCode: number): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export class RoeAPIException extends Error {
|
|
2
|
+
constructor(message, statusCode, response) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
this.statusCode = statusCode;
|
|
6
|
+
this.response = response;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class BadRequestError extends RoeAPIException {
|
|
10
|
+
}
|
|
11
|
+
export class AuthenticationError extends RoeAPIException {
|
|
12
|
+
}
|
|
13
|
+
export class InsufficientCreditsError extends RoeAPIException {
|
|
14
|
+
}
|
|
15
|
+
export class ForbiddenError extends RoeAPIException {
|
|
16
|
+
}
|
|
17
|
+
export class NotFoundError extends RoeAPIException {
|
|
18
|
+
}
|
|
19
|
+
export class RateLimitError extends RoeAPIException {
|
|
20
|
+
}
|
|
21
|
+
export class ServerError extends RoeAPIException {
|
|
22
|
+
}
|
|
23
|
+
export function getExceptionForStatusCode(status) {
|
|
24
|
+
const map = {
|
|
25
|
+
400: BadRequestError,
|
|
26
|
+
401: AuthenticationError,
|
|
27
|
+
402: InsufficientCreditsError,
|
|
28
|
+
403: ForbiddenError,
|
|
29
|
+
404: NotFoundError,
|
|
30
|
+
429: RateLimitError,
|
|
31
|
+
};
|
|
32
|
+
if (map[status])
|
|
33
|
+
return map[status];
|
|
34
|
+
if (status >= 500)
|
|
35
|
+
return ServerError;
|
|
36
|
+
return RoeAPIException;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extracts error message from various API response formats.
|
|
40
|
+
* Handles: { detail: string }, { error: string }, { message: string }, or raw string.
|
|
41
|
+
*/
|
|
42
|
+
export function extractErrorMessage(data, statusCode) {
|
|
43
|
+
if (typeof data === "string") {
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
if (typeof data === "object" && data !== null) {
|
|
47
|
+
// Try common error message field names
|
|
48
|
+
const obj = data;
|
|
49
|
+
if (typeof obj.detail === "string")
|
|
50
|
+
return obj.detail;
|
|
51
|
+
if (typeof obj.error === "string")
|
|
52
|
+
return obj.error;
|
|
53
|
+
if (typeof obj.message === "string")
|
|
54
|
+
return obj.message;
|
|
55
|
+
// Handle nested error object
|
|
56
|
+
if (typeof obj.error === "object" && obj.error !== null) {
|
|
57
|
+
const errObj = obj.error;
|
|
58
|
+
if (typeof errObj.message === "string")
|
|
59
|
+
return errObj.message;
|
|
60
|
+
}
|
|
61
|
+
// Handle array of errors
|
|
62
|
+
if (Array.isArray(obj.errors) && obj.errors.length > 0) {
|
|
63
|
+
const firstError = obj.errors[0];
|
|
64
|
+
if (typeof firstError === "string")
|
|
65
|
+
return firstError;
|
|
66
|
+
if (typeof firstError === "object" && firstError !== null && typeof firstError.message === "string") {
|
|
67
|
+
return firstError.message;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Fallback to generic message
|
|
72
|
+
return `HTTP ${statusCode} error`;
|
|
73
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { RoeClient } from "./client";
|
|
2
|
+
export { RoeConfig } from "./config";
|
|
3
|
+
export type { RoeConfigInput } from "./config";
|
|
4
|
+
export { RoeAuth } from "./auth";
|
|
5
|
+
export * from "./exceptions";
|
|
6
|
+
export * from "./api/agents";
|
|
7
|
+
export * from "./models/agent";
|
|
8
|
+
export * from "./models/job";
|
|
9
|
+
export * from "./models/responses";
|
|
10
|
+
export * from "./models/file";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { RoeClient } from "./client";
|
|
2
|
+
export { RoeConfig } from "./config";
|
|
3
|
+
export { RoeAuth } from "./auth";
|
|
4
|
+
export * from "./exceptions";
|
|
5
|
+
export * from "./api/agents";
|
|
6
|
+
export * from "./models/agent";
|
|
7
|
+
export * from "./models/job";
|
|
8
|
+
export * from "./models/responses";
|
|
9
|
+
export * from "./models/file";
|