11// Googlechat plugin module implements secret contract behavior.
2+ import { normalizeAccountId } from "openclaw/plugin-sdk/account-id" ;
23import {
34 createChannelSecretTargetRegistryEntries ,
45 getChannelSurface ,
@@ -18,6 +19,15 @@ type GoogleChatAccountLike = {
1819 accounts ?: Record < string , unknown > ;
1920} ;
2021
22+ function accountSecretOwner ( accountId : string ) {
23+ return {
24+ ownerKind : "account" as const ,
25+ ownerId : `googlechat:${ normalizeAccountId ( accountId ) } ` ,
26+ requiredForGateway : false ,
27+ disposition : "isolate" as const ,
28+ } ;
29+ }
30+
2131export const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries ( {
2232 channelKey : "googlechat" ,
2333 account : [
@@ -60,7 +70,7 @@ function collectGoogleChatAccountAssignment(params: {
6070 path : string ;
6171 defaults ?: SecretDefaults ;
6272 context : ResolverContext ;
63- active ?: boolean ;
73+ ownerAccountIds : string [ ] ;
6474 inactiveReason ?: string ;
6575} ) : void {
6676 const { explicitRef, ref } = resolveSecretInputRef ( {
@@ -71,7 +81,7 @@ function collectGoogleChatAccountAssignment(params: {
7181 if ( ! ref ) {
7282 return ;
7383 }
74- if ( params . active === false ) {
84+ if ( params . ownerAccountIds . length === 0 ) {
7585 pushInactiveSurfaceWarning ( {
7686 context : params . context ,
7787 path : `${ params . path } .serviceAccount` ,
@@ -90,18 +100,17 @@ function collectGoogleChatAccountAssignment(params: {
90100 message : `${ params . path } : serviceAccountRef is set; runtime will ignore plaintext serviceAccount.` ,
91101 } ) ;
92102 }
93- pushAssignment ( params . context , {
94- ref,
95- path : `${ params . path } .serviceAccount` ,
96- expected : "string-or-object" ,
97- ownerKind : "unknown" ,
98- ownerId : `${ params . path } .serviceAccount` ,
99- requiredForGateway : false ,
100- disposition : "fail-closed" ,
101- apply : ( value ) => {
102- params . target . serviceAccount = value ;
103- } ,
104- } ) ;
103+ for ( const accountId of params . ownerAccountIds ) {
104+ pushAssignment ( params . context , {
105+ ref,
106+ path : `${ params . path } .serviceAccount` ,
107+ expected : "string-or-object" ,
108+ ...accountSecretOwner ( accountId ) ,
109+ apply : ( value ) => {
110+ params . target . serviceAccount = value ;
111+ } ,
112+ } ) ;
113+ }
105114}
106115
107116export function collectRuntimeConfigAssignments ( params : {
@@ -115,22 +124,24 @@ export function collectRuntimeConfigAssignments(params: {
115124 }
116125 const googleChat = resolved . channel as GoogleChatAccountLike ;
117126 const surface = resolveChannelAccountSurface ( googleChat as Record < string , unknown > ) ;
118- const topLevelServiceAccountActive = ! surface . channelEnabled
119- ? false
127+ const topLevelServiceAccountOwners = ! surface . channelEnabled
128+ ? [ ]
120129 : ! surface . hasExplicitAccounts
121- ? true
122- : surface . accounts . some (
123- ( { account, enabled } ) =>
124- enabled &&
125- ! hasOwnProperty ( account , "serviceAccount" ) &&
126- ! hasOwnProperty ( account , "serviceAccountRef" ) ,
127- ) ;
130+ ? [ "default" ]
131+ : surface . accounts
132+ . filter (
133+ ( { account, enabled } ) =>
134+ enabled &&
135+ ! hasOwnProperty ( account , "serviceAccount" ) &&
136+ ! hasOwnProperty ( account , "serviceAccountRef" ) ,
137+ )
138+ . map ( ( { accountId } ) => accountId ) ;
128139 collectGoogleChatAccountAssignment ( {
129140 target : googleChat ,
130141 path : "channels.googlechat" ,
131142 defaults : params . defaults ,
132143 context : params . context ,
133- active : topLevelServiceAccountActive ,
144+ ownerAccountIds : topLevelServiceAccountOwners ,
134145 inactiveReason : "no enabled account inherits this top-level Google Chat serviceAccount." ,
135146 } ) ;
136147 if ( ! surface . hasExplicitAccounts ) {
@@ -148,7 +159,7 @@ export function collectRuntimeConfigAssignments(params: {
148159 path : `channels.googlechat.accounts.${ accountId } ` ,
149160 defaults : params . defaults ,
150161 context : params . context ,
151- active : enabled ,
162+ ownerAccountIds : enabled ? [ accountId ] : [ ] ,
152163 inactiveReason : "Google Chat account is disabled." ,
153164 } ) ;
154165 }
0 commit comments