@flowmails/flowmails-sdk 0.2.0 → 2.0.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.
package/dist/index.d.ts CHANGED
@@ -77,6 +77,29 @@ interface CreateWaitOptions {
77
77
  */
78
78
  timeoutMs?: number;
79
79
  }
80
+ /**
81
+ * How a wait's resolution is delivered besides the poll.
82
+ *
83
+ * The wait's resolution is also delivered as the `wait.resolved`
84
+ * webhook event, on the account's verified outbound webhook — signed,
85
+ * retried and logged. An agent with **no long-running process** (a
86
+ * serverless function, a CI job, a webhook-driven service) therefore
87
+ * does not have to write a polling loop to learn that a mail landed.
88
+ * Polling the wait keeps working either way.
89
+ *
90
+ * ## Why the name is a literal here
91
+ *
92
+ * The SDK is **dependency-free** by design — it is published to npm
93
+ * and the workspace package that holds the contract is private, so
94
+ * this package cannot import the constant the contract file holds.
95
+ *
96
+ * The two are therefore kept in step by a **test**, not by an import:
97
+ * `test/web-agent-sdk-cli-mcp-push-vocabulary.test.mjs` asserts that
98
+ * this string, the CLI's copy and the MCP tool descriptions are all
99
+ * the same value as the shared contract's `AGENT_WAIT_PUSH_EVENT`. A
100
+ * rename is a failing test, not a drift.
101
+ */
102
+ declare const WAIT_RESOLVED_EVENT = "wait.resolved";
80
103
  /** A durable wait, as the platform reports it. */
81
104
  interface WaitStatus {
82
105
  waitId: string;
@@ -89,6 +112,17 @@ interface WaitStatus {
89
112
  resolvedMessageId: string | null;
90
113
  /** ISO-8601 deadline. A wait past it reads as `expired`. */
91
114
  expiresAt: string | number;
115
+ /**
116
+ * How this wait's resolution is also delivered.
117
+ *
118
+ * The event name is the same one the CLI and the MCP tool
119
+ * descriptions name — a client that reads one of them reads the
120
+ * same fact as a client that reads another.
121
+ */
122
+ push?: {
123
+ /** The webhook event this wait's resolution is delivered as. */
124
+ event: typeof WAIT_RESOLVED_EVENT;
125
+ };
92
126
  }
93
127
  /**
94
128
  * A newly-opened wait.
@@ -142,7 +176,10 @@ interface AgentDomain {
142
176
  name: string;
143
177
  routingMode: "catchall" | "rules";
144
178
  localParts: string[];
145
- /** False when the per-account receive worker is not deployed yet. */
179
+ /**
180
+ * False when the domain's route table is not bound in the mail
181
+ * worker yet — its mail is not being accepted.
182
+ */
146
183
  ready: boolean;
147
184
  }
148
185
  /** Result of {@link AgentAddresses.create}. */
@@ -192,6 +229,57 @@ interface ThreadDetail {
192
229
  /** The chain, oldest first. */
193
230
  messages: ThreadMessage[];
194
231
  }
