@frontmcp/utils 1.8.6 → 1.9.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 (39) hide show
  1. package/env/browser-env.d.ts +1 -0
  2. package/env/browser-env.js +5 -0
  3. package/env/browser-runtime-context.d.ts +2 -1
  4. package/env/browser-runtime-context.js +104 -0
  5. package/env/index.d.ts +1 -1
  6. package/env/node-env.d.ts +11 -0
  7. package/env/node-env.js +8 -2
  8. package/env/runtime-context.d.ts +12 -5
  9. package/env/runtime-context.js +192 -0
  10. package/esm/async-context/browser-async-context.mjs +3 -2
  11. package/esm/async-context/node-async-context.mjs +3 -2
  12. package/esm/crypto/browser.mjs +3 -2
  13. package/esm/crypto/node.mjs +3 -2
  14. package/esm/env/browser-env.mjs +7 -2
  15. package/esm/env/browser-runtime-context.mjs +77 -0
  16. package/esm/env/node-env.mjs +10 -4
  17. package/esm/env/runtime-context.mjs +172 -0
  18. package/esm/event-emitter/browser-event-emitter.mjs +3 -2
  19. package/esm/event-emitter/node-event-emitter.mjs +3 -2
  20. package/esm/index.mjs +251 -250
  21. package/esm/path/browser-path.mjs +50 -0
  22. package/esm/path/node-path.mjs +16 -0
  23. package/index.d.ts +3 -3
  24. package/index.js +261 -274
  25. package/package.json +26 -8
  26. package/path/browser-path.js +79 -0
  27. package/path/node-path.js +45 -0
  28. package/storage/adapters/base.d.ts +6 -1
  29. package/storage/adapters/cloudflare-kv.d.ts +1 -0
  30. package/storage/adapters/index.d.ts +2 -1
  31. package/storage/adapters/memory.d.ts +2 -1
  32. package/storage/adapters/redis.d.ts +19 -0
  33. package/storage/adapters/upstash.d.ts +2 -1
  34. package/storage/adapters/vercel-kv.d.ts +2 -1
  35. package/storage/index.d.ts +4 -2
  36. package/storage/namespace.d.ts +2 -1
  37. package/storage/redis-error-listener.d.ts +27 -0
  38. package/storage/types.d.ts +11 -0
  39. package/storage/utils/compare-and-delete.d.ts +2 -0
@@ -7,6 +7,7 @@
7
7
  export declare function getEnv(_key: string): string | undefined;
8
8
  export declare function getEnv(_key: string, defaultValue: string): string;
9
9
  export declare function getCwd(): string;
10
+ export declare function getNodeEnv(): string | undefined;
10
11
  export declare function isProduction(): boolean;
11
12
  export declare function isDevelopment(): boolean;
12
13
  export declare function getEnvFlag(_key: string): boolean;
