openmcp-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/icons/openmcp.png +0 -0
- package/package.json +38 -0
- package/service/common/index.d.ts +5 -0
- package/service/common/index.d.ts.map +1 -0
- package/service/common/index.dto.d.ts +24 -0
- package/service/common/index.dto.d.ts.map +1 -0
- package/service/common/index.dto.js +2 -0
- package/service/common/index.js +17 -0
- package/service/common/router.d.ts +10 -0
- package/service/common/router.d.ts.map +1 -0
- package/service/common/router.js +54 -0
- package/service/hook/adapter.d.ts +67 -0
- package/service/hook/adapter.d.ts.map +1 -0
- package/service/hook/adapter.js +123 -0
- package/service/hook/db.d.ts +46 -0
- package/service/hook/db.d.ts.map +1 -0
- package/service/hook/db.js +179 -0
- package/service/hook/llm.d.ts +13 -0
- package/service/hook/llm.d.ts.map +1 -0
- package/service/hook/llm.js +89 -0
- package/service/hook/setting.d.ts +5 -0
- package/service/hook/setting.d.ts.map +1 -0
- package/service/hook/setting.js +13 -0
- package/service/hook/types.d.ts +90 -0
- package/service/hook/types.d.ts.map +1 -0
- package/service/hook/types.js +2 -0
- package/service/index.d.ts +5 -0
- package/service/index.d.ts.map +1 -0
- package/service/index.js +14 -0
- package/service/llm/llm.controller.d.ts +10 -0
- package/service/llm/llm.controller.d.ts.map +1 -0
- package/service/llm/llm.controller.js +61 -0
- package/service/llm/llm.dto.d.ts +8 -0
- package/service/llm/llm.dto.d.ts.map +1 -0
- package/service/llm/llm.dto.js +2 -0
- package/service/llm/llm.service.d.ts +8 -0
- package/service/llm/llm.service.d.ts.map +1 -0
- package/service/llm/llm.service.js +176 -0
- package/service/mcp/client.controller.d.ts +791 -0
- package/service/mcp/client.controller.d.ts.map +1 -0
- package/service/mcp/client.controller.js +177 -0
- package/service/mcp/client.dto.d.ts +42 -0
- package/service/mcp/client.dto.d.ts.map +1 -0
- package/service/mcp/client.dto.js +2 -0
- package/service/mcp/client.service.d.ts +763 -0
- package/service/mcp/client.service.d.ts.map +1 -0
- package/service/mcp/client.service.js +186 -0
- package/service/mcp/connect.controller.d.ts +17 -0
- package/service/mcp/connect.controller.d.ts.map +1 -0
- package/service/mcp/connect.controller.js +63 -0
- package/service/mcp/connect.service.d.ts +7 -0
- package/service/mcp/connect.service.d.ts.map +1 -0
- package/service/mcp/connect.service.js +76 -0
- package/service/mcp/ocr.controller.d.ts +18 -0
- package/service/mcp/ocr.controller.d.ts.map +1 -0
- package/service/mcp/ocr.controller.js +57 -0
- package/service/mcp/ocr.dto.d.ts +8 -0
- package/service/mcp/ocr.dto.d.ts.map +1 -0
- package/service/mcp/ocr.dto.js +2 -0
- package/service/mcp/ocr.service.d.ts +9 -0
- package/service/mcp/ocr.service.d.ts.map +1 -0
- package/service/mcp/ocr.service.js +143 -0
- package/service/panel/panel.controller.d.ts +32 -0
- package/service/panel/panel.controller.d.ts.map +1 -0
- package/service/panel/panel.controller.js +118 -0
- package/service/panel/panel.dto.d.ts +12 -0
- package/service/panel/panel.dto.d.ts.map +1 -0
- package/service/panel/panel.dto.js +2 -0
- package/service/panel/panel.service.d.ts +6 -0
- package/service/panel/panel.service.d.ts.map +1 -0
- package/service/panel/panel.service.js +95 -0
- package/service/setting/setting.controller.d.ts +23 -0
- package/service/setting/setting.controller.d.ts.map +1 -0
- package/service/setting/setting.controller.js +77 -0
- package/service/setting/setting.dto.d.ts +5 -0
- package/service/setting/setting.dto.d.ts.map +1 -0
- package/service/setting/setting.dto.js +2 -0
- package/service/setting/setting.service.d.ts +8 -0
- package/service/setting/setting.service.d.ts.map +1 -0
- package/service/setting/setting.service.js +121 -0
- package/task-loop.d.ts +105 -0
- package/task-loop.js +10985 -0
- package/task-loop.js.map +1 -0
- package/tools.js +8 -0
package/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
<div align="center">
|
2
|
+
|
3
|
+
<img src="./icons/openmcp.png" height="200px"/>
|
4
|
+
|
5
|
+
<h3>OpenMCP: 一体化 MCP Server 调试器</h3>
|
6
|
+
|
7
|
+
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=C6ZUTZvfqWoI12lWe7L93cWa1hUsuVT0&jump_from=webapi&authKey=McW6B1ogTPjPDrCyGttS890tMZGQ1KB3QLuG4aqVNRaYp4vlTSgf2c6dMcNjMuBD" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: #CB81DA; color: white; border-radius: .5em; text-decoration: none;">👉 加入 OpenMCP正式级技术组</a>
|
8
|
+
|
9
|
+
|
10
|
+
<a href="https://discord.gg/af5cfB9a" target="_blank" style="display: inline-block; padding: 8px 16px; background-color: rgb(84, 176, 84); color: white; border-radius: .5em; text-decoration: none;"> 加入 OpenMCP Discord频道</a>
|
11
|
+
|
12
|
+
</div>
|
13
|
+
|
14
|
+
|
15
|
+
## 安装
|
16
|
+
|
17
|
+
```bash
|
18
|
+
npm install openmcp-sdk
|
19
|
+
```
|
20
|
+
|
21
|
+
## 使用
|
22
|
+
|
23
|
+
文件名:main.ts
|
24
|
+
|
25
|
+
```typescript
|
26
|
+
import { TaskLoop } from 'openmcp-sdk/task-loop';
|
27
|
+
import { TaskLoopAdapter } from 'openmcp-sdk/service';
|
28
|
+
|
29
|
+
async function main() {
|
30
|
+
// 创建适配器,负责通信和 mcp 连接
|
31
|
+
const adapter = new TaskLoopAdapter();
|
32
|
+
|
33
|
+
// 连接 mcp 服务器
|
34
|
+
await adapter.connectMcpServer({
|
35
|
+
connectionType: 'STDIO',
|
36
|
+
command: 'node',
|
37
|
+
args: [
|
38
|
+
'~/projects/mcp/servers/src/puppeteer/dist/index.js'
|
39
|
+
]
|
40
|
+
});
|
41
|
+
|
42
|
+
// 获取工具列表
|
43
|
+
const tools = await adapter.listTools();
|
44
|
+
|
45
|
+
// 创建事件循环驱动器
|
46
|
+
const taskLoop = new TaskLoop({ adapter });
|
47
|
+
|
48
|
+
// 配置改次事件循环使用的大模型
|
49
|
+
taskLoop.setLlmConfig({
|
50
|
+
id: 'deepseek',
|
51
|
+
baseUrl: 'https://api.deepseek.com/v1',
|
52
|
+
userToken: process.env['DEEPSEEK_API_TOKEN'],
|
53
|
+
userModel: 'deepseek-chat'
|
54
|
+
});
|
55
|
+
|
56
|
+
// 创建当前事件循环对应的上下文,并且配置当前上下文的设置
|
57
|
+
const storage = {
|
58
|
+
messages: [],
|
59
|
+
settings: {
|
60
|
+
temperature: 0.7,
|
61
|
+
enableTools: tools,
|
62
|
+
systemPrompt: 'you are a clever bot',
|
63
|
+
contextLength: 20
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
// 本次发出的问题
|
68
|
+
const message = 'hello world';
|
69
|
+
|
70
|
+
// 事件循环结束的句柄
|
71
|
+
taskLoop.registerOnDone(() => {
|
72
|
+
console.log('taskLoop done');
|
73
|
+
});
|
74
|
+
|
75
|
+
// 事件循环每一次 epoch 开始的句柄
|
76
|
+
taskLoop.registerOnError((error) => {
|
77
|
+
console.log('taskLoop error', error);
|
78
|
+
});
|
79
|
+
|
80
|
+
// 事件循环出现 error 时的句柄(出现 error 不一定会停止事件循环)
|
81
|
+
taskLoop.registerOnEpoch(() => {
|
82
|
+
console.log('taskLoop epoch');
|
83
|
+
});
|
84
|
+
|
85
|
+
// 开启事件循环
|
86
|
+
await taskLoop.start(storage, message);
|
87
|
+
|
88
|
+
// 打印上下文,最终的回答在 messages.at(-1) 中
|
89
|
+
console.log(storage.messages);
|
90
|
+
}
|
91
|
+
|
92
|
+
main();
|
93
|
+
```
|
94
|
+
|
95
|
+
star 我们的项目:https://github.com/LSTM-Kirigaya/openmcp-client
|
Binary file
|
package/package.json
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
{
|
2
|
+
"name": "openmcp-sdk",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "openmcp-sdk",
|
5
|
+
"scripts": {
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
7
|
+
},
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "https://github.com/LSTM-Kirigaya/openmcp-client"
|
11
|
+
},
|
12
|
+
"keywords": [
|
13
|
+
"mcp",
|
14
|
+
"openmcp",
|
15
|
+
"openmcp-sdk",
|
16
|
+
"llm framework",
|
17
|
+
"agent",
|
18
|
+
"ai agent"
|
19
|
+
],
|
20
|
+
"author": "kirigaya",
|
21
|
+
"license": "Apache-2.0",
|
22
|
+
"bugs": {
|
23
|
+
"url": "https://github.com/LSTM-Kirigaya/openmcp-client/issues"
|
24
|
+
},
|
25
|
+
"homepage": "https://document.kirigaya.cn/blogs/openmcp/main.html",
|
26
|
+
"dependencies": {
|
27
|
+
"@modelcontextprotocol/sdk": "^1.10.2",
|
28
|
+
"@seald-io/nedb": "^4.1.1",
|
29
|
+
"@vue/server-renderer": "^3.5.13",
|
30
|
+
"axios": "^1.7.7",
|
31
|
+
"bson": "^6.8.0",
|
32
|
+
"openai": "^4.93.0",
|
33
|
+
"pako": "^2.1.0",
|
34
|
+
"tesseract.js": "^6.0.1",
|
35
|
+
"uuid": "^11.1.0",
|
36
|
+
"ws": "^8.18.1"
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { MapperDescriptor, RequestHandler, RequestClientType, RestfulResponse, ControllerOption, RequestHandlerStore } from "./index.dto";
|
2
|
+
export { MapperDescriptor, RequestHandler, RequestClientType };
|
3
|
+
export declare const requestHandlerStorage: Map<string, RequestHandlerStore<any, RestfulResponse>>;
|
4
|
+
export declare function Controller(command: string, option?: ControllerOption): <T>(target: any, propertykey: string, descriptor: MapperDescriptor<T>) => MapperDescriptor<T>;
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1I,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAE/D,eAAO,MAAM,qBAAqB,wDAA+D,CAAC;AAElG,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,gBAAqB,IACrD,CAAC,EAAE,QAAQ,GAAG,EAAE,aAAa,MAAM,EAAE,YAAY,gBAAgB,CAAC,CAAC,CAAC,yBAUvF"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { PostMessageble } from "../hook/adapter";
|
2
|
+
import { McpClient } from "../mcp/client.service";
|
3
|
+
export type RequestClientType = McpClient | undefined;
|
4
|
+
export type RequestHandler<T, R> = (client: RequestClientType, data: T, webview: PostMessageble) => Promise<R>;
|
5
|
+
export interface RequestHandlerStore<T, R> {
|
6
|
+
handler: RequestHandler<T, R>;
|
7
|
+
option?: ControllerOption;
|
8
|
+
}
|
9
|
+
export interface MapperDescriptor<T> {
|
10
|
+
configurable?: boolean;
|
11
|
+
enumerable?: boolean;
|
12
|
+
value?: RequestHandler<T, RestfulResponse>;
|
13
|
+
writable?: boolean;
|
14
|
+
get?(): any;
|
15
|
+
set?(v: any): void;
|
16
|
+
}
|
17
|
+
export interface RestfulResponse {
|
18
|
+
code: number;
|
19
|
+
msg: any;
|
20
|
+
}
|
21
|
+
export interface ControllerOption {
|
22
|
+
[key: string]: any;
|
23
|
+
}
|
24
|
+
//# sourceMappingURL=index.dto.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.dto.d.ts","sourceRoot":"","sources":["../../src/common/index.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,CAAC;AAEtD,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,IAAI,CAC/B,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,cAAc,KACtB,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,WAAW,mBAAmB,CAAC,CAAC,EAAE,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7B,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,IAAI,GAAG,CAAC;IACZ,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,gBAAgB;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.requestHandlerStorage = void 0;
|
4
|
+
exports.Controller = Controller;
|
5
|
+
exports.requestHandlerStorage = new Map();
|
6
|
+
function Controller(command, option = {}) {
|
7
|
+
return function (target, propertykey, descriptor) {
|
8
|
+
const handler = descriptor.value;
|
9
|
+
if (exports.requestHandlerStorage.has(command)) {
|
10
|
+
throw new Error(`Duplicate request handler for ${command}`);
|
11
|
+
}
|
12
|
+
if (handler) {
|
13
|
+
exports.requestHandlerStorage.set(command, { handler, option });
|
14
|
+
}
|
15
|
+
return descriptor;
|
16
|
+
};
|
17
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { PostMessageble } from "../hook/adapter";
|
2
|
+
import { LlmController } from "../llm/llm.controller";
|
3
|
+
import { ClientController } from "../mcp/client.controller";
|
4
|
+
import { ConnectController } from "../mcp/connect.controller";
|
5
|
+
import { OcrController } from "../mcp/ocr.controller";
|
6
|
+
import { PanelController } from "../panel/panel.controller";
|
7
|
+
import { SettingController } from "../setting/setting.controller";
|
8
|
+
export declare const ModuleControllers: (typeof LlmController | typeof ClientController | typeof ConnectController | typeof OcrController | typeof PanelController | typeof SettingController)[];
|
9
|
+
export declare function routeMessage(command: string, data: any, webview: PostMessageble): Promise<void>;
|
10
|
+
//# sourceMappingURL=router.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/common/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,eAAO,MAAM,iBAAiB,0JAO7B,CAAC;AAEF,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,iBAuBrF"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.ModuleControllers = void 0;
|
13
|
+
exports.routeMessage = routeMessage;
|
14
|
+
const _1 = require(".");
|
15
|
+
const llm_controller_1 = require("../llm/llm.controller");
|
16
|
+
const client_controller_1 = require("../mcp/client.controller");
|
17
|
+
const connect_controller_1 = require("../mcp/connect.controller");
|
18
|
+
const connect_service_1 = require("../mcp/connect.service");
|
19
|
+
const ocr_controller_1 = require("../mcp/ocr.controller");
|
20
|
+
const panel_controller_1 = require("../panel/panel.controller");
|
21
|
+
const setting_controller_1 = require("../setting/setting.controller");
|
22
|
+
exports.ModuleControllers = [
|
23
|
+
connect_controller_1.ConnectController,
|
24
|
+
client_controller_1.ClientController,
|
25
|
+
llm_controller_1.LlmController,
|
26
|
+
panel_controller_1.PanelController,
|
27
|
+
setting_controller_1.SettingController,
|
28
|
+
ocr_controller_1.OcrController
|
29
|
+
];
|
30
|
+
function routeMessage(command, data, webview) {
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
32
|
+
const handlerStore = _1.requestHandlerStorage.get(command);
|
33
|
+
if (handlerStore) {
|
34
|
+
const { handler, option = {} } = handlerStore;
|
35
|
+
try {
|
36
|
+
// TODO: select client based on something
|
37
|
+
const res = yield handler(connect_service_1.client, data, webview);
|
38
|
+
// res.code = -1 代表当前请求不需要返回发送
|
39
|
+
if (res.code >= 0) {
|
40
|
+
webview.postMessage({ command, data: res });
|
41
|
+
}
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
webview.postMessage({
|
45
|
+
command, data: {
|
46
|
+
code: 500,
|
47
|
+
msg: error.toString()
|
48
|
+
}
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return;
|
53
|
+
});
|
54
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { WebSocket } from 'ws';
|
2
|
+
import { EventEmitter } from 'events';
|
3
|
+
import { McpOptions } from '../mcp/client.dto';
|
4
|
+
export interface WebSocketMessage {
|
5
|
+
command: string;
|
6
|
+
data: any;
|
7
|
+
}
|
8
|
+
export interface WebSocketResponse {
|
9
|
+
result?: any;
|
10
|
+
timeCost?: number;
|
11
|
+
error?: string;
|
12
|
+
}
|
13
|
+
export interface PostMessageble {
|
14
|
+
postMessage(message: any): void;
|
15
|
+
}
|
16
|
+
export type MessageHandler = (message: any) => void;
|
17
|
+
export declare class VSCodeWebViewLike {
|
18
|
+
private ws;
|
19
|
+
private messageHandlers;
|
20
|
+
constructor(ws: WebSocket);
|
21
|
+
/**
|
22
|
+
* 发送消息(模拟 vscode.webview.postMessage)
|
23
|
+
* @param message - 包含 command 和 args 的消息
|
24
|
+
*/
|
25
|
+
postMessage(message: WebSocketMessage): void;
|
26
|
+
/**
|
27
|
+
* 接收消息(模拟 vscode.webview.onDidReceiveMessage)
|
28
|
+
* @param callback - 消息回调
|
29
|
+
* @returns {{ dispose: () => void }} - 可销毁的监听器
|
30
|
+
*/
|
31
|
+
onDidReceiveMessage(callback: MessageHandler): {
|
32
|
+
dispose: () => void;
|
33
|
+
};
|
34
|
+
}
|
35
|
+
export declare class TaskLoopAdapter {
|
36
|
+
emitter: EventEmitter;
|
37
|
+
private messageHandlers;
|
38
|
+
constructor(option?: any);
|
39
|
+
/**
|
40
|
+
* @description 发送消息
|
41
|
+
* @param message - 包含 command 和 args 的消息
|
42
|
+
*/
|
43
|
+
postMessage(message: WebSocketMessage): void;
|
44
|
+
/**
|
45
|
+
* @description 注册接受消息的句柄
|
46
|
+
* @param callback - 消息回调
|
47
|
+
* @returns {{ dispose: () => void }} - 可销毁的监听器
|
48
|
+
*/
|
49
|
+
onDidReceiveMessage(callback: MessageHandler): {
|
50
|
+
dispose: () => void;
|
51
|
+
};
|
52
|
+
/**
|
53
|
+
* @description 连接到 mcp 服务端
|
54
|
+
* @param mcpOption
|
55
|
+
*/
|
56
|
+
connectMcpServer(mcpOption: McpOptions): Promise<void>;
|
57
|
+
/**
|
58
|
+
* @description 获取 mcp 服务器的工具列表
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
listTools(): Promise<{
|
62
|
+
name: string;
|
63
|
+
description: string | undefined;
|
64
|
+
enabled: boolean;
|
65
|
+
}[]>;
|
66
|
+
}
|
67
|
+
//# sourceMappingURL=adapter.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/hook/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,GAAG,CAAC;CACb;AAGD,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC3B,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;CACnC;AAGD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;AAEpD,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,EAAE,CAAY;IACtB,OAAO,CAAC,eAAe,CAAsB;gBAEjC,EAAE,EAAE,SAAS;IAezB;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAQ5C;;;;OAIG;IACH,mBAAmB,CAAC,QAAQ,EAAE,cAAc,GAAG;QAAE,OAAO,EAAE,MAAM,IAAI,CAAA;KAAE;CAMzE;AAGD,qBAAa,eAAe;IACjB,OAAO,EAAE,YAAY,CAAC;IAC7B,OAAO,CAAC,eAAe,CAAsB;gBAEjC,MAAM,CAAC,EAAE,GAAG;IAgBxB;;;OAGG;IACI,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAInD;;;;OAIG;IACI,mBAAmB,CAAC,QAAQ,EAAE,cAAc,GAAG;QAAE,OAAO,EAAE,MAAM,IAAI,CAAA;KAAE;IAO7E;;;OAGG;IACU,gBAAgB,CAAC,SAAS,EAAE,UAAU;IAWnD;;;OAGG;IACU,SAAS;;;;;CAWzB"}
|
@@ -0,0 +1,123 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.TaskLoopAdapter = exports.VSCodeWebViewLike = void 0;
|
13
|
+
const ws_1 = require("ws");
|
14
|
+
const events_1 = require("events");
|
15
|
+
const router_1 = require("../common/router");
|
16
|
+
const connect_service_1 = require("../mcp/connect.service");
|
17
|
+
class VSCodeWebViewLike {
|
18
|
+
constructor(ws) {
|
19
|
+
this.ws = ws;
|
20
|
+
this.messageHandlers = new Set();
|
21
|
+
// 监听消息并触发回调
|
22
|
+
this.ws.on('message', (rawData) => {
|
23
|
+
try {
|
24
|
+
const message = JSON.parse(rawData.toString());
|
25
|
+
this.messageHandlers.forEach((handler) => handler(message));
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
console.error('Failed to parse WebSocket message:', error);
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* 发送消息(模拟 vscode.webview.postMessage)
|
34
|
+
* @param message - 包含 command 和 args 的消息
|
35
|
+
*/
|
36
|
+
postMessage(message) {
|
37
|
+
if (this.ws.readyState === ws_1.WebSocket.OPEN) {
|
38
|
+
this.ws.send(JSON.stringify(message));
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
console.error('WebSocket is not open, cannot send message');
|
42
|
+
}
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* 接收消息(模拟 vscode.webview.onDidReceiveMessage)
|
46
|
+
* @param callback - 消息回调
|
47
|
+
* @returns {{ dispose: () => void }} - 可销毁的监听器
|
48
|
+
*/
|
49
|
+
onDidReceiveMessage(callback) {
|
50
|
+
this.messageHandlers.add(callback);
|
51
|
+
return {
|
52
|
+
dispose: () => this.messageHandlers.delete(callback),
|
53
|
+
};
|
54
|
+
}
|
55
|
+
}
|
56
|
+
exports.VSCodeWebViewLike = VSCodeWebViewLike;
|
57
|
+
class TaskLoopAdapter {
|
58
|
+
constructor(option) {
|
59
|
+
this.emitter = new events_1.EventEmitter(option);
|
60
|
+
this.messageHandlers = new Set();
|
61
|
+
this.emitter.on('message/renderer', (message) => {
|
62
|
+
this.messageHandlers.forEach((handler) => handler(message));
|
63
|
+
});
|
64
|
+
// 默认需要将监听的消息导入到 routeMessage 中
|
65
|
+
this.onDidReceiveMessage((message) => {
|
66
|
+
const { command, data } = message;
|
67
|
+
(0, router_1.routeMessage)(command, data, this);
|
68
|
+
});
|
69
|
+
}
|
70
|
+
/**
|
71
|
+
* @description 发送消息
|
72
|
+
* @param message - 包含 command 和 args 的消息
|
73
|
+
*/
|
74
|
+
postMessage(message) {
|
75
|
+
this.emitter.emit('message/service', message);
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* @description 注册接受消息的句柄
|
79
|
+
* @param callback - 消息回调
|
80
|
+
* @returns {{ dispose: () => void }} - 可销毁的监听器
|
81
|
+
*/
|
82
|
+
onDidReceiveMessage(callback) {
|
83
|
+
this.messageHandlers.add(callback);
|
84
|
+
return {
|
85
|
+
dispose: () => this.messageHandlers.delete(callback),
|
86
|
+
};
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* @description 连接到 mcp 服务端
|
90
|
+
* @param mcpOption
|
91
|
+
*/
|
92
|
+
connectMcpServer(mcpOption) {
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
94
|
+
const res = yield (0, connect_service_1.connectService)(undefined, mcpOption);
|
95
|
+
if (res.code === 200) {
|
96
|
+
console.log('✅ 成功连接 mcp 服务器: ' + res.msg);
|
97
|
+
const version = connect_service_1.client === null || connect_service_1.client === void 0 ? void 0 : connect_service_1.client.getServerVersion();
|
98
|
+
console.log(version);
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
console.error('❌ 连接 mcp 服务器失败:' + res.msg);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* @description 获取 mcp 服务器的工具列表
|
107
|
+
* @returns
|
108
|
+
*/
|
109
|
+
listTools() {
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
111
|
+
const tools = yield (connect_service_1.client === null || connect_service_1.client === void 0 ? void 0 : connect_service_1.client.listTools());
|
112
|
+
if (tools === null || tools === void 0 ? void 0 : tools.tools) {
|
113
|
+
return tools.tools.map((tool) => ({
|
114
|
+
name: tool.name,
|
115
|
+
description: tool.description,
|
116
|
+
enabled: true
|
117
|
+
}));
|
118
|
+
}
|
119
|
+
return [];
|
120
|
+
});
|
121
|
+
}
|
122
|
+
}
|
123
|
+
exports.TaskLoopAdapter = TaskLoopAdapter;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import * as fs from 'fs';
|
2
|
+
interface Entity {
|
3
|
+
id: string | number;
|
4
|
+
[key: string]: any;
|
5
|
+
}
|
6
|
+
export declare class LocalDB<T extends Entity> {
|
7
|
+
private tableName;
|
8
|
+
private db;
|
9
|
+
constructor(tableName: string);
|
10
|
+
private init;
|
11
|
+
insert(entity: T): Promise<void>;
|
12
|
+
findById(id: string | number): Promise<T | undefined>;
|
13
|
+
findAll(): Promise<T[]>;
|
14
|
+
delete(id: string | number): Promise<void>;
|
15
|
+
close(): Promise<void>;
|
16
|
+
}
|
17
|
+
declare class DiskStorage {
|
18
|
+
#private;
|
19
|
+
constructor();
|
20
|
+
get(filename: string): Promise<Buffer | null>;
|
21
|
+
set(filename: string, data: string | Buffer, options?: fs.WriteFileOptions): Promise<void>;
|
22
|
+
delete(filename: string): Promise<void>;
|
23
|
+
getSync(filename: string): Buffer | null;
|
24
|
+
setSync(filename: string, data: string | Buffer, options?: fs.WriteFileOptions): void;
|
25
|
+
getStoragePath(filename: string): string;
|
26
|
+
deleteSync(filename: string): void;
|
27
|
+
}
|
28
|
+
interface SettingItem extends Entity {
|
29
|
+
MODEL_INDEX: number;
|
30
|
+
[key: string]: any;
|
31
|
+
}
|
32
|
+
interface OcrItem extends Entity {
|
33
|
+
filename: string;
|
34
|
+
text?: string;
|
35
|
+
createTime: number;
|
36
|
+
}
|
37
|
+
interface SystemPromptItem extends Entity {
|
38
|
+
name: string;
|
39
|
+
content: string;
|
40
|
+
}
|
41
|
+
export declare const diskStorage: DiskStorage;
|
42
|
+
export declare const settingDB: LocalDB<SettingItem>;
|
43
|
+
export declare const ocrDB: LocalDB<OcrItem>;
|
44
|
+
export declare const systemPromptDB: LocalDB<SystemPromptItem>;
|
45
|
+
export {};
|
46
|
+
//# sourceMappingURL=db.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/hook/db.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,UAAU,MAAM;IACZ,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAID,qBAAa,OAAO,CAAC,CAAC,SAAS,MAAM;IAGrB,OAAO,CAAC,SAAS;IAF7B,OAAO,CAAC,EAAE,CAAM;gBAEI,SAAS,EAAE,MAAM;YAIvB,IAAI;IAsBZ,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrD,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAIvB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B;AAED,cAAM,WAAW;;;IAeA,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ7C,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1F,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQxC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,GAAG,IAAI;IAUrF,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIxC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAM5C;AAED,UAAU,WAAY,SAAQ,MAAM;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,UAAU,OAAQ,SAAQ,MAAM;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,gBAAiB,SAAQ,MAAM;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,WAAW,aAAoB,CAAC;AAE7C,eAAO,MAAM,SAAS,sBAAsC,CAAC;AAC7D,eAAO,MAAM,KAAK,kBAA8B,CAAC;AACjD,eAAO,MAAM,cAAc,2BAAgD,CAAC"}
|