langmail-mcp 0.0.0 → 0.2.0

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 (138) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +89 -169
  3. package/dist/chunk-0fxfqny0.js +12642 -0
  4. package/dist/langmail-mcp.js +7 -0
  5. package/package.json +93 -98
  6. package/THIRD_PARTY_NOTICES.md +0 -388
  7. package/dist/attachments/download.js +0 -69
  8. package/dist/attachments/routes.js +0 -42
  9. package/dist/attachments/tickets.js +0 -45
  10. package/dist/attachments/upload-tickets.js +0 -43
  11. package/dist/attachments/upload.js +0 -136
  12. package/dist/caldav/account-settings.js +0 -92
  13. package/dist/caldav/agenda.js +0 -277
  14. package/dist/caldav/alarm.js +0 -97
  15. package/dist/caldav/client.js +0 -408
  16. package/dist/caldav/ical.js +0 -248
  17. package/dist/caldav/occurrence.js +0 -534
  18. package/dist/caldav/recurrence.js +0 -313
  19. package/dist/caldav/rsvp.js +0 -107
  20. package/dist/caldav/scheduling-handover.js +0 -22
  21. package/dist/caldav/timezone.js +0 -103
  22. package/dist/caldav/types.js +0 -5
  23. package/dist/config.js +0 -219
  24. package/dist/contacts/address-class.js +0 -79
  25. package/dist/contacts/birthdays.js +0 -81
  26. package/dist/contacts/card.js +0 -58
  27. package/dist/contacts/constants.js +0 -46
  28. package/dist/contacts/fold.js +0 -309
  29. package/dist/contacts/index.js +0 -10
  30. package/dist/contacts/merge.js +0 -388
  31. package/dist/contacts/observations.js +0 -115
  32. package/dist/contacts/profile.js +0 -402
  33. package/dist/contacts/scoring.js +0 -146
  34. package/dist/contacts/types.js +0 -7
  35. package/dist/contacts/upsert.js +0 -131
  36. package/dist/drafts/attachments.js +0 -254
  37. package/dist/drafts/idempotency.js +0 -60
  38. package/dist/drafts/send-guard.js +0 -184
  39. package/dist/email-render/email-viewer.html +0 -143
  40. package/dist/email-render/image-proxy.js +0 -389
  41. package/dist/email-render/meta.js +0 -48
  42. package/dist/email-render/sanitize.js +0 -93
  43. package/dist/email-render/viewer-resource.js +0 -104
  44. package/dist/http/bearer.js +0 -30
  45. package/dist/http/guard.js +0 -57
  46. package/dist/http/hosts.js +0 -10
  47. package/dist/http/listener.js +0 -170
  48. package/dist/http/routes.js +0 -72
  49. package/dist/ical/ical-parse.js +0 -357
  50. package/dist/ical/index.js +0 -4
  51. package/dist/ical/timezone.js +0 -22
  52. package/dist/ical/windows-zones.js +0 -155
  53. package/dist/index.js +0 -79
  54. package/dist/jmap/blob.js +0 -49
  55. package/dist/jmap/contacts.js +0 -226
  56. package/dist/jmap/drafts.js +0 -480
  57. package/dist/jmap/email.js +0 -668
  58. package/dist/jmap/index.js +0 -12
  59. package/dist/jmap/keywords.js +0 -22
  60. package/dist/jmap/live.js +0 -21
  61. package/dist/jmap/origin.js +0 -113
  62. package/dist/jmap/patch.js +0 -29
  63. package/dist/jmap/request.js +0 -37
  64. package/dist/jmap/session.js +0 -89
  65. package/dist/jmap/sieve.js +0 -71
  66. package/dist/jmap/submission.js +0 -107
  67. package/dist/jmap/timeout.js +0 -30
  68. package/dist/jmap/types.js +0 -6
  69. package/dist/logger.js +0 -48
  70. package/dist/mcp/handler.js +0 -255
  71. package/dist/mcp/http.js +0 -29
  72. package/dist/mcp/instructions.js +0 -44
  73. package/dist/mcp/links.js +0 -64
  74. package/dist/mcp/test-client.js +0 -43
  75. package/dist/mcp/tool-logging.js +0 -67
  76. package/dist/observability/errors.js +0 -41
  77. package/dist/rules/apply.js +0 -236
  78. package/dist/rules/rule.js +0 -280
  79. package/dist/rules/store.js +0 -92
  80. package/dist/tools/annotations.js +0 -71
  81. package/dist/tools/archive-emails.js +0 -40
  82. package/dist/tools/calendar-lookup.js +0 -64
  83. package/dist/tools/contact-common.js +0 -146
  84. package/dist/tools/contact-format.js +0 -72
  85. package/dist/tools/contact-write-through.js +0 -37
  86. package/dist/tools/create-calendar-event.js +0 -231
  87. package/dist/tools/create-calendar.js +0 -54
  88. package/dist/tools/create-contact.js +0 -172
  89. package/dist/tools/create-draft.js +0 -369
  90. package/dist/tools/create-mail-rule.js +0 -101
  91. package/dist/tools/delete-calendar-event.js +0 -165
  92. package/dist/tools/delete-contact.js +0 -60
  93. package/dist/tools/delete-draft.js +0 -129
  94. package/dist/tools/delete-mail-rule.js +0 -38
  95. package/dist/tools/download-attachment.js +0 -90
  96. package/dist/tools/download-email.js +0 -112
  97. package/dist/tools/draft-common.js +0 -600
  98. package/dist/tools/email-types.js +0 -58
  99. package/dist/tools/error-detail.js +0 -10
  100. package/dist/tools/file-emails-common.js +0 -75
  101. package/dist/tools/format.js +0 -131
  102. package/dist/tools/forward-message.js +0 -237
  103. package/dist/tools/forward-quote.js +0 -179
  104. package/dist/tools/get-draft.js +0 -61
  105. package/dist/tools/get-email.js +0 -164
  106. package/dist/tools/get-thread.js +0 -67
  107. package/dist/tools/keywords.js +0 -43
  108. package/dist/tools/list-calendar-events.js +0 -180
  109. package/dist/tools/list-calendars.js +0 -44
  110. package/dist/tools/list-drafts.js +0 -134
  111. package/dist/tools/list-mail-rules.js +0 -28
  112. package/dist/tools/list-unsubscribe.js +0 -152
  113. package/dist/tools/list-upcoming-birthdays.js +0 -165
  114. package/dist/tools/mail-rule-common.js +0 -43
  115. package/dist/tools/mail-rule-format.js +0 -79
  116. package/dist/tools/mailbox-lookup.js +0 -13
  117. package/dist/tools/mark-emails.js +0 -78
  118. package/dist/tools/merge-contacts.js +0 -145
  119. package/dist/tools/move-calendar-events.js +0 -340
  120. package/dist/tools/move-emails.js +0 -64
  121. package/dist/tools/one-click-post.js +0 -275
  122. package/dist/tools/preview-email.js +0 -204
  123. package/dist/tools/preview-mail-rule.js +0 -79
  124. package/dist/tools/reply-quote.js +0 -426
  125. package/dist/tools/reply-to-message.js +0 -292
  126. package/dist/tools/respond-to-event.js +0 -110
  127. package/dist/tools/result.js +0 -9
  128. package/dist/tools/search-contacts.js +0 -431
  129. package/dist/tools/search-emails.js +0 -570
  130. package/dist/tools/send-draft.js +0 -308
  131. package/dist/tools/trash-emails.js +0 -36
  132. package/dist/tools/unsubscribe-from-list.js +0 -249
  133. package/dist/tools/update-calendar-event.js +0 -973
  134. package/dist/tools/update-calendar.js +0 -100
  135. package/dist/tools/update-contact.js +0 -382
  136. package/dist/tools/update-draft.js +0 -714
  137. package/dist/tools/update-mail-rule.js +0 -103
  138. package/dist/tools/upload-attachments.js +0 -126
