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.
Files changed (85) hide show
  1. package/README.md +95 -0
  2. package/icons/openmcp.png +0 -0
  3. package/package.json +38 -0
  4. package/service/common/index.d.ts +5 -0
  5. package/service/common/index.d.ts.map +1 -0
  6. package/service/common/index.dto.d.ts +24 -0
  7. package/service/common/index.dto.d.ts.map +1 -0
  8. package/service/common/index.dto.js +2 -0
  9. package/service/common/index.js +17 -0
  10. package/service/common/router.d.ts +10 -0
  11. package/service/common/router.d.ts.map +1 -0
  12. package/service/common/router.js +54 -0
  13. package/service/hook/adapter.d.ts +67 -0
  14. package/service/hook/adapter.d.ts.map +1 -0
  15. package/service/hook/adapter.js +123 -0
  16. package/service/hook/db.d.ts +46 -0
  17. package/service/hook/db.d.ts.map +1 -0
  18. package/service/hook/db.js +179 -0
  19. package/service/hook/llm.d.ts +13 -0
  20. package/service/hook/llm.d.ts.map +1 -0
  21. package/service/hook/llm.js +89 -0
  22. package/service/hook/setting.d.ts +5 -0
  23. package/service/hook/setting.d.ts.map +1 -0
  24. package/service/hook/setting.js +13 -0
  25. package/service/hook/types.d.ts +90 -0
  26. package/service/hook/types.d.ts.map +1 -0
  27. package/service/hook/types.js +2 -0
  28. package/service/index.d.ts +5 -0
  29. package/service/index.d.ts.map +1 -0
  30. package/service/index.js +14 -0
  31. package/service/llm/llm.controller.d.ts +10 -0
  32. package/service/llm/llm.controller.d.ts.map +1 -0
  33. package/service/llm/llm.controller.js +61 -0
  34. package/service/llm/llm.dto.d.ts +8 -0
  35. package/service/llm/llm.dto.d.ts.map +1 -0
  36. package/service/llm/llm.dto.js +2 -0
  37. package/service/llm/llm.service.d.ts +8 -0
  38. package/service/llm/llm.service.d.ts.map +1 -0
  39. package/service/llm/llm.service.js +176 -0
  40. package/service/mcp/client.controller.d.ts +791 -0
  41. package/service/mcp/client.controller.d.ts.map +1 -0
  42. package/service/mcp/client.controller.js +177 -0
  43. package/service/mcp/client.dto.d.ts +42 -0
  44. package/service/mcp/client.dto.d.ts.map +1 -0
  45. package/service/mcp/client.dto.js +2 -0
  46. package/service/mcp/client.service.d.ts +763 -0
  47. package/service/mcp/client.service.d.ts.map +1 -0
  48. package/service/mcp/client.service.js +186 -0
  49. package/service/mcp/connect.controller.d.ts +17 -0
  50. package/service/mcp/connect.controller.d.ts.map +1 -0
  51. package/service/mcp/connect.controller.js +63 -0
  52. package/service/mcp/connect.service.d.ts +7 -0
  53. package/service/mcp/connect.service.d.ts.map +1 -0
  54. package/service/mcp/connect.service.js +76 -0
  55. package/service/mcp/ocr.controller.d.ts +18 -0
  56. package/service/mcp/ocr.controller.d.ts.map +1 -0
  57. package/service/mcp/ocr.controller.js +57 -0
  58. package/service/mcp/ocr.dto.d.ts +8 -0
  59. package/service/mcp/ocr.dto.d.ts.map +1 -0
  60. package/service/mcp/ocr.dto.js +2 -0
  61. package/service/mcp/ocr.service.d.ts +9 -0
  62. package/service/mcp/ocr.service.d.ts.map +1 -0
  63. package/service/mcp/ocr.service.js +143 -0
  64. package/service/panel/panel.controller.d.ts +32 -0
  65. package/service/panel/panel.controller.d.ts.map +1 -0
  66. package/service/panel/panel.controller.js +118 -0
  67. package/service/panel/panel.dto.d.ts +12 -0
  68. package/service/panel/panel.dto.d.ts.map +1 -0
  69. package/service/panel/panel.dto.js +2 -0
  70. package/service/panel/panel.service.d.ts +6 -0
  71. package/service/panel/panel.service.d.ts.map +1 -0
  72. package/service/panel/panel.service.js +95 -0
  73. package/service/setting/setting.controller.d.ts +23 -0
  74. package/service/setting/setting.controller.d.ts.map +1 -0
  75. package/service/setting/setting.controller.js +77 -0
  76. package/service/setting/setting.dto.d.ts +5 -0
  77. package/service/setting/setting.dto.d.ts.map +1 -0
  78. package/service/setting/setting.dto.js +2 -0
  79. package/service/setting/setting.service.d.ts +8 -0
  80. package/service/setting/setting.service.d.ts.map +1 -0
  81. package/service/setting/setting.service.js +121 -0
  82. package/task-loop.d.ts +105 -0
  83. package/task-loop.js +10985 -0
  84. package/task-loop.js.map +1 -0
  85. package/tools.js +8 -0
