@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.
Files changed (81) hide show
  1. package/dist/AgentChat.d.ts +28 -0
  2. package/dist/AgentChat.js +355 -0
  3. package/dist/AgentChatApp.d.ts +31 -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 +318 -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/auth.d.ts +41 -0
  16. package/dist/auth.js +86 -0
  17. package/dist/dock.d.ts +52 -0
  18. package/dist/dock.js +132 -0
  19. package/dist/docs.d.ts +48 -0
  20. package/dist/docs.js +178 -0
  21. package/dist/index.d.ts +17 -0
  22. package/dist/index.js +8 -0
  23. package/dist/mount.d.ts +50 -0
  24. package/dist/mount.js +38 -0
  25. package/dist/qual.d.ts +21 -0
  26. package/dist/qual.js +53 -0
  27. package/dist/sse.d.ts +14 -0
  28. package/dist/sse.js +99 -0
  29. package/dist/styles.css +1478 -0
  30. package/dist/theme.d.ts +10 -0
  31. package/dist/theme.js +14 -0
  32. package/dist/ui/CodeCopyHeader.d.ts +7 -0
  33. package/dist/ui/CodeCopyHeader.js +22 -0
  34. package/dist/ui/ConfirmCard.d.ts +15 -0
  35. package/dist/ui/ConfirmCard.js +9 -0
  36. package/dist/ui/Lightbox.d.ts +6 -0
  37. package/dist/ui/Lightbox.js +31 -0
  38. package/dist/ui/QueueBar.d.ts +44 -0
  39. package/dist/ui/QueueBar.js +17 -0
  40. package/dist/ui/Splitter.d.ts +27 -0
  41. package/dist/ui/Splitter.js +61 -0
  42. package/dist/ui/ThemeToggle.d.ts +2 -0
  43. package/dist/ui/ThemeToggle.js +16 -0
  44. package/dist/ui/TierPicker.d.ts +14 -0
  45. package/dist/ui/TierPicker.js +54 -0
  46. package/dist/ui/UIPromptCard.d.ts +17 -0
  47. package/dist/ui/UIPromptCard.js +18 -0
  48. package/dist/ui/timefmt.d.ts +35 -0
  49. package/dist/ui/timefmt.js +110 -0
  50. package/dist/ui/useNarrow.d.ts +7 -0
  51. package/dist/ui/useNarrow.js +15 -0
  52. package/package.json +72 -68
  53. package/src/App.tsx +13 -0
  54. package/src/agent-chat/AgentChat.tsx +692 -692
  55. package/src/agent-chat/AgentChatApp.tsx +206 -206
  56. package/src/agent-chat/{Dock.tsx → DockPanel.tsx} +73 -73
  57. package/src/agent-chat/PersonasPage.tsx +678 -678
  58. package/src/agent-chat/adapter.ts +272 -272
  59. package/src/agent-chat/app-def-check.ts +215 -215
  60. package/src/agent-chat/app.tsx +327 -327
  61. package/src/agent-chat/auth.ts +83 -83
  62. package/src/agent-chat/dock.ts +161 -161
  63. package/src/agent-chat/docs.ts +179 -179
  64. package/src/agent-chat/index.ts +17 -17
  65. package/src/agent-chat/mount.tsx +123 -123
  66. package/src/agent-chat/qual.ts +55 -55
  67. package/src/agent-chat/sse.ts +104 -104
  68. package/src/agent-chat/theme.ts +23 -23
  69. package/src/agent-chat/ui/CodeCopyHeader.tsx +29 -29
  70. package/src/agent-chat/ui/ConfirmCard.tsx +32 -32
  71. package/src/agent-chat/ui/Lightbox.tsx +32 -32
  72. package/src/agent-chat/ui/QueueBar.tsx +70 -70
  73. package/src/agent-chat/ui/Splitter.tsx +81 -81
  74. package/src/agent-chat/ui/ThemeToggle.tsx +25 -25
  75. package/src/agent-chat/ui/TierPicker.tsx +112 -112
  76. package/src/agent-chat/ui/UIPromptCard.tsx +68 -68
  77. package/src/agent-chat/ui/timefmt.ts +110 -110
  78. package/src/agent-chat/ui/useNarrow.ts +20 -20
  79. package/src/fake-product/entry.tsx +54 -0
  80. package/src/main.tsx +8 -0
  81. package/src/styles.css +1478 -1478
