@kaitranntt/ccs 7.37.0 → 7.37.1-dev.1
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/cliproxy/account-manager.d.ts +5 -207
- package/dist/cliproxy/account-manager.d.ts.map +1 -1
- package/dist/cliproxy/account-manager.js +35 -795
- package/dist/cliproxy/account-manager.js.map +1 -1
- package/dist/cliproxy/accounts/bulk-ops.d.ts +22 -0
- package/dist/cliproxy/accounts/bulk-ops.d.ts.map +1 -0
- package/dist/cliproxy/accounts/bulk-ops.js +88 -0
- package/dist/cliproxy/accounts/bulk-ops.js.map +1 -0
- package/dist/cliproxy/accounts/index.d.ts +19 -0
- package/dist/cliproxy/accounts/index.d.ts.map +1 -0
- package/dist/cliproxy/accounts/index.js +54 -0
- package/dist/cliproxy/accounts/index.js.map +1 -0
- package/dist/cliproxy/accounts/query.d.ts +36 -0
- package/dist/cliproxy/accounts/query.d.ts.map +1 -0
- package/dist/cliproxy/accounts/query.js +94 -0
- package/dist/cliproxy/accounts/query.js.map +1 -0
- package/dist/cliproxy/accounts/registry.d.ts +74 -0
- package/dist/cliproxy/accounts/registry.d.ts.map +1 -0
- package/dist/cliproxy/accounts/registry.js +510 -0
- package/dist/cliproxy/accounts/registry.js.map +1 -0
- package/dist/cliproxy/accounts/token-file-ops.d.ts +64 -0
- package/dist/cliproxy/accounts/token-file-ops.d.ts.map +1 -0
- package/dist/cliproxy/accounts/token-file-ops.js +206 -0
- package/dist/cliproxy/accounts/token-file-ops.js.map +1 -0
- package/dist/cliproxy/accounts/types.d.ts +66 -0
- package/dist/cliproxy/accounts/types.d.ts.map +1 -0
- package/dist/cliproxy/accounts/types.js +12 -0
- package/dist/cliproxy/accounts/types.js.map +1 -0
- package/dist/cliproxy/auth/token-expiry-checker.d.ts.map +1 -1
- package/dist/cliproxy/auth/token-expiry-checker.js +5 -1
- package/dist/cliproxy/auth/token-expiry-checker.js.map +1 -1
- package/dist/cliproxy/cliproxy-executor.d.ts +11 -28
- package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -1
- package/dist/cliproxy/cliproxy-executor.js +20 -1028
- package/dist/cliproxy/cliproxy-executor.js.map +1 -1
- package/dist/cliproxy/config/env-builder.d.ts +60 -0
- package/dist/cliproxy/config/env-builder.d.ts.map +1 -0
- package/dist/cliproxy/config/env-builder.js +311 -0
- package/dist/cliproxy/config/env-builder.js.map +1 -0
- package/dist/cliproxy/config/generator.d.ts +63 -0
- package/dist/cliproxy/config/generator.d.ts.map +1 -0
- package/dist/cliproxy/config/generator.js +336 -0
- package/dist/cliproxy/config/generator.js.map +1 -0
- package/dist/cliproxy/config/index.d.ts +10 -0
- package/dist/cliproxy/config/index.d.ts.map +1 -0
- package/dist/cliproxy/config/index.js +26 -0
- package/dist/cliproxy/config/index.js.map +1 -0
- package/dist/cliproxy/config/path-resolver.d.ts +47 -0
- package/dist/cliproxy/config/path-resolver.d.ts.map +1 -0
- package/dist/cliproxy/config/path-resolver.js +104 -0
- package/dist/cliproxy/config/path-resolver.js.map +1 -0
- package/dist/cliproxy/config/port-manager.d.ts +33 -0
- package/dist/cliproxy/config/port-manager.d.ts.map +1 -0
- package/dist/cliproxy/config/port-manager.js +68 -0
- package/dist/cliproxy/config/port-manager.js.map +1 -0
- package/dist/cliproxy/config/thinking-config.d.ts +39 -0
- package/dist/cliproxy/config/thinking-config.d.ts.map +1 -0
- package/dist/cliproxy/config/thinking-config.js +143 -0
- package/dist/cliproxy/config/thinking-config.js.map +1 -0
- package/dist/cliproxy/config-generator.d.ts +9 -221
- package/dist/cliproxy/config-generator.d.ts.map +1 -1
- package/dist/cliproxy/config-generator.js +12 -856
- package/dist/cliproxy/config-generator.js.map +1 -1
- package/dist/cliproxy/executor/env-resolver.d.ts +45 -0
- package/dist/cliproxy/executor/env-resolver.d.ts.map +1 -0
- package/dist/cliproxy/executor/env-resolver.js +106 -0
- package/dist/cliproxy/executor/env-resolver.js.map +1 -0
- package/dist/cliproxy/executor/index.d.ts +24 -0
- package/dist/cliproxy/executor/index.d.ts.map +1 -0
- package/dist/cliproxy/executor/index.js +669 -0
- package/dist/cliproxy/executor/index.js.map +1 -0
- package/dist/cliproxy/executor/lifecycle-manager.d.ts +33 -0
- package/dist/cliproxy/executor/lifecycle-manager.d.ts.map +1 -0
- package/dist/cliproxy/executor/lifecycle-manager.js +161 -0
- package/dist/cliproxy/executor/lifecycle-manager.js.map +1 -0
- package/dist/cliproxy/executor/retry-handler.d.ts +27 -0
- package/dist/cliproxy/executor/retry-handler.d.ts.map +1 -0
- package/dist/cliproxy/executor/retry-handler.js +109 -0
- package/dist/cliproxy/executor/retry-handler.js.map +1 -0
- package/dist/cliproxy/executor/session-bridge.d.ts +30 -0
- package/dist/cliproxy/executor/session-bridge.d.ts.map +1 -0
- package/dist/cliproxy/executor/session-bridge.js +232 -0
- package/dist/cliproxy/executor/session-bridge.js.map +1 -0
- package/dist/commands/cliproxy/auth-subcommand.d.ts +10 -0
- package/dist/commands/cliproxy/auth-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/auth-subcommand.js +55 -0
- package/dist/commands/cliproxy/auth-subcommand.js.map +1 -0
- package/dist/commands/cliproxy/help-subcommand.d.ts +8 -0
- package/dist/commands/cliproxy/help-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/help-subcommand.js +87 -0
- package/dist/commands/cliproxy/help-subcommand.js.map +1 -0
- package/dist/commands/cliproxy/index.d.ts +11 -0
- package/dist/commands/cliproxy/index.d.ts.map +1 -0
- package/dist/commands/cliproxy/index.js +196 -0
- package/dist/commands/cliproxy/index.js.map +1 -0
- package/dist/commands/cliproxy/install-subcommand.d.ts +14 -0
- package/dist/commands/cliproxy/install-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/install-subcommand.js +112 -0
- package/dist/commands/cliproxy/install-subcommand.js.map +1 -0
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts +10 -0
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js +54 -0
- package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js.map +1 -0
- package/dist/commands/cliproxy/quota-subcommand.d.ts +16 -0
- package/dist/commands/cliproxy/quota-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/quota-subcommand.js +383 -0
- package/dist/commands/cliproxy/quota-subcommand.js.map +1 -0
- package/dist/commands/cliproxy/variant-subcommand.d.ts +11 -0
- package/dist/commands/cliproxy/variant-subcommand.d.ts.map +1 -0
- package/dist/commands/cliproxy/variant-subcommand.js +292 -0
- package/dist/commands/cliproxy/variant-subcommand.js.map +1 -0
- package/dist/commands/cliproxy-command.d.ts +4 -15
- package/dist/commands/cliproxy-command.d.ts.map +1 -1
- package/dist/commands/cliproxy-command.js +5 -1090
- package/dist/commands/cliproxy-command.js.map +1 -1
- package/dist/commands/version-command.js +1 -1
- package/dist/commands/version-command.js.map +1 -1
- package/dist/ui/assets/{accounts-DmKrgrCj.js → accounts-D0KU1a-4.js} +1 -1
- package/dist/ui/assets/{alert-dialog-CHcjWgRn.js → alert-dialog-BNRDV_Kh.js} +1 -1
- package/dist/ui/assets/{api-BFHZ3RKb.js → api-ClkFu9LY.js} +1 -1
- package/dist/ui/assets/{auth-section-DAI6Q5vU.js → auth-section-CNhNN1Jp.js} +1 -1
- package/dist/ui/assets/{backups-section-B1O8i4FM.js → backups-section-CZ721HIu.js} +1 -1
- package/dist/ui/assets/cliproxy-DeGucfVg.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-3zVE7jZH.js → cliproxy-control-panel-T9i_Ldh0.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-DV0JzL4A.js → confirm-dialog-Cy1__gRc.js} +1 -1
- package/dist/ui/assets/{copilot-BX8vT5RR.js → copilot-Cdqs2Jbh.js} +3 -3
- package/dist/ui/assets/{globalenv-section-BAft0m9b.js → globalenv-section-BEKtYN6I.js} +1 -1
- package/dist/ui/assets/{health-ct5TpFUE.js → health-BaHazGgS.js} +1 -1
- package/dist/ui/assets/{index-BOsGipAU.js → index-BTBpI5th.js} +1 -1
- package/dist/ui/assets/{index-CU3zgD6n.js → index-BZn6kF0u.js} +1 -1
- package/dist/ui/assets/{index-B8-K01HW.js → index-C2MS84sf.js} +1 -1
- package/dist/ui/assets/{index-gfWiPznS.js → index-CiULLjNI.js} +8 -8
- package/dist/ui/assets/{index-RZ6b7YTz.js → index-PjscK1jS.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-Ng9oZdrw.js → proxy-status-widget-BY6Lnr80.js} +1 -1
- package/dist/ui/assets/{shared-DpInRmag.js → shared-dZGNvBe9.js} +1 -1
- package/dist/ui/assets/{switch-DkRSlAu-.js → switch-BCFbehJz.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/cliproxy-BsSI8qFW.js +0 -3
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core config generation for CLIProxyAPI
|
|
4
|
+
* Handles unified config.yaml generation for all providers
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.deleteConfig = exports.deleteConfigForPort = exports.configExists = exports.configNeedsRegeneration = exports.regenerateConfig = exports.parseUserApiKeys = exports.generateConfig = exports.getProviderConfig = exports.CLIPROXY_CONFIG_VERSION = exports.CCS_CONTROL_PANEL_SECRET = exports.CCS_INTERNAL_API_KEY = void 0;
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const base_config_loader_1 = require("../base-config-loader");
|
|
34
|
+
const unified_config_loader_1 = require("../../config/unified-config-loader");
|
|
35
|
+
const auth_token_manager_1 = require("../auth-token-manager");
|
|
36
|
+
const path_resolver_1 = require("./path-resolver");
|
|
37
|
+
const port_manager_1 = require("./port-manager");
|
|
38
|
+
/** Internal API key for CCS-managed requests */
|
|
39
|
+
exports.CCS_INTERNAL_API_KEY = 'ccs-internal-managed';
|
|
40
|
+
/** Simple secret key for Control Panel login (user-facing) */
|
|
41
|
+
exports.CCS_CONTROL_PANEL_SECRET = 'ccs';
|
|
42
|
+
/**
|
|
43
|
+
* Config version - bump when config format changes to trigger regeneration
|
|
44
|
+
* v1: Initial config (port, auth-dir, api-keys only)
|
|
45
|
+
* v2: Full-featured config with dashboard, quota mgmt, simplified key
|
|
46
|
+
* v3: Logging disabled by default (user opt-in via ~/.ccs/config.yaml)
|
|
47
|
+
* v4: Added Kiro (AWS) and GitHub Copilot providers
|
|
48
|
+
* v5: Added disable-cooling: true for stability
|
|
49
|
+
*/
|
|
50
|
+
exports.CLIPROXY_CONFIG_VERSION = 5;
|
|
51
|
+
/** Provider display names (static metadata) */
|
|
52
|
+
const PROVIDER_DISPLAY_NAMES = {
|
|
53
|
+
gemini: 'Gemini',
|
|
54
|
+
codex: 'Codex',
|
|
55
|
+
agy: 'Antigravity',
|
|
56
|
+
qwen: 'Qwen Code',
|
|
57
|
+
iflow: 'iFlow',
|
|
58
|
+
kiro: 'Kiro (AWS)',
|
|
59
|
+
ghcp: 'GitHub Copilot (OAuth)',
|
|
60
|
+
claude: 'Claude (Anthropic)',
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Get provider configuration
|
|
64
|
+
* Model mappings are loaded from config/base-{provider}.settings.json
|
|
65
|
+
*/
|
|
66
|
+
function getProviderConfig(provider) {
|
|
67
|
+
const displayName = PROVIDER_DISPLAY_NAMES[provider];
|
|
68
|
+
if (!displayName) {
|
|
69
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
70
|
+
}
|
|
71
|
+
// Load models from base config file
|
|
72
|
+
const models = (0, base_config_loader_1.getModelMappingFromConfig)(provider);
|
|
73
|
+
return {
|
|
74
|
+
name: provider,
|
|
75
|
+
displayName,
|
|
76
|
+
models,
|
|
77
|
+
requiresOAuth: true, // All CLIProxy providers require OAuth
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
exports.getProviderConfig = getProviderConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Get CLIProxy logging settings from user config.
|
|
83
|
+
* Defaults to disabled to prevent disk bloat.
|
|
84
|
+
*/
|
|
85
|
+
function getLoggingSettings() {
|
|
86
|
+
const config = (0, unified_config_loader_1.loadOrCreateUnifiedConfig)();
|
|
87
|
+
return {
|
|
88
|
+
loggingToFile: config.cliproxy.logging?.enabled ?? false,
|
|
89
|
+
requestLog: config.cliproxy.logging?.request_log ?? false,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generate UNIFIED config.yaml content for ALL providers
|
|
94
|
+
* This enables concurrent usage of gemini/codex/agy without config conflicts.
|
|
95
|
+
* CLIProxyAPI routes requests by model name to the appropriate provider.
|
|
96
|
+
*
|
|
97
|
+
* @param port - Server port (default: 8317)
|
|
98
|
+
* @param userApiKeys - User-added API keys to preserve (default: [])
|
|
99
|
+
*/
|
|
100
|
+
function generateUnifiedConfigContent(port = port_manager_1.CLIPROXY_DEFAULT_PORT, userApiKeys = []) {
|
|
101
|
+
const authDir = (0, path_resolver_1.getAuthDir)(); // Base auth dir - CLIProxyAPI scans subdirectories
|
|
102
|
+
// Convert Windows backslashes to forward slashes for YAML compatibility
|
|
103
|
+
const authDirNormalized = authDir.split(path.sep).join('/');
|
|
104
|
+
// Get logging settings from user config (disabled by default)
|
|
105
|
+
const { loggingToFile, requestLog } = getLoggingSettings();
|
|
106
|
+
// Get effective auth tokens (respects user customization)
|
|
107
|
+
const effectiveApiKey = (0, auth_token_manager_1.getEffectiveApiKey)();
|
|
108
|
+
const effectiveSecret = (0, auth_token_manager_1.getEffectiveManagementSecret)();
|
|
109
|
+
// Build api-keys section with internal key + preserved user keys
|
|
110
|
+
const allApiKeys = [effectiveApiKey, ...userApiKeys];
|
|
111
|
+
const apiKeysYaml = allApiKeys.map((key) => ` - "${key}"`).join('\n');
|
|
112
|
+
// Unified config with enhanced CLIProxyAPI features
|
|
113
|
+
const config = `# CLIProxyAPI config generated by CCS v${exports.CLIPROXY_CONFIG_VERSION}
|
|
114
|
+
# Supports: gemini, codex, agy, qwen, iflow (concurrent usage)
|
|
115
|
+
# Generated: ${new Date().toISOString()}
|
|
116
|
+
#
|
|
117
|
+
# This config is auto-managed by CCS. Manual edits may be overwritten.
|
|
118
|
+
# Use 'ccs doctor' to regenerate with latest settings.
|
|
119
|
+
|
|
120
|
+
# =============================================================================
|
|
121
|
+
# Server Settings
|
|
122
|
+
# =============================================================================
|
|
123
|
+
|
|
124
|
+
port: ${port}
|
|
125
|
+
debug: false
|
|
126
|
+
|
|
127
|
+
# =============================================================================
|
|
128
|
+
# Logging
|
|
129
|
+
# =============================================================================
|
|
130
|
+
# WARNING: Logs can grow to several GB if enabled!
|
|
131
|
+
# To enable logging, edit ~/.ccs/config.yaml:
|
|
132
|
+
# cliproxy:
|
|
133
|
+
# logging:
|
|
134
|
+
# enabled: true
|
|
135
|
+
# request_log: true
|
|
136
|
+
# Then run 'ccs doctor --fix' to regenerate this config.
|
|
137
|
+
# Use 'ccs cleanup' to remove old logs.
|
|
138
|
+
|
|
139
|
+
# Write logs to file (stored in ~/.ccs/cliproxy/logs/)
|
|
140
|
+
logging-to-file: ${loggingToFile}
|
|
141
|
+
|
|
142
|
+
# Log individual API requests for debugging/analytics
|
|
143
|
+
request-log: ${requestLog}
|
|
144
|
+
|
|
145
|
+
# =============================================================================
|
|
146
|
+
# Dashboard & Management
|
|
147
|
+
# =============================================================================
|
|
148
|
+
|
|
149
|
+
# Enable usage statistics for CCS dashboard analytics
|
|
150
|
+
usage-statistics-enabled: true
|
|
151
|
+
|
|
152
|
+
# Remote management API for CCS dashboard integration
|
|
153
|
+
remote-management:
|
|
154
|
+
allow-remote: true
|
|
155
|
+
secret-key: "${effectiveSecret}"
|
|
156
|
+
disable-control-panel: false
|
|
157
|
+
|
|
158
|
+
# =============================================================================
|
|
159
|
+
# Reliability & Quota Management
|
|
160
|
+
# =============================================================================
|
|
161
|
+
|
|
162
|
+
# Disable quota cooldown scheduling for stability
|
|
163
|
+
disable-cooling: true
|
|
164
|
+
|
|
165
|
+
# Auto-retry on transient errors (403, 408, 500, 502, 503, 504)
|
|
166
|
+
request-retry: 0
|
|
167
|
+
max-retry-interval: 0
|
|
168
|
+
|
|
169
|
+
# Auto-switch accounts on quota exceeded (429)
|
|
170
|
+
# This enables seamless multi-account rotation when rate limited
|
|
171
|
+
quota-exceeded:
|
|
172
|
+
switch-project: true
|
|
173
|
+
switch-preview-model: true
|
|
174
|
+
|
|
175
|
+
# =============================================================================
|
|
176
|
+
# Authentication
|
|
177
|
+
# =============================================================================
|
|
178
|
+
|
|
179
|
+
# API keys for CCS and user-added external requests
|
|
180
|
+
# NOTE: User-added keys are preserved across CCS updates (fix for issue #200)
|
|
181
|
+
api-keys:
|
|
182
|
+
${apiKeysYaml}
|
|
183
|
+
|
|
184
|
+
# OAuth tokens directory (auto-discovered by CLIProxyAPI)
|
|
185
|
+
auth-dir: "${authDirNormalized}"
|
|
186
|
+
`;
|
|
187
|
+
return config;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate unified config.yaml file (supports all providers concurrently)
|
|
191
|
+
* Only regenerates if config doesn't exist.
|
|
192
|
+
* @returns Path to config file
|
|
193
|
+
*/
|
|
194
|
+
function generateConfig(provider, port = port_manager_1.CLIPROXY_DEFAULT_PORT) {
|
|
195
|
+
const configPath = (0, path_resolver_1.getConfigPathForPort)(port);
|
|
196
|
+
// Ensure provider auth directory exists
|
|
197
|
+
const authDir = (0, path_resolver_1.getProviderAuthDir)(provider);
|
|
198
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
199
|
+
fs.mkdirSync(authDir, { recursive: true, mode: 0o700 });
|
|
200
|
+
// Only generate config if it doesn't exist (unified config serves all providers)
|
|
201
|
+
if (!fs.existsSync(configPath)) {
|
|
202
|
+
const configContent = generateUnifiedConfigContent(port);
|
|
203
|
+
fs.writeFileSync(configPath, configContent, { mode: 0o600 });
|
|
204
|
+
}
|
|
205
|
+
return configPath;
|
|
206
|
+
}
|
|
207
|
+
exports.generateConfig = generateConfig;
|
|
208
|
+
/**
|
|
209
|
+
* Parse user-added API keys from existing config content.
|
|
210
|
+
* Extracts all keys except the internal CCS key for preservation.
|
|
211
|
+
*
|
|
212
|
+
* @param content - Existing config.yaml content
|
|
213
|
+
* @returns Array of user-added API keys (excludes CCS_INTERNAL_API_KEY)
|
|
214
|
+
*/
|
|
215
|
+
function parseUserApiKeys(content) {
|
|
216
|
+
const userKeys = [];
|
|
217
|
+
// Find the api-keys section by looking for lines starting with " - " after "api-keys:"
|
|
218
|
+
// Normalize line endings first
|
|
219
|
+
const normalizedContent = content.replace(/\r\n/g, '\n');
|
|
220
|
+
// Find the api-keys: line and extract all subsequent key entries
|
|
221
|
+
const lines = normalizedContent.split('\n');
|
|
222
|
+
let inApiKeysSection = false;
|
|
223
|
+
for (const line of lines) {
|
|
224
|
+
// Check if this is the start of api-keys section
|
|
225
|
+
if (line.match(/^api-keys:\s*$/)) {
|
|
226
|
+
inApiKeysSection = true;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
// If we're in the api-keys section, look for key entries
|
|
230
|
+
if (inApiKeysSection) {
|
|
231
|
+
// Key entries are indented with " - " or similar
|
|
232
|
+
const keyMatch = line.match(/^\s+-\s*"([^"]*)"/);
|
|
233
|
+
if (keyMatch) {
|
|
234
|
+
const key = keyMatch[1];
|
|
235
|
+
// Exclude the internal CCS key and empty strings
|
|
236
|
+
if (key && key !== exports.CCS_INTERNAL_API_KEY) {
|
|
237
|
+
userKeys.push(key);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else if (line.match(/^\S/) && line.trim().length > 0) {
|
|
241
|
+
// Non-indented line that's not empty means we've left the api-keys section
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
// Continue for blank lines or other indented content
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return userKeys;
|
|
248
|
+
}
|
|
249
|
+
exports.parseUserApiKeys = parseUserApiKeys;
|
|
250
|
+
/**
|
|
251
|
+
* Force regenerate config.yaml with latest settings.
|
|
252
|
+
* Preserves user-added API keys and port settings.
|
|
253
|
+
*
|
|
254
|
+
* @param port - Default port to use if not found in existing config
|
|
255
|
+
* @returns Path to new config file
|
|
256
|
+
*/
|
|
257
|
+
function regenerateConfig(port = port_manager_1.CLIPROXY_DEFAULT_PORT) {
|
|
258
|
+
const configPath = (0, path_resolver_1.getConfigPathForPort)(port);
|
|
259
|
+
// Preserve user settings from existing config
|
|
260
|
+
let effectivePort = port;
|
|
261
|
+
let userApiKeys = [];
|
|
262
|
+
if (fs.existsSync(configPath)) {
|
|
263
|
+
try {
|
|
264
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
265
|
+
// Preserve port setting
|
|
266
|
+
const portMatch = content.match(/^port:\s*(\d+)/m);
|
|
267
|
+
if (portMatch) {
|
|
268
|
+
effectivePort = parseInt(portMatch[1], 10);
|
|
269
|
+
}
|
|
270
|
+
// Preserve user-added API keys (fix for issue #200)
|
|
271
|
+
userApiKeys = parseUserApiKeys(content);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// Use defaults if reading fails
|
|
275
|
+
}
|
|
276
|
+
// Delete existing config
|
|
277
|
+
fs.unlinkSync(configPath);
|
|
278
|
+
}
|
|
279
|
+
// Ensure directories exist
|
|
280
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
281
|
+
fs.mkdirSync((0, path_resolver_1.getAuthDir)(), { recursive: true, mode: 0o700 });
|
|
282
|
+
// Generate fresh config with preserved user API keys
|
|
283
|
+
const configContent = generateUnifiedConfigContent(effectivePort, userApiKeys);
|
|
284
|
+
fs.writeFileSync(configPath, configContent, { mode: 0o600 });
|
|
285
|
+
return configPath;
|
|
286
|
+
}
|
|
287
|
+
exports.regenerateConfig = regenerateConfig;
|
|
288
|
+
/**
|
|
289
|
+
* Check if config needs regeneration (version mismatch)
|
|
290
|
+
* @returns true if config should be regenerated
|
|
291
|
+
*/
|
|
292
|
+
function configNeedsRegeneration() {
|
|
293
|
+
const configPath = (0, path_resolver_1.getConfigPathForPort)(port_manager_1.CLIPROXY_DEFAULT_PORT);
|
|
294
|
+
if (!fs.existsSync(configPath)) {
|
|
295
|
+
return false; // Will be created on first use
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
299
|
+
// Check for version marker
|
|
300
|
+
const versionMatch = content.match(/CCS v(\d+)/);
|
|
301
|
+
if (!versionMatch) {
|
|
302
|
+
return true; // No version marker = old config
|
|
303
|
+
}
|
|
304
|
+
const configVersion = parseInt(versionMatch[1], 10);
|
|
305
|
+
return configVersion < exports.CLIPROXY_CONFIG_VERSION;
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return true; // Error reading = regenerate
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
exports.configNeedsRegeneration = configNeedsRegeneration;
|
|
312
|
+
/**
|
|
313
|
+
* Check if config exists for port
|
|
314
|
+
*/
|
|
315
|
+
function configExists(port = port_manager_1.CLIPROXY_DEFAULT_PORT) {
|
|
316
|
+
return fs.existsSync((0, path_resolver_1.getConfigPathForPort)(port));
|
|
317
|
+
}
|
|
318
|
+
exports.configExists = configExists;
|
|
319
|
+
/**
|
|
320
|
+
* Delete config file for specific port
|
|
321
|
+
*/
|
|
322
|
+
function deleteConfigForPort(port) {
|
|
323
|
+
const configPath = (0, path_resolver_1.getConfigPathForPort)(port);
|
|
324
|
+
if (fs.existsSync(configPath)) {
|
|
325
|
+
fs.unlinkSync(configPath);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.deleteConfigForPort = deleteConfigForPort;
|
|
329
|
+
/**
|
|
330
|
+
* Delete config file (default port)
|
|
331
|
+
*/
|
|
332
|
+
function deleteConfig() {
|
|
333
|
+
deleteConfigForPort(port_manager_1.CLIPROXY_DEFAULT_PORT);
|
|
334
|
+
}
|
|
335
|
+
exports.deleteConfig = deleteConfig;
|
|
336
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/cliproxy/config/generator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAE7B,8DAAkE;AAClE,8EAA+E;AAC/E,8DAAyF;AACzF,mDAAuF;AACvF,iDAAuD;AAEvD,gDAAgD;AACnC,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;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EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AALD,kDAKC;AAED;;GAEG;AACH,SAAgB,YAAY;IAC1B,mBAAmB,CAAC,oCAAqB,CAAC,CAAC;AAC7C,CAAC;AAFD,oCAEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config module barrel exports
|
|
3
|
+
* Re-exports all config generation utilities from modular structure
|
|
4
|
+
*/
|
|
5
|
+
export * from './generator';
|
|
6
|
+
export * from './port-manager';
|
|
7
|
+
export * from './env-builder';
|
|
8
|
+
export * from './thinking-config';
|
|
9
|
+
export * from './path-resolver';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/config/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config module barrel exports
|
|
4
|
+
* Re-exports all config generation utilities from modular structure
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./generator"), exports);
|
|
22
|
+
__exportStar(require("./port-manager"), exports);
|
|
23
|
+
__exportStar(require("./env-builder"), exports);
|
|
24
|
+
__exportStar(require("./thinking-config"), exports);
|
|
25
|
+
__exportStar(require("./path-resolver"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cliproxy/config/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,iDAA+B;AAC/B,gDAA8B;AAC9B,oDAAkC;AAClC,kDAAgC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path resolution utilities for CLIProxy directories and files
|
|
3
|
+
* Centralizes all path management for CLIProxy configuration
|
|
4
|
+
*/
|
|
5
|
+
import { CLIProxyProvider } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Get CLIProxy base directory
|
|
8
|
+
* All CLIProxy-related files are stored under ~/.ccs/cliproxy/
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCliproxyDir(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get CLIProxy writable directory for logs and runtime files.
|
|
13
|
+
* This directory is set as WRITABLE_PATH env var when spawning CLIProxy.
|
|
14
|
+
* Logs will be stored in ~/.ccs/cliproxy/logs/
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCliproxyWritablePath(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get base auth directory for CLIProxyAPI
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAuthDir(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get auth directory for provider
|
|
23
|
+
* All providers use a FLAT auth directory structure for unified config.
|
|
24
|
+
* CLIProxyAPI stores OAuth tokens directly in auth/ (not subdirectories).
|
|
25
|
+
* This enables all providers to be discovered and used concurrently.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getProviderAuthDir(_provider: CLIProxyProvider): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get config file path for a specific port.
|
|
30
|
+
* Default port uses config.yaml, others use config-{port}.yaml.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getConfigPathForPort(port: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Get CLIProxy config file path (default port)
|
|
35
|
+
* Named distinctly from config-manager's getConfigPath to avoid confusion.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCliproxyConfigPath(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get binary directory path
|
|
40
|
+
*/
|
|
41
|
+
export declare function getBinDir(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get path to user settings file for provider
|
|
44
|
+
* Example: ~/.ccs/gemini.settings.json
|
|
45
|
+
*/
|
|
46
|
+
export declare function getProviderSettingsPath(provider: CLIProxyProvider): string;
|
|
47
|
+
//# sourceMappingURL=path-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-resolver.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/config/path-resolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAItE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAE1E"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Path resolution utilities for CLIProxy directories and files
|
|
4
|
+
* Centralizes all path management for CLIProxy configuration
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.getProviderSettingsPath = exports.getBinDir = exports.getCliproxyConfigPath = exports.getConfigPathForPort = exports.getProviderAuthDir = exports.getAuthDir = exports.getCliproxyWritablePath = exports.getCliproxyDir = void 0;
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const config_manager_1 = require("../../utils/config-manager");
|
|
33
|
+
const port_manager_1 = require("./port-manager");
|
|
34
|
+
/**
|
|
35
|
+
* Get CLIProxy base directory
|
|
36
|
+
* All CLIProxy-related files are stored under ~/.ccs/cliproxy/
|
|
37
|
+
*/
|
|
38
|
+
function getCliproxyDir() {
|
|
39
|
+
return path.join((0, config_manager_1.getCcsDir)(), 'cliproxy');
|
|
40
|
+
}
|
|
41
|
+
exports.getCliproxyDir = getCliproxyDir;
|
|
42
|
+
/**
|
|
43
|
+
* Get CLIProxy writable directory for logs and runtime files.
|
|
44
|
+
* This directory is set as WRITABLE_PATH env var when spawning CLIProxy.
|
|
45
|
+
* Logs will be stored in ~/.ccs/cliproxy/logs/
|
|
46
|
+
*/
|
|
47
|
+
function getCliproxyWritablePath() {
|
|
48
|
+
return path.join((0, config_manager_1.getCcsDir)(), 'cliproxy');
|
|
49
|
+
}
|
|
50
|
+
exports.getCliproxyWritablePath = getCliproxyWritablePath;
|
|
51
|
+
/**
|
|
52
|
+
* Get base auth directory for CLIProxyAPI
|
|
53
|
+
*/
|
|
54
|
+
function getAuthDir() {
|
|
55
|
+
return path.join(getCliproxyDir(), 'auth');
|
|
56
|
+
}
|
|
57
|
+
exports.getAuthDir = getAuthDir;
|
|
58
|
+
/**
|
|
59
|
+
* Get auth directory for provider
|
|
60
|
+
* All providers use a FLAT auth directory structure for unified config.
|
|
61
|
+
* CLIProxyAPI stores OAuth tokens directly in auth/ (not subdirectories).
|
|
62
|
+
* This enables all providers to be discovered and used concurrently.
|
|
63
|
+
*/
|
|
64
|
+
function getProviderAuthDir(_provider) {
|
|
65
|
+
// Use flat structure - all auth files in same directory for unified discovery
|
|
66
|
+
// Provider param kept for API compatibility (CLIProxyAPI handles via auth file type field)
|
|
67
|
+
return path.join(getCliproxyDir(), 'auth');
|
|
68
|
+
}
|
|
69
|
+
exports.getProviderAuthDir = getProviderAuthDir;
|
|
70
|
+
/**
|
|
71
|
+
* Get config file path for a specific port.
|
|
72
|
+
* Default port uses config.yaml, others use config-{port}.yaml.
|
|
73
|
+
*/
|
|
74
|
+
function getConfigPathForPort(port) {
|
|
75
|
+
if (port === port_manager_1.CLIPROXY_DEFAULT_PORT) {
|
|
76
|
+
return path.join(getCliproxyDir(), 'config.yaml');
|
|
77
|
+
}
|
|
78
|
+
return path.join(getCliproxyDir(), `config-${port}.yaml`);
|
|
79
|
+
}
|
|
80
|
+
exports.getConfigPathForPort = getConfigPathForPort;
|
|
81
|
+
/**
|
|
82
|
+
* Get CLIProxy config file path (default port)
|
|
83
|
+
* Named distinctly from config-manager's getConfigPath to avoid confusion.
|
|
84
|
+
*/
|
|
85
|
+
function getCliproxyConfigPath() {
|
|
86
|
+
return getConfigPathForPort(port_manager_1.CLIPROXY_DEFAULT_PORT);
|
|
87
|
+
}
|
|
88
|
+
exports.getCliproxyConfigPath = getCliproxyConfigPath;
|
|
89
|
+
/**
|
|
90
|
+
* Get binary directory path
|
|
91
|
+
*/
|
|
92
|
+
function getBinDir() {
|
|
93
|
+
return path.join(getCliproxyDir(), 'bin');
|
|
94
|
+
}
|
|
95
|
+
exports.getBinDir = getBinDir;
|
|
96
|
+
/**
|
|
97
|
+
* Get path to user settings file for provider
|
|
98
|
+
* Example: ~/.ccs/gemini.settings.json
|
|
99
|
+
*/
|
|
100
|
+
function getProviderSettingsPath(provider) {
|
|
101
|
+
return path.join((0, config_manager_1.getCcsDir)(), `${provider}.settings.json`);
|
|
102
|
+
}
|
|
103
|
+
exports.getProviderSettingsPath = getProviderSettingsPath;
|
|
104
|
+
//# sourceMappingURL=path-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,QAA0B;IAChE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAA,0BAAS,GAAE,EAAE,GAAG,QAAQ,gBAAgB,CAAC,CAAC;AAC7D,CAAC;AAFD,0DAEC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port validation and management utilities
|
|
3
|
+
* Handles port number validation and default port resolution
|
|
4
|
+
*/
|
|
5
|
+
/** Default CLIProxy port */
|
|
6
|
+
export declare const CLIPROXY_DEFAULT_PORT = 8317;
|
|
7
|
+
/**
|
|
8
|
+
* Validate port is a valid positive integer (1-65535).
|
|
9
|
+
* Returns default port if invalid.
|
|
10
|
+
*
|
|
11
|
+
* @param port - Port number to validate
|
|
12
|
+
* @returns Valid port or CLIPROXY_DEFAULT_PORT (8317) if invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function validatePort(port: number | undefined): number;
|
|
15
|
+
/**
|
|
16
|
+
* Validate and sanitize port number for remote connections.
|
|
17
|
+
* Returns undefined for invalid ports (letting caller use default).
|
|
18
|
+
* Valid range: 1-65535, must be integer.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateRemotePort(port: number | undefined): number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Get default port for remote CLIProxyAPI based on protocol.
|
|
23
|
+
* - HTTP: 8317 (CLIProxyAPI default)
|
|
24
|
+
* - HTTPS: 443 (standard SSL port)
|
|
25
|
+
*/
|
|
26
|
+
export declare function getRemoteDefaultPort(protocol: 'http' | 'https'): number;
|
|
27
|
+
/**
|
|
28
|
+
* Normalize protocol to lowercase and validate.
|
|
29
|
+
* Handles runtime case sensitivity (e.g., 'HTTPS' → 'https').
|
|
30
|
+
* Defaults to 'http' for invalid values.
|
|
31
|
+
*/
|
|
32
|
+
export declare function normalizeProtocol(protocol: string | undefined): 'http' | 'https';
|
|
33
|
+
//# sourceMappingURL=port-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port-manager.d.ts","sourceRoot":"","sources":["../../../src/cliproxy/config/port-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4BAA4B;AAC5B,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQ7D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK/E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAOhF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Port validation and management utilities
|
|
4
|
+
* Handles port number validation and default port resolution
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.normalizeProtocol = exports.getRemoteDefaultPort = exports.validateRemotePort = exports.validatePort = exports.CLIPROXY_DEFAULT_PORT = void 0;
|
|
8
|
+
/** Default CLIProxy port */
|
|
9
|
+
exports.CLIPROXY_DEFAULT_PORT = 8317;
|
|
10
|
+
/**
|
|
11
|
+
* Validate port is a valid positive integer (1-65535).
|
|
12
|
+
* Returns default port if invalid.
|
|
13
|
+
*
|
|
14
|
+
* @param port - Port number to validate
|
|
15
|
+
* @returns Valid port or CLIPROXY_DEFAULT_PORT (8317) if invalid
|
|
16
|
+
*/
|
|
17
|
+
function validatePort(port) {
|
|
18
|
+
if (port === undefined || port === null) {
|
|
19
|
+
return exports.CLIPROXY_DEFAULT_PORT;
|
|
20
|
+
}
|
|
21
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535 || !Number.isInteger(port)) {
|
|
22
|
+
return exports.CLIPROXY_DEFAULT_PORT;
|
|
23
|
+
}
|
|
24
|
+
return port;
|
|
25
|
+
}
|
|
26
|
+
exports.validatePort = validatePort;
|
|
27
|
+
/**
|
|
28
|
+
* Validate and sanitize port number for remote connections.
|
|
29
|
+
* Returns undefined for invalid ports (letting caller use default).
|
|
30
|
+
* Valid range: 1-65535, must be integer.
|
|
31
|
+
*/
|
|
32
|
+
function validateRemotePort(port) {
|
|
33
|
+
if (port === undefined || port === null)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (typeof port !== 'number' || !Number.isInteger(port))
|
|
36
|
+
return undefined;
|
|
37
|
+
if (port <= 0 || port > 65535)
|
|
38
|
+
return undefined;
|
|
39
|
+
return port;
|
|
40
|
+
}
|
|
41
|
+
exports.validateRemotePort = validateRemotePort;
|
|
42
|
+
/**
|
|
43
|
+
* Get default port for remote CLIProxyAPI based on protocol.
|
|
44
|
+
* - HTTP: 8317 (CLIProxyAPI default)
|
|
45
|
+
* - HTTPS: 443 (standard SSL port)
|
|
46
|
+
*/
|
|
47
|
+
function getRemoteDefaultPort(protocol) {
|
|
48
|
+
return protocol === 'https' ? 443 : exports.CLIPROXY_DEFAULT_PORT;
|
|
49
|
+
}
|
|
50
|
+
exports.getRemoteDefaultPort = getRemoteDefaultPort;
|
|
51
|
+
/**
|
|
52
|
+
* Normalize protocol to lowercase and validate.
|
|
53
|
+
* Handles runtime case sensitivity (e.g., 'HTTPS' → 'https').
|
|
54
|
+
* Defaults to 'http' for invalid values.
|
|
55
|
+
*/
|
|
56
|
+
function normalizeProtocol(protocol) {
|
|
57
|
+
if (!protocol)
|
|
58
|
+
return 'http';
|
|
59
|
+
const normalized = protocol.toLowerCase();
|
|
60
|
+
if (normalized === 'https')
|
|
61
|
+
return 'https';
|
|
62
|
+
if (normalized === 'http')
|
|
63
|
+
return 'http';
|
|
64
|
+
// Invalid protocol (e.g., 'ftp') - default to http
|
|
65
|
+
return 'http';
|
|
66
|
+
}
|
|
67
|
+
exports.normalizeProtocol = normalizeProtocol;
|
|
68
|
+
//# sourceMappingURL=port-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port-manager.js","sourceRoot":"","sources":["../../../src/cliproxy/config/port-manager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4BAA4B;AACf,QAAA,qBAAqB,GAAG,IAAI,CAAC;AAE1C;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,IAAwB;IACnD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,6BAAqB,CAAC;IAC/B,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAClF,OAAO,6BAAqB,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,oCAQC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,IAAwB;IACzD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1E,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,SAAS,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC;AALD,gDAKC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,QAA0B;IAC7D,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,6BAAqB,CAAC;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