From f925da7d7d3d85cd7d079eddfbf26271e4a53e73 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Fri, 25 Apr 2025 19:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=A5=E5=85=B7=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renderer/src/App.vue | 10 +- .../src/components/k-input-object/index.vue | 12 --- .../src/components/main-panel/chat/chat.ts | 19 +++- .../src/components/main-panel/chat/index.vue | 35 ++----- .../main-panel/chat/message/index.ts | 3 +- .../main-panel/chat/message/streaming-box.vue | 41 ++++++++ .../main-panel/chat/message/toolcall.vue | 97 ++++++++++++++----- .../components/main-panel/chat/setting.vue | 2 +- .../components/main-panel/chat/task-loop.ts | 39 +++++--- .../components/main-panel/prompt/prompts.ts | 2 +- .../main-panel/resource/resources.ts | 2 +- .../main-panel/tool/tool-executor.vue | 1 - .../main-panel/tool/tool-logger.vue | 57 +++++------ .../src/components/main-panel/tool/tools.ts | 4 +- renderer/src/hook/mcp.ts | 2 +- renderer/src/hook/type.ts | 1 + renderer/src/views/about/index.vue | 2 +- renderer/src/views/connect/connection.ts | 73 +++++++++++++- renderer/src/views/connect/env-var.vue | 82 +--------------- service/.gitignore | 3 +- service/package-lock.json | 73 ++++++++++++++ service/package.json | 1 + service/src/controller/env-var.ts | 4 +- service/src/controller/index.ts | 6 +- service/src/controller/llm.ts | 4 +- .../controller/{handler.ts => mcp-server.ts} | 4 +- service/src/controller/ocr.ts | 0 service/src/controller/panel.ts | 6 +- service/src/controller/setting.ts | 6 +- service/src/controller/util.ts | 4 +- service/src/{ => hook}/adapter.ts | 0 .../{controller/connect.ts => hook/client.ts} | 0 service/src/{ => hook}/llm.ts | 0 service/src/hook/ocr.ts | 22 +++++ service/src/{util.ts => hook/setting.ts} | 2 +- .../protocol.type.ts => hook/types.ts} | 9 ++ service/src/index.ts | 4 +- service/src/types.ts | 8 -- service/tabs.锦恢的 MCP Server.json | 4 +- 39 files changed, 414 insertions(+), 230 deletions(-) create mode 100644 renderer/src/components/main-panel/chat/message/streaming-box.vue rename service/src/controller/{handler.ts => mcp-server.ts} (98%) create mode 100644 service/src/controller/ocr.ts rename service/src/{ => hook}/adapter.ts (100%) rename service/src/{controller/connect.ts => hook/client.ts} (100%) rename service/src/{ => hook}/llm.ts (100%) create mode 100644 service/src/hook/ocr.ts rename service/src/{util.ts => hook/setting.ts} (98%) rename service/src/{controller/protocol.type.ts => hook/types.ts} (91%) delete mode 100644 service/src/types.ts diff --git a/renderer/src/App.vue b/renderer/src/App.vue index 69653c0..0902968 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -15,7 +15,7 @@ import MainPanel from '@/components/main-panel/index.vue'; import { setDefaultCss } from './hook/css'; import { greenLog, pinkLog } from './views/setting/util'; import { acquireVsCodeApi, useMessageBridge } from './api/message-bridge'; -import { connectionArgs, connectionMethods, doConnect, launchConnect } from './views/connect/connection'; +import { connectionArgs, connectionMethods, doConnect, launchConnect, loadEnvVar } from './views/connect/connection'; import { loadSetting } from './hook/setting'; import { loadPanels } from './hook/panel'; @@ -29,13 +29,16 @@ bridge.addCommandListener('hello', data => { function initDebug() { - connectionArgs.commandString = 'node C:/Users/K/code/servers/src/puppeteer/dist/index.js'; + connectionArgs.commandString = 'node /Users/bytedance/projects/mcp/servers/src/puppeteer/dist/index.js'; connectionMethods.current = 'STDIO'; setTimeout(async () => { // 初始化 设置 loadSetting(); + // 初始化环境变量 + loadEnvVar(); + // 尝试连接 await doConnect(); @@ -56,6 +59,9 @@ async function initProduce() { // 初始化 设置 loadSetting(); + // 初始化环境变量 + loadEnvVar(); + // 尝试连接 await launchConnect(); diff --git a/renderer/src/components/k-input-object/index.vue b/renderer/src/components/k-input-object/index.vue index 51ea1bb..bfa94f8 100644 --- a/renderer/src/components/k-input-object/index.vue +++ b/renderer/src/components/k-input-object/index.vue @@ -93,18 +93,6 @@ export default defineComponent({ return JSON.stringify(obj1) === JSON.stringify(obj2) } - // 自动调整文本区域高度 - const adjustTextareaHeight = () => { - nextTick(() => { - if (textareaRef.value) { - textareaRef.value.style.height = 'auto' - textareaRef.value.style.height = `${textareaRef.value.scrollHeight}px` - } - }) - } - - watch(inputValue, adjustTextareaHeight, { immediate: true }) - const handleKeydown = (event: KeyboardEvent) => { if (event.key === '{') { event.preventDefault(); diff --git a/renderer/src/components/main-panel/chat/chat.ts b/renderer/src/components/main-panel/chat/chat.ts index 7ded387..7603708 100644 --- a/renderer/src/components/main-panel/chat/chat.ts +++ b/renderer/src/components/main-panel/chat/chat.ts @@ -1,4 +1,4 @@ -import { ToolItem } from "@/hook/type"; +import { ToolCallContent, ToolItem } from "@/hook/type"; import { Ref, ref } from "vue"; import type { OpenAI } from 'openai'; @@ -24,8 +24,17 @@ export interface IExtraInfo { [key: string]: any; } -export interface ChatMessage { - role: 'user' | 'assistant' | 'system' | 'tool'; +export interface ToolMessage { + role: 'tool'; + content: ToolCallContent[]; + tool_call_id?: string + name?: string // 工具名称,当 role 为 tool + tool_calls?: ToolCall[], + extraInfo: IExtraInfo +} + +export interface TextMessage { + role: 'user' | 'assistant' | 'system'; content: string; tool_call_id?: string name?: string // 工具名称,当 role 为 tool @@ -33,6 +42,8 @@ export interface ChatMessage { extraInfo: IExtraInfo } +export type ChatMessage = ToolMessage | TextMessage; + // 新增状态和工具数据 interface EnableToolItem { name: string; @@ -69,7 +80,7 @@ export const allTools = ref([]); export interface IRenderMessage { role: 'user' | 'assistant/content' | 'assistant/tool_calls' | 'tool'; content: string; - toolResult?: string; + toolResult?: ToolCallContent[]; tool_calls?: ToolCall[]; showJson?: Ref; extraInfo: IExtraInfo; diff --git a/renderer/src/components/main-panel/chat/index.vue b/renderer/src/components/main-panel/chat/index.vue index feec0c0..f615b1c 100644 --- a/renderer/src/components/main-panel/chat/index.vue +++ b/renderer/src/components/main-panel/chat/index.vue @@ -5,9 +5,12 @@
-
+
+
+ +
@@ -27,22 +30,7 @@
-
- -
-
-
- Agent - - 正在生成答案 - - - -
-
- -
-
+
@@ -84,26 +72,16 @@ import { ElMessage, ScrollbarInstance } from 'element-plus'; import { tabs } from '../panel'; import { ChatMessage, ChatStorage, IRenderMessage, MessageState, ToolCall } from './chat'; -import Setting from './setting.vue'; - -// 引入 markdown.ts 中的函数 -import { markdownToHtml } from './markdown'; import { TaskLoop } from './task-loop'; import { llmManager, llms } from '@/views/setting/llm'; import * as Message from './message'; +import Setting from './setting.vue'; defineComponent({ name: 'chat' }); const { t } = useI18n(); -function waitingMarkdownToHtml(content: string) { - if (content) { - return markdownToHtml(content); - } - return '|'; -} - const props = defineProps({ tabId: { type: Number, @@ -358,6 +336,7 @@ onUnmounted(() => { .message-avatar { margin-right: 12px; + margin-top: 7px; } .message-content { diff --git a/renderer/src/components/main-panel/chat/message/index.ts b/renderer/src/components/main-panel/chat/message/index.ts index 1cabaff..9be8e81 100644 --- a/renderer/src/components/main-panel/chat/message/index.ts +++ b/renderer/src/components/main-panel/chat/message/index.ts @@ -1,4 +1,5 @@ import Assistant from "./assistant.vue"; import Toolcall from "./toolcall.vue"; import User from "./user.vue"; -export { Assistant, Toolcall, User }; \ No newline at end of file +import StreamingBox from "./streaming-box.vue"; +export { Assistant, Toolcall, User, StreamingBox }; \ No newline at end of file diff --git a/renderer/src/components/main-panel/chat/message/streaming-box.vue b/renderer/src/components/main-panel/chat/message/streaming-box.vue new file mode 100644 index 0000000..a49fb36 --- /dev/null +++ b/renderer/src/components/main-panel/chat/message/streaming-box.vue @@ -0,0 +1,41 @@ + + + + + \ No newline at end of file diff --git a/renderer/src/components/main-panel/chat/message/toolcall.vue b/renderer/src/components/main-panel/chat/message/toolcall.vue index 28e6667..037c4bb 100644 --- a/renderer/src/components/main-panel/chat/message/toolcall.vue +++ b/renderer/src/components/main-panel/chat/message/toolcall.vue @@ -1,8 +1,7 @@