@guren/server 2.13.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/{Hash-CzrwKeDp.js → Hash-C8aejmi8.js} +5 -0
  2. package/dist/{McpServiceProvider-D6D9nhgn.js → McpServiceProvider-BawsYjgN.js} +72 -0
  3. package/dist/agent/AgentApprovalRequested.d.ts +59 -0
  4. package/dist/agent/approval.d.ts +295 -0
  5. package/dist/agent/audit-emitter.d.ts +64 -0
  6. package/dist/agent/audit.d.ts +103 -0
  7. package/dist/agent/derive.d.ts +155 -0
  8. package/dist/agent/dispatch.d.ts +165 -0
  9. package/dist/agent/events.d.ts +80 -0
  10. package/dist/agent/meta-tools.d.ts +62 -0
  11. package/dist/agent/public.d.ts +33 -0
  12. package/dist/agent/public.js +2 -0
  13. package/dist/agent/redact.d.ts +55 -0
  14. package/dist/agent/scopes.d.ts +115 -0
  15. package/dist/auth/AuthManager.d.ts +64 -0
  16. package/dist/auth/RequestAuthContext.d.ts +3 -5
  17. package/dist/auth/TokenGuard.d.ts +61 -0
  18. package/dist/auth/api-token.d.ts +25 -5
  19. package/dist/auth/context.d.ts +24 -0
  20. package/dist/auth/index.d.ts +5 -2
  21. package/dist/auth/index.js +2 -2
  22. package/dist/auth/password/DefaultHasher.d.ts +18 -5
  23. package/dist/auth/password/PasswordHasher.d.ts +15 -0
  24. package/dist/auth/password/hash-format.d.ts +19 -0
  25. package/dist/auth/providers/UserProvider.d.ts +7 -0
  26. package/dist/auth/types.d.ts +6 -0
  27. package/dist/{auth-C7sVmYgc.js → auth-DkYoAPVn.js} +431 -151
  28. package/dist/authorization/index.js +1 -1
  29. package/dist/authorization/middleware.d.ts +28 -1
  30. package/dist/{authorization-Dbcuc5ZK.js → authorization-CdfbCj8J.js} +119 -12
  31. package/dist/broadcasting/index.js +1 -1
  32. package/dist/{broadcasting-Dw-FhyjN.js → broadcasting-BwodCA4q.js} +2 -45
  33. package/dist/container/bindings.d.ts +19 -0
  34. package/dist/context-DoD0c7J_.js +26 -0
  35. package/dist/dispatch-erOS9epZ.js +285 -0
  36. package/dist/encryption/index.js +2 -2
  37. package/dist/{encryption-DJtkkhiw.js → encryption-D99Vmls3.js} +4 -1
  38. package/dist/http/dev-assets.d.ts +16 -0
  39. package/dist/http/middleware/auth.d.ts +2 -2
  40. package/dist/http/middleware/capabilities.d.ts +57 -0
  41. package/dist/http/middleware/csrf.d.ts +3 -0
  42. package/dist/http/public-assets.d.ts +10 -0
  43. package/dist/http/request.d.ts +139 -3
  44. package/dist/http/static-documents.d.ts +31 -0
  45. package/dist/index.d.ts +21 -4
  46. package/dist/index.js +1302 -118
  47. package/dist/internal/agent-preflight.d.ts +28 -0
  48. package/dist/internal/request.d.ts +25 -0
  49. package/dist/internal/request.js +2 -0
  50. package/dist/internal/route-path.d.ts +28 -0
  51. package/dist/internal/route-path.js +33 -0
  52. package/dist/internal/zod-compat.d.ts +201 -0
  53. package/dist/internal/zod-compat.js +193 -0
  54. package/dist/internal/zod-json-schema.d.ts +102 -0
  55. package/dist/internal/zod-json-schema.js +461 -0
  56. package/dist/logging/channels/DailyFileChannel.d.ts +0 -2
  57. package/dist/logging/daily-file-path.d.ts +24 -0
  58. package/dist/logging/index.d.ts +1 -0
  59. package/dist/logging/index.js +2 -2
  60. package/dist/{logging-CPaRMuPP.js → logging-B-kngi3q.js} +61 -18
  61. package/dist/mcp/create-mcp-server.d.ts +29 -0
  62. package/dist/mcp/index.js +1 -1
  63. package/dist/mvc/Controller.d.ts +20 -0
  64. package/dist/mvc/Router.d.ts +53 -0
  65. package/dist/request-CVQwpu2J.js +129 -0
  66. package/dist/runtime/index.js +94 -15
  67. package/dist/{vite-manifest-gdONBsM3.js → vite-manifest-w_RSOvQW.js} +1 -1
  68. package/package.json +22 -2
