@elizaos/agent 2.0.0-alpha.340 → 2.0.0-alpha.341
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/package.json +4 -4
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.d.ts +0 -9
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.js +80 -171
- package/plugins/plugin-imessage/typescript/src/index.d.ts +1 -1
- package/plugins/plugin-imessage/typescript/src/index.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/service.d.ts +1 -7
- package/plugins/plugin-imessage/typescript/src/service.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/service.js +11 -18
- package/plugins/plugin-imessage/typescript/src/setup-routes.d.ts +1 -2
- package/plugins/plugin-imessage/typescript/src/setup-routes.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/setup-routes.js +2 -55
- package/plugins/plugin-imessage/typescript/src/types.d.ts +0 -8
- package/plugins/plugin-imessage/typescript/src/types.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/agent",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.341",
|
|
4
4
|
"description": "Standalone elizaOS-based agent and backend server package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -467,7 +467,7 @@
|
|
|
467
467
|
"@elizaos/app-steward": "^0.0.0",
|
|
468
468
|
"@elizaos/app-task-coordinator": "^0.0.0",
|
|
469
469
|
"@elizaos/app-training": "^0.0.1",
|
|
470
|
-
"@elizaos/core": "^2.0.0-alpha.
|
|
470
|
+
"@elizaos/core": "^2.0.0-alpha.341",
|
|
471
471
|
"@elizaos/plugin-agent-orchestrator": "^0.6.2-alpha.0",
|
|
472
472
|
"@elizaos/plugin-browser-bridge": "^0.1.0",
|
|
473
473
|
"@elizaos/plugin-local-embedding": "^2.0.0-alpha.3",
|
|
@@ -476,8 +476,8 @@
|
|
|
476
476
|
"@elizaos/plugin-solana": "^2.0.0-alpha.6",
|
|
477
477
|
"@elizaos/plugin-sql": "^2.0.0-alpha.19",
|
|
478
478
|
"@elizaos/plugin-wechat": "^0.1.0",
|
|
479
|
-
"@elizaos/shared": "^2.0.0-alpha.
|
|
480
|
-
"@elizaos/skills": "^2.0.0-alpha.
|
|
479
|
+
"@elizaos/shared": "^2.0.0-alpha.341",
|
|
480
|
+
"@elizaos/skills": "^2.0.0-alpha.341",
|
|
481
481
|
"@hapi/boom": "^10.0.1",
|
|
482
482
|
"@noble/curves": "^2.0.1",
|
|
483
483
|
"@whiskeysockets/baileys": "7.0.0-rc.9",
|
|
@@ -197,15 +197,6 @@ export interface ChatDbReader {
|
|
|
197
197
|
* local Apple account, converted to JavaScript epoch milliseconds.
|
|
198
198
|
*/
|
|
199
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
200
|
/**
|
|
210
201
|
* List every chat the database knows about, joined with participant
|
|
211
202
|
* handles. Reads from `chat`, `chat_handle_join`, and `handle`. This
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatdb-reader.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/chatdb-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D;;;GAGG;AAC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AW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wBAAwB,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACrE;;;;;OAKG;IACH,cAAc,IAAI,MAAM,CAAC;IACzB;;;OAGG;IACH,4BAA4B,IAAI,MAAM,GAAG,IAAI,CAAC;IAC9C
|
|
1
|
+
{"version":3,"file":"chatdb-reader.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/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,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CAC9B,MAAM,GAAE,MAA6B,GACpC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAqV9B"}
|
|
@@ -380,73 +380,6 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
380
380
|
// Used once on service start to seed the polling cursor.
|
|
381
381
|
const tipStmt = db.query("SELECT MAX(ROWID) AS max_row_id FROM message");
|
|
382
382
|
const latestOwnMessageStmt = db.query("SELECT MAX(date) AS max_apple_date FROM message WHERE is_from_me = 1");
|
|
383
|
-
const recentMessagesStmt = db.query(`
|
|
384
|
-
SELECT
|
|
385
|
-
m.ROWID AS row_id,
|
|
386
|
-
m.guid AS guid,
|
|
387
|
-
m.text AS text,
|
|
388
|
-
m.attributedBody AS attributed_body,
|
|
389
|
-
m.date AS apple_date,
|
|
390
|
-
m.date_read AS apple_date_read,
|
|
391
|
-
m.date_edited AS apple_date_edited,
|
|
392
|
-
m.date_retracted AS apple_date_retracted,
|
|
393
|
-
m.is_from_me AS is_from_me,
|
|
394
|
-
m.is_read AS is_read,
|
|
395
|
-
m.is_sent AS is_sent,
|
|
396
|
-
m.is_delivered AS is_delivered,
|
|
397
|
-
m.item_type AS item_type,
|
|
398
|
-
m.reply_to_guid AS reply_to_guid,
|
|
399
|
-
m.associated_message_guid AS associated_message_guid,
|
|
400
|
-
m.associated_message_type AS associated_message_type,
|
|
401
|
-
m.associated_message_emoji AS associated_message_emoji,
|
|
402
|
-
m.cache_has_attachments AS cache_has_attachments,
|
|
403
|
-
m.service AS message_service,
|
|
404
|
-
h.id AS handle,
|
|
405
|
-
h.service AS handle_service,
|
|
406
|
-
c.chat_identifier AS chat_identifier,
|
|
407
|
-
c.display_name AS display_name,
|
|
408
|
-
c.style AS chat_style
|
|
409
|
-
FROM message m
|
|
410
|
-
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
411
|
-
LEFT JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
412
|
-
LEFT JOIN chat c ON cmj.chat_id = c.ROWID
|
|
413
|
-
ORDER BY m.ROWID DESC
|
|
414
|
-
LIMIT ?
|
|
415
|
-
`);
|
|
416
|
-
const recentMessagesByChatStmt = db.query(`
|
|
417
|
-
SELECT
|
|
418
|
-
m.ROWID AS row_id,
|
|
419
|
-
m.guid AS guid,
|
|
420
|
-
m.text AS text,
|
|
421
|
-
m.attributedBody AS attributed_body,
|
|
422
|
-
m.date AS apple_date,
|
|
423
|
-
m.date_read AS apple_date_read,
|
|
424
|
-
m.date_edited AS apple_date_edited,
|
|
425
|
-
m.date_retracted AS apple_date_retracted,
|
|
426
|
-
m.is_from_me AS is_from_me,
|
|
427
|
-
m.is_read AS is_read,
|
|
428
|
-
m.is_sent AS is_sent,
|
|
429
|
-
m.is_delivered AS is_delivered,
|
|
430
|
-
m.item_type AS item_type,
|
|
431
|
-
m.reply_to_guid AS reply_to_guid,
|
|
432
|
-
m.associated_message_guid AS associated_message_guid,
|
|
433
|
-
m.associated_message_type AS associated_message_type,
|
|
434
|
-
m.associated_message_emoji AS associated_message_emoji,
|
|
435
|
-
m.cache_has_attachments AS cache_has_attachments,
|
|
436
|
-
m.service AS message_service,
|
|
437
|
-
h.id AS handle,
|
|
438
|
-
h.service AS handle_service,
|
|
439
|
-
c.chat_identifier AS chat_identifier,
|
|
440
|
-
c.display_name AS display_name,
|
|
441
|
-
c.style AS chat_style
|
|
442
|
-
FROM message m
|
|
443
|
-
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
444
|
-
LEFT JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
445
|
-
LEFT JOIN chat c ON cmj.chat_id = c.ROWID
|
|
446
|
-
WHERE c.chat_identifier = ?
|
|
447
|
-
ORDER BY m.ROWID DESC
|
|
448
|
-
LIMIT ?
|
|
449
|
-
`);
|
|
450
383
|
// List-chats statement: every chat joined to handles via
|
|
451
384
|
// chat_handle_join, grouped so each chat returns one row with an
|
|
452
385
|
// aggregated participant list.
|
|
@@ -466,88 +399,6 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
466
399
|
ORDER BY c.last_read_message_timestamp DESC
|
|
467
400
|
`);
|
|
468
401
|
let closed = false;
|
|
469
|
-
function materializeMessages(rows) {
|
|
470
|
-
const out = [];
|
|
471
|
-
let undecodable = 0;
|
|
472
|
-
for (const row of rows) {
|
|
473
|
-
// Resolve the visible text: prefer the plain `text` column, fall
|
|
474
|
-
// back to decoding `attributedBody`, then empty string.
|
|
475
|
-
let text = "";
|
|
476
|
-
if (row.text && row.text.length > 0) {
|
|
477
|
-
text = row.text;
|
|
478
|
-
}
|
|
479
|
-
else if (row.attributed_body) {
|
|
480
|
-
const decoded = decodeAttributedBody(row.attributed_body);
|
|
481
|
-
if (decoded != null) {
|
|
482
|
-
text = decoded;
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
undecodable++;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
// Classify the row. Reactions get their own kind + a parsed
|
|
489
|
-
// reaction payload; system messages (group add/remove/rename)
|
|
490
|
-
// surface as `"system"` so the caller can log or ignore.
|
|
491
|
-
const assocType = row.associated_message_type ?? 0;
|
|
492
|
-
let kind = "text";
|
|
493
|
-
let reaction = null;
|
|
494
|
-
if (assocType >= 2000 && assocType < 4000) {
|
|
495
|
-
kind = "reaction";
|
|
496
|
-
reaction = parseReaction(row);
|
|
497
|
-
}
|
|
498
|
-
else if (row.item_type != null && row.item_type !== 0) {
|
|
499
|
-
kind = "system";
|
|
500
|
-
}
|
|
501
|
-
// Attachments — only fetched when the cache bit indicates any.
|
|
502
|
-
let attachments = [];
|
|
503
|
-
if (row.cache_has_attachments === 1) {
|
|
504
|
-
try {
|
|
505
|
-
const attRows = attachmentsStmt.all(row.row_id);
|
|
506
|
-
attachments = attRows.map((a) => ({
|
|
507
|
-
guid: a.guid,
|
|
508
|
-
filename: a.transfer_name ?? a.filename ?? null,
|
|
509
|
-
uti: a.uti,
|
|
510
|
-
mimeType: a.mime_type,
|
|
511
|
-
totalBytes: a.total_bytes,
|
|
512
|
-
isSticker: a.is_sticker === 1,
|
|
513
|
-
}));
|
|
514
|
-
}
|
|
515
|
-
catch (error) {
|
|
516
|
-
logger.debug(`[imessage] attachment query failed for rowid=${row.row_id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
// Service resolution: prefer the message row's own service field,
|
|
520
|
-
// fall back to the handle's service (stable across messages from
|
|
521
|
-
// the same sender), else unknown.
|
|
522
|
-
const service = row.message_service ?? row.handle_service ?? null;
|
|
523
|
-
out.push({
|
|
524
|
-
rowId: row.row_id,
|
|
525
|
-
guid: row.guid,
|
|
526
|
-
text,
|
|
527
|
-
kind,
|
|
528
|
-
handle: row.handle ?? "",
|
|
529
|
-
chatId: row.chat_identifier ?? "",
|
|
530
|
-
chatType: row.chat_style === 43 ? "group" : "direct",
|
|
531
|
-
displayName: row.display_name,
|
|
532
|
-
timestamp: appleDateToJsMs(row.apple_date),
|
|
533
|
-
isFromMe: row.is_from_me === 1,
|
|
534
|
-
service,
|
|
535
|
-
isSent: row.is_sent === 1,
|
|
536
|
-
isDelivered: row.is_delivered === 1,
|
|
537
|
-
isRead: row.is_read === 1,
|
|
538
|
-
dateRead: appleDateToJsMs(row.apple_date_read ?? 0),
|
|
539
|
-
dateEdited: appleDateToJsMs(row.apple_date_edited ?? 0),
|
|
540
|
-
dateRetracted: appleDateToJsMs(row.apple_date_retracted ?? 0),
|
|
541
|
-
replyToGuid: row.reply_to_guid,
|
|
542
|
-
reaction,
|
|
543
|
-
attachments,
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
if (undecodable > 0) {
|
|
547
|
-
logger.debug(`[imessage] chat.db poll: ${undecodable} row(s) had attributedBody that could not be decoded; their text is empty`);
|
|
548
|
-
}
|
|
549
|
-
return out;
|
|
550
|
-
}
|
|
551
402
|
return {
|
|
552
403
|
fetchNewMessages(sinceRowId, limit) {
|
|
553
404
|
if (closed)
|
|
@@ -560,7 +411,86 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
560
411
|
logger.error(`[imessage] chat.db query failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
561
412
|
return [];
|
|
562
413
|
}
|
|
563
|
-
|
|
414
|
+
const out = [];
|
|
415
|
+
let undecodable = 0;
|
|
416
|
+
for (const row of rows) {
|
|
417
|
+
// Resolve the visible text: prefer the plain `text` column, fall
|
|
418
|
+
// back to decoding `attributedBody`, then empty string.
|
|
419
|
+
let text = "";
|
|
420
|
+
if (row.text && row.text.length > 0) {
|
|
421
|
+
text = row.text;
|
|
422
|
+
}
|
|
423
|
+
else if (row.attributed_body) {
|
|
424
|
+
const decoded = decodeAttributedBody(row.attributed_body);
|
|
425
|
+
if (decoded != null) {
|
|
426
|
+
text = decoded;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
undecodable++;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// Classify the row. Reactions get their own kind + a parsed
|
|
433
|
+
// reaction payload; system messages (group add/remove/rename)
|
|
434
|
+
// surface as `"system"` so the caller can log or ignore.
|
|
435
|
+
const assocType = row.associated_message_type ?? 0;
|
|
436
|
+
let kind = "text";
|
|
437
|
+
let reaction = null;
|
|
438
|
+
if (assocType >= 2000 && assocType < 4000) {
|
|
439
|
+
kind = "reaction";
|
|
440
|
+
reaction = parseReaction(row);
|
|
441
|
+
}
|
|
442
|
+
else if (row.item_type != null && row.item_type !== 0) {
|
|
443
|
+
kind = "system";
|
|
444
|
+
}
|
|
445
|
+
// Attachments — only fetched when the cache bit indicates any.
|
|
446
|
+
let attachments = [];
|
|
447
|
+
if (row.cache_has_attachments === 1) {
|
|
448
|
+
try {
|
|
449
|
+
const attRows = attachmentsStmt.all(row.row_id);
|
|
450
|
+
attachments = attRows.map((a) => ({
|
|
451
|
+
guid: a.guid,
|
|
452
|
+
filename: a.transfer_name ?? a.filename ?? null,
|
|
453
|
+
uti: a.uti,
|
|
454
|
+
mimeType: a.mime_type,
|
|
455
|
+
totalBytes: a.total_bytes,
|
|
456
|
+
isSticker: a.is_sticker === 1,
|
|
457
|
+
}));
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
logger.debug(`[imessage] attachment query failed for rowid=${row.row_id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// Service resolution: prefer the message row's own service field,
|
|
464
|
+
// fall back to the handle's service (stable across messages from
|
|
465
|
+
// the same sender), else unknown.
|
|
466
|
+
const service = row.message_service ?? row.handle_service ?? null;
|
|
467
|
+
out.push({
|
|
468
|
+
rowId: row.row_id,
|
|
469
|
+
guid: row.guid,
|
|
470
|
+
text,
|
|
471
|
+
kind,
|
|
472
|
+
handle: row.handle ?? "",
|
|
473
|
+
chatId: row.chat_identifier ?? "",
|
|
474
|
+
chatType: row.chat_style === 43 ? "group" : "direct",
|
|
475
|
+
displayName: row.display_name,
|
|
476
|
+
timestamp: appleDateToJsMs(row.apple_date),
|
|
477
|
+
isFromMe: row.is_from_me === 1,
|
|
478
|
+
service,
|
|
479
|
+
isSent: row.is_sent === 1,
|
|
480
|
+
isDelivered: row.is_delivered === 1,
|
|
481
|
+
isRead: row.is_read === 1,
|
|
482
|
+
dateRead: appleDateToJsMs(row.apple_date_read ?? 0),
|
|
483
|
+
dateEdited: appleDateToJsMs(row.apple_date_edited ?? 0),
|
|
484
|
+
dateRetracted: appleDateToJsMs(row.apple_date_retracted ?? 0),
|
|
485
|
+
replyToGuid: row.reply_to_guid,
|
|
486
|
+
reaction,
|
|
487
|
+
attachments,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
if (undecodable > 0) {
|
|
491
|
+
logger.debug(`[imessage] chat.db poll: ${undecodable} row(s) had attributedBody that could not be decoded; their text is empty`);
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
564
494
|
},
|
|
565
495
|
getLatestRowId() {
|
|
566
496
|
if (closed)
|
|
@@ -587,27 +517,6 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
587
517
|
return null;
|
|
588
518
|
}
|
|
589
519
|
},
|
|
590
|
-
listMessages(options = {}) {
|
|
591
|
-
if (closed)
|
|
592
|
-
return [];
|
|
593
|
-
const chatId = options.chatId?.trim();
|
|
594
|
-
const requestedLimit = typeof options.limit === "number" && Number.isFinite(options.limit) ? options.limit : 50;
|
|
595
|
-
const limit = Math.max(1, Math.trunc(requestedLimit));
|
|
596
|
-
let rows;
|
|
597
|
-
try {
|
|
598
|
-
rows = chatId
|
|
599
|
-
? recentMessagesByChatStmt.all(chatId, limit)
|
|
600
|
-
: recentMessagesStmt.all(limit);
|
|
601
|
-
}
|
|
602
|
-
catch (error) {
|
|
603
|
-
logger.error(`[imessage] chat.db listMessages query failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
604
|
-
return [];
|
|
605
|
-
}
|
|
606
|
-
// Queries run DESC for efficiency on "latest N" reads. Reverse
|
|
607
|
-
// back to chronological order so API/UI callers can render in the
|
|
608
|
-
// natural oldest→newest sequence without a second sort.
|
|
609
|
-
return materializeMessages(rows).reverse();
|
|
610
|
-
},
|
|
611
520
|
listChats() {
|
|
612
521
|
if (closed)
|
|
613
522
|
return [];
|
|
@@ -9,7 +9,7 @@ import { sendMessage } from "./actions/index.js";
|
|
|
9
9
|
import { chatContextProvider, contactsProvider } from "./providers/index.js";
|
|
10
10
|
import { chatDbMessageToPublicShape, IMessageService, parseChatsFromAppleScript, parseMessagesFromAppleScript } from "./service.js";
|
|
11
11
|
export { DEFAULT_ACCOUNT_ID, type IMessageAccountConfig, type IMessageGroupConfig, type IMessageMultiAccountConfig, isIMessageMentionRequired, isIMessageUserAllowed, isMultiAccountEnabled, listEnabledIMessageAccounts, listIMessageAccountIds, normalizeAccountId, type ResolvedIMessageAccount, resolveDefaultIMessageAccountId, resolveIMessageAccount, resolveIMessageGroupConfig, } from "./accounts.js";
|
|
12
|
-
export { appleDateToJsMs, type
|
|
12
|
+
export { appleDateToJsMs, type ChatDbMessage, type ChatDbReader, type ChatDbAccessIssue, createFullDiskAccessAction, DEFAULT_CHAT_DB_PATH, getLastChatDbAccessIssue, MACOS_FULL_DISK_ACCESS_SETTINGS_URL, openChatDb, } from "./chatdb-reader.js";
|
|
13
13
|
export { addContact, type ContactPatch, type ContactsMap, deleteContact, type FullContact, listAllContacts, loadContacts, type NewContactInput, normalizeContactHandle, parseContactsOutput, type ResolvedContact, updateContact, } from "./contacts-reader.js";
|
|
14
14
|
export { createIMessageRpcClient, DEFAULT_PROBE_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, getChatInfo, getContactInfo, getMessages, type IMessageAttachment, type IMessageChat, type IMessageContact, type IMessageMessage, IMessageRpcClient, type IMessageRpcClientOptions, type IMessageRpcError, type IMessageRpcNotification, type IMessageRpcResponse, listChats, listContacts, probeIMessageRpc, sendIMessageRpc, } from "./rpc.js";
|
|
15
15
|
export * from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,mCAAmC,EACnC,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,aAAa,EACb,KAAK,WAAW,EAChB,eAAe,EACf,YAAY,EACZ,KAAK,eAAe,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,eAAe,EACpB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,WAAW,EACX,cAAc,EACd,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC5B,WAAW,GACZ,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,cAAc,EAAE,MAiCrB,CAAC;AAEF,eAAe,cAAc,CAAC;AAG9B,YAAY,EACV,cAAc,EACd,gCAAgC,GACjC,MAAM,aAAa,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { type IAgentRuntime, Service } from "@elizaos/core";
|
|
5
5
|
import { type ChatDbMessage } from "./chatdb-reader.js";
|
|
6
6
|
import { type ContactPatch, type ContactsMap, type FullContact, type NewContactInput } from "./contacts-reader.js";
|
|
7
|
-
import { type IIMessageService, type IMessageChat, type
|
|
7
|
+
import { type IIMessageService, type IMessageChat, type IMessageMessage, type IMessageServiceStatus, type IMessageSendOptions, type IMessageSendResult, type IMessageSettings } from "./types.js";
|
|
8
8
|
/**
|
|
9
9
|
* iMessage service for ElizaOS agents.
|
|
10
10
|
* Note: This only works on macOS.
|
|
@@ -94,12 +94,6 @@ export declare class IMessageService extends Service implements IIMessageService
|
|
|
94
94
|
* granted, etc.).
|
|
95
95
|
*/
|
|
96
96
|
getRecentMessages(limit?: number): Promise<IMessageMessage[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Return the newest messages in chronological order, optionally scoped
|
|
99
|
-
* to a single chat identifier. Returns an empty array if chat.db is not
|
|
100
|
-
* available and the connector is currently running in send-only mode.
|
|
101
|
-
*/
|
|
102
|
-
getMessages(options?: IMessageListMessagesOptions): Promise<IMessageMessage[]>;
|
|
103
97
|
/**
|
|
104
98
|
* List every chat the Messages.app database knows about, joined with
|
|
105
99
|
* participant handles. Returns an empty list if the chat.db reader is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAQL,KAAK,aAAa,EAIlB,OAAO,EACR,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,WAAW,EAGhB,KAAK,eAAe,EAGrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,KAAK,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAQL,KAAK,aAAa,EAIlB,OAAO,EACR,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,WAAW,EAGhB,KAAK,eAAe,EAGrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,KAAK,eAAe,EAEpB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AAIpB;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,OAAQ,YAAW,gBAAgB;IACtE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAyB;IAEnD,qBAAqB,SAAkE;IAEvF,OAAO,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,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5E;;;OAGG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvD,OAAO,CAAC,YAAY;YA0DN,gBAAgB;YAsBhB,iBAAiB;YAkBjB,UAAU;YAuBV,kBAAkB;YA8DlB,cAAc;IAU5B,OAAO,CAAC,YAAY;IAcpB;;;;;;;;;;;;;;;;;OAiBG;YACW,kBAAkB;YAkBlB,uBAAuB;IA2ErC;;;;;;;;;OASG;YACW,sBAAsB;IAuOpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,kBAAkB;IAgD1B,OAAO,CAAC,SAAS;IAuBjB;;;;;;;;;;;;;;;;;OAiBG;YACW,iBAAiB;CA6GhC;AAkBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,aAAa,GAAG,eAAe,CAU9E;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,CA0C9E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CA+CxE"}
|
|
@@ -156,7 +156,9 @@ export class IMessageService extends Service {
|
|
|
156
156
|
}
|
|
157
157
|
getStatus() {
|
|
158
158
|
const chatDbAvailable = this.chatDb !== null;
|
|
159
|
-
const accessIssue = chatDbAvailable
|
|
159
|
+
const accessIssue = chatDbAvailable
|
|
160
|
+
? null
|
|
161
|
+
: getLastChatDbAccessIssue(this.chatDbPath);
|
|
160
162
|
return {
|
|
161
163
|
available: true,
|
|
162
164
|
connected: this.connected,
|
|
@@ -231,18 +233,16 @@ export class IMessageService extends Service {
|
|
|
231
233
|
* granted, etc.).
|
|
232
234
|
*/
|
|
233
235
|
async getRecentMessages(limit = 50) {
|
|
234
|
-
return this.getMessages({ limit });
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Return the newest messages in chronological order, optionally scoped
|
|
238
|
-
* to a single chat identifier. Returns an empty array if chat.db is not
|
|
239
|
-
* available and the connector is currently running in send-only mode.
|
|
240
|
-
*/
|
|
241
|
-
async getMessages(options = {}) {
|
|
242
236
|
if (!this.chatDb) {
|
|
243
237
|
return [];
|
|
244
238
|
}
|
|
245
|
-
|
|
239
|
+
// `fetchNewMessages(0, limit)` returns the first `limit` rows in
|
|
240
|
+
// ROWID order, which for chat.db is also message-creation order.
|
|
241
|
+
// For "the most recent N messages" we'd ideally query with a
|
|
242
|
+
// different filter; fetching from 0 and slicing is fine for
|
|
243
|
+
// caller's expected use (startup inspection / debugging) because
|
|
244
|
+
// typical chat.db files have at most a few hundred thousand rows.
|
|
245
|
+
const rows = this.chatDb.fetchNewMessages(0, limit);
|
|
246
246
|
return rows.map(chatDbMessageToPublicShape);
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
@@ -1018,14 +1018,7 @@ export function chatDbMessageToPublicShape(row) {
|
|
|
1018
1018
|
chatId: row.chatId,
|
|
1019
1019
|
timestamp: row.timestamp,
|
|
1020
1020
|
isFromMe: row.isFromMe,
|
|
1021
|
-
hasAttachments:
|
|
1022
|
-
...(row.attachments.length > 0
|
|
1023
|
-
? {
|
|
1024
|
-
attachmentPaths: row.attachments
|
|
1025
|
-
.map((attachment) => attachment.filename)
|
|
1026
|
-
.filter((filename) => Boolean(filename)),
|
|
1027
|
-
}
|
|
1028
|
-
: {}),
|
|
1021
|
+
hasAttachments: false,
|
|
1029
1022
|
};
|
|
1030
1023
|
}
|
|
1031
1024
|
/**
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* Routes served (all under `/api/imessage`):
|
|
10
10
|
*
|
|
11
11
|
* GET /api/imessage/status service health + connection state
|
|
12
|
-
* GET /api/imessage/messages
|
|
13
|
-
* POST /api/imessage/messages send a message via Messages.app
|
|
12
|
+
* GET /api/imessage/messages recent messages from chat.db
|
|
14
13
|
* GET /api/imessage/chats list of chats (DMs + groups)
|
|
15
14
|
* GET /api/imessage/contacts every contact with full detail
|
|
16
15
|
* POST /api/imessage/contacts create a new contact
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-routes.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/setup-routes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"setup-routes.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/setup-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAiB,KAAK,EAA+B,MAAM,eAAe,CAAC;AAwTvF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,EA2CtC,CAAC"}
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* Routes served (all under `/api/imessage`):
|
|
10
10
|
*
|
|
11
11
|
* GET /api/imessage/status service health + connection state
|
|
12
|
-
* GET /api/imessage/messages
|
|
13
|
-
* POST /api/imessage/messages send a message via Messages.app
|
|
12
|
+
* GET /api/imessage/messages recent messages from chat.db
|
|
14
13
|
* GET /api/imessage/chats list of chats (DMs + groups)
|
|
15
14
|
* GET /api/imessage/contacts every contact with full detail
|
|
16
15
|
* POST /api/imessage/contacts create a new contact
|
|
@@ -70,11 +69,8 @@ async function handleMessages(req, res, runtime) {
|
|
|
70
69
|
const url = new URL(req.url ?? "/api/imessage/messages", "http://localhost");
|
|
71
70
|
const limitParam = url.searchParams.get("limit");
|
|
72
71
|
const limit = Math.min(Math.max(1, Number.parseInt(limitParam ?? "50", 10) || 50), 500);
|
|
73
|
-
const chatId = url.searchParams.get("chatId")?.trim() || undefined;
|
|
74
72
|
try {
|
|
75
|
-
const messages =
|
|
76
|
-
? await service.getMessages({ chatId, limit })
|
|
77
|
-
: await service.getRecentMessages(limit);
|
|
73
|
+
const messages = await service.getRecentMessages(limit);
|
|
78
74
|
res.status(200).json({ messages, count: messages.length });
|
|
79
75
|
}
|
|
80
76
|
catch (error) {
|
|
@@ -83,49 +79,6 @@ async function handleMessages(req, res, runtime) {
|
|
|
83
79
|
});
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
|
-
// ── POST /api/imessage/messages ────────────────────────────────────
|
|
87
|
-
async function handleSendMessage(req, res, runtime) {
|
|
88
|
-
const service = resolveService(runtime);
|
|
89
|
-
if (!service) {
|
|
90
|
-
res.status(503).json({ error: "imessage service not registered" });
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const body = req.body ?? {};
|
|
94
|
-
const to = body.to?.trim() || "";
|
|
95
|
-
const chatId = body.chatId?.trim() || "";
|
|
96
|
-
const text = body.text?.trim() || "";
|
|
97
|
-
const mediaUrl = body.mediaUrl?.trim() || undefined;
|
|
98
|
-
if (!to && !chatId) {
|
|
99
|
-
res.status(400).json({
|
|
100
|
-
error: "either to or chatId is required",
|
|
101
|
-
});
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (!text && !mediaUrl) {
|
|
105
|
-
res.status(400).json({
|
|
106
|
-
error: "either text or mediaUrl is required",
|
|
107
|
-
});
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
const result = await service.sendMessage(chatId ? `chat_id:${chatId}` : to, text, {
|
|
112
|
-
...(mediaUrl ? { mediaUrl } : {}),
|
|
113
|
-
...(typeof body.maxBytes === "number" ? { maxBytes: body.maxBytes } : {}),
|
|
114
|
-
});
|
|
115
|
-
if (!result.success) {
|
|
116
|
-
res.status(500).json({
|
|
117
|
-
error: result.error ?? "failed to send iMessage",
|
|
118
|
-
});
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
res.status(200).json(result);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
res.status(500).json({
|
|
125
|
-
error: `sendMessage threw: ${error instanceof Error ? error.message : String(error)}`,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
82
|
// ── GET /api/imessage/chats ─────────────────────────────────────────
|
|
130
83
|
async function handleChats(_req, res, runtime) {
|
|
131
84
|
const service = resolveService(runtime);
|
|
@@ -282,12 +235,6 @@ export const imessageSetupRoutes = [
|
|
|
282
235
|
handler: handleMessages,
|
|
283
236
|
rawPath: true,
|
|
284
237
|
},
|
|
285
|
-
{
|
|
286
|
-
type: "POST",
|
|
287
|
-
path: "/api/imessage/messages",
|
|
288
|
-
handler: handleSendMessage,
|
|
289
|
-
rawPath: true,
|
|
290
|
-
},
|
|
291
238
|
{
|
|
292
239
|
type: "GET",
|
|
293
240
|
path: "/api/imessage/chats",
|
|
@@ -88,12 +88,6 @@ export interface IMessageMessage {
|
|
|
88
88
|
/** Attachment paths */
|
|
89
89
|
attachmentPaths?: string[];
|
|
90
90
|
}
|
|
91
|
-
export interface IMessageListMessagesOptions {
|
|
92
|
-
/** Return only messages from this chat identifier. */
|
|
93
|
-
chatId?: string;
|
|
94
|
-
/** Maximum number of rows to return. */
|
|
95
|
-
limit?: number;
|
|
96
|
-
}
|
|
97
91
|
/**
|
|
98
92
|
* Options for sending a message
|
|
99
93
|
*/
|
|
@@ -141,8 +135,6 @@ export interface IIMessageService extends Service {
|
|
|
141
135
|
sendMessage(to: string, text: string, options?: IMessageSendOptions): Promise<IMessageSendResult>;
|
|
142
136
|
/** Get recent messages */
|
|
143
137
|
getRecentMessages(limit?: number): Promise<IMessageMessage[]>;
|
|
144
|
-
/** List newest messages, optionally filtered to one chat. */
|
|
145
|
-
getMessages(options?: IMessageListMessagesOptions): Promise<IMessageMessage[]>;
|
|
146
138
|
/** Get chats */
|
|
147
139
|
getChats(): Promise<IMessageChat[]>;
|
|
148
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OA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rB,mBAAmB;IACnB,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc;IACd,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,sBAAsB;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,uBAAuB;IACvB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,0CAA0C;AAC1C,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,kCAAkC;AAClC,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,qCAAqC;AACrC,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;CAOrB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE7F;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EA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