@kreuzberg/liter-llm-node 1.4.0-rc.19
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
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# TypeScript (Node.js)
|
|
2
|
+
|
|
3
|
+
<div align="center" style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0;">
|
|
4
|
+
<!-- Language Bindings -->
|
|
5
|
+
<a href="https://crates.io/crates/liter-llm">
|
|
6
|
+
<img src="https://img.shields.io/crates/v/liter-llm?label=Rust&color=007ec6" alt="Rust">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://pypi.org/project/liter-llm/">
|
|
9
|
+
<img src="https://img.shields.io/pypi/v/liter-llm?label=Python&color=007ec6" alt="Python">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@kreuzberg/liter-llm">
|
|
12
|
+
<img src="https://img.shields.io/npm/v/@kreuzberg/liter-llm?label=Node.js&color=007ec6" alt="Node.js">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@kreuzberg/liter-llm-wasm">
|
|
15
|
+
<img src="https://img.shields.io/npm/v/@kreuzberg/liter-llm-wasm?label=WASM&color=007ec6" alt="WASM">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://central.sonatype.com/artifact/dev.kreuzberg/liter-llm">
|
|
18
|
+
<img src="https://img.shields.io/maven-central/v/dev.kreuzberg/liter-llm?label=Java&color=007ec6" alt="Java">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://github.com/kreuzberg-dev/liter-llm/tree/main/packages/go">
|
|
21
|
+
<img src="https://img.shields.io/github/v/tag/kreuzberg-dev/liter-llm?label=Go&color=007ec6" alt="Go">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://www.nuget.org/packages/LiterLlm">
|
|
24
|
+
<img src="https://img.shields.io/nuget/v/LiterLlm?label=C%23&color=007ec6" alt="C#">
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://packagist.org/packages/kreuzberg/liter-llm">
|
|
27
|
+
<img src="https://img.shields.io/packagist/v/kreuzberg/liter-llm?label=PHP&color=007ec6" alt="PHP">
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://rubygems.org/gems/liter_llm">
|
|
30
|
+
<img src="https://img.shields.io/gem/v/liter_llm?label=Ruby&color=007ec6" alt="Ruby">
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://hex.pm/packages/liter_llm">
|
|
33
|
+
<img src="https://img.shields.io/hexpm/v/liter_llm?label=Elixir&color=007ec6" alt="Elixir">
|
|
34
|
+
</a>
|
|
35
|
+
<a href="https://github.com/kreuzberg-dev/liter-llm/pkgs/container/liter-llm">
|
|
36
|
+
<img src="https://img.shields.io/badge/Docker-007ec6?logo=docker&logoColor=white" alt="Docker">
|
|
37
|
+
</a>
|
|
38
|
+
<a href="https://github.com/kreuzberg-dev/homebrew-tap/blob/main/Formula/liter-llm.rb">
|
|
39
|
+
<img src="https://img.shields.io/badge/Homebrew-007ec6?logo=homebrew&logoColor=white" alt="Homebrew">
|
|
40
|
+
</a>
|
|
41
|
+
<a href="https://github.com/kreuzberg-dev/liter-llm/tree/main/crates/liter-llm-ffi">
|
|
42
|
+
<img src="https://img.shields.io/badge/C-FFI-007ec6" alt="C FFI">
|
|
43
|
+
</a>
|
|
44
|
+
|
|
45
|
+
<!-- Project Info -->
|
|
46
|
+
<a href="https://github.com/kreuzberg-dev/liter-llm/blob/main/LICENSE">
|
|
47
|
+
<img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License">
|
|
48
|
+
</a>
|
|
49
|
+
<a href="https://docs.liter-llm.kreuzberg.dev">
|
|
50
|
+
<img src="https://img.shields.io/badge/docs-kreuzberg.dev-007ec6" alt="Docs">
|
|
51
|
+
</a>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div align="center" style="margin: 20px 0;">
|
|
55
|
+
<picture>
|
|
56
|
+
<img width="100%" alt="kreuzberg.dev" src="https://github.com/user-attachments/assets/1b6c6ad7-3b6d-4171-b1c9-f2026cc9deb8" />
|
|
57
|
+
</picture>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div align="center" style="margin-bottom: 20px;">
|
|
61
|
+
<a href="https://discord.gg/xt9WY3GnKR">
|
|
62
|
+
<img height="22" src="https://img.shields.io/badge/Discord-Join%20our%20community-7289da?logo=discord&logoColor=white" alt="Discord">
|
|
63
|
+
</a>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
Universal LLM API client for TypeScript and Node.js. Access 143+ LLM providers through a single interface with native NAPI-RS bindings, async/await, streaming, tool calling, and full TypeScript type definitions.
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
### Package Installation
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
Install via one of the supported package managers:
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
**npm:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @kreuzberg/liter-llm
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
**pnpm:**
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pnpm add @kreuzberg/liter-llm
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
**yarn:**
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
yarn add @kreuzberg/liter-llm
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### System Requirements
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
- **Node.js 22+** required (NAPI-RS native bindings)
|
|
101
|
+
- API keys via environment variables (e.g. `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`)
|
|
102
|
+
|
|
103
|
+
### Platform Support
|
|
104
|
+
|
|
105
|
+
Pre-built binaries available for:
|
|
106
|
+
|
|
107
|
+
- macOS (arm64, x64)
|
|
108
|
+
- Linux (x64)
|
|
109
|
+
- Windows (x64)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Quick Start
|
|
113
|
+
|
|
114
|
+
### Basic Chat
|
|
115
|
+
|
|
116
|
+
Send a message to any provider using the `provider/model` prefix:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { LlmClient } from "@kreuzberg/liter-llm";
|
|
120
|
+
|
|
121
|
+
const client = new LlmClient({ apiKey: process.env.OPENAI_API_KEY! });
|
|
122
|
+
const response = await client.chat({
|
|
123
|
+
model: "openai/gpt-4o",
|
|
124
|
+
messages: [{ role: "user", content: "Hello!" }],
|
|
125
|
+
});
|
|
126
|
+
console.log(response.choices[0].message.content);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Common Use Cases
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
#### Streaming Responses
|
|
133
|
+
|
|
134
|
+
Stream tokens in real time:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { LlmClient } from "@kreuzberg/liter-llm";
|
|
138
|
+
|
|
139
|
+
const client = new LlmClient({ apiKey: process.env.OPENAI_API_KEY! });
|
|
140
|
+
const chunks = await client.chatStream({
|
|
141
|
+
model: "openai/gpt-4o",
|
|
142
|
+
messages: [{ role: "user", content: "Tell me a story" }],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
for (const chunk of chunks) {
|
|
146
|
+
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
|
|
147
|
+
}
|
|
148
|
+
console.log();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
#### Tool Calling
|
|
153
|
+
|
|
154
|
+
Define and invoke tools:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { LlmClient } from "@kreuzberg/liter-llm";
|
|
158
|
+
|
|
159
|
+
const client = new LlmClient({ apiKey: process.env.OPENAI_API_KEY! });
|
|
160
|
+
|
|
161
|
+
const tools = [
|
|
162
|
+
{
|
|
163
|
+
type: "function" as const,
|
|
164
|
+
function: {
|
|
165
|
+
name: "get_weather",
|
|
166
|
+
description: "Get the current weather for a location",
|
|
167
|
+
parameters: {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: {
|
|
170
|
+
location: { type: "string", description: "City name" },
|
|
171
|
+
},
|
|
172
|
+
required: ["location"],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
const response = await client.chat({
|
|
179
|
+
model: "openai/gpt-4o",
|
|
180
|
+
messages: [{ role: "user", content: "What is the weather in Berlin?" }],
|
|
181
|
+
tools,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
for (const call of response.choices[0]?.message?.toolCalls ?? []) {
|
|
185
|
+
console.log(`Tool: ${call.function.name}, Args: ${call.function.arguments}`);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
### Next Steps
|
|
191
|
+
|
|
192
|
+
- **[Provider Registry](https://github.com/kreuzberg-dev/liter-llm/blob/main/schemas/providers.json)** - Full list of supported providers
|
|
193
|
+
- **[GitHub Repository](https://github.com/kreuzberg-dev/liter-llm)** - Source, issues, and discussions
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## NAPI-RS Implementation Details
|
|
197
|
+
|
|
198
|
+
### Native Performance
|
|
199
|
+
|
|
200
|
+
This binding uses NAPI-RS to provide native Node.js bindings with:
|
|
201
|
+
|
|
202
|
+
- **Zero-copy data transfer** between JavaScript and Rust layers
|
|
203
|
+
- **Async by default** — all LLM calls return Promises backed by Tokio
|
|
204
|
+
- **Binary-compatible** pre-built native modules across platforms
|
|
205
|
+
- **TypeScript definitions** generated automatically from Rust types
|
|
206
|
+
|
|
207
|
+
### Threading Model
|
|
208
|
+
|
|
209
|
+
- LLM calls are non-blocking — Tokio async runtime handles concurrency
|
|
210
|
+
- Streaming responses use Node.js async iterators backed by Tokio streams
|
|
211
|
+
- CPU-bound work runs in `spawn_blocking` to avoid blocking the event loop
|
|
212
|
+
|
|
213
|
+
### Memory Management
|
|
214
|
+
|
|
215
|
+
- API keys are wrapped in `secrecy::SecretString` and never logged
|
|
216
|
+
- Streaming buffers are released as soon as each chunk is consumed
|
|
217
|
+
- Provider registry is compiled into the binary — no runtime disk access
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## Features
|
|
221
|
+
|
|
222
|
+
### Supported Providers (143+)
|
|
223
|
+
|
|
224
|
+
Route to any provider using the `provider/model` prefix convention:
|
|
225
|
+
|
|
226
|
+
| Provider | Example Model |
|
|
227
|
+
|----------|--------------|
|
|
228
|
+
| **OpenAI** | `openai/gpt-4o`, `openai/gpt-4o-mini` |
|
|
229
|
+
| **Anthropic** | `anthropic/claude-3-5-sonnet-20241022` |
|
|
230
|
+
| **Groq** | `groq/llama-3.1-70b-versatile` |
|
|
231
|
+
| **Mistral** | `mistral/mistral-large-latest` |
|
|
232
|
+
| **Cohere** | `cohere/command-r-plus` |
|
|
233
|
+
| **Together AI** | `together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo` |
|
|
234
|
+
| **Fireworks** | `fireworks/accounts/fireworks/models/llama-v3p1-70b-instruct` |
|
|
235
|
+
| **Google Vertex** | `vertexai/gemini-1.5-pro` |
|
|
236
|
+
| **Amazon Bedrock** | `bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0` |
|
|
237
|
+
|
|
238
|
+
**[Complete Provider List](https://github.com/kreuzberg-dev/liter-llm/blob/main/schemas/providers.json)**
|
|
239
|
+
|
|
240
|
+
### Key Capabilities
|
|
241
|
+
|
|
242
|
+
- **Provider Routing** -- Single client for 143+ LLM providers via `provider/model` prefix
|
|
243
|
+
- **Local LLMs** — Connect to locally-hosted models via Ollama, LM Studio, vLLM, llama.cpp, and other local inference servers
|
|
244
|
+
- **Unified API** -- Consistent `chat`, `chat_stream`, `embeddings`, `list_models` interface
|
|
245
|
+
|
|
246
|
+
- **Streaming** -- Real-time token streaming via `chat_stream`
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
- **Tool Calling** -- Function calling and tool use across all supporting providers
|
|
250
|
+
|
|
251
|
+
- **Type Safe** -- Schema-driven types compiled from JSON schemas
|
|
252
|
+
- **Secure** -- API keys never logged or serialized, managed via environment variables
|
|
253
|
+
- **Observability** -- Built-in [OpenTelemetry](https://opentelemetry.io/docs/specs/semconv/gen-ai/) with GenAI semantic conventions
|
|
254
|
+
- **Error Handling** -- Structured errors with provider context and retry hints
|
|
255
|
+
|
|
256
|
+
### Performance
|
|
257
|
+
|
|
258
|
+
Built on a compiled Rust core for speed and safety:
|
|
259
|
+
|
|
260
|
+
- **Provider resolution** at client construction -- zero per-request overhead
|
|
261
|
+
- **Configurable timeouts** and connection pooling
|
|
262
|
+
- **Zero-copy streaming** with SSE and AWS EventStream support
|
|
263
|
+
- **API keys** wrapped in secure memory, zeroed on drop
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## Provider Routing
|
|
267
|
+
|
|
268
|
+
Route to 143+ providers using the `provider/model` prefix convention:
|
|
269
|
+
|
|
270
|
+
```text
|
|
271
|
+
openai/gpt-4o
|
|
272
|
+
anthropic/claude-3-5-sonnet-20241022
|
|
273
|
+
groq/llama-3.1-70b-versatile
|
|
274
|
+
mistral/mistral-large-latest
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
See the [provider registry](https://github.com/kreuzberg-dev/liter-llm/blob/main/schemas/providers.json) for the full list.
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
## Proxy Server
|
|
281
|
+
|
|
282
|
+
liter-llm also ships as an OpenAI-compatible proxy server with Docker support:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
docker run -p 4000:4000 -e LITER_LLM_MASTER_KEY=sk-your-key ghcr.io/kreuzberg-dev/liter-llm
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
See the [proxy server documentation](https://docs.liter-llm.kreuzberg.dev/server/proxy/) for configuration, CLI usage, and MCP integration.
|
|
289
|
+
|
|
290
|
+
## Documentation
|
|
291
|
+
|
|
292
|
+
- **[Documentation](https://docs.liter-llm.kreuzberg.dev)** -- Full docs and API reference
|
|
293
|
+
- **[GitHub Repository](https://github.com/kreuzberg-dev/liter-llm)** -- Source, issues, and discussions
|
|
294
|
+
- **[Provider Registry](https://github.com/kreuzberg-dev/liter-llm/blob/main/schemas/providers.json)** -- 143 supported providers
|
|
295
|
+
|
|
296
|
+
Part of [kreuzberg.dev](https://kreuzberg.dev).
|
|
297
|
+
|
|
298
|
+
## Contributing
|
|
299
|
+
|
|
300
|
+
Contributions are welcome! See [CONTRIBUTING.md](https://github.com/kreuzberg-dev/liter-llm/blob/main/CONTRIBUTING.md) for guidelines.
|
|
301
|
+
|
|
302
|
+
Join our [Discord community](https://discord.gg/xt9WY3GnKR) for questions and discussion.
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
MIT -- see [LICENSE](https://github.com/kreuzberg-dev/liter-llm/blob/main/LICENSE) for details.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
// This file is auto-generated by alef — DO NOT EDIT.
|
|
2
|
+
// alef:hash:1a6eb53e1357f456099c9528315e1c745cd3d4df0f88e11e313e50c27b025426
|
|
3
|
+
// To regenerate: alef generate
|
|
4
|
+
// To verify freshness: alef verify --exit-code
|
|
5
|
+
// Issues & docs: https://github.com/kreuzberg-dev/alef
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a new LLM client with simple scalar configuration.
|
|
10
|
+
*
|
|
11
|
+
* This is the primary binding entry-point. All parameters except `api_key`
|
|
12
|
+
* are optional — omitting them uses the same defaults as
|
|
13
|
+
* [`ClientConfigBuilder`].
|
|
14
|
+
*
|
|
15
|
+
* # Errors
|
|
16
|
+
*
|
|
17
|
+
* Returns [`LiterLlmError`] if the underlying HTTP client cannot be
|
|
18
|
+
* constructed, or if the resolved provider configuration is invalid.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createClient(
|
|
21
|
+
apiKey: string,
|
|
22
|
+
baseUrl?: string | undefined | null,
|
|
23
|
+
timeoutSecs?: number | undefined | null,
|
|
24
|
+
maxRetries?: number | undefined | null,
|
|
25
|
+
modelHint?: string | undefined | null,
|
|
26
|
+
): JsDefaultClient;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create a new LLM client from a JSON string.
|
|
30
|
+
*
|
|
31
|
+
* The JSON object accepts the same fields as `liter-llm.toml` (snake_case).
|
|
32
|
+
*
|
|
33
|
+
* # Errors
|
|
34
|
+
*
|
|
35
|
+
* Returns [`LiterLlmError::BadRequest`] if `json` is not valid JSON or
|
|
36
|
+
* contains unknown fields.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createClientFromJson(json: string): JsDefaultClient;
|
|
39
|
+
|
|
40
|
+
export interface JsAssistantMessage {
|
|
41
|
+
content: string;
|
|
42
|
+
name: string;
|
|
43
|
+
toolCalls: Array<JsToolCall>;
|
|
44
|
+
refusal: string;
|
|
45
|
+
/** Deprecated legacy function_call field; retained for API compatibility. */
|
|
46
|
+
functionCall: JsFunctionCall;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface JsAudioContent {
|
|
50
|
+
/** Base64-encoded audio data. */
|
|
51
|
+
data: string;
|
|
52
|
+
/** Audio format (e.g., "wav", "mp3", "ogg"). */
|
|
53
|
+
format: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** How the API key is sent in the HTTP request. */
|
|
57
|
+
export declare enum JsAuthHeaderFormat {
|
|
58
|
+
/** Bearer token: `Authorization: Bearer <key>` */
|
|
59
|
+
Bearer = "Bearer",
|
|
60
|
+
/** Custom header: e.g., `X-Api-Key: <key>` */
|
|
61
|
+
ApiKey = "ApiKey",
|
|
62
|
+
/** No authentication required. */
|
|
63
|
+
None = "None",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface JsChatCompletionChunk {
|
|
67
|
+
id: string;
|
|
68
|
+
/**
|
|
69
|
+
* Always `"chat.completion.chunk"` from OpenAI-compatible APIs. Stored
|
|
70
|
+
* as a plain `String` so non-standard provider values do not fail parsing.
|
|
71
|
+
*/
|
|
72
|
+
object: string;
|
|
73
|
+
created: number;
|
|
74
|
+
model: string;
|
|
75
|
+
choices: Array<JsStreamChoice>;
|
|
76
|
+
usage: JsUsage;
|
|
77
|
+
systemFingerprint: string;
|
|
78
|
+
serviceTier: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface JsChatCompletionRequest {
|
|
82
|
+
model: string;
|
|
83
|
+
messages: Array<JsMessage>;
|
|
84
|
+
temperature: number;
|
|
85
|
+
topP: number;
|
|
86
|
+
n: number;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to stream the response.
|
|
89
|
+
*
|
|
90
|
+
* Managed by the client layer — do not set directly.
|
|
91
|
+
*/
|
|
92
|
+
stream: boolean;
|
|
93
|
+
stop: JsStopSequence;
|
|
94
|
+
maxTokens: number;
|
|
95
|
+
presencePenalty: number;
|
|
96
|
+
frequencyPenalty: number;
|
|
97
|
+
/**
|
|
98
|
+
* Token bias map. Uses `BTreeMap` (sorted keys) for deterministic
|
|
99
|
+
* serialization order — important when hashing or signing requests.
|
|
100
|
+
*/
|
|
101
|
+
logitBias: Record<string, number>;
|
|
102
|
+
user: string;
|
|
103
|
+
tools: Array<JsChatCompletionTool>;
|
|
104
|
+
toolChoice: JsToolChoice;
|
|
105
|
+
parallelToolCalls: boolean;
|
|
106
|
+
responseFormat: JsResponseFormat;
|
|
107
|
+
streamOptions: JsStreamOptions;
|
|
108
|
+
seed: number;
|
|
109
|
+
reasoningEffort: JsReasoningEffort;
|
|
110
|
+
/**
|
|
111
|
+
* Provider-specific extra parameters merged into the request body.
|
|
112
|
+
* Use for guardrails, safety settings, grounding config, etc.
|
|
113
|
+
*/
|
|
114
|
+
extraBody: unknown;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface JsChatCompletionResponse {
|
|
118
|
+
id: string;
|
|
119
|
+
/**
|
|
120
|
+
* Always `"chat.completion"` from OpenAI-compatible APIs. Stored as a
|
|
121
|
+
* plain `String` so non-standard provider values do not break deserialization.
|
|
122
|
+
*/
|
|
123
|
+
object: string;
|
|
124
|
+
created: number;
|
|
125
|
+
model: string;
|
|
126
|
+
choices: Array<JsChoice>;
|
|
127
|
+
usage: JsUsage;
|
|
128
|
+
systemFingerprint: string;
|
|
129
|
+
serviceTier: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface JsChatCompletionTool {
|
|
133
|
+
toolType: JsToolType;
|
|
134
|
+
function: JsFunctionDefinition;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface JsChoice {
|
|
138
|
+
index: number;
|
|
139
|
+
message: JsAssistantMessage;
|
|
140
|
+
finishReason: JsFinishReason;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type JsContentPart =
|
|
144
|
+
| { type: "text"; text: string }
|
|
145
|
+
| { type: "image_url"; imageUrl: JsImageUrl }
|
|
146
|
+
| { type: "document"; document: JsDocumentContent }
|
|
147
|
+
| { type: "input_audio"; inputAudio: JsAudioContent };
|
|
148
|
+
|
|
149
|
+
/** Request to create images from a text prompt. */
|
|
150
|
+
export interface JsCreateImageRequest {
|
|
151
|
+
prompt: string;
|
|
152
|
+
model: string;
|
|
153
|
+
n: number;
|
|
154
|
+
size: string;
|
|
155
|
+
quality: string;
|
|
156
|
+
style: string;
|
|
157
|
+
responseFormat: string;
|
|
158
|
+
user: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Request to generate speech audio from text. */
|
|
162
|
+
export interface JsCreateSpeechRequest {
|
|
163
|
+
model: string;
|
|
164
|
+
input: string;
|
|
165
|
+
voice: string;
|
|
166
|
+
responseFormat: string;
|
|
167
|
+
speed: number;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Request to transcribe audio into text. */
|
|
171
|
+
export interface JsCreateTranscriptionRequest {
|
|
172
|
+
model: string;
|
|
173
|
+
/** Base64-encoded audio file data. */
|
|
174
|
+
file: string;
|
|
175
|
+
language: string;
|
|
176
|
+
prompt: string;
|
|
177
|
+
responseFormat: string;
|
|
178
|
+
temperature: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Configuration for registering a custom LLM provider at runtime. */
|
|
182
|
+
export interface JsCustomProviderConfig {
|
|
183
|
+
/** Unique name for this provider (e.g., "my-provider"). */
|
|
184
|
+
name: string;
|
|
185
|
+
/** Base URL for the provider's API (e.g., "https://api.my-provider.com/v1"). */
|
|
186
|
+
baseUrl: string;
|
|
187
|
+
/** Authentication header format. */
|
|
188
|
+
authHeader: JsAuthHeaderFormat;
|
|
189
|
+
/** Model name prefixes that route to this provider (e.g., ["my-"]). */
|
|
190
|
+
modelPrefixes: Array<string>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Default client implementation backed by `reqwest`.
|
|
195
|
+
*
|
|
196
|
+
* The provider is resolved at construction time from `model_hint` (or
|
|
197
|
+
* defaults to OpenAI). However, individual requests can override the
|
|
198
|
+
* provider when their model string contains a prefix that clearly
|
|
199
|
+
* identifies a different provider (e.g. `"anthropic/claude-3"` will
|
|
200
|
+
* route to Anthropic even if the client was built without a hint).
|
|
201
|
+
*
|
|
202
|
+
* When the model prefix does not match any known provider, the
|
|
203
|
+
* construction-time provider is used as the fallback.
|
|
204
|
+
*
|
|
205
|
+
* The provider is stored behind an [`Arc`] so it can be shared cheaply into
|
|
206
|
+
* async closures and streaming tasks that must be `'static`.
|
|
207
|
+
*/
|
|
208
|
+
export declare class JsDefaultClient {
|
|
209
|
+
chat(req: JsChatCompletionRequest): Promise<JsChatCompletionResponse>;
|
|
210
|
+
chatStream(req: JsChatCompletionRequest): Promise<string>;
|
|
211
|
+
embed(req: JsEmbeddingRequest): Promise<JsEmbeddingResponse>;
|
|
212
|
+
listModels(): Promise<JsModelsListResponse>;
|
|
213
|
+
imageGenerate(req: JsCreateImageRequest): Promise<JsImagesResponse>;
|
|
214
|
+
transcribe(
|
|
215
|
+
req: JsCreateTranscriptionRequest,
|
|
216
|
+
): Promise<JsTranscriptionResponse>;
|
|
217
|
+
moderate(req: JsModerationRequest): Promise<JsModerationResponse>;
|
|
218
|
+
rerank(req: JsRerankRequest): Promise<JsRerankResponse>;
|
|
219
|
+
search(req: JsSearchRequest): Promise<JsSearchResponse>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface JsDeveloperMessage {
|
|
223
|
+
content: string;
|
|
224
|
+
name: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface JsDocumentContent {
|
|
228
|
+
/** Base64-encoded document data or URL. */
|
|
229
|
+
data: string;
|
|
230
|
+
/** MIME type (e.g., "application/pdf", "text/csv"). */
|
|
231
|
+
mediaType: string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The format in which the embedding vectors are returned. */
|
|
235
|
+
export declare enum JsEmbeddingFormat {
|
|
236
|
+
/** 32-bit floating-point numbers (default). */
|
|
237
|
+
Float = "float",
|
|
238
|
+
/** Base64-encoded string representation of the floats. */
|
|
239
|
+
Base64 = "base64",
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export declare enum JsEmbeddingInput {
|
|
243
|
+
Single = "Single",
|
|
244
|
+
Multiple = "Multiple",
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface JsEmbeddingObject {
|
|
248
|
+
/**
|
|
249
|
+
* Always `"embedding"` from OpenAI-compatible APIs. Stored as a plain
|
|
250
|
+
* `String` so non-standard provider values do not break deserialization.
|
|
251
|
+
*/
|
|
252
|
+
object: string;
|
|
253
|
+
embedding: Array<number>;
|
|
254
|
+
index: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface JsEmbeddingRequest {
|
|
258
|
+
model: string;
|
|
259
|
+
input: JsEmbeddingInput;
|
|
260
|
+
encodingFormat: JsEmbeddingFormat;
|
|
261
|
+
dimensions: number;
|
|
262
|
+
user: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface JsEmbeddingResponse {
|
|
266
|
+
/**
|
|
267
|
+
* Always `"list"` from OpenAI-compatible APIs. Stored as a plain
|
|
268
|
+
* `String` so non-standard provider values do not break deserialization.
|
|
269
|
+
*/
|
|
270
|
+
object: string;
|
|
271
|
+
data: Array<JsEmbeddingObject>;
|
|
272
|
+
model: string;
|
|
273
|
+
usage: JsUsage;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Why a choice stopped generating tokens. */
|
|
277
|
+
export declare enum JsFinishReason {
|
|
278
|
+
Stop = "stop",
|
|
279
|
+
Length = "length",
|
|
280
|
+
ToolCalls = "tool_calls",
|
|
281
|
+
ContentFilter = "content_filter",
|
|
282
|
+
/** Deprecated legacy finish reason; retained for API compatibility. */
|
|
283
|
+
FunctionCall = "function_call",
|
|
284
|
+
/**
|
|
285
|
+
* Catch-all for unknown finish reasons returned by non-OpenAI providers.
|
|
286
|
+
*
|
|
287
|
+
* Note: this intentionally does **not** carry the original string (e.g.
|
|
288
|
+
* `Other(String)`). Using `#[serde(other)]` requires a unit variant, and
|
|
289
|
+
* switching to `#[serde(untagged)]` would change deserialization semantics
|
|
290
|
+
* for all variants. The original value can be recovered by inspecting the
|
|
291
|
+
* raw JSON if needed.
|
|
292
|
+
*/
|
|
293
|
+
Other = "other",
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface JsFunctionCall {
|
|
297
|
+
name: string;
|
|
298
|
+
arguments: string;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface JsFunctionDefinition {
|
|
302
|
+
name: string;
|
|
303
|
+
description: string;
|
|
304
|
+
parameters: unknown;
|
|
305
|
+
strict: boolean;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Deprecated legacy function-role message body. */
|
|
309
|
+
export interface JsFunctionMessage {
|
|
310
|
+
content: string;
|
|
311
|
+
name: string;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** A single generated image, returned as either a URL or base64 data. */
|
|
315
|
+
export interface JsImage {
|
|
316
|
+
url: string;
|
|
317
|
+
b64Json: string;
|
|
318
|
+
revisedPrompt: string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export declare enum JsImageDetail {
|
|
322
|
+
Low = "low",
|
|
323
|
+
High = "high",
|
|
324
|
+
Auto = "auto",
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Response containing generated images. */
|
|
328
|
+
export interface JsImagesResponse {
|
|
329
|
+
created: number;
|
|
330
|
+
data: Array<JsImage>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface JsImageUrl {
|
|
334
|
+
url: string;
|
|
335
|
+
detail: JsImageDetail;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface JsJsonSchemaFormat {
|
|
339
|
+
name: string;
|
|
340
|
+
description: string;
|
|
341
|
+
schema: unknown;
|
|
342
|
+
strict: boolean;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export declare class JsLiterLlmError {}
|
|
346
|
+
|
|
347
|
+
/** A chat message in a conversation. */
|
|
348
|
+
export type JsMessage =
|
|
349
|
+
| { role: "system"; 0: JsSystemMessage }
|
|
350
|
+
| { role: "user"; 0: JsUserMessage }
|
|
351
|
+
| { role: "assistant"; 0: JsAssistantMessage }
|
|
352
|
+
| { role: "tool"; 0: JsToolMessage }
|
|
353
|
+
| { role: "developer"; 0: JsDeveloperMessage }
|
|
354
|
+
| { role: "function"; 0: JsFunctionMessage };
|
|
355
|
+
|
|
356
|
+
export interface JsModelObject {
|
|
357
|
+
id: string;
|
|
358
|
+
/**
|
|
359
|
+
* Always `"model"` from OpenAI-compatible APIs. Stored as a plain
|
|
360
|
+
* `String` so non-standard provider values do not break deserialization.
|
|
361
|
+
*/
|
|
362
|
+
object: string;
|
|
363
|
+
created: number;
|
|
364
|
+
ownedBy: string;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface JsModelsListResponse {
|
|
368
|
+
/**
|
|
369
|
+
* Always `"list"` from OpenAI-compatible APIs. Stored as a plain
|
|
370
|
+
* `String` so non-standard provider values do not break deserialization.
|
|
371
|
+
*/
|
|
372
|
+
object: string;
|
|
373
|
+
data: Array<JsModelObject>;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Boolean flags for each moderation category. */
|
|
377
|
+
export interface JsModerationCategories {
|
|
378
|
+
sexual: boolean;
|
|
379
|
+
hate: boolean;
|
|
380
|
+
harassment: boolean;
|
|
381
|
+
selfHarm: boolean;
|
|
382
|
+
sexualMinors: boolean;
|
|
383
|
+
hateThreatening: boolean;
|
|
384
|
+
violenceGraphic: boolean;
|
|
385
|
+
selfHarmIntent: boolean;
|
|
386
|
+
selfHarmInstructions: boolean;
|
|
387
|
+
harassmentThreatening: boolean;
|
|
388
|
+
violence: boolean;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Confidence scores for each moderation category. */
|
|
392
|
+
export interface JsModerationCategoryScores {
|
|
393
|
+
sexual: number;
|
|
394
|
+
hate: number;
|
|
395
|
+
harassment: number;
|
|
396
|
+
selfHarm: number;
|
|
397
|
+
sexualMinors: number;
|
|
398
|
+
hateThreatening: number;
|
|
399
|
+
violenceGraphic: number;
|
|
400
|
+
selfHarmIntent: number;
|
|
401
|
+
selfHarmInstructions: number;
|
|
402
|
+
harassmentThreatening: number;
|
|
403
|
+
violence: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** Input to the moderation endpoint — a single string or multiple strings. */
|
|
407
|
+
export declare enum JsModerationInput {
|
|
408
|
+
Single = "Single",
|
|
409
|
+
Multiple = "Multiple",
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** Request to classify content for policy violations. */
|
|
413
|
+
export interface JsModerationRequest {
|
|
414
|
+
input: JsModerationInput;
|
|
415
|
+
model: string;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Response from the moderation endpoint. */
|
|
419
|
+
export interface JsModerationResponse {
|
|
420
|
+
id: string;
|
|
421
|
+
model: string;
|
|
422
|
+
results: Array<JsModerationResult>;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** A single moderation classification result. */
|
|
426
|
+
export interface JsModerationResult {
|
|
427
|
+
flagged: boolean;
|
|
428
|
+
categories: JsModerationCategories;
|
|
429
|
+
categoryScores: JsModerationCategoryScores;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** Document input for OCR — either a URL or inline base64 data. */
|
|
433
|
+
export type JsOcrDocument =
|
|
434
|
+
| { type: "document_url"; url: string }
|
|
435
|
+
| { type: "base64"; data: string; mediaType: string };
|
|
436
|
+
|
|
437
|
+
/** An image extracted from an OCR page. */
|
|
438
|
+
export interface JsOcrImage {
|
|
439
|
+
/** Unique image identifier. */
|
|
440
|
+
id: string;
|
|
441
|
+
/** Base64-encoded image data. */
|
|
442
|
+
imageBase64: string;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** A single page of OCR output. */
|
|
446
|
+
export interface JsOcrPage {
|
|
447
|
+
/** Page index (0-based). */
|
|
448
|
+
index: number;
|
|
449
|
+
/** Extracted content as Markdown. */
|
|
450
|
+
markdown: string;
|
|
451
|
+
/** Extracted images, if `include_image_base64` was set. */
|
|
452
|
+
images: Array<JsOcrImage>;
|
|
453
|
+
/** Page dimensions in pixels, if available. */
|
|
454
|
+
dimensions: JsPageDimensions;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** An OCR request. */
|
|
458
|
+
export interface JsOcrRequest {
|
|
459
|
+
/** The model/provider to use (e.g. `"mistral/mistral-ocr-latest"`). */
|
|
460
|
+
model: string;
|
|
461
|
+
/** The document to process. */
|
|
462
|
+
document: JsOcrDocument;
|
|
463
|
+
/** Specific pages to process (1-indexed). `None` means all pages. */
|
|
464
|
+
pages: Array<number>;
|
|
465
|
+
/** Whether to include base64-encoded images of each page. */
|
|
466
|
+
includeImageBase64: boolean;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** An OCR response. */
|
|
470
|
+
export interface JsOcrResponse {
|
|
471
|
+
/** Extracted pages. */
|
|
472
|
+
pages: Array<JsOcrPage>;
|
|
473
|
+
/** The model used. */
|
|
474
|
+
model: string;
|
|
475
|
+
/** Token usage, if reported by the provider. */
|
|
476
|
+
usage: JsUsage;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Page dimensions in pixels. */
|
|
480
|
+
export interface JsPageDimensions {
|
|
481
|
+
/** Width in pixels. */
|
|
482
|
+
width: number;
|
|
483
|
+
/** Height in pixels. */
|
|
484
|
+
height: number;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Controls how much reasoning effort the model should use. */
|
|
488
|
+
export declare enum JsReasoningEffort {
|
|
489
|
+
Low = "low",
|
|
490
|
+
Medium = "medium",
|
|
491
|
+
High = "high",
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** A document to be reranked — either a plain string or an object with a text field. */
|
|
495
|
+
export declare enum JsRerankDocument {
|
|
496
|
+
Text = "Text",
|
|
497
|
+
Object = "Object",
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Request to rerank documents by relevance to a query. */
|
|
501
|
+
export interface JsRerankRequest {
|
|
502
|
+
model: string;
|
|
503
|
+
query: string;
|
|
504
|
+
documents: Array<JsRerankDocument>;
|
|
505
|
+
topN: number;
|
|
506
|
+
returnDocuments: boolean;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** Response from the rerank endpoint. */
|
|
510
|
+
export interface JsRerankResponse {
|
|
511
|
+
id: string;
|
|
512
|
+
results: Array<JsRerankResult>;
|
|
513
|
+
meta: unknown;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** A single reranked document with its relevance score. */
|
|
517
|
+
export interface JsRerankResult {
|
|
518
|
+
index: number;
|
|
519
|
+
relevanceScore: number;
|
|
520
|
+
document: JsRerankResultDocument;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** The text content of a reranked document, returned when `return_documents` is true. */
|
|
524
|
+
export interface JsRerankResultDocument {
|
|
525
|
+
text: string;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export type JsResponseFormat =
|
|
529
|
+
| { type: "text" }
|
|
530
|
+
| { type: "json_object" }
|
|
531
|
+
| { type: "json_schema"; jsonSchema: JsJsonSchemaFormat };
|
|
532
|
+
|
|
533
|
+
/** A search request. */
|
|
534
|
+
export interface JsSearchRequest {
|
|
535
|
+
/** The model/provider to use (e.g. `"brave/web-search"`, `"tavily/search"`). */
|
|
536
|
+
model: string;
|
|
537
|
+
/** The search query. */
|
|
538
|
+
query: string;
|
|
539
|
+
/** Maximum number of results to return. */
|
|
540
|
+
maxResults: number;
|
|
541
|
+
/** Domain filter — restrict results to specific domains. */
|
|
542
|
+
searchDomainFilter: Array<string>;
|
|
543
|
+
/** Country code for localized results (ISO 3166-1 alpha-2). */
|
|
544
|
+
country: string;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** A search response. */
|
|
548
|
+
export interface JsSearchResponse {
|
|
549
|
+
/** The search results. */
|
|
550
|
+
results: Array<JsSearchResult>;
|
|
551
|
+
/** The model used. */
|
|
552
|
+
model: string;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** An individual search result. */
|
|
556
|
+
export interface JsSearchResult {
|
|
557
|
+
/** Title of the result. */
|
|
558
|
+
title: string;
|
|
559
|
+
/** URL of the result. */
|
|
560
|
+
url: string;
|
|
561
|
+
/** Text snippet / excerpt. */
|
|
562
|
+
snippet: string;
|
|
563
|
+
/** Publication or last-updated date, if available. */
|
|
564
|
+
date: string;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export interface JsSpecificFunction {
|
|
568
|
+
name: string;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export interface JsSpecificToolChoice {
|
|
572
|
+
choiceType: JsToolType;
|
|
573
|
+
function: JsSpecificFunction;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export declare enum JsStopSequence {
|
|
577
|
+
Single = "Single",
|
|
578
|
+
Multiple = "Multiple",
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export interface JsStreamChoice {
|
|
582
|
+
index: number;
|
|
583
|
+
delta: JsStreamDelta;
|
|
584
|
+
finishReason: JsFinishReason;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export interface JsStreamDelta {
|
|
588
|
+
role: string;
|
|
589
|
+
content: string;
|
|
590
|
+
toolCalls: Array<JsStreamToolCall>;
|
|
591
|
+
/** Deprecated legacy function_call delta; retained for API compatibility. */
|
|
592
|
+
functionCall: JsStreamFunctionCall;
|
|
593
|
+
refusal: string;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export interface JsStreamFunctionCall {
|
|
597
|
+
name: string;
|
|
598
|
+
arguments: string;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export interface JsStreamOptions {
|
|
602
|
+
includeUsage: boolean;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export interface JsStreamToolCall {
|
|
606
|
+
index: number;
|
|
607
|
+
id: string;
|
|
608
|
+
callType: JsToolType;
|
|
609
|
+
function: JsStreamFunctionCall;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export interface JsSystemMessage {
|
|
613
|
+
content: string;
|
|
614
|
+
name: string;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
export interface JsToolCall {
|
|
618
|
+
id: string;
|
|
619
|
+
callType: JsToolType;
|
|
620
|
+
function: JsFunctionCall;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export declare enum JsToolChoice {
|
|
624
|
+
Mode = "Mode",
|
|
625
|
+
Specific = "Specific",
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export declare enum JsToolChoiceMode {
|
|
629
|
+
Auto = "auto",
|
|
630
|
+
Required = "required",
|
|
631
|
+
None = "none",
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export interface JsToolMessage {
|
|
635
|
+
content: string;
|
|
636
|
+
toolCallId: string;
|
|
637
|
+
name: string;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* The type discriminator for tool/tool-call objects.
|
|
642
|
+
*
|
|
643
|
+
* Per the OpenAI spec this is always `"function"`. Using an enum enforces
|
|
644
|
+
* that constraint at the type level and rejects any other value on
|
|
645
|
+
* deserialization.
|
|
646
|
+
*/
|
|
647
|
+
export declare enum JsToolType {
|
|
648
|
+
Function = "function",
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** Response from a transcription request. */
|
|
652
|
+
export interface JsTranscriptionResponse {
|
|
653
|
+
text: string;
|
|
654
|
+
language: string;
|
|
655
|
+
duration: number;
|
|
656
|
+
segments: Array<JsTranscriptionSegment>;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** A segment of transcribed audio with timing information. */
|
|
660
|
+
export interface JsTranscriptionSegment {
|
|
661
|
+
id: number;
|
|
662
|
+
start: number;
|
|
663
|
+
end: number;
|
|
664
|
+
text: string;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export interface JsUsage {
|
|
668
|
+
/** Prompt tokens used. Defaults to 0 when absent (some providers omit this). */
|
|
669
|
+
promptTokens: number;
|
|
670
|
+
/** Completion tokens used. Defaults to 0 when absent (e.g. embedding responses). */
|
|
671
|
+
completionTokens: number;
|
|
672
|
+
/** Total tokens used. Defaults to 0 when absent (some providers omit this). */
|
|
673
|
+
totalTokens: number;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export declare enum JsUserContent {
|
|
677
|
+
Text = "Text",
|
|
678
|
+
Parts = "Parts",
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export interface JsUserMessage {
|
|
682
|
+
content: JsUserContent;
|
|
683
|
+
name: string;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Register a custom provider in the global runtime registry.
|
|
688
|
+
*
|
|
689
|
+
* The provider will be checked **before** all built-in providers during model
|
|
690
|
+
* detection. If a provider with the same `name` already exists it is replaced.
|
|
691
|
+
*
|
|
692
|
+
* # Errors
|
|
693
|
+
*
|
|
694
|
+
* Returns an error if the config is invalid (empty name, empty base_url, or
|
|
695
|
+
* no model prefixes).
|
|
696
|
+
*/
|
|
697
|
+
export declare function registerCustomProvider(
|
|
698
|
+
config: JsCustomProviderConfig,
|
|
699
|
+
): void;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Remove a previously registered custom provider by name.
|
|
703
|
+
*
|
|
704
|
+
* Returns `true` if a provider with the given name was found and removed,
|
|
705
|
+
* `false` if no such provider existed.
|
|
706
|
+
*
|
|
707
|
+
* # Errors
|
|
708
|
+
*
|
|
709
|
+
* Returns an error only if the internal lock is poisoned.
|
|
710
|
+
*/
|
|
711
|
+
export declare function unregisterCustomProvider(name: string): boolean;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kreuzberg/liter-llm-node",
|
|
3
|
+
"version": "1.4.0-rc.19",
|
|
4
|
+
"description": "Native NAPI-RS bindings for liter-llm \u2014 high-performance LLM client powered by Rust",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"*.node"
|
|
11
|
+
],
|
|
12
|
+
"napi": {
|
|
13
|
+
"binaryName": "liter-llm-node",
|
|
14
|
+
"targets": [
|
|
15
|
+
"aarch64-apple-darwin",
|
|
16
|
+
"x86_64-unknown-linux-gnu",
|
|
17
|
+
"aarch64-unknown-linux-gnu",
|
|
18
|
+
"x86_64-pc-windows-msvc"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">= 22"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/kreuzberg-dev/liter-llm.git"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/kreuzberg-dev/liter-llm",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/kreuzberg-dev/liter-llm/issues"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"llm",
|
|
35
|
+
"llm-client",
|
|
36
|
+
"openai",
|
|
37
|
+
"anthropic",
|
|
38
|
+
"streaming",
|
|
39
|
+
"tool-calling",
|
|
40
|
+
"napi",
|
|
41
|
+
"rust",
|
|
42
|
+
"native"
|
|
43
|
+
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"registry": "https://registry.npmjs.org/",
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"artifacts": "napi artifacts",
|
|
50
|
+
"build": "napi build --platform --release",
|
|
51
|
+
"prepublishOnly": "napi prepublish -t npm --skip-optional-publish"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@napi-rs/cli": "^3.6.2"
|
|
55
|
+
}
|
|
56
|
+
}
|