@hilbras/sdk 3.4.1 → 3.4.3
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/dist/transport/fetch.d.ts +9 -0
- package/dist/transport/fetch.js +16 -4
- 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.3-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-1809%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`
|
|
@@ -26,6 +26,15 @@ export declare class FetchTransport implements Transport {
|
|
|
26
26
|
private _coalesce;
|
|
27
27
|
private _cleanupTimer;
|
|
28
28
|
constructor(options?: FetchTransportOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Start the idle-connection cleanup timer on first use.
|
|
31
|
+
*
|
|
32
|
+
* The timer is deliberately lazy. A client that never issues a request —
|
|
33
|
+
* including one whose constructor throws before the caller can dispose it —
|
|
34
|
+
* then holds no interval, so a failed construction cannot leave a repeating
|
|
35
|
+
* timer that pins the Node event loop open.
|
|
36
|
+
*/
|
|
37
|
+
private _ensureCleanupTimer;
|
|
29
38
|
private _getOrigin;
|
|
30
39
|
private _acquire;
|
|
31
40
|
private _release;
|
package/dist/transport/fetch.js
CHANGED
|
@@ -20,10 +20,21 @@ export class FetchTransport {
|
|
|
20
20
|
this._maxConnections = options.maxConnectionsPerOrigin ?? 6;
|
|
21
21
|
this._idleTimeout = options.idleTimeout ?? 30000;
|
|
22
22
|
this._coalesce = options.coalesceRequests ?? false;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Start the idle-connection cleanup timer on first use.
|
|
26
|
+
*
|
|
27
|
+
* The timer is deliberately lazy. A client that never issues a request —
|
|
28
|
+
* including one whose constructor throws before the caller can dispose it —
|
|
29
|
+
* then holds no interval, so a failed construction cannot leave a repeating
|
|
30
|
+
* timer that pins the Node event loop open.
|
|
31
|
+
*/
|
|
32
|
+
_ensureCleanupTimer() {
|
|
33
|
+
if (this._cleanupTimer !== null || typeof setInterval === "undefined")
|
|
34
|
+
return;
|
|
35
|
+
this._cleanupTimer = setInterval(() => this._cleanupPools(), this._idleTimeout);
|
|
36
|
+
// Never keep a process alive just to age out an idle connection pool.
|
|
37
|
+
this._cleanupTimer.unref?.();
|
|
27
38
|
}
|
|
28
39
|
_getOrigin(url) {
|
|
29
40
|
try {
|
|
@@ -76,6 +87,7 @@ export class FetchTransport {
|
|
|
76
87
|
return JSON.stringify([init.method || "GET", url, init.body ?? "", headers]);
|
|
77
88
|
}
|
|
78
89
|
async request(url, init) {
|
|
90
|
+
this._ensureCleanupTimer();
|
|
79
91
|
const origin = this._getOrigin(url);
|
|
80
92
|
const externalSignal = init.signal;
|
|
81
93
|
if (externalSignal?.aborted) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilbras/sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
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",
|