@@ -17,10 +17,9 @@ import { hasNonEmptyString } from "../infra/outbound/channel-target.js";
1717import type { PluginDiscoveryResult } from "../plugins/discovery.js" ;
1818import { listOfficialExternalChannelEnvVars } from "../plugins/official-external-plugin-catalog.js" ;
1919import { isRecord } from "../utils.js" ;
20+ import { isChannelConfigMetadataKey } from "./config-metadata.js" ;
2021import { listBundledChannelIds } from "./plugins/bundled-ids.js" ;
2122
22- const IGNORED_CHANNEL_CONFIG_KEYS = new Set ( [ "defaults" , "modelByChannel" ] ) ;
23-
2423export type AmbientEnvTriggerPolicy = "allow" | "suppress" ;
2524
2625type ChannelPresenceOptions = {
@@ -64,7 +63,9 @@ export function listExplicitlyDisabledChannelIdsForConfig(cfg: OpenClawConfig):
6463 }
6564 return Object . entries ( channels )
6665 . filter ( ( [ , value ] ) => isRecord ( value ) && value . enabled === false )
67- . map ( ( [ channelId ] ) => normalizeOptionalLowercaseString ( channelId ) )
66+ . map ( ( [ channelId ] ) => channelId . trim ( ) )
67+ . filter ( ( channelId ) => channelId && ! isChannelConfigMetadataKey ( channelId ) )
68+ . map ( ( channelId ) => normalizeOptionalLowercaseString ( channelId ) )
6869 . filter ( ( channelId ) : channelId is string => Boolean ( channelId ) ) ;
6970}
7071
@@ -139,15 +140,20 @@ export function listPotentialConfiguredChannelPresenceSignals(
139140) : ChannelPresenceSignal [ ] {
140141 const signals : ChannelPresenceSignal [ ] = [ ] ;
141142 const seenSignals = new Set < string > ( ) ;
142- const addSignal = ( channelId : string , source : ChannelPresenceSignalSource ) => {
143+ const configuredChannelIds = new Set < string > ( ) ;
144+ const addSignal = ( rawChannelId : string , source : ChannelPresenceSignalSource ) => {
145+ const channelId = rawChannelId . trim ( ) ;
146+ if ( ! channelId || isChannelConfigMetadataKey ( channelId ) ) {
147+ return ;
148+ }
143149 const key = `${ source } :${ channelId } ` ;
144150 if ( seenSignals . has ( key ) ) {
145151 return ;
146152 }
147153 seenSignals . add ( key ) ;
154+ configuredChannelIds . add ( channelId ) ;
148155 signals . push ( { channelId, source } ) ;
149156 } ;
150- const configuredChannelIds = new Set < string > ( ) ;
151157 const channelIds = options . channelIds ?? listBundledChannelIds ( env , options . discovery ) ;
152158 const channelEnvPrefixes = listChannelEnvPrefixes ( channelIds ) ;
153159 const scopedChannelIds = options . channelIds
@@ -163,13 +169,12 @@ export function listPotentialConfiguredChannelPresenceSignals(
163169 const channels = isRecord ( cfg . channels ) ? cfg . channels : null ;
164170 if ( channels ) {
165171 for ( const [ key , value ] of Object . entries ( channels ) ) {
166- if ( IGNORED_CHANNEL_CONFIG_KEYS . has ( key ) ) {
172+ if ( isChannelConfigMetadataKey ( key ) ) {
167173 continue ;
168174 }
169175 // Shared channel defaults are not concrete channel configuration; only per-channel entries
170176 // with meaningful settings should produce presence signals.
171177 if ( hasMeaningfulChannelConfig ( value ) ) {
172- configuredChannelIds . add ( key ) ;
173178 addSignal ( key , "config" ) ;
174179 }
175180 }
@@ -182,13 +187,11 @@ export function listPotentialConfiguredChannelPresenceSignals(
182187 }
183188 for ( const [ prefix , channelId ] of channelEnvPrefixes ) {
184189 if ( key . startsWith ( prefix ) ) {
185- configuredChannelIds . add ( channelId ) ;
186190 addSignal ( channelId , "env" ) ;
187191 }
188192 }
189193 for ( const { channelId, envVars } of officialExternalChannelEnvVars ) {
190194 if ( envVars . includes ( key ) ) {
191- configuredChannelIds . add ( channelId ) ;
192195 addSignal ( channelId , "env" ) ;
193196 }
194197 }
@@ -200,7 +203,6 @@ export function listPotentialConfiguredChannelPresenceSignals(
200203 // when the state directory exists to keep startup/status checks cheap.
201204 for ( const channelId of listPersistedAuthStateChannelIds ( options ) ) {
202205 if ( hasPersistedAuthState ( { channelId, cfg, env, options } ) ) {
203- configuredChannelIds . add ( channelId ) ;
204206 addSignal ( channelId , "persisted-auth" ) ;
205207 }
206208 }
0 commit comments