ai 0.0.0-85f9a635-20240518005312 → 0.0.0-9477ebb9-20250403064906

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +3521 -0
  2. package/README.md +112 -22
  3. package/dist/index.d.mts +3697 -1642
  4. package/dist/index.d.ts +3697 -1642
  5. package/dist/index.js +7201 -2942
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +7249 -2963
  8. package/dist/index.mjs.map +1 -1
  9. package/mcp-stdio/create-child-process.test.ts +92 -0
  10. package/mcp-stdio/create-child-process.ts +21 -0
  11. package/mcp-stdio/dist/index.d.mts +169 -0
  12. package/mcp-stdio/dist/index.d.ts +169 -0
  13. package/mcp-stdio/dist/index.js +352 -0
  14. package/mcp-stdio/dist/index.js.map +1 -0
  15. package/mcp-stdio/dist/index.mjs +337 -0
  16. package/mcp-stdio/dist/index.mjs.map +1 -0
  17. package/mcp-stdio/get-environment.ts +43 -0
  18. package/mcp-stdio/index.ts +4 -0
  19. package/mcp-stdio/mcp-stdio-transport.test.ts +262 -0
  20. package/mcp-stdio/mcp-stdio-transport.ts +157 -0
  21. package/package.json +46 -103
  22. package/react/dist/index.d.mts +10 -557
  23. package/react/dist/index.d.ts +10 -574
  24. package/react/dist/index.js +6 -1397
  25. package/react/dist/index.js.map +1 -1
  26. package/react/dist/index.mjs +10 -1384
  27. package/react/dist/index.mjs.map +1 -1
  28. package/rsc/dist/index.d.ts +432 -199
  29. package/rsc/dist/rsc-server.d.mts +431 -199
  30. package/rsc/dist/rsc-server.mjs +1599 -1357
  31. package/rsc/dist/rsc-server.mjs.map +1 -1
  32. package/rsc/dist/rsc-shared.d.mts +30 -23
  33. package/rsc/dist/rsc-shared.mjs +70 -108
  34. package/rsc/dist/rsc-shared.mjs.map +1 -1
  35. package/test/dist/index.d.mts +65 -0
  36. package/test/dist/index.d.ts +65 -0
  37. package/test/dist/index.js +121 -0
  38. package/test/dist/index.js.map +1 -0
  39. package/test/dist/index.mjs +94 -0
  40. package/test/dist/index.mjs.map +1 -0
  41. package/prompts/dist/index.d.mts +0 -324
  42. package/prompts/dist/index.d.ts +0 -324
  43. package/prompts/dist/index.js +0 -178
  44. package/prompts/dist/index.js.map +0 -1
  45. package/prompts/dist/index.mjs +0 -146
  46. package/prompts/dist/index.mjs.map +0 -1
  47. package/react/dist/index.server.d.mts +0 -17
  48. package/react/dist/index.server.d.ts +0 -17
  49. package/react/dist/index.server.js +0 -50
  50. package/react/dist/index.server.js.map +0 -1
  51. package/react/dist/index.server.mjs +0 -23
  52. package/react/dist/index.server.mjs.map +0 -1
  53. package/solid/dist/index.d.mts +0 -408
  54. package/solid/dist/index.d.ts +0 -408
  55. package/solid/dist/index.js +0 -1072
  56. package/solid/dist/index.js.map +0 -1
  57. package/solid/dist/index.mjs +0 -1044
  58. package/solid/dist/index.mjs.map +0 -1
  59. package/svelte/dist/index.d.mts +0 -484
  60. package/svelte/dist/index.d.ts +0 -484
  61. package/svelte/dist/index.js +0 -1778
  62. package/svelte/dist/index.js.map +0 -1
  63. package/svelte/dist/index.mjs +0 -1749
  64. package/svelte/dist/index.mjs.map +0 -1
  65. package/vue/dist/index.d.mts +0 -402
  66. package/vue/dist/index.d.ts +0 -402
  67. package/vue/dist/index.js +0 -1072
  68. package/vue/dist/index.js.map +0 -1
  69. package/vue/dist/index.mjs +0 -1034
  70. package/vue/dist/index.mjs.map +0 -1
package/README.md CHANGED
@@ -1,37 +1,127 @@
1
- # Vercel AI SDK
1
+ ![hero illustration](./assets/hero.gif)
2
2
 
3
- The Vercel AI SDK is **a library for building AI-powered streaming text and chat UIs**.
3
+ # AI SDK
4
4
 
