@frontmcp/plugin-cache 1.9.1-rc.3 → 1.9.2

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.
package/esm/index.mjs CHANGED
@@ -2597,6 +2597,53 @@ var init_redis_error_listener = __esm({
2597
2597
  DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS = 3e4;
2598
2598
  }
2599
2599
  });
2600
+ function decodeOrRaw(encoded) {
2601
+ try {
2602
+ return decodeURIComponent(encoded);
2603
+ } catch {
2604
+ return encoded;
2605
+ }
2606
+ }
2607
+ function mergeRedisUrlFields(rawUrl, fields) {
2608
+ let url;
2609
+ try {
2610
+ url = new URL(rawUrl);
2611
+ } catch {
2612
+ return void 0;
2613
+ }
2614
+ const urlHost = url.hostname.replace(/^\[(.*)\]$/, "$1");
2615
+ const urlPort = url.port ? Number(url.port) : void 0;
2616
+ const urlPassword = url.password ? decodeOrRaw(url.password) : void 0;
2617
+ const urlDbText = url.pathname.replace(/^\/+/, "") || url.searchParams.get("db") || void 0;
2618
+ const urlDb = urlDbText === void 0 ? void 0 : Number(urlDbText);
2619
+ const urlUsesTls = url.protocol === "rediss:";
2620
+ const fillIns = {};
2621
+ const conflicts = [];
2622
+ if (fields.host !== void 0 && fields.host !== urlHost) conflicts.push("host");
2623
+ if (fields.port !== void 0) {
2624
+ if (urlPort === void 0) fillIns.port = fields.port;
2625
+ else if (fields.port !== urlPort) conflicts.push("port");
2626
+ }
2627
+ if (fields.password !== void 0) {
2628
+ if (urlPassword === void 0) fillIns.password = fields.password;
2629
+ else if (fields.password !== urlPassword) conflicts.push("password");
2630
+ }
2631
+ if (fields.db !== void 0) {
2632
+ if (urlDb === void 0) fillIns.db = fields.db;
2633
+ else if (fields.db !== urlDb) conflicts.push("db");
2634
+ }
2635
+ if (fields.tls === true && !urlUsesTls) fillIns.tls = true;
2636
+ if (fields.tls === false && urlUsesTls) conflicts.push("tls");
2637
+ return { fillIns, conflicts };
2638
+ }
2639
+ function describeRedisUrlConflicts(conflicts) {
2640
+ return `redis ${conflicts.join(", ")} contradict${conflicts.length === 1 ? "s" : ""} redis.url. Fields beside a url only fill in what the URL leaves out (port, password, db, tls); put the value in the URL or drop the field.`;
2641
+ }
2642
+ var init_redis_url = __esm({
2643
+ "libs/utils/src/storage/redis-url.ts"() {
2644
+ "use strict";
2645
+ }
2646
+ });
2600
2647
  var init_utils = __esm({
2601
2648
  "libs/utils/src/storage/utils/index.ts"() {
2602
2649
  "use strict";
@@ -2631,6 +2678,17 @@ function getRedisClass() {
2631
2678
  });
2632
2679
  }
2633
2680
  }
