@@ -68,17 +68,17 @@ function stripMessageSuffix(target: string): string {
6868 return target . slice ( 0 , index ) ;
6969}
7070
71- export async function resolveGoogleChatOutboundSpace ( params : {
71+ async function resolveGoogleChatOutboundSpaceDetails ( params : {
7272 account : ResolvedGoogleChatAccount ;
7373 target : string ;
74- } ) : Promise < string > {
74+ } ) : Promise < { name : string ; resource ?: GoogleChatSpace } > {
7575 const normalized = normalizeGoogleChatTarget ( params . target ) ;
7676 if ( ! normalized ) {
7777 throw new Error ( "Missing Google Chat target." ) ;
7878 }
7979 const base = stripMessageSuffix ( normalized ) ;
8080 if ( isGoogleChatSpaceTarget ( base ) ) {
81- return base ;
81+ return { name : base } ;
8282 }
8383 if ( isGoogleChatUserTarget ( base ) ) {
8484 const dm = await findGoogleChatDirectMessage ( {
@@ -88,9 +88,16 @@ export async function resolveGoogleChatOutboundSpace(params: {
8888 if ( ! dm ?. name ) {
8989 throw new Error ( `No Google Chat DM found for ${ base } ` ) ;
9090 }
91- return dm . name ;
91+ return { name : dm . name , resource : dm } ;
9292 }
93- return base ;
93+ return { name : base } ;
94+ }
95+
96+ export async function resolveGoogleChatOutboundSpace ( params : {
97+ account : ResolvedGoogleChatAccount ;
98+ target : string ;
99+ } ) : Promise < string > {
100+ return ( await resolveGoogleChatOutboundSpaceDetails ( params ) ) . name ;
94101}
95102
96103export async function resolveGoogleChatOutboundSessionRoute ( params : {
@@ -100,19 +107,26 @@ export async function resolveGoogleChatOutboundSessionRoute(params: {
100107 target : string ;
101108} ) {
102109 const account = resolveGoogleChatAccount ( { cfg : params . cfg , accountId : params . accountId } ) ;
103- const spaceName = await resolveGoogleChatOutboundSpace ( { account, target : params . target } ) ;
110+ const resolvedSpace = await resolveGoogleChatOutboundSpaceDetails ( {
111+ account,
112+ target : params . target ,
113+ } ) ;
114+ const spaceName = resolvedSpace . name ;
104115 if ( ! isGoogleChatSpaceTarget ( spaceName ) ) {
105116 return null ;
106117 }
107- let space : GoogleChatSpace ;
108- try {
109- space = await getGoogleChatSpace ( { account, spaceName } ) ;
110- } catch {
111- // Space classification only enriches session routing. Delivery must remain
112- // available when this auxiliary read is unavailable or lacks permission.
113- return null ;
118+ let chatType = resolvedSpace . resource
119+ ? resolveGoogleChatSpaceChatType ( resolvedSpace . resource )
120+ : undefined ;
121+ if ( ! chatType ) {
122+ try {
123+ chatType = resolveGoogleChatSpaceChatType ( await getGoogleChatSpace ( { account, spaceName } ) ) ;
124+ } catch {
125+ // Space classification only enriches session routing. Delivery must remain
126+ // available when this auxiliary read is unavailable or lacks permission.
127+ return null ;
128+ }
114129 }
115- const chatType = resolveGoogleChatSpaceChatType ( space ) ;
116130 if ( ! chatType ) {
117131 return null ;
118132 }
0 commit comments