UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.42 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{N as parseAgentSessionKey}from"./session-key-BPgKfU2m.mjs";import{a as normalizeOptionalAgentRuntimeId}from"./agent-runtime-id-dWmvEQWJ.mjs"; //!src/sessions/agent-harness-session-key.ts const AGENT_HARNESS_SESSION_KEY_PREFIX=`harness:`;const AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE=`Session key namespace is reserved for agent harness-owned sessions.`;const AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE=`Agent harness-owned session identity is locked and cannot be replaced or shared.`;const AGENT_HARNESS_MODEL_RUN_FORBIDDEN_MESSAGE=`Agent harness-owned sessions cannot be used for one-shot model runs.`;const MODEL_SELECTION_LOCK_REMOVAL_MESSAGE=`Model-selection-locked sessions cannot be removed, unlocked, or reassigned.`;function resolveAgentHarnessSessionKeyRest(e){const t=e.trim().toLowerCase();return parseAgentSessionKey(t)?.rest??t}function resolveAgentHarnessSessionKeyOwner(e){const t=resolveAgentHarnessSessionKeyRest(e);if(!t.startsWith(AGENT_HARNESS_SESSION_KEY_PREFIX))return;const n=t.slice(8).split(`:`,1)[0];return normalizeOptionalAgentRuntimeId(n)}function isAgentHarnessSessionKey(e){return resolveAgentHarnessSessionKeyRest(e).startsWith(AGENT_HARNESS_SESSION_KEY_PREFIX)}function resolveMissingAgentHarnessSessionError(e,t){return t===void 0&&isAgentHarnessSessionKey(e)?AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE:void 0}function resolveAgentHarnessSessionContextError(e,t){if(!isAgentHarnessSessionKey(e))return;return t?resolveAgentHarnessSessionStoreEntryError(e,t):AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE}function isAgentHarnessSessionKeyOwnedBy(e,t){const n=normalizeOptionalAgentRuntimeId(t);return Boolean(n&&n===resolveAgentHarnessSessionKeyOwner(e))}function resolveSessionPinnedHarnessId(e){return e?.modelSelectionLocked===true&&!normalizeOptionalString(e.pluginOwnerId)?normalizeOptionalAgentRuntimeId(e.agentHarnessId):void 0}function sessionLockOwnerMatches(e,t){const n=normalizeOptionalString(e.pluginOwnerId);const r=normalizeOptionalString(t.pluginOwnerId);if(n||r)return n===r;return normalizeOptionalString(e.agentHarnessId)?.toLowerCase()===normalizeOptionalString(t.agentHarnessId)?.toLowerCase()}function hasEquivalentRelocatedLockedEntry(e){if(isAgentHarnessSessionKey(e.previousKey))return false;const t=normalizeOptionalString(e.previousEntry.sessionId);if(!t)return false;return Object.entries(e.store).some(([n,r])=>n!==e.previousKey&&r.modelSelectionLocked===true&&r.sessionId===t&&sessionLockOwnerMatches(e.previousEntry,r))}function resolveAgentHarnessSessionStoreTransitionError(e){for(const[t,n]of e.before??[]){const r=e.store[t];if(r?.modelSelectionLocked===true&&sessionLockOwnerMatches(n,r)){if(r.sessionId!==n.sessionId)return AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE;continue}if(r===void 0&&hasEquivalentRelocatedLockedEntry({previousKey:t,previousEntry:n,store:e.store}))continue;return MODEL_SELECTION_LOCK_REMOVAL_MESSAGE}}function isAgentHarnessSessionStoreEntryProtected(e,t){return isAgentHarnessSessionKey(e)&&t.modelSelectionLocked===true}function resolveAgentHarnessSessionStoreError(e){const t=/* @__PURE__ */ new Map;for(const[n,r]of Object.entries(e)){const e=resolveAgentHarnessSessionStoreEntryError(n,r);if(e)return e;if(!isValidAgentHarnessSessionStoreEntry(n,r))continue;const i=normalizeOptionalString(r.sessionId);if(!i||t.has(i))return AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE;t.set(i,n)}for(const[n,r]of Object.entries(e)){const e=normalizeOptionalString(r.sessionId);const i=e?t.get(e):void 0;if(i&&i!==n)return AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE}}function resolveAgentHarnessSessionIdMismatchError(e,t){if(!e||!resolveSessionPinnedHarnessId(e))return;const n=normalizeOptionalString(t);if(!n)return;return n===normalizeOptionalString(e.sessionId)?void 0:AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE}function resolveAgentHarnessSessionStoreEntryError(e,t){if(t.modelSelectionLocked!==true)return;const n=isAgentHarnessSessionKey(e);if(normalizeOptionalString(t.pluginOwnerId))return n?AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE:void 0;const r=normalizeOptionalString(t.agentHarnessId)?.toLowerCase();const i=Boolean(r)&&r===normalizeOptionalAgentRuntimeId(r);if(!normalizeOptionalString(t.sessionId)&&(n||t.agentHarnessId!==void 0))return AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE;if(n)return i&&isAgentHarnessSessionKeyOwnedBy(e,t.agentHarnessId)?void 0:AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE;if(t.agentHarnessId===void 0)return;if(!i)return AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE}function isValidAgentHarnessSessionStoreEntry(e,t){return t.modelSelectionLocked===true&&(isAgentHarnessSessionKey(e)||resolveSessionPinnedHarnessId(t)!==void 0)&&resolveAgentHarnessSessionStoreEntryError(e,t)===void 0}export{isAgentHarnessSessionKey as a,isValidAgentHarnessSessionStoreEntry as c,resolveAgentHarnessSessionStoreEntryError as d,resolveAgentHarnessSessionStoreError as f,resolveSessionPinnedHarnessId as h,MODEL_SELECTION_LOCK_REMOVAL_MESSAGE as i,resolveAgentHarnessSessionContextError as l,resolveMissingAgentHarnessSessionError as m,AGENT_HARNESS_SESSION_ID_LOCKED_MESSAGE as n,isAgentHarnessSessionKeyOwnedBy as o,resolveAgentHarnessSessionStoreTransitionError as p,AGENT_HARNESS_SESSION_KEY_RESERVED_MESSAGE as r,isAgentHarnessSessionStoreEntryProtected as s,AGENT_HARNESS_MODEL_RUN_FORBIDDEN_MESSAGE as t,resolveAgentHarnessSessionIdMismatchError as u};