magnitude-core
Version:
Magnitude e2e testing agent
35 lines (34 loc) • 1.39 kB
JavaScript
import { blueBright, bold, cyanBright, gray } from 'ansis';
export function narrateAgent(agent) {
agent.events.on('start', () => {
console.log(bold(blueBright(`▶ [start] agent started`)));
});
agent.events.on('stop', () => {
console.log(bold(blueBright(`■ [stop] agent stopped`)));
});
agent.events.on('thought', (thought) => {
console.log(gray `${thought}`);
//console.log(gray`⚙︎ ${thought}`);
});
agent.events.on('actStarted', (task, options) => {
console.log(bold(cyanBright(`◆ [act] ${task}`)));
});
agent.events.on('actionStarted', (action) => {
const actionDefinition = agent.identifyAction(action);
console.log(bold ` ${actionDefinition.render(action)}`);
});
}
export function narrateBrowserAgent(agent) {
narrateAgent(agent);
agent.browserAgentEvents.on('nav', (url) => {
console.log(bold(cyanBright `⮊ [nav] ${url}`));
});
agent.browserAgentEvents.on('extractStarted', (instructions, schema) => {
console.log(bold(cyanBright `⛏ [extract] ${instructions}`));
});
agent.browserAgentEvents.on('extractDone', (instructions, data) => {
// console.log has a decent default formatter for arbitrary data e.g. objects
console.log(data);
//console.log(blueBright`${JSON.stringify(data, null, 2)}`);
});
}