@hilbras/sdk 2.2.0 → 3.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/README.md +151 -5
- package/dist/client/client.d.ts +59 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +93 -6
- package/dist/client/client.js.map +1 -1
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/cost/alerts.d.ts +106 -0
- package/dist/cost/alerts.d.ts.map +1 -0
- package/dist/cost/alerts.js +150 -0
- package/dist/cost/alerts.js.map +1 -0
- package/dist/features/eval/ab-test.d.ts +80 -0
- package/dist/features/eval/ab-test.d.ts.map +1 -0
- package/dist/features/eval/ab-test.js +102 -0
- package/dist/features/eval/ab-test.js.map +1 -0
- package/dist/features/memory/index.d.ts +3 -0
- package/dist/features/memory/index.d.ts.map +1 -0
- package/dist/features/memory/index.js +2 -0
- package/dist/features/memory/index.js.map +1 -0
- package/dist/features/memory/memory.d.ts +46 -0
- package/dist/features/memory/memory.d.ts.map +1 -0
- package/dist/features/memory/memory.js +152 -0
- package/dist/features/memory/memory.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/logging/logger.d.ts +9 -0
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/logger.js +9 -0
- package/dist/logging/logger.js.map +1 -1
- package/dist/plugin/index.d.ts +9 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +8 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/registry.d.ts +50 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/registry.js +109 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/plugin/types.d.ts +120 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin/types.js +9 -0
- package/dist/plugin/types.js.map +1 -0
- package/dist/reasoning/normalizer.d.ts.map +1 -1
- package/dist/reasoning/normalizer.js +7 -1
- package/dist/reasoning/normalizer.js.map +1 -1
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +2 -0
- package/dist/security/index.js.map +1 -1
- package/dist/security/rbac.d.ts +81 -0
- package/dist/security/rbac.d.ts.map +1 -0
- package/dist/security/rbac.js +139 -0
- package/dist/security/rbac.js.map +1 -0
- package/dist/telemetry/sla.d.ts +100 -0
- package/dist/telemetry/sla.d.ts.map +1 -0
- package/dist/telemetry/sla.js +178 -0
- package/dist/telemetry/sla.js.map +1 -0
- package/dist/tokens/counter.d.ts +12 -2
- package/dist/tokens/counter.d.ts.map +1 -1
- package/dist/tokens/counter.js +12 -2
- package/dist/tokens/counter.js.map +1 -1
- package/dist/transport/middleware-transport.d.ts +31 -0
- package/dist/transport/middleware-transport.d.ts.map +1 -0
- package/dist/transport/middleware-transport.js +57 -0
- package/dist/transport/middleware-transport.js.map +1 -0
- package/dist/transport/transport.d.ts +7 -0
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/types/streams.d.ts +10 -0
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/streams.js +10 -0
- package/dist/types/streams.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Plugin Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages plugin lifecycle: registration, deduplication, and
|
|
5
|
+
* hook dispatch. Used internally by HilbrasClient.
|
|
6
|
+
*/
|
|
7
|
+
export class PluginRegistry {
|
|
8
|
+
_plugins = [];
|
|
9
|
+
_names = new Set();
|
|
10
|
+
/**
|
|
11
|
+
* Register one or more plugins. Duplicate names are ignored (last one wins
|
|
12
|
+
* if the same name is re-registered, the old one is removed first).
|
|
13
|
+
*/
|
|
14
|
+
async add(...plugins) {
|
|
15
|
+
for (const plugin of plugins) {
|
|
16
|
+
if (this._names.has(plugin.name)) {
|
|
17
|
+
// Remove old instance silently
|
|
18
|
+
await this.remove(plugin.name);
|
|
19
|
+
}
|
|
20
|
+
this._plugins.push(plugin);
|
|
21
|
+
this._names.add(plugin.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Remove a plugin by name and call its destroy() hook.
|
|
26
|
+
*/
|
|
27
|
+
async remove(name) {
|
|
28
|
+
const idx = this._plugins.findIndex((p) => p.name === name);
|
|
29
|
+
if (idx === -1)
|
|
30
|
+
return false;
|
|
31
|
+
const [removed] = this._plugins.splice(idx, 1);
|
|
32
|
+
this._names.delete(name);
|
|
33
|
+
try {
|
|
34
|
+
await removed.destroy?.();
|
|
35
|
+
}
|
|
36
|
+
catch { /* plugin destroy errors never break the SDK */ }
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Call setup() on all registered plugins.
|
|
41
|
+
*/
|
|
42
|
+
async setupAll(client) {
|
|
43
|
+
for (const plugin of this._plugins) {
|
|
44
|
+
try {
|
|
45
|
+
await plugin.setup?.(client);
|
|
46
|
+
}
|
|
47
|
+
catch { /* plugin setup errors never break the SDK */ }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Call onRequest on all plugins. If any plugin throws, the error
|
|
52
|
+
* propagates to abort the request.
|
|
53
|
+
*/
|
|
54
|
+
async fireRequest(ctx) {
|
|
55
|
+
for (const plugin of this._plugins) {
|
|
56
|
+
if (plugin.onRequest) {
|
|
57
|
+
await plugin.onRequest(ctx);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Call onResponse on all plugins. Errors are swallowed.
|
|
63
|
+
*/
|
|
64
|
+
async fireResponse(ctx) {
|
|
65
|
+
for (const plugin of this._plugins) {
|
|
66
|
+
try {
|
|
67
|
+
await plugin.onResponse?.(ctx);
|
|
68
|
+
}
|
|
69
|
+
catch { /* plugin response errors never break the SDK */ }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Call onError on all plugins. Errors are swallowed.
|
|
74
|
+
*/
|
|
75
|
+
async fireError(ctx) {
|
|
76
|
+
for (const plugin of this._plugins) {
|
|
77
|
+
try {
|
|
78
|
+
await plugin.onError?.(ctx);
|
|
79
|
+
}
|
|
80
|
+
catch { /* plugin error-hook errors never break the SDK */ }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Destroy all plugins (client disposal).
|
|
85
|
+
*/
|
|
86
|
+
async destroyAll() {
|
|
87
|
+
for (const plugin of this._plugins) {
|
|
88
|
+
try {
|
|
89
|
+
await plugin.destroy?.();
|
|
90
|
+
}
|
|
91
|
+
catch { /* cleanup errors swallowed */ }
|
|
92
|
+
}
|
|
93
|
+
this._plugins.length = 0;
|
|
94
|
+
this._names.clear();
|
|
95
|
+
}
|
|
96
|
+
/** Check if a plugin with the given name is registered */
|
|
97
|
+
has(name) {
|
|
98
|
+
return this._names.has(name);
|
|
99
|
+
}
|
|
100
|
+
/** Get all registered plugin names */
|
|
101
|
+
list() {
|
|
102
|
+
return this._plugins.map((p) => p.name);
|
|
103
|
+
}
|
|
104
|
+
/** Number of registered plugins */
|
|
105
|
+
get size() {
|
|
106
|
+
return this._plugins.length;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/plugin/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,OAAO,cAAc;IACjB,QAAQ,GAAa,EAAE,CAAC;IACxB,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAEnC;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,GAAG,OAAiB;QAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,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AAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,mCAAmC;IACnC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Plugin System Types
|
|
3
|
+
*
|
|
4
|
+
* Plugins extend the HilbrasClient with lifecycle hooks that fire
|
|
5
|
+
* around every LLM request. Plugins can modify requests, observe
|
|
6
|
+
* responses, handle errors, and clean up resources.
|
|
7
|
+
*/
|
|
8
|
+
import type { HilbrasClient } from "../client/client.js";
|
|
9
|
+
import type { Message } from "../types/messages.js";
|
|
10
|
+
/**
|
|
11
|
+
* Context passed to `onRequest` hooks. Plugins can inspect and
|
|
12
|
+
* mutate the request before it is sent to the provider.
|
|
13
|
+
*/
|
|
14
|
+
export interface PluginRequestContext {
|
|
15
|
+
/** The request ID assigned by the client */
|
|
16
|
+
requestId: string;
|
|
17
|
+
/** The resolved provider name */
|
|
18
|
+
provider: string;
|
|
19
|
+
/** The resolved model ID */
|
|
20
|
+
model: string;
|
|
21
|
+
/** The normalized messages being sent */
|
|
22
|
+
messages: Message[];
|
|
23
|
+
/** Additional provider-specific parameters */
|
|
24
|
+
extra?: Record<string, unknown>;
|
|
25
|
+
/** Abort signal for this request */
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
/** Timestamp when the request started */
|
|
28
|
+
timestamp: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Context passed to `onResponse` hooks. Fired after a successful
|
|
32
|
+
* LLM response (stream complete or non-stream completion).
|
|
33
|
+
*/
|
|
34
|
+
export interface PluginResponseContext {
|
|
35
|
+
/** The request ID */
|
|
36
|
+
requestId: string;
|
|
37
|
+
/** The provider that handled the request */
|
|
38
|
+
provider: string;
|
|
39
|
+
/** The model that was used */
|
|
40
|
+
model: string;
|
|
41
|
+
/** Duration of the request in milliseconds */
|
|
42
|
+
durationMs: number;
|
|
43
|
+
/** Input token count (if available) */
|
|
44
|
+
inputTokens?: number;
|
|
45
|
+
/** Output token count (if available) */
|
|
46
|
+
outputTokens?: number;
|
|
47
|
+
/** Whether this was a streaming request */
|
|
48
|
+
streaming: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Context passed to `onError` hooks. Fired when a request fails
|
|
52
|
+
* after all retries and fallbacks are exhausted.
|
|
53
|
+
*/
|
|
54
|
+
export interface PluginErrorContext {
|
|
55
|
+
/** The request ID */
|
|
56
|
+
requestId: string;
|
|
57
|
+
/** The provider that failed */
|
|
58
|
+
provider: string;
|
|
59
|
+
/** The model that failed */
|
|
60
|
+
model: string;
|
|
61
|
+
/** The error that caused the failure */
|
|
62
|
+
error: Error;
|
|
63
|
+
/** Duration of the request in milliseconds */
|
|
64
|
+
durationMs: number;
|
|
65
|
+
/** Number of attempts made */
|
|
66
|
+
attempts: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A plugin that extends the HilbrasClient with lifecycle hooks.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const loggingPlugin: Plugin = {
|
|
74
|
+
* name: "request-logger",
|
|
75
|
+
* version: "1.0.0",
|
|
76
|
+
* onRequest(ctx) {
|
|
77
|
+
* console.log(`[${ctx.requestId}] ${ctx.provider}/${ctx.model}`);
|
|
78
|
+
* },
|
|
79
|
+
* onResponse(ctx) {
|
|
80
|
+
* console.log(`[${ctx.requestId}] completed in ${ctx.durationMs}ms`);
|
|
81
|
+
* },
|
|
82
|
+
* onError(ctx) {
|
|
83
|
+
* console.error(`[${ctx.requestId}] failed: ${ctx.error.message}`);
|
|
84
|
+
* },
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* client.use(loggingPlugin);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export interface Plugin {
|
|
91
|
+
/** Unique plugin name (used for deduplication) */
|
|
92
|
+
name: string;
|
|
93
|
+
/** Semantic version string */
|
|
94
|
+
version?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Called once when the plugin is registered via `client.use()`.
|
|
97
|
+
* Use this to set up resources, subscribe to events, or
|
|
98
|
+
* configure the client.
|
|
99
|
+
*/
|
|
100
|
+
setup?(client: HilbrasClient): void | Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Called before every LLM request. Can inspect and modify the
|
|
103
|
+
* request context. Throw an error to abort the request.
|
|
104
|
+
*/
|
|
105
|
+
onRequest?(ctx: PluginRequestContext): void | Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Called after a successful LLM response.
|
|
108
|
+
*/
|
|
109
|
+
onResponse?(ctx: PluginResponseContext): void | Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Called when a request fails after all retries.
|
|
112
|
+
*/
|
|
113
|
+
onError?(ctx: PluginErrorContext): void | Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Called when the plugin is removed or the client is disposed.
|
|
116
|
+
* Use this to clean up resources.
|
|
117
|
+
*/
|
|
118
|
+
destroy?(): void | Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,KAAK,EAAE,MA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AAG,EAAE,oBAAoB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5D;;OAEG;IACH,UAAU,CAAC,CAAC,GAAG,EAAE,qBAAqB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;OAEG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;OAGG;IACH,OAAO,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Plugin System Types
|
|
3
|
+
*
|
|
4
|
+
* Plugins extend the HilbrasClient with lifecycle hooks that fire
|
|
5
|
+
* around every LLM request. Plugins can modify requests, observe
|
|
6
|
+
* responses, handle errors, and clean up resources.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../src/reasoning/normalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAO1D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,kBAAkB,CAAK;IAE/B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../src/reasoning/normalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAO1D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,kBAAkB,CAAK;IAE/B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAwC5C;IAED,qFAAqF;IACrF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAE1C;IAED,kEAAkE;IAClE,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;IAED,KAAK,IAAI,IAAI,CAIZ;CACF"}
|
|
@@ -35,7 +35,13 @@ export class ReasoningNormalizer {
|
|
|
35
35
|
: null;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
// Not a reasoning tag — return null (caller should yield as text)
|
|
38
|
+
// Not a reasoning tag — return null (caller should yield as text).
|
|
39
|
+
// v2.4.0 BUG-02: keep only a small tail for cross-chunk tag detection
|
|
40
|
+
// (e.g. chunk ends with "<think") to prevent unbounded buffer growth.
|
|
41
|
+
const MAX_TAG_PREFIX = 11; // "<reasoning>" is the longest opening tag
|
|
42
|
+
if (this._buffer.length > MAX_TAG_PREFIX) {
|
|
43
|
+
this._buffer = this._buffer.slice(-MAX_TAG_PREFIX);
|
|
44
|
+
}
|
|
39
45
|
return null;
|
|
40
46
|
}
|
|
41
47
|
// We're inside a tag — check for closing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../../src/reasoning/normalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,YAAY,GAAG;IACnB,sCAAsC;IACtC,wCAAwC;CACzC,CAAC;AAEF,MAAM,OAAO,mBAAmB;IACtB,OAAO,GAAG,EAAE,CAAC;IACb,MAAM,GAAG,KAAK,C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,kBAAkB,GAAG,CAAC,CAAC;YAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,CAAC;QAED,0DAA0D;QAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC5D,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAC9C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC9C,CAAC;IAED,qFAAqF;IACrF,MAAM,CAAC,MAAM,CAAC,IAAY;QACxB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACrC,CAAC;IAED,kEAAkE;IAClE,MAAM,CAAC,qBAAqB,CAAC,IAAY;QACvC,OAAO,0CAA0C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/security/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ export { AuditLogger, createRetentionPolicy } from "./audit-logger.js";
|
|
|
13
13
|
export type { AuditCategory, AuditSeverity, AuditEntry, AuthAuditEntry, DataAccessAuditEntry, ConfigChangeAuditEntry, SecurityAuditEntry, AuditLoggerConfig } from "./audit-logger.js";
|
|
14
14
|
export { RateLimiter, createRateLimiter, RateLimiterRegistry } from "./rate-limiter.js";
|
|
15
15
|
export type { RateLimiterConfig, ThrottleInfo, RateLimiterStats } from "./rate-limiter.js";
|
|
16
|
+
export { createRBACMiddleware, checkPermission } from "./rbac.js";
|
|
17
|
+
export type { RBACRole, RBACConfig, PermissionCheck } from "./rbac.js";
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE9E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACzE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtH,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEpJ,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvL,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxF,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AA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essages, createInjectionGuard, INJECTION_PATTERNS } from "./prompt-injection-guard.js";
|
|
8
8
|
export { AuditLogger, createRetentionPolicy } from "./audit-logger.js";
|
|
9
9
|
export { RateLimiter, createRateLimiter, RateLimiterRegistry } from "./rate-limiter.js";
|
|
10
|
+
// ─── RBAC (v3.0.0) ─────────────────────────────────────────────────────────
|
|
11
|
+
export { createRBACMiddleware, checkPermission } from "./rbac.js";
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGvE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGzE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtH,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGvE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGzE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtH,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxF,8EAA8E;AAC9E,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Role-Based Access Control (RBAC)
|
|
3
|
+
*
|
|
4
|
+
* Provides role definitions, permission checking, and RBAC middleware
|
|
5
|
+
* for controlling which providers, models, and features each user can access.
|
|
6
|
+
*/
|
|
7
|
+
import type { Middleware, MiddlewareContext } from "../middleware/middleware.js";
|
|
8
|
+
import { RateLimiterRegistry } from "./rate-limiter.js";
|
|
9
|
+
import { AuditLogger } from "./audit-logger.js";
|
|
10
|
+
/** A role definition with access constraints */
|
|
11
|
+
export interface RBACRole {
|
|
12
|
+
/** Role name */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Allowed provider names (empty = all providers allowed) */
|
|
15
|
+
allowedProviders?: string[];
|
|
16
|
+
/** Allowed model patterns (empty = all models allowed) */
|
|
17
|
+
allowedModels?: string[];
|
|
18
|
+
/** Maximum tokens per request (undefined = no limit) */
|
|
19
|
+
maxTokensPerRequest?: number;
|
|
20
|
+
/** Maximum budget per session in dollars (undefined = no limit) */
|
|
21
|
+
maxBudgetPerSession?: number;
|
|
22
|
+
/** Rate limit configuration */
|
|
23
|
+
rateLimit?: {
|
|
24
|
+
/** Maximum requests within the window */
|
|
25
|
+
maxRequests: number;
|
|
26
|
+
/** Window duration in milliseconds */
|
|
27
|
+
windowMs: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** @deprecated Use RBACRole instead */
|
|
31
|
+
export type Role = RBACRole;
|
|
32
|
+
/** RBAC configuration */
|
|
33
|
+
export interface RBACConfig {
|
|
34
|
+
/** Map of role name to role definition */
|
|
35
|
+
roles: Record<string, RBACRole>;
|
|
36
|
+
/** Default role for users without an explicit role */
|
|
37
|
+
defaultRole?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Result of a permission check */
|
|
40
|
+
export interface PermissionCheck {
|
|
41
|
+
/** Whether the action is allowed */
|
|
42
|
+
allowed: boolean;
|
|
43
|
+
/** Reason if denied */
|
|
44
|
+
reason?: string;
|
|
45
|
+
/** The role that was checked */
|
|
46
|
+
role: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a role has permission to use a specific provider/model.
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkPermission(role: RBACRole, provider: string, model: string, tokenCount?: number): PermissionCheck;
|
|
52
|
+
/**
|
|
53
|
+
* Create RBAC middleware that enforces role-based access control.
|
|
54
|
+
*
|
|
55
|
+
* The `getUserId` callback extracts the user identity from the request
|
|
56
|
+
* (e.g., from an auth header, API key, or session). The middleware
|
|
57
|
+
* checks the user's role against the requested provider/model.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const rbacMiddleware = createRBACMiddleware(
|
|
62
|
+
* {
|
|
63
|
+
* roles: {
|
|
64
|
+
* viewer: { name: "viewer", allowedProviders: ["openai"], maxTokensPerRequest: 4096 },
|
|
65
|
+
* admin: { name: "admin" }, // no restrictions
|
|
66
|
+
* },
|
|
67
|
+
* defaultRole: "viewer",
|
|
68
|
+
* },
|
|
69
|
+
* (ctx) => extractUserIdFromHeader(ctx.init),
|
|
70
|
+
* );
|
|
71
|
+
*
|
|
72
|
+
* const client = new HilbrasClient({ middleware: rbacMiddleware });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function createRBACMiddleware(config: RBACConfig, getUserId: (ctx: MiddlewareContext) => string | null, options?: {
|
|
76
|
+
/** Audit logger for access-denied events */
|
|
77
|
+
auditLogger?: AuditLogger;
|
|
78
|
+
/** Rate limiter registry (created automatically if not provided) */
|
|
79
|
+
rateLimiters?: RateLimiterRegistry;
|
|
80
|
+
}): Middleware;
|
|
81
|
+
//# sourceMappingURL=rbac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac.d.ts","sourceRoot":"","sources":["../../src/security/rbac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,gDAAgD;AAChD,MAAM,WAAW,QAAQ;IACvB,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wDAAwD;IACxD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mEAAmE;IACnE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,+BAA+B;IAC/B,SAAS,CAAC,EAAE;QACV,yCAAyC;QACzC,WAAW,EAAE,MAAM,CAAC;QACpB,sCAAsC;QACtC,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,uCAAuC;AACvC,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC;AAE5B,yBAAyB;AACzB,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mCAAmC;AACnC,MAAM,WAAW,eAAe;IAC9B,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,eAAe,CAuCjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,MAAM,GAAG,IAAI,EACpD,OAAO,CAAC,EAAE;IACR,4CAA4C;IAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oEAAoE;IACpE,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC,GACA,UAAU,CA0EZ"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Role-Based Access Control (RBAC)
|
|
3
|
+
*
|
|
4
|
+
* Provides role definitions, permission checking, and RBAC middleware
|
|
5
|
+
* for controlling which providers, models, and features each user can access.
|
|
6
|
+
*/
|
|
7
|
+
import { RateLimiterRegistry } from "./rate-limiter.js";
|
|
8
|
+
/**
|
|
9
|
+
* Check if a role has permission to use a specific provider/model.
|
|
10
|
+
*/
|
|
11
|
+
export function checkPermission(role, provider, model, tokenCount) {
|
|
12
|
+
// Check provider access
|
|
13
|
+
if (role.allowedProviders?.length && !role.allowedProviders.includes(provider)) {
|
|
14
|
+
return {
|
|
15
|
+
allowed: false,
|
|
16
|
+
reason: `Provider "${provider}" is not allowed for role "${role.name}". Allowed: ${role.allowedProviders.join(", ")}`,
|
|
17
|
+
role: role.name,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// Check model access
|
|
21
|
+
if (role.allowedModels?.length) {
|
|
22
|
+
const modelAllowed = role.allowedModels.some((pattern) => {
|
|
23
|
+
if (pattern.endsWith("*")) {
|
|
24
|
+
return model.startsWith(pattern.slice(0, -1));
|
|
25
|
+
}
|
|
26
|
+
return model === pattern;
|
|
27
|
+
});
|
|
28
|
+
if (!modelAllowed) {
|
|
29
|
+
return {
|
|
30
|
+
allowed: false,
|
|
31
|
+
reason: `Model "${model}" is not allowed for role "${role.name}". Allowed: ${role.allowedModels.join(", ")}`,
|
|
32
|
+
role: role.name,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Check token limit
|
|
37
|
+
if (role.maxTokensPerRequest !== undefined && tokenCount !== undefined) {
|
|
38
|
+
if (tokenCount > role.maxTokensPerRequest) {
|
|
39
|
+
return {
|
|
40
|
+
allowed: false,
|
|
41
|
+
reason: `Token count ${tokenCount} exceeds limit of ${role.maxTokensPerRequest} for role "${role.name}"`,
|
|
42
|
+
role: role.name,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { allowed: true, role: role.name };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create RBAC middleware that enforces role-based access control.
|
|
50
|
+
*
|
|
51
|
+
* The `getUserId` callback extracts the user identity from the request
|
|
52
|
+
* (e.g., from an auth header, API key, or session). The middleware
|
|
53
|
+
* checks the user's role against the requested provider/model.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const rbacMiddleware = createRBACMiddleware(
|
|
58
|
+
* {
|
|
59
|
+
* roles: {
|
|
60
|
+
* viewer: { name: "viewer", allowedProviders: ["openai"], maxTokensPerRequest: 4096 },
|
|
61
|
+
* admin: { name: "admin" }, // no restrictions
|
|
62
|
+
* },
|
|
63
|
+
* defaultRole: "viewer",
|
|
64
|
+
* },
|
|
65
|
+
* (ctx) => extractUserIdFromHeader(ctx.init),
|
|
66
|
+
* );
|
|
67
|
+
*
|
|
68
|
+
* const client = new HilbrasClient({ middleware: rbacMiddleware });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function createRBACMiddleware(config, getUserId, options) {
|
|
72
|
+
const rateLimiters = options?.rateLimiters ?? new RateLimiterRegistry();
|
|
73
|
+
const auditLogger = options?.auditLogger;
|
|
74
|
+
return async (ctx) => {
|
|
75
|
+
const userId = getUserId(ctx);
|
|
76
|
+
// If no user ID, apply default role or allow through
|
|
77
|
+
const roleId = config.defaultRole ?? "default";
|
|
78
|
+
const role = config.roles[roleId];
|
|
79
|
+
if (!role) {
|
|
80
|
+
// No role configured, allow through
|
|
81
|
+
return ctx.next();
|
|
82
|
+
}
|
|
83
|
+
// Extract provider/model from the request body if available
|
|
84
|
+
let provider = "";
|
|
85
|
+
let model = "";
|
|
86
|
+
let tokenCount;
|
|
87
|
+
try {
|
|
88
|
+
const body = ctx.init.body;
|
|
89
|
+
if (typeof body === "string") {
|
|
90
|
+
const parsed = JSON.parse(body);
|
|
91
|
+
provider = parsed.provider ?? "";
|
|
92
|
+
model = parsed.model ?? "";
|
|
93
|
+
tokenCount = parsed.max_tokens;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch { /* body may not be JSON — skip extraction */ }
|
|
97
|
+
// Check permissions
|
|
98
|
+
if (provider && model) {
|
|
99
|
+
const check = checkPermission(role, provider, model, tokenCount);
|
|
100
|
+
if (!check.allowed) {
|
|
101
|
+
auditLogger?.logSecurity({
|
|
102
|
+
eventType: "custom",
|
|
103
|
+
action: "rbac_denied",
|
|
104
|
+
description: check.reason ?? "Access denied",
|
|
105
|
+
severity: "warning",
|
|
106
|
+
});
|
|
107
|
+
return new Response(JSON.stringify({ error: check.reason }), {
|
|
108
|
+
status: 403,
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Check rate limit
|
|
114
|
+
if (role.rateLimit && userId) {
|
|
115
|
+
const limiter = rateLimiters.getOrCreate(`rbac:${userId}`, {
|
|
116
|
+
maxTokens: role.rateLimit.maxRequests,
|
|
117
|
+
refillRate: role.rateLimit.maxRequests / (role.rateLimit.windowMs / 1000),
|
|
118
|
+
});
|
|
119
|
+
const result = limiter.acquire();
|
|
120
|
+
if (!result.allowed) {
|
|
121
|
+
auditLogger?.logSecurity({
|
|
122
|
+
eventType: "rate_limit",
|
|
123
|
+
action: "rbac_rate_limit",
|
|
124
|
+
description: `Rate limit exceeded for user ${userId} (role: ${role.name})`,
|
|
125
|
+
severity: "warning",
|
|
126
|
+
});
|
|
127
|
+
return new Response(JSON.stringify({ error: "Rate limit exceeded", retryAfterMs: result.retryAfterMs }), {
|
|
128
|
+
status: 429,
|
|
129
|
+
headers: {
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
"Retry-After": String(Math.ceil((result.retryAfterMs ?? 1000) / 1000)),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return ctx.next();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=rbac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac.js","sourceRoot":"","sources":["../../src/security/rbac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA6CxD;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAc,EACd,QAAgB,EAChB,KAAa,EACb,UAAmB;IAEnB,wBAAwB;IACxB,IAAI,IAAI,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,aAAa,QAAQ,8BAA8B,IAAI,CAAC,IAAI,eAAe,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrH,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;IAED,qBAAqB;IACrB,IAAI,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,YAAY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C;QACH,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — SLA Monitoring
|
|
3
|
+
*
|
|
4
|
+
* Tracks latency, error rate, and availability against defined
|
|
5
|
+
* SLA thresholds, firing alerts on breaches.
|
|
6
|
+
*/
|
|
7
|
+
import type { HilbrasClient } from "../client/client.js";
|
|
8
|
+
/** Supported SLA metric types */
|
|
9
|
+
export type SLAMetric = "latency_p95" | "latency_p99" | "error_rate" | "availability" | "cost_per_request";
|
|
10
|
+
/** An SLA definition */
|
|
11
|
+
export interface SLADefinition {
|
|
12
|
+
/** Human-readable SLA name */
|
|
13
|
+
name: string;
|
|
14
|
+
/** The metric to monitor */
|
|
15
|
+
metric: SLAMetric;
|
|
16
|
+
/** Threshold value (latency in ms, rates as 0-1, cost in dollars) */
|
|
17
|
+
threshold: number;
|
|
18
|
+
/** Sliding window duration in milliseconds */
|
|
19
|
+
windowMs: number;
|
|
20
|
+
/** Callback fired on breach */
|
|
21
|
+
alertOnBreach?: (breach: SLABreach) => void;
|
|
22
|
+
}
|
|
23
|
+
/** An SLA breach event */
|
|
24
|
+
export interface SLABreach {
|
|
25
|
+
/** SLA name that was breached */
|
|
26
|
+
sla: string;
|
|
27
|
+
/** Metric that was breached */
|
|
28
|
+
metric: SLAMetric;
|
|
29
|
+
/** The threshold that was exceeded */
|
|
30
|
+
threshold: number;
|
|
31
|
+
/** The actual measured value */
|
|
32
|
+
actual: number;
|
|
33
|
+
/** Timestamp of the breach */
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
/** SLA compliance status for a single definition */
|
|
37
|
+
export interface SLAStatus {
|
|
38
|
+
/** SLA name */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Whether the SLA is currently being met */
|
|
41
|
+
compliant: boolean;
|
|
42
|
+
/** Current measured value */
|
|
43
|
+
currentValue: number;
|
|
44
|
+
/** The threshold */
|
|
45
|
+
threshold: number;
|
|
46
|
+
/** Number of breaches in the tracking window */
|
|
47
|
+
breachCount: number;
|
|
48
|
+
/** Last breach (if any) */
|
|
49
|
+
lastBreach?: SLABreach;
|
|
50
|
+
}
|
|
51
|
+
/** Complete SLA report */
|
|
52
|
+
export interface SLAReport {
|
|
53
|
+
/** Status of each SLA */
|
|
54
|
+
slas: SLAStatus[];
|
|
55
|
+
/** Whether all SLAs are compliant */
|
|
56
|
+
allCompliant: boolean;
|
|
57
|
+
/** Report timestamp */
|
|
58
|
+
timestamp: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Monitors SLA compliance by tracking request metrics in sliding
|
|
62
|
+
* windows and comparing against defined thresholds.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const monitor = new SLAMonitor(client, [
|
|
67
|
+
* { name: "p95 latency", metric: "latency_p95", threshold: 2000, windowMs: 60_000 },
|
|
68
|
+
* { name: "availability", metric: "availability", threshold: 0.99, windowMs: 300_000 },
|
|
69
|
+
* ]);
|
|
70
|
+
*
|
|
71
|
+
* // Later:
|
|
72
|
+
* const report = monitor.report();
|
|
73
|
+
* if (!report.allCompliant) {
|
|
74
|
+
* console.error("SLA breach!", report.slas.filter(s => !s.compliant));
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare class SLAMonitor {
|
|
79
|
+
private _records;
|
|
80
|
+
private _breaches;
|
|
81
|
+
private _definitions;
|
|
82
|
+
private _unsubscribers;
|
|
83
|
+
private _maxRecords;
|
|
84
|
+
constructor(client: HilbrasClient, definitions: SLADefinition[], options?: {
|
|
85
|
+
maxRecords?: number;
|
|
86
|
+
});
|
|
87
|
+
/** Get the current SLA compliance report */
|
|
88
|
+
report(): SLAReport;
|
|
89
|
+
/** Manually record a request (for external integrations) */
|
|
90
|
+
record(durationMs: number, success: boolean, cost?: number): void;
|
|
91
|
+
/** Dispose event subscriptions */
|
|
92
|
+
dispose(): void;
|
|
93
|
+
private _getWindowRecords;
|
|
94
|
+
private _getBreachesFor;
|
|
95
|
+
private _computeMetric;
|
|
96
|
+
private _isCompliant;
|
|
97
|
+
private _checkBreach;
|
|
98
|
+
private _trimRecords;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=sla.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sla.d.ts","sourceRoot":"","sources":["../../src/telemetry/sla.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,iCAAiC;AACjC,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,aAAa,GACb,YAAY,GACZ,cAAc,GACd,kBAAkB,CAAC;AAEvB,wBAAwB;AACxB,MAAM,WAAW,aAAa;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;CAC7C;AAED,0BAA0B;AAC1B,MAAM,WAAW,SAAS;IACxB,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,MAAM,EAAE,SAAS,CAAC;IAClB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,eAAe;IACf,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CA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