@vite-hub/runtime 0.5.0 → 0.6.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 (60) hide show
  1. package/dist/{core-DpLK9dQt.js → core-Crv8CV_r.js} +5 -7
  2. package/dist/{core-BfUEli_0.d.ts → core-auTkK4iZ.d.ts} +0 -6
  3. package/dist/detect-host-Du9saPsM.js +57 -0
  4. package/dist/detect-host-uTgoQ9i4.d.ts +17 -0
  5. package/dist/durability.d.ts +1 -3
  6. package/dist/durability.js +1 -2
  7. package/dist/{error-diagnostics-BM9W4pBg.js → error-diagnostics-Dj98U7ch.js} +1 -2
  8. package/dist/{error-diagnostics-0sYgKTT8.d.ts → error-diagnostics-DuusexaK.d.ts} +0 -2
  9. package/dist/{errors-BQ0ofIL4.js → errors-D2ixvqv3.js} +2 -3
  10. package/dist/{execution-budget-BPXbISEt.d.ts → execution-budget-Bv7h0-5V.d.ts} +0 -2
  11. package/dist/{hosted-console-ZfMo5MW4.d.ts → hosted-console-DInG3Xl9.d.ts} +3 -6
  12. package/dist/hosted-console-nLc1pL9J.js +71 -0
  13. package/dist/{index-DsisbCNa.d.ts → index-fSQ1ELEy.d.ts} +3 -38
  14. package/dist/index.d.ts +7 -6
  15. package/dist/index.js +7 -5
  16. package/dist/internal/console.d.ts +10 -5
  17. package/dist/internal/console.js +3 -2
  18. package/dist/internal/context.d.ts +1 -1
  19. package/dist/internal/context.js +1 -2
  20. package/dist/internal/detect-host.d.ts +2 -0
  21. package/dist/internal/detect-host.js +1 -0
  22. package/dist/internal/drain.d.ts +1 -3
  23. package/dist/internal/drain.js +3 -5
  24. package/dist/internal/error-diagnostics.d.ts +1 -1
  25. package/dist/internal/error-diagnostics.js +1 -2
  26. package/dist/internal/execution-budget.d.ts +1 -3
  27. package/dist/internal/execution-budget.js +3 -5
  28. package/dist/internal/grant.d.ts +1 -2
  29. package/dist/internal/grant.js +3 -4
  30. package/dist/internal/h3.d.ts +2 -4
  31. package/dist/internal/h3.js +4 -6
  32. package/dist/internal/node.d.ts +2 -3
  33. package/dist/internal/node.js +2 -3
  34. package/dist/internal/public-url.d.ts +1 -1
  35. package/dist/internal/public-url.js +1 -2
  36. package/dist/internal/response.d.ts +1 -1
  37. package/dist/internal/response.js +1 -2
  38. package/dist/internal/run-failed.d.ts +1 -3
  39. package/dist/internal/run-failed.js +1 -2
  40. package/dist/internal/run-scope.d.ts +1 -3
  41. package/dist/internal/run-scope.js +1 -2
  42. package/dist/internal/runtime-type.d.ts +1 -3
  43. package/dist/internal/runtime-type.js +2 -2
  44. package/dist/internal/shutdown.d.ts +1 -3
  45. package/dist/internal/shutdown.js +1 -2
  46. package/dist/internal/test-mode-setup.d.ts +1 -3
  47. package/dist/internal/test-mode-setup.js +1 -2
  48. package/dist/internal/test-mode.d.ts +1 -3
  49. package/dist/internal/test-mode.js +1 -2
  50. package/dist/internal/trace.d.ts +2 -4
  51. package/dist/internal/trace.js +1 -2
  52. package/dist/operations.d.ts +0 -3
  53. package/dist/operations.js +9 -10
  54. package/dist/{public-url-BCFhTiTM.d.ts → public-url-CaVJ4vFF.d.ts} +1 -2
  55. package/dist/{public-url-DizC8CFs.js → public-url-TlEVxNNh.js} +10 -72
  56. package/dist/{request-context-Dmsliqan.js → request-context-Dcf59Qh4.js} +11 -73
  57. package/dist/{response-iONbTI0E.d.ts → response-ClQ9ZSS_.d.ts} +0 -2
  58. package/dist/{response-Be5M4WIn.js → response-DEyMvEBF.js} +5 -7
  59. package/dist/{runtime-type-CHYQYwDx.js → runtime-type-EgaBGoVU.js} +2 -4
  60. package/package.json +9 -4
