@relayplane/proxy 1.3.2 → 1.5.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/dist/server.d.ts CHANGED
@@ -1,13 +1,249 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * RelayPlane Local LLM Proxy Server
2
+ * RelayPlane Agent Ops Proxy Server
3
+ *
4
+ * OpenAI-compatible proxy server with integrated observability via the Learning Ledger
5
+ * and auth enforcement via Auth Gate.
4
6
  *
5
- * Routes OpenAI-compatible requests to multiple providers.
6
7
  * Features:
7
- * - /health endpoint for monitoring
8
- * - Usage tracking with spending warnings
9
- * - Model aliases (rp:fast, rp:cheap, rp:best)
10
- * - Dry-run mode for testing
8
+ * - OpenAI-compatible `/v1/chat/completions` endpoint
9
+ * - Auth Gate integration for consumer vs API auth detection
10
+ * - Learning Ledger integration for run tracking
11
+ * - Timing capture (latency_ms, ttft_ms)
12
+ * - Structured error handling
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ import { Ledger } from '@relayplane/ledger';
17
+ import { AuthGate, type AuthProfileStorage } from '@relayplane/auth-gate';
18
+ import { PolicyEngine, type PolicyStorage } from '@relayplane/policy-engine';
19
+ import { RoutingEngine, type CapabilityRegistry, type ProviderManager } from '@relayplane/routing-engine';
20
+ import { ExplanationEngine, RunComparator, Simulator } from '@relayplane/explainability';
21
+ import type { AuthEnforcementMode } from '@relayplane/ledger';
22
+ import { LearningEngine, type LearningEngineConfig } from '@relayplane/learning-engine';
23
+ import { RelayPlaneMiddleware } from './middleware.js';
24
+ import { type RelayPlaneConfig, type MeshConfig } from './relay-config.js';
25
+ import { type MeshHandle } from './mesh.js';
26
+ /**
27
+ * Proxy server configuration
28
+ */
29
+ export interface ProxyServerConfig {
30
+ port?: number;
31
+ host?: string;
32
+ ledger?: Ledger;
33
+ authStorage?: AuthProfileStorage;
34
+ policyStorage?: PolicyStorage;
35
+ policyEngine?: PolicyEngine;
36
+ verbose?: boolean;
37
+ defaultWorkspaceId?: string;
38
+ defaultAgentId?: string;
39
+ defaultAuthEnforcementMode?: AuthEnforcementMode;
40
+ enforcePolicies?: boolean;
41
+ routingEngine?: RoutingEngine;
42
+ capabilityRegistry?: CapabilityRegistry;
43
+ providerManager?: ProviderManager;
44
+ /** Enable capability-based routing (Phase 3) */
45
+ enableRouting?: boolean;
46
+ learningEngine?: LearningEngine;
47
+ /** Enable learning engine analytics and suggestions (default: false) */
48
+ enableLearning?: boolean;
49
+ learningConfig?: LearningEngineConfig;
50
+ /** Mesh config overrides */
51
+ meshConfig?: Partial<MeshConfig>;
52
+ /** Enable mesh learning layer (default: true) */
53
+ enableMesh?: boolean;
54
+ providers?: {
55
+ anthropic?: {
56
+ apiKey: string;
57
+ baseUrl?: string;
58
+ };
59
+ openai?: {
60
+ apiKey: string;
61
+ baseUrl?: string;
62
+ };
63
+ openrouter?: {
64
+ apiKey: string;
65
+ baseUrl?: string;
66
+ };
67
+ google?: {
68
+ apiKey: string;
69
+ baseUrl?: string;
70
+ };
71
+ together?: {
72
+ apiKey: string;
73
+ baseUrl?: string;
74
+ };
75
+ deepseek?: {
76
+ apiKey: string;
77
+ baseUrl?: string;
78
+ };
79
+ };
80
+ }
81
+ /**
82
+ * RelayPlane Agent Ops Proxy Server
83
+ */
84
+ export declare class ProxyServer {
85
+ private server;
86
+ private ledger;
87
+ private authGate;
88
+ private policyEngine;
89
+ private routingEngine;
90
+ private capabilityRegistry;
91
+ private providerManager;
92
+ private explainer;
93
+ private comparator;
94
+ private simulator;
95
+ private learningEngine;
96
+ private meshHandle;
97
+ private meshConfig;
98
+ private config;
99
+ constructor(config?: ProxyServerConfig);
100
+ /**
101
+ * Build provider overrides from config
102
+ */
103
+ private buildProviderOverrides;
104
+ /**
105
+ * Configure provider API keys from config
106
+ */
107
+ private configureProviderApiKeys;
108
+ /**
109
+ * Start the proxy server
110
+ */
111
+ start(): Promise<void>;
112
+ /**
113
+ * Stop the proxy server
114
+ */
115
+ stop(): Promise<void>;
116
+ /**
117
+ * Handle incoming request
118
+ */
119
+ private handleRequest;
120
+ private handleListPolicies;
121
+ private handleCreatePolicy;
122
+ private handleGetPolicy;
123
+ private handleUpdatePolicy;
124
+ private handleDeletePolicy;
125
+ private handlePolicyTest;
126
+ private handleGetBudget;
127
+ /**
128
+ * Handle GET /v1/runs/{id}/explain - Full decision chain explanation
129
+ */
130
+ private handleExplainRun;
131
+ /**
132
+ * Handle GET /v1/runs/{id}/timeline - Timeline view only
133
+ */
134
+ private handleRunTimeline;
135
+ /**
136
+ * Handle GET /v1/runs/{id}/decisions - Raw decision chain
137
+ */
138
+ private handleRunDecisions;
139
+ /**
140
+ * Handle GET /v1/runs/{id} - Run inspector (all details)
141
+ */
142
+ private handleRunInspector;
143
+ /**
144
+ * Handle GET /v1/runs/compare?ids=run1,run2 - Run comparison
145
+ */
146
+ private handleCompareRuns;
147
+ /**
148
+ * Handle POST /v1/simulate/policy - Policy simulation
149
+ */
150
+ private handleSimulatePolicy;
151
+ /**
152
+ * Handle POST /v1/simulate/routing - Routing simulation
153
+ */
154
+ private handleSimulateRouting;
155
+ /**
156
+ * Handle /v1/chat/completions
157
+ */
158
+ private handleChatCompletions;
159
+ /**
160
+ * Forward request to provider
161
+ */
162
+ private forwardToProvider;
163
+ /**
164
+ * Detect auth type from Authorization header
165
+ */
166
+ private detectAuthType;
167
+ /**
168
+ * Estimate cost based on provider and usage
169
+ */
170
+ private estimateCost;
171
+ /**
172
+ * Read request body
173
+ */
174
+ private readBody;
175
+ /**
176
+ * Send error response
177
+ */
178
+ private sendError;
179
+ private handleAnalyticsSummary;
180
+ private handleRunAnalysis;
181
+ private handleListSuggestions;
182
+ private handleApproveSuggestion;
183
+ private handleRejectSuggestion;
184
+ private handleListRules;
185
+ private handleRuleEffectiveness;
186
+ /**
187
+ * Log message
188
+ */
189
+ private log;
190
+ /**
191
+ * Get the ledger instance (useful for testing)
192
+ */
193
+ getLedger(): Ledger;
194
+ /**
195
+ * Get the auth gate instance (useful for testing)
196
+ */
197
+ getAuthGate(): AuthGate;
198
+ /**
199
+ * Get the policy engine instance (useful for testing and policy management)
200
+ */
201
+ getPolicyEngine(): PolicyEngine;
202
+ /**
203
+ * Get the routing engine instance (Phase 3)
204
+ */
205
+ getRoutingEngine(): RoutingEngine;
206
+ /**
207
+ * Get the capability registry instance (Phase 3)
208
+ */
209
+ getCapabilityRegistry(): CapabilityRegistry;
210
+ /**
211
+ * Get the provider manager instance (Phase 3)
212
+ */
213
+ getProviderManager(): ProviderManager;
214
+ /**
215
+ * Get the explanation engine instance (Phase 4)
216
+ */
217
+ getExplainer(): ExplanationEngine;
218
+ /**
219
+ * Get the run comparator instance (Phase 4)
220
+ */
221
+ getComparator(): RunComparator;
222
+ /**
223
+ * Get the simulator instance (Phase 4)
224
+ */
225
+ getSimulator(): Simulator;
226
+ /**
227
+ * Get the learning engine instance (Phase 5)
228
+ */
229
+ getLearningEngine(): LearningEngine | null;
230
+ /**
231
+ * Get the mesh handle instance (Phase 6)
232
+ */
233
+ getMeshHandle(): MeshHandle | null;
234
+ }
235
+ /**
236
+ * Create a new proxy server
237
+ */
238
+ export declare function createProxyServer(config?: ProxyServerConfig): ProxyServer;
239
+ /**
240
+ * Create a proxy server with optional circuit breaker middleware wrapping.
241
+ * This gives the advanced proxy the same circuit breaker protection as standalone.
11
242
  */
12
- export {};
243
+ export declare function createSandboxedProxyServer(config?: ProxyServerConfig & {
244
+ relayplane?: Partial<RelayPlaneConfig>;
245
+ }): {
246
+ server: ProxyServer;
247
+ middleware?: RelayPlaneMiddleware;
248
+ };
13
249
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,MAAM,EAAgB,MAAM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