UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.99 kB
import{xt as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{c as t,d as n,f as r,g as i,n as a,s as o}from"./openclaw-state-read-schemas-YhOPoIHM.mjs";import{a as s,i as c}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{r as l}from"./openclaw-state-read-agent-id-DmscQLD6.mjs";import{t as u}from"./openclaw-state-read-github-identity-profile-id-BSDFrs4w.mjs";function resolveConfiguredGitHubHost(e){let t=e?.gateway?.github?.host?.trim().toLowerCase()||`github.com`;if(!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/u.test(t)||t.includes(`..`))throw Error(`gateway.github.host must be a hostname`);return t}const d=/^[A-Za-z0-9_.-]+$/u;function githubPathParts(e){let t=e.split(`/`).filter(Boolean),n=t[0],r=t[1]?.replace(/\.git$/iu,``);return t.length!==2||!n||!r||!d.test(n)||!d.test(r)||n===`.`||n===`..`||r===`.`||r===`..`?null:{owner:n,repo:r}}function parseProjectGitUrl(e,t=resolveConfiguredGitHubHost()){let n=e.trim();if(!n||n.startsWith(`-`)||n.includes(`\0`)||/[\r\n\t ]/u.test(n))return null;let r=`git@${t}:`,i=n.toLowerCase().startsWith(r)?n.slice(r.length):void 0,a;if(i!==void 0)a=githubPathParts(i);else{let e=URL.parse(n);if(!e)return null;let r=e.protocol===`https:`,i=e.protocol===`ssh:`&&e.username===`git`&&(!e.port||e.port===`22`);if(!r&&!i||e.hostname.toLowerCase()!==t||e.password||r&&e.username||e.search||e.hash)return null;a=githubPathParts(e.pathname)}return a?{url:`https://${t}/${a.owner.toLowerCase()}/${a.repo.toLowerCase()}.git`,name:a.repo}:null}const f=i().min(1).max(64).refine(e=>{let t=l(e);return t.ok&&t.value===e}),p=n().int().positive().max(2**53-1),m=o(`source`,[r({source:t(`anonymous`)}).strict(),r({source:t(`system-detected`),accountId:p}).strict(),r({source:a([`system-configured`,`agent-override`]),profileId:i().regex(u),accountId:p}).strict()]),h=r({agentId:f,provenance:r({agentId:f,createdVia:a([`operator`,`agent`,`template`]),creatorAgentId:f.nullable(),createdAtMs:n().int().nonnegative().max(2**53-1)}).strict().nullable()}).strict().refine(e=>e.provenance===null||e.provenance.agentId===e.agentId),g=r({key:i().regex(/^[a-f0-9]{64}$/u),baseCommit:i().regex(/^[a-f0-9]{40}$/u),source:r({kind:t(`repository`),url:i().max(2048),repositoryId:i().min(1).max(256).regex(/^[A-Za-z0-9_+/=-]+$/u),owner:r({agent:h,identity:m}).strict()}).strict()});function readRepositoryWorkerProjectSnapshot(t){if(!e(t)||t.source===void 0)return;let n=g.safeParse(t),r=n.success?n.data.source:void 0,i=r&&URL.canParse(r.url)?new URL(r.url).hostname.toLowerCase():void 0;if(Object.keys(t).some(e=>![`key`,`baseCommit`,`source`,`preparation`].includes(e))||!n.success||!i||parseProjectGitUrl(n.data.source.url,i)?.url!==n.data.source.url)throw Error(`Worker environment has an invalid repository preparation snapshot`);return n.data}function parsePresenceDemand(t){if(!e(t))throw Error(`Prepared-pool presence demand is invalid`);let n=t,r=n.revision,i=n.profileId,a=n.requestedRef,o=n.preparationKey,s=n.lastPresentAtMs,c=n.retireAtMs,l;try{l=readRepositoryWorkerProjectSnapshot(n.project)}catch{throw Error(`Prepared-pool presence demand is invalid`)}if(typeof r!=`number`||!Number.isSafeInteger(r)||r<1||typeof i!=`string`||!/^[A-Za-z0-9_-]{1,128}$/u.test(i)||a!==null&&(typeof a!=`string`||!a||a.length>1024)||typeof o!=`string`||!/^[a-f0-9]{64}$/u.test(o)||!l||typeof s!=`number`||!Number.isSafeInteger(s)||s<0||c!==null&&(typeof c!=`number`||!Number.isSafeInteger(c)||c<s))throw Error(`Prepared-pool presence demand is invalid`);return{revision:r,profileId:i,requestedRef:a,preparationKey:o,project:l,lastPresentAtMs:s,retireAtMs:c}}function readPreparedPoolPresenceDemandInDatabase(e){let t=c(e,s(e).selectFrom(`config_machine_state`).select(`value_json`).where(`state_key`,`=`,`cloudWorkers.preparedPool.humanPresenceDemand`));if(t){if(t.value_json.length>32768)throw Error(`Prepared-pool presence demand exceeds its record budget`);return parsePresenceDemand(JSON.parse(t.value_json))}}export{readPreparedPoolPresenceDemandInDatabase};