asteroid-odyssey 1.3.10 → 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'),v=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 v__namespace=/*#__PURE__*/_interopNamespace(v);var Pe=Object.defineProperty;var le=(e,t)=>{for(var r in t)Pe(e,r,{get:t[r],enumerable:true});};function q(e,t){try{let i=v__namespace.pki.publicKeyFromPem(t).encrypt(e,"RSAES-PKCS1-V1_5");return v__namespace.util.encode64(i)}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:()=>Fe,executeAgentStructured:()=>Ge,getAgentProfile:()=>M,getAgentProfiles:()=>L,getBrowserSessionRecording:()=>K,getCredentialsPublicKey:()=>W,getExecutionResult:()=>B,getExecutionStatus:()=>j,getOpenApi:()=>ke,healthCheck:()=>ze,updateAgentProfile:()=>H});var de={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var ue=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 we=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},_e=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 "&"}},k=({allowReserved:e,explode:t,name:r,style:i,value:s})=>{if(!t){let o=(e?s:s.map(p=>encodeURIComponent(p))).join(_e(i));switch(i){case "label":return `.${o}`;case "matrix":return `;${r}=${o}`;case "simple":return o;default:return `${r}=${o}`}}let a=we(i),n=s.map(o=>i==="label"||i==="simple"?e?o:encodeURIComponent(o):b({allowReserved:e,name:r,value:o})).join(a);return i==="label"||i==="matrix"?a+n:n},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)}`},z=({allowReserved:e,explode:t,name:r,style:i,value:s,valueOnly:a})=>{if(s instanceof Date)return a?s.toISOString():`${r}=${s.toISOString()}`;if(i!=="deepObject"&&!t){let p=[];Object.entries(s).forEach(([u,m])=>{p=[...p,u,e?m:encodeURIComponent(m)];});let d=p.join(",");switch(i){case "form":return `${r}=${d}`;case "label":return `.${d}`;case "matrix":return `;${r}=${d}`;default:return d}}let n=Oe(i),o=Object.entries(s).map(([p,d])=>b({allowReserved:e,name:i==="deepObject"?`${r}[${p}]`:p,value:d})).join(n);return i==="label"||i==="matrix"?n+o:o};var Te=/\{[^{}]+\}/g,ve=({path:e,url:t})=>{let r=t,i=t.match(Te);if(i)for(let s of i){let a=false,n=s.substring(1,s.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)){r=r.replace(s,k({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){r=r.replace(s,z({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){r=r.replace(s,`;${b({name:n,value:p})}`);continue}let d=encodeURIComponent(o==="label"?`.${p}`:p);r=r.replace(s,d);}return r},ye=({allowReserved:e,array:t,object:r}={})=>s=>{let a=[];if(s&&typeof s=="object")for(let n in s){let o=s[n];if(o!=null)if(Array.isArray(o)){let p=k({allowReserved:e,explode:true,name:n,style:"form",value:o,...t});p&&a.push(p);}else if(typeof o=="object"){let p=z({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...r});p&&a.push(p);}else {let p=b({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ge=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"}},De=(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(De(t,r.name))continue;let i=await ue(r,t.auth);if(!i)continue;let s=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[s]=i;break;case "cookie":t.headers.append("Cookie",`${s}=${i}`);break;case "header":default:t.headers.set(s,i);break}}},F=e=>Ue({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:ye(e.querySerializer),url:e.url}),Ue=({baseUrl:e,path:t,query:r,querySerializer:i,url:s})=>{let a=s.startsWith("/")?s:`/${s}`,n=(e??"")+a;t&&(n=ve({path:t,url:n}));let o=r?i(r):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},G=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=D(e.headers,t.headers),r},D=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let i=r instanceof Headers?r.entries():Object.entries(r);for(let[s,a]of i)if(a===null)t.delete(s);else if(Array.isArray(a))for(let n of a)t.append(s,n);else a!==void 0&&t.set(s,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 i=this.getInterceptorIndex(t);return this._fns[i]?(this._fns[i]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},fe=()=>({error:new P,request:new P,response:new P}),Ie=ye({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),qe={"Content-Type":"application/json"},w=(e={})=>({...de,headers:qe,parseAs:"auto",querySerializer:Ie,...e});var N=(e={})=>{let t=G(w(),e),r=()=>({...t}),i=n=>(t=G(t,n),r()),s=fe(),a=async n=>{let o={...t,...n,fetch:n.fetch??t.fetch??globalThis.fetch,headers:D(t.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=F(o),d={redirect:"follow",...o,body:o.serializedBody},u=new Request(p,d);for(let l of s.request._fns)l&&(u=await l(u,o));let m=o.fetch,c=await m(u);for(let l of s.response._fns)l&&(c=await l(c,u,o));let E={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...E};let l=(o.parseAs==="auto"?ge(c.headers.get("Content-Type")):o.parseAs)??"json",x;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":x=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(o.responseValidator&&await o.responseValidator(x),o.responseTransformer&&(x=await o.responseTransformer(x))),o.responseStyle==="data"?x:{data:x,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,A=R;for(let l of s.error._fns)l&&(A=await l(R,c,u,o));if(A=A||{},o.throwOnError)throw A;return o.responseStyle==="data"?void 0:{error:A,...E}};return {buildUrl:F,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:r,head:n=>a({...n,method:"HEAD"}),interceptors:s,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:i,trace:n=>a({...n,method:"TRACE"})}};var y=N(w({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var ke=e=>(e?.client??y).get({url:"/openapi.yaml",...e}),ze=e=>(e?.client??y).get({url:"/health",...e}),Fe=e=>(e.client??y).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ge=e=>(e.client??y).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??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),B=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),K=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),L=e=>(e?.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),V=e=>(e.client??y).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??y).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),M=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),H=e=>(e.client??y).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??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ce={};le(ce,{agentExecutePost:()=>oe,agentList:()=>re,executionActivitiesGet:()=>ie,executionContextFilesGet:()=>se,executionContextFilesUpload:()=>ae,executionUserMessagesAdd:()=>pe,executionsList:()=>ne,tempFilesStage:()=>We});var Ae=(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 U={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,i])=>{i!=null&&(Array.isArray(i)?i.forEach(s=>Ae(t,r,s)):Ae(t,r,i));}),t}},Q={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var me=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:i,value:s})=>{if(!t){let o=(e?s:s.map(p=>encodeURIComponent(p))).join(je(i));switch(i){case "label":return `.${o}`;case "matrix":return `;${r}=${o}`;case "simple":return o;default:return `${r}=${o}`}}let a=Ne(i),n=s.map(o=>i==="label"||i==="simple"?e?o:encodeURIComponent(o):_({allowReserved:e,name:r,value:o})).join(a);return i==="label"||i==="matrix"?a+n:n},_=({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:i,value:s,valueOnly:a})=>{if(s instanceof Date)return a?s.toISOString():`${r}=${s.toISOString()}`;if(i!=="deepObject"&&!t){let p=[];Object.entries(s).forEach(([u,m])=>{p=[...p,u,e?m:encodeURIComponent(m)];});let d=p.join(",");switch(i){case "form":return `${r}=${d}`;case "label":return `.${d}`;case "matrix":return `;${r}=${d}`;default:return d}}let n=Be(i),o=Object.entries(s).map(([p,d])=>_({allowReserved:e,name:i==="deepObject"?`${r}[${p}]`:p,value:d})).join(n);return i==="label"||i==="matrix"?n+o:o};var Ke=/\{[^{}]+\}/g,Le=({path:e,url:t})=>{let r=t,i=t.match(Ke);if(i)for(let s of i){let a=false,n=s.substring(1,s.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)){r=r.replace(s,J({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){r=r.replace(s,Y({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){r=r.replace(s,`;${_({name:n,value:p})}`);continue}let d=encodeURIComponent(o==="label"?`.${p}`:p);r=r.replace(s,d);}return r},Ee=({allowReserved:e,array:t,object:r}={})=>s=>{let a=[];if(s&&typeof s=="object")for(let n in s){let o=s[n];if(o!=null)if(Array.isArray(o)){let p=J({allowReserved:e,explode:true,name:n,style:"form",value:o,...t});p&&a.push(p);}else if(typeof o=="object"){let p=Y({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...r});p&&a.push(p);}else {let p=_({allowReserved:e,name:n,value:o});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 i=await me(r,t.auth);if(!i)continue;let s=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[s]=i;break;case "cookie":t.headers.append("Cookie",`${s}=${i}`);break;case "header":default:t.headers.set(s,i);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:i,url:s})=>{let a=s.startsWith("/")?s:`/${s}`,n=(e??"")+a;t&&(n=Le({path:t,url:n}));let o=r?i(r):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},ee=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=I(e.headers,t.headers),r},I=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let i=r instanceof Headers?r.entries():Object.entries(r);for(let[s,a]of i)if(a===null)t.delete(s);else if(Array.isArray(a))for(let n of a)t.append(s,n);else a!==void 0&&t.set(s,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 i=this.getInterceptorIndex(t);return this._fns[i]?(this._fns[i]=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}),Me=Ee({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),He={"Content-Type":"application/json"},T=(e={})=>({...Q,headers:He,parseAs:"auto",querySerializer:Me,...e});var te=(e={})=>{let t=ee(T(),e),r=()=>({...t}),i=n=>(t=ee(t,n),r()),s=Ce(),a=async n=>{let o={...t,...n,fetch:n.fetch??t.fetch??globalThis.fetch,headers:I(t.headers,n.headers),serializedBody:void 0};o.security&&await Se({...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),d={redirect:"follow",...o,body:o.serializedBody},u=new Request(p,d);for(let l of s.request._fns)l&&(u=await l(u,o));let m=o.fetch,c=await m(u);for(let l of s.response._fns)l&&(c=await l(c,u,o));let E={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...E};let l=(o.parseAs==="auto"?he(c.headers.get("Content-Type")):o.parseAs)??"json",x;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":x=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(o.responseValidator&&await o.responseValidator(x),o.responseTransformer&&(x=await o.responseTransformer(x))),o.responseStyle==="data"?x:{data:x,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,A=R;for(let l of s.error._fns)l&&(A=await l(R,c,u,o));if(A=A||{},o.throwOnError)throw A;return o.responseStyle==="data"?void 0:{error:A,...E}};return {buildUrl:Z,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:r,head:n=>a({...n,method:"HEAD"}),interceptors:s,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:i,trace:n=>a({...n,method:"TRACE"})}};var f=te(T({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var re=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),oe=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}}),ne=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),ie=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),se=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),ae=e=>(e.client??f).post({...U,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??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),We=e=>(e.client??f).post({...U,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});var Xe={};var Qe={};var Je=(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},g=async(e,t,r)=>{try{let i=await e();return Je(i,r)}catch(i){throw i instanceof Error?i.message.includes("No response data received")||i.message.startsWith("Failed to")?i:new Error(`Failed to ${t}: ${i.message}`):new Error(`Failed to ${t}: Unknown error`)}},jt=(e,t)=>(y.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),f.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),y.setConfig({baseUrl:t?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),f.setConfig({baseUrl:t?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:y,agentsV2Client:f}),Bt=async(e,t,r)=>(await g(()=>oe({client:e.agentsV2Client,path:{agentId:t},body:r}),"execute agent")).executionId,Ye=async(e,t)=>g(()=>j({client:e.agentsV1Client,path:{id:t}}),"get execution status"),Ze=async(e,t)=>{let r=await g(()=>B({client:e.agentsV1Client,path:{id:t}}),"get execution result");if(r.error)throw new Error(r.error);return r.execution_result||{}},Kt=async(e,t,r=1e3,i=36e5)=>{for(var s=Math.floor(i/r);s>0;){let a=await Ye(e,t),n=a.status;if(n==="completed")return await Ze(e,t);if(n==="failed"||n==="cancelled")throw new Error(`Execution ${t} ended with status: ${n}${a.reason?" - "+a.reason:""}`);await new Promise(o=>setTimeout(o,r)),s--;}throw new Error(`Execution ${t} timed out after ${i}ms`)},Lt=async(e,t)=>g(()=>K({client:e.agentsV1Client,path:{id:t}}),"get browser session recording"),Vt=async(e,t,r)=>g(()=>ae({client:e.agentsV2Client,path:{executionId:t},body:{files:r}}),"upload execution files"),$t=async(e,t)=>g(()=>L({client:e.agentsV1Client,query:t?{organization_id:t}:void 0}),"get agent profiles"),be=async e=>g(()=>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 i=await be(e);r.credentials=t.credentials.map(s=>({...s,data:q(s.data,i)}));}return g(()=>V({client:e.agentsV1Client,body:r}),"create agent profile")},Ht=async(e,t)=>g(()=>M({client:e.agentsV1Client,path:{profile_id:t}}),"get agent profile"),Wt=async(e,t,r)=>{let i={...r};if(r.credentials_to_add&&r.credentials_to_add.length>0){let s=await be(e);i.credentials_to_add=r.credentials_to_add.map(a=>({...a,data:q(a.data,s)}));}return g(()=>H({client:e.agentsV1Client,path:{profile_id:t},body:i}),"update agent profile")},Xt=async(e,t)=>g(()=>$({client:e.agentsV1Client,path:{profile_id:t}}),"delete agent profile"),Qt=async(e,t,r)=>g(()=>ie({client:e.agentsV2Client,path:{executionId:t},query:{limit:r,order:"desc"}}),"get execution activities"),Jt=async(e,t,r)=>{await g(()=>pe({client:e.agentsV2Client,path:{executionId:t},body:{message:r}}),"add message to execution");},Yt=async(e,t)=>g(()=>se({client:e.agentsV2Client,path:{executionId:t}}),"get execution files"),Zt=async(e,t,r,i=true,s=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 n=Re__default.default.dirname(a);if(i&&!h__default.default.existsSync(n))h__default.default.mkdirSync(n,{recursive:true});else if(!i&&!h__default.default.existsSync(n))throw new Error(`Parent directory does not exist: ${n}`);try{let o=await fetch(t.signedUrl,{signal:AbortSignal.timeout(s*1e3)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let p=o.headers.get("content-length");if(p&&parseInt(p)!==t.fileSize)throw new Error(`Content length mismatch: expected ${t.fileSize}, got ${p}`);let d=await o.arrayBuffer(),u=Buffer.from(d);if(u.length!==t.fileSize)throw new Error(`Downloaded file size mismatch: expected ${t.fileSize}, got ${u.length}`);return h__default.default.writeFileSync(a,u),a}catch(o){throw o instanceof Error?new Error(`Failed to download file: ${o.message}`):new Error("Failed to download file: Unknown error")}},er=async(e,t,r,i)=>(await g(()=>re({client:e.agentsV2Client,query:{organizationId:t,page:r,pageSize:i}}),"get agents")).items,tr=async(e,t)=>g(()=>ne({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=Xe;exports.AgentsV2SDK=ce;exports.AgentsV2Types=Qe;exports.AsteroidClient=jt;exports.addMessageToExecution=Jt;exports.createAgentProfile=Mt;exports.deleteAgentProfile=Xt;exports.downloadExecutionFile=Zt;exports.executeAgent=Bt;exports.getAgentProfile=Ht;exports.getAgentProfiles=$t;exports.getAgents=er;exports.getBrowserSessionRecording=Lt;exports.getCredentialsPublicKey=be;exports.getExecutionFiles=Yt;exports.getExecutionResult=Ze;exports.getExecutionStatus=Ye;exports.getExecutions=tr;exports.getLastNExecutionActivities=Qt;exports.updateAgentProfile=Wt;exports.uploadExecutionFiles=Vt;exports.waitForExecutionResult=Kt;
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 v 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 q(e,t){try{let i=v.pki.publicKeyFromPem(t).encrypt(e,"RSAES-PKCS1-V1_5");return v.util.encode64(i)}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:()=>Fe,executeAgentStructured:()=>Ge,getAgentProfile:()=>M,getAgentProfiles:()=>L,getBrowserSessionRecording:()=>K,getCredentialsPublicKey:()=>W,getExecutionResult:()=>B,getExecutionStatus:()=>j,getOpenApi:()=>ke,healthCheck:()=>ze,updateAgentProfile:()=>H});var de={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var ue=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 we=e=>{switch(e){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},_e=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 "&"}},k=({allowReserved:e,explode:t,name:r,style:i,value:s})=>{if(!t){let o=(e?s:s.map(p=>encodeURIComponent(p))).join(_e(i));switch(i){case "label":return `.${o}`;case "matrix":return `;${r}=${o}`;case "simple":return o;default:return `${r}=${o}`}}let a=we(i),n=s.map(o=>i==="label"||i==="simple"?e?o:encodeURIComponent(o):b({allowReserved:e,name:r,value:o})).join(a);return i==="label"||i==="matrix"?a+n:n},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)}`},z=({allowReserved:e,explode:t,name:r,style:i,value:s,valueOnly:a})=>{if(s instanceof Date)return a?s.toISOString():`${r}=${s.toISOString()}`;if(i!=="deepObject"&&!t){let p=[];Object.entries(s).forEach(([u,m])=>{p=[...p,u,e?m:encodeURIComponent(m)];});let d=p.join(",");switch(i){case "form":return `${r}=${d}`;case "label":return `.${d}`;case "matrix":return `;${r}=${d}`;default:return d}}let n=Oe(i),o=Object.entries(s).map(([p,d])=>b({allowReserved:e,name:i==="deepObject"?`${r}[${p}]`:p,value:d})).join(n);return i==="label"||i==="matrix"?n+o:o};var Te=/\{[^{}]+\}/g,ve=({path:e,url:t})=>{let r=t,i=t.match(Te);if(i)for(let s of i){let a=false,n=s.substring(1,s.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)){r=r.replace(s,k({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){r=r.replace(s,z({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){r=r.replace(s,`;${b({name:n,value:p})}`);continue}let d=encodeURIComponent(o==="label"?`.${p}`:p);r=r.replace(s,d);}return r},ye=({allowReserved:e,array:t,object:r}={})=>s=>{let a=[];if(s&&typeof s=="object")for(let n in s){let o=s[n];if(o!=null)if(Array.isArray(o)){let p=k({allowReserved:e,explode:true,name:n,style:"form",value:o,...t});p&&a.push(p);}else if(typeof o=="object"){let p=z({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...r});p&&a.push(p);}else {let p=b({allowReserved:e,name:n,value:o});p&&a.push(p);}}return a.join("&")},ge=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"}},De=(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(De(t,r.name))continue;let i=await ue(r,t.auth);if(!i)continue;let s=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[s]=i;break;case "cookie":t.headers.append("Cookie",`${s}=${i}`);break;case "header":default:t.headers.set(s,i);break}}},F=e=>Ue({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:ye(e.querySerializer),url:e.url}),Ue=({baseUrl:e,path:t,query:r,querySerializer:i,url:s})=>{let a=s.startsWith("/")?s:`/${s}`,n=(e??"")+a;t&&(n=ve({path:t,url:n}));let o=r?i(r):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},G=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=D(e.headers,t.headers),r},D=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let i=r instanceof Headers?r.entries():Object.entries(r);for(let[s,a]of i)if(a===null)t.delete(s);else if(Array.isArray(a))for(let n of a)t.append(s,n);else a!==void 0&&t.set(s,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 i=this.getInterceptorIndex(t);return this._fns[i]?(this._fns[i]=r,t):false}use(t){return this._fns=[...this._fns,t],this._fns.length-1}},fe=()=>({error:new P,request:new P,response:new P}),Ie=ye({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),qe={"Content-Type":"application/json"},w=(e={})=>({...de,headers:qe,parseAs:"auto",querySerializer:Ie,...e});var N=(e={})=>{let t=G(w(),e),r=()=>({...t}),i=n=>(t=G(t,n),r()),s=fe(),a=async n=>{let o={...t,...n,fetch:n.fetch??t.fetch??globalThis.fetch,headers:D(t.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=F(o),d={redirect:"follow",...o,body:o.serializedBody},u=new Request(p,d);for(let l of s.request._fns)l&&(u=await l(u,o));let m=o.fetch,c=await m(u);for(let l of s.response._fns)l&&(c=await l(c,u,o));let E={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...E};let l=(o.parseAs==="auto"?ge(c.headers.get("Content-Type")):o.parseAs)??"json",x;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":x=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(o.responseValidator&&await o.responseValidator(x),o.responseTransformer&&(x=await o.responseTransformer(x))),o.responseStyle==="data"?x:{data:x,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,A=R;for(let l of s.error._fns)l&&(A=await l(R,c,u,o));if(A=A||{},o.throwOnError)throw A;return o.responseStyle==="data"?void 0:{error:A,...E}};return {buildUrl:F,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:r,head:n=>a({...n,method:"HEAD"}),interceptors:s,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:i,trace:n=>a({...n,method:"TRACE"})}};var y=N(w({baseUrl:"https://odyssey.asteroid.ai/api/v1"}));var ke=e=>(e?.client??y).get({url:"/openapi.yaml",...e}),ze=e=>(e?.client??y).get({url:"/health",...e}),Fe=e=>(e.client??y).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent/{id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ge=e=>(e.client??y).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??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/status",...e}),B=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/result",...e}),K=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/execution/{id}/browser_session/recording",...e}),L=e=>(e?.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e}),V=e=>(e.client??y).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles",...e,headers:{"Content-Type":"application/json",...e.headers}}),$=e=>(e.client??y).delete({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),M=e=>(e.client??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agent-profiles/{profile_id}",...e}),H=e=>(e.client??y).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??y).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/credentials/public_key",...e});var ce={};le(ce,{agentExecutePost:()=>oe,agentList:()=>re,executionActivitiesGet:()=>ie,executionContextFilesGet:()=>se,executionContextFilesUpload:()=>ae,executionUserMessagesAdd:()=>pe,executionsList:()=>ne,tempFilesStage:()=>We});var Ae=(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 U={bodySerializer:e=>{let t=new FormData;return Object.entries(e).forEach(([r,i])=>{i!=null&&(Array.isArray(i)?i.forEach(s=>Ae(t,r,s)):Ae(t,r,i));}),t}},Q={bodySerializer:e=>JSON.stringify(e,(t,r)=>typeof r=="bigint"?r.toString():r)};var me=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:i,value:s})=>{if(!t){let o=(e?s:s.map(p=>encodeURIComponent(p))).join(je(i));switch(i){case "label":return `.${o}`;case "matrix":return `;${r}=${o}`;case "simple":return o;default:return `${r}=${o}`}}let a=Ne(i),n=s.map(o=>i==="label"||i==="simple"?e?o:encodeURIComponent(o):_({allowReserved:e,name:r,value:o})).join(a);return i==="label"||i==="matrix"?a+n:n},_=({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:i,value:s,valueOnly:a})=>{if(s instanceof Date)return a?s.toISOString():`${r}=${s.toISOString()}`;if(i!=="deepObject"&&!t){let p=[];Object.entries(s).forEach(([u,m])=>{p=[...p,u,e?m:encodeURIComponent(m)];});let d=p.join(",");switch(i){case "form":return `${r}=${d}`;case "label":return `.${d}`;case "matrix":return `;${r}=${d}`;default:return d}}let n=Be(i),o=Object.entries(s).map(([p,d])=>_({allowReserved:e,name:i==="deepObject"?`${r}[${p}]`:p,value:d})).join(n);return i==="label"||i==="matrix"?n+o:o};var Ke=/\{[^{}]+\}/g,Le=({path:e,url:t})=>{let r=t,i=t.match(Ke);if(i)for(let s of i){let a=false,n=s.substring(1,s.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)){r=r.replace(s,J({explode:a,name:n,style:o,value:p}));continue}if(typeof p=="object"){r=r.replace(s,Y({explode:a,name:n,style:o,value:p,valueOnly:true}));continue}if(o==="matrix"){r=r.replace(s,`;${_({name:n,value:p})}`);continue}let d=encodeURIComponent(o==="label"?`.${p}`:p);r=r.replace(s,d);}return r},Ee=({allowReserved:e,array:t,object:r}={})=>s=>{let a=[];if(s&&typeof s=="object")for(let n in s){let o=s[n];if(o!=null)if(Array.isArray(o)){let p=J({allowReserved:e,explode:true,name:n,style:"form",value:o,...t});p&&a.push(p);}else if(typeof o=="object"){let p=Y({allowReserved:e,explode:true,name:n,style:"deepObject",value:o,...r});p&&a.push(p);}else {let p=_({allowReserved:e,name:n,value:o});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 i=await me(r,t.auth);if(!i)continue;let s=r.name??"Authorization";switch(r.in){case "query":t.query||(t.query={}),t.query[s]=i;break;case "cookie":t.headers.append("Cookie",`${s}=${i}`);break;case "header":default:t.headers.set(s,i);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:i,url:s})=>{let a=s.startsWith("/")?s:`/${s}`,n=(e??"")+a;t&&(n=Le({path:t,url:n}));let o=r?i(r):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(n+=`?${o}`),n},ee=(e,t)=>{let r={...e,...t};return r.baseUrl?.endsWith("/")&&(r.baseUrl=r.baseUrl.substring(0,r.baseUrl.length-1)),r.headers=I(e.headers,t.headers),r},I=(...e)=>{let t=new Headers;for(let r of e){if(!r||typeof r!="object")continue;let i=r instanceof Headers?r.entries():Object.entries(r);for(let[s,a]of i)if(a===null)t.delete(s);else if(Array.isArray(a))for(let n of a)t.append(s,n);else a!==void 0&&t.set(s,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 i=this.getInterceptorIndex(t);return this._fns[i]?(this._fns[i]=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}),Me=Ee({allowReserved:false,array:{explode:true,style:"form"},object:{explode:true,style:"deepObject"}}),He={"Content-Type":"application/json"},T=(e={})=>({...Q,headers:He,parseAs:"auto",querySerializer:Me,...e});var te=(e={})=>{let t=ee(T(),e),r=()=>({...t}),i=n=>(t=ee(t,n),r()),s=Ce(),a=async n=>{let o={...t,...n,fetch:n.fetch??t.fetch??globalThis.fetch,headers:I(t.headers,n.headers),serializedBody:void 0};o.security&&await Se({...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),d={redirect:"follow",...o,body:o.serializedBody},u=new Request(p,d);for(let l of s.request._fns)l&&(u=await l(u,o));let m=o.fetch,c=await m(u);for(let l of s.response._fns)l&&(c=await l(c,u,o));let E={request:u,response:c};if(c.ok){if(c.status===204||c.headers.get("Content-Length")==="0")return o.responseStyle==="data"?{}:{data:{},...E};let l=(o.parseAs==="auto"?he(c.headers.get("Content-Type")):o.parseAs)??"json",x;switch(l){case "arrayBuffer":case "blob":case "formData":case "json":case "text":x=await c[l]();break;case "stream":return o.responseStyle==="data"?c.body:{data:c.body,...E}}return l==="json"&&(o.responseValidator&&await o.responseValidator(x),o.responseTransformer&&(x=await o.responseTransformer(x))),o.responseStyle==="data"?x:{data:x,...E}}let S=await c.text(),C;try{C=JSON.parse(S);}catch{}let R=C??S,A=R;for(let l of s.error._fns)l&&(A=await l(R,c,u,o));if(A=A||{},o.throwOnError)throw A;return o.responseStyle==="data"?void 0:{error:A,...E}};return {buildUrl:Z,connect:n=>a({...n,method:"CONNECT"}),delete:n=>a({...n,method:"DELETE"}),get:n=>a({...n,method:"GET"}),getConfig:r,head:n=>a({...n,method:"HEAD"}),interceptors:s,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:i,trace:n=>a({...n,method:"TRACE"})}};var f=te(T({baseUrl:"https://odyssey.asteroid.ai/agents/v2"}));var re=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/agents",...e}),oe=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}}),ne=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions",...e}),ie=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/activities",...e}),se=e=>(e.client??f).get({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/context-files",...e}),ae=e=>(e.client??f).post({...U,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??f).post({security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/executions/{executionId}/user-messages",...e,headers:{"Content-Type":"application/json",...e.headers}}),We=e=>(e.client??f).post({...U,security:[{name:"X-Asteroid-Agents-Api-Key",type:"apiKey"}],url:"/temp-files/{organizationId}",...e,headers:{"Content-Type":null,...e.headers}});var Xe={};var Qe={};var Je=(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},g=async(e,t,r)=>{try{let i=await e();return Je(i,r)}catch(i){throw i instanceof Error?i.message.includes("No response data received")||i.message.startsWith("Failed to")?i:new Error(`Failed to ${t}: ${i.message}`):new Error(`Failed to ${t}: Unknown error`)}},jt=(e,t)=>(y.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),f.setConfig({headers:{"X-Asteroid-Agents-Api-Key":e}}),y.setConfig({baseUrl:t?.v1?.baseUrl||"https://odyssey.asteroid.ai/api/v1"}),f.setConfig({baseUrl:t?.v2?.baseUrl||"https://odyssey.asteroid.ai/agents/v2"}),{agentsV1Client:y,agentsV2Client:f}),Bt=async(e,t,r)=>(await g(()=>oe({client:e.agentsV2Client,path:{agentId:t},body:r}),"execute agent")).executionId,Ye=async(e,t)=>g(()=>j({client:e.agentsV1Client,path:{id:t}}),"get execution status"),Ze=async(e,t)=>{let r=await g(()=>B({client:e.agentsV1Client,path:{id:t}}),"get execution result");if(r.error)throw new Error(r.error);return r.execution_result||{}},Kt=async(e,t,r=1e3,i=36e5)=>{for(var s=Math.floor(i/r);s>0;){let a=await Ye(e,t),n=a.status;if(n==="completed")return await Ze(e,t);if(n==="failed"||n==="cancelled")throw new Error(`Execution ${t} ended with status: ${n}${a.reason?" - "+a.reason:""}`);await new Promise(o=>setTimeout(o,r)),s--;}throw new Error(`Execution ${t} timed out after ${i}ms`)},Lt=async(e,t)=>g(()=>K({client:e.agentsV1Client,path:{id:t}}),"get browser session recording"),Vt=async(e,t,r)=>g(()=>ae({client:e.agentsV2Client,path:{executionId:t},body:{files:r}}),"upload execution files"),$t=async(e,t)=>g(()=>L({client:e.agentsV1Client,query:t?{organization_id:t}:void 0}),"get agent profiles"),be=async e=>g(()=>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 i=await be(e);r.credentials=t.credentials.map(s=>({...s,data:q(s.data,i)}));}return g(()=>V({client:e.agentsV1Client,body:r}),"create agent profile")},Ht=async(e,t)=>g(()=>M({client:e.agentsV1Client,path:{profile_id:t}}),"get agent profile"),Wt=async(e,t,r)=>{let i={...r};if(r.credentials_to_add&&r.credentials_to_add.length>0){let s=await be(e);i.credentials_to_add=r.credentials_to_add.map(a=>({...a,data:q(a.data,s)}));}return g(()=>H({client:e.agentsV1Client,path:{profile_id:t},body:i}),"update agent profile")},Xt=async(e,t)=>g(()=>$({client:e.agentsV1Client,path:{profile_id:t}}),"delete agent profile"),Qt=async(e,t,r)=>g(()=>ie({client:e.agentsV2Client,path:{executionId:t},query:{limit:r,order:"desc"}}),"get execution activities"),Jt=async(e,t,r)=>{await g(()=>pe({client:e.agentsV2Client,path:{executionId:t},body:{message:r}}),"add message to execution");},Yt=async(e,t)=>g(()=>se({client:e.agentsV2Client,path:{executionId:t}}),"get execution files"),Zt=async(e,t,r,i=true,s=30)=>{let a;h.existsSync(r)&&h.lstatSync(r).isDirectory()||r.endsWith("/")?a=Re.join(r,t.fileName):a=r;let n=Re.dirname(a);if(i&&!h.existsSync(n))h.mkdirSync(n,{recursive:true});else if(!i&&!h.existsSync(n))throw new Error(`Parent directory does not exist: ${n}`);try{let o=await fetch(t.signedUrl,{signal:AbortSignal.timeout(s*1e3)});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let p=o.headers.get("content-length");if(p&&parseInt(p)!==t.fileSize)throw new Error(`Content length mismatch: expected ${t.fileSize}, got ${p}`);let d=await o.arrayBuffer(),u=Buffer.from(d);if(u.length!==t.fileSize)throw new Error(`Downloaded file size mismatch: expected ${t.fileSize}, got ${u.length}`);return h.writeFileSync(a,u),a}catch(o){throw o instanceof Error?new Error(`Failed to download file: ${o.message}`):new Error("Failed to download file: Unknown error")}},er=async(e,t,r,i)=>(await g(()=>re({client:e.agentsV2Client,query:{organizationId:t,page:r,pageSize:i}}),"get agents")).items,tr=async(e,t)=>g(()=>ne({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,Xe as AgentsV1Types,ce as AgentsV2SDK,Qe as AgentsV2Types,jt as AsteroidClient,Jt as addMessageToExecution,Mt as createAgentProfile,Xt as deleteAgentProfile,Zt as downloadExecutionFile,Bt as executeAgent,Ht as getAgentProfile,$t as getAgentProfiles,er as getAgents,Lt as getBrowserSessionRecording,be as getCredentialsPublicKey,Yt as getExecutionFiles,Ze as getExecutionResult,Ye as getExecutionStatus,tr as getExecutions,Qt as getLastNExecutionActivities,Wt as updateAgentProfile,Vt as uploadExecutionFiles,Kt 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.10",
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
  }