@relayplane/proxy 1.1.0 → 1.1.2
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 +120 -221
- package/dist/__tests__/model-suggestions.test.d.ts +2 -0
- package/dist/__tests__/model-suggestions.test.d.ts.map +1 -0
- package/dist/__tests__/model-suggestions.test.js +67 -0
- package/dist/__tests__/model-suggestions.test.js.map +1 -0
- package/dist/__tests__/routing-aliases.test.d.ts +2 -0
- package/dist/__tests__/routing-aliases.test.d.ts.map +1 -0
- package/dist/__tests__/routing-aliases.test.js +81 -0
- package/dist/__tests__/routing-aliases.test.js.map +1 -0
- package/dist/cli.d.ts +36 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +304 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +80 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/standalone-proxy.d.ts +101 -0
- package/dist/standalone-proxy.d.ts.map +1 -0
- package/dist/standalone-proxy.js +2524 -0
- package/dist/standalone-proxy.js.map +1 -0
- package/dist/swarm-client.d.ts +87 -0
- package/dist/swarm-client.d.ts.map +1 -0
- package/dist/swarm-client.js +205 -0
- package/dist/swarm-client.js.map +1 -0
- package/dist/telemetry.d.ts +127 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +426 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/utils/model-suggestions.d.ts +28 -0
- package/dist/utils/model-suggestions.d.ts.map +1 -0
- package/dist/utils/model-suggestions.js +50 -0
- package/dist/utils/model-suggestions.js.map +1 -0
- package/package.json +35 -29
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @relayplane/proxy
|
|
4
|
+
*
|
|
5
|
+
* RelayPlane Agent Ops Proxy Server
|
|
6
|
+
*
|
|
7
|
+
* Intelligent AI model routing with integrated observability.
|
|
8
|
+
* This is a standalone proxy that routes requests to optimal models
|
|
9
|
+
* based on task type and cost optimization.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { startProxy } from '@relayplane/proxy';
|
|
14
|
+
*
|
|
15
|
+
* // Start the proxy server
|
|
16
|
+
* await startProxy({ port: 3001 });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.printTelemetryDisclosure = exports.getTelemetryPath = exports.clearTelemetry = exports.getTelemetryStats = exports.getLocalTelemetry = exports.clearAuditBuffer = exports.getAuditBuffer = exports.isOfflineMode = exports.setOfflineMode = exports.isAuditMode = exports.setAuditMode = exports.estimateCost = exports.inferTaskType = exports.recordTelemetry = exports.getConfigPath = exports.getConfigDir = exports.getApiKey = exports.setApiKey = exports.getDeviceId = exports.disableTelemetry = exports.enableTelemetry = exports.isTelemetryEnabled = exports.markFirstRunComplete = exports.isFirstRun = exports.updateConfig = exports.saveConfig = exports.loadConfig = exports.startProxy = void 0;
|
|
23
|
+
// Standalone proxy (requires only @relayplane/core)
|
|
24
|
+
var standalone_proxy_js_1 = require("./standalone-proxy.js");
|
|
25
|
+
Object.defineProperty(exports, "startProxy", { enumerable: true, get: function () { return standalone_proxy_js_1.startProxy; } });
|
|
26
|
+
// Configuration
|
|
27
|
+
var config_js_1 = require("./config.js");
|
|
28
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_js_1.loadConfig; } });
|
|
29
|
+
Object.defineProperty(exports, "saveConfig", { enumerable: true, get: function () { return config_js_1.saveConfig; } });
|
|
30
|
+
Object.defineProperty(exports, "updateConfig", { enumerable: true, get: function () { return config_js_1.updateConfig; } });
|
|
31
|
+
Object.defineProperty(exports, "isFirstRun", { enumerable: true, get: function () { return config_js_1.isFirstRun; } });
|
|
32
|
+
Object.defineProperty(exports, "markFirstRunComplete", { enumerable: true, get: function () { return config_js_1.markFirstRunComplete; } });
|
|
33
|
+
Object.defineProperty(exports, "isTelemetryEnabled", { enumerable: true, get: function () { return config_js_1.isTelemetryEnabled; } });
|
|
34
|
+
Object.defineProperty(exports, "enableTelemetry", { enumerable: true, get: function () { return config_js_1.enableTelemetry; } });
|
|
35
|
+
Object.defineProperty(exports, "disableTelemetry", { enumerable: true, get: function () { return config_js_1.disableTelemetry; } });
|
|
36
|
+
Object.defineProperty(exports, "getDeviceId", { enumerable: true, get: function () { return config_js_1.getDeviceId; } });
|
|
37
|
+
Object.defineProperty(exports, "setApiKey", { enumerable: true, get: function () { return config_js_1.setApiKey; } });
|
|
38
|
+
Object.defineProperty(exports, "getApiKey", { enumerable: true, get: function () { return config_js_1.getApiKey; } });
|
|
39
|
+
Object.defineProperty(exports, "getConfigDir", { enumerable: true, get: function () { return config_js_1.getConfigDir; } });
|
|
40
|
+
Object.defineProperty(exports, "getConfigPath", { enumerable: true, get: function () { return config_js_1.getConfigPath; } });
|
|
41
|
+
// Telemetry
|
|
42
|
+
var telemetry_js_1 = require("./telemetry.js");
|
|
43
|
+
Object.defineProperty(exports, "recordTelemetry", { enumerable: true, get: function () { return telemetry_js_1.recordTelemetry; } });
|
|
44
|
+
Object.defineProperty(exports, "inferTaskType", { enumerable: true, get: function () { return telemetry_js_1.inferTaskType; } });
|
|
45
|
+
Object.defineProperty(exports, "estimateCost", { enumerable: true, get: function () { return telemetry_js_1.estimateCost; } });
|
|
46
|
+
Object.defineProperty(exports, "setAuditMode", { enumerable: true, get: function () { return telemetry_js_1.setAuditMode; } });
|
|
47
|
+
Object.defineProperty(exports, "isAuditMode", { enumerable: true, get: function () { return telemetry_js_1.isAuditMode; } });
|
|
48
|
+
Object.defineProperty(exports, "setOfflineMode", { enumerable: true, get: function () { return telemetry_js_1.setOfflineMode; } });
|
|
49
|
+
Object.defineProperty(exports, "isOfflineMode", { enumerable: true, get: function () { return telemetry_js_1.isOfflineMode; } });
|
|
50
|
+
Object.defineProperty(exports, "getAuditBuffer", { enumerable: true, get: function () { return telemetry_js_1.getAuditBuffer; } });
|
|
51
|
+
Object.defineProperty(exports, "clearAuditBuffer", { enumerable: true, get: function () { return telemetry_js_1.clearAuditBuffer; } });
|
|
52
|
+
Object.defineProperty(exports, "getLocalTelemetry", { enumerable: true, get: function () { return telemetry_js_1.getLocalTelemetry; } });
|
|
53
|
+
Object.defineProperty(exports, "getTelemetryStats", { enumerable: true, get: function () { return telemetry_js_1.getTelemetryStats; } });
|
|
54
|
+
Object.defineProperty(exports, "clearTelemetry", { enumerable: true, get: function () { return telemetry_js_1.clearTelemetry; } });
|
|
55
|
+
Object.defineProperty(exports, "getTelemetryPath", { enumerable: true, get: function () { return telemetry_js_1.getTelemetryPath; } });
|
|
56
|
+
Object.defineProperty(exports, "printTelemetryDisclosure", { enumerable: true, get: function () { return telemetry_js_1.printTelemetryDisclosure; } });
|
|
57
|
+
// Note: Advanced features (ProxyServer, streaming, etc.) require additional
|
|
58
|
+
// dependencies. Install @relayplane/ledger, @relayplane/auth-gate, etc.
|
|
59
|
+
// for full functionality. See documentation for details.
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,oDAAoD;AACpD,6DAAmD;AAA1C,iHAAA,UAAU,OAAA;AAGnB,gBAAgB;AAChB,yCAcqB;AAbnB,uGAAA,UAAU,OAAA;AACV,uGAAA,UAAU,OAAA;AACV,yGAAA,YAAY,OAAA;AACZ,uGAAA,UAAU,OAAA;AACV,iHAAA,oBAAoB,OAAA;AACpB,+GAAA,kBAAkB,OAAA;AAClB,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,wGAAA,WAAW,OAAA;AACX,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AAIf,YAAY;AACZ,+CAewB;AAdtB,+GAAA,eAAe,OAAA;AACf,6GAAA,aAAa,OAAA;AACb,4GAAA,YAAY,OAAA;AACZ,4GAAA,YAAY,OAAA;AACZ,2GAAA,WAAW,OAAA;AACX,8GAAA,cAAc,OAAA;AACd,6GAAA,aAAa,OAAA;AACb,8GAAA,cAAc,OAAA;AACd,gHAAA,gBAAgB,OAAA;AAChB,iHAAA,iBAAiB,OAAA;AACjB,iHAAA,iBAAiB,OAAA;AACjB,8GAAA,cAAc,OAAA;AACd,gHAAA,gBAAgB,OAAA;AAChB,wHAAA,wBAAwB,OAAA;AAO1B,4EAA4E;AAC5E,wEAAwE;AACxE,yDAAyD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RelayPlane L2/L3 Proxy Server
|
|
3
|
+
*
|
|
4
|
+
* An LLM Gateway proxy that intelligently routes requests
|
|
5
|
+
* to the optimal model using @relayplane/core.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - OpenAI-compatible API (/v1/chat/completions)
|
|
9
|
+
* - Native Anthropic API (/v1/messages) for Claude Code integration
|
|
10
|
+
* - Streaming (SSE) for both OpenAI and Anthropic formats
|
|
11
|
+
* - Auth passthrough for Claude Code (OAuth/subscription billing)
|
|
12
|
+
* - Cross-provider routing (Anthropic, OpenAI, Google, xAI)
|
|
13
|
+
* - Tool/function calling with format conversion
|
|
14
|
+
*
|
|
15
|
+
* Authentication:
|
|
16
|
+
* - Anthropic: Passthrough incoming Authorization header OR ANTHROPIC_API_KEY env
|
|
17
|
+
* - Other providers: Require provider-specific API key env vars
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
import * as http from 'node:http';
|
|
22
|
+
import type { Provider } from '@relayplane/core';
|
|
23
|
+
/**
|
|
24
|
+
* Provider endpoint configuration
|
|
25
|
+
*/
|
|
26
|
+
export interface ProviderEndpoint {
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
apiKeyEnv: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Default provider endpoints
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_ENDPOINTS: Record<string, ProviderEndpoint>;
|
|
34
|
+
/**
|
|
35
|
+
* Model to provider/model mapping
|
|
36
|
+
*/
|
|
37
|
+
export declare const MODEL_MAPPING: Record<string, {
|
|
38
|
+
provider: Provider;
|
|
39
|
+
model: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* RelayPlane model aliases - resolve before routing
|
|
43
|
+
* These are user-friendly aliases that map to internal routing modes
|
|
44
|
+
*/
|
|
45
|
+
export declare const RELAYPLANE_ALIASES: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Smart routing aliases - map to specific provider/model combinations
|
|
48
|
+
* These provide semantic shortcuts for common use cases
|
|
49
|
+
*/
|
|
50
|
+
export declare const SMART_ALIASES: Record<string, {
|
|
51
|
+
provider: Provider;
|
|
52
|
+
model: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all available model names for error suggestions
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAvailableModelNames(): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Resolve model aliases before routing
|
|
60
|
+
* Returns the resolved model name (may be same as input if no alias found)
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveModelAlias(model: string): string;
|
|
63
|
+
type RoutingSuffix = 'cost' | 'fast' | 'quality';
|
|
64
|
+
interface ParsedModel {
|
|
65
|
+
baseModel: string;
|
|
66
|
+
suffix: RoutingSuffix | null;
|
|
67
|
+
}
|
|
68
|
+
interface CascadeConfig {
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
models: string[];
|
|
71
|
+
escalateOn: 'uncertainty' | 'refusal' | 'error';
|
|
72
|
+
maxEscalations: number;
|
|
73
|
+
}
|
|
74
|
+
type Complexity = 'simple' | 'moderate' | 'complex';
|
|
75
|
+
/**
|
|
76
|
+
* Proxy server configuration
|
|
77
|
+
*/
|
|
78
|
+
export interface ProxyConfig {
|
|
79
|
+
port?: number;
|
|
80
|
+
host?: string;
|
|
81
|
+
dbPath?: string;
|
|
82
|
+
verbose?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Auth passthrough mode for Anthropic requests.
|
|
85
|
+
* - 'passthrough': Forward incoming Authorization header to Anthropic (for Claude Code OAuth)
|
|
86
|
+
* - 'env': Always use ANTHROPIC_API_KEY env var
|
|
87
|
+
* - 'auto' (default): Use incoming auth if present, fallback to env var
|
|
88
|
+
*/
|
|
89
|
+
anthropicAuth?: 'passthrough' | 'env' | 'auto';
|
|
90
|
+
}
|
|
91
|
+
export declare function parseModelSuffix(model: string): ParsedModel;
|
|
92
|
+
export declare function classifyComplexity(messages: Array<{
|
|
93
|
+
content?: unknown;
|
|
94
|
+
}>): Complexity;
|
|
95
|
+
export declare function shouldEscalate(responseText: string, trigger: CascadeConfig['escalateOn']): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Start the RelayPlane proxy server
|
|
98
|
+
*/
|
|
99
|
+
export declare function startProxy(config?: ProxyConfig): Promise<http.Server>;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=standalone-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-proxy.d.ts","sourceRoot":"","sources":["../src/standalone-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAKlC,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,kBAAkB,CAAC;AAG3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MA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