chat 4.27.0 → 4.29.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.
Files changed (49) hide show
  1. package/dist/ai/index.d.ts +501 -0
  2. package/dist/ai/index.js +500 -0
  3. package/dist/chat-D9UYaaNO.d.ts +3156 -0
  4. package/dist/chunk-HD375J7S.js +128 -0
  5. package/dist/{chunk-AN7MRAVW.js → chunk-V25FKIIL.js} +5 -1
  6. package/dist/index.d.ts +35 -2934
  7. package/dist/index.js +567 -210
  8. package/dist/{jsx-runtime-Co9uV6l7.d.ts → jsx-runtime-CFq1K_Ve.d.ts} +11 -1
  9. package/dist/jsx-runtime.d.ts +1 -1
  10. package/dist/jsx-runtime.js +1 -1
  11. package/docs/actions.mdx +52 -1
  12. package/docs/adapters.mdx +72 -36
  13. package/docs/ai/ai-sdk-tools.mdx +227 -0
  14. package/docs/ai/index.mdx +63 -0
  15. package/docs/ai/meta.json +4 -0
  16. package/docs/{api → ai}/to-ai-messages.mdx +16 -3
  17. package/docs/ai/types.mdx +243 -0
  18. package/docs/api/cards.mdx +4 -0
  19. package/docs/api/chat.mdx +132 -10
  20. package/docs/api/index.mdx +6 -6
  21. package/docs/api/markdown.mdx +28 -5
  22. package/docs/api/message.mdx +54 -1
  23. package/docs/api/meta.json +1 -0
  24. package/docs/api/modals.mdx +50 -0
  25. package/docs/api/postable-message.mdx +58 -4
  26. package/docs/api/thread.mdx +11 -3
  27. package/docs/api/transcripts.mdx +220 -0
  28. package/docs/cards.mdx +6 -0
  29. package/docs/concurrency.mdx +58 -15
  30. package/docs/contributing/building.mdx +74 -2
  31. package/docs/contributing/testing.mdx +4 -0
  32. package/docs/conversation-history.mdx +137 -0
  33. package/docs/direct-messages.mdx +23 -5
  34. package/docs/ephemeral-messages.mdx +1 -1
  35. package/docs/error-handling.mdx +15 -3
  36. package/docs/files.mdx +21 -1
  37. package/docs/handling-events.mdx +10 -7
  38. package/docs/index.mdx +8 -5
  39. package/docs/meta.json +17 -3
  40. package/docs/modals.mdx +24 -0
  41. package/docs/posting-messages.mdx +10 -4
  42. package/docs/slash-commands.mdx +4 -4
  43. package/docs/streaming.mdx +75 -27
  44. package/docs/subject.mdx +53 -0
  45. package/docs/testing.mdx +142 -0
  46. package/docs/threads-messages-channels.mdx +10 -1
  47. package/docs/usage.mdx +15 -2
  48. package/package.json +23 -2
  49. package/resources/guides/how-to-build-an-ai-agent-for-slack-with-chat-sdk-and-ai-sdk.md +1 -1
