@elizaos/plugin-matrix 2.0.0-alpha.3 → 2.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Join room action for Matrix plugin.
3
+ */
4
+ import type { Action } from "@elizaos/core";
5
+ export declare const joinRoom: Action;
6
+ //# sourceMappingURL=joinRoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joinRoom.d.ts","sourceRoot":"","sources":["../../src/actions/joinRoom.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,MAAM,EAOP,MAAM,eAAe,CAAC;AA2BvB,eAAO,MAAM,QAAQ,EAAE,MA4GtB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * List rooms action for Matrix plugin.
3
+ */
4
+ import type { Action } from "@elizaos/core";
5
+ export declare const listRooms: Action;
6
+ //# sourceMappingURL=listRooms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listRooms.d.ts","sourceRoot":"","sources":["../../src/actions/listRooms.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,MAAM,EAOP,MAAM,eAAe,CAAC;AAIvB,eAAO,MAAM,SAAS,EAAE,MA6EvB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Send message action for Matrix plugin.
3
+ */
4
+ import type { Action } from "@elizaos/core";
5
+ export declare const sendMessage: Action;
6
+ //# sourceMappingURL=sendMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendMessage.d.ts","sourceRoot":"","sources":["../../src/actions/sendMessage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,MAAM,EAOP,MAAM,eAAe,CAAC;AA6BvB,eAAO,MAAM,WAAW,EAAE,MAqIzB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Send reaction action for Matrix plugin.
3
+ */
4
+ import type { Action } from "@elizaos/core";
5
+ export declare const sendReaction: Action;
6
+ //# sourceMappingURL=sendReaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendReaction.d.ts","sourceRoot":"","sources":["../../src/actions/sendReaction.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,MAAM,EAOP,MAAM,eAAe,CAAC;AAwBvB,eAAO,MAAM,YAAY,EAAE,MA6H1B,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Matrix messaging integration plugin for ElizaOS.
3
+ *
4
+ * This plugin provides Matrix protocol integration using matrix-js-sdk.
5
+ */
6
+ import type { Plugin } from "@elizaos/core";
7
+ export { MatrixService } from "./service.js";
8
+ export * from "./types.js";
9
+ import { joinRoom } from "./actions/joinRoom.js";
10
+ import { listRooms } from "./actions/listRooms.js";
11
+ import { sendMessage } from "./actions/sendMessage.js";
12
+ import { sendReaction } from "./actions/sendReaction.js";
13
+ export { sendMessage, sendReaction, listRooms, joinRoom };
14
+ import { roomStateProvider } from "./providers/roomState.js";
15
+ import { userContextProvider } from "./providers/userContext.js";
16
+ export { roomStateProvider, userContextProvider };
17
+ /**
18
+ * Matrix plugin definition.
19
+ */
20
+ declare const matrixPlugin: Plugin;
21
+ export default matrixPlugin;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAI3D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAC;AAKlD;;GAEG;AACH,QAAA,MAAM,YAAY,EAAE,MA8DnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { logger as logger2 } from "@elizaos/core";
3
3
 
4
4
  // src/service.ts
5
- import { Service, logger } from "@elizaos/core";
5
+ import { logger, Service } from "@elizaos/core";
6
6
  import * as sdk from "matrix-js-sdk";
7
7
 
8
8
  // src/types.ts
@@ -402,8 +402,185 @@ class MatrixService extends Service {
402
402
  await this.client.sendReadReceipt(new sdk.MatrixEvent({ event_id: eventId, room_id: roomId }));
403
403
  }
404
404
  }
405
- // src/actions/sendMessage.ts
405
+ // src/actions/joinRoom.ts
406
406
  import { composePromptFromState, ModelType, parseJSONObjectFromText } from "@elizaos/core";
