Skip to content

Commit 0ac4d22

Browse files
committed
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)
1 parent 19b3690 commit 0ac4d22

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/hooks/think-mode/index.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { detectThinkKeyword, extractPromptText } from "./detector"
2-
import { getHighVariant, isAlreadyHighVariant } from "./switcher"
2+
import { getHighVariant, isAlreadyHighVariant, getThinkingConfig } from "./switcher"
33
import type { ThinkModeState, ThinkModeInput } from "./types"
4+
import { log } from "../../shared"
45

56
export * from "./detector"
67
export * from "./switcher"
@@ -23,6 +24,7 @@ export function createThinkModeHook() {
2324
const state: ThinkModeState = {
2425
requested: false,
2526
modelSwitched: false,
27+
thinkingConfigInjected: false,
2628
}
2729

2830
if (!detectThinkKeyword(promptText)) {
@@ -47,17 +49,31 @@ export function createThinkModeHook() {
4749
}
4850

4951
const highVariant = getHighVariant(currentModel.modelID)
52+
const thinkingConfig = getThinkingConfig(currentModel.providerID, currentModel.modelID)
5053

51-
if (!highVariant) {
52-
thinkModeState.set(sessionID, state)
53-
return
54+
if (highVariant) {
55+
output.message.model = {
56+
providerID: currentModel.providerID,
57+
modelID: highVariant,
58+
}
59+
state.modelSwitched = true
60+
log("Think mode: model switched to high variant", {
61+
sessionID,
62+
from: currentModel.modelID,
63+
to: highVariant,
64+
})
5465
}
5566

56-
output.message.model = {
57-
providerID: currentModel.providerID,
58-
modelID: highVariant,
67+
if (thinkingConfig) {
68+
Object.assign(output.message, thinkingConfig)
69+
state.thinkingConfigInjected = true
70+
log("Think mode: thinking config injected", {
71+
sessionID,
72+
provider: currentModel.providerID,
73+
config: thinkingConfig,
74+
})
5975
}
60-
state.modelSwitched = true
76+
6177
thinkModeState.set(sessionID, state)
6278
},
6379

src/hooks/think-mode/switcher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ export const THINKING_CONFIGS: Record<string, Record<string, unknown>> = {
5555
type: "enabled",
5656
budgetTokens: 64000,
5757
},
58+
maxTokens: 128000,
5859
},
5960
"amazon-bedrock": {
6061
reasoningConfig: {
6162
type: "enabled",
6263
budgetTokens: 32000,
6364
},
65+
maxTokens: 64000,
6466
},
6567
google: {
6668
providerOptions: {

src/hooks/think-mode/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface ThinkModeState {
22
requested: boolean
33
modelSwitched: boolean
4+
thinkingConfigInjected: boolean
45
providerID?: string
56
modelID?: string
67
}

0 commit comments

Comments
 (0)