openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 4.89 kB
JavaScript
import{h as isArtifactPreservingStateRead}from"./sqlite-readonly-worker-BWA2KeVB.mjs";import{t as resolveStateDir}from"./state-dir-C22DK7p0.mjs";import{i as resolveIdentityPathViaExistingAncestorSync}from"./path-existence-4c3xWldM.mjs";import{n as assertDatabasePathIdentity,o as inspectDatabasePathIdentitySync}from"./sqlite-worker-identity-gGA4fE_R.mjs";import"./sqlite-database-admission-BikxIIFA.mjs";import"./sqlite-schema-facts-x2rWNNBl.mjs";import{u as resolveSessionStorePathCore}from"./agent-scope-config-CGe7-g8s.mjs";import"./openclaw-agent-db-resources-Ce80pC0J.mjs";import{et as isGatewayExternallySupervised}from"./openclaw-state-db-cache-btIGXlEI.mjs";import{n as matchesAgentDatabaseReadCandidatePath}from"./agent-database-readers-CvzYLGgy.mjs";import{n as cloneEnvWithPlatformSemantics}from"./config-env-vars-DC4WV43c.mjs";import fsSync from"node:fs";import path from"node:path";import{isMainThread}from"node:worker_threads";
//!src/config/sessions/session-store-read-candidates.ts
function resolveCapturedSessionStorePath(e,t,n,r,i=`configured`){if(!r)return resolveSessionStorePathCore(i==="default"?void 0:e,{agentId:t,env:n});const a=r.get(t);if(!a)throw new Error(`Session store path was not captured for ${t}`);return a[i]}function captureSessionStoreReadCandidate(e,t){const n=path.resolve(e);return{path:n,physicalPath:t?path.join(resolveIdentityPathViaExistingAncestorSync(path.dirname(n)),path.basename(n)):resolveIdentityPathViaExistingAncestorSync(n),...t?{scope:t}:{}}}function isSessionStoreReadCandidateCurrent(e){const t=captureSessionStoreReadCandidate(e.path,e.scope).physicalPath;return matchesSessionStoreReadCandidatePhysicalPath(e,t)}function matchesSessionStoreReadCandidatePhysicalPath(e,t){const n=resolveCapturedSessionStoreReadCandidatePhysicalPath(e);if(t===n)return true;if(e.scope||!isSymlinkFreeWindowsShortPath(e.path)&&!isSymlinkFreeWindowsShortPath(e.physicalPath))return false;return matchesWindowsFileAlias(t,n)}function resolveCapturedSessionStoreReadCandidatePhysicalPath(e){if(e.scope||!isSymlinkFreeWindowsShortPath(e.physicalPath))return e.physicalPath;return resolveIdentityPathViaExistingAncestorSync(e.physicalPath)}function isSymlinkFreeWindowsShortPath(e){if(process.platform!==`win32`||!/(?:^|[\\/])[^\\/]*~\d+(?=[\\/]|$)/iu.test(e))return false;return isSymlinkFreePath(e)}function isSymlinkFreePath(e){const t=path.resolve(e);const n=path.parse(t);let r=n.root;for(const e of t.slice(n.root.length).split(path.sep)){r=path.join(r,e);const t=fsSync.lstatSync(r,{throwIfNoEntry:false});if(!t||t.isSymbolicLink())return false}return true}function matchesWindowsFileAlias(e,t){const n=isSymlinkFreeWindowsShortPath(e)?e:isSymlinkFreeWindowsShortPath(t)?t:void 0;if(process.platform!==`win32`||!n||!isSymlinkFreePath(e)||!isSymlinkFreePath(t))return false;const r=fsSync.statSync(path.dirname(e),{bigint:true});const i=fsSync.statSync(path.dirname(t),{bigint:true});if(r.dev!==i.dev||r.ino!==i.ino)return false;const a=inspectDatabasePathIdentitySync(e);const o=inspectDatabasePathIdentitySync(t);return a?.key.startsWith(`file:`)===true&&a.key===o?.key&&a.birthtime===o.birthtime}function assertSessionStoreReadCandidate(e,t){if(isMainThread&&isArtifactPreservingStateRead()){const n=t.find(t=>t.identity&&(t.path===path.resolve(e)||t.physicalPath===path.resolve(e)));if(!n)throw new Error(`Session inspection requires a worker-prepared physical candidate`);return n.physicalPath}const n=resolveIdentityPathViaExistingAncestorSync(e);for(const r of t){const t=!r.scope&&n===resolveCapturedSessionStoreReadCandidatePhysicalPath(r);if((matchesAgentDatabaseReadCandidatePath(r,e)||t||!r.scope&&matchesWindowsFileAlias(r.path,e))&&(!r.scope||matchesAgentDatabaseReadCandidatePath({...r,path:resolveCapturedSessionStoreReadCandidatePhysicalPath(r)},n))&&(!r.scope&&r.path===path.resolve(e)?matchesSessionStoreReadCandidatePhysicalPath(r,n):isSessionStoreReadCandidateCurrent(r))){if(r.identity)assertDatabasePathIdentity(r.path,r.identity);return n}}throw new Error(`Session database target changed outside captured discovery custody: ${e}`)}
//!src/config/sessions/transcript-target-binding.ts
const storageEnvironmentKeys=/* @__PURE__ */ new Set([`OPENCLAW_STATE_DIR`,`OPENCLAW_SUPERVISOR_MODE`,`OPENCLAW_HOME`,`HOME`,`USERPROFILE`,`PREFIX`,`ANDROID_DATA`,`OPENCLAW_TEST_FAST`,`VITEST`,`VITEST_POOL_ID`,`VITEST_WORKER_ID`,`NODE_ENV`]);function captureSessionTranscriptStorageEnvironment(e){const t=cloneEnvWithPlatformSemantics(Object.fromEntries(Object.keys(e).filter(e=>storageEnvironmentKeys.has(e.toUpperCase())).map(t=>[t,e[t]])));return{OPENCLAW_STATE_DIR:resolveStateDir(t),...isGatewayExternallySupervised(t)?{OPENCLAW_SUPERVISOR_MODE:`external`}:{}}}export{resolveCapturedSessionStorePath as i,assertSessionStoreReadCandidate as n,captureSessionStoreReadCandidate as r,captureSessionTranscriptStorageEnvironment as t};