mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add getSessionModel utility function
This commit is contained in:
1 parent
f12654ce66
commit
b11b3a227e
1 file changed
+22
@@ -0,0 +1,22 @@
|
||||
import type { MessageWithParts } from '@/api/types'
|
||||
|
||||
export function getSessionModel(
|
||||
messages: MessageWithParts[] | undefined,
|
||||
fallbackModel?: string | null
|
||||
): string | null {
|
||||
const assistantMessages = messages?.filter(msg => msg.info.role === 'assistant') || []
|
||||
let latest = assistantMessages[assistantMessages.length - 1]
|
||||
|
||||
if (latest?.info.role === 'assistant') {
|
||||
const tokens = latest.info.tokens.input + latest.info.tokens.output + latest.info.tokens.reasoning
|
||||
if (tokens === 0 && assistantMessages.length > 1) {
|
||||
latest = assistantMessages[assistantMessages.length - 2]
|
||||
}
|
||||
}
|
||||
|
||||
if (latest?.info.role === 'assistant') {
|
||||
return `${latest.info.providerID}/${latest.info.modelID}`
|
||||
}
|
||||
|
||||
return fallbackModel || null
|
||||
}
|
||||
Reference in new issue
Block a user