@elsium-ai/core 0.1.6 → 0.2.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 +54 -0
- package/dist/index.js +2 -3
- package/package.json +2 -3
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)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @bun
|
|
2
1
|
// src/errors.ts
|
|
3
2
|
class ElsiumError extends Error {
|
|
4
3
|
code;
|
|
@@ -124,7 +123,7 @@ function tryCatchSync(fn) {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
// src/utils.ts
|
|
127
|
-
import { randomBytes } from "crypto";
|
|
126
|
+
import { randomBytes } from "node:crypto";
|
|
128
127
|
function cryptoHex(bytes) {
|
|
129
128
|
return randomBytes(bytes).toString("hex");
|
|
130
129
|
}
|
|
@@ -617,7 +616,7 @@ function createCircuitBreaker(config) {
|
|
|
617
616
|
};
|
|
618
617
|
}
|
|
619
618
|
// src/dedup.ts
|
|
620
|
-
import { createHash } from "crypto";
|
|
619
|
+
import { createHash } from "node:crypto";
|
|
621
620
|
function createDedup(config) {
|
|
622
621
|
const ttlMs = config?.ttlMs ?? 5000;
|
|
623
622
|
const maxEntries = config?.maxEntries ?? 1000;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elsium-ai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Core types, schemas, errors, and utilities for ElsiumAI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Utrera <ebutrera9103@gmail.com>",
|
|
@@ -22,14 +22,13 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target
|
|
25
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node && bun x tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
26
26
|
"dev": "bun --watch src/index.ts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^3.24.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"bun-types": "^1.3.0",
|
|
33
32
|
"typescript": "^5.7.0"
|
|
34
33
|
}
|
|
35
34
|
}
|