UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 10.3 kB
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{D as parseStrictPositiveInteger,E as parseStrictNonNegativeInteger,c as asFiniteNumberInRange}from"./number-coercion-B3CfI447.mjs";import{t as parseBoolean}from"./boolean-coercion-CzFC463r.mjs";import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import{_ as resolveDefaultAgentId,f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{u as resolveWorkspaceStateIdentity}from"./workspace-state-identity-D-_UPy3C.mjs";import"./agent-scope-Dw5XRSEh.mjs"; //!src/memory-host-sdk/dreaming.ts const DEFAULT_MEMORY_DREAMING_FREQUENCY=`0 3 * * *`;const DEFAULT_MEMORY_DREAMING_PLUGIN_ID=`memory-core`;const MANAGED_MEMORY_DREAMING_CRON_NAME=`Memory Dreaming Promotion`;const MANAGED_MEMORY_DREAMING_CRON_TAG=`[managed-by=memory-core.short-term-promotion]`;const MEMORY_DREAMING_SYSTEM_EVENT_TEXT=`__openclaw_memory_core_short_term_promotion_dream__`;const LEGACY_MEMORY_LIGHT_DREAMING_CRON_NAME=`Memory Light Dreaming`;const LEGACY_MEMORY_LIGHT_DREAMING_CRON_TAG=`[managed-by=memory-core.dreaming.light]`;const LEGACY_MEMORY_LIGHT_DREAMING_EVENT_TEXT=`__openclaw_memory_core_light_sleep__`;const LEGACY_MEMORY_REM_DREAMING_CRON_NAME=`Memory REM Dreaming`;const LEGACY_MEMORY_REM_DREAMING_CRON_TAG=`[managed-by=memory-core.dreaming.rem]`;const LEGACY_MEMORY_REM_DREAMING_EVENT_TEXT=`__openclaw_memory_core_rem_sleep__`;const DEFAULT_MEMORY_DEEP_DREAMING_LIMIT=10;const DEFAULT_MEMORY_DEEP_DREAMING_MIN_SCORE=.75;const DEFAULT_MEMORY_DEEP_DREAMING_MIN_RECALL_COUNT=3;const DEFAULT_MEMORY_DEEP_DREAMING_MIN_UNIQUE_QUERIES=3;const DEFAULT_MEMORY_DEEP_DREAMING_RECENCY_HALF_LIFE_DAYS=14;const DEFAULT_MEMORY_DEEP_DREAMING_MAX_PROMOTED_SNIPPET_TOKENS=160;const DEFAULT_MEMORY_DEEP_DREAMING_MAX_PRIOR_ENTRY_LOSS_FRACTION=.25;const DEFAULT_MEMORY_LIGHT_DREAMING_SOURCES=[`daily`,`sessions`,`recall`];const DEFAULT_MEMORY_DEEP_DREAMING_SOURCES=[`daily`,`memory`,`sessions`,`logs`,`recall`];const DEFAULT_MEMORY_REM_DREAMING_SOURCES=[`memory`,`daily`,`deep`];function normalizeScore(e,t){if(typeof e===`string`&&!e.trim())return t;return asFiniteNumberInRange(Number(e),{min:0,max:1})??t}function normalizeStringArray(e,t){if(!Array.isArray(e))return[...t];const n=[];for(const r of e){const e=normalizeChoice(r,t);if(e&&!n.includes(e))n.push(e)}return n.length>0?n:[...t]}function normalizeChoice(e,t){const n=normalizeOptionalLowercaseString(e);return t.find(e=>e===n)}function resolveExecutionConfig(e,t){const n=asNullableRecord(e);const r=parseStrictPositiveInteger(n?.maxOutputTokens);const i=parseStrictPositiveInteger(n?.timeoutMs);const a=n?.temperature;const o=typeof a===`number`&&Number.isFinite(a)&&a>=0?Math.min(2,a):void 0;const s=normalizeOptionalString(n?.model)??t.model;return{speed:normalizeChoice(n?.speed,[`fast`,`balanced`,`slow`])??t.speed,thinking:normalizeChoice(n?.thinking,[`low`,`medium`,`high`])??t.thinking,budget:normalizeChoice(n?.budget,[`cheap`,`medium`,`expensive`])??t.budget,...s?{model:s}:{},...typeof r===`number`?{maxOutputTokens:r}:{},...typeof o===`number`?{temperature:o}:{},...typeof i===`number`?{timeoutMs:i}:{}}}function formatLocalIsoDay(e){const t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function resolveMemoryDreamingPluginId(e){const t=asNullableRecord(e);const n=asNullableRecord(t?.plugins);const r=asNullableRecord(n?.slots);const i=normalizeOptionalString(r?.memory);if(i&&normalizeLowercaseStringOrEmpty(i)!==`none`)return i;return DEFAULT_MEMORY_DREAMING_PLUGIN_ID}function resolveMemoryDreamingPluginConfig(e){const t=asNullableRecord(e);const n=asNullableRecord(t?.plugins);const r=asNullableRecord(n?.entries);const i=resolveMemoryDreamingPluginId(e);const a=asNullableRecord(asNullableRecord(r?.[i])?.config);if(a?.dreaming!==void 0||i===`memory-core`)return a??void 0;const o=asNullableRecord(asNullableRecord(r?.[DEFAULT_MEMORY_DREAMING_PLUGIN_ID])?.config);return(o?.dreaming!==void 0?o:a)??void 0}function resolveMemoryDreamingConfig(e){const t=asNullableRecord(e.pluginConfig?.dreaming);const n=normalizeOptionalString(t?.frequency)??`0 3 * * *`;const r=normalizeOptionalString(t?.timezone)??normalizeOptionalString(e.cfg?.agents?.defaults?.userTimezone);const i=asNullableRecord(t?.storage);const a=asNullableRecord(t?.execution);const o=asNullableRecord(t?.phases);const s=normalizeOptionalString(t?.model);const c=resolveExecutionConfig(a?.defaults,{speed:`balanced`,thinking:`medium`,budget:`medium`,...s?{model:s}:{}});const l=asNullableRecord(o?.light);const u=asNullableRecord(o?.deep);const d=asNullableRecord(o?.rem);const f=asNullableRecord(u?.recovery);const p=parseStrictPositiveInteger(u?.maxAgeDays);const m=parseStrictPositiveInteger(u?.maxPromotedSnippetTokens);const phaseExecution=(e,t,n,r)=>resolveExecutionConfig(e,{...c,speed:t,thinking:n,budget:r});return{enabled:parseBoolean(t?.enabled)??true,frequency:n,...r?{timezone:r}:{},verboseLogging:parseBoolean(t?.verboseLogging)??false,storage:{mode:normalizeChoice(i?.mode,[`inline`,`separate`,`both`])??`separate`,separateReports:parseBoolean(i?.separateReports)??false},execution:{defaults:c},phases:{light:{enabled:parseBoolean(l?.enabled)??true,cron:n,lookbackDays:parseStrictNonNegativeInteger(l?.lookbackDays)??2,limit:parseStrictNonNegativeInteger(l?.limit)??100,dedupeSimilarity:normalizeScore(l?.dedupeSimilarity,.9),sources:normalizeStringArray(l?.sources,DEFAULT_MEMORY_LIGHT_DREAMING_SOURCES),execution:phaseExecution(l?.execution,`fast`,`low`,`cheap`)},deep:{enabled:parseBoolean(u?.enabled)??true,cron:n,limit:parseStrictNonNegativeInteger(u?.limit)??DEFAULT_MEMORY_DEEP_DREAMING_LIMIT,minScore:normalizeScore(u?.minScore,DEFAULT_MEMORY_DEEP_DREAMING_MIN_SCORE),minRecallCount:parseStrictNonNegativeInteger(u?.minRecallCount)??3,minUniqueQueries:parseStrictNonNegativeInteger(u?.minUniqueQueries)??3,recencyHalfLifeDays:parseStrictNonNegativeInteger(u?.recencyHalfLifeDays)??14,maxAgeDays:p??30,maxPromotedSnippetTokens:m??160,maxPriorEntryLossFraction:normalizeScore(u?.maxPriorEntryLossFraction,DEFAULT_MEMORY_DEEP_DREAMING_MAX_PRIOR_ENTRY_LOSS_FRACTION),sources:normalizeStringArray(u?.sources,DEFAULT_MEMORY_DEEP_DREAMING_SOURCES),recovery:{enabled:parseBoolean(f?.enabled)??true,triggerBelowHealth:normalizeScore(f?.triggerBelowHealth,.35),lookbackDays:parseStrictNonNegativeInteger(f?.lookbackDays)??30,maxRecoveredCandidates:parseStrictNonNegativeInteger(f?.maxRecoveredCandidates)??20,minRecoveryConfidence:normalizeScore(f?.minRecoveryConfidence,.9),autoWriteMinConfidence:normalizeScore(f?.autoWriteMinConfidence,.97)},execution:phaseExecution(u?.execution,`balanced`,`high`,`medium`)},rem:{enabled:parseBoolean(d?.enabled)??true,cron:n,lookbackDays:parseStrictNonNegativeInteger(d?.lookbackDays)??7,limit:parseStrictNonNegativeInteger(d?.limit)??10,minPatternStrength:normalizeScore(d?.minPatternStrength,.75),sources:normalizeStringArray(d?.sources,DEFAULT_MEMORY_REM_DREAMING_SOURCES),execution:phaseExecution(d?.execution,`slow`,`high`,`expensive`)}}}}function resolveMemoryDreamingPhaseConfig(e,t){return{...e.phases[t],enabled:e.enabled&&e.phases[t].enabled,...e.timezone?{timezone:e.timezone}:{},verboseLogging:e.verboseLogging,storage:e.storage}}function resolveMemoryDeepDreamingConfig(e){return resolveMemoryDreamingPhaseConfig(resolveMemoryDreamingConfig(e),`deep`)}function resolveMemoryLightDreamingConfig(e){return resolveMemoryDreamingPhaseConfig(resolveMemoryDreamingConfig(e),`light`)}function resolveMemoryRemDreamingConfig(e){return resolveMemoryDreamingPhaseConfig(resolveMemoryDreamingConfig(e),`rem`)}let memoryDreamingDayFormatter;function formatMemoryDreamingDay(e,t){if(!t)return formatLocalIsoDay(e);try{if(memoryDreamingDayFormatter?.timezone!==t)memoryDreamingDayFormatter={timezone:t,formatter:new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`})};const n=memoryDreamingDayFormatter.formatter.formatToParts(new Date(e));const r=new Map(n.map(e=>[e.type,e.value]));return`${r.get(`year`)}-${r.get(`month`)}-${r.get(`day`)}`}catch{}return formatLocalIsoDay(e)}function isSameMemoryDreamingDay(e,t,n){return formatMemoryDreamingDay(e,n)===formatMemoryDreamingDay(t,n)}function resolveMemoryDreamingWorkspaces(e,t={}){const n=listAgentIds(e);const r=/* @__PURE__ */ new Map;const addWorkspace=(t,n)=>{const i=t?.trim();if(!i)return;const a=normalizeOptionalLowercaseString(n)||resolveDefaultAgentId(e);const o=resolveWorkspaceStateIdentity(i).workspacePath;const s=r.get(o);if(s){if(!s.agentIds.includes(a))s.agentIds.push(a);return}r.set(o,{workspaceDir:i,agentIds:[a]})};for(const r of n)addWorkspace(resolveAgentWorkspaceDir(e,r,t.env),r);const i=t.primaryWorkspaceDir?.trim();if(i)addWorkspace(i,t.primaryAgentId??resolveDefaultAgentId(e));return[...r.values()]}function resolveMemoryDreamingWorkspace(e,t,n={}){const r=resolveWorkspaceStateIdentity(t).workspacePath;return resolveMemoryDreamingWorkspaces(e,n).find(e=>resolveWorkspaceStateIdentity(e.workspaceDir).workspacePath===r)}export{resolveMemoryDreamingWorkspace as C,resolveMemoryRemDreamingConfig as E,resolveMemoryDreamingPluginId as S,resolveMemoryLightDreamingConfig as T,formatMemoryDreamingDay as _,DEFAULT_MEMORY_DEEP_DREAMING_RECENCY_HALF_LIFE_DAYS as a,resolveMemoryDreamingConfig as b,LEGACY_MEMORY_LIGHT_DREAMING_CRON_NAME as c,LEGACY_MEMORY_REM_DREAMING_CRON_NAME as d,LEGACY_MEMORY_REM_DREAMING_CRON_TAG as f,MEMORY_DREAMING_SYSTEM_EVENT_TEXT as g,MANAGED_MEMORY_DREAMING_CRON_TAG as h,DEFAULT_MEMORY_DEEP_DREAMING_MIN_UNIQUE_QUERIES as i,LEGACY_MEMORY_LIGHT_DREAMING_CRON_TAG as l,MANAGED_MEMORY_DREAMING_CRON_NAME as m,DEFAULT_MEMORY_DEEP_DREAMING_MIN_RECALL_COUNT as n,DEFAULT_MEMORY_DREAMING_FREQUENCY as o,LEGACY_MEMORY_REM_DREAMING_EVENT_TEXT as p,DEFAULT_MEMORY_DEEP_DREAMING_MIN_SCORE as r,DEFAULT_MEMORY_DREAMING_PLUGIN_ID as s,DEFAULT_MEMORY_DEEP_DREAMING_MAX_PROMOTED_SNIPPET_TOKENS as t,LEGACY_MEMORY_LIGHT_DREAMING_EVENT_TEXT as u,isSameMemoryDreamingDay as v,resolveMemoryDreamingWorkspaces as w,resolveMemoryDreamingPluginConfig as x,resolveMemoryDeepDreamingConfig as y};