232
+ /**
233
+ * The agent's own record of what it did with one message.
234
+ *
235
+ * The event log says a mail arrived; this says whether the agent
236
+ * already handled it. An agent that restarts reads it back to tell
237
+ * "I never saw this" from "I saw it and never finished".
238
+ */
239
+ interface MessageState {
240
+ /** The SMTP `Message-ID` — the id the event log carried. */
241
+ messageId: string;
242
+ /** The platform domain id whose mailbox received the message. */
243
+ domainId: string;
244
+ /**
245
+ * `pending` → `processing` → `done` | `failed`.
246
+ *
247
+ * The platform records what the agent wrote and never moves a row
248
+ * on its own — there is no rule engine and no sweeper behind it.
249
+ */
250
+ state: "pending" | "processing" | "done" | "failed";
251
+ /** Short labels the agent attached to the message. */
252
+ labels: string[];
253
+ /** A free-text note about what the agent did. */
254
+ note: string | null;
255
+ /** Who holds the claim, when the message is `processing`. */
256
+ claimedBy: string | null;
257
+ /** ISO-8601 timestamp of the claim. */
258
+ claimedAt: string | number | null;
259
+ /** ISO-8601 timestamp of the last write. */
260
+ updatedAt: string | number;
261
+ }
262
+ /** Options for {@link AgentMessages.claim}. */
263
+ interface ClaimMessageOptions {
264
+ /** The platform domain id whose mailbox received the message. */
265
+ domainId: string;
266
+ /**
267
+ * Which worker of yours holds the claim, e.g. `worker-1`.
268
+ * Defaults to the credential.
269
+ */
270
+ claimedBy?: string;
271
+ }
272
+ /** Options for {@link AgentMessages.complete}. */
273
+ interface CompleteMessageOptions {
274
+ /** The platform domain id whose mailbox received the message. */
275
+ domainId: string;
276
+ /** `done` when finished with it, `failed` when it did not succeed. */
277
+ state: "done" | "failed";
278
+ /** Short labels to attach, e.g. `["invoice"]`. */
279
+ labels?: string[];
280
+ /** A short free-text note about what the agent did. */
281
+ note?: string;
282
+ }
195
283
  /**
196
284
  * One search hit.
197
285
  *
@@ -282,6 +370,23 @@ interface SendOptions {
282
370
  html?: string;
283
371
  /** Attachments. */
284
372
  attachments?: SendAttachment[];
373
+ /**
374
+ * Send **one message per recipient** — the default — or one shared
375
+ * message for everybody.
376
+ *
377
+ * `true` (the default): every recipient gets their own message. They
378
+ * cannot see each other, one refused address does not hold up the
379
+ * others, and {@link SendResult.recipients} reports what happened to
380
+ * **each** address. `false`: everybody is on one envelope — one
381
+ * message, one relay call, one bill from a provider that charges per
382
+ * message — and then a single refused address refuses the whole
383
+ * send, because there was only ever one send.
384
+ *
385
+ * The default is per-recipient because a partial failure has to be
386
+ * observable. With one shared envelope the answer is all-or-nothing
387
+ * by construction.
388
+ */
389
+ perRecipient?: boolean;
285
390
  /**
286
391
  * Idempotency key — the same key under the same account and the
287
392
  * same request returns the **original** result and does not send
@@ -306,11 +411,40 @@ interface SendOptions {
306
411
  * the relay assigned, which is the key every read path takes — pass
307
412
  * it to {@link AgentMessages.get} to read a reply, or to
308
413
  * {@link AgentMessages.status} to poll delivery.
414
+ *
415
+ * ## `status` is the send's verdict
416
+ *
417
+ * `status` is the **aggregate** over every recipient:
418
+ *
419
+ * - `"sent"` — everybody was accepted;
420
+ * - `"partial"` — some were accepted and some were refused;
421
+ * - `"failed"` — nobody was accepted.
422
+ *
423
+ * ## A send that failed
424
+ *
425
+ * The backend answers `201` for a send the relay **refused** — the
426
+ * message row exists, the mail does not. That used to be invisible:
427
+ * the answer was `{ id, status: "failed", messageId: "" }` with
428
+ * nothing else, so an agent could not tell a refused send from a
429
+ * lost one (the 2026-10-31 audit, P0-1).
430
+ *
431
+ * Two fields now say what happened:
432
+ *
433
+ * - `error` — the typed slug (`"send_failed"`), or `null` when every
434
+ * recipient was accepted. **It is never `null` on a failed or a
435
+ * partial send**, so "failed with no reason" is not a state the
436
+ * wire can be in, and "check `result.error` before treating a 201
437
+ * as sent" stays true.
438
+ * - `sendFeedback` — the relay's own reason, when it gave one
439
+ * (`null` when it did not).
440
+ *
441
+ * Both are optional because the SDK also talks to older backends that
442
+ * did not send them; on those, `status` is the only signal.
309
443
  */
