1- import { Type } from "@sinclair/typebox" ;
1+ import { Type , type TSchema } from "@sinclair/typebox" ;
22import { listChannelPlugins } from "../../channels/plugins/index.js" ;
33import {
44 channelSupportsMessageCapability ,
@@ -82,7 +82,7 @@ const interactiveMessageSchema = Type.Object(
8282) ;
8383
8484function buildSendSchema ( options : { includeInteractive : boolean } ) {
85- const props : Record < string , unknown > = {
85+ const props : Record < string , TSchema > = {
8686 message : Type . Optional ( Type . String ( ) ) ,
8787 effectId : Type . Optional (
8888 Type . String ( {
@@ -167,7 +167,7 @@ function buildFetchSchema() {
167167}
168168
169169function buildPollSchema ( ) {
170- const props : Record < string , unknown > = {
170+ const props : Record < string , TSchema > = {
171171 pollId : Type . Optional ( Type . String ( ) ) ,
172172 pollOptionId : Type . Optional (
173173 Type . String ( {
@@ -346,7 +346,7 @@ function buildChannelManagementSchema() {
346346
347347function buildMessageToolSchemaProps ( options : {
348348 includeInteractive : boolean ;
349- extraProperties ?: Record < string , unknown > ;
349+ extraProperties ?: Record < string , TSchema > ;
350350} ) {
351351 return {
352352 ...buildRoutingSchema ( ) ,
@@ -370,7 +370,7 @@ function buildMessageToolSchemaFromActions(
370370 actions : readonly string [ ] ,
371371 options : {
372372 includeInteractive : boolean ;
373- extraProperties ?: Record < string , unknown > ;
373+ extraProperties ?: Record < string , TSchema > ;
374374 } ,
375375) {
376376 const props = buildMessageToolSchemaProps ( options ) ;
@@ -547,34 +547,39 @@ function buildMessageToolDescription(options?: {
547547 requesterSenderId ?: string ;
548548} ) : string {
549549 const baseDescription = "Send, delete, and manage messages via channel plugins." ;
550+ const resolvedOptions = options ?? { } ;
551+ const currentChannel = normalizeMessageChannel ( resolvedOptions . currentChannel ) ;
550552
551553 // If we have a current channel, show its actions and list other configured channels
552- if ( options ?. currentChannel ) {
554+ if ( currentChannel ) {
553555 const channelActions = listChannelSupportedActions ( {
554- cfg : options . config ,
555- channel : options . currentChannel ,
556- currentChannelId : options . currentChannelId ,
557- currentThreadTs : options . currentThreadTs ,
558- currentMessageId : options . currentMessageId ,
559- accountId : options . currentAccountId ,
560- sessionKey : options . sessionKey ,
561- sessionId : options . sessionId ,
562- agentId : options . agentId ,
563- requesterSenderId : options . requesterSenderId ,
556+ cfg : resolvedOptions . config ,
557+ channel : currentChannel ,
558+ currentChannelId : resolvedOptions . currentChannelId ,
559+ currentThreadTs : resolvedOptions . currentThreadTs ,
560+ currentMessageId : resolvedOptions . currentMessageId ,
561+ accountId : resolvedOptions . currentAccountId ,
562+ sessionKey : resolvedOptions . sessionKey ,
563+ sessionId : resolvedOptions . sessionId ,
564+ agentId : resolvedOptions . agentId ,
565+ requesterSenderId : resolvedOptions . requesterSenderId ,
564566 } ) ;
565567 if ( channelActions . length > 0 ) {
566568 // Always include "send" as a base action
567569 const allActions = new Set ( [ "send" , ...channelActions ] ) ;
568570 const actionList = Array . from ( allActions ) . toSorted ( ) . join ( ", " ) ;
569- let desc = `${ baseDescription } Current channel (${ options . currentChannel } ) supports: ${ actionList } .` ;
571+ let desc = `${ baseDescription } Current channel (${ currentChannel } ) supports: ${ actionList } .` ;
570572
571573 // Include other configured channels so cron/isolated agents can discover them
572574 const otherChannels : string [ ] = [ ] ;
573575 for ( const plugin of listChannelPlugins ( ) ) {
574- if ( plugin . id === options . currentChannel ) {
576+ if ( plugin . id === currentChannel ) {
575577 continue ;
576578 }
577- const actions = listChannelSupportedActions ( { cfg : options . config , channel : plugin . id } ) ;
579+ const actions = listChannelSupportedActions ( {
580+ cfg : resolvedOptions . config ,
581+ channel : plugin . id ,
582+ } ) ;
578583 if ( actions . length > 0 ) {
579584 const all = new Set ( [ "send" , ...actions ] ) ;
580585 otherChannels . push ( `${ plugin . id } (${ Array . from ( all ) . toSorted ( ) . join ( ", " ) } )` ) ;
@@ -589,8 +594,8 @@ function buildMessageToolDescription(options?: {
589594 }
590595
591596 // Fallback to generic description with all configured actions
592- if ( options ? .config ) {
593- const actions = listChannelMessageActions ( options . config ) ;
597+ if ( resolvedOptions . config ) {
598+ const actions = listChannelMessageActions ( resolvedOptions . config ) ;
594599 if ( actions . length > 0 ) {
595600 return `${ baseDescription } Supports actions: ${ actions . join ( ", " ) } .` ;
596601 }
0 commit comments