@@ -364,6 +364,26 @@ export declare class Controller {
364
364
  protected validateParamsSafe<T>(schema: ZodLikeSchema<T>): SafeValidationResult<T>;
365
365
  private runValidation;
366
366
  private runValidationSafe;
367
+ /**
368
+ * The parsed body as sent: an array stays an array, a string stays a string.
369
+ * Only validation reads it — a schema is what decides whether the shape is
370
+ * acceptable, so narrowing first would make a non-object contract
371
+ * unreachable.
372
+ *
373
+ * Memoized in a box rather than by truthiness: a body of `null`, `''`, `0`
374
+ * or `false` is a parsed body, and re-reading the request would find the
375
+ * stream consumed.
376
+ *
377
+ * No fallback of its own: an unparseable body already arrives here as `{}`
378
+ * from {@link parseRequestBody}, which is what gives every dispatch path the
379
+ * same answer. A second fallback here could only diverge from that one.
380
+ */
381
+ private getRawBody;
382
+ /**
383
+ * The record view of {@link getRawBody}, for the field-by-field helpers
384
+ * (`input`, `only`, `except`, `has`). A non-object body has no field to
385
+ * read, so it reads as `{}`.
386
+ */
367
387
  private getBody;
368
388
  }
369
389
  export {};
@@ -109,6 +109,8 @@ export interface RouteContractOptions<TParamsSchema extends SchemaLike<unknown>
109
109
  * and expose the record to the controller via `this.model(Post)`.
110
110
  */
111
111
  bind?: Record<string, RouteModelBinding>;
112
+ /** Agent exposure metadata (RFC 0016). See {@link AgentRouteMetadata}. */
113
+ agent?: AgentRouteMetadata;
112
114
  }
