@cc-monitoring/proxy-core 0.1.1 → 0.1.3
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/cli/__tests__/commands.test.d.ts +0 -1
- package/dist/cli/__tests__/commands.test.js +0 -1
- package/dist/cli/commands/config.d.ts +0 -1
- package/dist/cli/commands/config.js +0 -1
- package/dist/cli/commands/exec.d.ts +1 -0
- package/dist/cli/commands/exec.js +131 -0
- package/dist/cli/commands/kill.d.ts +0 -1
- package/dist/cli/commands/kill.js +0 -1
- package/dist/cli/commands/logs.d.ts +0 -1
- package/dist/cli/commands/logs.js +0 -1
- package/dist/cli/commands/reload.d.ts +0 -1
- package/dist/cli/commands/reload.js +0 -1
- package/dist/cli/commands/start.d.ts +0 -1
- package/dist/cli/commands/start.js +0 -1
- package/dist/cli/commands/status.d.ts +0 -1
- package/dist/cli/commands/status.js +0 -1
- package/dist/cli/commands/stop.d.ts +0 -1
- package/dist/cli/commands/stop.js +0 -1
- package/dist/cli/commands/test.d.ts +0 -1
- package/dist/cli/commands/test.js +0 -1
- package/dist/cli/commands/ui.d.ts +0 -1
- package/dist/cli/commands/ui.js +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +78 -22
- package/dist/config/__tests__/config.test.d.ts +0 -1
- package/dist/config/__tests__/config.test.js +0 -1
- package/dist/config/index.d.ts +0 -1
- package/dist/config/index.js +0 -1
- package/dist/config/schema.d.ts +0 -1
- package/dist/config/schema.js +0 -1
- package/dist/logger/__tests__/logger.test.d.ts +0 -1
- package/dist/logger/__tests__/logger.test.js +0 -1
- package/dist/logger/index.d.ts +0 -1
- package/dist/logger/index.js +0 -1
- package/dist/server/__tests__/providers-route.test.d.ts +0 -1
- package/dist/server/__tests__/providers-route.test.js +0 -1
- package/dist/server/__tests__/proxy.test.d.ts +0 -1
- package/dist/server/__tests__/proxy.test.js +0 -1
- package/dist/server/__tests__/server.test.d.ts +0 -1
- package/dist/server/__tests__/server.test.js +0 -1
- package/dist/server/__tests__/ui-route.test.d.ts +0 -1
- package/dist/server/__tests__/ui-route.test.js +0 -1
- package/dist/server/auth.d.ts +0 -1
- package/dist/server/auth.js +0 -1
- package/dist/server/data-push.d.ts +0 -1
- package/dist/server/data-push.js +0 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js +0 -1
- package/dist/server/middleware/__tests__/request-id.test.d.ts +0 -1
- package/dist/server/middleware/__tests__/request-id.test.js +0 -1
- package/dist/server/middleware/request-id.d.ts +0 -1
- package/dist/server/middleware/request-id.js +0 -1
- package/dist/server/providers-route.d.ts +0 -1
- package/dist/server/providers-route.js +0 -1
- package/dist/server/proxy.d.ts +0 -1
- package/dist/server/proxy.js +10 -3
- package/dist/server/ui-route.d.ts +0 -1
- package/dist/server/ui-route.js +125 -1
- package/dist/tools/curl.tool.d.ts +0 -1
- package/dist/tools/curl.tool.js +0 -1
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tools/probe.tool.d.ts +0 -1
- package/dist/tools/probe.tool.js +0 -1
- package/dist/tools/registry.d.ts +0 -1
- package/dist/tools/registry.js +0 -1
- package/dist/tools/types.d.ts +0 -1
- package/dist/tools/types.js +0 -1
- package/dist/types/api.d.ts +0 -1
- package/dist/types/api.js +0 -1
- package/dist/types/config.d.ts +0 -1
- package/dist/types/config.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/log.d.ts +0 -1
- package/dist/types/log.js +0 -1
- package/dist/types/pm2.d.ts +0 -1
- package/dist/types/pm2.js +0 -1
- package/dist/utils/__mocks__/esm-dirname.d.ts +0 -1
- package/dist/utils/__mocks__/esm-dirname.js +0 -1
- package/dist/utils/__mocks__/pm2-helpers.d.ts +0 -1
- package/dist/utils/__mocks__/pm2-helpers.js +0 -1
- package/dist/utils/__tests__/db-migration.test.d.ts +0 -1
- package/dist/utils/__tests__/db-migration.test.js +0 -1
- package/dist/utils/__tests__/inject-loop.test.d.ts +0 -1
- package/dist/utils/__tests__/inject-loop.test.js +0 -1
- package/dist/utils/__tests__/net.test.d.ts +0 -1
- package/dist/utils/__tests__/net.test.js +0 -1
- package/dist/utils/__tests__/pm2.test.d.ts +0 -1
- package/dist/utils/__tests__/pm2.test.js +0 -1
- package/dist/utils/__tests__/providers-db.test.d.ts +0 -1
- package/dist/utils/__tests__/providers-db.test.js +0 -1
- package/dist/utils/__tests__/request-writer.test.d.ts +0 -1
- package/dist/utils/__tests__/request-writer.test.js +0 -1
- package/dist/utils/__tests__/sse-accumulator.test.d.ts +0 -1
- package/dist/utils/__tests__/sse-accumulator.test.js +0 -1
- package/dist/utils/__tests__/sse-writer.test.d.ts +0 -1
- package/dist/utils/__tests__/sse-writer.test.js +0 -1
- package/dist/utils/__tests__/tool-injector.test.d.ts +0 -1
- package/dist/utils/__tests__/tool-injector.test.js +0 -1
- package/dist/utils/db.d.ts +0 -1
- package/dist/utils/db.js +0 -1
- package/dist/utils/esm-dirname.d.ts +0 -1
- package/dist/utils/esm-dirname.js +0 -1
- package/dist/utils/inject-loop.d.ts +0 -1
- package/dist/utils/inject-loop.js +0 -1
- package/dist/utils/migrate-files-to-db.d.ts +0 -1
- package/dist/utils/migrate-files-to-db.js +0 -1
- package/dist/utils/net.d.ts +0 -1
- package/dist/utils/net.js +0 -1
- package/dist/utils/paths.d.ts +0 -1
- package/dist/utils/paths.js +0 -1
- package/dist/utils/pm2.d.ts +0 -1
- package/dist/utils/pm2.js +0 -1
- package/dist/utils/providers-db.d.ts +0 -1
- package/dist/utils/providers-db.js +0 -1
- package/dist/utils/request-writer.d.ts +0 -1
- package/dist/utils/request-writer.js +0 -1
- package/dist/utils/sse-accumulator.d.ts +0 -1
- package/dist/utils/sse-accumulator.js +0 -1
- package/dist/utils/sse-writer.d.ts +0 -1
- package/dist/utils/sse-writer.js +0 -1
- package/dist/utils/stats-aggregator.d.ts +0 -1
- package/dist/utils/stats-aggregator.js +0 -1
- package/dist/utils/status-history.d.ts +0 -1
- package/dist/utils/status-history.js +0 -1
- package/dist/utils/tool-injector.d.ts +0 -1
- package/dist/utils/tool-injector.js +0 -1
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.js +0 -1
- package/package.json +1 -1
- package/dist/cli/__tests__/commands.test.d.ts.map +0 -1
- package/dist/cli/__tests__/commands.test.js.map +0 -1
- package/dist/cli/commands/config.d.ts.map +0 -1
- package/dist/cli/commands/config.js.map +0 -1
- package/dist/cli/commands/kill.d.ts.map +0 -1
- package/dist/cli/commands/kill.js.map +0 -1
- package/dist/cli/commands/logs.d.ts.map +0 -1
- package/dist/cli/commands/logs.js.map +0 -1
- package/dist/cli/commands/reload.d.ts.map +0 -1
- package/dist/cli/commands/reload.js.map +0 -1
- package/dist/cli/commands/start.d.ts.map +0 -1
- package/dist/cli/commands/start.js.map +0 -1
- package/dist/cli/commands/status.d.ts.map +0 -1
- package/dist/cli/commands/status.js.map +0 -1
- package/dist/cli/commands/stop.d.ts.map +0 -1
- package/dist/cli/commands/stop.js.map +0 -1
- package/dist/cli/commands/test.d.ts.map +0 -1
- package/dist/cli/commands/test.js.map +0 -1
- package/dist/cli/commands/ui.d.ts.map +0 -1
- package/dist/cli/commands/ui.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/config/__tests__/config.test.d.ts.map +0 -1
- package/dist/config/__tests__/config.test.js.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/schema.d.ts.map +0 -1
- package/dist/config/schema.js.map +0 -1
- package/dist/logger/__tests__/logger.test.d.ts.map +0 -1
- package/dist/logger/__tests__/logger.test.js.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/server/__tests__/providers-route.test.d.ts.map +0 -1
- package/dist/server/__tests__/providers-route.test.js.map +0 -1
- package/dist/server/__tests__/proxy.test.d.ts.map +0 -1
- package/dist/server/__tests__/proxy.test.js.map +0 -1
- package/dist/server/__tests__/server.test.d.ts.map +0 -1
- package/dist/server/__tests__/server.test.js.map +0 -1
- package/dist/server/__tests__/ui-route.test.d.ts.map +0 -1
- package/dist/server/__tests__/ui-route.test.js.map +0 -1
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/auth.js.map +0 -1
- package/dist/server/data-push.d.ts.map +0 -1
- package/dist/server/data-push.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/middleware/__tests__/request-id.test.d.ts.map +0 -1
- package/dist/server/middleware/__tests__/request-id.test.js.map +0 -1
- package/dist/server/middleware/request-id.d.ts.map +0 -1
- package/dist/server/middleware/request-id.js.map +0 -1
- package/dist/server/providers-route.d.ts.map +0 -1
- package/dist/server/providers-route.js.map +0 -1
- package/dist/server/proxy.d.ts.map +0 -1
- package/dist/server/proxy.js.map +0 -1
- package/dist/server/ui-route.d.ts.map +0 -1
- package/dist/server/ui-route.js.map +0 -1
- package/dist/tools/curl.tool.d.ts.map +0 -1
- package/dist/tools/curl.tool.js.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/probe.tool.d.ts.map +0 -1
- package/dist/tools/probe.tool.js.map +0 -1
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/registry.js.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js.map +0 -1
- package/dist/types/api.d.ts.map +0 -1
- package/dist/types/api.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/log.d.ts.map +0 -1
- package/dist/types/log.js.map +0 -1
- package/dist/types/pm2.d.ts.map +0 -1
- package/dist/types/pm2.js.map +0 -1
- package/dist/utils/__mocks__/esm-dirname.d.ts.map +0 -1
- package/dist/utils/__mocks__/esm-dirname.js.map +0 -1
- package/dist/utils/__mocks__/pm2-helpers.d.ts.map +0 -1
- package/dist/utils/__mocks__/pm2-helpers.js.map +0 -1
- package/dist/utils/__tests__/db-migration.test.d.ts.map +0 -1
- package/dist/utils/__tests__/db-migration.test.js.map +0 -1
- package/dist/utils/__tests__/inject-loop.test.d.ts.map +0 -1
- package/dist/utils/__tests__/inject-loop.test.js.map +0 -1
- package/dist/utils/__tests__/net.test.d.ts.map +0 -1
- package/dist/utils/__tests__/net.test.js.map +0 -1
- package/dist/utils/__tests__/pm2.test.d.ts.map +0 -1
- package/dist/utils/__tests__/pm2.test.js.map +0 -1
- package/dist/utils/__tests__/providers-db.test.d.ts.map +0 -1
- package/dist/utils/__tests__/providers-db.test.js.map +0 -1
- package/dist/utils/__tests__/request-writer.test.d.ts.map +0 -1
- package/dist/utils/__tests__/request-writer.test.js.map +0 -1
- package/dist/utils/__tests__/sse-accumulator.test.d.ts.map +0 -1
- package/dist/utils/__tests__/sse-accumulator.test.js.map +0 -1
- package/dist/utils/__tests__/sse-writer.test.d.ts.map +0 -1
- package/dist/utils/__tests__/sse-writer.test.js.map +0 -1
- package/dist/utils/__tests__/tool-injector.test.d.ts.map +0 -1
- package/dist/utils/__tests__/tool-injector.test.js.map +0 -1
- package/dist/utils/db.d.ts.map +0 -1
- package/dist/utils/db.js.map +0 -1
- package/dist/utils/esm-dirname.d.ts.map +0 -1
- package/dist/utils/esm-dirname.js.map +0 -1
- package/dist/utils/inject-loop.d.ts.map +0 -1
- package/dist/utils/inject-loop.js.map +0 -1
- package/dist/utils/migrate-files-to-db.d.ts.map +0 -1
- package/dist/utils/migrate-files-to-db.js.map +0 -1
- package/dist/utils/net.d.ts.map +0 -1
- package/dist/utils/net.js.map +0 -1
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pm2.d.ts.map +0 -1
- package/dist/utils/pm2.js.map +0 -1
- package/dist/utils/providers-db.d.ts.map +0 -1
- package/dist/utils/providers-db.js.map +0 -1
- package/dist/utils/request-writer.d.ts.map +0 -1
- package/dist/utils/request-writer.js.map +0 -1
- package/dist/utils/sse-accumulator.d.ts.map +0 -1
- package/dist/utils/sse-accumulator.js.map +0 -1
- package/dist/utils/sse-writer.d.ts.map +0 -1
- package/dist/utils/sse-writer.js.map +0 -1
- package/dist/utils/stats-aggregator.d.ts.map +0 -1
- package/dist/utils/stats-aggregator.js.map +0 -1
- package/dist/utils/status-history.d.ts.map +0 -1
- package/dist/utils/status-history.js.map +0 -1
- package/dist/utils/tool-injector.d.ts.map +0 -1
- package/dist/utils/tool-injector.js.map +0 -1
- package/dist/utils/version.d.ts.map +0 -1
- package/dist/utils/version.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function execCommand(prompt: string): Promise<void>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { loadConfig } from '../../config/index.js';
|
|
2
|
+
async function parseSSEStream(response) {
|
|
3
|
+
const reader = response.body.getReader();
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
let buffer = '';
|
|
6
|
+
let exitCode = 0;
|
|
7
|
+
while (true) {
|
|
8
|
+
const { done, value } = await reader.read();
|
|
9
|
+
if (done)
|
|
10
|
+
break;
|
|
11
|
+
buffer += decoder.decode(value, { stream: true });
|
|
12
|
+
const lines = buffer.split('\n');
|
|
13
|
+
buffer = lines.pop() || ''; // Keep incomplete line in buffer
|
|
14
|
+
let eventType = '';
|
|
15
|
+
let eventData = '';
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
if (line.startsWith('event: ')) {
|
|
18
|
+
eventType = line.slice(7);
|
|
19
|
+
}
|
|
20
|
+
else if (line.startsWith('data: ')) {
|
|
21
|
+
eventData = line.slice(6);
|
|
22
|
+
}
|
|
23
|
+
else if (line === '') {
|
|
24
|
+
// End of event
|
|
25
|
+
if (eventType && eventData) {
|
|
26
|
+
try {
|
|
27
|
+
const data = JSON.parse(eventData);
|
|
28
|
+
if (eventType === 'data') {
|
|
29
|
+
if (data.type === 'stderr') {
|
|
30
|
+
process.stderr.write(data.content);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
process.stdout.write(data.content);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (eventType === 'error') {
|
|
37
|
+
console.error('\nError:', data.message);
|
|
38
|
+
}
|
|
39
|
+
else if (eventType === 'done') {
|
|
40
|
+
exitCode = data.code ?? 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Ignore malformed JSON
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
eventType = '';
|
|
48
|
+
eventData = '';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return exitCode;
|
|
53
|
+
}
|
|
54
|
+
async function checkServerReachable(baseUrl) {
|
|
55
|
+
try {
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const timeoutId = setTimeout(() => controller.abort(), 2000);
|
|
58
|
+
const response = await fetch(`${baseUrl}/ui/api/status`, {
|
|
59
|
+
signal: controller.signal
|
|
60
|
+
});
|
|
61
|
+
clearTimeout(timeoutId);
|
|
62
|
+
return response.ok;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export async function execCommand(prompt) {
|
|
69
|
+
// Load config
|
|
70
|
+
const config = await loadConfig();
|
|
71
|
+
const host = config.server.host === '0.0.0.0' || config.server.host === '::'
|
|
72
|
+
? '127.0.0.1'
|
|
73
|
+
: config.server.host;
|
|
74
|
+
const baseUrl = `http://${host}:${config.server.port}`;
|
|
75
|
+
// Check if server is reachable
|
|
76
|
+
const isReachable = await checkServerReachable(baseUrl);
|
|
77
|
+
if (!isReachable) {
|
|
78
|
+
console.error('Server not running. Use "ccm start" first.');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
// Build request
|
|
82
|
+
const headers = {
|
|
83
|
+
'Content-Type': 'application/json'
|
|
84
|
+
};
|
|
85
|
+
if (config.auth?.token) {
|
|
86
|
+
headers['Authorization'] = `Bearer ${config.auth.token}`;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch(`${baseUrl}/ui/api/exec`, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers,
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
tool: 'claude',
|
|
94
|
+
prompt,
|
|
95
|
+
stream: true
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
const text = await response.text();
|
|
100
|
+
let errorMsg = `Request failed with status ${response.status}`;
|
|
101
|
+
try {
|
|
102
|
+
const json = JSON.parse(text);
|
|
103
|
+
errorMsg = json.error || errorMsg;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
errorMsg = text || errorMsg;
|
|
107
|
+
}
|
|
108
|
+
console.error('Error:', errorMsg);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
const contentType = response.headers.get('content-type') || '';
|
|
112
|
+
if (contentType.includes('text/event-stream')) {
|
|
113
|
+
const exitCode = await parseSSEStream(response);
|
|
114
|
+
process.exit(exitCode);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const result = await response.json();
|
|
118
|
+
if (result.output) {
|
|
119
|
+
process.stdout.write(result.output);
|
|
120
|
+
}
|
|
121
|
+
if (result.error) {
|
|
122
|
+
process.stderr.write(result.error);
|
|
123
|
+
}
|
|
124
|
+
process.exit(result.success ? 0 : 1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
console.error('Failed to execute command:', err.message);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
package/dist/cli/commands/ui.js
CHANGED
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -2,58 +2,115 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { setConfigPathOverride } from '../utils/paths.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { getProjectVersion } from '../utils/version.js';
|
|
6
|
+
// Check for -p/--prompt BEFORE loading commander and other commands
|
|
7
|
+
function checkForPromptOption() {
|
|
8
|
+
let prompt = null;
|
|
9
|
+
let configPath = null;
|
|
10
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
11
|
+
const arg = process.argv[i];
|
|
12
|
+
if (arg === '-p' || arg === '--prompt') {
|
|
13
|
+
if (i + 1 < process.argv.length) {
|
|
14
|
+
prompt = process.argv[i + 1];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (arg === '-c' || arg === '--config') {
|
|
18
|
+
if (i + 1 < process.argv.length) {
|
|
19
|
+
configPath = process.argv[i + 1];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { prompt, configPath };
|
|
24
|
+
}
|
|
25
|
+
// Handle prompt option early
|
|
26
|
+
const { prompt, configPath } = checkForPromptOption();
|
|
27
|
+
if (prompt) {
|
|
28
|
+
if (configPath) {
|
|
29
|
+
setConfigPathOverride(path.resolve(configPath));
|
|
30
|
+
}
|
|
31
|
+
const { execCommand } = await import('./commands/exec.js');
|
|
32
|
+
await execCommand(prompt);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
14
35
|
const program = new Command();
|
|
15
36
|
program
|
|
16
|
-
.name('
|
|
17
|
-
.description('Claude Code Proxy Helper
|
|
18
|
-
.version(
|
|
37
|
+
.name('ccm')
|
|
38
|
+
.description('Claude Code Proxy Helper')
|
|
39
|
+
.version(getProjectVersion())
|
|
19
40
|
.option('-c, --config <path>', 'Path to config file')
|
|
41
|
+
.option('-p, --prompt <prompt>', 'Execute claude -p <prompt> via server')
|
|
20
42
|
.hook('preAction', () => {
|
|
21
43
|
const opts = program.opts();
|
|
22
44
|
if (opts.config) {
|
|
23
45
|
setConfigPathOverride(path.resolve(opts.config));
|
|
24
46
|
}
|
|
25
47
|
});
|
|
48
|
+
program.command('prompt')
|
|
49
|
+
.alias('p')
|
|
50
|
+
.description('Execute claude -p <prompt> via server')
|
|
51
|
+
.argument('<prompt>', 'Prompt text')
|
|
52
|
+
.action(async (prompt) => {
|
|
53
|
+
const { execCommand } = await import('./commands/exec.js');
|
|
54
|
+
await execCommand(prompt);
|
|
55
|
+
});
|
|
26
56
|
program.command('start')
|
|
27
57
|
.description('Start proxy server')
|
|
28
58
|
.option('-p, --port <port>', 'Override port', (val) => parseInt(val))
|
|
29
|
-
.action(
|
|
59
|
+
.action(async (options) => {
|
|
60
|
+
const { startCommand } = await import('./commands/start.js');
|
|
61
|
+
await startCommand(options);
|
|
62
|
+
});
|
|
30
63
|
program.command('stop')
|
|
31
64
|
.description('Stop proxy server')
|
|
32
|
-
.action(
|
|
65
|
+
.action(async () => {
|
|
66
|
+
const { stopCommand } = await import('./commands/stop.js');
|
|
67
|
+
await stopCommand();
|
|
68
|
+
});
|
|
33
69
|
program.command('kill')
|
|
34
70
|
.description('Kill proxy server and remove from PM2')
|
|
35
|
-
.action(
|
|
71
|
+
.action(async () => {
|
|
72
|
+
const { killCommand } = await import('./commands/kill.js');
|
|
73
|
+
await killCommand();
|
|
74
|
+
});
|
|
36
75
|
program.command('status')
|
|
37
76
|
.description('Show server status')
|
|
38
|
-
.action(
|
|
77
|
+
.action(async () => {
|
|
78
|
+
const { statusCommand } = await import('./commands/status.js');
|
|
79
|
+
await statusCommand();
|
|
80
|
+
});
|
|
39
81
|
program.command('logs [n]')
|
|
40
82
|
.description('Show recent logs')
|
|
41
83
|
.option('-l, --level <level>', 'Filter by level')
|
|
42
84
|
.option('-g, --grep <pattern>', 'Search pattern')
|
|
43
|
-
.action(
|
|
85
|
+
.action(async (n, options) => {
|
|
86
|
+
const { logsCommand } = await import('./commands/logs.js');
|
|
87
|
+
await logsCommand(n, options);
|
|
88
|
+
});
|
|
44
89
|
program.command('config <action> [key] [value]')
|
|
45
90
|
.description('Manage configuration (show/set/reset)')
|
|
46
|
-
.action(
|
|
91
|
+
.action(async (action, key, value) => {
|
|
92
|
+
const { configCommand } = await import('./commands/config.js');
|
|
93
|
+
await configCommand(action, key, value);
|
|
94
|
+
});
|
|
47
95
|
program.command('reload')
|
|
48
96
|
.description('Restart server (graceful)')
|
|
49
|
-
.action(
|
|
97
|
+
.action(async () => {
|
|
98
|
+
const { reloadCommand } = await import('./commands/reload.js');
|
|
99
|
+
await reloadCommand();
|
|
100
|
+
});
|
|
50
101
|
program.command('test')
|
|
51
102
|
.description('Test connection to target')
|
|
52
|
-
.action(
|
|
103
|
+
.action(async () => {
|
|
104
|
+
const { testCommand } = await import('./commands/test.js');
|
|
105
|
+
await testCommand();
|
|
106
|
+
});
|
|
53
107
|
program.command('ui')
|
|
54
108
|
.description('Open web UI dashboard')
|
|
55
109
|
.option('--build', 'Force rebuild UI')
|
|
56
|
-
.action(
|
|
110
|
+
.action(async (options) => {
|
|
111
|
+
const { uiCommand } = await import('./commands/ui.js');
|
|
112
|
+
await uiCommand(options);
|
|
113
|
+
});
|
|
57
114
|
program.command('clean-requests')
|
|
58
115
|
.description('清理旧的请求日志(SQLite)')
|
|
59
116
|
.option('--days <days>', '保留最近N天的数据', '7')
|
|
@@ -71,4 +128,3 @@ program.command('clean-requests')
|
|
|
71
128
|
console.log('清理完成');
|
|
72
129
|
});
|
|
73
130
|
program.parse();
|
|
74
|
-
//# sourceMappingURL=index.js.map
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
package/dist/config/schema.d.ts
CHANGED
package/dist/config/schema.js
CHANGED
package/dist/logger/index.d.ts
CHANGED
package/dist/logger/index.js
CHANGED
package/dist/server/auth.d.ts
CHANGED
package/dist/server/auth.js
CHANGED
|
@@ -3,4 +3,3 @@ export declare function addDataClient(ws: WebSocket): void;
|
|
|
3
3
|
export declare function removeDataClient(ws: WebSocket): void;
|
|
4
4
|
export declare function pushNewRequest(summary: any): void;
|
|
5
5
|
export declare function pushStatsNotify(): void;
|
|
6
|
-
//# sourceMappingURL=data-push.d.ts.map
|
package/dist/server/data-push.js
CHANGED
package/dist/server/index.d.ts
CHANGED
package/dist/server/index.js
CHANGED
package/dist/server/proxy.d.ts
CHANGED
|
@@ -22,4 +22,3 @@ export declare function getErrorStatusCode(error: ProxyError): number;
|
|
|
22
22
|
export declare function getErrorMessage(error: ProxyError): string;
|
|
23
23
|
export declare function setupProxy(fastify: FastifyInstance, proxyConfig: ProxyConfig): Promise<void>;
|
|
24
24
|
export {};
|
|
25
|
-
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/server/proxy.js
CHANGED
|
@@ -74,10 +74,18 @@ function filterForwardHeaders(headers, proxyApiKey) {
|
|
|
74
74
|
// Remove headers that cause issues
|
|
75
75
|
delete filtered.host;
|
|
76
76
|
delete filtered['content-length'];
|
|
77
|
+
delete filtered['x-req-key'];
|
|
77
78
|
// Replace API key if proxy key is configured
|
|
78
79
|
if (proxyApiKey) {
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
// Only replace existing headers, don't add new ones
|
|
81
|
+
if ('x-api-key' in filtered) {
|
|
82
|
+
filtered['x-api-key'] = proxyApiKey;
|
|
83
|
+
}
|
|
84
|
+
if ('authorization' in filtered || 'Authorization' in filtered) {
|
|
85
|
+
// Use the same case as the original header
|
|
86
|
+
const key = 'authorization' in filtered ? 'authorization' : 'Authorization';
|
|
87
|
+
filtered[key] = `Bearer ${proxyApiKey}`;
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
return filtered;
|
|
83
91
|
}
|
|
@@ -397,4 +405,3 @@ export async function setupProxy(fastify, proxyConfig) {
|
|
|
397
405
|
}
|
|
398
406
|
});
|
|
399
407
|
}
|
|
400
|
-
//# sourceMappingURL=proxy.js.map
|