sideora 0.0.1-alpha.0 → 0.1.0-alpha.2

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 (221) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +57 -6
  3. package/assets/sounds/freesound_community-mail-40275.mp3 +0 -0
  4. package/assets/sounds/mixkit-clear-announce-tones-2861.wav +0 -0
  5. package/assets/sounds/mixkit-happy-bells-notification-937.wav +0 -0
  6. package/assets/sounds/mixkit-musical-alert-notification-2309.wav +0 -0
  7. package/assets/sounds/nice-chime.mp3 +0 -0
  8. package/bin/sideora.js +2430 -12
  9. package/extension/dist/assets/background.ts-NW8YqAlO.js +1 -0
  10. package/extension/dist/assets/fillCode-Ci8IkBvY.js +1 -0
  11. package/extension/dist/assets/index.html-DrrPha1M.js +2 -0
  12. package/extension/dist/assets/modulepreload-polyfill-DcjICKwh.js +1 -0
  13. package/extension/dist/assets/shell-82MNMljp.css +1 -0
  14. package/extension/dist/assets/shell-QYBN1bx1.js +1 -0
  15. package/extension/dist/icons/icon-128.png +0 -0
  16. package/extension/dist/icons/icon-16.png +0 -0
  17. package/extension/dist/icons/icon-32.png +0 -0
  18. package/extension/dist/icons/icon-48.png +0 -0
  19. package/extension/dist/manifest.json +40 -0
  20. package/extension/dist/service-worker-loader.js +1 -0
  21. package/extension/dist/src/newtab/index.html +14 -0
  22. package/extension/dist/src/panel/index.html +15 -0
  23. package/extension/dist-web/assets/abnfDiagram-WEYOIA3C-CoXOc872.js +1 -0
  24. package/extension/dist-web/assets/apple-touch-icon-DSgRQASq.png +0 -0
  25. package/extension/dist-web/assets/architecture-WOLXFQ4H-BkJ4AerO.js +1 -0
  26. package/extension/dist-web/assets/architectureDiagram-ZHVYKT53-aPkSDlxA.js +36 -0
  27. package/extension/dist-web/assets/blockDiagram-RJAE7QA3-CH1G4NBZ.js +140 -0
  28. package/extension/dist-web/assets/c4Diagram-XDPPPE54-Baum1zDu.js +38 -0
  29. package/extension/dist-web/assets/channel-PsQg-mnK.js +1 -0
  30. package/extension/dist-web/assets/chunk-2E7WHVMD-CKvLrWRa.js +88 -0
  31. package/extension/dist-web/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  32. package/extension/dist-web/assets/chunk-4EMNKR2T-6fjnroCZ.js +1 -0
  33. package/extension/dist-web/assets/chunk-55XCU76K-Ygs3sNpi.js +1 -0
  34. package/extension/dist-web/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  35. package/extension/dist-web/assets/chunk-7S6XSTFO-iX5xYzfP.js +2 -0
  36. package/extension/dist-web/assets/chunk-AQDTSKZB-D9zwhFI8.js +72 -0
  37. package/extension/dist-web/assets/chunk-DSNLSHJZ-siGS-4qu.js +129 -0
  38. package/extension/dist-web/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  39. package/extension/dist-web/assets/chunk-HAGFOTED-_3dtnWXn.js +62 -0
  40. package/extension/dist-web/assets/chunk-HNE4Q36P-BPzRHi72.js +1 -0
  41. package/extension/dist-web/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  42. package/extension/dist-web/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  43. package/extension/dist-web/assets/chunk-NGNAAXSQ-DI_UYJZ4.js +136 -0
  44. package/extension/dist-web/assets/chunk-NQOKRVIF-AXbmOBjs.js +213 -0
  45. package/extension/dist-web/assets/chunk-UHW7PFBP-B3xrZ8sD.js +1 -0
  46. package/extension/dist-web/assets/chunk-VQ5W62QI-D_k7Pa6b.js +1 -0
  47. package/extension/dist-web/assets/chunk-WQQL4CDK-BBIrWwoZ.js +10 -0
  48. package/extension/dist-web/assets/chunk-XXDRQBXY-i7MKP1NY.js +1 -0
  49. package/extension/dist-web/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  50. package/extension/dist-web/assets/chunk-YZO67HFG-Z7qp5QAI.js +1 -0
  51. package/extension/dist-web/assets/chunk-ZAUX2LTX-CSt3c0Rb.js +1 -0
  52. package/extension/dist-web/assets/chunk-ZCHMQSOR-g8XRABGK.js +2 -0
  53. package/extension/dist-web/assets/classDiagram-v2-4MYWR3UA-BL706wzc.js +217 -0
  54. package/extension/dist-web/assets/cose-bilkent-JH36ORCC-C6J2IoHg.js +1 -0
  55. package/extension/dist-web/assets/cynefin-EF2NZ3EQ-DLhQOiAy.js +1 -0
  56. package/extension/dist-web/assets/cynefinDiagram-WF24UDRP-Cv9Lx6_l.js +62 -0
  57. package/extension/dist-web/assets/cytoscape.esm-nTrd5EVq.js +321 -0
  58. package/extension/dist-web/assets/d3-scale-CElPUUud.js +1 -0
  59. package/extension/dist-web/assets/d3-selection-COWvaQNI.js +1 -0
  60. package/extension/dist-web/assets/dagre-NK4GIZVX-ngM-w2EC.js +4 -0
  61. package/extension/dist-web/assets/diagram-CBK3MWTC-kp8sayNG.js +24 -0
  62. package/extension/dist-web/assets/diagram-I5XIIV2D-BZ_Dgs6K.js +24 -0
  63. package/extension/dist-web/assets/diagram-ODIL2UCW-DWhUyArG.js +30 -0
  64. package/extension/dist-web/assets/diagram-PFBEJUXE-CBAdEK7l.js +3 -0
  65. package/extension/dist-web/assets/diagram-RJA3I4VV-kOdIr_3K.js +41 -0
  66. package/extension/dist-web/assets/diagram-TYUNFSNR-BrWGa0x5.js +200 -0
  67. package/extension/dist-web/assets/dist-DdXDFcej.js +1 -0
  68. package/extension/dist-web/assets/docx-preview-D1zbEiLy.js +20 -0
  69. package/extension/dist-web/assets/earth-Ce3xs8Cb.webp +0 -0
  70. package/extension/dist-web/assets/ebnfDiagram-V4P3TTPT-0r3weWmj.js +1 -0
  71. package/extension/dist-web/assets/elk-QONTBCTQ-D3oElRZ3.js +27 -0
  72. package/extension/dist-web/assets/erDiagram-KYQIGQAA-B9oU7_j_.js +99 -0
  73. package/extension/dist-web/assets/eventmodeling-K75KTNOO-CMKgc1nP.js +1 -0
  74. package/extension/dist-web/assets/favicon-D_X6tUVf.svg +5 -0
  75. package/extension/dist-web/assets/flowDiagram-IUGLLWBU-yRwks0Mw.js +1 -0
  76. package/extension/dist-web/assets/ganttDiagram-R7GPNTJY-cJqD1qwQ.js +292 -0
  77. package/extension/dist-web/assets/gitGraph-VSP46ZUC-CuBQqkbr.js +1 -0
  78. package/extension/dist-web/assets/gitGraphDiagram-PDYL7XHY-D7bHnQXC.js +106 -0
  79. package/extension/dist-web/assets/graphlib-DS17s2tU.js +1 -0
  80. package/extension/dist-web/assets/home-CV7-8Trs.js +1 -0
  81. package/extension/dist-web/assets/index-CQvw7Wy_.js +7 -0
  82. package/extension/dist-web/assets/index-CVKnZ21i.css +1 -0
  83. package/extension/dist-web/assets/info-OHQRW6UA-B8kyzV4O.js +1 -0
  84. package/extension/dist-web/assets/infoDiagram-MVDRKAX5-CEm6lezX.js +2 -0
  85. package/extension/dist-web/assets/ishikawaDiagram-HPEHV2GE-Ce3uv2wr.js +70 -0
  86. package/extension/dist-web/assets/journeyDiagram-BOSHW7O7-QgdahHCP.js +139 -0
  87. package/extension/dist-web/assets/jszip.min-3XXygzvy.js +2 -0
  88. package/extension/dist-web/assets/kanban-definition-FNSA4HC5-DPuTtWgR.js +89 -0
  89. package/extension/dist-web/assets/katex-MEuSR36T.js +257 -0
  90. package/extension/dist-web/assets/mermaid-parser.core-h7U7YGn_.js +7 -0
  91. package/extension/dist-web/assets/mermaid.core-DkGhophj.js +44 -0
  92. package/extension/dist-web/assets/mindmap-definition-6OY57UG3-D7VQxbda.js +98 -0
  93. package/extension/dist-web/assets/mount-CBzzf6KQ.js +195 -0
  94. package/extension/dist-web/assets/mount-DtvYnQXt.css +1 -0
  95. package/extension/dist-web/assets/officeparser.browser.slim-kEjhTrQ1.js +1989 -0
  96. package/extension/dist-web/assets/packet-JDAUHWVQ-oafHgw6X.js +1 -0
  97. package/extension/dist-web/assets/pegDiagram-ECIUJNBX-C3zo1naj.js +1 -0
  98. package/extension/dist-web/assets/peoria-B5TBlKDG.jpg +0 -0
  99. package/extension/dist-web/assets/peoria-thumb-CN8upAdZ.jpg +0 -0
  100. package/extension/dist-web/assets/pie-XZMESJXO-DXzeBQqF.js +1 -0
  101. package/extension/dist-web/assets/pieDiagram-GNMPY74T-S5NzPthl.js +39 -0
  102. package/extension/dist-web/assets/quadrantDiagram-D57K4MC3-C9glHQmk.js +7 -0
  103. package/extension/dist-web/assets/radar-ABXABTNO-CWTNqtbu.js +1 -0
  104. package/extension/dist-web/assets/railroad-I3PHUGI6-BTpD5_Bu.js +1 -0
  105. package/extension/dist-web/assets/railroad-abnf-LNEFI6M7-bWyxoXQG.js +1 -0
  106. package/extension/dist-web/assets/railroad-ebnf-DWYD2UWJ-ri5733DQ.js +1 -0
  107. package/extension/dist-web/assets/railroad-peg-JR7BVNR7-CmGfTubP.js +1 -0
  108. package/extension/dist-web/assets/railroadDiagram-Y72NRBL7-DTfe6Dh1.js +1 -0
  109. package/extension/dist-web/assets/requirementDiagram-EQYSW5RA-DQDzcS3L.js +84 -0
  110. package/extension/dist-web/assets/rolldown-runtime-COiEfhsA.js +1 -0
  111. package/extension/dist-web/assets/rough.esm-Dy-Kn_BL.js +1 -0
  112. package/extension/dist-web/assets/sankeyDiagram-SY24JHO5-DyMKWxdB.js +40 -0
  113. package/extension/dist-web/assets/sequenceDiagram-BLEHNHQU-dIkB1mCn.js +169 -0
  114. package/extension/dist-web/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
  115. package/extension/dist-web/assets/stateDiagram-v2-A6IESKWZ-Bj_vxEVF.js +291 -0
  116. package/extension/dist-web/assets/swimlanes-B3ENRKFQ-BSkWEwHR.js +1 -0
  117. package/extension/dist-web/assets/swimlanesDiagram-AYQRV4AK-BTzSDlSM.js +8 -0
  118. package/extension/dist-web/assets/timeline-definition-JXYKGLGB-TwfWS0pw.js +120 -0
  119. package/extension/dist-web/assets/treeView-D4JQ5SDB-BzA_8YYb.js +1 -0
  120. package/extension/dist-web/assets/treemap-SAJKECNS-BI9d6--2.js +1 -0
  121. package/extension/dist-web/assets/usecaseDiagram-WPOLBNNX-BOVbAUPk.js +328 -0
  122. package/extension/dist-web/assets/vennDiagram-Q3Y3IDCW-X2kYAWaj.js +34 -0
  123. package/extension/dist-web/assets/wardley-7MLQ67FV-CItxqJ8G.js +1 -0
  124. package/extension/dist-web/assets/wardleyDiagram-IVAIDKWA-BnUXvKD_.js +78 -0
  125. package/extension/dist-web/assets/xychartDiagram-4URNHDU4-ysvBXvyE.js +7 -0
  126. package/extension/dist-web/icon-192.png +0 -0
  127. package/extension/dist-web/icon-512.png +0 -0
  128. package/extension/dist-web/index.html +25 -0
  129. package/extension/dist-web/manifest.webmanifest +14 -0
  130. package/package.json +64 -12
  131. package/plugin/.claude-plugin/icon.png +0 -0
  132. package/plugin/.claude-plugin/plugin.json +6 -0
  133. package/plugin/.mcp.json +8 -0
  134. package/plugin/README.md +72 -0
  135. package/plugin/mcp-launcher.mjs +48 -0
  136. package/src/account-probe.js +45 -0
  137. package/src/accounts.js +687 -0
  138. package/src/ai.js +269 -0
  139. package/src/assistant-runs.js +32 -0
  140. package/src/attached-mail.js +76 -0
  141. package/src/auth-gate.js +70 -0
  142. package/src/backup-cli.js +158 -0
  143. package/src/backup.js +329 -0
  144. package/src/bimi.js +233 -0
  145. package/src/bridge.js +101 -0
  146. package/src/calendar-alerts.js +56 -0
  147. package/src/chats.js +27 -0
  148. package/src/compose-editor.js +58 -0
  149. package/src/config.js +420 -0
  150. package/src/connections.d.ts +24 -0
  151. package/src/connections.js +37 -0
  152. package/src/core/agent.js +92 -0
  153. package/src/core/assistant.d.ts +13 -0
  154. package/src/core/assistant.js +790 -0
  155. package/src/core/chats.js +323 -0
  156. package/src/core/markdown.d.ts +8 -0
  157. package/src/core/markdown.js +239 -0
  158. package/src/core/notes.js +445 -0
  159. package/src/core/otp.js +152 -0
  160. package/src/core/rules.js +196 -0
  161. package/src/core/runs.d.ts +9 -0
  162. package/src/core/runs.js +211 -0
  163. package/src/core/thread.js +526 -0
  164. package/src/core/write.js +247 -0
  165. package/src/core-db.js +131 -0
  166. package/src/core.js +174 -0
  167. package/src/credentials.js +320 -0
  168. package/src/daemon.js +564 -0
  169. package/src/events.js +213 -0
  170. package/src/extension-id.d.ts +2 -0
  171. package/src/extension-id.js +5 -0
  172. package/src/file-lock.js +27 -0
  173. package/src/files-index.js +154 -0
  174. package/src/google-contacts.js +315 -0
  175. package/src/google-signin.js +306 -0
  176. package/src/host/assistant-html.js +44 -0
  177. package/src/host/chats-files.js +137 -0
  178. package/src/host/file-prep.js +122 -0
  179. package/src/host/notes-files.js +158 -0
  180. package/src/host/office-text.js +224 -0
  181. package/src/host/office-worker.js +8 -0
  182. package/src/host/rules-file.js +20 -0
  183. package/src/host/secrets-file.js +91 -0
  184. package/src/host/systemd.js +90 -0
  185. package/src/hub.js +245 -0
  186. package/src/identity.js +316 -0
  187. package/src/labels.js +5 -0
  188. package/src/mail-port.d.ts +79 -0
  189. package/src/mail-port.js +148 -0
  190. package/src/mcp-server.js +747 -0
  191. package/src/microsoft-app.js +20 -0
  192. package/src/microsoft-signin.js +194 -0
  193. package/src/migrate.js +327 -0
  194. package/src/notes-html.js +450 -0
  195. package/src/notes.js +19 -0
  196. package/src/notify.js +105 -0
  197. package/src/onepassword.js +223 -0
  198. package/src/op-registry.d.ts +14 -0
  199. package/src/op-registry.js +150 -0
  200. package/src/ops.js +1251 -0
  201. package/src/otp.js +6 -0
  202. package/src/panel-ops.js +273 -0
  203. package/src/pictures.js +735 -0
  204. package/src/postinstall.js +25 -0
  205. package/src/relay-passkey.js +122 -0
  206. package/src/relay-request.js +155 -0
  207. package/src/relay-seal.js +56 -0
  208. package/src/relay-settings.js +139 -0
  209. package/src/relay.js +876 -0
  210. package/src/render.js +82 -0
  211. package/src/rules-store.js +8 -0
  212. package/src/safe-fetch.js +215 -0
  213. package/src/sender-auth.js +270 -0
  214. package/src/site-match.js +77 -0
  215. package/src/tui-agenda.js +266 -0
  216. package/src/tui.js +670 -0
  217. package/src/vmc.js +376 -0
  218. package/src/wake.js +96 -0
  219. package/src/web-access.js +185 -0
  220. package/src/web-server.js +241 -0
  221. package/src/web-service.js +152 -0
