chat 4.18.0 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{chunk-WAB7KMH4.js → chunk-JW7GYSMH.js} +3 -3
- package/dist/chunk-JW7GYSMH.js.map +1 -0
- package/dist/index.d.ts +220 -13
- package/dist/index.js +274 -56
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/docs/adapters/whatsapp.mdx +222 -0
- package/docs/{adapters/index.mdx → adapters.mdx} +46 -65
- package/docs/api/channel.mdx +15 -0
- package/docs/api/index.mdx +1 -0
- package/docs/api/thread.mdx +50 -0
- package/docs/contributing/building.mdx +1 -0
- package/docs/error-handling.mdx +2 -2
- package/docs/getting-started.mdx +2 -0
- package/docs/guides/code-review-hono.mdx +3 -3
- package/docs/guides/discord-nuxt.mdx +3 -2
- package/docs/guides/durable-chat-sessions-nextjs.mdx +331 -0
- package/docs/guides/meta.json +7 -1
- package/docs/guides/scheduled-posts-neon.mdx +447 -0
- package/docs/guides/slack-nextjs.mdx +3 -2
- package/docs/index.mdx +3 -1
- package/docs/meta.json +3 -4
- package/docs/slash-commands.mdx +4 -4
- package/docs/{state/index.mdx → state.mdx} +24 -12
- package/docs/threads-messages-channels.mdx +17 -0
- package/docs/usage.mdx +5 -0
- package/package.json +1 -1
- package/dist/chunk-WAB7KMH4.js.map +0 -1
- package/docs/adapters/discord.mdx +0 -217
- package/docs/adapters/gchat.mdx +0 -237
- package/docs/adapters/github.mdx +0 -222
- package/docs/adapters/linear.mdx +0 -206
- package/docs/adapters/meta.json +0 -13
- package/docs/adapters/slack.mdx +0 -314
- package/docs/adapters/teams.mdx +0 -287
- package/docs/adapters/telegram.mdx +0 -161
- package/docs/state/ioredis.mdx +0 -81
- package/docs/state/memory.mdx +0 -52
- package/docs/state/meta.json +0 -4
- package/docs/state/postgres.mdx +0 -98
- package/docs/state/redis.mdx +0 -100
- package/dist/{jsx-runtime-BYavlUk9.d.ts → jsx-runtime-C2ATKxHQ.d.ts} +95 -95
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
2
|
-
import { C as CardElement, M as ModalElement, a as ChatElement, b as CardChild, A as ActionsComponent, B as ButtonComponent, c as CardComponent, d as cardChildToFallbackText$1, e as CardLinkComponent, T as TextComponent, D as DividerComponent, F as FieldComponent, f as FieldsComponent, g as fromReactElement$1, I as ImageComponent, i as isCardElement$1, h as isJSX$1, L as LinkButtonComponent, S as SectionComponent, j as Table$2, t as toCardElement$1, k as toModalElement$1, l as fromReactModalElement$1, m as isModalElement$1, n as ModalComponent, R as RadioSelectComponent, o as SelectComponent, p as SelectOptionComponent, q as TextInputComponent } from './jsx-runtime-BYavlUk9.js';
|
|
3
|
-
export { r as ActionsElement, s as ButtonElement, u as ButtonOptions, V as ButtonProps, v as ButtonStyle, W as CardJSXElement, X as CardJSXProps, Y as CardLinkProps, w as CardOptions, Z as CardProps, _ as ContainerProps, x as DividerElement, $ as DividerProps, y as FieldElement, a0 as FieldProps, z as FieldsElement, E as ImageElement, a1 as ImageProps, G as LinkButtonElement, H as LinkButtonOptions, a2 as LinkButtonProps, J as LinkElement, a8 as ModalChild, a9 as ModalOptions, a3 as ModalProps, aa as RadioSelectElement, ab as RadioSelectOptions, K as SectionElement, ac as SelectElement, ad as SelectOptionElement, a4 as SelectOptionProps, ae as SelectOptions, a5 as SelectProps, N as TableAlignment, O as TableElement, P as TableOptions, Q as TextElement, af as TextInputElement, ag as TextInputOptions, a6 as TextInputProps, a7 as TextProps, U as TextStyle } from './jsx-runtime-BYavlUk9.js';
|
|
4
2
|
import { Root, List, Content, Blockquote, Code, Emphasis, InlineCode, Delete, Link, ListItem, Paragraph, Strong, TableCell, Table as Table$1, TableRow, Text } from 'mdast';
|
|
5
3
|
export { Blockquote, Code, Content, Delete, Emphasis, InlineCode, Link, List, ListItem, Table as MdastTable, Paragraph, Root, Strong, TableCell, TableRow, Text } from 'mdast';
|
|
4
|
+
import { C as CardElement, M as ModalElement, a as ChatElement, b as CardChild, A as ActionsComponent, B as ButtonComponent, c as CardComponent, d as cardChildToFallbackText$1, e as CardLinkComponent, T as TextComponent, D as DividerComponent, F as FieldComponent, f as FieldsComponent, g as fromReactElement$1, I as ImageComponent, i as isCardElement$1, h as isJSX$1, L as LinkButtonComponent, S as SectionComponent, j as Table$2, t as toCardElement$1, k as toModalElement$1, l as fromReactModalElement$1, m as isModalElement$1, n as ModalComponent, R as RadioSelectComponent, o as SelectComponent, p as SelectOptionComponent, q as TextInputComponent } from './jsx-runtime-C2ATKxHQ.js';
|
|
5
|
+
export { r as ActionsElement, s as ButtonElement, u as ButtonOptions, V as ButtonProps, v as ButtonStyle, W as CardJSXElement, X as CardJSXProps, Y as CardLinkProps, w as CardOptions, Z as CardProps, _ as ContainerProps, x as DividerElement, $ as DividerProps, y as FieldElement, a0 as FieldProps, z as FieldsElement, E as ImageElement, a1 as ImageProps, G as LinkButtonElement, H as LinkButtonOptions, a2 as LinkButtonProps, J as LinkElement, a8 as ModalChild, a9 as ModalOptions, a3 as ModalProps, aa as RadioSelectElement, ab as RadioSelectOptions, K as SectionElement, ac as SelectElement, ad as SelectOptionElement, a4 as SelectOptionProps, ae as SelectOptions, a5 as SelectProps, N as TableAlignment, O as TableElement, P as TableOptions, Q as TextElement, af as TextInputElement, ag as TextInputOptions, a6 as TextInputProps, a7 as TextProps, U as TextStyle } from './jsx-runtime-C2ATKxHQ.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Logger types and implementations for chat-sdk
|
|
@@ -77,6 +77,28 @@ interface ChatConfig<TAdapters extends Record<string, Adapter> = Record<string,
|
|
|
77
77
|
* Pass "silent" to disable all logging.
|
|
78
78
|
*/
|
|
79
79
|
logger?: Logger | LogLevel;
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for persistent message history.
|
|
82
|
+
* Only used by adapters that set `persistMessageHistory: true`.
|
|
83
|
+
*/
|
|
84
|
+
messageHistory?: {
|
|
85
|
+
/** Maximum messages to store per thread (default: 100) */
|
|
86
|
+
maxMessages?: number;
|
|
87
|
+
/** TTL for cached history in milliseconds (default: 7 days) */
|
|
88
|
+
ttlMs?: number;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Behavior when a thread lock cannot be acquired (another handler is processing).
|
|
92
|
+
* - `'drop'` (default) — throw `LockError`, preserving current behavior
|
|
93
|
+
* - `'force'` — force-release the existing lock and re-acquire
|
|
94
|
+
* - callback — custom logic receiving `(threadId, message)`, return `'force'` or `'drop'`
|
|
95
|
+
*
|
|
96
|
+
* When `'force'` is used, the previous handler continues executing — only the lock
|
|
97
|
+
* is released, not the handler itself. This means two handlers may run concurrently
|
|
98
|
+
* on the same thread. The old handler's `releaseLock()` call becomes a no-op since
|
|
99
|
+
* the token no longer matches.
|
|
100
|
+
*/
|
|
101
|
+
onLockConflict?: "force" | "drop" | ((threadId: string, message: Message) => "force" | "drop" | Promise<"force" | "drop">);
|
|
80
102
|
/** State adapter for subscriptions and locking */
|
|
81
103
|
state: StateAdapter;
|
|
82
104
|
/**
|
|
@@ -122,7 +144,7 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
122
144
|
* Default fallback: first two colon-separated parts (e.g., "slack:C123").
|
|
123
145
|
* Adapters with different structures should override this.
|
|
124
146
|
*/
|
|
125
|
-
channelIdFromThreadId
|
|
147
|
+
channelIdFromThreadId(threadId: string): string;
|
|
126
148
|
/** Decode thread ID string back to platform-specific data */
|
|
127
149
|
decodeThreadId(threadId: string): TThreadId;
|
|
128
150
|
/** Delete a message */
|
|
@@ -233,6 +255,11 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
233
255
|
}>;
|
|
234
256
|
/** Parse platform message format to normalized format */
|
|
235
257
|
parseMessage(raw: TRawMessage): Message<TRawMessage>;
|
|
258
|
+
/**
|
|
259
|
+
* When true, the SDK persists message history in the state adapter for this platform.
|
|
260
|
+
* Use this for platforms that lack server-side message history APIs (e.g., WhatsApp, Telegram).
|
|
261
|
+
*/
|
|
262
|
+
readonly persistMessageHistory?: boolean;
|
|
236
263
|
/**
|
|
237
264
|
* Post a message to channel top-level (not in a thread).
|
|
238
265
|
*/
|
|
@@ -248,13 +275,27 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
248
275
|
* @param message - The message content
|
|
249
276
|
* @returns EphemeralMessage with usedFallback: false
|
|
250
277
|
*/
|
|
251
|
-
postEphemeral?(threadId: string, userId: string, message: AdapterPostableMessage): Promise<EphemeralMessage
|
|
278
|
+
postEphemeral?(threadId: string, userId: string, message: AdapterPostableMessage): Promise<EphemeralMessage<TRawMessage>>;
|
|
252
279
|
/** Post a message to a thread */
|
|
253
280
|
postMessage(threadId: string, message: AdapterPostableMessage): Promise<RawMessage<TRawMessage>>;
|
|
254
281
|
/** Remove a reaction from a message */
|
|
255
282
|
removeReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
256
283
|
/** Render formatted content to platform-specific string */
|
|
257
284
|
renderFormatted(content: FormattedContent): string;
|
|
285
|
+
/**
|
|
286
|
+
* Schedule a message for future delivery.
|
|
287
|
+
*
|
|
288
|
+
* Optional — only supported by adapters with native scheduling APIs (e.g., Slack).
|
|
289
|
+
* Thread.schedule() will throw NotImplementedError if this method is absent.
|
|
290
|
+
*
|
|
291
|
+
* @param threadId - The thread to post in
|
|
292
|
+
* @param message - The message content
|
|
293
|
+
* @param options - Scheduling options including the target delivery time
|
|
294
|
+
* @returns A ScheduledMessage with cancel() capability
|
|
295
|
+
*/
|
|
296
|
+
scheduleMessage?(threadId: string, message: AdapterPostableMessage, options: {
|
|
297
|
+
postAt: Date;
|
|
298
|
+
}): Promise<ScheduledMessage<TRawMessage>>;
|
|
258
299
|
/** Show typing indicator */
|
|
259
300
|
startTyping(threadId: string, status?: string): Promise<void>;
|
|
260
301
|
/**
|
|
@@ -398,6 +439,11 @@ interface ChatInstance {
|
|
|
398
439
|
interface StateAdapter {
|
|
399
440
|
/** Acquire a lock on a thread (returns null if already locked) */
|
|
400
441
|
acquireLock(threadId: string, ttlMs: number): Promise<Lock | null>;
|
|
442
|
+
/** Atomically append a value to a list. Trims to maxLength (keeping newest). Refreshes TTL. */
|
|
443
|
+
appendToList(key: string, value: unknown, options?: {
|
|
444
|
+
maxLength?: number;
|
|
445
|
+
ttlMs?: number;
|
|
446
|
+
}): Promise<void>;
|
|
401
447
|
/** Connect to the state backend */
|
|
402
448
|
connect(): Promise<void>;
|
|
403
449
|
/** Delete a cached value */
|
|
@@ -406,8 +452,16 @@ interface StateAdapter {
|
|
|
406
452
|
disconnect(): Promise<void>;
|
|
407
453
|
/** Extend a lock's TTL */
|
|
408
454
|
extendLock(lock: Lock, ttlMs: number): Promise<boolean>;
|
|
455
|
+
/**
|
|
456
|
+
* Force-release a lock on a thread, regardless of ownership token.
|
|
457
|
+
* The previous lock holder's handler continues running — only the lock is released.
|
|
458
|
+
* The old handler's `releaseLock()` becomes a no-op (token mismatch).
|
|
459
|
+
*/
|
|
460
|
+
forceReleaseLock(threadId: string): Promise<void>;
|
|
409
461
|
/** Get a cached value by key */
|
|
410
462
|
get<T = unknown>(key: string): Promise<T | null>;
|
|
463
|
+
/** Read all values from a list in insertion order. Returns empty array if key does not exist. */
|
|
464
|
+
getList<T = unknown>(key: string): Promise<T[]>;
|
|
411
465
|
/** Check if subscribed to a thread */
|
|
412
466
|
isSubscribed(threadId: string): Promise<boolean>;
|
|
413
467
|
/** Release a lock */
|
|
@@ -456,7 +510,30 @@ interface Postable<TState = Record<string, unknown>, TRawMessage = unknown> {
|
|
|
456
510
|
/**
|
|
457
511
|
* Post an ephemeral message visible only to a specific user.
|
|
458
512
|
*/
|
|
459
|
-
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
513
|
+
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage<TRawMessage> | null>;
|
|
514
|
+
/**
|
|
515
|
+
* Schedule a message for future delivery.
|
|
516
|
+
*
|
|
517
|
+
* Currently only supported by the Slack adapter. Other adapters
|
|
518
|
+
* will throw NotImplementedError.
|
|
519
|
+
*
|
|
520
|
+
* @param message - The message content (streaming not supported)
|
|
521
|
+
* @param options - Scheduling options including the target delivery time
|
|
522
|
+
* @returns A ScheduledMessage with cancel() capability
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```typescript
|
|
526
|
+
* const scheduled = await thread.schedule("Reminder: standup!", {
|
|
527
|
+
* postAt: new Date("2026-03-09T09:00:00Z"),
|
|
528
|
+
* });
|
|
529
|
+
*
|
|
530
|
+
* // Cancel before it's sent
|
|
531
|
+
* await scheduled.cancel();
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
schedule(message: AdapterPostableMessage | ChatElement, options: {
|
|
535
|
+
postAt: Date;
|
|
536
|
+
}): Promise<ScheduledMessage<TRawMessage>>;
|
|
460
537
|
/**
|
|
461
538
|
* Set the state. Merges with existing state by default.
|
|
462
539
|
*/
|
|
@@ -630,7 +707,7 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> extend
|
|
|
630
707
|
* }
|
|
631
708
|
* ```
|
|
632
709
|
*/
|
|
633
|
-
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
710
|
+
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage<TRawMessage> | null>;
|
|
634
711
|
/** Recently fetched messages (cached) */
|
|
635
712
|
recentMessages: Message<TRawMessage>[];
|
|
636
713
|
/**
|
|
@@ -796,11 +873,11 @@ interface SentMessage<TRawMessage = unknown> extends Message<TRawMessage> {
|
|
|
796
873
|
* Ephemeral messages are visible only to a specific user and typically
|
|
797
874
|
* cannot be edited or deleted (platform-dependent).
|
|
798
875
|
*/
|
|
799
|
-
interface EphemeralMessage {
|
|
876
|
+
interface EphemeralMessage<TRawMessage = unknown> {
|
|
800
877
|
/** Message ID (may be empty for some platforms) */
|
|
801
878
|
id: string;
|
|
802
879
|
/** Platform-specific raw response */
|
|
803
|
-
raw:
|
|
880
|
+
raw: TRawMessage;
|
|
804
881
|
/** Thread ID where message was sent (or DM thread if fallback was used) */
|
|
805
882
|
threadId: string;
|
|
806
883
|
/** Whether this used native ephemeral or fell back to DM */
|
|
@@ -818,6 +895,24 @@ interface PostEphemeralOptions {
|
|
|
818
895
|
*/
|
|
819
896
|
fallbackToDM: boolean;
|
|
820
897
|
}
|
|
898
|
+
/**
|
|
899
|
+
* Result of scheduling a message for future delivery.
|
|
900
|
+
*
|
|
901
|
+
* Currently only supported by the Slack adapter via `chat.scheduleMessage`.
|
|
902
|
+
* Other adapters will throw `NotImplementedError` when `schedule()` is called.
|
|
903
|
+
*/
|
|
904
|
+
interface ScheduledMessage<TRawMessage = unknown> {
|
|
905
|
+
/** Cancel the scheduled message before it's sent */
|
|
906
|
+
cancel(): Promise<void>;
|
|
907
|
+
/** Channel ID where the message will be posted */
|
|
908
|
+
channelId: string;
|
|
909
|
+
/** When the message will be sent */
|
|
910
|
+
postAt: Date;
|
|
911
|
+
/** Platform-specific raw response */
|
|
912
|
+
raw: TRawMessage;
|
|
913
|
+
/** Platform-specific scheduled message ID */
|
|
914
|
+
scheduledMessageId: string;
|
|
915
|
+
}
|
|
821
916
|
/**
|
|
822
917
|
* Input type for adapter postMessage/editMessage methods.
|
|
823
918
|
* This excludes streams since adapters handle content synchronously.
|
|
@@ -944,6 +1039,15 @@ interface FileUpload {
|
|
|
944
1039
|
* ```
|
|
945
1040
|
*/
|
|
946
1041
|
type MentionHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => void | Promise<void>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Handler for direct messages (1:1 conversations with the bot).
|
|
1044
|
+
*
|
|
1045
|
+
* Registered via `chat.onDirectMessage(handler)`. Called when a message
|
|
1046
|
+
* is received in a DM thread that is not subscribed. If no `onDirectMessage`
|
|
1047
|
+
* handlers are registered, DMs fall through to `onNewMention` for backward
|
|
1048
|
+
* compatibility.
|
|
1049
|
+
*/
|
|
1050
|
+
type DirectMessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message, channel: Channel<TState>) => void | Promise<void>;
|
|
947
1051
|
/**
|
|
948
1052
|
* Handler for messages matching a regex pattern.
|
|
949
1053
|
*
|
|
@@ -1520,6 +1624,70 @@ declare class Message<TRawMessage = unknown> {
|
|
|
1520
1624
|
static [WORKFLOW_DESERIALIZE](data: SerializedMessage): Message;
|
|
1521
1625
|
}
|
|
1522
1626
|
|
|
1627
|
+
/**
|
|
1628
|
+
* A message formatted for AI SDK consumption.
|
|
1629
|
+
*/
|
|
1630
|
+
interface AiMessage {
|
|
1631
|
+
content: string;
|
|
1632
|
+
role: "user" | "assistant";
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Options for converting messages to AI SDK format.
|
|
1636
|
+
*/
|
|
1637
|
+
interface ToAiMessagesOptions {
|
|
1638
|
+
/** When true, prefixes user messages with "[username]: " for multi-user context */
|
|
1639
|
+
includeNames?: boolean;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Convert chat SDK messages to AI SDK conversation format.
|
|
1643
|
+
*
|
|
1644
|
+
* - Filters out messages with empty/whitespace-only text
|
|
1645
|
+
* - Maps `author.isMe === true` to `"assistant"`, otherwise `"user"`
|
|
1646
|
+
* - Uses `message.text` for content
|
|
1647
|
+
*
|
|
1648
|
+
* Works with `FetchResult.messages`, `thread.recentMessages`, or collected iterables.
|
|
1649
|
+
*
|
|
1650
|
+
* @example
|
|
1651
|
+
* ```typescript
|
|
1652
|
+
* const result = await thread.adapter.fetchMessages(thread.id, { limit: 20 });
|
|
1653
|
+
* const history = toAiMessages(result.messages);
|
|
1654
|
+
* const response = await agent.stream({ prompt: history });
|
|
1655
|
+
* ```
|
|
1656
|
+
*/
|
|
1657
|
+
declare function toAiMessages(messages: Message[], options?: ToAiMessagesOptions): AiMessage[];
|
|
1658
|
+
|
|
1659
|
+
interface MessageHistoryConfig {
|
|
1660
|
+
/** Maximum messages to keep per thread (default: 100) */
|
|
1661
|
+
maxMessages?: number;
|
|
1662
|
+
/** TTL for cached history in milliseconds (default: 7 days) */
|
|
1663
|
+
ttlMs?: number;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Persistent message history cache backed by the StateAdapter.
|
|
1667
|
+
*
|
|
1668
|
+
* Used by adapters that lack server-side message history APIs (e.g., WhatsApp, Telegram).
|
|
1669
|
+
* Messages are atomically appended via `state.appendToList()`, which is safe
|
|
1670
|
+
* without holding a thread lock.
|
|
1671
|
+
*/
|
|
1672
|
+
declare class MessageHistoryCache {
|
|
1673
|
+
private readonly state;
|
|
1674
|
+
private readonly maxMessages;
|
|
1675
|
+
private readonly ttlMs;
|
|
1676
|
+
constructor(state: StateAdapter, config?: MessageHistoryConfig);
|
|
1677
|
+
/**
|
|
1678
|
+
* Atomically append a message to the history for a thread.
|
|
1679
|
+
* Trims to maxMessages (keeps newest) and refreshes TTL.
|
|
1680
|
+
*/
|
|
1681
|
+
append(threadId: string, message: Message): Promise<void>;
|
|
1682
|
+
/**
|
|
1683
|
+
* Get messages for a thread in chronological order (oldest first).
|
|
1684
|
+
*
|
|
1685
|
+
* @param threadId - The thread ID
|
|
1686
|
+
* @param limit - Optional limit on number of messages to return (returns newest N)
|
|
1687
|
+
*/
|
|
1688
|
+
getMessages(threadId: string, limit?: number): Promise<Message[]>;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1523
1691
|
/**
|
|
1524
1692
|
* Serialized channel data for passing to external systems (e.g., workflow engines).
|
|
1525
1693
|
*/
|
|
@@ -1536,6 +1704,7 @@ interface ChannelImplConfigWithAdapter {
|
|
|
1536
1704
|
adapter: Adapter;
|
|
1537
1705
|
id: string;
|
|
1538
1706
|
isDM?: boolean;
|
|
1707
|
+
messageHistory?: MessageHistoryCache;
|
|
1539
1708
|
stateAdapter: StateAdapter;
|
|
1540
1709
|
}
|
|
1541
1710
|
/**
|
|
@@ -1554,6 +1723,7 @@ declare class ChannelImpl<TState = Record<string, unknown>> implements Channel<T
|
|
|
1554
1723
|
private readonly _adapterName?;
|
|
1555
1724
|
private _stateAdapterInstance?;
|
|
1556
1725
|
private _name;
|
|
1726
|
+
private readonly _messageHistory?;
|
|
1557
1727
|
constructor(config: ChannelImplConfig);
|
|
1558
1728
|
get adapter(): Adapter;
|
|
1559
1729
|
private get _stateAdapter();
|
|
@@ -1576,6 +1746,9 @@ declare class ChannelImpl<TState = Record<string, unknown>> implements Channel<T
|
|
|
1576
1746
|
post(message: string | PostableMessage | ChatElement): Promise<SentMessage>;
|
|
1577
1747
|
private postSingleMessage;
|
|
1578
1748
|
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
1749
|
+
schedule(message: AdapterPostableMessage | ChatElement, options: {
|
|
1750
|
+
postAt: Date;
|
|
1751
|
+
}): Promise<ScheduledMessage>;
|
|
1579
1752
|
startTyping(status?: string): Promise<void>;
|
|
1580
1753
|
mentionUser(userId: string): string;
|
|
1581
1754
|
toJSON(): SerializedChannel;
|
|
@@ -1586,8 +1759,6 @@ declare class ChannelImpl<TState = Record<string, unknown>> implements Channel<T
|
|
|
1586
1759
|
}
|
|
1587
1760
|
/**
|
|
1588
1761
|
* Derive the channel ID from a thread ID.
|
|
1589
|
-
* Uses adapter.channelIdFromThreadId if available, otherwise defaults to
|
|
1590
|
-
* first two colon-separated parts.
|
|
1591
1762
|
*/
|
|
1592
1763
|
declare function deriveChannelId(adapter: Adapter, threadId: string): string;
|
|
1593
1764
|
|
|
@@ -1662,7 +1833,10 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1662
1833
|
private readonly _streamingUpdateIntervalMs;
|
|
1663
1834
|
private readonly _fallbackStreamingPlaceholderText;
|
|
1664
1835
|
private readonly _dedupeTtlMs;
|
|
1836
|
+
private readonly _onLockConflict;
|
|
1837
|
+
private readonly _messageHistory;
|
|
1665
1838
|
private readonly mentionHandlers;
|
|
1839
|
+
private readonly directMessageHandlers;
|
|
1666
1840
|
private readonly messagePatterns;
|
|
1667
1841
|
private readonly subscribedMessageHandlers;
|
|
1668
1842
|
private readonly reactionHandlers;
|
|
@@ -1732,6 +1906,24 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1732
1906
|
* ```
|
|
1733
1907
|
*/
|
|
1734
1908
|
onNewMention(handler: MentionHandler<TState>): void;
|
|
1909
|
+
/**
|
|
1910
|
+
* Register a handler for direct messages.
|
|
1911
|
+
*
|
|
1912
|
+
* Called when a message is received in a DM thread that is not subscribed.
|
|
1913
|
+
* If no `onDirectMessage` handlers are registered, DMs fall through to
|
|
1914
|
+
* `onNewMention` for backward compatibility.
|
|
1915
|
+
*
|
|
1916
|
+
* @param handler - Handler called for DM messages
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```typescript
|
|
1920
|
+
* chat.onDirectMessage(async (thread, message) => {
|
|
1921
|
+
* await thread.subscribe();
|
|
1922
|
+
* await thread.post("Thanks for the DM!");
|
|
1923
|
+
* });
|
|
1924
|
+
* ```
|
|
1925
|
+
*/
|
|
1926
|
+
onDirectMessage(handler: DirectMessageHandler<TState>): void;
|
|
1735
1927
|
/**
|
|
1736
1928
|
* Register a handler for messages matching a regex pattern.
|
|
1737
1929
|
*
|
|
@@ -2123,6 +2315,7 @@ interface ThreadImplConfigWithAdapter {
|
|
|
2123
2315
|
initialMessage?: Message;
|
|
2124
2316
|
isDM?: boolean;
|
|
2125
2317
|
isSubscribedContext?: boolean;
|
|
2318
|
+
messageHistory?: MessageHistoryCache;
|
|
2126
2319
|
stateAdapter: StateAdapter;
|
|
2127
2320
|
streamingUpdateIntervalMs?: number;
|
|
2128
2321
|
}
|
|
@@ -2162,6 +2355,8 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
2162
2355
|
private readonly _fallbackStreamingPlaceholderText;
|
|
2163
2356
|
/** Cached channel instance */
|
|
2164
2357
|
private _channel?;
|
|
2358
|
+
/** Message history cache (set only for adapters with persistMessageHistory) */
|
|
2359
|
+
private readonly _messageHistory?;
|
|
2165
2360
|
constructor(config: ThreadImplConfig);
|
|
2166
2361
|
/**
|
|
2167
2362
|
* Get the adapter for this thread.
|
|
@@ -2203,6 +2398,9 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
2203
2398
|
unsubscribe(): Promise<void>;
|
|
2204
2399
|
post(message: string | PostableMessage | ChatElement): Promise<SentMessage>;
|
|
2205
2400
|
postEphemeral(user: string | Author, message: AdapterPostableMessage | ChatElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
2401
|
+
schedule(message: AdapterPostableMessage | ChatElement, options: {
|
|
2402
|
+
postAt: Date;
|
|
2403
|
+
}): Promise<ScheduledMessage>;
|
|
2206
2404
|
/**
|
|
2207
2405
|
* Handle streaming from an AsyncIterable.
|
|
2208
2406
|
* Normalizes the stream (supports both textStream and fullStream from AI SDK),
|
|
@@ -2347,7 +2545,7 @@ declare const defaultEmojiResolver: EmojiResolver;
|
|
|
2347
2545
|
* // Returns: "Thanks! 👍"
|
|
2348
2546
|
* ```
|
|
2349
2547
|
*/
|
|
2350
|
-
declare function convertEmojiPlaceholders(text: string, platform: "slack" | "gchat" | "teams" | "discord" | "github" | "linear", resolver?: EmojiResolver): string;
|
|
2548
|
+
declare function convertEmojiPlaceholders(text: string, platform: "slack" | "gchat" | "teams" | "discord" | "github" | "linear" | "whatsapp", resolver?: EmojiResolver): string;
|
|
2351
2549
|
/** Base emoji object with well-known emoji as EmojiValue singletons */
|
|
2352
2550
|
type BaseEmojiHelper = {
|
|
2353
2551
|
[K in WellKnownEmoji]: EmojiValue;
|
|
@@ -2526,10 +2724,19 @@ declare function getNodeValue(node: Content): string;
|
|
|
2526
2724
|
* Supports GFM (GitHub Flavored Markdown) for strikethrough, tables, etc.
|
|
2527
2725
|
*/
|
|
2528
2726
|
declare function parseMarkdown(markdown: string): Root;
|
|
2727
|
+
/**
|
|
2728
|
+
* Options for stringifyMarkdown.
|
|
2729
|
+
*/
|
|
2730
|
+
interface StringifyOptions {
|
|
2731
|
+
/** Bullet character for unordered lists. Default: `'*'` */
|
|
2732
|
+
bullet?: "*" | "-" | "+";
|
|
2733
|
+
/** Emphasis marker character. Default: `'*'` */
|
|
2734
|
+
emphasis?: "*" | "_";
|
|
2735
|
+
}
|
|
2529
2736
|
/**
|
|
2530
2737
|
* Stringify an AST back to markdown.
|
|
2531
2738
|
*/
|
|
2532
|
-
declare function stringifyMarkdown(ast: Root): string;
|
|
2739
|
+
declare function stringifyMarkdown(ast: Root, options?: StringifyOptions): string;
|
|
2533
2740
|
/**
|
|
2534
2741
|
* Extract plain text from an AST (strips all formatting).
|
|
2535
2742
|
*/
|
|
@@ -2697,4 +2904,4 @@ declare const Select: SelectComponent;
|
|
|
2697
2904
|
declare const SelectOption: SelectOptionComponent;
|
|
2698
2905
|
declare const TextInput: TextInputComponent;
|
|
2699
2906
|
|
|
2700
|
-
export { type ActionEvent, type ActionHandler, Actions, ActionsComponent, type Adapter, type AdapterPostableMessage, type AppHomeOpenedEvent, type AppHomeOpenedHandler, type AssistantContextChangedEvent, type AssistantContextChangedHandler, type AssistantThreadStartedEvent, type AssistantThreadStartedHandler, type Attachment, type Author, BaseFormatConverter, Button, ButtonComponent, Card, CardChild, CardComponent, CardElement, CardLink, CardLinkComponent, CardText, type Channel, ChannelImpl, type ChannelInfo, Chat, type ChatConfig, ChatElement, ChatError, type ChatInstance, ConsoleLogger, type CustomEmojiMap, DEFAULT_EMOJI_MAP, Divider, DividerComponent, type Emoji, type EmojiFormats, type EmojiMapConfig, EmojiResolver, type EmojiValue, type EphemeralMessage, type FetchDirection, type FetchOptions, type FetchResult, Field, FieldComponent, Fields, FieldsComponent, type FileUpload, type FormatConverter, type FormattedContent, Image, ImageComponent, LinkButton, LinkButtonComponent, type ListThreadsOptions, type ListThreadsResult, type Lock, LockError, type LogLevel, type Logger, type MarkdownConverter, type MarkdownTextChunk, type MemberJoinedChannelEvent, type MemberJoinedChannelHandler, type MentionHandler, Message, type MessageData, type MessageHandler, type MessageMetadata, Modal, type ModalCloseEvent, type ModalCloseHandler, type ModalCloseResponse, ModalComponent, ModalElement, type ModalErrorsResponse, type ModalPushResponse, type ModalResponse, type ModalSubmitEvent, type ModalSubmitHandler, type ModalUpdateResponse, NotImplementedError, type PlanUpdateChunk, type PostEphemeralOptions, type Postable, type PostableAst, type PostableCard, type PostableMarkdown, type PostableMessage, type PostableRaw, RadioSelect, RadioSelectComponent, RateLimitError, type RawMessage, type ReactionEvent, type ReactionHandler, Section, SectionComponent, Select, SelectComponent, SelectOption, SelectOptionComponent, type SentMessage, type SerializedChannel, type SerializedMessage, type SerializedThread, type SlashCommandEvent, type SlashCommandHandler, type StateAdapter, type StreamChunk, type StreamEvent, type StreamOptions, StreamingMarkdownRenderer, type SubscribedMessageHandler, THREAD_STATE_TTL_MS, Table, type TaskUpdateChunk, TextComponent, TextInput, TextInputComponent, type Thread, ThreadImpl, type ThreadInfo, type ThreadSummary, type WebhookOptions, type WellKnownEmoji, blockquote, cardChildToFallbackText, codeBlock, convertEmojiPlaceholders, createEmoji, defaultEmojiResolver, deriveChannelId, emoji, emphasis, fromFullStream, fromReactElement, fromReactModalElement, getEmoji, getNodeChildren, getNodeValue, inlineCode, isBlockquoteNode, isCardElement, isCodeNode, isDeleteNode, isEmphasisNode, isInlineCodeNode, isJSX, isLinkNode, isListItemNode, isListNode, isModalElement, isParagraphNode, isStrongNode, isTableCellNode, isTableNode, isTableRowNode, isTextNode, link, markdownToPlainText, paragraph, parseMarkdown, root, strikethrough, stringifyMarkdown, strong, tableElementToAscii, tableToAscii, text, toCardElement, toModalElement, toPlainText, walkAst };
|
|
2907
|
+
export { type ActionEvent, type ActionHandler, Actions, ActionsComponent, type Adapter, type AdapterPostableMessage, type AiMessage, type AppHomeOpenedEvent, type AppHomeOpenedHandler, type AssistantContextChangedEvent, type AssistantContextChangedHandler, type AssistantThreadStartedEvent, type AssistantThreadStartedHandler, type Attachment, type Author, BaseFormatConverter, Button, ButtonComponent, Card, CardChild, CardComponent, CardElement, CardLink, CardLinkComponent, CardText, type Channel, ChannelImpl, type ChannelInfo, Chat, type ChatConfig, ChatElement, ChatError, type ChatInstance, ConsoleLogger, type CustomEmojiMap, DEFAULT_EMOJI_MAP, type DirectMessageHandler, Divider, DividerComponent, type Emoji, type EmojiFormats, type EmojiMapConfig, EmojiResolver, type EmojiValue, type EphemeralMessage, type FetchDirection, type FetchOptions, type FetchResult, Field, FieldComponent, Fields, FieldsComponent, type FileUpload, type FormatConverter, type FormattedContent, Image, ImageComponent, LinkButton, LinkButtonComponent, type ListThreadsOptions, type ListThreadsResult, type Lock, LockError, type LogLevel, type Logger, type MarkdownConverter, type MarkdownTextChunk, type MemberJoinedChannelEvent, type MemberJoinedChannelHandler, type MentionHandler, Message, type MessageData, type MessageHandler, MessageHistoryCache, type MessageHistoryConfig, type MessageMetadata, Modal, type ModalCloseEvent, type ModalCloseHandler, type ModalCloseResponse, ModalComponent, ModalElement, type ModalErrorsResponse, type ModalPushResponse, type ModalResponse, type ModalSubmitEvent, type ModalSubmitHandler, type ModalUpdateResponse, NotImplementedError, type PlanUpdateChunk, type PostEphemeralOptions, type Postable, type PostableAst, type PostableCard, type PostableMarkdown, type PostableMessage, type PostableRaw, RadioSelect, RadioSelectComponent, RateLimitError, type RawMessage, type ReactionEvent, type ReactionHandler, type ScheduledMessage, Section, SectionComponent, Select, SelectComponent, SelectOption, SelectOptionComponent, type SentMessage, type SerializedChannel, type SerializedMessage, type SerializedThread, type SlashCommandEvent, type SlashCommandHandler, type StateAdapter, type StreamChunk, type StreamEvent, type StreamOptions, StreamingMarkdownRenderer, type SubscribedMessageHandler, THREAD_STATE_TTL_MS, Table, type TaskUpdateChunk, TextComponent, TextInput, TextInputComponent, type Thread, ThreadImpl, type ThreadInfo, type ThreadSummary, type WebhookOptions, type WellKnownEmoji, blockquote, cardChildToFallbackText, codeBlock, convertEmojiPlaceholders, createEmoji, defaultEmojiResolver, deriveChannelId, emoji, emphasis, fromFullStream, fromReactElement, fromReactModalElement, getEmoji, getNodeChildren, getNodeValue, inlineCode, isBlockquoteNode, isCardElement, isCodeNode, isDeleteNode, isEmphasisNode, isInlineCodeNode, isJSX, isLinkNode, isListItemNode, isListNode, isModalElement, isParagraphNode, isStrongNode, isTableCellNode, isTableNode, isTableRowNode, isTextNode, link, markdownToPlainText, paragraph, parseMarkdown, root, strikethrough, stringifyMarkdown, strong, tableElementToAscii, tableToAscii, text, toAiMessages, toCardElement, toModalElement, toPlainText, walkAst };
|