openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
9 lines • 7.78 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./utils-Dlk0IYAa.mjs";import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import"./session-key-BPgKfU2m.mjs";import{n as listAgentEntries,u as tryResolveDefaultAgentId}from"./agent-roster-4XrgUgPK.mjs";import{i as isSameSessionStoreConfig,t as isPerAgentSessionStoreConfig}from"./session-store-config-Ck41Fpqm.mjs";import"./agent-scope-config-CG9CFpGX.mjs";import{t as coerceConfig}from"./io.read-helpers-B0XuPBY2.mjs";import{r as setConfigValueAtPath,t as getConfigValueAtPath}from"./config-paths-BNzEq3Gi.mjs";import{t as findSkillWorkshopPolicyWriteRefusal}from"./skill-workshop-plugin-migration-Zw7c8SVS.mjs";import{t as applyUnsetPathsForWrite}from"./config-path-mutation-CQ3JedXX.mjs";import{a as retireLegacyAgentDefaultMarkers,r as LEGACY_AGENT_ROSTER_RULES,s as findLegacyConfigRuleIssues}from"./legacy-tools-by-sender-D6Y_L891.mjs";import{r as resolveLegacyAgentRosterOwner}from"./legacy.roster-CU2eR_i6.mjs";import{n as materializeLegacyAgentOwnershipForActiveChannelsResultAsync}from"./validation-CGAl0yU4.mjs";import{r as restoreEnvVarRefsFromResolved}from"./env-preserve-aj205DNy.mjs";import{r as createConfigValidationFailedError}from"./io.write-errors-CQyW8lY6.mjs";import{n as prepareConfigWriteValues}from"./io.write-prepare-B9fpYBu2.mjs";import{n as pinLegacyInheritedAuthOwnerForRosterTransition,t as assertSafeLegacyInheritedAuthDirTransition}from"./legacy-inherited-auth-dir-9LCjV4lR.mjs";import{r as pinSurvivorWorkspaceForRosterCollapse}from"./agent-workspace-roster-transition-2Z1xbeeO.mjs";import{isDeepStrictEqual}from"node:util";
//!src/config/io.auth-inheritance-owner.ts
const AUTH_INHERITANCE_PATH=`agents.defaults.authInheritance`;function explicitlySetsAuthInheritance(e){return Boolean(e?.some(e=>{const t=e.join(`.`);return t===AUTH_INHERITANCE_PATH||t.startsWith(`${AUTH_INHERITANCE_PATH}.`)}))}function prepareAuthInheritanceOwnerForWrite(e){if(!e.writesOwnershipTopology||explicitlySetsAuthInheritance(e.explicitSetPaths))return{config:e.targetConfig,insertedPaths:[]};assertSafeLegacyInheritedAuthDirTransition(e.currentConfig,e.targetConfig,e.env);const t=pinLegacyInheritedAuthOwnerForRosterTransition(e.currentConfig,e.targetConfig);return{config:t,insertedPaths:t===e.targetConfig?[]:[[`agents`,`defaults`,`authInheritance`,`agentId`]]}}
//!src/config/io.ownership-write-guard.ts
function assertAutomaticBindingsWriteAllowed(e){if(e.bindingsIncludeOwned&&e.ownershipPaths.some(e=>e[0]===`bindings`))throw Object.assign(/* @__PURE__ */ new Error(`Automatic agent ownership materialization cannot append to $include-owned bindings. Add the required channel-wide binding to the include, then retry.`),{code:`CONFIG_WRITE_REJECTED`})}
//!src/config/io.session-store-owner.ts
const SESSION_STORE_OWNER_PATH=[`agents`,`defaults`,`sessionStore`,`agentId`];const SESSION_STORE_CONFIG_PATH=SESSION_STORE_OWNER_PATH.slice(0,-1);function prepareSessionStoreOwnershipForWrite(e){const t=isSameSessionStoreConfig(e.currentStore,e.targetConfig.session?.store,e.env);const n=t&&!isPerAgentSessionStoreConfig(e.currentStore);const r=e.currentConfig.agents?.defaults?.sessionStore?.agentId;const i=getConfigValueAtPath(e.explicitSetValueSource??e.targetConfig,SESSION_STORE_CONFIG_PATH);const a=Boolean(isRecord(i)&&typeof i.agentId===`string`&&e.explicitSetPaths?.some(e=>isDeepStrictEqual(e,SESSION_STORE_CONFIG_PATH)||isDeepStrictEqual(e,SESSION_STORE_OWNER_PATH)));if(t||!r||a)return{config:e.targetConfig,sameFixedSessionStore:n,ownershipPaths:[]};const o=applyUnsetPathsForWrite(e.targetConfig,[[...SESSION_STORE_OWNER_PATH]]);return{config:{...o,agents:o.agents??{}},sameFixedSessionStore:n,ownershipPaths:[[...SESSION_STORE_OWNER_PATH]]}}
//!src/config/io.write-topology.ts
function cloneConfigPathParents(e,t,n){let r=e;let i=t;for(const e of n.slice(0,-1)){const t=isRecord(r)?r[e]:void 0;const n=i[e];if(n===t){const n=isRecord(t)?{...t}:{};i[e]=n;i=n}else if(isRecord(n))i=n;else{const t={};i[e]=t;i=t}r=t}}async function prepareConfigWriteTopology(e){const{snapshot:t,options:n,unsetPaths:r,env:i,homedir:a,pluginMetadataSnapshot:o}=e;const s=prepareConfigWriteValues({snapshot:t,nextConfig:e.nextConfig,writeOptions:n,env:i,lowerPrecedenceEnv:e.lowerPrecedenceEnv,explicitSetPaths:n.explicitSetPaths,explicitSetValueSource:n.explicitSetValueSource});const c=findSkillWorkshopPolicyWriteRefusal({previousConfig:t.authoredConfig??t.sourceConfig,nextConfig:s.authoredConfig,writesPlugins:[...n.explicitSetPaths??[],...r].some(e=>e[0]===`plugins`)||!isDeepStrictEqual((t.authoredConfig??t.sourceConfig).plugins,s.authoredConfig.plugins)});if(c)throw createConfigValidationFailedError([{path:`plugins`,message:c}]);const l=findLegacyConfigRuleIssues(t.sourceConfigBeforeMigrations??t.sourceConfig,LEGACY_AGENT_ROSTER_RULES).length===0?retireLegacyAgentDefaultMarkers(s.resolvedConfig):void 0;let u=l?.config??s.resolvedConfig;const d=resolveLegacyAgentRosterOwner(t.sourceConfigBeforeMigrations??t.parsed);const f=listAgentEntries(t.config);const p=listAgentEntries(u);const m=new Set(p.map(e=>normalizeAgentId(e.id)));const h=tryResolveDefaultAgentId(t.config);const g=f.length<=1&&p.length>1;const _=Boolean(h&&m.has(h));const v=n.persistCanonicalAgentRoster===true||!isDeepStrictEqual(f,p)||[...n.explicitSetPaths??[],...r].some(e=>e[0]===`agents`&&(e.length===1||e[1]===`entries`||e[1]===`list`||e[1]===`ownership`));const y=g||d!==void 0&&v;const b=p.length>1&&t.config.agents?.ownership===`explicit`;const x=(y||b)&&u.agents?.ownership===void 0;if(x)u={...u,agents:{...u.agents,ownership:`explicit`}};const S=pinSurvivorWorkspaceForRosterCollapse(t.config,u,i);u=S.config;const C=prepareAuthInheritanceOwnerForWrite({currentConfig:t.config,targetConfig:u,writesOwnershipTopology:v,explicitSetPaths:n.explicitSetPaths,env:i});u=C.config;const w=prepareSessionStoreOwnershipForWrite({currentConfig:t.config,currentStore:(t.sourceConfigBeforeMigrations??t.config).session?.store,targetConfig:u,env:i,explicitSetPaths:n.explicitSetPaths,explicitSetValueSource:n.explicitSetValueSource});u=w.config;const{sameFixedSessionStore:T}=w;const E=d&&v&&m.has(normalizeAgentId(d))?d:void 0;const D=(g&&_?h:void 0)??E;const O=D?await materializeLegacyAgentOwnershipForActiveChannelsResultAsync(u,D,i,o?.manifestRegistry.plugins,{materializeSessionStore:T,materializeWorkspace:true,homedir:a}):{config:u,insertedPaths:[]};u=O.config;const k=[...O.insertedPaths.concat(S.insertedPaths),...C.insertedPaths,...w.ownershipPaths,...x?[[`agents`,`ownership`]]:[]];const A=u.agents?.defaults?.sessionStore;if(!D&&v&&f.length===1&&h&&!_&&T&&(A===void 0||isRecord(A)&&!Object.hasOwn(A,`agentId`))){u={...u,agents:{...u.agents,defaults:{...u.agents?.defaults,sessionStore:{...A,agentId:h}}}};k.push([`agents`,`defaults`,`sessionStore`,`agentId`])}const j=[...new Map(k.map(e=>[e.join(`\0`),e])).values()];assertAutomaticBindingsWriteAllowed({bindingsIncludeOwned:t.bindingsIncludeOwned===true,ownershipPaths:j});const M=[...n.explicitSetPaths??[],...j];const N=s.explicitSetValueSource;const P={...N};for(const e of j){cloneConfigPathParents(N,P,e);setConfigValueAtPath(P,e,getConfigValueAtPath(u,e))}return{nextConfig:u,clearedSessionStoreOwner:w.ownershipPaths.length>0,resolutionEnv:s.resolutionEnv,authoredConfig:u===s.resolvedConfig?s.authoredConfig:coerceConfig(restoreEnvVarRefsFromResolved(u,s.authoredConfig,s.resolvedConfig)),authoredSourceConfig:s.authoredSourceConfig,authoredRuntimeConfig:s.authoredRuntimeConfig,explicitSetPaths:M,explicitSetValueSource:P,persistCanonicalAgentRoster:n.persistCanonicalAgentRoster===true||y||x||(l?.changes.length??0)>0,preserveLegacyAgentRoster:Boolean(d)&&!v,cronOwner:y?d?{provenOwnerAgentId:d}:{}:void 0}}export{prepareConfigWriteTopology as t};