UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

95 lines (94 loc) • 3.79 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { l as resolveAgentIdFromSessionKey } from "./session-key-CqAyZeVk.mjs"; import { l as resolveSessionStorePathCore } from "./paths-DvQ5AJvD.mjs"; import { t as warnPluginSdkDeprecation } from "./sdk-deprecation-D5N9acnu.mjs"; import { c as withSessionEntriesFromStoresInWorker } from "./session-entry-read-runtime-1Fp1sybj.mjs"; import { r as resolveSqliteSessionKey } from "./session-accessor.sqlite-scope-helpers-5_tKUULP.mjs"; import { s as isNativeSessionEntryRead } from "./session-entry-read-ordered-DPv30g3R.mjs"; import "./session-accessor-CizTbDQj.mjs"; import { r as getCliSessionBinding } from "./cli-session-binding-BEOgFSDg.mjs"; import { a as loadSessionEntryReadOnly } from "./session-accessor.sqlite-exact-read-CbvqUmsG.mjs"; import { t as resolveSessionLifecycleTimestamps } from "./lifecycle-BFcckgci.mjs"; import { a as resolveSessionResetPolicy, i as evaluateSessionFreshness } from "./reset-mDbPCz5g.mjs"; //#region 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 }; } /** @deprecated Runtime callers should await resolveSessionEntryResetFreshnessAsync. */ 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 })); } /** Entry and transcript fallback belong to the same retained worker snapshot. */ 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); }); } /** Consume entry and lifecycle facts from one retained read without opening another snapshot. */ 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 }; } //#endregion export { resolveSessionEntryResetFreshnessAsync as i, resolvePreparedSessionEntryResetFreshness as n, resolveSessionEntryResetFreshness as r, hasProviderOwnedSession as t };