chat 4.12.0 → 4.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -269,6 +269,8 @@ interface StreamOptions {
269
269
  recipientTeamId?: string;
270
270
  /** Minimum interval between updates in ms (default: 1000). Used for fallback mode (GChat/Teams). */
271
271
  updateIntervalMs?: number;
272
+ /** Block Kit elements to attach when stopping the stream (Slack only, via chat.stopStream) */
273
+ stopBlocks?: unknown[];
272
274
  }
273
275
  /** Internal interface for Chat instance passed to adapters */
274
276
  interface ChatInstance {
@@ -333,6 +335,9 @@ interface ChatInstance {
333
335
  adapter: Adapter;
334
336
  channelId: string;
335
337
  }, options?: WebhookOptions): void;
338
+ processAssistantThreadStarted(event: AssistantThreadStartedEvent, options?: WebhookOptions): void;
339
+ processAssistantContextChanged(event: AssistantContextChangedEvent, options?: WebhookOptions): void;
340
+ processAppHomeOpened(event: AppHomeOpenedEvent, options?: WebhookOptions): void;
336
341
  getState(): StateAdapter;
337
342
  getUserName(): string;
338
343
  /** Get the configured logger, optionally with a child prefix */
@@ -1256,6 +1261,42 @@ interface SlashCommandEvent<TState = Record<string, unknown>> {
1256
1261
  * ```
1257
1262
  */
1258
1263
  type SlashCommandHandler<TState = Record<string, unknown>> = (event: SlashCommandEvent<TState>) => Promise<void>;
1264
+ interface AssistantThreadStartedEvent {
1265
+ threadId: string;
1266
+ userId: string;
1267
+ channelId: string;
1268
+ threadTs: string;
1269
+ context: {
1270
+ channelId?: string;
1271
+ teamId?: string;
1272
+ enterpriseId?: string;
1273
+ threadEntryPoint?: string;
1274
+ forceSearch?: boolean;
1275
+ };
1276
+ adapter: Adapter;
1277
+ }
1278
+ type AssistantThreadStartedHandler = (event: AssistantThreadStartedEvent) => Promise<void>;
1279
+ interface AssistantContextChangedEvent {
1280
+ threadId: string;
1281
+ userId: string;
1282
+ channelId: string;
1283
+ threadTs: string;
1284
+ context: {
1285
+ channelId?: string;
1286
+ teamId?: string;
1287
+ enterpriseId?: string;
1288
+ threadEntryPoint?: string;
1289
+ forceSearch?: boolean;
1290
+ };
1291
+ adapter: Adapter;
1292
+ }
1293
+ type AssistantContextChangedHandler = (event: AssistantContextChangedEvent) => Promise<void>;
1294
+ interface AppHomeOpenedEvent {
1295
+ userId: string;
1296
+ channelId: string;
1297
+ adapter: Adapter;
1298
+ }
1299
+ type AppHomeOpenedHandler = (event: AppHomeOpenedEvent) => Promise<void>;
1259
1300
 
1260
1301
  /**
1261
1302
  * Message class with serialization support for workflow engines.
@@ -1552,6 +1593,9 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
1552
1593
  private modalSubmitHandlers;
1553
1594
  private modalCloseHandlers;
1554
1595
  private slashCommandHandlers;
1596
+ private assistantThreadStartedHandlers;
1597
+ private assistantContextChangedHandlers;
1598
+ private appHomeOpenedHandlers;
1555
1599
  /** Initialization state */
1556
1600
  private initPromise;
1557
1601
  private initialized;
@@ -1748,6 +1792,9 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
1748
1792
  onSlashCommand(handler: SlashCommandHandler<TState>): void;
1749
1793
  onSlashCommand(command: string, handler: SlashCommandHandler<TState>): void;
1750
1794
  onSlashCommand(commands: string[], handler: SlashCommandHandler<TState>): void;
1795
+ onAssistantThreadStarted(handler: AssistantThreadStartedHandler): void;
1796
+ onAssistantContextChanged(handler: AssistantContextChangedHandler): void;
1797
+ onAppHomeOpened(handler: AppHomeOpenedHandler): void;
1751
1798
  /**
1752
1799
  * Get an adapter by name with type safety.
1753
1800
  */
@@ -1802,6 +1849,9 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
1802
1849
  adapter: Adapter;
1803
1850
  channelId: string;
1804
1851
  }, options?: WebhookOptions): void;
1852
+ processAssistantThreadStarted(event: AssistantThreadStartedEvent, options?: WebhookOptions): void;
1853
+ processAssistantContextChanged(event: AssistantContextChangedEvent, options?: WebhookOptions): void;
1854
+ processAppHomeOpened(event: AppHomeOpenedEvent, options?: WebhookOptions): void;
1805
1855
  /**
1806
1856
  * Handle a slash command event internally.
1807
1857
  */
@@ -2457,4 +2507,4 @@ declare const Select: typeof Select$1;
2457
2507
  declare const SelectOption: typeof SelectOption$1;
2458
2508
  declare const TextInput: typeof TextInput$1;
2459
2509
 
2460
- export { type ActionEvent, type ActionHandler, Actions, type Adapter, type AdapterPostableMessage, type Attachment, type Author, BaseFormatConverter, Button, Card, CardChild, CardElement, CardJSXElement, CardText, type Channel, ChannelImpl, type ChannelInfo, 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, LinkButton, type ListThreadsOptions, type ListThreadsResult, 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 Postable, type PostableAst, type PostableCard, type PostableMarkdown, type PostableMessage, type PostableRaw, RadioSelect, RateLimitError, type RawMessage, type ReactionEvent, type ReactionHandler, Section, Select, SelectOption, type SentMessage, type SerializedChannel, type SerializedMessage, type SerializedThread, type SlashCommandEvent, type SlashCommandHandler, type StateAdapter, type StreamOptions, type SubscribedMessageHandler, THREAD_STATE_TTL_MS, TextInput, type Thread, ThreadImpl, type ThreadInfo, type ThreadSummary, type WebhookOptions, type WellKnownEmoji, blockquote, codeBlock, convertEmojiPlaceholders, createEmoji, defaultEmojiResolver, deriveChannelId, 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 };
2510
+ export { type ActionEvent, type ActionHandler, Actions, type Adapter, type AdapterPostableMessage, type AppHomeOpenedEvent, type AppHomeOpenedHandler, type AssistantContextChangedEvent, type AssistantContextChangedHandler, type AssistantThreadStartedEvent, type AssistantThreadStartedHandler, type Attachment, type Author, BaseFormatConverter, Button, Card, CardChild, CardElement, CardJSXElement, CardText, type Channel, ChannelImpl, type ChannelInfo, 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, LinkButton, type ListThreadsOptions, type ListThreadsResult, 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 Postable, type PostableAst, type PostableCard, type PostableMarkdown, type PostableMessage, type PostableRaw, RadioSelect, RateLimitError, type RawMessage, type ReactionEvent, type ReactionHandler, Section, Select, SelectOption, type SentMessage, type SerializedChannel, type SerializedMessage, type SerializedThread, type SlashCommandEvent, type SlashCommandHandler, type StateAdapter, type StreamOptions, type SubscribedMessageHandler, THREAD_STATE_TTL_MS, TextInput, type Thread, ThreadImpl, type ThreadInfo, type ThreadSummary, type WebhookOptions, type WellKnownEmoji, blockquote, codeBlock, convertEmojiPlaceholders, createEmoji, defaultEmojiResolver, deriveChannelId, 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 };
package/dist/index.js CHANGED
@@ -1358,6 +1358,9 @@ var Chat = class {
1358
1358
  modalSubmitHandlers = [];
1359
1359
  modalCloseHandlers = [];
1360
1360
  slashCommandHandlers = [];
1361
+ assistantThreadStartedHandlers = [];
1362
+ assistantContextChangedHandlers = [];
1363
+ appHomeOpenedHandlers = [];
1361
1364
  /** Initialization state */
1362
1365
  initPromise = null;
1363
1366
  initialized = false;
@@ -1590,6 +1593,18 @@ var Chat = class {
1590
1593
  });
1591
1594
  }
1592
1595
  }
1596
+ onAssistantThreadStarted(handler) {
1597
+ this.assistantThreadStartedHandlers.push(handler);
1598
+ this.logger.debug("Registered assistant thread started handler");
1599
+ }
1600
+ onAssistantContextChanged(handler) {
1601
+ this.assistantContextChangedHandlers.push(handler);
1602
+ this.logger.debug("Registered assistant context changed handler");
1603
+ }
1604
+ onAppHomeOpened(handler) {
1605
+ this.appHomeOpenedHandlers.push(handler);
1606
+ this.logger.debug("Registered app home opened handler");
1607
+ }
1593
1608
  /**
1594
1609
  * Get an adapter by name with type safety.
1595
1610
  */
@@ -1744,6 +1759,51 @@ var Chat = class {
1744
1759
  options.waitUntil(task);
1745
1760
  }
1746
1761
  }
1762
+ processAssistantThreadStarted(event, options) {
1763
+ const task = (async () => {
1764
+ for (const handler of this.assistantThreadStartedHandlers) {
1765
+ await handler(event);
1766
+ }
1767
+ })().catch((err) => {
1768
+ this.logger.error("Assistant thread started handler error", {
1769
+ error: err,
1770
+ threadId: event.threadId
1771
+ });
1772
+ });
1773
+ if (options?.waitUntil) {
1774
+ options.waitUntil(task);
1775
+ }
1776
+ }
1777
+ processAssistantContextChanged(event, options) {
1778
+ const task = (async () => {
1779
+ for (const handler of this.assistantContextChangedHandlers) {
1780
+ await handler(event);
1781
+ }
1782
+ })().catch((err) => {
1783
+ this.logger.error("Assistant context changed handler error", {
1784
+ error: err,
1785
+ threadId: event.threadId
1786
+ });
1787
+ });
1788
+ if (options?.waitUntil) {
1789
+ options.waitUntil(task);
1790
+ }
1791
+ }
1792
+ processAppHomeOpened(event, options) {
1793
+ const task = (async () => {
1794
+ for (const handler of this.appHomeOpenedHandlers) {
1795
+ await handler(event);
1796
+ }
1797
+ })().catch((err) => {
1798
+ this.logger.error("App home opened handler error", {
1799
+ error: err,
1800
+ userId: event.userId
1801
+ });
1802
+ });
1803
+ if (options?.waitUntil) {
1804
+ options.waitUntil(task);
1805
+ }
1806
+ }
1747
1807
  /**
1748
1808
  * Handle a slash command event internally.
1749
1809
  */
@@ -1904,12 +1964,12 @@ var Chat = class {
1904
1964
  metadata: { dateSent: /* @__PURE__ */ new Date(), edited: false },
1905
1965
  attachments: []
1906
1966
  }) : {};
1907
- const thread = await this.createThread(
1967
+ const thread = event.threadId ? await this.createThread(
1908
1968
  event.adapter,
1909
1969
  event.threadId,
1910
1970
  messageForThread,
1911
1971
  isSubscribed
1912
- );
1972
+ ) : null;
1913
1973
  const fullEvent = {
1914
1974
  ...event,
1915
1975
  thread,