113
115
  export interface RouteOpenApiMetadata {
114
116
  summary?: string;
@@ -117,6 +119,39 @@ export interface RouteOpenApiMetadata {
117
119
  operationId?: string;
118
120
  deprecated?: boolean;
119
121
  }
122
+ /**
123
+ * Agent exposure metadata for a route (RFC 0016). Declaring it marks the
124
+ * route as an agent tool; everything else about the tool — its input schema,
125
+ * output schema, authorization — is derived from the contracts the route
126
+ * already carries, never restated here.
127
+ *
128
+ * Storage only: no defaults are applied at registration, and the router does
129
+ * not require a route name here — `.agent()` may legally be chained before
130
+ * `.name()`, so name-requirement enforcement is deliberately left to static
131
+ * checks over `definitions()` (a route without a name cannot become a tool;
132
+ * the name is the tool's identity).
133
+ */
134
+ export interface AgentRouteMetadata {
135
+ /** Tool description. Absent, the route's OpenAPI `description` ?? `summary` stands in. */
136
+ description?: string;
137
+ /** Tool name override. Defaults to the route name, used verbatim. */
138
+ toolName?: string;
139
+ /** Protocol surfaces this tool appears on. Unset surfaces count as exposed. */
140
+ expose?: {
141
+ mcp?: boolean;
142
+ webMcp?: boolean;
143
+ };
144
+ /** MCP ToolAnnotations override: the tool does not modify its environment. Unset: GET/QUERY routes read-only. */
145
+ readOnlyHint?: boolean;
146
+ /** MCP ToolAnnotations override. `false` is the strong claim "additive updates only"; unset keeps the spec default (true for non-read-only tools). */
147
+ destructiveHint?: boolean;
148
+ /** MCP ToolAnnotations override: repeat calls with the same arguments have no additional effect. Unset: PUT/DELETE routes idempotent. */
149
+ idempotentHint?: boolean;
150
+ /** Route invocations through an agent surface require server-side approval. */
151
+ approval?: 'required';
152
+ /** Argument fields masked in agent audit logs. */
153
+ redact?: string[];
154
+ }
120
155
  /**
121
156
  * Represents a registered route definition for introspection.
122
157
  */
@@ -161,6 +196,11 @@ export interface RouteDefinition {
161
196
  };
162
197
  /** Route model bindings: param name → bound model class name (from `bind`) */
163
198
  bindings?: Record<string, string>;
199
+ /**
200
+ * Agent exposure metadata as declared (RFC 0016) — raw, no defaults
201
+ * applied. Absence means the route is not an agent tool.
202
+ */
203
+ agent?: AgentRouteMetadata;
164
204
  summary?: string;
165
205
  description?: string;
166
206
  tags?: string[];
@@ -176,6 +216,8 @@ export interface RouteBuilder<M extends string = never> {
176
216
  name(routeName: string): RouteBuilder<M>;
177
217
  /** Attach middleware to this specific route. See {@link RouteMiddlewareInput}. */
178
218
  middleware(...items: RouteMiddlewareInput<M>[]): RouteBuilder<M>;
219
+ /** Expose this route as an agent tool (RFC 0016). See {@link AgentRouteMetadata}. */
220
+ agent(metadata: AgentRouteMetadata): RouteBuilder<M>;
179
221
  }
180
222
  /**
181
223
  * Accepted by `.middleware()`: a registered alias name or a handler function.
@@ -208,6 +250,14 @@ export interface ResourceRouteOptions {
208
250
  param?: string;
209
251
  only?: ResourceAction[];
210
252
  except?: ResourceAction[];
253
+ /**
254
+ * Per-action agent exposure (RFC 0016). An action not listed here is not
255
+ * exposed as a tool — deny by default, no `destroy: false` spelling needed.
256
+ * Listing an action this call does not register (excluded via `only`/
257
+ * `except`, or missing from the controller) throws: metadata for a tool
258
+ * that cannot exist is a wiring mistake, not a no-op.
259
+ */
260
+ agent?: Partial<Record<ResourceAction, AgentRouteMetadata>>;
211
261
  }
212
262
  /**
213
263
  * Instance-based router for app-local route registration and mounting.
@@ -288,6 +338,9 @@ export declare class Router<M extends string = never> {
288
338
  * thrown: `definitions()` must stay side-effect-free for introspection of
289
339
  * routers that never mount (audit, codegen), and an unresolvable alias
290
340
  * simply contributes no capabilities.
341
+ *
342
+ * This walks the chain; the rules for combining what it finds live with the
343
+ * capability type, in `mergeCapabilities`.
291
344
  */
292
345
  private aggregateCapabilities;
293
346
  private resolveMiddlewareNames;
