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
@@ -0,0 +1,157 @@
1
+ import type { ChildProcess, IOType } from 'node:child_process';
2
+ import { Stream } from 'node:stream';
3
+ import {
4
+ JSONRPCMessage,
5
+ JSONRPCMessageSchema,
6
+ } from '../core/tool/mcp/json-rpc-message';
7
+ import { MCPTransport } from '../core/tool/mcp/mcp-transport';
8
+ import { MCPClientError } from '../errors';
9
+ import { createChildProcess } from './create-child-process';
10
+
11
+ export interface StdioConfig {
12
+ command: string;
13
+ args?: string[];
14
+ env?: Record<string, string>;
15
+ stderr?: IOType | Stream | number;
16
+ cwd?: string;
17
+ }
18
+
19
+ export class StdioMCPTransport implements MCPTransport {
20
+ private process?: ChildProcess;
21
+ private abortController: AbortController = new AbortController();
22
+ private readBuffer: ReadBuffer = new ReadBuffer();
23
+ private serverParams: StdioConfig;
24
+
25
+ onclose?: () => void;
26
+ onerror?: (error: unknown) => void;
27
+ onmessage?: (message: JSONRPCMessage) => void;
28
+
29
+ constructor(server: StdioConfig) {
30
+ this.serverParams = server;
31
+ }
32
+
33
+ async start(): Promise<void> {
34
+ if (this.process) {
35
+ throw new MCPClientError({
36
+ message: 'StdioMCPTransport already started.',
37
+ });
38
+ }
39
+
40
+ return new Promise(async (resolve, reject) => {
41
+ try {
42
+ const process = await createChildProcess(
43
+ this.serverParams,
44
+ this.abortController.signal,
45
+ );
46
+
47
+ this.process = process;
48
+
49
+ this.process.on('error', error => {
50
+ if (error.name === 'AbortError') {
51
+ this.onclose?.();
52
+ return;
53
+ }
54
+
55
+ reject(error);
56
+ this.onerror?.(error);
57
+ });
58
+
59
+ this.process.on('spawn', () => {
60
+ resolve();
61
+ });
62
+
63
+ this.process.on('close', _code => {
64
+ this.process = undefined;
65
+ this.onclose?.();
66
+ });
67
+
68
+ this.process.stdin?.on('error', error => {
69
+ this.onerror?.(error);
70
+ });
71
+
72
+ this.process.stdout?.on('data', chunk => {
73
+ this.readBuffer.append(chunk);
74
+ this.processReadBuffer();
75
+ });
76
+
77
+ this.process.stdout?.on('error', error => {
78
+ this.onerror?.(error);
79
+ });
80
+ } catch (error) {
81
+ reject(error);
82
+ this.onerror?.(error);
83
+ }
84
+ });
85
+ }
86
+
87
+ private processReadBuffer() {
88
+ while (true) {
89
+ try {
90
+ const message = this.readBuffer.readMessage();
91
+ if (message === null) {
92
+ break;
93
+ }
94
+
95
+ this.onmessage?.(message);
96
+ } catch (error) {
97
+ this.onerror?.(error as Error);
98
+ }
99
+ }
100
+ }
101
+
102
+ async close(): Promise<void> {
103
+ this.abortController.abort();
104
+ this.process = undefined;
105
+ this.readBuffer.clear();
106
+ }
107
+
108
+ send(message: JSONRPCMessage): Promise<void> {
109
+ return new Promise(resolve => {
110
+ if (!this.process?.stdin) {
111
+ throw new MCPClientError({
112
+ message: 'StdioClientTransport not connected',
113
+ });
114
+ }
115
+
116
+ const json = serializeMessage(message);
117
+ if (this.process.stdin.write(json)) {
118
+ resolve();
119
+ } else {
120
+ this.process.stdin.once('drain', resolve);
121
+ }
122
+ });
123
+ }
124
+ }
125
+
126
+ class ReadBuffer {
127
+ private buffer?: Buffer;
128
+
129
+ append(chunk: Buffer): void {
130
+ this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
131
+ }
132
+
133
+ readMessage(): JSONRPCMessage | null {
134
+ if (!this.buffer) return null;
135
+
136
+ const index = this.buffer.indexOf('\n');
137
+ if (index === -1) {
138
+ return null;
139
+ }
140
+
141
+ const line = this.buffer.toString('utf8', 0, index);
142
+ this.buffer = this.buffer.subarray(index + 1);
143
+ return deserializeMessage(line);
144
+ }
145
+
146
+ clear(): void {
147
+ this.buffer = undefined;
148
+ }
149
+ }
150
+
151
+ function serializeMessage(message: JSONRPCMessage): string {
152
+ return JSON.stringify(message) + '\n';
153
+ }
154
+
155
+ export function deserializeMessage(line: string): JSONRPCMessage {
156
+ return JSONRPCMessageSchema.parse(JSON.parse(line));
157
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "0.0.0-85f9a635-20240518005312",
3
+ "version": "0.0.0-9477ebb9-20250403064906",
4
+ "description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
4
5
  "license": "Apache-2.0",
5
6
  "sideEffects": false,
6
7
  "main": "./dist/index.js",
@@ -8,14 +9,11 @@
8
9
  "types": "./dist/index.d.ts",
9
10
  "files": [
10
11
  "dist/**/*",
12
+ "mcp-stdio/**/*",
11
13
  "react/dist/**/*",
12
- "svelte/dist/**/*",
13
- "vue/dist/**/*",
14
- "solid/dist/**/*",
15
- "prompts/dist/**/*",
16
14
  "rsc/dist/**/*",
17
- "google/dist/**/*",
18
- "mistral/dist/**/*"
15
+ "test/dist/**/*",
16
+ "CHANGELOG.md"
19
17
  ],
20
18
  "exports": {
21
19
  "./package.json": "./package.json",
@@ -24,113 +22,59 @@
24
22
  "import": "./dist/index.mjs",
25
23
  "require": "./dist/index.js"
26
24
  },
25
+ "./test": {
26
+ "types": "./test/dist/index.d.ts",
27
+ "import": "./test/dist/index.mjs",
28
+ "module": "./test/dist/index.mjs",
29
+ "require": "./test/dist/index.js"
30
+ },
27
31
  "./rsc": {
28
32
  "types": "./rsc/dist/index.d.ts",
29
33
  "react-server": "./rsc/dist/rsc-server.mjs",
30
34
  "import": "./rsc/dist/rsc-client.mjs"
31
35
  },
32
- "./prompts": {
33
- "types": "./prompts/dist/index.d.ts",
34
- "import": "./prompts/dist/index.mjs",
35
- "require": "./prompts/dist/index.js"
36
- },
37
36
  "./react": {
38
37
  "types": "./react/dist/index.d.ts",
39
38
  "react-server": "./react/dist/index.server.mjs",
40
39
  "import": "./react/dist/index.mjs",
41
40
  "require": "./react/dist/index.js"
42
41
  },
43
- "./svelte": {
44
- "types": "./svelte/dist/index.d.ts",
45
- "import": "./svelte/dist/index.mjs",
46
- "require": "./svelte/dist/index.js"
47
- },
48
- "./vue": {
49
- "types": "./vue/dist/index.d.ts",
50
- "import": "./vue/dist/index.mjs",
51
- "require": "./vue/dist/index.js"
52
- },
53
- "./solid": {
54
- "types": "./solid/dist/index.d.ts",
55
- "import": "./solid/dist/index.mjs",
56
- "require": "./solid/dist/index.js"
42
+ "./mcp-stdio": {
43
+ "types": "./mcp-stdio/dist/index.d.ts",
44
+ "import": "./mcp-stdio/dist/index.mjs",
45
+ "require": "./mcp-stdio/dist/index.js"
57
46
  }
58
47
  },
59
48
  "dependencies": {
60
- "@ai-sdk/provider": "0.0.0-85f9a635-20240518005312",
61
- "@ai-sdk/provider-utils": "0.0.0-85f9a635-20240518005312",
62
- "secure-json-parse": "2.7.0",
63
- "eventsource-parser": "1.1.2",
64
- "jsondiffpatch": "0.6.0",
65
- "json-schema": "0.4.0",
66
- "nanoid": "3.3.6",
67
- "solid-swr-store": "0.10.7",
68
- "sswr": "2.0.0",
69
- "swr": "2.2.0",
70
- "swr-store": "0.10.6",
71
- "swrv": "1.0.4",
72
- "zod-to-json-schema": "3.22.5"
49
+ "@ai-sdk/provider": "1.1.0",
50
+ "@ai-sdk/provider-utils": "2.2.3",
51
+ "@ai-sdk/react": "0.0.0-9477ebb9-20250403064906",
52
+ "@ai-sdk/ui-utils": "0.0.0-9477ebb9-20250403064906",
53
+ "@opentelemetry/api": "1.9.0",
54
+ "jsondiffpatch": "0.6.0"
73
55
  },
74
56
  "devDependencies": {
75
- "@anthropic-ai/sdk": "0.18.0",
76
- "@aws-sdk/client-bedrock-runtime": "3.451.0",
77
- "@edge-runtime/vm": "^3.2.0",
78
- "@google/generative-ai": "0.1.1",
79
- "@huggingface/inference": "2.6.4",
80
- "@mistralai/mistralai": "0.1.3",
81
- "@solidjs/testing-library": "0.8.4",
82
- "@testing-library/jest-dom": "^6.4.5",
83
- "@testing-library/react": "^14.0.0",
84
- "@testing-library/user-event": "^14.5.1",
85
- "@testing-library/vue": "^8.0.1",
86
- "@types/json-schema": "7.0.15",
87
- "@types/node": "^17.0.12",
88
- "@types/react": "^18.2.8",
89
- "@types/react-dom": "^18.2.0",
90
- "@vitejs/plugin-react": "4.2.0",
91
- "@vitejs/plugin-vue": "4.5.0",
92
- "cohere-ai": "^7.6.2",
93
- "eslint": "^7.32.0",
94
- "jsdom": "^24.0.0",
95
- "langchain": "0.0.196",
96
- "msw": "2.0.9",
97
- "openai": "4.47.1",
98
- "react-dom": "^18.2.0",
57
+ "@edge-runtime/vm": "^5.0.0",
58
+ "@types/node": "20.17.24",
59
+ "@types/react": "^18",
60
+ "@types/react-dom": "^18",
61
+ "@vitejs/plugin-react": "4.3.3",
62
+ "eslint": "8.57.1",
63
+ "react-dom": "^18",
99
64
  "react-server-dom-webpack": "18.3.0-canary-eb33bd747-20240312",
100
- "solid-js": "^1.8.7",
101
65
  "tsup": "^7.2.0",
102
- "typescript": "5.1.3",
103
- "vite-plugin-solid": "2.7.2",
104
- "zod": "3.22.4",
66
+ "typescript": "5.6.3",
67
+ "zod": "3.23.8",
105
68
  "@vercel/ai-tsconfig": "0.0.0",
106
69
  "eslint-config-vercel-ai": "0.0.0"
107
70
  },
108
71
  "peerDependencies": {
109
- "openai": "^4.42.0",
110
- "react": "^18.2.0",
111
- "solid-js": "^1.7.7",
112
- "svelte": "^3.0.0 || ^4.0.0",
113
- "vue": "^3.3.4",
114
- "zod": "^3.0.0"
72
+ "react": "^18 || ^19 || ^19.0.0-rc",
73
+ "zod": "^3.23.8"
115
74
  },
116
75
  "peerDependenciesMeta": {
117
76
  "react": {
118
77
  "optional": true
119
- },
120
- "svelte": {
121
- "optional": true
122
- },
123
- "vue": {
124
- "optional": true
125
- },
126
- "solid-js": {
127
- "optional": true
128
- },
129
- "zod": {
130
- "optional": true
131
- },
132
- "openai": {
133
- "optional": true
134
78
  }
135
79
  },
136
80
  "engines": {
@@ -149,30 +93,29 @@
149
93
  },
150
94
  "keywords": [
151
95
  "ai",
152
- "nextjs",
153
- "svelte",
96
+ "vercel",
154
97
  "react",
155
- "vue"
98
+ "next",
99
+ "nextjs"
156
100
  ],
157
101
  "scripts": {
158
- "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
159
- "clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist && rm -rf rsc/dist",
160
- "dev": "tsup --watch",
102
+ "build": "tsup",
103
+ "build:watch": "tsup --watch",
104
+ "clean": "rm -rf dist && rm -rf react/dist && rm -rf rsc/dist",
161
105
  "lint": "eslint \"./**/*.ts*\"",
162
106
  "type-check": "tsc --noEmit",
163
107
  "prettier-check": "prettier --check \"./**/*.ts*\"",
164
- "test": "pnpm test:node && pnpm test:edge && pnpm test:ui",
108
+ "test": "pnpm test:node && pnpm test:edge && pnpm test:ui && pnpm test:e2e",
109
+ "test:e2e": "playwright test",
165
110
  "test:edge": "vitest --config vitest.edge.config.js --run",
111
+ "test:edge:watch": "vitest --config vitest.edge.config.js",
166
112
  "test:node": "vitest --config vitest.node.config.js --run",
113
+ "test:node:watch": "vitest --config vitest.node.config.js",
167
114
  "test:node:core": "pnpm vitest --config vitest.node.config.js --run ./core/",
168
- "test:ui": "pnpm test:ui:react && pnpm test:ui:vue && pnpm test:ui:solid",
115
+ "test:node:core:watch": "pnpm vitest --config vitest.node.config.js ./core/",
116
+ "test:node:util": "pnpm vitest --config vitest.node.config.js --run ./util/",
117
+ "test:ui": "pnpm test:ui:react",
169
118
  "test:ui:react": "vitest --config vitest.ui.react.config.js --run",
170
- "test:ui:solid": "vitest --config vitest.ui.solid.config.js --run",
171
- "test:ui:vue": "vitest --config vitest.ui.vue.config.js --run",
172
- "test:edge:watch": "vitest --config vitest.edge.config.js",
173
- "test:node:watch": "vitest --config vitest.node.config.js",
174
- "test:ui:react:watch": "vitest --config vitest.ui.react.config.js",
175
- "test:ui:solid:watch": "vitest --config vitest.ui.solid.config.js",
176
- "test:ui:vue:watch": "vitest --config vitest.ui.vue.config.js"
119
+ "test:ui:react:watch": "vitest --config vitest.ui.react.config.js"
177
120
  }
178
121
  }