11import {
22 type ClaudeSettings ,
33 type ModelCapabilities ,
4- type ServerProviderModel ,
54 type ServerProviderSlashCommand ,
65 type ServerProviderResetCredits ,
76} from "@t3tools/contracts" ;
@@ -13,7 +12,7 @@ import * as Path from "effect/Path";
1312import * as Ref from "effect/Ref" ;
1413import * as Result from "effect/Result" ;
1514import { ChildProcess , ChildProcessSpawner } from "effect/unstable/process" ;
16- import { createModelCapabilities , readCustomModelEntries } from "@t3tools/shared/model" ;
15+ import { createModelCapabilities } from "@t3tools/shared/model" ;
1716import { resolveSpawnCommand } from "@t3tools/shared/shell" ;
1817import {
1918 query as claudeQuery ,
@@ -49,6 +48,7 @@ import {
4948 type ClaudeModelCatalog ,
5049 formatClaudeVersionUpgradeMessage ,
5150 resolveClaudeModelsForVersion ,
51+ withClaudeReportedModels ,
5252} from "../ClaudeModelCatalog.ts" ;
5353
5454const DEFAULT_CLAUDE_MODEL_CAPABILITIES : ModelCapabilities = createModelCapabilities ( {
@@ -311,53 +311,6 @@ function dedupeSlashCommands(
311311 return [ ...commandsByName . values ( ) ] ;
312312}
313313
314- /** Strip Claude Code's context-window suffix, e.g. `opus[1m]` -> `opus`. */
315- function stripClaudeModelSuffix ( value : string ) : string {
316- return value . replace ( / \[ [ ^ \] ] * \] $ / , "" ) . trim ( ) ;
317- }
318-
319- /**
320- * Append models Claude Code reports that the bundled catalog does not know,
321- * such as ids from an Anthropic-compatible gateway with model discovery on.
322- * Catalog models, including ones the installed version cannot run, are never
323- * duplicated and keep T3's descriptors. A custom model with the same slug keeps
324- * its settings-owned row. Discovered ids carry no capabilities
325- * because the adapter resolves options from the catalog only, and are passed
326- * through to Claude Code verbatim at runtime.
327- */
328- function mergeClaudeReportedModels (
329- models : ReadonlyArray < ServerProviderModel > ,
330- modelCatalog : ClaudeModelCatalog ,
331- customModels : ClaudeSettings [ "customModels" ] ,
332- reportedModels : ReadonlyArray < ClaudeModelInfo > | undefined ,
333- ) : ReadonlyArray < ServerProviderModel > {
334- if ( ! reportedModels ?. length ) return models ;
335- const known = new Set < string > ( ) ;
336- for ( const { model } of modelCatalog . models ) {
337- known . add ( model . slug . toLowerCase ( ) ) ;
338- for ( const alias of model . aliases ?? [ ] ) known . add ( alias . toLowerCase ( ) ) ;
339- }
340- for ( const entry of readCustomModelEntries ( customModels ) ) known . add ( entry . slug . toLowerCase ( ) ) ;
341- const discovered : Array < ServerProviderModel > = [ ] ;
342- for ( const info of reportedModels ) {
343- const slug = info . value . trim ( ) ;
344- // `default` is Claude Code's pointer at its own default model, not a model.
345- if ( ! slug || slug === "default" ) continue ;
346- const ids = [ slug , info . resolvedModel ?? "" ] . map ( ( id ) =>
347- stripClaudeModelSuffix ( id ) . toLowerCase ( ) ,
348- ) ;
349- if ( ids . some ( ( id ) => id && known . has ( id ) ) ) continue ;
350- known . add ( slug . toLowerCase ( ) ) ;
351- discovered . push ( {
352- slug,
353- name : info . displayName . trim ( ) || slug ,
354- isCustom : false ,
355- capabilities : DEFAULT_CLAUDE_MODEL_CAPABILITIES ,
356- } ) ;
357- }
358- return discovered . length ? [ ...models , ...discovered ] : models ;
359- }
360-
361314function waitForAbortSignal ( signal : AbortSignal ) : Promise < void > {
362315 if ( signal . aborted ) {
363316 return Promise . resolve ( ) ;
@@ -584,11 +537,9 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
584537 ? yield * resolveCapabilities ( claudeSettings ) . pipe ( Effect . orElseSucceed ( ( ) => undefined ) )
585538 : undefined ;
586539 const models = providerModelsFromSettings (
587- mergeClaudeReportedModels (
588- resolveClaudeModelsForVersion ( modelCatalog , parsedVersion ) ,
589- modelCatalog ,
590- claudeSettings . customModels ,
591- capabilities ?. models ,
540+ resolveClaudeModelsForVersion (
541+ withClaudeReportedModels ( modelCatalog , claudeSettings . customModels , capabilities ?. models ) ,
542+ parsedVersion ,
592543 ) ,
593544 claudeSettings . customModels ,
594545 DEFAULT_CLAUDE_MODEL_CAPABILITIES ,
0 commit comments