@njuptlzf/agent-chat-web 0.1.0 → 0.3.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.
Files changed (85) hide show
  1. package/dist/AgentChat.d.ts +34 -0
  2. package/dist/AgentChat.js +373 -0
  3. package/dist/AgentChatApp.d.ts +34 -0
  4. package/dist/AgentChatApp.js +90 -0
  5. package/dist/DockPanel.d.ts +22 -0
  6. package/dist/DockPanel.js +22 -0
  7. package/dist/PersonasPage.d.ts +1 -0
  8. package/dist/PersonasPage.js +326 -0
  9. package/dist/adapter.d.ts +52 -0
  10. package/dist/adapter.js +242 -0
  11. package/dist/app-def-check.d.ts +50 -0
  12. package/dist/app-def-check.js +184 -0
  13. package/dist/app.d.ts +112 -0
  14. package/dist/app.js +174 -0
  15. package/dist/assets/_commonjs-dynamic-modules-TDtrdbi3.js +1 -0
  16. package/dist/assets/exceljs.min-jlEt4kSc.js +29 -0
  17. package/dist/assets/index-B7uSE8SM.css +1 -0
  18. package/dist/assets/index-D57mU5H5.js +50 -0
  19. package/dist/assets/index-Dviy7gnB.js +44 -0
  20. package/dist/assets/pdf-CfhDiWmk.js +55 -0
  21. package/dist/assets/pdf.worker.min-CdXBBzB4.js +1 -0
  22. package/dist/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  23. package/dist/auth.d.ts +41 -0
  24. package/dist/auth.js +86 -0
  25. package/dist/dock.d.ts +52 -0
  26. package/dist/dock.js +132 -0
  27. package/dist/docs.d.ts +48 -0
  28. package/dist/docs.js +178 -0
  29. package/dist/index.d.ts +17 -0
  30. package/dist/index.html +13 -0
  31. package/dist/index.js +8 -0
  32. package/dist/mount.d.ts +56 -0
  33. package/dist/mount.js +38 -0
  34. package/dist/qual.d.ts +21 -0
  35. package/dist/qual.js +53 -0
  36. package/dist/sse.d.ts +14 -0
  37. package/dist/sse.js +99 -0
  38. package/dist/styles.css +1492 -0
  39. package/dist/suggestions.d.ts +41 -0
  40. package/dist/suggestions.js +98 -0
  41. package/dist/theme.d.ts +10 -0
  42. package/dist/theme.js +14 -0
  43. package/dist/ui/CodeCopyHeader.d.ts +7 -0
  44. package/dist/ui/CodeCopyHeader.js +22 -0
  45. package/dist/ui/ConfirmCard.d.ts +15 -0
  46. package/dist/ui/ConfirmCard.js +9 -0
  47. package/dist/ui/FollowUpSuggestions.d.ts +9 -0
  48. package/dist/ui/FollowUpSuggestions.js +13 -0
  49. package/dist/ui/Icon.d.ts +8 -0
  50. package/dist/ui/Icon.js +26 -0
  51. package/dist/ui/Lightbox.d.ts +6 -0
  52. package/dist/ui/Lightbox.js +31 -0
  53. package/dist/ui/QueueBar.d.ts +44 -0
  54. package/dist/ui/QueueBar.js +17 -0
  55. package/dist/ui/Splitter.d.ts +27 -0
  56. package/dist/ui/Splitter.js +61 -0
  57. package/dist/ui/ThemeToggle.d.ts +2 -0
  58. package/dist/ui/ThemeToggle.js +16 -0
  59. package/dist/ui/TierPicker.d.ts +14 -0
  60. package/dist/ui/TierPicker.js +54 -0
  61. package/dist/ui/UIPromptCard.d.ts +17 -0
  62. package/dist/ui/UIPromptCard.js +18 -0
  63. package/dist/ui/icons.d.ts +19 -0
  64. package/dist/ui/icons.js +25 -0
  65. package/dist/ui/slots.d.ts +23 -0
  66. package/dist/ui/slots.js +13 -0
  67. package/dist/ui/timefmt.d.ts +35 -0
  68. package/dist/ui/timefmt.js +110 -0
  69. package/dist/ui/useNarrow.d.ts +7 -0
  70. package/dist/ui/useNarrow.js +15 -0
  71. package/package.json +14 -11
  72. package/src/App.tsx +13 -0
  73. package/src/agent-chat/AgentChat.tsx +39 -2
  74. package/src/agent-chat/AgentChatApp.tsx +5 -0
  75. package/src/agent-chat/{Dock.tsx → DockPanel.tsx} +73 -73
  76. package/src/agent-chat/PersonasPage.tsx +28 -1
  77. package/src/agent-chat/mount.tsx +130 -123
  78. package/src/agent-chat/suggestions.ts +127 -0
  79. package/src/agent-chat/ui/FollowUpSuggestions.tsx +28 -0
  80. package/src/agent-chat/ui/Icon.tsx +53 -0
  81. package/src/agent-chat/ui/icons.ts +31 -0
  82. package/src/agent-chat/ui/slots.tsx +35 -0
  83. package/src/fake-product/entry.tsx +63 -0
  84. package/src/main.tsx +8 -0
  85. package/src/styles.css +15 -1
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 图标值解析:`branding.ui.icons.<槽名>` 的一个字符串怎么画。
3
+ * 三种形态:`svg:<内置名>` / `url:https?://…`(图片地址)/ 其它非空字符串(emoji 或短文本)。
4
+ * 任何非法值都回落默认矢量——图标坏了不该让界面报错,也不该引入任何 HTML 注入面。
5
+ */
6
+ const BUILTIN_SVGS = ["paperclip", "plus", "image", "upload"];
7
+ const DEFAULT_ICON = { kind: "svg", name: "paperclip" };
8
+ const MAX_TEXT = 8;
9
+ export function parseIconSpec(spec) {
10
+ if (spec === undefined || spec === null)
11
+ return DEFAULT_ICON;
12
+ const value = spec.trim();
13
+ if (!value)
14
+ return DEFAULT_ICON;
15
+ if (value.startsWith("svg:")) {
16
+ const name = value.slice(4).trim();
17
+ return BUILTIN_SVGS.includes(name) ? { kind: "svg", name } : DEFAULT_ICON;
18
+ }
19
+ if (value.startsWith("url:")) {
20
+ const href = value.slice(4).trim();
21
+ // 只放行 http(s);相对路径与其它协议一律回落默认(纵深防御,前端兜一道)。
22
+ return /^https?:\/\/\S+$/i.test(href) ? { kind: "url", href } : DEFAULT_ICON;
23
+ }
24
+ return { kind: "text", text: value.length > MAX_TEXT ? value.slice(0, MAX_TEXT) : value };
25
+ }
@@ -0,0 +1,23 @@
1
+ import { type ComponentType } from "react";
2
+ export interface IconProps {
3
+ /** 图标值(`branding.ui.icons` 里该槽的字符串);缺省回落内置矢量。 */
4
+ spec?: string;
5
+ }
6
+ /**
7
+ * 聊天壳的视觉件槽位注册表:所有视觉件要么是 assistant-ui 原生原语,要么是
8
+ * 这里登记的可替换自定义组件——壳体 JSX 不写死字形、不自造建议状态机。
9
+ *
10
+ * `Slots` / `IconProps` **故意不进公共 barrel**(不新增公开导出符号):产品要
11
+ * 整体换皮时,在 `AgentApp` 的 `slots` 里传结构兼容的组件即可,TS 自动对上。
12
+ * 槽组件渲染在 `AssistantRuntimeProvider`(`FollowUpSuggestions` 还在
13
+ * `ThreadPrimitive.Root`)之内,可直接使用库原语;不得反向 import 平台内部路径。
14
+ */
15
+ export interface Slots {
16
+ Icon: ComponentType<IconProps>;
17
+ FollowUpSuggestions: ComponentType;
18
+ }
19
+ export declare const defaultSlots: Slots;
20
+ export declare const SlotsProvider: import("react").Provider<Slots>;
21
+ export declare function useSlots(): Slots;
22
+ /** 纯函数:默认槽位 + 局部覆盖(未覆盖的槽保持默认),不渲染 DOM 即可单测。 */
23
+ export declare function resolveSlots(overrides?: Partial<Slots>): Slots;
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from "react";
2
+ import { Icon } from "./Icon.js";
3
+ import { FollowUpSuggestions } from "./FollowUpSuggestions.js";
4
+ export const defaultSlots = { Icon, FollowUpSuggestions };
5
+ const SlotsContext = createContext(defaultSlots);
6
+ export const SlotsProvider = SlotsContext.Provider;
7
+ export function useSlots() {
8
+ return useContext(SlotsContext);
9
+ }
10
+ /** 纯函数:默认槽位 + 局部覆盖(未覆盖的槽保持默认),不渲染 DOM 即可单测。 */
11
+ export function resolveSlots(overrides) {
12
+ return { ...defaultSlots, ...overrides };
13
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Session-list time helpers (batch 12, DSH-inspired): human relative labels
3
+ * and calendar-day grouping. Pure and `now`-injected so they are testable
4
+ * without a clock mock.
5
+ *
6
+ * 另外提供**绝对时刻**显示(`fmtTime` / `fmtDate`):
7
+ * 服务端一律存 UTC ISO,页面以前直接 `iso.slice(0,16)` 截出来显示——那是 UTC,
8
+ * +08:00 的运维看审计流水/学习记录会以为「8 小时前」。现在统一转成浏览器本地时区。
9
+ */
10
+ /** 刚刚 / N 分钟前 / N 小时前 / 昨天 / M月D日(跨年带年份)。 */
11
+ export declare function relativeTime(iso: string, now: Date): string;
12
+ /** Group label for a session row; buckets follow calendar days, not 24h windows. */
13
+ export declare function groupOf(iso: string, now: Date): string;
14
+ /**
15
+ * Bucket a session list in order. Assumes items are sorted newest-first (the
16
+ * server does that); a newer item after an older one starts a new bucket run
17
+ * rather than being silently merged — same behaviour as DSH's list.
18
+ */
19
+ export declare function groupSessions<T extends {
20
+ updatedAt: string;
21
+ }>(items: readonly T[], now: Date): Array<{
22
+ label: string;
23
+ items: T[];
24
+ }>;
25
+ /**
26
+ * 绝对时刻 → 「2026-11-03 09:12」(本地时区)。
27
+ *
28
+ * - `timeZone` 只给测试用(固定时区做断言);页面调用不传 = 用户本地时区。
29
+ * - 空值显示「—」;**解析不了就原样返回**(不吞、不假装是今天)。
30
+ * - 只喂 ISO 时刻(含 Z 或偏移);别喂「2026-11-03」这种纯日期——那会被当 UTC 零点,
31
+ * 在负时区会退到前一天。
32
+ */
33
+ export declare function fmtTime(iso: string | null | undefined, timeZone?: string): string;
34
+ /** 绝对时刻 → 「2026-11-03」(本地时区)。语义同 `fmtTime`。 */
35
+ export declare function fmtDate(iso: string | null | undefined, timeZone?: string): string;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Session-list time helpers (batch 12, DSH-inspired): human relative labels
3
+ * and calendar-day grouping. Pure and `now`-injected so they are testable
4
+ * without a clock mock.
5
+ *
6
+ * 另外提供**绝对时刻**显示(`fmtTime` / `fmtDate`):
7
+ * 服务端一律存 UTC ISO,页面以前直接 `iso.slice(0,16)` 截出来显示——那是 UTC,
8
+ * +08:00 的运维看审计流水/学习记录会以为「8 小时前」。现在统一转成浏览器本地时区。
9
+ */
10
+ const DAY = 86_400_000;
11
+ function startOfDay(t) {
12
+ const d = new Date(t);
13
+ d.setHours(0, 0, 0, 0);
14
+ return d.getTime();
15
+ }
16
+ /** Whole calendar days between the item's day and today (0 = today, 1 = yesterday). */
17
+ function daysAgo(iso, now) {
18
+ const t = Date.parse(iso);
19
+ if (Number.isNaN(t))
20
+ return 0;
21
+ return Math.round((startOfDay(now.getTime()) - startOfDay(t)) / DAY);
22
+ }
23
+ /** 刚刚 / N 分钟前 / N 小时前 / 昨天 / M月D日(跨年带年份)。 */
24
+ export function relativeTime(iso, now) {
25
+ const t = Date.parse(iso);
26
+ if (Number.isNaN(t))
27
+ return "";
28
+ const diff = now.getTime() - t; // negative (clock skew / future) reads as "刚刚"
29
+ if (diff < 60_000)
30
+ return "刚刚";
31
+ if (diff < 3_600_000)
32
+ return `${Math.floor(diff / 60_000)} 分钟前`;
33
+ const days = daysAgo(iso, now);
34
+ if (days === 0)
35
+ return `${Math.floor(diff / 3_600_000)} 小时前`;
36
+ const d = new Date(t);
37
+ if (days === 1)
38
+ return "昨天";
39
+ const md = `${d.getMonth() + 1}月${d.getDate()}日`;
40
+ return d.getFullYear() === now.getFullYear() ? md : `${d.getFullYear()}年${md}`;
41
+ }
42
+ /** Group label for a session row; buckets follow calendar days, not 24h windows. */
43
+ export function groupOf(iso, now) {
44
+ const days = daysAgo(iso, now);
45
+ if (days <= 0)
46
+ return "今天";
47
+ if (days === 1)
48
+ return "昨天";
49
+ if (days <= 6)
50
+ return "近 7 天";
51
+ if (days <= 29)
52
+ return "近 30 天";
53
+ return "更早";
54
+ }
55
+ /**
56
+ * Bucket a session list in order. Assumes items are sorted newest-first (the
57
+ * server does that); a newer item after an older one starts a new bucket run
58
+ * rather than being silently merged — same behaviour as DSH's list.
59
+ */
60
+ export function groupSessions(items, now) {
61
+ const out = [];
62
+ for (const item of items) {
63
+ const label = groupOf(item.updatedAt, now);
64
+ const last = out[out.length - 1];
65
+ if (last && last.label === label)
66
+ last.items.push(item);
67
+ else
68
+ out.push({ label, items: [item] });
69
+ }
70
+ return out;
71
+ }
72
+ /**
73
+ * 绝对时刻 → 「2026-11-03 09:12」(本地时区)。
74
+ *
75
+ * - `timeZone` 只给测试用(固定时区做断言);页面调用不传 = 用户本地时区。
76
+ * - 空值显示「—」;**解析不了就原样返回**(不吞、不假装是今天)。
77
+ * - 只喂 ISO 时刻(含 Z 或偏移);别喂「2026-11-03」这种纯日期——那会被当 UTC 零点,
78
+ * 在负时区会退到前一天。
79
+ */
80
+ export function fmtTime(iso, timeZone) {
81
+ const parts = fmtParts(iso, timeZone, true);
82
+ if (!parts)
83
+ return iso ? String(iso) : "—";
84
+ return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
85
+ }
86
+ /** 绝对时刻 → 「2026-11-03」(本地时区)。语义同 `fmtTime`。 */
87
+ export function fmtDate(iso, timeZone) {
88
+ const parts = fmtParts(iso, timeZone, false);
89
+ if (!parts)
90
+ return iso ? String(iso) : "—";
91
+ return `${parts.year}-${parts.month}-${parts.day}`;
92
+ }
93
+ function fmtParts(iso, timeZone, withTime) {
94
+ if (!iso)
95
+ return null;
96
+ const d = new Date(iso);
97
+ if (Number.isNaN(d.getTime()))
98
+ return null;
99
+ const parts = new Intl.DateTimeFormat("zh-CN", {
100
+ ...(timeZone ? { timeZone } : {}),
101
+ year: "numeric",
102
+ month: "2-digit",
103
+ day: "2-digit",
104
+ ...(withTime ? { hour: "2-digit", minute: "2-digit" } : {}),
105
+ // h23:不用 hour12:false——某些 ICU 版本会把午夜排成 "24:00"。
106
+ hourCycle: withTime ? "h23" : undefined,
107
+ }).formatToParts(d);
108
+ const get = (type) => parts.find((p) => p.type === type)?.value ?? "";
109
+ return { year: get("year"), month: get("month"), day: get("day"), hour: get("hour"), minute: get("minute") };
110
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 视口是否窄于 maxWidth(响应式布局用)。
3
+ *
4
+ * 用 useSyncExternalStore 而不是 useState+useEffect:首帧就能拿到正确值,
5
+ * 不会出现"先按宽屏渲染再跳成窄屏"的闪动。服务端渲染(无 window)回落 false。
6
+ */
7
+ export declare function useNarrow(maxWidth: number): boolean;
@@ -0,0 +1,15 @@
1
+ import { useSyncExternalStore } from "react";
2
+ /**
3
+ * 视口是否窄于 maxWidth(响应式布局用)。
4
+ *
5
+ * 用 useSyncExternalStore 而不是 useState+useEffect:首帧就能拿到正确值,
6
+ * 不会出现"先按宽屏渲染再跳成窄屏"的闪动。服务端渲染(无 window)回落 false。
7
+ */
8
+ export function useNarrow(maxWidth) {
9
+ const query = `(max-width: ${maxWidth}px)`;
10
+ return useSyncExternalStore((onChange) => {
11
+ const mql = window.matchMedia(query);
12
+ mql.addEventListener("change", onChange);
13
+ return () => mql.removeEventListener("change", onChange);
14
+ }, () => window.matchMedia(query).matches, () => false);
15
+ }
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@njuptlzf/agent-chat-web",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Business-agnostic web chat shell for agentChat products: AgentApp mount, AppDef contract, host panels and HTTP helpers.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./src/agent-chat/index.ts",
10
- "default": "./src/agent-chat/index.ts"
9
+ "agent-chat-source": "./src/agent-chat/index.ts",
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
11
12
  },
12
- "./styles.css": "./src/styles.css",
13
+ "./styles.css": "./dist/styles.css",
13
14
  "./app-def-check": {
14
- "types": "./src/agent-chat/app-def-check.ts",
15
- "default": "./src/agent-chat/app-def-check.ts"
15
+ "agent-chat-source": "./src/agent-chat/app-def-check.ts",
16
+ "types": "./dist/app-def-check.d.ts",
17
+ "default": "./dist/app-def-check.js"
16
18
  },
17
19
  "./package.json": "./package.json"
18
20
  },
