mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
feat(claude): offer the four current Claude models, drop the 1M presets (#2153)
* fix(claude): drop the obsolete 1M model presets The opus, sonnet and fable aliases now resolve to models with a native 1M window (Opus 5.5, Sonnet 5.5, Fable 5.1), so Claude Code documents the "[1m]" suffix as having no effect on them and its own /model picker no longer lists 1M rows. Remove Sonnet 1M / Opus 1M / Fable 1M from the shared, Android and iOS catalogs. Sessions stored with a "[1m]" value keep working: the composer keeps the current model selectable, and the context-budget fallback treats any "[1m]" model and the remaining aliases as 1M, so local-mode sessions on plain opus/sonnet no longer show a 200k budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): seed a 1M turn-1 context window for bare Claude aliases With the 1M presets gone, a session on plain fable/opus/sonnet must not seed 200k before its first result: those aliases now resolve to models with a native 1M window. Seed 1M when the selected model is a preset alias; an explicit full id still seeds conservatively until its result arrives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(claude): offer the four current Claude models as presets The Claude presets now mirror the aliases Claude Code's /model lists, in its order: Opus, Fable, Sonnet, Haiku. Each alias resolves to the newest model of its family, and all four have a native 1M window, so neither 1M variants nor pinned older versions are offered. Haiku was missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(claude): read the effective context window from get_context_usage The 1M seed for the aliases is wrong for users who disable 1M (CLAUDE_CODE_DISABLE_1M_CONTEXT) or cap it with autoCompactWindow. In remote mode, ask Claude via the get_context_usage control request after each system/init and use its maxTokens, which is what /context shows. A result's raw contextWindow no longer overwrites that value. Older CLIs that reject the request keep the existing seed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: weishu <twsxtd@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
weishu
parent
97224c9dd7
commit
3f8686e623
+2
-4
@@ -20,12 +20,10 @@ object NewSessionCatalogs {
|
||||
/** `'auto'` sentinel rows use the web's "Default" label. */
|
||||
val CLAUDE_MODELS: List<OptionItem> = listOf(
|
||||
OptionItem("auto", "Default"),
|
||||
OptionItem("sonnet", "Sonnet"),
|
||||
OptionItem("sonnet[1m]", "Sonnet 1M"),
|
||||
OptionItem("opus", "Opus"),
|
||||
OptionItem("opus[1m]", "Opus 1M"),
|
||||
OptionItem("fable", "Fable"),
|
||||
OptionItem("fable[1m]", "Fable 1M"),
|
||||
OptionItem("sonnet", "Sonnet"),
|
||||
OptionItem("haiku", "Haiku"),
|
||||
)
|
||||
|
||||
val CLAUDE_EFFORTS: List<OptionItem> = listOf(
|
||||
|
||||
@@ -11,12 +11,10 @@ package app.hapi.protocol.catalog
|
||||
object ClaudeModels {
|
||||
/** `CLAUDE_MODEL_LABELS` — declaration order preserved (picker order). */
|
||||
val LABELS: Map<String, String> = linkedMapOf(
|
||||
"sonnet" to "Sonnet",
|
||||
"sonnet[1m]" to "Sonnet 1M",
|
||||
"opus" to "Opus",
|
||||
"opus[1m]" to "Opus 1M",
|
||||
"fable" to "Fable",
|
||||
"fable[1m]" to "Fable 1M",
|
||||
"sonnet" to "Sonnet",
|
||||
"haiku" to "Haiku",
|
||||
)
|
||||
|
||||
/** `CLAUDE_MODEL_PRESETS`. */
|
||||
|
||||
@@ -71,6 +71,7 @@ export async function claudeRemote(opts: {
|
||||
onSessionFound: (id: string, extras?: { forkedFrom?: string }) => void,
|
||||
onThinkingChange?: (thinking: boolean) => void,
|
||||
onMessage: (message: SDKMessage) => void,
|
||||
onContextUsage?: (usage: { model?: string, maxTokens?: number }) => void,
|
||||
onFirstResult?: (initialMessage: string) => void,
|
||||
onCompactResultAccepted?: () => void,
|
||||
onCompletionEvent?: (message: string) => void,
|
||||
@@ -554,6 +555,13 @@ export async function claudeRemote(opts: {
|
||||
|
||||
const systemInit = message as SDKSystemMessage;
|
||||
|
||||
if (opts.onContextUsage) {
|
||||
// Older CLIs may not support get_context_usage; the converter's seed stays.
|
||||
response.getContextUsage().then(opts.onContextUsage, (e) => {
|
||||
logger.debug('[claudeRemote] get_context_usage failed', e);
|
||||
});
|
||||
}
|
||||
|
||||
// Claude silently starts in default when plan/auto is unavailable
|
||||
// (e.g. auto disabled by settings); surface it instead of
|
||||
// showing a mode that is not in effect.
|
||||
|
||||
@@ -497,6 +497,7 @@ class ClaudeRemoteLauncher extends RemoteLauncherBase {
|
||||
claudeEnvVars: session.claudeEnvVars,
|
||||
claudeArgs: session.claudeArgs,
|
||||
onMessage,
|
||||
onContextUsage: (usage) => sdkToLogConverter.applyContextUsage(usage.model, usage.maxTokens),
|
||||
onFirstResult: (initialMessage) => {
|
||||
// SDK streams omit Claude Code's native ai-title; it is only in the transcript.
|
||||
const sessionId = session.sessionId;
|
||||
|
||||
@@ -50,6 +50,54 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('Query', () => {
|
||||
it('routes context usage and permission mode responses independently', async () => {
|
||||
const { Query } = await import('./query')
|
||||
const stdin = new PassThrough()
|
||||
const stdout = new PassThrough()
|
||||
const query = new Query(stdin, stdout, Promise.resolve())
|
||||
|
||||
const contextUsage = query.getContextUsage()
|
||||
const contextRequest = JSON.parse(stdin.read().toString())
|
||||
const permissionMode = query.setPermissionMode('auto')
|
||||
const permissionRequest = JSON.parse(stdin.read().toString())
|
||||
|
||||
expect(contextRequest.request).toEqual({ subtype: 'get_context_usage' })
|
||||
expect(permissionRequest.request).toEqual({ subtype: 'set_permission_mode', mode: 'auto' })
|
||||
|
||||
const usage = { model: 'claude-fable-5-1', maxTokens: 200_000 }
|
||||
for (const response of [
|
||||
{ subtype: 'success', request_id: permissionRequest.request_id },
|
||||
{ subtype: 'success', request_id: contextRequest.request_id, response: usage }
|
||||
]) {
|
||||
stdout.write(JSON.stringify({ type: 'control_response', response }) + '\n')
|
||||
}
|
||||
|
||||
await expect(permissionMode).resolves.toBeUndefined()
|
||||
await expect(contextUsage).resolves.toEqual(usage)
|
||||
stdout.end()
|
||||
})
|
||||
|
||||
it('rejects unsupported context usage requests without ending the message stream', async () => {
|
||||
const { Query } = await import('./query')
|
||||
const stdin = new PassThrough()
|
||||
const stdout = new PassThrough()
|
||||
const query = new Query(stdin, stdout, Promise.resolve())
|
||||
|
||||
const contextUsage = query.getContextUsage()
|
||||
const request = JSON.parse(stdin.read().toString())
|
||||
const rejected = expect(contextUsage).rejects.toThrow('Unsupported request')
|
||||
stdout.write(JSON.stringify({
|
||||
type: 'control_response',
|
||||
response: { subtype: 'error', request_id: request.request_id, error: 'Unsupported request' }
|
||||
}) + '\n')
|
||||
await rejected
|
||||
|
||||
const message = { type: 'system', subtype: 'init', model: 'claude-fable-5-1', session_id: 'test-session' }
|
||||
stdout.end(JSON.stringify(message) + '\n')
|
||||
await expect(query.next()).resolves.toEqual({ value: message, done: false })
|
||||
await expect(query.next()).resolves.toEqual({ value: undefined, done: true })
|
||||
})
|
||||
|
||||
it('preserves externally set errors even if the process exits cleanly', async () => {
|
||||
const { Query } = await import('./query')
|
||||
const stdout = new PassThrough()
|
||||
|
||||
@@ -180,6 +180,21 @@ export class Query implements AsyncIterableIterator<SDKMessage> {
|
||||
}, this.childStdin)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask Claude for the active model's effective context window (what /context shows:
|
||||
* honors CLAUDE_CODE_DISABLE_1M_CONTEXT and settings autoCompactWindow).
|
||||
*/
|
||||
async getContextUsage(): Promise<{ model?: string, maxTokens?: number }> {
|
||||
if (!this.childStdin) {
|
||||
throw new Error('getContextUsage requires --input-format stream-json')
|
||||
}
|
||||
|
||||
const response = await this.request({
|
||||
subtype: 'get_context_usage'
|
||||
}, this.childStdin) as { response?: { model?: string, maxTokens?: number } }
|
||||
return response.response ?? {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Claude's native permission mode without restarting the process
|
||||
*/
|
||||
@@ -207,6 +222,7 @@ export class Query implements AsyncIterableIterator<SDKMessage> {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pendingControlResponses.set(requestId, (response) => {
|
||||
this.pendingControlResponses.delete(requestId)
|
||||
if (response.subtype === 'success') {
|
||||
resolve(response)
|
||||
} else {
|
||||
|
||||
@@ -638,6 +638,68 @@ describe('SDKToLogConverter', () => {
|
||||
expect(turn1?.message?.usage?.context_window).toBe(1_000_000)
|
||||
})
|
||||
|
||||
it('seeds a 1M turn-1 estimate for a bare preset alias, which resolves to a native 1M model', () => {
|
||||
const seededConverter = new SDKToLogConverter({
|
||||
...context,
|
||||
selectedModel: 'fable'
|
||||
} as any)
|
||||
|
||||
seededConverter.convert({
|
||||
type: 'system',
|
||||
subtype: 'init',
|
||||
session_id: 'session-7b',
|
||||
model: 'claude-fable-5-1'
|
||||
} as SDKSystemMessage)
|
||||
|
||||
const turn1 = seededConverter.convert({
|
||||
type: 'assistant',
|
||||
message: {
|
||||
role: 'assistant',
|
||||
model: 'claude-fable-5-1',
|
||||
content: [{ type: 'text', text: 'hi' }],
|
||||
usage: { input_tokens: 10, output_tokens: 20 }
|
||||
}
|
||||
} as any) as any
|
||||
|
||||
expect(turn1?.message?.usage?.context_window).toBe(1_000_000)
|
||||
})
|
||||
|
||||
it('uses get_context_usage over the alias seed and over a later result (1M disabled / autoCompactWindow)', () => {
|
||||
const seededConverter = new SDKToLogConverter({
|
||||
...context,
|
||||
selectedModel: 'fable'
|
||||
} as any)
|
||||
|
||||
seededConverter.convert({
|
||||
type: 'system',
|
||||
subtype: 'init',
|
||||
session_id: 'session-7c',
|
||||
model: 'claude-fable-5-1'
|
||||
} as SDKSystemMessage)
|
||||
|
||||
seededConverter.applyContextUsage('claude-sonnet-5-5', 100_000)
|
||||
expect((seededConverter.convert(makeAssistantMessage()) as any)?.message?.usage?.context_window).toBe(1_000_000)
|
||||
expect(seededConverter.currentContextWindow()).toBe(1_000_000)
|
||||
|
||||
seededConverter.applyContextUsage('claude-fable-5-1', 200_000)
|
||||
expect((seededConverter.convert(makeAssistantMessage()) as any)?.message?.usage?.context_window).toBe(200_000)
|
||||
expect(seededConverter.currentContextWindow()).toBe(200_000)
|
||||
|
||||
seededConverter.convert({
|
||||
type: 'result',
|
||||
subtype: 'success',
|
||||
num_turns: 1,
|
||||
total_cost_usd: 0,
|
||||
duration_ms: 1,
|
||||
duration_api_ms: 1,
|
||||
is_error: false,
|
||||
session_id: 'session-7c',
|
||||
modelUsage: { 'claude-fable-5-1': { contextWindow: 1_000_000 } }
|
||||
} as SDKResultMessage)
|
||||
expect((seededConverter.convert(makeAssistantMessage()) as any)?.message?.usage?.context_window).toBe(200_000)
|
||||
expect(seededConverter.currentContextWindow()).toBe(200_000)
|
||||
})
|
||||
|
||||
it('seeds a conservative 200k when neither the bare init model nor a selectedModel hint indicates 1M, until result confirms it', () => {
|
||||
// Bare init model + no selectedModel hint: neither signal says "1M", so we can't
|
||||
// know the real window on turn 1 and seed 200k conservatively rather than
|
||||
@@ -740,18 +802,18 @@ describe('SDKToLogConverter', () => {
|
||||
// selectedModel and none on the bare init model). Without a live update, the
|
||||
// converter would still be seeding from the stale "fable[1m]" snapshot and
|
||||
// would over-seed 1,000,000 for the newly-selected model's first turn.
|
||||
liveConverter.updateSelectedModel('sonnet')
|
||||
liveConverter.updateSelectedModel('claude-sonnet-4-6')
|
||||
liveConverter.convert({
|
||||
type: 'system',
|
||||
subtype: 'init',
|
||||
session_id: 'session-10',
|
||||
model: 'claude-sonnet-5'
|
||||
model: 'claude-sonnet-4-6'
|
||||
} as SDKSystemMessage)
|
||||
const afterSwitch = liveConverter.convert({
|
||||
type: 'assistant',
|
||||
message: {
|
||||
role: 'assistant',
|
||||
model: 'claude-sonnet-5',
|
||||
model: 'claude-sonnet-4-6',
|
||||
content: [{ type: 'text', text: 'hi' }],
|
||||
usage: { input_tokens: 10, output_tokens: 20 }
|
||||
}
|
||||
@@ -928,9 +990,15 @@ describe('SDKToLogConverter', () => {
|
||||
} as any) as any
|
||||
expect(t1?.message?.usage?.context_window).toBe(1_000_000)
|
||||
|
||||
// Switch to plain fable (200k): must re-seed 200k, NOT keep the stale 1M.
|
||||
// Switch to plain fable and let its result report a smaller window: the
|
||||
// plain entry must take it without overwriting fable[1m]'s 1M.
|
||||
conv.updateSelectedModel('fable')
|
||||
conv.convert({ type: 'system', subtype: 'init', session_id: 's', model: 'claude-fable-5' } as SDKSystemMessage)
|
||||
conv.convert({
|
||||
type: 'result', subtype: 'success', num_turns: 1, total_cost_usd: 0,
|
||||
duration_ms: 1, duration_api_ms: 1, is_error: false, session_id: 's',
|
||||
modelUsage: { 'claude-fable-5': { contextWindow: 200_000 } }
|
||||
} as SDKResultMessage)
|
||||
const t2 = conv.convert({
|
||||
type: 'assistant',
|
||||
message: { role: 'assistant', model: 'claude-fable-5', content: [{ type: 'text', text: 'b' }], usage: { input_tokens: 10, output_tokens: 20 } }
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {
|
||||
SDKResultMessage
|
||||
} from '@/claude/sdk'
|
||||
import type { RawJSONLines } from '@/claude/types'
|
||||
import { isClaudeModelPreset } from '@hapi/protocol'
|
||||
import type { ClaudePermissionMode } from '@hapi/protocol/types'
|
||||
import { logger } from '@/lib'
|
||||
|
||||
@@ -103,6 +104,10 @@ export class SDKToLogConverter {
|
||||
// — rather than a single sticky number — means a mid-session model switch picks up the
|
||||
// new model's own window immediately instead of inheriting the previous model's.
|
||||
private modelContextWindows = new Map<string, number>()
|
||||
// Keys whose window came from Claude's get_context_usage. That value is the effective
|
||||
// window (capped by DISABLE_1M / autoCompactWindow), so a result's raw contextWindow
|
||||
// must not overwrite it.
|
||||
private contextUsageKeys = new Set<string>()
|
||||
|
||||
constructor(
|
||||
context: Omit<ConversionContext, 'parentUuid'>,
|
||||
@@ -150,6 +155,21 @@ export class SDKToLogConverter {
|
||||
this.context.selectedModel = model ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Claude's get_context_usage answer for the current session model.
|
||||
*/
|
||||
applyContextUsage(model: string | undefined, maxTokens: number | undefined): void {
|
||||
const key = this.resolvedContextWindowKey
|
||||
if (!key || !this.resolvedModel || !model || typeof maxTokens !== 'number' || maxTokens <= 0) {
|
||||
return
|
||||
}
|
||||
if (this.resolvedModel.replace(/\[1m\]$/, '') !== model.replace(/\[1m\]$/, '')) {
|
||||
return
|
||||
}
|
||||
this.modelContextWindows.set(key, maxTokens)
|
||||
this.contextUsageKeys.add(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* The contextWindow currently resolved for this session's model — the
|
||||
* same value `convert()` stamps onto relayed assistant usage. Undefined
|
||||
@@ -387,7 +407,10 @@ export class SDKToLogConverter {
|
||||
// first result lands. Guarding/seeding on resolvedContextWindowKey
|
||||
// (not the bare init id) is what forces a re-seed when switching
|
||||
// fable[1m] <-> fable, whose bare ids would otherwise be identical.
|
||||
// The bare preset aliases (opus/fable/sonnet/haiku) now resolve to models
|
||||
// with a native 1M window, so selecting one seeds 1M as well.
|
||||
const seedIs1m = (this.context.selectedModel?.endsWith('[1m]') ?? false)
|
||||
|| isClaudeModelPreset(this.context.selectedModel)
|
||||
|| systemMsg.model.endsWith('[1m]')
|
||||
this.modelContextWindows.set(this.resolvedContextWindowKey, seedIs1m ? 1_000_000 : 200_000)
|
||||
}
|
||||
@@ -425,7 +448,9 @@ export class SDKToLogConverter {
|
||||
const key = (this.resolvedModel && model === this.resolvedModel)
|
||||
? (this.resolvedContextWindowKey ?? model)
|
||||
: model
|
||||
this.modelContextWindows.set(key, cw)
|
||||
if (!this.contextUsageKeys.has(key)) {
|
||||
this.modelContextWindows.set(key, cw)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,17 @@ import Foundation
|
||||
public enum ClaudeModels {
|
||||
/// Preset ids in declaration (picker) order.
|
||||
public static let presets: [String] = [
|
||||
"sonnet",
|
||||
"sonnet[1m]",
|
||||
"opus",
|
||||
"opus[1m]",
|
||||
"fable",
|
||||
"fable[1m]",
|
||||
"sonnet",
|
||||
"haiku",
|
||||
]
|
||||
|
||||
private static let labels: [String: String] = [
|
||||
"sonnet": "Sonnet",
|
||||
"sonnet[1m]": "Sonnet 1M",
|
||||
"opus": "Opus",
|
||||
"opus[1m]": "Opus 1M",
|
||||
"fable": "Fable",
|
||||
"fable[1m]": "Fable 1M",
|
||||
"sonnet": "Sonnet",
|
||||
"haiku": "Haiku",
|
||||
]
|
||||
|
||||
/// `getClaudeModelLabel`: trimmed lookup; unknown/blank → nil.
|
||||
|
||||
@@ -246,12 +246,10 @@ struct CatalogTests {
|
||||
@Test func newSessionCatalogsMatchTheWebOptionLists() {
|
||||
#expect(NewSessionCatalogs.claudeModels == [
|
||||
NewSessionOption(value: "auto", label: "Default"),
|
||||
NewSessionOption(value: "sonnet", label: "Sonnet"),
|
||||
NewSessionOption(value: "sonnet[1m]", label: "Sonnet 1M"),
|
||||
NewSessionOption(value: "opus", label: "Opus"),
|
||||
NewSessionOption(value: "opus[1m]", label: "Opus 1M"),
|
||||
NewSessionOption(value: "fable", label: "Fable"),
|
||||
NewSessionOption(value: "fable[1m]", label: "Fable 1M"),
|
||||
NewSessionOption(value: "sonnet", label: "Sonnet"),
|
||||
NewSessionOption(value: "haiku", label: "Haiku"),
|
||||
])
|
||||
#expect(NewSessionCatalogs.claudeEfforts == [
|
||||
NewSessionOption(value: "auto", label: "Auto"),
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('isClaudeModelPreset', () => {
|
||||
})
|
||||
|
||||
test('rejects unknown model string', () => {
|
||||
expect(isClaudeModelPreset('haiku')).toBe(false)
|
||||
expect(isClaudeModelPreset('claude-haiku-4-5')).toBe(false)
|
||||
})
|
||||
|
||||
test('rejects null and undefined', () => {
|
||||
@@ -34,7 +34,7 @@ describe('getClaudeModelLabel', () => {
|
||||
test('returns label for known presets', () => {
|
||||
expect(getClaudeModelLabel('sonnet')).toBe('Sonnet')
|
||||
expect(getClaudeModelLabel('opus')).toBe('Opus')
|
||||
expect(getClaudeModelLabel('opus[1m]')).toBe('Opus 1M')
|
||||
expect(getClaudeModelLabel('opus[1m]')).toBeNull()
|
||||
})
|
||||
|
||||
test('trims whitespace before lookup', () => {
|
||||
@@ -42,7 +42,7 @@ describe('getClaudeModelLabel', () => {
|
||||
})
|
||||
|
||||
test('returns null for unknown model', () => {
|
||||
expect(getClaudeModelLabel('haiku')).toBeNull()
|
||||
expect(getClaudeModelLabel('claude-haiku-4-5')).toBeNull()
|
||||
})
|
||||
|
||||
test('returns null for empty/whitespace-only string', () => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { ClaudeModelSummary } from './apiTypes'
|
||||
|
||||
// Fallback aliases in Claude Code's /model order, used until its live catalog
|
||||
// arrives. Each resolves to the newest model of its family.
|
||||
export const CLAUDE_MODEL_LABELS = {
|
||||
sonnet: 'Sonnet',
|
||||
'sonnet[1m]': 'Sonnet 1M',
|
||||
opus: 'Opus',
|
||||
'opus[1m]': 'Opus 1M',
|
||||
fable: 'Fable',
|
||||
'fable[1m]': 'Fable 1M'
|
||||
sonnet: 'Sonnet',
|
||||
haiku: 'Haiku'
|
||||
} as const
|
||||
|
||||
export type ClaudeModelPreset = keyof typeof CLAUDE_MODEL_LABELS
|
||||
|
||||
@@ -2,8 +2,15 @@ import { describe, expect, it } from 'vitest'
|
||||
import { getContextBudgetTokens } from './modelConfig'
|
||||
|
||||
describe('getContextBudgetTokens', () => {
|
||||
it('uses the large budget only for explicit 1m Claude presets', () => {
|
||||
it('keeps the large budget for sessions stored with a [1m] alias', () => {
|
||||
expect(getContextBudgetTokens('sonnet[1m]', 'claude')).toBe(990_000)
|
||||
expect(getContextBudgetTokens('opus[1m]', 'claude')).toBe(990_000)
|
||||
})
|
||||
|
||||
it('uses the large budget for the aliases, which now resolve to native 1M models', () => {
|
||||
expect(getContextBudgetTokens('opus', 'claude')).toBe(990_000)
|
||||
expect(getContextBudgetTokens('sonnet', 'claude')).toBe(990_000)
|
||||
expect(getContextBudgetTokens('haiku', 'claude')).toBe(990_000)
|
||||
})
|
||||
|
||||
it('uses the default Claude budget for full Claude model names', () => {
|
||||
|
||||
@@ -74,16 +74,17 @@ export function getContextBudgetTokens(model: string | null | undefined, flavor?
|
||||
if (!trimmedModel) {
|
||||
return DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS
|
||||
}
|
||||
if (isClaudeModelPreset(trimmedModel) || trimmedModel.startsWith('claude-')) {
|
||||
// Fable ships with a 1M window even under its bare id: the SDK
|
||||
// result message reports modelUsage["claude-fable-5"].contextWindow
|
||||
// = 1,000,000, so the "[1m]" suffix check alone would undercount
|
||||
// local-mode sessions (their transcript usage carries no
|
||||
// context_window and falls through to this heuristic).
|
||||
const isFable = trimmedModel === 'fable'
|
||||
|| trimmedModel === 'fable[1m]'
|
||||
if (isClaudeModelPreset(trimmedModel) || trimmedModel.startsWith('claude-') || trimmedModel.endsWith('[1m]')) {
|
||||
// The preset aliases (opus/fable/sonnet/haiku) resolve to models with a
|
||||
// native 1M window, and Fable ships 1M even under its bare id (the
|
||||
// SDK result reports modelUsage["claude-fable-5"].contextWindow =
|
||||
// 1,000,000). Local-mode transcript usage carries no
|
||||
// context_window and falls through to this heuristic, so the
|
||||
// "[1m]" suffix check alone would undercount them.
|
||||
const isLarge = isClaudeModelPreset(trimmedModel)
|
||||
|| trimmedModel.endsWith('[1m]')
|
||||
|| trimmedModel.startsWith('claude-fable')
|
||||
return trimmedModel.endsWith('[1m]') || isFable
|
||||
return isLarge
|
||||
? LARGE_CLAUDE_CONTEXT_WINDOW_TOKENS
|
||||
: DEFAULT_CLAUDE_CONTEXT_WINDOW_TOKENS
|
||||
}
|
||||
|
||||
@@ -6,30 +6,26 @@ describe('getClaudeComposerModelOptions', () => {
|
||||
expect(getClaudeComposerModelOptions('claude-opus-4-1-20250805')).toEqual([
|
||||
{ value: null, label: 'Default' },
|
||||
{ value: 'claude-opus-4-1-20250805', label: 'claude-opus-4-1-20250805' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'sonnet[1m]', label: 'Sonnet 1M' },
|
||||
{ value: 'opus', label: 'Opus' },
|
||||
{ value: 'opus[1m]', label: 'Opus 1M' },
|
||||
{ value: 'fable', label: 'Fable' },
|
||||
{ value: 'fable[1m]', label: 'Fable 1M' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'haiku', label: 'Haiku' },
|
||||
])
|
||||
})
|
||||
|
||||
it('does not duplicate preset Claude models', () => {
|
||||
expect(getClaudeComposerModelOptions('opus')).toEqual([
|
||||
{ value: null, label: 'Default' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'sonnet[1m]', label: 'Sonnet 1M' },
|
||||
{ value: 'opus', label: 'Opus' },
|
||||
{ value: 'opus[1m]', label: 'Opus 1M' },
|
||||
{ value: 'fable', label: 'Fable' },
|
||||
{ value: 'fable[1m]', label: 'Fable 1M' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'haiku', label: 'Haiku' },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('getNextClaudeComposerModel', () => {
|
||||
it('cycles from a non-preset Claude model to the next selectable model instead of auto', () => {
|
||||
expect(getNextClaudeComposerModel('claude-opus-4-1-20250805')).toBe('sonnet')
|
||||
expect(getNextClaudeComposerModel('claude-opus-4-1-20250805')).toBe('opus')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -59,9 +59,13 @@ describe('getModelOptionsForFlavor', () => {
|
||||
|
||||
it('returns Claude model options for claude flavor', () => {
|
||||
const options = getModelOptionsForFlavor('claude')
|
||||
expect(options[0]).toEqual({ value: null, label: 'Default' })
|
||||
expect(options.some((o) => o.value === 'sonnet')).toBe(true)
|
||||
expect(options.some((o) => o.value === 'opus')).toBe(true)
|
||||
expect(options).toEqual([
|
||||
{ value: null, label: 'Default' },
|
||||
{ value: 'opus', label: 'Opus' },
|
||||
{ value: 'fable', label: 'Fable' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'haiku', label: 'Haiku' },
|
||||
])
|
||||
})
|
||||
|
||||
it('uses the Claude catalog as the whole list, as the CLI picker shows it', () => {
|
||||
@@ -104,13 +108,13 @@ describe('getModelOptionsForFlavor', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps a saved built-in alias the catalog does not list as the current model', () => {
|
||||
it('keeps a saved 1M alias the catalog does not list as the current model', () => {
|
||||
const options = getModelOptionsForFlavor('claude', 'opus[1m]', [
|
||||
{ value: 'opus', label: 'Opus 5.5' },
|
||||
])
|
||||
expect(options).toEqual([
|
||||
{ value: null, label: 'Default' },
|
||||
{ value: 'opus[1m]', label: 'Opus 1M' },
|
||||
{ value: 'opus[1m]', label: 'opus[1m]' },
|
||||
{ value: 'opus', label: 'Opus 5.5' },
|
||||
])
|
||||
})
|
||||
@@ -294,9 +298,9 @@ describe('getClaudeLaunchModelOptions', () => {
|
||||
expect(options[1]).toEqual({ value: 'claude-opus-4-1', label: 'claude-opus-4-1 (no longer listed)' })
|
||||
})
|
||||
|
||||
it('marks a saved built-in alias the catalog no longer lists, like any other model', () => {
|
||||
it('marks a saved 1M alias the catalog no longer lists, like any other model', () => {
|
||||
const options = getClaudeLaunchModelOptions(catalog, 'opus[1m]', 'no longer listed', 'Other models')
|
||||
expect(options[1]).toEqual({ value: 'opus[1m]', label: 'Opus 1M (no longer listed)' })
|
||||
expect(options[1]).toEqual({ value: 'opus[1m]', label: 'opus[1m] (no longer listed)' })
|
||||
})
|
||||
|
||||
it('keeps a saved model selectable before the catalog arrives, without claiming it is gone', () => {
|
||||
@@ -304,7 +308,7 @@ describe('getClaudeLaunchModelOptions', () => {
|
||||
expect(options.slice(0, 3)).toEqual([
|
||||
{ value: 'auto', label: 'Default' },
|
||||
{ value: 'claude-opus-4-1', label: 'claude-opus-4-1' },
|
||||
{ value: 'sonnet', label: 'Sonnet' },
|
||||
{ value: 'opus', label: 'Opus' },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,10 +14,8 @@ describe('Claude model options', () => {
|
||||
})
|
||||
|
||||
it('exposes friendly labels for Claude model presets', () => {
|
||||
expect(CLAUDE_MODEL_PRESETS).toEqual(['sonnet', 'sonnet[1m]', 'opus', 'opus[1m]', 'fable', 'fable[1m]'])
|
||||
expect(getClaudeModelLabel('sonnet[1m]')).toBe('Sonnet 1M')
|
||||
expect(getClaudeModelLabel('opus[1m]')).toBe('Opus 1M')
|
||||
expect(getClaudeModelLabel('fable[1m]')).toBe('Fable 1M')
|
||||
expect(CLAUDE_MODEL_PRESETS).toEqual(['opus', 'fable', 'sonnet', 'haiku'])
|
||||
expect(getClaudeModelLabel('haiku')).toBe('Haiku')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ describe('getToolTimingDetails', () => {
|
||||
describe('formatSubagentModelLabel', () => {
|
||||
it('uses getClaudeModelLabel for a preset alias', () => {
|
||||
expect(formatSubagentModelLabel('opus')).toBe('Opus')
|
||||
expect(formatSubagentModelLabel('sonnet[1m]')).toBe('Sonnet 1M')
|
||||
expect(formatSubagentModelLabel('fable')).toBe('Fable')
|
||||
})
|
||||
|
||||
it('extracts name + version from a full SDK model id, dropping the date suffix', () => {
|
||||
|
||||
Reference in New Issue
Block a user