save
This commit is contained in:
parent
d23d9f6638
commit
6416f293a4
@ -68,8 +68,6 @@ function initProduce() {
|
|||||||
// 初始化 tab
|
// 初始化 tab
|
||||||
loadPanels();
|
loadPanels();
|
||||||
|
|
||||||
// 尝试连接
|
|
||||||
doConnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -48,11 +48,6 @@ class MessageBridge {
|
|||||||
|
|
||||||
this.postMessage = (message) => vscode.postMessage(message);
|
this.postMessage = (message) => vscode.postMessage(message);
|
||||||
this.isConnected.value = true;
|
this.isConnected.value = true;
|
||||||
|
|
||||||
this.postMessage({
|
|
||||||
command: 'init',
|
|
||||||
data: {}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocket 环境连接
|
// WebSocket 环境连接
|
||||||
|
@ -22,9 +22,14 @@ export function loadPanels() {
|
|||||||
const bridge = useMessageBridge();
|
const bridge = useMessageBridge();
|
||||||
|
|
||||||
bridge.addCommandListener('panel/load', data => {
|
bridge.addCommandListener('panel/load', data => {
|
||||||
|
if (data.code !== 200) {
|
||||||
|
pinkLog('tabs 加载失败');
|
||||||
|
console.log(data.msg);
|
||||||
|
|
||||||
|
} else {
|
||||||
const persistTab = data.msg as SaveTab;
|
const persistTab = data.msg as SaveTab;
|
||||||
|
|
||||||
console.log('receive persist tab', persistTab);
|
pinkLog('tabs 加载成功');
|
||||||
|
|
||||||
if (persistTab.tabs.length === 0) {
|
if (persistTab.tabs.length === 0) {
|
||||||
// 空的,直接返回不需要管
|
// 空的,直接返回不需要管
|
||||||
@ -46,6 +51,7 @@ export function loadPanels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tabs.activeIndex = persistTab.currentIndex;
|
tabs.activeIndex = persistTab.currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
||||||
|
@ -7,9 +7,13 @@ export function loadSetting() {
|
|||||||
const bridge = useMessageBridge();
|
const bridge = useMessageBridge();
|
||||||
|
|
||||||
bridge.addCommandListener('setting/load', data => {
|
bridge.addCommandListener('setting/load', data => {
|
||||||
const persistConfig = data.msg;
|
if (data.code !== 200) {
|
||||||
|
pinkLog('配置加载失败');
|
||||||
|
console.log(data.msg);
|
||||||
|
|
||||||
console.log('receive persist config', persistConfig);
|
} else {
|
||||||
|
const persistConfig = data.msg;
|
||||||
|
pinkLog('配置加载成功');
|
||||||
|
|
||||||
llmManager.currentModelIndex = persistConfig.MODEL_INDEX;
|
llmManager.currentModelIndex = persistConfig.MODEL_INDEX;
|
||||||
I18n.global.locale.value = persistConfig.LANG;
|
I18n.global.locale.value = persistConfig.LANG;
|
||||||
@ -17,6 +21,7 @@ export function loadSetting() {
|
|||||||
persistConfig.LLM_INFO.forEach((element: any) => {
|
persistConfig.LLM_INFO.forEach((element: any) => {
|
||||||
llms.push(element);
|
llms.push(element);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
||||||
|
@ -13,6 +13,11 @@ export interface WebSocketResponse {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PostMessageble {
|
||||||
|
postMessage(message: any): void;
|
||||||
|
onDidReceiveMessage(callback: MessageHandler): { dispose: () => void };
|
||||||
|
}
|
||||||
|
|
||||||
// 监听器回调类型
|
// 监听器回调类型
|
||||||
export type MessageHandler = (message: any) => void;
|
export type MessageHandler = (message: any) => void;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { VSCodeWebViewLike } from "../adapter";
|
import { PostMessageble } from "../adapter";
|
||||||
import { MCPClient } from "./connect";
|
import { MCPClient } from "./connect";
|
||||||
|
|
||||||
// ==================== 接口定义 ====================
|
// ==================== 接口定义 ====================
|
||||||
@ -23,7 +23,7 @@ export interface CallToolOption {
|
|||||||
*/
|
*/
|
||||||
export async function listPrompts(
|
export async function listPrompts(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -56,7 +56,7 @@ export async function listPrompts(
|
|||||||
export async function getPrompt(
|
export async function getPrompt(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
option: GetPromptOption,
|
option: GetPromptOption,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -88,7 +88,7 @@ export async function getPrompt(
|
|||||||
*/
|
*/
|
||||||
export async function listResources(
|
export async function listResources(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -121,7 +121,7 @@ export async function listResources(
|
|||||||
*/
|
*/
|
||||||
export async function listResourceTemplates(
|
export async function listResourceTemplates(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -155,7 +155,7 @@ export async function listResourceTemplates(
|
|||||||
export async function readResource(
|
export async function readResource(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
option: ReadResourceOption,
|
option: ReadResourceOption,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -187,7 +187,7 @@ export async function readResource(
|
|||||||
*/
|
*/
|
||||||
export async function listTools(
|
export async function listTools(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -223,7 +223,7 @@ export async function listTools(
|
|||||||
export async function callTool(
|
export async function callTool(
|
||||||
client: MCPClient | undefined,
|
client: MCPClient | undefined,
|
||||||
option: CallToolOption,
|
option: CallToolOption,
|
||||||
webview: VSCodeWebViewLike
|
webview: PostMessageble
|
||||||
) {
|
) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import { VSCodeWebViewLike } from '../adapter';
|
import { PostMessageble } from '../adapter';
|
||||||
import { connect, MCPClient, type MCPOptions } from './connect';
|
import { connect, MCPClient, type MCPOptions } from './connect';
|
||||||
import { callTool, getPrompt, listPrompts, listResources, listResourceTemplates, listTools, readResource } from './handler';
|
import { callTool, getPrompt, listPrompts, listResources, listResourceTemplates, listTools, readResource } from './handler';
|
||||||
import { chatCompletionHandler } from './llm';
|
import { chatCompletionHandler } from './llm';
|
||||||
@ -11,7 +11,7 @@ import { ping } from './util';
|
|||||||
// TODO: 支持更多的 client
|
// TODO: 支持更多的 client
|
||||||
let client: MCPClient | undefined = undefined;
|
let client: MCPClient | undefined = undefined;
|
||||||
|
|
||||||
async function connectHandler(option: MCPOptions, webview: VSCodeWebViewLike) {
|
async function connectHandler(option: MCPOptions, webview: PostMessageble) {
|
||||||
try {
|
try {
|
||||||
client = await connect(option);
|
client = await connect(option);
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
@ -34,7 +34,7 @@ async function connectHandler(option: MCPOptions, webview: VSCodeWebViewLike) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function messageController(command: string, data: any, webview: VSCodeWebViewLike) {
|
export function messageController(command: string, data: any, webview: PostMessageble) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case 'connect':
|
case 'connect':
|
||||||
connectHandler(data, webview);
|
connectHandler(data, webview);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { OpenAI } from 'openai';
|
import { OpenAI } from 'openai';
|
||||||
import { MCPClient } from './connect';
|
import { MCPClient } from './connect';
|
||||||
|
import { PostMessageble } from '../adapter';
|
||||||
|
|
||||||
let currentStream: AsyncIterable<any> | null = null;
|
let currentStream: AsyncIterable<any> | null = null;
|
||||||
|
|
||||||
export async function chatCompletionHandler(client: MCPClient | undefined, data: any, webview: { postMessage: (message: any) => void }) {
|
export async function chatCompletionHandler(client: MCPClient | undefined, data: any, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
@ -99,7 +100,7 @@ export async function chatCompletionHandler(client: MCPClient | undefined, data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理中止消息的函数
|
// 处理中止消息的函数
|
||||||
export function handleAbortMessage(webview: { postMessage: (message: any) => void }) {
|
export function handleAbortMessage(webview: PostMessageble) {
|
||||||
if (currentStream) {
|
if (currentStream) {
|
||||||
// 标记流已中止
|
// 标记流已中止
|
||||||
currentStream = null;
|
currentStream = null;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { VSCodeWebViewLike } from '../adapter';
|
import { PostMessageble } from '../adapter';
|
||||||
import { loadConfig, loadTabSaveConfig, saveConfig, saveTabSaveConfig } from '../util';
|
import { loadConfig, loadTabSaveConfig, saveConfig, saveTabSaveConfig } from '../util';
|
||||||
import { MCPClient } from './connect';
|
import { MCPClient } from './connect';
|
||||||
|
|
||||||
export async function panelSaveHandler(client: MCPClient | undefined, data: any, webview: VSCodeWebViewLike) {
|
export async function panelSaveHandler(client: MCPClient | undefined, data: any, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
@ -35,7 +35,7 @@ export async function panelSaveHandler(client: MCPClient | undefined, data: any,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function panelLoadHandler(client: MCPClient | undefined, webview: VSCodeWebViewLike) {
|
export async function panelLoadHandler(client: MCPClient | undefined, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { VSCodeWebViewLike } from '../adapter';
|
import { PostMessageble } from '../adapter';
|
||||||
import { loadConfig, saveConfig } from '../util';
|
import { loadConfig, saveConfig } from '../util';
|
||||||
import { MCPClient } from './connect';
|
import { MCPClient } from './connect';
|
||||||
|
|
||||||
export async function settingSaveHandler(client: MCPClient | undefined, data: any, webview: VSCodeWebViewLike) {
|
export async function settingSaveHandler(client: MCPClient | undefined, data: any, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
@ -35,7 +35,7 @@ export async function settingSaveHandler(client: MCPClient | undefined, data: an
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function settingLoadHandler(client: MCPClient | undefined, webview: VSCodeWebViewLike) {
|
export async function settingLoadHandler(client: MCPClient | undefined, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { VSCodeWebViewLike } from "../adapter";
|
import { PostMessageble } from "../adapter";
|
||||||
import { MCPClient } from "./connect";
|
import { MCPClient } from "./connect";
|
||||||
|
|
||||||
export function ping(client: MCPClient | undefined, webview: VSCodeWebViewLike) {
|
export function ping(client: MCPClient | undefined, webview: PostMessageble) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const connectResult = {
|
const connectResult = {
|
||||||
code: 501,
|
code: 501,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user