wechaty-web-panel 1.6.59 → 1.6.61

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 (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/src/botInstance/cozev3.d.ts +44 -0
  3. package/dist/cjs/src/botInstance/cozev3.js +133 -0
  4. package/dist/cjs/src/botInstance/{unOfficialOpenAi.d.ts → qany.d.ts} +17 -20
  5. package/dist/cjs/src/botInstance/qany.js +134 -0
  6. package/dist/cjs/src/botInstance/sdk/cozev3.d.ts +55 -0
  7. package/dist/cjs/src/botInstance/sdk/cozev3.js +307 -0
  8. package/dist/cjs/src/botInstance/sdk/qanything.d.ts +35 -0
  9. package/dist/cjs/src/botInstance/sdk/qanything.js +143 -0
  10. package/dist/cjs/src/common/hook.js +7 -1
  11. package/dist/cjs/src/common/index.js +1 -1
  12. package/dist/cjs/src/handlers/on-login.js +1 -1
  13. package/dist/cjs/src/index.js +1 -1
  14. package/dist/cjs/src/lib/index.d.ts +1 -6
  15. package/dist/cjs/src/lib/index.js +23 -4
  16. package/dist/cjs/src/package-json.d.ts +4 -8
  17. package/dist/cjs/src/package-json.js +6 -10
  18. package/dist/cjs/src/proxy/aibotk.js +6 -0
  19. package/dist/{esm/src/proxy/bot/chatgpt-web.d.ts → cjs/src/proxy/bot/cozev3.d.ts} +8 -3
  20. package/dist/cjs/src/proxy/bot/cozev3.js +47 -0
  21. package/dist/cjs/src/proxy/bot/dispatch.js +16 -7
  22. package/dist/cjs/src/proxy/bot/qany.d.ts +10 -0
  23. package/dist/cjs/src/proxy/bot/qany.js +36 -0
  24. package/dist/cjs/src/proxy/cozeV3Ai.d.ts +19 -0
  25. package/dist/cjs/src/proxy/cozeV3Ai.js +66 -0
  26. package/dist/cjs/src/proxy/mqtt.js +4 -2
  27. package/dist/cjs/src/proxy/qAnyAi.d.ts +14 -0
  28. package/dist/cjs/src/proxy/qAnyAi.js +64 -0
  29. package/dist/cjs/src/service/event-dispatch-service.js +19 -7
  30. package/dist/cjs/test/wechat.js +1 -1
  31. package/dist/esm/src/botInstance/cozev3.d.ts +44 -0
  32. package/dist/esm/src/botInstance/cozev3.js +128 -0
  33. package/dist/esm/src/botInstance/{unOfficialOpenAi.d.ts → qany.d.ts} +17 -20
  34. package/dist/esm/src/botInstance/qany.js +129 -0
  35. package/dist/esm/src/botInstance/sdk/cozev3.d.ts +55 -0
  36. package/dist/esm/src/botInstance/sdk/cozev3.js +301 -0
  37. package/dist/esm/src/botInstance/sdk/qanything.d.ts +35 -0
  38. package/dist/esm/src/botInstance/sdk/qanything.js +137 -0
  39. package/dist/esm/src/common/hook.js +7 -1
  40. package/dist/esm/src/common/index.js +1 -1
  41. package/dist/esm/src/handlers/on-login.js +1 -1
  42. package/dist/esm/src/index.js +1 -1
  43. package/dist/esm/src/lib/index.d.ts +1 -6
  44. package/dist/esm/src/lib/index.js +23 -4
  45. package/dist/esm/src/package-json.d.ts +4 -8
  46. package/dist/esm/src/package-json.js +6 -10
  47. package/dist/esm/src/proxy/aibotk.js +6 -0
  48. package/dist/{cjs/src/proxy/bot/chatgpt-web.d.ts → esm/src/proxy/bot/cozev3.d.ts} +8 -3
  49. package/dist/esm/src/proxy/bot/cozev3.js +38 -0
  50. package/dist/esm/src/proxy/bot/dispatch.js +16 -7
  51. package/dist/esm/src/proxy/bot/qany.d.ts +10 -0
  52. package/dist/esm/src/proxy/bot/qany.js +27 -0
  53. package/dist/esm/src/proxy/cozeV3Ai.d.ts +19 -0
  54. package/dist/esm/src/proxy/cozeV3Ai.js +57 -0
  55. package/dist/esm/src/proxy/mqtt.js +4 -2
  56. package/dist/esm/src/proxy/qAnyAi.d.ts +14 -0
  57. package/dist/esm/src/proxy/qAnyAi.js +55 -0
  58. package/dist/esm/src/service/event-dispatch-service.js +19 -7
  59. package/dist/esm/test/wechat.js +1 -1
  60. package/package.json +6 -10
  61. package/dist/cjs/src/botInstance/unOfficialOpenAi.js +0 -136
  62. package/dist/cjs/src/proxy/bot/chatgpt-web.js +0 -47
  63. package/dist/esm/src/botInstance/unOfficialOpenAi.js +0 -131
  64. package/dist/esm/src/proxy/bot/chatgpt-web.js +0 -38
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.60(2024-08-06)
4
+ 1、添加有道QAnything 支持
5
+ 2、添加CozeV3 支持
6
+ 3、更新机器人头像
7
+ 4、增长二维码过期时间
8
+
3
9
  ### V1.6.59(2024-07-12)
4
10
  1、Dify 和 FastGPT 添加备注参数,可以获取用户的备注信息,更加个性化
5
11
 
@@ -0,0 +1,44 @@
1
+ export default CozeV3Ai;
2
+ declare class CozeV3Ai {
3
+ constructor(config?: {
4
+ isAiAgent: boolean;
5
+ showDownloadUrl: boolean;
6
+ token: string;
7
+ proxyPass: string;
8
+ showQuestion: boolean;
9
+ timeoutMs: number;
10
+ promotId: string;
11
+ systemMessage: string;
12
+ });
13
+ cozeV3Chat: CozeV3Api | null;
14
+ config: {
15
+ isAiAgent: boolean;
16
+ showDownloadUrl: boolean;
17
+ token: string;
18
+ proxyPass: string;
19
+ showQuestion: boolean;
20
+ timeoutMs: number;
21
+ promotId: string;
22
+ systemMessage: string;
23
+ };
24
+ contentCensor: ContentCensor | null;
25
+ chatOption: {};
26
+ eol: string;
27
+ iswindows: boolean;
28
+ init(): Promise<void>;
29
+ /**
30
+ * 重置apikey
31
+ * @return {Promise<void>}
32
+ */
33
+ reset(): Promise<void>;
34
+ getReply({ content, inputs }: {
35
+ content: any;
36
+ inputs: any;
37
+ }, id: any, adminId?: string, systemMessage?: string): Promise<{
38
+ type: number;
39
+ content: any;
40
+ }[]>;
41
+ }
42
+ import { CozeV3Api } from "./sdk/cozev3.js";
43
+ import { ContentCensor } from "../lib/contentCensor.js";
44
+ //# sourceMappingURL=cozev3.d.ts.map
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const cozev3_js_1 = require("./sdk/cozev3.js");
7
+ const aichatDb_js_1 = require("../db/aichatDb.js");
8
+ const aibotk_js_1 = require("../proxy/aibotk.js");
9
+ const contentCensor_js_1 = require("../lib/contentCensor.js");
10
+ const puppet_type_js_1 = require("../const/puppet-type.js");
11
+ const dayjs_1 = __importDefault(require("dayjs"));
12
+ const index_js_1 = require("../lib/index.js");
13
+ class CozeV3Ai {
14
+ constructor(config = {
15
+ isAiAgent: false,
16
+ showDownloadUrl: false,
17
+ token: '',
18
+ proxyPass: '',
19
+ showQuestion: true,
20
+ timeoutMs: 60,
21
+ promotId: '',
22
+ systemMessage: '', // 预设promotion
23
+ }) {
24
+ this.cozeV3Chat = null;
25
+ this.config = { showDownloadUrl: false, isAiAgent: false, ...config };
26
+ this.contentCensor = null;
27
+ this.chatOption = {};
28
+ this.eol = '\n';
29
+ this.iswindows = false;
30
+ }
31
+ async init() {
32
+ this.eol = await (0, puppet_type_js_1.getPuppetEol)();
33
+ this.iswindows = await (0, puppet_type_js_1.isWindowsPlatform)();
34
+ if (this.config.promotId) {
35
+ const promotInfo = await (0, aibotk_js_1.getPromotInfo)(this.config.promotId);
36
+ if (promotInfo) {
37
+ this.config.systemMessage = promotInfo.promot;
38
+ }
39
+ }
40
+ if (this.config.filter) {
41
+ this.contentCensor = new contentCensor_js_1.ContentCensor(this.config.filterConfig);
42
+ }
43
+ const baseOptions = {
44
+ baseUrl: this.config.proxyPass,
45
+ apiKey: this.config.token,
46
+ botId: this.config.botId,
47
+ stream: this.config.stream,
48
+ debug: !!this.config.debug,
49
+ systemMessage: this.config.systemMessage || '',
50
+ };
51
+ console.log(`api请求地址:${this.config.proxyPass}`);
52
+ this.cozeV3Chat = new cozev3_js_1.CozeV3Api({
53
+ ...baseOptions,
54
+ });
55
+ }
56
+ /**
57
+ * 重置apikey
58
+ * @return {Promise<void>}
59
+ */
60
+ reset() {
61
+ this.cozeV3Chat = null;
62
+ }
63
+ async getReply({ content, inputs }, id, adminId = '', systemMessage = '') {
64
+ try {
65
+ if (!this.cozeV3Chat) {
66
+ console.log('启用Coze v3对话平台');
67
+ await this.init();
68
+ }
69
+ if (this.config.filter) {
70
+ const censor = await this.contentCensor.checkText(content);
71
+ if (!censor) {
72
+ console.log(`问题:${content},包含违规词,已拦截`);
73
+ return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
74
+ }
75
+ }
76
+ if (systemMessage || content === 'reset' || content === '重置') {
77
+ console.log('重新更新上下文对话');
78
+ this.chatOption[id] = {};
79
+ if (content === 'reset' || content === '重置') {
80
+ return [{ type: 1, content: '上下文已重置' }];
81
+ }
82
+ }
83
+ const { conversationId, text } = systemMessage ? await this.cozeV3Chat.sendMessage(content, { ...this.chatOption[id], variables: inputs, systemMessage, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id }) : await this.cozeV3Chat.sendMessage(content, { ...this.chatOption[id], variables: inputs, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000, user: id });
84
+ if (this.config.filter) {
85
+ const censor = await this.contentCensor.checkText(text);
86
+ if (!censor) {
87
+ console.log(`回复: ${text},包含违规词,已拦截`);
88
+ return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
89
+ }
90
+ }
91
+ if (this.config.record) {
92
+ void (0, aichatDb_js_1.addAichatRecord)({ contactId: id, adminId, input: content, output: text, time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss') });
93
+ }
94
+ // 保存对话id 对于同一个用户的对话不更新conversationId
95
+ if (!this.chatOption[id]?.conversationId) {
96
+ this.chatOption[id] = {
97
+ conversationId
98
+ };
99
+ }
100
+ let replys = [];
101
+ let message;
102
+ if (this.config.showQuestion) {
103
+ message = `${content}${this.eol}-----------${this.eol}` + (this.iswindows ? text.replaceAll('\n', this.eol) : text);
104
+ }
105
+ else {
106
+ message = this.iswindows ? text.replaceAll('\n', this.eol) : text;
107
+ }
108
+ const imgs = (0, index_js_1.extractImageLinks)(message);
109
+ while (message.length > 1500) {
110
+ replys.push(message.slice(0, 1500));
111
+ message = message.slice(1500);
112
+ }
113
+ replys.push(message);
114
+ replys = replys.map(item => {
115
+ return {
116
+ type: 1,
117
+ content: item.trim()
118
+ };
119
+ });
120
+ if (imgs.length) {
121
+ console.log('提取到内容中的图片', imgs);
122
+ replys = replys.concat(imgs);
123
+ }
124
+ return replys;
125
+ }
126
+ catch (e) {
127
+ console.log('Coze V3 请求报错:' + e);
128
+ return [];
129
+ }
130
+ }
131
+ }
132
+ exports.default = CozeV3Ai;
133
+ //# sourceMappingURL=cozev3.js.map
@@ -1,38 +1,33 @@
1
- export default UnOfficialOpenAi;
2
- declare class UnOfficialOpenAi {
1
+ export default QAnyAi;
2
+ declare class QAnyAi {
3
3
  constructor(config?: {
4
4
  token: string;
5
- debug: boolean;
5
+ botId: string;
6
6
  proxyPass: string;
7
- proxyUrl: string;
8
7
  showQuestion: boolean;
9
- systemMessage: string;
8
+ showSuggestions: boolean;
10
9
  timeoutMs: number;
10
+ promotId: string;
11
+ systemMessage: string;
11
12
  });
12
- chatGPT: {
13
- _accessToken: any;
14
- _apiReverseProxyUrl: any;
15
- _debug: boolean;
16
- _model: any;
17
- _fetch: any;
18
- _headers: any;
19
- accessToken: any;
20
- sendMessage(text: any, opts?: {}): Promise<any>;
21
- } | null;
13
+ qanyChat: QAnyApi | null;
22
14
  config: {
23
15
  token: string;
24
- debug: boolean;
16
+ botId: string;
25
17
  proxyPass: string;
26
- proxyUrl: string;
27
18
  showQuestion: boolean;
28
- systemMessage: string;
19
+ showSuggestions: boolean;
29
20
  timeoutMs: number;
21
+ promotId: string;
22
+ systemMessage: string;
30
23
  };
24
+ contentCensor: ContentCensor | null;
31
25
  chatOption: {};
32
26
  eol: string;
27
+ iswindows: boolean;
33
28
  init(): Promise<void>;
34
29
  /**
35
- * 重置实例
30
+ * 重置apikey
36
31
  * @return {Promise<void>}
37
32
  */
38
33
  reset(): Promise<void>;
@@ -41,4 +36,6 @@ declare class UnOfficialOpenAi {
41
36
  content: any;
42
37
  }[]>;
43
38
  }
44
- //# sourceMappingURL=unOfficialOpenAi.d.ts.map
39
+ import { QAnyApi } from "./sdk/qanything.js";
40
+ import { ContentCensor } from "../lib/contentCensor.js";
41
+ //# sourceMappingURL=qany.d.ts.map
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const qanything_js_1 = require("./sdk/qanything.js");
7
+ const aichatDb_js_1 = require("../db/aichatDb.js");
8
+ const contentCensor_js_1 = require("../lib/contentCensor.js");
9
+ const puppet_type_js_1 = require("../const/puppet-type.js");
10
+ const dayjs_1 = __importDefault(require("dayjs"));
11
+ const index_js_1 = require("../lib/index.js");
12
+ class QAnyAi {
13
+ constructor(config = {
14
+ token: '',
15
+ botId: '',
16
+ proxyPass: '',
17
+ showQuestion: true,
18
+ showSuggestions: false,
19
+ timeoutMs: 180,
20
+ promotId: '',
21
+ systemMessage: '' // 预设promotion
22
+ }) {
23
+ this.qanyChat = null;
24
+ this.config = { ...config };
25
+ this.contentCensor = null;
26
+ this.chatOption = {};
27
+ this.eol = '\n';
28
+ this.iswindows = false;
29
+ }
30
+ async init() {
31
+ this.eol = await (0, puppet_type_js_1.getPuppetEol)();
32
+ this.iswindows = await (0, puppet_type_js_1.isWindowsPlatform)();
33
+ if (this.config.filter) {
34
+ this.contentCensor = new contentCensor_js_1.ContentCensor(this.config.filterConfig);
35
+ }
36
+ const baseOptions = {
37
+ apiKey: this.config.token,
38
+ apiBaseUrl: this.config.proxyPass,
39
+ debug: !!this.config.debug,
40
+ botId: this.config.botId,
41
+ };
42
+ console.log(`api请求地址:${this.config.proxyPass}`);
43
+ this.qanyChat = new qanything_js_1.QAnyApi({
44
+ ...baseOptions,
45
+ });
46
+ }
47
+ /**
48
+ * 重置apikey
49
+ * @return {Promise<void>}
50
+ */
51
+ reset() {
52
+ this.qanyChat = null;
53
+ }
54
+ async getReply(content, uid, adminId = '', systemMessage = '') {
55
+ try {
56
+ if (!this.qanyChat) {
57
+ console.log('启用QAnything对话平台');
58
+ await this.init();
59
+ }
60
+ if (this.config.filter) {
61
+ const censor = await this.contentCensor.checkText(content);
62
+ if (!censor) {
63
+ console.log(`问题:${content},包含违规词,已拦截`);
64
+ return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
65
+ }
66
+ }
67
+ if (content === 'reset' || content === '重置') {
68
+ console.log('重新更新上下文对话');
69
+ this.chatOption[uid] = {
70
+ needHistory: false
71
+ };
72
+ if (content === 'reset' || content === '重置') {
73
+ return [{ type: 1, content: '上下文已重置' }];
74
+ }
75
+ }
76
+ const { text, id } = await this.qanyChat.sendMessage(content, {
77
+ ...this.chatOption[uid],
78
+ timeoutMs: this.config.timeoutMs * 1000 || 180 * 1000,
79
+ user: uid
80
+ });
81
+ if (this.config.filter) {
82
+ const censor = await this.contentCensor.checkText(text);
83
+ if (!censor) {
84
+ console.log(`回复: ${text},包含违规词,已拦截`);
85
+ return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
86
+ }
87
+ }
88
+ if (this.config.record) {
89
+ void (0, aichatDb_js_1.addAichatRecord)({
90
+ contactId: uid,
91
+ adminId,
92
+ input: content,
93
+ output: text,
94
+ time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss')
95
+ });
96
+ }
97
+ // 保存对话id 对于同一个用户的对话不更新conversationId
98
+ this.chatOption[uid] = {
99
+ needHistory: true
100
+ };
101
+ let replys = [];
102
+ let message;
103
+ if (this.config.showQuestion) {
104
+ message = `${content}${this.eol}-----------${this.eol}` + (this.iswindows ? text.replaceAll('\n', this.eol) : text);
105
+ }
106
+ else {
107
+ message = this.iswindows ? text.replaceAll('\n', this.eol) : text;
108
+ }
109
+ const imgs = (0, index_js_1.extractImageLinks)(message);
110
+ while (message.length > 1500) {
111
+ replys.push(message.slice(0, 1500));
112
+ message = message.slice(1500);
113
+ }
114
+ replys.push(message);
115
+ replys = replys.map(item => {
116
+ return {
117
+ type: 1,
118
+ content: item.trim()
119
+ };
120
+ });
121
+ if (imgs.length) {
122
+ console.log('提取到内容中的图片', imgs);
123
+ replys = replys.concat(imgs);
124
+ }
125
+ return replys;
126
+ }
127
+ catch (e) {
128
+ console.log('QAnything请求报错:' + e);
129
+ return [];
130
+ }
131
+ }
132
+ }
133
+ exports.default = QAnyAi;
134
+ //# sourceMappingURL=qany.js.map
@@ -0,0 +1,55 @@
1
+ export class CozeV3Api extends CozeClient {
2
+ sendMessage(query: any, { systemMessage, user, needConversation, conversationId, timeoutMs, files, variables, }: {
3
+ systemMessage: any;
4
+ user: any;
5
+ needConversation?: boolean | undefined;
6
+ conversationId?: null | undefined;
7
+ timeoutMs?: number | undefined;
8
+ files?: null | undefined;
9
+ variables: any;
10
+ }): Promise<any>;
11
+ getConversationMessages({ chatId, timeoutMs, conversationId }: {
12
+ chatId: any;
13
+ timeoutMs: any;
14
+ conversationId: any;
15
+ }): Promise<any>;
16
+ }
17
+ declare class CozeClient {
18
+ constructor({ apiKey, baseUrl, debug, systemMessage, stream, botId }: {
19
+ apiKey: any;
20
+ baseUrl?: string | undefined;
21
+ debug?: boolean | undefined;
22
+ systemMessage?: null | undefined;
23
+ stream?: boolean | undefined;
24
+ botId: any;
25
+ });
26
+ apiKey: any;
27
+ baseUrl: string;
28
+ debug: boolean;
29
+ stream: boolean;
30
+ botId: any;
31
+ systemMessage: any;
32
+ updateApiKey(apiKey: any): void;
33
+ sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
34
+ sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
35
+ method: any;
36
+ endpoint: any;
37
+ data: any;
38
+ params: any;
39
+ stream?: boolean | undefined;
40
+ headerParams?: {} | undefined;
41
+ timeoutMs?: number | undefined;
42
+ }): Promise<import("axios").AxiosResponse<any, any>>;
43
+ getConversationId({ messages, timeoutMs }: {
44
+ messages: any;
45
+ timeoutMs: any;
46
+ }): Promise<any>;
47
+ retrieveStatus({ conversationId, chatId, timeoutMs }: {
48
+ conversationId: any;
49
+ chatId: any;
50
+ timeoutMs: any;
51
+ }): Promise<any>;
52
+ fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
53
+ }
54
+ export {};
55
+ //# sourceMappingURL=cozev3.d.ts.map