@elizaos/plugin-imessage 2.0.3-beta.2 → 2.0.3-beta.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.
- package/dist/accounts.d.ts +135 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +209 -0
- package/dist/accounts.js.map +1 -0
- package/dist/api/bluebubbles-routes.d.ts +10 -0
- package/dist/api/bluebubbles-routes.d.ts.map +1 -0
- package/dist/api/bluebubbles-routes.js +132 -0
- package/dist/api/bluebubbles-routes.js.map +1 -0
- package/dist/api/imessage-routes.d.ts +68 -0
- package/dist/api/imessage-routes.d.ts.map +1 -0
- package/dist/api/imessage-routes.js +228 -0
- package/dist/api/imessage-routes.js.map +1 -0
- package/dist/chatdb-reader.d.ts +240 -0
- package/dist/chatdb-reader.d.ts.map +1 -0
- package/dist/chatdb-reader.js +667 -0
- package/dist/chatdb-reader.js.map +1 -0
- package/dist/config.d.ts +60 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -0
- package/dist/connector-account-provider.d.ts +18 -0
- package/dist/connector-account-provider.d.ts.map +1 -0
- package/dist/connector-account-provider.js +83 -0
- package/dist/connector-account-provider.js.map +1 -0
- package/dist/contacts-reader.d.ts +141 -0
- package/dist/contacts-reader.d.ts.map +1 -0
- package/dist/contacts-reader.js +359 -0
- package/dist/contacts-reader.js.map +1 -0
- package/dist/data-routes.d.ts +21 -0
- package/dist/data-routes.d.ts.map +1 -0
- package/dist/data-routes.js +280 -0
- package/dist/data-routes.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +5 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/rpc.d.ts +206 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +393 -0
- package/dist/rpc.js.map +1 -0
- package/dist/service.d.ts +264 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +1705 -0
- package/dist/service.js.map +1 -0
- package/dist/setup-routes.d.ts +26 -0
- package/dist/setup-routes.d.ts.map +1 -0
- package/dist/setup-routes.js +139 -0
- package/dist/setup-routes.js.map +1 -0
- package/dist/types.d.ts +192 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +138 -0
- package/dist/types.js.map +1 -0
- package/package.json +4 -3
- package/registry-entry.json +103 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
2
|
+
/**
|
|
3
|
+
* Default account identifier used when no specific account is configured
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_ACCOUNT_ID = "default";
|
|
6
|
+
/**
|
|
7
|
+
* Group-specific configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface IMessageGroupConfig {
|
|
10
|
+
/** If false, ignore messages from this group */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** Allowlist for users in this group */
|
|
13
|
+
allowFrom?: Array<string | number>;
|
|
14
|
+
/** Require bot mention to respond */
|
|
15
|
+
requireMention?: boolean;
|
|
16
|
+
/** Custom system prompt for this group */
|
|
17
|
+
systemPrompt?: string;
|
|
18
|
+
/** Skills enabled for this group */
|
|
19
|
+
skills?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for a single iMessage account
|
|
23
|
+
*/
|
|
24
|
+
export interface IMessageAccountConfig {
|
|
25
|
+
/** Optional display name for this account */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** If false, do not start this iMessage account */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/** Path to the iMessage CLI tool */
|
|
30
|
+
cliPath?: string;
|
|
31
|
+
/** Path to the iMessage database */
|
|
32
|
+
dbPath?: string;
|
|
33
|
+
/** iMessage service type (iMessage or SMS) */
|
|
34
|
+
service?: "iMessage" | "SMS";
|
|
35
|
+
/** Phone number region code */
|
|
36
|
+
region?: string;
|
|
37
|
+
/** Allowlist for DM senders */
|
|
38
|
+
allowFrom?: Array<string | number>;
|
|
39
|
+
/** Allowlist for groups */
|
|
40
|
+
groupAllowFrom?: Array<string | number>;
|
|
41
|
+
/** DM access policy */
|
|
42
|
+
dmPolicy?: "open" | "allowlist" | "pairing" | "disabled";
|
|
43
|
+
/** Group message access policy */
|
|
44
|
+
groupPolicy?: "open" | "allowlist" | "disabled";
|
|
45
|
+
/** Whether to include attachments */
|
|
46
|
+
includeAttachments?: boolean;
|
|
47
|
+
/** Max media size in MB */
|
|
48
|
+
mediaMaxMb?: number;
|
|
49
|
+
/** Text chunk limit for messages */
|
|
50
|
+
textChunkLimit?: number;
|
|
51
|
+
/** Group-specific configurations */
|
|
52
|
+
groups?: Record<string, IMessageGroupConfig>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Multi-account iMessage configuration structure
|
|
56
|
+
*/
|
|
57
|
+
export interface IMessageMultiAccountConfig {
|
|
58
|
+
/** Default/base configuration applied to all accounts */
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
cliPath?: string;
|
|
61
|
+
dbPath?: string;
|
|
62
|
+
service?: "iMessage" | "SMS";
|
|
63
|
+
region?: string;
|
|
64
|
+
dmPolicy?: "open" | "allowlist" | "pairing" | "disabled";
|
|
65
|
+
groupPolicy?: "open" | "allowlist" | "disabled";
|
|
66
|
+
includeAttachments?: boolean;
|
|
67
|
+
mediaMaxMb?: number;
|
|
68
|
+
textChunkLimit?: number;
|
|
69
|
+
/** Per-account configuration overrides */
|
|
70
|
+
accounts?: Record<string, IMessageAccountConfig>;
|
|
71
|
+
/** Group configurations at base level */
|
|
72
|
+
groups?: Record<string, IMessageGroupConfig>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolved iMessage account with all configuration merged
|
|
76
|
+
*/
|
|
77
|
+
export interface ResolvedIMessageAccount {
|
|
78
|
+
accountId: string;
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
name?: string;
|
|
81
|
+
cliPath: string;
|
|
82
|
+
dbPath?: string;
|
|
83
|
+
configured: boolean;
|
|
84
|
+
config: IMessageAccountConfig;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Normalizes an account ID, returning the default if not provided
|
|
88
|
+
*/
|
|
89
|
+
export declare function normalizeAccountId(accountId?: string | null): string;
|
|
90
|
+
/**
|
|
91
|
+
* Gets the account inventory configuration from runtime settings
|
|
92
|
+
*/
|
|
93
|
+
export declare function getMultiAccountConfig(runtime: IAgentRuntime): IMessageMultiAccountConfig;
|
|
94
|
+
/**
|
|
95
|
+
* Lists all configured account IDs
|
|
96
|
+
*/
|
|
97
|
+
export declare function listIMessageAccountIds(runtime: IAgentRuntime): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Resolves the default account ID to use
|
|
100
|
+
*/
|
|
101
|
+
export declare function resolveDefaultIMessageAccountId(runtime: IAgentRuntime): string;
|
|
102
|
+
/**
|
|
103
|
+
* Resolves a complete iMessage account configuration
|
|
104
|
+
*/
|
|
105
|
+
export declare function resolveIMessageAccount(runtime: IAgentRuntime, accountId?: string | null): ResolvedIMessageAccount;
|
|
106
|
+
/**
|
|
107
|
+
* Lists all enabled iMessage accounts
|
|
108
|
+
*/
|
|
109
|
+
export declare function listEnabledIMessageAccounts(runtime: IAgentRuntime): ResolvedIMessageAccount[];
|
|
110
|
+
/**
|
|
111
|
+
* Checks whether more than one enabled account record is configured
|
|
112
|
+
*/
|
|
113
|
+
export declare function isMultiAccountEnabled(runtime: IAgentRuntime): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Resolves group configuration for a specific group
|
|
116
|
+
*/
|
|
117
|
+
export declare function resolveIMessageGroupConfig(runtime: IAgentRuntime, accountId: string, groupId: string): IMessageGroupConfig | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a user is allowed based on policy and allowlist
|
|
120
|
+
*/
|
|
121
|
+
export declare function isIMessageUserAllowed(params: {
|
|
122
|
+
identifier: string;
|
|
123
|
+
accountConfig: IMessageAccountConfig;
|
|
124
|
+
isGroup: boolean;
|
|
125
|
+
groupId?: string;
|
|
126
|
+
groupConfig?: IMessageGroupConfig;
|
|
127
|
+
}): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Checks if mention is required in a group
|
|
130
|
+
*/
|
|
131
|
+
export declare function isIMessageMentionRequired(params: {
|
|
132
|
+
accountConfig: IMessageAccountConfig;
|
|
133
|
+
groupConfig?: IMessageGroupConfig;
|
|
134
|
+
}): boolean;
|
|
135
|
+
//# 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;AAEnD;;GAEG;AACH,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wCAAwC;IACxC,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACnC,qCAAqC;IACrC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,OAAO,CAAC,EAAE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rC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CA8CV;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,aAAa,EAAE,qBAAqB,CAAC;IACrC,WAAW,CAAC,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CAGV"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default account identifier used when no specific account is configured
|
|
3
|
+
*/
|
|
4
|
+
export const DEFAULT_ACCOUNT_ID = "default";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes an account ID, returning the default if not provided
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeAccountId(accountId) {
|
|
9
|
+
if (!accountId || typeof accountId !== "string") {
|
|
10
|
+
return DEFAULT_ACCOUNT_ID;
|
|
11
|
+
}
|
|
12
|
+
const trimmed = accountId.trim().toLowerCase();
|
|
13
|
+
if (!trimmed || trimmed === "default") {
|
|
14
|
+
return DEFAULT_ACCOUNT_ID;
|
|
15
|
+
}
|
|
16
|
+
return trimmed;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Gets the account inventory configuration from runtime settings
|
|
20
|
+
*/
|
|
21
|
+
export function getMultiAccountConfig(runtime) {
|
|
22
|
+
const characterIMessage = runtime.character.settings?.imessage;
|
|
23
|
+
return {
|
|
24
|
+
enabled: characterIMessage?.enabled,
|
|
25
|
+
cliPath: characterIMessage?.cliPath,
|
|
26
|
+
dbPath: characterIMessage?.dbPath,
|
|
27
|
+
service: characterIMessage?.service,
|
|
28
|
+
region: characterIMessage?.region,
|
|
29
|
+
dmPolicy: characterIMessage?.dmPolicy,
|
|
30
|
+
groupPolicy: characterIMessage?.groupPolicy,
|
|
31
|
+
includeAttachments: characterIMessage?.includeAttachments,
|
|
32
|
+
mediaMaxMb: characterIMessage?.mediaMaxMb,
|
|
33
|
+
textChunkLimit: characterIMessage?.textChunkLimit,
|
|
34
|
+
accounts: characterIMessage?.accounts,
|
|
35
|
+
groups: characterIMessage?.groups,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Lists all configured account IDs
|
|
40
|
+
*/
|
|
41
|
+
export function listIMessageAccountIds(runtime) {
|
|
42
|
+
const config = getMultiAccountConfig(runtime);
|
|
43
|
+
const accounts = config.accounts;
|
|
44
|
+
if (!accounts || typeof accounts !== "object") {
|
|
45
|
+
return [DEFAULT_ACCOUNT_ID];
|
|
46
|
+
}
|
|
47
|
+
const ids = Object.keys(accounts).filter(Boolean);
|
|
48
|
+
if (ids.length === 0) {
|
|
49
|
+
return [DEFAULT_ACCOUNT_ID];
|
|
50
|
+
}
|
|
51
|
+
return ids.slice().sort((a, b) => a.localeCompare(b));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the default account ID to use
|
|
55
|
+
*/
|
|
56
|
+
export function resolveDefaultIMessageAccountId(runtime) {
|
|
57
|
+
const ids = listIMessageAccountIds(runtime);
|
|
58
|
+
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
59
|
+
return DEFAULT_ACCOUNT_ID;
|
|
60
|
+
}
|
|
61
|
+
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the account-specific configuration
|
|
65
|
+
*/
|
|
66
|
+
function getAccountConfig(runtime, accountId) {
|
|
67
|
+
const config = getMultiAccountConfig(runtime);
|
|
68
|
+
const accounts = config.accounts;
|
|
69
|
+
if (!accounts || typeof accounts !== "object") {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
return accounts[accountId];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Merges base configuration with account-specific overrides
|
|
76
|
+
*/
|
|
77
|
+
function mergeIMessageAccountConfig(runtime, accountId) {
|
|
78
|
+
const multiConfig = getMultiAccountConfig(runtime);
|
|
79
|
+
const { accounts: _ignored, ...baseConfig } = multiConfig;
|
|
80
|
+
const accountConfig = getAccountConfig(runtime, accountId) ?? {};
|
|
81
|
+
// Get environment/runtime settings for the base config
|
|
82
|
+
const envCliPath = runtime.getSetting("IMESSAGE_CLI_PATH");
|
|
83
|
+
const envDbPath = runtime.getSetting("IMESSAGE_DB_PATH");
|
|
84
|
+
const envDmPolicy = runtime.getSetting("IMESSAGE_DM_POLICY");
|
|
85
|
+
const envGroupPolicy = runtime.getSetting("IMESSAGE_GROUP_POLICY");
|
|
86
|
+
const envConfig = {
|
|
87
|
+
cliPath: envCliPath || undefined,
|
|
88
|
+
dbPath: envDbPath || undefined,
|
|
89
|
+
dmPolicy: envDmPolicy,
|
|
90
|
+
groupPolicy: envGroupPolicy,
|
|
91
|
+
};
|
|
92
|
+
// Merge order: env defaults < base config < account config
|
|
93
|
+
return {
|
|
94
|
+
...envConfig,
|
|
95
|
+
...baseConfig,
|
|
96
|
+
...accountConfig,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolves a complete iMessage account configuration
|
|
101
|
+
*/
|
|
102
|
+
export function resolveIMessageAccount(runtime, accountId) {
|
|
103
|
+
const normalizedAccountId = normalizeAccountId(accountId);
|
|
104
|
+
const multiConfig = getMultiAccountConfig(runtime);
|
|
105
|
+
const baseEnabled = multiConfig.enabled !== false;
|
|
106
|
+
const merged = mergeIMessageAccountConfig(runtime, normalizedAccountId);
|
|
107
|
+
const accountEnabled = merged.enabled !== false;
|
|
108
|
+
const enabled = baseEnabled && accountEnabled;
|
|
109
|
+
const cliPath = merged.cliPath?.trim() || "imsg";
|
|
110
|
+
// Determine if this account is actually configured
|
|
111
|
+
const configured = Boolean(merged.cliPath?.trim() ||
|
|
112
|
+
merged.dbPath?.trim() ||
|
|
113
|
+
merged.service ||
|
|
114
|
+
merged.region?.trim() ||
|
|
115
|
+
(merged.allowFrom && merged.allowFrom.length > 0) ||
|
|
116
|
+
(merged.groupAllowFrom && merged.groupAllowFrom.length > 0) ||
|
|
117
|
+
merged.dmPolicy ||
|
|
118
|
+
merged.groupPolicy ||
|
|
119
|
+
typeof merged.includeAttachments === "boolean" ||
|
|
120
|
+
typeof merged.mediaMaxMb === "number" ||
|
|
121
|
+
typeof merged.textChunkLimit === "number" ||
|
|
122
|
+
(merged.groups && Object.keys(merged.groups).length > 0));
|
|
123
|
+
return {
|
|
124
|
+
accountId: normalizedAccountId,
|
|
125
|
+
enabled,
|
|
126
|
+
name: merged.name?.trim() || undefined,
|
|
127
|
+
cliPath,
|
|
128
|
+
dbPath: merged.dbPath?.trim() || undefined,
|
|
129
|
+
configured,
|
|
130
|
+
config: merged,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Lists all enabled iMessage accounts
|
|
135
|
+
*/
|
|
136
|
+
export function listEnabledIMessageAccounts(runtime) {
|
|
137
|
+
return listIMessageAccountIds(runtime)
|
|
138
|
+
.map((accountId) => resolveIMessageAccount(runtime, accountId))
|
|
139
|
+
.filter((account) => account.enabled);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks whether more than one enabled account record is configured
|
|
143
|
+
*/
|
|
144
|
+
export function isMultiAccountEnabled(runtime) {
|
|
145
|
+
const accounts = listEnabledIMessageAccounts(runtime);
|
|
146
|
+
return accounts.length > 1;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Resolves group configuration for a specific group
|
|
150
|
+
*/
|
|
151
|
+
export function resolveIMessageGroupConfig(runtime, accountId, groupId) {
|
|
152
|
+
const multiConfig = getMultiAccountConfig(runtime);
|
|
153
|
+
const accountConfig = getAccountConfig(runtime, accountId);
|
|
154
|
+
// Check account-level groups first
|
|
155
|
+
const accountGroup = accountConfig?.groups?.[groupId];
|
|
156
|
+
if (accountGroup) {
|
|
157
|
+
return accountGroup;
|
|
158
|
+
}
|
|
159
|
+
// Fall back to base-level groups
|
|
160
|
+
return multiConfig.groups?.[groupId];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a user is allowed based on policy and allowlist
|
|
164
|
+
*/
|
|
165
|
+
export function isIMessageUserAllowed(params) {
|
|
166
|
+
const { identifier, accountConfig, isGroup, groupConfig } = params;
|
|
167
|
+
if (isGroup) {
|
|
168
|
+
const policy = accountConfig.groupPolicy ?? "allowlist";
|
|
169
|
+
if (policy === "disabled") {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
if (policy === "open") {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
// Check group-specific allowlist first
|
|
176
|
+
if (groupConfig?.allowFrom?.length) {
|
|
177
|
+
return groupConfig.allowFrom.some((allowed) => String(allowed) === identifier);
|
|
178
|
+
}
|
|
179
|
+
// Check account-level group allowlist
|
|
180
|
+
if (accountConfig.groupAllowFrom?.length) {
|
|
181
|
+
return accountConfig.groupAllowFrom.some((allowed) => String(allowed) === identifier);
|
|
182
|
+
}
|
|
183
|
+
return policy !== "allowlist";
|
|
184
|
+
}
|
|
185
|
+
// DM handling
|
|
186
|
+
const policy = accountConfig.dmPolicy ?? "pairing";
|
|
187
|
+
if (policy === "disabled") {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (policy === "open") {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (policy === "pairing") {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
// Allowlist policy
|
|
197
|
+
if (accountConfig.allowFrom?.length) {
|
|
198
|
+
return accountConfig.allowFrom.some((allowed) => String(allowed) === identifier);
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Checks if mention is required in a group
|
|
204
|
+
*/
|
|
205
|
+
export function isIMessageMentionRequired(params) {
|
|
206
|
+
const { groupConfig } = params;
|
|
207
|
+
return groupConfig?.requireMention ?? false;
|
|
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AC,KAAK,UAAU,CAAC,CAAC;QACjF,CAAC;QAED,sCAAsC;QACtC,IAAI,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;YACzC,OAAO,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC;QACxF,CAAC;QAED,OAAO,MAAM,KAAK,WAAW,CAAC;IAChC,CAAC;IAED,cAAc;IACd,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,IAAI,SAAS,CAAC;IACnD,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mBAAmB;IACnB,IAAI,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QACpC,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAGzC;IACC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAC/B,OAAO,WAAW,EAAE,cAAc,IAAI,KAAK,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type http from "node:http";
|
|
2
|
+
import type { RouteHelpers } from "@elizaos/core";
|
|
3
|
+
export interface BlueBubblesRouteState {
|
|
4
|
+
runtime?: {
|
|
5
|
+
getService(type: string): unknown;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveBlueBubblesWebhookPath(state: BlueBubblesRouteState): string;
|
|
9
|
+
export declare function handleBlueBubblesRoute(req: http.IncomingMessage, res: http.ServerResponse, pathname: string, method: string, state: BlueBubblesRouteState, helpers: RouteHelpers): Promise<boolean>;
|
|
10
|
+
//# sourceMappingURL=bluebubbles-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bluebubbles-routes.d.ts","sourceRoot":"","sources":["../../src/api/bluebubbles-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA0BlD,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;KACnC,CAAC;CACH;AAUD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAOlF;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,qBAAqB,EAC5B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,OAAO,CAAC,CAkJlB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const BLUEBUBBLES_SERVICE_NAME = "bluebubbles";
|
|
2
|
+
const DEFAULT_WEBHOOK_PATH = "/webhooks/bluebubbles";
|
|
3
|
+
const MAX_BODY_BYTES = 1_048_576;
|
|
4
|
+
function resolveService(state) {
|
|
5
|
+
if (!state.runtime) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const raw = state.runtime.getService(BLUEBUBBLES_SERVICE_NAME);
|
|
9
|
+
return raw ?? null;
|
|
10
|
+
}
|
|
11
|
+
export function resolveBlueBubblesWebhookPath(state) {
|
|
12
|
+
const service = resolveService(state);
|
|
13
|
+
const configuredPath = service?.getWebhookPath();
|
|
14
|
+
if (typeof configuredPath === "string" && configuredPath.trim().length > 0) {
|
|
15
|
+
return configuredPath.trim();
|
|
16
|
+
}
|
|
17
|
+
return DEFAULT_WEBHOOK_PATH;
|
|
18
|
+
}
|
|
19
|
+
export async function handleBlueBubblesRoute(req, res, pathname, method, state, helpers) {
|
|
20
|
+
const webhookPath = resolveBlueBubblesWebhookPath(state);
|
|
21
|
+
const isWebhookPath = pathname === webhookPath;
|
|
22
|
+
const isApiPath = pathname.startsWith("/api/bluebubbles");
|
|
23
|
+
if (!isWebhookPath && !isApiPath) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (method === "GET" && pathname === "/api/bluebubbles/status") {
|
|
27
|
+
const service = resolveService(state);
|
|
28
|
+
if (!service) {
|
|
29
|
+
helpers.json(res, {
|
|
30
|
+
available: false,
|
|
31
|
+
connected: false,
|
|
32
|
+
webhookPath,
|
|
33
|
+
reason: "bluebubbles service not registered",
|
|
34
|
+
});
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
helpers.json(res, {
|
|
38
|
+
available: true,
|
|
39
|
+
connected: service.isConnected(),
|
|
40
|
+
webhookPath,
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (method === "GET" && pathname === "/api/bluebubbles/chats") {
|
|
45
|
+
const service = resolveService(state);
|
|
46
|
+
if (!service) {
|
|
47
|
+
helpers.error(res, "bluebubbles service not registered", 503);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const client = service.getClient();
|
|
51
|
+
if (!client) {
|
|
52
|
+
helpers.error(res, "bluebubbles client not available", 503);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const url = new URL(req.url ?? pathname, "http://localhost");
|
|
56
|
+
const limit = Math.min(Math.max(1, Number.parseInt(url.searchParams.get("limit") ?? "100", 10) || 100), 500);
|
|
57
|
+
const offset = Math.max(0, Number.parseInt(url.searchParams.get("offset") ?? "0", 10) || 0);
|
|
58
|
+
try {
|
|
59
|
+
const chats = await client.listChats(limit, offset);
|
|
60
|
+
helpers.json(res, { chats, count: chats.length, limit, offset });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
helpers.error(res, `failed to read bluebubbles chats: ${error instanceof Error ? error.message : String(error)}`, 500);
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (method === "GET" && pathname === "/api/bluebubbles/messages") {
|
|
68
|
+
const service = resolveService(state);
|
|
69
|
+
if (!service) {
|
|
70
|
+
helpers.error(res, "bluebubbles service not registered", 503);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const client = service.getClient();
|
|
74
|
+
if (!client) {
|
|
75
|
+
helpers.error(res, "bluebubbles client not available", 503);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
const url = new URL(req.url ?? pathname, "http://localhost");
|
|
79
|
+
const chatGuid = (url.searchParams.get("chatGuid") ?? "").trim();
|
|
80
|
+
if (!chatGuid) {
|
|
81
|
+
helpers.error(res, "chatGuid query parameter is required", 400);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const limit = Math.min(Math.max(1, Number.parseInt(url.searchParams.get("limit") ?? "50", 10) || 50), 500);
|
|
85
|
+
const offset = Math.max(0, Number.parseInt(url.searchParams.get("offset") ?? "0", 10) || 0);
|
|
86
|
+
try {
|
|
87
|
+
const messages = await client.getMessages(chatGuid, limit, offset);
|
|
88
|
+
helpers.json(res, {
|
|
89
|
+
chatGuid,
|
|
90
|
+
messages,
|
|
91
|
+
count: messages.length,
|
|
92
|
+
limit,
|
|
93
|
+
offset,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
helpers.error(res, `failed to read bluebubbles messages: ${error instanceof Error ? error.message : String(error)}`, 500);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (method === "POST" && isWebhookPath) {
|
|
102
|
+
const service = resolveService(state);
|
|
103
|
+
if (!service) {
|
|
104
|
+
helpers.error(res, "bluebubbles service not registered", 503);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
const payload = await helpers.readJsonBody(req, res, {
|
|
108
|
+
maxBytes: MAX_BODY_BYTES,
|
|
109
|
+
});
|
|
110
|
+
if (!payload) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (typeof payload.type !== "string" ||
|
|
114
|
+
!payload.type.trim() ||
|
|
115
|
+
typeof payload.data !== "object" ||
|
|
116
|
+
payload.data === null ||
|
|
117
|
+
Array.isArray(payload.data)) {
|
|
118
|
+
helpers.error(res, "invalid BlueBubbles webhook payload", 400);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await service.handleWebhook(payload);
|
|
123
|
+
helpers.json(res, { ok: true });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
helpers.error(res, `failed to handle bluebubbles webhook: ${error instanceof Error ? error.message : String(error)}`, 500);
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=bluebubbles-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bluebubbles-routes.js","sourceRoot":"","sources":["../../src/api/bluebubbles-routes.ts"],"names":[],"mappings":"AAGA,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAC/C,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AACrD,MAAM,cAAc,GAAG,SAAS,CAAC;AA4BjC,SAAS,cAAc,CAAC,KAA4B;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAA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,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IACE,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;YAChC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;YACpB,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;YAChC,OAAO,CAAC,IAAI,KAAK,IAAI;YACrB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAC3B,CAAC;YACD,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,qCAAqC,EAAE,GAAG,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,GAAG,EACH,yCAAyC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACjG,GAAG,CACJ,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* iMessage connector HTTP routes.
|
|
3
|
+
*
|
|
4
|
+
* Exposes the @elizaos/plugin-imessage service state through Eliza's
|
|
5
|
+
* HTTP API so downstream UI layers (the dashboard, a future CLI, third-
|
|
6
|
+
* party integrations) can read and write against the macOS Messages.app
|
|
7
|
+
* world without each client having to go straight to chat.db or native
|
|
8
|
+
* macOS bridges.
|
|
9
|
+
*
|
|
10
|
+
* Routes served (all under `/api/imessage`):
|
|
11
|
+
*
|
|
12
|
+
* GET /api/imessage/status service health + cursor + counts
|
|
13
|
+
* GET /api/imessage/messages recent messages from chat.db
|
|
14
|
+
* GET /api/imessage/chats list of chats (DMs + groups)
|
|
15
|
+
* GET /api/imessage/contacts every contact with full detail
|
|
16
|
+
* POST /api/imessage/contacts create a new contact
|
|
17
|
+
* PATCH /api/imessage/contacts/:id update an existing contact
|
|
18
|
+
* DELETE /api/imessage/contacts/:id delete a contact
|
|
19
|
+
*
|
|
20
|
+
* Each handler pulls the IMessageService instance off the runtime via
|
|
21
|
+
* `runtime.getService("imessage")` and calls the public methods added
|
|
22
|
+
* in the plugin's patched branch. If the service isn't registered (the
|
|
23
|
+
* plugin isn't enabled, Eliza booted before it was loaded, etc.) we
|
|
24
|
+
* return 503 with a structured reason so the UI can render an
|
|
25
|
+
* informative empty state.
|
|
26
|
+
*
|
|
27
|
+
* Write endpoints (POST/PATCH/DELETE on contacts) touch the real macOS
|
|
28
|
+
* Contacts store through CNContactStore and require the Contacts privacy
|
|
29
|
+
* grant. Once granted, the permission is persistent across restarts.
|
|
30
|
+
*/
|
|
31
|
+
import type http from "node:http";
|
|
32
|
+
import type { RouteHelpers } from "@elizaos/core";
|
|
33
|
+
/**
|
|
34
|
+
* Route helper options accepted by the host. This plugin depends on core, not
|
|
35
|
+
* the agent package, so the route file stays usable without importing agent
|
|
36
|
+
* internals.
|
|
37
|
+
*/
|
|
38
|
+
export interface ReadJsonBodyOptions {
|
|
39
|
+
maxBytes?: number;
|
|
40
|
+
requireObject?: boolean;
|
|
41
|
+
readErrorStatus?: number;
|
|
42
|
+
nonObjectStatus?: number;
|
|
43
|
+
parseErrorStatus?: number;
|
|
44
|
+
readErrorMessage?: string;
|
|
45
|
+
nonObjectMessage?: string;
|
|
46
|
+
parseErrorMessage?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface IMessageRouteState {
|
|
49
|
+
/**
|
|
50
|
+
* The running AgentRuntime (or a test runtime). Typed loosely as
|
|
51
|
+
* `unknown` so this route file doesn't re-declare core's stricter
|
|
52
|
+
* generic getService signature — we narrow the result inside
|
|
53
|
+
* resolveService via an unknown cast. Optional so route files
|
|
54
|
+
* tolerate the boot window where the runtime hasn't finished
|
|
55
|
+
* registering services yet.
|
|
56
|
+
*/
|
|
57
|
+
runtime?: {
|
|
58
|
+
getService(type: string): unknown;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Route handler entry point. Returns `true` when a route matched and
|
|
63
|
+
* the response has been written; returns `false` so the caller can
|
|
64
|
+
* continue to other route handlers (mirrors the handleWhatsAppRoute /
|
|
65
|
+
* handleWalletRoute pattern used elsewhere in this codebase).
|
|
66
|
+
*/
|
|
67
|
+
export declare function handleIMessageRoute(req: http.IncomingMessage, res: http.ServerResponse, pathname: string, method: string, state: IMessageRouteState, helpers: RouteHelpers): Promise<boolean>;
|
|
68
|
+
//# sourceMappingURL=imessage-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imessage-routes.d.ts","sourceRoot":"","sources":["../../src/api/imessage-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAEpE;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AA2ED,MAAM,WAAW,kBAAkB;IACjC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;KACnC,CAAC;CACH;AAyBD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,OAAO,CAAC,CA0NlB"}
|