asteroid-odyssey 1.2.4 → 1.3.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/dist/index.js CHANGED
@@ -1,388 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.deleteAgentProfile = exports.updateAgentProfile = exports.getAgentProfile = exports.createAgentProfile = exports.getCredentialsPublicKey = exports.getAgentProfiles = exports.uploadExecutionFiles = exports.getBrowserSessionRecording = exports.waitForExecutionResult = exports.getExecutionResult = exports.getExecutionStatus = exports.executeAgent = exports.AsteroidClient = void 0;
40
- const client_fetch_1 = require("@hey-api/client-fetch");
41
- const AgentsSDK = __importStar(require("./generated/agents/sdk.gen"));
42
- const encryption_1 = require("./utils/encryption");
43
- /**
44
- * Create an API client with a provided API key.
45
- *
46
- * @param apiKey - Your API key.
47
- * @returns A configured API client.
48
- *
49
- * @example
50
- * const client = AsteroidClient('your-api-key');
51
- */
52
- const AsteroidClient = (apiKey, options) => {
53
- return (0, client_fetch_1.createClient)({
54
- baseUrl: options?.baseUrl || 'https://odyssey.asteroid.ai/api/v1',
55
- headers: {
56
- 'X-Asteroid-Agents-Api-Key': apiKey
57
- }
58
- });
59
- };
60
- exports.AsteroidClient = AsteroidClient;
61
- /**
62
- * Execute an agent with parameters including optional agent profile ID.
63
- *
64
- * @param client - The API client.
65
- * @param agentId - The ID of the agent to execute.
66
- * @param executionData - The structured execution parameters.
67
- * @returns The execution ID.
68
- *
69
- * @example
70
- * const executionId = await executeAgent(client, 'my-agent-id', {
71
- * agent_profile_id: 'profile-123',
72
- * dynamic_data: { input: "some dynamic value" }
73
- * });
74
- */
75
- const executeAgent = async (client, agentId, executionData) => {
76
- const response = await AgentsSDK.executeAgentStructured({
77
- client,
78
- path: { id: agentId },
79
- body: executionData,
80
- });
81
- if (response.error) {
82
- throw new Error(response.error.error);
83
- }
84
- return response.data.execution_id;
85
- };
86
- exports.executeAgent = executeAgent;
87
- /**
88
- * Get the current status for an execution.
89
- *
90
- * @param client - The API client.
91
- * @param executionId - The execution identifier.
92
- * @returns The execution status details.
93
- *
94
- * @example
95
- * const status = await getExecutionStatus(client, executionId);
96
- * console.log(status.status);
97
- */
98
- const getExecutionStatus = async (client, executionId) => {
99
- const response = await AgentsSDK.getExecutionStatus({
100
- client,
101
- path: { id: executionId },
102
- });
103
- if (response.error) {
104
- throw new Error(response.error.error);
105
- }
106
- return response.data;
107
- };
108
- exports.getExecutionStatus = getExecutionStatus;
109
- /**
110
- * Get the final result of an execution.
111
- *
112
- * @param client - The API client.
113
- * @param executionId - The execution identifier.
114
- * @returns The result object of the execution.
115
- *
116
- * @example
117
- * const result = await getExecutionResult(client, executionId);
118
- * console.log(result);
119
- */
120
- const getExecutionResult = async (client, executionId) => {
121
- const response = await AgentsSDK.getExecutionResult({
122
- client,
123
- path: { id: executionId },
124
- });
125
- if (response.error) {
126
- throw new Error(response.error.error);
127
- }
128
- if (response.data.error) {
129
- throw new Error(response.data.error);
130
- }
131
- return response.data.execution_result || {};
132
- };
133
- exports.getExecutionResult = getExecutionResult;
134
- /**
135
- * Waits for an execution to reach a terminal state and returns the result.
136
- * Continuously polls the execution status until it's either "completed", "cancelled", or "failed".
137
- *
138
- * @param client - The API client.
139
- * @param executionId - The execution identifier.
140
- * @param interval - Polling interval in milliseconds (default is 1000ms).
141
- * @returns A promise that resolves with the execution result if completed.
142
- * @throws An error if the execution ends as "cancelled" or "failed".
143
- *
144
- * @example
145
- * const result = await waitForExecutionResult(client, executionId, 2000);
146
- */
147
- const waitForExecutionResult = async (client, executionId, interval = 1000, timeout = 3600000 // 1 hour
148
- ) => {
149
- var steps = Math.floor(timeout / interval);
150
- // Keep polling the execution status until it's either "completed", "cancelled", or "failed".
151
- while (steps > 0) {
152
- const status = await (0, exports.getExecutionStatus)(client, executionId);
153
- const currentStatus = status.status;
154
- if (currentStatus === 'completed') {
155
- return await (0, exports.getExecutionResult)(client, executionId);
156
- }
157
- else if (currentStatus === 'failed' || currentStatus === 'cancelled') {
158
- throw new Error(`Execution ${executionId} ended with status: ${currentStatus}${status.reason ? ' - ' + status.reason : ''}`);
159
- }
160
- // Wait for the specified interval before polling again
161
- await new Promise(resolve => setTimeout(resolve, interval));
162
- steps--;
163
- }
164
- throw new Error(`Execution ${executionId} timed out after ${timeout}ms`);
165
- };
166
- exports.waitForExecutionResult = waitForExecutionResult;
167
- /**
168
- * Get the browser session recording URL for a completed execution.
169
- *
170
- * @param client - The API client.
171
- * @param executionId - The execution identifier.
172
- * @returns The browser session recording URL.
173
- *
174
- * @example
175
- * const recording = await getBrowserSessionRecording(client, executionId);
176
- * console.log(recording.recording_url);
177
- */
178
- const getBrowserSessionRecording = async (client, executionId) => {
179
- const response = await AgentsSDK.getBrowserSessionRecording({
180
- client,
181
- path: { id: executionId },
182
- });
183
- if (response.error) {
184
- throw new Error(response.error.error);
185
- }
186
- return response.data;
187
- };
188
- exports.getBrowserSessionRecording = getBrowserSessionRecording;
189
- /**
190
- * Upload files to an execution.
191
- *
192
- * @param client - The API client.
193
- * @param executionId - The execution identifier.
194
- * @param files - Array of files to upload.
195
- * @returns The uploaded file IDs and success message.
196
- *
197
- * @example
198
- * const fileInput = document.getElementById('file-input') as HTMLInputElement;
199
- * const files = Array.from(fileInput.files || []);
200
- * const result = await uploadExecutionFiles(client, executionId, files);
201
- * console.log(result.file_ids);
202
- */
203
- const uploadExecutionFiles = async (client, executionId, files) => {
204
- const response = await AgentsSDK.uploadExecutionFiles({
205
- client,
206
- path: { id: executionId },
207
- body: { files },
208
- });
209
- if (response.error) {
210
- throw new Error(response.error.error);
211
- }
212
- return response.data;
213
- };
214
- exports.uploadExecutionFiles = uploadExecutionFiles;
215
- /**
216
- * Get agent profiles for an organization (or all organizations for the user if not specified).
217
- *
218
- * @param client - The API client.
219
- * @param organizationId - Optional organization ID to filter by.
220
- * @returns The list of agent profiles.
221
- *
222
- * @example
223
- * const profiles = await getAgentProfiles(client, 'org_123');
224
- */
225
- const getAgentProfiles = async (client, organizationId) => {
226
- const response = await AgentsSDK.getAgentProfiles({
227
- client,
228
- query: organizationId ? { organization_id: organizationId } : undefined,
229
- });
230
- if (response.error) {
231
- throw new Error(response.error.error);
232
- }
233
- return response.data;
234
- };
235
- exports.getAgentProfiles = getAgentProfiles;
236
- /**
237
- * Get the public key for encrypting credentials.
238
- *
239
- * @param client - The API client.
240
- * @returns The PEM-formatted public key.
241
- *
242
- * @example
243
- * const publicKey = await getCredentialsPublicKey(client);
244
- */
245
- const getCredentialsPublicKey = async (client) => {
246
- const response = await AgentsSDK.getCredentialsPublicKey({
247
- client,
248
- });
249
- if (response.error) {
250
- const errorMessage = typeof response.error === 'object' && 'error' in response.error
251
- ? response.error.error
252
- : typeof response.error === 'string'
253
- ? response.error
254
- : JSON.stringify(response.error);
255
- throw new Error(errorMessage || 'Unknown error');
256
- }
257
- if (!response.data) {
258
- throw new Error('Public key not found');
259
- }
260
- return response.data;
261
- };
262
- exports.getCredentialsPublicKey = getCredentialsPublicKey;
263
- /**
264
- * Create a new agent profile.
265
- *
266
- * @param client - The API client.
267
- * @param payload - The agent profile data.
268
- * @returns The created agent profile.
269
- *
270
- * @example
271
- * const profile = await createAgentProfile(client, {
272
- * name: 'My Profile',
273
- * description: 'Profile description',
274
- * organization_id: 'org_123',
275
- * proxy_cc: 'us',
276
- * proxy_type: 'residential',
277
- * captcha_solver_active: false,
278
- * sticky_ip: false,
279
- * credentials: []
280
- * });
281
- */
282
- const createAgentProfile = async (client, payload) => {
283
- // If credentials are provided, encrypt them before sending
284
- let processedPayload = { ...payload };
285
- if (payload.credentials && payload.credentials.length > 0) {
286
- // Get the public key for encryption
287
- const publicKey = await (0, exports.getCredentialsPublicKey)(client);
288
- // Encrypt each credential's data field
289
- processedPayload.credentials = payload.credentials.map(credential => ({
290
- ...credential,
291
- data: (0, encryption_1.encryptWithPublicKey)(credential.data, publicKey)
292
- }));
293
- }
294
- const response = await AgentsSDK.createAgentProfile({
295
- client,
296
- body: processedPayload,
297
- });
298
- if (response.error) {
299
- throw new Error(response.error.error);
300
- }
301
- return response.data;
302
- };
303
- exports.createAgentProfile = createAgentProfile;
304
- /**
305
- * Get a specific agent profile by ID.
306
- *
307
- * @param client - The API client.
308
- * @param profileId - The agent profile ID.
309
- * @returns The agent profile.
310
- *
311
- * @example
312
- * const profile = await getAgentProfile(client, 'profile_123');
313
- */
314
- const getAgentProfile = async (client, profileId) => {
315
- const response = await AgentsSDK.getAgentProfile({
316
- client,
317
- path: { profile_id: profileId },
318
- });
319
- if (response.error) {
320
- throw new Error(response.error.error);
321
- }
322
- return response.data;
323
- };
324
- exports.getAgentProfile = getAgentProfile;
325
- /**
326
- * Update an existing agent profile.
327
- *
328
- * @param client - The API client.
329
- * @param profileId - The agent profile ID.
330
- * @param payload - The update data.
331
- * @returns The updated agent profile.
332
- *
333
- * @example
334
- * const updated = await updateAgentProfile(client, 'profile_123', {
335
- * name: 'New Name',
336
- * credentials_to_add: [{ name: 'API_KEY', data: 'secret-key' }],
337
- * credentials_to_delete: ['cred_456']
338
- * });
339
- */
340
- const updateAgentProfile = async (client, profileId, payload) => {
341
- // If credentials_to_add are provided, encrypt them before sending
342
- let processedPayload = { ...payload };
343
- if (payload.credentials_to_add && payload.credentials_to_add.length > 0) {
344
- // Get the public key for encryption
345
- const publicKey = await (0, exports.getCredentialsPublicKey)(client);
346
- // Encrypt the data field of each credential to add
347
- processedPayload.credentials_to_add = payload.credentials_to_add.map(credential => ({
348
- ...credential,
349
- data: (0, encryption_1.encryptWithPublicKey)(credential.data, publicKey)
350
- }));
351
- }
352
- const response = await AgentsSDK.updateAgentProfile({
353
- client,
354
- path: { profile_id: profileId },
355
- body: processedPayload,
356
- });
357
- if (response.error) {
358
- throw new Error(response.error.error);
359
- }
360
- return response.data;
361
- };
362
- exports.updateAgentProfile = updateAgentProfile;
363
- /**
364
- * Delete an agent profile by ID.
365
- *
366
- * @param client - The API client.
367
- * @param profileId - The agent profile ID.
368
- * @returns A success message.
369
- *
370
- * @example
371
- * await deleteAgentProfile(client, 'profile_123');
372
- */
373
- const deleteAgentProfile = async (client, profileId) => {
374
- const response = await AgentsSDK.deleteAgentProfile({
375
- client,
376
- path: { profile_id: profileId },
377
- });
378
- if (response.error) {
379
- throw new Error(response.error.error);
380
- }
381
- return response.data;
382
- };
383
- exports.deleteAgentProfile = deleteAgentProfile;
384
- /**
385
- * Optionally, re-export all generated functions and types.
386
- */
387
- __exportStar(require("./generated/agents/sdk.gen"), exports);
388
- __exportStar(require("./generated/agents/types.gen"), exports);
1
+ 'use strict';var T=require('node-forge');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var T__namespace=/*#__PURE__*/_interopNamespace(T);var me=Object.defineProperty;var se=(e,r)=>{for(var t in r)me(e,t,{get:r[t],enumerable:true});};function U(e,r){try{let s=T__namespace.pki.publicKeyFromPem(r).encrypt(e,"RSAES-PKCS1-V1_5");return T__namespace.util.encode64(s)}catch(t){throw console.error("Encryption failed:",t),new Error("Failed to encrypt: "+(t instanceof Error?t.message:"unknown error"))}}var J={};se(J,{createAgentProfile:()=>F,deleteAgentProfile:()=>N,executeAgent:()=>Ue,executeAgentStructured:()=>B,getAgentProfile:()=>W,getAgentProfiles:()=>M,getBrowserSessionRecording:()=>H,getCredentialsPublicKey:()=>X,getExecutionResult:()=>V,getExecutionStatus:()=>$,getOpenApi:()=>qe,healthCheck:()=>De,updateAgentProfile:()=>Q,uploadExecutionFiles:()=>K});var ie=(e,r,t)=>{typeof t=="string"||t instanceof Blob?e.append(r,t):t instanceof Date?e.append(r,t.toISOString()):e.append(r,JSON.stringify(t));};var k={bodySerializer:e=>{let r=new FormData;return Object.entries(e).forEach(([t,s])=>{s!=null&&(Array.isArray(s)?s.forEach(i=>ie(r,t,i)):ie(r,t,s));}),r}},z={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};var ae=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var Ee=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},Re=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Se=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},v=({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(!r){let o=(e?i:i.map(p=>encodeURIComponent(p))).join(Re(s));switch(s){case "label":return `.${o}`;case "matrix":return `;${t}=${o}`;case "simple":return o;default:return `${t}=${o}`}}let a=Ee(s),n=i.map(o=>s==="label"||s==="simple"?e?o:encodeURIComponent(o):S({allowReserved:e,name:t,value:o})).join(a);return s==="label"||s==="matrix"?a+n:n},S=({allowReserved:e,name:r,value:t})=>{if(t==null)return "";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${e?t:encodeURIComponent(t)}`},_=({allowReserved:e,explode:r,name:t,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${t}=${i.toISOString()}`;if(s!=="deepObject"&&!r){let p=[];Object.entries(i).forEach(([y,x])=>{p=[...p,y,e?x:encodeURIComponent(x)];});let u=p.join(",");switch(s){case "form":return `${t}=${u}`;case "label":return `.${u}`;case "matrix":return `;${t}=${u}`;default:return u}}let n=Se(s),o=Object.entries(i).map(([p,u])=>S({allowReserved:e,name:s==="deepObject"?`${t}[${p}]`:p,value:u})).join(n);return s==="label"||s==="matrix"?n+o:o};var be=/\{[^{}]+\}/g,Pe=({path:e,url:r})=>{let t=r,s=r.match(be);if(s)for(let i of s){let a=false,n=i.substring(1,i.length-1),o="simple";n.endsWith("*")&&(a=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),o="label"):n.startsWith(";")&&(n=n.substring(1),o="matrix");let p=e[n];if(p==null)continue;if(Array.isArray(p)){t=t.replace(i,v({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){t=t.replace(i,_({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){t=t.replace(i,`;${S({name:n,value:p})}`);continue}let u=encodeURIComponent(o==="label"?`.${p}`:p);t=t.replace(i,u);}return t},pe=({allowReserved:e,array:r,object:t}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let n in i){let o=i[n];if(o!=null)if(Array.isArray(o)){let p=v({allowReserved:e,explode:true,name:n,style:"form",value:o,...r});p&&a.push(p);}else if(typeof o=="object"){let p=_({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...t});p&&a.push(p);}else {let p=S({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ce=e=>{if(!e)return "stream";let r=e.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return "blob";if(r.startsWith("text/"))return "text"}},Oe=(e,r)=>r?!!(e.headers.has(r)||e.query?.[r]||e.headers.get("Cookie")?.includes(`${r}=`)):false,le=async({security:e,...r})=>{for(let t of e){if(Oe(r,t.name))continue;let s=await ae(t,r.auth);if(!s)continue;let i=t.name??"Authorization";switch(t.in){case "query":r.query||(r.query={}),r.query[i]=s;break;case "cookie":r.headers.append("Cookie",`${i}=${s}`);break;case "header":default:r.headers.set(i,s);break}}},G=e=>Ce({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:pe(e.querySerializer),url:e.url}),Ce=({baseUrl:e,path:r,query:t,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,n=(e??"")+a;r&&(n=Pe({path:r,url:n}));let o=t?s(t):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},j=(e,r)=>{let t={...e,...r};return t.baseUrl?.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=q(e.headers,r.headers),t},q=(...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[i,a]of s)if(a===null)r.delete(i);else if(Array.isArray(a))for(let n of a)r.append(i,n);else a!==void 0&&r.set(i,typeof a=="object"?JSON.stringify(a):a);}return r},b=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let t=this.getInterceptorIndex(r);return !!this._fns[t]}eject(r){let t=this.getInterceptorIndex(r);this._fns[t]&&(this._fns[t]=null);}update(r,t){let s=this.getInterceptorIndex(r);return this._fns[s]?(this._fns[s]=t,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},ue=()=>({error:new b,request:new b,response:new b}),we=pe({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Te={"Content-Type":"application/json"},P=(e={})=>({...z,headers:Te,parseAs:"auto",querySerializer:we,...e});var I=(e={})=>{let r=j(P(),e),t=()=>({...r}),s=n=>(r=j(r,n),t()),i=ue(),a=async n=>{let o={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:q(r.headers,n.headers),serializedBody:void 0};o.security&&await le({...o,security:o.security}),o.requestValidator&&await o.requestValidator(o),o.body&&o.bodySerializer&&(o.serializedBody=o.bodySerializer(o.body)),(o.serializedBody===void 0||o.serializedBody==="")&&o.headers.delete("Content-Type");let p=G(o),u={redirect:"follow",...o,body:o.serializedBody},y=new Request(p,u);for(let l of i.request._fns)l&&(y=await l(y,o));let x=o.fetch,c=await x(y);for(let l of i.response._fns)l&&(c=await l(c,y,o));let A={request:y,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...A};let l=(o.parseAs==="auto"?ce(c.headers.get("Content-Type")):o.parseAs)??"json",f;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":f=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...A}}return l==="json"&&(o.responseValidator&&await o.responseValidator(f),o.responseTransformer&&(f=await o.responseTransformer(f))),o.responseStyle==="data"?f:{data:f,...A}}let m=await c.text(),E;try{E=JSON.parse(m);}catch{}let R=E??m,g=R;for(let l of i.error._fns)l&&(g=await l(R,c,y,o));if(g=g||{},o.throwOnError)throw g;return o.responseStyle==="data"?void 0:{error:g,...A}};return {buildUrl:G,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:t,head:n=>a({...n,method:"HEAD"}),interceptors:i,options:n=>a({...n,method:"OPTIONS"}),patch:n=>a({...n,method:"PATCH"}),post:n=>a({...n,method:"POST"}),put:n=>a({...n,method:"PUT"}),request:a,setConfig:s,trace:n=>a({...n,method:"TRACE"})}};var d=I(P({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var qe=e=>(e?.client??d).get({url:"/openapi.yaml",...e}),K=e=>(e.client??d).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/files",...e,headers:{"Content-Type":null,...e.headers}}),De=e=>(e?.client??d).get({url:"/health",...e}),Ue=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),B=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),V=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),H=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),M=e=>(e?.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),F=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),N=e=>(e.client??d).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),W=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),Q=e=>(e.client??d).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),X=e=>(e?.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ne={};se(ne,{activitiesGet:()=>re,userMessagesAdd:()=>oe});var de={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};var ye=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var ke=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},ze=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},ve=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},L=({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(!r){let o=(e?i:i.map(p=>encodeURIComponent(p))).join(ze(s));switch(s){case "label":return `.${o}`;case "matrix":return `;${t}=${o}`;case "simple":return o;default:return `${t}=${o}`}}let a=ke(s),n=i.map(o=>s==="label"||s==="simple"?e?o:encodeURIComponent(o):O({allowReserved:e,name:t,value:o})).join(a);return s==="label"||s==="matrix"?a+n:n},O=({allowReserved:e,name:r,value:t})=>{if(t==null)return "";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${e?t:encodeURIComponent(t)}`},Y=({allowReserved:e,explode:r,name:t,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${t}=${i.toISOString()}`;if(s!=="deepObject"&&!r){let p=[];Object.entries(i).forEach(([y,x])=>{p=[...p,y,e?x:encodeURIComponent(x)];});let u=p.join(",");switch(s){case "form":return `${t}=${u}`;case "label":return `.${u}`;case "matrix":return `;${t}=${u}`;default:return u}}let n=ve(s),o=Object.entries(i).map(([p,u])=>O({allowReserved:e,name:s==="deepObject"?`${t}[${p}]`:p,value:u})).join(n);return s==="label"||s==="matrix"?n+o:o};var _e=/\{[^{}]+\}/g,Ge=({path:e,url:r})=>{let t=r,s=r.match(_e);if(s)for(let i of s){let a=false,n=i.substring(1,i.length-1),o="simple";n.endsWith("*")&&(a=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),o="label"):n.startsWith(";")&&(n=n.substring(1),o="matrix");let p=e[n];if(p==null)continue;if(Array.isArray(p)){t=t.replace(i,L({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){t=t.replace(i,Y({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){t=t.replace(i,`;${O({name:n,value:p})}`);continue}let u=encodeURIComponent(o==="label"?`.${p}`:p);t=t.replace(i,u);}return t},fe=({allowReserved:e,array:r,object:t}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let n in i){let o=i[n];if(o!=null)if(Array.isArray(o)){let p=L({allowReserved:e,explode:true,name:n,style:"form",value:o,...r});p&&a.push(p);}else if(typeof o=="object"){let p=Y({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...t});p&&a.push(p);}else {let p=O({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ge=e=>{if(!e)return "stream";let r=e.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return "blob";if(r.startsWith("text/"))return "text"}},je=(e,r)=>r?!!(e.headers.has(r)||e.query?.[r]||e.headers.get("Cookie")?.includes(`${r}=`)):false,xe=async({security:e,...r})=>{for(let t of e){if(je(r,t.name))continue;let s=await ye(t,r.auth);if(!s)continue;let i=t.name??"Authorization";switch(t.in){case "query":r.query||(r.query={}),r.query[i]=s;break;case "cookie":r.headers.append("Cookie",`${i}=${s}`);break;case "header":default:r.headers.set(i,s);break}}},Z=e=>Ie({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:fe(e.querySerializer),url:e.url}),Ie=({baseUrl:e,path:r,query:t,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,n=(e??"")+a;r&&(n=Ge({path:r,url:n}));let o=t?s(t):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},ee=(e,r)=>{let t={...e,...r};return t.baseUrl?.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=D(e.headers,r.headers),t},D=(...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[i,a]of s)if(a===null)r.delete(i);else if(Array.isArray(a))for(let n of a)r.append(i,n);else a!==void 0&&r.set(i,typeof a=="object"?JSON.stringify(a):a);}return r},C=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let t=this.getInterceptorIndex(r);return !!this._fns[t]}eject(r){let t=this.getInterceptorIndex(r);this._fns[t]&&(this._fns[t]=null);}update(r,t){let s=this.getInterceptorIndex(r);return this._fns[s]?(this._fns[s]=t,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},Ae=()=>({error:new C,request:new C,response:new C}),Ke=fe({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Be={"Content-Type":"application/json"},w=(e={})=>({...de,headers:Be,parseAs:"auto",querySerializer:Ke,...e});var te=(e={})=>{let r=ee(w(),e),t=()=>({...r}),s=n=>(r=ee(r,n),t()),i=Ae(),a=async n=>{let o={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:D(r.headers,n.headers),serializedBody:void 0};o.security&&await xe({...o,security:o.security}),o.requestValidator&&await o.requestValidator(o),o.body&&o.bodySerializer&&(o.serializedBody=o.bodySerializer(o.body)),(o.serializedBody===void 0||o.serializedBody==="")&&o.headers.delete("Content-Type");let p=Z(o),u={redirect:"follow",...o,body:o.serializedBody},y=new Request(p,u);for(let l of i.request._fns)l&&(y=await l(y,o));let x=o.fetch,c=await x(y);for(let l of i.response._fns)l&&(c=await l(c,y,o));let A={request:y,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...A};let l=(o.parseAs==="auto"?ge(c.headers.get("Content-Type")):o.parseAs)??"json",f;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":f=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...A}}return l==="json"&&(o.responseValidator&&await o.responseValidator(f),o.responseTransformer&&(f=await o.responseTransformer(f))),o.responseStyle==="data"?f:{data:f,...A}}let m=await c.text(),E;try{E=JSON.parse(m);}catch{}let R=E??m,g=R;for(let l of i.error._fns)l&&(g=await l(R,c,y,o));if(g=g||{},o.throwOnError)throw g;return o.responseStyle==="data"?void 0:{error:g,...A}};return {buildUrl:Z,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:t,head:n=>a({...n,method:"HEAD"}),interceptors:i,options:n=>a({...n,method:"OPTIONS"}),patch:n=>a({...n,method:"PATCH"}),post:n=>a({...n,method:"POST"}),put:n=>a({...n,method:"PUT"}),request:a,setConfig:s,trace:n=>a({...n,method:"TRACE"})}};var h=te(w());var re=e=>(e.client??h).get({url:"/executions/{executionId}/activities",...e}),oe=e=>(e.client??h).post({url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}});var $e={};var Ve={};var qt=(e,r)=>(d.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),h.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),d.setConfig({baseUrl:r?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),h.setConfig({baseUrl:r?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:d,agentsV2Client:h}),Dt=async(e,r,t)=>{let s=await B({client:e.agentsV1Client,path:{id:r},body:t});if(s.error)throw new Error(s.error.error);return s.data.execution_id},He=async(e,r)=>{let t=await $({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);return t.data},Me=async(e,r)=>{let t=await V({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);if(t.data.error)throw new Error(t.data.error);return t.data.execution_result||{}},Ut=async(e,r,t=1e3,s=36e5)=>{for(var i=Math.floor(s/t);i>0;){let a=await He(e,r),n=a.status;if(n==="completed")return await Me(e,r);if(n==="failed"||n==="cancelled")throw new Error(`Execution ${r} ended with status: ${n}${a.reason?" - "+a.reason:""}`);await new Promise(o=>setTimeout(o,t)),i--;}throw new Error(`Execution ${r} timed out after ${s}ms`)},kt=async(e,r)=>{let t=await H({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);return t.data},zt=async(e,r,t)=>{let s=await K({client:e.agentsV1Client,path:{id:r},body:{files:t}});if(s.error)throw new Error(s.error.error);return s.data},vt=async(e,r)=>{let t=await M({client:e.agentsV1Client,query:r?{organization_id:r}:void 0});if(t.error)throw new Error(t.error.error);return t.data},he=async e=>{let r=await X({client:e.agentsV1Client});if(r.error){let t=typeof r.error=="object"&&"error"in r.error?r.error.error:typeof r.error=="string"?r.error:JSON.stringify(r.error);throw new Error(t||"Unknown error")}if(!r.data)throw new Error("Public key not found");return r.data},_t=async(e,r)=>{let t={...r};if(r.credentials&&r.credentials.length>0){let i=await he(e);t.credentials=r.credentials.map(a=>({...a,data:U(a.data,i)}));}let s=await F({client:e.agentsV1Client,body:t});if(s.error)throw new Error(s.error.error);return s.data},Gt=async(e,r)=>{let t=await W({client:e.agentsV1Client,path:{profile_id:r}});if(t.error)throw new Error(t.error.error);return t.data},jt=async(e,r,t)=>{let s={...t};if(t.credentials_to_add&&t.credentials_to_add.length>0){let a=await he(e);s.credentials_to_add=t.credentials_to_add.map(n=>({...n,data:U(n.data,a)}));}let i=await Q({client:e.agentsV1Client,path:{profile_id:r},body:s});if(i.error)throw new Error(i.error.error);return i.data},It=async(e,r)=>{let t=await N({client:e.agentsV1Client,path:{profile_id:r}});if(t.error)throw new Error(t.error.error);return t.data},Kt=async(e,r,t)=>{let s=await re({client:e.agentsV2Client,path:{executionId:r},query:{limit:t,order:"desc"}});if(s.error)throw console.error(s.error),new Error(s.error.error);return s.data},Bt=async(e,r,t)=>{let s=await oe({client:e.agentsV2Client,path:{executionId:r},body:{message:t}});if(s.error)throw console.error(s.error),new Error(s.error.error)};
2
+ exports.AgentsV1SDK=J;exports.AgentsV1Types=$e;exports.AgentsV2SDK=ne;exports.AgentsV2Types=Ve;exports.AsteroidClient=qt;exports.addMessageToExecution=Bt;exports.createAgentProfile=_t;exports.deleteAgentProfile=It;exports.executeAgent=Dt;exports.getAgentProfile=Gt;exports.getAgentProfiles=vt;exports.getBrowserSessionRecording=kt;exports.getCredentialsPublicKey=he;exports.getExecutionResult=Me;exports.getExecutionStatus=He;exports.getLastNExecutionActivities=Kt;exports.updateAgentProfile=jt;exports.uploadExecutionFiles=zt;exports.waitForExecutionResult=Ut;
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import*as T from'node-forge';var me=Object.defineProperty;var se=(e,r)=>{for(var t in r)me(e,t,{get:r[t],enumerable:true});};function U(e,r){try{let s=T.pki.publicKeyFromPem(r).encrypt(e,"RSAES-PKCS1-V1_5");return T.util.encode64(s)}catch(t){throw console.error("Encryption failed:",t),new Error("Failed to encrypt: "+(t instanceof Error?t.message:"unknown error"))}}var J={};se(J,{createAgentProfile:()=>F,deleteAgentProfile:()=>N,executeAgent:()=>Ue,executeAgentStructured:()=>B,getAgentProfile:()=>W,getAgentProfiles:()=>M,getBrowserSessionRecording:()=>H,getCredentialsPublicKey:()=>X,getExecutionResult:()=>V,getExecutionStatus:()=>$,getOpenApi:()=>qe,healthCheck:()=>De,updateAgentProfile:()=>Q,uploadExecutionFiles:()=>K});var ie=(e,r,t)=>{typeof t=="string"||t instanceof Blob?e.append(r,t):t instanceof Date?e.append(r,t.toISOString()):e.append(r,JSON.stringify(t));};var k={bodySerializer:e=>{let r=new FormData;return Object.entries(e).forEach(([t,s])=>{s!=null&&(Array.isArray(s)?s.forEach(i=>ie(r,t,i)):ie(r,t,s));}),r}},z={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};var ae=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var Ee=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},Re=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Se=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},v=({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(!r){let o=(e?i:i.map(p=>encodeURIComponent(p))).join(Re(s));switch(s){case "label":return `.${o}`;case "matrix":return `;${t}=${o}`;case "simple":return o;default:return `${t}=${o}`}}let a=Ee(s),n=i.map(o=>s==="label"||s==="simple"?e?o:encodeURIComponent(o):S({allowReserved:e,name:t,value:o})).join(a);return s==="label"||s==="matrix"?a+n:n},S=({allowReserved:e,name:r,value:t})=>{if(t==null)return "";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${e?t:encodeURIComponent(t)}`},_=({allowReserved:e,explode:r,name:t,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${t}=${i.toISOString()}`;if(s!=="deepObject"&&!r){let p=[];Object.entries(i).forEach(([y,x])=>{p=[...p,y,e?x:encodeURIComponent(x)];});let u=p.join(",");switch(s){case "form":return `${t}=${u}`;case "label":return `.${u}`;case "matrix":return `;${t}=${u}`;default:return u}}let n=Se(s),o=Object.entries(i).map(([p,u])=>S({allowReserved:e,name:s==="deepObject"?`${t}[${p}]`:p,value:u})).join(n);return s==="label"||s==="matrix"?n+o:o};var be=/\{[^{}]+\}/g,Pe=({path:e,url:r})=>{let t=r,s=r.match(be);if(s)for(let i of s){let a=false,n=i.substring(1,i.length-1),o="simple";n.endsWith("*")&&(a=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),o="label"):n.startsWith(";")&&(n=n.substring(1),o="matrix");let p=e[n];if(p==null)continue;if(Array.isArray(p)){t=t.replace(i,v({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){t=t.replace(i,_({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){t=t.replace(i,`;${S({name:n,value:p})}`);continue}let u=encodeURIComponent(o==="label"?`.${p}`:p);t=t.replace(i,u);}return t},pe=({allowReserved:e,array:r,object:t}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let n in i){let o=i[n];if(o!=null)if(Array.isArray(o)){let p=v({allowReserved:e,explode:true,name:n,style:"form",value:o,...r});p&&a.push(p);}else if(typeof o=="object"){let p=_({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...t});p&&a.push(p);}else {let p=S({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ce=e=>{if(!e)return "stream";let r=e.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return "blob";if(r.startsWith("text/"))return "text"}},Oe=(e,r)=>r?!!(e.headers.has(r)||e.query?.[r]||e.headers.get("Cookie")?.includes(`${r}=`)):false,le=async({security:e,...r})=>{for(let t of e){if(Oe(r,t.name))continue;let s=await ae(t,r.auth);if(!s)continue;let i=t.name??"Authorization";switch(t.in){case "query":r.query||(r.query={}),r.query[i]=s;break;case "cookie":r.headers.append("Cookie",`${i}=${s}`);break;case "header":default:r.headers.set(i,s);break}}},G=e=>Ce({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:pe(e.querySerializer),url:e.url}),Ce=({baseUrl:e,path:r,query:t,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,n=(e??"")+a;r&&(n=Pe({path:r,url:n}));let o=t?s(t):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},j=(e,r)=>{let t={...e,...r};return t.baseUrl?.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=q(e.headers,r.headers),t},q=(...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[i,a]of s)if(a===null)r.delete(i);else if(Array.isArray(a))for(let n of a)r.append(i,n);else a!==void 0&&r.set(i,typeof a=="object"?JSON.stringify(a):a);}return r},b=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let t=this.getInterceptorIndex(r);return !!this._fns[t]}eject(r){let t=this.getInterceptorIndex(r);this._fns[t]&&(this._fns[t]=null);}update(r,t){let s=this.getInterceptorIndex(r);return this._fns[s]?(this._fns[s]=t,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},ue=()=>({error:new b,request:new b,response:new b}),we=pe({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Te={"Content-Type":"application/json"},P=(e={})=>({...z,headers:Te,parseAs:"auto",querySerializer:we,...e});var I=(e={})=>{let r=j(P(),e),t=()=>({...r}),s=n=>(r=j(r,n),t()),i=ue(),a=async n=>{let o={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:q(r.headers,n.headers),serializedBody:void 0};o.security&&await le({...o,security:o.security}),o.requestValidator&&await o.requestValidator(o),o.body&&o.bodySerializer&&(o.serializedBody=o.bodySerializer(o.body)),(o.serializedBody===void 0||o.serializedBody==="")&&o.headers.delete("Content-Type");let p=G(o),u={redirect:"follow",...o,body:o.serializedBody},y=new Request(p,u);for(let l of i.request._fns)l&&(y=await l(y,o));let x=o.fetch,c=await x(y);for(let l of i.response._fns)l&&(c=await l(c,y,o));let A={request:y,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...A};let l=(o.parseAs==="auto"?ce(c.headers.get("Content-Type")):o.parseAs)??"json",f;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":f=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...A}}return l==="json"&&(o.responseValidator&&await o.responseValidator(f),o.responseTransformer&&(f=await o.responseTransformer(f))),o.responseStyle==="data"?f:{data:f,...A}}let m=await c.text(),E;try{E=JSON.parse(m);}catch{}let R=E??m,g=R;for(let l of i.error._fns)l&&(g=await l(R,c,y,o));if(g=g||{},o.throwOnError)throw g;return o.responseStyle==="data"?void 0:{error:g,...A}};return {buildUrl:G,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:t,head:n=>a({...n,method:"HEAD"}),interceptors:i,options:n=>a({...n,method:"OPTIONS"}),patch:n=>a({...n,method:"PATCH"}),post:n=>a({...n,method:"POST"}),put:n=>a({...n,method:"PUT"}),request:a,setConfig:s,trace:n=>a({...n,method:"TRACE"})}};var d=I(P({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var qe=e=>(e?.client??d).get({url:"/openapi.yaml",...e}),K=e=>(e.client??d).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/files",...e,headers:{"Content-Type":null,...e.headers}}),De=e=>(e?.client??d).get({url:"/health",...e}),Ue=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),B=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),V=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),H=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),M=e=>(e?.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),F=e=>(e.client??d).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),N=e=>(e.client??d).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),W=e=>(e.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),Q=e=>(e.client??d).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),X=e=>(e?.client??d).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ne={};se(ne,{activitiesGet:()=>re,userMessagesAdd:()=>oe});var de={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};var ye=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var ke=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},ze=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},ve=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},L=({allowReserved:e,explode:r,name:t,style:s,value:i})=>{if(!r){let o=(e?i:i.map(p=>encodeURIComponent(p))).join(ze(s));switch(s){case "label":return `.${o}`;case "matrix":return `;${t}=${o}`;case "simple":return o;default:return `${t}=${o}`}}let a=ke(s),n=i.map(o=>s==="label"||s==="simple"?e?o:encodeURIComponent(o):O({allowReserved:e,name:t,value:o})).join(a);return s==="label"||s==="matrix"?a+n:n},O=({allowReserved:e,name:r,value:t})=>{if(t==null)return "";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${e?t:encodeURIComponent(t)}`},Y=({allowReserved:e,explode:r,name:t,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${t}=${i.toISOString()}`;if(s!=="deepObject"&&!r){let p=[];Object.entries(i).forEach(([y,x])=>{p=[...p,y,e?x:encodeURIComponent(x)];});let u=p.join(",");switch(s){case "form":return `${t}=${u}`;case "label":return `.${u}`;case "matrix":return `;${t}=${u}`;default:return u}}let n=ve(s),o=Object.entries(i).map(([p,u])=>O({allowReserved:e,name:s==="deepObject"?`${t}[${p}]`:p,value:u})).join(n);return s==="label"||s==="matrix"?n+o:o};var _e=/\{[^{}]+\}/g,Ge=({path:e,url:r})=>{let t=r,s=r.match(_e);if(s)for(let i of s){let a=false,n=i.substring(1,i.length-1),o="simple";n.endsWith("*")&&(a=true,n=n.substring(0,n.length-1)),n.startsWith(".")?(n=n.substring(1),o="label"):n.startsWith(";")&&(n=n.substring(1),o="matrix");let p=e[n];if(p==null)continue;if(Array.isArray(p)){t=t.replace(i,L({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){t=t.replace(i,Y({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){t=t.replace(i,`;${O({name:n,value:p})}`);continue}let u=encodeURIComponent(o==="label"?`.${p}`:p);t=t.replace(i,u);}return t},fe=({allowReserved:e,array:r,object:t}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let n in i){let o=i[n];if(o!=null)if(Array.isArray(o)){let p=L({allowReserved:e,explode:true,name:n,style:"form",value:o,...r});p&&a.push(p);}else if(typeof o=="object"){let p=Y({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...t});p&&a.push(p);}else {let p=O({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ge=e=>{if(!e)return "stream";let r=e.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return "json";if(r==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return "blob";if(r.startsWith("text/"))return "text"}},je=(e,r)=>r?!!(e.headers.has(r)||e.query?.[r]||e.headers.get("Cookie")?.includes(`${r}=`)):false,xe=async({security:e,...r})=>{for(let t of e){if(je(r,t.name))continue;let s=await ye(t,r.auth);if(!s)continue;let i=t.name??"Authorization";switch(t.in){case "query":r.query||(r.query={}),r.query[i]=s;break;case "cookie":r.headers.append("Cookie",`${i}=${s}`);break;case "header":default:r.headers.set(i,s);break}}},Z=e=>Ie({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:fe(e.querySerializer),url:e.url}),Ie=({baseUrl:e,path:r,query:t,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,n=(e??"")+a;r&&(n=Ge({path:r,url:n}));let o=t?s(t):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},ee=(e,r)=>{let t={...e,...r};return t.baseUrl?.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=D(e.headers,r.headers),t},D=(...e)=>{let r=new Headers;for(let t of e){if(!t||typeof t!="object")continue;let s=t instanceof Headers?t.entries():Object.entries(t);for(let[i,a]of s)if(a===null)r.delete(i);else if(Array.isArray(a))for(let n of a)r.append(i,n);else a!==void 0&&r.set(i,typeof a=="object"?JSON.stringify(a):a);}return r},C=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(r){return typeof r=="number"?this._fns[r]?r:-1:this._fns.indexOf(r)}exists(r){let t=this.getInterceptorIndex(r);return !!this._fns[t]}eject(r){let t=this.getInterceptorIndex(r);this._fns[t]&&(this._fns[t]=null);}update(r,t){let s=this.getInterceptorIndex(r);return this._fns[s]?(this._fns[s]=t,r):false}use(r){return this._fns=[...this._fns,r],this._fns.length-1}},Ae=()=>({error:new C,request:new C,response:new C}),Ke=fe({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Be={"Content-Type":"application/json"},w=(e={})=>({...de,headers:Be,parseAs:"auto",querySerializer:Ke,...e});var te=(e={})=>{let r=ee(w(),e),t=()=>({...r}),s=n=>(r=ee(r,n),t()),i=Ae(),a=async n=>{let o={...r,...n,fetch:n.fetch??r.fetch??globalThis.fetch,headers:D(r.headers,n.headers),serializedBody:void 0};o.security&&await xe({...o,security:o.security}),o.requestValidator&&await o.requestValidator(o),o.body&&o.bodySerializer&&(o.serializedBody=o.bodySerializer(o.body)),(o.serializedBody===void 0||o.serializedBody==="")&&o.headers.delete("Content-Type");let p=Z(o),u={redirect:"follow",...o,body:o.serializedBody},y=new Request(p,u);for(let l of i.request._fns)l&&(y=await l(y,o));let x=o.fetch,c=await x(y);for(let l of i.response._fns)l&&(c=await l(c,y,o));let A={request:y,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...A};let l=(o.parseAs==="auto"?ge(c.headers.get("Content-Type")):o.parseAs)??"json",f;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":f=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...A}}return l==="json"&&(o.responseValidator&&await o.responseValidator(f),o.responseTransformer&&(f=await o.responseTransformer(f))),o.responseStyle==="data"?f:{data:f,...A}}let m=await c.text(),E;try{E=JSON.parse(m);}catch{}let R=E??m,g=R;for(let l of i.error._fns)l&&(g=await l(R,c,y,o));if(g=g||{},o.throwOnError)throw g;return o.responseStyle==="data"?void 0:{error:g,...A}};return {buildUrl:Z,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:t,head:n=>a({...n,method:"HEAD"}),interceptors:i,options:n=>a({...n,method:"OPTIONS"}),patch:n=>a({...n,method:"PATCH"}),post:n=>a({...n,method:"POST"}),put:n=>a({...n,method:"PUT"}),request:a,setConfig:s,trace:n=>a({...n,method:"TRACE"})}};var h=te(w());var re=e=>(e.client??h).get({url:"/executions/{executionId}/activities",...e}),oe=e=>(e.client??h).post({url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}});var $e={};var Ve={};var qt=(e,r)=>(d.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),h.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),d.setConfig({baseUrl:r?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),h.setConfig({baseUrl:r?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:d,agentsV2Client:h}),Dt=async(e,r,t)=>{let s=await B({client:e.agentsV1Client,path:{id:r},body:t});if(s.error)throw new Error(s.error.error);return s.data.execution_id},He=async(e,r)=>{let t=await $({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);return t.data},Me=async(e,r)=>{let t=await V({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);if(t.data.error)throw new Error(t.data.error);return t.data.execution_result||{}},Ut=async(e,r,t=1e3,s=36e5)=>{for(var i=Math.floor(s/t);i>0;){let a=await He(e,r),n=a.status;if(n==="completed")return await Me(e,r);if(n==="failed"||n==="cancelled")throw new Error(`Execution ${r} ended with status: ${n}${a.reason?" - "+a.reason:""}`);await new Promise(o=>setTimeout(o,t)),i--;}throw new Error(`Execution ${r} timed out after ${s}ms`)},kt=async(e,r)=>{let t=await H({client:e.agentsV1Client,path:{id:r}});if(t.error)throw new Error(t.error.error);return t.data},zt=async(e,r,t)=>{let s=await K({client:e.agentsV1Client,path:{id:r},body:{files:t}});if(s.error)throw new Error(s.error.error);return s.data},vt=async(e,r)=>{let t=await M({client:e.agentsV1Client,query:r?{organization_id:r}:void 0});if(t.error)throw new Error(t.error.error);return t.data},he=async e=>{let r=await X({client:e.agentsV1Client});if(r.error){let t=typeof r.error=="object"&&"error"in r.error?r.error.error:typeof r.error=="string"?r.error:JSON.stringify(r.error);throw new Error(t||"Unknown error")}if(!r.data)throw new Error("Public key not found");return r.data},_t=async(e,r)=>{let t={...r};if(r.credentials&&r.credentials.length>0){let i=await he(e);t.credentials=r.credentials.map(a=>({...a,data:U(a.data,i)}));}let s=await F({client:e.agentsV1Client,body:t});if(s.error)throw new Error(s.error.error);return s.data},Gt=async(e,r)=>{let t=await W({client:e.agentsV1Client,path:{profile_id:r}});if(t.error)throw new Error(t.error.error);return t.data},jt=async(e,r,t)=>{let s={...t};if(t.credentials_to_add&&t.credentials_to_add.length>0){let a=await he(e);s.credentials_to_add=t.credentials_to_add.map(n=>({...n,data:U(n.data,a)}));}let i=await Q({client:e.agentsV1Client,path:{profile_id:r},body:s});if(i.error)throw new Error(i.error.error);return i.data},It=async(e,r)=>{let t=await N({client:e.agentsV1Client,path:{profile_id:r}});if(t.error)throw new Error(t.error.error);return t.data},Kt=async(e,r,t)=>{let s=await re({client:e.agentsV2Client,path:{executionId:r},query:{limit:t,order:"desc"}});if(s.error)throw console.error(s.error),new Error(s.error.error);return s.data},Bt=async(e,r,t)=>{let s=await oe({client:e.agentsV2Client,path:{executionId:r},body:{message:t}});if(s.error)throw console.error(s.error),new Error(s.error.error)};
2
+ export{J as AgentsV1SDK,$e as AgentsV1Types,ne as AgentsV2SDK,Ve as AgentsV2Types,qt as AsteroidClient,Bt as addMessageToExecution,_t as createAgentProfile,It as deleteAgentProfile,Dt as executeAgent,Gt as getAgentProfile,vt as getAgentProfiles,kt as getBrowserSessionRecording,he as getCredentialsPublicKey,Me as getExecutionResult,He as getExecutionStatus,Kt as getLastNExecutionActivities,jt as updateAgentProfile,zt as uploadExecutionFiles,Ut as waitForExecutionResult};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "asteroid-odyssey",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "description": "SDK for interacting with Asteroid Agents API",
5
- "main": "dist/index.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
7
8
  "files": [
8
9
  "dist"
@@ -15,20 +16,29 @@
15
16
  ],
16
17
  "author": "Asteroid",
17
18
  "license": "MIT",
19
+ "sideEffects": false,
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
18
27
  "devDependencies": {
19
- "@hey-api/openapi-ts": "^0.64.12",
20
28
  "@types/node": "^22.13.4",
21
29
  "@types/node-forge": "^1.3.11",
22
30
  "openapi-typescript-codegen": "^0.29.0",
23
31
  "ts-node": "^10.9.2",
24
- "typescript": "^5.7.3"
32
+ "typescript": "^5.7.3",
33
+ "prettier": "^3.6.2",
34
+ "tsup": "^8.0.2"
25
35
  },
26
36
  "dependencies": {
27
- "@hey-api/client-fetch": "^0.8.3",
37
+ "@hey-api/openapi-ts": "^0.80.15",
28
38
  "node-forge": "^1.3.1"
29
39
  },
30
40
  "scripts": {
31
- "build": "tsc",
32
- "openapi-ts": "openapi-ts"
41
+ "build": "tsup --config tsup.config.ts",
42
+ "generate": "openapi-ts --file v1.config.ts && openapi-ts --file v2.config.ts"
33
43
  }
34
44
  }
@@ -1,12 +0,0 @@
1
- import type { ClientOptions } from './types.gen';
2
- import { type Config, type ClientOptions as DefaultClientOptions } from '@hey-api/client-fetch';
3
- /**
4
- * The `createClientConfig()` function will be called on client initialization
5
- * and the returned object will become the client's initial configuration.
6
- *
7
- * You may want to initialize your client this way instead of calling
8
- * `setConfig()`. This is useful for example if you're using Next.js
9
- * to ensure your client always has the correct values.
10
- */
11
- export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
12
- export declare const client: import("@hey-api/client-fetch").Client;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- // This file is auto-generated by @hey-api/openapi-ts
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.client = void 0;
5
- const client_fetch_1 = require("@hey-api/client-fetch");
6
- exports.client = (0, client_fetch_1.createClient)((0, client_fetch_1.createConfig)({
7
- baseUrl: 'https://odyssey.asteroid.ai/api/v1'
8
- }));
@@ -1,2 +0,0 @@
1
- export * from './types.gen';
2
- export * from './sdk.gen';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- // This file is auto-generated by @hey-api/openapi-ts
18
- __exportStar(require("./types.gen"), exports);
19
- __exportStar(require("./sdk.gen"), exports);