Indeed processing the stream fully and queuing up the function calls does the job, thank you!
The code below does the job:
let functionCalls: ResponseFunctionToolCall[] = [];
do {
// Process text messages.
({ assistantMessage, functionCalls } =
await this.streamResponse(input, {
assistantMessage,
conversation,
toolChoice: this.getToolChoice(someData),
tools,
user,
}));
// Process function calls.
input = [];
for (const functionCall of functionCalls) {
const res = await this.processFunctionCall(tarotReading, functionCall);
someData = res.someData;
input = [...input, ...res.input];
}
} while (functionCalls.length);