gauss-ai 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +489 -0
- package/LICENSE +21 -0
- package/README.md +269 -0
- package/dist/a2a/index.cjs +7 -0
- package/dist/a2a/index.cjs.map +1 -0
- package/dist/a2a/index.d.cts +30 -0
- package/dist/a2a/index.d.ts +30 -0
- package/dist/a2a/index.js +7 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/agent-UIQDSYCE.js +16 -0
- package/dist/agent-UIQDSYCE.js.map +1 -0
- package/dist/agent-builder-8W3mBR-N.d.ts +1075 -0
- package/dist/agent-builder-GEMYdb1p.d.cts +1075 -0
- package/dist/agent-graph-AMQYAWNF.js +1422 -0
- package/dist/agent-graph-AMQYAWNF.js.map +1 -0
- package/dist/ai-sdk-mcp.adapter-SEN6KHNU.js +124 -0
- package/dist/ai-sdk-mcp.adapter-SEN6KHNU.js.map +1 -0
- package/dist/browser/index.js +10 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/bun-runtime.adapter-MQDAJLQM.js +8 -0
- package/dist/bun-runtime.adapter-MQDAJLQM.js.map +1 -0
- package/dist/bun-runtime.adapter-XKOUXVAK.cjs +8 -0
- package/dist/bun-runtime.adapter-XKOUXVAK.cjs.map +1 -0
- package/dist/chat-A3XMRPJL.js +129 -0
- package/dist/chat-A3XMRPJL.js.map +1 -0
- package/dist/chunk-2ZRU47NC.js +91 -0
- package/dist/chunk-2ZRU47NC.js.map +1 -0
- package/dist/chunk-3LD3JTH4.cjs +18 -0
- package/dist/chunk-3LD3JTH4.cjs.map +1 -0
- package/dist/chunk-5FE5TG2W.cjs +16 -0
- package/dist/chunk-5FE5TG2W.cjs.map +1 -0
- package/dist/chunk-6XF673YC.cjs +436 -0
- package/dist/chunk-6XF673YC.cjs.map +1 -0
- package/dist/chunk-7CKWZJNS.js +230 -0
- package/dist/chunk-7CKWZJNS.js.map +1 -0
- package/dist/chunk-BI2G665F.js +4588 -0
- package/dist/chunk-BI2G665F.js.map +1 -0
- package/dist/chunk-C5NLWJS2.js +139 -0
- package/dist/chunk-C5NLWJS2.js.map +1 -0
- package/dist/chunk-CJZ66SU3.cjs +4321 -0
- package/dist/chunk-CJZ66SU3.cjs.map +1 -0
- package/dist/chunk-DAMT2CXW.cjs +91 -0
- package/dist/chunk-DAMT2CXW.cjs.map +1 -0
- package/dist/chunk-E7WG3MO5.js +18 -0
- package/dist/chunk-E7WG3MO5.js.map +1 -0
- package/dist/chunk-EFDM6R4J.js +99 -0
- package/dist/chunk-EFDM6R4J.js.map +1 -0
- package/dist/chunk-F7WIPPEO.js +256 -0
- package/dist/chunk-F7WIPPEO.js.map +1 -0
- package/dist/chunk-FAYDE67N.js +6927 -0
- package/dist/chunk-FAYDE67N.js.map +1 -0
- package/dist/chunk-GAE2KKCM.js +21 -0
- package/dist/chunk-GAE2KKCM.js.map +1 -0
- package/dist/chunk-INLNGRXM.cjs +130 -0
- package/dist/chunk-INLNGRXM.cjs.map +1 -0
- package/dist/chunk-JKXKXB5O.js +130 -0
- package/dist/chunk-JKXKXB5O.js.map +1 -0
- package/dist/chunk-K6SAETGP.js +375 -0
- package/dist/chunk-K6SAETGP.js.map +1 -0
- package/dist/chunk-KEASLAYR.js +157 -0
- package/dist/chunk-KEASLAYR.js.map +1 -0
- package/dist/chunk-KKJVNM6O.js +436 -0
- package/dist/chunk-KKJVNM6O.js.map +1 -0
- package/dist/chunk-KYIMVRIM.js +16 -0
- package/dist/chunk-KYIMVRIM.js.map +1 -0
- package/dist/chunk-MB7NXIZD.js +4321 -0
- package/dist/chunk-MB7NXIZD.js.map +1 -0
- package/dist/chunk-MHHDXPGE.js +209 -0
- package/dist/chunk-MHHDXPGE.js.map +1 -0
- package/dist/chunk-NE6JJA5W.js +401 -0
- package/dist/chunk-NE6JJA5W.js.map +1 -0
- package/dist/chunk-PF46XZBF.cjs +6927 -0
- package/dist/chunk-PF46XZBF.cjs.map +1 -0
- package/dist/chunk-PSJIAGDE.cjs +375 -0
- package/dist/chunk-PSJIAGDE.cjs.map +1 -0
- package/dist/chunk-PWOQDXNQ.js +16 -0
- package/dist/chunk-PWOQDXNQ.js.map +1 -0
- package/dist/chunk-QYOMQBBZ.cjs +230 -0
- package/dist/chunk-QYOMQBBZ.cjs.map +1 -0
- package/dist/chunk-UDFXLC4J.cjs +16 -0
- package/dist/chunk-UDFXLC4J.cjs.map +1 -0
- package/dist/chunk-UO4NGXRT.cjs +259 -0
- package/dist/chunk-UO4NGXRT.cjs.map +1 -0
- package/dist/chunk-UPFDFLEW.js +40 -0
- package/dist/chunk-UPFDFLEW.js.map +1 -0
- package/dist/chunk-V55JSQS7.cjs +16 -0
- package/dist/chunk-V55JSQS7.cjs.map +1 -0
- package/dist/chunk-VJADHXZL.cjs +16 -0
- package/dist/chunk-VJADHXZL.cjs.map +1 -0
- package/dist/chunk-VRWD7LCI.js +59 -0
- package/dist/chunk-VRWD7LCI.js.map +1 -0
- package/dist/chunk-WKKQ443C.js +487 -0
- package/dist/chunk-WKKQ443C.js.map +1 -0
- package/dist/chunk-X2GHUHAF.js +436 -0
- package/dist/chunk-X2GHUHAF.js.map +1 -0
- package/dist/chunk-XLGW3XNI.cjs +256 -0
- package/dist/chunk-XLGW3XNI.cjs.map +1 -0
- package/dist/chunk-ZFJKX4DP.js +16 -0
- package/dist/chunk-ZFJKX4DP.js.map +1 -0
- package/dist/chunk-ZM2OEWM2.js +259 -0
- package/dist/chunk-ZM2OEWM2.js.map +1 -0
- package/dist/chunk-ZNAIP2XV.js +16 -0
- package/dist/chunk-ZNAIP2XV.js.map +1 -0
- package/dist/chunk-ZYFAZYSL.js +42 -0
- package/dist/chunk-ZYFAZYSL.js.map +1 -0
- package/dist/cli/index.js +421 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config-4MHT6TQW.js +153 -0
- package/dist/config-4MHT6TQW.js.map +1 -0
- package/dist/config-REERQFK4.cjs +153 -0
- package/dist/config-REERQFK4.cjs.map +1 -0
- package/dist/cost-tracker-JLOU7IZJ.js +7 -0
- package/dist/cost-tracker-JLOU7IZJ.js.map +1 -0
- package/dist/demo-C52GMSYH.js +188 -0
- package/dist/demo-C52GMSYH.js.map +1 -0
- package/dist/deno/index.js +306 -0
- package/dist/deno/index.js.map +1 -0
- package/dist/deno-runtime.adapter-F744HY7K.js +8 -0
- package/dist/deno-runtime.adapter-F744HY7K.js.map +1 -0
- package/dist/deno-runtime.adapter-RFEVNSCV.cjs +8 -0
- package/dist/deno-runtime.adapter-RFEVNSCV.cjs.map +1 -0
- package/dist/dev-D7DDVDA4.js +218 -0
- package/dist/dev-D7DDVDA4.js.map +1 -0
- package/dist/edge/index.js +10 -0
- package/dist/edge/index.js.map +1 -0
- package/dist/edge-runtime.adapter-UQCW2F7X.js +8 -0
- package/dist/edge-runtime.adapter-UQCW2F7X.js.map +1 -0
- package/dist/edge-runtime.adapter-YED6F3AY.cjs +8 -0
- package/dist/edge-runtime.adapter-YED6F3AY.cjs.map +1 -0
- package/dist/graph-MGFAQZ5W.js +50 -0
- package/dist/graph-MGFAQZ5W.js.map +1 -0
- package/dist/graph-visualization-HBSVQXJK.js +9 -0
- package/dist/graph-visualization-HBSVQXJK.js.map +1 -0
- package/dist/index-BRgqNnh3.d.cts +982 -0
- package/dist/index-CZxpYUxZ.d.ts +982 -0
- package/dist/index.cjs +14789 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10275 -0
- package/dist/index.d.ts +10275 -0
- package/dist/index.js +14789 -0
- package/dist/index.js.map +1 -0
- package/dist/init-CFWXTQ35.js +133 -0
- package/dist/init-CFWXTQ35.js.map +1 -0
- package/dist/llm-VWO4MC7J.cjs +17 -0
- package/dist/llm-VWO4MC7J.cjs.map +1 -0
- package/dist/llm-XLXVSPBI.js +17 -0
- package/dist/llm-XLXVSPBI.js.map +1 -0
- package/dist/logging-WRAK5ZXT.js +33 -0
- package/dist/logging-WRAK5ZXT.js.map +1 -0
- package/dist/metrics-FAHZVVD4.js +47 -0
- package/dist/metrics-FAHZVVD4.js.map +1 -0
- package/dist/node/index.cjs +280 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +51 -0
- package/dist/node/index.d.ts +51 -0
- package/dist/node/index.js +280 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node-runtime.adapter-5L7PJ6W2.js +8 -0
- package/dist/node-runtime.adapter-5L7PJ6W2.js.map +1 -0
- package/dist/node-runtime.adapter-CCRZVGHB.cjs +8 -0
- package/dist/node-runtime.adapter-CCRZVGHB.cjs.map +1 -0
- package/dist/persist-usage-WTBTCWEF.js +7 -0
- package/dist/persist-usage-WTBTCWEF.js.map +1 -0
- package/dist/plugin-RCPBWUUA.js +207 -0
- package/dist/plugin-RCPBWUUA.js.map +1 -0
- package/dist/plugins/index.cjs +75 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +8 -0
- package/dist/plugins/index.d.ts +8 -0
- package/dist/plugins/index.js +75 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins-L4ING3CX.js +4625 -0
- package/dist/plugins-L4ING3CX.js.map +1 -0
- package/dist/providers/index.cjs +189 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +168 -0
- package/dist/providers/index.d.ts +168 -0
- package/dist/providers/index.js +189 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers-3RNQ5CKZ.js +59 -0
- package/dist/providers-3RNQ5CKZ.js.map +1 -0
- package/dist/providers-66GPXUGQ.cjs +59 -0
- package/dist/providers-66GPXUGQ.cjs.map +1 -0
- package/dist/repl-K6QN4I2S.js +678 -0
- package/dist/repl-K6QN4I2S.js.map +1 -0
- package/dist/rest/index.cjs +17 -0
- package/dist/rest/index.cjs.map +1 -0
- package/dist/rest/index.d.cts +102 -0
- package/dist/rest/index.d.ts +102 -0
- package/dist/rest/index.js +17 -0
- package/dist/rest/index.js.map +1 -0
- package/dist/runtime-deno.js +15 -0
- package/dist/runtime-deno.js.map +1 -0
- package/dist/runtime-edge.js +15 -0
- package/dist/runtime-edge.js.map +1 -0
- package/dist/runtime-node.js +15 -0
- package/dist/runtime-node.js.map +1 -0
- package/dist/scraping/index.cjs +11 -0
- package/dist/scraping/index.cjs.map +1 -0
- package/dist/scraping/index.d.cts +17 -0
- package/dist/scraping/index.d.ts +17 -0
- package/dist/scraping/index.js +11 -0
- package/dist/scraping/index.js.map +1 -0
- package/dist/semantic-scraping.port-CZWUea88.d.cts +54 -0
- package/dist/semantic-scraping.port-CZWUea88.d.ts +54 -0
- package/dist/server/index.js +166 -0
- package/dist/server/index.js.map +1 -0
- package/dist/testing/index.cjs +25 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +63 -0
- package/dist/testing/index.d.ts +63 -0
- package/dist/testing/index.js +25 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/token-counter.port-CRgxZZGe.d.ts +334 -0
- package/dist/token-counter.port-D7BHMCRR.d.cts +334 -0
- package/dist/tools-BZM33OBZ.js +10 -0
- package/dist/tools-BZM33OBZ.js.map +1 -0
- package/dist/tracing-XA3TEWP4.js +48 -0
- package/dist/tracing-XA3TEWP4.js.map +1 -0
- package/dist/types-CVsP7gFI.d.cts +235 -0
- package/dist/types-CVsP7gFI.d.ts +235 -0
- package/dist/virtual-fs.adapter-BBLS-3AY.d.ts +26 -0
- package/dist/virtual-fs.adapter-nb0CTYOj.d.cts +26 -0
- package/dist/workflow/index.cjs +9 -0
- package/dist/workflow/index.cjs.map +1 -0
- package/dist/workflow/index.d.cts +62 -0
- package/dist/workflow/index.d.ts +62 -0
- package/dist/workflow/index.js +9 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow.port-BaCttxrw.d.cts +153 -0
- package/dist/workflow.port-BaCttxrw.d.ts +153 -0
- package/package.json +230 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
// src/plugins/plugin-manager.ts
|
|
2
|
+
var PluginManager = class {
|
|
3
|
+
plugins = [];
|
|
4
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
5
|
+
initPromise;
|
|
6
|
+
disposed = false;
|
|
7
|
+
register(plugin) {
|
|
8
|
+
if (this.initPromise) throw new Error("Cannot register plugins after initialization");
|
|
9
|
+
if (this.plugins.some((p) => p.name === plugin.name)) {
|
|
10
|
+
throw new Error(`Plugin "${plugin.name}" is already registered`);
|
|
11
|
+
}
|
|
12
|
+
this.plugins.push(plugin);
|
|
13
|
+
}
|
|
14
|
+
async initialize(ctx) {
|
|
15
|
+
if (this.disposed) throw new Error("Cannot initialize a disposed PluginManager");
|
|
16
|
+
if (!this.initPromise) {
|
|
17
|
+
this.initPromise = this.doInitialize(ctx);
|
|
18
|
+
}
|
|
19
|
+
return this.initPromise;
|
|
20
|
+
}
|
|
21
|
+
async doInitialize(ctx) {
|
|
22
|
+
const initialized = [];
|
|
23
|
+
try {
|
|
24
|
+
for (const plugin of this.plugins) {
|
|
25
|
+
const pluginCtx = {
|
|
26
|
+
...ctx,
|
|
27
|
+
on: (eventType, handler) => {
|
|
28
|
+
const unsubscribe = ctx.on(eventType, handler);
|
|
29
|
+
let unsubscribers = this.subscriptions.get(plugin);
|
|
30
|
+
if (!unsubscribers) {
|
|
31
|
+
unsubscribers = /* @__PURE__ */ new Set();
|
|
32
|
+
this.subscriptions.set(plugin, unsubscribers);
|
|
33
|
+
}
|
|
34
|
+
const trackedUnsubscribe = () => {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
unsubscribers?.delete(trackedUnsubscribe);
|
|
37
|
+
};
|
|
38
|
+
unsubscribers.add(trackedUnsubscribe);
|
|
39
|
+
return trackedUnsubscribe;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (plugin.setup) {
|
|
43
|
+
await plugin.setup(pluginCtx);
|
|
44
|
+
}
|
|
45
|
+
initialized.push(plugin);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
await this.rollback(initialized);
|
|
49
|
+
this.initPromise = void 0;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async rollback(initialized) {
|
|
54
|
+
for (let i = initialized.length - 1; i >= 0; i--) {
|
|
55
|
+
const plugin = initialized[i];
|
|
56
|
+
this.detachAllSubscriptions(plugin);
|
|
57
|
+
if (!plugin.dispose) continue;
|
|
58
|
+
try {
|
|
59
|
+
await plugin.dispose();
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
detachAllSubscriptions(plugin) {
|
|
65
|
+
const unsubscribers = this.subscriptions.get(plugin);
|
|
66
|
+
if (!unsubscribers) return;
|
|
67
|
+
for (const unsubscribe of unsubscribers) {
|
|
68
|
+
try {
|
|
69
|
+
unsubscribe();
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.subscriptions.delete(plugin);
|
|
74
|
+
}
|
|
75
|
+
/** Collect all plugin tools with deterministic override protection. */
|
|
76
|
+
collectTools() {
|
|
77
|
+
const tools = {};
|
|
78
|
+
for (const plugin of this.plugins) {
|
|
79
|
+
if (!plugin.tools) continue;
|
|
80
|
+
for (const [toolName, toolDef] of Object.entries(plugin.tools)) {
|
|
81
|
+
if (toolName in tools) {
|
|
82
|
+
throw new Error(`Duplicate plugin tool "${toolName}" from plugin "${plugin.name}"`);
|
|
83
|
+
}
|
|
84
|
+
tools[toolName] = toolDef;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return tools;
|
|
88
|
+
}
|
|
89
|
+
async runBeforeRun(ctx, params) {
|
|
90
|
+
let prompt = params.prompt;
|
|
91
|
+
for (const plugin of this.plugins) {
|
|
92
|
+
const hook = plugin.hooks?.beforeRun;
|
|
93
|
+
if (!hook) continue;
|
|
94
|
+
const result = await hook(ctx, { prompt });
|
|
95
|
+
if (result?.prompt !== void 0) {
|
|
96
|
+
prompt = result.prompt;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { prompt };
|
|
100
|
+
}
|
|
101
|
+
async runAfterRun(ctx, params) {
|
|
102
|
+
for (const plugin of this.plugins) {
|
|
103
|
+
const hook = plugin.hooks?.afterRun;
|
|
104
|
+
if (!hook) continue;
|
|
105
|
+
await hook(ctx, params);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async runBeforeTool(ctx, params) {
|
|
109
|
+
let args = params.args;
|
|
110
|
+
for (const plugin of this.plugins) {
|
|
111
|
+
const hook = plugin.hooks?.beforeTool;
|
|
112
|
+
if (!hook) continue;
|
|
113
|
+
const result = await hook(ctx, {
|
|
114
|
+
toolName: params.toolName,
|
|
115
|
+
args
|
|
116
|
+
});
|
|
117
|
+
if (result?.args !== void 0) {
|
|
118
|
+
args = result.args;
|
|
119
|
+
}
|
|
120
|
+
if (result?.skip) {
|
|
121
|
+
return {
|
|
122
|
+
args,
|
|
123
|
+
skip: true,
|
|
124
|
+
result: result.result
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { args };
|
|
129
|
+
}
|
|
130
|
+
async runAfterTool(ctx, params) {
|
|
131
|
+
for (const plugin of this.plugins) {
|
|
132
|
+
const hook = plugin.hooks?.afterTool;
|
|
133
|
+
if (!hook) continue;
|
|
134
|
+
await hook(ctx, params);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async runBeforeStep(ctx, params) {
|
|
138
|
+
let step = params.step;
|
|
139
|
+
for (const plugin of this.plugins) {
|
|
140
|
+
const hook = plugin.hooks?.beforeStep;
|
|
141
|
+
if (!hook) continue;
|
|
142
|
+
const result = await hook(ctx, {
|
|
143
|
+
stepIndex: params.stepIndex,
|
|
144
|
+
step
|
|
145
|
+
});
|
|
146
|
+
if (result?.step !== void 0) {
|
|
147
|
+
step = result.step;
|
|
148
|
+
}
|
|
149
|
+
if (result?.skip) {
|
|
150
|
+
return {
|
|
151
|
+
step,
|
|
152
|
+
skip: true
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { step };
|
|
157
|
+
}
|
|
158
|
+
async runAfterStep(ctx, params) {
|
|
159
|
+
for (const plugin of this.plugins) {
|
|
160
|
+
const hook = plugin.hooks?.afterStep;
|
|
161
|
+
if (!hook) continue;
|
|
162
|
+
await hook(ctx, params);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async runOnError(ctx, params) {
|
|
166
|
+
let suppress = false;
|
|
167
|
+
for (const plugin of this.plugins) {
|
|
168
|
+
const hook = plugin.hooks?.onError;
|
|
169
|
+
if (!hook) continue;
|
|
170
|
+
try {
|
|
171
|
+
const result = await hook(ctx, params);
|
|
172
|
+
if (result?.suppress) suppress = true;
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { suppress };
|
|
177
|
+
}
|
|
178
|
+
async dispose() {
|
|
179
|
+
if (this.disposed) return;
|
|
180
|
+
this.disposed = true;
|
|
181
|
+
const errors = [];
|
|
182
|
+
for (let i = this.plugins.length - 1; i >= 0; i--) {
|
|
183
|
+
const plugin = this.plugins[i];
|
|
184
|
+
this.detachAllSubscriptions(plugin);
|
|
185
|
+
if (!plugin.dispose) continue;
|
|
186
|
+
try {
|
|
187
|
+
await plugin.dispose();
|
|
188
|
+
} catch (error) {
|
|
189
|
+
errors.push(error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (errors.length > 0) {
|
|
193
|
+
throw new AggregateError(errors, "Plugin disposal errors");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
get count() {
|
|
197
|
+
return this.plugins.length;
|
|
198
|
+
}
|
|
199
|
+
getPlugins() {
|
|
200
|
+
return this.plugins;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/adapters/resilience/circuit-breaker.ts
|
|
205
|
+
var DEFAULT_CIRCUIT_BREAKER_CONFIG = {
|
|
206
|
+
failureThreshold: 5,
|
|
207
|
+
resetTimeoutMs: 3e4,
|
|
208
|
+
monitorWindowMs: 6e4
|
|
209
|
+
};
|
|
210
|
+
var CircuitBreaker = class {
|
|
211
|
+
constructor(config = DEFAULT_CIRCUIT_BREAKER_CONFIG) {
|
|
212
|
+
this.config = config;
|
|
213
|
+
}
|
|
214
|
+
state = "closed" /* CLOSED */;
|
|
215
|
+
failures = [];
|
|
216
|
+
lastFailureTime = 0;
|
|
217
|
+
halfOpenTestInProgress = false;
|
|
218
|
+
async execute(operation) {
|
|
219
|
+
if (this.shouldReject()) {
|
|
220
|
+
throw new CircuitBreakerError("Circuit breaker is OPEN");
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const result = await operation();
|
|
224
|
+
this.onSuccess();
|
|
225
|
+
return result;
|
|
226
|
+
} catch (error) {
|
|
227
|
+
this.onFailure();
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
getState() {
|
|
232
|
+
this.updateState();
|
|
233
|
+
return this.state;
|
|
234
|
+
}
|
|
235
|
+
getFailureCount() {
|
|
236
|
+
this.cleanupOldFailures();
|
|
237
|
+
return this.failures.length;
|
|
238
|
+
}
|
|
239
|
+
reset() {
|
|
240
|
+
this.state = "closed" /* CLOSED */;
|
|
241
|
+
this.failures = [];
|
|
242
|
+
this.lastFailureTime = 0;
|
|
243
|
+
this.halfOpenTestInProgress = false;
|
|
244
|
+
}
|
|
245
|
+
shouldReject() {
|
|
246
|
+
this.updateState();
|
|
247
|
+
if (this.state === "open" /* OPEN */) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
if (this.state === "half-open" /* HALF_OPEN */ && this.halfOpenTestInProgress) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
onSuccess() {
|
|
256
|
+
if (this.state === "half-open" /* HALF_OPEN */) {
|
|
257
|
+
this.state = "closed" /* CLOSED */;
|
|
258
|
+
this.failures = [];
|
|
259
|
+
this.halfOpenTestInProgress = false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
onFailure() {
|
|
263
|
+
const now = Date.now();
|
|
264
|
+
this.failures.push({ timestamp: now });
|
|
265
|
+
this.lastFailureTime = now;
|
|
266
|
+
this.halfOpenTestInProgress = false;
|
|
267
|
+
if (this.state === "half-open" /* HALF_OPEN */) {
|
|
268
|
+
this.state = "open" /* OPEN */;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
this.cleanupOldFailures();
|
|
272
|
+
if (this.failures.length >= this.config.failureThreshold) {
|
|
273
|
+
this.state = "open" /* OPEN */;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
updateState() {
|
|
277
|
+
if (this.state === "open" /* OPEN */) {
|
|
278
|
+
const now = Date.now();
|
|
279
|
+
if (now - this.lastFailureTime >= this.config.resetTimeoutMs) {
|
|
280
|
+
this.state = "half-open" /* HALF_OPEN */;
|
|
281
|
+
this.halfOpenTestInProgress = false;
|
|
282
|
+
}
|
|
283
|
+
} else if (this.state === "half-open" /* HALF_OPEN */ && !this.halfOpenTestInProgress) {
|
|
284
|
+
this.halfOpenTestInProgress = true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
cleanupOldFailures() {
|
|
288
|
+
const now = Date.now();
|
|
289
|
+
const cutoff = now - this.config.monitorWindowMs;
|
|
290
|
+
this.failures = this.failures.filter((failure) => failure.timestamp > cutoff);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
var CircuitBreakerError = class extends Error {
|
|
294
|
+
constructor(message) {
|
|
295
|
+
super(message);
|
|
296
|
+
this.name = "CircuitBreakerError";
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/adapters/resilience/tool-cache.ts
|
|
301
|
+
var DEFAULT_TOOL_CACHE_CONFIG = {
|
|
302
|
+
defaultTtlMs: 3e5,
|
|
303
|
+
// 5 minutes
|
|
304
|
+
maxSize: 1e3
|
|
305
|
+
};
|
|
306
|
+
var ToolCache = class {
|
|
307
|
+
constructor(config = DEFAULT_TOOL_CACHE_CONFIG) {
|
|
308
|
+
this.config = config;
|
|
309
|
+
this.cleanupIntervalMs = config.cleanupIntervalMs ?? 6e4;
|
|
310
|
+
}
|
|
311
|
+
cache = /* @__PURE__ */ new Map();
|
|
312
|
+
lastCleanup = 0;
|
|
313
|
+
cleanupIntervalMs;
|
|
314
|
+
/**
|
|
315
|
+
* Check if a non-expired entry exists for the key
|
|
316
|
+
*/
|
|
317
|
+
has(key) {
|
|
318
|
+
const entry = this.cache.get(key);
|
|
319
|
+
if (!entry) return false;
|
|
320
|
+
if (Date.now() > entry.expiresAt) {
|
|
321
|
+
this.cache.delete(key);
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get a cached value
|
|
328
|
+
*/
|
|
329
|
+
get(key) {
|
|
330
|
+
const entry = this.cache.get(key);
|
|
331
|
+
if (!entry) {
|
|
332
|
+
this.missCount++;
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
const now = Date.now();
|
|
336
|
+
if (now > entry.expiresAt) {
|
|
337
|
+
this.cache.delete(key);
|
|
338
|
+
this.missCount++;
|
|
339
|
+
return void 0;
|
|
340
|
+
}
|
|
341
|
+
this.cache.delete(key);
|
|
342
|
+
this.cache.set(key, entry);
|
|
343
|
+
entry.lastAccessed = now;
|
|
344
|
+
this.hitCount++;
|
|
345
|
+
return entry.value;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Set a cached value
|
|
349
|
+
*/
|
|
350
|
+
set(key, value, ttlMs) {
|
|
351
|
+
const now = Date.now();
|
|
352
|
+
const ttl = ttlMs ?? this.config.defaultTtlMs;
|
|
353
|
+
if (ttl <= 0) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const entry = {
|
|
357
|
+
value,
|
|
358
|
+
expiresAt: now + ttl,
|
|
359
|
+
lastAccessed: now
|
|
360
|
+
};
|
|
361
|
+
if (this.cache.size >= this.config.maxSize && !this.cache.has(key)) {
|
|
362
|
+
if (this.config.maxSize === 0) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
this.evictLRU();
|
|
366
|
+
}
|
|
367
|
+
this.cache.delete(key);
|
|
368
|
+
this.cache.set(key, entry);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Invalidate a specific cache entry
|
|
372
|
+
*/
|
|
373
|
+
invalidate(key) {
|
|
374
|
+
return this.cache.delete(key);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Clear all cache entries
|
|
378
|
+
*/
|
|
379
|
+
clear() {
|
|
380
|
+
this.cache.clear();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get current cache size
|
|
384
|
+
*/
|
|
385
|
+
get size() {
|
|
386
|
+
this.cleanupExpired();
|
|
387
|
+
return this.cache.size;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get cache hit/miss statistics
|
|
391
|
+
*/
|
|
392
|
+
getStats() {
|
|
393
|
+
this.cleanupExpired();
|
|
394
|
+
return {
|
|
395
|
+
hits: this.hitCount,
|
|
396
|
+
misses: this.missCount,
|
|
397
|
+
size: this.cache.size
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Reset statistics
|
|
402
|
+
*/
|
|
403
|
+
resetStats() {
|
|
404
|
+
this.hitCount = 0;
|
|
405
|
+
this.missCount = 0;
|
|
406
|
+
}
|
|
407
|
+
hitCount = 0;
|
|
408
|
+
missCount = 0;
|
|
409
|
+
evictLRU() {
|
|
410
|
+
const firstKey = this.cache.keys().next().value;
|
|
411
|
+
if (firstKey !== void 0) {
|
|
412
|
+
this.cache.delete(firstKey);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
cleanupExpired() {
|
|
416
|
+
const now = Date.now();
|
|
417
|
+
if (now - this.lastCleanup < this.cleanupIntervalMs) return;
|
|
418
|
+
this.lastCleanup = now;
|
|
419
|
+
const expired = [];
|
|
420
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
421
|
+
if (now > entry.expiresAt) {
|
|
422
|
+
expired.push(key);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
expired.forEach((key) => this.cache.delete(key));
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
export {
|
|
430
|
+
PluginManager,
|
|
431
|
+
DEFAULT_CIRCUIT_BREAKER_CONFIG,
|
|
432
|
+
CircuitBreaker,
|
|
433
|
+
DEFAULT_TOOL_CACHE_CONFIG,
|
|
434
|
+
ToolCache
|
|
435
|
+
};
|
|
436
|
+
//# sourceMappingURL=chunk-X2GHUHAF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/plugin-manager.ts","../src/adapters/resilience/circuit-breaker.ts","../src/adapters/resilience/tool-cache.ts"],"sourcesContent":["// =============================================================================\n// PluginManager — Manages plugin lifecycle, tools, and hook execution order\n// =============================================================================\n\nimport type { Tool } from \"../core/llm/index.js\";\n\nimport type {\n AfterRunParams,\n AfterStepParams,\n AfterToolParams,\n BeforeRunParams,\n BeforeRunResult,\n BeforeStepParams,\n BeforeStepResult,\n BeforeToolParams,\n BeforeToolResult,\n Plugin,\n OnErrorParams,\n OnErrorResult,\n PluginContext,\n PluginSetupContext,\n} from \"../ports/plugin.port.js\";\n\nexport class PluginManager {\n private readonly plugins: Plugin[] = [];\n private readonly subscriptions = new Map<Plugin, Set<() => void>>();\n private initPromise?: Promise<void>;\n private disposed = false;\n\n register(plugin: Plugin): void {\n if (this.initPromise) throw new Error(\"Cannot register plugins after initialization\");\n if (this.plugins.some((p) => p.name === plugin.name)) {\n throw new Error(`Plugin \\\"${plugin.name}\\\" is already registered`);\n }\n this.plugins.push(plugin);\n }\n\n async initialize(ctx: PluginSetupContext): Promise<void> {\n if (this.disposed) throw new Error(\"Cannot initialize a disposed PluginManager\");\n if (!this.initPromise) {\n this.initPromise = this.doInitialize(ctx);\n }\n return this.initPromise;\n }\n\n private async doInitialize(ctx: PluginSetupContext): Promise<void> {\n const initialized: Plugin[] = [];\n\n try {\n for (const plugin of this.plugins) {\n const pluginCtx: PluginSetupContext = {\n ...ctx,\n on: (eventType, handler) => {\n const unsubscribe = ctx.on(eventType, handler);\n let unsubscribers = this.subscriptions.get(plugin);\n if (!unsubscribers) {\n unsubscribers = new Set();\n this.subscriptions.set(plugin, unsubscribers);\n }\n\n const trackedUnsubscribe = (): void => {\n unsubscribe();\n unsubscribers?.delete(trackedUnsubscribe);\n };\n\n unsubscribers.add(trackedUnsubscribe);\n return trackedUnsubscribe;\n },\n };\n\n if (plugin.setup) {\n await plugin.setup(pluginCtx);\n }\n\n initialized.push(plugin);\n }\n } catch (error) {\n await this.rollback(initialized);\n this.initPromise = undefined;\n throw error;\n }\n }\n\n private async rollback(initialized: Plugin[]): Promise<void> {\n for (let i = initialized.length - 1; i >= 0; i--) {\n const plugin = initialized[i]!;\n this.detachAllSubscriptions(plugin);\n if (!plugin.dispose) continue;\n try {\n await plugin.dispose();\n } catch {\n // Best-effort rollback\n }\n }\n }\n\n private detachAllSubscriptions(plugin: Plugin): void {\n const unsubscribers = this.subscriptions.get(plugin);\n if (!unsubscribers) return;\n for (const unsubscribe of unsubscribers) {\n try {\n unsubscribe();\n } catch {\n // Best-effort cleanup\n }\n }\n this.subscriptions.delete(plugin);\n }\n\n /** Collect all plugin tools with deterministic override protection. */\n collectTools(): Record<string, Tool<any, any>> {\n const tools: Record<string, Tool<any, any>> = {};\n\n for (const plugin of this.plugins) {\n if (!plugin.tools) continue;\n\n for (const [toolName, toolDef] of Object.entries(plugin.tools)) {\n if (toolName in tools) {\n throw new Error(`Duplicate plugin tool \\\"${toolName}\\\" from plugin \\\"${plugin.name}\\\"`);\n }\n tools[toolName] = toolDef;\n }\n }\n\n return tools;\n }\n\n async runBeforeRun(ctx: PluginContext, params: BeforeRunParams): Promise<BeforeRunResult> {\n let prompt = params.prompt;\n\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.beforeRun;\n if (!hook) continue;\n\n const result = await hook(ctx, { prompt });\n if (result?.prompt !== undefined) {\n prompt = result.prompt;\n }\n }\n\n return { prompt };\n }\n\n async runAfterRun(ctx: PluginContext, params: AfterRunParams): Promise<void> {\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.afterRun;\n if (!hook) continue;\n await hook(ctx, params);\n }\n }\n\n async runBeforeTool(ctx: PluginContext, params: BeforeToolParams): Promise<BeforeToolResult> {\n let args = params.args;\n\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.beforeTool;\n if (!hook) continue;\n\n const result = await hook(ctx, {\n toolName: params.toolName,\n args,\n });\n\n if (result?.args !== undefined) {\n args = result.args;\n }\n\n if (result?.skip) {\n return {\n args,\n skip: true,\n result: result.result,\n };\n }\n }\n\n return { args };\n }\n\n async runAfterTool(ctx: PluginContext, params: AfterToolParams): Promise<void> {\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.afterTool;\n if (!hook) continue;\n await hook(ctx, params);\n }\n }\n\n async runBeforeStep(ctx: PluginContext, params: BeforeStepParams): Promise<BeforeStepResult> {\n let step = params.step;\n\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.beforeStep;\n if (!hook) continue;\n\n const result = await hook(ctx, {\n stepIndex: params.stepIndex,\n step,\n });\n\n if (result?.step !== undefined) {\n step = result.step;\n }\n\n if (result?.skip) {\n return {\n step,\n skip: true,\n };\n }\n }\n\n return { step };\n }\n\n async runAfterStep(ctx: PluginContext, params: AfterStepParams): Promise<void> {\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.afterStep;\n if (!hook) continue;\n await hook(ctx, params);\n }\n }\n\n async runOnError(ctx: PluginContext, params: OnErrorParams): Promise<OnErrorResult> {\n let suppress = false;\n\n for (const plugin of this.plugins) {\n const hook = plugin.hooks?.onError;\n if (!hook) continue;\n\n try {\n const result = await hook(ctx, params);\n if (result?.suppress) suppress = true;\n } catch {\n // onError must be best-effort and never mask original failures\n }\n }\n\n return { suppress };\n }\n\n async dispose(): Promise<void> {\n if (this.disposed) return;\n this.disposed = true;\n\n const errors: unknown[] = [];\n\n for (let i = this.plugins.length - 1; i >= 0; i--) {\n const plugin = this.plugins[i]!;\n this.detachAllSubscriptions(plugin);\n\n if (!plugin.dispose) continue;\n\n try {\n await plugin.dispose();\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n throw new AggregateError(errors, \"Plugin disposal errors\");\n }\n }\n\n get count(): number {\n return this.plugins.length;\n }\n\n getPlugins(): readonly Plugin[] {\n return this.plugins;\n }\n}\n","/**\n * Circuit Breaker implementation following the classic pattern\n * States: closed → open → half-open\n */\n\nexport interface CircuitBreakerConfig {\n readonly failureThreshold: number;\n readonly resetTimeoutMs: number;\n readonly monitorWindowMs: number;\n}\n\nexport const DEFAULT_CIRCUIT_BREAKER_CONFIG: CircuitBreakerConfig = {\n failureThreshold: 5,\n resetTimeoutMs: 30_000,\n monitorWindowMs: 60_000,\n};\n\nexport enum CircuitBreakerState {\n CLOSED = 'closed',\n OPEN = 'open',\n HALF_OPEN = 'half-open',\n}\n\ninterface FailureRecord {\n timestamp: number;\n}\n\nexport class CircuitBreaker {\n private state: CircuitBreakerState = CircuitBreakerState.CLOSED;\n private failures: FailureRecord[] = [];\n private lastFailureTime = 0;\n private halfOpenTestInProgress = false;\n\n constructor(private readonly config: CircuitBreakerConfig = DEFAULT_CIRCUIT_BREAKER_CONFIG) {}\n\n async execute<T>(operation: () => Promise<T>): Promise<T> {\n if (this.shouldReject()) {\n throw new CircuitBreakerError('Circuit breaker is OPEN');\n }\n\n try {\n const result = await operation();\n this.onSuccess();\n return result;\n } catch (error) {\n this.onFailure();\n throw error;\n }\n }\n\n getState(): CircuitBreakerState {\n this.updateState();\n return this.state;\n }\n\n getFailureCount(): number {\n this.cleanupOldFailures();\n return this.failures.length;\n }\n\n reset(): void {\n this.state = CircuitBreakerState.CLOSED;\n this.failures = [];\n this.lastFailureTime = 0;\n this.halfOpenTestInProgress = false;\n }\n\n private shouldReject(): boolean {\n this.updateState();\n \n if (this.state === CircuitBreakerState.OPEN) {\n return true;\n }\n \n if (this.state === CircuitBreakerState.HALF_OPEN && this.halfOpenTestInProgress) {\n return true;\n }\n\n return false;\n }\n\n private onSuccess(): void {\n if (this.state === CircuitBreakerState.HALF_OPEN) {\n this.state = CircuitBreakerState.CLOSED;\n this.failures = [];\n this.halfOpenTestInProgress = false;\n }\n }\n\n private onFailure(): void {\n const now = Date.now();\n this.failures.push({ timestamp: now });\n this.lastFailureTime = now;\n this.halfOpenTestInProgress = false;\n \n // A failure during HALF_OPEN always reopens the circuit immediately\n if (this.state === CircuitBreakerState.HALF_OPEN) {\n this.state = CircuitBreakerState.OPEN;\n return;\n }\n \n this.cleanupOldFailures();\n \n if (this.failures.length >= this.config.failureThreshold) {\n this.state = CircuitBreakerState.OPEN;\n }\n }\n\n private updateState(): void {\n if (this.state === CircuitBreakerState.OPEN) {\n const now = Date.now();\n if (now - this.lastFailureTime >= this.config.resetTimeoutMs) {\n this.state = CircuitBreakerState.HALF_OPEN;\n this.halfOpenTestInProgress = false;\n }\n } else if (this.state === CircuitBreakerState.HALF_OPEN && !this.halfOpenTestInProgress) {\n this.halfOpenTestInProgress = true;\n }\n }\n\n private cleanupOldFailures(): void {\n const now = Date.now();\n const cutoff = now - this.config.monitorWindowMs;\n this.failures = this.failures.filter(failure => failure.timestamp > cutoff);\n }\n}\n\nexport class CircuitBreakerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CircuitBreakerError';\n }\n}","/**\n * LRU Cache with TTL support for tool execution results\n */\n\nexport interface ToolCacheConfig {\n readonly defaultTtlMs: number;\n readonly maxSize: number;\n readonly cleanupIntervalMs?: number;\n}\n\nexport const DEFAULT_TOOL_CACHE_CONFIG: ToolCacheConfig = {\n defaultTtlMs: 300_000, // 5 minutes\n maxSize: 1000,\n};\n\ninterface CacheEntry<T> {\n value: T;\n expiresAt: number;\n lastAccessed: number;\n}\n\nexport class ToolCache<T = any> {\n private cache = new Map<string, CacheEntry<T>>();\n private lastCleanup = 0;\n private readonly cleanupIntervalMs: number;\n\n constructor(private readonly config: ToolCacheConfig = DEFAULT_TOOL_CACHE_CONFIG) {\n this.cleanupIntervalMs = config.cleanupIntervalMs ?? 60_000;\n }\n\n /**\n * Check if a non-expired entry exists for the key\n */\n has(key: string): boolean {\n const entry = this.cache.get(key);\n if (!entry) return false;\n if (Date.now() > entry.expiresAt) {\n this.cache.delete(key);\n return false;\n }\n return true;\n }\n\n /**\n * Get a cached value\n */\n get(key: string): T | undefined {\n const entry = this.cache.get(key);\n \n if (!entry) {\n this.missCount++;\n return undefined;\n }\n\n const now = Date.now();\n \n // Check if expired\n if (now > entry.expiresAt) {\n this.cache.delete(key);\n this.missCount++;\n return undefined;\n }\n\n // Move to end for LRU ordering\n this.cache.delete(key);\n this.cache.set(key, entry);\n\n entry.lastAccessed = now;\n this.hitCount++;\n \n return entry.value;\n }\n\n /**\n * Set a cached value\n */\n set(key: string, value: T, ttlMs?: number): void {\n const now = Date.now();\n const ttl = ttlMs ?? this.config.defaultTtlMs;\n \n // Handle zero or negative TTL - don't cache\n if (ttl <= 0) {\n return;\n }\n \n const entry: CacheEntry<T> = {\n value,\n expiresAt: now + ttl,\n lastAccessed: now,\n };\n\n // If cache is at capacity, remove LRU item\n if (this.cache.size >= this.config.maxSize && !this.cache.has(key)) {\n // Don't add if max size is 0\n if (this.config.maxSize === 0) {\n return;\n }\n this.evictLRU();\n }\n\n // Delete before set to move existing key to end of insertion order (LRU)\n this.cache.delete(key);\n this.cache.set(key, entry);\n }\n\n /**\n * Invalidate a specific cache entry\n */\n invalidate(key: string): boolean {\n return this.cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n */\n clear(): void {\n this.cache.clear();\n }\n\n /**\n * Get current cache size\n */\n get size(): number {\n this.cleanupExpired();\n return this.cache.size;\n }\n\n /**\n * Get cache hit/miss statistics\n */\n getStats(): { hits: number; misses: number; size: number } {\n this.cleanupExpired();\n return {\n hits: this.hitCount,\n misses: this.missCount,\n size: this.cache.size,\n };\n }\n\n /**\n * Reset statistics\n */\n resetStats(): void {\n this.hitCount = 0;\n this.missCount = 0;\n }\n\n private hitCount = 0;\n private missCount = 0;\n\n private evictLRU(): void {\n const firstKey = this.cache.keys().next().value;\n if (firstKey !== undefined) {\n this.cache.delete(firstKey);\n }\n }\n\n private cleanupExpired(): void {\n const now = Date.now();\n if (now - this.lastCleanup < this.cleanupIntervalMs) return;\n this.lastCleanup = now;\n\n const expired: string[] = [];\n\n for (const [key, entry] of this.cache.entries()) {\n if (now > entry.expiresAt) {\n expired.push(key);\n }\n }\n\n expired.forEach(key => this.cache.delete(key));\n }\n}"],"mappings":";AAuBO,IAAM,gBAAN,MAAoB;AAAA,EACR,UAAoB,CAAC;AAAA,EACrB,gBAAgB,oBAAI,IAA6B;AAAA,EAC1D;AAAA,EACA,WAAW;AAAA,EAEnB,SAAS,QAAsB;AAC7B,QAAI,KAAK,YAAa,OAAM,IAAI,MAAM,8CAA8C;AACpF,QAAI,KAAK,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,IAAI,GAAG;AACpD,YAAM,IAAI,MAAM,WAAY,OAAO,IAAI,yBAA0B;AAAA,IACnE;AACA,SAAK,QAAQ,KAAK,MAAM;AAAA,EAC1B;AAAA,EAEA,MAAM,WAAW,KAAwC;AACvD,QAAI,KAAK,SAAU,OAAM,IAAI,MAAM,4CAA4C;AAC/E,QAAI,CAAC,KAAK,aAAa;AACrB,WAAK,cAAc,KAAK,aAAa,GAAG;AAAA,IAC1C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAc,aAAa,KAAwC;AACjE,UAAM,cAAwB,CAAC;AAE/B,QAAI;AACF,iBAAW,UAAU,KAAK,SAAS;AACjC,cAAM,YAAgC;AAAA,UACpC,GAAG;AAAA,UACH,IAAI,CAAC,WAAW,YA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