dsh-rp-card 1.7.12 → 1.7.14

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # 更新记录
2
2
 
3
+ ## 1.7.14
4
+
5
+ 补充 `card_avatar` 的文档与工具指南(1.7.13 的 npm 包为补文档前版本)。
6
+
7
+ - `docs/supplements/头像呈现.md` 与 `lib/avatar.js` 指南同步:新增「全局约定:标准名一致」「五、前端插入与玩家文案」(示例层级与参考文案)「六、主提示词中的角色判断规则」与「示例代码(可直接复用)」。
8
+ - `checkAvatarCard` 增加 `hasWhoRule` 检测:已有多角色切换但主提示词缺「当前主交互角色」判定时提示补齐。
9
+ - 测试总数 139。
10
+
11
+ ## 1.7.13
12
+
13
+ 新增头像与图像呈现工具 `card_avatar`。
14
+
15
+ - 新工具 `card_avatar`(`guide` / `css` / `check`):用户要求换头像、头像自定义、头像切换或多角色头像时启动;`guide` 输出纯净操作指南,`css` 生成覆盖平台头像位的 CSS,`check` 检查卡的 `built_in_css` / `pre_prompt` 是否实现覆盖与 `data-c` 切换。
16
+ - 新增 `lib/avatar.js`(纯函数,不调模型)与 `docs/supplements/头像呈现.md`(操作指南)。
17
+ - 系统提示词新增「头像与图像呈现」段:固定头像用 CSS 覆盖(不依赖 AI);多角色用 `data-who` 标记 + `:has([data-c])` 切换;玩家自定义复制到「自定义配置里的内置 CSS」;覆盖头像位需同时让内部 `img` 透明。
18
+ - 新增 `tests/avatar.test.mjs`(10 项);`inject.test.mjs` 工具清单同步;测试总数 137。
19
+
3
20
  ## 1.7.12
4
21
 
5
22
  档案页补平台容器与沙箱环境约束。