@@ -1,6 +1,6 @@
1
- import { r as isRuntimeObject } from "../runtime-type-CHYQYwDx.js";
2
- import { t as ViteHubError } from "../errors-BQ0ofIL4.js";
3
- //#region src/internal/grant.ts
1
+ import { t as ViteHubError } from "../errors-D2ixvqv3.js";
2
+ import { r as isRuntimeObject } from "../runtime-type-EgaBGoVU.js";
3
+ // src/internal/grant.ts
4
4
  /**
5
5
  * Define one kind of grant. Keep the definition module-private: the module that owns the check issues grants,
6
6
  * and the sensitive action verifies them. Each definition has its own registry, so a grant from another definition,
@@ -40,5 +40,4 @@ function defineGrant(kind, bind) {
40
40
  }
41
41
  });
42
42
  }
43
- //#endregion
44
43
  export { defineGrant };
@@ -1,7 +1,6 @@
1
- import { dt as ViteHubContext, ft as ViteHubRuntime, pt as ViteHubStandardProps } from "../core-BfUEli_0.js";
2
- import { a as RequestRuntimeContext, d as sendPreparedResponse, o as RuntimeContextOptions, u as installRequestStandardContext } from "../index-DsisbCNa.js";
1
+ import { c as installRequestStandardContext, i as RuntimeContextOptions, l as sendPreparedResponse, r as RequestRuntimeContext } from "../index-fSQ1ELEy.js";
2
+ import { dt as ViteHubContext, ft as ViteHubRuntime, pt as ViteHubStandardProps } from "../core-auTkK4iZ.js";
3
3
  import { EventHandlerRequest } from "h3";
4
- //#region src/internal/h3.d.ts
5
4
  declare module "h3" {
6
5
  interface H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> {
7
6
  readonly "~standard": ViteHubStandardProps;
@@ -38,5 +37,4 @@ export declare function getStandardContext(value: Request | ViteHubContext): Vit
38
37
  /** Adapt one request. Pass an H3 event or a web Request. Await flushWaitUntil when the host has no lifetime API. */
39
38
  export declare function getRuntimeContext(value: Request | ViteHubContext): H3RuntimeContext;
40
39
  export declare function getRuntimeContext<const TOptions extends H3RuntimeContextOptions>(value: Request | ViteHubContext, options: TOptions): H3RuntimeContext<TOptions>;
41
- //#endregion
42
40
  export { type ViteHubContext, type ViteHubRuntime, type ViteHubStandardProps, installRequestStandardContext, sendPreparedResponse };
@@ -1,7 +1,7 @@
1
- import { S as ownValue, a as installRequestStandardContext, b as getCloudflareEnv, c as sendPreparedResponse, i as getStandardContext$1, n as firstAddress, o as isHostRequest, s as requestAddressPaths, t as createStandardRuntimeContext, v as activeEnvStorageKey, x as ownObject, y as cloudflareOwners } from "../request-context-Dmsliqan.js";
2
- import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
1
+ import { _ as activeEnvStorageKey, a as installRequestStandardContext, b as ownObject, c as sendPreparedResponse, i as getStandardContext$1, n as firstAddress, o as isHostRequest, s as requestAddressPaths, t as createStandardRuntimeContext, v as cloudflareOwners, x as ownValue, y as getCloudflareEnv } from "../request-context-Dcf59Qh4.js";
2
+ import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
- //#region ../internal/dist/runtime/cloudflare-env.js
4
+ // ../internal/dist/runtime/cloudflare-env.js
5
5
  const runtimeGlobal = globalThis;
6
6
  runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
7
7
  /** Return the Cloudflare Worker execution context of a request event, if the host provides one. */
@@ -38,8 +38,7 @@ function resolveWaitUntil(event, options = {}) {
38
38
  if (typeof waitUntil === "function") return waitUntil.bind(owner);
39
39
  }
40
40
  }
41
- //#endregion
42
- //#region src/internal/h3.ts
41
+ // src/internal/h3.ts
43
42
  function responseHeaders(target) {
44
43
  const { headers, errHeaders } = target;
45
44
  if (!errHeaders) return headers;
@@ -171,5 +170,4 @@ function getRuntimeContext(value, options = {}) {
171
170
  }
172
171
  return createStandardRuntimeContext(value, value["~standard"], options);
173
172
  }
174
- //#endregion
175
173
  export { getRuntimeContext, getStandardContext, installRequestStandardContext, installStandardContext, sendPreparedResponse };
@@ -1,5 +1,4 @@
1
- import { w as RuntimeResourceInspector } from "../index-DsisbCNa.js";
2
- //#region src/internal/node.d.ts
1
+ import { S as RuntimeResourceInspector } from "../index-fSQ1ELEy.js";
3
2
  type ReadText = (path: string, options?: {
4
3
  signal?: AbortSignal;
5
4
  }) => Promise<string>;
@@ -30,4 +29,4 @@ export interface ProcessReconciler extends ProcessReconcilerRunContext {
30
29
  wake: (reason: string) => void;
31
30
  }
32
31
  export declare function createProcessReconciler(options: ProcessReconcilerOptions): ProcessReconciler;
33
- //#endregion
32
+ export {};
@@ -1,9 +1,9 @@
1
- import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
1
+ import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
5
  import { availableMemory, memoryUsage, resourceUsage } from "node:process";
