openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.47 kB
JavaScript
import{n as e}from"./openclaw-state-read-rolldown-runtime-C7TU3oOp.mjs";import{xt as t}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{n,t as r}from"./openclaw-state-read-json-coercion-CAL-_nfN.mjs";import{a as i,r as a}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{o}from"./openclaw-state-read-openclaw-state-db-schema-helpers-QFZd8aJI.mjs";import{a as s}from"./openclaw-state-read-sqlite-transaction-Bt-IwVhZ.mjs";var c=/* @__PURE__ */ e({findLiveRegistryWorktreeByOwnerInDatabase:()=>findLiveRegistryWorktreeByOwnerInDatabase,getRegistryWorktreeInDatabase:()=>getRegistryWorktreeInDatabase,listRegistryWorktreesInDatabase:()=>listRegistryWorktreesInDatabase,rowToRecord:()=>rowToRecord,worktreeGcRevision:()=>worktreeGcRevision,worktreeReadOperations:()=>u});const l=[`id`,`repo_fingerprint`,`repo_root`,`path`,`branch`,`base_ref`,`owner_kind`,`owner_id`,`snapshot_ref`,`created_at`,`last_active_at`,`removed_at`,`run_end_cleanup_json`,`gc_protection_json`];function parseRunEndCleanup(e){let t=n(e??``);if(!t||typeof t.at!=`number`||!Number.isInteger(t.at)||t.at<0)return;let r=t.at;switch(t.outcome){case`failed`:return typeof t.reason==`string`&&t.reason.length>0&&t.reason.length<=500?{outcome:t.outcome,at:r,reason:t.reason}:void 0;case`removed-lossless`:case`retained-busy`:case`retained-dirty`:case`retained-unpushed`:case`retained-provisioned-drift`:return t.reason===void 0?{outcome:t.outcome,at:r}:void 0;default:return}}function rowToRecord(e){let r=parseRunEndCleanup(e.run_end_cleanup_json),i={id:e.id,name:e.path.split(/[\\/]/).at(-1)??e.id,repoFingerprint:e.repo_fingerprint,repoRoot:e.repo_root,path:e.path,branch:e.branch,baseRef:e.base_ref,ownerKind:e.owner_kind,...e.owner_id?{ownerId:e.owner_id}:{},...e.snapshot_ref?{snapshotRef:e.snapshot_ref}:{},createdAt:e.created_at,lastActiveAt:e.last_active_at,...e.removed_at==null?{}:{removedAt:e.removed_at},...r?{runEndCleanup:r}:{}},a=n(e.gc_protection_json??``);if(a&&a.revision===worktreeGcRevision(i)&&typeof a.reason==`string`){i.gcProtection=a.reason;let e=a.retry;t(e)&&typeof e.stage==`string`&&typeof e.elapsedMs==`number`&&Number.isSafeInteger(e.elapsedMs)&&e.elapsedMs>=0&&typeof e.attempts==`number`&&Number.isSafeInteger(e.attempts)&&e.attempts>0&&typeof e.retryAt==`number`&&Number.isSafeInteger(e.retryAt)&&e.retryAt>=0&&(i.gcRetry={stage:e.stage,elapsedMs:e.elapsedMs,attempts:e.attempts,retryAt:e.retryAt})}return i}function worktreeGcRevision(e){return JSON.stringify([e.path,e.repoRoot,e.repoFingerprint,e.branch,e.baseRef,e.createdAt,e.ownerKind,e.ownerId,e.lastActiveAt,e.removedAt,e.snapshotRef,e.runEndCleanup])}function getRegistryWorktreeInDatabase(e,t){let n=i(e).selectFrom(`worktrees`).select(l).where(`id`,`=`,t),r=a(e,n).rows[0];return r?rowToRecord(r):void 0}function findLiveRegistryWorktreeByOwnerInDatabase(e,t,n){let r=i(e).selectFrom(`worktrees`).select(l).where(`owner_kind`,`=`,t).where(`owner_id`,`=`,n).where(`removed_at`,`is`,null).orderBy(`created_at`,`desc`).limit(1),o=a(e,r).rows[0];return o?rowToRecord(o):void 0}function findLiveRegistryWorktreeByPathInDatabase(e,t){let n=a(e,i(e).selectFrom(`worktrees`).select(l).where(`path`,`=`,t).where(`removed_at`,`is`,null).orderBy(`created_at`,`desc`).limit(1)).rows[0];return n?rowToRecord(n):void 0}function listRegistryWorktreesInDatabase(e,t={}){let n=i(e).selectFrom(`worktrees`).select(l).orderBy(`created_at`,`desc`).orderBy(`id`,`asc`);return t.liveOnly&&(n=n.where(`removed_at`,`is`,null)),a(e,n).rows.map(rowToRecord)}function listLiveRegistryWorktreeIdsInDatabase(e){let t=i(e).selectFrom(`worktrees`).select(`id`).where(`removed_at`,`is`,null);return a(e,t).rows.map(e=>e.id)}function listExistingLiveWorktreePathsInDatabase(e){if(!o(e,`worktrees`))return[];let t=i(e).selectFrom(`worktrees`).select(`path`).where(`removed_at`,`is`,null).orderBy(`path`);return a(e,t).rows.map(e=>e.path)}function isProvisionedFileState(e){return t(e)&&typeof e.path==`string`&&(e.mode===null||typeof e.mode==`number`&&Number.isInteger(e.mode)&&e.mode>=0&&e.mode<=4095)&&typeof e.chunks==`number`&&Number.isInteger(e.chunks)&&e.chunks>=0}function parseProvisionedData(e){let t=r(e??``);if(Array.isArray(t))return t.every(e=>typeof e==`string`||isProvisionedFileState(e))?t:void 0}function readProvisionedData(e,t){let n=i(e).selectFrom(`worktrees`).select(`provisioned_paths_json`).where(`id`,`=`,t),r=a(e,n).rows[0];return parseProvisionedData(r?.provisioned_paths_json??null)}function getRegistryWorktreeProvisionedPathsInDatabase(e,t){return readProvisionedData(e,t)?.map(e=>typeof e==`string`?e:e.path)}function getRegistryWorktreeProvisionedStateInDatabase(e,t){let n=readProvisionedData(e,t);return n?.every(e=>typeof e!=`string`)?n:void 0}function getRegistryWorktreeProvisionedChunkInDatabase(e,t){let n=i(e).selectFrom(`worktree_provisioned_file_chunks`).select(`data`).where(`worktree_id`,`=`,t.worktreeId).where(`path`,`=`,t.path).where(`chunk_index`,`=`,t.chunkIndex);return a(e,n).rows[0]?.data}const u={"worktrees.findLiveByOwner":({ownerKind:e,ownerId:t},n)=>({type:`worktrees.findLiveByOwner`,value:findLiveRegistryWorktreeByOwnerInDatabase(n,e,t)}),"worktrees.get":({id:e},t)=>({type:`worktrees.get`,value:getRegistryWorktreeInDatabase(t,e)}),"worktrees.sessionBinding":({boundId:e,ownerId:t},n)=>({type:`worktrees.sessionBinding`,value:s(n,()=>{let r=e?getRegistryWorktreeInDatabase(n,e):void 0;return r&&r.removedAt===void 0?r:findLiveRegistryWorktreeByOwnerInDatabase(n,`session`,t)})}),"worktrees.findLiveByPath":({path:e},t)=>({type:`worktrees.findLiveByPath`,value:findLiveRegistryWorktreeByPathInDatabase(t,e)}),"worktrees.list":(e,t)=>({type:`worktrees.list`,value:listRegistryWorktreesInDatabase(t,e)}),"worktrees.liveIds":(e,t)=>({type:`worktrees.liveIds`,value:listLiveRegistryWorktreeIdsInDatabase(t)}),"worktrees.livePaths":(e,t)=>({type:`worktrees.livePaths`,value:listExistingLiveWorktreePathsInDatabase(t)}),"worktrees.provisionedPaths":({id:e},t)=>({type:`worktrees.provisionedPaths`,value:getRegistryWorktreeProvisionedPathsInDatabase(t,e)}),"worktrees.provisionedState":({id:e},t)=>({type:`worktrees.provisionedState`,value:getRegistryWorktreeProvisionedStateInDatabase(t,e)}),"worktrees.provisionedChunk":(e,t)=>({type:`worktrees.provisionedChunk`,value:getRegistryWorktreeProvisionedChunkInDatabase(t,e)})};export{rowToRecord as a,c as i,getRegistryWorktreeInDatabase as n,listRegistryWorktreesInDatabase as r,findLiveRegistryWorktreeByOwnerInDatabase as t};