ccman 3.0.20 → 3.0.21
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/index.js +49 -212
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var init_package = __esm({
|
|
|
39
39
|
"../core/package.json"() {
|
|
40
40
|
package_default = {
|
|
41
41
|
name: "@ccman/core",
|
|
42
|
-
version: "3.0.
|
|
42
|
+
version: "3.0.21",
|
|
43
43
|
type: "module",
|
|
44
44
|
description: "Core business logic for ccman",
|
|
45
45
|
main: "./dist/index.js",
|
|
@@ -2357,20 +2357,20 @@ var init_claude2 = __esm({
|
|
|
2357
2357
|
});
|
|
2358
2358
|
|
|
2359
2359
|
// ../core/dist/tool-manager.js
|
|
2360
|
-
function
|
|
2361
|
-
const
|
|
2362
|
-
const
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2360
|
+
function createToolManager(tool) {
|
|
2361
|
+
const toolConfig = TOOL_CONFIGS[tool];
|
|
2362
|
+
const configPath = toolConfig.configPath;
|
|
2363
|
+
function generateId() {
|
|
2364
|
+
const timestamp = Date.now();
|
|
2365
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
2366
|
+
return `${tool}-${timestamp}-${random}`;
|
|
2367
|
+
}
|
|
2367
2368
|
function loadConfig2() {
|
|
2368
2369
|
if (!fileExists(configPath)) {
|
|
2369
2370
|
ensureDir(getCcmanDir());
|
|
2370
2371
|
const initialConfig = {
|
|
2371
2372
|
providers: [],
|
|
2372
2373
|
presets: []
|
|
2373
|
-
// 只存储用户自定义预置
|
|
2374
2374
|
};
|
|
2375
2375
|
writeJSON(configPath, initialConfig);
|
|
2376
2376
|
return initialConfig;
|
|
@@ -2389,12 +2389,11 @@ function createCodexManager() {
|
|
|
2389
2389
|
}
|
|
2390
2390
|
const timestamp = Date.now();
|
|
2391
2391
|
const provider = {
|
|
2392
|
-
id: generateId(
|
|
2392
|
+
id: generateId(),
|
|
2393
2393
|
name: input.name,
|
|
2394
2394
|
baseUrl: input.baseUrl,
|
|
2395
2395
|
apiKey: input.apiKey,
|
|
2396
2396
|
model: input.model,
|
|
2397
|
-
// 保存 model 字段
|
|
2398
2397
|
createdAt: timestamp,
|
|
2399
2398
|
lastModified: timestamp
|
|
2400
2399
|
};
|
|
@@ -2428,7 +2427,7 @@ function createCodexManager() {
|
|
|
2428
2427
|
config.currentProviderId = id;
|
|
2429
2428
|
provider.lastUsedAt = Date.now();
|
|
2430
2429
|
saveConfig2(config);
|
|
2431
|
-
|
|
2430
|
+
toolConfig.writer(provider);
|
|
2432
2431
|
},
|
|
2433
2432
|
getCurrent() {
|
|
2434
2433
|
const config = loadConfig2();
|
|
@@ -2461,7 +2460,7 @@ function createCodexManager() {
|
|
|
2461
2460
|
provider.lastModified = Date.now();
|
|
2462
2461
|
saveConfig2(config);
|
|
2463
2462
|
if (config.currentProviderId === id) {
|
|
2464
|
-
|
|
2463
|
+
toolConfig.writer(provider);
|
|
2465
2464
|
}
|
|
2466
2465
|
return provider;
|
|
2467
2466
|
},
|
|
@@ -2487,7 +2486,7 @@ function createCodexManager() {
|
|
|
2487
2486
|
const timestamp = Date.now();
|
|
2488
2487
|
const newProvider = {
|
|
2489
2488
|
...source,
|
|
2490
|
-
id: generateId(
|
|
2489
|
+
id: generateId(),
|
|
2491
2490
|
name: newName,
|
|
2492
2491
|
createdAt: timestamp,
|
|
2493
2492
|
lastModified: timestamp,
|
|
@@ -2502,7 +2501,7 @@ function createCodexManager() {
|
|
|
2502
2501
|
if (!config.presets) {
|
|
2503
2502
|
config.presets = [];
|
|
2504
2503
|
}
|
|
2505
|
-
const allPresets = [...
|
|
2504
|
+
const allPresets = [...toolConfig.builtinPresets, ...config.presets];
|
|
2506
2505
|
const nameExists = allPresets.some((p) => p.name === input.name);
|
|
2507
2506
|
if (nameExists) {
|
|
2508
2507
|
throw new PresetNameConflictError(input.name);
|
|
@@ -2514,12 +2513,23 @@ function createCodexManager() {
|
|
|
2514
2513
|
};
|
|
2515
2514
|
config.presets.push(preset);
|
|
2516
2515
|
saveConfig2(config);
|
|
2517
|
-
return
|
|
2516
|
+
return {
|
|
2517
|
+
...preset,
|
|
2518
|
+
isBuiltIn: false
|
|
2519
|
+
};
|
|
2518
2520
|
},
|
|
2519
2521
|
listPresets() {
|
|
2520
2522
|
const config = loadConfig2();
|
|
2521
2523
|
const userPresets = config.presets || [];
|
|
2522
|
-
|
|
2524
|
+
const builtinWithFlag = toolConfig.builtinPresets.map((p) => ({
|
|
2525
|
+
...p,
|
|
2526
|
+
isBuiltIn: true
|
|
2527
|
+
}));
|
|
2528
|
+
const userWithFlag = userPresets.map((p) => ({
|
|
2529
|
+
...p,
|
|
2530
|
+
isBuiltIn: false
|
|
2531
|
+
}));
|
|
2532
|
+
return [...builtinWithFlag, ...userWithFlag];
|
|
2523
2533
|
},
|
|
2524
2534
|
editPreset(name, updates) {
|
|
2525
2535
|
const config = loadConfig2();
|
|
@@ -2531,7 +2541,7 @@ function createCodexManager() {
|
|
|
2531
2541
|
throw new Error(`\u9884\u7F6E\u4E0D\u5B58\u5728: ${name}`);
|
|
2532
2542
|
}
|
|
2533
2543
|
if (updates.name !== void 0 && updates.name !== preset.name) {
|
|
2534
|
-
const allPresets = [...
|
|
2544
|
+
const allPresets = [...toolConfig.builtinPresets, ...config.presets];
|
|
2535
2545
|
const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
|
|
2536
2546
|
if (nameConflict) {
|
|
2537
2547
|
throw new PresetNameConflictError(updates.name);
|
|
@@ -2544,7 +2554,10 @@ function createCodexManager() {
|
|
|
2544
2554
|
if (updates.description !== void 0)
|
|
2545
2555
|
preset.description = updates.description;
|
|
2546
2556
|
saveConfig2(config);
|
|
2547
|
-
return
|
|
2557
|
+
return {
|
|
2558
|
+
...preset,
|
|
2559
|
+
isBuiltIn: false
|
|
2560
|
+
};
|
|
2548
2561
|
},
|
|
2549
2562
|
removePreset(name) {
|
|
2550
2563
|
const config = loadConfig2();
|
|
@@ -2560,201 +2573,13 @@ function createCodexManager() {
|
|
|
2560
2573
|
}
|
|
2561
2574
|
};
|
|
2562
2575
|
}
|
|
2576
|
+
function createCodexManager() {
|
|
2577
|
+
return createToolManager("codex");
|
|
2578
|
+
}
|
|
2563
2579
|
function createClaudeManager() {
|
|
2564
|
-
|
|
2565
|
-
function loadConfig2() {
|
|
2566
|
-
if (!fileExists(configPath)) {
|
|
2567
|
-
ensureDir(getCcmanDir());
|
|
2568
|
-
const initialConfig = {
|
|
2569
|
-
providers: [],
|
|
2570
|
-
presets: []
|
|
2571
|
-
// 只存储用户自定义预置
|
|
2572
|
-
};
|
|
2573
|
-
writeJSON(configPath, initialConfig);
|
|
2574
|
-
return initialConfig;
|
|
2575
|
-
}
|
|
2576
|
-
return readJSON(configPath);
|
|
2577
|
-
}
|
|
2578
|
-
function saveConfig2(config) {
|
|
2579
|
-
writeJSON(configPath, config);
|
|
2580
|
-
}
|
|
2581
|
-
return {
|
|
2582
|
-
add(input) {
|
|
2583
|
-
const config = loadConfig2();
|
|
2584
|
-
const nameExists = config.providers.some((p) => p.name === input.name);
|
|
2585
|
-
if (nameExists) {
|
|
2586
|
-
throw new ProviderNameConflictError(input.name);
|
|
2587
|
-
}
|
|
2588
|
-
const timestamp = Date.now();
|
|
2589
|
-
const provider = {
|
|
2590
|
-
id: generateId("claude"),
|
|
2591
|
-
name: input.name,
|
|
2592
|
-
baseUrl: input.baseUrl,
|
|
2593
|
-
apiKey: input.apiKey,
|
|
2594
|
-
createdAt: timestamp,
|
|
2595
|
-
lastModified: timestamp
|
|
2596
|
-
};
|
|
2597
|
-
config.providers.push(provider);
|
|
2598
|
-
saveConfig2(config);
|
|
2599
|
-
return provider;
|
|
2600
|
-
},
|
|
2601
|
-
list() {
|
|
2602
|
-
const config = loadConfig2();
|
|
2603
|
-
return config.providers;
|
|
2604
|
-
},
|
|
2605
|
-
get(id) {
|
|
2606
|
-
const config = loadConfig2();
|
|
2607
|
-
const provider = config.providers.find((p) => p.id === id);
|
|
2608
|
-
if (!provider) {
|
|
2609
|
-
throw new ProviderNotFoundError(id);
|
|
2610
|
-
}
|
|
2611
|
-
return provider;
|
|
2612
|
-
},
|
|
2613
|
-
findByName(name) {
|
|
2614
|
-
const config = loadConfig2();
|
|
2615
|
-
const lowerName = name.toLowerCase();
|
|
2616
|
-
return config.providers.find((p) => p.name.toLowerCase() === lowerName);
|
|
2617
|
-
},
|
|
2618
|
-
switch(id) {
|
|
2619
|
-
const config = loadConfig2();
|
|
2620
|
-
const provider = config.providers.find((p) => p.id === id);
|
|
2621
|
-
if (!provider) {
|
|
2622
|
-
throw new ProviderNotFoundError(id);
|
|
2623
|
-
}
|
|
2624
|
-
config.currentProviderId = id;
|
|
2625
|
-
provider.lastUsedAt = Date.now();
|
|
2626
|
-
saveConfig2(config);
|
|
2627
|
-
writeClaudeConfig(provider);
|
|
2628
|
-
},
|
|
2629
|
-
getCurrent() {
|
|
2630
|
-
const config = loadConfig2();
|
|
2631
|
-
if (!config.currentProviderId) {
|
|
2632
|
-
return null;
|
|
2633
|
-
}
|
|
2634
|
-
const provider = config.providers.find((p) => p.id === config.currentProviderId);
|
|
2635
|
-
return provider || null;
|
|
2636
|
-
},
|
|
2637
|
-
edit(id, updates) {
|
|
2638
|
-
const config = loadConfig2();
|
|
2639
|
-
const provider = config.providers.find((p) => p.id === id);
|
|
2640
|
-
if (!provider) {
|
|
2641
|
-
throw new ProviderNotFoundError(id);
|
|
2642
|
-
}
|
|
2643
|
-
if (updates.name !== void 0 && updates.name !== provider.name) {
|
|
2644
|
-
const nameConflict = config.providers.some((p) => p.id !== id && p.name === updates.name);
|
|
2645
|
-
if (nameConflict) {
|
|
2646
|
-
throw new ProviderNameConflictError(updates.name);
|
|
2647
|
-
}
|
|
2648
|
-
}
|
|
2649
|
-
if (updates.name !== void 0)
|
|
2650
|
-
provider.name = updates.name;
|
|
2651
|
-
if (updates.baseUrl !== void 0)
|
|
2652
|
-
provider.baseUrl = updates.baseUrl;
|
|
2653
|
-
if (updates.apiKey !== void 0)
|
|
2654
|
-
provider.apiKey = updates.apiKey;
|
|
2655
|
-
provider.lastModified = Date.now();
|
|
2656
|
-
saveConfig2(config);
|
|
2657
|
-
if (config.currentProviderId === id) {
|
|
2658
|
-
writeClaudeConfig(provider);
|
|
2659
|
-
}
|
|
2660
|
-
return provider;
|
|
2661
|
-
},
|
|
2662
|
-
remove(id) {
|
|
2663
|
-
const config = loadConfig2();
|
|
2664
|
-
const index = config.providers.findIndex((p) => p.id === id);
|
|
2665
|
-
if (index === -1) {
|
|
2666
|
-
throw new ProviderNotFoundError(id);
|
|
2667
|
-
}
|
|
2668
|
-
if (config.currentProviderId === id) {
|
|
2669
|
-
config.currentProviderId = void 0;
|
|
2670
|
-
}
|
|
2671
|
-
config.providers.splice(index, 1);
|
|
2672
|
-
saveConfig2(config);
|
|
2673
|
-
},
|
|
2674
|
-
clone(sourceId, newName) {
|
|
2675
|
-
const source = this.get(sourceId);
|
|
2676
|
-
const config = loadConfig2();
|
|
2677
|
-
const nameExists = config.providers.some((p) => p.name === newName);
|
|
2678
|
-
if (nameExists) {
|
|
2679
|
-
throw new ProviderNameConflictError(newName);
|
|
2680
|
-
}
|
|
2681
|
-
const timestamp = Date.now();
|
|
2682
|
-
const newProvider = {
|
|
2683
|
-
...source,
|
|
2684
|
-
id: generateId("claude"),
|
|
2685
|
-
name: newName,
|
|
2686
|
-
createdAt: timestamp,
|
|
2687
|
-
lastModified: timestamp,
|
|
2688
|
-
lastUsedAt: void 0
|
|
2689
|
-
};
|
|
2690
|
-
config.providers.push(newProvider);
|
|
2691
|
-
saveConfig2(config);
|
|
2692
|
-
return newProvider;
|
|
2693
|
-
},
|
|
2694
|
-
addPreset(input) {
|
|
2695
|
-
const config = loadConfig2();
|
|
2696
|
-
if (!config.presets) {
|
|
2697
|
-
config.presets = [];
|
|
2698
|
-
}
|
|
2699
|
-
const allPresets = [...CC_PRESETS, ...config.presets];
|
|
2700
|
-
const nameExists = allPresets.some((p) => p.name === input.name);
|
|
2701
|
-
if (nameExists) {
|
|
2702
|
-
throw new PresetNameConflictError(input.name);
|
|
2703
|
-
}
|
|
2704
|
-
const preset = {
|
|
2705
|
-
name: input.name,
|
|
2706
|
-
baseUrl: input.baseUrl,
|
|
2707
|
-
description: input.description
|
|
2708
|
-
};
|
|
2709
|
-
config.presets.push(preset);
|
|
2710
|
-
saveConfig2(config);
|
|
2711
|
-
return preset;
|
|
2712
|
-
},
|
|
2713
|
-
listPresets() {
|
|
2714
|
-
const config = loadConfig2();
|
|
2715
|
-
const userPresets = config.presets || [];
|
|
2716
|
-
return [...CC_PRESETS, ...userPresets];
|
|
2717
|
-
},
|
|
2718
|
-
editPreset(name, updates) {
|
|
2719
|
-
const config = loadConfig2();
|
|
2720
|
-
if (!config.presets) {
|
|
2721
|
-
config.presets = [];
|
|
2722
|
-
}
|
|
2723
|
-
const preset = config.presets.find((p) => p.name === name);
|
|
2724
|
-
if (!preset) {
|
|
2725
|
-
throw new Error(`\u9884\u7F6E\u4E0D\u5B58\u5728: ${name}`);
|
|
2726
|
-
}
|
|
2727
|
-
if (updates.name !== void 0 && updates.name !== preset.name) {
|
|
2728
|
-
const allPresets = [...CC_PRESETS, ...config.presets];
|
|
2729
|
-
const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
|
|
2730
|
-
if (nameConflict) {
|
|
2731
|
-
throw new PresetNameConflictError(updates.name);
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
if (updates.name !== void 0)
|
|
2735
|
-
preset.name = updates.name;
|
|
2736
|
-
if (updates.baseUrl !== void 0)
|
|
2737
|
-
preset.baseUrl = updates.baseUrl;
|
|
2738
|
-
if (updates.description !== void 0)
|
|
2739
|
-
preset.description = updates.description;
|
|
2740
|
-
saveConfig2(config);
|
|
2741
|
-
return preset;
|
|
2742
|
-
},
|
|
2743
|
-
removePreset(name) {
|
|
2744
|
-
const config = loadConfig2();
|
|
2745
|
-
if (!config.presets) {
|
|
2746
|
-
return;
|
|
2747
|
-
}
|
|
2748
|
-
const index = config.presets.findIndex((p) => p.name === name);
|
|
2749
|
-
if (index === -1) {
|
|
2750
|
-
throw new Error(`Preset not found: ${name}`);
|
|
2751
|
-
}
|
|
2752
|
-
config.presets.splice(index, 1);
|
|
2753
|
-
saveConfig2(config);
|
|
2754
|
-
}
|
|
2755
|
-
};
|
|
2580
|
+
return createToolManager("claude");
|
|
2756
2581
|
}
|
|
2757
|
-
var path3, ProviderNotFoundError, ProviderNameConflictError, PresetNameConflictError;
|
|
2582
|
+
var path3, ProviderNotFoundError, ProviderNameConflictError, PresetNameConflictError, TOOL_CONFIGS;
|
|
2758
2583
|
var init_tool_manager = __esm({
|
|
2759
2584
|
"../core/dist/tool-manager.js"() {
|
|
2760
2585
|
"use strict";
|
|
@@ -2783,6 +2608,18 @@ var init_tool_manager = __esm({
|
|
|
2783
2608
|
this.name = "PresetNameConflictError";
|
|
2784
2609
|
}
|
|
2785
2610
|
};
|
|
2611
|
+
TOOL_CONFIGS = {
|
|
2612
|
+
codex: {
|
|
2613
|
+
configPath: path3.join(getCcmanDir(), "codex.json"),
|
|
2614
|
+
builtinPresets: CODEX_PRESETS,
|
|
2615
|
+
writer: writeCodexConfig
|
|
2616
|
+
},
|
|
2617
|
+
claude: {
|
|
2618
|
+
configPath: path3.join(getCcmanDir(), "claude.json"),
|
|
2619
|
+
builtinPresets: CC_PRESETS,
|
|
2620
|
+
writer: writeClaudeConfig
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2786
2623
|
}
|
|
2787
2624
|
});
|
|
2788
2625
|
|