@@ -0,0 +1,32 @@
1
+ import { RequestClientType } from "../common";
2
+ import { PostMessageble } from "../hook/adapter";
3
+ export declare class PanelController {
4
+ savePanel(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
5
+ code: number;
6
+ msg: string;
7
+ }>;
8
+ loadPanel(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
9
+ code: number;
10
+ msg: import("./panel.dto").SaveTab;
11
+ }>;
12
+ setSystemPrompt(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
13
+ code: number;
14
+ msg: string;
15
+ }>;
16
+ deleteSystemPrompt(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
17
+ code: number;
18
+ msg: string;
19
+ }>;
20
+ saveSystemPrompts(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
21
+ code: number;
22
+ msg: string;
23
+ }>;
24
+ loadSystemPrompts(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
25
+ code: number;
26
+ msg: {
27
+ name: string;
28
+ content: string;
29
+ }[];
30
+ }>;
31
+ }
32
+ //# sourceMappingURL=panel.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.controller.d.ts","sourceRoot":"","sources":["../../src/panel/panel.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,qBAAa,eAAe;IAElB,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAYvE,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAWvE,eAAe,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAgB7E,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAUhF,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAkB/E,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;;;;CAgBxF"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PanelController = void 0;
19
+ const common_1 = require("../common");
20
+ const db_1 = require("../hook/db");
21
+ const panel_service_1 = require("./panel.service");
22
+ class PanelController {
23
+ savePanel(client, data, webview) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const serverInfo = client === null || client === void 0 ? void 0 : client.getServerVersion();
26
+ (0, panel_service_1.saveTabSaveConfig)(serverInfo, data);
27
+ return {
28
+ code: 200,
29
+ msg: 'Settings saved successfully'
30
+ };
31
+ });
32
+ }
33
+ loadPanel(client, data, webview) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const serverInfo = client === null || client === void 0 ? void 0 : client.getServerVersion();
36
+ const config = (0, panel_service_1.loadTabSaveConfig)(serverInfo);
37
+ return {
38
+ code: 200,
39
+ msg: config
40
+ };
41
+ });
42
+ }
43
+ setSystemPrompt(client, data, webview) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const { name, content } = data;
46
+ yield db_1.systemPromptDB.insert({
47
+ id: name,
48
+ name,
49
+ content
50
+ });
51
+ return {
52
+ code: 200,
53
+ msg: 'Settings saved successfully'
54
+ };
55
+ });
56
+ }
57
+ deleteSystemPrompt(client, data, webview) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const { name } = data;
60
+ yield db_1.systemPromptDB.delete(name);
61
+ return {
62
+ code: 200,
63
+ msg: 'Settings saved successfully'
64
+ };
65
+ });
66
+ }
67
+ saveSystemPrompts(client, data, webview) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const { prompts } = data;
70
+ yield Promise.all(prompts.map((prompt) => {
71
+ db_1.systemPromptDB.insert({
72
+ id: prompt.name,
73
+ name: prompt.name,
74
+ content: prompt.content
75
+ });
76
+ }));
77
+ return {
78
+ code: 200,
79
+ msg: 'Settings saved successfully'
80
+ };
81
+ });
82
+ }
83
+ loadSystemPrompts(client, data, webview) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const queryPrompts = yield db_1.systemPromptDB.findAll();
86
+ const prompts = [];
87
+ for (const prompt of queryPrompts) {
88
+ prompts.push({
89
+ name: prompt.name,
90
+ content: prompt.content
91
+ });
92
+ }
93
+ return {
94
+ code: 200,
95
+ msg: prompts
96
+ };
97
+ });
98
+ }
99
+ }
100
+ exports.PanelController = PanelController;
101
+ __decorate([
102
+ (0, common_1.Controller)('panel/save')
103
+ ], PanelController.prototype, "savePanel", null);
104
+ __decorate([
105
+ (0, common_1.Controller)('panel/load')
106
+ ], PanelController.prototype, "loadPanel", null);
107
+ __decorate([
108
+ (0, common_1.Controller)('system-prompts/set')
109
+ ], PanelController.prototype, "setSystemPrompt", null);
110
+ __decorate([
111
+ (0, common_1.Controller)('system-prompts/delete')
112
+ ], PanelController.prototype, "deleteSystemPrompt", null);
113
+ __decorate([
114
+ (0, common_1.Controller)('system-prompts/save')
115
+ ], PanelController.prototype, "saveSystemPrompts", null);
116
+ __decorate([
117
+ (0, common_1.Controller)('system-prompts/load')
118
+ ], PanelController.prototype, "loadSystemPrompts", null);
@@ -0,0 +1,12 @@
1
+ export interface SaveTabItem {
2
+ name: string;
3
+ icon: string;
4
+ type: string;
5
+ componentIndex: number;
6
+ storage: Record<string, any>;
7
+ }
8
+ export interface SaveTab {
9
+ tabs: SaveTabItem[];
10
+ currentIndex: number;
11
+ }
12
+ //# sourceMappingURL=panel.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.dto.d.ts","sourceRoot":"","sources":["../../src/panel/panel.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,WAAW,EAAE,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;CACpB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { IServerVersion } from '../mcp/client.dto';
2
+ import { SaveTab } from './panel.dto';
3
+ import { IConfig } from '../setting/setting.dto';
4
+ export declare function loadTabSaveConfig(serverInfo: IServerVersion): SaveTab;
5
+ export declare function saveTabSaveConfig(serverInfo: IServerVersion, config: Partial<IConfig>): void;
6
+ //# sourceMappingURL=panel.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.service.d.ts","sourceRoot":"","sources":["../../src/panel/panel.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAyCjD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAcrE;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAS5F"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadTabSaveConfig = loadTabSaveConfig;
37
+ exports.saveTabSaveConfig = saveTabSaveConfig;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const setting_1 = require("../hook/setting");
41
+ const DEFAULT_TABS = {
42
+ tabs: [],
43
+ currentIndex: -1
44
+ };
45
+ function getTabSavePath(serverInfo) {
46
+ const { name = 'untitle', version = '0.0.0' } = serverInfo || {};
47
+ // 过滤所有不能成为路径的字符
48
+ const escapeName = name.replace(/[\\/:*?"<>|]/g, '_');
49
+ const tabSaveName = `tabs.${escapeName}.json`;
50
+ // 如果是 vscode 插件下,则修改为 ~/.vscode/openmcp.json
51
+ if (setting_1.VSCODE_WORKSPACE) {
52
+ // 在 VSCode 插件环境下
53
+ const configDir = path.join(setting_1.VSCODE_WORKSPACE, '.vscode');
54
+ if (!fs.existsSync(configDir)) {
55
+ fs.mkdirSync(configDir, { recursive: true });
56
+ }
57
+ return path.join(configDir, tabSaveName);
58
+ }
59
+ return tabSaveName;
60
+ }
61
+ function createSaveTabConfig(serverInfo) {
62
+ const configPath = getTabSavePath(serverInfo);
63
+ const configDir = path.dirname(configPath);
64
+ // 确保配置目录存在
65
+ if (configDir && !fs.existsSync(configDir)) {
66
+ fs.mkdirSync(configDir, { recursive: true });
67
+ }
68
+ // 写入默认配置
69
+ fs.writeFileSync(configPath, JSON.stringify(DEFAULT_TABS, null, 2), 'utf-8');
70
+ return DEFAULT_TABS;
71
+ }
72
+ function loadTabSaveConfig(serverInfo) {
73
+ const tabSavePath = getTabSavePath(serverInfo);
74
+ if (!fs.existsSync(tabSavePath)) {
75
+ return createSaveTabConfig(serverInfo);
76
+ }
77
+ try {
78
+ const configData = fs.readFileSync(tabSavePath, 'utf-8');
79
+ return JSON.parse(configData);
80
+ }
81
+ catch (error) {
82
+ console.error('Error loading config file, creating new one:', error);
83
+ return createSaveTabConfig(serverInfo);
84
+ }
85
+ }
86
+ function saveTabSaveConfig(serverInfo, config) {
87
+ const tabSavePath = getTabSavePath(serverInfo);
88
+ try {
89
+ fs.writeFileSync(tabSavePath, JSON.stringify(config, null, 2), 'utf-8');
90
+ }
91
+ catch (error) {
92
+ console.error('Error saving config file:', error);
93
+ throw error;
94
+ }
95
+ }
@@ -0,0 +1,23 @@
1
+ import { RequestClientType } from "../common";
2
+ import { PostMessageble } from "../hook/adapter";
3
+ export declare class SettingController {
4
+ saveSetting(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
5
+ code: number;
6
+ msg: string;
7
+ }>;
8
+ loadSetting(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
9
+ code: number;
10
+ msg: import("./setting.dto").IConfig;
11
+ }>;
12
+ setTourController(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
13
+ code: number;
14
+ msg: string;
15
+ }>;
16
+ getTourController(client: RequestClientType, data: any, webview: PostMessageble): Promise<{
17
+ code: number;
18
+ msg: {
19
+ userHasReadGuide: boolean;
20
+ };
21
+ }>;
22
+ }
23
+ //# sourceMappingURL=setting.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.controller.d.ts","sourceRoot":"","sources":["../../src/setting/setting.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,qBAAa,iBAAiB;IAGpB,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAWzE,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAWzE,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;IAa/E,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc;;;;;;CAYxF"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SettingController = void 0;
19
+ const common_1 = require("../common");
20
+ const setting_service_1 = require("./setting.service");
21
+ class SettingController {
22
+ saveSetting(client, data, webview) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ (0, setting_service_1.saveSetting)(data);
25
+ console.log('Settings saved successfully');
26
+ return {
27
+ code: 200,
28
+ msg: 'Settings saved successfully'
29
+ };
30
+ });
31
+ }
32
+ loadSetting(client, data, webview) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ console.log('enter loading');
35
+ const config = (0, setting_service_1.loadSetting)();
36
+ return {
37
+ code: 200,
38
+ msg: config
39
+ };
40
+ });
41
+ }
42
+ setTourController(client, data, webview) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const { userHasReadGuide } = data;
45
+ (0, setting_service_1.setTour)(userHasReadGuide);
46
+ return {
47
+ code: 200,
48
+ msg: 'setTour success'
49
+ };
50
+ });
51
+ }
52
+ getTourController(client, data, webview) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ console.log('enter');
55
+ const { userHasReadGuide } = (0, setting_service_1.getTour)();
56
+ return {
57
+ code: 200,
58
+ msg: {
59
+ userHasReadGuide
60
+ }
61
+ };
62
+ });
63
+ }
64
+ }
65
+ exports.SettingController = SettingController;
66
+ __decorate([
67
+ (0, common_1.Controller)('setting/save')
68
+ ], SettingController.prototype, "saveSetting", null);
69
+ __decorate([
70
+ (0, common_1.Controller)('setting/load')
71
+ ], SettingController.prototype, "loadSetting", null);
72
+ __decorate([
73
+ (0, common_1.Controller)('setting/set-tour')
74
+ ], SettingController.prototype, "setTourController", null);
75
+ __decorate([
76
+ (0, common_1.Controller)('setting/get-tour')
77
+ ], SettingController.prototype, "getTourController", null);
@@ -0,0 +1,5 @@
1
+ export interface IConfig {
2
+ MODEL_INDEX: number;
3
+ [key: string]: any;
4
+ }
5
+ //# sourceMappingURL=setting.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.dto.d.ts","sourceRoot":"","sources":["../../src/setting/setting.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { IConfig } from './setting.dto';
2
+ export declare function loadSetting(): IConfig;
3
+ export declare function saveSetting(config: Partial<IConfig>): void;
4
+ export declare function getTour(): {
5
+ userHasReadGuide: boolean;
6
+ };
7
+ export declare function setTour(userHasReadGuide: boolean): void;
8
+ //# sourceMappingURL=setting.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.service.d.ts","sourceRoot":"","sources":["../../src/setting/setting.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAyCxC,wBAAgB,WAAW,IAAI,OAAO,CAcrC;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAU1D;AAED,wBAAgB,OAAO;;EAatB;AAED,wBAAgB,OAAO,CAAC,gBAAgB,EAAE,OAAO,GAAG,IAAI,CASvD"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadSetting = loadSetting;
37
+ exports.saveSetting = saveSetting;
38
+ exports.getTour = getTour;
39
+ exports.setTour = setTour;
40
+ const fs = __importStar(require("fs"));
41
+ const os = __importStar(require("os"));
42
+ const path = __importStar(require("path"));
43
+ const llm_1 = require("../hook/llm");
44
+ function getConfigurationPath() {
45
+ const homeDir = os.homedir();
46
+ const configDir = path.join(homeDir, '.openmcp');
47
+ if (!fs.existsSync(configDir)) {
48
+ fs.mkdirSync(configDir, { recursive: true });
49
+ }
50
+ return path.join(configDir, 'setting.json');
51
+ }
52
+ function getDefaultLanguage() {
53
+ if (process.env.VSCODE_PID) {
54
+ // TODO: 获取 vscode 内部的语言
55
+ }
56
+ return 'zh';
57
+ }
58
+ const DEFAULT_CONFIG = {
59
+ MODEL_INDEX: 0,
60
+ LLM_INFO: llm_1.llms,
61
+ LANG: getDefaultLanguage(), MCP_TIMEOUT_SEC: 60
62
+ };
63
+ function createConfig() {
64
+ const configPath = getConfigurationPath();
65
+ const configDir = path.dirname(configPath);
66
+ // 确保配置目录存在
67
+ if (configDir && !fs.existsSync(configDir)) {
68
+ fs.mkdirSync(configDir, { recursive: true });
69
+ }
70
+ // 写入默认配置
71
+ fs.writeFileSync(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
72
+ return DEFAULT_CONFIG;
73
+ }
74
+ function loadSetting() {
75
+ const configPath = getConfigurationPath();
76
+ if (!fs.existsSync(configPath)) {
77
+ return createConfig();
78
+ }
79
+ try {
80
+ const configData = fs.readFileSync(configPath, 'utf-8');
81
+ return JSON.parse(configData);
82
+ }
83
+ catch (error) {
84
+ console.error('Error loading config file, creating new one:', error);
85
+ return createConfig();
86
+ }
87
+ }
88
+ function saveSetting(config) {
89
+ const configPath = getConfigurationPath();
90
+ console.log('save to ' + configPath);
91
+ try {
92
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
93
+ }
94
+ catch (error) {
95
+ console.error('Error saving config file:', error);
96
+ throw error;
97
+ }
98
+ }
99
+ function getTour() {
100
+ const configPath = getConfigurationPath();
101
+ const KEY = path.join(path.dirname(configPath), 'KEY');
102
+ console.log(KEY);
103
+ if (!fs.existsSync(KEY)) {
104
+ return {
105
+ userHasReadGuide: false
106
+ };
107
+ }
108
+ return {
109
+ userHasReadGuide: true
110
+ };
111
+ }
112
+ function setTour(userHasReadGuide) {
113
+ const configPath = getConfigurationPath();
114
+ const KEY = path.join(path.dirname(configPath), 'KEY');
115
+ if (userHasReadGuide) {
116
+ const key = `直面恐惧,创造未来
117
+ Face your fears, create the future
118
+ 恐怖に直面し、未来を創り出す`;
119
+ fs.writeFileSync(KEY, key, 'utf-8');
120
+ }
121
+ }
package/task-loop.d.ts ADDED
@@ -0,0 +1,105 @@
1
+ /* eslint-disable */
2
+ import type { OpenAI } from 'openai';
3
+
4
+ export type ChatCompletionChunk = OpenAI.Chat.Completions.ChatCompletionChunk;
5
+ export type ChatCompletionCreateParamsBase = OpenAI.Chat.Completions.ChatCompletionCreateParams & { id?: string };
6
+
7
+ export interface TaskLoopOptions {
8
+ maxEpochs?: number;
9
+ maxJsonParseRetry?: number;
10
+ adapter?: any;
11
+ }
12
+
13
+ export type Ref<T> = {
14
+ value: T;
15
+ };
16
+
17
+ export interface ToolCall {
18
+ id?: string;
19
+ index?: number;
20
+ type: string;
21
+ function: {
22
+ name: string;
23
+ arguments: string;
24
+ }
25
+ }
26
+
27
+ export enum MessageState {
28
+ ServerError = 'server internal error',
29
+ ReceiveChunkError = 'receive chunk error',
30
+ Timeout = 'timeout',
31
+ MaxEpochs = 'max epochs',
32
+ Unknown = 'unknown error',
33
+ Abort = 'abort',
34
+ ToolCall = 'tool call failed',
35
+ None = 'none',
36
+ Success = 'success',
37
+ ParseJsonError = 'parse json error'
38
+ }
39
+
40
+ export interface IErrorMssage {
41
+ state: MessageState;
42
+ msg: string;
43
+ }
44
+
45
+ export interface IDoConversationResult {
46
+ stop: boolean;
47
+ }
48
+
49
+ /**
50
+ * @description 对任务循环进行的抽象封装
51
+ */
52
+ export class TaskLoop {
53
+ private streamingContent;
54
+ private streamingToolCalls;
55
+ private readonly taskOptions;
56
+ private bridge;
57
+ private currentChatId;
58
+ private onError;
59
+ private onChunk;
60
+ private onDone;
61
+ private onEpoch;
62
+ private completionUsage;
63
+ private llmConfig;
64
+ constructor(taskOptions?: TaskLoopOptions);
65
+ private handleChunkDeltaContent;
66
+ private handleChunkDeltaToolCalls;
67
+ private handleChunkUsage;
68
+ private doConversation;
69
+ makeChatData(tabStorage: any): ChatCompletionCreateParamsBase | undefined;
70
+ abort(): void;
71
+ registerOnError(handler: (msg: IErrorMssage) => void): void;
72
+ registerOnChunk(handler: (chunk: ChatCompletionChunk) => void): void;
73
+ registerOnDone(handler: () => void): void;
74
+ registerOnEpoch(handler: () => void): void;
75
+ setMaxEpochs(maxEpochs: number): void;
76
+ /**
77
+ * @description 设置当前的 LLM 配置,用于 nodejs 环境运行
78
+ * @param config
79
+ * @example
80
+ * setLlmConfig({
81
+ * id: 'openai',
82
+ * baseUrl: 'https://api.openai.com/v1',
83
+ * userToken: 'sk-xxx',
84
+ * userModel: 'gpt-3.5-turbo',
85
+ * })
86
+ */
87
+ setLlmConfig(config: any): void;
88
+ getLlmConfig(): any;
89
+ bindStreaming(content: Ref<string>, toolCalls: Ref<ToolCall[]>): void;
90
+ connectToService(): Promise<void>;
91
+ /**
92
+ * @description 开启循环,异步更新 DOM
93
+ */
94
+ start(tabStorage: any, userMessage: string): Promise<void>;
95
+ }
96
+
97
+ export declare const getToolSchema: any;
98
+ export declare const useMessageBridge: any;
99
+ export declare const llmManager: any;
100
+ export declare const llms: any;
101
+ export declare const pinkLog: any;
102
+ export declare const redLog: any;
103
+ export declare const ElMessage: any;
104
+ export declare const handleToolCalls: any;
105
+ export declare const getPlatform: any;