ai 6.0.31 → 6.0.33
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/CHANGELOG.md +12 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/00-introduction/index.mdx +76 -0
- package/docs/02-foundations/01-overview.mdx +43 -0
- package/docs/02-foundations/02-providers-and-models.mdx +163 -0
- package/docs/02-foundations/03-prompts.mdx +620 -0
- package/docs/02-foundations/04-tools.mdx +160 -0
- package/docs/02-foundations/05-streaming.mdx +62 -0
- package/docs/02-foundations/index.mdx +43 -0
- package/docs/02-getting-started/00-choosing-a-provider.mdx +110 -0
- package/docs/02-getting-started/01-navigating-the-library.mdx +85 -0
- package/docs/02-getting-started/02-nextjs-app-router.mdx +556 -0
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +542 -0
- package/docs/02-getting-started/04-svelte.mdx +627 -0
- package/docs/02-getting-started/05-nuxt.mdx +566 -0
- package/docs/02-getting-started/06-nodejs.mdx +512 -0
- package/docs/02-getting-started/07-expo.mdx +766 -0
- package/docs/02-getting-started/08-tanstack-start.mdx +583 -0
- package/docs/02-getting-started/index.mdx +44 -0
- package/docs/03-agents/01-overview.mdx +96 -0
- package/docs/03-agents/02-building-agents.mdx +367 -0
- package/docs/03-agents/03-workflows.mdx +370 -0
- package/docs/03-agents/04-loop-control.mdx +350 -0
- package/docs/03-agents/05-configuring-call-options.mdx +286 -0
- package/docs/03-agents/index.mdx +40 -0
- package/docs/03-ai-sdk-core/01-overview.mdx +33 -0
- package/docs/03-ai-sdk-core/05-generating-text.mdx +600 -0
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +662 -0
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1102 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +375 -0
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +144 -0
- package/docs/03-ai-sdk-core/25-settings.mdx +198 -0
- package/docs/03-ai-sdk-core/30-embeddings.mdx +247 -0
- package/docs/03-ai-sdk-core/31-reranking.mdx +218 -0
- package/docs/03-ai-sdk-core/35-image-generation.mdx +341 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +173 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +167 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +480 -0
- package/docs/03-ai-sdk-core/45-provider-management.mdx +349 -0
- package/docs/03-ai-sdk-core/50-error-handling.mdx +149 -0
- package/docs/03-ai-sdk-core/55-testing.mdx +218 -0
- package/docs/03-ai-sdk-core/60-telemetry.mdx +313 -0
- package/docs/03-ai-sdk-core/65-devtools.mdx +107 -0
- package/docs/03-ai-sdk-core/index.mdx +88 -0
- package/docs/04-ai-sdk-ui/01-overview.mdx +44 -0
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +1313 -0
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +535 -0
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +263 -0
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +682 -0
- package/docs/04-ai-sdk-ui/04-generative-user-interfaces.mdx +389 -0
- package/docs/04-ai-sdk-ui/05-completion.mdx +186 -0
- package/docs/04-ai-sdk-ui/08-object-generation.mdx +344 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +397 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +190 -0
- package/docs/04-ai-sdk-ui/21-transport.mdx +174 -0
- package/docs/04-ai-sdk-ui/24-reading-ui-message-streams.mdx +104 -0
- package/docs/04-ai-sdk-ui/25-message-metadata.mdx +152 -0
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +477 -0
- package/docs/04-ai-sdk-ui/index.mdx +64 -0
- package/docs/05-ai-sdk-rsc/01-overview.mdx +45 -0
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +209 -0
- package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +279 -0
- package/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx +105 -0
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +282 -0
- package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +158 -0
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +273 -0
- package/docs/05-ai-sdk-rsc/08-error-handling.mdx +96 -0
- package/docs/05-ai-sdk-rsc/09-authentication.mdx +42 -0
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +722 -0
- package/docs/05-ai-sdk-rsc/index.mdx +58 -0
- package/docs/06-advanced/01-prompt-engineering.mdx +96 -0
- package/docs/06-advanced/02-stopping-streams.mdx +184 -0
- package/docs/06-advanced/03-backpressure.mdx +173 -0
- package/docs/06-advanced/04-caching.mdx +169 -0
- package/docs/06-advanced/05-multiple-streamables.mdx +68 -0
- package/docs/06-advanced/06-rate-limiting.mdx +60 -0
- package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +213 -0
- package/docs/06-advanced/08-model-as-router.mdx +120 -0
- package/docs/06-advanced/09-multistep-interfaces.mdx +115 -0
- package/docs/06-advanced/09-sequential-generations.mdx +55 -0
- package/docs/06-advanced/10-vercel-deployment-guide.mdx +117 -0
- package/docs/06-advanced/index.mdx +11 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2142 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3215 -0
- package/docs/07-reference/01-ai-sdk-core/03-generate-object.mdx +780 -0
- package/docs/07-reference/01-ai-sdk-core/04-stream-object.mdx +1140 -0
- package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +190 -0
- package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +171 -0
- package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +309 -0
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +227 -0
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +138 -0
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +214 -0
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +203 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +449 -0
- package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +148 -0
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +168 -0
- package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +144 -0
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +196 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +175 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +410 -0
- package/docs/07-reference/01-ai-sdk-core/24-mcp-stdio-transport.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/25-json-schema.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/26-zod-schema.mdx +109 -0
- package/docs/07-reference/01-ai-sdk-core/27-valibot-schema.mdx +55 -0
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +342 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +415 -0
- package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +246 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +101 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +113 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +182 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +121 -0
- package/docs/07-reference/01-ai-sdk-core/50-cosine-similarity.mdx +52 -0
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +59 -0
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +64 -0
- package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +46 -0
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/67-simulate-streaming-middleware.mdx +71 -0
- package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +80 -0
- package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +155 -0
- package/docs/07-reference/01-ai-sdk-core/70-extract-json-middleware.mdx +147 -0
- package/docs/07-reference/01-ai-sdk-core/70-step-count-is.mdx +84 -0
- package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +120 -0
- package/docs/07-reference/01-ai-sdk-core/75-simulate-readable-stream.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +145 -0
- package/docs/07-reference/01-ai-sdk-core/90-generate-id.mdx +43 -0
- package/docs/07-reference/01-ai-sdk-core/91-create-id-generator.mdx +89 -0
- package/docs/07-reference/01-ai-sdk-core/index.mdx +159 -0
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +446 -0
- package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +179 -0
- package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +178 -0
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +230 -0
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +108 -0
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +151 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +113 -0
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +73 -0
- package/docs/07-reference/02-ai-sdk-ui/43-read-ui-message-stream.mdx +57 -0
- package/docs/07-reference/02-ai-sdk-ui/46-infer-ui-tools.mdx +99 -0
- package/docs/07-reference/02-ai-sdk-ui/47-infer-ui-tool.mdx +75 -0
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +333 -0
- package/docs/07-reference/02-ai-sdk-ui/index.mdx +89 -0
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +767 -0
- package/docs/07-reference/03-ai-sdk-rsc/02-create-ai.mdx +90 -0
- package/docs/07-reference/03-ai-sdk-rsc/03-create-streamable-ui.mdx +91 -0
- package/docs/07-reference/03-ai-sdk-rsc/04-create-streamable-value.mdx +48 -0
- package/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx +78 -0
- package/docs/07-reference/03-ai-sdk-rsc/06-get-ai-state.mdx +50 -0
- package/docs/07-reference/03-ai-sdk-rsc/07-get-mutable-ai-state.mdx +70 -0
- package/docs/07-reference/03-ai-sdk-rsc/08-use-ai-state.mdx +26 -0
- package/docs/07-reference/03-ai-sdk-rsc/09-use-actions.mdx +42 -0
- package/docs/07-reference/03-ai-sdk-rsc/10-use-ui-state.mdx +35 -0
- package/docs/07-reference/03-ai-sdk-rsc/11-use-streamable-value.mdx +46 -0
- package/docs/07-reference/03-ai-sdk-rsc/20-render.mdx +262 -0
- package/docs/07-reference/03-ai-sdk-rsc/index.mdx +67 -0
- package/docs/07-reference/04-stream-helpers/01-ai-stream.mdx +89 -0
- package/docs/07-reference/04-stream-helpers/02-streaming-text-response.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/05-stream-to-response.mdx +108 -0
- package/docs/07-reference/04-stream-helpers/07-openai-stream.mdx +77 -0
- package/docs/07-reference/04-stream-helpers/08-anthropic-stream.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/09-aws-bedrock-stream.mdx +91 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-anthropic-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-messages-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/11-aws-bedrock-cohere-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/12-aws-bedrock-llama-2-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/13-cohere-stream.mdx +78 -0
- package/docs/07-reference/04-stream-helpers/14-google-generative-ai-stream.mdx +85 -0
- package/docs/07-reference/04-stream-helpers/15-hugging-face-stream.mdx +84 -0
- package/docs/07-reference/04-stream-helpers/16-langchain-adapter.mdx +98 -0
- package/docs/07-reference/04-stream-helpers/16-llamaindex-adapter.mdx +70 -0
- package/docs/07-reference/04-stream-helpers/17-mistral-stream.mdx +81 -0
- package/docs/07-reference/04-stream-helpers/18-replicate-stream.mdx +83 -0
- package/docs/07-reference/04-stream-helpers/19-inkeep-stream.mdx +80 -0
- package/docs/07-reference/04-stream-helpers/index.mdx +103 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +30 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-download-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-empty-response-body-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-argument-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-message-role-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +47 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-response-data-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-input-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-json-parse-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-api-key-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-setting-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-message-conversion-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-content-generated-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +36 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +43 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-speech-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-tool-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-retry-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-too-many-embedding-values-for-call-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-not-found-for-approval-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-repair-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-type-validation-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-unsupported-functionality-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +38 -0
- package/docs/07-reference/index.mdx +34 -0
- package/docs/08-migration-guides/00-versioning.mdx +46 -0
- package/docs/08-migration-guides/24-migration-guide-6-0.mdx +823 -0
- package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +882 -0
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +3427 -0
- package/docs/08-migration-guides/27-migration-guide-4-2.mdx +99 -0
- package/docs/08-migration-guides/28-migration-guide-4-1.mdx +14 -0
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1157 -0
- package/docs/08-migration-guides/36-migration-guide-3-4.mdx +14 -0
- package/docs/08-migration-guides/37-migration-guide-3-3.mdx +64 -0
- package/docs/08-migration-guides/38-migration-guide-3-2.mdx +46 -0
- package/docs/08-migration-guides/39-migration-guide-3-1.mdx +168 -0
- package/docs/08-migration-guides/index.mdx +22 -0
- package/docs/09-troubleshooting/01-azure-stream-slow.mdx +33 -0
- package/docs/09-troubleshooting/02-client-side-function-calls-not-invoked.mdx +22 -0
- package/docs/09-troubleshooting/03-server-actions-in-client-components.mdx +40 -0
- package/docs/09-troubleshooting/04-strange-stream-output.mdx +36 -0
- package/docs/09-troubleshooting/05-streamable-ui-errors.mdx +16 -0
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +106 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-deployed.mdx +31 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-proxied.mdx +31 -0
- package/docs/09-troubleshooting/06-timeout-on-vercel.mdx +60 -0
- package/docs/09-troubleshooting/07-unclosed-streams.mdx +34 -0
- package/docs/09-troubleshooting/08-use-chat-failed-to-parse-stream.mdx +26 -0
- package/docs/09-troubleshooting/09-client-stream-error.mdx +25 -0
- package/docs/09-troubleshooting/10-use-chat-tools-no-response.mdx +32 -0
- package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +149 -0
- package/docs/09-troubleshooting/12-typescript-performance-zod.mdx +46 -0
- package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +59 -0
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +73 -0
- package/docs/09-troubleshooting/14-stream-abort-handling.mdx +73 -0
- package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +48 -0
- package/docs/09-troubleshooting/15-abort-breaks-resumable-streams.mdx +55 -0
- package/docs/09-troubleshooting/15-stream-text-not-working.mdx +33 -0
- package/docs/09-troubleshooting/16-streaming-status-delay.mdx +63 -0
- package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +141 -0
- package/docs/09-troubleshooting/18-ontoolcall-type-narrowing.mdx +66 -0
- package/docs/09-troubleshooting/19-unsupported-model-version.mdx +50 -0
- package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +72 -0
- package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +21 -0
- package/docs/09-troubleshooting/40-typescript-cannot-find-namespace-jsx.mdx +24 -0
- package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +39 -0
- package/docs/09-troubleshooting/60-jest-cannot-find-module-ai-rsc.mdx +22 -0
- package/docs/09-troubleshooting/index.mdx +11 -0
- package/package.json +8 -4
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Stream Protocols
|
|
3
|
+
description: Learn more about the supported stream protocols in the AI SDK.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Stream Protocols
|
|
7
|
+
|
|
8
|
+
AI SDK UI functions such as `useChat` and `useCompletion` support both text streams and data streams.
|
|
9
|
+
The stream protocol defines how the data is streamed to the frontend on top of the HTTP protocol.
|
|
10
|
+
|
|
11
|
+
This page describes both protocols and how to use them in the backend and frontend.
|
|
12
|
+
|
|
13
|
+
You can use this information to develop custom backends and frontends for your use case, e.g.,
|
|
14
|
+
to provide compatible API endpoints that are implemented in a different language such as Python.
|
|
15
|
+
|
|
16
|
+
For instance, here's an example using [FastAPI](https://github.com/vercel/ai/tree/main/examples/next-fastapi) as a backend.
|
|
17
|
+
|
|
18
|
+
## Text Stream Protocol
|
|
19
|
+
|
|
20
|
+
A text stream contains chunks in plain text, that are streamed to the frontend.
|
|
21
|
+
Each chunk is then appended together to form a full text response.
|
|
22
|
+
|
|
23
|
+
Text streams are supported by `useChat`, `useCompletion`, and `useObject`.
|
|
24
|
+
When you use `useChat` or `useCompletion`, you need to enable text streaming
|
|
25
|
+
by setting the `streamProtocol` options to `text`.
|
|
26
|
+
|
|
27
|
+
You can generate text streams with `streamText` in the backend.
|
|
28
|
+
When you call `toTextStreamResponse()` on the result object,
|
|
29
|
+
a streaming HTTP response is returned.
|
|
30
|
+
|
|
31
|
+
<Note>
|
|
32
|
+
Text streams only support basic text data. If you need to stream other types
|
|
33
|
+
of data such as tool calls, use data streams.
|
|
34
|
+
</Note>
|
|
35
|
+
|
|
36
|
+
### Text Stream Example
|
|
37
|
+
|
|
38
|
+
Here is a Next.js example that uses the text stream protocol:
|
|
39
|
+
|
|
40
|
+
```tsx filename='app/page.tsx'
|
|
41
|
+
'use client';
|
|
42
|
+
|
|
43
|
+
import { useChat } from '@ai-sdk/react';
|
|
44
|
+
import { TextStreamChatTransport } from 'ai';
|
|
45
|
+
import { useState } from 'react';
|
|
46
|
+
|
|
47
|
+
export default function Chat() {
|
|
48
|
+
const [input, setInput] = useState('');
|
|
49
|
+
const { messages, sendMessage } = useChat({
|
|
50
|
+
transport: new TextStreamChatTransport({ api: '/api/chat' }),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
|
|
55
|
+
{messages.map(message => (
|
|
56
|
+
<div key={message.id} className="whitespace-pre-wrap">
|
|
57
|
+
{message.role === 'user' ? 'User: ' : 'AI: '}
|
|
58
|
+
{message.parts.map((part, i) => {
|
|
59
|
+
switch (part.type) {
|
|
60
|
+
case 'text':
|
|
61
|
+
return <div key={`${message.id}-${i}`}>{part.text}</div>;
|
|
62
|
+
}
|
|
63
|
+
})}
|
|
64
|
+
</div>
|
|
65
|
+
))}
|
|
66
|
+
|
|
67
|
+
<form
|
|
68
|
+
onSubmit={e => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
sendMessage({ text: input });
|
|
71
|
+
setInput('');
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<input
|
|
75
|
+
className="fixed dark:bg-zinc-900 bottom-0 w-full max-w-md p-2 mb-8 border border-zinc-300 dark:border-zinc-800 rounded shadow-xl"
|
|
76
|
+
value={input}
|
|
77
|
+
placeholder="Say something..."
|
|
78
|
+
onChange={e => setInput(e.currentTarget.value)}
|
|
79
|
+
/>
|
|
80
|
+
</form>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```ts filename='app/api/chat/route.ts'
|
|
87
|
+
import { streamText, UIMessage, convertToModelMessages } from 'ai';
|
|
88
|
+
__PROVIDER_IMPORT__;
|
|
89
|
+
|
|
90
|
+
// Allow streaming responses up to 30 seconds
|
|
91
|
+
export const maxDuration = 30;
|
|
92
|
+
|
|
93
|
+
export async function POST(req: Request) {
|
|
94
|
+
const { messages }: { messages: UIMessage[] } = await req.json();
|
|
95
|
+
|
|
96
|
+
const result = streamText({
|
|
97
|
+
model: __MODEL__,
|
|
98
|
+
messages: await convertToModelMessages(messages),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return result.toTextStreamResponse();
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Data Stream Protocol
|
|
106
|
+
|
|
107
|
+
A data stream follows a special protocol that the AI SDK provides to send information to the frontend.
|
|
108
|
+
|
|
109
|
+
The data stream protocol uses Server-Sent Events (SSE) format for improved standardization, keep-alive through ping, reconnect capabilities, and better cache handling.
|
|
110
|
+
|
|
111
|
+
<Note>
|
|
112
|
+
When you provide data streams from a custom backend, you need to set the
|
|
113
|
+
`x-vercel-ai-ui-message-stream` header to `v1`.
|
|
114
|
+
</Note>
|
|
115
|
+
|
|
116
|
+
The following stream parts are currently supported:
|
|
117
|
+
|
|
118
|
+
### Message Start Part
|
|
119
|
+
|
|
120
|
+
Indicates the beginning of a new message with metadata.
|
|
121
|
+
|
|
122
|
+
Format: Server-Sent Event with JSON object
|
|
123
|
+
|
|
124
|
+
Example:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
data: {"type":"start","messageId":"..."}
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Text Parts
|
|
132
|
+
|
|
133
|
+
Text content is streamed using a start/delta/end pattern with unique IDs for each text block.
|
|
134
|
+
|
|
135
|
+
#### Text Start Part
|
|
136
|
+
|
|
137
|
+
Indicates the beginning of a text block.
|
|
138
|
+
|
|
139
|
+
Format: Server-Sent Event with JSON object
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
data: {"type":"text-start","id":"msg_68679a454370819ca74c8eb3d04379630dd1afb72306ca5d"}
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Text Delta Part
|
|
149
|
+
|
|
150
|
+
Contains incremental text content for the text block.
|
|
151
|
+
|
|
152
|
+
Format: Server-Sent Event with JSON object
|
|
153
|
+
|
|
154
|
+
Example:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
data: {"type":"text-delta","id":"msg_68679a454370819ca74c8eb3d04379630dd1afb72306ca5d","delta":"Hello"}
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Text End Part
|
|
162
|
+
|
|
163
|
+
Indicates the completion of a text block.
|
|
164
|
+
|
|
165
|
+
Format: Server-Sent Event with JSON object
|
|
166
|
+
|
|
167
|
+
Example:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
data: {"type":"text-end","id":"msg_68679a454370819ca74c8eb3d04379630dd1afb72306ca5d"}
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Reasoning Parts
|
|
175
|
+
|
|
176
|
+
Reasoning content is streamed using a start/delta/end pattern with unique IDs for each reasoning block.
|
|
177
|
+
|
|
178
|
+
#### Reasoning Start Part
|
|
179
|
+
|
|
180
|
+
Indicates the beginning of a reasoning block.
|
|
181
|
+
|
|
182
|
+
Format: Server-Sent Event with JSON object
|
|
183
|
+
|
|
184
|
+
Example:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
data: {"type":"reasoning-start","id":"reasoning_123"}
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Reasoning Delta Part
|
|
192
|
+
|
|
193
|
+
Contains incremental reasoning content for the reasoning block.
|
|
194
|
+
|
|
195
|
+
Format: Server-Sent Event with JSON object
|
|
196
|
+
|
|
197
|
+
Example:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
data: {"type":"reasoning-delta","id":"reasoning_123","delta":"This is some reasoning"}
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Reasoning End Part
|
|
205
|
+
|
|
206
|
+
Indicates the completion of a reasoning block.
|
|
207
|
+
|
|
208
|
+
Format: Server-Sent Event with JSON object
|
|
209
|
+
|
|
210
|
+
Example:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
data: {"type":"reasoning-end","id":"reasoning_123"}
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Source Parts
|
|
218
|
+
|
|
219
|
+
Source parts provide references to external content sources.
|
|
220
|
+
|
|
221
|
+
#### Source URL Part
|
|
222
|
+
|
|
223
|
+
References to external URLs.
|
|
224
|
+
|
|
225
|
+
Format: Server-Sent Event with JSON object
|
|
226
|
+
|
|
227
|
+
Example:
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
data: {"type":"source-url","sourceId":"https://example.com","url":"https://example.com"}
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Source Document Part
|
|
235
|
+
|
|
236
|
+
References to documents or files.
|
|
237
|
+
|
|
238
|
+
Format: Server-Sent Event with JSON object
|
|
239
|
+
|
|
240
|
+
Example:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
data: {"type":"source-document","sourceId":"https://example.com","mediaType":"file","title":"Title"}
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### File Part
|
|
248
|
+
|
|
249
|
+
The file parts contain references to files with their media type.
|
|
250
|
+
|
|
251
|
+
Format: Server-Sent Event with JSON object
|
|
252
|
+
|
|
253
|
+
Example:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
data: {"type":"file","url":"https://example.com/file.png","mediaType":"image/png"}
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Data Parts
|
|
261
|
+
|
|
262
|
+
Custom data parts allow streaming of arbitrary structured data with type-specific handling.
|
|
263
|
+
|
|
264
|
+
Format: Server-Sent Event with JSON object where the type includes a custom suffix
|
|
265
|
+
|
|
266
|
+
Example:
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
data: {"type":"data-weather","data":{"location":"SF","temperature":100}}
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
The `data-*` type pattern allows you to define custom data types that your frontend can handle specifically.
|
|
274
|
+
|
|
275
|
+
### Error Part
|
|
276
|
+
|
|
277
|
+
The error parts are appended to the message as they are received.
|
|
278
|
+
|
|
279
|
+
Format: Server-Sent Event with JSON object
|
|
280
|
+
|
|
281
|
+
Example:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
data: {"type":"error","errorText":"error message"}
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Tool Input Start Part
|
|
289
|
+
|
|
290
|
+
Indicates the beginning of tool input streaming.
|
|
291
|
+
|
|
292
|
+
Format: Server-Sent Event with JSON object
|
|
293
|
+
|
|
294
|
+
Example:
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
data: {"type":"tool-input-start","toolCallId":"call_fJdQDqnXeGxTmr4E3YPSR7Ar","toolName":"getWeatherInformation"}
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Tool Input Delta Part
|
|
302
|
+
|
|
303
|
+
Incremental chunks of tool input as it's being generated.
|
|
304
|
+
|
|
305
|
+
Format: Server-Sent Event with JSON object
|
|
306
|
+
|
|
307
|
+
Example:
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
data: {"type":"tool-input-delta","toolCallId":"call_fJdQDqnXeGxTmr4E3YPSR7Ar","inputTextDelta":"San Francisco"}
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Tool Input Available Part
|
|
315
|
+
|
|
316
|
+
Indicates that tool input is complete and ready for execution.
|
|
317
|
+
|
|
318
|
+
Format: Server-Sent Event with JSON object
|
|
319
|
+
|
|
320
|
+
Example:
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
data: {"type":"tool-input-available","toolCallId":"call_fJdQDqnXeGxTmr4E3YPSR7Ar","toolName":"getWeatherInformation","input":{"city":"San Francisco"}}
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Tool Output Available Part
|
|
328
|
+
|
|
329
|
+
Contains the result of tool execution.
|
|
330
|
+
|
|
331
|
+
Format: Server-Sent Event with JSON object
|
|
332
|
+
|
|
333
|
+
Example:
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
data: {"type":"tool-output-available","toolCallId":"call_fJdQDqnXeGxTmr4E3YPSR7Ar","output":{"city":"San Francisco","weather":"sunny"}}
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Start Step Part
|
|
341
|
+
|
|
342
|
+
A part indicating the start of a step.
|
|
343
|
+
|
|
344
|
+
Format: Server-Sent Event with JSON object
|
|
345
|
+
|
|
346
|
+
Example:
|
|
347
|
+
|
|
348
|
+
```
|
|
349
|
+
data: {"type":"start-step"}
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Finish Step Part
|
|
354
|
+
|
|
355
|
+
A part indicating that a step (i.e., one LLM API call in the backend) has been completed.
|
|
356
|
+
|
|
357
|
+
This part is necessary to correctly process multiple stitched assistant calls, e.g. when calling tools in the backend, and using steps in `useChat` at the same time.
|
|
358
|
+
|
|
359
|
+
Format: Server-Sent Event with JSON object
|
|
360
|
+
|
|
361
|
+
Example:
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
data: {"type":"finish-step"}
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Finish Message Part
|
|
369
|
+
|
|
370
|
+
A part indicating the completion of a message.
|
|
371
|
+
|
|
372
|
+
Format: Server-Sent Event with JSON object
|
|
373
|
+
|
|
374
|
+
Example:
|
|
375
|
+
|
|
376
|
+
```
|
|
377
|
+
data: {"type":"finish"}
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Abort Part
|
|
382
|
+
|
|
383
|
+
Indicates the stream was aborted.
|
|
384
|
+
|
|
385
|
+
Format: Server-Sent Event with JSON object
|
|
386
|
+
|
|
387
|
+
Example:
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
data: {"type":"abort","reason":"user cancelled"}
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Stream Termination
|
|
395
|
+
|
|
396
|
+
The stream ends with a special `[DONE]` marker.
|
|
397
|
+
|
|
398
|
+
Format: Server-Sent Event with literal `[DONE]`
|
|
399
|
+
|
|
400
|
+
Example:
|
|
401
|
+
|
|
402
|
+
```
|
|
403
|
+
data: [DONE]
|
|
404
|
+
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
The data stream protocol is supported
|
|
408
|
+
by `useChat` and `useCompletion` on the frontend and used by default.
|
|
409
|
+
`useCompletion` only supports the `text` and `data` stream parts.
|
|
410
|
+
|
|
411
|
+
On the backend, you can use `toUIMessageStreamResponse()` from the `streamText` result object to return a streaming HTTP response.
|
|
412
|
+
|
|
413
|
+
### UI Message Stream Example
|
|
414
|
+
|
|
415
|
+
Here is a Next.js example that uses the UI message stream protocol:
|
|
416
|
+
|
|
417
|
+
```tsx filename='app/page.tsx'
|
|
418
|
+
'use client';
|
|
419
|
+
|
|
420
|
+
import { useChat } from '@ai-sdk/react';
|
|
421
|
+
import { useState } from 'react';
|
|
422
|
+
|
|
423
|
+
export default function Chat() {
|
|
424
|
+
const [input, setInput] = useState('');
|
|
425
|
+
const { messages, sendMessage } = useChat();
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
|
|
429
|
+
{messages.map(message => (
|
|
430
|
+
<div key={message.id} className="whitespace-pre-wrap">
|
|
431
|
+
{message.role === 'user' ? 'User: ' : 'AI: '}
|
|
432
|
+
{message.parts.map((part, i) => {
|
|
433
|
+
switch (part.type) {
|
|
434
|
+
case 'text':
|
|
435
|
+
return <div key={`${message.id}-${i}`}>{part.text}</div>;
|
|
436
|
+
}
|
|
437
|
+
})}
|
|
438
|
+
</div>
|
|
439
|
+
))}
|
|
440
|
+
|
|
441
|
+
<form
|
|
442
|
+
onSubmit={e => {
|
|
443
|
+
e.preventDefault();
|
|
444
|
+
sendMessage({ text: input });
|
|
445
|
+
setInput('');
|
|
446
|
+
}}
|
|
447
|
+
>
|
|
448
|
+
<input
|
|
449
|
+
className="fixed dark:bg-zinc-900 bottom-0 w-full max-w-md p-2 mb-8 border border-zinc-300 dark:border-zinc-800 rounded shadow-xl"
|
|
450
|
+
value={input}
|
|
451
|
+
placeholder="Say something..."
|
|
452
|
+
onChange={e => setInput(e.currentTarget.value)}
|
|
453
|
+
/>
|
|
454
|
+
</form>
|
|
455
|
+
</div>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
```ts filename='app/api/chat/route.ts'
|
|
461
|
+
import { streamText, UIMessage, convertToModelMessages } from 'ai';
|
|
462
|
+
__PROVIDER_IMPORT__;
|
|
463
|
+
|
|
464
|
+
// Allow streaming responses up to 30 seconds
|
|
465
|
+
export const maxDuration = 30;
|
|
466
|
+
|
|
467
|
+
export async function POST(req: Request) {
|
|
468
|
+
const { messages }: { messages: UIMessage[] } = await req.json();
|
|
469
|
+
|
|
470
|
+
const result = streamText({
|
|
471
|
+
model: __MODEL__,
|
|
472
|
+
messages: await convertToModelMessages(messages),
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
return result.toUIMessageStreamResponse();
|
|
476
|
+
}
|
|
477
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI SDK UI
|
|
3
|
+
description: Learn about the AI SDK UI.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AI SDK UI
|
|
7
|
+
|
|
8
|
+
<IndexCards
|
|
9
|
+
cards={[
|
|
10
|
+
{
|
|
11
|
+
title: 'Overview',
|
|
12
|
+
description: 'Get an overview about the AI SDK UI.',
|
|
13
|
+
href: '/docs/ai-sdk-ui/overview'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'Chatbot',
|
|
17
|
+
description: 'Learn how to integrate an interface for a chatbot.',
|
|
18
|
+
href: '/docs/ai-sdk-ui/chatbot'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: 'Chatbot Message Persistence',
|
|
22
|
+
description: 'Learn how to store and load chat messages in a chatbot.',
|
|
23
|
+
href: '/docs/ai-sdk-ui/chatbot-message-persistence'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: 'Chatbot Tool Usage',
|
|
27
|
+
description:
|
|
28
|
+
'Learn how to integrate an interface for a chatbot with tool calling.',
|
|
29
|
+
href: '/docs/ai-sdk-ui/chatbot-tool-usage'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'Completion',
|
|
33
|
+
description: 'Learn how to integrate an interface for text completion.',
|
|
34
|
+
href: '/docs/ai-sdk-ui/completion'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: 'Object Generation',
|
|
38
|
+
description: 'Learn how to integrate an interface for object generation.',
|
|
39
|
+
href: '/docs/ai-sdk-ui/object-generation'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
title: 'Streaming Data',
|
|
43
|
+
description: 'Learn how to stream data.',
|
|
44
|
+
href: '/docs/ai-sdk-ui/streaming-data'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title: 'Reading UI Message Streams',
|
|
48
|
+
description: 'Learn how to read UIMessage streams for terminal UIs, custom clients, and server components.',
|
|
49
|
+
href: '/docs/ai-sdk-ui/reading-ui-message-streams'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
title: 'Error Handling',
|
|
53
|
+
description: 'Learn how to handle errors.',
|
|
54
|
+
href: '/docs/ai-sdk-ui/error-handling'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: 'Stream Protocol',
|
|
58
|
+
description:
|
|
59
|
+
'The stream protocol defines how data is sent from the backend to the AI SDK UI frontend.',
|
|
60
|
+
href: '/docs/ai-sdk-ui/stream-protocol'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
]}
|
|
64
|
+
/>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview
|
|
3
|
+
description: An overview of AI SDK RSC.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AI SDK RSC
|
|
7
|
+
|
|
8
|
+
<Note type="warning">
|
|
9
|
+
AI SDK RSC is currently experimental. We recommend using [AI SDK
|
|
10
|
+
UI](/docs/ai-sdk-ui/overview) for production. For guidance on migrating from
|
|
11
|
+
RSC to UI, see our [migration guide](/docs/ai-sdk-rsc/migrating-to-ui).
|
|
12
|
+
</Note>
|
|
13
|
+
|
|
14
|
+
<Note>
|
|
15
|
+
The `@ai-sdk/rsc` package is compatible with frameworks that support React
|
|
16
|
+
Server Components.
|
|
17
|
+
</Note>
|
|
18
|
+
|
|
19
|
+
[React Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components) (RSC) allow you to write UI that can be rendered on the server and streamed to the client. RSCs enable [ Server Actions ](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#with-client-components), a new way to call server-side code directly from the client just like any other function with end-to-end type-safety. This combination opens the door to a new way of building AI applications, allowing the large language model (LLM) to generate and stream UI directly from the server to the client.
|
|
20
|
+
|
|
21
|
+
## AI SDK RSC Functions
|
|
22
|
+
|
|
23
|
+
AI SDK RSC has various functions designed to help you build AI-native applications with React Server Components. These functions:
|
|
24
|
+
|
|
25
|
+
1. Provide abstractions for building Generative UI applications.
|
|
26
|
+
- [`streamUI`](/docs/reference/ai-sdk-rsc/stream-ui): calls a model and allows it to respond with React Server Components.
|
|
27
|
+
- [`useUIState`](/docs/reference/ai-sdk-rsc/use-ui-state): returns the current UI state and a function to update the UI State (like React's `useState`). UI State is the visual representation of the AI state.
|
|
28
|
+
- [`useAIState`](/docs/reference/ai-sdk-rsc/use-ai-state): returns the current AI state and a function to update the AI State (like React's `useState`). The AI state is intended to contain context and information shared with the AI model, such as system messages, function responses, and other relevant data.
|
|
29
|
+
- [`useActions`](/docs/reference/ai-sdk-rsc/use-actions): provides access to your Server Actions from the client. This is particularly useful for building interfaces that require user interactions with the server.
|
|
30
|
+
- [`createAI`](/docs/reference/ai-sdk-rsc/create-ai): creates a client-server context provider that can be used to wrap parts of your application tree to easily manage both UI and AI states of your application.
|
|
31
|
+
2. Make it simple to work with streamable values between the server and client.
|
|
32
|
+
- [`createStreamableValue`](/docs/reference/ai-sdk-rsc/create-streamable-value): creates a stream that sends values from the server to the client. The value can be any serializable data.
|
|
33
|
+
- [`readStreamableValue`](/docs/reference/ai-sdk-rsc/read-streamable-value): reads a streamable value from the client that was originally created using `createStreamableValue`.
|
|
34
|
+
- [`createStreamableUI`](/docs/reference/ai-sdk-rsc/create-streamable-ui): creates a stream that sends UI from the server to the client.
|
|
35
|
+
- [`useStreamableValue`](/docs/reference/ai-sdk-rsc/use-streamable-value): accepts a streamable value created using `createStreamableValue` and returns the current value, error, and pending state.
|
|
36
|
+
|
|
37
|
+
## Templates
|
|
38
|
+
|
|
39
|
+
Check out the following templates to see AI SDK RSC in action.
|
|
40
|
+
|
|
41
|
+
<Templates type="generative-ui" />
|
|
42
|
+
|
|
43
|
+
## API Reference
|
|
44
|
+
|
|
45
|
+
Please check out the [AI SDK RSC API Reference](/docs/reference/ai-sdk-rsc) for more details on each function.
|