openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
63 lines (58 loc) • 5.25 kB
JavaScript
import{J as e}from"./transcript-sqlite-database-admission-IPmtadyc.mjs";import{t}from"./transcript-sqlite-schema-sql-BnVx4b5A.mjs";const n=t(e,`session_transcript_cold_archive_chunks`);function withoutAgentColdArchiveChunks(e){return e.replace(`${n}\n\n`,``)}function withoutAgentPostgresColdArchiveChunks(e){return e.replace(/CREATE TABLE "session_transcript_cold_archive_chunks" \([\s\S]*?\n\);\n\n/gu,``).replace(/ALTER TABLE "session_transcript_cold_archive_chunks" [^\n]+\n\n/gu,``)}function agentColdArchiveChunksPostgresMigration(e){return(e.match(/CREATE TABLE "session_transcript_cold_archive_chunks" \([\s\S]*?\n\);|ALTER TABLE "session_transcript_cold_archive_chunks" [^\n]+/gu)??[]).join(`
`)}function withLegacyAgentIndexes(e){return e.replace(`CREATE INDEX IF NOT EXISTS idx_agent_session_nodes_label`,`CREATE INDEX IF NOT EXISTS idx_agent_session_nodes_last_interaction_at
ON session_nodes(last_interaction_at DESC, session_key);
CREATE INDEX IF NOT EXISTS idx_agent_session_nodes_label`).replace(`CREATE TABLE IF NOT EXISTS board_tabs (`,`CREATE INDEX IF NOT EXISTS idx_agent_session_reactions_message
ON session_reactions(session_key, session_id, message_id);
CREATE TABLE IF NOT EXISTS board_tabs (`)}function withLegacyAgentPostgresIndexes(e){return`${e}
ALTER FUNCTION openclaw_transcript_navigation_check(text)
CALLED ON NULL INPUT RESET search_path;
CREATE INDEX "idx_agent_session_nodes_last_interaction_at"
ON "session_nodes" (("last_interaction_at") DESC NULLS LAST,
("session_key") ASC NULLS FIRST);
CREATE INDEX "idx_agent_session_reactions_message"
ON "session_reactions" (("session_key") ASC NULLS FIRST,
("session_id") ASC NULLS FIRST, ("message_id") ASC NULLS FIRST);
`}const r=`
DROP INDEX IF EXISTS idx_agent_session_nodes_last_interaction_at;
DROP INDEX IF EXISTS idx_agent_session_reactions_message;
`,i=[`memory_index_sources`,`memory_index_chunks`],a=[`insert`,`update`,`delete`],o=i.flatMap(e=>a.map(t=>({name:`${e}_revision_after_${t}`,table:e,sql:`CREATE TRIGGER IF NOT EXISTS ${e}_revision_after_${t}
AFTER ${t.toUpperCase()} ON ${e}
BEGIN
UPDATE memory_index_state SET revision = revision + 1 WHERE id = 1;
END;`})));o.map(e=>e.name);function withLegacyAgentMemoryRevisionTriggers(e){let t=o.map(e=>e.sql).join(`
`);return e.replace(`CREATE INDEX IF NOT EXISTS idx_memory_embedding_cache_updated_at`,`${t}\n\nCREATE INDEX IF NOT EXISTS idx_memory_embedding_cache_updated_at`)}function withLegacyAgentPostgresMemoryRevisionTriggers(e){return`${e}\n${i.map(e=>`CREATE FUNCTION "openclaw_${e}_trigger"() RETURNS trigger LANGUAGE plpgsql SET search_path FROM CURRENT AS $trigger$
BEGIN
UPDATE memory_index_state SET revision = revision + 1 WHERE id = 1;
RETURN NULL;
END;
$trigger$;
${a.map(t=>`CREATE TRIGGER "${e}_revision_after_${t}" AFTER ${t.toUpperCase()} ON "${e}" FOR EACH ROW EXECUTE FUNCTION "openclaw_${e}_trigger"();`).join(`
`)}`).join(`
`)}`}const s=i.flatMap(e=>a.map(t=>`DROP TRIGGER IF EXISTS ${e}_revision_after_${t};`)).join(`
`),c=i.map(e=>`${a.map(t=>`DROP TRIGGER IF EXISTS ${e}_revision_after_${t} ON ${e};`).join(`
`)}
DROP FUNCTION IF EXISTS openclaw_${e}_trigger();`).join(`
`);function withoutTrajectoryPayloadColumns(e){return e.replace(` event_utf8_bytes INTEGER,
event_payload BLOB,
event_codec TEXT,
`,``).replace(`COALESCE(event_utf8_bytes, octet_length(event_json))`,`octet_length(event_json)`)}function withLegacyAgentPostgresTrajectoryStorage(e){return e.replace(` "event_utf8_bytes" bigint,
"event_payload" bytea,
"event_codec" text COLLATE "C",
`,``).replaceAll(`coalesce("event_utf8_bytes", octet_length("event_json"))`,`octet_length("event_json")`)}const l=`
ALTER TABLE "trajectory_runtime_events" ADD COLUMN "event_utf8_bytes" bigint;
ALTER TABLE "trajectory_runtime_events" ADD COLUMN "event_payload" bytea;
ALTER TABLE "trajectory_runtime_events" ADD COLUMN "event_codec" text COLLATE "C";
DROP INDEX "idx_agent_trajectory_runtime_run";
CREATE INDEX "idx_agent_trajectory_runtime_run"
ON "trajectory_runtime_events" (("session_id") ASC NULLS FIRST,
("run_id") ASC NULLS FIRST, ("created_at") ASC NULLS FIRST,
(COALESCE("event_utf8_bytes", octet_length("event_json"))) ASC NULLS FIRST);
`;function migrateAgentTrajectoryStorageInTransaction(e){e.exec(`
ALTER TABLE trajectory_runtime_events ADD COLUMN event_utf8_bytes INTEGER;
ALTER TABLE trajectory_runtime_events ADD COLUMN event_payload BLOB;
ALTER TABLE trajectory_runtime_events ADD COLUMN event_codec TEXT;
DROP INDEX idx_agent_trajectory_runtime_run;
CREATE INDEX idx_agent_trajectory_runtime_run
ON trajectory_runtime_events(session_id, run_id, created_at,
COALESCE(event_utf8_bytes, octet_length(event_json)));
`)}export{c as a,withLegacyAgentPostgresMemoryRevisionTriggers as c,withLegacyAgentPostgresIndexes as d,n as f,withoutAgentPostgresColdArchiveChunks as h,withoutTrajectoryPayloadColumns as i,r as l,withoutAgentColdArchiveChunks as m,migrateAgentTrajectoryStorageInTransaction as n,s as o,agentColdArchiveChunksPostgresMigration as p,withLegacyAgentPostgresTrajectoryStorage as r,withLegacyAgentMemoryRevisionTriggers as s,l as t,withLegacyAgentIndexes as u};