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
@@ -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-
|
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
|
-
"
|
18
|
-
"
|
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
|
-
"./
|
44
|
-
"types": "./
|
45
|
-
"import": "./
|
46
|
-
"require": "./
|
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": "
|
61
|
-
"@ai-sdk/provider-utils": "
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
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
|
-
"@
|
76
|
-
"@
|
77
|
-
"@
|
78
|
-
"@
|
79
|
-
"@
|
80
|
-
"
|
81
|
-
"
|
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.
|
103
|
-
"
|
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
|
-
"
|
110
|
-
"
|
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
|
-
"
|
153
|
-
"svelte",
|
96
|
+
"vercel",
|
154
97
|
"react",
|
155
|
-
"
|
98
|
+
"next",
|
99
|
+
"nextjs"
|
156
100
|
],
|
157
101
|
"scripts": {
|
158
|
-
"build": "tsup
|
159
|
-
"
|
160
|
-
"
|
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:
|
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:
|
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
|
}
|