11/* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */ 
2+ import  {  z  }  from  'zod' ; 
3+ 
24import  {  UploadFileItem  }  from  '../../files' ; 
35import  {  MessageSemanticSearchChunk  }  from  '../../rag' ; 
4- import  {  ChatMessageError  }  from  '../common/base' ; 
6+ import  {  ChatMessageError ,   ChatMessageErrorSchema  }  from  '../common/base' ; 
57import  {  ChatPluginPayload  }  from  '../common/tools' ; 
6- import  {  UIChatMessage ,  UIMessageRoleType  }  from  './chat' ; 
8+ import  {  UIChatMessage  }  from  './chat' ; 
9+ import  {  SemanticSearchChunkSchema  }  from  './rag' ; 
10+ 
11+ export  type  CreateMessageRoleType  =  'user'  |  'assistant'  |  'tool'  |  'supervisor' ; 
712
813export  interface  CreateMessageParams 
914  extends  Partial < Omit < UIChatMessage ,  'content'  |  'role'  |  'topicId'  |  'chunksList' > >  { 
@@ -14,7 +19,7 @@ export interface CreateMessageParams
1419  fromModel ?: string ; 
1520  fromProvider ?: string ; 
1621  groupId ?: string ; 
17-   role : UIMessageRoleType ; 
22+   role : CreateMessageRoleType ; 
1823  sessionId : string ; 
1924  targetId ?: string  |  null ; 
2025  threadId ?: string  |  null ; 
@@ -28,7 +33,7 @@ export interface CreateMessageParams
2833 */ 
2934export  interface  CreateNewMessageParams  { 
3035  // ========== Required fields ========== 
31-   role : UIMessageRoleType ; 
36+   role : CreateMessageRoleType ; 
3237  content : string ; 
3338  sessionId : string ; 
3439
@@ -103,3 +108,92 @@ export interface SendGroupMessageParams {
103108   */ 
104109  targetMemberId ?: string  |  null ; 
105110} 
111+ 
112+ // ========== Zod Schemas ========== // 
113+ 
114+ const  UIMessageRoleTypeSchema  =  z . enum ( [ 'user' ,  'assistant' ,  'tool' ,  'supervisor' ] ) ; 
115+ 
116+ const  ChatPluginPayloadSchema  =  z . object ( { 
117+   apiName : z . string ( ) , 
118+   arguments : z . string ( ) , 
119+   identifier : z . string ( ) , 
120+   type : z . string ( ) , 
121+ } ) ; 
122+ 
123+ export  const  CreateMessageParamsSchema  =  z 
124+   . object ( { 
125+     content : z . string ( ) , 
126+     role : UIMessageRoleTypeSchema , 
127+     sessionId : z . string ( ) . nullable ( ) . optional ( ) , 
128+     error : ChatMessageErrorSchema . nullable ( ) . optional ( ) , 
129+     fileChunks : z . array ( SemanticSearchChunkSchema ) . optional ( ) , 
130+     files : z . array ( z . string ( ) ) . optional ( ) , 
131+     fromModel : z . string ( ) . optional ( ) , 
132+     fromProvider : z . string ( ) . optional ( ) , 
133+     groupId : z . string ( ) . optional ( ) , 
134+     targetId : z . string ( ) . nullable ( ) . optional ( ) , 
135+     threadId : z . string ( ) . nullable ( ) . optional ( ) , 
136+     topicId : z . string ( ) . optional ( ) , 
137+     traceId : z . string ( ) . optional ( ) , 
138+     // Allow additional fields from UIChatMessage (many can be null) 
139+     agentId : z . string ( ) . optional ( ) , 
140+     children : z . any ( ) . optional ( ) , 
141+     chunksList : z . any ( ) . optional ( ) , 
142+     createdAt : z . number ( ) . optional ( ) , 
143+     extra : z . any ( ) . optional ( ) , 
144+     favorite : z . boolean ( ) . optional ( ) , 
145+     fileList : z . any ( ) . optional ( ) , 
146+     id : z . string ( ) . optional ( ) , 
147+     imageList : z . any ( ) . optional ( ) , 
148+     meta : z . any ( ) . optional ( ) , 
149+     metadata : z . any ( ) . nullable ( ) . optional ( ) , 
150+     model : z . string ( ) . nullable ( ) . optional ( ) , 
151+     observationId : z . string ( ) . optional ( ) , 
152+     parentId : z . string ( ) . optional ( ) , 
153+     performance : z . any ( ) . optional ( ) , 
154+     plugin : z . any ( ) . optional ( ) , 
155+     pluginError : z . any ( ) . optional ( ) , 
156+     pluginState : z . any ( ) . optional ( ) , 
157+     provider : z . string ( ) . nullable ( ) . optional ( ) , 
158+     quotaId : z . string ( ) . optional ( ) , 
159+     ragQuery : z . string ( ) . nullable ( ) . optional ( ) , 
160+     ragQueryId : z . string ( ) . nullable ( ) . optional ( ) , 
161+     reasoning : z . any ( ) . optional ( ) , 
162+     search : z . any ( ) . optional ( ) , 
163+     tool_call_id : z . string ( ) . optional ( ) , 
164+     toolCalls : z . any ( ) . optional ( ) , 
165+     tools : z . any ( ) . optional ( ) , 
166+     translate : z . any ( ) . optional ( ) , 
167+     tts : z . any ( ) . optional ( ) , 
168+     updatedAt : z . number ( ) . optional ( ) , 
169+   } ) 
170+   . passthrough ( ) ; 
171+ 
172+ export  const  CreateNewMessageParamsSchema  =  z 
173+   . object ( { 
174+     // Required fields 
175+     role : UIMessageRoleTypeSchema , 
176+     content : z . string ( ) , 
177+     sessionId : z . string ( ) . nullable ( ) . optional ( ) , 
178+     // Tool related 
179+     tool_call_id : z . string ( ) . optional ( ) , 
180+     plugin : ChatPluginPayloadSchema . optional ( ) , 
181+     // Grouping 
182+     parentId : z . string ( ) . optional ( ) , 
183+     groupId : z . string ( ) . optional ( ) , 
184+     // Context 
185+     topicId : z . string ( ) . optional ( ) , 
186+     threadId : z . string ( ) . nullable ( ) . optional ( ) , 
187+     targetId : z . string ( ) . nullable ( ) . optional ( ) , 
188+     // Model info 
189+     model : z . string ( ) . nullable ( ) . optional ( ) , 
190+     provider : z . string ( ) . nullable ( ) . optional ( ) , 
191+     // Content 
192+     files : z . array ( z . string ( ) ) . optional ( ) , 
193+     // Error handling 
194+     error : ChatMessageErrorSchema . nullable ( ) . optional ( ) , 
195+     // Metadata 
196+     traceId : z . string ( ) . optional ( ) , 
197+     fileChunks : z . array ( SemanticSearchChunkSchema ) . optional ( ) , 
198+   } ) 
199+   . passthrough ( ) ; 
0 commit comments