openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.91 kB
JavaScript
import{Lt as e}from"./sqlite-readonly-subsystem-Bfq7Sewc.mjs";import{a as t,n}from"./sqlite-readonly-sqlite-schema-catalog-8883sMXx.mjs";import{On as r,kn as i,on as a,wn as o}from"./sqlite-readonly-sqlite-database-admission-Bj6bmeyX.mjs";import{r as s}from"./sqlite-readonly-path-existence-lfal2A68.mjs";import{l as c}from"./sqlite-readonly-node-sqlite-C-jA8uc4.mjs";import{_ as l,st as u,x as d}from"./sqlite-readonly-location.worker.js";import{i as f}from"./sqlite-readonly-openclaw-state-worker-error-CRDBDn6B.mjs";import{i as p}from"./sqlite-readonly-sqlite-worker-operation-admission-_cdnKaoc.mjs";function normalizeSqliteCatalogSql(e){return e.replace(/\s+/gu,` `).replace(/\s*([(),])\s*/gu,`$1`).trim()}function hasDanglingSkillWorkshopCollectionReviewIndex(e){return t(e,()=>inspectSkillWorkshopCollectionReviewIndex(e))}function inspectSkillWorkshopCollectionReviewIndex(e){let t=e.prepare(`SELECT tbl_name, rootpage, sql FROM sqlite_schema WHERE type = 'index' AND name = ?`).get(f);if(t?.tbl_name!==`skill_workshop_collection_reviews`||typeof t.rootpage!=`number`||t.rootpage<=0||typeof t.sql!=`string`||normalizeSqliteCatalogSql(t.sql)!==normalizeSqliteCatalogSql(`CREATE INDEX idx_skill_workshop_collection_reviews_workspace_time ON skill_workshop_collection_reviews(workspace_dir, create_time DESC, review_id DESC)`))return!1;let n=e.prepare(`PRAGMA table_info(skill_workshop_collection_reviews)`).all();return n.some(e=>e.name===`owner_agent_id`)&&!n.some(e=>e.name===`workspace_dir`)}function openDoctorStateSchemaReadAdmission(e){if(!a(e)&&(c(e),hasDanglingSkillWorkshopCollectionReviewIndex(e)))return n(e)}const m=e(Symbol.for(`openclaw.stateSchemaMutationConflictError`),()=>class extends Error{constructor(e,t){super(`OpenClaw refused shared state schema mutation at ${e} because another Gateway owns that state directory. Stop that Gateway or perform the update through its managed restart path, then retry.`,{cause:t}),this.name=`StateSchemaMutationConflictError`}});function acquireSchemaMaintenanceLease({databasePath:e,busyTimeoutMs:t}){if(p(e))return;let n=s(e),r=d(n);if(r)r.assertCurrent();else try{return l(n,{busyTimeoutMs:t})}catch(e){throw e instanceof u?new m(n,e):e}}function withStateDatabaseSchemaMaintenance(e,t){let n=acquireSchemaMaintenanceLease(e);return n?i(n,`state schema mutation`,()=>n.run(t)):t()}async function withStateDatabaseSchemaMaintenanceAsync(e,t){let n=acquireSchemaMaintenanceLease(e);if(!n)return await t();let i;try{i={value:await n.run(t)}}catch(e){i={error:e}}try{n.release()}catch(e){throw`error`in i?r([i.error,e],`state schema mutation and resource release both failed`,i.error):new o(`state schema mutation completed, but releasing its resource failed`,e)}if(`error`in i)throw i.error;return i.value}export{openDoctorStateSchemaReadAdmission as i,withStateDatabaseSchemaMaintenance as n,withStateDatabaseSchemaMaintenanceAsync as r,m as t};