@guren/server 2.28.1 → 2.29.1

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 (31) hide show
  1. package/dist/{DocsViewerServiceProvider-BMbcTYVw.js → DocsViewerServiceProvider-BVPZjwQp.js} +7 -1
  2. package/dist/{Gate-CYfoGQqh.js → Gate-DFiuutZm.js} +1 -25
  3. package/dist/{McpServiceProvider-PGFPlYTy.js → McpServiceProvider-CvFExxdJ.js} +45 -2
  4. package/dist/{MessageSigner-Bd25ZJAV.js → MessageSigner-DIUT1Yao.js} +4 -2
  5. package/dist/{Resource-BhOua2OB.js → Resource-ZMJH4lyD.js} +2 -1
  6. package/dist/auth/index.js +1 -1
  7. package/dist/{auth-DIugW0O-.js → auth-DRMeSwev.js} +1 -1
  8. package/dist/authorization/index.js +2 -2
  9. package/dist/{authorization-CKOLYWvi.js → authorization-DUjeyGWh.js} +2 -1
  10. package/dist/{dev-banner-DnaL8Ku6.js → dev-banner-wz0V_g0R.js} +1 -1
  11. package/dist/encryption/index.js +2 -2
  12. package/dist/{encryption-CWK5l22W.js → encryption-DF8lZkpj.js} +1 -1
  13. package/dist/http/Application.d.ts +10 -54
  14. package/dist/http/boot-sequence.d.ts +8 -0
  15. package/dist/http/server-lifecycle.d.ts +88 -0
  16. package/dist/index.js +171 -318
  17. package/dist/internal/testing.js +1 -1
  18. package/dist/introspection/types.d.ts +6 -0
  19. package/dist/mcp/McpServiceProvider.d.ts +7 -0
  20. package/dist/mcp/index.js +1 -1
  21. package/dist/mcp/runtime-error-capture.d.ts +24 -0
  22. package/dist/mcp/runtime-errors.d.ts +59 -0
  23. package/dist/mvc/Router.d.ts +2 -0
  24. package/dist/request-container-BbuH0JJy.js +25 -0
  25. package/dist/runtime/index.js +2 -2
  26. package/dist/runtime-error-capture-BclelWhA.js +48 -0
  27. package/dist/runtime-errors-DOPBX0Ox.js +135 -0
  28. package/dist/vite-manifest-DO0pU1vm.js +391 -0
  29. package/package.json +3 -3
  30. package/dist/endpoint-Coq0K_6I.js +0 -26
  31. package/dist/vite-manifest-wPxfAzjW.js +0 -146
@@ -1,4 +1,4 @@
1
- import { _ as INERTIA_VARY, f as definePlugin, i as Controller, n as Resource, r as collect, t as JsonResource, u as defineModule, v as acceptsJson, x as serializePage, y as buildInertiaPage } from "../Resource-BhOua2OB.js";
1
+ import { _ as INERTIA_VARY, f as definePlugin, i as Controller, n as Resource, r as collect, t as JsonResource, u as defineModule, v as acceptsJson, x as serializePage, y as buildInertiaPage } from "../Resource-ZMJH4lyD.js";
2
2
  import { r as formatValidationErrors } from "../request-CLOYytGP.js";
3
3
  import { n as ValidationException } from "../errors-JpkcCjjn.js";
4
4
  import { n as ServiceProvider } from "../ServiceProvider-G0YclITd.js";
