roe-typescript 0.1.3 → 1.0.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.
@@ -1,12 +1,7 @@
1
- import { PaginationHelper } from "../utils/pagination.js";
2
1
  import { isUuidString } from "../utils/fileDetection.js";
2
+ import { postDynamicInputs } from "../utils/dynamicInputs.js";
3
3
  import { BadRequestError, RoeAPIException } from "../exceptions.js";
4
- import { AgentVersionWithApi, BaseAgentWithApi, } from "../models/agent.js";
5
4
  import { Job, JobBatch } from "../models/job.js";
6
- /**
7
- * Validates that a value is a valid UUID string.
8
- * @throws BadRequestError if the value is not a valid UUID
9
- */
10
5
  function validateUuid(value, fieldName) {
11
6
  if (!isUuidString(value)) {
12
7
  throw new BadRequestError(`Invalid ${fieldName}: "${value}" is not a valid UUID`, 400);
@@ -16,88 +11,137 @@ export class AgentVersionsAPI {
16
11
  constructor(agentsApi) {
17
12
  this.agentsApi = agentsApi;
18
13
  }
19
- get http() {
20
- return this.agentsApi.httpClient;
14
+ get raw() {
15
+ return this.agentsApi.raw;
16
+ }
17
+ get organizationId() {
18
+ return this.agentsApi.config.organizationId;
21
19
  }
22
20
  async list(agentId) {
23
21
  validateUuid(agentId, "agentId");
24
- const data = await this.http.get(`/v1/agents/${agentId}/versions/`);
25
- return data.map((v) => this.wrap(v));
22
+ const { data } = await this.raw.GET("/v1/agents/{agent_id}/versions/", {
23
+ params: {
24
+ path: { agent_id: agentId },
25
+ query: { organization_id: this.organizationId },
26
+ },
27
+ });
28
+ return (data ?? []);
26
29
  }
27
30
  async retrieve(agentId, versionId, getSupportsEval) {
28
31
  validateUuid(agentId, "agentId");
29
32
  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
+ const query = { organization_id: this.organizationId };
34
+ if (getSupportsEval !== undefined)
35
+ query.get_supports_eval = String(getSupportsEval).toLowerCase();
36
+ const { data } = await this.raw.GET("/v1/agents/{agent_id}/versions/{agent_version_id}/", {
37
+ params: {
38
+ path: { agent_id: agentId, agent_version_id: versionId },
39
+ query: query,
40
+ },
41
+ });
42
+ return data;
33
43
  }
34
44
  async retrieveCurrent(agentId) {
35
45
  validateUuid(agentId, "agentId");
36
- const data = await this.http.get(`/v1/agents/${agentId}/versions/current/`);
37
- return this.wrap(data);
46
+ const { data } = await this.raw.GET("/v1/agents/{agent_id}/versions/current/", {
47
+ params: {
48
+ path: { agent_id: agentId },
49
+ query: { organization_id: this.organizationId },
50
+ },
51
+ });
52
+ return data;
38
53
  }
39
54
  async create(params) {
40
55
  validateUuid(params.agentId, "agentId");
41
- const payload = {
42
- input_definitions: params.inputDefinitions ?? [],
43
- engine_config: params.engineConfig ?? {},
56
+ const body = {
57
+ input_definitions: (params.inputDefinitions ?? []),
58
+ engine_config: (params.engineConfig ?? {}),
44
59
  };
45
60
  if (params.versionName !== undefined)
46
- payload.version_name = params.versionName;
61
+ body.version_name = params.versionName;
47
62
  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,
63
+ body.description = params.description;
64
+ const { data } = await this.raw.POST("/v1/agents/{agent_id}/versions/", {
65
+ params: {
66
+ path: { agent_id: params.agentId },
67
+ query: { organization_id: this.organizationId },
68
+ },
69
+ body,
52
70
  });
71
+ if (!data?.id) {
72
+ throw new RoeAPIException(`Unexpected response from server: ${JSON.stringify(data)}`);
73
+ }
74
+ // POST returns a partial create payload; re-fetch to get the full version.
53
75
  return this.retrieve(params.agentId, data.id);
54
76
  }
55
77
  async update(agentId, versionId, updates) {
56
78
  validateUuid(agentId, "agentId");
57
79
  validateUuid(versionId, "versionId");
58
- const payload = {};
80
+ const body = {};
59
81
  if (updates.versionName !== undefined)
60
- payload.version_name = updates.versionName;
82
+ body.version_name = updates.versionName;
61
83
  if (updates.description !== undefined)
62
- payload.description = updates.description;
63
- await this.http.put(`/v1/agents/${agentId}/versions/${versionId}/`, payload);
84
+ body.description = updates.description;
85
+ await this.raw.PATCH("/v1/agents/{agent_id}/versions/{agent_version_id}/", {
86
+ params: {
87
+ path: { agent_id: agentId, agent_version_id: versionId },
88
+ query: { organization_id: this.organizationId },
89
+ },
90
+ body,
91
+ });
64
92
  }
65
93
  async delete(agentId, versionId) {
66
94
  validateUuid(agentId, "agentId");
67
95
  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;
96
+ await this.raw.DELETE("/v1/agents/{agent_id}/versions/{agent_version_id}/", {
97
+ params: {
98
+ path: { agent_id: agentId, agent_version_id: versionId },
99
+ query: { organization_id: this.organizationId },
100
+ },
101
+ });
74
102
  }
75
103
  }
76
104
  export class AgentJobsAPI {
77
105
  constructor(agentsApi) {
78
106
  this.agentsApi = agentsApi;
79
107
  }
80
- get http() {
81
- return this.agentsApi.httpClient;
108
+ get raw() {
109
+ return this.agentsApi.raw;
110
+ }
111
+ get organizationId() {
112
+ return this.agentsApi.config.organizationId;
82
113
  }
83
114
  async retrieveStatus(jobId) {
84
115
  validateUuid(jobId, "jobId");
85
- return this.http.get(`/v1/agents/jobs/${jobId}/status/`);
116
+ const { data } = await this.raw.GET("/v1/agents/jobs/{job_id}/status/", {
117
+ params: {
118
+ path: { job_id: jobId },
119
+ query: { organization_id: this.organizationId },
120
+ },
121
+ });
122
+ return data;
86
123
  }
87
124
  async retrieveResult(jobId) {
88
125
  validateUuid(jobId, "jobId");
89
- return this.http.get(`/v1/agents/jobs/${jobId}/result/`);
126
+ const { data } = await this.raw.GET("/v1/agents/jobs/{agent_job_id}/result/", {
127
+ params: {
128
+ path: { agent_job_id: jobId },
129
+ query: { organization_id: this.organizationId },
130
+ },
131
+ });
132
+ return data;
90
133
  }
91
134
  async retrieveStatusMany(jobIds) {
92
135
  const results = [];
93
136
  for (const chunk of this.iterChunks(jobIds, AgentJobsAPI.MAX_BATCH_SIZE)) {
94
137
  if (!chunk.length)
95
138
  continue;
96
- const data = await this.http.post({
97
- url: "/v1/agents/jobs/statuses/",
98
- json: { job_ids: chunk },
139
+ const { data } = await this.raw.POST("/v1/agents/jobs/statuses/", {
140
+ params: { query: { organization_id: this.organizationId } },
141
+ body: { job_ids: chunk },
99
142
  });
100
- results.push(...data);
143
+ if (data)
144
+ results.push(...data);
101
145
  }
102
146
  return results;
103
147
  }
@@ -106,33 +150,64 @@ export class AgentJobsAPI {
106
150
  for (const chunk of this.iterChunks(jobIds, AgentJobsAPI.MAX_BATCH_SIZE)) {
107
151
  if (!chunk.length)
108
152
  continue;
109
- const data = await this.http.post({
110
- url: "/v1/agents/jobs/results/",
111
- json: { job_ids: chunk },
153
+ const { data } = await this.raw.POST("/v1/agents/jobs/results/", {
154
+ params: { query: { organization_id: this.organizationId } },
155
+ body: { job_ids: chunk },
112
156
  });
113
- results.push(...data);
157
+ if (Array.isArray(data)) {
158
+ results.push(...data);
159
+ }
160
+ else if (data?.results) {
161
+ results.push(...data.results);
162
+ }
114
163
  }
115
164
  return results;
116
165
  }
117
166
  async downloadReference(jobId, resourceId, asAttachment = false) {
118
167
  validateUuid(jobId, "jobId");
119
- // resourceId is a filename/identifier, not a UUID no validation needed
120
- const params = asAttachment ? { download: "true" } : undefined;
121
- return this.http.getBytes(`/v1/agents/jobs/${jobId}/references/${resourceId}/`, params);
168
+ // The endpoint streams binary; openapi-fetch's typed GET expects a JSON
169
+ // response per the spec, so we use parseAs:"arrayBuffer" to skip JSON
170
+ // parsing and read raw bytes.
171
+ const query = { organization_id: this.organizationId };
172
+ if (asAttachment)
173
+ query.download = "true";
174
+ const result = await this.raw.GET("/v1/agents/jobs/{agent_job_id}/references/{resource_id}/", {
175
+ params: {
176
+ path: { agent_job_id: jobId, resource_id: resourceId },
177
+ query,
178
+ },
179
+ parseAs: "arrayBuffer",
180
+ });
181
+ const buf = result.data ?? new ArrayBuffer(0);
182
+ return Buffer.from(buf);
122
183
  }
123
184
  async cancel(jobId) {
124
185
  validateUuid(jobId, "jobId");
125
- await this.http.post({ url: `/v1/agents/jobs/${jobId}/cancel/` });
186
+ await this.raw.POST("/v1/agents/jobs/{job_id}/cancel/", {
187
+ params: {
188
+ path: { job_id: jobId },
189
+ query: { organization_id: this.organizationId },
190
+ },
191
+ });
126
192
  }
127
193
  async cancelAll(agentId) {
128
194
  validateUuid(agentId, "agentId");
129
- await this.http.post({ url: `/v1/agents/${agentId}/jobs/cancel-all/` });
195
+ await this.raw.POST("/v1/agents/{agent_id}/jobs/cancel-all/", {
196
+ params: {
197
+ path: { agent_id: agentId },
198
+ query: { organization_id: this.organizationId },
199
+ },
200
+ });
130
201
  }
131
202
  async deleteData(jobId) {
132
203
  validateUuid(jobId, "jobId");
133
- return this.http.post({
134
- url: `/v1/agents/jobs/${jobId}/delete-data/`,
204
+ const { data } = await this.raw.POST("/v1/agents/jobs/{job_id}/delete-data/", {
205
+ params: {
206
+ path: { job_id: jobId },
207
+ query: { organization_id: this.organizationId },
208
+ },
135
209
  });
210
+ return data;
136
211
  }
137
212
  *iterChunks(items, size) {
138
213
  for (let i = 0; i < items.length; i += size) {
@@ -142,77 +217,93 @@ export class AgentJobsAPI {
142
217
  }
143
218
  AgentJobsAPI.MAX_BATCH_SIZE = 1000;
144
219
  export class AgentsAPI {
145
- constructor(config, httpClient) {
220
+ constructor(config, raw) {
146
221
  this.config = config;
147
- this.httpClient = httpClient;
222
+ this.raw = raw;
148
223
  this.versions = new AgentVersionsAPI(this);
149
224
  this.jobs = new AgentJobsAPI(this);
150
225
  }
151
- wrapBase(data) {
152
- const obj = new BaseAgentWithApi(data);
153
- obj.setAgentsApi(this);
154
- return obj;
155
- }
156
226
  async list(params) {
157
- const query = PaginationHelper.buildQueryParams(this.config.organizationId, params?.page, params?.pageSize);
158
- const resp = await this.httpClient.get("/v1/agents/", query);
159
- const wrapped = resp.results.map((a) => this.wrapBase(a));
160
- return { ...resp, results: wrapped };
227
+ const { data } = await this.raw.GET("/v1/agents/", {
228
+ params: {
229
+ query: {
230
+ organization_id: this.config.organizationId,
231
+ page: params?.page,
232
+ page_size: params?.pageSize,
233
+ },
234
+ },
235
+ });
236
+ return data;
161
237
  }
162
238
  async retrieve(agentId) {
163
239
  validateUuid(agentId, "agentId");
164
- const data = await this.httpClient.get(`/v1/agents/${agentId}/`);
165
- return this.wrapBase(data);
240
+ const { data } = await this.raw.GET("/v1/agents/{agent_id}/", {
241
+ params: {
242
+ path: { agent_id: agentId },
243
+ query: { organization_id: this.config.organizationId },
244
+ },
245
+ });
246
+ return data;
166
247
  }
167
248
  async create(params) {
168
- const payload = {
249
+ const body = {
169
250
  name: params.name,
170
251
  engine_class_id: params.engineClassId,
171
252
  organization_id: this.config.organizationId,
172
- input_definitions: params.inputDefinitions ?? [],
173
- engine_config: params.engineConfig ?? {},
253
+ input_definitions: (params.inputDefinitions ?? []),
254
+ engine_config: (params.engineConfig ?? {}),
174
255
  };
175
256
  if (params.versionName !== undefined)
176
- payload.version_name = params.versionName;
257
+ body.version_name = params.versionName;
177
258
  if (params.description !== undefined)
178
- payload.description = params.description;
179
- const data = await this.httpClient.post({ url: "/v1/agents/", json: payload });
180
- return this.wrapBase(data);
259
+ body.description = params.description;
260
+ const { data } = await this.raw.POST("/v1/agents/", {
261
+ params: { query: { organization_id: this.config.organizationId } },
262
+ body,
263
+ });
264
+ return data;
181
265
  }
182
266
  async update(agentId, updates) {
183
267
  validateUuid(agentId, "agentId");
184
- const payload = {};
268
+ const body = {};
185
269
  if (updates.name !== undefined)
186
- payload.name = updates.name;
270
+ body.name = updates.name;
187
271
  if (updates.disableCache !== undefined)
188
- payload.disable_cache = updates.disableCache;
272
+ body.disable_cache = updates.disableCache;
189
273
  if (updates.cacheFailedJobs !== undefined)
190
- payload.cache_failed_jobs = updates.cacheFailedJobs;
191
- const data = await this.httpClient.put(`/v1/agents/${agentId}/`, payload);
192
- return this.wrapBase(data);
274
+ body.cache_failed_jobs = updates.cacheFailedJobs;
275
+ const { data } = await this.raw.PATCH("/v1/agents/{agent_id}/", {
276
+ params: {
277
+ path: { agent_id: agentId },
278
+ query: { organization_id: this.config.organizationId },
279
+ },
280
+ body,
281
+ });
282
+ return data;
193
283
  }
194
284
  async delete(agentId) {
195
285
  validateUuid(agentId, "agentId");
196
- await this.httpClient.delete(`/v1/agents/${agentId}/`);
286
+ await this.raw.DELETE("/v1/agents/{agent_id}/", {
287
+ params: {
288
+ path: { agent_id: agentId },
289
+ query: { organization_id: this.config.organizationId },
290
+ },
291
+ });
197
292
  }
198
293
  async duplicate(agentId) {
199
294
  validateUuid(agentId, "agentId");
200
- const data = await this.httpClient.post({
201
- url: `/v1/agents/${agentId}/duplicate/`,
295
+ const { data } = await this.raw.POST("/v1/agents/{agent_id}/duplicate/", {
296
+ params: {
297
+ path: { agent_id: agentId },
298
+ query: { organization_id: this.config.organizationId },
299
+ },
202
300
  });
203
- return this.wrapBase(data.base_agent);
301
+ return data;
204
302
  }
205
303
  async run(params) {
206
304
  validateUuid(params.agentId, "agentId");
207
- const response = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${params.agentId}/async/`, params.inputs, undefined, params.metadata);
208
- // Handle both string response and object response formats
209
- const jobId = typeof response === "string" ? response : response?.job_id;
210
- if (!jobId || typeof jobId !== "string") {
211
- throw new RoeAPIException(`Invalid job ID returned from API: ${JSON.stringify(response)}`);
212
- }
213
- if (!isUuidString(jobId)) {
214
- throw new RoeAPIException(`Invalid job ID format returned from API: ${jobId}`);
215
- }
305
+ const response = await postDynamicInputs(this.raw, "/v1/agents/run/{agent_id}/async/", { agent_id: params.agentId }, { organization_id: this.config.organizationId }, params.inputs, params.metadata, this.config.maxRetries);
306
+ const jobId = this.extractJobId(response);
216
307
  return new Job({ agentsApi: this, jobId, timeoutSeconds: params.timeoutSeconds });
217
308
  }
218
309
  async runMany(params) {
@@ -221,21 +312,23 @@ export class AgentsAPI {
221
312
  for (const chunk of this.iterChunks(params.batchInputs, AgentsAPI.MAX_BATCH_SIZE)) {
222
313
  if (!chunk.length)
223
314
  continue;
224
- const json = { inputs: chunk };
315
+ // Generated request type only models { inputs }, but the backend also
316
+ // accepts a sibling `metadata` field — attach it via a serializer cast.
317
+ const body = { inputs: chunk };
225
318
  if (params.metadata !== undefined)
226
- json.metadata = params.metadata;
227
- const resp = await this.httpClient.post({
228
- url: `/v1/agents/run/${params.agentId}/async/many/`,
229
- json,
319
+ body.metadata = params.metadata;
320
+ const { data } = await this.raw.POST("/v1/agents/run/{agent_id}/async/many/", {
321
+ params: {
322
+ path: { agent_id: params.agentId },
323
+ query: { organization_id: this.config.organizationId },
324
+ },
325
+ body: body,
230
326
  });
231
- // Validate each returned job ID
232
- for (const jobId of resp) {
233
- if (!jobId || typeof jobId !== "string") {
327
+ const ids = Array.isArray(data) ? data : [];
328
+ for (const jobId of ids) {
329
+ if (typeof jobId !== "string" || !isUuidString(jobId)) {
234
330
  throw new RoeAPIException(`Invalid job ID returned from batch API: ${JSON.stringify(jobId)}`);
235
331
  }
236
- if (!isUuidString(jobId)) {
237
- throw new RoeAPIException(`Invalid job ID format returned from batch API: ${jobId}`);
238
- }
239
332
  allJobIds.push(jobId);
240
333
  }
241
334
  }
@@ -243,27 +336,33 @@ export class AgentsAPI {
243
336
  }
244
337
  async runSync(agentId, inputs, metadata) {
245
338
  validateUuid(agentId, "agentId");
246
- const resp = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${agentId}/`, inputs, undefined, metadata);
247
- return resp;
339
+ return postDynamicInputs(this.raw, "/v1/agents/run/{agent_id}/", { agent_id: agentId }, { organization_id: this.config.organizationId }, inputs, metadata, this.config.maxRetries);
248
340
  }
249
341
  async runVersion(params) {
250
342
  validateUuid(params.agentId, "agentId");
251
343
  validateUuid(params.versionId, "versionId");
252
- const response = await this.httpClient.postWithDynamicInputs(`/v1/agents/run/${params.agentId}/versions/${params.versionId}/async/`, params.inputs, undefined, params.metadata);
253
- // Handle both string response and object response formats
254
- const jobId = typeof response === "string" ? response : response?.job_id;
255
- if (!jobId || typeof jobId !== "string") {
256
- throw new RoeAPIException(`Invalid job ID returned from API: ${JSON.stringify(response)}`);
257
- }
258
- if (!isUuidString(jobId)) {
259
- throw new RoeAPIException(`Invalid job ID format returned from API: ${jobId}`);
260
- }
344
+ const response = await postDynamicInputs(this.raw, "/v1/agents/run/{agent_id}/versions/{agent_version_id}/async/", { agent_id: params.agentId, agent_version_id: params.versionId }, { organization_id: this.config.organizationId }, params.inputs, params.metadata, this.config.maxRetries);
345
+ const jobId = this.extractJobId(response);
261
346
  return new Job({ agentsApi: this, jobId, timeoutSeconds: params.timeoutSeconds });
262
347
  }
263
348
  async runVersionSync(agentId, versionId, inputs, metadata) {
264
349
  validateUuid(agentId, "agentId");
265
350
  validateUuid(versionId, "versionId");
266
- return this.httpClient.postWithDynamicInputs(`/v1/agents/run/${agentId}/versions/${versionId}/`, inputs, undefined, metadata);
351
+ return postDynamicInputs(this.raw, "/v1/agents/run/{agent_id}/versions/{agent_version_id}/", { agent_id: agentId, agent_version_id: versionId }, { organization_id: this.config.organizationId }, inputs, metadata, this.config.maxRetries);
352
+ }
353
+ extractJobId(response) {
354
+ let jobId;
355
+ if (typeof response === "string") {
356
+ jobId = response;
357
+ }
358
+ else if (response && typeof response === "object") {
359
+ const obj = response;
360
+ jobId = obj.job_id ?? obj.id;
361
+ }
362
+ if (typeof jobId !== "string" || !isUuidString(jobId)) {
363
+ throw new RoeAPIException(`Invalid job ID returned from API: ${JSON.stringify(response)}`);
364
+ }
365
+ return jobId;
267
366
  }
268
367
  *iterChunks(items, size) {
269
368
  for (let i = 0; i < items.length; i += size) {
@@ -1,11 +1,16 @@
1
1
  import { RoeConfig } from "../config.js";
2
- import { RoeHTTPClient } from "../utils/httpClient.js";
3
- import { PaginatedResponse } from "../models/responses.js";
4
- import { Policy, PolicyVersion } from "../models/policy.js";
2
+ import type { RoeRawClient } from "../generated/client.js";
3
+ import type { components } from "../generated/schema.js";
4
+ type Policy = components["schemas"]["Policy"];
5
+ type CreatePolicy = components["schemas"]["CreatePolicy"];
6
+ type UpdatePolicy = components["schemas"]["UpdatePolicy"];
7
+ type PolicyVersion = components["schemas"]["PolicyVersion"];
8
+ type PaginatedPolicyList = components["schemas"]["PaginatedPolicyList"];
5
9
  export declare class PolicyVersionsAPI {
6
10
  private readonly policiesApi;
7
11
  constructor(policiesApi: PoliciesAPI);
8
- private get http();
12
+ private get raw();
13
+ private get organizationId();
9
14
  list(policyId: string): Promise<PolicyVersion[]>;
10
15
  retrieve(policyId: string, versionId: string): Promise<PolicyVersion>;
11
16
  create(params: {
@@ -17,23 +22,24 @@ export declare class PolicyVersionsAPI {
17
22
  }
18
23
  export declare class PoliciesAPI {
19
24
  readonly config: RoeConfig;
20
- readonly httpClient: RoeHTTPClient;
25
+ readonly raw: RoeRawClient;
21
26
  readonly versions: PolicyVersionsAPI;
22
- constructor(config: RoeConfig, httpClient: RoeHTTPClient);
27
+ constructor(config: RoeConfig, raw: RoeRawClient);
23
28
  list(params?: {
24
29
  page?: number;
25
30
  pageSize?: number;
26
- }): Promise<PaginatedResponse<Policy>>;
31
+ }): Promise<PaginatedPolicyList>;
27
32
  retrieve(policyId: string): Promise<Policy>;
28
33
  create(params: {
29
34
  name: string;
30
35
  content: Record<string, unknown>;
31
36
  description?: string;
32
37
  versionName?: string;
33
- }): Promise<Policy>;
38
+ }): Promise<CreatePolicy>;
34
39
  update(policyId: string, updates: {
35
40
  name?: string;
36
41
  description?: string;
37
- }): Promise<Policy>;
42
+ }): Promise<UpdatePolicy>;
38
43
  delete(policyId: string): Promise<void>;
39
44
  }
45
+ export {};