EasyAgent/demo/lib/assistant_sim.js
2026-02-28 03:00:08 +08:00

31 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const { startSpinner, stopSpinner } = require('./ui/spinner');
const { truncateText, sleep, streamText } = require('./ui/stream');
const { GREY, RESET } = require('./env');
function createAssistantSimulator(state, options) {
const showReasoning = options.showReasoning;
return async function simulateAssistantReply(userInput) {
const spinner = startSpinner('');
await sleep(600);
spinner.setLabel(' 思考中...');
await sleep(1200);
stopSpinner(spinner, showReasoning ? '○ 思考完成' : '○');
if (showReasoning) {
const reasoning = `好的,用户让我根据输入「${userInput}」做出回应,并给出明确的下一步。`;
const snippet = truncateText(reasoning, 50);
await streamText('', `${GREY}${snippet}${RESET}`, 12);
}
const reply = '这是模拟的 Eagent 回复内容。后续会替换为真实模型流式输出。';
await streamText('Eagent', reply, 18);
state.tokenUsage += userInput.length + reply.length;
};
}
module.exports = { createAssistantSimulator };