openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.12 kB
JavaScript
import{t as e}from"./transcript-session-canonical-key-error-BMfMRBaI.mjs";import{n as t}from"./transcript-agent-id-DmscQLD6.mjs";import{r as n}from"./transcript-session-key-normalization-CxaUSpng.mjs";import"./transcript-session-key-DI46891-.mjs";import{n as r,r as i}from"./transcript-store-entry-DT0snT2F.mjs";import"./transcript-session-entry-json-Bunk1tNp.mjs";function canonicalSessionKeyMigrationRequiredError(t){return new e(t)}function isCanonicalSessionKey(e){let t=e.trim();if(!t||e!==t||r(e)!==e)return!1;let i=n(t);return t===`global`||t===`unknown`||i!==null&&t.startsWith(`agent:${i.agentId}:`)}function assertCanonicalSessionKeyWrite(e,r){let i=n(e);if(!isCanonicalSessionKey(e)||r&&i&&i.agentId!==t(r))throw canonicalSessionKeyMigrationRequiredError(`refusing non-canonical session key write ${e}`)}function validateCanonicalSessionRowEntry(e,t,a=`admission`){if(e.entry_json===`{}`&&e.entry_valid===-1&&e.retained_window_id===e.current_session_id)return;if(!t||e.entry_valid!==1&&(a!==`read`||e.entry_valid!==0)||(e.parent_session_key??void 0)!==(t.parentSessionKey??t.spawnedBy??void 0)||(e.spawned_by??void 0)!==(t.spawnedBy??void 0)||(e.fork_source_session_key??void 0)!==(t.forkSource?.sessionKey??void 0))throw canonicalSessionKeyMigrationRequiredError(`invalid persisted session row requires repair for ${e.session_key}`);let o=i(e.session_key,t);if(o!==e.session_key)throw canonicalSessionKeyMigrationRequiredError(`non-canonical persisted row resolves to session key ${o}`);let s=e.session_key.trim(),c=n(s);if(e.session_key!==s||r(s)!==s||!c&&s!==`global`&&s!==`unknown`)throw canonicalSessionKeyMigrationRequiredError(`non-canonical persisted row resolves to session key ${s||e.session_key}`);for(let t of[e.parent_session_key,e.spawned_by,e.fork_source_session_key]){if(!t)continue;let e=r(t),i=n(e);if(e!==t||!i&&e!==`global`&&e!==`unknown`)throw canonicalSessionKeyMigrationRequiredError(`non-canonical persisted row resolves to session key ${e||t}`)}return t}export{canonicalSessionKeyMigrationRequiredError as n,validateCanonicalSessionRowEntry as r,assertCanonicalSessionKeyWrite as t};