addToolResult fails to update parallel client tool call results

The `useChat` hook exports an [`addToolResult`](https://github.com/vercel/ai/blob/825ace6919ec32907b24a194459790d51c12c115/packages/react/src/use-chat.ts#L544)  function to update client-side tool call results. There are occasions where the assistant will output several parallel client-side tool calls. The idea, as far as I understand, is for the client to call `addToolResult` for each of these client-side tool calls (possibly through some UI interaction), and when all client-side calls have logged results, the assistant response will be triggered.

This all works fine in theory, but I noticed that if you try to batch update several parallel tool call results with `addToolResult`, the asynchronous triggers to mutate function only preserve one of the calls.

An illustrative example. If we have three tool calls in parallel, so that the `toolInvocations` from the assistant message are:

```
[
    {
        "state": "call",
        "toolCallId": "call_id1",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "call",
        "toolCallId": "call_id2",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "call",
        "toolCallId": "call_id3",
        "toolName": "toolName",
        "args": {...}
    },
]
```

Now I have a UI component that deals with all user interaction of the parallel tool calls before sending the results to `addToolResult`

```
const SomeFormForClientToolCalls = ({toolInvocations})  => {
  // dictionary from toolId to result to log
  const [toolResults, setToolResults] = useState<Record<string, any>({})
  
  return (
     <div>
     {.... some form to handle the client responses to the parallel tool calls}

     <Button 
      onClick={ 
        toolInvocations.forEach(tool => {
          const result = toolResults[tool.toolCallId]
          addToolResult({toolCallId: tool.toolCallId, result: result})
        })
      }>
        Submit
      </Button>

     </div>

  )
}
```

This will **not** update all the tool call states, probably only the last one, because addToolCall uses the current message state when mutating to an updated state. Since the first call might not complete and re-render the messages variable, this results in undesirable behavior. 

Expected output:

```
[
    {
        "state": "result",
        "result": {...},
        "toolCallId": "result_id1",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "result",
        "result": {...},
        "toolCallId": "result_id2",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "result",
        "result": {...},
        "toolCallId": "result_id3",
        "toolName": "toolName",
        "args": {...}
    },
]
```

Actual likely output: 

```
[
    {
        "state": "call",
        "toolCallId": "call_id1",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "call",
        "toolCallId": "call_id2",
        "toolName": "toolName",
        "args": {...}
    },
    {
        "state": "result",
        "result": {...},
        "toolCallId": "result_id3",
        "toolName": "toolName",
        "args": {...}
    },
]

```

One hacky fix is to add a time delay between each of the addToolResult calls but that is suboptimal for many reasons.

Not sure what the cleanest solution is but it seems like a classic case of when one should use the mutate/setState versions that take a callback from previous state to next state.

Labels: bug, ai/ui
State: closed