feat(think-mode): inject thinking config with maxTokens for extended thinking
- Actually inject THINKING_CONFIGS into message (was defined but unused) - Add maxTokens: 128000 for Anthropic (required for extended thinking) - Add maxTokens: 64000 for Amazon Bedrock - Track thinkingConfigInjected state 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { detectThinkKeyword, extractPromptText } from "./detector"
|
import { detectThinkKeyword, extractPromptText } from "./detector"
|
||||||
import { getHighVariant, isAlreadyHighVariant } from "./switcher"
|
import { getHighVariant, isAlreadyHighVariant, getThinkingConfig } from "./switcher"
|
||||||
import type { ThinkModeState, ThinkModeInput } from "./types"
|
import type { ThinkModeState, ThinkModeInput } from "./types"
|
||||||
|
import { log } from "../../shared"
|
||||||
|
|
||||||
export * from "./detector"
|
export * from "./detector"
|
||||||
export * from "./switcher"
|
export * from "./switcher"
|
||||||
@@ -23,6 +24,7 @@ export function createThinkModeHook() {
|
|||||||
const state: ThinkModeState = {
|
const state: ThinkModeState = {
|
||||||
requested: false,
|
requested: false,
|
||||||
modelSwitched: false,
|
modelSwitched: false,
|
||||||
|
thinkingConfigInjected: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!detectThinkKeyword(promptText)) {
|
if (!detectThinkKeyword(promptText)) {
|
||||||
@@ -47,17 +49,31 @@ export function createThinkModeHook() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const highVariant = getHighVariant(currentModel.modelID)
|
const highVariant = getHighVariant(currentModel.modelID)
|
||||||
|
const thinkingConfig = getThinkingConfig(currentModel.providerID, currentModel.modelID)
|
||||||
|
|
||||||
if (!highVariant) {
|
if (highVariant) {
|
||||||
thinkModeState.set(sessionID, state)
|
output.message.model = {
|
||||||
return
|
providerID: currentModel.providerID,
|
||||||
|
modelID: highVariant,
|
||||||
|
}
|
||||||
|
state.modelSwitched = true
|
||||||
|
log("Think mode: model switched to high variant", {
|
||||||
|
sessionID,
|
||||||
|
from: currentModel.modelID,
|
||||||
|
to: highVariant,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
output.message.model = {
|
if (thinkingConfig) {
|
||||||
providerID: currentModel.providerID,
|
Object.assign(output.message, thinkingConfig)
|
||||||
modelID: highVariant,
|
state.thinkingConfigInjected = true
|
||||||
|
log("Think mode: thinking config injected", {
|
||||||
|
sessionID,
|
||||||
|
provider: currentModel.providerID,
|
||||||
|
config: thinkingConfig,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
state.modelSwitched = true
|
|
||||||
thinkModeState.set(sessionID, state)
|
thinkModeState.set(sessionID, state)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -55,12 +55,14 @@ export const THINKING_CONFIGS: Record<string, Record<string, unknown>> = {
|
|||||||
type: "enabled",
|
type: "enabled",
|
||||||
budgetTokens: 64000,
|
budgetTokens: 64000,
|
||||||
},
|
},
|
||||||
|
maxTokens: 128000,
|
||||||
},
|
},
|
||||||
"amazon-bedrock": {
|
"amazon-bedrock": {
|
||||||
reasoningConfig: {
|
reasoningConfig: {
|
||||||
type: "enabled",
|
type: "enabled",
|
||||||
budgetTokens: 32000,
|
budgetTokens: 32000,
|
||||||
},
|
},
|
||||||
|
maxTokens: 64000,
|
||||||
},
|
},
|
||||||
google: {
|
google: {
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface ThinkModeState {
|
export interface ThinkModeState {
|
||||||
requested: boolean
|
requested: boolean
|
||||||
modelSwitched: boolean
|
modelSwitched: boolean
|
||||||
|
thinkingConfigInjected: boolean
|
||||||
providerID?: string
|
providerID?: string
|
||||||
modelID?: string
|
modelID?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user