Files
hapi/web/src/components/AssistantChat/claudeEffortOptions.ts
T
480a476e9b feat(web): give every harness the same effort control (#2261)
Effort looked and behaved differently per harness. Codex and OpenCode
had no toolbar button and called it "Reasoning effort", Claude called the
unset choice "Auto" while others said "Default", Chinese used both 思考强度
and 推理强度, and the status bar and header showed effort only for
Codex, OpenCode and Pi.

- Codex/OpenCode get the same toolbar effort button as Claude; it opens
  the same anchored Effort section.
- Every effort picker is titled Effort (推理强度), and the unset choice is
  Default everywhere. An unset toolbar button reads "Default effort".
- The status bar, header, shared-turn metadata and Codex agent tool cards
  use one "effort <level>" label. Claude and Grok now show their effort,
  with "default" when unset; Pi and AGY show it only when set, since
  their models may not take one.

via [HAPI](https://hapi.run)

Co-authored-by: HAPI <noreply@hapi.run>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 18:01:39 +08:00

55 lines
1.7 KiB
TypeScript

import { CLAUDE_EFFORT_LABELS, CLAUDE_EFFORT_LEVELS, type ClaudeEffortLevel } from '@hapi/protocol'
export type ClaudeComposerEffortOption = {
value: string | null
label: string
}
function normalizeClaudeComposerEffort(effort?: string | null): string | null {
const trimmedEffort = effort?.trim().toLowerCase()
if (!trimmedEffort || trimmedEffort === 'auto' || trimmedEffort === 'default') {
return null
}
return trimmedEffort
}
function formatEffortLabel(effort: string): string {
return CLAUDE_EFFORT_LABELS[effort as keyof typeof CLAUDE_EFFORT_LABELS]
?? `${effort.charAt(0).toUpperCase()}${effort.slice(1)}`
}
/**
* `supportedLevels` narrows the list to what the current model accepts
* (`[]` = no effort control); undefined offers every level.
*/
export function getClaudeComposerEffortOptions(
currentEffort?: string | null,
supportedLevels?: readonly string[]
): ClaudeComposerEffortOption[] {
const normalizedCurrentEffort = normalizeClaudeComposerEffort(currentEffort)
const levels: readonly ClaudeEffortLevel[] = supportedLevels
? CLAUDE_EFFORT_LEVELS.filter((effort) => supportedLevels.includes(effort))
: CLAUDE_EFFORT_LEVELS
const options: ClaudeComposerEffortOption[] = [
{ value: null, label: 'Default' }
]
if (
normalizedCurrentEffort
&& !levels.includes(normalizedCurrentEffort as ClaudeEffortLevel)
) {
options.push({
value: normalizedCurrentEffort,
label: formatEffortLabel(normalizedCurrentEffort)
})
}
options.push(...levels.map((effort) => ({
value: effort,
label: CLAUDE_EFFORT_LABELS[effort]
})))
return options
}