@frontmcp/plugins 0.6.0 → 0.6.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/{src/cache → cache}/cache.types.d.ts +26 -3
- package/cache/index.js +412 -0
- package/{src/cache → cache}/providers/cache-memory.provider.d.ts +3 -3
- package/{src/cache → cache}/providers/cache-redis.provider.d.ts +3 -3
- package/cache/providers/cache-vercel-kv.provider.d.ts +24 -0
- package/codecall/index.js +2988 -0
- package/{src/codecall → codecall}/tools/invoke.schema.d.ts +6 -1
- package/esm/cache/index.mjs +395 -0
- package/esm/codecall/index.mjs +2959 -0
- package/esm/index.mjs +2951 -0
- package/esm/package.json +85 -0
- package/index.js +2973 -0
- package/package.json +49 -10
- package/src/cache/README.md +0 -186
- package/src/cache/cache.plugin.js +0 -135
- package/src/cache/cache.plugin.js.map +0 -1
- package/src/cache/cache.symbol.js +0 -5
- package/src/cache/cache.symbol.js.map +0 -1
- package/src/cache/cache.types.js +0 -3
- package/src/cache/cache.types.js.map +0 -1
- package/src/cache/index.js +0 -8
- package/src/cache/index.js.map +0 -1
- package/src/cache/providers/cache-memory.provider.js +0 -110
- package/src/cache/providers/cache-memory.provider.js.map +0 -1
- package/src/cache/providers/cache-redis.provider.js +0 -69
- package/src/cache/providers/cache-redis.provider.js.map +0 -1
- package/src/codecall/README.md +0 -999
- package/src/codecall/codecall.plugin.js +0 -152
- package/src/codecall/codecall.plugin.js.map +0 -1
- package/src/codecall/codecall.symbol.js +0 -4
- package/src/codecall/codecall.symbol.js.map +0 -1
- package/src/codecall/codecall.types.js +0 -262
- package/src/codecall/codecall.types.js.map +0 -1
- package/src/codecall/errors/index.js +0 -6
- package/src/codecall/errors/index.js.map +0 -1
- package/src/codecall/errors/tool-call.errors.js +0 -119
- package/src/codecall/errors/tool-call.errors.js.map +0 -1
- package/src/codecall/index.js +0 -8
- package/src/codecall/index.js.map +0 -1
- package/src/codecall/providers/code-call.config.js +0 -120
- package/src/codecall/providers/code-call.config.js.map +0 -1
- package/src/codecall/security/index.js +0 -7
- package/src/codecall/security/index.js.map +0 -1
- package/src/codecall/security/self-reference-guard.js +0 -70
- package/src/codecall/security/self-reference-guard.js.map +0 -1
- package/src/codecall/security/tool-access-control.service.js +0 -170
- package/src/codecall/security/tool-access-control.service.js.map +0 -1
- package/src/codecall/services/audit-logger.service.js +0 -322
- package/src/codecall/services/audit-logger.service.js.map +0 -1
- package/src/codecall/services/enclave.service.js +0 -214
- package/src/codecall/services/enclave.service.js.map +0 -1
- package/src/codecall/services/error-enrichment.service.js +0 -387
- package/src/codecall/services/error-enrichment.service.js.map +0 -1
- package/src/codecall/services/index.js +0 -13
- package/src/codecall/services/index.js.map +0 -1
- package/src/codecall/services/output-sanitizer.js +0 -260
- package/src/codecall/services/output-sanitizer.js.map +0 -1
- package/src/codecall/services/synonym-expansion.service.js +0 -374
- package/src/codecall/services/synonym-expansion.service.js.map +0 -1
- package/src/codecall/services/tool-search.service.js +0 -587
- package/src/codecall/services/tool-search.service.js.map +0 -1
- package/src/codecall/tools/describe.schema.js +0 -67
- package/src/codecall/tools/describe.schema.js.map +0 -1
- package/src/codecall/tools/describe.tool.js +0 -207
- package/src/codecall/tools/describe.tool.js.map +0 -1
- package/src/codecall/tools/execute.schema.js +0 -116
- package/src/codecall/tools/execute.schema.js.map +0 -1
- package/src/codecall/tools/execute.tool.js +0 -238
- package/src/codecall/tools/execute.tool.js.map +0 -1
- package/src/codecall/tools/index.js +0 -13
- package/src/codecall/tools/index.js.map +0 -1
- package/src/codecall/tools/invoke.schema.js +0 -27
- package/src/codecall/tools/invoke.schema.js.map +0 -1
- package/src/codecall/tools/invoke.tool.js +0 -70
- package/src/codecall/tools/invoke.tool.js.map +0 -1
- package/src/codecall/tools/search.schema.js +0 -60
- package/src/codecall/tools/search.schema.js.map +0 -1
- package/src/codecall/tools/search.tool.js +0 -108
- package/src/codecall/tools/search.tool.js.map +0 -1
- package/src/codecall/utils/describe.utils.js +0 -531
- package/src/codecall/utils/describe.utils.js.map +0 -1
- package/src/codecall/utils/index.js +0 -7
- package/src/codecall/utils/index.js.map +0 -1
- package/src/codecall/utils/mcp-result.js +0 -36
- package/src/codecall/utils/mcp-result.js.map +0 -1
- package/src/index.js +0 -9
- package/src/index.js.map +0 -1
- /package/{src/cache → cache}/cache.plugin.d.ts +0 -0
- /package/{src/cache → cache}/cache.symbol.d.ts +0 -0
- /package/{src/cache → cache}/index.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.plugin.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.symbol.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.types.d.ts +0 -0
- /package/{src/codecall → codecall}/errors/index.d.ts +0 -0
- /package/{src/codecall → codecall}/errors/tool-call.errors.d.ts +0 -0
- /package/{src/codecall → codecall}/index.d.ts +0 -0
- /package/{src/codecall → codecall}/providers/code-call.config.d.ts +0 -0
- /package/{src/codecall → codecall}/security/index.d.ts +0 -0
- /package/{src/codecall → codecall}/security/self-reference-guard.d.ts +0 -0
- /package/{src/codecall → codecall}/security/tool-access-control.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/audit-logger.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/enclave.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/error-enrichment.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/index.d.ts +0 -0
- /package/{src/codecall → codecall}/services/output-sanitizer.d.ts +0 -0
- /package/{src/codecall → codecall}/services/synonym-expansion.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/tool-search.service.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/describe.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/describe.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/execute.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/execute.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/index.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/invoke.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/search.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/search.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/describe.utils.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/index.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/mcp-result.d.ts +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
|
@@ -34,11 +34,34 @@ export interface RedisCachePluginOptions extends BaseCachePluginOptions {
|
|
|
34
34
|
export type MemoryCachePluginOptions = BaseCachePluginOptions & {
|
|
35
35
|
type: 'memory';
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Use global store configuration from @FrontMcp decorator.
|
|
39
|
+
* Requires `redis` to be configured in the main FrontMcp options.
|
|
40
|
+
* Supports both Redis and Vercel KV global configurations.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // In main.ts - configure global store
|
|
45
|
+
* @FrontMcp({
|
|
46
|
+
* redis: { host: 'localhost', port: 6379 },
|
|
47
|
+
* apps: [MyApp]
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* // In app - use global store
|
|
51
|
+
* @App({
|
|
52
|
+
* plugins: [CachePlugin.init({ type: 'global-store' })]
|
|
53
|
+
* })
|
|
54
|
+
* class MyApp {}
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface GlobalStoreCachePluginOptions extends BaseCachePluginOptions {
|
|
58
|
+
type: 'global-store';
|
|
59
|
+
}
|
|
37
60
|
export type RedisCacheOptions = RedisClientCachePluginOptions | RedisCachePluginOptions;
|
|
38
|
-
export type CachePluginOptions = MemoryCachePluginOptions | RedisCacheOptions;
|
|
61
|
+
export type CachePluginOptions = MemoryCachePluginOptions | RedisCacheOptions | GlobalStoreCachePluginOptions;
|
|
39
62
|
export interface CacheStoreInterface {
|
|
40
|
-
setValue(key: string, value:
|
|
41
|
-
getValue<T =
|
|
63
|
+
setValue(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
|
|
64
|
+
getValue<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
42
65
|
delete(key: string): Promise<void>;
|
|
43
66
|
exists(key: string): Promise<boolean>;
|
|
44
67
|
close(): Promise<void>;
|
package/cache/index.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
31
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
32
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
33
|
+
if (decorator = decorators[i])
|
|
34
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
35
|
+
if (kind && result) __defProp(target, key, result);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
39
|
+
|
|
40
|
+
// libs/plugins/src/cache/index.ts
|
|
41
|
+
var cache_exports = {};
|
|
42
|
+
__export(cache_exports, {
|
|
43
|
+
default: () => CachePlugin
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(cache_exports);
|
|
46
|
+
|
|
47
|
+
// libs/plugins/src/cache/cache.plugin.ts
|
|
48
|
+
var import_sdk4 = require("@frontmcp/sdk");
|
|
49
|
+
|
|
50
|
+
// libs/plugins/src/cache/providers/cache-redis.provider.ts
|
|
51
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
52
|
+
var import_sdk = require("@frontmcp/sdk");
|
|
53
|
+
var CacheRedisProvider = class {
|
|
54
|
+
client;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
if (options.type !== "redis" && options.type !== "redis-client") {
|
|
57
|
+
throw new Error("Invalid cache provider type");
|
|
58
|
+
}
|
|
59
|
+
if (options.type === "redis-client") {
|
|
60
|
+
this.client = options.client;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.client = new import_ioredis.default({
|
|
64
|
+
lazyConnect: false,
|
|
65
|
+
maxRetriesPerRequest: 3,
|
|
66
|
+
...options.config
|
|
67
|
+
});
|
|
68
|
+
this.client.on("connect", () => console.log("[Redis] Connected"));
|
|
69
|
+
this.client.on("error", (err) => console.error("[Redis] Error:", err));
|
|
70
|
+
}
|
|
71
|
+
/** Set a value (auto-stringifies objects) */
|
|
72
|
+
async setValue(key, value, ttlSeconds) {
|
|
73
|
+
const strValue = typeof value === "string" ? value : JSON.stringify(value);
|
|
74
|
+
if (ttlSeconds && ttlSeconds > 0) {
|
|
75
|
+
await this.client.set(key, strValue, "EX", ttlSeconds);
|
|
76
|
+
} else {
|
|
77
|
+
await this.client.set(key, strValue);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Get a value and automatically parse JSON if possible */
|
|
81
|
+
async getValue(key, defaultValue) {
|
|
82
|
+
const raw = await this.client.get(key);
|
|
83
|
+
if (raw === null) return defaultValue;
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(raw);
|
|
86
|
+
} catch {
|
|
87
|
+
return raw;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Delete a key */
|
|
91
|
+
async delete(key) {
|
|
92
|
+
await this.client.del(key);
|
|
93
|
+
}
|
|
94
|
+
/** Check if a key exists */
|
|
95
|
+
async exists(key) {
|
|
96
|
+
return await this.client.exists(key) === 1;
|
|
97
|
+
}
|
|
98
|
+
/** Gracefully close the Redis connection */
|
|
99
|
+
async close() {
|
|
100
|
+
await this.client.quit();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
CacheRedisProvider = __decorateClass([
|
|
104
|
+
(0, import_sdk.Provider)({
|
|
105
|
+
name: "provider:cache:redis",
|
|
106
|
+
description: "Redis-based cache provider",
|
|
107
|
+
scope: import_sdk.ProviderScope.GLOBAL
|
|
108
|
+
})
|
|
109
|
+
], CacheRedisProvider);
|
|
110
|
+
|
|
111
|
+
// libs/plugins/src/cache/providers/cache-memory.provider.ts
|
|
112
|
+
var import_sdk2 = require("@frontmcp/sdk");
|
|
113
|
+
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
114
|
+
var CacheMemoryProvider = class {
|
|
115
|
+
memory = /* @__PURE__ */ new Map();
|
|
116
|
+
sweeper;
|
|
117
|
+
constructor(sweepIntervalTTL = 60) {
|
|
118
|
+
this.sweeper = setInterval(() => this.sweep(), sweepIntervalTTL * 1e3);
|
|
119
|
+
this.sweeper.unref?.();
|
|
120
|
+
}
|
|
121
|
+
/** Set a value (auto-stringifies objects) */
|
|
122
|
+
async setValue(key, value, ttlSeconds) {
|
|
123
|
+
const strValue = typeof value === "string" ? value : JSON.stringify(value);
|
|
124
|
+
const existing = this.memory.get(key);
|
|
125
|
+
if (existing?.timeout) clearTimeout(existing.timeout);
|
|
126
|
+
const entry = { value: strValue };
|
|
127
|
+
if (ttlSeconds && ttlSeconds > 0) {
|
|
128
|
+
const ttlMs = ttlSeconds * 1e3;
|
|
129
|
+
entry.expiresAt = Date.now() + ttlMs;
|
|
130
|
+
if (ttlMs <= MAX_TIMEOUT_MS) {
|
|
131
|
+
entry.timeout = setTimeout(() => {
|
|
132
|
+
const e = this.memory.get(key);
|
|
133
|
+
if (e && e.expiresAt && e.expiresAt <= Date.now()) {
|
|
134
|
+
this.memory.delete(key);
|
|
135
|
+
}
|
|
136
|
+
}, ttlMs);
|
|
137
|
+
entry.timeout.unref?.();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.memory.set(key, entry);
|
|
141
|
+
}
|
|
142
|
+
/** Get a value and automatically parse JSON if possible */
|
|
143
|
+
async getValue(key, defaultValue) {
|
|
144
|
+
const entry = this.memory.get(key);
|
|
145
|
+
if (!entry) return defaultValue;
|
|
146
|
+
if (this.isExpired(entry)) {
|
|
147
|
+
await this.delete(key);
|
|
148
|
+
return defaultValue;
|
|
149
|
+
}
|
|
150
|
+
const raw = entry.value;
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(raw);
|
|
153
|
+
} catch {
|
|
154
|
+
return raw;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Delete a key */
|
|
158
|
+
async delete(key) {
|
|
159
|
+
const entry = this.memory.get(key);
|
|
160
|
+
if (entry?.timeout) clearTimeout(entry.timeout);
|
|
161
|
+
this.memory.delete(key);
|
|
162
|
+
}
|
|
163
|
+
/** Check if a key exists (and not expired) */
|
|
164
|
+
async exists(key) {
|
|
165
|
+
const entry = this.memory.get(key);
|
|
166
|
+
if (!entry) return false;
|
|
167
|
+
if (this.isExpired(entry)) {
|
|
168
|
+
await this.delete(key);
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
/** Gracefully close the provider */
|
|
174
|
+
async close() {
|
|
175
|
+
if (this.sweeper) clearInterval(this.sweeper);
|
|
176
|
+
for (const [, entry] of this.memory) {
|
|
177
|
+
if (entry.timeout) clearTimeout(entry.timeout);
|
|
178
|
+
}
|
|
179
|
+
this.memory.clear();
|
|
180
|
+
}
|
|
181
|
+
// ---- internals ----
|
|
182
|
+
isExpired(entry) {
|
|
183
|
+
return entry.expiresAt !== void 0 && entry.expiresAt <= Date.now();
|
|
184
|
+
}
|
|
185
|
+
/** Periodically remove expired keys to keep memory tidy */
|
|
186
|
+
sweep() {
|
|
187
|
+
const now = Date.now();
|
|
188
|
+
for (const [key, entry] of this.memory) {
|
|
189
|
+
if (entry.expiresAt !== void 0 && entry.expiresAt <= now) {
|
|
190
|
+
if (entry.timeout) clearTimeout(entry.timeout);
|
|
191
|
+
this.memory.delete(key);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
CacheMemoryProvider = __decorateClass([
|
|
197
|
+
(0, import_sdk2.Provider)({
|
|
198
|
+
name: "provider:cache:memory",
|
|
199
|
+
description: "Memory-based cache provider",
|
|
200
|
+
scope: import_sdk2.ProviderScope.GLOBAL
|
|
201
|
+
})
|
|
202
|
+
], CacheMemoryProvider);
|
|
203
|
+
|
|
204
|
+
// libs/plugins/src/cache/providers/cache-vercel-kv.provider.ts
|
|
205
|
+
var import_sdk3 = require("@frontmcp/sdk");
|
|
206
|
+
var CacheVercelKvProvider = class {
|
|
207
|
+
kv;
|
|
208
|
+
keyPrefix;
|
|
209
|
+
defaultTTL;
|
|
210
|
+
constructor(options = {}) {
|
|
211
|
+
const vercelKv = require("@vercel/kv");
|
|
212
|
+
const hasUrl = options.url !== void 0;
|
|
213
|
+
const hasToken = options.token !== void 0;
|
|
214
|
+
if (hasUrl !== hasToken) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`CacheVercelKvProvider: Both 'url' and 'token' must be provided together, or neither. Received: url=${hasUrl ? "provided" : "missing"}, token=${hasToken ? "provided" : "missing"}`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
if (options.url && options.token) {
|
|
220
|
+
this.kv = vercelKv.createClient({
|
|
221
|
+
url: options.url,
|
|
222
|
+
token: options.token
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
this.kv = vercelKv.kv;
|
|
226
|
+
}
|
|
227
|
+
this.keyPrefix = options.keyPrefix ?? "cache:";
|
|
228
|
+
this.defaultTTL = options.defaultTTL ?? 60 * 60 * 24;
|
|
229
|
+
}
|
|
230
|
+
prefixKey(key) {
|
|
231
|
+
return `${this.keyPrefix}${key}`;
|
|
232
|
+
}
|
|
233
|
+
/** Set a value (auto-stringifies objects) */
|
|
234
|
+
async setValue(key, value, ttlSeconds) {
|
|
235
|
+
const strValue = typeof value === "string" ? value : JSON.stringify(value);
|
|
236
|
+
const ttl = ttlSeconds ?? this.defaultTTL;
|
|
237
|
+
if (ttl > 0) {
|
|
238
|
+
await this.kv.set(this.prefixKey(key), strValue, { ex: ttl });
|
|
239
|
+
} else {
|
|
240
|
+
await this.kv.set(this.prefixKey(key), strValue);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** Get a value and automatically parse JSON if possible */
|
|
244
|
+
async getValue(key, defaultValue) {
|
|
245
|
+
const raw = await this.kv.get(this.prefixKey(key));
|
|
246
|
+
if (raw === null || raw === void 0) return defaultValue;
|
|
247
|
+
if (typeof raw === "string") {
|
|
248
|
+
try {
|
|
249
|
+
return JSON.parse(raw);
|
|
250
|
+
} catch {
|
|
251
|
+
return raw;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return raw;
|
|
255
|
+
}
|
|
256
|
+
/** Delete a key */
|
|
257
|
+
async delete(key) {
|
|
258
|
+
await this.kv.del(this.prefixKey(key));
|
|
259
|
+
}
|
|
260
|
+
/** Check if a key exists */
|
|
261
|
+
async exists(key) {
|
|
262
|
+
return await this.kv.exists(this.prefixKey(key)) === 1;
|
|
263
|
+
}
|
|
264
|
+
/** Gracefully close the provider (no-op for Vercel KV - stateless REST API) */
|
|
265
|
+
async close() {
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
CacheVercelKvProvider = __decorateClass([
|
|
269
|
+
(0, import_sdk3.Provider)({
|
|
270
|
+
name: "provider:cache:vercel-kv",
|
|
271
|
+
description: "Vercel KV-based cache provider",
|
|
272
|
+
scope: import_sdk3.ProviderScope.GLOBAL
|
|
273
|
+
})
|
|
274
|
+
], CacheVercelKvProvider);
|
|
275
|
+
|
|
276
|
+
// libs/plugins/src/cache/cache.symbol.ts
|
|
277
|
+
var CacheStoreToken = /* @__PURE__ */ Symbol("plugin:cache:store");
|
|
278
|
+
|
|
279
|
+
// libs/plugins/src/cache/cache.plugin.ts
|
|
280
|
+
var CachePlugin = class extends import_sdk4.DynamicPlugin {
|
|
281
|
+
options;
|
|
282
|
+
constructor(options = CachePlugin.defaultOptions) {
|
|
283
|
+
super();
|
|
284
|
+
this.options = {
|
|
285
|
+
defaultTTL: 60 * 60 * 24,
|
|
286
|
+
...options
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async willReadCache(flowCtx) {
|
|
290
|
+
const { tool, toolContext } = flowCtx.state;
|
|
291
|
+
if (!tool || !toolContext) return;
|
|
292
|
+
const { cache } = toolContext.metadata;
|
|
293
|
+
if (!cache || typeof toolContext.input === "undefined") {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const cacheStore = this.get(CacheStoreToken);
|
|
297
|
+
const hash = hashObject({ tool: tool.fullName, input: toolContext.input });
|
|
298
|
+
const cached = await cacheStore.getValue(hash);
|
|
299
|
+
if (cached !== void 0 && cached !== null) {
|
|
300
|
+
if (cache === true || cache.ttl && cache.slideWindow) {
|
|
301
|
+
const ttl = cache === true ? this.options.defaultTTL : cache.ttl ?? this.options.defaultTTL;
|
|
302
|
+
await cacheStore.setValue(hash, cached, ttl);
|
|
303
|
+
}
|
|
304
|
+
if (!tool.safeParseOutput(cached).success) {
|
|
305
|
+
await cacheStore.delete(hash);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
flowCtx.state.rawOutput = cached;
|
|
309
|
+
toolContext.respond(cached);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async willWriteCache(flowCtx) {
|
|
313
|
+
const { tool, toolContext } = flowCtx.state;
|
|
314
|
+
if (!tool || !toolContext) return;
|
|
315
|
+
const { cache } = toolContext.metadata;
|
|
316
|
+
if (!cache || typeof toolContext.input === "undefined") {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const cacheStore = this.get(CacheStoreToken);
|
|
320
|
+
const ttl = cache === true ? this.options.defaultTTL : cache.ttl ?? this.options.defaultTTL;
|
|
321
|
+
const hash = hashObject({ tool: tool.fullName, input: toolContext.input });
|
|
322
|
+
await cacheStore.setValue(hash, toolContext.output, ttl);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
__publicField(CachePlugin, "dynamicProviders", (options) => {
|
|
326
|
+
const providers = [];
|
|
327
|
+
switch (options.type) {
|
|
328
|
+
case "global-store":
|
|
329
|
+
providers.push({
|
|
330
|
+
name: "cache:global-store",
|
|
331
|
+
provide: CacheStoreToken,
|
|
332
|
+
inject: () => [import_sdk4.FrontMcpConfig],
|
|
333
|
+
useFactory: (config) => {
|
|
334
|
+
const storeConfig = (0, import_sdk4.getGlobalStoreConfig)("CachePlugin", config);
|
|
335
|
+
const globalOptions = options;
|
|
336
|
+
if ((0, import_sdk4.isVercelKvProvider)(storeConfig)) {
|
|
337
|
+
return new CacheVercelKvProvider({
|
|
338
|
+
url: storeConfig.url,
|
|
339
|
+
token: storeConfig.token,
|
|
340
|
+
keyPrefix: storeConfig.keyPrefix,
|
|
341
|
+
defaultTTL: globalOptions.defaultTTL
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return new CacheRedisProvider({
|
|
345
|
+
type: "redis",
|
|
346
|
+
config: {
|
|
347
|
+
host: storeConfig.host ?? "localhost",
|
|
348
|
+
port: storeConfig.port ?? 6379,
|
|
349
|
+
password: storeConfig.password,
|
|
350
|
+
db: storeConfig.db
|
|
351
|
+
},
|
|
352
|
+
defaultTTL: globalOptions.defaultTTL
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
break;
|
|
357
|
+
case "redis":
|
|
358
|
+
case "redis-client":
|
|
359
|
+
providers.push({
|
|
360
|
+
name: "cache:redis",
|
|
361
|
+
provide: CacheStoreToken,
|
|
362
|
+
useValue: new CacheRedisProvider(options)
|
|
363
|
+
});
|
|
364
|
+
break;
|
|
365
|
+
case "memory":
|
|
366
|
+
providers.push({
|
|
367
|
+
name: "cache:memory",
|
|
368
|
+
provide: CacheStoreToken,
|
|
369
|
+
useValue: new CacheMemoryProvider(options.defaultTTL)
|
|
370
|
+
});
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
return providers;
|
|
374
|
+
});
|
|
375
|
+
__publicField(CachePlugin, "defaultOptions", {
|
|
376
|
+
type: "memory"
|
|
377
|
+
});
|
|
378
|
+
__decorateClass([
|
|
379
|
+
import_sdk4.ToolHook.Will("execute", { priority: 1e3 })
|
|
380
|
+
], CachePlugin.prototype, "willReadCache", 1);
|
|
381
|
+
__decorateClass([
|
|
382
|
+
import_sdk4.ToolHook.Did("execute", { priority: 1e3 })
|
|
383
|
+
], CachePlugin.prototype, "willWriteCache", 1);
|
|
384
|
+
CachePlugin = __decorateClass([
|
|
385
|
+
(0, import_sdk4.Plugin)({
|
|
386
|
+
name: "cache",
|
|
387
|
+
description: "Cache plugin for caching tool results",
|
|
388
|
+
providers: [
|
|
389
|
+
/* add providers that always loaded with the plugin or default providers */
|
|
390
|
+
{
|
|
391
|
+
// this is a default provider for cache, will be overridden if dynamicProviders based on config
|
|
392
|
+
name: "cache:memory",
|
|
393
|
+
provide: CacheStoreToken,
|
|
394
|
+
useValue: new CacheMemoryProvider(60 * 60 * 24)
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
})
|
|
398
|
+
], CachePlugin);
|
|
399
|
+
function hashObject(obj) {
|
|
400
|
+
const keys = Object.keys(obj).sort();
|
|
401
|
+
return keys.reduce((acc, key) => {
|
|
402
|
+
acc += key + ":";
|
|
403
|
+
const val = obj[key];
|
|
404
|
+
if (typeof val === "object" && val !== null) {
|
|
405
|
+
acc += hashObject(val);
|
|
406
|
+
} else {
|
|
407
|
+
acc += String(val);
|
|
408
|
+
}
|
|
409
|
+
acc += ";";
|
|
410
|
+
return acc;
|
|
411
|
+
}, "");
|
|
412
|
+
}
|
|
@@ -3,10 +3,10 @@ export default class CacheMemoryProvider implements CacheStoreInterface {
|
|
|
3
3
|
private readonly memory;
|
|
4
4
|
private sweeper?;
|
|
5
5
|
constructor(sweepIntervalTTL?: number);
|
|
6
|
-
/** Set
|
|
7
|
-
setValue(key: string, value:
|
|
6
|
+
/** Set a value (auto-stringifies objects) */
|
|
7
|
+
setValue(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
|
|
8
8
|
/** Get a value and automatically parse JSON if possible */
|
|
9
|
-
getValue<T =
|
|
9
|
+
getValue<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
10
10
|
/** Delete a key */
|
|
11
11
|
delete(key: string): Promise<void>;
|
|
12
12
|
/** Check if a key exists (and not expired) */
|
|
@@ -2,10 +2,10 @@ import { CacheStoreInterface, RedisCacheOptions } from '../cache.types';
|
|
|
2
2
|
export default class CacheRedisProvider implements CacheStoreInterface {
|
|
3
3
|
private readonly client;
|
|
4
4
|
constructor(options: RedisCacheOptions);
|
|
5
|
-
/** Set
|
|
6
|
-
setValue(key: string, value:
|
|
5
|
+
/** Set a value (auto-stringifies objects) */
|
|
6
|
+
setValue(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
|
|
7
7
|
/** Get a value and automatically parse JSON if possible */
|
|
8
|
-
getValue<T =
|
|
8
|
+
getValue<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
9
9
|
/** Delete a key */
|
|
10
10
|
delete(key: string): Promise<void>;
|
|
11
11
|
/** Check if a key exists */
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CacheStoreInterface } from '../cache.types';
|
|
2
|
+
export interface CacheVercelKvProviderOptions {
|
|
3
|
+
url?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
keyPrefix?: string;
|
|
6
|
+
defaultTTL?: number;
|
|
7
|
+
}
|
|
8
|
+
export default class CacheVercelKvProvider implements CacheStoreInterface {
|
|
9
|
+
private kv;
|
|
10
|
+
private readonly keyPrefix;
|
|
11
|
+
private readonly defaultTTL;
|
|
12
|
+
constructor(options?: CacheVercelKvProviderOptions);
|
|
13
|
+
private prefixKey;
|
|
14
|
+
/** Set a value (auto-stringifies objects) */
|
|
15
|
+
setValue(key: string, value: unknown, ttlSeconds?: number): Promise<void>;
|
|
16
|
+
/** Get a value and automatically parse JSON if possible */
|
|
17
|
+
getValue<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
18
|
+
/** Delete a key */
|
|
19
|
+
delete(key: string): Promise<void>;
|
|
20
|
+
/** Check if a key exists */
|
|
21
|
+
exists(key: string): Promise<boolean>;
|
|
22
|
+
/** Gracefully close the provider (no-op for Vercel KV - stateless REST API) */
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|