|
1 | 1 | <template> |
2 | | - <div class="header"></div> |
3 | | - <div class="app-container"> |
4 | | - <!-- 主体内容区域 --> |
5 | | - <div class="main-content"> |
6 | | - <router-view /> |
7 | | - </div> |
8 | | - <div class="right-panel" :class="{ collapsed: !showTinyRobot }"> |
9 | | - <div class="right-panel-header">智能助手操作区</div> |
10 | | - <tiny-robot-chat /> |
11 | | - </div> |
12 | | - <IconAi @click="showTinyRobot = !showTinyRobot" class="style-settings-icon"></IconAi> |
13 | | - <tiny-dialog-box |
14 | | - v-model:visible="boxVisibility" |
15 | | - :close-on-click-modal="false" |
16 | | - title="请填写您的LLM信息" |
17 | | - :show-close="false" |
18 | | - width="30%" |
19 | | - > |
20 | | - <div> |
21 | | - <tiny-form ref="formRef" :model="createData" label-width="120px"> |
22 | | - <tiny-form-item label="LLM URL" prop="llmUrl" :rules="{ required: true, messages: '必填', trigger: 'blur' }"> |
23 | | - <tiny-input v-model="createData.llmUrl"></tiny-input> |
24 | | - </tiny-form-item> |
25 | | - <tiny-form-item |
26 | | - label="API Key" |
27 | | - prop="llmApiKey" |
28 | | - :rules="{ required: true, messages: '必填', trigger: 'blur' }" |
29 | | - > |
30 | | - <tiny-input v-model="createData.llmApiKey"></tiny-input> |
31 | | - </tiny-form-item> |
32 | | - <tiny-form-item> |
33 | | - <tiny-button @click="submit" type="primary">保存</tiny-button> |
34 | | - </tiny-form-item> |
35 | | - </tiny-form> |
36 | | - </div> |
37 | | - </tiny-dialog-box> |
| 2 | + <div> |
| 3 | + <router-view /> |
| 4 | + <TinyRemoter sessionId="78b66563-95c0-4839-8007-e8af634dd657" /> |
38 | 5 | </div> |
39 | 6 | </template> |
40 | 7 |
|
41 | 8 | <script setup lang="ts"> |
42 | | -import '@opentiny/icons/style/all.css' |
43 | | -import TinyRobotChat from './components/tiny-robot-chat.vue' |
44 | | -import { showTinyRobot } from './composable/utils' |
45 | | -import { IconAi } from '@opentiny/tiny-robot-svgs' |
46 | | -import { reactive, ref } from 'vue' |
47 | | -import { $local, isEnvLLMDefined, isLocalLLMDefined } from './composable/utils' |
48 | | -const boxVisibility = ref(false) |
49 | | -const formRef = ref() |
50 | | -const createData = reactive({ |
51 | | - llmUrl: $local.llmUrl || import.meta.env.VITE_LLM_URL, |
52 | | - llmApiKey: $local.llmApiKey || import.meta.env.VITE_LLM_API_KEY |
53 | | -}) |
54 | | -
|
55 | | -const submit = () => { |
56 | | - formRef.value.validate().then(() => { |
57 | | - $local.llmUrl = createData.llmUrl |
58 | | - $local.llmApiKey = createData.llmApiKey |
59 | | - boxVisibility.value = false |
60 | | - window.location.reload() |
61 | | - }) |
| 9 | +import { TinyRemoter } from '@opentiny/next-remoter' |
| 10 | +import { WebMcpClient, createMessageChannelPairTransport } from '@opentiny/next-sdk' |
| 11 | +import type { Transport } from '@opentiny/next-sdk' |
| 12 | +import { AGENT_ROOT } from './const' |
| 13 | +import { provide } from 'vue' |
| 14 | +
|
| 15 | +const [serverTransport, clientTransport] = createMessageChannelPairTransport() |
| 16 | +
|
| 17 | +// 定义 MCP Server 的能力 |
| 18 | +const capabilities = { |
| 19 | + prompts: { listChanged: true }, |
| 20 | + resources: { subscribe: true, listChanged: true }, |
| 21 | + tools: { listChanged: true }, |
| 22 | + completions: {}, |
| 23 | + logging: {} |
62 | 24 | } |
63 | 25 |
|
64 | | -if (!isEnvLLMDefined && !isLocalLLMDefined) { |
65 | | - boxVisibility.value = true |
| 26 | +const mcpServer: { |
| 27 | + transport: Transport | null |
| 28 | + capabilities: Record<string, any> |
| 29 | +} = { |
| 30 | + transport: serverTransport, |
| 31 | + capabilities |
66 | 32 | } |
| 33 | +
|
| 34 | +provide('mcpServer', mcpServer) |
| 35 | +
|
| 36 | +serverTransport.onerror = (error) => { |
| 37 | + console.error(`ServerTransport error:`, error) |
| 38 | +} |
| 39 | +
|
| 40 | +const createProxyTransport = async () => { |
| 41 | + const client = new WebMcpClient( |
| 42 | + { name: 'mcp-web-client', version: '1.0.0' }, |
| 43 | + { capabilities: { roots: { listChanged: true }, sampling: {}, elicitation: {} } } |
| 44 | + ) |
| 45 | + // @ts-expect-error client |
| 46 | + window.client = client |
| 47 | + await client.connect(clientTransport) |
| 48 | +
|
| 49 | + const { sessionId } = await client.connect({ |
| 50 | + url: AGENT_ROOT + 'mcp', |
| 51 | + sessionId: '78b66563-95c0-4839-8007-e8af634dd657', |
| 52 | + agent: true, |
| 53 | + onError: (error: Error) => { |
| 54 | + console.error('Connect proxy error:', error) |
| 55 | + } |
| 56 | + }) |
| 57 | +
|
| 58 | + console.log('sessionId', sessionId) |
| 59 | +
|
| 60 | + window.addEventListener('pagehide', client.onPagehide) |
| 61 | +} |
| 62 | +
|
| 63 | +createProxyTransport() |
67 | 64 | </script> |
68 | 65 |
|
69 | 66 | <style scoped> |
|
0 commit comments