2681
+ function resolveUrlFillIns(connectionUrl, options) {
2682
+ const { url: configUrl, ...siblingFields } = { url: void 0, ...options.config };
2683
+ if (options.url && configUrl && configUrl !== options.url) {
2684
+ throw new StorageConfigError("redis", "redis.url and redis.config.url name different servers; set one of them.");
2685
+ }
2686
+ const merge = mergeRedisUrlFields(connectionUrl, siblingFields);
2687
+ if (merge && merge.conflicts.length > 0) {
2688
+ throw new StorageConfigError("redis", describeRedisUrlConflicts(merge.conflicts));
2689
+ }
2690
+ return merge?.fillIns ?? {};
2691
+ }
2634
2692
  function createRedisClient(options) {
2635
2693
  const RedisClass = getRedisClass();
2636
2694
  const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
@@ -2651,6 +2709,7 @@ var init_redis = __esm({
2651
2709
  "use strict";
2652
2710
  init_errors();
2653
2711
  init_redis_error_listener();
2712
+ init_redis_url();
2654
2713
  init_utils();
2655
2714
  init_compare_and_delete();
2656
2715
  init_base();
@@ -2664,6 +2723,8 @@ var init_redis = __esm({
2664
2723
  connecting;
2665
2724
  keyPrefix;
2666
2725
  subscriptionHandlers = /* @__PURE__ */ new Map();
2726
+ connectionUrl;
2727
+ urlFillIns;
2667
2728
  constructor(options = {}) {
2668
2729
  super();
2669
2730
  const hasClient = options.client !== void 0;
@@ -2685,6 +2746,9 @@ var init_redis = __esm({
2685
2746
  this.options = options;
2686
2747
  this.ownsClient = !hasClient;
2687
2748
  this.keyPrefix = options.keyPrefix ?? "";
2749
+ const configUrl = options.config?.url;
2750
+ this.connectionUrl = options.url ?? (typeof configUrl === "string" ? configUrl : void 0);
2751
+ this.urlFillIns = this.connectionUrl ? resolveUrlFillIns(this.connectionUrl, options) : {};
2688
2752
  }
2689
2753
  // ============================================
2690
2754
  // Connection Lifecycle
@@ -2707,8 +2771,8 @@ var init_redis = __esm({
2707
2771
  client = this.options.client;
2708
2772
  } else {
2709
2773
  const RedisClass = getRedisClass();
2710
- if (this.options.url) {
2711
- client = new RedisClass(this.options.url, this.buildRedisOptions());
2774
+ if (this.connectionUrl) {
2775
+ client = new RedisClass(this.connectionUrl, this.buildRedisOptions());
2712
2776
  } else {
2713
2777
  client = new RedisClass(this.buildRedisOptions());
2714
2778
  }
@@ -2944,14 +3008,19 @@ var init_redis = __esm({
2944
3008
  * Build Redis options from config.
2945
3009
  */
2946
3010
  buildRedisOptions() {
2947
- if (this.options.url) {
3011
+ if (this.connectionUrl) {
3012
+ const { port, password, db, tls } = this.urlFillIns;
2948
3013
  return {
3014
+ ...port !== void 0 ? { port } : {},
3015
+ ...password !== void 0 ? { password } : {},
3016
+ ...db !== void 0 ? { db } : {},
3017
+ ...tls ? { tls: {} } : {},
2949
3018
  lazyConnect: false,
2950
3019
  maxRetriesPerRequest: 3
2951
3020
  };
2952
3021
  }
2953
3022
  const config = this.options.config;
2954
- if (!config) {
3023
+ if (!config || typeof config.url === "string" || config.host === void 0) {
2955
3024
  throw new StorageConfigError("redis", "Redis config is required when URL is not provided");
2956
3025
  }
2957
3026
  return {
@@ -2970,8 +3039,8 @@ var init_redis = __esm({
2970
3039
  async createSubscriber() {
2971
3040
  const RedisClass = getRedisClass();
2972
3041
  let subscriber;
2973
- if (this.options.url) {
2974
- subscriber = new RedisClass(this.options.url);
3042
+ if (this.connectionUrl) {
3043
+ subscriber = new RedisClass(this.connectionUrl, this.buildRedisOptions());
2975
3044
  } else if (this.options.config) {
2976
3045
  subscriber = new RedisClass(this.buildRedisOptions());
2977
3046
  } else if (this.options.client) {
@@ -3020,7 +3089,8 @@ var init_redis = __esm({
3020
3089
  });
3021
3090
  var vercel_kv_exports = {};
3022
3091
  __export(vercel_kv_exports, {
3023
- VercelKvStorageAdapter: () => VercelKvStorageAdapter
3092
+ VercelKvStorageAdapter: () => VercelKvStorageAdapter,
3093
+ createVercelKvClient: () => createVercelKvClient
3024
3094
  });
3025
3095
  async function loadVercelKv() {
3026
3096
  try {
@@ -3032,6 +3102,15 @@ async function loadVercelKv() {
3032
3102
  throw new Error("@vercel/kv is required for Vercel KV storage adapter. Install it with: npm install @vercel/kv");
3033
3103
  }
3034
3104
  }
3105
+ async function createVercelKvClient(connection = {}) {
3106
+ const url = connection.url ?? process.env["KV_REST_API_URL"];
3107
+ const token = connection.token ?? process.env["KV_REST_API_TOKEN"];
3108
+ if (!url || !token) {
3109
+ throw new StorageConfigError("vercel-kv", "Pass url and token, or set KV_REST_API_URL and KV_REST_API_TOKEN.");
3110
+ }
3111
+ const { createClient } = await loadVercelKv();
3112
+ return createClient({ url, token, cache: void 0, automaticDeserialization: false });
3113
+ }
3035
3114
  var VercelKvStorageAdapter;
3036
3115
  var init_vercel_kv = __esm({
3037
3116
  "libs/utils/src/storage/adapters/vercel-kv.ts"() {
@@ -3064,13 +3143,7 @@ var init_vercel_kv = __esm({
3064
3143
  async connect() {
3065
3144
  if (this.connected) return;
3066
3145
  try {
3067
- const { createClient } = await loadVercelKv();
3068
- const url = this.options.url;
3069
- const token = this.options.token;
3070
- if (!url || !token) {
3071
- throw new StorageConfigError("vercel-kv", "URL and token are required");
3072
- }
3073
- this.client = createClient({ url, token, cache: void 0, automaticDeserialization: false });
3146
+ this.client = await createVercelKvClient({ url: this.options.url, token: this.options.token });
3074
3147
  await this.client.exists("__healthcheck__");
3075
3148
  this.connected = true;
3076
3149
  } catch (e) {
@@ -3241,9 +3314,12 @@ var upstash_exports = {};
3241
3314
  __export(upstash_exports, {
3242
3315
  UpstashStorageAdapter: () => UpstashStorageAdapter
3243
3316
  });
3244
- function getUpstashRedis() {
3317
+ async function loadUpstashRedis() {
3245
3318
  try {
3246
- return __require2("@upstash/redis");
3319
+ const mod = await import("@upstash/redis");
3320
+ const resolved = typeof mod.Redis === "function" ? mod : mod.default;
3321
+ if (!resolved || typeof resolved.Redis !== "function") throw new Error("Redis missing");
3322
+ return resolved;
3247
3323
  } catch {
3248
3324
  throw new Error(
3249
3325
  "@upstash/redis is required for Upstash storage adapter. Install it with: npm install @upstash/redis"
@@ -3289,7 +3365,7 @@ var init_upstash = __esm({
3289
3365
  async connect() {
3290
3366
  if (this.connected) return;
3291
3367
  try {
3292
- const { Redis: Redis2 } = getUpstashRedis();
3368
+ const { Redis: Redis2 } = await loadUpstashRedis();
3293
3369
  const url = this.options.url;
3294
3370
  const token = this.options.token;
3295
3371
  if (!url || !token) {
@@ -3778,6 +3854,7 @@ init_errors();
3778
3854
  init_errors();
3779
3855
  init_memory();
3780
3856
  init_redis_error_listener();
3857
+ init_redis_url();
3781
3858
  init_errors();
3782
3859
  init_crypto();
3783
3860
  init_errors();
@@ -3962,11 +4039,11 @@ CacheRedisProvider = __decorateClass([
3962
4039
  // plugins/plugin-cache/src/providers/cache-vercel-kv.provider.ts
3963
4040
  import { Provider as Provider3, ProviderScope as ProviderScope3 } from "@frontmcp/sdk";
3964
4041
  var CacheVercelKvProvider = class {
3965
- kv;
4042
+ connection;
4043
+ client;
3966
4044
  keyPrefix;
3967
4045
  defaultTTL;
3968
4046
  constructor(options = {}) {
3969
- const vercelKv = __require("@vercel/kv");
3970
4047
  const hasUrl = options.url !== void 0;
3971
4048
  const hasToken = options.token !== void 0;
3972
4049
  if (hasUrl !== hasToken) {
@@ -3974,17 +4051,21 @@ var CacheVercelKvProvider = class {
3974
4051
  `CacheVercelKvProvider: Both 'url' and 'token' must be provided together, or neither. Received: url=${hasUrl ? "provided" : "missing"}, token=${hasToken ? "provided" : "missing"}`
3975
4052
  );
3976
4053
  }
3977
- if (options.url && options.token) {
3978
- this.kv = vercelKv.createClient({
3979
- url: options.url,
3980
- token: options.token
3981
- });
3982
- } else {
3983
- this.kv = vercelKv.kv;
3984
- }
4054
+ this.connection = { url: options.url, token: options.token };
3985
4055
  this.keyPrefix = options.keyPrefix ?? "cache:";
3986
4056
  this.defaultTTL = options.defaultTTL ?? 60 * 60 * 24;
3987
4057
  }
4058
+ /**
4059
+ * The client, built on first use from the url and token (or KV_REST_API_URL / KV_REST_API_TOKEN)
4060
+ * by the shared loader, which a Cloudflare Worker can bundle (#711). A failed attempt is retried.
4061
+ */
4062
+ kv() {
4063
+ this.client ??= createVercelKvClient(this.connection).catch((error) => {
4064
+ this.client = void 0;
4065
+ throw error;
4066
+ });
4067
+ return this.client;
4068
+ }
3988
4069
  prefixKey(key) {
3989
4070
  return `${this.keyPrefix}${key}`;
3990
4071
  }
@@ -3992,15 +4073,17 @@ var CacheVercelKvProvider = class {
3992
4073
  async setValue(key, value, ttlSeconds) {
3993
4074
  const strValue = typeof value === "string" ? value : JSON.stringify(value);
3994
4075
  const ttl = ttlSeconds ?? this.defaultTTL;
4076
+ const kv = await this.kv();
3995
4077
  if (ttl > 0) {
3996
- await this.kv.set(this.prefixKey(key), strValue, { ex: ttl });
4078
+ await kv.set(this.prefixKey(key), strValue, { ex: ttl });
3997
4079
  } else {
3998
- await this.kv.set(this.prefixKey(key), strValue);
4080
+ await kv.set(this.prefixKey(key), strValue);
3999
4081
  }
4000
4082
  }
4001
4083
  /** Get a value and automatically parse JSON if possible */
4002
4084
  async getValue(key, defaultValue) {
4003
- const raw = await this.kv.get(this.prefixKey(key));
4085
+ const kv = await this.kv();
4086
+ const raw = await kv.get(this.prefixKey(key));
4004
4087
  if (raw === null || raw === void 0) return defaultValue;
4005
4088
  if (typeof raw === "string") {
4006
4089
  try {
@@ -4013,11 +4096,13 @@ var CacheVercelKvProvider = class {
4013
4096
  }
4014
4097
  /** Delete a key */
4015
4098
  async delete(key) {
4016
- await this.kv.del(this.prefixKey(key));
4099
+ const kv = await this.kv();
4100
+ await kv.del(this.prefixKey(key));
4017
4101
  }
4018
4102
  /** Check if a key exists */
4019
4103
  async exists(key) {
4020
- return await this.kv.exists(this.prefixKey(key)) === 1;
4104
+ const kv = await this.kv();
4105
+ return await kv.exists(this.prefixKey(key)) === 1;
4021
4106
  }
4022
4107
  /** Gracefully close the provider (no-op for Vercel KV - stateless REST API) */
4023
4108
  async close() {
package/esm/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontmcp/plugin-cache",
3
- "version": "1.9.1-rc.3",
3
+ "version": "1.9.2",
4
4
  "description": "Cache plugin for FrontMCP - Redis, Vercel KV, and in-memory caching with automatic tool result caching",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "license": "Apache-2.0",
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@frontmcp/sdk": "1.9.1-rc.3",
52
- "@frontmcp/utils": "1.9.1-rc.3",
51
+ "@frontmcp/sdk": "1.9.2",
52
+ "@frontmcp/utils": "1.9.2",
53
53
  "ioredis": "^5.8.0"
54
54
  },
55
55
  "peerDependencies": {
package/index.js CHANGED
@@ -2596,6 +2596,53 @@ var init_redis_error_listener = __esm({
2596
2596
  DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS = 3e4;
2597
2597
  }
2598
2598
  });
2599
+ function decodeOrRaw(encoded) {
2600
+ try {
2601
+ return decodeURIComponent(encoded);
2602
+ } catch {
2603
+ return encoded;
2604
+ }
2605
+ }
2606
+ function mergeRedisUrlFields(rawUrl, fields) {
2607
+ let url;
2608
+ try {
2609
+ url = new URL(rawUrl);
2610
+ } catch {
2611
+ return void 0;
2612
+ }
2613
+ const urlHost = url.hostname.replace(/^\[(.*)\]$/, "$1");
2614
+ const urlPort = url.port ? Number(url.port) : void 0;
2615
+ const urlPassword = url.password ? decodeOrRaw(url.password) : void 0;
2616
+ const urlDbText = url.pathname.replace(/^\/+/, "") || url.searchParams.get("db") || void 0;
2617
+ const urlDb = urlDbText === void 0 ? void 0 : Number(urlDbText);
2618
+ const urlUsesTls = url.protocol === "rediss:";
2619
+ const fillIns = {};
2620
+ const conflicts = [];
2621
+ if (fields.host !== void 0 && fields.host !== urlHost) conflicts.push("host");
2622
+ if (fields.port !== void 0) {
2623
+ if (urlPort === void 0) fillIns.port = fields.port;
2624
+ else if (fields.port !== urlPort) conflicts.push("port");
2625
+ }
2626
+ if (fields.password !== void 0) {
2627
+ if (urlPassword === void 0) fillIns.password = fields.password;
2628
+ else if (fields.password !== urlPassword) conflicts.push("password");
2629
+ }
2630
+ if (fields.db !== void 0) {
2631
+ if (urlDb === void 0) fillIns.db = fields.db;
2632
+ else if (fields.db !== urlDb) conflicts.push("db");
2633
+ }
2634
+ if (fields.tls === true && !urlUsesTls) fillIns.tls = true;
2635
+ if (fields.tls === false && urlUsesTls) conflicts.push("tls");
2636
+ return { fillIns, conflicts };
2637
+ }
2638
+ function describeRedisUrlConflicts(conflicts) {
2639
+ return `redis ${conflicts.join(", ")} contradict${conflicts.length === 1 ? "s" : ""} redis.url. Fields beside a url only fill in what the URL leaves out (port, password, db, tls); put the value in the URL or drop the field.`;
2640
+ }
2641
+ var init_redis_url = __esm({
2642
+ "libs/utils/src/storage/redis-url.ts"() {
2643
+ "use strict";
2644
+ }
2645
+ });
2599
2646
  var init_utils = __esm({
2600
2647
  "libs/utils/src/storage/utils/index.ts"() {
2601
2648
  "use strict";
@@ -2630,6 +2677,17 @@ function getRedisClass() {
2630
2677
  });
2631
2678
  }
2632
2679
  }
2680
+ function resolveUrlFillIns(connectionUrl, options) {
2681
+ const { url: configUrl, ...siblingFields } = { url: void 0, ...options.config };
2682
+ if (options.url && configUrl && configUrl !== options.url) {
2683
+ throw new StorageConfigError("redis", "redis.url and redis.config.url name different servers; set one of them.");
2684
+ }
2685
+ const merge = mergeRedisUrlFields(connectionUrl, siblingFields);
2686
+ if (merge && merge.conflicts.length > 0) {
2687
+ throw new StorageConfigError("redis", describeRedisUrlConflicts(merge.conflicts));
2688
+ }
2689
+ return merge?.fillIns ?? {};
2690
+ }
2633
2691
  function createRedisClient(options) {
2634
2692
  const RedisClass = getRedisClass();
2635
2693
  const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
@@ -2650,6 +2708,7 @@ var init_redis = __esm({
2650
2708
  "use strict";
2651
2709
  init_errors();
2652
2710
  init_redis_error_listener();
2711
+ init_redis_url();
2653
2712
  init_utils();
2654
2713
  init_compare_and_delete();
2655
2714
  init_base();
@@ -2663,6 +2722,8 @@ var init_redis = __esm({
2663
2722
  connecting;
2664
2723
  keyPrefix;
2665
2724
  subscriptionHandlers = /* @__PURE__ */ new Map();
2725
+ connectionUrl;
2726
+ urlFillIns;
2666
2727
  constructor(options = {}) {
2667
2728
  super();
2668
2729
  const hasClient = options.client !== void 0;
@@ -2684,6 +2745,9 @@ var init_redis = __esm({
2684
2745
  this.options = options;
2685
2746
  this.ownsClient = !hasClient;
2686
2747
  this.keyPrefix = options.keyPrefix ?? "";
2748
+ const configUrl = options.config?.url;
2749
+ this.connectionUrl = options.url ?? (typeof configUrl === "string" ? configUrl : void 0);
2750
+ this.urlFillIns = this.connectionUrl ? resolveUrlFillIns(this.connectionUrl, options) : {};
2687
2751
  }
2688
2752
  // ============================================
2689
2753
  // Connection Lifecycle
@@ -2706,8 +2770,8 @@ var init_redis = __esm({
2706
2770
  client = this.options.client;
2707
2771
  } else {
2708
2772
  const RedisClass = getRedisClass();
2709
- if (this.options.url) {
2710
- client = new RedisClass(this.options.url, this.buildRedisOptions());
2773
+ if (this.connectionUrl) {
2774
+ client = new RedisClass(this.connectionUrl, this.buildRedisOptions());
2711
2775
  } else {
2712
2776
  client = new RedisClass(this.buildRedisOptions());
2713
2777
  }
@@ -2943,14 +3007,19 @@ var init_redis = __esm({
2943
3007
  * Build Redis options from config.
2944
3008
  */
2945
3009
  buildRedisOptions() {
2946
- if (this.options.url) {
3010
+ if (this.connectionUrl) {
3011
+ const { port, password, db, tls } = this.urlFillIns;
2947
3012
  return {
3013
+ ...port !== void 0 ? { port } : {},
3014
+ ...password !== void 0 ? { password } : {},
3015
+ ...db !== void 0 ? { db } : {},
3016
+ ...tls ? { tls: {} } : {},
2948
3017
  lazyConnect: false,
2949
3018
  maxRetriesPerRequest: 3
2950
3019
  };
2951
3020
  }
2952
3021
  const config = this.options.config;
2953
- if (!config) {
3022
+ if (!config || typeof config.url === "string" || config.host === void 0) {
2954
3023
  throw new StorageConfigError("redis", "Redis config is required when URL is not provided");
2955
3024
  }
2956
3025
  return {
@@ -2969,8 +3038,8 @@ var init_redis = __esm({
2969
3038
  async createSubscriber() {
2970
3039
  const RedisClass = getRedisClass();
2971
3040
  let subscriber;
2972
- if (this.options.url) {
2973
- subscriber = new RedisClass(this.options.url);
3041
+ if (this.connectionUrl) {
3042
+ subscriber = new RedisClass(this.connectionUrl, this.buildRedisOptions());
2974
3043
  } else if (this.options.config) {
2975
3044
  subscriber = new RedisClass(this.buildRedisOptions());
2976
3045
  } else if (this.options.client) {
@@ -3019,7 +3088,8 @@ var init_redis = __esm({
3019
3088
  });
3020
3089
  var vercel_kv_exports = {};
3021
3090
  __export2(vercel_kv_exports, {
3022
- VercelKvStorageAdapter: () => VercelKvStorageAdapter
3091
+ VercelKvStorageAdapter: () => VercelKvStorageAdapter,
3092
+ createVercelKvClient: () => createVercelKvClient
3023
3093
  });
3024
3094
  async function loadVercelKv() {
3025
3095
  try {
@@ -3031,6 +3101,15 @@ async function loadVercelKv() {
3031
3101
  throw new Error("@vercel/kv is required for Vercel KV storage adapter. Install it with: npm install @vercel/kv");
3032
3102
  }
3033
3103
  }
3104
+ async function createVercelKvClient(connection = {}) {
3105
+ const url = connection.url ?? process.env["KV_REST_API_URL"];
3106
+ const token = connection.token ?? process.env["KV_REST_API_TOKEN"];
3107
+ if (!url || !token) {
3108
+ throw new StorageConfigError("vercel-kv", "Pass url and token, or set KV_REST_API_URL and KV_REST_API_TOKEN.");
3109
+ }
3110
+ const { createClient } = await loadVercelKv();
3111
+ return createClient({ url, token, cache: void 0, automaticDeserialization: false });
3112
+ }
3034
3113
  var VercelKvStorageAdapter;
3035
3114
  var init_vercel_kv = __esm({
3036
3115
  "libs/utils/src/storage/adapters/vercel-kv.ts"() {
@@ -3063,13 +3142,7 @@ var init_vercel_kv = __esm({
3063
3142
  async connect() {
3064
3143
  if (this.connected) return;
3065
3144
  try {
3066
- const { createClient } = await loadVercelKv();
3067
- const url = this.options.url;
3068
- const token = this.options.token;
3069
- if (!url || !token) {
3070
- throw new StorageConfigError("vercel-kv", "URL and token are required");
3071
- }
3072
- this.client = createClient({ url, token, cache: void 0, automaticDeserialization: false });
3145
+ this.client = await createVercelKvClient({ url: this.options.url, token: this.options.token });
3073
3146
  await this.client.exists("__healthcheck__");
3074
3147
  this.connected = true;
3075
3148
  } catch (e) {
@@ -3240,9 +3313,12 @@ var upstash_exports = {};
3240
3313
  __export2(upstash_exports, {
3241
3314
  UpstashStorageAdapter: () => UpstashStorageAdapter
3242
3315
  });
3243
- function getUpstashRedis() {
3316
+ async function loadUpstashRedis() {
3244
3317
  try {
3245
- return __require("@upstash/redis");
3318
+ const mod = await import("@upstash/redis");
3319
+ const resolved = typeof mod.Redis === "function" ? mod : mod.default;
3320
+ if (!resolved || typeof resolved.Redis !== "function") throw new Error("Redis missing");
3321
+ return resolved;
3246
3322
  } catch {
3247
3323
  throw new Error(
3248
3324
  "@upstash/redis is required for Upstash storage adapter. Install it with: npm install @upstash/redis"
@@ -3288,7 +3364,7 @@ var init_upstash = __esm({
3288
3364
  async connect() {
3289
3365
  if (this.connected) return;
3290
3366
  try {
3291
- const { Redis: Redis2 } = getUpstashRedis();
3367
+ const { Redis: Redis2 } = await loadUpstashRedis();
3292
3368
  const url = this.options.url;
3293
3369
  const token = this.options.token;
3294
3370
  if (!url || !token) {
@@ -3777,6 +3853,7 @@ init_errors();
3777
3853
  init_errors();
3778
3854
  init_memory();
3779
3855
  init_redis_error_listener();
3856
+ init_redis_url();
3780
3857
  init_errors();
3781
3858
  init_crypto();
3782
3859
  init_errors();
@@ -3961,11 +4038,11 @@ CacheRedisProvider = __decorateClass([
3961
4038
  // plugins/plugin-cache/src/providers/cache-vercel-kv.provider.ts
3962
4039
  var import_sdk3 = require("@frontmcp/sdk");
3963
4040
  var CacheVercelKvProvider = class {
3964
- kv;
4041
+ connection;
4042
+ client;
3965
4043
  keyPrefix;
3966
4044
  defaultTTL;
3967
4045
  constructor(options = {}) {
3968
- const vercelKv = require("@vercel/kv");
3969
4046
  const hasUrl = options.url !== void 0;
3970
4047
  const hasToken = options.token !== void 0;
3971
4048
  if (hasUrl !== hasToken) {
@@ -3973,17 +4050,21 @@ var CacheVercelKvProvider = class {
3973
4050
  `CacheVercelKvProvider: Both 'url' and 'token' must be provided together, or neither. Received: url=${hasUrl ? "provided" : "missing"}, token=${hasToken ? "provided" : "missing"}`
3974
4051
  );
3975
4052
  }
3976
- if (options.url && options.token) {
3977
- this.kv = vercelKv.createClient({
3978
- url: options.url,
3979
- token: options.token
3980
- });
3981
- } else {
3982
- this.kv = vercelKv.kv;
3983
- }
4053
+ this.connection = { url: options.url, token: options.token };
3984
4054
  this.keyPrefix = options.keyPrefix ?? "cache:";
3985
4055
  this.defaultTTL = options.defaultTTL ?? 60 * 60 * 24;
3986
4056
  }
4057
+ /**
4058
+ * The client, built on first use from the url and token (or KV_REST_API_URL / KV_REST_API_TOKEN)
4059
+ * by the shared loader, which a Cloudflare Worker can bundle (#711). A failed attempt is retried.
4060
+ */
4061
+ kv() {
4062
+ this.client ??= createVercelKvClient(this.connection).catch((error) => {
4063
+ this.client = void 0;
4064
+ throw error;
4065
+ });
4066
+ return this.client;
4067
+ }
3987
4068
  prefixKey(key) {
3988
4069
  return `${this.keyPrefix}${key}`;
3989
4070
  }
@@ -3991,15 +4072,17 @@ var CacheVercelKvProvider = class {
3991
4072
  async setValue(key, value, ttlSeconds) {
3992
4073
  const strValue = typeof value === "string" ? value : JSON.stringify(value);
3993
4074
  const ttl = ttlSeconds ?? this.defaultTTL;
4075
+ const kv = await this.kv();
3994
4076
  if (ttl > 0) {
3995
- await this.kv.set(this.prefixKey(key), strValue, { ex: ttl });
4077
+ await kv.set(this.prefixKey(key), strValue, { ex: ttl });
3996
4078
  } else {
3997
- await this.kv.set(this.prefixKey(key), strValue);
4079
+ await kv.set(this.prefixKey(key), strValue);
3998
4080
  }
3999
4081
  }
4000
4082
  /** Get a value and automatically parse JSON if possible */
4001
4083
  async getValue(key, defaultValue) {
4002
- const raw = await this.kv.get(this.prefixKey(key));
4084
+ const kv = await this.kv();
4085
+ const raw = await kv.get(this.prefixKey(key));
4003
4086
  if (raw === null || raw === void 0) return defaultValue;
4004
4087
  if (typeof raw === "string") {
4005
4088
  try {
@@ -4012,11 +4095,13 @@ var CacheVercelKvProvider = class {
4012
4095
  }
4013
4096
  /** Delete a key */
4014
4097
  async delete(key) {
4015
- await this.kv.del(this.prefixKey(key));
4098
+ const kv = await this.kv();
4099
+ await kv.del(this.prefixKey(key));
4016
4100
  }
4017
4101
  /** Check if a key exists */
4018
4102
  async exists(key) {
4019
- return await this.kv.exists(this.prefixKey(key)) === 1;
4103
+ const kv = await this.kv();
4104
+ return await kv.exists(this.prefixKey(key)) === 1;
4020
4105
  }
4021
4106
  /** Gracefully close the provider (no-op for Vercel KV - stateless REST API) */
4022
4107
  async close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontmcp/plugin-cache",
3
- "version": "1.9.1-rc.3",
3
+ "version": "1.9.2",
4
4
  "description": "Cache plugin for FrontMCP - Redis, Vercel KV, and in-memory caching with automatic tool result caching",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "license": "Apache-2.0",
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@frontmcp/sdk": "1.9.1-rc.3",
52
- "@frontmcp/utils": "1.9.1-rc.3",
51
+ "@frontmcp/sdk": "1.9.2",
52
+ "@frontmcp/utils": "1.9.2",
53
53
  "ioredis": "^5.8.0"
54
54
  },
55
55
  "peerDependencies": {
@@ -1,4 +1,4 @@
1
- import { CacheStoreInterface } from '../cache.types';
1
+ import { type CacheStoreInterface } from '../cache.types';
2
2
  export interface CacheVercelKvProviderOptions {
3
3
  url?: string;
4
4
  token?: string;
@@ -6,10 +6,16 @@ export interface CacheVercelKvProviderOptions {
6
6
  defaultTTL?: number;
7
7
  }
8
8
  export default class CacheVercelKvProvider implements CacheStoreInterface {
9
- private kv;
9
+ private readonly connection;
10
+ private client?;
10
11
  private readonly keyPrefix;
11
12
  private readonly defaultTTL;
12
13
  constructor(options?: CacheVercelKvProviderOptions);
14
+ /**
15
+ * The client, built on first use from the url and token (or KV_REST_API_URL / KV_REST_API_TOKEN)
16
+ * by the shared loader, which a Cloudflare Worker can bundle (#711). A failed attempt is retried.
17
+ */
18
+ private kv;
13
19
  private prefixKey;
14
20
  /** Set a value (auto-stringifies objects) */
15
21
  setValue(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"cache-vercel-kv.provider.d.ts","sourceRoot":"","sources":["../../src/providers/cache-vercel-kv.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAeD,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,mBAAmB;IACvE,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,GAAE,4BAAiC;IA6BtD,OAAO,CAAC,SAAS;IAIjB,6CAA6C;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW/E,2DAA2D;IACrD,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAgBlF,mBAAmB;IACb,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,4BAA4B;IACtB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3C,+EAA+E;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
1
+ {"version":3,"file":"cache-vercel-kv.provider.d.ts","sourceRoot":"","sources":["../../src/providers/cache-vercel-kv.provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAeD,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,mBAAmB;IACvE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;IAChD,OAAO,CAAC,MAAM,CAAC,CAA0B;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,GAAE,4BAAiC;IAgBtD;;;OAGG;IACH,OAAO,CAAC,EAAE;IAQV,OAAO,CAAC,SAAS;IAIjB,6CAA6C;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/E,2DAA2D;IACrD,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAiBlF,mBAAmB;IACb,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,4BAA4B;IACtB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3C,+EAA+E;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}