@@ -0,0 +1,501 @@
1
+ import { r as Chat, R as ChannelVisibility } from '../chat-D9UYaaNO.js';
2
+ export { g as AiAssistantMessage, h as AiFilePart, i as AiImagePart, j as AiMessage, k as AiMessagePart, l as AiTextPart, m as AiUserMessage, n as ToAiMessagesOptions, t as toAiMessages } from '../chat-D9UYaaNO.js';
3
+ import * as ai from 'ai';
4
+ import { Tool } from 'ai';
5
+ import '@workflow/serde';
6
+ import 'mdast';
7
+ import '../jsx-runtime-CFq1K_Ve.js';
8
+
9
+ /**
10
+ * The Chat instance used by all tools to dispatch operations.
11
+ * Always typed as `Chat<any, any>` so callers can pass strongly-typed
12
+ * `Chat` instances without having to repeat their adapter/state generics.
13
+ */
14
+ type ChatBinding = Chat<any, any>;
15
+ /**
16
+ * Common options for write tools that may require approval before executing.
17
+ */
18
+ interface ToolOptions {
19
+ needsApproval?: boolean;
20
+ }
21
+ /**
22
+ * Per-tool overrides for customizing tool behavior without changing the
23
+ * underlying implementation. `execute`, `inputSchema`, and `outputSchema`
24
+ * are intentionally excluded so tool semantics stay stable.
25
+ */
26
+ type ToolOverrides = Partial<Pick<Tool, "description" | "inputExamples" | "metadata" | "needsApproval" | "onInputAvailable" | "onInputDelta" | "onInputStart" | "providerOptions" | "strict" | "title" | "toModelOutput">>;
27
+
28
+ declare const getChannelInfo: (chat: ChatBinding) => ai.Tool<{
29
+ channelId: string;
30
+ }, {
31
+ id: string;
32
+ name: string | undefined;
33
+ isDM: boolean;
34
+ memberCount: number | undefined;
35
+ channelVisibility: ChannelVisibility | undefined;
36
+ }>;
37
+
38
+ declare const postMessage: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
39
+ threadId: string;
40
+ message: string | {
41
+ markdown: string;
42
+ } | {
43
+ raw: string;
44
+ };
45
+ }, {
46
+ messageId: string;
47
+ threadId: string;
48
+ }>;
49
+ declare const postChannelMessage: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
50
+ channelId: string;
51
+ message: string | {
52
+ markdown: string;
53
+ } | {
54
+ raw: string;
55
+ };
56
+ }, {
57
+ messageId: string;
58
+ threadId: string;
59
+ }>;
60
+ declare const sendDirectMessage: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
61
+ userId: string;
62
+ message: string | {
63
+ markdown: string;
64
+ } | {
65
+ raw: string;
66
+ };
67
+ }, {
68
+ messageId: string;
69
+ threadId: string;
70
+ }>;
71
+ declare const editMessage: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
72
+ threadId: string;
73
+ messageId: string;
74
+ message: string | {
75
+ markdown: string;
76
+ } | {
77
+ raw: string;
78
+ };
79
+ }, {
80
+ messageId: string;
81
+ threadId: string;
82
+ }>;
83
+ declare const deleteMessage: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
84
+ threadId: string;
85
+ messageId: string;
86
+ }, {
87
+ deleted: boolean;
88
+ messageId: string;
89
+ threadId: string;
90
+ }>;
91
+
92
+ declare const addReaction: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
93
+ threadId: string;
94
+ messageId: string;
95
+ emoji: string;
96
+ }, {
97
+ added: boolean;
98
+ emoji: string;
99
+ messageId: string;
100
+ threadId: string;
101
+ }>;
102
+ declare const removeReaction: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
103
+ threadId: string;
104
+ messageId: string;
105
+ emoji: string;
106
+ }, {
107
+ removed: boolean;
108
+ emoji: string;
109
+ messageId: string;
110
+ threadId: string;
111
+ }>;
112
+
113
+ declare const fetchMessages: (chat: ChatBinding) => ai.Tool<{
114
+ threadId: string;
115
+ limit: number;
116
+ direction: "forward" | "backward";
117
+ cursor?: string | undefined;
118
+ }, {
119
+ messages: {
120
+ id: string;
121
+ threadId: string;
122
+ text: string;
123
+ author: {
124
+ userId: string;
125
+ userName: string;
126
+ fullName: string;
127
+ isBot: boolean | "unknown";
128
+ isMe: boolean;
129
+ };
130
+ dateSent: string;
131
+ edited: boolean;
132
+ isMention: boolean | undefined;
133
+ attachments: {
134
+ type: "file" | "image" | "video" | "audio";
135
+ name: string | undefined;
136
+ mimeType: string | undefined;
137
+ url: string | undefined;
138
+ }[];
139
+ }[];
140
+ nextCursor: string | undefined;
141
+ }>;
142
+ declare const fetchChannelMessages: (chat: ChatBinding) => ai.Tool<{
143
+ channelId: string;
144
+ limit: number;
145
+ direction: "forward" | "backward";
146
+ cursor?: string | undefined;
147
+ }, {
148
+ messages: any;
149
+ nextCursor: any;
150
+ }>;
151
+ declare const fetchThread: (chat: ChatBinding) => ai.Tool<{
152
+ threadId: string;
153
+ }, {
154
+ id: string;
155
+ channelId: string;
156
+ channelName: string | undefined;
157
+ channelVisibility: ChannelVisibility | undefined;
158
+ isDM: boolean;
159
+ }>;
160
+ declare const listThreads: (chat: ChatBinding) => ai.Tool<{
161
+ channelId: string;
162
+ limit: number;
163
+ cursor?: string | undefined;
164
+ }, {
165
+ threads: any;
166
+ nextCursor: any;
167
+ }>;
168
+ declare const getThreadParticipants: (chat: ChatBinding) => ai.Tool<{
169
+ threadId: string;
170
+ }, {
171
+ participants: {
172
+ userId: string;
173
+ userName: string;
174
+ fullName: string;
175
+ isBot: boolean | "unknown";
176
+ }[];
177
+ }>;
178
+ declare const subscribeThread: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
179
+ threadId: string;
180
+ }, {
181
+ subscribed: boolean;
182
+ threadId: string;
183
+ }>;
184
+ declare const unsubscribeThread: (chat: ChatBinding, { needsApproval }?: ToolOptions) => ai.Tool<{
185
+ threadId: string;
186
+ }, {
187
+ subscribed: boolean;
188
+ threadId: string;
189
+ }>;
190
+ declare const startTyping: (chat: ChatBinding) => ai.Tool<{
191
+ threadId: string;
192
+ status?: string | undefined;
193
+ }, {
194
+ typing: boolean;
195
+ threadId: string;
196
+ }>;
197
+
198
+ declare const getUser: (chat: ChatBinding) => ai.Tool<{
199
+ userId: string;
200
+ }, {
201
+ userId: string;
202
+ userName: string;
203
+ fullName: string;
204
+ email: string | undefined;
205
+ isBot: boolean;
206
+ avatarUrl: string | undefined;
207
+ } | null>;
208
+
209
+ type ChatToolName = "fetchMessages" | "fetchChannelMessages" | "fetchThread" | "listThreads" | "getThreadParticipants" | "getChannelInfo" | "getUser" | "startTyping" | "postMessage" | "postChannelMessage" | "sendDirectMessage" | "editMessage" | "deleteMessage" | "addReaction" | "removeReaction" | "subscribeThread" | "unsubscribeThread";
210
+ /**
211
+ * Names of every tool that mutates platform state.
212
+ * These default to `needsApproval: true` and can be toggled via
213
+ * `requireApproval` on {@link createChatTools}.
214
+ */
215
+ type ChatWriteToolName = "postMessage" | "postChannelMessage" | "sendDirectMessage" | "editMessage" | "deleteMessage" | "addReaction" | "removeReaction" | "subscribeThread" | "unsubscribeThread";
216
+ /**
217
+ * Whether write operations require user approval.
218
+ *
219
+ * - `true` — every write tool needs approval (default)
220
+ * - `false` — no write tool needs approval
221
+ * - object — per-tool override; unspecified write tools default to `true`
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * requireApproval: {
226
+ * deleteMessage: true,
227
+ * postMessage: false,
228
+ * sendDirectMessage: false,
229
+ * addReaction: false,
230
+ * }
231
+ * ```
232
+ */
233
+ type ApprovalConfig = boolean | Partial<Record<ChatWriteToolName, boolean>>;
234
+ /**
235
+ * Predefined tool presets for common chat-agent use cases.
236
+ *
237
+ * - `'reader'` — read-only: fetch threads, messages, channel info, users
238
+ * - `'messenger'` — basic posting: post in thread/channel, DM, react, typing
239
+ * - `'moderator'` — full management: read + write + edit/delete + subscriptions
240
+ */
241
+ type ChatToolPreset = "reader" | "messenger" | "moderator";
242
+ interface ChatToolsOptions {
243
+ /** The Chat instance the tools dispatch operations against. */
244
+ chat: ChatBinding;
245
+ /**
246
+ * Per-tool overrides for customizing tool behavior (description, title,
247
+ * needsApproval, etc.) without changing the underlying implementation.
248
+ * Core tool fields cannot be overridden.
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * createChatTools({
253
+ * chat,
254
+ * overrides: {
255
+ * deleteMessage: { needsApproval: false },
256
+ * postMessage: { description: 'Reply in the active support thread.' },
257
+ * },
258
+ * })
259
+ * ```
260
+ */
261
+ overrides?: Partial<Record<ChatToolName, ToolOverrides>>;
262
+ /**
263
+ * Restrict the returned tools to a predefined preset.
264
+ * Omit to get all tools (same as `'moderator'`).
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * createChatTools({ chat, preset: 'reader' })
269
+ * createChatTools({ chat, preset: ['reader', 'messenger'] })
270
+ * ```
271
+ */
272
+ preset?: ChatToolPreset | ChatToolPreset[];
273
+ /**
274
+ * Whether write operations require user approval before executing.
275
+ * Defaults to `true` for all write tools.
276
+ *
277
+ * @see {@link ApprovalConfig}
278
+ */
279
+ requireApproval?: ApprovalConfig;
280
+ }
281
+ /**
282
+ * Create a set of Chat SDK tools for the Vercel AI SDK.
283
+ *
284
+ * Lets an AI agent operate inside a workspace: read messages, post replies,
285
+ * send DMs, react, edit, delete, and manage thread subscriptions across
286
+ * every adapter the supplied {@link ChatBinding} has registered.
287
+ *
288
+ * Write operations require user approval by default. Control this globally
289
+ * or per-tool via `requireApproval`. Use `preset` to scope the toolset.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * import { Chat } from 'chat'
294
+ * import { createChatTools } from 'chat/ai'
295
+ * import { generateText } from 'ai'
296
+ *
297
+ * const chat = new Chat({ ... })
298
+ *
299
+ * const result = await generateText({
300
+ * model: yourModel,
301
+ * tools: createChatTools({ chat, preset: 'messenger' }),
302
+ * prompt: 'Reply in thread slack:C123:1234.5678 with the daily summary.',
303
+ * })
304
+ * ```
305
+ *
306
+ * @example Granular approval
307
+ * ```ts
308
+ * createChatTools({
309
+ * chat,
310
+ * preset: 'moderator',
311
+ * requireApproval: {
312
+ * deleteMessage: true,
313
+ * editMessage: true,
314
+ * postMessage: false,
315
+ * addReaction: false,
316
+ * },
317
+ * })
318
+ * ```
319
+ */
320
+ declare function createChatTools({ chat, requireApproval, preset, overrides, }: ChatToolsOptions): Partial<{
321
+ fetchMessages: ai.Tool<{
322
+ threadId: string;
323
+ limit: number;
324
+ direction: "forward" | "backward";
325
+ cursor?: string | undefined;
326
+ }, {
327
+ messages: {
328
+ id: string;
329
+ threadId: string;
330
+ text: string;
331
+ author: {
332
+ userId: string;
333
+ userName: string;
334
+ fullName: string;
335
+ isBot: boolean | "unknown";
336
+ isMe: boolean;
337
+ };
338
+ dateSent: string;
339
+ edited: boolean;
340
+ isMention: boolean | undefined;
341
+ attachments: {
342
+ type: "file" | "image" | "video" | "audio";
343
+ name: string | undefined;
344
+ mimeType: string | undefined;
345
+ url: string | undefined;
346
+ }[];
347
+ }[];
348
+ nextCursor: string | undefined;
349
+ }>;
350
+ fetchChannelMessages: ai.Tool<{
351
+ channelId: string;
352
+ limit: number;
353
+ direction: "forward" | "backward";
354
+ cursor?: string | undefined;
355
+ }, {
356
+ messages: any;
357
+ nextCursor: any;
358
+ }>;
359
+ fetchThread: ai.Tool<{
360
+ threadId: string;
361
+ }, {
362
+ id: string;
363
+ channelId: string;
364
+ channelName: string | undefined;
365
+ channelVisibility: ChannelVisibility | undefined;
366
+ isDM: boolean;
367
+ }>;
368
+ listThreads: ai.Tool<{
369
+ channelId: string;
370
+ limit: number;
371
+ cursor?: string | undefined;
372
+ }, {
373
+ threads: any;
374
+ nextCursor: any;
375
+ }>;
376
+ getThreadParticipants: ai.Tool<{
377
+ threadId: string;
378
+ }, {
379
+ participants: {
380
+ userId: string;
381
+ userName: string;
382
+ fullName: string;
383
+ isBot: boolean | "unknown";
384
+ }[];
385
+ }>;
386
+ getChannelInfo: ai.Tool<{
387
+ channelId: string;
388
+ }, {
389
+ id: string;
390
+ name: string | undefined;
391
+ isDM: boolean;
392
+ memberCount: number | undefined;
393
+ channelVisibility: ChannelVisibility | undefined;
394
+ }>;
395
+ getUser: ai.Tool<{
396
+ userId: string;
397
+ }, {
398
+ userId: string;
399
+ userName: string;
400
+ fullName: string;
401
+ email: string | undefined;
402
+ isBot: boolean;
403
+ avatarUrl: string | undefined;
404
+ } | null>;
405
+ startTyping: ai.Tool<{
406
+ threadId: string;
407
+ status?: string | undefined;
408
+ }, {
409
+ typing: boolean;
410
+ threadId: string;
411
+ }>;
412
+ postMessage: ai.Tool<{
413
+ threadId: string;
414
+ message: string | {
415
+ markdown: string;
416
+ } | {
417
+ raw: string;
418
+ };
419
+ }, {
420
+ messageId: string;
421
+ threadId: string;
422
+ }>;
423
+ postChannelMessage: ai.Tool<{
424
+ channelId: string;
425
+ message: string | {
426
+ markdown: string;
427
+ } | {
428
+ raw: string;
429
+ };
430
+ }, {
431
+ messageId: string;
432
+ threadId: string;
433
+ }>;
434
+ sendDirectMessage: ai.Tool<{
435
+ userId: string;
436
+ message: string | {
437
+ markdown: string;
438
+ } | {
439
+ raw: string;
440
+ };
441
+ }, {
442
+ messageId: string;
443
+ threadId: string;
444
+ }>;
445
+ editMessage: ai.Tool<{
446
+ threadId: string;
447
+ messageId: string;
448
+ message: string | {
449
+ markdown: string;
450
+ } | {
451
+ raw: string;
452
+ };
453
+ }, {
454
+ messageId: string;
455
+ threadId: string;
456
+ }>;
457
+ deleteMessage: ai.Tool<{
458
+ threadId: string;
459
+ messageId: string;
460
+ }, {
461
+ deleted: boolean;
462
+ messageId: string;
463
+ threadId: string;
464
+ }>;
465
+ addReaction: ai.Tool<{
466
+ threadId: string;
467
+ messageId: string;
468
+ emoji: string;
469
+ }, {
470
+ added: boolean;
471
+ emoji: string;
472
+ messageId: string;
473
+ threadId: string;
474
+ }>;
475
+ removeReaction: ai.Tool<{
476
+ threadId: string;
477
+ messageId: string;
478
+ emoji: string;
479
+ }, {
480
+ removed: boolean;
481
+ emoji: string;
482
+ messageId: string;
483
+ threadId: string;
484
+ }>;
485
+ subscribeThread: ai.Tool<{
486
+ threadId: string;
487
+ }, {
488
+ subscribed: boolean;
489
+ threadId: string;
490
+ }>;
491
+ unsubscribeThread: ai.Tool<{
492
+ threadId: string;
493
+ }, {
494
+ subscribed: boolean;
495
+ threadId: string;
496
+ }>;
497
+ }>;
498
+ /** The shape of the object returned by {@link createChatTools}. */
499
+ type ChatTools = ReturnType<typeof createChatTools>;
500
+
501
+ export { type ApprovalConfig, type ChatBinding, type ChatToolName, type ChatToolPreset, type ChatTools, type ChatToolsOptions, type ChatWriteToolName, type ToolOptions, type ToolOverrides, addReaction, createChatTools, deleteMessage, editMessage, fetchChannelMessages, fetchMessages, fetchThread, getChannelInfo, getThreadParticipants, getUser, listThreads, postChannelMessage, postMessage, removeReaction, sendDirectMessage, startTyping, subscribeThread, unsubscribeThread };