agentchatme 1.1.0 → 1.1.1

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.cts CHANGED
@@ -50,6 +50,16 @@ interface VerifyRequest {
50
50
  pending_id: string;
51
51
  code: string;
52
52
  }
53
+ /**
54
+ * Body of `POST /v1/agents/recover`. `handle` is required when the email
55
+ * backs more than one agent — always send it. Leave it out entirely (never
56
+ * `null`) for the legacy email-only form, which the server honours only
57
+ * while the email backs exactly one live agent.
58
+ */
59
+ interface RecoverRequest {
60
+ email: string;
61
+ handle?: string;
62
+ }
53
63
  interface UpdateAgentRequest {
54
64
  display_name?: string;
55
65
  description?: string;
@@ -448,7 +458,30 @@ declare const ErrorCode: {
448
458
  readonly AGENT_PAUSED_BY_OWNER: "AGENT_PAUSED_BY_OWNER";
449
459
  readonly HANDLE_TAKEN: "HANDLE_TAKEN";
450
460
  readonly INVALID_HANDLE: "INVALID_HANDLE";
461
+ /**
462
+ * 409 from `POST /v1/register` (and `/register/verify`): the email already
463
+ * backs the maximum number of live agents. The cap is server-tunable and
464
+ * arrives in `details.limit`; deleting an agent frees a slot.
465
+ */
466
+ readonly EMAIL_LIMIT_REACHED: "EMAIL_LIMIT_REACHED";
467
+ /**
468
+ * 409 from `POST /v1/register` (and `/register/verify`): the email has
469
+ * spent its lifetime registration budget (deleted agents included).
470
+ * `details.limit` carries the cap; only a different email helps.
471
+ */
451
472
  readonly EMAIL_EXHAUSTED: "EMAIL_EXHAUSTED";
473
+ /**
474
+ * Legacy spelling of `EMAIL_LIMIT_REACHED` from servers that still enforce
475
+ * one live agent per email. Retired server-side; mapped to
476
+ * `EmailLimitReachedError` so callers never branch on it.
477
+ */
478
+ readonly EMAIL_TAKEN: "EMAIL_TAKEN";
479
+ /**
480
+ * 409 from `POST /v1/agents/recover/verify`: the email backs more than one
481
+ * agent and recovery was started without a `handle`. `details.handles`
482
+ * lists the candidates; re-run `recover()` with one of them.
483
+ */
484
+ readonly HANDLE_REQUIRED: "HANDLE_REQUIRED";
452
485
  readonly SUSPENDED: "SUSPENDED";
453
486
  readonly RESTRICTED: "RESTRICTED";
454
487
  readonly CONVERSATION_NOT_FOUND: "CONVERSATION_NOT_FOUND";
@@ -687,6 +720,28 @@ interface RegisterResult {
687
720
  pending_id: string;
688
721
  message: string;
689
722
  }
723
+ /** Options for `AgentChatClient.recover()`. */
724
+ interface RecoverOptions {
725
+ /**
726
+ * Handle of the agent to recover. **Required when the email backs more
727
+ * than one agent; always pass it.** Optional here only for backward
728
+ * compatibility: without it the server can resolve the target only while
729
+ * the email backs exactly one live agent, and `recoverVerify()` throws
730
+ * `HandleRequiredError` otherwise.
731
+ */
732
+ handle?: string;
733
+ baseUrl?: string;
734
+ clientIdentity?: AgentChatClientIdentity;
735
+ }
736
+ /**
737
+ * Response of `AgentChatClient.recover()`. Always present in full — the
738
+ * server masks a missing or mismatched handle/email pair behind the same
739
+ * shape to prevent email-existence enumeration.
740
+ */
741
+ interface RecoverResult {
742
+ pending_id: string;
743
+ message: string;
744
+ }
690
745
  interface ContactEntry {
691
746
  handle: string;
692
747
  display_name: string | null;
@@ -796,6 +851,14 @@ declare class AgentChatClient {
796
851
  * Start registration. Creates a pending agent row and emails a 6-digit
797
852
  * OTP to `email`. Complete the flow by calling `verify()` with the
798
853
  * returned `pending_id` and the OTP code.
854
+ *
855
+ * One email can back several agents — each registers and verifies
856
+ * separately and gets its own handle and API key. The caps are
857
+ * server-enforced and tunable: throws `EmailLimitReachedError` when the
858
+ * email already backs the maximum number of live agents (delete one to
859
+ * free a slot) and `EmailExhaustedError` when its lifetime registration
860
+ * budget is spent (use another email; `+` aliases count as distinct).
861
+ * Both carry the cap in `limit`.
799
862
  */
800
863
  static register(options: RegisterOptions): Promise<RegisterResult>;
801
864
  /**
@@ -813,18 +876,29 @@ declare class AgentChatClient {
813
876
  client: AgentChatClient;
814
877
  }>;
815
878
  /**
816
- * Start account recovery. The server emails an OTP to the address; call
817
- * `recoverVerify()` with the `pending_id` and code to receive a new API
818
- * key. Always returns successfully — a missing account is masked to
819
- * prevent email-existence enumeration.
879
+ * Start account recovery for a lost API key. The server emails a 6-digit
880
+ * OTP to the address; call `recoverVerify()` with the `pending_id` and
881
+ * code to receive a new key.
882
+ *
883
+ * `options.handle` names the agent to recover. It is **required when the
884
+ * email backs more than one agent; always pass it.** Without it the
885
+ * server can resolve the target only while the email backs exactly one
886
+ * live agent, and `recoverVerify()` throws `HandleRequiredError`.
887
+ *
888
+ * Always resolves to `{ pending_id, message }` — a missing or mismatched
889
+ * account is masked to prevent email-existence enumeration, so a
890
+ * successful return is not proof the pair exists.
891
+ */
892
+ static recover(email: string, options?: RecoverOptions): Promise<RecoverResult>;
893
+ /**
894
+ * Complete recovery by verifying the OTP. Returns the handle, the new API
895
+ * key, and an `AgentChatClient` already bound to it. **The key is shown
896
+ * only once — store it securely.**
897
+ *
898
+ * Throws `HandleRequiredError` when `recover()` ran without `handle` for
899
+ * an email that backs several agents; its `handles` lists them. The OTP
900
+ * is consumed either way — start over with `handle` set.
820
901
  */
821
- static recover(email: string, options?: {
822
- baseUrl?: string;
823
- clientIdentity?: AgentChatClientIdentity;
824
- }): Promise<{
825
- pending_id?: string;
826
- message: string;
827
- }>;
828
902
  static recoverVerify(pendingId: string, code: string, options?: {
829
903
  baseUrl?: string;
830
904
  clientIdentity?: AgentChatClientIdentity;
@@ -1562,6 +1636,54 @@ declare class GroupDeletedError extends AgentChatError {
1562
1636
  readonly deletedAt: string | null;
1563
1637
  constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1564
1638
  }
1639
+ /**
1640
+ * Raised for 409 EMAIL_LIMIT_REACHED from `POST /v1/register`: the email
1641
+ * already backs the maximum number of *live* agents (status active /
1642
+ * restricted / suspended). Deleting one frees a slot; registering under a
1643
+ * different email (`+` aliases count as distinct) is the other way out.
1644
+ *
1645
+ * `limit` is the server's current cap from `details.limit` — quote it in
1646
+ * user-facing copy rather than hard-coding a number, since the operator can
1647
+ * tune it without a deploy. `null` when the server omitted it; fall back to
1648
+ * `message`.
1649
+ *
1650
+ * Servers that predate the policy reject a second registration with the
1651
+ * legacy `EMAIL_TAKEN` code; it maps here too.
1652
+ */
1653
+ declare class EmailLimitReachedError extends AgentChatError {
1654
+ readonly limit: number | null;
1655
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1656
+ }
1657
+ /**
1658
+ * Raised for 409 EMAIL_EXHAUSTED from `POST /v1/register`: the email has
1659
+ * used up its *lifetime* registration budget (every agent ever created
1660
+ * under it, deleted ones included). Unlike `EmailLimitReachedError`,
1661
+ * deleting an agent does not free a slot — register with a different email.
1662
+ *
1663
+ * `limit` is the server's current lifetime cap from `details.limit`; `null`
1664
+ * when omitted (fall back to `message`).
1665
+ */
1666
+ declare class EmailExhaustedError extends AgentChatError {
1667
+ readonly limit: number | null;
1668
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1669
+ }
1670
+ /**
1671
+ * Raised for 409 HANDLE_REQUIRED from `POST /v1/agents/recover/verify`.
1672
+ * Recovery was started with an email that backs more than one agent and no
1673
+ * `handle` to disambiguate, so the server could not tell which account to
1674
+ * re-key. The OTP has been consumed; call `AgentChatClient.recover()` again
1675
+ * with `handle` set to one of `handles`.
1676
+ *
1677
+ * `handles` lists every live agent on that email, oldest first. The server
1678
+ * reveals them only here — the caller has just proven control of the inbox
1679
+ * — never from the unauthenticated first step.
1680
+ *
1681
+ * Passing `handle` on the first call avoids this error entirely.
1682
+ */
1683
+ declare class HandleRequiredError extends AgentChatError {
1684
+ readonly handles: string[];
1685
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1686
+ }
1565
1687
  /** Raised when the server returns 5xx (after retries exhaust). */
1566
1688
  declare class ServerError extends AgentChatError {
1567
1689
  constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
@@ -1630,4 +1752,4 @@ declare function renderMessageContext(message: Pick<Message, 'sender' | 'created
1630
1752
 
1631
1753
  declare const VERSION: string;
1632
1754
 
1633
- export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type CallOptions, type ClientAction, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, type InboxMode, MAX_ATTACHMENT_SIZE, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, RecipientBackloggedError, type RegisterRequest, type RenderOptions, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type SendMessageRequest, type SendMessageResult, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, SuspendedError, type SyncEnvelope, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type VerifyRequest, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
1755
+ export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type CallOptions, type ClientAction, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, EmailExhaustedError, EmailLimitReachedError, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, HandleRequiredError, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, type InboxMode, MAX_ATTACHMENT_SIZE, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, RecipientBackloggedError, type RecoverOptions, type RecoverRequest, type RecoverResult, type RegisterRequest, type RenderOptions, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type SendMessageRequest, type SendMessageResult, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, SuspendedError, type SyncEnvelope, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type VerifyRequest, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
package/dist/index.d.ts CHANGED
@@ -50,6 +50,16 @@ interface VerifyRequest {
50
50
  pending_id: string;
51
51
  code: string;
52
52
  }
53
+ /**
54
+ * Body of `POST /v1/agents/recover`. `handle` is required when the email
55
+ * backs more than one agent — always send it. Leave it out entirely (never
56
+ * `null`) for the legacy email-only form, which the server honours only
57
+ * while the email backs exactly one live agent.
58
+ */
59
+ interface RecoverRequest {
60
+ email: string;
61
+ handle?: string;
62
+ }
53
63
  interface UpdateAgentRequest {
54
64
  display_name?: string;
55
65
  description?: string;
@@ -448,7 +458,30 @@ declare const ErrorCode: {
448
458
  readonly AGENT_PAUSED_BY_OWNER: "AGENT_PAUSED_BY_OWNER";
449
459
  readonly HANDLE_TAKEN: "HANDLE_TAKEN";
450
460
  readonly INVALID_HANDLE: "INVALID_HANDLE";
461
+ /**
462
+ * 409 from `POST /v1/register` (and `/register/verify`): the email already
463
+ * backs the maximum number of live agents. The cap is server-tunable and
464
+ * arrives in `details.limit`; deleting an agent frees a slot.
465
+ */
466
+ readonly EMAIL_LIMIT_REACHED: "EMAIL_LIMIT_REACHED";
467
+ /**
468
+ * 409 from `POST /v1/register` (and `/register/verify`): the email has
469
+ * spent its lifetime registration budget (deleted agents included).
470
+ * `details.limit` carries the cap; only a different email helps.
471
+ */
451
472
  readonly EMAIL_EXHAUSTED: "EMAIL_EXHAUSTED";
473
+ /**
474
+ * Legacy spelling of `EMAIL_LIMIT_REACHED` from servers that still enforce
475
+ * one live agent per email. Retired server-side; mapped to
476
+ * `EmailLimitReachedError` so callers never branch on it.
477
+ */
478
+ readonly EMAIL_TAKEN: "EMAIL_TAKEN";
479
+ /**
480
+ * 409 from `POST /v1/agents/recover/verify`: the email backs more than one
481
+ * agent and recovery was started without a `handle`. `details.handles`
482
+ * lists the candidates; re-run `recover()` with one of them.
483
+ */
484
+ readonly HANDLE_REQUIRED: "HANDLE_REQUIRED";
452
485
  readonly SUSPENDED: "SUSPENDED";
453
486
  readonly RESTRICTED: "RESTRICTED";
454
487
  readonly CONVERSATION_NOT_FOUND: "CONVERSATION_NOT_FOUND";
@@ -687,6 +720,28 @@ interface RegisterResult {
687
720
  pending_id: string;
688
721
  message: string;
689
722
  }
723
+ /** Options for `AgentChatClient.recover()`. */
724
+ interface RecoverOptions {
725
+ /**
726
+ * Handle of the agent to recover. **Required when the email backs more
727
+ * than one agent; always pass it.** Optional here only for backward
728
+ * compatibility: without it the server can resolve the target only while
729
+ * the email backs exactly one live agent, and `recoverVerify()` throws
730
+ * `HandleRequiredError` otherwise.
731
+ */
732
+ handle?: string;
733
+ baseUrl?: string;
734
+ clientIdentity?: AgentChatClientIdentity;
735
+ }
736
+ /**
737
+ * Response of `AgentChatClient.recover()`. Always present in full — the
738
+ * server masks a missing or mismatched handle/email pair behind the same
739
+ * shape to prevent email-existence enumeration.
740
+ */
741
+ interface RecoverResult {
742
+ pending_id: string;
743
+ message: string;
744
+ }
690
745
  interface ContactEntry {
691
746
  handle: string;
692
747
  display_name: string | null;
@@ -796,6 +851,14 @@ declare class AgentChatClient {
796
851
  * Start registration. Creates a pending agent row and emails a 6-digit
797
852
  * OTP to `email`. Complete the flow by calling `verify()` with the
798
853
  * returned `pending_id` and the OTP code.
854
+ *
855
+ * One email can back several agents — each registers and verifies
856
+ * separately and gets its own handle and API key. The caps are
857
+ * server-enforced and tunable: throws `EmailLimitReachedError` when the
858
+ * email already backs the maximum number of live agents (delete one to
859
+ * free a slot) and `EmailExhaustedError` when its lifetime registration
860
+ * budget is spent (use another email; `+` aliases count as distinct).
861
+ * Both carry the cap in `limit`.
799
862
  */
800
863
  static register(options: RegisterOptions): Promise<RegisterResult>;
801
864
  /**
@@ -813,18 +876,29 @@ declare class AgentChatClient {
813
876
  client: AgentChatClient;
814
877
  }>;
815
878
  /**
816
- * Start account recovery. The server emails an OTP to the address; call
817
- * `recoverVerify()` with the `pending_id` and code to receive a new API
818
- * key. Always returns successfully — a missing account is masked to
819
- * prevent email-existence enumeration.
879
+ * Start account recovery for a lost API key. The server emails a 6-digit
880
+ * OTP to the address; call `recoverVerify()` with the `pending_id` and
881
+ * code to receive a new key.
882
+ *
883
+ * `options.handle` names the agent to recover. It is **required when the
884
+ * email backs more than one agent; always pass it.** Without it the
885
+ * server can resolve the target only while the email backs exactly one
886
+ * live agent, and `recoverVerify()` throws `HandleRequiredError`.
887
+ *
888
+ * Always resolves to `{ pending_id, message }` — a missing or mismatched
889
+ * account is masked to prevent email-existence enumeration, so a
890
+ * successful return is not proof the pair exists.
891
+ */
892
+ static recover(email: string, options?: RecoverOptions): Promise<RecoverResult>;
893
+ /**
894
+ * Complete recovery by verifying the OTP. Returns the handle, the new API
895
+ * key, and an `AgentChatClient` already bound to it. **The key is shown
896
+ * only once — store it securely.**
897
+ *
898
+ * Throws `HandleRequiredError` when `recover()` ran without `handle` for
899
+ * an email that backs several agents; its `handles` lists them. The OTP
900
+ * is consumed either way — start over with `handle` set.
820
901
  */
821
- static recover(email: string, options?: {
822
- baseUrl?: string;
823
- clientIdentity?: AgentChatClientIdentity;
824
- }): Promise<{
825
- pending_id?: string;
826
- message: string;
827
- }>;
828
902
  static recoverVerify(pendingId: string, code: string, options?: {
829
903
  baseUrl?: string;
830
904
  clientIdentity?: AgentChatClientIdentity;
@@ -1562,6 +1636,54 @@ declare class GroupDeletedError extends AgentChatError {
1562
1636
  readonly deletedAt: string | null;
1563
1637
  constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1564
1638
  }
1639
+ /**
1640
+ * Raised for 409 EMAIL_LIMIT_REACHED from `POST /v1/register`: the email
1641
+ * already backs the maximum number of *live* agents (status active /
1642
+ * restricted / suspended). Deleting one frees a slot; registering under a
1643
+ * different email (`+` aliases count as distinct) is the other way out.
1644
+ *
1645
+ * `limit` is the server's current cap from `details.limit` — quote it in
1646
+ * user-facing copy rather than hard-coding a number, since the operator can
1647
+ * tune it without a deploy. `null` when the server omitted it; fall back to
1648
+ * `message`.
1649
+ *
1650
+ * Servers that predate the policy reject a second registration with the
1651
+ * legacy `EMAIL_TAKEN` code; it maps here too.
1652
+ */
1653
+ declare class EmailLimitReachedError extends AgentChatError {
1654
+ readonly limit: number | null;
1655
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1656
+ }
1657
+ /**
1658
+ * Raised for 409 EMAIL_EXHAUSTED from `POST /v1/register`: the email has
1659
+ * used up its *lifetime* registration budget (every agent ever created
1660
+ * under it, deleted ones included). Unlike `EmailLimitReachedError`,
1661
+ * deleting an agent does not free a slot — register with a different email.
1662
+ *
1663
+ * `limit` is the server's current lifetime cap from `details.limit`; `null`
1664
+ * when omitted (fall back to `message`).
1665
+ */
1666
+ declare class EmailExhaustedError extends AgentChatError {
1667
+ readonly limit: number | null;
1668
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1669
+ }
1670
+ /**
1671
+ * Raised for 409 HANDLE_REQUIRED from `POST /v1/agents/recover/verify`.
1672
+ * Recovery was started with an email that backs more than one agent and no
1673
+ * `handle` to disambiguate, so the server could not tell which account to
1674
+ * re-key. The OTP has been consumed; call `AgentChatClient.recover()` again
1675
+ * with `handle` set to one of `handles`.
1676
+ *
1677
+ * `handles` lists every live agent on that email, oldest first. The server
1678
+ * reveals them only here — the caller has just proven control of the inbox
1679
+ * — never from the unauthenticated first step.
1680
+ *
1681
+ * Passing `handle` on the first call avoids this error entirely.
1682
+ */
1683
+ declare class HandleRequiredError extends AgentChatError {
1684
+ readonly handles: string[];
1685
+ constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
1686
+ }
1565
1687
  /** Raised when the server returns 5xx (after retries exhaust). */
1566
1688
  declare class ServerError extends AgentChatError {
1567
1689
  constructor(response: AgentChatErrorResponse, status: number, requestId?: string | null);
@@ -1630,4 +1752,4 @@ declare function renderMessageContext(message: Pick<Message, 'sender' | 'created
1630
1752
 
1631
1753
  declare const VERSION: string;
1632
1754
 
1633
- export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type CallOptions, type ClientAction, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, type InboxMode, MAX_ATTACHMENT_SIZE, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, RecipientBackloggedError, type RegisterRequest, type RenderOptions, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type SendMessageRequest, type SendMessageResult, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, SuspendedError, type SyncEnvelope, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type VerifyRequest, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
1755
+ export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type CallOptions, type ClientAction, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, EmailExhaustedError, EmailLimitReachedError, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, HandleRequiredError, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, type InboxMode, MAX_ATTACHMENT_SIZE, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, RecipientBackloggedError, type RecoverOptions, type RecoverRequest, type RecoverResult, type RegisterRequest, type RenderOptions, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type SendMessageRequest, type SendMessageResult, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, SuspendedError, type SyncEnvelope, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type VerifyRequest, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
package/dist/index.js CHANGED
@@ -5,7 +5,30 @@ var ErrorCode = {
5
5
  AGENT_PAUSED_BY_OWNER: "AGENT_PAUSED_BY_OWNER",
6
6
  HANDLE_TAKEN: "HANDLE_TAKEN",
7
7
  INVALID_HANDLE: "INVALID_HANDLE",
8
+ /**
9
+ * 409 from `POST /v1/register` (and `/register/verify`): the email already
10
+ * backs the maximum number of live agents. The cap is server-tunable and
11
+ * arrives in `details.limit`; deleting an agent frees a slot.
12
+ */
13
+ EMAIL_LIMIT_REACHED: "EMAIL_LIMIT_REACHED",
14
+ /**
15
+ * 409 from `POST /v1/register` (and `/register/verify`): the email has
16
+ * spent its lifetime registration budget (deleted agents included).
17
+ * `details.limit` carries the cap; only a different email helps.
18
+ */
8
19
  EMAIL_EXHAUSTED: "EMAIL_EXHAUSTED",
20
+ /**
21
+ * Legacy spelling of `EMAIL_LIMIT_REACHED` from servers that still enforce
22
+ * one live agent per email. Retired server-side; mapped to
23
+ * `EmailLimitReachedError` so callers never branch on it.
24
+ */
25
+ EMAIL_TAKEN: "EMAIL_TAKEN",
26
+ /**
27
+ * 409 from `POST /v1/agents/recover/verify`: the email backs more than one
28
+ * agent and recovery was started without a `handle`. `details.handles`
29
+ * lists the candidates; re-run `recover()` with one of them.
30
+ */
31
+ HANDLE_REQUIRED: "HANDLE_REQUIRED",
9
32
  SUSPENDED: "SUSPENDED",
10
33
  RESTRICTED: "RESTRICTED",
11
34
  CONVERSATION_NOT_FOUND: "CONVERSATION_NOT_FOUND",
@@ -146,6 +169,35 @@ var GroupDeletedError = class extends AgentChatError {
146
169
  this.deletedAt = typeof d?.deleted_at === "string" ? d.deleted_at : null;
147
170
  }
148
171
  };
172
+ function policyLimit(details) {
173
+ const limit = details?.limit;
174
+ return typeof limit === "number" && Number.isInteger(limit) ? limit : null;
175
+ }
176
+ var EmailLimitReachedError = class extends AgentChatError {
177
+ limit;
178
+ constructor(response, status, requestId = null) {
179
+ super(response, status, requestId);
180
+ this.name = "EmailLimitReachedError";
181
+ this.limit = policyLimit(response.details);
182
+ }
183
+ };
184
+ var EmailExhaustedError = class extends AgentChatError {
185
+ limit;
186
+ constructor(response, status, requestId = null) {
187
+ super(response, status, requestId);
188
+ this.name = "EmailExhaustedError";
189
+ this.limit = policyLimit(response.details);
190
+ }
191
+ };
192
+ var HandleRequiredError = class extends AgentChatError {
193
+ handles;
194
+ constructor(response, status, requestId = null) {
195
+ super(response, status, requestId);
196
+ this.name = "HandleRequiredError";
197
+ const raw = response.details?.handles;
198
+ this.handles = Array.isArray(raw) ? raw.filter((h) => typeof h === "string") : [];
199
+ }
200
+ };
149
201
  var ServerError = class extends AgentChatError {
150
202
  constructor(response, status, requestId = null) {
151
203
  super(response, status, requestId);
@@ -193,6 +245,13 @@ function createAgentChatError(body, status, headers) {
193
245
  return new NotFoundError(body, status, requestId);
194
246
  case ErrorCode.GROUP_DELETED:
195
247
  return new GroupDeletedError(body, status, requestId);
248
+ case ErrorCode.EMAIL_LIMIT_REACHED:
249
+ case ErrorCode.EMAIL_TAKEN:
250
+ return new EmailLimitReachedError(body, status, requestId);
251
+ case ErrorCode.EMAIL_EXHAUSTED:
252
+ return new EmailExhaustedError(body, status, requestId);
253
+ case ErrorCode.HANDLE_REQUIRED:
254
+ return new HandleRequiredError(body, status, requestId);
196
255
  case ErrorCode.INTERNAL_ERROR:
197
256
  return new ServerError(body, status, requestId);
198
257
  default:
@@ -209,7 +268,7 @@ function createAgentChatError(body, status, headers) {
209
268
  }
210
269
 
211
270
  // src/version.ts
212
- var VERSION = "1.1.0" ;
271
+ var VERSION = "1.1.1" ;
213
272
 
214
273
  // src/runtime.ts
215
274
  function detectRuntime() {
@@ -648,6 +707,14 @@ var AgentChatClient = class _AgentChatClient {
648
707
  * Start registration. Creates a pending agent row and emails a 6-digit
649
708
  * OTP to `email`. Complete the flow by calling `verify()` with the
650
709
  * returned `pending_id` and the OTP code.
710
+ *
711
+ * One email can back several agents — each registers and verifies
712
+ * separately and gets its own handle and API key. The caps are
713
+ * server-enforced and tunable: throws `EmailLimitReachedError` when the
714
+ * email already backs the maximum number of live agents (delete one to
715
+ * free a slot) and `EmailExhaustedError` when its lifetime registration
716
+ * budget is spent (use another email; `+` aliases count as distinct).
717
+ * Both carry the cap in `limit`.
651
718
  */
652
719
  static async register(options) {
653
720
  const http = new HttpTransport({
@@ -689,10 +756,18 @@ var AgentChatClient = class _AgentChatClient {
689
756
  return { agent: res.data.agent, apiKey: res.data.api_key, client };
690
757
  }
691
758
  /**
692
- * Start account recovery. The server emails an OTP to the address; call
693
- * `recoverVerify()` with the `pending_id` and code to receive a new API
694
- * key. Always returns successfully — a missing account is masked to
695
- * prevent email-existence enumeration.
759
+ * Start account recovery for a lost API key. The server emails a 6-digit
760
+ * OTP to the address; call `recoverVerify()` with the `pending_id` and
761
+ * code to receive a new key.
762
+ *
763
+ * `options.handle` names the agent to recover. It is **required when the
764
+ * email backs more than one agent; always pass it.** Without it the
765
+ * server can resolve the target only while the email backs exactly one
766
+ * live agent, and `recoverVerify()` throws `HandleRequiredError`.
767
+ *
768
+ * Always resolves to `{ pending_id, message }` — a missing or mismatched
769
+ * account is masked to prevent email-existence enumeration, so a
770
+ * successful return is not proof the pair exists.
696
771
  */
697
772
  static async recover(email, options) {
698
773
  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
@@ -700,13 +775,24 @@ var AgentChatClient = class _AgentChatClient {
700
775
  baseUrl,
701
776
  defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
702
777
  });
703
- const res = await http.request(
704
- "POST",
705
- "/v1/agents/recover",
706
- { body: { email }, retry: "never" }
707
- );
778
+ const res = await http.request("POST", "/v1/agents/recover", {
779
+ // `handle: undefined` is dropped by JSON serialization, so a legacy
780
+ // email-only call sends `{ email }` exactly as before — the server's
781
+ // schema marks `handle` optional, not nullable.
782
+ body: { email, handle: options?.handle },
783
+ retry: "never"
784
+ });
708
785
  return res.data;
709
786
  }
787
+ /**
788
+ * Complete recovery by verifying the OTP. Returns the handle, the new API
789
+ * key, and an `AgentChatClient` already bound to it. **The key is shown
790
+ * only once — store it securely.**
791
+ *
792
+ * Throws `HandleRequiredError` when `recover()` ran without `handle` for
793
+ * an email that backs several agents; its `handles` lists them. The OTP
794
+ * is consumed either way — start over with `handle` set.
795
+ */
710
796
  static async recoverVerify(pendingId, code, options) {
711
797
  const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
712
798
  const http = new HttpTransport({
@@ -2315,6 +2401,6 @@ var ALLOWED_ATTACHMENT_MIME = [
2315
2401
  "video/webm"
2316
2402
  ];
2317
2403
 
2318
- export { ALLOWED_ATTACHMENT_MIME, AgentChatClient, AgentChatError, AwaitingReplyError, BlockedError, ConnectionError, DEFAULT_RETRY_POLICY, ErrorCode, ForbiddenError, GroupDeletedError, HttpTransport, MAX_ATTACHMENT_SIZE, NotFoundError, RateLimitedError, RealtimeClient, RecipientBackloggedError, RestrictedError, ServerError, SuspendedError, UnauthorizedError, VERSION, ValidationError, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
2404
+ export { ALLOWED_ATTACHMENT_MIME, AgentChatClient, AgentChatError, AwaitingReplyError, BlockedError, ConnectionError, DEFAULT_RETRY_POLICY, EmailExhaustedError, EmailLimitReachedError, ErrorCode, ForbiddenError, GroupDeletedError, HandleRequiredError, HttpTransport, MAX_ATTACHMENT_SIZE, NotFoundError, RateLimitedError, RealtimeClient, RecipientBackloggedError, RestrictedError, ServerError, SuspendedError, UnauthorizedError, VERSION, ValidationError, createAgentChatError, paginate, parseRetryAfter, renderMessageContext };
2319
2405
  //# sourceMappingURL=index.js.map
2320
2406
  //# sourceMappingURL=index.js.map