@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.
Files changed (259) hide show
  1. package/dist/cli/__tests__/commands.test.d.ts +0 -1
  2. package/dist/cli/__tests__/commands.test.js +0 -1
  3. package/dist/cli/commands/config.d.ts +0 -1
  4. package/dist/cli/commands/config.js +0 -1
  5. package/dist/cli/commands/exec.d.ts +1 -0
  6. package/dist/cli/commands/exec.js +131 -0
  7. package/dist/cli/commands/kill.d.ts +0 -1
  8. package/dist/cli/commands/kill.js +0 -1
  9. package/dist/cli/commands/logs.d.ts +0 -1
  10. package/dist/cli/commands/logs.js +0 -1
  11. package/dist/cli/commands/reload.d.ts +0 -1
  12. package/dist/cli/commands/reload.js +0 -1
  13. package/dist/cli/commands/start.d.ts +0 -1
  14. package/dist/cli/commands/start.js +0 -1
  15. package/dist/cli/commands/status.d.ts +0 -1
  16. package/dist/cli/commands/status.js +0 -1
  17. package/dist/cli/commands/stop.d.ts +0 -1
  18. package/dist/cli/commands/stop.js +0 -1
  19. package/dist/cli/commands/test.d.ts +0 -1
  20. package/dist/cli/commands/test.js +0 -1
  21. package/dist/cli/commands/ui.d.ts +0 -1
  22. package/dist/cli/commands/ui.js +0 -1
  23. package/dist/cli/index.d.ts +0 -1
  24. package/dist/cli/index.js +78 -22
  25. package/dist/config/__tests__/config.test.d.ts +0 -1
  26. package/dist/config/__tests__/config.test.js +0 -1
  27. package/dist/config/index.d.ts +0 -1
  28. package/dist/config/index.js +0 -1
  29. package/dist/config/schema.d.ts +0 -1
  30. package/dist/config/schema.js +0 -1
  31. package/dist/logger/__tests__/logger.test.d.ts +0 -1
  32. package/dist/logger/__tests__/logger.test.js +0 -1
  33. package/dist/logger/index.d.ts +0 -1
  34. package/dist/logger/index.js +0 -1
  35. package/dist/server/__tests__/providers-route.test.d.ts +0 -1
  36. package/dist/server/__tests__/providers-route.test.js +0 -1
  37. package/dist/server/__tests__/proxy.test.d.ts +0 -1
  38. package/dist/server/__tests__/proxy.test.js +0 -1
  39. package/dist/server/__tests__/server.test.d.ts +0 -1
  40. package/dist/server/__tests__/server.test.js +0 -1
  41. package/dist/server/__tests__/ui-route.test.d.ts +0 -1
  42. package/dist/server/__tests__/ui-route.test.js +0 -1
  43. package/dist/server/auth.d.ts +0 -1
  44. package/dist/server/auth.js +0 -1
  45. package/dist/server/data-push.d.ts +0 -1
  46. package/dist/server/data-push.js +0 -1
  47. package/dist/server/index.d.ts +0 -1
  48. package/dist/server/index.js +0 -1
  49. package/dist/server/middleware/__tests__/request-id.test.d.ts +0 -1
  50. package/dist/server/middleware/__tests__/request-id.test.js +0 -1
  51. package/dist/server/middleware/request-id.d.ts +0 -1
  52. package/dist/server/middleware/request-id.js +0 -1
  53. package/dist/server/providers-route.d.ts +0 -1
  54. package/dist/server/providers-route.js +0 -1
  55. package/dist/server/proxy.d.ts +0 -1
  56. package/dist/server/proxy.js +10 -3
  57. package/dist/server/ui-route.d.ts +0 -1
  58. package/dist/server/ui-route.js +125 -1
  59. package/dist/tools/curl.tool.d.ts +0 -1
  60. package/dist/tools/curl.tool.js +0 -1
  61. package/dist/tools/index.d.ts +0 -1
  62. package/dist/tools/index.js +0 -1
  63. package/dist/tools/probe.tool.d.ts +0 -1
  64. package/dist/tools/probe.tool.js +0 -1
  65. package/dist/tools/registry.d.ts +0 -1
  66. package/dist/tools/registry.js +0 -1
  67. package/dist/tools/types.d.ts +0 -1
  68. package/dist/tools/types.js +0 -1
  69. package/dist/types/api.d.ts +0 -1
  70. package/dist/types/api.js +0 -1
  71. package/dist/types/config.d.ts +0 -1
  72. package/dist/types/config.js +0 -1
  73. package/dist/types/index.d.ts +0 -1
  74. package/dist/types/index.js +0 -1
  75. package/dist/types/log.d.ts +0 -1
  76. package/dist/types/log.js +0 -1
  77. package/dist/types/pm2.d.ts +0 -1
  78. package/dist/types/pm2.js +0 -1
  79. package/dist/utils/__mocks__/esm-dirname.d.ts +0 -1
  80. package/dist/utils/__mocks__/esm-dirname.js +0 -1
  81. package/dist/utils/__mocks__/pm2-helpers.d.ts +0 -1
  82. package/dist/utils/__mocks__/pm2-helpers.js +0 -1
  83. package/dist/utils/__tests__/db-migration.test.d.ts +0 -1
  84. package/dist/utils/__tests__/db-migration.test.js +0 -1
  85. package/dist/utils/__tests__/inject-loop.test.d.ts +0 -1
  86. package/dist/utils/__tests__/inject-loop.test.js +0 -1
  87. package/dist/utils/__tests__/net.test.d.ts +0 -1
  88. package/dist/utils/__tests__/net.test.js +0 -1
  89. package/dist/utils/__tests__/pm2.test.d.ts +0 -1
  90. package/dist/utils/__tests__/pm2.test.js +0 -1
  91. package/dist/utils/__tests__/providers-db.test.d.ts +0 -1
  92. package/dist/utils/__tests__/providers-db.test.js +0 -1
  93. package/dist/utils/__tests__/request-writer.test.d.ts +0 -1
  94. package/dist/utils/__tests__/request-writer.test.js +0 -1
  95. package/dist/utils/__tests__/sse-accumulator.test.d.ts +0 -1
  96. package/dist/utils/__tests__/sse-accumulator.test.js +0 -1
  97. package/dist/utils/__tests__/sse-writer.test.d.ts +0 -1
  98. package/dist/utils/__tests__/sse-writer.test.js +0 -1
  99. package/dist/utils/__tests__/tool-injector.test.d.ts +0 -1
  100. package/dist/utils/__tests__/tool-injector.test.js +0 -1
  101. package/dist/utils/db.d.ts +0 -1
  102. package/dist/utils/db.js +0 -1
  103. package/dist/utils/esm-dirname.d.ts +0 -1
  104. package/dist/utils/esm-dirname.js +0 -1
  105. package/dist/utils/inject-loop.d.ts +0 -1
  106. package/dist/utils/inject-loop.js +0 -1
  107. package/dist/utils/migrate-files-to-db.d.ts +0 -1
  108. package/dist/utils/migrate-files-to-db.js +0 -1
  109. package/dist/utils/net.d.ts +0 -1
  110. package/dist/utils/net.js +0 -1
  111. package/dist/utils/paths.d.ts +0 -1
  112. package/dist/utils/paths.js +0 -1
  113. package/dist/utils/pm2.d.ts +0 -1
  114. package/dist/utils/pm2.js +0 -1
  115. package/dist/utils/providers-db.d.ts +0 -1
  116. package/dist/utils/providers-db.js +0 -1
  117. package/dist/utils/request-writer.d.ts +0 -1
  118. package/dist/utils/request-writer.js +0 -1
  119. package/dist/utils/sse-accumulator.d.ts +0 -1
  120. package/dist/utils/sse-accumulator.js +0 -1
  121. package/dist/utils/sse-writer.d.ts +0 -1
  122. package/dist/utils/sse-writer.js +0 -1
  123. package/dist/utils/stats-aggregator.d.ts +0 -1
  124. package/dist/utils/stats-aggregator.js +0 -1
  125. package/dist/utils/status-history.d.ts +0 -1
  126. package/dist/utils/status-history.js +0 -1
  127. package/dist/utils/tool-injector.d.ts +0 -1
  128. package/dist/utils/tool-injector.js +0 -1
  129. package/dist/utils/version.d.ts +0 -1
  130. package/dist/utils/version.js +0 -1
  131. package/package.json +1 -1
  132. package/dist/cli/__tests__/commands.test.d.ts.map +0 -1
  133. package/dist/cli/__tests__/commands.test.js.map +0 -1
  134. package/dist/cli/commands/config.d.ts.map +0 -1
  135. package/dist/cli/commands/config.js.map +0 -1
  136. package/dist/cli/commands/kill.d.ts.map +0 -1
  137. package/dist/cli/commands/kill.js.map +0 -1
  138. package/dist/cli/commands/logs.d.ts.map +0 -1
  139. package/dist/cli/commands/logs.js.map +0 -1
  140. package/dist/cli/commands/reload.d.ts.map +0 -1
  141. package/dist/cli/commands/reload.js.map +0 -1
  142. package/dist/cli/commands/start.d.ts.map +0 -1
  143. package/dist/cli/commands/start.js.map +0 -1
  144. package/dist/cli/commands/status.d.ts.map +0 -1
  145. package/dist/cli/commands/status.js.map +0 -1
  146. package/dist/cli/commands/stop.d.ts.map +0 -1
  147. package/dist/cli/commands/stop.js.map +0 -1
  148. package/dist/cli/commands/test.d.ts.map +0 -1
  149. package/dist/cli/commands/test.js.map +0 -1
  150. package/dist/cli/commands/ui.d.ts.map +0 -1
  151. package/dist/cli/commands/ui.js.map +0 -1
  152. package/dist/cli/index.d.ts.map +0 -1
  153. package/dist/cli/index.js.map +0 -1
  154. package/dist/config/__tests__/config.test.d.ts.map +0 -1
  155. package/dist/config/__tests__/config.test.js.map +0 -1
  156. package/dist/config/index.d.ts.map +0 -1
  157. package/dist/config/index.js.map +0 -1
  158. package/dist/config/schema.d.ts.map +0 -1
  159. package/dist/config/schema.js.map +0 -1
  160. package/dist/logger/__tests__/logger.test.d.ts.map +0 -1
  161. package/dist/logger/__tests__/logger.test.js.map +0 -1
  162. package/dist/logger/index.d.ts.map +0 -1
  163. package/dist/logger/index.js.map +0 -1
  164. package/dist/server/__tests__/providers-route.test.d.ts.map +0 -1
  165. package/dist/server/__tests__/providers-route.test.js.map +0 -1
  166. package/dist/server/__tests__/proxy.test.d.ts.map +0 -1
  167. package/dist/server/__tests__/proxy.test.js.map +0 -1
  168. package/dist/server/__tests__/server.test.d.ts.map +0 -1
  169. package/dist/server/__tests__/server.test.js.map +0 -1
  170. package/dist/server/__tests__/ui-route.test.d.ts.map +0 -1
  171. package/dist/server/__tests__/ui-route.test.js.map +0 -1
  172. package/dist/server/auth.d.ts.map +0 -1
  173. package/dist/server/auth.js.map +0 -1
  174. package/dist/server/data-push.d.ts.map +0 -1
  175. package/dist/server/data-push.js.map +0 -1
  176. package/dist/server/index.d.ts.map +0 -1
  177. package/dist/server/index.js.map +0 -1
  178. package/dist/server/middleware/__tests__/request-id.test.d.ts.map +0 -1
  179. package/dist/server/middleware/__tests__/request-id.test.js.map +0 -1
  180. package/dist/server/middleware/request-id.d.ts.map +0 -1
  181. package/dist/server/middleware/request-id.js.map +0 -1
  182. package/dist/server/providers-route.d.ts.map +0 -1
  183. package/dist/server/providers-route.js.map +0 -1
  184. package/dist/server/proxy.d.ts.map +0 -1
  185. package/dist/server/proxy.js.map +0 -1
  186. package/dist/server/ui-route.d.ts.map +0 -1
  187. package/dist/server/ui-route.js.map +0 -1
  188. package/dist/tools/curl.tool.d.ts.map +0 -1
  189. package/dist/tools/curl.tool.js.map +0 -1
  190. package/dist/tools/index.d.ts.map +0 -1
  191. package/dist/tools/index.js.map +0 -1
  192. package/dist/tools/probe.tool.d.ts.map +0 -1
  193. package/dist/tools/probe.tool.js.map +0 -1
  194. package/dist/tools/registry.d.ts.map +0 -1
  195. package/dist/tools/registry.js.map +0 -1
  196. package/dist/tools/types.d.ts.map +0 -1
  197. package/dist/tools/types.js.map +0 -1
  198. package/dist/types/api.d.ts.map +0 -1
  199. package/dist/types/api.js.map +0 -1
  200. package/dist/types/config.d.ts.map +0 -1
  201. package/dist/types/config.js.map +0 -1
  202. package/dist/types/index.d.ts.map +0 -1
  203. package/dist/types/index.js.map +0 -1
  204. package/dist/types/log.d.ts.map +0 -1
  205. package/dist/types/log.js.map +0 -1
  206. package/dist/types/pm2.d.ts.map +0 -1
  207. package/dist/types/pm2.js.map +0 -1
  208. package/dist/utils/__mocks__/esm-dirname.d.ts.map +0 -1
  209. package/dist/utils/__mocks__/esm-dirname.js.map +0 -1
  210. package/dist/utils/__mocks__/pm2-helpers.d.ts.map +0 -1
  211. package/dist/utils/__mocks__/pm2-helpers.js.map +0 -1
  212. package/dist/utils/__tests__/db-migration.test.d.ts.map +0 -1
  213. package/dist/utils/__tests__/db-migration.test.js.map +0 -1
  214. package/dist/utils/__tests__/inject-loop.test.d.ts.map +0 -1
  215. package/dist/utils/__tests__/inject-loop.test.js.map +0 -1
  216. package/dist/utils/__tests__/net.test.d.ts.map +0 -1
  217. package/dist/utils/__tests__/net.test.js.map +0 -1
  218. package/dist/utils/__tests__/pm2.test.d.ts.map +0 -1
  219. package/dist/utils/__tests__/pm2.test.js.map +0 -1
  220. package/dist/utils/__tests__/providers-db.test.d.ts.map +0 -1
  221. package/dist/utils/__tests__/providers-db.test.js.map +0 -1
  222. package/dist/utils/__tests__/request-writer.test.d.ts.map +0 -1
  223. package/dist/utils/__tests__/request-writer.test.js.map +0 -1
  224. package/dist/utils/__tests__/sse-accumulator.test.d.ts.map +0 -1
  225. package/dist/utils/__tests__/sse-accumulator.test.js.map +0 -1
  226. package/dist/utils/__tests__/sse-writer.test.d.ts.map +0 -1
  227. package/dist/utils/__tests__/sse-writer.test.js.map +0 -1
  228. package/dist/utils/__tests__/tool-injector.test.d.ts.map +0 -1
  229. package/dist/utils/__tests__/tool-injector.test.js.map +0 -1
  230. package/dist/utils/db.d.ts.map +0 -1
  231. package/dist/utils/db.js.map +0 -1
  232. package/dist/utils/esm-dirname.d.ts.map +0 -1
  233. package/dist/utils/esm-dirname.js.map +0 -1
  234. package/dist/utils/inject-loop.d.ts.map +0 -1
  235. package/dist/utils/inject-loop.js.map +0 -1
  236. package/dist/utils/migrate-files-to-db.d.ts.map +0 -1
  237. package/dist/utils/migrate-files-to-db.js.map +0 -1
  238. package/dist/utils/net.d.ts.map +0 -1
  239. package/dist/utils/net.js.map +0 -1
  240. package/dist/utils/paths.d.ts.map +0 -1
  241. package/dist/utils/paths.js.map +0 -1
  242. package/dist/utils/pm2.d.ts.map +0 -1
  243. package/dist/utils/pm2.js.map +0 -1
  244. package/dist/utils/providers-db.d.ts.map +0 -1
  245. package/dist/utils/providers-db.js.map +0 -1
  246. package/dist/utils/request-writer.d.ts.map +0 -1
  247. package/dist/utils/request-writer.js.map +0 -1
  248. package/dist/utils/sse-accumulator.d.ts.map +0 -1
  249. package/dist/utils/sse-accumulator.js.map +0 -1
  250. package/dist/utils/sse-writer.d.ts.map +0 -1
  251. package/dist/utils/sse-writer.js.map +0 -1
  252. package/dist/utils/stats-aggregator.d.ts.map +0 -1
  253. package/dist/utils/stats-aggregator.js.map +0 -1
  254. package/dist/utils/status-history.d.ts.map +0 -1
  255. package/dist/utils/status-history.js.map +0 -1
  256. package/dist/utils/tool-injector.d.ts.map +0 -1
  257. package/dist/utils/tool-injector.js.map +0 -1
  258. package/dist/utils/version.d.ts.map +0 -1
  259. package/dist/utils/version.js.map +0 -1
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=commands.test.d.ts.map
@@ -284,4 +284,3 @@ describe('uiCommand', () => {
284
284
  expect(execSync).toHaveBeenCalled();
285
285
  });
