wechaty-web-panel 1.6.75 → 1.6.76
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/dist/cjs/src/bot/coze/sdk/index.d.ts +38 -0
- package/dist/cjs/src/bot/coze/sdk/index.js +108 -0
- package/dist/cjs/src/bot/dify/sdk/index.d.ts +167 -0
- package/dist/cjs/src/bot/dify/sdk/index.js +471 -0
- package/dist/cjs/src/bot/dify/sdk/office.d.ts +143 -0
- package/dist/cjs/src/bot/dify/sdk/office.js +329 -0
- package/dist/cjs/src/botInstance/cozev3.d.ts +8 -1
- package/dist/cjs/src/botInstance/cozev3.js +57 -46
- package/dist/cjs/src/botInstance/officialOpenAi.js +4 -0
- package/dist/cjs/src/botInstance/sdk/cozev3.js +12 -4
- package/dist/cjs/src/handlers/on-message.js +5 -5
- package/dist/cjs/src/package-json.d.ts +1 -1
- package/dist/cjs/src/package-json.js +2 -2
- package/dist/cjs/src/proxy/aibotk.js +1 -0
- package/dist/cjs/src/proxy/cozeV3Ai.d.ts +1 -1
- package/dist/esm/src/bot/coze/sdk/index.d.ts +38 -0
- package/dist/esm/src/bot/coze/sdk/index.js +105 -0
- package/dist/esm/src/bot/dify/sdk/index.d.ts +167 -0
- package/dist/esm/src/bot/dify/sdk/index.js +461 -0
- package/dist/esm/src/bot/dify/sdk/office.d.ts +143 -0
- package/dist/esm/src/bot/dify/sdk/office.js +319 -0
- package/dist/esm/src/botInstance/cozev3.d.ts +8 -1
- package/dist/esm/src/botInstance/cozev3.js +57 -46
- package/dist/esm/src/botInstance/officialOpenAi.js +4 -0
- package/dist/esm/src/botInstance/sdk/cozev3.js +12 -4
- package/dist/esm/src/handlers/on-message.js +5 -5
- package/dist/esm/src/package-json.d.ts +1 -1
- package/dist/esm/src/package-json.js +2 -2
- package/dist/esm/src/proxy/aibotk.js +1 -0
- package/dist/esm/src/proxy/cozeV3Ai.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class CozeV3Api extends CozeClient {
|
|
2
|
+
sendMessage(query: any, { file, fileType, fileUrl, systemMessage, user, needConversation, conversationId, timeoutMs, files, variables, }: {
|
|
3
|
+
file: any;
|
|
4
|
+
fileType: any;
|
|
5
|
+
fileUrl: any;
|
|
6
|
+
systemMessage: any;
|
|
7
|
+
user: any;
|
|
8
|
+
needConversation?: boolean | undefined;
|
|
9
|
+
conversationId?: null | undefined;
|
|
10
|
+
timeoutMs?: number | undefined;
|
|
11
|
+
files?: null | undefined;
|
|
12
|
+
variables: any;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
text: string;
|
|
15
|
+
conversationId: null;
|
|
16
|
+
id: string;
|
|
17
|
+
files: never[];
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
declare class CozeClient {
|
|
21
|
+
constructor({ apiKey, baseUrl, debug, systemMessage, stream, botId }: {
|
|
22
|
+
apiKey: any;
|
|
23
|
+
baseUrl?: string | undefined;
|
|
24
|
+
debug?: boolean | undefined;
|
|
25
|
+
systemMessage?: null | undefined;
|
|
26
|
+
stream?: boolean | undefined;
|
|
27
|
+
botId: any;
|
|
28
|
+
});
|
|
29
|
+
apiKey: any;
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
debug: boolean;
|
|
32
|
+
stream: boolean;
|
|
33
|
+
botId: any;
|
|
34
|
+
systemMessage: any;
|
|
35
|
+
updateApiKey(apiKey: any): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CozeV3Api = void 0;
|
|
4
|
+
const api_1 = require("@coze/api");
|
|
5
|
+
// import { FileBox } from 'file-box';
|
|
6
|
+
// import fs from 'fs';
|
|
7
|
+
class CozeClient {
|
|
8
|
+
constructor({ apiKey, baseUrl = api_1.COZE_CN_BASE_URL, debug = false, systemMessage = null, stream = false, botId }) {
|
|
9
|
+
this.apiKey = apiKey;
|
|
10
|
+
this.baseUrl = baseUrl;
|
|
11
|
+
this.debug = debug;
|
|
12
|
+
this.stream = stream;
|
|
13
|
+
this.botId = botId;
|
|
14
|
+
this.systemMessage = systemMessage;
|
|
15
|
+
}
|
|
16
|
+
updateApiKey(apiKey) {
|
|
17
|
+
this.apiKey = apiKey;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class CozeV3Api extends CozeClient {
|
|
21
|
+
async sendMessage(query, { file, fileType, fileUrl, systemMessage, user, needConversation = true, conversationId = null, timeoutMs = 100 * 1000, files = null, variables, }) {
|
|
22
|
+
try {
|
|
23
|
+
const client = new api_1.CozeAPI({ baseURL: this.baseUrl, token: this.apiKey });
|
|
24
|
+
let messages = [
|
|
25
|
+
{
|
|
26
|
+
role: 'user',
|
|
27
|
+
content: query,
|
|
28
|
+
content_type: 'text',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
if (fileUrl) {
|
|
32
|
+
const mediaMessage = [{
|
|
33
|
+
type: 'text',
|
|
34
|
+
text: query,
|
|
35
|
+
}, {
|
|
36
|
+
type: fileType,
|
|
37
|
+
file_url: fileUrl
|
|
38
|
+
}];
|
|
39
|
+
messages = [{
|
|
40
|
+
role: 'user',
|
|
41
|
+
content: JSON.stringify(mediaMessage),
|
|
42
|
+
content_type: 'object_string',
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
else if (file) {
|
|
46
|
+
const fileBuffer = await file.toStream();
|
|
47
|
+
const fileRes = await client.files.upload({ file: fileBuffer });
|
|
48
|
+
console.log('fileRes', fileRes);
|
|
49
|
+
const mediaMessage = [{
|
|
50
|
+
type: 'text',
|
|
51
|
+
text: query,
|
|
52
|
+
}, {
|
|
53
|
+
type: fileType,
|
|
54
|
+
file_id: fileRes.id
|
|
55
|
+
}];
|
|
56
|
+
messages = [{
|
|
57
|
+
role: 'user',
|
|
58
|
+
content: JSON.stringify(mediaMessage),
|
|
59
|
+
content_type: 'object_string',
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
if (!conversationId && needConversation) {
|
|
63
|
+
const res = await client.conversations.create({
|
|
64
|
+
messages,
|
|
65
|
+
timeoutMs,
|
|
66
|
+
});
|
|
67
|
+
console.log('conversation', res);
|
|
68
|
+
conversationId = res.id;
|
|
69
|
+
messages = [];
|
|
70
|
+
}
|
|
71
|
+
const data = {
|
|
72
|
+
bot_id: this.botId,
|
|
73
|
+
custom_variables: {
|
|
74
|
+
...variables,
|
|
75
|
+
},
|
|
76
|
+
additional_messages: messages,
|
|
77
|
+
user_id: user,
|
|
78
|
+
auto_save_history: true,
|
|
79
|
+
};
|
|
80
|
+
if (systemMessage || this.systemMessage) {
|
|
81
|
+
data.custom_variables.systemMessage = systemMessage || this.systemMessage;
|
|
82
|
+
}
|
|
83
|
+
if (conversationId && needConversation) {
|
|
84
|
+
data.conversation_id = conversationId;
|
|
85
|
+
}
|
|
86
|
+
const stream = await client.chat.stream(data);
|
|
87
|
+
let answer = '';
|
|
88
|
+
let lastMessageId = '';
|
|
89
|
+
for await (const part of stream) {
|
|
90
|
+
if (part.event === api_1.ChatEventType.CONVERSATION_CHAT_FAILED || part.event === api_1.ChatEventType.ERROR) {
|
|
91
|
+
console.log('Coze 请求失败,请根据失败原因进行排查问题', JSON.stringify(part.data));
|
|
92
|
+
return { text: answer, conversationId, id: lastMessageId, files: [] };
|
|
93
|
+
}
|
|
94
|
+
if (part.event === api_1.ChatEventType.CONVERSATION_MESSAGE_COMPLETED && part.data.type === 'answer' && part.data.content_type === 'text') {
|
|
95
|
+
answer = part.data.content;
|
|
96
|
+
lastMessageId = part.data.id;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { text: answer, conversationId, id: lastMessageId, files: [] };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.log('Coze 请求失败,请根据失败原因进行排查问题', JSON.stringify(error));
|
|
103
|
+
return { text: '', conversationId: conversationId, id: '', files: [] };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.CozeV3Api = CozeV3Api;
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export const BASE_URL: "https://api.dify.ai/v1";
|
|
2
|
+
export namespace routes {
|
|
3
|
+
namespace feedback {
|
|
4
|
+
const method: string;
|
|
5
|
+
function url(messageId: any): string;
|
|
6
|
+
}
|
|
7
|
+
namespace application {
|
|
8
|
+
const method_1: string;
|
|
9
|
+
export { method_1 as method };
|
|
10
|
+
export function url_1(): string;
|
|
11
|
+
export { url_1 as url };
|
|
12
|
+
}
|
|
13
|
+
namespace fileUpload {
|
|
14
|
+
const method_2: string;
|
|
15
|
+
export { method_2 as method };
|
|
16
|
+
export function url_2(): string;
|
|
17
|
+
export { url_2 as url };
|
|
18
|
+
}
|
|
19
|
+
namespace textToAudio {
|
|
20
|
+
const method_3: string;
|
|
21
|
+
export { method_3 as method };
|
|
22
|
+
export function url_3(): string;
|
|
23
|
+
export { url_3 as url };
|
|
24
|
+
}
|
|
25
|
+
namespace getMeta {
|
|
26
|
+
const method_4: string;
|
|
27
|
+
export { method_4 as method };
|
|
28
|
+
export function url_4(): string;
|
|
29
|
+
export { url_4 as url };
|
|
30
|
+
}
|
|
31
|
+
namespace createCompletionMessage {
|
|
32
|
+
const method_5: string;
|
|
33
|
+
export { method_5 as method };
|
|
34
|
+
export function url_5(): string;
|
|
35
|
+
export { url_5 as url };
|
|
36
|
+
}
|
|
37
|
+
namespace createChatMessage {
|
|
38
|
+
const method_6: string;
|
|
39
|
+
export { method_6 as method };
|
|
40
|
+
export function url_6(): string;
|
|
41
|
+
export { url_6 as url };
|
|
42
|
+
}
|
|
43
|
+
namespace getSuggested {
|
|
44
|
+
const method_7: string;
|
|
45
|
+
export { method_7 as method };
|
|
46
|
+
export function url_7(message_id: any): string;
|
|
47
|
+
export { url_7 as url };
|
|
48
|
+
}
|
|
49
|
+
namespace stopChatMessage {
|
|
50
|
+
const method_8: string;
|
|
51
|
+
export { method_8 as method };
|
|
52
|
+
export function url_8(task_id: any): string;
|
|
53
|
+
export { url_8 as url };
|
|
54
|
+
}
|
|
55
|
+
namespace getConversations {
|
|
56
|
+
const method_9: string;
|
|
57
|
+
export { method_9 as method };
|
|
58
|
+
export function url_9(): string;
|
|
59
|
+
export { url_9 as url };
|
|
60
|
+
}
|
|
61
|
+
namespace getConversationMessages {
|
|
62
|
+
const method_10: string;
|
|
63
|
+
export { method_10 as method };
|
|
64
|
+
export function url_10(): string;
|
|
65
|
+
export { url_10 as url };
|
|
66
|
+
}
|
|
67
|
+
namespace renameConversation {
|
|
68
|
+
const method_11: string;
|
|
69
|
+
export { method_11 as method };
|
|
70
|
+
export function url_11(conversation_id: any): string;
|
|
71
|
+
export { url_11 as url };
|
|
72
|
+
}
|
|
73
|
+
namespace deleteConversation {
|
|
74
|
+
const method_12: string;
|
|
75
|
+
export { method_12 as method };
|
|
76
|
+
export function url_12(conversation_id: any): string;
|
|
77
|
+
export { url_12 as url };
|
|
78
|
+
}
|
|
79
|
+
namespace audioToText {
|
|
80
|
+
const method_13: string;
|
|
81
|
+
export { method_13 as method };
|
|
82
|
+
export function url_13(): string;
|
|
83
|
+
export { url_13 as url };
|
|
84
|
+
}
|
|
85
|
+
namespace getWorkflowInfo {
|
|
86
|
+
const method_14: string;
|
|
87
|
+
export { method_14 as method };
|
|
88
|
+
export function url_14(): string;
|
|
89
|
+
export { url_14 as url };
|
|
90
|
+
}
|
|
91
|
+
namespace runWorkflow {
|
|
92
|
+
const method_15: string;
|
|
93
|
+
export { method_15 as method };
|
|
94
|
+
export function url_15(): string;
|
|
95
|
+
export { url_15 as url };
|
|
96
|
+
}
|
|
97
|
+
namespace stopWorkflow {
|
|
98
|
+
const method_16: string;
|
|
99
|
+
export { method_16 as method };
|
|
100
|
+
export function url_16(task_id: any): string;
|
|
101
|
+
export { url_16 as url };
|
|
102
|
+
}
|
|
103
|
+
namespace getWorkflowResult {
|
|
104
|
+
const method_17: string;
|
|
105
|
+
export { method_17 as method };
|
|
106
|
+
export function url_17(task_id: any): string;
|
|
107
|
+
export { url_17 as url };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class DifyClient {
|
|
111
|
+
constructor({ apiKey, baseUrl, debug, systemMessage, stream }: {
|
|
112
|
+
apiKey: any;
|
|
113
|
+
baseUrl?: string | undefined;
|
|
114
|
+
debug?: boolean | undefined;
|
|
115
|
+
systemMessage?: null | undefined;
|
|
116
|
+
stream?: boolean | undefined;
|
|
117
|
+
});
|
|
118
|
+
apiKey: any;
|
|
119
|
+
baseUrl: string;
|
|
120
|
+
debug: boolean;
|
|
121
|
+
stream: boolean;
|
|
122
|
+
systemMessage: any;
|
|
123
|
+
updateApiKey(apiKey: any): void;
|
|
124
|
+
sendUploadRequest(method: any, endpoint: any, data?: null, params?: null, stream?: boolean, headerParams?: {}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
125
|
+
sendRequest({ method, endpoint, data, params, stream, headerParams, timeoutMs }: {
|
|
126
|
+
method: any;
|
|
127
|
+
endpoint: any;
|
|
128
|
+
data: any;
|
|
129
|
+
params: any;
|
|
130
|
+
stream?: boolean | undefined;
|
|
131
|
+
headerParams?: {} | undefined;
|
|
132
|
+
timeoutMs?: number | undefined;
|
|
133
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
134
|
+
messageFeedback(messageId: any, rating: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
135
|
+
getApplicationParameters(user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
136
|
+
fileUpload(data: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
137
|
+
textToAudio(text: any, user: any, streaming?: boolean): Promise<import("axios").AxiosResponse<any, any>>;
|
|
138
|
+
getMeta(user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
139
|
+
}
|
|
140
|
+
export class CompletionClient extends DifyClient {
|
|
141
|
+
createCompletionMessage(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
|
|
142
|
+
runWorkflow(inputs: any, user: any, stream?: boolean, files?: null): Promise<import("axios").AxiosResponse<any, any>>;
|
|
143
|
+
}
|
|
144
|
+
export class ChatClient extends DifyClient {
|
|
145
|
+
sendMessage(query: any, { systemMessage, user, conversationId, timeoutMs, files, inputs }: {
|
|
146
|
+
systemMessage: any;
|
|
147
|
+
user: any;
|
|
148
|
+
conversationId?: null | undefined;
|
|
149
|
+
timeoutMs?: number | undefined;
|
|
150
|
+
files?: null | undefined;
|
|
151
|
+
inputs: any;
|
|
152
|
+
}): Promise<any>;
|
|
153
|
+
getConversationMessages(user: any, conversationId?: string, firstId?: null, limit?: null): Promise<import("axios").AxiosResponse<any, any>>;
|
|
154
|
+
getConversations(user: any, firstId?: null, limit?: null, pinned?: null): Promise<import("axios").AxiosResponse<any, any>>;
|
|
155
|
+
renameConversation(conversationId: any, name: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
156
|
+
getSuggested(message_id: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
157
|
+
stopMessage(task_id: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
158
|
+
audioToText(data: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
159
|
+
}
|
|
160
|
+
export class WorkflowClient extends DifyClient {
|
|
161
|
+
run(inputs: any, user: any, stream: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
162
|
+
stop(task_id: any, user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
163
|
+
info(user: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
164
|
+
result(task_id: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
165
|
+
getWorkflowResult(input: any, user: any, isStream: any): Promise<any>;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=index.d.ts.map
|