package/src/otp.js ADDED
@@ -0,0 +1,6 @@
1
+ // A verification code in a mail (the core's detector, src/core/otp.js), with mail's plain text (mailcore's).
2
+
3
+ import { plainText } from 'mailcore';
4
+ import { makeFindCode } from './core/otp.js';
5
+
6
+ export const findCode = makeFindCode(plainText);
@@ -0,0 +1,273 @@
1
+ // What the panel can ask of this Mac, whatever carries the asking: the ops, and
2
+ // the pushes that tell it something changed. Two wires use them: Chrome's
3
+ // native messaging (src/bridge.js, the extension) and HTTP on this computer
4
+ // (src/web-server.js, the web app).
5
+ //
6
+ // Ops are the functions of src/ops.js (reads, mark read, drafts, send, and
7
+ // the rules and quiet hours of rules.yaml), of src/connections.js (the
8
+ // accounts, and their Google sign-in) and of src/notes.js (the notes; a
9
+ // change of one is pushed as the event { type: 'notes', id }).
10
+ // runOp(op, args) → { ok: true, result } | { ok: false, error }
11
+ // and, for the web app only, the AI models kept on this Mac (src/ai.js).
12
+ // Pushes, as `follow(send, after)` hands them out until its stop is called:
13
+ // { push: 'event', event } a daemon event (newmail, …)
14
+ // { push: 'gap', lost, oldest } events were missed: reload
15
+ // { push: 'daemon', up, error? } the daemon came or went
16
+ // Events come from two places: the daemon's cursor-backed queue (new mail:
17
+ // nothing is missed across a reconnect) and its live socket (`drafts`: a
18
+ // hint to reload, worth nothing later, so it is not queued).
19
+
20
+ import net from 'node:net';
21
+ import { pollEvents, currentCursor, EVENTS_SOCK } from './events.js';
22
+ import * as ops from './ops.js';
23
+ import { findCode } from './otp.js';
24
+ import { connections } from './connections.js';
25
+ import * as notes from './notes.js';
26
+
27
+ /**
28
+ * A mail opened in the panel, with the verification code it brings (otp.js), whatever its age: the panel offers it
29
+ * under the sender, saying when it is likely expired. (A listing has codes only on mail of the last minutes: those
30
+ * are the ones a page waits for.)
31
+ */
32
+ export function withCode(m) {
33
+ if (!m || typeof m !== 'object' || m.code) return m;
34
+ try {
35
+ const code = findCode(m.subject, m.body);
36
+ return code ? { ...m, code } : m;
37
+ } catch {
38
+ return m;
39
+ }
40
+ }
41
+
42
+ export const OPS = {
43
+ hello: async () => ({ service: 'sideora', protocol: 3, accounts: ops.listAccounts() }),
44
+ accounts: async () => ops.listAccounts(),
45
+ list: ops.listMail,
46
+ search: ops.searchMail,
47
+ read: async (a) => withCode(await ops.readMail(a)),
48
+ thread: ops.thread,
49
+ attachment: ops.attachment,
50
+ attachedMail: async (a) => withCode(await ops.attachedMail(a)),
51
+ attachmentAt: ops.attachmentAt,
52
+ whoami: ops.whoami,
53
+ contacts: ops.contacts,
54
+ contactBooks: ops.contactBooks,
55
+ addContact: ops.addContact,
56
+ files: ops.files,
57
+ events: ops.events,
58
+ event: ops.event,
59
+ respondToEvent: ops.respondToEvent,
60
+ saveEvent: ops.saveEvent,
61
+ deleteEvent: ops.deleteEvent,
62
+ markRead: ops.markRead,
63
+ flag: ops.flag,
64
+ move: ops.move,
65
+ saveDraft: ops.saveDraft,
66
+ draft: ops.readDraft,
67
+ addAttachment: ops.addAttachment,
68
+ removeAttachment: ops.removeAttachment,
69
+ sendDraft: ops.sendDraft,
70
+ deleteDraft: ops.deleteDraft,
71
+ rules: async () => ops.rules(),
72
+ saveRule: async (a) => ops.saveRule(a),
73
+ removeRule: async (a) => ops.removeRule(a),
74
+ moveRule: async (a) => ops.moveRule(a),
75
+ setQuietHours: async (a) => ops.setQuietHours(a),
76
+ playSound: async (a) => ops.playSound(a),
77
+ myDay: ops.myDay,
78
+ people: ops.people,
79
+ person: ops.person,
80
+ accountSettings: async () => connections.doc(),
81
+ testAccount: async (a) => connections.test({ spec: a?.spec, password: a?.password, onePassword: link(a?.onePassword) }),
82
+ addAccount: async (a) => connections.add({ name: a?.name, label: a?.label, spec: a?.spec, password: a?.password, onePassword: link(a?.onePassword) }),
83
+ editAccount: async (a) => connections.edit({ name: a?.name, label: a?.label, spec: a?.spec, password: a?.password, onePassword: link(a?.onePassword), was: a?.was }),
84
+ // 1Password items whose websites match the account's servers or address: titles, vaults, websites, IDs (never a secret)
85
+ onePasswordItems: async (a) => connections.onePasswordItems({ server: a?.server, email: a?.email, smtp: a?.smtp }),
86
+ removeAccount: async (a) => connections.remove({ name: a?.name }),
87
+ setDefaultAccount: async (a) => connections.setDefault({ name: a?.name }),
88
+ // Google sign-in of an account with a Google calendar (or a Gmail mailbox getting one: connect): the panel names the
89
+ // account only, gets the consent page's address to open, then asks how it went. The tokens stay on this side.
90
+ googleSignInStart: async (a) => connections.googleSignIn.start({ account: a?.account, connect: a?.connect === true }),
91
+ googleSignInStatus: async (a) => connections.googleSignIn.status({ account: a?.account }),
92
+ googleSignInCancel: async (a) => connections.googleSignIn.cancel({ account: a?.account }),
93
+ microsoftSignInStart: async (a) => (await import('./microsoft-signin.js')).startSignIn({ label: typeof a?.label === 'string' ? a.label.trim() : undefined, via: a?.via === 'relay' ? 'relay' : 'local' }),
94
+ microsoftSignInStatus: async () => (await import('./microsoft-signin.js')).signInStatus(),
95
+ microsoftSignInCancel: async () => (await import('./microsoft-signin.js')).cancelSignIn(),
96
+ // (only what the page says is passed on: never a file, a key store or a way to fetch)
97
+ relaySettings: async () => (await import('./relay-settings.js')).relaySettings(),
98
+ relayJoin: async (a) => (await import('./relay-settings.js')).joinFromSettings(a?.code ? { url: String(a?.url ?? ''), code: String(a.code) } : { invitation: String(a?.invitation ?? '') }),
99
+ relayPairLink: async (a) => (await import('./relay-settings.js')).pairFromSettings({ limited: a?.limited === true }),
100
+ relayPairStatus: async (a) => (await import('./relay-settings.js')).pairStatus({ ref: String(a?.ref ?? '') }),
101
+ relayPairCancel: async (a) => (await import('./relay-settings.js')).cancelPairing({ ref: String(a?.ref ?? '') }),
102
+ relayForget: async (a) => (await import('./relay-settings.js')).forgetFromSettings({ id: String(a?.id ?? '') }),
103
+ relayAdmin: async (a) => (await import('./relay-settings.js')).adminFromSettings({ id: String(a?.id ?? ''), on: a?.on !== false }),
104
+ relayMove: async (a) => (await import('./relay-settings.js')).moveFromSettings({ url: String(a?.url ?? '') }),
105
+ relayRequest: async (a) => (await import('./relay-settings.js')).requestFromSettings({ url: String(a?.url ?? ''), name: a?.name, email: a?.email, note: a?.note }),
106
+ relayRequestConfirm: async (a) => (await import('./relay-settings.js')).confirmFromSettings({ code: String(a?.code ?? '') }),
107
+ relayRequestResend: async () => (await import('./relay-settings.js')).resendFromSettings(),
108
+ relayRequestCheck: async () => (await import('./relay-settings.js')).checkFromSettings(),
109
+ relayRequestCancel: async () => (await import('./relay-settings.js')).cancelRequestFromSettings(),
110
+ relayLeave: async (a) => (await import('./relay-settings.js')).leaveFromSettings({ force: a?.force === true }),
111
+ signatures: async () => ops.signatures(),
112
+ saveSignature: async (a) => ops.saveSignature(a),
113
+ removeSignature: async (a) => ops.removeSignature(a),
114
+ setSignatureDetails: async (a) => ops.setSignatureDetails(a),
115
+ setIdentity: async (a) => ops.setIdentity(a),
116
+ senderPictures: ops.senderPictures,
117
+ pictureSettings: async () => ops.pictureSettings(),
118
+ setPictureSettings: async (a) => ops.setPictureSettings({ enabled: a?.enabled, gravatar: a?.gravatar, otherIcons: a?.otherIcons }),
119
+ calendarView: async () => ops.calendarView(),
120
+ setCalendarView: async (a) => ops.setCalendarView({ hidden: a?.hidden }),
121
+ // notes (src/notes.js): kept on this Mac; the whole text saved by revision, or one thing added or ticked as the note is now
122
+ notes: async (a) => notes.listNotes({ q: a?.q }),
123
+ note: async (a) => notes.readNote({ id: a?.id }),
124
+ saveNote: async (a) => notes.saveNote(a),
125
+ addToNote: async (a) => notes.addToNote(a),
126
+ tickNote: async (a) => notes.tickNote(a),
127
+ unlinkNote: async (a) => notes.unlinkNote({ id: a?.id, link: a?.link }),
128
+ noteChanges: async (a) => notes.noteChanges({ id: a?.id, since: a?.since }),
129
+ removeNote: async (a) => notes.removeNote({ id: a?.id }),
130
+ restoreNote: async (a) => notes.restoreNote({ id: a?.id }),
131
+ addNotePicture: async (a) => notes.addNotePicture({ data: a?.data }),
132
+ notePicture: async (a) => notes.notePicture({ id: a?.id }),
133
+ fetchNotePicture: async (a) => notes.fetchNotePicture({ url: a?.url }),
134
+ // the assistant's chats (src/chats.js): kept on this Mac, the whole chat saved by revision
135
+ chats: async () => (await import('./chats.js')).listChats(),
136
+ chat: async (a) => (await import('./chats.js')).readChat({ id: a?.id }),
137
+ saveChat: async (a) => (await import('./chats.js')).saveChat(a),
138
+ removeChat: async (a) => (await import('./chats.js')).removeChat({ id: a?.id }),
139
+ // a file attached to a question of a chat: kept once, by what it holds; given back to be shown (or to the extension's worker, which asks the model itself)
140
+ addChatFile: async (a) => (await import('./chats.js')).addChatFile({ data: a?.data }),
141
+ chatFile: async (a) => (await import('./chats.js')).chatFile({ id: a?.id }),
142
+ // AI models kept and asked on this Mac (src/ai.js), by the hub alone (src/hub.js: HUB_ONLY). Loaded when first asked for.
143
+ aiMessage: async (a, ctx) => (await import('./ai.js')).aiMessage(a, ctx),
144
+ aiChat: async (a, ctx) => (await import('./ai.js')).aiChat(a, ctx),
145
+ // the extension's way to the web app it shows in its pages (extension/src/shell/shell.ts): where it is served, and
146
+ // with `pair`, a code that pairs the frame (the extension's alone: not served on the web, nor through the relay)
147
+ webEntry: async (a) => {
148
+ const access = await import('./web-access.js');
149
+ const port = access.notedPort();
150
+ const down = 'the web app is not running on this computer: start it with `sideora web install`';
151
+ if (!port) throw new Error(down);
152
+ // (a port noted by a server that stopped since: said, rather than a frame of a page that does not load)
153
+ const net = await import('node:net');
154
+ const up = await new Promise((resolve) => { const c = net.connect(port, '127.0.0.1'); const t = setTimeout(() => { c.destroy(); resolve(false); }, 1500); c.once('connect', () => { clearTimeout(t); c.destroy(); resolve(true); }); c.once('error', () => { clearTimeout(t); resolve(false); }); });
155
+ if (!up) throw new Error(down);
156
+ return { url: `http://127.0.0.1:${port}`, ...(a?.pair === true ? { code: access.newPairingCode(Date.now(), 'extension').code } : {}) };
157
+ },
158
+ // the assistant's answers, run by the hub (src/assistant-runs.js, over src/core/assistant.js): started, followed, a web search allowed, stopped
159
+ assistantStart: async (a) => (await import('./assistant-runs.js')).assistantStart(a),
160
+ assistantWait: async (a, ctx) => (await import('./assistant-runs.js')).assistantWait(a, ctx),
161
+ assistantAnswer: async (a) => (await import('./assistant-runs.js')).assistantAnswer(a),
162
+ assistantStop: async (a) => (await import('./assistant-runs.js')).assistantStop(a)
163
+ };
164
+
165
+ /** A 1Password item as the panel names it: its two IDs, nothing else passed on. */
166
+ function link(v) {
167
+ if (v == null) return undefined;
168
+ return { vaultId: typeof v.vaultId === 'string' ? v.vaultId : '', itemId: typeof v.itemId === 'string' ? v.itemId : '' };
169
+ }
170
+
171
+ /** The ops of the web app alone: its server's process is the one that holds what they keep (src/ai.js); the bridge serves none of them (src/op-registry.js). */
172
+ export { WEB_ONLY } from './op-registry.js';
173
+
174
+ /** Run one op. Never throws: a failure is the answer. `ctx.signal`: whoever asked let go (an op that waits long stops then). */
175
+ export async function runOp(op, args, ops = OPS, ctx = {}) {
176
+ const fn = typeof op === 'string' && Object.hasOwn(ops, op) ? ops[op] : null;
177
+ if (!fn) return { ok: false, error: `unknown op "${op}"` };
178
+ try {
179
+ return { ok: true, result: await fn(args || {}, ctx) };
180
+ } catch (e) {
181
+ return { ok: false, error: e?.message || String(e) };
182
+ }
183
+ }
184
+
185
+ // --- daemon events → pushes ---------------------------------------------------
186
+
187
+ // what the long-poll below does not hand over without being asked: a draft changed, the calendar changed, an event is about to start
188
+ const LIVE_ONLY = ['drafts', 'calendar', 'reminder', 'mailchanged'];
189
+
190
+ /**
191
+ * Tell `send` of everything the panel is pushed, from the event after `after`
192
+ * (a cursor; none: from now). A push out of the daemon's queue comes with its
193
+ * cursor (`send(push, cursor)`): what to give as `after` to miss nothing after
194
+ * it. `checkpoint(cursor)`, when given, is told where the queue stands whenever that is known and nothing was sent
195
+ * for it (as the feed starts, after a wait that brought nothing): a listener that comes back gives its last cursor
196
+ * and misses nothing, whether or not an event ever reached it. Returns how to stop: nothing is sent after it, and
197
+ * nothing is left running.
198
+ */
199
+ export function follow(send, after, { checkpoint } = {}) {
200
+ const stop = new AbortController();
201
+ const out = (msg, cursor) => { if (!stop.signal.aborted) send(msg, cursor); };
202
+ const at = (cursor) => { if (!stop.signal.aborted && checkpoint && Number.isFinite(cursor)) checkpoint(cursor); };
203
+ const sleep = (ms) => new Promise((done) => {
204
+ const end = () => { clearTimeout(t); stop.signal.removeEventListener('abort', end); done(); };
205
+ const t = setTimeout(end, ms);
206
+ stop.signal.addEventListener('abort', end, { once: true });
207
+ });
208
+ followLive(out, stop.signal);
209
+ // a note changed, by this panel, another browser's, or a tool: no daemon is needed to tell of it
210
+ const unwatch = notes.watchNotes((id) => out({ push: 'event', event: { type: 'notes', id } }));
211
+ stop.signal.addEventListener('abort', unwatch, { once: true });
212
+ (async () => {
213
+ let cursor = Number.isFinite(Number(after)) && after != null && after !== '' ? Number(after) : 'now';
214
+ let up = null;
215
+ let delay = 5000;
216
+ while (!stop.signal.aborted) {
217
+ try {
218
+ // a long-poll answers only when mail arrives, so ask something quick first:
219
+ // otherwise "the daemon is back" would wait minutes for the next event
220
+ if (up !== true) {
221
+ const now = await currentCursor(stop.signal);
222
+ if (cursor === 'now' && Number.isFinite(now)) cursor = now; // "from now" is from here, whenever the first wait starts
223
+ up = true; delay = 5000;
224
+ out({ push: 'daemon', up: true });
225
+ at(cursor);
226
+ }
227
+ const r = await pollEvents({ after: cursor, timeout: 300, match: 'all', signal: stop.signal });
228
+ if (r.gap) out({ push: 'gap', lost: r.lost, oldest: r.oldest });
229
+ for (const event of r.events || []) out({ push: 'event', event }, event.seq);
230
+ if (r.cursor != null) { cursor = r.cursor; at(cursor); }
231
+ } catch (e) {
232
+ if (stop.signal.aborted) return;
233
+ // a restart is not an outage: look again once before telling the panel
234
+ if (up === true) { up = null; await sleep(3000); continue; }
235
+ if (up !== false) { up = false; out({ push: 'daemon', up: false, error: e.message }); }
236
+ await sleep(delay);
237
+ delay = Math.min(delay * 2, 60000);
238
+ }
239
+ }
240
+ })();
241
+ return () => stop.abort();
242
+ }
243
+
244
+ /** Forward the live-only events the panel cares about; reconnect quietly when the daemon restarts. */
245
+ function followLive(send, signal) {
246
+ if (signal.aborted) return;
247
+ let pending = '';
248
+ let again;
249
+ const sock = net.connect(EVENTS_SOCK);
250
+ const end = () => { clearTimeout(again); sock.destroy(); };
251
+ signal.addEventListener('abort', end, { once: true });
252
+ sock.setEncoding('utf8');
253
+ sock.on('data', (chunk) => {
254
+ pending += chunk;
255
+ let at;
256
+ while ((at = pending.indexOf('\n')) >= 0) {
257
+ const line = pending.slice(0, at);
258
+ pending = pending.slice(at + 1);
259
+ try {
260
+ const event = JSON.parse(line);
261
+ if (LIVE_ONLY.includes(event.type)) send({ push: 'event', event });
262
+ } catch { /* not a full JSON line: skip it */ }
263
+ }
264
+ });
265
+ sock.on('error', () => {}); // 'close' follows
266
+ sock.on('close', () => {
267
+ signal.removeEventListener('abort', end);
268
+ if (signal.aborted) return;
269
+ const drop = () => clearTimeout(again);
270
+ again = setTimeout(() => { signal.removeEventListener('abort', drop); followLive(send, signal); }, 10000);
271
+ signal.addEventListener('abort', drop, { once: true });
272
+ });
273
+ }