286
286
  });
287
- //# sourceMappingURL=commands.test.js.map
@@ -1,2 +1 @@
1
1
  export declare function configCommand(action: string, key?: string, value?: string): Promise<void>;
2
- //# sourceMappingURL=config.d.ts.map
@@ -37,4 +37,3 @@ export async function configCommand(action, key, value) {
37
37
  }
38
38
  console.error('Invalid action. Use: show, set, reset');
39
39
  }
40
- //# sourceMappingURL=config.js.map
@@ -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
+ }
@@ -1,2 +1 @@
1
1
  export declare function killCommand(): Promise<void>;
2
- //# sourceMappingURL=kill.d.ts.map
@@ -4,4 +4,3 @@ export async function killCommand() {
4
4
  await killProcess('cc-monitoring');
5
5
  console.log('Server killed and removed from PM2');
6
6
  }
7
- //# sourceMappingURL=kill.js.map
@@ -3,4 +3,3 @@ export interface LogsOptions {
3
3
  grep?: string;
4
4
  }
5
5
  export declare function logsCommand(n: string | undefined, options: LogsOptions): Promise<void>;
6
- //# sourceMappingURL=logs.d.ts.map
@@ -9,4 +9,3 @@ export async function logsCommand(n, options) {
9
9
  });
10
10
  logs.forEach(line => console.log(line));
