@mastra/deployer 0.0.0-a2a-20250421213654
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/LICENSE.md +46 -0
- package/README.md +159 -0
- package/dist/_tsup-dts-rollup.d.cts +548 -0
- package/dist/_tsup-dts-rollup.d.ts +548 -0
- package/dist/build/analyze.cjs +10 -0
- package/dist/build/analyze.d.cts +1 -0
- package/dist/build/analyze.d.ts +1 -0
- package/dist/build/analyze.js +1 -0
- package/dist/build/bundler.cjs +14 -0
- package/dist/build/bundler.d.cts +2 -0
- package/dist/build/bundler.d.ts +2 -0
- package/dist/build/bundler.js +1 -0
- package/dist/build/index.cjs +46 -0
- package/dist/build/index.d.cts +9 -0
- package/dist/build/index.d.ts +9 -0
- package/dist/build/index.js +5 -0
- package/dist/bundler/index.cjs +10 -0
- package/dist/bundler/index.d.cts +1 -0
- package/dist/bundler/index.d.ts +1 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-2ZPQX6BX.cjs +254 -0
- package/dist/chunk-4AYFLP6G.js +227 -0
- package/dist/chunk-4VC5Z4YR.cjs +391 -0
- package/dist/chunk-54KOF3NB.cjs +137 -0
- package/dist/chunk-5QD7CDGY.js +306 -0
- package/dist/chunk-6QMONK4A.cjs +2 -0
- package/dist/chunk-AOSWYZKN.js +138 -0
- package/dist/chunk-C4JT7CIH.js +1 -0
- package/dist/chunk-IMGVLBV7.cjs +149 -0
- package/dist/chunk-KTYDROLB.js +136 -0
- package/dist/chunk-LA6Y6GAB.cjs +312 -0
- package/dist/chunk-Q6OKTZNC.cjs +316 -0
- package/dist/chunk-USZDOFES.js +301 -0
- package/dist/chunk-UV4RQQ3R.js +359 -0
- package/dist/chunk-WVBUOQT6.js +111 -0
- package/dist/chunk-Z7KAM3CZ.cjs +164 -0
- package/dist/index.cjs +190 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +149 -0
- package/dist/server/index.cjs +3952 -0
- package/dist/server/index.d.cts +2 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +3944 -0
- package/dist/services/index.cjs +18 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +1 -0
- package/dist/templates/instrumentation-template.js +89 -0
- package/dist/validator/custom-resolver.cjs +52 -0
- package/dist/validator/custom-resolver.d.cts +1 -0
- package/dist/validator/custom-resolver.d.ts +1 -0
- package/dist/validator/custom-resolver.js +50 -0
- package/dist/validator/loader.cjs +7 -0
- package/dist/validator/loader.d.cts +1 -0
- package/dist/validator/loader.d.ts +1 -0
- package/dist/validator/loader.js +4 -0
- package/package.json +140 -0
|
@@ -0,0 +1,3952 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var promises = require('fs/promises');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var posix = require('path/posix');
|
|
7
|
+
var url = require('url');
|
|
8
|
+
var http = require('http');
|
|
9
|
+
var http2 = require('http2');
|
|
10
|
+
var stream = require('stream');
|
|
11
|
+
var filepath = require('hono/utils/filepath');
|
|
12
|
+
var mime = require('hono/utils/mime');
|
|
13
|
+
var fs = require('fs');
|
|
14
|
+
var html = require('hono/html');
|
|
15
|
+
var core = require('@mastra/core');
|
|
16
|
+
var di = require('@mastra/core/di');
|
|
17
|
+
var hono = require('hono');
|
|
18
|
+
var bodyLimit = require('hono/body-limit');
|
|
19
|
+
var cors = require('hono/cors');
|
|
20
|
+
var logger = require('hono/logger');
|
|
21
|
+
var timeout = require('hono/timeout');
|
|
22
|
+
var httpException = require('hono/http-exception');
|
|
23
|
+
var a2a = require('@mastra/server/handlers/a2a');
|
|
24
|
+
var agents = require('@mastra/server/handlers/agents');
|
|
25
|
+
var logs = require('@mastra/server/handlers/logs');
|
|
26
|
+
var memory = require('@mastra/server/handlers/memory');
|
|
27
|
+
var network = require('@mastra/server/handlers/network');
|
|
28
|
+
var agent = require('@mastra/core/agent');
|
|
29
|
+
var zod = require('zod');
|
|
30
|
+
var telemetry = require('@mastra/server/handlers/telemetry');
|
|
31
|
+
var tools = require('@mastra/server/handlers/tools');
|
|
32
|
+
var vector = require('@mastra/server/handlers/vector');
|
|
33
|
+
var voice = require('@mastra/server/handlers/voice');
|
|
34
|
+
var workflows = require('@mastra/server/handlers/workflows');
|
|
35
|
+
var streaming = require('hono/streaming');
|
|
36
|
+
|
|
37
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
38
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
39
|
+
|
|
40
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
41
|
+
|
|
42
|
+
// src/server/index.ts
|
|
43
|
+
var RequestError = class extends Error {
|
|
44
|
+
static name = "RequestError";
|
|
45
|
+
constructor(message, options) {
|
|
46
|
+
super(message, options);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var toRequestError = (e2) => {
|
|
50
|
+
if (e2 instanceof RequestError) {
|
|
51
|
+
return e2;
|
|
52
|
+
}
|
|
53
|
+
return new RequestError(e2.message, { cause: e2 });
|
|
54
|
+
};
|
|
55
|
+
var GlobalRequest = global.Request;
|
|
56
|
+
var Request = class extends GlobalRequest {
|
|
57
|
+
constructor(input, options) {
|
|
58
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
59
|
+
input = input[getRequestCache]();
|
|
60
|
+
}
|
|
61
|
+
if (typeof options?.body?.getReader !== "undefined") {
|
|
62
|
+
options.duplex ??= "half";
|
|
63
|
+
}
|
|
64
|
+
super(input, options);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var newRequestFromIncoming = (method, url, incoming, abortController) => {
|
|
68
|
+
const headerRecord = [];
|
|
69
|
+
const rawHeaders = incoming.rawHeaders;
|
|
70
|
+
for (let i2 = 0; i2 < rawHeaders.length; i2 += 2) {
|
|
71
|
+
const { [i2]: key, [i2 + 1]: value } = rawHeaders;
|
|
72
|
+
if (key.charCodeAt(0) !== /*:*/
|
|
73
|
+
58) {
|
|
74
|
+
headerRecord.push([key, value]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const init = {
|
|
78
|
+
method,
|
|
79
|
+
headers: headerRecord,
|
|
80
|
+
signal: abortController.signal
|
|
81
|
+
};
|
|
82
|
+
if (method === "TRACE") {
|
|
83
|
+
init.method = "GET";
|
|
84
|
+
const req = new Request(url, init);
|
|
85
|
+
Object.defineProperty(req, "method", {
|
|
86
|
+
get() {
|
|
87
|
+
return "TRACE";
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return req;
|
|
91
|
+
}
|
|
92
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
93
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
94
|
+
init.body = new ReadableStream({
|
|
95
|
+
start(controller) {
|
|
96
|
+
controller.enqueue(incoming.rawBody);
|
|
97
|
+
controller.close();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
init.body = stream.Readable.toWeb(incoming);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return new Request(url, init);
|
|
105
|
+
};
|
|
106
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
107
|
+
var requestCache = Symbol("requestCache");
|
|
108
|
+
var incomingKey = Symbol("incomingKey");
|
|
109
|
+
var urlKey = Symbol("urlKey");
|
|
110
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
111
|
+
var getAbortController = Symbol("getAbortController");
|
|
112
|
+
var requestPrototype = {
|
|
113
|
+
get method() {
|
|
114
|
+
return this[incomingKey].method || "GET";
|
|
115
|
+
},
|
|
116
|
+
get url() {
|
|
117
|
+
return this[urlKey];
|
|
118
|
+
},
|
|
119
|
+
[getAbortController]() {
|
|
120
|
+
this[getRequestCache]();
|
|
121
|
+
return this[abortControllerKey];
|
|
122
|
+
},
|
|
123
|
+
[getRequestCache]() {
|
|
124
|
+
this[abortControllerKey] ||= new AbortController();
|
|
125
|
+
return this[requestCache] ||= newRequestFromIncoming(
|
|
126
|
+
this.method,
|
|
127
|
+
this[urlKey],
|
|
128
|
+
this[incomingKey],
|
|
129
|
+
this[abortControllerKey]
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
[
|
|
134
|
+
"body",
|
|
135
|
+
"bodyUsed",
|
|
136
|
+
"cache",
|
|
137
|
+
"credentials",
|
|
138
|
+
"destination",
|
|
139
|
+
"headers",
|
|
140
|
+
"integrity",
|
|
141
|
+
"mode",
|
|
142
|
+
"redirect",
|
|
143
|
+
"referrer",
|
|
144
|
+
"referrerPolicy",
|
|
145
|
+
"signal",
|
|
146
|
+
"keepalive"
|
|
147
|
+
].forEach((k) => {
|
|
148
|
+
Object.defineProperty(requestPrototype, k, {
|
|
149
|
+
get() {
|
|
150
|
+
return this[getRequestCache]()[k];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
155
|
+
Object.defineProperty(requestPrototype, k, {
|
|
156
|
+
value: function() {
|
|
157
|
+
return this[getRequestCache]()[k]();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
Object.setPrototypeOf(requestPrototype, Request.prototype);
|
|
162
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
163
|
+
const req = Object.create(requestPrototype);
|
|
164
|
+
req[incomingKey] = incoming;
|
|
165
|
+
const host = (incoming instanceof http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
166
|
+
if (!host) {
|
|
167
|
+
throw new RequestError("Missing host header");
|
|
168
|
+
}
|
|
169
|
+
const url = new URL(
|
|
170
|
+
`${incoming instanceof http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
|
|
171
|
+
);
|
|
172
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
|
|
173
|
+
throw new RequestError("Invalid host header");
|
|
174
|
+
}
|
|
175
|
+
req[urlKey] = url.href;
|
|
176
|
+
return req;
|
|
177
|
+
};
|
|
178
|
+
function writeFromReadableStream(stream2, writable) {
|
|
179
|
+
if (stream2.locked) {
|
|
180
|
+
throw new TypeError("ReadableStream is locked.");
|
|
181
|
+
} else if (writable.destroyed) {
|
|
182
|
+
stream2.cancel();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const reader = stream2.getReader();
|
|
186
|
+
writable.on("close", cancel);
|
|
187
|
+
writable.on("error", cancel);
|
|
188
|
+
reader.read().then(flow, cancel);
|
|
189
|
+
return reader.closed.finally(() => {
|
|
190
|
+
writable.off("close", cancel);
|
|
191
|
+
writable.off("error", cancel);
|
|
192
|
+
});
|
|
193
|
+
function cancel(error) {
|
|
194
|
+
reader.cancel(error).catch(() => {
|
|
195
|
+
});
|
|
196
|
+
if (error) {
|
|
197
|
+
writable.destroy(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function onDrain() {
|
|
201
|
+
reader.read().then(flow, cancel);
|
|
202
|
+
}
|
|
203
|
+
function flow({ done, value }) {
|
|
204
|
+
try {
|
|
205
|
+
if (done) {
|
|
206
|
+
writable.end();
|
|
207
|
+
} else if (!writable.write(value)) {
|
|
208
|
+
writable.once("drain", onDrain);
|
|
209
|
+
} else {
|
|
210
|
+
return reader.read().then(flow, cancel);
|
|
211
|
+
}
|
|
212
|
+
} catch (e2) {
|
|
213
|
+
cancel(e2);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
218
|
+
const res = {};
|
|
219
|
+
if (!(headers instanceof Headers)) {
|
|
220
|
+
headers = new Headers(headers ?? void 0);
|
|
221
|
+
}
|
|
222
|
+
const cookies = [];
|
|
223
|
+
for (const [k, v] of headers) {
|
|
224
|
+
if (k === "set-cookie") {
|
|
225
|
+
cookies.push(v);
|
|
226
|
+
} else {
|
|
227
|
+
res[k] = v;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (cookies.length > 0) {
|
|
231
|
+
res["set-cookie"] = cookies;
|
|
232
|
+
}
|
|
233
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
234
|
+
return res;
|
|
235
|
+
};
|
|
236
|
+
var responseCache = Symbol("responseCache");
|
|
237
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
238
|
+
var cacheKey = Symbol("cache");
|
|
239
|
+
var GlobalResponse = global.Response;
|
|
240
|
+
var Response2 = class _Response {
|
|
241
|
+
#body;
|
|
242
|
+
#init;
|
|
243
|
+
[getResponseCache]() {
|
|
244
|
+
delete this[cacheKey];
|
|
245
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
246
|
+
}
|
|
247
|
+
constructor(body, init) {
|
|
248
|
+
this.#body = body;
|
|
249
|
+
if (init instanceof _Response) {
|
|
250
|
+
const cachedGlobalResponse = init[responseCache];
|
|
251
|
+
if (cachedGlobalResponse) {
|
|
252
|
+
this.#init = cachedGlobalResponse;
|
|
253
|
+
this[getResponseCache]();
|
|
254
|
+
return;
|
|
255
|
+
} else {
|
|
256
|
+
this.#init = init.#init;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
this.#init = init;
|
|
260
|
+
}
|
|
261
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined") {
|
|
262
|
+
let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
263
|
+
if (headers instanceof Headers) {
|
|
264
|
+
headers = buildOutgoingHttpHeaders(headers);
|
|
265
|
+
}
|
|
266
|
+
this[cacheKey] = [init?.status || 200, body, headers];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
[
|
|
271
|
+
"body",
|
|
272
|
+
"bodyUsed",
|
|
273
|
+
"headers",
|
|
274
|
+
"ok",
|
|
275
|
+
"redirected",
|
|
276
|
+
"status",
|
|
277
|
+
"statusText",
|
|
278
|
+
"trailers",
|
|
279
|
+
"type",
|
|
280
|
+
"url"
|
|
281
|
+
].forEach((k) => {
|
|
282
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
283
|
+
get() {
|
|
284
|
+
return this[getResponseCache]()[k];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
289
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
290
|
+
value: function() {
|
|
291
|
+
return this[getResponseCache]()[k]();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
296
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
297
|
+
var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
|
|
298
|
+
(k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
|
|
299
|
+
);
|
|
300
|
+
if (!stateKey) {
|
|
301
|
+
console.warn("Failed to find Response internal state key");
|
|
302
|
+
}
|
|
303
|
+
function getInternalBody(response) {
|
|
304
|
+
if (!stateKey) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (response instanceof Response2) {
|
|
308
|
+
response = response[getResponseCache]();
|
|
309
|
+
}
|
|
310
|
+
const state = response[stateKey];
|
|
311
|
+
return state && state.body || void 0;
|
|
312
|
+
}
|
|
313
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
314
|
+
var webFetch = global.fetch;
|
|
315
|
+
if (typeof global.crypto === "undefined") {
|
|
316
|
+
global.crypto = crypto__default.default;
|
|
317
|
+
}
|
|
318
|
+
global.fetch = (info, init) => {
|
|
319
|
+
init = {
|
|
320
|
+
// Disable compression handling so people can return the result of a fetch
|
|
321
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
322
|
+
compress: false,
|
|
323
|
+
...init
|
|
324
|
+
};
|
|
325
|
+
return webFetch(info, init);
|
|
326
|
+
};
|
|
327
|
+
var regBuffer = /^no$/i;
|
|
328
|
+
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
329
|
+
var handleRequestError = () => new Response(null, {
|
|
330
|
+
status: 400
|
|
331
|
+
});
|
|
332
|
+
var handleFetchError = (e2) => new Response(null, {
|
|
333
|
+
status: e2 instanceof Error && (e2.name === "TimeoutError" || e2.constructor.name === "TimeoutError") ? 504 : 500
|
|
334
|
+
});
|
|
335
|
+
var handleResponseError = (e2, outgoing) => {
|
|
336
|
+
const err = e2 instanceof Error ? e2 : new Error("unknown error", { cause: e2 });
|
|
337
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
338
|
+
console.info("The user aborted a request.");
|
|
339
|
+
} else {
|
|
340
|
+
console.error(e2);
|
|
341
|
+
if (!outgoing.headersSent) {
|
|
342
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
343
|
+
}
|
|
344
|
+
outgoing.end(`Error: ${err.message}`);
|
|
345
|
+
outgoing.destroy(err);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var responseViaCache = (res, outgoing) => {
|
|
349
|
+
const [status, body, header] = res[cacheKey];
|
|
350
|
+
if (typeof body === "string") {
|
|
351
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
352
|
+
outgoing.writeHead(status, header);
|
|
353
|
+
outgoing.end(body);
|
|
354
|
+
} else {
|
|
355
|
+
outgoing.writeHead(status, header);
|
|
356
|
+
return writeFromReadableStream(body, outgoing)?.catch(
|
|
357
|
+
(e2) => handleResponseError(e2, outgoing)
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
362
|
+
if (res instanceof Promise) {
|
|
363
|
+
if (options.errorHandler) {
|
|
364
|
+
try {
|
|
365
|
+
res = await res;
|
|
366
|
+
} catch (err) {
|
|
367
|
+
const errRes = await options.errorHandler(err);
|
|
368
|
+
if (!errRes) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
res = errRes;
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
res = await res.catch(handleFetchError);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (cacheKey in res) {
|
|
378
|
+
return responseViaCache(res, outgoing);
|
|
379
|
+
}
|
|
380
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
381
|
+
const internalBody = getInternalBody(res);
|
|
382
|
+
if (internalBody) {
|
|
383
|
+
const { length, source, stream: stream2 } = internalBody;
|
|
384
|
+
if (source instanceof Uint8Array && source.byteLength !== length) ; else {
|
|
385
|
+
if (length) {
|
|
386
|
+
resHeaderRecord["content-length"] = length;
|
|
387
|
+
}
|
|
388
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
389
|
+
if (typeof source === "string" || source instanceof Uint8Array) {
|
|
390
|
+
outgoing.end(source);
|
|
391
|
+
} else if (source instanceof Blob) {
|
|
392
|
+
outgoing.end(new Uint8Array(await source.arrayBuffer()));
|
|
393
|
+
} else {
|
|
394
|
+
await writeFromReadableStream(stream2, outgoing);
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (res.body) {
|
|
400
|
+
const {
|
|
401
|
+
"transfer-encoding": transferEncoding,
|
|
402
|
+
"content-encoding": contentEncoding,
|
|
403
|
+
"content-length": contentLength,
|
|
404
|
+
"x-accel-buffering": accelBuffering,
|
|
405
|
+
"content-type": contentType
|
|
406
|
+
} = resHeaderRecord;
|
|
407
|
+
if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
|
|
408
|
+
accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
|
|
409
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
410
|
+
await writeFromReadableStream(res.body, outgoing);
|
|
411
|
+
} else {
|
|
412
|
+
const buffer = await res.arrayBuffer();
|
|
413
|
+
resHeaderRecord["content-length"] = buffer.byteLength;
|
|
414
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
415
|
+
outgoing.end(new Uint8Array(buffer));
|
|
416
|
+
}
|
|
417
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) ; else {
|
|
418
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
419
|
+
outgoing.end();
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
423
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request) {
|
|
424
|
+
Object.defineProperty(global, "Request", {
|
|
425
|
+
value: Request
|
|
426
|
+
});
|
|
427
|
+
Object.defineProperty(global, "Response", {
|
|
428
|
+
value: Response2
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return async (incoming, outgoing) => {
|
|
432
|
+
let res, req;
|
|
433
|
+
try {
|
|
434
|
+
req = newRequest(incoming, options.hostname);
|
|
435
|
+
outgoing.on("close", () => {
|
|
436
|
+
const abortController = req[abortControllerKey];
|
|
437
|
+
if (!abortController) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (incoming.errored) {
|
|
441
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
442
|
+
} else if (!outgoing.writableFinished) {
|
|
443
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
447
|
+
if (cacheKey in res) {
|
|
448
|
+
return responseViaCache(res, outgoing);
|
|
449
|
+
}
|
|
450
|
+
} catch (e2) {
|
|
451
|
+
if (!res) {
|
|
452
|
+
if (options.errorHandler) {
|
|
453
|
+
res = await options.errorHandler(req ? e2 : toRequestError(e2));
|
|
454
|
+
if (!res) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
} else if (!req) {
|
|
458
|
+
res = handleRequestError();
|
|
459
|
+
} else {
|
|
460
|
+
res = handleFetchError(e2);
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
return handleResponseError(e2, outgoing);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
return responseViaResponseObject(res, outgoing, options);
|
|
468
|
+
} catch (e2) {
|
|
469
|
+
return handleResponseError(e2, outgoing);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
var createAdaptorServer = (options) => {
|
|
474
|
+
const fetchCallback = options.fetch;
|
|
475
|
+
const requestListener = getRequestListener(fetchCallback, {
|
|
476
|
+
hostname: options.hostname,
|
|
477
|
+
overrideGlobalObjects: options.overrideGlobalObjects
|
|
478
|
+
});
|
|
479
|
+
const createServer = options.createServer || http.createServer;
|
|
480
|
+
const server = createServer(options.serverOptions || {}, requestListener);
|
|
481
|
+
return server;
|
|
482
|
+
};
|
|
483
|
+
var serve = (options, listeningListener) => {
|
|
484
|
+
const server = createAdaptorServer(options);
|
|
485
|
+
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
486
|
+
const serverInfo = server.address();
|
|
487
|
+
listeningListener && listeningListener(serverInfo);
|
|
488
|
+
});
|
|
489
|
+
return server;
|
|
490
|
+
};
|
|
491
|
+
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
492
|
+
var ENCODINGS = {
|
|
493
|
+
br: ".br",
|
|
494
|
+
zstd: ".zst",
|
|
495
|
+
gzip: ".gz"
|
|
496
|
+
};
|
|
497
|
+
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
498
|
+
var createStreamBody = (stream2) => {
|
|
499
|
+
const body = new ReadableStream({
|
|
500
|
+
start(controller) {
|
|
501
|
+
stream2.on("data", (chunk) => {
|
|
502
|
+
controller.enqueue(chunk);
|
|
503
|
+
});
|
|
504
|
+
stream2.on("end", () => {
|
|
505
|
+
controller.close();
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
cancel() {
|
|
509
|
+
stream2.destroy();
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
return body;
|
|
513
|
+
};
|
|
514
|
+
var addCurrentDirPrefix = (path) => {
|
|
515
|
+
return `./${path}`;
|
|
516
|
+
};
|
|
517
|
+
var getStats = (path) => {
|
|
518
|
+
let stats;
|
|
519
|
+
try {
|
|
520
|
+
stats = fs.lstatSync(path);
|
|
521
|
+
} catch {
|
|
522
|
+
}
|
|
523
|
+
return stats;
|
|
524
|
+
};
|
|
525
|
+
var serveStatic = (options = { root: "" }) => {
|
|
526
|
+
return async (c2, next) => {
|
|
527
|
+
if (c2.finalized) {
|
|
528
|
+
return next();
|
|
529
|
+
}
|
|
530
|
+
let filename;
|
|
531
|
+
try {
|
|
532
|
+
filename = options.path ?? decodeURIComponent(c2.req.path);
|
|
533
|
+
} catch {
|
|
534
|
+
await options.onNotFound?.(c2.req.path, c2);
|
|
535
|
+
return next();
|
|
536
|
+
}
|
|
537
|
+
let path = filepath.getFilePathWithoutDefaultDocument({
|
|
538
|
+
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
|
|
539
|
+
root: options.root
|
|
540
|
+
});
|
|
541
|
+
if (path) {
|
|
542
|
+
path = addCurrentDirPrefix(path);
|
|
543
|
+
} else {
|
|
544
|
+
return next();
|
|
545
|
+
}
|
|
546
|
+
let stats = getStats(path);
|
|
547
|
+
if (stats && stats.isDirectory()) {
|
|
548
|
+
path = filepath.getFilePath({
|
|
549
|
+
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
|
|
550
|
+
root: options.root,
|
|
551
|
+
defaultDocument: options.index ?? "index.html"
|
|
552
|
+
});
|
|
553
|
+
if (path) {
|
|
554
|
+
path = addCurrentDirPrefix(path);
|
|
555
|
+
} else {
|
|
556
|
+
return next();
|
|
557
|
+
}
|
|
558
|
+
stats = getStats(path);
|
|
559
|
+
}
|
|
560
|
+
if (!stats) {
|
|
561
|
+
await options.onNotFound?.(path, c2);
|
|
562
|
+
return next();
|
|
563
|
+
}
|
|
564
|
+
await options.onFound?.(path, c2);
|
|
565
|
+
const mimeType = mime.getMimeType(path);
|
|
566
|
+
c2.header("Content-Type", mimeType || "application/octet-stream");
|
|
567
|
+
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
568
|
+
const acceptEncodingSet = new Set(
|
|
569
|
+
c2.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
|
|
570
|
+
);
|
|
571
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
572
|
+
if (!acceptEncodingSet.has(encoding)) {
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
576
|
+
if (precompressedStats) {
|
|
577
|
+
c2.header("Content-Encoding", encoding);
|
|
578
|
+
c2.header("Vary", "Accept-Encoding", { append: true });
|
|
579
|
+
stats = precompressedStats;
|
|
580
|
+
path = path + ENCODINGS[encoding];
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
const size = stats.size;
|
|
586
|
+
if (c2.req.method == "HEAD" || c2.req.method == "OPTIONS") {
|
|
587
|
+
c2.header("Content-Length", size.toString());
|
|
588
|
+
c2.status(200);
|
|
589
|
+
return c2.body(null);
|
|
590
|
+
}
|
|
591
|
+
const range = c2.req.header("range") || "";
|
|
592
|
+
if (!range) {
|
|
593
|
+
c2.header("Content-Length", size.toString());
|
|
594
|
+
return c2.body(createStreamBody(fs.createReadStream(path)), 200);
|
|
595
|
+
}
|
|
596
|
+
c2.header("Accept-Ranges", "bytes");
|
|
597
|
+
c2.header("Date", stats.birthtime.toUTCString());
|
|
598
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
599
|
+
const start = parts[0] ? parseInt(parts[0], 10) : 0;
|
|
600
|
+
let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
|
|
601
|
+
if (size < end - start + 1) {
|
|
602
|
+
end = size - 1;
|
|
603
|
+
}
|
|
604
|
+
const chunksize = end - start + 1;
|
|
605
|
+
const stream2 = fs.createReadStream(path, { start, end });
|
|
606
|
+
c2.header("Content-Length", chunksize.toString());
|
|
607
|
+
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
608
|
+
return c2.body(createStreamBody(stream2), 206);
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
var RENDER_TYPE = {
|
|
612
|
+
STRING_ARRAY: "string_array",
|
|
613
|
+
STRING: "string",
|
|
614
|
+
JSON_STRING: "json_string",
|
|
615
|
+
RAW: "raw"
|
|
616
|
+
};
|
|
617
|
+
var RENDER_TYPE_MAP = {
|
|
618
|
+
configUrl: RENDER_TYPE.STRING,
|
|
619
|
+
deepLinking: RENDER_TYPE.RAW,
|
|
620
|
+
presets: RENDER_TYPE.STRING_ARRAY,
|
|
621
|
+
plugins: RENDER_TYPE.STRING_ARRAY,
|
|
622
|
+
spec: RENDER_TYPE.JSON_STRING,
|
|
623
|
+
url: RENDER_TYPE.STRING,
|
|
624
|
+
urls: RENDER_TYPE.JSON_STRING,
|
|
625
|
+
layout: RENDER_TYPE.STRING,
|
|
626
|
+
docExpansion: RENDER_TYPE.STRING,
|
|
627
|
+
maxDisplayedTags: RENDER_TYPE.RAW,
|
|
628
|
+
operationsSorter: RENDER_TYPE.RAW,
|
|
629
|
+
requestInterceptor: RENDER_TYPE.RAW,
|
|
630
|
+
responseInterceptor: RENDER_TYPE.RAW,
|
|
631
|
+
persistAuthorization: RENDER_TYPE.RAW,
|
|
632
|
+
defaultModelsExpandDepth: RENDER_TYPE.RAW,
|
|
633
|
+
defaultModelExpandDepth: RENDER_TYPE.RAW,
|
|
634
|
+
defaultModelRendering: RENDER_TYPE.STRING,
|
|
635
|
+
displayRequestDuration: RENDER_TYPE.RAW,
|
|
636
|
+
filter: RENDER_TYPE.RAW,
|
|
637
|
+
showExtensions: RENDER_TYPE.RAW,
|
|
638
|
+
showCommonExtensions: RENDER_TYPE.RAW,
|
|
639
|
+
queryConfigEnabled: RENDER_TYPE.RAW,
|
|
640
|
+
displayOperationId: RENDER_TYPE.RAW,
|
|
641
|
+
tagsSorter: RENDER_TYPE.RAW,
|
|
642
|
+
onComplete: RENDER_TYPE.RAW,
|
|
643
|
+
syntaxHighlight: RENDER_TYPE.JSON_STRING,
|
|
644
|
+
tryItOutEnabled: RENDER_TYPE.RAW,
|
|
645
|
+
requestSnippetsEnabled: RENDER_TYPE.RAW,
|
|
646
|
+
requestSnippets: RENDER_TYPE.JSON_STRING,
|
|
647
|
+
oauth2RedirectUrl: RENDER_TYPE.STRING,
|
|
648
|
+
showMutabledRequest: RENDER_TYPE.RAW,
|
|
649
|
+
request: RENDER_TYPE.JSON_STRING,
|
|
650
|
+
supportedSubmitMethods: RENDER_TYPE.JSON_STRING,
|
|
651
|
+
validatorUrl: RENDER_TYPE.STRING,
|
|
652
|
+
withCredentials: RENDER_TYPE.RAW,
|
|
653
|
+
modelPropertyMacro: RENDER_TYPE.RAW,
|
|
654
|
+
parameterMacro: RENDER_TYPE.RAW
|
|
655
|
+
};
|
|
656
|
+
var renderSwaggerUIOptions = (options) => {
|
|
657
|
+
const optionsStrings = Object.entries(options).map(([k, v]) => {
|
|
658
|
+
const key = k;
|
|
659
|
+
if (!RENDER_TYPE_MAP[key] || v === void 0) {
|
|
660
|
+
return "";
|
|
661
|
+
}
|
|
662
|
+
switch (RENDER_TYPE_MAP[key]) {
|
|
663
|
+
case RENDER_TYPE.STRING:
|
|
664
|
+
return `${key}: '${v}'`;
|
|
665
|
+
case RENDER_TYPE.STRING_ARRAY:
|
|
666
|
+
if (!Array.isArray(v)) {
|
|
667
|
+
return "";
|
|
668
|
+
}
|
|
669
|
+
return `${key}: [${v.map((ve) => `${ve}`).join(",")}]`;
|
|
670
|
+
case RENDER_TYPE.JSON_STRING:
|
|
671
|
+
return `${key}: ${JSON.stringify(v)}`;
|
|
672
|
+
case RENDER_TYPE.RAW:
|
|
673
|
+
return `${key}: ${v}`;
|
|
674
|
+
default:
|
|
675
|
+
return "";
|
|
676
|
+
}
|
|
677
|
+
}).filter((item) => item !== "").join(",");
|
|
678
|
+
return optionsStrings;
|
|
679
|
+
};
|
|
680
|
+
var remoteAssets = ({ version }) => {
|
|
681
|
+
const url = `https://cdn.jsdelivr.net/npm/swagger-ui-dist${version !== void 0 ? `@${version}` : ""}`;
|
|
682
|
+
return {
|
|
683
|
+
css: [`${url}/swagger-ui.css`],
|
|
684
|
+
js: [`${url}/swagger-ui-bundle.js`]
|
|
685
|
+
};
|
|
686
|
+
};
|
|
687
|
+
var SwaggerUI = (options) => {
|
|
688
|
+
const asset = remoteAssets({ version: options?.version });
|
|
689
|
+
delete options.version;
|
|
690
|
+
if (options.manuallySwaggerUIHtml) {
|
|
691
|
+
return options.manuallySwaggerUIHtml(asset);
|
|
692
|
+
}
|
|
693
|
+
const optionsStrings = renderSwaggerUIOptions(options);
|
|
694
|
+
return `
|
|
695
|
+
<div>
|
|
696
|
+
<div id="swagger-ui"></div>
|
|
697
|
+
${asset.css.map((url) => html.html`<link rel="stylesheet" href="${url}" />`)}
|
|
698
|
+
${asset.js.map((url) => html.html`<script src="${url}" crossorigin="anonymous"></script>`)}
|
|
699
|
+
<script>
|
|
700
|
+
window.onload = () => {
|
|
701
|
+
window.ui = SwaggerUIBundle({
|
|
702
|
+
dom_id: '#swagger-ui',${optionsStrings},
|
|
703
|
+
})
|
|
704
|
+
}
|
|
705
|
+
</script>
|
|
706
|
+
</div>
|
|
707
|
+
`;
|
|
708
|
+
};
|
|
709
|
+
var middleware = (options) => async (c2) => {
|
|
710
|
+
const title = options?.title ?? "SwaggerUI";
|
|
711
|
+
return c2.html(
|
|
712
|
+
/* html */
|
|
713
|
+
`
|
|
714
|
+
<html lang="en">
|
|
715
|
+
<head>
|
|
716
|
+
<meta charset="utf-8" />
|
|
717
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
718
|
+
<meta name="description" content="SwaggerUI" />
|
|
719
|
+
<title>${title}</title>
|
|
720
|
+
</head>
|
|
721
|
+
<body>
|
|
722
|
+
${SwaggerUI(options)}
|
|
723
|
+
</body>
|
|
724
|
+
</html>
|
|
725
|
+
`
|
|
726
|
+
);
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// ../../node_modules/.pnpm/hono-openapi@0.4.6_hono@4.7.4_openapi-types@12.1.3_zod@3.24.3/node_modules/hono-openapi/utils.js
|
|
730
|
+
var e = Symbol("openapi");
|
|
731
|
+
var s2 = ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
732
|
+
var n = (e2) => e2.charAt(0).toUpperCase() + e2.slice(1);
|
|
733
|
+
var o = /* @__PURE__ */ new Map();
|
|
734
|
+
var a = (e2, t2) => {
|
|
735
|
+
const s3 = `${e2}:${t2}`;
|
|
736
|
+
if (o.has(s3)) return o.get(s3);
|
|
737
|
+
let a2 = e2;
|
|
738
|
+
if ("/" === t2) return `${a2}Index`;
|
|
739
|
+
for (const e3 of t2.split("/")) 123 === e3.charCodeAt(0) ? a2 += `By${n(e3.slice(1, -1))}` : a2 += n(e3);
|
|
740
|
+
return o.set(s3, a2), a2;
|
|
741
|
+
};
|
|
742
|
+
var r = /* @__PURE__ */ new Map();
|
|
743
|
+
function c(e2, t2, s3) {
|
|
744
|
+
return e2 && t2 in e2 ? e2[t2] ?? s3 : s3;
|
|
745
|
+
}
|
|
746
|
+
function i(...e2) {
|
|
747
|
+
return e2.reduce((e3, t2) => {
|
|
748
|
+
if (!t2) return e3;
|
|
749
|
+
let s3;
|
|
750
|
+
return ("tags" in e3 && e3.tags || "tags" in t2 && t2.tags) && (s3 = [...c(e3, "tags", []), ...c(t2, "tags", [])]), { ...e3, ...t2, tags: s3, responses: { ...c(e3, "responses", {}), ...c(t2, "responses", {}) }, parameters: m(e3.parameters, t2.parameters) };
|
|
751
|
+
}, {});
|
|
752
|
+
}
|
|
753
|
+
function p({ path: e2, method: t2, data: s3, schema: n2 }) {
|
|
754
|
+
e2 = ((e3) => e3.split("/").map((e4) => {
|
|
755
|
+
let t3 = e4;
|
|
756
|
+
return t3.startsWith(":") && (t3 = t3.slice(1, t3.length), t3.endsWith("?") && (t3 = t3.slice(0, -1)), t3 = `{${t3}}`), t3;
|
|
757
|
+
}).join("/"))(e2);
|
|
758
|
+
const o2 = t2.toLowerCase();
|
|
759
|
+
if ("all" === o2) if (r.has(e2)) {
|
|
760
|
+
const t3 = r.get(e2) ?? {};
|
|
761
|
+
r.set(e2, { ...t3, ...s3, parameters: m(t3.parameters, s3.parameters) });
|
|
762
|
+
} else r.set(e2, s3);
|
|
763
|
+
else {
|
|
764
|
+
const t3 = function(e3) {
|
|
765
|
+
const t4 = Array.from(r.keys());
|
|
766
|
+
let s4 = {};
|
|
767
|
+
for (const n3 of t4) e3.match(n3) && (s4 = i(s4, r.get(n3) ?? {}));
|
|
768
|
+
return s4;
|
|
769
|
+
}(e2);
|
|
770
|
+
n2[e2] = { ...n2[e2] ? n2[e2] : {}, [o2]: { responses: {}, operationId: a(o2, e2), ...i(t3, n2[e2]?.[o2], s3) } };
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
var l = (e2) => "$ref" in e2 ? e2.$ref : `${e2.in} ${e2.name}`;
|
|
774
|
+
function m(...e2) {
|
|
775
|
+
const t2 = e2.flatMap((e3) => e3 ?? []).reduce((e3, t3) => (e3.set(l(t3), t3), e3), /* @__PURE__ */ new Map());
|
|
776
|
+
return Array.from(t2.values());
|
|
777
|
+
}
|
|
778
|
+
function u(e2, { excludeStaticFile: t2 = true, exclude: s3 = [] }) {
|
|
779
|
+
const n2 = {}, o2 = Array.isArray(s3) ? s3 : [s3];
|
|
780
|
+
for (const [s4, a2] of Object.entries(e2)) if (!(o2.some((e3) => "string" == typeof e3 ? s4 === e3 : e3.test(s4)) || s4.includes("*") || t2 && s4.includes("."))) {
|
|
781
|
+
for (const e3 of Object.keys(a2)) {
|
|
782
|
+
const t3 = a2[e3];
|
|
783
|
+
if (s4.includes("{")) {
|
|
784
|
+
t3.parameters || (t3.parameters = []);
|
|
785
|
+
const e4 = s4.split("/").filter((e5) => e5.startsWith("{") && !t3.parameters.find((t4) => "path" === t4.in && t4.name === e5.slice(1, e5.length - 1)));
|
|
786
|
+
for (const s5 of e4) {
|
|
787
|
+
const e5 = s5.slice(1, s5.length - 1), n3 = t3.parameters.findIndex((t4) => "param" === t4.in && t4.name === e5);
|
|
788
|
+
-1 !== n3 ? t3.parameters[n3].in = "path" : t3.parameters.push({ schema: { type: "string" }, in: "path", name: e5, required: true });
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
t3.responses || (t3.responses = { 200: {} });
|
|
792
|
+
}
|
|
793
|
+
n2[s4] = a2;
|
|
794
|
+
}
|
|
795
|
+
return n2;
|
|
796
|
+
}
|
|
797
|
+
function f(e2, t2) {
|
|
798
|
+
const s3 = { version: "3.1.0", components: {} };
|
|
799
|
+
let n2 = null;
|
|
800
|
+
return async (o2) => (n2 || (n2 = await d(e2, t2, s3, o2)), o2.json(n2));
|
|
801
|
+
}
|
|
802
|
+
async function d(t2, { documentation: n2 = {}, excludeStaticFile: o2 = true, exclude: a2 = [], excludeMethods: r2 = ["OPTIONS"], excludeTags: c2 = [], defaultOptions: i2 } = { documentation: {}, excludeStaticFile: true, exclude: [], excludeMethods: ["OPTIONS"], excludeTags: [] }, { version: l2 = "3.1.0", components: m2 = {} } = { version: "3.1.0", components: {} }, f2) {
|
|
803
|
+
const d2 = { version: l2, components: m2 }, h2 = {};
|
|
804
|
+
for (const n3 of t2.routes) {
|
|
805
|
+
if (!(e in n3.handler)) continue;
|
|
806
|
+
if (r2.includes(n3.method)) continue;
|
|
807
|
+
if (false === s2.includes(n3.method) && "ALL" !== n3.method) continue;
|
|
808
|
+
const { resolver: t3, metadata: o3 = {} } = n3.handler[e], a3 = i2?.[n3.method], { docs: c3, components: l3 } = await t3({ ...d2, ...o3 }, a3);
|
|
809
|
+
d2.components = { ...d2.components, ...l3 ?? {} }, p({ method: n3.method, path: n3.path, data: c3, schema: h2 });
|
|
810
|
+
}
|
|
811
|
+
for (const e2 in h2) for (const t3 in h2[e2]) {
|
|
812
|
+
const s3 = h2[e2][t3]?.hide;
|
|
813
|
+
s3 && ("boolean" == typeof s3 ? s3 : f2 && s3(f2)) && delete h2[e2][t3];
|
|
814
|
+
}
|
|
815
|
+
return { openapi: d2.version, ...{ ...n2, tags: n2.tags?.filter((e2) => !c2?.includes(e2?.name)), info: { title: "Hono Documentation", description: "Development documentation", version: "0.0.0", ...n2.info }, paths: { ...u(h2, { excludeStaticFile: o2, exclude: a2 }), ...n2.paths }, components: { ...n2.components, schemas: { ...d2.components, ...n2.components?.schemas } } } };
|
|
816
|
+
}
|
|
817
|
+
function h(s3) {
|
|
818
|
+
const { validateResponse: n2, ...o2 } = s3;
|
|
819
|
+
return Object.assign(async (e2, o3) => {
|
|
820
|
+
if (await o3(), n2 && s3.responses) {
|
|
821
|
+
const o4 = e2.res.status, a2 = e2.res.headers.get("content-type");
|
|
822
|
+
if (o4 && a2) {
|
|
823
|
+
const r2 = s3.responses[o4];
|
|
824
|
+
if (r2 && "content" in r2 && r2.content) {
|
|
825
|
+
const s4 = a2.split(";")[0], o5 = r2.content[s4];
|
|
826
|
+
if (o5?.schema && "validator" in o5.schema) try {
|
|
827
|
+
let t2;
|
|
828
|
+
const n3 = e2.res.clone();
|
|
829
|
+
if ("application/json" === s4 ? t2 = await n3.json() : "text/plain" === s4 && (t2 = await n3.text()), !t2) throw new Error("No data to validate!");
|
|
830
|
+
await o5.schema.validator(t2);
|
|
831
|
+
} catch (e3) {
|
|
832
|
+
let s5 = { status: 500, message: "Response validation failed!" };
|
|
833
|
+
throw "object" == typeof n2 && (s5 = { ...s5, ...n2 }), new httpException.HTTPException(s5.status, { message: s5.message, cause: e3 });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}, { [e]: { resolver: (e2, t2) => x(e2, o2, t2) } });
|
|
839
|
+
}
|
|
840
|
+
async function x(e2, t2, s3 = {}) {
|
|
841
|
+
let n2 = {};
|
|
842
|
+
const o2 = { ...s3, ...t2, responses: { ...s3?.responses, ...t2.responses } };
|
|
843
|
+
if (o2.responses) for (const t3 of Object.keys(o2.responses)) {
|
|
844
|
+
const s4 = o2.responses[t3];
|
|
845
|
+
if (s4 && "content" in s4) for (const t4 of Object.keys(s4.content ?? {})) {
|
|
846
|
+
const o3 = s4.content?.[t4];
|
|
847
|
+
if (o3 && (o3.schema && "builder" in o3.schema)) {
|
|
848
|
+
const t5 = await o3.schema.builder(e2);
|
|
849
|
+
o3.schema = t5.schema, t5.components && (n2 = { ...n2, ...t5.components });
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return { docs: o2, components: n2 };
|
|
854
|
+
}
|
|
855
|
+
function handleError(error, defaultMessage) {
|
|
856
|
+
const apiError = error;
|
|
857
|
+
throw new httpException.HTTPException(apiError.status || 500, {
|
|
858
|
+
message: apiError.message || defaultMessage
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
function errorHandler(err, c2) {
|
|
862
|
+
if (err instanceof httpException.HTTPException) {
|
|
863
|
+
return c2.json({ error: err.message }, err.status);
|
|
864
|
+
}
|
|
865
|
+
console.error(err);
|
|
866
|
+
return c2.json({ error: "Internal Server Error" }, 500);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// src/server/handlers/a2a.ts
|
|
870
|
+
async function handleA2ARequestEndpoint(c2) {
|
|
871
|
+
try {
|
|
872
|
+
const mastra = c2.get("mastra");
|
|
873
|
+
const agents = mastra.getAgents();
|
|
874
|
+
const agent = Object.values(agents)[0];
|
|
875
|
+
if (!agent) {
|
|
876
|
+
return c2.json(
|
|
877
|
+
{
|
|
878
|
+
jsonrpc: "2.0",
|
|
879
|
+
id: null,
|
|
880
|
+
error: {
|
|
881
|
+
code: -32603,
|
|
882
|
+
message: "No agent available"
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
500
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
const body = await c2.req.json();
|
|
889
|
+
const response = await a2a.handleA2ARequest({ request: body, agent });
|
|
890
|
+
return c2.json(response);
|
|
891
|
+
} catch (error) {
|
|
892
|
+
return handleError(error, "Error handling A2A request");
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
async function handleAgentCardEndpoint(c2) {
|
|
896
|
+
try {
|
|
897
|
+
const mastra = c2.get("mastra");
|
|
898
|
+
const agents = mastra.getAgents();
|
|
899
|
+
const agent = Object.values(agents)[0];
|
|
900
|
+
if (!agent) {
|
|
901
|
+
return c2.json({ error: "No agent available" }, 500);
|
|
902
|
+
}
|
|
903
|
+
const baseUrl = `${c2.req.url.split("/api/")[0]}`;
|
|
904
|
+
const agentCard = a2a.handleAgentCardRequest({ agent, baseUrl });
|
|
905
|
+
return c2.json(agentCard);
|
|
906
|
+
} catch (error) {
|
|
907
|
+
return handleError(error, "Error handling agent card request");
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
async function getAgentsHandler(c2) {
|
|
911
|
+
const serializedAgents = await agents.getAgentsHandler({ mastra: c2.get("mastra") });
|
|
912
|
+
return c2.json(serializedAgents);
|
|
913
|
+
}
|
|
914
|
+
async function getAgentByIdHandler(c2) {
|
|
915
|
+
const mastra = c2.get("mastra");
|
|
916
|
+
const agentId = c2.req.param("agentId");
|
|
917
|
+
const result = await agents.getAgentByIdHandler({
|
|
918
|
+
mastra,
|
|
919
|
+
agentId
|
|
920
|
+
});
|
|
921
|
+
return c2.json(result);
|
|
922
|
+
}
|
|
923
|
+
async function getEvalsByAgentIdHandler(c2) {
|
|
924
|
+
const mastra = c2.get("mastra");
|
|
925
|
+
const agentId = c2.req.param("agentId");
|
|
926
|
+
const result = await agents.getEvalsByAgentIdHandler({
|
|
927
|
+
mastra,
|
|
928
|
+
agentId
|
|
929
|
+
});
|
|
930
|
+
return c2.json(result);
|
|
931
|
+
}
|
|
932
|
+
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
933
|
+
const mastra = c2.get("mastra");
|
|
934
|
+
const agentId = c2.req.param("agentId");
|
|
935
|
+
const result = await agents.getLiveEvalsByAgentIdHandler({
|
|
936
|
+
mastra,
|
|
937
|
+
agentId
|
|
938
|
+
});
|
|
939
|
+
return c2.json(result);
|
|
940
|
+
}
|
|
941
|
+
async function generateHandler(c2) {
|
|
942
|
+
try {
|
|
943
|
+
const mastra = c2.get("mastra");
|
|
944
|
+
const agentId = c2.req.param("agentId");
|
|
945
|
+
const container = c2.get("container");
|
|
946
|
+
const body = await c2.req.json();
|
|
947
|
+
const result = await agents.generateHandler({
|
|
948
|
+
mastra,
|
|
949
|
+
agentId,
|
|
950
|
+
container,
|
|
951
|
+
body
|
|
952
|
+
});
|
|
953
|
+
return c2.json(result);
|
|
954
|
+
} catch (error) {
|
|
955
|
+
return handleError(error, "Error generating from agent");
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
async function streamGenerateHandler(c2) {
|
|
959
|
+
try {
|
|
960
|
+
const mastra = c2.get("mastra");
|
|
961
|
+
const agentId = c2.req.param("agentId");
|
|
962
|
+
const container = c2.get("container");
|
|
963
|
+
const body = await c2.req.json();
|
|
964
|
+
const streamResponse = await agents.streamGenerateHandler({
|
|
965
|
+
mastra,
|
|
966
|
+
agentId,
|
|
967
|
+
container,
|
|
968
|
+
body
|
|
969
|
+
});
|
|
970
|
+
return streamResponse;
|
|
971
|
+
} catch (error) {
|
|
972
|
+
return handleError(error, "Error streaming from agent");
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
async function setAgentInstructionsHandler(c2) {
|
|
976
|
+
try {
|
|
977
|
+
const isPlayground = c2.get("playground") === true;
|
|
978
|
+
if (!isPlayground) {
|
|
979
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
980
|
+
}
|
|
981
|
+
const agentId = c2.req.param("agentId");
|
|
982
|
+
const { instructions } = await c2.req.json();
|
|
983
|
+
if (!agentId || !instructions) {
|
|
984
|
+
return c2.json({ error: "Missing required fields" }, 400);
|
|
985
|
+
}
|
|
986
|
+
const mastra = c2.get("mastra");
|
|
987
|
+
const agent = mastra.getAgent(agentId);
|
|
988
|
+
if (!agent) {
|
|
989
|
+
return c2.json({ error: "Agent not found" }, 404);
|
|
990
|
+
}
|
|
991
|
+
agent.__updateInstructions(instructions);
|
|
992
|
+
return c2.json(
|
|
993
|
+
{
|
|
994
|
+
instructions
|
|
995
|
+
},
|
|
996
|
+
200
|
|
997
|
+
);
|
|
998
|
+
} catch (error) {
|
|
999
|
+
return handleError(error, "Error setting agent instructions");
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// src/server/handlers/client.ts
|
|
1004
|
+
var clients = /* @__PURE__ */ new Set();
|
|
1005
|
+
function handleClientsRefresh(c2) {
|
|
1006
|
+
const stream2 = new ReadableStream({
|
|
1007
|
+
start(controller) {
|
|
1008
|
+
clients.add(controller);
|
|
1009
|
+
controller.enqueue("data: connected\n\n");
|
|
1010
|
+
c2.req.raw.signal.addEventListener("abort", () => {
|
|
1011
|
+
clients.delete(controller);
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
return new Response(stream2, {
|
|
1016
|
+
headers: {
|
|
1017
|
+
"Content-Type": "text/event-stream",
|
|
1018
|
+
"Cache-Control": "no-cache",
|
|
1019
|
+
Connection: "keep-alive",
|
|
1020
|
+
"Access-Control-Allow-Origin": "*"
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
function handleTriggerClientsRefresh(c2) {
|
|
1025
|
+
clients.forEach((controller) => {
|
|
1026
|
+
try {
|
|
1027
|
+
controller.enqueue("data: refresh\n\n");
|
|
1028
|
+
} catch {
|
|
1029
|
+
clients.delete(controller);
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
return c2.json({ success: true, clients: clients.size });
|
|
1033
|
+
}
|
|
1034
|
+
async function getLogsHandler(c2) {
|
|
1035
|
+
try {
|
|
1036
|
+
const mastra = c2.get("mastra");
|
|
1037
|
+
const transportId = c2.req.query("transportId");
|
|
1038
|
+
const logs$1 = await logs.getLogsHandler({
|
|
1039
|
+
mastra,
|
|
1040
|
+
transportId
|
|
1041
|
+
});
|
|
1042
|
+
return c2.json(logs$1);
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
return handleError(error, "Error getting logs");
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
async function getLogsByRunIdHandler(c2) {
|
|
1048
|
+
try {
|
|
1049
|
+
const mastra = c2.get("mastra");
|
|
1050
|
+
const runId = c2.req.param("runId");
|
|
1051
|
+
const transportId = c2.req.query("transportId");
|
|
1052
|
+
const logs$1 = await logs.getLogsByRunIdHandler({
|
|
1053
|
+
mastra,
|
|
1054
|
+
runId,
|
|
1055
|
+
transportId
|
|
1056
|
+
});
|
|
1057
|
+
return c2.json(logs$1);
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
return handleError(error, "Error getting logs by run ID");
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
async function getLogTransports(c2) {
|
|
1063
|
+
try {
|
|
1064
|
+
const mastra = c2.get("mastra");
|
|
1065
|
+
const result = await logs.getLogTransports({
|
|
1066
|
+
mastra
|
|
1067
|
+
});
|
|
1068
|
+
return c2.json(result);
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
return handleError(error, "Error getting log Transports");
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
async function getMemoryStatusHandler(c2) {
|
|
1074
|
+
try {
|
|
1075
|
+
const mastra = c2.get("mastra");
|
|
1076
|
+
const agentId = c2.req.query("agentId");
|
|
1077
|
+
const result = await memory.getMemoryStatusHandler({
|
|
1078
|
+
mastra,
|
|
1079
|
+
agentId
|
|
1080
|
+
});
|
|
1081
|
+
return c2.json(result);
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
return handleError(error, "Error getting memory status");
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async function getThreadsHandler(c2) {
|
|
1087
|
+
try {
|
|
1088
|
+
const mastra = c2.get("mastra");
|
|
1089
|
+
const agentId = c2.req.query("agentId");
|
|
1090
|
+
const resourceId = c2.req.query("resourceid");
|
|
1091
|
+
const result = await memory.getThreadsHandler({
|
|
1092
|
+
mastra,
|
|
1093
|
+
agentId,
|
|
1094
|
+
resourceId
|
|
1095
|
+
});
|
|
1096
|
+
return c2.json(result);
|
|
1097
|
+
} catch (error) {
|
|
1098
|
+
return handleError(error, "Error getting threads");
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async function getThreadByIdHandler(c2) {
|
|
1102
|
+
try {
|
|
1103
|
+
const mastra = c2.get("mastra");
|
|
1104
|
+
const agentId = c2.req.query("agentId");
|
|
1105
|
+
const threadId = c2.req.param("threadId");
|
|
1106
|
+
const result = await memory.getThreadByIdHandler({
|
|
1107
|
+
mastra,
|
|
1108
|
+
agentId,
|
|
1109
|
+
threadId
|
|
1110
|
+
});
|
|
1111
|
+
return c2.json(result);
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
return handleError(error, "Error getting thread");
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
async function saveMessagesHandler(c2) {
|
|
1117
|
+
try {
|
|
1118
|
+
const mastra = c2.get("mastra");
|
|
1119
|
+
const agentId = c2.req.query("agentId");
|
|
1120
|
+
const body = await c2.req.json();
|
|
1121
|
+
const result = await memory.saveMessagesHandler({
|
|
1122
|
+
mastra,
|
|
1123
|
+
agentId,
|
|
1124
|
+
body
|
|
1125
|
+
});
|
|
1126
|
+
return c2.json(result);
|
|
1127
|
+
} catch (error) {
|
|
1128
|
+
return handleError(error, "Error saving messages");
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
async function createThreadHandler(c2) {
|
|
1132
|
+
try {
|
|
1133
|
+
const mastra = c2.get("mastra");
|
|
1134
|
+
const agentId = c2.req.query("agentId");
|
|
1135
|
+
const body = await c2.req.json();
|
|
1136
|
+
const result = await memory.createThreadHandler({
|
|
1137
|
+
mastra,
|
|
1138
|
+
agentId,
|
|
1139
|
+
body
|
|
1140
|
+
});
|
|
1141
|
+
return c2.json(result);
|
|
1142
|
+
} catch (error) {
|
|
1143
|
+
return handleError(error, "Error saving thread to memory");
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
async function updateThreadHandler(c2) {
|
|
1147
|
+
try {
|
|
1148
|
+
const mastra = c2.get("mastra");
|
|
1149
|
+
const agentId = c2.req.query("agentId");
|
|
1150
|
+
const threadId = c2.req.param("threadId");
|
|
1151
|
+
const body = await c2.req.json();
|
|
1152
|
+
const result = await memory.updateThreadHandler({
|
|
1153
|
+
mastra,
|
|
1154
|
+
agentId,
|
|
1155
|
+
threadId,
|
|
1156
|
+
body
|
|
1157
|
+
});
|
|
1158
|
+
return c2.json(result);
|
|
1159
|
+
} catch (error) {
|
|
1160
|
+
return handleError(error, "Error updating thread");
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
async function deleteThreadHandler(c2) {
|
|
1164
|
+
try {
|
|
1165
|
+
const mastra = c2.get("mastra");
|
|
1166
|
+
const agentId = c2.req.query("agentId");
|
|
1167
|
+
const threadId = c2.req.param("threadId");
|
|
1168
|
+
const result = await memory.deleteThreadHandler({
|
|
1169
|
+
mastra,
|
|
1170
|
+
agentId,
|
|
1171
|
+
threadId
|
|
1172
|
+
});
|
|
1173
|
+
return c2.json(result);
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
return handleError(error, "Error deleting thread");
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
async function getMessagesHandler(c2) {
|
|
1179
|
+
try {
|
|
1180
|
+
const mastra = c2.get("mastra");
|
|
1181
|
+
const agentId = c2.req.query("agentId");
|
|
1182
|
+
const threadId = c2.req.param("threadId");
|
|
1183
|
+
const result = await memory.getMessagesHandler({
|
|
1184
|
+
mastra,
|
|
1185
|
+
agentId,
|
|
1186
|
+
threadId
|
|
1187
|
+
});
|
|
1188
|
+
return c2.json(result);
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
return handleError(error, "Error getting messages");
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
async function getNetworksHandler(c2) {
|
|
1194
|
+
try {
|
|
1195
|
+
const mastra = c2.get("mastra");
|
|
1196
|
+
const networks = await network.getNetworksHandler({
|
|
1197
|
+
mastra
|
|
1198
|
+
});
|
|
1199
|
+
return c2.json(networks);
|
|
1200
|
+
} catch (error) {
|
|
1201
|
+
return handleError(error, "Error getting networks");
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
async function getNetworkByIdHandler(c2) {
|
|
1205
|
+
try {
|
|
1206
|
+
const mastra = c2.get("mastra");
|
|
1207
|
+
const networkId = c2.req.param("networkId");
|
|
1208
|
+
const network$1 = await network.getNetworkByIdHandler({
|
|
1209
|
+
mastra,
|
|
1210
|
+
networkId
|
|
1211
|
+
});
|
|
1212
|
+
return c2.json(network$1);
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
return handleError(error, "Error getting network by ID");
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
async function generateHandler2(c2) {
|
|
1218
|
+
try {
|
|
1219
|
+
const mastra = c2.get("mastra");
|
|
1220
|
+
const container = c2.get("container");
|
|
1221
|
+
const networkId = c2.req.param("networkId");
|
|
1222
|
+
const body = await c2.req.json();
|
|
1223
|
+
const result = await network.generateHandler({
|
|
1224
|
+
mastra,
|
|
1225
|
+
container,
|
|
1226
|
+
networkId,
|
|
1227
|
+
body
|
|
1228
|
+
});
|
|
1229
|
+
return c2.json(result);
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
return handleError(error, "Error generating from network");
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
async function streamGenerateHandler2(c2) {
|
|
1235
|
+
try {
|
|
1236
|
+
const mastra = c2.get("mastra");
|
|
1237
|
+
const container = c2.get("container");
|
|
1238
|
+
const networkId = c2.req.param("networkId");
|
|
1239
|
+
const body = await c2.req.json();
|
|
1240
|
+
const streamResponse = await network.streamGenerateHandler({
|
|
1241
|
+
mastra,
|
|
1242
|
+
container,
|
|
1243
|
+
networkId,
|
|
1244
|
+
body
|
|
1245
|
+
});
|
|
1246
|
+
return streamResponse;
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
return handleError(error, "Error streaming from network");
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
async function generateSystemPromptHandler(c2) {
|
|
1252
|
+
try {
|
|
1253
|
+
const agentId = c2.req.param("agentId");
|
|
1254
|
+
const isPlayground = c2.get("playground") === true;
|
|
1255
|
+
if (!isPlayground) {
|
|
1256
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
1257
|
+
}
|
|
1258
|
+
const { instructions, comment } = await c2.req.json();
|
|
1259
|
+
if (!instructions) {
|
|
1260
|
+
return c2.json({ error: "Missing instructions in request body" }, 400);
|
|
1261
|
+
}
|
|
1262
|
+
const mastra = c2.get("mastra");
|
|
1263
|
+
const agent$1 = mastra.getAgent(agentId);
|
|
1264
|
+
if (!agent$1) {
|
|
1265
|
+
return c2.json({ error: "Agent not found" }, 404);
|
|
1266
|
+
}
|
|
1267
|
+
let evalSummary = "";
|
|
1268
|
+
try {
|
|
1269
|
+
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "test") || [];
|
|
1270
|
+
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "live") || [];
|
|
1271
|
+
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
1272
|
+
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
1273
|
+
);
|
|
1274
|
+
evalSummary = evalsMapped.map(
|
|
1275
|
+
({ input, output, result: result2 }) => `
|
|
1276
|
+
Input: ${input}
|
|
1277
|
+
|
|
1278
|
+
Output: ${output}
|
|
1279
|
+
|
|
1280
|
+
Result: ${JSON.stringify(result2)}
|
|
1281
|
+
|
|
1282
|
+
`
|
|
1283
|
+
).join("");
|
|
1284
|
+
} catch (error) {
|
|
1285
|
+
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
1286
|
+
}
|
|
1287
|
+
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
1288
|
+
You are an expert system prompt engineer, specialized in analyzing and enhancing instructions to create clear, effective, and comprehensive system prompts. Your goal is to help users transform their basic instructions into well-structured system prompts that will guide AI behavior effectively.
|
|
1289
|
+
Follow these steps to analyze and enhance the instructions:
|
|
1290
|
+
1. ANALYSIS PHASE
|
|
1291
|
+
- Identify the core purpose and goals
|
|
1292
|
+
- Extract key constraints and requirements
|
|
1293
|
+
- Recognize domain-specific terminology and concepts
|
|
1294
|
+
- Note any implicit assumptions that should be made explicit
|
|
1295
|
+
2. PROMPT STRUCTURE
|
|
1296
|
+
Create a system prompt with these components:
|
|
1297
|
+
a) ROLE DEFINITION
|
|
1298
|
+
- Clear statement of the AI's role and purpose
|
|
1299
|
+
- Key responsibilities and scope
|
|
1300
|
+
- Primary stakeholders and users
|
|
1301
|
+
b) CORE CAPABILITIES
|
|
1302
|
+
- Main functions and abilities
|
|
1303
|
+
- Specific domain knowledge required
|
|
1304
|
+
- Tools and resources available
|
|
1305
|
+
c) BEHAVIORAL GUIDELINES
|
|
1306
|
+
- Communication style and tone
|
|
1307
|
+
- Decision-making framework
|
|
1308
|
+
- Error handling approach
|
|
1309
|
+
- Ethical considerations
|
|
1310
|
+
d) CONSTRAINTS & BOUNDARIES
|
|
1311
|
+
- Explicit limitations
|
|
1312
|
+
- Out-of-scope activities
|
|
1313
|
+
- Security and privacy considerations
|
|
1314
|
+
e) SUCCESS CRITERIA
|
|
1315
|
+
- Quality standards
|
|
1316
|
+
- Expected outcomes
|
|
1317
|
+
- Performance metrics
|
|
1318
|
+
3. QUALITY CHECKS
|
|
1319
|
+
Ensure the prompt is:
|
|
1320
|
+
- Clear and unambiguous
|
|
1321
|
+
- Comprehensive yet concise
|
|
1322
|
+
- Properly scoped
|
|
1323
|
+
- Technically accurate
|
|
1324
|
+
- Ethically sound
|
|
1325
|
+
4. OUTPUT FORMAT
|
|
1326
|
+
Return a structured response with:
|
|
1327
|
+
- Enhanced system prompt
|
|
1328
|
+
- Analysis of key components
|
|
1329
|
+
- Identified goals and constraints
|
|
1330
|
+
- Core domain concepts
|
|
1331
|
+
Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
|
|
1332
|
+
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
1333
|
+
`;
|
|
1334
|
+
const systemPromptAgent = new agent.Agent({
|
|
1335
|
+
name: "system-prompt-enhancer",
|
|
1336
|
+
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
1337
|
+
model: agent$1.llm?.getModel()
|
|
1338
|
+
});
|
|
1339
|
+
const result = await systemPromptAgent.generate(
|
|
1340
|
+
`
|
|
1341
|
+
We need to improve the system prompt.
|
|
1342
|
+
Current: ${instructions}
|
|
1343
|
+
${comment ? `User feedback: ${comment}` : ""}
|
|
1344
|
+
${evalSummary ? `
|
|
1345
|
+
Evaluation Results:
|
|
1346
|
+
${evalSummary}` : ""}
|
|
1347
|
+
`,
|
|
1348
|
+
{
|
|
1349
|
+
output: zod.z.object({
|
|
1350
|
+
new_prompt: zod.z.string(),
|
|
1351
|
+
explanation: zod.z.string()
|
|
1352
|
+
})
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
return c2.json(result?.object || {});
|
|
1356
|
+
} catch (error) {
|
|
1357
|
+
return handleError(error, "Error generating system prompt");
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// src/server/handlers/root.ts
|
|
1362
|
+
async function rootHandler(c2) {
|
|
1363
|
+
return c2.text("Hello to the Mastra API!");
|
|
1364
|
+
}
|
|
1365
|
+
async function getTelemetryHandler(c2) {
|
|
1366
|
+
try {
|
|
1367
|
+
const mastra = c2.get("mastra");
|
|
1368
|
+
const { name, scope, page, perPage } = c2.req.query();
|
|
1369
|
+
const attribute = c2.req.queries("attribute");
|
|
1370
|
+
const traces = await telemetry.getTelemetryHandler({
|
|
1371
|
+
mastra,
|
|
1372
|
+
body: { name, scope, page: Number(page ?? 0), perPage: Number(perPage ?? 100), attribute }
|
|
1373
|
+
});
|
|
1374
|
+
return c2.json({ traces });
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
return handleError(error, "Error getting telemetry traces");
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
async function storeTelemetryHandler(c2) {
|
|
1380
|
+
try {
|
|
1381
|
+
const body = await c2.req.json();
|
|
1382
|
+
const mastra = c2.get("mastra");
|
|
1383
|
+
const result = await telemetry.storeTelemetryHandler({ mastra, body });
|
|
1384
|
+
if (result.status === "error") {
|
|
1385
|
+
return c2.json(result, 500);
|
|
1386
|
+
}
|
|
1387
|
+
return c2.json(result, 200);
|
|
1388
|
+
} catch (error) {
|
|
1389
|
+
return handleError(error, "Error storing telemetry traces");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
async function getToolsHandler(c2) {
|
|
1393
|
+
try {
|
|
1394
|
+
const tools$1 = c2.get("tools");
|
|
1395
|
+
const result = await tools.getToolsHandler({
|
|
1396
|
+
tools: tools$1
|
|
1397
|
+
});
|
|
1398
|
+
return c2.json(result);
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
return handleError(error, "Error getting tools");
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
async function getToolByIdHandler(c2) {
|
|
1404
|
+
try {
|
|
1405
|
+
const tools$1 = c2.get("tools");
|
|
1406
|
+
const toolId = c2.req.param("toolId");
|
|
1407
|
+
const result = await tools.getToolByIdHandler({
|
|
1408
|
+
tools: tools$1,
|
|
1409
|
+
toolId
|
|
1410
|
+
});
|
|
1411
|
+
return c2.json(result);
|
|
1412
|
+
} catch (error) {
|
|
1413
|
+
return handleError(error, "Error getting tool");
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
function executeToolHandler(tools$1) {
|
|
1417
|
+
return async (c2) => {
|
|
1418
|
+
try {
|
|
1419
|
+
const mastra = c2.get("mastra");
|
|
1420
|
+
const container = c2.get("container");
|
|
1421
|
+
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
1422
|
+
const { data } = await c2.req.json();
|
|
1423
|
+
const result = await tools.executeToolHandler(tools$1)({
|
|
1424
|
+
mastra,
|
|
1425
|
+
toolId,
|
|
1426
|
+
data,
|
|
1427
|
+
container
|
|
1428
|
+
});
|
|
1429
|
+
return c2.json(result);
|
|
1430
|
+
} catch (error) {
|
|
1431
|
+
return handleError(error, "Error executing tool");
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
async function executeAgentToolHandler(c2) {
|
|
1436
|
+
try {
|
|
1437
|
+
const mastra = c2.get("mastra");
|
|
1438
|
+
const container = c2.get("container");
|
|
1439
|
+
const agentId = c2.req.param("agentId");
|
|
1440
|
+
const toolId = c2.req.param("toolId");
|
|
1441
|
+
const { data } = await c2.req.json();
|
|
1442
|
+
const result = await tools.executeAgentToolHandler({
|
|
1443
|
+
mastra,
|
|
1444
|
+
agentId,
|
|
1445
|
+
toolId,
|
|
1446
|
+
data,
|
|
1447
|
+
container
|
|
1448
|
+
});
|
|
1449
|
+
return c2.json(result);
|
|
1450
|
+
} catch (error) {
|
|
1451
|
+
return handleError(error, "Error executing tool");
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
async function upsertVectors(c2) {
|
|
1455
|
+
try {
|
|
1456
|
+
const mastra = c2.get("mastra");
|
|
1457
|
+
const vectorName = c2.req.param("vectorName");
|
|
1458
|
+
const body = await c2.req.json();
|
|
1459
|
+
const result = await vector.upsertVectors({
|
|
1460
|
+
mastra,
|
|
1461
|
+
vectorName,
|
|
1462
|
+
index: body
|
|
1463
|
+
});
|
|
1464
|
+
return c2.json({ ids: result });
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
return handleError(error, "Error upserting vectors");
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
async function createIndex(c2) {
|
|
1470
|
+
try {
|
|
1471
|
+
const mastra = c2.get("mastra");
|
|
1472
|
+
const vectorName = c2.req.param("vectorName");
|
|
1473
|
+
const body = await c2.req.json();
|
|
1474
|
+
await vector.createIndex({
|
|
1475
|
+
mastra,
|
|
1476
|
+
vectorName,
|
|
1477
|
+
index: body
|
|
1478
|
+
});
|
|
1479
|
+
return c2.json({ success: true });
|
|
1480
|
+
} catch (error) {
|
|
1481
|
+
return handleError(error, "Error creating index");
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
async function queryVectors(c2) {
|
|
1485
|
+
try {
|
|
1486
|
+
const mastra = c2.get("mastra");
|
|
1487
|
+
const vectorName = c2.req.param("vectorName");
|
|
1488
|
+
const { indexName, queryVector, topK = 10, filter, includeVector = false } = await c2.req.json();
|
|
1489
|
+
const results = await vector.queryVectors({
|
|
1490
|
+
mastra,
|
|
1491
|
+
vectorName,
|
|
1492
|
+
query: { indexName, queryVector, topK, filter, includeVector }
|
|
1493
|
+
});
|
|
1494
|
+
return c2.json({ results });
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
return handleError(error, "Error querying vectors");
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
async function listIndexes(c2) {
|
|
1500
|
+
try {
|
|
1501
|
+
const mastra = c2.get("mastra");
|
|
1502
|
+
const vectorName = c2.req.param("vectorName");
|
|
1503
|
+
const indexes = await vector.listIndexes({
|
|
1504
|
+
mastra,
|
|
1505
|
+
vectorName
|
|
1506
|
+
});
|
|
1507
|
+
return c2.json({ indexes });
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
return handleError(error, "Error listing indexes");
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
async function describeIndex(c2) {
|
|
1513
|
+
try {
|
|
1514
|
+
const mastra = c2.get("mastra");
|
|
1515
|
+
const vectorName = c2.req.param("vectorName");
|
|
1516
|
+
const indexName = c2.req.param("indexName");
|
|
1517
|
+
if (!indexName) {
|
|
1518
|
+
throw new httpException.HTTPException(400, { message: "Index name is required" });
|
|
1519
|
+
}
|
|
1520
|
+
const stats = await vector.describeIndex({
|
|
1521
|
+
mastra,
|
|
1522
|
+
vectorName,
|
|
1523
|
+
indexName
|
|
1524
|
+
});
|
|
1525
|
+
return c2.json({
|
|
1526
|
+
dimension: stats.dimension,
|
|
1527
|
+
count: stats.count,
|
|
1528
|
+
metric: stats.metric?.toLowerCase()
|
|
1529
|
+
});
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
return handleError(error, "Error describing index");
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
async function deleteIndex(c2) {
|
|
1535
|
+
try {
|
|
1536
|
+
const mastra = c2.get("mastra");
|
|
1537
|
+
const vectorName = c2.req.param("vectorName");
|
|
1538
|
+
const indexName = c2.req.param("indexName");
|
|
1539
|
+
if (!indexName) {
|
|
1540
|
+
throw new httpException.HTTPException(400, { message: "Index name is required" });
|
|
1541
|
+
}
|
|
1542
|
+
await vector.deleteIndex({
|
|
1543
|
+
mastra,
|
|
1544
|
+
vectorName,
|
|
1545
|
+
indexName
|
|
1546
|
+
});
|
|
1547
|
+
return c2.json({ success: true });
|
|
1548
|
+
} catch (error) {
|
|
1549
|
+
return handleError(error, "Error deleting index");
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
async function getSpeakersHandler(c2) {
|
|
1553
|
+
try {
|
|
1554
|
+
const mastra = c2.get("mastra");
|
|
1555
|
+
const agentId = c2.req.param("agentId");
|
|
1556
|
+
const speakers = await voice.getSpeakersHandler({
|
|
1557
|
+
mastra,
|
|
1558
|
+
agentId
|
|
1559
|
+
});
|
|
1560
|
+
return c2.json(speakers);
|
|
1561
|
+
} catch (error) {
|
|
1562
|
+
return handleError(error, "Error getting speakers");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
async function speakHandler(c2) {
|
|
1566
|
+
try {
|
|
1567
|
+
const mastra = c2.get("mastra");
|
|
1568
|
+
const agentId = c2.req.param("agentId");
|
|
1569
|
+
const { input, options } = await c2.req.json();
|
|
1570
|
+
const audioStream = await voice.generateSpeechHandler({
|
|
1571
|
+
mastra,
|
|
1572
|
+
agentId,
|
|
1573
|
+
body: { text: input, speakerId: options?.speakerId }
|
|
1574
|
+
});
|
|
1575
|
+
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
1576
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1577
|
+
return c2.body(audioStream);
|
|
1578
|
+
} catch (error) {
|
|
1579
|
+
return handleError(error, "Error generating speech");
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
async function listenHandler(c2) {
|
|
1583
|
+
try {
|
|
1584
|
+
const mastra = c2.get("mastra");
|
|
1585
|
+
const agentId = c2.req.param("agentId");
|
|
1586
|
+
const formData = await c2.req.formData();
|
|
1587
|
+
const audioFile = formData.get("audio");
|
|
1588
|
+
const options = formData.get("options");
|
|
1589
|
+
if (!audioFile || !(audioFile instanceof File)) {
|
|
1590
|
+
throw new httpException.HTTPException(400, { message: "Audio file is required" });
|
|
1591
|
+
}
|
|
1592
|
+
const audioData = await audioFile.arrayBuffer();
|
|
1593
|
+
let parsedOptions = {};
|
|
1594
|
+
try {
|
|
1595
|
+
parsedOptions = options ? JSON.parse(options) : {};
|
|
1596
|
+
} catch {
|
|
1597
|
+
}
|
|
1598
|
+
const transcription = await voice.transcribeSpeechHandler({
|
|
1599
|
+
mastra,
|
|
1600
|
+
agentId,
|
|
1601
|
+
body: {
|
|
1602
|
+
audioData: Buffer.from(audioData),
|
|
1603
|
+
options: parsedOptions
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
return c2.json({ text: transcription });
|
|
1607
|
+
} catch (error) {
|
|
1608
|
+
return handleError(error, "Error transcribing speech");
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
async function getWorkflowsHandler(c2) {
|
|
1612
|
+
try {
|
|
1613
|
+
const mastra = c2.get("mastra");
|
|
1614
|
+
const workflows$1 = await workflows.getWorkflowsHandler({
|
|
1615
|
+
mastra
|
|
1616
|
+
});
|
|
1617
|
+
return c2.json(workflows$1);
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
return handleError(error, "Error getting workflows");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
async function getWorkflowByIdHandler(c2) {
|
|
1623
|
+
try {
|
|
1624
|
+
const mastra = c2.get("mastra");
|
|
1625
|
+
const workflowId = c2.req.param("workflowId");
|
|
1626
|
+
const workflow = await workflows.getWorkflowByIdHandler({
|
|
1627
|
+
mastra,
|
|
1628
|
+
workflowId
|
|
1629
|
+
});
|
|
1630
|
+
return c2.json(workflow);
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
return handleError(error, "Error getting workflow");
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
async function startAsyncWorkflowHandler(c2) {
|
|
1636
|
+
try {
|
|
1637
|
+
const mastra = c2.get("mastra");
|
|
1638
|
+
const container = c2.get("container");
|
|
1639
|
+
const workflowId = c2.req.param("workflowId");
|
|
1640
|
+
const triggerData = await c2.req.json();
|
|
1641
|
+
const runId = c2.req.query("runId");
|
|
1642
|
+
const result = await workflows.startAsyncWorkflowHandler({
|
|
1643
|
+
mastra,
|
|
1644
|
+
container,
|
|
1645
|
+
workflowId,
|
|
1646
|
+
runId,
|
|
1647
|
+
triggerData
|
|
1648
|
+
});
|
|
1649
|
+
return c2.json(result);
|
|
1650
|
+
} catch (error) {
|
|
1651
|
+
return handleError(error, "Error executing workflow");
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
async function createRunHandler(c2) {
|
|
1655
|
+
try {
|
|
1656
|
+
const mastra = c2.get("mastra");
|
|
1657
|
+
const workflowId = c2.req.param("workflowId");
|
|
1658
|
+
const prevRunId = c2.req.query("runId");
|
|
1659
|
+
const result = await workflows.createRunHandler({
|
|
1660
|
+
mastra,
|
|
1661
|
+
workflowId,
|
|
1662
|
+
runId: prevRunId
|
|
1663
|
+
});
|
|
1664
|
+
return c2.json(result);
|
|
1665
|
+
} catch (e2) {
|
|
1666
|
+
return handleError(e2, "Error creating run");
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
async function startWorkflowRunHandler(c2) {
|
|
1670
|
+
try {
|
|
1671
|
+
const mastra = c2.get("mastra");
|
|
1672
|
+
const container = c2.get("container");
|
|
1673
|
+
const workflowId = c2.req.param("workflowId");
|
|
1674
|
+
const triggerData = await c2.req.json();
|
|
1675
|
+
const runId = c2.req.query("runId");
|
|
1676
|
+
await workflows.startWorkflowRunHandler({
|
|
1677
|
+
mastra,
|
|
1678
|
+
container,
|
|
1679
|
+
workflowId,
|
|
1680
|
+
runId,
|
|
1681
|
+
triggerData
|
|
1682
|
+
});
|
|
1683
|
+
return c2.json({ message: "Workflow run started" });
|
|
1684
|
+
} catch (e2) {
|
|
1685
|
+
return handleError(e2, "Error starting workflow run");
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
function watchWorkflowHandler(c2) {
|
|
1689
|
+
try {
|
|
1690
|
+
const mastra = c2.get("mastra");
|
|
1691
|
+
const logger2 = mastra.getLogger();
|
|
1692
|
+
const workflowId = c2.req.param("workflowId");
|
|
1693
|
+
const runId = c2.req.query("runId");
|
|
1694
|
+
if (!runId) {
|
|
1695
|
+
throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
|
|
1696
|
+
}
|
|
1697
|
+
return streaming.stream(
|
|
1698
|
+
c2,
|
|
1699
|
+
async (stream2) => {
|
|
1700
|
+
try {
|
|
1701
|
+
const result = await workflows.watchWorkflowHandler({
|
|
1702
|
+
mastra,
|
|
1703
|
+
workflowId,
|
|
1704
|
+
runId
|
|
1705
|
+
});
|
|
1706
|
+
stream2.onAbort(() => {
|
|
1707
|
+
if (!result.locked) {
|
|
1708
|
+
return result.cancel();
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
for await (const chunk of result) {
|
|
1712
|
+
await stream2.write(chunk.toString() + "");
|
|
1713
|
+
}
|
|
1714
|
+
} catch (err) {
|
|
1715
|
+
console.log(err);
|
|
1716
|
+
}
|
|
1717
|
+
},
|
|
1718
|
+
async (err) => {
|
|
1719
|
+
logger2.error("Error in watch stream: " + err?.message);
|
|
1720
|
+
}
|
|
1721
|
+
);
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
return handleError(error, "Error watching workflow");
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
async function resumeAsyncWorkflowHandler(c2) {
|
|
1727
|
+
try {
|
|
1728
|
+
const mastra = c2.get("mastra");
|
|
1729
|
+
const container = c2.get("container");
|
|
1730
|
+
const workflowId = c2.req.param("workflowId");
|
|
1731
|
+
const runId = c2.req.query("runId");
|
|
1732
|
+
const { stepId, context } = await c2.req.json();
|
|
1733
|
+
if (!runId) {
|
|
1734
|
+
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
1735
|
+
}
|
|
1736
|
+
const result = await workflows.resumeAsyncWorkflowHandler({
|
|
1737
|
+
mastra,
|
|
1738
|
+
container,
|
|
1739
|
+
workflowId,
|
|
1740
|
+
runId,
|
|
1741
|
+
body: { stepId, context }
|
|
1742
|
+
});
|
|
1743
|
+
return c2.json(result);
|
|
1744
|
+
} catch (error) {
|
|
1745
|
+
return handleError(error, "Error resuming workflow step");
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
async function resumeWorkflowHandler(c2) {
|
|
1749
|
+
try {
|
|
1750
|
+
const mastra = c2.get("mastra");
|
|
1751
|
+
const container = c2.get("container");
|
|
1752
|
+
const workflowId = c2.req.param("workflowId");
|
|
1753
|
+
const runId = c2.req.query("runId");
|
|
1754
|
+
const { stepId, context } = await c2.req.json();
|
|
1755
|
+
if (!runId) {
|
|
1756
|
+
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
1757
|
+
}
|
|
1758
|
+
await workflows.resumeWorkflowHandler({
|
|
1759
|
+
mastra,
|
|
1760
|
+
container,
|
|
1761
|
+
workflowId,
|
|
1762
|
+
runId,
|
|
1763
|
+
body: { stepId, context }
|
|
1764
|
+
});
|
|
1765
|
+
return c2.json({ message: "Workflow run resumed" });
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
return handleError(error, "Error resuming workflow");
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
async function getWorkflowRunsHandler(c2) {
|
|
1771
|
+
try {
|
|
1772
|
+
const mastra = c2.get("mastra");
|
|
1773
|
+
const workflowId = c2.req.param("workflowId");
|
|
1774
|
+
const workflowRuns = await workflows.getWorkflowRunsHandler({
|
|
1775
|
+
mastra,
|
|
1776
|
+
workflowId
|
|
1777
|
+
});
|
|
1778
|
+
return c2.json(workflowRuns);
|
|
1779
|
+
} catch (error) {
|
|
1780
|
+
return handleError(error, "Error getting workflow runs");
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
// src/server/welcome.ts
|
|
1785
|
+
var html2 = `
|
|
1786
|
+
<!doctype html>
|
|
1787
|
+
<html lang="en">
|
|
1788
|
+
<head>
|
|
1789
|
+
<meta charset="UTF-8" />
|
|
1790
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
1791
|
+
<title>Welcome to Mastra</title>
|
|
1792
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/inter-ui/3.19.3/inter.min.css" />
|
|
1793
|
+
<style>
|
|
1794
|
+
body {
|
|
1795
|
+
margin: 0;
|
|
1796
|
+
padding: 0;
|
|
1797
|
+
background-color: #0d0d0d;
|
|
1798
|
+
color: #ffffff;
|
|
1799
|
+
font-family:
|
|
1800
|
+
'Inter',
|
|
1801
|
+
-apple-system,
|
|
1802
|
+
BlinkMacSystemFont,
|
|
1803
|
+
system-ui,
|
|
1804
|
+
sans-serif;
|
|
1805
|
+
min-height: 100vh;
|
|
1806
|
+
display: flex;
|
|
1807
|
+
flex-direction: column;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
main {
|
|
1811
|
+
flex: 1;
|
|
1812
|
+
display: flex;
|
|
1813
|
+
flex-direction: column;
|
|
1814
|
+
align-items: center;
|
|
1815
|
+
justify-content: center;
|
|
1816
|
+
padding: 2rem;
|
|
1817
|
+
text-align: center;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
h1 {
|
|
1821
|
+
font-size: 4rem;
|
|
1822
|
+
font-weight: 600;
|
|
1823
|
+
margin: 0 0 1rem 0;
|
|
1824
|
+
background: linear-gradient(to right, #fff, #ccc);
|
|
1825
|
+
-webkit-background-clip: text;
|
|
1826
|
+
-webkit-text-fill-color: transparent;
|
|
1827
|
+
line-height: 1.2;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
.subtitle {
|
|
1831
|
+
color: #9ca3af;
|
|
1832
|
+
font-size: 1.25rem;
|
|
1833
|
+
max-width: 600px;
|
|
1834
|
+
margin: 0 auto 3rem auto;
|
|
1835
|
+
line-height: 1.6;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
.docs-link {
|
|
1839
|
+
background-color: #1a1a1a;
|
|
1840
|
+
padding: 1rem 2rem;
|
|
1841
|
+
border-radius: 0.5rem;
|
|
1842
|
+
display: flex;
|
|
1843
|
+
align-items: center;
|
|
1844
|
+
gap: 1rem;
|
|
1845
|
+
font-family: monospace;
|
|
1846
|
+
font-size: 1rem;
|
|
1847
|
+
color: #ffffff;
|
|
1848
|
+
text-decoration: none;
|
|
1849
|
+
transition: background-color 0.2s;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
.docs-link:hover {
|
|
1853
|
+
background-color: #252525;
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
.arrow-icon {
|
|
1857
|
+
transition: transform 0.2s;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
.docs-link:hover .arrow-icon {
|
|
1861
|
+
transform: translateX(4px);
|
|
1862
|
+
}
|
|
1863
|
+
</style>
|
|
1864
|
+
</head>
|
|
1865
|
+
<body>
|
|
1866
|
+
<main>
|
|
1867
|
+
<h1>Welcome to Mastra</h1>
|
|
1868
|
+
<p class="subtitle">
|
|
1869
|
+
From the team that brought you Gatsby: prototype and productionize AI features with a modern JS/TS stack.
|
|
1870
|
+
</p>
|
|
1871
|
+
|
|
1872
|
+
<a href="https://mastra.ai/docs" class="docs-link">
|
|
1873
|
+
Browse the docs
|
|
1874
|
+
<svg
|
|
1875
|
+
class="arrow-icon"
|
|
1876
|
+
width="20"
|
|
1877
|
+
height="20"
|
|
1878
|
+
viewBox="0 0 24 24"
|
|
1879
|
+
fill="none"
|
|
1880
|
+
stroke="currentColor"
|
|
1881
|
+
strokeWidth="2"
|
|
1882
|
+
>
|
|
1883
|
+
<path d="M5 12h14M12 5l7 7-7 7" />
|
|
1884
|
+
</svg>
|
|
1885
|
+
</a>
|
|
1886
|
+
</main>
|
|
1887
|
+
</body>
|
|
1888
|
+
</html>
|
|
1889
|
+
`;
|
|
1890
|
+
|
|
1891
|
+
// src/server/index.ts
|
|
1892
|
+
async function createHonoServer(mastra, options = {}) {
|
|
1893
|
+
const app = new hono.Hono();
|
|
1894
|
+
const server = mastra.getServer();
|
|
1895
|
+
const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
1896
|
+
const mastraToolsPaths = (await import(url.pathToFileURL(posix.join(__dirname, "tools.mjs")).href)).tools;
|
|
1897
|
+
const toolImports = mastraToolsPaths ? await Promise.all(
|
|
1898
|
+
// @ts-ignore
|
|
1899
|
+
mastraToolsPaths.map(async (toolPath) => {
|
|
1900
|
+
return import(url.pathToFileURL(posix.join(__dirname, toolPath)).href);
|
|
1901
|
+
})
|
|
1902
|
+
) : [];
|
|
1903
|
+
const tools = toolImports.reduce((acc, toolModule) => {
|
|
1904
|
+
Object.entries(toolModule).forEach(([key, tool]) => {
|
|
1905
|
+
acc[key] = tool;
|
|
1906
|
+
});
|
|
1907
|
+
return acc;
|
|
1908
|
+
}, {});
|
|
1909
|
+
app.use("*", async function setTelemetryInfo(c2, next) {
|
|
1910
|
+
const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
|
|
1911
|
+
const span = core.Telemetry.getActiveSpan();
|
|
1912
|
+
if (span) {
|
|
1913
|
+
span.setAttribute("http.request_id", requestId);
|
|
1914
|
+
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
1915
|
+
const newCtx = core.Telemetry.setBaggage({
|
|
1916
|
+
"http.request_id": requestId
|
|
1917
|
+
});
|
|
1918
|
+
await new Promise((resolve) => {
|
|
1919
|
+
core.Telemetry.withContext(newCtx, async () => {
|
|
1920
|
+
await next();
|
|
1921
|
+
resolve(true);
|
|
1922
|
+
});
|
|
1923
|
+
});
|
|
1924
|
+
} else {
|
|
1925
|
+
await next();
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
if (options.apiReqLogs) {
|
|
1929
|
+
app.use(logger.logger());
|
|
1930
|
+
}
|
|
1931
|
+
app.onError(errorHandler);
|
|
1932
|
+
app.use("*", function setContext(c2, next) {
|
|
1933
|
+
const container = new di.Container();
|
|
1934
|
+
c2.set("container", container);
|
|
1935
|
+
c2.set("mastra", mastra);
|
|
1936
|
+
c2.set("tools", tools);
|
|
1937
|
+
c2.set("playground", options.playground === true);
|
|
1938
|
+
return next();
|
|
1939
|
+
});
|
|
1940
|
+
const serverMiddleware = mastra.getServerMiddleware?.();
|
|
1941
|
+
if (serverMiddleware && serverMiddleware.length > 0) {
|
|
1942
|
+
for (const m2 of serverMiddleware) {
|
|
1943
|
+
app.use(m2.path, m2.handler);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (server?.cors === false) {
|
|
1947
|
+
app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3));
|
|
1948
|
+
} else {
|
|
1949
|
+
const corsConfig = {
|
|
1950
|
+
origin: "*",
|
|
1951
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
1952
|
+
credentials: false,
|
|
1953
|
+
maxAge: 3600,
|
|
1954
|
+
...server?.cors,
|
|
1955
|
+
allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type", ...server?.cors?.allowHeaders ?? []],
|
|
1956
|
+
exposeHeaders: ["Content-Length", "X-Requested-With", ...server?.cors?.exposeHeaders ?? []]
|
|
1957
|
+
};
|
|
1958
|
+
app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3), cors.cors(corsConfig));
|
|
1959
|
+
}
|
|
1960
|
+
const bodyLimitOptions = {
|
|
1961
|
+
maxSize: 4.5 * 1024 * 1024,
|
|
1962
|
+
// 4.5 MB,
|
|
1963
|
+
onError: (c2) => c2.json({ error: "Request body too large" }, 413)
|
|
1964
|
+
};
|
|
1965
|
+
const routes = server?.apiRoutes;
|
|
1966
|
+
if (server?.middleware) {
|
|
1967
|
+
const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
|
|
1968
|
+
const middlewares = normalizedMiddlewares.map((middleware2) => {
|
|
1969
|
+
if (typeof middleware2 === "function") {
|
|
1970
|
+
return {
|
|
1971
|
+
path: "*",
|
|
1972
|
+
handler: middleware2
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1975
|
+
return middleware2;
|
|
1976
|
+
});
|
|
1977
|
+
for (const middleware2 of middlewares) {
|
|
1978
|
+
app.use(middleware2.path, middleware2.handler);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
if (routes) {
|
|
1982
|
+
for (const route of routes) {
|
|
1983
|
+
const middlewares = [];
|
|
1984
|
+
if (route.middleware) {
|
|
1985
|
+
middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
|
|
1986
|
+
}
|
|
1987
|
+
if (route.openapi) {
|
|
1988
|
+
middlewares.push(h(route.openapi));
|
|
1989
|
+
}
|
|
1990
|
+
if (route.method === "GET") {
|
|
1991
|
+
app.get(route.path, ...middlewares, route.handler);
|
|
1992
|
+
} else if (route.method === "POST") {
|
|
1993
|
+
app.post(route.path, ...middlewares, route.handler);
|
|
1994
|
+
} else if (route.method === "PUT") {
|
|
1995
|
+
app.put(route.path, ...middlewares, route.handler);
|
|
1996
|
+
} else if (route.method === "DELETE") {
|
|
1997
|
+
app.delete(route.path, ...middlewares, route.handler);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
app.get(
|
|
2002
|
+
"/api",
|
|
2003
|
+
h({
|
|
2004
|
+
description: "Get API status",
|
|
2005
|
+
tags: ["system"],
|
|
2006
|
+
responses: {
|
|
2007
|
+
200: {
|
|
2008
|
+
description: "Success"
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}),
|
|
2012
|
+
rootHandler
|
|
2013
|
+
);
|
|
2014
|
+
app.get(
|
|
2015
|
+
"/api/agents",
|
|
2016
|
+
h({
|
|
2017
|
+
description: "Get all available agents",
|
|
2018
|
+
tags: ["agents"],
|
|
2019
|
+
responses: {
|
|
2020
|
+
200: {
|
|
2021
|
+
description: "List of all agents"
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}),
|
|
2025
|
+
getAgentsHandler
|
|
2026
|
+
);
|
|
2027
|
+
app.get(
|
|
2028
|
+
"/api/networks",
|
|
2029
|
+
h({
|
|
2030
|
+
description: "Get all available networks",
|
|
2031
|
+
tags: ["networks"],
|
|
2032
|
+
responses: {
|
|
2033
|
+
200: {
|
|
2034
|
+
description: "List of all networks"
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}),
|
|
2038
|
+
getNetworksHandler
|
|
2039
|
+
);
|
|
2040
|
+
app.get(
|
|
2041
|
+
"/api/networks/:networkId",
|
|
2042
|
+
h({
|
|
2043
|
+
description: "Get network by ID",
|
|
2044
|
+
tags: ["networks"],
|
|
2045
|
+
parameters: [
|
|
2046
|
+
{
|
|
2047
|
+
name: "networkId",
|
|
2048
|
+
in: "path",
|
|
2049
|
+
required: true,
|
|
2050
|
+
schema: { type: "string" }
|
|
2051
|
+
}
|
|
2052
|
+
],
|
|
2053
|
+
responses: {
|
|
2054
|
+
200: {
|
|
2055
|
+
description: "Network details"
|
|
2056
|
+
},
|
|
2057
|
+
404: {
|
|
2058
|
+
description: "Network not found"
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}),
|
|
2062
|
+
getNetworkByIdHandler
|
|
2063
|
+
);
|
|
2064
|
+
app.post(
|
|
2065
|
+
"/api/networks/:networkId/generate",
|
|
2066
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2067
|
+
h({
|
|
2068
|
+
description: "Generate a response from a network",
|
|
2069
|
+
tags: ["networks"],
|
|
2070
|
+
parameters: [
|
|
2071
|
+
{
|
|
2072
|
+
name: "networkId",
|
|
2073
|
+
in: "path",
|
|
2074
|
+
required: true,
|
|
2075
|
+
schema: { type: "string" }
|
|
2076
|
+
}
|
|
2077
|
+
],
|
|
2078
|
+
requestBody: {
|
|
2079
|
+
required: true,
|
|
2080
|
+
content: {
|
|
2081
|
+
"application/json": {
|
|
2082
|
+
schema: {
|
|
2083
|
+
type: "object",
|
|
2084
|
+
properties: {
|
|
2085
|
+
input: {
|
|
2086
|
+
oneOf: [
|
|
2087
|
+
{ type: "string" },
|
|
2088
|
+
{
|
|
2089
|
+
type: "array",
|
|
2090
|
+
items: { type: "object" }
|
|
2091
|
+
}
|
|
2092
|
+
],
|
|
2093
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
2094
|
+
}
|
|
2095
|
+
},
|
|
2096
|
+
required: ["input"]
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
},
|
|
2101
|
+
responses: {
|
|
2102
|
+
200: {
|
|
2103
|
+
description: "Generated response"
|
|
2104
|
+
},
|
|
2105
|
+
404: {
|
|
2106
|
+
description: "Network not found"
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}),
|
|
2110
|
+
generateHandler2
|
|
2111
|
+
);
|
|
2112
|
+
app.post(
|
|
2113
|
+
"/api/networks/:networkId/stream",
|
|
2114
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2115
|
+
h({
|
|
2116
|
+
description: "Generate a response from a network",
|
|
2117
|
+
tags: ["networks"],
|
|
2118
|
+
parameters: [
|
|
2119
|
+
{
|
|
2120
|
+
name: "networkId",
|
|
2121
|
+
in: "path",
|
|
2122
|
+
required: true,
|
|
2123
|
+
schema: { type: "string" }
|
|
2124
|
+
}
|
|
2125
|
+
],
|
|
2126
|
+
requestBody: {
|
|
2127
|
+
required: true,
|
|
2128
|
+
content: {
|
|
2129
|
+
"application/json": {
|
|
2130
|
+
schema: {
|
|
2131
|
+
type: "object",
|
|
2132
|
+
properties: {
|
|
2133
|
+
input: {
|
|
2134
|
+
oneOf: [
|
|
2135
|
+
{ type: "string" },
|
|
2136
|
+
{
|
|
2137
|
+
type: "array",
|
|
2138
|
+
items: { type: "object" }
|
|
2139
|
+
}
|
|
2140
|
+
],
|
|
2141
|
+
description: "Input for the network, can be a string or an array of CoreMessage objects"
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
required: ["input"]
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
},
|
|
2149
|
+
responses: {
|
|
2150
|
+
200: {
|
|
2151
|
+
description: "Generated response"
|
|
2152
|
+
},
|
|
2153
|
+
404: {
|
|
2154
|
+
description: "Network not found"
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}),
|
|
2158
|
+
streamGenerateHandler2
|
|
2159
|
+
);
|
|
2160
|
+
app.get(
|
|
2161
|
+
"/api/agents/:agentId",
|
|
2162
|
+
h({
|
|
2163
|
+
description: "Get agent by ID",
|
|
2164
|
+
tags: ["agents"],
|
|
2165
|
+
parameters: [
|
|
2166
|
+
{
|
|
2167
|
+
name: "agentId",
|
|
2168
|
+
in: "path",
|
|
2169
|
+
required: true,
|
|
2170
|
+
schema: { type: "string" }
|
|
2171
|
+
}
|
|
2172
|
+
],
|
|
2173
|
+
responses: {
|
|
2174
|
+
200: {
|
|
2175
|
+
description: "Agent details"
|
|
2176
|
+
},
|
|
2177
|
+
404: {
|
|
2178
|
+
description: "Agent not found"
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}),
|
|
2182
|
+
getAgentByIdHandler
|
|
2183
|
+
);
|
|
2184
|
+
app.get(
|
|
2185
|
+
"/api/agents/:agentId/evals/ci",
|
|
2186
|
+
h({
|
|
2187
|
+
description: "Get CI evals by agent ID",
|
|
2188
|
+
tags: ["agents"],
|
|
2189
|
+
parameters: [
|
|
2190
|
+
{
|
|
2191
|
+
name: "agentId",
|
|
2192
|
+
in: "path",
|
|
2193
|
+
required: true,
|
|
2194
|
+
schema: { type: "string" }
|
|
2195
|
+
}
|
|
2196
|
+
],
|
|
2197
|
+
responses: {
|
|
2198
|
+
200: {
|
|
2199
|
+
description: "List of evals"
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
}),
|
|
2203
|
+
getEvalsByAgentIdHandler
|
|
2204
|
+
);
|
|
2205
|
+
app.get(
|
|
2206
|
+
"/api/agents/:agentId/evals/live",
|
|
2207
|
+
h({
|
|
2208
|
+
description: "Get live evals by agent ID",
|
|
2209
|
+
tags: ["agents"],
|
|
2210
|
+
parameters: [
|
|
2211
|
+
{
|
|
2212
|
+
name: "agentId",
|
|
2213
|
+
in: "path",
|
|
2214
|
+
required: true,
|
|
2215
|
+
schema: { type: "string" }
|
|
2216
|
+
}
|
|
2217
|
+
],
|
|
2218
|
+
responses: {
|
|
2219
|
+
200: {
|
|
2220
|
+
description: "List of evals"
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}),
|
|
2224
|
+
getLiveEvalsByAgentIdHandler
|
|
2225
|
+
);
|
|
2226
|
+
app.post(
|
|
2227
|
+
"/api/agents/:agentId/generate",
|
|
2228
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2229
|
+
h({
|
|
2230
|
+
description: "Generate a response from an agent",
|
|
2231
|
+
tags: ["agents"],
|
|
2232
|
+
parameters: [
|
|
2233
|
+
{
|
|
2234
|
+
name: "agentId",
|
|
2235
|
+
in: "path",
|
|
2236
|
+
required: true,
|
|
2237
|
+
schema: { type: "string" }
|
|
2238
|
+
}
|
|
2239
|
+
],
|
|
2240
|
+
requestBody: {
|
|
2241
|
+
required: true,
|
|
2242
|
+
content: {
|
|
2243
|
+
"application/json": {
|
|
2244
|
+
schema: {
|
|
2245
|
+
type: "object",
|
|
2246
|
+
properties: {
|
|
2247
|
+
messages: {
|
|
2248
|
+
type: "array",
|
|
2249
|
+
items: { type: "object" }
|
|
2250
|
+
},
|
|
2251
|
+
threadId: { type: "string" },
|
|
2252
|
+
resourceId: { type: "string", description: "The resource ID for the conversation" },
|
|
2253
|
+
resourceid: {
|
|
2254
|
+
type: "string",
|
|
2255
|
+
description: "The resource ID for the conversation (deprecated, use resourceId instead)",
|
|
2256
|
+
deprecated: true
|
|
2257
|
+
},
|
|
2258
|
+
runId: { type: "string" },
|
|
2259
|
+
output: { type: "object" }
|
|
2260
|
+
},
|
|
2261
|
+
required: ["messages"]
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
},
|
|
2266
|
+
responses: {
|
|
2267
|
+
200: {
|
|
2268
|
+
description: "Generated response"
|
|
2269
|
+
},
|
|
2270
|
+
404: {
|
|
2271
|
+
description: "Agent not found"
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}),
|
|
2275
|
+
generateHandler
|
|
2276
|
+
);
|
|
2277
|
+
app.post(
|
|
2278
|
+
"/api/agents/:agentId/stream",
|
|
2279
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2280
|
+
h({
|
|
2281
|
+
description: "Stream a response from an agent",
|
|
2282
|
+
tags: ["agents"],
|
|
2283
|
+
parameters: [
|
|
2284
|
+
{
|
|
2285
|
+
name: "agentId",
|
|
2286
|
+
in: "path",
|
|
2287
|
+
required: true,
|
|
2288
|
+
schema: { type: "string" }
|
|
2289
|
+
}
|
|
2290
|
+
],
|
|
2291
|
+
requestBody: {
|
|
2292
|
+
required: true,
|
|
2293
|
+
content: {
|
|
2294
|
+
"application/json": {
|
|
2295
|
+
schema: {
|
|
2296
|
+
type: "object",
|
|
2297
|
+
properties: {
|
|
2298
|
+
messages: {
|
|
2299
|
+
type: "array",
|
|
2300
|
+
items: { type: "object" }
|
|
2301
|
+
},
|
|
2302
|
+
threadId: { type: "string" },
|
|
2303
|
+
resourceId: { type: "string", description: "The resource ID for the conversation" },
|
|
2304
|
+
resourceid: {
|
|
2305
|
+
type: "string",
|
|
2306
|
+
description: "The resource ID for the conversation (deprecated, use resourceId instead)",
|
|
2307
|
+
deprecated: true
|
|
2308
|
+
},
|
|
2309
|
+
runId: { type: "string" },
|
|
2310
|
+
output: { type: "object" }
|
|
2311
|
+
},
|
|
2312
|
+
required: ["messages"]
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
},
|
|
2317
|
+
responses: {
|
|
2318
|
+
200: {
|
|
2319
|
+
description: "Streamed response"
|
|
2320
|
+
},
|
|
2321
|
+
404: {
|
|
2322
|
+
description: "Agent not found"
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
}),
|
|
2326
|
+
streamGenerateHandler
|
|
2327
|
+
);
|
|
2328
|
+
app.post(
|
|
2329
|
+
"/api/agents/:agentId/instructions",
|
|
2330
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2331
|
+
h({
|
|
2332
|
+
description: "Update an agent's instructions",
|
|
2333
|
+
tags: ["agents"],
|
|
2334
|
+
parameters: [
|
|
2335
|
+
{
|
|
2336
|
+
name: "agentId",
|
|
2337
|
+
in: "path",
|
|
2338
|
+
required: true,
|
|
2339
|
+
schema: { type: "string" }
|
|
2340
|
+
}
|
|
2341
|
+
],
|
|
2342
|
+
requestBody: {
|
|
2343
|
+
required: true,
|
|
2344
|
+
content: {
|
|
2345
|
+
"application/json": {
|
|
2346
|
+
schema: {
|
|
2347
|
+
type: "object",
|
|
2348
|
+
properties: {
|
|
2349
|
+
instructions: {
|
|
2350
|
+
type: "string",
|
|
2351
|
+
description: "New instructions for the agent"
|
|
2352
|
+
}
|
|
2353
|
+
},
|
|
2354
|
+
required: ["instructions"]
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
},
|
|
2359
|
+
responses: {
|
|
2360
|
+
200: {
|
|
2361
|
+
description: "Instructions updated successfully"
|
|
2362
|
+
},
|
|
2363
|
+
403: {
|
|
2364
|
+
description: "Not allowed in non-playground environment"
|
|
2365
|
+
},
|
|
2366
|
+
404: {
|
|
2367
|
+
description: "Agent not found"
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
}),
|
|
2371
|
+
setAgentInstructionsHandler
|
|
2372
|
+
);
|
|
2373
|
+
app.post(
|
|
2374
|
+
"/api/agents/:agentId/instructions/enhance",
|
|
2375
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2376
|
+
h({
|
|
2377
|
+
description: "Generate an improved system prompt from instructions",
|
|
2378
|
+
tags: ["agents"],
|
|
2379
|
+
parameters: [
|
|
2380
|
+
{
|
|
2381
|
+
name: "agentId",
|
|
2382
|
+
in: "path",
|
|
2383
|
+
required: true,
|
|
2384
|
+
schema: { type: "string" },
|
|
2385
|
+
description: "ID of the agent whose model will be used for prompt generation"
|
|
2386
|
+
}
|
|
2387
|
+
],
|
|
2388
|
+
requestBody: {
|
|
2389
|
+
required: true,
|
|
2390
|
+
content: {
|
|
2391
|
+
"application/json": {
|
|
2392
|
+
schema: {
|
|
2393
|
+
type: "object",
|
|
2394
|
+
properties: {
|
|
2395
|
+
instructions: {
|
|
2396
|
+
type: "string",
|
|
2397
|
+
description: "Instructions to generate a system prompt from"
|
|
2398
|
+
},
|
|
2399
|
+
comment: {
|
|
2400
|
+
type: "string",
|
|
2401
|
+
description: "Optional comment for the enhanced prompt"
|
|
2402
|
+
}
|
|
2403
|
+
},
|
|
2404
|
+
required: ["instructions"]
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
},
|
|
2409
|
+
responses: {
|
|
2410
|
+
200: {
|
|
2411
|
+
description: "Generated system prompt and analysis",
|
|
2412
|
+
content: {
|
|
2413
|
+
"application/json": {
|
|
2414
|
+
schema: {
|
|
2415
|
+
type: "object",
|
|
2416
|
+
properties: {
|
|
2417
|
+
explanation: {
|
|
2418
|
+
type: "string",
|
|
2419
|
+
description: "Detailed analysis of the instructions"
|
|
2420
|
+
},
|
|
2421
|
+
new_prompt: {
|
|
2422
|
+
type: "string",
|
|
2423
|
+
description: "The enhanced system prompt"
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
},
|
|
2430
|
+
400: {
|
|
2431
|
+
description: "Missing or invalid request parameters"
|
|
2432
|
+
},
|
|
2433
|
+
404: {
|
|
2434
|
+
description: "Agent not found"
|
|
2435
|
+
},
|
|
2436
|
+
500: {
|
|
2437
|
+
description: "Internal server error or model response parsing error"
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
}),
|
|
2441
|
+
generateSystemPromptHandler
|
|
2442
|
+
);
|
|
2443
|
+
app.get(
|
|
2444
|
+
"/api/agents/:agentId/speakers",
|
|
2445
|
+
async (c2, next) => {
|
|
2446
|
+
c2.header("Deprecation", "true");
|
|
2447
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
|
|
2448
|
+
c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
|
|
2449
|
+
return next();
|
|
2450
|
+
},
|
|
2451
|
+
h({
|
|
2452
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
|
|
2453
|
+
tags: ["agents"],
|
|
2454
|
+
parameters: [
|
|
2455
|
+
{
|
|
2456
|
+
name: "agentId",
|
|
2457
|
+
in: "path",
|
|
2458
|
+
required: true,
|
|
2459
|
+
schema: { type: "string" }
|
|
2460
|
+
}
|
|
2461
|
+
],
|
|
2462
|
+
responses: {
|
|
2463
|
+
200: {
|
|
2464
|
+
description: "List of available speakers",
|
|
2465
|
+
content: {
|
|
2466
|
+
"application/json": {
|
|
2467
|
+
schema: {
|
|
2468
|
+
type: "array",
|
|
2469
|
+
items: {
|
|
2470
|
+
type: "object",
|
|
2471
|
+
description: "Speaker information depending on the voice provider",
|
|
2472
|
+
properties: {
|
|
2473
|
+
voiceId: { type: "string" }
|
|
2474
|
+
},
|
|
2475
|
+
additionalProperties: true
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
},
|
|
2481
|
+
400: {
|
|
2482
|
+
description: "Agent does not have voice capabilities"
|
|
2483
|
+
},
|
|
2484
|
+
404: {
|
|
2485
|
+
description: "Agent not found"
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
}),
|
|
2489
|
+
getSpeakersHandler
|
|
2490
|
+
);
|
|
2491
|
+
app.get(
|
|
2492
|
+
"/api/agents/:agentId/voice/speakers",
|
|
2493
|
+
h({
|
|
2494
|
+
description: "Get available speakers for an agent",
|
|
2495
|
+
tags: ["agents"],
|
|
2496
|
+
parameters: [
|
|
2497
|
+
{
|
|
2498
|
+
name: "agentId",
|
|
2499
|
+
in: "path",
|
|
2500
|
+
required: true,
|
|
2501
|
+
schema: { type: "string" }
|
|
2502
|
+
}
|
|
2503
|
+
],
|
|
2504
|
+
responses: {
|
|
2505
|
+
200: {
|
|
2506
|
+
description: "List of available speakers",
|
|
2507
|
+
content: {
|
|
2508
|
+
"application/json": {
|
|
2509
|
+
schema: {
|
|
2510
|
+
type: "array",
|
|
2511
|
+
items: {
|
|
2512
|
+
type: "object",
|
|
2513
|
+
description: "Speaker information depending on the voice provider",
|
|
2514
|
+
properties: {
|
|
2515
|
+
voiceId: { type: "string" }
|
|
2516
|
+
},
|
|
2517
|
+
additionalProperties: true
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
},
|
|
2523
|
+
400: {
|
|
2524
|
+
description: "Agent does not have voice capabilities"
|
|
2525
|
+
},
|
|
2526
|
+
404: {
|
|
2527
|
+
description: "Agent not found"
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
}),
|
|
2531
|
+
getSpeakersHandler
|
|
2532
|
+
);
|
|
2533
|
+
app.post(
|
|
2534
|
+
"/api/agents/:agentId/speak",
|
|
2535
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2536
|
+
async (c2, next) => {
|
|
2537
|
+
c2.header("Deprecation", "true");
|
|
2538
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speak instead"');
|
|
2539
|
+
c2.header("Link", '</api/agents/:agentId/voice/speak>; rel="successor-version"');
|
|
2540
|
+
return next();
|
|
2541
|
+
},
|
|
2542
|
+
h({
|
|
2543
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/speak instead. Convert text to speech using the agent's voice provider",
|
|
2544
|
+
tags: ["agents"],
|
|
2545
|
+
parameters: [
|
|
2546
|
+
{
|
|
2547
|
+
name: "agentId",
|
|
2548
|
+
in: "path",
|
|
2549
|
+
required: true,
|
|
2550
|
+
schema: { type: "string" }
|
|
2551
|
+
}
|
|
2552
|
+
],
|
|
2553
|
+
requestBody: {
|
|
2554
|
+
required: true,
|
|
2555
|
+
content: {
|
|
2556
|
+
"application/json": {
|
|
2557
|
+
schema: {
|
|
2558
|
+
type: "object",
|
|
2559
|
+
properties: {
|
|
2560
|
+
text: {
|
|
2561
|
+
type: "string",
|
|
2562
|
+
description: "Text to convert to speech"
|
|
2563
|
+
},
|
|
2564
|
+
options: {
|
|
2565
|
+
type: "object",
|
|
2566
|
+
description: "Provider-specific options for speech generation",
|
|
2567
|
+
properties: {
|
|
2568
|
+
speaker: {
|
|
2569
|
+
type: "string",
|
|
2570
|
+
description: "Speaker ID to use for speech generation"
|
|
2571
|
+
}
|
|
2572
|
+
},
|
|
2573
|
+
additionalProperties: true
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
required: ["text"]
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
},
|
|
2581
|
+
responses: {
|
|
2582
|
+
200: {
|
|
2583
|
+
description: "Audio stream",
|
|
2584
|
+
content: {
|
|
2585
|
+
"audio/mpeg": {
|
|
2586
|
+
schema: {
|
|
2587
|
+
format: "binary",
|
|
2588
|
+
description: "Audio stream containing the generated speech"
|
|
2589
|
+
}
|
|
2590
|
+
},
|
|
2591
|
+
"audio/*": {
|
|
2592
|
+
schema: {
|
|
2593
|
+
format: "binary",
|
|
2594
|
+
description: "Audio stream depending on the provider"
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
},
|
|
2599
|
+
400: {
|
|
2600
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
2601
|
+
},
|
|
2602
|
+
404: {
|
|
2603
|
+
description: "Agent not found"
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
}),
|
|
2607
|
+
speakHandler
|
|
2608
|
+
);
|
|
2609
|
+
app.post(
|
|
2610
|
+
"/api/agents/:agentId/voice/speak",
|
|
2611
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2612
|
+
h({
|
|
2613
|
+
description: "Convert text to speech using the agent's voice provider",
|
|
2614
|
+
tags: ["agents"],
|
|
2615
|
+
parameters: [
|
|
2616
|
+
{
|
|
2617
|
+
name: "agentId",
|
|
2618
|
+
in: "path",
|
|
2619
|
+
required: true,
|
|
2620
|
+
schema: { type: "string" }
|
|
2621
|
+
}
|
|
2622
|
+
],
|
|
2623
|
+
requestBody: {
|
|
2624
|
+
required: true,
|
|
2625
|
+
content: {
|
|
2626
|
+
"application/json": {
|
|
2627
|
+
schema: {
|
|
2628
|
+
type: "object",
|
|
2629
|
+
properties: {
|
|
2630
|
+
input: {
|
|
2631
|
+
type: "string",
|
|
2632
|
+
description: "Text to convert to speech"
|
|
2633
|
+
},
|
|
2634
|
+
options: {
|
|
2635
|
+
type: "object",
|
|
2636
|
+
description: "Provider-specific options for speech generation",
|
|
2637
|
+
properties: {
|
|
2638
|
+
speaker: {
|
|
2639
|
+
type: "string",
|
|
2640
|
+
description: "Speaker ID to use for speech generation"
|
|
2641
|
+
},
|
|
2642
|
+
options: {
|
|
2643
|
+
type: "object",
|
|
2644
|
+
description: "Provider-specific options for speech generation",
|
|
2645
|
+
additionalProperties: true
|
|
2646
|
+
}
|
|
2647
|
+
},
|
|
2648
|
+
additionalProperties: true
|
|
2649
|
+
}
|
|
2650
|
+
},
|
|
2651
|
+
required: ["text"]
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
},
|
|
2656
|
+
responses: {
|
|
2657
|
+
200: {
|
|
2658
|
+
description: "Audio stream",
|
|
2659
|
+
content: {
|
|
2660
|
+
"audio/mpeg": {
|
|
2661
|
+
schema: {
|
|
2662
|
+
format: "binary",
|
|
2663
|
+
description: "Audio stream containing the generated speech"
|
|
2664
|
+
}
|
|
2665
|
+
},
|
|
2666
|
+
"audio/*": {
|
|
2667
|
+
schema: {
|
|
2668
|
+
format: "binary",
|
|
2669
|
+
description: "Audio stream depending on the provider"
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
},
|
|
2674
|
+
400: {
|
|
2675
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
2676
|
+
},
|
|
2677
|
+
404: {
|
|
2678
|
+
description: "Agent not found"
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}),
|
|
2682
|
+
speakHandler
|
|
2683
|
+
);
|
|
2684
|
+
app.post(
|
|
2685
|
+
"/api/agents/:agentId/listen",
|
|
2686
|
+
bodyLimit.bodyLimit({
|
|
2687
|
+
...bodyLimitOptions,
|
|
2688
|
+
maxSize: 10 * 1024 * 1024
|
|
2689
|
+
// 10 MB for audio files
|
|
2690
|
+
}),
|
|
2691
|
+
async (c2, next) => {
|
|
2692
|
+
c2.header("Deprecation", "true");
|
|
2693
|
+
c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/listen instead"');
|
|
2694
|
+
c2.header("Link", '</api/agents/:agentId/voice/listen>; rel="successor-version"');
|
|
2695
|
+
return next();
|
|
2696
|
+
},
|
|
2697
|
+
h({
|
|
2698
|
+
description: "[DEPRECATED] Use /api/agents/:agentId/voice/listen instead. Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
2699
|
+
tags: ["agents"],
|
|
2700
|
+
parameters: [
|
|
2701
|
+
{
|
|
2702
|
+
name: "agentId",
|
|
2703
|
+
in: "path",
|
|
2704
|
+
required: true,
|
|
2705
|
+
schema: { type: "string" }
|
|
2706
|
+
}
|
|
2707
|
+
],
|
|
2708
|
+
requestBody: {
|
|
2709
|
+
required: true,
|
|
2710
|
+
content: {
|
|
2711
|
+
"audio/mpeg": {
|
|
2712
|
+
schema: {
|
|
2713
|
+
format: "binary",
|
|
2714
|
+
description: "Audio data stream to transcribe (supports various formats depending on provider like mp3, wav, webm, flac)"
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
},
|
|
2719
|
+
responses: {
|
|
2720
|
+
200: {
|
|
2721
|
+
description: "Transcription result",
|
|
2722
|
+
content: {
|
|
2723
|
+
"application/json": {
|
|
2724
|
+
schema: {
|
|
2725
|
+
type: "object",
|
|
2726
|
+
properties: {
|
|
2727
|
+
text: {
|
|
2728
|
+
type: "string",
|
|
2729
|
+
description: "Transcribed text"
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
},
|
|
2736
|
+
400: {
|
|
2737
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
2738
|
+
},
|
|
2739
|
+
404: {
|
|
2740
|
+
description: "Agent not found"
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
}),
|
|
2744
|
+
listenHandler
|
|
2745
|
+
);
|
|
2746
|
+
app.post(
|
|
2747
|
+
"/api/agents/:agentId/voice/listen",
|
|
2748
|
+
bodyLimit.bodyLimit({
|
|
2749
|
+
...bodyLimitOptions,
|
|
2750
|
+
maxSize: 10 * 1024 * 1024
|
|
2751
|
+
// 10 MB for audio files
|
|
2752
|
+
}),
|
|
2753
|
+
h({
|
|
2754
|
+
description: "Convert speech to text using the agent's voice provider. Additional provider-specific options can be passed as query parameters.",
|
|
2755
|
+
tags: ["agents"],
|
|
2756
|
+
parameters: [
|
|
2757
|
+
{
|
|
2758
|
+
name: "agentId",
|
|
2759
|
+
in: "path",
|
|
2760
|
+
required: true,
|
|
2761
|
+
schema: { type: "string" }
|
|
2762
|
+
}
|
|
2763
|
+
],
|
|
2764
|
+
requestBody: {
|
|
2765
|
+
required: true,
|
|
2766
|
+
content: {
|
|
2767
|
+
"multipart/form-data": {
|
|
2768
|
+
schema: {
|
|
2769
|
+
type: "object",
|
|
2770
|
+
required: ["audio"],
|
|
2771
|
+
properties: {
|
|
2772
|
+
audio: {
|
|
2773
|
+
type: "string",
|
|
2774
|
+
format: "binary",
|
|
2775
|
+
description: "Audio data stream to transcribe (supports various formats depending on provider like mp3, wav, webm, flac)"
|
|
2776
|
+
},
|
|
2777
|
+
options: {
|
|
2778
|
+
type: "object",
|
|
2779
|
+
description: "Provider-specific options for speech-to-text",
|
|
2780
|
+
additionalProperties: true
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
},
|
|
2787
|
+
responses: {
|
|
2788
|
+
200: {
|
|
2789
|
+
description: "Transcription result",
|
|
2790
|
+
content: {
|
|
2791
|
+
"application/json": {
|
|
2792
|
+
schema: {
|
|
2793
|
+
type: "object",
|
|
2794
|
+
properties: {
|
|
2795
|
+
text: {
|
|
2796
|
+
type: "string",
|
|
2797
|
+
description: "Transcribed text"
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
},
|
|
2804
|
+
400: {
|
|
2805
|
+
description: "Agent does not have voice capabilities or invalid request"
|
|
2806
|
+
},
|
|
2807
|
+
404: {
|
|
2808
|
+
description: "Agent not found"
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
}),
|
|
2812
|
+
listenHandler
|
|
2813
|
+
);
|
|
2814
|
+
app.post(
|
|
2815
|
+
"/api/agents/:agentId/tools/:toolId/execute",
|
|
2816
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2817
|
+
h({
|
|
2818
|
+
description: "Execute a tool through an agent",
|
|
2819
|
+
tags: ["agents"],
|
|
2820
|
+
parameters: [
|
|
2821
|
+
{
|
|
2822
|
+
name: "agentId",
|
|
2823
|
+
in: "path",
|
|
2824
|
+
required: true,
|
|
2825
|
+
schema: { type: "string" }
|
|
2826
|
+
},
|
|
2827
|
+
{
|
|
2828
|
+
name: "toolId",
|
|
2829
|
+
in: "path",
|
|
2830
|
+
required: true,
|
|
2831
|
+
schema: { type: "string" }
|
|
2832
|
+
}
|
|
2833
|
+
],
|
|
2834
|
+
requestBody: {
|
|
2835
|
+
required: true,
|
|
2836
|
+
content: {
|
|
2837
|
+
"application/json": {
|
|
2838
|
+
schema: {
|
|
2839
|
+
type: "object",
|
|
2840
|
+
properties: {
|
|
2841
|
+
data: { type: "object" }
|
|
2842
|
+
},
|
|
2843
|
+
required: ["data"]
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
},
|
|
2848
|
+
responses: {
|
|
2849
|
+
200: {
|
|
2850
|
+
description: "Tool execution result"
|
|
2851
|
+
},
|
|
2852
|
+
404: {
|
|
2853
|
+
description: "Tool or agent not found"
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
}),
|
|
2857
|
+
executeAgentToolHandler
|
|
2858
|
+
);
|
|
2859
|
+
app.get(
|
|
2860
|
+
"/api/memory/status",
|
|
2861
|
+
h({
|
|
2862
|
+
description: "Get memory status",
|
|
2863
|
+
tags: ["memory"],
|
|
2864
|
+
parameters: [
|
|
2865
|
+
{
|
|
2866
|
+
name: "agentId",
|
|
2867
|
+
in: "query",
|
|
2868
|
+
required: true,
|
|
2869
|
+
schema: { type: "string" }
|
|
2870
|
+
}
|
|
2871
|
+
],
|
|
2872
|
+
responses: {
|
|
2873
|
+
200: {
|
|
2874
|
+
description: "Memory status"
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
}),
|
|
2878
|
+
getMemoryStatusHandler
|
|
2879
|
+
);
|
|
2880
|
+
app.get(
|
|
2881
|
+
"/api/memory/threads",
|
|
2882
|
+
h({
|
|
2883
|
+
description: "Get all threads",
|
|
2884
|
+
tags: ["memory"],
|
|
2885
|
+
parameters: [
|
|
2886
|
+
{
|
|
2887
|
+
name: "resourceid",
|
|
2888
|
+
in: "query",
|
|
2889
|
+
required: true,
|
|
2890
|
+
schema: { type: "string" }
|
|
2891
|
+
},
|
|
2892
|
+
{
|
|
2893
|
+
name: "agentId",
|
|
2894
|
+
in: "query",
|
|
2895
|
+
required: true,
|
|
2896
|
+
schema: { type: "string" }
|
|
2897
|
+
}
|
|
2898
|
+
],
|
|
2899
|
+
responses: {
|
|
2900
|
+
200: {
|
|
2901
|
+
description: "List of all threads"
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
}),
|
|
2905
|
+
getThreadsHandler
|
|
2906
|
+
);
|
|
2907
|
+
app.get(
|
|
2908
|
+
"/api/memory/threads/:threadId",
|
|
2909
|
+
h({
|
|
2910
|
+
description: "Get thread by ID",
|
|
2911
|
+
tags: ["memory"],
|
|
2912
|
+
parameters: [
|
|
2913
|
+
{
|
|
2914
|
+
name: "threadId",
|
|
2915
|
+
in: "path",
|
|
2916
|
+
required: true,
|
|
2917
|
+
schema: { type: "string" }
|
|
2918
|
+
},
|
|
2919
|
+
{
|
|
2920
|
+
name: "agentId",
|
|
2921
|
+
in: "query",
|
|
2922
|
+
required: true,
|
|
2923
|
+
schema: { type: "string" }
|
|
2924
|
+
}
|
|
2925
|
+
],
|
|
2926
|
+
responses: {
|
|
2927
|
+
200: {
|
|
2928
|
+
description: "Thread details"
|
|
2929
|
+
},
|
|
2930
|
+
404: {
|
|
2931
|
+
description: "Thread not found"
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
}),
|
|
2935
|
+
getThreadByIdHandler
|
|
2936
|
+
);
|
|
2937
|
+
app.get(
|
|
2938
|
+
"/api/memory/threads/:threadId/messages",
|
|
2939
|
+
h({
|
|
2940
|
+
description: "Get messages for a thread",
|
|
2941
|
+
tags: ["memory"],
|
|
2942
|
+
parameters: [
|
|
2943
|
+
{
|
|
2944
|
+
name: "threadId",
|
|
2945
|
+
in: "path",
|
|
2946
|
+
required: true,
|
|
2947
|
+
schema: { type: "string" }
|
|
2948
|
+
},
|
|
2949
|
+
{
|
|
2950
|
+
name: "agentId",
|
|
2951
|
+
in: "query",
|
|
2952
|
+
required: true,
|
|
2953
|
+
schema: { type: "string" }
|
|
2954
|
+
}
|
|
2955
|
+
],
|
|
2956
|
+
responses: {
|
|
2957
|
+
200: {
|
|
2958
|
+
description: "List of messages"
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}),
|
|
2962
|
+
getMessagesHandler
|
|
2963
|
+
);
|
|
2964
|
+
app.post(
|
|
2965
|
+
"/api/memory/threads",
|
|
2966
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2967
|
+
h({
|
|
2968
|
+
description: "Create a new thread",
|
|
2969
|
+
tags: ["memory"],
|
|
2970
|
+
parameters: [
|
|
2971
|
+
{
|
|
2972
|
+
name: "agentId",
|
|
2973
|
+
in: "query",
|
|
2974
|
+
required: true,
|
|
2975
|
+
schema: { type: "string" }
|
|
2976
|
+
}
|
|
2977
|
+
],
|
|
2978
|
+
requestBody: {
|
|
2979
|
+
required: true,
|
|
2980
|
+
content: {
|
|
2981
|
+
"application/json": {
|
|
2982
|
+
schema: {
|
|
2983
|
+
type: "object",
|
|
2984
|
+
properties: {
|
|
2985
|
+
title: { type: "string" },
|
|
2986
|
+
metadata: { type: "object" },
|
|
2987
|
+
resourceid: { type: "string" },
|
|
2988
|
+
threadId: { type: "string" }
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
},
|
|
2994
|
+
responses: {
|
|
2995
|
+
200: {
|
|
2996
|
+
description: "Created thread"
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
}),
|
|
3000
|
+
createThreadHandler
|
|
3001
|
+
);
|
|
3002
|
+
app.patch(
|
|
3003
|
+
"/api/memory/threads/:threadId",
|
|
3004
|
+
h({
|
|
3005
|
+
description: "Update a thread",
|
|
3006
|
+
tags: ["memory"],
|
|
3007
|
+
parameters: [
|
|
3008
|
+
{
|
|
3009
|
+
name: "threadId",
|
|
3010
|
+
in: "path",
|
|
3011
|
+
required: true,
|
|
3012
|
+
schema: { type: "string" }
|
|
3013
|
+
},
|
|
3014
|
+
{
|
|
3015
|
+
name: "agentId",
|
|
3016
|
+
in: "query",
|
|
3017
|
+
required: true,
|
|
3018
|
+
schema: { type: "string" }
|
|
3019
|
+
}
|
|
3020
|
+
],
|
|
3021
|
+
requestBody: {
|
|
3022
|
+
required: true,
|
|
3023
|
+
content: {
|
|
3024
|
+
"application/json": {
|
|
3025
|
+
schema: { type: "object" }
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
},
|
|
3029
|
+
responses: {
|
|
3030
|
+
200: {
|
|
3031
|
+
description: "Updated thread"
|
|
3032
|
+
},
|
|
3033
|
+
404: {
|
|
3034
|
+
description: "Thread not found"
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
}),
|
|
3038
|
+
updateThreadHandler
|
|
3039
|
+
);
|
|
3040
|
+
app.delete(
|
|
3041
|
+
"/api/memory/threads/:threadId",
|
|
3042
|
+
h({
|
|
3043
|
+
description: "Delete a thread",
|
|
3044
|
+
tags: ["memory"],
|
|
3045
|
+
parameters: [
|
|
3046
|
+
{
|
|
3047
|
+
name: "threadId",
|
|
3048
|
+
in: "path",
|
|
3049
|
+
required: true,
|
|
3050
|
+
schema: { type: "string" }
|
|
3051
|
+
},
|
|
3052
|
+
{
|
|
3053
|
+
name: "agentId",
|
|
3054
|
+
in: "query",
|
|
3055
|
+
required: true,
|
|
3056
|
+
schema: { type: "string" }
|
|
3057
|
+
}
|
|
3058
|
+
],
|
|
3059
|
+
responses: {
|
|
3060
|
+
200: {
|
|
3061
|
+
description: "Thread deleted"
|
|
3062
|
+
},
|
|
3063
|
+
404: {
|
|
3064
|
+
description: "Thread not found"
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
}),
|
|
3068
|
+
deleteThreadHandler
|
|
3069
|
+
);
|
|
3070
|
+
app.post(
|
|
3071
|
+
"/api/memory/save-messages",
|
|
3072
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3073
|
+
h({
|
|
3074
|
+
description: "Save messages",
|
|
3075
|
+
tags: ["memory"],
|
|
3076
|
+
parameters: [
|
|
3077
|
+
{
|
|
3078
|
+
name: "agentId",
|
|
3079
|
+
in: "query",
|
|
3080
|
+
required: true,
|
|
3081
|
+
schema: { type: "string" }
|
|
3082
|
+
}
|
|
3083
|
+
],
|
|
3084
|
+
requestBody: {
|
|
3085
|
+
required: true,
|
|
3086
|
+
content: {
|
|
3087
|
+
"application/json": {
|
|
3088
|
+
schema: {
|
|
3089
|
+
type: "object",
|
|
3090
|
+
properties: {
|
|
3091
|
+
messages: {
|
|
3092
|
+
type: "array",
|
|
3093
|
+
items: { type: "object" }
|
|
3094
|
+
}
|
|
3095
|
+
},
|
|
3096
|
+
required: ["messages"]
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
},
|
|
3101
|
+
responses: {
|
|
3102
|
+
200: {
|
|
3103
|
+
description: "Messages saved"
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
}),
|
|
3107
|
+
saveMessagesHandler
|
|
3108
|
+
);
|
|
3109
|
+
app.get(
|
|
3110
|
+
"/api/telemetry",
|
|
3111
|
+
h({
|
|
3112
|
+
description: "Get all traces",
|
|
3113
|
+
tags: ["telemetry"],
|
|
3114
|
+
responses: {
|
|
3115
|
+
200: {
|
|
3116
|
+
description: "List of all traces (paged)"
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
}),
|
|
3120
|
+
getTelemetryHandler
|
|
3121
|
+
);
|
|
3122
|
+
app.post(
|
|
3123
|
+
"/api/telemetry",
|
|
3124
|
+
h({
|
|
3125
|
+
description: "Store telemetry",
|
|
3126
|
+
tags: ["telemetry"],
|
|
3127
|
+
responses: {
|
|
3128
|
+
200: {
|
|
3129
|
+
description: "Traces stored"
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}),
|
|
3133
|
+
storeTelemetryHandler
|
|
3134
|
+
);
|
|
3135
|
+
app.get(
|
|
3136
|
+
"/api/workflows",
|
|
3137
|
+
h({
|
|
3138
|
+
description: "Get all workflows",
|
|
3139
|
+
tags: ["workflows"],
|
|
3140
|
+
responses: {
|
|
3141
|
+
200: {
|
|
3142
|
+
description: "List of all workflows"
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
}),
|
|
3146
|
+
getWorkflowsHandler
|
|
3147
|
+
);
|
|
3148
|
+
app.get(
|
|
3149
|
+
"/api/workflows/:workflowId",
|
|
3150
|
+
h({
|
|
3151
|
+
description: "Get workflow by ID",
|
|
3152
|
+
tags: ["workflows"],
|
|
3153
|
+
parameters: [
|
|
3154
|
+
{
|
|
3155
|
+
name: "workflowId",
|
|
3156
|
+
in: "path",
|
|
3157
|
+
required: true,
|
|
3158
|
+
schema: { type: "string" }
|
|
3159
|
+
}
|
|
3160
|
+
],
|
|
3161
|
+
responses: {
|
|
3162
|
+
200: {
|
|
3163
|
+
description: "Workflow details"
|
|
3164
|
+
},
|
|
3165
|
+
404: {
|
|
3166
|
+
description: "Workflow not found"
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
}),
|
|
3170
|
+
getWorkflowByIdHandler
|
|
3171
|
+
);
|
|
3172
|
+
app.get(
|
|
3173
|
+
"/api/workflows/:workflowId/runs",
|
|
3174
|
+
h({
|
|
3175
|
+
description: "Get all runs for a workflow",
|
|
3176
|
+
tags: ["workflows"],
|
|
3177
|
+
parameters: [
|
|
3178
|
+
{
|
|
3179
|
+
name: "workflowId",
|
|
3180
|
+
in: "path",
|
|
3181
|
+
required: true,
|
|
3182
|
+
schema: { type: "string" }
|
|
3183
|
+
}
|
|
3184
|
+
],
|
|
3185
|
+
responses: {
|
|
3186
|
+
200: {
|
|
3187
|
+
description: "List of workflow runs from storage"
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
}),
|
|
3191
|
+
getWorkflowRunsHandler
|
|
3192
|
+
);
|
|
3193
|
+
app.post(
|
|
3194
|
+
"/api/workflows/:workflowId/resume",
|
|
3195
|
+
h({
|
|
3196
|
+
description: "Resume a suspended workflow step",
|
|
3197
|
+
tags: ["workflows"],
|
|
3198
|
+
parameters: [
|
|
3199
|
+
{
|
|
3200
|
+
name: "workflowId",
|
|
3201
|
+
in: "path",
|
|
3202
|
+
required: true,
|
|
3203
|
+
schema: { type: "string" }
|
|
3204
|
+
},
|
|
3205
|
+
{
|
|
3206
|
+
name: "runId",
|
|
3207
|
+
in: "query",
|
|
3208
|
+
required: true,
|
|
3209
|
+
schema: { type: "string" }
|
|
3210
|
+
}
|
|
3211
|
+
],
|
|
3212
|
+
requestBody: {
|
|
3213
|
+
required: true,
|
|
3214
|
+
content: {
|
|
3215
|
+
"application/json": {
|
|
3216
|
+
schema: {
|
|
3217
|
+
type: "object",
|
|
3218
|
+
properties: {
|
|
3219
|
+
stepId: { type: "string" },
|
|
3220
|
+
context: { type: "object" }
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}),
|
|
3227
|
+
resumeWorkflowHandler
|
|
3228
|
+
);
|
|
3229
|
+
app.post(
|
|
3230
|
+
"/api/workflows/:workflowId/resumeAsync",
|
|
3231
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3232
|
+
h({
|
|
3233
|
+
description: "@deprecated Use /api/workflows/:workflowId/resume-async instead",
|
|
3234
|
+
tags: ["workflows"],
|
|
3235
|
+
parameters: [
|
|
3236
|
+
{
|
|
3237
|
+
name: "workflowId",
|
|
3238
|
+
in: "path",
|
|
3239
|
+
required: true,
|
|
3240
|
+
schema: { type: "string" }
|
|
3241
|
+
},
|
|
3242
|
+
{
|
|
3243
|
+
name: "runId",
|
|
3244
|
+
in: "query",
|
|
3245
|
+
required: true,
|
|
3246
|
+
schema: { type: "string" }
|
|
3247
|
+
}
|
|
3248
|
+
],
|
|
3249
|
+
requestBody: {
|
|
3250
|
+
required: true,
|
|
3251
|
+
content: {
|
|
3252
|
+
"application/json": {
|
|
3253
|
+
schema: {
|
|
3254
|
+
type: "object",
|
|
3255
|
+
properties: {
|
|
3256
|
+
stepId: { type: "string" },
|
|
3257
|
+
context: { type: "object" }
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
}),
|
|
3264
|
+
resumeAsyncWorkflowHandler
|
|
3265
|
+
);
|
|
3266
|
+
app.post(
|
|
3267
|
+
"/api/workflows/:workflowId/resume-async",
|
|
3268
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3269
|
+
h({
|
|
3270
|
+
description: "Resume a suspended workflow step",
|
|
3271
|
+
tags: ["workflows"],
|
|
3272
|
+
parameters: [
|
|
3273
|
+
{
|
|
3274
|
+
name: "workflowId",
|
|
3275
|
+
in: "path",
|
|
3276
|
+
required: true,
|
|
3277
|
+
schema: { type: "string" }
|
|
3278
|
+
},
|
|
3279
|
+
{
|
|
3280
|
+
name: "runId",
|
|
3281
|
+
in: "query",
|
|
3282
|
+
required: true,
|
|
3283
|
+
schema: { type: "string" }
|
|
3284
|
+
}
|
|
3285
|
+
],
|
|
3286
|
+
requestBody: {
|
|
3287
|
+
required: true,
|
|
3288
|
+
content: {
|
|
3289
|
+
"application/json": {
|
|
3290
|
+
schema: {
|
|
3291
|
+
type: "object",
|
|
3292
|
+
properties: {
|
|
3293
|
+
stepId: { type: "string" },
|
|
3294
|
+
context: { type: "object" }
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
}),
|
|
3301
|
+
resumeAsyncWorkflowHandler
|
|
3302
|
+
);
|
|
3303
|
+
app.post(
|
|
3304
|
+
"/api/workflows/:workflowId/createRun",
|
|
3305
|
+
h({
|
|
3306
|
+
description: "Create a new workflow run",
|
|
3307
|
+
tags: ["workflows"],
|
|
3308
|
+
parameters: [
|
|
3309
|
+
{
|
|
3310
|
+
name: "workflowId",
|
|
3311
|
+
in: "path",
|
|
3312
|
+
required: true,
|
|
3313
|
+
schema: { type: "string" }
|
|
3314
|
+
},
|
|
3315
|
+
{
|
|
3316
|
+
name: "runId",
|
|
3317
|
+
in: "query",
|
|
3318
|
+
required: false,
|
|
3319
|
+
schema: { type: "string" }
|
|
3320
|
+
}
|
|
3321
|
+
],
|
|
3322
|
+
responses: {
|
|
3323
|
+
200: {
|
|
3324
|
+
description: "New workflow run created"
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}),
|
|
3328
|
+
createRunHandler
|
|
3329
|
+
);
|
|
3330
|
+
app.post(
|
|
3331
|
+
"/api/workflows/:workflowId/startAsync",
|
|
3332
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3333
|
+
h({
|
|
3334
|
+
description: "Execute/Start a workflow",
|
|
3335
|
+
tags: ["workflows"],
|
|
3336
|
+
parameters: [
|
|
3337
|
+
{
|
|
3338
|
+
name: "workflowId",
|
|
3339
|
+
in: "path",
|
|
3340
|
+
required: true,
|
|
3341
|
+
schema: { type: "string" }
|
|
3342
|
+
},
|
|
3343
|
+
{
|
|
3344
|
+
name: "runId",
|
|
3345
|
+
in: "query",
|
|
3346
|
+
required: false,
|
|
3347
|
+
schema: { type: "string" }
|
|
3348
|
+
}
|
|
3349
|
+
],
|
|
3350
|
+
requestBody: {
|
|
3351
|
+
required: true,
|
|
3352
|
+
content: {
|
|
3353
|
+
"application/json": {
|
|
3354
|
+
schema: {
|
|
3355
|
+
type: "object",
|
|
3356
|
+
properties: {
|
|
3357
|
+
input: { type: "object" }
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
},
|
|
3363
|
+
responses: {
|
|
3364
|
+
200: {
|
|
3365
|
+
description: "Workflow execution result"
|
|
3366
|
+
},
|
|
3367
|
+
404: {
|
|
3368
|
+
description: "Workflow not found"
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}),
|
|
3372
|
+
startAsyncWorkflowHandler
|
|
3373
|
+
);
|
|
3374
|
+
app.post(
|
|
3375
|
+
"/api/workflows/:workflowId/start-async",
|
|
3376
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3377
|
+
h({
|
|
3378
|
+
description: "@deprecated Use /api/workflows/:workflowId/start-async instead",
|
|
3379
|
+
tags: ["workflows"],
|
|
3380
|
+
parameters: [
|
|
3381
|
+
{
|
|
3382
|
+
name: "workflowId",
|
|
3383
|
+
in: "path",
|
|
3384
|
+
required: true,
|
|
3385
|
+
schema: { type: "string" }
|
|
3386
|
+
},
|
|
3387
|
+
{
|
|
3388
|
+
name: "runId",
|
|
3389
|
+
in: "query",
|
|
3390
|
+
required: false,
|
|
3391
|
+
schema: { type: "string" }
|
|
3392
|
+
}
|
|
3393
|
+
],
|
|
3394
|
+
requestBody: {
|
|
3395
|
+
required: true,
|
|
3396
|
+
content: {
|
|
3397
|
+
"application/json": {
|
|
3398
|
+
schema: {
|
|
3399
|
+
type: "object",
|
|
3400
|
+
properties: {
|
|
3401
|
+
input: { type: "object" }
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
},
|
|
3407
|
+
responses: {
|
|
3408
|
+
200: {
|
|
3409
|
+
description: "Workflow execution result"
|
|
3410
|
+
},
|
|
3411
|
+
404: {
|
|
3412
|
+
description: "Workflow not found"
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
}),
|
|
3416
|
+
startAsyncWorkflowHandler
|
|
3417
|
+
);
|
|
3418
|
+
app.post(
|
|
3419
|
+
"/api/workflows/:workflowId/start",
|
|
3420
|
+
h({
|
|
3421
|
+
description: "Create and start a new workflow run",
|
|
3422
|
+
tags: ["workflows"],
|
|
3423
|
+
parameters: [
|
|
3424
|
+
{
|
|
3425
|
+
name: "workflowId",
|
|
3426
|
+
in: "path",
|
|
3427
|
+
required: true,
|
|
3428
|
+
schema: { type: "string" }
|
|
3429
|
+
},
|
|
3430
|
+
{
|
|
3431
|
+
name: "runId",
|
|
3432
|
+
in: "query",
|
|
3433
|
+
required: true,
|
|
3434
|
+
schema: { type: "string" }
|
|
3435
|
+
}
|
|
3436
|
+
],
|
|
3437
|
+
requestBody: {
|
|
3438
|
+
required: true,
|
|
3439
|
+
content: {
|
|
3440
|
+
"application/json": {
|
|
3441
|
+
schema: {
|
|
3442
|
+
type: "object",
|
|
3443
|
+
properties: {
|
|
3444
|
+
input: { type: "object" }
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
},
|
|
3450
|
+
responses: {
|
|
3451
|
+
200: {
|
|
3452
|
+
description: "Workflow run started"
|
|
3453
|
+
},
|
|
3454
|
+
404: {
|
|
3455
|
+
description: "Workflow not found"
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
}),
|
|
3459
|
+
startWorkflowRunHandler
|
|
3460
|
+
);
|
|
3461
|
+
app.get(
|
|
3462
|
+
"/api/workflows/:workflowId/watch",
|
|
3463
|
+
h({
|
|
3464
|
+
description: "Watch workflow transitions in real-time",
|
|
3465
|
+
parameters: [
|
|
3466
|
+
{
|
|
3467
|
+
name: "workflowId",
|
|
3468
|
+
in: "path",
|
|
3469
|
+
required: true,
|
|
3470
|
+
schema: { type: "string" }
|
|
3471
|
+
},
|
|
3472
|
+
{
|
|
3473
|
+
name: "runId",
|
|
3474
|
+
in: "query",
|
|
3475
|
+
required: false,
|
|
3476
|
+
schema: { type: "string" }
|
|
3477
|
+
}
|
|
3478
|
+
],
|
|
3479
|
+
tags: ["workflows"],
|
|
3480
|
+
responses: {
|
|
3481
|
+
200: {
|
|
3482
|
+
description: "Workflow transitions in real-time"
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
}),
|
|
3486
|
+
watchWorkflowHandler
|
|
3487
|
+
);
|
|
3488
|
+
app.get(
|
|
3489
|
+
"/api/logs",
|
|
3490
|
+
h({
|
|
3491
|
+
description: "Get all logs",
|
|
3492
|
+
tags: ["logs"],
|
|
3493
|
+
parameters: [
|
|
3494
|
+
{
|
|
3495
|
+
name: "transportId",
|
|
3496
|
+
in: "query",
|
|
3497
|
+
required: true,
|
|
3498
|
+
schema: { type: "string" }
|
|
3499
|
+
}
|
|
3500
|
+
],
|
|
3501
|
+
responses: {
|
|
3502
|
+
200: {
|
|
3503
|
+
description: "List of all logs"
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
}),
|
|
3507
|
+
getLogsHandler
|
|
3508
|
+
);
|
|
3509
|
+
app.get(
|
|
3510
|
+
"/api/logs/transports",
|
|
3511
|
+
h({
|
|
3512
|
+
description: "List of all log transports",
|
|
3513
|
+
tags: ["logs"],
|
|
3514
|
+
responses: {
|
|
3515
|
+
200: {
|
|
3516
|
+
description: "List of all log transports"
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
}),
|
|
3520
|
+
getLogTransports
|
|
3521
|
+
);
|
|
3522
|
+
app.get(
|
|
3523
|
+
"/api/logs/:runId",
|
|
3524
|
+
h({
|
|
3525
|
+
description: "Get logs by run ID",
|
|
3526
|
+
tags: ["logs"],
|
|
3527
|
+
parameters: [
|
|
3528
|
+
{
|
|
3529
|
+
name: "runId",
|
|
3530
|
+
in: "path",
|
|
3531
|
+
required: true,
|
|
3532
|
+
schema: { type: "string" }
|
|
3533
|
+
},
|
|
3534
|
+
{
|
|
3535
|
+
name: "transportId",
|
|
3536
|
+
in: "query",
|
|
3537
|
+
required: true,
|
|
3538
|
+
schema: { type: "string" }
|
|
3539
|
+
}
|
|
3540
|
+
],
|
|
3541
|
+
responses: {
|
|
3542
|
+
200: {
|
|
3543
|
+
description: "List of logs for run ID"
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
}),
|
|
3547
|
+
getLogsByRunIdHandler
|
|
3548
|
+
);
|
|
3549
|
+
app.get(
|
|
3550
|
+
"/api/tools",
|
|
3551
|
+
h({
|
|
3552
|
+
description: "Get all tools",
|
|
3553
|
+
tags: ["tools"],
|
|
3554
|
+
responses: {
|
|
3555
|
+
200: {
|
|
3556
|
+
description: "List of all tools"
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
}),
|
|
3560
|
+
getToolsHandler
|
|
3561
|
+
);
|
|
3562
|
+
app.get(
|
|
3563
|
+
"/api/tools/:toolId",
|
|
3564
|
+
h({
|
|
3565
|
+
description: "Get tool by ID",
|
|
3566
|
+
tags: ["tools"],
|
|
3567
|
+
parameters: [
|
|
3568
|
+
{
|
|
3569
|
+
name: "toolId",
|
|
3570
|
+
in: "path",
|
|
3571
|
+
required: true,
|
|
3572
|
+
schema: { type: "string" }
|
|
3573
|
+
}
|
|
3574
|
+
],
|
|
3575
|
+
responses: {
|
|
3576
|
+
200: {
|
|
3577
|
+
description: "Tool details"
|
|
3578
|
+
},
|
|
3579
|
+
404: {
|
|
3580
|
+
description: "Tool not found"
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}),
|
|
3584
|
+
getToolByIdHandler
|
|
3585
|
+
);
|
|
3586
|
+
app.post(
|
|
3587
|
+
"/api/tools/:toolId/execute",
|
|
3588
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3589
|
+
h({
|
|
3590
|
+
description: "Execute a tool",
|
|
3591
|
+
tags: ["tools"],
|
|
3592
|
+
parameters: [
|
|
3593
|
+
{
|
|
3594
|
+
name: "toolId",
|
|
3595
|
+
in: "path",
|
|
3596
|
+
required: true,
|
|
3597
|
+
schema: { type: "string" }
|
|
3598
|
+
}
|
|
3599
|
+
],
|
|
3600
|
+
requestBody: {
|
|
3601
|
+
required: true,
|
|
3602
|
+
content: {
|
|
3603
|
+
"application/json": {
|
|
3604
|
+
schema: {
|
|
3605
|
+
type: "object",
|
|
3606
|
+
properties: {
|
|
3607
|
+
data: { type: "object" }
|
|
3608
|
+
},
|
|
3609
|
+
required: ["data"]
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
},
|
|
3614
|
+
responses: {
|
|
3615
|
+
200: {
|
|
3616
|
+
description: "Tool execution result"
|
|
3617
|
+
},
|
|
3618
|
+
404: {
|
|
3619
|
+
description: "Tool not found"
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
}),
|
|
3623
|
+
executeToolHandler(tools)
|
|
3624
|
+
);
|
|
3625
|
+
app.post(
|
|
3626
|
+
"/api/vector/:vectorName/upsert",
|
|
3627
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3628
|
+
h({
|
|
3629
|
+
description: "Upsert vectors into an index",
|
|
3630
|
+
tags: ["vector"],
|
|
3631
|
+
parameters: [
|
|
3632
|
+
{
|
|
3633
|
+
name: "vectorName",
|
|
3634
|
+
in: "path",
|
|
3635
|
+
required: true,
|
|
3636
|
+
schema: { type: "string" }
|
|
3637
|
+
}
|
|
3638
|
+
],
|
|
3639
|
+
requestBody: {
|
|
3640
|
+
required: true,
|
|
3641
|
+
content: {
|
|
3642
|
+
"application/json": {
|
|
3643
|
+
schema: {
|
|
3644
|
+
type: "object",
|
|
3645
|
+
properties: {
|
|
3646
|
+
indexName: { type: "string" },
|
|
3647
|
+
vectors: {
|
|
3648
|
+
type: "array",
|
|
3649
|
+
items: {
|
|
3650
|
+
type: "array",
|
|
3651
|
+
items: { type: "number" }
|
|
3652
|
+
}
|
|
3653
|
+
},
|
|
3654
|
+
metadata: {
|
|
3655
|
+
type: "array",
|
|
3656
|
+
items: { type: "object" }
|
|
3657
|
+
},
|
|
3658
|
+
ids: {
|
|
3659
|
+
type: "array",
|
|
3660
|
+
items: { type: "string" }
|
|
3661
|
+
}
|
|
3662
|
+
},
|
|
3663
|
+
required: ["indexName", "vectors"]
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
},
|
|
3668
|
+
responses: {
|
|
3669
|
+
200: {
|
|
3670
|
+
description: "Vectors upserted successfully"
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
}),
|
|
3674
|
+
upsertVectors
|
|
3675
|
+
);
|
|
3676
|
+
app.post(
|
|
3677
|
+
"/api/vector/:vectorName/create-index",
|
|
3678
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3679
|
+
h({
|
|
3680
|
+
description: "Create a new vector index",
|
|
3681
|
+
tags: ["vector"],
|
|
3682
|
+
parameters: [
|
|
3683
|
+
{
|
|
3684
|
+
name: "vectorName",
|
|
3685
|
+
in: "path",
|
|
3686
|
+
required: true,
|
|
3687
|
+
schema: { type: "string" }
|
|
3688
|
+
}
|
|
3689
|
+
],
|
|
3690
|
+
requestBody: {
|
|
3691
|
+
required: true,
|
|
3692
|
+
content: {
|
|
3693
|
+
"application/json": {
|
|
3694
|
+
schema: {
|
|
3695
|
+
type: "object",
|
|
3696
|
+
properties: {
|
|
3697
|
+
indexName: { type: "string" },
|
|
3698
|
+
dimension: { type: "number" },
|
|
3699
|
+
metric: {
|
|
3700
|
+
type: "string",
|
|
3701
|
+
enum: ["cosine", "euclidean", "dotproduct"]
|
|
3702
|
+
}
|
|
3703
|
+
},
|
|
3704
|
+
required: ["indexName", "dimension"]
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
}
|
|
3708
|
+
},
|
|
3709
|
+
responses: {
|
|
3710
|
+
200: {
|
|
3711
|
+
description: "Index created successfully"
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
}),
|
|
3715
|
+
createIndex
|
|
3716
|
+
);
|
|
3717
|
+
app.post(
|
|
3718
|
+
"/api/vector/:vectorName/query",
|
|
3719
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3720
|
+
h({
|
|
3721
|
+
description: "Query vectors from an index",
|
|
3722
|
+
tags: ["vector"],
|
|
3723
|
+
parameters: [
|
|
3724
|
+
{
|
|
3725
|
+
name: "vectorName",
|
|
3726
|
+
in: "path",
|
|
3727
|
+
required: true,
|
|
3728
|
+
schema: { type: "string" }
|
|
3729
|
+
}
|
|
3730
|
+
],
|
|
3731
|
+
requestBody: {
|
|
3732
|
+
required: true,
|
|
3733
|
+
content: {
|
|
3734
|
+
"application/json": {
|
|
3735
|
+
schema: {
|
|
3736
|
+
type: "object",
|
|
3737
|
+
properties: {
|
|
3738
|
+
indexName: { type: "string" },
|
|
3739
|
+
queryVector: {
|
|
3740
|
+
type: "array",
|
|
3741
|
+
items: { type: "number" }
|
|
3742
|
+
},
|
|
3743
|
+
topK: { type: "number" },
|
|
3744
|
+
filter: { type: "object" },
|
|
3745
|
+
includeVector: { type: "boolean" }
|
|
3746
|
+
},
|
|
3747
|
+
required: ["indexName", "queryVector"]
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
},
|
|
3752
|
+
responses: {
|
|
3753
|
+
200: {
|
|
3754
|
+
description: "Query results"
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
}),
|
|
3758
|
+
queryVectors
|
|
3759
|
+
);
|
|
3760
|
+
app.get(
|
|
3761
|
+
"/api/vector/:vectorName/indexes",
|
|
3762
|
+
h({
|
|
3763
|
+
description: "List all indexes for a vector store",
|
|
3764
|
+
tags: ["vector"],
|
|
3765
|
+
parameters: [
|
|
3766
|
+
{
|
|
3767
|
+
name: "vectorName",
|
|
3768
|
+
in: "path",
|
|
3769
|
+
required: true,
|
|
3770
|
+
schema: { type: "string" }
|
|
3771
|
+
}
|
|
3772
|
+
],
|
|
3773
|
+
responses: {
|
|
3774
|
+
200: {
|
|
3775
|
+
description: "List of indexes"
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
}),
|
|
3779
|
+
listIndexes
|
|
3780
|
+
);
|
|
3781
|
+
app.get(
|
|
3782
|
+
"/api/vector/:vectorName/indexes/:indexName",
|
|
3783
|
+
h({
|
|
3784
|
+
description: "Get details about a specific index",
|
|
3785
|
+
tags: ["vector"],
|
|
3786
|
+
parameters: [
|
|
3787
|
+
{
|
|
3788
|
+
name: "vectorName",
|
|
3789
|
+
in: "path",
|
|
3790
|
+
required: true,
|
|
3791
|
+
schema: { type: "string" }
|
|
3792
|
+
},
|
|
3793
|
+
{
|
|
3794
|
+
name: "indexName",
|
|
3795
|
+
in: "path",
|
|
3796
|
+
required: true,
|
|
3797
|
+
schema: { type: "string" }
|
|
3798
|
+
}
|
|
3799
|
+
],
|
|
3800
|
+
responses: {
|
|
3801
|
+
200: {
|
|
3802
|
+
description: "Index details"
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
}),
|
|
3806
|
+
describeIndex
|
|
3807
|
+
);
|
|
3808
|
+
app.delete(
|
|
3809
|
+
"/api/vector/:vectorName/indexes/:indexName",
|
|
3810
|
+
h({
|
|
3811
|
+
description: "Delete a specific index",
|
|
3812
|
+
tags: ["vector"],
|
|
3813
|
+
parameters: [
|
|
3814
|
+
{
|
|
3815
|
+
name: "vectorName",
|
|
3816
|
+
in: "path",
|
|
3817
|
+
required: true,
|
|
3818
|
+
schema: { type: "string" }
|
|
3819
|
+
},
|
|
3820
|
+
{
|
|
3821
|
+
name: "indexName",
|
|
3822
|
+
in: "path",
|
|
3823
|
+
required: true,
|
|
3824
|
+
schema: { type: "string" }
|
|
3825
|
+
}
|
|
3826
|
+
],
|
|
3827
|
+
responses: {
|
|
3828
|
+
200: {
|
|
3829
|
+
description: "Index deleted successfully"
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
}),
|
|
3833
|
+
deleteIndex
|
|
3834
|
+
);
|
|
3835
|
+
app.get(
|
|
3836
|
+
"/openapi.json",
|
|
3837
|
+
f(app, {
|
|
3838
|
+
documentation: {
|
|
3839
|
+
info: { title: "Mastra API", version: "1.0.0", description: "Mastra API" }
|
|
3840
|
+
}
|
|
3841
|
+
})
|
|
3842
|
+
);
|
|
3843
|
+
app.get("/swagger-ui", middleware({ url: "/openapi.json" }));
|
|
3844
|
+
if (options?.swaggerUI) {
|
|
3845
|
+
app.get("/swagger-ui", middleware({ url: "/openapi.json" }));
|
|
3846
|
+
}
|
|
3847
|
+
app.post(
|
|
3848
|
+
"/api/a2a",
|
|
3849
|
+
h({
|
|
3850
|
+
description: "A2A Protocol endpoint for agent-to-agent communication",
|
|
3851
|
+
tags: ["a2a"],
|
|
3852
|
+
requestBody: {
|
|
3853
|
+
content: {
|
|
3854
|
+
"application/json": {
|
|
3855
|
+
schema: { type: "object" }
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
},
|
|
3859
|
+
responses: {
|
|
3860
|
+
200: {
|
|
3861
|
+
description: "A2A response",
|
|
3862
|
+
content: {
|
|
3863
|
+
"application/json": {
|
|
3864
|
+
schema: { type: "object" }
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3869
|
+
}),
|
|
3870
|
+
handleA2ARequestEndpoint
|
|
3871
|
+
);
|
|
3872
|
+
app.get(
|
|
3873
|
+
"/api/a2a/agent-card",
|
|
3874
|
+
h({
|
|
3875
|
+
description: "Get the A2A agent card for this agent",
|
|
3876
|
+
tags: ["a2a"],
|
|
3877
|
+
responses: {
|
|
3878
|
+
200: {
|
|
3879
|
+
description: "Agent card",
|
|
3880
|
+
content: {
|
|
3881
|
+
"application/json": {
|
|
3882
|
+
schema: { type: "object" }
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
}),
|
|
3888
|
+
handleAgentCardEndpoint
|
|
3889
|
+
);
|
|
3890
|
+
if (options?.playground) {
|
|
3891
|
+
app.get("/refresh-events", handleClientsRefresh);
|
|
3892
|
+
app.post("/__refresh", handleTriggerClientsRefresh);
|
|
3893
|
+
app.use("/assets/*", async (c2, next) => {
|
|
3894
|
+
const path = c2.req.path;
|
|
3895
|
+
if (path.endsWith(".js")) {
|
|
3896
|
+
c2.header("Content-Type", "application/javascript");
|
|
3897
|
+
} else if (path.endsWith(".css")) {
|
|
3898
|
+
c2.header("Content-Type", "text/css");
|
|
3899
|
+
}
|
|
3900
|
+
await next();
|
|
3901
|
+
});
|
|
3902
|
+
app.use(
|
|
3903
|
+
"/assets/*",
|
|
3904
|
+
serveStatic({
|
|
3905
|
+
root: "./playground/assets"
|
|
3906
|
+
})
|
|
3907
|
+
);
|
|
3908
|
+
app.use(
|
|
3909
|
+
"*",
|
|
3910
|
+
serveStatic({
|
|
3911
|
+
root: "./playground"
|
|
3912
|
+
})
|
|
3913
|
+
);
|
|
3914
|
+
}
|
|
3915
|
+
app.get("*", async (c2, next) => {
|
|
3916
|
+
if (c2.req.path.startsWith("/api/") || c2.req.path.startsWith("/swagger-ui") || c2.req.path.startsWith("/openapi.json")) {
|
|
3917
|
+
return await next();
|
|
3918
|
+
}
|
|
3919
|
+
if (options?.playground) {
|
|
3920
|
+
const indexHtml = await promises.readFile(posix.join(process.cwd(), "./playground/index.html"), "utf-8");
|
|
3921
|
+
return c2.newResponse(indexHtml, 200, { "Content-Type": "text/html" });
|
|
3922
|
+
}
|
|
3923
|
+
return c2.newResponse(html2, 200, { "Content-Type": "text/html" });
|
|
3924
|
+
});
|
|
3925
|
+
return app;
|
|
3926
|
+
}
|
|
3927
|
+
async function createNodeServer(mastra, options = {}) {
|
|
3928
|
+
const app = await createHonoServer(mastra, options);
|
|
3929
|
+
const serverOptions = mastra.getServer();
|
|
3930
|
+
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
3931
|
+
const server = serve(
|
|
3932
|
+
{
|
|
3933
|
+
fetch: app.fetch,
|
|
3934
|
+
port
|
|
3935
|
+
},
|
|
3936
|
+
() => {
|
|
3937
|
+
const logger2 = mastra.getLogger();
|
|
3938
|
+
logger2.info(`\u{1F984} Mastra API running on port ${port}/api`);
|
|
3939
|
+
logger2.info(`\u{1F4DA} Open API documentation available at http://localhost:${port}/openapi.json`);
|
|
3940
|
+
if (options?.swaggerUI) {
|
|
3941
|
+
logger2.info(`\u{1F9EA} Swagger UI available at http://localhost:${port}/swagger-ui`);
|
|
3942
|
+
}
|
|
3943
|
+
if (options?.playground) {
|
|
3944
|
+
logger2.info(`\u{1F468}\u200D\u{1F4BB} Playground available at http://localhost:${port}/`);
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
);
|
|
3948
|
+
return server;
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
exports.createHonoServer = createHonoServer;
|
|
3952
|
+
exports.createNodeServer = createNodeServer;
|