@elizaos/plugin-imessage 2.0.0-alpha.9 → 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.
Files changed (59) hide show
  1. package/README.md +184 -0
  2. package/auto-enable.ts +21 -0
  3. package/dist/api/bluebubbles-routes.d.ts +10 -0
  4. package/dist/api/bluebubbles-routes.d.ts.map +1 -0
  5. package/dist/api/bluebubbles-routes.js +132 -0
  6. package/dist/api/bluebubbles-routes.js.map +1 -0
  7. package/dist/api/imessage-routes.d.ts +80 -0
  8. package/dist/api/imessage-routes.d.ts.map +1 -0
  9. package/dist/api/imessage-routes.js +230 -0
  10. package/dist/api/imessage-routes.js.map +1 -0
  11. package/dist/chatdb-reader.d.ts +240 -0
  12. package/dist/chatdb-reader.d.ts.map +1 -0
  13. package/dist/chatdb-reader.js +647 -0
  14. package/dist/chatdb-reader.js.map +1 -0
  15. package/dist/connector-account-provider.d.ts +18 -0
  16. package/dist/connector-account-provider.d.ts.map +1 -0
  17. package/dist/connector-account-provider.js +83 -0
  18. package/dist/connector-account-provider.js.map +1 -0
  19. package/dist/contacts-reader.d.ts +147 -0
  20. package/dist/contacts-reader.d.ts.map +1 -0
  21. package/dist/contacts-reader.js +481 -0
  22. package/dist/contacts-reader.js.map +1 -0
  23. package/dist/index.d.ts +11 -11
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +48 -16
  26. package/dist/index.js.map +1 -1
  27. package/dist/providers/index.d.ts +1 -2
  28. package/dist/providers/index.d.ts.map +1 -1
  29. package/dist/providers/index.js +2 -2
  30. package/dist/providers/index.js.map +1 -1
  31. package/dist/rpc.d.ts +16 -4
  32. package/dist/rpc.d.ts.map +1 -1
  33. package/dist/rpc.js +103 -11
  34. package/dist/rpc.js.map +1 -1
  35. package/dist/service.d.ts +203 -8
  36. package/dist/service.d.ts.map +1 -1
  37. package/dist/service.js +1368 -107
  38. package/dist/service.js.map +1 -1
  39. package/dist/setup-routes.d.ts +38 -0
  40. package/dist/setup-routes.d.ts.map +1 -0
  41. package/dist/setup-routes.js +322 -0
  42. package/dist/setup-routes.js.map +1 -0
  43. package/dist/types.d.ts +29 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js +2 -0
  46. package/dist/types.js.map +1 -1
  47. package/package.json +19 -10
  48. package/dist/actions/index.d.ts +0 -5
  49. package/dist/actions/index.d.ts.map +0 -1
  50. package/dist/actions/index.js +0 -5
  51. package/dist/actions/index.js.map +0 -1
  52. package/dist/actions/sendMessage.d.ts +0 -6
  53. package/dist/actions/sendMessage.d.ts.map +0 -1
  54. package/dist/actions/sendMessage.js +0 -178
  55. package/dist/actions/sendMessage.js.map +0 -1
  56. package/dist/providers/chatContext.d.ts +0 -6
  57. package/dist/providers/chatContext.d.ts.map +0 -1
  58. package/dist/providers/chatContext.js +0 -60
  59. package/dist/providers/chatContext.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imessage-routes.js","sourceRoot":"","sources":["../../src/api/imessage-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA4HH,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,gDAAgD;AAEnF,SAAS,cAAc,CAAC,KAAyB;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAC5D,OAAQ,GAA8C,IAAI,IAAI,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,MAAM,GAAG,yBAAyB,CAAC;IACzC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ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,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,GAAG,EACH,wBAAwB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChF,GAAG,CACJ,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,KAAK,IAAI,CAAC,CAAC,sCAAsC;IACjD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,240 @@
