@suifei/dsh-ai-team 0.4.135 → 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 +12 -0
- package/README.md +28 -6
- package/client.js +77 -15
- package/index.js +14 -4
- package/lib/domain/avatar.js +235 -24
- package/lib/domain/catalog-sync.js +2 -2
- package/lib/ledger/fold.js +3 -1
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.136 - 2026-11-19
|
|
4
|
+
|
|
5
|
+
**头像库运行时从 npm 取最新版,不再随插件打包**
|
|
6
|
+
|
|
7
|
+
- `@suifei/hash-avatar` 从插件依赖里去掉。插件运行时从 npm 取 latest:只走 registry 型镜像(npmmirror → npmjs),整包核对 registry 给的 sha512 integrity,取出 `src/hash-avatar.js` 先试画一张再换上;缓存在 `~/.dsh/ai-team/vendor/hash-avatar/<版本>/`,只留当前版本。下载与解包复用在线人才库同步的同一套实现。库更新了插件不用重发。
|
|
8
|
+
- 什么时候查新版:启动只装本机缓存,不联网;界面第一次取头像时才查,之后每 6 小时最多查一次。首次使用会等库下载完(最多 15 秒);离线又没有缓存时头像接口回 503,界面退回首字母,60 秒内不重试。
|
|
9
|
+
- 可选值以当前加载的库为准:新增 `GET /ai-team/api/avatar/meta`(库版本、性别 / 年龄 / 种族 / 画风、种族分组)。挑选界面的种族改成按分组的下拉(人类、奇幻与神话、动物、科幻与奇物,没归组的进「其它」),新增画风下拉;1.3.0 的 88 个种族、10 种画风都配了中文名,库以后新增的取值先显示原 id。校验(talent.yml、成员资料)同样按库的取值,写错仍拒绝;头像参数可带可选的 `art`。
|
|
10
|
+
- 图片地址带库版本(`v=`),同版本可长缓存,换版本自动刷新;显示不到 64px 时去掉外圈指纹和动效。
|
|
11
|
+
- 诊断日志:`avatar.lib.load` / `avatar.lib.missing` / `avatar.lib.update` / `avatar.lib.current` / `avatar.lib.sync.fail`。
|
|
12
|
+
- README:加 Star 徽章、欢迎 Star 与「参与贡献」一节。
|
|
13
|
+
- 测试:`test/avatar.test.js` 新增运行时取库(假 registry:首次下载、同版本不动、换新版、integrity 不符 / 缺文件 / 不是头像库都拒绝且不动旧版、重启读缓存不联网)、节流与离线、`avatar/meta` 与 `avatar.svg` 路由、界面地址与挑选;测试打 tar 包的函数挪到 `test/tar-helper.js` 共用。全量 439。实机:隔离宿主从 npmmirror 取到 1.3.0(88 个种族、10 种画风),人才市场与挑选界面截图核对(`.ptc/rounds/r57-steps.json`,`shots-r57/`)。
|
|
14
|
+
|
|
3
15
|
## 0.4.135 - 2026-11-18
|
|
4
16
|
|
|
5
17
|
**头像:人才市场、团队、成员卡片都有头像(@suifei/hash-avatar,本机生成)**
|
package/README.md
CHANGED
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
<a href="https://www.npmjs.com/package/@suifei/dsh-ai-team"><img alt="npm" src="https://img.shields.io/npm/v/@suifei/dsh-ai-team?color=2f6feb&label=npm"></a>
|
|
13
13
|
<a href="https://github.com/suifei/dsh-ai-team/releases"><img alt="release" src="https://img.shields.io/github/v/release/suifei/dsh-ai-team?color=2f6feb"></a>
|
|
14
14
|
<a href="./LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-2f6feb"></a>
|
|
15
|
-
<img alt="tests" src="https://img.shields.io/badge/tests-
|
|
15
|
+
<img alt="tests" src="https://img.shields.io/badge/tests-439%20passing-2ea043">
|
|
16
16
|
<img alt="dsh" src="https://img.shields.io/badge/DeepSeek%20Harness-plugin-6f42c1">
|
|
17
|
+
<a href="https://github.com/suifei/dsh-ai-team/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/suifei/dsh-ai-team?style=social"></a>
|
|
17
18
|
</p>
|
|
18
19
|
|
|
20
|
+
<p align="center">觉得有用?点右上角 ⭐ <a href="https://github.com/suifei/dsh-ai-team">Star</a> 支持一下,也欢迎 <a href="https://github.com/suifei/dsh-ai-team/issues">提 issue</a> 和 <a href="https://github.com/suifei/dsh-ai-team/pulls">发 PR</a>。</p>
|
|
21
|
+
|
|
19
22
|
> 文渊阁,藏修、校勘、纂辑之地。
|
|
20
23
|
> 在这里,Human 不在环里逐条调度,而是在环上定方向、守信任、做最后那一步。
|
|
21
24
|
|
|
@@ -30,7 +33,7 @@
|
|
|
30
33
|
- **人才市场**(0.4.124–0.4.129):9 个内置团队、44 位内置人才,各自带看家技能。可以招聘、复制为可编辑、自建人才并装技能,也能把项目成员「存为人才」;新建项目时选团队,或从人才里挑人组新团队。
|
|
31
34
|
- **主理人只调度交付**(0.4.128):主理人不看产出,只问负责人做全没有;内容由验收人把关。
|
|
32
35
|
- **在线人才库**(0.4.130–0.4.131):「同步在线库」从 [`@suifei/dsh-ai-team-catalog`](https://www.npmjs.com/package/@suifei/dsh-ai-team-catalog) 拉取最新的人才与团队。国内走 npmmirror 整包下载,约 1 秒同步完;逐个文件核对 sha256,失败不影响旧版本,可一键退回内置。
|
|
33
|
-
- **头像**(0.4.135):人才市场、团队、成员卡片都有头像,由 [`@suifei/hash-avatar`](https://www.npmjs.com/package/@suifei/hash-avatar)
|
|
36
|
+
- **头像**(0.4.135–0.4.136):人才市场、团队、成员卡片都有头像,由 [`@suifei/hash-avatar`](https://www.npmjs.com/package/@suifei/hash-avatar) 在本机按名字生成。这个库**不随插件打包**:插件运行时从 npm 取最新版并缓存在本机,库更新了插件不用重发,新增的种族、画风直接出现在挑选界面里。内置人才预置了参数(默认亚洲人),自定义成员和人才可以选性别、年龄、种族(人类 / 奇幻 / 动物 / 科幻共 88 种)和画风(扁平、像素、水墨等 10 种)。
|
|
34
37
|
- **弹窗与人员池**(0.4.132–0.4.133):
|
|
35
38
|
- 弹窗占主页面的 90%,功能按钮固定在右上角。
|
|
36
39
|
- 成员资料按「资料 / 模型 / 技能 / 协作」分页签。
|
|
@@ -38,8 +41,18 @@
|
|
|
38
41
|
- 人员池是成员卡片,可以一次给多位成员批量配置模型。
|
|
39
42
|
|
|
40
43
|
<p align="center">
|
|
41
|
-
<img src="https://github.com/suifei/dsh-ai-team/releases/download/v0.4.
|
|
42
|
-
<sub
|
|
44
|
+
<img src="https://github.com/suifei/dsh-ai-team/releases/download/v0.4.135/talent-market-avatars.png" width="860" alt="人才市场:每位人才都有头像,同步在线库后按分类挑人" /><br/>
|
|
45
|
+
<sub>人才市场:每位人才都有自己的头像,同步在线库后按分类挑人</sub>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
<img src="https://github.com/suifei/dsh-ai-team/releases/download/v0.4.135/project-members-avatars.png" width="860" alt="项目主对话:左栏成员与消息都带头像" /><br/>
|
|
50
|
+
<sub>项目里:左栏成员和对话消息都带头像</sub>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
<img src="https://github.com/suifei/dsh-ai-team/releases/download/v0.4.135/member-profile-avatar.png" width="860" alt="成员资料:挑选头像的性别、年龄、人种" /><br/>
|
|
55
|
+
<sub>成员资料:头像可选性别、年龄、人种,左侧实时预览</sub>
|
|
43
56
|
</p>
|
|
44
57
|
|
|
45
58
|
<p align="center">
|
|
@@ -51,7 +64,7 @@
|
|
|
51
64
|
|
|
52
65
|
### 顺带做了个头像库:hash-avatar
|
|
53
66
|
|
|
54
|
-
为了让人才市场里的每位人才都有一张自己的脸,我们另做了一个开源库 **[`@suifei/hash-avatar`](https://www.npmjs.com/package/@suifei/hash-avatar)**([GitHub](https://github.com/suifei/hash-avatar)
|
|
67
|
+
为了让人才市场里的每位人才都有一张自己的脸,我们另做了一个开源库 **[`@suifei/hash-avatar`](https://www.npmjs.com/package/@suifei/hash-avatar)**([GitHub](https://github.com/suifei/hash-avatar))<a href="https://github.com/suifei/hash-avatar/stargazers"><img alt="hash-avatar stars" src="https://img.shields.io/github/stars/suifei/hash-avatar?style=social" align="absmiddle"></a>,同样欢迎 Star。文渊阁的头像就是它在本机生成的。
|
|
55
68
|
|
|
56
69
|
<p align="center">
|
|
57
70
|
<img src="https://avatar.onrpc.com/v1/%E5%A2%A8%E6%B8%8A.svg?gender=male&age=middle&race=asian&size=96" width="72" alt="墨渊" />
|
|
@@ -63,7 +76,7 @@
|
|
|
63
76
|
</p>
|
|
64
77
|
|
|
65
78
|
- **由名字或 email 确定**:输入经 SHA-256 决定五官、发型和配色;同一个名字永远是同一张脸。外圈 128 个刻度画出哈希的前 128 位,两个不同输入撞上同一张图的概率低于 UUIDv4 撞车。
|
|
66
|
-
-
|
|
79
|
+
- **性别、年龄、种族、画风只是渲染参数**,不进哈希,所以换参数后还是认得出同一个人:`gender=male|female|neutral`、`age=baby|teen|youth|middle|old`;`race` 有人类、奇幻与神话、动物、科幻与奇物四组共 88 种(如 `asian`、`elf`、`fox`、`robot`);`art` 有 `flat`、`pixel`、`ink`、`comic`、`watercolor` 等 10 种画风。
|
|
67
80
|
- **零依赖、同步、浏览器和 Node 都能用**,一张约 0.1 ms、约 6 KB 的 SVG;Apache-2.0。
|
|
68
81
|
- **不写代码也能用**:`https://avatar.onrpc.com/<名字>.svg?gender=female&age=youth&race=asian` 直接当图片地址。
|
|
69
82
|
|
|
@@ -297,6 +310,15 @@ round-19 DeepSeek + Zhipu 双 provider
|
|
|
297
310
|
- distilly / darwin 不内置,有则用、无则不用;`huashu-nuwa` 已被 Team 技能目录排除。
|
|
298
311
|
- desktop profile 由插件 patch 固定为 `danger-full-access / never`,只应在可信机器使用。
|
|
299
312
|
|
|
313
|
+
## 参与贡献
|
|
314
|
+
|
|
315
|
+
欢迎 ⭐ [Star](https://github.com/suifei/dsh-ai-team),这是对我们最直接的鼓励。
|
|
316
|
+
|
|
317
|
+
- **用着有问题、有想法**:到 [Issues](https://github.com/suifei/dsh-ai-team/issues) 说一声,附上截图或诊断日志最好。
|
|
318
|
+
- **想动手改**:Fork 后开分支提 [PR](https://github.com/suifei/dsh-ai-team/pulls),改行为的代码请配测试,`node --test` 全绿再提交。
|
|
319
|
+
- **贡献人才和团队**:新的人才(`talents/<人才>/talent.yml`)和团队(`teams/<团队>/team.yml`)都欢迎,合并后会随在线人才库发给所有用户。
|
|
320
|
+
- **头像库**:[hash-avatar](https://github.com/suifei/hash-avatar) 同样欢迎 Star 和贡献新的种族、画风。
|
|
321
|
+
|
|
300
322
|
---
|
|
301
323
|
|
|
302
324
|
## License
|
package/client.js
CHANGED
|
@@ -308,7 +308,8 @@ window.__ModuleLoader__.load({
|
|
|
308
308
|
talentLoadFailed: '人才市场读取失败:{error}',
|
|
309
309
|
talentSkills: '技能:{skills}',
|
|
310
310
|
talentUser: '自建',
|
|
311
|
-
avatarTitle: '头像', avatarGender: '性别', avatarAge: '年龄', avatarRace: '
|
|
311
|
+
avatarTitle: '头像', avatarGender: '性别', avatarAge: '年龄', avatarRace: '种族', avatarArt: '画风', avatarHint: '头像按名字在本机生成(hash-avatar,自动更新到 npm 最新版);改名会换一张脸,参数不变。',
|
|
312
|
+
avatar_southasian: '南亚人', avatar_seasian: '东南亚人', avatar_mideast: '中东人', avatar_latino: '拉丁裔', avatar_indigenous: '原住民', avatar_pacific: '太平洋岛民', avatar_elf: '精灵', avatar_orc: '兽人', avatar_goblin: '哥布林', avatar_troll: '巨魔', avatar_vampire: '吸血鬼', avatar_zombie: '僵尸', avatar_mummy: '木乃伊', avatar_oni: '鬼', avatar_tengu: '天狗', avatar_demon: '恶魔', avatar_angel: '天使', avatar_fairy: '仙子', avatar_mermaid: '人鱼', avatar_jinn: '灯神', avatar_dragon: '龙', avatar_kitsune: '九尾狐', avatar_qilin: '麒麟', avatar_phoenix: '凤凰', avatar_unicorn: '独角兽', avatar_nian: '年兽', avatar_tanuki: '狸猫', avatar_yeti: '雪怪', avatar_werewolf: '狼人', avatar_golem: '魔像', avatar_ghost: '幽灵', avatar_skeleton: '骷髅', avatar_slime: '史莱姆', avatar_cat: '猫', avatar_dog: '狗', avatar_fox: '狐狸', avatar_wolf: '狼', avatar_tiger: '老虎', avatar_lion: '狮子', avatar_leopard: '豹', avatar_panda: '熊猫', avatar_redpanda: '小熊猫', avatar_bear: '熊', avatar_koala: '考拉', avatar_raccoon: '浣熊', avatar_rabbit: '兔子', avatar_mouse: '老鼠', avatar_hamster: '仓鼠', avatar_hedgehog: '刺猬', avatar_capybara: '水豚', avatar_monkey: '猴子', avatar_ox: '牛', avatar_horse: '马', avatar_zebra: '斑马', avatar_giraffe: '长颈鹿', avatar_deer: '鹿', avatar_goat: '山羊', avatar_sheep: '绵羊', avatar_pig: '猪', avatar_elephant: '大象', avatar_snake: '蛇', avatar_frog: '青蛙', avatar_octopus: '章鱼', avatar_owl: '猫头鹰', avatar_penguin: '企鹅', avatar_rooster: '公鸡', avatar_chick: '小鸡', avatar_duck: '鸭子', avatar_parrot: '鹦鹉', avatar_bee: '蜜蜂', avatar_cyborg: '赛博格', avatar_android: '仿生人', avatar_hologram: '全息影像', avatar_robot: '机器人', avatar_ai: 'AI', avatar_alien: '外星人', avatar_insectoid: '虫族', avatar_mushroom: '蘑菇', avatar_pumpkin: '南瓜', avatar_snowman: '雪人', avatar_cactus: '仙人掌', avatar_star: '星星', avatar_any: '随机', avatar_art_flat: '扁平', avatar_art_pixel: '像素', avatar_art_ink: '水墨', avatar_art_comic: '漫画', avatar_art_sketch: '素描', avatar_art_neon: '霓虹', avatar_art_pop: '波普', avatar_art_mood: '心情', avatar_art_watercolor: '水彩', avatar_art_glitch: '故障', avatar_group_human: '人类', avatar_group_fantasy: '奇幻与神话', avatar_group_animal: '动物', avatar_group_scifi: '科幻与奇物', avatar_group_other: '其它',
|
|
312
313
|
avatar_male: '男', avatar_female: '女', avatar_neutral: '中性', avatar_baby: '婴儿', avatar_teen: '少年', avatar_youth: '青年', avatar_middle: '中年', avatar_old: '老年', avatar_asian: '黄种人', avatar_white: '白人', avatar_black: '黑人', avatar_brown: '棕色人种', avatar_auto: '不指定',
|
|
313
314
|
profileTabBasic: '资料', profileTabModel: '模型', profileTabSkills: '技能', profileTabCollab: '协作', profileNotes: '备忘', profileNotesEmpty: '还没有备忘。', profileSkillsEmpty: '还没装技能;在下面填技能名加一个,或到人才市场招已带技能的人才。',
|
|
314
315
|
teamPickDetail: '人才简介', teamPickDetailEmpty: '在左边点一位人才,这里看简介;点「加入」放进右边的团队。', teamLeadMark: '负责人', projectTeamMembers: '团队成员 · {n} 位',
|
|
@@ -764,7 +765,8 @@ window.__ModuleLoader__.load({
|
|
|
764
765
|
talentLoadFailed: 'Could not load the talent market: {error}',
|
|
765
766
|
talentSkills: 'Skills: {skills}',
|
|
766
767
|
talentUser: 'Custom',
|
|
767
|
-
avatarTitle: 'Avatar', avatarGender: 'Gender', avatarAge: 'Age', avatarRace: '
|
|
768
|
+
avatarTitle: 'Avatar', avatarGender: 'Gender', avatarAge: 'Age', avatarRace: 'Kind', avatarArt: 'Style', avatarHint: 'Drawn locally from the name (hash-avatar, kept at the latest npm release); renaming gives a new face with the same settings.',
|
|
769
|
+
avatar_art_flat: 'Flat', avatar_art_pixel: 'Pixel', avatar_art_ink: 'Ink', avatar_art_comic: 'Comic', avatar_art_sketch: 'Sketch', avatar_art_neon: 'Neon', avatar_art_pop: 'Pop', avatar_art_mood: 'Mood', avatar_art_watercolor: 'Watercolor', avatar_art_glitch: 'Glitch', avatar_group_human: 'Human', avatar_group_fantasy: 'Fantasy', avatar_group_animal: 'Animal', avatar_group_scifi: 'Sci-fi', avatar_group_other: 'Other',
|
|
768
770
|
avatar_male: 'Male', avatar_female: 'Female', avatar_neutral: 'Neutral', avatar_baby: 'Baby', avatar_teen: 'Teen', avatar_youth: 'Young', avatar_middle: 'Middle-aged', avatar_old: 'Senior', avatar_asian: 'Asian', avatar_white: 'White', avatar_black: 'Black', avatar_brown: 'Brown', avatar_auto: 'Any',
|
|
769
771
|
profileTabBasic: 'Profile', profileTabModel: 'Model', profileTabSkills: 'Skills', profileTabCollab: 'Collaboration', profileNotes: 'Notes', profileNotesEmpty: 'No notes yet.', profileSkillsEmpty: 'No skills yet; add one by name below, or hire a talent that comes with skills.',
|
|
770
772
|
teamPickDetail: 'Talent details', teamPickDetailEmpty: 'Pick a talent on the left to see its details; “Add” puts it into the team on the right.', teamLeadMark: 'Lead', projectTeamMembers: 'Team members · {n}',
|
|
@@ -1209,6 +1211,7 @@ window.__ModuleLoader__.load({
|
|
|
1209
1211
|
.at-avatarpickrows { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
1210
1212
|
.at-avatarpickrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
1211
1213
|
.at-avatarpickrow > .at-panetitle { width: 36px; flex: none; }
|
|
1214
|
+
.at-avatarselect { height: 30px; min-width: 120px; padding: 0 8px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 8px; background: var(--dsw-alias-bg-layer-1); color: inherit; font: inherit; }
|
|
1212
1215
|
.at-avatar-human { border-color: transparent; background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-inverted); }
|
|
1213
1216
|
.at-msgb { min-width: 0; flex: 1; }
|
|
1214
1217
|
.at-msgh { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
@@ -1667,20 +1670,38 @@ window.__ModuleLoader__.load({
|
|
|
1667
1670
|
return h('span', { className: 'at-avatar at-avatar-img', style, 'aria-hidden': 'true' },
|
|
1668
1671
|
h('img', { src: url, alt: '', loading: 'lazy', decoding: 'async', referrerPolicy: 'no-referrer', onError: () => setBrokenUrl(url) }));
|
|
1669
1672
|
}
|
|
1670
|
-
/**
|
|
1673
|
+
/**
|
|
1674
|
+
* 头像参数挑选,左边实时预览。性别、年龄是分段按钮;种族按库的 GROUPS 分组下拉,画风下拉——
|
|
1675
|
+
* 取值来自当前加载的 hash-avatar(/ai-team/api/avatar/meta),库新增的取值没配中文名时显示原 id。
|
|
1676
|
+
* 人才新建、自定义成员、成员资料共用。
|
|
1677
|
+
*/
|
|
1671
1678
|
function AvatarPicker({ t, value, seed, onChange }) {
|
|
1672
1679
|
const current = { ...AVATAR_PICK_DEFAULT, ...(value || {}) };
|
|
1680
|
+
const options = AVATAR_META.options;
|
|
1681
|
+
const set = (key, option) => onChange(avatarPickNext(current, key, option));
|
|
1682
|
+
const segmented = (key, label) => h('div', { key, className: 'at-avatarpickrow' },
|
|
1683
|
+
h('span', { className: 'at-panetitle' }, t(label)),
|
|
1684
|
+
h('div', { className: 'at-mode at-addtabs', role: 'group', 'aria-label': t(label) }, (key === 'gender' ? options.genders : options.ages).map((option) => h('button', {
|
|
1685
|
+
key: option,
|
|
1686
|
+
type: 'button',
|
|
1687
|
+
'aria-pressed': current[key] === option ? 'true' : 'false',
|
|
1688
|
+
onClick: () => set(key, option),
|
|
1689
|
+
}, avatarLabel(t, option)))));
|
|
1690
|
+
const groups = Object.entries(options.groups);
|
|
1673
1691
|
return h('div', { className: 'at-avatarpick' },
|
|
1674
1692
|
h(Avatar, { name: seed, seed, avatar: current, size: 72 }),
|
|
1675
1693
|
h('div', { className: 'at-avatarpickrows' },
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1694
|
+
segmented('gender', 'avatarGender'),
|
|
1695
|
+
segmented('age', 'avatarAge'),
|
|
1696
|
+
h('div', { className: 'at-avatarpickrow' },
|
|
1697
|
+
h('span', { className: 'at-panetitle' }, t('avatarRace')),
|
|
1698
|
+
h('select', { className: 'at-avatarselect', 'aria-label': t('avatarRace'), value: current.race, onChange: (event) => set('race', event.target.value) },
|
|
1699
|
+
groups.length > 1
|
|
1700
|
+
? groups.map(([group, list]) => h('optgroup', { key: group, label: avatarLabel(t, group, 'avatar_group_') }, list.map((race) => h('option', { key: race, value: race }, avatarLabel(t, race)))))
|
|
1701
|
+
: options.races.map((race) => h('option', { key: race, value: race }, avatarLabel(t, race)))),
|
|
1702
|
+
options.arts.length > 1 ? h('span', { className: 'at-panetitle' }, t('avatarArt')) : null,
|
|
1703
|
+
options.arts.length > 1 ? h('select', { className: 'at-avatarselect', 'aria-label': t('avatarArt'), value: current.art || options.arts[0], onChange: (event) => set('art', event.target.value) },
|
|
1704
|
+
options.arts.map((art) => h('option', { key: art, value: art }, avatarLabel(t, art, 'avatar_art_')))) : null),
|
|
1684
1705
|
h('div', { className: 'at-modalmeta' }, t('avatarHint'))));
|
|
1685
1706
|
}
|
|
1686
1707
|
|
|
@@ -3278,9 +3299,31 @@ window.__ModuleLoader__.load({
|
|
|
3278
3299
|
}
|
|
3279
3300
|
|
|
3280
3301
|
// <member-copy>
|
|
3281
|
-
// 头像:插件本机按名字画(@suifei/hash-avatar
|
|
3302
|
+
// 头像:插件本机按名字画(@suifei/hash-avatar 运行时从 npm 取 latest),人才与按原名招来的成员是同一张脸。
|
|
3282
3303
|
const AVATAR_ROUTE = '/ai-team/api/avatar.svg';
|
|
3283
|
-
|
|
3304
|
+
/** 库还没报上来之前认的取值(与 lib/domain/avatar.js 的 BASE_OPTIONS 同)。 */
|
|
3305
|
+
const AVATAR_BASE_OPTIONS = { genders: ['male', 'female', 'neutral'], ages: ['baby', 'teen', 'youth', 'middle', 'old'], races: ['asian', 'white', 'black', 'brown', 'auto'], groups: { human: ['asian', 'white', 'black', 'brown', 'auto'] }, arts: ['flat'] };
|
|
3306
|
+
/** 当前头像库:版本进图片地址(换版本即换地址,旧缓存不挡新图),可选值给挑选界面。由 /ai-team/api/avatar/meta 填。 */
|
|
3307
|
+
const AVATAR_META = { version: '', options: AVATAR_BASE_OPTIONS };
|
|
3308
|
+
function setAvatarMeta(body) {
|
|
3309
|
+
const o = body && body.options;
|
|
3310
|
+
const list = (value, fallback) => (Array.isArray(value) && value.length > 0 ? value.filter((x) => typeof x === 'string') : fallback);
|
|
3311
|
+
const groups = o && o.groups && typeof o.groups === 'object' ? Object.fromEntries(Object.entries(o.groups).filter(([, v]) => Array.isArray(v) && v.length > 0)) : {};
|
|
3312
|
+
AVATAR_META.version = body && typeof body.version === 'string' ? body.version : '';
|
|
3313
|
+
AVATAR_META.options = o ? { genders: list(o.genders, AVATAR_BASE_OPTIONS.genders), ages: list(o.ages, AVATAR_BASE_OPTIONS.ages), races: list(o.races, AVATAR_BASE_OPTIONS.races), groups: Object.keys(groups).length > 0 ? groups : AVATAR_BASE_OPTIONS.groups, arts: list(o.arts, AVATAR_BASE_OPTIONS.arts) } : AVATAR_BASE_OPTIONS;
|
|
3314
|
+
return AVATAR_META;
|
|
3315
|
+
}
|
|
3316
|
+
/** 选项的显示名:有翻译用翻译,库新增、还没配名字的显示原 id。 */
|
|
3317
|
+
function avatarLabel(t, key, prefix = 'avatar_') {
|
|
3318
|
+
const text = typeof t === 'function' ? t(prefix + key) : '';
|
|
3319
|
+
return typeof text === 'string' && text !== '' && !text.endsWith(prefix + key) ? text : key;
|
|
3320
|
+
}
|
|
3321
|
+
/** 挑选后的新参数;画风选回库的第一个(默认 flat)就不写进参数。 */
|
|
3322
|
+
function avatarPickNext(current, key, option) {
|
|
3323
|
+
const next = { ...current, [key]: option };
|
|
3324
|
+
if (key === 'art' && option === AVATAR_META.options.arts[0]) delete next.art;
|
|
3325
|
+
return next;
|
|
3326
|
+
}
|
|
3284
3327
|
/** 没设过头像、也查不到来源人才的成员:亚洲人、青年、性别不指定。 */
|
|
3285
3328
|
const AVATAR_FALLBACK = { gender: 'neutral', age: 'youth', race: 'asian' };
|
|
3286
3329
|
/** 自建时的初始选项:亚洲人、青年、男。 */
|
|
@@ -3292,9 +3335,13 @@ window.__ModuleLoader__.load({
|
|
|
3292
3335
|
return String(name ?? '').trim() || '?';
|
|
3293
3336
|
}
|
|
3294
3337
|
function avatarUrl(seed, avatar, size) {
|
|
3295
|
-
const
|
|
3338
|
+
const o = AVATAR_META.options;
|
|
3339
|
+
const lists = { gender: o.genders, age: o.ages, race: o.races };
|
|
3340
|
+
const pick = (key) => (lists[key].includes(avatar && avatar[key]) ? avatar[key] : AVATAR_FALLBACK[key]);
|
|
3296
3341
|
const px = Math.max(16, Math.min(1024, Math.round((Number(size) || 24) * 2)));
|
|
3297
|
-
|
|
3342
|
+
const art = avatar && o.arts.includes(avatar.art) && avatar.art !== o.arts[0] ? '&art=' + avatar.art : '';
|
|
3343
|
+
const version = AVATAR_META.version ? '&v=' + encodeURIComponent(AVATAR_META.version) : '';
|
|
3344
|
+
return AVATAR_ROUTE + '?name=' + encodeURIComponent(String(seed ?? '')) + '&gender=' + pick('gender') + '&age=' + pick('age') + '&race=' + pick('race') + art + '&size=' + px + version;
|
|
3298
3345
|
}
|
|
3299
3346
|
/** 成员的头像参数:自己设过的 > 来源人才的 > 默认(负责人按中年)。 */
|
|
3300
3347
|
function memberAvatarOf(agent, talents) {
|
|
@@ -3538,6 +3585,8 @@ window.__ModuleLoader__.load({
|
|
|
3538
3585
|
// 人才市场(「添加成员」弹窗第一页):可招聘的人才、筛选条件与当前页。
|
|
3539
3586
|
const [mTab, setMTab] = React.useState('market');
|
|
3540
3587
|
const [talents, setTalents] = React.useState(null);
|
|
3588
|
+
// 头像库 meta 到了就重画一遍(图片地址带上库版本、挑选界面换成库的可选值)。
|
|
3589
|
+
const [, setAvatarRev] = React.useState(0);
|
|
3541
3590
|
const [talentError, setTalentError] = React.useState('');
|
|
3542
3591
|
const [catalogInfo, setCatalogInfo] = React.useState(null);
|
|
3543
3592
|
const [catalogBusy, setCatalogBusy] = React.useState(false);
|
|
@@ -3725,6 +3774,8 @@ window.__ModuleLoader__.load({
|
|
|
3725
3774
|
// The package is @suifei/dsh-ai-team; the Host prefix is /ai-team.
|
|
3726
3775
|
// 头像要按成员的来源人才取参数:进工作台(切项目)时顺带取人才列表(没设过头像的老成员靠它)。
|
|
3727
3776
|
void loadTalents();
|
|
3777
|
+
// 头像库版本与可选值(首次启动时服务端会等库下载完,最多 15 秒)。
|
|
3778
|
+
void loadAvatarMeta();
|
|
3728
3779
|
const query = projectId ? '?project=' + encodeURIComponent(projectId) : '';
|
|
3729
3780
|
async function load() {
|
|
3730
3781
|
const seq = ++loadSeqRef.current;
|
|
@@ -4402,6 +4453,17 @@ window.__ModuleLoader__.load({
|
|
|
4402
4453
|
loadCatalogInfo();
|
|
4403
4454
|
}
|
|
4404
4455
|
/** 每次打开弹窗现取:用户刚改了 talent.yml 也能立刻看到。 */
|
|
4456
|
+
async function loadAvatarMeta() {
|
|
4457
|
+
try {
|
|
4458
|
+
const response = await fetch('/ai-team/api/avatar/meta?wait=15000', { headers: { accept: 'application/json' } });
|
|
4459
|
+
const body = await response.json().catch(() => null);
|
|
4460
|
+
if (!response.ok || !body) return;
|
|
4461
|
+
setAvatarMeta(body);
|
|
4462
|
+
setAvatarRev((n) => n + 1);
|
|
4463
|
+
} catch {
|
|
4464
|
+
// 取不到就用默认可选值;图片照样按名字取,失败退回首字母。
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4405
4467
|
async function loadTalents() {
|
|
4406
4468
|
setTalentError('');
|
|
4407
4469
|
try {
|
package/index.js
CHANGED
|
@@ -73,7 +73,7 @@ import { messageContent, normalizeAttachments } from './lib/domain/rich-message.
|
|
|
73
73
|
import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.js';
|
|
74
74
|
import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
|
|
75
75
|
import { CATALOG_PACKAGE, clearOfficialCatalog, officialStatus, syncOfficialCatalog } from './lib/domain/catalog-sync.js';
|
|
76
|
-
import { renderAvatarSvg } from './lib/domain/avatar.js';
|
|
76
|
+
import { AVATAR_PACKAGE, avatarOptions, renderAvatarSvg, startAvatarLib } from './lib/domain/avatar.js';
|
|
77
77
|
import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, forkTalent, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
|
|
78
78
|
|
|
79
79
|
export const name = 'ai-team';
|
|
@@ -389,6 +389,8 @@ export function apply(ctx, config = {}) {
|
|
|
389
389
|
ctx.effect(() => {
|
|
390
390
|
const webServer = serviceOf(ctx, 'webServer');
|
|
391
391
|
if (webServer === undefined) return () => {};
|
|
392
|
+
// 头像库不随插件打包:先用本机缓存,后台从 npm 取 latest(lib/domain/avatar.js)。
|
|
393
|
+
const avatarLib = startAvatarLib({ dshHome: dshHome(), diag });
|
|
392
394
|
|
|
393
395
|
let booted = null;
|
|
394
396
|
let bootError = null;
|
|
@@ -2385,13 +2387,20 @@ export function apply(ctx, config = {}) {
|
|
|
2385
2387
|
return send(res, { talents: listTalents(talentCatalog(diag)) });
|
|
2386
2388
|
}
|
|
2387
2389
|
// 第 3 步:官方在线人才库。状态 / 同步(npmmirror → jsDelivr,逐文件 sha256 校验后整体替换)/ 清除(退回内置)。
|
|
2388
|
-
//
|
|
2390
|
+
// 头像:运行时从 npm 取来的 @suifei/hash-avatar 在本机出 SVG。界面地址带库版本(v=),
|
|
2391
|
+
// 同版本同参同图,可长缓存;库换版本地址就变。库还没就绪回 503,界面退回首字母。
|
|
2392
|
+
if (req.method === 'GET' && url.pathname === '/ai-team/api/avatar/meta') {
|
|
2393
|
+
const lib = await avatarLib.ready(Number(url.searchParams.get('wait') ?? 0) || 0);
|
|
2394
|
+
return send(res, { package: AVATAR_PACKAGE, version: lib?.version ?? null, contract: lib?.contract ?? null, syncedAt: lib?.syncedAt ?? null, ready: lib !== null, options: avatarOptions(lib) });
|
|
2395
|
+
}
|
|
2389
2396
|
if (req.method === 'GET' && url.pathname === '/ai-team/api/avatar.svg') {
|
|
2397
|
+
await avatarLib.ready();
|
|
2390
2398
|
const q = url.searchParams;
|
|
2391
|
-
const svg = renderAvatarSvg(q.get('name') ?? '', { gender: q.get('gender'), age: q.get('age'), race: q.get('race'), size: q.get('size') });
|
|
2399
|
+
const svg = renderAvatarSvg(q.get('name') ?? '', { gender: q.get('gender'), age: q.get('age'), race: q.get('race'), art: q.get('art'), size: q.get('size') });
|
|
2400
|
+
if (svg === null) return send(res, { error: { code: 'E_UNAVAILABLE', message: `${AVATAR_PACKAGE} 还没取到(离线或镜像不可达)` } }, 503);
|
|
2392
2401
|
res.statusCode = 200;
|
|
2393
2402
|
res.setHeader('content-type', 'image/svg+xml; charset=utf-8');
|
|
2394
|
-
res.setHeader('cache-control', 'private, max-age=31536000, immutable');
|
|
2403
|
+
res.setHeader('cache-control', q.get('v') ? 'private, max-age=31536000, immutable' : 'private, max-age=3600');
|
|
2395
2404
|
res.setHeader('x-content-type-options', 'nosniff');
|
|
2396
2405
|
return res.end(svg);
|
|
2397
2406
|
}
|
|
@@ -3269,6 +3278,7 @@ export function apply(ctx, config = {}) {
|
|
|
3269
3278
|
// composition: a racing parent-agent dispose left the previous
|
|
3270
3279
|
// session-controller graph half-disposed and broke plugin toggles.
|
|
3271
3280
|
disposed = true;
|
|
3281
|
+
try { avatarLib.dispose(); } catch { /* already disposed */ }
|
|
3272
3282
|
try { removeDiagSink(); } catch { /* sink already replaced */ }
|
|
3273
3283
|
try { disposeShellGuard(); } catch { /* already disposed */ }
|
|
3274
3284
|
try { disposeStopGuard(); } catch { /* already disposed */ }
|
package/lib/domain/avatar.js
CHANGED
|
@@ -1,47 +1,258 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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 最早的五种人种)。人才市场、团队、成员共用这一份。
|
|
5
11
|
*/
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
14
|
import { createRequire } from 'node:module';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { catalogMirrors, latestVersion, packageReader } from './catalog-sync.js';
|
|
7
17
|
|
|
8
|
-
const
|
|
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}$/;
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
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
|
+
});
|
|
13
33
|
|
|
14
|
-
/**
|
|
34
|
+
/** 默认:亚洲人、青年、性别不指定;画风不写即库的默认(flat)。 */
|
|
15
35
|
export const DEFAULT_AVATAR = Object.freeze({ gender: 'neutral', age: 'youth', race: 'asian' });
|
|
16
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
|
+
|
|
17
81
|
/**
|
|
18
|
-
* 校验头像参数。缺省(undefined / null)返回 null
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @param {string} [label]
|
|
22
|
-
* @returns {{ gender: string, age: string, race: string } | null}
|
|
82
|
+
* 校验头像参数。缺省(undefined / null)返回 null;gender / age / race 可只给一部分,缺的按 DEFAULT_AVATAR 补;
|
|
83
|
+
* art 可选,不写就不带。写错的值抛错并说明哪一项,不静默改成别的。取值以当前库为准。
|
|
84
|
+
* @returns {{ gender: string, age: string, race: string, art?: string } | null}
|
|
23
85
|
*/
|
|
24
86
|
export function parseAvatar(value, label = 'avatar') {
|
|
25
87
|
if (value === undefined || value === null) return null;
|
|
26
|
-
if (typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} 必须是对象(gender / age / race)`);
|
|
27
|
-
const
|
|
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) => {
|
|
28
91
|
const raw = value[key];
|
|
29
|
-
if (
|
|
30
|
-
|
|
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
|
+
}
|
|
31
96
|
return raw;
|
|
32
97
|
};
|
|
33
|
-
|
|
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;
|
|
34
102
|
}
|
|
35
103
|
|
|
36
104
|
/**
|
|
37
|
-
* 画一张头像 SVG
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param {{ gender?: string, age?: string, race?: string, size?: number|string }} [options]
|
|
105
|
+
* 画一张头像 SVG;库还没就绪返回 null(路由回 503,界面退回首字母)。参数宽松:写错或缺省的按默认;
|
|
106
|
+
* 尺寸夹到 16..1024;小于 128px(客户端按 2 倍像素取图,即显示不到 64px)时去掉外圈指纹与动效:
|
|
107
|
+
* 太密看不清,几十张卡片一起动也费 CPU(见 hash-avatar README)。
|
|
41
108
|
*/
|
|
42
109
|
export function renderAvatarSvg(name, options = {}) {
|
|
43
|
-
|
|
110
|
+
if (active === null) return null;
|
|
111
|
+
const allowed = avatarOptions();
|
|
112
|
+
const pick = (key, list) => (list.includes(options[key]) ? options[key] : DEFAULT_AVATAR[key]);
|
|
44
113
|
const size = Math.max(16, Math.min(1024, Math.round(Number(options.size) || 64)));
|
|
45
114
|
const input = String(name ?? '').trim().slice(0, 200) || '?';
|
|
46
|
-
|
|
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
|
+
};
|
|
47
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/ledger/fold.js
CHANGED
|
@@ -199,7 +199,9 @@ function avatarOr(value, fallback) {
|
|
|
199
199
|
if (!isPlainObject(value)) return fallback;
|
|
200
200
|
const pick = (key) => (typeof value[key] === 'string' && value[key] !== '' ? value[key] : null);
|
|
201
201
|
const avatar = { gender: pick('gender'), age: pick('age'), race: pick('race') };
|
|
202
|
-
|
|
202
|
+
if (!(avatar.gender && avatar.age && avatar.race)) return fallback;
|
|
203
|
+
const art = pick('art');
|
|
204
|
+
return art ? { ...avatar, art } : avatar;
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
function makeMember(payload, event, existing) {
|
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",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@deepseek-ai/schemastery": "~3.19.0",
|
|
40
|
-
"@suifei/hash-avatar": "~1.0.1",
|
|
41
40
|
"yaml": "~2.9.1"
|
|
42
41
|
},
|
|
43
42
|
"files": [
|