@hilbras/sdk 1.5.0 → 2.1.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 +98 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://img.shields.io/badge/version-
|
|
2
|
+
<img src="https://img.shields.io/badge/version-2.0.0-blue" alt="version">
|
|
3
3
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="license">
|
|
4
4
|
<img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen" alt="node">
|
|
5
5
|
<img src="https://img.shields.io/badge/types-strict-blueviolet" alt="types">
|
|
6
|
-
<img src="https://img.shields.io/badge/tests-
|
|
6
|
+
<img src="https://img.shields.io/badge/tests-1541%20passing-brightgreen" alt="tests">
|
|
7
7
|
<img src="https://img.shields.io/badge/runtime%20deps-zero-brightgreen" alt="zero deps">
|
|
8
8
|
</p>
|
|
9
9
|
|
|
@@ -56,6 +56,12 @@ Application
|
|
|
56
56
|
npm install @hilbras/sdk
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
### React (optional)
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install @hilbras/react
|
|
63
|
+
```
|
|
64
|
+
|
|
59
65
|
## Quick start
|
|
60
66
|
|
|
61
67
|
```bash
|
|
@@ -107,7 +113,8 @@ const reply = await client.complete({
|
|
|
107
113
|
| **Reasoning normalization** | Detect & normalize `<thinking>` / `<reasoning>` tags and native fields | [API Reference](docs/api-reference.md) |
|
|
108
114
|
| **Agent framework** | ToolLoopAgent, ReActAgent, PlanAndExecuteAgent with approval, budget, cost tracking | [Agent](docs/agent.md) |
|
|
109
115
|
| **Evaluation** | LLM output evaluation with built-in metrics (exact_match, similarity, toxicity) | [Eval](docs/eval.md) |
|
|
110
|
-
| **
|
|
116
|
+
| **React hooks** | `useChat`, `useCompletion`, `useCost` with streaming, abort, retry | [React](#react-hooks) |
|
|
117
|
+
| **Framework hooks** | Vue, Svelte, Solid, Qwik, Angular, Next.js, Astro, Remix | [Frameworks](docs/frameworks.md) |
|
|
111
118
|
| **RAG primitives** | VectorStore, Retriever, RAGPipeline, chunking | [RAG](docs/rag.md) |
|
|
112
119
|
| **Provider catalog** | Runtime provider/model discovery with search | [Catalog](docs/catalog.md) |
|
|
113
120
|
| **CLI** | `hilbras` CLI for init, provider management, model listing, cost estimation | [CLI](docs/cli.md) |
|
|
@@ -118,6 +125,92 @@ const reply = await client.complete({
|
|
|
118
125
|
|
|
119
126
|
---
|
|
120
127
|
|
|
128
|
+
## React Hooks
|
|
129
|
+
|
|
130
|
+
First-class React integration via `@hilbras/react`. Zero runtime dependencies beyond React itself.
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install @hilbras/react
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### useChat — Streaming chat
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { HilbrasProvider, useChat } from "@hilbras/react";
|
|
140
|
+
|
|
141
|
+
function App() {
|
|
142
|
+
return (
|
|
143
|
+
<HilbrasProvider config={{ providers: [{ name: "openai", apiKey: process.env.OPENAI_API_KEY }] }}>
|
|
144
|
+
<Chat />
|
|
145
|
+
</HilbrasProvider>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function Chat() {
|
|
150
|
+
const { messages, input, setInput, handleSubmit, isLoading, stop, retry } = useChat({
|
|
151
|
+
provider: "openai",
|
|
152
|
+
model: "gpt-4o",
|
|
153
|
+
systemPrompt: "You are a helpful assistant.",
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div>
|
|
158
|
+
{messages.map((m) => (
|
|
159
|
+
<div key={m.id} className={m.role}>
|
|
160
|
+
{m.content}
|
|
161
|
+
</div>
|
|
162
|
+
))}
|
|
163
|
+
<form onSubmit={handleSubmit}>
|
|
164
|
+
<input value={input} onChange={(e) => setInput(e.target.value)} disabled={isLoading} />
|
|
165
|
+
<button type="submit" disabled={isLoading}>Send</button>
|
|
166
|
+
{isLoading && <button onClick={stop}>Stop</button>}
|
|
167
|
+
</form>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### useCompletion — Text completion
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
import { useCompletion } from "@hilbras/react";
|
|
177
|
+
|
|
178
|
+
function AutoComplete() {
|
|
179
|
+
const { completion, prompt, setPrompt, complete, isLoading } = useCompletion({
|
|
180
|
+
provider: "openai",
|
|
181
|
+
model: "gpt-4o",
|
|
182
|
+
systemPrompt: "Complete the following text:",
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div>
|
|
187
|
+
<textarea value={prompt} onChange={(e) => setPrompt(e.target.value)} />
|
|
188
|
+
<button onClick={() => complete()} disabled={isLoading}>Complete</button>
|
|
189
|
+
{completion && <div>{completion}</div>}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### useCost — Real-time cost tracking
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import { useCost } from "@hilbras/react";
|
|
199
|
+
|
|
200
|
+
function CostDisplay() {
|
|
201
|
+
const { snapshot, isBudgetLow } = useCost();
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div style={{ color: isBudgetLow ? "red" : "green" }}>
|
|
205
|
+
Cost: ${snapshot.totalCost.toFixed(4)} | Tokens: {snapshot.totalTokens}
|
|
206
|
+
{snapshot.remainingBudget != null && ` | Remaining: $${snapshot.remainingBudget.toFixed(2)}`}
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
121
214
|
## Documentation
|
|
122
215
|
|
|
123
216
|
- **[Getting Started](docs/getting-started.md)** — install, configure, first request
|
|
@@ -148,7 +241,7 @@ import { FetchTransport } from "@hilbras/sdk/transport/fetch"; // Transport
|
|
|
148
241
|
import { validateBaseUrl } from "@hilbras/sdk"; // SSRF guard
|
|
149
242
|
|
|
150
243
|
// Packages
|
|
151
|
-
import { useChat } from "@hilbras/react";
|
|
244
|
+
import { useChat, useCompletion, useCost, HilbrasProvider } from "@hilbras/react"; // React hooks
|
|
152
245
|
import { useChat } from "@hilbras/vue"; // Vue composables
|
|
153
246
|
import { useChat } from "@hilbras/svelte"; // Svelte stores
|
|
154
247
|
import { useChat } from "@hilbras/solid"; // Solid signals
|
|
@@ -168,7 +261,7 @@ import { exportTrainingData } from "@hilbras/fine-tune"; // Fine-tuning
|
|
|
168
261
|
```bash
|
|
169
262
|
npm install
|
|
170
263
|
npm run build # Compile TypeScript
|
|
171
|
-
npm test # Run
|
|
264
|
+
npm test # Run 1541 tests
|
|
172
265
|
npm run test:watch # Watch mode
|
|
173
266
|
npm run lint # Lint with oxlint
|
|
174
267
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilbras/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Provider-agnostic LLM client SDK — streaming, tool calling, embeddings, image generation, speech synthesis, transcription, reranking, circuit breaker, retry, reasoning normalization, cost enforcement, structured output with schema validation, type-safe tool builder, and SSRF-safe provider registration. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|