19
21
  "files": [
20
- "src/agent-chat",
21
- "src/styles.css"
22
+ "dist",
23
+ "src"
22
24
  ],
23
25
  "repository": {
24
26
  "type": "git",
@@ -48,10 +50,9 @@
48
50
  "preview": "vite preview"
49
51
  },
50
52
  "dependencies": {
51
- "@njuptlzf/agent-chat-protocol": "^0.1.0",
53
+ "@njuptlzf/agent-chat-protocol": "^0.3.0",
52
54
  "@assistant-ui/react": "^0.15.28",
53
55
  "@assistant-ui/react-markdown": "^0.14.22",
54
- "chart.js": "^4.5.1",
55
56
  "exceljs": "^4.4.0",
56
57
  "mammoth": "^1.13.0",
57
58
  "pdfjs-dist": "^6.4.299",
@@ -64,5 +65,7 @@
64
65
  "@vitejs/plugin-react": "^5.0.0",
65
66
  "typescript": "^5.9.0",
66
67
  "vite": "^7.0.0"
67
- }
68
+ },
69
+ "main": "./dist/index.js",
70
+ "types": "./dist/index.d.ts"
68
71
  }
package/src/App.tsx ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 前端入口:**这里只剩选择产品**。
3
+ *
4
+ * 产品的事实(导航注册表、文案、侧栏入口、页面)住在 `apps/web/src/<产品>/entry.tsx`,
5
+ * 机械接线在 core 的 `agent-chat/mount.tsx`。换产品 = 设 `VITE_PRODUCT=<目录名>`
6
+ * 重新构建,**不用改这个文件**。
7
+ *
8
+ * `@product` 由 vite 的 alias 解析(默认产品见 apps/web/products.ts 的 DEFAULT_PRODUCT);
9
+ * tsc 侧由 tsconfig 的 paths 指向默认产品(所有 entry 都在 src 下,都会被类型检查)。
10
+ */
11
+ import { App } from "@product";
12
+
13
+ export default App;
@@ -19,6 +19,7 @@ import {
19
19
  } from "@assistant-ui/react";