11
11
  }
12
- //# sourceMappingURL=logs.js.map
@@ -1,2 +1 @@
1
1
  export declare function reloadCommand(): Promise<void>;
2
- //# sourceMappingURL=reload.d.ts.map
@@ -51,4 +51,3 @@ export async function reloadCommand() {
51
51
  process.exit(1);
52
52
  }
53
53
  }
54
- //# sourceMappingURL=reload.js.map
@@ -2,4 +2,3 @@ export interface StartOptions {
2
2
  port?: number;
3
3
  }
4
4
  export declare function startCommand(options: StartOptions): Promise<void>;
5
- //# sourceMappingURL=start.d.ts.map
@@ -67,4 +67,3 @@ function printSummary(config) {
67
67
  console.log(` ${chalk.gray('Logs')} ${path.join(logsDir, 'out.log')}`);
68
68
  console.log();
69
69
  }
70
- //# sourceMappingURL=start.js.map
@@ -1,2 +1 @@
1
1
  export declare function statusCommand(): Promise<void>;
2
- //# sourceMappingURL=status.d.ts.map
@@ -12,4 +12,3 @@ export async function statusCommand() {
12
12
  console.log(` Uptime: ${(status.uptime / 1000).toFixed(0)}s`);
13
13
  console.log(` Restarts: ${status.restarts}`);
14
14
  }
