@wengine-ai/claude-code-router-shared 2.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/constants.d.ts +14 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +14 -0
- package/dist/preset/export.d.ts +39 -0
- package/dist/preset/install.d.ts +71 -0
- package/dist/preset/marketplace.d.ts +16 -0
- package/dist/preset/merge.d.ts +21 -0
- package/dist/preset/readPreset.d.ts +10 -0
- package/dist/preset/schema.d.ts +90 -0
- package/dist/preset/sensitiveFields.d.ts +24 -0
- package/dist/preset/types.d.ts +167 -0
- package/package.json +30 -0
- package/src/constants.ts +32 -0
- package/src/index.ts +12 -0
- package/src/preset/export.ts +115 -0
- package/src/preset/install.ts +416 -0
- package/src/preset/marketplace.ts +56 -0
- package/src/preset/merge.ts +229 -0
- package/src/preset/readPreset.ts +30 -0
- package/src/preset/schema.ts +720 -0
- package/src/preset/sensitiveFields.ts +227 -0
- package/src/preset/types.ts +267 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for preset functionality
|
|
3
|
+
*/
|
|
4
|
+
export interface UserInputValues {
|
|
5
|
+
[inputId: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export declare enum InputType {
|
|
8
|
+
PASSWORD = "password",// Password input (hidden)
|
|
9
|
+
INPUT = "input",// Text input
|
|
10
|
+
SELECT = "select",// Single selection
|
|
11
|
+
MULTISELECT = "multiselect",// Multiple selection
|
|
12
|
+
CONFIRM = "confirm",// Confirmation checkbox
|
|
13
|
+
EDITOR = "editor",// Multi-line text editor
|
|
14
|
+
NUMBER = "number"
|
|
15
|
+
}
|
|
16
|
+
export interface InputOption {
|
|
17
|
+
label: string;
|
|
18
|
+
value: string | number | boolean;
|
|
19
|
+
description?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
icon?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DynamicOptions {
|
|
24
|
+
type: 'static' | 'providers' | 'models' | 'custom';
|
|
25
|
+
options?: InputOption[];
|
|
26
|
+
providerField?: string;
|
|
27
|
+
source?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Condition {
|
|
30
|
+
field: string;
|
|
31
|
+
operator?: 'eq' | 'ne' | 'in' | 'nin' | 'gt' | 'lt' | 'gte' | 'lte' | 'exists';
|
|
32
|
+
value?: any;
|
|
33
|
+
}
|
|
34
|
+
export interface RequiredInput {
|
|
35
|
+
id: string;
|
|
36
|
+
type?: InputType;
|
|
37
|
+
label?: string;
|
|
38
|
+
prompt?: string;
|
|
39
|
+
placeholder?: string;
|
|
40
|
+
options?: InputOption[] | DynamicOptions;
|
|
41
|
+
when?: Condition | Condition[];
|
|
42
|
+
defaultValue?: any;
|
|
43
|
+
required?: boolean;
|
|
44
|
+
validator?: RegExp | string | ((value: any) => boolean | string);
|
|
45
|
+
min?: number;
|
|
46
|
+
max?: number;
|
|
47
|
+
rows?: number;
|
|
48
|
+
dependsOn?: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface ProviderConfig {
|
|
51
|
+
name: string;
|
|
52
|
+
api_base_url: string;
|
|
53
|
+
api_key: string;
|
|
54
|
+
models: string[];
|
|
55
|
+
transformer?: any;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}
|
|
58
|
+
export interface RouterConfig {
|
|
59
|
+
default?: string;
|
|
60
|
+
background?: string;
|
|
61
|
+
think?: string;
|
|
62
|
+
longContext?: string;
|
|
63
|
+
longContextThreshold?: number;
|
|
64
|
+
webSearch?: string;
|
|
65
|
+
image?: string;
|
|
66
|
+
models?: Record<string, string>;
|
|
67
|
+
[key: string]: string | number | Record<string, string> | undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface TransformerConfig {
|
|
70
|
+
path?: string;
|
|
71
|
+
use: Array<string | [string, any]>;
|
|
72
|
+
options?: any;
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
}
|
|
75
|
+
export interface PresetMetadata {
|
|
76
|
+
name: string;
|
|
77
|
+
version: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
author?: string;
|
|
80
|
+
homepage?: string;
|
|
81
|
+
repository?: string;
|
|
82
|
+
license?: string;
|
|
83
|
+
keywords?: string[];
|
|
84
|
+
ccrVersion?: string;
|
|
85
|
+
source?: string;
|
|
86
|
+
sourceType?: 'local' | 'gist' | 'registry';
|
|
87
|
+
checksum?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface PresetConfigSection {
|
|
90
|
+
Providers?: ProviderConfig[];
|
|
91
|
+
Router?: RouterConfig;
|
|
92
|
+
transformers?: TransformerConfig[];
|
|
93
|
+
StatusLine?: any;
|
|
94
|
+
NON_INTERACTIVE_MODE?: boolean;
|
|
95
|
+
noServer?: boolean;
|
|
96
|
+
claudeCodeSettings?: {
|
|
97
|
+
env?: Record<string, any>;
|
|
98
|
+
statusLine?: any;
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
};
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
export interface TemplateConfig {
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
}
|
|
106
|
+
export interface ConfigMapping {
|
|
107
|
+
target: string;
|
|
108
|
+
value: string | any;
|
|
109
|
+
when?: Condition | Condition[];
|
|
110
|
+
}
|
|
111
|
+
export interface PresetFile {
|
|
112
|
+
metadata?: PresetMetadata;
|
|
113
|
+
config: PresetConfigSection;
|
|
114
|
+
secrets?: {
|
|
115
|
+
[fieldPath: string]: string;
|
|
116
|
+
};
|
|
117
|
+
schema?: RequiredInput[];
|
|
118
|
+
template?: TemplateConfig;
|
|
119
|
+
configMappings?: ConfigMapping[];
|
|
120
|
+
}
|
|
121
|
+
export interface ManifestFile extends PresetMetadata, PresetConfigSection {
|
|
122
|
+
schema?: RequiredInput[];
|
|
123
|
+
template?: TemplateConfig;
|
|
124
|
+
configMappings?: ConfigMapping[];
|
|
125
|
+
userValues?: UserInputValues;
|
|
126
|
+
}
|
|
127
|
+
export interface PresetIndexEntry {
|
|
128
|
+
id: string;
|
|
129
|
+
name: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
version: string;
|
|
132
|
+
author?: string;
|
|
133
|
+
downloads?: number;
|
|
134
|
+
stars?: number;
|
|
135
|
+
tags?: string[];
|
|
136
|
+
url: string;
|
|
137
|
+
repo?: string;
|
|
138
|
+
checksum?: string;
|
|
139
|
+
ccrVersion?: string;
|
|
140
|
+
}
|
|
141
|
+
export interface PresetRegistry {
|
|
142
|
+
version: string;
|
|
143
|
+
lastUpdated: string;
|
|
144
|
+
presets: PresetIndexEntry[];
|
|
145
|
+
}
|
|
146
|
+
export interface ValidationResult {
|
|
147
|
+
valid: boolean;
|
|
148
|
+
errors: string[];
|
|
149
|
+
warnings: string[];
|
|
150
|
+
}
|
|
151
|
+
export declare enum MergeStrategy {
|
|
152
|
+
ASK = "ask",// Interactive prompt
|
|
153
|
+
OVERWRITE = "overwrite",// Overwrite existing
|
|
154
|
+
MERGE = "merge",// Intelligent merge
|
|
155
|
+
SKIP = "skip"
|
|
156
|
+
}
|
|
157
|
+
export interface SanitizeResult {
|
|
158
|
+
sanitizedConfig: any;
|
|
159
|
+
sanitizedCount: number;
|
|
160
|
+
}
|
|
161
|
+
export interface PresetInfo {
|
|
162
|
+
name: string;
|
|
163
|
+
version?: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
author?: string;
|
|
166
|
+
config: PresetConfigSection;
|
|
167
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wengine-ai/claude-code-router-shared",
|
|
3
|
+
"version": "2.0.21",
|
|
4
|
+
"description": "Shared utilities and constants for Claude Code Router",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node ../../scripts/build-shared.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"claude",
|
|
12
|
+
"code",
|
|
13
|
+
"router",
|
|
14
|
+
"shared"
|
|
15
|
+
],
|
|
16
|
+
"author": "musistudio",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"adm-zip": "^0.5.16",
|
|
20
|
+
"archiver": "^7.0.1",
|
|
21
|
+
"json5": "^2.2.3"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/adm-zip": "^0.5.7",
|
|
25
|
+
"@types/archiver": "^7.0.0",
|
|
26
|
+
"@types/node": "^24.0.15",
|
|
27
|
+
"esbuild": "^0.25.1",
|
|
28
|
+
"typescript": "^5.8.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
}
|