@@ -0,0 +1,182 @@
1
+ # 头像与图像呈现(card_avatar)
2
+
3
+ > 工具触发:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」。
4
+ > 动作:`guide`(操作指南)、`css`(生成覆盖 CSS)、`check`(自检卡的实现)。
5
+ > 作者/agent 侧可用 `card_avatar`(action=css)传入玩家与 NPC 直链,预置或生成交付用 CSS;玩家侧不接触工具。
6
+
7
+ ---
8
+
9
+ ## 全局约定:标准名一致
10
+
11
+ 标准名(角色档案中的名字)必须在三处逐字一致:状态栏「[姓名/代号]」、世界书角色 key、CSS 的 `data-c`。这是全卡约定,不写进 `ppt` 的角色判断规则里。
12
+
13
+ ---
14
+
15
+ ## 一、先判断需求属于哪类
16
+
17
+ | 需求 | 做法 | 依赖 AI |
18
+ |---|---|---|
19
+ | 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |
20
+ | 多角色随说话人切换 | AI 输出 `data-who` 标记 + CSS `:has` 查表 | 是 |
21
+ | 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |
22
+
23
+ **原则**:能固定的不交给 AI;只有「当前是谁」才用标记。
24
+
25
+ ---
26
+
27
+ ## 二、固定头像(最可靠,首选)
28
+
29
+ ```css
30
+ /* 玩家头像 */
31
+ #customized-question-avatar{
32
+ background-image:url("玩家头像.png") !important;
33
+ background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
34
+ }
35
+ #customized-question-avatar img{opacity:0 !important;}
36
+
37
+ /* AI 头像(单角色) */
38
+ #customized-answer-avatar{
39
+ background-image:url("AI头像.png") !important;
40
+ background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
41
+ }
42
+ #customized-answer-avatar img{opacity:0 !important;}
43
+ ```
44
+
45
+ 要点:容器设背景图,内部 `img` 透明;只改其一会出现旧图透出或布局跳动。
46
+
47
+ ---
48
+
49
+ ## 三、多角色头像切换
50
+
51
+ 1. 输出格式里要求 AI 每条消息前输出隐藏标记:
52
+
53
+ ```html
54
+ <span data-who data-c="角色标准名"></span>
55
+ ```
56
+
57
+ 2. CSS 隐藏标记并按角色切换:
58
+
59
+ ```css
60
+ #customized-answer [data-who]{ display:none !important; }
61
+
62
+ #customized-answer:has([data-c="角色A"]) #customized-answer-avatar{
63
+ background-image:url("A.png") !important;
64
+ background-size:cover !important;background-position:center !important;
65
+ }
66
+ #customized-answer:has([data-c="角色B"]) #customized-answer-avatar{
67
+ background-image:url("B.png") !important;
68
+ background-size:cover !important;background-position:center !important;
69
+ }
70
+ ```
71
+
72
+ 规则:
73
+
74
+ - `data-c` 必须与角色档案、状态栏、世界书角色名**逐字一致**;
75
+ - 必须保留默认头像(未命中标记时回落);
76
+ - 玩家自己的消息不输出标记;
77
+ - 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。
78
+
79
+ ---
80
+
81
+ ## 四、玩家自定义换图
82
+
83
+ 1. 玩家把图片上传到图床,拿到直链;
84
+ 2. 在卡前端输入直链,点「生成 CSS」;
85
+ 3. 复制 CSS,粘贴到平台的「自定义配置里的内置 CSS」,保存;
86
+ 4. 回到聊天页刷新查看。
87
+
88
+ 前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。
89
+
90
+ ### 示例代码(可直接复用)
91
+
92
+ ```js
93
+ // 生成覆盖平台头像位的 CSS
94
+ function buildAvatarCss(playerUrl, npcList) {
95
+ const clean = (s) => String(s || '').trim().replace(/["\\)\s]/g, '');
96
+ const out = [];
97
+ const p = clean(playerUrl);
98
+ if (p) out.push(
99
+ '#customized-question-avatar{\n' +
100
+ ' background-image:url("' + p + '") !important;\n' +
101
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
102
+ '}\n#customized-question-avatar img{opacity:0 !important;}'
103
+ );
104
+ (npcList || []).forEach((n) => {
105
+ const u = clean(n && n.url), name = String((n && n.name) || '').trim();
106
+ if (!u || !name) return;
107
+ out.push(
108
+ '#customized-answer:has([data-c="' + name + '"]) #customized-answer-avatar{\n' +
109
+ ' background-image:url("' + u + '") !important;\n' +
110
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
111
+ '}'
112
+ );
113
+ });
114
+ return out.join('\n\n');
115
+ }
116
+
117
+ // 复制到剪贴板:平台内只能用 execCommand,必须在点击同步栈内执行
118
+ function copyText(text, btn) {
119
+ var ta = document.createElement('textarea');
120
+ ta.value = text;
121
+ ta.setAttribute('readonly', '');
122
+ ta.style.position = 'fixed';
123
+ ta.style.left = '-9999px';
124
+ document.body.appendChild(ta);
125
+ ta.select();
126
+ var ok = false;
127
+ try { ok = document.execCommand('copy'); } catch (e) { ok = false; }
128
+ ta.remove();
129
+ if (btn) btn.textContent = ok ? '已复制' : '复制失败,请手动选择';
130
+ return ok;
131
+ }
132
+
133
+ // 绑定
134
+ // btn.onclick = () => copyText(buildAvatarCss(playerUrl, [{ name: '苏小小', url: girlUrl }]), btn);
135
+ ```
136
+
137
+ 说明:
138
+
139
+ - 玩家头像走 `#customized-question-avatar`;多角色走 `:has([data-c="角色名"])`;
140
+ - URL 先剔除引号、反斜杠、括号与空白,避免 `url()` 断裂;
141
+ - 复制结果以 `execCommand` 返回值为准,不固定显示“已复制”;
142
+ - 本地选图用 `FileReader.readAsDataURL` 只做预览,不要写进 CSS。
143
+
144
+ ---
145
+
146
+ ## 五、前端插入与玩家文案
147
+
148
+ 前端(`desc`)生成或已有代码插入新功能时,可参考示例层级(具体情况具体分析,合理即可):
149
+
150
+ ```
151
+ #玩家信息收集页
152
+ #头像卡:
153
+ ##每个角色一行(本地选图上传 + 效果预览 + 直链输入)
154
+ ##生成 CSS 卡:直链输入 + 代码生成 + 预览 + 复制
155
+ ```
156
+
157
+ 参考文案:
158
+
159
+ - 介绍:「本卡支持自定义头像,你和其他角色的头像都可以换成自己的图片。」
160
+ - 选图说明:「图片直接上传只在本页生效,用于效果预览,不会在聊天页面生效;要真正实现切换,请先把图片上传到你的创作图库,获取URL直链后填入下面的输入框。」
161
+ - 粘贴位置:「把复制到的 CSS 粘贴到平台的『自定义配置』里的内置 CSS,保存后回到聊天页刷新即可生效。」
162
+ - 复制反馈:成功「已复制」/ 失败「复制失败,请手动选择下面的文本」。
163
+
164
+ ---
165
+
166
+ ## 六、主提示词中的角色判断规则(当卡内存在多个角色时,需要写入 `ppt`)
167
+
168
+ - 每轮先判定「当前主交互角色」,顺序为:① 场景中正在说话/动作的对象 → ② 玩家最近一句提到的对象 → ③ 事件或任务指定的对象 → ④ 近期玩家互动最频繁的对象
169
+ - 用角色档案里的标准名输出 `data-who`,不得使用简称、昵称或代号变体
170
+ - 无法判定(多人同屏、环境事件、纯旁白)→ 不输出标记
171
+ - 每轮只允许一个主交互角色;每条消息仅允许一个标记
172
+ - 标记放在该条消息内容的最前面,不插在气泡文本中间
173
+
174
+ ---
175
+
176
+ ## 七、验收清单
177
+
178
+ - 玩家头像打开即显示,AI 漏写不受影响;
179
+ - 单角色 AI 头像固定显示;
180
+ - 多角色消息头像各自切换,未命中时回落默认;
181
+ - `data-who` 标记在正文里不可见;
182
+ - 覆盖后平台其它 UI(按钮、输入框)未受影响。
package/index.js CHANGED
@@ -13,6 +13,7 @@ import { keyStatus } from './lib/image-setup.js';
13
13
  import { loadManifest } from './lib/assets.js';
