@relayplane/proxy 0.1.9 → 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.
@@ -0,0 +1,209 @@
1
+ /**
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.
6
+ *
7
+ * Features:
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
+ /**
23
+ * Proxy server configuration
24
+ */
25
+ export interface ProxyServerConfig {
26
+ port?: number;
27
+ host?: string;
28
+ ledger?: Ledger;
29
+ authStorage?: AuthProfileStorage;
30
+ policyStorage?: PolicyStorage;
31
+ policyEngine?: PolicyEngine;
32
+ verbose?: boolean;
33
+ defaultWorkspaceId?: string;
34
+ defaultAgentId?: string;
35
+ defaultAuthEnforcementMode?: AuthEnforcementMode;
36
+ enforcePolicies?: boolean;
37
+ routingEngine?: RoutingEngine;
38
+ capabilityRegistry?: CapabilityRegistry;
39
+ providerManager?: ProviderManager;
40
+ /** Enable capability-based routing (Phase 3) */
41
+ enableRouting?: boolean;
42
+ providers?: {
43
+ anthropic?: {
44
+ apiKey: string;
45
+ baseUrl?: string;
46
+ };
47
+ openai?: {
48
+ apiKey: string;
49
+ baseUrl?: string;
50
+ };
51
+ openrouter?: {
52
+ apiKey: string;
53
+ baseUrl?: string;
54
+ };
55
+ google?: {
56
+ apiKey: string;
57
+ baseUrl?: string;
58
+ };
59
+ together?: {
60
+ apiKey: string;
61
+ baseUrl?: string;
62
+ };
63
+ deepseek?: {
64
+ apiKey: string;
65
+ baseUrl?: string;
66
+ };
67
+ };
68
+ }
69
+ /**
70
+ * RelayPlane Agent Ops Proxy Server
71
+ */
72
+ export declare class ProxyServer {
73
+ private server;
74
+ private ledger;
75
+ private authGate;
76
+ private policyEngine;
77
+ private routingEngine;
78
+ private capabilityRegistry;
79
+ private providerManager;
80
+ private explainer;
81
+ private comparator;
82
+ private simulator;
83
+ private config;
84
+ constructor(config?: ProxyServerConfig);
85
+ /**
86
+ * Build provider overrides from config
87
+ */
88
+ private buildProviderOverrides;
89
+ /**
90
+ * Configure provider API keys from config
91
+ */
92
+ private configureProviderApiKeys;
93
+ /**
94
+ * Start the proxy server
95
+ */
96
+ start(): Promise<void>;
97
+ /**
98
+ * Stop the proxy server
99
+ */
100
+ stop(): Promise<void>;
101
+ /**
102
+ * Handle incoming request
103
+ */
104
+ private handleRequest;
105
+ private handleListPolicies;
106
+ private handleCreatePolicy;
107
+ private handleGetPolicy;
108
+ private handleUpdatePolicy;
109
+ private handleDeletePolicy;
110
+ private handlePolicyTest;
111
+ private handleGetBudget;
112
+ /**
113
+ * Handle GET /v1/runs/{id}/explain - Full decision chain explanation
114
+ */
115
+ private handleExplainRun;
116
+ /**
117
+ * Handle GET /v1/runs/{id}/timeline - Timeline view only
118
+ */
119
+ private handleRunTimeline;
120
+ /**
121
+ * Handle GET /v1/runs/{id}/decisions - Raw decision chain
122
+ */
123
+ private handleRunDecisions;
124
+ /**
125
+ * Handle GET /v1/runs/{id} - Run inspector (all details)
126
+ */
127
+ private handleRunInspector;
128
+ /**
129
+ * Handle GET /v1/runs/compare?ids=run1,run2 - Run comparison
130
+ */
131
+ private handleCompareRuns;
132
+ /**
133
+ * Handle POST /v1/simulate/policy - Policy simulation
134
+ */
135
+ private handleSimulatePolicy;
136
+ /**
137
+ * Handle POST /v1/simulate/routing - Routing simulation
138
+ */
139
+ private handleSimulateRouting;
140
+ /**
141
+ * Handle /v1/chat/completions
142
+ */
143
+ private handleChatCompletions;
144
+ /**
145
+ * Forward request to provider
146
+ */
147
+ private forwardToProvider;
148
+ /**
149
+ * Detect auth type from Authorization header
150
+ */
151
+ private detectAuthType;
152
+ /**
153
+ * Estimate cost based on provider and usage
154
+ */
155
+ private estimateCost;
156
+ /**
157
+ * Read request body
158
+ */
159
+ private readBody;
160
+ /**
161
+ * Send error response
162
+ */
163
+ private sendError;
164
+ /**
165
+ * Log message
166
+ */
167
+ private log;
168
+ /**
169
+ * Get the ledger instance (useful for testing)
170
+ */
171
+ getLedger(): Ledger;
172
+ /**
173
+ * Get the auth gate instance (useful for testing)
174
+ */
175
+ getAuthGate(): AuthGate;
176
+ /**
177
+ * Get the policy engine instance (useful for testing and policy management)
178
+ */
179
+ getPolicyEngine(): PolicyEngine;
180
+ /**
181
+ * Get the routing engine instance (Phase 3)
182
+ */
183
+ getRoutingEngine(): RoutingEngine;
184
+ /**
185
+ * Get the capability registry instance (Phase 3)
186
+ */
187
+ getCapabilityRegistry(): CapabilityRegistry;
188
+ /**
189
+ * Get the provider manager instance (Phase 3)
190
+ */
191
+ getProviderManager(): ProviderManager;
192
+ /**
193
+ * Get the explanation engine instance (Phase 4)
194
+ */
195
+ getExplainer(): ExplanationEngine;
196
+ /**
197
+ * Get the run comparator instance (Phase 4)
198
+ */
199
+ getComparator(): RunComparator;
200
+ /**
201
+ * Get the simulator instance (Phase 4)
202
+ */
203
+ getSimulator(): Simulator;
204
+ }
205
+ /**
206
+ * Create a new proxy server
207
+ */
208
+ export declare function createProxyServer(config?: ProxyServerConfig): ProxyServer;
209
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;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