Skip to content

Commit 29c9be3

Browse files
Refactor tool handling: remove UI tool checks (#1846)
Fixes OPS-3293
1 parent b524d90 commit 29c9be3

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

packages/react-ui/src/app/features/ai/lib/assistant-ui-chat-hook.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { toast } from '@openops/components/ui';
99
import { flowHelper, FlowVersion } from '@openops/shared';
1010
import { getFrontendToolDefinitions } from '@openops/ui-kit';
1111
import { useQuery, useQueryClient } from '@tanstack/react-query';
12-
import { DefaultChatTransport, ToolSet, UIMessage } from 'ai';
12+
import {
13+
DefaultChatTransport,
14+
lastAssistantMessageIsCompleteWithToolCalls,
15+
ToolSet,
16+
UIMessage,
17+
} from 'ai';
1318
import { t } from 'i18next';
1419
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
1520
import { aiChatApi } from '../../builder/ai-chat/lib/chat-api';
@@ -279,17 +284,7 @@ export const useAssistantChat = ({
279284
}
280285
}
281286
},
282-
// send message automatically when there's a frontend tool call
283-
sendAutomaticallyWhen: ({ messages }) => {
284-
const lastMessage = messages[messages.length - 1];
285-
const lastMessagePart =
286-
lastMessage?.parts?.[lastMessage.parts.length - 1];
287-
return (
288-
lastMessagePart?.type?.includes('tool-ui') &&
289-
'output' in lastMessagePart &&
290-
!!lastMessagePart.output
291-
);
292-
},
287+
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
293288
});
294289

295290
useEffect(() => {

packages/server/api/src/app/ai/chat/llm-stream-handler.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
TextStreamPart,
1414
ToolSet,
1515
} from 'ai';
16-
import {
17-
hasToolCall,
18-
sanitizeMessages,
19-
UI_TOOL_PREFIX,
20-
} from '../mcp/tool-utils';
16+
import { sanitizeMessages } from '../mcp/tool-utils';
2117
import { createVoidTool } from '../mcp/void-tool';
2218
import {
2319
addCacheControlToMessages,
@@ -92,10 +88,7 @@ export function getLLMAsyncStream(
9288
tools: toolsProxy,
9389
toolChoice,
9490
maxRetries: MAX_RETRIES,
95-
stopWhen: [
96-
stepCountIs(maxRecursionDepth),
97-
hasToolCall((name) => name.startsWith(UI_TOOL_PREFIX)),
98-
],
91+
stopWhen: [stepCountIs(maxRecursionDepth)],
9992
onStepFinish,
10093
onFinish: async (result) => {
10194
const outputText = result.text || '';

0 commit comments

Comments
 (0)