15
- //# sourceMappingURL=status.js.map
@@ -1,2 +1 @@
1
1
  export declare function stopCommand(): Promise<void>;
2
- //# sourceMappingURL=stop.d.ts.map
@@ -4,4 +4,3 @@ export async function stopCommand() {
4
4
  await stopProcess('cc-monitoring');
5
5
  console.log('Server stopped');
6
6
  }
7
- //# sourceMappingURL=stop.js.map
@@ -1,2 +1 @@
1
1
  export declare function testCommand(): Promise<void>;
2
- //# sourceMappingURL=test.d.ts.map
@@ -13,4 +13,3 @@ export async function testCommand() {
13
13
  console.error('Connection failed:', err.message);
14
14
  }
15
15
  }
16
- //# sourceMappingURL=test.js.map
@@ -2,4 +2,3 @@ export interface UiOptions {
2
2
  build?: boolean;
3
3
  }
4
4
  export declare function uiCommand(options: UiOptions): Promise<void>;
5
- //# sourceMappingURL=ui.d.ts.map
@@ -32,4 +32,3 @@ export async function uiCommand(options) {
32
32
  const open = (await import('open')).default;
33
33
  await open(url);
34
34
  }
35
- //# sourceMappingURL=ui.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=index.d.ts.map
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 { startCommand } from './commands/start.js';
6
- import { stopCommand } from './commands/stop.js';
7
- import { killCommand } from './commands/kill.js';
8
- import { statusCommand } from './commands/status.js';
9
- import { logsCommand } from './commands/logs.js';
10
- import { configCommand } from './commands/config.js';
11
- import { reloadCommand } from './commands/reload.js';
12
- import { testCommand } from './commands/test.js';
13
- import { uiCommand } from './commands/ui.js';
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('proxy')
17
- .description('Claude Code Proxy Helper - Forward requests to Aliyun')
18
- .version('1.0.0')
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(startCommand);
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(stopCommand);
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(killCommand);
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(statusCommand);
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(logsCommand);
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(configCommand);
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(reloadCommand);
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(testCommand);
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(uiCommand);
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
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=config.test.d.ts.map
@@ -157,4 +157,3 @@ describe('ConfigError', () => {
157
157
  expect(err).toBeInstanceOf(Error);
158
158
  });
