@elsium-ai/gateway 0.1.6

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.
@@ -0,0 +1,19 @@
1
+ import type { Logger, Middleware, XRayData } from '@elsium-ai/core';
2
+ export declare function composeMiddleware(middlewares: Middleware[]): Middleware;
3
+ export declare function loggingMiddleware(logger?: Logger): Middleware;
4
+ export declare function costTrackingMiddleware(): Middleware & {
5
+ getTotalCost(): number;
6
+ getTotalTokens(): number;
7
+ getCallCount(): number;
8
+ reset(): void;
9
+ };
10
+ export interface XRayStore {
11
+ lastCall(): XRayData | null;
12
+ callHistory(limit?: number): XRayData[];
13
+ getByTraceId(traceId: string): XRayData | undefined;
14
+ clear(): void;
15
+ }
16
+ export declare function xrayMiddleware(options?: {
17
+ maxHistory?: number;
18
+ }): Middleware & XRayStore;
19
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,MAAM,EACN,UAAU,EAGV,QAAQ,EACR,MAAM,iBAAiB,CAAA;AAIxB,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU,CAoBvE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAyB7D;AAED,wBAAgB,sBAAsB,IAAI,UAAU,GAAG;IACtD,YAAY,IAAI,MAAM,CAAA;IACtB,cAAc,IAAI,MAAM,CAAA;IACxB,YAAY,IAAI,MAAM,CAAA;IACtB,KAAK,IAAI,IAAI,CAAA;CACb,CAuBA;AAkBD,MAAM,WAAW,SAAS;IACzB,QAAQ,IAAI,QAAQ,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;IACvC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IACnD,KAAK,IAAI,IAAI,CAAA;CACb;AAkFD,wBAAgB,cAAc,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,UAAU,GAAG,SAAS,CA4B5F"}
@@ -0,0 +1,5 @@
1
+ import type { CostBreakdown, TokenUsage } from '@elsium-ai/core';
2
+ import type { ModelPricing } from './provider';
3
+ export declare function calculateCost(model: string, usage: TokenUsage): CostBreakdown;
4
+ export declare function registerPricing(model: string, pricing: ModelPricing): void;
5
+ //# sourceMappingURL=pricing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA0C9C,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,aAAa,CAwB7E;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAE1E"}
@@ -0,0 +1,31 @@
1
+ import type { CompletionRequest, ElsiumStream, LLMResponse, ProviderConfig } from '@elsium-ai/core';
2
+ export interface ModelPricing {
3
+ inputPerMillion: number;
4
+ outputPerMillion: number;
5
+ }
6
+ export interface ModelTier {
7
+ tier: 'low' | 'mid' | 'high';
8
+ costPerMToken: number;
9
+ }
10
+ export interface ProviderMetadata {
11
+ baseUrl?: string;
12
+ capabilities?: string[];
13
+ pricing?: Record<string, ModelPricing>;
14
+ modelTiers?: Record<string, ModelTier>;
15
+ authStyle?: 'bearer' | 'x-api-key' | 'query-param';
16
+ }
17
+ export interface LLMProvider {
18
+ readonly name: string;
19
+ readonly defaultModel: string;
20
+ readonly metadata?: ProviderMetadata;
21
+ complete(request: CompletionRequest): Promise<LLMResponse>;
22
+ stream(request: CompletionRequest): ElsiumStream;
23
+ listModels(): Promise<string[]>;
24
+ }
25
+ export type ProviderFactory = (config: ProviderConfig) => LLMProvider;
26
+ export declare function registerProvider(name: string, factory: ProviderFactory): void;
27
+ export declare function getProviderFactory(name: string): ProviderFactory | undefined;
28
+ export declare function listProviders(): string[];
29
+ export declare function registerProviderMetadata(name: string, metadata: ProviderMetadata): void;
30
+ export declare function getProviderMetadata(name: string): ProviderMetadata | undefined;
31
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEnG,MAAM,WAAW,YAAY;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;IAC5B,aAAa,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACtC,SAAS,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAA;CAClD;AAED,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAEpC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1D,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAAA;IAChD,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;CAC/B;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK,WAAW,CAAA;AAKrE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAE7E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAE5E;AAED,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAEvF;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAE9E"}
@@ -0,0 +1,4 @@
1
+ import { type ProviderConfig } from '@elsium-ai/core';
2
+ import type { LLMProvider } from '../provider';
3
+ export declare function createAnthropicProvider(config: ProviderConfig): LLMProvider;
4
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,cAAc,EASnB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AA2C9C,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAuT3E"}
@@ -0,0 +1,4 @@
1
+ import { type ProviderConfig } from '@elsium-ai/core';
2
+ import type { LLMProvider } from '../provider';
3
+ export declare function createGoogleProvider(config: ProviderConfig): LLMProvider;
4
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,cAAc,EASnB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAmC9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAiPxE"}
@@ -0,0 +1,4 @@
1
+ import { type ProviderConfig } from '@elsium-ai/core';
2
+ import type { LLMProvider } from '../provider';
3
+ export declare function createOpenAIProvider(config: ProviderConfig): LLMProvider;
4
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,cAAc,EASnB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAgD9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAmRxE"}
@@ -0,0 +1,38 @@
1
+ import type { CompletionRequest, LLMResponse } from '@elsium-ai/core';
2
+ import { type CircuitBreakerConfig, type ElsiumStream } from '@elsium-ai/core';
3
+ export type RoutingStrategy = 'fallback' | 'cost-optimized' | 'latency-optimized' | 'capability-aware';
4
+ export interface ProviderEntry {
5
+ name: string;
6
+ config: {
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ };
10
+ model?: string;
11
+ priority?: number;
12
+ capabilities?: string[];
13
+ }
14
+ export interface CostOptimizerConfig {
15
+ simpleModel: {
16
+ provider: string;
17
+ model: string;
18
+ };
19
+ complexModel: {
20
+ provider: string;
21
+ model: string;
22
+ };
23
+ complexityThreshold?: number;
24
+ }
25
+ export interface ProviderMeshConfig {
26
+ providers: ProviderEntry[];
27
+ strategy: RoutingStrategy;
28
+ costOptimizer?: CostOptimizerConfig;
29
+ circuitBreaker?: CircuitBreakerConfig | boolean;
30
+ }
31
+ export interface ProviderMesh {
32
+ complete(request: CompletionRequest): Promise<LLMResponse>;
33
+ stream(request: CompletionRequest): ElsiumStream;
34
+ readonly providers: string[];
35
+ readonly strategy: RoutingStrategy;
36
+ }
37
+ export declare function createProviderMesh(config: ProviderMeshConfig): ProviderMesh;
38
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +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,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,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,CAsO3E"}
@@ -0,0 +1,33 @@
1
+ import type { Middleware } from '@elsium-ai/core';
2
+ export interface SecurityViolation {
3
+ type: 'prompt_injection' | 'jailbreak' | 'secret_detected' | 'blocked_pattern';
4
+ detail: string;
5
+ severity: 'low' | 'medium' | 'high';
6
+ }
7
+ export interface SecurityResult {
8
+ safe: boolean;
9
+ violations: SecurityViolation[];
10
+ }
11
+ export interface SecurityMiddlewareConfig {
12
+ promptInjection?: boolean;
13
+ secretRedaction?: boolean;
14
+ jailbreakDetection?: boolean;
15
+ blockedPatterns?: RegExp[];
16
+ piiTypes?: Array<'email' | 'phone' | 'address' | 'passport' | 'all'>;
17
+ onViolation?: (violation: SecurityViolation) => void;
18
+ }
19
+ export type DataClassification = 'public' | 'internal' | 'confidential' | 'restricted';
20
+ export interface ClassificationResult {
21
+ level: DataClassification;
22
+ detectedTypes: string[];
23
+ }
24
+ export declare function classifyContent(text: string): ClassificationResult;
25
+ export declare function detectPromptInjection(text: string): SecurityViolation[];
26
+ export declare function detectJailbreak(text: string): SecurityViolation[];
27
+ export declare function redactSecrets(text: string, piiTypes?: Array<'email' | 'phone' | 'address' | 'passport' | 'all'>): {
28
+ redacted: string;
29
+ found: SecurityViolation[];
30
+ };
31
+ export declare function checkBlockedPatterns(text: string, patterns: RegExp[]): SecurityViolation[];
32
+ export declare function securityMiddleware(config: SecurityMiddlewareConfig): Middleware;
33
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +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,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC,GAClE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,iBAAiB,EAAE,CAAA;CAAE,CAYlD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAa1F;AAwDD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,UAAU,CAuB/E"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@elsium-ai/gateway",
3
+ "version": "0.1.6",
4
+ "description": "Multi-provider LLM gateway for ElsiumAI",
5
+ "license": "MIT",
6
+ "author": "Eric Utrera <ebutrera9103@gmail.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/elsium-ai/elsium-ai",
10
+ "directory": "packages/gateway"
11
+ },
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun && bun x tsc -p tsconfig.build.json --emitDeclarationOnly",
26
+ "dev": "bun --watch src/index.ts"
27
+ },
28
+ "dependencies": {
29
+ "@elsium-ai/core": "workspace:*",
30
+ "zod": "^3.24.0"
31
+ },
32
+ "devDependencies": {
33
+ "bun-types": "^1.3.0",
34
+ "typescript": "^5.7.0"
35
+ }
36
+ }