1- import * as readline from "node:readline" ;
2- import { createChatBus , createConversation } from "../src/index.js" ;
1+ import {
2+ attachInteractiveConsole ,
3+ createChatBus ,
4+ createConversation ,
5+ } from "../src/index.js" ;
36import { anthropicAdapter } from "../src/adapters/anthropic.js" ;
47
8+ // ANSI color codes for participants
9+ const colors : Record < string , string > = {
10+ keynesian : "\x1b[36m" , // Cyan
11+ austrian : "\x1b[35m" , // Magenta
12+ technologist : "\x1b[33m" , // Yellow
13+ human : "\x1b[32m" , // Green
14+ reset : "\x1b[0m" ,
15+ } ;
16+
17+ function colorize ( name : string ) : string {
18+ const c = colors [ name ] || "" ;
19+ return `${ c } [${ name } ]${ colors . reset } ` ;
20+ }
21+
522const bus = createChatBus ( ) ;
623
24+ // Track current speaker for coloring
25+ let currentSpeaker = "" ;
26+ let firstToken = true ;
27+
728bus . register ( {
829 name : "keynesian" ,
930 type : "llm" ,
@@ -39,12 +60,21 @@ bus.register({
3960
4061const convo = createConversation ( bus , {
4162 participants : [ "keynesian" , "austrian" , "technologist" ] ,
42- topic : "How should society respond to widespread AI automation and potential job displacement?" ,
63+ topic :
64+ "How should society respond to widespread AI automation and potential job displacement?" ,
4365 maxTurns : 9 ,
4466 delayMs : 2000 ,
4567 // pauseCondition: () => true,
4668
4769 onToken : ( chunk , speaker ) => {
70+ if ( speaker !== currentSpeaker ) {
71+ currentSpeaker = speaker ;
72+ firstToken = true ;
73+ }
74+ if ( firstToken ) {
75+ process . stdout . write ( `\n${ colorize ( speaker ) } ` ) ;
76+ firstToken = false ;
77+ }
4878 process . stdout . write ( chunk ) ;
4979 } ,
5080
@@ -59,28 +89,7 @@ const convo = createConversation(bus, {
5989 } ,
6090} ) ;
6191
62- const rl = readline . createInterface ( {
63- input : process . stdin ,
64- output : process . stdout ,
65- } ) ;
66-
67- rl . on ( "line" , ( input ) => {
68- const msg = input . trim ( ) ;
69- const result = convo . send ( msg ) ;
70- if ( msg ) {
71- if ( result . intent === "interrupt" ) {
72- console . log ( "\n⚡ Interrupted — your message injected." ) ;
73- } else {
74- console . log ( "\n💬 Message injected." ) ;
75- }
76- }
77- } ) ;
78-
79- rl . on ( "SIGINT" , ( ) => {
80- console . log ( "\n🛑 Stopping..." ) ;
81- convo . stop ( ) ;
82- rl . close ( ) ;
83- } ) ;
92+ const rl = attachInteractiveConsole ( convo ) ;
8493
8594console . log ( "💰 Topic: AI, Automation, and the Future of Work?" ) ;
8695console . log ( "💡 Type + Enter to interrupt anytime. Ctrl+C to stop.\n" ) ;
0 commit comments