159
159
  });
160
- //# sourceMappingURL=config.test.js.map
@@ -5,4 +5,3 @@ export declare function resetConfig(configPath?: string): Promise<void>;
5
5
  export declare class ConfigError extends Error {
6
6
  constructor(message: string);
7
7
  }
8
- //# sourceMappingURL=index.d.ts.map
@@ -61,4 +61,3 @@ export class ConfigError extends Error {
61
61
  this.name = 'ConfigError';
62
62
  }
63
63
  }
64
- //# sourceMappingURL=index.js.map
@@ -129,4 +129,3 @@ interface ValidationResult {
129
129
  }>;
130
130
  }
131
131
  export {};
132
- //# sourceMappingURL=schema.d.ts.map
@@ -39,4 +39,3 @@ export function validateConfig(config) {
39
39
  }))
40
40
  };
41
41
  }
42
- //# sourceMappingURL=schema.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=logger.test.d.ts.map
@@ -120,4 +120,3 @@ describe('readLogs', () => {
120
120
  expect(parsed.msg).toBe('valid entry');
121
121
  });
122
122
  });
123
- //# sourceMappingURL=logger.test.js.map
@@ -9,4 +9,3 @@ export declare function readLogs(filePath: string, options: {
9
9
  grep?: string;
10
10
  }): Promise<string[]>;
