UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

58 lines (57 loc) • 2.98 kB
import { _t as parseSqliteTableDefinition } from "./sqlite-database-admission-DQIqro3d.mjs"; import { t as extractSqliteTableSchema } from "./sqlite-schema-sql-CPyk_2Hd.mjs"; import { t as OPENCLAW_AGENT_SCHEMA_SQL } from "./openclaw-agent-schema-BDRJZxWF.mjs"; import { h as runSqliteReadOperationSync, o as getAdmittedSqliteSchemaFacts } from "./sqlite-schema-facts-B1bVE8IB.mjs"; import { a as runSqliteImmediateTransactionSync } from "./sqlite-transaction-BHHu6P5-.mjs"; //#region src/state/openclaw-agent-standing-intents-schema.ts const STANDING_INTENTS_TABLE = "standing_intents"; const STANDING_INTENTS_FTS_TABLE = "standing_intents_fts"; const STANDING_INTENTS_FTS_SHADOW_TABLES = [ "standing_intents_fts_config", "standing_intents_fts_data", "standing_intents_fts_docsize", "standing_intents_fts_idx" ]; const creatorColumnSql = "creator_sender TEXT CHECK (creator_sender IS NULL OR length(trim(creator_sender)) > 0)"; const admittedSchemas = /* @__PURE__ */ new WeakSet(); function hasCurrentStandingIntentsSchema(e) { try { const t = getAdmittedSqliteSchemaFacts(e); if (!t) return false; if (admittedSchemas.has(t)) return true; if (![ "standing_intents", "standing_intents_fts", ...STANDING_INTENTS_FTS_SHADOW_TABLES ].every((e) => t.tables.has(e)) || !["idx_standing_intents_lifecycle", "idx_standing_intents_scope"].every((e) => t.indexes.has(e)) || ![ "standing_intents_fts_after_insert", "standing_intents_fts_after_delete", "standing_intents_fts_after_update" ].every((e) => t.triggers.has(e)) || parseSqliteTableDefinition(t.tableSql.get("standing_intents") ?? null, "standing_intents").columns.get("creator_sender") !== creatorColumnSql) return false; admittedSchemas.add(t); return true; } catch { return false; } } /** The optional synchronous owner supplies write grants only when main-schema DDL is needed. */ function ensureOpenClawAgentStandingIntentsSchema(e, t) { runSqliteReadOperationSync(e, () => { if (hasCurrentStandingIntentsSchema(e)) return; const ensure = () => { if (hasCurrentStandingIntentsSchema(e)) return; const t = extractSqliteTableSchema(OPENCLAW_AGENT_SCHEMA_SQL, STANDING_INTENTS_TABLE, { endMarker: "CREATE TABLE IF NOT EXISTS session_transcript_index_state (", includeEndMarker: false, errorMessage: "OpenClaw standing-intents schema markers are missing." }); e.exec(t.replaceAll(/CREATE ((?:VIRTUAL )?TABLE|INDEX|TRIGGER) IF NOT EXISTS /gu, "CREATE $1 IF NOT EXISTS main.")); if (!e.prepare("PRAGMA main.table_info(standing_intents)").all().some((e) => e.name === "creator_sender")) e.exec(`ALTER TABLE main.standing_intents ADD COLUMN ${creatorColumnSql}`); }; if (e.isTransaction) ensure(); else if (t) t(ensure); else runSqliteImmediateTransactionSync(e, ensure); }); } //#endregion export { ensureOpenClawAgentStandingIntentsSchema as i, STANDING_INTENTS_FTS_TABLE as n, STANDING_INTENTS_TABLE as r, STANDING_INTENTS_FTS_SHADOW_TABLES as t };