universal-agent-memory 0.7.3 → 0.8.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/README.md +121 -20
- package/dist/cli/memory.js +27 -0
- package/dist/cli/memory.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +2 -2
- package/dist/cli/update.js.map +1 -1
- package/dist/memory/adaptive-context.d.ts +100 -0
- package/dist/memory/adaptive-context.d.ts.map +1 -0
- package/dist/memory/adaptive-context.js +456 -0
- package/dist/memory/adaptive-context.js.map +1 -0
- package/dist/utils/calculate-average.d.ts +15 -0
- package/dist/utils/calculate-average.d.ts.map +1 -0
- package/dist/utils/calculate-average.js +21 -0
- package/dist/utils/calculate-average.js.map +1 -0
- package/dist/utils/config-manager.d.ts +30 -0
- package/dist/utils/config-manager.d.ts.map +1 -0
- package/dist/utils/config-manager.js +41 -0
- package/dist/utils/config-manager.js.map +1 -0
- package/dist/utils/fetch-with-retry.d.ts +5 -0
- package/dist/utils/fetch-with-retry.d.ts.map +1 -0
- package/dist/utils/fetch-with-retry.js +61 -0
- package/dist/utils/fetch-with-retry.js.map +1 -0
- package/dist/utils/order-processor-refactored.d.ts +126 -0
- package/dist/utils/order-processor-refactored.d.ts.map +1 -0
- package/dist/utils/order-processor-refactored.js +165 -0
- package/dist/utils/order-processor-refactored.js.map +1 -0
- package/dist/utils/order-processor-strategy.d.ts +72 -0
- package/dist/utils/order-processor-strategy.d.ts.map +1 -0
- package/dist/utils/order-processor-strategy.js +158 -0
- package/dist/utils/order-processor-strategy.js.map +1 -0
- package/dist/utils/order-processor.d.ts +242 -0
- package/dist/utils/order-processor.d.ts.map +1 -0
- package/dist/utils/order-processor.js +370 -0
- package/dist/utils/order-processor.js.map +1 -0
- package/dist/utils/rate-limiter-simple.d.ts +58 -0
- package/dist/utils/rate-limiter-simple.d.ts.map +1 -0
- package/dist/utils/rate-limiter-simple.js +100 -0
- package/dist/utils/rate-limiter-simple.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sliding-window rate limiter that tracks requests per client.
|
|
3
|
+
* Uses a Map to store request timestamps for each client and
|
|
4
|
+
* automatically cleans up expired entries.
|
|
5
|
+
*/
|
|
6
|
+
export class RateLimiter {
|
|
7
|
+
maxRequests;
|
|
8
|
+
windowMs;
|
|
9
|
+
clients = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new RateLimiter instance.
|
|
12
|
+
*
|
|
13
|
+
* @param config - Configuration for request limits and time window
|
|
14
|
+
* @throws Error if maxRequests or windowMs are not positive numbers
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
if (typeof config.maxRequests !== 'number' ||
|
|
18
|
+
config.maxRequests <= 0 ||
|
|
19
|
+
!Number.isInteger(config.maxRequests)) {
|
|
20
|
+
throw new Error('maxRequests must be a positive integer');
|
|
21
|
+
}
|
|
22
|
+
if (typeof config.windowMs !== 'number' ||
|
|
23
|
+
config.windowMs <= 0 ||
|
|
24
|
+
!Number.isInteger(config.windowMs)) {
|
|
25
|
+
throw new Error('windowMs must be a positive integer');
|
|
26
|
+
}
|
|
27
|
+
this.maxRequests = config.maxRequests;
|
|
28
|
+
this.windowMs = config.windowMs;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a request from the given client is allowed.
|
|
32
|
+
* If allowed, records the request timestamp.
|
|
33
|
+
*
|
|
34
|
+
* @param clientId - Unique identifier for the client
|
|
35
|
+
* @returns True if the request is allowed, false if rate limited
|
|
36
|
+
*/
|
|
37
|
+
isAllowed(clientId) {
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
this.cleanupExpiredEntries(clientId, now);
|
|
40
|
+
const entry = this.clients.get(clientId);
|
|
41
|
+
if (!entry) {
|
|
42
|
+
this.clients.set(clientId, { timestamps: [now] });
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (entry.timestamps.length < this.maxRequests) {
|
|
46
|
+
entry.timestamps.push(now);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the number of remaining requests for a client within the current window.
|
|
53
|
+
*
|
|
54
|
+
* @param clientId - Unique identifier for the client
|
|
55
|
+
* @returns Number of remaining allowed requests
|
|
56
|
+
*/
|
|
57
|
+
getRemainingRequests(clientId) {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
this.cleanupExpiredEntries(clientId, now);
|
|
60
|
+
const entry = this.clients.get(clientId);
|
|
61
|
+
if (!entry) {
|
|
62
|
+
return this.maxRequests;
|
|
63
|
+
}
|
|
64
|
+
return Math.max(0, this.maxRequests - entry.timestamps.length);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resets rate limiting state.
|
|
68
|
+
* If clientId is provided, resets only that client.
|
|
69
|
+
* Otherwise, resets all clients.
|
|
70
|
+
*
|
|
71
|
+
* @param clientId - Optional client identifier to reset
|
|
72
|
+
*/
|
|
73
|
+
reset(clientId) {
|
|
74
|
+
if (clientId !== undefined) {
|
|
75
|
+
this.clients.delete(clientId);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.clients.clear();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Removes expired timestamps from a client's entry.
|
|
83
|
+
* Deletes the entry entirely if no valid timestamps remain.
|
|
84
|
+
*
|
|
85
|
+
* @param clientId - Client identifier to clean up
|
|
86
|
+
* @param now - Current timestamp for expiration calculation
|
|
87
|
+
*/
|
|
88
|
+
cleanupExpiredEntries(clientId, now) {
|
|
89
|
+
const entry = this.clients.get(clientId);
|
|
90
|
+
if (!entry) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const cutoff = now - this.windowMs;
|
|
94
|
+
entry.timestamps = entry.timestamps.filter((timestamp) => timestamp > cutoff);
|
|
95
|
+
if (entry.timestamps.length === 0) {
|
|
96
|
+
this.clients.delete(clientId);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=rate-limiter-simple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter-simple.js","sourceRoot":"","sources":["../../src/utils/rate-limiter-simple.ts"],"names":[],"mappings":"AAiBA;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACL,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,OAAO,GAA6B,IAAI,GAAG,EAAE,CAAC;IAE/D;;;;;OAKG;IACH,YAAY,MAAyB;QACnC,IACE,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ;YACtC,MAAM,CAAC,WAAW,IAAI,CAAC;YACvB,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EACrC,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QAED,IACE,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ;YACnC,MAAM,CAAC,QAAQ,IAAI,CAAC;YACpB,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAClC,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,QAAgB;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAE1C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEzC,IAAI,CAAC,KAAK,EAAE,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QACT,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC;QACnC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CACxC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,MAAM,CAClC,CAAC;QAEF,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universal-agent-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Universal AI agent memory system - CLAUDE.md templates, memory, worktrees for Claude Code, Factory.AI, VSCode, OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|