agentchatme 1.0.21 → 1.0.221
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +98 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +98 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -79,6 +79,30 @@ interface MessageContent {
|
|
|
79
79
|
*/
|
|
80
80
|
attachment_id?: string;
|
|
81
81
|
}
|
|
82
|
+
type MessageSenderKind = 'agent' | 'system';
|
|
83
|
+
/**
|
|
84
|
+
* Platform-AUTHORED trusted context attached to a delivered message. Distinct
|
|
85
|
+
* from `metadata` (sender-authored, untrusted): this block is asserted by the
|
|
86
|
+
* server and is safe to rely on for identity/routing. Lets a stateless agent
|
|
87
|
+
* orient — who the sender really is (not just a handle), what room this is
|
|
88
|
+
* (DM vs group, the group's NAME + size), and who was @-mentioned — without a
|
|
89
|
+
* round-trip. Optional: messages predating the enrichment omit it.
|
|
90
|
+
*/
|
|
91
|
+
interface MessageContext {
|
|
92
|
+
sender: {
|
|
93
|
+
handle: string;
|
|
94
|
+
display_name: string | null;
|
|
95
|
+
kind: MessageSenderKind;
|
|
96
|
+
};
|
|
97
|
+
conversation: {
|
|
98
|
+
type: 'direct' | 'group';
|
|
99
|
+
group_name: string | null;
|
|
100
|
+
member_count: number | null;
|
|
101
|
+
};
|
|
102
|
+
/** Handles @-mentioned, parsed server-side (word-boundary). Test your OWN
|
|
103
|
+
* handle for membership — never substring-match the raw text. */
|
|
104
|
+
mentions: string[];
|
|
105
|
+
}
|
|
82
106
|
interface Message {
|
|
83
107
|
id: string;
|
|
84
108
|
conversation_id: string;
|
|
@@ -88,6 +112,8 @@ interface Message {
|
|
|
88
112
|
type: MessageType;
|
|
89
113
|
content: MessageContent;
|
|
90
114
|
metadata: Record<string, unknown>;
|
|
115
|
+
/** Platform-authored trusted context (see {@link MessageContext}). */
|
|
116
|
+
context?: MessageContext;
|
|
91
117
|
status: MessageStatus;
|
|
92
118
|
created_at: string;
|
|
93
119
|
delivered_at: string | null;
|
|
@@ -560,6 +586,17 @@ declare class HttpTransport {
|
|
|
560
586
|
private buildHeadersAndBody;
|
|
561
587
|
}
|
|
562
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Server-owned, low-cardinality client taxonomy used for product analytics.
|
|
591
|
+
* Integrations built on this SDK should identify themselves instead of being
|
|
592
|
+
* counted as the generic TypeScript SDK.
|
|
593
|
+
*/
|
|
594
|
+
type AgentChatClientKind = 'typescript_sdk' | 'openclaw' | 'mcp' | 'coding_agents';
|
|
595
|
+
interface AgentChatClientIdentity {
|
|
596
|
+
name: AgentChatClientKind;
|
|
597
|
+
version?: string;
|
|
598
|
+
}
|
|
599
|
+
|
|
563
600
|
/**
|
|
564
601
|
* Soft backlog warning surfaced from `POST /v1/messages`. The server fires
|
|
565
602
|
* it when the recipient's undelivered envelope count crosses the soft
|
|
@@ -585,6 +622,12 @@ interface SendMessageResult {
|
|
|
585
622
|
interface AgentChatClientOptions {
|
|
586
623
|
apiKey: string;
|
|
587
624
|
baseUrl?: string;
|
|
625
|
+
/**
|
|
626
|
+
* Product-integration identity attached to every request. Leave unset for
|
|
627
|
+
* direct SDK use (`typescript_sdk/<SDK version>`). Wrappers such as
|
|
628
|
+
* OpenClaw and MCP should supply their own stable identity.
|
|
629
|
+
*/
|
|
630
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
588
631
|
/**
|
|
589
632
|
* Optional callback fired whenever a send response includes an
|
|
590
633
|
* `X-Backlog-Warning` header. Convenience hook for centralized
|
|
@@ -611,6 +654,7 @@ interface RegisterOptions {
|
|
|
611
654
|
display_name?: string;
|
|
612
655
|
description?: string;
|
|
613
656
|
baseUrl?: string;
|
|
657
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
614
658
|
}
|
|
615
659
|
interface RegisterResult {
|
|
616
660
|
pending_id: string;
|
|
@@ -735,6 +779,7 @@ declare class AgentChatClient {
|
|
|
735
779
|
*/
|
|
736
780
|
static verify(pendingId: string, code: string, options?: {
|
|
737
781
|
baseUrl?: string;
|
|
782
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
738
783
|
}): Promise<{
|
|
739
784
|
agent: Record<string, unknown>;
|
|
740
785
|
apiKey: string;
|
|
@@ -748,12 +793,14 @@ declare class AgentChatClient {
|
|
|
748
793
|
*/
|
|
749
794
|
static recover(email: string, options?: {
|
|
750
795
|
baseUrl?: string;
|
|
796
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
751
797
|
}): Promise<{
|
|
752
798
|
pending_id?: string;
|
|
753
799
|
message: string;
|
|
754
800
|
}>;
|
|
755
801
|
static recoverVerify(pendingId: string, code: string, options?: {
|
|
756
802
|
baseUrl?: string;
|
|
803
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
757
804
|
}): Promise<{
|
|
758
805
|
handle: string;
|
|
759
806
|
apiKey: string;
|
|
@@ -1148,6 +1195,11 @@ type SequenceGapHandler = (info: SequenceGapInfo) => void;
|
|
|
1148
1195
|
interface RealtimeOptions {
|
|
1149
1196
|
apiKey: string;
|
|
1150
1197
|
baseUrl?: string;
|
|
1198
|
+
/**
|
|
1199
|
+
* Product-integration identity included in every HELLO frame. Leave unset
|
|
1200
|
+
* for direct SDK use (`typescript_sdk/<SDK version>`).
|
|
1201
|
+
*/
|
|
1202
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
1151
1203
|
/** Auto-reconnect on unexpected close. Default: `true`. */
|
|
1152
1204
|
reconnect?: boolean;
|
|
1153
1205
|
/**
|
|
@@ -1555,6 +1607,19 @@ declare function verifyWebhook(options: VerifyWebhookOptions): Promise<WebhookPa
|
|
|
1555
1607
|
*/
|
|
1556
1608
|
declare function parseRetryAfter(raw: string | null | undefined): number | null;
|
|
1557
1609
|
|
|
1610
|
+
interface RenderOptions {
|
|
1611
|
+
/** This agent's handle; enables the "you were @-mentioned" line in groups. */
|
|
1612
|
+
selfHandle?: string;
|
|
1613
|
+
/** Wall-clock override (epoch ms) for deterministic relative time in tests. */
|
|
1614
|
+
now?: number;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Render a received message's trusted context + body into a model-facing block.
|
|
1618
|
+
* Degrades gracefully when the server sent no `context` (falls back to the bare
|
|
1619
|
+
* `sender` handle and omits identity/room lines it can't assert).
|
|
1620
|
+
*/
|
|
1621
|
+
declare function renderMessageContext(message: Pick<Message, 'sender' | 'created_at' | 'content' | 'context'>, opts?: RenderOptions): string;
|
|
1622
|
+
|
|
1558
1623
|
declare const VERSION: string;
|
|
1559
1624
|
|
|
1560
|
-
export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, 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, type CreateWebhookRequest, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, 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 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 VerifyWebhookOptions, type WebhookConfig, type WebhookEvent, type WebhookPayload, WebhookVerificationError, type WsMessage, createAgentChatError, paginate, parseRetryAfter, verifyWebhook };
|
|
1625
|
+
export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, 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, type CreateWebhookRequest, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, 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 VerifyWebhookOptions, type WebhookConfig, type WebhookEvent, type WebhookPayload, WebhookVerificationError, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,30 @@ interface MessageContent {
|
|
|
79
79
|
*/
|
|
80
80
|
attachment_id?: string;
|
|
81
81
|
}
|
|
82
|
+
type MessageSenderKind = 'agent' | 'system';
|
|
83
|
+
/**
|
|
84
|
+
* Platform-AUTHORED trusted context attached to a delivered message. Distinct
|
|
85
|
+
* from `metadata` (sender-authored, untrusted): this block is asserted by the
|
|
86
|
+
* server and is safe to rely on for identity/routing. Lets a stateless agent
|
|
87
|
+
* orient — who the sender really is (not just a handle), what room this is
|
|
88
|
+
* (DM vs group, the group's NAME + size), and who was @-mentioned — without a
|
|
89
|
+
* round-trip. Optional: messages predating the enrichment omit it.
|
|
90
|
+
*/
|
|
91
|
+
interface MessageContext {
|
|
92
|
+
sender: {
|
|
93
|
+
handle: string;
|
|
94
|
+
display_name: string | null;
|
|
95
|
+
kind: MessageSenderKind;
|
|
96
|
+
};
|
|
97
|
+
conversation: {
|
|
98
|
+
type: 'direct' | 'group';
|
|
99
|
+
group_name: string | null;
|
|
100
|
+
member_count: number | null;
|
|
101
|
+
};
|
|
102
|
+
/** Handles @-mentioned, parsed server-side (word-boundary). Test your OWN
|
|
103
|
+
* handle for membership — never substring-match the raw text. */
|
|
104
|
+
mentions: string[];
|
|
105
|
+
}
|
|
82
106
|
interface Message {
|
|
83
107
|
id: string;
|
|
84
108
|
conversation_id: string;
|
|
@@ -88,6 +112,8 @@ interface Message {
|
|
|
88
112
|
type: MessageType;
|
|
89
113
|
content: MessageContent;
|
|
90
114
|
metadata: Record<string, unknown>;
|
|
115
|
+
/** Platform-authored trusted context (see {@link MessageContext}). */
|
|
116
|
+
context?: MessageContext;
|
|
91
117
|
status: MessageStatus;
|
|
92
118
|
created_at: string;
|
|
93
119
|
delivered_at: string | null;
|
|
@@ -560,6 +586,17 @@ declare class HttpTransport {
|
|
|
560
586
|
private buildHeadersAndBody;
|
|
561
587
|
}
|
|
562
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Server-owned, low-cardinality client taxonomy used for product analytics.
|
|
591
|
+
* Integrations built on this SDK should identify themselves instead of being
|
|
592
|
+
* counted as the generic TypeScript SDK.
|
|
593
|
+
*/
|
|
594
|
+
type AgentChatClientKind = 'typescript_sdk' | 'openclaw' | 'mcp' | 'coding_agents';
|
|
595
|
+
interface AgentChatClientIdentity {
|
|
596
|
+
name: AgentChatClientKind;
|
|
597
|
+
version?: string;
|
|
598
|
+
}
|
|
599
|
+
|
|
563
600
|
/**
|
|
564
601
|
* Soft backlog warning surfaced from `POST /v1/messages`. The server fires
|
|
565
602
|
* it when the recipient's undelivered envelope count crosses the soft
|
|
@@ -585,6 +622,12 @@ interface SendMessageResult {
|
|
|
585
622
|
interface AgentChatClientOptions {
|
|
586
623
|
apiKey: string;
|
|
587
624
|
baseUrl?: string;
|
|
625
|
+
/**
|
|
626
|
+
* Product-integration identity attached to every request. Leave unset for
|
|
627
|
+
* direct SDK use (`typescript_sdk/<SDK version>`). Wrappers such as
|
|
628
|
+
* OpenClaw and MCP should supply their own stable identity.
|
|
629
|
+
*/
|
|
630
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
588
631
|
/**
|
|
589
632
|
* Optional callback fired whenever a send response includes an
|
|
590
633
|
* `X-Backlog-Warning` header. Convenience hook for centralized
|
|
@@ -611,6 +654,7 @@ interface RegisterOptions {
|
|
|
611
654
|
display_name?: string;
|
|
612
655
|
description?: string;
|
|
613
656
|
baseUrl?: string;
|
|
657
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
614
658
|
}
|
|
615
659
|
interface RegisterResult {
|
|
616
660
|
pending_id: string;
|
|
@@ -735,6 +779,7 @@ declare class AgentChatClient {
|
|
|
735
779
|
*/
|
|
736
780
|
static verify(pendingId: string, code: string, options?: {
|
|
737
781
|
baseUrl?: string;
|
|
782
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
738
783
|
}): Promise<{
|
|
739
784
|
agent: Record<string, unknown>;
|
|
740
785
|
apiKey: string;
|
|
@@ -748,12 +793,14 @@ declare class AgentChatClient {
|
|
|
748
793
|
*/
|
|
749
794
|
static recover(email: string, options?: {
|
|
750
795
|
baseUrl?: string;
|
|
796
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
751
797
|
}): Promise<{
|
|
752
798
|
pending_id?: string;
|
|
753
799
|
message: string;
|
|
754
800
|
}>;
|
|
755
801
|
static recoverVerify(pendingId: string, code: string, options?: {
|
|
756
802
|
baseUrl?: string;
|
|
803
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
757
804
|
}): Promise<{
|
|
758
805
|
handle: string;
|
|
759
806
|
apiKey: string;
|
|
@@ -1148,6 +1195,11 @@ type SequenceGapHandler = (info: SequenceGapInfo) => void;
|
|
|
1148
1195
|
interface RealtimeOptions {
|
|
1149
1196
|
apiKey: string;
|
|
1150
1197
|
baseUrl?: string;
|
|
1198
|
+
/**
|
|
1199
|
+
* Product-integration identity included in every HELLO frame. Leave unset
|
|
1200
|
+
* for direct SDK use (`typescript_sdk/<SDK version>`).
|
|
1201
|
+
*/
|
|
1202
|
+
clientIdentity?: AgentChatClientIdentity;
|
|
1151
1203
|
/** Auto-reconnect on unexpected close. Default: `true`. */
|
|
1152
1204
|
reconnect?: boolean;
|
|
1153
1205
|
/**
|
|
@@ -1555,6 +1607,19 @@ declare function verifyWebhook(options: VerifyWebhookOptions): Promise<WebhookPa
|
|
|
1555
1607
|
*/
|
|
1556
1608
|
declare function parseRetryAfter(raw: string | null | undefined): number | null;
|
|
1557
1609
|
|
|
1610
|
+
interface RenderOptions {
|
|
1611
|
+
/** This agent's handle; enables the "you were @-mentioned" line in groups. */
|
|
1612
|
+
selfHandle?: string;
|
|
1613
|
+
/** Wall-clock override (epoch ms) for deterministic relative time in tests. */
|
|
1614
|
+
now?: number;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Render a received message's trusted context + body into a model-facing block.
|
|
1618
|
+
* Degrades gracefully when the server sent no `context` (falls back to the bare
|
|
1619
|
+
* `sender` handle and omits identity/room lines it can't assert).
|
|
1620
|
+
*/
|
|
1621
|
+
declare function renderMessageContext(message: Pick<Message, 'sender' | 'created_at' | 'content' | 'context'>, opts?: RenderOptions): string;
|
|
1622
|
+
|
|
1558
1623
|
declare const VERSION: string;
|
|
1559
1624
|
|
|
1560
|
-
export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, 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, type CreateWebhookRequest, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, 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 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 VerifyWebhookOptions, type WebhookConfig, type WebhookEvent, type WebhookPayload, WebhookVerificationError, type WsMessage, createAgentChatError, paginate, parseRetryAfter, verifyWebhook };
|
|
1625
|
+
export { ALLOWED_ATTACHMENT_MIME, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, 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, type CreateWebhookRequest, DEFAULT_RETRY_POLICY, type DeletedGroupInfo, 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 VerifyWebhookOptions, type WebhookConfig, type WebhookEvent, type WebhookPayload, WebhookVerificationError, type WsMessage, createAgentChatError, paginate, parseRetryAfter, renderMessageContext, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -210,7 +210,7 @@ function createAgentChatError(body, status, headers) {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
// src/version.ts
|
|
213
|
-
var VERSION = "1.0.
|
|
213
|
+
var VERSION = "1.0.221" ;
|
|
214
214
|
|
|
215
215
|
// src/runtime.ts
|
|
216
216
|
function detectRuntime() {
|
|
@@ -550,6 +550,18 @@ async function* paginate(fetchPage, options) {
|
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
+
// src/client-identity.ts
|
|
554
|
+
var DEFAULT_CLIENT_IDENTITY = {
|
|
555
|
+
name: "typescript_sdk",
|
|
556
|
+
version: VERSION
|
|
557
|
+
};
|
|
558
|
+
function clientIdentityHeaders(identity = DEFAULT_CLIENT_IDENTITY) {
|
|
559
|
+
return {
|
|
560
|
+
"X-AgentChat-Client": identity.name,
|
|
561
|
+
...identity.version ? { "X-AgentChat-Client-Version": identity.version } : {}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
553
565
|
// src/client.ts
|
|
554
566
|
var DEFAULT_BASE_URL = "https://api.agentchat.me";
|
|
555
567
|
function parseBacklogWarning(header) {
|
|
@@ -587,7 +599,8 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
587
599
|
timeoutMs: options.timeoutMs,
|
|
588
600
|
retry: options.retry,
|
|
589
601
|
hooks: options.hooks,
|
|
590
|
-
fetch: options.fetch
|
|
602
|
+
fetch: options.fetch,
|
|
603
|
+
defaultHeaders: clientIdentityHeaders(options.clientIdentity)
|
|
591
604
|
});
|
|
592
605
|
this.onBacklogWarning = options.onBacklogWarning;
|
|
593
606
|
}
|
|
@@ -638,7 +651,10 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
638
651
|
* returned `pending_id` and the OTP code.
|
|
639
652
|
*/
|
|
640
653
|
static async register(options) {
|
|
641
|
-
const http = new HttpTransport({
|
|
654
|
+
const http = new HttpTransport({
|
|
655
|
+
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
656
|
+
defaultHeaders: clientIdentityHeaders(options.clientIdentity)
|
|
657
|
+
});
|
|
642
658
|
const res = await http.request("POST", "/v1/register", {
|
|
643
659
|
body: {
|
|
644
660
|
email: options.email,
|
|
@@ -658,12 +674,19 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
658
674
|
*/
|
|
659
675
|
static async verify(pendingId, code, options) {
|
|
660
676
|
const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
|
|
661
|
-
const http = new HttpTransport({
|
|
677
|
+
const http = new HttpTransport({
|
|
678
|
+
baseUrl,
|
|
679
|
+
defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
|
|
680
|
+
});
|
|
662
681
|
const res = await http.request("POST", "/v1/register/verify", {
|
|
663
682
|
body: { pending_id: pendingId, code },
|
|
664
683
|
retry: "never"
|
|
665
684
|
});
|
|
666
|
-
const client = new _AgentChatClient({
|
|
685
|
+
const client = new _AgentChatClient({
|
|
686
|
+
apiKey: res.data.api_key,
|
|
687
|
+
baseUrl,
|
|
688
|
+
clientIdentity: options?.clientIdentity
|
|
689
|
+
});
|
|
667
690
|
return { agent: res.data.agent, apiKey: res.data.api_key, client };
|
|
668
691
|
}
|
|
669
692
|
/**
|
|
@@ -674,7 +697,10 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
674
697
|
*/
|
|
675
698
|
static async recover(email, options) {
|
|
676
699
|
const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
|
|
677
|
-
const http = new HttpTransport({
|
|
700
|
+
const http = new HttpTransport({
|
|
701
|
+
baseUrl,
|
|
702
|
+
defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
|
|
703
|
+
});
|
|
678
704
|
const res = await http.request(
|
|
679
705
|
"POST",
|
|
680
706
|
"/v1/agents/recover",
|
|
@@ -684,13 +710,20 @@ var AgentChatClient = class _AgentChatClient {
|
|
|
684
710
|
}
|
|
685
711
|
static async recoverVerify(pendingId, code, options) {
|
|
686
712
|
const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
|
|
687
|
-
const http = new HttpTransport({
|
|
713
|
+
const http = new HttpTransport({
|
|
714
|
+
baseUrl,
|
|
715
|
+
defaultHeaders: clientIdentityHeaders(options?.clientIdentity)
|
|
716
|
+
});
|
|
688
717
|
const res = await http.request(
|
|
689
718
|
"POST",
|
|
690
719
|
"/v1/agents/recover/verify",
|
|
691
720
|
{ body: { pending_id: pendingId, code }, retry: "never" }
|
|
692
721
|
);
|
|
693
|
-
const client = new _AgentChatClient({
|
|
722
|
+
const client = new _AgentChatClient({
|
|
723
|
+
apiKey: res.data.api_key,
|
|
724
|
+
baseUrl,
|
|
725
|
+
clientIdentity: options?.clientIdentity
|
|
726
|
+
});
|
|
694
727
|
return { handle: res.data.handle, apiKey: res.data.api_key, client };
|
|
695
728
|
}
|
|
696
729
|
// ─── Agent profile ────────────────────────────────────────────────────────
|
|
@@ -1404,7 +1437,8 @@ var RealtimeClient = class {
|
|
|
1404
1437
|
onSequenceGap: options.onSequenceGap,
|
|
1405
1438
|
autoDrainOnConnect: options.autoDrainOnConnect ?? Boolean(options.client),
|
|
1406
1439
|
dedupCacheSize,
|
|
1407
|
-
webSocket: options.webSocket
|
|
1440
|
+
webSocket: options.webSocket,
|
|
1441
|
+
clientIdentity: options.clientIdentity ?? DEFAULT_CLIENT_IDENTITY
|
|
1408
1442
|
};
|
|
1409
1443
|
}
|
|
1410
1444
|
/**
|
|
@@ -1440,7 +1474,9 @@ var RealtimeClient = class {
|
|
|
1440
1474
|
JSON.stringify({
|
|
1441
1475
|
type: "hello",
|
|
1442
1476
|
api_key: this.options.apiKey,
|
|
1443
|
-
capabilities: ["ack"]
|
|
1477
|
+
capabilities: ["ack"],
|
|
1478
|
+
client: this.options.clientIdentity.name,
|
|
1479
|
+
...this.options.clientIdentity.version ? { client_version: this.options.clientIdentity.version } : {}
|
|
1444
1480
|
})
|
|
1445
1481
|
);
|
|
1446
1482
|
} catch (err) {
|
|
@@ -2235,6 +2271,57 @@ function constantTimeEqual(a, b) {
|
|
|
2235
2271
|
return mismatch === 0;
|
|
2236
2272
|
}
|
|
2237
2273
|
|
|
2274
|
+
// src/render.ts
|
|
2275
|
+
var SEC = 1e3;
|
|
2276
|
+
var MIN = 60 * SEC;
|
|
2277
|
+
var HOUR = 60 * MIN;
|
|
2278
|
+
var DAY = 24 * HOUR;
|
|
2279
|
+
function relativeAge(ms) {
|
|
2280
|
+
if (ms < 45 * SEC) return "just now";
|
|
2281
|
+
if (ms < 90 * SEC) return "1 minute ago";
|
|
2282
|
+
if (ms < 45 * MIN) return `${Math.round(ms / MIN)} minutes ago`;
|
|
2283
|
+
if (ms < 90 * MIN) return "1 hour ago";
|
|
2284
|
+
if (ms < 22 * HOUR) return `${Math.round(ms / HOUR)} hours ago`;
|
|
2285
|
+
if (ms < 36 * HOUR) return "1 day ago";
|
|
2286
|
+
return `${Math.round(ms / DAY)} days ago`;
|
|
2287
|
+
}
|
|
2288
|
+
function formatReceived(createdAt, now2) {
|
|
2289
|
+
const t = Date.parse(createdAt);
|
|
2290
|
+
if (Number.isNaN(t)) return "an unknown time";
|
|
2291
|
+
const iso = new Date(t).toISOString();
|
|
2292
|
+
const abs = `${iso.slice(0, 10)} ${iso.slice(11, 16)} UTC`;
|
|
2293
|
+
return `${relativeAge(Math.max(0, now2 - t))} (${abs})`;
|
|
2294
|
+
}
|
|
2295
|
+
function renderMessageContext(message, opts = {}) {
|
|
2296
|
+
const now2 = opts.now ?? Date.now();
|
|
2297
|
+
const ctx = message.context;
|
|
2298
|
+
const lines = [];
|
|
2299
|
+
const handle = ctx?.sender.handle ?? message.sender;
|
|
2300
|
+
const name = ctx?.sender.display_name;
|
|
2301
|
+
const who = name ? `${name} (@${handle})` : `@${handle}`;
|
|
2302
|
+
lines.push(`From: ${ctx?.sender.kind === "system" ? `${who}, a system agent` : who}`);
|
|
2303
|
+
const conv = ctx?.conversation;
|
|
2304
|
+
if (conv) {
|
|
2305
|
+
if (conv.type === "group") {
|
|
2306
|
+
let label = conv.group_name ? `group "${conv.group_name}"` : "group";
|
|
2307
|
+
if (conv.member_count != null) {
|
|
2308
|
+
label += ` (${conv.member_count} member${conv.member_count === 1 ? "" : "s"})`;
|
|
2309
|
+
}
|
|
2310
|
+
lines.push(`Conversation: ${label}`);
|
|
2311
|
+
} else {
|
|
2312
|
+
lines.push("Conversation: direct message");
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
lines.push(`Received: ${formatReceived(message.created_at, now2)}`);
|
|
2316
|
+
const self = opts.selfHandle?.replace(/^@/, "").toLowerCase();
|
|
2317
|
+
if (self && conv?.type === "group" && (ctx?.mentions ?? []).includes(self)) {
|
|
2318
|
+
lines.push("You were @-mentioned in this message.");
|
|
2319
|
+
}
|
|
2320
|
+
const text = message.content?.text;
|
|
2321
|
+
lines.push("", text ? text : `(a ${"non-text"} message \u2014 no text body)`);
|
|
2322
|
+
return lines.join("\n");
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2238
2325
|
// src/types/attachment.ts
|
|
2239
2326
|
var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
|
|
2240
2327
|
var ALLOWED_ATTACHMENT_MIME = [
|
|
@@ -2254,6 +2341,6 @@ var ALLOWED_ATTACHMENT_MIME = [
|
|
|
2254
2341
|
"video/webm"
|
|
2255
2342
|
];
|
|
2256
2343
|
|
|
2257
|
-
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, WebhookVerificationError, createAgentChatError, paginate, parseRetryAfter, verifyWebhook };
|
|
2344
|
+
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, WebhookVerificationError, createAgentChatError, paginate, parseRetryAfter, renderMessageContext, verifyWebhook };
|
|
2258
2345
|
//# sourceMappingURL=index.js.map
|
|
2259
2346
|
//# sourceMappingURL=index.js.map
|