dedupe fix
This commit is contained in:
parent
093acd4062
commit
b0725ed597
1 changed files with 55 additions and 17 deletions
|
|
@ -412,16 +412,35 @@ function ChatPage() {
|
||||||
// Handle Realtime API format (this is what you're actually getting!)
|
// Handle Realtime API format (this is what you're actually getting!)
|
||||||
else if (chunk.type === "response.output_item.added" && chunk.item?.type === "function_call") {
|
else if (chunk.type === "response.output_item.added" && chunk.item?.type === "function_call") {
|
||||||
console.log("🟢 CREATING function call (added):", chunk.item.id, chunk.item.tool_name || chunk.item.name)
|
console.log("🟢 CREATING function call (added):", chunk.item.id, chunk.item.tool_name || chunk.item.name)
|
||||||
const functionCall: FunctionCall = {
|
|
||||||
name: chunk.item.tool_name || chunk.item.name || "unknown",
|
// Try to find an existing pending call to update (created by earlier deltas)
|
||||||
arguments: chunk.item.inputs || undefined,
|
let existing = currentFunctionCalls.find(fc => fc.id === chunk.item.id)
|
||||||
status: "pending",
|
if (!existing) {
|
||||||
argumentsString: "",
|
existing = [...currentFunctionCalls].reverse().find(fc =>
|
||||||
id: chunk.item.id,
|
fc.status === "pending" &&
|
||||||
type: chunk.item.type
|
!fc.id &&
|
||||||
|
(fc.name === (chunk.item.tool_name || chunk.item.name))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.id = chunk.item.id
|
||||||
|
existing.type = chunk.item.type
|
||||||
|
existing.name = chunk.item.tool_name || chunk.item.name || existing.name
|
||||||
|
existing.arguments = chunk.item.inputs || existing.arguments
|
||||||
|
console.log("🟢 UPDATED existing pending function call with id:", existing.id)
|
||||||
|
} else {
|
||||||
|
const functionCall: FunctionCall = {
|
||||||
|
name: chunk.item.tool_name || chunk.item.name || "unknown",
|
||||||
|
arguments: chunk.item.inputs || undefined,
|
||||||
|
status: "pending",
|
||||||
|
argumentsString: "",
|
||||||
|
id: chunk.item.id,
|
||||||
|
type: chunk.item.type
|
||||||
|
}
|
||||||
|
currentFunctionCalls.push(functionCall)
|
||||||
|
console.log("🟢 Function calls now:", currentFunctionCalls.map(fc => ({ id: fc.id, name: fc.name })))
|
||||||
}
|
}
|
||||||
currentFunctionCalls.push(functionCall)
|
|
||||||
console.log("🟢 Function calls now:", currentFunctionCalls.map(fc => ({ id: fc.id, name: fc.name })))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle function call arguments streaming (Realtime API)
|
// Handle function call arguments streaming (Realtime API)
|
||||||
|
|
@ -525,15 +544,34 @@ function ChatPage() {
|
||||||
// Handle function call output item added (new format)
|
// Handle function call output item added (new format)
|
||||||
else if (chunk.type === "response.output_item.added" && chunk.item?.type?.includes("_call") && chunk.item?.type !== "function_call") {
|
else if (chunk.type === "response.output_item.added" && chunk.item?.type?.includes("_call") && chunk.item?.type !== "function_call") {
|
||||||
console.log("🟡 CREATING tool call (added):", chunk.item.id, chunk.item.tool_name || chunk.item.name, chunk.item.type)
|
console.log("🟡 CREATING tool call (added):", chunk.item.id, chunk.item.tool_name || chunk.item.name, chunk.item.type)
|
||||||
const functionCall = {
|
|
||||||
name: chunk.item.tool_name || chunk.item.name || chunk.item.type || "unknown",
|
// Dedupe by id or pending with same name
|
||||||
arguments: chunk.item.inputs || {},
|
let existing = currentFunctionCalls.find(fc => fc.id === chunk.item.id)
|
||||||
status: "pending" as const,
|
if (!existing) {
|
||||||
id: chunk.item.id,
|
existing = [...currentFunctionCalls].reverse().find(fc =>
|
||||||
type: chunk.item.type
|
fc.status === "pending" &&
|
||||||
|
!fc.id &&
|
||||||
|
(fc.name === (chunk.item.tool_name || chunk.item.name || chunk.item.type))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.id = chunk.item.id
|
||||||
|
existing.type = chunk.item.type
|
||||||
|
existing.name = chunk.item.tool_name || chunk.item.name || chunk.item.type || existing.name
|
||||||
|
existing.arguments = chunk.item.inputs || existing.arguments
|
||||||
|
console.log("🟡 UPDATED existing pending tool call with id:", existing.id)
|
||||||
|
} else {
|
||||||
|
const functionCall = {
|
||||||
|
name: chunk.item.tool_name || chunk.item.name || chunk.item.type || "unknown",
|
||||||
|
arguments: chunk.item.inputs || {},
|
||||||
|
status: "pending" as const,
|
||||||
|
id: chunk.item.id,
|
||||||
|
type: chunk.item.type
|
||||||
|
}
|
||||||
|
currentFunctionCalls.push(functionCall)
|
||||||
|
console.log("🟡 Function calls now:", currentFunctionCalls.map(fc => ({ id: fc.id, name: fc.name, type: fc.type })))
|
||||||
}
|
}
|
||||||
currentFunctionCalls.push(functionCall)
|
|
||||||
console.log("🟡 Function calls now:", currentFunctionCalls.map(fc => ({ id: fc.id, name: fc.name, type: fc.type })))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle function call results
|
// Handle function call results
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue