fix: cancel parallel tool calls mid-execution (#489)
This commit is contained in:
parent
a8bfdf2d56
commit
fb1d13d600
|
@ -395,7 +395,10 @@ export const useGeminiStream = (
|
||||||
};
|
};
|
||||||
|
|
||||||
const streamingState: StreamingState =
|
const streamingState: StreamingState =
|
||||||
isResponding || toolCalls.some((t) => t.status === 'awaiting_approval')
|
isResponding ||
|
||||||
|
toolCalls.some(
|
||||||
|
(t) => t.status === 'awaiting_approval' || t.status === 'executing',
|
||||||
|
)
|
||||||
? StreamingState.Responding
|
? StreamingState.Responding
|
||||||
: StreamingState.Idle;
|
: StreamingState.Idle;
|
||||||
|
|
||||||
|
|
|
@ -185,12 +185,19 @@ export function useToolScheduler(
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// effect for executing scheduled tool calls
|
// effect for executing scheduled tool calls
|
||||||
if (toolCalls.every((t) => t.status === 'scheduled')) {
|
if (toolCalls.every((t) => t.status === 'scheduled')) {
|
||||||
|
const signal = abortController.signal;
|
||||||
toolCalls.forEach((c) => {
|
toolCalls.forEach((c) => {
|
||||||
const callId = c.request.callId;
|
const callId = c.request.callId;
|
||||||
setToolCalls(setStatus(c.request.callId, 'executing'));
|
setToolCalls(setStatus(c.request.callId, 'executing'));
|
||||||
c.tool
|
c.tool
|
||||||
.execute(c.request.args, abortController.signal)
|
.execute(c.request.args, signal)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
|
if (signal.aborted) {
|
||||||
|
setToolCalls(
|
||||||
|
setStatus(callId, 'cancelled', 'Cancelled during execution'),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const functionResponse: Part = {
|
const functionResponse: Part = {
|
||||||
functionResponse: {
|
functionResponse: {
|
||||||
name: c.request.name,
|
name: c.request.name,
|
||||||
|
|
Loading…
Reference in New Issue