@hilbras/sdk 3.4.1 → 3.4.2
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 +2 -2
- package/dist/security/tool-policy.d.ts +12 -1
- package/dist/security/tool-policy.js +27 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://img.shields.io/badge/version-3.4.
|
|
2
|
+
<img src="https://img.shields.io/badge/version-3.4.2-blue" alt="version">
|
|
3
3
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="license">
|
|
4
4
|
<img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen" alt="node">
|
|
5
5
|
<img src="https://img.shields.io/badge/types-strict-blueviolet" alt="types">
|
|
6
|
-
<img src="https://img.shields.io/badge/tests-
|
|
6
|
+
<img src="https://img.shields.io/badge/tests-1806%20passing-brightgreen" alt="tests">
|
|
7
7
|
<img src="https://img.shields.io/badge/runtime%20deps-zero-brightgreen" alt="zero deps">
|
|
8
8
|
</p>
|
|
9
9
|
|
|
@@ -26,7 +26,18 @@ export interface ToolPolicyCheck {
|
|
|
26
26
|
export declare class ToolPolicy {
|
|
27
27
|
private readonly _allowed;
|
|
28
28
|
private readonly _denied;
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @param input The allow-list and deny-list.
|
|
31
|
+
* @param options `emptyAllowListIsRestrictive` keeps an empty allow-list
|
|
32
|
+
* meaningful as "nothing is permitted". It is off by default because an
|
|
33
|
+
* empty `allowedTools` in configuration means "no restriction", and
|
|
34
|
+
* {@link narrow} needs the opposite meaning: the intersection of two
|
|
35
|
+
* allow-lists can legitimately be empty, and treating that as unrestricted
|
|
36
|
+
* would make narrowing wider instead of narrower.
|
|
37
|
+
*/
|
|
38
|
+
constructor(input?: ToolPolicyInput, options?: {
|
|
39
|
+
emptyAllowListIsRestrictive?: boolean;
|
|
40
|
+
});
|
|
30
41
|
/** True when the policy constrains nothing. */
|
|
31
42
|
isEmpty(): boolean;
|
|
32
43
|
get allowedTools(): readonly string[] | undefined;
|
|
@@ -14,10 +14,22 @@
|
|
|
14
14
|
export class ToolPolicy {
|
|
15
15
|
_allowed;
|
|
16
16
|
_denied;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param input The allow-list and deny-list.
|
|
19
|
+
* @param options `emptyAllowListIsRestrictive` keeps an empty allow-list
|
|
20
|
+
* meaningful as "nothing is permitted". It is off by default because an
|
|
21
|
+
* empty `allowedTools` in configuration means "no restriction", and
|
|
22
|
+
* {@link narrow} needs the opposite meaning: the intersection of two
|
|
23
|
+
* allow-lists can legitimately be empty, and treating that as unrestricted
|
|
24
|
+
* would make narrowing wider instead of narrower.
|
|
25
|
+
*/
|
|
26
|
+
constructor(input = {}, options = {}) {
|
|
27
|
+
const allowed = input.allowedTools;
|
|
28
|
+
this._allowed = allowed === undefined
|
|
29
|
+
? undefined
|
|
30
|
+
: allowed.length > 0 || options.emptyAllowListIsRestrictive
|
|
31
|
+
? Object.freeze([...allowed])
|
|
32
|
+
: undefined;
|
|
21
33
|
this._denied = Object.freeze([...(input.deniedTools ?? [])]);
|
|
22
34
|
}
|
|
23
35
|
/** True when the policy constrains nothing. */
|
|
@@ -55,15 +67,17 @@ export class ToolPolicy {
|
|
|
55
67
|
if (other === undefined)
|
|
56
68
|
return this;
|
|
57
69
|
const narrower = other instanceof ToolPolicy ? other : new ToolPolicy(other);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
let allowed;
|
|
71
|
+
if (this._allowed === undefined) {
|
|
72
|
+
allowed = narrower.allowedTools;
|
|
73
|
+
}
|
|
74
|
+
else if (narrower.allowedTools === undefined) {
|
|
75
|
+
allowed = this._allowed;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
allowed = this._allowed.filter((name) => narrower.allowedTools.includes(name));
|
|
79
|
+
}
|
|
80
|
+
return new ToolPolicy({ allowedTools: allowed, deniedTools: [...this._denied, ...narrower.deniedTools] }, { emptyAllowListIsRestrictive: true });
|
|
67
81
|
}
|
|
68
82
|
/**
|
|
69
83
|
* Validate a whole tool set at once. Returns the first violation, or `null`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilbras/sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "Provider-agnostic LLM client SDK — streaming, tool calling, embeddings, image generation, speech synthesis, transcription, reranking, circuit breaker, retry, reasoning normalization, cost enforcement, structured output with schema validation, type-safe tool builder, and SSRF-safe provider registration. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|