wechaty-web-panel 1.6.125 → 1.6.126

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.
@@ -159,11 +159,20 @@ export class DifyClient {
159
159
  user,
160
160
  streaming
161
161
  };
162
- return this.sendRequest(routes.textToAudio.method, routes.textToAudio.url(), data, null, streaming);
162
+ return this.sendRequest({
163
+ method: routes.textToAudio.method,
164
+ endpoint: routes.textToAudio.url(),
165
+ data,
166
+ stream: streaming
167
+ });
163
168
  }
164
169
  getMeta(user) {
165
170
  const params = { user };
166
- return this.sendRequest(routes.meta.method, routes.meta.url(), null, params);
171
+ return this.sendRequest({
172
+ method: routes.getMeta.method,
173
+ endpoint: routes.getMeta.url(),
174
+ params
175
+ });
167
176
  }
168
177
  }
169
178
  export class CompletionClient extends DifyClient {
@@ -187,7 +196,12 @@ export class CompletionClient extends DifyClient {
187
196
  user,
188
197
  response_mode: stream ? "streaming" : "blocking",
189
198
  };
190
- return this.sendRequest(routes.runWorkflow.method, routes.runWorkflow.url(), data, null, stream);
199
+ return this.sendRequest({
200
+ method: routes.runWorkflow.method,
201
+ endpoint: routes.runWorkflow.url(),
202
+ data,
203
+ stream
204
+ });
191
205
  }
192
206
  }
193
207
  export class ChatClient extends DifyClient {
@@ -219,7 +233,7 @@ export class ChatClient extends DifyClient {
219
233
  function unicodeToChar(text) {
220
234
  if (!text)
221
235
  return '';
222
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
236
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
223
237
  return String.fromCharCode(parseInt(p1, 16));
224
238
  });
225
239
  }
@@ -303,7 +317,7 @@ export class ChatClient extends DifyClient {
303
317
  if (this.debug) {
304
318
  console.log('dify request error', res.data.code, res.data.message);
305
319
  }
306
- return Promise.reject(res.message);
320
+ return Promise.reject(res.data.message);
307
321
  }
308
322
  const response = res.data;
309
323
  return {
@@ -345,15 +359,26 @@ export class ChatClient extends DifyClient {
345
359
  }
346
360
  getSuggested(message_id, user) {
347
361
  const data = { user };
348
- return this.sendRequest(routes.getSuggested.method, routes.getSuggested.url(message_id), data);
362
+ return this.sendRequest({
363
+ method: routes.getSuggested.method,
364
+ endpoint: routes.getSuggested.url(message_id),
365
+ params: data
366
+ });
349
367
  }
350
368
  stopMessage(task_id, user) {
351
369
  const data = { user };
352
- return this.sendRequest(routes.stopChatMessage.method, routes.stopChatMessage.url(task_id), data);
370
+ return this.sendRequest({
371
+ method: routes.stopChatMessage.method,
372
+ endpoint: routes.stopChatMessage.url(task_id),
373
+ data
374
+ });
353
375
  }
354
376
  audioToText(data) {
355
- return this.sendRequest(routes.audioToText.method, routes.audioToText.url(), data, null, false, {
356
- "Content-Type": 'multipart/form-data'
377
+ return this.sendRequest({
378
+ method: routes.audioToText.method,
379
+ endpoint: routes.audioToText.url(),
380
+ data,
381
+ headerParams: { 'Content-Type': 'multipart/form-data' }
357
382
  });
358
383
  }
359
384
  }
@@ -364,25 +389,42 @@ export class WorkflowClient extends DifyClient {
364
389
  response_mode: stream ? "streaming" : "blocking",
365
390
  user
366
391
  };
367
- return this.sendRequest(routes.runWorkflow.method, routes.runWorkflow.url(), data, null, stream);
392
+ return this.sendRequest({
393
+ method: routes.runWorkflow.method,
394
+ endpoint: routes.runWorkflow.url(),
395
+ data,
396
+ stream
397
+ });
368
398
  }
369
399
  stop(task_id, user) {
370
400
  const data = { user };
371
- return this.sendRequest(routes.stopWorkflow.method, routes.stopWorkflow.url(task_id), data);
401
+ return this.sendRequest({
402
+ method: routes.stopWorkflow.method,
403
+ endpoint: routes.stopWorkflow.url(task_id),
404
+ data
405
+ });
372
406
  }
373
407
  info(user) {
374
408
  const params = { user };
375
- return this.sendRequest(routes.getWorkflowInfo.method, routes.getWorkflowInfo.url(), null, params);
409
+ console.log('获取工作流信息', routes.getWorkflowInfo.method, routes.getWorkflowInfo.url());
410
+ return this.sendRequest({
411
+ method: routes.getWorkflowInfo.method,
412
+ endpoint: routes.getWorkflowInfo.url(),
413
+ params
414
+ });
376
415
  }
377
416
  result(task_id) {
378
- return this.sendRequest(routes.getWorkflowResult.method, routes.getWorkflowResult.url(task_id), null);
417
+ return this.sendRequest({
418
+ method: routes.getWorkflowResult.method,
419
+ endpoint: routes.getWorkflowResult.url(task_id)
420
+ });
379
421
  }
380
422
  async getWorkflowResult(input, user, isStream) {
381
423
  const res = await this.run(input, user, isStream);
382
424
  function unicodeToChar(text) {
383
425
  if (!text)
384
426
  return '';
385
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
427
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
386
428
  return String.fromCharCode(parseInt(p1, 16));
387
429
  });
388
430
  }
