094d0c17e8
- 实验类型:自定义标识、数据契约、默认值和真实调用后的接入验收 - 测试方案:按类型校验 A/B 值,保留历史分组与预设快照,未验收禁止发布 - 用户管理:真实账号分页搜索、只读预览与有效账号人工指定校验 - 文档与验证:同步迁移014及消费者接口说明,15项核心回归通过
85 lines
3.6 KiB
TypeScript
85 lines
3.6 KiB
TypeScript
/** 数字人业务输入边界,限制内容体积并分离公开内容和服务端提示词。 */
|
|
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: idSchema,
|
|
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(""),
|
|
values: z.object({ A: z.json(), B: z.json() }).optional(),
|
|
typeRevision: z.number().int().positive().optional(),
|
|
}),
|
|
});
|
|
/** 用户自己的会话配置,不包含实验或服务端模型选择。 */
|
|
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([]),
|
|
});
|