310
444
  interface SendResult {
311
445
  /** Numeric email row id (stringified for JSON safety). */
312
446
  id: string;
313
- /** The row's lifecycle state at send time. */
447
+ /** The send's aggregate state at send time. */
314
448
  status: string;
315
449
  /**
316
450
  * The SMTP `Message-ID` the relay assigned (the receive worker's
@@ -318,6 +452,96 @@ interface SendResult {
318
452
  * accepted it.
319
453
  */
320
454
  messageId?: string;
455
+ /**
456
+ * The relay's reason for the failure, when the relay gave one —
457
+ * `null` when it did not, and `null` on a send that succeeded.
458
+ */
459
+ sendFeedback?: string | null;
460
+ /**
461
+ * The typed failure slug (`"send_failed"`), or `null` when the send
462
+ * did not fail.
463
+ *
464
+ * A failed send always carries one: `status: "failed"` with
465
+ * `error: null` is not a state the backend can answer. A **partial**
466
+ * send carries it too — `status: "partial"` says *some* recipients
467
+ * were refused, and `error` says "not all of them got through".
468
+ */
469
+ error?: string | null;
470
+ /**
471
+ * One entry per recipient — what happened to **each** address.
472
+ *
473
+ * This is the per-recipient detail a multi-recipient send needs:
474
+ * "the first two went out and the third was refused because X" is a
475
+ * fact the audit log must not flatten, and the answer must not
476
+ * flatten it either.
477
+ *
478
+ * Absent on a body written by an older backend, which had no such
479
+ * field. On those, `status` is the whole answer.
480
+ */
481
+ recipients?: SendRecipientResult[];
482
+ }
483
+ /**
484
+ * One recipient's outcome inside a send.
485
+ *
486
+ * In per-recipient mode each address is its own message, its own row
487
+ * and its own relay call — so this entry is that message: its id, its
488
+ * verdict, and the relay's reason when the relay refused it.
489
+ */
490
+ interface SendRecipientResult {
491
+ /** The address this entry is about. */
492
+ to: string;
493
+ /** The platform's row id for the message that carried it. */
494
+ id: string;
495
+ /** Whether the relay accepted this recipient's message. */
496
+ status: "sent" | "failed";
497
+ /** The SMTP `Message-ID`, when the relay assigned one. */
498
+ messageId?: string;
499
+ /** The relay's reason, when the relay gave one. */
500
+ sendFeedback?: string | null;
501
+ }
502
+ /**
503
+ * The outbound half of a domain — what the platform last recorded
504
+ * about whether it can send.
505
+ *
506
+ * Read from `fm.me().sending`, the connection check's answer to
507
+ * "may this key's domain send?". It is the same verdict the
508
+ * dashboard shows, read from the same document, so the two cannot
509
+ * disagree.
510
+ */
511
+ interface AccountSendingState {
512
+ /**
513
+ * True only when the domain can send right now.
514
+ *
515
+ * Read it **with** `configured` and `state`: `configured: false`
516
+ * means sending was never set up (it is optional), while a
517
+ * configured domain can still be temporarily `canSend: false` with
518
+ * `state: "setup_required"`, `"misconfigured"`, etc.
519
+ */
520
+ canSend: boolean;
521
+ /**
522
+ * Whether an outbound provider is configured for the bound domain.
523
+ *
524
+ * Sending is optional. `false` means sending was never set up — a
525
+ * different answer from "configured but currently broken", which also
526
+ * reads `canSend: false`. Enable it from the domain page in the
527
+ * dashboard.
528
+ */
529
+ configured: boolean;
530
+ /**
531
+ * The outbound verdict, in the platform's neutral vocabulary:
532
+ * `ready`, `setup_required`, `unverified`, `misconfigured`,
533
+ * `disabled`, `no_credential`, `credential_rejected`, `unknown` or
534
+ * `error`.
535
+ */
536
+ state: string;
537
+ /** The detail the platform recorded with the verdict. */
538
+ detail: string | null;
539
+ /**
540
+ * When the sending half was last probed, in epoch milliseconds —
541
+ * `null` when it never was. The platform probes on demand, so an
542
+ * old stamp means the answer may be out of date.
543
+ */
544
+ checkedAt: number | null;
321
545
  }
