openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.36 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as safeParseJson}from"./json-coercion-DNNwq4_v.mjs";import{T as publishSqliteDatabaseAdmission,v as peekSqliteDatabaseAdmissionForPath}from"./sqlite-database-admission-B3KDkUt-.mjs";import{i as executeSqliteQuerySync,s as getNodeSqliteKysely}from"./kysely-sync-R08Pt8qn.mjs";
//!src/config/io.health-state.kernel.ts
const healthReceipt={name:`config.health`,read:e=>isRecord(e)?e:void 0,lifetime:`process`};function readConfigHealthReceipt(e){return peekSqliteDatabaseAdmissionForPath(e,healthReceipt)}function publishConfigHealthChanged(e){publishSqliteDatabaseAdmission(e,healthReceipt,{})}function parseFingerprint(e){const t=safeParseJson(e??``);return t&&typeof t===`object`?t:void 0}function stringifyFingerprint(e){return e?JSON.stringify(e):null}function selectConfigHealthRows(e){const t=getNodeSqliteKysely(e).selectFrom(`config_health_entries`).select([`config_path`,`last_known_good_json`,`last_promoted_good_json`,`last_observed_suspicious_signature`,`updated_at_ms`]);return executeSqliteQuerySync(e,t.orderBy(`config_path`,`asc`)).rows}function decodeConfigHealthRows(e){return{entries:Object.fromEntries(e.map(e=>[e.config_path,{lastKnownGood:parseFingerprint(e.last_known_good_json),lastPromotedGood:parseFingerprint(e.last_promoted_good_json),lastObservedSuspiciousSignature:e.last_observed_suspicious_signature}]))}}function readConfigHealthStateInDatabase(e){return decodeConfigHealthRows(selectConfigHealthRows(e))}function prepareConfigHealthPatch(e){return{...Object.hasOwn(e,`lastKnownGood`)?{last_known_good_json:stringifyFingerprint(e.lastKnownGood)}:{},...Object.hasOwn(e,`lastPromotedGood`)?{last_promoted_good_json:stringifyFingerprint(e.lastPromotedGood)}:{},...Object.hasOwn(e,`lastObservedSuspiciousSignature`)?{last_observed_suspicious_signature:e.lastObservedSuspiciousSignature??null}:{}}}function patchConfigHealthEntryInDatabase(e,t,n,r,i){if(r===void 0)return false;const a=getNodeSqliteKysely(e);const o=r===null?a.insertInto(`config_health_entries`).values({config_path:t,last_known_good_json:null,last_promoted_good_json:null,last_observed_suspicious_signature:null,...n,updated_at_ms:i}).onConflict(e=>e.column(`config_path`).doNothing()):a.updateTable(`config_health_entries`).set({...n,updated_at_ms:i}).where(`config_path`,`=`,t).where(`last_known_good_json`,r.lastKnownGoodJson===null?`is`:`=`,r.lastKnownGoodJson).where(`last_promoted_good_json`,r.lastPromotedGoodJson===null?`is`:`=`,r.lastPromotedGoodJson).where(`last_observed_suspicious_signature`,r.suspiciousSignature===null?`is`:`=`,r.suspiciousSignature).where(`updated_at_ms`,`=`,r.updatedAtMs);const s=executeSqliteQuerySync(e,o).numAffectedRows===1n;if(s)publishConfigHealthChanged(e);return s}function writeConfigHealthPatchInDatabase(e,t,n,r){executeSqliteQuerySync(e,getNodeSqliteKysely(e).insertInto(`config_health_entries`).values({config_path:t,last_known_good_json:null,last_promoted_good_json:null,last_observed_suspicious_signature:null,...n,updated_at_ms:r}).onConflict(e=>e.column(`config_path`).doUpdateSet({...n,updated_at_ms:r})));publishConfigHealthChanged(e)}export{readConfigHealthStateInDatabase as a,readConfigHealthReceipt as i,prepareConfigHealthPatch as n,writeConfigHealthPatchInDatabase as o,publishConfigHealthChanged as r,patchConfigHealthEntryInDatabase as t};