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}`;
|
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[] = [];
|
const result: string[] = [];
|
||||||
if (cap.text) result.push('text');
|
if (cap.text) result.push('text');
|
||||||
if (cap.audio) result.push('audio');
|
if (cap.audio) result.push('audio');
|
||||||
@@ -248,20 +249,20 @@ const deriveModelMetadata = (providerId: string, model: ProviderModel): ModelMet
|
|||||||
id: model.id,
|
id: model.id,
|
||||||
providerId,
|
providerId,
|
||||||
name: model.name,
|
name: model.name,
|
||||||
tool_call: model.capabilities.toolcall,
|
tool_call: model.capabilities?.toolcall,
|
||||||
reasoning: model.capabilities.reasoning,
|
reasoning: model.capabilities?.reasoning,
|
||||||
temperature: model.capabilities.temperature,
|
temperature: model.capabilities?.temperature,
|
||||||
attachment: model.capabilities.attachment,
|
attachment: model.capabilities?.attachment,
|
||||||
modalities: {
|
modalities: model.capabilities ? {
|
||||||
input: mapModalities(model.capabilities.input),
|
input: mapModalities(model.capabilities.input),
|
||||||
output: mapModalities(model.capabilities.output),
|
output: mapModalities(model.capabilities.output),
|
||||||
},
|
} : undefined,
|
||||||
cost: {
|
cost: model.cost ? {
|
||||||
input: model.cost.input,
|
input: model.cost.input,
|
||||||
output: model.cost.output,
|
output: model.cost.output,
|
||||||
cache_read: model.cost.cache.read,
|
cache_read: model.cost.cache?.read,
|
||||||
cache_write: model.cost.cache.write,
|
cache_write: model.cost.cache?.write,
|
||||||
},
|
} : undefined,
|
||||||
limit: model.limit,
|
limit: model.limit,
|
||||||
release_date: model.release_date,
|
release_date: model.release_date,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user