407
+ var JOIN_ROOM_TEMPLATE = `You are helping to extract a Matrix room identifier.
408
+
409
+ The user wants to join a Matrix room.
410
+
411
+ Recent conversation:
412
+ {{recentMessages}}
413
+
414
+ Extract the room ID (!room:server) or room alias (#alias:server) to join.
415
+
416
+ Respond with a JSON object like:
417
+ {
418
+ "room": "!room:matrix.org"
419
+ }
420
+
421
+ or:
422
+
423
+ {
424
+ "room": "#alias:matrix.org"
425
+ }
426
+
427
+ Only respond with the JSON object, no other text.`;
428
+ var joinRoom = {
429
+ name: "MATRIX_JOIN_ROOM",
430
+ similes: ["JOIN_MATRIX_ROOM", "ENTER_ROOM"],
431
+ description: "Join a Matrix room by ID or alias",
432
+ validate: async (_runtime, message, _state) => {
433
+ return message.content.source === "matrix";
434
+ },
435
+ handler: async (runtime, message, state, _options, callback) => {
436
+ const matrixService = runtime.getService(MATRIX_SERVICE_NAME);
437
+ if (!matrixService || !matrixService.isConnected()) {
438
+ if (callback) {
439
+ await callback({ text: "Matrix service is not available.", source: "matrix" });
440
+ }
441
+ return { success: false, error: "Matrix service not available" };
442
+ }
443
+ const composedState = state ?? {
444
+ values: {},
445
+ data: {},
446
+ text: ""
447
+ };
448
+ const prompt = await composePromptFromState({
449
+ template: JOIN_ROOM_TEMPLATE,
450
+ state: composedState
451
+ });
452
+ let room = null;
453
+ for (let attempt = 0;attempt < 3; attempt++) {
454
+ const response = await runtime.useModel(ModelType.TEXT_SMALL, {
455
+ prompt
456
+ });
457
+ const parsed = parseJSONObjectFromText(response);
458
+ if (parsed?.room) {
459
+ const roomStr = String(parsed.room).trim();
460
+ if (isValidMatrixRoomId(roomStr) || isValidMatrixRoomAlias(roomStr)) {
461
+ room = roomStr;
462
+ break;
463
+ }
464
+ }
465
+ }
466
+ if (!room) {
467
+ if (callback) {
468
+ await callback({
469
+ text: "I couldn't understand which room you want me to join. Please specify a room ID (!room:server) or alias (#alias:server).",
470
+ source: "matrix"
471
+ });
472
+ }
473
+ return { success: false, error: "Could not extract room identifier" };
474
+ }
475
+ try {
476
+ const roomId = await matrixService.joinRoom(room);
477
+ if (callback) {
478
+ await callback({
479
+ text: `Joined room ${room}.`,
480
+ source: message.content.source
481
+ });
482
+ }
483
+ return {
484
+ success: true,
485
+ data: {
486
+ roomId,
487
+ joined: room
488
+ }
489
+ };
490
+ } catch (err) {
491
+ const error = err instanceof Error ? err.message : String(err);
492
+ if (callback) {
493
+ await callback({
494
+ text: `Failed to join room: ${error}`,
495
+ source: "matrix"
496
+ });
497
+ }
498
+ return { success: false, error };
499
+ }
500
+ },
501
+ examples: [
502
+ [
503
+ {
504
+ name: "{{user1}}",
505
+ content: { text: "Join #general:matrix.org" }
506
+ },
507
+ {
508
+ name: "{{agent}}",
509
+ content: {
510
+ text: "I'll join that room.",
511
+ actions: ["MATRIX_JOIN_ROOM"]
512
+ }
513
+ }
514
+ ]
515
+ ]
516
+ };
517
+
518
+ // src/actions/listRooms.ts
519
+ var listRooms = {
520
+ name: "MATRIX_LIST_ROOMS",
521
+ similes: ["LIST_MATRIX_ROOMS", "SHOW_ROOMS", "GET_ROOMS", "MY_ROOMS"],
522
+ description: "List all Matrix rooms the bot has joined",
523
+ validate: async (_runtime, message, _state) => {
524
+ return message.content.source === "matrix";
525
+ },
526
+ handler: async (runtime, message, _state, _options, callback) => {
527
+ const matrixService = runtime.getService(MATRIX_SERVICE_NAME);
528
+ if (!matrixService || !matrixService.isConnected()) {
529
+ if (callback) {
530
+ await callback({ text: "Matrix service is not available.", source: "matrix" });
531
+ }
532
+ return { success: false, error: "Matrix service not available" };
533
+ }
534
+ const rooms = await matrixService.getJoinedRooms();
535
+ const roomList = rooms.map((room) => {
536
+ const name = room.name || room.canonicalAlias || room.roomId;
537
+ const members = `${room.memberCount} members`;
538
+ const encrypted = room.isEncrypted ? " (encrypted)" : "";
539
+ return `- ${name} (${members})${encrypted}`;
540
+ });
541
+ const responseText = rooms.length > 0 ? `Joined ${rooms.length} room(s):
542
+
543
+ ${roomList.join(`
544
+ `)}` : "Not currently in any rooms.";
545
+ if (callback) {
546
+ await callback({
547
+ text: responseText,
548
+ source: message.content.source
549
+ });
550
+ }
551
+ return {
552
+ success: true,
553
+ data: {
554
+ roomCount: rooms.length,
555
+ rooms: rooms.map((r) => ({
556
+ roomId: r.roomId,
557
+ name: r.name,
558
+ alias: r.canonicalAlias,
559
+ memberCount: r.memberCount,
560
+ isEncrypted: r.isEncrypted
561
+ }))
562
+ }
563
+ };
564
+ },
565
+ examples: [
566
+ [
567
+ {
568
+ name: "{{user1}}",
569
+ content: { text: "What rooms are you in?" }
570
+ },
571
+ {
572
+ name: "{{agent}}",
573
+ content: {
574
+ text: "I'll list the rooms I've joined.",
575
+ actions: ["MATRIX_LIST_ROOMS"]
576
+ }
577
+ }
578
+ ]
579
+ ]
580
+ };
581
+
582
+ // src/actions/sendMessage.ts
583
+ import { composePromptFromState as composePromptFromState2, ModelType as ModelType2, parseJSONObjectFromText as parseJSONObjectFromText2 } from "@elizaos/core";
407
584
  var SEND_MESSAGE_TEMPLATE = `You are helping to extract send message parameters for Matrix.
408
585
 
409
586
  The user wants to send a message to a Matrix room.
@@ -424,13 +601,9 @@ Respond with a JSON object like:
424
601
  Only respond with the JSON object, no other text.`;