11
11
  export { LEVEL_MAP, NUM_TO_LEVEL };
12
- //# sourceMappingURL=index.d.ts.map
@@ -117,4 +117,3 @@ export async function readLogs(filePath, options) {
117
117
  return filtered;
118
118
  }
119
119
  export { LEVEL_MAP, NUM_TO_LEVEL };
120
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=providers-route.test.d.ts.map
@@ -222,4 +222,3 @@ describe('Providers API', () => {
222
222
  });
223
223
  });
224
224
  });
225
- //# sourceMappingURL=providers-route.test.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=proxy.test.d.ts.map
@@ -93,4 +93,3 @@ describe('resolveProxyTarget', () => {
93
93
  expect(result.apiKey).toBe('config-key');
94
94
  });
95
95
  });
96
- //# sourceMappingURL=proxy.test.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=server.test.d.ts.map
@@ -121,4 +121,3 @@ describe('createServer', () => {
121
121
  expect(server).toBeDefined();
122
122
  });
123
123
  });
124
- //# sourceMappingURL=server.test.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=ui-route.test.d.ts.map
@@ -365,4 +365,3 @@ describe('setupUiRoutes', () => {
365
365
  });
366
366
  });
367
367
  });
368
- //# sourceMappingURL=ui-route.test.js.map
@@ -1,3 +1,2 @@
1
1
  export declare const AUTH_TOKEN_ENV = "UI_AUTH_TOKEN";
