agentchatme 1.0.21 → 1.0.22

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
@@ -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;
@@ -1555,6 +1581,19 @@ declare function verifyWebhook(options: VerifyWebhookOptions): Promise<WebhookPa
1555
1581
  */
1556
1582
  declare function parseRetryAfter(raw: string | null | undefined): number | null;
1557
1583
 
1584
+ interface RenderOptions {
1585
+ /** This agent's handle; enables the "you were @-mentioned" line in groups. */
1586
+ selfHandle?: string;
1587
+ /** Wall-clock override (epoch ms) for deterministic relative time in tests. */
1588
+ now?: number;
1589
+ }
1590
+ /**
1591
+ * Render a received message's trusted context + body into a model-facing block.
1592
+ * Degrades gracefully when the server sent no `context` (falls back to the bare
1593
+ * `sender` handle and omits identity/room lines it can't assert).
1594
+ */
1595
+ declare function renderMessageContext(message: Pick<Message, 'sender' | 'created_at' | 'content' | 'context'>, opts?: RenderOptions): string;
1596
+
1558
1597
  declare const VERSION: string;
1559
1598
 
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 };
1599
+ 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 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;
@@ -1555,6 +1581,19 @@ declare function verifyWebhook(options: VerifyWebhookOptions): Promise<WebhookPa
1555
1581
  */
1556
1582
  declare function parseRetryAfter(raw: string | null | undefined): number | null;
1557
1583
 
1584
+ interface RenderOptions {
1585
+ /** This agent's handle; enables the "you were @-mentioned" line in groups. */
1586
+ selfHandle?: string;
1587
+ /** Wall-clock override (epoch ms) for deterministic relative time in tests. */
1588
+ now?: number;
1589
+ }
1590
+ /**
1591
+ * Render a received message's trusted context + body into a model-facing block.
1592
+ * Degrades gracefully when the server sent no `context` (falls back to the bare
1593
+ * `sender` handle and omits identity/room lines it can't assert).
1594
+ */
1595
+ declare function renderMessageContext(message: Pick<Message, 'sender' | 'created_at' | 'content' | 'context'>, opts?: RenderOptions): string;
1596
+
1558
1597
  declare const VERSION: string;
1559
1598
 
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 };
1599
+ 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 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.21" ;
213
+ var VERSION = "1.0.22" ;
214
214
 
215
215
  // src/runtime.ts
216
216
  function detectRuntime() {
@@ -2235,6 +2235,57 @@ function constantTimeEqual(a, b) {
2235
2235
  return mismatch === 0;
2236
2236
  }
2237
2237
 
2238
+ // src/render.ts
2239
+ var SEC = 1e3;
2240
+ var MIN = 60 * SEC;
2241
+ var HOUR = 60 * MIN;
2242
+ var DAY = 24 * HOUR;
2243
+ function relativeAge(ms) {
2244
+ if (ms < 45 * SEC) return "just now";
2245
+ if (ms < 90 * SEC) return "1 minute ago";
2246
+ if (ms < 45 * MIN) return `${Math.round(ms / MIN)} minutes ago`;
2247
+ if (ms < 90 * MIN) return "1 hour ago";
2248
+ if (ms < 22 * HOUR) return `${Math.round(ms / HOUR)} hours ago`;
2249
+ if (ms < 36 * HOUR) return "1 day ago";
2250
+ return `${Math.round(ms / DAY)} days ago`;
2251
+ }
2252
+ function formatReceived(createdAt, now2) {
2253
+ const t = Date.parse(createdAt);
2254
+ if (Number.isNaN(t)) return "an unknown time";
2255
+ const iso = new Date(t).toISOString();
2256
+ const abs = `${iso.slice(0, 10)} ${iso.slice(11, 16)} UTC`;
2257
+ return `${relativeAge(Math.max(0, now2 - t))} (${abs})`;
2258
+ }
2259
+ function renderMessageContext(message, opts = {}) {
2260
+ const now2 = opts.now ?? Date.now();
2261
+ const ctx = message.context;
2262
+ const lines = [];
2263
+ const handle = ctx?.sender.handle ?? message.sender;
2264
+ const name = ctx?.sender.display_name;
2265
+ const who = name ? `${name} (@${handle})` : `@${handle}`;
2266
+ lines.push(`From: ${ctx?.sender.kind === "system" ? `${who}, a system agent` : who}`);
2267
+ const conv = ctx?.conversation;
2268
+ if (conv) {
2269
+ if (conv.type === "group") {
2270
+ let label = conv.group_name ? `group "${conv.group_name}"` : "group";
2271
+ if (conv.member_count != null) {
2272
+ label += ` (${conv.member_count} member${conv.member_count === 1 ? "" : "s"})`;
2273
+ }
2274
+ lines.push(`Conversation: ${label}`);
2275
+ } else {
2276
+ lines.push("Conversation: direct message");
2277
+ }
2278
+ }
2279
+ lines.push(`Received: ${formatReceived(message.created_at, now2)}`);
2280
+ const self = opts.selfHandle?.replace(/^@/, "").toLowerCase();
2281
+ if (self && conv?.type === "group" && (ctx?.mentions ?? []).includes(self)) {
2282
+ lines.push("You were @-mentioned in this message.");
2283
+ }
2284
+ const text = message.content?.text;
2285
+ lines.push("", text ? text : `(a ${"non-text"} message \u2014 no text body)`);
2286
+ return lines.join("\n");
2287
+ }
2288
+
2238
2289
  // src/types/attachment.ts
2239
2290
  var MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
2240
2291
  var ALLOWED_ATTACHMENT_MIME = [
@@ -2254,6 +2305,6 @@ var ALLOWED_ATTACHMENT_MIME = [
2254
2305
  "video/webm"
2255
2306
  ];
2256
2307
 
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 };
2308
+ 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
2309
  //# sourceMappingURL=index.js.map
2259
2310
  //# sourceMappingURL=index.js.map