Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb46c0fdb5 | |||
| 3530219123 | |||
| fb8be9c460 | |||
| ae2b58e0b8 | |||
| 4638c72680 | |||
| 1f11112e04 | |||
| cac56740cc | |||
| f75a9abecc | |||
| afc474b0c4 | |||
| a963bec3f3 | |||
| 81079c7364 | |||
| 4079397625 |
@@ -34,7 +34,7 @@ PORT=3210
|
|||||||
HOSTNAME=0.0.0.0
|
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` 区分:
|
环境标识按 `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/components/digital-home.tsx`、`digital.css`:深色双 UI、移动/桌面适配、探索、流式对话、停止、重生成、分支、固定记忆、世界书与用户身份。
|
||||||
- `src/lib/digital.ts`:前台协议、请求和 SSE 解码。
|
- `src/lib/digital.ts`:前台协议、请求和 SSE 解码。
|
||||||
- `src/app/api/digital/[...path]/route.ts`:白名单 BFF,只转发前台接口,禁止访问后台实验管理,写入校验同源。
|
- `src/app/api/digital/[...path]/route.ts`:白名单 BFF,只转发前台接口,禁止访问后台实验管理,写入校验同源。
|
||||||
@@ -134,3 +134,26 @@ pnpm start:prod
|
|||||||
通用实验消费者可经 `GET /api/digital/decisions/:key` 读取本人类型决策的 `data.value`,沿用 HttpOnly 会话与不缓存策略。类型、测试方案和用户分组全部在后台管理;新类型需要应用真实使用返回值并完成后台接入验收后才可启动。
|
通用实验消费者可经 `GET /api/digital/decisions/:key` 读取本人类型决策的 `data.value`,沿用 HttpOnly 会话与不缓存策略。类型、测试方案和用户分组全部在后台管理;新类型需要应用真实使用返回值并完成后台接入验收后才可启动。
|
||||||
|
|
||||||
`src/components/conversation-row.tsx` 提供会话列表横滑删除、桌面删除入口与模态确认。灵感回复读取本人会话上下文,选择后只加入草稿,原草稿保留;回车发送覆盖 H5/Web,支持中文输入法、Shift+Enter 与手机换行按钮。
|
`src/components/conversation-row.tsx` 提供会话列表横滑删除、桌面删除入口与模态确认。灵感回复读取本人会话上下文,选择后只加入草稿,原草稿保留;回车发送覆盖 H5/Web,支持中文输入法、Shift+Enter 与手机换行按钮。
|
||||||
|
|
||||||
|
内部滚动区域统一隐藏原生轨道,保留触摸/键盘滚动,设定表单关闭横向溢出。风格控制提示使用只读 `GET /api/digital/conversations/:id/style-policy`,打开设定不会写入实验分组、决策或曝光。
|
||||||
|
|
||||||
|
实验决策支持 A~Z 动态组;未入组时组别为 null。界面消费 `decision.value`(`new` / `true` 为新版),组名仅用于归因。决策过期使用服务端的 `fallbackValue`,不将无实验用户伪装成 A 组;旧服务未返回value时保留既有兼容路径。
|
||||||
|
|
||||||
|
## 登录跳转回归
|
||||||
|
|
||||||
|
- `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 Link from "next/link";
|
||||||
import { LoginForm } from "@/components/login-form";
|
import { LoginForm } from "@/components/login-form";
|
||||||
import "@/components/digital-login.css";
|
import "@/components/digital-login.css";
|
||||||
@@ -31,9 +31,9 @@ export default function LoginPage() {
|
|||||||
<section className="stellar-login-panel">
|
<section className="stellar-login-panel">
|
||||||
<span className="stellar-login-star">✧</span>
|
<span className="stellar-login-star">✧</span>
|
||||||
<h2>欢迎回到星港</h2>
|
<h2>欢迎回到星港</h2>
|
||||||
<p>使用你的现有账号,继续未完的故事。</p>
|
<p>使用你的星港账号,继续未完的故事。</p>
|
||||||
<LoginForm />
|
<LoginForm />
|
||||||
<small>私人数字人空间 · 不开放公开注册</small>
|
<small>账号由管理员开通 · 与后台账号独立</small>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
/** 清理会话后返回当前站点,保持反向代理域名与本地访问地址。 */
|
||||||
|
import { NextRequest } from "next/server";
|
||||||
|
import { logoutRedirect } from "@/lib/auth-redirect";
|
||||||
|
|
||||||
import { clearSessionToken } from "@/lib/session";
|
import { clearSessionToken } from "@/lib/session";
|
||||||
|
|
||||||
|
/** 客户端主动退出时仅清理 Cookie,由页面处理导航。 */
|
||||||
export async function POST() {
|
export async function POST() {
|
||||||
await clearSessionToken();
|
await clearSessionToken();
|
||||||
return Response.json({ success: true, data: null });
|
return Response.json({ success: true, data: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 会话过期或链接退出后跳转站内页面,不使用服务端监听地址。 */
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
await clearSessionToken();
|
await clearSessionToken();
|
||||||
const next = request.nextUrl.searchParams.get("next") || "/login";
|
return logoutRedirect(request.nextUrl.searchParams.get("next"));
|
||||||
|
|
||||||
return NextResponse.redirect(new URL(next, request.url));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,15 @@ async function proxy(
|
|||||||
const { path } = await context.params;
|
const { path } = await context.params;
|
||||||
const joined = path.join("/");
|
const joined = path.join("/");
|
||||||
if (
|
if (
|
||||||
!/^(bootstrap|profile|exposure|decisions\/[a-zA-Z0-9_-]+|conversations(?:\/[a-zA-Z0-9_-]+(?:\/(?:stream|stop|branch|suggestions|messages\/[a-zA-Z0-9_-]+))?)?)$/.test(
|
!/^(bootstrap|profile|exposure|decisions\/[a-zA-Z0-9_-]+|conversations(?:\/[a-zA-Z0-9_-]+(?:\/(?:stream|stop|branch|suggestions|style-policy|messages\/[a-zA-Z0-9_-]+))?)?)$/.test(
|
||||||
joined,
|
joined,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return Response.json({ message: "接口不存在" }, { status: 404 });
|
return Response.json({ message: "接口不存在" }, { status: 404 });
|
||||||
if (joined.startsWith("decisions/") && request.method !== "GET")
|
if (
|
||||||
|
(joined.startsWith("decisions/") || joined.endsWith("/style-policy")) &&
|
||||||
|
request.method !== "GET"
|
||||||
|
)
|
||||||
return Response.json(
|
return Response.json(
|
||||||
{ message: "仅支持读取决策" },
|
{ message: "仅支持读取决策" },
|
||||||
{ status: 405, headers: { Allow: "GET" } },
|
{ status: 405, headers: { Allow: "GET" } },
|
||||||
|
|||||||
+151
-32
@@ -90,6 +90,14 @@ function MessageText({
|
|||||||
message: Message;
|
message: Message;
|
||||||
animate: boolean;
|
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 (
|
return (
|
||||||
<div className="dh-message-text">
|
<div className="dh-message-text">
|
||||||
<TypedText
|
<TypedText
|
||||||
@@ -105,7 +113,7 @@ function MessageText({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/** 前台无分组按钮、调试开关或实验配置。 */
|
/** 前台管理个人会话偏好;后台方案仅展示覆盖提示,不开放实验操作。 */
|
||||||
export function DigitalHome({
|
export function DigitalHome({
|
||||||
initial,
|
initial,
|
||||||
initialSummaries,
|
initialSummaries,
|
||||||
@@ -126,6 +134,9 @@ export function DigitalHome({
|
|||||||
[opening, setOpening] = useState(false),
|
[opening, setOpening] = useState(false),
|
||||||
[error, setError] = useState(""),
|
[error, setError] = useState(""),
|
||||||
[notice, setNotice] = useState("");
|
[notice, setNotice] = useState("");
|
||||||
|
const [stylePolicy, setStylePolicy] = useState<
|
||||||
|
"loading" | "personal" | "managed" | "unknown"
|
||||||
|
>("loading");
|
||||||
const [showSettings, setShowSettings] = useState(false),
|
const [showSettings, setShowSettings] = useState(false),
|
||||||
[settings, setSettings] = useState<Settings | null>(null),
|
[settings, setSettings] = useState<Settings | null>(null),
|
||||||
[profile, setProfile] = useState<Profile | null>(initial.profile);
|
[profile, setProfile] = useState<Profile | null>(initial.profile);
|
||||||
@@ -163,13 +174,48 @@ export function DigitalHome({
|
|||||||
viewport = useRef<HTMLDivElement>(null),
|
viewport = useRef<HTMLDivElement>(null),
|
||||||
messagesElement = useRef<HTMLDivElement>(null),
|
messagesElement = useRef<HTMLDivElement>(null),
|
||||||
textarea = useRef<HTMLTextAreaElement>(null),
|
textarea = useRef<HTMLTextAreaElement>(null),
|
||||||
|
// 跟随是用户意图,内容增高导致暂时离底不能自动退出跟随。
|
||||||
atBottom = useRef(true),
|
atBottom = useRef(true),
|
||||||
|
touchY = useRef<number | null>(null),
|
||||||
|
draggingScroll = useRef(false),
|
||||||
currentId = useRef<string | null>(null),
|
currentId = useRef<string | null>(null),
|
||||||
openSequence = useRef(0);
|
openSequence = useRef(0);
|
||||||
const cards = boot?.catalog.filter((c) => c.kind === "character") ?? [],
|
const cards = boot?.catalog.filter((c) => c.kind === "character") ?? [],
|
||||||
books = boot?.catalog.filter((c) => c.kind === "worldbook") ?? [],
|
books = boot?.catalog.filter((c) => c.kind === "worldbook") ?? [],
|
||||||
presets = boot?.catalog.filter((c) => c.kind === "preset") ?? [];
|
presets = boot?.catalog.filter((c) => c.kind === "preset") ?? [];
|
||||||
const conversationId = conversation?.id;
|
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;
|
||||||
|
const controller = new AbortController();
|
||||||
|
digital<{ managed: boolean }>(
|
||||||
|
`conversations/${conversationId}/style-policy`,
|
||||||
|
"GET",
|
||||||
|
undefined,
|
||||||
|
controller.signal,
|
||||||
|
)
|
||||||
|
.then((policy) => {
|
||||||
|
if (!controller.signal.aborted)
|
||||||
|
setStylePolicy(policy.managed ? "managed" : "personal");
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (!controller.signal.aborted) setStylePolicy("unknown");
|
||||||
|
});
|
||||||
|
return () => controller.abort();
|
||||||
|
}, [showSettings, conversationId]);
|
||||||
const decisionExpiresAt = boot?.decision.expiresAt,
|
const decisionExpiresAt = boot?.decision.expiresAt,
|
||||||
decisionServerNow = boot?.serverNow;
|
decisionServerNow = boot?.serverNow;
|
||||||
const currentCard = cards.find((c) => c.id === conversation?.characterId);
|
const currentCard = cards.find((c) => c.id === conversation?.characterId);
|
||||||
@@ -226,6 +272,7 @@ export function DigitalHome({
|
|||||||
decision: {
|
decision: {
|
||||||
...current.decision,
|
...current.decision,
|
||||||
variant: current.decision.fallbackVariant,
|
variant: current.decision.fallbackVariant,
|
||||||
|
value: current.decision.fallbackValue,
|
||||||
decisionId: null,
|
decisionId: null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -241,17 +288,34 @@ export function DigitalHome({
|
|||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [notice]);
|
}, [notice]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const el = messagesElement.current;
|
const el = messagesElement.current,
|
||||||
if (!el) return;
|
view = viewport.current;
|
||||||
const observer = new ResizeObserver(() => {
|
if (!el || !view) return;
|
||||||
if (atBottom.current)
|
let frame = 0;
|
||||||
viewport.current?.scrollTo({
|
const follow = () => {
|
||||||
top: viewport.current.scrollHeight,
|
cancelAnimationFrame(frame);
|
||||||
behavior: "instant",
|
frame = requestAnimationFrame(() => {
|
||||||
});
|
if (!atBottom.current) return;
|
||||||
|
view.scrollTo({ top: view.scrollHeight, behavior: "instant" });
|
||||||
|
setShowJump(false);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
// 同时观察内容与可视区:视觉打字、结束后的操作栏、输入框和软键盘都会改变底部位置。
|
||||||
|
const observer = new ResizeObserver(follow);
|
||||||
observer.observe(el);
|
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]);
|
}, [conversationId]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!conversationId) return;
|
if (!conversationId) return;
|
||||||
@@ -396,6 +460,7 @@ export function DigitalHome({
|
|||||||
setActiveMessage(null);
|
setActiveMessage(null);
|
||||||
setShowMenu(false);
|
setShowMenu(false);
|
||||||
atBottom.current = true;
|
atBottom.current = true;
|
||||||
|
setShowJump(false);
|
||||||
try {
|
try {
|
||||||
setDraft(sessionStorage.getItem(`dh-draft:${id}`) ?? "");
|
setDraft(sessionStorage.getItem(`dh-draft:${id}`) ?? "");
|
||||||
} catch {
|
} catch {
|
||||||
@@ -445,7 +510,7 @@ export function DigitalHome({
|
|||||||
favoritePending.current = false;
|
favoritePending.current = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function send(mode: "send" | "regenerate" = "send") {
|
async function send(mode: "send" | "regenerate" | "continue" = "send") {
|
||||||
if (
|
if (
|
||||||
!conversation ||
|
!conversation ||
|
||||||
busy ||
|
busy ||
|
||||||
@@ -455,13 +520,14 @@ export function DigitalHome({
|
|||||||
return;
|
return;
|
||||||
closeIdeas();
|
closeIdeas();
|
||||||
const id = conversation.id,
|
const id = conversation.id,
|
||||||
content = draft.trim(),
|
content = mode === "send" ? draft.trim() : "",
|
||||||
requestId = crypto.randomUUID();
|
requestId = crypto.randomUUID();
|
||||||
let assistantId = `pending-${requestId}`;
|
let assistantId = `pending-${requestId}`;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError("");
|
setError("");
|
||||||
setNotice("");
|
setNotice("");
|
||||||
atBottom.current = true;
|
atBottom.current = true;
|
||||||
|
setShowJump(false);
|
||||||
streamingId.current = id;
|
streamingId.current = id;
|
||||||
if (mode === "send") {
|
if (mode === "send") {
|
||||||
setDraft("");
|
setDraft("");
|
||||||
@@ -792,7 +858,11 @@ export function DigitalHome({
|
|||||||
await digital(`conversations/${conversation.id}`, "PATCH", { settings });
|
await digital(`conversations/${conversation.id}`, "PATCH", { settings });
|
||||||
setConversation((c) => (c ? { ...c, settings } : c));
|
setConversation((c) => (c ? { ...c, settings } : c));
|
||||||
setShowSettings(false);
|
setShowSettings(false);
|
||||||
setNotice("对话设定已保存,下次回复生效");
|
setNotice(
|
||||||
|
stylePolicy === "managed"
|
||||||
|
? "设定已保存;当前叙事风格仍由统一方案控制"
|
||||||
|
: "对话设定已保存,下次回复生效",
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reportError(e);
|
reportError(e);
|
||||||
}
|
}
|
||||||
@@ -872,7 +942,15 @@ export function DigitalHome({
|
|||||||
<legend className={inSheet ? "dh-visually-hidden" : undefined}>
|
<legend className={inSheet ? "dh-visually-hidden" : undefined}>
|
||||||
叙事风格
|
叙事风格
|
||||||
</legend>
|
</legend>
|
||||||
<p className="dh-style-help">为这段故事选一种氛围</p>
|
<p className="dh-style-help" role="status">
|
||||||
|
{stylePolicy === "loading"
|
||||||
|
? "正在确认风格设置…"
|
||||||
|
: stylePolicy === "managed"
|
||||||
|
? "当前使用统一叙事风格。可以保存个人偏好,统一风格解除后采用。"
|
||||||
|
: stylePolicy === "unknown"
|
||||||
|
? "暂时无法确认当前风格,可以先保存个人偏好。"
|
||||||
|
: "为这段故事选一种氛围,也可以跟随角色默认风格。"}
|
||||||
|
</p>
|
||||||
<div className="dh-style-options">
|
<div className="dh-style-options">
|
||||||
{[
|
{[
|
||||||
{
|
{
|
||||||
@@ -886,8 +964,7 @@ export function DigitalHome({
|
|||||||
{
|
{
|
||||||
id: value,
|
id: value,
|
||||||
name: "当前会话风格",
|
name: "当前会话风格",
|
||||||
description:
|
description: "这个风格暂不可用,回复时会采用可用的默认风格。",
|
||||||
"此风格暂不在可选列表中,可以保留或选择其他风格。",
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
@@ -905,9 +982,6 @@ export function DigitalHome({
|
|||||||
onChange={() => onChange(p.id || undefined)}
|
onChange={() => onChange(p.id || undefined)}
|
||||||
/>
|
/>
|
||||||
<span className="dh-style-card">
|
<span className="dh-style-card">
|
||||||
<span className="dh-style-symbol" aria-hidden="true">
|
|
||||||
{p.id ? <WandSparkles /> : <Sparkles />}
|
|
||||||
</span>
|
|
||||||
<span className="dh-style-copy">
|
<span className="dh-style-copy">
|
||||||
<strong>{p.name}</strong>
|
<strong>{p.name}</strong>
|
||||||
<small>{p.description || "以这套风格继续你们的故事。"}</small>
|
<small>{p.description || "以这套风格继续你们的故事。"}</small>
|
||||||
@@ -960,7 +1034,12 @@ export function DigitalHome({
|
|||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const modern = boot?.decision.variant === "B";
|
// UI按消费者返回值决定,组名仅用于归因;C到Z同样可以返回新版UI。
|
||||||
|
// 缺少value时兼容尚未升级的服务响应。
|
||||||
|
const modern =
|
||||||
|
boot?.decision.value !== undefined
|
||||||
|
? boot.decision.value === "new" || boot.decision.value === true
|
||||||
|
: boot?.decision.variant === "B";
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`dh-app ${modern ? "dh-modern" : "dh-classic"} ${conversation ? "dh-in-chat" : ""}`}
|
className={`dh-app ${modern ? "dh-modern" : "dh-classic"} ${conversation ? "dh-in-chat" : ""}`}
|
||||||
@@ -1051,6 +1130,7 @@ export function DigitalHome({
|
|||||||
aria-label="对话设定"
|
aria-label="对话设定"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSettings(conversation.settings);
|
setSettings(conversation.settings);
|
||||||
|
setStylePolicy("loading");
|
||||||
setShowSettings(true);
|
setShowSettings(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1088,12 +1168,45 @@ export function DigitalHome({
|
|||||||
<div
|
<div
|
||||||
className="dh-messages"
|
className="dh-messages"
|
||||||
ref={viewport}
|
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={() => {
|
onScroll={() => {
|
||||||
const v = viewport.current;
|
const v = viewport.current;
|
||||||
if (v) {
|
if (v) {
|
||||||
atBottom.current =
|
const gap = v.scrollHeight - v.scrollTop - v.clientHeight;
|
||||||
v.scrollHeight - v.scrollTop - v.clientHeight < 110;
|
if (gap <= 2) atBottom.current = true;
|
||||||
setShowJump(!atBottom.current);
|
else if (draggingScroll.current) atBottom.current = false;
|
||||||
|
setShowJump(!atBottom.current && gap > 80);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1129,13 +1242,6 @@ export function DigitalHome({
|
|||||||
m.id === activeMessage && m.status === "generating"
|
m.id === activeMessage && m.status === "generating"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{!m.content && m.status === "generating" && (
|
|
||||||
<span className="dh-thinking">
|
|
||||||
<i />
|
|
||||||
<i />
|
|
||||||
<i />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{!busy && m.content && (
|
{!busy && m.content && (
|
||||||
<div className="dh-message-actions">
|
<div className="dh-message-actions">
|
||||||
@@ -1214,9 +1320,10 @@ export function DigitalHome({
|
|||||||
className="dh-jump"
|
className="dh-jump"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
atBottom.current = true;
|
atBottom.current = true;
|
||||||
|
setShowJump(false);
|
||||||
viewport.current?.scrollTo({
|
viewport.current?.scrollTo({
|
||||||
top: viewport.current.scrollHeight,
|
top: viewport.current.scrollHeight,
|
||||||
behavior: "smooth",
|
behavior: "instant",
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1286,6 +1393,7 @@ export function DigitalHome({
|
|||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
<div className="dh-compose-tools">
|
<div className="dh-compose-tools">
|
||||||
|
<div className="dh-compose-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={busy || ideasLoading}
|
disabled={busy || ideasLoading}
|
||||||
@@ -1294,6 +1402,17 @@ export function DigitalHome({
|
|||||||
<Sparkles size={14} />
|
<Sparkles size={14} />
|
||||||
{ideasLoading ? "灵感生成中…" : "灵感回复"}
|
{ideasLoading ? "灵感生成中…" : "灵感回复"}
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="让角色继续"
|
||||||
|
title="不发送输入框里的草稿,让角色接着说"
|
||||||
|
disabled={busy || ideasLoading || !canContinue}
|
||||||
|
onClick={() => send("continue")}
|
||||||
|
>
|
||||||
|
<ChevronRight size={14} />
|
||||||
|
继续
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="dh-mobile-linebreak"
|
className="dh-mobile-linebreak"
|
||||||
@@ -1876,7 +1995,7 @@ export function DigitalHome({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="dh-form-note">
|
<p className="dh-form-note">
|
||||||
保存后从下一次回复生效。可以固定单条消息,将它加入对话记忆。
|
保存后用于接下来的回复。固定单条消息,可将它加入对话记忆。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button className="dh-primary" type="submit">
|
<button className="dh-primary" type="submit">
|
||||||
|
|||||||
+78
-44
@@ -762,6 +762,11 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 0 4px 8px;
|
margin: 0 4px 8px;
|
||||||
}
|
}
|
||||||
|
.dh-compose-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
.dh-app .dh-compose-tools button {
|
.dh-app .dh-compose-tools button {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -969,6 +974,11 @@
|
|||||||
color: #d4cbd5;
|
color: #d4cbd5;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
.dh-settings > label small {
|
||||||
|
color: var(--dh-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.7;
|
||||||
|
}
|
||||||
.dh-profile-form textarea,
|
.dh-profile-form textarea,
|
||||||
.dh-settings textarea {
|
.dh-settings textarea {
|
||||||
resize: vertical;
|
resize: vertical;
|
||||||
@@ -1169,8 +1179,8 @@
|
|||||||
}
|
}
|
||||||
.dh-style-options {
|
.dh-style-options {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
grid-template-columns: minmax(0, 1fr);
|
||||||
gap: 10px;
|
gap: 0;
|
||||||
}
|
}
|
||||||
.dh-style-option {
|
.dh-style-option {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -1178,10 +1188,6 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
-webkit-tap-highlight-color: transparent;
|
-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 {
|
.dh-style-option > input {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 1px;
|
width: 1px;
|
||||||
@@ -1195,41 +1201,26 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
height: 100%;
|
min-height: 72px;
|
||||||
min-height: 88px;
|
padding: 14px 10px;
|
||||||
padding: 15px 13px;
|
border: 0;
|
||||||
border: 1px solid #ffffff17;
|
border-bottom: 1px solid var(--dh-line);
|
||||||
border-radius: 13px;
|
border-radius: 0;
|
||||||
background: color-mix(in srgb, var(--dh-soft) 60%, var(--dh-panel));
|
background: transparent;
|
||||||
transition:
|
transition:
|
||||||
border-color 160ms,
|
border-color 160ms,
|
||||||
background 160ms;
|
background 160ms;
|
||||||
}
|
}
|
||||||
.dh-style-option:hover .dh-style-card {
|
.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 {
|
.dh-style-option > input:checked + .dh-style-card {
|
||||||
border-color: var(--dh-accent);
|
background: color-mix(in srgb, var(--dh-accent) 7%, transparent);
|
||||||
background: color-mix(in srgb, var(--dh-accent) 9%, var(--dh-panel));
|
|
||||||
}
|
}
|
||||||
.dh-style-option > input:focus-visible + .dh-style-card {
|
.dh-style-option > input:focus-visible + .dh-style-card {
|
||||||
outline: 2px solid var(--dh-accent);
|
outline: 2px solid var(--dh-accent);
|
||||||
outline-offset: 3px;
|
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 {
|
.dh-style-copy {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -1256,8 +1247,7 @@
|
|||||||
height: 17px;
|
height: 17px;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
color: transparent;
|
color: transparent;
|
||||||
border: 1px solid #ffffff30;
|
border: 0;
|
||||||
border-radius: 50%;
|
|
||||||
}
|
}
|
||||||
.dh-style-check svg {
|
.dh-style-check svg {
|
||||||
width: 11px;
|
width: 11px;
|
||||||
@@ -1265,9 +1255,8 @@
|
|||||||
stroke-width: 3;
|
stroke-width: 3;
|
||||||
}
|
}
|
||||||
.dh-style-option > input:checked + .dh-style-card .dh-style-check {
|
.dh-style-option > input:checked + .dh-style-card .dh-style-check {
|
||||||
color: var(--dh-accent-ink);
|
color: var(--dh-accent);
|
||||||
background: var(--dh-accent);
|
background: transparent;
|
||||||
border-color: var(--dh-accent);
|
|
||||||
}
|
}
|
||||||
@media (width <= 600px) {
|
@media (width <= 600px) {
|
||||||
.dh-style-options {
|
.dh-style-options {
|
||||||
@@ -1357,18 +1346,18 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
.dh-selection-sheet .dh-checkbox {
|
.dh-selection-sheet .dh-checkbox {
|
||||||
min-height: 74px;
|
min-height: 70px;
|
||||||
padding: 14px;
|
padding: 14px 10px;
|
||||||
margin: 0 0 10px;
|
margin: 0;
|
||||||
border: 1px solid #ffffff17;
|
border: 0;
|
||||||
border-radius: 13px;
|
border-bottom: 1px solid var(--dh-line);
|
||||||
|
border-radius: 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.dh-selection-sheet .dh-checkbox.is-selected {
|
.dh-selection-sheet .dh-checkbox.is-selected {
|
||||||
background: color-mix(in srgb, var(--dh-accent) 9%, var(--dh-panel));
|
background: color-mix(in srgb, var(--dh-accent) 7%, transparent);
|
||||||
border-color: var(--dh-accent);
|
|
||||||
}
|
}
|
||||||
.dh-selection-sheet .dh-checkbox:focus-within {
|
.dh-selection-sheet .dh-checkbox:has(input:focus-visible) {
|
||||||
outline: 2px solid var(--dh-accent);
|
outline: 2px solid var(--dh-accent);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
}
|
}
|
||||||
@@ -1601,8 +1590,7 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
scrollbar-width: thin;
|
scrollbar-width: none;
|
||||||
scrollbar-color: #ffffff20 transparent;
|
|
||||||
}
|
}
|
||||||
.dh-messages-inner {
|
.dh-messages-inner {
|
||||||
max-width: 840px;
|
max-width: 840px;
|
||||||
@@ -2289,3 +2277,49 @@
|
|||||||
body:has(.dh-app) .environment-badge {
|
body:has(.dh-app) .environment-badge {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 内部区域保留手势和键盘滚动,不显示系统轨道,也不允许设定表单横向漂移。 */
|
||||||
|
.dh-app,
|
||||||
|
.dh-app * {
|
||||||
|
scrollbar-width: none !important;
|
||||||
|
}
|
||||||
|
.dh-app::-webkit-scrollbar,
|
||||||
|
.dh-app *::-webkit-scrollbar {
|
||||||
|
display: none !important;
|
||||||
|
width: 0 !important;
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
.dh-settings-body,
|
||||||
|
.dh-selection-body,
|
||||||
|
.dh-detail-body,
|
||||||
|
.dh-ideas-list {
|
||||||
|
min-width: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
.dh-settings-body {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.dh-settings-body > label,
|
||||||
|
.dh-settings fieldset,
|
||||||
|
.dh-selection-sheet fieldset {
|
||||||
|
min-width: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.dh-app textarea {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
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";
|
"use client";
|
||||||
|
|
||||||
/** 复用原有账号登录,成功后进入数字人空间。 */
|
/** 独立星港用户账号登录,成功后进入数字人空间。 */
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Eye, EyeOff, LockKeyhole, Smartphone } from "lucide-react";
|
import { Eye, EyeOff, LockKeyhole, Smartphone } from "lucide-react";
|
||||||
import { FormEvent, useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
|
|
||||||
/** 现有账号的登录表单,不保存明文密码。 */
|
/** 独立用户的登录表单,不保存明文密码。 */
|
||||||
export function LoginForm() {
|
export function LoginForm() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/** 登出后的站内跳转,避免反向代理后的内部监听地址泄漏到浏览器。 */
|
||||||
|
|
||||||
|
/** 使用相对 Location 留在当前站点,并拒绝外部地址和 URL 控制字符。 */
|
||||||
|
export function logoutRedirect(next: string | null) {
|
||||||
|
let destination = "/login";
|
||||||
|
if (
|
||||||
|
next?.startsWith("/") &&
|
||||||
|
!/^\/[/\\]/.test(next) &&
|
||||||
|
!/[\\\u0000-\u0020\u007f]/.test(next)
|
||||||
|
) {
|
||||||
|
const local = new URL(next, "https://same-origin.invalid");
|
||||||
|
// 消除点路径后仍须禁止双斜杠,避免 /.//host 被规范化为外站地址。
|
||||||
|
if (local.origin === "https://same-origin.invalid" && !local.pathname.startsWith("//")) {
|
||||||
|
destination = local.pathname + local.search + local.hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Route Handler 可直接返回相对 Location;不使用 request.url(生产中可能是 0.0.0.0)。
|
||||||
|
return new Response(null, { status: 307, headers: { Location: destination } });
|
||||||
|
}
|
||||||
+4
-2
@@ -123,10 +123,12 @@ export type Bootstrap = {
|
|||||||
catalog: Card[];
|
catalog: Card[];
|
||||||
profile: Profile;
|
profile: Profile;
|
||||||
decision: {
|
decision: {
|
||||||
variant: "A" | "B";
|
variant: string | null;
|
||||||
|
value?: unknown;
|
||||||
|
fallbackValue?: unknown;
|
||||||
decisionId: string | null;
|
decisionId: string | null;
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
fallbackVariant: "A" | "B";
|
fallbackVariant: string | null;
|
||||||
};
|
};
|
||||||
serverNow: number;
|
serverNow: number;
|
||||||
};
|
};
|
||||||
|
|||||||
+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 = {
|
export type Role = {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/** 回归登录过期后的跳转:仅返回站内路径,不把服务监听地址发送给浏览器。 */
|
||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { logoutRedirect } from '../src/lib/auth-redirect.ts';
|
||||||
|
|
||||||
|
test('登录过期后跳回当前站点的登录页,不依赖服务内部地址', () => {
|
||||||
|
const response = logoutRedirect(null);
|
||||||
|
assert.equal(response.status, 307);
|
||||||
|
assert.equal(response.headers.get('location'), '/login');
|
||||||
|
assert.equal(new URL(response.headers.get('location'), 'https://mrzhan.top/api/auth/logout').href, 'https://mrzhan.top/login');
|
||||||
|
assert.equal(new URL(response.headers.get('location'), 'http://localhost:3210/api/auth/logout').href, 'http://localhost:3210/login');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('保留站内路径和查询参数', () => {
|
||||||
|
assert.equal(logoutRedirect('/login?reason=expired').headers.get('location'), '/login?reason=expired');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('拒绝外部链接、协议相对地址及反斜杠变体', () => {
|
||||||
|
for (const next of ['https://example.com', '//example.com', '/\\example.com', 'javascript:alert(1)', '\n//example.com', '/\n/example.com', '/.//example.com', '/%2e//example.com']) {
|
||||||
|
assert.equal(logoutRedirect(next).headers.get('location'), '/login', next);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user