feat(digital): 接入角色世界书与账号实验服务
- digital: 新增私有会话、DeepSeek流式生成、停止与分支、世界书和预设编排 - experiments: 新增账号稳定分组、人工指定、生命周期、预设快照及实验漏斗审计 - migrations/data: 初始化20位成年角色、4本世界书与3种叙事预设 - tests/docs: 补充11项核心回归、市场参考和部署说明
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/** 数字人业务输入边界,限制内容体积并分离公开内容和服务端提示词。 */
|
||||
import { z } from "zod";
|
||||
/** URL 中的稳定业务标识。 */
|
||||
export const idSchema = z.string().regex(/^[a-zA-Z0-9_-]{1,64}$/);
|
||||
const text = z.string().max(12000);
|
||||
/** 世界书条目:采用确定性关键词匹配,禁止运行用户正则。 */
|
||||
export const entrySchema = z.object({
|
||||
id: idSchema,
|
||||
name: z.string().max(120),
|
||||
keys: z.array(z.string().min(1).max(100)).max(40).default([]),
|
||||
secondaryKeys: z.array(z.string().min(1).max(100)).max(40).default([]),
|
||||
content: text,
|
||||
constant: z.boolean().default(false),
|
||||
enabled: z.boolean().default(true),
|
||||
priority: z.number().int().min(0).max(1000).default(100),
|
||||
position: z.enum(["before", "after"]).default("after"),
|
||||
caseSensitive: z.boolean().default(false),
|
||||
scanDepth: z.number().int().min(1).max(30).default(6),
|
||||
});
|
||||
/** 可发布的角色、世界书和生成预设;未知字段不进入数据库。 */
|
||||
export const contentSchema = z.object({
|
||||
kind: z.enum(["character", "worldbook", "preset"]),
|
||||
name: z.string().min(1).max(120),
|
||||
status: z.enum(["draft", "published", "archived"]).default("draft"),
|
||||
body: z.object({
|
||||
description: text.default(""),
|
||||
personality: text.default(""),
|
||||
scenario: text.default(""),
|
||||
greeting: text.default(""),
|
||||
alternateGreetings: z.array(text).max(8).default([]),
|
||||
examples: text.default(""),
|
||||
systemPrompt: text.default(""),
|
||||
gender: z.enum(["female", "male", "other"]).default("female"),
|
||||
age: z.number().int().min(18).max(1000).default(25),
|
||||
cover: z
|
||||
.string()
|
||||
.max(1000)
|
||||
.refine(
|
||||
(v) => !v || /^\/(?!\/)/.test(v) || /^https:\/\//.test(v),
|
||||
"图片须为站内路径或 HTTPS",
|
||||
),
|
||||
tags: z.array(z.string().max(40)).max(12).default([]),
|
||||
bookIds: z.array(idSchema).max(12).default([]),
|
||||
presetId: idSchema.optional(),
|
||||
entries: z.array(entrySchema).max(150).default([]),
|
||||
temperature: z.number().min(0).max(1.5).default(0.9),
|
||||
maxTokens: z.number().int().min(100).max(1500).default(700),
|
||||
contextBudget: z.number().int().min(6000).max(24000).default(12000),
|
||||
worldBudget: z.number().int().min(0).max(8000).default(3500),
|
||||
source: z.string().max(1000).default("项目原创"),
|
||||
}),
|
||||
});
|
||||
/** 内容记录只保存经过 schema 解析的数据。 */
|
||||
export type ContentInput = z.infer<typeof contentSchema>;
|
||||
/** 实验配置仅通过后台写入,分组语义在同一实验生命周期中固定。 */
|
||||
export const experimentSchema = z.object({
|
||||
name: z.string().min(1).max(120),
|
||||
scope: z.enum(["ui", "chat"]),
|
||||
config: z.object({
|
||||
audience: z.enum(["all", "new", "existing", "specified"]).default("all"),
|
||||
cutoff: z.iso.datetime().optional(),
|
||||
accounts: z
|
||||
.array(z.string().regex(/^(employee|super_admin):[0-9]+$/))
|
||||
.max(500)
|
||||
.default([]),
|
||||
traffic: z.number().int().min(0).max(10000).default(10000),
|
||||
weightB: z.number().int().min(0).max(10000).default(5000),
|
||||
baseline: z.enum(["A", "B"]).default("A"),
|
||||
winner: z.enum(["A", "B"]).optional(),
|
||||
presetA: idSchema.optional(),
|
||||
presetB: idSchema.optional(),
|
||||
description: z.string().max(2000).default(""),
|
||||
}),
|
||||
});
|
||||
/** 用户自己的会话配置,不包含实验或服务端模型选择。 */
|
||||
export const settingsSchema = z.object({
|
||||
persona: z.string().max(2000).default(""),
|
||||
userName: z.string().max(60).default("旅人"),
|
||||
memory: z.string().max(3000).default(""),
|
||||
presetId: idSchema.optional(),
|
||||
bookIds: z.array(idSchema).max(8).default([]),
|
||||
});
|
||||
Reference in New Issue
Block a user