( configHandler: ConfigHandler, abortController: AbortController, msg: Message<ToCoreProtocol["llm/streamChat"][0]>, ide: IDE, messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>, )
| 7 | import { TTS } from "../util/tts"; |
| 8 | |
| 9 | export async function* llmStreamChat( |
| 10 | configHandler: ConfigHandler, |
| 11 | abortController: AbortController, |
| 12 | msg: Message<ToCoreProtocol["llm/streamChat"][0]>, |
| 13 | ide: IDE, |
| 14 | messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>, |
| 15 | ): AsyncGenerator<ChatMessage, PromptLog> { |
| 16 | const { config } = await configHandler.loadConfig(); |
| 17 | if (!config) { |
| 18 | throw new Error("Config not loaded"); |
| 19 | } |
| 20 | |
| 21 | // Stop TTS on new StreamChat |
| 22 | if (config.experimental?.readResponseTTS) { |
| 23 | void TTS.kill(); |
| 24 | } |
| 25 | |
| 26 | const { |
| 27 | legacySlashCommandData, |
| 28 | completionOptions, |
| 29 | messages, |
| 30 | messageOptions, |
| 31 | } = msg.data; |
| 32 | |
| 33 | const model = config.selectedModelByRole.chat; |
| 34 | |
| 35 | if (!model) { |
| 36 | throw new Error("No chat model selected"); |
| 37 | } |
| 38 | |
| 39 | // Log to return in case of error |
| 40 | const errorPromptLog = { |
| 41 | modelTitle: model?.title ?? model?.model, |
| 42 | modelProvider: model?.underlyingProviderName ?? "unknown", |
| 43 | completion: "", |
| 44 | prompt: "", |
| 45 | completionOptions: { |
| 46 | ...msg.data.completionOptions, |
| 47 | model: model?.model, |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | try { |
| 52 | if (legacySlashCommandData) { |
| 53 | const { command, contextItems, historyIndex, input, selectedCode } = |
| 54 | legacySlashCommandData; |
| 55 | const slashCommand = config.slashCommands?.find( |
| 56 | (sc) => sc.name === command.name, |
| 57 | ); |
| 58 | if (!slashCommand) { |
| 59 | throw new Error(`Unknown slash command ${command.name}`); |
| 60 | } |
| 61 | if (!slashCommand.run) { |
| 62 | console.error( |
| 63 | `Slash command ${command.name} (${command.source}) has no run function`, |
| 64 | ); |
| 65 | throw new Error(`Slash command not found`); |
| 66 | } |
no test coverage detected