@@ -23,6 +23,7 @@ __export(browser_env_exports, {
23
23
  getCwd: () => getCwd,
24
24
  getEnv: () => getEnv,
25
25
  getEnvFlag: () => getEnvFlag,
26
+ getNodeEnv: () => getNodeEnv,
26
27
  isDebug: () => isDebug,
27
28
  isDevelopment: () => isDevelopment,
28
29
  isEdgeRuntime: () => isEdgeRuntime,
@@ -55,6 +56,9 @@ function getEnv(_key, defaultValue) {
55
56
  function getCwd() {
56
57
  return "/";
57
58
  }
59
+ function getNodeEnv() {
60
+ return void 0;
61
+ }
58
62
  function isProduction() {
59
63
  return false;
60
64
  }
@@ -83,6 +87,7 @@ function supportsAnsi() {
83
87
  getCwd,
84
88
  getEnv,
85
89
  getEnvFlag,
90
+ getNodeEnv,
86
91
  isDebug,
87
92
  isDevelopment,
88
93
  isEdgeRuntime,
@@ -18,7 +18,7 @@ export interface RuntimeContext {
18
18
  target: string;
19
19
  env: string;
20
20
  }
21
- export type Surface = 'mcp' | 'cli' | 'http-trigger' | 'job' | 'agent';
21
+ export type Surface = 'mcp' | 'cli' | 'http-trigger' | 'job' | 'agent' | 'webmcp';
22
22
  export interface CallContext {
23
23
  surface?: Surface;
24
24
  }
@@ -47,6 +47,7 @@ export declare const entryAvailabilitySchema: import("@frontmcp/lazy-zod").ZodOb
47
47
  "http-trigger": "http-trigger";
48
48
  job: "job";
49
49
  agent: "agent";
50
+ webmcp: "webmcp";
50
51
  }>>>;
51
52
  env: import("@frontmcp/lazy-zod").ZodOptional<import("@frontmcp/lazy-zod").ZodArray<import("@frontmcp/lazy-zod").ZodString>>;
52
53
  }, import("zod/v4/core").$strict>;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // libs/utils/src/env/browser-runtime-context.ts
21
+ var browser_runtime_context_exports = {};
22
+ __export(browser_runtime_context_exports, {
23
+ checkEntryAvailability: () => checkEntryAvailability,
24
+ detectRuntimeContext: () => detectRuntimeContext,
25
+ entryAvailabilitySchema: () => entryAvailabilitySchema,
26
+ getRuntimeContext: () => getRuntimeContext,
27
+ isEntryAvailable: () => isEntryAvailable,
28
+ resetRuntimeContext: () => resetRuntimeContext
29
+ });
30
+ module.exports = __toCommonJS(browser_runtime_context_exports);
31
+ var import_lazy_zod = require("@frontmcp/lazy-zod");
32
+ var entryAvailabilitySchema = import_lazy_zod.z.object({
33
+ os: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
34
+ platform: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
35
+ runtime: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
36
+ deployment: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
37
+ provider: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
38
+ target: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
39
+ surface: import_lazy_zod.z.array(import_lazy_zod.z.enum(["mcp", "cli", "http-trigger", "job", "agent", "webmcp"])).optional(),
40
+ env: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional()
41
+ }).strict();
42
+ var PROCESS_AXES = [
43
+ { key: "os", ctxKey: "os" },
44
+ { key: "platform", ctxKey: "platform" },
45
+ { key: "runtime", ctxKey: "runtime" },
46
+ { key: "deployment", ctxKey: "deployment" },
47
+ { key: "provider", ctxKey: "provider" },
48
+ { key: "target", ctxKey: "target" },
49
+ { key: "env", ctxKey: "env" }
50
+ ];
51
+ function isEntryAvailable(availability, ctx, callCtx) {
52
+ if (!availability) return true;
53
+ for (const { key, ctxKey } of PROCESS_AXES) {
54
+ const allowed = availability[key];
55
+ if (allowed === void 0) continue;
56
+ if (allowed.length === 0) return false;
57
+ if (!allowed.includes(ctx[ctxKey])) return false;
58
+ }
59
+ if (availability.surface !== void 0) {
60
+ if (availability.surface.length === 0) return false;
61
+ if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) return false;
62
+ }
63
+ return true;
64
+ }
65
+ function checkEntryAvailability(availability, ctx, callCtx) {
66
+ if (!availability) return { available: true, missingAxes: [] };
67
+ const missing = [];
68
+ for (const { key, ctxKey } of PROCESS_AXES) {
69
+ const allowed = availability[key];
70
+ if (allowed === void 0) continue;
71
+ if (allowed.length === 0 || !allowed.includes(ctx[ctxKey])) missing.push(key);
72
+ }
73
+ if (availability.surface !== void 0) {
74
+ if (availability.surface.length === 0) missing.push("surface");
75
+ else if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) missing.push("surface");
76
+ }
77
+ return { available: missing.length === 0, missingAxes: missing };
78
+ }
79
+ function detectRuntimeContext() {
80
+ return {
81
+ os: "browser",
82
+ platform: "browser",
83
+ runtime: "browser",
84
+ deployment: "standalone",
85
+ provider: "bare",
86
+ target: "browser",
87
+ env: "production"
88
+ };
89
+ }
90
+ var browserContext = detectRuntimeContext();
91
+ function getRuntimeContext() {
92
+ return browserContext;
93
+ }
94
+ function resetRuntimeContext() {
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ checkEntryAvailability,
99
+ detectRuntimeContext,
100
+ entryAvailabilitySchema,
101
+ getRuntimeContext,
102
+ isEntryAvailable,
103
+ resetRuntimeContext
104
+ });
package/env/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { getEnv, getCwd, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, } from '#env';
1
+ export { getEnv, getCwd, getNodeEnv, isProduction, isDevelopment, getEnvFlag, isDebug, setEnv, isEdgeRuntime, isServerless, supportsAnsi, } from '#env';
2
2
  export { getRuntimeContext, resetRuntimeContext, detectRuntimeContext, isEntryAvailable, checkEntryAvailability, entryAvailabilitySchema, } from '#runtime-context';
