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.
- package/CHANGELOG.md +3521 -0
- package/README.md +112 -22
- package/dist/index.d.mts +3697 -1642
- package/dist/index.d.ts +3697 -1642
- package/dist/index.js +7201 -2942
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7249 -2963
- package/dist/index.mjs.map +1 -1
- package/mcp-stdio/create-child-process.test.ts +92 -0
- package/mcp-stdio/create-child-process.ts +21 -0
- package/mcp-stdio/dist/index.d.mts +169 -0
- package/mcp-stdio/dist/index.d.ts +169 -0
- package/mcp-stdio/dist/index.js +352 -0
- package/mcp-stdio/dist/index.js.map +1 -0
- package/mcp-stdio/dist/index.mjs +337 -0
- package/mcp-stdio/dist/index.mjs.map +1 -0
- package/mcp-stdio/get-environment.ts +43 -0
- package/mcp-stdio/index.ts +4 -0
- package/mcp-stdio/mcp-stdio-transport.test.ts +262 -0
- package/mcp-stdio/mcp-stdio-transport.ts +157 -0
- package/package.json +46 -103
- package/react/dist/index.d.mts +10 -557
- package/react/dist/index.d.ts +10 -574
- package/react/dist/index.js +6 -1397
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +10 -1384
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +432 -199
- package/rsc/dist/rsc-server.d.mts +431 -199
- package/rsc/dist/rsc-server.mjs +1599 -1357
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +30 -23
- package/rsc/dist/rsc-shared.mjs +70 -108
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/test/dist/index.d.mts +65 -0
- package/test/dist/index.d.ts +65 -0
- package/test/dist/index.js +121 -0
- package/test/dist/index.js.map +1 -0
- package/test/dist/index.mjs +94 -0
- package/test/dist/index.mjs.map +1 -0
- package/prompts/dist/index.d.mts +0 -324
- package/prompts/dist/index.d.ts +0 -324
- package/prompts/dist/index.js +0 -178
- package/prompts/dist/index.js.map +0 -1
- package/prompts/dist/index.mjs +0 -146
- package/prompts/dist/index.mjs.map +0 -1
- package/react/dist/index.server.d.mts +0 -17
- package/react/dist/index.server.d.ts +0 -17
- package/react/dist/index.server.js +0 -50
- package/react/dist/index.server.js.map +0 -1
- package/react/dist/index.server.mjs +0 -23
- package/react/dist/index.server.mjs.map +0 -1
- package/solid/dist/index.d.mts +0 -408
- package/solid/dist/index.d.ts +0 -408
- package/solid/dist/index.js +0 -1072
- package/solid/dist/index.js.map +0 -1
- package/solid/dist/index.mjs +0 -1044
- package/solid/dist/index.mjs.map +0 -1
- package/svelte/dist/index.d.mts +0 -484
- package/svelte/dist/index.d.ts +0 -484
- package/svelte/dist/index.js +0 -1778
- package/svelte/dist/index.js.map +0 -1
- package/svelte/dist/index.mjs +0 -1749
- package/svelte/dist/index.mjs.map +0 -1
- package/vue/dist/index.d.mts +0 -402
- package/vue/dist/index.d.ts +0 -402
- package/vue/dist/index.js +0 -1072
- package/vue/dist/index.js.map +0 -1
- package/vue/dist/index.mjs +0 -1034
- package/vue/dist/index.mjs.map +0 -1
package/README.md
CHANGED
@@ -1,37 +1,127 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
# AI SDK
|
4
4
|
|
5
|
-
|
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
|
-
|
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
|
-
|
16
|
-
|
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
|
-
|
17
|
+
## Usage
|
20
18
|
|
21
|
-
|
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
|
-
|
56
|
+
```tsx
|
57
|
+
'use client';
|
24
58
|
|
25
|
-
|
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
|
-
|
61
|
+
export default function Page() {
|
62
|
+
const { messages, input, handleSubmit, handleInputChange, status } =
|
63
|
+
useChat();
|
32
64
|
|
33
|
-
|
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
|
-
|
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
|
-
|
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).
|