wechaty-web-panel 1.6.112 → 1.6.113

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 (109) hide show
  1. package/dist/bot/chatgpt/index.js +235 -0
  2. package/dist/bot/coze/sdk/index.js +110 -0
  3. package/dist/bot/dify/sdk/index.js +461 -0
  4. package/dist/bot/dify/sdk/office.js +319 -0
  5. package/dist/bot/fastgpt/index.js +98 -0
  6. package/dist/bot/qanything/index.js +136 -0
  7. package/dist/botInstance/coze.js +167 -0
  8. package/dist/botInstance/cozev3.js +157 -0
  9. package/dist/botInstance/dify.js +160 -0
  10. package/dist/botInstance/fastgpt.js +130 -0
  11. package/dist/botInstance/gpt4v.js +95 -0
  12. package/dist/botInstance/officialOpenAi.js +186 -0
  13. package/dist/botInstance/qany.js +144 -0
  14. package/dist/botInstance/sdk/chatGPT4V.js +89 -0
  15. package/dist/botInstance/sdk/coze.js +200 -0
  16. package/dist/botInstance/sdk/difyClient.js +354 -0
  17. package/dist/botInstance/sdk/pTimeout.js +97 -0
  18. package/dist/botInstance/sdk/qanything.js +137 -0
  19. package/dist/botInstance/sdk/quick-lru.js +237 -0
  20. package/dist/common/hook.js +66 -0
  21. package/dist/common/index.js +513 -0
  22. package/dist/common/multiReply.js +158 -0
  23. package/dist/common/reply.js +23 -0
  24. package/dist/const/puppet-type.js +71 -0
  25. package/dist/db/aiDb.js +27 -0
  26. package/dist/db/aichatDb.js +84 -0
  27. package/dist/db/chatHistory.js +137 -0
  28. package/dist/db/configDb.js +97 -0
  29. package/dist/db/global.js +62 -0
  30. package/dist/db/gptConfig.js +85 -0
  31. package/dist/db/nedb.js +88 -0
  32. package/dist/db/puppetDb.js +58 -0
  33. package/dist/db/roomDb.js +83 -0
  34. package/dist/db/rssConfig.js +82 -0
  35. package/dist/db/rssHistory.js +88 -0
  36. package/dist/db/userDb.js +27 -0
  37. package/dist/handlers/on-callback-message.js +183 -0
  38. package/dist/handlers/on-error.js +5 -0
  39. package/dist/handlers/on-friend.js +62 -0
  40. package/dist/handlers/on-heartbeat.js +20 -0
  41. package/dist/handlers/on-login.js +58 -0
  42. package/dist/handlers/on-logout.js +17 -0
  43. package/dist/handlers/on-message.js +644 -0
  44. package/dist/handlers/on-ready.js +36 -0
  45. package/dist/handlers/on-record-message.js +56 -0
  46. package/dist/handlers/on-roomjoin.js +42 -0
  47. package/dist/handlers/on-roomleave.js +12 -0
  48. package/dist/handlers/on-roomtopic.js +16 -0
  49. package/dist/handlers/on-scan.js +64 -0
  50. package/dist/handlers/on-verifycode.js +42 -0
  51. package/dist/index.js +81 -69306
  52. package/dist/lib/contentCensor.js +23 -0
  53. package/dist/lib/index.js +562 -0
  54. package/dist/lib/oss.js +43 -0
  55. package/dist/lib/s3oss.js +33 -0
  56. package/dist/mcp/mcp-server.js +26 -0
  57. package/dist/mcp/src/config/database.js +51 -0
  58. package/dist/mcp/src/index.js +238 -0
  59. package/dist/mcp/src/mcp/schemas.js +178 -0
  60. package/dist/mcp/src/mcp/server.js +421 -0
  61. package/dist/mcp/src/mcp/streamable-server.js +690 -0
  62. package/dist/mcp/src/models/ChatMessage.js +151 -0
  63. package/dist/mcp/src/models/Friend.js +64 -0
  64. package/dist/mcp/src/models/Group.js +55 -0
  65. package/dist/mcp/src/models/GroupMember.js +67 -0
  66. package/dist/mcp/src/models/index.js +27 -0
  67. package/dist/mcp/src/scripts/migrate.js +21 -0
  68. package/dist/mcp/src/services/ChatDataService.js +284 -0
  69. package/dist/mcp/src/services/McpService.js +521 -0
  70. package/dist/mcp/src/services/McpTools.js +504 -0
  71. package/dist/mcp/streamable-examples.js +283 -0
  72. package/dist/mcp/streamable-server.js +79 -0
  73. package/dist/mcp/test-mcp.js +64 -0
  74. package/dist/mcp/test-streamable-server.js +86 -0
  75. package/dist/package-json.js +89 -0
  76. package/dist/proxy/aibotk.js +829 -0
  77. package/dist/proxy/api.js +431 -0
  78. package/dist/proxy/apib.js +587 -0
  79. package/dist/proxy/bot/chatgpt.js +38 -0
  80. package/dist/proxy/bot/coze.js +38 -0
  81. package/dist/proxy/bot/cozev3.js +38 -0
  82. package/dist/proxy/bot/dify.js +38 -0
  83. package/dist/proxy/bot/dispatch.js +81 -0
  84. package/dist/proxy/bot/fastgpt.js +27 -0
  85. package/dist/proxy/bot/qany.js +27 -0
  86. package/dist/proxy/config.js +14 -0
  87. package/dist/proxy/cozeAi.js +60 -0
  88. package/dist/proxy/cozeV3Ai.js +60 -0
  89. package/dist/proxy/difyAi.js +58 -0
  90. package/dist/proxy/fastgpt.js +55 -0
  91. package/dist/proxy/mqtt.js +275 -0
  92. package/dist/proxy/multimodal.js +122 -0
  93. package/dist/proxy/openAi.js +63 -0
  94. package/dist/proxy/outapi.js +62 -0
  95. package/dist/proxy/qAnyAi.js +57 -0
  96. package/dist/proxy/superagent.js +200 -0
  97. package/dist/proxy/tencent-open.js +255 -0
  98. package/dist/service/event-dispatch-service.js +309 -0
  99. package/dist/service/gpt4vService.js +45 -0
  100. package/dist/service/msg-filter-service.js +121 -0
  101. package/dist/service/msg-filters.js +645 -0
  102. package/dist/service/room-async-service.js +455 -0
  103. package/dist/task/index.js +535 -0
  104. package/dist/task/rss.js +174 -0
  105. package/package.json +2 -2
  106. package/src/package-json.js +2 -2
  107. package/tsconfig.json +3 -12
  108. package/dist/index.d.ts +0 -9
  109. package/tsconfig.cjs.json +0 -12
