evolve-sdk 0.0.52.dev756__tar.gz → 0.0.52.dev760__tar.gz
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.
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/PKG-INFO +1 -1
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/bridge/dist/bridge.bundle.cjs +3 -3
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/__init__.py +7 -1
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/hosted.py +177 -7
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/PKG-INFO +1 -1
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/pyproject.toml +1 -1
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/LICENSE +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/MANIFEST.in +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/README.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/bridge/__init__.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/_http.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/agent.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/bridge.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/browser_credentials.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/browser_profiles.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/config.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/integrations.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/managed_secrets.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/pipeline/__init__.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/pipeline/pipeline.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/pipeline/types.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/__init__.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/agent_md/judge.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/agent_md/reduce.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/agent_md/verify.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/user/judge.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/user/retry_feedback.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/prompts/user/verify.md +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/results.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/retry.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/schema.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/sessions_client.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/storage_client.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/swarm/__init__.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/swarm/results.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/swarm/swarm.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/swarm/types.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve/utils.py +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/SOURCES.txt +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/dependency_links.txt +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/requires.txt +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/top_level.txt +0 -0
- {evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/setup.cfg +0 -0
|
@@ -640,8 +640,8 @@ ${C}
|
|
|
640
640
|
${f}
|
|
641
641
|
\`\`\``:f}});else if(Array.isArray(f)){for(let m of f)if(m.type==="text"){let v=m.text;p.push({type:"content",content:{type:"text",text:d?`\`\`\`
|
|
642
642
|
${v}
|
|
643
|
-
\`\`\``:v}})}}return{sessionUpdate:"tool_call_update",toolCallId:u,status:d?"failed":"completed",content:p}}function c(l,u){let d=q0n[l]||"other",f=[],p=[],m=l;switch(l){case"Read":case"read_file":m=`Read ${u.file_path||u.absolute_path||"file"}`,(u.file_path||u.absolute_path)&&p.push({path:u.file_path||u.absolute_path});break;case"Write":case"write_file":m=`Write ${u.file_path||"file"}`,u.file_path&&(p.push({path:u.file_path}),f.push({type:"diff",path:u.file_path,oldText:null,newText:u.content||""}));break;case"Edit":case"edit_file":m=`Edit ${u.file_path||"file"}`,u.file_path&&p.push({path:u.file_path});break;case"Bash":case"shell":case"run_shell_command":m=u.command?`\`${u.command}\``:"Run command",u.description&&f.push({type:"content",content:{type:"text",text:u.description}});break;case"WebFetch":m=u.url?`Fetch ${u.url}`:"Web fetch";break;case"WebSearch":case"brave_web_search":m=u.query?`"${u.query}"`:"Web search";break;case"Glob":m=`Find ${u.pattern||"files"}`,u.path&&p.push({path:u.path});break;case"Grep":m=`grep "${u.pattern||""}"`;break;case"LS":case"list_directory":m=`List ${u.path||"directory"}`,u.path&&p.push({path:u.path});break;case"Task":m=u.description||"Subagent task";break;case"TodoWrite":m="Update todos";break;case"ExitPlanMode":m="Exit plan mode";break;default:m=l}return{title:m,kind:d,content:f,locations:p}}}function V5t(e){switch(e){case"claude":return d0n();case"codex":return f0n();case"gemini":return T0n();case"qwen":return V0n();case"kimi":return P0n();case"opencode":return L0n();case"droid":return m0n();default:return()=>null}}var $0n=(0,DK.promisify)(rU.execFile),QS="SKILL.md",G0n=(0,Zt.join)((0,W0.homedir)(),".cache","evolve","skills"),sTe=["skills","skills/.curated","skills/.experimental","skills/.system",".claude/skills"],H0n=/^([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+)(?:@(.+))?$/,z0n=/^[0-9a-f]{40}$/,j8t=2e3,Y8t=64*1024*1024,Hw=class extends Error{constructor(e){super(e),this.name="SkillRefError"}},z0=class extends Error{constructor(e){super(e),this.name="SkillResolveError"}};function W0n(e){return e==="~"?(0,W0.homedir)():e.startsWith("~/")?(0,Zt.join)((0,W0.homedir)(),e.slice(2)):e}function J0n(e){let t=e.indexOf("@");if(t===-1)return{base:e};let r=e.slice(t+1);if(!r)throw new Hw(`Empty @ref in skill reference segment: ${JSON.stringify(e)}`);return{base:e.slice(0,t),gitRef:r}}var j0n=/^[A-Za-z0-9._-]+$/;function qxe(e,t,r){if(!j0n.test(e))throw new Hw(`Cannot parse skill reference ${JSON.stringify(r)}: ${t} ${JSON.stringify(e)} may only contain letters, digits, ".", "_" and "-".`);return e}function Y0n(e){let t=String(e??"").trim();if(!t)throw new Hw("Skill reference cannot be empty.");if(t.startsWith("upload:")){let s=t.slice(7);if(!s)throw new Hw(`Skill upload reference ${JSON.stringify(t)} names no upload id.`);return{kind:"upload",id:s,raw:t}}if(t.startsWith("./")||t.startsWith("../")||t.startsWith("/")||t.startsWith("~"))return{kind:"local",path:W0n(t),raw:t};let r=t.match(/^(?:https?:\/\/)?(?:www\.)?skills\.sh\/(.+)$/);if(r){let s=r[1].replace(/\/+$/,"").split("/").filter(Boolean);if(s.length<2||s.length>3)throw new Hw(`Cannot parse skill reference ${JSON.stringify(t)}: expected skills.sh/<owner>/<repo> or skills.sh/<owner>/<repo>/<skill>, optionally @ref.`);let{base:o,gitRef:a}=J0n(s[s.length-1]);s[s.length-1]=o;let[c,l,u]=s;return qxe(c,"owner",t),qxe(l,"repo",t),u!==void 0&&qxe(u,"skill name",t),{kind:"git",host:"github.com",org:c,repo:l,...a?{gitRef:a}:{},...u?{skillName:u}:{},viaSkillsSh:!0,raw:t}}let n=t.match(/^https?:\/\/([^/]+)\/(.+)$/);if(n){let s=n[1],o=n[2].replace(/\/+$/,"").split("/").filter(Boolean);if(o.length<2)throw new Hw(`Git URL must have at least org/name in the path: ${JSON.stringify(t)}`);let a=o[0],c=o[1].replace(/\.git$/,""),l,u;return o.length>=4&&o[2]==="tree"&&(l=o[3],o.length>4&&(u=o.slice(4).join("/"))),{kind:"git",host:s,org:a,repo:c,...l?{gitRef:l}:{},...u?{subdir:u}:{},viaSkillsSh:!1,raw:t}}let i=t.match(H0n);if(i)return{kind:"git",host:"github.com",org:i[1],repo:i[2],...i[3]?{gitRef:i[3]}:{},viaSkillsSh:!1,raw:t};throw new Hw(`Cannot parse skill reference ${JSON.stringify(t)}. Expected skills.sh/<owner>/<repo>[/<skill>], org/repo[@ref], an https git URL, or a local folder path (prefix relative paths with './').`)}function $5t(e){return`https://${e.host}/${e.org}/${e.repo}.git`}function AK(e){return`https://${e.host}/${e.org}/${e.repo}`}async function G0(e,t){try{let{stdout:r}=await $0n("git",e,{cwd:t.cwd,timeout:t.timeoutMs,env:t.gitEnv??process.env,maxBuffer:16777216});return r}catch(r){let n=r,i=(n.stderr||n.message||"").trim();throw new z0(`git ${e[0]} failed${n.killed?" (timed out)":""}: ${i}`)}}async function K0n(e,t={}){if(e.gitRef&&z0n.test(e.gitRef))return e.gitRef;let r=e.gitRef??"HEAD",n=(await G0(["ls-remote",$5t(e),r],{timeoutMs:t.lsRemoteTimeoutMs??3e4,gitEnv:t.gitEnv})).trim().split(`
|
|
644
|
-
`)[0];if(!n)throw new z0(`No matching ref ${JSON.stringify(r)} found in ${AK(e)}`);return n.split(" ")[0]}async function K8t(e){let t=[],r=async i=>{let s=i===""?e:(0,Zt.join)(e,i),o=await(0,vr.readdir)(s,{withFileTypes:!0});for(let a of o){let c=i===""?a.name:`${i}/${a.name}`;a.isDirectory()?await r(c):a.isFile()&&t.push(c)}};await r(""),t.sort();let n=(0,Uu.createHash)("sha256");for(let i of t){let s=(0,Uu.createHash)("sha256").update(await(0,vr.readFile)((0,Zt.join)(e,i))).digest("hex");n.update(i),n.update("\0"),n.update(s),n.update("\0")}return`sha256:${n.digest("hex")}`}async function eU(e){try{return(await(0,vr.stat)(e)).isFile()}catch{return!1}}async function oTe(e){try{return(await(0,vr.stat)(e)).isDirectory()}catch{return!1}}async function Z8t(e,t){if(!await oTe(e))throw new z0(`Skill path does not exist or is not a directory: ${t}`);if(await eU((0,Zt.join)(e,QS)))return[e];let r=(await(0,vr.readdir)(e,{withFileTypes:!0})).filter(s=>s.isDirectory()&&!s.name.startsWith(".")).map(s=>s.name).sort(),n=[],i=[];for(let s of r)await eU((0,Zt.join)(e,s,QS))?i.push((0,Zt.join)(e,s)):n.push(s);if(n.length>0)throw new z0(`Skill root ${t} contains child directories without ${QS}: ${n.join(", ")}`);if(i.length===0)throw new z0(`Skill path ${t} must be a skill directory containing ${QS}, or a root whose immediate child directories each contain ${QS}.`);return i}async function Z0n(e){let t=new Map;await eU((0,Zt.join)(e,QS))&&t.set((0,Zt.basename)(e),e);for(let r of sTe){let n=(0,Zt.join)(e,r);if(!await oTe(n))continue;let i=await(0,vr.readdir)(n,{withFileTypes:!0});for(let s of i.sort((o,a)=>o.name<a.name?-1:1)){if(!s.isDirectory()||s.name.startsWith("."))continue;let o=(0,Zt.join)(n,s.name);await eU((0,Zt.join)(o,QS))&&t.set(s.name,o)}}return Array.from(t,([r,n])=>({dir:n,name:r}))}function X0n(e){return e.cacheDir??process.env.EVOLVE_SKILLS_CACHE??G0n}async function Q0n(e,t,r){let n=(0,Zt.join)(X0n(r),e.host,e.org,e.repo,t),i=(0,Zt.join)(n,e.repo),s=(0,Zt.join)(n,".evolve-complete");if(await eU(s)&&await oTe(i))return i;await(0,vr.mkdir)((0,Zt.dirname)(n),{recursive:!0});let o=await(0,vr.mkdtemp)(`${n}.tmp-`),a=(0,Zt.join)(o,e.repo),c=r.checkoutTimeoutMs??12e4,l={cwd:a,timeoutMs:c,gitEnv:r.gitEnv};try{await(0,vr.mkdir)(a),await G0(["init","--quiet"],l),await G0(["remote","add","origin",$5t(e)],l),e.subdir?(await G0(["sparse-checkout","init","--cone"],l),await G0(["sparse-checkout","set",e.subdir],l)):(await G0(["sparse-checkout","init","--cone"],l),await G0(["sparse-checkout","set",...sTe],l)),await G0(["fetch","--quiet","--depth=1","origin",t],l),await G0(["checkout","--quiet","FETCH_HEAD"],l),await(0,vr.rm)((0,Zt.join)(a,".git"),{recursive:!0,force:!0}),await(0,vr.writeFile)((0,Zt.join)(o,".evolve-complete"),""),await(0,vr.rm)(n,{recursive:!0,force:!0});try{await(0,vr.rename)(o,n)}catch{await(0,vr.rm)(o,{recursive:!0,force:!0})}return i}catch(u){throw await(0,vr.rm)(o,{recursive:!0,force:!0}),u}}async function X8t(e,t){let r=0,n=0,i=async s=>{let o=await(0,vr.readdir)(s,{withFileTypes:!0});for(let a of o){let c=(0,Zt.join)(s,a.name);if(a.isDirectory())await i(c);else if(a.isFile()&&(r+=1,n+=(await(0,vr.stat)(c)).size,r>j8t||n>Y8t))throw new z0(`Skill ${t} exceeds the size ceiling (${j8t} files / ${Y8t} bytes) \u2014 a skill is instructions, not a dataset.`)}};await i(e)}async function evn(e,t={}){let r=new Map;for(let n of e){let i=Y0n(n);if(i.kind==="upload")throw new z0(`Skill reference ${JSON.stringify(i.raw)} is a platform upload handle; only the hosted platform can resolve it. Use a skills.sh/git reference or a local folder here.`);if(i.kind==="local"){let c=await Z8t(i.path,i.raw);for(let l of c)await X8t(l,i.raw),r.set((0,Zt.basename)(l),{name:(0,Zt.basename)(l),dir:l,source:i.raw,digest:await K8t(l)});continue}let s=await K0n(i,t),o=await Q0n(i,s,t),a;if(i.subdir)a=(await Z8t((0,Zt.join)(o,i.subdir),`${i.raw} (${i.subdir})`)).map(c=>({dir:c,name:(0,Zt.basename)(c)}));else if(a=await Z0n(o),a.length===0)throw new z0(`No skills found in ${AK(i)}@${s.slice(0,12)}: expected ${QS} at the repo root or under ${sTe.join(", ")}.`);if(i.skillName){let c=a.filter(l=>l.name===i.skillName);if(c.length===0)throw new z0(`Skill ${JSON.stringify(i.skillName)} not found in ${AK(i)}@${s.slice(0,12)}. Available: ${a.map(l=>l.name).sort().join(", ")||"(none)"}`);a=c}for(let{dir:c,name:l}of a)await X8t(c,i.raw),r.set(l,{name:l,dir:c,source:i.raw,gitUrl:AK(i),gitCommit:s,digest:await K8t(c)})}return Array.from(r.values()).sort((n,i)=>n.name<i.name?-1:n.name>i.name?1:0)}function EK(e){return`'${e.replace(/'/g,"'\\''")}'`}async function tvn(e,t,r){if(t.length===0)return;let{tarGzipDirectory:n}=await Promise.resolve().then(()=>(D8t(),N8t));await e.files.makeDir(r);for(let i of t){let s=await n(i.dir),o=`${r}/.evolve-skill-${i.name}.tgz`,a=`${r}/${i.name}`;await e.files.write(o,s),await e.commands.run(`mkdir -p ${EK(a)} && tar -xzf ${EK(o)} -C ${EK(a)} && rm -f ${EK(o)}`,{timeoutMs:6e4})}}function BK(e){return e!==null&&typeof e=="object"&&"safeParse"in e&&typeof e.safeParse=="function"}function G5t(e){return JSON.stringify(Xke(e,{target:"jsonSchema7"}),null,2)}function H5t(e){return JSON.stringify(e,null,2)}var fc=class extends Error{field;constructor(e,t){super(t),this.name="EvolveConfigError",this.field=e}};function eTe(e){return typeof e=="string"&&e.trim()!==""}function pR(e){return e==null?String(e):JSON.stringify(e)}function z5t(e){if(!e)return;if(e.type!==void 0&&!Wyn(e.type))throw new fc("type",`Evolve agent config: unknown agent type ${pR(e.type)}. Valid types: ${Object.keys(J0).join(", ")}.`);let t=e.type??GK;if(e.model!==void 0&&!eTe(e.model))throw new fc("model",`Evolve agent config: "model" is empty (${pR(e.model)}). Pass a model id such as "${Jw(t).defaultModel}", or omit model entirely to use ${t}'s default.`);if(e.config!==void 0){if(!j5t(t))throw new fc("config",`Evolve agent config: agent "${t}" does not support a native config. Agents with native-config support: ${Y5t().join(", ")}.`);let r=e.config;if(typeof r=="string"){if(!eTe(r))throw new fc("config",`Evolve agent config: "config" is an empty path (${pR(r)}). Pass a local settings file path or an inline JSON object.`)}else if(!RK(r))throw new fc("config",`Evolve agent config: "config" must be a local file path or a JSON object, received ${pR(r)}.`)}e.preset!==void 0&&W5t(t,e.preset)}function W5t(e,t){if(!q8t.includes(t))throw new fc("preset",`Evolve agent config: unknown preset ${pR(t)}. Valid presets: ${q8t.join(", ")}.`);let r=nvn(t);if(!r.includes(e))throw new fc("preset",`Evolve agent config: agent "${e}" cannot guarantee preset "${t}". Agents that can: ${r.join(", ")}.`)}function rvn(e){let t=J0[e]?.presets;return t?Object.keys(t):[]}function nvn(e){return Object.keys(J0).filter(t=>rvn(t).includes(e))}function J5t(e,t){let r={...e};for(let[n,i]of Object.entries(t)){let s=r[n];if(RK(s)&&RK(i))r[n]=J5t(s,i);else if(Array.isArray(s)&&Array.isArray(i)){let o=[...s];for(let a of i)o.some(c=>mR(c)===mR(a))||o.push(a);r[n]=o}else r[n]=i}return r}function RK(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function j5t(e){return J0[e]?.nativeConfig!==void 0}function Y5t(){return Object.keys(J0).filter(j5t)}function ivn(e,t){if(t===void 0)return;let r=J0[e]?.nativeConfig;if(!r)throw new fc("config",`Evolve agent config: agent "${e}" does not support a native config. Agents with native-config support: ${Y5t().join(", ")}.`);let n;if(typeof t=="string"){let i=t.replace(/^~/,process.env.HOME||"");if(!Dg.existsSync(i))throw new fc("config",`Agent config file not found: ${i}`);let s=Dg.readFileSync(i,"utf-8");try{n=r.format==="toml"?f_(s):JSON.parse(s)}catch(o){throw new fc("config",`Invalid ${e} config file ${t}: ${o.message}`)}}else{let i;try{i=JSON.parse(JSON.stringify(t))}catch(s){throw new fc("config",`Invalid inline ${e} config: not JSON-serializable: ${s.message}`)}if(JSON.stringify(i)!==JSON.stringify(t))throw new fc("config",`Invalid inline ${e} config: expected a JSON object that can be represented without conversion`);n=i}if(!RK(n))throw new fc("config",`Invalid ${e} config: expected a ${r.format==="toml"?"TOML table":"JSON object"}.`);if(r.format==="toml"){let i;try{i=f_(dx(n))}catch(s){throw new fc("config",`Invalid ${e} config for TOML conversion: ${s.message}`)}if(mR(i)!==mR(n))throw new fc("config",`Invalid ${e} config: the document cannot be represented losslessly as TOML (TOML has no null and no mixed-type arrays)`)}return n}function mR(e){return Array.isArray(e)?`[${e.map(mR).join(",")}]`:e&&typeof e=="object"?`{${Object.entries(e).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${mR(r)}`).join(",")}}`:JSON.stringify(e)??"null"}function svn(e){if(!e||!eTe(e.prompt))throw new fc("prompt",`run() requires a non-empty "prompt" string, received ${pR(e?.prompt)}.`)}function ovn(e){if(e){for(let t of mU)if(t in e)throw new fc(`observability.${t}`,`Evolve observability metadata: "${t}" is reserved for session identity and would split this run across two dashboard sessions. Reserved keys: ${mU.join(", ")}. Use a different key, or set the session tag with .withSessionTagPrefix().`)}}function K5t(e){if(e.externalGateway){if(e.providerApiKey||e.providerBaseUrl||e.oauthToken)throw new Error("externalGateway cannot be combined with providerApiKey/providerBaseUrl/oauthToken (direct mode)");if(e.apiKey)throw new Error("externalGateway cannot be combined with apiKey (Evolve gateway mode)")}}function avn(e){let t=e.replace(/^~/,process.env.HOME||"");if(!Dg.existsSync(t))throw new Error(`OAuth file not found: ${t}`);return Dg.readFileSync(t,"utf-8")}function Q8t(e){let t=e?.type??GK,r=Jw(t),n=ivn(t,e?.config);e?.preset!==void 0&&W5t(t,e.preset);let i={...n!==void 0?{config:n}:{},...e?.preset!==void 0?{preset:e.preset}:{}};if(e?.externalGateway){K5t(e);let{apiKey:c,baseUrl:l,revoke:u}=e.externalGateway;if(!c||!l||typeof u!="function")throw new Error("externalGateway requires apiKey, baseUrl, and a revoke() function");return{type:t,apiKey:c,baseUrl:l,isDirectMode:!0,externalGateway:{revoke:u},model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.oauthToken){if(t!=="claude")throw new Error(`oauthToken is only supported for claude agent (Claude Max subscription), not ${t}. Use providerApiKey for ${t} instead.`);return{type:t,apiKey:e.oauthToken,isDirectMode:!0,isOAuth:!0,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.providerApiKey){let c=r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0,l=e.providerBaseUrl??c??r.defaultBaseUrl;return{type:t,apiKey:e.providerApiKey,baseUrl:l,isDirectMode:!0,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.apiKey)return{type:t,apiKey:e.apiKey,isDirectMode:!1,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i};let s=process.env[Dd];if(s)return{type:t,apiKey:s,isDirectMode:!1,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i};if(r.providerEnvMap){let c=(e?.model??r.defaultModel)?.split("/")[0],l=c?r.providerEnvMap[c]:void 0,u=l?process.env[l.keyEnv]:void 0;if(u){let d=(r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0)??r.defaultBaseUrl;return{type:t,apiKey:u,baseUrl:d,isDirectMode:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}}let o=process.env[r.apiKeyEnv];if(o){let c=(r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0)??r.defaultBaseUrl;return{type:t,apiKey:o,baseUrl:c,isDirectMode:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}if(r.oauthEnv){let c=process.env[r.oauthEnv];if(c){if(r.oauthFileName){let l=avn(c);return{type:t,apiKey:"__oauth_file__",isDirectMode:!0,isOAuth:!0,oauthFileContent:l,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}return{type:t,apiKey:c,isDirectMode:!0,isOAuth:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}}let a=r.oauthEnv?r.oauthFileName?`, or ${r.oauthEnv}`:`, oauthToken, or ${r.oauthEnv}`:"";throw new Error(`No API key found for ${t}. Set apiKey (gateway), providerApiKey (direct)${a}, or ${Dd} / ${r.apiKeyEnv} env var.`)}function cvn(e){return`e2b_${Buffer.from(e,"utf8").toString("hex")}`}var Z5t=new WeakSet;function Vxe(e){return Z5t.add(e),e}function X5t(e){return Z5t.has(e)}function e5t(e,t){return new Error(`${Dd} is set but ${e} failed to load.
|
|
643
|
+
\`\`\``:v}})}}return{sessionUpdate:"tool_call_update",toolCallId:u,status:d?"failed":"completed",content:p}}function c(l,u){let d=q0n[l]||"other",f=[],p=[],m=l;switch(l){case"Read":case"read_file":m=`Read ${u.file_path||u.absolute_path||"file"}`,(u.file_path||u.absolute_path)&&p.push({path:u.file_path||u.absolute_path});break;case"Write":case"write_file":m=`Write ${u.file_path||"file"}`,u.file_path&&(p.push({path:u.file_path}),f.push({type:"diff",path:u.file_path,oldText:null,newText:u.content||""}));break;case"Edit":case"edit_file":m=`Edit ${u.file_path||"file"}`,u.file_path&&p.push({path:u.file_path});break;case"Bash":case"shell":case"run_shell_command":m=u.command?`\`${u.command}\``:"Run command",u.description&&f.push({type:"content",content:{type:"text",text:u.description}});break;case"WebFetch":m=u.url?`Fetch ${u.url}`:"Web fetch";break;case"WebSearch":case"brave_web_search":m=u.query?`"${u.query}"`:"Web search";break;case"Glob":m=`Find ${u.pattern||"files"}`,u.path&&p.push({path:u.path});break;case"Grep":m=`grep "${u.pattern||""}"`;break;case"LS":case"list_directory":m=`List ${u.path||"directory"}`,u.path&&p.push({path:u.path});break;case"Task":m=u.description||"Subagent task";break;case"TodoWrite":m="Update todos";break;case"ExitPlanMode":m="Exit plan mode";break;default:m=l}return{title:m,kind:d,content:f,locations:p}}}function V5t(e){switch(e){case"claude":return d0n();case"codex":return f0n();case"gemini":return T0n();case"qwen":return V0n();case"kimi":return P0n();case"opencode":return L0n();case"droid":return m0n();default:return()=>null}}var $0n=(0,DK.promisify)(rU.execFile),QS="SKILL.md",G0n=(0,Zt.join)((0,W0.homedir)(),".cache","evolve","skills"),sTe=["skills","skills/.curated","skills/.experimental","skills/.system",".claude/skills"],H0n=/^([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+)(?:@(.+))?$/,z0n=/^[0-9a-f]{40}$/,j8t=2e3,Y8t=64*1024*1024,Hw=class extends Error{constructor(e){super(e),this.name="SkillRefError"}},z0=class extends Error{constructor(e){super(e),this.name="SkillResolveError"}};function W0n(e){return e==="~"?(0,W0.homedir)():e.startsWith("~/")?(0,Zt.join)((0,W0.homedir)(),e.slice(2)):e}function J0n(e){let t=e.indexOf("@");if(t===-1)return{base:e};let r=e.slice(t+1);if(!r)throw new Hw(`Empty @ref in skill reference segment: ${JSON.stringify(e)}`);return{base:e.slice(0,t),gitRef:r}}var j0n=/^[A-Za-z0-9._-]+$/;function qxe(e,t,r){if(!j0n.test(e))throw new Hw(`Cannot parse skill reference ${JSON.stringify(r)}: ${t} ${JSON.stringify(e)} may only contain letters, digits, ".", "_" and "-".`);return e}function Y0n(e){let t=String(e??"").trim();if(!t)throw new Hw("Skill reference cannot be empty.");if(t.startsWith("upload:")){let s=t.slice(7);if(!s)throw new Hw(`Skill upload reference ${JSON.stringify(t)} names no upload id.`);return{kind:"upload",id:s,raw:t}}if(t.startsWith("./")||t.startsWith("../")||t.startsWith("/")||t.startsWith("~"))return{kind:"local",path:W0n(t),raw:t};let r=t.match(/^(?:https?:\/\/)?(?:www\.)?skills\.sh\/(.+)$/);if(r){let s=r[1].replace(/\/+$/,"").split("/").filter(Boolean);if(s.length<2||s.length>3)throw new Hw(`Cannot parse skill reference ${JSON.stringify(t)}: expected skills.sh/<owner>/<repo> or skills.sh/<owner>/<repo>/<skill>, optionally @ref.`);let{base:o,gitRef:a}=J0n(s[s.length-1]);s[s.length-1]=o;let[c,l,u]=s;return qxe(c,"owner",t),qxe(l,"repo",t),u!==void 0&&qxe(u,"skill name",t),{kind:"git",host:"github.com",org:c,repo:l,...a?{gitRef:a}:{},...u?{skillName:u}:{},viaSkillsSh:!0,raw:t}}let n=t.match(/^https?:\/\/([^/]+)\/(.+)$/);if(n){let s=n[1],o=n[2].replace(/\/+$/,"").split("/").filter(Boolean);if(o.length<2)throw new Hw(`Git URL must have at least org/name in the path: ${JSON.stringify(t)}`);let a=o[0],c=o[1].replace(/\.git$/,""),l,u;return o.length>=4&&o[2]==="tree"&&(l=o[3],o.length>4&&(u=o.slice(4).join("/"))),{kind:"git",host:s,org:a,repo:c,...l?{gitRef:l}:{},...u?{subdir:u}:{},viaSkillsSh:!1,raw:t}}let i=t.match(H0n);if(i)return{kind:"git",host:"github.com",org:i[1],repo:i[2],...i[3]?{gitRef:i[3]}:{},viaSkillsSh:!1,raw:t};throw new Hw(`Cannot parse skill reference ${JSON.stringify(t)}. Expected skills.sh/<owner>/<repo>[/<skill>], org/repo[@ref], an https git URL, or a local folder path (prefix relative paths with './').`)}function $5t(e){return`https://${e.host}/${e.org}/${e.repo}.git`}function AK(e){return`https://${e.host}/${e.org}/${e.repo}`}async function G0(e,t){try{let{stdout:r}=await $0n("git",e,{cwd:t.cwd,timeout:t.timeoutMs,env:t.gitEnv??process.env,maxBuffer:16777216});return r}catch(r){let n=r,i=(n.stderr||n.message||"").trim();throw new z0(`git ${e[0]} failed${n.killed?" (timed out)":""}: ${i}`)}}async function K0n(e,t={}){if(e.gitRef&&z0n.test(e.gitRef))return e.gitRef;let r=e.gitRef??"HEAD",n=(await G0(["ls-remote",$5t(e),r,`${r}^{}`],{timeoutMs:t.lsRemoteTimeoutMs??3e4,gitEnv:t.gitEnv})).trim().split(`
|
|
644
|
+
`).filter(s=>s.length>0).map(s=>{let[o,a]=s.split(" ");return{sha:o,name:a}});if(n.length===0||!n[0].sha)throw new z0(`No matching ref ${JSON.stringify(r)} found in ${AK(e)}`);let i=n[0];return(n.find(s=>s.name===`${i.name}^{}`)??i).sha}async function K8t(e){let t=[],r=async i=>{let s=i===""?e:(0,Zt.join)(e,i),o=await(0,vr.readdir)(s,{withFileTypes:!0});for(let a of o){let c=i===""?a.name:`${i}/${a.name}`;a.isDirectory()?await r(c):a.isFile()&&t.push(c)}};await r(""),t.sort();let n=(0,Uu.createHash)("sha256");for(let i of t){let s=(0,Uu.createHash)("sha256").update(await(0,vr.readFile)((0,Zt.join)(e,i))).digest("hex");n.update(i),n.update("\0"),n.update(s),n.update("\0")}return`sha256:${n.digest("hex")}`}async function eU(e){try{return(await(0,vr.stat)(e)).isFile()}catch{return!1}}async function oTe(e){try{return(await(0,vr.stat)(e)).isDirectory()}catch{return!1}}async function Z8t(e,t){if(!await oTe(e))throw new z0(`Skill path does not exist or is not a directory: ${t}`);if(await eU((0,Zt.join)(e,QS)))return[e];let r=(await(0,vr.readdir)(e,{withFileTypes:!0})).filter(s=>s.isDirectory()&&!s.name.startsWith(".")).map(s=>s.name).sort(),n=[],i=[];for(let s of r)await eU((0,Zt.join)(e,s,QS))?i.push((0,Zt.join)(e,s)):n.push(s);if(n.length>0)throw new z0(`Skill root ${t} contains child directories without ${QS}: ${n.join(", ")}`);if(i.length===0)throw new z0(`Skill path ${t} must be a skill directory containing ${QS}, or a root whose immediate child directories each contain ${QS}.`);return i}async function Z0n(e){let t=new Map;await eU((0,Zt.join)(e,QS))&&t.set((0,Zt.basename)(e),e);for(let r of sTe){let n=(0,Zt.join)(e,r);if(!await oTe(n))continue;let i=await(0,vr.readdir)(n,{withFileTypes:!0});for(let s of i.sort((o,a)=>o.name<a.name?-1:1)){if(!s.isDirectory()||s.name.startsWith("."))continue;let o=(0,Zt.join)(n,s.name);await eU((0,Zt.join)(o,QS))&&t.set(s.name,o)}}return Array.from(t,([r,n])=>({dir:n,name:r}))}function X0n(e){return e.cacheDir??process.env.EVOLVE_SKILLS_CACHE??G0n}async function Q0n(e,t,r){let n=(0,Zt.join)(X0n(r),e.host,e.org,e.repo,t),i=(0,Zt.join)(n,e.repo),s=(0,Zt.join)(n,".evolve-complete");if(await eU(s)&&await oTe(i))return i;await(0,vr.mkdir)((0,Zt.dirname)(n),{recursive:!0});let o=await(0,vr.mkdtemp)(`${n}.tmp-`),a=(0,Zt.join)(o,e.repo),c=r.checkoutTimeoutMs??12e4,l={cwd:a,timeoutMs:c,gitEnv:r.gitEnv};try{await(0,vr.mkdir)(a),await G0(["init","--quiet"],l),await G0(["remote","add","origin",$5t(e)],l),e.subdir?(await G0(["sparse-checkout","init","--cone"],l),await G0(["sparse-checkout","set",e.subdir],l)):(await G0(["sparse-checkout","init","--cone"],l),await G0(["sparse-checkout","set",...sTe],l)),await G0(["fetch","--quiet","--depth=1","origin",t],l),await G0(["checkout","--quiet","FETCH_HEAD"],l),await(0,vr.rm)((0,Zt.join)(a,".git"),{recursive:!0,force:!0}),await(0,vr.writeFile)((0,Zt.join)(o,".evolve-complete"),""),await(0,vr.rm)(n,{recursive:!0,force:!0});try{await(0,vr.rename)(o,n)}catch{await(0,vr.rm)(o,{recursive:!0,force:!0})}return i}catch(u){throw await(0,vr.rm)(o,{recursive:!0,force:!0}),u}}async function X8t(e,t){let r=0,n=0,i=async s=>{let o=await(0,vr.readdir)(s,{withFileTypes:!0});for(let a of o){let c=(0,Zt.join)(s,a.name);if(a.isDirectory())await i(c);else if(a.isFile()&&(r+=1,n+=(await(0,vr.stat)(c)).size,r>j8t||n>Y8t))throw new z0(`Skill ${t} exceeds the size ceiling (${j8t} files / ${Y8t} bytes) \u2014 a skill is instructions, not a dataset.`)}};await i(e)}async function evn(e,t={}){let r=new Map;for(let n of e){let i=Y0n(n);if(i.kind==="upload")throw new z0(`Skill reference ${JSON.stringify(i.raw)} is a platform upload handle; only the hosted platform can resolve it. Use a skills.sh/git reference or a local folder here.`);if(i.kind==="local"){let c=await Z8t(i.path,i.raw);for(let l of c)await X8t(l,i.raw),r.set((0,Zt.basename)(l),{name:(0,Zt.basename)(l),dir:l,source:i.raw,digest:await K8t(l)});continue}let s=await K0n(i,t),o=await Q0n(i,s,t),a;if(i.subdir)a=(await Z8t((0,Zt.join)(o,i.subdir),`${i.raw} (${i.subdir})`)).map(c=>({dir:c,name:(0,Zt.basename)(c)}));else if(a=await Z0n(o),a.length===0)throw new z0(`No skills found in ${AK(i)}@${s.slice(0,12)}: expected ${QS} at the repo root or under ${sTe.join(", ")}.`);if(i.skillName){let c=a.filter(l=>l.name===i.skillName);if(c.length===0)throw new z0(`Skill ${JSON.stringify(i.skillName)} not found in ${AK(i)}@${s.slice(0,12)}. Available: ${a.map(l=>l.name).sort().join(", ")||"(none)"}`);a=c}for(let{dir:c,name:l}of a)await X8t(c,i.raw),r.set(l,{name:l,dir:c,source:i.raw,gitUrl:AK(i),gitCommit:s,digest:await K8t(c)})}return Array.from(r.values()).sort((n,i)=>n.name<i.name?-1:n.name>i.name?1:0)}function EK(e){return`'${e.replace(/'/g,"'\\''")}'`}async function tvn(e,t,r){if(t.length===0)return;let{tarGzipDirectory:n}=await Promise.resolve().then(()=>(D8t(),N8t));await e.files.makeDir(r);for(let i of t){let s=await n(i.dir),o=`${r}/.evolve-skill-${i.name}.tgz`,a=`${r}/${i.name}`;await e.files.write(o,s),await e.commands.run(`mkdir -p ${EK(a)} && tar -xzf ${EK(o)} -C ${EK(a)} && rm -f ${EK(o)}`,{timeoutMs:6e4})}}function BK(e){return e!==null&&typeof e=="object"&&"safeParse"in e&&typeof e.safeParse=="function"}function G5t(e){return JSON.stringify(Xke(e,{target:"jsonSchema7"}),null,2)}function H5t(e){return JSON.stringify(e,null,2)}var fc=class extends Error{field;constructor(e,t){super(t),this.name="EvolveConfigError",this.field=e}};function eTe(e){return typeof e=="string"&&e.trim()!==""}function pR(e){return e==null?String(e):JSON.stringify(e)}function z5t(e){if(!e)return;if(e.type!==void 0&&!Wyn(e.type))throw new fc("type",`Evolve agent config: unknown agent type ${pR(e.type)}. Valid types: ${Object.keys(J0).join(", ")}.`);let t=e.type??GK;if(e.model!==void 0&&!eTe(e.model))throw new fc("model",`Evolve agent config: "model" is empty (${pR(e.model)}). Pass a model id such as "${Jw(t).defaultModel}", or omit model entirely to use ${t}'s default.`);if(e.config!==void 0){if(!j5t(t))throw new fc("config",`Evolve agent config: agent "${t}" does not support a native config. Agents with native-config support: ${Y5t().join(", ")}.`);let r=e.config;if(typeof r=="string"){if(!eTe(r))throw new fc("config",`Evolve agent config: "config" is an empty path (${pR(r)}). Pass a local settings file path or an inline JSON object.`)}else if(!RK(r))throw new fc("config",`Evolve agent config: "config" must be a local file path or a JSON object, received ${pR(r)}.`)}e.preset!==void 0&&W5t(t,e.preset)}function W5t(e,t){if(!q8t.includes(t))throw new fc("preset",`Evolve agent config: unknown preset ${pR(t)}. Valid presets: ${q8t.join(", ")}.`);let r=nvn(t);if(!r.includes(e))throw new fc("preset",`Evolve agent config: agent "${e}" cannot guarantee preset "${t}". Agents that can: ${r.join(", ")}.`)}function rvn(e){let t=J0[e]?.presets;return t?Object.keys(t):[]}function nvn(e){return Object.keys(J0).filter(t=>rvn(t).includes(e))}function J5t(e,t){let r={...e};for(let[n,i]of Object.entries(t)){let s=r[n];if(RK(s)&&RK(i))r[n]=J5t(s,i);else if(Array.isArray(s)&&Array.isArray(i)){let o=[...s];for(let a of i)o.some(c=>mR(c)===mR(a))||o.push(a);r[n]=o}else r[n]=i}return r}function RK(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function j5t(e){return J0[e]?.nativeConfig!==void 0}function Y5t(){return Object.keys(J0).filter(j5t)}function ivn(e,t){if(t===void 0)return;let r=J0[e]?.nativeConfig;if(!r)throw new fc("config",`Evolve agent config: agent "${e}" does not support a native config. Agents with native-config support: ${Y5t().join(", ")}.`);let n;if(typeof t=="string"){let i=t.replace(/^~/,process.env.HOME||"");if(!Dg.existsSync(i))throw new fc("config",`Agent config file not found: ${i}`);let s=Dg.readFileSync(i,"utf-8");try{n=r.format==="toml"?f_(s):JSON.parse(s)}catch(o){throw new fc("config",`Invalid ${e} config file ${t}: ${o.message}`)}}else{let i;try{i=JSON.parse(JSON.stringify(t))}catch(s){throw new fc("config",`Invalid inline ${e} config: not JSON-serializable: ${s.message}`)}if(JSON.stringify(i)!==JSON.stringify(t))throw new fc("config",`Invalid inline ${e} config: expected a JSON object that can be represented without conversion`);n=i}if(!RK(n))throw new fc("config",`Invalid ${e} config: expected a ${r.format==="toml"?"TOML table":"JSON object"}.`);if(r.format==="toml"){let i;try{i=f_(dx(n))}catch(s){throw new fc("config",`Invalid ${e} config for TOML conversion: ${s.message}`)}if(mR(i)!==mR(n))throw new fc("config",`Invalid ${e} config: the document cannot be represented losslessly as TOML (TOML has no null and no mixed-type arrays)`)}return n}function mR(e){return Array.isArray(e)?`[${e.map(mR).join(",")}]`:e&&typeof e=="object"?`{${Object.entries(e).sort(([t],[r])=>t<r?-1:t>r?1:0).map(([t,r])=>`${JSON.stringify(t)}:${mR(r)}`).join(",")}}`:JSON.stringify(e)??"null"}function svn(e){if(!e||!eTe(e.prompt))throw new fc("prompt",`run() requires a non-empty "prompt" string, received ${pR(e?.prompt)}.`)}function ovn(e){if(e){for(let t of mU)if(t in e)throw new fc(`observability.${t}`,`Evolve observability metadata: "${t}" is reserved for session identity and would split this run across two dashboard sessions. Reserved keys: ${mU.join(", ")}. Use a different key, or set the session tag with .withSessionTagPrefix().`)}}function K5t(e){if(e.externalGateway){if(e.providerApiKey||e.providerBaseUrl||e.oauthToken)throw new Error("externalGateway cannot be combined with providerApiKey/providerBaseUrl/oauthToken (direct mode)");if(e.apiKey)throw new Error("externalGateway cannot be combined with apiKey (Evolve gateway mode)")}}function avn(e){let t=e.replace(/^~/,process.env.HOME||"");if(!Dg.existsSync(t))throw new Error(`OAuth file not found: ${t}`);return Dg.readFileSync(t,"utf-8")}function Q8t(e){let t=e?.type??GK,r=Jw(t),n=ivn(t,e?.config);e?.preset!==void 0&&W5t(t,e.preset);let i={...n!==void 0?{config:n}:{},...e?.preset!==void 0?{preset:e.preset}:{}};if(e?.externalGateway){K5t(e);let{apiKey:c,baseUrl:l,revoke:u}=e.externalGateway;if(!c||!l||typeof u!="function")throw new Error("externalGateway requires apiKey, baseUrl, and a revoke() function");return{type:t,apiKey:c,baseUrl:l,isDirectMode:!0,externalGateway:{revoke:u},model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.oauthToken){if(t!=="claude")throw new Error(`oauthToken is only supported for claude agent (Claude Max subscription), not ${t}. Use providerApiKey for ${t} instead.`);return{type:t,apiKey:e.oauthToken,isDirectMode:!0,isOAuth:!0,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.providerApiKey){let c=r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0,l=e.providerBaseUrl??c??r.defaultBaseUrl;return{type:t,apiKey:e.providerApiKey,baseUrl:l,isDirectMode:!0,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i}}if(e?.apiKey)return{type:t,apiKey:e.apiKey,isDirectMode:!1,model:e.model,reasoningEffort:e.reasoningEffort,maxContextSize:e.maxContextSize,...i};let s=process.env[Dd];if(s)return{type:t,apiKey:s,isDirectMode:!1,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i};if(r.providerEnvMap){let c=(e?.model??r.defaultModel)?.split("/")[0],l=c?r.providerEnvMap[c]:void 0,u=l?process.env[l.keyEnv]:void 0;if(u){let d=(r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0)??r.defaultBaseUrl;return{type:t,apiKey:u,baseUrl:d,isDirectMode:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}}let o=process.env[r.apiKeyEnv];if(o){let c=(r.baseUrlEnv?process.env[r.baseUrlEnv]:void 0)??r.defaultBaseUrl;return{type:t,apiKey:o,baseUrl:c,isDirectMode:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}if(r.oauthEnv){let c=process.env[r.oauthEnv];if(c){if(r.oauthFileName){let l=avn(c);return{type:t,apiKey:"__oauth_file__",isDirectMode:!0,isOAuth:!0,oauthFileContent:l,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}return{type:t,apiKey:c,isDirectMode:!0,isOAuth:!0,model:e?.model,reasoningEffort:e?.reasoningEffort,maxContextSize:e?.maxContextSize,...i}}}let a=r.oauthEnv?r.oauthFileName?`, or ${r.oauthEnv}`:`, oauthToken, or ${r.oauthEnv}`:"";throw new Error(`No API key found for ${t}. Set apiKey (gateway), providerApiKey (direct)${a}, or ${Dd} / ${r.apiKeyEnv} env var.`)}function cvn(e){return`e2b_${Buffer.from(e,"utf8").toString("hex")}`}var Z5t=new WeakSet;function Vxe(e){return Z5t.add(e),e}function X5t(e){return Z5t.has(e)}function e5t(e,t){return new Error(`${Dd} is set but ${e} failed to load.
|
|
645
645
|
Try installing: ${t}`)}function t5t(e){return e.message?.includes("Cannot find module")||e.message?.includes("MODULE_NOT_FOUND")}function $xe(e,t){if(!t||t.timeoutMs===void 0&&t.resources===void 0)return e;let r=e.create.bind(e);return e.create=(n={})=>r({...t.timeoutMs!==void 0?{timeoutMs:t.timeoutMs}:{},...t.resources!==void 0?{resources:t.resources}:{},...n}),e}async function aTe(e,t="e2b",r){let n=e||process.env[Dd];if(!n)throw new Error(`${Dd} is required for Evolve-managed sandbox features`);if(!uU.includes(t))throw new Error(`Unknown managed sandbox provider "${t}". Supported: ${uU.join(", ")}`);if(t==="daytona")try{let{createDaytonaProvider:i}=await Promise.resolve().then(()=>(dB(),j0e));return $xe(Vxe(i({apiKey:n,apiUrl:bR("daytona"),managedToolboxUrl:STe()})),r)}catch(i){let s=i;throw t5t(s)?e5t("@evolvingmachines/daytona","npm install @evolvingmachines/daytona"):s}if(t==="modal"){let{ManagedModalProvider:i}=await Promise.resolve().then(()=>(L8t(),F8t));return $xe(Vxe(new i({apiKey:n,baseUrl:bR("modal")})),r)}try{let{createE2BProvider:i}=await Promise.resolve().then(()=>(E1(),yne));return $xe(Vxe(i({apiKey:cvn(n),apiUrl:VK()})),r)}catch(i){let s=i;throw t5t(s)?e5t("@evolvingmachines/e2b","npm install @evolvingmachines/sdk"):s}}function Q5t(e="e2b",t){let r=typeof t=="string"?{apiKey:t}:t??{},{apiKey:n,...i}=r;return aTe(n,e,i)}async function lvn(){let e=process.env[dU];if(e)try{let{createE2BProvider:s}=await Promise.resolve().then(()=>(E1(),yne));return process.env.E2B_API_URL===VK()&&delete process.env.E2B_API_URL,s({apiKey:e})}catch(s){let o=s;throw o.message?.includes("Cannot find module")||o.message?.includes("MODULE_NOT_FOUND")?new Error(`${dU} is set but @evolvingmachines/e2b failed to load.
|
|
646
646
|
Try reinstalling: npm install @evolvingmachines/sdk`):o}let t=process.env[fU];if(t)try{let{createDaytonaProvider:s}=await Promise.resolve().then(()=>(dB(),j0e));return s({apiKey:t})}catch(s){let o=s;throw o.message?.includes("Cannot find module")||o.message?.includes("MODULE_NOT_FOUND")?new Error(`${fU} is set but @evolvingmachines/daytona failed to load.
|
|
647
647
|
Try installing: npm install @evolvingmachines/daytona`):o}let r=process.env[pU],n=process.env[$K];if(r&&n)try{let{createModalProvider:s}=await Promise.resolve().then(()=>(SK(),R8t));return s({tokenId:r,tokenSecret:n})}catch(s){let o=s;throw o.message?.includes("Cannot find module")||o.message?.includes("MODULE_NOT_FOUND")?new Error(`${pU} is set but @evolvingmachines/modal failed to load.
|
|
@@ -1224,7 +1224,7 @@ PY`,{timeoutMs:1e4})).exitCode!==0)throw new Error("Managed secret egress proxy
|
|
|
1224
1224
|
`);d=P.pop()??"";for(let F of P){if(!F.trim())continue;let H=f(F);if(this.captureDroidSession(F,H),this.sessionLogger?.writeEventParsed(F,H),t?.onStdout?.(F+`
|
|
1225
1225
|
`),H&&t?.onContent)for(let Y of H)t.onContent(Y)}},m=C=>{t?.onStderr?.(C)},v=await a.commands.spawn(c,{cwd:this.workingDir,timeoutMs:n,envs:u,onStdout:p,onStderr:m}),b=this.beginOperation("run",v,t,"run_start");if(this.hasRun=!0,i)return this.watchBackgroundOperation(b,"run",v,t,a),{sandboxId:a.sandboxId,sessionId:this.managedBrowserSession?.sessionId,browser:this.browserResponseInfo(),runId:l,exitCode:0,stdout:`Background process started with ID ${v.processId}`,stderr:""};let S;try{S=await v.wait()}catch(C){throw this.interruptedOperations.delete(b),this.finalizeOperation(b,t,"run_failed","error"),C}if(this.interruptedOperations.delete(b)||S.exitCode===130?this.finalizeOperation(b,t,"run_interrupted","interrupted"):S.exitCode===0?this.finalizeOperation(b,t,"run_complete","idle"):this.finalizeOperation(b,t,"run_failed","error"),d.trim()){let C=f(d);if(this.captureDroidSession(d,C),this.sessionLogger?.writeEventParsed(d,C),t?.onStdout?.(d+`
|
|
1226
1226
|
`),C&&t?.onContent)for(let P of C)t.onContent(P)}await this.writeDroidSessionState(a),this.sessionLogger&&!i&&await this.flushSessionLoggerWithTimeout();let T;if(this.storage&&!i&&S.exitCode===0)try{T=await o5t(a,this.storage,this.agentConfig.type,this.workingDir,{tag:this.sessionTag,model:this.agentConfig.model||this.registry.defaultModel,workspaceMode:this.options.workspaceMode||"knowledge",comment:s,parentId:this.lastCheckpointId}),this.lastCheckpointId=T.id}catch(C){console.warn(`[Evolve] Auto-checkpoint failed: ${C.message}`)}return{sandboxId:a.sandboxId,sessionId:this.managedBrowserSession?.sessionId,browser:this.browserResponseInfo(),runId:l,exitCode:S.exitCode,stdout:S.stdout,stderr:S.stderr,checkpoint:T}}async executeCommand(e,t={},r){let{timeoutMs:n=hU,background:i=!1}=t;if(this.activeCommand)throw new Error("Agent is already running. Call interrupt(), wait for the active/background command to finish, or create a new Evolve instance.");let s=await this.getSandbox(r);this.credentialsSealed||await this.ensureProviderRuntimeToken(),this.lastRunTimestamp=Date.now(),this.requiresPreRunDashboardIngest()&&(this.ensureSessionLogger(s),this.sessionLogger?.writePrompt(e),await this.flushSessionLoggerWithTimeout());let o="",a="",c=m=>{o+=m,r?.onStdout?.(m)},l=m=>{a+=m,r?.onStderr?.(m)},u=this.credentialsSealed?{}:this.buildProviderRuntimeProcessEnvs(),d=await s.commands.spawn(e,{cwd:this.workingDir,timeoutMs:n,envs:Object.keys(u).length>0?u:void 0,onStdout:c,onStderr:l}),f=this.beginOperation("command",d,r,"command_start");if(i)return this.watchBackgroundOperation(f,"command",d,r),{sandboxId:s.sandboxId,sessionId:this.managedBrowserSession?.sessionId,browser:this.browserResponseInfo(),exitCode:0,stdout:`Background process started with ID ${d.processId}`,stderr:""};let p;try{p=await d.wait()}catch(m){throw this.interruptedOperations.delete(f),this.finalizeOperation(f,r,"command_failed","error"),m}return this.interruptedOperations.delete(f)||p.exitCode===130?this.finalizeOperation(f,r,"command_interrupted","interrupted"):p.exitCode===0?this.finalizeOperation(f,r,"command_complete","idle"):this.finalizeOperation(f,r,"command_failed","error"),{sandboxId:s.sandboxId,sessionId:this.managedBrowserSession?.sessionId,browser:this.browserResponseInfo(),exitCode:p.exitCode,stdout:o||p.stdout||"",stderr:a||p.stderr||""}}async sealCredentials(){if(!this.credentialsSealed){if(!this.sandbox)throw new Error("No active sandbox. Call run() or executeCommand() first.");if(this.activeCommand)throw new Error("Cannot seal credentials while a process is running.");if(this.agentConfig.isDirectMode&&!this.agentConfig.externalGateway)throw new Error("Credential sealing requires gateway mode; direct provider credentials cannot be revoked by Evolve");if([this.options.secrets&&Object.keys(this.options.secrets).length>0,this.options.sandboxCreateOptions?.envs&&Object.keys(this.options.sandboxCreateOptions.envs).length>0,this.options.managedSecrets,this.options.integrations,this.options.mcpServers&&Object.keys(this.options.mcpServers).length>0,this.options.managedBrowser,this.options.browserCredentials].some(Boolean))throw new Error("Credential sealing requires a credential-minimal sandbox: omit secrets, managed secrets, integrations, MCP servers, and browser credentials");if(this.agentConfig.externalGateway){await this.agentConfig.externalGateway.revoke(),this.credentialsSealed=!0;return}if(!this.providerRuntimeToken||!this.options.providerRouting)throw new Error("Cannot seal credentials: no active provider runtime token to revoke. Without a gateway-issued runtime token the sandbox may hold credentials Evolve cannot revoke, so sealing would be a false guarantee.");await this.closeProviderRuntimeToken(!0),this.credentialsSealed=!0}}isSealed(){return this.credentialsSealed}async collectArtifacts(e){if(!this.credentialsSealed)throw new Error("Call sealCredentials() before collecting artifacts.");if(!this.sandbox)throw new Error("No active sandbox.");if(this.activeCommand)throw new Error("Cannot collect artifacts while a process is running.");return Ybn(this.sandbox,this.workingDir,e)}async uploadContext(e){let t=await this.getSandbox();await this.uploadContextFiles(t,e)}async uploadFiles(e){let t=await this.getSandbox();await this.uploadWorkspaceFiles(t,e)}async uploadFileFromPath(e,t){let r=await this.getSandbox(),n=e.startsWith("/")?e:`${this.workingDir}/${e}`,i=n.substring(0,n.lastIndexOf("/"));if(i&&await r.commands.run(`mkdir -p ${i}`,{timeoutMs:3e4}),r.files.writeFromPath){await r.files.writeFromPath(n,t);return}let{readFile:s}=await import("fs/promises");await r.files.write(n,await s(t))}async getOutputFiles(e=!1){let t=await this.getSandbox(),r=`${this.workingDir}/output`,n=e?"":"-maxdepth 1",i=(await t.commands.run(`find ${r} ${n} -type f -exec stat -c '%n|%Z' {} \\; 2>/dev/null || true`,{timeoutMs:3e4})).stdout.split(`
|
|
1227
|
-
`).filter(Boolean),s=this.lastRunTimestamp?Math.floor(this.lastRunTimestamp/1e3)-2:0,o=[],a=`${r}/`;for(let f of i){let[p,m]=f.split("|");if(!p||!m)continue;let v=parseInt(m,10);s>0&&v<s||o.push(p)}let c={},l=await Promise.all(o.map(async f=>{try{let p=await t.files.read(f);return{relativePath:f.startsWith(a)?f.slice(a.length):f.split("/").pop()||f,content:p}}catch{return null}}));for(let f of l)f&&(c[f.relativePath]=f.content);if(!this.zodSchema&&!this.jsonSchema)return{files:c,data:null};let u=c["result.json"];if(!u)return{files:c,data:null,error:"Schema provided but agent did not create output/result.json"};let d=typeof u=="string"?u:new TextDecoder().decode(u);try{let f=JSON.parse(d);if(this.zodSchema){let p=this.zodSchema.safeParse(f);return p.success?{files:c,data:p.data}:{files:c,data:null,error:`Schema validation failed: ${p.error.message}`,rawData:d}}if(this.compiledValidator){if(this.compiledValidator(f))return{files:c,data:f};{let p=this.compiledValidator.errors?.map(m=>`${m.instancePath} ${m.message}`).join(", ")||"Unknown validation error";return{files:c,data:null,error:`Schema validation failed: ${p}`,rawData:d}}}return{files:c,data:null}}catch(f){return{files:c,data:null,error:`Failed to parse result.json: ${f.message}`,rawData:d}}}async checkpoint(e){if(!this.storage)throw new Error("Storage not configured. Call .withStorage().");if(!this.sandbox)throw new Error("No active sandbox. Call run() first.");let t=await o5t(this.sandbox,this.storage,this.agentConfig.type,this.workingDir,{tag:this.sessionTag,model:this.agentConfig.model||this.registry.defaultModel,workspaceMode:this.options.workspaceMode||"knowledge",comment:e?.comment,parentId:this.lastCheckpointId});return this.lastCheckpointId=t.id,t}getSession(){return this.sandbox?.sandboxId||this.options.sandboxId||null}async setSession(e){if(this.credentialsSealed)throw new Error("Agent credentials are sealed and this Evolve instance cannot switch sandboxes");if(this.options.managedSecrets)throw new Error("setSession() cannot be used with managed secrets; managed secret grants are sandbox-scoped.");if(this.options.sandboxCreateOptions?.user)throw new Error("setSession() cannot be used with a configured sandbox user; the user cannot be enforced on an existing sandbox.");if(this.activeCommand&&!await this.interrupt())throw new Error("Cannot switch session while an active process is running and could not be interrupted.");await this.rotateSession(),await this.closeProviderRuntimeToken(),await this.closeManagedSecretRuntimeToken(),await this.closeManagedBrowserSession(),this.options.sandboxId=e,this.sandbox=void 0,this.interruptedOperations.clear(),this.invalidateActiveOperation(),this.sandboxState="ready",this.agentState="idle",this.hasRun=!0,this.lastCheckpointId=void 0}async pause(e){this.sandbox&&(this.activeCommand&&await this.interrupt(e),await this.sandbox.pause(),this.sandboxState="paused",this.agentState="idle",this.emitLifecycle(e,"sandbox_pause"))}async resume(e){this.sandbox&&this.options.sandboxProvider&&(this.sandbox=await this.options.sandboxProvider.connect(this.sandbox.sandboxId),this.sandboxState="ready",this.agentState="idle",this.emitLifecycle(e,"sandbox_resume"))}async interrupt(e){if(!this.activeCommand&&!this.activeProcessId)return!1;let t=this.activeOperationId,r=this.activeOperationKind,n=!1;try{this.activeCommand?n=await this.activeCommand.kill():this.sandbox&&this.activeProcessId&&(n=await this.sandbox.commands.kill(this.activeProcessId))}catch{n=!1}if(!n)return this.sandboxState="running",this.agentState="running",!1;t!==null&&this.interruptedOperations.add(t),this.invalidateActiveOperation(),this.sandboxState="ready",this.agentState="interrupted";let i=r==="run"?"run_interrupted":"command_interrupted";return this.emitLifecycle(e,i),n}status(){let e=this.browserRuntimeInfo();return{sandboxId:this.getSession(),sandbox:this.sandboxState,agent:this.agentState,activeProcessId:this.activeProcessId,hasRun:this.hasRun,timestamp:new Date().toISOString(),...e?{browser:e}:{}}}async kill(e){await this.rotateSession();let t;try{this.activeCommand&&await this.interrupt(e),this.sandbox&&(await this.sandbox.kill(),this.sandbox=void 0)}catch(r){t=r}finally{await this.closeProviderRuntimeToken(),await this.closeManagedSecretRuntimeToken(),await this.closeManagedBrowserSession()}if(t)throw t;this.options.sandboxId=void 0,this.interruptedOperations.clear(),this.invalidateActiveOperation(),this.sandboxState="stopped",this.agentState="idle",this.hasRun=!1,this.lastCheckpointId=void 0,this.emitLifecycle(e,"sandbox_killed")}async getHost(e){return(await this.getSandbox()).getHost(e)}getAgentType(){return this.agentConfig.type}getSessionTag(){return!this.sandbox&&!this.sessionLogger?null:this.sessionTag}getSessionTimestamp(){return this.sessionLogger?.getTimestamp()||null}async flushObservability(){await this.sessionLogger?.flush()}async rotateSession(){let e=!!this.sessionLogger;this.sessionLogger&&(await this.sessionLogger.close(),this.sessionLogger=void 0),e&&(this.previousSessionTag=this.sessionTag),this.sessionTag=I5t(this.options.sessionTagPrefix||"evolve")}async fetchSpend(e){if(this.agentConfig.isDirectMode)throw new Error("Cost tracking requires gateway mode (set EVOLVE_API_KEY).");let t=this.agentConfig.apiKey;if(!t)throw new Error("Cost tracking requires an API key.");let r=process.env.EVOLVE_DASHBOARD_URL||oa,n=await fetch(`${r}/api/sessions/spend?${e}`,{headers:{Authorization:`Bearer ${t}`},signal:AbortSignal.timeout(1e4)});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`Spend query failed (${n.status}): ${i}`)}return n}resolveSpendTag(){if(this.sandbox||this.sessionLogger)return this.sessionTag;if(this.previousSessionTag)return this.previousSessionTag;throw new Error("No session to query. Call run() first.")}normalizeRunCost(e,t){return{...e,asOf:e.asOf??t.asOf,isComplete:e.isComplete??t.isComplete,truncated:e.truncated??t.truncated}}normalizeSessionCost(e){let t={asOf:e.asOf,isComplete:e.isComplete,truncated:e.truncated};return{...e,runs:e.runs.map(r=>this.normalizeRunCost(r,t))}}async getSessionCost(){let e=this.resolveSpendTag(),t=new URLSearchParams({tag:e}),r=await(await this.fetchSpend(t)).json();return this.normalizeSessionCost(r)}async getRunCost(e){let t=this.resolveSpendTag();if("runId"in e){let s=new URLSearchParams({tag:t,runId:e.runId}),o=await(await this.fetchSpend(s)).json();return this.normalizeRunCost(o,{asOf:new Date().toISOString(),isComplete:!1,truncated:!1})}let r=await this.getSessionCost(),n=e.index>0?e.index-1:r.runs.length+e.index,i=r.runs[n];if(!i)throw new Error(`Run index ${e.index} out of range. Session has ${r.runs.length} run(s).`);return i}};function tSn(e){return(e||process.env.EVOLVE_DASHBOARD_URL||oa).replace(/\/$/,"")}function rSn(e){let t=e||process.env.EVOLVE_API_KEY;if(!t)throw new Error("Browser profiles require EVOLVE_API_KEY or an explicit apiKey");return t}async function nSn(e){return await e.text().catch(()=>"")}async function x5t(e,t,r={}){let n=await fetch(`${tSn(e?.dashboardUrl)}${t}`,{...r,headers:{Authorization:`Bearer ${rSn(e?.apiKey)}`,accept:"application/json",...r.body?{"content-type":"application/json"}:{},...r.headers||{}}});if(!n.ok)throw new Error(`Browser profiles request failed (${n.status}): ${await nSn(n)}`);return n.status===204?{}:await n.json()}var iSn=class{constructor(e={}){this.config=e}toMetadata(e){return{id:e.id,profile:e.profile,createdAt:e.createdAt||e.created_at||"",updatedAt:e.updatedAt||e.updated_at||"",lastUsedAt:e.lastUsedAt??e.last_used_at??null}}async list(){return{profiles:(await x5t(this.config,"/api/browser-profiles")).profiles.map(e=>this.toMetadata(e))}}async delete(e){return await x5t(this.config,"/api/browser-profiles",{method:"DELETE",body:JSON.stringify(e)})}};function sSn(e={}){return new iSn(e)}var Yw=class extends A5t.EventEmitter{config={};agent;fallbackSandboxState="stopped";fallbackAgentState="idle";fallbackHasRun=!1;constructor(){super()}on(e,t){return super.on(e,t)}off(e,t){return super.off(e,t)}emit(e,...t){return super.emit(e,...t)}withAgent(e){return e&&(z5t(e),K5t(e),this.config.agent=e,this._cachedGatewayOverrides=null),this}withSandbox(e){return this.config.sandbox=e,this}withSandboxCreateOptions(e){return this.config.sandboxCreateOptions={...e,envs:e.envs?{...e.envs}:void 0,metadata:e.metadata?{...e.metadata}:void 0},this}withWorkingDirectory(e){return this.config.workingDirectory=e,this}withWorkspaceMode(e){return this.config.workspaceMode=e,this}withSecrets(e){return this.config.secrets={...this.config.secrets,...e},this}withManagedSecrets(e){return this.config.managedSecrets=e,this}withSession(e){return this.config.sandboxId=e,this.agent||(this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.fallbackHasRun=!0),this}withSystemPrompt(e){return this.config.systemPrompt=e,this}withContext(e){return this.config.context={...this.config.context,...e},this}withFiles(e){return this.config.files={...this.config.files,...e},this}withMcpServers(e){return this.config.mcpServers={...this.config.mcpServers,...e},this}withBrowser(e={provider:"agent-browser",remote:!0}){return e===!1?delete this.config.browser:this.config.browser=e,this}withBrowserCredentials(e={}){return this.config.browserCredentials=e,this}withPlugins(e){let t=Array.isArray(e)?e:[e];return this.config.plugins=[...this.config.plugins??[],...t],this}withSkills(e){return this.config.skills=e,this}withSchema(e,t){return this.config.schema=e,t&&(BK(e)?console.warn("[Evolve] schemaOptions ignored for Zod schemas - use .passthrough(), .strip(), z.coerce instead"):this.config.schemaOptions=t),this}withSessionTagPrefix(e){return this.config.sessionTagPrefix=e,this}withObservability(e){return this.config.observability={...this.config.observability,...e},this}withIntegrations(e){return this.config.integrations=e,this}withStorage(e){return this.config.storage=e||{},this}static integrations=Hvn;static browserCredentials=bbn;static browserProfiles=sSn;static managedSecrets=Dbn;async initializeAgent(){let e=Q8t(this.config.agent),t=Jw(e.type);if(this.config.integrations&&e.isDirectMode)throw new Error("withIntegrations() is available only in gateway mode with EVOLVE_API_KEY");if(this.config.managedSecrets&&e.isDirectMode)throw new Error("withManagedSecrets() is available only in gateway mode with EVOLVE_API_KEY");if(this.config.managedSecrets&&this.config.sandboxId)throw new Error("withManagedSecrets() cannot be used with withSession(); managed secret grants are sandbox-scoped.");let r=$bn(this.config.managedSecrets,t);if(r&&this.config.sandbox&&!X5t(this.config.sandbox))throw new Error("withManagedSecrets() requires an Evolve-managed sandbox; remove withSandbox() or pass a managed sandbox provider.");let n=this.config.sandbox??(r?await aTe(e.apiKey):await lvn()),i={},s,o,a=this.config.skills,c;if(this.config.browser){let d=lbn(this.config.browser);if(c=d,d.provider==="browser-use"){if(e.isDirectMode)throw new Error('withBrowser("browser-use") requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.');i=_Te(e.apiKey)}if((d.provider==="actionbook"||d.provider==="agent-browser")&&d.managed){if(e.isDirectMode)throw new Error(`Managed browser provider "${d.provider}" requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.`);s=d.provider==="actionbook"?Avn:kvn,o={provider:d.provider,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa,...d.profile?{profile:d.profile}:{}}}if(d.profile&&!d.managed)throw new Error('withBrowser({ profile }) requires managed remote browser mode. Use .withBrowser({ profile }) or .withBrowser({ provider: "agent-browser", remote: true, profile }).')}if(this.config.browserCredentials!==void 0){if(this.config.sandboxId)throw new Error("withBrowserCredentials() cannot be used with withSession(); browser login tokens are run-scoped.");if(e.isDirectMode)throw new Error("withBrowserCredentials() requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.");if(!c||c.provider!=="agent-browser"||!c.managed)throw new Error('withBrowserCredentials() requires .withBrowser() or .withBrowser({ provider: "agent-browser", remote: true }).');if(this.config.mcpServers?.["browser-login"])throw new Error('withBrowserCredentials() reserves the "browser-login" MCP server name.')}let l=this.config.storage!==void 0?e7t(this.config.storage,!e.isDirectMode,oa,e.isDirectMode?void 0:e.apiKey):void 0,u={sandboxProvider:n,sandboxCreateOptions:this.config.sandboxCreateOptions,secrets:this.config.secrets,managedSecrets:r?{secrets:r,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa}:void 0,sandboxId:this.config.sandboxId,workingDirectory:this.config.workingDirectory,workspaceMode:this.config.workspaceMode,systemPrompt:this.config.systemPrompt,context:this.config.context,files:this.config.files,mcpServers:{...i,...this.config.mcpServers},browserPrompt:s,managedBrowser:o,browserCredentials:this.config.browserCredentials!==void 0?{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa,config:this.config.browserCredentials}:void 0,plugins:this.config.plugins,skills:a,schema:this.config.schema,schemaOptions:this.config.schemaOptions,sessionTagPrefix:this.config.sessionTagPrefix,observability:this.config.observability,integrations:this.config.integrations?{...this.config.integrations,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa}:void 0,providerRouting:e.isDirectMode?void 0:{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa},storage:l};this.agent=new eSn(e,u)}createStreamCallbacks(){let e=this.listenerCount("stdout")>0,t=this.listenerCount("stderr")>0,r=this.listenerCount("content")>0,n=this.listenerCount("lifecycle")>0;return{onStdout:e?i=>this.emit("stdout",i):void 0,onStderr:t?i=>this.emit("stderr",i):void 0,onContent:r?i=>this.emit("content",i):void 0,onLifecycle:n?i=>this.emit("lifecycle",i):void 0}}emitLifecycleFromStatus(e){if(this.listenerCount("lifecycle")===0)return;let t=this.status();this.emit("lifecycle",{sandboxId:t.sandboxId,sandbox:t.sandbox,agent:t.agent,timestamp:new Date().toISOString(),reason:e,...t.browser?{browser:t.browser}:{}})}async run({prompt:e,timeoutMs:t,background:r,from:n,checkpointComment:i}){if(n&&this.config.sandboxId)throw new Error("Cannot use 'from' with 'withSession()' \u2014 restore requires a fresh sandbox.");this.agent||await this.initializeAgent();let s=this.createStreamCallbacks();return this.agent.run({prompt:e,timeoutMs:t,background:r,from:n,checkpointComment:i},s)}async executeCommand(e,t={}){this.agent||await this.initializeAgent();let r=this.createStreamCallbacks();return this.agent.executeCommand(e,t,r)}async prepareSandbox(){this.agent||await this.initializeAgent();let e=this.createStreamCallbacks();return(await this.agent.getSandbox(e)).sandboxId}async sealCredentials(){if(!this.agent)throw new Error("Agent not initialized. Call run() or executeCommand() first.");await this.agent.sealCredentials()}isSealed(){return this.agent?.isSealed()??!1}resolvedSkills(){return this.agent?.resolvedSkills()??[]}async collectArtifacts(e){if(!this.agent)throw new Error("Agent not initialized. Call run() or executeCommand() first.");return this.agent.collectArtifacts(e)}async interrupt(){if(!this.agent)return!1;let e=this.createStreamCallbacks();return this.agent.interrupt(e)}async uploadContext(e){return this.agent||await this.initializeAgent(),this.agent.uploadContext(e)}async uploadFiles(e){return this.agent||await this.initializeAgent(),this.agent.uploadFiles(e)}async uploadFileFromPath(e,t){return this.agent||await this.initializeAgent(),this.agent.uploadFileFromPath(e,t)}async getOutputFiles(e=!1){if(!this.agent)throw new Error("Agent not initialized. Call run() first.");return this.agent.getOutputFiles(e)}async checkpoint(e){if(!this.agent)throw new Error("Agent not initialized. Call run() first.");return this.agent.checkpoint(e)}_cachedGatewayOverrides=null;resolveGatewayOverrides(){if(this._cachedGatewayOverrides!==null)return this._cachedGatewayOverrides||void 0;try{let e=Q8t(this.config.agent);if(!e.isDirectMode)return this._cachedGatewayOverrides={gatewayUrl:oa,gatewayApiKey:e.apiKey},this._cachedGatewayOverrides}catch{}this._cachedGatewayOverrides=void 0}async listCheckpoints(e){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return f5t(this.config.storage,this.resolveGatewayOverrides()||{}).listCheckpoints(e)}storage(){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return f5t(this.config.storage,this.resolveGatewayOverrides()||{})}getSession(){return this.agent?this.agent.getSession():this.config.sandboxId??null}async setSession(e){if(this.config.managedSecrets)throw new Error("setSession() cannot be used with withManagedSecrets(); managed secret grants are sandbox-scoped.");this.agent?await this.agent.setSession(e):(this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.fallbackHasRun=!0),this.config.sandboxId=e}status(){return this.agent?this.agent.status():{sandboxId:this.config.sandboxId??null,sandbox:this.fallbackSandboxState,agent:this.fallbackAgentState,activeProcessId:null,hasRun:this.fallbackHasRun,timestamp:new Date().toISOString()}}async pause(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.pause(e);return}this.config.sandboxId&&this.config.sandbox&&(await(await this.config.sandbox.connect(this.config.sandboxId)).pause(),this.fallbackSandboxState="paused",this.fallbackAgentState="idle",this.emitLifecycleFromStatus("sandbox_pause"))}async resume(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.resume(e);return}this.config.sandboxId&&this.config.sandbox&&(await this.config.sandbox.connect(this.config.sandboxId),this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.emitLifecycleFromStatus("sandbox_resume"))}async kill(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.kill(e),this.config.sandboxId=void 0,this.fallbackSandboxState="stopped",this.fallbackAgentState="idle",this.fallbackHasRun=!1;return}this.config.sandboxId&&this.config.sandbox&&(await(await this.config.sandbox.connect(this.config.sandboxId)).kill(),this.fallbackSandboxState="stopped",this.fallbackAgentState="idle",this.fallbackHasRun=!1,this.emitLifecycleFromStatus("sandbox_killed"),this.config.sandboxId=void 0)}async getHost(e){return this.agent||await this.initializeAgent(),this.agent.getHost(e)}getSessionTag(){return this.agent?.getSessionTag()||null}getSessionTimestamp(){return this.agent?.getSessionTimestamp()||null}async flushObservability(){await this.agent?.flushObservability()}async getSessionCost(){if(!this.agent)throw new Error("No agent initialized. Call run() first.");return this.agent.getSessionCost()}async getRunCost(e){if(!this.agent)throw new Error("No agent initialized. Call run() first.");return this.agent.getRunCost(e)}},oSn=class{permits;queue=[];constructor(e){if(e<1)throw new Error("Semaphore max must be >= 1");this.permits=e}async use(e){await this.acquire();try{return await e()}finally{this.release()}}acquire(){return this.permits>0?(this.permits--,Promise.resolve()):new Promise(e=>this.queue.push(e))}release(){this.queue.length>0?this.queue.shift()():this.permits++}},Z3=Symbol.for("evolve.SwarmResult"),T5t=class _7t extends Array{get success(){return this.filter(t=>t.status==="success")}get filtered(){return this.filter(t=>t.status==="filtered")}get error(){return this.filter(t=>t.status==="error")}static from(t){let r=new _7t;return r.push(...t),r}},wZn=class PK{config;semaphore;constructor(t={}){let r=t.concurrency??ITe;if(r>HK)throw new Error(`concurrency=${r} exceeds max ${HK}. For higher parallelism, scale horizontally with multiple processes.`);this.config={agent:t.agent,sandbox:t.sandbox,tag:t.tag??"swarm",concurrency:r,timeoutMs:t.timeoutMs??hU,workspaceMode:t.workspaceMode??"knowledge",retry:t.retry,mcpServers:t.mcpServers,skills:t.skills,integrations:t.integrations},this.semaphore=new oSn(this.config.concurrency)}async map(t){let{items:r,prompt:n,bestOf:i,verify:s}=t,o=t.retry??this.config.retry,a=this.generateOperationId(),c=t.timeoutMs??this.config.timeoutMs;if(i&&s)throw new Error("map() cannot use both bestOf and verify options simultaneously");let l=await Promise.all(r.map((u,d)=>i?this.executeMapItemWithBestOf(u,n,d,a,t,c,o):s?this.executeMapItemWithVerify(u,n,d,a,t,c,o):o?V0(f=>this.executeMapItem(u,n,d,a,t,c,f),o,d):this.executeMapItem(u,n,d,a,t,c)));return T5t.from(l)}async filter(t){let{items:r,prompt:n,condition:i,verify:s}=t,o=t.retry??this.config.retry,a=this.generateOperationId(),c=t.timeoutMs??this.config.timeoutMs,l=await Promise.all(r.map((d,f)=>s?this.executeFilterItemWithVerify(d,n,f,a,t,c,o):o?V0(p=>this.executeFilterItem(d,n,f,a,t,c,p),o,f):this.executeFilterItem(d,n,f,a,t,c))),u=[];for(let d of l)if(d.status==="error")u.push(d);else if(d.data!==null)try{i(d.data)?u.push(d):u.push({...d,status:"filtered"})}catch(f){u.push({...d,status:"error",data:null,error:`Condition function threw: ${f.message}`})}return T5t.from(u)}async reduce(t){let{items:r,prompt:n,verify:i}=t,s=t.retry??this.config.retry,o=this.generateOperationId(),a=t.timeoutMs??this.config.timeoutMs,c=[],l=[];r.forEach((P,F)=>{c.push(this.getFiles(P)),l.push(this.getIndex(P,F))});let u={};c.forEach((P,F)=>{Object.entries(P).forEach(([H,Y])=>{u[`item_${l[F]}/${H}`]=Y})});let d=Gxe(u),f=Ww(Dvn,{fileTree:d}),p=t.systemPrompt?`${f}
|
|
1227
|
+
`).filter(Boolean),s=this.lastRunTimestamp?Math.floor(this.lastRunTimestamp/1e3)-2:0,o=[],a=`${r}/`;for(let f of i){let[p,m]=f.split("|");if(!p||!m)continue;let v=parseInt(m,10);s>0&&v<s||o.push(p)}let c={},l=await Promise.all(o.map(async f=>{try{let p=await t.files.read(f);return{relativePath:f.startsWith(a)?f.slice(a.length):f.split("/").pop()||f,content:p}}catch{return null}}));for(let f of l)f&&(c[f.relativePath]=f.content);if(!this.zodSchema&&!this.jsonSchema)return{files:c,data:null};let u=c["result.json"];if(!u)return{files:c,data:null,error:"Schema provided but agent did not create output/result.json"};let d=typeof u=="string"?u:new TextDecoder().decode(u);try{let f=JSON.parse(d);if(this.zodSchema){let p=this.zodSchema.safeParse(f);return p.success?{files:c,data:p.data}:{files:c,data:null,error:`Schema validation failed: ${p.error.message}`,rawData:d}}if(this.compiledValidator){if(this.compiledValidator(f))return{files:c,data:f};{let p=this.compiledValidator.errors?.map(m=>`${m.instancePath} ${m.message}`).join(", ")||"Unknown validation error";return{files:c,data:null,error:`Schema validation failed: ${p}`,rawData:d}}}return{files:c,data:null}}catch(f){return{files:c,data:null,error:`Failed to parse result.json: ${f.message}`,rawData:d}}}async checkpoint(e){if(!this.storage)throw new Error("Storage not configured. Call .withStorage().");if(!this.sandbox)throw new Error("No active sandbox. Call run() first.");let t=await o5t(this.sandbox,this.storage,this.agentConfig.type,this.workingDir,{tag:this.sessionTag,model:this.agentConfig.model||this.registry.defaultModel,workspaceMode:this.options.workspaceMode||"knowledge",comment:e?.comment,parentId:this.lastCheckpointId});return this.lastCheckpointId=t.id,t}getSession(){return this.sandbox?.sandboxId||this.options.sandboxId||null}async setSession(e){if(this.credentialsSealed)throw new Error("Agent credentials are sealed and this Evolve instance cannot switch sandboxes");if(this.options.managedSecrets)throw new Error("setSession() cannot be used with managed secrets; managed secret grants are sandbox-scoped.");if(this.options.sandboxCreateOptions?.user)throw new Error("setSession() cannot be used with a configured sandbox user; the user cannot be enforced on an existing sandbox.");if(this.activeCommand&&!await this.interrupt())throw new Error("Cannot switch session while an active process is running and could not be interrupted.");await this.rotateSession(),await this.closeProviderRuntimeToken(),await this.closeManagedSecretRuntimeToken(),await this.closeManagedBrowserSession(),this.options.sandboxId=e,this.sandbox=void 0,this.interruptedOperations.clear(),this.invalidateActiveOperation(),this.sandboxState="ready",this.agentState="idle",this.hasRun=!0,this.lastCheckpointId=void 0}async pause(e){this.sandbox&&(this.activeCommand&&await this.interrupt(e),await this.sandbox.pause(),this.sandboxState="paused",this.agentState="idle",this.emitLifecycle(e,"sandbox_pause"))}async resume(e){this.sandbox&&this.options.sandboxProvider&&(this.sandbox=await this.options.sandboxProvider.connect(this.sandbox.sandboxId),this.sandboxState="ready",this.agentState="idle",this.emitLifecycle(e,"sandbox_resume"))}async interrupt(e){if(!this.activeCommand&&!this.activeProcessId)return!1;let t=this.activeOperationId,r=this.activeOperationKind,n=!1;try{this.activeCommand?n=await this.activeCommand.kill():this.sandbox&&this.activeProcessId&&(n=await this.sandbox.commands.kill(this.activeProcessId))}catch{n=!1}if(!n)return this.sandboxState="running",this.agentState="running",!1;t!==null&&this.interruptedOperations.add(t),this.invalidateActiveOperation(),this.sandboxState="ready",this.agentState="interrupted";let i=r==="run"?"run_interrupted":"command_interrupted";return this.emitLifecycle(e,i),n}status(){let e=this.browserRuntimeInfo();return{sandboxId:this.getSession(),sandbox:this.sandboxState,agent:this.agentState,activeProcessId:this.activeProcessId,hasRun:this.hasRun,timestamp:new Date().toISOString(),...e?{browser:e}:{}}}async kill(e){await this.rotateSession();let t;try{this.activeCommand&&await this.interrupt(e),this.sandbox&&(await this.sandbox.kill(),this.sandbox=void 0)}catch(r){t=r}finally{await this.closeProviderRuntimeToken(),await this.closeManagedSecretRuntimeToken(),await this.closeManagedBrowserSession()}if(t)throw t;this.options.sandboxId=void 0,this.interruptedOperations.clear(),this.invalidateActiveOperation(),this.sandboxState="stopped",this.agentState="idle",this.hasRun=!1,this.lastCheckpointId=void 0,this.emitLifecycle(e,"sandbox_killed")}async getHost(e){return(await this.getSandbox()).getHost(e)}getAgentType(){return this.agentConfig.type}getSessionTag(){return!this.sandbox&&!this.sessionLogger?null:this.sessionTag}getSessionTimestamp(){return this.sessionLogger?.getTimestamp()||null}async flushObservability(){await this.sessionLogger?.flush()}async rotateSession(){let e=!!this.sessionLogger;this.sessionLogger&&(await this.sessionLogger.close(),this.sessionLogger=void 0),e&&(this.previousSessionTag=this.sessionTag),this.sessionTag=I5t(this.options.sessionTagPrefix||"evolve")}async fetchSpend(e){if(this.agentConfig.isDirectMode)throw new Error("Cost tracking requires gateway mode (set EVOLVE_API_KEY).");let t=this.agentConfig.apiKey;if(!t)throw new Error("Cost tracking requires an API key.");let r=process.env.EVOLVE_DASHBOARD_URL||oa,n=await fetch(`${r}/api/sessions/spend?${e}`,{headers:{Authorization:`Bearer ${t}`},signal:AbortSignal.timeout(1e4)});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`Spend query failed (${n.status}): ${i}`)}return n}resolveSpendTag(){if(this.sandbox||this.sessionLogger)return this.sessionTag;if(this.previousSessionTag)return this.previousSessionTag;throw new Error("No session to query. Call run() first.")}normalizeRunCost(e,t){return{...e,asOf:e.asOf??t.asOf,isComplete:e.isComplete??t.isComplete,truncated:e.truncated??t.truncated}}normalizeSessionCost(e){let t={asOf:e.asOf,isComplete:e.isComplete,truncated:e.truncated};return{...e,runs:e.runs.map(r=>this.normalizeRunCost(r,t))}}async getSessionCost(){let e=this.resolveSpendTag(),t=new URLSearchParams({tag:e}),r=await(await this.fetchSpend(t)).json();return this.normalizeSessionCost(r)}async getRunCost(e){let t=this.resolveSpendTag();if("runId"in e){let s=new URLSearchParams({tag:t,runId:e.runId}),o=await(await this.fetchSpend(s)).json();return this.normalizeRunCost(o,{asOf:new Date().toISOString(),isComplete:!1,truncated:!1})}let r=await this.getSessionCost(),n=e.index>0?e.index-1:r.runs.length+e.index,i=r.runs[n];if(!i)throw new Error(`Run index ${e.index} out of range. Session has ${r.runs.length} run(s).`);return i}};function tSn(e){return(e||process.env.EVOLVE_DASHBOARD_URL||oa).replace(/\/$/,"")}function rSn(e){let t=e||process.env.EVOLVE_API_KEY;if(!t)throw new Error("Browser profiles require EVOLVE_API_KEY or an explicit apiKey");return t}async function nSn(e){return await e.text().catch(()=>"")}async function x5t(e,t,r={}){let n=await fetch(`${tSn(e?.dashboardUrl)}${t}`,{...r,headers:{Authorization:`Bearer ${rSn(e?.apiKey)}`,accept:"application/json",...r.body?{"content-type":"application/json"}:{},...r.headers||{}}});if(!n.ok)throw new Error(`Browser profiles request failed (${n.status}): ${await nSn(n)}`);return n.status===204?{}:await n.json()}var iSn=class{constructor(e={}){this.config=e}toMetadata(e){return{id:e.id,profile:e.profile,createdAt:e.createdAt||e.created_at||"",updatedAt:e.updatedAt||e.updated_at||"",lastUsedAt:e.lastUsedAt??e.last_used_at??null}}async list(){return{profiles:(await x5t(this.config,"/api/browser-profiles")).profiles.map(e=>this.toMetadata(e))}}async delete(e){return await x5t(this.config,"/api/browser-profiles",{method:"DELETE",body:JSON.stringify(e)})}};function sSn(e={}){return new iSn(e)}var Yw=class extends A5t.EventEmitter{config={};agent;fallbackSandboxState="stopped";fallbackAgentState="idle";fallbackHasRun=!1;constructor(){super()}on(e,t){return super.on(e,t)}off(e,t){return super.off(e,t)}emit(e,...t){return super.emit(e,...t)}withAgent(e){return e&&(z5t(e),K5t(e),this.config.agent=e,this._cachedGatewayOverrides=null),this}withSandbox(e){return this.config.sandbox=e,this}withSandboxCreateOptions(e){return this.config.sandboxCreateOptions={...e,envs:e.envs?{...e.envs}:void 0,metadata:e.metadata?{...e.metadata}:void 0},this}withWorkingDirectory(e){return this.config.workingDirectory=e,this}withWorkspaceMode(e){return this.config.workspaceMode=e,this}withSecrets(e){return this.config.secrets={...this.config.secrets,...e},this}withManagedSecrets(e){return this.config.managedSecrets=e,this}withSession(e){return this.config.sandboxId=e,this.agent||(this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.fallbackHasRun=!0),this}withSystemPrompt(e){return this.config.systemPrompt=e,this}withContext(e){return this.config.context={...this.config.context,...e},this}withFiles(e){return this.config.files={...this.config.files,...e},this}withMcpServers(e){return this.config.mcpServers={...this.config.mcpServers,...e},this}withBrowser(e={provider:"agent-browser",remote:!0}){return e===!1?delete this.config.browser:this.config.browser=e,this}withBrowserCredentials(e={}){return this.config.browserCredentials=e,this}withPlugins(e){let t=Array.isArray(e)?e:[e];return this.config.plugins=[...this.config.plugins??[],...t],this}withSkills(e){return this.config.skills=e,this}withSchema(e,t){return this.config.schema=e,t&&(BK(e)?console.warn("[Evolve] schemaOptions ignored for Zod schemas - use .passthrough(), .strip(), z.coerce instead"):this.config.schemaOptions=t),this}withSessionTagPrefix(e){return this.config.sessionTagPrefix=e,this}withObservability(e){return this.config.observability={...this.config.observability,...e},this}withIntegrations(e){return this.config.integrations=e,this}withStorage(e){return this.config.storage=e||{},this}static integrations=Hvn;static browserCredentials=bbn;static browserProfiles=sSn;static managedSecrets=Dbn;async initializeAgent(){let e=Q8t(this.config.agent),t=Jw(e.type);if(this.config.integrations&&e.isDirectMode)throw new Error("withIntegrations() is available only in gateway mode with EVOLVE_API_KEY");if(this.config.managedSecrets&&e.isDirectMode)throw new Error("withManagedSecrets() is available only in gateway mode with EVOLVE_API_KEY");if(this.config.managedSecrets&&this.config.sandboxId)throw new Error("withManagedSecrets() cannot be used with withSession(); managed secret grants are sandbox-scoped.");let r=$bn(this.config.managedSecrets,t);if(r&&this.config.sandbox&&!X5t(this.config.sandbox))throw new Error("withManagedSecrets() requires an Evolve-managed sandbox; remove withSandbox() or pass a managed sandbox provider.");let n=this.config.sandbox??(r?await aTe(e.apiKey):await lvn()),i={},s,o,a=this.config.skills,c;if(this.config.browser){let d=lbn(this.config.browser);if(c=d,d.provider==="browser-use"){if(e.isDirectMode)throw new Error('withBrowser("browser-use") requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.');i=_Te(e.apiKey)}if((d.provider==="actionbook"||d.provider==="agent-browser")&&d.managed){if(e.isDirectMode)throw new Error(`Managed browser provider "${d.provider}" requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.`);s=d.provider==="actionbook"?Avn:kvn,o={provider:d.provider,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa,...d.profile?{profile:d.profile}:{}}}if(d.profile&&!d.managed)throw new Error('withBrowser({ profile }) requires managed remote browser mode. Use .withBrowser({ profile }) or .withBrowser({ provider: "agent-browser", remote: true, profile }).')}if(this.config.browserCredentials!==void 0){if(this.config.sandboxId)throw new Error("withBrowserCredentials() cannot be used with withSession(); browser login tokens are run-scoped.");if(e.isDirectMode)throw new Error("withBrowserCredentials() requires gateway mode. Use apiKey/EVOLVE_API_KEY instead of providerApiKey/direct mode.");if(!c||c.provider!=="agent-browser"||!c.managed)throw new Error('withBrowserCredentials() requires .withBrowser() or .withBrowser({ provider: "agent-browser", remote: true }).');if(this.config.mcpServers?.["browser-login"])throw new Error('withBrowserCredentials() reserves the "browser-login" MCP server name.')}let l=this.config.storage!==void 0?e7t(this.config.storage,!e.isDirectMode,oa,e.isDirectMode?void 0:e.apiKey):void 0,u={sandboxProvider:n,sandboxCreateOptions:this.config.sandboxCreateOptions,secrets:this.config.secrets,managedSecrets:r?{secrets:r,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa}:void 0,sandboxId:this.config.sandboxId,workingDirectory:this.config.workingDirectory,workspaceMode:this.config.workspaceMode,systemPrompt:this.config.systemPrompt,context:this.config.context,files:this.config.files,mcpServers:{...i,...this.config.mcpServers},browserPrompt:s,managedBrowser:o,browserCredentials:this.config.browserCredentials!==void 0?{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa,config:this.config.browserCredentials}:void 0,plugins:this.config.plugins,skills:a,schema:this.config.schema,schemaOptions:this.config.schemaOptions,sessionTagPrefix:this.config.sessionTagPrefix,observability:this.config.observability,integrations:this.config.integrations?{...this.config.integrations,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa}:void 0,providerRouting:e.isDirectMode?void 0:{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||oa},storage:l};this.agent=new eSn(e,u)}createStreamCallbacks(){let e=this.listenerCount("stdout")>0,t=this.listenerCount("stderr")>0,r=this.listenerCount("content")>0,n=this.listenerCount("lifecycle")>0;return{onStdout:e?i=>this.emit("stdout",i):void 0,onStderr:t?i=>this.emit("stderr",i):void 0,onContent:r?i=>this.emit("content",i):void 0,onLifecycle:n?i=>this.emit("lifecycle",i):void 0}}emitLifecycleFromStatus(e){if(this.listenerCount("lifecycle")===0)return;let t=this.status();this.emit("lifecycle",{sandboxId:t.sandboxId,sandbox:t.sandbox,agent:t.agent,timestamp:new Date().toISOString(),reason:e,...t.browser?{browser:t.browser}:{}})}async run({prompt:e,timeoutMs:t,background:r,from:n,checkpointComment:i}){if(n&&this.config.sandboxId)throw new Error("Cannot use 'from' with 'withSession()' \u2014 restore requires a fresh sandbox.");this.agent||await this.initializeAgent();let s=this.createStreamCallbacks();return this.agent.run({prompt:e,timeoutMs:t,background:r,from:n,checkpointComment:i},s)}async executeCommand(e,t={}){this.agent||await this.initializeAgent();let r=this.createStreamCallbacks();return this.agent.executeCommand(e,t,r)}async prepareSandbox(){this.agent||await this.initializeAgent();let e=this.createStreamCallbacks();return(await this.agent.getSandbox(e)).sandboxId}async sealCredentials(){if(!this.agent)throw new Error("Agent not initialized. Call run() or executeCommand() first.");await this.agent.sealCredentials()}isSealed(){return this.agent?.isSealed()??!1}resolvedSkills(){return this.agent?.resolvedSkills()??[]}async collectArtifacts(e){if(!this.agent)throw new Error("Agent not initialized. Call run() or executeCommand() first.");return this.agent.collectArtifacts(e)}async interrupt(){if(!this.agent)return!1;let e=this.createStreamCallbacks();return this.agent.interrupt(e)}async uploadContext(e){return this.agent||await this.initializeAgent(),this.agent.uploadContext(e)}async uploadFiles(e){return this.agent||await this.initializeAgent(),this.agent.uploadFiles(e)}async uploadFileFromPath(e,t){return this.agent||await this.initializeAgent(),this.agent.uploadFileFromPath(e,t)}async getOutputFiles(e=!1){if(!this.agent)throw new Error("Agent not initialized. Call run() first.");return this.agent.getOutputFiles(e)}async checkpoint(e){if(!this.agent)throw new Error("Agent not initialized. Call run() first.");return this.agent.checkpoint(e)}_cachedGatewayOverrides=null;resolveGatewayOverrides(){if(this._cachedGatewayOverrides!==null)return this._cachedGatewayOverrides||void 0;try{let e=Q8t(this.config.agent);if(!e.isDirectMode)return this._cachedGatewayOverrides={gatewayUrl:oa,gatewayApiKey:e.apiKey},this._cachedGatewayOverrides}catch{}this._cachedGatewayOverrides=void 0}async listCheckpoints(e){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return f5t(this.config.storage,this.resolveGatewayOverrides()||{}).listCheckpoints(e)}storage(){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return f5t(this.config.storage,this.resolveGatewayOverrides()||{})}getSession(){return this.agent?this.agent.getSession():this.config.sandboxId??null}async setSession(e){if(this.config.managedSecrets)throw new Error("setSession() cannot be used with withManagedSecrets(); managed secret grants are sandbox-scoped.");this.agent?await this.agent.setSession(e):(this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.fallbackHasRun=!0),this.config.sandboxId=e}status(){return this.agent?this.agent.status():{sandboxId:this.config.sandboxId??null,sandbox:this.fallbackSandboxState,agent:this.fallbackAgentState,activeProcessId:null,hasRun:this.fallbackHasRun,timestamp:new Date().toISOString()}}async pause(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.pause(e);return}this.config.sandboxId&&this.config.sandbox&&(await(await this.config.sandbox.connect(this.config.sandboxId)).pause(),this.fallbackSandboxState="paused",this.fallbackAgentState="idle",this.emitLifecycleFromStatus("sandbox_pause"))}async resume(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.resume(e);return}this.config.sandboxId&&this.config.sandbox&&(await this.config.sandbox.connect(this.config.sandboxId),this.fallbackSandboxState="ready",this.fallbackAgentState="idle",this.emitLifecycleFromStatus("sandbox_resume"))}async kill(){if(this.agent){let e=this.createStreamCallbacks();await this.agent.kill(e),this.config.sandboxId=void 0,this.fallbackSandboxState="stopped",this.fallbackAgentState="idle",this.fallbackHasRun=!1;return}this.config.sandboxId&&this.config.sandbox&&(await(await this.config.sandbox.connect(this.config.sandboxId)).kill(),this.fallbackSandboxState="stopped",this.fallbackAgentState="idle",this.fallbackHasRun=!1,this.emitLifecycleFromStatus("sandbox_killed"),this.config.sandboxId=void 0)}async getHost(e){return this.agent||await this.initializeAgent(),this.agent.getHost(e)}getSessionTag(){return this.agent?.getSessionTag()||null}getSessionTimestamp(){return this.agent?.getSessionTimestamp()||null}async flushObservability(){await this.agent?.flushObservability()}async getSessionCost(){if(!this.agent)throw new Error("No agent initialized. Call run() first.");return this.agent.getSessionCost()}async getRunCost(e){if(!this.agent)throw new Error("No agent initialized. Call run() first.");return this.agent.getRunCost(e)}},oSn=class{permits;queue=[];constructor(e){if(e<1)throw new Error("Semaphore max must be >= 1");this.permits=e}async use(e){await this.acquire();try{return await e()}finally{this.release()}}acquire(){return this.permits>0?(this.permits--,Promise.resolve()):new Promise(e=>this.queue.push(e))}release(){this.queue.length>0?this.queue.shift()():this.permits++}},Z3=Symbol.for("evolve.SwarmResult"),T5t=class _7t extends Array{get success(){return this.filter(t=>t.status==="success")}get filtered(){return this.filter(t=>t.status==="filtered")}get error(){return this.filter(t=>t.status==="error")}static from(t){let r=new _7t;return r.push(...t),r}},xZn=class PK{config;semaphore;constructor(t={}){let r=t.concurrency??ITe;if(r>HK)throw new Error(`concurrency=${r} exceeds max ${HK}. For higher parallelism, scale horizontally with multiple processes.`);this.config={agent:t.agent,sandbox:t.sandbox,tag:t.tag??"swarm",concurrency:r,timeoutMs:t.timeoutMs??hU,workspaceMode:t.workspaceMode??"knowledge",retry:t.retry,mcpServers:t.mcpServers,skills:t.skills,integrations:t.integrations},this.semaphore=new oSn(this.config.concurrency)}async map(t){let{items:r,prompt:n,bestOf:i,verify:s}=t,o=t.retry??this.config.retry,a=this.generateOperationId(),c=t.timeoutMs??this.config.timeoutMs;if(i&&s)throw new Error("map() cannot use both bestOf and verify options simultaneously");let l=await Promise.all(r.map((u,d)=>i?this.executeMapItemWithBestOf(u,n,d,a,t,c,o):s?this.executeMapItemWithVerify(u,n,d,a,t,c,o):o?V0(f=>this.executeMapItem(u,n,d,a,t,c,f),o,d):this.executeMapItem(u,n,d,a,t,c)));return T5t.from(l)}async filter(t){let{items:r,prompt:n,condition:i,verify:s}=t,o=t.retry??this.config.retry,a=this.generateOperationId(),c=t.timeoutMs??this.config.timeoutMs,l=await Promise.all(r.map((d,f)=>s?this.executeFilterItemWithVerify(d,n,f,a,t,c,o):o?V0(p=>this.executeFilterItem(d,n,f,a,t,c,p),o,f):this.executeFilterItem(d,n,f,a,t,c))),u=[];for(let d of l)if(d.status==="error")u.push(d);else if(d.data!==null)try{i(d.data)?u.push(d):u.push({...d,status:"filtered"})}catch(f){u.push({...d,status:"error",data:null,error:`Condition function threw: ${f.message}`})}return T5t.from(u)}async reduce(t){let{items:r,prompt:n,verify:i}=t,s=t.retry??this.config.retry,o=this.generateOperationId(),a=t.timeoutMs??this.config.timeoutMs,c=[],l=[];r.forEach((P,F)=>{c.push(this.getFiles(P)),l.push(this.getIndex(P,F))});let u={};c.forEach((P,F)=>{Object.entries(P).forEach(([H,Y])=>{u[`item_${l[F]}/${H}`]=Y})});let d=Gxe(u),f=Ww(Dvn,{fileTree:d}),p=t.systemPrompt?`${f}
|
|
1228
1228
|
|
|
1229
1229
|
${t.systemPrompt}`:f,m=(P,F,H)=>({operationId:o,operation:"reduce",tag:P.tag,sandboxId:P.sandboxId,swarmName:this.config.tag,operationName:t.name,inputCount:r.length,inputIndices:l,errorRetry:F,verifyRetry:H,...this.pipelineContextToMeta(t._pipelineContext)}),v=t.mcpServers??this.config.mcpServers,b=t.skills??this.config.skills,S=t.integrations??this.config.integrations,T=async(P,F,H,Y)=>{let B=await this.semaphore.use(()=>this.execute(u,P,{systemPrompt:p,schema:t.schema,schemaOptions:t.schemaOptions,agent:t.agent,mcpServers:v,skills:b,integrations:S,tagPrefix:F,timeoutMs:a,observability:{swarmName:this.config.tag,operationName:t.name,operationId:o,operation:"reduce",role:"worker",errorRetry:H,verifyRetry:Y&&Y>1?Y-1:void 0,...this.pipelineContextToObservability(t._pipelineContext)}})),X=m(B,H,Y&&Y>1?Y-1:void 0);return B.error?{status:"error",data:null,files:B.files,meta:X,error:B.error,rawData:B.rawData}:{status:"success",data:B.data,files:B.files,meta:X}},C=`${this.config.tag}-reduce`;return i?this.runWithVerification((P,F,H)=>T(P,F,void 0,H),{originalPrompt:n,inputFiles:u,verifyConfig:i,timeoutMs:a,systemPrompt:p,schema:t.schema,mcpServers:v,skills:b,integrations:S,operationId:o,baseTag:C,retry:s,operation:"reduce",_pipelineContext:t._pipelineContext}):s?V0(P=>{let F=P>1?P-1:void 0,H=F?`${C}-er${F}`:C;return T(n,H,F)},s):T(n,C)}async bestOf(t){let{item:r,prompt:n,config:i}=t,s=t.retry??this.config.retry,o=i.n??i.taskAgents?.length;if(o===void 0)throw new Error("bestOf requires n or taskAgents");if(o<2)throw new Error("bestOf requires n >= 2");let a=this.generateOperationId(),c=t.timeoutMs??this.config.timeoutMs,l=this.getFiles(r),u=i.mcpServers??this.config.mcpServers,d=i.judgeMcpServers??i.mcpServers??this.config.mcpServers,f=i.skills??this.config.skills,p=i.judgeSkills??i.skills??this.config.skills,m=i.integrations??this.config.integrations,v=i.judgeIntegrations??i.integrations??this.config.integrations,b=await Promise.all(Array.from({length:o},async(F,H)=>{let Y=s?await V0(B=>this.executeBestOfCandidate({inputFiles:l,prompt:n,candidateIndex:H,operationId:a,config:i,systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,mcpServers:u,skills:f,integrations:m,timeoutMs:c,attempt:B}),s,H):await this.executeBestOfCandidate({inputFiles:l,prompt:n,candidateIndex:H,operationId:a,config:i,systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,mcpServers:u,skills:f,integrations:m,timeoutMs:c});return i.onCandidateComplete?.(0,H,Y.status==="success"?"success":"error"),Y})),S=s?await V0(F=>this.executeBestOfJudge({inputFiles:l,taskPrompt:n,candidates:b,config:i,timeoutMs:c,operationId:a,systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,mcpServers:d,skills:p,integrations:v,attempt:F}),{...s,retryOn:void 0},0):await this.executeBestOfJudge({inputFiles:l,taskPrompt:n,candidates:b,config:i,timeoutMs:c,operationId:a,systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,mcpServers:d,skills:p,integrations:v}),T=b.findIndex(F=>F.status==="success"),C=S.decision?.winner??(T>=0?T:0);i.onJudgeComplete?.(0,C,S.decision?.reasoning??"Judge failed to provide reasoning");let P={operationId:a,operation:"bestof-judge",tag:S.tag,sandboxId:S.sandboxId,swarmName:this.config.tag,operationName:t.name,candidateCount:o};return{winner:b[C]??b[0],winnerIndex:C,judgeReasoning:S.decision?.reasoning??"Judge failed to provide reasoning",judgeMeta:P,candidates:b}}async execute(t,r,n){let i=null,s="",o=n.tagPrefix,a={},c=null,l,u,d={...this.config.agent,...n.agent};try{i=new Yw().withAgent(d).withSandbox(this.config.sandbox).withWorkspaceMode(this.config.workspaceMode).withSessionTagPrefix(n.tagPrefix),n.schema&&i.withSchema(n.schema,n.schemaOptions),n.systemPrompt&&i.withSystemPrompt(n.systemPrompt),n.mcpServers&&i.withMcpServers(n.mcpServers),n.skills?.length&&i.withSkills(n.skills),n.integrations&&i.withIntegrations(n.integrations),n.observability&&i.withObservability(n.observability),Object.keys(t).length>0&&i.withContext(t);let f=await i.run({prompt:r,timeoutMs:n.timeoutMs});s=f.sandboxId,o=i.getSessionTag()??n.tagPrefix;let p=null;try{p=await i.getOutputFiles(!0),a=p.files}catch{}f.exitCode!==0?l=`Agent exited with code ${f.exitCode}`:n.schema?p?(c=p.data,p.error&&(l=p.error),p.rawData&&(u=p.rawData)):l="Failed to read output files from sandbox":c=a}catch(f){if(l=f.message,i){o=i.getSessionTag()??n.tagPrefix;try{a=(await i.getOutputFiles(!0)).files}catch{}}}finally{i&&await i.kill().catch(()=>{})}return{files:a,data:c,tag:o,sandboxId:s,error:l,rawData:u}}async executeMapItem(t,r,n,i,s,o,a=1){let c=this.getFiles(t),l=a>1?`${this.config.tag}-map-${n}-er${a-1}`:`${this.config.tag}-map-${n}`,u=this.evaluatePrompt(r,c,n);if(u instanceof Error)return this.buildErrorResult(`Prompt function threw: ${u.message}`,{operationId:i,operation:"map",tag:l,sandboxId:"",itemIndex:n});let d=s.mcpServers??this.config.mcpServers,f=s.skills??this.config.skills,p=s.integrations??this.config.integrations,m=await this.semaphore.use(()=>this.execute(c,u,{systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,agent:s.agent,mcpServers:d,skills:f,integrations:p,tagPrefix:l,timeoutMs:o,observability:{swarmName:this.config.tag,operationName:s.name,operationId:i,operation:"map",itemIndex:n,role:"worker",errorRetry:a>1?a-1:void 0,...this.pipelineContextToObservability(s._pipelineContext)}})),v={operationId:i,operation:"map",tag:m.tag,sandboxId:m.sandboxId,swarmName:this.config.tag,operationName:s.name,itemIndex:n,errorRetry:a>1?a-1:void 0,...this.pipelineContextToMeta(s._pipelineContext)};return this.buildResult(m,v)}async executeMapItemWithVerify(t,r,n,i,s,o,a){let c=this.getFiles(t),l=`${this.config.tag}-map-${n}`,u=s.verify,d=s.mcpServers??this.config.mcpServers,f=s.skills??this.config.skills,p=s.integrations??this.config.integrations,m=this.evaluatePrompt(r,c,n);if(m instanceof Error)return this.buildErrorResult(`Prompt function threw: ${m.message}`,{operationId:i,operation:"map",tag:l,sandboxId:"",itemIndex:n});let v=async(b,S,T)=>{let C=await this.semaphore.use(()=>this.execute(c,b,{systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,agent:s.agent,mcpServers:d,skills:f,integrations:p,tagPrefix:S,timeoutMs:o,observability:{swarmName:this.config.tag,operationName:s.name,operationId:i,operation:"map",itemIndex:n,role:"worker",verifyRetry:T&&T>1?T-1:void 0,...this.pipelineContextToObservability(s._pipelineContext)}})),P={operationId:i,operation:"map",tag:C.tag,sandboxId:C.sandboxId,swarmName:this.config.tag,operationName:s.name,itemIndex:n,verifyRetry:T&&T>1?T-1:void 0,...this.pipelineContextToMeta(s._pipelineContext)};return this.buildResult(C,P)};return this.runWithVerification(v,{originalPrompt:m,inputFiles:c,verifyConfig:u,timeoutMs:o,systemPrompt:s.systemPrompt,schema:s.schema,mcpServers:d,skills:f,integrations:p,operationId:i,baseTag:l,retry:a,itemIndex:n,operation:"map",_pipelineContext:s._pipelineContext})}async executeMapItemWithBestOf(t,r,n,i,s,o,a){let c=this.getFiles(t),l=`${this.config.tag}-map-${n}`,u=this.evaluatePrompt(r,c,n);if(u instanceof Error)return this.buildErrorResult(`Prompt function threw: ${u.message}`,{operationId:i,operation:"map",tag:l,sandboxId:"",itemIndex:n});let d=s.bestOf,f=d.n??d.taskAgents?.length;if(f===void 0||f<2)return this.buildErrorResult("bestOf requires n >= 2 or taskAgents with at least 2 elements",{operationId:i,operation:"map",tag:l,sandboxId:"",itemIndex:n});let p=s.mcpServers??this.config.mcpServers,m=d.mcpServers??p,v=d.judgeMcpServers??d.mcpServers??p,b=s.skills??this.config.skills,S=d.skills??b,T=d.judgeSkills??d.skills??b,C=s.integrations??this.config.integrations,P=d.integrations??C,F=d.judgeIntegrations??d.integrations??C,H=await Promise.all(Array.from({length:f},async(We,de)=>{let O=a?await V0($=>this.executeBestOfCandidate({inputFiles:c,prompt:u,candidateIndex:de,operationId:i,config:d,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:m,skills:S,integrations:P,timeoutMs:o,parentIndex:n,attempt:$,_pipelineContext:s._pipelineContext}),a,de):await this.executeBestOfCandidate({inputFiles:c,prompt:u,candidateIndex:de,operationId:i,config:d,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:m,skills:S,integrations:P,timeoutMs:o,parentIndex:n,_pipelineContext:s._pipelineContext});return d.onCandidateComplete?.(n,de,O.status==="success"?"success":"error"),O})),Y=a?await V0(We=>this.executeBestOfJudge({inputFiles:c,taskPrompt:u,candidates:H,config:d,timeoutMs:o,operationId:i,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:v,skills:T,integrations:F,parentIndex:n,attempt:We,_pipelineContext:s._pipelineContext}),{...a,retryOn:void 0},0):await this.executeBestOfJudge({inputFiles:c,taskPrompt:u,candidates:H,config:d,timeoutMs:o,operationId:i,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:v,skills:T,integrations:F,parentIndex:n,_pipelineContext:s._pipelineContext}),B=H.findIndex(We=>We.status==="success"),X=Y.decision?.winner??(B>=0?B:0),pe=H[X]??H[0];d.onJudgeComplete?.(n,X,Y.decision?.reasoning??"Judge failed to provide reasoning");let V={operationId:i,operation:"bestof-judge",tag:Y.tag,sandboxId:Y.sandboxId,swarmName:this.config.tag,operationName:s.name,candidateCount:f,...this.pipelineContextToMeta(s._pipelineContext)};return{...pe,meta:{...pe.meta,operation:"map",swarmName:this.config.tag,operationName:s.name,itemIndex:n,...this.pipelineContextToMeta(s._pipelineContext)},bestOf:{winnerIndex:X,judgeReasoning:Y.decision?.reasoning??"Judge failed to provide reasoning",judgeMeta:V,candidates:H}}}async executeFilterItem(t,r,n,i,s,o,a=1){let c=this.getFiles(t),l=a>1?`${this.config.tag}-filter-${n}-er${a-1}`:`${this.config.tag}-filter-${n}`,u=s.mcpServers??this.config.mcpServers,d=s.skills??this.config.skills,f=s.integrations??this.config.integrations,p=await this.semaphore.use(()=>this.execute(c,r,{systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,agent:s.agent,mcpServers:u,skills:d,integrations:f,tagPrefix:l,timeoutMs:o,observability:{swarmName:this.config.tag,operationName:s.name,operationId:i,operation:"filter",itemIndex:n,role:"worker",errorRetry:a>1?a-1:void 0,...this.pipelineContextToObservability(s._pipelineContext)}})),m={operationId:i,operation:"filter",tag:p.tag,sandboxId:p.sandboxId,swarmName:this.config.tag,operationName:s.name,itemIndex:n,errorRetry:a>1?a-1:void 0,...this.pipelineContextToMeta(s._pipelineContext)};return this.buildResult(p,m,c)}async executeFilterItemWithVerify(t,r,n,i,s,o,a){let c=this.getFiles(t),l=`${this.config.tag}-filter-${n}`,u=s.verify,d=s.mcpServers??this.config.mcpServers,f=s.skills??this.config.skills,p=s.integrations??this.config.integrations,m=async(v,b,S)=>{let T=await this.semaphore.use(()=>this.execute(c,v,{systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,agent:s.agent,mcpServers:d,skills:f,integrations:p,tagPrefix:b,timeoutMs:o,observability:{swarmName:this.config.tag,operationName:s.name,operationId:i,operation:"filter",itemIndex:n,role:"worker",verifyRetry:S&&S>1?S-1:void 0,...this.pipelineContextToObservability(s._pipelineContext)}})),C={operationId:i,operation:"filter",tag:T.tag,sandboxId:T.sandboxId,swarmName:this.config.tag,operationName:s.name,itemIndex:n,verifyRetry:S&&S>1?S-1:void 0,...this.pipelineContextToMeta(s._pipelineContext)};return this.buildResult(T,C,c)};return this.runWithVerification(m,{originalPrompt:r,inputFiles:c,verifyConfig:u,timeoutMs:o,systemPrompt:s.systemPrompt,schema:s.schema,mcpServers:d,skills:f,integrations:p,operationId:i,baseTag:l,retry:a,itemIndex:n,operation:"filter",_pipelineContext:s._pipelineContext})}async executeBestOfCandidate(t){let{inputFiles:r,prompt:n,candidateIndex:i,operationId:s,config:o,timeoutMs:a,parentIndex:c,attempt:l=1,_pipelineContext:u}=t,d=c!==void 0?`${this.config.tag}-map-${c}-bestof-cand-${i}`:`${this.config.tag}-bestof-cand-${i}`,f=l>1?`${d}-er${l-1}`:d,p=await this.semaphore.use(()=>this.execute(r,n,{systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,agent:o.taskAgents?.[i],mcpServers:t.mcpServers,skills:t.skills,integrations:t.integrations,tagPrefix:f,timeoutMs:a,observability:{swarmName:this.config.tag,operationId:s,operation:"map",itemIndex:c,role:"candidate",candidateIndex:i,errorRetry:l>1?l-1:void 0,...this.pipelineContextToObservability(u)}})),m={operationId:s,operation:"bestof-cand",tag:p.tag,sandboxId:p.sandboxId,swarmName:this.config.tag,itemIndex:i,errorRetry:l>1?l-1:void 0,candidateIndex:i,...this.pipelineContextToMeta(u)};return this.buildResult(p,m)}buildJudgeContext(t){let r=this.buildEvaluatorContext({inputFiles:t.inputFiles,taskPrompt:t.taskPrompt,systemPrompt:t.systemPrompt,schema:t.schema});return t.candidates.forEach((n,i)=>{n.status==="error"&&(r[`candidate_${i}/_failed.txt`]=`STATUS: FAILED
|
|
1230
1230
|
|
|
@@ -71,6 +71,8 @@ from .hosted import (
|
|
|
71
71
|
EvolveDigestMismatchError,
|
|
72
72
|
EvolveIncompleteDownloadError,
|
|
73
73
|
ExceptionInfo,
|
|
74
|
+
GateRunningError,
|
|
75
|
+
GateRunningProgress,
|
|
74
76
|
HostedEvolve,
|
|
75
77
|
HOSTED_ERROR_CODES,
|
|
76
78
|
HostedErrorCode,
|
|
@@ -104,6 +106,7 @@ from .hosted import (
|
|
|
104
106
|
StatusVocabulary,
|
|
105
107
|
StopResponse,
|
|
106
108
|
Task,
|
|
109
|
+
TaskGate,
|
|
107
110
|
TaskPage,
|
|
108
111
|
TaskProviderVerdict,
|
|
109
112
|
TimingInfo,
|
|
@@ -389,7 +392,7 @@ async def list_checkpoints(
|
|
|
389
392
|
await store.close()
|
|
390
393
|
|
|
391
394
|
|
|
392
|
-
__version__ = '0.0.52.
|
|
395
|
+
__version__ = '0.0.52.dev760'
|
|
393
396
|
|
|
394
397
|
__all__ = [
|
|
395
398
|
# Main classes
|
|
@@ -468,6 +471,8 @@ __all__ = [
|
|
|
468
471
|
'EvolveDigestMismatchError',
|
|
469
472
|
'EvolveIncompleteDownloadError',
|
|
470
473
|
'NoActiveVersionError',
|
|
474
|
+
'GateRunningError',
|
|
475
|
+
'GateRunningProgress',
|
|
471
476
|
'Dataset',
|
|
472
477
|
'ActiveDataset',
|
|
473
478
|
'DatasetManifestAuthor',
|
|
@@ -482,6 +487,7 @@ __all__ = [
|
|
|
482
487
|
'ImportTaskFailure',
|
|
483
488
|
'ImportWarning',
|
|
484
489
|
'Task',
|
|
490
|
+
'TaskGate',
|
|
485
491
|
'TaskProviderVerdict',
|
|
486
492
|
'AgentArm',
|
|
487
493
|
'AgentDatasetStats',
|
|
@@ -281,6 +281,36 @@ class NoActiveVersionError(Exception):
|
|
|
281
281
|
self.dataset = name
|
|
282
282
|
|
|
283
283
|
|
|
284
|
+
class GateRunningError(Exception):
|
|
285
|
+
"""Raised by ``datasets().activate()`` when the activation gate is still
|
|
286
|
+
scheduled or running — the API's 202 ``gate_running`` answer.
|
|
287
|
+
|
|
288
|
+
NOT an :class:`EvolveAPIError`: the wire body is deliberately not the
|
|
289
|
+
error envelope, because an in-progress gate is a healthy state — nothing
|
|
290
|
+
is wrong and nothing is asked of the caller. Poll the dataset (each
|
|
291
|
+
version carries ``gate``); a gate that PASSES activates the version
|
|
292
|
+
itself, so there is normally nothing left to call. Its own type, like
|
|
293
|
+
:class:`NoActiveVersionError`, because ``activate()`` promised a Dataset
|
|
294
|
+
it cannot return yet.
|
|
295
|
+
|
|
296
|
+
``gate`` is a :class:`GateRunningProgress` — the gate's progress at the
|
|
297
|
+
moment of the call.
|
|
298
|
+
"""
|
|
299
|
+
|
|
300
|
+
def __init__(
|
|
301
|
+
self, dataset: str, version: str, message: str, gate: 'GateRunningProgress'
|
|
302
|
+
):
|
|
303
|
+
super().__init__(message)
|
|
304
|
+
#: The stable machine word for this state.
|
|
305
|
+
self.code = 'gate_running'
|
|
306
|
+
#: The dataset whose version is still being proven.
|
|
307
|
+
self.dataset = dataset
|
|
308
|
+
#: The version the gate is proving.
|
|
309
|
+
self.version = version
|
|
310
|
+
#: Gate progress at the moment of the call.
|
|
311
|
+
self.gate = gate
|
|
312
|
+
|
|
313
|
+
|
|
284
314
|
# =============================================================================
|
|
285
315
|
# PUBLIC TYPES
|
|
286
316
|
# =============================================================================
|
|
@@ -341,13 +371,34 @@ class DatasetVersionGate:
|
|
|
341
371
|
``failed_tasks`` names each ineligible task with the gate's own reasons
|
|
342
372
|
(the server sends the first 25); it is empty while the gate is healthy and
|
|
343
373
|
empty on servers that predate the field — absence is "nothing to report",
|
|
344
|
-
never a crash.
|
|
374
|
+
never a crash. ``failed_task_count`` is the TRUE total of ineligible
|
|
375
|
+
tasks: the list is capped at 25, so a gate that failed more tasks than
|
|
376
|
+
that is under-counted by ``len(failed_tasks)`` — this number never is (it
|
|
377
|
+
falls back to the length on servers that predate the field, which never
|
|
378
|
+
truncated without it).
|
|
345
379
|
"""
|
|
346
380
|
status: str
|
|
347
381
|
attempts: int
|
|
348
382
|
code: Optional[str] = None
|
|
349
383
|
message: Optional[str] = None
|
|
350
384
|
failed_tasks: List[DatasetVersionGateFailedTask] = field(default_factory=list)
|
|
385
|
+
failed_task_count: int = 0
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
@dataclass
|
|
389
|
+
class GateRunningProgress:
|
|
390
|
+
"""Gate progress at the moment of an ``activate()`` call that answered
|
|
391
|
+
202 — carried on :class:`GateRunningError`.
|
|
392
|
+
|
|
393
|
+
``status`` is the gate's own lifecycle (PENDING or RUNNING here),
|
|
394
|
+
``tasks`` the version's task count, ``unverified`` the tasks the gate has
|
|
395
|
+
not yet produced a verdict for, and ``ineligible`` the tasks whose
|
|
396
|
+
verdict so far is not activation-eligible.
|
|
397
|
+
"""
|
|
398
|
+
status: str
|
|
399
|
+
tasks: int = 0
|
|
400
|
+
unverified: int = 0
|
|
401
|
+
ineligible: int = 0
|
|
351
402
|
|
|
352
403
|
|
|
353
404
|
@dataclass
|
|
@@ -407,6 +458,25 @@ class TaskProviderVerdict:
|
|
|
407
458
|
degrades_to: Optional[str] = None
|
|
408
459
|
|
|
409
460
|
|
|
461
|
+
@dataclass
|
|
462
|
+
class TaskGate:
|
|
463
|
+
"""One task's activation-gate verdict — the public subset.
|
|
464
|
+
|
|
465
|
+
The per-task half of the version's ``gate``: while the gate is RUNNING,
|
|
466
|
+
verdicts appear on tasks as they land. ``outcome`` is PASS; FLAKY (gold
|
|
467
|
+
passed only on a retry — still eligible under the operator default); FAIL
|
|
468
|
+
(definitive: gold never scored 1.0, or a do-nothing agent did); or ERROR
|
|
469
|
+
(inconclusive — no usable score, e.g. no archived solution to run).
|
|
470
|
+
``reasons`` are human-readable and empty on PASS. The full stored verdict
|
|
471
|
+
carries oracle diagnostics that stay internal, like the environment specs
|
|
472
|
+
beside it.
|
|
473
|
+
"""
|
|
474
|
+
outcome: str
|
|
475
|
+
flaky: bool = False
|
|
476
|
+
reasons: List[str] = field(default_factory=list)
|
|
477
|
+
ran_at: Optional[str] = None
|
|
478
|
+
|
|
479
|
+
|
|
410
480
|
@dataclass
|
|
411
481
|
class Task:
|
|
412
482
|
"""Public task fields only — instructions/environments/tests never leave the server.
|
|
@@ -419,6 +489,10 @@ class Task:
|
|
|
419
489
|
``gpus``/``gpu_types`` are the task's declared GPU requirement (Harbor's
|
|
420
490
|
task fields honored verbatim): 0 = a CPU task; ``gpu_types`` None = any
|
|
421
491
|
type is acceptable (always None when ``gpus`` is 0).
|
|
492
|
+
|
|
493
|
+
``gate`` is this task's activation-gate verdict — ``None`` until the gate
|
|
494
|
+
has run it, and ``None`` on servers that predate the field: absence is
|
|
495
|
+
"nothing to report", never "passed".
|
|
422
496
|
"""
|
|
423
497
|
task_name: str
|
|
424
498
|
agent_timeout_sec: float
|
|
@@ -426,6 +500,7 @@ class Task:
|
|
|
426
500
|
providers: Dict[str, TaskProviderVerdict]
|
|
427
501
|
gpus: int = 0
|
|
428
502
|
gpu_types: Optional[List[str]] = None
|
|
503
|
+
gate: Optional[TaskGate] = None
|
|
429
504
|
|
|
430
505
|
|
|
431
506
|
@dataclass
|
|
@@ -1739,12 +1814,24 @@ def _map_version_gate(data: Any) -> Optional[DatasetVersionGate]:
|
|
|
1739
1814
|
raw_failed = data.get('failed_tasks')
|
|
1740
1815
|
if not isinstance(raw_failed, list):
|
|
1741
1816
|
raw_failed = failure.get('failed_tasks')
|
|
1817
|
+
failed_tasks = _map_gate_failed_tasks(raw_failed)
|
|
1818
|
+
raw_count = data.get('failed_task_count')
|
|
1819
|
+
if not isinstance(raw_count, int) or isinstance(raw_count, bool):
|
|
1820
|
+
raw_count = failure.get('failed_task_count')
|
|
1742
1821
|
return DatasetVersionGate(
|
|
1743
1822
|
status=data['status'],
|
|
1744
1823
|
attempts=attempts if isinstance(attempts, int) and not isinstance(attempts, bool) else 0,
|
|
1745
1824
|
code=code if isinstance(code, str) else None,
|
|
1746
1825
|
message=message if isinstance(message, str) else None,
|
|
1747
|
-
failed_tasks=
|
|
1826
|
+
failed_tasks=failed_tasks,
|
|
1827
|
+
# The TRUE total behind the 25-task cap on failed_tasks. An older
|
|
1828
|
+
# server never truncated without the count, so absence reads as the
|
|
1829
|
+
# length.
|
|
1830
|
+
failed_task_count=(
|
|
1831
|
+
raw_count
|
|
1832
|
+
if isinstance(raw_count, int) and not isinstance(raw_count, bool)
|
|
1833
|
+
else len(failed_tasks)
|
|
1834
|
+
),
|
|
1748
1835
|
)
|
|
1749
1836
|
|
|
1750
1837
|
|
|
@@ -1833,6 +1920,46 @@ def _map_dataset_summary(data: Dict[str, Any]) -> Dataset:
|
|
|
1833
1920
|
)
|
|
1834
1921
|
|
|
1835
1922
|
|
|
1923
|
+
def _map_gate_running_progress(data: Any) -> GateRunningProgress:
|
|
1924
|
+
"""The 202 body's ``gate`` progress block, defensively.
|
|
1925
|
+
|
|
1926
|
+
A count that is not a number reads as 0 and a missing status as PENDING
|
|
1927
|
+
(scheduled is the least a 202 can mean) — a misbehaving server must never
|
|
1928
|
+
crash the refusal path.
|
|
1929
|
+
"""
|
|
1930
|
+
raw = data if isinstance(data, dict) else {}
|
|
1931
|
+
|
|
1932
|
+
def _count(value: Any) -> int:
|
|
1933
|
+
return value if isinstance(value, int) and not isinstance(value, bool) else 0
|
|
1934
|
+
|
|
1935
|
+
status = raw.get('status')
|
|
1936
|
+
return GateRunningProgress(
|
|
1937
|
+
status=status if isinstance(status, str) else 'PENDING',
|
|
1938
|
+
tasks=_count(raw.get('tasks')),
|
|
1939
|
+
unverified=_count(raw.get('unverified')),
|
|
1940
|
+
ineligible=_count(raw.get('ineligible')),
|
|
1941
|
+
)
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
def _map_task_gate(data: Any) -> Optional[TaskGate]:
|
|
1945
|
+
"""A task's own activation-gate verdict, with the gate mappers' tolerance.
|
|
1946
|
+
|
|
1947
|
+
Absent (the gate has not run it, or an older server) or unreadable input
|
|
1948
|
+
is ``None`` — "nothing to report", never "passed" and never a crash. An
|
|
1949
|
+
entry without an outcome word is no verdict at all.
|
|
1950
|
+
"""
|
|
1951
|
+
if not isinstance(data, dict) or not isinstance(data.get('outcome'), str):
|
|
1952
|
+
return None
|
|
1953
|
+
reasons = data.get('reasons')
|
|
1954
|
+
ran_at = data.get('ran_at')
|
|
1955
|
+
return TaskGate(
|
|
1956
|
+
outcome=data['outcome'],
|
|
1957
|
+
flaky=data.get('flaky') is True,
|
|
1958
|
+
reasons=[r for r in reasons if isinstance(r, str)] if isinstance(reasons, list) else [],
|
|
1959
|
+
ran_at=ran_at if isinstance(ran_at, str) else None,
|
|
1960
|
+
)
|
|
1961
|
+
|
|
1962
|
+
|
|
1836
1963
|
def _map_task(data: Dict[str, Any]) -> Task:
|
|
1837
1964
|
providers_raw = data.get('providers') or {}
|
|
1838
1965
|
gpus_raw = data.get('gpus')
|
|
@@ -1857,6 +1984,9 @@ def _map_task(data: Dict[str, Any]) -> Task:
|
|
|
1857
1984
|
if isinstance(gpu_types_raw, list) and gpu_types_raw
|
|
1858
1985
|
else None
|
|
1859
1986
|
),
|
|
1987
|
+
# The per-task half of the version's gate — verdicts appear here as
|
|
1988
|
+
# they land while the gate runs.
|
|
1989
|
+
gate=_map_task_gate(data.get('gate')),
|
|
1860
1990
|
)
|
|
1861
1991
|
|
|
1862
1992
|
|
|
@@ -2434,6 +2564,25 @@ class _HostedHttp:
|
|
|
2434
2564
|
) -> Dict[str, Any]:
|
|
2435
2565
|
return await asyncio.to_thread(self._request_sync, path, method, body, headers, False)
|
|
2436
2566
|
|
|
2567
|
+
async def request_json_status(
|
|
2568
|
+
self,
|
|
2569
|
+
path: str,
|
|
2570
|
+
method: str = 'GET',
|
|
2571
|
+
body: Optional[Dict[str, Any]] = None,
|
|
2572
|
+
headers: Optional[Dict[str, str]] = None,
|
|
2573
|
+
) -> 'tuple[Dict[str, Any], int]':
|
|
2574
|
+
"""Like :meth:`request_json`, plus the HTTP status code.
|
|
2575
|
+
|
|
2576
|
+
For the one verb whose 2xx statuses mean different bodies — activate
|
|
2577
|
+
answers 200 with the Dataset and 202 with a GateRunning progress
|
|
2578
|
+
report — where parsing every 2xx as the success shape returned a
|
|
2579
|
+
garbage object.
|
|
2580
|
+
"""
|
|
2581
|
+
return await asyncio.to_thread(
|
|
2582
|
+
self._request_sync, path, method, body, headers, False,
|
|
2583
|
+
REQUEST_TIMEOUT_SEC, True,
|
|
2584
|
+
)
|
|
2585
|
+
|
|
2437
2586
|
async def request_bytes(
|
|
2438
2587
|
self, path: str, *, timeout: int = DOWNLOAD_TIMEOUT_SEC
|
|
2439
2588
|
) -> 'tuple[bytes, Dict[str, str]]':
|
|
@@ -2493,6 +2642,7 @@ class _HostedHttp:
|
|
|
2493
2642
|
headers: Optional[Dict[str, str]],
|
|
2494
2643
|
raw: bool,
|
|
2495
2644
|
timeout: int = REQUEST_TIMEOUT_SEC,
|
|
2645
|
+
with_status: bool = False,
|
|
2496
2646
|
):
|
|
2497
2647
|
data = json.dumps(body).encode('utf-8') if body is not None else None
|
|
2498
2648
|
request_headers = {
|
|
@@ -2512,13 +2662,13 @@ class _HostedHttp:
|
|
|
2512
2662
|
try:
|
|
2513
2663
|
with _http.urlopen(request, timeout=timeout) as response:
|
|
2514
2664
|
payload = response.read()
|
|
2665
|
+
status = response.status
|
|
2515
2666
|
if raw:
|
|
2516
2667
|
return payload, dict(response.headers.items())
|
|
2517
2668
|
except urllib.error.HTTPError as exc:
|
|
2518
2669
|
_raise_api_error(exc)
|
|
2519
|
-
if
|
|
2520
|
-
|
|
2521
|
-
return json.loads(payload.decode('utf-8'))
|
|
2670
|
+
parsed = json.loads(payload.decode('utf-8')) if payload else {}
|
|
2671
|
+
return (parsed, status) if with_status else parsed
|
|
2522
2672
|
|
|
2523
2673
|
def _download_sync(self, path: str, to_dir: str, default_filename: str) -> str:
|
|
2524
2674
|
"""Stream a download straight to disk — never buffers the archive in memory."""
|
|
@@ -3216,13 +3366,33 @@ class DatasetsClient:
|
|
|
3216
3366
|
async def activate(self, name: str, version: str) -> Dataset:
|
|
3217
3367
|
"""Make a READY version the dataset's active version.
|
|
3218
3368
|
|
|
3219
|
-
Returns the full detail shape, exactly like :meth:`get`.
|
|
3369
|
+
Returns the full detail shape, exactly like :meth:`get`. While the
|
|
3370
|
+
version's activation gate is still scheduled or running the API
|
|
3371
|
+
answers 202 ``gate_running`` — a healthy in-progress state, raised
|
|
3372
|
+
here as the typed :class:`GateRunningError` (its ``gate`` carries the
|
|
3373
|
+
gate's progress). A gate that passes activates the version itself, so
|
|
3374
|
+
there is normally nothing left to call.
|
|
3220
3375
|
"""
|
|
3221
|
-
raw = await self._http.
|
|
3376
|
+
raw, status = await self._http.request_json_status(
|
|
3222
3377
|
f'/api/datasets/{urllib.parse.quote(name)}'
|
|
3223
3378
|
f'/versions/{urllib.parse.quote(version)}/activate',
|
|
3224
3379
|
method='POST',
|
|
3225
3380
|
)
|
|
3381
|
+
# 202 is "not yet", not "here is the dataset": the body is a
|
|
3382
|
+
# GateRunning progress report — parsing it as a Dataset returned a
|
|
3383
|
+
# garbage object. Typed, like NoActiveVersionError, so a caller can
|
|
3384
|
+
# branch and poll.
|
|
3385
|
+
if status == 202:
|
|
3386
|
+
message = raw.get('message')
|
|
3387
|
+
raise GateRunningError(
|
|
3388
|
+
name,
|
|
3389
|
+
version,
|
|
3390
|
+
message if isinstance(message, str) else (
|
|
3391
|
+
f'Dataset {name!r} version {version!r} is still being '
|
|
3392
|
+
'proven by its activation gate'
|
|
3393
|
+
),
|
|
3394
|
+
_map_gate_running_progress(raw.get('gate')),
|
|
3395
|
+
)
|
|
3226
3396
|
return _map_dataset_detail(raw)
|
|
3227
3397
|
|
|
3228
3398
|
async def update(self, name: str, *, upstream_auto_import: bool) -> Dataset:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{evolve_sdk-0.0.52.dev756 → evolve_sdk-0.0.52.dev760}/evolve_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|