MCPcopy Create free account
hub / github.com/cortexkit/magic-context / getModelKeyFromMessages

Function getModelKeyFromMessages

packages/plugin/src/tui/index.tsx:362–384  ·  view source on GitHub ↗
(api: TuiPluginApi, sessionId: string)

Source from the content-addressed store, hash-verified

360}
361
362function 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
386async function showRecompDialog(api: TuiPluginApi, targetSessionId = getSessionId(api)): Promise<boolean> {
387 const sessionId = targetSessionId

Callers 1

showStatusDialogFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected