UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

52 lines (51 loc) • 1.71 kB
export const RETRYABLE_REMOTE_ERROR_CODES = [ "auth_transient", "connect_failed", "timeout", "liveness_no_output", "transport_lost", ]; export function isRetryableRemoteErrorCode(code) { return RETRYABLE_REMOTE_ERROR_CODES.includes(code); } export class RemoteExecutionError extends Error { code; constructor(code, message, cause) { super(message, cause === undefined ? undefined : { cause }); this.name = "RemoteExecutionError"; this.code = code; } } export function hasDestroy(env) { return typeof env.destroy === "function"; } export function isRemoteExecutionEnv(env) { const e = env; return (typeof e.workspaceHandle === "function" && typeof e.execStream === "function" && typeof e.suspendVM === "function" && typeof e.destroy === "function" && typeof e.capabilities === "object" && e.capabilities !== null); } export function missingRestoreSurface(env) { const e = env; const missing = []; if (typeof e.resumeVM !== "function") missing.push("resumeVM"); if (typeof e.postResumeInit !== "function") missing.push("postResumeInit"); return missing; } export function isSuspendable(env) { return isRemoteExecutionEnv(env) && env.capabilities.suspendable === true && missingRestoreSurface(env).length === 0; } export function isIsolated(env) { return isRemoteExecutionEnv(env) ? env.capabilities.isolation === true : false; } export function boundaryIsTheSandbox(env) { return isIsolated(env); } export function canonicalPathIsAuthoritative(env) { return isRemoteExecutionEnv(env) ? env.capabilities.canonicalPathAuthoritative === true : false; }