@njuptlzf/agent-chat-web 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgentChat.d.ts +28 -0
- package/dist/AgentChat.js +355 -0
- package/dist/AgentChatApp.d.ts +31 -0
- package/dist/AgentChatApp.js +90 -0
- package/dist/DockPanel.d.ts +22 -0
- package/dist/DockPanel.js +22 -0
- package/dist/PersonasPage.d.ts +1 -0
- package/dist/PersonasPage.js +318 -0
- package/dist/adapter.d.ts +52 -0
- package/dist/adapter.js +242 -0
- package/dist/app-def-check.d.ts +50 -0
- package/dist/app-def-check.js +184 -0
- package/dist/app.d.ts +112 -0
- package/dist/app.js +174 -0
- package/dist/auth.d.ts +41 -0
- package/dist/auth.js +86 -0
- package/dist/dock.d.ts +52 -0
- package/dist/dock.js +132 -0
- package/dist/docs.d.ts +48 -0
- package/dist/docs.js +178 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +8 -0
- package/dist/mount.d.ts +50 -0
- package/dist/mount.js +38 -0
- package/dist/qual.d.ts +21 -0
- package/dist/qual.js +53 -0
- package/dist/sse.d.ts +14 -0
- package/dist/sse.js +99 -0
- package/dist/styles.css +1478 -0
- package/dist/theme.d.ts +10 -0
- package/dist/theme.js +14 -0
- package/dist/ui/CodeCopyHeader.d.ts +7 -0
- package/dist/ui/CodeCopyHeader.js +22 -0
- package/dist/ui/ConfirmCard.d.ts +15 -0
- package/dist/ui/ConfirmCard.js +9 -0
- package/dist/ui/Lightbox.d.ts +6 -0
- package/dist/ui/Lightbox.js +31 -0
- package/dist/ui/QueueBar.d.ts +44 -0
- package/dist/ui/QueueBar.js +17 -0
- package/dist/ui/Splitter.d.ts +27 -0
- package/dist/ui/Splitter.js +61 -0
- package/dist/ui/ThemeToggle.d.ts +2 -0
- package/dist/ui/ThemeToggle.js +16 -0
- package/dist/ui/TierPicker.d.ts +14 -0
- package/dist/ui/TierPicker.js +54 -0
- package/dist/ui/UIPromptCard.d.ts +17 -0
- package/dist/ui/UIPromptCard.js +18 -0
- package/dist/ui/timefmt.d.ts +35 -0
- package/dist/ui/timefmt.js +110 -0
- package/dist/ui/useNarrow.d.ts +7 -0
- package/dist/ui/useNarrow.js +15 -0
- package/package.json +72 -68
- package/src/App.tsx +13 -0
- package/src/agent-chat/AgentChat.tsx +692 -692
- package/src/agent-chat/AgentChatApp.tsx +206 -206
- package/src/agent-chat/{Dock.tsx → DockPanel.tsx} +73 -73
- package/src/agent-chat/PersonasPage.tsx +678 -678
- package/src/agent-chat/adapter.ts +272 -272
- package/src/agent-chat/app-def-check.ts +215 -215
- package/src/agent-chat/app.tsx +327 -327
- package/src/agent-chat/auth.ts +83 -83
- package/src/agent-chat/dock.ts +161 -161
- package/src/agent-chat/docs.ts +179 -179
- package/src/agent-chat/index.ts +17 -17
- package/src/agent-chat/mount.tsx +123 -123
- package/src/agent-chat/qual.ts +55 -55
- package/src/agent-chat/sse.ts +104 -104
- package/src/agent-chat/theme.ts +23 -23
- package/src/agent-chat/ui/CodeCopyHeader.tsx +29 -29
- package/src/agent-chat/ui/ConfirmCard.tsx +32 -32
- package/src/agent-chat/ui/Lightbox.tsx +32 -32
- package/src/agent-chat/ui/QueueBar.tsx +70 -70
- package/src/agent-chat/ui/Splitter.tsx +81 -81
- package/src/agent-chat/ui/ThemeToggle.tsx +25 -25
- package/src/agent-chat/ui/TierPicker.tsx +112 -112
- package/src/agent-chat/ui/UIPromptCard.tsx +68 -68
- package/src/agent-chat/ui/timefmt.ts +110 -110
- package/src/agent-chat/ui/useNarrow.ts +20 -20
- package/src/fake-product/entry.tsx +54 -0
- package/src/main.tsx +8 -0
- package/src/styles.css +1478 -1478
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { BrandingResponse, ChatCommand } from "@njuptlzf/agent-chat-protocol";
|
|
3
|
+
import { type ThreadMessageLike } from "@assistant-ui/react";
|
|
4
|
+
export default function ChatApp({ branding, sessionId, initialMessages, tier, scope, renderCard, persona, title, policyNote, welcome, suggestions, commands, onRunEnd, onTier, }: {
|
|
5
|
+
branding: BrandingResponse;
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
initialMessages?: readonly ThreadMessageLike[];
|
|
8
|
+
tier?: string;
|
|
9
|
+
scope?: string;
|
|
10
|
+
/** 产物卡渲染器:由产品 AppDef 注入,core 不认识 details 的形状。 */
|
|
11
|
+
renderCard?: (details: unknown) => ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* 人格:随每条消息发给服务端;undefined = 产品默认助手。
|
|
14
|
+
* **id 由产品 manifest 声明**,core 不认识具体名字(通用化),
|
|
15
|
+
* 所以这里是普通字符串,不是字面量联合类型。
|
|
16
|
+
*/
|
|
17
|
+
persona?: string;
|
|
18
|
+
/** 对话区列头(2026-11-04):随人格换(声明人格→「人格 B」),缺省回落产品名。 */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** 常驻提示条(如「由 AI 生成,仅供参考」)。只在人格需要说明时传。 */
|
|
21
|
+
policyNote?: string;
|
|
22
|
+
/** 空态文案/快捷问法覆盖(声明人格与默认助手问的不是一类事)。 */
|
|
23
|
+
welcome?: string;
|
|
24
|
+
suggestions?: string[];
|
|
25
|
+
commands: ChatCommand[];
|
|
26
|
+
onRunEnd: () => void;
|
|
27
|
+
onTier: (id: string) => void;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ActionBarPrimitive, AuiIf, AssistantRuntimeProvider, ComposerPrimitive, MessagePrimitive, ThreadPrimitive, useAui, useAuiState, useLocalRuntime, useMessageTiming, } from "@assistant-ui/react";
|
|
4
|
+
import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
|
|
5
|
+
import { createChatAdapter, dataUrlToImage, markEdit } from "./adapter.js";
|
|
6
|
+
import { docKind, docPart, fileToDoc, MAX_DOCS } from "./docs.js";
|
|
7
|
+
import { auth } from "./auth.js";
|
|
8
|
+
import { dockStore, subscribeChat } from "./dock.js";
|
|
9
|
+
import { postDecision, postJson } from "./sse.js";
|
|
10
|
+
import { ConfirmCard } from "./ui/ConfirmCard.js";
|
|
11
|
+
import CodeCopyHeader from "./ui/CodeCopyHeader.js";
|
|
12
|
+
import { Lightbox } from "./ui/Lightbox.js";
|
|
13
|
+
import { QueueBar } from "./ui/QueueBar.js";
|
|
14
|
+
import { TierPicker } from "./ui/TierPicker.js";
|
|
15
|
+
import ThemeToggle from "./ui/ThemeToggle.js";
|
|
16
|
+
import { UIPromptCard } from "./ui/UIPromptCard.js";
|
|
17
|
+
export default function ChatApp({ branding, sessionId, initialMessages, tier, scope, renderCard, persona, title, policyNote, welcome, suggestions, commands, onRunEnd, onTier, }) {
|
|
18
|
+
const [running, setRunning] = useState(false);
|
|
19
|
+
const [queue, setQueue] = useState([]);
|
|
20
|
+
const [usage, setUsage] = useState(null);
|
|
21
|
+
const [confirms, setConfirms] = useState([]);
|
|
22
|
+
const [uiPrompts, setUiPrompts] = useState([]);
|
|
23
|
+
const [notices, setNotices] = useState([]);
|
|
24
|
+
// 工具中文名(SSE 首帧 tools_meta)——用户视角只显示这句,不显示声明名。
|
|
25
|
+
const [toolLabels, setToolLabels] = useState({});
|
|
26
|
+
const noticeSeq = useRef(0);
|
|
27
|
+
const runningRef = useRef(false);
|
|
28
|
+
const queueRef = useRef([]);
|
|
29
|
+
const sessionIdRef = useRef(sessionId);
|
|
30
|
+
const tierRef = useRef(tier);
|
|
31
|
+
const scopeRef = useRef(scope);
|
|
32
|
+
queueRef.current = queue;
|
|
33
|
+
tierRef.current = tier;
|
|
34
|
+
scopeRef.current = scope;
|
|
35
|
+
const adapter = useMemo(() => createChatAdapter({
|
|
36
|
+
getSessionId: () => sessionIdRef.current,
|
|
37
|
+
setSessionId: (id) => {
|
|
38
|
+
sessionIdRef.current = id;
|
|
39
|
+
},
|
|
40
|
+
getContext: () => {
|
|
41
|
+
// One-shot: a page-supplied context belongs to the message that
|
|
42
|
+
// carried it, never to the next thing typed into the box.
|
|
43
|
+
const ctx = contextRef.current;
|
|
44
|
+
contextRef.current = undefined;
|
|
45
|
+
return ctx;
|
|
46
|
+
},
|
|
47
|
+
getAuthToken: () => auth.token,
|
|
48
|
+
getTier: () => tierRef.current,
|
|
49
|
+
getScope: () => scopeRef.current,
|
|
50
|
+
getPersona: () => persona,
|
|
51
|
+
onRunEnd: ({ usage }) => {
|
|
52
|
+
setUsage(usage);
|
|
53
|
+
setConfirms([]);
|
|
54
|
+
setUiPrompts([]);
|
|
55
|
+
runningRef.current = false;
|
|
56
|
+
setRunning(false);
|
|
57
|
+
onRunEnd();
|
|
58
|
+
setTimeout(() => flushRef.current?.(), 0);
|
|
59
|
+
},
|
|
60
|
+
onToolConfirm: (info) => setConfirms((c) => [...c.filter((x) => x.toolCallId !== info.toolCallId), info]),
|
|
61
|
+
onToolSettled: (toolCallId) => setConfirms((c) => c.filter((x) => x.toolCallId !== toolCallId)),
|
|
62
|
+
onToolsMeta: (labels) => setToolLabels(labels),
|
|
63
|
+
onUiPrompt: (p) => setUiPrompts((xs) => [...xs.filter((x) => x.id !== p.id), p]),
|
|
64
|
+
onUiNotify: (n) => {
|
|
65
|
+
const key = ++noticeSeq.current;
|
|
66
|
+
setNotices((xs) => [...xs, { ...n, key }]);
|
|
67
|
+
setTimeout(() => setNotices((xs) => xs.filter((x) => x.key !== key)), 8000);
|
|
68
|
+
},
|
|
69
|
+
}), [onRunEnd]);
|
|
70
|
+
// A7: thumbs up/down. The official FeedbackAdapter hook gives us the rated
|
|
71
|
+
// message; the client message id is an opaque ref (the server's own messageId
|
|
72
|
+
// is a per-run counter, so it cannot anchor a stored answer).
|
|
73
|
+
const feedbackAdapter = useMemo(() => ({
|
|
74
|
+
submit: ({ message, type }) => {
|
|
75
|
+
const sid = sessionIdRef.current;
|
|
76
|
+
if (!sid)
|
|
77
|
+
return;
|
|
78
|
+
void postJson("/api/feedback", { sessionId: sid, rating: type === "positive" ? "up" : "down", ref: message.id }, auth.token).catch(() => { });
|
|
79
|
+
},
|
|
80
|
+
}), []);
|
|
81
|
+
const runtime = useLocalRuntime(adapter, { initialMessages, adapters: { feedback: feedbackAdapter } });
|
|
82
|
+
const answerConfirm = useCallback((info, allow) => {
|
|
83
|
+
setConfirms((c) => c.filter((x) => x.toolCallId !== info.toolCallId));
|
|
84
|
+
void postDecision({ sessionId: info.sessionId, toolCallId: info.toolCallId, allow }, auth.token);
|
|
85
|
+
}, []);
|
|
86
|
+
// Answer an extension dialog. The server pairs it back to the parked run by id;
|
|
87
|
+
// a lost POST is harmless (the prompt fails closed on its own timeout).
|
|
88
|
+
const answerUI = useCallback((prompt, answer) => {
|
|
89
|
+
setUiPrompts((xs) => xs.filter((x) => x.id !== prompt.id));
|
|
90
|
+
const sessionId = sessionIdRef.current;
|
|
91
|
+
if (!sessionId)
|
|
92
|
+
return;
|
|
93
|
+
void postJson("/api/ui-response", { sessionId, id: prompt.id, ...answer }, auth.token).catch(() => { });
|
|
94
|
+
}, []);
|
|
95
|
+
const flush = useCallback(() => {
|
|
96
|
+
const [head, ...rest] = queueRef.current;
|
|
97
|
+
if (!head)
|
|
98
|
+
return;
|
|
99
|
+
setQueue(rest);
|
|
100
|
+
runningRef.current = true;
|
|
101
|
+
setRunning(true);
|
|
102
|
+
runtime.thread.append({ role: "user", content: head });
|
|
103
|
+
}, [runtime]);
|
|
104
|
+
const flushRef = useRef(flush);
|
|
105
|
+
flushRef.current = flush;
|
|
106
|
+
const send = useCallback((raw, images = [], docs = []) => {
|
|
107
|
+
const text = raw.trim();
|
|
108
|
+
if (!text && images.length === 0 && docs.length === 0)
|
|
109
|
+
return;
|
|
110
|
+
const content = [
|
|
111
|
+
...(text ? [{ type: "text", text }] : []),
|
|
112
|
+
...images.map((img) => ({ type: "image", image: `data:${img.mimeType};base64,${img.data}` })),
|
|
113
|
+
// B4-A: converted documents ride file parts; the adapter re-reads them.
|
|
114
|
+
...docs.map((d) => docPart(d)),
|
|
115
|
+
];
|
|
116
|
+
if (runningRef.current) {
|
|
117
|
+
// E2: the whole message waits, images included — the queue stores parts,
|
|
118
|
+
// so a queued attachment is appended with the text that carried it.
|
|
119
|
+
setQueue((q) => [...q, content]);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
runningRef.current = true;
|
|
123
|
+
setRunning(true);
|
|
124
|
+
runtime.thread.append({ role: "user", content });
|
|
125
|
+
}, [runtime]);
|
|
126
|
+
// Host-injected prompts: the dock's sendToChat() hands work to whichever chat
|
|
127
|
+
// is mounted, with the caller's page context attached to that one message.
|
|
128
|
+
const contextRef = useRef(undefined);
|
|
129
|
+
useEffect(() => subscribeChat((task) => {
|
|
130
|
+
contextRef.current = task.context;
|
|
131
|
+
send(task.text);
|
|
132
|
+
}), [send]);
|
|
133
|
+
// 坞(Dock)要知道有没有对话在跑:业务页跳转前据此提示。
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
dockStore.setRunning(running);
|
|
136
|
+
}, [running]);
|
|
137
|
+
// steer: bump one queued item to the front and stop the current run to make room now
|
|
138
|
+
const steer = (i) => {
|
|
139
|
+
setQueue((q) => {
|
|
140
|
+
const item = q[i];
|
|
141
|
+
return item ? [item, ...q.filter((_, j) => j !== i)] : q;
|
|
142
|
+
});
|
|
143
|
+
runtime.thread.cancelRun();
|
|
144
|
+
};
|
|
145
|
+
const drop = (i) => setQueue((q) => q.filter((_, j) => j !== i));
|
|
146
|
+
return (_jsx(AssistantRuntimeProvider, { runtime: runtime, children: _jsxs("div", { className: "chat", children: [_jsxs("header", { className: "chatbar", children: [branding.logo ? _jsx("img", { className: "logo", src: branding.logo, alt: "" }) : null, _jsx("h1", { children: title ?? branding.title }), _jsx(ThemeToggle, {})] }), policyNote && (_jsxs("p", { className: "policy-bar", role: "note", children: [_jsx("span", { className: "policy-dot", "aria-hidden": "true", children: "i" }), _jsx("span", { children: policyNote })] })), _jsxs(ThreadPrimitive.Root, { className: "thread", children: [_jsxs("div", { className: "thread-wrap", children: [_jsxs(ThreadPrimitive.Viewport, { className: "viewport", children: [_jsx(ThreadPrimitive.Empty, { children: _jsxs("div", { className: "welcome", children: [_jsx("p", { children: welcome ?? branding.welcome ?? "有什么可以帮你?" }), (suggestions ?? branding.suggestions ?? []).map((s) => (_jsx("button", { className: "chip", onClick: () => send(s), children: s }, s)))] }) }), _jsx(ToolLabels.Provider, { value: toolLabels, children: _jsx(CardRenderer.Provider, { value: renderCard ?? (() => null), children: _jsx(ThreadPrimitive.Messages, { components: { UserMessage, UserEditComposer, AssistantMessage } }) }) }), _jsx(AuiIf, { condition: (s) => s.thread.isRunning, children: _jsx(RunningIndicator, {}) })] }), _jsx(ThreadPrimitive.ScrollToBottom, { className: "scroll-bottom", title: "\u6EDA\u52A8\u5230\u6700\u65B0", children: "\u2193" })] }), confirms.length > 0 && (_jsx("div", { className: "confirms", children: confirms.map((c) => (_jsx(ConfirmCard, { request: c, onAnswer: (allow) => answerConfirm(c, allow) }, c.toolCallId))) })), notices.length > 0 && (_jsx("div", { className: "notices", children: notices.map((n) => (_jsx("div", { className: `notice ${n.level}`, children: n.message }, n.key))) })), uiPrompts.length > 0 && (_jsx("div", { className: "confirms", children: uiPrompts.map((p) => (_jsx(UIPromptCard, { prompt: p, onAnswer: (a) => answerUI(p, a) }, p.id))) })), queue.length > 0 && _jsx(QueueBar, { queue: queue, onSteer: steer, onDrop: drop }), usage && (_jsxs("div", { className: "statusbar", children: ["\u672C\u6B21\u7528\u91CF ", usage.total, " tokens\uFF08\u8F93\u5165 ", usage.input, " / \u8F93\u51FA ", usage.output, "\uFF09"] })), _jsx(Composer, { running: running, commands: commands, tiers: branding.tiers, tier: tier, onTier: onTier, onSend: send, onStop: () => runtime.thread.cancelRun() }), _jsx(Lightbox, {})] })] }) }));
|
|
147
|
+
}
|
|
148
|
+
/** Shown while a run is streaming: animated dots + seconds since this run's
|
|
149
|
+
* indicator mounted (unmount/remount per run resets the counter by design). */
|
|
150
|
+
function RunningIndicator() {
|
|
151
|
+
const [sec, setSec] = useState(0);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const t = setInterval(() => setSec((s) => s + 1), 1000);
|
|
154
|
+
return () => clearInterval(t);
|
|
155
|
+
}, []);
|
|
156
|
+
return (_jsxs("div", { className: "loading", role: "status", "aria-live": "polite", children: [_jsxs("span", { className: "dots", "aria-hidden": "true", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] }), "\u6B63\u5728\u751F\u6210 ", sec, "s"] }));
|
|
157
|
+
}
|
|
158
|
+
/** Timestamp from the message state; the local runtime fills createdAt for
|
|
159
|
+
* live messages and restored history already carries it (fromThreadMessageLike:
|
|
160
|
+
* `createdAt ?? new Date()`). */
|
|
161
|
+
function MessageTime() {
|
|
162
|
+
const createdAt = useAuiState((s) => s.message.createdAt);
|
|
163
|
+
// E3: the adapter measured the wait for the first visible output; restored
|
|
164
|
+
// history and pre-stream errors carry no timing, so the label just stays away.
|
|
165
|
+
const firstTokenTime = useMessageTiming()?.firstTokenTime;
|
|
166
|
+
const d = new Date(createdAt);
|
|
167
|
+
return (_jsxs("div", { className: "msg-time", children: [`${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`, firstTokenTime !== undefined && _jsxs("span", { className: "msg-ttft", children: ["\u00B7 \u9996\u5B57 ", (firstTokenTime / 1000).toFixed(1), "s"] })] }));
|
|
168
|
+
}
|
|
169
|
+
function UserMessage() {
|
|
170
|
+
return (_jsxs(MessagePrimitive.Root, { className: "msg user", children: [_jsx(MessagePrimitive.Parts, { components: { File: DocChip } }), _jsx(MessageTime, {}), _jsx(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", className: "actions", children: _jsx(ActionBarPrimitive.Edit, { title: "\u7F16\u8F91\u8FD9\u6761\u6D88\u606F\uFF08\u4F1A\u4E22\u5F03\u5B83\u4E4B\u540E\u7684\u56DE\u7B54\u5E76\u91CD\u65B0\u63D0\u95EE\uFF09", children: "\u7F16\u8F91" }) })] }));
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Shown in place of UserMessage while its Edit button is active.
|
|
174
|
+
*
|
|
175
|
+
* assistant-ui picks this by `s.message.composer.isEditing`, so it must be
|
|
176
|
+
* passed as `components.UserEditComposer` — without it the edit state renders
|
|
177
|
+
* the plain bubble and there is no way to type. The attachment strip is not
|
|
178
|
+
* decoration: the edit composer lifts a user message's images out of `content`
|
|
179
|
+
* into `attachments`, so without rendering them the user cannot see what the
|
|
180
|
+
* edit kept (it keeps them; adapter.ts reads both lists).
|
|
181
|
+
*/
|
|
182
|
+
function UserEditComposer() {
|
|
183
|
+
const aui = useAui();
|
|
184
|
+
// ③ Same auto-grow as the main composer (CSS caps it at the token height).
|
|
185
|
+
const taRef = useRef(null);
|
|
186
|
+
const text = useAuiState((s) => s.composer.text);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const el = taRef.current;
|
|
189
|
+
if (!el)
|
|
190
|
+
return;
|
|
191
|
+
el.style.height = "auto";
|
|
192
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
193
|
+
}, [text]);
|
|
194
|
+
// Both submit paths (Enter submits the form; the Send button is a plain
|
|
195
|
+
// button calling send() from onClick) run before the official send, so the
|
|
196
|
+
// flag is set in time. The guard mirrors the library's composerSendDisabled:
|
|
197
|
+
// a submit it would refuse must not leave the flag behind, or the next
|
|
198
|
+
// ordinary message would truncate a turn nobody edited.
|
|
199
|
+
const mark = () => {
|
|
200
|
+
const thread = aui.thread.getState();
|
|
201
|
+
if (!thread.isDisabled && !thread.isRunning && aui.composer.getState().canSend)
|
|
202
|
+
markEdit();
|
|
203
|
+
};
|
|
204
|
+
return (_jsxs(ComposerPrimitive.Root, { className: "edit-composer", onSubmit: mark, children: [_jsx(ComposerPrimitive.Attachments, { components: { Image: EditThumb, File: EditFile } }), _jsx(ComposerPrimitive.Input, { ref: taRef, className: "edit-input", autoFocus: true, submitMode: "enter", "aria-label": "\u7F16\u8F91\u6D88\u606F" }), _jsxs("div", { className: "edit-actions", children: [_jsx(ComposerPrimitive.Cancel, { className: "edit-btn", children: "\u53D6\u6D88" }), _jsx(ComposerPrimitive.Send, { className: "edit-btn primary", onClick: mark, children: "\u91CD\u65B0\u53D1\u9001" })] })] }));
|
|
205
|
+
}
|
|
206
|
+
/** An image kept by the edit composer, read from the attachment in scope. */
|
|
207
|
+
function EditThumb() {
|
|
208
|
+
const image = useAuiState((s) => {
|
|
209
|
+
const part = s.attachment.content?.find((p) => p.type === "image");
|
|
210
|
+
return part?.type === "image" ? part.image : undefined;
|
|
211
|
+
});
|
|
212
|
+
return image ? _jsx("img", { src: image, alt: "\u9644\u4EF6" }) : null;
|
|
213
|
+
}
|
|
214
|
+
/** A converted document kept by the edit composer (B4-A). */
|
|
215
|
+
function EditFile() {
|
|
216
|
+
const doc = useAuiState((s) => {
|
|
217
|
+
const part = s.attachment.content?.find((p) => p.type === "file");
|
|
218
|
+
return part?.type === "file" ? { filename: part.filename, chars: part.data.length } : undefined;
|
|
219
|
+
});
|
|
220
|
+
return doc ? _jsxs("span", { className: "doc-chip", children: ["\uD83D\uDCC4 ", doc.filename ?? "文档", "\uFF08", doc.chars, " \u5B57\u7B26\uFF09"] }) : null;
|
|
221
|
+
}
|
|
222
|
+
/** The document attachment shown inside a sent user bubble. */
|
|
223
|
+
function DocChip({ filename, data }) {
|
|
224
|
+
return (_jsxs("details", { className: "doc-chip", title: "\u4E0A\u4F20\u6587\u4EF6\u5DF2\u7531\u6D4F\u89C8\u5668\u8F6C\u6362\u4E3A\u6587\u672C\u968F\u6D88\u606F\u53D1\u9001", children: [_jsxs("summary", { children: ["\uD83D\uDCC4 ", filename ?? "文档"] }), _jsx("pre", { children: data })] }));
|
|
225
|
+
}
|
|
226
|
+
function AssistantMessage() {
|
|
227
|
+
return (_jsxs(MessagePrimitive.Root, { className: "msg assistant", children: [_jsx(MessagePrimitive.Parts, { components: { Text: MarkdownText, Reasoning: ReasoningBlock, tools: { Fallback: ToolCard } } }), _jsx(MessageTime, {}), _jsxs(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", className: "actions", children: [_jsx(ActionBarPrimitive.Copy, { title: "\u590D\u5236\u56DE\u7B54", children: "\u590D\u5236" }), _jsx(ActionBarPrimitive.Reload, { title: "\u91CD\u65B0\u751F\u6210\uFF08\u65E7\u56DE\u7B54\u4ECD\u7559\u5728\u670D\u52A1\u7AEF\u4E0A\u4E0B\u6587\u91CC\uFF09", children: "\u91CD\u65B0\u751F\u6210" }), _jsx(ActionBarPrimitive.FeedbackPositive, { title: "\u8FD9\u6761\u56DE\u7B54\u6709\u7528", children: "\uD83D\uDC4D" }), _jsx(ActionBarPrimitive.FeedbackNegative, { title: "\u8FD9\u6761\u56DE\u7B54\u6709\u95EE\u9898", children: "\uD83D\uDC4E" })] })] }));
|
|
228
|
+
}
|
|
229
|
+
/** Markdown rendering for answer text; reads its own text from the message part context. */
|
|
230
|
+
function MarkdownText() {
|
|
231
|
+
return _jsx(MarkdownTextPrimitive, { className: "md", smooth: true, components: { CodeHeader: CodeCopyHeader } });
|
|
232
|
+
}
|
|
233
|
+
function ReasoningBlock({ text }) {
|
|
234
|
+
return (_jsxs("details", { className: "reasoning", children: [_jsx("summary", { children: "\u601D\u8003\u8FC7\u7A0B" }), _jsx("div", { className: "reasoning-body", children: text })] }));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 工具的用户可见中文名(SSE 首帧 tools_meta,manifest `agent.toolLabels`)。
|
|
238
|
+
* 用户视角零实现细节(README 边界):不显示 `mcp__<server>__<tool>` 声明名、
|
|
239
|
+
* 不显示参数/结果原始 JSON;受限原因(⛔)是人话,必须直出。
|
|
240
|
+
*/
|
|
241
|
+
const ToolLabels = createContext({});
|
|
242
|
+
/** 产物卡渲染器由产品 AppDef 注入:core 只透传 details,不认识任何业务字段。 */
|
|
243
|
+
const CardRenderer = createContext(() => null);
|
|
244
|
+
/** 通用卡片槽:产品没注入 renderer 时什么也不画。 */
|
|
245
|
+
function CardSlot({ details }) {
|
|
246
|
+
const render = useContext(CardRenderer);
|
|
247
|
+
return _jsx(_Fragment, { children: render(details) });
|
|
248
|
+
}
|
|
249
|
+
function ToolCard({ toolName, result, isError, status }) {
|
|
250
|
+
const labels = useContext(ToolLabels);
|
|
251
|
+
const pending = status?.type === "running";
|
|
252
|
+
// adapter 把结果包成 {text, details}(details 走 protocol 现成通道)。
|
|
253
|
+
const view = (typeof result === "object" && result !== null ? result : { text: String(result ?? "") });
|
|
254
|
+
const blocked = !isError && Boolean(view.details?.blocked);
|
|
255
|
+
return (_jsxs("div", { className: `tool${isError ? " err" : blocked ? " blocked" : ""}`, children: [_jsxs("div", { className: "tool-head", children: [_jsx("span", { className: "tool-name", children: labels[toolName] ?? "调用工具" }), pending && _jsx("span", { className: "tool-run", children: "\u6267\u884C\u4E2D\u2026" }), !pending && isError && _jsx("span", { className: "tool-run bad", children: "\u2717 \u5931\u8D25" }), !pending && blocked && _jsx("span", { className: "tool-run warn", children: "\u26D4 \u53D7\u9650" }), !pending && !isError && !blocked && _jsx("span", { className: "tool-run ok", children: "\u2713 \u5B8C\u6210" })] }), blocked && view.details?.user_message && _jsx("p", { className: "tool-blocked", children: view.details.user_message }), !pending && !isError && !blocked && _jsx(CardSlot, { details: view.details }), isError && view.text && _jsx("pre", { className: "tool-err-text", children: view.text })] }));
|
|
256
|
+
}
|
|
257
|
+
function Composer({ running, commands, tiers, tier, onTier, onSend, onStop, }) {
|
|
258
|
+
const [text, setText] = useState("");
|
|
259
|
+
const [images, setImages] = useState([]);
|
|
260
|
+
// B4-A: converted documents, held as finished text — the heavy parsing has
|
|
261
|
+
// already happened in the browser before anything lands here.
|
|
262
|
+
const [docs, setDocs] = useState([]);
|
|
263
|
+
const [docBusy, setDocBusy] = useState(null);
|
|
264
|
+
const [docError, setDocError] = useState(null);
|
|
265
|
+
const fileRef = useRef(null);
|
|
266
|
+
// ③ Auto-grow: keep the textarea exactly as tall as its content, up to the
|
|
267
|
+
// CSS max-height (after which it scrolls internally).
|
|
268
|
+
const taRef = useRef(null);
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
const el = taRef.current;
|
|
271
|
+
if (!el)
|
|
272
|
+
return;
|
|
273
|
+
el.style.height = "auto";
|
|
274
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
275
|
+
}, [text]);
|
|
276
|
+
// "/" opens the picker: it is UI-only, the server expands the command before
|
|
277
|
+
// the model sees anything. Once a space is typed the command is settled.
|
|
278
|
+
const slash = /^\/([a-z0-9-]*)$/.exec(text)?.[1];
|
|
279
|
+
const matches = slash === undefined ? [] : commands.filter((c) => c.name.startsWith(slash));
|
|
280
|
+
const pickCommand = (name) => setText(`/${name} `);
|
|
281
|
+
const pick = async (fileList) => {
|
|
282
|
+
const pickedImages = [];
|
|
283
|
+
const newDocs = [];
|
|
284
|
+
const errors = [];
|
|
285
|
+
for (const file of Array.from(fileList ?? [])) {
|
|
286
|
+
if (docKind(file.name)) {
|
|
287
|
+
if (docs.length + newDocs.length >= MAX_DOCS) {
|
|
288
|
+
errors.push(`文档最多 ${MAX_DOCS} 个`);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
setDocBusy(file.name);
|
|
292
|
+
setDocError(null);
|
|
293
|
+
try {
|
|
294
|
+
newDocs.push(await fileToDoc(file));
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
errors.push(err.message);
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
setDocBusy(null);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (pickedImages.length < 4) {
|
|
304
|
+
const url = await new Promise((resolve) => {
|
|
305
|
+
const r = new FileReader();
|
|
306
|
+
r.onload = () => resolve(String(r.result));
|
|
307
|
+
r.readAsDataURL(file);
|
|
308
|
+
});
|
|
309
|
+
const image = dataUrlToImage(url);
|
|
310
|
+
if (image)
|
|
311
|
+
pickedImages.push({ url, image });
|
|
312
|
+
else
|
|
313
|
+
errors.push(`暂不支持的文件:${file.name}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (pickedImages.length > 0)
|
|
317
|
+
setImages((prev) => [...prev, ...pickedImages].slice(0, 4));
|
|
318
|
+
if (newDocs.length > 0)
|
|
319
|
+
setDocs((prev) => [...prev, ...newDocs].slice(0, MAX_DOCS));
|
|
320
|
+
setDocError(errors.length > 0 ? errors.join(";") : null);
|
|
321
|
+
};
|
|
322
|
+
const submit = () => {
|
|
323
|
+
const text2 = text.trim();
|
|
324
|
+
if (!text2 && images.length === 0 && docs.length === 0)
|
|
325
|
+
return;
|
|
326
|
+
// Never send while a document is mid-parse: the chip is not in `docs` yet.
|
|
327
|
+
if (docBusy !== null)
|
|
328
|
+
return;
|
|
329
|
+
// An unknown "/foo" is never sent: the server would 400 it, and the picker
|
|
330
|
+
// is the only way to name a command.
|
|
331
|
+
if (text2.startsWith("/") && !commands.some((c) => text2 === `/${c.name}` || text2.startsWith(`/${c.name} `)))
|
|
332
|
+
return;
|
|
333
|
+
onSend(text2, images.map((i) => i.image), docs);
|
|
334
|
+
setText("");
|
|
335
|
+
// E2: the queue carries images too, so the composer always hands them off.
|
|
336
|
+
setImages([]);
|
|
337
|
+
setDocs([]);
|
|
338
|
+
setDocError(null);
|
|
339
|
+
};
|
|
340
|
+
return (_jsxs("div", { className: "composer", children: [matches.length > 0 && (_jsx("div", { className: "cmds", role: "listbox", "aria-label": "\u6307\u4EE4", children: matches.map((c) => (_jsxs("button", { type: "button", className: "cmd", role: "option", "aria-selected": false, onClick: () => pickCommand(c.name), children: [_jsxs("span", { className: "cmd-name", children: ["/", c.name] }), _jsx("span", { className: "cmd-desc", children: c.description })] }, c.name))) })), images.length > 0 && (_jsx("div", { className: "attach", children: images.map((img, i) => (_jsxs("span", { className: "attach-thumb", children: [_jsx("img", { src: img.url, alt: `附件 ${i + 1}` }), _jsx("button", { type: "button", title: "\u79FB\u9664\u56FE\u7247", onClick: () => setImages((p) => p.filter((_, j) => j !== i)), children: "\u00D7" })] }, i))) })), (docs.length > 0 || docBusy !== null) && (_jsxs("div", { className: "attach", children: [docs.map((d, i) => (_jsxs("span", { className: "doc-chip", title: `${d.text.length} 字符${d.truncated ? "(已截断)" : ""}`, children: ["\uD83D\uDCC4 ", d.name, _jsx("button", { type: "button", title: "\u79FB\u9664\u6587\u6863", onClick: () => setDocs((p) => p.filter((_, j) => j !== i)), children: "\u00D7" })] }, i))), docBusy !== null && _jsxs("span", { className: "doc-chip pending", children: ["\u23F3 \u6B63\u5728\u89E3\u6790 ", docBusy, "\u2026"] })] })), docError !== null && _jsx("div", { className: "attach-err", children: docError }), _jsx("textarea", { ref: taRef, rows: 1, value: text, onChange: (e) => setText(e.target.value), onPaste: (e) => {
|
|
341
|
+
const files = Array.from(e.clipboardData.files);
|
|
342
|
+
if (files.length > 0) {
|
|
343
|
+
e.preventDefault();
|
|
344
|
+
void pick(e.clipboardData.files);
|
|
345
|
+
}
|
|
346
|
+
}, onKeyDown: (e) => {
|
|
347
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
348
|
+
e.preventDefault();
|
|
349
|
+
submit();
|
|
350
|
+
}
|
|
351
|
+
}, placeholder: running ? "输入追加需求,将在当前回答后执行…" : "输入问题,Enter 发送(可粘贴或选择图片/文档)" }), _jsx("input", { ref: fileRef, type: "file", accept: "image/png,image/jpeg,image/webp,image/gif,.md,.markdown,.txt,.log,.json,.yaml,.yml,.csv,.tsv,.pdf,.docx,.xlsx,.xlsm", multiple: true, hidden: true, onChange: (e) => {
|
|
352
|
+
void pick(e.target.files);
|
|
353
|
+
e.target.value = "";
|
|
354
|
+
} }), _jsx("button", { type: "button", className: "attach-btn", title: "\u6DFB\u52A0\u56FE\u7247\u6216\u6587\u6863\uFF08\u5404\u6700\u591A 4 \u4E2A\uFF09", onClick: () => fileRef.current?.click(), children: "\uD83D\uDCCE" }), tiers && tiers.length > 0 && _jsx(TierPicker, { tiers: tiers, value: tier, onChange: onTier }), running ? (_jsx("button", { className: "stop", onClick: onStop, children: "\u505C\u6B62" })) : (_jsx("button", { className: "send", disabled: (!text.trim() && images.length === 0 && docs.length === 0) || docBusy !== null, onClick: submit, children: "\u53D1\u9001" }))] }));
|
|
355
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { BrandingResponse } from "@njuptlzf/agent-chat-protocol";
|
|
3
|
+
/**
|
|
4
|
+
* agentChat 本体(可独立开源的一层):自己的侧栏(新会话+历史会话)加对话。
|
|
5
|
+
* 零业务知识——标题/欢迎语/档位/指令全部来自服务端 branding 与协议。
|
|
6
|
+
*/
|
|
7
|
+
export default function AgentChatApp({ branding, scope, renderCard, persona, title, policyNote, welcome, suggestions, compact, showBrand, assistantLabel, }: {
|
|
8
|
+
branding: BrandingResponse;
|
|
9
|
+
/** Qualification the default persona answers for; undefined runs the product default. */
|
|
10
|
+
scope?: string;
|
|
11
|
+
/** 产物卡渲染器(产品注入,透传给平台聊天组件)。 */
|
|
12
|
+
renderCard?: (details: unknown) => ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* 人格:undefined = 产品默认助手。会话列表也按它过滤(见 visibleSessions)。
|
|
15
|
+
* id 由产品 manifest 声明,core 不认识具体名字(通用化)。
|
|
16
|
+
*/
|
|
17
|
+
persona?: string;
|
|
18
|
+
/** 对话区列头:产品随人格给(「人格 B」/「默认助手」),缺省回落产品名。 */
|
|
19
|
+
title?: string;
|
|
20
|
+
policyNote?: string;
|
|
21
|
+
welcome?: string;
|
|
22
|
+
suggestions?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* 助手在界面上的叫法:core 只用于「正在回答」这类提示语,默认「助手」。
|
|
25
|
+
* 产品传自己的(manifest 里的人格 label),core 不认识具体名字。
|
|
26
|
+
*/
|
|
27
|
+
assistantLabel?: string;
|
|
28
|
+
/** 坞里窄栏形态:默认收起会话侧栏(用户手动展开仍然优先)。 */
|
|
29
|
+
compact?: boolean;
|
|
30
|
+
showBrand?: boolean;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import ChatApp from "./AgentChat.js";
|
|
4
|
+
import { auth } from "./auth.js";
|
|
5
|
+
import { confirmInterrupt } from "./dock.js";
|
|
6
|
+
import { fetchJson } from "./sse.js";
|
|
7
|
+
import { Splitter, usePaneWidth } from "./ui/Splitter.js";
|
|
8
|
+
import { groupSessions, relativeTime } from "./ui/timefmt.js";
|
|
9
|
+
import { useNarrow } from "./ui/useNarrow.js";
|
|
10
|
+
/**
|
|
11
|
+
* agentChat 本体(可独立开源的一层):自己的侧栏(新会话+历史会话)加对话。
|
|
12
|
+
* 零业务知识——标题/欢迎语/档位/指令全部来自服务端 branding 与协议。
|
|
13
|
+
*/
|
|
14
|
+
export default function AgentChatApp({ branding, scope, renderCard, persona, title, policyNote, welcome, suggestions, compact = false, showBrand = false, assistantLabel = "助手", }) {
|
|
15
|
+
const [active, setActive] = useState({ key: 0 });
|
|
16
|
+
const [sessions, setSessions] = useState(null);
|
|
17
|
+
// 不同人格各看各的历史:混在一起的话,点开对方那条就是 persona_mismatch。
|
|
18
|
+
// 老会话 persona 为 null ⇒ 按**产品默认助手**算。默认助手的 id 由 branding 下发
|
|
19
|
+
// (通用化),core 不假定它叫什么;老服务端没这个字段时退回协议兜底 id。
|
|
20
|
+
const defaultPersona = branding.defaultPersona ?? "default";
|
|
21
|
+
const visibleSessions = (sessions ?? []).filter((s) => (s.persona ?? defaultPersona) === (persona ?? defaultPersona));
|
|
22
|
+
// Default to the first declared tier so the shown price is always the charged price.
|
|
23
|
+
const [tier, setTier] = useState(branding.tiers?.[0]?.id);
|
|
24
|
+
const [commands, setCommands] = useState([]);
|
|
25
|
+
// 侧栏可拖宽(参考 DSH):默认 210px,160..420px 夹逼,记忆在 localStorage。
|
|
26
|
+
const nav = usePaneWidth("acnav.width", 210, 160, 420);
|
|
27
|
+
// ⑦ 侧栏折叠:状态持久在 localStorage;折叠后由左缘竖条唤回。
|
|
28
|
+
const [collapsed, setCollapsed] = useState(() => localStorage.getItem("acnav.collapsed") === "1");
|
|
29
|
+
// 窄屏自动折叠:150px 业务导航 + 210px 会话栏会把对话区挤没(实测 744px 宽时
|
|
30
|
+
// 会话栏占掉近半)。窄屏只看对话,但用户的显式操作优先——手动展开过就不再自动收。
|
|
31
|
+
const narrow = useNarrow(900);
|
|
32
|
+
const [userPinned, setUserPinned] = useState(false);
|
|
33
|
+
const shownCollapsed = collapsed || (compact ? !userPinned : narrow && !userPinned);
|
|
34
|
+
const toggleCollapsed = () => {
|
|
35
|
+
const next = !shownCollapsed;
|
|
36
|
+
setCollapsed(next);
|
|
37
|
+
setUserPinned(true);
|
|
38
|
+
localStorage.setItem("acnav.collapsed", next ? "1" : "0");
|
|
39
|
+
};
|
|
40
|
+
const reloadSessions = useCallback(() => {
|
|
41
|
+
// Entry decides the visible range: this drawer is reached from a
|
|
42
|
+
// qualification, so it only lists that qualification's sessions. A session
|
|
43
|
+
// is bound to its scope server-side, so a cross-scope row here would only
|
|
44
|
+
// fail to resume.
|
|
45
|
+
const q = scope ? `?scope=${encodeURIComponent(scope)}` : "";
|
|
46
|
+
fetchJson(`/api/sessions${q}`, auth.token)
|
|
47
|
+
.then((r) => setSessions(r.sessions))
|
|
48
|
+
.catch(() => setSessions([]));
|
|
49
|
+
}, [scope]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
// The slash surface is the scope's (S1): refetch when the qualification changes.
|
|
52
|
+
const q = scope ? `?qual=${encodeURIComponent(scope)}` : "";
|
|
53
|
+
fetchJson(`/api/commands${q}`)
|
|
54
|
+
.then((r) => setCommands(r.commands))
|
|
55
|
+
.catch(() => setCommands([]));
|
|
56
|
+
reloadSessions();
|
|
57
|
+
}, [reloadSessions]);
|
|
58
|
+
// Switching scope must start a fresh thread: the previous one belongs to the
|
|
59
|
+
// another persona and the server would reject resuming it (400 scope_mismatch).
|
|
60
|
+
// The "are you sure" prompt lives in App.pick(), before the scope even changes.
|
|
61
|
+
const scopeRef = useRef(scope);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (scopeRef.current === scope)
|
|
64
|
+
return;
|
|
65
|
+
scopeRef.current = scope;
|
|
66
|
+
setActive((a) => ({ key: a.key + 1 }));
|
|
67
|
+
}, [scope]);
|
|
68
|
+
// 换会话会卸掉正在跑的那一轮,先确认(切业务页不算,坞是常驻的)。
|
|
69
|
+
const newSession = () => {
|
|
70
|
+
if (!confirmInterrupt("新建会话", assistantLabel))
|
|
71
|
+
return;
|
|
72
|
+
setActive((a) => ({ key: a.key + 1 }));
|
|
73
|
+
};
|
|
74
|
+
const openSession = async (s) => {
|
|
75
|
+
if (!confirmInterrupt("切换历史会话", assistantLabel))
|
|
76
|
+
return;
|
|
77
|
+
// If the display fetch fails we still resume the session: the server holds the context.
|
|
78
|
+
let initialMessages;
|
|
79
|
+
try {
|
|
80
|
+
const r = await fetchJson(`/api/history?sessionId=${encodeURIComponent(s.sessionId)}`, auth.token);
|
|
81
|
+
initialMessages = r.messages.map((m) => ({ role: m.role, content: m.text, createdAt: new Date(m.at) }));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
initialMessages = undefined;
|
|
85
|
+
}
|
|
86
|
+
setActive((a) => ({ key: a.key + 1, sessionId: s.sessionId, initialMessages }));
|
|
87
|
+
};
|
|
88
|
+
const chat = (_jsx(ChatApp, { branding: branding, persona: persona, title: title, policyNote: policyNote, welcome: welcome, suggestions: suggestions, sessionId: active.sessionId, initialMessages: active.initialMessages, tier: tier, scope: scope, renderCard: renderCard, onTier: setTier, commands: commands, onRunEnd: reloadSessions }, active.key));
|
|
89
|
+
return (_jsxs("div", { className: "ac-row", children: [_jsxs("aside", { className: `side acnav${shownCollapsed ? " collapsed" : ""}`, style: { flexBasis: nav.width }, children: [showBrand && (_jsxs("div", { className: "brand", children: [branding.logo ? _jsx("img", { className: "logo", src: branding.logo, alt: "" }) : null, _jsx("span", { children: branding.title })] })), _jsx("button", { className: "newchat", onClick: newSession, title: "\u91CD\u65B0\u5F00\u59CB\u4E00\u4E2A\u4F1A\u8BDD", children: "\uFF0B \u65B0\u4F1A\u8BDD" }), _jsxs("div", { className: "hist-h", children: ["\u5386\u53F2\u4F1A\u8BDD", _jsx("button", { className: "collapse-btn", onClick: toggleCollapsed, title: "\u6536\u8D77\u4FA7\u680F", children: "\u00AB" })] }), _jsx("div", { className: "sessions", children: sessions === null ? (_jsx("div", { className: "s-empty", children: "\u52A0\u8F7D\u4E2D\u2026" })) : visibleSessions.length === 0 ? (_jsx("div", { className: "s-empty", children: "\u6682\u65E0\u5386\u53F2\u4F1A\u8BDD" })) : (groupSessions(visibleSessions, new Date()).map((g) => (_jsxs("div", { children: [_jsx("div", { className: "s-group", children: g.label }), g.items.map((s) => (_jsxs("button", { className: "s-item", title: s.title, onClick: () => void openSession(s), children: [_jsx("span", { className: "s-title", children: s.title }), _jsxs("span", { className: "s-meta", children: [relativeTime(s.updatedAt, new Date()), " \u00B7 ", s.messageCount, " \u6761"] })] }, s.sessionId)))] }, g.label)))) })] }), !shownCollapsed && _jsx(Splitter, { ...nav.handlers }), shownCollapsed && (_jsxs("button", { className: "side-open", onClick: toggleCollapsed, title: "\u5C55\u5F00\u5386\u53F2\u4F1A\u8BDD\u4FA7\u680F", "aria-label": "\u5C55\u5F00\u5386\u53F2\u4F1A\u8BDD\u4FA7\u680F", children: [_jsx("span", { className: "side-open-arrow", children: "\u00BB" }), _jsx("span", { className: "side-open-text", children: "\u5386\u53F2" })] })), _jsx("main", { className: "content", children: chat })] }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* 聊天坞(agentChat Dock):把对话做成一个"能力",挂在任何业务页右边。
|
|
4
|
+
*
|
|
5
|
+
* 三种形态由 `dock.ts` 的状态机决定:
|
|
6
|
+
* docked 挤压内容区(宽屏默认)
|
|
7
|
+
* floating 悬浮在内容区右下角,不改布局
|
|
8
|
+
* closed 收成右缘竖排唤回按钮(面板用 display:none 藏起来而不是卸载——
|
|
9
|
+
* 对话流、滚动位置、会话视图都要在开关之间活着)
|
|
10
|
+
*
|
|
11
|
+
* `full=true` 是「对话」路由:坞撑满内容区,业务页不渲染。
|
|
12
|
+
*/
|
|
13
|
+
export default function Dock({ chat, full, onClose, title, children, }: {
|
|
14
|
+
/** 对话组件(只挂一份,开关形态之间不重挂)。 */
|
|
15
|
+
chat: ReactNode;
|
|
16
|
+
full?: boolean;
|
|
17
|
+
/** 坞的标题:换人格时这里也要换,否则点了「声明人格」还写着「默认助手」。 */
|
|
18
|
+
title?: string;
|
|
19
|
+
/** 聊天路由下点收起:由宿主决定退到哪个业务页。 */
|
|
20
|
+
onClose?: () => void;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { dockStore, reopenMode, useDockMode } from "./dock.js";
|
|
3
|
+
/**
|
|
4
|
+
* 聊天坞(agentChat Dock):把对话做成一个"能力",挂在任何业务页右边。
|
|
5
|
+
*
|
|
6
|
+
* 三种形态由 `dock.ts` 的状态机决定:
|
|
7
|
+
* docked 挤压内容区(宽屏默认)
|
|
8
|
+
* floating 悬浮在内容区右下角,不改布局
|
|
9
|
+
* closed 收成右缘竖排唤回按钮(面板用 display:none 藏起来而不是卸载——
|
|
10
|
+
* 对话流、滚动位置、会话视图都要在开关之间活着)
|
|
11
|
+
*
|
|
12
|
+
* `full=true` 是「对话」路由:坞撑满内容区,业务页不渲染。
|
|
13
|
+
*/
|
|
14
|
+
export default function Dock({ chat, full = false, onClose, title = "助手", children, }) {
|
|
15
|
+
const mode = useDockMode();
|
|
16
|
+
const shown = full ? "full" : mode;
|
|
17
|
+
const close = () => {
|
|
18
|
+
dockStore.setMode("closed");
|
|
19
|
+
onClose?.();
|
|
20
|
+
};
|
|
21
|
+
return (_jsxs("div", { className: `dock-wrap ${shown}`, children: [!full && _jsx("main", { className: "content", children: children }), _jsxs("aside", { className: `dock-pane${mode === "closed" && !full ? " gone" : ""}`, "aria-label": title, children: [_jsxs("div", { className: "dock-head", children: [_jsx("span", { className: "dock-title", children: title }), full ? null : (_jsx("button", { className: "dock-btn", onClick: () => dockStore.setMode(mode === "floating" ? "docked" : "floating"), title: mode === "floating" ? "停靠到右侧" : "改为悬浮", "aria-label": mode === "floating" ? "停靠到右侧" : "改为悬浮", children: mode === "floating" ? "⇥" : "⤢" })), _jsx("button", { className: "dock-btn", onClick: close, title: `收起${title}`, "aria-label": `收起${title}`, children: "\u00BB" })] }), _jsx("div", { className: "dock-body", children: chat })] }), mode === "closed" && !full && (_jsxs("button", { className: "side-open dock-open", onClick: () => dockStore.setMode(reopenMode(mode, dockStore.lastOpen(), window.innerWidth > 1100)), title: `打开${title}`, "aria-label": `打开${title}`, children: [_jsx("span", { className: "side-open-arrow", children: "\u00AB" }), _jsx("span", { className: "side-open-text", children: title })] }))] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PersonasPage(): import("react").JSX.Element;
|