u
This commit is contained in:
@@ -16,6 +16,13 @@
|
||||
import { Automat } from 'react-automat';
|
||||
import { modelconversation as modelconversationApi } from '../api';
|
||||
import authAutomat from './authAutomat';
|
||||
import {
|
||||
attachUserEnv,
|
||||
getCurrentRoute,
|
||||
isSetUserRouteTool,
|
||||
extractRouteFromToolData,
|
||||
navigateToClientRoute,
|
||||
} from '../components/chat/userEnv';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ModelConversation
|
||||
@@ -752,6 +759,20 @@ const actions = {
|
||||
* Turns the working icon green, shows tooltip with content, displays name behind the work icon.
|
||||
*/
|
||||
applyStreamToolCall(data) {
|
||||
let toolName = data?.name;
|
||||
if (!toolName && data?.id) {
|
||||
const turns = chatAutomat.state.activeTurns;
|
||||
const lastTurn = turns?.[turns.length - 1];
|
||||
const existing = lastTurn?.tools?.find((t) => t.id === data.id);
|
||||
toolName = existing?.name;
|
||||
}
|
||||
if (isSetUserRouteTool(toolName)) {
|
||||
const targetRoute = extractRouteFromToolData(data);
|
||||
if (targetRoute) {
|
||||
void navigateToClientRoute(targetRoute, data.id);
|
||||
}
|
||||
}
|
||||
|
||||
chatAutomat.setState((prev) => {
|
||||
const turns = prev.activeTurns ? [...prev.activeTurns] : [];
|
||||
if (turns.length === 0) {
|
||||
@@ -1020,6 +1041,9 @@ const actions = {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeRoute =
|
||||
(typeof textOrPayload === 'object' && textOrPayload?.route) || getCurrentRoute();
|
||||
|
||||
const tempId = `temp-${Date.now()}`;
|
||||
let finalContent = trimmed;
|
||||
if (fileAttachments.length > 0) {
|
||||
@@ -1033,11 +1057,14 @@ const actions = {
|
||||
finalContent = trimmed ? `${prefix}\n\n${trimmed}` : prefix;
|
||||
}
|
||||
|
||||
const optimisticContent = attachUserEnv(finalContent, activeRoute);
|
||||
const promptMessage = attachUserEnv(trimmed, activeRoute);
|
||||
|
||||
const optimisticMsg = {
|
||||
id: tempId,
|
||||
conversation_id: selectedConversationId,
|
||||
role: 'user',
|
||||
message: JSON.stringify({ content: finalContent }),
|
||||
message: JSON.stringify({ content: optimisticContent }),
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
@@ -1065,7 +1092,7 @@ const actions = {
|
||||
|
||||
try {
|
||||
const res = await modelconversationApi.addMessage(selectedConversationId, {
|
||||
message: trimmed,
|
||||
message: promptMessage,
|
||||
attachments: fileAttachments.length > 0 ? fileAttachments : undefined,
|
||||
});
|
||||
const createdMsg = res?.message || optimisticMsg;
|
||||
@@ -1255,6 +1282,18 @@ const actions = {
|
||||
}
|
||||
}
|
||||
|
||||
if (message.role === 'tool') {
|
||||
try {
|
||||
const payload = typeof message.message === 'string' ? JSON.parse(message.message) : message.message;
|
||||
if (isSetUserRouteTool(payload?.name)) {
|
||||
const targetRoute = extractRouteFromToolData(payload);
|
||||
if (targetRoute) {
|
||||
void navigateToClientRoute(targetRoute, message.id || payload?.tool_call_id);
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const isAssistant = message.role === 'assistant' || message.role === 'model';
|
||||
let hasAskUser = false;
|
||||
if (isAssistant) {
|
||||
@@ -1263,6 +1302,17 @@ const actions = {
|
||||
if (payload?.tool_calls?.some((tc) => tc.function?.name === 'ask_user')) {
|
||||
hasAskUser = true;
|
||||
}
|
||||
if (Array.isArray(payload?.tool_calls)) {
|
||||
for (const tc of payload.tool_calls) {
|
||||
const name = tc.function?.name || tc.name;
|
||||
if (isSetUserRouteTool(name)) {
|
||||
const targetRoute = extractRouteFromToolData(tc.function || tc);
|
||||
if (targetRoute) {
|
||||
void navigateToClientRoute(targetRoute, tc.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
// If this assistant message matches one we created locally on 'done', update with real DB ID & keep turns
|
||||
|
||||
Reference in New Issue
Block a user