@njuptlzf/agent-chat-web 0.2.0 → 0.4.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 +7 -1
- package/dist/AgentChat.js +35 -5
- package/dist/AgentChatApp.d.ts +4 -1
- package/dist/AgentChatApp.js +2 -2
- package/dist/PersonasPage.js +8 -0
- package/dist/adapter.d.ts +9 -0
- package/dist/adapter.js +15 -0
- package/dist/mount.d.ts +7 -1
- package/dist/mount.js +2 -2
- package/dist/styles.css +1505 -1478
- package/dist/suggestions.d.ts +41 -0
- package/dist/suggestions.js +98 -0
- package/dist/ui/FollowUpSuggestions.d.ts +9 -0
- package/dist/ui/FollowUpSuggestions.js +13 -0
- package/dist/ui/Icon.d.ts +8 -0
- package/dist/ui/Icon.js +26 -0
- package/dist/ui/MemberCards.d.ts +15 -0
- package/dist/ui/MemberCards.js +13 -0
- package/dist/ui/icons.d.ts +19 -0
- package/dist/ui/icons.js +25 -0
- package/dist/ui/members.d.ts +42 -0
- package/dist/ui/members.js +53 -0
- package/dist/ui/slots.d.ts +29 -0
- package/dist/ui/slots.js +14 -0
- package/package.json +71 -72
- package/src/App.tsx +13 -13
- package/src/agent-chat/AgentChat.tsx +741 -692
- package/src/agent-chat/AgentChatApp.tsx +211 -206
- package/src/agent-chat/DockPanel.tsx +73 -73
- package/src/agent-chat/PersonasPage.tsx +705 -678
- package/src/agent-chat/adapter.ts +293 -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 +130 -123
- package/src/agent-chat/qual.ts +55 -55
- package/src/agent-chat/sse.ts +104 -104
- package/src/agent-chat/suggestions.ts +127 -0
- 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/FollowUpSuggestions.tsx +28 -0
- package/src/agent-chat/ui/Icon.tsx +53 -0
- package/src/agent-chat/ui/Lightbox.tsx +32 -32
- package/src/agent-chat/ui/MemberCards.tsx +46 -0
- 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/icons.ts +31 -0
- package/src/agent-chat/ui/members.ts +106 -0
- package/src/agent-chat/ui/slots.tsx +41 -0
- package/src/agent-chat/ui/timefmt.ts +110 -110
- package/src/agent-chat/ui/useNarrow.ts +20 -20
- package/src/fake-product/entry.tsx +63 -54
- package/src/main.tsx +8 -8
- package/src/styles.css +1505 -1478
package/dist/AgentChat.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { BrandingResponse, ChatCommand } from "@njuptlzf/agent-chat-protocol";
|
|
3
3
|
import { type ThreadMessageLike } from "@assistant-ui/react";
|
|
4
|
-
|
|
4
|
+
import { type Slots } from "./ui/slots.tsx";
|
|
5
|
+
export default function ChatApp({ branding, sessionId, initialMessages, tier, scope, renderCard, slots: slotsOverride, persona, title, policyNote, welcome, suggestions, commands, onRunEnd, onTier, }: {
|
|
5
6
|
branding: BrandingResponse;
|
|
6
7
|
sessionId?: string;
|
|
7
8
|
initialMessages?: readonly ThreadMessageLike[];
|
|
@@ -9,6 +10,11 @@ export default function ChatApp({ branding, sessionId, initialMessages, tier, sc
|
|
|
9
10
|
scope?: string;
|
|
10
11
|
/** 产物卡渲染器:由产品 AppDef 注入,core 不认识 details 的形状。 */
|
|
11
12
|
renderCard?: (details: unknown) => ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* 视觉件槽位覆盖(可插拔):产品可整体替换 Icon / FollowUpSuggestions;
|
|
15
|
+
* 不传 = 全部走平台默认实现。见 ui/slots.tsx 的槽位契约。
|
|
16
|
+
*/
|
|
17
|
+
slots?: Partial<Slots>;
|
|
12
18
|
/**
|
|
13
19
|
* 人格:随每条消息发给服务端;undefined = 产品默认助手。
|
|
14
20
|
* **id 由产品 manifest 声明**,core 不认识具体名字(通用化),
|
package/dist/AgentChat.js
CHANGED
|
@@ -3,6 +3,8 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use
|
|
|
3
3
|
import { ActionBarPrimitive, AuiIf, AssistantRuntimeProvider, ComposerPrimitive, MessagePrimitive, ThreadPrimitive, useAui, useAuiState, useLocalRuntime, useMessageTiming, } from "@assistant-ui/react";
|
|
4
4
|
import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
|
|
5
5
|
import { createChatAdapter, dataUrlToImage, markEdit } from "./adapter.js";
|
|
6
|
+
import { emptyMembersState, reduceMembers } from "./ui/members.js";
|
|
7
|
+
import { createFollowUpAdapter, followUpConfigOf, resolveFollowUpMode } from "./suggestions.js";
|
|
6
8
|
import { docKind, docPart, fileToDoc, MAX_DOCS } from "./docs.js";
|
|
7
9
|
import { auth } from "./auth.js";
|
|
8
10
|
import { dockStore, subscribeChat } from "./dock.js";
|
|
@@ -11,16 +13,19 @@ import { ConfirmCard } from "./ui/ConfirmCard.js";
|
|
|
11
13
|
import CodeCopyHeader from "./ui/CodeCopyHeader.js";
|
|
12
14
|
import { Lightbox } from "./ui/Lightbox.js";
|
|
13
15
|
import { QueueBar } from "./ui/QueueBar.js";
|
|
16
|
+
import { resolveSlots, SlotsProvider, useSlots } from "./ui/slots.js";
|
|
14
17
|
import { TierPicker } from "./ui/TierPicker.js";
|
|
15
18
|
import ThemeToggle from "./ui/ThemeToggle.js";
|
|
16
19
|
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, }) {
|
|
20
|
+
export default function ChatApp({ branding, sessionId, initialMessages, tier, scope, renderCard, slots: slotsOverride, persona, title, policyNote, welcome, suggestions, commands, onRunEnd, onTier, }) {
|
|
18
21
|
const [running, setRunning] = useState(false);
|
|
19
22
|
const [queue, setQueue] = useState([]);
|
|
20
23
|
const [usage, setUsage] = useState(null);
|
|
21
24
|
const [confirms, setConfirms] = useState([]);
|
|
22
25
|
const [uiPrompts, setUiPrompts] = useState([]);
|
|
23
26
|
const [notices, setNotices] = useState([]);
|
|
27
|
+
// 多 phase 成员卡片(W4):member_* / run_done 事件逐帧归集;档 1 恒为 emptyMembersState。
|
|
28
|
+
const [members, setMembers] = useState(emptyMembersState);
|
|
24
29
|
// 工具中文名(SSE 首帧 tools_meta)——用户视角只显示这句,不显示声明名。
|
|
25
30
|
const [toolLabels, setToolLabels] = useState({});
|
|
26
31
|
const noticeSeq = useRef(0);
|
|
@@ -66,6 +71,7 @@ export default function ChatApp({ branding, sessionId, initialMessages, tier, sc
|
|
|
66
71
|
setNotices((xs) => [...xs, { ...n, key }]);
|
|
67
72
|
setTimeout(() => setNotices((xs) => xs.filter((x) => x.key !== key)), 8000);
|
|
68
73
|
},
|
|
74
|
+
onMember: (ev) => setMembers((prev) => reduceMembers(prev, ev)),
|
|
69
75
|
}), [onRunEnd]);
|
|
70
76
|
// A7: thumbs up/down. The official FeedbackAdapter hook gives us the rated
|
|
71
77
|
// message; the client message id is an opaque ref (the server's own messageId
|
|
@@ -78,7 +84,30 @@ export default function ChatApp({ branding, sessionId, initialMessages, tier, sc
|
|
|
78
84
|
void postJson("/api/feedback", { sessionId: sid, rating: type === "positive" ? "up" : "down", ref: message.id }, auth.token).catch(() => { });
|
|
79
85
|
},
|
|
80
86
|
}), []);
|
|
81
|
-
|
|
87
|
+
// 下一步建议:生效模式 = 全局 off 硬地板 > 人格 followUpMode > 全局 mode > llm。
|
|
88
|
+
// adapter 必须 useMemo 稳定引用,否则每次 render 新对象会让库重复生成。
|
|
89
|
+
const followUpCfg = useMemo(() => followUpConfigOf(branding.ui?.followUp), [branding.ui?.followUp]);
|
|
90
|
+
const followUpMode = resolveFollowUpMode(branding, persona);
|
|
91
|
+
const followUpPersona = persona ?? branding.defaultPersona;
|
|
92
|
+
const suggestionAdapter = useMemo(() => (followUpMode === "off" ? undefined : createFollowUpAdapter(followUpCfg, followUpMode, followUpPersona)), [followUpCfg, followUpMode, followUpPersona]);
|
|
93
|
+
const slots = useMemo(() => resolveSlots(slotsOverride), [slotsOverride]);
|
|
94
|
+
const runtime = useLocalRuntime(adapter, {
|
|
95
|
+
initialMessages,
|
|
96
|
+
adapters: {
|
|
97
|
+
feedback: feedbackAdapter,
|
|
98
|
+
// off = 不挂载:库拿到 undefined 直接不生成,零开销。
|
|
99
|
+
...(suggestionAdapter ? { suggestion: suggestionAdapter } : {}),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const { FollowUpSuggestions, MemberCards } = useSlots();
|
|
103
|
+
// 成员的展示名:branding 下发的 persona label(只展示字段),id 兜底。
|
|
104
|
+
const memberLabels = useMemo(() => {
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const [id, ui] of Object.entries(branding.personas ?? {}))
|
|
107
|
+
if (ui.label)
|
|
108
|
+
out[id] = ui.label;
|
|
109
|
+
return out;
|
|
110
|
+
}, [branding.personas]);
|
|
82
111
|
const answerConfirm = useCallback((info, allow) => {
|
|
83
112
|
setConfirms((c) => c.filter((x) => x.toolCallId !== info.toolCallId));
|
|
84
113
|
void postDecision({ sessionId: info.sessionId, toolCallId: info.toolCallId, allow }, auth.token);
|
|
@@ -143,7 +172,7 @@ export default function ChatApp({ branding, sessionId, initialMessages, tier, sc
|
|
|
143
172
|
runtime.thread.cancelRun();
|
|
144
173
|
};
|
|
145
174
|
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, {})] })] }) }));
|
|
175
|
+
return (_jsx(AssistantRuntimeProvider, { runtime: runtime, children: _jsx(SlotsProvider, { value: slots, 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" })] }), _jsx(FollowUpSuggestions, {}), 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))) })), _jsx(MemberCards, { members: members.members, labels: memberLabels }), 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, attachIconSpec: branding.ui?.icons?.attachment, onStop: () => runtime.thread.cancelRun() }), _jsx(Lightbox, {})] })] }) }) }));
|
|
147
176
|
}
|
|
148
177
|
/** Shown while a run is streaming: animated dots + seconds since this run's
|
|
149
178
|
* indicator mounted (unmount/remount per run resets the counter by design). */
|
|
@@ -254,7 +283,8 @@ function ToolCard({ toolName, result, isError, status }) {
|
|
|
254
283
|
const blocked = !isError && Boolean(view.details?.blocked);
|
|
255
284
|
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
285
|
}
|
|
257
|
-
function Composer({ running, commands, tiers, tier, onTier, onSend, onStop, }) {
|
|
286
|
+
function Composer({ running, commands, tiers, tier, onTier, onSend, attachIconSpec, onStop, }) {
|
|
287
|
+
const { Icon } = useSlots();
|
|
258
288
|
const [text, setText] = useState("");
|
|
259
289
|
const [images, setImages] = useState([]);
|
|
260
290
|
// B4-A: converted documents, held as finished text — the heavy parsing has
|
|
@@ -351,5 +381,5 @@ function Composer({ running, commands, tiers, tier, onTier, onSend, onStop, }) {
|
|
|
351
381
|
}, 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
382
|
void pick(e.target.files);
|
|
353
383
|
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:
|
|
384
|
+
} }), _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: _jsx(Icon, { spec: attachIconSpec }) }), 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
385
|
}
|
package/dist/AgentChatApp.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { BrandingResponse } from "@njuptlzf/agent-chat-protocol";
|
|
3
|
+
import type { Slots } from "./ui/slots.tsx";
|
|
3
4
|
/**
|
|
4
5
|
* agentChat 本体(可独立开源的一层):自己的侧栏(新会话+历史会话)加对话。
|
|
5
6
|
* 零业务知识——标题/欢迎语/档位/指令全部来自服务端 branding 与协议。
|
|
6
7
|
*/
|
|
7
|
-
export default function AgentChatApp({ branding, scope, renderCard, persona, title, policyNote, welcome, suggestions, compact, showBrand, assistantLabel, }: {
|
|
8
|
+
export default function AgentChatApp({ branding, scope, renderCard, slots, persona, title, policyNote, welcome, suggestions, compact, showBrand, assistantLabel, }: {
|
|
8
9
|
branding: BrandingResponse;
|
|
9
10
|
/** Qualification the default persona answers for; undefined runs the product default. */
|
|
10
11
|
scope?: string;
|
|
11
12
|
/** 产物卡渲染器(产品注入,透传给平台聊天组件)。 */
|
|
12
13
|
renderCard?: (details: unknown) => ReactNode;
|
|
14
|
+
/** 视觉件槽位覆盖(可插拔,见 ui/slots.tsx)。 */
|
|
15
|
+
slots?: Partial<Slots>;
|
|
13
16
|
/**
|
|
14
17
|
* 人格:undefined = 产品默认助手。会话列表也按它过滤(见 visibleSessions)。
|
|
15
18
|
* id 由产品 manifest 声明,core 不认识具体名字(通用化)。
|
package/dist/AgentChatApp.js
CHANGED
|
@@ -11,7 +11,7 @@ import { useNarrow } from "./ui/useNarrow.js";
|
|
|
11
11
|
* agentChat 本体(可独立开源的一层):自己的侧栏(新会话+历史会话)加对话。
|
|
12
12
|
* 零业务知识——标题/欢迎语/档位/指令全部来自服务端 branding 与协议。
|
|
13
13
|
*/
|
|
14
|
-
export default function AgentChatApp({ branding, scope, renderCard, persona, title, policyNote, welcome, suggestions, compact = false, showBrand = false, assistantLabel = "助手", }) {
|
|
14
|
+
export default function AgentChatApp({ branding, scope, renderCard, slots, persona, title, policyNote, welcome, suggestions, compact = false, showBrand = false, assistantLabel = "助手", }) {
|
|
15
15
|
const [active, setActive] = useState({ key: 0 });
|
|
16
16
|
const [sessions, setSessions] = useState(null);
|
|
17
17
|
// 不同人格各看各的历史:混在一起的话,点开对方那条就是 persona_mismatch。
|
|
@@ -85,6 +85,6 @@ export default function AgentChatApp({ branding, scope, renderCard, persona, tit
|
|
|
85
85
|
}
|
|
86
86
|
setActive((a) => ({ key: a.key + 1, sessionId: s.sessionId, initialMessages }));
|
|
87
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));
|
|
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, slots: slots, onTier: setTier, commands: commands, onRunEnd: reloadSessions }, active.key));
|
|
89
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
90
|
}
|
package/dist/PersonasPage.js
CHANGED
|
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useState } from "react";
|
|
|
3
3
|
import { apiHeaders, auth } from "./auth.js";
|
|
4
4
|
import { fetchJson } from "./sse.js";
|
|
5
5
|
import { fmtTime } from "./ui/timefmt.js";
|
|
6
|
+
const FOLLOW_UP_OPTIONS = ["off", "static", "llm"];
|
|
6
7
|
const UI_FIELDS = [
|
|
7
8
|
{ key: "label", label: "入口名" },
|
|
8
9
|
{ key: "icon", label: "图标" },
|
|
@@ -14,6 +15,8 @@ const UI_FIELDS = [
|
|
|
14
15
|
{ key: "policyNote", label: "常驻提示条", multiline: true },
|
|
15
16
|
// 快捷问法是一组(表里叫 suggestions):一行一条,空行忽略。
|
|
16
17
|
{ key: "suggestions", label: "快捷问法(一行一条)", multiline: true, list: true },
|
|
18
|
+
// 轮次结束后的下一步建议:闭合三态,用下拉而不是文本框——打错值会被服务端 400。
|
|
19
|
+
{ key: "followUpMode", label: "下一步建议", options: FOLLOW_UP_OPTIONS },
|
|
17
20
|
];
|
|
18
21
|
const SOURCE_TEXT = { manifest: "manifest", file: "已改", draft: "草稿" };
|
|
19
22
|
const ACTION_TEXT = { save: "保存", reset: "恢复默认", rollback: "回滚" };
|
|
@@ -311,6 +314,11 @@ export default function PersonasPage() {
|
|
|
311
314
|
}
|
|
312
315
|
setUi(next);
|
|
313
316
|
};
|
|
317
|
+
// 闭合枚举用下拉:空项 = 清掉覆盖回落出厂值(manifest 值就是默认值)。
|
|
318
|
+
if (f.options) {
|
|
319
|
+
const globalOff = list?.globalFollowUpMode === "off";
|
|
320
|
+
return (_jsxs(_Fragment, { children: [_jsxs("select", { "data-field": f.key, value: value, disabled: globalOff, onChange: (e) => onChange(e.target.value), children: [_jsx("option", { value: "", children: placeholder ? `用出厂值(${placeholder})` : "用出厂值 / 跟随全局" }), f.options.map((o) => (_jsx("option", { value: o, children: o }, o)))] }), globalOff && _jsx("span", { children: "\u5168\u5C40\u5DF2\u5173\u95ED\uFF0C\u6B64\u9879\u6682\u4E0D\u751F\u6548" })] }));
|
|
321
|
+
}
|
|
314
322
|
return f.multiline ? (_jsx("textarea", { "data-field": f.key, rows: f.list ? 3 : 2, value: value, placeholder: placeholder, onChange: (e) => onChange(e.target.value) })) : (_jsx("input", { "data-field": f.key, value: value, placeholder: placeholder, onChange: (e) => onChange(e.target.value) }));
|
|
315
323
|
})()] }, f.key))) }), detail.id === list.defaultPersona && (_jsxs("p", { className: "ps-note", children: ["\u9ED8\u8BA4\u52A9\u624B\u6CA1\u6709\u4FA7\u680F\u5165\u53E3\uFF1A", _jsx("b", { children: "\u56FE\u6807 / \u6807\u7B7E / \u60AC\u505C\u63D0\u793A" }), "\u76EE\u524D\u6CA1\u6709\u5C55\u793A\u4F4D\u7F6E\uFF1B", _jsx("b", { children: "\u5165\u53E3\u540D" }), "\u7528\u5728\u804A\u5929\u7A97\u6807\u9898\uFF0C", _jsx("b", { children: "\u7A7A\u6001\u6807\u9898 / \u63D0\u793A\u6761 / \u5FEB\u6377\u95EE\u6CD5" }), "\u7528\u5728\u5BF9\u8BDD\u7A7A\u6001\u3002"] }))] }), _jsxs("section", { className: "ps-sec", children: [_jsxs("div", { className: "ps-sec-head", children: [_jsx("h3", { children: "\u80FD\u529B\u9762\uFF08\u53EA\u8BFB\uFF09" }), _jsx("span", { className: "ps-note", children: "\u6765\u81EA manifest\uFF0C\u6539\u5B83\u8981\u6539\u4EE3\u7801 + review\uFF1B\u8FD9\u91CC\u53EA\u80FD\u4E34\u65F6\u505C\u7528" })] }), allow === null ? (_jsx("p", { className: "ps-note", children: "\u8BE5\u4EBA\u683C\u6CA1\u6709\u5DE5\u5177\u767D\u540D\u5355\uFF08= \u4E0D\u9650\uFF09\u3002\u505C\u7528\u4ECD\u7136\u751F\u6548\uFF0C\u4F46\u767D\u540D\u5355\u672C\u8EAB\u4E0D\u5728\u8FD9\u91CC\u6539\u3002" })) : allow.length === 0 ? (_jsx("p", { className: "ps-note", children: "\u767D\u540D\u5355\u662F\u7A7A\u6570\u7EC4\uFF1A\u4E00\u4E2A\u5DE5\u5177\u90FD\u4E0D\u7ED9\uFF08\u4E0D\u662F\u300C\u5168\u7ED9\u300D\uFF09\u3002" })) : (_jsx("ul", { className: "ps-tools", children: candidates.map((name) => (_jsx("li", { children: _jsxs("label", { children: [_jsx("input", { type: "checkbox", checked: disabled.includes(name), onChange: (e) => {
|
|
316
324
|
setDisabled((cur) => (e.target.checked ? [...cur, name] : cur.filter((n) => n !== name)));
|
package/dist/adapter.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export interface ChatBridge {
|
|
|
32
32
|
onUiPrompt(prompt: UiPromptEvent): void;
|
|
33
33
|
/** An extension sent a notification; show it, no answer expected. */
|
|
34
34
|
onUiNotify(note: UiNotifyEvent): void;
|
|
35
|
+
/**
|
|
36
|
+
* 多 phase 的成员事件(W4)。缺省 = 旧前端完全不消费成员视图——平台加事件、
|
|
37
|
+
* 产品不接也不会崩(降级契约)。传了就逐帧交给 `reduceMembers`。
|
|
38
|
+
*/
|
|
39
|
+
onMember?(ev: MemberEvent): void;
|
|
35
40
|
}
|
|
36
41
|
/** Mark the next run as an edit. Call it before the composer sends. */
|
|
37
42
|
export declare function markEdit(): void;
|
|
@@ -43,6 +48,10 @@ export type UiPromptEvent = Extract<ChatEvent, {
|
|
|
43
48
|
export type UiNotifyEvent = Extract<ChatEvent, {
|
|
44
49
|
type: "ui_notify";
|
|
45
50
|
}>;
|
|
51
|
+
/** 多 phase 的成员/Run 级事件,交给 ChatBridge 归集成成员卡片(W4)。 */
|
|
52
|
+
export type MemberEvent = Extract<ChatEvent, {
|
|
53
|
+
type: "member_started" | "member_delta" | "member_done" | "run_done";
|
|
54
|
+
}>;
|
|
46
55
|
/**
|
|
47
56
|
* Bridges our SSE wire protocol to assistant-ui's ChatModelAdapter.
|
|
48
57
|
*
|
package/dist/adapter.js
CHANGED
|
@@ -216,10 +216,25 @@ export function createChatAdapter(bridge) {
|
|
|
216
216
|
case "ui_notify":
|
|
217
217
|
bridge.onUiNotify(ev);
|
|
218
218
|
continue;
|
|
219
|
+
case "member_started":
|
|
220
|
+
case "member_delta":
|
|
221
|
+
case "member_done":
|
|
222
|
+
case "run_done":
|
|
223
|
+
// 多 phase 的成员/Run 事件:交给成员视图归集,不进主气泡 parts。
|
|
224
|
+
// 旧 bridge 没传 onMember 时静默丢弃——这就是降级契约(不崩、不污染气泡)。
|
|
225
|
+
bridge.onMember?.(ev);
|
|
226
|
+
// 多 phase 不发 `done`(收口语义由 run_done 承担),状态栏用量在这里补上。
|
|
227
|
+
if (ev.type === "run_done")
|
|
228
|
+
usage ??= ev.usage;
|
|
229
|
+
continue;
|
|
219
230
|
case "done":
|
|
220
231
|
usage ??= ev.usage;
|
|
221
232
|
aborted = ev.aborted;
|
|
222
233
|
continue;
|
|
234
|
+
default:
|
|
235
|
+
// 降级契约显式化:平台未来新增的事件类型,旧前端安全忽略——
|
|
236
|
+
// 不 throw、不往 parts 塞东西(那会污染回答气泡)。
|
|
237
|
+
continue;
|
|
223
238
|
}
|
|
224
239
|
chunks++;
|
|
225
240
|
yield { content: [...parts], metadata: { timing: snapshot() } };
|
package/dist/mount.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { ReactNode } from "react";
|
|
16
16
|
import type { BrandingResponse } from "@njuptlzf/agent-chat-protocol";
|
|
17
17
|
import { useAppHost, type AppDef } from "./app.tsx";
|
|
18
|
+
import type { Slots } from "./ui/slots.tsx";
|
|
18
19
|
/** 宿主状态(`useAppHost` 的返回值):插槽从这里取品牌、身份、路由、人格。 */
|
|
19
20
|
export type AppHost = ReturnType<typeof useAppHost>;
|
|
20
21
|
/** 产品给的界面文案:全由 branding(manifest 声明)与当前人格决定。 */
|
|
@@ -33,6 +34,11 @@ export interface AgentAppProps {
|
|
|
33
34
|
def: AppDef;
|
|
34
35
|
/** 文案兜底:core 不认得任何人格名,也不写死任何一句话。 */
|
|
35
36
|
texts(branding: BrandingResponse, persona: string): AppTexts;
|
|
37
|
+
/**
|
|
38
|
+
* 视觉件槽位覆盖(可插拔):整体替换 Icon / FollowUpSuggestions 等。
|
|
39
|
+
* 组件写结构兼容的形状即可(类型不导出,避免新增公开符号);不传 = 全默认。
|
|
40
|
+
*/
|
|
41
|
+
slots?: Partial<Slots>;
|
|
36
42
|
/** 侧栏底部的产品入口(声明人格、反馈问题…)。闭包,不能调 hook。 */
|
|
37
43
|
footer?(host: AppHost): ReactNode;
|
|
38
44
|
/** 宿主级组件(每日总结、反馈抽屉…)。闭包,不能调 hook。 */
|
|
@@ -47,4 +53,4 @@ export interface AgentAppProps {
|
|
|
47
53
|
* 差别只有一处:人格不再由 core 判断"谁是声明人格"——`host.persona` 原样传给
|
|
48
54
|
* `AgentChatApp`("" 收敛成 undefined = 产品默认助手),文案由 `texts` 决定。
|
|
49
55
|
*/
|
|
50
|
-
export declare function AgentApp({ def, texts, footer, extras, loadErrorHint }: AgentAppProps): import("react").JSX.Element;
|
|
56
|
+
export declare function AgentApp({ def, texts, slots, footer, extras, loadErrorHint }: AgentAppProps): import("react").JSX.Element;
|
package/dist/mount.js
CHANGED
|
@@ -9,7 +9,7 @@ import { AppShell, themeVarsOf, useAppHost } from "./app.js";
|
|
|
9
9
|
* 差别只有一处:人格不再由 core 判断"谁是声明人格"——`host.persona` 原样传给
|
|
10
10
|
* `AgentChatApp`("" 收敛成 undefined = 产品默认助手),文案由 `texts` 决定。
|
|
11
11
|
*/
|
|
12
|
-
export function AgentApp({ def, texts, footer, extras, loadErrorHint }) {
|
|
12
|
+
export function AgentApp({ def, texts, slots, footer, extras, loadErrorHint }) {
|
|
13
13
|
const host = useAppHost(def);
|
|
14
14
|
if (host.loadError) {
|
|
15
15
|
return (_jsxs("div", { className: "center", children: [_jsxs("p", { children: ["\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\uFF1A", host.loadError] }), loadErrorHint] }));
|
|
@@ -32,7 +32,7 @@ export function AgentApp({ def, texts, footer, extras, loadErrorHint }) {
|
|
|
32
32
|
go(r);
|
|
33
33
|
}, onQuals: () => go("quals"), switchTitle: def.labels?.switchTitle, footer: footer?.(host), children: [_jsx(DockPanel, { title: t.title, full: dockFull, onClose: host.closeChat, chat: _jsx(AgentChatApp
|
|
34
34
|
// key 让切人格时重挂:会话绑死人格,同一个实例换 persona 只会撞 persona_mismatch。
|
|
35
|
-
, { branding: branding, scope: qual?.id, renderCard: def.cardRenderer,
|
|
35
|
+
, { branding: branding, scope: qual?.id, renderCard: def.cardRenderer, slots: slots,
|
|
36
36
|
// core 只做形状收敛("" → undefined = 产品默认助手),不认识具体名字。
|
|
37
37
|
persona: persona || undefined, title: t.title, assistantLabel: t.assistantLabel, policyNote: t.policyNote, welcome: t.welcome, suggestions: t.suggestions, compact: !dockFull }, persona), children: def.page(ctx) }), extras?.(host)] }) }));
|
|
38
38
|
}
|