@elsium-ai/gateway 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 +57 -0
- package/dist/index.js +3 -4
- package/dist/router.d.ts +0 -1
- package/dist/router.d.ts.map +1 -1
- package/package.json +2 -3
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @elsium-ai/gateway
|
|
2
|
+
|
|
3
|
+
Multi-provider LLM gateway for [ElsiumAI](https://github.com/elsium-ai/elsium-ai).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@elsium-ai/gateway)
|
|
6
|
+
[](https://github.com/elsium-ai/elsium-ai/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @elsium-ai/gateway @elsium-ai/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## What's Inside
|
|
15
|
+
|
|
16
|
+
- **Multi-provider support** — Anthropic, OpenAI, Google out of the box
|
|
17
|
+
- **Provider Mesh** — Fallback, cost-optimized, latency-racing, and capability-aware routing
|
|
18
|
+
- **Middleware** — Composable logging, cost tracking, security, and X-Ray inspection
|
|
19
|
+
- **Bulkhead Isolation** — Bounds concurrency so one slow consumer can't starve others
|
|
20
|
+
- **Security** — Prompt injection detection, jailbreak detection, PII/secret redaction
|
|
21
|
+
- **X-Ray Mode** — Deep request/response inspection for debugging
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { gateway, createProviderMesh } from '@elsium-ai/gateway'
|
|
27
|
+
import { env } from '@elsium-ai/core'
|
|
28
|
+
|
|
29
|
+
// Single provider
|
|
30
|
+
const llm = gateway({
|
|
31
|
+
provider: 'anthropic',
|
|
32
|
+
model: 'claude-sonnet-4-6',
|
|
33
|
+
apiKey: env('ANTHROPIC_API_KEY'),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const response = await llm.complete({
|
|
37
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Multi-provider with fallback
|
|
41
|
+
const mesh = createProviderMesh({
|
|
42
|
+
providers: [
|
|
43
|
+
{ name: 'anthropic', config: { apiKey: env('ANTHROPIC_API_KEY') } },
|
|
44
|
+
{ name: 'openai', config: { apiKey: env('OPENAI_API_KEY') } },
|
|
45
|
+
],
|
|
46
|
+
strategy: 'fallback',
|
|
47
|
+
circuitBreaker: { failureThreshold: 5, resetTimeoutMs: 30_000 },
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Part of ElsiumAI
|
|
52
|
+
|
|
53
|
+
This package is the gateway 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.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](https://github.com/elsium-ai/elsium-ai/blob/main/LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @bun
|
|
2
1
|
// ../core/src/errors.ts
|
|
3
2
|
class ElsiumError extends Error {
|
|
4
3
|
code;
|
|
@@ -89,7 +88,7 @@ class ElsiumError extends Error {
|
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
// ../core/src/utils.ts
|
|
92
|
-
import { randomBytes } from "crypto";
|
|
91
|
+
import { randomBytes } from "node:crypto";
|
|
93
92
|
function cryptoHex(bytes) {
|
|
94
93
|
return randomBytes(bytes).toString("hex");
|
|
95
94
|
}
|
|
@@ -744,7 +743,7 @@ function resolveModelName(model) {
|
|
|
744
743
|
function calculateCost(model, usage) {
|
|
745
744
|
const pricing = PRICING[resolveModelName(model)];
|
|
746
745
|
if (!pricing) {
|
|
747
|
-
log.warn(`Unknown model "${model}"
|
|
746
|
+
log.warn(`Unknown model "${model}" — cost will be reported as $0. Register pricing with registerPricing().`);
|
|
748
747
|
return {
|
|
749
748
|
inputCost: 0,
|
|
750
749
|
outputCost: 0,
|
|
@@ -2388,7 +2387,7 @@ function createProviderMesh(config) {
|
|
|
2388
2387
|
retryable: false
|
|
2389
2388
|
});
|
|
2390
2389
|
}
|
|
2391
|
-
const sortedProviders = [...config.providers]
|
|
2390
|
+
const sortedProviders = [...config.providers];
|
|
2392
2391
|
const gateways = new Map;
|
|
2393
2392
|
const circuitBreakers = new Map;
|
|
2394
2393
|
for (const entry of sortedProviders) {
|
package/dist/router.d.ts
CHANGED
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAEN,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAEjB,MAAM,iBAAiB,CAAA;AAKxB,MAAM,MAAM,eAAe,GACxB,UAAU,GACV,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,CAAA;AAErB,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAEN,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAEjB,MAAM,iBAAiB,CAAA;AAKxB,MAAM,MAAM,eAAe,GACxB,UAAU,GACV,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,CAAA;AAErB,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAChD,YAAY,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IACjD,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,aAAa,EAAE,CAAA;IAC1B,QAAQ,EAAE,eAAe,CAAA;IACzB,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,cAAc,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAA;CAC/C;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1D,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAAA;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;CAClC;AAoDD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAoO3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elsium-ai/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Multi-provider LLM gateway for ElsiumAI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Utrera <ebutrera9103@gmail.com>",
|
|
@@ -22,7 +22,7 @@
|
|
|
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": {
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"zod": "^3.24.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"bun-types": "^1.3.0",
|
|
34
33
|
"typescript": "^5.7.0"
|
|
35
34
|
}
|
|
36
35
|
}
|