File size: 1,077 Bytes
033ca06 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import type { ToolCall } from "@langchain/core/messages";
import type { AIMessage } from "@langchain/langgraph-sdk";
import type { Translations } from "../i18n";
import { hasToolCalls } from "../messages/utils";
export function explainLastToolCall(message: AIMessage, t: Translations) {
if (hasToolCalls(message)) {
const lastToolCall = message.tool_calls![message.tool_calls!.length - 1]!;
return explainToolCall(lastToolCall, t);
}
return t.common.thinking;
}
export function explainToolCall(toolCall: ToolCall, t: Translations) {
if (toolCall.name === "web_search" || toolCall.name === "image_search") {
return t.toolCalls.searchFor(toolCall.args.query);
} else if (toolCall.name === "web_fetch") {
return t.toolCalls.viewWebPage;
} else if (toolCall.name === "present_files") {
return t.toolCalls.presentFiles;
} else if (toolCall.name === "write_todos") {
return t.toolCalls.writeTodos;
} else if (toolCall.args.description) {
return toolCall.args.description;
} else {
return t.toolCalls.useTool(toolCall.name);
}
}
|