@@ -1,68 +1,68 @@
1
- import { useState } from "react";
2
- import type { UiPromptEvent } from "../adapter.ts";
3
-
4
- /**
5
- * Card for an extension dialog (`ctx.ui.select/confirm/input`, custom component
6
- * UI-R3 — assistant-ui has no equivalent primitive for extension UI prompts).
7
- * The server parks the run inside the extension's await until this answers
8
- * POST /api/ui-response, so every kind offers an explicit way out: `cancelled`
9
- * maps to the fail-closed default (false / undefined) if the user dismisses
10
- * instead of choosing.
11
- */
12
- export function UIPromptCard({
13
- prompt,
14
- onAnswer,
15
- }: {
16
- prompt: UiPromptEvent;
17
- onAnswer: (a: { value?: string; confirmed?: boolean; cancelled?: true }) => void;
18
- }) {
19
- const [text, setText] = useState("");
20
- const submitInput = () => {
21
- if (text.trim()) onAnswer({ value: text });
22
- };
23
- return (
24
- <div className="uidialog" role={prompt.kind === "confirm" ? "alertdialog" : "dialog"} aria-label={prompt.title}>
25
- <div className="uidialog-title">{prompt.title}</div>
26
- {prompt.message && <div className="uidialog-msg">{prompt.message}</div>}
27
- {prompt.kind === "select" && (
28
- <div className="uidialog-options">
29
- {(prompt.options ?? []).map((o) => (
30
- <button key={o} onClick={() => onAnswer({ value: o })}>
31
- {o}
32
- </button>
33
- ))}
34
- <button className="uidialog-dismiss" onClick={() => onAnswer({ cancelled: true })}>
35
- 取消
36
- </button>
37
- </div>
38
- )}
39
- {prompt.kind === "confirm" && (
40
- <div className="uidialog-actions">
41
- <button className="allow" onClick={() => onAnswer({ confirmed: true })}>
42
- 确定
43
- </button>
44
- <button className="deny" onClick={() => onAnswer({ cancelled: true })}>
45
- 取消
46
- </button>
47
- </div>
48
- )}
49
- {prompt.kind === "input" && (
50
- <div className="uidialog-input">
51
- <input
52
- value={text}
53
- placeholder={prompt.placeholder ?? ""}
54
- autoFocus
55
- onChange={(e) => setText(e.target.value)}
56
- onKeyDown={(e) => e.key === "Enter" && submitInput()}
57
- />
58
- <button onClick={submitInput} disabled={!text.trim()}>
59
- 提交
60
- </button>
61
- <button className="uidialog-dismiss" onClick={() => onAnswer({ cancelled: true })}>
62
- 取消
63
- </button>
64
- </div>
65
- )}
66
- </div>
67
- );
68
- }
1
+ import { useState } from "react";
2
+ import type { UiPromptEvent } from "../adapter.ts";
3
+
4
+ /**
5
+ * Card for an extension dialog (`ctx.ui.select/confirm/input`, custom component
6
+ * UI-R3 — assistant-ui has no equivalent primitive for extension UI prompts).
7
+ * The server parks the run inside the extension's await until this answers
8
+ * POST /api/ui-response, so every kind offers an explicit way out: `cancelled`
9
+ * maps to the fail-closed default (false / undefined) if the user dismisses
10
+ * instead of choosing.
11
+ */
12
+ export function UIPromptCard({
13
+ prompt,
14
+ onAnswer,
15
+ }: {
16
+ prompt: UiPromptEvent;
17
+ onAnswer: (a: { value?: string; confirmed?: boolean; cancelled?: true }) => void;
18
+ }) {
19
+ const [text, setText] = useState("");
20
+ const submitInput = () => {
21
+ if (text.trim()) onAnswer({ value: text });
22
+ };
23
+ return (
24
+ <div className="uidialog" role={prompt.kind === "confirm" ? "alertdialog" : "dialog"} aria-label={prompt.title}>
25
+ <div className="uidialog-title">{prompt.title}</div>
26
+ {prompt.message && <div className="uidialog-msg">{prompt.message}</div>}
27
+ {prompt.kind === "select" && (
28
+ <div className="uidialog-options">
29
+ {(prompt.options ?? []).map((o) => (
30
+ <button key={o} onClick={() => onAnswer({ value: o })}>
31
+ {o}
32
+ </button>
33
+ ))}
34
+ <button className="uidialog-dismiss" onClick={() => onAnswer({ cancelled: true })}>
35
+ 取消
36
+ </button>
37
+ </div>
38
+ )}
39
+ {prompt.kind === "confirm" && (
40
+ <div className="uidialog-actions">
41
+ <button className="allow" onClick={() => onAnswer({ confirmed: true })}>
42
+ 确定
43
+ </button>
44
+ <button className="deny" onClick={() => onAnswer({ cancelled: true })}>
45
+ 取消
46
+ </button>
47
+ </div>
48
+ )}
49
+ {prompt.kind === "input" && (
50
+ <div className="uidialog-input">
51
+ <input
52
+ value={text}
53
+ placeholder={prompt.placeholder ?? ""}
54
+ autoFocus
55
+ onChange={(e) => setText(e.target.value)}
56
+ onKeyDown={(e) => e.key === "Enter" && submitInput()}
57
+ />
58
+ <button onClick={submitInput} disabled={!text.trim()}>
59
+ 提交
60
+ </button>
61
+ <button className="uidialog-dismiss" onClick={() => onAnswer({ cancelled: true })}>
62
+ 取消
63
+ </button>
64
+ </div>
65
+ )}
66
+ </div>
67
+ );
68
+ }
@@ -1,110 +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
-
11
- const DAY = 86_400_000;
12
-
13
- function startOfDay(t: number): number {
14
- const d = new Date(t);
15
- d.setHours(0, 0, 0, 0);
16
- return d.getTime();
17
- }
18
-
19
- /** Whole calendar days between the item's day and today (0 = today, 1 = yesterday). */
20
- function daysAgo(iso: string, now: Date): number {
21
- const t = Date.parse(iso);
22
- if (Number.isNaN(t)) return 0;
23
- return Math.round((startOfDay(now.getTime()) - startOfDay(t)) / DAY);
24
- }
25
-
26
- /** 刚刚 / N 分钟前 / N 小时前 / 昨天 / M月D日(跨年带年份)。 */
27
- export function relativeTime(iso: string, now: Date): string {
28
- const t = Date.parse(iso);
29
- if (Number.isNaN(t)) return "";
30
- const diff = now.getTime() - t; // negative (clock skew / future) reads as "刚刚"
31
- if (diff < 60_000) return "刚刚";
32
- if (diff < 3_600_000) return `${Math.floor(diff / 60_000)} 分钟前`;
33
- const days = daysAgo(iso, now);
34
- if (days === 0) return `${Math.floor(diff / 3_600_000)} 小时前`;
35
- const d = new Date(t);
36
- if (days === 1) return "昨天";
37
- const md = `${d.getMonth() + 1}月${d.getDate()}日`;
38
- return d.getFullYear() === now.getFullYear() ? md : `${d.getFullYear()}年${md}`;
39
- }
40
-
41
- /** Group label for a session row; buckets follow calendar days, not 24h windows. */
42
- export function groupOf(iso: string, now: Date): string {
43
- const days = daysAgo(iso, now);
44
- if (days <= 0) return "今天";
45
- if (days === 1) return "昨天";
46
- if (days <= 6) return "近 7 天";
47
- if (days <= 29) return "近 30 天";
48
- return "更早";
49
- }
50
-
51
- /**
52
- * Bucket a session list in order. Assumes items are sorted newest-first (the
53
- * server does that); a newer item after an older one starts a new bucket run
54
- * rather than being silently merged — same behaviour as DSH's list.
55
- */
56
- export function groupSessions<T extends { updatedAt: string }>(
57
- items: readonly T[],
58
- now: Date,
59
- ): Array<{ label: string; items: T[] }> {
60
- const out: Array<{ label: string; items: T[] }> = [];
61
- for (const item of items) {
62
- const label = groupOf(item.updatedAt, now);
63
- const last = out[out.length - 1];
64
- if (last && last.label === label) last.items.push(item);
65
- else out.push({ label, items: [item] });
66
- }
67
- return out;
68
- }
69
-
70
- /**
71
- * 绝对时刻 → 「2026-11-03 09:12」(本地时区)。
72
- *
73
- * - `timeZone` 只给测试用(固定时区做断言);页面调用不传 = 用户本地时区。
74
- * - 空值显示「—」;**解析不了就原样返回**(不吞、不假装是今天)。
75
- * - 只喂 ISO 时刻(含 Z 或偏移);别喂「2026-11-03」这种纯日期——那会被当 UTC 零点,
76
- * 在负时区会退到前一天。
77
- */
78
- export function fmtTime(iso: string | null | undefined, timeZone?: string): string {
79
- const parts = fmtParts(iso, timeZone, true);
80
- if (!parts) return iso ? String(iso) : "—";
81
- return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
82
- }
83
-
84
- /** 绝对时刻 → 「2026-11-03」(本地时区)。语义同 `fmtTime`。 */
85
- export function fmtDate(iso: string | null | undefined, timeZone?: string): string {
86
- const parts = fmtParts(iso, timeZone, false);
87
- if (!parts) return iso ? String(iso) : "—";
88
- return `${parts.year}-${parts.month}-${parts.day}`;
89
- }
90
-
91
- function fmtParts(
92
- iso: string | null | undefined,
93
- timeZone: string | undefined,
94
- withTime: boolean,
95
- ): { year: string; month: string; day: string; hour: string; minute: string } | null {
96
- if (!iso) return null;
97
- const d = new Date(iso);
98
- if (Number.isNaN(d.getTime())) 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: string) => 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
- }
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
+
11
+ const DAY = 86_400_000;
12
+
13
+ function startOfDay(t: number): number {
14
+ const d = new Date(t);
15
+ d.setHours(0, 0, 0, 0);
16
+ return d.getTime();
17
+ }
18
+
19
+ /** Whole calendar days between the item's day and today (0 = today, 1 = yesterday). */
20
+ function daysAgo(iso: string, now: Date): number {
21
+ const t = Date.parse(iso);
22
+ if (Number.isNaN(t)) return 0;
23
+ return Math.round((startOfDay(now.getTime()) - startOfDay(t)) / DAY);
24
+ }
25
+
26
+ /** 刚刚 / N 分钟前 / N 小时前 / 昨天 / M月D日(跨年带年份)。 */
27
+ export function relativeTime(iso: string, now: Date): string {
28
+ const t = Date.parse(iso);
29
+ if (Number.isNaN(t)) return "";
30
+ const diff = now.getTime() - t; // negative (clock skew / future) reads as "刚刚"
31
+ if (diff < 60_000) return "刚刚";
32
+ if (diff < 3_600_000) return `${Math.floor(diff / 60_000)} 分钟前`;
33
+ const days = daysAgo(iso, now);
34
+ if (days === 0) return `${Math.floor(diff / 3_600_000)} 小时前`;
35
+ const d = new Date(t);
36
+ if (days === 1) return "昨天";
37
+ const md = `${d.getMonth() + 1}月${d.getDate()}日`;
38
+ return d.getFullYear() === now.getFullYear() ? md : `${d.getFullYear()}年${md}`;
39
+ }
40
+
41
+ /** Group label for a session row; buckets follow calendar days, not 24h windows. */
42
+ export function groupOf(iso: string, now: Date): string {
43
+ const days = daysAgo(iso, now);
44
+ if (days <= 0) return "今天";
45
+ if (days === 1) return "昨天";
46
+ if (days <= 6) return "近 7 天";
47
+ if (days <= 29) return "近 30 天";
48
+ return "更早";
49
+ }
50
+
51
+ /**
52
+ * Bucket a session list in order. Assumes items are sorted newest-first (the
53
+ * server does that); a newer item after an older one starts a new bucket run
54
+ * rather than being silently merged — same behaviour as DSH's list.
55
+ */
56
+ export function groupSessions<T extends { updatedAt: string }>(
57
+ items: readonly T[],
58
+ now: Date,
59
+ ): Array<{ label: string; items: T[] }> {
60
+ const out: Array<{ label: string; items: T[] }> = [];
61
+ for (const item of items) {
62
+ const label = groupOf(item.updatedAt, now);
63
+ const last = out[out.length - 1];
64
+ if (last && last.label === label) last.items.push(item);
65
+ else out.push({ label, items: [item] });
66
+ }
67
+ return out;
68
+ }
69
+
70
+ /**
71
+ * 绝对时刻 → 「2026-11-03 09:12」(本地时区)。
72
+ *
73
+ * - `timeZone` 只给测试用(固定时区做断言);页面调用不传 = 用户本地时区。
74
+ * - 空值显示「—」;**解析不了就原样返回**(不吞、不假装是今天)。
75
+ * - 只喂 ISO 时刻(含 Z 或偏移);别喂「2026-11-03」这种纯日期——那会被当 UTC 零点,
76
+ * 在负时区会退到前一天。
77
+ */
78
+ export function fmtTime(iso: string | null | undefined, timeZone?: string): string {
79
+ const parts = fmtParts(iso, timeZone, true);
80
+ if (!parts) return iso ? String(iso) : "—";
81
+ return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
82
+ }
83
+
84
+ /** 绝对时刻 → 「2026-11-03」(本地时区)。语义同 `fmtTime`。 */
85
+ export function fmtDate(iso: string | null | undefined, timeZone?: string): string {
86
+ const parts = fmtParts(iso, timeZone, false);
87
+ if (!parts) return iso ? String(iso) : "—";
88
+ return `${parts.year}-${parts.month}-${parts.day}`;
89
+ }
90
+
91
+ function fmtParts(
92
+ iso: string | null | undefined,
93
+ timeZone: string | undefined,
94
+ withTime: boolean,
95
+ ): { year: string; month: string; day: string; hour: string; minute: string } | null {
96
+ if (!iso) return null;
97
+ const d = new Date(iso);
98
+ if (Number.isNaN(d.getTime())) 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: string) => 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
+ }
@@ -1,20 +1,20 @@
1
- import { useSyncExternalStore } from "react";
2
-
3
- /**
4
- * 视口是否窄于 maxWidth(响应式布局用)。
5
- *
6
- * 用 useSyncExternalStore 而不是 useState+useEffect:首帧就能拿到正确值,
7
- * 不会出现"先按宽屏渲染再跳成窄屏"的闪动。服务端渲染(无 window)回落 false。
8
- */
9
- export function useNarrow(maxWidth: number): boolean {
10
- const query = `(max-width: ${maxWidth}px)`;
11
- return useSyncExternalStore(
12
- (onChange) => {
13
- const mql = window.matchMedia(query);
14
- mql.addEventListener("change", onChange);
15
- return () => mql.removeEventListener("change", onChange);
16
- },
17
- () => window.matchMedia(query).matches,
18
- () => false,
19
- );
20
- }
1
+ import { useSyncExternalStore } from "react";
2
+
3
+ /**
4
+ * 视口是否窄于 maxWidth(响应式布局用)。
5
+ *
6
+ * 用 useSyncExternalStore 而不是 useState+useEffect:首帧就能拿到正确值,
7
+ * 不会出现"先按宽屏渲染再跳成窄屏"的闪动。服务端渲染(无 window)回落 false。
8
+ */
9
+ export function useNarrow(maxWidth: number): boolean {
10
+ const query = `(max-width: ${maxWidth}px)`;
11
+ return useSyncExternalStore(
12
+ (onChange) => {
13
+ const mql = window.matchMedia(query);
14
+ mql.addEventListener("change", onChange);
15
+ return () => mql.removeEventListener("change", onChange);
16
+ },
17
+ () => window.matchMedia(query).matches,
18
+ () => false,
19
+ );
20
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * **第二产品的最小样板**:用于构建期产品切换验收。
3
+ *
4
+ * 它不是真产品,是「照抄起点」:一个 AppDef(路由表 + 侧栏 + 页面)加一个
5
+ * 组合根调用,就能接进 core 的壳。真实产品照它写,再补自己的页面与文案。
6
+ *
7
+ * 与真产品同契约(`vite.config.ts` 的 `appDefGuard` 会校验 appDef):
8
+ * - `export const appDef`:导航注册表,必须过 core 的 20 条结构契约;
9
+ * - `export function App`:组合根组件(`AgentApp` + 产品的事实)。
10
+ *
11
+ * 构建:`VITE_PRODUCT=fake-product npm --prefix apps/web run build`
12
+ * (CI 里跑这一条,等于每次都在验「切换真的有效」)。
13
+ */
14
+ import { AgentApp } from "../agent-chat/mount.tsx";
15
+ import type { AppDef } from "../agent-chat/app.tsx";
16
+
17
+ /**
18
+ * 路由键只能是**小写字母**(core 用 `/^#\/([a-z]+)/` 从 hash 取键)。
19
+ * 写成 "my-page" 这类取不出来,页面会像「点不动」——契约里有这一条。
20
+ */
21
+ const ROUTES = {
22
+ chat: "助手",
23
+ home: "首页",
24
+ } as const;
25
+
26
+ const appDef: AppDef = {
27
+ home: "home",
28
+ // core 不认识这个键,它只是「坞撑满内容区」的那个路由。
29
+ chatRoute: "chat",
30
+ routes: { ...ROUTES },
31
+ navItems: () => [
32
+ { route: "chat", label: ROUTES.chat },
33
+ { route: "home", label: ROUTES.home },
34
+ ],
35
+ page: (ctx) =>
36
+ ctx.route === "home" ? (
37
+ <main className="content" style={{ padding: 24 }}>
38
+ <h2>样板首页</h2>
39
+ <p>这是第二产品样板:只有两个路由,没有业务页面。</p>
40
+ </main>
41
+ ) : null,
42
+ };
43
+
44
+ export { appDef };
45
+
46
+ export function App() {
47
+ return (
48
+ <AgentApp
49
+ def={appDef}
50
+ // 文案(坞标题、助手名)由产品给;core 不写死任何一句话、不认任何人格名。
51
+ texts={() => ({ title: "样板助手", assistantLabel: "助手" })}
52
+ />
53
+ );
54
+ }
package/src/main.tsx ADDED
@@ -0,0 +1,8 @@
1
+ import { createRoot } from "react-dom/client";
2
+ import App from "./App.tsx";
3
+ import { applyThemeMode, loadThemeMode } from "./agent-chat/theme.ts";
4
+ import "./styles.css";
5
+
6
+ // Pin the saved theme mode before the first paint to avoid a flash.
7
+ applyThemeMode(loadThemeMode());
8
+ createRoot(document.getElementById("root")!).render(<App />);