dsh-rp-card 1.7.11 → 1.7.13
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,24 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## 1.7.13
|
|
4
|
+
|
|
5
|
+
新增头像与图像呈现工具 `card_avatar`。
|
|
6
|
+
|
|
7
|
+
- 新工具 `card_avatar`(`guide` / `css` / `check`):用户要求换头像、头像自定义、头像切换或多角色头像时启动;`guide` 输出纯净操作指南,`css` 生成覆盖平台头像位的 CSS,`check` 检查卡的 `built_in_css` / `pre_prompt` 是否实现覆盖与 `data-c` 切换。
|
|
8
|
+
- 新增 `lib/avatar.js`(纯函数,不调模型)与 `docs/supplements/头像呈现.md`(操作指南)。
|
|
9
|
+
- 系统提示词新增「头像与图像呈现」段:固定头像用 CSS 覆盖(不依赖 AI);多角色用 `data-who` 标记 + `:has([data-c])` 切换;玩家自定义复制到「自定义配置里的内置 CSS」;覆盖头像位需同时让内部 `img` 透明。
|
|
10
|
+
- 新增 `tests/avatar.test.mjs`(10 项);`inject.test.mjs` 工具清单同步;测试总数 137。
|
|
11
|
+
|
|
12
|
+
## 1.7.12
|
|
13
|
+
|
|
14
|
+
档案页补平台容器与沙箱环境约束。
|
|
15
|
+
|
|
16
|
+
- `docs/2-档案页.txt` 新增 §2.9.5「容器尺寸、外观基准与滚动」:容器三档(约 1000 / 1240 / 1415 px、高约 484)作为外观设计基准;运行时监听容器尺寸变化重算布局(ResizeObserver,退回 window.resize);外层平台页面无滚动条,超长内容由卡内滚动区承担;滚动联动沿用 §2.10.5 的 rAF 节流。
|
|
17
|
+
- §2.9.2 d) 健壮性:删除「跨会话存储必须 try/catch 降级」的表述,改为「平台无保存接口,不依赖跨会话存储;确需暂存只在内存中维护」。
|
|
18
|
+
- §4.4 平台兼容:`alert` / `confirm` / `prompt` 条补原因(平台 iframe 无 `allow-modals`:调用不弹窗,`confirm` 返回 `false`、`prompt` 返回 `null`);「需要跨页面保存的初始化数据,使用页面自身 JS 状态管理」改为「平台不提供前端持久化接口,前端状态只放内存,刷新 / 重进 / 新对话后丢失属预期」。
|
|
19
|
+
- 系统提示词 profile 段补平台环境约束(尺寸三档、无滚动条、无保存接口、无 modals)。
|
|
20
|
+
- 仅文档与提示词,代码行为不变;测试总数 127。
|
|
21
|
+
|
|
3
22
|
## 1.7.11
|
|
4
23
|
|
|
5
24
|
交付纪律改写:收窄到卡内提示词与世界书,避免抑制正常对话回复。
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
a) schema 驱动表单。触发条件:填写字段超过 12 个,或存在两条及以上分支/身份路线。做法:以一份字段描述数组(键、标签、控件类型、占位、选项、默认值、依赖、是否只读/自动生成)作为唯一数据源,渲染、取值、示例填充、随机生成、输出编译全部由通用函数消费它。禁止逐页手写表单结构,禁止逐页手写读取字段的代码。
|
|
95
95
|
b) 三态输入。每个填写区至少具备"空白"与"示例"两态;字段多时再加"随机"态。示例可只补空字段或整体覆盖,但结果必须整组自洽。随机按区块给粒度(人物/场景/经济各一个按钮),不要只给一个总随机。
|
|
96
96
|
c) 随机的约束传播。随机不得各字段独立抽取。先声明依赖链(例:性别 → 外貌候选库 → 称谓;规模 → 资金区间;身份 → 可用装备表),按链顺序抽;任一锚点字段被改动,其下游整组重抽。
|
|
97
|
-
d) 健壮性。所有外链图片必须写 onerror
|
|
97
|
+
d) 健壮性。所有外链图片必须写 onerror 降级为占位(首字母、剪影或纯色块),占位尺寸与图片一致,加载失败时布局不得跳动。平台无保存接口(见 4.4),不要依赖跨会话存储;确需暂存时只在内存中维护,离开页面即失属预期。平台禁用项见 4.4。
|
|
98
98
|
e) 破坏性操作。重置、清除、离开未保存页面都必须二次确认,确认控件用页面内弹层,不用原生 confirm(4.4)。
|
|
99
99
|
f) 返回与丢失保护。多步流程中存在未保存修改时,离开须提示"继续填写 / 放弃修改 / 保存并离开"。
|
|
100
100
|
2.9.3 高级选项(默认不使用;由你根据玩家需求判断是否启用)
|
|
@@ -110,6 +110,13 @@ f) 返回与丢失保护。多步流程中存在未保存修改时,离开须
|
|
|
110
110
|
一张卡只选一种主骨架;其他骨架只能作为主流程中的一个环节出现,不得并列成多个入口。
|
|
111
111
|
骨架定下后,字段表、状态槽、输出模板三者必须一一对应:一条路线一套字段集、一套状态、一份输出模板。
|
|
112
112
|
高级选项无论启用还是不启用,都在交付说明里写一句,让玩家知道你做了什么选择、为什么。
|
|
113
|
+
|
|
114
|
+
2.9.5 容器尺寸、外观基准与滚动
|
|
115
|
+
平台容器宽度有三档(约 1000 / 1240 / 1415 px,高度约 484 px),关闭平台侧栏会变宽。
|
|
116
|
+
- 外观设计以这三档为基准:按 1000 宽做主干排版,1240 / 1415 时检查留白、双栏与间距是否合理;不要只按浏览器视口设计。
|
|
117
|
+
- 运行时监听容器尺寸变化并重算布局(优先 ResizeObserver,不可用时退回 window.resize),不得用首次测量的值写死百分比布局。
|
|
118
|
+
- 高度预算按 484 px 考虑;内容超出时由卡内滚动容器承担(overflow-y: auto 的内部滚动区)。外层平台页面没有滚动条,不得假设外层会滚动。
|
|
119
|
+
- 滚动联动沿用 2.10.5:一律 rAF 节流,不在 scroll 事件里直接写样式。
|
|
113
120
|
2.10 动效规范
|
|
114
121
|
2.10.1 三条口径
|
|
115
122
|
动效的职责是让“状态变化被看见”,不是装饰。先确定哪个变化需要被看见,再挑条目;不要为了用某条动效而制造一次状态变化。
|
|
@@ -365,11 +372,11 @@ d) 骨架已有能力,不要为这两项单独发明新的前端交互。
|
|
|
365
372
|
- "window.open"。
|
|
366
373
|
- "postMessage" 与父窗口通信。
|
|
367
374
|
- "history.pushState" 和浏览器历史导航。
|
|
368
|
-
- "alert"、"confirm"、"prompt"
|
|
375
|
+
- "alert"、"confirm"、"prompt"(平台 iframe 无 "allow-modals":调用不弹窗,"confirm" 直接返回 "false"、"prompt" 返回 "null")。
|
|
369
376
|
- "navigator.clipboard" 系列("writeText" / "write" / "ClipboardItem")与 "window.clipboardData":平台 iframe 实测失败;复制只用 "document.execCommand('copy')"(见 3.6.1)。
|
|
370
377
|
- "location.reload"。
|
|
371
378
|
- 浏览器打印和下载作为主要输出方式。
|
|
372
|
-
|
|
379
|
+
平台不提供前端持久化接口("localStorage" / "sessionStorage" / cookie / IndexedDB 读取即抛错);前端状态只放内存,刷新、重进或新对话后丢失属预期,不要设计依赖持久化的功能。
|
|
373
380
|
需要输出数据时,以可见文本和复制功能为主要交付方式。
|
|
374
381
|
|
|
375
382
|
4.5 跨部分边界:聊天原生输入不属于本部分
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# 头像与图像呈现(card_avatar)
|
|
2
|
+
|
|
3
|
+
> 工具触发:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」。
|
|
4
|
+
> 动作:`guide`(操作指南)、`css`(生成覆盖 CSS)、`check`(自检卡的实现)。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 一、先判断需求属于哪类
|
|
9
|
+
|
|
10
|
+
| 需求 | 做法 | 依赖 AI |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |
|
|
13
|
+
| 多角色随说话人切换 | AI 输出 `data-who` 标记 + CSS `:has` 查表 | 是 |
|
|
14
|
+
| 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |
|
|
15
|
+
|
|
16
|
+
**原则**:能固定的不交给 AI;只有「当前是谁」才用标记。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 二、固定头像(最可靠,首选)
|
|
21
|
+
|
|
22
|
+
```css
|
|
23
|
+
/* 玩家头像 */
|
|
24
|
+
#customized-question-avatar{
|
|
25
|
+
background-image:url("玩家头像.png") !important;
|
|
26
|
+
background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
|
|
27
|
+
}
|
|
28
|
+
#customized-question-avatar img{opacity:0 !important;}
|
|
29
|
+
|
|
30
|
+
/* AI 头像(单角色) */
|
|
31
|
+
#customized-answer-avatar{
|
|
32
|
+
background-image:url("AI头像.png") !important;
|
|
33
|
+
background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
|
|
34
|
+
}
|
|
35
|
+
#customized-answer-avatar img{opacity:0 !important;}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
要点:容器设背景图,内部 `img` 透明;只改其一会出现旧图透出或布局跳动。
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 三、多角色头像切换
|
|
43
|
+
|
|
44
|
+
1. 输出格式里要求 AI 每条消息前输出隐藏标记:
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<span data-who data-c="角色标准名"></span>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. CSS 隐藏标记并按角色切换:
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
#customized-answer [data-who]{ display:none !important; }
|
|
54
|
+
|
|
55
|
+
#customized-answer:has([data-c="角色A"]) #customized-answer-avatar{
|
|
56
|
+
background-image:url("A.png") !important;
|
|
57
|
+
background-size:cover !important;background-position:center !important;
|
|
58
|
+
}
|
|
59
|
+
#customized-answer:has([data-c="角色B"]) #customized-answer-avatar{
|
|
60
|
+
background-image:url("B.png") !important;
|
|
61
|
+
background-size:cover !important;background-position:center !important;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
规则:
|
|
66
|
+
|
|
67
|
+
- `data-c` 必须与角色档案、状态栏、世界书角色名**逐字一致**;
|
|
68
|
+
- 必须保留默认头像(未命中标记时回落);
|
|
69
|
+
- 玩家自己的消息不输出标记;
|
|
70
|
+
- 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 四、玩家自定义换图
|
|
75
|
+
|
|
76
|
+
1. 玩家把图片上传到图床,拿到直链;
|
|
77
|
+
2. 用 `card_avatar`(action=css)或卡前端生成 CSS;
|
|
78
|
+
3. 复制 CSS,粘贴到平台的「**自定义配置里的内置 CSS**」,保存;
|
|
79
|
+
4. 回到聊天页刷新查看。
|
|
80
|
+
|
|
81
|
+
前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 五、验收清单
|
|
86
|
+
|
|
87
|
+
- 玩家头像打开即显示,AI 漏写不受影响;
|
|
88
|
+
- 单角色 AI 头像固定显示;
|
|
89
|
+
- 多角色消息头像各自切换,未命中时回落默认;
|
|
90
|
+
- `data-who` 标记在正文里不可见;
|
|
91
|
+
- 覆盖后平台其它 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
|
'- 当用户说「我想学」「讲一下原理」「为什么这么做」「教我」时,开启教学模式:每一步多做三件事——这步在干什么、为什么这么做、换个做法会怎样;不改变实现,只增加解释。',
|
|
@@ -1498,7 +1556,7 @@ export function apply(ctx) {
|
|
|
1498
1556
|
'世界书标签旁车:`.card-build/wb-plan.json`(可用 `template --part writing` 生成骨架)。每条标 职责(知识/规则/路由/控制词)、激活(内容锚/格式字段锚/格式标记锚)、载体(wb/ppt/ptx/post);常驻条目必填 `anchorSource`(如 `post:【命运】模式`)。没有该文件时校验跳过,旧卡不受影响。',
|
|
1499
1557
|
'状态机是可选方案(输出标记 → 条件加载规则),不启用时 `ppt` 不得承诺阶段/时限/进度。',
|
|
1500
1558
|
'世界书部署字段一律用平台默认值,不要询问用户、也不要照抄任何示例数字:sort=0、depth=0、probability=100、value_region=1、key_region=6、value_type=0。只有用户明确要求更深扫描时才改 depth。',
|
|
1501
|
-
'2. profile:`desc` 完整单文件 HTML。硬约束:地图/全景/立绘/插画必须用 `image_asset` 产图,不得用 CSS 或手写 SVG 拼替代品;透明人物立绘走 Recraft、其余位图走 Seedream;轮播类交互必须首尾循环;界面文案面向玩家,禁止复述需求或数据来源;抽取库条目必须含名称与效果,不许空壳条目;重新随机必须重抽所有未锁定字段,不得残留上一次的选中值或「未知」。**跨部分边界:desc 只做初始化页 iframe 内控件;平台聊天原生输入/发送按钮/消息气泡归第三部分,不得在 desc 里新建聊天输入替代它。**若需求是“终端风格输入栏”,只在第三部分 built_in_css 改原生输入;desc
|
|
1559
|
+
'2. profile:`desc` 完整单文件 HTML。硬约束:地图/全景/立绘/插画必须用 `image_asset` 产图,不得用 CSS 或手写 SVG 拼替代品;透明人物立绘走 Recraft、其余位图走 Seedream;轮播类交互必须首尾循环;界面文案面向玩家,禁止复述需求或数据来源;抽取库条目必须含名称与效果,不许空壳条目;重新随机必须重抽所有未锁定字段,不得残留上一次的选中值或「未知」。**跨部分边界:desc 只做初始化页 iframe 内控件;平台聊天原生输入/发送按钮/消息气泡归第三部分,不得在 desc 里新建聊天输入替代它。**若需求是“终端风格输入栏”,只在第三部分 built_in_css 改原生输入;desc 里只能做展示或复制,不能发送到聊天。**平台环境(docs/2 §2.9.5 与 4.4):容器宽约 1000/1240/1415、高约 484,外观按这三档设计并监听尺寸变化重算布局;外层页面无滚动条,超长内容由卡内滚动区承担;无保存接口,前端状态只放内存(刷新/重进即失属预期);无 allow-modals,禁止 alert/confirm/prompt。**',
|
|
1502
1560
|
'复制按钮(`desc` 内,见 档案页 §3.6.1,2026-11-16 平台实测):只能走 `document.execCommand("copy")`——首选临时 textarea(fixed 移出视口、readonly、复制后移除),失败再用选中页面可见文本;禁止 `navigator.clipboard`(writeText / write / ClipboardItem)与 `window.clipboardData` 作主路径或兜底,它们在平台 iframe 里必然失败。复制必须在点击处理函数同步栈内执行(先 await / 先请求再复制会失效);成功/失败以 execCommand 返回值为准,不得点后固定显示“已复制”;失败要给可选中的文本让玩家手动复制。',
|
|
1503
1561
|
'动态几何(见 档案页 §2.11):图像上的点位必须相对图像内容框定位,图片与点位同处一个变换容器(transform 不得只加在 img 上);位移只能由布局尺寸推导,禁止用 getBoundingClientRect 反推已变换坐标;循环轮播的瞬移复位要等动画结束(transitionend 或同源时长);受约束控件钳制后回写控件本身并动态更新 max,约束收紧时回写当前值;拖拽用 pointerdown/move/up(move/up 挂 window),8px 阈值区分点击与拖动,容器声明 touch-action,拖动期间关 transition。',
|
|
1504
1562
|
'3. chat:`built_in_css` 与 `rgx_rep`。每条正则:`scope` 省略即 1(USER),要 AI=2 / GLOBAL=10 才显式写;`is_enable` 必填;`match_regex` 与 `replace_text` 配对,`replace_text` 允许空字符串;`is_only_render` 按需。',
|
package/lib/avatar.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
|
|
50
|
+
if (hasPlayer) findings.push('已覆盖玩家头像位');
|
|
51
|
+
if (hasAnswer) findings.push('已覆盖 AI 头像位');
|
|
52
|
+
if (hasSwitch) findings.push('已使用 :has([data-c]) 多角色切换');
|
|
53
|
+
if (hasMark) findings.push('已输出或隐藏 data-who 标记');
|
|
54
|
+
if (hasImgTransparent) findings.push('头像位内部 img 已透明');
|
|
55
|
+
|
|
56
|
+
if (!hasPlayer) suggestions.push('玩家头像固定:用 #customized-question-avatar 背景图覆盖,不依赖 AI');
|
|
57
|
+
if (!hasAnswer) suggestions.push('单角色 AI 头像固定:用 #customized-answer-avatar 背景图覆盖');
|
|
58
|
+
if (!hasSwitch && hasMark) suggestions.push('已有 data-who 标记,但缺少 :has([data-c]) 切换规则');
|
|
59
|
+
if (hasSwitch && !hasMark) suggestions.push('已有切换规则,但提示词里缺少 data-who 标记输出要求');
|
|
60
|
+
if ((hasPlayer || hasAnswer) && !hasImgTransparent) suggestions.push('覆盖头像位时需同时让内部 img 透明(opacity:0),否则旧头像会透出');
|
|
61
|
+
if (!suggestions.length && (hasPlayer || hasAnswer)) suggestions.push('实现符合规范:固定头像不依赖 AI,多角色切换用 data-c');
|
|
62
|
+
|
|
63
|
+
return { findings, suggestions, flags: { hasPlayer, hasAnswer, hasSwitch, hasMark, hasImgTransparent } };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 纯净操作指南(面向玩家/写卡者,不含测试内容) */
|
|
67
|
+
export function avatarGuide() {
|
|
68
|
+
return [
|
|
69
|
+
'# 头像与图像呈现 · 操作指南',
|
|
70
|
+
'',
|
|
71
|
+
'## 适用场景',
|
|
72
|
+
'用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时使用本指南。',
|
|
73
|
+
'',
|
|
74
|
+
'## 一、先判断需求属于哪类',
|
|
75
|
+
'',
|
|
76
|
+
'| 需求 | 做法 | 依赖 AI |',
|
|
77
|
+
'|---|---|---|',
|
|
78
|
+
'| 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |',
|
|
79
|
+
'| 多角色随说话人切换 | AI 输出 data-who 标记 + CSS :has 查表 | 是 |',
|
|
80
|
+
'| 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |',
|
|
81
|
+
'',
|
|
82
|
+
'## 二、固定头像(最可靠,首选)',
|
|
83
|
+
'',
|
|
84
|
+
'```css',
|
|
85
|
+
'/* 玩家头像 */',
|
|
86
|
+
'#customized-question-avatar{',
|
|
87
|
+
' background-image:url("玩家头像.png") !important;',
|
|
88
|
+
' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
|
|
89
|
+
'}',
|
|
90
|
+
'#customized-question-avatar img{opacity:0 !important;}',
|
|
91
|
+
'',
|
|
92
|
+
'/* AI 头像(单角色) */',
|
|
93
|
+
'#customized-answer-avatar{',
|
|
94
|
+
' background-image:url("AI头像.png") !important;',
|
|
95
|
+
' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
|
|
96
|
+
'}',
|
|
97
|
+
'#customized-answer-avatar img{opacity:0 !important;}',
|
|
98
|
+
'```',
|
|
99
|
+
'',
|
|
100
|
+
'要点:容器设背景图,内部 img 透明;只改其一会出现旧图透出或布局跳动。',
|
|
101
|
+
'',
|
|
102
|
+
'## 三、多角色头像切换',
|
|
103
|
+
'',
|
|
104
|
+
'1. 在输出格式里要求 AI 每条消息前输出隐藏标记:',
|
|
105
|
+
'',
|
|
106
|
+
'```html',
|
|
107
|
+
'<span data-who data-c="角色标准名"></span>',
|
|
108
|
+
'```',
|
|
109
|
+
'',
|
|
110
|
+
'2. CSS 里隐藏标记并按角色切换:',
|
|
111
|
+
'',
|
|
112
|
+
'```css',
|
|
113
|
+
'#customized-answer [data-who]{ display:none !important; }',
|
|
114
|
+
'#customized-answer:has([data-c="角色A"]) #customized-answer-avatar{ background-image:url("A.png") !important; }',
|
|
115
|
+
'#customized-answer:has([data-c="角色B"]) #customized-answer-avatar{ background-image:url("B.png") !important; }',
|
|
116
|
+
'```',
|
|
117
|
+
'',
|
|
118
|
+
'规则:',
|
|
119
|
+
'- data-c 必须与角色档案、状态栏、世界书的角色名逐字一致;',
|
|
120
|
+
'- 必须保留默认头像(未命中标记时回落);',
|
|
121
|
+
'- 玩家自己的消息不输出标记;',
|
|
122
|
+
'- 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。',
|
|
123
|
+
'',
|
|
124
|
+
'## 四、玩家自定义换图',
|
|
125
|
+
'',
|
|
126
|
+
'1. 玩家把图片上传到图床,拿到直链;',
|
|
127
|
+
'2. 在卡前端或本工具生成 CSS;',
|
|
128
|
+
'3. 复制 CSS,粘贴到平台的「**自定义配置里的内置 CSS**」,保存;',
|
|
129
|
+
'4. 回到聊天页刷新查看。',
|
|
130
|
+
'',
|
|
131
|
+
'前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。',
|
|
132
|
+
'',
|
|
133
|
+
'## 五、验收清单',
|
|
134
|
+
'',
|
|
135
|
+
'- 玩家头像打开即显示,AI 漏写不受影响;',
|
|
136
|
+
'- 单角色 AI 头像固定显示;',
|
|
137
|
+
'- 多角色消息头像各自切换,未命中时回落默认;',
|
|
138
|
+
'- data-who 标记在正文里不可见;',
|
|
139
|
+
'- 覆盖后平台其它 UI(按钮、输入框)未受影响。',
|
|
140
|
+
].join('\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 工具动作分发 */
|
|
144
|
+
export function avatarAction(args = {}) {
|
|
145
|
+
const action = String(args.action || 'guide');
|
|
146
|
+
if (action === 'guide') return { action, guide: avatarGuide() };
|
|
147
|
+
if (action === 'css') {
|
|
148
|
+
const css = buildAvatarCss({ player: args.player_url || '', npc: args.npc || [] });
|
|
149
|
+
return { action, css, note: css ? '复制到「自定义配置里的内置 CSS」' : '未提供图片地址' };
|
|
150
|
+
}
|
|
151
|
+
if (action === 'check') {
|
|
152
|
+
const result = checkAvatarCard({ built_in_css: args.built_in_css || '', pre_prompt: args.pre_prompt || '' });
|
|
153
|
+
return { action, ...result };
|
|
154
|
+
}
|
|
155
|
+
throw new Error(`未知动作:${action}(可用:${AVATAR_ACTIONS.join(' / ')})`);
|
|
156
|
+
}
|