@kenhkl/agent-moss 0.17.11 → 0.17.12
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/dist/cli.js +4 -3
- package/dist/server.d.ts +10 -1
- package/dist/server.js +4 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1295,7 +1295,7 @@ function sessionSweepAction() {
|
|
|
1295
1295
|
function noteSessionAccess(key, sessionId) {
|
|
1296
1296
|
const limit = sessionSweepThreshold();
|
|
1297
1297
|
if (limit <= 0 || !sessionId) return [0, false];
|
|
1298
|
-
const now =
|
|
1298
|
+
const now = performance.now() / 1e3;
|
|
1299
1299
|
const cutoff = now - sessionSweepWindow();
|
|
1300
1300
|
let entries = (sessionWindow.get(key) ?? []).filter(([t]) => t >= cutoff);
|
|
1301
1301
|
entries.push([now, sessionId]);
|
|
@@ -1317,7 +1317,7 @@ function queueAbuseAction() {
|
|
|
1317
1317
|
function noteQueueReject(key) {
|
|
1318
1318
|
const limit = queueAbuseThreshold();
|
|
1319
1319
|
if (limit <= 0 || !key) return [0, false];
|
|
1320
|
-
const now =
|
|
1320
|
+
const now = performance.now() / 1e3;
|
|
1321
1321
|
const cutoff = now - queueAbuseWindow();
|
|
1322
1322
|
let entries = (queueRejects.get(key) ?? []).filter((t) => t >= cutoff);
|
|
1323
1323
|
entries.push(now);
|
|
@@ -13199,6 +13199,7 @@ var init_console = __esm({
|
|
|
13199
13199
|
// src/server.ts
|
|
13200
13200
|
var server_exports = {};
|
|
13201
13201
|
__export(server_exports, {
|
|
13202
|
+
RateLimiter: () => RateLimiter,
|
|
13202
13203
|
createApp: () => createApp,
|
|
13203
13204
|
findFreePort: () => findFreePort,
|
|
13204
13205
|
logDeploymentSelfCheck: () => logDeploymentSelfCheck,
|
|
@@ -13557,7 +13558,7 @@ var init_server = __esm({
|
|
|
13557
13558
|
allow(key) {
|
|
13558
13559
|
if (!this.enabled) return true;
|
|
13559
13560
|
const burst = this.burst ?? Math.max(this.qps, 1) * 2;
|
|
13560
|
-
const now =
|
|
13561
|
+
const now = performance.now() / 1e3;
|
|
13561
13562
|
const [tokens, last] = this.buckets.get(key) ?? [burst, now];
|
|
13562
13563
|
const next = Math.min(burst, tokens + (now - last) * this.qps);
|
|
13563
13564
|
if (next < 1) {
|
package/dist/server.d.ts
CHANGED
|
@@ -13,6 +13,15 @@ import { Hono } from 'hono';
|
|
|
13
13
|
* 与 Python `agent_moss/server/app.py::_log_deployment_selfcheck` 对齐。
|
|
14
14
|
*/
|
|
15
15
|
declare function logDeploymentSelfCheck(): void;
|
|
16
|
+
/** 令牌桶(按主体/来源)。qps<=0 时不生效(默认)。 */
|
|
17
|
+
declare class RateLimiter {
|
|
18
|
+
private qps;
|
|
19
|
+
private burst?;
|
|
20
|
+
private buckets;
|
|
21
|
+
constructor(qps: number, burst?: number | undefined);
|
|
22
|
+
get enabled(): boolean;
|
|
23
|
+
allow(key: string): boolean;
|
|
24
|
+
}
|
|
16
25
|
declare function createApp(): Hono;
|
|
17
26
|
/**
|
|
18
27
|
* 从 startPort 开始找第一个可用端口(照搬 OpenDesk findFreePort 策略)。
|
|
@@ -45,4 +54,4 @@ declare function startUnixSocketServer(socketPath?: string): Promise<{
|
|
|
45
54
|
close: () => Promise<void>;
|
|
46
55
|
}>;
|
|
47
56
|
|
|
48
|
-
export { createApp, findFreePort, logDeploymentSelfCheck, startServer, startUnixSocketServer };
|
|
57
|
+
export { RateLimiter, createApp, findFreePort, logDeploymentSelfCheck, startServer, startUnixSocketServer };
|
package/dist/server.js
CHANGED
|
@@ -1141,7 +1141,7 @@ function sessionSweepAction() {
|
|
|
1141
1141
|
function noteSessionAccess(key, sessionId) {
|
|
1142
1142
|
const limit = sessionSweepThreshold();
|
|
1143
1143
|
if (limit <= 0 || !sessionId) return [0, false];
|
|
1144
|
-
const now =
|
|
1144
|
+
const now = performance.now() / 1e3;
|
|
1145
1145
|
const cutoff = now - sessionSweepWindow();
|
|
1146
1146
|
let entries = (sessionWindow.get(key) ?? []).filter(([t]) => t >= cutoff);
|
|
1147
1147
|
entries.push([now, sessionId]);
|
|
@@ -1163,7 +1163,7 @@ function queueAbuseAction() {
|
|
|
1163
1163
|
function noteQueueReject(key) {
|
|
1164
1164
|
const limit = queueAbuseThreshold();
|
|
1165
1165
|
if (limit <= 0 || !key) return [0, false];
|
|
1166
|
-
const now =
|
|
1166
|
+
const now = performance.now() / 1e3;
|
|
1167
1167
|
const cutoff = now - queueAbuseWindow();
|
|
1168
1168
|
let entries = (queueRejects.get(key) ?? []).filter((t) => t >= cutoff);
|
|
1169
1169
|
entries.push(now);
|
|
@@ -12933,7 +12933,7 @@ var RateLimiter = class {
|
|
|
12933
12933
|
allow(key) {
|
|
12934
12934
|
if (!this.enabled) return true;
|
|
12935
12935
|
const burst = this.burst ?? Math.max(this.qps, 1) * 2;
|
|
12936
|
-
const now =
|
|
12936
|
+
const now = performance.now() / 1e3;
|
|
12937
12937
|
const [tokens, last] = this.buckets.get(key) ?? [burst, now];
|
|
12938
12938
|
const next = Math.min(burst, tokens + (now - last) * this.qps);
|
|
12939
12939
|
if (next < 1) {
|
|
@@ -13194,6 +13194,7 @@ async function startUnixSocketServer(socketPath = "/var/run/agent_moss/agent_mos
|
|
|
13194
13194
|
};
|
|
13195
13195
|
}
|
|
13196
13196
|
export {
|
|
13197
|
+
RateLimiter,
|
|
13197
13198
|
createApp,
|
|
13198
13199
|
findFreePort,
|
|
13199
13200
|
logDeploymentSelfCheck,
|