evolve-sdk 0.0.52.dev638__py3-none-any.whl → 0.0.52.dev656__py3-none-any.whl

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.
@@ -1233,7 +1233,7 @@ PY`,{timeoutMs:1e4})).exitCode!==0)throw new Error("Managed secret egress proxy
1233
1233
  `);d=P.pop()??"";for(let L of P){if(!L.trim())continue;let z=f(L);if(this.captureDroidSession(L,z),this.sessionLogger?.writeEventParsed(L,z),t?.onStdout?.(L+`
1234
1234
  `),z&&t?.onContent)for(let j of z)t.onContent(j)}},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+`
1235
1235
  `),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 e8t(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=K3,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 cvn(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(`
1236
- `).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 e8t(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=g8t(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||aa,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 hvn(e){return(e||process.env.EVOLVE_DASHBOARD_URL||aa).replace(/\/$/,"")}function mvn(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 gvn(e){return await e.text().catch(()=>"")}async function b8t(e,t,r={}){let n=await fetch(`${hvn(e?.dashboardUrl)}${t}`,{...r,headers:{Authorization:`Bearer ${mvn(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 gvn(n)}`);return n.status===204?{}:await n.json()}var yvn=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 b8t(this.config,"/api/browser-profiles")).profiles.map(e=>this.toMetadata(e))}}async delete(e){return await b8t(this.config,"/api/browser-profiles",{method:"DELETE",body:JSON.stringify(e)})}};function vvn(e={}){return new yvn(e)}var Lw=class extends I8t.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&&(U8t(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&&(dK(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=Qyn;static browserCredentials=R0n;static browserProfiles=vvn;static managedSecrets=J0n;async initializeAgent(){let e=WJt(this.config.agent),t=rR(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=tvn(this.config.managedSecrets,t);if(r&&this.config.sandbox&&!L8t(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 vxe(e.apiKey):await vyn()),i={},s,o,a=this.config.skills,c;if(this.config.browser){let d=_0n(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=Rxe(e.apiKey)}if((d.provider==="actionbook"||d.provider==="agent-browser")&&(a=I0n(d.provider,a),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"?Uyn:Fyn,o={provider:d.provider,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||aa,...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?V8t(this.config.storage,!e.isDirectMode,aa,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||aa}: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||aa,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||aa}:void 0,providerRouting:e.isDirectMode?void 0:{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||aa},storage:l};this.agent=new pvn(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}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=WJt(this.config.agent);if(!e.isDirectMode)return this._cachedGatewayOverrides={gatewayUrl:aa,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 o8t(this.config.storage,this.resolveGatewayOverrides()||{}).listCheckpoints(e)}storage(){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return o8t(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)}},bvn=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++}},D3=Symbol.for("evolve.SwarmResult"),S8t=class c5t 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 c5t;return r.push(...t),r}},Ejn=class aK{config;semaphore;constructor(t={}){let r=t.concurrency??Dxe;if(r>vK)throw new Error(`concurrency=${r} exceeds max ${vK}. 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??K3,workspaceMode:t.workspaceMode??"knowledge",retry:t.retry,mcpServers:t.mcpServers,skills:t.skills,integrations:t.integrations},this.semaphore=new bvn(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?q0(f=>this.executeMapItem(u,n,d,a,t,c,f),o,d):this.executeMapItem(u,n,d,a,t,c)));return S8t.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?q0(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 S8t.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,L)=>{c.push(this.getFiles(P)),l.push(this.getIndex(P,L))});let u={};c.forEach((P,L)=>{Object.entries(P).forEach(([z,j])=>{u[`item_${l[L]}/${z}`]=j})});let d=sxe(u),f=Fw(Gyn,{fileTree:d}),p=t.systemPrompt?`${f}
1236
+ `).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 e8t(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=g8t(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||aa,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 hvn(e){return(e||process.env.EVOLVE_DASHBOARD_URL||aa).replace(/\/$/,"")}function mvn(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 gvn(e){return await e.text().catch(()=>"")}async function b8t(e,t,r={}){let n=await fetch(`${hvn(e?.dashboardUrl)}${t}`,{...r,headers:{Authorization:`Bearer ${mvn(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 gvn(n)}`);return n.status===204?{}:await n.json()}var yvn=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 b8t(this.config,"/api/browser-profiles")).profiles.map(e=>this.toMetadata(e))}}async delete(e){return await b8t(this.config,"/api/browser-profiles",{method:"DELETE",body:JSON.stringify(e)})}};function vvn(e={}){return new yvn(e)}var Lw=class extends I8t.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&&(U8t(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&&(dK(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=Qyn;static browserCredentials=R0n;static browserProfiles=vvn;static managedSecrets=J0n;async initializeAgent(){let e=WJt(this.config.agent),t=rR(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=tvn(this.config.managedSecrets,t);if(r&&this.config.sandbox&&!L8t(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 vxe(e.apiKey):await vyn()),i={},s,o,a=this.config.skills,c;if(this.config.browser){let d=_0n(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=Rxe(e.apiKey)}if((d.provider==="actionbook"||d.provider==="agent-browser")&&(a=I0n(d.provider,a),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"?Uyn:Fyn,o={provider:d.provider,apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||aa,...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?V8t(this.config.storage,!e.isDirectMode,aa,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||aa}: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||aa,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||aa}:void 0,providerRouting:e.isDirectMode?void 0:{apiKey:e.apiKey,dashboardUrl:process.env.EVOLVE_DASHBOARD_URL||aa},storage:l};this.agent=new pvn(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}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=WJt(this.config.agent);if(!e.isDirectMode)return this._cachedGatewayOverrides={gatewayUrl:aa,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 o8t(this.config.storage,this.resolveGatewayOverrides()||{}).listCheckpoints(e)}storage(){if(this.config.storage===void 0)throw new Error("Storage not configured. Call .withStorage().");return o8t(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)}},bvn=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++}},D3=Symbol.for("evolve.SwarmResult"),S8t=class c5t 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 c5t;return r.push(...t),r}},Ajn=class aK{config;semaphore;constructor(t={}){let r=t.concurrency??Dxe;if(r>vK)throw new Error(`concurrency=${r} exceeds max ${vK}. 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??K3,workspaceMode:t.workspaceMode??"knowledge",retry:t.retry,mcpServers:t.mcpServers,skills:t.skills,integrations:t.integrations},this.semaphore=new bvn(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?q0(f=>this.executeMapItem(u,n,d,a,t,c,f),o,d):this.executeMapItem(u,n,d,a,t,c)));return S8t.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?q0(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 S8t.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,L)=>{c.push(this.getFiles(P)),l.push(this.getIndex(P,L))});let u={};c.forEach((P,L)=>{Object.entries(P).forEach(([z,j])=>{u[`item_${l[L]}/${z}`]=j})});let d=sxe(u),f=Fw(Gyn,{fileTree:d}),p=t.systemPrompt?`${f}
1237
1237
 
1238
1238
  ${t.systemPrompt}`:f,m=(P,L,z)=>({operationId:o,operation:"reduce",tag:P.tag,sandboxId:P.sandboxId,swarmName:this.config.tag,operationName:t.name,inputCount:r.length,inputIndices:l,errorRetry:L,verifyRetry:z,...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,L,z,j)=>{let U=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:L,timeoutMs:a,observability:{swarmName:this.config.tag,operationName:t.name,operationId:o,operation:"reduce",role:"worker",errorRetry:z,verifyRetry:j&&j>1?j-1:void 0,...this.pipelineContextToObservability(t._pipelineContext)}})),X=m(U,z,j&&j>1?j-1:void 0);return U.error?{status:"error",data:null,files:U.files,meta:X,error:U.error,rawData:U.rawData}:{status:"success",data:U.data,files:U.files,meta:X}},C=`${this.config.tag}-reduce`;return i?this.runWithVerification((P,L,z)=>T(P,L,void 0,z),{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?q0(P=>{let L=P>1?P-1:void 0,z=L?`${C}-er${L}`:C;return T(n,z,L)},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(L,z)=>{let j=s?await q0(U=>this.executeBestOfCandidate({inputFiles:l,prompt:n,candidateIndex:z,operationId:a,config:i,systemPrompt:t.systemPrompt,schema:t.schema,schemaOptions:t.schemaOptions,mcpServers:u,skills:f,integrations:m,timeoutMs:c,attempt:U}),s,z):await this.executeBestOfCandidate({inputFiles:l,prompt:n,candidateIndex:z,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,z,j.status==="success"?"success":"error"),j})),S=s?await q0(L=>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:L}),{...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(L=>L.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 Lw().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,L=d.judgeIntegrations??d.integrations??C,z=await Promise.all(Array.from({length:f},async(We,de)=>{let O=a?await q0($=>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})),j=a?await q0(We=>this.executeBestOfJudge({inputFiles:c,taskPrompt:u,candidates:z,config:d,timeoutMs:o,operationId:i,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:v,skills:T,integrations:L,parentIndex:n,attempt:We,_pipelineContext:s._pipelineContext}),{...a,retryOn:void 0},0):await this.executeBestOfJudge({inputFiles:c,taskPrompt:u,candidates:z,config:d,timeoutMs:o,operationId:i,systemPrompt:s.systemPrompt,schema:s.schema,schemaOptions:s.schemaOptions,mcpServers:v,skills:T,integrations:L,parentIndex:n,_pipelineContext:s._pipelineContext}),U=z.findIndex(We=>We.status==="success"),X=j.decision?.winner??(U>=0?U:0),pe=z[X]??z[0];d.onJudgeComplete?.(n,X,j.decision?.reasoning??"Judge failed to provide reasoning");let V={operationId:i,operation:"bestof-judge",tag:j.tag,sandboxId:j.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:j.decision?.reasoning??"Judge failed to provide reasoning",judgeMeta:V,candidates:z}}}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
1239
1239
 
evolve/__init__.py CHANGED
@@ -33,60 +33,76 @@ from .config import (
33
33
  HostedClientConfig,
34
34
  )
35
35
  from .hosted import (
36
- ActiveBenchmark,
37
- Benchmark,
38
- BenchmarkImport,
39
- ImportFailure,
40
- BenchmarkImportFailure,
41
- BenchmarkImportPage,
42
- BenchmarkVersion,
43
- BenchmarksClient,
36
+ ActiveDataset,
37
+ Agent,
38
+ AgentArm,
39
+ AgentCapability,
40
+ AgentInfo,
41
+ AgentPage,
42
+ AgentResult,
43
+ AgentsClient,
44
+ ApiKey,
45
+ AttemptPhase,
46
+ AuthClient,
47
+ AuthStatus,
44
48
  CapabilityDocument,
45
- HarnessCapability,
46
- HarnessModel,
47
- HostedEvolve,
48
- HOSTED_ERROR_CODES,
49
- HostedErrorCode,
50
- ProviderCapability,
51
- StatusVocabulary,
52
- UpstreamStatus,
53
- is_hosted_error_code,
54
- meta,
55
- ComparisonAggregate,
56
- ComparisonCell,
57
- ComparisonCoverage,
58
- ComparisonTaskRow,
59
- CustomHarness,
60
- CustomHarnessesClient,
49
+ CompareCell,
50
+ CompareCoverage,
51
+ CompareJobAggregate,
52
+ CompareResponse,
53
+ CompareTaskRow,
54
+ Dataset,
55
+ DatasetImport,
56
+ DatasetImportFailure,
57
+ DatasetImportPage,
58
+ DatasetPage,
59
+ DatasetRef,
60
+ DatasetSelector,
61
+ DatasetVersion,
62
+ DatasetsClient,
63
+ EvalSandboxProvider,
61
64
  EvolveAPIError,
62
65
  EvolveDigestMismatchError,
63
66
  EvolveIncompleteDownloadError,
64
- BenchmarkPage,
65
- CustomHarnessPage,
67
+ ExceptionInfo,
68
+ HostedEvolve,
69
+ HOSTED_ERROR_CODES,
70
+ HostedErrorCode,
71
+ ImportTaskFailure,
72
+ ImportWarning,
66
73
  Job,
67
- JobAgent,
68
- JobComparison,
69
74
  JobCounts,
70
75
  JobEvent,
71
76
  JobFailure,
72
77
  JobPage,
78
+ JobStatus,
79
+ JobTaskRollup,
80
+ JobTaskRollupPage,
73
81
  JobsClient,
74
- ModelUsage,
82
+ ModelInfo,
75
83
  NoActiveVersionError,
76
- RegradeFilter,
77
- RegradeJob,
78
- RegradePage,
79
- RegradeResultsPage,
80
- RegradeResult,
84
+ ManagedProviderCapability,
85
+ ProviderCapability,
86
+ SourceJob,
87
+ SpendSource,
88
+ StatusVocabulary,
89
+ StopResponse,
81
90
  Task,
82
91
  TaskPage,
83
92
  TaskProviderVerdict,
93
+ TimingInfo,
94
+ TraceEvent,
95
+ TraceEventPage,
84
96
  Trial,
85
- TrialDetail,
86
97
  TrialPage,
98
+ TrialStatus,
87
99
  TrialTally,
88
- TrialTraceEvent,
89
- TrialTracePage,
100
+ TrialsClient,
101
+ UpstreamStatus,
102
+ VerifierEnvironmentMode,
103
+ VerifierResult,
104
+ is_hosted_error_code,
105
+ meta,
90
106
  )
91
107
  from .results import (
92
108
  AgentResponse,
@@ -235,22 +251,22 @@ def browser_profiles(config: Optional[BrowserProfilesClientConfig] = None) -> Br
235
251
  return BrowserProfilesClient(config or BrowserProfilesClientConfig())
236
252
 
237
253
 
238
- def benchmarks(config: Optional[HostedClientConfig] = None) -> BenchmarksClient:
239
- """Create a standalone hosted-evals benchmarks client (shared catalog).
254
+ def datasets(config: Optional[HostedClientConfig] = None) -> DatasetsClient:
255
+ """Create a standalone hosted-evals datasets client (shared catalog).
240
256
 
241
257
  Uses EVOLVE_API_KEY unless HostedClientConfig(api_key=...) is provided.
242
258
  """
243
- return BenchmarksClient(config)
259
+ return DatasetsClient(config)
244
260
 
245
261
 
246
- def custom_harnesses(config: Optional[HostedClientConfig] = None) -> CustomHarnessesClient:
247
- """Create a standalone hosted-evals custom harnesses client.
262
+ def agents(config: Optional[HostedClientConfig] = None) -> AgentsClient:
263
+ """Create a standalone hosted-evals registered-agents client.
248
264
 
249
- Register a private harness once, then name it in agents[].harness
265
+ Register a private agent once, then name it in job agents[].name
250
266
  exactly like a built-in. Uses EVOLVE_API_KEY unless
251
267
  HostedClientConfig(api_key=...) is provided.
252
268
  """
253
- return CustomHarnessesClient(config)
269
+ return AgentsClient(config)
254
270
 
255
271
 
256
272
  def hosted(config: Optional[HostedClientConfig] = None) -> HostedEvolve:
@@ -261,14 +277,14 @@ def hosted(config: Optional[HostedClientConfig] = None) -> HostedEvolve:
261
277
  shift key apart that do completely different things is a trap. ``hosted()``
262
278
  says which half of the SDK you are reaching for.
263
279
 
264
- The three clients underneath are built lazily, so ``await hosted().meta()``
280
+ The four clients underneath are built lazily, so ``await hosted().meta()``
265
281
  works with no API key configured::
266
282
 
267
283
  from evolve import hosted
268
284
 
269
285
  client = hosted()
270
- doc = await client.meta() # public, no key needed
271
- job = await client.jobs.run(...) # needs EVOLVE_API_KEY
286
+ doc = await client.meta() # public, no key needed
287
+ job = await client.jobs.start(...) # needs EVOLVE_API_KEY
272
288
  """
273
289
  return HostedEvolve(config)
274
290
 
@@ -283,6 +299,25 @@ def jobs(config: Optional[HostedClientConfig] = None) -> JobsClient:
283
299
  return JobsClient(config)
284
300
 
285
301
 
302
+ def trials(config: Optional[HostedClientConfig] = None) -> TrialsClient:
303
+ """Create a standalone hosted-evals trials client.
304
+
305
+ A trial id is globally addressable — no method takes a job id. Uses
306
+ EVOLVE_API_KEY unless HostedClientConfig(api_key=...) is provided.
307
+ """
308
+ return TrialsClient(config)
309
+
310
+
311
+ def auth(config: Optional[HostedClientConfig] = None) -> AuthClient:
312
+ """Create a standalone hosted-evals auth client (caller identity).
313
+
314
+ Wave-gated: until the server's wave lands, status() reports the route's
315
+ not-found as the API error it is. Uses EVOLVE_API_KEY unless
316
+ HostedClientConfig(api_key=...) is provided.
317
+ """
318
+ return AuthClient(config)
319
+
320
+
286
321
  def managed_secrets(config: Optional[ManagedSecretsClientConfig] = None) -> ManagedSecretsClient:
287
322
  """Create a standalone managed secrets client.
288
323
 
@@ -326,7 +361,7 @@ async def list_checkpoints(
326
361
  await store.close()
327
362
 
328
363
 
329
- __version__ = '0.0.52.dev638'
364
+ __version__ = '0.0.52.dev656'
330
365
 
331
366
  __all__ = [
332
367
  # Main classes
@@ -393,60 +428,78 @@ __all__ = [
393
428
  'browser_profiles',
394
429
  'managed_secrets',
395
430
 
396
- # Hosted evals (benchmarks + custom harnesses + jobs)
431
+ # Hosted evals (datasets + agents + jobs + trials + auth)
397
432
  'HostedClientConfig',
398
- 'BenchmarksClient',
399
- 'CustomHarnessesClient',
433
+ 'DatasetsClient',
434
+ 'AgentsClient',
400
435
  'JobsClient',
436
+ 'TrialsClient',
437
+ 'AuthClient',
401
438
  'EvolveAPIError',
402
439
  'EvolveDigestMismatchError',
403
440
  'EvolveIncompleteDownloadError',
404
441
  'NoActiveVersionError',
405
- 'Benchmark',
406
- 'ActiveBenchmark',
407
- 'BenchmarkImport',
408
- 'ImportFailure',
409
- 'BenchmarkImportFailure',
410
- 'BenchmarkVersion',
442
+ 'Dataset',
443
+ 'ActiveDataset',
444
+ 'DatasetVersion',
445
+ 'DatasetRef',
446
+ 'DatasetSelector',
447
+ 'DatasetImport',
448
+ 'DatasetImportFailure',
449
+ 'ImportTaskFailure',
450
+ 'ImportWarning',
411
451
  'Task',
412
452
  'TaskProviderVerdict',
413
- 'JobAgent',
453
+ 'AgentArm',
414
454
  'Job',
415
455
  'JobCounts',
416
456
  'JobFailure',
457
+ 'JobStatus',
458
+ 'TrialStatus',
459
+ 'EvalSandboxProvider',
460
+ 'SpendSource',
461
+ 'VerifierEnvironmentMode',
462
+ 'AttemptPhase',
463
+ 'JobTaskRollup',
464
+ 'SourceJob',
417
465
  'TrialTally',
418
466
  'JobEvent',
419
- 'JobComparison',
420
- 'ComparisonAggregate',
421
- 'ComparisonCell',
422
- 'ComparisonCoverage',
423
- 'ComparisonTaskRow',
424
- 'RegradeJob',
425
- 'RegradeResult',
426
- 'RegradeFilter',
427
- 'RegradeResultsPage',
428
- 'ModelUsage',
429
- 'RegradePage',
467
+ 'CompareResponse',
468
+ 'CompareJobAggregate',
469
+ 'CompareCell',
470
+ 'CompareCoverage',
471
+ 'CompareTaskRow',
430
472
  'Trial',
431
- 'TrialDetail',
432
- 'TrialTraceEvent',
433
- 'TrialTracePage',
473
+ 'TimingInfo',
474
+ 'ModelInfo',
475
+ 'AgentInfo',
476
+ 'AgentResult',
477
+ 'VerifierResult',
478
+ 'ExceptionInfo',
479
+ 'StopResponse',
480
+ 'TraceEvent',
481
+ 'TraceEventPage',
434
482
  'JobPage',
435
483
  'TrialPage',
436
- 'BenchmarkPage',
437
- 'CustomHarnessPage',
484
+ 'JobTaskRollupPage',
485
+ 'DatasetPage',
486
+ 'AgentPage',
438
487
  'TaskPage',
439
- 'CustomHarness',
440
- 'BenchmarkImportPage',
441
- 'benchmarks',
442
- 'custom_harnesses',
488
+ 'Agent',
489
+ 'DatasetImportPage',
490
+ 'ApiKey',
491
+ 'AuthStatus',
492
+ 'datasets',
493
+ 'agents',
443
494
  'jobs',
495
+ 'trials',
496
+ 'auth',
444
497
  'hosted',
445
498
  'meta',
446
499
  'HostedEvolve',
447
500
  'CapabilityDocument',
448
- 'HarnessCapability',
449
- 'HarnessModel',
501
+ 'AgentCapability',
502
+ 'ManagedProviderCapability',
450
503
  'ProviderCapability',
451
504
  'StatusVocabulary',
452
505
  'UpstreamStatus',
evolve/config.py CHANGED
@@ -82,7 +82,7 @@ class BrowserCredentialsConfig:
82
82
 
83
83
  @dataclass
84
84
  class HostedClientConfig:
85
- """Standalone hosted evals client configuration (benchmarks/jobs).
85
+ """Standalone hosted evals client configuration (datasets/jobs).
86
86
 
87
87
  Args:
88
88
  api_key: Evolve API key override (default: EVOLVE_API_KEY)