mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 14: Phase 14: Model view models use ModelInfo field names
This commit is contained in:
1 parent
2d4abe79e1
commit
fbc3e02208
15 files changed
+49
-62
No files matched your search
@@ -87,8 +87,8 @@ describe('getProviders', () => {
|
||||
expect(result.providers[0]).toMatchObject({ id: 'anthropic', name: 'Anthropic' })
|
||||
expect(result.providers[0].models).toHaveLength(1)
|
||||
expect(result.providers[0].models[0]).toMatchObject({
|
||||
key: 'claude-sonnet-4',
|
||||
id: 'claude-sonnet-4-20250514',
|
||||
id: 'claude-sonnet-4',
|
||||
modelID: 'claude-sonnet-4-20250514',
|
||||
name: 'Claude Sonnet 4',
|
||||
limit: { context: 200000, output: 64000 },
|
||||
released: Date.UTC(2025, 4, 22),
|
||||
@@ -132,7 +132,7 @@ describe('getProviders', () => {
|
||||
const result = await getProviders('/repo')
|
||||
|
||||
expect(result.providers.map((provider) => provider.id)).toEqual(['anthropic'])
|
||||
expect(result.providers[0].models.map((model) => model.key)).toEqual(['claude-sonnet-4'])
|
||||
expect(result.providers[0].models.map((model) => model.id)).toEqual(['claude-sonnet-4'])
|
||||
})
|
||||
|
||||
it('sorts providers and models in the TUI order', async () => {
|
||||
@@ -288,14 +288,8 @@ describe('saveOpenCodeModelVariant', () => {
|
||||
})
|
||||
|
||||
describe('providerModelRef', () => {
|
||||
it('prefers the catalog key over the backing model id', () => {
|
||||
expect(providerModelRef({ id: 'anthropic' }, { id: 'claude-sonnet-4-20250514', key: 'claude-sonnet-4' })).toBe(
|
||||
'anthropic/claude-sonnet-4'
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to the model id when no key is present', () => {
|
||||
expect(providerModelRef({ id: 'openai' }, { id: 'gpt-4o' })).toBe('openai/gpt-4o')
|
||||
it('formats the provider and catalog model id as an OpenCode model ref', () => {
|
||||
expect(providerModelRef({ id: 'anthropic' }, { id: 'claude-sonnet-4' })).toBe('anthropic/claude-sonnet-4')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -18,17 +18,14 @@ import {
|
||||
} from "@opencode-manager/shared/opencode";
|
||||
import type { CredentialListResponse, CredentialStatusResponse } from "@opencode-manager/shared/schemas";
|
||||
|
||||
export interface Model {
|
||||
id: string;
|
||||
key?: string;
|
||||
name: string;
|
||||
export type Model = Pick<ModelInfo, 'id' | 'modelID' | 'name'> & {
|
||||
limit?: {
|
||||
context: number;
|
||||
output: number;
|
||||
};
|
||||
released: number;
|
||||
free: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export interface Provider {
|
||||
id: string;
|
||||
@@ -47,8 +44,8 @@ export type OpenCodeModelState = ModelPreference
|
||||
|
||||
function mapModelInfo(model: ModelInfo): Model {
|
||||
return {
|
||||
id: model.modelID,
|
||||
key: model.id,
|
||||
id: model.id,
|
||||
modelID: model.modelID,
|
||||
name: model.name,
|
||||
limit: {
|
||||
context: model.limit.context,
|
||||
@@ -167,11 +164,11 @@ export async function toggleOpenCodeFavoriteModel(model: ModelSelection): Promis
|
||||
}
|
||||
|
||||
export function formatModelName(model: Model): string {
|
||||
return model.name || model.id;
|
||||
return model.name || model.modelID;
|
||||
}
|
||||
|
||||
export function providerModelRef(provider: { id: string }, model: { id: string; key?: string }): string {
|
||||
return formatOpenCodeModelRef({ providerID: provider.id, id: model.key ?? model.id });
|
||||
export function providerModelRef(provider: { id: string }, model: { id: string }): string {
|
||||
return formatOpenCodeModelRef({ providerID: provider.id, id: model.id });
|
||||
}
|
||||
|
||||
export function modelSelectionRef(model: ModelSelection): string {
|
||||
|
||||
Reference in new issue
Block a user