@hivemagnus/ardent 3.1.0 → 3.1.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.
- package/README.md +7 -0
- package/dist/plugin-http.js +13 -5
- package/dist/plugins.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -579,3 +579,10 @@ Hermes team plugin or require a sibling Magnus checkout. The compatibility probe
|
|
|
579
579
|
explicitly enables `hermes_compat` and allows its combined functional workload
|
|
580
580
|
through the fixture's rate buckets. Default throttling remains covered by the
|
|
581
581
|
separate rate-limit tests.
|
|
582
|
+
|
|
583
|
+
HTTP mounts may set `rateLimit: { perMinute, burst }` for their authentication
|
|
584
|
+
boundary. Defaults are 600 requests per minute and a burst of 120. Limits must be
|
|
585
|
+
positive integers no greater than 6000 and 1200 respectively. All mounts from one
|
|
586
|
+
plugin in the same boundary must agree; management and independent ingress retain
|
|
587
|
+
separate buckets. This capacity is trusted plugin policy and grants no authentication
|
|
588
|
+
or task authority. The one MiB body limit remains in force.
|
package/dist/plugin-http.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { bodyLimit } from 'hono/body-limit';
|
|
2
3
|
import { pluginContext } from './plugins.js';
|
|
3
4
|
import { TokenBucketLimiter } from './a2a-rate-limit.js';
|
|
5
|
+
const capacity = z.object({ perMinute: z.number().int().min(1).max(6000), burst: z.number().int().min(1).max(1200) }).strict();
|
|
4
6
|
/** Hono's route precedence must never let an extension shadow an existing handler. */
|
|
5
7
|
function overlaps(a, b) {
|
|
6
8
|
const left = a.split('/'), right = b.split('/');
|
|
@@ -9,11 +11,17 @@ function overlaps(a, b) {
|
|
|
9
11
|
export function mountPluginHttp(app, runtime, env, jobs) {
|
|
10
12
|
const claimed = app.routes.filter(route => route.method !== 'ALL').map(route => ({ method: route.method, path: route.path, owner: '' }));
|
|
11
13
|
const planned = [];
|
|
14
|
+
const capacities = new Map();
|
|
12
15
|
const ctx = pluginContext(runtime, env);
|
|
13
16
|
for (const plugin of runtime.plugins)
|
|
14
17
|
for (const mount of plugin.httpRoutes?.(ctx, jobs) ?? []) {
|
|
15
18
|
if (!['management', 'independent'].includes(mount.security))
|
|
16
19
|
throw new Error('Plugin HTTP security declaration is required');
|
|
20
|
+
const scope = `${plugin.name}:${mount.security}`, budget = capacity.parse(mount.rateLimit ?? { perMinute: 600, burst: 120 });
|
|
21
|
+
const priorBudget = capacities.get(scope);
|
|
22
|
+
if (priorBudget && (priorBudget.perMinute !== budget.perMinute || priorBudget.burst !== budget.burst))
|
|
23
|
+
throw new Error('Conflicting plugin ingress capacity within an authentication boundary');
|
|
24
|
+
capacities.set(scope, budget);
|
|
17
25
|
for (const route of mount.app.routes) {
|
|
18
26
|
const path = route.path;
|
|
19
27
|
if (!['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'].includes(route.method) ||
|
|
@@ -25,14 +33,14 @@ export function mountPluginHttp(app, runtime, env, jobs) {
|
|
|
25
33
|
if (claimed.some(prior => (prior.method === route.method || [prior.method, route.method].every(method => ['GET', 'HEAD'].includes(method))) && overlaps(prior.path, path) && (prior.owner !== plugin.name || prior.path.replace(/:[^/]+/g, ':') === path.replace(/:[^/]+/g, ':'))))
|
|
26
34
|
throw new Error(`Plugin ${plugin.name} HTTP route ${route.method} ${path} overlaps an existing route`);
|
|
27
35
|
claimed.push({ method: route.method, path, owner: plugin.name });
|
|
28
|
-
planned.push({ route,
|
|
36
|
+
planned.push({ route, scope });
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
|
-
//
|
|
39
|
+
// Separate bounded buckets for management and independent ingress prevent one boundary consuming the other’s capacity.
|
|
32
40
|
const limits = new Map();
|
|
33
|
-
for (const { route,
|
|
34
|
-
const limiter = limits.get(
|
|
35
|
-
limits.set(
|
|
41
|
+
for (const { route, scope } of planned) {
|
|
42
|
+
const limiter = limits.get(scope) ?? new TokenBucketLimiter(capacities.get(scope));
|
|
43
|
+
limits.set(scope, limiter);
|
|
36
44
|
app.on(route.method, route.path, async (c, next) => {
|
|
37
45
|
const result = limiter.take('ingress');
|
|
38
46
|
if (!result.allowed)
|
package/dist/plugins.d.ts
CHANGED
|
@@ -97,6 +97,11 @@ export type ArdentHttpRoutes = {
|
|
|
97
97
|
/** Management aliases keep bearer auth. Independent ingress must authenticate inside every handler. */
|
|
98
98
|
security: 'management' | 'independent';
|
|
99
99
|
app: Hono;
|
|
100
|
+
/** Bounded capacity for this plugin's authentication boundary; all mounts in it must agree. */
|
|
101
|
+
rateLimit?: {
|
|
102
|
+
perMinute: number;
|
|
103
|
+
burst: number;
|
|
104
|
+
};
|
|
100
105
|
};
|
|
101
106
|
/**
|
|
102
107
|
* An Ardent extension. Every hook is optional.
|