@relayplane/proxy 0.2.0 → 1.1.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 +221 -120
- package/dist/server.d.ts +8 -204
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +562 -1014
- package/dist/server.js.map +1 -1
- package/package.json +30 -29
- package/__tests__/server.test.ts +0 -512
- package/__tests__/telemetry.test.ts +0 -126
- package/dist/cli.d.ts +0 -36
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -304
- package/dist/cli.js.map +0 -1
- package/dist/config.d.ts +0 -80
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -208
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -74
- package/dist/index.js.map +0 -1
- package/dist/streaming.d.ts +0 -80
- package/dist/streaming.d.ts.map +0 -1
- package/dist/streaming.js +0 -271
- package/dist/streaming.js.map +0 -1
- package/dist/telemetry.d.ts +0 -111
- package/dist/telemetry.d.ts.map +0 -1
- package/dist/telemetry.js +0 -315
- package/dist/telemetry.js.map +0 -1
- package/src/cli.ts +0 -341
- package/src/config.ts +0 -206
- package/src/index.ts +0 -82
- package/src/server.ts +0 -1328
- package/src/streaming.ts +0 -331
- package/src/telemetry.ts +0 -343
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -21
package/src/config.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RelayPlane Proxy Configuration
|
|
3
|
-
*
|
|
4
|
-
* Handles configuration persistence, telemetry settings, and device identity.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
import * as path from 'path';
|
|
11
|
-
import * as os from 'os';
|
|
12
|
-
import * as crypto from 'crypto';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Configuration schema for RelayPlane proxy
|
|
16
|
-
*/
|
|
17
|
-
export interface ProxyConfig {
|
|
18
|
-
/** Anonymous device ID (generated on first run) */
|
|
19
|
-
device_id: string;
|
|
20
|
-
|
|
21
|
-
/** Telemetry enabled state */
|
|
22
|
-
telemetry_enabled: boolean;
|
|
23
|
-
|
|
24
|
-
/** Whether first run disclosure has been shown */
|
|
25
|
-
first_run_complete: boolean;
|
|
26
|
-
|
|
27
|
-
/** RelayPlane API key (for Pro features) */
|
|
28
|
-
api_key?: string;
|
|
29
|
-
|
|
30
|
-
/** Schema version for migrations */
|
|
31
|
-
config_version: number;
|
|
32
|
-
|
|
33
|
-
/** Timestamp of config creation */
|
|
34
|
-
created_at: string;
|
|
35
|
-
|
|
36
|
-
/** Timestamp of last update */
|
|
37
|
-
updated_at: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const CONFIG_VERSION = 1;
|
|
41
|
-
const CONFIG_DIR = path.join(os.homedir(), '.relayplane');
|
|
42
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Generate an anonymous device ID
|
|
46
|
-
* Uses a random hash that cannot be traced back to the device
|
|
47
|
-
*/
|
|
48
|
-
function generateDeviceId(): string {
|
|
49
|
-
const randomBytes = crypto.randomBytes(16);
|
|
50
|
-
const hash = crypto.createHash('sha256').update(randomBytes).digest('hex');
|
|
51
|
-
return `anon_${hash.slice(0, 16)}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Ensure config directory exists
|
|
56
|
-
*/
|
|
57
|
-
function ensureConfigDir(): void {
|
|
58
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
59
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Create default configuration
|
|
65
|
-
*/
|
|
66
|
-
function createDefaultConfig(): ProxyConfig {
|
|
67
|
-
const now = new Date().toISOString();
|
|
68
|
-
return {
|
|
69
|
-
device_id: generateDeviceId(),
|
|
70
|
-
telemetry_enabled: true, // On by default, opt-out available
|
|
71
|
-
first_run_complete: false,
|
|
72
|
-
config_version: CONFIG_VERSION,
|
|
73
|
-
created_at: now,
|
|
74
|
-
updated_at: now,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Load configuration from disk
|
|
80
|
-
* Creates default config if none exists
|
|
81
|
-
*/
|
|
82
|
-
export function loadConfig(): ProxyConfig {
|
|
83
|
-
ensureConfigDir();
|
|
84
|
-
|
|
85
|
-
if (!fs.existsSync(CONFIG_FILE)) {
|
|
86
|
-
const config = createDefaultConfig();
|
|
87
|
-
saveConfig(config);
|
|
88
|
-
return config;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
93
|
-
const config = JSON.parse(data) as ProxyConfig;
|
|
94
|
-
|
|
95
|
-
// Ensure required fields exist (for migrations)
|
|
96
|
-
if (!config.device_id) {
|
|
97
|
-
config.device_id = generateDeviceId();
|
|
98
|
-
}
|
|
99
|
-
if (config.telemetry_enabled === undefined) {
|
|
100
|
-
config.telemetry_enabled = true;
|
|
101
|
-
}
|
|
102
|
-
if (!config.config_version) {
|
|
103
|
-
config.config_version = CONFIG_VERSION;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return config;
|
|
107
|
-
} catch (err) {
|
|
108
|
-
// If config is corrupted, create new one
|
|
109
|
-
const config = createDefaultConfig();
|
|
110
|
-
saveConfig(config);
|
|
111
|
-
return config;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Save configuration to disk
|
|
117
|
-
*/
|
|
118
|
-
export function saveConfig(config: ProxyConfig): void {
|
|
119
|
-
ensureConfigDir();
|
|
120
|
-
config.updated_at = new Date().toISOString();
|
|
121
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Update specific config fields
|
|
126
|
-
*/
|
|
127
|
-
export function updateConfig(updates: Partial<ProxyConfig>): ProxyConfig {
|
|
128
|
-
const config = loadConfig();
|
|
129
|
-
Object.assign(config, updates);
|
|
130
|
-
saveConfig(config);
|
|
131
|
-
return config;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Check if this is the first run (disclosure not shown yet)
|
|
136
|
-
*/
|
|
137
|
-
export function isFirstRun(): boolean {
|
|
138
|
-
const config = loadConfig();
|
|
139
|
-
return !config.first_run_complete;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Mark first run as complete
|
|
144
|
-
*/
|
|
145
|
-
export function markFirstRunComplete(): void {
|
|
146
|
-
updateConfig({ first_run_complete: true });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Check if telemetry is enabled
|
|
151
|
-
*/
|
|
152
|
-
export function isTelemetryEnabled(): boolean {
|
|
153
|
-
const config = loadConfig();
|
|
154
|
-
return config.telemetry_enabled;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Enable telemetry
|
|
159
|
-
*/
|
|
160
|
-
export function enableTelemetry(): void {
|
|
161
|
-
updateConfig({ telemetry_enabled: true });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Disable telemetry
|
|
166
|
-
*/
|
|
167
|
-
export function disableTelemetry(): void {
|
|
168
|
-
updateConfig({ telemetry_enabled: false });
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Get device ID for telemetry
|
|
173
|
-
*/
|
|
174
|
-
export function getDeviceId(): string {
|
|
175
|
-
const config = loadConfig();
|
|
176
|
-
return config.device_id;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Set API key for Pro features
|
|
181
|
-
*/
|
|
182
|
-
export function setApiKey(key: string): void {
|
|
183
|
-
updateConfig({ api_key: key });
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get API key
|
|
188
|
-
*/
|
|
189
|
-
export function getApiKey(): string | undefined {
|
|
190
|
-
const config = loadConfig();
|
|
191
|
-
return config.api_key;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Get config directory path
|
|
196
|
-
*/
|
|
197
|
-
export function getConfigDir(): string {
|
|
198
|
-
return CONFIG_DIR;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Get config file path
|
|
203
|
-
*/
|
|
204
|
-
export function getConfigPath(): string {
|
|
205
|
-
return CONFIG_FILE;
|
|
206
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @relayplane/proxy
|
|
3
|
-
*
|
|
4
|
-
* RelayPlane Agent Ops Proxy Server
|
|
5
|
-
*
|
|
6
|
-
* Intelligent AI model routing with integrated observability via
|
|
7
|
-
* the Learning Ledger and auth enforcement via Auth Gate.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { createProxyServer } from '@relayplane/proxy';
|
|
12
|
-
*
|
|
13
|
-
* const server = createProxyServer({
|
|
14
|
-
* port: 3001,
|
|
15
|
-
* providers: {
|
|
16
|
-
* anthropic: { apiKey: process.env.ANTHROPIC_API_KEY! },
|
|
17
|
-
* openai: { apiKey: process.env.OPENAI_API_KEY! },
|
|
18
|
-
* },
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* await server.start();
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @packageDocumentation
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
// New Agent Ops proxy server (Phase 1)
|
|
28
|
-
export { ProxyServer, createProxyServer } from './server.js';
|
|
29
|
-
export type { ProxyServerConfig } from './server.js';
|
|
30
|
-
|
|
31
|
-
// Streaming support (Phase 8)
|
|
32
|
-
export {
|
|
33
|
-
SSEWriter,
|
|
34
|
-
createSSEWriter,
|
|
35
|
-
streamProviderResponse,
|
|
36
|
-
aggregateStreamingResponse,
|
|
37
|
-
startKeepAlive,
|
|
38
|
-
} from './streaming.js';
|
|
39
|
-
export type { SSEMessage } from './streaming.js';
|
|
40
|
-
|
|
41
|
-
// Legacy proxy functionality from openclaw
|
|
42
|
-
export { startProxy, type ProxyConfig } from '@relayplane/openclaw';
|
|
43
|
-
|
|
44
|
-
// Configuration
|
|
45
|
-
export {
|
|
46
|
-
loadConfig,
|
|
47
|
-
saveConfig,
|
|
48
|
-
updateConfig,
|
|
49
|
-
isFirstRun,
|
|
50
|
-
markFirstRunComplete,
|
|
51
|
-
isTelemetryEnabled,
|
|
52
|
-
enableTelemetry,
|
|
53
|
-
disableTelemetry,
|
|
54
|
-
getDeviceId,
|
|
55
|
-
setApiKey,
|
|
56
|
-
getApiKey,
|
|
57
|
-
getConfigDir,
|
|
58
|
-
getConfigPath,
|
|
59
|
-
} from './config.js';
|
|
60
|
-
export type { ProxyConfig as ProxyLocalConfig } from './config.js';
|
|
61
|
-
|
|
62
|
-
// Telemetry
|
|
63
|
-
export {
|
|
64
|
-
recordTelemetry,
|
|
65
|
-
inferTaskType,
|
|
66
|
-
estimateCost,
|
|
67
|
-
setAuditMode,
|
|
68
|
-
isAuditMode,
|
|
69
|
-
setOfflineMode,
|
|
70
|
-
isOfflineMode,
|
|
71
|
-
getAuditBuffer,
|
|
72
|
-
clearAuditBuffer,
|
|
73
|
-
getLocalTelemetry,
|
|
74
|
-
getTelemetryStats,
|
|
75
|
-
clearTelemetry,
|
|
76
|
-
getTelemetryPath,
|
|
77
|
-
printTelemetryDisclosure,
|
|
78
|
-
} from './telemetry.js';
|
|
79
|
-
export type { TelemetryEvent } from './telemetry.js';
|
|
80
|
-
|
|
81
|
-
// Re-export core types
|
|
82
|
-
export type { Provider, TaskType } from '@relayplane/core';
|