( options: Pick<ChatCommandOptions, 'sessionId' | 'aiChatId' | 'question'>, deps: Pick<ChatCommandDeps, 'dbManager' | 'aiChatManager'> )
| 125 | } |
| 126 | |
| 127 | export function resolveAIChatTarget( |
| 128 | options: Pick<ChatCommandOptions, 'sessionId' | 'aiChatId' | 'question'>, |
| 129 | deps: Pick<ChatCommandDeps, 'dbManager' | 'aiChatManager'> |
| 130 | ): ResolvedAIChatTarget { |
| 131 | if (options.aiChatId) { |
| 132 | const aiChat = deps.aiChatManager.getAIChat(options.aiChatId) |
| 133 | if (!aiChat) { |
| 134 | throw new Error(`AI chat ${options.aiChatId} not found`) |
| 135 | } |
| 136 | if (options.sessionId && options.sessionId !== aiChat.sessionId) { |
| 137 | throw new Error(`AI chat ${options.aiChatId} belongs to session ${aiChat.sessionId}, not ${options.sessionId}`) |
| 138 | } |
| 139 | assertSessionExists(deps.dbManager, aiChat.sessionId) |
| 140 | return { sessionId: aiChat.sessionId, aiChatId: aiChat.id, assistantId: aiChat.assistantId, created: false } |
| 141 | } |
| 142 | |
| 143 | const sessionId = options.sessionId ?? resolveSingleSessionId(deps.dbManager) |
| 144 | assertSessionExists(deps.dbManager, sessionId) |
| 145 | const aiChat = deps.aiChatManager.createAIChat(sessionId, buildTitle(options.question), 'general_cn') |
| 146 | return { sessionId, aiChatId: aiChat.id, assistantId: aiChat.assistantId, created: true } |
| 147 | } |
| 148 | |
| 149 | export async function runChatTurn( |
| 150 | options: Required<Pick<ChatCommandOptions, 'question'>> & |
no test coverage detected