20
20
  import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
21
21
  import { createChatAdapter, dataUrlToImage, markEdit, type UiNotifyEvent, type UiPromptEvent } from "./adapter.ts";
22
+ import { createFollowUpAdapter, followUpConfigOf, resolveFollowUpMode } from "./suggestions.ts";
22
23
  import { docKind, docPart, fileToDoc, MAX_DOCS, type DocEntry } from "./docs.ts";
23
24
  import { auth } from "./auth.ts";
24
25
  import { dockStore, subscribeChat } from "./dock.ts";
@@ -27,6 +28,7 @@ import { ConfirmCard, type ConfirmRequest } from "./ui/ConfirmCard.tsx";
27
28
  import CodeCopyHeader from "./ui/CodeCopyHeader.tsx";
28
29
  import { Lightbox } from "./ui/Lightbox.tsx";
29
30
  import { QueueBar, type QueuedMessage, type QueuedPart } from "./ui/QueueBar.tsx";
31
+ import { resolveSlots, SlotsProvider, useSlots, type Slots } from "./ui/slots.tsx";
30
32
  import { TierPicker } from "./ui/TierPicker.tsx";
31
33
  import ThemeToggle from "./ui/ThemeToggle.tsx";
32
34
  import { UIPromptCard } from "./ui/UIPromptCard.tsx";
