@frontmcp/plugins 0.6.2 → 0.7.1

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