Description
const { messages, sendMessage, addToolApprovalResponse } = useChat({
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses, // will be turned off later (see below)
})
const model = 'gpt-4o'
// I'm sending model info to backend
sendMessage({ text: 'hey' }, { body: { model }})
// ...later, on approval
// seems like `addToolApprovalResponse` on `sendAutomaticallyWhen` doesn't send `body` like sendMessage does
addToolApprovalResponse({ id, approved: true })
// so as a workaround, I turned off `sendAutomaticalyWhen` and sendMessage manually after addToolApprovalResponse
sendMessage(undefined, { body: { model }})
Why this happens?
packages\ai\src\ui\chat.ts > AbstractChat > sendMessage executes makeRequest with options which has .body in it
await this.makeRequest({
trigger: 'submit-message',
messageId: message.messageId,
...options,
});
but AbstractChat > addToolApprovalResponse does not.
// automatically send the message if the sendAutomaticallyWhen function returns true
if (
this.status !== 'streaming' &&
this.status !== 'submitted' &&
this.sendAutomaticallyWhen?.({ messages: this.state.messages })
) {
// no await to avoid deadlocking
this.makeRequest({
trigger: 'submit-message',
messageId: this.lastMessage?.id,
// no options here! <-
});
}
Idea
You can keep previous body in AbstractChat.body property?
Related
AI SDK Version
"ai": "^6.0.0-beta.151",
Code of Conduct
Description
Why this happens?
packages\ai\src\ui\chat.ts > AbstractChat > sendMessageexecutesmakeRequestwith options which has .body in itbut
AbstractChat > addToolApprovalResponsedoes not.Idea
You can keep previous body in AbstractChat.body property?
Related
addToolApprovalResponseandaddToolOutput#11048 - make it possible to pass body to addToolApprovalResponsesendMessage({text:""})as a workaroundsendMessage()reports 'TypeError: Cannot read properties of undefined (reading 'state')' #11024 - withaddToolOutputCannot read properties of undefined (reading 'startsWith')- happens when failed to pass model toToolLoopAgenton backendAI SDK Version
"ai": "^6.0.0-beta.151",
Code of Conduct