@@ -42,12 +42,12 @@ type ChannelTokenRef struct {
4242
4343// CreateTaskRequest defines the structure of the request body for creating a task
4444type CreateTaskRequest struct {
45- Namespace string `json:"namespace,omitempty"` // Optional, defaults to "default"
46- AgentName string `json:"agentName"` // Required
47- UserMessage string `json:"userMessage,omitempty"` // Optional if contextWindow is provided
48- ContextWindow []acp.Message `json:"contextWindow,omitempty"` // Optional if userMessage is provided
49- BaseURL string `json:"baseURL,omitempty"` // Optional, base URL for the contact channel
50- ChannelTokenFrom * ChannelTokenRef `json:"channelTokenFrom ,omitempty"` // Optional, reference to secret containing the token
45+ Namespace string `json:"namespace,omitempty"` // Optional, defaults to "default"
46+ AgentName string `json:"agentName"` // Required
47+ UserMessage string `json:"userMessage,omitempty"` // Optional if contextWindow is provided
48+ ContextWindow []acp.Message `json:"contextWindow,omitempty"` // Optional if userMessage is provided
49+ BaseURL string `json:"baseURL,omitempty"` // Optional, base URL for the contact channel
50+ ChannelToken string `json:"channelToken ,omitempty"` // Optional, token for the contact channel API
5151}
5252
5353// CreateAgentRequest defines the structure of the request body for creating an agent
@@ -1220,13 +1220,37 @@ func (s *APIServer) createTask(c *gin.Context) {
12201220 return
12211221 }
12221222
1223- // Extract the baseURL and channelTokenFrom fields
1223+ // Extract the baseURL and channelToken fields
12241224 baseURL := req .BaseURL
1225+ channelToken := req .ChannelToken
1226+
1227+ // Create a secret for the channel token if provided
12251228 var channelTokenFrom * acp.SecretKeyRef
1226- if req .ChannelTokenFrom != nil {
1229+ if channelToken != "" {
1230+ // Generate a secret name based on the task
1231+ secretName := fmt .Sprintf ("channel-token-%s" , uuid .New ().String ()[:8 ])
1232+
1233+ // Create the secret
1234+ secret := & corev1.Secret {
1235+ ObjectMeta : metav1.ObjectMeta {
1236+ Name : secretName ,
1237+ Namespace : namespace ,
1238+ },
1239+ Data : map [string ][]byte {
1240+ "token" : []byte (channelToken ),
1241+ },
1242+ }
1243+
1244+ if err := s .client .Create (ctx , secret ); err != nil {
1245+ logger .Error (err , "Failed to create channel token secret" )
1246+ c .JSON (http .StatusInternalServerError , gin.H {"error" : "Failed to create channel token secret: " + err .Error ()})
1247+ return
1248+ }
1249+
1250+ // Reference the secret
12271251 channelTokenFrom = & acp.SecretKeyRef {
1228- Name : req . ChannelTokenFrom . Name ,
1229- Key : req . ChannelTokenFrom . Key ,
1252+ Name : secretName ,
1253+ Key : "token" ,
12301254 }
12311255 }
12321256
@@ -1273,5 +1297,5 @@ func (s *APIServer) createTask(c *gin.Context) {
12731297 }
12741298
12751299 // Return the created task
1276- c .JSON (http .StatusCreated , task )
1300+ c .JSON (http .StatusCreated , sanitizeTask ( * task ) )
12771301}
0 commit comments