@node-llm/core 1.6.1 → 1.7.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 +64 -249
- package/dist/aliases.d.ts +2 -0
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +3 -1
- package/dist/chat/Chat.d.ts +10 -1
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +17 -3
- package/dist/chat/ChatOptions.d.ts +2 -1
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +5 -2
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +5 -2
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +15 -1
- package/dist/errors/index.d.ts +19 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/models/models.d.ts.map +1 -1
- package/dist/models/models.js +109 -20
- package/dist/providers/Provider.d.ts +32 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +23 -1
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +15 -0
- package/dist/providers/anthropic/types.d.ts +7 -1
- package/dist/providers/anthropic/types.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.js +9 -2
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +3 -2
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +18 -2
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +17 -2
- package/dist/providers/gemini/types.d.ts +4 -0
- package/dist/providers/gemini/types.d.ts.map +1 -1
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +18 -3
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +11 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CAkL9F"}
|
|
@@ -11,7 +11,7 @@ export class DeepSeekStreaming {
|
|
|
11
11
|
}
|
|
12
12
|
async *execute(request, controller) {
|
|
13
13
|
const abortController = controller || new AbortController();
|
|
14
|
-
const { model, messages, tools, max_tokens, response_format, headers: _headers, requestTimeout, ...rest } = request;
|
|
14
|
+
const { model, messages, tools, max_tokens, response_format, thinking: _thinking, headers: _headers, requestTimeout, ...rest } = request;
|
|
15
15
|
const mappedMessages = mapSystemMessages(messages, false);
|
|
16
16
|
const body = {
|
|
17
17
|
model,
|
|
@@ -100,7 +100,8 @@ export class DeepSeekStreaming {
|
|
|
100
100
|
if (deltaContent || deltaReasoning) {
|
|
101
101
|
yield {
|
|
102
102
|
content: deltaContent || "",
|
|
103
|
-
reasoning: deltaReasoning || ""
|
|
103
|
+
reasoning: deltaReasoning || "",
|
|
104
|
+
thinking: deltaReasoning ? { text: deltaReasoning } : undefined
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
// Handle tool calls delta
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS3D,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS3D,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAuI1D,OAAO,CAAC,cAAc;CAyBvB"}
|
|
@@ -37,6 +37,11 @@ export class GeminiChat {
|
|
|
37
37
|
},
|
|
38
38
|
...rest
|
|
39
39
|
};
|
|
40
|
+
if (request.thinking) {
|
|
41
|
+
payload.thinkingConfig = {
|
|
42
|
+
includeThoughts: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
40
45
|
if (systemInstructionParts.length > 0) {
|
|
41
46
|
payload.systemInstruction = { parts: systemInstructionParts };
|
|
42
47
|
}
|
|
@@ -65,8 +70,12 @@ export class GeminiChat {
|
|
|
65
70
|
const json = (await response.json());
|
|
66
71
|
logger.logResponse("Gemini", response.status, response.statusText, json);
|
|
67
72
|
const candidate = json.candidates?.[0];
|
|
73
|
+
const reasoningText = candidate?.content?.parts
|
|
74
|
+
?.filter((p) => p.thought)
|
|
75
|
+
.map((p) => p.text)
|
|
76
|
+
.join("\n") || null;
|
|
68
77
|
const content = candidate?.content?.parts
|
|
69
|
-
?.filter((p) => p.text)
|
|
78
|
+
?.filter((p) => !p.thought && p.text)
|
|
70
79
|
.map((p) => p.text)
|
|
71
80
|
.join("\n") || null;
|
|
72
81
|
const tool_calls = candidate?.content?.parts
|
|
@@ -89,7 +98,14 @@ export class GeminiChat {
|
|
|
89
98
|
const calculatedUsage = usage
|
|
90
99
|
? ModelRegistry.calculateCost(usage, request.model, "gemini")
|
|
91
100
|
: undefined;
|
|
92
|
-
|
|
101
|
+
const thinkingResult = reasoningText ? { text: reasoningText } : undefined;
|
|
102
|
+
return {
|
|
103
|
+
content,
|
|
104
|
+
tool_calls,
|
|
105
|
+
usage: calculatedUsage,
|
|
106
|
+
thinking: thinkingResult,
|
|
107
|
+
reasoning: reasoningText
|
|
108
|
+
};
|
|
93
109
|
}
|
|
94
110
|
sanitizeSchema(schema) {
|
|
95
111
|
if (typeof schema !== "object" || schema === null)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AASxD,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AASxD,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;IA+K7F,OAAO,CAAC,cAAc;CAyBvB"}
|
|
@@ -28,10 +28,20 @@ export class GeminiStreaming {
|
|
|
28
28
|
generationConfig.responseSchema = this.sanitizeSchema(request.response_format.json_schema.schema);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, requestTimeout: _requestTimeout, thinking: _thinking, ...rest } = request;
|
|
31
32
|
const payload = {
|
|
32
33
|
contents,
|
|
33
|
-
generationConfig
|
|
34
|
+
generationConfig: {
|
|
35
|
+
...generationConfig,
|
|
36
|
+
...(rest.generationConfig || {})
|
|
37
|
+
},
|
|
38
|
+
...rest
|
|
34
39
|
};
|
|
40
|
+
if (_thinking) {
|
|
41
|
+
payload.thinkingConfig = {
|
|
42
|
+
includeThoughts: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
35
45
|
if (systemInstructionParts.length > 0) {
|
|
36
46
|
payload.systemInstruction = { parts: systemInstructionParts };
|
|
37
47
|
}
|
|
@@ -98,7 +108,12 @@ export class GeminiStreaming {
|
|
|
98
108
|
const parts = json.candidates?.[0]?.content?.parts || [];
|
|
99
109
|
for (const part of parts) {
|
|
100
110
|
if (part.text) {
|
|
101
|
-
|
|
111
|
+
if (part.thought) {
|
|
112
|
+
yield { content: "", thinking: { text: part.text } };
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
yield { content: part.text };
|
|
116
|
+
}
|
|
102
117
|
}
|
|
103
118
|
// Handle function calls
|
|
104
119
|
if (part.functionCall) {
|
|
@@ -12,6 +12,7 @@ export interface GeminiPart {
|
|
|
12
12
|
name: string;
|
|
13
13
|
response: Record<string, unknown>;
|
|
14
14
|
};
|
|
15
|
+
thought?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export interface GeminiContent {
|
|
17
18
|
role?: "user" | "model";
|
|
@@ -42,6 +43,9 @@ export interface GeminiGenerateContentRequest {
|
|
|
42
43
|
category: string;
|
|
43
44
|
threshold: string;
|
|
44
45
|
}>;
|
|
46
|
+
thinkingConfig?: {
|
|
47
|
+
includeThoughts: boolean;
|
|
48
|
+
};
|
|
45
49
|
}
|
|
46
50
|
export interface GeminiGenerateContentResponse {
|
|
47
51
|
candidates?: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,YAAY,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,CAAC;IACF,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EA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B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,UAAU;IAInB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA+G3D"}
|
|
@@ -21,7 +21,7 @@ export class OpenAIChat {
|
|
|
21
21
|
(typeof this.providerOrUrl === "string"
|
|
22
22
|
? Capabilities.supportsDeveloperRole(request.model)
|
|
23
23
|
: this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
|
|
24
|
-
const { model, messages, tools, temperature: _, max_tokens, response_format, headers: _headers, requestTimeout: _requestTimeout, signal, ...rest } = request;
|
|
24
|
+
const { model, messages, tools, temperature: _, max_tokens, response_format, thinking, headers: _headers, requestTimeout: _requestTimeout, signal, ...rest } = request;
|
|
25
25
|
const mappedMessages = mapSystemMessages(messages, !!supportsDeveloperRole);
|
|
26
26
|
const body = {
|
|
27
27
|
model,
|
|
@@ -42,6 +42,9 @@ export class OpenAIChat {
|
|
|
42
42
|
body.tools = tools;
|
|
43
43
|
if (response_format)
|
|
44
44
|
body.response_format = response_format;
|
|
45
|
+
if (thinking?.effort && thinking.effort !== "none") {
|
|
46
|
+
body.reasoning_effort = thinking.effort;
|
|
47
|
+
}
|
|
45
48
|
const url = buildUrl(this.baseUrl, "/chat/completions");
|
|
46
49
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
47
50
|
const response = await fetchWithTimeout(url, {
|
|
@@ -62,7 +65,7 @@ export class OpenAIChat {
|
|
|
62
65
|
const message = json.choices[0]?.message;
|
|
63
66
|
const content = message?.content ?? null;
|
|
64
67
|
const tool_calls = message?.tool_calls;
|
|
65
|
-
const
|
|
68
|
+
const reasoningText = message?.reasoning_content || null;
|
|
66
69
|
const usage = json.usage
|
|
67
70
|
? {
|
|
68
71
|
input_tokens: json.usage.prompt_tokens,
|
|
@@ -72,10 +75,22 @@ export class OpenAIChat {
|
|
|
72
75
|
reasoning_tokens: json.usage.completion_tokens_details?.reasoning_tokens
|
|
73
76
|
}
|
|
74
77
|
: undefined;
|
|
78
|
+
const thinkingResult = reasoningText || usage?.reasoning_tokens
|
|
79
|
+
? {
|
|
80
|
+
text: reasoningText || undefined,
|
|
81
|
+
tokens: usage?.reasoning_tokens
|
|
82
|
+
}
|
|
83
|
+
: undefined;
|
|
75
84
|
if (!content && !tool_calls) {
|
|
76
85
|
throw new Error("OpenAI returned empty response");
|
|
77
86
|
}
|
|
78
87
|
const calculatedUsage = usage ? ModelRegistry.calculateCost(usage, model, "openai") : undefined;
|
|
79
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
content,
|
|
90
|
+
tool_calls,
|
|
91
|
+
usage: calculatedUsage,
|
|
92
|
+
thinking: thinkingResult,
|
|
93
|
+
reasoning: reasoningText
|
|
94
|
+
};
|
|
80
95
|
}
|
|
81
96
|
}
|
|
@@ -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;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,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;IAIxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAGd,aAAa,EAAE,cAAc,GAAG,MAAM,EACtC,MAAM,EAAE,MAAM;IAK1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CAoM9F"}
|
|
@@ -15,8 +15,9 @@ export class OpenAIStreaming {
|
|
|
15
15
|
this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
|
|
16
16
|
}
|
|
17
17
|
async *execute(request, controller) {
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const internalController = new AbortController();
|
|
19
|
+
const abortController = controller || internalController;
|
|
20
|
+
const signal = request.signal ? request.signal : abortController.signal;
|
|
20
21
|
const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
|
|
21
22
|
const isMainOpenAI = this.baseUrl.includes("api.openai.com");
|
|
22
23
|
const supportsDeveloperRole = isMainOpenAI &&
|
|
@@ -46,6 +47,9 @@ export class OpenAIStreaming {
|
|
|
46
47
|
if (request.tools && request.tools.length > 0) {
|
|
47
48
|
body.tools = request.tools;
|
|
48
49
|
}
|
|
50
|
+
if (request.thinking?.effort && request.thinking.effort !== "none") {
|
|
51
|
+
body.reasoning_effort = request.thinking.effort;
|
|
52
|
+
}
|
|
49
53
|
let done = false;
|
|
50
54
|
// Track tool calls being built across chunks
|
|
51
55
|
const toolCallsMap = new Map();
|
|
@@ -60,7 +64,7 @@ export class OpenAIStreaming {
|
|
|
60
64
|
...request.headers
|
|
61
65
|
},
|
|
62
66
|
body: JSON.stringify(body),
|
|
63
|
-
signal
|
|
67
|
+
signal
|
|
64
68
|
}, request.requestTimeout);
|
|
65
69
|
if (!response.ok) {
|
|
66
70
|
await handleOpenAIError(response, request.model);
|
|
@@ -119,6 +123,10 @@ export class OpenAIStreaming {
|
|
|
119
123
|
if (delta?.content) {
|
|
120
124
|
yield { content: delta.content };
|
|
121
125
|
}
|
|
126
|
+
// Handle reasoning content delta
|
|
127
|
+
if (delta?.reasoning_content) {
|
|
128
|
+
yield { content: "", thinking: { text: delta.reasoning_content } };
|
|
129
|
+
}
|
|
122
130
|
// Handle tool calls delta
|
|
123
131
|
if (delta?.tool_calls) {
|
|
124
132
|
for (const toolCallDelta of delta.tool_calls) {
|