@@ -89,6 +89,12 @@ export type RouteSchemaEntry = JsonSchema | {
89
89
  export type RouteEntry = Omit<RouteDefinition, 'schemas' | 'controller' | 'middlewareNames' | 'module'> & {
90
90
  module: string | null;
91
91
  controller?: ControllerRef;
92
+ /** Populated only by graph introspection after matching the actual bound class identity. */
93
+ bindingSources?: Record<string, {
94
+ file: string;
95
+ exportName: string;
96
+ name: string;
97
+ }>;
92
98
  /** In the order `mount()` runs them: named, then group-scoped inline, then route-local inline. */
93
99
  middleware: MiddlewareEntry[];
94
100
  schemas: Partial<Record<'params' | 'query' | 'body' | 'output', RouteSchemaEntry>>;
@@ -1,3 +1,4 @@
1
+ import type { RuntimeErrorQuery } from './runtime-errors.js';
1
2
  import { ServiceProvider } from '../container/ServiceProvider.js';
2
3
  /**
3
4
  * What this provider calls on `@guren/cli`, spelled here: the package cannot be
@@ -5,8 +6,14 @@ import { ServiceProvider } from '../container/ServiceProvider.js';
5
6
  * build as `any`. Same seam as `DocsViewerServiceProvider`'s.
6
7
  */
7
8
  export interface DevMcpCliApi {
9
+ createDevCenterHandler?(options: {
10
+ cwd: string;
11
+ }): {
12
+ fetch(request: Request): Promise<Response>;
13
+ };
8
14
  createDevMcpHandler?(options: {
9
15
  cwd: string;
16
+ runtimeErrors?: (query: RuntimeErrorQuery) => unknown;
10
17
  }): {
11
18
  fetch(request: Request): Promise<Response>;
12
19
  };
package/dist/mcp/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as McpServiceProvider } from "../McpServiceProvider-PGFPlYTy.js";
1
+ import { t as McpServiceProvider } from "../McpServiceProvider-CvFExxdJ.js";
2
2
  export { McpServiceProvider };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The half of the dev-only runtime error collector that every build carries:
3
+ * the binding names, the capture call ExceptionHandler makes, and the loader for
4
+ * `./runtime-errors`. The buffer (node:fs frame resolution, hono/route) stays
5
+ * behind that loader so a deploy bundle drops it.
6
+ */
7
+ import type { Context } from 'hono';
8
+ export declare const RUNTIME_ERRORS_BINDING = "dev.runtimeErrors";
9
+ export declare const RUNTIME_ERRORS_PATH = "/_guren/runtime/errors";
10
+ /** What the `RUNTIME_ERRORS_BINDING` binding answers; `RuntimeErrorBuffer` implements it. */
11
+ export interface RuntimeErrorCollector {
12
+ capture(error: Error, ctx: Context, status: number): void;
13
+ }
14
+ type RuntimeErrorsModule = typeof import('./runtime-errors.js');
15
+ /**
16
+ * The buffer module while the collector is enabled, else undefined. The NODE_ENV
17
+ * read is plain member access so a deploy build's `--define` settles the branch
18
+ * and the bundler drops the `import()` with it; `isMcpEndpointEnabled()` alone is
19
+ * a call no define can settle. `tests/mcp/runtime-errors.test.ts` pins the form.
20
+ */
21
+ export declare function loadRuntimeErrorsModule(): Promise<RuntimeErrorsModule> | undefined;
22
+ /** Only ExceptionHandler calls this, after applying its dontReport policy. */
23
+ export declare function captureRuntimeError(error: Error, ctx: Context, status: number): void;
24
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { Context } from 'hono';
2
+ import type { RuntimeErrorCollector } from './runtime-error-capture.js';
3
+ export { RUNTIME_ERRORS_BINDING, RUNTIME_ERRORS_PATH } from './runtime-error-capture.js';
4
+ export interface RuntimeErrorQuery {
5
+ sessionId?: string;
6
+ after?: number;
7
+ limit?: number;
8
+ }
9
+ export interface RuntimeErrorEvent {
10
+ sessionId: string;
11
+ sequence: number;
12
+ occurredAt: string;
13
+ method: string;
14
+ route?: {
15
+ method: string;
16
+ pattern: string;
17
+ name?: string;
18
+ };
19
+ correlation: 'matched' | 'ambiguous' | 'unavailable';
20
+ status: number;
21
+ category: 'server-error';
22
+ frames: Array<{
23
+ file: string;
24
+ line?: number;
25
+ column?: number;
26
+ }>;
27
+ }
28
+ export interface RuntimeErrorResult {
29
+ schemaVersion: 1;
30
+ status: 'available';
31
+ sessionId: string;
32
+ startedAt: string;
33
+ events: RuntimeErrorEvent[];
34
+ nextCursor: {
35
+ sessionId: string;
36
+ after: number;
37
+ };
38
+ dropped: number;
39
+ cursorExpired: boolean;
40
+ }
41
+ export declare class RuntimeErrorBuffer implements RuntimeErrorCollector {
42
+ private readonly root;
43
+ private readonly now;
44
+ private sessionId;
45
+ private startedAt;
46
+ private sequence;
47
+ private dropped;
48
+ private bytes;
49
+ private events;
50
+ constructor(root: string, now?: () => number);
51
+ reset(): void;
52
+ /** Called through `captureRuntimeError()`, which has already checked the status and guards the call. */
53
+ capture(error: Error, ctx: Context, status: number): void;
54
+ record(error: Error, detail: Pick<RuntimeErrorEvent, 'method' | 'route' | 'correlation' | 'status'>): void;
55
+ read(query?: RuntimeErrorQuery): RuntimeErrorResult;
56
+ private evict;
57
+ private expire;
58
+ private frames;
59
+ }
@@ -295,6 +295,8 @@ export declare class Router<in M extends string = never> {
295
295
  controller?: ControllerConstructor;
296
296
  action?: string;
297
297
  }>;
298
+ /** Model identities behind the serialized binding names, indexed like definitions (RFC 0032). */
299
+ registeredModelBindings(): ReadonlyArray<Record<string, BindableModel>>;
298
300
  /**
299
301
  * Every alias and group resolved, and each route's chain in `mount()` order,
300
302
  * index-aligned with {@link definitions} (RFC 0026 §3). Like `definitions()`,
@@ -0,0 +1,25 @@
1
+ //#region src/http/request-container.ts
2
+ /**
3
+ * Context variable the serving Application's container is stamped under
4
+ * (RFC 0023 §2). The stamp is the first middleware `Application` mounts, so
5
+ * nothing an app registers runs ahead of it. The one place a middleware
6
+ * reaches its app's container without holding the app.
7
+ */
8
+ const CONTAINER_CONTEXT_KEY = "guren.container";
9
+ /**
10
+ * The container of the Application serving `ctx`, or undefined off an
11
+ * Application (bare Hono). Judged by shape rather than `instanceof`: a test
12
+ * double answering every key must not pass as a container.
13
+ */
14
+ function tryGetRequestContainer(ctx) {
15
+ const container = ctx.get(CONTAINER_CONTEXT_KEY);
16
+ return typeof container?.makeOptional === "function" ? container : void 0;
17
+ }
18
+ /** The container of the Application serving `ctx`; throws off an Application (bare Hono). */
19
+ function getRequestContainer(ctx) {
20
+ const container = tryGetRequestContainer(ctx);
21
+ if (!container) throw new Error("No Application container on this request. The container is stamped by Application; a bare Hono app has none — pass the service explicitly there.");
22
+ return container;
23
+ }
24
+ //#endregion
25
+ export { getRequestContainer as n, tryGetRequestContainer as r, CONTAINER_CONTEXT_KEY as t };
@@ -1,8 +1,8 @@
1
1
  import { a as trimTrailingSlashes, n as isRealPathWithin, t as isPathWithin } from "../contained-path-BkNSBljW.js";
2
2
  import { n as parseImportMap } from "../inertia-defaults-BjrcT7za.js";
3
3
  import { n as hash } from "../Hash-D2DFd8xX.js";
4
- import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-wPxfAzjW.js";
5
- import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-DnaL8Ku6.js";
4
+ import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-DO0pU1vm.js";
5
+ import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-wz0V_g0R.js";
6
6
  import { createRequire } from "node:module";
7
7
  import { dirname, extname, join, resolve } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
@@ -0,0 +1,48 @@
1
+ import { t as createLoopbackGuard } from "./loopback-guard-CG8xB4v0.js";
2
+ import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
3
+ //#region src/mcp/endpoint.ts
4
+ const MCP_ENDPOINT_PATH = "/_guren/mcp";
5
+ /**
6
+ * Whether the MCP endpoint is mounted: opt-in via `GUREN_MCP=1`, never in
7
+ * production (it exposes project introspection and code generation). The env
8
+ * reads are plain member access on purpose: the deploy plugins settle NODE_ENV
9
+ * with `--define`, which matches one exact expression, so an optional chain
10
+ * leaves a runtime read that reopens the gate on workerd; `tests/mcp/endpoint.test.ts` pins the form.
11
+ */
12
+ function isMcpEndpointEnabled() {
13
+ if (typeof process === "undefined") return false;
14
+ if (process.env.NODE_ENV === "production") return false;
15
+ return process.env.GUREN_MCP === "1";
16
+ }
17
+ /**
18
+ * Restricts the MCP endpoint to the developer's own machine. The endpoint is
19
+ * CSRF-exempt (agent clients carry no token), so this guard takes over: a web
20
+ * page is rejected unless its `Origin` is loopback, and every caller unless its
21
+ * socket peer is. It fails closed when the runtime reports no peer at all.
22
+ */
23
+ function createMcpAccessGuard() {
24
+ return createLoopbackGuard("the MCP endpoint");
25
+ }
26
+ //#endregion
27
+ //#region src/mcp/runtime-error-capture.ts
28
+ const RUNTIME_ERRORS_BINDING = "dev.runtimeErrors";
29
+ const RUNTIME_ERRORS_PATH = "/_guren/runtime/errors";
30
+ let loading;
31
+ /**
32
+ * The buffer module while the collector is enabled, else undefined. The NODE_ENV
33
+ * read is plain member access so a deploy build's `--define` settles the branch
34
+ * and the bundler drops the `import()` with it; `isMcpEndpointEnabled()` alone is
35
+ * a call no define can settle. `tests/mcp/runtime-errors.test.ts` pins the form.
36
+ */
37
+ function loadRuntimeErrorsModule() {
38
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && isMcpEndpointEnabled()) return loading ??= import("./runtime-errors-DOPBX0Ox.js");
39
+ }
40
+ /** Only ExceptionHandler calls this, after applying its dontReport policy. */
41
+ function captureRuntimeError(error, ctx, status) {
42
+ if (!isMcpEndpointEnabled() || status < 500 || status > 599 || !Number.isInteger(status)) return;
43
+ try {
44
+ tryGetRequestContainer(ctx)?.makeOptional(RUNTIME_ERRORS_BINDING)?.capture(error, ctx, status);
45
+ } catch {}
46
+ }
47
+ //#endregion
48
+ export { MCP_ENDPOINT_PATH as a, loadRuntimeErrorsModule as i, RUNTIME_ERRORS_PATH as n, createMcpAccessGuard as o, captureRuntimeError as r, isMcpEndpointEnabled as s, RUNTIME_ERRORS_BINDING as t };
@@ -0,0 +1,135 @@
1
+ import { n as RUNTIME_ERRORS_PATH, t as RUNTIME_ERRORS_BINDING } from "./runtime-error-capture-BclelWhA.js";
2
+ import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
3
+ import { realpathSync, statSync } from "node:fs";
4
+ import { routePath } from "hono/route";
5
+ //#region src/mcp/runtime-errors.ts
6
+ var RuntimeErrorBuffer = class {
7
+ root;
8
+ now;
9
+ sessionId = crypto.randomUUID();
10
+ startedAt;
11
+ sequence = 0;
12
+ dropped = 0;
13
+ bytes = 0;
14
+ events = [];
15
+ constructor(root, now = Date.now) {
16
+ this.root = root;
17
+ this.now = now;
18
+ this.startedAt = new Date(now()).toISOString();
19
+ }
20
+ reset() {
21
+ this.sessionId = crypto.randomUUID();
22
+ this.startedAt = new Date(this.now()).toISOString();
23
+ this.sequence = this.dropped = this.bytes = 0;
24
+ this.events = [];
25
+ }
26
+ /** Called through `captureRuntimeError()`, which has already checked the status and guards the call. */
27
+ capture(error, ctx, status) {
28
+ const pattern = routePath(ctx);
29
+ const matches = (tryGetRequestContainer(ctx)?.makeOptional("router")?.definitions() ?? []).filter((entry) => entry.path === pattern && (entry.method === ctx.req.method || entry.method === "ALL"));
30
+ const route = matches.length === 1 ? matches[0] : void 0;
31
+ this.record(error, {
32
+ method: ctx.req.method,
33
+ status,
34
+ correlation: matches.length === 1 ? "matched" : matches.length > 1 ? "ambiguous" : "unavailable",
35
+ ...route ? { route: {
36
+ method: route.method,
37
+ pattern: route.path,
38
+ ...route.name ? { name: route.name } : {}
39
+ } } : {}
40
+ });
41
+ }
42
+ record(error, detail) {
43
+ const at = this.now();
44
+ this.expire(at);
45
+ const event = {
46
+ sessionId: this.sessionId,
47
+ sequence: ++this.sequence,
48
+ occurredAt: new Date(at).toISOString(),
49
+ method: /^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|CONNECT|TRACE|QUERY)$/.test(detail.method) ? detail.method : "UNKNOWN",
50
+ ...detail.route ? { route: detail.route } : {},
51
+ correlation: detail.correlation,
52
+ status: detail.status,
53
+ category: "server-error",
54
+ frames: this.frames(error.stack)
55
+ };
56
+ const bytes = new TextEncoder().encode(JSON.stringify(event)).length;
57
+ if (bytes > 8192) {
58
+ this.dropped++;
59
+ return;
60
+ }
61
+ this.events.push({
62
+ event,
63
+ at,
64
+ bytes
65
+ });
66
+ this.bytes += bytes;
67
+ while (this.events.length > 100 || this.bytes > 262144) this.evict();
68
+ }
69
+ read(query = {}) {
70
+ const after = query.after ?? 0;
71
+ const limit = query.limit ?? 20;
72
+ if (!Number.isSafeInteger(after) || after < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100 || query.sessionId !== void 0 && typeof query.sessionId !== "string") throw new Error("Invalid runtime error cursor or limit.");
73
+ this.expire(this.now());
74
+ const different = query.sessionId !== void 0 && query.sessionId !== this.sessionId;
75
+ const start = different ? 0 : after;
76
+ const events = this.events.filter(({ event }) => event.sequence > start).slice(0, limit).map(({ event }) => structuredClone(event));
77
+ const earliest = this.events[0]?.event.sequence ?? this.sequence + 1;
78
+ return {
79
+ schemaVersion: 1,
80
+ status: "available",
81
+ sessionId: this.sessionId,
82
+ startedAt: this.startedAt,
83
+ events,
84
+ nextCursor: {
85
+ sessionId: this.sessionId,
86
+ after: events.at(-1)?.sequence ?? this.sequence
87
+ },
88
+ dropped: this.dropped,
89
+ cursorExpired: different || start < earliest - 1 || start > this.sequence
90
+ };
91
+ }
92
+ evict() {
93
+ const removed = this.events.shift();
94
+ if (removed) {
95
+ this.bytes -= removed.bytes;
96
+ this.dropped++;
97
+ }
98
+ }
99
+ expire(at) {
100
+ while (this.events[0] && at - this.events[0].at >= 9e5) this.evict();
101
+ }
102
+ frames(stack) {
103
+ const root = this.root.replace(/\\/g, "/").replace(/\/$/, "") + "/";
104
+ const frames = [];
105
+ let actualRoot;
106
+ try {
107
+ actualRoot = realpathSync(this.root).replace(/\\/g, "/").replace(/\/$/, "") + "/";
108
+ } catch {
109
+ return frames;
110
+ }
111
+ for (const line of (stack ?? "").slice(0, 32768).split("\n").slice(1, 41)) {
112
+ const match = line.match(/(?:\(|\s)((?:file:\/\/)?(?:\/|[A-Za-z]:[\\/])[^\n]*):([0-9]+):([0-9]+)\)?$/);
113
+ if (!match) continue;
114
+ const path = match[1].replace(/^file:\/\//, "").replace(/\\/g, "/");
115
+ if (!path.startsWith(root)) continue;
116
+ const file = path.slice(root.length);
117
+ if (!/^[\w./@ -]+\.(?:[cm]?[jt]sx?)$/.test(file) || file.split("/").some((part) => part === ".." || part === "node_modules" || part.startsWith("."))) continue;
118
+ try {
119
+ const actual = realpathSync(path).replace(/\\/g, "/");
120
+ if (!actual.startsWith(actualRoot) || !statSync(actual).isFile()) continue;
121
+ } catch {
122
+ continue;
123
+ }
124
+ frames.push({
125
+ file,
126
+ line: Number(match[2]),
127
+ column: Number(match[3])
128
+ });
129
+ if (frames.length === 10) break;
130
+ }
131
+ return frames;
132
+ }
133
+ };
134
+ //#endregion
135
+ export { RUNTIME_ERRORS_BINDING, RUNTIME_ERRORS_PATH, RuntimeErrorBuffer };