asteroid-odyssey 1.3.11 → 1.6.4

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,2 +1,8 @@
1
- 'use strict';var h=require('fs'),Re=require('path'),D=require('node-forge');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}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 h__default=/*#__PURE__*/_interopDefault(h);var Re__default=/*#__PURE__*/_interopDefault(Re);var D__namespace=/*#__PURE__*/_interopNamespace(D);var Pe=Object.defineProperty;var le=(e,t)=>{for(var r in t)Pe(e,r,{get:t[r],enumerable:true});};function U(e,t){try{let s=D__namespace.pki.publicKeyFromPem(t).encrypt(e,"RSAES-PKCS1-V1_5");return D__namespace.util.encode64(s)}catch(r){throw console.error("Encryption failed:",r),new Error("Failed to encrypt: "+(r instanceof Error?r.message:"unknown error"))}}var X={};le(X,{createAgentProfile:()=>V,deleteAgentProfile:()=>$,executeAgent:()=>Ie,executeAgentStructured:()=>Fe,getAgentProfile:()=>H,getAgentProfiles:()=>L,getBrowserSessionRecording:()=>K,getCredentialsPublicKey:()=>W,getExecutionResult:()=>B,getExecutionStatus:()=>j,getOpenApi:()=>ze,healthCheck:()=>Ge,updateAgentProfile:()=>M});var ue={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var de=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var _e=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},we=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Oe=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},z=({allowReserved:e,explode:t,name:r,style:s,value:i})=>{if(!t){let n=(e?i:i.map(p=>encodeURIComponent(p))).join(we(s));switch(s){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let a=_e(s),o=i.map(n=>s==="label"||s==="simple"?e?n:encodeURIComponent(n):b({allowReserved:e,name:r,value:n})).join(a);return s==="label"||s==="matrix"?a+o:o},b=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},G=({allowReserved:e,explode:t,name:r,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${r}=${i.toISOString()}`;if(s!=="deepObject"&&!t){let p=[];Object.entries(i).forEach(([d,A])=>{p=[...p,d,e?A:encodeURIComponent(A)];});let u=p.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let o=Oe(s),n=Object.entries(i).map(([p,u])=>b({allowReserved:e,name:s==="deepObject"?`${r}[${p}]`:p,value:u})).join(o);return s==="label"||s==="matrix"?o+n:n};var Te=/\{[^{}]+\}/g,De=({path:e,url:t})=>{let r=t,s=t.match(Te);if(s)for(let i of s){let a=false,o=i.substring(1,i.length-1),n="simple";o.endsWith("*")&&(a=true,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),n="label"):o.startsWith(";")&&(o=o.substring(1),n="matrix");let p=e[o];if(p==null)continue;if(Array.isArray(p)){r=r.replace(i,z({explode:a,name:o,style:n,value:p}));continue}if(typeof p=="object"){r=r.replace(i,G({explode:a,name:o,style:n,value:p,valueOnly:true}));continue}if(n==="matrix"){r=r.replace(i,`;${b({name:o,value:p})}`);continue}let u=encodeURIComponent(n==="label"?`.${p}`:p);r=r.replace(i,u);}return r},ge=({allowReserved:e,array:t,object:r}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let o in i){let n=i[o];if(n!=null)if(Array.isArray(n)){let p=z({allowReserved:e,explode:true,name:o,style:"form",value:n,...t});p&&a.push(p);}else if(typeof n=="object"){let p=G({allowReserved:e,explode:true,name:o,style:"deepObject",value:n,...r});p&&a.push(p);}else {let p=b({allowReserved:e,name:o,value:n});p&&a.push(p);}}return a.join("&")},ye=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},qe=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,xe=async({security:e,...t})=>{for(let r of e){if(qe(t,r.name))continue;let s=await de(r,t.auth);if(!s)continue;let i=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[i]=s;break;case "cookie":t.headers.append("Cookie",`${i}=${s}`);break;case "header":default:t.headers.set(i,s);break}}},I=e=>ke({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:ge(e.querySerializer),url:e.url}),ke=({baseUrl:e,path:t,query:r,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,o=(e??"")+a;t&&(o=De({path:t,url:o}));let n=r?s(r):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(o+=`?${n}`),o},F=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=q(e.headers,t.headers),r},q=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let s=r instanceof Headers?r.entries():Object.entries(r);for(let[i,a]of s)if(a===null)t.delete(i);else if(Array.isArray(a))for(let o of a)t.append(i,o);else a!==void 0&&t.set(i,typeof a=="object"?JSON.stringify(a):a);}return t},P=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(t){return typeof t=="number"?this._fns[t]?t:-1:this._fns.indexOf(t)}exists(t){let r=this.getInterceptorIndex(t);return !!this._fns[r]}eject(t){let r=this.getInterceptorIndex(t);this._fns[r]&&(this._fns[r]=null);}update(t,r){let s=this.getInterceptorIndex(t);return this._fns[s]?(this._fns[s]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},me=()=>({error:new P,request:new P,response:new P}),ve=ge({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Ue={"Content-Type":"application/json"},_=(e={})=>({...ue,headers:Ue,parseAs:"auto",querySerializer:ve,...e});var N=(e={})=>{let t=F(_(),e),r=()=>({...t}),s=o=>(t=F(t,o),r()),i=me(),a=async o=>{let n={...t,...o,fetch:o.fetch??t.fetch??globalThis.fetch,headers:q(t.headers,o.headers),serializedBody:void 0};n.security&&await xe({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.serializedBody===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let p=I(n),u={redirect:"follow",...n,body:n.serializedBody},d=new Request(p,u);for(let l of i.request._fns)l&&(d=await l(d,n));let A=n.fetch,c=await A(d);for(let l of i.response._fns)l&&(c=await l(c,d,n));let E={request:d,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return n.responseStyle==="data"?{}:{data:{},...E};let l=(n.parseAs==="auto"?ye(c.headers.get("Content-Type")):n.parseAs)??"json",m;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":m=await c[l]();break;case "stream":return n.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(n.responseValidator&&await n.responseValidator(m),n.responseTransformer&&(m=await n.responseTransformer(m))),n.responseStyle==="data"?m:{data:m,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,f=R;for(let l of i.error._fns)l&&(f=await l(R,c,d,n));if(f=f||{},n.throwOnError)throw f;return n.responseStyle==="data"?void 0:{error:f,...E}};return {buildUrl:I,connect:o=>a({...o,method:"CONNECT"}),delete:o=>a({...o,method:"DELETE"}),get:o=>a({...o,method:"GET"}),getConfig:r,head:o=>a({...o,method:"HEAD"}),interceptors:i,options:o=>a({...o,method:"OPTIONS"}),patch:o=>a({...o,method:"PATCH"}),post:o=>a({...o,method:"POST"}),put:o=>a({...o,method:"PUT"}),request:a,setConfig:s,trace:o=>a({...o,method:"TRACE"})}};var g=N(_({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var ze=e=>(e?.client??g).get({url:"/openapi.yaml",...e}),Ge=e=>(e?.client??g).get({url:"/health",...e}),Ie=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Fe=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),j=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),B=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),K=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),L=e=>(e?.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),V=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??g).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),H=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),M=e=>(e.client??g).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),W=e=>(e?.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ce={};le(ce,{agentExecutePost:()=>ne,agentList:()=>re,executionActivitiesGet:()=>se,executionContextFilesGet:()=>ie,executionContextFilesUpload:()=>ae,executionGet:()=>We,executionUserMessagesAdd:()=>pe,executionsList:()=>oe,tempFilesStage:()=>Xe});var fe=(e,t,r)=>{typeof r=="string"||r instanceof Blob?e.append(t,r):r instanceof Date?e.append(t,r.toISOString()):e.append(t,JSON.stringify(r));};var k={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,s])=>{s!=null&&(Array.isArray(s)?s.forEach(i=>fe(t,r,i)):fe(t,r,s));}),t}},Q={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var Ae=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var Ne=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},je=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Be=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},J=({allowReserved:e,explode:t,name:r,style:s,value:i})=>{if(!t){let n=(e?i:i.map(p=>encodeURIComponent(p))).join(je(s));switch(s){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let a=Ne(s),o=i.map(n=>s==="label"||s==="simple"?e?n:encodeURIComponent(n):w({allowReserved:e,name:r,value:n})).join(a);return s==="label"||s==="matrix"?a+o:o},w=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},Y=({allowReserved:e,explode:t,name:r,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${r}=${i.toISOString()}`;if(s!=="deepObject"&&!t){let p=[];Object.entries(i).forEach(([d,A])=>{p=[...p,d,e?A:encodeURIComponent(A)];});let u=p.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let o=Be(s),n=Object.entries(i).map(([p,u])=>w({allowReserved:e,name:s==="deepObject"?`${r}[${p}]`:p,value:u})).join(o);return s==="label"||s==="matrix"?o+n:n};var Ke=/\{[^{}]+\}/g,Le=({path:e,url:t})=>{let r=t,s=t.match(Ke);if(s)for(let i of s){let a=false,o=i.substring(1,i.length-1),n="simple";o.endsWith("*")&&(a=true,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),n="label"):o.startsWith(";")&&(o=o.substring(1),n="matrix");let p=e[o];if(p==null)continue;if(Array.isArray(p)){r=r.replace(i,J({explode:a,name:o,style:n,value:p}));continue}if(typeof p=="object"){r=r.replace(i,Y({explode:a,name:o,style:n,value:p,valueOnly:true}));continue}if(n==="matrix"){r=r.replace(i,`;${w({name:o,value:p})}`);continue}let u=encodeURIComponent(n==="label"?`.${p}`:p);r=r.replace(i,u);}return r},Ee=({allowReserved:e,array:t,object:r}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let o in i){let n=i[o];if(n!=null)if(Array.isArray(n)){let p=J({allowReserved:e,explode:true,name:o,style:"form",value:n,...t});p&&a.push(p);}else if(typeof n=="object"){let p=Y({allowReserved:e,explode:true,name:o,style:"deepObject",value:n,...r});p&&a.push(p);}else {let p=w({allowReserved:e,name:o,value:n});p&&a.push(p);}}return a.join("&")},he=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},Ve=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,Se=async({security:e,...t})=>{for(let r of e){if(Ve(t,r.name))continue;let s=await Ae(r,t.auth);if(!s)continue;let i=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[i]=s;break;case "cookie":t.headers.append("Cookie",`${i}=${s}`);break;case "header":default:t.headers.set(i,s);break}}},Z=e=>$e({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:Ee(e.querySerializer),url:e.url}),$e=({baseUrl:e,path:t,query:r,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,o=(e??"")+a;t&&(o=Le({path:t,url:o}));let n=r?s(r):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(o+=`?${n}`),o},ee=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=v(e.headers,t.headers),r},v=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let s=r instanceof Headers?r.entries():Object.entries(r);for(let[i,a]of s)if(a===null)t.delete(i);else if(Array.isArray(a))for(let o of a)t.append(i,o);else a!==void 0&&t.set(i,typeof a=="object"?JSON.stringify(a):a);}return t},O=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(t){return typeof t=="number"?this._fns[t]?t:-1:this._fns.indexOf(t)}exists(t){let r=this.getInterceptorIndex(t);return !!this._fns[r]}eject(t){let r=this.getInterceptorIndex(t);this._fns[r]&&(this._fns[r]=null);}update(t,r){let s=this.getInterceptorIndex(t);return this._fns[s]?(this._fns[s]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},Ce=()=>({error:new O,request:new O,response:new O}),He=Ee({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Me={"Content-Type":"application/json"},T=(e={})=>({...Q,headers:Me,parseAs:"auto",querySerializer:He,...e});var te=(e={})=>{let t=ee(T(),e),r=()=>({...t}),s=o=>(t=ee(t,o),r()),i=Ce(),a=async o=>{let n={...t,...o,fetch:o.fetch??t.fetch??globalThis.fetch,headers:v(t.headers,o.headers),serializedBody:void 0};n.security&&await Se({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.serializedBody===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let p=Z(n),u={redirect:"follow",...n,body:n.serializedBody},d=new Request(p,u);for(let l of i.request._fns)l&&(d=await l(d,n));let A=n.fetch,c=await A(d);for(let l of i.response._fns)l&&(c=await l(c,d,n));let E={request:d,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return n.responseStyle==="data"?{}:{data:{},...E};let l=(n.parseAs==="auto"?he(c.headers.get("Content-Type")):n.parseAs)??"json",m;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":m=await c[l]();break;case "stream":return n.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(n.responseValidator&&await n.responseValidator(m),n.responseTransformer&&(m=await n.responseTransformer(m))),n.responseStyle==="data"?m:{data:m,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,f=R;for(let l of i.error._fns)l&&(f=await l(R,c,d,n));if(f=f||{},n.throwOnError)throw f;return n.responseStyle==="data"?void 0:{error:f,...E}};return {buildUrl:Z,connect:o=>a({...o,method:"CONNECT"}),delete:o=>a({...o,method:"DELETE"}),get:o=>a({...o,method:"GET"}),getConfig:r,head:o=>a({...o,method:"HEAD"}),interceptors:i,options:o=>a({...o,method:"OPTIONS"}),patch:o=>a({...o,method:"PATCH"}),post:o=>a({...o,method:"POST"}),put:o=>a({...o,method:"PUT"}),request:a,setConfig:s,trace:o=>a({...o,method:"TRACE"})}};var x=te(T({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var re=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),ne=e=>(e.client??x).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents/{agentId}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),oe=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),We=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}",...e}),se=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),ie=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),ae=e=>(e.client??x).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e,headers:{"Content-Type":null,...e.headers}}),pe=e=>(e.client??x).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),Xe=e=>(e.client??x).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});var Qe={};var Je={};var Ye=(e,t)=>{if(e.error){let r;throw typeof e.error=="object"&&e.error!==null&&"error"in e.error?r=e.error.error:typeof e.error=="string"?r=e.error:r=JSON.stringify(e.error),new Error(r||"Unknown error")}if(e.data===void 0)throw new Error(t||"No response data received");return e.data},y=async(e,t,r)=>{try{let s=await e();return Ye(s,r)}catch(s){throw s instanceof Error?s.message.includes("No response data received")||s.message.startsWith("Failed to")?s:new Error(`Failed to ${t}: ${s.message}`):new Error(`Failed to ${t}: Unknown error`)}},Bt=(e,t)=>(g.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),x.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),g.setConfig({baseUrl:t?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),x.setConfig({baseUrl:t?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:g,agentsV2Client:x}),Kt=async(e,t,r)=>(await y(()=>ne({client:e.agentsV2Client,path:{agentId:t},body:r}),"execute agent")).executionId,Ze=async(e,t)=>y(()=>j({client:e.agentsV1Client,path:{id:t}}),"get execution status"),et=async(e,t)=>{let r=await y(()=>B({client:e.agentsV1Client,path:{id:t}}),"get execution result");if(r.error)throw new Error(r.error);return r.execution_result||{}},Lt=async(e,t,r=1e3,s=36e5)=>{for(var i=Math.floor(s/r);i>0;){let a=await Ze(e,t),o=a.status;if(o==="completed")return await et(e,t);if(o==="failed"||o==="cancelled")throw new Error(`Execution ${t} ended with status: ${o}${a.reason?" - "+a.reason:""}`);await new Promise(n=>setTimeout(n,r)),i--;}throw new Error(`Execution ${t} timed out after ${s}ms`)},Vt=async(e,t)=>y(()=>K({client:e.agentsV1Client,path:{id:t}}),"get browser session recording"),$t=async(e,t,r)=>y(()=>ae({client:e.agentsV2Client,path:{executionId:t},body:{files:r}}),"upload execution files"),Ht=async(e,t)=>y(()=>L({client:e.agentsV1Client,query:t?{organization_id:t}:void 0}),"get agent profiles"),be=async e=>y(()=>W({client:e.agentsV1Client}),"get credentials public key","Public key not found"),Mt=async(e,t)=>{let r={...t};if(t.credentials&&t.credentials.length>0){let s=await be(e);r.credentials=t.credentials.map(i=>({...i,data:U(i.data,s)}));}return y(()=>V({client:e.agentsV1Client,body:r}),"create agent profile")},Wt=async(e,t)=>y(()=>H({client:e.agentsV1Client,path:{profile_id:t}}),"get agent profile"),Xt=async(e,t,r)=>{let s={...r};if(r.credentials_to_add&&r.credentials_to_add.length>0){let i=await be(e);s.credentials_to_add=r.credentials_to_add.map(a=>({...a,data:U(a.data,i)}));}return y(()=>M({client:e.agentsV1Client,path:{profile_id:t},body:s}),"update agent profile")},Qt=async(e,t)=>y(()=>$({client:e.agentsV1Client,path:{profile_id:t}}),"delete agent profile"),Jt=async(e,t,r)=>y(()=>se({client:e.agentsV2Client,path:{executionId:t},query:{limit:r,order:"desc"}}),"get execution activities"),Yt=async(e,t,r)=>{await y(()=>pe({client:e.agentsV2Client,path:{executionId:t},body:{message:r}}),"add message to execution");},Zt=async(e,t)=>y(()=>ie({client:e.agentsV2Client,path:{executionId:t}}),"get execution files"),er=async(e,t,r,s=true,i=30)=>{let a;h__default.default.existsSync(r)&&h__default.default.lstatSync(r).isDirectory()||r.endsWith("/")?a=Re__default.default.join(r,t.fileName):a=r;let o=Re__default.default.dirname(a);if(s&&!h__default.default.existsSync(o))h__default.default.mkdirSync(o,{recursive:true});else if(!s&&!h__default.default.existsSync(o))throw new Error(`Parent directory does not exist: ${o}`);try{let n=await fetch(t.signedUrl,{signal:AbortSignal.timeout(i*1e3)});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);let p=n.headers.get("content-length");if(p&&parseInt(p)!==t.fileSize)throw new Error(`Content length mismatch: expected ${t.fileSize}, got ${p}`);let u=await n.arrayBuffer(),d=Buffer.from(u);if(d.length!==t.fileSize)throw new Error(`Downloaded file size mismatch: expected ${t.fileSize}, got ${d.length}`);return h__default.default.writeFileSync(a,d),a}catch(n){throw n instanceof Error?new Error(`Failed to download file: ${n.message}`):new Error("Failed to download file: Unknown error")}},tr=async(e,t,r,s)=>(await y(()=>re({client:e.agentsV2Client,query:{organizationId:t,page:r,pageSize:s}}),"get agents")).items,rr=async(e,t)=>y(()=>oe({client:e.agentsV2Client,query:{organizationId:t.query.organizationId,page:t.query.page,pageSize:t.query.pageSize,executionId:t.query.executionId,agentId:t.query.agentId,status:t.query.status,agentVersion:t.query.agentVersion,createdAfter:t.query.createdAfter,createdBefore:t.query.createdBefore,humanLabels:t.query.humanLabels,outcomeLabel:t.query.outcomeLabel,sortField:t.query.sortField,sortDirection:t.query.sortDirection}}),"get executions");
2
- exports.AgentsV1SDK=X;exports.AgentsV1Types=Qe;exports.AgentsV2SDK=ce;exports.AgentsV2Types=Je;exports.AsteroidClient=Bt;exports.addMessageToExecution=Yt;exports.createAgentProfile=Mt;exports.deleteAgentProfile=Qt;exports.downloadExecutionFile=er;exports.executeAgent=Kt;exports.getAgentProfile=Wt;exports.getAgentProfiles=Ht;exports.getAgents=tr;exports.getBrowserSessionRecording=Vt;exports.getCredentialsPublicKey=be;exports.getExecutionFiles=Zt;exports.getExecutionResult=et;exports.getExecutionStatus=Ze;exports.getExecutions=rr;exports.getLastNExecutionActivities=Jt;exports.updateAgentProfile=Xt;exports.uploadExecutionFiles=$t;exports.waitForExecutionResult=Lt;
1
+ 'use strict';var $=(e,t,r)=>{typeof r=="string"||r instanceof Blob?e.append(t,r):r instanceof Date?e.append(t,r.toISOString()):e.append(t,JSON.stringify(r));};var q={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,s])=>{s!=null&&(Array.isArray(s)?s.forEach(o=>$(t,r,o)):$(t,r,s));}),t}},k={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var W=({onRequest:e,onSseError:t,onSseEvent:r,responseTransformer:s,responseValidator:o,sseDefaultRetryDelay:c,sseMaxRetryAttempts:a,sseMaxRetryDelay:i,sseSleepFn:l,url:u,...n})=>{let y,O=l??(p=>new Promise(x=>setTimeout(x,p)));return {stream:async function*(){let p=c??3e3,x=0,S=n.signal??new AbortController().signal;for(;!S.aborted;){x++;let b=n.headers instanceof Headers?n.headers:new Headers(n.headers);y!==void 0&&b.set("Last-Event-ID",y);try{let C={redirect:"follow",...n,body:n.serializedBody,headers:b,signal:S},h=new Request(u,C);e&&(h=await e(u,C));let g=await(n.fetch??globalThis.fetch)(h);if(!g.ok)throw new Error(`SSE failed: ${g.status} ${g.statusText}`);if(!g.body)throw new Error("No body in SSE response");let A=g.body.pipeThrough(new TextDecoderStream).getReader(),w="",B=()=>{try{A.cancel();}catch{}};S.addEventListener("abort",B);try{for(;;){let{done:ee,value:te}=await A.read();if(ee)break;w+=te,w=w.replace(/\r\n/g,`
2
+ `).replace(/\r/g,`
3
+ `);let K=w.split(`
4
+
5
+ `);w=K.pop()??"";for(let re of K){let ne=re.split(`
6
+ `),U=[],M;for(let m of ne)if(m.startsWith("data:"))U.push(m.replace(/^data:\s*/,""));else if(m.startsWith("event:"))M=m.replace(/^event:\s*/,"");else if(m.startsWith("id:"))y=m.replace(/^id:\s*/,"");else if(m.startsWith("retry:")){let H=Number.parseInt(m.replace(/^retry:\s*/,""),10);Number.isNaN(H)||(p=H);}let R,N=!1;if(U.length){let m=U.join(`
7
+ `);try{R=JSON.parse(m),N=!0;}catch{R=m;}}N&&(o&&await o(R),s&&(R=await s(R))),r?.({data:R,event:M,id:y,retry:p}),U.length&&(yield R);}}}finally{S.removeEventListener("abort",B),A.releaseLock();}break}catch(C){if(t?.(C),a!==void 0&&x>=a)break;let h=Math.min(p*2**(x-1),i??3e4);await O(h);}}}()}};var se=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},oe=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},ie=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},v=({allowReserved:e,explode:t,name:r,style:s,value:o})=>{if(!t){let i=(e?o:o.map(l=>encodeURIComponent(l))).join(oe(s));switch(s){case "label":return `.${i}`;case "matrix":return `;${r}=${i}`;case "simple":return i;default:return `${r}=${i}`}}let c=se(s),a=o.map(i=>s==="label"||s==="simple"?e?i:encodeURIComponent(i):P({allowReserved:e,name:r,value:i})).join(c);return s==="label"||s==="matrix"?c+a:a},P=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},I=({allowReserved:e,explode:t,name:r,style:s,value:o,valueOnly:c})=>{if(o instanceof Date)return c?o.toISOString():`${r}=${o.toISOString()}`;if(s!=="deepObject"&&!t){let l=[];Object.entries(o).forEach(([n,y])=>{l=[...l,n,e?y:encodeURIComponent(y)];});let u=l.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let a=ie(s),i=Object.entries(o).map(([l,u])=>P({allowReserved:e,name:s==="deepObject"?`${r}[${l}]`:l,value:u})).join(a);return s==="label"||s==="matrix"?a+i:i};var ae=/\{[^{}]+\}/g,le=({path:e,url:t})=>{let r=t,s=t.match(ae);if(s)for(let o of s){let c=false,a=o.substring(1,o.length-1),i="simple";a.endsWith("*")&&(c=true,a=a.substring(0,a.length-1)),a.startsWith(".")?(a=a.substring(1),i="label"):a.startsWith(";")&&(a=a.substring(1),i="matrix");let l=e[a];if(l==null)continue;if(Array.isArray(l)){r=r.replace(o,v({explode:c,name:a,style:i,value:l}));continue}if(typeof l=="object"){r=r.replace(o,I({explode:c,name:a,style:i,value:l,valueOnly:true}));continue}if(i==="matrix"){r=r.replace(o,`;${P({name:a,value:l})}`);continue}let u=encodeURIComponent(i==="label"?`.${l}`:l);r=r.replace(o,u);}return r},V=({baseUrl:e,path:t,query:r,querySerializer:s,url:o})=>{let c=o.startsWith("/")?o:`/${o}`,a=(e??"")+c;t&&(a=le({path:t,url:a}));let i=r?s(r):"";return i.startsWith("?")&&(i=i.substring(1)),i&&(a+=`?${i}`),a};function X(e){let t=e.body!==void 0;if(t&&e.bodySerializer)return "serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(t)return e.body}var Q=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var J=({parameters:e={},...t}={})=>s=>{let o=[];if(s&&typeof s=="object")for(let c in s){let a=s[c];if(a==null)continue;let i=e[c]||t;if(Array.isArray(a)){let l=v({allowReserved:i.allowReserved,explode:true,name:c,style:"form",value:a,...i.array});l&&o.push(l);}else if(typeof a=="object"){let l=I({allowReserved:i.allowReserved,explode:true,name:c,style:"deepObject",value:a,...i.object});l&&o.push(l);}else {let l=P({allowReserved:i.allowReserved,name:c,value:a});l&&o.push(l);}}return o.join("&")},_=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},ce=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,Y=async({security:e,...t})=>{for(let r of e){if(ce(t,r.name))continue;let s=await Q(r,t.auth);if(!s)continue;let o=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[o]=s;break;case "cookie":t.headers.append("Cookie",`${o}=${s}`);break;default:t.headers.set(o,s);break}}},G=e=>V({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:J(e.querySerializer),url:e.url}),j=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=F(e.headers,t.headers),r},pe=e=>{let t=[];return e.forEach((r,s)=>{t.push([s,r]);}),t},F=(...e)=>{let t=new Headers;for(let r of e){if(!r)continue;let s=r instanceof Headers?pe(r):Object.entries(r);for(let[o,c]of s)if(c===null)t.delete(o);else if(Array.isArray(c))for(let a of c)t.append(o,a);else c!==void 0&&t.set(o,typeof c=="object"?JSON.stringify(c):c);}return t},T=class{fns=[];clear(){this.fns=[];}eject(t){let r=this.getInterceptorIndex(t);this.fns[r]&&(this.fns[r]=null);}exists(t){let r=this.getInterceptorIndex(t);return !!this.fns[r]}getInterceptorIndex(t){return typeof t=="number"?this.fns[t]?t:-1:this.fns.indexOf(t)}update(t,r){let s=this.getInterceptorIndex(t);return this.fns[s]?(this.fns[s]=r,t):false}use(t){return this.fns.push(t),this.fns.length-1}},Z=()=>({error:new T,request:new T,response:new T}),ue=J({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),de={"Content-Type":"application/json"},D=(e={})=>({...k,headers:de,parseAs:"auto",querySerializer:ue,...e});var L=(e={})=>{let t=j(D(),e),r=()=>({...t}),s=u=>(t=j(t,u),r()),o=Z(),c=async u=>{let n={...t,...u,fetch:u.fetch??t.fetch??globalThis.fetch,headers:F(t.headers,u.headers),serializedBody:void 0};n.security&&await Y({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body!==void 0&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.body===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let y=G(n);return {opts:n,url:y}},a=async u=>{let{opts:n,url:y}=await c(u),O={redirect:"follow",...n,body:X(n)},E=new Request(y,O);for(let d of o.request.fns)d&&(E=await d(E,n));let z=n.fetch,p;try{p=await z(E);}catch(d){let g=d;for(let A of o.error.fns)A&&(g=await A(d,void 0,E,n));if(g=g||{},n.throwOnError)throw g;return n.responseStyle==="data"?void 0:{error:g,request:E,response:void 0}}for(let d of o.response.fns)d&&(p=await d(p,E,n));let x={request:E,response:p};if(p.ok){let d=(n.parseAs==="auto"?_(p.headers.get("Content-Type")):n.parseAs)??"json";if(p.status===204||p.headers.get("Content-Length")==="0"){let A;switch(d){case "arrayBuffer":case "blob":case "text":A=await p[d]();break;case "formData":A=new FormData;break;case "stream":A=p.body;break;default:A={};break}return n.responseStyle==="data"?A:{data:A,...x}}let g;switch(d){case "arrayBuffer":case "blob":case "formData":case "json":case "text":g=await p[d]();break;case "stream":return n.responseStyle==="data"?p.body:{data:p.body,...x}}return d==="json"&&(n.responseValidator&&await n.responseValidator(g),n.responseTransformer&&(g=await n.responseTransformer(g))),n.responseStyle==="data"?g:{data:g,...x}}let S=await p.text(),b;try{b=JSON.parse(S);}catch{}let C=b??S,h=C;for(let d of o.error.fns)d&&(h=await d(C,p,E,n));if(h=h||{},n.throwOnError)throw h;return n.responseStyle==="data"?void 0:{error:h,...x}},i=u=>n=>a({...n,method:u}),l=u=>async n=>{let{opts:y,url:O}=await c(n);return W({...y,body:y.body,headers:y.headers,method:u,onRequest:async(E,z)=>{let p=new Request(E,z);for(let x of o.request.fns)x&&(p=await x(p,y));return p},url:O})};return {buildUrl:G,connect:i("CONNECT"),delete:i("DELETE"),get:i("GET"),getConfig:r,head:i("HEAD"),interceptors:o,options:i("OPTIONS"),patch:i("PATCH"),post:i("POST"),put:i("PUT"),request:a,setConfig:s,sse:{connect:l("CONNECT"),delete:l("DELETE"),get:l("GET"),head:l("HEAD"),options:l("OPTIONS"),patch:l("PATCH"),post:l("POST"),put:l("PUT"),trace:l("TRACE")},trace:i("TRACE")}};var f=L(D({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var ge=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),fe=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),ye=e=>(e.client??f).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e}),xe=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e}),Ae=e=>(e.client??f).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ee=e=>(e.client??f).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}/clear-browser-cache",...e}),me=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),he=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents/{agentId}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),Se=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),Ce=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}",...e}),Re=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),Pe=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),Oe=e=>(e.client??f).post({...q,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e,headers:{"Content-Type":null,...e.headers}}),be=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/status",...e,headers:{"Content-Type":"application/json",...e.headers}}),we=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),Te=e=>(e.client??f).post({...q,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});
8
+ exports.agentExecutePost=he;exports.agentList=me;exports.agentProfileClearBrowserCache=Ee;exports.agentProfileDelete=ye;exports.agentProfileGet=xe;exports.agentProfileUpdate=Ae;exports.agentProfilesCreate=fe;exports.agentProfilesList=ge;exports.executionActivitiesGet=Re;exports.executionContextFilesGet=Pe;exports.executionContextFilesUpload=Oe;exports.executionGet=Ce;exports.executionStatusUpdate=be;exports.executionUserMessagesAdd=we;exports.executionsList=Se;exports.tempFilesStage=Te;
package/dist/index.mjs CHANGED
@@ -1,2 +1,8 @@
1
- import h from'fs';import Re from'path';import*as D from'node-forge';var Pe=Object.defineProperty;var le=(e,t)=>{for(var r in t)Pe(e,r,{get:t[r],enumerable:true});};function U(e,t){try{let s=D.pki.publicKeyFromPem(t).encrypt(e,"RSAES-PKCS1-V1_5");return D.util.encode64(s)}catch(r){throw console.error("Encryption failed:",r),new Error("Failed to encrypt: "+(r instanceof Error?r.message:"unknown error"))}}var X={};le(X,{createAgentProfile:()=>V,deleteAgentProfile:()=>$,executeAgent:()=>Ie,executeAgentStructured:()=>Fe,getAgentProfile:()=>H,getAgentProfiles:()=>L,getBrowserSessionRecording:()=>K,getCredentialsPublicKey:()=>W,getExecutionResult:()=>B,getExecutionStatus:()=>j,getOpenApi:()=>ze,healthCheck:()=>Ge,updateAgentProfile:()=>M});var ue={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var de=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var _e=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},we=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Oe=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},z=({allowReserved:e,explode:t,name:r,style:s,value:i})=>{if(!t){let n=(e?i:i.map(p=>encodeURIComponent(p))).join(we(s));switch(s){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let a=_e(s),o=i.map(n=>s==="label"||s==="simple"?e?n:encodeURIComponent(n):b({allowReserved:e,name:r,value:n})).join(a);return s==="label"||s==="matrix"?a+o:o},b=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},G=({allowReserved:e,explode:t,name:r,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${r}=${i.toISOString()}`;if(s!=="deepObject"&&!t){let p=[];Object.entries(i).forEach(([d,A])=>{p=[...p,d,e?A:encodeURIComponent(A)];});let u=p.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let o=Oe(s),n=Object.entries(i).map(([p,u])=>b({allowReserved:e,name:s==="deepObject"?`${r}[${p}]`:p,value:u})).join(o);return s==="label"||s==="matrix"?o+n:n};var Te=/\{[^{}]+\}/g,De=({path:e,url:t})=>{let r=t,s=t.match(Te);if(s)for(let i of s){let a=false,o=i.substring(1,i.length-1),n="simple";o.endsWith("*")&&(a=true,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),n="label"):o.startsWith(";")&&(o=o.substring(1),n="matrix");let p=e[o];if(p==null)continue;if(Array.isArray(p)){r=r.replace(i,z({explode:a,name:o,style:n,value:p}));continue}if(typeof p=="object"){r=r.replace(i,G({explode:a,name:o,style:n,value:p,valueOnly:true}));continue}if(n==="matrix"){r=r.replace(i,`;${b({name:o,value:p})}`);continue}let u=encodeURIComponent(n==="label"?`.${p}`:p);r=r.replace(i,u);}return r},ge=({allowReserved:e,array:t,object:r}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let o in i){let n=i[o];if(n!=null)if(Array.isArray(n)){let p=z({allowReserved:e,explode:true,name:o,style:"form",value:n,...t});p&&a.push(p);}else if(typeof n=="object"){let p=G({allowReserved:e,explode:true,name:o,style:"deepObject",value:n,...r});p&&a.push(p);}else {let p=b({allowReserved:e,name:o,value:n});p&&a.push(p);}}return a.join("&")},ye=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},qe=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,xe=async({security:e,...t})=>{for(let r of e){if(qe(t,r.name))continue;let s=await de(r,t.auth);if(!s)continue;let i=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[i]=s;break;case "cookie":t.headers.append("Cookie",`${i}=${s}`);break;case "header":default:t.headers.set(i,s);break}}},I=e=>ke({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:ge(e.querySerializer),url:e.url}),ke=({baseUrl:e,path:t,query:r,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,o=(e??"")+a;t&&(o=De({path:t,url:o}));let n=r?s(r):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(o+=`?${n}`),o},F=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=q(e.headers,t.headers),r},q=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let s=r instanceof Headers?r.entries():Object.entries(r);for(let[i,a]of s)if(a===null)t.delete(i);else if(Array.isArray(a))for(let o of a)t.append(i,o);else a!==void 0&&t.set(i,typeof a=="object"?JSON.stringify(a):a);}return t},P=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(t){return typeof t=="number"?this._fns[t]?t:-1:this._fns.indexOf(t)}exists(t){let r=this.getInterceptorIndex(t);return !!this._fns[r]}eject(t){let r=this.getInterceptorIndex(t);this._fns[r]&&(this._fns[r]=null);}update(t,r){let s=this.getInterceptorIndex(t);return this._fns[s]?(this._fns[s]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},me=()=>({error:new P,request:new P,response:new P}),ve=ge({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Ue={"Content-Type":"application/json"},_=(e={})=>({...ue,headers:Ue,parseAs:"auto",querySerializer:ve,...e});var N=(e={})=>{let t=F(_(),e),r=()=>({...t}),s=o=>(t=F(t,o),r()),i=me(),a=async o=>{let n={...t,...o,fetch:o.fetch??t.fetch??globalThis.fetch,headers:q(t.headers,o.headers),serializedBody:void 0};n.security&&await xe({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.serializedBody===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let p=I(n),u={redirect:"follow",...n,body:n.serializedBody},d=new Request(p,u);for(let l of i.request._fns)l&&(d=await l(d,n));let A=n.fetch,c=await A(d);for(let l of i.response._fns)l&&(c=await l(c,d,n));let E={request:d,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return n.responseStyle==="data"?{}:{data:{},...E};let l=(n.parseAs==="auto"?ye(c.headers.get("Content-Type")):n.parseAs)??"json",m;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":m=await c[l]();break;case "stream":return n.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(n.responseValidator&&await n.responseValidator(m),n.responseTransformer&&(m=await n.responseTransformer(m))),n.responseStyle==="data"?m:{data:m,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,f=R;for(let l of i.error._fns)l&&(f=await l(R,c,d,n));if(f=f||{},n.throwOnError)throw f;return n.responseStyle==="data"?void 0:{error:f,...E}};return {buildUrl:I,connect:o=>a({...o,method:"CONNECT"}),delete:o=>a({...o,method:"DELETE"}),get:o=>a({...o,method:"GET"}),getConfig:r,head:o=>a({...o,method:"HEAD"}),interceptors:i,options:o=>a({...o,method:"OPTIONS"}),patch:o=>a({...o,method:"PATCH"}),post:o=>a({...o,method:"POST"}),put:o=>a({...o,method:"PUT"}),request:a,setConfig:s,trace:o=>a({...o,method:"TRACE"})}};var g=N(_({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var ze=e=>(e?.client??g).get({url:"/openapi.yaml",...e}),Ge=e=>(e?.client??g).get({url:"/health",...e}),Ie=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Fe=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),j=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),B=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),K=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),L=e=>(e?.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),V=e=>(e.client??g).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??g).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),H=e=>(e.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),M=e=>(e.client??g).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),W=e=>(e?.client??g).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ce={};le(ce,{agentExecutePost:()=>ne,agentList:()=>re,executionActivitiesGet:()=>se,executionContextFilesGet:()=>ie,executionContextFilesUpload:()=>ae,executionGet:()=>We,executionUserMessagesAdd:()=>pe,executionsList:()=>oe,tempFilesStage:()=>Xe});var fe=(e,t,r)=>{typeof r=="string"||r instanceof Blob?e.append(t,r):r instanceof Date?e.append(t,r.toISOString()):e.append(t,JSON.stringify(r));};var k={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,s])=>{s!=null&&(Array.isArray(s)?s.forEach(i=>fe(t,r,i)):fe(t,r,s));}),t}},Q={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var Ae=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var Ne=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},je=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},Be=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},J=({allowReserved:e,explode:t,name:r,style:s,value:i})=>{if(!t){let n=(e?i:i.map(p=>encodeURIComponent(p))).join(je(s));switch(s){case "label":return `.${n}`;case "matrix":return `;${r}=${n}`;case "simple":return n;default:return `${r}=${n}`}}let a=Ne(s),o=i.map(n=>s==="label"||s==="simple"?e?n:encodeURIComponent(n):w({allowReserved:e,name:r,value:n})).join(a);return s==="label"||s==="matrix"?a+o:o},w=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},Y=({allowReserved:e,explode:t,name:r,style:s,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${r}=${i.toISOString()}`;if(s!=="deepObject"&&!t){let p=[];Object.entries(i).forEach(([d,A])=>{p=[...p,d,e?A:encodeURIComponent(A)];});let u=p.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let o=Be(s),n=Object.entries(i).map(([p,u])=>w({allowReserved:e,name:s==="deepObject"?`${r}[${p}]`:p,value:u})).join(o);return s==="label"||s==="matrix"?o+n:n};var Ke=/\{[^{}]+\}/g,Le=({path:e,url:t})=>{let r=t,s=t.match(Ke);if(s)for(let i of s){let a=false,o=i.substring(1,i.length-1),n="simple";o.endsWith("*")&&(a=true,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),n="label"):o.startsWith(";")&&(o=o.substring(1),n="matrix");let p=e[o];if(p==null)continue;if(Array.isArray(p)){r=r.replace(i,J({explode:a,name:o,style:n,value:p}));continue}if(typeof p=="object"){r=r.replace(i,Y({explode:a,name:o,style:n,value:p,valueOnly:true}));continue}if(n==="matrix"){r=r.replace(i,`;${w({name:o,value:p})}`);continue}let u=encodeURIComponent(n==="label"?`.${p}`:p);r=r.replace(i,u);}return r},Ee=({allowReserved:e,array:t,object:r}={})=>i=>{let a=[];if(i&&typeof i=="object")for(let o in i){let n=i[o];if(n!=null)if(Array.isArray(n)){let p=J({allowReserved:e,explode:true,name:o,style:"form",value:n,...t});p&&a.push(p);}else if(typeof n=="object"){let p=Y({allowReserved:e,explode:true,name:o,style:"deepObject",value:n,...r});p&&a.push(p);}else {let p=w({allowReserved:e,name:o,value:n});p&&a.push(p);}}return a.join("&")},he=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},Ve=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,Se=async({security:e,...t})=>{for(let r of e){if(Ve(t,r.name))continue;let s=await Ae(r,t.auth);if(!s)continue;let i=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[i]=s;break;case "cookie":t.headers.append("Cookie",`${i}=${s}`);break;case "header":default:t.headers.set(i,s);break}}},Z=e=>$e({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:Ee(e.querySerializer),url:e.url}),$e=({baseUrl:e,path:t,query:r,querySerializer:s,url:i})=>{let a=i.startsWith("/")?i:`/${i}`,o=(e??"")+a;t&&(o=Le({path:t,url:o}));let n=r?s(r):"";return n.startsWith("?")&&(n=n.substring(1)),n&&(o+=`?${n}`),o},ee=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=v(e.headers,t.headers),r},v=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let s=r instanceof Headers?r.entries():Object.entries(r);for(let[i,a]of s)if(a===null)t.delete(i);else if(Array.isArray(a))for(let o of a)t.append(i,o);else a!==void 0&&t.set(i,typeof a=="object"?JSON.stringify(a):a);}return t},O=class{_fns;constructor(){this._fns=[];}clear(){this._fns=[];}getInterceptorIndex(t){return typeof t=="number"?this._fns[t]?t:-1:this._fns.indexOf(t)}exists(t){let r=this.getInterceptorIndex(t);return !!this._fns[r]}eject(t){let r=this.getInterceptorIndex(t);this._fns[r]&&(this._fns[r]=null);}update(t,r){let s=this.getInterceptorIndex(t);return this._fns[s]?(this._fns[s]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},Ce=()=>({error:new O,request:new O,response:new O}),He=Ee({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),Me={"Content-Type":"application/json"},T=(e={})=>({...Q,headers:Me,parseAs:"auto",querySerializer:He,...e});var te=(e={})=>{let t=ee(T(),e),r=()=>({...t}),s=o=>(t=ee(t,o),r()),i=Ce(),a=async o=>{let n={...t,...o,fetch:o.fetch??t.fetch??globalThis.fetch,headers:v(t.headers,o.headers),serializedBody:void 0};n.security&&await Se({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.serializedBody===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let p=Z(n),u={redirect:"follow",...n,body:n.serializedBody},d=new Request(p,u);for(let l of i.request._fns)l&&(d=await l(d,n));let A=n.fetch,c=await A(d);for(let l of i.response._fns)l&&(c=await l(c,d,n));let E={request:d,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return n.responseStyle==="data"?{}:{data:{},...E};let l=(n.parseAs==="auto"?he(c.headers.get("Content-Type")):n.parseAs)??"json",m;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":m=await c[l]();break;case "stream":return n.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(n.responseValidator&&await n.responseValidator(m),n.responseTransformer&&(m=await n.responseTransformer(m))),n.responseStyle==="data"?m:{data:m,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,f=R;for(let l of i.error._fns)l&&(f=await l(R,c,d,n));if(f=f||{},n.throwOnError)throw f;return n.responseStyle==="data"?void 0:{error:f,...E}};return {buildUrl:Z,connect:o=>a({...o,method:"CONNECT"}),delete:o=>a({...o,method:"DELETE"}),get:o=>a({...o,method:"GET"}),getConfig:r,head:o=>a({...o,method:"HEAD"}),interceptors:i,options:o=>a({...o,method:"OPTIONS"}),patch:o=>a({...o,method:"PATCH"}),post:o=>a({...o,method:"POST"}),put:o=>a({...o,method:"PUT"}),request:a,setConfig:s,trace:o=>a({...o,method:"TRACE"})}};var x=te(T({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var re=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),ne=e=>(e.client??x).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents/{agentId}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),oe=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),We=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}",...e}),se=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),ie=e=>(e.client??x).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),ae=e=>(e.client??x).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e,headers:{"Content-Type":null,...e.headers}}),pe=e=>(e.client??x).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),Xe=e=>(e.client??x).post({...k,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});var Qe={};var Je={};var Ye=(e,t)=>{if(e.error){let r;throw typeof e.error=="object"&&e.error!==null&&"error"in e.error?r=e.error.error:typeof e.error=="string"?r=e.error:r=JSON.stringify(e.error),new Error(r||"Unknown error")}if(e.data===void 0)throw new Error(t||"No response data received");return e.data},y=async(e,t,r)=>{try{let s=await e();return Ye(s,r)}catch(s){throw s instanceof Error?s.message.includes("No response data received")||s.message.startsWith("Failed to")?s:new Error(`Failed to ${t}: ${s.message}`):new Error(`Failed to ${t}: Unknown error`)}},Bt=(e,t)=>(g.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),x.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),g.setConfig({baseUrl:t?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),x.setConfig({baseUrl:t?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:g,agentsV2Client:x}),Kt=async(e,t,r)=>(await y(()=>ne({client:e.agentsV2Client,path:{agentId:t},body:r}),"execute agent")).executionId,Ze=async(e,t)=>y(()=>j({client:e.agentsV1Client,path:{id:t}}),"get execution status"),et=async(e,t)=>{let r=await y(()=>B({client:e.agentsV1Client,path:{id:t}}),"get execution result");if(r.error)throw new Error(r.error);return r.execution_result||{}},Lt=async(e,t,r=1e3,s=36e5)=>{for(var i=Math.floor(s/r);i>0;){let a=await Ze(e,t),o=a.status;if(o==="completed")return await et(e,t);if(o==="failed"||o==="cancelled")throw new Error(`Execution ${t} ended with status: ${o}${a.reason?" - "+a.reason:""}`);await new Promise(n=>setTimeout(n,r)),i--;}throw new Error(`Execution ${t} timed out after ${s}ms`)},Vt=async(e,t)=>y(()=>K({client:e.agentsV1Client,path:{id:t}}),"get browser session recording"),$t=async(e,t,r)=>y(()=>ae({client:e.agentsV2Client,path:{executionId:t},body:{files:r}}),"upload execution files"),Ht=async(e,t)=>y(()=>L({client:e.agentsV1Client,query:t?{organization_id:t}:void 0}),"get agent profiles"),be=async e=>y(()=>W({client:e.agentsV1Client}),"get credentials public key","Public key not found"),Mt=async(e,t)=>{let r={...t};if(t.credentials&&t.credentials.length>0){let s=await be(e);r.credentials=t.credentials.map(i=>({...i,data:U(i.data,s)}));}return y(()=>V({client:e.agentsV1Client,body:r}),"create agent profile")},Wt=async(e,t)=>y(()=>H({client:e.agentsV1Client,path:{profile_id:t}}),"get agent profile"),Xt=async(e,t,r)=>{let s={...r};if(r.credentials_to_add&&r.credentials_to_add.length>0){let i=await be(e);s.credentials_to_add=r.credentials_to_add.map(a=>({...a,data:U(a.data,i)}));}return y(()=>M({client:e.agentsV1Client,path:{profile_id:t},body:s}),"update agent profile")},Qt=async(e,t)=>y(()=>$({client:e.agentsV1Client,path:{profile_id:t}}),"delete agent profile"),Jt=async(e,t,r)=>y(()=>se({client:e.agentsV2Client,path:{executionId:t},query:{limit:r,order:"desc"}}),"get execution activities"),Yt=async(e,t,r)=>{await y(()=>pe({client:e.agentsV2Client,path:{executionId:t},body:{message:r}}),"add message to execution");},Zt=async(e,t)=>y(()=>ie({client:e.agentsV2Client,path:{executionId:t}}),"get execution files"),er=async(e,t,r,s=true,i=30)=>{let a;h.existsSync(r)&&h.lstatSync(r).isDirectory()||r.endsWith("/")?a=Re.join(r,t.fileName):a=r;let o=Re.dirname(a);if(s&&!h.existsSync(o))h.mkdirSync(o,{recursive:true});else if(!s&&!h.existsSync(o))throw new Error(`Parent directory does not exist: ${o}`);try{let n=await fetch(t.signedUrl,{signal:AbortSignal.timeout(i*1e3)});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);let p=n.headers.get("content-length");if(p&&parseInt(p)!==t.fileSize)throw new Error(`Content length mismatch: expected ${t.fileSize}, got ${p}`);let u=await n.arrayBuffer(),d=Buffer.from(u);if(d.length!==t.fileSize)throw new Error(`Downloaded file size mismatch: expected ${t.fileSize}, got ${d.length}`);return h.writeFileSync(a,d),a}catch(n){throw n instanceof Error?new Error(`Failed to download file: ${n.message}`):new Error("Failed to download file: Unknown error")}},tr=async(e,t,r,s)=>(await y(()=>re({client:e.agentsV2Client,query:{organizationId:t,page:r,pageSize:s}}),"get agents")).items,rr=async(e,t)=>y(()=>oe({client:e.agentsV2Client,query:{organizationId:t.query.organizationId,page:t.query.page,pageSize:t.query.pageSize,executionId:t.query.executionId,agentId:t.query.agentId,status:t.query.status,agentVersion:t.query.agentVersion,createdAfter:t.query.createdAfter,createdBefore:t.query.createdBefore,humanLabels:t.query.humanLabels,outcomeLabel:t.query.outcomeLabel,sortField:t.query.sortField,sortDirection:t.query.sortDirection}}),"get executions");
2
- export{X as AgentsV1SDK,Qe as AgentsV1Types,ce as AgentsV2SDK,Je as AgentsV2Types,Bt as AsteroidClient,Yt as addMessageToExecution,Mt as createAgentProfile,Qt as deleteAgentProfile,er as downloadExecutionFile,Kt as executeAgent,Wt as getAgentProfile,Ht as getAgentProfiles,tr as getAgents,Vt as getBrowserSessionRecording,be as getCredentialsPublicKey,Zt as getExecutionFiles,et as getExecutionResult,Ze as getExecutionStatus,rr as getExecutions,Jt as getLastNExecutionActivities,Xt as updateAgentProfile,$t as uploadExecutionFiles,Lt as waitForExecutionResult};
1
+ var $=(e,t,r)=>{typeof r=="string"||r instanceof Blob?e.append(t,r):r instanceof Date?e.append(t,r.toISOString()):e.append(t,JSON.stringify(r));};var q={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,s])=>{s!=null&&(Array.isArray(s)?s.forEach(o=>$(t,r,o)):$(t,r,s));}),t}},k={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var W=({onRequest:e,onSseError:t,onSseEvent:r,responseTransformer:s,responseValidator:o,sseDefaultRetryDelay:c,sseMaxRetryAttempts:a,sseMaxRetryDelay:i,sseSleepFn:l,url:u,...n})=>{let y,O=l??(p=>new Promise(x=>setTimeout(x,p)));return {stream:async function*(){let p=c??3e3,x=0,S=n.signal??new AbortController().signal;for(;!S.aborted;){x++;let b=n.headers instanceof Headers?n.headers:new Headers(n.headers);y!==void 0&&b.set("Last-Event-ID",y);try{let C={redirect:"follow",...n,body:n.serializedBody,headers:b,signal:S},h=new Request(u,C);e&&(h=await e(u,C));let g=await(n.fetch??globalThis.fetch)(h);if(!g.ok)throw new Error(`SSE failed: ${g.status} ${g.statusText}`);if(!g.body)throw new Error("No body in SSE response");let A=g.body.pipeThrough(new TextDecoderStream).getReader(),w="",B=()=>{try{A.cancel();}catch{}};S.addEventListener("abort",B);try{for(;;){let{done:ee,value:te}=await A.read();if(ee)break;w+=te,w=w.replace(/\r\n/g,`
2
+ `).replace(/\r/g,`
3
+ `);let K=w.split(`
4
+
5
+ `);w=K.pop()??"";for(let re of K){let ne=re.split(`
6
+ `),U=[],M;for(let m of ne)if(m.startsWith("data:"))U.push(m.replace(/^data:\s*/,""));else if(m.startsWith("event:"))M=m.replace(/^event:\s*/,"");else if(m.startsWith("id:"))y=m.replace(/^id:\s*/,"");else if(m.startsWith("retry:")){let H=Number.parseInt(m.replace(/^retry:\s*/,""),10);Number.isNaN(H)||(p=H);}let R,N=!1;if(U.length){let m=U.join(`
7
+ `);try{R=JSON.parse(m),N=!0;}catch{R=m;}}N&&(o&&await o(R),s&&(R=await s(R))),r?.({data:R,event:M,id:y,retry:p}),U.length&&(yield R);}}}finally{S.removeEventListener("abort",B),A.releaseLock();}break}catch(C){if(t?.(C),a!==void 0&&x>=a)break;let h=Math.min(p*2**(x-1),i??3e4);await O(h);}}}()}};var se=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},oe=e=>{switch(e){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},ie=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},v=({allowReserved:e,explode:t,name:r,style:s,value:o})=>{if(!t){let i=(e?o:o.map(l=>encodeURIComponent(l))).join(oe(s));switch(s){case "label":return `.${i}`;case "matrix":return `;${r}=${i}`;case "simple":return i;default:return `${r}=${i}`}}let c=se(s),a=o.map(i=>s==="label"||s==="simple"?e?i:encodeURIComponent(i):P({allowReserved:e,name:r,value:i})).join(c);return s==="label"||s==="matrix"?c+a:a},P=({allowReserved:e,name:t,value:r})=>{if(r==null)return "";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${t}=${e?r:encodeURIComponent(r)}`},I=({allowReserved:e,explode:t,name:r,style:s,value:o,valueOnly:c})=>{if(o instanceof Date)return c?o.toISOString():`${r}=${o.toISOString()}`;if(s!=="deepObject"&&!t){let l=[];Object.entries(o).forEach(([n,y])=>{l=[...l,n,e?y:encodeURIComponent(y)];});let u=l.join(",");switch(s){case "form":return `${r}=${u}`;case "label":return `.${u}`;case "matrix":return `;${r}=${u}`;default:return u}}let a=ie(s),i=Object.entries(o).map(([l,u])=>P({allowReserved:e,name:s==="deepObject"?`${r}[${l}]`:l,value:u})).join(a);return s==="label"||s==="matrix"?a+i:i};var ae=/\{[^{}]+\}/g,le=({path:e,url:t})=>{let r=t,s=t.match(ae);if(s)for(let o of s){let c=false,a=o.substring(1,o.length-1),i="simple";a.endsWith("*")&&(c=true,a=a.substring(0,a.length-1)),a.startsWith(".")?(a=a.substring(1),i="label"):a.startsWith(";")&&(a=a.substring(1),i="matrix");let l=e[a];if(l==null)continue;if(Array.isArray(l)){r=r.replace(o,v({explode:c,name:a,style:i,value:l}));continue}if(typeof l=="object"){r=r.replace(o,I({explode:c,name:a,style:i,value:l,valueOnly:true}));continue}if(i==="matrix"){r=r.replace(o,`;${P({name:a,value:l})}`);continue}let u=encodeURIComponent(i==="label"?`.${l}`:l);r=r.replace(o,u);}return r},V=({baseUrl:e,path:t,query:r,querySerializer:s,url:o})=>{let c=o.startsWith("/")?o:`/${o}`,a=(e??"")+c;t&&(a=le({path:t,url:a}));let i=r?s(r):"";return i.startsWith("?")&&(i=i.substring(1)),i&&(a+=`?${i}`),a};function X(e){let t=e.body!==void 0;if(t&&e.bodySerializer)return "serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(t)return e.body}var Q=async(e,t)=>{let r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r};var J=({parameters:e={},...t}={})=>s=>{let o=[];if(s&&typeof s=="object")for(let c in s){let a=s[c];if(a==null)continue;let i=e[c]||t;if(Array.isArray(a)){let l=v({allowReserved:i.allowReserved,explode:true,name:c,style:"form",value:a,...i.array});l&&o.push(l);}else if(typeof a=="object"){let l=I({allowReserved:i.allowReserved,explode:true,name:c,style:"deepObject",value:a,...i.object});l&&o.push(l);}else {let l=P({allowReserved:i.allowReserved,name:c,value:a});l&&o.push(l);}}return o.join("&")},_=e=>{if(!e)return "stream";let t=e.split(";")[0]?.trim();if(t){if(t.startsWith("application/json")||t.endsWith("+json"))return "json";if(t==="multipart/form-data")return "formData";if(["application/","audio/","image/","video/"].some(r=>t.startsWith(r)))return "blob";if(t.startsWith("text/"))return "text"}},ce=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get("Cookie")?.includes(`${t}=`)):false,Y=async({security:e,...t})=>{for(let r of e){if(ce(t,r.name))continue;let s=await Q(r,t.auth);if(!s)continue;let o=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[o]=s;break;case "cookie":t.headers.append("Cookie",`${o}=${s}`);break;default:t.headers.set(o,s);break}}},G=e=>V({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:J(e.querySerializer),url:e.url}),j=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=F(e.headers,t.headers),r},pe=e=>{let t=[];return e.forEach((r,s)=>{t.push([s,r]);}),t},F=(...e)=>{let t=new Headers;for(let r of e){if(!r)continue;let s=r instanceof Headers?pe(r):Object.entries(r);for(let[o,c]of s)if(c===null)t.delete(o);else if(Array.isArray(c))for(let a of c)t.append(o,a);else c!==void 0&&t.set(o,typeof c=="object"?JSON.stringify(c):c);}return t},T=class{fns=[];clear(){this.fns=[];}eject(t){let r=this.getInterceptorIndex(t);this.fns[r]&&(this.fns[r]=null);}exists(t){let r=this.getInterceptorIndex(t);return !!this.fns[r]}getInterceptorIndex(t){return typeof t=="number"?this.fns[t]?t:-1:this.fns.indexOf(t)}update(t,r){let s=this.getInterceptorIndex(t);return this.fns[s]?(this.fns[s]=r,t):false}use(t){return this.fns.push(t),this.fns.length-1}},Z=()=>({error:new T,request:new T,response:new T}),ue=J({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),de={"Content-Type":"application/json"},D=(e={})=>({...k,headers:de,parseAs:"auto",querySerializer:ue,...e});var L=(e={})=>{let t=j(D(),e),r=()=>({...t}),s=u=>(t=j(t,u),r()),o=Z(),c=async u=>{let n={...t,...u,fetch:u.fetch??t.fetch??globalThis.fetch,headers:F(t.headers,u.headers),serializedBody:void 0};n.security&&await Y({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body!==void 0&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.body===void 0||n.serializedBody==="")&&n.headers.delete("Content-Type");let y=G(n);return {opts:n,url:y}},a=async u=>{let{opts:n,url:y}=await c(u),O={redirect:"follow",...n,body:X(n)},E=new Request(y,O);for(let d of o.request.fns)d&&(E=await d(E,n));let z=n.fetch,p;try{p=await z(E);}catch(d){let g=d;for(let A of o.error.fns)A&&(g=await A(d,void 0,E,n));if(g=g||{},n.throwOnError)throw g;return n.responseStyle==="data"?void 0:{error:g,request:E,response:void 0}}for(let d of o.response.fns)d&&(p=await d(p,E,n));let x={request:E,response:p};if(p.ok){let d=(n.parseAs==="auto"?_(p.headers.get("Content-Type")):n.parseAs)??"json";if(p.status===204||p.headers.get("Content-Length")==="0"){let A;switch(d){case "arrayBuffer":case "blob":case "text":A=await p[d]();break;case "formData":A=new FormData;break;case "stream":A=p.body;break;default:A={};break}return n.responseStyle==="data"?A:{data:A,...x}}let g;switch(d){case "arrayBuffer":case "blob":case "formData":case "json":case "text":g=await p[d]();break;case "stream":return n.responseStyle==="data"?p.body:{data:p.body,...x}}return d==="json"&&(n.responseValidator&&await n.responseValidator(g),n.responseTransformer&&(g=await n.responseTransformer(g))),n.responseStyle==="data"?g:{data:g,...x}}let S=await p.text(),b;try{b=JSON.parse(S);}catch{}let C=b??S,h=C;for(let d of o.error.fns)d&&(h=await d(C,p,E,n));if(h=h||{},n.throwOnError)throw h;return n.responseStyle==="data"?void 0:{error:h,...x}},i=u=>n=>a({...n,method:u}),l=u=>async n=>{let{opts:y,url:O}=await c(n);return W({...y,body:y.body,headers:y.headers,method:u,onRequest:async(E,z)=>{let p=new Request(E,z);for(let x of o.request.fns)x&&(p=await x(p,y));return p},url:O})};return {buildUrl:G,connect:i("CONNECT"),delete:i("DELETE"),get:i("GET"),getConfig:r,head:i("HEAD"),interceptors:o,options:i("OPTIONS"),patch:i("PATCH"),post:i("POST"),put:i("PUT"),request:a,setConfig:s,sse:{connect:l("CONNECT"),delete:l("DELETE"),get:l("GET"),head:l("HEAD"),options:l("OPTIONS"),patch:l("PATCH"),post:l("POST"),put:l("PUT"),trace:l("TRACE")},trace:i("TRACE")}};var f=L(D({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var ge=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),fe=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),ye=e=>(e.client??f).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e}),xe=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e}),Ae=e=>(e.client??f).patch({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ee=e=>(e.client??f).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profileId}/clear-browser-cache",...e}),me=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),he=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents/{agentId}/execute",...e,headers:{"Content-Type":"application/json",...e.headers}}),Se=e=>(e?.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),Ce=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}",...e}),Re=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),Pe=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),Oe=e=>(e.client??f).post({...q,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e,headers:{"Content-Type":null,...e.headers}}),be=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/status",...e,headers:{"Content-Type":"application/json",...e.headers}}),we=e=>(e.client??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),Te=e=>(e.client??f).post({...q,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});
8
+ export{he as agentExecutePost,me as agentList,Ee as agentProfileClearBrowserCache,ye as agentProfileDelete,xe as agentProfileGet,Ae as agentProfileUpdate,fe as agentProfilesCreate,ge as agentProfilesList,Re as executionActivitiesGet,Pe as executionContextFilesGet,Oe as executionContextFilesUpload,Ce as executionGet,be as executionStatusUpdate,we as executionUserMessagesAdd,Se as executionsList,Te as tempFilesStage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asteroid-odyssey",
3
- "version": "1.3.11",
3
+ "version": "1.6.4",
4
4
  "description": "SDK for interacting with Asteroid Agents API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,20 +25,17 @@
25
25
  }
26
26
  },
27
27
  "devDependencies": {
28
- "@types/node": "^22.13.4",
29
- "@types/node-forge": "^1.3.11",
30
- "openapi-typescript-codegen": "^0.29.0",
28
+ "@types/node": "^25.0.0",
31
29
  "prettier": "^3.6.2",
32
- "ts-node": "^10.9.2",
33
30
  "tsup": "^8.0.2",
34
- "typescript": "^5.7.3"
31
+ "typescript": "^5.7.3",
32
+ "undici-types": "^7.16.0"
35
33
  },
36
34
  "dependencies": {
37
- "@hey-api/openapi-ts": "^0.82.0",
38
- "node-forge": "^1.3.1"
35
+ "@hey-api/openapi-ts": "^0.89.0"
39
36
  },
40
37
  "scripts": {
41
38
  "build": "tsup --config tsup.config.ts",
42
- "generate": "openapi-ts --file v1.config.ts && openapi-ts --file v2.config.ts"
39
+ "generate": "openapi-ts --file openapi-ts.config.ts"
43
40
  }
44
41
  }