2
2
  export declare function checkAuth(request: any, config: any): boolean;
3
- //# sourceMappingURL=auth.d.ts.map
@@ -13,4 +13,3 @@ export function checkAuth(request, config) {
13
13
  : authHeader;
14
14
  return provided === token;
15
15
  }
16
- //# sourceMappingURL=auth.js.map
@@ -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
@@ -30,4 +30,3 @@ function broadcast(msg) {
30
30
  }
31
31
  }
32
32
  }
33
- //# sourceMappingURL=data-push.js.map
@@ -1,4 +1,3 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
2
  export declare function createServer(): Promise<FastifyInstance>;
3
3
  export declare function startServer(): Promise<void>;
4
- //# sourceMappingURL=index.d.ts.map
@@ -47,4 +47,3 @@ if (_isPm2 || _isDirectExecution) {
47
47
  process.exit(1);
48
48
  });
49
49
  }
50
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=request-id.test.d.ts.map
@@ -26,4 +26,3 @@ describe('requestIdMiddleware', () => {
26
26
  expect(body.id).toBe('custom-id-123');
27
27
  });
28
28
  });
29
- //# sourceMappingURL=request-id.test.js.map
@@ -1,3 +1,2 @@
1
1
  import { FastifyInstance } from 'fastify';
2
2
  export declare const requestIdMiddleware: (fastify: FastifyInstance) => Promise<void>;
3
- //# sourceMappingURL=request-id.d.ts.map
@@ -10,4 +10,3 @@ export const requestIdMiddleware = async (fastify) => {
10
10
  }
11
11
  });
12
12
  };
13
- //# sourceMappingURL=request-id.js.map
@@ -1,3 +1,2 @@
1
1
  import { FastifyInstance } from 'fastify';
2
2
  export declare function setupProvidersRoutes(fastify: FastifyInstance, config: any): Promise<void>;
3
- //# sourceMappingURL=providers-route.d.ts.map
@@ -51,4 +51,3 @@ export async function setupProvidersRoutes(fastify, config) {
51
51
  }
52
52
  });
53
53
  }
54
- //# sourceMappingURL=providers-route.js.map
@@ -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
@@ -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
- filtered['x-api-key'] = proxyApiKey;
80
- filtered['authorization'] = `Bearer ${proxyApiKey}`;
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
@@ -1,3 +1,2 @@
1
1
  import { FastifyInstance } from 'fastify';
2
2
  export declare function setupUiRoutes(fastify: FastifyInstance): Promise<void>;
3
- //# sourceMappingURL=ui-route.d.ts.map