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.
- package/dist/ai/index.d.ts +501 -0
- package/dist/ai/index.js +500 -0
- package/dist/chat-D9UYaaNO.d.ts +3156 -0
- package/dist/chunk-HD375J7S.js +128 -0
- package/dist/{chunk-AN7MRAVW.js → chunk-V25FKIIL.js} +5 -1
- package/dist/index.d.ts +35 -2934
- package/dist/index.js +567 -210
- package/dist/{jsx-runtime-Co9uV6l7.d.ts → jsx-runtime-CFq1K_Ve.d.ts} +11 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/docs/actions.mdx +52 -1
- package/docs/adapters.mdx +72 -36
- package/docs/ai/ai-sdk-tools.mdx +227 -0
- package/docs/ai/index.mdx +63 -0
- package/docs/ai/meta.json +4 -0
- package/docs/{api → ai}/to-ai-messages.mdx +16 -3
- package/docs/ai/types.mdx +243 -0
- package/docs/api/cards.mdx +4 -0
- package/docs/api/chat.mdx +132 -10
- package/docs/api/index.mdx +6 -6
- package/docs/api/markdown.mdx +28 -5
- package/docs/api/message.mdx +54 -1
- package/docs/api/meta.json +1 -0
- package/docs/api/modals.mdx +50 -0
- package/docs/api/postable-message.mdx +58 -4
- package/docs/api/thread.mdx +11 -3
- package/docs/api/transcripts.mdx +220 -0
- package/docs/cards.mdx +6 -0
- package/docs/concurrency.mdx +58 -15
- package/docs/contributing/building.mdx +74 -2
- package/docs/contributing/testing.mdx +4 -0
- package/docs/conversation-history.mdx +137 -0
- package/docs/direct-messages.mdx +23 -5
- package/docs/ephemeral-messages.mdx +1 -1
- package/docs/error-handling.mdx +15 -3
- package/docs/files.mdx +21 -1
- package/docs/handling-events.mdx +10 -7
- package/docs/index.mdx +8 -5
- package/docs/meta.json +17 -3
- package/docs/modals.mdx +24 -0
- package/docs/posting-messages.mdx +10 -4
- package/docs/slash-commands.mdx +4 -4
- package/docs/streaming.mdx +75 -27
- package/docs/subject.mdx +53 -0
- package/docs/testing.mdx +142 -0
- package/docs/threads-messages-channels.mdx +10 -1
- package/docs/usage.mdx +15 -2
- package/package.json +23 -2
- package/resources/guides/how-to-build-an-ai-agent-for-slack-with-chat-sdk-and-ai-sdk.md +1 -1
|
@@ -52,6 +52,8 @@ type TextStyle = "plain" | "bold" | "muted";
|
|
|
52
52
|
interface ButtonElement {
|
|
53
53
|
/** Whether this button triggers a regular action or opens a modal dialog. Default: "action" */
|
|
54
54
|
actionType?: "action" | "modal";
|
|
55
|
+
/** URL to POST action data to when this button is clicked */
|
|
56
|
+
callbackUrl?: string;
|
|
55
57
|
/** If true, the button is displayed in an inactive state and doesn't respond to user actions */
|
|
56
58
|
disabled?: boolean;
|
|
57
59
|
/** Unique action ID for callback routing */
|
|
@@ -241,6 +243,8 @@ declare function Actions(children: (ButtonElement | LinkButtonElement | SelectEl
|
|
|
241
243
|
interface ButtonOptions {
|
|
242
244
|
/** Whether this button triggers a regular action or opens a modal dialog. Default: "action" */
|
|
243
245
|
actionType?: "action" | "modal";
|
|
246
|
+
/** URL to POST action data to when this button is clicked */
|
|
247
|
+
callbackUrl?: string;
|
|
244
248
|
/** If true, the button is displayed in an inactive state and doesn't respond to user actions */
|
|
245
249
|
disabled?: boolean;
|
|
246
250
|
/** Unique action ID for callback routing */
|
|
@@ -374,6 +378,8 @@ declare function cardChildToFallbackText(child: CardChild): string | null;
|
|
|
374
378
|
type ModalChild = TextInputElement | SelectElement | ExternalSelectElement | RadioSelectElement | TextElement | FieldsElement;
|
|
375
379
|
interface ModalElement {
|
|
376
380
|
callbackId: string;
|
|
381
|
+
/** URL to POST form values to when this modal is submitted */
|
|
382
|
+
callbackUrl?: string;
|
|
377
383
|
children: ModalChild[];
|
|
378
384
|
closeLabel?: string;
|
|
379
385
|
notifyOnClose?: boolean;
|
|
@@ -427,6 +433,8 @@ interface RadioSelectElement {
|
|
|
427
433
|
declare function isModalElement(value: unknown): value is ModalElement;
|
|
428
434
|
interface ModalOptions {
|
|
429
435
|
callbackId: string;
|
|
436
|
+
/** URL to POST form values to when this modal is submitted */
|
|
437
|
+
callbackUrl?: string;
|
|
430
438
|
children?: ModalChild[];
|
|
431
439
|
closeLabel?: string;
|
|
432
440
|
notifyOnClose?: boolean;
|
|
@@ -527,6 +535,7 @@ interface TextProps {
|
|
|
527
535
|
/** Props for Button component in JSX */
|
|
528
536
|
interface ButtonProps {
|
|
529
537
|
actionType?: "action" | "modal";
|
|
538
|
+
callbackUrl?: string;
|
|
530
539
|
children?: string | number | (string | number | undefined)[];
|
|
531
540
|
disabled?: boolean;
|
|
532
541
|
id: string;
|
|
@@ -566,6 +575,7 @@ type DividerProps = Record<string, never>;
|
|
|
566
575
|
/** Props for Modal component in JSX */
|
|
567
576
|
interface ModalProps {
|
|
568
577
|
callbackId: string;
|
|
578
|
+
callbackUrl?: string;
|
|
569
579
|
children?: unknown;
|
|
570
580
|
closeLabel?: string;
|
|
571
581
|
notifyOnClose?: boolean;
|
|
@@ -769,4 +779,4 @@ declare namespace JSX {
|
|
|
769
779
|
}
|
|
770
780
|
}
|
|
771
781
|
|
|
772
|
-
export { type
|
|
782
|
+
export { type DividerProps as $, type ActionsComponent as A, type ButtonComponent as B, type CardElement as C, type DividerComponent as D, type ExternalSelectComponent as E, type FieldComponent as F, type LinkButtonOptions as G, type LinkElement as H, type ImageComponent as I, type SectionElement as J, type TableAlignment as K, type LinkButtonComponent as L, type ModalComponent as M, type TableElement as N, type TableOptions as O, type TextElement as P, type TextStyle as Q, type RadioSelectComponent as R, type SectionComponent as S, type TextComponent as T, type ButtonProps as U, type CardJSXElement as V, type CardJSXProps as W, type CardLinkProps as X, type CardProps as Y, type ChatElement as Z, type ContainerProps as _, type CardChild as a, type ExternalSelectProps as a0, type FieldProps as a1, type ImageProps as a2, type LinkButtonProps as a3, type ModalProps as a4, type SelectOptionProps as a5, type SelectProps as a6, type TextInputProps as a7, type TextProps as a8, type ExternalSelectElement as a9, type ExternalSelectOptions as aa, type ModalChild as ab, type ModalElement as ac, type ModalOptions as ad, type RadioSelectElement as ae, type RadioSelectOptions as af, type SelectElement as ag, type SelectOptionElement as ah, type SelectOptions as ai, type TextInputElement as aj, type TextInputOptions as ak, type TableProps as al, type TableComponent as am, isCardLinkProps as an, jsx as ao, jsxs as ap, jsxDEV as aq, Fragment as ar, JSX as as, type CardComponent as b, cardChildToFallbackText as c, type CardLinkComponent as d, type FieldsComponent as e, fromReactElement as f, isJSX as g, Table as h, isCardElement as i, toModalElement as j, fromReactModalElement as k, isModalElement as l, type SelectComponent as m, type SelectOptionComponent as n, type TextInputComponent as o, type ActionsElement as p, type ButtonElement as q, type ButtonOptions as r, type ButtonStyle as s, toCardElement as t, type CardOptions as u, type DividerElement as v, type FieldElement as w, type FieldsElement as x, type ImageElement as y, type LinkButtonElement as z };
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as ActionsComponent, B as ButtonComponent,
|
|
1
|
+
export { A as ActionsComponent, B as ButtonComponent, U as ButtonProps, b as CardComponent, V as CardJSXElement, W as CardJSXProps, d as CardLinkComponent, X as CardLinkProps, Y as CardProps, Z as ChatElement, _ as ContainerProps, D as DividerComponent, $ as DividerProps, E as ExternalSelectComponent, a0 as ExternalSelectProps, F as FieldComponent, a1 as FieldProps, e as FieldsComponent, ar as Fragment, I as ImageComponent, a2 as ImageProps, as as JSX, L as LinkButtonComponent, a3 as LinkButtonProps, M as ModalComponent, a4 as ModalProps, R as RadioSelectComponent, S as SectionComponent, m as SelectComponent, n as SelectOptionComponent, a5 as SelectOptionProps, a6 as SelectProps, am as TableComponent, al as TableProps, T as TextComponent, o as TextInputComponent, a7 as TextInputProps, a8 as TextProps, an as isCardLinkProps, g as isJSX, ao as jsx, aq as jsxDEV, ap as jsxs, t as toCardElement, j as toModalElement } from './jsx-runtime-CFq1K_Ve.js';
|
package/dist/jsx-runtime.js
CHANGED
package/docs/actions.mdx
CHANGED
|
@@ -94,5 +94,56 @@ bot.onAction("feedback", async (event) => {
|
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
<Callout type="info">
|
|
97
|
-
Modals are currently supported on Slack. Other platforms will receive a no-op
|
|
97
|
+
Modals are currently supported on Slack and Teams. Other platforms will receive a no-op
|
|
98
|
+
or fallback behavior.
|
|
98
99
|
</Callout>
|
|
100
|
+
|
|
101
|
+
## Callback URLs
|
|
102
|
+
|
|
103
|
+
Buttons accept a `callbackUrl` prop. When clicked, the action data is POSTed to that URL in addition to firing any `onAction` handler. This pairs naturally with webhook-based workflow engines to build approval flows without any `onAction` handler at all:
|
|
104
|
+
|
|
105
|
+
```tsx title="lib/bot.tsx" lineNumbers
|
|
106
|
+
bot.onNewMention(async (thread) => {
|
|
107
|
+
const approveUrl = "https://example.com/webhook/approve";
|
|
108
|
+
const denyUrl = "https://example.com/webhook/deny";
|
|
109
|
+
|
|
110
|
+
await thread.post(
|
|
111
|
+
<Card title="Deploy v2.4.1?">
|
|
112
|
+
<Actions>
|
|
113
|
+
<Button callbackUrl={approveUrl} id="approve" style="primary">
|
|
114
|
+
Approve
|
|
115
|
+
</Button>
|
|
116
|
+
<Button callbackUrl={denyUrl} id="deny" style="danger">
|
|
117
|
+
Deny
|
|
118
|
+
</Button>
|
|
119
|
+
</Actions>
|
|
120
|
+
</Card>
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Callback payload
|
|
126
|
+
|
|
127
|
+
The POST body sent to the `callbackUrl`:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"type": "action",
|
|
132
|
+
"actionId": "approve",
|
|
133
|
+
"user": { "id": "U123", "name": "alice" },
|
|
134
|
+
"threadId": "slack:C123:1234567890.123",
|
|
135
|
+
"messageId": "1234567890.456"
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
If the button also has a `value` prop, it is included in the payload as `"value"`.
|
|
140
|
+
|
|
141
|
+
<Callout type="info">
|
|
142
|
+
Platform limits apply to encoded button data. Discord's `custom_id` has a 100
|
|
143
|
+
character limit - if the action ID plus callback token exceed this, posting
|
|
144
|
+
the card throws a `ValidationError`. Telegram's `callback_data` has a 64 byte
|
|
145
|
+
limit - buttons that exceed this will throw a `ValidationError`. Keep action
|
|
146
|
+
IDs short when using `callbackUrl` on these platforms.
|
|
147
|
+
</Callout>
|
|
148
|
+
|
|
149
|
+
For modals, see [callbackUrl on modals](/docs/modals#callback-urls).
|
package/docs/adapters.mdx
CHANGED
|
@@ -8,57 +8,64 @@ prerequisites:
|
|
|
8
8
|
|
|
9
9
|
Adapters handle webhook verification, message parsing, and API calls for each platform. Install only the adapters you need. Browse all available adapters — including community-built ones — on the [Adapters](/adapters) page.
|
|
10
10
|
|
|
11
|
+
Need a browser chat UI? See the [Web adapter](/adapters/official/web) — it speaks the AI SDK UI stream protocol and works with React (`@ai-sdk/react`), Vue (`@ai-sdk/vue`), and Svelte (`@ai-sdk/svelte`), so the same bot serves Slack, Teams, **and** any browser framework out of the box.
|
|
12
|
+
|
|
11
13
|
Ready to build your own? Follow the [building](/docs/contributing/building) guide.
|
|
12
14
|
|
|
13
15
|
## Feature matrix
|
|
14
16
|
|
|
17
|
+
<GlobalFeatureMatrix type="platform" />
|
|
15
18
|
### Messaging
|
|
16
19
|
|
|
17
|
-
| Feature | [Slack](/adapters/slack) | [Teams](/adapters/teams) | [Google Chat](/adapters/google-chat) | [Discord](/adapters/discord) | [Telegram](/adapters/telegram) | [GitHub](/adapters/github) | [Linear](/adapters/linear) | [WhatsApp](/adapters/whatsapp) |
|
|
18
|
-
|
|
19
|
-
| Post message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
20
|
-
| Edit message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <
|
|
21
|
-
| Delete message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <
|
|
22
|
-
| File uploads | <Check /> | <Check /> | <Cross /> | <Check /> | <Warn /> Single file | <Cross /> | <Cross /> | <Check /> Images, audio, docs |
|
|
23
|
-
| Streaming | <Check /> Native | <Warn />
|
|
24
|
-
| Scheduled messages | <Check /> Native | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
20
|
+
| Feature | [Slack](/adapters/slack) | [Teams](/adapters/teams) | [Google Chat](/adapters/google-chat) | [Discord](/adapters/discord) | [Telegram](/adapters/telegram) | [GitHub](/adapters/github) | [Linear](/adapters/linear) | [WhatsApp](/adapters/whatsapp) | [Messenger](/adapters/messenger) |
|
|
21
|
+
|---------|-------|-------|-------------|---------|---------|--------|--------|-----------|-----------|
|
|
22
|
+
| Post message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
23
|
+
| Edit message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Partial | <Cross /> | <Cross /> |
|
|
24
|
+
| Delete message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Partial | <Cross /> | <Cross /> |
|
|
25
|
+
| File uploads | <Check /> | <Check /> | <Cross /> | <Check /> | <Warn /> Single file/media | <Cross /> | <Cross /> | <Check /> Images, audio, docs | <Cross /> |
|
|
26
|
+
| Streaming | <Check /> Native | <Warn /> Native (DMs) / Buffered | <Warn /> Post+Edit | <Warn /> Post+Edit | <Warn /> Post+Edit | <Warn /> Buffered | <Warn /> Agent sessions / Post+Edit | <Warn /> Buffered | <Warn /> Buffered |
|
|
27
|
+
| Scheduled messages | <Check /> Native | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
25
28
|
|
|
26
29
|
### Rich content
|
|
27
30
|
|
|
28
|
-
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp |
|
|
29
|
-
|
|
30
|
-
| Card format | Block Kit | Adaptive Cards | Google Chat Cards | Embeds | Markdown + inline keyboard buttons | GFM Markdown | Markdown | WhatsApp templates |
|
|
31
|
-
| Buttons | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Inline keyboard callbacks | <Cross /> | <Cross /> | <Check /> Interactive replies |
|
|
32
|
-
| Link buttons | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Inline keyboard URLs | <Cross /> | <Cross /> | <Cross /> |
|
|
33
|
-
| Select menus | <Check /> | <Cross /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
34
|
-
| Tables | <Check /> Block Kit | <Check /> GFM | <Warn /> ASCII | <Check /> GFM | <Warn /> ASCII | <Check /> GFM | <Check /> GFM | <Cross /> |
|
|
35
|
-
| Fields | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Template variables |
|
|
36
|
-
| Images in cards | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> | <Check /> |
|
|
37
|
-
| Modals | <Check /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
31
|
+
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp | Messenger |
|
|
32
|
+
|---------|-------|-------|-------------|---------|----------|--------|--------|-----------|-----------|
|
|
33
|
+
| Card format | Block Kit | Adaptive Cards | Google Chat Cards | Embeds | Markdown + inline keyboard buttons | GFM Markdown | Markdown | WhatsApp templates | Generic/Button Templates |
|
|
34
|
+
| Buttons | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Inline keyboard callbacks | <Cross /> | <Cross /> | <Check /> Interactive replies | <Warn /> Max 3, postback |
|
|
35
|
+
| Link buttons | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Inline keyboard URLs | <Cross /> | <Cross /> | <Cross /> | <Check /> |
|
|
36
|
+
| Select menus | <Check /> | <Cross /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
37
|
+
| Tables | <Check /> Block Kit | <Check /> GFM | <Warn /> ASCII | <Check /> GFM | <Warn /> ASCII | <Check /> GFM | <Check /> GFM | <Cross /> | <Warn /> ASCII |
|
|
38
|
+
| Fields | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Template variables | <Warn /> ASCII |
|
|
39
|
+
| Images in cards | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> | <Check /> | <Check /> |
|
|
40
|
+
| Modals | <Check /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
38
41
|
|
|
39
42
|
### Conversations
|
|
40
43
|
|
|
41
|
-
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp |
|
|
42
|
-
|
|
43
|
-
| Slash commands | <Check /> | <Cross /> | <Cross /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
44
|
-
| Mentions | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> |
|
|
45
|
-
| Add reactions | <Check /> | <Cross /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> |
|
|
46
|
-
| Remove reactions | <Check /> | <Cross /> | <Check /> | <Check /> | <Check /> | <Warn /> | <Warn /> | <Cross /> |
|
|
47
|
-
| Typing indicator | <
|
|
48
|
-
| DMs | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> | <Check /> |
|
|
49
|
-
| Ephemeral messages | <Check /> Native | <Cross /> | <Check /> Native | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
44
|
+
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp | Messenger |
|
|
45
|
+
|---------|-------|-------|-------------|---------|----------|--------|--------|-----------|-----------|
|
|
46
|
+
| Slash commands | <Check /> | <Cross /> | <Cross /> | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
47
|
+
| Mentions | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Check /> |
|
|
48
|
+
| Add reactions | <Check /> | <Cross /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> |
|
|
49
|
+
| Remove reactions | <Check /> | <Cross /> | <Check /> | <Check /> | <Check /> | <Warn /> | <Warn /> | <Check /> | <Cross /> |
|
|
50
|
+
| Typing indicator | <Check /> | <Check /> | <Cross /> | <Check /> | <Check /> | <Cross /> | <Warn /> Agent sessions | <Cross /> | <Check /> |
|
|
51
|
+
| DMs | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> | <Check /> | <Check /> |
|
|
52
|
+
| Ephemeral messages | <Check /> Native | <Cross /> | <Check /> Native | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> |
|
|
53
|
+
| User lookup ([`getUser`](/docs/api/chat#getuser)) | <Check /> | <Warn /> Cached | <Warn /> Cached | <Check /> | <Warn /> Seen users | <Check /> | <Check /> | <Cross /> | <Cross /> |
|
|
54
|
+
| Parent subject ([`message.subject`](/docs/subject)) | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Check /> | <Check /> | <Cross /> | <Cross /> |
|
|
55
|
+
| Native client ([`.webClient` / `.octokit` / `.linearClient`](/docs/api/chat#getadapter)) | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Cross /> | <Check /> | <Check /> | <Cross /> | <Cross /> |
|
|
56
|
+
| Custom API endpoint (`apiUrl`) | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
50
57
|
|
|
51
58
|
### Message history
|
|
52
59
|
|
|
53
|
-
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp |
|
|
54
|
-
|
|
55
|
-
| Fetch messages | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Cached | <Check /> | <Check /> | <Warn /> Cached sent messages only |
|
|
56
|
-
| Fetch single message | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Warn /> Cached | <Cross /> | <Cross /> | <
|
|
57
|
-
| Fetch thread info | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <
|
|
58
|
-
| Fetch channel messages | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Cached | <Check /> | <Cross /> | <
|
|
59
|
-
| List threads | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> | <Cross /> |
|
|
60
|
-
| Fetch channel info | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> |
|
|
61
|
-
| Post channel message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> | <Check /> |
|
|
60
|
+
| Feature | Slack | Teams | Google Chat | Discord | Telegram | GitHub | Linear | WhatsApp | Messenger |
|
|
61
|
+
|---------|-------|-------|-------------|---------|----------|--------|--------|-----------|-----------|
|
|
62
|
+
| Fetch messages | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Cached | <Check /> | <Check /> | <Warn /> Cached sent messages only | <Warn /> Cached sent messages only |
|
|
63
|
+
| Fetch single message | <Check /> | <Cross /> | <Cross /> | <Cross /> | <Warn /> Cached | <Cross /> | <Cross /> | <Cross /> | <Warn /> Cached |
|
|
64
|
+
| Fetch thread info | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
65
|
+
| Fetch channel messages | <Check /> | <Check /> | <Check /> | <Check /> | <Warn /> Cached | <Check /> | <Cross /> | <Cross /> | <Warn /> Cached |
|
|
66
|
+
| List threads | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> | <Cross /> | <Cross /> |
|
|
67
|
+
| Fetch channel info | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> | <Check /> |
|
|
68
|
+
| Post channel message | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> | <Check /> | <Check /> |
|
|
62
69
|
|
|
63
70
|
<Callout type="info">
|
|
64
71
|
<Warn /> indicates partial support — the feature works with limitations. See individual adapter pages for details.
|
|
@@ -108,3 +115,32 @@ Each adapter auto-detects credentials from environment variables, so you only ne
|
|
|
108
115
|
</Callout>
|
|
109
116
|
|
|
110
117
|
Each adapter creates a webhook handler accessible via `bot.webhooks.<name>`.
|
|
118
|
+
|
|
119
|
+
## Customizing an adapter via subclassing
|
|
120
|
+
|
|
121
|
+
Each official adapter exposes its extension surface as `protected` members so you can subclass it to override or extend platform-specific behavior without forking the package. Use this when you need to handle a payload type the built-in adapter doesn't cover, intercept verification, or wrap an existing handler.
|
|
122
|
+
|
|
123
|
+
```typescript title="lib/custom-telegram.ts" lineNumbers
|
|
124
|
+
import { TelegramAdapter, type TelegramUpdate } from "@chat-adapter/telegram";
|
|
125
|
+
import type { WebhookOptions } from "chat";
|
|
126
|
+
|
|
127
|
+
export class CustomTelegramAdapter extends TelegramAdapter {
|
|
128
|
+
protected override processUpdate(
|
|
129
|
+
update: TelegramUpdate,
|
|
130
|
+
options?: WebhookOptions
|
|
131
|
+
): void {
|
|
132
|
+
// Handle a payload type the base adapter doesn't, e.g. chat_join_request.
|
|
133
|
+
if ("chat_join_request" in update) {
|
|
134
|
+
this.logger.info("Received chat_join_request", { update });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
super.processUpdate(update, options);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Construct your subclass anywhere you'd construct the base adapter — for example, `adapters: { telegram: new CustomTelegramAdapter({ ... }) }`. Members marked `private` (internal caches, in-flight runtime state, one-shot warning flags) intentionally remain inaccessible; if you find a hook you need that isn't `protected`, please open an issue.
|
|
143
|
+
|
|
144
|
+
<Callout type="warn">
|
|
145
|
+
The `protected` extension surface is intentionally broader than the public API but is not yet considered fully stable. Method signatures may evolve (renames, parameter changes, new hook splits) in minor releases as we learn from real-world subclasses. Pin the adapter version you build against, watch the changelog for the affected adapter, and prefer overriding the smallest hook that solves your problem so upgrades stay easy. If you rely on a particular hook, please open an issue so we can promote it to a stable, documented extension point.
|
|
146
|
+
</Callout>
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI SDK Tools
|
|
3
|
+
description: Give an AI agent the ability to operate inside your workspace. Post messages, send DMs, react, edit, delete; all with built-in approval gates.
|
|
4
|
+
type: guide
|
|
5
|
+
prerequisites:
|
|
6
|
+
- /docs/usage
|
|
7
|
+
related:
|
|
8
|
+
- /docs/ai
|
|
9
|
+
- /docs/ai/to-ai-messages
|
|
10
|
+
- /docs/streaming
|
|
11
|
+
- /docs/conversation-history
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
`createChatTools` exposes Chat SDK operations as ready-to-use [AI SDK](https://ai-sdk.dev) tools so an agent can act inside the same workspaces your bot is connected to: read messages, post replies, send DMs, react, edit, delete, and manage thread subscriptions across every adapter you've registered.
|
|
15
|
+
|
|
16
|
+
Write operations require user approval out of the box, toggle them globally or per-tool when you want unattended execution.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
The tools live in the [`chat/ai`](/docs/ai) subpath of the core `chat` package:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createChatTools } from "chat/ai";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`ai` and `zod` are optional peer dependencies — install them if you haven't already:
|
|
27
|
+
|
|
28
|
+
<PackageInstall package="ai zod" />
|
|
29
|
+
|
|
30
|
+
<Callout>
|
|
31
|
+
Pair `createChatTools` with [`toAiMessages`](/docs/ai/to-ai-messages)
|
|
32
|
+
to feed prior thread history into the agent before it picks a tool.
|
|
33
|
+
Both ship from the same `chat/ai` subpath, which keeps the optional
|
|
34
|
+
`ai` / `zod` peer deps out of bundles that don't import them.
|
|
35
|
+
</Callout>
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
Pass your `Chat` instance and the tools you want into any AI SDK call:
|
|
40
|
+
|
|
41
|
+
```typescript title="lib/agent.ts" lineNumbers
|
|
42
|
+
import { Chat } from "chat";
|
|
43
|
+
import { createChatTools } from "chat/ai";
|
|
44
|
+
import { createSlackAdapter } from "@chat-adapter/slack";
|
|
45
|
+
import { createMemoryState } from "@chat-adapter/state-memory";
|
|
46
|
+
import { generateText } from "ai";
|
|
47
|
+
|
|
48
|
+
const chat = new Chat({
|
|
49
|
+
userName: "mybot",
|
|
50
|
+
adapters: { slack: createSlackAdapter() },
|
|
51
|
+
state: createMemoryState(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const result = await generateText({
|
|
55
|
+
model: "anthropic/claude-sonnet-4.6",
|
|
56
|
+
tools: createChatTools({
|
|
57
|
+
chat,
|
|
58
|
+
preset: "messenger",
|
|
59
|
+
requireApproval: false, // unattended script, no human-in-the-loop needed
|
|
60
|
+
}),
|
|
61
|
+
prompt:
|
|
62
|
+
"Post a friendly hello in slack:C0123ABC and react to it with a thumbs up.",
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Each tool resolves the right adapter from the id prefix you give it (`slack:...`, `discord:...`, `gchat:...`), so the same agent can drive any platform your `Chat` instance is wired up to.
|
|
67
|
+
|
|
68
|
+
## Presets
|
|
69
|
+
|
|
70
|
+
Pass `preset` to scope the toolset down to what an agent actually needs.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// Read-only — fetch messages, threads, channel info, users
|
|
74
|
+
createChatTools({ chat, preset: "reader" });
|
|
75
|
+
|
|
76
|
+
// Basic posting — read + post + DM + react + typing indicator
|
|
77
|
+
createChatTools({ chat, preset: "messenger" });
|
|
78
|
+
|
|
79
|
+
// Full management — everything including edit, delete, subscriptions
|
|
80
|
+
createChatTools({ chat, preset: "moderator" });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Presets compose — pass an array to combine them:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
createChatTools({ chat, preset: ["reader", "messenger"] });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Omit `preset` entirely to get every tool (same as `'moderator'`).
|
|
90
|
+
|
|
91
|
+
| Preset | Tools included |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `reader` | `fetchMessages`, `fetchChannelMessages`, `fetchThread`, `listThreads`, `getThreadParticipants`, `getChannelInfo`, `getUser` |
|
|
94
|
+
| `messenger` | `fetchMessages`, `fetchThread`, `getChannelInfo`, `getUser`, `postMessage`, `postChannelMessage`, `sendDirectMessage`, `addReaction`, `removeReaction`, `startTyping` |
|
|
95
|
+
| `moderator` | All read tools plus `postMessage`, `postChannelMessage`, `sendDirectMessage`, `editMessage`, `deleteMessage`, `addReaction`, `removeReaction`, `subscribeThread`, `unsubscribeThread`, `startTyping` |
|
|
96
|
+
|
|
97
|
+
## Approval control
|
|
98
|
+
|
|
99
|
+
Write operations (posting, editing, deleting, reacting, subscribing) default to `needsApproval: true`. The AI SDK pauses execution and surfaces an approval request that your application is expected to confirm before the tool runs. This keeps a human in the loop for anything visible to the workspace.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// All writes need approval (default)
|
|
103
|
+
createChatTools({ chat });
|
|
104
|
+
|
|
105
|
+
// No approval needed
|
|
106
|
+
createChatTools({ chat, requireApproval: false });
|
|
107
|
+
|
|
108
|
+
// Per-tool — only destructive actions need approval
|
|
109
|
+
createChatTools({
|
|
110
|
+
chat,
|
|
111
|
+
requireApproval: {
|
|
112
|
+
deleteMessage: true,
|
|
113
|
+
editMessage: true,
|
|
114
|
+
sendDirectMessage: false,
|
|
115
|
+
postMessage: false,
|
|
116
|
+
addReaction: false,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Read tools (`fetchMessages`, `fetchThread`, `getChannelInfo`, …) and the `startTyping` indicator never require approval.
|
|
122
|
+
|
|
123
|
+
## Cherry-picking tools
|
|
124
|
+
|
|
125
|
+
Each tool is also exported as a standalone factory you can hand to `tools` directly:
|
|
126
|
+
|
|
127
|
+
```typescript title="lib/agent.ts" lineNumbers
|
|
128
|
+
import { fetchMessages, postMessage, addReaction } from "chat/ai";
|
|
129
|
+
|
|
130
|
+
const tools = {
|
|
131
|
+
fetchMessages: fetchMessages(chat),
|
|
132
|
+
postMessage: postMessage(chat, { needsApproval: false }),
|
|
133
|
+
addReaction: addReaction(chat, { needsApproval: false }),
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Useful when you want a small, targeted toolset without going through `createChatTools`.
|
|
138
|
+
|
|
139
|
+
## Tool overrides
|
|
140
|
+
|
|
141
|
+
Customize any AI SDK [`tool()`](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) property per tool, keyed by tool name:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import type { ChatToolName, ToolOverrides } from "chat/ai";
|
|
145
|
+
|
|
146
|
+
createChatTools({
|
|
147
|
+
chat,
|
|
148
|
+
overrides: {
|
|
149
|
+
postMessage: {
|
|
150
|
+
description: "Reply in the active customer support thread.",
|
|
151
|
+
needsApproval: false,
|
|
152
|
+
},
|
|
153
|
+
deleteMessage: { needsApproval: true },
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
| Property | Type | Description |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `description` | `string` | Custom tool description shown to the model |
|
|
161
|
+
| `title` | `string` | Human-readable title |
|
|
162
|
+
| `strict` | `boolean` | Strict mode for input generation |
|
|
163
|
+
| `inputExamples` | `array` | Examples that show the model what tool input should look like |
|
|
164
|
+
| `metadata` | `object` | Tool metadata propagated to tool call and result parts |
|
|
165
|
+
| `needsApproval` | `boolean \| function` | Gate execution behind an approval request |
|
|
166
|
+
| `providerOptions` | `ProviderOptions` | Provider-specific metadata |
|
|
167
|
+
| `onInputStart` | `function` | Callback when argument streaming starts |
|
|
168
|
+
| `onInputDelta` | `function` | Callback on each streaming delta |
|
|
169
|
+
| `onInputAvailable` | `function` | Callback when full input is available |
|
|
170
|
+
| `toModelOutput` | `function` | Custom mapping of tool result to model output |
|
|
171
|
+
|
|
172
|
+
Core properties (`execute`, `inputSchema`, `outputSchema`, and tool-kind fields like `type`, `id`, `args`) cannot be overridden so tool semantics stay stable.
|
|
173
|
+
|
|
174
|
+
## Available tools
|
|
175
|
+
|
|
176
|
+
All ids accept the full Chat SDK form: `slack:C123ABC:1234567890.123456` for a thread, `slack:C123ABC` for a channel, and the platform-native user id (e.g. `U123456` on Slack, `users/123` on Google Chat). The tools auto-detect the adapter from the prefix.
|
|
177
|
+
|
|
178
|
+
### Reading
|
|
179
|
+
|
|
180
|
+
| Tool | Description |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `fetchMessages` | Fetch recent messages from a thread (paginated) |
|
|
183
|
+
| `fetchChannelMessages` | Fetch top-level messages in a channel (not thread replies) |
|
|
184
|
+
| `fetchThread` | Fetch metadata for a thread (channel id, visibility, DM status) |
|
|
185
|
+
| `listThreads` | List recent threads in a channel with their root message |
|
|
186
|
+
| `getThreadParticipants` | Return the unique non-bot participants in a thread |
|
|
187
|
+
| `getChannelInfo` | Fetch channel metadata (name, member count, visibility) |
|
|
188
|
+
| `getUser` | Look up a user's profile by id |
|
|
189
|
+
|
|
190
|
+
### Writing
|
|
191
|
+
|
|
192
|
+
| Tool | Description | Default approval |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `postMessage` | Post a reply in an existing thread | required |
|
|
195
|
+
| `postChannelMessage` | Post a top-level message in a channel | required |
|
|
196
|
+
| `sendDirectMessage` | Open a DM with a user and post in it | required |
|
|
197
|
+
| `editMessage` | Edit a message the bot previously posted | required |
|
|
198
|
+
| `deleteMessage` | Delete a message the bot previously posted | required |
|
|
199
|
+
| `addReaction` | Add an emoji reaction to a message | required |
|
|
200
|
+
| `removeReaction` | Remove a previously-added reaction | required |
|
|
201
|
+
| `subscribeThread` | Subscribe the bot to all future messages in a thread | required |
|
|
202
|
+
| `unsubscribeThread` | Stop receiving non-mention messages in a thread | required |
|
|
203
|
+
| `startTyping` | Show a typing indicator in a thread | not gated |
|
|
204
|
+
|
|
205
|
+
## API
|
|
206
|
+
|
|
207
|
+
### `createChatTools(options)`
|
|
208
|
+
|
|
209
|
+
Returns an object of tools, ready to spread into `tools` of any AI SDK call.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
type ChatToolsOptions = {
|
|
213
|
+
chat: Chat;
|
|
214
|
+
requireApproval?: boolean | Partial<Record<ChatWriteToolName, boolean>>;
|
|
215
|
+
preset?: ChatToolPreset | ChatToolPreset[];
|
|
216
|
+
overrides?: Partial<Record<ChatToolName, ToolOverrides>>;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
type ChatToolPreset = "reader" | "messenger" | "moderator";
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
| Option | Description |
|
|
223
|
+
|---|---|
|
|
224
|
+
| `chat` | The `Chat` instance the tools dispatch operations against. Required. |
|
|
225
|
+
| `preset` | Preset (or array of presets) restricting which tools are returned. Omit to get every tool. |
|
|
226
|
+
| `requireApproval` | `true` (default), `false`, or per-tool overrides. Read tools and `startTyping` are never gated. |
|
|
227
|
+
| `overrides` | Per-tool customization of any AI SDK `tool()` property except `execute`, `inputSchema`, and `outputSchema`. |
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview
|
|
3
|
+
description: AI utilities that ship with Chat SDK — agent tools, message conversion, and supporting types.
|
|
4
|
+
type: overview
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `chat/ai` subpath is the home for AI utilities that ship with Chat SDK.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createChatTools, toAiMessages } from "chat/ai";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add the optional peers if you don't already have them:
|
|
14
|
+
|
|
15
|
+
<PackageInstall package="ai zod" />
|
|
16
|
+
|
|
17
|
+
## What's included
|
|
18
|
+
|
|
19
|
+
| Page | What it gives you |
|
|
20
|
+
|---|---|
|
|
21
|
+
| [AI SDK Tools](/docs/ai/ai-sdk-tools) | `createChatTools` and standalone tool factories that let an agent post messages, send DMs, react, edit, delete, and manage subscriptions across every adapter your `Chat` instance has registered. Built-in approval gates and presets keep writes safe. |
|
|
22
|
+
| [`toAiMessages`](/docs/ai/to-ai-messages) | Convert Chat SDK [`Message[]`](/docs/api/message) into the `{ role, content }[]` shape expected by AI SDK calls. Handles role mapping, attachments, links, sorting, and optional per-message transforms. |
|
|
23
|
+
| [Types](/docs/ai/types) | Reference for every type exported from `chat/ai` — agent message shapes, tool option contracts, presets, approval config, and the binding type that ties tools to your `Chat` instance. |
|
|
24
|
+
|
|
25
|
+
## Typical flow
|
|
26
|
+
|
|
27
|
+
A Chat SDK bot wired to a tool-calling agent usually looks like this:
|
|
28
|
+
|
|
29
|
+
```typescript title="lib/agent.ts" lineNumbers
|
|
30
|
+
import { Chat } from "chat";
|
|
31
|
+
import { createChatTools, toAiMessages } from "chat/ai";
|
|
32
|
+
import { ToolLoopAgent } from "ai";
|
|
33
|
+
|
|
34
|
+
const chat = new Chat({ /* adapters, state, ... */ });
|
|
35
|
+
|
|
36
|
+
const agent = new ToolLoopAgent({
|
|
37
|
+
model: "anthropic/claude-sonnet-4.6",
|
|
38
|
+
instructions: "You operate inside a chat workspace via Chat SDK tools.",
|
|
39
|
+
tools: createChatTools({ chat, preset: "messenger", requireApproval: true }),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
bot.onSubscribedMessage(async (thread) => {
|
|
43
|
+
const { messages } = await thread.adapter.fetchMessages(thread.id, {
|
|
44
|
+
limit: 20,
|
|
45
|
+
});
|
|
46
|
+
const history = await toAiMessages(messages);
|
|
47
|
+
const result = await agent.stream({ prompt: history });
|
|
48
|
+
await thread.post(result.fullStream);
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
1. [`toAiMessages`](/docs/ai/to-ai-messages) converts messages into an output compatible with AI SDK's `ModelMessage[]`.
|
|
53
|
+
2. [`createChatTools`](/docs/ai/ai-sdk-tools) gives the agent pre-built and fully customizable AI SDK tools.
|
|
54
|
+
3. The streamed response is rendered back into the thread via the standard [`thread.post(stream)`](/docs/streaming) flow.
|
|
55
|
+
|
|
56
|
+
## Backwards compatibility
|
|
57
|
+
|
|
58
|
+
`toAiMessages` and the related `Ai*` types are still re-exported from the top-level `chat` package so older bots keep working. Those re-exports are now flagged with `@deprecated` JSDoc — your editor will surface a hint pointing at `chat/ai`. Migrating is a one-line import change:
|
|
59
|
+
|
|
60
|
+
```diff
|
|
61
|
+
- import { toAiMessages } from "chat";
|
|
62
|
+
+ import { toAiMessages } from "chat/ai";
|
|
63
|
+
```
|
|
@@ -2,18 +2,31 @@
|
|
|
2
2
|
title: toAiMessages
|
|
3
3
|
description: Convert Chat SDK messages to AI SDK conversation format.
|
|
4
4
|
type: reference
|
|
5
|
+
related:
|
|
6
|
+
- /docs/ai
|
|
7
|
+
- /docs/ai/ai-sdk-tools
|
|
8
|
+
- /docs/ai/types
|
|
9
|
+
- /docs/streaming
|
|
5
10
|
---
|
|
6
11
|
|
|
7
|
-
Convert an array of `Message` objects into the `{ role, content }[]` format expected by AI
|
|
12
|
+
Convert an array of [`Message`](/docs/api/message) objects into the `{ role, content }[]` format expected by the AI SDK. The output is structurally compatible with AI SDK's `ModelMessage[]`.
|
|
8
13
|
|
|
9
14
|
```typescript
|
|
10
|
-
import { toAiMessages } from "chat";
|
|
15
|
+
import { toAiMessages } from "chat/ai";
|
|
11
16
|
```
|
|
12
17
|
|
|
18
|
+
<Callout>
|
|
19
|
+
`toAiMessages` is also re-exported from the main `chat` entrypoint
|
|
20
|
+
for backwards compatibility (with a `@deprecated` JSDoc hint), but
|
|
21
|
+
new code should import it from [`chat/ai`](/docs/ai) alongside
|
|
22
|
+
[`createChatTools`](/docs/ai/ai-sdk-tools) and the rest of the AI
|
|
23
|
+
utilities.
|
|
24
|
+
</Callout>
|
|
25
|
+
|
|
13
26
|
## Usage
|
|
14
27
|
|
|
15
28
|
```typescript title="lib/bot.ts" lineNumbers
|
|
16
|
-
import { toAiMessages } from "chat";
|
|
29
|
+
import { toAiMessages } from "chat/ai";
|
|
17
30
|
|
|
18
31
|
bot.onSubscribedMessage(async (thread, message) => {
|
|
19
32
|
const result = await thread.adapter.fetchMessages(thread.id, { limit: 20 });
|