14
14
  import { evaluateAction } from './lib/evaluate.js';
15
15
  import { reviewAction, REVIEW_ACTIONS } from './lib/review.js';
16
+ import { avatarAction, AVATAR_ACTIONS } from './lib/avatar.js';
16
17
  import { resolveVisionDelegate } from './lib/vision.js';
17
18
 
18
19
  // 视觉检查委托目标:环境变量 > profile 的 subagent 允许列表首个 DeepSeek 项 > 兜底。
@@ -1151,6 +1152,55 @@ export function apply(ctx) {
1151
1152
  }));
1152
1153
  });
1153
1154
 
1155
+ bindService(ctx, 'tools', (c, tools) => {
1156
+ c.effect(() => tools.register({
1157
+ name: 'card_avatar',
1158
+ description: '头像与图像呈现工具:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时使用。动作:guide(纯净操作指南:固定头像、多角色切换、玩家自定义三步)→ css(根据玩家与 NPC 图片地址生成覆盖平台头像位的 CSS)→ check(检查卡的 built_in_css / pre_prompt 是否已实现头像覆盖与 data-c 切换)。工具不调模型,不改卡。',
1159
+ parameters: {
1160
+ type: 'object',
1161
+ properties: {
1162
+ action: { type: 'string', enum: AVATAR_ACTIONS, description: '动作:guide / css / check' },
1163
+ player_url: { type: 'string', description: 'css:玩家头像图片直链' },
1164
+ npc: {
1165
+ type: 'array',
1166
+ description: 'css:NPC 头像列表 [{ name: 角色标准名, url: 图片直链 }]',
1167
+ items: {
1168
+ type: 'object',
1169
+ properties: { name: { type: 'string' }, url: { type: 'string' } },
1170
+ required: ['name', 'url'],
1171
+ },
1172
+ },
1173
+ built_in_css: { type: 'string', description: 'check:卡的 built_in_css' },
1174
+ pre_prompt: { type: 'string', description: 'check:卡的 pre_prompt(输出格式)' },
1175
+ },
1176
+ required: ['action'],
1177
+ },
1178
+ output: {
1179
+ schema: {
1180
+ type: 'object',
1181
+ properties: { ok: { type: 'boolean' }, action: { type: 'string' }, output: { type: 'string' } },
1182
+ required: ['ok', 'action', 'output'],
1183
+ },
1184
+ render: (_args, value) => [
1185
+ { type: 'text', text: value && typeof value.output === 'string' ? value.output : JSON.stringify(value, null, 2) },
1186
+ ],
1187
+ },
1188
+ execute: async (args) => {
1189
+ const act = args && args.action ? String(args.action) : 'guide';
1190
+ try {
1191
+ const result = avatarAction({ ...(args || {}) });
1192
+ return {
1193
+ ok: true,
1194
+ action: act,
1195
+ output: result.guide ? result.guide : JSON.stringify(result, null, 2),
1196
+ };
1197
+ } catch (e) {
1198
+ return { ok: false, action: act, output: `错误:${e && e.message ? e.message : String(e)}` };
1199
+ }
1200
+ },
1201
+ }));
1202
+ });
1203
+
1154
1204
  bindService(ctx, 'tools', (c, tools) => {
1155
1205
  c.effect(() => tools.register({
1156
1206
  name: 'card_library',
@@ -1418,6 +1468,14 @@ export function apply(ctx) {
1418
1468
  '- 只做本次要求的事,不顺手重做整卡;改完回归主奴线三栏 / 自由人两栏 / 奴隶表 / 背包 / 声望块 / 折叠。',
1419
1469
  '- 用户只要评估不要改 → 走上传卡评估流程;不要为了改功能先跑完整 audit。',
1420
1470
  '',
1471
+ '## 头像与图像呈现(工具 card_avatar)',
1472
+ '触发:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时,先调用 `card_avatar`(action=guide)拿操作指南,再按指南实现;实现后用 action=check 自检。',
1473
+ '- 固定头像(玩家 / 单角色 AI):CSS 覆盖 `#customized-question-avatar` / `#customized-answer-avatar`(容器背景图 + 内部 `img{opacity:0}`),**不依赖 AI**;',
1474
+ '- 多角色切换:输出格式要求每条消息前输出 `<span data-who data-c="角色标准名"></span>`,CSS 用 `:has([data-c="名字"])` 切换该条消息的头像位,并保留默认头像兜底;',
1475
+ '- 玩家自定义:用 `card_avatar`(action=css)生成覆盖 CSS,让玩家复制到平台的「**自定义配置里的内置 CSS**」——不要写成「自定义 CSS」;',
1476
+ '- `data-c` 必须与角色档案、状态栏、世界书的角色名逐字一致;一条消息只有一个头像位,多角色同屏时拆成多条消息;',
1477
+ '- 前端选图只能本地预览、无法上传;不要在卡里承诺自动上传或自动写入 CSS。',
1478
+ '',
1421
1479
  '## 教学模式(默认关闭)',
1422
1480
  '默认按正常节奏干活,不讲解原理。',
1423
1481
  '- 当用户说「我想学」「讲一下原理」「为什么这么做」「教我」时,开启教学模式:每一步多做三件事——这步在干什么、为什么这么做、换个做法会怎样;不改变实现,只增加解释。',
package/lib/avatar.js ADDED
@@ -0,0 +1,235 @@
1
+ /**
2
+ * 头像与图像呈现(card_avatar)
3
+ * 纯函数模块:不调模型、不读写卡;产出操作指南、CSS 片段与检查结论。
4
+ */
5
+
6
+ export const AVATAR_ACTIONS = ['guide', 'css', 'check'];
7
+
8
+ const cleanUrl = (s) => String(s || '').trim().replace(/["\\)\s]/g, '');
9
+
10
+ /** 生成「覆盖平台头像位」的 CSS 片段 */
11
+ export function buildAvatarCss({ player = '', npc = [] } = {}) {
12
+ const rules = [];
13
+ const p = cleanUrl(player);
14
+ if (p) {
15
+ rules.push(
16
+ '#customized-question-avatar{\n' +
17
+ ' background-image:url("' + p + '") !important;\n' +
18
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
19
+ '}\n' +
20
+ '#customized-question-avatar img{opacity:0 !important;}'
21
+ );
22
+ }
23
+ for (const item of Array.isArray(npc) ? npc : []) {
24
+ const url = cleanUrl(item && item.url);
25
+ const name = String((item && item.name) || '').trim();
26
+ if (!url || !name) continue;
27
+ rules.push(
28
+ '#customized-answer:has([data-c="' + name + '"]) #customized-answer-avatar{\n' +
29
+ ' background-image:url("' + url + '") !important;\n' +
30
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
31
+ '}'
32
+ );
33
+ }
34
+ return rules.join('\n\n');
35
+ }
36
+
37
+ /** 检查卡内头像实现状态 */
38
+ export function checkAvatarCard({ built_in_css = '', pre_prompt = '' } = {}) {
39
+ const css = String(built_in_css || '');
40
+ const ppt = String(pre_prompt || '');
41
+ const findings = [];
42
+ const suggestions = [];
43
+
44
+ const hasPlayer = css.includes('#customized-question-avatar');
45
+ const hasAnswer = css.includes('#customized-answer-avatar');
46
+ const hasSwitch = /:has\(\s*\[data-c=/i.test(css);
47
+ const hasMark = /data-who/i.test(css) || /data-who/i.test(ppt);
48
+ const hasImgTransparent = /#customized-(question|answer)-avatar\s+img\s*\{[^}]*opacity\s*:\s*0/i.test(css);
49
+ const hasWhoRule = /(当前主交互角色|主交互角色)/.test(ppt) && /data-who|data-c/.test(ppt);
50
+
51
+ if (hasPlayer) findings.push('已覆盖玩家头像位');
52
+ if (hasAnswer) findings.push('已覆盖 AI 头像位');
53
+ if (hasSwitch) findings.push('已使用 :has([data-c]) 多角色切换');
54
+ if (hasMark) findings.push('已输出或隐藏 data-who 标记');
55
+ if (hasWhoRule) findings.push('主提示词含「当前主交互角色」判断规则');
56
+ if (hasImgTransparent) findings.push('头像位内部 img 已透明');
57
+
58
+ if (!hasPlayer) suggestions.push('玩家头像固定:用 #customized-question-avatar 背景图覆盖,不依赖 AI');
59
+ if (!hasAnswer) suggestions.push('单角色 AI 头像固定:用 #customized-answer-avatar 背景图覆盖');
60
+ if (!hasSwitch && hasMark) suggestions.push('已有 data-who 标记,但缺少 :has([data-c]) 切换规则');
61
+ if (hasSwitch && !hasMark) suggestions.push('已有切换规则,但提示词里缺少 data-who 标记输出要求');
62
+ if (hasSwitch && !hasWhoRule) suggestions.push('多角色切换需在主提示词写明「当前主交互角色」判定顺序(大世界场景必备)');
63
+ if ((hasPlayer || hasAnswer) && !hasImgTransparent) suggestions.push('覆盖头像位时需同时让内部 img 透明(opacity:0),否则旧头像会透出');
64
+ if (!suggestions.length && (hasPlayer || hasAnswer)) suggestions.push('实现符合规范:固定头像不依赖 AI,多角色切换用 data-c');
65
+
66
+ return { findings, suggestions, flags: { hasPlayer, hasAnswer, hasSwitch, hasMark, hasImgTransparent, hasWhoRule } };
67
+ }
68
+
69
+ /** 纯净操作指南(面向玩家/写卡者,不含测试内容) */
70
+ export function avatarGuide() {
71
+ return [
72
+ '# 头像与图像呈现 · 操作指南',
73
+ '',
74
+ '## 全局约定:标准名一致',
75
+ '',
76
+ '标准名(角色档案中的名字)必须在三处逐字一致:状态栏「[姓名/代号]」、世界书角色 key、CSS 的 `data-c`。这是全卡约定,不写进 `ppt` 的角色判断规则里。',
77
+ '',
78
+ '## 适用场景',
79
+ '用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时使用本指南。',
80
+ '',
81
+ '## 一、先判断需求属于哪类',
82
+ '',
83
+ '| 需求 | 做法 | 依赖 AI |',
84
+ '|---|---|---|',
85
+ '| 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |',
86
+ '| 多角色随说话人切换 | AI 输出 data-who 标记 + CSS :has 查表 | 是 |',
87
+ '| 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |',
88
+ '',
89
+ '## 二、固定头像(最可靠,首选)',
90
+ '',
91
+ '```css',
92
+ '/* 玩家头像 */',
93
+ '#customized-question-avatar{',
94
+ ' background-image:url("玩家头像.png") !important;',
95
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
96
+ '}',
97
+ '#customized-question-avatar img{opacity:0 !important;}',
98
+ '',
99
+ '/* AI 头像(单角色) */',
100
+ '#customized-answer-avatar{',
101
+ ' background-image:url("AI头像.png") !important;',
102
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
103
+ '}',
104
+ '#customized-answer-avatar img{opacity:0 !important;}',
105
+ '```',
106
+ '',
107
+ '要点:容器设背景图,内部 img 透明;只改其一会出现旧图透出或布局跳动。',
108
+ '',
109
+ '## 三、多角色头像切换',
110
+ '',
111
+ '1. 在输出格式里要求 AI 每条消息前输出隐藏标记:',
112
+ '',
113
+ '```html',
114
+ '<span data-who data-c="角色标准名"></span>',
115
+ '```',
116
+ '',
117
+ '2. CSS 里隐藏标记并按角色切换:',
118
+ '',
119
+ '```css',
120
+ '#customized-answer [data-who]{ display:none !important; }',
121
+ '#customized-answer:has([data-c="角色A"]) #customized-answer-avatar{ background-image:url("A.png") !important; }',
122
+ '#customized-answer:has([data-c="角色B"]) #customized-answer-avatar{ background-image:url("B.png") !important; }',
123
+ '```',
124
+ '',
125
+ '规则:',
126
+ '- data-c 必须与角色档案、状态栏、世界书的角色名逐字一致;',
127
+ '- 必须保留默认头像(未命中标记时回落);',
128
+ '- 玩家自己的消息不输出标记;',
129
+ '- 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。',
130
+ '',
131
+ '## 四、玩家自定义换图',
132
+ '',
133
+ '1. 玩家把图片上传到图床,拿到直链;',
134
+ '2. 在卡前端输入直链,点「生成 CSS」;',
135
+ '3. 复制 CSS,粘贴到平台的「自定义配置里的内置 CSS」,保存;',
136
+ '4. 回到聊天页刷新查看。',
137
+ '',
138
+ '前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。',
139
+ '',
140
+ '### 示例代码(可直接复用)',
141
+ '',
142
+ '```js',
143
+ '// 生成覆盖平台头像位的 CSS',
144
+ 'function buildAvatarCss(playerUrl, npcList) {',
145
+ ' const clean = (s) => String(s || "").trim().replace(/["\\\\)\\s]/g, "");',
146
+ ' const out = [];',
147
+ ' const p = clean(playerUrl);',
148
+ ' if (p) out.push(',
149
+ ' "#customized-question-avatar{\\n" +',
150
+ ' " background-image:url(\\"" + p + "\\") !important;\\n" +',
151
+ ' " background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\\n" +',
152
+ ' "}\\n#customized-question-avatar img{opacity:0 !important;}"',
153
+ ' );',
154
+ ' (npcList || []).forEach((n) => {',
155
+ ' const u = clean(n && n.url), name = String((n && n.name) || "").trim();',
156
+ ' if (!u || !name) return;',
157
+ ' out.push(',
158
+ ' "#customized-answer:has([data-c=\\"" + name + "\\"]) #customized-answer-avatar{\\n" +',
159
+ ' " background-image:url(\\"" + u + "\\") !important;\\n" +',
160
+ ' " background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\\n" +',
161
+ ' "}"',
162
+ ' );',
163
+ ' });',
164
+ ' return out.join("\\n\\n");',
165
+ '}',
166
+ '',
167
+ '// 复制到剪贴板:平台内只能用 execCommand,必须在点击同步栈内执行',
168
+ 'function copyText(text, btn) {',
169
+ ' var ta = document.createElement("textarea");',
170
+ ' ta.value = text;',
171
+ ' ta.setAttribute("readonly", "");',
172
+ ' ta.style.position = "fixed";',
173
+ ' ta.style.left = "-9999px";',
174
+ ' document.body.appendChild(ta);',
175
+ ' ta.select();',
176
+ ' var ok = false;',
177
+ ' try { ok = document.execCommand("copy"); } catch (e) { ok = false; }',
178
+ ' ta.remove();',
179
+ ' if (btn) btn.textContent = ok ? "已复制" : "复制失败,请手动选择";',
180
+ ' return ok;',
181
+ '}',
182
+ '```',
183
+ '',
184
+ '说明:玩家头像走 `#customized-question-avatar`;多角色走 `:has([data-c="角色名"])`;URL 先剔除引号、反斜杠、括号与空白;复制结果以 `execCommand` 返回值为准;本地选图只用 `FileReader` 预览,不要写进 CSS。',
185
+ '',
186
+ '## 五、前端插入与玩家文案',
187
+ '',
188
+ '前端(desc)生成或已有代码插入新功能时,可参考示例层级(具体情况具体分析,合理即可):',
189
+ '',
190
+ '```',
191
+ '#玩家信息收集页',
192
+ '#头像卡:',
193
+ '##每个角色一行(本地选图上传 + 效果预览 + 直链输入)',
194
+ '##生成 CSS 卡:直链输入 + 代码生成 + 预览 + 复制',
195
+ '```',
196
+ '',
197
+ '参考文案:',
198
+ '',
199
+ '- 介绍:「本卡支持自定义头像,你和其他角色的头像都可以换成自己的图片。」',
200
+ '- 选图说明:「图片直接上传只在本页生效,用于效果预览,不会在聊天页面生效;要真正实现切换,请先把图片上传到你的创作图库,获取URL直链后填入下面的输入框。」',
201
+ '- 粘贴位置:「把复制到的 CSS 粘贴到平台的『自定义配置』里的内置 CSS,保存后回到聊天页刷新即可生效。」',
202
+ '- 复制反馈:成功「已复制」/ 失败「复制失败,请手动选择下面的文本」。',
203
+ '',
204
+ '## 六、主提示词中的角色判断规则(当卡内存在多个角色时,需要写入 ppt)',
205
+ '',
206
+ '- 每轮先判定「当前主交互角色」,顺序为:① 场景中正在说话/动作的对象 → ② 玩家最近一句提到的对象 → ③ 事件或任务指定的对象 → ④ 近期玩家互动最频繁的对象',
207
+ '- 用角色档案里的标准名输出 `data-who`,不得使用简称、昵称或代号变体',
208
+ '- 无法判定(多人同屏、环境事件、纯旁白)→ 不输出标记',
209
+ '- 每轮只允许一个主交互角色;每条消息仅允许一个标记',
210
+ '- 标记放在该条消息内容的最前面,不插在气泡文本中间',
211
+ '',
212
+ '## 七、验收清单',
213
+ '',
214
+ '- 玩家头像打开即显示,AI 漏写不受影响;',
215
+ '- 单角色 AI 头像固定显示;',
216
+ '- 多角色消息头像各自切换,未命中时回落默认;',
217
+ '- data-who 标记在正文里不可见;',
218
+ '- 覆盖后平台其它 UI(按钮、输入框)未受影响。',
219
+ ].join('\n');
220
+ }
221
+
222
+ /** 工具动作分发 */
223
+ export function avatarAction(args = {}) {
224
+ const action = String(args.action || 'guide');
225
+ if (action === 'guide') return { action, guide: avatarGuide() };
226
+ if (action === 'css') {
227
+ const css = buildAvatarCss({ player: args.player_url || '', npc: args.npc || [] });
228
+ return { action, css, note: css ? '复制到「自定义配置里的内置 CSS」' : '未提供图片地址' };
229
+ }
230
+ if (action === 'check') {
231
+ const result = checkAvatarCard({ built_in_css: args.built_in_css || '', pre_prompt: args.pre_prompt || '' });
232
+ return { action, ...result };
233
+ }
234
+ throw new Error(`未知动作:${action}(可用:${AVATAR_ACTIONS.join(' / ')})`);
235
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-rp-card",
3
- "version": "1.7.12",
3
+ "version": "1.7.14",
4
4
  "type": "module",
5
5
  "description": "DeepSeek Harness 插件:按四部分流程创作 RP 卡,含世界书规则层、人工门禁、图像能力设置、上传卡评估与平台组装。",
6
6
  "main": "index.js",