openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.15 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{l as resolveAgentIdFromSessionKey}from"./session-key-BPgKfU2m.mjs";import{l as resolveSessionStorePathCore}from"./paths-CcxgiC3g.mjs";import{t as warnPluginSdkDeprecation}from"./sdk-deprecation-BDUCyBrU.mjs";import{c as withSessionEntriesFromStoresInWorker}from"./session-entry-read-runtime-kAgwDw0B.mjs";import{r as resolveSqliteSessionKey}from"./session-accessor.sqlite-scope-helpers-_Zyjm1vW.mjs";import{s as isNativeSessionEntryRead}from"./session-entry-read-ordered-CeFDTZ-N.mjs";import"./session-accessor-CY8UYP4m.mjs";import{r as getCliSessionBinding}from"./cli-session-binding-uwQzKK6C.mjs";import{a as loadSessionEntryReadOnly}from"./session-accessor.sqlite-exact-read-CzR5cjvF.mjs";import{n as resolveSessionLifecycleTimestamps}from"./lifecycle-B_MGwESC.mjs";import{a as resolveSessionResetPolicy,i as evaluateSessionFreshness}from"./reset-Cqx9zpZ-.mjs";
//!src/config/sessions/entry-freshness.ts
function hasProviderOwnedSession(e){const t=normalizeOptionalString(e?.providerOverride??e?.modelProvider);return Boolean(t&&getCliSessionBinding(e,t))}function resolveFreshnessScope(e){const t=e.agentId??resolveAgentIdFromSessionKey(e.sessionKey,e.defaultAgentId);const n=e.sessionCfg;const r=e.storePath??resolveSessionStorePathCore(n?.store,{agentId:t,env:e.env});return{...e,agentId:t,storePath:r}}function resolveSessionEntryResetFreshness(e){warnPluginSdkDeprecation({family:`session-entry-freshness`,method:`resolveSessionEntryResetFreshness / runtime.channel.session.resolveEntryResetFreshness`,replacement:`await resolveSessionEntryResetFreshnessAsync / runtime.channel.session.resolveEntryResetFreshnessAsync`});return readSessionEntryResetFreshness(resolveFreshnessScope(e))}function readSessionEntryResetFreshness(e){const t=loadSessionEntryReadOnly(e);return resolvePreparedSessionEntryResetFreshness(e,t,resolveSessionLifecycleTimestamps({...e,entry:t}))}async function resolveSessionEntryResetFreshnessAsync(e){const t=resolveFreshnessScope(e);if(isNativeSessionEntryRead(t,t.agentId))return readSessionEntryResetFreshness(t);const n=resolveSqliteSessionKey(t.sessionKey,t.agentId);return withSessionEntriesFromStoresInWorker([{...t,sessionKeys:[n],lifecycleSessionKey:n}],([t])=>{return resolvePreparedSessionEntryResetFreshness(e,t.result.entries[0]?.entry,t.result.lifecycleTimestamps)})}function resolvePreparedSessionEntryResetFreshness(e,t,n){const r=e.resetType;const i=resolveSessionResetPolicy({sessionCfg:e.sessionCfg,resetType:r,resetOverride:e.resetOverride});const a={lifecycleTimestamps:n,resetPolicy:i,resetType:r};if(!t)return{state:`missing`,entry:void 0,freshness:void 0,...a};const o=i.configured!==true&&hasProviderOwnedSession(t)?{fresh:true}:evaluateSessionFreshness({updatedAt:t.updatedAt,sessionStartedAt:n.sessionStartedAt,lastInteractionAt:n.lastInteractionAt,now:e.now??Date.now(),policy:i});return{state:o.fresh?`fresh`:`stale`,entry:t,freshness:o,...a}}export{resolveSessionEntryResetFreshnessAsync as i,resolvePreparedSessionEntryResetFreshness as n,resolveSessionEntryResetFreshness as r,hasProviderOwnedSession as t};