From fcf3b8cb9fb7d42833b8913bcd25f4986fbf085a Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Tue, 22 Apr 2025 02:25:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E4=B8=AD=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BF=9B=E8=A1=8C=E5=B7=A5=E5=85=B7=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renderer/src/App.vue | 2 +- .../src/components/main-panel/chat/index.vue | 15 +-- renderer/src/components/main-panel/panel.ts | 2 +- .../main-panel/tool/tool-executor.vue | 48 +++++++-- .../components/main-panel/tool/tool-list.vue | 6 +- .../main-panel/tool/tool-logger.vue | 7 ++ .../src/components/main-panel/tool/tools.ts | 1 + renderer/src/hook/panel.ts | 4 +- renderer/src/views/setting/llm.ts | 27 ++++- service/tabs.锦恢的 MCP Server.json | 100 +++++++++++++++++- 10 files changed, 181 insertions(+), 31 deletions(-) diff --git a/renderer/src/App.vue b/renderer/src/App.vue index d732fa2..013e3dd 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -29,7 +29,7 @@ bridge.addCommandListener('hello', data => { function initDebug() { - connectionArgs.commandString = 'uv run mcp run ../servers/bing-picture.py'; + connectionArgs.commandString = 'uv run mcp run ../servers/main.py'; connectionMethods.current = 'STDIO'; setTimeout(async () => { diff --git a/renderer/src/components/main-panel/chat/index.vue b/renderer/src/components/main-panel/chat/index.vue index e58b981..52d9e3d 100644 --- a/renderer/src/components/main-panel/chat/index.vue +++ b/renderer/src/components/main-panel/chat/index.vue @@ -42,7 +42,10 @@
{{ call.function.name }} - {{ call.type }} + {{ 'tool' }} + + +
@@ -154,7 +157,7 @@ import MessageMeta from './message-meta.vue'; // 引入 markdown.ts 中的函数 import { markdownToHtml, copyToClipboard } from './markdown'; import { ChatCompletionChunk, TaskLoop } from './task-loop'; -import { llmManager, llms } from '@/views/setting/llm'; +import { createTest, llmManager, llms } from '@/views/setting/llm'; defineComponent({ name: 'chat' }); @@ -390,14 +393,6 @@ const jsonResultToHtml = (jsonString: string) => { return html; }; -const formatToolArguments = (args: string) => { - try { - const parsed = JSON.parse(args); - return JSON.stringify(parsed, null, 2); - } catch { - return args; - } -}; diff --git a/renderer/src/components/main-panel/panel.ts b/renderer/src/components/main-panel/panel.ts index 6e7347e..03db395 100644 --- a/renderer/src/components/main-panel/panel.ts +++ b/renderer/src/components/main-panel/panel.ts @@ -50,7 +50,7 @@ watch( { deep: true } ); -function createTab(type: string, index: number): Tab { +export function createTab(type: string, index: number): Tab { let customName: string | null = null; return { diff --git a/renderer/src/components/main-panel/tool/tool-executor.vue b/renderer/src/components/main-panel/tool/tool-executor.vue index 6af4550..d456b7d 100644 --- a/renderer/src/components/main-panel/tool/tool-executor.vue +++ b/renderer/src/components/main-panel/tool/tool-executor.vue @@ -3,7 +3,7 @@

{{ currentTool?.name }}

- + @@ -53,8 +53,7 @@ import { useI18n } from 'vue-i18n'; import type { FormInstance, FormRules } from 'element-plus'; import { tabs } from '../panel'; import { callTool, toolsManager, ToolStorage } from './tools'; -import { CasualRestAPI, ToolCallResponse } from '@/hook/type'; -import { useMessageBridge } from '@/api/message-bridge'; +import { pinkLog } from '@/views/setting/util'; defineComponent({ name: 'tool-executor' }); @@ -70,8 +69,11 @@ const props = defineProps({ const tab = tabs.content[props.tabId]; const tabStorage = tab.storage as ToolStorage; +if (!tabStorage.formData) { + tabStorage.formData = {}; +} + const formRef = ref(); -const formData = ref>({}); const loading = ref(false); const currentTool = computed(() => { @@ -97,14 +99,38 @@ const formRules = computed(() => { return rules; }); +const getDefaultValue = (property: any) => { + if (property.type === 'number' || property.type === 'integer') { + return 0; + } else if (property.type === 'boolean') { + return false; + } else { + return ''; + } +}; + const initFormData = () => { - formData.value = {}; + // 初始化,根据输入的 inputSchema 校验 + // 1. 当前是否存在缺失的 key value,如果有,则根据 schema 给与默认值 + // 2. 如果有多余的 key value,则删除 + if (!currentTool.value?.inputSchema?.properties) return; + + const newSchemaDataForm: Record = {}; Object.entries(currentTool.value.inputSchema.properties).forEach(([name, property]) => { - formData.value[name] = (property.type === 'number' || property.type === 'integer') ? 0 : - property.type === 'boolean' ? false : ''; + newSchemaDataForm[name] = getDefaultValue(property); + let originType: string = typeof tabStorage.formData[name]; + if (originType === 'number') { + originType = 'integer'; + } + + if (tabStorage.formData[name] !== undefined && originType === property.type) { + newSchemaDataForm[name] = tabStorage.formData[name]; + } }); + + tabStorage.formData = newSchemaDataForm; }; const resetForm = () => { @@ -114,7 +140,7 @@ const resetForm = () => { async function handleExecute() { if (!currentTool.value) return; - const toolResponse = await callTool(tabStorage.currentToolName, formData.value); + const toolResponse = await callTool(tabStorage.currentToolName, tabStorage.formData); tabStorage.lastToolCallResponse = toolResponse; } diff --git a/renderer/src/components/main-panel/tool/tool-list.vue b/renderer/src/components/main-panel/tool/tool-list.vue index 62a39c0..9fef885 100644 --- a/renderer/src/components/main-panel/tool/tool-list.vue +++ b/renderer/src/components/main-panel/tool/tool-list.vue @@ -73,7 +73,11 @@ onMounted(() => { commandCancel = bridge.addCommandListener('tools/list', (data: CasualRestAPI) => { toolsManager.tools = data.msg.tools || []; - if (toolsManager.tools.length > 0) { + const targetTool = toolsManager.tools.find((tool) => { + return tool.name === tabStorage.currentToolName; + }); + + if (targetTool === undefined) { tabStorage.currentToolName = toolsManager.tools[0].name; tabStorage.lastToolCallResponse = undefined; } diff --git a/renderer/src/components/main-panel/tool/tool-logger.vue b/renderer/src/components/main-panel/tool/tool-logger.vue index 5fe83fa..c9ecef7 100644 --- a/renderer/src/components/main-panel/tool/tool-logger.vue +++ b/renderer/src/components/main-panel/tool/tool-logger.vue @@ -41,6 +41,7 @@ import { defineComponent, defineProps, computed, ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { tabs } from '../panel'; import { ToolStorage } from './tools'; +import { markdownToHtml } from '../chat/markdown'; defineComponent({ name: 'tool-logger' }); const { t } = useI18n(); @@ -64,6 +65,12 @@ const formattedJson = computed(() => { return 'Invalid JSON'; } }); + +const jsonResultToHtml = (jsonString: string) => { + const formattedJson = JSON.stringify(JSON.parse(jsonString), null, 2); + const html = markdownToHtml('```json\n' + formattedJson + '\n```'); + return html; +};