{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-4SSU7T3F.cjs","../src/cli/commands/chat/actions/response-handler.ts"],"names":["streamChatResponse","credentials","messages","options","terminal","modelMessages","msg","spinnerManager","textStream","getChatProvider","fullResponse","chalk","delta","error","errorMessage"],"mappings":"AAAA;AACA,wDAAwC,wDAAyC,4ECA/D,IAULA,CAAAA,CAAqB,KAAA,CAChCC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAAAA,EACoB,CACpB,GAAI,CACF,IAAMC,CAAAA,CAAgCH,CAAAA,CAAS,GAAA,CAAKI,CAAAA,EAAAA,CAAS,CAC3D,IAAA,CAAMA,CAAAA,CAAI,IAAA,CACV,OAAA,CAASA,CAAAA,CAAI,OACf,CAAA,CAAE,CAAA,CAEEH,CAAAA,CAAQ,OAAA,EACVI,mBAAAA,CAAe,KAAA,CAAM,eAAA,CAAiB,wBAAwB,CAAA,CAKhE,IAAMC,CAAAA,CAAa,MAFEC,iCAAAA,CAAgBR,CAAY,QAAQ,CAAA,CAEnB,UAAA,CACpCA,CAAAA,CACAI,CACF,CAAA,CAEIK,CAAAA,CAAe,EAAA,CAEfP,CAAAA,CAAQ,OAAA,EACVI,mBAAAA,CAAe,IAAA,CAAK,eAAe,CAAA,CAGjCH,CAAAA,EAAY,OAAOA,CAAAA,CAAS,KAAA,EAAU,UAAA,EACxCA,CAAAA,CAAS,KAAA,CAAM,CAAA,CAGjB,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAMO,eAAAA,CAAM,IAAA,CAAK,CAAA;AAAA,WAAA,CAAe,CAAC,CAAA,CAEhD,IAAA,KAAA,CAAA,IAAiBC,EAAAA,GAASJ,CAAAA,CACxBE,CAAAA,EAAgBE,CAAAA,CAChB,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAMA,CAAK,CAAA,CAG5B,OAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA;AAAA;AAAA,CAAM,CAAA,CAEvBR,CAAAA,EAAY,OAAOA,CAAAA,CAAS,MAAA,EAAW,UAAA,EACzCA,CAAAA,CAAS,MAAA,CAAO,CAAA,CAGXM,CACT,CAAA,KAAA,CAASG,CAAAA,CAAO,CACVV,CAAAA,CAAQ,OAAA,EACVI,mBAAAA,CAAe,IAAA,CAAK,eAAA,CAAiB,wBAAwB,CAAA,CAG/D,IAAMO,CAAAA,CAAeD,EAAAA,WAAiB,KAAA,CAAQA,CAAAA,CAAM,OAAA,CAAU,MAAA,CAAOA,CAAK,CAAA,CAC1E,MAAA,OAAA,CAAQ,KAAA,CAAMF,eAAAA,CAAM,GAAA,CAAI,CAAA,kCAAA,EAAgCG,CAAY,CAAA,CAAA;AD3D2J","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-4SSU7T3F.cjs","sourcesContent":[null,"import type {ModelMessage} from 'ai';\nimport chalk from 'chalk';\nimport {getChatProvider} from '../../../../core/providers/index.js';\nimport {spinnerManager} from '../../../../core/shared/spinner.js';\nimport type {ChatOptions} from '../types.js';\n\ninterface SimpleMessage {\n  role: 'user' | 'assistant' | 'system';\n  content: string;\n}\n\nexport const streamChatResponse = async (\n  credentials: any,\n  messages: SimpleMessage[],\n  options: ChatOptions,\n  terminal?: any,\n): Promise<string> => {\n  try {\n    const modelMessages: ModelMessage[] = messages.map((msg) => ({\n      role: msg.role,\n      content: msg.content,\n    }));\n\n    if (options.verbose) {\n      spinnerManager.start('chat-response', 'Getting AI response...');\n    }\n\n    const chatProvider = getChatProvider(credentials.provider);\n\n    const textStream = await chatProvider.streamChat(\n      credentials,\n      modelMessages,\n    );\n\n    let fullResponse = '';\n\n    if (options.verbose) {\n      spinnerManager.stop('chat-response');\n    }\n\n    if (terminal && typeof terminal.pause === 'function') {\n      terminal.pause();\n    }\n\n    process.stdout.write(chalk.blue('\\nAssistant: '));\n\n    for await (const delta of textStream) {\n      fullResponse += delta;\n      process.stdout.write(delta);\n    }\n\n    process.stdout.write('\\n\\n');\n\n    if (terminal && typeof terminal.resume === 'function') {\n      terminal.resume();\n    }\n\n    return fullResponse;\n  } catch (error) {\n    if (options.verbose) {\n      spinnerManager.fail('chat-response', 'Failed to get response');\n    }\n\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    console.error(chalk.red(`❌ Error getting AI response: ${errorMessage}`));\n\n    if (options.verbose && error instanceof Error && error.stack) {\n      console.error(chalk.dim('Stack trace:'));\n      console.error(chalk.dim(error.stack));\n    }\n\n    throw error;\n  }\n};\n"]}