@guren/server 2.25.1 → 2.27.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 (121) hide show
  1. package/dist/{DocsViewerServiceProvider-CIRNHQ2I.js → DocsViewerServiceProvider-BMbcTYVw.js} +1 -1
  2. package/dist/{Gate-YOt54xGF.js → Gate-BL_zW82W.js} +1 -1
  3. package/dist/{Job-COMzBNOL.js → Job-DsFMcXVk.js} +35 -3
  4. package/dist/{McpServiceProvider-B-LioPSz.js → McpServiceProvider-PGFPlYTy.js} +1 -1
  5. package/dist/{Resource-BdYd4J9a.js → Resource-q3tJpJ0K.js} +194 -54
  6. package/dist/{ServiceProvider-DDW3MqQJ.js → ServiceProvider-G0YclITd.js} +60 -8
  7. package/dist/agent/dispatch.d.ts +4 -4
  8. package/dist/agent/public.js +1 -1
  9. package/dist/agent/scopes.d.ts +1 -3
  10. package/dist/agent-request-Caj6bnbj.js +18 -0
  11. package/dist/auth/AuthManager.d.ts +4 -0
  12. package/dist/auth/email-verification.d.ts +8 -1
  13. package/dist/auth/index.js +1 -1
  14. package/dist/auth/password/describe-hasher.d.ts +11 -0
  15. package/dist/auth/password-reset.d.ts +8 -2
  16. package/dist/{auth-vFeem6uM.js → auth-DIugW0O-.js} +108 -13
  17. package/dist/authorization/index.js +2 -2
  18. package/dist/authorization/middleware.d.ts +8 -0
  19. package/dist/{authorization-BLhwA2Yh.js → authorization-Daa6CxCg.js} +17 -2
  20. package/dist/broadcasting/BroadcastManager.d.ts +23 -6
  21. package/dist/broadcasting/index.d.ts +1 -1
  22. package/dist/broadcasting/index.js +1 -1
  23. package/dist/broadcasting/types.d.ts +13 -1
  24. package/dist/{broadcasting-BUBCPCnu.js → broadcasting-N4cRV42s.js} +205 -34
  25. package/dist/cache/CacheManager.d.ts +5 -0
  26. package/dist/cache/TaggedCache.d.ts +2 -0
  27. package/dist/cache/index.js +1 -1
  28. package/dist/cache/pending-computations.d.ts +22 -0
  29. package/dist/cache/stores/FileStore.d.ts +2 -0
  30. package/dist/cache/stores/MemoryStore.d.ts +1 -0
  31. package/dist/cache/stores/RedisStore.d.ts +1 -0
  32. package/dist/cache/stores/file-lock.d.ts +1 -0
  33. package/dist/cache/types.d.ts +2 -0
  34. package/dist/{cache-93n2PCnB.js → cache-BlXopnH1.js} +247 -38
  35. package/dist/contained-path-BkNSBljW.js +78 -0
  36. package/dist/container/Container.d.ts +6 -2
  37. package/dist/container/ServiceProvider.d.ts +27 -2
  38. package/dist/container/defineModule.d.ts +14 -5
  39. package/dist/container/definePlugin.d.ts +2 -0
  40. package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
  41. package/dist/dev-banner-CfQDnkfQ.js +51 -0
  42. package/dist/{dispatch-BAwzftws.js → dispatch-ENWpBxbE.js} +26 -4
  43. package/dist/driver-map-CkQc52j-.js +12 -0
  44. package/dist/encryption/index.js +1 -1
  45. package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
  46. package/dist/events/EventManager.d.ts +2 -0
  47. package/dist/events/index.js +1 -1
  48. package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
  49. package/dist/health/HealthManager.d.ts +0 -1
  50. package/dist/health/index.js +1 -1
  51. package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
  52. package/dist/host-port-t6wQFaRu.js +15 -0
  53. package/dist/hot-reload/testing.d.ts +2 -1
  54. package/dist/http/Application.d.ts +31 -2
  55. package/dist/http/dev-banner.d.ts +0 -8
  56. package/dist/http/host-port.d.ts +8 -0
  57. package/dist/http/middleware/force-https.d.ts +2 -1
  58. package/dist/http/middleware/index.d.ts +1 -0
  59. package/dist/http/middleware/rate-limit.d.ts +1 -4
  60. package/dist/http/middleware/session-manager.d.ts +5 -0
  61. package/dist/http/middleware/websocket-origin.d.ts +22 -0
  62. package/dist/http/public-assets.d.ts +6 -1
  63. package/dist/i18n/index.js +1 -1
  64. package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
  65. package/dist/index.d.ts +8 -4
  66. package/dist/index.js +744 -273
  67. package/dist/internal/agent-request.d.ts +18 -0
  68. package/dist/internal/app-conventions.d.ts +6 -0
  69. package/dist/internal/app-conventions.js +9 -0
  70. package/dist/internal/dispatched-request.d.ts +4 -0
  71. package/dist/internal/testing.d.ts +1 -1
  72. package/dist/internal/testing.js +3 -3
  73. package/dist/internal/zod-json-schema.js +1 -1
  74. package/dist/introspection/driver-map.d.ts +3 -0
  75. package/dist/introspection/flag.d.ts +12 -0
  76. package/dist/introspection/manifest.d.ts +17 -0
  77. package/dist/introspection/plain-json.d.ts +7 -0
  78. package/dist/introspection/types.d.ts +167 -0
  79. package/dist/lambda/index.js +66 -28
  80. package/dist/logging/index.js +1 -1
  81. package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
  82. package/dist/mail/index.js +1 -1
  83. package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
  84. package/dist/mcp/index.js +1 -1
  85. package/dist/mvc/Controller.d.ts +3 -2
  86. package/dist/mvc/Router.d.ts +33 -0
  87. package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
  88. package/dist/mvc/inertia/props.d.ts +71 -0
  89. package/dist/notifications/index.js +1 -1
  90. package/dist/notifications/registry.d.ts +2 -2
  91. package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
  92. package/dist/providers/ConfigServiceProvider.d.ts +12 -5
  93. package/dist/queue/Job.d.ts +5 -0
  94. package/dist/queue/QueueManager.d.ts +3 -0
  95. package/dist/queue/Worker.d.ts +6 -1
  96. package/dist/queue/drivers/RedisDriver.d.ts +4 -2
  97. package/dist/queue/drivers/SqsDriver.d.ts +31 -2
  98. package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
  99. package/dist/queue/index.js +2 -2
  100. package/dist/queue/serialize.d.ts +7 -0
  101. package/dist/queue/types.d.ts +13 -2
  102. package/dist/{queue-BiBn5Sff.js → queue-C8s3buYz.js} +299 -125
  103. package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
  104. package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
  105. package/dist/redis/auth-token-scripts.d.ts +4 -0
  106. package/dist/redis/index.js +50 -0
  107. package/dist/runtime/index.js +17 -37
  108. package/dist/scheduling/ScheduledTask.d.ts +2 -1
  109. package/dist/scheduling/index.js +1 -1
  110. package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
  111. package/dist/serialize-CKXek0Tr.js +17 -0
  112. package/dist/storage/StorageManager.d.ts +5 -0
  113. package/dist/storage/drivers/LocalDriver.d.ts +15 -0
  114. package/dist/storage/index.js +1 -1
  115. package/dist/storage/url-path.d.ts +2 -0
  116. package/dist/{storage-6HLaUf9j.js → storage-IlUesK2t.js} +91 -29
  117. package/dist/support/contained-path.d.ts +8 -0
  118. package/dist/support/registry-collision.d.ts +12 -0
  119. package/dist/{vite-manifest-DK55BTLk.js → vite-manifest-wPxfAzjW.js} +2 -58
  120. package/package.json +6 -2
  121. package/dist/trim-slashes-BLY9hKAa.js +0 -22
