@elsium-ai/core 0.1.6 → 0.1.7
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 +54 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @elsium-ai/core
|
|
2
|
+
|
|
3
|
+
Core types, schemas, errors, and utilities for [ElsiumAI](https://github.com/elsium-ai/elsium-ai).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@elsium-ai/core)
|
|
6
|
+
[](https://github.com/elsium-ai/elsium-ai/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @elsium-ai/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## What's Inside
|
|
15
|
+
|
|
16
|
+
- **Types** — `CompletionRequest`, `LLMResponse`, `Message`, `Middleware`, and all shared interfaces
|
|
17
|
+
- **Circuit Breaker** — Detects failing providers, stops sending traffic, auto-recovers
|
|
18
|
+
- **Request Dedup** — Identical in-flight calls coalesce into one API request
|
|
19
|
+
- **Policy Engine** — Declarative rules to deny by model, cost, token count, or content pattern
|
|
20
|
+
- **Graceful Shutdown** — Drains in-flight operations before process exit
|
|
21
|
+
- **Retry with Backoff** — Exponential backoff with jitter
|
|
22
|
+
- **Logger** — Structured logging with levels and context
|
|
23
|
+
- **Config** — Type-safe environment variable access via `env()`
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import {
|
|
29
|
+
createCircuitBreaker,
|
|
30
|
+
createPolicySet,
|
|
31
|
+
modelAccessPolicy,
|
|
32
|
+
costLimitPolicy,
|
|
33
|
+
policyMiddleware,
|
|
34
|
+
env,
|
|
35
|
+
} from '@elsium-ai/core'
|
|
36
|
+
|
|
37
|
+
// Circuit breaker
|
|
38
|
+
const cb = createCircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 30_000 })
|
|
39
|
+
const result = await cb.execute(() => fetchFromProvider())
|
|
40
|
+
|
|
41
|
+
// Policy engine
|
|
42
|
+
const policies = createPolicySet([
|
|
43
|
+
modelAccessPolicy(['claude-sonnet-4-6', 'gpt-4o']),
|
|
44
|
+
costLimitPolicy(5.00),
|
|
45
|
+
])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Part of ElsiumAI
|
|
49
|
+
|
|
50
|
+
This package is the foundation layer of the [ElsiumAI](https://github.com/elsium-ai/elsium-ai) framework. See the [full documentation](https://github.com/elsium-ai/elsium-ai) for guides and examples.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
[MIT](https://github.com/elsium-ai/elsium-ai/blob/main/LICENSE)
|