chat 4.4.0 → 4.5.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/dist/index.d.ts +348 -47
- package/dist/index.js +354 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { C as CardElement, a as CardJSXElement, M as ModalElement, b as CardChild, A as Actions$1, B as Button$1, c as Card$1, T as Text$1, D as Divider$1, F as Field$1, d as Fields$1, f as fromReactElement$1, I as Image$1, i as isCardElement$1, e as isJSX$1, S as Section$1, t as toCardElement$1, g as toModalElement$1, h as fromReactModalElement$1, j as isModalElement$1, k as Modal$1, l as Select$1, m as SelectOption$1, n as TextInput$1 } from './jsx-runtime-CFK57xOl.js';
|
|
2
2
|
export { x as ActionsElement, y as ButtonElement, z as ButtonOptions, o as ButtonProps, E as ButtonStyle, p as CardJSXProps, G as CardOptions, q as CardProps, r as ContainerProps, H as DividerElement, s as DividerProps, J as FieldElement, u as FieldProps, K as FieldsElement, L as ImageElement, v as ImageProps, Q as ModalChild, R as ModalOptions, N as SectionElement, U as SelectElement, V as SelectOptionElement, W as SelectOptions, O as TextElement, X as TextInputElement, Y as TextInputOptions, w as TextProps, P as TextStyle } from './jsx-runtime-CFK57xOl.js';
|
|
3
|
+
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
3
4
|
import { Root, Content, Blockquote, Code, Emphasis, InlineCode, Delete, Link, ListItem, List, Paragraph, Strong, Text } from 'mdast';
|
|
4
5
|
export { Blockquote, Code, Content, Delete, Emphasis, InlineCode, Link, List, ListItem, Paragraph, Root, Strong, Text } from 'mdast';
|
|
5
6
|
|
|
@@ -182,6 +183,18 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
182
183
|
* ```
|
|
183
184
|
*/
|
|
184
185
|
openDM?(userId: string): Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Post an ephemeral message visible only to a specific user.
|
|
188
|
+
*
|
|
189
|
+
* This is optional - if not implemented, Thread.postEphemeral will
|
|
190
|
+
* fall back to openDM + postMessage when fallbackToDM is true.
|
|
191
|
+
*
|
|
192
|
+
* @param threadId - The thread to post in
|
|
193
|
+
* @param userId - The user who should see the message
|
|
194
|
+
* @param message - The message content
|
|
195
|
+
* @returns EphemeralMessage with usedFallback: false
|
|
196
|
+
*/
|
|
197
|
+
postEphemeral?(threadId: string, userId: string, message: AdapterPostableMessage): Promise<EphemeralMessage>;
|
|
185
198
|
/**
|
|
186
199
|
* Check if a thread is a direct message conversation.
|
|
187
200
|
*
|
|
@@ -418,6 +431,35 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> {
|
|
|
418
431
|
* ```
|
|
419
432
|
*/
|
|
420
433
|
post(message: string | PostableMessage | CardJSXElement): Promise<SentMessage<TRawMessage>>;
|
|
434
|
+
/**
|
|
435
|
+
* Post an ephemeral message visible only to a specific user.
|
|
436
|
+
*
|
|
437
|
+
* **Platform Behavior:**
|
|
438
|
+
* - **Slack**: Native ephemeral (session-dependent, disappears on reload)
|
|
439
|
+
* - **Google Chat**: Native private message (persists, only target user sees it)
|
|
440
|
+
* - **Discord**: No native support - requires fallbackToDM: true
|
|
441
|
+
* - **Teams**: No native support - requires fallbackToDM: true
|
|
442
|
+
*
|
|
443
|
+
* @param user - User ID string or Author object (from message.author or event.user)
|
|
444
|
+
* @param message - Message content (string, markdown, card, etc.). Streaming is not supported.
|
|
445
|
+
* @param options.fallbackToDM - Required. If true, falls back to DM when native
|
|
446
|
+
* ephemeral is not supported. If false, returns null when unsupported.
|
|
447
|
+
* @returns EphemeralMessage with `usedFallback: true` if DM was used, or null
|
|
448
|
+
* if native ephemeral not supported and fallbackToDM is false
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* // Always send (DM fallback on Discord/Teams)
|
|
453
|
+
* await thread.postEphemeral(user, 'Only you can see this!', { fallbackToDM: true })
|
|
454
|
+
*
|
|
455
|
+
* // Only send if native ephemeral supported (Slack/GChat)
|
|
456
|
+
* const result = await thread.postEphemeral(user, 'Secret!', { fallbackToDM: false })
|
|
457
|
+
* if (!result) {
|
|
458
|
+
* // Platform doesn't support native ephemeral - handle accordingly
|
|
459
|
+
* }
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
postEphemeral(user: string | Author, message: AdapterPostableMessage | CardJSXElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
421
463
|
/**
|
|
422
464
|
* Show typing indicator in the thread.
|
|
423
465
|
*
|
|
@@ -524,45 +566,6 @@ interface FetchResult<TRawMessage = unknown> {
|
|
|
524
566
|
* This is the canonical representation of message formatting.
|
|
525
567
|
*/
|
|
526
568
|
type FormattedContent = Root;
|
|
527
|
-
interface Message<TRawMessage = unknown> {
|
|
528
|
-
/** Unique message ID */
|
|
529
|
-
readonly id: string;
|
|
530
|
-
/** Thread this message belongs to */
|
|
531
|
-
readonly threadId: string;
|
|
532
|
-
/** Plain text content (all formatting stripped) */
|
|
533
|
-
text: string;
|
|
534
|
-
/**
|
|
535
|
-
* Structured formatting as an AST (mdast Root).
|
|
536
|
-
* This is the canonical representation - use this for processing.
|
|
537
|
-
* Use `stringifyMarkdown(message.formatted)` to get markdown string.
|
|
538
|
-
*/
|
|
539
|
-
formatted: FormattedContent;
|
|
540
|
-
/** Platform-specific raw payload (escape hatch) */
|
|
541
|
-
raw: TRawMessage;
|
|
542
|
-
/** Message author */
|
|
543
|
-
author: Author;
|
|
544
|
-
/** Message metadata */
|
|
545
|
-
metadata: MessageMetadata;
|
|
546
|
-
/** Attachments */
|
|
547
|
-
attachments: Attachment[];
|
|
548
|
-
/**
|
|
549
|
-
* Whether the bot is @-mentioned in this message.
|
|
550
|
-
*
|
|
551
|
-
* This is set by the Chat SDK before passing the message to handlers.
|
|
552
|
-
* It checks for `@username` in the message text using the adapter's
|
|
553
|
-
* configured `userName` and optional `botUserId`.
|
|
554
|
-
*
|
|
555
|
-
* @example
|
|
556
|
-
* ```typescript
|
|
557
|
-
* chat.onSubscribedMessage(async (thread, message) => {
|
|
558
|
-
* if (message.isMention) {
|
|
559
|
-
* await thread.post("You mentioned me!");
|
|
560
|
-
* }
|
|
561
|
-
* });
|
|
562
|
-
* ```
|
|
563
|
-
*/
|
|
564
|
-
isMention?: boolean;
|
|
565
|
-
}
|
|
566
569
|
/** Raw message returned from adapter (before wrapping as SentMessage) */
|
|
567
570
|
interface RawMessage<TRawMessage = unknown> {
|
|
568
571
|
id: string;
|
|
@@ -599,6 +602,34 @@ interface SentMessage<TRawMessage = unknown> extends Message<TRawMessage> {
|
|
|
599
602
|
/** Remove a reaction from this message */
|
|
600
603
|
removeReaction(emoji: EmojiValue | string): Promise<void>;
|
|
601
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Result of posting an ephemeral message.
|
|
607
|
+
*
|
|
608
|
+
* Ephemeral messages are visible only to a specific user and typically
|
|
609
|
+
* cannot be edited or deleted (platform-dependent).
|
|
610
|
+
*/
|
|
611
|
+
interface EphemeralMessage {
|
|
612
|
+
/** Message ID (may be empty for some platforms) */
|
|
613
|
+
id: string;
|
|
614
|
+
/** Thread ID where message was sent (or DM thread if fallback was used) */
|
|
615
|
+
threadId: string;
|
|
616
|
+
/** Whether this used native ephemeral or fell back to DM */
|
|
617
|
+
usedFallback: boolean;
|
|
618
|
+
/** Platform-specific raw response */
|
|
619
|
+
raw: unknown;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Options for posting ephemeral messages.
|
|
623
|
+
*/
|
|
624
|
+
interface PostEphemeralOptions {
|
|
625
|
+
/**
|
|
626
|
+
* Controls behavior when native ephemeral is not supported by the platform.
|
|
627
|
+
*
|
|
628
|
+
* - `true`: Falls back to sending a DM to the user
|
|
629
|
+
* - `false`: Returns `null` if native ephemeral is not supported
|
|
630
|
+
*/
|
|
631
|
+
fallbackToDM: boolean;
|
|
632
|
+
}
|
|
602
633
|
/**
|
|
603
634
|
* Input type for adapter postMessage/editMessage methods.
|
|
604
635
|
* This excludes streams since adapters handle content synchronously.
|
|
@@ -934,6 +965,7 @@ interface ModalSubmitEvent {
|
|
|
934
965
|
interface ModalCloseEvent {
|
|
935
966
|
callbackId: string;
|
|
936
967
|
viewId: string;
|
|
968
|
+
privateMetadata?: string;
|
|
937
969
|
user: Author;
|
|
938
970
|
adapter: Adapter;
|
|
939
971
|
raw: unknown;
|
|
@@ -957,6 +989,153 @@ type ModalResponse = ModalCloseResponse | ModalErrorsResponse | ModalUpdateRespo
|
|
|
957
989
|
type ModalSubmitHandler = (event: ModalSubmitEvent) => Promise<ModalResponse | undefined>;
|
|
958
990
|
type ModalCloseHandler = (event: ModalCloseEvent) => Promise<void>;
|
|
959
991
|
|
|
992
|
+
/**
|
|
993
|
+
* Message class with serialization support for workflow engines.
|
|
994
|
+
*/
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Input data for creating a Message instance.
|
|
998
|
+
* Use this interface when constructing Message objects.
|
|
999
|
+
*/
|
|
1000
|
+
interface MessageData<TRawMessage = unknown> {
|
|
1001
|
+
/** Unique message ID */
|
|
1002
|
+
id: string;
|
|
1003
|
+
/** Thread this message belongs to */
|
|
1004
|
+
threadId: string;
|
|
1005
|
+
/** Plain text content (all formatting stripped) */
|
|
1006
|
+
text: string;
|
|
1007
|
+
/** Structured formatting as an AST (mdast Root) */
|
|
1008
|
+
formatted: FormattedContent;
|
|
1009
|
+
/** Platform-specific raw payload (escape hatch) */
|
|
1010
|
+
raw: TRawMessage;
|
|
1011
|
+
/** Message author */
|
|
1012
|
+
author: Author;
|
|
1013
|
+
/** Message metadata */
|
|
1014
|
+
metadata: MessageMetadata;
|
|
1015
|
+
/** Attachments */
|
|
1016
|
+
attachments: Attachment[];
|
|
1017
|
+
/** Whether the bot is @-mentioned in this message */
|
|
1018
|
+
isMention?: boolean;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Serialized message data for passing to external systems (e.g., workflow engines).
|
|
1022
|
+
* Dates are converted to ISO strings, and non-serializable fields are omitted.
|
|
1023
|
+
*/
|
|
1024
|
+
interface SerializedMessage {
|
|
1025
|
+
_type: "chat:Message";
|
|
1026
|
+
id: string;
|
|
1027
|
+
threadId: string;
|
|
1028
|
+
text: string;
|
|
1029
|
+
formatted: Root;
|
|
1030
|
+
raw: unknown;
|
|
1031
|
+
author: {
|
|
1032
|
+
userId: string;
|
|
1033
|
+
userName: string;
|
|
1034
|
+
fullName: string;
|
|
1035
|
+
isBot: boolean | "unknown";
|
|
1036
|
+
isMe: boolean;
|
|
1037
|
+
};
|
|
1038
|
+
metadata: {
|
|
1039
|
+
dateSent: string;
|
|
1040
|
+
edited: boolean;
|
|
1041
|
+
editedAt?: string;
|
|
1042
|
+
};
|
|
1043
|
+
attachments: Array<{
|
|
1044
|
+
type: "image" | "file" | "video" | "audio";
|
|
1045
|
+
url?: string;
|
|
1046
|
+
name?: string;
|
|
1047
|
+
mimeType?: string;
|
|
1048
|
+
size?: number;
|
|
1049
|
+
width?: number;
|
|
1050
|
+
height?: number;
|
|
1051
|
+
}>;
|
|
1052
|
+
isMention?: boolean;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* A chat message with serialization support for workflow engines.
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* ```typescript
|
|
1059
|
+
* // Create a message
|
|
1060
|
+
* const message = new Message({
|
|
1061
|
+
* id: "msg-1",
|
|
1062
|
+
* threadId: "slack:C123:1234.5678",
|
|
1063
|
+
* text: "Hello world",
|
|
1064
|
+
* formatted: parseMarkdown("Hello world"),
|
|
1065
|
+
* raw: {},
|
|
1066
|
+
* author: { userId: "U123", userName: "user", fullName: "User", isBot: false, isMe: false },
|
|
1067
|
+
* metadata: { dateSent: new Date(), edited: false },
|
|
1068
|
+
* attachments: [],
|
|
1069
|
+
* });
|
|
1070
|
+
*
|
|
1071
|
+
* // Serialize for workflow
|
|
1072
|
+
* const serialized = message.toJSON();
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
declare class Message<TRawMessage = unknown> {
|
|
1076
|
+
/** Unique message ID */
|
|
1077
|
+
readonly id: string;
|
|
1078
|
+
/** Thread this message belongs to */
|
|
1079
|
+
readonly threadId: string;
|
|
1080
|
+
/** Plain text content (all formatting stripped) */
|
|
1081
|
+
text: string;
|
|
1082
|
+
/**
|
|
1083
|
+
* Structured formatting as an AST (mdast Root).
|
|
1084
|
+
* This is the canonical representation - use this for processing.
|
|
1085
|
+
* Use `stringifyMarkdown(message.formatted)` to get markdown string.
|
|
1086
|
+
*/
|
|
1087
|
+
formatted: FormattedContent;
|
|
1088
|
+
/** Platform-specific raw payload (escape hatch) */
|
|
1089
|
+
raw: TRawMessage;
|
|
1090
|
+
/** Message author */
|
|
1091
|
+
author: Author;
|
|
1092
|
+
/** Message metadata */
|
|
1093
|
+
metadata: MessageMetadata;
|
|
1094
|
+
/** Attachments */
|
|
1095
|
+
attachments: Attachment[];
|
|
1096
|
+
/**
|
|
1097
|
+
* Whether the bot is @-mentioned in this message.
|
|
1098
|
+
*
|
|
1099
|
+
* This is set by the Chat SDK before passing the message to handlers.
|
|
1100
|
+
* It checks for `@username` in the message text using the adapter's
|
|
1101
|
+
* configured `userName` and optional `botUserId`.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* chat.onSubscribedMessage(async (thread, message) => {
|
|
1106
|
+
* if (message.isMention) {
|
|
1107
|
+
* await thread.post("You mentioned me!");
|
|
1108
|
+
* }
|
|
1109
|
+
* });
|
|
1110
|
+
* ```
|
|
1111
|
+
*/
|
|
1112
|
+
isMention?: boolean;
|
|
1113
|
+
constructor(data: MessageData<TRawMessage>);
|
|
1114
|
+
/**
|
|
1115
|
+
* Serialize the message to a plain JSON object.
|
|
1116
|
+
* Use this to pass message data to external systems like workflow engines.
|
|
1117
|
+
*
|
|
1118
|
+
* Note: Attachment `data` (Buffer) and `fetchData` (function) are omitted
|
|
1119
|
+
* as they're not serializable.
|
|
1120
|
+
*/
|
|
1121
|
+
toJSON(): SerializedMessage;
|
|
1122
|
+
/**
|
|
1123
|
+
* Reconstruct a Message from serialized JSON data.
|
|
1124
|
+
* Converts ISO date strings back to Date objects.
|
|
1125
|
+
*/
|
|
1126
|
+
static fromJSON<TRawMessage = unknown>(json: SerializedMessage): Message<TRawMessage>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Serialize a Message instance for @workflow/serde.
|
|
1129
|
+
* This static method is automatically called by workflow serialization.
|
|
1130
|
+
*/
|
|
1131
|
+
static [WORKFLOW_SERIALIZE](instance: Message): SerializedMessage;
|
|
1132
|
+
/**
|
|
1133
|
+
* Deserialize a Message from @workflow/serde.
|
|
1134
|
+
* This static method is automatically called by workflow deserialization.
|
|
1135
|
+
*/
|
|
1136
|
+
static [WORKFLOW_DESERIALIZE](data: SerializedMessage): Message;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
960
1139
|
/** Filter can be EmojiValue objects, emoji names, or raw emoji formats */
|
|
961
1140
|
type EmojiFilter = EmojiValue | string;
|
|
962
1141
|
/**
|
|
@@ -998,6 +1177,29 @@ type Webhooks<TAdapters extends Record<string, Adapter>> = {
|
|
|
998
1177
|
* });
|
|
999
1178
|
*/
|
|
1000
1179
|
declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Adapter>, TState = Record<string, unknown>> implements ChatInstance {
|
|
1180
|
+
/**
|
|
1181
|
+
* Register this Chat instance as the global singleton.
|
|
1182
|
+
* Required for Thread deserialization via @workflow/serde.
|
|
1183
|
+
*
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```typescript
|
|
1186
|
+
* const chat = new Chat({ ... });
|
|
1187
|
+
* chat.registerSingleton();
|
|
1188
|
+
*
|
|
1189
|
+
* // Now threads can be deserialized without passing chat explicitly
|
|
1190
|
+
* const thread = ThreadImpl.fromJSON(serializedThread);
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
registerSingleton(): this;
|
|
1194
|
+
/**
|
|
1195
|
+
* Get the registered singleton Chat instance.
|
|
1196
|
+
* Throws if no singleton has been registered.
|
|
1197
|
+
*/
|
|
1198
|
+
static getSingleton(): Chat;
|
|
1199
|
+
/**
|
|
1200
|
+
* Check if a singleton has been registered.
|
|
1201
|
+
*/
|
|
1202
|
+
static hasSingleton(): boolean;
|
|
1001
1203
|
private adapters;
|
|
1002
1204
|
private _stateAdapter;
|
|
1003
1205
|
private userName;
|
|
@@ -1171,6 +1373,26 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1171
1373
|
* Get an adapter by name with type safety.
|
|
1172
1374
|
*/
|
|
1173
1375
|
getAdapter<K extends keyof TAdapters>(name: K): TAdapters[K];
|
|
1376
|
+
/**
|
|
1377
|
+
* Get a JSON.parse reviver function that automatically deserializes
|
|
1378
|
+
* chat:Thread and chat:Message objects.
|
|
1379
|
+
*
|
|
1380
|
+
* Use this when parsing JSON that contains serialized Thread or Message objects
|
|
1381
|
+
* (e.g., from workflow engine payloads).
|
|
1382
|
+
*
|
|
1383
|
+
* @returns A reviver function for JSON.parse
|
|
1384
|
+
*
|
|
1385
|
+
* @example
|
|
1386
|
+
* ```typescript
|
|
1387
|
+
* // Parse workflow payload with automatic deserialization
|
|
1388
|
+
* const data = JSON.parse(payload, chat.reviver());
|
|
1389
|
+
*
|
|
1390
|
+
* // data.thread is now a ThreadImpl instance
|
|
1391
|
+
* // data.message is now a Message object with Date fields restored
|
|
1392
|
+
* await data.thread.post("Hello from workflow!");
|
|
1393
|
+
* ```
|
|
1394
|
+
*/
|
|
1395
|
+
reviver(): (key: string, value: unknown) => unknown;
|
|
1174
1396
|
/**
|
|
1175
1397
|
* Process an incoming message from an adapter.
|
|
1176
1398
|
* Handles waitUntil registration and error catching internally.
|
|
@@ -1257,27 +1479,55 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1257
1479
|
private runHandlers;
|
|
1258
1480
|
}
|
|
1259
1481
|
|
|
1260
|
-
|
|
1482
|
+
/**
|
|
1483
|
+
* Serialized thread data for passing to external systems (e.g., workflow engines).
|
|
1484
|
+
*/
|
|
1485
|
+
interface SerializedThread {
|
|
1486
|
+
_type: "chat:Thread";
|
|
1487
|
+
id: string;
|
|
1488
|
+
channelId: string;
|
|
1489
|
+
isDM: boolean;
|
|
1490
|
+
adapterName: string;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Config for creating a ThreadImpl with explicit adapter/state instances.
|
|
1494
|
+
*/
|
|
1495
|
+
interface ThreadImplConfigWithAdapter {
|
|
1261
1496
|
id: string;
|
|
1262
1497
|
adapter: Adapter;
|
|
1263
1498
|
channelId: string;
|
|
1264
1499
|
stateAdapter: StateAdapter;
|
|
1265
1500
|
initialMessage?: Message;
|
|
1266
|
-
/** If true, thread is known to be subscribed (for short-circuit optimization) */
|
|
1267
1501
|
isSubscribedContext?: boolean;
|
|
1268
|
-
/** Whether this is a direct message conversation */
|
|
1269
1502
|
isDM?: boolean;
|
|
1270
|
-
/** Current message context for streaming (provides userId/teamId) */
|
|
1271
1503
|
currentMessage?: Message;
|
|
1272
|
-
/** Update interval for fallback streaming in milliseconds. Defaults to 500ms. */
|
|
1273
1504
|
streamingUpdateIntervalMs?: number;
|
|
1274
1505
|
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Config for creating a ThreadImpl with lazy adapter resolution.
|
|
1508
|
+
* The adapter will be looked up from the Chat singleton on first access.
|
|
1509
|
+
*/
|
|
1510
|
+
interface ThreadImplConfigLazy {
|
|
1511
|
+
id: string;
|
|
1512
|
+
adapterName: string;
|
|
1513
|
+
channelId: string;
|
|
1514
|
+
initialMessage?: Message;
|
|
1515
|
+
isSubscribedContext?: boolean;
|
|
1516
|
+
isDM?: boolean;
|
|
1517
|
+
currentMessage?: Message;
|
|
1518
|
+
streamingUpdateIntervalMs?: number;
|
|
1519
|
+
}
|
|
1520
|
+
type ThreadImplConfig = ThreadImplConfigWithAdapter | ThreadImplConfigLazy;
|
|
1275
1521
|
declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TState> {
|
|
1276
1522
|
readonly id: string;
|
|
1277
|
-
readonly adapter: Adapter;
|
|
1278
1523
|
readonly channelId: string;
|
|
1279
1524
|
readonly isDM: boolean;
|
|
1280
|
-
|
|
1525
|
+
/** Direct adapter instance (if provided) */
|
|
1526
|
+
private _adapter?;
|
|
1527
|
+
/** Adapter name for lazy resolution */
|
|
1528
|
+
private _adapterName?;
|
|
1529
|
+
/** Direct state adapter instance (if provided) */
|
|
1530
|
+
private _stateAdapterInstance?;
|
|
1281
1531
|
private _recentMessages;
|
|
1282
1532
|
private _isSubscribedContext;
|
|
1283
1533
|
/** Current message context for streaming - provides userId/teamId */
|
|
@@ -1285,6 +1535,16 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
1285
1535
|
/** Update interval for fallback streaming */
|
|
1286
1536
|
private _streamingUpdateIntervalMs;
|
|
1287
1537
|
constructor(config: ThreadImplConfig);
|
|
1538
|
+
/**
|
|
1539
|
+
* Get the adapter for this thread.
|
|
1540
|
+
* If created with lazy config, resolves from Chat singleton on first access.
|
|
1541
|
+
*/
|
|
1542
|
+
get adapter(): Adapter;
|
|
1543
|
+
/**
|
|
1544
|
+
* Get the state adapter for this thread.
|
|
1545
|
+
* If created with lazy config, resolves from Chat singleton on first access.
|
|
1546
|
+
*/
|
|
1547
|
+
private get _stateAdapter();
|
|
1288
1548
|
get recentMessages(): Message[];
|
|
1289
1549
|
set recentMessages(messages: Message[]);
|
|
1290
1550
|
/**
|
|
@@ -1304,6 +1564,7 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
1304
1564
|
subscribe(): Promise<void>;
|
|
1305
1565
|
unsubscribe(): Promise<void>;
|
|
1306
1566
|
post(message: string | PostableMessage | CardJSXElement): Promise<SentMessage>;
|
|
1567
|
+
postEphemeral(user: string | Author, message: AdapterPostableMessage | CardJSXElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
1307
1568
|
/**
|
|
1308
1569
|
* Handle streaming from an AsyncIterable.
|
|
1309
1570
|
* Uses adapter's native streaming if available, otherwise falls back to post+edit.
|
|
@@ -1319,6 +1580,46 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
1319
1580
|
private fallbackStream;
|
|
1320
1581
|
refresh(): Promise<void>;
|
|
1321
1582
|
mentionUser(userId: string): string;
|
|
1583
|
+
/**
|
|
1584
|
+
* Serialize the thread to a plain JSON object.
|
|
1585
|
+
* Use this to pass thread data to external systems like workflow engines.
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```typescript
|
|
1589
|
+
* // Pass to a workflow
|
|
1590
|
+
* await workflow.start("my-workflow", {
|
|
1591
|
+
* thread: thread.toJSON(),
|
|
1592
|
+
* message: serializeMessage(message),
|
|
1593
|
+
* });
|
|
1594
|
+
* ```
|
|
1595
|
+
*/
|
|
1596
|
+
toJSON(): SerializedThread;
|
|
1597
|
+
/**
|
|
1598
|
+
* Reconstruct a Thread from serialized JSON data.
|
|
1599
|
+
*
|
|
1600
|
+
* Reconstructs a ThreadImpl from serialized data.
|
|
1601
|
+
* Uses lazy resolution from Chat.getSingleton() for adapter and state.
|
|
1602
|
+
*
|
|
1603
|
+
* @param json - Serialized thread data
|
|
1604
|
+
* @requires Call `chat.registerSingleton()` before deserializing threads
|
|
1605
|
+
*
|
|
1606
|
+
* @example
|
|
1607
|
+
* ```typescript
|
|
1608
|
+
* const thread = ThreadImpl.fromJSON(serializedThread);
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
static fromJSON<TState = Record<string, unknown>>(json: SerializedThread): ThreadImpl<TState>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Serialize a ThreadImpl instance for @workflow/serde.
|
|
1614
|
+
* This static method is automatically called by workflow serialization.
|
|
1615
|
+
*/
|
|
1616
|
+
static [WORKFLOW_SERIALIZE](instance: ThreadImpl): SerializedThread;
|
|
1617
|
+
/**
|
|
1618
|
+
* Deserialize a ThreadImpl from @workflow/serde.
|
|
1619
|
+
* Uses lazy adapter resolution from Chat.getSingleton().
|
|
1620
|
+
* Requires chat.registerSingleton() to have been called.
|
|
1621
|
+
*/
|
|
1622
|
+
static [WORKFLOW_DESERIALIZE](data: SerializedThread): ThreadImpl;
|
|
1322
1623
|
private createSentMessage;
|
|
1323
1624
|
}
|
|
1324
1625
|
|
|
@@ -1713,4 +2014,4 @@ declare const Select: typeof Select$1;
|
|
|
1713
2014
|
declare const SelectOption: typeof SelectOption$1;
|
|
1714
2015
|
declare const TextInput: typeof TextInput$1;
|
|
1715
2016
|
|
|
1716
|
-
export { type ActionEvent, type ActionHandler, Actions, type Adapter, type AdapterPostableMessage, type Attachment, type Author, BaseFormatConverter, Button, Card, CardChild, CardElement, CardJSXElement, CardText, Chat, type ChatConfig, ChatError, type ChatInstance, ConsoleLogger, type CustomEmojiMap, DEFAULT_EMOJI_MAP, Divider, type Emoji, type EmojiFormats, type EmojiMapConfig, EmojiResolver, type EmojiValue, type FetchDirection, type FetchOptions, type FetchResult, Field, Fields, type FileUpload, type FormatConverter, type FormattedContent, Image, type Lock, LockError, type LogLevel, type Logger, type MarkdownConverter, type MentionHandler, type
|
|
2017
|
+
export { type ActionEvent, type ActionHandler, Actions, type Adapter, type AdapterPostableMessage, type Attachment, type Author, BaseFormatConverter, Button, Card, CardChild, CardElement, CardJSXElement, CardText, Chat, type ChatConfig, ChatError, type ChatInstance, ConsoleLogger, type CustomEmojiMap, DEFAULT_EMOJI_MAP, Divider, type Emoji, type EmojiFormats, type EmojiMapConfig, EmojiResolver, type EmojiValue, type EphemeralMessage, type FetchDirection, type FetchOptions, type FetchResult, Field, Fields, type FileUpload, type FormatConverter, type FormattedContent, Image, type Lock, LockError, type LogLevel, type Logger, type MarkdownConverter, type MentionHandler, Message, type MessageData, type MessageHandler, type MessageMetadata, Modal, type ModalCloseEvent, type ModalCloseHandler, type ModalCloseResponse, ModalElement, type ModalErrorsResponse, type ModalPushResponse, type ModalResponse, type ModalSubmitEvent, type ModalSubmitHandler, type ModalUpdateResponse, NotImplementedError, type PostEphemeralOptions, type PostableAst, type PostableCard, type PostableMarkdown, type PostableMessage, type PostableRaw, RateLimitError, type RawMessage, type ReactionEvent, type ReactionHandler, Section, Select, SelectOption, type SentMessage, type SerializedMessage, type SerializedThread, type StateAdapter, type StreamOptions, type SubscribedMessageHandler, THREAD_STATE_TTL_MS, TextInput, type Thread, ThreadImpl, type ThreadInfo, type WebhookOptions, type WellKnownEmoji, blockquote, codeBlock, convertEmojiPlaceholders, createEmoji, defaultEmojiResolver, emoji, emphasis, fromReactElement, fromReactModalElement, getEmoji, getNodeChildren, getNodeValue, inlineCode, isBlockquoteNode, isCardElement, isCodeNode, isDeleteNode, isEmphasisNode, isInlineCodeNode, isJSX, isLinkNode, isListItemNode, isListNode, isModalElement, isParagraphNode, isStrongNode, isTextNode, link, markdownToPlainText, paragraph, parseMarkdown, root, strikethrough, stringifyMarkdown, strong, text, toCardElement, toModalElement, toPlainText, walkAst };
|