@mastra/deployer 1.37.0-alpha.1 → 1.37.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/_types/@hono_node-server/dist/index.d.ts +8 -0
- package/dist/_types/@hono_node-server/dist/listener.d.ts +13 -0
- package/dist/_types/@hono_node-server/dist/request.d.ts +25 -0
- package/dist/_types/@hono_node-server/dist/server.d.ts +10 -0
- package/dist/_types/@hono_node-server/dist/types.d.ts +44 -0
- package/dist/_types/@mastra_hono/dist/auth-middleware.d.ts +8 -0
- package/dist/_types/@mastra_hono/dist/browser-stream/index.d.ts +35 -0
- package/dist/_types/@mastra_hono/dist/index.d.ts +59 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/server/index.cjs +16 -205
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +12 -201
- package/dist/server/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mastra/deployer
|
|
2
2
|
|
|
3
|
+
## 1.37.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`df1947a`](https://github.com/mastra-ai/mastra/commit/df1947affa40f742067542251fac7ca759492ef4), [`ee59b74`](https://github.com/mastra-ai/mastra/commit/ee59b743ce73ad11784b4d9c6fbba8568edee1c8), [`a97b1a0`](https://github.com/mastra-ai/mastra/commit/a97b1a0abaed83946c3519d1e0f680d0815b8a67)]:
|
|
8
|
+
- @mastra/core@1.37.0-alpha.2
|
|
9
|
+
- @mastra/server@1.37.0-alpha.2
|
|
10
|
+
|
|
3
11
|
## 1.37.0-alpha.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createAdaptorServer, serve } from './server.js';
|
|
2
|
+
export { getRequestListener } from './listener.js';
|
|
3
|
+
export { RequestError } from './request.js';
|
|
4
|
+
export { Http2Bindings, HttpBindings, ServerType } from './types.js';
|
|
5
|
+
import 'node:net';
|
|
6
|
+
import 'node:http';
|
|
7
|
+
import 'node:http2';
|
|
8
|
+
import 'node:https';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
3
|
+
import { FetchCallback, CustomErrorHandler } from './types.js';
|
|
4
|
+
import 'node:https';
|
|
5
|
+
|
|
6
|
+
declare const getRequestListener: (fetchCallback: FetchCallback, options?: {
|
|
7
|
+
hostname?: string;
|
|
8
|
+
errorHandler?: CustomErrorHandler;
|
|
9
|
+
overrideGlobalObjects?: boolean;
|
|
10
|
+
autoCleanupIncoming?: boolean;
|
|
11
|
+
}) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { getRequestListener };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http';
|
|
2
|
+
import { Http2ServerRequest } from 'node:http2';
|
|
3
|
+
|
|
4
|
+
declare class RequestError extends Error {
|
|
5
|
+
constructor(message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
declare const toRequestError: (e: unknown) => RequestError;
|
|
10
|
+
declare const GlobalRequest: {
|
|
11
|
+
new (input: RequestInfo | URL, init?: RequestInit): globalThis.Request;
|
|
12
|
+
prototype: globalThis.Request;
|
|
13
|
+
};
|
|
14
|
+
declare class Request extends GlobalRequest {
|
|
15
|
+
constructor(input: string | Request, options?: RequestInit);
|
|
16
|
+
}
|
|
17
|
+
type IncomingMessageWithWrapBodyStream = IncomingMessage & {
|
|
18
|
+
[wrapBodyStream]: boolean;
|
|
19
|
+
};
|
|
20
|
+
declare const wrapBodyStream: unique symbol;
|
|
21
|
+
declare const abortControllerKey: unique symbol;
|
|
22
|
+
declare const getAbortController: unique symbol;
|
|
23
|
+
declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
|
|
24
|
+
|
|
25
|
+
export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AddressInfo } from 'node:net';
|
|
2
|
+
import { Options, ServerType } from './types.js';
|
|
3
|
+
import 'node:http';
|
|
4
|
+
import 'node:http2';
|
|
5
|
+
import 'node:https';
|
|
6
|
+
|
|
7
|
+
declare const createAdaptorServer: (options: Options) => ServerType;
|
|
8
|
+
declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
|
|
9
|
+
|
|
10
|
+
export { createAdaptorServer, serve };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
|
|
2
|
+
import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
|
|
3
|
+
import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
|
|
4
|
+
|
|
5
|
+
type HttpBindings = {
|
|
6
|
+
incoming: IncomingMessage;
|
|
7
|
+
outgoing: ServerResponse;
|
|
8
|
+
};
|
|
9
|
+
type Http2Bindings = {
|
|
10
|
+
incoming: Http2ServerRequest;
|
|
11
|
+
outgoing: Http2ServerResponse;
|
|
12
|
+
};
|
|
13
|
+
type FetchCallback = (request: Request, env: HttpBindings | Http2Bindings) => Promise<unknown> | unknown;
|
|
14
|
+
type NextHandlerOption = {
|
|
15
|
+
fetch: FetchCallback;
|
|
16
|
+
};
|
|
17
|
+
type ServerType = Server | Http2Server | Http2SecureServer;
|
|
18
|
+
type createHttpOptions = {
|
|
19
|
+
serverOptions?: ServerOptions$1;
|
|
20
|
+
createServer?: typeof createServer;
|
|
21
|
+
};
|
|
22
|
+
type createHttpsOptions = {
|
|
23
|
+
serverOptions?: ServerOptions$2;
|
|
24
|
+
createServer?: typeof createServer$1;
|
|
25
|
+
};
|
|
26
|
+
type createHttp2Options = {
|
|
27
|
+
serverOptions?: ServerOptions$3;
|
|
28
|
+
createServer?: typeof createServer$2;
|
|
29
|
+
};
|
|
30
|
+
type createSecureHttp2Options = {
|
|
31
|
+
serverOptions?: SecureServerOptions;
|
|
32
|
+
createServer?: typeof createSecureServer;
|
|
33
|
+
};
|
|
34
|
+
type ServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
|
35
|
+
type Options = {
|
|
36
|
+
fetch: FetchCallback;
|
|
37
|
+
overrideGlobalObjects?: boolean;
|
|
38
|
+
autoCleanupIncoming?: boolean;
|
|
39
|
+
port?: number;
|
|
40
|
+
hostname?: string;
|
|
41
|
+
} & ServerOptions;
|
|
42
|
+
type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
|
|
43
|
+
|
|
44
|
+
export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import type { MiddlewareHandler } from 'hono';
|
|
3
|
+
export interface HonoAuthMiddlewareOptions {
|
|
4
|
+
mastra: Mastra;
|
|
5
|
+
requiresAuth?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function createAuthMiddleware({ mastra, requiresAuth }: HonoAuthMiddlewareOptions): MiddlewareHandler;
|
|
8
|
+
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BrowserStreamConfig, BrowserStreamResult } from '@mastra/server/browser-stream';
|
|
2
|
+
import type { Env, Hono, Schema } from 'hono';
|
|
3
|
+
/**
|
|
4
|
+
* Set up WebSocket-based browser stream endpoint for real-time screencast viewing.
|
|
5
|
+
*
|
|
6
|
+
* Creates a WebSocket route at `/browser/:agentId/stream` that:
|
|
7
|
+
* - Accepts viewer connections
|
|
8
|
+
* - Starts screencast when first viewer connects
|
|
9
|
+
* - Broadcasts frames to all connected viewers
|
|
10
|
+
* - Stops screencast when last viewer disconnects
|
|
11
|
+
*
|
|
12
|
+
* **Note**: Requires `ws` package to be installed. If not available, returns null
|
|
13
|
+
* and logs a warning. Browser streaming will be disabled but everything else works.
|
|
14
|
+
*
|
|
15
|
+
* @param app - The Hono application instance
|
|
16
|
+
* @param config - Configuration for browser stream
|
|
17
|
+
* @returns Object containing injectWebSocket function and registry instance, or null if ws is not available
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { Hono } from 'hono';
|
|
22
|
+
* import { serve } from '@hono/node-server';
|
|
23
|
+
* import { setupBrowserStream } from '@mastra/hono';
|
|
24
|
+
*
|
|
25
|
+
* const app = new Hono();
|
|
26
|
+
* const browserStream = await setupBrowserStream(app, {
|
|
27
|
+
* getToolset: (agentId) => browserToolsets.get(agentId),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const server = serve({ fetch: app.fetch, port: 4111 });
|
|
31
|
+
* browserStream?.injectWebSocket(server);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function setupBrowserStream<E extends Env, S extends Schema, B extends string>(app: Hono<E, S, B>, config: BrowserStreamConfig): Promise<BrowserStreamResult | null>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
4
|
+
import type { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
5
|
+
import type { ParsedRequestParams, ServerRoute } from '@mastra/server/server-adapter';
|
|
6
|
+
import { MastraServer as MastraServerBase } from '@mastra/server/server-adapter';
|
|
7
|
+
import type { Context, HonoRequest, MiddlewareHandler } from 'hono';
|
|
8
|
+
export { createAuthMiddleware } from './auth-middleware.js';
|
|
9
|
+
export type { HonoAuthMiddlewareOptions } from './auth-middleware.js';
|
|
10
|
+
export { setupBrowserStream } from './browser-stream/index.js';
|
|
11
|
+
export type HonoVariables = {
|
|
12
|
+
mastra: Mastra;
|
|
13
|
+
requestContext: RequestContext;
|
|
14
|
+
registeredTools: ToolsInput;
|
|
15
|
+
abortSignal: AbortSignal;
|
|
16
|
+
taskStore: InMemoryTaskStore;
|
|
17
|
+
customRouteAuthConfig?: Map<string, boolean>;
|
|
18
|
+
cachedBody?: unknown;
|
|
19
|
+
};
|
|
20
|
+
export type HonoBindings = {};
|
|
21
|
+
/**
|
|
22
|
+
* Generic handler function type compatible across Hono versions.
|
|
23
|
+
* Uses a minimal signature that all Hono middleware handlers satisfy.
|
|
24
|
+
*/
|
|
25
|
+
type HonoRouteHandler = (...args: any[]) => any;
|
|
26
|
+
/**
|
|
27
|
+
* Minimal interface representing what MastraServer needs from a Hono app.
|
|
28
|
+
* This allows any Hono app instance to be passed without strict generic matching,
|
|
29
|
+
* avoiding the version mismatch issues that occur with Hono's strict generic types.
|
|
30
|
+
*/
|
|
31
|
+
export interface HonoApp {
|
|
32
|
+
use(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
33
|
+
get(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
34
|
+
post(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
35
|
+
put(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
36
|
+
delete(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
37
|
+
patch(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
38
|
+
all(path: string, ...handlers: HonoRouteHandler[]): unknown;
|
|
39
|
+
}
|
|
40
|
+
export declare class MastraServer extends MastraServerBase<HonoApp, HonoRequest, Context> {
|
|
41
|
+
createContextMiddleware(): MiddlewareHandler;
|
|
42
|
+
stream(route: ServerRoute, res: Context, result: {
|
|
43
|
+
fullStream: ReadableStream;
|
|
44
|
+
}): Promise<any>;
|
|
45
|
+
getParams(route: ServerRoute, request: HonoRequest): Promise<ParsedRequestParams>;
|
|
46
|
+
/**
|
|
47
|
+
* Parse FormData into a plain object, converting File objects to Buffers.
|
|
48
|
+
*/
|
|
49
|
+
private parseFormData;
|
|
50
|
+
sendResponse(route: ServerRoute, response: Context, result: unknown, prefix?: string): Promise<any>;
|
|
51
|
+
registerRoute(app: HonoApp, route: ServerRoute, { prefix: prefixParam }?: {
|
|
52
|
+
prefix?: string;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
registerCustomApiRoutes(): Promise<void>;
|
|
55
|
+
registerContextMiddleware(): void;
|
|
56
|
+
registerAuthMiddleware(): void;
|
|
57
|
+
registerHttpLoggingMiddleware(): void;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-deployer
|
|
|
3
3
|
description: Documentation for @mastra/deployer. Use when working with @mastra/deployer APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/deployer"
|
|
6
|
-
version: "1.37.0-alpha.
|
|
6
|
+
version: "1.37.0-alpha.2"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/server/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var path = require('path');
|
|
|
7
7
|
var url = require('url');
|
|
8
8
|
var http = require('http');
|
|
9
9
|
var http2 = require('http2');
|
|
10
|
-
var stream
|
|
10
|
+
var stream = require('stream');
|
|
11
11
|
var crypto = require('crypto');
|
|
12
12
|
var mime = require('hono/utils/mime');
|
|
13
13
|
var fs = require('fs');
|
|
@@ -17,6 +17,8 @@ var tools = require('@mastra/core/tools');
|
|
|
17
17
|
var serverAdapter = require('@mastra/server/server-adapter');
|
|
18
18
|
var util = require('util');
|
|
19
19
|
var buffer = require('buffer');
|
|
20
|
+
var bodyLimit = require('hono/body-limit');
|
|
21
|
+
var streaming = require('hono/streaming');
|
|
20
22
|
var auth = require('@mastra/server/auth');
|
|
21
23
|
var browserStream = require('@mastra/server/browser-stream');
|
|
22
24
|
var store = require('@mastra/server/a2a/store');
|
|
@@ -65,7 +67,7 @@ var toRequestError = (e) => {
|
|
|
65
67
|
return new RequestError(e.message, { cause: e });
|
|
66
68
|
};
|
|
67
69
|
var GlobalRequest = global.Request;
|
|
68
|
-
var
|
|
70
|
+
var Request = class extends GlobalRequest {
|
|
69
71
|
constructor(input, options) {
|
|
70
72
|
if (typeof input === "object" && getRequestCache in input) {
|
|
71
73
|
input = input[getRequestCache]();
|
|
@@ -97,7 +99,7 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
97
99
|
};
|
|
98
100
|
if (method === "TRACE") {
|
|
99
101
|
init.method = "GET";
|
|
100
|
-
const req = new
|
|
102
|
+
const req = new Request(url, init);
|
|
101
103
|
Object.defineProperty(req, "method", {
|
|
102
104
|
get() {
|
|
103
105
|
return "TRACE";
|
|
@@ -118,7 +120,7 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
118
120
|
init.body = new ReadableStream({
|
|
119
121
|
async pull(controller) {
|
|
120
122
|
try {
|
|
121
|
-
reader ||= stream
|
|
123
|
+
reader ||= stream.Readable.toWeb(incoming).getReader();
|
|
122
124
|
const { done, value } = await reader.read();
|
|
123
125
|
if (done) {
|
|
124
126
|
controller.close();
|
|
@@ -131,10 +133,10 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
131
133
|
}
|
|
132
134
|
});
|
|
133
135
|
} else {
|
|
134
|
-
init.body = stream
|
|
136
|
+
init.body = stream.Readable.toWeb(incoming);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
|
-
return new
|
|
139
|
+
return new Request(url, init);
|
|
138
140
|
};
|
|
139
141
|
var getRequestCache = /* @__PURE__ */ Symbol("getRequestCache");
|
|
140
142
|
var requestCache = /* @__PURE__ */ Symbol("requestCache");
|
|
@@ -206,7 +208,7 @@ Object.defineProperty(requestPrototype, /* @__PURE__ */ Symbol.for("nodejs.util.
|
|
|
206
208
|
return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
|
|
207
209
|
}
|
|
208
210
|
});
|
|
209
|
-
Object.setPrototypeOf(requestPrototype,
|
|
211
|
+
Object.setPrototypeOf(requestPrototype, Request.prototype);
|
|
210
212
|
var newRequest = (incoming, defaultHostname) => {
|
|
211
213
|
const req = Object.create(requestPrototype);
|
|
212
214
|
req[incomingKey] = incoming;
|
|
@@ -575,9 +577,9 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
575
577
|
};
|
|
576
578
|
var getRequestListener = (fetchCallback, options = {}) => {
|
|
577
579
|
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
578
|
-
if (options.overrideGlobalObjects !== false && global.Request !==
|
|
580
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request) {
|
|
579
581
|
Object.defineProperty(global, "Request", {
|
|
580
|
-
value:
|
|
582
|
+
value: Request
|
|
581
583
|
});
|
|
582
584
|
Object.defineProperty(global, "Response", {
|
|
583
585
|
value: Response2
|
|
@@ -691,7 +693,7 @@ var pr54206Applied = () => {
|
|
|
691
693
|
var useReadableToWeb = pr54206Applied();
|
|
692
694
|
var createStreamBody = (stream2) => {
|
|
693
695
|
if (useReadableToWeb) {
|
|
694
|
-
return stream
|
|
696
|
+
return stream.Readable.toWeb(stream2);
|
|
695
697
|
}
|
|
696
698
|
const body = new ReadableStream({
|
|
697
699
|
start(controller) {
|
|
@@ -1127,7 +1129,7 @@ var kHeadersCount = /* @__PURE__ */ Symbol("kHeadersCount");
|
|
|
1127
1129
|
var kTrailers = /* @__PURE__ */ Symbol("kTrailers");
|
|
1128
1130
|
var kTrailersDistinct = /* @__PURE__ */ Symbol("kTrailersDistinct");
|
|
1129
1131
|
var kTrailersCount = /* @__PURE__ */ Symbol("kTrailersCount");
|
|
1130
|
-
var FetchIncomingMessage = class extends stream
|
|
1132
|
+
var FetchIncomingMessage = class extends stream.Readable {
|
|
1131
1133
|
get socket() {
|
|
1132
1134
|
return null;
|
|
1133
1135
|
}
|
|
@@ -1583,7 +1585,7 @@ var WrittenDataBuffer = class {
|
|
|
1583
1585
|
return this[kCorked];
|
|
1584
1586
|
}
|
|
1585
1587
|
};
|
|
1586
|
-
var FetchOutgoingMessage = class extends stream
|
|
1588
|
+
var FetchOutgoingMessage = class extends stream.Writable {
|
|
1587
1589
|
req;
|
|
1588
1590
|
outputData;
|
|
1589
1591
|
outputSize;
|
|
@@ -2784,197 +2786,6 @@ function toFetchResponse(res) {
|
|
|
2784
2786
|
}
|
|
2785
2787
|
return res.fetchResponse;
|
|
2786
2788
|
}
|
|
2787
|
-
var HTTPException = class extends Error {
|
|
2788
|
-
res;
|
|
2789
|
-
status;
|
|
2790
|
-
/**
|
|
2791
|
-
* Creates an instance of `HTTPException`.
|
|
2792
|
-
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
2793
|
-
* @param options - Additional options for the exception.
|
|
2794
|
-
*/
|
|
2795
|
-
constructor(status = 500, options) {
|
|
2796
|
-
super(options?.message, { cause: options?.cause });
|
|
2797
|
-
this.res = options?.res;
|
|
2798
|
-
this.status = status;
|
|
2799
|
-
}
|
|
2800
|
-
/**
|
|
2801
|
-
* Returns the response object associated with the exception.
|
|
2802
|
-
* If a response object is not provided, a new response is created with the error message and status code.
|
|
2803
|
-
* @returns The response object.
|
|
2804
|
-
*/
|
|
2805
|
-
getResponse() {
|
|
2806
|
-
if (this.res) {
|
|
2807
|
-
const newResponse = new Response(this.res.body, {
|
|
2808
|
-
status: this.status,
|
|
2809
|
-
headers: this.res.headers
|
|
2810
|
-
});
|
|
2811
|
-
return newResponse;
|
|
2812
|
-
}
|
|
2813
|
-
return new Response(this.message, {
|
|
2814
|
-
status: this.status
|
|
2815
|
-
});
|
|
2816
|
-
}
|
|
2817
|
-
};
|
|
2818
|
-
var ERROR_MESSAGE = "Payload Too Large";
|
|
2819
|
-
var bodyLimit = (options) => {
|
|
2820
|
-
const onError3 = options.onError || (() => {
|
|
2821
|
-
const res = new Response(ERROR_MESSAGE, {
|
|
2822
|
-
status: 413
|
|
2823
|
-
});
|
|
2824
|
-
throw new HTTPException(413, { res });
|
|
2825
|
-
});
|
|
2826
|
-
const maxSize = options.maxSize;
|
|
2827
|
-
return async function bodyLimit2(c, next) {
|
|
2828
|
-
if (!c.req.raw.body) {
|
|
2829
|
-
return next();
|
|
2830
|
-
}
|
|
2831
|
-
const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
|
|
2832
|
-
const hasContentLength = c.req.raw.headers.has("content-length");
|
|
2833
|
-
if (hasContentLength && !hasTransferEncoding) {
|
|
2834
|
-
const contentLength = parseInt(c.req.raw.headers.get("content-length") || "0", 10);
|
|
2835
|
-
return contentLength > maxSize ? onError3(c) : next();
|
|
2836
|
-
}
|
|
2837
|
-
let size = 0;
|
|
2838
|
-
const chunks = [];
|
|
2839
|
-
const rawReader = c.req.raw.body.getReader();
|
|
2840
|
-
for (; ; ) {
|
|
2841
|
-
const { done, value } = await rawReader.read();
|
|
2842
|
-
if (done) {
|
|
2843
|
-
break;
|
|
2844
|
-
}
|
|
2845
|
-
size += value.length;
|
|
2846
|
-
if (size > maxSize) {
|
|
2847
|
-
return onError3(c);
|
|
2848
|
-
}
|
|
2849
|
-
chunks.push(value);
|
|
2850
|
-
}
|
|
2851
|
-
const requestInit = {
|
|
2852
|
-
body: new ReadableStream({
|
|
2853
|
-
start(controller) {
|
|
2854
|
-
for (const chunk of chunks) {
|
|
2855
|
-
controller.enqueue(chunk);
|
|
2856
|
-
}
|
|
2857
|
-
controller.close();
|
|
2858
|
-
}
|
|
2859
|
-
}),
|
|
2860
|
-
duplex: "half"
|
|
2861
|
-
};
|
|
2862
|
-
c.req.raw = new Request(c.req.raw, requestInit);
|
|
2863
|
-
return next();
|
|
2864
|
-
};
|
|
2865
|
-
};
|
|
2866
|
-
var StreamingApi = class {
|
|
2867
|
-
writer;
|
|
2868
|
-
encoder;
|
|
2869
|
-
writable;
|
|
2870
|
-
abortSubscribers = [];
|
|
2871
|
-
responseReadable;
|
|
2872
|
-
/**
|
|
2873
|
-
* Whether the stream has been aborted.
|
|
2874
|
-
*/
|
|
2875
|
-
aborted = false;
|
|
2876
|
-
/**
|
|
2877
|
-
* Whether the stream has been closed normally.
|
|
2878
|
-
*/
|
|
2879
|
-
closed = false;
|
|
2880
|
-
constructor(writable, _readable) {
|
|
2881
|
-
this.writable = writable;
|
|
2882
|
-
this.writer = writable.getWriter();
|
|
2883
|
-
this.encoder = new TextEncoder();
|
|
2884
|
-
const reader = _readable.getReader();
|
|
2885
|
-
this.abortSubscribers.push(async () => {
|
|
2886
|
-
await reader.cancel();
|
|
2887
|
-
});
|
|
2888
|
-
this.responseReadable = new ReadableStream({
|
|
2889
|
-
async pull(controller) {
|
|
2890
|
-
const { done, value } = await reader.read();
|
|
2891
|
-
done ? controller.close() : controller.enqueue(value);
|
|
2892
|
-
},
|
|
2893
|
-
cancel: () => {
|
|
2894
|
-
this.abort();
|
|
2895
|
-
}
|
|
2896
|
-
});
|
|
2897
|
-
}
|
|
2898
|
-
async write(input) {
|
|
2899
|
-
try {
|
|
2900
|
-
if (typeof input === "string") {
|
|
2901
|
-
input = this.encoder.encode(input);
|
|
2902
|
-
}
|
|
2903
|
-
await this.writer.write(input);
|
|
2904
|
-
} catch {
|
|
2905
|
-
}
|
|
2906
|
-
return this;
|
|
2907
|
-
}
|
|
2908
|
-
async writeln(input) {
|
|
2909
|
-
await this.write(input + "\n");
|
|
2910
|
-
return this;
|
|
2911
|
-
}
|
|
2912
|
-
sleep(ms) {
|
|
2913
|
-
return new Promise((res) => setTimeout(res, ms));
|
|
2914
|
-
}
|
|
2915
|
-
async close() {
|
|
2916
|
-
try {
|
|
2917
|
-
await this.writer.close();
|
|
2918
|
-
} catch {
|
|
2919
|
-
}
|
|
2920
|
-
this.closed = true;
|
|
2921
|
-
}
|
|
2922
|
-
async pipe(body) {
|
|
2923
|
-
this.writer.releaseLock();
|
|
2924
|
-
await body.pipeTo(this.writable, { preventClose: true });
|
|
2925
|
-
this.writer = this.writable.getWriter();
|
|
2926
|
-
}
|
|
2927
|
-
onAbort(listener) {
|
|
2928
|
-
this.abortSubscribers.push(listener);
|
|
2929
|
-
}
|
|
2930
|
-
/**
|
|
2931
|
-
* Abort the stream.
|
|
2932
|
-
* You can call this method when stream is aborted by external event.
|
|
2933
|
-
*/
|
|
2934
|
-
abort() {
|
|
2935
|
-
if (!this.aborted) {
|
|
2936
|
-
this.aborted = true;
|
|
2937
|
-
this.abortSubscribers.forEach((subscriber) => subscriber());
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
};
|
|
2941
|
-
var isOldBunVersion = () => {
|
|
2942
|
-
const version2 = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
2943
|
-
if (version2 === void 0) {
|
|
2944
|
-
return false;
|
|
2945
|
-
}
|
|
2946
|
-
const result = version2.startsWith("1.1") || version2.startsWith("1.0") || version2.startsWith("0.");
|
|
2947
|
-
isOldBunVersion = () => result;
|
|
2948
|
-
return result;
|
|
2949
|
-
};
|
|
2950
|
-
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
2951
|
-
var stream = (c, cb, onError3) => {
|
|
2952
|
-
const { readable, writable } = new TransformStream();
|
|
2953
|
-
const stream2 = new StreamingApi(writable, readable);
|
|
2954
|
-
if (isOldBunVersion()) {
|
|
2955
|
-
c.req.raw.signal.addEventListener("abort", () => {
|
|
2956
|
-
if (!stream2.closed) {
|
|
2957
|
-
stream2.abort();
|
|
2958
|
-
}
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
contextStash.set(stream2.responseReadable, c);
|
|
2962
|
-
(async () => {
|
|
2963
|
-
try {
|
|
2964
|
-
await cb(stream2);
|
|
2965
|
-
} catch (e) {
|
|
2966
|
-
if (e === void 0) ;
|
|
2967
|
-
else if (e instanceof Error && onError3) {
|
|
2968
|
-
await onError3(e, stream2);
|
|
2969
|
-
} else {
|
|
2970
|
-
console.error(e);
|
|
2971
|
-
}
|
|
2972
|
-
} finally {
|
|
2973
|
-
stream2.close();
|
|
2974
|
-
}
|
|
2975
|
-
})();
|
|
2976
|
-
return c.newResponse(stream2.responseReadable);
|
|
2977
|
-
};
|
|
2978
2789
|
// @__NO_SIDE_EFFECTS__
|
|
2979
2790
|
function $constructor(name, initializer3, params) {
|
|
2980
2791
|
function init(inst, def) {
|
|
@@ -3345,7 +3156,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
3345
3156
|
res.header("Content-Type", "text/plain");
|
|
3346
3157
|
}
|
|
3347
3158
|
res.header("Transfer-Encoding", "chunked");
|
|
3348
|
-
return stream(
|
|
3159
|
+
return streaming.stream(
|
|
3349
3160
|
res,
|
|
3350
3161
|
async (stream2) => {
|
|
3351
3162
|
const readableStream = result instanceof ReadableStream ? result : result.fullStream;
|
|
@@ -3517,7 +3328,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
3517
3328
|
const middlewares = [];
|
|
3518
3329
|
if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {
|
|
3519
3330
|
middlewares.push(
|
|
3520
|
-
bodyLimit({
|
|
3331
|
+
bodyLimit.bodyLimit({
|
|
3521
3332
|
maxSize,
|
|
3522
3333
|
onError: this.bodyLimitOptions.onError
|
|
3523
3334
|
})
|