1
+ /**
2
+ * macOS chat.db reader for @elizaos/plugin-imessage.
3
+ *
4
+ * iMessage stores every message in a SQLite database at
5
+ * `~/Library/Messages/chat.db`. Reading it requires Full Disk Access on
6
+ * whichever process hosts the plugin (the Eliza agent, typically). This
7
+ * module opens that file read-only and exposes a single `fetchNewMessages`
8
+ * method the polling loop uses to walk forward by ROWID.
9
+ *
10
+ * ---
11
+ *
12
+ * Backend: runtime SQLite built-ins. Bun exposes `bun:sqlite`; Node 22+
13
+ * exposes `node:sqlite`. We normalize both to the small query surface this
14
+ * module needs so live chat.db reads keep working in test runners and under
15
+ * either runtime.
16
+ *
17
+ * Prior to this module, the plugin attempted to read messages by running
18
+ * AppleScript against Messages.app's `get messages` verb — a verb that
19
+ * does not exist in Messages.app's scripting dictionary. That code path
20
+ * silently returned an empty list on every poll, so inbound messages
21
+ * never reached the agent.
22
+ */
23
+ import type { IMessagePermissionAction } from "./types.js";
24
+ /**
25
+ * Default path to macOS's iMessage database. Requires Full Disk Access
26
+ * on whichever process opens it.
27
+ */
28
+ export declare const DEFAULT_CHAT_DB_PATH: string;
29
+ export declare const MACOS_FULL_DISK_ACCESS_SETTINGS_URL = "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles";
30
+ export interface ChatDbAccessIssue {
31
+ code: "sqlite_unavailable" | "open_failed";
32
+ path: string;
33
+ reason: string;
34
+ permissionAction: IMessagePermissionAction | null;
35
+ }
36
+ export declare function createFullDiskAccessAction(): IMessagePermissionAction;
37
+ /**
38
+ * Convert an Apple Cocoa date delta to JavaScript milliseconds since
39
+ * epoch. Handles both legacy (seconds) and modern (nanoseconds) storage.
40
+ */
41
+ export declare function appleDateToJsMs(appleDate: number): number;
42
+ /**
43
+ * Extract the plain UTF-8 text from an `attributedBody` BLOB.
44
+ *
45
+ * Modern macOS (~10.13+) stores message text as an `NSMutableAttributedString`
46
+ * serialised via Apple's legacy `typedstream` / NSArchiver format, because
47
+ * Messages.app wants to attach attributes (links, mentions, formatting)
48
+ * that plain text can't carry. Empirically, on a fresh macOS chat.db,
49
+ * ~97% of message rows have `text=NULL` and their actual readable content
50
+ * only exists in `attributedBody`. Reading chat.db without decoding this
51
+ * blob means being blind to almost every real message.
52
+ *
53
+ * Full typedstream parsing is complex (class inheritance chains, object
54
+ * references, multiple string encodings) and worth ~500 lines of code.
55
+ * The good news: Messages.app uses a narrow, stable subset for its own
56
+ * message text, and the text always appears after the same marker
57
+ * sequence: `NSString\x00\x01\x94\x84\x01\x2b` (class name, object flags,
58
+ * then `+` which is typedstream's "cstring" verb), followed by a length
59
+ * byte, followed by the UTF-8 bytes. For strings longer than 254 bytes
60
+ * typedstream escapes the length with `0x81` followed by a little-endian
61
+ * uint16 length, then the bytes. Everything else we don't care about.
62
+ *
63
+ * Verified against real blobs from a live chat.db — hit rate is ~100% on
64
+ * the messages checked, including short replies like "Yo" and longer
65
+ * messages with emoji. Returns null if no marker is found, which the
66
+ * caller uses as a signal to fall back to the raw `text` column or
67
+ * skip the row.
68
+ *
69
+ * References:
70
+ * - Apple's typedstream format: see darling-gnustep-base, GSTypedStream.m
71
+ * - imessage-exporter's Rust implementation (MIT) for the full parser
72
+ * - NSAttributedString serialisation in Cocoa Foundation
73
+ */
74
+ export declare function decodeAttributedBody(blob: Uint8Array | Buffer | null | undefined): string | null;
75
+ /** A single attachment attached to a message. */
76
+ export interface ChatDbAttachment {
77
+ /** chat.db `attachment.guid`. */
78
+ guid: string;
79
+ /** Filename as stored, if known. */
80
+ filename: string | null;
81
+ /** Apple UTI (e.g. `public.jpeg`, `com.apple.quicktime-movie`). */
82
+ uti: string | null;
83
+ /** Best-available MIME type (may be null for some UTIs). */
84
+ mimeType: string | null;
85
+ /** Total size in bytes. */
86
+ totalBytes: number | null;
87
+ /** True when the attachment is a Messages sticker. */
88
+ isSticker: boolean;
89
+ }
90
+ /**
91
+ * A reaction / tapback signal. iMessage stores reactions as their own
92
+ * `message` rows with a non-zero `associated_message_type` and an
93
+ * `associated_message_guid` pointing at the original message.
94
+ *
95
+ * Type codes (empirically from chat.db):
96
+ * 2000 = love, 2001 = like, 2002 = dislike, 2003 = laugh,
97
+ * 2004 = emphasis, 2005 = question, 2006 = sticker-reply.
98
+ * 3000+ = the matching "remove" for each.
99
+ */
100
+ export interface ChatDbReaction {
101
+ kind: "love" | "like" | "dislike" | "laugh" | "emphasis" | "question" | "sticker" | "unknown";
102
+ /** Whether this is an add (+) or remove (-) tapback. */
103
+ add: boolean;
104
+ /** Raw numeric type for callers that want the full taxonomy. */
105
+ rawType: number;
106
+ /** GUID of the message being reacted to. */
107
+ targetGuid: string;
108
+ /** Genmoji / custom emoji when the reaction is a sticker-like reaction. */
109
+ emoji: string | null;
110
+ }
111
+ /**
112
+ * A normalized iMessage, ready to be turned into an agent Memory. Unlike
113
+ * the first version of this reader, rows whose `text` column is NULL are
114
+ * NOT skipped — the reader falls back to decoding the `attributedBody`
115
+ * blob, which covers the ~97% of messages on modern macOS that store
116
+ * their text there. If both paths yield nothing, `text` is an empty
117
+ * string and the row is flagged via `kind`.
118
+ */
119
+ export interface ChatDbMessage {
120
+ /** chat.db `message.ROWID`. Monotonic, used as the polling cursor. */
121
+ rowId: number;
122
+ /** chat.db `message.guid`. Stable across devices, used for deduplication. */
123
+ guid: string;
124
+ /** Plain text of the message. May be the empty string for reactions, system events, or undecodable blobs. */
125
+ text: string;
126
+ /**
127
+ * Classification of the row. Most conversation turns are `"text"`.
128
+ * `"reaction"` rows carry no text — their payload is in `reaction`.
129
+ * `"system"` covers group add/remove/rename events.
130
+ */
131
+ kind: "text" | "reaction" | "system" | "other";
132
+ /** Sender identity: phone number (E.164) or email address. Empty for outbound. */
133
+ handle: string;
134
+ /** `chat.chat_identifier`. Stable room key for 1:1 and group conversations. */
135
+ chatId: string;
136
+ /** Classification derived from `chat.style` (45 = 1:1, 43 = group). */
137
+ chatType: "direct" | "group";
138
+ /** Group name if set by users; always null for 1:1 chats. */
139
+ displayName: string | null;
140
+ /** JavaScript milliseconds since epoch, converted from Apple's Cocoa date. */
141
+ timestamp: number;
142
+ /** True if the message was sent by the local Apple ID (the agent's account). */
143
+ isFromMe: boolean;
144
+ /** Delivery service as reported by Apple: `iMessage`, `SMS`, `RCS`, etc. */
145
+ service: string | null;
146
+ /** Sent flag — reliable for outbound, always 1 for delivered. */
147
+ isSent: boolean;
148
+ /** Delivered flag — Apple confirmed delivery to the recipient's device. */
149
+ isDelivered: boolean;
150
+ /** Read flag — the recipient opened the thread. Only meaningful for outbound. */
151
+ isRead: boolean;
152
+ /** When the recipient read this message, or 0 if unread/never. */
153
+ dateRead: number;
154
+ /** When the message was edited (modern macOS), or 0 if never edited. */
155
+ dateEdited: number;
156
+ /** When the message was unsent/retracted, or 0 if still live. */
157
+ dateRetracted: number;
158
+ /** GUID of the message this one is an inline reply to, if any. */
159
+ replyToGuid: string | null;
160
+ /** Reaction payload when `kind === "reaction"`. */
161
+ reaction: ChatDbReaction | null;
162
+ /** Zero or more attachments bound to this message. */
163
+ attachments: ChatDbAttachment[];
164
+ }
165
+ /**
166
+ * Read-only handle for a live chat.db. Created via {@link openChatDb}.
167
+ * The service owns the lifetime: opens on start, closes on stop.
168
+ */
169
+ /** A single chat (conversation room) as surfaced by `listChats`. */
170
+ export interface ChatDbChatSummary {
171
+ chatId: string;
172
+ chatType: "direct" | "group";
173
+ displayName: string | null;
174
+ serviceName: string | null;
175
+ participants: string[];
176
+ lastReadMessageTimestamp: number;
177
+ }
178
+ export interface ChatDbReader {
179
+ /**
180
+ * Fetch messages with ROWID strictly greater than `sinceRowId`, up to
181
+ * `limit` rows. Rows are returned in ascending ROWID order so the
182
+ * caller can advance its cursor to the last row's `rowId`.
183
+ *
184
+ * Returns an empty array when the database has no new messages or
185
+ * when the reader has been closed.
186
+ */
187
+ fetchNewMessages(sinceRowId: number, limit: number): ChatDbMessage[];
188
+ /**
189
+ * Return the largest `message.ROWID` currently in the database. Used
190
+ * on service start to seed the polling cursor at the tip so a fresh
191
+ * launch does not replay the entire backlog. Returns 0 on empty dbs
192
+ * or if the query fails.
193
+ */
194
+ getLatestRowId(): number;
195
+ /**
196
+ * Return the timestamp of the most recent outbound message authored by the
197
+ * local Apple account, converted to JavaScript epoch milliseconds.
198
+ */
199
+ getLatestOwnMessageTimestamp(): number | null;
200
+ /**
201
+ * Return the newest messages in chronological order, optionally scoped
202
+ * to a single chat identifier. Unlike `fetchNewMessages`, this is for
203
+ * ad-hoc inspection and UI reads rather than cursor-based polling.
204
+ */
205
+ listMessages(options?: {
206
+ chatId?: string;
207
+ limit?: number;
208
+ }): ChatDbMessage[];
209
+ /**
210
+ * List every chat the database knows about, joined with participant
211
+ * handles. Reads from `chat`, `chat_handle_join`, and `handle`. This
212
+ * is the replacement for the old AppleScript-based `getChats` path,
213
+ * which was slower and returned less data.
214
+ */
215
+ listChats(): ChatDbChatSummary[];
216
+ /** Close the underlying SQLite handle. Idempotent. */
217
+ close(): void;
218
+ }
219
+ interface ChatDbDiagnosticsLogger {
220
+ warn(message: string): void;
221
+ debug(message: string): void;
222
+ }
223
+ export interface OpenChatDbOptions {
224
+ diagnosticsLogger?: ChatDbDiagnosticsLogger;
225
+ }
226
+ export declare function getLastChatDbAccessIssue(dbPath?: string): ChatDbAccessIssue | null;
227
+ /**
228
+ * Open macOS chat.db read-only and return a reader bound to it.
229
+ *
230
+ * Returns `null` — and logs a human-readable reason — in every failure
231
+ * mode so the caller can degrade to send-only operation instead of
232
+ * crashing the runtime:
233
+ *
234
+ * - Not running under Bun (bun:sqlite built-in unavailable)
235
+ * - chat.db does not exist at the given path
236
+ * - chat.db exists but cannot be opened (missing Full Disk Access, etc.)
237
+ */
238
+ export declare function openChatDb(dbPath?: string, options?: OpenChatDbOptions): Promise<ChatDbReader | null>;
239
+ export {};
240
+ //# sourceMappingURL=chatdb-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatdb-reader.d.ts","sourceRoot":"","sources":["../src/chatdb-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAoD,CAAC;AAEtF,eAAO,MAAM,mCAAmC,6EAC4B,CAAC;AAE7E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,oBAAoB,GAAG,aAAa,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,wBAAwB,GAAG,IAAI,CAAC;CACnD;AAED,wBAAgB,0BAA0B,IAAI,wBAAwB,CAWrE;AAWD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAsEhG;AAmDD,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,mEAAmE;IACnE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,4DAA4D;IAC5D,QAA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