@frontmcp/plugin-cache 1.8.5 → 1.8.7
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/cache.plugin.d.ts.map +1 -1
- package/esm/index.mjs +107 -31
- package/esm/package.json +3 -3
- package/index.js +107 -31
- package/package.json +3 -3
package/cache.plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.plugin.d.ts","sourceRoot":"","sources":["../src/cache.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAOb,KAAK,SAAS,EAEd,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.plugin.d.ts","sourceRoot":"","sources":["../src/cache.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAOb,KAAK,SAAS,EAEd,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,eAAe,CAAC;AA8C5F,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACxE,OAAgB,gBAAgB,GAAI,SAAS,kBAAkB,oBAuD7D;IAEF,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAEvC;IACF,OAAO,EAAE,kBAAkB,CAAC;gBAEhB,OAAO,GAAE,kBAA+C;IAQpE;;OAEG;IACH,OAAO,CAAC,eAAe;IAkBvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;IACH,OAAO,CAAC,MAAM;IAQR,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IA0DnD,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IAyB1D;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAQrB;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGvC"}
|
package/esm/index.mjs
CHANGED
|
@@ -296,7 +296,6 @@ import {
|
|
|
296
296
|
} from "@frontmcp/sdk";
|
|
297
297
|
|
|
298
298
|
// libs/utils/dist/esm/index.mjs
|
|
299
|
-
import { createRequire as __frontmcpCreateRequire } from "module";
|
|
300
299
|
import { z } from "@frontmcp/lazy-zod";
|
|
301
300
|
var import_event_emitter = __toESM(require_node_event_emitter(), 1);
|
|
302
301
|
import { z as z2 } from "@frontmcp/lazy-zod";
|
|
@@ -309,7 +308,8 @@ import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils.js";
|
|
|
309
308
|
import { gcm } from "@noble/ciphers/aes.js";
|
|
310
309
|
import { analyzeForReDoS, REDOS_THRESHOLDS } from "@enclave-vm/ast";
|
|
311
310
|
import { z as z3 } from "@frontmcp/lazy-zod";
|
|
312
|
-
var
|
|
311
|
+
var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : void 0;
|
|
312
|
+
var require2 = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || "file:///") : void 0;
|
|
313
313
|
var __defProp2 = Object.defineProperty;
|
|
314
314
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
315
315
|
var __require2 = /* @__PURE__ */ ((x) => typeof require2 !== "undefined" ? require2 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -2545,6 +2545,39 @@ var init_crypto = __esm({
|
|
|
2545
2545
|
HKDF_SHA256_MAX_LENGTH = 255 * 32;
|
|
2546
2546
|
}
|
|
2547
2547
|
});
|
|
2548
|
+
function attachRedisErrorListener(client, options = {}) {
|
|
2549
|
+
const label = options.label ?? "redis";
|
|
2550
|
+
const intervalMs = options.intervalMs ?? DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS;
|
|
2551
|
+
let lastLoggedAt = 0;
|
|
2552
|
+
let suppressed = 0;
|
|
2553
|
+
const listener = (error) => {
|
|
2554
|
+
const now = Date.now();
|
|
2555
|
+
if (lastLoggedAt !== 0 && now - lastLoggedAt < intervalMs) {
|
|
2556
|
+
suppressed++;
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
const extra = suppressed > 0 ? ` (${suppressed} similar error(s) suppressed)` : "";
|
|
2560
|
+
suppressed = 0;
|
|
2561
|
+
lastLoggedAt = now;
|
|
2562
|
+
const message = `[${label}] Redis connection error: ${error?.message ?? String(error)}${extra}`;
|
|
2563
|
+
if (options.logger) {
|
|
2564
|
+
options.logger.warn(message);
|
|
2565
|
+
} else {
|
|
2566
|
+
console.warn(message);
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
client.on("error", listener);
|
|
2570
|
+
return () => {
|
|
2571
|
+
client.removeListener("error", listener);
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
var DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS;
|
|
2575
|
+
var init_redis_error_listener = __esm({
|
|
2576
|
+
"libs/utils/src/storage/redis-error-listener.ts"() {
|
|
2577
|
+
"use strict";
|
|
2578
|
+
DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS = 3e4;
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2548
2581
|
var init_utils = __esm({
|
|
2549
2582
|
"libs/utils/src/storage/utils/index.ts"() {
|
|
2550
2583
|
"use strict";
|
|
@@ -2553,7 +2586,8 @@ var init_utils = __esm({
|
|
|
2553
2586
|
});
|
|
2554
2587
|
var redis_exports = {};
|
|
2555
2588
|
__export(redis_exports, {
|
|
2556
|
-
RedisStorageAdapter: () => RedisStorageAdapter
|
|
2589
|
+
RedisStorageAdapter: () => RedisStorageAdapter,
|
|
2590
|
+
createRedisClient: () => createRedisClient
|
|
2557
2591
|
});
|
|
2558
2592
|
function getRedisClass() {
|
|
2559
2593
|
try {
|
|
@@ -2562,25 +2596,45 @@ function getRedisClass() {
|
|
|
2562
2596
|
const msg = error instanceof Error ? error.message : String(error);
|
|
2563
2597
|
if (msg.includes("Dynamic require") || msg.includes("require is not defined")) {
|
|
2564
2598
|
throw new Error(
|
|
2565
|
-
`Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode
|
|
2599
|
+
`Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`,
|
|
2600
|
+
{ cause: error }
|
|
2566
2601
|
);
|
|
2567
2602
|
}
|
|
2568
|
-
throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis"
|
|
2603
|
+
throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis", {
|
|
2604
|
+
cause: error
|
|
2605
|
+
});
|
|
2569
2606
|
}
|
|
2570
2607
|
}
|
|
2608
|
+
function createRedisClient(options) {
|
|
2609
|
+
const RedisClass = getRedisClass();
|
|
2610
|
+
const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
|
|
2611
|
+
const client = options.url ? new RedisClass(options.url, baseOptions) : new RedisClass({
|
|
2612
|
+
...baseOptions,
|
|
2613
|
+
host: options.host ?? "localhost",
|
|
2614
|
+
port: options.port ?? 6379,
|
|
2615
|
+
password: options.password,
|
|
2616
|
+
db: options.db ?? 0,
|
|
2617
|
+
tls: options.tls ? {} : void 0
|
|
2618
|
+
});
|
|
2619
|
+
attachRedisErrorListener(client, { label: options.label ?? "redis", logger: options.logger });
|
|
2620
|
+
return client;
|
|
2621
|
+
}
|
|
2571
2622
|
var RedisStorageAdapter;
|
|
2572
2623
|
var init_redis = __esm({
|
|
2573
2624
|
"libs/utils/src/storage/adapters/redis.ts"() {
|
|
2574
2625
|
"use strict";
|
|
2575
|
-
init_base();
|
|
2576
2626
|
init_errors();
|
|
2627
|
+
init_redis_error_listener();
|
|
2577
2628
|
init_utils();
|
|
2629
|
+
init_base();
|
|
2578
2630
|
RedisStorageAdapter = class extends BaseStorageAdapter {
|
|
2579
2631
|
backendName = "redis";
|
|
2580
2632
|
client;
|
|
2581
2633
|
subscriber;
|
|
2582
2634
|
options;
|
|
2583
2635
|
ownsClient;
|
|
2636
|
+
detachErrorListener;
|
|
2637
|
+
connecting;
|
|
2584
2638
|
keyPrefix;
|
|
2585
2639
|
subscriptionHandlers = /* @__PURE__ */ new Map();
|
|
2586
2640
|
constructor(options = {}) {
|
|
@@ -2610,21 +2664,45 @@ var init_redis = __esm({
|
|
|
2610
2664
|
// ============================================
|
|
2611
2665
|
async connect() {
|
|
2612
2666
|
if (this.connected) return;
|
|
2667
|
+
this.connecting ??= this.openConnection().finally(() => {
|
|
2668
|
+
this.connecting = void 0;
|
|
2669
|
+
});
|
|
2670
|
+
return this.connecting;
|
|
2671
|
+
}
|
|
2672
|
+
async openConnection() {
|
|
2673
|
+
let socketError;
|
|
2674
|
+
const recordSocketError = (error) => {
|
|
2675
|
+
socketError = error;
|
|
2676
|
+
};
|
|
2677
|
+
let client;
|
|
2613
2678
|
try {
|
|
2614
2679
|
if (this.options.client) {
|
|
2615
|
-
|
|
2680
|
+
client = this.options.client;
|
|
2616
2681
|
} else {
|
|
2617
2682
|
const RedisClass = getRedisClass();
|
|
2618
2683
|
if (this.options.url) {
|
|
2619
|
-
|
|
2684
|
+
client = new RedisClass(this.options.url, this.buildRedisOptions());
|
|
2620
2685
|
} else {
|
|
2621
|
-
|
|
2686
|
+
client = new RedisClass(this.buildRedisOptions());
|
|
2622
2687
|
}
|
|
2688
|
+
client.on("error", recordSocketError);
|
|
2623
2689
|
}
|
|
2624
|
-
await
|
|
2690
|
+
await client.ping();
|
|
2691
|
+
this.client = client;
|
|
2625
2692
|
this.connected = true;
|
|
2693
|
+
if (this.ownsClient) {
|
|
2694
|
+
client.removeListener("error", recordSocketError);
|
|
2695
|
+
this.detachErrorListener = attachRedisErrorListener(client, { label: "RedisStorage" });
|
|
2696
|
+
}
|
|
2626
2697
|
} catch (e) {
|
|
2627
|
-
|
|
2698
|
+
if (this.ownsClient && client) {
|
|
2699
|
+
try {
|
|
2700
|
+
client.disconnect();
|
|
2701
|
+
} catch {
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
const cause = socketError ?? (e instanceof Error ? e : void 0);
|
|
2705
|
+
throw new StorageConnectionError("Failed to connect to Redis", cause, "redis");
|
|
2628
2706
|
}
|
|
2629
2707
|
}
|
|
2630
2708
|
async disconnect() {
|
|
@@ -2636,6 +2714,8 @@ var init_redis = __esm({
|
|
|
2636
2714
|
if (this.ownsClient && this.client) {
|
|
2637
2715
|
await this.client.quit();
|
|
2638
2716
|
}
|
|
2717
|
+
this.detachErrorListener?.();
|
|
2718
|
+
this.detachErrorListener = void 0;
|
|
2639
2719
|
this.client = void 0;
|
|
2640
2720
|
this.connected = false;
|
|
2641
2721
|
this.subscriptionHandlers.clear();
|
|
@@ -2863,6 +2943,7 @@ var init_redis = __esm({
|
|
|
2863
2943
|
} else {
|
|
2864
2944
|
throw new StorageConfigError("redis", "Cannot create subscriber without url, config, or client");
|
|
2865
2945
|
}
|
|
2946
|
+
attachRedisErrorListener(subscriber, { label: "RedisStorage:subscriber" });
|
|
2866
2947
|
subscriber.on("message", (channel, message) => {
|
|
2867
2948
|
const handlers = this.subscriptionHandlers.get(channel);
|
|
2868
2949
|
if (handlers) {
|
|
@@ -3645,6 +3726,7 @@ var entryAvailabilitySchema = z3.object({
|
|
|
3645
3726
|
}).strict();
|
|
3646
3727
|
init_errors();
|
|
3647
3728
|
init_memory();
|
|
3729
|
+
init_redis_error_listener();
|
|
3648
3730
|
init_errors();
|
|
3649
3731
|
init_crypto();
|
|
3650
3732
|
init_errors();
|
|
@@ -3916,6 +3998,9 @@ var CachePlugin = class extends DynamicPlugin {
|
|
|
3916
3998
|
* Check if a tool should be cached based on metadata or tools list.
|
|
3917
3999
|
*/
|
|
3918
4000
|
shouldCacheTool(toolName, cacheMetadata) {
|
|
4001
|
+
if (typeof cacheMetadata === "object" && cacheMetadata.ttl !== void 0 && cacheMetadata.ttl <= 0) {
|
|
4002
|
+
return false;
|
|
4003
|
+
}
|
|
3919
4004
|
if (cacheMetadata) return true;
|
|
3920
4005
|
const patterns = this.options.toolPatterns ?? [];
|
|
3921
4006
|
return matchesToolPattern(toolName, patterns);
|
|
@@ -3970,23 +4055,9 @@ var CachePlugin = class extends DynamicPlugin {
|
|
|
3970
4055
|
await cacheStore.delete(hash);
|
|
3971
4056
|
return;
|
|
3972
4057
|
}
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
const cachedRecord = cached;
|
|
3977
|
-
const existingMeta = cachedRecord["_meta"] || {};
|
|
3978
|
-
cachedWithMeta = {
|
|
3979
|
-
...cachedRecord,
|
|
3980
|
-
_meta: {
|
|
3981
|
-
...existingMeta,
|
|
3982
|
-
cache: "hit"
|
|
3983
|
-
}
|
|
3984
|
-
};
|
|
3985
|
-
} else {
|
|
3986
|
-
cachedWithMeta = cached;
|
|
3987
|
-
}
|
|
3988
|
-
flowCtx.state.rawOutput = cachedWithMeta;
|
|
3989
|
-
toolContext.respond(cachedWithMeta);
|
|
4058
|
+
flowCtx.state.set("resultMeta", { ...flowCtx.state.resultMeta, cache: "hit" });
|
|
4059
|
+
flowCtx.state.set("rawOutput", cached);
|
|
4060
|
+
toolContext.respond(cached);
|
|
3990
4061
|
}
|
|
3991
4062
|
}
|
|
3992
4063
|
async willWriteCache(flowCtx) {
|
|
@@ -4089,7 +4160,9 @@ __publicField(CachePlugin, "dynamicProviders", (options) => {
|
|
|
4089
4160
|
providers.push({
|
|
4090
4161
|
name: "cache:memory",
|
|
4091
4162
|
provide: CacheStoreToken,
|
|
4092
|
-
|
|
4163
|
+
// Built per server: `init()` runs once, so a value here would be shared by every server using it.
|
|
4164
|
+
inject: () => [],
|
|
4165
|
+
useFactory: () => new CacheMemoryProvider(options.defaultTTL)
|
|
4093
4166
|
});
|
|
4094
4167
|
break;
|
|
4095
4168
|
}
|
|
@@ -4111,10 +4184,13 @@ CachePlugin = __decorateClass([
|
|
|
4111
4184
|
providers: [
|
|
4112
4185
|
/* add providers that always loaded with the plugin or default providers */
|
|
4113
4186
|
{
|
|
4114
|
-
// this is a default provider for cache, will be overridden if dynamicProviders based on config
|
|
4187
|
+
// this is a default provider for cache, will be overridden if dynamicProviders based on config.
|
|
4188
|
+
// A factory, so each server gets its own store: a value built here is one store for every
|
|
4189
|
+
// server in the process, created when this module loads.
|
|
4115
4190
|
name: "cache:memory",
|
|
4116
4191
|
provide: CacheStoreToken,
|
|
4117
|
-
|
|
4192
|
+
inject: () => [],
|
|
4193
|
+
useFactory: () => new CacheMemoryProvider(60 * 60 * 24)
|
|
4118
4194
|
}
|
|
4119
4195
|
]
|
|
4120
4196
|
})
|
package/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/plugin-cache",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
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.8.
|
|
52
|
-
"@frontmcp/utils": "1.8.
|
|
51
|
+
"@frontmcp/sdk": "1.8.7",
|
|
52
|
+
"@frontmcp/utils": "1.8.7",
|
|
53
53
|
"ioredis": "^5.8.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
package/index.js
CHANGED
|
@@ -296,7 +296,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
296
296
|
var import_sdk4 = require("@frontmcp/sdk");
|
|
297
297
|
|
|
298
298
|
// libs/utils/dist/esm/index.mjs
|
|
299
|
-
var import_module = require("module");
|
|
300
299
|
var import_lazy_zod = require("@frontmcp/lazy-zod");
|
|
301
300
|
var import_lazy_zod2 = require("@frontmcp/lazy-zod");
|
|
302
301
|
var import_event_emitter = __toESM(require_node_event_emitter(), 1);
|
|
@@ -310,7 +309,8 @@ var import_crypto_provider = __toESM(require_node(), 1);
|
|
|
310
309
|
var import_ast = require("@enclave-vm/ast");
|
|
311
310
|
var import_lazy_zod3 = require("@frontmcp/lazy-zod");
|
|
312
311
|
var import_meta = {};
|
|
313
|
-
var
|
|
312
|
+
var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : void 0;
|
|
313
|
+
var require2 = __frontmcpModule ? __frontmcpModule.createRequire(import_meta.url || "file:///") : void 0;
|
|
314
314
|
var __defProp2 = Object.defineProperty;
|
|
315
315
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
316
316
|
var __require = /* @__PURE__ */ ((x) => typeof require2 !== "undefined" ? require2 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -2546,6 +2546,39 @@ var init_crypto = __esm({
|
|
|
2546
2546
|
HKDF_SHA256_MAX_LENGTH = 255 * 32;
|
|
2547
2547
|
}
|
|
2548
2548
|
});
|
|
2549
|
+
function attachRedisErrorListener(client, options = {}) {
|
|
2550
|
+
const label = options.label ?? "redis";
|
|
2551
|
+
const intervalMs = options.intervalMs ?? DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS;
|
|
2552
|
+
let lastLoggedAt = 0;
|
|
2553
|
+
let suppressed = 0;
|
|
2554
|
+
const listener = (error) => {
|
|
2555
|
+
const now = Date.now();
|
|
2556
|
+
if (lastLoggedAt !== 0 && now - lastLoggedAt < intervalMs) {
|
|
2557
|
+
suppressed++;
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
const extra = suppressed > 0 ? ` (${suppressed} similar error(s) suppressed)` : "";
|
|
2561
|
+
suppressed = 0;
|
|
2562
|
+
lastLoggedAt = now;
|
|
2563
|
+
const message = `[${label}] Redis connection error: ${error?.message ?? String(error)}${extra}`;
|
|
2564
|
+
if (options.logger) {
|
|
2565
|
+
options.logger.warn(message);
|
|
2566
|
+
} else {
|
|
2567
|
+
console.warn(message);
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
client.on("error", listener);
|
|
2571
|
+
return () => {
|
|
2572
|
+
client.removeListener("error", listener);
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
var DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS;
|
|
2576
|
+
var init_redis_error_listener = __esm({
|
|
2577
|
+
"libs/utils/src/storage/redis-error-listener.ts"() {
|
|
2578
|
+
"use strict";
|
|
2579
|
+
DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS = 3e4;
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2549
2582
|
var init_utils = __esm({
|
|
2550
2583
|
"libs/utils/src/storage/utils/index.ts"() {
|
|
2551
2584
|
"use strict";
|
|
@@ -2554,7 +2587,8 @@ var init_utils = __esm({
|
|
|
2554
2587
|
});
|
|
2555
2588
|
var redis_exports = {};
|
|
2556
2589
|
__export2(redis_exports, {
|
|
2557
|
-
RedisStorageAdapter: () => RedisStorageAdapter
|
|
2590
|
+
RedisStorageAdapter: () => RedisStorageAdapter,
|
|
2591
|
+
createRedisClient: () => createRedisClient
|
|
2558
2592
|
});
|
|
2559
2593
|
function getRedisClass() {
|
|
2560
2594
|
try {
|
|
@@ -2563,25 +2597,45 @@ function getRedisClass() {
|
|
|
2563
2597
|
const msg = error instanceof Error ? error.message : String(error);
|
|
2564
2598
|
if (msg.includes("Dynamic require") || msg.includes("require is not defined")) {
|
|
2565
2599
|
throw new Error(
|
|
2566
|
-
`Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode
|
|
2600
|
+
`Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`,
|
|
2601
|
+
{ cause: error }
|
|
2567
2602
|
);
|
|
2568
2603
|
}
|
|
2569
|
-
throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis"
|
|
2604
|
+
throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis", {
|
|
2605
|
+
cause: error
|
|
2606
|
+
});
|
|
2570
2607
|
}
|
|
2571
2608
|
}
|
|
2609
|
+
function createRedisClient(options) {
|
|
2610
|
+
const RedisClass = getRedisClass();
|
|
2611
|
+
const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
|
|
2612
|
+
const client = options.url ? new RedisClass(options.url, baseOptions) : new RedisClass({
|
|
2613
|
+
...baseOptions,
|
|
2614
|
+
host: options.host ?? "localhost",
|
|
2615
|
+
port: options.port ?? 6379,
|
|
2616
|
+
password: options.password,
|
|
2617
|
+
db: options.db ?? 0,
|
|
2618
|
+
tls: options.tls ? {} : void 0
|
|
2619
|
+
});
|
|
2620
|
+
attachRedisErrorListener(client, { label: options.label ?? "redis", logger: options.logger });
|
|
2621
|
+
return client;
|
|
2622
|
+
}
|
|
2572
2623
|
var RedisStorageAdapter;
|
|
2573
2624
|
var init_redis = __esm({
|
|
2574
2625
|
"libs/utils/src/storage/adapters/redis.ts"() {
|
|
2575
2626
|
"use strict";
|
|
2576
|
-
init_base();
|
|
2577
2627
|
init_errors();
|
|
2628
|
+
init_redis_error_listener();
|
|
2578
2629
|
init_utils();
|
|
2630
|
+
init_base();
|
|
2579
2631
|
RedisStorageAdapter = class extends BaseStorageAdapter {
|
|
2580
2632
|
backendName = "redis";
|
|
2581
2633
|
client;
|
|
2582
2634
|
subscriber;
|
|
2583
2635
|
options;
|
|
2584
2636
|
ownsClient;
|
|
2637
|
+
detachErrorListener;
|
|
2638
|
+
connecting;
|
|
2585
2639
|
keyPrefix;
|
|
2586
2640
|
subscriptionHandlers = /* @__PURE__ */ new Map();
|
|
2587
2641
|
constructor(options = {}) {
|
|
@@ -2611,21 +2665,45 @@ var init_redis = __esm({
|
|
|
2611
2665
|
// ============================================
|
|
2612
2666
|
async connect() {
|
|
2613
2667
|
if (this.connected) return;
|
|
2668
|
+
this.connecting ??= this.openConnection().finally(() => {
|
|
2669
|
+
this.connecting = void 0;
|
|
2670
|
+
});
|
|
2671
|
+
return this.connecting;
|
|
2672
|
+
}
|
|
2673
|
+
async openConnection() {
|
|
2674
|
+
let socketError;
|
|
2675
|
+
const recordSocketError = (error) => {
|
|
2676
|
+
socketError = error;
|
|
2677
|
+
};
|
|
2678
|
+
let client;
|
|
2614
2679
|
try {
|
|
2615
2680
|
if (this.options.client) {
|
|
2616
|
-
|
|
2681
|
+
client = this.options.client;
|
|
2617
2682
|
} else {
|
|
2618
2683
|
const RedisClass = getRedisClass();
|
|
2619
2684
|
if (this.options.url) {
|
|
2620
|
-
|
|
2685
|
+
client = new RedisClass(this.options.url, this.buildRedisOptions());
|
|
2621
2686
|
} else {
|
|
2622
|
-
|
|
2687
|
+
client = new RedisClass(this.buildRedisOptions());
|
|
2623
2688
|
}
|
|
2689
|
+
client.on("error", recordSocketError);
|
|
2624
2690
|
}
|
|
2625
|
-
await
|
|
2691
|
+
await client.ping();
|
|
2692
|
+
this.client = client;
|
|
2626
2693
|
this.connected = true;
|
|
2694
|
+
if (this.ownsClient) {
|
|
2695
|
+
client.removeListener("error", recordSocketError);
|
|
2696
|
+
this.detachErrorListener = attachRedisErrorListener(client, { label: "RedisStorage" });
|
|
2697
|
+
}
|
|
2627
2698
|
} catch (e) {
|
|
2628
|
-
|
|
2699
|
+
if (this.ownsClient && client) {
|
|
2700
|
+
try {
|
|
2701
|
+
client.disconnect();
|
|
2702
|
+
} catch {
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
const cause = socketError ?? (e instanceof Error ? e : void 0);
|
|
2706
|
+
throw new StorageConnectionError("Failed to connect to Redis", cause, "redis");
|
|
2629
2707
|
}
|
|
2630
2708
|
}
|
|
2631
2709
|
async disconnect() {
|
|
@@ -2637,6 +2715,8 @@ var init_redis = __esm({
|
|
|
2637
2715
|
if (this.ownsClient && this.client) {
|
|
2638
2716
|
await this.client.quit();
|
|
2639
2717
|
}
|
|
2718
|
+
this.detachErrorListener?.();
|
|
2719
|
+
this.detachErrorListener = void 0;
|
|
2640
2720
|
this.client = void 0;
|
|
2641
2721
|
this.connected = false;
|
|
2642
2722
|
this.subscriptionHandlers.clear();
|
|
@@ -2864,6 +2944,7 @@ var init_redis = __esm({
|
|
|
2864
2944
|
} else {
|
|
2865
2945
|
throw new StorageConfigError("redis", "Cannot create subscriber without url, config, or client");
|
|
2866
2946
|
}
|
|
2947
|
+
attachRedisErrorListener(subscriber, { label: "RedisStorage:subscriber" });
|
|
2867
2948
|
subscriber.on("message", (channel, message) => {
|
|
2868
2949
|
const handlers = this.subscriptionHandlers.get(channel);
|
|
2869
2950
|
if (handlers) {
|
|
@@ -3646,6 +3727,7 @@ var entryAvailabilitySchema = import_lazy_zod3.z.object({
|
|
|
3646
3727
|
}).strict();
|
|
3647
3728
|
init_errors();
|
|
3648
3729
|
init_memory();
|
|
3730
|
+
init_redis_error_listener();
|
|
3649
3731
|
init_errors();
|
|
3650
3732
|
init_crypto();
|
|
3651
3733
|
init_errors();
|
|
@@ -3917,6 +3999,9 @@ var CachePlugin = class extends import_sdk4.DynamicPlugin {
|
|
|
3917
3999
|
* Check if a tool should be cached based on metadata or tools list.
|
|
3918
4000
|
*/
|
|
3919
4001
|
shouldCacheTool(toolName, cacheMetadata) {
|
|
4002
|
+
if (typeof cacheMetadata === "object" && cacheMetadata.ttl !== void 0 && cacheMetadata.ttl <= 0) {
|
|
4003
|
+
return false;
|
|
4004
|
+
}
|
|
3920
4005
|
if (cacheMetadata) return true;
|
|
3921
4006
|
const patterns = this.options.toolPatterns ?? [];
|
|
3922
4007
|
return matchesToolPattern(toolName, patterns);
|
|
@@ -3971,23 +4056,9 @@ var CachePlugin = class extends import_sdk4.DynamicPlugin {
|
|
|
3971
4056
|
await cacheStore.delete(hash);
|
|
3972
4057
|
return;
|
|
3973
4058
|
}
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
const cachedRecord = cached;
|
|
3978
|
-
const existingMeta = cachedRecord["_meta"] || {};
|
|
3979
|
-
cachedWithMeta = {
|
|
3980
|
-
...cachedRecord,
|
|
3981
|
-
_meta: {
|
|
3982
|
-
...existingMeta,
|
|
3983
|
-
cache: "hit"
|
|
3984
|
-
}
|
|
3985
|
-
};
|
|
3986
|
-
} else {
|
|
3987
|
-
cachedWithMeta = cached;
|
|
3988
|
-
}
|
|
3989
|
-
flowCtx.state.rawOutput = cachedWithMeta;
|
|
3990
|
-
toolContext.respond(cachedWithMeta);
|
|
4059
|
+
flowCtx.state.set("resultMeta", { ...flowCtx.state.resultMeta, cache: "hit" });
|
|
4060
|
+
flowCtx.state.set("rawOutput", cached);
|
|
4061
|
+
toolContext.respond(cached);
|
|
3991
4062
|
}
|
|
3992
4063
|
}
|
|
3993
4064
|
async willWriteCache(flowCtx) {
|
|
@@ -4090,7 +4161,9 @@ __publicField(CachePlugin, "dynamicProviders", (options) => {
|
|
|
4090
4161
|
providers.push({
|
|
4091
4162
|
name: "cache:memory",
|
|
4092
4163
|
provide: CacheStoreToken,
|
|
4093
|
-
|
|
4164
|
+
// Built per server: `init()` runs once, so a value here would be shared by every server using it.
|
|
4165
|
+
inject: () => [],
|
|
4166
|
+
useFactory: () => new CacheMemoryProvider(options.defaultTTL)
|
|
4094
4167
|
});
|
|
4095
4168
|
break;
|
|
4096
4169
|
}
|
|
@@ -4112,10 +4185,13 @@ CachePlugin = __decorateClass([
|
|
|
4112
4185
|
providers: [
|
|
4113
4186
|
/* add providers that always loaded with the plugin or default providers */
|
|
4114
4187
|
{
|
|
4115
|
-
// this is a default provider for cache, will be overridden if dynamicProviders based on config
|
|
4188
|
+
// this is a default provider for cache, will be overridden if dynamicProviders based on config.
|
|
4189
|
+
// A factory, so each server gets its own store: a value built here is one store for every
|
|
4190
|
+
// server in the process, created when this module loads.
|
|
4116
4191
|
name: "cache:memory",
|
|
4117
4192
|
provide: CacheStoreToken,
|
|
4118
|
-
|
|
4193
|
+
inject: () => [],
|
|
4194
|
+
useFactory: () => new CacheMemoryProvider(60 * 60 * 24)
|
|
4119
4195
|
}
|
|
4120
4196
|
]
|
|
4121
4197
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/plugin-cache",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
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.8.
|
|
52
|
-
"@frontmcp/utils": "1.8.
|
|
51
|
+
"@frontmcp/sdk": "1.8.7",
|
|
52
|
+
"@frontmcp/utils": "1.8.7",
|
|
53
53
|
"ioredis": "^5.8.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|