Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 418783069b | |||
| 098ecee594 | |||
| 6a8407da48 | |||
| b87b2cad73 | |||
| 6a420983f7 | |||
| 30b52b5d73 |
@@ -62,7 +62,7 @@ http://localhost:8848/
|
|||||||
├── src/ # 前端源码
|
├── src/ # 前端源码
|
||||||
│ ├── api/ # HTTP API 封装,业务接口集中在 access.ts
|
│ ├── api/ # HTTP API 封装,业务接口集中在 access.ts
|
||||||
│ ├── assets/ # 图片、SVG、iconfont 等静态资源
|
│ ├── assets/ # 图片、SVG、iconfont 等静态资源
|
||||||
│ ├── components/ # 通用组件,DigitalMessageText.vue 提供对白/叙述预览与聊天记录展示
|
│ ├── components/ # 模板沉淀的通用组件
|
||||||
│ ├── config/ # 读取 public/platform-config.json 的运行时配置
|
│ ├── config/ # 读取 public/platform-config.json 的运行时配置
|
||||||
│ ├── directives/ # 自定义指令,如权限、复制、长按、波纹
|
│ ├── directives/ # 自定义指令,如权限、复制、长按、波纹
|
||||||
│ ├── layout/ # 后台布局、菜单、标签页、导航栏与布局 hooks
|
│ ├── layout/ # 后台布局、菜单、标签页、导航栏与布局 hooks
|
||||||
@@ -70,12 +70,11 @@ http://localhost:8848/
|
|||||||
│ ├── router/ # 静态路由、剩余路由、路由实例与守卫
|
│ ├── router/ # 静态路由、剩余路由、路由实例与守卫
|
||||||
│ ├── store/ # Pinia store,含用户、权限、标签页、主题等模块
|
│ ├── store/ # Pinia store,含用户、权限、标签页、主题等模块
|
||||||
│ ├── style/ # 全局样式、主题、暗色模式、侧边栏和过渡样式
|
│ ├── style/ # 全局样式、主题、暗色模式、侧边栏和过渡样式
|
||||||
│ ├── utils/ # 鉴权、HTTP、缓存及 digital-message-format.ts 受限文本解析
|
│ ├── utils/ # 鉴权、HTTP、缓存、消息、进度条、树处理等工具
|
||||||
│ └── views/
|
│ └── views/
|
||||||
│ ├── digital/ # 内容库、实验类型、测试方案和用户分组
|
│ ├── digital/ # 内容库、实验类型、测试方案和用户分组
|
||||||
│ └── ... # 原门店与员工业务兼容页面
|
│ └── ... # 原门店与员工业务兼容页面
|
||||||
├── types/ # 全局类型声明、组件声明、路由声明和 Vue shim
|
├── types/ # 全局类型声明、组件声明、路由声明和 Vue shim
|
||||||
├── tests/ # 数字人对白/叙述格式回归,与 role-user 使用相同用例
|
|
||||||
├── AGENTS.md # Codex/Agent 入口规则,转到 RTK.md 并登记本地 skill
|
├── AGENTS.md # Codex/Agent 入口规则,转到 RTK.md 并登记本地 skill
|
||||||
├── RTK.md # 本仓库协作规则与 README 同步要求
|
├── RTK.md # 本仓库协作规则与 README 同步要求
|
||||||
├── Dockerfile # 容器构建入口
|
├── Dockerfile # 容器构建入口
|
||||||
@@ -215,10 +214,6 @@ pnpm build
|
|||||||
|
|
||||||
## 数字人运营
|
## 数字人运营
|
||||||
|
|
||||||
角色「人格与开场」提供对白/叙述格式说明和首次问候、示例对白、其他开场的实时预览,预览替换角色/用户占位符但不修改原文。生成预设始终遵守系统统一排版:`*叙述*` 与 `“对白”`,切换时空一行。用户管理的聊天记录也使用 `DigitalMessageText.vue`,用户原文保持纯文本,角色消息兼容旧括号与引号。
|
|
||||||
|
|
||||||
`src/utils/digital-message-format.ts` 与 `role-user/src/lib/digital-message-format.ts` 保持同一实现和用例,两仓独立构建。所有内容通过文本节点展示,不使用 HTML 注入。执行 `node --experimental-strip-types --test tests/*.test.mjs` 验证协议兼容。
|
|
||||||
|
|
||||||
- `src/views/digital/content.vue`:角色卡、世界书、预设,草稿/发布/下架,JSON 导入导出。
|
- `src/views/digital/content.vue`:角色卡、世界书、预设,草稿/发布/下架,JSON 导入导出。
|
||||||
- `src/views/digital/experiments.vue`:测试方案的类型选择、A/B 返回值、百分比、人群、生命周期、效果和审计。
|
- `src/views/digital/experiments.vue`:测试方案的类型选择、A/B 返回值、百分比、人群、生命周期、效果和审计。
|
||||||
- `src/views/digital/experiment-types.vue`:类型创建、默认值契约、来源、调用示例与接入验收。
|
- `src/views/digital/experiment-types.vue`:类型创建、默认值契约、来源、调用示例与接入验收。
|
||||||
@@ -258,5 +253,3 @@ pnpm build
|
|||||||
`src/views/digital/users.vue` 对应 `/digital/users`,用于创建独立 C 端账号、搜索用户、修改昵称/状态、重置密码,以及按用户查看数字人会话和原始消息。账号由后台开通,无公开注册;与管理员/员工账号分别鉴权,重置 C 端密码不影响后台。停用保留聊天记录。
|
`src/views/digital/users.vue` 对应 `/digital/users`,用于创建独立 C 端账号、搜索用户、修改昵称/状态、重置密码,以及按用户查看数字人会话和原始消息。账号由后台开通,无公开注册;与管理员/员工账号分别鉴权,重置 C 端密码不影响后台。停用保留聊天记录。
|
||||||
|
|
||||||
`src/api/access.ts` 定义 C 端用户、会话和消息响应类型。消息记录第1页为最新内容,每页按发送顺序展示,支持刷新、分页和生成状态查看。原实验账号页面 `/digital/experiment-users` 更名为「实验用户分组」,只针对 C 端用户配置实验。
|
`src/api/access.ts` 定义 C 端用户、会话和消息响应类型。消息记录第1页为最新内容,每页按发送顺序展示,支持刷新、分页和生成状态查看。原实验账号页面 `/digital/experiment-users` 更名为「实验用户分组」,只针对 C 端用户配置实验。
|
||||||
|
|
||||||
用户列表展示账号的 NSFW 开关;创建用户默认开启,编辑用户可单独开启或关闭。与前台「我的」读取和修改同一份服务端账号偏好,不覆盖收藏、称呼或身份背景。已有账号未保存该字段时默认开启,游客的登录限制不变;需与 `access-manage` 配套发布。
|
|
||||||
|
|||||||
@@ -1232,8 +1232,6 @@ export type DigitalUser = {
|
|||||||
username: string;
|
username: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
status: "ACTIVE" | "INACTIVE";
|
status: "ACTIVE" | "INACTIVE";
|
||||||
/** 账号未保存内容偏好时默认开启,后端在生成时读取实际值。 */
|
|
||||||
nsfwEnabled?: boolean;
|
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
lastLoginAt: string | null;
|
lastLoginAt: string | null;
|
||||||
conversations: number;
|
conversations: number;
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
/** 角色编辑预览与聊天记录共用的受限文本展示,用户消息和 HTML 字面量均不作为标签解释。 */
|
|
||||||
import { computed } from "vue";
|
|
||||||
import { parseDigitalMessage } from "@/utils/digital-message-format";
|
|
||||||
|
|
||||||
const props = withDefaults(
|
|
||||||
defineProps<{
|
|
||||||
text: string;
|
|
||||||
role?: "assistant" | "user";
|
|
||||||
incomplete?: boolean;
|
|
||||||
}>(),
|
|
||||||
{ role: "assistant", incomplete: false }
|
|
||||||
);
|
|
||||||
const blocks = computed(() =>
|
|
||||||
parseDigitalMessage(props.text, props.incomplete)
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div
|
|
||||||
class="digital-message-text"
|
|
||||||
:class="{ 'is-prose': role === 'assistant' }"
|
|
||||||
>
|
|
||||||
<template v-if="role === 'assistant' && blocks.length">
|
|
||||||
<p
|
|
||||||
v-for="(block, index) in blocks"
|
|
||||||
:key="index"
|
|
||||||
:class="[
|
|
||||||
block.kind,
|
|
||||||
{
|
|
||||||
'is-latin':
|
|
||||||
/[A-Za-z]/.test(block.text) && !/[\u3400-\u9fff]/.test(block.text)
|
|
||||||
}
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<strong v-if="block.kind === 'dialogue'">{{ block.text }}</strong>
|
|
||||||
<template v-else>{{ block.text }}</template>
|
|
||||||
</p>
|
|
||||||
</template>
|
|
||||||
<template v-else>{{ text || "(未生成正文)" }}</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.digital-message-text {
|
|
||||||
line-height: 1.9;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.is-prose {
|
|
||||||
white-space: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.is-prose > p {
|
|
||||||
margin: 0;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.is-prose > p + p {
|
|
||||||
margin-top: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialogue {
|
|
||||||
color: var(--digital-dialogue-ink, var(--el-text-color-primary));
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialogue strong {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.narration {
|
|
||||||
color: var(--digital-narration-ink, var(--el-text-color-regular));
|
|
||||||
}
|
|
||||||
|
|
||||||
.narration.is-latin {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
/** 数字人消息的受限文本格式:对白、故事叙述与旧版括号;始终返回文本,不解释 HTML。 */
|
|
||||||
|
|
||||||
/** 有序展示片段;原始 content 继续用于存储、复制、记忆和上下文。 */
|
|
||||||
export type DigitalMessageBlock = {
|
|
||||||
kind: "dialogue" | "narration" | "plain";
|
|
||||||
text: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const quotePairs: Record<string, string> = {
|
|
||||||
'"': '"',
|
|
||||||
"“": "”",
|
|
||||||
"「": "」",
|
|
||||||
"『": "』",
|
|
||||||
"«": "»",
|
|
||||||
""": """
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 跳过转义字符;引号不跨行,括号按同类型嵌套匹配,避免误吞后续内容。 */
|
|
||||||
function closingIndex(
|
|
||||||
text: string,
|
|
||||||
from: number,
|
|
||||||
open: string,
|
|
||||||
close: string,
|
|
||||||
nested = false
|
|
||||||
) {
|
|
||||||
let depth = 1;
|
|
||||||
for (let i = from; i < text.length; i++) {
|
|
||||||
if (text[i] === "\\") {
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!nested && quotePairs[open] && text[i] === "\n") return -1;
|
|
||||||
if (nested && text.startsWith(open, i)) depth++;
|
|
||||||
if (text.startsWith(close, i)) {
|
|
||||||
depth--;
|
|
||||||
if (depth === 0) return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 星号需要处于词边界,避免把乘法、文件名或普通单词里的星号视为排版。 */
|
|
||||||
function markerBoundary(text: string, index: number) {
|
|
||||||
return (
|
|
||||||
index === 0 || /[\s。!?!?,,;;::))\]”"」』»]/u.test(text[index - 1])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析累计正文而非单个 SSE delta。未闭合标记仅在流式/中断展示时延续当前样式;
|
|
||||||
* 旧版括号外文本按对白处理,有引号的旧开场白将引号外文字作为叙述,其他纯文本保留。
|
|
||||||
* 与 role-user/src/lib/digital-message-format.ts 保持同一实现和用例,独立构建时无需跨仓引用。
|
|
||||||
*/
|
|
||||||
export function parseDigitalMessage(
|
|
||||||
source: string,
|
|
||||||
streaming = false
|
|
||||||
): DigitalMessageBlock[] {
|
|
||||||
const blocks: DigitalMessageBlock[] = [];
|
|
||||||
for (const paragraph of source.replace(/\r\n?/g, "\n").split(/\n\s*\n/)) {
|
|
||||||
const parts: DigitalMessageBlock[] = [];
|
|
||||||
let legacyNarration = false;
|
|
||||||
const push = (kind: DigitalMessageBlock["kind"], text: string) => {
|
|
||||||
if (!text) return;
|
|
||||||
const last = parts[parts.length - 1];
|
|
||||||
if (last?.kind === kind) last.text += text;
|
|
||||||
else parts.push({ kind, text });
|
|
||||||
};
|
|
||||||
for (let i = 0; i < paragraph.length; ) {
|
|
||||||
const char = paragraph[i];
|
|
||||||
if (
|
|
||||||
char === "\\" &&
|
|
||||||
/[*"\\()()“”「」『』]/u.test(paragraph[i + 1] ?? "")
|
|
||||||
) {
|
|
||||||
push("plain", paragraph[i + 1]);
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const quoteEnd = quotePairs[char];
|
|
||||||
if (quoteEnd) {
|
|
||||||
const close = closingIndex(paragraph, i + 1, char, quoteEnd);
|
|
||||||
const lineEnd = paragraph.indexOf("\n", i + 1);
|
|
||||||
const end =
|
|
||||||
close >= 0 ? close + 1 : lineEnd >= 0 ? lineEnd : paragraph.length;
|
|
||||||
push("dialogue", paragraph.slice(i, end));
|
|
||||||
i = end;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
char === "*" &&
|
|
||||||
markerBoundary(paragraph, i) &&
|
|
||||||
!/\s/u.test(paragraph[i + 1] ?? "")
|
|
||||||
) {
|
|
||||||
const marker = paragraph.startsWith("**", i) ? "**" : "*";
|
|
||||||
const close = closingIndex(
|
|
||||||
paragraph,
|
|
||||||
i + marker.length,
|
|
||||||
marker,
|
|
||||||
marker
|
|
||||||
);
|
|
||||||
if (close >= 0 || streaming) {
|
|
||||||
push(
|
|
||||||
marker === "**" ? "dialogue" : "narration",
|
|
||||||
paragraph.slice(i + marker.length, close >= 0 ? close : undefined)
|
|
||||||
);
|
|
||||||
i = close >= 0 ? close + marker.length : paragraph.length;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 格式不完整的历史正文原样保留,不猜测后面的哪些字符属于标记。
|
|
||||||
push("plain", paragraph.slice(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((char === "(" || char === "(") && markerBoundary(paragraph, i)) {
|
|
||||||
const close = closingIndex(
|
|
||||||
paragraph,
|
|
||||||
i + 1,
|
|
||||||
char,
|
|
||||||
char === "(" ? ")" : ")",
|
|
||||||
true
|
|
||||||
);
|
|
||||||
if (close >= 0 || streaming) {
|
|
||||||
legacyNarration = true;
|
|
||||||
push(
|
|
||||||
"narration",
|
|
||||||
paragraph.slice(i + 1, close >= 0 ? close : undefined)
|
|
||||||
);
|
|
||||||
i = close >= 0 ? close + 1 : paragraph.length;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
push("plain", paragraph.slice(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
push("plain", char);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
const hasDialogue = parts.some(part => part.kind === "dialogue");
|
|
||||||
for (const part of parts) {
|
|
||||||
const kind =
|
|
||||||
part.kind !== "plain"
|
|
||||||
? part.kind
|
|
||||||
: legacyNarration
|
|
||||||
? "dialogue"
|
|
||||||
: hasDialogue
|
|
||||||
? "narration"
|
|
||||||
: "plain";
|
|
||||||
for (const line of part.text.split(/\n+/)) {
|
|
||||||
if (line.trim()) blocks.push({ kind, text: line.trim() });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 数字人内容库:角色、世界书、预设分别编辑,开场与示例使用聊天格式实时预览。 */
|
/** 数字人内容库:角色、世界书、叙事预设分别编辑,发布状态显式可见。 */
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { digital, type Content, type Entry } from "@/api/access";
|
import { digital, type Content, type Entry } from "@/api/access";
|
||||||
import DigitalMessageText from "@/components/DigitalMessageText.vue";
|
|
||||||
const contents = ref<Content[]>([]),
|
const contents = ref<Content[]>([]),
|
||||||
kind = ref("character"),
|
kind = ref("character"),
|
||||||
query = ref(""),
|
query = ref(""),
|
||||||
@@ -30,12 +29,6 @@ const statusNames: Record<string, string> = {
|
|||||||
published: "已发布",
|
published: "已发布",
|
||||||
archived: "已下架"
|
archived: "已下架"
|
||||||
};
|
};
|
||||||
/** 占位符仅用于当前预览,不改写编辑内容或数据库中的角色模板。 */
|
|
||||||
function previewText(value: string) {
|
|
||||||
return value
|
|
||||||
.replaceAll("{{char}}", edit.value?.name || "角色")
|
|
||||||
.replaceAll("{{user}}", "旅人");
|
|
||||||
}
|
|
||||||
const books = computed(() =>
|
const books = computed(() =>
|
||||||
contents.value.filter(c => c.kind === "worldbook" && c.status === "published")
|
contents.value.filter(c => c.kind === "worldbook" && c.status === "published")
|
||||||
);
|
);
|
||||||
@@ -330,12 +323,7 @@ onMounted(load);
|
|||||||
v-if="edit.kind === 'character'"
|
v-if="edit.kind === 'character'"
|
||||||
label="人格与开场"
|
label="人格与开场"
|
||||||
name="persona"
|
name="persona"
|
||||||
><el-alert
|
><el-form-item label="性格、背景和关系"
|
||||||
class="format-guide"
|
|
||||||
title="对白与叙述分段书写"
|
|
||||||
description="对白使用成对引号,如:“你来了。”;动作、神态、心理和环境用单星号包裹,如:*她合上书,抬头微笑。*。切换时空一行,下方预览与聊天使用相同的格式规则。"
|
|
||||||
:closable="false"
|
|
||||||
/><el-form-item label="性格、背景和关系"
|
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.personality"
|
v-model="edit.body.personality"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
@@ -346,36 +334,15 @@ onMounted(load);
|
|||||||
type="textarea"
|
type="textarea"
|
||||||
:rows="3" /></el-form-item
|
:rows="3" /></el-form-item
|
||||||
><el-form-item label="首次问候(支持 {{char}} / {{user}} 占位符)"
|
><el-form-item label="首次问候(支持 {{char}} / {{user}} 占位符)"
|
||||||
><div class="format-editor">
|
><el-input
|
||||||
<el-input
|
v-model="edit.body.greeting"
|
||||||
v-model="edit.body.greeting"
|
type="textarea"
|
||||||
type="textarea"
|
:rows="4" /></el-form-item
|
||||||
:rows="4"
|
|
||||||
placeholder="*她合上书,抬头看向你。* “你来了。”"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-if="edit.body.greeting.trim()"
|
|
||||||
class="format-preview"
|
|
||||||
aria-label="首次问候展示预览"
|
|
||||||
>
|
|
||||||
<small>首次问候 · 展示效果</small>
|
|
||||||
<DigitalMessageText :text="previewText(edit.body.greeting)" />
|
|
||||||
</div></div></el-form-item
|
|
||||||
><el-form-item label="示例对白"
|
><el-form-item label="示例对白"
|
||||||
><div class="format-editor">
|
><el-input
|
||||||
<el-input
|
v-model="edit.body.examples"
|
||||||
v-model="edit.body.examples"
|
type="textarea"
|
||||||
type="textarea"
|
:rows="4" /></el-form-item
|
||||||
:rows="4"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-if="edit.body.examples.trim()"
|
|
||||||
class="format-preview"
|
|
||||||
aria-label="示例对白展示预览"
|
|
||||||
>
|
|
||||||
<small>示例对白 · 展示效果</small>
|
|
||||||
<DigitalMessageText :text="previewText(edit.body.examples)" />
|
|
||||||
</div></div></el-form-item
|
|
||||||
><el-form-item label="角色系统指令"
|
><el-form-item label="角色系统指令"
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.systemPrompt"
|
v-model="edit.body.systemPrompt"
|
||||||
@@ -388,24 +355,12 @@ onMounted(load);
|
|||||||
:key="i"
|
:key="i"
|
||||||
class="entry-row"
|
class="entry-row"
|
||||||
>
|
>
|
||||||
<div class="format-editor">
|
<el-input
|
||||||
<el-input
|
v-model="edit.body.alternateGreetings[i]"
|
||||||
v-model="edit.body.alternateGreetings[i]"
|
type="textarea"
|
||||||
type="textarea"
|
:rows="2"
|
||||||
:rows="2"
|
/><el-button
|
||||||
/>
|
@click="edit.body.alternateGreetings.splice(i, 1)"
|
||||||
<div
|
|
||||||
v-if="edit.body.alternateGreetings[i].trim()"
|
|
||||||
class="format-preview"
|
|
||||||
:aria-label="`其他开场 ${i + 1} 展示预览`"
|
|
||||||
>
|
|
||||||
<small>其他开场 {{ i + 1 }} · 展示效果</small>
|
|
||||||
<DigitalMessageText
|
|
||||||
:text="previewText(edit.body.alternateGreetings[i])"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<el-button @click="edit.body.alternateGreetings.splice(i, 1)"
|
|
||||||
>移除</el-button
|
>移除</el-button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -510,11 +465,7 @@ onMounted(load);
|
|||||||
v-if="edit.kind === 'preset'"
|
v-if="edit.kind === 'preset'"
|
||||||
label="生成编排"
|
label="生成编排"
|
||||||
name="generation"
|
name="generation"
|
||||||
><el-alert
|
><el-form-item label="系统指令"
|
||||||
class="format-guide"
|
|
||||||
title="系统统一区分对白和叙述"
|
|
||||||
description="本页设置叙事风格;对白使用引号、叙述使用单星号并分段的排版规则始终生效,发送、继续与重新生成共用。"
|
|
||||||
:closable="false" /><el-form-item label="系统指令"
|
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.systemPrompt"
|
v-model="edit.body.systemPrompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
@@ -561,37 +512,6 @@ onMounted(load);
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.format-guide {
|
|
||||||
margin-bottom: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.format-editor {
|
|
||||||
width: 100%;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.format-preview {
|
|
||||||
--digital-dialogue-ink: #fff5fc;
|
|
||||||
--digital-narration-ink: #c2b6c4;
|
|
||||||
|
|
||||||
max-height: 300px;
|
|
||||||
padding: 14px 18px;
|
|
||||||
margin-top: 10px;
|
|
||||||
overflow: auto;
|
|
||||||
font-size: 14px;
|
|
||||||
color: #e6dfe7;
|
|
||||||
background: #211c23;
|
|
||||||
border: 1px solid #ffffff12;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.format-preview > small {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
font-size: 11px;
|
|
||||||
color: #b5a6b8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
|
|||||||
+11
-61
@@ -1,8 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 独立 C 端用户管理:开户、内容偏好、停用、改密与区分对白/叙述的持久化聊天记录。 */
|
/** 独立 C 端用户管理:开户、停用、重置密码及按用户查看持久化聊天记录。 */
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import DigitalMessageText from "@/components/DigitalMessageText.vue";
|
|
||||||
import {
|
import {
|
||||||
digital,
|
digital,
|
||||||
type DigitalUser,
|
type DigitalUser,
|
||||||
@@ -17,14 +16,9 @@ const q = ref(""),
|
|||||||
users = ref<DigitalUser[]>([]);
|
users = ref<DigitalUser[]>([]);
|
||||||
const creating = ref(false),
|
const creating = ref(false),
|
||||||
saving = ref(false),
|
saving = ref(false),
|
||||||
createForm = ref({
|
createForm = ref({ username: "", displayName: "", password: "" });
|
||||||
username: "",
|
|
||||||
displayName: "",
|
|
||||||
password: "",
|
|
||||||
nsfwEnabled: true
|
|
||||||
});
|
|
||||||
const editing = ref<DigitalUser | null>(null),
|
const editing = ref<DigitalUser | null>(null),
|
||||||
editForm = ref({ displayName: "", status: "ACTIVE", nsfwEnabled: true });
|
editForm = ref({ displayName: "", status: "ACTIVE" });
|
||||||
const resetTarget = ref<DigitalUser | null>(null),
|
const resetTarget = ref<DigitalUser | null>(null),
|
||||||
newPassword = ref("");
|
newPassword = ref("");
|
||||||
const selected = ref<DigitalUser | null>(null),
|
const selected = ref<DigitalUser | null>(null),
|
||||||
@@ -89,12 +83,7 @@ async function create() {
|
|||||||
try {
|
try {
|
||||||
await digital("users", "post", createForm.value);
|
await digital("users", "post", createForm.value);
|
||||||
creating.value = false;
|
creating.value = false;
|
||||||
createForm.value = {
|
createForm.value = { username: "", displayName: "", password: "" };
|
||||||
username: "",
|
|
||||||
displayName: "",
|
|
||||||
password: "",
|
|
||||||
nsfwEnabled: true
|
|
||||||
};
|
|
||||||
search();
|
search();
|
||||||
ElMessage.success("C 端账号已创建,可在星港前台登录");
|
ElMessage.success("C 端账号已创建,可在星港前台登录");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -105,11 +94,7 @@ async function create() {
|
|||||||
}
|
}
|
||||||
function edit(user: DigitalUser) {
|
function edit(user: DigitalUser) {
|
||||||
editing.value = user;
|
editing.value = user;
|
||||||
editForm.value = {
|
editForm.value = { displayName: user.displayName, status: user.status };
|
||||||
displayName: user.displayName,
|
|
||||||
status: user.status,
|
|
||||||
nsfwEnabled: user.nsfwEnabled ?? true
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
async function saveEdit() {
|
async function saveEdit() {
|
||||||
if (!editing.value) return;
|
if (!editing.value) return;
|
||||||
@@ -215,12 +200,7 @@ onMounted(load);
|
|||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="
|
@click="
|
||||||
createForm = {
|
createForm = { username: '', displayName: '', password: '' };
|
||||||
username: '',
|
|
||||||
displayName: '',
|
|
||||||
password: '',
|
|
||||||
nsfwEnabled: true
|
|
||||||
};
|
|
||||||
creating = true;
|
creating = true;
|
||||||
"
|
"
|
||||||
>创建 C 端用户</el-button
|
>创建 C 端用户</el-button
|
||||||
@@ -261,12 +241,6 @@ onMounted(load);
|
|||||||
row.status === "ACTIVE" ? "正常" : "已停用"
|
row.status === "ACTIVE" ? "正常" : "已停用"
|
||||||
}}</el-tag></template
|
}}</el-tag></template
|
||||||
></el-table-column
|
></el-table-column
|
||||||
><el-table-column label="NSFW" width="100"
|
|
||||||
><template #default="{ row }"
|
|
||||||
><el-tag :type="row.nsfwEnabled === false ? 'info' : 'success'">{{
|
|
||||||
row.nsfwEnabled === false ? "已关闭" : "已开启"
|
|
||||||
}}</el-tag></template
|
|
||||||
></el-table-column
|
|
||||||
><el-table-column
|
><el-table-column
|
||||||
prop="conversations"
|
prop="conversations"
|
||||||
label="会话数"
|
label="会话数"
|
||||||
@@ -331,17 +305,7 @@ onMounted(load);
|
|||||||
show-password
|
show-password
|
||||||
maxlength="128"
|
maxlength="128"
|
||||||
placeholder="至少8位"
|
placeholder="至少8位"
|
||||||
autocomplete="new-password" /></el-form-item
|
autocomplete="new-password" /></el-form-item></el-form
|
||||||
><el-form-item label="NSFW 成人内容"
|
|
||||||
><el-switch
|
|
||||||
v-model="createForm.nsfwEnabled"
|
|
||||||
active-text="开启"
|
|
||||||
inactive-text="关闭"
|
|
||||||
/>
|
|
||||||
<p class="secondary">
|
|
||||||
登录账号默认开启,用户可在前台保存自己的选择。
|
|
||||||
</p>
|
|
||||||
</el-form-item></el-form
|
|
||||||
><template #footer
|
><template #footer
|
||||||
><el-button @click="creating = false">取消</el-button
|
><el-button @click="creating = false">取消</el-button
|
||||||
><el-button type="primary" :loading="saving" @click="create"
|
><el-button type="primary" :loading="saving" @click="create"
|
||||||
@@ -365,14 +329,7 @@ onMounted(load);
|
|||||||
><el-radio value="ACTIVE">正常</el-radio
|
><el-radio value="ACTIVE">正常</el-radio
|
||||||
><el-radio value="INACTIVE">停用</el-radio></el-radio-group
|
><el-radio value="INACTIVE">停用</el-radio></el-radio-group
|
||||||
></el-form-item
|
></el-form-item
|
||||||
><el-form-item label="NSFW 成人内容"
|
></el-form
|
||||||
><el-switch
|
|
||||||
v-model="editForm.nsfwEnabled"
|
|
||||||
active-text="开启"
|
|
||||||
inactive-text="关闭"
|
|
||||||
/>
|
|
||||||
<p class="secondary">保存后用于该账号的后续回复。</p>
|
|
||||||
</el-form-item></el-form
|
|
||||||
><el-alert
|
><el-alert
|
||||||
title="停用后用户无法登录,已有会话记录仍保留。"
|
title="停用后用户无法登录,已有会话记录仍保留。"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
@@ -478,14 +435,7 @@ onMounted(load);
|
|||||||
>{{ states[m.status] ?? m.status }}</el-tag
|
>{{ states[m.status] ?? m.status }}</el-tag
|
||||||
><el-tag v-if="m.pinned" size="small">已固定</el-tag>
|
><el-tag v-if="m.pinned" size="small">已固定</el-tag>
|
||||||
</div>
|
</div>
|
||||||
<DigitalMessageText
|
<p>{{ m.content || "(未生成正文)" }}</p>
|
||||||
class="history-message-body"
|
|
||||||
:text="m.content"
|
|
||||||
:role="m.role"
|
|
||||||
:incomplete="
|
|
||||||
['generating', 'stopped', 'failed'].includes(m.status)
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<el-pagination
|
<el-pagination
|
||||||
@@ -614,7 +564,7 @@ h2 {
|
|||||||
color: var(--el-text-color-secondary);
|
color: var(--el-text-color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.messages article .history-message-body {
|
.messages article p {
|
||||||
padding: 12px 14px;
|
padding: 12px 14px;
|
||||||
margin: 6px 0;
|
margin: 6px 0;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
@@ -623,7 +573,7 @@ h2 {
|
|||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.messages article.user .history-message-body {
|
.messages article.user p {
|
||||||
background: var(--el-color-primary-light-9);
|
background: var(--el-color-primary-light-9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
/** 对白、叙述、旧消息与累计流式文本的格式回归,不依赖浏览器或真实模型。 */
|
|
||||||
import test from "node:test";
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import { parseDigitalMessage as parse } from "../src/utils/digital-message-format.ts";
|
|
||||||
|
|
||||||
test("标准消息按剧情顺序拆分叙述、对白与心理,隐藏星号并保留引号", () => {
|
|
||||||
assert.deepEqual(parse("*她合上书。*\n\n“你来了。”\n\n*她终于放松下来。*"), [
|
|
||||||
{ kind: "narration", text: "她合上书。" },
|
|
||||||
{ kind: "dialogue", text: "“你来了。”" },
|
|
||||||
{ kind: "narration", text: "她终于放松下来。" }
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("旧消息的成对括号与括号外对白兼容,内层括号不会提前关闭叙述", () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
parse(
|
|
||||||
"(她抱起书(封面有些旧),笑了笑)你来了。\n(她心里有些高兴)坐吧。"
|
|
||||||
),
|
|
||||||
[
|
|
||||||
{ kind: "narration", text: "她抱起书(封面有些旧),笑了笑" },
|
|
||||||
{ kind: "dialogue", text: "你来了。" },
|
|
||||||
{ kind: "narration", text: "她心里有些高兴" },
|
|
||||||
{ kind: "dialogue", text: "坐吧。" }
|
|
||||||
]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("旧开场白的无标记叙述与引号对白分别展示,英文撇号不作为对白", () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
parse('She picked up her book.\n"You’re early. Don\'t wait outside."'),
|
|
||||||
[
|
|
||||||
{ kind: "narration", text: "She picked up her book." },
|
|
||||||
{ kind: "dialogue", text: '"You’re early. Don\'t wait outside."' }
|
|
||||||
]
|
|
||||||
);
|
|
||||||
for (const [open, close] of [
|
|
||||||
["“", "”"],
|
|
||||||
["「", "」"],
|
|
||||||
["『", "』"],
|
|
||||||
["«", "»"],
|
|
||||||
[""", """]
|
|
||||||
]) {
|
|
||||||
assert.deepEqual(parse(`${open}你好${close}`), [
|
|
||||||
{ kind: "dialogue", text: `${open}你好${close}` }
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("纯文本、普通备注、乘法与不完整的历史标记保留原文", () => {
|
|
||||||
for (const text of [
|
|
||||||
"普通文本",
|
|
||||||
"说明(选填)",
|
|
||||||
"3 * 4 = 12",
|
|
||||||
"file*name.txt",
|
|
||||||
"*未闭合",
|
|
||||||
"(未闭合"
|
|
||||||
]) {
|
|
||||||
assert.deepEqual(parse(text), [{ kind: "plain", text }]);
|
|
||||||
}
|
|
||||||
assert.deepEqual(parse(" \n\r\n"), []);
|
|
||||||
assert.deepEqual(parse("第一段\r\n\r\n第二段"), [
|
|
||||||
{ kind: "plain", text: "第一段" },
|
|
||||||
{ kind: "plain", text: "第二段" }
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("显式叙述里的引号保持为故事文本,不再二次推断", () => {
|
|
||||||
assert.deepEqual(parse("*她想到“明天”这个词,轻轻笑了。*"), [
|
|
||||||
{ kind: "narration", text: "她想到“明天”这个词,轻轻笑了。" }
|
|
||||||
]);
|
|
||||||
assert.deepEqual(parse("**“你好。”**"), [
|
|
||||||
{ kind: "dialogue", text: "“你好。”" }
|
|
||||||
]);
|
|
||||||
assert.deepEqual(parse("\\*字面星号\\*"), [
|
|
||||||
{ kind: "plain", text: "*字面星号*" }
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("累计流式输入的每个字符前缀都隐藏未闭合星号,完成态排版相同", () => {
|
|
||||||
const source = "*她推开门。*\n\n“你来了。”\n\n*她松了口气。*";
|
|
||||||
for (let end = 1; end <= source.length; end++) {
|
|
||||||
const blocks = parse(source.slice(0, end), true);
|
|
||||||
assert.equal(
|
|
||||||
blocks.some(block => block.text.includes("*")),
|
|
||||||
false,
|
|
||||||
`前缀 ${end}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert.deepEqual(parse(source, true), parse(source));
|
|
||||||
assert.deepEqual(parse("*她推开门", true), [
|
|
||||||
{ kind: "narration", text: "她推开门" }
|
|
||||||
]);
|
|
||||||
assert.deepEqual(parse("(她推开门", true), [
|
|
||||||
{ kind: "narration", text: "她推开门" }
|
|
||||||
]);
|
|
||||||
assert.deepEqual(parse("“你来了", true), [
|
|
||||||
{ kind: "dialogue", text: "“你来了" }
|
|
||||||
]);
|
|
||||||
assert.deepEqual(parse("**Hello", true), [
|
|
||||||
{ kind: "dialogue", text: "Hello" }
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("HTML 与脚本内容只作为文本保留,格式解析不会生成任何标签", () => {
|
|
||||||
const text = "<script>globalThis.injected = true</script>";
|
|
||||||
assert.deepEqual(parse(text), [{ kind: "plain", text }]);
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user