@@ -11,6 +11,8 @@ export interface PluginDefinition<TConfig = void> {
11
11
  register(container: Container, config: TConfig): void | Promise<void>;
12
12
  /** Called after all providers have registered. */
13
13
  boot?(container: Container, config: TConfig): void | Promise<void>;
14
+ /** Called in place of `register` under introspection (RFC 0026 §2); see `ServiceProvider.introspect`. */
15
+ introspect?(container: Container, config: TConfig): void | Promise<void>;
14
16
  /** Defer instantiation until one of `provides` is resolved. */
15
17
  deferred?: boolean;
16
18
  /** Services bound by this plugin; required when `deferred` is true. */
@@ -1,4 +1,5 @@
1
1
  import { t as warnOnce } from "./warn-once-p-IlMjra.js";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
2
3
  //#region src/support/deprecate.ts
3
4
  /** The release these shims were deprecated in, and the one that removes them (RFC 0023 Part 3). */
4
5
  const SINCE = "2.23.0";
@@ -39,7 +40,7 @@ var Container = class Container {
39
40
  tags = /* @__PURE__ */ new Map();
40
41
  contextualBindings = [];
41
42
  resolvingStack = [];
42
- scopedInstances = [];
43
+ scope;
43
44
  fakes = /* @__PURE__ */ new Map();
44
45
  /**
45
46
  * @internal Installed by ProviderManager once every eager provider has booted.
@@ -87,8 +88,8 @@ var Container = class Container {
87
88
  const binding = this.bindings.get(resolvedKey) ?? this.loadDeferred(key, resolvedKey);
88
89
  if (!binding) throw new Error(`Service "${key}" not found in container`);
89
90
  if (binding.singleton && binding.instance !== void 0) return binding.instance;
90
- if (this.scopedInstances.length > 0) {
91
- const currentScope = this.scopedInstances[this.scopedInstances.length - 1];
91
+ const currentScope = this.scope?.getStore();
92
+ if (currentScope) {
92
93
  if (currentScope.has(resolvedKey)) return currentScope.get(resolvedKey);
93
94
  }
94
95
  const contextualFactory = this.findContextualBinding(resolvedKey);
@@ -96,7 +97,7 @@ var Container = class Container {
96
97
  try {
97
98
  const instance = (contextualFactory ?? binding.factory)(this);
98
99
  if (binding.singleton) binding.instance = instance;
99
- if (this.scopedInstances.length > 0 && !binding.singleton) this.scopedInstances[this.scopedInstances.length - 1].set(resolvedKey, instance);
100
+ if (!binding.singleton) currentScope?.set(resolvedKey, instance);
100
101
  return instance;
101
102
  } finally {
102
103
  this.resolvingStack.pop();
@@ -159,22 +160,17 @@ var Container = class Container {
159
160
  } };
160
161
  } };
161
162
  }
162
- /** Services resolved inside the callback are cached for the scope and released when it ends. */
163
+ /**
164
+ * Services resolved inside the callback are cached for the scope. The cache lives
165
+ * as long as the async context: work detached inside the scope (a timer, an
166
+ * un-awaited promise) keeps it and every cached instance reachable.
167
+ */
163
168
  scoped(callback) {
164
- this.scopedInstances.push(/* @__PURE__ */ new Map());
165
- try {
166
- return callback();
167
- } finally {
168
- this.scopedInstances.pop();
169
- }
169
+ this.scope ??= new AsyncLocalStorage();
170
+ return this.scope.run(/* @__PURE__ */ new Map(), callback);
170
171
  }
171
- async scopedAsync(callback) {
172
- this.scopedInstances.push(/* @__PURE__ */ new Map());
173
- try {
174
- return await callback();
175
- } finally {
176
- this.scopedInstances.pop();
177
- }
172
+ scopedAsync(callback) {
173
+ return this.scoped(callback);
178
174
  }
179
175
  fake(key, instance) {
180
176
  const shadowed = this.fakes.has(key) ? { instance: this.fakes.get(key) } : void 0;
@@ -0,0 +1,51 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
2
+ import { n as isWildcardHost, t as formatHostPort } from "./host-port-t6wQFaRu.js";
3
+ import chalk from "chalk";
4
+ import figlet from "figlet";
5
+ import standard from "figlet/importable-fonts/Standard.js";
6
+ //#region package.json
7
+ var version = "2.27.0";
8
+ //#endregion
9
+ //#region src/http/dev-banner.ts
10
+ var dev_banner_exports = /* @__PURE__ */ __exportAll({
11
+ GUREN_ASCII_ART: () => GUREN_ASCII_ART,
12
+ logDevServerBanner: () => logDevServerBanner
13
+ });
14
+ figlet.parseFont("Standard", standard);
15
+ function generateAsciiArt(text) {
16
+ try {
17
+ return figlet.textSync(text, {
18
+ font: "Standard",
19
+ horizontalLayout: "default",
20
+ verticalLayout: "default"
21
+ });
22
+ } catch (error) {
23
+ console.error("Failed to generate FIGlet banner, falling back to plain text:", error);
24
+ return text.toUpperCase();
25
+ }
26
+ }
27
+ const GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
28
+ const GUREN_VERSION = version;
29
+ function logDevServerBanner({ hostname, port, assetsUrl = "http://localhost:5173" }) {
30
+ const localUrl = `http://localhost:${port}`;
31
+ const boundUrl = `http://${formatHostPort(hostname, port)}`;
32
+ const boundLabel = isWildcardHost(hostname) ? " (all interfaces)" : "";
33
+ const header = [
34
+ GUREN_ASCII_ART,
35
+ chalk.magentaBright.bold(`Guren v${GUREN_VERSION} ignites — burning bright like a crimson lotus.`),
36
+ ""
37
+ ];
38
+ const detail = (label, value) => `${chalk.magentaBright(" •")} ${chalk.bold(label.padEnd(14))}: ${chalk.cyanBright(value)}`;
39
+ const banner = [
40
+ ...header,
41
+ detail("App URL", localUrl),
42
+ detail("Bound address", `${boundUrl}${boundLabel}`),
43
+ detail("Asset server", `${assetsUrl} (Vite)`),
44
+ "",
45
+ chalk.yellowBright("Press Ctrl+C to douse the flames."),
46
+ ""
47
+ ].join("\n");
48
+ console.log(banner);
49
+ }
50
+ //#endregion
51
+ export { dev_banner_exports as n, logDevServerBanner as r, GUREN_ASCII_ART as t };
@@ -1,4 +1,5 @@
1
1
  import { PATH_PARAM_PATTERN } from "./internal/route-path.js";
2
+ import { t as AGENT_SURFACE_HEADER } from "./agent-request-Caj6bnbj.js";
2
3
  //#region src/internal/agent-preflight.ts
3
4
  /**
4
5
  * The wire protocol of an agent preflight (RFC 0016 §5.4), in a leaf module so
@@ -17,6 +18,27 @@ const AGENT_PREFLIGHT_HEADER = "X-Guren-Agent-Preflight";
17
18
  */
18
19
  const AGENT_PREFLIGHT_VERDICT_HEADER = "X-Guren-Agent-Preflight-Verdict";
19
20
  //#endregion
21
+ //#region src/internal/dispatched-request.ts
22
+ /**
23
+ * Which `Request` objects the agent dispatcher built (RFC 0016 §3), keyed on
24
+ * **object identity** like the principal seam in `agent-principal.ts`: a
25
+ * request that crosses a socket arrives as a new object and carries nothing,
26
+ * so seeing the mark means the request was handed to `app.fetch` in this
27
+ * process. Not `isAgentToolRequest()` in `agent-request.ts`, whose header any
28
+ * client can send: that one only picks the shape of a refusal.
29
+ * Not exported from the package index.
30
+ */
31
+ const dispatched = /* @__PURE__ */ new WeakSet();
32
+ /** Mark `request` as built by `buildToolRequest`, returning that same object. */
33
+ function markDispatchedToolRequest(request) {
34
+ dispatched.add(request);
35
+ return request;
36
+ }
37
+ /** Whether this exact object was built by the dispatcher in this process. */
38
+ function isDispatchedToolRequest(request) {
39
+ return dispatched.has(request);
40
+ }
41
+ //#endregion
20
42
  //#region src/agent/dispatch.ts
21
43
  /** How many characters of a non-JSON response body survive into the result. */
22
44
  const TEXT_RESPONSE_CAP = 5e4;
@@ -79,7 +101,7 @@ function buildToolRequest(tool, args, options = {}) {
79
101
  }
80
102
  const headers = new Headers({
81
103
  Accept: "application/json",
82
- "X-Guren-Agent-Surface": options.surface ?? "mcp"
104
+ [AGENT_SURFACE_HEADER]: options.surface ?? "mcp"
83
105
  });
84
106
  if (options.authorization) headers.set("Authorization", options.authorization);
85
107
  if (options.preflight) headers.set(AGENT_PREFLIGHT_HEADER, "1");
@@ -92,11 +114,11 @@ function buildToolRequest(tool, args, options = {}) {
92
114
  if (body !== void 0) headers.set("Content-Type", "application/json");
93
115
  const qs = query.toString();
94
116
  const url = `${origin}${path}${qs ? `?${qs}` : ""}`;
95
- return { request: new Request(url, {
117
+ return { request: markDispatchedToolRequest(new Request(url, {
96
118
  method,
97
119
  headers,
98
120
  body
99
- }) };
121
+ })) };
100
122
  }
101
123
  /**
102
124
  * The contract a property was declared under, or undefined if the derivation
@@ -235,4 +257,4 @@ function isRecord(value) {
235
257
  return typeof value === "object" && value !== null && !Array.isArray(value);
236
258
  }
237
259
  //#endregion
238
- export { mapToolResponse as a, describeBuildFailure as i, advertisesStructuredOutput as n, AGENT_PREFLIGHT_HEADER as o, buildToolRequest as r, AGENT_PREFLIGHT_VERDICT_HEADER as s, PREFLIGHT_ARGUMENT as t };
260
+ export { mapToolResponse as a, AGENT_PREFLIGHT_VERDICT_HEADER as c, describeBuildFailure as i, advertisesStructuredOutput as n, isDispatchedToolRequest as o, buildToolRequest as r, AGENT_PREFLIGHT_HEADER as s, PREFLIGHT_ARGUMENT as t };
@@ -0,0 +1,12 @@
1
+ //#region src/introspection/driver-map.ts
2
+ /** `DriverMapEntry` from a manager's entries, each with the driver it was configured with or null. */
3
+ function describeDriverMap(defaultName, drivers) {
4
+ const entries = {};
5
+ for (const [name, driver] of drivers) entries[name] = { driver };
6
+ return {
7
+ default: defaultName,
8
+ entries
9
+ };
10
+ }
11
+ //#endregion
12
+ export { describeDriverMap as t };
@@ -1,5 +1,5 @@
1
1
  import { a as generateAppKey, c as parseAppKey, i as encodeDerivedKey, l as parsePreviousAppKeys, n as deriveAppKey, o as getAppKeyringFromEnv, r as deriveAppKeyring, s as normalizeAppKey, t as MessageSigner } from "../MessageSigner-Bd25ZJAV.js";
2
2
  import { a as md5, c as sha256, d as verifyPassword, i as hmac, l as sha512, n as hash, o as needsRehash, r as hashPassword, s as secureCompare, t as check, u as verifyHmac } from "../Hash-D2DFd8xX.js";
3
3
  import { a as random, c as randomHex, d as sample, f as shuffle, i as pick, l as randomInt, m as uuid, n as generatePassword, o as randomBase64, p as urlSafeToken, r as generateSlug, s as randomBase64Url, t as generateOtp, u as randomString } from "../Random-S0OvCuR8.js";
4
- import { a as decrypt, c as getEncrypter, i as createEncrypter, l as setEncrypter, n as verifySignedUrl, o as encrypt, r as Encrypter, s as generateKey, t as signUrl } from "../encryption-D1dxfMqD.js";
4
+ import { a as decrypt, c as getEncrypter, i as createEncrypter, l as setEncrypter, n as verifySignedUrl, o as encrypt, r as Encrypter, s as generateKey, t as signUrl } from "../encryption-CWK5l22W.js";
5
5
  export { Encrypter, MessageSigner, check, createEncrypter, decrypt, deriveAppKey, deriveAppKeyring, encodeDerivedKey, encrypt, generateAppKey, generateKey, generateOtp, generatePassword, generateSlug, getAppKeyringFromEnv, getEncrypter, hash, hashPassword, hmac, md5, needsRehash, normalizeAppKey, parseAppKey, parsePreviousAppKeys, pick, random, randomBase64, randomBase64Url, randomHex, randomInt, randomString, sample, secureCompare, setEncrypter, sha256, sha512, shuffle, signUrl, urlSafeToken, uuid, verifyHmac, verifyPassword, verifySignedUrl };
@@ -1,5 +1,5 @@
1
1
  import { a as generateAppKey, s as normalizeAppKey, t as MessageSigner } from "./MessageSigner-Bd25ZJAV.js";
2
- import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-D5ezhhiV.js";
2
+ import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-DWwscxfW.js";
3
3
  import { createCipheriv, createDecipheriv, createHmac, randomBytes } from "crypto";
4
4
  //#region src/encryption/Encrypter.ts
5
5
  /**
@@ -9,6 +9,7 @@ export declare class EventManager {
9
9
  /** Next `listenerSeq` per "<event>\u0000<queue>", never reset; see {@link RegisteredListener.listenerSeq}. */
10
10
  private readonly listenerSeqCounters;
11
11
  private queueDispatcher?;
12
+ private readonly claimedOnce;
12
13
  on<T extends Event>(event: EventClass<T> | string, listener: EventListener<T>, options?: ListenerOptions): EventSubscription;
13
14
  private register;
14
15
  once<T extends Event>(event: EventClass<T> | string, listener: EventListener<T>, options?: Omit<ListenerOptions, 'once'>): EventSubscription;
@@ -18,6 +19,7 @@ export declare class EventManager {
18
19
  * listeners anyway, so this is for a process that emits and never listens.
19
20
  */
20
21
  registerEvent(eventClass: EventClass): void;
22
+ private rememberEventClass;
21
23
  /**
22
24
  * Registers a `Listener` subclass under its own statics: `event`, `priority`,
23
25
  * and `queue` when `shouldQueue`. The instance is built per invocation, so
@@ -1,2 +1,2 @@
1
- import { a as RequestFinished, c as UserLoggedOut, d as EventManager, f as createEventManager, i as JobProcessed, l as createQueueEventDispatcher, n as ApplicationStarted, o as RequestReceived, p as Event, r as JobFailed, s as UserAuthenticated, t as ApplicationShutdown, u as Listener } from "../events-c94CdUFc.js";
1
+ import { a as RequestFinished, c as UserLoggedOut, d as EventManager, f as createEventManager, i as JobProcessed, l as createQueueEventDispatcher, n as ApplicationStarted, o as RequestReceived, p as Event, r as JobFailed, s as UserAuthenticated, t as ApplicationShutdown, u as Listener } from "../events-DQavGm8W.js";
2
2
  export { ApplicationShutdown, ApplicationStarted, Event, EventManager, JobFailed, JobProcessed, Listener, RequestFinished, RequestReceived, UserAuthenticated, UserLoggedOut, createEventManager, createQueueEventDispatcher };
@@ -1,5 +1,5 @@
1
1
  import { t as warnOnce } from "./warn-once-p-IlMjra.js";
2
- import { d as resolveQueueDriver, l as registerJob, t as Job } from "./Job-COMzBNOL.js";
2
+ import { d as resolveQueueDriver, l as registerJob, p as reportRegistryCollision, t as Job } from "./Job-DsFMcXVk.js";
3
3
  //#region src/events/Event.ts
4
4
  /** Base class for all application events. */
5
5
  var Event = class {
@@ -67,12 +67,13 @@ var EventManager = class {
67
67
  /** Next `listenerSeq` per "<event>\u0000<queue>", never reset; see {@link RegisteredListener.listenerSeq}. */
68
68
  listenerSeqCounters = /* @__PURE__ */ new Map();
69
69
  queueDispatcher;
70
+ claimedOnce = /* @__PURE__ */ new WeakSet();
70
71
  on(event, listener, options = {}) {
71
72
  return this.register(event, listener, options);
72
73
  }
73
74
  register(event, listener, options, failed) {
74
75
  const eventName = this.nameOf(event);
75
- if (typeof event !== "string") this.eventClasses.set(eventName, event);
76
+ if (typeof event !== "string") this.rememberEventClass(eventName, event);
76
77
  const registeredListeners = this.listeners.get(eventName) ?? [];
77
78
  const registered = {
78
79
  listener,
@@ -101,7 +102,11 @@ var EventManager = class {
101
102
  * listeners anyway, so this is for a process that emits and never listens.
102
103
  */
103
104
  registerEvent(eventClass) {
104
- this.eventClasses.set(resolveEventName(eventClass), eventClass);
105
+ this.rememberEventClass(resolveEventName(eventClass), eventClass);
106
+ }
107
+ rememberEventClass(eventName, eventClass) {
108
+ reportRegistryCollision("event", eventName, this.eventClasses.get(eventName), eventClass);
109
+ this.eventClasses.set(eventName, eventClass);
105
110
  }
106
111
  /**
107
112
  * Registers a `Listener` subclass under its own statics: `event`, `priority`,
@@ -163,14 +168,22 @@ var EventManager = class {
163
168
  const registeredListeners = this.listeners.get(eventName);
164
169
  if (!registeredListeners || registeredListeners.length === 0) return;
165
170
  const listenersToCall = [...registeredListeners];
166
- const toRemove = [];
167
171
  const call = async (registered) => {
168
- const queued = await this.invoke(registered, event, eventName);
169
- if (registered.options.once && !queued) toRemove.push(registered);
172
+ if (registered.options.once) {
173
+ if (this.claimedOnce.has(registered)) return;
174
+ this.claimedOnce.add(registered);
175
+ }
176
+ try {
177
+ const queued = await this.invoke(registered, event, eventName);
178
+ if (registered.options.once && !queued) this.forget(eventName, registeredListeners, [registered]);
179
+ if (queued) this.claimedOnce.delete(registered);
180
+ } catch (error) {
181
+ this.claimedOnce.delete(registered);
182
+ throw error;
183
+ }
170
184
  };
171
185
  if (parallel) await Promise.all(listenersToCall.map(call));
172
186
  else for (const registered of listenersToCall) await call(registered);
173
- this.forget(eventName, registeredListeners, toRemove);
174
187
  }
175
188
  /** Resolves whether the listener was sent to a queue rather than run here. */
176
189
  async invoke(registered, event, eventName) {
@@ -12,6 +12,5 @@ export declare class HealthManager {
12
12
  middleware(options?: HealthMiddlewareOptions): Middleware;
13
13
  private runChecks;
14
14
  private runCheck;
15
- private timeoutPromise;
16
15
  }
17
16
  export declare function createHealthManager(): HealthManager;
@@ -1,2 +1,2 @@
1
- import { a as CacheCheck, c as HealthManager, i as StorageCheck, l as createHealthManager, n as customCheck, o as RedisCheck, r as MemoryCheck, s as DatabaseCheck, t as CustomCheck, u as HealthCheck } from "../health-CB0oS_UE.js";
1
+ import { a as CacheCheck, c as HealthManager, i as StorageCheck, l as createHealthManager, n as customCheck, o as RedisCheck, r as MemoryCheck, s as DatabaseCheck, t as CustomCheck, u as HealthCheck } from "../health-Bg0Xj3aD.js";
2
2
  export { CacheCheck, CustomCheck, DatabaseCheck, HealthCheck, HealthManager, MemoryCheck, RedisCheck, StorageCheck, createHealthManager, customCheck };
@@ -96,8 +96,13 @@ var HealthManager = class {
96
96
  async runCheck(registered) {
97
97
  const { check, options } = registered;
98
98
  const start = performance.now();
99
+ let timer;
99
100
  try {
100
- const result = await Promise.race([check.check(), this.timeoutPromise(options.timeout)]);
101
+ const result = await Promise.race([check.check(), new Promise((_, reject) => {
102
+ timer = setTimeout(() => {
103
+ reject(/* @__PURE__ */ new Error(`Health check timed out after ${options.timeout}ms`));
104
+ }, options.timeout);
105
+ })]);
101
106
  result.duration = Math.round(performance.now() - start);
102
107
  return result;
103
108
  } catch (error) {
@@ -108,15 +113,10 @@ var HealthManager = class {
108
113
  message: error instanceof Error ? error.message : "Check failed with error",
109
114
  duration
110
115
  };
116
+ } finally {
117
+ clearTimeout(timer);
111
118
  }
112
119
  }
113
- timeoutPromise(ms) {
114
- return new Promise((_, reject) => {
115
- setTimeout(() => {
116
- reject(/* @__PURE__ */ new Error(`Health check timed out after ${ms}ms`));
117
- }, ms);
118
- });
119
- }
120
120
  };
121
121
  function createHealthManager() {
122
122
  return new HealthManager();
@@ -0,0 +1,15 @@
1
+ //#region src/http/host-port.ts
2
+ /**
3
+ * A wildcard bind answers on every interface but is not itself dialable on
4
+ * every platform. The dev banner and `Application.listen()`'s returned address
5
+ * both render this fact.
6
+ */
7
+ function isWildcardHost(hostname) {
8
+ return hostname === "0.0.0.0" || hostname === "::";
9
+ }
10
+ /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
11
+ function formatHostPort(hostname, port) {
12
+ return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
13
+ }
14
+ //#endregion
15
+ export { isWildcardHost as n, formatHostPort as t };
@@ -4,6 +4,7 @@
4
4
  */
5
5
  /**
6
6
  * Runs `callback` with the registry's `--hot` guard satisfied. The guard reads
7
- * `process.execArgv`, which is also how the real thing detects `bun --hot`.
7
+ * `process.execArgv`, which is also how the real thing detects `bun --hot`. A
8
+ * callback returning a promise keeps the flag until that promise settles.
8
9
  */
9
10
  export declare function withHotRuntime<T>(callback: () => T): T;
@@ -11,12 +11,13 @@ import type { DetectLocaleOptions } from './middleware/detect-locale.js';
11
11
  import type { TranslationLoader } from '../i18n/index.js';
12
12
  import { type SecurityHeadersOptions } from './middleware/security-headers.js';
13
13
  import { type HostAuthorizationOptions } from './middleware/host-authorization.js';
14
- import { type DevBannerOptions } from './dev-banner.js';
14
+ import type { DevBannerOptions } from './dev-banner.js';
15
15
  import { startViteDevServer, type StartViteDevServerOptions } from './vite-dev-server.js';
16
16
  import type { InertiaDocumentOptions, InertiaSsrRenderer } from '../mvc/inertia/InertiaEngine.js';
17
17
  import { type SharedInertiaPropsResolver } from '../mvc/inertia/shared.js';
18
18
  import type { EnvSchema } from '../config/env.js';
19
19
  import type { ConfigDefinition } from '../config/define.js';
20
+ import type { AppManifest } from '../introspection/types.js';
20
21
  type BunServer = {
21
22
  stop?: (closeConnections?: boolean) => void | Promise<void>;
22
23
  requestIP?: (request: Request) => {
@@ -89,10 +90,18 @@ export interface ApplicationOptions {
89
90
  readonly env?: EnvSchema;
90
91
  /**
91
92
  * The definitions `config/*.ts` export, resolved against `env` and bound before
92
- * any provider registers (RFC 0027 §2). One definition per key.
93
+ * any provider registers (RFC 0027 §2). One definition per key, counting the
94
+ * `config` of every module.
93
95
  */
94
96
  readonly config?: ReadonlyArray<ConfigDefinition>;
95
97
  }
98
+ /** A config definition and where it was listed: `createApp({ config })[index]`, or a module's `config[index]`. */
99
+ export interface ConfiguredDefinition {
100
+ readonly definition: ConfigDefinition;
101
+ readonly index: number;
102
+ /** The listing module's name; absent for `createApp({ config })`. */
103
+ readonly module?: string;
104
+ }
96
105
  export interface InertiaApplicationOptions {
97
106
  /** Document defaults for server-rendered responses; each per-response {@link InertiaOptions} field overrides its own. */
98
107
  readonly document?: InertiaDocumentOptions;
@@ -183,13 +192,18 @@ export declare class Application {
183
192
  private disposeBunTeardown?;
184
193
  private autoSessionAttached;
185
194
  private readonly cookielessAuthPaths;
195
+ /** {@link configDefinitions} with where each was listed, which ConfigServiceProvider's errors name. */
196
+ readonly configEntries: ReadonlyArray<ConfiguredDefinition>;
186
197
  private routesRegistered;
187
198
  private bootPromise?;
199
+ private manifestPromise?;
200
+ private bootAttempted;
188
201
  constructor(options?: ApplicationOptions);
189
202
  get auth(): AuthManager;
190
203
  get authOptions(): AuthPluginOptions | undefined;
191
204
  get i18nOptions(): I18nPluginOptions | undefined;
192
205
  get envSchema(): EnvSchema | undefined;
206
+ /** `createApp({ config })`, then each module's `config` in `modules` order (RFC 0002, RFC 0027 §2). */
193
207
  get configDefinitions(): ReadonlyArray<ConfigDefinition>;
194
208
  markAutoSessionAttached(): void;
195
209
  /** Whether `key` is supplied by a deferred provider, which only activates on a `make()` after boot. */
@@ -206,6 +220,8 @@ export declare class Application {
206
220
  /** Matched by exact path — see {@link declareCookielessAuthPath}. */
207
221
  getCookielessAuthPaths(): ReadonlySet<string>;
208
222
  mountRoutes(): Promise<void>;
223
+ /** Runs the registrars once; `introspect()` stops here, since mounting refuses an unregistered alias it reports. */
224
+ private registerRoutes;
209
225
  /**
210
226
  * Every failure here is one a request would otherwise surface as a 500:
211
227
  * an unnamed prototype route cannot be looked up, a named one the fixture
@@ -230,6 +246,13 @@ export declare class Application {
230
246
  * unbooted. Never await it from a provider's own `boot`: it waits on itself.
231
247
  */
232
248
  booted(): Promise<void>;
249
+ /**
250
+ * Registers providers and routes, then describes the result (RFC 0026 §1).
251
+ * Never mounts on Hono or runs `createApp({ boot })`, a provider's `boot()`
252
+ * or `listen()`. Memoised; the application cannot boot afterwards.
253
+ */
254
+ introspect(): Promise<AppManifest>;
255
+ private introspectOnce;
233
256
  private bootOnce;
234
257
  /**
235
258
  * After every provider has booted: `auth` was asked for, yet the default
@@ -275,6 +298,12 @@ export declare class Application {
275
298
  stop(closeActiveConnections?: boolean): Promise<void>;
276
299
  register(provider: ServiceProviderConstructor): this;
277
300
  registerMany(providers: Array<ServiceProviderConstructor>): this;
301
+ /**
302
+ * Prints the dev server banner. `listen()` loads the banner module first, so it
303
+ * prints there at once; a call before anything has loaded it prints once the
304
+ * import settles. The module is never loaded under `NODE_ENV=production`, which
305
+ * keeps it out of deploy bundles, so a call there prints nothing.
306
+ */
278
307
  logDevServerBanner(options: DevBannerOptions): void;
279
308
  /**
280
309
  * Closes the managed Vite dev server, but only while this application still
@@ -4,12 +4,4 @@ export interface DevBannerOptions {
4
4
  port: number;
5
5
  assetsUrl?: string;
6
6
  }
7
- /**
8
- * A wildcard bind answers on every interface but is not itself dialable on
9
- * every platform. Shared with `Application.listen()`'s returned address, which
10
- * is the same fact rendered twice.
11
- */
12
- export declare function isWildcardHost(hostname: string): boolean;
13
- /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
14
- export declare function formatHostPort(hostname: string, port: number): string;
15
7
  export declare function logDevServerBanner({ hostname, port, assetsUrl, }: DevBannerOptions): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A wildcard bind answers on every interface but is not itself dialable on
3
+ * every platform. The dev banner and `Application.listen()`'s returned address
4
+ * both render this fact.
5
+ */
6
+ export declare function isWildcardHost(hostname: string): boolean;
7
+ /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
8
+ export declare function formatHostPort(hostname: string, port: number): string;
@@ -11,6 +11,7 @@ export interface ForceHttpsOptions {
11
11
  }
12
12
  /**
13
13
  * Redirects HTTP to HTTPS and sets Strict-Transport-Security. Equivalent to
14
- * Rails' `force_ssl`.
14
+ * Rails' `force_ssl`. An agent tool call the dispatcher re-enters in process
15
+ * passes through.
15
16
  */
16
17
  export declare function createForceHttpsMiddleware(options?: ForceHttpsOptions): MiddlewareHandler;
@@ -18,6 +18,7 @@ export { createSecurityHeaders, type SecurityHeadersOptions, type HstsOptions, }
18
18
  export { createCspMiddleware, getCspNonce, CSP_NONCE_KEY, type CspOptions, type CspDirectives, } from './csp.js';
19
19
  export { createHostAuthorizationMiddleware, type HostAuthorizationOptions, } from './host-authorization.js';
20
20
  export { createCorsMiddleware, type CorsOptions, } from './cors.js';
21
+ export { createWebSocketOriginGuard, type WebSocketOriginOptions, } from './websocket-origin.js';
21
22
  export { createRedirectSafetyMiddleware, isSafeRedirectUrl, type RedirectSafetyOptions, } from './redirect-safety.js';
22
23
  export { createForceHttpsMiddleware, type ForceHttpsOptions, } from './force-https.js';
23
24
  export { requestIdMiddleware } from './request-id.js';
@@ -15,10 +15,7 @@ export interface RateLimitStore {
15
15
  declare abstract class BaseMemoryStore implements RateLimitStore {
16
16
  protected readonly now: () => number;
17
17
  protected cleanupInterval?: ReturnType<typeof setInterval>;
18
- /**
19
- * Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
20
- * both duplicates work and keeps the process alive on its own.
21
- */
18
+ /** A sweep leaked across a hot reload would run beside this one. */
22
19
  private readonly hotReloadClaim;
23
20
  constructor(cleanupIntervalMs?: number, now?: () => number);
24
21
  abstract get(key: string): Promise<RateLimitEntry | null>;
@@ -1,4 +1,5 @@
1
1
  import { type SessionCookieOptions, type SessionStore } from './session.js';
2
+ import type { SessionEntry } from '../../introspection/types.js';
2
3
  export interface MemorySessionDriverOptions {
3
4
  /** Clock for expiry, injectable for tests. @default Date.now */
4
5
  now?: () => number;
@@ -48,6 +49,8 @@ export declare const PER_PROCESS_SESSION_DRIVERS: ReadonlySet<string>;
48
49
  * manifest instead, and a name in neither is unverifiable, not absent.
49
50
  */
50
51
  export declare const BUILT_IN_SESSION_DRIVERS: ReadonlyMap<string, boolean>;
52
+ /** Null for a driver outside {@link BUILT_IN_SESSION_DRIVERS}: a plugin's `gurenPlugin` manifest says which it is. */
53
+ export declare function sessionDriverIsPerProcess(driver: string): boolean | null;
51
54
  /** Cookie and TTL settings plus the named stores one of which is the default. */
52
55
  export interface SessionConfig extends SessionCookieOptions {
53
56
  /** @default 'memory' */
@@ -82,6 +85,8 @@ export declare class SessionManager {
82
85
  registerDriver<K extends keyof SessionDrivers>(name: K, factory: SessionDriverFactory<SessionDrivers[K]>): void;
83
86
  registerDriver(name: string, factory: SessionDriverFactory): void;
84
87
  getStoreNames(): string[];
88
+ /** The declared stores and the default, building none of them (RFC 0026 §1). */
89
+ describe(): Omit<SessionEntry, 'source'>;
85
90
  /**
86
91
  * Sweep expired sessions from the default store and from any other store
87
92
  * already built, on stores that support it (`deleteExpired`). Stores that
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The check against Cross-Site WebSocket Hijacking. CORS does not cover a
3
+ * WebSocket handshake and the browser sends the app's cookies with it, so a page
4
+ * on another site could open a socket as the signed-in user. The browser sets
5
+ * both `Origin` and `Host`, and a page elsewhere cannot make them agree.
6
+ */
7
+ import type { Context, MiddlewareHandler } from 'hono';
8
+ export interface WebSocketOriginOptions {
9
+ /**
10
+ * Origins that may open a socket besides the request's own host, such as
11
+ * `https://app.example.com` behind a proxy that rewrites `Host`.
12
+ */
13
+ allowedOrigins?: string[];
14
+ }
15
+ /**
16
+ * Hosts are compared, not schemes: TLS usually ends at a proxy, so the app sees
17
+ * `http:`. No `Origin` is not a browser and carries no ambient cookies; `null`
18
+ * (sandboxed frames, file://) fails to parse and is refused.
19
+ */
20
+ export declare function webSocketOriginCheck(allowedOrigins?: string[]): (ctx: Context) => boolean;
21
+ /** Refuses, with 403, a request whose `Origin` is neither the app's own host nor listed. */
22
+ export declare function createWebSocketOriginGuard(options?: WebSocketOriginOptions): MiddlewareHandler;
@@ -5,7 +5,12 @@ import type { Application } from './Application.js';
5
5
  * extending it — an app that wants one more extension spreads this rather
6
6
  * than restating it, so additions here reach it.
7
7
  */
8
- export declare const DEFAULT_ROOT_PUBLIC_ASSET_EXTENSIONS: readonly ['.svg', '.png', '.jpg', '.jpeg', '.gif', '.ico', '.webp', '.avif', '.webmanifest', '.txt'];
8
+ export declare const DEFAULT_ROOT_PUBLIC_ASSET_EXTENSIONS: readonly ['.svg', '.png', '.jpg', '.jpeg', '.gif', '.ico', '.webp', '.avif', '.webmanifest', '.txt', '.woff2', '.woff', '.ttf', '.otf'];
9
+ /**
10
+ * Must give each extension the media type Hono's `getMimeType` does
11
+ * (`public-assets.test.ts`): `serveStatic` types the same file under `/public/*`.
12
+ */
13
+ export declare const DEFAULT_CONTENT_TYPES: Readonly<Record<string, string>>;
9
14
  export type RootPublicAssetsConfig = boolean | RootPublicAssetsOptions;
10
15
  export interface RootPublicAssetsOptions {
11
16
  /** Enable or disable root-level public asset serving. Defaults to true. */
@@ -1,2 +1,2 @@
1
- import { a as resolveI18n, c as tc, d as Translator, f as getPluralizationRule, i as getI18n, l as tryGetI18n, m as selectPluralForm, n as I18nManager, o as setI18n, p as pluralizationRules, r as createI18n, s as t, t as MemoryLoader, u as JsonLoader } from "../i18n-DqcRD4qL.js";
1
+ import { a as resolveI18n, c as tc, d as Translator, f as getPluralizationRule, i as getI18n, l as tryGetI18n, m as selectPluralForm, n as I18nManager, o as setI18n, p as pluralizationRules, r as createI18n, s as t, t as MemoryLoader, u as JsonLoader } from "../i18n-DmMKcbqj.js";
2
2
  export { I18nManager, JsonLoader, MemoryLoader, Translator, createI18n, getI18n, getPluralizationRule, pluralizationRules, resolveI18n, selectPluralForm, setI18n, t, tc, tryGetI18n };
@@ -1,4 +1,4 @@
1
- import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-D5ezhhiV.js";
1
+ import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-DWwscxfW.js";
2
2
  import { basename, extname, join } from "node:path";
3
3
  import { readFile, readdir } from "node:fs/promises";
4
4
  //#region src/i18n/pluralization.ts