@@ -0,0 +1,129 @@
1
+ //#region src/http/request.ts
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ /**
6
+ * Parses the incoming request body and returns the parsed value as-is: a JSON
7
+ * array stays an array, a JSON string stays a string. Use this wherever the
8
+ * result is handed to a schema and *that* decides the shape — a route
9
+ * contract's `body`, `Controller.validateBody()`, `validateRequest()`.
10
+ *
11
+ * Falls back to an empty object when the body cannot be parsed (malformed
12
+ * JSON, a form body the parser cannot decode, an empty POST, an unsupported
13
+ * content type). That fallback is load bearing: an all-optional object schema
14
+ * has to keep passing on an empty body, which `undefined` would break. The
15
+ * cost is that a non-object schema sees `{}` there and fails validation,
16
+ * rather than receiving nothing.
17
+ *
18
+ * The fallback does not distinguish whose fault the failure was: a body the
19
+ * client could never have sent correctly and a body already consumed upstream
20
+ * (middleware reading `ctx.req.raw` directly, bypassing Hono's cache) both read
21
+ * as `{}` here. That is deliberate — the JSON branch above has always behaved
22
+ * this way, and telling the two apart means matching runtime-specific error
23
+ * codes, which would answer differently on Bun, Node and Workers. A parser
24
+ * error is a poor signal for a middleware-ordering bug either way.
25
+ *
26
+ * Form submissions have no non-object shape to preserve, so they normalize to
27
+ * a record exactly as {@link parseRequestPayload} does.
28
+ */
29
+ async function parseRequestBody(ctx) {
30
+ if ((ctx.req.header("content-type") ?? "").includes("application/json")) return ctx.req.json().catch(() => ({}));
31
+ if (typeof ctx.req.parseBody === "function") try {
32
+ const form = await ctx.req.parseBody();
33
+ return Object.fromEntries(Object.entries(form).map(([key, value]) => [key, Array.isArray(value) ? value[0] : value]));
34
+ } catch {
35
+ return {};
36
+ }
37
+ return {};
38
+ }
39
+ /**
40
+ * The one multipart read behind `Controller.file()` and `Controller.files()`,
41
+ * guarded so a body the parser cannot decode carries no files rather than
42
+ * crashing the request: it reads as `{}`, which is the same answer both helpers
43
+ * already give for a field that is simply absent — `null` and `[]`. Left to
44
+ * throw, the parser's `TypeError` escaped as a 500 reporting the exception and
45
+ * a stack, the defect {@link parseRequestBody} fixes for the validation paths.
46
+ *
47
+ * Deliberately *not* routed through {@link parseRequestBody}, which looks like
48
+ * the same rule and is not: it parses without `{ all: true }` and flattens a
49
+ * repeated field to its first value, so sharing it would silently reduce
50
+ * `files()` to one file per field. `{ all: true }` is the contract here, and a
51
+ * malformed-body test cannot see its loss — hence the separate function.
52
+ *
53
+ * There is no media-type gate, deliberately: Hono decides the media type inside
54
+ * `parseBody()`, having lowercased it first. A caller that gates before calling
55
+ * — or that reads uploads through `Request.formData()`, whose handling of the
56
+ * media type is not Hono's — answers `null` for an uppercase
57
+ * `MULTIPART/FORM-DATA` body this returns the file for.
58
+ *
59
+ * That was measured on Bun 1.3.14, and the host half of it has already moved:
60
+ * Bun 1.4.0 accepts the same header `1.3.14` rejects, and Node always did. The
61
+ * divergence is therefore a property of *where the media type is decided*, not
62
+ * of any one runtime — which is the argument for deciding it in one place, and
63
+ * why `@guren/testing`'s controller mock reaches this function rather than
64
+ * restating it.
65
+ *
66
+ * try/catch rather than `.catch()`, for the reason given on the shared
67
+ * fallback: `parseBody` may throw synchronously as well as reject, and only one
68
+ * of those two shapes reaches a `.catch()`.
69
+ *
70
+ * It fails open in one direction, deliberately and for the same reason
71
+ * {@link parseRequestBody} does: a body already consumed upstream reads as
72
+ * "no upload" rather than throwing, so a middleware-ordering bug loses the 500
73
+ * that used to announce it. Telling that apart from a client's malformed body
74
+ * means matching runtime-specific error codes, which answer differently on Bun,
75
+ * Node and Workers.
76
+ */
77
+ async function parseRequestUploads(ctx) {
78
+ try {
79
+ return await ctx.req.parseBody({ all: true });
80
+ } catch {
81
+ return {};
82
+ }
83
+ }
84
+ /**
85
+ * The record-shaped view of {@link parseRequestBody}, for callers that read the
86
+ * payload field by field (`payload.channel`, per-field validation rules,
87
+ * `Controller.input()`/`only()`/`except()`/`has()`). A body that is not a plain
88
+ * object — an array, a string, `null` — becomes `{}`, because there is no
89
+ * field to read on one.
90
+ */
91
+ async function parseRequestPayload(ctx) {
92
+ return asRecord(await parseRequestBody(ctx));
93
+ }
94
+ /** Narrow a parsed body to the record view described on {@link parseRequestPayload}. */
95
+ function asRecord(body) {
96
+ return isPlainObject(body) ? body : {};
97
+ }
98
+ /**
99
+ * Collects query parameters preserving repeated keys as arrays while keeping
100
+ * single occurrences as plain strings (`?tag=a&tag=b` → `{ tag: ['a', 'b'] }`,
101
+ * `?page=2` → `{ page: '2' }`). Use this instead of `ctx.req.query()` when
102
+ * feeding query data into validation schemas.
103
+ *
104
+ * Materialized with `Object.fromEntries`, never by assigning into an object
105
+ * literal — the same rule, and for the same reason, as the form branch of
106
+ * {@link parseRequestBody} above. Query keys are attacker-controlled, and
107
+ * `flat['__proto__'] = …` hits `Object.prototype`'s inherited setter instead
108
+ * of defining a field: `?__proto__=one` silently vanished before reaching the
109
+ * schema, and `?__proto__=one&__proto__=two` set the returned record's own
110
+ * prototype to that array. Hono hands over a null-prototype object, so the
111
+ * key arrives here intact; only this last step could lose it.
112
+ */
113
+ function flattenRequestQueries(ctx) {
114
+ return Object.fromEntries(Object.entries(ctx.req.queries()).map(([key, values]) => [key, values.length === 1 ? values[0] : values]));
115
+ }
116
+ /**
117
+ * Converts a Zod-style validation error into a flat record usable by forms.
118
+ */
119
+ function formatValidationErrors(error, fallbackMessage = "The provided data is invalid.") {
120
+ const errors = {};
121
+ for (const issue of error.issues ?? []) {
122
+ const field = issue.path?.[0];
123
+ if (typeof field === "string" && !errors[field]) errors[field] = issue.message;
124
+ }
125
+ if (Object.keys(errors).length === 0) errors.message = fallbackMessage;
126
+ return errors;
127
+ }
128
+ //#endregion
129
+ export { parseRequestPayload as a, parseRequestBody as i, flattenRequestQueries as n, parseRequestUploads as o, formatValidationErrors as r, asRecord as t };
@@ -1,11 +1,12 @@
1
1
  import { n as trimTrailingSlashes } from "../trim-slashes-ZJ_VsY5s.js";
