| 25 | const NOT_AVAILABLE_WEB = 'This feature is not available in web mode' |
| 26 | |
| 27 | export class FetchAIAdapter implements AIAdapter { |
| 28 | // ===== 对话管理 ===== |
| 29 | async getAIChat(aiChatId: string): Promise<AIChat | null> { |
| 30 | try { |
| 31 | return await get<AIChat>(`/ai/chats/${aiChatId}`) |
| 32 | } catch { |
| 33 | return null |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | async getAIChats(sessionId: string): Promise<AIChat[]> { |
| 38 | return get<AIChat[]>(`/ai/chats?sessionId=${encodeURIComponent(sessionId)}`) |
| 39 | } |
| 40 | |
| 41 | async createAIChat(sessionId: string, title: string | undefined, assistantId: string): Promise<AIChat> { |
| 42 | return post<AIChat>('/ai/chats', { sessionId, title, assistantId }) |
| 43 | } |
| 44 | |
| 45 | async updateAIChatTitle(aiChatId: string, title: string): Promise<boolean> { |
| 46 | return put<boolean>(`/ai/chats/${aiChatId}/title`, { title }) |
| 47 | } |
| 48 | |
| 49 | async deleteAIChat(aiChatId: string): Promise<boolean> { |
| 50 | return del<boolean>(`/ai/chats/${aiChatId}`) |
| 51 | } |
| 52 | |
| 53 | // ===== 消息 ===== |
| 54 | async getMessages(aiChatId: string): Promise<AIMessage[]> { |
| 55 | return get<AIMessage[]>(`/ai/chats/${aiChatId}/messages`) |
| 56 | } |
| 57 | |
| 58 | async addMessage( |
| 59 | aiChatId: string, |
| 60 | role: AIMessageRole, |
| 61 | content: string, |
| 62 | dataKeywords?: string[], |
| 63 | dataMessageCount?: number, |
| 64 | contentBlocks?: ContentBlock[], |
| 65 | tokenUsage?: TokenUsageData |
| 66 | ): Promise<AIMessage> { |
| 67 | return post<AIMessage>(`/ai/chats/${aiChatId}/messages`, { |
| 68 | role, |
| 69 | content, |
| 70 | dataKeywords, |
| 71 | dataMessageCount, |
| 72 | contentBlocks, |
| 73 | tokenUsage, |
| 74 | }) |
| 75 | } |
| 76 | |
| 77 | async deleteMessagesFrom(aiChatId: string, messageId: string): Promise<void> { |
| 78 | return post<void>(`/ai/chats/${aiChatId}/messages/${messageId}/delete-from`, {}) |
| 79 | } |
| 80 | |
| 81 | async forkAIChat(sourceAIChatId: string, upToMessageId: string, title?: string): Promise<AIChat> { |
| 82 | return post<AIChat>(`/ai/chats/${sourceAIChatId}/fork`, { upToMessageId, title }) |
| 83 | } |
| 84 |
nothing calls this directly
no outgoing calls
no test coverage detected