@node-llm/core 1.16.2 → 1.17.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/dist/agent/Agent.d.ts +3 -0
- package/dist/agent/Agent.d.ts.map +1 -1
- package/dist/agent/Agent.js +3 -0
- package/dist/aliases.d.ts +33 -9
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +34 -10
- package/dist/chat/Chat.d.ts +16 -5
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +113 -78
- package/dist/chat/ChatOptions.d.ts +19 -0
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +69 -58
- package/dist/chat/ToolCallOutcome.d.ts +30 -0
- package/dist/chat/ToolCallOutcome.d.ts.map +1 -0
- package/dist/chat/ToolCallOutcome.js +43 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/llm.d.ts +1 -1
- package/dist/llm.d.ts.map +1 -1
- package/dist/models/models.json +1464 -1014
- package/dist/providers/bedrock/BedrockProvider.js +1 -1
- package/dist/providers/bedrock/Chat.js +1 -1
- package/dist/providers/bedrock/Embeddings.js +1 -1
- package/dist/providers/bedrock/Image.js +1 -1
- package/dist/providers/bedrock/Moderation.js +1 -1
- package/dist/providers/bedrock/Streaming.js +1 -1
- package/dist/providers/bedrock/config.d.ts +9 -1
- package/dist/providers/bedrock/config.d.ts.map +1 -1
- package/dist/providers/bedrock/config.js +4 -2
- package/dist/providers/bedrock/index.d.ts.map +1 -1
- package/dist/providers/bedrock/index.js +1 -0
- package/dist/utils/handler-stacking.d.ts +31 -0
- package/dist/utils/handler-stacking.d.ts.map +1 -0
- package/dist/utils/handler-stacking.js +66 -0
- package/package.json +13 -10
|
@@ -65,7 +65,7 @@ export class BedrockProvider extends BaseProvider {
|
|
|
65
65
|
this.moderationHandler = new BedrockModeration(config);
|
|
66
66
|
}
|
|
67
67
|
apiBase() {
|
|
68
|
-
return getBedrockEndpoint(this.config.region);
|
|
68
|
+
return getBedrockEndpoint(this.config.region, this.config.apiBase);
|
|
69
69
|
}
|
|
70
70
|
headers() {
|
|
71
71
|
// Headers are built dynamically based on auth mode
|
|
@@ -20,7 +20,7 @@ export class BedrockChat {
|
|
|
20
20
|
constructor(config) {
|
|
21
21
|
this.config = config;
|
|
22
22
|
this.authMode = validateBedrockConfig(config);
|
|
23
|
-
this.baseUrl = getBedrockEndpoint(config.region);
|
|
23
|
+
this.baseUrl = getBedrockEndpoint(config.region, config.apiBase);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Execute a chat request against Bedrock Converse API.
|
|
@@ -17,7 +17,7 @@ export class BedrockEmbeddings {
|
|
|
17
17
|
constructor(config) {
|
|
18
18
|
this.config = config;
|
|
19
19
|
this.authMode = validateBedrockConfig(config);
|
|
20
|
-
this.baseUrl = getBedrockEndpoint(config.region);
|
|
20
|
+
this.baseUrl = getBedrockEndpoint(config.region, config.apiBase);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Execute an embedding request against Bedrock InvokeModel API.
|
|
@@ -12,7 +12,7 @@ export class BedrockImage {
|
|
|
12
12
|
baseUrl;
|
|
13
13
|
constructor(config) {
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.baseUrl = getBedrockEndpoint(config.region);
|
|
15
|
+
this.baseUrl = getBedrockEndpoint(config.region, config.apiBase);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Execute an image generation request.
|
|
@@ -15,7 +15,7 @@ export class BedrockModeration {
|
|
|
15
15
|
constructor(config) {
|
|
16
16
|
this.config = config;
|
|
17
17
|
this.authMode = validateBedrockConfig(config);
|
|
18
|
-
this.baseUrl = getBedrockEndpoint(config.region);
|
|
18
|
+
this.baseUrl = getBedrockEndpoint(config.region, config.apiBase);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Execute a moderation request against Bedrock Guardrails.
|
|
@@ -18,7 +18,7 @@ export class BedrockStreaming {
|
|
|
18
18
|
constructor(config) {
|
|
19
19
|
this.config = config;
|
|
20
20
|
this.authMode = validateBedrockConfig(config);
|
|
21
|
-
this.baseUrl = getBedrockEndpoint(config.region);
|
|
21
|
+
this.baseUrl = getBedrockEndpoint(config.region, config.apiBase);
|
|
22
22
|
}
|
|
23
23
|
async *execute(request, controller) {
|
|
24
24
|
const internalController = new AbortController();
|
|
@@ -37,6 +37,12 @@ export interface BedrockConfig {
|
|
|
37
37
|
* Default: 120000 (2 minutes)
|
|
38
38
|
*/
|
|
39
39
|
requestTimeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Custom Bedrock Runtime endpoint override (e.g. for routing traffic
|
|
42
|
+
* through a proxy or private gateway). Defaults to the standard
|
|
43
|
+
* `https://bedrock-runtime.{region}.amazonaws.com` endpoint when unset.
|
|
44
|
+
*/
|
|
45
|
+
apiBase?: string;
|
|
40
46
|
/**
|
|
41
47
|
* Default Bedrock Guardrail identifier (ID or ARN).
|
|
42
48
|
*/
|
|
@@ -52,6 +58,8 @@ export interface BedrockConfig {
|
|
|
52
58
|
export declare function validateBedrockConfig(config: BedrockConfig): "apiKey" | "sigv4";
|
|
53
59
|
/**
|
|
54
60
|
* Build the Bedrock Runtime endpoint URL for a given region.
|
|
61
|
+
* Pass `apiBase` to route through a custom endpoint (e.g. a proxy/gateway)
|
|
62
|
+
* instead of the standard AWS Bedrock Runtime URL.
|
|
55
63
|
*/
|
|
56
|
-
export declare function getBedrockEndpoint(region: string): string;
|
|
64
|
+
export declare function getBedrockEndpoint(region: string, apiBase?: string): string;
|
|
57
65
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAKf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAuB/E;AAED
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAKf;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAKtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAuB/E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3E"}
|
|
@@ -27,7 +27,9 @@ export function validateBedrockConfig(config) {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Build the Bedrock Runtime endpoint URL for a given region.
|
|
30
|
+
* Pass `apiBase` to route through a custom endpoint (e.g. a proxy/gateway)
|
|
31
|
+
* instead of the standard AWS Bedrock Runtime URL.
|
|
30
32
|
*/
|
|
31
|
-
export function getBedrockEndpoint(region) {
|
|
32
|
-
return `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
33
|
+
export function getBedrockEndpoint(region, apiBase) {
|
|
34
|
+
return apiBase || `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
33
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,wBAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,wBAAgB,uBAAuB,SAwBtC;AAED,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,cAAc,YAAY,CAAC"}
|
|
@@ -19,6 +19,7 @@ export function registerBedrockProvider() {
|
|
|
19
19
|
accessKeyId: cfg.bedrockAccessKeyId,
|
|
20
20
|
secretAccessKey: cfg.bedrockSecretAccessKey,
|
|
21
21
|
sessionToken: cfg.bedrockSessionToken,
|
|
22
|
+
apiBase: cfg.bedrockApiBase,
|
|
22
23
|
guardrailIdentifier: cfg.bedrockGuardrailIdentifier,
|
|
23
24
|
guardrailVersion: cfg.bedrockGuardrailVersion
|
|
24
25
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines a single "constructor-provided" handler with a list of handlers
|
|
3
|
+
* appended later (e.g. via fluent on*() calls), preserving registration order.
|
|
4
|
+
*/
|
|
5
|
+
export declare function collectHandlers<T>(single: T | undefined, list: T[] | undefined): T[];
|
|
6
|
+
/**
|
|
7
|
+
* Runs every handler with the given args, awaiting each in order. Use for
|
|
8
|
+
* pure observers (onNewMessage, onEndMessage, onToolCallStart, onToolCallEnd)
|
|
9
|
+
* where every registered handler should fire and none of them return a value.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runAllHandlers<Args extends unknown[]>(handlers: Array<(...args: Args) => unknown>, ...args: Args): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Runs every handler in order and returns the first defined (non-void)
|
|
14
|
+
* result, but still calls the remaining handlers so every one of them gets a
|
|
15
|
+
* chance to observe/react (mirrors the middleware-runner directive pattern).
|
|
16
|
+
* Use for onToolCallError, where the first STOP/RETRY/CONTINUE wins.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runDirectiveHandlers<Args extends unknown[], R>(handlers: Array<(...args: Args) => R | void | Promise<R | void>>, ...args: Args): Promise<R | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Runs every handler in order, AND-ing boolean results together. Used for
|
|
21
|
+
* onConfirmToolCall: every registered handler must approve for the call to
|
|
22
|
+
* proceed. Short-circuits once a handler declines.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runConfirmHandlers<Args extends unknown[]>(handlers: Array<(...args: Args) => Promise<boolean> | boolean>, ...args: Args): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Runs every handler in order, feeding each handler's (possibly transformed)
|
|
27
|
+
* output into the next as its input. Used for onBeforeRequest/onAfterResponse,
|
|
28
|
+
* where each handler may rewrite the value for downstream handlers.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runChainHandlers<T>(handlers: Array<(value: T) => Promise<T | void> | T | void>, initial: T): Promise<T>;
|
|
31
|
+
//# sourceMappingURL=handler-stacking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-stacking.d.ts","sourceRoot":"","sources":["../../src/utils/handler-stacking.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,CAKpF;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,SAAS,OAAO,EAAE,EACzD,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,EAC3C,GAAG,IAAI,EAAE,IAAI,GACZ,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EAClE,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAChE,GAAG,IAAI,EAAE,IAAI,GACZ,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASxB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,SAAS,OAAO,EAAE,EAC7D,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,EAC9D,GAAG,IAAI,EAAE,IAAI,GACZ,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,QAAQ,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAC3D,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,CAAC,CAAC,CASZ"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines a single "constructor-provided" handler with a list of handlers
|
|
3
|
+
* appended later (e.g. via fluent on*() calls), preserving registration order.
|
|
4
|
+
*/
|
|
5
|
+
export function collectHandlers(single, list) {
|
|
6
|
+
const handlers = [];
|
|
7
|
+
if (single)
|
|
8
|
+
handlers.push(single);
|
|
9
|
+
if (list)
|
|
10
|
+
handlers.push(...list);
|
|
11
|
+
return handlers;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Runs every handler with the given args, awaiting each in order. Use for
|
|
15
|
+
* pure observers (onNewMessage, onEndMessage, onToolCallStart, onToolCallEnd)
|
|
16
|
+
* where every registered handler should fire and none of them return a value.
|
|
17
|
+
*/
|
|
18
|
+
export async function runAllHandlers(handlers, ...args) {
|
|
19
|
+
for (const handler of handlers) {
|
|
20
|
+
await handler(...args);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runs every handler in order and returns the first defined (non-void)
|
|
25
|
+
* result, but still calls the remaining handlers so every one of them gets a
|
|
26
|
+
* chance to observe/react (mirrors the middleware-runner directive pattern).
|
|
27
|
+
* Use for onToolCallError, where the first STOP/RETRY/CONTINUE wins.
|
|
28
|
+
*/
|
|
29
|
+
export async function runDirectiveHandlers(handlers, ...args) {
|
|
30
|
+
let result;
|
|
31
|
+
for (const handler of handlers) {
|
|
32
|
+
const value = await handler(...args);
|
|
33
|
+
if (value !== undefined && result === undefined) {
|
|
34
|
+
result = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs every handler in order, AND-ing boolean results together. Used for
|
|
41
|
+
* onConfirmToolCall: every registered handler must approve for the call to
|
|
42
|
+
* proceed. Short-circuits once a handler declines.
|
|
43
|
+
*/
|
|
44
|
+
export async function runConfirmHandlers(handlers, ...args) {
|
|
45
|
+
for (const handler of handlers) {
|
|
46
|
+
const approved = await handler(...args);
|
|
47
|
+
if (approved === false)
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs every handler in order, feeding each handler's (possibly transformed)
|
|
54
|
+
* output into the next as its input. Used for onBeforeRequest/onAfterResponse,
|
|
55
|
+
* where each handler may rewrite the value for downstream handlers.
|
|
56
|
+
*/
|
|
57
|
+
export async function runChainHandlers(handlers, initial) {
|
|
58
|
+
let value = initial;
|
|
59
|
+
for (const handler of handlers) {
|
|
60
|
+
const result = await handler(value);
|
|
61
|
+
if (result !== undefined) {
|
|
62
|
+
value = result;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-llm/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -55,6 +55,17 @@
|
|
|
55
55
|
"README.md",
|
|
56
56
|
"LICENSE"
|
|
57
57
|
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc -p tsconfig.json",
|
|
60
|
+
"dev": "tsc -w",
|
|
61
|
+
"lint": "tsc --noEmit",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:docs": "vitest run test/docs",
|
|
64
|
+
"test:watch": "vitest",
|
|
65
|
+
"prepack": "npm run build && cp ../../CHANGELOG.md ./CHANGELOG.md",
|
|
66
|
+
"postpack": "rm ./CHANGELOG.md",
|
|
67
|
+
"prepublishOnly": "npm run build && npm run test:docs"
|
|
68
|
+
},
|
|
58
69
|
"dependencies": {
|
|
59
70
|
"zod": "^3.23.8",
|
|
60
71
|
"zod-to-json-schema": "^3.25.1"
|
|
@@ -64,13 +75,5 @@
|
|
|
64
75
|
"@pollyjs/adapter-node-http": "^6.0.6",
|
|
65
76
|
"@pollyjs/core": "^6.0.6",
|
|
66
77
|
"@pollyjs/persister-fs": "^6.0.6"
|
|
67
|
-
},
|
|
68
|
-
"scripts": {
|
|
69
|
-
"build": "tsc -p tsconfig.json",
|
|
70
|
-
"dev": "tsc -w",
|
|
71
|
-
"lint": "tsc --noEmit",
|
|
72
|
-
"test": "vitest run",
|
|
73
|
-
"test:docs": "vitest run test/docs",
|
|
74
|
-
"test:watch": "vitest"
|
|
75
78
|
}
|
|
76
|
-
}
|
|
79
|
+
}
|