@suifei/dsh-ai-team 0.4.134 → 0.4.136
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/CHANGELOG.md +23 -0
- package/README.md +54 -4
- package/client.js +166 -11
- package/index.js +21 -0
- package/lib/domain/avatar.js +258 -0
- package/lib/domain/catalog-sync.js +2 -2
- package/lib/domain/catalog.js +8 -2
- package/lib/host/default-roster.js +1 -0
- package/lib/host/service.js +19 -3
- package/lib/ledger/fold.js +12 -0
- package/package.json +1 -1
- package/talents/algo-reimplementer/talent.yml +2 -1
- package/talents/analyst/talent.yml +2 -1
- package/talents/architect/talent.yml +2 -1
- package/talents/binary-analyst/talent.yml +2 -1
- package/talents/biz-analyst/talent.yml +2 -1
- package/talents/code-reviewer/talent.yml +2 -1
- package/talents/content-author/talent.yml +2 -1
- package/talents/content-strategist/talent.yml +2 -1
- package/talents/copywriter/talent.yml +2 -1
- package/talents/creative-director/talent.yml +2 -1
- package/talents/curriculum-designer/talent.yml +2 -1
- package/talents/data-analyst/talent.yml +2 -1
- package/talents/deobfuscator/talent.yml +2 -1
- package/talents/diagrammer/talent.yml +2 -1
- package/talents/dynamic-debugger/talent.yml +2 -1
- package/talents/editor/talent.yml +2 -1
- package/talents/editorial-lead/talent.yml +2 -1
- package/talents/education-lead/talent.yml +2 -1
- package/talents/engineer/talent.yml +2 -1
- package/talents/executor/talent.yml +2 -1
- package/talents/experiment-designer/talent.yml +2 -1
- package/talents/fact-checker/talent.yml +2 -1
- package/talents/game-artist/talent.yml +2 -1
- package/talents/game-designer/talent.yml +2 -1
- package/talents/game-director/talent.yml +2 -1
- package/talents/game-tester/talent.yml +2 -1
- package/talents/gameplay-programmer/talent.yml +2 -1
- package/talents/mobile-re/talent.yml +2 -1
- package/talents/paper-writer/talent.yml +2 -1
- package/talents/peer-reviewer/talent.yml +2 -1
- package/talents/pmo-lead/talent.yml +2 -1
- package/talents/principal-investigator/talent.yml +2 -1
- package/talents/qa-acceptor/talent.yml +2 -1
- package/talents/re-lead/talent.yml +2 -1
- package/talents/re-verifier/talent.yml +2 -1
- package/talents/research-lead/talent.yml +2 -1
- package/talents/researcher/talent.yml +2 -1
- package/talents/scriptwriter/talent.yml +2 -1
- package/talents/security-auditor/talent.yml +2 -1
- package/talents/seo-specialist/talent.yml +2 -1
- package/talents/storyboard-artist/talent.yml +2 -1
- package/talents/tech-writer/talent.yml +2 -1
- package/talents/ux-designer/talent.yml +2 -1
- package/talents/video-editor/talent.yml +2 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 头像:参数校验(人才 talent.yml 的 `avatar`、成员资料的 `avatar`)与本机画图。
|
|
3
|
+
*
|
|
4
|
+
* 画图库 @suifei/hash-avatar 不随插件打包:插件运行时从 npm 取 latest(只走 registry 型镜像,
|
|
5
|
+
* 整包核对 registry 给的 sha512 integrity,下载与解包复用 catalog-sync.js),落到
|
|
6
|
+
* `<dshHome>/ai-team/vendor/hash-avatar/<版本>/hash-avatar.cjs`,`current.json` 记当前版本。
|
|
7
|
+
* 库更新了,插件不用重发:启动时先用本机缓存,后台查新版,有就换上。
|
|
8
|
+
*
|
|
9
|
+
* 可选值(性别 / 年龄 / 种族 / 画风、种族分组)以当前加载的库为准(GENDERS / AGES / RACES / ARTS / GROUPS),
|
|
10
|
+
* 库还没就绪时退回 BASE_OPTIONS(契约 v1 最早的五种人种)。人才市场、团队、成员共用这一份。
|
|
11
|
+
*/
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { catalogMirrors, latestVersion, packageReader } from './catalog-sync.js';
|
|
17
|
+
|
|
18
|
+
export const AVATAR_PACKAGE = '@suifei/hash-avatar';
|
|
19
|
+
/** 包里要的那一个文件:零依赖的 UMD 单文件。 */
|
|
20
|
+
export const AVATAR_FILE = 'src/hash-avatar.js';
|
|
21
|
+
export const MAX_AVATAR_LIB_BYTES = 4 * 1024 * 1024;
|
|
22
|
+
const SEMVER = /^\d+\.\d+\.\d+$/;
|
|
23
|
+
const TOKEN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
24
|
+
|
|
25
|
+
/** 库还没就绪时认的取值(契约 v1 的最小集合)。 */
|
|
26
|
+
export const BASE_OPTIONS = Object.freeze({
|
|
27
|
+
genders: Object.freeze(['male', 'female', 'neutral']),
|
|
28
|
+
ages: Object.freeze(['baby', 'teen', 'youth', 'middle', 'old']),
|
|
29
|
+
races: Object.freeze(['asian', 'white', 'black', 'brown', 'auto']),
|
|
30
|
+
groups: Object.freeze({ human: Object.freeze(['asian', 'white', 'black', 'brown', 'auto']) }),
|
|
31
|
+
arts: Object.freeze(['flat']),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/** 默认:亚洲人、青年、性别不指定;画风不写即库的默认(flat)。 */
|
|
35
|
+
export const DEFAULT_AVATAR = Object.freeze({ gender: 'neutral', age: 'youth', race: 'asian' });
|
|
36
|
+
|
|
37
|
+
/** 当前加载的库:{ api, version(npm 版本), contract, syncedAt, mirror } 或 null。 */
|
|
38
|
+
let active = null;
|
|
39
|
+
|
|
40
|
+
export function activeAvatarLib() {
|
|
41
|
+
return active;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 测试与启动用:直接装上一个库对象(null 卸下)。 */
|
|
45
|
+
export function useAvatarLib(api, meta = {}) {
|
|
46
|
+
if (api === null) {
|
|
47
|
+
active = null;
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
checkApi(api);
|
|
51
|
+
active = { api, version: meta.version ?? null, contract: typeof api.version === 'string' ? api.version : null, syncedAt: meta.syncedAt ?? null, mirror: meta.mirror ?? null };
|
|
52
|
+
return active;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function tokens(value, fallback) {
|
|
56
|
+
const list = Array.isArray(value) ? value.filter((x) => typeof x === 'string' && TOKEN.test(x)) : [];
|
|
57
|
+
return list.length > 0 ? Object.freeze(list) : fallback;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 当前可选值(界面挑选与校验共用)。 */
|
|
61
|
+
export function avatarOptions(lib = active) {
|
|
62
|
+
if (lib === null) return BASE_OPTIONS;
|
|
63
|
+
const { api } = lib;
|
|
64
|
+
const races = tokens(api.RACES, BASE_OPTIONS.races);
|
|
65
|
+
const groups = {};
|
|
66
|
+
if (api.GROUPS !== null && typeof api.GROUPS === 'object') {
|
|
67
|
+
for (const [group, list] of Object.entries(api.GROUPS)) {
|
|
68
|
+
if (!TOKEN.test(group)) continue;
|
|
69
|
+
const members = tokens(list, null);
|
|
70
|
+
if (members !== null) groups[group] = members.filter((race) => races.includes(race));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (Object.keys(groups).length === 0) groups.human = races;
|
|
74
|
+
// 没归进任何组的取值(如 1.3.0 的 any「随机」)收进 other,挑选界面才选得到。
|
|
75
|
+
const grouped = new Set(Object.values(groups).flat());
|
|
76
|
+
const other = races.filter((race) => !grouped.has(race));
|
|
77
|
+
if (other.length > 0) groups.other = Object.freeze([...(groups.other ?? []), ...other]);
|
|
78
|
+
return Object.freeze({ genders: tokens(api.GENDERS, BASE_OPTIONS.genders), ages: tokens(api.AGES, BASE_OPTIONS.ages), races, groups: Object.freeze(groups), arts: tokens(api.ARTS, BASE_OPTIONS.arts) });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 校验头像参数。缺省(undefined / null)返回 null;gender / age / race 可只给一部分,缺的按 DEFAULT_AVATAR 补;
|
|
83
|
+
* art 可选,不写就不带。写错的值抛错并说明哪一项,不静默改成别的。取值以当前库为准。
|
|
84
|
+
* @returns {{ gender: string, age: string, race: string, art?: string } | null}
|
|
85
|
+
*/
|
|
86
|
+
export function parseAvatar(value, label = 'avatar') {
|
|
87
|
+
if (value === undefined || value === null) return null;
|
|
88
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} 必须是对象(gender / age / race / art)`);
|
|
89
|
+
const options = avatarOptions();
|
|
90
|
+
const check = (key, allowed) => {
|
|
91
|
+
const raw = value[key];
|
|
92
|
+
if (typeof raw !== 'string' || !allowed.includes(raw)) {
|
|
93
|
+
const shown = allowed.length > 12 ? `${allowed.slice(0, 12).join(' / ')} …(共 ${allowed.length} 个)` : allowed.join(' / ');
|
|
94
|
+
throw new Error(`${label}.${key} 只认 ${shown}`);
|
|
95
|
+
}
|
|
96
|
+
return raw;
|
|
97
|
+
};
|
|
98
|
+
const pick = (key, allowed) => (value[key] === undefined || value[key] === null || value[key] === '' ? DEFAULT_AVATAR[key] : check(key, allowed));
|
|
99
|
+
const out = { gender: pick('gender', options.genders), age: pick('age', options.ages), race: pick('race', options.races) };
|
|
100
|
+
if (value.art !== undefined && value.art !== null && value.art !== '') out.art = check('art', options.arts);
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 画一张头像 SVG;库还没就绪返回 null(路由回 503,界面退回首字母)。参数宽松:写错或缺省的按默认;
|
|
106
|
+
* 尺寸夹到 16..1024;小于 128px(客户端按 2 倍像素取图,即显示不到 64px)时去掉外圈指纹与动效:
|
|
107
|
+
* 太密看不清,几十张卡片一起动也费 CPU(见 hash-avatar README)。
|
|
108
|
+
*/
|
|
109
|
+
export function renderAvatarSvg(name, options = {}) {
|
|
110
|
+
if (active === null) return null;
|
|
111
|
+
const allowed = avatarOptions();
|
|
112
|
+
const pick = (key, list) => (list.includes(options[key]) ? options[key] : DEFAULT_AVATAR[key]);
|
|
113
|
+
const size = Math.max(16, Math.min(1024, Math.round(Number(options.size) || 64)));
|
|
114
|
+
const input = String(name ?? '').trim().slice(0, 200) || '?';
|
|
115
|
+
const art = allowed.arts.includes(options.art) ? { art: options.art } : {};
|
|
116
|
+
const large = size >= 128;
|
|
117
|
+
return active.api.svg(input, { gender: pick('gender', allowed.genders), age: pick('age', allowed.ages), race: pick('race', allowed.races), ...art, size, fingerprint: large, animate: large });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function checkApi(api) {
|
|
121
|
+
if (api === null || typeof api !== 'object' || typeof api.svg !== 'function') throw new Error('不是 hash-avatar:缺 svg()');
|
|
122
|
+
const probe = api.svg('probe', { size: 32 });
|
|
123
|
+
if (typeof probe !== 'string' || !probe.startsWith('<svg')) throw new Error('hash-avatar 的 svg() 没画出 SVG');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function requireFresh(file) {
|
|
127
|
+
const req = createRequire(file);
|
|
128
|
+
delete req.cache[file];
|
|
129
|
+
return req(file);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 头像库在本机的落盘目录:`<dshHome>/ai-team/vendor/hash-avatar/`。 */
|
|
133
|
+
export function avatarLibDir(dshHome) {
|
|
134
|
+
if (typeof dshHome !== 'string' || dshHome === '') throw new Error('avatarLibDir: 需要 dshHome');
|
|
135
|
+
return join(dshHome, 'ai-team', 'vendor', 'hash-avatar');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function readCurrent(dshHome) {
|
|
139
|
+
try {
|
|
140
|
+
const current = JSON.parse(readFileSync(join(avatarLibDir(dshHome), 'current.json'), 'utf8'));
|
|
141
|
+
return SEMVER.test(current?.version ?? '') ? current : null;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 装上本机缓存的库;没有或坏了返回 null(不抛)。 */
|
|
148
|
+
export function loadAvatarLib(dshHome) {
|
|
149
|
+
const current = readCurrent(dshHome);
|
|
150
|
+
if (current === null) return null;
|
|
151
|
+
try {
|
|
152
|
+
const file = join(avatarLibDir(dshHome), current.version, 'hash-avatar.cjs');
|
|
153
|
+
if (!existsSync(file)) return null;
|
|
154
|
+
return useAvatarLib(requireFresh(file), current);
|
|
155
|
+
} catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 取代码只走 registry 型镜像(整包有 sha512 integrity 可核对);CDN 按文件取没有校验,不用来取代码。 */
|
|
161
|
+
export function avatarMirrors(env = process.env) {
|
|
162
|
+
return catalogMirrors(env).filter((mirror) => mirror.kind === 'registry');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 从 npm 取 latest 头像库;已是这个版本且已加载就不动。成功后立即换上。失败抛错,旧版本原样保留。
|
|
167
|
+
* @returns {Promise<{ updated: boolean, version: string, previous?: string|null, mirror?: string, contract?: string|null }>}
|
|
168
|
+
*/
|
|
169
|
+
export async function syncAvatarLib({ dshHome, fetchImpl = globalThis.fetch, mirrors = avatarMirrors(), timeoutMs = 15000, now = () => new Date().toISOString() } = {}) {
|
|
170
|
+
if (typeof fetchImpl !== 'function') throw new Error('当前宿主没有 fetch,取不到头像库');
|
|
171
|
+
const base = avatarLibDir(dshHome);
|
|
172
|
+
const current = readCurrent(dshHome);
|
|
173
|
+
const latest = await latestVersion({ fetchImpl, mirrors, pkg: AVATAR_PACKAGE, timeoutMs });
|
|
174
|
+
if (current !== null && current.version === latest.version) {
|
|
175
|
+
if (active === null || active.version !== latest.version) loadAvatarLib(dshHome);
|
|
176
|
+
if (active !== null && active.version === latest.version) return { updated: false, version: latest.version };
|
|
177
|
+
}
|
|
178
|
+
const ordered = [...mirrors.filter((m) => m.name === latest.mirror), ...mirrors.filter((m) => m.name !== latest.mirror)];
|
|
179
|
+
mkdirSync(base, { recursive: true });
|
|
180
|
+
const errors = [];
|
|
181
|
+
for (const mirror of ordered) {
|
|
182
|
+
const staging = join(base, `.staging-${latest.version}-${randomBytes(4).toString('hex')}`);
|
|
183
|
+
try {
|
|
184
|
+
const read = await packageReader(mirror, { fetchImpl, pkg: AVATAR_PACKAGE, version: latest.version, timeoutMs });
|
|
185
|
+
const code = await read(AVATAR_FILE);
|
|
186
|
+
if (code.length === 0 || code.length > MAX_AVATAR_LIB_BYTES) throw new Error(`${AVATAR_FILE} 大小不合格(${code.length})`);
|
|
187
|
+
mkdirSync(staging, { recursive: true });
|
|
188
|
+
writeFileSync(join(staging, 'hash-avatar.cjs'), code);
|
|
189
|
+
checkApi(requireFresh(join(staging, 'hash-avatar.cjs')));
|
|
190
|
+
const target = join(base, latest.version);
|
|
191
|
+
rmSync(target, { recursive: true, force: true });
|
|
192
|
+
renameSync(staging, target);
|
|
193
|
+
const record = { version: latest.version, syncedAt: now(), mirror: mirror.name };
|
|
194
|
+
writeFileSync(join(base, 'current.json.tmp'), JSON.stringify(record, null, 2) + '\n');
|
|
195
|
+
renameSync(join(base, 'current.json.tmp'), join(base, 'current.json'));
|
|
196
|
+
for (const name of readdirSync(base)) {
|
|
197
|
+
if (name === latest.version || name === 'current.json') continue;
|
|
198
|
+
rmSync(join(base, name), { recursive: true, force: true });
|
|
199
|
+
}
|
|
200
|
+
if (loadAvatarLib(dshHome) === null) throw new Error('新版本装不上');
|
|
201
|
+
return { updated: true, version: latest.version, previous: current?.version ?? null, mirror: mirror.name, contract: active.contract };
|
|
202
|
+
} catch (error) {
|
|
203
|
+
rmSync(staging, { recursive: true, force: true });
|
|
204
|
+
errors.push(`${mirror.name}: ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
throw new Error(`取头像库 ${AVATAR_PACKAGE}@${latest.version} 失败(${errors.join(';')})`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 插件启动用:先装本机缓存;查新版按需触发,不设定时器——界面取头像或 meta 时才查,
|
|
212
|
+
* 之后每 checkEveryMs 最多查一次(没用到头像的场景不联网)。
|
|
213
|
+
* `ready(ms)` 给路由用:库已就绪立即返回(顺带按节流查新版);没就绪就等一次在途的同步(最多 ms),仍没有返回 null。
|
|
214
|
+
*/
|
|
215
|
+
export function startAvatarLib({ dshHome, diag = null, fetchImpl = globalThis.fetch, mirrors, checkEveryMs = 6 * 3600 * 1000, clock = () => Date.now() } = {}) {
|
|
216
|
+
const loaded = loadAvatarLib(dshHome);
|
|
217
|
+
diag?.append(loaded === null ? { ev: 'avatar.lib.missing' } : { ev: 'avatar.lib.load', version: loaded.version, contract: loaded.contract });
|
|
218
|
+
let inflight = null;
|
|
219
|
+
let lastCheck = -Infinity;
|
|
220
|
+
let disposed = false;
|
|
221
|
+
const refresh = () => {
|
|
222
|
+
if (disposed) return Promise.resolve(null);
|
|
223
|
+
if (inflight !== null) return inflight;
|
|
224
|
+
lastCheck = clock();
|
|
225
|
+
inflight = syncAvatarLib({ dshHome, fetchImpl, ...(mirrors ? { mirrors } : {}) })
|
|
226
|
+
.then((result) => {
|
|
227
|
+
diag?.append(result.updated ? { ev: 'avatar.lib.update', version: result.version, previous: result.previous, mirror: result.mirror, contract: result.contract } : { ev: 'avatar.lib.current', version: result.version });
|
|
228
|
+
return result;
|
|
229
|
+
}, (error) => {
|
|
230
|
+
diag?.append({ ev: 'avatar.lib.sync.fail', message: error.message });
|
|
231
|
+
return null;
|
|
232
|
+
})
|
|
233
|
+
.finally(() => { inflight = null; });
|
|
234
|
+
return inflight;
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
refresh,
|
|
238
|
+
async ready(ms = 15000) {
|
|
239
|
+
if (active !== null) {
|
|
240
|
+
if (clock() - lastCheck >= checkEveryMs) void refresh();
|
|
241
|
+
return active;
|
|
242
|
+
}
|
|
243
|
+
// 刚失败过(离线)就别让每张图都再试一次:60 秒内直接回 null。
|
|
244
|
+
const recentlyFailed = inflight === null && clock() - lastCheck < 60 * 1000;
|
|
245
|
+
if (ms <= 0 || recentlyFailed) {
|
|
246
|
+
if (!recentlyFailed) void refresh();
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
let timer = null;
|
|
250
|
+
await Promise.race([refresh(), new Promise((resolve) => { timer = setTimeout(resolve, ms); })]);
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
return active;
|
|
253
|
+
},
|
|
254
|
+
dispose() {
|
|
255
|
+
disposed = true;
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -232,8 +232,8 @@ function checkIntegrity(buffer, integrity) {
|
|
|
232
232
|
if (createHash('sha512').update(buffer).digest('base64') !== entry.slice('sha512-'.length)) throw new Error('整包 integrity 校验不符');
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
/** 取包里文件的方法:registry 型一次下整包、核对 integrity 后从内存取;CDN
|
|
236
|
-
async function packageReader(mirror, { fetchImpl, pkg, version, timeoutMs }) {
|
|
235
|
+
/** 取包里文件的方法:registry 型一次下整包、核对 integrity 后从内存取;CDN 型按文件下。头像库(lib/domain/avatar.js)也用它取代码。 */
|
|
236
|
+
export async function packageReader(mirror, { fetchImpl, pkg, version, timeoutMs }) {
|
|
237
237
|
if (mirror.kind !== 'registry') {
|
|
238
238
|
return async (path) => Buffer.from(await (await fetchOk(fetchImpl, mirror.file(pkg, version, path), timeoutMs)).arrayBuffer());
|
|
239
239
|
}
|
package/lib/domain/catalog.js
CHANGED
|
@@ -16,6 +16,7 @@ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, write
|
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
18
|
import { parse, stringify } from 'yaml';
|
|
19
|
+
import { parseAvatar } from './avatar.js';
|
|
19
20
|
import { compareVersions, officialRoot } from './catalog-sync.js';
|
|
20
21
|
|
|
21
22
|
/** 插件内置目录(包根,下有 talents/ 与 teams/)。 */
|
|
@@ -94,6 +95,7 @@ export function parseTalent(source, label = 'talent') {
|
|
|
94
95
|
personality: text(doc.personality, 2000),
|
|
95
96
|
skills: skillList(doc.skills, `${label}: skills`),
|
|
96
97
|
model,
|
|
98
|
+
avatar: parseAvatar(doc.avatar, `${label}: avatar`),
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -197,7 +199,7 @@ export function loadCatalog({ roots = catalogRoots(), diag } = {}) {
|
|
|
197
199
|
/** 人才市场列表(给「添加成员」弹窗):按分类、名字排序。 */
|
|
198
200
|
export function listTalents(catalog) {
|
|
199
201
|
return [...catalog.talents.values()]
|
|
200
|
-
.map(({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model, shadows }) => ({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model, forked: source === 'user' && shadows !== undefined }))
|
|
202
|
+
.map(({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model, avatar, shadows }) => ({ id, source, version, name, role, duty: d, category, tags, description, personality, skills, model, avatar: avatar ?? null, forked: source === 'user' && shadows !== undefined }))
|
|
201
203
|
.sort((a, b) => a.category.localeCompare(b.category, 'zh') || a.name.localeCompare(b.name, 'zh'));
|
|
202
204
|
}
|
|
203
205
|
|
|
@@ -224,6 +226,7 @@ export function resolveTeam(catalog, name = DEFAULT_TEAM, { diag } = {}) {
|
|
|
224
226
|
skills: [...new Set([...talent.skills, ...member.skills])],
|
|
225
227
|
talent: { id: talent.id, version: talent.version, source: talent.source },
|
|
226
228
|
model: talent.model,
|
|
229
|
+
avatar: talent.avatar ?? null,
|
|
227
230
|
};
|
|
228
231
|
});
|
|
229
232
|
return { id: wanted, source: entry.source, dir: entry.dir, team: { name: entry.name || wanted, description: entry.description, lead: entry.lead, procedures: entry.procedures, members } };
|
|
@@ -269,6 +272,8 @@ function talentDoc(input) {
|
|
|
269
272
|
if (skills.length) doc.skills = skills;
|
|
270
273
|
const m = input?.model;
|
|
271
274
|
if (m && (text(m.provider, 80) || text(m.model, 160))) doc.model = { provider: text(m.provider, 80), model: text(m.model, 160), reasoningEffort: text(m.reasoningEffort, 20) };
|
|
275
|
+
const avatar = parseAvatar(input?.avatar);
|
|
276
|
+
if (avatar) doc.avatar = avatar;
|
|
272
277
|
return doc;
|
|
273
278
|
}
|
|
274
279
|
|
|
@@ -355,7 +360,7 @@ export function listTeams(catalog) {
|
|
|
355
360
|
.map((entry) => {
|
|
356
361
|
const members = entry.members.map((m) => {
|
|
357
362
|
const t = catalog.talents.get(m.talent);
|
|
358
|
-
return { id: m.id, talent: m.talent, name: m.name || t?.name || m.talent, role: m.role || t?.role || '', duty: m.duty ?? t?.duty ?? null, description: t?.description ?? '', category: t?.category ?? '', skills: [...new Set([...(t?.skills ?? []), ...(m.skills ?? [])])], missing: t === undefined };
|
|
363
|
+
return { id: m.id, talent: m.talent, name: m.name || t?.name || m.talent, role: m.role || t?.role || '', duty: m.duty ?? t?.duty ?? null, description: t?.description ?? '', category: t?.category ?? '', skills: [...new Set([...(t?.skills ?? []), ...(m.skills ?? [])])], avatar: t?.avatar ?? null, missing: t === undefined };
|
|
359
364
|
});
|
|
360
365
|
return { id: entry.id, source: entry.source, name: entry.name || entry.id, description: entry.description, lead: entry.lead, members, broken: members.some((m) => m.missing) };
|
|
361
366
|
})
|
|
@@ -417,6 +422,7 @@ export function talentFromMember(member, duty) {
|
|
|
417
422
|
tags: [],
|
|
418
423
|
personality: text(member?.personality, 2000),
|
|
419
424
|
model: provider || model ? { provider, model, reasoningEffort: text(config.reasoningEffort, 20) } : null,
|
|
425
|
+
avatar: member?.avatar ?? null,
|
|
420
426
|
skills: (Array.isArray(member?.skills) ? member.skills : []).map((s) => text(String(s), 64)).filter((s) => SKILL_NAME.test(s)),
|
|
421
427
|
};
|
|
422
428
|
}
|
|
@@ -27,6 +27,7 @@ function teamFields(preset, member) {
|
|
|
27
27
|
talentVersion: member.talent.version,
|
|
28
28
|
...(member.duty ? { duty: member.duty } : {}),
|
|
29
29
|
...(member.skills?.length > 0 ? { skills: member.skills } : {}),
|
|
30
|
+
...(member.avatar ? { avatar: member.avatar } : {}),
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
|
package/lib/host/service.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import { appendReply, createThread } from '../domain/thread.js';
|
|
23
23
|
import { boardView, quadrantsView, taskCard } from './views.js';
|
|
24
24
|
import { applyMemberConfigPatch, normalizeMemberConfig } from '../domain/member-config.js';
|
|
25
|
+
import { parseAvatar } from '../domain/avatar.js';
|
|
25
26
|
import { MEMBER_STATUS, isBoardIdle } from '../ledger/fold.js';
|
|
26
27
|
|
|
27
28
|
const MEMBER_STATUS_VALUES = new Set(Object.values(MEMBER_STATUS));
|
|
@@ -33,6 +34,15 @@ import { describeAttachments, findMentions, normalizeAttachments, plainMentionLi
|
|
|
33
34
|
* 主理人只调度交付、不核对产出(用户 2026-11-18):对别人的产出验收或退回都拒绝,并指路给验收人。
|
|
34
35
|
* 只在命令层拦,不进 fold:历史账本里主理人验收过的事件重放不受影响。
|
|
35
36
|
*/
|
|
37
|
+
/** 成员头像参数:写错的值按 INVALID_ARGUMENT 拒绝(lib/domain/avatar.js 同一份校验)。 */
|
|
38
|
+
function memberAvatar(value) {
|
|
39
|
+
try {
|
|
40
|
+
return parseAvatar(value);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return fail(ERRORS.INVALID_ARGUMENT, error.message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
36
46
|
function refuseLeadReview(state, reviewer) {
|
|
37
47
|
if (reviewer === null || reviewer === undefined || !isLeadMember(reviewer, state)) return;
|
|
38
48
|
fail(ERRORS.NOT_ELIGIBLE, 'the lead does not review deliverables: only ask the assignee whether it is complete, and leave acceptance to a QA member (or Human)', {
|
|
@@ -206,6 +216,7 @@ export class TeamService {
|
|
|
206
216
|
team: m.team ?? null,
|
|
207
217
|
talent: m.talent ?? null,
|
|
208
218
|
talentVersion: m.talentVersion ?? null,
|
|
219
|
+
avatar: m.avatar ?? null,
|
|
209
220
|
duty: m.duty ?? null,
|
|
210
221
|
profileVersion: m.profileVersion ?? 1,
|
|
211
222
|
distillVersion: m.distillVersion ?? 0,
|
|
@@ -763,6 +774,7 @@ export class TeamService {
|
|
|
763
774
|
const talent = ref(payload.talent);
|
|
764
775
|
const talentVersion = talent === null ? null : ref(payload.talentVersion);
|
|
765
776
|
const skills = Array.isArray(payload.skills) ? payload.skills.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim()) : [];
|
|
777
|
+
const avatar = memberAvatar(payload.avatar);
|
|
766
778
|
await this.append(command, 'project/member-added', {
|
|
767
779
|
memberId: member.id,
|
|
768
780
|
name: member.name,
|
|
@@ -775,6 +787,7 @@ export class TeamService {
|
|
|
775
787
|
...(talent !== null ? { talent, ...(talentVersion !== null ? { talentVersion } : {}) } : {}),
|
|
776
788
|
...(payload.duty ? { duty: payload.duty } : {}),
|
|
777
789
|
...(skills.length > 0 ? { skills } : {}),
|
|
790
|
+
...(avatar !== null ? { avatar } : {}),
|
|
778
791
|
});
|
|
779
792
|
return { member };
|
|
780
793
|
}
|
|
@@ -837,7 +850,7 @@ export class TeamService {
|
|
|
837
850
|
}
|
|
838
851
|
|
|
839
852
|
async updateMemberProfile(command, payload) {
|
|
840
|
-
if (command.actor.kind !== 'human') fail(ERRORS.UNAUTHORIZED, 'only Human may change name, role or
|
|
853
|
+
if (command.actor.kind !== 'human') fail(ERRORS.UNAUTHORIZED, 'only Human may change name, role, personality or avatar');
|
|
841
854
|
const member = this.state.members?.[payload.memberId];
|
|
842
855
|
if (member === undefined || member.kind !== 'agent') fail(ERRORS.NOT_FOUND, `agent ${String(payload.memberId)} not found`);
|
|
843
856
|
const text = (value) => (typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined);
|
|
@@ -845,14 +858,17 @@ export class TeamService {
|
|
|
845
858
|
const role = text(payload.role);
|
|
846
859
|
// An empty personality means "leave it unchanged", not "clear it".
|
|
847
860
|
const personality = text(payload.personality);
|
|
848
|
-
|
|
849
|
-
|
|
861
|
+
const avatar = memberAvatar(payload.avatar);
|
|
862
|
+
const avatarChanged = avatar !== null && JSON.stringify(avatar) !== JSON.stringify(member.avatar ?? null);
|
|
863
|
+
if (name === undefined && role === undefined && personality === undefined && !avatarChanged) {
|
|
864
|
+
fail(ERRORS.INVALID_ARGUMENT, 'name, role, personality or avatar is required');
|
|
850
865
|
}
|
|
851
866
|
await this.append(command, 'member/profile-updated', {
|
|
852
867
|
memberId: member.id,
|
|
853
868
|
...(name === undefined ? {} : { name }),
|
|
854
869
|
...(role === undefined ? {} : { role }),
|
|
855
870
|
...(personality === undefined ? {} : { personality }),
|
|
871
|
+
...(avatarChanged ? { avatar } : {}),
|
|
856
872
|
updatedBy: command.actor.memberId,
|
|
857
873
|
reason: payload.reason ?? '',
|
|
858
874
|
});
|
package/lib/ledger/fold.js
CHANGED
|
@@ -195,6 +195,15 @@ function makeProject(payload, event) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
function avatarOr(value, fallback) {
|
|
199
|
+
if (!isPlainObject(value)) return fallback;
|
|
200
|
+
const pick = (key) => (typeof value[key] === 'string' && value[key] !== '' ? value[key] : null);
|
|
201
|
+
const avatar = { gender: pick('gender'), age: pick('age'), race: pick('race') };
|
|
202
|
+
if (!(avatar.gender && avatar.age && avatar.race)) return fallback;
|
|
203
|
+
const art = pick('art');
|
|
204
|
+
return art ? { ...avatar, art } : avatar;
|
|
205
|
+
}
|
|
206
|
+
|
|
198
207
|
function makeMember(payload, event, existing) {
|
|
199
208
|
const source = isPlainObject(payload.member) ? payload.member : payload;
|
|
200
209
|
const kind = source.kind === 'human' || source.kind === 'agent' ? source.kind : existing?.kind ?? 'agent';
|
|
@@ -211,6 +220,8 @@ function makeMember(payload, event, existing) {
|
|
|
211
220
|
// 招自人才市场的哪位人才、哪个版本(talents/<人才>/talent.yml)。
|
|
212
221
|
talent: stringOrNull(source.talent) ?? existing?.talent ?? null,
|
|
213
222
|
talentVersion: stringOrNull(source.talentVersion) ?? existing?.talentVersion ?? null,
|
|
223
|
+
// 头像参数 { gender, age, race }(lib/domain/avatar.js);没有就按来源人才的或默认的画。
|
|
224
|
+
avatar: avatarOr(source.avatar, existing?.avatar ?? null),
|
|
214
225
|
duty: ['lead', 'qa', 'executor'].includes(source.duty) ? source.duty : existing?.duty ?? null,
|
|
215
226
|
status,
|
|
216
227
|
preset: stringOrNull(source.preset),
|
|
@@ -1067,6 +1078,7 @@ function applyEventCore(state, event) {
|
|
|
1067
1078
|
name: textOr(source.name, existing.name),
|
|
1068
1079
|
role: textOr(source.role, existing.role),
|
|
1069
1080
|
personality: textOr(source.personality, existing.personality ?? ''),
|
|
1081
|
+
avatar: avatarOr(source.avatar, existing.avatar ?? null),
|
|
1070
1082
|
profileVersion: intOr(source.profileVersion, (existing.profileVersion ?? 1) + 1),
|
|
1071
1083
|
profileUpdatedAt: event.at,
|
|
1072
1084
|
profileUpdatedBy: textOr(source.updatedBy, actorMemberId(event)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.136",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|