3
3
  export type { RuntimeContext, EntryAvailability, Surface, CallContext } from '#runtime-context';
4
4
  export { detectProvider, resetProviderCacheForTesting } from './provider';
package/env/node-env.d.ts CHANGED
@@ -4,6 +4,17 @@
4
4
  export declare function getEnv(key: string): string | undefined;
5
5
  export declare function getEnv(key: string, defaultValue: string): string;
6
6
  export declare function getCwd(): string;
7
+ /**
8
+ * The NODE_ENV this process runs with.
9
+ *
10
+ * Bundlers replace `process.env.NODE_ENV` with a literal when they build —
11
+ * `wrangler dev` with `"development"`, `wrangler deploy` with `"production"` —
12
+ * so a value the deployment sets at run time (a Cloudflare Worker's
13
+ * `[vars] NODE_ENV`) was never seen (#680). The live value is read first,
14
+ * through a key no bundler folds; the build-time value only fills in when the
15
+ * runtime sets none.
16
+ */
17
+ export declare function getNodeEnv(): string | undefined;
7
18
  export declare function isProduction(): boolean;
8
19
  export declare function isDevelopment(): boolean;
9
20
  export declare function getEnvFlag(key: string): boolean;
package/env/node-env.js CHANGED
@@ -23,6 +23,7 @@ __export(node_env_exports, {
23
23
  getCwd: () => getCwd,
24
24
  getEnv: () => getEnv,
25
25
  getEnvFlag: () => getEnvFlag,
26
+ getNodeEnv: () => getNodeEnv,
26
27
  isDebug: () => isDebug,
27
28
  isDevelopment: () => isDevelopment,
28
29
  isEdgeRuntime: () => isEdgeRuntime,
@@ -55,11 +56,15 @@ function getEnv(key, defaultValue) {
55
56
  function getCwd() {
56
57
  return process.cwd();
57
58
  }
59
+ var NODE_ENV_KEY = "NODE_ENV";
60
+ function getNodeEnv() {
61
+ return process.env[NODE_ENV_KEY] || process.env["NODE_ENV"] || void 0;
62
+ }
58
63
  function isProduction() {
59
- return process.env["NODE_ENV"] === "production";
64
+ return getNodeEnv() === "production";
60
65
  }
61
66
  function isDevelopment() {
62
- return process.env["NODE_ENV"] === "development";
67
+ return getNodeEnv() === "development";
63
68
  }
64
69
  function getEnvFlag(key) {
65
70
  const v = process.env[key];
@@ -91,6 +96,7 @@ function supportsAnsi() {
91
96
  getCwd,
92
97
  getEnv,
93
98
  getEnvFlag,
99
+ getNodeEnv,
94
100
  isDebug,
95
101
  isDevelopment,
96
102
  isEdgeRuntime,
@@ -12,11 +12,11 @@
12
12
  * - `os` as the new name for `platform` (alias preserved for back-compat)
13
13
  * - `provider` (vercel / lambda / cloudflare / netlify / docker / bare / …)
14
14
  * - `target` (the build output produced by `frontmcp build --target <x>`)
15
- * - `surface` (per-call axis: mcp / cli / agent / job / http-trigger)
15
+ * - `surface` (per-call axis: mcp / cli / agent / job / http-trigger / webmcp)
16
16
  */
17
17
  /**
18
18
  * Snapshot of the current runtime environment. Detected once and cached
19
- * for the lifetime of the process.
19
+ * for the lifetime of the process (`env` is read live from `NODE_ENV`).
20
20
  */
21
21
  export interface RuntimeContext {
22
22
  /** OS platform: 'darwin', 'linux', 'win32', etc. (issue #417: renamed from platform) */
@@ -39,7 +39,7 @@ export interface RuntimeContext {
39
39
  * Set by transport adapters / agent dispatchers / job runners on the
40
40
  * outgoing `ctx` so registry filtering can fork on call origin.
41
41
  */
42
- export type Surface = 'mcp' | 'cli' | 'http-trigger' | 'job' | 'agent';
42
+ export type Surface = 'mcp' | 'cli' | 'http-trigger' | 'job' | 'agent' | 'webmcp';
43
43
  /** Call-context wrapper threaded through `findTool` for per-call filtering. */
44
44
  export interface CallContext {
45
45
  surface?: Surface;
@@ -82,7 +82,7 @@ export interface EntryAvailability {
82
82
  provider?: string[];
83
83
  /** Build-target constraint (issue #417). */
84
84
  target?: string[];
85
- /** Surface constraint (issue #417): 'mcp', 'cli', 'agent', 'job', 'http-trigger'. */
85
+ /** Surface constraint (issue #417): 'mcp', 'cli', 'agent', 'job', 'http-trigger', 'webmcp'. */
86
86
  surface?: Surface[];
87
87
  /** Environment constraint: 'production', 'development', 'test', etc. */
88
88
  env?: string[];
@@ -103,6 +103,7 @@ export declare const entryAvailabilitySchema: import("@frontmcp/lazy-zod").ZodOb
103
103
  "http-trigger": "http-trigger";
104
104
  job: "job";
105
105
  agent: "agent";
106
+ webmcp: "webmcp";
106
107
  }>>>;
107
108
  env: import("@frontmcp/lazy-zod").ZodOptional<import("@frontmcp/lazy-zod").ZodArray<import("@frontmcp/lazy-zod").ZodString>>;
108
109
  }, import("zod/v4/core").$strict>;
@@ -134,7 +135,13 @@ export declare function checkEntryAvailability(availability: EntryAvailability |
134
135
  export declare function detectRuntimeContext(): RuntimeContext;
135
136
  /**
136
137
  * Get the current runtime context (lazy singleton).
137
- * The context is detected on first call and cached for the process lifetime.
138
+ * The context is detected on first call and cached for the process lifetime,
139
+ * except `env`, which always reflects the live `NODE_ENV`. A Cloudflare Worker's
140
+ * `[vars]` reach `process.env` on the first request, after module evaluation has
141
+ * already read this context, so a frozen `env` would report `development` in a
142
+ * production deployment. It is read through `getNodeEnv()`, so a bundler's
143
+ * build-time `process.env.NODE_ENV` (`wrangler dev` inlines `development`) does
144
+ * not hide the value the deployment sets.
138
145
  */
139
146
  export declare function getRuntimeContext(): RuntimeContext;
140
147
  /**
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // libs/utils/src/env/runtime-context.ts
21
+ var runtime_context_exports = {};
22
+ __export(runtime_context_exports, {
23
+ checkEntryAvailability: () => checkEntryAvailability,
24
+ detectRuntimeContext: () => detectRuntimeContext,
25
+ entryAvailabilitySchema: () => entryAvailabilitySchema,
26
+ getRuntimeContext: () => getRuntimeContext,
27
+ isEntryAvailable: () => isEntryAvailable,
28
+ resetRuntimeContext: () => resetRuntimeContext
29
+ });
30
+ module.exports = __toCommonJS(runtime_context_exports);
31
+ var import_lazy_zod = require("@frontmcp/lazy-zod");
32
+ var import_env = require("#env");
33
+
34
+ // libs/utils/src/env/build-target.ts
35
+ var cached;
36
+ function getBuildTarget() {
37
+ if (cached) return cached;
38
+ cached = resolveBuildTarget();
39
+ return cached;
40
+ }
41
+ function resolveBuildTarget() {
42
+ const globalAny = globalThis;
43
+ const fromGlobal = globalAny.FRONTMCP_BUILD_TARGET;
44
+ if (typeof fromGlobal === "string" && isKnownTarget(fromGlobal)) return fromGlobal;
45
+ const fromEnv = typeof process !== "undefined" ? process.env?.["FRONTMCP_BUILD_TARGET"] : void 0;
46
+ if (typeof fromEnv === "string" && isKnownTarget(fromEnv)) return fromEnv;
47
+ return "unknown";
48
+ }
49
+ function isKnownTarget(value) {
50
+ return value === "unknown" || value === "node" || value === "distributed" || value === "cli" || value === "vercel" || value === "lambda" || value === "cloudflare" || value === "browser" || value === "sdk" || value === "mcpb";
51
+ }
52
+
53
+ // libs/utils/src/env/provider.ts
54
+ var cached2;
55
+ function detectProvider() {
56
+ if (cached2) return cached2;
57
+ cached2 = detectProviderUncached();
58
+ return cached2;
59
+ }
60
+ function detectProviderUncached() {
61
+ const explicit = process.env["FRONTMCP_PROVIDER"];
62
+ if (explicit && isKnownProvider(explicit)) return explicit;
63
+ if (process.env["VERCEL"]) return "vercel";
64
+ if (process.env["AWS_LAMBDA_FUNCTION_NAME"]) return "lambda";
65
+ if (process.env["CF_PAGES"]) return "cloudflare";
66
+ if (process.env["NETLIFY"]) return "netlify";
67
+ if (process.env["AZURE_FUNCTIONS_ENVIRONMENT"]) return "azure";
68
+ if (process.env["K_SERVICE"]) return "gcp";
69
+ if (process.env["FLY_APP_NAME"]) return "fly";
70
+ if (process.env["RENDER"]) return "render";
71
+ if (process.env["RAILWAY_ENVIRONMENT"]) return "railway";
72
+ try {
73
+ const nodeFs = require("node:fs");
74
+ if (nodeFs.existsSync("/.dockerenv")) return "docker";
75
+ } catch {
76
+ }
77
+ return "bare";
78
+ }
79
+ function isKnownProvider(value) {
80
+ return value === "bare" || value === "docker" || value === "vercel" || value === "lambda" || value === "cloudflare" || value === "netlify" || value === "azure" || value === "gcp" || value === "fly" || value === "render" || value === "railway";
81
+ }
82
+
83
+ // libs/utils/src/env/runtime-context.ts
84
+ var entryAvailabilitySchema = import_lazy_zod.z.object({
85
+ os: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
86
+ platform: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
87
+ runtime: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
88
+ deployment: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
89
+ provider: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
90
+ target: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional(),
91
+ surface: import_lazy_zod.z.array(import_lazy_zod.z.enum(["mcp", "cli", "http-trigger", "job", "agent", "webmcp"])).optional(),
92
+ env: import_lazy_zod.z.array(import_lazy_zod.z.string().min(1)).optional()
93
+ }).strict();
94
+ var PROCESS_AXES = [
95
+ // `os` and `platform` both compare against the same RuntimeContext value
96
+ // — keeping `platform` as a deprecated alias lets pre-#417 metadata
97
+ // continue to match without any code change.
98
+ { key: "os", ctxKey: "os" },
99
+ { key: "platform", ctxKey: "platform" },
100
+ { key: "runtime", ctxKey: "runtime" },
101
+ { key: "deployment", ctxKey: "deployment" },
102
+ { key: "provider", ctxKey: "provider" },
103
+ { key: "target", ctxKey: "target" },
104
+ { key: "env", ctxKey: "env" }
105
+ ];
106
+ function isEntryAvailable(availability, ctx, callCtx) {
107
+ if (!availability) return true;
108
+ for (const { key, ctxKey } of PROCESS_AXES) {
109
+ const allowed = availability[key];
110
+ if (allowed === void 0) continue;
111
+ if (allowed.length === 0) return false;
112
+ if (!allowed.includes(ctx[ctxKey])) return false;
113
+ }
114
+ if (availability.surface !== void 0) {
115
+ if (availability.surface.length === 0) return false;
116
+ if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) {
117
+ return false;
118
+ }
119
+ }
120
+ return true;
121
+ }
122
+ function checkEntryAvailability(availability, ctx, callCtx) {
123
+ if (!availability) return { available: true, missingAxes: [] };
124
+ const missing = [];
125
+ for (const { key, ctxKey } of PROCESS_AXES) {
126
+ const allowed = availability[key];
127
+ if (allowed === void 0) continue;
128
+ if (allowed.length === 0 || !allowed.includes(ctx[ctxKey])) {
129
+ missing.push(key);
130
+ }
131
+ }
132
+ if (availability.surface !== void 0) {
133
+ if (availability.surface.length === 0) {
134
+ missing.push("surface");
135
+ } else if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) {
136
+ missing.push("surface");
137
+ }
138
+ }
139
+ return { available: missing.length === 0, missingAxes: missing };
140
+ }
141
+ function detectRuntime() {
142
+ if (typeof globalThis !== "undefined" && "Bun" in globalThis) return "bun";
143
+ if (typeof globalThis !== "undefined" && "Deno" in globalThis) return "deno";
144
+ if ((0, import_env.isEdgeRuntime)()) return "edge";
145
+ return "node";
146
+ }
147
+ function detectDeployment(runtime) {
148
+ const explicit = process.env["FRONTMCP_DEPLOYMENT_MODE"];
149
+ if (explicit === "distributed") return "distributed";
150
+ if (explicit === "serverless") return "serverless";
151
+ if (runtime === "browser") return "browser";
152
+ if ((0, import_env.isServerless)()) return "serverless";
153
+ return "standalone";
154
+ }
155
+ function detectRuntimeContext() {
156
+ const runtime = detectRuntime();
157
+ const os = process.platform;
158
+ return {
159
+ os,
160
+ platform: os,
161
+ runtime,
162
+ deployment: detectDeployment(runtime),
163
+ provider: detectProvider(),
164
+ target: getBuildTarget(),
165
+ env: (0, import_env.getNodeEnv)() || "development"
166
+ };
167
+ }
168
+ var cached3;
169
+ function getRuntimeContext() {
170
+ if (!cached3) {
171
+ const detected = detectRuntimeContext();
172
+ Object.defineProperty(detected, "env", {
173
+ get: () => (0, import_env.getNodeEnv)() || "development",
174
+ enumerable: true,
175
+ configurable: true
176
+ });
177
+ cached3 = detected;
178
+ }
179
+ return cached3;
180
+ }
181
+ function resetRuntimeContext() {
182
+ cached3 = void 0;
183
+ }
184
+ // Annotate the CommonJS export names for ESM import in node:
185
+ 0 && (module.exports = {
186
+ checkEntryAvailability,
187
+ detectRuntimeContext,
188
+ entryAvailabilitySchema,
189
+ getRuntimeContext,
190
+ isEntryAvailable,
191
+ resetRuntimeContext
192
+ });
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/async-context/overlap-error.ts
4
5
  var AsyncContextOverlapError = class extends Error {
5
6
  constructor(message) {
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/async-context/node-async-context.ts
4
5
  import { AsyncLocalStorage } from "node:async_hooks";
5
6
 
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/crypto/browser.ts
4
5
  import { sha256 as sha256Hash } from "@noble/hashes/sha2.js";
5
6
  import { hmac } from "@noble/hashes/hmac.js";
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/crypto/node.ts
4
5
  import crypto from "node:crypto";
5
6
 
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/env/edge-scope.ts
4
5
  function hasEdgeGlobalScope() {
5
6
  if (typeof globalThis === "undefined") return false;
@@ -22,6 +23,9 @@ function getEnv(_key, defaultValue) {
22
23
  function getCwd() {
23
24
  return "/";
24
25
  }
26
+ function getNodeEnv() {
27
+ return void 0;
28
+ }
25
29
  function isProduction() {
26
30
  return false;
27
31
  }
@@ -49,6 +53,7 @@ export {
49
53
  getCwd,
50
54
  getEnv,
51
55
  getEnvFlag,
56
+ getNodeEnv,
52
57
  isDebug,
53
58
  isDevelopment,
54
59
  isEdgeRuntime,
@@ -0,0 +1,77 @@
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
4
+ // libs/utils/src/env/browser-runtime-context.ts
5
+ import { z } from "@frontmcp/lazy-zod";
6
+ var entryAvailabilitySchema = z.object({
7
+ os: z.array(z.string().min(1)).optional(),
8
+ platform: z.array(z.string().min(1)).optional(),
9
+ runtime: z.array(z.string().min(1)).optional(),
10
+ deployment: z.array(z.string().min(1)).optional(),
11
+ provider: z.array(z.string().min(1)).optional(),
12
+ target: z.array(z.string().min(1)).optional(),
13
+ surface: z.array(z.enum(["mcp", "cli", "http-trigger", "job", "agent", "webmcp"])).optional(),
14
+ env: z.array(z.string().min(1)).optional()
15
+ }).strict();
16
+ var PROCESS_AXES = [
17
+ { key: "os", ctxKey: "os" },
18
+ { key: "platform", ctxKey: "platform" },
19
+ { key: "runtime", ctxKey: "runtime" },
20
+ { key: "deployment", ctxKey: "deployment" },
21
+ { key: "provider", ctxKey: "provider" },
22
+ { key: "target", ctxKey: "target" },
23
+ { key: "env", ctxKey: "env" }
24
+ ];
25
+ function isEntryAvailable(availability, ctx, callCtx) {
26
+ if (!availability) return true;
27
+ for (const { key, ctxKey } of PROCESS_AXES) {
28
+ const allowed = availability[key];
29
+ if (allowed === void 0) continue;
30
+ if (allowed.length === 0) return false;
31
+ if (!allowed.includes(ctx[ctxKey])) return false;
32
+ }
33
+ if (availability.surface !== void 0) {
34
+ if (availability.surface.length === 0) return false;
35
+ if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) return false;
36
+ }
37
+ return true;
38
+ }
39
+ function checkEntryAvailability(availability, ctx, callCtx) {
40
+ if (!availability) return { available: true, missingAxes: [] };
41
+ const missing = [];
42
+ for (const { key, ctxKey } of PROCESS_AXES) {
43
+ const allowed = availability[key];
44
+ if (allowed === void 0) continue;
45
+ if (allowed.length === 0 || !allowed.includes(ctx[ctxKey])) missing.push(key);
46
+ }
47
+ if (availability.surface !== void 0) {
48
+ if (availability.surface.length === 0) missing.push("surface");
49
+ else if (callCtx?.surface !== void 0 && !availability.surface.includes(callCtx.surface)) missing.push("surface");
50
+ }
51
+ return { available: missing.length === 0, missingAxes: missing };
52
+ }
53
+ function detectRuntimeContext() {
54
+ return {
55
+ os: "browser",
56
+ platform: "browser",
57
+ runtime: "browser",
58
+ deployment: "standalone",
59
+ provider: "bare",
60
+ target: "browser",
61
+ env: "production"
62
+ };
63
+ }
64
+ var browserContext = detectRuntimeContext();
65
+ function getRuntimeContext() {
66
+ return browserContext;
67
+ }
68
+ function resetRuntimeContext() {
69
+ }
70
+ export {
71
+ checkEntryAvailability,
72
+ detectRuntimeContext,
73
+ entryAvailabilitySchema,
74
+ getRuntimeContext,
75
+ isEntryAvailable,
76
+ resetRuntimeContext
77
+ };
@@ -1,5 +1,6 @@
1
- import { createRequire as __frontmcpCreateRequire } from 'module';
2
- const require = __frontmcpCreateRequire(import.meta.url || 'file:///');
1
+ var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : undefined;
2
+ const require = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || 'file:///') : undefined;
3
+ // __frontmcpCreateRequire
3
4
  // libs/utils/src/env/edge-scope.ts
4
5
  function hasEdgeGlobalScope() {
5
6
  if (typeof globalThis === "undefined") return false;
@@ -22,11 +23,15 @@ function getEnv(key, defaultValue) {
22
23
  function getCwd() {
23
24
  return process.cwd();
24
25
  }
26
+ var NODE_ENV_KEY = "NODE_ENV";
27
+ function getNodeEnv() {
28
+ return process.env[NODE_ENV_KEY] || process.env["NODE_ENV"] || void 0;
29
+ }
25
30
  function isProduction() {
26
- return process.env["NODE_ENV"] === "production";
31
+ return getNodeEnv() === "production";
27
32
  }
28
33
  function isDevelopment() {
29
- return process.env["NODE_ENV"] === "development";
34
+ return getNodeEnv() === "development";
30
35
  }
31
36
  function getEnvFlag(key) {
32
37
  const v = process.env[key];
@@ -57,6 +62,7 @@ export {
57
62
  getCwd,
58
63
  getEnv,
59
64
  getEnvFlag,
65
+ getNodeEnv,
60
66
  isDebug,
61
67
  isDevelopment,
62
68
  isEdgeRuntime,