@tkpdx01/ccc 1.2.5 → 1.2.7

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/src/utils.js CHANGED
@@ -1,82 +1,67 @@
1
- // 从文本中提取 URL 和 token
2
- export function extractFromText(text) {
3
- // 提取 URL
4
- const urlRegex = /https?:\/\/[^\s"'<>]+/gi;
5
- const urls = text.match(urlRegex) || [];
6
-
7
- // 提取 sk token
8
- const tokenRegex = /sk-[a-zA-Z0-9_-]+/g;
9
- const tokens = text.match(tokenRegex) || [];
10
-
11
- return { urls, tokens };
12
- }
13
-
14
- // 从 URL 获取域名作为名称(去掉协议和www子域名)
15
- export function getDomainName(url) {
16
- try {
17
- const urlObj = new URL(url);
18
- // 获取完整域名
19
- let hostname = urlObj.hostname;
20
- // 移除 www. 前缀
21
- hostname = hostname.replace(/^www\./, '');
22
- return hostname;
23
- } catch {
24
- return null;
25
- }
26
- }
27
-
28
- // 生成安全的 profile 名称
29
- export function sanitizeProfileName(name) {
30
- return name
31
- .replace(/[<>:"/\\|?*]/g, '_') // 替换 Windows 非法字符
32
- .replace(/\s+/g, '_') // 替换空格
33
- .replace(/_+/g, '_') // 合并多个下划线
34
- .replace(/^_|_$/g, '') // 去除首尾下划线
35
- .substring(0, 50); // 限制长度
36
- }
37
-
38
- // 将导入的配置转换为 Claude Code settings 格式
39
- export function convertToClaudeSettings(provider, template) {
40
- const baseSettings = template || {};
41
- const config = provider.settingsConfig || {};
42
-
43
- // env 中提取 API 信息
44
- const env = config.env || {};
45
- const apiKey = env.ANTHROPIC_AUTH_TOKEN || env.ANTHROPIC_API_KEY || config.apiKey || '';
46
- const apiUrl = env.ANTHROPIC_BASE_URL || config.apiUrl || provider.websiteUrl || '';
47
-
48
- // 提取 model 设置
49
- const model = config.model || '';
50
-
51
- // 只保留模板设置,替换 env 中的 API 信息
52
- const settings = {
53
- ...baseSettings,
54
- env: {
55
- ...baseSettings.env,
56
- ANTHROPIC_AUTH_TOKEN: apiKey,
57
- ANTHROPIC_BASE_URL: apiUrl
58
- }
59
- };
60
-
61
- // 如果有 model 设置,添加到配置中
62
- if (model) {
63
- settings.model = model;
64
- }
65
-
66
- return settings;
67
- }
68
-
69
- // 格式化显示配置值
70
- export function formatValue(key, value) {
71
- if (key === 'apiKey' && value) {
72
- return value.substring(0, 15) + '...';
73
- }
74
- if (typeof value === 'boolean') {
75
- return value ? 'true' : 'false';
76
- }
77
- if (typeof value === 'object') {
78
- return JSON.stringify(value, null, 2).split('\n').join('\n ');
79
- }
80
- return String(value);
81
- }
82
-
1
+ // 从文本中提取 URL 和 token
2
+ export function extractFromText(text) {
3
+ // 提取 URL
4
+ const urlRegex = /https?:\/\/[^\s"'<>]+/gi;
5
+ const urls = text.match(urlRegex) || [];
6
+
7
+ // 提取 sk token
8
+ const tokenRegex = /sk-[a-zA-Z0-9_-]+/g;
9
+ const tokens = text.match(tokenRegex) || [];
10
+
11
+ return { urls, tokens };
12
+ }
13
+
14
+ // 从 URL 获取域名作为名称(去掉协议和www子域名)
15
+ export function getDomainName(url) {
16
+ try {
17
+ const urlObj = new URL(url);
18
+ // 获取完整域名
19
+ let hostname = urlObj.hostname;
20
+ // 移除 www. 前缀
21
+ hostname = hostname.replace(/^www\./, '');
22
+ return hostname;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ // 生成安全的 profile 名称
29
+ export function sanitizeProfileName(name) {
30
+ return name
31
+ .replace(/[<>:"/\\|?*]/g, '_') // 替换 Windows 非法字符
32
+ .replace(/\s+/g, '_') // 替换空格
33
+ .replace(/_+/g, '_') // 合并多个下划线
34
+ .replace(/^_|_$/g, '') // 去除首尾下划线
35
+ .substring(0, 50); // 限制长度
36
+ }
37
+
38
+ // 将导入的配置转换为影子配置格式(只包含 API 凭证)
39
+ export function convertToClaudeSettings(provider, template) {
40
+ const config = provider.settingsConfig || {};
41
+
42
+ // 从 env 中提取 API 信息
43
+ const env = config.env || {};
44
+ const apiKey = env.ANTHROPIC_AUTH_TOKEN || env.ANTHROPIC_API_KEY || config.apiKey || '';
45
+ const apiUrl = env.ANTHROPIC_BASE_URL || config.apiUrl || provider.websiteUrl || '';
46
+
47
+ // 影子配置只存储 API 凭证,不用 env 包裹
48
+ return {
49
+ ANTHROPIC_AUTH_TOKEN: apiKey,
50
+ ANTHROPIC_BASE_URL: apiUrl
51
+ };
52
+ }
53
+
54
+ // 格式化显示配置值
55
+ export function formatValue(key, value) {
56
+ if ((key === 'apiKey' || key === 'ANTHROPIC_AUTH_TOKEN') && value) {
57
+ return value.substring(0, 15) + '...';
58
+ }
59
+ if (typeof value === 'boolean') {
60
+ return value ? 'true' : 'false';
61
+ }
62
+ if (typeof value === 'object') {
63
+ return JSON.stringify(value, null, 2).split('\n').join('\n ');
64
+ }
65
+ return String(value);
66
+ }
67
+