6
- //#region src/internal/node.ts
6
+ // src/internal/node.ts
7
7
  function observation(name, value, scope, source, unit) {
8
8
  return value === void 0 || !Number.isFinite(value) ? [] : [{
9
9
  name,
@@ -395,5 +395,4 @@ function createProcessReconciler(options) {
395
395
  wake
396
396
  };
397
397
  }
398
- //#endregion
399
398
  export { createProcessReconciler, nodeRuntimeResources, resolveLinuxCgroupV2Path };
@@ -1,2 +1,2 @@
1
- import { a as resetPublicUrlAgentNames, i as registerPublicUrlAgentName, n as configuredPublicOrigins } from "../public-url-BCFhTiTM.js";
1
+ import { a as resetPublicUrlAgentNames, i as registerPublicUrlAgentName, n as configuredPublicOrigins } from "../public-url-CaVJ4vFF.js";
2
2
  export { configuredPublicOrigins, registerPublicUrlAgentName, resetPublicUrlAgentNames };
@@ -1,2 +1 @@
1
- import { i as resetPublicUrlAgentNames, r as registerPublicUrlAgentName, t as configuredPublicOrigins } from "../public-url-DizC8CFs.js";
2
- export { configuredPublicOrigins, registerPublicUrlAgentName, resetPublicUrlAgentNames };
1
+ export { t as configuredPublicOrigins, r as registerPublicUrlAgentName, i as resetPublicUrlAgentNames } from "../public-url-TlEVxNNh.js";
@@ -1,2 +1,2 @@
1
- import { a as serializeResponse, i as isSerializedResponse, n as deserializeResponse, o as toResponse, r as isResponse } from "../response-iONbTI0E.js";
1
+ import { a as serializeResponse, i as isSerializedResponse, n as deserializeResponse, o as toResponse, r as isResponse } from "../response-ClQ9ZSS_.js";
2
2
  export { deserializeResponse, isResponse, isSerializedResponse, serializeResponse, toResponse };
@@ -1,2 +1 @@
1
- import { a as toResponse, i as serializeResponse, n as isResponse, r as isSerializedResponse, t as deserializeResponse } from "../response-Be5M4WIn.js";
2
- export { deserializeResponse, isResponse, isSerializedResponse, serializeResponse, toResponse };
1
+ export { t as deserializeResponse, n as isResponse, r as isSerializedResponse, i as serializeResponse, a as toResponse } from "../response-DEyMvEBF.js";
@@ -1,4 +1,3 @@
1
- //#region src/internal/run-failed.d.ts
2
1
  /** The error of a failed run: its message and, for a ViteHub error, its code. */
3
2
  export interface RunFailedError {
4
3
  message: string;
@@ -36,5 +35,4 @@ export declare function toRunFailedError(error: unknown): RunFailedError;
36
35
  * serverless host keeps the work alive, and it never throws: an alert that fails must not change the run.
37
36
  */
38
37
  export declare function emitRunFailed(event: RunFailedEvent): Promise<void>;
39
- export declare function hasRunFailedListeners(): boolean;
40
- //#endregion
38
+ export declare function hasRunFailedListeners(): boolean;
@@ -1,4 +1,4 @@
1
- //#region src/internal/run-failed.ts
1
+ // src/internal/run-failed.ts
2
2
  const runFailedEventNames = [
3
3
  "invocation.failed",
4
4
  "schedule.failed",
@@ -51,5 +51,4 @@ async function emitRunFailed(event) {
51
51
  function hasRunFailedListeners() {
52
52
  return listeners().size > 0;
53
53
  }
54
- //#endregion
55
54
  export { emitRunFailed, hasRunFailedListeners, onRunFailed, runFailedEventNames, toRunFailedError };
@@ -1,4 +1,3 @@
1
- //#region src/internal/run-scope.d.ts
2
1
  /** Wraps one unit of work, such as a Schedule run or a Queue job. It calls `run` once and passes on its error. */
3
2
  export type RunScope = (run: () => Promise<void>) => Promise<unknown>;
4
3
  /**
@@ -7,5 +6,4 @@ export type RunScope = (run: () => Promise<void>) => Promise<unknown>;
7
6
  */
8
7
  export declare function registerRunScope(scope: RunScope): void;
9
8
  /** Runs one Schedule run or Queue job inside every registered scope. A Nitro request gets its scopes from middleware. */
10
- export declare function runInRunScopes<T>(run: () => T | Promise<T>): Promise<T>;
11
- //#endregion
9
+ export declare function runInRunScopes<T>(run: () => T | Promise<T>): Promise<T>;
@@ -1,4 +1,4 @@
1
- //#region src/internal/run-scope.ts
1
+ // src/internal/run-scope.ts
2
2
  const scopesKey = Symbol.for("vitehub.runtime.runScopes");
3
3
  function scopes() {
4
4
  const runtimeGlobal = globalThis;
@@ -26,5 +26,4 @@ async function runInRunScopes(run) {
26
26
  await next();
27
27
  return result;
28
28
  }
29
- //#endregion
30
29
  export { registerRunScope, runInRunScopes };
@@ -1,5 +1,4 @@
1
- import { t as runtimeErrorDiagnostics } from "../error-diagnostics-0sYgKTT8.js";
2
- //#region src/internal/runtime-type.d.ts
1
+ import { t as runtimeErrorDiagnostics } from "../error-diagnostics-DuusexaK.js";
3
2
  type RuntimeTypeMap = {
4
3
  bigint: bigint;
5
4
  boolean: boolean;
@@ -22,5 +21,4 @@ export declare function isRuntimeObject(value: unknown): value is object;
22
21
  * and a Response from another Fetch implementation all fail. A proxy fails too. The check reads no property of `value`.
23
22
  */
24
23
  export declare function isRuntimeResponse(value: unknown): value is Response;
25
- //#endregion
26
24
  export { runtimeErrorDiagnostics };
@@ -1,3 +1,3 @@
1
- import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
2
- import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-CHYQYwDx.js";
1
+ import { t as runtimeErrorDiagnostics } from "../error-diagnostics-Dj98U7ch.js";
2
+ import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-EgaBGoVU.js";
3
3
  export { asUnknownBoundary, hasRuntimeType, isRuntimeObject, isRuntimeResponse, runtimeErrorDiagnostics };
@@ -1,4 +1,3 @@
1
- //#region src/internal/shutdown.d.ts
2
1
  /**
3
2
  * Graceful shutdown that ViteHub owns.
4
3
  *
@@ -80,5 +79,4 @@ export declare function runShutdownDrains(app?: ShutdownApp, runtime?: ShutdownR
80
79
  * The drain runs when a server that owns stop signals gets SIGTERM or SIGINT, or when the
81
80
  * Nitro app closes. All drains share the budget in `VITEHUB_SHUTDOWN_DRAIN_MS`.
82
81
  */
83
- export declare function onShutdown(app: ShutdownApp, name: string, drain: ShutdownDrain, runtime?: ShutdownRuntime | undefined): void;
84
- //#endregion
82
+ export declare function onShutdown(app: ShutdownApp, name: string, drain: ShutdownDrain, runtime?: ShutdownRuntime | undefined): void;
@@ -1,4 +1,4 @@
1
- //#region src/internal/shutdown.ts
1
+ // src/internal/shutdown.ts
2
2
  /** Name of the variable that sets the shared drain budget in milliseconds. The default is 0. */
3
3
  const shutdownDrainEnv = "VITEHUB_SHUTDOWN_DRAIN_MS";
4
4
  const settleMs = 15e3;
@@ -196,5 +196,4 @@ function onShutdown(app, name, drain, runtime = currentProcess()) {
196
196
  else state.trap = "skipped";
197
197
  }
198
198
  }
199
- //#endregion
200
199
  export { onShutdown, runShutdownDrains, shutdownDrainEnv, shutdownState };
@@ -1,7 +1,5 @@
1
1
  import { ViteHubTestMode } from "./test-mode.js";
2
- //#region src/internal/test-mode-setup.d.ts
3
2
  /** Turns test mode on for this process, or returns the active one. */
4
3
  export declare function enableViteHubTestMode(options?: {
5
4
  root?: string;
6
- }): ViteHubTestMode;
7
- //#endregion
5
+ }): ViteHubTestMode;
@@ -1,5 +1,5 @@
1
1
  import { viteHubTestModeKey } from "./test-mode.js";
2
- //#region src/internal/test-mode-setup.ts
2
+ // src/internal/test-mode-setup.ts
3
3
  const processRoots = /* @__PURE__ */ new Map();
4
4
  function isRunning(pid) {
5
5
  try {
@@ -106,5 +106,4 @@ function enableViteHubTestMode(options = {}) {
106
106
  target[viteHubTestModeKey] = mode;
107
107
  return mode;
108
108
  }
109
- //#endregion
110
109
  export { enableViteHubTestMode };
@@ -1,4 +1,3 @@
1
- //#region src/internal/test-mode.d.ts
2
1
  /**
3
2
  * Test mode for app tests. `vite-hub/test` turns it on, and each Server Primitive then uses a local backend that lives
4
3
  * until the next reset, instead of its configured driver. The state is on `globalThis`, so every package copy in the
@@ -28,5 +27,4 @@ export type ViteHubTestModeGlobal = typeof globalThis & {
28
27
  [viteHubTestModeKey]?: ViteHubTestMode;
29
28
  };
30
29
  /** The active test mode, or `undefined` outside tests. */
31
- export declare function getViteHubTestMode(): ViteHubTestMode | undefined;
32
- //#endregion
30
+ export declare function getViteHubTestMode(): ViteHubTestMode | undefined;
@@ -1,9 +1,8 @@
1
- //#region src/internal/test-mode.ts
1
+ // src/internal/test-mode.ts
2
2
  /** The `globalThis` key of the active test mode. */
3
3
  const viteHubTestModeKey = Symbol.for("vitehub.test");
4
4
  /** The active test mode, or `undefined` outside tests. */
5
5
  function getViteHubTestMode() {
6
6
  return globalThis[viteHubTestModeKey];
7
7
  }
8
- //#endregion
9
8
  export { getViteHubTestMode, viteHubTestModeKey };
@@ -1,6 +1,4 @@
1
- import { $ as emitTraceEvent, ct as traceEventsToOpenTelemetryLogRecords, lt as traceEventsToOpenTelemetrySpans } from "../core-BfUEli_0.js";
2
- import "../index-DsisbCNa.js";
3
- //#region src/internal/trace-attributes.d.ts
1
+ import { $ as emitTraceEvent, ct as traceEventsToOpenTelemetryLogRecords, lt as traceEventsToOpenTelemetrySpans } from "../core-auTkK4iZ.js";
2
+ import "../index-fSQ1ELEy.js";
4
3
  export declare function isTraceContentAttributeKey(key: string): boolean;
5
- //#endregion
6
4
  export { emitTraceEvent, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans };
@@ -1,2 +1 @@
1
- import { _ as traceEventsToOpenTelemetrySpans, g as traceEventsToOpenTelemetryLogRecords, s as emitTraceEvent, y as isTraceContentAttributeKey } from "../core-DpLK9dQt.js";
2
- export { emitTraceEvent, isTraceContentAttributeKey, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans };
1
+ export { s as emitTraceEvent, y as isTraceContentAttributeKey, g as traceEventsToOpenTelemetryLogRecords, _ as traceEventsToOpenTelemetrySpans } from "../core-Crv8CV_r.js";
@@ -1,6 +1,4 @@
1
1
  import { StandardSchemaV1 } from "@standard-schema/spec";
2
- //#region ../internal/dist/operation-definition-C0NDEa7Q.d.ts
3
- //#region src/operation-definition.d.ts
4
2
  /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
5
3
  type OperationKind = "read" | "write" | "destructive";
6
4
  /** The signed-in user of a call. */
@@ -174,5 +172,4 @@ interface OperationContributingPlugin {
174
172
  operations?: OperationContributions;
175
173
  };
176
174
  }
177
- //#endregion
178
175
  export { type OperationAccess, type OperationActor, type OperationContext, type OperationContributingPlugin, type OperationContributionEntry, type OperationContributions, type OperationDefinition, type OperationFailure, type OperationKind, type OperationResult, type OperationUser, defineOperation };
@@ -1,6 +1,6 @@
1
1
  import { defineDiagnostics } from "nostics";
2
2
  import { toJsonSchema } from "@valibot/to-json-schema";
3
- //#region ../internal/dist/error-diagnostics-B11Jh1zF.js
3
+ // ../internal/dist/error-diagnostics-B5oT1e3D.js
4
4
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
5
5
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
6
6
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -257,6 +257,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
257
257
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
258
258
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
259
259
  },
260
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
261
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
262
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
263
+ },
260
264
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
261
265
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
262
266
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -271,14 +275,12 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
271
275
  }
272
276
  }
273
277
  });
