openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 3.33 kB
JavaScript
import { i as getAdmittedSqliteSchemaFacts } from "./sqlite-schema-facts-BVf0E_0z.mjs";
import { f as readExistingAgentSchemaMeta } from "./sqlite-readonly-location-DEj0l7LR.mjs";
import { t as SqliteSchemaMismatchError } from "./sqlite-schema-issues-BnRd2KGO.mjs";
import { a as readSqliteUserVersion, n as createNewerSqliteSchemaVersionError } from "./sqlite-user-version-DLMl1A7W.mjs";
import { i as OpenClawAgentDatabaseMediaMigrationRequiredError } from "./openclaw-state-worker-error-Bi-BnNrV.mjs";
import { n as normalizeAgentId } from "./agent-id-D1-Q6vR4.mjs";
import "./openclaw-agent-db-contract-OYt2DCoK.mjs";
//#region src/state/openclaw-agent-db-schema-read.ts
function assertSupportedAgentSchemaVersion(db, pathname) {
const userVersion = getAdmittedSqliteSchemaFacts(db)?.userVersion ?? readSqliteUserVersion(db);
if (userVersion > 25) throw createNewerSqliteSchemaVersionError("OpenClaw agent database", pathname, userVersion, 25);
return userVersion;
}
/** Readers may pass their immediate check; writers reread the version after integrity work. */
function assertCanonicalAgentPersistenceVersion(db, pathname, userVersion = getAdmittedSqliteSchemaFacts(db)?.userVersion ?? readSqliteUserVersion(db)) {
const hasApplicationSchema = userVersion === 0 && db.prepare("SELECT 1 FROM sqlite_master WHERE substr(name, 1, 7) <> 'sqlite_' LIMIT 1").get();
const isNewUnownedDatabase = userVersion === 0 && readExistingAgentSchemaMeta(db) === null && !hasApplicationSchema;
if (userVersion < 17 && !isNewUnownedDatabase) throw new OpenClawAgentDatabaseMediaMigrationRequiredError(pathname, userVersion);
if (userVersion < 25 && !isNewUnownedDatabase) throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} uses schema version ${userVersion}; stop active agents and run openclaw doctor --fix to migrate session identities before using it.`);
}
function assertExistingAgentSchemaOwner(existing, agentId, pathname) {
if (!existing) return;
if (existing.role !== "agent") throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} has schema role ${existing.role ?? "unknown"}; expected agent. Run openclaw doctor --fix to inspect and repair its ownership.`);
if (!existing.agentId) throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} has no agent owner. Run openclaw doctor --fix to inspect and repair its ownership.`);
if (normalizeAgentId(existing.agentId) !== agentId) throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} belongs to agent ${existing.agentId}; requested agent ${agentId}.`);
}
function assertCurrentAgentSchemaMetadata(metadata, agentId, pathname) {
if (!metadata) throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} has no schema ownership metadata. Run openclaw doctor --fix to inspect and repair its ownership.`);
assertExistingAgentSchemaOwner(metadata, agentId, pathname);
if (metadata.schemaVersion !== 25) throw new SqliteSchemaMismatchError(`OpenClaw agent database ${pathname} metadata schema version ${metadata.schemaVersion ?? "invalid"} does not match 25; run openclaw doctor --fix before using it.`);
}
//#endregion
export { assertSupportedAgentSchemaVersion as i, assertCurrentAgentSchemaMetadata as n, assertExistingAgentSchemaOwner as r, assertCanonicalAgentPersistenceVersion as t };