2
- import { n as hash } from "../Hash-CzrwKeDp.js";
3
- import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-gdONBsM3.js";
2
+ import { n as hash } from "../Hash-C8aejmi8.js";
3
+ import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-w_RSOvQW.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { realpath } from "node:fs/promises";
6
6
  import { dirname, extname, join, resolve, sep } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { serveStatic } from "hono/bun";
9
+ import { getMimeType } from "hono/utils/mime";
9
10
  //#region src/support/contained-path.ts
10
11
  /**
11
12
  * Is `candidate` a path strictly below `root`, judged lexically?
@@ -48,6 +49,69 @@ async function canonicalize(path) {
48
49
  }
49
50
  }
50
51
  //#endregion
52
+ //#region src/http/static-documents.ts
53
+ /**
54
+ * The one rule for "a browser would render this as a document in the serving
55
+ * origin". A file the app merely *stores* under `public/` — an upload keeping
56
+ * its original extension, most of all — otherwise becomes script running as
57
+ * the app: same cookies, same session, same CSRF token.
58
+ *
59
+ * A denylist rather than the attachments engine's `INLINE_CONTENT_TYPES`
60
+ * allowlist, because these mounts also serve the app's own build output. An
61
+ * allowlist here would have to enumerate every asset type a project can ship,
62
+ * and would break a deployment the first time it shipped one that was missed.
63
+ * Everything absent from this set — scripts, stylesheets, fonts, images,
64
+ * media, PDFs — is inert when navigated to, and stays inline.
65
+ */
66
+ const DOCUMENT_CONTENT_TYPES = /* @__PURE__ */ new Set([
67
+ "text/html",
68
+ "text/xml",
69
+ "application/xml",
70
+ "text/xsl"
71
+ ]);
72
+ /**
73
+ * Judged on the media type alone. Both inputs this module reads are
74
+ * parameterised — Hono's `getMimeType` returns `text/html; charset=utf-8`, and
75
+ * so does a hand-written `contentTypeMap` entry — so comparing the header
76
+ * verbatim is precisely how the check stops matching while still looking
77
+ * present.
78
+ */
79
+ function rendersAsDocument(contentType) {
80
+ if (!contentType) return false;
81
+ const mediaType = contentType.split(";", 1)[0].trim().toLowerCase();
82
+ return DOCUMENT_CONTENT_TYPES.has(mediaType) || mediaType.endsWith("+xml");
83
+ }
84
+ /**
85
+ * Neutralizes a served document by turning it into a download.
86
+ *
87
+ * `Content-Disposition: attachment` is honoured for navigations and ignored
88
+ * for subresource loads, which is what makes it usable on a general asset
89
+ * route: `<img src="/logo.svg">`, `<link rel="icon">` and CSS `url()` keep
90
+ * working unchanged, while `/logo.svg` opened directly is downloaded instead
91
+ * of rendered. An `<iframe>` or `<object>` *is* a navigation, so an SVG or
92
+ * HTML page embedded that way stops rendering — which is the same mechanism
93
+ * as the fix, not an exception to it. `nosniff` rides along for the types a
94
+ * browser would otherwise promote on its own.
95
+ */
96
+ function applyDocumentDisposition(headers, contentType) {
97
+ if (!rendersAsDocument(contentType)) return;
98
+ headers.set("Content-Disposition", "attachment");
99
+ headers.set("X-Content-Type-Options", "nosniff");
100
+ }
101
+ /**
102
+ * The {@link import('hono/bun').serveStatic} form of
103
+ * {@link applyDocumentDisposition}, for use as its `onFound` hook.
104
+ *
105
+ * Keyed on the same `getMimeType(path)` the middleware itself used a line
106
+ * earlier to set `Content-Type`, rather than on the extension: the two agree
107
+ * by construction only while they read the same function.
108
+ */
109
+ function guardStaticDocument(path, ctx) {
110
+ if (!rendersAsDocument(getMimeType(path))) return;
111
+ ctx.header("Content-Disposition", "attachment");
112
+ ctx.header("X-Content-Type-Options", "nosniff");
113
+ }
114
+ //#endregion
51
115
  //#region src/http/public-assets.ts
