@node-llm/core 1.4.2 → 1.5.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 +87 -19
- package/dist/chat/Chat.d.ts +51 -0
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +189 -55
- package/dist/chat/ChatOptions.d.ts +11 -2
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +7 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +9 -1
- package/dist/chat/ChatStream.d.ts +15 -1
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +122 -36
- package/dist/chat/Role.d.ts +1 -1
- package/dist/chat/Role.d.ts.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -1
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm.d.ts +4 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +10 -0
- package/dist/providers/Provider.d.ts +6 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -0
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +1 -0
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +4 -3
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +3 -2
- package/dist/providers/anthropic/Utils.js +2 -2
- package/dist/providers/deepseek/Chat.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.js +8 -5
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.js +1 -0
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +7 -4
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +4 -3
- package/dist/providers/gemini/ChatUtils.js +5 -5
- package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +1 -0
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +3 -2
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
- package/dist/providers/ollama/OllamaProvider.js +1 -0
- package/dist/providers/openai/Capabilities.d.ts +1 -0
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +3 -0
- package/dist/providers/openai/Chat.d.ts +4 -2
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +16 -7
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +3 -2
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +3 -2
- package/dist/providers/openai/Moderation.d.ts.map +1 -1
- package/dist/providers/openai/Moderation.js +3 -2
- package/dist/providers/openai/OpenAIProvider.d.ts +1 -0
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +3 -2
- package/dist/providers/openai/Streaming.d.ts +4 -2
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +15 -6
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +5 -4
- package/dist/providers/openrouter/OpenRouterProvider.d.ts +1 -0
- package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/openrouter/OpenRouterProvider.js +1 -0
- package/dist/providers/utils.d.ts +8 -0
- package/dist/providers/utils.d.ts.map +1 -0
- package/dist/providers/utils.js +16 -0
- package/dist/utils/fetch.d.ts +12 -0
- package/dist/utils/fetch.d.ts.map +1 -0
- package/dist/utils/fetch.js +34 -0
- package/package.json +11 -12
- package/dist/aliases.json +0 -132
- package/dist/utils/sanitize.d.ts +0 -21
- package/dist/utils/sanitize.d.ts.map +0 -1
- package/dist/utils/sanitize.js +0 -76
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ChatRequest, ChatChunk } from "../Provider.js";
|
|
2
|
+
import { OpenAIProvider } from "./OpenAIProvider.js";
|
|
2
3
|
export declare class OpenAIStreaming {
|
|
3
|
-
private readonly
|
|
4
|
+
private readonly providerOrUrl;
|
|
4
5
|
private readonly apiKey;
|
|
5
|
-
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
constructor(providerOrUrl: OpenAIProvider | string, apiKey: string);
|
|
6
8
|
execute(request: ChatRequest, controller?: AbortController): AsyncGenerator<ChatChunk>;
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=Streaming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI7F,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA8K7B"}
|
|
@@ -3,19 +3,28 @@ import { handleOpenAIError } from "./Errors.js";
|
|
|
3
3
|
import { buildUrl } from "./utils.js";
|
|
4
4
|
import { APIError } from "../../errors/index.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
7
|
+
import { mapSystemMessages } from "../utils.js";
|
|
6
8
|
export class OpenAIStreaming {
|
|
7
|
-
|
|
9
|
+
providerOrUrl;
|
|
8
10
|
apiKey;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(providerOrUrl, apiKey) {
|
|
13
|
+
this.providerOrUrl = providerOrUrl;
|
|
11
14
|
this.apiKey = apiKey;
|
|
15
|
+
this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
|
|
12
16
|
}
|
|
13
17
|
async *execute(request, controller) {
|
|
14
18
|
const abortController = controller || new AbortController();
|
|
15
19
|
const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
|
|
20
|
+
const isMainOpenAI = this.baseUrl.includes("api.openai.com");
|
|
21
|
+
const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
|
|
22
|
+
? Capabilities.supportsDeveloperRole(request.model)
|
|
23
|
+
: this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
|
|
24
|
+
const mappedMessages = mapSystemMessages(request.messages, !!supportsDeveloperRole);
|
|
16
25
|
const body = {
|
|
17
26
|
model: request.model,
|
|
18
|
-
messages:
|
|
27
|
+
messages: mappedMessages,
|
|
19
28
|
stream: true,
|
|
20
29
|
};
|
|
21
30
|
if (temperature !== undefined && temperature !== null) {
|
|
@@ -36,7 +45,7 @@ export class OpenAIStreaming {
|
|
|
36
45
|
try {
|
|
37
46
|
const url = buildUrl(this.baseUrl, '/chat/completions');
|
|
38
47
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
39
|
-
const response = await
|
|
48
|
+
const response = await fetchWithTimeout(url, {
|
|
40
49
|
method: "POST",
|
|
41
50
|
headers: {
|
|
42
51
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
@@ -45,7 +54,7 @@ export class OpenAIStreaming {
|
|
|
45
54
|
},
|
|
46
55
|
body: JSON.stringify(body),
|
|
47
56
|
signal: abortController.signal,
|
|
48
|
-
});
|
|
57
|
+
}, request.requestTimeout);
|
|
49
58
|
if (!response.ok) {
|
|
50
59
|
await handleOpenAIError(response, request.model);
|
|
51
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAQ7E,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAU9D,oBAAoB;YAgDpB,iBAAiB;CA4HhC"}
|
|
@@ -3,6 +3,7 @@ import { AudioUtils } from "../../utils/audio.js";
|
|
|
3
3
|
import { DEFAULT_MODELS } from "../../constants.js";
|
|
4
4
|
import { buildUrl } from "./utils.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
6
7
|
export class OpenAITranscription {
|
|
7
8
|
baseUrl;
|
|
8
9
|
apiKey;
|
|
@@ -33,13 +34,13 @@ export class OpenAITranscription {
|
|
|
33
34
|
}
|
|
34
35
|
const url = buildUrl(this.baseUrl, '/audio/transcriptions');
|
|
35
36
|
logger.logRequest("OpenAI", "POST", url, { model: request.model || DEFAULT_MODELS.TRANSCRIPTION, file: fileName });
|
|
36
|
-
const response = await
|
|
37
|
+
const response = await fetchWithTimeout(url, {
|
|
37
38
|
method: "POST",
|
|
38
39
|
headers: {
|
|
39
40
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
40
41
|
},
|
|
41
42
|
body: formData,
|
|
42
|
-
});
|
|
43
|
+
}, request.requestTimeout);
|
|
43
44
|
if (!response.ok) {
|
|
44
45
|
await handleOpenAIError(response, request.model || DEFAULT_MODELS.TRANSCRIPTION);
|
|
45
46
|
}
|
|
@@ -126,14 +127,14 @@ export class OpenAITranscription {
|
|
|
126
127
|
};
|
|
127
128
|
const url = buildUrl(this.baseUrl, '/chat/completions');
|
|
128
129
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
129
|
-
const response = await
|
|
130
|
+
const response = await fetchWithTimeout(url, {
|
|
130
131
|
method: "POST",
|
|
131
132
|
headers: {
|
|
132
133
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
133
134
|
"Content-Type": "application/json",
|
|
134
135
|
},
|
|
135
136
|
body: JSON.stringify(body),
|
|
136
|
-
});
|
|
137
|
+
}, request.requestTimeout);
|
|
137
138
|
if (!response.ok) {
|
|
138
139
|
await handleOpenAIError(response, actualModel);
|
|
139
140
|
}
|
|
@@ -13,6 +13,7 @@ export declare class OpenRouterProvider extends OpenAIProvider {
|
|
|
13
13
|
supportsTranscription: (model: string) => boolean;
|
|
14
14
|
supportsModeration: (model: string) => boolean;
|
|
15
15
|
supportsReasoning: (model: string) => boolean;
|
|
16
|
+
supportsDeveloperRole: (_model: string) => boolean;
|
|
16
17
|
getContextWindow: (model: string) => number | null;
|
|
17
18
|
};
|
|
18
19
|
constructor(options: OpenRouterProviderOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenRouterProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openrouter/OpenRouterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;IAC7C,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,MAAM;oCACT,MAAM;mCACP,MAAM;
|
|
1
|
+
{"version":3,"file":"OpenRouterProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openrouter/OpenRouterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;IAC7C,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,MAAM;oCACT,MAAM;mCACP,MAAM;wCACD,MAAM;kCACZ,MAAM;MAChC;gBAEU,OAAO,EAAE,yBAAyB;IAO9C,SAAS,CAAC,YAAY,IAAI,MAAM;CAGjC"}
|
|
@@ -10,6 +10,7 @@ export class OpenRouterProvider extends OpenAIProvider {
|
|
|
10
10
|
supportsTranscription: (model) => OpenRouterCapabilities.supportsTranscription(model),
|
|
11
11
|
supportsModeration: (model) => OpenRouterCapabilities.supportsModeration(model),
|
|
12
12
|
supportsReasoning: (model) => OpenRouterCapabilities.supportsReasoning(model),
|
|
13
|
+
supportsDeveloperRole: (_model) => true,
|
|
13
14
|
getContextWindow: (model) => OpenRouterCapabilities.getContextWindow(model) || null,
|
|
14
15
|
};
|
|
15
16
|
constructor(options) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Message } from "../chat/Message.js";
|
|
2
|
+
/**
|
|
3
|
+
* Maps system and developer roles based on provider capabilities.
|
|
4
|
+
* If supportsDeveloperRole is true, both "system" and "developer" messages are mapped to "developer".
|
|
5
|
+
* If supportsDeveloperRole is false, both "system" and "developer" messages are mapped to "system".
|
|
6
|
+
*/
|
|
7
|
+
export declare function mapSystemMessages(messages: Message[], supportsDeveloperRole: boolean): Message[];
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,qBAAqB,EAAE,OAAO,GAAG,OAAO,EAAE,CAUhG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps system and developer roles based on provider capabilities.
|
|
3
|
+
* If supportsDeveloperRole is true, both "system" and "developer" messages are mapped to "developer".
|
|
4
|
+
* If supportsDeveloperRole is false, both "system" and "developer" messages are mapped to "system".
|
|
5
|
+
*/
|
|
6
|
+
export function mapSystemMessages(messages, supportsDeveloperRole) {
|
|
7
|
+
return messages.map(msg => {
|
|
8
|
+
if (msg.role === "system" || msg.role === "developer") {
|
|
9
|
+
return {
|
|
10
|
+
...msg,
|
|
11
|
+
role: supportsDeveloperRole ? "developer" : "system"
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return msg;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch with timeout support.
|
|
3
|
+
* Wraps the standard fetch API with an AbortController to enforce request timeouts.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The URL to fetch
|
|
6
|
+
* @param options - Standard fetch options
|
|
7
|
+
* @param timeoutMs - Timeout in milliseconds (optional)
|
|
8
|
+
* @returns Promise<Response>
|
|
9
|
+
* @throws Error if the request times out
|
|
10
|
+
*/
|
|
11
|
+
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
12
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch with timeout support.
|
|
3
|
+
* Wraps the standard fetch API with an AbortController to enforce request timeouts.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The URL to fetch
|
|
6
|
+
* @param options - Standard fetch options
|
|
7
|
+
* @param timeoutMs - Timeout in milliseconds (optional)
|
|
8
|
+
* @returns Promise<Response>
|
|
9
|
+
* @throws Error if the request times out
|
|
10
|
+
*/
|
|
11
|
+
export async function fetchWithTimeout(url, options = {}, timeoutMs) {
|
|
12
|
+
// If no timeout is specified, use standard fetch
|
|
13
|
+
if (!timeoutMs || timeoutMs <= 0) {
|
|
14
|
+
return fetch(url, options);
|
|
15
|
+
}
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
...options,
|
|
21
|
+
signal: controller.signal,
|
|
22
|
+
});
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
clearTimeout(timeoutId);
|
|
28
|
+
// Check if the error was due to abort (timeout)
|
|
29
|
+
if (error.name === 'AbortError') {
|
|
30
|
+
throw new Error(`Request timeout after ${timeoutMs}ms`);
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-llm/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/node-llm/node-llm",
|
|
41
41
|
"directory": "packages/core"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://node-llm.eshaiju.com",
|
|
44
44
|
"bugs": {
|
|
45
|
-
"url": "https://github.com/
|
|
45
|
+
"url": "https://github.com/node-llm/node-llm/issues"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=20.0.0"
|
|
@@ -52,14 +52,6 @@
|
|
|
52
52
|
"README.md",
|
|
53
53
|
"LICENSE"
|
|
54
54
|
],
|
|
55
|
-
"scripts": {
|
|
56
|
-
"build": "tsc -p tsconfig.json",
|
|
57
|
-
"dev": "tsc -w",
|
|
58
|
-
"lint": "tsc --noEmit",
|
|
59
|
-
"test": "vitest run",
|
|
60
|
-
"test:watch": "vitest",
|
|
61
|
-
"prepublishOnly": "npm run build"
|
|
62
|
-
},
|
|
63
55
|
"dependencies": {
|
|
64
56
|
"zod": "^3.23.8",
|
|
65
57
|
"zod-to-json-schema": "^3.25.1"
|
|
@@ -69,5 +61,12 @@
|
|
|
69
61
|
"@pollyjs/adapter-node-http": "^6.0.6",
|
|
70
62
|
"@pollyjs/core": "^6.0.6",
|
|
71
63
|
"@pollyjs/persister-fs": "^6.0.6"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.json",
|
|
67
|
+
"dev": "tsc -w",
|
|
68
|
+
"lint": "tsc --noEmit",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"test:watch": "vitest"
|
|
72
71
|
}
|
|
73
|
-
}
|
|
72
|
+
}
|
package/dist/aliases.json
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"chatgpt-4o": {
|
|
3
|
-
"openai": "chatgpt-4o-latest",
|
|
4
|
-
"openrouter": "openai/chatgpt-4o-latest"
|
|
5
|
-
},
|
|
6
|
-
"claude-3-5-haiku": {
|
|
7
|
-
"anthropic": "claude-3-5-haiku-20241022",
|
|
8
|
-
"openrouter": "anthropic/claude-3.5-haiku",
|
|
9
|
-
"bedrock": "anthropic.claude-3-5-haiku-20241022-v1:0"
|
|
10
|
-
},
|
|
11
|
-
"claude-3-5-sonnet": {
|
|
12
|
-
"anthropic": "claude-3-5-sonnet-20240620",
|
|
13
|
-
"openrouter": "anthropic/claude-3.5-sonnet",
|
|
14
|
-
"bedrock": "anthropic.claude-3-5-sonnet-20240620-v1:0"
|
|
15
|
-
},
|
|
16
|
-
"claude-sonnet-4-5": {
|
|
17
|
-
"anthropic": "claude-sonnet-4-5-20250929"
|
|
18
|
-
},
|
|
19
|
-
"claude-sonnet-4": {
|
|
20
|
-
"anthropic": "claude-sonnet-4-20250514"
|
|
21
|
-
},
|
|
22
|
-
"claude-3-7-sonnet": {
|
|
23
|
-
"anthropic": "claude-3-7-sonnet-20250219",
|
|
24
|
-
"openrouter": "anthropic/claude-3.7-sonnet",
|
|
25
|
-
"bedrock": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
|
|
26
|
-
},
|
|
27
|
-
"claude-3-haiku": {
|
|
28
|
-
"anthropic": "claude-3-haiku-20240307",
|
|
29
|
-
"openrouter": "anthropic/claude-3-haiku",
|
|
30
|
-
"bedrock": "anthropic.claude-3-haiku-20240307-v1:0:200k"
|
|
31
|
-
},
|
|
32
|
-
"claude-3-opus": {
|
|
33
|
-
"anthropic": "claude-3-opus-20240229",
|
|
34
|
-
"openrouter": "anthropic/claude-3-opus",
|
|
35
|
-
"bedrock": "anthropic.claude-3-opus-20240229-v1:0:200k"
|
|
36
|
-
},
|
|
37
|
-
"claude-3-sonnet": {
|
|
38
|
-
"bedrock": "anthropic.claude-3-sonnet-20240229-v1:0"
|
|
39
|
-
},
|
|
40
|
-
"deepseek-chat": {
|
|
41
|
-
"deepseek": "deepseek-chat",
|
|
42
|
-
"openrouter": "deepseek/deepseek-chat"
|
|
43
|
-
},
|
|
44
|
-
"gemini-flash": {
|
|
45
|
-
"gemini": "gemini-flash-latest",
|
|
46
|
-
"vertexai": "gemini-flash-latest",
|
|
47
|
-
"openrouter": "google/gemini-flash-latest"
|
|
48
|
-
},
|
|
49
|
-
"gemini-pro": {
|
|
50
|
-
"gemini": "gemini-1.5-pro-001",
|
|
51
|
-
"vertexai": "gemini-1.5-pro-001",
|
|
52
|
-
"openrouter": "google/gemini-1.5-pro-001"
|
|
53
|
-
},
|
|
54
|
-
"gemini-1.5-flash": {
|
|
55
|
-
"gemini": "gemini-1.5-flash-001",
|
|
56
|
-
"vertexai": "gemini-1.5-flash-001",
|
|
57
|
-
"openrouter": "google/gemini-1.5-flash-001"
|
|
58
|
-
},
|
|
59
|
-
"gemini-1.5-pro": {
|
|
60
|
-
"gemini": "gemini-1.5-pro-001",
|
|
61
|
-
"vertexai": "gemini-1.5-pro-001",
|
|
62
|
-
"openrouter": "google/gemini-1.5-pro-001"
|
|
63
|
-
},
|
|
64
|
-
"gemini-2.0-flash": {
|
|
65
|
-
"gemini": "gemini-2.0-flash",
|
|
66
|
-
"vertexai": "gemini-2.0-flash"
|
|
67
|
-
},
|
|
68
|
-
"gemini-2.0-flash-001": {
|
|
69
|
-
"gemini": "gemini-2.0-flash-001",
|
|
70
|
-
"openrouter": "google/gemini-2.0-flash-001",
|
|
71
|
-
"vertexai": "gemini-2.0-flash-001"
|
|
72
|
-
},
|
|
73
|
-
"gpt-3.5-turbo": {
|
|
74
|
-
"openai": "gpt-3.5-turbo",
|
|
75
|
-
"openrouter": "openai/gpt-3.5-turbo"
|
|
76
|
-
},
|
|
77
|
-
"gpt-4": {
|
|
78
|
-
"openai": "gpt-4",
|
|
79
|
-
"openrouter": "openai/gpt-4"
|
|
80
|
-
},
|
|
81
|
-
"gpt-4-turbo": {
|
|
82
|
-
"openai": "gpt-4-turbo",
|
|
83
|
-
"openrouter": "openai/gpt-4-turbo"
|
|
84
|
-
},
|
|
85
|
-
"gpt-4o": {
|
|
86
|
-
"openai": "gpt-4o",
|
|
87
|
-
"openrouter": "openai/gpt-4o"
|
|
88
|
-
},
|
|
89
|
-
"gpt-4o-mini": {
|
|
90
|
-
"openai": "gpt-4o-mini",
|
|
91
|
-
"openrouter": "openai/gpt-4o-mini"
|
|
92
|
-
},
|
|
93
|
-
"llama-3-1-405b": {
|
|
94
|
-
"openrouter": "meta-llama/llama-3.1-405b"
|
|
95
|
-
},
|
|
96
|
-
"llama-3-1-405b-instruct": {
|
|
97
|
-
"openrouter": "meta-llama/llama-3.1-405b-instruct"
|
|
98
|
-
},
|
|
99
|
-
"llama-3-1-70b": {
|
|
100
|
-
"openrouter": "meta-llama/llama-3.1-70b"
|
|
101
|
-
},
|
|
102
|
-
"llama-3-1-70b-instruct": {
|
|
103
|
-
"openrouter": "meta-llama/llama-3.1-70b-instruct"
|
|
104
|
-
},
|
|
105
|
-
"llama-3-1-8b": {
|
|
106
|
-
"openrouter": "meta-llama/llama-3.1-8b"
|
|
107
|
-
},
|
|
108
|
-
"llama-3-1-8b-instruct": {
|
|
109
|
-
"openrouter": "meta-llama/llama-3.1-8b-instruct"
|
|
110
|
-
},
|
|
111
|
-
"llama-3-2-1b-instruct": {
|
|
112
|
-
"openrouter": "meta-llama/llama-3.2-1b-instruct"
|
|
113
|
-
},
|
|
114
|
-
"llama-3-2-3b-instruct": {
|
|
115
|
-
"openrouter": "meta-llama/llama-3.2-3b-instruct"
|
|
116
|
-
},
|
|
117
|
-
"llama-3-3-70b-instruct": {
|
|
118
|
-
"openrouter": "meta-llama/llama-3.3-70b-instruct"
|
|
119
|
-
},
|
|
120
|
-
"mistral-large": {
|
|
121
|
-
"mistral": "mistral-large-latest",
|
|
122
|
-
"openrouter": "mistralai/mistral-large"
|
|
123
|
-
},
|
|
124
|
-
"mistral-medium": {
|
|
125
|
-
"mistral": "mistral-medium-latest",
|
|
126
|
-
"openrouter": "mistralai/mistral-medium"
|
|
127
|
-
},
|
|
128
|
-
"mistral-small": {
|
|
129
|
-
"mistral": "mistral-small-latest",
|
|
130
|
-
"openrouter": "mistralai/mistral-small"
|
|
131
|
-
}
|
|
132
|
-
}
|
package/dist/utils/sanitize.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for sanitizing sensitive data from error messages and objects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Sanitizes API keys and other sensitive data from strings
|
|
6
|
-
* @param text - The text to sanitize
|
|
7
|
-
* @returns Sanitized text with sensitive data redacted
|
|
8
|
-
*/
|
|
9
|
-
export declare function sanitizeText(text: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Sanitizes an error object by redacting sensitive data
|
|
12
|
-
* @param error - The error object to sanitize
|
|
13
|
-
* @returns Sanitized error object
|
|
14
|
-
*/
|
|
15
|
-
export declare function sanitizeError(error: any): any;
|
|
16
|
-
/**
|
|
17
|
-
* Logs an error with sanitized output
|
|
18
|
-
* @param error - The error to log
|
|
19
|
-
*/
|
|
20
|
-
export declare function logSanitizedError(error: any): void;
|
|
21
|
-
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/utils/sanitize.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiCjD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CA+B7C;AAiBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAGlD"}
|
package/dist/utils/sanitize.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for sanitizing sensitive data from error messages and objects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Sanitizes API keys and other sensitive data from strings
|
|
6
|
-
* @param text - The text to sanitize
|
|
7
|
-
* @returns Sanitized text with sensitive data redacted
|
|
8
|
-
*/
|
|
9
|
-
export function sanitizeText(text) {
|
|
10
|
-
if (!text)
|
|
11
|
-
return text;
|
|
12
|
-
// Sanitize API keys (various formats)
|
|
13
|
-
// OpenAI: sk-...
|
|
14
|
-
// Anthropic: sk-ant-...
|
|
15
|
-
// Generic patterns
|
|
16
|
-
let sanitized = text;
|
|
17
|
-
// Pattern: sk-ant-api03-... or sk-...
|
|
18
|
-
sanitized = sanitized.replace(/sk-ant-[a-zA-Z0-9_-]{8,}/g, (match) => `sk-ant-***${match.slice(-4)}`);
|
|
19
|
-
sanitized = sanitized.replace(/sk-[a-zA-Z0-9_-]{20,}/g, (match) => `sk-***${match.slice(-4)}`);
|
|
20
|
-
// Pattern: Bearer tokens
|
|
21
|
-
sanitized = sanitized.replace(/Bearer\s+[a-zA-Z0-9_-]{20,}/gi, (match) => `Bearer ***${match.slice(-4)}`);
|
|
22
|
-
// Pattern: API keys in error messages like "Incorrect API key provided: 8TAXX2TT***..."
|
|
23
|
-
sanitized = sanitized.replace(/API key[^:]*:\s*[a-zA-Z0-9]{4,}\**/gi, 'API key: [REDACTED]');
|
|
24
|
-
return sanitized;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Sanitizes an error object by redacting sensitive data
|
|
28
|
-
* @param error - The error object to sanitize
|
|
29
|
-
* @returns Sanitized error object
|
|
30
|
-
*/
|
|
31
|
-
export function sanitizeError(error) {
|
|
32
|
-
if (!error)
|
|
33
|
-
return error;
|
|
34
|
-
// Handle Error instances
|
|
35
|
-
if (error instanceof Error) {
|
|
36
|
-
const sanitized = new Error(sanitizeText(error.message));
|
|
37
|
-
sanitized.name = error.name;
|
|
38
|
-
sanitized.stack = error.stack ? sanitizeText(error.stack) : undefined;
|
|
39
|
-
// Copy other properties
|
|
40
|
-
Object.keys(error).forEach(key => {
|
|
41
|
-
if (key !== 'message' && key !== 'stack' && key !== 'name') {
|
|
42
|
-
sanitized[key] = sanitizeErrorValue(error[key]);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return sanitized;
|
|
46
|
-
}
|
|
47
|
-
// Handle plain objects
|
|
48
|
-
if (typeof error === 'object') {
|
|
49
|
-
const sanitized = Array.isArray(error) ? [] : {};
|
|
50
|
-
for (const key in error) {
|
|
51
|
-
sanitized[key] = sanitizeErrorValue(error[key]);
|
|
52
|
-
}
|
|
53
|
-
return sanitized;
|
|
54
|
-
}
|
|
55
|
-
return error;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Sanitizes a single value (recursive helper)
|
|
59
|
-
*/
|
|
60
|
-
function sanitizeErrorValue(value) {
|
|
61
|
-
if (typeof value === 'string') {
|
|
62
|
-
return sanitizeText(value);
|
|
63
|
-
}
|
|
64
|
-
if (typeof value === 'object' && value !== null) {
|
|
65
|
-
return sanitizeError(value);
|
|
66
|
-
}
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Logs an error with sanitized output
|
|
71
|
-
* @param error - The error to log
|
|
72
|
-
*/
|
|
73
|
-
export function logSanitizedError(error) {
|
|
74
|
-
const sanitized = sanitizeError(error);
|
|
75
|
-
console.error('[NodeLLM Error]', sanitized);
|
|
76
|
-
}
|