5
- ## Features
5
+ The [AI SDK](https://sdk.vercel.ai/docs) is a TypeScript toolkit designed to help you build AI-powered applications using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
6
6
 
7
- - React, Svelte, Vue and Solid helpers for streaming text responses and building chat and completion UIs
8
- - React Server Components API for streaming [Generative UI](https://vercel.com/blog/ai-sdk-3-generative-ui)
9
- - First-class support for [OpenAI](https://openai.com), [Anthropic](https://www.anthropic.com), [Mistral](https://mistral.ai), [Perplexity](https://perplexity.ai), [AWS Bedrock](https://aws.amazon.com/bedrock/), [Azure](https://ai.azure.com), [Google Gemini](https://ai.google.dev), [Hugging Face](https://huggingface.co), [Fireworks](https://app.fireworks.ai), [Cohere](https://cohere.com), [LangChain](https://js.langchain.com/docs), [Replicate](https://replicate.com), Ollama, and more.
10
- - Node.js, Serverless, and [Edge Runtime](https://edge-runtime.vercel.app/) support
11
- - Lifecycle callbacks for saving completed streaming responses to a database (in the same request)
7
+ To learn more about how to use the AI SDK, check out our [API Reference](https://sdk.vercel.ai/docs/reference) and [Documentation](https://sdk.vercel.ai/docs).
12
8
 
13
9
  ## Installation
14
10
 
15
- ```sh
16
- pnpm install ai
11
+ You will need Node.js 18+ and pnpm installed on your local development machine.
12
+
13
+ ```shell
14
+ npm install ai
17
15
  ```
18
16
 
19
- View the full documentation and examples on [sdk.vercel.ai/docs](https://sdk.vercel.ai/docs).
17
+ ## Usage
20
18
 
21
- ## Authors
19
+ ### AI SDK Core
20
+
21
+ The [AI SDK Core](https://sdk.vercel.ai/docs/ai-sdk-core/overview) module provides a unified API to interact with model providers like [OpenAI](https://sdk.vercel.ai/providers/ai-sdk-providers/openai), [Anthropic](https://sdk.vercel.ai/providers/ai-sdk-providers/anthropic), [Google](https://sdk.vercel.ai/providers/ai-sdk-providers/google-generative-ai), and more.
22
+
23
+ You will then install the model provider of your choice.
24
+
25
+ ```shell
26
+ npm install @ai-sdk/openai
27
+ ```
28
+
29
+ ###### @/index.ts (Node.js Runtime)
30
+
31
+ ```ts
32
+ import { generateText } from 'ai';
33
+ import { openai } from '@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is set
34
+
35
+ const { text } = await generateText({
36
+ model: openai('gpt-4o'),
37
+ system: 'You are a friendly assistant!',
38
+ prompt: 'Why is the sky blue?',
39
+ });
40
+
41
+ console.log(text);
42
+ ```
43
+
44
+ ### AI SDK UI
45
+
46
+ The [AI SDK UI](https://sdk.vercel.ai/docs/ai-sdk-ui/overview) module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, and Vue.
47
+
48
+ You need to install the package for your framework:
49
+
50
+ ```shell
51
+ npm install @ai-sdk/react
52
+ ```
53
+
54
+ ###### @/app/page.tsx (Next.js App Router)
22
55
 
23
- This library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from:
56
+ ```tsx
57
+ 'use client';
24
58
 
25
- - Jared Palmer ([@jaredpalmer](https://twitter.com/jaredpalmer)) - [Vercel](https://vercel.com)
26
- - Shu Ding ([@shuding\_](https://twitter.com/shuding_)) - [Vercel](https://vercel.com)
27
- - Max Leiter ([@max_leiter](https://twitter.com/max_leiter)) - [Vercel](https://vercel.com)
28
- - Malte Ubl ([@cramforce](https://twitter.com/cramforce)) - [Vercel](https://vercel.com)
29
- - Justin Ridgewell ([@jridgewell](https://github.com/jridgewell))
59
+ import { useChat } from '@ai-sdk/react';
30
60
 
31
- [Contributors](https://github.com/vercel/ai/graphs/contributors)
61
+ export default function Page() {
62
+ const { messages, input, handleSubmit, handleInputChange, status } =
63
+ useChat();
32
64
 
33
- ## Related: Deploy your own Next.js AI Chatbot
65
+ return (
66
+ <div>
67
+ {messages.map(message => (
68
+ <div key={message.id}>
69
+ <strong>{`${message.role}: `}</strong>
70
+ {message.parts.map((part, index) => {
71
+ switch (part.type) {
72
+ case 'text':
73
+ return <span key={index}>{part.text}</span>;
34
74
 
35
- If you're looking to for a full AI Chatbot application to jumpstart your AI journey, you should checkout [our sister OSS AI Chatbot project](https://github.com/vercel/ai-chatbot) or click the button below to deploy your own to [Vercel](https://vercel.com).
75
+ // other cases can handle images, tool calls, etc
76
+ }
77
+ })}
78
+ </div>
79
+ ))}
80
+
81
+ <form onSubmit={handleSubmit}>
82
+ <input
83
+ value={input}
84
+ placeholder="Send a message..."
85
+ onChange={handleInputChange}
86
+ disabled={status !== 'ready'}
87
+ />
88
+ </form>
89
+ </div>
90
+ );
91
+ }
92
+ ```
93
+
94
+ ###### @/app/api/chat/route.ts (Next.js App Router)
95
+
96
+ ```ts
97
+ import { streamText } from 'ai';
98
+ import { openai } from '@ai-sdk/openai';
99
+
100
+ export async function POST(req: Request) {
101
+ const { messages } = await req.json();
102
+
103
+ const result = streamText({
104
+ model: openai('gpt-4o'),
105
+ system: 'You are a helpful assistant.',
106
+ messages,
107
+ });
108
+
109
+ return result.toDataStreamResponse();
110
+ }
111
+ ```
112
+
113
+ ## Templates
114
+
115
+ We've built [templates](https://vercel.com/templates?type=ai) that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.
116
+
117
+ ## Community
118
+
119
+ The AI SDK community can be found on [GitHub Discussions](https://github.com/vercel/ai/discussions) where you can ask questions, voice ideas, and share your projects with other people.
120
+
121
+ ## Contributing
122
+
123
+ Contributions to the AI SDK are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](https://github.com/vercel/ai/blob/main/CONTRIBUTING.md) to make sure you have smooth experience contributing to AI SDK.
124
+
125
+ ## Authors
36
126
 
37
- [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/templates/Next.js/nextjs-ai-chatbot)
127
+ This library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from the [Open Source Community](https://github.com/vercel/ai/graphs/contributors).