@wengine-ai/claude-code-router-shared 2.0.41 → 2.3.236
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/LICENSE +21 -0
- package/dist/__tests__/auto-compact-state.test.d.ts +1 -0
- package/dist/__tests__/pi-models.test.d.ts +1 -0
- package/dist/__tests__/setup.d.ts +1 -0
- package/dist/client-integrations.d.ts +214 -0
- package/dist/constants.d.ts +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -14
- package/dist/projectConfig.d.ts +111 -0
- package/package.json +9 -3
- package/src/constants.ts +0 -32
- package/src/index.ts +0 -12
- package/src/preset/export.ts +0 -115
- package/src/preset/install.ts +0 -416
- package/src/preset/marketplace.ts +0 -56
- package/src/preset/merge.ts +0 -229
- package/src/preset/readPreset.ts +0 -30
- package/src/preset/schema.ts +0 -720
- package/src/preset/sensitiveFields.ts +0 -227
- package/src/preset/types.ts +0 -267
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type ClientId } from "./client-integrations";
|
|
2
|
+
export interface ProjectConfig {
|
|
3
|
+
projectPath?: string;
|
|
4
|
+
Router?: Record<string, any>;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface ProjectConfigEntry {
|
|
8
|
+
id: string;
|
|
9
|
+
path: string;
|
|
10
|
+
configPath: string;
|
|
11
|
+
Router: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export interface ProjectTakeoverSyncResult {
|
|
14
|
+
updated: number;
|
|
15
|
+
skipped: number;
|
|
16
|
+
failed: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
path: string;
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read the project-level config for a given project path.
|
|
24
|
+
* Returns null if no project-level config has been created yet.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readProjectConfig(projectPath: string): Promise<ProjectConfig | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Write the project-level config for a given project path.
|
|
29
|
+
* Always stores `projectPath` alongside `Router` so the project can be
|
|
30
|
+
* identified later (e.g. when listing all configured projects).
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeProjectConfig(projectPath: string, config: ProjectConfig): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Delete the project-level config directory for a given project path.
|
|
35
|
+
*/
|
|
36
|
+
export declare function deleteProjectConfig(projectPath: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* List all projects that have a project-level config under ~/.claude-code-router/.
|
|
39
|
+
*/
|
|
40
|
+
export declare function listProjectConfigs(): Promise<ProjectConfigEntry[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Find a project config entry by its id (the directory name under HOME_DIR).
|
|
43
|
+
*/
|
|
44
|
+
export declare function readProjectConfigById(id: string): Promise<ProjectConfigEntry | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Path to a project's `.claude/settings.local.json` file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getClaudeSettingsLocalPath(projectPath: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Read a project's `.claude/settings.local.json`, returning `{}` if missing or invalid.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readClaudeSettingsLocal(projectPath: string): Promise<Record<string, any>>;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the project's `.claude/settings.local.json` currently routes
|
|
55
|
+
* Claude Code traffic through ccr.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getCcrTakeoverStatus(projectPath: string): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Enable or disable "ccr takeover" for a project's `.claude/settings.local.json`.
|
|
60
|
+
*
|
|
61
|
+
* When enabling, this restores a previous takeover backup if one exists
|
|
62
|
+
* (preserving any customizations made while ccr was managing the project,
|
|
63
|
+
* such as `permissions`/`hooks`), then re-applies the ccr-managed fields
|
|
64
|
+
* (`ANTHROPIC_BASE_URL`/`ANTHROPIC_AUTH_TOKEN`, model family routing env vars,
|
|
65
|
+
* auto-compact settings, and the status line command) from the *current*
|
|
66
|
+
* global config, so model routing stays in sync even if the global config
|
|
67
|
+
* changed since the backup was taken.
|
|
68
|
+
*
|
|
69
|
+
* When disabling, the ccr-managed fields are removed first, then the remaining
|
|
70
|
+
* (user-customized) settings are backed up, so re-enabling takeover later
|
|
71
|
+
* restores those personalizations instead of losing them. Ccr-managed fields
|
|
72
|
+
* are not backed up — they are re-applied from the current global config on the
|
|
73
|
+
* next enable.
|
|
74
|
+
*/
|
|
75
|
+
export declare function setCcrTakeover(projectPath: string, enabled: boolean, config: Record<string, any>): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Refresh ccr-managed fields in a project's active `.claude/settings.local.json`
|
|
78
|
+
* from the current global config. Returns false when the project is not
|
|
79
|
+
* currently under ccr takeover.
|
|
80
|
+
*/
|
|
81
|
+
export declare function refreshCcrProjectTakeover(projectPath: string, config: Record<string, any>): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* List which project-takeover-capable clients (Claude Code, pi, qwen-code,
|
|
84
|
+
* opencode) currently route a given project through ccr. Derived directly from each
|
|
85
|
+
* client's project-scoped config file, so it needs no separately stored flag
|
|
86
|
+
* and is always consistent with the real on-disk state.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getProjectTakeoverClients(projectPath: string): Promise<ClientId[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Apply ccr takeover for exactly the given set of clients on a project:
|
|
91
|
+
* enable each listed client and disable every other supported one. An empty
|
|
92
|
+
* list removes takeover for all of them. Returns the resulting active set.
|
|
93
|
+
*/
|
|
94
|
+
export declare function setProjectTakeover(projectPath: string, clients: ClientId[], config: Record<string, any>): Promise<ClientId[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Refresh ccr-managed fields for whichever clients currently take over a
|
|
97
|
+
* project, pulling fresh values (proxy URL/token, model aliases, context
|
|
98
|
+
* window) from the current global config. Returns true if any client was
|
|
99
|
+
* refreshed.
|
|
100
|
+
*/
|
|
101
|
+
export declare function refreshProjectTakeovers(projectPath: string, config: Record<string, any>): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Refresh `.claude/settings.local.json` for projects that are both:
|
|
104
|
+
* - following the global Router (`Router: {}` in their project config), and
|
|
105
|
+
* - currently under ccr takeover.
|
|
106
|
+
*
|
|
107
|
+
* This keeps client-side managed fields (model aliases, auto-compact window,
|
|
108
|
+
* statusline, proxy URL/token) aligned after the global config changes without
|
|
109
|
+
* touching projects that have local Router overrides or disabled takeover.
|
|
110
|
+
*/
|
|
111
|
+
export declare function syncGlobalProjectTakeovers(config: Record<string, any>): Promise<ProjectTakeoverSyncResult>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wengine-ai/claude-code-router-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.236",
|
|
4
4
|
"description": "Shared utilities and constants for Claude Code Router",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "node ../../scripts/build-shared.js"
|
|
8
|
+
"build": "node ../../scripts/build-shared.js",
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"test:watch": "vitest"
|
|
9
11
|
},
|
|
10
12
|
"keywords": [
|
|
11
13
|
"claude",
|
|
@@ -15,6 +17,9 @@
|
|
|
15
17
|
],
|
|
16
18
|
"author": "musistudio",
|
|
17
19
|
"license": "MIT",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
18
23
|
"dependencies": {
|
|
19
24
|
"adm-zip": "^0.5.16",
|
|
20
25
|
"archiver": "^7.0.1",
|
|
@@ -25,6 +30,7 @@
|
|
|
25
30
|
"@types/archiver": "^7.0.0",
|
|
26
31
|
"@types/node": "^24.0.15",
|
|
27
32
|
"esbuild": "^0.25.1",
|
|
28
|
-
"typescript": "^5.8.2"
|
|
33
|
+
"typescript": "^5.8.2",
|
|
34
|
+
"vitest": "^4.1.9"
|
|
29
35
|
}
|
|
30
36
|
}
|
package/src/constants.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
|
|
4
|
-
export const HOME_DIR = path.join(os.homedir(), ".claude-code-router");
|
|
5
|
-
|
|
6
|
-
export const CONFIG_FILE = path.join(HOME_DIR, "config.json");
|
|
7
|
-
|
|
8
|
-
export const PLUGINS_DIR = path.join(HOME_DIR, "plugins");
|
|
9
|
-
|
|
10
|
-
export const PRESETS_DIR = path.join(HOME_DIR, "presets");
|
|
11
|
-
|
|
12
|
-
export const PID_FILE = path.join(HOME_DIR, '.claude-code-router.pid');
|
|
13
|
-
|
|
14
|
-
export const REFERENCE_COUNT_FILE = path.join(os.tmpdir(), "claude-code-reference-count.txt");
|
|
15
|
-
|
|
16
|
-
// Claude projects directory
|
|
17
|
-
export const CLAUDE_PROJECTS_DIR = path.join(os.homedir(), ".claude", "projects");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export interface DefaultConfig {
|
|
21
|
-
LOG: boolean;
|
|
22
|
-
OPENAI_API_KEY: string;
|
|
23
|
-
OPENAI_BASE_URL: string;
|
|
24
|
-
OPENAI_MODEL: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const DEFAULT_CONFIG: DefaultConfig = {
|
|
28
|
-
LOG: false,
|
|
29
|
-
OPENAI_API_KEY: "",
|
|
30
|
-
OPENAI_BASE_URL: "",
|
|
31
|
-
OPENAI_MODEL: "",
|
|
32
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
|
|
3
|
-
// Export preset-related functionality
|
|
4
|
-
export * from './preset/types';
|
|
5
|
-
export * from './preset/sensitiveFields';
|
|
6
|
-
export * from './preset/merge';
|
|
7
|
-
export * from './preset/install';
|
|
8
|
-
export * from './preset/export';
|
|
9
|
-
export * from './preset/readPreset';
|
|
10
|
-
export * from './preset/schema';
|
|
11
|
-
export * from './preset/marketplace';
|
|
12
|
-
|
package/src/preset/export.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Preset export core functionality
|
|
3
|
-
* Note: This module does not contain CLI interaction logic, interaction logic is provided by the caller
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as fs from 'fs/promises';
|
|
7
|
-
import * as path from 'path';
|
|
8
|
-
import { sanitizeConfig } from './sensitiveFields';
|
|
9
|
-
import { PresetMetadata, ManifestFile } from './types';
|
|
10
|
-
import { HOME_DIR } from '../constants';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Export options
|
|
14
|
-
*/
|
|
15
|
-
export interface ExportOptions {
|
|
16
|
-
includeSensitive?: boolean;
|
|
17
|
-
description?: string;
|
|
18
|
-
author?: string;
|
|
19
|
-
tags?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Export result
|
|
24
|
-
*/
|
|
25
|
-
export interface ExportResult {
|
|
26
|
-
presetDir: string;
|
|
27
|
-
sanitizedConfig: any;
|
|
28
|
-
metadata: PresetMetadata;
|
|
29
|
-
sanitizedCount: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create manifest object
|
|
34
|
-
* @param presetName Preset name
|
|
35
|
-
* @param config Configuration object
|
|
36
|
-
* @param sanitizedConfig Sanitized configuration
|
|
37
|
-
* @param options Export options
|
|
38
|
-
*/
|
|
39
|
-
export function createManifest(
|
|
40
|
-
presetName: string,
|
|
41
|
-
config: any,
|
|
42
|
-
sanitizedConfig: any,
|
|
43
|
-
options: ExportOptions
|
|
44
|
-
): ManifestFile {
|
|
45
|
-
const metadata: PresetMetadata = {
|
|
46
|
-
name: presetName,
|
|
47
|
-
version: '1.0.0',
|
|
48
|
-
description: options.description,
|
|
49
|
-
author: options.author,
|
|
50
|
-
keywords: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
...metadata,
|
|
55
|
-
...sanitizedConfig,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Export preset configuration
|
|
61
|
-
* @param presetName Preset name
|
|
62
|
-
* @param config Current configuration
|
|
63
|
-
* @param options Export options
|
|
64
|
-
* @returns Export result
|
|
65
|
-
*/
|
|
66
|
-
export async function exportPreset(
|
|
67
|
-
presetName: string,
|
|
68
|
-
config: any,
|
|
69
|
-
options: ExportOptions = {}
|
|
70
|
-
): Promise<ExportResult> {
|
|
71
|
-
// 1. Collect metadata
|
|
72
|
-
const metadata: PresetMetadata = {
|
|
73
|
-
name: presetName,
|
|
74
|
-
version: '1.0.0',
|
|
75
|
-
description: options.description,
|
|
76
|
-
author: options.author,
|
|
77
|
-
keywords: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// 2. Sanitize configuration
|
|
81
|
-
const { sanitizedConfig, sanitizedCount } = await sanitizeConfig(config);
|
|
82
|
-
|
|
83
|
-
// 3. Generate manifest.json (flattened structure)
|
|
84
|
-
const manifest: ManifestFile = {
|
|
85
|
-
...metadata,
|
|
86
|
-
...sanitizedConfig,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// 4. Create preset directory
|
|
90
|
-
const presetDir = path.join(HOME_DIR, 'presets', presetName);
|
|
91
|
-
|
|
92
|
-
// Check if preset directory already exists
|
|
93
|
-
try {
|
|
94
|
-
await fs.access(presetDir);
|
|
95
|
-
throw new Error(`Preset directory already exists: ${presetName}`);
|
|
96
|
-
} catch (error: any) {
|
|
97
|
-
if (error.code !== 'ENOENT') {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Create preset directory
|
|
103
|
-
await fs.mkdir(presetDir, { recursive: true });
|
|
104
|
-
|
|
105
|
-
// 5. Write manifest.json to preset directory
|
|
106
|
-
const manifestPath = path.join(presetDir, 'manifest.json');
|
|
107
|
-
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8');
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
presetDir,
|
|
111
|
-
sanitizedConfig,
|
|
112
|
-
metadata,
|
|
113
|
-
sanitizedCount,
|
|
114
|
-
};
|
|
115
|
-
}
|