| 360 | } |
| 361 | |
| 362 | function getModelKeyFromMessages(api: TuiPluginApi, sessionId: string): string | undefined { |
| 363 | try { |
| 364 | const msgs = api.state.session.messages(sessionId) |
| 365 | // Find the last assistant message with model info |
| 366 | // AssistantMessage has providerID/modelID as top-level fields |
| 367 | // UserMessage has model: { providerID, modelID } |
| 368 | for (let i = msgs.length - 1; i >= 0; i--) { |
| 369 | const msg = msgs[i] as Record<string, unknown> |
| 370 | if (msg.role === "assistant" && msg.providerID && msg.modelID) { |
| 371 | return `${msg.providerID}/${msg.modelID}` |
| 372 | } |
| 373 | if (msg.role === "user") { |
| 374 | const model = msg.model as Record<string, unknown> | undefined |
| 375 | if (model?.providerID && model?.modelID) { |
| 376 | return `${model.providerID}/${model.modelID}` |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } catch { |
| 381 | // messages not available |
| 382 | } |
| 383 | return undefined |
| 384 | } |
| 385 | |
| 386 | async function showRecompDialog(api: TuiPluginApi, targetSessionId = getSessionId(api)): Promise<boolean> { |
| 387 | const sessionId = targetSessionId |