feat(chatbot): add chatbot backend api support

This commit is contained in:
yiling
2026-07-07 10:55:22 +08:00
parent 5e73fcf4aa
commit e55ee3a3f0
8 changed files with 973 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import { z } from 'zod'
export const chatRequestSchema = z
.object({
textPrompt: z.string().optional(),
attachedFiles: z.array(z.string()).optional(), // Uploaded file asset IDs
assetIds: z.array(z.string()).optional(), // Workspace file/folder IDs referenced
sessionId: z.string().optional(), // ID of existing session (to continue)
contextAssetId: z.string().optional(), // Active page context asset ID
projectId: z.string().optional(), // Target project ID
})
.superRefine((data, ctx) => {
const hasPrompt = data.textPrompt && data.textPrompt.trim().length > 0
const hasFiles = data.attachedFiles && data.attachedFiles.length > 0
const hasAssets = data.assetIds && data.assetIds.length > 0
if (!hasPrompt && !hasFiles && !hasAssets) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'At least one of textPrompt, attachedFiles, or assetIds must be provided.',
path: ['textPrompt'],
})
}
})
export type ChatRequest = z.infer<typeof chatRequestSchema>
export const chatSessionInfoSchema = z.object({
id: z.string(),
agentId: z.string(),
userId: z.string().nullable(),
assetId: z.string().nullable(),
userCommentId: z.string().nullable(),
createdAt: z.string(),
updatedAt: z.string(),
})
export type ChatSessionInfo = z.infer<typeof chatSessionInfoSchema>
export const chatMessageSchema = z.object({
id: z.string(),
role: z.enum(['user', 'assistant', 'toolCall', 'toolResult', 'thinking_level_change']),
content: z.string(),
timestamp: z.string(),
entry: z.unknown(), // Raw session entry data
})
export type ChatMessage = z.infer<typeof chatMessageSchema>
+1
View File
@@ -18,3 +18,4 @@ export * from './team'
export * from './upload'
export * from './user-metadata'
export * from './versionStack'
export * from './chat'