52
116
  const DEFAULT_CACHE_CONTROL = "public, max-age=31536000, immutable";
53
117
  const DEFAULT_EXTENSIONS = [
@@ -72,7 +136,10 @@ const DEFAULT_CONTENT_TYPES = {
72
136
  ".webp": "image/webp",
73
137
  ".avif": "image/avif",
74
138
  ".webmanifest": "application/manifest+json",
75
- ".txt": "text/plain; charset=utf-8"
139
+ ".txt": "text/plain; charset=utf-8",
140
+ ".js": "text/javascript; charset=utf-8",
141
+ ".mjs": "text/javascript; charset=utf-8",
142
+ ".css": "text/css; charset=utf-8"
76
143
  };
77
144
  function registerRootPublicAssets(app, publicDir, config) {
78
145
  const normalized = normalizeConfig(config);
@@ -81,7 +148,7 @@ function registerRootPublicAssets(app, publicDir, config) {
81
148
  console.warn("Root public asset serving is only available when running on Bun; skipping registration.");
82
149
  return;
83
150
  }
84
- const { extensions, cacheControlHeader, routePrefix, contentTypeMap } = normalized;
151
+ const { extensions, cacheControlHeader, routePrefix, contentTypeMap, inlineDocuments } = normalized;
85
152
  const normalizedPrefix = routePrefix ? trimTrailingSlashes(routePrefix) || "/" : void 0;
86
153
  app.hono.use(async (ctx, next) => {
87
154
  const path = ctx.req.path;
@@ -96,10 +163,12 @@ function registerRootPublicAssets(app, publicDir, config) {
96
163
  const file = Bun.file(candidatePath);
97
164
  if (!await file.exists()) return next();
98
165
  if (!await isRealPathWithin(publicDir, candidatePath)) return next();
166
+ const contentType = contentTypeMap?.[extension] ?? DEFAULT_CONTENT_TYPES[extension] ?? "application/octet-stream";
99
167
  const headers = new Headers({
100
168
  "Cache-Control": cacheControlHeader,
101
- "Content-Type": contentTypeMap?.[extension] ?? DEFAULT_CONTENT_TYPES[extension] ?? "application/octet-stream"
169
+ "Content-Type": contentType
102
170
  });
171
+ if (!inlineDocuments) applyDocumentDisposition(headers, contentType);
103
172
  return new Response(file, { headers });
104
173
  });
105
174
  }
@@ -107,14 +176,16 @@ function normalizeConfig(config) {
107
176
  if (config === false) return;
108
177
  if (config === void 0 || config === true) return {
109
178
  extensions: new Set(DEFAULT_EXTENSIONS),
110
- cacheControlHeader: DEFAULT_CACHE_CONTROL
179
+ cacheControlHeader: DEFAULT_CACHE_CONTROL,
180
+ inlineDocuments: false
111
181
  };
112
182
  if (!(config.enabled ?? true)) return;
113
183
  return {
114
184
  extensions: new Set((config.extensions && config.extensions.length > 0 ? config.extensions : DEFAULT_EXTENSIONS).map((ext) => normalizeExtension(ext))),
115
185
  cacheControlHeader: config.cacheControlHeader ?? DEFAULT_CACHE_CONTROL,
116
186
  routePrefix: config.routePrefix,
117
- contentTypeMap: config.contentTypeMap
187
+ contentTypeMap: config.contentTypeMap,
188
+ inlineDocuments: config.inlineDocuments ?? false
118
189
  };
119
190
  }
120
191
  function normalizeExtension(value) {
@@ -197,7 +268,8 @@ function registerDevAssets(app, options) {
197
268
  const cssRewrite = createStaticRewrite(cssRoute);
198
269
  app.use(cssRoute, serveStatic({
199
270
  root: cssDir,
200
- rewriteRequestPath: cssRewrite
271
+ rewriteRequestPath: cssRewrite,
272
+ onFound: options.inlineDocuments ? void 0 : guardStaticDocument
201
273
  }));
202
274
  }
203
275
  if (options.inertiaClient !== false) {
@@ -218,7 +290,8 @@ function registerDevAssets(app, options) {
218
290
  const rewriteRequestPath = createStaticRewrite(publicRoute);
219
291
  app.use(publicRoute, serveStatic({
220
292
  root: publicDir,
221
- rewriteRequestPath
293
+ rewriteRequestPath,
294
+ onFound: options.inlineDocuments ? void 0 : guardStaticDocument
222
295
  }));
223
296
  if (options.favicon !== false) app.hono.get("/favicon.ico", () => new Response(null, { status: 204 }));
224
297
  registerRootPublicAssets(app, publicDir, options.rootPublicAssets);
@@ -289,10 +362,13 @@ async function transpileFile(fsPath, transpile, containmentRoot) {
289
362
  } });
290
363
  }
291
364
  const body = await file.arrayBuffer();
292
- return new Response(body, { headers: {
293
- "Content-Type": file.type || "application/octet-stream",
365
+ const contentType = file.type || "application/octet-stream";
366
+ const headers = new Headers({
367
+ "Content-Type": contentType,
294
368
  "Cache-Control": isDev() ? "no-cache" : "public, max-age=31536000"
295
- } });
369
+ });
370
+ applyDocumentDisposition(headers, contentType);
371
+ return new Response(body, { headers });
296
372
  }
297
373
  function buildCandidatePaths(fsPath) {
298
374
  if (extname(fsPath)) return [fsPath];
@@ -352,7 +428,8 @@ function configureInertiaAssets(app, options) {
352
428
  app.use(publicRoute, serveStatic({
353
429
  root: publicDir,
354
430
  rewriteRequestPath,
355
- onFound: (_path, ctx) => {
431
+ onFound: (path, ctx) => {
432
+ if (!options.inlineDocuments) guardStaticDocument(path, ctx);
356
433
  if (ctx.req.path.startsWith(hashedAssetsPrefix)) ctx.header("Cache-Control", "public, max-age=31536000, immutable");
357
434
  }
358
435
  }));
@@ -394,10 +471,12 @@ function registerBuiltInertiaClient(app, inertiaClientDir, inertiaClientPath) {
394
471
  if (!await file.exists()) return ctx.notFound();
395
472
  if (containmentRoot && !await isRealPathWithin(containmentRoot, targetPath)) return ctx.notFound();
396
473
  const contentType = file.type || "application/javascript; charset=utf-8";
397
- return new Response(file, { headers: {
474
+ const headers = new Headers({
398
475
  "Content-Type": contentType,
399
476
  "Cache-Control": "public, max-age=31536000"
400
- } });
477
+ });
478
+ applyDocumentDisposition(headers, contentType);
479
+ return new Response(file, { headers });
401
480
  });
402
481
  }
403
482
  function autoConfigureInertiaAssets(app, options) {
@@ -40,7 +40,7 @@ function parseImportMap(value, options = {}) {
40
40
  const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
41
41
  //#endregion
42
42
  //#region package.json
43
- var version = "2.13.0";
43
+ var version = "2.15.0";
44
44
  //#endregion
45
45
  //#region src/http/dev-banner.ts
46
46
  figlet.parseFont("Standard", standard);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -94,6 +94,10 @@
94
94
  "types": "./dist/mcp/index.d.ts",
95
95
  "default": "./dist/mcp/index.js"
96
96
  },
97
+ "./agent": {
98
+ "types": "./dist/agent/public.d.ts",
99
+ "default": "./dist/agent/public.js"
100
+ },
97
101
  "./lambda": {
98
102
  "types": "./dist/lambda/index.d.ts",
99
103
  "default": "./dist/lambda/index.js"
@@ -106,6 +110,22 @@
106
110
  "types": "./dist/support/expiry.d.ts",
107
111
  "default": "./dist/support/expiry.js"
108
112
  },
113
+ "./internal/request": {
114
+ "types": "./dist/internal/request.d.ts",
115
+ "default": "./dist/internal/request.js"
116
+ },
117
+ "./internal/route-path": {
118
+ "types": "./dist/internal/route-path.d.ts",
119
+ "default": "./dist/internal/route-path.js"
120
+ },
121
+ "./internal/zod-compat": {
122
+ "types": "./dist/internal/zod-compat.d.ts",
123
+ "default": "./dist/internal/zod-compat.js"
124
+ },
125
+ "./internal/zod-json-schema": {
126
+ "types": "./dist/internal/zod-json-schema.d.ts",
127
+ "default": "./dist/internal/zod-json-schema.js"
128
+ },
109
129
  "./jsx-runtime": {
110
130
  "types": "./dist/jsx-runtime.d.ts",
111
131
  "default": "./dist/jsx-runtime.js"
@@ -122,7 +142,7 @@
122
142
  "test": "bun test"
123
143
  },
124
144
  "dependencies": {
125
- "@guren/orm": "^2.6.1",
145
+ "@guren/orm": "^2.6.2",
126
146
  "@modelcontextprotocol/sdk": "^1.30.0",
127
147
  "chalk": "^5.3.0",
128
148
  "consola": "^3.4.2",