fix: generate fallback tool call IDs for providers missing id field

pull/12585/head
T1mn 2026-02-07 14:55:06 +08:00
parent 4abf8049c9
commit e73b137452
1 changed files with 11 additions and 3 deletions

View File

@ -517,13 +517,21 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV2 {
const index = toolCallDelta.index
if (toolCalls[index] == null) {
if (toolCallDelta.id == null) {
// Providers known to not send tool call IDs (see https://github.com/anomalyco/opencode/issues/6290)
const providersMissingToolCallId = ["nvidia", "glm", "bedrock", "chutes"]
const shouldGenerateFallbackId = providersMissingToolCallId.some((p) =>
providerOptionsName.toLowerCase().includes(p),
)
if (toolCallDelta.id == null && !shouldGenerateFallbackId) {
throw new InvalidResponseDataError({
data: toolCallDelta,
message: `Expected 'id' to be a string.`,
})
}
const toolCallId = toolCallDelta.id ?? generateId()
if (toolCallDelta.function?.name == null) {
throw new InvalidResponseDataError({
data: toolCallDelta,
@ -533,12 +541,12 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV2 {
controller.enqueue({
type: "tool-input-start",
id: toolCallDelta.id,
id: toolCallId,
toolName: toolCallDelta.function.name,
})
toolCalls[index] = {
id: toolCallDelta.id,
id: toolCallId,
type: "function",
function: {
name: toolCallDelta.function.name,