@@ -259,10 +259,13 @@ export class AIService {
259
259
console . log ( "KM" , this . runtime . knowledgeManager )
260
260
console . log ( "Before" , this . runtime . memoryManagers )
261
261
this . runtime . memoryManagers . set ( this . runtime . knowledgeManager . tableName , this . runtime . knowledgeManager ) ;
262
+ this . runtime . messageManager = this . runtime . knowledgeManager ;
263
+
262
264
try {
263
265
this . runtime . databaseAdapter = dbadapter . init ( this . runtime ) ;
264
266
} catch ( error ) {
265
267
console . error ( "Failed to initialize database adapter:" , error ) ;
268
+ throw error ;
266
269
}
267
270
console . log ( "After" , this . runtime . memoryManagers )
268
271
}
@@ -363,164 +366,164 @@ function contentToUuid(content:string):UUID {
363
366
return uuid as `${string } -${string } -${string } -${string } -${string } `;
364
367
}
365
368
366
- async function process_text ( this : any , agentId : string , userName : string , name : string , sUserId : string | undefined ,
367
- sRoomId : string , text :string , agents : Map < string , any > ) {
368
- const roomId = stringToUuid (
369
- sRoomId ?? "default-room-" + agentId
370
- ) ;
371
- const userId = stringToUuid ( sUserId ?? "user" ) ;
372
-
373
- let runtime = agents . get ( agentId ) ;
374
-
375
- if ( ! runtime ) {
376
- console . error (
377
- `Runtime not found for agentId: ${ agentId } `
378
- ) ;
379
- return ;
380
- }
381
-
382
- await runtime . ensureConnection (
383
- userId ,
384
- roomId ,
385
- userName ,
386
- name ,
387
- "direct"
388
- ) ;
369
+ // async function process_text(this: any, agentId: string, userName: string, name: string, sUserId: string | undefined,
370
+ // sRoomId: string, text:string, agents: Map<string, any>) {
371
+ // const roomId = stringToUuid(
372
+ // sRoomId ?? "default-room-" + agentId
373
+ // );
374
+ // const userId = stringToUuid(sUserId ?? "user");
375
+
376
+ // let runtime = agents.get(agentId);
377
+
378
+ // if (!runtime) {
379
+ // console.error(
380
+ // `Runtime not found for agentId: ${agentId}`
381
+ // );
382
+ // return;
383
+ // }
384
+
385
+ // await runtime.ensureConnection(
386
+ // userId,
387
+ // roomId,
388
+ // userName,
389
+ // name,
390
+ // "direct"
391
+ // );
389
392
390
393
391
- // if empty text, directly return
392
- if ( ! text ) {
393
- console . error ( "Empty text" ) ;
394
- return ;
395
- }
396
-
397
- const messageId = stringToUuid ( Date . now ( ) . toString ( ) ) ;
398
-
399
- const attachments : Media [ ] = [ ] ;
400
- // if (req.file) {
401
- // const filePath = path.join(
402
- // process.cwd(),
403
- // "data",
404
- // "uploads",
405
- // req.file.filename
406
- // );
407
- // attachments.push({
408
- // id: Date.now().toString(),
409
- // url: filePath,
410
- // title: req.file.originalname,
411
- // source: "direct",
412
- // description: `Uploaded file: ${req.file.originalname}`,
413
- // text: "",
414
- // contentType: req.file.mimetype,
415
- // });
416
- // }
417
-
418
- const content : Content = {
419
- text,
420
- attachments,
421
- source : "direct" ,
422
- inReplyTo : "0-0-0-0-0" ,
423
- } ;
424
-
425
- const userMessage = {
426
- content,
427
- userId,
428
- roomId,
429
- agentId : runtime . agentId ,
430
- } ;
431
-
432
- const memory : Memory = {
433
- id : contentToUuid ( content . text ) , // stringToUuid(messageId + "-" + userId),
434
- ...userMessage ,
435
- agentId : runtime . agentId ,
436
- userId,
437
- roomId,
438
- content,
439
- createdAt : Date . now ( ) ,
440
- } ;
441
-
442
-
443
-
444
- await runtime . messageManager . addEmbeddingToMemory ( memory ) ;
445
- await runtime . messageManager . createMemory ( memory ) ;
446
-
447
- let state = await runtime . composeState ( userMessage , {
448
- agentName : runtime . character . name ,
449
- } ) ;
450
-
451
- const context = composeContext ( {
452
- state,
453
- template : messageHandlerTemplate ,
454
- } ) ;
455
-
456
- const response = await generateMessageResponse ( {
457
- runtime : runtime ,
458
- context,
459
- modelClass : ModelClass . LARGE ,
460
- } ) ;
461
-
462
- if ( ! response ) {
463
- // res.status(500).send(
464
- /// "No response from generateMessageResponse"
465
- console . error ( "No response from generateMessageResponse" ) ;
466
- //);
467
- return ;
468
- }
394
+ // // if empty text, directly return
395
+ // if (!text) {
396
+ // console.error("Empty text");
397
+ // return;
398
+ // }
399
+
400
+ // const messageId = stringToUuid(Date.now().toString());
401
+
402
+ // const attachments: Media[] = [];
403
+ // // if (req.file) {
404
+ // // const filePath = path.join(
405
+ // // process.cwd(),
406
+ // // "data",
407
+ // // "uploads",
408
+ // // req.file.filename
409
+ // // );
410
+ // // attachments.push({
411
+ // // id: Date.now().toString(),
412
+ // // url: filePath,
413
+ // // title: req.file.originalname,
414
+ // // source: "direct",
415
+ // // description: `Uploaded file: ${req.file.originalname}`,
416
+ // // text: "",
417
+ // // contentType: req.file.mimetype,
418
+ // // });
419
+ // // }
420
+
421
+ // const content: Content = {
422
+ // text,
423
+ // attachments,
424
+ // source: "direct",
425
+ // inReplyTo: "0-0-0-0-0",
426
+ // };
469
427
470
- // save response to memory
471
- const responseMessage : Memory = {
472
- id : stringToUuid ( messageId + "-" + runtime . agentId ) ,
473
- ...userMessage ,
474
- userId : runtime . agentId ,
475
- content : response ,
476
- embedding : getEmbeddingZeroVector ( ) ,
477
- createdAt : Date . now ( ) ,
478
- } ;
479
-
480
- await runtime . messageManager . createMemory ( responseMessage ) ;
481
-
482
- state = await runtime . updateRecentMessageState ( state ) ;
483
-
484
- let message = null as Content | null ;
485
-
486
- await runtime . processActions (
487
- memory ,
488
- [ responseMessage ] ,
489
- state ,
490
- async ( newMessages : Content | null ) => {
491
- message = newMessages ;
492
- return [ memory ] ;
493
- }
494
- ) ;
428
+ // const userMessage = {
429
+ // content,
430
+ // userId,
431
+ // roomId,
432
+ // agentId: runtime.agentId,
433
+ // };
495
434
496
- await runtime . evaluate ( memory , state ) ;
435
+ // const memory: Memory = {
436
+ // id: contentToUuid(content.text), // stringToUuid(messageId + "-" + userId),
437
+ // ...userMessage,
438
+ // agentId: runtime.agentId,
439
+ // userId,
440
+ // roomId,
441
+ // content,
442
+ // createdAt: Date.now(),
443
+ // };
497
444
498
- // Check if we should suppress the initial message
499
- const action = runtime . actions . find (
500
- ( a : { name : string | undefined ; } ) => a . name === response . action
501
- ) ;
502
- const shouldSuppressInitialMessage =
503
- action ?. suppressInitialMessage ;
445
+
504
446
505
- if ( ! shouldSuppressInitialMessage ) {
506
- if ( message ) {
507
- //res.json([response, message]);
508
- console . log ( [ response , message ] ) ;
509
- } else {
510
- //res.json([response]);
511
- console . log ( [ response ] ) ;
447
+ // await runtime.messageManager.addEmbeddingToMemory(memory);
448
+ // await runtime.messageManager.createMemory(memory);
449
+
450
+ // let state = await runtime.composeState(userMessage, {
451
+ // agentName: runtime.character.name,
452
+ // });
453
+
454
+ // const context = composeContext({
455
+ // state,
456
+ // template: messageHandlerTemplate,
457
+ // });
458
+
459
+ // const response = await generateMessageResponse({
460
+ // runtime: runtime,
461
+ // context,
462
+ // modelClass: ModelClass.LARGE,
463
+ // });
464
+
465
+ // if (!response) {
466
+ // // res.status(500).send(
467
+ // /// "No response from generateMessageResponse"
468
+ // console.error("No response from generateMessageResponse");
469
+ // //);
470
+ // return;
471
+ // }
472
+
473
+ // // save response to memory
474
+ // const responseMessage: Memory = {
475
+ // id: stringToUuid(messageId + "-" + runtime.agentId),
476
+ // ...userMessage,
477
+ // userId: runtime.agentId,
478
+ // content: response,
479
+ // embedding: getEmbeddingZeroVector(),
480
+ // createdAt: Date.now(),
481
+ // };
512
482
513
- }
514
- } else {
515
- if ( message ) {
516
- //res.json([message]);
517
- console . log ( [ message ] ) ;
518
- } else {
519
- //res.json([]);
520
- console . log ( [ ] ) ;
521
- }
522
- }
523
- }
483
+ // await runtime.messageManager.createMemory(responseMessage);
484
+
485
+ // state = await runtime.updateRecentMessageState(state);
486
+
487
+ // let message = null as Content | null;
488
+
489
+ // await runtime.processActions(
490
+ // memory,
491
+ // [responseMessage],
492
+ // state,
493
+ // async (newMessages: Content | null) => {
494
+ // message = newMessages;
495
+ // return [memory];
496
+ // }
497
+ // );
498
+
499
+ // await runtime.evaluate(memory, state);
500
+
501
+ // // Check if we should suppress the initial message
502
+ // const action = runtime.actions.find(
503
+ // (a: { name: string | undefined; }) => a.name === response.action
504
+ // );
505
+ // const shouldSuppressInitialMessage =
506
+ // action?.suppressInitialMessage;
507
+
508
+ // if (!shouldSuppressInitialMessage) {
509
+ // if (message) {
510
+ // //res.json([response, message]);
511
+ // console.log([response, message]);
512
+ // } else {
513
+ // //res.json([response]);
514
+ // console.log([response]);
515
+
516
+ // }
517
+ // } else {
518
+ // if (message) {
519
+ // //res.json([message]);
520
+ // console.log([message]);
521
+ // } else {
522
+ // //res.json([]);
523
+ // console.log([]);
524
+ // }
525
+ // }
526
+ // }
524
527
525
528
// interface IMemoryManager {
526
529
// runtime: string;
0 commit comments