@@ -21,6 +21,49 @@ const SLACK_V2_AGENT_OPERATIONS = [
2121 'rename_agent_session' ,
2222] as const
2323
24+ const SLACK_V2_SESSION_OPERATIONS = [ 'set_agent_session_status' , 'rename_agent_session' ] as const
25+
26+ function hasConfiguredSlackValue (
27+ values : Record < string , unknown > | undefined ,
28+ fieldIds : readonly string [ ]
29+ ) : boolean {
30+ return fieldIds . some ( ( fieldId ) => {
31+ const value = values ?. [ fieldId ]
32+ return value !== undefined && value !== null && value !== ''
33+ } )
34+ }
35+
36+ function isLegacySuggestedPromptsConfiguration ( values ?: Record < string , unknown > ) : boolean {
37+ if ( values ?. operation !== 'set_suggested_prompts' ) return false
38+
39+ const hasAgentFields = hasConfiguredSlackValue ( values , [
40+ 'agentBotCredential' ,
41+ 'manualAgentBotCredential' ,
42+ 'agentChannel' ,
43+ 'manualAgentChannel' ,
44+ 'agentThreadTs' ,
45+ ] )
46+ if ( hasAgentFields ) return false
47+
48+ return hasConfiguredSlackValue ( values , [
49+ 'credential' ,
50+ 'manualCredential' ,
51+ 'channel' ,
52+ 'manualChannel' ,
53+ 'getThreadTimestamp' ,
54+ ] )
55+ }
56+
57+ function getSlackV2AgentOperationCondition ( values ?: Record < string , unknown > ) {
58+ return {
59+ field : 'operation' as const ,
60+ value : [
61+ ...( isLegacySuggestedPromptsConfiguration ( values ) ? [ ] : [ 'set_suggested_prompts' ] ) ,
62+ ...SLACK_V2_SESSION_OPERATIONS ,
63+ ] ,
64+ }
65+ }
66+
2467const CHANNEL_FIELD = [ 'channel' , 'manualChannel' ] as const
2568
2669/**
@@ -2948,22 +2991,31 @@ function adaptSubBlockForV2(sb: SubBlockConfig): SubBlockConfig {
29482991 serviceAccountGroup : 'Custom bots' ,
29492992 serviceAccountConnect : 'Set up a custom bot' ,
29502993 } ,
2951- condition : { field : 'operation' , value : [ ...SLACK_V2_AGENT_OPERATIONS ] , not : true } ,
2994+ condition : ( values ?: Record < string , unknown > ) =>
2995+ isLegacySuggestedPromptsConfiguration ( values )
2996+ ? { field : 'operation' , value : 'set_suggested_prompts' }
2997+ : { field : 'operation' , value : [ ...SLACK_V2_AGENT_OPERATIONS ] , not : true } ,
29522998 }
29532999 }
29543000 if ( sb . id === 'manualCredential' ) {
29553001 return {
29563002 ...rest ,
29573003 placeholder : 'Enter credential ID' ,
2958- condition : { field : 'operation' , value : [ ...SLACK_V2_AGENT_OPERATIONS ] , not : true } ,
3004+ condition : ( values ?: Record < string , unknown > ) =>
3005+ isLegacySuggestedPromptsConfiguration ( values )
3006+ ? { field : 'operation' , value : 'set_suggested_prompts' }
3007+ : { field : 'operation' , value : [ ...SLACK_V2_AGENT_OPERATIONS ] , not : true } ,
29593008 }
29603009 }
29613010 if ( sb . id === 'channel' || sb . id === 'manualChannel' ) {
29623011 return {
29633012 ...sb ,
29643013 dependsOn : [ 'credential' ] ,
29653014 condition : ( values ?: Record < string , unknown > ) => {
2966- if ( SLACK_V2_AGENT_OPERATIONS . includes ( values ?. operation as never ) ) {
3015+ if (
3016+ SLACK_V2_AGENT_OPERATIONS . includes ( values ?. operation as never ) &&
3017+ ! isLegacySuggestedPromptsConfiguration ( values )
3018+ ) {
29673019 return { field : 'operation' , value : [ ...SLACK_V2_AGENT_OPERATIONS ] , not : true }
29683020 }
29693021 if ( typeof condition !== 'function' ) {
@@ -2973,15 +3025,24 @@ function adaptSubBlockForV2(sb: SubBlockConfig): SubBlockConfig {
29733025 } ,
29743026 required : {
29753027 field : 'operation' ,
2976- value : [ 'list_canvases' , 'list_scheduled_messages' , ...SLACK_V2_AGENT_OPERATIONS ] ,
3028+ value : [ 'list_canvases' , 'list_scheduled_messages' , ...SLACK_V2_SESSION_OPERATIONS ] ,
29773029 not : true ,
29783030 } ,
29793031 }
29803032 }
29813033 if ( sb . id === 'getThreadTimestamp' ) {
29823034 return {
29833035 ...sb ,
2984- condition : { field : 'operation' , value : [ 'get_thread' , 'get_thread_replies' ] } ,
3036+ condition : ( values ?: Record < string , unknown > ) => ( {
3037+ field : 'operation' ,
3038+ value : [
3039+ 'get_thread' ,
3040+ 'get_thread_replies' ,
3041+ 'set_status' ,
3042+ 'set_title' ,
3043+ ...( isLegacySuggestedPromptsConfiguration ( values ) ? [ 'set_suggested_prompts' ] : [ ] ) ,
3044+ ] ,
3045+ } ) ,
29853046 required : true ,
29863047 }
29873048 }
@@ -3006,7 +3067,7 @@ function getSlackV2AgentSubBlocks(): SubBlockConfig[] {
30063067 serviceAccountGroup : 'Custom bots' ,
30073068 serviceAccountConnect : 'Set up a custom bot' ,
30083069 } ,
3009- condition : { field : 'operation' , value : [ ... SLACK_V2_AGENT_OPERATIONS ] } ,
3070+ condition : getSlackV2AgentOperationCondition ,
30103071 required : true ,
30113072 mode : 'basic' ,
30123073 } ,
@@ -3016,7 +3077,7 @@ function getSlackV2AgentSubBlocks(): SubBlockConfig[] {
30163077 type : 'short-input' ,
30173078 canonicalParamId : 'agentCredentialId' ,
30183079 placeholder : 'Enter custom bot credential ID' ,
3019- condition : { field : 'operation' , value : [ ... SLACK_V2_AGENT_OPERATIONS ] } ,
3080+ condition : getSlackV2AgentOperationCondition ,
30203081 required : true ,
30213082 mode : 'advanced' ,
30223083 } ,
@@ -3029,7 +3090,7 @@ function getSlackV2AgentSubBlocks(): SubBlockConfig[] {
30293090 selectorKey : 'slack.channels' ,
30303091 placeholder : 'Select Slack channel' ,
30313092 dependsOn : [ 'agentBotCredential' ] ,
3032- condition : { field : 'operation' , value : [ ... SLACK_V2_AGENT_OPERATIONS ] } ,
3093+ condition : getSlackV2AgentOperationCondition ,
30333094 required : true ,
30343095 mode : 'basic' ,
30353096 } ,
@@ -3039,7 +3100,7 @@ function getSlackV2AgentSubBlocks(): SubBlockConfig[] {
30393100 type : 'short-input' ,
30403101 canonicalParamId : 'agentChannelId' ,
30413102 placeholder : 'Enter Slack channel ID' ,
3042- condition : { field : 'operation' , value : [ ... SLACK_V2_AGENT_OPERATIONS ] } ,
3103+ condition : getSlackV2AgentOperationCondition ,
30433104 required : true ,
30443105 mode : 'advanced' ,
30453106 } ,
@@ -3048,10 +3109,7 @@ function getSlackV2AgentSubBlocks(): SubBlockConfig[] {
30483109 title : 'Thread Timestamp' ,
30493110 type : 'short-input' ,
30503111 placeholder : 'Thread timestamp (thread_ts)' ,
3051- condition : {
3052- field : 'operation' ,
3053- value : [ 'set_suggested_prompts' , 'set_agent_session_status' , 'rename_agent_session' ] ,
3054- } ,
3112+ condition : getSlackV2AgentOperationCondition ,
30553113 required : {
30563114 field : 'operation' ,
30573115 value : [ 'set_agent_session_status' , 'rename_agent_session' ] ,
@@ -3153,17 +3211,9 @@ export function getSlackV2OperationSentences() {
31533211 if ( ! operationSentences ) {
31543212 throw new Error ( 'Slack action sentences must be defined before building slack_v2' )
31553213 }
3156- const { set_status : _setStatus , set_title : _setTitle , ...v2Sentences } = operationSentences
31573214 return {
3158- ...v2Sentences ,
3159- set_suggested_prompts : [
3160- {
3161- text : 'Set suggested prompts in' ,
3162- field : [ 'agentChannel' , 'manualAgentChannel' ] ,
3163- core : true ,
3164- } ,
3165- { text : ', for thread' , field : 'agentThreadTs' } ,
3166- ] ,
3215+ ...operationSentences ,
3216+ set_suggested_prompts : [ 'Set suggested prompts' ] ,
31673217 set_agent_session_status : [
31683218 { text : 'Set agent session to' , field : 'agentSessionStatus' , core : true } ,
31693219 { text : 'on thread' , field : 'agentThreadTs' , core : true } ,
@@ -3239,6 +3289,8 @@ export const SlackV2Block: BlockConfig<SlackResponse> = {
32393289 { label : 'Get Thread Replies' , id : 'get_thread_replies' } ,
32403290 { label : 'Get Channel History' , id : 'get_channel_history' } ,
32413291 { label : 'Get Message Permalink' , id : 'get_permalink' } ,
3292+ { label : 'Set Assistant Status' , id : 'set_status' } ,
3293+ { label : 'Set Assistant Title' , id : 'set_title' } ,
32423294 { label : 'Set Suggested Prompts' , id : 'set_suggested_prompts' } ,
32433295 { label : 'Set Agent Session Status' , id : 'set_agent_session_status' } ,
32443296 { label : 'Rename Agent Session' , id : 'rename_agent_session' } ,
@@ -3290,6 +3342,8 @@ export const SlackV2Block: BlockConfig<SlackResponse> = {
32903342 'slack_get_thread_replies' ,
32913343 'slack_get_channel_history' ,
32923344 'slack_get_permalink' ,
3345+ 'slack_set_status' ,
3346+ 'slack_set_title' ,
32933347 'slack_set_suggested_prompts' ,
32943348 'slack_set_suggested_prompts_v2' ,
32953349 'slack_set_agent_session_status_v2' ,
0 commit comments