@@ -76,7 +76,7 @@ Update the `index.ts` file in your `hello-agent` application directory with the
7676<TypeScriptExample filename = " index.ts" >
7777
7878``` ts
79- import { DeepgramSTT , TextComponent , RealtimeKitTransport , ElevenLabsTTS , ArtificialObject } from ' @cloudflare/realtime-agents' ;
79+ import { DeepgramSTT , TextComponent , RealtimeKitTransport , ElevenLabsTTS , RealtimeAgent } from ' @cloudflare/realtime-agents' ;
8080
8181class MyTextProcessor extends TextComponent {
8282 env: Env ;
@@ -94,46 +94,48 @@ class MyTextProcessor extends TextComponent {
9494 }
9595}
9696
97- export class RoomObject extends ArtificialObject <Env > {
97+ export class MyAgent extends RealtimeAgent <Env > {
9898 constructor (ctx : DurableObjectState , env : Env ) {
9999 super (ctx , env );
100100 }
101101
102- async init(meetingId : string , authToken : string , workerUrl : string , accountId : string , apiToken : string ) {
102+ async init(agentId : string , meetingId : string , authToken : string , workerUrl : string , accountId : string , apiToken : string ) {
103103 // Construct your text processor for generating responses to text
104104 const textProcessor = new MyTextProcessor (this .env );
105105 // Construct a Meeting object to join the RTK meeting
106- const meeting = new RealtimeKitTransport (meetingId , authToken , [
107- {
108- media_kind: ' audio' ,
109- stream_kind: ' webcam' ,
110- preset_name: ' group_call_host' ,
111- },
112- ]);
106+ const rtkTransport = new RealtimeKitTransport (meetingId , authToken );
113107
114108 // Construct a pipeline to take in meeting audio, transcribe it using
115109 // Deepgram, and pass our generated responses through ElevenLabs to
116110 // be spoken in the meeting
117111 await this .initPipeline (
118- [meeting , new DeepgramSTT (this .env .DEEPGRAM_API_KEY ), textProcessor , new ElevenLabsTTS (this .env .ELEVENLABS_API_KEY ), meeting ],
119- meetingId ,
112+ [
113+ rtkTransport ,
114+ new DeepgramSTT (this .env .DEEPGRAM_API_KEY ),
115+ textProcessor ,
116+ new ElevenLabsTTS (this .env .ELEVENLABS_API_KEY ),
117+ rtkTransport ,
118+ ],
119+ agentId ,
120120 workerUrl ,
121121 accountId ,
122122 apiToken ,
123123 );
124124
125+ const { meeting } = rtkTransport ;
126+
125127 // The RTK meeting object is accessible to us, so we can register handlers
126128 // on various events like participant joins/leaves, chat, etc.
127129 // This is optional
128- meeting .rtkMeeting . participants .joined .on (' participantJoined' , (participant ) => {
130+ meeting .participants .joined .on (' participantJoined' , (participant ) => {
129131 textProcessor .speak (` Participant Joined ${participant .name } ` );
130132 });
131- meeting .rtkMeeting . participants .joined .on (' participantLeft' , (participant ) => {
133+ meeting .participants .joined .on (' participantLeft' , (participant ) => {
132134 textProcessor .speak (` Participant Left ${participant .name } ` );
133135 });
134136
135137 // Make sure to actually join the meeting after registering all handlers
136- await meeting .rtkMeeting . join ();
138+ await meeting .join ();
137139 }
138140
139141 async deinit() {
@@ -150,7 +152,9 @@ export default {
150152 return new Response (null , { status: 400 });
151153 }
152154
153- const stub = env .ROOM_OBJECT .get (env .ROOM_OBJECT .idFromName (meetingId ));
155+ const agentId = meetingId ;
156+ const agent = env .MY_AGENT .idFromName (meetingId );
157+ const stub = env .MY_AGENT .get (agent );
154158 // The fetch method is implemented for handling internal pipeline logic
155159 if (url .pathname .startsWith (' /agentsInternal' )) {
156160 return stub .fetch (request );
@@ -167,7 +171,7 @@ export default {
167171 }
168172
169173 // We just need the part after `Bearer `
170- await stub .init (meetingId , authHeader .split (' ' )[1 ], url .host , env .ACCOUNT_ID , env .API_TOKEN );
174+ await stub .init (agentId , meetingId , authHeader .split (' ' )[1 ], url .host , env .ACCOUNT_ID , env .API_TOKEN );
171175
172176 return new Response (null , { status: 200 });
173177 case ' /deinit' :
@@ -178,6 +182,7 @@ export default {
178182 return new Response (null , { status: 404 });
179183 },
180184} satisfies ExportedHandler <Env >;
185+
181186```
182187</TypeScriptExample >
183188
0 commit comments