322
546
  /**
323
547
  * What the credential behind the client is allowed to do, and which
@@ -337,8 +561,6 @@ interface AccountInfo {
337
561
  * sending. `null` when the credential carries no binding.
338
562
  */
339
563
  domain: string | null;
340
- /** The per-account receive worker the credential sends through. */
341
- workerHost: string | null;
342
564
  /**
343
565
  * Which credential type answered: `"sdk_key"` (the dashboard's
344
566
  * domain-bound API key) or `"agent_credential"` (a scoped
@@ -347,6 +569,39 @@ interface AccountInfo {
347
569
  credentialType: string;
348
570
  /** The scopes this credential holds. */
349
571
  scopes: string[];
572
+ /**
573
+ * The outbound half — **may this domain actually send?**
574
+ *
575
+ * `null` when the answer is not knowable: the credential carries no
576
+ * bound domain, the platform could not be read, or the domain has
577
+ * no row. `null` means "we do not know", which is different from
578
+ * "this domain cannot send" — read it with `state` before acting
579
+ * on it.
580
+ */
581
+ sending: AccountSendingState | null;
582
+ }
583
+ /**
584
+ * The shared mail worker, and the version of it.
585
+ *
586
+ * The mail worker is **Flowmails' own** deployment — one shared
587
+ * worker serves every tenant, isolated by the domain id on every row.
588
+ * It is versioned, and an older one silently does less than the
589
+ * platform expects (no route tables before `1.4.0`, no Message-ID
590
+ * lookup before `1.5.1`, no event reporting before `1.6.0`). An agent
591
+ * that cannot see the version cannot tell why its events are empty.
592
+ */
593
+ interface WorkerVersionInfo {
594
+ /**
595
+ * The version the platform last deployed — `null` when it has no
596
+ * record (read {@link lastDeployAt} with it).
597
+ */
598
+ version: string | null;
599
+ /** Whether the shared mail worker answered (its schema is migrated before deploy). */
600
+ bootstrapped: boolean;
601
+ /** When the platform last deployed this worker (ISO-8601), or `null`. */
602
+ lastDeployAt: string | null;
603
+ /** The last deploy error, when one happened, or `null`. */
604
+ lastDeployError: string | null;
350
605
  }
