31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
'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 };
|