Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb1314470a | |||
| fb46c0fdb5 | |||
| 3530219123 | |||
| f921204dc8 | |||
| fb8be9c460 | |||
| ae2b58e0b8 | |||
| c45fb9c941 | |||
| 4638c72680 | |||
| 1f11112e04 | |||
| 6a40040573 | |||
| d3fe1b21ed |
@@ -34,7 +34,7 @@ PORT=3210
|
||||
HOSTNAME=0.0.0.0
|
||||
```
|
||||
|
||||
`ACCESS_MANAGE_API_BASE_URL` 指向 `access-manage` 服务端 API 根路径。数字人登录调用后端 `POST /api/auth/digital/login`,接受现有超级管理员或员工账号,登录成功后只把 JWT 写入 Next.js 服务端 HttpOnly Cookie,不写入 `localStorage`。
|
||||
`ACCESS_MANAGE_API_BASE_URL` 指向 `access-manage` 服务端 API 根路径。数字人登录调用后端 `POST /api/auth/digital/login`,仅接受后台开通的独立 C 端账号,登录成功后只把 JWT 写入 Next.js 服务端 HttpOnly Cookie,不写入 `localStorage`。
|
||||
|
||||
环境标识按 `APP_ENV` 区分:
|
||||
|
||||
@@ -122,7 +122,7 @@ pnpm start:prod
|
||||
|
||||
## 数字人空间
|
||||
|
||||
- `/discover` 为默认入口,复用原登录账户和 HttpOnly Cookie。
|
||||
- `/discover` 为默认入口,使用独立 C 端账号和 HttpOnly Cookie。
|
||||
- `src/components/digital-home.tsx`、`digital.css`:深色双 UI、移动/桌面适配、探索、流式对话、停止、重生成、分支、固定记忆、世界书与用户身份。
|
||||
- `src/lib/digital.ts`:前台协议、请求和 SSE 解码。
|
||||
- `src/app/api/digital/[...path]/route.ts`:白名单 BFF,只转发前台接口,禁止访问后台实验管理,写入校验同源。
|
||||
@@ -144,3 +144,16 @@ pnpm start:prod
|
||||
- `src/lib/auth-redirect.ts`:登出与会话过期后使用站内相对 `Location`,避免跳到 Next.js 内部监听地址 `0.0.0.0:3210`;仅允许站内返回路径。
|
||||
- `tests/auth-redirect.test.mjs`:覆盖正式域名/本地地址的登录页跳转、站内参数和外部地址拦截。
|
||||
- 执行:`node --experimental-strip-types --test tests/auth-redirect.test.mjs`(Node.js 22)。
|
||||
|
||||
聊天滚动将“跟随最新”与当前底部距离分开:停在底部时,流式回复、结束后操作栏及软键盘导致的尺寸变化均继续贴底;主动上翻才暂停跟随,点击“回到最新”重新启用。等待首段正文仅显示思考点,收到文字后才显示打字光标,结束时移除生成提示。
|
||||
|
||||
聊天输入区“继续”让 NPC 基于上一段内容继续说话,不发送或清空输入框草稿,也不插入用户气泡;可连续点击生成多段,生成时沿用停止按钮。角色尚无可接续内容时按钮不可用。
|
||||
|
||||
NPC 尚未出字就停止或失败时,“继续”仍可接续此前已完成的角色内容,输入草稿保持不变。
|
||||
|
||||
|
||||
### 独立 C 端登录
|
||||
|
||||
前台通过 `/api/auth/digital/login` 使用独立 C 端账号,由后台「用户管理」开通;不再使用管理员/员工身份。已有数字人业务账号由迁移复制密码哈希并保留会话,之后两套账号密码和状态独立。登录令牌保存在 HttpOnly Cookie,密码重置/账号停用会撤销旧登录状态。
|
||||
|
||||
对话设置的世界书与叙事风格使用平面列表;选中只保留轻底色和一个勾选标记,键盘焦点仍显示明确轮廓。
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** 星港登录页,沿用既有账号,无公开注册。 */
|
||||
/** 星港登录页,使用独立用户账号,无公开注册。 */
|
||||
import Link from "next/link";
|
||||
import { LoginForm } from "@/components/login-form";
|
||||
import "@/components/digital-login.css";
|
||||
@@ -31,9 +31,9 @@ export default function LoginPage() {
|
||||
<section className="stellar-login-panel">
|
||||
<span className="stellar-login-star">✧</span>
|
||||
<h2>欢迎回到星港</h2>
|
||||
<p>使用你的现有账号,继续未完的故事。</p>
|
||||
<p>使用你的星港账号,继续未完的故事。</p>
|
||||
<LoginForm />
|
||||
<small>私人数字人空间 · 不开放公开注册</small>
|
||||
<small>账号由管理员开通 · 与后台账号独立</small>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
|
||||
+117
-37
@@ -90,6 +90,14 @@ function MessageText({
|
||||
message: Message;
|
||||
animate: boolean;
|
||||
}) {
|
||||
if (message.status === "generating" && !message.content.trim())
|
||||
return (
|
||||
<span className="dh-thinking" role="status" aria-label="正在思考">
|
||||
<i aria-hidden />
|
||||
<i aria-hidden />
|
||||
<i aria-hidden />
|
||||
</span>
|
||||
);
|
||||
return (
|
||||
<div className="dh-message-text">
|
||||
<TypedText
|
||||
@@ -166,13 +174,29 @@ export function DigitalHome({
|
||||
viewport = useRef<HTMLDivElement>(null),
|
||||
messagesElement = useRef<HTMLDivElement>(null),
|
||||
textarea = useRef<HTMLTextAreaElement>(null),
|
||||
// 跟随是用户意图,内容增高导致暂时离底不能自动退出跟随。
|
||||
atBottom = useRef(true),
|
||||
touchY = useRef<number | null>(null),
|
||||
draggingScroll = useRef(false),
|
||||
currentId = useRef<string | null>(null),
|
||||
openSequence = useRef(0);
|
||||
const cards = boot?.catalog.filter((c) => c.kind === "character") ?? [],
|
||||
books = boot?.catalog.filter((c) => c.kind === "worldbook") ?? [],
|
||||
presets = boot?.catalog.filter((c) => c.kind === "preset") ?? [];
|
||||
const conversationId = conversation?.id;
|
||||
// 尚未产生正文的失败/停止不算新台词,继续时接回上一段;真实用户消息仍是边界。
|
||||
const lastReply = conversation?.messages.findLast(
|
||||
(m) =>
|
||||
!(
|
||||
m.role === "assistant" &&
|
||||
["stopped", "failed"].includes(m.status) &&
|
||||
!m.content.trim()
|
||||
),
|
||||
);
|
||||
const canContinue =
|
||||
lastReply?.role === "assistant" &&
|
||||
["complete", "stopped"].includes(lastReply.status) &&
|
||||
!!lastReply.content.trim();
|
||||
// 状态提示走只读接口,打开设定不应写入实验分组、决策或曝光。
|
||||
useEffect(() => {
|
||||
if (!showSettings || !conversationId) return;
|
||||
@@ -264,17 +288,34 @@ export function DigitalHome({
|
||||
return () => clearTimeout(timer);
|
||||
}, [notice]);
|
||||
useEffect(() => {
|
||||
const el = messagesElement.current;
|
||||
if (!el) return;
|
||||
const observer = new ResizeObserver(() => {
|
||||
if (atBottom.current)
|
||||
viewport.current?.scrollTo({
|
||||
top: viewport.current.scrollHeight,
|
||||
behavior: "instant",
|
||||
});
|
||||
});
|
||||
const el = messagesElement.current,
|
||||
view = viewport.current;
|
||||
if (!el || !view) return;
|
||||
let frame = 0;
|
||||
const follow = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
if (!atBottom.current) return;
|
||||
view.scrollTo({ top: view.scrollHeight, behavior: "instant" });
|
||||
setShowJump(false);
|
||||
});
|
||||
};
|
||||
// 同时观察内容与可视区:视觉打字、结束后的操作栏、输入框和软键盘都会改变底部位置。
|
||||
const observer = new ResizeObserver(follow);
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
observer.observe(view);
|
||||
const endDrag = () => {
|
||||
draggingScroll.current = false;
|
||||
};
|
||||
window.addEventListener("pointerup", endDrag);
|
||||
window.addEventListener("pointercancel", endDrag);
|
||||
follow();
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
cancelAnimationFrame(frame);
|
||||
window.removeEventListener("pointerup", endDrag);
|
||||
window.removeEventListener("pointercancel", endDrag);
|
||||
};
|
||||
}, [conversationId]);
|
||||
useEffect(() => {
|
||||
if (!conversationId) return;
|
||||
@@ -419,6 +460,7 @@ export function DigitalHome({
|
||||
setActiveMessage(null);
|
||||
setShowMenu(false);
|
||||
atBottom.current = true;
|
||||
setShowJump(false);
|
||||
try {
|
||||
setDraft(sessionStorage.getItem(`dh-draft:${id}`) ?? "");
|
||||
} catch {
|
||||
@@ -468,7 +510,7 @@ export function DigitalHome({
|
||||
favoritePending.current = false;
|
||||
}
|
||||
}
|
||||
async function send(mode: "send" | "regenerate" = "send") {
|
||||
async function send(mode: "send" | "regenerate" | "continue" = "send") {
|
||||
if (
|
||||
!conversation ||
|
||||
busy ||
|
||||
@@ -478,13 +520,14 @@ export function DigitalHome({
|
||||
return;
|
||||
closeIdeas();
|
||||
const id = conversation.id,
|
||||
content = draft.trim(),
|
||||
content = mode === "send" ? draft.trim() : "",
|
||||
requestId = crypto.randomUUID();
|
||||
let assistantId = `pending-${requestId}`;
|
||||
setBusy(true);
|
||||
setError("");
|
||||
setNotice("");
|
||||
atBottom.current = true;
|
||||
setShowJump(false);
|
||||
streamingId.current = id;
|
||||
if (mode === "send") {
|
||||
setDraft("");
|
||||
@@ -939,9 +982,6 @@ export function DigitalHome({
|
||||
onChange={() => onChange(p.id || undefined)}
|
||||
/>
|
||||
<span className="dh-style-card">
|
||||
<span className="dh-style-symbol" aria-hidden="true">
|
||||
{p.id ? <WandSparkles /> : <Sparkles />}
|
||||
</span>
|
||||
<span className="dh-style-copy">
|
||||
<strong>{p.name}</strong>
|
||||
<small>{p.description || "以这套风格继续你们的故事。"}</small>
|
||||
@@ -996,9 +1036,10 @@ export function DigitalHome({
|
||||
);
|
||||
// UI按消费者返回值决定,组名仅用于归因;C到Z同样可以返回新版UI。
|
||||
// 缺少value时兼容尚未升级的服务响应。
|
||||
const modern = boot?.decision.value !== undefined
|
||||
? boot.decision.value === "new" || boot.decision.value === true
|
||||
: boot?.decision.variant === "B";
|
||||
const modern =
|
||||
boot?.decision.value !== undefined
|
||||
? boot.decision.value === "new" || boot.decision.value === true
|
||||
: boot?.decision.variant === "B";
|
||||
return (
|
||||
<div
|
||||
className={`dh-app ${modern ? "dh-modern" : "dh-classic"} ${conversation ? "dh-in-chat" : ""}`}
|
||||
@@ -1127,12 +1168,45 @@ export function DigitalHome({
|
||||
<div
|
||||
className="dh-messages"
|
||||
ref={viewport}
|
||||
tabIndex={0}
|
||||
aria-label="聊天消息"
|
||||
onWheel={(event) => {
|
||||
if (event.deltaY < 0 && event.currentTarget.scrollTop > 0)
|
||||
atBottom.current = false;
|
||||
}}
|
||||
onTouchStart={(event) => {
|
||||
touchY.current = event.touches[0]?.clientY ?? null;
|
||||
}}
|
||||
onTouchMove={(event) => {
|
||||
const y = event.touches[0]?.clientY;
|
||||
if (
|
||||
y !== undefined &&
|
||||
touchY.current !== null &&
|
||||
y > touchY.current &&
|
||||
event.currentTarget.scrollTop > 0
|
||||
)
|
||||
atBottom.current = false;
|
||||
touchY.current = y ?? null;
|
||||
}}
|
||||
onTouchEnd={() => {
|
||||
touchY.current = null;
|
||||
}}
|
||||
onPointerDown={(event) => {
|
||||
draggingScroll.current =
|
||||
event.pointerType === "mouse" &&
|
||||
event.target === event.currentTarget;
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (["ArrowUp", "PageUp", "Home"].includes(event.key))
|
||||
atBottom.current = false;
|
||||
}}
|
||||
onScroll={() => {
|
||||
const v = viewport.current;
|
||||
if (v) {
|
||||
atBottom.current =
|
||||
v.scrollHeight - v.scrollTop - v.clientHeight < 110;
|
||||
setShowJump(!atBottom.current);
|
||||
const gap = v.scrollHeight - v.scrollTop - v.clientHeight;
|
||||
if (gap <= 2) atBottom.current = true;
|
||||
else if (draggingScroll.current) atBottom.current = false;
|
||||
setShowJump(!atBottom.current && gap > 80);
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -1168,13 +1242,6 @@ export function DigitalHome({
|
||||
m.id === activeMessage && m.status === "generating"
|
||||
}
|
||||
/>
|
||||
{!m.content && m.status === "generating" && (
|
||||
<span className="dh-thinking">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{!busy && m.content && (
|
||||
<div className="dh-message-actions">
|
||||
@@ -1253,9 +1320,10 @@ export function DigitalHome({
|
||||
className="dh-jump"
|
||||
onClick={() => {
|
||||
atBottom.current = true;
|
||||
setShowJump(false);
|
||||
viewport.current?.scrollTo({
|
||||
top: viewport.current.scrollHeight,
|
||||
behavior: "smooth",
|
||||
behavior: "instant",
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -1325,14 +1393,26 @@ export function DigitalHome({
|
||||
</section>
|
||||
)}
|
||||
<div className="dh-compose-tools">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy || ideasLoading}
|
||||
onClick={generateIdeas}
|
||||
>
|
||||
<Sparkles size={14} />
|
||||
{ideasLoading ? "灵感生成中…" : "灵感回复"}
|
||||
</button>
|
||||
<div className="dh-compose-actions">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy || ideasLoading}
|
||||
onClick={generateIdeas}
|
||||
>
|
||||
<Sparkles size={14} />
|
||||
{ideasLoading ? "灵感生成中…" : "灵感回复"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="让角色继续"
|
||||
title="不发送输入框里的草稿,让角色接着说"
|
||||
disabled={busy || ideasLoading || !canContinue}
|
||||
onClick={() => send("continue")}
|
||||
>
|
||||
<ChevronRight size={14} />
|
||||
继续
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="dh-mobile-linebreak"
|
||||
|
||||
+37
-42
@@ -762,6 +762,11 @@
|
||||
align-items: center;
|
||||
margin: 0 4px 8px;
|
||||
}
|
||||
.dh-compose-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
.dh-app .dh-compose-tools button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1174,8 +1179,8 @@
|
||||
}
|
||||
.dh-style-options {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 0;
|
||||
}
|
||||
.dh-style-option {
|
||||
position: relative;
|
||||
@@ -1183,10 +1188,6 @@
|
||||
cursor: pointer;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.dh-style-option:first-child,
|
||||
.dh-style-option:last-child:nth-child(even) {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.dh-style-option > input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
@@ -1200,41 +1201,26 @@
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
height: 100%;
|
||||
min-height: 88px;
|
||||
padding: 15px 13px;
|
||||
border: 1px solid #ffffff17;
|
||||
border-radius: 13px;
|
||||
background: color-mix(in srgb, var(--dh-soft) 60%, var(--dh-panel));
|
||||
min-height: 72px;
|
||||
padding: 14px 10px;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--dh-line);
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
transition:
|
||||
border-color 160ms,
|
||||
background 160ms;
|
||||
}
|
||||
.dh-style-option:hover .dh-style-card {
|
||||
border-color: color-mix(in srgb, var(--dh-accent) 55%, transparent);
|
||||
background: #ffffff04;
|
||||
}
|
||||
.dh-style-option > input:checked + .dh-style-card {
|
||||
border-color: var(--dh-accent);
|
||||
background: color-mix(in srgb, var(--dh-accent) 9%, var(--dh-panel));
|
||||
background: color-mix(in srgb, var(--dh-accent) 7%, transparent);
|
||||
}
|
||||
.dh-style-option > input:focus-visible + .dh-style-card {
|
||||
outline: 2px solid var(--dh-accent);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.dh-style-symbol {
|
||||
display: grid;
|
||||
flex: none;
|
||||
place-items: center;
|
||||
width: 29px;
|
||||
height: 29px;
|
||||
color: var(--dh-accent);
|
||||
background: color-mix(in srgb, var(--dh-accent) 10%, transparent);
|
||||
border-radius: 9px;
|
||||
}
|
||||
.dh-style-symbol svg {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
.dh-style-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
@@ -1261,8 +1247,7 @@
|
||||
height: 17px;
|
||||
margin-top: 2px;
|
||||
color: transparent;
|
||||
border: 1px solid #ffffff30;
|
||||
border-radius: 50%;
|
||||
border: 0;
|
||||
}
|
||||
.dh-style-check svg {
|
||||
width: 11px;
|
||||
@@ -1270,9 +1255,8 @@
|
||||
stroke-width: 3;
|
||||
}
|
||||
.dh-style-option > input:checked + .dh-style-card .dh-style-check {
|
||||
color: var(--dh-accent-ink);
|
||||
background: var(--dh-accent);
|
||||
border-color: var(--dh-accent);
|
||||
color: var(--dh-accent);
|
||||
background: transparent;
|
||||
}
|
||||
@media (width <= 600px) {
|
||||
.dh-style-options {
|
||||
@@ -1362,18 +1346,18 @@
|
||||
border: 0;
|
||||
}
|
||||
.dh-selection-sheet .dh-checkbox {
|
||||
min-height: 74px;
|
||||
padding: 14px;
|
||||
margin: 0 0 10px;
|
||||
border: 1px solid #ffffff17;
|
||||
border-radius: 13px;
|
||||
min-height: 70px;
|
||||
padding: 14px 10px;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--dh-line);
|
||||
border-radius: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
.dh-selection-sheet .dh-checkbox.is-selected {
|
||||
background: color-mix(in srgb, var(--dh-accent) 9%, var(--dh-panel));
|
||||
border-color: var(--dh-accent);
|
||||
background: color-mix(in srgb, var(--dh-accent) 7%, transparent);
|
||||
}
|
||||
.dh-selection-sheet .dh-checkbox:focus-within {
|
||||
.dh-selection-sheet .dh-checkbox:has(input:focus-visible) {
|
||||
outline: 2px solid var(--dh-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
@@ -2328,3 +2312,14 @@ body:has(.dh-app) .environment-badge {
|
||||
overflow-x: hidden;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
/* 世界书与风格统一使用平面列表,选中只保留轻底色和一个勾选标记。 */
|
||||
.dh-settings .dh-book-picker {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.dh-checkbox input {
|
||||
flex: none;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
|
||||
/** 复用原有账号登录,成功后进入数字人空间。 */
|
||||
/** 独立星港用户账号登录,成功后进入数字人空间。 */
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Eye, EyeOff, LockKeyhole, Smartphone } from "lucide-react";
|
||||
import { FormEvent, useState } from "react";
|
||||
|
||||
/** 现有账号的登录表单,不保存明文密码。 */
|
||||
/** 独立用户的登录表单,不保存明文密码。 */
|
||||
export function LoginForm() {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState("");
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
export type AccountType = "SUPER_ADMIN" | "EMPLOYEE";
|
||||
/** 前台身份与业务协议,数字人账号使用独立 DIGITAL_USER 类型。 */
|
||||
export type AccountType = "SUPER_ADMIN" | "EMPLOYEE" | "DIGITAL_USER";
|
||||
|
||||
export type Role = {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user