@elizaos/plugin-matrix 2.0.0-alpha.7 → 2.0.0-beta.1

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.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # @elizaos/plugin-matrix
2
+
3
+ Matrix messaging integration plugin for ElizaOS agents.
4
+
5
+ ## Features
6
+
7
+ - **Decentralized Messaging**: Connect to any Matrix homeserver
8
+ - **End-to-End Encryption**: Optional E2EE support for secure communications
9
+ - **Room Support**: Join, leave, and manage Matrix rooms
10
+ - **Reactions**: React to messages with emoji
11
+ - **Threading**: Support for Matrix threads
12
+ - **Direct Messages**: Handle DMs and group rooms
13
+ - **Typing Indicators**: Send typing notifications
14
+ - **Read Receipts**: Mark messages as read
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @elizaos/plugin-matrix
20
+ ```
21
+
22
+ ## Prerequisites
23
+
24
+ 1. **Matrix Account**: A Matrix account on any homeserver
25
+ 2. **Access Token**: Generate an access token for your account
26
+
27
+ ### Getting an Access Token
28
+
29
+ You can get an access token by:
30
+
31
+ 1. **Element/Web Client**: Settings -> Help & About -> Access Token
32
+ 2. **API Login**: Use the Matrix login API with your password
33
+ 3. **Command Line**: Use `curl` or a tool like `matrix-commander`
34
+
35
+ ## Configuration
36
+
37
+ Set the following environment variables:
38
+
39
+ ### Required
40
+
41
+ | Variable | Description |
42
+ |----------|-------------|
43
+ | `MATRIX_HOMESERVER` | Homeserver URL (e.g., https://matrix.org) |
44
+ | `MATRIX_USER_ID` | Full Matrix user ID (@user:homeserver.org) |
45
+ | `MATRIX_ACCESS_TOKEN` | Access token for authentication |
46
+
47
+ ### Optional
48
+
49
+ | Variable | Description | Default |
50
+ |----------|-------------|---------|
51
+ | `MATRIX_DEVICE_ID` | Device ID for this session | Auto-generated |
52
+ | `MATRIX_ROOMS` | Comma-separated room IDs/aliases to auto-join | - |
53
+ | `MATRIX_AUTO_JOIN` | Auto-accept room invites | `false` |
54
+ | `MATRIX_ENCRYPTION` | Enable E2EE support | `false` |
55
+ | `MATRIX_REQUIRE_MENTION` | Only respond when mentioned in rooms | `false` |
56
+
57
+ ## Usage
58
+
59
+ ### Basic Setup
60
+
61
+ ```typescript
62
+ import matrixPlugin from "@elizaos/plugin-matrix";
63
+
64
+ const agent = new Agent({
65
+ plugins: [matrixPlugin],
66
+ });
67
+ ```
68
+
69
+ ### Actions
70
+
71
+ Matrix messaging is exposed through the canonical message connector actions.
72
+ Use `source: "matrix"` when a request needs to target Matrix explicitly.
73
+
74
+ | Primary action | Operation | Description |
75
+ |----------------|-----------|-------------|
76
+ | `MESSAGE` | `send` | Send a message to a Matrix room, channel, thread, or DM |
77
+ | `MESSAGE` | `react` | React to a Matrix message with an emoji |
78
+ | `MESSAGE` | `list_channels` | List joined Matrix rooms |
79
+ | `MESSAGE` | `join` | Join a Matrix room by ID or alias |
80
+ | `MESSAGE` | `leave` | Leave a Matrix room |
81
+
82
+ ### Providers
83
+
84
+ #### matrixRoomState
85
+
86
+ Provides context about the current Matrix room:
87
+ - Room ID and name
88
+ - Member count
89
+ - Encryption status
90
+ - Whether it's a DM
91
+
92
+ #### matrixUserContext
93
+
94
+ Provides context about the user in the conversation:
95
+ - User ID
96
+ - Display name
97
+ - Avatar URL
98
+
99
+ ### Events
100
+
101
+ The plugin emits the following events:
102
+
103
+ | Event | Description |
104
+ |-------|-------------|
105
+ | `MATRIX_MESSAGE_RECEIVED` | A message was received |
106
+ | `MATRIX_MESSAGE_SENT` | A message was sent |
107
+ | `MATRIX_ROOM_JOINED` | Joined a room |
108
+ | `MATRIX_ROOM_LEFT` | Left a room |
109
+ | `MATRIX_INVITE_RECEIVED` | Received a room invite |
110
+ | `MATRIX_REACTION_RECEIVED` | Received a reaction |
111
+ | `MATRIX_SYNC_COMPLETE` | Initial sync completed |
112
+ | `MATRIX_CONNECTION_READY` | Client connected |
113
+ | `MATRIX_CONNECTION_LOST` | Connection lost |
114
+
115
+ ## Message Limits
116
+
117
+ - Maximum message length: 4000 characters
118
+ - Longer messages are split automatically
119
+
120
+ ## Matrix ID Formats
121
+
122
+ - **User ID**: `@localpart:homeserver.org`
123
+ - **Room ID**: `!opaque_id:homeserver.org`
124
+ - **Room Alias**: `#human_readable:homeserver.org`
125
+
126
+ ## Security Considerations
127
+
128
+ 1. **Token Security**: Never expose your access token
129
+ 2. **Homeserver Trust**: Only connect to trusted homeservers
130
+ 3. **E2EE**: Enable encryption for sensitive communications
131
+ 4. **Room Verification**: Verify room members when using E2EE
132
+
133
+ ## Troubleshooting
134
+
135
+ ### Connection Issues
136
+
137
+ 1. Verify your homeserver URL is correct
138
+ 2. Check that your access token is valid
139
+ 3. Ensure your homeserver is reachable
140
+
141
+ ### Sync Issues
142
+
143
+ 1. The initial sync may take time for accounts with many rooms
144
+ 2. Check homeserver rate limits
145
+ 3. Verify network connectivity
146
+
147
+ ### Encryption Issues
148
+
149
+ 1. Ensure E2EE is enabled on both ends
150
+ 2. Verify device is properly set up
151
+ 3. Check for key verification requirements
152
+
153
+ ## License
154
+
155
+ MIT
package/auto-enable.ts ADDED
@@ -0,0 +1,20 @@
1
+ // Auto-enable check for @elizaos/plugin-matrix.
2
+ //
3
+ // Plugin manifest entry-point — referenced by package.json's
4
+ // `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
5
+ // no service init, no transitive imports of the full plugin runtime. The
6
+ // auto-enable engine loads dozens of these per boot.
7
+ import type { PluginAutoEnableContext } from "@elizaos/core";
8
+
9
+ /** Enable when a `matrix` connector block is present and not explicitly disabled. */
10
+ export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
11
+ const c = (ctx.config?.connectors as Record<string, unknown> | undefined)?.matrix;
12
+ if (!c || typeof c !== "object") return false;
13
+ const config = c as Record<string, unknown>;
14
+ if (config.enabled === false) return false;
15
+ // The full per-connector field check (homeserver/accessToken/userId) lives
16
+ // in the central engine's isConnectorConfigured. We delegate to a simple
17
+ // "block present + not explicitly disabled" check here; the central
18
+ // engine's stricter check remains as a fallback during migration.
19
+ return true;
20
+ }
@@ -0,0 +1,14 @@
1
+ import type { IAgentRuntime } from "@elizaos/core";
2
+ import type { MatrixSettings } from "./types.js";
3
+ export declare const DEFAULT_MATRIX_ACCOUNT_ID = "default";
4
+ export type MatrixAccountConfig = Partial<Omit<MatrixSettings, "rooms" | "accountId">> & {
5
+ accountId?: string;
6
+ id?: string;
7
+ rooms?: string[] | string;
8
+ };
9
+ export declare function normalizeMatrixAccountId(accountId?: unknown): string;
10
+ export declare function listMatrixAccountIds(runtime: IAgentRuntime): string[];
11
+ export declare function resolveDefaultMatrixAccountId(runtime: IAgentRuntime): string;
12
+ export declare function readMatrixAccountId(...sources: unknown[]): string | undefined;
13
+ export declare function resolveMatrixAccountSettings(runtime: IAgentRuntime, requestedAccountId?: string | null): MatrixSettings;
14
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,GAAG;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CAC3B,CAAC;AAqEF,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAIpE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAkBrE;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAQ5E;AAED,wBAAgB,mBAAmB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CA6B7E;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa,EACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,cAAc,CAiDhB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Matrix ConnectorAccountManager provider.
3
+ *
4
+ * Adapts the multi-account scaffolding in `accounts.ts` to the
5
+ * `ConnectorAccountProvider` contract from
6
+ * `@elizaos/core/connectors/account-manager`.
7
+ *
8
+ * Source of truth for accounts is character settings (`character.settings.matrix`)
9
+ * + MATRIX_ACCOUNTS JSON env var + single-account env vars (MATRIX_HOMESERVER,
10
+ * MATRIX_USER_ID, MATRIX_ACCESS_TOKEN). AccountKey is `<homeserver>/<userId>`
11
+ * by convention; role is `OWNER` since matrix access tokens authenticate the
12
+ * user, not a bot. E2EE keys are scoped per account by the matrix client and
13
+ * are NOT shared between accounts.
14
+ */
15
+ import type { ConnectorAccountProvider, IAgentRuntime } from "@elizaos/core";
16
+ export declare const MATRIX_PROVIDER_ID = "matrix";
17
+ export declare function createMatrixConnectorAccountProvider(runtime: IAgentRuntime): ConnectorAccountProvider;
18
+ //# sourceMappingURL=connector-account-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-account-provider.d.ts","sourceRoot":"","sources":["../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAIV,wBAAwB,EACxB,aAAa,EACd,MAAM,eAAe,CAAC;AASvB,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAmC3C,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,aAAa,GACrB,wBAAwB,CAmC1B"}
package/dist/index.d.ts CHANGED
@@ -4,16 +4,9 @@
4
4
  * This plugin provides Matrix protocol integration using matrix-js-sdk.
5
5
  */
6
6
  import type { Plugin } from "@elizaos/core";
7
+ export * from "./accounts.js";
7
8
  export { MatrixService } from "./service.js";
8
9
  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
10
  /**
18
11
  * Matrix plugin definition.
19
12
  */
@@ -1 +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"}
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;AAG3D,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,cAAc,YAAY,CAAC;AAO3B;;GAEG;AACH,QAAA,MAAM,YAAY,EAAE,MAmFnB,CAAC;AAEF,eAAe,YAAY,CAAC"}