aamp-openclaw-plugin 0.1.43 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ import { createRequire as __aampCreateRequire } from "module"; const require = __aampCreateRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined")
12
+ return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+
35
+ // src/file-store.ts
36
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
37
+ import { dirname, join } from "node:path";
38
+ import { homedir } from "node:os";
39
+ function defaultCredentialsPath() {
40
+ return join(homedir(), ".openclaw", "extensions", "aamp-openclaw-plugin", ".credentials.json");
41
+ }
42
+ function loadCachedIdentity(file) {
43
+ const resolved = file ?? defaultCredentialsPath();
44
+ if (!existsSync(resolved))
45
+ return null;
46
+ try {
47
+ const parsed = JSON.parse(readFileSync(resolved, "utf-8"));
48
+ if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword)
49
+ return null;
50
+ return parsed;
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+ function saveCachedIdentity(identity, file) {
56
+ const resolved = file ?? defaultCredentialsPath();
57
+ mkdirSync(dirname(resolved), { recursive: true });
58
+ writeFileSync(resolved, JSON.stringify(identity, null, 2), "utf-8");
59
+ }
60
+ function ensureDir(dir) {
61
+ mkdirSync(dir, { recursive: true });
62
+ }
63
+ function readBinaryFile(path) {
64
+ return readFileSync(path);
65
+ }
66
+ function writeBinaryFile(path, content) {
67
+ mkdirSync(dirname(path), { recursive: true });
68
+ writeFileSync(path, content);
69
+ }
70
+
71
+ export {
72
+ __require,
73
+ __commonJS,
74
+ __toESM,
75
+ defaultCredentialsPath,
76
+ loadCachedIdentity,
77
+ saveCachedIdentity,
78
+ ensureDir,
79
+ readBinaryFile,
80
+ writeBinaryFile
81
+ };
82
+ //# sourceMappingURL=chunk-ORTVVAMV.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/file-store.ts"],
4
+ "sourcesContent": ["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { homedir } from 'node:os'\n\nexport interface Identity {\n email: string\n jmapToken: string\n smtpPassword: string\n}\n\nexport function defaultCredentialsPath(): string {\n return join(homedir(), '.openclaw', 'extensions', 'aamp-openclaw-plugin', '.credentials.json')\n}\n\nexport function loadCachedIdentity(file?: string): Identity | null {\n const resolved = file ?? defaultCredentialsPath()\n if (!existsSync(resolved)) return null\n try {\n const parsed = JSON.parse(readFileSync(resolved, 'utf-8')) as Partial<Identity>\n if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword) return null\n return parsed as Identity\n } catch {\n return null\n }\n}\n\nexport function saveCachedIdentity(identity: Identity, file?: string): void {\n const resolved = file ?? defaultCredentialsPath()\n mkdirSync(dirname(resolved), { recursive: true })\n writeFileSync(resolved, JSON.stringify(identity, null, 2), 'utf-8')\n}\n\nexport function ensureDir(dir: string): void {\n mkdirSync(dir, { recursive: true })\n}\n\nexport function readBinaryFile(path: string): Buffer {\n return readFileSync(path)\n}\n\nexport function writeBinaryFile(path: string, content: Uint8Array | Buffer): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, content)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAC9B,SAAS,eAAe;AAQjB,SAAS,yBAAiC;AAC/C,SAAO,KAAK,QAAQ,GAAG,aAAa,cAAc,wBAAwB,mBAAmB;AAC/F;AAEO,SAAS,mBAAmB,MAAgC;AACjE,QAAM,WAAW,QAAQ,uBAAuB;AAChD,MAAI,CAAC,WAAW,QAAQ;AAAG,WAAO;AAClC,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AACzD,QAAI,CAAC,OAAO,SAAS,CAAC,OAAO,aAAa,CAAC,OAAO;AAAc,aAAO;AACvE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,mBAAmB,UAAoB,MAAqB;AAC1E,QAAM,WAAW,QAAQ,uBAAuB;AAChD,YAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,gBAAc,UAAU,KAAK,UAAU,UAAU,MAAM,CAAC,GAAG,OAAO;AACpE;AAEO,SAAS,UAAU,KAAmB;AAC3C,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC;AAEO,SAAS,eAAe,MAAsB;AACnD,SAAO,aAAa,IAAI;AAC1B;AAEO,SAAS,gBAAgB,MAAc,SAAoC;AAChF,YAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5C,gBAAc,MAAM,OAAO;AAC7B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,81 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // src/file-store.ts
35
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
36
+ import { dirname, join } from "node:path";
37
+ import { homedir } from "node:os";
38
+ function defaultCredentialsPath() {
39
+ return join(homedir(), ".openclaw", "extensions", "aamp-openclaw-plugin", ".credentials.json");
40
+ }
41
+ function loadCachedIdentity(file) {
42
+ const resolved = file ?? defaultCredentialsPath();
43
+ if (!existsSync(resolved))
44
+ return null;
45
+ try {
46
+ const parsed = JSON.parse(readFileSync(resolved, "utf-8"));
47
+ if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword)
48
+ return null;
49
+ return parsed;
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+ function saveCachedIdentity(identity, file) {
55
+ const resolved = file ?? defaultCredentialsPath();
56
+ mkdirSync(dirname(resolved), { recursive: true });
57
+ writeFileSync(resolved, JSON.stringify(identity, null, 2), "utf-8");
58
+ }
59
+ function ensureDir(dir) {
60
+ mkdirSync(dir, { recursive: true });
61
+ }
62
+ function readBinaryFile(path) {
63
+ return readFileSync(path);
64
+ }
65
+ function writeBinaryFile(path, content) {
66
+ mkdirSync(dirname(path), { recursive: true });
67
+ writeFileSync(path, content);
68
+ }
69
+
70
+ export {
71
+ __require,
72
+ __commonJS,
73
+ __toESM,
74
+ defaultCredentialsPath,
75
+ loadCachedIdentity,
76
+ saveCachedIdentity,
77
+ ensureDir,
78
+ readBinaryFile,
79
+ writeBinaryFile
80
+ };
81
+ //# sourceMappingURL=chunk-W4C7IUCH.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/file-store.ts"],
4
+ "sourcesContent": ["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { homedir } from 'node:os'\n\nexport interface Identity {\n email: string\n jmapToken: string\n smtpPassword: string\n}\n\nexport function defaultCredentialsPath(): string {\n return join(homedir(), '.openclaw', 'extensions', 'aamp-openclaw-plugin', '.credentials.json')\n}\n\nexport function loadCachedIdentity(file?: string): Identity | null {\n const resolved = file ?? defaultCredentialsPath()\n if (!existsSync(resolved)) return null\n try {\n const parsed = JSON.parse(readFileSync(resolved, 'utf-8')) as Partial<Identity>\n if (!parsed.email || !parsed.jmapToken || !parsed.smtpPassword) return null\n return parsed as Identity\n } catch {\n return null\n }\n}\n\nexport function saveCachedIdentity(identity: Identity, file?: string): void {\n const resolved = file ?? defaultCredentialsPath()\n mkdirSync(dirname(resolved), { recursive: true })\n writeFileSync(resolved, JSON.stringify(identity, null, 2), 'utf-8')\n}\n\nexport function ensureDir(dir: string): void {\n mkdirSync(dir, { recursive: true })\n}\n\nexport function readBinaryFile(path: string): Buffer {\n return readFileSync(path)\n}\n\nexport function writeBinaryFile(path: string, content: Uint8Array | Buffer): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, content)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAC9B,SAAS,eAAe;AAQjB,SAAS,yBAAiC;AAC/C,SAAO,KAAK,QAAQ,GAAG,aAAa,cAAc,wBAAwB,mBAAmB;AAC/F;AAEO,SAAS,mBAAmB,MAAgC;AACjE,QAAM,WAAW,QAAQ,uBAAuB;AAChD,MAAI,CAAC,WAAW,QAAQ;AAAG,WAAO;AAClC,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AACzD,QAAI,CAAC,OAAO,SAAS,CAAC,OAAO,aAAa,CAAC,OAAO;AAAc,aAAO;AACvE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,mBAAmB,UAAoB,MAAqB;AAC1E,QAAM,WAAW,QAAQ,uBAAuB;AAChD,YAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,gBAAc,UAAU,KAAK,UAAU,UAAU,MAAM,CAAC,GAAG,OAAO;AACpE;AAEO,SAAS,UAAU,KAAmB;AAC3C,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC;AAEO,SAAS,eAAe,MAAsB;AACnD,SAAO,aAAa,IAAI;AAC1B;AAEO,SAAS,gBAAgB,MAAc,SAAoC;AAChF,YAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5C,gBAAc,MAAM,OAAO;AAC7B;",
6
+ "names": []
7
+ }
package/dist/index.js CHANGED
@@ -910,21 +910,17 @@ var JmapPushClient = class extends TinyEmitter {
910
910
  this.emit("error", new Error(`JMAP WebSocket handshake failed: ${res.statusCode ?? "unknown"} ${res.statusMessage ?? ""}${headerSummary ? ` | headers: ${headerSummary}` : ""}`));
911
911
  this.scheduleReconnect();
912
912
  });
913
- this.ws.on("open", async () => {
914
- this.connecting = false;
915
- this.connected = true;
916
- this.stopPolling();
917
- this.startPingHeartbeat();
918
- const accountId = this.session?.primaryAccounts["urn:ietf:params:jmap:mail"];
919
- if (accountId && this.emailState === null) {
920
- await this.initEmailState(accountId);
921
- }
922
- this.ws.send(JSON.stringify({
923
- "@type": "WebSocketPushEnable",
924
- dataTypes: ["Email"],
925
- pushState: null
926
- }));
927
- this.emit("connected");
913
+ this.ws.on("open", () => {
914
+ void this.handleWebSocketOpen().catch((err) => {
915
+ const reason = `websocket open initialization failed: ${err.message}`;
916
+ this.connecting = false;
917
+ this.connected = false;
918
+ this.stopPingHeartbeat();
919
+ this.startPolling(reason);
920
+ this.emit("error", new Error(`JMAP ${reason}`));
921
+ this.ws?.close();
922
+ this.scheduleReconnect();
923
+ });
928
924
  });
929
925
  this.ws.on("pong", () => {
930
926
  });
@@ -977,6 +973,22 @@ var JmapPushClient = class extends TinyEmitter {
977
973
  this.pingTimer = null;
978
974
  }
979
975
  }
976
+ async handleWebSocketOpen() {
977
+ this.connecting = false;
978
+ this.connected = true;
979
+ this.stopPolling();
980
+ this.startPingHeartbeat();
981
+ const accountId = this.session?.primaryAccounts["urn:ietf:params:jmap:mail"];
982
+ if (accountId && this.emailState === null) {
983
+ await this.initEmailState(accountId);
984
+ }
985
+ this.ws?.send(JSON.stringify({
986
+ "@type": "WebSocketPushEnable",
987
+ dataTypes: ["Email"],
988
+ pushState: null
989
+ }));
990
+ this.emit("connected");
991
+ }
980
992
  startSafetySync() {
981
993
  if (this.safetySyncTimer)
982
994
  return;
@@ -1605,38 +1617,103 @@ var SmtpSender = class _SmtpSender {
1605
1617
  const data = await res.json();
1606
1618
  return data.methodResponses ?? [];
1607
1619
  }
1608
- async uploadSentAttachment(attachment) {
1620
+ async uploadJmapBlob(params) {
1609
1621
  const session = await this.resolveJmapSession();
1610
- const content = typeof attachment.content === "string" ? Buffer.from(attachment.content, "base64") : attachment.content;
1611
1622
  const uploadUrl = session.uploadUrl.replace(/\{accountId\}|%7BaccountId%7D/gi, encodeURIComponent(session.accountId));
1612
1623
  const res = await this.fetch(uploadUrl, {
1613
1624
  method: "POST",
1614
1625
  headers: {
1615
1626
  Authorization: this.getJmapAuthHeader(),
1616
- "Content-Type": attachment.contentType
1627
+ "Content-Type": params.contentType
1617
1628
  },
1618
- body: content
1629
+ body: params.content
1619
1630
  });
1620
1631
  const bodyText = await res.text();
1621
1632
  if (!res.ok) {
1622
- throw new Error(`JMAP attachment upload failed: ${res.status} ${bodyText}`);
1633
+ throw new Error(`JMAP blob upload failed: ${res.status} ${bodyText}`);
1623
1634
  }
1624
1635
  let data;
1625
1636
  try {
1626
1637
  data = JSON.parse(bodyText);
1627
1638
  } catch {
1628
- throw new Error("JMAP attachment upload returned invalid JSON");
1639
+ throw new Error("JMAP blob upload returned invalid JSON");
1629
1640
  }
1630
1641
  if (!data.blobId) {
1631
- throw new Error("JMAP attachment upload did not return blobId");
1642
+ throw new Error("JMAP blob upload did not return blobId");
1632
1643
  }
1633
1644
  return {
1634
1645
  blobId: data.blobId,
1635
- type: data.type ?? attachment.contentType,
1636
- size: data.size ?? content.byteLength,
1637
- name: attachment.filename
1646
+ type: data.type ?? params.contentType,
1647
+ size: data.size ?? params.content.byteLength
1638
1648
  };
1639
1649
  }
1650
+ async buildRawSentMessage(params) {
1651
+ const rawTransport = createTransport({
1652
+ streamTransport: true,
1653
+ buffer: true,
1654
+ newline: "unix"
1655
+ });
1656
+ const mailOptions = {
1657
+ from: params.from,
1658
+ to: params.to,
1659
+ subject: params.subject,
1660
+ text: params.text,
1661
+ headers: params.aampHeaders
1662
+ };
1663
+ if (params.messageId)
1664
+ mailOptions.messageId = sanitize(params.messageId);
1665
+ if (params.inReplyTo)
1666
+ mailOptions.inReplyTo = params.inReplyTo;
1667
+ if (params.references)
1668
+ mailOptions.references = params.references;
1669
+ if (params.attachments?.length) {
1670
+ mailOptions.attachments = params.attachments.map((attachment) => ({
1671
+ filename: attachment.filename,
1672
+ contentType: attachment.contentType,
1673
+ content: typeof attachment.content === "string" ? Buffer.from(attachment.content, "base64") : attachment.content
1674
+ }));
1675
+ }
1676
+ const info = await rawTransport.sendMail(mailOptions);
1677
+ const rawMessage = info.message;
1678
+ if (Buffer.isBuffer(rawMessage))
1679
+ return rawMessage;
1680
+ if (rawMessage instanceof Uint8Array)
1681
+ return Buffer.from(rawMessage);
1682
+ if (typeof rawMessage === "string")
1683
+ return Buffer.from(rawMessage);
1684
+ throw new Error("Raw message generation did not return a Buffer");
1685
+ }
1686
+ async importRawSentMessage(params) {
1687
+ if (!this.canPersistSentCopy())
1688
+ return;
1689
+ const sentMailboxId = await this.getSentMailboxId();
1690
+ if (!sentMailboxId)
1691
+ return;
1692
+ const rawMessage = await this.buildRawSentMessage(params);
1693
+ const uploadedMessage = await this.uploadJmapBlob({
1694
+ content: rawMessage,
1695
+ contentType: "message/rfc822"
1696
+ });
1697
+ const responses = await this.jmapCall([
1698
+ [
1699
+ "Email/import",
1700
+ {
1701
+ emails: {
1702
+ sent1: {
1703
+ blobId: uploadedMessage.blobId,
1704
+ mailboxIds: { [sentMailboxId]: true },
1705
+ keywords: { "$seen": true }
1706
+ }
1707
+ }
1708
+ },
1709
+ "import1"
1710
+ ]
1711
+ ]);
1712
+ const result = responses.find(([name]) => name === "Email/import")?.[1];
1713
+ if (result?.notImported?.sent1) {
1714
+ throw new Error(`JMAP sent message import failed: ${JSON.stringify(result.notImported.sent1)}`);
1715
+ }
1716
+ }
1640
1717
  async getSentMailboxId() {
1641
1718
  if (!this.sentMailboxIdPromise) {
1642
1719
  this.sentMailboxIdPromise = (async () => {
@@ -1658,10 +1735,13 @@ var SmtpSender = class _SmtpSender {
1658
1735
  async saveToSent(params) {
1659
1736
  if (!this.canPersistSentCopy())
1660
1737
  return;
1738
+ if (params.attachments?.length) {
1739
+ await this.importRawSentMessage(params);
1740
+ return;
1741
+ }
1661
1742
  const sentMailboxId = await this.getSentMailboxId();
1662
1743
  if (!sentMailboxId)
1663
1744
  return;
1664
- const uploadedAttachments = params.attachments?.length ? await Promise.all(params.attachments.map((attachment) => this.uploadSentAttachment(attachment))) : [];
1665
1745
  const emailCreate = {
1666
1746
  mailboxIds: { [sentMailboxId]: true },
1667
1747
  from: [{ email: params.from }],
@@ -1669,35 +1749,13 @@ var SmtpSender = class _SmtpSender {
1669
1749
  subject: params.subject,
1670
1750
  keywords: { "$seen": true }
1671
1751
  };
1672
- if (uploadedAttachments.length) {
1673
- emailCreate.bodyStructure = {
1674
- type: "multipart/mixed",
1675
- subParts: [
1676
- { partId: "body", type: "text/plain" },
1677
- ...uploadedAttachments.map((attachment) => ({
1678
- blobId: attachment.blobId,
1679
- type: attachment.type,
1680
- size: attachment.size,
1681
- name: attachment.name,
1682
- disposition: "attachment"
1683
- }))
1684
- ]
1685
- };
1686
- emailCreate.bodyValues = {
1687
- body: {
1688
- value: params.text,
1689
- isTruncated: false
1690
- }
1691
- };
1692
- } else {
1693
- emailCreate.bodyValues = {
1694
- body: {
1695
- value: params.text,
1696
- charset: "utf-8"
1697
- }
1698
- };
1699
- emailCreate.textBody = [{ partId: "body", type: "text/plain" }];
1700
- }
1752
+ emailCreate.bodyValues = {
1753
+ body: {
1754
+ value: params.text,
1755
+ charset: "utf-8"
1756
+ }
1757
+ };
1758
+ emailCreate.textBody = [{ partId: "body", type: "text/plain" }];
1701
1759
  if (params.inReplyTo) {
1702
1760
  emailCreate["header:In-Reply-To:asText"] = ` ${sanitize(params.inReplyTo)}`;
1703
1761
  }
@@ -2370,6 +2428,25 @@ function buildRegisteredCommandDispatchPayload(opts) {
2370
2428
  };
2371
2429
  }
2372
2430
  var DEFAULT_TASK_DISPATCH_CONCURRENCY = 10;
2431
+ function asStreamRecord(value) {
2432
+ if (!value || typeof value !== "object" || Array.isArray(value))
2433
+ return void 0;
2434
+ return value;
2435
+ }
2436
+ function normalizeSseStreamEvent(params) {
2437
+ const record = asStreamRecord(params.data) ?? {};
2438
+ const payload = asStreamRecord(record.payload) ?? record;
2439
+ const seqValue = Number(record.seq);
2440
+ return {
2441
+ id: typeof record.id === "string" && record.id ? record.id : params.eventId,
2442
+ streamId: String(record.streamId ?? params.streamId),
2443
+ taskId: String(record.taskId ?? ""),
2444
+ seq: Number.isFinite(seqValue) ? seqValue : params.seq,
2445
+ timestamp: String(record.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()),
2446
+ type: String(record.type ?? params.eventType ?? "message"),
2447
+ payload
2448
+ };
2449
+ }
2373
2450
  function normalizeTaskDispatchConcurrency(value) {
2374
2451
  if (value == null)
2375
2452
  return DEFAULT_TASK_DISPATCH_CONCURRENCY;
@@ -3000,7 +3077,8 @@ var AampClient = class _AampClient extends TinyEmitter {
3000
3077
  const res = await fetchImpl(url, {
3001
3078
  headers: {
3002
3079
  Authorization: `Basic ${this.config.mailboxToken}`,
3003
- Accept: "text/event-stream"
3080
+ Accept: "text/event-stream",
3081
+ ...opts.lastEventId ? { "Last-Event-ID": opts.lastEventId } : {}
3004
3082
  },
3005
3083
  signal: controller.signal
3006
3084
  });
@@ -3014,16 +3092,19 @@ var AampClient = class _AampClient extends TinyEmitter {
3014
3092
  let currentEvent = "message";
3015
3093
  let currentId = "";
3016
3094
  let currentData = [];
3095
+ let fallbackSeq = 0;
3017
3096
  const flush = () => {
3018
3097
  if (!currentData.length)
3019
3098
  return;
3020
3099
  try {
3021
- const parsed = JSON.parse(currentData.join("\n"));
3022
- handlers.onEvent({
3023
- ...parsed,
3024
- ...currentId ? { id: currentId } : {},
3025
- type: parsed.type ?? currentEvent
3026
- });
3100
+ fallbackSeq += 1;
3101
+ handlers.onEvent(normalizeSseStreamEvent({
3102
+ data: JSON.parse(currentData.join("\n")),
3103
+ streamId,
3104
+ eventType: currentEvent,
3105
+ eventId: currentId || void 0,
3106
+ seq: fallbackSeq
3107
+ }));
3027
3108
  } catch (err) {
3028
3109
  handlers.onError?.(err);
3029
3110
  } finally {
@@ -3377,8 +3458,11 @@ async function ensureTaskStream(task) {
3377
3458
  });
3378
3459
  await aampClient.appendStreamEvent({
3379
3460
  streamId: created.streamId,
3380
- type: "status",
3381
- payload: { state: "running", label: "Task queued in OpenClaw" }
3461
+ type: "todo",
3462
+ payload: {
3463
+ items: [{ id: "openclaw-queued", content: "Task queued in OpenClaw", status: "in_progress" }],
3464
+ summary: "Task queued in OpenClaw"
3465
+ }
3382
3466
  });
3383
3467
  activeTaskStreams.set(task.taskId, created.streamId);
3384
3468
  return created.streamId;
@@ -4653,9 +4737,9 @@ ${task.bodyText}` : "",
4653
4737
  content: readBinaryFile(a.path)
4654
4738
  }));
4655
4739
  }
4656
- await appendTaskStream(task.taskId, "status", {
4657
- state: "completing",
4658
- label: `Sending ${p.status} result`
4740
+ await appendTaskStream(task.taskId, "todo", {
4741
+ items: [{ id: "openclaw-result", content: `Sending ${p.status} result`, status: "completed" }],
4742
+ summary: `Sending ${p.status} result`
4659
4743
  });
4660
4744
  if (p.output) {
4661
4745
  await appendTaskStream(task.taskId, "text.delta", { text: p.output });
@@ -4734,9 +4818,9 @@ ${task.bodyText}` : "",
4734
4818
  if (!aampClient?.isConnected()) {
4735
4819
  return { content: [{ type: "text", text: "Error: AAMP client is not connected." }] };
4736
4820
  }
4737
- await appendTaskStream(task.taskId, "status", {
4738
- state: "help_needed",
4739
- label: p.blockedReason
4821
+ await appendTaskStream(task.taskId, "todo", {
4822
+ items: [{ id: "openclaw-help", content: p.blockedReason, status: "completed" }],
4823
+ summary: p.blockedReason
4740
4824
  });
4741
4825
  try {
4742
4826
  await aampClient.sendHelp({
@@ -4749,12 +4833,9 @@ ${task.bodyText}` : "",
4749
4833
  });
4750
4834
  } catch (err) {
4751
4835
  const message = err instanceof Error ? err.message : String(err);
4752
- await appendTaskStream(task.taskId, "error", {
4753
- message: `Failed to send help request: ${message}`
4754
- });
4755
- await appendTaskStream(task.taskId, "status", {
4756
- state: "running",
4757
- label: "Help request failed; task still needs a reply"
4836
+ await appendTaskStream(task.taskId, "todo", {
4837
+ items: [{ id: "openclaw-help", content: "Help request failed; task still needs a reply", status: "in_progress" }],
4838
+ summary: `Failed to send help request: ${message}`
4758
4839
  });
4759
4840
  api.logger.error(`[AAMP] aamp_send_help failed for ${task.taskId}: ${message}`);
4760
4841
  return {