@@ -413,6 +455,7 @@ export class WorkflowClient extends DifyClient {
413
455
  task_id = res?.workflow_run_id;
414
456
  console.log('工作流node节点执行任务中');
415
457
  }
458
+ console.log('工作流输出结果', res.event, res.data);
416
459
  if (res.event === 'workflow_finished' || res.event === 'tts_message_end') {
417
460
  console.log('工作流执行完毕,正在组装数据进行发送');
418
461
  task_id = res?.workflow_run_id;
@@ -421,12 +464,13 @@ export class WorkflowClient extends DifyClient {
421
464
  });
422
465
  });
423
466
  stream.on('end', async () => {
467
+ console.log('执行工作流结束');
424
468
  const { data } = task_id ? await this.result(task_id) : { data: { outputs: '' } };
425
469
  console.log('获取工作流执行结果', task_id, JSON.stringify(data.outputs));
426
470
  let outputs = {};
427
471
  if (data.outputs) {
428
472
  try {
429
- outputs = JSON.parse(data.outputs);
473
+ outputs = typeof data.outputs === 'object' ? data.outputs : JSON.parse(data.outputs);
430
474
  }
431
475
  catch (error) {
432
476
  console.log(`获取工作流执行结果,失败:${error}`);
@@ -443,7 +487,7 @@ export class WorkflowClient extends DifyClient {
443
487
  if (!isStream) {
444
488
  if (res.data.code) {
445
489
  console.log('Dify 工作流执行失败', res.data.code, res.data.message);
446
- return Promise.reject(res.message);
490
+ return Promise.reject(res.data.message);
447
491
  }
448
492
  const response = res.data;
449
493
  return {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.125",
6
+ "version": "1.6.126",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js"
@@ -3,7 +3,7 @@ const getDifyWorkflowContent = async (baseurl, token, inputs) => {
3
3
  try {
4
4
  const user = 'dify-schedule';
5
5
  console.log('getDifyWorkflowContent request info:', baseurl, token, inputs);
6
- const workflow = new WorkflowClient(token, baseurl);
6
+ const workflow = new WorkflowClient({ apiKey: token, baseUrl: baseurl, stream: true });
7
7
  console.log(`正在获取Dify工作流基础信息...`);
8
8
  const info = await workflow.info(user);
9
9
  console.log(`Dify工作流【${info.data.name}】开始执行...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.6.125",
3
+ "version": "1.6.126",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js"
@@ -179,22 +179,20 @@ export class DifyClient {
179
179
  user,
180
180
  streaming
181
181
  };
182
- return this.sendRequest(
183
- routes.textToAudio.method,
184
- routes.textToAudio.url(),
182
+ return this.sendRequest({
183
+ method: routes.textToAudio.method,
184
+ endpoint: routes.textToAudio.url(),
185
185
  data,
186
- null,
187
- streaming
188
- );
186
+ stream: streaming
187
+ });
189
188
  }
190
189
  getMeta(user) {
191
190
  const params = { user };
192
- return this.sendRequest(
193
- routes.meta.method,
194
- routes.meta.url(),
195
- null,
191
+ return this.sendRequest({
192
+ method: routes.getMeta.method,
193
+ endpoint: routes.getMeta.url(),
196
194
  params
197
- );
195
+ });
198
196
  }
199
197
  }
200
198
 
@@ -219,13 +217,12 @@ export class CompletionClient extends DifyClient {
219
217
  user,
220
218
  response_mode: stream ? "streaming" : "blocking",
221
219
  };
222
- return this.sendRequest(
223
- routes.runWorkflow.method,
224
- routes.runWorkflow.url(),
220
+ return this.sendRequest({
221
+ method: routes.runWorkflow.method,
222
+ endpoint: routes.runWorkflow.url(),
225
223
  data,
226
- null,
227
224
  stream
228
- );
225
+ });
229
226
  }
230
227
  }
231
228
 
@@ -261,7 +258,7 @@ export class ChatClient extends DifyClient {
261
258
  if (!text)
262
259
  return ''
263
260
 
264
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
261
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
265
262
  return String.fromCharCode(parseInt(p1, 16))
266
263
  })
267
264
  }
@@ -344,7 +341,7 @@ export class ChatClient extends DifyClient {
344
341
  if (this.debug) {
345
342
  console.log('dify request error', res.data.code, res.data.message)
346
343
  }
347
- return Promise.reject(res.message)
344
+ return Promise.reject(res.data.message)
348
345
  }
349
346
 
350
347
  const response = res.data
@@ -390,31 +387,27 @@ export class ChatClient extends DifyClient {
390
387
  }
391
388
  getSuggested(message_id, user) {
392
389
  const data = { user };
393
- return this.sendRequest(
394
- routes.getSuggested.method,
395
- routes.getSuggested.url(message_id),
396
- data
397
- );
390
+ return this.sendRequest({
391
+ method: routes.getSuggested.method,
392
+ endpoint: routes.getSuggested.url(message_id),
393
+ params: data
394
+ });
398
395
  }
399
396
  stopMessage(task_id, user) {
400
397
  const data = { user };
401
- return this.sendRequest(
402
- routes.stopChatMessage.method,
403
- routes.stopChatMessage.url(task_id),
398
+ return this.sendRequest({
399
+ method: routes.stopChatMessage.method,
400
+ endpoint: routes.stopChatMessage.url(task_id),
404
401
  data
405
- );
402
+ });
406
403
  }
407
404
  audioToText(data) {
408
- return this.sendRequest(
409
- routes.audioToText.method,
410
- routes.audioToText.url(),
405
+ return this.sendRequest({
406
+ method: routes.audioToText.method,
407
+ endpoint: routes.audioToText.url(),
411
408
  data,
412
- null,
413
- false,
414
- {
415
- "Content-Type": 'multipart/form-data'
416
- }
417
- );
409
+ headerParams: { 'Content-Type': 'multipart/form-data' }
410
+ });
418
411
  }
419
412
  }
420
413
 
@@ -427,38 +420,37 @@ export class WorkflowClient extends DifyClient {
427
420
  user
428
421
  };
429
422
 
430
- return this.sendRequest(
431
- routes.runWorkflow.method,
432
- routes.runWorkflow.url(),
423
+ return this.sendRequest({
424
+ method: routes.runWorkflow.method,
425
+ endpoint: routes.runWorkflow.url(),
433
426
  data,
434
- null,
435
427
  stream
436
- );
428
+ });
437
429
  }
438
430
 
439
431
  stop(task_id, user) {
440
432
  const data = { user };
441
- return this.sendRequest(
442
- routes.stopWorkflow.method,
443
- routes.stopWorkflow.url(task_id),
433
+ return this.sendRequest({
434
+ method: routes.stopWorkflow.method,
435
+ endpoint: routes.stopWorkflow.url(task_id),
444
436
  data
445
- );
437
+ });
446
438
  }
447
439
  info(user) {
448
440
  const params = { user };
449
- return this.sendRequest(
450
- routes.getWorkflowInfo.method,
451
- routes.getWorkflowInfo.url(),
452
- null,
441
+ console.log('获取工作流信息', routes.getWorkflowInfo.method,
442
+ routes.getWorkflowInfo.url())
443
+ return this.sendRequest({
444
+ method: routes.getWorkflowInfo.method,
445
+ endpoint: routes.getWorkflowInfo.url(),
453
446
  params
454
- );
447
+ });
455
448
  }
456
449
  result(task_id) {
457
- return this.sendRequest(
458
- routes.getWorkflowResult.method,
459
- routes.getWorkflowResult.url(task_id),
460
- null
461
- );
450
+ return this.sendRequest({
451
+ method: routes.getWorkflowResult.method,
452
+ endpoint: routes.getWorkflowResult.url(task_id)
453
+ });
462
454
  }
463
455
  async getWorkflowResult(input, user, isStream) {
464
456
  const res = await this.run(input, user, isStream)
@@ -466,7 +458,7 @@ export class WorkflowClient extends DifyClient {
466
458
  if (!text)
467
459
  return ''
468
460
 
469
- return text.replace(/\\u[0-9a-f]{4}/g, (_match, p1) => {
461
+ return text.replace(/\\u([0-9a-f]{4})/g, (_match, p1) => {
470
462
  return String.fromCharCode(parseInt(p1, 16))
471
463
  })
472
464
  }
@@ -497,6 +489,7 @@ export class WorkflowClient extends DifyClient {
497
489
  task_id = res?.workflow_run_id
498
490
  console.log('工作流node节点执行任务中')
499
491
  }
492
+ console.log('工作流输出结果', res.event, res.data)
500
493
  if (res.event === 'workflow_finished' || res.event === 'tts_message_end') {
501
494
  console.log('工作流执行完毕,正在组装数据进行发送')
502
495
  task_id = res?.workflow_run_id
@@ -505,13 +498,13 @@ export class WorkflowClient extends DifyClient {
505
498
  })
506
499
  })
507
500
  stream.on('end', async () => {
508
-
501
+ console.log('执行工作流结束')
509
502
  const { data } = task_id ? await this.result(task_id) : { data: { outputs: '' } }
510
503
  console.log('获取工作流执行结果', task_id, JSON.stringify(data.outputs))
511
504
  let outputs = {}
512
505
  if(data.outputs) {
513
506
  try {
514
- outputs = JSON.parse(data.outputs)
507
+ outputs = typeof data.outputs === 'object' ? data.outputs : JSON.parse(data.outputs)
515
508
  } catch (error) {
516
509
  console.log(`获取工作流执行结果,失败:${error}`)
517
510
  }
@@ -527,7 +520,7 @@ export class WorkflowClient extends DifyClient {
527
520
  if (!isStream) {
528
521
  if (res.data.code) {
529
522
  console.log('Dify 工作流执行失败', res.data.code, res.data.message)
530
- return Promise.reject(res.message)
523
+ return Promise.reject(res.data.message)
531
524
  }
532
525
  const response = res.data
533
526
  return {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.6.125",
6
+ "version": "1.6.126",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js"
@@ -6,7 +6,7 @@ const getDifyWorkflowContent = async (baseurl, token, inputs) => {
6
6
  try {
7
7
  const user = 'dify-schedule'
8
8
  console.log('getDifyWorkflowContent request info:', baseurl, token, inputs)
9
- const workflow = new WorkflowClient(token, baseurl);
9
+ const workflow = new WorkflowClient({apiKey: token, baseUrl: baseurl, stream: true});
10
10
  console.log(`正在获取Dify工作流基础信息...`)
11
11
  const info = await workflow.info(user);
12
12
  console.log(`Dify工作流【${info.data.name}】开始执行...`)