@@ -0,0 +1,137 @@
1
+ import axios from 'axios';
2
+ const BASE_URL = 'https://openapi.youdao.com';
3
+ const routes = {
4
+ // 发起对话
5
+ creatChat: {
6
+ method: 'POST', url: () => '/q_anything/api/bot/chat_stream',
7
+ }
8
+ };
9
+ class QAnyClient {
10
+ constructor({ apiKey, baseUrl = BASE_URL, debug = false, stream = true, botId }) {
11
+ this.apiKey = apiKey;
12
+ this.baseUrl = baseUrl || BASE_URL;
13
+ this.debug = debug;
14
+ this.stream = stream;
15
+ this.botId = botId;
16
+ this.history = [];
17
+ }
18
+ updateApiKey(apiKey) {
19
+ this.apiKey = apiKey;
20
+ }
21
+ async sendRequest({ method, endpoint, data, params, stream = false, headerParams = {}, timeoutMs = 100 * 1000 }) {
22
+ const headers = {
23
+ ...{
24
+ Authorization: `${this.apiKey}`,
25
+ 'Content-Type': 'application/json',
26
+ },
27
+ ...headerParams,
28
+ };
29
+ const url = `${this.baseUrl}${endpoint}`;
30
+ let response;
31
+ if (this.debug) {
32
+ console.log('request', url, { data, headers, params });
33
+ }
34
+ if (!stream) {
35
+ response = await axios.request({
36
+ method,
37
+ url,
38
+ data: data || {},
39
+ params: params || {},
40
+ headers,
41
+ timeout: timeoutMs,
42
+ });
43
+ }
44
+ else {
45
+ response = await axios({
46
+ method,
47
+ url,
48
+ data,
49
+ params,
50
+ headers,
51
+ responseType: 'stream',
52
+ });
53
+ }
54
+ return response;
55
+ }
56
+ }
57
+ class QAnyApi extends QAnyClient {
58
+ async sendMessage(query, { needHistory, user, timeoutMs = 100 * 1000, variables, }) {
59
+ if (needHistory) {
60
+ this.history = this.history.slice(-2);
61
+ }
62
+ else {
63
+ this.history = [];
64
+ }
65
+ const data = {
66
+ uuid: this.botId,
67
+ question: query,
68
+ history: this.history
69
+ };
70
+ const res = await this.sendRequest({
71
+ method: routes.creatChat.method,
72
+ endpoint: routes.creatChat.url(),
73
+ data,
74
+ stream: this.stream,
75
+ timeoutMs,
76
+ });
77
+ const asyncSSE = stream => {
78
+ return new Promise((resolve, reject) => {
79
+ const answers = [];
80
+ let answer = '';
81
+ let id = '';
82
+ const chunks = [];
83
+ try {
84
+ stream.on('data', data => {
85
+ chunks.push(data);
86
+ });
87
+ stream.on('end', async () => {
88
+ const result = Buffer.concat(chunks);
89
+ console.log('思考完毕,准备回复');
90
+ const streams = new TextDecoder('utf-8').decode(result, { stream: true }).split('\n');
91
+ for (const stream of streams) {
92
+ let res = {};
93
+ try {
94
+ res = JSON.parse(stream.substring(5)) || {};
95
+ }
96
+ catch (e) {
97
+ // console.log('json 解析错误,不影响输出', stream)
98
+ try {
99
+ res = JSON.parse(stream) || {};
100
+ }
101
+ catch (e) {
102
+ // console.log('json 解析错误,不影响输出', stream)
103
+ }
104
+ }
105
+ if (res.errorCode && res.errorCode !== '0') {
106
+ console.log('QAnything 请求报错', res.msg);
107
+ answer = res.msg;
108
+ }
109
+ else if (res.errorCode) {
110
+ if (res.result.response && !res.result.singleQAId) {
111
+ answers.push(res.result.response);
112
+ }
113
+ if (res.result.singleQAId) {
114
+ this.history = res.result.history;
115
+ id = res.result.singleQAId;
116
+ answer = res.result.response;
117
+ }
118
+ }
119
+ }
120
+ if (!answer) {
121
+ answer = answers.join('');
122
+ }
123
+ resolve({ text: answer, conversationId: '', id: id });
124
+ });
125
+ }
126
+ catch (e) {
127
+ resolve({ text: `agent 出错,${e}`, conversationId: '', files: [] });
128
+ }
129
+ });
130
+ };
131
+ console.log('进入流式输出模式,请耐心等待模型的思考');
132
+ const result = await asyncSSE(res.data);
133
+ return result;
134
+ }
135
+ }
136
+ export { QAnyApi };
137
+ //# sourceMappingURL=qanything.js.map
@@ -0,0 +1,237 @@
1
+ export default class QuickLRU extends Map {
2
+ constructor(options = {}) {
3
+ super();
4
+ if (!(options.maxSize && options.maxSize > 0)) {
5
+ throw new TypeError('`maxSize` must be a number greater than 0');
6
+ }
7
+ if (typeof options.maxAge === 'number' && options.maxAge === 0) {
8
+ throw new TypeError('`maxAge` must be a number greater than 0');
9
+ }
10
+ // TODO: Use private class fields when ESLint supports them.
11
+ this.maxSize = options.maxSize;
12
+ this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
13
+ this.onEviction = options.onEviction;
14
+ this.cache = new Map();
15
+ this.oldCache = new Map();
16
+ this._size = 0;
17
+ }
18
+ // TODO: Use private class methods when targeting Node.js 16.
19
+ _emitEvictions(cache) {
20
+ if (typeof this.onEviction !== 'function') {
21
+ return;
22
+ }
23
+ for (const [key, item] of cache) {
24
+ this.onEviction(key, item.value);
25
+ }
26
+ }
27
+ _deleteIfExpired(key, item) {
28
+ if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
29
+ if (typeof this.onEviction === 'function') {
30
+ this.onEviction(key, item.value);
31
+ }
32
+ return this.delete(key);
33
+ }
34
+ return false;
35
+ }
36
+ _getOrDeleteIfExpired(key, item) {
37
+ const deleted = this._deleteIfExpired(key, item);
38
+ if (deleted === false) {
39
+ return item.value;
40
+ }
41
+ }
42
+ _getItemValue(key, item) {
43
+ return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
44
+ }
45
+ _peek(key, cache) {
46
+ const item = cache.get(key);
47
+ return this._getItemValue(key, item);
48
+ }
49
+ _set(key, value) {
50
+ this.cache.set(key, value);
51
+ this._size++;
52
+ if (this._size >= this.maxSize) {
53
+ this._size = 0;
54
+ this._emitEvictions(this.oldCache);
55
+ this.oldCache = this.cache;
56
+ this.cache = new Map();
57
+ }
58
+ }
59
+ _moveToRecent(key, item) {
60
+ this.oldCache.delete(key);
61
+ this._set(key, item);
62
+ }
63
+ *_entriesAscending() {
64
+ for (const item of this.oldCache) {
65
+ const [key, value] = item;
66
+ if (!this.cache.has(key)) {
67
+ const deleted = this._deleteIfExpired(key, value);
68
+ if (deleted === false) {
69
+ yield item;
70
+ }
71
+ }
72
+ }
73
+ for (const item of this.cache) {
74
+ const [key, value] = item;
75
+ const deleted = this._deleteIfExpired(key, value);
76
+ if (deleted === false) {
77
+ yield item;
78
+ }
79
+ }
80
+ }
81
+ get(key) {
82
+ if (this.cache.has(key)) {
83
+ const item = this.cache.get(key);
84
+ return this._getItemValue(key, item);
85
+ }
86
+ if (this.oldCache.has(key)) {
87
+ const item = this.oldCache.get(key);
88
+ if (this._deleteIfExpired(key, item) === false) {
89
+ this._moveToRecent(key, item);
90
+ return item.value;
91
+ }
92
+ }
93
+ }
94
+ set(key, value, { maxAge = this.maxAge } = {}) {
95
+ const expiry = typeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY ?
96
+ Date.now() + maxAge :
97
+ undefined;
98
+ if (this.cache.has(key)) {
99
+ this.cache.set(key, {
100
+ value,
101
+ expiry
102
+ });
103
+ }
104
+ else {
105
+ this._set(key, { value, expiry });
106
+ }
107
+ }
108
+ has(key) {
109
+ if (this.cache.has(key)) {
110
+ return !this._deleteIfExpired(key, this.cache.get(key));
111
+ }
112
+ if (this.oldCache.has(key)) {
113
+ return !this._deleteIfExpired(key, this.oldCache.get(key));
114
+ }
115
+ return false;
116
+ }
117
+ peek(key) {
118
+ if (this.cache.has(key)) {
119
+ return this._peek(key, this.cache);
120
+ }
121
+ if (this.oldCache.has(key)) {
122
+ return this._peek(key, this.oldCache);
123
+ }
124
+ }
125
+ delete(key) {
126
+ const deleted = this.cache.delete(key);
127
+ if (deleted) {
128
+ this._size--;
129
+ }
130
+ return this.oldCache.delete(key) || deleted;
131
+ }
132
+ clear() {
133
+ this.cache.clear();
134
+ this.oldCache.clear();
135
+ this._size = 0;
136
+ }
137
+ resize(newSize) {
138
+ if (!(newSize && newSize > 0)) {
139
+ throw new TypeError('`maxSize` must be a number greater than 0');
140
+ }
141
+ const items = [...this._entriesAscending()];
142
+ const removeCount = items.length - newSize;
143
+ if (removeCount < 0) {
144
+ this.cache = new Map(items);
145
+ this.oldCache = new Map();
146
+ this._size = items.length;
147
+ }
148
+ else {
149
+ if (removeCount > 0) {
150
+ this._emitEvictions(items.slice(0, removeCount));
151
+ }
152
+ this.oldCache = new Map(items.slice(removeCount));
153
+ this.cache = new Map();
154
+ this._size = 0;
155
+ }
156
+ this.maxSize = newSize;
157
+ }
158
+ *keys() {
159
+ for (const [key] of this) {
160
+ yield key;
161
+ }
162
+ }
163
+ *values() {
164
+ for (const [, value] of this) {
165
+ yield value;
166
+ }
167
+ }
168
+ *[Symbol.iterator]() {
169
+ for (const item of this.cache) {
170
+ const [key, value] = item;
171
+ const deleted = this._deleteIfExpired(key, value);
172
+ if (deleted === false) {
173
+ yield [key, value.value];
174
+ }
175
+ }
176
+ for (const item of this.oldCache) {
177
+ const [key, value] = item;
178
+ if (!this.cache.has(key)) {
179
+ const deleted = this._deleteIfExpired(key, value);
180
+ if (deleted === false) {
181
+ yield [key, value.value];
182
+ }
183
+ }
184
+ }
185
+ }
186
+ *entriesDescending() {
187
+ let items = [...this.cache];
188
+ for (let i = items.length - 1; i >= 0; --i) {
189
+ const item = items[i];
190
+ const [key, value] = item;
191
+ const deleted = this._deleteIfExpired(key, value);
192
+ if (deleted === false) {
193
+ yield [key, value.value];
194
+ }
195
+ }
196
+ items = [...this.oldCache];
197
+ for (let i = items.length - 1; i >= 0; --i) {
198
+ const item = items[i];
199
+ const [key, value] = item;
200
+ if (!this.cache.has(key)) {
201
+ const deleted = this._deleteIfExpired(key, value);
202
+ if (deleted === false) {
203
+ yield [key, value.value];
204
+ }
205
+ }
206
+ }
207
+ }
208
+ *entriesAscending() {
209
+ for (const [key, value] of this._entriesAscending()) {
210
+ yield [key, value.value];
211
+ }
212
+ }
213
+ get size() {
214
+ if (!this._size) {
215
+ return this.oldCache.size;
216
+ }
217
+ let oldCacheSize = 0;
218
+ for (const key of this.oldCache.keys()) {
219
+ if (!this.cache.has(key)) {
220
+ oldCacheSize++;
221
+ }
222
+ }
223
+ return Math.min(this._size + oldCacheSize, this.maxSize);
224
+ }
225
+ entries() {
226
+ return this.entriesAscending();
227
+ }
228
+ forEach(callbackFunction, thisArgument = this) {
229
+ for (const [key, value] of this.entriesAscending()) {
230
+ callbackFunction.call(thisArgument, value, key, this);
231
+ }
232
+ }
233
+ get [Symbol.toStringTag]() {
234
+ return JSON.stringify([...this.entriesAscending()]);
235
+ }
236
+ }
237
+ //# sourceMappingURL=quick-lru.js.map
@@ -0,0 +1,66 @@
1
+ import { delay } from "../lib/index.js";
2
+ /**
3
+ * 指定用户消息转发到群或好友 如果被拦截成功 则不进行其他回复操作
4
+ * @returns {Promise<boolean>}
5
+ */
6
+ export async function privateForward({ that, msg, name, config }) {
7
+ const { role } = config?.userInfo || {};
8
+ const privateForwards = config.privateForwards;
9
+ if (role !== 'vip' || !privateForwards || !privateForwards.length || msg.text().includes('请在手机上查看]'))
10
+ return false;
11
+ let result = false;
12
+ try {
13
+ if (privateForwards.length) {
14
+ for (let item of privateForwards) {
15
+ if (item.name === name) {
16
+ result = true;
17
+ for (let roomName of item.rooms) {
18
+ await delay(500);
19
+ const room = await that.Room.find({ topic: roomName });
20
+ if (!room) {
21
+ console.log(`查找不到群:${roomName},请检查群名是否正确`);
22
+ }
23
+ // 只转发文字
24
+ if (item.type === 1 && msg.type() === 7) {
25
+ room && msg && msg.forward(room);
26
+ }
27
+ else {
28
+ if (msg.type() === 6) {
29
+ const file = await msg.toFileBox();
30
+ room.say(file);
31
+ }
32
+ else {
33
+ room && msg && msg.forward(room);
34
+ }
35
+ }
36
+ }
37
+ for (let contactName of item.contacts) {
38
+ await delay(500);
39
+ const contact = await that.Contact.find({ name: contactName });
40
+ if (!contact) {
41
+ console.log(`查找不到用户:${contactName},请检查用户昵称是否正确`);
42
+ }
43
+ // 只转发文字
44
+ if (item.type === 1 && msg.type() === 7) {
45
+ contact && msg && msg.forward(contact);
46
+ }
47
+ else {
48
+ if (msg.type() === 6) {
49
+ const file = await msg.toFileBox();
50
+ contact.say(file);
51
+ }
52
+ else {
53
+ contact && msg && msg.forward(contact);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ catch (e) {
63
+ console.log("error", e);
64
+ }
65
+ }
66
+ //# sourceMappingURL=hook.js.map