351
606
  interface FlowmailsOptions {
352
607
  /** `fm_<32+hex>` API key issued in `apps/web/app/routes/dashboard/settings/api-keys.tsx`. */
@@ -355,13 +610,13 @@ interface FlowmailsOptions {
355
610
  baseURL?: string;
356
611
  /**
357
612
  * The **platform** origin, used by the listen half of the surface
358
- * (`fm.events`, `fm.messages`, `fm.waits`, `fm.addresses`). The
359
- * send path goes to {@link baseURL} (the SDK backend); the event
360
- * log, the durable wait and the message read live on the platform
361
- * worker, which is a different deployment.
613
+ * (`fm.events`, `fm.messages`, `fm.waits`, `fm.addresses`).
362
614
  *
363
- * Defaults to `https://flowmails.net`. Set it for a self-hosted or
364
- * staging deployment — the same API key authenticates both.
615
+ * @deprecated The whole surface is served by the SDK backend now —
616
+ * the agent platform moved there — so this defaults to the same
617
+ * origin as {@link baseURL}. It is kept so a client that set it
618
+ * keeps working against a private or staging deployment that
619
+ * splits the two. A client that does not set it gets one host.
365
620
  */
366
621
  platformURL?: string;
367
622
  /** Inject a `fetch` implementation (Workers environments, test harnesses). */
@@ -406,6 +661,26 @@ declare class Flowmails {
406
661
  * Returns `{ id, status, messageId }` on success; throws one of
407
662
  * `AuthenticationError` / `ValidationError` / `RateLimitError` /
408
663
  * `UpstreamError` on failure (all subclasses of `FlowmailsError`).
664
+ *
665
+ * **A send the relay refused is not a throw.** The backend answers
666
+ * `201` with `status: "failed"`, and the result carries the
667
+ * reason: `error` is the typed slug and `sendFeedback` is the
668
+ * relay's own words. Check `result.error` before treating a `201`
669
+ * as "sent".
670
+ *
671
+ * **A partial send is not a success either.** Several recipients
672
+ * each get their own message, and the relay can refuse some of them.
673
+ * `status` is then `"partial"` — `error` is still set, and
674
+ * `result.recipients` says exactly which addresses were refused and
675
+ * why:
676
+ *
677
+ * ```ts
678
+ * const result = await fm.send({ from, to: ["a@x.test", "b@x.test"], subject, text });
679
+ * if (result.status === "partial") {
680
+ * const refused = result.recipients?.filter((r) => r.status === "failed") ?? [];
681
+ * // retry only these
682
+ * }
683
+ * ```
409
684
  */
410
685
  send(opts: SendOptions): Promise<SendResult>;
411
686
  /**
@@ -417,10 +692,44 @@ declare class Flowmails {
417
692
  * scopes — and it sends nothing, so running it can never mail
418
693
  * somebody by accident.
419
694
  *
695
+ * It also answers the question the 2026-10-31 audit (P0-1) found
696
+ * missing: **may this domain actually send?** — `info.sending`
697
+ * carries the platform's own verdict, read from the same document
698
+ * the dashboard reads.
699
+ *
700
+ * ```ts
701
+ * const me = await fm.me();
702
+ * if (me.sending && !me.sending.canSend) {
703
+ * // me.sending.configured: false means sending was never set up;
704
+ * // otherwise me.sending.state says why: "setup_required", …
705
+ * }
706
+ * ```
707
+ *
420
708
  * @throws {AuthenticationError} when the key is missing, malformed
421
709
  * or revoked.
422
710
  */
423
711
  me(): Promise<AccountInfo>;
712
+ /**
713
+ * The shared mail worker, and the version of it.
714
+ *
715
+ * The mail worker does the actual receiving and sending — it is
716
+ * Flowmails' own deployment, one shared worker for every tenant —
717
+ * and it is versioned: `1.4.0` brought the route tables, `1.5.1` the
718
+ * Message-ID lookup, `1.6.0` the event reporting that fills the
719
+ * log this SDK reads. An agent whose worker is older than the
720
+ * platform expects sees an empty event log and has no way to tell
721
+ * "no mail yet" from "my worker cannot report".
722
+ *
723
+ * ```ts
724
+ * const fm = new Flowmails({ apiKey: process.env.FLOWMAILS_API_KEY! });
725
+ * const worker = await fm.workerVersion();
726
+ * if (!worker.version || worker.version < "1.6.0") { … }
727
+ * ```
728
+ *
729
+ * @throws {AuthenticationError} when the key is missing, malformed
730
+ * or revoked.
731
+ */
732
+ workerVersion(): Promise<WorkerVersionInfo>;
424
733
  /**
425
734
  * The event log — the listen half of the surface, read with a
426
735
  * cursor.
@@ -506,6 +815,28 @@ interface AgentMessages {
506
815
  }): Promise<MessageDetail>;
507
816
  /** Poll a sent message's delivery state by row id or `Message-ID`. */
508
817
  status(id: string): Promise<SendStatus>;
818
+ /**
819
+ * `claim_message`: take a message for processing.
820
+ *
821
+ * The platform records that this credential is working on the
822
+ * message now — a **mutex**, so two workers of the same account do
823
+ * not process the same message at once. It does not judge the mail
824
+ * and does not act on it.
825
+ *
826
+ * @throws {ValidationError} when `messageId` or `domainId` is
827
+ * missing.
828
+ */
829
+ claim(messageId: string, opts: ClaimMessageOptions): Promise<MessageState>;
830
+ /**
831
+ * `complete_message`: record the outcome (`done` or `failed`).
832
+ *
833
+ * The platform stores what the agent said and takes no further
834
+ * action on it.
835
+ *
836
+ * @throws {ValidationError} when `messageId`, `domainId` or
837
+ * `state` is missing, or `state` is neither `done` nor `failed`.
838
+ */
839
+ complete(messageId: string, opts: CompleteMessageOptions): Promise<MessageState>;
509
840
  /**
510
841
  * `search_emails`: look **back** through the mailbox.
511
842
  *
@@ -597,8 +928,22 @@ interface SendStatus {
597
928
  status: string;
598
929
  /** The SMTP `Message-ID`; empty when the relay never accepted it. */
599
930
  messageId: string;
600
- /** The relay's error string when `status` is `failed`, else null. */
931
+ /**
932
+ * The relay's error string when `status` is `failed`, else null.
933
+ *
934
+ * The same reason the send response carries — read from the same
935
+ * column on the same worker.
936
+ */
601
937
  sendFeedback: string | null;
938
+ /**
939
+ * The typed failure slug (`"send_failed"`) when `status` is
940
+ * `failed`, else `null`.
941
+ *
942
+ * Optional: an older backend does not send it. When it is present,
943
+ * a `failed` status always carries one — "failed with no reason" is
944
+ * not a state the wire can be in.
945
+ */
946
+ error?: string | null;
602
947
  /** `CURRENT_TIMESTAMP` from the worker; opaque to the SDK. */
603
948
  createdAt: string | null;
604
949
  }
@@ -671,4 +1016,4 @@ declare class UpstreamError extends FlowmailsError {
671
1016
  constructor(code: string, upstreamMessage: string | undefined, status?: number);
672
1017
  }
673
1018
 
674
- export { type AccountInfo, type AgentAddress, type AgentAddresses, type AgentDomain, type AgentEvent, type AgentEvents, type AgentMessages, type AgentThreads, type AgentWaits, AuthenticationError, type CreateAddressResult, type CreateWaitOptions, type CreateWaitResult, Flowmails, FlowmailsError, type FlowmailsOptions, type ListEventsOptions, type ListEventsResult, type MessageDetail, RateLimitError, type SearchMessageHit, type SearchMessagesOptions, type SearchMessagesResult, type SendAttachment, type SendOptions, type SendResult, type SendStatus, type ThreadDetail, type ThreadMessage, UpstreamError, ValidationError, type WaitStatus };
1019
+ export { type AccountInfo, type AccountSendingState, type AgentAddress, type AgentAddresses, type AgentDomain, type AgentEvent, type AgentEvents, type AgentMessages, type AgentThreads, type AgentWaits, AuthenticationError, type ClaimMessageOptions, type CompleteMessageOptions, type CreateAddressResult, type CreateWaitOptions, type CreateWaitResult, Flowmails, FlowmailsError, type FlowmailsOptions, type ListEventsOptions, type ListEventsResult, type MessageDetail, type MessageState, RateLimitError, type SearchMessageHit, type SearchMessagesOptions, type SearchMessagesResult, type SendAttachment, type SendOptions, type SendRecipientResult, type SendResult, type SendStatus, type ThreadDetail, type ThreadMessage, UpstreamError, ValidationError, WAIT_RESOLVED_EVENT, type WaitStatus, type WorkerVersionInfo };
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ var UpstreamError = class extends FlowmailsError {
53
53
  };
54
54
 
55
55
  // src/client.ts
56
+ var WAIT_RESOLVED_EVENT = "wait.resolved";
56
57
  var Flowmails = class {
57
58
  apiKey;
58
59
  baseURL;
@@ -69,10 +70,7 @@ var Flowmails = class {
69
70
  /\/+$/,
70
71
  ""
71
72
  );
72
- this.platformURL = (opts.platformURL ?? "https://flowmails.net").replace(
73
- /\/+$/,
74
- ""
75
- );
73
+ this.platformURL = (opts.platformURL ?? this.baseURL).replace(/\/+$/, "");
76
74
  this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
77
75
  this.maxRetries = opts.maxRetries ?? 2;
78
76
  this.requestId = opts.requestId;
@@ -88,6 +86,26 @@ var Flowmails = class {
88
86
  * Returns `{ id, status, messageId }` on success; throws one of
89
87
  * `AuthenticationError` / `ValidationError` / `RateLimitError` /
90
88
  * `UpstreamError` on failure (all subclasses of `FlowmailsError`).
89
+ *
90
+ * **A send the relay refused is not a throw.** The backend answers
91
+ * `201` with `status: "failed"`, and the result carries the
92
+ * reason: `error` is the typed slug and `sendFeedback` is the
93
+ * relay's own words. Check `result.error` before treating a `201`
94
+ * as "sent".
95
+ *
96
+ * **A partial send is not a success either.** Several recipients
97
+ * each get their own message, and the relay can refuse some of them.
98
+ * `status` is then `"partial"` — `error` is still set, and
99
+ * `result.recipients` says exactly which addresses were refused and
100
+ * why:
101
+ *
102
+ * ```ts
103
+ * const result = await fm.send({ from, to: ["a@x.test", "b@x.test"], subject, text });
104
+ * if (result.status === "partial") {
105
+ * const refused = result.recipients?.filter((r) => r.status === "failed") ?? [];
106
+ * // retry only these
107
+ * }
108
+ * ```
91
109
  */
92
110
  async send(opts) {
93
111
  const body = {
@@ -111,7 +129,13 @@ var Flowmails = class {
111
129
  // It is deliberately **not** renamed: the backend's body is
112
130
  // camelCase already, and a rename here would be one more place
113
131
  // for the two sides to disagree.
114
- idempotencyKey: opts.idempotencyKey
132
+ idempotencyKey: opts.idempotencyKey,
133
+ // The delivery mode travels under the same name as on the wire.
134
+ // It is deliberately **not** defaulted here: the backend owns the
135
+ // default, so a new SDK talking to an older backend and an old
136
+ // SDK talking to a new backend both behave the way the backend
137
+ // says they should.
138
+ perRecipient: opts.perRecipient
115
139
  };
116
140
  return this.request(this.baseURL, "POST", "/api/v1/messages", {
117
141
  body
@@ -126,12 +150,48 @@ var Flowmails = class {
126
150
  * scopes — and it sends nothing, so running it can never mail
127
151
  * somebody by accident.
128
152
  *
153
+ * It also answers the question the 2026-10-31 audit (P0-1) found
154
+ * missing: **may this domain actually send?** — `info.sending`
155
+ * carries the platform's own verdict, read from the same document
156
+ * the dashboard reads.
157
+ *
158
+ * ```ts
159
+ * const me = await fm.me();
160
+ * if (me.sending && !me.sending.canSend) {
161
+ * // me.sending.configured: false means sending was never set up;
162
+ * // otherwise me.sending.state says why: "setup_required", …
163
+ * }
164
+ * ```
165
+ *
129
166
  * @throws {AuthenticationError} when the key is missing, malformed
130
167
  * or revoked.
131
168
  */
132
169
  async me() {
133
170
  return this.request(this.baseURL, "GET", "/api/v1/me");
134
171
  }
172
+ /**
173
+ * The shared mail worker, and the version of it.
174
+ *
175
+ * The mail worker does the actual receiving and sending — it is
176
+ * Flowmails' own deployment, one shared worker for every tenant —
177
+ * and it is versioned: `1.4.0` brought the route tables, `1.5.1` the
178
+ * Message-ID lookup, `1.6.0` the event reporting that fills the
179
+ * log this SDK reads. An agent whose worker is older than the
180
+ * platform expects sees an empty event log and has no way to tell
181
+ * "no mail yet" from "my worker cannot report".
182
+ *
183
+ * ```ts
184
+ * const fm = new Flowmails({ apiKey: process.env.FLOWMAILS_API_KEY! });
185
+ * const worker = await fm.workerVersion();
186
+ * if (!worker.version || worker.version < "1.6.0") { … }
187
+ * ```
188
+ *
189
+ * @throws {AuthenticationError} when the key is missing, malformed
190
+ * or revoked.
191
+ */
192
+ async workerVersion() {
193
+ return this.request(this.baseURL, "GET", "/api/v1/worker-version");
194
+ }
135
195
  /**
136
196
  * The event log — the listen half of the surface, read with a
137
197
  * cursor.
@@ -201,6 +261,79 @@ var Flowmails = class {
201
261
  `/api/v1/messages/${encodeURIComponent(id)}`
202
262
  );
203
263
  },
264
+ /**
265
+ * Claim a message for processing.
266
+ *
267
+ * The event log says a mail arrived; it does not say whether the
268
+ * agent already handled it. This writes that fact down, so a
269
+ * restarted agent can tell "I never saw this" from "I saw it and
270
+ * never finished".
271
+ *
272
+ * The claim is a **mutex, not a decision**: the platform records
273
+ * that this credential is working on the message and refuses a
274
+ * second live claim by another credential of the same account. It
275
+ * does not judge whether the mail matters and does not act on it.
276
+ *
277
+ * ```ts
278
+ * await fm.messages.claim(event.messageId, { domainId });
279
+ * // …process…
280
+ * await fm.messages.complete(event.messageId, { domainId, state: "done" });
281
+ * ```
282
+ *
283
+ * @throws {ValidationError} when `messageId` or `domainId` is
284
+ * missing.
285
+ */
286
+ claim: async (messageId, opts) => {
287
+ if (!messageId) {
288
+ throw new ValidationError("message_id_required", "messageId is required");
289
+ }
290
+ if (!opts?.domainId) {
291
+ throw new ValidationError("domain_id_required", "domainId is required");
292
+ }
293
+ return this.request(
294
+ this.platformURL,
295
+ "POST",
296
+ `/api/agent/messages/${encodeURIComponent(messageId)}/claim`,
297
+ { body: { domainId: opts.domainId, claimedBy: opts.claimedBy } }
298
+ );
299
+ },
300
+ /**
301
+ * Record how a message turned out.
302
+ *
303
+ * `done` or `failed`, optionally with labels and a note. The
304
+ * platform stores what the agent said and takes no further action
305
+ * on it.
306
+ *
307
+ * @throws {ValidationError} when `messageId`, `domainId` or
308
+ * `state` is missing, or `state` is neither `done` nor `failed`.
309
+ */
310
+ complete: async (messageId, opts) => {
311
+ if (!messageId) {
312
+ throw new ValidationError("message_id_required", "messageId is required");
313
+ }
314
+ if (!opts?.domainId) {
315
+ throw new ValidationError("domain_id_required", "domainId is required");
316
+ }
317
+ if (opts.state !== "done" && opts.state !== "failed") {
318
+ throw new ValidationError(
319
+ "invalid_state",
320
+ "state must be 'done' or 'failed'"
321
+ );
322
+ }
323
+ return this.request(
324
+ this.platformURL,
325
+ "POST",
326
+ `/api/agent/messages/${encodeURIComponent(messageId)}/complete`,
327
+ {
328
+ body: {
329
+ domainId: opts.domainId,
330
+ state: opts.state,
331
+ labels: opts.labels,
332
+ note: opts.note
333
+ }
334
+ }
335
+ );
336
+ },
204
337
  /**
205
338
  * Look back through the mailbox.
206
339
  *
@@ -441,6 +574,6 @@ function sleep(ms) {
441
574
  return new Promise((resolve) => setTimeout(resolve, ms));
442
575
  }
443
576
 
444
- export { AuthenticationError, Flowmails, FlowmailsError, RateLimitError, UpstreamError, ValidationError };
577
+ export { AuthenticationError, Flowmails, FlowmailsError, RateLimitError, UpstreamError, ValidationError, WAIT_RESOLVED_EVENT };
445
578
  //# sourceMappingURL=index.js.map
446
579
  //# sourceMappingURL=index.js.map