ccman 3.0.19 → 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.
Files changed (2) hide show
  1. package/dist/index.js +50 -223
  2. 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.19",
42
+ version: "3.0.21",
43
43
  type: "module",
44
44
  description: "Core business logic for ccman",
45
45
  main: "./dist/index.js",
@@ -2302,14 +2302,9 @@ var init_codex2 = __esm({
2302
2302
  "../core/dist/presets/codex.js"() {
2303
2303
  "use strict";
2304
2304
  CODEX_PRESETS = [
2305
- {
2306
- name: "PackyCode",
2307
- baseUrl: "https://api.packycode.com",
2308
- description: "PackyCode API \u670D\u52A1"
2309
- },
2310
2305
  {
2311
2306
  name: "88Code",
2312
- baseUrl: "https://www.88code.org/api",
2307
+ baseUrl: "https://www.88code.org/openai/v1",
2313
2308
  description: "88Code API \u670D\u52A1"
2314
2309
  }
2315
2310
  ];
@@ -2337,11 +2332,6 @@ var init_claude2 = __esm({
2337
2332
  baseUrl: "https://api.packycode.com",
2338
2333
  description: "PackyCode API \u670D\u52A1"
2339
2334
  },
2340
- {
2341
- name: "CoordCode",
2342
- baseUrl: "https://api.coordcode.com/api",
2343
- description: "CoordCode API \u670D\u52A1"
2344
- },
2345
2335
  {
2346
2336
  name: "88Code",
2347
2337
  baseUrl: "https://www.88code.org/api",
@@ -2367,20 +2357,20 @@ var init_claude2 = __esm({
2367
2357
  });
2368
2358
 
2369
2359
  // ../core/dist/tool-manager.js
2370
- function generateId(tool) {
2371
- const timestamp = Date.now();
2372
- const random = Math.random().toString(36).substring(2, 8);
2373
- return `${tool}-${timestamp}-${random}`;
2374
- }
2375
- function createCodexManager() {
2376
- const configPath = path3.join(getCcmanDir(), "codex.json");
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
+ }
2377
2368
  function loadConfig2() {
2378
2369
  if (!fileExists(configPath)) {
2379
2370
  ensureDir(getCcmanDir());
2380
2371
  const initialConfig = {
2381
2372
  providers: [],
2382
2373
  presets: []
2383
- // 只存储用户自定义预置
2384
2374
  };
2385
2375
  writeJSON(configPath, initialConfig);
2386
2376
  return initialConfig;
@@ -2399,12 +2389,11 @@ function createCodexManager() {
2399
2389
  }
2400
2390
  const timestamp = Date.now();
2401
2391
  const provider = {
2402
- id: generateId("codex"),
2392
+ id: generateId(),
2403
2393
  name: input.name,
2404
2394
  baseUrl: input.baseUrl,
2405
2395
  apiKey: input.apiKey,
2406
2396
  model: input.model,
2407
- // 保存 model 字段
2408
2397
  createdAt: timestamp,
2409
2398
  lastModified: timestamp
2410
2399
  };
@@ -2438,7 +2427,7 @@ function createCodexManager() {
2438
2427
  config.currentProviderId = id;
2439
2428
  provider.lastUsedAt = Date.now();
2440
2429
  saveConfig2(config);
2441
- writeCodexConfig(provider);
2430
+ toolConfig.writer(provider);
2442
2431
  },
2443
2432
  getCurrent() {
2444
2433
  const config = loadConfig2();
@@ -2471,7 +2460,7 @@ function createCodexManager() {
2471
2460
  provider.lastModified = Date.now();
2472
2461
  saveConfig2(config);
2473
2462
  if (config.currentProviderId === id) {
2474
- writeCodexConfig(provider);
2463
+ toolConfig.writer(provider);
2475
2464
  }
2476
2465
  return provider;
2477
2466
  },
@@ -2497,7 +2486,7 @@ function createCodexManager() {
2497
2486
  const timestamp = Date.now();
2498
2487
  const newProvider = {
2499
2488
  ...source,
2500
- id: generateId("codex"),
2489
+ id: generateId(),
2501
2490
  name: newName,
2502
2491
  createdAt: timestamp,
2503
2492
  lastModified: timestamp,
@@ -2512,7 +2501,7 @@ function createCodexManager() {
2512
2501
  if (!config.presets) {
2513
2502
  config.presets = [];
2514
2503
  }
2515
- const allPresets = [...CODEX_PRESETS, ...config.presets];
2504
+ const allPresets = [...toolConfig.builtinPresets, ...config.presets];
2516
2505
  const nameExists = allPresets.some((p) => p.name === input.name);
2517
2506
  if (nameExists) {
2518
2507
  throw new PresetNameConflictError(input.name);
@@ -2524,12 +2513,23 @@ function createCodexManager() {
2524
2513
  };
2525
2514
  config.presets.push(preset);
2526
2515
  saveConfig2(config);
2527
- return preset;
2516
+ return {
2517
+ ...preset,
2518
+ isBuiltIn: false
2519
+ };
2528
2520
  },
2529
2521
  listPresets() {
2530
2522
  const config = loadConfig2();
2531
2523
  const userPresets = config.presets || [];
2532
- return [...CODEX_PRESETS, ...userPresets];
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];
2533
2533
  },
2534
2534
  editPreset(name, updates) {
2535
2535
  const config = loadConfig2();
@@ -2541,7 +2541,7 @@ function createCodexManager() {
2541
2541
  throw new Error(`\u9884\u7F6E\u4E0D\u5B58\u5728: ${name}`);
2542
2542
  }
2543
2543
  if (updates.name !== void 0 && updates.name !== preset.name) {
2544
- const allPresets = [...CODEX_PRESETS, ...config.presets];
2544
+ const allPresets = [...toolConfig.builtinPresets, ...config.presets];
2545
2545
  const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
2546
2546
  if (nameConflict) {
2547
2547
  throw new PresetNameConflictError(updates.name);
@@ -2554,7 +2554,10 @@ function createCodexManager() {
2554
2554
  if (updates.description !== void 0)
2555
2555
  preset.description = updates.description;
2556
2556
  saveConfig2(config);
2557
- return preset;
2557
+ return {
2558
+ ...preset,
2559
+ isBuiltIn: false
2560
+ };
2558
2561
  },
2559
2562
  removePreset(name) {
2560
2563
  const config = loadConfig2();
@@ -2570,201 +2573,13 @@ function createCodexManager() {
2570
2573
  }
2571
2574
  };
2572
2575
  }
2576
+ function createCodexManager() {
2577
+ return createToolManager("codex");
2578
+ }
2573
2579
  function createClaudeManager() {
2574
- const configPath = path3.join(getCcmanDir(), "claude.json");
2575
- function loadConfig2() {
2576
- if (!fileExists(configPath)) {
2577
- ensureDir(getCcmanDir());
2578
- const initialConfig = {
2579
- providers: [],
2580
- presets: []
2581
- // 只存储用户自定义预置
2582
- };
2583
- writeJSON(configPath, initialConfig);
2584
- return initialConfig;
2585
- }
2586
- return readJSON(configPath);
2587
- }
2588
- function saveConfig2(config) {
2589
- writeJSON(configPath, config);
2590
- }
2591
- return {
2592
- add(input) {
2593
- const config = loadConfig2();
2594
- const nameExists = config.providers.some((p) => p.name === input.name);
2595
- if (nameExists) {
2596
- throw new ProviderNameConflictError(input.name);
2597
- }
2598
- const timestamp = Date.now();
2599
- const provider = {
2600
- id: generateId("claude"),
2601
- name: input.name,
2602
- baseUrl: input.baseUrl,
2603
- apiKey: input.apiKey,
2604
- createdAt: timestamp,
2605
- lastModified: timestamp
2606
- };
2607
- config.providers.push(provider);
2608
- saveConfig2(config);
2609
- return provider;
2610
- },
2611
- list() {
2612
- const config = loadConfig2();
2613
- return config.providers;
2614
- },
2615
- get(id) {
2616
- const config = loadConfig2();
2617
- const provider = config.providers.find((p) => p.id === id);
2618
- if (!provider) {
2619
- throw new ProviderNotFoundError(id);
2620
- }
2621
- return provider;
2622
- },
2623
- findByName(name) {
2624
- const config = loadConfig2();
2625
- const lowerName = name.toLowerCase();
2626
- return config.providers.find((p) => p.name.toLowerCase() === lowerName);
2627
- },
2628
- switch(id) {
2629
- const config = loadConfig2();
2630
- const provider = config.providers.find((p) => p.id === id);
2631
- if (!provider) {
2632
- throw new ProviderNotFoundError(id);
2633
- }
2634
- config.currentProviderId = id;
2635
- provider.lastUsedAt = Date.now();
2636
- saveConfig2(config);
2637
- writeClaudeConfig(provider);
2638
- },
2639
- getCurrent() {
2640
- const config = loadConfig2();
2641
- if (!config.currentProviderId) {
2642
- return null;
2643
- }
2644
- const provider = config.providers.find((p) => p.id === config.currentProviderId);
2645
- return provider || null;
2646
- },
2647
- edit(id, updates) {
2648
- const config = loadConfig2();
2649
- const provider = config.providers.find((p) => p.id === id);
2650
- if (!provider) {
2651
- throw new ProviderNotFoundError(id);
2652
- }
2653
- if (updates.name !== void 0 && updates.name !== provider.name) {
2654
- const nameConflict = config.providers.some((p) => p.id !== id && p.name === updates.name);
2655
- if (nameConflict) {
2656
- throw new ProviderNameConflictError(updates.name);
2657
- }
2658
- }
2659
- if (updates.name !== void 0)
2660
- provider.name = updates.name;
2661
- if (updates.baseUrl !== void 0)
2662
- provider.baseUrl = updates.baseUrl;
2663
- if (updates.apiKey !== void 0)
2664
- provider.apiKey = updates.apiKey;
2665
- provider.lastModified = Date.now();
2666
- saveConfig2(config);
2667
- if (config.currentProviderId === id) {
2668
- writeClaudeConfig(provider);
2669
- }
2670
- return provider;
2671
- },
2672
- remove(id) {
2673
- const config = loadConfig2();
2674
- const index = config.providers.findIndex((p) => p.id === id);
2675
- if (index === -1) {
2676
- throw new ProviderNotFoundError(id);
2677
- }
2678
- if (config.currentProviderId === id) {
2679
- config.currentProviderId = void 0;
2680
- }
2681
- config.providers.splice(index, 1);
2682
- saveConfig2(config);
2683
- },
2684
- clone(sourceId, newName) {
2685
- const source = this.get(sourceId);
2686
- const config = loadConfig2();
2687
- const nameExists = config.providers.some((p) => p.name === newName);
2688
- if (nameExists) {
2689
- throw new ProviderNameConflictError(newName);
2690
- }
2691
- const timestamp = Date.now();
2692
- const newProvider = {
2693
- ...source,
2694
- id: generateId("claude"),
2695
- name: newName,
2696
- createdAt: timestamp,
2697
- lastModified: timestamp,
2698
- lastUsedAt: void 0
2699
- };
2700
- config.providers.push(newProvider);
2701
- saveConfig2(config);
2702
- return newProvider;
2703
- },
2704
- addPreset(input) {
2705
- const config = loadConfig2();
2706
- if (!config.presets) {
2707
- config.presets = [];
2708
- }
2709
- const allPresets = [...CC_PRESETS, ...config.presets];
2710
- const nameExists = allPresets.some((p) => p.name === input.name);
2711
- if (nameExists) {
2712
- throw new PresetNameConflictError(input.name);
2713
- }
2714
- const preset = {
2715
- name: input.name,
2716
- baseUrl: input.baseUrl,
2717
- description: input.description
2718
- };
2719
- config.presets.push(preset);
2720
- saveConfig2(config);
2721
- return preset;
2722
- },
2723
- listPresets() {
2724
- const config = loadConfig2();
2725
- const userPresets = config.presets || [];
2726
- return [...CC_PRESETS, ...userPresets];
2727
- },
2728
- editPreset(name, updates) {
2729
- const config = loadConfig2();
2730
- if (!config.presets) {
2731
- config.presets = [];
2732
- }
2733
- const preset = config.presets.find((p) => p.name === name);
2734
- if (!preset) {
2735
- throw new Error(`\u9884\u7F6E\u4E0D\u5B58\u5728: ${name}`);
2736
- }
2737
- if (updates.name !== void 0 && updates.name !== preset.name) {
2738
- const allPresets = [...CC_PRESETS, ...config.presets];
2739
- const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
2740
- if (nameConflict) {
2741
- throw new PresetNameConflictError(updates.name);
2742
- }
2743
- }
2744
- if (updates.name !== void 0)
2745
- preset.name = updates.name;
2746
- if (updates.baseUrl !== void 0)
2747
- preset.baseUrl = updates.baseUrl;
2748
- if (updates.description !== void 0)
2749
- preset.description = updates.description;
2750
- saveConfig2(config);
2751
- return preset;
2752
- },
2753
- removePreset(name) {
2754
- const config = loadConfig2();
2755
- if (!config.presets) {
2756
- return;
2757
- }
2758
- const index = config.presets.findIndex((p) => p.name === name);
2759
- if (index === -1) {
2760
- throw new Error(`Preset not found: ${name}`);
2761
- }
2762
- config.presets.splice(index, 1);
2763
- saveConfig2(config);
2764
- }
2765
- };
2580
+ return createToolManager("claude");
2766
2581
  }
2767
- var path3, ProviderNotFoundError, ProviderNameConflictError, PresetNameConflictError;
2582
+ var path3, ProviderNotFoundError, ProviderNameConflictError, PresetNameConflictError, TOOL_CONFIGS;
2768
2583
  var init_tool_manager = __esm({
2769
2584
  "../core/dist/tool-manager.js"() {
2770
2585
  "use strict";
@@ -2793,6 +2608,18 @@ var init_tool_manager = __esm({
2793
2608
  this.name = "PresetNameConflictError";
2794
2609
  }
2795
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
+ };
2796
2623
  }
2797
2624
  });
2798
2625
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccman",
3
- "version": "3.0.19",
3
+ "version": "3.0.21",
4
4
  "description": "Manage Codex and Claude Code API service provider configurations",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {