@assistant-ui/mcp-docs-server 0.1.35 → 0.1.38
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/.docs/organized/code-examples/waterfall.md +1 -1
- package/.docs/organized/code-examples/with-a2a.md +2 -2
- package/.docs/organized/code-examples/with-ag-ui.md +2 -2
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +4 -4
- package/.docs/organized/code-examples/with-artifacts.md +4 -4
- package/.docs/organized/code-examples/with-assistant-transport.md +70 -54
- package/.docs/organized/code-examples/with-browser-extension.md +4 -4
- package/.docs/organized/code-examples/with-chain-of-thought.md +40 -89
- package/.docs/organized/code-examples/with-cloud-standalone.md +4 -4
- package/.docs/organized/code-examples/with-cloud.md +4 -4
- package/.docs/organized/code-examples/with-custom-thread-list.md +4 -4
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +7 -7
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +7 -7
- package/.docs/organized/code-examples/with-eve.md +343 -0
- package/.docs/organized/code-examples/with-expo.md +910 -933
- package/.docs/organized/code-examples/with-external-store.md +2 -2
- package/.docs/organized/code-examples/with-ffmpeg.md +5 -8
- package/.docs/organized/code-examples/with-generative-ui.md +6 -6
- package/.docs/organized/code-examples/with-google-adk.md +3 -3
- package/.docs/organized/code-examples/with-heat-graph.md +1 -1
- package/.docs/organized/code-examples/with-image-generation.md +4 -4
- package/.docs/organized/code-examples/with-interactables.md +166 -338
- package/.docs/organized/code-examples/with-langchain.md +4 -4
- package/.docs/organized/code-examples/with-langgraph.md +20 -157
- package/.docs/organized/code-examples/with-livekit.md +8 -8
- package/.docs/organized/code-examples/with-mcp.md +19 -10
- package/.docs/organized/code-examples/with-opencode.md +3 -3
- package/.docs/organized/code-examples/with-pi.md +9 -7
- package/.docs/organized/code-examples/with-react-hook-form.md +13 -6
- package/.docs/organized/code-examples/with-react-ink-web.md +5 -5
- package/.docs/organized/code-examples/with-react-ink.md +1 -1
- package/.docs/organized/code-examples/with-react-router.md +11 -11
- package/.docs/organized/code-examples/with-resumable-stream.md +5 -5
- package/.docs/organized/code-examples/with-store.md +1 -1
- package/.docs/organized/code-examples/with-tanstack.md +7 -7
- package/.docs/organized/code-examples/with-tap-runtime.md +2 -2
- package/.docs/organized/code-examples/with-virtualized-thread.md +44 -24
- package/.docs/raw/docs/(docs)/cli.mdx +5 -3
- package/.docs/raw/docs/(docs)/devtools.mdx +25 -2
- package/.docs/raw/docs/(docs)/index.mdx +5 -2
- package/.docs/raw/docs/(docs)/installation.mdx +5 -2
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +16 -16
- package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +73 -42
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +3 -20
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +234 -166
- package/.docs/raw/docs/(reference)/api-reference/integrations/eve.mdx +51 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +4 -1
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +70 -38
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +30 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +7 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +26 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/chain-of-thought.mdx +15 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +103 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +16 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +56 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/queue-item.mdx +12 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +12 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +14 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +57 -1
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +6 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/interactables-legacy.mdx +55 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/interactables.mdx +151 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +15 -15
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +20 -20
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +25 -9
- package/.docs/raw/docs/cloud/langgraph.mdx +1 -1
- package/.docs/raw/docs/guides/headless-composer-input.mdx +113 -0
- package/.docs/raw/docs/guides/latex.mdx +28 -22
- package/.docs/raw/docs/guides/mentions.mdx +32 -7
- package/.docs/raw/docs/guides/slash-commands.mdx +3 -6
- package/.docs/raw/docs/guides/speech.mdx +5 -7
- package/.docs/raw/docs/guides/virtualization.mdx +77 -7
- package/.docs/raw/docs/guides/voice.mdx +3 -2
- package/.docs/raw/docs/integrations/attachments/custom-adapter.mdx +4 -12
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +7 -10
- package/.docs/raw/docs/integrations/auth/clerk.mdx +3 -9
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +3 -8
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +11 -8
- package/.docs/raw/docs/integrations/index.mdx +6 -13
- package/.docs/raw/docs/integrations/observability/helicone.mdx +3 -4
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +3 -5
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +5 -4
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +4 -3
- package/.docs/raw/docs/migrations/react-langgraph-v0-7.mdx +2 -2
- package/.docs/raw/docs/primitives/composer.mdx +8 -0
- package/.docs/raw/docs/primitives/thread-list.mdx +30 -6
- package/.docs/raw/docs/primitives/thread.mdx +24 -0
- package/.docs/raw/docs/runtimes/a2a/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/ag-ui/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +24 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +1 -1
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +54 -0
- package/.docs/raw/docs/runtimes/eve/overview.mdx +100 -0
- package/.docs/raw/docs/runtimes/eve/quickstart.mdx +143 -0
- package/.docs/raw/docs/runtimes/google-adk/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/langchain.mdx +388 -20
- package/.docs/raw/docs/runtimes/langgraph/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +1 -1
- package/.docs/raw/docs/runtimes/opencode/hooks.mdx +1 -1
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +6 -0
- package/.docs/raw/docs/tools/defining-tools.mdx +9 -0
- package/.docs/raw/docs/tools/generative-ui.mdx +37 -0
- package/.docs/raw/docs/tools/interactables-legacy.mdx +410 -0
- package/.docs/raw/docs/tools/interactables.mdx +892 -223
- package/.docs/raw/docs/tools/mcp-apps.mdx +12 -3
- package/.docs/raw/docs/tools/mcp.mdx +9 -4
- package/.docs/raw/docs/tools/multi-agent.mdx +5 -0
- package/.docs/raw/docs/tools/user-managed-mcp.mdx +17 -3
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +2 -0
- package/.docs/raw/docs/ui/file.mdx +1 -1
- package/.docs/raw/docs/ui/follow-up-suggestions.mdx +80 -0
- package/.docs/raw/docs/ui/model-selector.mdx +38 -5
- package/.docs/raw/docs/ui/part-grouping.mdx +38 -0
- package/.docs/raw/docs/utilities/react-o11y.mdx +92 -6
- package/README.md +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -2
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.js +0 -4
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/docs.js +18 -6
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.d.ts +3 -1
- package/dist/tools/examples.d.ts.map +1 -1
- package/dist/tools/examples.js +1 -1
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/resources.d.ts +7 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +74 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/search.d.ts +33 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +39 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/tests/test-setup.d.ts.map +1 -1
- package/dist/tools/tests/test-setup.js +3 -1
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/mdx.d.ts +2 -1
- package/dist/utils/mdx.d.ts.map +1 -1
- package/dist/utils/mdx.js +19 -2
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +18 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/search.d.ts +10 -0
- package/dist/utils/search.d.ts.map +1 -0
- package/dist/utils/search.js +97 -0
- package/dist/utils/search.js.map +1 -0
- package/package.json +4 -4
- package/src/constants.ts +2 -0
- package/src/index.ts +28 -6
- package/src/prepare-docs/copy-raw.ts +0 -5
- package/src/tools/docs.ts +30 -4
- package/src/tools/examples.ts +4 -2
- package/src/tools/resources.ts +114 -0
- package/src/tools/search.ts +46 -0
- package/src/tools/tests/completions.test.ts +46 -0
- package/src/tools/tests/directory-size-cap.test.ts +50 -0
- package/src/tools/tests/mcp-protocol.test.ts +21 -1
- package/src/tools/tests/resources.test.ts +102 -0
- package/src/tools/tests/search.test.ts +37 -0
- package/src/tools/tests/test-setup.ts +2 -0
- package/src/utils/mdx.ts +21 -1
- package/src/utils/paths.ts +22 -0
- package/src/utils/search.ts +131 -0
- package/.docs/raw/blog/2024-07-29-hello/index.mdx +0 -64
- package/.docs/raw/blog/2024-09-11/index.mdx +0 -10
- package/.docs/raw/blog/2024-12-15/index.mdx +0 -10
- package/.docs/raw/blog/2025-01-31-changelog/index.mdx +0 -127
- package/.docs/raw/blog/2026-03-launch-week/index.mdx +0 -258
|
@@ -3,7 +3,7 @@ title: ThreadPrimitive
|
|
|
3
3
|
description: Thread primitives for rendering chat transcripts, message lists, viewport state, suggestions, and composers in assistant-ui.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { ThreadPrimitiveIfProps, ThreadPrimitiveMessageByIndexProps, ThreadPrimitiveMessagesProps, ThreadPrimitiveRootProps, ThreadPrimitiveScrollToBottomProps, ThreadPrimitiveSuggestionByIndexProps, ThreadPrimitiveSuggestionProps, ThreadPrimitiveSuggestionsProps, ThreadPrimitiveViewportFooterProps, ThreadPrimitiveViewportProps, ThreadPrimitiveViewportProviderProps } from "@/generated/typeDocs";
|
|
6
|
+
import { ThreadPrimitiveIfProps, ThreadPrimitiveMessageByIndexProps, ThreadPrimitiveMessagesProps, ThreadPrimitiveRootProps, ThreadPrimitiveScrollToBottomProps, ThreadPrimitiveSuggestionByIndexProps, ThreadPrimitiveSuggestionProps, ThreadPrimitiveSuggestionsProps, ThreadPrimitiveUnstable_MessageByIdProps, ThreadPrimitiveViewportFooterProps, ThreadPrimitiveViewportProps, ThreadPrimitiveViewportProviderProps } from "@/generated/typeDocs";
|
|
7
7
|
import { ThreadPrimitive as ThreadPrimitiveDocs } from "@/generated/primitiveDocs";
|
|
8
8
|
|
|
9
9
|
{/* AUTO-GENERATED PAGE by scripts/generate-api-reference.mts */}
|
|
@@ -51,6 +51,16 @@ const Thread = () => (
|
|
|
51
51
|
<p>This primitive renders a <code>{`<${ThreadPrimitiveDocs.Root?.element}>`}</code> element unless <code>asChild</code> is set.</p>
|
|
52
52
|
)}
|
|
53
53
|
|
|
54
|
+
```tsx
|
|
55
|
+
<ThreadPrimitive.Root>
|
|
56
|
+
<ThreadPrimitive.Viewport>
|
|
57
|
+
<ThreadPrimitive.Messages>
|
|
58
|
+
{() => <MyMessage />}
|
|
59
|
+
</ThreadPrimitive.Messages>
|
|
60
|
+
</ThreadPrimitive.Viewport>
|
|
61
|
+
</ThreadPrimitive.Root>
|
|
62
|
+
```
|
|
63
|
+
|
|
54
64
|
<ParametersTable {...ThreadPrimitiveRootProps} />
|
|
55
65
|
|
|
56
66
|
### Empty
|
|
@@ -101,6 +111,14 @@ const Thread = () => (
|
|
|
101
111
|
<p>This primitive renders a <code>{`<${ThreadPrimitiveDocs.Viewport?.element}>`}</code> element unless <code>asChild</code> is set.</p>
|
|
102
112
|
)}
|
|
103
113
|
|
|
114
|
+
```tsx
|
|
115
|
+
<ThreadPrimitive.Viewport turnAnchor="top">
|
|
116
|
+
<ThreadPrimitive.Messages>
|
|
117
|
+
{() => <MyMessage />}
|
|
118
|
+
</ThreadPrimitive.Messages>
|
|
119
|
+
</ThreadPrimitive.Viewport>
|
|
120
|
+
```
|
|
121
|
+
|
|
104
122
|
<ParametersTable {...ThreadPrimitiveViewportProps} />
|
|
105
123
|
|
|
106
124
|
### ViewportProvider
|
|
@@ -133,6 +151,17 @@ const Thread = () => (
|
|
|
133
151
|
<p>This primitive renders a <code>{`<${ThreadPrimitiveDocs.ViewportFooter?.element}>`}</code> element unless <code>asChild</code> is set.</p>
|
|
134
152
|
)}
|
|
135
153
|
|
|
154
|
+
```tsx
|
|
155
|
+
<ThreadPrimitive.Viewport>
|
|
156
|
+
<ThreadPrimitive.Messages>
|
|
157
|
+
{() => <MyMessage />}
|
|
158
|
+
</ThreadPrimitive.Messages>
|
|
159
|
+
<ThreadPrimitive.ViewportFooter className="sticky bottom-0">
|
|
160
|
+
<Composer />
|
|
161
|
+
</ThreadPrimitive.ViewportFooter>
|
|
162
|
+
</ThreadPrimitive.Viewport>
|
|
163
|
+
```
|
|
164
|
+
|
|
136
165
|
<ParametersTable {...ThreadPrimitiveViewportFooterProps} />
|
|
137
166
|
|
|
138
167
|
### Messages
|
|
@@ -167,6 +196,33 @@ const Thread = () => (
|
|
|
167
196
|
|
|
168
197
|
<ParametersTable {...ThreadPrimitiveMessageByIndexProps} />
|
|
169
198
|
|
|
199
|
+
### Unstable_MessageById
|
|
200
|
+
|
|
201
|
+
{ThreadPrimitiveDocs.Unstable_MessageById?.deprecated && (
|
|
202
|
+
<Callout type="tip">
|
|
203
|
+
<strong>Experimental.</strong> {ThreadPrimitiveDocs.Unstable_MessageById.deprecated}
|
|
204
|
+
</Callout>
|
|
205
|
+
)}
|
|
206
|
+
|
|
207
|
+
{ThreadPrimitiveDocs.Unstable_MessageById?.description}
|
|
208
|
+
|
|
209
|
+
{ThreadPrimitiveDocs.Unstable_MessageById?.element && (
|
|
210
|
+
<p>This primitive renders a <code>{`<${ThreadPrimitiveDocs.Unstable_MessageById?.element}>`}</code> element unless <code>asChild</code> is set.</p>
|
|
211
|
+
)}
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
const messageIds = unstable_useThreadMessageIds();
|
|
215
|
+
return messageIds.map((messageId) => (
|
|
216
|
+
<ThreadPrimitive.Unstable_MessageById
|
|
217
|
+
key={messageId}
|
|
218
|
+
messageId={messageId}
|
|
219
|
+
components={MESSAGE_COMPONENTS}
|
|
220
|
+
/>
|
|
221
|
+
));
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
<ParametersTable {...ThreadPrimitiveUnstable_MessageByIdProps} />
|
|
225
|
+
|
|
170
226
|
### ScrollToBottom
|
|
171
227
|
|
|
172
228
|
{ThreadPrimitiveDocs.ScrollToBottom?.deprecated && (
|
|
@@ -36,4 +36,10 @@ Toolkits are the current registration API. Tool **rendering** and **status** are
|
|
|
36
36
|
<Card title={"Tool Status"} href={"/docs/api-reference/tools/status"}>
|
|
37
37
|
{"Read tool arguments, execution status, and result state inside assistant-ui tool UI components."}
|
|
38
38
|
</Card>
|
|
39
|
+
<Card title={"Interactables"} href={"/docs/api-reference/tools/interactables"}>
|
|
40
|
+
{"Unstable interactables APIs for model-editable app and message state, including hooks, resources, toolkit helpers, and snapshot utilities."}
|
|
41
|
+
</Card>
|
|
42
|
+
<Card title={"Interactables (legacy)"} href={"/docs/api-reference/tools/interactables-legacy"}>
|
|
43
|
+
{"Deprecated legacy interactables APIs for registering model-editable components with per-instance update tools."}
|
|
44
|
+
</Card>
|
|
39
45
|
</Cards>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Interactables (legacy)
|
|
3
|
+
description: Deprecated legacy interactables APIs for registering model-editable components with per-instance update tools.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Interactables, useAssistantInteractable, useInteractableState } from "@/generated/typeDocs";
|
|
7
|
+
|
|
8
|
+
{/* AUTO-GENERATED PAGE by scripts/generate-api-reference.mts */}
|
|
9
|
+
{/* Do not edit manually. */}
|
|
10
|
+
|
|
11
|
+
{/* api-reference:start */}
|
|
12
|
+
{/* AUTO-GENERATED by scripts/generate-api-reference.mts */}
|
|
13
|
+
{/* Do not edit this block manually. */}
|
|
14
|
+
|
|
15
|
+
## API Reference
|
|
16
|
+
|
|
17
|
+
### Interactables
|
|
18
|
+
|
|
19
|
+
<Callout type="warn">
|
|
20
|
+
<strong>Deprecated.</strong> Since 2026-06-14 — migrate to the Unstable / Experimental API.
|
|
21
|
+
Scheduled for removal on/after 2026-09-14. See
|
|
22
|
+
[Interactables migration guide](https://www.assistant-ui.com/docs/tools/interactables#migrating-from-the-previous-api).
|
|
23
|
+
</Callout>
|
|
24
|
+
|
|
25
|
+
<ParametersTable {...Interactables} />
|
|
26
|
+
|
|
27
|
+
### useAssistantInteractable
|
|
28
|
+
|
|
29
|
+
<Callout type="warn">
|
|
30
|
+
<strong>Deprecated.</strong> Since 2026-06-14 — migrate to the Unstable / Experimental API.
|
|
31
|
+
Scheduled for removal on/after 2026-09-14. See
|
|
32
|
+
[Interactables migration guide](https://www.assistant-ui.com/docs/tools/interactables#migrating-from-the-previous-api).
|
|
33
|
+
</Callout>
|
|
34
|
+
|
|
35
|
+
Registers an interactable with the AI assistant.
|
|
36
|
+
|
|
37
|
+
This hook handles registration only. To read and write the interactable's
|
|
38
|
+
state, use [useInteractableState](/docs/api-reference/tools/interactables-legacy#useinteractablestate) with the returned id.
|
|
39
|
+
|
|
40
|
+
<ParametersTable {...useAssistantInteractable} />
|
|
41
|
+
|
|
42
|
+
### useInteractableState
|
|
43
|
+
|
|
44
|
+
<Callout type="warn">
|
|
45
|
+
<strong>Deprecated.</strong> Since 2026-06-14 — migrate to the Unstable / Experimental API.
|
|
46
|
+
Scheduled for removal on/after 2026-09-14. See
|
|
47
|
+
[Interactables migration guide](https://www.assistant-ui.com/docs/tools/interactables#migrating-from-the-previous-api).
|
|
48
|
+
</Callout>
|
|
49
|
+
|
|
50
|
+
Reads and writes the state of a registered interactable.
|
|
51
|
+
|
|
52
|
+
Pair with [useAssistantInteractable](/docs/api-reference/tools/interactables-legacy#useassistantinteractable) which handles registration.
|
|
53
|
+
|
|
54
|
+
<ParametersTable {...useInteractableState} />
|
|
55
|
+
{/* api-reference:end */}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Interactables
|
|
3
|
+
description: Unstable interactables APIs for model-editable app and message state, including hooks, resources, toolkit helpers, and snapshot utilities.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions, unstable_useInteractable, unstable_useInteractableState, unstable_useInteractableVersions } from "@/generated/typeDocs";
|
|
7
|
+
|
|
8
|
+
{/* AUTO-GENERATED PAGE by scripts/generate-api-reference.mts */}
|
|
9
|
+
{/* Do not edit manually. */}
|
|
10
|
+
|
|
11
|
+
{/* api-reference:start */}
|
|
12
|
+
{/* AUTO-GENERATED by scripts/generate-api-reference.mts */}
|
|
13
|
+
{/* Do not edit this block manually. */}
|
|
14
|
+
|
|
15
|
+
## API Reference
|
|
16
|
+
|
|
17
|
+
### unstable_Interactables
|
|
18
|
+
|
|
19
|
+
<Callout type="tip">
|
|
20
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
21
|
+
</Callout>
|
|
22
|
+
|
|
23
|
+
Registers the unstable interactables store scope.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const unstable_Interactables: Resource<ClientOutput<"unstable_interactables">, [(Unstable_InteractablesConfig | undefined)?]>;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### unstable_useInteractable
|
|
30
|
+
|
|
31
|
+
<Callout type="tip">
|
|
32
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
33
|
+
</Callout>
|
|
34
|
+
|
|
35
|
+
Registers an interactable with the AI assistant and returns its live state,
|
|
36
|
+
like `useState` that the model can also read and update.
|
|
37
|
+
|
|
38
|
+
Call this once per place that shows the interactable. Other components can
|
|
39
|
+
read and write the same instance by passing its `id` to
|
|
40
|
+
`unstable_useInteractableState`.
|
|
41
|
+
|
|
42
|
+
For tool-created interactables rendered inside tool-call message parts,
|
|
43
|
+
`version` carries this message's version of the instance — its state as of
|
|
44
|
+
that point in the conversation, whether it is the most recent tool-driven
|
|
45
|
+
version, and a `restore()` back to it. Whether older messages render frozen history or stay
|
|
46
|
+
live-editable is the component's choice. Inside an `update_{name}` part the
|
|
47
|
+
instance `id` is inferred from the call, so the same component works at the
|
|
48
|
+
creating call and at update calls.
|
|
49
|
+
|
|
50
|
+
<ParametersTable {...unstable_useInteractable} />
|
|
51
|
+
|
|
52
|
+
### unstable_useInteractableState
|
|
53
|
+
|
|
54
|
+
<Callout type="tip">
|
|
55
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
56
|
+
</Callout>
|
|
57
|
+
|
|
58
|
+
Reads and writes the state of an interactable registered elsewhere, by id.
|
|
59
|
+
|
|
60
|
+
Use this from secondary readers (children, siblings); the owning component
|
|
61
|
+
registers with `unstable_useInteractable`, which returns state directly. Returns
|
|
62
|
+
`undefined` until the owning interactable is registered.
|
|
63
|
+
|
|
64
|
+
<ParametersTable {...unstable_useInteractableState} />
|
|
65
|
+
|
|
66
|
+
### unstable_useInteractableVersions
|
|
67
|
+
|
|
68
|
+
<Callout type="tip">
|
|
69
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
70
|
+
</Callout>
|
|
71
|
+
|
|
72
|
+
Every version of a tool-created interactable recorded in the current
|
|
73
|
+
thread, oldest first: the creating tool call, each user edit, and each
|
|
74
|
+
`update_*` call. Each entry carries the full state as of that version and a
|
|
75
|
+
`restore()` that sets the live instance back to it — enough for a version
|
|
76
|
+
picker like an artifact's history dropdown.
|
|
77
|
+
|
|
78
|
+
<ParametersTable {...unstable_useInteractableVersions} />
|
|
79
|
+
|
|
80
|
+
### unstable_interactableTool
|
|
81
|
+
|
|
82
|
+
<Callout type="tip">
|
|
83
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
84
|
+
</Callout>
|
|
85
|
+
|
|
86
|
+
Defines a tool that creates a thread-scoped interactable from its arguments,
|
|
87
|
+
for assignment to a toolkit entry — the entry key is the interactable name:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
notepad: unstable_interactableTool({
|
|
91
|
+
description: "A notepad the user can read and edit.",
|
|
92
|
+
stateSchema: notepadSchema,
|
|
93
|
+
render: (props) => <Notepad {...props} />,
|
|
94
|
+
}),
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`render` shows at the creating call and — installed automatically — at every
|
|
98
|
+
`update_{name}` call, with streaming previews, instance-id wiring, and
|
|
99
|
+
registration handled. It receives the live `state`/`setState` plus this
|
|
100
|
+
message's `version`; whether older messages render frozen history or stay
|
|
101
|
+
live-editable is the render function's choice.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const unstable_interactableTool: <TSchema extends Unstable_InteractableStateSchema>(config: Unstable_InteractableToolConfig<TSchema>) => ToolDefinition<Record<string, unknown>, { success: true; }>;
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### unstable_getInteractableSnapshots
|
|
108
|
+
|
|
109
|
+
<Callout type="tip">
|
|
110
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
111
|
+
</Callout>
|
|
112
|
+
|
|
113
|
+
Reads the interactable snapshots stamped on a message's
|
|
114
|
+
`metadata.custom.interactables`, or `undefined` if none. This is the read
|
|
115
|
+
half of the snapshot channel — integrations use it to surface interactable
|
|
116
|
+
state to the model (see `unstable_injectInteractableContext` in
|
|
117
|
+
`@assistant-ui/react-ai-sdk` for the AI SDK implementation).
|
|
118
|
+
|
|
119
|
+
<ParametersTable {...unstable_getInteractableSnapshots} />
|
|
120
|
+
|
|
121
|
+
### unstable_formatInteractableSnapshot
|
|
122
|
+
|
|
123
|
+
<Callout type="tip">
|
|
124
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
125
|
+
</Callout>
|
|
126
|
+
|
|
127
|
+
Canonical model-facing wording for one snapshot entry.
|
|
128
|
+
|
|
129
|
+
<ParametersTable {...unstable_formatInteractableSnapshot} />
|
|
130
|
+
|
|
131
|
+
### unstable_getInteractableVersions
|
|
132
|
+
|
|
133
|
+
<Callout type="tip">
|
|
134
|
+
<strong>Experimental.</strong> Unstable / Experimental (not actually removed).
|
|
135
|
+
</Callout>
|
|
136
|
+
|
|
137
|
+
Every version of interactable `id` recorded in the thread, oldest first,
|
|
138
|
+
folded chronologically:
|
|
139
|
+
|
|
140
|
+
- the tool call whose `toolCallId` equals `id` seeds the baseline with its
|
|
141
|
+
args (`origin: "create"`) — the `id: toolCallId` convention for
|
|
142
|
+
tool-created interactables,
|
|
143
|
+
- a snapshot stamped on a user message is a `"user-edit"` version (a full
|
|
144
|
+
snapshot replaces the state; a partial one shallow-merges),
|
|
145
|
+
- each accepted `update_*` call shallow-merges an `"update"` version.
|
|
146
|
+
|
|
147
|
+
The last entry is the state the model knows. Partial snapshots and update
|
|
148
|
+
calls with no baseline to merge into are skipped.
|
|
149
|
+
|
|
150
|
+
<ParametersTable {...unstable_getInteractableVersions} />
|
|
151
|
+
{/* api-reference:end */}
|
|
@@ -44,6 +44,21 @@ type AssistantDataUIProps = {
|
|
|
44
44
|
const makeAssistantDataUI: <T = any>(dataUI: AssistantDataUIProps<T>) => AssistantDataUI;
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
### McpAppRenderer
|
|
48
|
+
|
|
49
|
+
<ParametersTable {...McpAppRenderer} />
|
|
50
|
+
|
|
51
|
+
### McpAppsRemoteHost
|
|
52
|
+
|
|
53
|
+
<ParametersTable {...McpAppsRemoteHost} />
|
|
54
|
+
|
|
55
|
+
### useAssistantDataUI
|
|
56
|
+
|
|
57
|
+
Registers a renderer for named `data` message parts while the component is
|
|
58
|
+
mounted.
|
|
59
|
+
|
|
60
|
+
<ParametersTable {...useAssistantDataUI} />
|
|
61
|
+
|
|
47
62
|
### makeAssistantToolUI
|
|
48
63
|
|
|
49
64
|
<Callout type="warn">
|
|
@@ -74,21 +89,6 @@ type AssistantToolUIProps = {
|
|
|
74
89
|
const makeAssistantToolUI: <TArgs, TResult>(tool: AssistantToolUIProps<TArgs, TResult>) => AssistantToolUI;
|
|
75
90
|
```
|
|
76
91
|
|
|
77
|
-
### McpAppRenderer
|
|
78
|
-
|
|
79
|
-
<ParametersTable {...McpAppRenderer} />
|
|
80
|
-
|
|
81
|
-
### McpAppsRemoteHost
|
|
82
|
-
|
|
83
|
-
<ParametersTable {...McpAppsRemoteHost} />
|
|
84
|
-
|
|
85
|
-
### useAssistantDataUI
|
|
86
|
-
|
|
87
|
-
Registers a renderer for named `data` message parts while the component is
|
|
88
|
-
mounted.
|
|
89
|
-
|
|
90
|
-
<ParametersTable {...useAssistantDataUI} />
|
|
91
|
-
|
|
92
92
|
### useAssistantToolUI
|
|
93
93
|
|
|
94
94
|
<Callout type="warn">
|
|
@@ -115,26 +115,6 @@ client build.
|
|
|
115
115
|
function externalTool(): never;
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
### hitl
|
|
119
|
-
|
|
120
|
-
<Callout type="warn">
|
|
121
|
-
<strong>Deprecated.</strong> Use [humanTool](/docs/api-reference/tools/toolkits#humantool).
|
|
122
|
-
</Callout>
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
const hitl: typeof humanTool;
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### hitlTool
|
|
129
|
-
|
|
130
|
-
<Callout type="warn">
|
|
131
|
-
<strong>Deprecated.</strong> Use [humanTool](/docs/api-reference/tools/toolkits#humantool).
|
|
132
|
-
</Callout>
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
const hitlTool: typeof humanTool;
|
|
136
|
-
```
|
|
137
|
-
|
|
138
118
|
### humanTool
|
|
139
119
|
|
|
140
120
|
Marks a tool as **human-in-the-loop**: the agent pauses and the UI (`render`)
|
|
@@ -172,4 +152,24 @@ supplied by `useAuiToolOverrides(...)`.
|
|
|
172
152
|
```ts
|
|
173
153
|
function stubTool(): never;
|
|
174
154
|
```
|
|
155
|
+
|
|
156
|
+
### hitl
|
|
157
|
+
|
|
158
|
+
<Callout type="warn">
|
|
159
|
+
<strong>Deprecated.</strong> Use [humanTool](/docs/api-reference/tools/toolkits#humantool).
|
|
160
|
+
</Callout>
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const hitl: typeof humanTool;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### hitlTool
|
|
167
|
+
|
|
168
|
+
<Callout type="warn">
|
|
169
|
+
<strong>Deprecated.</strong> Use [humanTool](/docs/api-reference/tools/toolkits#humantool).
|
|
170
|
+
</Callout>
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
const hitlTool: typeof humanTool;
|
|
174
|
+
```
|
|
175
175
|
{/* api-reference:end */}
|
|
@@ -3,7 +3,7 @@ title: Utilities
|
|
|
3
3
|
description: Miscellaneous @assistant-ui/react utilities for custom rendering, composition, and advanced assistant UI behavior.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { AssistantCloud, ChainOfThoughtClient, DevToolsHooks, InMemoryThreadList,
|
|
6
|
+
import { AssistantCloud, ChainOfThoughtClient, DevToolsHooks, InMemoryThreadList, SingleThreadList, Suggestions, useSmooth } from "@/generated/typeDocs";
|
|
7
7
|
|
|
8
8
|
{/* AUTO-GENERATED PAGE by scripts/generate-api-reference.mts */}
|
|
9
9
|
{/* Do not edit manually. */}
|
|
@@ -36,10 +36,6 @@ const createMessageQueue: (driver: MessageQueueDriver) => MessageQueueController
|
|
|
36
36
|
|
|
37
37
|
<ParametersTable {...InMemoryThreadList} />
|
|
38
38
|
|
|
39
|
-
### Interactables
|
|
40
|
-
|
|
41
|
-
<ParametersTable {...Interactables} />
|
|
42
|
-
|
|
43
39
|
### SingleThreadList
|
|
44
40
|
|
|
45
41
|
<ParametersTable {...SingleThreadList} />
|
|
@@ -48,6 +44,16 @@ const createMessageQueue: (driver: MessageQueueDriver) => MessageQueueController
|
|
|
48
44
|
|
|
49
45
|
<ParametersTable {...Suggestions} />
|
|
50
46
|
|
|
47
|
+
### unstable_defaultDirectiveFormatter
|
|
48
|
+
|
|
49
|
+
Default directive formatter using the `:type[label]{name=id}` syntax.
|
|
50
|
+
|
|
51
|
+
When `id` equals `label`, the `{name=…}` attribute is omitted for brevity.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const unstable_defaultDirectiveFormatter: Unstable_DirectiveFormatter;
|
|
55
|
+
```
|
|
56
|
+
|
|
51
57
|
### useSmooth
|
|
52
58
|
|
|
53
59
|
Animates streamed message part text with a typewriter-style reveal.
|
|
@@ -66,13 +72,23 @@ const { text, status } = useSmooth(useMessagePartText(), {
|
|
|
66
72
|
|
|
67
73
|
<ParametersTable {...useSmooth} />
|
|
68
74
|
|
|
69
|
-
###
|
|
75
|
+
### fromThreadMessageLike
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
<Callout type="tip">
|
|
78
|
+
<strong>Experimental.</strong> This API is experimental and may change without notice.
|
|
79
|
+
</Callout>
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
```ts
|
|
82
|
+
const fromThreadMessageLike: (like: ThreadMessageLike, fallbackId: string, fallbackStatus: MessageStatus) => ThreadMessage;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### generateId
|
|
86
|
+
|
|
87
|
+
<Callout type="tip">
|
|
88
|
+
<strong>Experimental.</strong> This API is experimental and may change without notice.
|
|
89
|
+
</Callout>
|
|
74
90
|
|
|
75
91
|
```ts
|
|
76
|
-
const
|
|
92
|
+
const generateId: (size?: number) => string;
|
|
77
93
|
```
|
|
78
94
|
{/* api-reference:end */}
|
|
@@ -547,6 +547,6 @@ For other authentication providers or custom implementations, see the [Cloud Aut
|
|
|
547
547
|
|
|
548
548
|
## Next Steps
|
|
549
549
|
|
|
550
|
-
- Learn about [LangGraph runtime setup](/docs/runtimes/langgraph) for your application
|
|
550
|
+
- Learn about [LangGraph runtime setup](/docs/runtimes/langgraph/overview) for your application
|
|
551
551
|
- Explore [ThreadListRuntime](/docs/api-reference/runtimes/thread-list-runtime) for advanced thread management
|
|
552
552
|
- Check out the [LangGraph example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-langgraph) on GitHub
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Headless Composer Input
|
|
3
|
+
description: Build a custom composer input while keeping assistant-ui composer state and send gating.
|
|
4
|
+
platforms: ["react"]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`ComposerPrimitive.Input` is still the recommended composer input for most apps. It owns autosize, keyboard shortcuts, IME handling, paste-to-attachment, focus behavior, and trigger-popover keyboard integration.
|
|
8
|
+
|
|
9
|
+
Use `unstable_useComposerInput` when you already own the input surface, such as a custom editor, a `contentEditable` surface, or a textarea wrapper whose behavior cannot be expressed through `ComposerPrimitive.Input`'s props, `asChild`, or `render` APIs.
|
|
10
|
+
|
|
11
|
+
<Callout type="warn">
|
|
12
|
+
This API is marked unstable and may change without notice. It is a thin bridge
|
|
13
|
+
to composer text and send state, not a replacement implementation of
|
|
14
|
+
`ComposerPrimitive.Input`.
|
|
15
|
+
</Callout>
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Render the custom input inside a composer and mirror text changes into the assistant-ui composer state:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
"use client";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
ComposerPrimitive,
|
|
26
|
+
unstable_useComposerInput,
|
|
27
|
+
unstable_useTriggerPopoverAriaProps,
|
|
28
|
+
} from "@assistant-ui/react";
|
|
29
|
+
|
|
30
|
+
function HeadlessComposer() {
|
|
31
|
+
const composer = unstable_useComposerInput();
|
|
32
|
+
const popoverAria = unstable_useTriggerPopoverAriaProps();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ComposerPrimitive.Root>
|
|
36
|
+
<textarea
|
|
37
|
+
aria-label="Message"
|
|
38
|
+
value={composer.value}
|
|
39
|
+
disabled={composer.isDisabled}
|
|
40
|
+
onChange={(event) => {
|
|
41
|
+
composer.setText(event.currentTarget.value);
|
|
42
|
+
}}
|
|
43
|
+
onKeyDown={(event) => {
|
|
44
|
+
if (event.nativeEvent.isComposing) return;
|
|
45
|
+
|
|
46
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
|
|
49
|
+
if (composer.canSend) {
|
|
50
|
+
composer.send();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}}
|
|
54
|
+
{...popoverAria}
|
|
55
|
+
/>
|
|
56
|
+
<ComposerPrimitive.Send />
|
|
57
|
+
</ComposerPrimitive.Root>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`composer.send()` exposes the same send action used by `ComposerPrimitive.Send`, including send options such as `composer.send({ steer: true })`. It is a no-op unless `composer.canSend` is `true`; check `canSend` in custom keyboard handlers to keep your event handling explicit.
|
|
63
|
+
|
|
64
|
+
## Hook Result
|
|
65
|
+
|
|
66
|
+
| Field | Description |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `value` | Current composer text. Returns `""` when the composer is not editing. |
|
|
69
|
+
| `setText(text)` | Writes text into the composer while it is editing. |
|
|
70
|
+
| `send(options?)` | Sends the current composer message when `canSend` is `true`; otherwise a no-op. |
|
|
71
|
+
| `isDisabled` | Combines the hook's `disabled` option with assistant-ui disabled sources, such as thread disabled state and active dictation input lock. |
|
|
72
|
+
| `canSend` | Matches `ComposerPrimitive.Send` gating, then also respects `isDisabled`. |
|
|
73
|
+
|
|
74
|
+
Pass `disabled` when your editor has an additional read-only state:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const composer = unstable_useComposerInput({
|
|
78
|
+
disabled: editorReadOnly,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## What You Still Own
|
|
83
|
+
|
|
84
|
+
The hook does not recreate the behavior of `ComposerPrimitive.Input`. Your input or editor remains responsible for:
|
|
85
|
+
|
|
86
|
+
- Enter/newline shortcuts, steer shortcuts, escape/cancel behavior, and any other keyboard behavior.
|
|
87
|
+
- IME and composition handling.
|
|
88
|
+
- Cursor and selection tracking.
|
|
89
|
+
- Autosize and focus management.
|
|
90
|
+
- Paste/drop attachment behavior.
|
|
91
|
+
- Rich text state, serialization, and DOM synchronization for `contentEditable` or editor-library integrations.
|
|
92
|
+
|
|
93
|
+
For styled textareas, prefer `ComposerPrimitive.Input`. Reach for the headless hook when the editor has its own model or DOM lifecycle and assistant-ui should only supply composer state and send gating.
|
|
94
|
+
|
|
95
|
+
## Trigger Popovers
|
|
96
|
+
|
|
97
|
+
`unstable_useTriggerPopoverAriaProps` returns the combobox ARIA attributes for the currently open trigger popover:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
const popoverAria = unstable_useTriggerPopoverAriaProps();
|
|
101
|
+
|
|
102
|
+
<textarea {...popoverAria} />;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Spread these props last so they can mirror `ComposerPrimitive.Input` when a popover is open.
|
|
106
|
+
|
|
107
|
+
This helper only describes the open popover to assistive technology. It does not wire a custom editor into mention or slash-command keyboard handling, cursor tracking, or item insertion. For the full built-in trigger-popover experience, use `ComposerPrimitive.Input`; for richer editors, integrate the trigger UI with the editor's own selection and keyboard model.
|
|
108
|
+
|
|
109
|
+
## Related
|
|
110
|
+
|
|
111
|
+
- [Composer primitives](/docs/primitives/composer)
|
|
112
|
+
- [Composer Trigger Popover](/docs/ui/composer-trigger-popover)
|
|
113
|
+
- [Input History](/docs/guides/input-history)
|
|
@@ -106,47 +106,53 @@ By default, remark-math (react-markdown path) supports:
|
|
|
106
106
|
|
|
107
107
|
## Supporting Alternative LaTeX Delimiters
|
|
108
108
|
|
|
109
|
-
Many language models
|
|
110
|
-
- `\(...\)` for inline math
|
|
111
|
-
-
|
|
112
|
-
- Custom formats like `[/math]...[/math]`
|
|
109
|
+
Many language models emit math in delimiters that remark-math does not recognize:
|
|
110
|
+
- `\(...\)` for inline math and `\[...\]` for display math
|
|
111
|
+
- custom tags like `[/math]...[/math]` and `[/inline]...[/inline]`
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
`@assistant-ui/react-markdown` exports `normalizeMathDelimiters`, which rewrites these to the `$...$` and `$$...$$` form remark-math parses. Pass it to the `preprocess` prop of `MarkdownTextPrimitive`:
|
|
115
114
|
|
|
116
115
|
```tsx title="/components/assistant-ui/markdown-text.tsx"
|
|
117
|
-
import {
|
|
116
|
+
import {
|
|
117
|
+
MarkdownTextPrimitive,
|
|
118
|
+
normalizeMathDelimiters, // [!code ++]
|
|
119
|
+
} from "@assistant-ui/react-markdown";
|
|
118
120
|
|
|
119
121
|
const MarkdownTextImpl = () => {
|
|
120
122
|
return (
|
|
121
123
|
<MarkdownTextPrimitive
|
|
122
124
|
remarkPlugins={[remarkGfm, remarkMath]}
|
|
123
125
|
rehypePlugins={[rehypeKatex]}
|
|
124
|
-
preprocess={
|
|
126
|
+
preprocess={normalizeMathDelimiters} // [!code ++]
|
|
125
127
|
className="aui-md"
|
|
126
128
|
components={defaultComponents}
|
|
127
129
|
/>
|
|
128
130
|
);
|
|
129
131
|
};
|
|
132
|
+
```
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.replace(/\[\/math\]([\s\S]*?)\[\/math\]/g, (_, content) => `$$${content.trim()}$$`)
|
|
134
|
+
The individual transforms `rewriteLatexBracketDelimiters` and `rewriteCustomMathTags` are exported too, for finer control over which delimiters are normalized.
|
|
135
|
+
|
|
136
|
+
<Callout type="info">
|
|
137
|
+
Using [Streamdown](/docs/ui/streamdown) as your renderer? The same helpers are exported from `@assistant-ui/react-streamdown` and accepted by the `preprocess` prop of `StreamdownTextPrimitive`.
|
|
138
|
+
</Callout>
|
|
137
139
|
|
|
138
|
-
|
|
139
|
-
.replace(/\[\/inline\]([\s\S]*?)\[\/inline\]/g, (_, content) => `$${content.trim()}$`)
|
|
140
|
+
### Currency amounts
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
.replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$${content.trim()}$`)
|
|
142
|
+
With single-dollar inline math enabled (the default on the react-markdown path), remark-math reads a lone `$` as a math delimiter, so prose such as `$5 ... $10` is parsed as math. `escapeCurrencyDollars` escapes a `$` immediately followed by a digit so currency survives, while leaving the `$$` of display math intact. Compose it with the delimiter normalization:
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
```tsx title="/components/assistant-ui/markdown-text.tsx"
|
|
145
|
+
import {
|
|
146
|
+
normalizeMathDelimiters,
|
|
147
|
+
escapeCurrencyDollars, // [!code ++]
|
|
148
|
+
} from "@assistant-ui/react-markdown";
|
|
149
|
+
|
|
150
|
+
<MarkdownTextPrimitive
|
|
151
|
+
preprocess={(text) => escapeCurrencyDollars(normalizeMathDelimiters(text))} // [!code ++]
|
|
152
|
+
// ...
|
|
153
|
+
/>;
|
|
148
154
|
```
|
|
149
155
|
|
|
150
156
|
<Callout type="tip">
|
|
151
|
-
Inside `MarkdownTextPrimitive`, the streamed text first passes through `preprocess` (delimiter normalization) and then through `useSmooth` (character
|
|
157
|
+
Inside `MarkdownTextPrimitive`, the streamed text first passes through `preprocess` (delimiter normalization) and then through `useSmooth` (character by character accumulation), and only then reaches the markdown parser. Both run before remark-math sees the text, so delimiter replacement and the streaming smoothing stay streaming safe; a partially received delimiter is accumulated in the smoothing buffer rather than parsed mid fragment.
|
|
152
158
|
</Callout>
|