asteroid-odyssey 1.3.10 → 1.3.11

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,2 @@
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 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;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
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
+ 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asteroid-odyssey",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "description": "SDK for interacting with Asteroid Agents API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",