@node-llm/core 0.8.0 → 1.0.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 -67
- package/dist/chat/Chat.d.ts +3 -2
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +4 -4
- package/dist/chat/ChatStream.d.ts +25 -0
- package/dist/chat/ChatStream.d.ts.map +1 -0
- package/dist/chat/ChatStream.js +93 -0
- package/dist/config.d.ts +4 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/embedding/Embedding.d.ts +1 -1
- package/dist/embedding/Embedding.d.ts.map +1 -1
- package/dist/errors/index.d.ts +22 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +32 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/llm.d.ts +2 -1
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +26 -28
- package/dist/models/ModelRegistry.d.ts +4 -0
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +15 -0
- package/dist/models/models.d.ts +729 -60
- package/dist/models/models.d.ts.map +1 -1
- package/dist/models/models.js +24375 -2312
- package/dist/models/types.d.ts +3 -3
- package/dist/models/types.d.ts.map +1 -1
- package/dist/models/types.js +3 -0
- package/dist/providers/BaseProvider.d.ts +21 -0
- package/dist/providers/BaseProvider.d.ts.map +1 -0
- package/dist/providers/BaseProvider.js +28 -0
- package/dist/providers/Provider.d.ts +19 -1
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +6 -7
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +16 -13
- package/dist/providers/anthropic/Streaming.d.ts +1 -1
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +80 -54
- package/dist/providers/deepseek/Capabilities.js +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +5 -1
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.js +15 -1
- package/dist/providers/deepseek/Streaming.d.ts +1 -1
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +80 -48
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Embeddings.d.ts +1 -1
- package/dist/providers/gemini/Embeddings.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.d.ts +6 -4
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +14 -4
- package/dist/providers/gemini/Streaming.d.ts +1 -1
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +62 -39
- package/dist/providers/ollama/Capabilities.d.ts.map +1 -1
- package/dist/providers/ollama/Capabilities.js +5 -1
- package/dist/providers/ollama/OllamaProvider.d.ts +1 -0
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
- package/dist/providers/ollama/OllamaProvider.js +3 -0
- package/dist/providers/openai/Embedding.d.ts +1 -1
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.d.ts +6 -3
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +15 -1
- package/dist/providers/openai/Streaming.d.ts +1 -1
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +75 -43
- package/dist/providers/openrouter/Capabilities.d.ts +13 -0
- package/dist/providers/openrouter/Capabilities.d.ts.map +1 -0
- package/dist/providers/openrouter/Capabilities.js +67 -0
- package/dist/providers/openrouter/Models.d.ts +11 -0
- package/dist/providers/openrouter/Models.d.ts.map +1 -0
- package/dist/providers/openrouter/Models.js +88 -0
- package/dist/providers/openrouter/OpenRouterProvider.d.ts +21 -0
- package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -0
- package/dist/providers/openrouter/OpenRouterProvider.js +24 -0
- package/dist/providers/openrouter/index.d.ts +11 -0
- package/dist/providers/openrouter/index.d.ts.map +1 -0
- package/dist/providers/openrouter/index.js +26 -0
- package/dist/providers/registry.d.ts +11 -1
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +14 -0
- package/dist/streaming/Stream.d.ts +29 -0
- package/dist/streaming/Stream.d.ts.map +1 -0
- package/dist/streaming/Stream.js +67 -0
- package/dist/utils/FileLoader.d.ts.map +1 -1
- package/dist/utils/FileLoader.js +34 -3
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +24 -0
- package/package.json +1 -1
- package/dist/chat/Stream.d.ts +0 -21
- package/dist/chat/Stream.d.ts.map +0 -1
- package/dist/chat/Stream.js +0 -73
- package/dist/providers/Embedding.d.ts +0 -20
- package/dist/providers/Embedding.d.ts.map +0 -1
- package/dist/providers/Embedding.js +0 -1
package/README.md
CHANGED
|
@@ -8,9 +8,40 @@
|
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
[](https://www.typescriptlang.org/)
|
|
10
10
|
|
|
11
|
-
**
|
|
11
|
+
**An opinionated architectural layer for using Large Language Models in Node.js.**
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
node-llm provides a unified, production-oriented API for interacting with over **540+ models** across multiple providers (OpenAI, Gemini, Anthropic, DeepSeek, OpenRouter, Ollama, etc.) without coupling your application to any single SDK.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ⚡ The Golden Path
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { LLM } from "@node-llm/core";
|
|
21
|
+
|
|
22
|
+
// 1. Configure once
|
|
23
|
+
LLM.configure({ provider: "openai" });
|
|
24
|
+
|
|
25
|
+
// 2. Chat (High-level request/response)
|
|
26
|
+
const chat = LLM.chat("gpt-4o");
|
|
27
|
+
const response = await chat.ask("Explain event-driven architecture");
|
|
28
|
+
console.log(response.content);
|
|
29
|
+
|
|
30
|
+
// 3. Streaming (Standard AsyncIterator)
|
|
31
|
+
for await (const chunk of chat.stream("Explain event-driven architecture")) {
|
|
32
|
+
process.stdout.write(chunk.content);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### Why node-llm?
|
|
39
|
+
|
|
40
|
+
Most AI integrations today are provider-specific and create long-term architectural risk. node-llm exists to solve these problems by providing:
|
|
41
|
+
|
|
42
|
+
- **Provider Isolation**: Your application never touches a provider SDK directly.
|
|
43
|
+
- **Unified Mental Model**: Tools, vision, and structured outputs feel identical across providers.
|
|
44
|
+
- **Production-First**: Core concern for streaming, retries, and error handling.
|
|
14
45
|
|
|
15
46
|
<br/>
|
|
16
47
|
|
|
@@ -26,6 +57,9 @@
|
|
|
26
57
|
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/deepseek-color.svg" height="28" />
|
|
27
58
|
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/deepseek-text.svg" height="20" />
|
|
28
59
|
|
|
60
|
+
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openrouter.svg" height="28" />
|
|
61
|
+
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openrouter-text.svg" height="22" />
|
|
62
|
+
|
|
29
63
|
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/ollama.svg" height="28" />
|
|
30
64
|
<img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/ollama-text.svg" height="18" />
|
|
31
65
|
</p>
|
|
@@ -34,69 +68,42 @@
|
|
|
34
68
|
|
|
35
69
|
---
|
|
36
70
|
|
|
37
|
-
## ⚡ Quick Example
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import { LLM } from "@node-llm/core";
|
|
41
|
-
|
|
42
|
-
// 1. Configure once
|
|
43
|
-
LLM.configure({ provider: "openai" });
|
|
44
|
-
|
|
45
|
-
// 2. Basic Chat
|
|
46
|
-
const chat = LLM.chat("gpt-4o");
|
|
47
|
-
const response = await chat.ask("Explain Node.js");
|
|
48
|
-
console.log(response.content);
|
|
49
|
-
|
|
50
|
-
// 3. Streaming
|
|
51
|
-
for await (const chunk of chat.stream("Explain Node.js")) {
|
|
52
|
-
process.stdout.write(chunk.content);
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
71
|
## 🔮 Capabilities
|
|
59
72
|
|
|
60
73
|
### 💬 Unified Chat
|
|
61
|
-
Stop rewriting code for every provider. `node-llm` normalizes inputs and outputs.
|
|
62
|
-
|
|
74
|
+
Stop rewriting code for every provider. `node-llm` normalizes inputs and outputs into a single, predictable mental model.
|
|
63
75
|
```ts
|
|
64
76
|
const chat = LLM.chat(); // Defaults to GPT-4o
|
|
65
77
|
await chat.ask("Hello world");
|
|
66
78
|
```
|
|
67
79
|
|
|
68
80
|
### 👁️ Smart Vision & Files
|
|
69
|
-
Pass images, PDFs, or audio files directly. We handle the base64 encoding and MIME
|
|
70
|
-
|
|
81
|
+
Pass images, PDFs, or audio files directly. We handle the heavy lifting: fetching remote URLs, base64 encoding, and MIME type mapping.
|
|
71
82
|
```ts
|
|
72
83
|
await chat.ask("Analyze this interface", {
|
|
73
|
-
files: ["./screenshot.png", "
|
|
84
|
+
files: ["./screenshot.png", "https://example.com/spec.pdf"]
|
|
74
85
|
});
|
|
75
86
|
```
|
|
76
87
|
|
|
77
88
|
### 🛠️ Auto-Executing Tools
|
|
78
|
-
Define tools once
|
|
79
|
-
|
|
89
|
+
Define tools once; node-llm manages the recursive execution loop for you, keeping your controller logic clean.
|
|
80
90
|
```ts
|
|
81
91
|
const tools = [{
|
|
82
|
-
|
|
83
|
-
function: { name: 'get_weather', ... }
|
|
84
|
-
handler: async ({ loc }) => `Sunny in ${loc}`
|
|
92
|
+
handler: async ({ loc }) => `Sunny in ${loc}`,
|
|
93
|
+
function: { name: 'get_weather', description: 'Get current weather', parameters: { ... } }
|
|
85
94
|
}];
|
|
86
95
|
|
|
87
96
|
await chat.withTools(tools).ask("Weather in Tokyo?");
|
|
88
97
|
```
|
|
89
98
|
|
|
90
99
|
### ✨ Structured Output
|
|
91
|
-
Get type-safe JSON back using **Zod** schemas.
|
|
92
|
-
|
|
100
|
+
Get type-safe, validated JSON back using **Zod** schemas.
|
|
93
101
|
```ts
|
|
94
102
|
import { z } from "zod";
|
|
95
|
-
|
|
96
103
|
const Product = z.object({ name: z.string(), price: z.number() });
|
|
97
|
-
const res = await chat.withSchema(Product).ask("Generate a gadget");
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
const res = await chat.withSchema(Product).ask("Generate a gadget");
|
|
106
|
+
console.log(res.parsed.name); // Full type-safety
|
|
100
107
|
```
|
|
101
108
|
|
|
102
109
|
### 🎨 Image Generation
|
|
@@ -110,39 +117,35 @@ await LLM.transcribe("meeting-recording.wav");
|
|
|
110
117
|
```
|
|
111
118
|
|
|
112
119
|
### 🧠 Deep Reasoning
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
Direct access to the thought process of models like **DeepSeek R1** or **OpenAI o1/o3** using the `.reasoning` field.
|
|
115
121
|
```ts
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
console.log(res.reasoning); // Output the model's inner thought process
|
|
120
|
-
console.log(res.content); // Output the final answer
|
|
122
|
+
const res = await LLM.chat("deepseek-reasoner").ask("Solve this logical puzzle");
|
|
123
|
+
console.log(res.reasoning); // Chain-of-thought
|
|
121
124
|
```
|
|
122
125
|
|
|
123
126
|
---
|
|
124
127
|
|
|
125
|
-
##
|
|
128
|
+
## 🚀 Why use this over official SDKs?
|
|
126
129
|
|
|
127
|
-
|
|
|
128
|
-
| :--- | :--- |
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/ollama.svg" height="18"> <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/ollama-text.svg" height="12"> | **Local Inference**, Chat, Streaming, Tools, Vision, Embeddings |
|
|
130
|
+
| Feature | node-llm | Official SDKs | Architectural Impact |
|
|
131
|
+
| :--- | :--- | :--- | :--- |
|
|
132
|
+
| **Provider Logic** | Transparently Handled | Exposed to your code | **Low Coupling** |
|
|
133
|
+
| **Streaming** | Standard `AsyncIterator` | Vendor-specific Events | **Predictable Data Flow** |
|
|
134
|
+
| **Tool Loops** | Automated Recursion | Manual implementation | **Reduced Boilerplate** |
|
|
135
|
+
| **Files/Vision** | Intelligent Path/URL handling | Base64/Buffer management | **Cleaner Service Layer** |
|
|
134
136
|
|
|
135
137
|
---
|
|
136
138
|
|
|
137
|
-
##
|
|
139
|
+
## 📋 Supported Providers
|
|
138
140
|
|
|
139
|
-
|
|
|
140
|
-
| :--- | :--- |
|
|
141
|
-
|
|
|
142
|
-
| **
|
|
143
|
-
| **
|
|
144
|
-
| **
|
|
145
|
-
| **
|
|
141
|
+
| Provider | Supported Features |
|
|
142
|
+
| :--- | :--- |
|
|
143
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openai.svg" height="18"> **OpenAI** | Chat, Streaming, Tools, Vision, Audio, Images, Transcription, **Reasoning** |
|
|
144
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/gemini-color.svg" height="18"> **Gemini** | Chat, Streaming, Tools, Vision, Audio, Video, Embeddings |
|
|
145
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/anthropic-text.svg" height="12"> **Anthropic** | Chat, Streaming, Tools, Vision, PDF, Structured Output |
|
|
146
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/deepseek-color.svg" height="18"> **DeepSeek** | Chat (V3), **Reasoning (R1)**, Tools, Streaming |
|
|
147
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openrouter.svg" height="18"> **OpenRouter** | **Aggregator**, Chat, Streaming, Tools, Vision, Embeddings, **Reasoning** |
|
|
148
|
+
| <img src="https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/ollama.svg" height="18"> **Ollama** | **Local Inference**, Chat, Streaming, Tools, Vision, Embeddings |
|
|
146
149
|
|
|
147
150
|
---
|
|
148
151
|
|
|
@@ -159,9 +162,3 @@ npm install @node-llm/core
|
|
|
159
162
|
## 🫶 Credits
|
|
160
163
|
|
|
161
164
|
Heavily inspired by the elegant design of [RubyLLM](https://rubyllm.com/).
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## 📄 License
|
|
166
|
-
|
|
167
|
-
MIT © [node-llm contributors]
|
package/dist/chat/Chat.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "./Message.js";
|
|
2
2
|
import { ChatOptions } from "./ChatOptions.js";
|
|
3
|
-
import { Provider, Usage } from "../providers/Provider.js";
|
|
3
|
+
import { Provider, Usage, ChatChunk } from "../providers/Provider.js";
|
|
4
|
+
import { Stream } from "../streaming/Stream.js";
|
|
4
5
|
import { Tool } from "./Tool.js";
|
|
5
6
|
import { Schema } from "../schema/Schema.js";
|
|
6
7
|
import { z } from "zod";
|
|
@@ -95,6 +96,6 @@ export declare class Chat {
|
|
|
95
96
|
/**
|
|
96
97
|
* Streams the model's response to a user question.
|
|
97
98
|
*/
|
|
98
|
-
stream(content: string):
|
|
99
|
+
stream(content: string): Stream<ChatChunk>;
|
|
99
100
|
}
|
|
100
101
|
//# sourceMappingURL=Chat.d.ts.map
|
package/dist/chat/Chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../src/chat/Chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../src/chat/Chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAItE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,IAAI;IAKb,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,QAAQ,CAAW;gBAGR,QAAQ,EAAE,QAAQ,EAC3B,KAAK,EAAE,MAA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C,YAAY,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI;IAKlE,UAAU,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAKlD,YAAY,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAKlD;;OAEG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgMrF;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;CAI3C"}
|
package/dist/chat/Chat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FileLoader } from "../utils/FileLoader.js";
|
|
2
2
|
import { Executor } from "../executor/Executor.js";
|
|
3
3
|
import { LLM } from "../llm.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ChatStream } from "./ChatStream.js";
|
|
5
5
|
import { Schema } from "../schema/Schema.js";
|
|
6
6
|
import { toJsonSchema } from "../schema/to-json-schema.js";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -355,8 +355,8 @@ export class Chat {
|
|
|
355
355
|
/**
|
|
356
356
|
* Streams the model's response to a user question.
|
|
357
357
|
*/
|
|
358
|
-
|
|
359
|
-
const streamer = new
|
|
360
|
-
|
|
358
|
+
stream(content) {
|
|
359
|
+
const streamer = new ChatStream(this.provider, this.model, this.options, this.messages);
|
|
360
|
+
return streamer.create(content);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Message } from "./Message.js";
|
|
2
|
+
import { ChatOptions } from "./ChatOptions.js";
|
|
3
|
+
import { Provider, ChatChunk } from "../providers/Provider.js";
|
|
4
|
+
import { Stream } from "../streaming/Stream.js";
|
|
5
|
+
/**
|
|
6
|
+
* Internal handler for chat streaming logic.
|
|
7
|
+
* Wraps the provider's stream with side effects like history updates and events.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ChatStream {
|
|
10
|
+
private readonly provider;
|
|
11
|
+
private readonly model;
|
|
12
|
+
private readonly options;
|
|
13
|
+
private messages;
|
|
14
|
+
constructor(provider: Provider, model: string, options?: ChatOptions, messages?: Message[]);
|
|
15
|
+
/**
|
|
16
|
+
* Read-only access to message history
|
|
17
|
+
*/
|
|
18
|
+
get history(): readonly Message[];
|
|
19
|
+
/**
|
|
20
|
+
* Creates a high-level Stream object for the chat response.
|
|
21
|
+
* @param content The user's question.
|
|
22
|
+
*/
|
|
23
|
+
create(content: string): Stream<ChatChunk>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ChatStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatStream.d.ts","sourceRoot":"","sources":["../../src/chat/ChatStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,UAAU;IAInB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,QAAQ,CAAY;gBAGT,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,EAC1C,QAAQ,CAAC,EAAE,OAAO,EAAE;IAmBtB;;OAEG;IACH,IAAI,OAAO,IAAI,SAAS,OAAO,EAAE,CAEhC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;CAyE3C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ChatResponseString } from "./ChatResponse.js";
|
|
2
|
+
import { Stream } from "../streaming/Stream.js";
|
|
3
|
+
/**
|
|
4
|
+
* Internal handler for chat streaming logic.
|
|
5
|
+
* Wraps the provider's stream with side effects like history updates and events.
|
|
6
|
+
*/
|
|
7
|
+
export class ChatStream {
|
|
8
|
+
provider;
|
|
9
|
+
model;
|
|
10
|
+
options;
|
|
11
|
+
messages;
|
|
12
|
+
constructor(provider, model, options = {}, messages) {
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
this.model = model;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.messages = messages ?? [];
|
|
17
|
+
// Only initialize if we're starting a new history
|
|
18
|
+
if (this.messages.length === 0) {
|
|
19
|
+
if (options.systemPrompt) {
|
|
20
|
+
this.messages.push({
|
|
21
|
+
role: "system",
|
|
22
|
+
content: options.systemPrompt,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (options.messages) {
|
|
26
|
+
this.messages.push(...options.messages);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read-only access to message history
|
|
32
|
+
*/
|
|
33
|
+
get history() {
|
|
34
|
+
return this.messages;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a high-level Stream object for the chat response.
|
|
38
|
+
* @param content The user's question.
|
|
39
|
+
*/
|
|
40
|
+
create(content) {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
// We create a wrapper async generator that handles our side effects
|
|
43
|
+
const sideEffectGenerator = async function* (provider, model, messages, options, abortController) {
|
|
44
|
+
messages.push({ role: "user", content });
|
|
45
|
+
if (!provider.stream) {
|
|
46
|
+
throw new Error("Streaming not supported by provider");
|
|
47
|
+
}
|
|
48
|
+
let full = "";
|
|
49
|
+
let fullReasoning = "";
|
|
50
|
+
let isFirst = true;
|
|
51
|
+
try {
|
|
52
|
+
for await (const chunk of provider.stream({
|
|
53
|
+
model,
|
|
54
|
+
messages,
|
|
55
|
+
temperature: options.temperature,
|
|
56
|
+
max_tokens: options.maxTokens,
|
|
57
|
+
signal: abortController.signal,
|
|
58
|
+
})) {
|
|
59
|
+
if (isFirst) {
|
|
60
|
+
if (options.onNewMessage)
|
|
61
|
+
options.onNewMessage();
|
|
62
|
+
isFirst = false;
|
|
63
|
+
}
|
|
64
|
+
if (chunk.content) {
|
|
65
|
+
full += chunk.content;
|
|
66
|
+
}
|
|
67
|
+
if (chunk.reasoning) {
|
|
68
|
+
fullReasoning += chunk.reasoning;
|
|
69
|
+
}
|
|
70
|
+
yield chunk;
|
|
71
|
+
}
|
|
72
|
+
// Finalize history
|
|
73
|
+
messages.push({
|
|
74
|
+
role: "assistant",
|
|
75
|
+
content: full,
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
reasoning: fullReasoning || undefined
|
|
78
|
+
});
|
|
79
|
+
if (options.onEndMessage) {
|
|
80
|
+
options.onEndMessage(new ChatResponseString(full, { input_tokens: 0, output_tokens: 0, total_tokens: 0 }, model, fullReasoning || undefined));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
85
|
+
// Stream was aborted, we might still want to save what we got?
|
|
86
|
+
// For now just rethrow or handle as needed
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return new Stream(() => sideEffectGenerator(this.provider, this.model, this.messages, this.options, controller), controller);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export interface NodeLLMConfig {
|
|
|
12
12
|
deepseekApiKey?: string;
|
|
13
13
|
deepseekApiBase?: string;
|
|
14
14
|
ollamaApiBase?: string;
|
|
15
|
-
|
|
15
|
+
openrouterApiKey?: string;
|
|
16
|
+
openrouterApiBase?: string;
|
|
16
17
|
}
|
|
17
18
|
declare class Configuration implements NodeLLMConfig {
|
|
18
19
|
openaiApiKey?: string;
|
|
@@ -24,7 +25,8 @@ declare class Configuration implements NodeLLMConfig {
|
|
|
24
25
|
deepseekApiKey?: string;
|
|
25
26
|
deepseekApiBase?: string;
|
|
26
27
|
ollamaApiBase?: string;
|
|
27
|
-
|
|
28
|
+
openrouterApiKey?: string;
|
|
29
|
+
openrouterApiBase?: string;
|
|
28
30
|
}
|
|
29
31
|
export declare const config: Configuration;
|
|
30
32
|
export {};
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,cAAM,aAAc,YAAW,aAAa;IACnC,YAAY,CAAC,EAAE,MAAM,CAAsC;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAuC;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAyC;IACjE,gBAAgB,CAAC,EAAE,MAAM,CAA0C;IACnE,YAAY,CAAC,EAAE,MAAM,CAAsC;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAuC;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAwC;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAyC;IACjE,aAAa,CAAC,EAAE,MAAM,CAAsE;IAC5F,gBAAgB,CAAC,EAAE,MAAM,CAA0C;IACnE,iBAAiB,CAAC,EAAE,MAAM,CAA2C;CAC7E;AAED,eAAO,MAAM,MAAM,eAAsB,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -8,5 +8,7 @@ class Configuration {
|
|
|
8
8
|
deepseekApiKey = process.env.DEEPSEEK_API_KEY?.trim();
|
|
9
9
|
deepseekApiBase = process.env.DEEPSEEK_API_BASE?.trim();
|
|
10
10
|
ollamaApiBase = process.env.OLLAMA_API_BASE?.trim() || "http://localhost:11434/v1";
|
|
11
|
+
openrouterApiKey = process.env.OPENROUTER_API_KEY?.trim();
|
|
12
|
+
openrouterApiBase = process.env.OPENROUTER_API_BASE?.trim();
|
|
11
13
|
}
|
|
12
14
|
export const config = new Configuration();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../src/embedding/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../src/embedding/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,qBAAa,SAAS;IACpB,SAAgB,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;IACpC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,QAAQ,EAAE,iBAAiB;IAOvC;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -63,4 +63,26 @@ export declare class NotFoundError extends LLMError {
|
|
|
63
63
|
export declare class CapabilityError extends LLMError {
|
|
64
64
|
constructor(message: string);
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when LLM provider is not configured
|
|
68
|
+
*/
|
|
69
|
+
export declare class ProviderNotConfiguredError extends LLMError {
|
|
70
|
+
constructor();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Thrown when a provider doesn't support a requested feature
|
|
74
|
+
*/
|
|
75
|
+
export declare class UnsupportedFeatureError extends LLMError {
|
|
76
|
+
readonly provider: string;
|
|
77
|
+
readonly feature: string;
|
|
78
|
+
constructor(provider: string, feature: string);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when a model doesn't support a requested capability
|
|
82
|
+
*/
|
|
83
|
+
export declare class ModelCapabilityError extends LLMError {
|
|
84
|
+
readonly model: string;
|
|
85
|
+
readonly capability: string;
|
|
86
|
+
constructor(model: string, capability: string);
|
|
87
|
+
}
|
|
66
88
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aACY,IAAI,CAAC,E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AM,EAAE,KAAK,CAAC,EAAE,MAAM;CAI1E;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,QAAQ;gBAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAI1F;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAI1F;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAG5B;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,QAAQ;;CAIvD;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,QAAQ;aAEjC,QAAQ,EAAE,MAAM;aAChB,OAAO,EAAE,MAAM;gBADf,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;CAIlC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;aAE9B,KAAK,EAAE,MAAM;aACb,UAAU,EAAE,MAAM;gBADlB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM;CAIrC"}
|
package/dist/errors/index.js
CHANGED
|
@@ -95,3 +95,35 @@ export class CapabilityError extends LLMError {
|
|
|
95
95
|
super(message, "CAPABILITY_ERROR");
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Thrown when LLM provider is not configured
|
|
100
|
+
*/
|
|
101
|
+
export class ProviderNotConfiguredError extends LLMError {
|
|
102
|
+
constructor() {
|
|
103
|
+
super("LLM provider not configured", "PROVIDER_NOT_CONFIGURED");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Thrown when a provider doesn't support a requested feature
|
|
108
|
+
*/
|
|
109
|
+
export class UnsupportedFeatureError extends LLMError {
|
|
110
|
+
provider;
|
|
111
|
+
feature;
|
|
112
|
+
constructor(provider, feature) {
|
|
113
|
+
super(`${provider} does not support ${feature}`, "UNSUPPORTED_FEATURE");
|
|
114
|
+
this.provider = provider;
|
|
115
|
+
this.feature = feature;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Thrown when a model doesn't support a requested capability
|
|
120
|
+
*/
|
|
121
|
+
export class ModelCapabilityError extends LLMError {
|
|
122
|
+
model;
|
|
123
|
+
capability;
|
|
124
|
+
constructor(model, capability) {
|
|
125
|
+
super(`Model ${model} does not support ${capability}`, "MODEL_CAPABILITY_ERROR");
|
|
126
|
+
this.model = model;
|
|
127
|
+
this.capability = capability;
|
|
128
|
+
}
|
|
129
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Chat } from "./chat/Chat.js";
|
|
2
|
-
export { Stream } from "./
|
|
2
|
+
export { Stream } from "./streaming/Stream.js";
|
|
3
3
|
export { GeneratedImage } from "./image/GeneratedImage.js";
|
|
4
4
|
export type { Message } from "./chat/Message.js";
|
|
5
5
|
export type { Role } from "./chat/Role.js";
|
|
@@ -11,10 +11,13 @@ export { LLM, Transcription, Moderation, Embedding } from "./llm.js";
|
|
|
11
11
|
export { config } from "./config.js";
|
|
12
12
|
export type { NodeLLMConfig } from "./config.js";
|
|
13
13
|
export { providerRegistry } from "./providers/registry.js";
|
|
14
|
+
export { BaseProvider } from "./providers/BaseProvider.js";
|
|
14
15
|
export { OpenAIProvider } from "./providers/openai/OpenAIProvider.js";
|
|
15
16
|
export { registerOpenAIProvider } from "./providers/openai/index.js";
|
|
16
17
|
export { registerAnthropicProvider } from "./providers/anthropic/index.js";
|
|
17
18
|
export { registerOllamaProvider, OllamaProvider } from "./providers/ollama/index.js";
|
|
19
|
+
export { OpenRouterProvider } from "./providers/openrouter/OpenRouterProvider.js";
|
|
20
|
+
export { registerOpenRouterProvider } from "./providers/registry.js";
|
|
18
21
|
export type { ImageRequest, ImageResponse } from "./providers/Provider.js";
|
|
19
22
|
export * from "./errors/index.js";
|
|
20
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export { Chat } from "./chat/Chat.js";
|
|
2
|
-
export { Stream } from "./
|
|
2
|
+
export { Stream } from "./streaming/Stream.js";
|
|
3
3
|
export { GeneratedImage } from "./image/GeneratedImage.js";
|
|
4
4
|
export { z } from "zod";
|
|
5
5
|
export { LLM, Transcription, Moderation, Embedding } from "./llm.js";
|
|
6
6
|
export { config } from "./config.js";
|
|
7
7
|
export { providerRegistry } from "./providers/registry.js";
|
|
8
|
+
export { BaseProvider } from "./providers/BaseProvider.js";
|
|
8
9
|
export { OpenAIProvider } from "./providers/openai/OpenAIProvider.js";
|
|
9
10
|
export { registerOpenAIProvider } from "./providers/openai/index.js";
|
|
10
11
|
export { registerAnthropicProvider } from "./providers/anthropic/index.js";
|
|
11
12
|
export { registerOllamaProvider, OllamaProvider } from "./providers/ollama/index.js";
|
|
13
|
+
export { OpenRouterProvider } from "./providers/openrouter/OpenRouterProvider.js";
|
|
14
|
+
export { registerOpenRouterProvider } from "./providers/registry.js";
|
|
12
15
|
export * from "./errors/index.js";
|
package/dist/llm.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ type LLMConfig = {
|
|
|
21
21
|
declare class LLMCore {
|
|
22
22
|
readonly models: typeof ModelRegistry;
|
|
23
23
|
readonly config: {
|
|
24
|
-
[key: string]: any;
|
|
25
24
|
openaiApiKey?: string;
|
|
26
25
|
openaiApiBase?: string;
|
|
27
26
|
anthropicApiKey?: string;
|
|
@@ -31,6 +30,8 @@ declare class LLMCore {
|
|
|
31
30
|
deepseekApiKey?: string;
|
|
32
31
|
deepseekApiBase?: string;
|
|
33
32
|
ollamaApiBase?: string;
|
|
33
|
+
openrouterApiKey?: string;
|
|
34
|
+
openrouterApiBase?: string;
|
|
34
35
|
};
|
|
35
36
|
private provider?;
|
|
36
37
|
private defaultTranscriptionModelId?;
|
package/dist/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,QAAQ,EACR,SAAS,EAKV,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,QAAQ,EACR,SAAS,EAKV,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;A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