dsh-skill-harbor 0.5.3 → 0.5.4
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 -21
- package/README.md +44 -44
- package/cordis.patch.yml +4 -4
- package/dsh.plugin.json +1 -1
- package/lib/client.js +1447 -23
- package/lib/index.js +34 -1
- package/package.json +7 -2
- package/src/audit/normalize.js +77 -77
- package/src/audit/rules.js +167 -167
- package/src/budget/announcement.js +53 -53
- package/src/client/api.js +79 -79
- package/src/client/labels.js +6 -6
- package/src/client/lang.js +20 -0
- package/src/client/locales.js +688 -688
- package/src/client/mount.js +31 -0
- package/src/client/panel.js +5 -1
- package/src/client/react.js +13 -0
- package/src/client.js +35 -11
- package/src/collect/frontmatter.js +169 -169
- package/src/collect/observe.js +143 -143
- package/src/collect/ranks.js +56 -56
- package/src/collect/roots.js +92 -92
- package/src/collect/shadow.js +68 -68
- package/src/collect/watcher.js +86 -86
- package/src/config.js +42 -42
- package/src/index.js +34 -1
- package/src/market/fetch.js +94 -94
- package/src/market/install.js +169 -169
- package/src/market/source.js +90 -90
- package/src/market/store.js +66 -66
- package/src/market/zip.js +201 -201
- package/src/provider/lifecycle.js +74 -74
- package/src/routes/guard.js +156 -156
- package/src/routes/safe-path.js +96 -96
- package/src/routes/store.js +72 -72
- package/src/settings.js +83 -83
- package/lib/client/api.js +0 -79
- package/lib/client/labels.js +0 -6
- package/lib/client/locales.js +0 -688
- package/lib/client/panel.js +0 -527
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 字符预算 —— 渐进披露第一层到底占多少上下文。
|
|
3
|
-
*
|
|
4
|
-
* 只算 `name + description + whenToUse` 三层字段,**正文不计入**:
|
|
5
|
-
* 正文是第二层(按需加载),把它算进公告预算会系统性高估。
|
|
6
|
-
*/
|
|
7
|
-
import { charLength } from '../audit/normalize.js'
|
|
8
|
-
|
|
9
|
-
/** 单条技能的公告字符数。 */
|
|
10
|
-
export function announcementCharsOf(skill) {
|
|
11
|
-
if (skill === null || typeof skill !== 'object') return 0
|
|
12
|
-
return (
|
|
13
|
-
charLength(skill.name ?? '') +
|
|
14
|
-
charLength(skill.description ?? '') +
|
|
15
|
-
charLength(skill.whenToUse ?? '')
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 整个目录的字符账。
|
|
21
|
-
* 分开统计「全部」与「模型可见」—— 遮蔽掉的与 disable-model-invocation
|
|
22
|
-
* 关掉的都不进模型上下文,混在一起会误导用户。
|
|
23
|
-
*/
|
|
24
|
-
export function budgetReport(observations, options = {}) {
|
|
25
|
-
const { perSkillLimit = 4000 } = options
|
|
26
|
-
|
|
27
|
-
const rows = observations.map(observation => {
|
|
28
|
-
const chars = announcementCharsOf(observation)
|
|
29
|
-
return {
|
|
30
|
-
name: observation.name,
|
|
31
|
-
source: observation.source,
|
|
32
|
-
chars,
|
|
33
|
-
overLimit: chars > perSkillLimit,
|
|
34
|
-
modelInvocable: observation.modelInvocable === true,
|
|
35
|
-
shadowed: observation.shadowedBy !== undefined,
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const announced = rows.filter(row => !row.shadowed && row.modelInvocable)
|
|
40
|
-
const skipped = rows.filter(row => row.shadowed || !row.modelInvocable)
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
total: rows.reduce((sum, row) => sum + row.chars, 0),
|
|
44
|
-
announcedTotal: announced.reduce((sum, row) => sum + row.chars, 0),
|
|
45
|
-
skippedTotal: skipped.reduce((sum, row) => sum + row.chars, 0),
|
|
46
|
-
count: rows.length,
|
|
47
|
-
announcedCount: announced.length,
|
|
48
|
-
skippedCount: skipped.length,
|
|
49
|
-
perSkillLimit,
|
|
50
|
-
overLimit: announced.filter(row => row.overLimit),
|
|
51
|
-
rows,
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 字符预算 —— 渐进披露第一层到底占多少上下文。
|
|
3
|
+
*
|
|
4
|
+
* 只算 `name + description + whenToUse` 三层字段,**正文不计入**:
|
|
5
|
+
* 正文是第二层(按需加载),把它算进公告预算会系统性高估。
|
|
6
|
+
*/
|
|
7
|
+
import { charLength } from '../audit/normalize.js'
|
|
8
|
+
|
|
9
|
+
/** 单条技能的公告字符数。 */
|
|
10
|
+
export function announcementCharsOf(skill) {
|
|
11
|
+
if (skill === null || typeof skill !== 'object') return 0
|
|
12
|
+
return (
|
|
13
|
+
charLength(skill.name ?? '') +
|
|
14
|
+
charLength(skill.description ?? '') +
|
|
15
|
+
charLength(skill.whenToUse ?? '')
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 整个目录的字符账。
|
|
21
|
+
* 分开统计「全部」与「模型可见」—— 遮蔽掉的与 disable-model-invocation
|
|
22
|
+
* 关掉的都不进模型上下文,混在一起会误导用户。
|
|
23
|
+
*/
|
|
24
|
+
export function budgetReport(observations, options = {}) {
|
|
25
|
+
const { perSkillLimit = 4000 } = options
|
|
26
|
+
|
|
27
|
+
const rows = observations.map(observation => {
|
|
28
|
+
const chars = announcementCharsOf(observation)
|
|
29
|
+
return {
|
|
30
|
+
name: observation.name,
|
|
31
|
+
source: observation.source,
|
|
32
|
+
chars,
|
|
33
|
+
overLimit: chars > perSkillLimit,
|
|
34
|
+
modelInvocable: observation.modelInvocable === true,
|
|
35
|
+
shadowed: observation.shadowedBy !== undefined,
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const announced = rows.filter(row => !row.shadowed && row.modelInvocable)
|
|
40
|
+
const skipped = rows.filter(row => row.shadowed || !row.modelInvocable)
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
total: rows.reduce((sum, row) => sum + row.chars, 0),
|
|
44
|
+
announcedTotal: announced.reduce((sum, row) => sum + row.chars, 0),
|
|
45
|
+
skippedTotal: skipped.reduce((sum, row) => sum + row.chars, 0),
|
|
46
|
+
count: rows.length,
|
|
47
|
+
announcedCount: announced.length,
|
|
48
|
+
skippedCount: skipped.length,
|
|
49
|
+
perSkillLimit,
|
|
50
|
+
overLimit: announced.filter(row => row.overLimit),
|
|
51
|
+
rows,
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/client/api.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 客户端唯一 fetch 出口。
|
|
3
|
-
*
|
|
4
|
-
* 必须按 `document.baseURI` 解析 —— 反代带路径前缀(如 `/app/dsh/`)部署时,
|
|
5
|
-
* 写死 `/api/...` 会打到站点根而不是应用根,全部 404。
|
|
6
|
-
*/
|
|
7
|
-
import { LOCALES } from './locales.js'
|
|
8
|
-
|
|
9
|
-
export const API_PREFIX = '/dsh-skill-harbor/api'
|
|
10
|
-
export const CSRF_HEADER = 'x-dsh-skill-harbor'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 相对路径 → 绝对 URL,锚定到 document.baseURI。
|
|
14
|
-
* 非 `/` 开头或无 document 环境时原样返回。
|
|
15
|
-
*/
|
|
16
|
-
export function resolveApiUrl(path) {
|
|
17
|
-
if (typeof path !== 'string') return String(path)
|
|
18
|
-
try {
|
|
19
|
-
if (path.startsWith('/') && typeof document !== 'undefined' && document.baseURI) {
|
|
20
|
-
return new URL(path.slice(1), document.baseURI).href
|
|
21
|
-
}
|
|
22
|
-
} catch {
|
|
23
|
-
/* 落到原样返回 */
|
|
24
|
-
}
|
|
25
|
-
return path
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function request(path, options = {}) {
|
|
29
|
-
const url = resolveApiUrl(`${API_PREFIX}${path}`)
|
|
30
|
-
const method = options.method ?? 'GET'
|
|
31
|
-
|
|
32
|
-
const headers = { ...options.headers }
|
|
33
|
-
if (method !== 'GET' && method !== 'HEAD') {
|
|
34
|
-
// 写方法必须带自定义头;跨站表单设不了这个头
|
|
35
|
-
headers[CSRF_HEADER] = '1'
|
|
36
|
-
if (options.body !== undefined) headers['content-type'] = 'application/json'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const response = await fetch(url, {
|
|
40
|
-
method,
|
|
41
|
-
headers,
|
|
42
|
-
credentials: 'same-origin',
|
|
43
|
-
...options.body === undefined ? {} : { body: JSON.stringify(options.body) },
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
let payload = null
|
|
47
|
-
try {
|
|
48
|
-
payload = await response.json()
|
|
49
|
-
} catch {
|
|
50
|
-
payload = null
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
const error = new Error(payload?.message ?? payload?.error ?? `HTTP ${response.status}`)
|
|
55
|
-
error.status = response.status
|
|
56
|
-
error.payload = payload
|
|
57
|
-
throw error
|
|
58
|
-
}
|
|
59
|
-
return payload
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const api = {
|
|
63
|
-
list: () => request('/list'),
|
|
64
|
-
read: path => request(`/read?path=${encodeURIComponent(path)}`),
|
|
65
|
-
audit: () => request('/audit'),
|
|
66
|
-
budget: () => request('/budget'),
|
|
67
|
-
setEnabled: (path, enabled) => request('/set-enabled', { method: 'POST', body: { path, enabled } }),
|
|
68
|
-
update: (path, content) => request('/update', { method: 'POST', body: { path, content } }),
|
|
69
|
-
remove: path => request('/delete', { method: 'POST', body: { path } }),
|
|
70
|
-
importArchive: (archive, targetSource) =>
|
|
71
|
-
request('/import', { method: 'POST', body: { archive, targetSource } }),
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** 取某语言的字典,缺省回落 zh。 */
|
|
75
|
-
export function dict(lang) {
|
|
76
|
-
return LOCALES[lang] ?? LOCALES.zh
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { request }
|
|
1
|
+
/**
|
|
2
|
+
* 客户端唯一 fetch 出口。
|
|
3
|
+
*
|
|
4
|
+
* 必须按 `document.baseURI` 解析 —— 反代带路径前缀(如 `/app/dsh/`)部署时,
|
|
5
|
+
* 写死 `/api/...` 会打到站点根而不是应用根,全部 404。
|
|
6
|
+
*/
|
|
7
|
+
import { LOCALES } from './locales.js'
|
|
8
|
+
|
|
9
|
+
export const API_PREFIX = '/dsh-skill-harbor/api'
|
|
10
|
+
export const CSRF_HEADER = 'x-dsh-skill-harbor'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 相对路径 → 绝对 URL,锚定到 document.baseURI。
|
|
14
|
+
* 非 `/` 开头或无 document 环境时原样返回。
|
|
15
|
+
*/
|
|
16
|
+
export function resolveApiUrl(path) {
|
|
17
|
+
if (typeof path !== 'string') return String(path)
|
|
18
|
+
try {
|
|
19
|
+
if (path.startsWith('/') && typeof document !== 'undefined' && document.baseURI) {
|
|
20
|
+
return new URL(path.slice(1), document.baseURI).href
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
/* 落到原样返回 */
|
|
24
|
+
}
|
|
25
|
+
return path
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function request(path, options = {}) {
|
|
29
|
+
const url = resolveApiUrl(`${API_PREFIX}${path}`)
|
|
30
|
+
const method = options.method ?? 'GET'
|
|
31
|
+
|
|
32
|
+
const headers = { ...options.headers }
|
|
33
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
34
|
+
// 写方法必须带自定义头;跨站表单设不了这个头
|
|
35
|
+
headers[CSRF_HEADER] = '1'
|
|
36
|
+
if (options.body !== undefined) headers['content-type'] = 'application/json'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
method,
|
|
41
|
+
headers,
|
|
42
|
+
credentials: 'same-origin',
|
|
43
|
+
...options.body === undefined ? {} : { body: JSON.stringify(options.body) },
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
let payload = null
|
|
47
|
+
try {
|
|
48
|
+
payload = await response.json()
|
|
49
|
+
} catch {
|
|
50
|
+
payload = null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const error = new Error(payload?.message ?? payload?.error ?? `HTTP ${response.status}`)
|
|
55
|
+
error.status = response.status
|
|
56
|
+
error.payload = payload
|
|
57
|
+
throw error
|
|
58
|
+
}
|
|
59
|
+
return payload
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const api = {
|
|
63
|
+
list: () => request('/list'),
|
|
64
|
+
read: path => request(`/read?path=${encodeURIComponent(path)}`),
|
|
65
|
+
audit: () => request('/audit'),
|
|
66
|
+
budget: () => request('/budget'),
|
|
67
|
+
setEnabled: (path, enabled) => request('/set-enabled', { method: 'POST', body: { path, enabled } }),
|
|
68
|
+
update: (path, content) => request('/update', { method: 'POST', body: { path, content } }),
|
|
69
|
+
remove: path => request('/delete', { method: 'POST', body: { path } }),
|
|
70
|
+
importArchive: (archive, targetSource) =>
|
|
71
|
+
request('/import', { method: 'POST', body: { archive, targetSource } }),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 取某语言的字典,缺省回落 zh。 */
|
|
75
|
+
export function dict(lang) {
|
|
76
|
+
return LOCALES[lang] ?? LOCALES.zh
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { request }
|
package/src/client/labels.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** 状态的显示标签(与 locales 分离,供 panel 复用)。 */
|
|
2
|
-
export const FILE_STATE_LABEL = Object.freeze({
|
|
3
|
-
editable: 'editable',
|
|
4
|
-
'provider-file': 'provider-file',
|
|
5
|
-
virtual: 'virtual',
|
|
6
|
-
})
|
|
1
|
+
/** 状态的显示标签(与 locales 分离,供 panel 复用)。 */
|
|
2
|
+
export const FILE_STATE_LABEL = Object.freeze({
|
|
3
|
+
editable: 'editable',
|
|
4
|
+
'provider-file': 'provider-file',
|
|
5
|
+
virtual: 'virtual',
|
|
6
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 界面语言探测。
|
|
3
|
+
*
|
|
4
|
+
* 宿主把多个语种打包进同一份产物,运行期按浏览器语言挑字典;
|
|
5
|
+
* 命中不到(含 it/ko 之外的陌生语种、非浏览器环境)一律回落 zh。
|
|
6
|
+
*/
|
|
7
|
+
import { LOCALES } from './locales.js'
|
|
8
|
+
|
|
9
|
+
export function detectLang() {
|
|
10
|
+
try {
|
|
11
|
+
const raw = typeof navigator !== 'undefined' && navigator && navigator.language
|
|
12
|
+
? String(navigator.language)
|
|
13
|
+
: ''
|
|
14
|
+
const base = raw.toLowerCase().split('-')[0]
|
|
15
|
+
if (base !== '' && Object.prototype.hasOwnProperty.call(LOCALES, base)) return base
|
|
16
|
+
} catch {
|
|
17
|
+
/* 非浏览器环境(node --test / SSR)走回落 */
|
|
18
|
+
}
|
|
19
|
+
return 'zh'
|
|
20
|
+
}
|