425
602
  var sendMessage = {
426
603
  name: "MATRIX_SEND_MESSAGE",
427
- similes: [
428
- "SEND_MATRIX_MESSAGE",
429
- "MESSAGE_MATRIX",
430
- "MATRIX_TEXT"
431
- ],
604
+ similes: ["SEND_MATRIX_MESSAGE", "MESSAGE_MATRIX", "MATRIX_TEXT"],
432
605
  description: "Send a message to a Matrix room",
433
- validate: async (runtime, message, _state) => {
606
+ validate: async (_runtime, message, _state) => {
434
607
  return message.content.source === "matrix";
435
608
  },
436
609
  handler: async (runtime, message, state, _options, callback) => {
@@ -446,16 +619,16 @@ var sendMessage = {
446
619
  data: {},
447
620
  text: ""
448
621
  };
449
- const prompt = await composePromptFromState({
622
+ const prompt = await composePromptFromState2({
450
623
  template: SEND_MESSAGE_TEMPLATE,
451
624
  state: composedState
452
625
  });
453
626
  let messageInfo = null;
454
627
  for (let attempt = 0;attempt < 3; attempt++) {
455
- const response = await runtime.useModel(ModelType.TEXT_SMALL, {
628
+ const response = await runtime.useModel(ModelType2.TEXT_SMALL, {
456
629
  prompt
457
630
  });
458
- const parsed = parseJSONObjectFromText(response);
631
+ const parsed = parseJSONObjectFromText2(response);
459
632
  if (parsed?.text) {
460
633
  messageInfo = {
461
634
  text: String(parsed.text),
@@ -536,7 +709,7 @@ var sendMessage = {
536
709
  };
537
710
 
538
711
  // src/actions/sendReaction.ts
539
- import { composePromptFromState as composePromptFromState2, ModelType as ModelType2, parseJSONObjectFromText as parseJSONObjectFromText2 } from "@elizaos/core";
712
+ import { composePromptFromState as composePromptFromState3, ModelType as ModelType3, parseJSONObjectFromText as parseJSONObjectFromText3 } from "@elizaos/core";
540
713
  var SEND_REACTION_TEMPLATE = `You are helping to extract reaction parameters for Matrix.
541
714
 
542
715
  The user wants to react to a Matrix message with an emoji.
@@ -557,13 +730,9 @@ Respond with a JSON object like:
557
730
  Only respond with the JSON object, no other text.`;
558
731
  var sendReaction = {
559
732
  name: "MATRIX_SEND_REACTION",
560
- similes: [
561
- "REACT_MATRIX",
562
- "MATRIX_REACT",
563
- "ADD_MATRIX_REACTION"
564
- ],
733
+ similes: ["REACT_MATRIX", "MATRIX_REACT", "ADD_MATRIX_REACTION"],
565
734
  description: "React to a Matrix message with an emoji",
566
- validate: async (runtime, message, _state) => {
735
+ validate: async (_runtime, message, _state) => {
567
736
  return message.content.source === "matrix";
568
737
  },
569
738
  handler: async (runtime, message, state, _options, callback) => {
@@ -579,16 +748,16 @@ var sendReaction = {
579
748
  data: {},
580
749
  text: ""
581
750
  };
582
- const prompt = await composePromptFromState2({
751
+ const prompt = await composePromptFromState3({
583
752
  template: SEND_REACTION_TEMPLATE,
584
753
  state: composedState
585
754
  });
586
755
  let reactionInfo = null;
587
756
  for (let attempt = 0;attempt < 3; attempt++) {
588
- const response = await runtime.useModel(ModelType2.TEXT_SMALL, {
757
+ const response = await runtime.useModel(ModelType3.TEXT_SMALL, {
589
758
  prompt
590
759
  });
591
- const parsed = parseJSONObjectFromText2(response);
760
+ const parsed = parseJSONObjectFromText3(response);
592
761
  if (parsed?.emoji && parsed?.eventId) {
593
762
  reactionInfo = {
594
763
  emoji: String(parsed.emoji),
@@ -659,191 +828,6 @@ var sendReaction = {
659
828
  ]
660
829
  };
661
830
 
662
- // src/actions/listRooms.ts
663
- var listRooms = {
664
- name: "MATRIX_LIST_ROOMS",
665
- similes: [
666
- "LIST_MATRIX_ROOMS",
667
- "SHOW_ROOMS",
668
- "GET_ROOMS",
669
- "MY_ROOMS"
670
- ],
671
- description: "List all Matrix rooms the bot has joined",
672
- validate: async (runtime, message, _state) => {
673
- return message.content.source === "matrix";
674
- },
675
- handler: async (runtime, message, _state, _options, callback) => {
676
- const matrixService = runtime.getService(MATRIX_SERVICE_NAME);
677
- if (!matrixService || !matrixService.isConnected()) {
678
- if (callback) {
679
- await callback({ text: "Matrix service is not available.", source: "matrix" });
680
- }
681
- return { success: false, error: "Matrix service not available" };
682
- }
683
- const rooms = await matrixService.getJoinedRooms();
684
- const roomList = rooms.map((room) => {
685
- const name = room.name || room.canonicalAlias || room.roomId;
686
- const members = `${room.memberCount} members`;
687
- const encrypted = room.isEncrypted ? " (encrypted)" : "";
688
- return `- ${name} (${members})${encrypted}`;
689
- });
690
- const responseText = rooms.length > 0 ? `Joined ${rooms.length} room(s):
691
-
692
- ${roomList.join(`
693
- `)}` : "Not currently in any rooms.";
694
- if (callback) {
695
- await callback({
696
- text: responseText,
697
- source: message.content.source
698
- });
699
- }
700
- return {
701
- success: true,
702
- data: {
703
- roomCount: rooms.length,
704
- rooms: rooms.map((r) => ({
705
- roomId: r.roomId,
706
- name: r.name,
707
- alias: r.canonicalAlias,
708
- memberCount: r.memberCount,
709
- isEncrypted: r.isEncrypted
710
- }))
711
- }
712
- };
713
- },
714
- examples: [
715
- [
716
- {
717
- name: "{{user1}}",
718
- content: { text: "What rooms are you in?" }
719
- },
720
- {
721
- name: "{{agent}}",
722
- content: {
723
- text: "I'll list the rooms I've joined.",
724
- actions: ["MATRIX_LIST_ROOMS"]
725
- }
726
- }
727
- ]
728
- ]
729
- };
730
-
731
- // src/actions/joinRoom.ts
732
- import { composePromptFromState as composePromptFromState3, ModelType as ModelType3, parseJSONObjectFromText as parseJSONObjectFromText3 } from "@elizaos/core";
733
- var JOIN_ROOM_TEMPLATE = `You are helping to extract a Matrix room identifier.
734
-
735
- The user wants to join a Matrix room.
736
-
737
- Recent conversation:
738
- {{recentMessages}}
739
-
740
- Extract the room ID (!room:server) or room alias (#alias:server) to join.
741
-
742
- Respond with a JSON object like:
743
- {
744
- "room": "!room:matrix.org"
745
- }
746
-
747
- or:
748
-
749
- {
750
- "room": "#alias:matrix.org"
751
- }
752
-
753
- Only respond with the JSON object, no other text.`;
754
- var joinRoom = {
755
- name: "MATRIX_JOIN_ROOM",
756
- similes: [
757
- "JOIN_MATRIX_ROOM",
758
- "ENTER_ROOM"
759
- ],
760
- description: "Join a Matrix room by ID or alias",
761
- validate: async (runtime, message, _state) => {
762
- return message.content.source === "matrix";
763
- },
764
- handler: async (runtime, message, state, _options, callback) => {
765
- const matrixService = runtime.getService(MATRIX_SERVICE_NAME);
766
- if (!matrixService || !matrixService.isConnected()) {
767
- if (callback) {
768
- await callback({ text: "Matrix service is not available.", source: "matrix" });
769
- }
770
- return { success: false, error: "Matrix service not available" };
771
- }
772
- const composedState = state ?? {
773
- values: {},
774
- data: {},
775
- text: ""
776
- };
777
- const prompt = await composePromptFromState3({
778
- template: JOIN_ROOM_TEMPLATE,
779
- state: composedState
780
- });
781
- let room = null;
782
- for (let attempt = 0;attempt < 3; attempt++) {
783
- const response = await runtime.useModel(ModelType3.TEXT_SMALL, {
784
- prompt
785
- });
786
- const parsed = parseJSONObjectFromText3(response);
787
- if (parsed?.room) {
788
- const roomStr = String(parsed.room).trim();
789
- if (isValidMatrixRoomId(roomStr) || isValidMatrixRoomAlias(roomStr)) {
790
- room = roomStr;
791
- break;
792
- }
793
- }
794
- }
795
- if (!room) {
796
- if (callback) {
797
- await callback({
798
- text: "I couldn't understand which room you want me to join. Please specify a room ID (!room:server) or alias (#alias:server).",
799
- source: "matrix"
800
- });
801
- }
802
- return { success: false, error: "Could not extract room identifier" };
803
- }
804
- try {
805
- const roomId = await matrixService.joinRoom(room);
806
- if (callback) {
807
- await callback({
808
- text: `Joined room ${room}.`,
809
- source: message.content.source
810
- });
811
- }
812
- return {
813
- success: true,
814
- data: {
815
- roomId,
816
- joined: room
817
- }
818
- };
819
- } catch (err) {
820
- const error = err instanceof Error ? err.message : String(err);
821
- if (callback) {
822
- await callback({
823
- text: `Failed to join room: ${error}`,
824
- source: "matrix"
825
- });
826
- }
827
- return { success: false, error };
828
- }
829
- },
830
- examples: [
831
- [
832
- {
833
- name: "{{user1}}",
834
- content: { text: "Join #general:matrix.org" }
835
- },
836
- {
837
- name: "{{agent}}",
838
- content: {
839
- text: "I'll join that room.",
840
- actions: ["MATRIX_JOIN_ROOM"]
841
- }
842
- }
843
- ]
844
- ]
845
- };
846
-
847
831
  // src/providers/roomState.ts
848
832
  var roomStateProvider = {
849
833
  name: "matrixRoomState",
@@ -1042,4 +1026,4 @@ export {
1042
1026
  MATRIX_SERVICE_NAME
1043
1027
  };
1044
1028
 
1045
- //# debugId=35E58066575BB30D64756E2164756E21
1029
+ //# debugId=A4D19A2C309BC12964756E2164756E21