@@ -38,6 +40,7 @@ export default function ChatApp({
38
40
  tier,
39
41
  scope,
40
42
  renderCard,
43
+ slots: slotsOverride,
41
44
  persona,
42
45
  title,
43
46
  policyNote,
@@ -54,6 +57,11 @@ export default function ChatApp({
54
57
  scope?: string;
55
58
  /** 产物卡渲染器:由产品 AppDef 注入,core 不认识 details 的形状。 */
56
59
  renderCard?: (details: unknown) => ReactNode;
60
+ /**
61
+ * 视觉件槽位覆盖(可插拔):产品可整体替换 Icon / FollowUpSuggestions;
62
+ * 不传 = 全部走平台默认实现。见 ui/slots.tsx 的槽位契约。
63
+ */
64
+ slots?: Partial<Slots>;
57
65
  /**
58
66
  * 人格:随每条消息发给服务端;undefined = 产品默认助手。
59
67
  * **id 由产品 manifest 声明**,core 不认识具体名字(通用化),
@@ -144,7 +152,26 @@ export default function ChatApp({
144
152
  [],
145
153
  );
146
154
 
147
- const runtime = useLocalRuntime(adapter, { initialMessages, adapters: { feedback: feedbackAdapter } });
155
+ // 下一步建议:生效模式 = 全局 off 硬地板 > 人格 followUpMode > 全局 mode > llm。
156
+ // adapter 必须 useMemo 稳定引用,否则每次 render 新对象会让库重复生成。
157
+ const followUpCfg = useMemo(() => followUpConfigOf(branding.ui?.followUp), [branding.ui?.followUp]);
158
+ const followUpMode = resolveFollowUpMode(branding, persona);
159
+ const followUpPersona = persona ?? branding.defaultPersona;
160
+ const suggestionAdapter = useMemo(
161
+ () => (followUpMode === "off" ? undefined : createFollowUpAdapter(followUpCfg, followUpMode, followUpPersona)),
162
+ [followUpCfg, followUpMode, followUpPersona],
163
+ );
164
+ const slots = useMemo(() => resolveSlots(slotsOverride), [slotsOverride]);
165
+
166
+ const runtime = useLocalRuntime(adapter, {
167
+ initialMessages,
168
+ adapters: {
169
+ feedback: feedbackAdapter,
170
+ // off = 不挂载:库拿到 undefined 直接不生成,零开销。
171
+ ...(suggestionAdapter ? { suggestion: suggestionAdapter } : {}),
172
+ },
173
+ });
174
+ const { FollowUpSuggestions } = useSlots();
148
175
 
149
176
  const answerConfirm = useCallback((info: ConfirmRequest, allow: boolean) => {
150
177
  setConfirms((c) => c.filter((x) => x.toolCallId !== info.toolCallId));
@@ -223,6 +250,7 @@ export default function ChatApp({
223
250
 
224
251
  return (
225
252
  <AssistantRuntimeProvider runtime={runtime}>
253
+ <SlotsProvider value={slots}>
226
254
  <div className="chat">
227
255
  <header className="chatbar">
228
256
  {branding.logo ? <img className="logo" src={branding.logo} alt="" /> : null}
@@ -271,6 +299,9 @@ export default function ChatApp({
271
299
  </ThreadPrimitive.ScrollToBottom>
272
300
  </div>
273
301
 
302
+ {/* 轮次结束后的「下一步建议」条(可插拔槽位):数据由库生成,off 时为空。
303
+ 必须在 ThreadPrimitive.Root 内——槽组件直接消费库原语。 */}
304
+ <FollowUpSuggestions />
274
305
  {confirms.length > 0 && (
275
306
  <div className="confirms">
276
307
  {confirms.map((c) => (
@@ -305,11 +336,13 @@ export default function ChatApp({
305
336
  tier={tier}
306
337
  onTier={onTier}
307
338
  onSend={send}
339
+ attachIconSpec={branding.ui?.icons?.attachment}
308
340
  onStop={() => runtime.thread.cancelRun()}
309
341
  />
310
342
  <Lightbox />
311
343
  </ThreadPrimitive.Root>
312
344
  </div>
345
+ </SlotsProvider>
313
346
  </AssistantRuntimeProvider>
314
347
  );
315
348
  }
@@ -518,6 +551,7 @@ function Composer({
518
551
  tier,
519
552
  onTier,
520
553
  onSend,
554
+ attachIconSpec,
521
555
  onStop,
522
556
  }: {
523
557
  running: boolean;
@@ -526,8 +560,11 @@ function Composer({
526
560
  tier?: string;
527
561
  onTier: (id: string) => void;
528
562
  onSend: (t: string, images: ChatImage[], docs: DocEntry[]) => void;
563
+ /** 附件按钮的图标值(`branding.ui.icons.attachment`);组件本身经槽位注册表取。 */
564
+ attachIconSpec?: string;
529
565
  onStop: () => void;
530
566
  }) {
567
+ const { Icon } = useSlots();
531
568
  const [text, setText] = useState("");
532
569
  const [images, setImages] = useState<{ url: string; image: ChatImage }[]>([]);
533
570
  // B4-A: converted documents, held as finished text — the heavy parsing has
@@ -674,7 +711,7 @@ function Composer({
674
711
  }}
675
712
  />
676
713
  <button type="button" className="attach-btn" title="添加图片或文档(各最多 4 个)" onClick={() => fileRef.current?.click()}>
677
- 📎
714
+ <Icon spec={attachIconSpec} />
678
715
  </button>
679
716
  {/* 档位下拉放在发送旁(DSH 选模型的位置);只出现 label/倍率,物理模型名不进浏览器 */}
680
717
  {tiers && tiers.length > 0 && <TierPicker tiers={tiers} value={tier} onChange={onTier} />}
@@ -5,6 +5,7 @@ import ChatApp from "./AgentChat.tsx";
5
5
  import { auth } from "./auth.ts";
6
6
  import { confirmInterrupt } from "./dock.ts";
7
7
  import { fetchJson } from "./sse.ts";
8
+ import type { Slots } from "./ui/slots.tsx";
8
9
  import { Splitter, usePaneWidth } from "./ui/Splitter.tsx";
9
10
  import { groupSessions, relativeTime } from "./ui/timefmt.ts";
10
11
  import { useNarrow } from "./ui/useNarrow.ts";
@@ -24,6 +25,7 @@ export default function AgentChatApp({
24
25
  branding,
25
26
  scope,
26
27
  renderCard,
28
+ slots,
27
29
  persona,
28
30
  title,
29
31
  policyNote,
@@ -38,6 +40,8 @@ export default function AgentChatApp({
38
40
  scope?: string;
39
41
  /** 产物卡渲染器(产品注入,透传给平台聊天组件)。 */
40
42
  renderCard?: (details: unknown) => ReactNode;
43
+ /** 视觉件槽位覆盖(可插拔,见 ui/slots.tsx)。 */
44
+ slots?: Partial<Slots>;
41
45
  /**
42
46
  * 人格:undefined = 产品默认助手。会话列表也按它过滤(见 visibleSessions)。
43
47
  * id 由产品 manifest 声明,core 不认识具体名字(通用化)。
@@ -149,6 +153,7 @@ export default function AgentChatApp({
149
153
  tier={tier}
150
154
  scope={scope}
151
155
  renderCard={renderCard}
156
+ slots={slots}
152
157
  onTier={setTier}
153
158
  commands={commands}
154
159
  onRunEnd={reloadSessions}
@@ -1,74 +1,74 @@
1
- import type { ReactNode } from "react";
2
- import { dockStore, reopenMode, useDockMode, type DockMode } from "./dock.ts";
3
-
4
- /**
5
- * 聊天坞(agentChat Dock):把对话做成一个"能力",挂在任何业务页右边。
6
- *
7
- * 三种形态由 `dock.ts` 的状态机决定:
8
- * docked 挤压内容区(宽屏默认)
9
- * floating 悬浮在内容区右下角,不改布局
10
- * closed 收成右缘竖排唤回按钮(面板用 display:none 藏起来而不是卸载——
11
- * 对话流、滚动位置、会话视图都要在开关之间活着)
12
- *
13
- * `full=true` 是「对话」路由:坞撑满内容区,业务页不渲染。
14
- */
15
- export default function Dock({
16
- chat,
17
- full = false,
18
- onClose,
19
- title = "助手",
20
- children,
21
- }: {
22
- /** 对话组件(只挂一份,开关形态之间不重挂)。 */
23
- chat: ReactNode;
24
- full?: boolean;
25
- /** 坞的标题:换人格时这里也要换,否则点了「声明人格」还写着「默认助手」。 */
26
- title?: string;
27
- /** 聊天路由下点收起:由宿主决定退到哪个业务页。 */
28
- onClose?: () => void;
29
- children?: ReactNode;
30
- }) {
31
- const mode = useDockMode();
32
- const shown: DockMode | "full" = full ? "full" : mode;
33
-
34
- const close = () => {
35
- dockStore.setMode("closed");
36
- onClose?.();
37
- };
38
-
39
- return (
40
- <div className={`dock-wrap ${shown}`}>
41
- {!full && <main className="content">{children}</main>}
42
- <aside className={`dock-pane${mode === "closed" && !full ? " gone" : ""}`} aria-label={title}>
43
- <div className="dock-head">
44
- <span className="dock-title">{title}</span>
45
- {full ? null : (
46
- <button
47
- className="dock-btn"
48
- onClick={() => dockStore.setMode(mode === "floating" ? "docked" : "floating")}
49
- title={mode === "floating" ? "停靠到右侧" : "改为悬浮"}
50
- aria-label={mode === "floating" ? "停靠到右侧" : "改为悬浮"}
51
- >
52
- {mode === "floating" ? "⇥" : "⤢"}
53
- </button>
54
- )}
55
- <button className="dock-btn" onClick={close} title={`收起${title}`} aria-label={`收起${title}`}>
56
- »
57
- </button>
58
- </div>
59
- <div className="dock-body">{chat}</div>
60
- </aside>
61
- {mode === "closed" && !full && (
62
- <button
63
- className="side-open dock-open"
64
- onClick={() => dockStore.setMode(reopenMode(mode, dockStore.lastOpen(), window.innerWidth > 1100))}
65
- title={`打开${title}`}
66
- aria-label={`打开${title}`}
67
- >
68
- <span className="side-open-arrow">«</span>
69
- <span className="side-open-text">{title}</span>
70
- </button>
71
- )}
72
- </div>
73
- );
1
+ import type { ReactNode } from "react";
2
+ import { dockStore, reopenMode, useDockMode, type DockMode } from "./dock.ts";
3
+
4
+ /**
5
+ * 聊天坞(agentChat Dock):把对话做成一个"能力",挂在任何业务页右边。
6
+ *
7
+ * 三种形态由 `dock.ts` 的状态机决定:
8
+ * docked 挤压内容区(宽屏默认)
9
+ * floating 悬浮在内容区右下角,不改布局
10
+ * closed 收成右缘竖排唤回按钮(面板用 display:none 藏起来而不是卸载——
11
+ * 对话流、滚动位置、会话视图都要在开关之间活着)
12
+ *
13
+ * `full=true` 是「对话」路由:坞撑满内容区,业务页不渲染。
14
+ */
15
+ export default function Dock({
16
+ chat,
17
+ full = false,
18
+ onClose,
19
+ title = "助手",
20
+ children,
21
+ }: {
22
+ /** 对话组件(只挂一份,开关形态之间不重挂)。 */
23
+ chat: ReactNode;
24
+ full?: boolean;
25
+ /** 坞的标题:换人格时这里也要换,否则点了「声明人格」还写着「默认助手」。 */
26
+ title?: string;
27
+ /** 聊天路由下点收起:由宿主决定退到哪个业务页。 */
28
+ onClose?: () => void;
29
+ children?: ReactNode;
30
+ }) {
31
+ const mode = useDockMode();
32
+ const shown: DockMode | "full" = full ? "full" : mode;
33
+
34
+ const close = () => {
35
+ dockStore.setMode("closed");
36
+ onClose?.();
37
+ };
38
+
39
+ return (
40
+ <div className={`dock-wrap ${shown}`}>
41
+ {!full && <main className="content">{children}</main>}
42
+ <aside className={`dock-pane${mode === "closed" && !full ? " gone" : ""}`} aria-label={title}>
43
+ <div className="dock-head">
44
+ <span className="dock-title">{title}</span>
45
+ {full ? null : (
46
+ <button
47
+ className="dock-btn"
48
+ onClick={() => dockStore.setMode(mode === "floating" ? "docked" : "floating")}
49
+ title={mode === "floating" ? "停靠到右侧" : "改为悬浮"}
50
+ aria-label={mode === "floating" ? "停靠到右侧" : "改为悬浮"}
51
+ >
52
+ {mode === "floating" ? "⇥" : "⤢"}
53
+ </button>
54
+ )}
55
+ <button className="dock-btn" onClick={close} title={`收起${title}`} aria-label={`收起${title}`}>
56
+ »
57
+ </button>
58
+ </div>
59
+ <div className="dock-body">{chat}</div>
60
+ </aside>
61
+ {mode === "closed" && !full && (
62
+ <button
63
+ className="side-open dock-open"
64
+ onClick={() => dockStore.setMode(reopenMode(mode, dockStore.lastOpen(), window.innerWidth > 1100))}
65
+ title={`打开${title}`}
66
+ aria-label={`打开${title}`}
67
+ >
68
+ <span className="side-open-arrow">«</span>
69
+ <span className="side-open-text">{title}</span>
70
+ </button>
71
+ )}
72
+ </div>
73
+ );
74
74
  }