samva 0.43.0 → 0.43.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.
package/README.md CHANGED
@@ -1,9 +1,38 @@
1
1
  # samva
2
2
 
3
- Samva is the email and WhatsApp API for your app: transactional and campaign sending, inbound replies threaded into conversations, programmable mailboxes, and signed webhooks. AI agents get their own addresses and WhatsApp numbers on the same platform.
3
+ Samva is email and WhatsApp for AI agents, and the API developers build on. An agent gets its own address and WhatsApp number, and the same platform covers transactional and campaign sending, inbound replies threaded into conversations, programmable mailboxes, and signed webhooks.
4
4
 
5
5
  TypeScript SDK for Samva's public customer API.
6
6
 
7
+ ## Give an agent a mailbox
8
+
9
+ Create a mailbox, send from it, and read what comes back. A hosted `samva.email` address needs no DNS setup.
10
+
11
+ ```typescript
12
+ import { createClient } from "samva";
13
+
14
+ const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
15
+
16
+ const mailbox = await samva.mailboxes.create({
17
+ endpoint: { channel: "email", address: "support@acme.samva.email" },
18
+ name: "Support",
19
+ });
20
+
21
+ const receipt = await samva.mailboxes.sendMessage({
22
+ id: mailbox.id,
23
+ to: ["customer@example.com"],
24
+ subject: "Your support request",
25
+ text: "We are looking into your request.",
26
+ });
27
+ console.log(receipt.state);
28
+ ```
29
+
30
+ Replies arrive as signed webhooks or over the mailbox event stream, threaded to the conversation. Give
31
+ the agent a key that reaches only its own mailbox, and set rules that hold a send for a person to
32
+ approve: see [Give an agent an inbox](https://samva.dev/docs/mailboxes). To drive the same mailbox
33
+ from an MCP client instead, connect it to `https://mcp.samva.dev`
34
+ ([guide](https://samva.dev/docs/developers/mcp)).
35
+
7
36
  ## Documentation
8
37
 
9
38
  See [AGENTS.md](./AGENTS.md) for concise guidance when using this package with coding agents.
@@ -144,7 +173,7 @@ const samva = createClient({
144
173
  ```
145
174
 
146
175
  - `X-API-Key` is configured automatically from `apiKey`.
147
- - Organization context is derived from the API key — do not send `x-org-slug`.
176
+ - Organization context is derived from the API key, so do not send `x-org-slug`.
148
177
 
149
178
  ### OAuth bearer (interactive, multi-org)
150
179
 
@@ -256,9 +285,9 @@ error with `Effect.catchTag` does not require importing its constructor.
256
285
 
257
286
  Both clients retry safe operations by default:
258
287
 
259
- - **What retries** — reads (`GET`/`HEAD`) and requests covered by `x-idempotent` in the OpenAPI document and its optional `x-idempotent-when` condition. Both clients attach one key per logical call and reuse it across retries. Other mutations never retry.
260
- - **When** — only for `isRetryable` failures: throttling (`429`), transient server errors (including a transient `BillingProviderError`), and request-transport failures. `ValidationError`, `ConflictError`, `NotFound`, auth, and billing-limit `PaymentRequiredError` failures never retry.
261
- - **How** — jittered exponential backoff, bounded to four attempts total. A `429` honors the server's `retryAfterSeconds` hint (capped at 60s) in place of the computed delay.
288
+ - **What retries**: reads (`GET`/`HEAD`) and requests covered by `x-idempotent` in the OpenAPI document and its optional `x-idempotent-when` condition. Both clients attach one key per logical call and reuse it across retries. Other mutations never retry.
289
+ - **When**: only for `isRetryable` failures: throttling (`429`), transient server errors (including a transient `BillingProviderError`), and request-transport failures. `ValidationError`, `ConflictError`, `NotFound`, auth, and billing-limit `PaymentRequiredError` failures never retry.
290
+ - **How**: jittered exponential backoff, bounded to four attempts total. A `429` honors the server's `retryAfterSeconds` hint (capped at 60s) in place of the computed delay.
262
291
 
263
292
  `contacts.startImport` retries only `mode: "new"`. Resumes use a generation fence and never retry automatically, even with an explicit key. After an ambiguous resume response, read `contacts.getImportJob` before deciding what to do next.
264
293
 
@@ -278,7 +307,7 @@ program.pipe(Effect.provide(Retry.layer({ times: 6, while: isRetryable })));
278
307
 
279
308
  ### Idempotency keys
280
309
 
281
- Each idempotent operation generates an `Idempotency-Key` per logical call — stable across the built-in retries, distinct across calls — so a retried send never delivers twice. Pass an explicit key for cross-process deduplication (safe to replay the same request from a different machine):
310
+ Each idempotent operation generates an `Idempotency-Key` per logical call, stable across the built-in retries and distinct across calls, so a retried send never delivers twice. Pass an explicit key for cross-process deduplication (safe to replay the same request from a different machine):
282
311
 
283
312
  ```typescript
284
313
  import { createClient } from "samva";
@@ -307,8 +336,8 @@ Effect pagination uses Streams:
307
336
 
308
337
  Every list answers `{ items, nextCursor }`: pass `nextCursor` back as `cursor` for the next page, and stop when it is null. Every list operation that pages carries two `Stream` companions, so you traverse pages without hand-rolling a cursor loop:
309
338
 
310
- - **`list.items(input?)`** — a `Stream` of individual items across all pages.
311
- - **`list.pages(input?)`** — a `Stream` of raw page envelopes.
339
+ - **`list.items(input?)`**: a `Stream` of individual items across all pages.
340
+ - **`list.pages(input?)`**: a `Stream` of raw page envelopes.
312
341
 
313
342
  ```typescript
314
343
  import { Effect, Stream } from "effect";
@@ -334,7 +363,7 @@ Effect client configuration accepts `apiKey: string | Redacted<string>` and unwr
334
363
  only for authentication. Promise client configuration accepts `apiKey: string` and does not require
335
364
  Effect, including in browser bundles.
336
365
 
337
- Secret-bearing response fields — the plaintext API key returned by `apiKeys.create` / `apiKeys.rotate`, and the webhook signing secret from `webhooks.regenerateSecret` — decode to `Redacted<string>` on the Effect surface. The secret never leaks through logs, `String(...)`, or `JSON.stringify`; unwrap it explicitly with `Redacted.value` when you need the plaintext:
366
+ Secret-bearing response fields (the plaintext API key returned by `apiKeys.create` / `apiKeys.rotate`, and the webhook signing secret from `webhooks.regenerateSecret`) decode to `Redacted<string>` on the Effect surface. The secret never leaks through logs, `String(...)`, or `JSON.stringify`; unwrap it explicitly with `Redacted.value` when you need the plaintext:
338
367
 
339
368
  ```typescript
340
369
  import { Effect, Redacted } from "effect";
@@ -37,7 +37,7 @@ export declare class Messages {
37
37
  /**
38
38
  * Send a message
39
39
  *
40
- * Sends a message on the requested channel and returns its receipt (id, status, and why it waits when it does) with a 201 Created status. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. `channel` selects the payload variant. Email and WhatsApp sends are available. Repeating an identical request with the same optional `Idempotency-Key` header returns the original receipt; reusing the key for different content returns a conflict.
40
+ * An email send whose namespace has no sending setup returns ValidationError: share the sender domain with namespaces, or use a sender owned by that namespace. Sending setup that has stopped after failure returns ValidationError; restart or reconcile the domain's sending setup. Setup still in progress returns ConflictError. Sends a message on the requested channel and returns its receipt (id, status, and why it waits when it does) with a 201 Created status. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. `channel` selects the payload variant. Email and WhatsApp sends are available. Repeating an identical request with the same optional `Idempotency-Key` header returns the original receipt; reusing the key for different content returns a conflict.
41
41
  */
42
42
  static send<ThrowOnError extends boolean = false>(parameters: EmailSendMessagePayload | SmsSendMessagePayload | WhatsAppSendMessagePayload, options?: Options<never, ThrowOnError>): RequestResult<MessagesSendResponses, MessagesSendErrors, ThrowOnError>;
43
43
  /**
@@ -166,7 +166,7 @@ export declare class ScheduledMessages {
166
166
  /**
167
167
  * Schedule a message
168
168
  *
169
- * Schedules a message for dispatch at the absolute ISO-8601 timestamp supplied in scheduledFor. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. The send payload is the same channel union the immediate send accepts, with each channel's content checked at schedule time so a send that could never render fails now rather than hours later: email and WhatsApp schedules are available. Optional timezone is validated IANA display metadata only and never changes the execution instant.
169
+ * Schedules a message for dispatch at the absolute ISO-8601 timestamp supplied in scheduledFor. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. The send payload is the same channel union the immediate send accepts, with each channel's content checked at schedule time so a send that could never render fails now rather than hours later: email and WhatsApp schedules are available. Email schedules placed explicitly in a namespace require its sending setup to be ready: ValidationError means share the sender domain with namespaces or use a sender owned by that namespace. Setup that has stopped after failure also returns ValidationError and requires restarting or reconciling the domain's sending setup. ConflictError means setup is still in progress. Optional timezone is validated IANA display metadata only and never changes the execution instant.
170
170
  */
171
171
  static create<ThrowOnError extends boolean = false>(parameters: {
172
172
  namespaceId?: NamespaceId | null | undefined;
@@ -294,7 +294,7 @@ export declare class Campaigns {
294
294
  /**
295
295
  * Schedule a campaign run
296
296
  *
297
- * Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address.
297
+ * Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. Scheduling refuses with ValidationError when the sending namespace has no sending setup: share the sender domain with namespaces, or use a sender owned by that namespace. Sending setup that has stopped after failure returns ValidationError; restart or reconcile the domain's sending setup. Setup still in progress returns ConflictError; retry after setup finishes. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address.
298
298
  */
299
299
  static scheduleRun<ThrowOnError extends boolean = false>(parameters: {
300
300
  id: CampaignId;
@@ -3797,7 +3797,7 @@ export declare class Mailboxes {
3797
3797
  /**
3798
3798
  * Approve a mailbox action
3799
3799
  *
3800
- * Records approval of a send and returns 202 while it is pending. A send is queued for automatic retry within 15 minutes of approval; repeating approval does not extend this deadline. Accepted, completed, and notSent replays return 200. No expiry applies before approval. Only a person signed in or through OAuth may approve, and never the proposer. Non-send approvals execute synchronously and return 200 with their own execution states. Set `always: true` to add an actor-specific rule allowing matching future actions, subject to policy floors and guards. Remembering an allowance for a hosted agent or API key requires an organization owner or admin. A hand-off cannot be always allowed. The action's `resolution` names the approver; approving a held send publishes one `mailbox.action.resolved` event.
3800
+ * Records approval of a send and returns 202 while it is pending. A send is queued for automatic retry within 15 minutes of approval; repeating approval does not extend this deadline. Accepted, completed, and notSent replays return 200. No expiry applies before approval. Only a person signed in or through OAuth may approve, and never the proposer. Non-send approvals execute synchronously and return 200 with their own execution states. Set `always: true` to add an actor-specific rule allowing matching future actions, subject to policy floors and guards. Remembering an allowance for a hosted agent or API key requires an organization owner or admin; for a hosted agent's integration tool call it lets that tool run without approval for every agent, which only the organization owner may do. A held action's `alwaysAllow` says who may and whether the caller can. A hand-off cannot be always allowed. The action's `resolution` names the approver; approving a held send publishes one `mailbox.action.resolved` event.
3801
3801
  */
3802
3802
  static approveAction<ThrowOnError extends boolean = false>(parameters: {
3803
3803
  id: MailboxId;
@@ -69,7 +69,7 @@ var Messages = class {
69
69
  /**
70
70
  * Send a message
71
71
  *
72
- * Sends a message on the requested channel and returns its receipt (id, status, and why it waits when it does) with a 201 Created status. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. `channel` selects the payload variant. Email and WhatsApp sends are available. Repeating an identical request with the same optional `Idempotency-Key` header returns the original receipt; reusing the key for different content returns a conflict.
72
+ * An email send whose namespace has no sending setup returns ValidationError: share the sender domain with namespaces, or use a sender owned by that namespace. Sending setup that has stopped after failure returns ValidationError; restart or reconcile the domain's sending setup. Setup still in progress returns ConflictError. Sends a message on the requested channel and returns its receipt (id, status, and why it waits when it does) with a 201 Created status. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. `channel` selects the payload variant. Email and WhatsApp sends are available. Repeating an identical request with the same optional `Idempotency-Key` header returns the original receipt; reusing the key for different content returns a conflict.
73
73
  */
74
74
  static send(parameters, options) {
75
75
  const params = { body: parameters };
@@ -438,7 +438,7 @@ var ScheduledMessages = class {
438
438
  /**
439
439
  * Schedule a message
440
440
  *
441
- * Schedules a message for dispatch at the absolute ISO-8601 timestamp supplied in scheduledFor. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. The send payload is the same channel union the immediate send accepts, with each channel's content checked at schedule time so a send that could never render fails now rather than hours later: email and WhatsApp schedules are available. Optional timezone is validated IANA display metadata only and never changes the execution instant.
441
+ * Schedules a message for dispatch at the absolute ISO-8601 timestamp supplied in scheduledFor. Requires `messages:create` or the send permission of the channel it sends on, such as `email:send`. The send payload is the same channel union the immediate send accepts, with each channel's content checked at schedule time so a send that could never render fails now rather than hours later: email and WhatsApp schedules are available. Email schedules placed explicitly in a namespace require its sending setup to be ready: ValidationError means share the sender domain with namespaces or use a sender owned by that namespace. Setup that has stopped after failure also returns ValidationError and requires restarting or reconciling the domain's sending setup. ConflictError means setup is still in progress. Optional timezone is validated IANA display metadata only and never changes the execution instant.
442
442
  */
443
443
  static create(parameters, options) {
444
444
  const params = buildClientParams([parameters], [{ args: [
@@ -846,7 +846,7 @@ var Campaigns = class {
846
846
  /**
847
847
  * Schedule a campaign run
848
848
  *
849
- * Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address.
849
+ * Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. Scheduling refuses with ValidationError when the sending namespace has no sending setup: share the sender domain with namespaces, or use a sender owned by that namespace. Sending setup that has stopped after failure returns ValidationError; restart or reconcile the domain's sending setup. Setup still in progress returns ConflictError; retry after setup finishes. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address.
850
850
  */
851
851
  static scheduleRun(parameters, options) {
852
852
  const params = buildClientParams([parameters], [{ args: [{
@@ -11809,7 +11809,7 @@ var Mailboxes = class {
11809
11809
  /**
11810
11810
  * Approve a mailbox action
11811
11811
  *
11812
- * Records approval of a send and returns 202 while it is pending. A send is queued for automatic retry within 15 minutes of approval; repeating approval does not extend this deadline. Accepted, completed, and notSent replays return 200. No expiry applies before approval. Only a person signed in or through OAuth may approve, and never the proposer. Non-send approvals execute synchronously and return 200 with their own execution states. Set `always: true` to add an actor-specific rule allowing matching future actions, subject to policy floors and guards. Remembering an allowance for a hosted agent or API key requires an organization owner or admin. A hand-off cannot be always allowed. The action's `resolution` names the approver; approving a held send publishes one `mailbox.action.resolved` event.
11812
+ * Records approval of a send and returns 202 while it is pending. A send is queued for automatic retry within 15 minutes of approval; repeating approval does not extend this deadline. Accepted, completed, and notSent replays return 200. No expiry applies before approval. Only a person signed in or through OAuth may approve, and never the proposer. Non-send approvals execute synchronously and return 200 with their own execution states. Set `always: true` to add an actor-specific rule allowing matching future actions, subject to policy floors and guards. Remembering an allowance for a hosted agent or API key requires an organization owner or admin; for a hosted agent's integration tool call it lets that tool run without approval for every agent, which only the organization owner may do. A held action's `alwaysAllow` says who may and whether the caller can. A hand-off cannot be always allowed. The action's `resolution` names the approver; approving a held send publishes one `mailbox.action.resolved` event.
11813
11813
  */
11814
11814
  static approveAction(parameters, options) {
11815
11815
  const params = buildClientParams([parameters], [{ args: [
@@ -434,12 +434,12 @@ export type MailboxActionDecision = {
434
434
  outcome: "allow" | "hold" | "refuse";
435
435
  reason: string;
436
436
  scopes: Array<{
437
- kind: "organization" | "mailbox" | "agent" | "apiKey";
437
+ kind: "organization" | "integration" | "mailbox" | "agent" | "apiKey";
438
438
  id: string;
439
439
  }>;
440
440
  rule?: {
441
441
  scope: {
442
- kind: "organization" | "mailbox" | "agent" | "apiKey";
442
+ kind: "organization" | "integration" | "mailbox" | "agent" | "apiKey";
443
443
  id: string;
444
444
  };
445
445
  index: number;
@@ -532,6 +532,10 @@ export type MailboxNonSendAction = {
532
532
  * How a held action's approval ended: who approved, denied, or cancelled it, when, and the denial reason. Null while it waits for approval and for an action that never needed one.
533
533
  */
534
534
  resolution: MailboxActionResolution | null;
535
+ /**
536
+ * Who may approve this held action with Always allow, and whether the caller may. Null for an action that is not held, a hand-off, and a reply held for integration data.
537
+ */
538
+ alwaysAllow: MailboxAlwaysAllow | null;
535
539
  createdAt: string;
536
540
  updatedAt: string;
537
541
  type: "updateDraft" | "createNote" | "assignThread" | "changeThreadState" | "call" | "extensionRequest" | "toolCall" | "handoff";
@@ -558,6 +562,16 @@ export type MailboxToolCall = {
558
562
  [key: string]: JsonValue;
559
563
  };
560
564
  };
565
+ export type MailboxAlwaysAllow = {
566
+ /**
567
+ * Who may approve with Always allow. `owner`: only the organization owner, because it lets an integration tool run without approval for every agent. `admin`: an organization owner or admin, because it adds a rule for one hosted agent or API key. `approver`: anyone who may approve the action.
568
+ */
569
+ by: "owner" | "admin" | "approver";
570
+ /**
571
+ * Whether the caller is someone `by` names.
572
+ */
573
+ allowed: boolean;
574
+ };
561
575
  /**
562
576
  * How the action's approval ended.
563
577
  */
@@ -593,6 +607,10 @@ export type MailboxSendAction = {
593
607
  * How a held action's approval ended: who approved, denied, or cancelled it, when, and the denial reason. Null while it waits for approval and for an action that never needed one.
594
608
  */
595
609
  resolution: MailboxActionResolution | null;
610
+ /**
611
+ * Who may approve this held action with Always allow, and whether the caller may. Null for an action that is not held, a hand-off, and a reply held for integration data.
612
+ */
613
+ alwaysAllow: MailboxAlwaysAllow | null;
596
614
  createdAt: string;
597
615
  updatedAt: string;
598
616
  type: "sendMessage" | "reply";
@@ -1235,6 +1253,7 @@ export type MailboxNeedsYouItem = {
1235
1253
  displayName?: string | null | undefined;
1236
1254
  };
1237
1255
  source: "humanUi" | "externalApi" | "aiSdkTool" | "extension" | "externalAgent" | "samvaManagedAgent" | "system";
1256
+ alwaysAllow: MailboxAlwaysAllow | null;
1238
1257
  createdAt: string;
1239
1258
  } | {
1240
1259
  type: "quarantinedMessage";
@@ -1250,12 +1269,12 @@ export type PolicyDecision = {
1250
1269
  outcome: "allow" | "hold" | "refuse";
1251
1270
  reason: string;
1252
1271
  scopes: Array<{
1253
- kind: "organization" | "mailbox" | "agent" | "apiKey";
1272
+ kind: "organization" | "integration" | "mailbox" | "agent" | "apiKey";
1254
1273
  id: string;
1255
1274
  }>;
1256
1275
  rule?: {
1257
1276
  scope: {
1258
- kind: "organization" | "mailbox" | "agent" | "apiKey";
1277
+ kind: "organization" | "integration" | "mailbox" | "agent" | "apiKey";
1259
1278
  id: string;
1260
1279
  };
1261
1280
  index: number;
@@ -600,7 +600,7 @@ var CampaignsGroup = class extends HttpApiGroup.make("Campaigns").add(HttpApiEnd
600
600
  CampaignsScheduleRun503.pipe(HttpApiSchema.status(503)),
601
601
  CampaignsScheduleRun504.pipe(HttpApiSchema.status(504))
602
602
  ]
603
- }).middleware(ApiKeySecurityMiddleware).annotate(OpenApi.Identifier, "campaigns.scheduleRun").annotate(OpenApi.Summary, "Schedule a campaign run").annotate(OpenApi.Description, "Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address."), HttpApiEndpoint.get("campaignsGetRun", "/v1/campaigns/:id/runs/:runId", {
603
+ }).middleware(ApiKeySecurityMiddleware).annotate(OpenApi.Identifier, "campaigns.scheduleRun").annotate(OpenApi.Summary, "Schedule a campaign run").annotate(OpenApi.Description, "Schedules an email campaign run at the absolute ISO-8601 instant in scheduledFor, or immediately when omitted. The optional Idempotency-Key header is scoped to the organization and replays return the original run. Scheduling refuses with ValidationError when the sending namespace has no sending setup: share the sender domain with namespaces, or use a sender owned by that namespace. Sending setup that has stopped after failure returns ValidationError; restart or reconcile the domain's sending setup. Setup still in progress returns ConflictError; retry after setup finishes. An email campaign must carry the brand footer: it is refused with CampaignFooterRequiredError when its footer is off and its template renders no BrandFooter, and with BrandAddressRequiredError when a brand that signs it off has no postal address."), HttpApiEndpoint.get("campaignsGetRun", "/v1/campaigns/:id/runs/:runId", {
604
604
  params: CampaignsGetRunPathParams,
605
605
  success: CampaignsGetRun200,
606
606
  error: [