openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
47 lines • 17.3 kB
JavaScript
import{St as e}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{c as t}from"./openclaw-state-read-sqlite-schema-sql-BnVx4b5A.mjs";import{_ as n,o as r}from"./openclaw-state-read-sqlite-schema-facts-Dtolu7-X.mjs";import{a as i,r as a}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{l as o,n as s,o as c,s as l}from"./openclaw-state-read-openclaw-state-db-schema-helpers-QFZd8aJI.mjs";import"./openclaw-state-read-sqlite-transaction-Bt-IwVhZ.mjs";const u=[`github_publication_requests`,`github_personal_publication_requests`,`github_repository_publication_requests`];function needsPublicationDraftMigration(e){return u.some(t=>c(e,t)&&!l(e,t,`draft`))}const d={version:28,tables:u,columns:u.map(e=>`${e}.draft`),migrate:e=>{let t=!1;for(let n of u)t=s(e,n,`draft INTEGER`)||t;return t},applied:`Retained the requested GitHub PR draft choice (v28)`};function withLegacyPublicationDraft(e){return e.replace(/(CREATE TABLE(?: IF NOT EXISTS)? "?github_(?:personal_|repository_)?publication_requests"? \([\s\S]*?)\n {2}(?:"draft" bigint|draft INTEGER),/gu,`$1`)}const f=[[`agent_deletion_journal`,`phase`,`TEXT`,!0],[`agent_database_leases`,`provenance`,`TEXT`,!0],[`user_profile_identities`,`canonical_login`,`TEXT`],[`user_profile_identities`,`authorization_id`,`TEXT`],[`user_profile_identities`,`authorization_basis_json`,`TEXT`],[`user_profile_identities`,`verified_email_json`,`TEXT`,!0],[`template_installs`,`bootstrap_content_digest`,`TEXT`],[`template_installs`,`bootstrap_source_path`,`TEXT`],[`worker_environments`,`desktop_json`,`TEXT`],[`worker_environments`,`bootstrap_install_kind`,`TEXT`],[`worker_environments`,`preparation_purpose`,`TEXT`],[`template_package_refs`,`extension_adapter_identity`,`TEXT`],[`template_package_refs`,`extension_detected_format`,`TEXT`],[`template_package_refs`,`extension_format`,`TEXT`],[`template_package_refs`,`extension_id`,`TEXT`],[`template_package_refs`,`extension_mapped_json`,`TEXT`],[`template_package_refs`,`extension_unavailable_json`,`TEXT`],[`worker_environments`,`shared_host`,`INTEGER`],[`worker_environments`,`node_setup_id`,`TEXT`],[`worker_environments`,`node_device_id`,`TEXT`],[`worker_session_placements`,`terminal_reason`,`TEXT`],[`worker_session_placements`,`terminal_at_ms`,`INTEGER`],[`worker_workspace_pending_results`,`repository_workspace_id`,`TEXT`,!0],[`worker_session_placement_moves`,`abandon_source`,`INTEGER`,!0],[`worker_session_placement_moves`,`target_machine_class`,`TEXT`,!0],[`worker_session_placement_moves`,`target_os`,`TEXT`,!0],[`worktrees`,`run_end_cleanup_json`,`TEXT`],[`worktrees`,`gc_protection_json`,`TEXT`],[`device_bootstrap_tokens`,`setup_id`,`TEXT`,!0],[`session_groups`,`cwd`,`TEXT`,!0],[`session_groups`,`worktree`,`INTEGER`,!0],[`secret_store_entries`,`allowed_hosts`,`TEXT`],[`web_push_subscriptions`,`device_id`,`TEXT`,!0],[`web_push_subscriptions`,`user_profile_id`,`TEXT`,!0],[`web_push_subscriptions`,`preferences_json`,`TEXT`,!0],[`task_runs`,`execution_owner_host`,`TEXT`,!0],[`task_runs`,`execution_owner_pid`,`INTEGER`,!0],[`task_runs`,`execution_owner_start_identity`,`INTEGER`,!0],[`session_watch_cursors`,`watcher_store_path`,`TEXT`,!0],[`subagent_runs`,`requester_store_path`,`TEXT`,!0],[`subagent_runs`,`controller_store_path`,`TEXT`,!0],[`cron_jobs`,`grant_definition_revision`,`TEXT`],[`cron_jobs`,`grant_definition_generation`,`INTEGER`],[`cron_jobs`,`grant_definition_updated_at`,`INTEGER`]];function lazyColumnDefinitions(e){return f.filter(t=>e===void 0||!!t[3]===e).map(([e,t,n])=>({columnName:t,dataType:n,tableName:e}))}const p=lazyColumnDefinitions(),m=lazyColumnDefinitions(!1),h=lazyColumnDefinitions(!0),g={packageUpdatedAt:[[`template_package_refs`,`updated_at_ms INTEGER NOT NULL DEFAULT 0`]],packageIntegrity:[[`template_package_refs`,`package_integrity TEXT NOT NULL DEFAULT 'sha256:0000000000000000000000000000000000000000000000000000000000000000'`]],diagnosticSequence:[[`diagnostic_events`,`sequence INTEGER NOT NULL DEFAULT 0`]],cronRunLogs:[[`worktrees`,`provisioned_paths_json TEXT`],[`apns_registrations`,`relay_origin TEXT`],[`device_pairing_pending`,`refreshed_at_ms INTEGER`],[`device_pairing_pending`,`browser_origin TEXT`],[`device_pairing_paired`,`approved_via TEXT`],[`device_pairing_paired`,`browser_origin TEXT`],[`device_pairing_paired`,`operator_label TEXT`],[`device_pairing_paired`,`node_surface_json TEXT`],[`device_pairing_paired`,`pending_node_surface_json TEXT`],[`cron_run_logs`,`status TEXT`],[`cron_run_logs`,`error TEXT`],[`cron_run_logs`,`summary TEXT`],[`cron_run_logs`,`diagnostics_summary TEXT`],[`cron_run_logs`,`delivery_status TEXT`],[`cron_run_logs`,`delivery_error TEXT`],[`cron_run_logs`,`delivered INTEGER`],[`cron_run_logs`,`session_id TEXT`],[`cron_run_logs`,`session_key TEXT`],[`cron_run_logs`,`run_id TEXT`],[`cron_run_logs`,`run_at_ms INTEGER`],[`cron_run_logs`,`duration_ms INTEGER`],[`cron_run_logs`,`next_run_at_ms INTEGER`],[`cron_run_logs`,`model TEXT`],[`cron_run_logs`,`provider TEXT`],[`cron_run_logs`,`total_tokens INTEGER`],[`cron_run_logs`,`entry_json TEXT NOT NULL DEFAULT '{}'`],[`cron_run_logs`,`created_at INTEGER NOT NULL DEFAULT 0`]],acpReplay:[[`acp_replay_events`,`estimated_bytes INTEGER NOT NULL DEFAULT 0`],[`acp_replay_sessions`,`estimated_bytes INTEGER NOT NULL DEFAULT 0`]],cronJobs:[[`cron_jobs`,`description TEXT`],[`cron_jobs`,`declaration_key TEXT`],[`cron_jobs`,`owner_agent_id TEXT`],[`cron_jobs`,`name TEXT NOT NULL DEFAULT ''`],[`cron_jobs`,`enabled INTEGER NOT NULL DEFAULT 1`],[`cron_jobs`,`agent_id TEXT`],[`cron_jobs`,`payload_kind TEXT NOT NULL DEFAULT 'message'`],[`cron_jobs`,`state_json TEXT NOT NULL DEFAULT '{}'`],[`cron_jobs`,`runtime_updated_at_ms INTEGER`],[`cron_jobs`,`schedule_identity TEXT`],[`cron_jobs`,`sort_order INTEGER NOT NULL DEFAULT 0`]],deliveryQueue:[[`sandbox_registry_entries`,`session_key TEXT`],[`sandbox_registry_entries`,`backend_id TEXT`],[`sandbox_registry_entries`,`runtime_label TEXT`],[`sandbox_registry_entries`,`image TEXT`],[`sandbox_registry_entries`,`created_at_ms INTEGER`],[`sandbox_registry_entries`,`last_used_at_ms INTEGER`],[`sandbox_registry_entries`,`config_label_kind TEXT`],[`sandbox_registry_entries`,`config_hash TEXT`],[`sandbox_registry_entries`,`cdp_port INTEGER`],[`sandbox_registry_entries`,`no_vnc_port INTEGER`],[`delivery_queue_entries`,`entry_kind TEXT`],[`delivery_queue_entries`,`session_key TEXT`],[`delivery_queue_entries`,`channel TEXT`],[`delivery_queue_entries`,`target TEXT`],[`delivery_queue_entries`,`account_id TEXT`],[`delivery_queue_entries`,`retry_count INTEGER NOT NULL DEFAULT 0`],[`delivery_queue_entries`,`last_attempt_at INTEGER`],[`delivery_queue_entries`,`last_error TEXT`],[`delivery_queue_entries`,`recovery_state TEXT`],[`delivery_queue_entries`,`platform_send_started_at INTEGER`]],originalMediaRoot:[[`managed_outgoing_image_records`,`original_media_root TEXT NOT NULL DEFAULT ''`]],beforeTaskAttribution:[[`managed_outgoing_image_records`,`agent_id TEXT`],[`managed_outgoing_image_records`,`cleanup_pending INTEGER NOT NULL DEFAULT 0 CHECK (cleanup_pending IN (0, 1))`],[`current_conversation_bindings`,`conversation_kind TEXT NOT NULL DEFAULT 'channel'`],[`device_bootstrap_tokens`,`pending_profile_json TEXT`],[`gateway_restart_handoff`,`restart_trace_started_at INTEGER`],[`gateway_restart_handoff`,`restart_trace_last_at INTEGER`],[`gateway_restart_intent`,`reason TEXT`],[`gateway_restart_sentinel`,`delivery_channel TEXT`],[`gateway_restart_sentinel`,`delivery_to TEXT`],[`gateway_restart_sentinel`,`delivery_account_id TEXT`],[`gateway_restart_sentinel`,`message TEXT`],[`gateway_restart_sentinel`,`continuation_json TEXT`],[`gateway_restart_sentinel`,`doctor_hint TEXT`],[`gateway_restart_sentinel`,`stats_json TEXT`],[`gateway_boot_lifecycle`,`startup_reason TEXT`],[`official_external_plugin_catalog_snapshots`,`trust_mode TEXT`],[`official_external_plugin_catalog_snapshots`,`trust_key_id TEXT`],[`official_external_plugin_catalog_snapshots`,`trust_signature_count INTEGER`],[`official_external_plugin_catalog_snapshots`,`trust_threshold INTEGER`],[`official_external_plugin_catalog_snapshots`,`trust_verified_at TEXT`]],taskRequester:[[`task_runs`,`requester_agent_id TEXT`]],taskRunDetails:[[`task_runs`,`tool_use_count INTEGER`],[`task_runs`,`last_tool_name TEXT`],[`task_runs`,`detail_json TEXT`]],workerEnvironments:[[`worker_environments`,`bootstrap_bundle_hash TEXT`],[`worker_environments`,`bootstrap_openclaw_version TEXT`],[`worker_environments`,`bootstrap_protocol_features_json TEXT`],[`worker_environments`,`bootstrap_install_kind TEXT`],[`worker_environments`,`owner_epoch INTEGER NOT NULL DEFAULT 0 CHECK (owner_epoch >= 0)`],[`worker_environments`,`ssh_host_key TEXT`],[`worker_workspace_pending_results`,`staged_result_ref TEXT`],[`worker_environments`,`teardown_terminal_state TEXT CHECK (teardown_terminal_state IN ('destroyed', 'failed'))`]]},_=[[`claw_installs`,`template_installs`],[`claw_workspace_files`,`template_workspace_files`],[`claw_package_refs`,`template_package_refs`],[`claw_cron_refs`,`template_cron_refs`],[`claw_mcp_server_refs`,`template_mcp_server_refs`]],v=[[`template_installs`,`claw_name`,`template_name`],[`template_installs`,`claw_version`,`template_version`],[`template_package_refs`,`claw_name`,`template_name`]],y=new Set(_.map(([,e])=>e)),b=m.filter(({tableName:e})=>y.has(e)),x=[...g.packageUpdatedAt,...g.packageIntegrity],S=[[`template_installs`,[1,2,3].map(e=>[`openclaw.clawInstallRecord.v${e}`,`openclaw.templateInstallRecord.v${e}`])],[`template_workspace_files`,[[`openclaw.clawWorkspaceFileRecord.v1`,`openclaw.templateWorkspaceFileRecord.v1`]]],[`template_package_refs`,[[`openclaw.clawPackageRef.v1`,`openclaw.templatePackageRef.v1`]]],[`template_cron_refs`,[[`openclaw.clawCronRef.v1`,`openclaw.templateCronRef.v1`]]],[`template_mcp_server_refs`,[[`openclaw.clawMcpServerRef.v1`,`openclaw.templateMcpServerRef.v1`]]]],literal=e=>`'${e.replaceAll(`'`,`''`)}'`;function legacyTemplateStateIdentifier(e){for(let[t,n]of[..._,...v.map(([,e,t])=>[e,t])])if(e===n)return t;return e}function withLegacyTemplateStateSchema(e){return e.replace(/\btemplate_(?:installs|workspace_files|package_refs|cron_refs|mcp_server_refs|name|version)\b/gu,legacyTemplateStateIdentifier).replaceAll(`'template-introduced'`,`'claw-introduced'`).replaceAll(`'template'`,`'claw'`)}function withLegacyTemplateStateCompatibility(e){return{...e,excludedTables:e.excludedTables?.map(withLegacyTemplateStateSchema),allowedMissingTables:e.allowedMissingTables?.map(withLegacyTemplateStateSchema),allowedMissingColumns:e.allowedMissingColumns?.map(withLegacyTemplateStateSchema),allowedColumnDefinitions:e.allowedColumnDefinitions&&Object.fromEntries(Object.entries(e.allowedColumnDefinitions).map(([e,t])=>[withLegacyTemplateStateSchema(e),t.map(withLegacyTemplateStateSchema)]))}}function versionUpdates(e,n){return`UPDATE ${t(e)} SET schema_version = CASE schema_version
${n.map(([e,t])=>`WHEN ${literal(e)} THEN ${literal(t)}`).join(`
`)}
ELSE schema_version END WHERE schema_version IN (${n.map(([e])=>literal(e)).join(`, `)});`}function migrateTemplateStateNames(r,o){if(o>=36)return!1;let s=n(r),c=new Set(s.tables),l=/* @__PURE__ */ new Set([..._.flat(),`agent_provenance`]),u=new Map([...s.tableSql].flatMap(([t,n])=>n&&l.has(t)?[[t,new Set(e(n,t).columns.keys())]]:[])),addColumn=(e,n)=>{let i=n.trim().split(/\s+/,1)[0],a=u.get(e);return!i||!a||a.has(i)?!1:(r.exec(`ALTER TABLE ${t(e)} ADD COLUMN ${n};`),a.add(i),!0)},d=!1;for(let[e,n]of _)if(c.has(e)){if(c.has(n))throw Error(`Both ${e} and ${n} exist; preserve the store for Doctor inspection.`);r.exec(`ALTER TABLE ${t(e)} RENAME TO ${t(n)};`),c.delete(e),c.add(n);let i=u.get(e);if(!i)throw Error(`Missing predecessor column contract for ${e}`);u.set(n,i),u.delete(e),d=!0}for(let[e,n,i]of v)u.get(e)?.has(n)&&(r.exec(`ALTER TABLE ${t(e)} RENAME COLUMN ${t(n)} TO ${t(i)};`),u.get(e)?.delete(n),u.get(e)?.add(i),d=!0);for(let{tableName:e,columnName:t,dataType:n}of b)addColumn(e,`${t} ${n}`);let f=i(r);addColumn(...g.packageUpdatedAt[0])&&a(r,f.updateTable(`template_package_refs`).set(e=>({updated_at_ms:e.ref(`installed_at_ms`)})));for(let[e,t]of g.packageIntegrity)addColumn(e,t);let p=n(r),m={template_package_refs:[`origin`,`claw-introduced`,`template-introduced`],template_mcp_server_refs:[`origin`,`claw-introduced`,`template-introduced`],agent_provenance:[`created_via`,`claw`,`template`]};for(let n of[`template_installs`,...Object.keys(m)]){let i=p.tableSql.get(n);if(!i)continue;let a=i.slice(i.indexOf(`(`)),o=a;for(let[e,,r]of v)e===n&&(o=o.replaceAll(t(r),r));let s=m[n];if(s&&(o=o.replaceAll(literal(s[1]),literal(s[2]))),o===a)continue;let c=t(`${n}_migration_v36`),l=[...e(i,n).columns.keys()],u=/\bWITHOUT\s+ROWID\b/iu.test(i)?[]:[`rowid`],f=[...u,...l].map(t).join(`, `),h=[...u.map(t),...l.map(e=>s&&e===s[0]?`CASE ${t(e)} WHEN ${literal(s[1])} THEN ${literal(s[2])} ELSE ${t(e)} END`:t(e))].join(`, `);r.exec(`CREATE TABLE ${c} ${o};
INSERT INTO ${c} (${f}) SELECT ${h} FROM ${t(n)};
DROP TABLE ${t(n)};
ALTER TABLE ${c} RENAME TO ${t(n)};`);for(let e of[...p.indexDefinitions.values(),...p.triggers.values()])e.table===n&&typeof e.sql==`string`&&r.exec(e.sql);d=!0}for(let[e,t]of S)if(c.has(e))for(let[n,i]of t)a(r,f.updateTable(e).set({schema_version:i}).where(`schema_version`,`=`,n));return d}const C={version:36,tables:[..._.flat(),`agent_provenance`,`sqlite_stat1`,`sqlite_stat4`],columns:[...b.map(({tableName:e,columnName:t})=>`${e}.${t}`),...x.map(([e,t])=>`${e}.${t.split(` `,1)[0]}`)],migrate:migrateTemplateStateNames,applied:`Migrated released starter tables and provenance to canonical Template names (v36)`},w=`DO $template_names_v36$
DECLARE item record; column_item record; constraint_name text; next_constraint_name text;
BEGIN
FOR item IN SELECT * FROM (VALUES
${_.map(([e,t])=>`(${literal(e)}, ${literal(t)})`).join(`,
`)}
) AS names(old_name, new_name) LOOP
EXECUTE format('ALTER TABLE %I RENAME TO %I', item.old_name, item.new_name);
FOR column_item IN SELECT * FROM (VALUES
${v.map(([e,t,n])=>`(${literal(e)}, ${literal(t)}, ${literal(n)})`).join(`,
`)}
) AS columns(table_name, old_name, new_name) WHERE table_name = item.new_name LOOP
EXECUTE format('ALTER TABLE %I RENAME COLUMN %I TO %I', item.new_name, column_item.old_name, column_item.new_name);
END LOOP;
FOR constraint_name IN SELECT conname FROM pg_constraint
WHERE conrelid = to_regclass(item.new_name) LOOP
next_constraint_name := constraint_name;
IF left(constraint_name, length(item.old_name) + 1) = item.old_name || '_' THEN
next_constraint_name := item.new_name || substr(constraint_name, length(item.old_name) + 1);
END IF;
next_constraint_name := replace(replace(next_constraint_name, '_claw_name_', '_template_name_'), '_claw_version_', '_template_version_');
IF next_constraint_name <> constraint_name THEN
EXECUTE format('ALTER TABLE %I RENAME CONSTRAINT %I TO %I', item.new_name, constraint_name, next_constraint_name);
END IF;
END LOOP;
END LOOP;
${[`template_package_refs`,`template_mcp_server_refs`].map(e=>`
ALTER TABLE ${t(e)} DROP CONSTRAINT ${t(`${e}_origin_check`)};
UPDATE ${t(e)} SET origin = 'template-introduced' WHERE origin = 'claw-introduced';
ALTER TABLE ${t(e)} ADD CONSTRAINT ${t(`${e}_origin_check`)}
CHECK (origin IN ('template-introduced', 'pre-existing'));`).join(`
`)}
IF to_regclass('agent_provenance') IS NOT NULL THEN
ALTER TABLE agent_provenance DROP CONSTRAINT agent_provenance_created_via_check;
UPDATE agent_provenance SET created_via = 'template' WHERE created_via = 'claw';
ALTER TABLE agent_provenance ADD CONSTRAINT agent_provenance_created_via_check
CHECK (created_via IN ('operator', 'agent', 'template'));
END IF;
${S.map(([e,t])=>versionUpdates(e,t)).join(`
`)}
END $template_names_v36$;`;function tableSql(e){let t=r(e);if(t)return t.tableSql.get(`operator_approvals`)??void 0;let n=e.prepare(`SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'operator_approvals'`).get();return typeof n?.sql==`string`?n.sql:void 0}function hasCanonicalOperatorApprovalKinds(e){return!c(e,`operator_approvals`)||/kind\s+text\s+not\s+null\s+check\s*\(\s*kind\s+in\s*\(\s*'exec'\s*,\s*'plugin'\s*,\s*'system-agent'\s*\)\s*\)/.test(tableSql(e)?.toLowerCase()??``)}function assertCanonicalOperatorApprovalKinds(e,t){if(!hasCanonicalOperatorApprovalKinds(e))throw new o(`OpenClaw state database ${t} has a legacy operator approval schema; run openclaw doctor --fix to migrate it.`)}function isCanonicalOperatorApprovalKind(e){return e===`exec`||e===`plugin`||e===`system-agent`}function detectOperatorApprovalSchemaMigration(e,t){return hasCanonicalOperatorApprovalKinds(e)?[]:[{kind:`operator-approvals-system-agent`,path:t}]}export{_ as a,withLegacyTemplateStateCompatibility as c,p as d,m as f,withLegacyPublicationDraft as g,d as h,w as i,withLegacyTemplateStateSchema as l,needsPublicationDraftMigration as m,detectOperatorApprovalSchemaMigration as n,legacyTemplateStateIdentifier as o,g as p,isCanonicalOperatorApprovalKind as r,C as s,assertCanonicalOperatorApprovalKinds as t,h as u};