@njuptlzf/agent-chat-web 0.0.0-stage → 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 (82) 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 -6
  53. package/src/App.tsx +13 -0
  54. package/src/agent-chat/AgentChat.tsx +692 -0
  55. package/src/agent-chat/AgentChatApp.tsx +206 -0
  56. package/src/agent-chat/DockPanel.tsx +74 -0
  57. package/src/agent-chat/PersonasPage.tsx +678 -0
  58. package/src/agent-chat/adapter.ts +272 -0
  59. package/src/agent-chat/app-def-check.ts +215 -0
  60. package/src/agent-chat/app.tsx +327 -0
  61. package/src/agent-chat/auth.ts +83 -0
  62. package/src/agent-chat/dock.ts +162 -0
  63. package/src/agent-chat/docs.ts +179 -0
  64. package/src/agent-chat/index.ts +17 -0
  65. package/src/agent-chat/mount.tsx +123 -0
  66. package/src/agent-chat/qual.ts +55 -0
  67. package/src/agent-chat/sse.ts +104 -0
  68. package/src/agent-chat/theme.ts +23 -0
  69. package/src/agent-chat/ui/CodeCopyHeader.tsx +29 -0
  70. package/src/agent-chat/ui/ConfirmCard.tsx +32 -0
  71. package/src/agent-chat/ui/Lightbox.tsx +32 -0
  72. package/src/agent-chat/ui/QueueBar.tsx +70 -0
  73. package/src/agent-chat/ui/Splitter.tsx +81 -0
  74. package/src/agent-chat/ui/ThemeToggle.tsx +25 -0
  75. package/src/agent-chat/ui/TierPicker.tsx +112 -0
  76. package/src/agent-chat/ui/UIPromptCard.tsx +68 -0
  77. package/src/agent-chat/ui/timefmt.ts +110 -0
  78. package/src/agent-chat/ui/useNarrow.ts +20 -0
  79. package/src/fake-product/entry.tsx +54 -0
  80. package/src/main.tsx +8 -0
  81. package/src/styles.css +1478 -0
  82. package/README.md +0 -3
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Theme mode (L2): "auto" follows the OS via `color-scheme: light dark` +
3
+ * light-dark() tokens; "light"/dark" pin it with a data-theme attribute on
4
+ * <html>. The choice persists per browser (localStorage) — it is a device
5
+ * preference, not product state, so it never travels through the protocol.
6
+ */
7
+ export type ThemeMode = "auto" | "light" | "dark";
8
+ export declare function loadThemeMode(): ThemeMode;
9
+ export declare function applyThemeMode(mode: ThemeMode): void;
10
+ export declare function saveThemeMode(mode: ThemeMode): void;
package/dist/theme.js ADDED
@@ -0,0 +1,14 @@
1
+ const KEY = "ac.theme";
2
+ export function loadThemeMode() {
3
+ const v = globalThis.localStorage?.getItem(KEY);
4
+ return v === "light" || v === "dark" ? v : "auto";
5
+ }
6
+ export function applyThemeMode(mode) {
7
+ if (mode === "auto")
8
+ document.documentElement.removeAttribute("data-theme");
9
+ else
10
+ document.documentElement.setAttribute("data-theme", mode);
11
+ }
12
+ export function saveThemeMode(mode) {
13
+ globalThis.localStorage?.setItem(KEY, mode);
14
+ }
@@ -0,0 +1,7 @@
1
+ import type { CodeHeaderProps } from "@assistant-ui/react-markdown";
2
+ /**
3
+ * Code-fence header with a copy button (assistant-ui's default CodeHeader
4
+ * renders nothing). It receives the raw `code` from the primitive, so there is
5
+ * no DOM scraping here — the string the model emitted is the string copied.
6
+ */
7
+ export default function CodeCopyHeader({ language, code }: CodeHeaderProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ /**
4
+ * Code-fence header with a copy button (assistant-ui's default CodeHeader
5
+ * renders nothing). It receives the raw `code` from the primitive, so there is
6
+ * no DOM scraping here — the string the model emitted is the string copied.
7
+ */
8
+ export default function CodeCopyHeader({ language, code }) {
9
+ const [copied, setCopied] = useState(false);
10
+ const copy = async () => {
11
+ try {
12
+ await navigator.clipboard.writeText(code);
13
+ setCopied(true);
14
+ setTimeout(() => setCopied(false), 1500);
15
+ }
16
+ catch {
17
+ // Clipboard can be refused (permissions/insecure context): stay silent,
18
+ // the code is still selectable by hand.
19
+ }
20
+ };
21
+ return (_jsxs("div", { className: "code-head", children: [_jsx("span", { className: "code-lang", children: language || "text" }), _jsx("button", { type: "button", className: "copy-code", onClick: () => void copy(), children: copied ? "已复制" : "复制" })] }));
22
+ }
@@ -0,0 +1,15 @@
1
+ export interface ConfirmRequest {
2
+ sessionId: string;
3
+ toolCallId: string;
4
+ name: string;
5
+ args: Record<string, unknown>;
6
+ }
7
+ /**
8
+ * Tool-execution permission card (`tool_confirm` event, custom component UI-R3).
9
+ * assistant-ui has no server-parked approval primitive; answering POSTs
10
+ * /api/decision — the caller (ChatApp) keeps that plumbing, this is pure view.
11
+ */
12
+ export declare function ConfirmCard({ request, onAnswer, }: {
13
+ request: ConfirmRequest;
14
+ onAnswer: (allow: boolean) => void;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Tool-execution permission card (`tool_confirm` event, custom component UI-R3).
4
+ * assistant-ui has no server-parked approval primitive; answering POSTs
5
+ * /api/decision — the caller (ChatApp) keeps that plumbing, this is pure view.
6
+ */
7
+ export function ConfirmCard({ request, onAnswer, }) {
8
+ return (_jsxs("div", { className: "confirm", children: [_jsxs("div", { className: "confirm-title", children: ["\u26A0\uFE0F \u52A9\u624B\u8BF7\u6C42\u6267\u884C ", _jsx("b", { children: request.name }), "\uFF0C\u662F\u5426\u5141\u8BB8\uFF1F"] }), _jsx("pre", { className: "confirm-args", children: JSON.stringify(request.args, null, 2) }), _jsxs("div", { className: "confirm-actions", children: [_jsx("button", { className: "allow", onClick: () => onAnswer(true), children: "\u5141\u8BB8" }), _jsx("button", { className: "deny", onClick: () => onAnswer(false), children: "\u62D2\u7EDD" })] })] }));
9
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ⑥ 图片点击放大(lightbox)。全局委托监听,只认 `.thread` 内的 `<img>`
3
+ * (品牌 logo、头像等不在对话区,不会触发)。点击遮罩或放大图本身关闭,
4
+ * Esc 也关闭。纯前端,零协议改动。
5
+ */
6
+ export declare function Lightbox(): import("react").JSX.Element | null;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ /**
4
+ * ⑥ 图片点击放大(lightbox)。全局委托监听,只认 `.thread` 内的 `<img>`
5
+ * (品牌 logo、头像等不在对话区,不会触发)。点击遮罩或放大图本身关闭,
6
+ * Esc 也关闭。纯前端,零协议改动。
7
+ */
8
+ export function Lightbox() {
9
+ const [src, setSrc] = useState(null);
10
+ useEffect(() => {
11
+ const onClick = (e) => {
12
+ const t = e.target;
13
+ if (!(t instanceof HTMLImageElement) || !t.closest(".thread"))
14
+ return;
15
+ setSrc(t.currentSrc || t.src);
16
+ };
17
+ const onKey = (e) => {
18
+ if (e.key === "Escape")
19
+ setSrc(null);
20
+ };
21
+ document.addEventListener("click", onClick, true);
22
+ document.addEventListener("keydown", onKey);
23
+ return () => {
24
+ document.removeEventListener("click", onClick, true);
25
+ document.removeEventListener("keydown", onKey);
26
+ };
27
+ }, []);
28
+ if (!src)
29
+ return null;
30
+ return (_jsx("div", { className: "lightbox", role: "dialog", "aria-label": "\u56FE\u7247\u9884\u89C8", onClick: () => setSrc(null), children: _jsx("img", { src: src, alt: "" }) }));
31
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Waiting-queue bar (custom component, UI-R3).
3
+ *
4
+ * Why not the official queue: `ComposerPrimitive.Queue` + `unstable_enableMessageQueue`
5
+ * cover enqueue/remove, but the local runtime wires the queue driver WITHOUT a
6
+ * `cancel` callback, so a steer-lane move degrades to "process next" instead of
7
+ * interrupting the running answer; and `notifyCancelled` pauses queue advance
8
+ * after a user-initiated stop, which kills our "stop then flush next" behavior.
9
+ * Forensics: @assistant-ui/core local-thread-runtime-core.js:356-366,
10
+ * message-queue.d.ts:13-30. Kept as a reusable custom component per the
11
+ * official-first rule (it does not match).
12
+ */
13
+ /** A content part a queued send can carry: the composer only produces these three. */
14
+ export type QueuedPart = {
15
+ type: "text";
16
+ text: string;
17
+ } | {
18
+ type: "image";
19
+ image: string;
20
+ } | {
21
+ type: "file";
22
+ filename?: string;
23
+ mimeType: string;
24
+ data: string;
25
+ };
26
+ /**
27
+ * One queued send (E2, documents since B4-A). It holds content parts rather
28
+ * than a string because a message waiting behind the current answer may carry
29
+ * images and converted documents too — the queue is only a local staging
30
+ * area, and whatever sits here is appended to the thread verbatim once the run
31
+ * ends.
32
+ */
33
+ export type QueuedMessage = readonly QueuedPart[];
34
+ /** What the bar shows for one queued message (the payload itself is a parts array). */
35
+ export declare function queuedPreview(message: QueuedMessage): {
36
+ text: string;
37
+ images: number;
38
+ docs: number;
39
+ };
40
+ export declare function QueueBar({ queue, onSteer, onDrop, }: {
41
+ queue: readonly QueuedMessage[];
42
+ onSteer: (i: number) => void;
43
+ onDrop: (i: number) => void;
44
+ }): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ /** What the bar shows for one queued message (the payload itself is a parts array). */
3
+ export function queuedPreview(message) {
4
+ const text = message
5
+ .filter((p) => p.type === "text")
6
+ .map((p) => p.text)
7
+ .join("");
8
+ const images = message.filter((p) => p.type === "image").length;
9
+ const docs = message.filter((p) => p.type === "file").length;
10
+ return { text: text.trim(), images, docs };
11
+ }
12
+ export function QueueBar({ queue, onSteer, onDrop, }) {
13
+ return (_jsxs("div", { className: "queuebar", children: [_jsxs("span", { className: "q-label", children: ["\u7B49\u5F85 ", queue.length, " \u6761"] }), queue.map((q, i) => {
14
+ const { text, images, docs } = queuedPreview(q);
15
+ return (_jsxs("span", { className: "q-item", title: text || `${images} 图片 / ${docs} 文档`, children: [images > 0 && _jsxs("span", { className: "q-img", "aria-label": `${images} 张图片`, children: ["\uD83D\uDDBC", images > 1 ? `×${images}` : ""] }), docs > 0 && _jsxs("span", { className: "q-img", "aria-label": `${docs} 个文档`, children: ["\uD83D\uDCC4", docs > 1 ? `×${docs}` : ""] }), _jsx("span", { className: "q-text", children: text }), _jsx("button", { onClick: () => onSteer(i), title: "\u4E2D\u6B62\u5F53\u524D\u56DE\u7B54\uFF0C\u4F18\u5148\u53D1\u9001\u8FD9\u6761", children: "\u63D2\u961F" }), _jsx("button", { onClick: () => onDrop(i), title: "\u4ECE\u961F\u5217\u79FB\u9664", children: "\u79FB\u9664" })] }, i));
16
+ })] }));
17
+ }
@@ -0,0 +1,27 @@
1
+ import { type PointerEvent as ReactPointerEvent } from "react";
2
+ /**
3
+ * 解析左栏宽度:记忆值合法才用,否则回落默认。
4
+ * 损坏的 localStorage(NaN/越界/改参后旧值)一律回默认,不会把布局带坏。
5
+ */
6
+ export declare function resolveWidth(stored: string | null, fallback: number, min: number, max: number): number;
7
+ /**
8
+ * 可拖拽竖向分隔条(agentChat 通用能力,零业务知识):拖动调整左栏宽度,
9
+ * 宽度记忆在 localStorage(每浏览器),双击恢复默认。参考 DSH 侧栏拖拽。
10
+ */
11
+ export declare function usePaneWidth(storageKey: string, fallback: number, min: number, max: number): {
12
+ width: number;
13
+ handlers: {
14
+ onPointerDown: (e: ReactPointerEvent<HTMLDivElement>) => void;
15
+ onPointerMove: (e: ReactPointerEvent<HTMLDivElement>) => void;
16
+ onPointerUp: () => void;
17
+ onDoubleClick: () => void;
18
+ };
19
+ };
20
+ interface SplitterProps {
21
+ onPointerDown?: (e: ReactPointerEvent<HTMLDivElement>) => void;
22
+ onPointerMove?: (e: ReactPointerEvent<HTMLDivElement>) => void;
23
+ onPointerUp?: (e: ReactPointerEvent<HTMLDivElement>) => void;
24
+ onDoubleClick?: () => void;
25
+ }
26
+ export declare function Splitter(props: SplitterProps): import("react").JSX.Element;
27
+ export {};
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useRef, useState } from "react";
3
+ function clamp(v, min, max) {
4
+ return Math.min(max, Math.max(min, v));
5
+ }
6
+ /**
7
+ * 解析左栏宽度:记忆值合法才用,否则回落默认。
8
+ * 损坏的 localStorage(NaN/越界/改参后旧值)一律回默认,不会把布局带坏。
9
+ */
10
+ export function resolveWidth(stored, fallback, min, max) {
11
+ const v = Number(stored);
12
+ return stored !== null && stored !== "" && Number.isFinite(v) && v >= min && v <= max ? v : fallback;
13
+ }
14
+ /**
15
+ * 可拖拽竖向分隔条(agentChat 通用能力,零业务知识):拖动调整左栏宽度,
16
+ * 宽度记忆在 localStorage(每浏览器),双击恢复默认。参考 DSH 侧栏拖拽。
17
+ */
18
+ export function usePaneWidth(storageKey, fallback, min, max) {
19
+ const [width, setWidth] = useState(() => {
20
+ let stored = null;
21
+ try {
22
+ stored = localStorage.getItem(storageKey);
23
+ }
24
+ catch {
25
+ /* 隐私模式读不到就算了 */
26
+ }
27
+ return resolveWidth(stored, fallback, min, max);
28
+ });
29
+ const drag = useRef(null);
30
+ const commit = useCallback((v) => {
31
+ const w = clamp(v, min, max);
32
+ setWidth(w);
33
+ try {
34
+ localStorage.setItem(storageKey, String(w));
35
+ }
36
+ catch {
37
+ /* 写不进去只影响"记忆",不影响本次拖拽 */
38
+ }
39
+ }, [storageKey, min, max]);
40
+ return {
41
+ width,
42
+ handlers: {
43
+ onPointerDown: (e) => {
44
+ e.currentTarget.setPointerCapture(e.pointerId);
45
+ drag.current = { startX: e.clientX, startW: width };
46
+ },
47
+ onPointerMove: (e) => {
48
+ const d = drag.current;
49
+ if (d)
50
+ commit(d.startW + e.clientX - d.startX);
51
+ },
52
+ onPointerUp: () => {
53
+ drag.current = null;
54
+ },
55
+ onDoubleClick: () => commit(fallback),
56
+ },
57
+ };
58
+ }
59
+ export function Splitter(props) {
60
+ return (_jsx("div", { className: "splitter", role: "separator", "aria-orientation": "vertical", title: "\u62D6\u52A8\u8C03\u6574\u5BBD\u5EA6\uFF0C\u53CC\u51FB\u6062\u590D\u9ED8\u8BA4", ...props }));
61
+ }
@@ -0,0 +1,2 @@
1
+ /** 三态循环:跟随系统 → 浅色 → 深色。自包含:状态、持久化、应用都在这里。 */
2
+ export default function ThemeToggle(): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { applyThemeMode, loadThemeMode, saveThemeMode } from "../theme.js";
4
+ const ICON = { auto: "🌗", light: "☀️", dark: "🌙" };
5
+ const LABEL = { auto: "跟随系统", light: "浅色", dark: "深色" };
6
+ const CYCLE = { auto: "light", light: "dark", dark: "auto" };
7
+ /** 三态循环:跟随系统 → 浅色 → 深色。自包含:状态、持久化、应用都在这里。 */
8
+ export default function ThemeToggle() {
9
+ const [mode, setMode] = useState(loadThemeMode);
10
+ return (_jsx("button", { className: "theme-toggle", title: `主题:${LABEL[mode]}(点击切换)`, onClick: () => {
11
+ const next = CYCLE[mode];
12
+ setMode(next);
13
+ applyThemeMode(next);
14
+ saveThemeMode(next);
15
+ }, children: ICON[mode] }));
16
+ }
@@ -0,0 +1,14 @@
1
+ import type { ModelTier } from "@njuptlzf/agent-chat-protocol";
2
+ /**
3
+ * 档位下拉选择器(U1b)。assistant-ui 0.15.28 没有通用下拉/菜单原语
4
+ * (index.d.ts 只有 thread/composer 原语与 unstable trigger-popover 钩子),
5
+ * 按规范自定义。样式对齐宿主截图:触发钮只显示当前档位,弹出列表每行
6
+ * label + 右对齐消耗倍率,顶部结构化描述卡(名称/说明/倍率/单价)。
7
+ * ponytail: 只做点击+Esc+方向键,无焦点陷阱/滚动锁定;升级路径 = 换无头
8
+ * 菜单库(如 radix popover)。
9
+ */
10
+ export declare function TierPicker({ tiers, value, onChange, }: {
11
+ tiers: ModelTier[];
12
+ value?: string;
13
+ onChange: (id: string) => void;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ /**
4
+ * 档位下拉选择器(U1b)。assistant-ui 0.15.28 没有通用下拉/菜单原语
5
+ * (index.d.ts 只有 thread/composer 原语与 unstable trigger-popover 钩子),
6
+ * 按规范自定义。样式对齐宿主截图:触发钮只显示当前档位,弹出列表每行
7
+ * label + 右对齐消耗倍率,顶部结构化描述卡(名称/说明/倍率/单价)。
8
+ * ponytail: 只做点击+Esc+方向键,无焦点陷阱/滚动锁定;升级路径 = 换无头
9
+ * 菜单库(如 radix popover)。
10
+ */
11
+ export function TierPicker({ tiers, value, onChange, }) {
12
+ const [open, setOpen] = useState(false);
13
+ const [hover, setHover] = useState(null);
14
+ const rootRef = useRef(null);
15
+ const current = tiers.find((t) => t.id === value) ?? tiers[0];
16
+ const shown = tiers[hover ?? tiers.indexOf(current)] ?? current;
17
+ useEffect(() => {
18
+ if (!open)
19
+ return;
20
+ const onDoc = (e) => {
21
+ if (!rootRef.current?.contains(e.target))
22
+ setOpen(false);
23
+ };
24
+ document.addEventListener("mousedown", onDoc);
25
+ return () => document.removeEventListener("mousedown", onDoc);
26
+ }, [open]);
27
+ const pick = (t) => {
28
+ onChange(t.id);
29
+ setOpen(false);
30
+ setHover(null);
31
+ };
32
+ return (_jsxs("div", { className: "tierpick", ref: rootRef, onKeyDown: (e) => {
33
+ if (e.key === "Escape") {
34
+ setOpen(false);
35
+ setHover(null);
36
+ }
37
+ else if (open && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
38
+ e.preventDefault();
39
+ const base = hover ?? tiers.indexOf(current);
40
+ setHover(e.key === "ArrowDown" ? Math.min(tiers.length - 1, base + 1) : Math.max(0, base - 1));
41
+ }
42
+ else if (open && e.key === "Enter" && hover !== null) {
43
+ e.preventDefault();
44
+ const t = tiers[hover];
45
+ if (t)
46
+ pick(t);
47
+ }
48
+ }, children: [open && (_jsxs("div", { className: "tier-pop", role: "listbox", "aria-label": "\u56DE\u7B54\u6863\u4F4D", children: [_jsxs("div", { className: "tier-desc", children: [_jsx("div", { className: "tier-desc-name", children: shown.label }), shown.description && _jsx("div", { className: "tier-desc-text", children: shown.description }), _jsxs("div", { className: "tier-desc-meta", children: [_jsx("span", { children: "\u6D88\u8017\u500D\u7387" }), _jsxs("span", { children: ["\u00D7", shown.multiplier] })] }), shown.pricePerThousandTokensCents !== undefined && (_jsxs("div", { className: "tier-desc-meta", children: [_jsx("span", { children: "\u5355\u4EF7" }), _jsxs("span", { children: [shown.pricePerThousandTokensCents, " \u5206/\u5343\u5B57"] })] }))] }), tiers.map((t, i) => (_jsxs("button", { type: "button", role: "option", "aria-selected": t.id === current.id, className: t.id === current.id ? "tier-row on" : "tier-row", onMouseEnter: () => setHover(i), onClick: () => pick(t), children: [_jsx("span", { children: t.label }), _jsxs("span", { className: "tier-mult", children: ["\u00D7", t.multiplier] })] }, t.id)))] })), _jsxs("button", { type: "button", className: "tier-btn", "aria-haspopup": "listbox", "aria-expanded": open, onKeyDown: (e) => {
49
+ if (!open && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
50
+ e.preventDefault();
51
+ setOpen(true);
52
+ }
53
+ }, onClick: () => setOpen((o) => !o), children: [current.label, _jsx("span", { className: "tier-caret", children: "\u25BE" })] })] }));
54
+ }
@@ -0,0 +1,17 @@
1
+ import type { UiPromptEvent } from "../adapter.ts";
2
+ /**
3
+ * Card for an extension dialog (`ctx.ui.select/confirm/input`, custom component
4
+ * UI-R3 — assistant-ui has no equivalent primitive for extension UI prompts).
5
+ * The server parks the run inside the extension's await until this answers
6
+ * POST /api/ui-response, so every kind offers an explicit way out: `cancelled`
7
+ * maps to the fail-closed default (false / undefined) if the user dismisses
8
+ * instead of choosing.
9
+ */
10
+ export declare function UIPromptCard({ prompt, onAnswer, }: {
11
+ prompt: UiPromptEvent;
12
+ onAnswer: (a: {
13
+ value?: string;
14
+ confirmed?: boolean;
15
+ cancelled?: true;
16
+ }) => void;
17
+ }): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ /**
4
+ * Card for an extension dialog (`ctx.ui.select/confirm/input`, custom component
5
+ * UI-R3 — assistant-ui has no equivalent primitive for extension UI prompts).
6
+ * The server parks the run inside the extension's await until this answers
7
+ * POST /api/ui-response, so every kind offers an explicit way out: `cancelled`
8
+ * maps to the fail-closed default (false / undefined) if the user dismisses
9
+ * instead of choosing.
10
+ */
11
+ export function UIPromptCard({ prompt, onAnswer, }) {
12
+ const [text, setText] = useState("");
13
+ const submitInput = () => {
14
+ if (text.trim())
15
+ onAnswer({ value: text });
16
+ };
17
+ return (_jsxs("div", { className: "uidialog", role: prompt.kind === "confirm" ? "alertdialog" : "dialog", "aria-label": prompt.title, children: [_jsx("div", { className: "uidialog-title", children: prompt.title }), prompt.message && _jsx("div", { className: "uidialog-msg", children: prompt.message }), prompt.kind === "select" && (_jsxs("div", { className: "uidialog-options", children: [(prompt.options ?? []).map((o) => (_jsx("button", { onClick: () => onAnswer({ value: o }), children: o }, o))), _jsx("button", { className: "uidialog-dismiss", onClick: () => onAnswer({ cancelled: true }), children: "\u53D6\u6D88" })] })), prompt.kind === "confirm" && (_jsxs("div", { className: "uidialog-actions", children: [_jsx("button", { className: "allow", onClick: () => onAnswer({ confirmed: true }), children: "\u786E\u5B9A" }), _jsx("button", { className: "deny", onClick: () => onAnswer({ cancelled: true }), children: "\u53D6\u6D88" })] })), prompt.kind === "input" && (_jsxs("div", { className: "uidialog-input", children: [_jsx("input", { value: text, placeholder: prompt.placeholder ?? "", autoFocus: true, onChange: (e) => setText(e.target.value), onKeyDown: (e) => e.key === "Enter" && submitInput() }), _jsx("button", { onClick: submitInput, disabled: !text.trim(), children: "\u63D0\u4EA4" }), _jsx("button", { className: "uidialog-dismiss", onClick: () => onAnswer({ cancelled: true }), children: "\u53D6\u6D88" })] }))] }));
18
+ }
@@ -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
+ }