foliko 1.1.79 → 1.1.81
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/package.json +1 -1
- package/plugins/weixin-plugin.js +49 -15
package/package.json
CHANGED
package/plugins/weixin-plugin.js
CHANGED
|
@@ -378,7 +378,7 @@ class WeixinPlugin extends Plugin {
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
_on_event_message(){
|
|
381
|
-
const {sessionId}=this
|
|
381
|
+
const {sessionId}=this
|
|
382
382
|
const sessionScope = this.agent.createSessionScope(sessionId);
|
|
383
383
|
sessionScope.on('stream:chunk', ({ chunk }) => {})
|
|
384
384
|
}
|
|
@@ -388,25 +388,59 @@ class WeixinPlugin extends Plugin {
|
|
|
388
388
|
*/
|
|
389
389
|
_setupSessionScopeListeners(agent, sessionId, originalMsg, userId) {
|
|
390
390
|
const sessionScope = agent.createSessionScope(sessionId)
|
|
391
|
+
const renderState = { inThink: false, inCodeBlock: false };
|
|
392
|
+
const lineBuffer = { value: '' };
|
|
393
|
+
|
|
394
|
+
// 流式文本处理
|
|
395
|
+
sessionScope.on('stream:chunk', ({ chunk }) => {
|
|
396
|
+
if (chunk.type === 'text') {
|
|
397
|
+
lineBuffer.value += chunk.text;
|
|
398
|
+
} else if (chunk.type === 'tool-call') {
|
|
399
|
+
const args = chunk.input ? JSON.stringify(chunk.input).slice(0, 30) : '';
|
|
400
|
+
log.info(`[Tool] ${chunk.toolName} ${args}...`);
|
|
401
|
+
} else if (chunk.type === 'tool-result') {
|
|
402
|
+
const result = chunk.result;
|
|
403
|
+
const shortResult = typeof result === 'string' ? result.slice(0, 30) : JSON.stringify(result).slice(0, 30);
|
|
404
|
+
log.info(`[Tool] ${chunk.toolName} ${shortResult}...`);
|
|
405
|
+
} else if (chunk.type === 'usage') {
|
|
406
|
+
log.debug(`[Usage] input: ${chunk.inputTokens || 0}, output: ${chunk.outputTokens || 0}`);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
391
409
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
410
|
+
// 消息开始
|
|
411
|
+
sessionScope.on('message:start', async () => {
|
|
412
|
+
this.startTypingInterval();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
// 消息完成
|
|
416
|
+
// sessionScope.on('message:complete', async ({ content }) => {
|
|
417
|
+
|
|
418
|
+
// if (!content) {
|
|
419
|
+
|
|
420
|
+
// }
|
|
421
|
+
// });
|
|
422
|
+
|
|
423
|
+
// 队列完成
|
|
424
|
+
sessionScope.on('queue:completed', async () => {
|
|
425
|
+
this.stopTypingInterval();
|
|
426
|
+
if(!cleanResponse(lineBuffer.value.trim())){
|
|
427
|
+
const msg = '继续进行下一步';
|
|
428
|
+
await agent.sendMessage(msg, { sessionId, priority: 1 });
|
|
429
|
+
}else(lineBuffer.value.trim()) {
|
|
430
|
+
await this._sendMessageBatch(originalMsg, userId, lineBuffer.value.trim(), true);
|
|
431
|
+
//log.debug(`[Queue] Remaining buffer: ${lineBuffer.value}`);
|
|
400
432
|
}
|
|
401
|
-
|
|
433
|
+
lineBuffer.value = '';
|
|
434
|
+
});
|
|
402
435
|
|
|
436
|
+
// 队列失败
|
|
403
437
|
sessionScope.on('queue:failed', async ({ error }) => {
|
|
404
|
-
this.stopTypingInterval()
|
|
405
|
-
await this._sendMessageBatch(originalMsg, userId, error, true)
|
|
406
|
-
})
|
|
438
|
+
this.stopTypingInterval();
|
|
439
|
+
await this._sendMessageBatch(originalMsg, userId, error, true);
|
|
440
|
+
});
|
|
407
441
|
|
|
408
|
-
this._sessionScopes.set(sessionId, sessionScope)
|
|
409
|
-
return sessionScope
|
|
442
|
+
this._sessionScopes.set(sessionId, sessionScope);
|
|
443
|
+
return sessionScope;
|
|
410
444
|
}
|
|
411
445
|
|
|
412
446
|
/**
|