@standardagents/builder 0.9.12 → 0.9.15
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/dist/built-in-routes.js.map +1 -1
- package/dist/index.d.ts +41 -4
- package/dist/index.js +588 -102
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +147 -12
- package/dist/plugin.js.map +1 -1
- package/package.json +10 -8
- package/dist/mcp.js +0 -663
- package/dist/mcp.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardagents/builder",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "restricted",
|
|
@@ -33,11 +33,6 @@
|
|
|
33
33
|
"import": "./dist/built-in-routes.js",
|
|
34
34
|
"default": "./dist/built-in-routes.js"
|
|
35
35
|
},
|
|
36
|
-
"./mcp": {
|
|
37
|
-
"workerd": "./dist/mcp.js",
|
|
38
|
-
"import": "./dist/mcp.js",
|
|
39
|
-
"default": "./dist/mcp.js"
|
|
40
|
-
},
|
|
41
36
|
"./rou3": {
|
|
42
37
|
"workerd": "./dist/rou3.js",
|
|
43
38
|
"import": "./dist/rou3.js",
|
|
@@ -59,11 +54,15 @@
|
|
|
59
54
|
"build:ui:test": "KEEP_TEST_IDS=true vite build --config vite.config.ui.ts",
|
|
60
55
|
"dev": "tsup --watch",
|
|
61
56
|
"dev:ui": "vite --config vite.config.ui.ts --port 5177",
|
|
62
|
-
"typecheck": "tsc --noEmit"
|
|
57
|
+
"typecheck": "tsc --noEmit",
|
|
58
|
+
"test": "vitest",
|
|
59
|
+
"test:unit": "vitest --config vitest.config.ts",
|
|
60
|
+
"test:integration": "vitest --config vitest.workerd.config.ts",
|
|
61
|
+
"test:watch": "vitest --watch",
|
|
62
|
+
"test:coverage": "vitest run --coverage"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@formkit/drag-and-drop": "^0.5.3",
|
|
66
|
-
"@modelcontextprotocol/sdk": "^1.17.4",
|
|
67
66
|
"@vueuse/core": "^14.0.0",
|
|
68
67
|
"lucide-vue-next": "^0.546.0",
|
|
69
68
|
"monaco-editor": "^0.52.2",
|
|
@@ -76,11 +75,13 @@
|
|
|
76
75
|
"zodown": "^0.2.1"
|
|
77
76
|
},
|
|
78
77
|
"devDependencies": {
|
|
78
|
+
"@cloudflare/vitest-pool-workers": "^0.10.14",
|
|
79
79
|
"@cloudflare/workers-types": "^4.0.0",
|
|
80
80
|
"@iconify-json/lucide": "^1.2.62",
|
|
81
81
|
"@tailwindcss/vite": "^4.1.12",
|
|
82
82
|
"@types/node": "^22.16.5",
|
|
83
83
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
84
|
+
"@vitest/coverage-istanbul": "^4.0.15",
|
|
84
85
|
"@vue/tsconfig": "^0.7.0",
|
|
85
86
|
"esbuild-plugin-alias": "^0.2.1",
|
|
86
87
|
"tailwindcss": "^4.1.12",
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"unplugin-vue": "^7.0.4",
|
|
92
93
|
"vite": "^7.0.6",
|
|
93
94
|
"vite-plugin-monaco-editor": "^1.1.0",
|
|
95
|
+
"vitest": "^2.1.9",
|
|
94
96
|
"vue-tsc": "^2.0.0"
|
|
95
97
|
},
|
|
96
98
|
"peerDependencies": {
|
package/dist/mcp.js
DELETED
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
-
import { tools } from 'virtual:@standardagents-tools';
|
|
4
|
-
import { zodown } from 'zodown';
|
|
5
|
-
|
|
6
|
-
// src/mcp/server.ts
|
|
7
|
-
|
|
8
|
-
// src/utils/ServerResponseProxy.ts
|
|
9
|
-
var ServerResponseProxy = class {
|
|
10
|
-
_statusCode = 200;
|
|
11
|
-
_statusMessage;
|
|
12
|
-
_headers = {};
|
|
13
|
-
_cookies = [];
|
|
14
|
-
_body = [];
|
|
15
|
-
_finished = false;
|
|
16
|
-
_headersSent = false;
|
|
17
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
18
|
-
_closed = false;
|
|
19
|
-
_streamController;
|
|
20
|
-
_isStreaming = false;
|
|
21
|
-
constructor() {
|
|
22
|
-
}
|
|
23
|
-
get statusCode() {
|
|
24
|
-
return this._statusCode;
|
|
25
|
-
}
|
|
26
|
-
set statusCode(code) {
|
|
27
|
-
if (this._headersSent) {
|
|
28
|
-
throw new Error("Cannot set status code after headers have been sent");
|
|
29
|
-
}
|
|
30
|
-
this._statusCode = code;
|
|
31
|
-
}
|
|
32
|
-
get statusMessage() {
|
|
33
|
-
return this._statusMessage;
|
|
34
|
-
}
|
|
35
|
-
set statusMessage(message) {
|
|
36
|
-
if (this._headersSent) {
|
|
37
|
-
throw new Error("Cannot set status message after headers have been sent");
|
|
38
|
-
}
|
|
39
|
-
this._statusMessage = message;
|
|
40
|
-
}
|
|
41
|
-
get headersSent() {
|
|
42
|
-
return this._headersSent;
|
|
43
|
-
}
|
|
44
|
-
get finished() {
|
|
45
|
-
return this._finished;
|
|
46
|
-
}
|
|
47
|
-
writeHead(statusCode, statusMessage, headers) {
|
|
48
|
-
if (this._headersSent) {
|
|
49
|
-
throw new Error("Cannot set headers after they are sent");
|
|
50
|
-
}
|
|
51
|
-
this._statusCode = statusCode;
|
|
52
|
-
if (typeof statusMessage === "string") {
|
|
53
|
-
this._statusMessage = statusMessage;
|
|
54
|
-
if (headers) {
|
|
55
|
-
this._setHeaders(headers);
|
|
56
|
-
}
|
|
57
|
-
} else if (statusMessage) {
|
|
58
|
-
this._setHeaders(statusMessage);
|
|
59
|
-
}
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
setHeader(name, value) {
|
|
63
|
-
if (this._headersSent) {
|
|
64
|
-
throw new Error("Cannot set headers after they are sent");
|
|
65
|
-
}
|
|
66
|
-
this._headers[name.toLowerCase()] = String(value);
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
getHeader(name) {
|
|
70
|
-
return this._headers[name.toLowerCase()];
|
|
71
|
-
}
|
|
72
|
-
getHeaders() {
|
|
73
|
-
return { ...this._headers };
|
|
74
|
-
}
|
|
75
|
-
getHeaderNames() {
|
|
76
|
-
return Object.keys(this._headers);
|
|
77
|
-
}
|
|
78
|
-
hasHeader(name) {
|
|
79
|
-
return name.toLowerCase() in this._headers;
|
|
80
|
-
}
|
|
81
|
-
removeHeader(name) {
|
|
82
|
-
if (this._headersSent) {
|
|
83
|
-
throw new Error("Cannot remove headers after they are sent");
|
|
84
|
-
}
|
|
85
|
-
delete this._headers[name.toLowerCase()];
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
write(chunk, encoding, callback) {
|
|
89
|
-
if (this._finished) {
|
|
90
|
-
throw new Error("Cannot write after end");
|
|
91
|
-
}
|
|
92
|
-
if (!this._headersSent) {
|
|
93
|
-
this._headersSent = true;
|
|
94
|
-
}
|
|
95
|
-
let data;
|
|
96
|
-
if (typeof chunk === "string") {
|
|
97
|
-
data = new TextEncoder().encode(chunk);
|
|
98
|
-
} else {
|
|
99
|
-
data = chunk;
|
|
100
|
-
}
|
|
101
|
-
const contentType = this._headers["content-type"];
|
|
102
|
-
if (typeof contentType === "string" && contentType.includes("text/event-stream")) {
|
|
103
|
-
this._isStreaming = true;
|
|
104
|
-
if (this._streamController) {
|
|
105
|
-
this._streamController.enqueue(data);
|
|
106
|
-
} else {
|
|
107
|
-
this._body.push(data);
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
this._body.push(data);
|
|
111
|
-
}
|
|
112
|
-
if (typeof encoding === "function") {
|
|
113
|
-
encoding();
|
|
114
|
-
} else if (callback) {
|
|
115
|
-
callback();
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
end(chunk, encoding, callback) {
|
|
120
|
-
if (this._finished) {
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
if (chunk !== void 0) {
|
|
124
|
-
this.write(chunk, encoding, callback);
|
|
125
|
-
} else if (typeof encoding === "function") {
|
|
126
|
-
encoding();
|
|
127
|
-
} else if (callback) {
|
|
128
|
-
callback();
|
|
129
|
-
}
|
|
130
|
-
if (!this._headersSent) {
|
|
131
|
-
this._headersSent = true;
|
|
132
|
-
}
|
|
133
|
-
this._finished = true;
|
|
134
|
-
if (this._streamController) {
|
|
135
|
-
this._streamController.close();
|
|
136
|
-
}
|
|
137
|
-
this.emit("finish");
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
writeContinue() {
|
|
141
|
-
}
|
|
142
|
-
writeProcessing() {
|
|
143
|
-
}
|
|
144
|
-
flushHeaders() {
|
|
145
|
-
if (!this._headersSent) {
|
|
146
|
-
this._headersSent = true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
setTimeout(msecs, callback) {
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
addTrailers(headers) {
|
|
153
|
-
}
|
|
154
|
-
cork() {
|
|
155
|
-
}
|
|
156
|
-
uncork() {
|
|
157
|
-
}
|
|
158
|
-
destroy(error) {
|
|
159
|
-
if (!this._closed) {
|
|
160
|
-
this._closed = true;
|
|
161
|
-
this.emit("close");
|
|
162
|
-
}
|
|
163
|
-
this._finished = true;
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
// Event emitter methods
|
|
167
|
-
on(event, listener) {
|
|
168
|
-
if (!this._listeners.has(event)) {
|
|
169
|
-
this._listeners.set(event, []);
|
|
170
|
-
}
|
|
171
|
-
this._listeners.get(event).push(listener);
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
once(event, listener) {
|
|
175
|
-
const onceWrapper = (...args) => {
|
|
176
|
-
this.off(event, onceWrapper);
|
|
177
|
-
listener(...args);
|
|
178
|
-
};
|
|
179
|
-
return this.on(event, onceWrapper);
|
|
180
|
-
}
|
|
181
|
-
off(event, listener) {
|
|
182
|
-
const listeners = this._listeners.get(event);
|
|
183
|
-
if (listeners) {
|
|
184
|
-
const index = listeners.indexOf(listener);
|
|
185
|
-
if (index !== -1) {
|
|
186
|
-
listeners.splice(index, 1);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
emit(event, ...args) {
|
|
192
|
-
const listeners = this._listeners.get(event);
|
|
193
|
-
if (listeners && listeners.length > 0) {
|
|
194
|
-
listeners.forEach((listener) => {
|
|
195
|
-
try {
|
|
196
|
-
listener(...args);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
setTimeout(() => this.emit("error", error), 0);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
addListener(event, listener) {
|
|
206
|
-
return this.on(event, listener);
|
|
207
|
-
}
|
|
208
|
-
removeListener(event, listener) {
|
|
209
|
-
return this.off(event, listener);
|
|
210
|
-
}
|
|
211
|
-
removeAllListeners(event) {
|
|
212
|
-
if (event) {
|
|
213
|
-
this._listeners.delete(event);
|
|
214
|
-
} else {
|
|
215
|
-
this._listeners.clear();
|
|
216
|
-
}
|
|
217
|
-
return this;
|
|
218
|
-
}
|
|
219
|
-
// Cookie handling methods
|
|
220
|
-
cookie(name, value, options) {
|
|
221
|
-
if (this._headersSent) {
|
|
222
|
-
throw new Error("Cannot set headers after they are sent");
|
|
223
|
-
}
|
|
224
|
-
let cookie = `${name}=${value}`;
|
|
225
|
-
if (options) {
|
|
226
|
-
if (options.domain) cookie += `; Domain=${options.domain}`;
|
|
227
|
-
if (options.expires)
|
|
228
|
-
cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
229
|
-
if (options.httpOnly) cookie += "; HttpOnly";
|
|
230
|
-
if (options.maxAge) cookie += `; Max-Age=${options.maxAge}`;
|
|
231
|
-
if (options.path) cookie += `; Path=${options.path}`;
|
|
232
|
-
if (options.secure) cookie += "; Secure";
|
|
233
|
-
if (options.sameSite) {
|
|
234
|
-
if (typeof options.sameSite === "boolean") {
|
|
235
|
-
cookie += "; SameSite=Strict";
|
|
236
|
-
} else {
|
|
237
|
-
cookie += `; SameSite=${options.sameSite}`;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
this._cookies.push(cookie);
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
clearCookie(name, options) {
|
|
245
|
-
if (this._headersSent) {
|
|
246
|
-
throw new Error("Cannot set headers after they are sent");
|
|
247
|
-
}
|
|
248
|
-
let cookie = `${name}=; Expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
|
249
|
-
if (options) {
|
|
250
|
-
if (options.domain) cookie += `; Domain=${options.domain}`;
|
|
251
|
-
if (options.path) cookie += `; Path=${options.path}`;
|
|
252
|
-
}
|
|
253
|
-
this._cookies.push(cookie);
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
_setHeaders(headers) {
|
|
257
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
258
|
-
if (value !== void 0) {
|
|
259
|
-
this._headers[key.toLowerCase()] = Array.isArray(value) ? value : String(value);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
toResponse() {
|
|
264
|
-
const headers = new Headers();
|
|
265
|
-
for (const [key, value] of Object.entries(this._headers)) {
|
|
266
|
-
if (Array.isArray(value)) {
|
|
267
|
-
value.forEach((v) => headers.append(key, v));
|
|
268
|
-
} else {
|
|
269
|
-
headers.set(key, value);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
this._cookies.forEach((cookie) => {
|
|
273
|
-
headers.append("set-cookie", cookie);
|
|
274
|
-
});
|
|
275
|
-
const contentType = headers.get("content-type");
|
|
276
|
-
if (contentType && contentType.includes("text/event-stream")) {
|
|
277
|
-
const stream = new ReadableStream({
|
|
278
|
-
start: (controller) => {
|
|
279
|
-
this._streamController = controller;
|
|
280
|
-
if (this._body.length > 0) {
|
|
281
|
-
for (const chunk of this._body) {
|
|
282
|
-
controller.enqueue(chunk);
|
|
283
|
-
}
|
|
284
|
-
this._body = [];
|
|
285
|
-
}
|
|
286
|
-
if (this._finished) {
|
|
287
|
-
controller.close();
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
cancel: () => {
|
|
291
|
-
this._streamController = void 0;
|
|
292
|
-
this._closed = true;
|
|
293
|
-
this.emit("close");
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
return new Response(stream, {
|
|
297
|
-
status: this._statusCode,
|
|
298
|
-
statusText: this._statusMessage,
|
|
299
|
-
headers
|
|
300
|
-
});
|
|
301
|
-
} else {
|
|
302
|
-
let body = null;
|
|
303
|
-
if (this._body.length > 0) {
|
|
304
|
-
const totalLength = this._body.reduce(
|
|
305
|
-
(sum, chunk) => sum + chunk.length,
|
|
306
|
-
0
|
|
307
|
-
);
|
|
308
|
-
const combined = new Uint8Array(totalLength);
|
|
309
|
-
let offset = 0;
|
|
310
|
-
for (const chunk of this._body) {
|
|
311
|
-
combined.set(chunk, offset);
|
|
312
|
-
offset += chunk.length;
|
|
313
|
-
}
|
|
314
|
-
body = combined;
|
|
315
|
-
}
|
|
316
|
-
return new Response(body, {
|
|
317
|
-
status: this._statusCode,
|
|
318
|
-
statusText: this._statusMessage,
|
|
319
|
-
headers
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// src/utils/IncomingMessageProxy.ts
|
|
326
|
-
var IncomingMessageProxy = class {
|
|
327
|
-
_request;
|
|
328
|
-
_url;
|
|
329
|
-
_body;
|
|
330
|
-
_bodyRead = false;
|
|
331
|
-
_streaming = false;
|
|
332
|
-
_streamEnded = false;
|
|
333
|
-
_streamDestroyed = false;
|
|
334
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
335
|
-
_encoding;
|
|
336
|
-
constructor(request) {
|
|
337
|
-
this._request = request;
|
|
338
|
-
this._url = new URL(request.url);
|
|
339
|
-
}
|
|
340
|
-
// HTTP version (mock)
|
|
341
|
-
get httpVersion() {
|
|
342
|
-
return "1.1";
|
|
343
|
-
}
|
|
344
|
-
get httpVersionMajor() {
|
|
345
|
-
return 1;
|
|
346
|
-
}
|
|
347
|
-
get httpVersionMinor() {
|
|
348
|
-
return 1;
|
|
349
|
-
}
|
|
350
|
-
// Request method
|
|
351
|
-
get method() {
|
|
352
|
-
return this._request.method;
|
|
353
|
-
}
|
|
354
|
-
// URL and path properties
|
|
355
|
-
get url() {
|
|
356
|
-
return this._url.pathname + this._url.search;
|
|
357
|
-
}
|
|
358
|
-
get pathname() {
|
|
359
|
-
return this._url.pathname;
|
|
360
|
-
}
|
|
361
|
-
get search() {
|
|
362
|
-
return this._url.search;
|
|
363
|
-
}
|
|
364
|
-
get query() {
|
|
365
|
-
return this._url.search.slice(1);
|
|
366
|
-
}
|
|
367
|
-
get path() {
|
|
368
|
-
return this._url.pathname + this._url.search;
|
|
369
|
-
}
|
|
370
|
-
// Headers proxy
|
|
371
|
-
get headers() {
|
|
372
|
-
const headers = {};
|
|
373
|
-
this._request.headers.forEach((value, key) => {
|
|
374
|
-
const lowerKey = key.toLowerCase();
|
|
375
|
-
if (headers[lowerKey]) {
|
|
376
|
-
if (Array.isArray(headers[lowerKey])) {
|
|
377
|
-
headers[lowerKey].push(value);
|
|
378
|
-
} else {
|
|
379
|
-
headers[lowerKey] = [headers[lowerKey], value];
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
headers[lowerKey] = value;
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
return headers;
|
|
386
|
-
}
|
|
387
|
-
get rawHeaders() {
|
|
388
|
-
const raw = [];
|
|
389
|
-
this._request.headers.forEach((value, key) => {
|
|
390
|
-
raw.push(key, value);
|
|
391
|
-
});
|
|
392
|
-
return raw;
|
|
393
|
-
}
|
|
394
|
-
// Host and connection info
|
|
395
|
-
get host() {
|
|
396
|
-
return this._url.host;
|
|
397
|
-
}
|
|
398
|
-
get hostname() {
|
|
399
|
-
return this._url.hostname;
|
|
400
|
-
}
|
|
401
|
-
get port() {
|
|
402
|
-
return this._url.port || (this._url.protocol === "https:" ? "443" : "80");
|
|
403
|
-
}
|
|
404
|
-
get protocol() {
|
|
405
|
-
return this._url.protocol;
|
|
406
|
-
}
|
|
407
|
-
// Socket properties (mocked for compatibility)
|
|
408
|
-
get connection() {
|
|
409
|
-
return {
|
|
410
|
-
remoteAddress: this._request.headers.get("cf-connecting-ip") || this._request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || "127.0.0.1",
|
|
411
|
-
remotePort: null,
|
|
412
|
-
localAddress: this._url.hostname,
|
|
413
|
-
localPort: parseInt(this.port),
|
|
414
|
-
encrypted: this._url.protocol === "https:"
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
get socket() {
|
|
418
|
-
return this.connection;
|
|
419
|
-
}
|
|
420
|
-
// Complete flag (always true for Request objects)
|
|
421
|
-
get complete() {
|
|
422
|
-
return true;
|
|
423
|
-
}
|
|
424
|
-
// Readable stream properties
|
|
425
|
-
get readable() {
|
|
426
|
-
return !this._streamEnded && !this._streamDestroyed;
|
|
427
|
-
}
|
|
428
|
-
get readableEnded() {
|
|
429
|
-
return this._streamEnded;
|
|
430
|
-
}
|
|
431
|
-
get destroyed() {
|
|
432
|
-
return this._streamDestroyed;
|
|
433
|
-
}
|
|
434
|
-
// Status code (only available on responses, null for requests)
|
|
435
|
-
get statusCode() {
|
|
436
|
-
return null;
|
|
437
|
-
}
|
|
438
|
-
get statusMessage() {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
// Trailer support (not supported by fetch API)
|
|
442
|
-
get trailers() {
|
|
443
|
-
return {};
|
|
444
|
-
}
|
|
445
|
-
get rawTrailers() {
|
|
446
|
-
return [];
|
|
447
|
-
}
|
|
448
|
-
// Body reading methods
|
|
449
|
-
async read() {
|
|
450
|
-
if (this._bodyRead) {
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
if (!this._body) {
|
|
454
|
-
this._body = await this._request.arrayBuffer();
|
|
455
|
-
}
|
|
456
|
-
this._bodyRead = true;
|
|
457
|
-
return new Uint8Array(this._body);
|
|
458
|
-
}
|
|
459
|
-
async text() {
|
|
460
|
-
if (!this._body) {
|
|
461
|
-
this._body = await this._request.arrayBuffer();
|
|
462
|
-
}
|
|
463
|
-
return new TextDecoder().decode(this._body);
|
|
464
|
-
}
|
|
465
|
-
async json() {
|
|
466
|
-
const text = await this.text();
|
|
467
|
-
return JSON.parse(text);
|
|
468
|
-
}
|
|
469
|
-
async arrayBuffer() {
|
|
470
|
-
if (!this._body) {
|
|
471
|
-
this._body = await this._request.arrayBuffer();
|
|
472
|
-
}
|
|
473
|
-
return this._body;
|
|
474
|
-
}
|
|
475
|
-
// Event emitter methods
|
|
476
|
-
on(event, listener) {
|
|
477
|
-
if (!this._listeners.has(event)) {
|
|
478
|
-
this._listeners.set(event, []);
|
|
479
|
-
}
|
|
480
|
-
this._listeners.get(event).push(listener);
|
|
481
|
-
if (event === "data" && !this._streaming && !this._streamEnded) {
|
|
482
|
-
this._startStreaming();
|
|
483
|
-
}
|
|
484
|
-
return this;
|
|
485
|
-
}
|
|
486
|
-
once(event, listener) {
|
|
487
|
-
const onceWrapper = (...args) => {
|
|
488
|
-
this.off(event, onceWrapper);
|
|
489
|
-
listener(...args);
|
|
490
|
-
};
|
|
491
|
-
return this.on(event, onceWrapper);
|
|
492
|
-
}
|
|
493
|
-
off(event, listener) {
|
|
494
|
-
const listeners = this._listeners.get(event);
|
|
495
|
-
if (listeners) {
|
|
496
|
-
const index = listeners.indexOf(listener);
|
|
497
|
-
if (index !== -1) {
|
|
498
|
-
listeners.splice(index, 1);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return this;
|
|
502
|
-
}
|
|
503
|
-
emit(event, ...args) {
|
|
504
|
-
const listeners = this._listeners.get(event);
|
|
505
|
-
if (listeners && listeners.length > 0) {
|
|
506
|
-
listeners.forEach((listener) => {
|
|
507
|
-
try {
|
|
508
|
-
listener(...args);
|
|
509
|
-
} catch (error) {
|
|
510
|
-
setTimeout(() => this.emit("error", error), 0);
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
addListener(event, listener) {
|
|
518
|
-
return this.on(event, listener);
|
|
519
|
-
}
|
|
520
|
-
removeListener(event, listener) {
|
|
521
|
-
return this.off(event, listener);
|
|
522
|
-
}
|
|
523
|
-
removeAllListeners(event) {
|
|
524
|
-
if (event) {
|
|
525
|
-
this._listeners.delete(event);
|
|
526
|
-
} else {
|
|
527
|
-
this._listeners.clear();
|
|
528
|
-
}
|
|
529
|
-
return this;
|
|
530
|
-
}
|
|
531
|
-
setEncoding(encoding) {
|
|
532
|
-
this._encoding = encoding;
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
pause() {
|
|
536
|
-
return this;
|
|
537
|
-
}
|
|
538
|
-
resume() {
|
|
539
|
-
return this;
|
|
540
|
-
}
|
|
541
|
-
isPaused() {
|
|
542
|
-
return false;
|
|
543
|
-
}
|
|
544
|
-
pipe(destination) {
|
|
545
|
-
return destination;
|
|
546
|
-
}
|
|
547
|
-
unpipe(destination) {
|
|
548
|
-
return this;
|
|
549
|
-
}
|
|
550
|
-
wrap(stream) {
|
|
551
|
-
return this;
|
|
552
|
-
}
|
|
553
|
-
push(chunk, encoding) {
|
|
554
|
-
return false;
|
|
555
|
-
}
|
|
556
|
-
unshift(chunk, encoding) {
|
|
557
|
-
}
|
|
558
|
-
setTimeout(msecs, callback) {
|
|
559
|
-
return this;
|
|
560
|
-
}
|
|
561
|
-
destroy(error) {
|
|
562
|
-
if (this._streamDestroyed) {
|
|
563
|
-
return this;
|
|
564
|
-
}
|
|
565
|
-
this._streamDestroyed = true;
|
|
566
|
-
this._streamEnded = true;
|
|
567
|
-
if (error) {
|
|
568
|
-
this.emit("error", error);
|
|
569
|
-
}
|
|
570
|
-
this.emit("close");
|
|
571
|
-
return this;
|
|
572
|
-
}
|
|
573
|
-
// Utility methods
|
|
574
|
-
header(name) {
|
|
575
|
-
return this.headers[name.toLowerCase()];
|
|
576
|
-
}
|
|
577
|
-
get(name) {
|
|
578
|
-
const header = this.headers[name.toLowerCase()];
|
|
579
|
-
return Array.isArray(header) ? header[0] : header;
|
|
580
|
-
}
|
|
581
|
-
// Private method to start streaming the body
|
|
582
|
-
async _startStreaming() {
|
|
583
|
-
if (this._streaming || this._streamEnded || this._streamDestroyed) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
this._streaming = true;
|
|
587
|
-
try {
|
|
588
|
-
if (!this._request.body) {
|
|
589
|
-
this._streamEnded = true;
|
|
590
|
-
this.emit("end");
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
const reader = this._request.body.getReader();
|
|
594
|
-
while (true) {
|
|
595
|
-
const { done, value } = await reader.read();
|
|
596
|
-
if (this._streamDestroyed) {
|
|
597
|
-
reader.cancel();
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
if (done) {
|
|
601
|
-
this._streamEnded = true;
|
|
602
|
-
this.emit("end");
|
|
603
|
-
break;
|
|
604
|
-
}
|
|
605
|
-
if (value) {
|
|
606
|
-
let chunk = value;
|
|
607
|
-
if (this._encoding) {
|
|
608
|
-
chunk = new TextDecoder(this._encoding).decode(value);
|
|
609
|
-
}
|
|
610
|
-
this.emit("data", chunk);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
} catch (error) {
|
|
614
|
-
this._streamEnded = true;
|
|
615
|
-
this.emit("error", error);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
async function handle(req, env) {
|
|
620
|
-
const transport = new StreamableHTTPServerTransport({
|
|
621
|
-
sessionIdGenerator: void 0,
|
|
622
|
-
enableJsonResponse: true
|
|
623
|
-
});
|
|
624
|
-
const server = await createMCPServer();
|
|
625
|
-
await server.connect(transport);
|
|
626
|
-
const res = new ServerResponseProxy();
|
|
627
|
-
await transport.handleRequest(new IncomingMessageProxy(req), res);
|
|
628
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
629
|
-
return res.toResponse();
|
|
630
|
-
}
|
|
631
|
-
async function createMCPServer(env, req) {
|
|
632
|
-
const server = new McpServer({
|
|
633
|
-
name: "agent-kit",
|
|
634
|
-
version: "1.0.0"
|
|
635
|
-
});
|
|
636
|
-
for (const name in tools) {
|
|
637
|
-
const [description, args, tool] = await tools[name]();
|
|
638
|
-
const v3Args = zodown(args);
|
|
639
|
-
server.tool(
|
|
640
|
-
name,
|
|
641
|
-
description,
|
|
642
|
-
args ? v3Args.shape : {},
|
|
643
|
-
(args2) => {
|
|
644
|
-
const flow = {
|
|
645
|
-
id: "stateless",
|
|
646
|
-
active: {
|
|
647
|
-
tool: "1",
|
|
648
|
-
args: {},
|
|
649
|
-
retries: 0,
|
|
650
|
-
reasons: []
|
|
651
|
-
},
|
|
652
|
-
queue: []
|
|
653
|
-
};
|
|
654
|
-
return tool(flow, args2);
|
|
655
|
-
}
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
return server;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
export { createMCPServer, handle };
|
|
662
|
-
//# sourceMappingURL=mcp.js.map
|
|
663
|
-
//# sourceMappingURL=mcp.js.map
|