@@ -1,309 +0,0 @@
1
- // The collection fold: observations in, card mutations out. Pure — no IO —
2
- // so every writer (the calendar tools, anything that folds mail) shares one
3
- // exhaustively tested core, and the thin upsert helper only has
4
- // to apply the returned creates, updates and the destroys each update names
5
- // over JMAP.
6
- //
7
- // Ownership rules enforced here: standard card properties belong to the
8
- // user — collection fills blanks (a missing display name, a missing
9
- // address) but never overwrites a non-empty value; the extension property
10
- // is machine-owned and updated freely. Cards already holding an observed
11
- // address — personal-book contacts included — are updated in place, never
12
- // duplicated into the collected book. When a personal-book card and a
13
- // Collected card both hold an observed address (an import of a person
14
- // collection already knew), the Collected card's history is merged into the
15
- // personal card and the Collected card is destroyed, so one address resolves
16
- // to one person.
17
- import { classifyContext, normalizeAddress } from "./address-class.js";
18
- import { cardAddresses, collectedNoteEntry, collectedUid, nextEmailKey, normalizeName, readCollected, } from "./card.js";
19
- import { COLLECTED_NOTE_KEY, COLLECTED_PATCH_PATH, INTERACTION_LOG_SIZE, RELAY_LIST_SIZE, } from "./constants.js";
20
- import { mergeCollectedExtensions } from "./merge.js";
21
- const CONFIDENCE_RANK = {
22
- confirmed: 2,
23
- strong: 1,
24
- weak: 0,
25
- };
26
- const time = (iso) => new Date(iso).getTime();
27
- const addAddress = (w, address) => {
28
- w.emails[nextEmailKey(w.emails)] = {
29
- address,
30
- contexts: { [classifyContext(address)]: true },
31
- };
32
- w.addresses.add(address);
33
- w.changedEmails = true;
34
- };
35
- const apply = (w, obs) => {
36
- const address = normalizeAddress(obs.address);
37
- if (!w.addresses.has(address)) {
38
- addAddress(w, address);
39
- }
40
- const entry = w.ext.addresses[address];
41
- // The interaction log doubles as a short-range dedup window: re-folding a
42
- // record already in the log (a retried poll batch) upgrades confidence at
43
- // most — it never double-counts. Re-runs older than the window still
44
- // inflate counters; accepted MVP gap, documented in the plan.
45
- const alreadyLogged = w.ext.interactions.some((t) => t.recordId === obs.recordId);
46
- if (entry) {
47
- if (CONFIDENCE_RANK[obs.confidence] > CONFIDENCE_RANK[entry.confidence]) {
48
- entry.confidence = obs.confidence;
49
- w.touched = true;
50
- }
51
- if (!alreadyLogged) {
52
- entry.count += 1;
53
- if (time(obs.date) > time(entry.lastSeen)) {
54
- entry.lastSeen = obs.date;
55
- }
56
- if (time(obs.date) < time(entry.firstSeen)) {
57
- entry.firstSeen = obs.date;
58
- }
59
- }
60
- }
61
- else {
62
- w.ext.addresses[address] = {
63
- confidence: obs.confidence,
64
- count: alreadyLogged ? 0 : 1,
65
- firstSeen: obs.date,
66
- lastSeen: obs.date,
67
- };
68
- w.touched = true;
69
- }
70
- if (!alreadyLogged) {
71
- w.ext.interactions.push({
72
- channel: obs.channel,
73
- date: obs.date,
74
- direction: obs.direction,
75
- recordId: obs.recordId,
76
- });
77
- w.ext.interactions.sort((a, b) => time(b.date) - time(a.date));
78
- w.ext.interactions = w.ext.interactions.slice(0, INTERACTION_LOG_SIZE);
79
- w.touched = true;
80
- }
81
- if (!w.name && obs.name) {
82
- w.name = obs.name;
83
- w.changedName = true;
84
- w.touched = true;
85
- }
86
- w.recordIds.add(obs.recordId);
87
- };
88
- // Merges a Collected card into a personal card and marks it for destroy. Its
89
- // addresses join the personal card, as collection does for any blank it
90
- // fills; so does the name if the personal card has none. A card already
91
- // listed in `absorbed` was merged by an earlier fold whose destroy never
92
- // landed: its history is not summed again, but anything added to it since
93
- // (an address) still moves over.
94
- const absorb = (into, from, fromEmails) => {
95
- into.absorbs.push(from.id ?? "");
96
- into.touched = true;
97
- into.ext = mergeCollectedExtensions(into.ext, from.ext, from.id ?? "");
98
- for (const entry of Object.values(fromEmails)) {
99
- const address = normalizeAddress(entry.address);
100
- if (!into.addresses.has(address)) {
101
- into.emails[nextEmailKey(into.emails)] = entry;
102
- into.addresses.add(address);
103
- into.changedEmails = true;
104
- }
105
- }
106
- if (!into.name && from.name) {
107
- into.name = from.name;
108
- into.changedName = true;
109
- }
110
- };
111
- // The properties a card collection minted carries: what the fold writes, and
112
- // the metadata the server and RFC 9553 add. Anything else on a Collected
113
- // card (a phone, a birthday, a photo, a nickname) was put there by a person.
114
- const COLLECTION_PROPERTIES = new Set([
115
- "@type",
116
- "addressBookIds",
117
- "created",
118
- "emails",
119
- "id",
120
- "kind",
121
- "name",
122
- "notes",
123
- "prodId",
124
- "uid",
125
- "updated",
126
- "version",
127
- ]);
128
- // A Collected card collection can merge away: in the Collected book only,
129
- // and carrying nothing a person put there. A detail added through
130
- // update_contact or a CardDAV client would be lost with the card, so such a
131
- // pair stays. An allow-list, because the card comes back from the server
132
- // with every JSContact property it holds, typed or not.
133
- const isDisposable = (card, collectedBookId) => {
134
- const books = Object.keys(card.addressBookIds).filter((id) => card.addressBookIds[id]);
135
- const filled = Object.entries(card).filter(([, value]) => value !== null && value !== undefined);
136
- return (books.length === 1 &&
137
- books[0] === collectedBookId &&
138
- filled.every(([key]) => COLLECTION_PROPERTIES.has(key)) &&
139
- Object.keys(card.notes ?? {}).every((key) => key === COLLECTED_NOTE_KEY));
140
- };
141
- // The conservative merge gate: a new address may join an existing person
142
- // only on an exact normalized display-name match PLUS co-occurrence — the
143
- // same record also sighted an address already belonging to that person.
144
- const canJoin = (w, obs, recordAddresses) => {
145
- if (!(obs.name && w.name) ||
146
- normalizeName(obs.name) !== normalizeName(w.name)) {
147
- return false;
148
- }
149
- const cooccurring = recordAddresses.get(obs.recordId);
150
- if (!cooccurring) {
151
- return false;
152
- }
153
- for (const a of w.addresses) {
154
- if (cooccurring.has(a) && a !== normalizeAddress(obs.address)) {
155
- return true;
156
- }
157
- }
158
- return false;
159
- };
160
- // For each observed address held by both a card outside the Collected book
161
- // (or a Collected card merge_contacts merged others into) and one or more
162
- // disposable Collected cards, absorbs the Collected cards into the first
163
- // such personal card. Returns the cards still in play; each
164
- // personal card lists the ones it absorbed, for the caller to destroy.
165
- const mergeCollectedTwins = (ctx, cards, observations) => {
166
- const byId = new Map(ctx.cards.map((c) => [c.id, c]));
167
- const inCollected = (w) => (byId.get(w.id ?? "")?.addressBookIds[ctx.collectedBookId] ?? false) ===
168
- true;
169
- let kept = cards;
170
- for (const address of new Set(observations.map((o) => normalizeAddress(o.address)))) {
171
- const holders = kept.filter((w) => w.addresses.has(address));
172
- // A Collected card that merge_contacts folded others into counts as a
173
- // target too: in the moment before the index catches up with a merge, a
174
- // sighting of a merged address mints a fresh Collected card, which the
175
- // next batch then folds back into the card the user chose.
176
- // Only when exactly one holder is such a card: two of them sharing an
177
- // address are two choices the user made, not a duplicate to clear.
178
- const mergeTargets = holders.filter((w) => (w.ext.absorbed?.length ?? 0) > 0);
179
- const personal = holders.find((w) => !inCollected(w)) ??
180
- (mergeTargets.length === 1 ? mergeTargets[0] : undefined);
181
- if (!personal) {
182
- continue;
183
- }
184
- const disposable = holders.filter((w) => {
185
- const card = byId.get(w.id ?? "");
186
- return (w !== personal &&
187
- card !== undefined &&
188
- isDisposable(card, ctx.collectedBookId));
189
- });
190
- // A Collected card that shares an address with yet another card stays:
191
- // its history for that address belongs to neither card alone, and a
192
- // merge writes to the personal card only, so nothing has to be split.
193
- const survivors = kept.filter((w) => w !== personal && !disposable.includes(w));
194
- const doomed = disposable.filter((w) => [...w.addresses].every((a) => personal.addresses.has(a) ||
195
- !survivors.some((s) => s.addresses.has(a))));
196
- kept = kept.filter((w) => !doomed.includes(w));
197
- for (const collected of doomed) {
198
- absorb(personal, collected, byId.get(collected.id ?? "")?.emails ?? {});
199
- }
200
- }
201
- return kept;
202
- };
203
- export const foldObservations = (ctx, observations, relays = []) => {
204
- const initial = ctx.cards.map((card) => ({
205
- absorbs: [],
206
- addresses: new Set(cardAddresses(card)),
207
- changedEmails: false,
208
- changedName: false,
209
- emails: { ...(card.emails ?? {}) },
210
- ext: readCollected(card),
211
- hasNotes: typeof card.notes === "object" && card.notes !== null,
212
- id: card.id,
213
- ...(card.name?.full ? { name: card.name.full } : {}),
214
- recordIds: new Set(),
215
- touched: false,
216
- }));
217
- // A personal-book card and a Collected card holding the same observed
218
- // address are one person: the personal card takes the history first, so
219
- // this batch's observations land on it, and the Collected card goes.
220
- const existing = mergeCollectedTwins(ctx, initial, observations);
221
- const drafts = [];
222
- const all = () => [...existing, ...drafts];
223
- // Which addresses each record sighted — the co-occurrence half of the
224
- // merge gate (relay and self addresses are already extracted away).
225
- const recordAddresses = new Map();
226
- for (const obs of observations) {
227
- const set = recordAddresses.get(obs.recordId) ?? new Set();
228
- set.add(normalizeAddress(obs.address));
229
- recordAddresses.set(obs.recordId, set);
230
- }
231
- // Oldest first, so firstSeen/lastSeen and the log settle deterministically.
232
- const ordered = [...observations].sort((a, b) => time(a.date) - time(b.date));
233
- for (const obs of ordered) {
234
- const address = normalizeAddress(obs.address);
235
- const holder = all().find((w) => w.addresses.has(address));
236
- if (holder) {
237
- apply(holder, obs);
238
- continue;
239
- }
240
- const joinable = all().find((w) => canJoin(w, obs, recordAddresses));
241
- if (joinable) {
242
- apply(joinable, obs);
243
- continue;
244
- }
245
- const draft = {
246
- absorbs: [],
247
- addresses: new Set(),
248
- changedEmails: false,
249
- changedName: false,
250
- emails: {},
251
- // Stamped at creation and round-tripped by readCollected from then on,
252
- // so a card the collection pipeline minted stays distinguishable from
253
- // one the user authored through the contact tools.
254
- ext: { addresses: {}, interactions: [], source: "derived" },
255
- // Irrelevant for a draft (creates carry `notes` wholesale), but the
256
- // shape is shared with existing cards.
257
- hasNotes: false,
258
- recordIds: new Set(),
259
- touched: true,
260
- };
261
- drafts.push(draft);
262
- apply(draft, obs);
263
- }
264
- // A relay observed alongside a known person lands in that person's
265
- // extension data, so the tool can surface it as excluded. A full list
266
- // keeps its first entries — no write churn once the cap is reached.
267
- for (const relay of relays) {
268
- for (const w of all()) {
269
- if (!w.recordIds.has(relay.recordId)) {
270
- continue;
271
- }
272
- const current = w.ext.relays ?? [];
273
- if (!current.includes(relay.address) &&
274
- current.length < RELAY_LIST_SIZE) {
275
- w.ext.relays = [...current, relay.address];
276
- w.touched = true;
277
- }
278
- }
279
- }
280
- const creates = drafts.map((d) => {
281
- const primary = [...d.addresses][0] ?? "";
282
- return {
283
- addressBookIds: { [ctx.collectedBookId]: true },
284
- emails: d.emails,
285
- notes: { [COLLECTED_NOTE_KEY]: collectedNoteEntry(d.ext) },
286
- ...(d.name ? { name: { full: d.name } } : {}),
287
- uid: collectedUid(primary),
288
- version: "1.0",
289
- };
290
- });
291
- const updates = existing
292
- .filter((w) => w.touched)
293
- .map((w) => ({
294
- absorbs: w.absorbs,
295
- cardId: w.id ?? "",
296
- // The extension rides a scoped patch path so user-authored note
297
- // entries on the same card are never replaced — except on a card
298
- // with no notes at all, where RFC 8620 §5.3 rejects the scoped path
299
- // (missing parent) and a full top-level set is both required and safe.
300
- patch: {
301
- ...(w.hasNotes
302
- ? { [COLLECTED_PATCH_PATH]: collectedNoteEntry(w.ext) }
303
- : { notes: { [COLLECTED_NOTE_KEY]: collectedNoteEntry(w.ext) } }),
304
- ...(w.changedEmails ? { emails: w.emails } : {}),
305
- ...(w.changedName && w.name ? { name: { full: w.name } } : {}),
306
- },
307
- }));
308
- return { creates, updates };
309
- };
@@ -1,10 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: package entry point requires re-exports
2
- export { normalizeAddress } from "./address-class.js";
3
- export { daysUntil, formatCalendarDate, nextOccurrence, parseCalendarDate, todayIn, } from "./birthdays.js";
4
- export { collectedNoteEntry, collectedUid, nextKey, readCollected, } from "./card.js";
5
- export { BIRTHDAY_KEY, COLLECTED_BOOK_NAME, COLLECTED_NOTE_KEY, PERSONAL_BOOK_NAME, SHOWN_INTERACTIONS, USER_NOTE_KEY, } from "./constants.js";
6
- export { mergeCards, withPreferredEmail } from "./merge.js";
7
- export { observationsFromEmail, observationsFromEvent, } from "./observations.js";
8
- export { birthAnniversary, formatBirthday, formatCardAddress, hasRole, isRolePhrase, MAX_ROLES, normalizeRole, parseBirthday, patchCardAddress, readBirthday, readNote, readOrganization, readPhones, readPostalAddresses, readRoles, sourceOf, toCardAddress, toCardPhone, userNoteEntry, userNoteKey, withBirthday, withRoles, } from "./profile.js";
9
- export { addressCandidates, bestAddress, rankCards, relationshipFor, relativeAge, } from "./scoring.js";
10
- export { collectContacts, liveCollectionDeps, } from "./upsert.js";