UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.01 kB
import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import"./agent-scope-config-CG9CFpGX.mjs";import{a as resolveUpdateRehearsalRoot}from"./update-rehearsal-paths-C4qLj9oD.mjs";import{i as UPDATE_POST_INSTALL_DOCTOR_RESULT_PATH_ENV}from"./update-doctor-result-B09W3zwf.mjs";import{f as isUpdateDoctorLintPass}from"./update-phase-CCaxuca0.mjs"; //!src/flows/doctor-update-budget.ts const PUBLISHED_VALIDATION_WORK_MS=298e3;const COMMAND_VALIDATION_WORK_MS=288e3;const INSPECTION_WINDOW_MS=PUBLISHED_VALIDATION_WORK_MS/2;const AGENT_INSPECTION_ALLOWANCE_MS=2e3;const RUN_INSPECTION_ALLOWANCE_MS=5e3;function resolveCommandStartedAt(e,t){const n=e??Math.floor(performance.timeOrigin);return Math.min(Math.max(n,t),Date.now())}async function resolveDoctorUpdateBudget(e){const t=resolveUpdateRehearsalRoot(e.env);const n=isUpdateDoctorLintPass(e.env)&&Boolean(e.env[`OPENCLAW_UPDATE_POST_INSTALL_DOCTOR_RESULT_PATH`]?.trim());if(!t&&!n)return;const{listUpdateRunsAsync:r}=await import(`./update-run-reader-tNF5l9at.mjs`);let i;let a=false;try{const t=await r({active:true,limit:2},{env:e.env});const n=t.length===1?t[0]:void 0;i=n?.steps.find(e=>e.step===`validating`&&e.startedAtMs!==void 0)?.startedAtMs;a=Boolean(n?.steps.some(e=>e.step===`candidate-state-snapshot`&&e.status===`in_progress`))}catch{}if(!t&&i===void 0)return;const o=Math.max(listAgentIds(e.cfg).length,e.preparedAgentCount??0);const s=/* @__PURE__ */ new Map;if(!t)return{agentCount:o,phase:`activation`,inspectionDeadlineMs:Date.now()+INSPECTION_WINDOW_MS,source:`activation-policy`,deferred:s};if(i===void 0)return{agentCount:o,phase:`validation`,inspectionDeadlineMs:Date.now(),source:`unavailable-validation-origin`,deferred:s};if(a){const t=resolveCommandStartedAt(e.commandStartedAtMs,i);return{agentCount:o,phase:`validation`,commandStartedAtMs:t,disposalDeadlineMs:t+COMMAND_VALIDATION_WORK_MS,inspectionDeadlineMs:t+COMMAND_VALIDATION_WORK_MS/2,source:`validation-command`,deferred:s}}return{agentCount:o,phase:`validation`,disposalDeadlineMs:i+PUBLISHED_VALIDATION_WORK_MS,inspectionDeadlineMs:i+INSPECTION_WINDOW_MS,source:`validation-ledger`,deferred:s}}function admitDoctorUpdateInspection(e,t,n){if(!e)return true;const r=t===`agent`?Math.max(1,e.agentCount)*AGENT_INSPECTION_ALLOWANCE_MS:RUN_INSPECTION_ALLOWANCE_MS;if(Date.now()+r<=e.inspectionDeadlineMs&&n.every(t=>!e.deferred.has(t.id)))return true;for(const t of n){if(e.deferred.has(t.id))continue;e.deferred.set(t.id,{checkId:t.id,source:`doctor`,severity:`warning`,errorCode:`update-inspection-deferred`,requirement:`update-validation-budget`,message:`${t.label} deferred until after activation: ${e.agentCount} agent scopes need a ${r}ms inspection allowance, with ${Math.max(0,e.inspectionDeadlineMs-Date.now())}ms remaining in the ${e.phase} inspection window (${e.source}).`,fixHint:"Run `openclaw doctor --fix` after activation to complete deferred checks and repairs."})}return false}export{resolveDoctorUpdateBudget as n,admitDoctorUpdateInspection as t};