fix: add defensive checks for missing model cost and capabilities fields (#855)
OpenCode v1.3.13 may omit cost and capabilities from provider model config responses. The deriveModelMetadata function accessed these fields without optional chaining, causing a TypeError that crashes the chat interface.
This commit is contained in:
@@ -234,7 +234,8 @@ const buildModelMetadataKey = (providerId: string, modelId: string) => {
|
||||
return `${normalizedProvider}/${modelId}`;
|
||||
};
|
||||
|
||||
const mapModalities = (cap: { text: boolean; audio: boolean; image: boolean; video: boolean; pdf: boolean }): string[] => {
|
||||
const mapModalities = (cap: { text: boolean; audio: boolean; image: boolean; video: boolean; pdf: boolean } | undefined): string[] => {
|
||||
if (!cap) return [];
|
||||
const result: string[] = [];
|
||||
if (cap.text) result.push('text');
|
||||
if (cap.audio) result.push('audio');
|
||||
@@ -248,20 +249,20 @@ const deriveModelMetadata = (providerId: string, model: ProviderModel): ModelMet
|
||||
id: model.id,
|
||||
providerId,
|
||||
name: model.name,
|
||||
tool_call: model.capabilities.toolcall,
|
||||
reasoning: model.capabilities.reasoning,
|
||||
temperature: model.capabilities.temperature,
|
||||
attachment: model.capabilities.attachment,
|
||||
modalities: {
|
||||
tool_call: model.capabilities?.toolcall,
|
||||
reasoning: model.capabilities?.reasoning,
|
||||
temperature: model.capabilities?.temperature,
|
||||
attachment: model.capabilities?.attachment,
|
||||
modalities: model.capabilities ? {
|
||||
input: mapModalities(model.capabilities.input),
|
||||
output: mapModalities(model.capabilities.output),
|
||||
},
|
||||
cost: {
|
||||
} : undefined,
|
||||
cost: model.cost ? {
|
||||
input: model.cost.input,
|
||||
output: model.cost.output,
|
||||
cache_read: model.cost.cache.read,
|
||||
cache_write: model.cost.cache.write,
|
||||
},
|
||||
cache_read: model.cost.cache?.read,
|
||||
cache_write: model.cost.cache?.write,
|
||||
} : undefined,
|
||||
limit: model.limit,
|
||||
release_date: model.release_date,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user