274
- //#endregion
275
- //#region ../internal/dist/object.js
278
+ // ../internal/dist/object.js
276
279
  /** A non-null object or a function that is not an array. */
277
280
  function isRecordOrFunction(value) {
278
281
  return Object(value) === value && !Array.isArray(value);
279
282
  }
280
- //#endregion
281
- //#region ../internal/dist/standard-schema.js
283
+ // ../internal/dist/standard-schema.js
282
284
  function readOwn(value, key) {
283
285
  if (value === null || Object(value) !== value) return;
284
286
  try {
@@ -307,8 +309,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
307
309
  return;
308
310
  }
309
311
  }
310
- //#endregion
311
- //#region ../internal/dist/valibot.js
312
+ // ../internal/dist/valibot.js
312
313
  const valibotTargets = /* @__PURE__ */ new Set([
313
314
  "draft-07",
314
315
  "draft-2020-12",
@@ -349,8 +350,7 @@ function withValibotJsonSchema(schema, options = {}) {
349
350
  }
350
351
  };
351
352
  }
352
- //#endregion
353
- //#region ../internal/dist/operation-definition.js
353
+ // ../internal/dist/operation-definition.js
354
354
  const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
355
355
  const kinds = /* @__PURE__ */ new Set([
356
356
  "read",
@@ -410,5 +410,4 @@ function isSectionId(section) {
410
410
  function operationInputJsonSchema(operation) {
411
411
  return standardJsonSchema(operation.input, "input") ?? { type: "object" };
412
412
  }
413
- //#endregion
414
413
  export { defineOperation };
@@ -1,4 +1,3 @@
1
- //#region src/public-url.d.ts
2
1
  /** Public origins resolved from `vitehub({ publicUrl })` at build time. */
3
2
  interface PublicUrlConfig {
4
3
  /** One origin for the whole deployment. */
@@ -33,7 +32,7 @@ declare function resolvePublicUrl(options?: {
33
32
  * Build the hosted Console URL that opens one Agent invocation, such as
34
33
  * `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fagents%2Fbot%2Finvocations%2Fid`.
35
34
  * `origin` must not include the application base path. The hosted Console checks the project URL when it opens the link.
35
+ * A self-hosted Console of `vitehub({ console: { url } })` replaces the hosted origin.
36
36
  */
37
37
  declare function consoleInvocationUrl(origin: string, agentName: string, invocationId: string): string;
38
- //#endregion
39
38
  export { resetPublicUrlAgentNames as a, registerPublicUrlAgentName as i, configuredPublicOrigins as n, resolvePublicUrl as o, consoleInvocationUrl as r, PublicUrlConfig as t };
@@ -1,75 +1,14 @@
1
- import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
2
- //#region src/hosted-console.ts
1
+ // src/hosted-console-origin.ts
3
2
  /** The origin of the hosted Console. */
4
3
  const hostedConsoleOrigin = "https://console.vitehub.dev";
5
- const loopbackHosts = /* @__PURE__ */ new Set([
6
- "localhost",
7
- "127.0.0.1",
8
- "[::1]"
9
- ]);
10
- const pathBase = "https://console.invalid";
11
4
  /**
12
- * The Console path of a link, such as `/agents/bot/invocations/abc?tab=trace`, or `undefined` when the value is not a
13
- * Console path. A Console path starts with one `/`. Absolute URLs, protocol-relative URLs, and backslashes are not
14
- * Console paths, so a link cannot send the browser to another site. A path that starts with `/_vitehub`, as on a
15
- * Console that the app serves, loses that prefix.
5
+ * The origin of the ViteHub Console that opens this app: `vitehub({ console: { url } })` of a self-hosted Console, else
6
+ * the hosted Console.
16
7
  */
17
- function normalizeConsolePath(path) {
18
- if (!path.startsWith("/") || path.startsWith("//") || path.includes("\\")) return void 0;
19
- let url;
20
- try {
21
- url = new URL(path, pathBase);
22
- } catch {
23
- return;
24
- }
25
- if (url.origin !== pathBase) return void 0;
26
- const pathname = url.pathname.replace(/^\/_vitehub(?=\/|$)/, "") || "/";
27
- if (pathname.startsWith("//")) return void 0;
28
- return `${pathname}${url.search}${url.hash}`;
8
+ function configuredConsoleOrigin() {
9
+ return typeof __VITEHUB_CONSOLE_URL__ === "string" ? __VITEHUB_CONSOLE_URL__ : hostedConsoleOrigin;
29
10
  }
30
- /**
31
- * The project URL of a link: the app origin and its application mount, such as `https://app.example.com/portal`, or
32
- * `undefined` when the URL cannot be a project. A project URL is `https:`, or `http:` on a loopback host, and has no
33
- * user name or password.
34
- */
35
- function normalizeConsoleProjectUrl(projectUrl) {
36
- let url;
37
- try {
38
- url = new URL(projectUrl);
39
- } catch {
40
- return;
41
- }
42
- if (url.username || url.password) return void 0;
43
- if (url.protocol !== "https:" && !(url.protocol === "http:" && loopbackHosts.has(url.hostname))) return void 0;
44
- const mount = url.pathname.search(/\/_vitehub(?=\/|$)/);
45
- const base = (mount === -1 ? url.pathname : url.pathname.slice(0, mount)).replace(/\/+$/, "");
46
- return `${url.origin}${base}`;
47
- }
48
- /**
49
- * The hosted Console URL that opens one page of a project, such as
50
- * `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fkv`.
51
- *
52
- * `projectUrl` is the app origin with its application mount, such as `https://app.example.com/portal`. `path` is the
53
- * Console path, such as `/agents/bot/invocations/abc`. The hosted Console switches to the project when this browser
54
- * linked it, or asks the person to link it first. The URL holds no secret.
55
- *
56
- * Throws `RUNTIME_CONSOLE_PROJECT_URL_INVALID` when `projectUrl` is not `https:` (or `http:` on a loopback host), and
57
- * `RUNTIME_CONSOLE_PATH_INVALID` when `path` is not a Console path.
58
- */
59
- function hostedConsoleUrl(projectUrl, path, consoleOrigin = hostedConsoleOrigin) {
60
- const project = normalizeConsoleProjectUrl(projectUrl);
61
- if (!project) throw runtimeErrorDiagnostics.RUNTIME_CONSOLE_PROJECT_URL_INVALID({ value: projectUrl });
62
- const consolePath = normalizeConsolePath(path);
63
- if (!consolePath) throw runtimeErrorDiagnostics.RUNTIME_CONSOLE_PATH_INVALID({ value: path });
64
- const url = new URL("/open", consoleOrigin);
65
- url.search = new URLSearchParams({
66
- project,
67
- path: consolePath
68
- }).toString();
69
- return url.href;
70
- }
71
- //#endregion
72
- //#region src/route-segment.ts
11
+ // src/route-segment.ts
73
12
  const plainSegment = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
74
13
  function encodeRouteSegment(value) {
75
14
  if (plainSegment.test(value)) return value;
@@ -84,8 +23,7 @@ function decodeRouteSegment(segment) {
84
23
  for (let index = 1; index < segment.length; index += 4) value += String.fromCharCode(Number.parseInt(segment.slice(index, index + 4), 16));
85
24
  return encodeRouteSegment(value) === segment ? value : void 0;
86
25
  }
87
- //#endregion
88
- //#region src/public-url.ts
26
+ // src/public-url.ts
89
27
  const publicUrlAgentNames = /* @__PURE__ */ new Map();
90
28
  /** Replace aliases when a generated Agent registry is installed. */
91
29
  function resetPublicUrlAgentNames() {
@@ -138,11 +76,11 @@ function resolvePublicUrl(options = {}) {
138
76
  * Build the hosted Console URL that opens one Agent invocation, such as
139
77
  * `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fagents%2Fbot%2Finvocations%2Fid`.
140
78
  * `origin` must not include the application base path. The hosted Console checks the project URL when it opens the link.
79
+ * A self-hosted Console of `vitehub({ console: { url } })` replaces the hosted origin.
141
80
  */
142
81
  function consoleInvocationUrl(origin, agentName, invocationId) {
143
82
  const project = `${new URL(origin).origin}${applicationBasePath()}`;
144
83
  const path = `/agents/${encodeRouteSegment(agentName)}/invocations/${encodeURIComponent(invocationId)}`;
145
- return `${hostedConsoleOrigin}/open?project=${encodeURIComponent(project)}&path=${encodeURIComponent(path)}`;
84
+ return `${configuredConsoleOrigin()}/open?project=${encodeURIComponent(project)}&path=${encodeURIComponent(path)}`;
146
85
  }
147
- //#endregion
148
- export { resolvePublicUrl as a, hostedConsoleOrigin as c, normalizeConsoleProjectUrl as d, resetPublicUrlAgentNames as i, hostedConsoleUrl as l, consoleInvocationUrl as n, decodeRouteSegment as o, registerPublicUrlAgentName as r, encodeRouteSegment as s, configuredPublicOrigins as t, normalizeConsolePath as u };
86
+ export { resolvePublicUrl as a, configuredConsoleOrigin as c, resetPublicUrlAgentNames as i, hostedConsoleOrigin as l, consoleInvocationUrl as n, decodeRouteSegment as o, registerPublicUrlAgentName as r, encodeRouteSegment as s, configuredPublicOrigins as t };
@@ -1,8 +1,8 @@
1
- import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
2
- import { n as createRuntimeContext } from "./core-DpLK9dQt.js";
3
- import { s as isRuntimeDiagnostic } from "./response-Be5M4WIn.js";
1
+ import { t as runtimeErrorDiagnostics } from "./error-diagnostics-Dj98U7ch.js";
2
+ import { n as createRuntimeContext } from "./core-Crv8CV_r.js";
3
+ import { s as isRuntimeDiagnostic } from "./response-DEyMvEBF.js";
4
4
  import { Diagnostic, defineDiagnostics } from "nostics";
5
- //#region ../internal/dist/runtime/cloudflare-env-lookup.js
5
+ // ../internal/dist/runtime/cloudflare-env-lookup.js
6
6
  /** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
7
7
  const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
8
8
  let activeEnv;
@@ -39,8 +39,7 @@ function getCloudflareEnv(event, options = {}) {
39
39
  for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
40
40
  return options.fallback === false ? void 0 : getActiveCloudflareEnv();
41
41
  }
42
- //#endregion
43
- //#region src/instance.ts
42
+ // src/instance.ts
44
43
  /** The environment variable that names this server instance. */
45
44
  const instanceIdEnv = "VITEHUB_INSTANCE_ID";
46
45
  const generatedKey = Symbol.for("vitehub.runtime.instance-id");
@@ -68,8 +67,7 @@ function getInstanceId() {
68
67
  const state = globalThis;
69
68
  return state[generatedKey] ??= generatedInstanceId();
70
69
  }
71
- //#endregion
72
- //#region src/result.ts
70
+ // src/result.ts
73
71
  const resultErrorBrand = Symbol.for("vitehub.runtime.resultError");
74
72
  /**
75
73
  * Prepares a recognized diagnostic for a result, keeping its metadata in memory.
@@ -139,8 +137,7 @@ function defineErrors(options) {
139
137
  }
140
138
  return catalog;
141
139
  }
142
- //#endregion
143
- //#region src/lease.ts
140
+ // src/lease.ts
144
141
  const leaseErrorDiagnostics = /*#__PURE__*/ defineErrors({
145
142
  docs: "https://vitehub.dev/docs/runtime/diagnostics",
146
143
  codes: {
@@ -366,8 +363,7 @@ function createSqlLeaseStore(client) {
366
363
  }
367
364
  });
368
365
  }
369
- //#endregion
370
- //#region src/duration.ts
366
+ // src/duration.ts
371
367
  const second = 1e3;
372
368
  const minute = 60 * second;
373
369
  const hour = 60 * minute;
@@ -454,44 +450,7 @@ function parseDuration(value, option, round, legacyUnit = "ms") {
454
450
  unit: legacyUnitName
455
451
  });
456
452
  }
457
- /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
458
- function hostFromNitroPreset(value) {
459
- const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
460
- if (!normalized) return;
461
- if (normalized.startsWith("cloudflare")) return "cloudflare";
462
- if (normalized.startsWith("deno")) return "deno";
463
- if (normalized.startsWith("netlify")) return "netlify";
464
- if (normalized === "node" || normalized.startsWith("node-")) return "node";
465
- if (normalized.startsWith("vercel")) return "vercel";
466
- }
467
- const providerHosts = [
468
- ["WORKERS_CI", "cloudflare"],
469
- ["NETLIFY", "netlify"],
470
- ["NOW_BUILDER", "vercel"],
471
- ["VERCEL", "vercel"],
472
- ["VERCEL_ENV", "vercel"],
473
- ["DENO_DEPLOY", "deno"],
474
- ["DENO_DEPLOYMENT_ID", "deno"]
475
- ];
476
- /**
477
- * Returns the ViteHub host that this process builds or runs on, or `undefined` when no variable names a host.
478
- * The order is `VITEHUB_HOST`, `NITRO_PRESET`, `SERVER_PRESET`, then the provider variables:
479
- * `WORKERS_CI` (Cloudflare Workers Builds), `NETLIFY`, `NOW_BUILDER`, `VERCEL` or `VERCEL_ENV`, then `DENO_DEPLOY` or `DENO_DEPLOYMENT_ID`.
480
- * `vitehub()` uses this result when `host` is omitted, and `"node"` when it is `undefined`.
481
- */
482
- function detectHost$1(env = process.env) {
483
- for (const name of [
484
- "VITEHUB_HOST",
485
- "NITRO_PRESET",
486
- "SERVER_PRESET"
487
- ]) {
488
- const host = hostFromNitroPreset(env[name]);
489
- if (host) return host;
490
- }
491
- return providerHosts.find(([name]) => env[name]?.trim())?.[1];
492
- }
493
- //#endregion
494
- //#region src/host.ts
453
+ // src/host.ts
495
454
  const hostBindingErrors = /*#__PURE__*/ defineErrors({
496
455
  docs: "https://vitehub.dev/docs/runtime/diagnostics",
497
456
  codes: {
@@ -505,25 +464,6 @@ const hostBindingErrors = /*#__PURE__*/ defineErrors({
505
464
  }
506
465
  }
507
466
  });
508
- /**
509
- * Returns the host that this code builds or runs on, or `undefined` when nothing names one.
510
- * It reads `VITEHUB_HOST`, `NITRO_PRESET`, `SERVER_PRESET`, then the build variables of Cloudflare Workers Builds
511
- * (`WORKERS_CI`), Netlify, Vercel, and Deno Deploy. Inside a Cloudflare Worker, it returns `"cloudflare"`.
512
- * `vitehub()` uses the same detection when `host` is omitted.
513
- *
514
- * @example
515
- * ```ts
516
- * import { detectHost } from "vite-hub/runtime"
517
- *
518
- * const host = detectHost() ?? "node"
519
- * ```
520
- */
521
- function detectHost(env = processEnv()) {
522
- return detectHost$1(env) ?? (globalThis.navigator?.userAgent === "Cloudflare-Workers" ? "cloudflare" : void 0);
523
- }
524
- function processEnv() {
525
- return globalThis.process?.env ?? {};
526
- }
527
467
  function getHostBinding(name, event) {
528
468
  const env = (event && hostBindingsOf(event)) ?? getActiveCloudflareEnv();
529
469
  if (!env) return [hostBindingErrors.RUNTIME_HOST_BINDINGS_UNAVAILABLE({ name }), void 0];
@@ -534,8 +474,7 @@ function getHostBinding(name, event) {
534
474
  function hostBindingsOf(event) {
535
475
  return event["~standard"]?.runtime?.cloudflare?.env ?? getCloudflareEnv(event, { fallback: false });
536
476
  }
537
- //#endregion
538
- //#region src/request-context.ts
477
+ // src/request-context.ts
539
478
  function isObjectLike(value) {
540
479
  return value !== null && (typeof value === "object" || typeof value === "function");
541
480
  }
@@ -683,5 +622,4 @@ function createStandardRuntimeContext(event, standard, options) {
683
622
  function getRuntimeContext(value, options = {}) {
684
623
  return createStandardRuntimeContext(value, getStandardContext(value), options);
685
624
  }
686
- //#endregion
687
- export { ownValue as S, instanceIdEnv as _, installRequestStandardContext as a, getCloudflareEnv as b, sendPreparedResponse as c, parseDuration as d, createMemoryLeaseStore as f, getInstanceId as g, toResultError as h, getStandardContext as i, detectHost as l, defineErrors as m, firstAddress as n, isHostRequest as o, createSqlLeaseStore as p, getRuntimeContext as r, requestAddressPaths as s, createStandardRuntimeContext as t, getHostBinding as u, activeEnvStorageKey as v, ownObject as x, cloudflareOwners as y };
625
+ export { activeEnvStorageKey as _, installRequestStandardContext as a, ownObject as b, sendPreparedResponse as c, createMemoryLeaseStore as d, createSqlLeaseStore as f, instanceIdEnv as g, getInstanceId as h, getStandardContext as i, getHostBinding as l, toResultError as m, firstAddress as n, isHostRequest as o, defineErrors as p, getRuntimeContext as r, requestAddressPaths as s, createStandardRuntimeContext as t, parseDuration as u, cloudflareOwners as v, ownValue as x, getCloudflareEnv as y };
@@ -1,4 +1,3 @@
1
- //#region src/response.d.ts
2
1
  /** A JSON-safe representation of a web Response for durable boundaries. */
3
2
  interface SerializedResponse {
4
3
  readonly body: {
@@ -29,5 +28,4 @@ declare function serializeResponse(response: Response): Promise<SerializedRespon
29
28
  /** Reconstruct a native Response from a durable response record. */
30
29
  declare function deserializeResponse(value: SerializedResponse): Response;
31
30
  declare function isSerializedResponse(value: unknown): value is SerializedResponse;
32
- //#endregion
33
31
  export { serializeResponse as a, isSerializedResponse as i, deserializeResponse as n, toResponse as o, isResponse as r, SerializedResponse as t };