@vetta-org/theme-ui 0.1.1 → 0.1.2

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 (301) hide show
  1. package/package.json +733 -5
  2. package/src/action-approval/AppearanceActionPickerView.tsx +2 -78
  3. package/src/action-approval/AppearanceApprovalDrawerView.tsx +2 -9
  4. package/src/action-approval/BatchTasksApprovalFrameView.tsx +4 -1
  5. package/src/action-approval/GenericActionApprovalView.tsx +2 -9
  6. package/src/action-approval/ManageActionApprovalFrameView.tsx +4 -1
  7. package/src/action-approval/NavigationOpenApprovalView.tsx +2 -9
  8. package/src/action-approval/SchedulerActionApprovalDialogView.tsx +3 -1
  9. package/src/action-approval/SchedulerEditApprovalDrawerView.tsx +3 -10
  10. package/src/action-approval/index.ts +0 -1
  11. package/src/activity/ActivityPanel.tsx +13 -10
  12. package/src/activity/ActivityPanelFrame.test.tsx +32 -0
  13. package/src/activity/ActivityPanelFrame.tsx +3 -2
  14. package/src/activity/BackgroundTasksTabPanelView.tsx +1 -1
  15. package/src/activity/BrowserPanelView.tsx +48 -49
  16. package/src/activity/DebugTabPanelView.tsx +1 -1
  17. package/src/activity/MarkdownPreviewView.tsx +56 -59
  18. package/src/activity/PluginTabPickerView.tsx +5 -3
  19. package/src/activity/PortsTabPanelView.tsx +911 -0
  20. package/src/activity/ToolCallsSubTabView.tsx +1 -1
  21. package/src/activity/WorkflowTabPanelView.tsx +1 -1
  22. package/src/activity/index.ts +9 -0
  23. package/src/app/AppBackground.tsx +1 -1
  24. package/src/app/AppBootLoadingView.tsx +4 -2
  25. package/src/app-shell/DefaultWindowControls.tsx +1 -1
  26. package/src/app-shell/PageHeaderActionGroup.tsx +1 -1
  27. package/src/app-shell/PageHeaderContent.tsx +36 -7
  28. package/src/app-shell/PageHeaderFrame.tsx +15 -3
  29. package/src/app-shell/PageHeaderSidebarTrigger.tsx +1 -1
  30. package/src/app-shell/PageHeaderTitle.tsx +1 -1
  31. package/src/app-shell/WindowControlButton.tsx +1 -1
  32. package/src/app-shell/header-crowding.test.ts +62 -0
  33. package/src/app-shell/header-crowding.tsx +137 -0
  34. package/src/appearance/BackgroundImageFrame.tsx +1 -1
  35. package/src/appearance/CenterSliceImageFrame.tsx +1 -1
  36. package/src/appearance/CornerImageFrame.tsx +1 -1
  37. package/src/appearance/HorizontalSliceImageFrame.tsx +1 -1
  38. package/src/appearance/NineSliceImageFrame.tsx +1 -1
  39. package/src/appearance/ThemeSurface.tsx +1 -1
  40. package/src/batch-tasks/BatchProjectFoldersFieldView.tsx +2 -1
  41. package/src/batch-tasks/BatchTaskProjectActionsView.test.tsx +97 -0
  42. package/src/batch-tasks/BatchTaskProjectActionsView.tsx +45 -35
  43. package/src/batch-tasks/batchTaskUi.tsx +0 -29
  44. package/src/bottom-panel/BottomPanelView.test.tsx +43 -0
  45. package/src/bottom-panel/BottomPanelView.tsx +222 -0
  46. package/src/bottom-panel/index.ts +26 -0
  47. package/src/chat/AgentAvatarView.tsx +1 -1
  48. package/src/chat/AnnotationViews.tsx +107 -0
  49. package/src/chat/AskUserQuestionView.tsx +18 -11
  50. package/src/chat/AssistantMessageView.tsx +48 -13
  51. package/src/chat/AtPanelView.test.tsx +61 -0
  52. package/src/chat/AtPanelView.tsx +63 -38
  53. package/src/chat/BashTerminalCard.tsx +1 -2
  54. package/src/chat/ChatHeaderActionsView.tsx +74 -18
  55. package/src/chat/CompactionStepView.test.tsx +34 -0
  56. package/src/chat/CompactionStepView.tsx +85 -0
  57. package/src/chat/ExecutionModeSelectorView.tsx +20 -5
  58. package/src/chat/HeaderActionBarView.tsx +731 -0
  59. package/src/chat/HeaderActionOverflowMenu.tsx +137 -0
  60. package/src/chat/InlineModelPicker.test.tsx +81 -0
  61. package/src/chat/InlineModelPicker.tsx +201 -0
  62. package/src/chat/InlineTokenChip.tsx +2 -68
  63. package/src/chat/InputBarBackground.tsx +1 -1
  64. package/src/chat/InputBarPlaceholder.tsx +26 -3
  65. package/src/chat/LiveThinkingView.tsx +51 -37
  66. package/src/chat/MessageBoundaryViews.tsx +21 -0
  67. package/src/chat/MessageFeedContext.tsx +13 -5
  68. package/src/chat/MessageFeedLayoutView.tsx +28 -3
  69. package/src/chat/MessageFeedView.test.tsx +81 -0
  70. package/src/chat/MessageFeedView.tsx +72 -152
  71. package/src/chat/MessageInputView.tsx +1 -1
  72. package/src/chat/MessageLayoutView.tsx +1 -1
  73. package/src/chat/MessageSelectionContextMenuView.tsx +4 -1
  74. package/src/chat/MessageTimelineView.tsx +1 -1
  75. package/src/chat/MessageView.tsx +1 -1
  76. package/src/chat/MessageVisualView.tsx +1 -1
  77. package/src/chat/ModelConfiguration.tsx +283 -0
  78. package/src/chat/ModelSelectorTrigger.tsx +63 -0
  79. package/src/chat/ModelSelectorView.tsx +1037 -223
  80. package/src/chat/NewSession.ts +1 -37
  81. package/src/chat/NewSessionPicker.tsx +3 -2
  82. package/src/chat/ProjectSelectorView.tsx +3 -2
  83. package/src/chat/ReasoningStepSlider.tsx +61 -0
  84. package/src/chat/RemoteSessionBadgeView.tsx +24 -0
  85. package/src/chat/SkillPromptAreaView.tsx +5 -19
  86. package/src/chat/TeamMemberReplyCardView.test.tsx +33 -0
  87. package/src/chat/TeamMemberReplyCardView.tsx +133 -0
  88. package/src/chat/TextBlockView.tsx +7 -770
  89. package/src/chat/TodoProgress.tsx +25 -53
  90. package/src/chat/TodoStatusBarView.tsx +14 -5
  91. package/src/chat/UserMessageView.tsx +113 -33
  92. package/src/chat/header-action-narrow.test.ts +21 -0
  93. package/src/chat/header-action-narrow.ts +38 -0
  94. package/src/chat/index.ts +32 -27
  95. package/src/chat/markdown-link.ts +7 -279
  96. package/src/chat/send-button.css +4 -22
  97. package/src/chat/streaming-reveal.test.ts +218 -0
  98. package/src/chat/streaming-reveal.ts +13 -0
  99. package/src/file-explorer/ConfirmDeleteDialogView.tsx +2 -1
  100. package/src/file-explorer/FileContextMenuView.tsx +44 -11
  101. package/src/file-explorer/FileExplorerSettingsView.tsx +97 -0
  102. package/src/file-explorer/FileTreeCreateRow.tsx +1 -1
  103. package/src/file-explorer/FileTreeNodeView.tsx +59 -18
  104. package/src/file-explorer/FileTreeView.tsx +236 -129
  105. package/src/file-explorer/file-tree-dom.ts +23 -0
  106. package/src/file-explorer/file-tree-rows.test.ts +74 -0
  107. package/src/file-explorer/file-tree-rows.ts +168 -0
  108. package/src/file-explorer/index.ts +17 -0
  109. package/src/file-explorer/types.ts +3 -0
  110. package/src/file-explorer/useFileTreeMarqueeSelection.ts +24 -16
  111. package/src/file-preview/FilePreviewDialogView.tsx +2 -2
  112. package/src/file-preview/FilePreviewView.tsx +12 -2
  113. package/src/file-preview/TextFileEditorView.tsx +2 -1
  114. package/src/index.ts +1 -0
  115. package/src/knowledge/KnowledgeHowItWorksDialogView.tsx +1 -1
  116. package/src/layout/AppFrame.tsx +3 -2
  117. package/src/layout/MainContentFrame.tsx +7 -2
  118. package/src/layout/ResizeHandle.tsx +68 -17
  119. package/src/layout/SidebarDock.tsx +75 -19
  120. package/src/layout/SidebarOverlay.tsx +1 -1
  121. package/src/layout/index.ts +1 -1
  122. package/src/layout/resize-handle-axis.test.ts +51 -0
  123. package/src/live-indicators.test.ts +43 -0
  124. package/src/markdown/CodeBlock.tsx +123 -0
  125. package/src/markdown/InlineTokenChip.tsx +68 -0
  126. package/src/markdown/MarkdownContent.tsx +411 -0
  127. package/src/markdown/MarkdownImage.tsx +51 -0
  128. package/src/markdown/MathFormula.tsx +46 -0
  129. package/src/markdown/MermaidBlock.tsx +43 -0
  130. package/src/markdown/RichCodeBlock.tsx +127 -0
  131. package/src/markdown/SvgPreview.tsx +45 -0
  132. package/src/markdown/WebsiteIcon.tsx +94 -0
  133. package/src/markdown/builtin-renderers.tsx +43 -0
  134. package/src/markdown/definition.tsx +49 -0
  135. package/src/markdown/host.tsx +18 -0
  136. package/src/markdown/index.ts +11 -0
  137. package/src/markdown/inline-tokens.ts +187 -0
  138. package/src/markdown/markdown-link.ts +279 -0
  139. package/src/markdown/math-client.ts +116 -0
  140. package/src/markdown/math-render.ts +23 -0
  141. package/src/markdown/math-syntax.ts +80 -0
  142. package/src/markdown/math.worker.ts +16 -0
  143. package/src/markdown/nodes.ts +15 -0
  144. package/src/markdown/preview-policy.ts +43 -0
  145. package/src/markdown/rich-labels.ts +49 -0
  146. package/src/markdown/rich-syntax.ts +93 -0
  147. package/src/markdown/stable-blocks.test.ts +90 -0
  148. package/src/markdown/stable-blocks.ts +124 -0
  149. package/src/markdown/streaming-reveal.ts +297 -0
  150. package/src/markdown/streaming.test.ts +57 -0
  151. package/src/markdown/streaming.ts +211 -0
  152. package/src/markdown/use-render-snapshot.ts +24 -0
  153. package/src/markdown/use-rich-visibility.ts +24 -0
  154. package/src/overlays/CommandMenuRow.tsx +38 -9
  155. package/src/overlays/CommandMenuView.tsx +77 -117
  156. package/src/overlays/ConfirmDialogView.tsx +25 -20
  157. package/src/overlays/ReleaseNoteMarkdown.tsx +29 -0
  158. package/src/overlays/SplashOptionRow.tsx +46 -0
  159. package/src/overlays/SplashPanel.tsx +85 -0
  160. package/src/overlays/SplashParts.tsx +213 -0
  161. package/src/overlays/UpdateCheckerView.tsx +34 -18
  162. package/src/overlays/UpdateRestartDialogView.tsx +139 -54
  163. package/src/overlays/command-menu-types.ts +2 -0
  164. package/src/overlays/command-menu.css +1 -20
  165. package/src/overlays/index.ts +14 -1
  166. package/src/plugin-ui/index.ts +8 -0
  167. package/src/project/ConversationTagDotsView.tsx +1 -1
  168. package/src/project/ConversationTagEditorDialogView.tsx +4 -1
  169. package/src/project/DefaultConversationSectionView.tsx +4 -4
  170. package/src/project/DefaultSessionListView.tsx +5 -31
  171. package/src/project/DefaultSessionRowView.tsx +106 -55
  172. package/src/project/ManageSessionsSplashView.tsx +439 -0
  173. package/src/project/NewProjectDialogView.tsx +3 -10
  174. package/src/project/ProjectContextMenuView.tsx +30 -139
  175. package/src/project/ProjectDetailPageView.test.tsx +140 -0
  176. package/src/project/ProjectDetailPageView.tsx +372 -165
  177. package/src/project/ProjectGroupView.tsx +1 -1
  178. package/src/project/ProjectRowView.tsx +29 -12
  179. package/src/project/ProjectSessionsView.tsx +25 -47
  180. package/src/project/QuickScrollOverlay.tsx +1 -1
  181. package/src/project/SessionContextMenuView.tsx +15 -7
  182. package/src/project/SessionRowMoreButton.tsx +50 -0
  183. package/src/project/SessionRowView.tsx +106 -63
  184. package/src/project/SessionTitleMarquee.tsx +54 -0
  185. package/src/project/SidebarProjectDisclosure.tsx +60 -0
  186. package/src/project/SidebarProjectsSectionView.tsx +6 -1
  187. package/src/project/index.ts +12 -0
  188. package/src/project/session-row-transition.ts +9 -0
  189. package/src/project/types.ts +4 -2
  190. package/src/project/useActiveSessionAutoScroll.ts +10 -4
  191. package/src/registry.ts +0 -2
  192. package/src/scheduler/AutomationDetailPaneView.tsx +68 -0
  193. package/src/scheduler/AutomationPageView.tsx +118 -121
  194. package/src/scheduler/ExecutionHistoryView.tsx +7 -5
  195. package/src/scheduler/TaskListView.tsx +52 -201
  196. package/src/scheduler/index.ts +7 -12
  197. package/src/settings/AchievementSettingsView.tsx +0 -1
  198. package/src/settings/AppshotSettingsView.tsx +0 -1
  199. package/src/settings/BuiltinMcpSectionView.tsx +1 -1
  200. package/src/settings/EnvironmentGitRowView.tsx +156 -0
  201. package/src/settings/EnvironmentSettingsView.tsx +25 -3
  202. package/src/settings/GeneralSettingsView.tsx +17 -20
  203. package/src/settings/ImChannelGuideDialogView.tsx +2 -2
  204. package/src/settings/ImFeishuDialogView.tsx +1 -1
  205. package/src/settings/ImLegacyImportBannerView.tsx +1 -1
  206. package/src/settings/ImLogDrawerView.tsx +2 -1
  207. package/src/settings/JsonConfigInputView.tsx +171 -0
  208. package/src/settings/ModelsFetchedModelsDrawerView.tsx +292 -0
  209. package/src/settings/ModelsProvidersSectionView.tsx +26 -23
  210. package/src/settings/MotionSelect.tsx +9 -7
  211. package/src/settings/NotificationSettingsView.tsx +79 -0
  212. package/src/settings/PermissionsSettingsView.tsx +3 -7
  213. package/src/settings/PresetProviderModelsListView.tsx +141 -24
  214. package/src/settings/PresetProviderRowView.tsx +205 -182
  215. package/src/settings/ProxySettingsSectionView.tsx +182 -0
  216. package/src/settings/QrBindDialogView.tsx +1 -1
  217. package/src/settings/QuickPanelSettingsSectionView.tsx +0 -2
  218. package/src/settings/RemoteMcpSectionView.tsx +1 -1
  219. package/src/settings/SettingChrome.tsx +2 -2
  220. package/src/settings/SettingsAiAssistButtonView.tsx +9 -119
  221. package/src/settings/SettingsFormFields.tsx +4 -7
  222. package/src/settings/SettingsSidebarView.tsx +64 -3
  223. package/src/settings/ShortcutRecorderView.test.tsx +108 -0
  224. package/src/settings/ShortcutRecorderView.tsx +15 -9
  225. package/src/settings/ShortcutsSettingsView.tsx +1 -1
  226. package/src/settings/SpaceEditorDialogView.tsx +120 -0
  227. package/src/settings/SpacesSettingsView.tsx +105 -0
  228. package/src/settings/WebhookEndpointListView.tsx +4 -5
  229. package/src/settings/index.ts +41 -29
  230. package/src/shared/ActivityStatusDot.tsx +69 -0
  231. package/src/shared/AvatarStackView.tsx +13 -13
  232. package/src/shared/BotAvatar.tsx +11 -9
  233. package/src/shared/CodeBlockCopyButton.tsx +1 -1
  234. package/src/shared/ContextMenuView.tsx +4 -11
  235. package/src/shared/MarkdownTable.tsx +2 -2
  236. package/src/shared/SyntaxHighlightedCode.tsx +0 -0
  237. package/src/shared/TabBar.outline.test.tsx +59 -0
  238. package/src/shared/TabBar.tsx +22 -17
  239. package/src/shared/VettaKbd.test.tsx +52 -0
  240. package/src/shared/VettaKbd.tsx +81 -0
  241. package/src/shared/connected-tab-outline.test.ts +2 -2
  242. package/src/shared/connected-tab-outline.ts +2 -1
  243. package/src/shared/index.ts +6 -0
  244. package/src/shared/kbd-keys.test.ts +61 -0
  245. package/src/shared/kbd-keys.ts +253 -0
  246. package/src/shared/provider-icon/icons.ts +4 -2
  247. package/src/shared/provider-icon/index.tsx +1 -1
  248. package/src/shared/provider-icon/magpie.svg +1 -0
  249. package/src/sidebar/AddProjectMenuTriggerView.tsx +25 -15
  250. package/src/sidebar/DefaultSidebar.tsx +3 -1
  251. package/src/sidebar/MessageCenterDialogView.tsx +3 -2
  252. package/src/sidebar/MessageCenterEmptyState.tsx +1 -1
  253. package/src/sidebar/MessageCenterTabs.tsx +1 -1
  254. package/src/sidebar/MessageCenterToolbarButton.tsx +1 -1
  255. package/src/sidebar/MessageCenterTriggerView.tsx +2 -2
  256. package/src/sidebar/ProjectsPanelEmptyState.tsx +26 -7
  257. package/src/sidebar/SessionStatusIcon.tsx +16 -1
  258. package/src/sidebar/SettingsMenuThemeSection.tsx +1 -1
  259. package/src/sidebar/SettingsMenuTriggerView.test.tsx +42 -0
  260. package/src/sidebar/SettingsMenuTriggerView.tsx +28 -50
  261. package/src/sidebar/ShowMoreSessionsButton.tsx +1 -1
  262. package/src/sidebar/SidebarFilterSelectView.tsx +8 -16
  263. package/src/sidebar/SidebarNavBadgeView.tsx +1 -1
  264. package/src/sidebar/SidebarNavIcon.tsx +1 -1
  265. package/src/sidebar/SidebarNavItemButton.tsx +1 -1
  266. package/src/sidebar/SidebarNavMorePanel.tsx +19 -7
  267. package/src/sidebar/SidebarNavigation.tsx +24 -15
  268. package/src/sidebar/SidebarPanel.tsx +11 -2
  269. package/src/sidebar/SidebarSectionTriggerLabel.tsx +20 -0
  270. package/src/sidebar/SidebarTopBar.tsx +10 -7
  271. package/src/sidebar/WaitingPulseBadge.tsx +19 -0
  272. package/src/sidebar/index.ts +1 -16
  273. package/src/skills/index.ts +0 -19
  274. package/src/skills/skill-icon.tsx +4 -8
  275. package/src/styles.css +24 -6
  276. package/src/chat/DefaultSceneCarousel.tsx +0 -113
  277. package/src/chat/SceneCard.tsx +0 -138
  278. package/src/scheduler/HistoryDrawerView.tsx +0 -149
  279. package/src/scheduler/TaskFormDialogView.tsx +0 -60
  280. package/src/settings/SubscriptionActionsView.tsx +0 -63
  281. package/src/settings/SubscriptionCardsView.tsx +0 -212
  282. package/src/settings/TeamDetailView.tsx +0 -148
  283. package/src/settings/TeamDialogsView.tsx +0 -151
  284. package/src/settings/TeamListView.tsx +0 -57
  285. package/src/settings/TeamSettingsView.tsx +0 -51
  286. package/src/settings/TokenActivityChartView.tsx +0 -286
  287. package/src/settings/UsageStatsView.tsx +0 -101
  288. package/src/settings/shouldCloseEmptyApiKeyEditor.test.ts +0 -135
  289. package/src/settings/shouldCloseEmptyApiKeyEditor.ts +0 -40
  290. package/src/settings/token-activity.test.ts +0 -195
  291. package/src/settings/token-activity.ts +0 -320
  292. package/src/sidebar/AddProjectMenuItem.tsx +0 -21
  293. package/src/sidebar/AddProjectMenuPopoverView.tsx +0 -52
  294. package/src/sidebar/NotificationMessageListView.tsx +0 -136
  295. package/src/sidebar/SettingsMenuAccountSection.tsx +0 -32
  296. package/src/sidebar/SettingsMenuQuotaSection.tsx +0 -45
  297. package/src/skills/SceneCardView.tsx +0 -194
  298. package/src/skills/SkillCardView.tsx +0 -186
  299. package/src/skills/SkillDetailDialogView.tsx +0 -138
  300. package/src/skills/SkillTagGroupView.tsx +0 -56
  301. package/src/skills/SkillToggleSwitch.tsx +0 -31
@@ -1,770 +1,7 @@
1
- import { memo, useCallback, useEffect, useMemo, useRef, useState, type JSX } from "react";
2
- import ReactMarkdown from "react-markdown";
3
- import type { Components } from "react-markdown";
4
- import remarkGfm from "remark-gfm";
5
- import { CodeBlockCopyButtonView } from "../shared/CodeBlockCopyButton";
6
- import {
7
- MarkdownTable,
8
- MarkdownTableBody,
9
- MarkdownTableCell,
10
- MarkdownTableHead,
11
- MarkdownTableHeaderCell,
12
- MarkdownTableRow,
13
- } from "../shared/MarkdownTable";
14
- import { SyntaxHighlightedCode } from "../shared/SyntaxHighlightedCode";
15
- import { SkillTypeIcon } from "../skills/skill-icon";
16
- import { InlineTokenChip } from "./InlineTokenChip";
17
- import {
18
- chatUrlTransform,
19
- classifyMarkdownLink,
20
- normalizeLocalFileLinksInMarkdown,
21
- } from "./markdown-link";
22
-
23
- /** Minimal hast-like nodes for the streaming chunk rehype plugin. */
24
- interface HastText {
25
- type: "text";
26
- value: string;
27
- }
28
- interface HastElement {
29
- type: "element";
30
- tagName: string;
31
- properties?: Record<string, unknown>;
32
- children: Array<HastText | HastElement>;
33
- }
34
- interface HastRoot {
35
- type: "root";
36
- children: Array<HastText | HastElement>;
37
- }
38
-
39
- /** 文件 / 链接 badge 的公共样式:半透明主题色底 + 主题色描边与文字。 */
40
- const LINK_BADGE_CLASS =
41
- "inline-flex max-w-full items-center gap-1 rounded-md border border-primary/25 bg-primary/10 px-1.5 py-px align-middle text-[13px] font-medium text-primary no-underline transition-colors hover:bg-primary/20";
42
-
43
- const remarkPlugins = [remarkGfm];
44
-
45
- /**
46
- * 用户消息里的行内 token(skill / scene 引用、文件、图片)。
47
- * 语法归宿主所有——theme-ui 只负责渲染,解析函数由 inlineTokens.parse 注入。
48
- */
49
- export type InlineTokenPiece =
50
- | { kind: "text"; text: string }
51
- | { kind: "skill"; name: string }
52
- | { kind: "scene"; name: string }
53
- | { kind: "connector"; name: string }
54
- | { kind: "member"; participantId: string; handle: string }
55
- | { kind: "file"; path: string; isDirectory?: boolean }
56
- | { kind: "image"; path: string };
57
-
58
- export interface InlineTokenSupport {
59
- parse: (text: string) => InlineTokenPiece[];
60
- /** Structured annotations into the original Markdown source; never inferred from display text. */
61
- annotations?: readonly InlineTokenAnnotation[];
62
- /**
63
- * 图片 token 的胶囊文案(如「图 1」)。缩略图不在文本流里渲染,
64
- * 它们集中在气泡上方并带同样的编号,因此这里只要一个标签。
65
- */
66
- getImageLabel: (path: string) => string;
67
- /** 连接器的展示名与 logo;查不到时回退成真实名 + 通用图标。 */
68
- getConnector?: (name: string) => { label: string; iconUrl?: string } | undefined;
69
- /**
70
- * skill 的展示名与图标。文本流里只有 slug,别名/图标要宿主回查,
71
- * 否则气泡里的胶囊与输入框里刚插入的那枚对不上。查不到时回退成 slug + 默认图。
72
- */
73
- getSkill?: (name: string) => { label: string; icon?: string } | undefined;
74
- /** scene 与 skill 共用视觉语言,但使用场景图标和独立元数据命名空间。 */
75
- getScene?: (name: string) => { label: string; icon?: string } | undefined;
76
- /** Team member metadata resolved by stable participant identity. */
77
- getMember?: (participantId: string) => { label: string; avatar?: string; meta?: string } | undefined;
78
- }
79
-
80
- interface InlineTokenAnnotationRange {
81
- /** Exact serialized token text, used to reject stale or mismatched offsets. */
82
- readonly text: string;
83
- /** UTF-16 offsets into the original Markdown source. */
84
- readonly start: number;
85
- readonly end: number;
86
- }
87
-
88
- export type InlineTokenAnnotation =
89
- | ({ readonly kind: "skill" | "scene" | "connector"; readonly name: string } & InlineTokenAnnotationRange)
90
- | ({
91
- readonly kind: "file" | "image";
92
- readonly path: string;
93
- readonly isDirectory?: boolean;
94
- } & InlineTokenAnnotationRange)
95
- | ({
96
- readonly kind: "member";
97
- readonly participantId: string;
98
- readonly handle: string;
99
- } & InlineTokenAnnotationRange);
100
-
101
- const INLINE_TOKEN_TAG = "vetta-inline-token";
102
-
103
- /** 把文本节点里的 token 换成自定义元素;代码块与链接文本内不处理。 */
104
- function rehypeInlineTokens(parse: (text: string) => InlineTokenPiece[]) {
105
- return (tree: HastRoot): void => {
106
- function visit(node: HastRoot | HastElement, inLiteral: boolean): void {
107
- const newChildren: Array<(typeof node.children)[number]> = [];
108
- for (const child of node.children) {
109
- if (child.type === "text" && !inLiteral) {
110
- const pieces = parse((child as HastText).value);
111
- if (pieces.length === 1 && pieces[0].kind === "text") {
112
- newChildren.push(child);
113
- continue;
114
- }
115
- for (const piece of pieces) {
116
- if (piece.kind === "text") {
117
- newChildren.push({ type: "text", value: piece.text } as HastText);
118
- continue;
119
- }
120
- newChildren.push({
121
- type: "element",
122
- tagName: INLINE_TOKEN_TAG,
123
- properties: {
124
- "data-token-kind": piece.kind,
125
- "data-token-value":
126
- piece.kind === "skill" || piece.kind === "scene" || piece.kind === "connector"
127
- ? piece.name
128
- : piece.kind === "member"
129
- ? piece.participantId
130
- : piece.path,
131
- "data-token-directory": piece.kind === "file" && piece.isDirectory ? "true" : "false",
132
- },
133
- children: [],
134
- });
135
- }
136
- continue;
137
- }
138
- newChildren.push(child);
139
- if (child.type === "element") {
140
- const tag = child.tagName;
141
- visit(child, inLiteral || tag === "code" || tag === "pre" || tag === "a");
142
- }
143
- }
144
- node.children = newChildren as typeof node.children;
145
- }
146
-
147
- visit(tree, false);
148
- };
149
- }
150
-
151
- interface MdastNode {
152
- type: string;
153
- value?: string;
154
- children?: MdastNode[];
155
- position?: { start?: { offset?: number }; end?: { offset?: number } };
156
- data?: { hName?: string; hProperties?: Record<string, unknown> };
157
- }
158
-
159
- function remarkInlineTokenAnnotations(annotations: readonly InlineTokenAnnotation[]) {
160
- const ordered = [...annotations].sort((left, right) => left.start - right.start || left.end - right.end);
161
- return (tree: MdastNode): void => {
162
- function visit(node: MdastNode, inLiteral: boolean): void {
163
- if (!node.children) return;
164
- const nextChildren: MdastNode[] = [];
165
- for (const child of node.children) {
166
- const literal = inLiteral || child.type === "code" || child.type === "inlineCode" || child.type === "link";
167
- const nodeStart = child.position?.start?.offset;
168
- const nodeEnd = child.position?.end?.offset;
169
- if (child.type !== "text" || literal || nodeStart === undefined || nodeEnd === undefined) {
170
- nextChildren.push(child);
171
- visit(child, literal);
172
- continue;
173
- }
174
- const value = child.value ?? "";
175
- const contained = ordered.filter(
176
- (annotation) => annotation.start >= nodeStart && annotation.end <= nodeEnd,
177
- );
178
- if (contained.length === 0) {
179
- nextChildren.push(child);
180
- continue;
181
- }
182
- let cursor = 0;
183
- for (const annotation of contained) {
184
- const start = annotation.start - nodeStart;
185
- const end = annotation.end - nodeStart;
186
- if (start < cursor || end <= start || value.slice(start, end) !== annotation.text) continue;
187
- if (annotation.kind === "member" && annotation.text !== `@${annotation.handle}`) continue;
188
- if (start > cursor) nextChildren.push({ type: "text", value: value.slice(cursor, start) });
189
- const tokenValue =
190
- "name" in annotation
191
- ? annotation.name
192
- : "participantId" in annotation
193
- ? annotation.participantId
194
- : annotation.path;
195
- nextChildren.push({
196
- type: "inlineToken",
197
- data: {
198
- hName: INLINE_TOKEN_TAG,
199
- hProperties: {
200
- "data-token-kind": annotation.kind,
201
- "data-token-value": tokenValue,
202
- ...(annotation.kind === "member"
203
- ? { "data-token-handle": annotation.handle }
204
- : {}),
205
- ...(annotation.kind === "file"
206
- ? { "data-token-directory": annotation.isDirectory ? "true" : "false" }
207
- : {}),
208
- },
209
- },
210
- });
211
- cursor = end;
212
- }
213
- if (cursor < value.length) nextChildren.push({ type: "text", value: value.slice(cursor) });
214
- }
215
- node.children = nextChildren;
216
- }
217
-
218
- visit(tree, false);
219
- };
220
- }
221
-
222
- function projectAnnotationsToNormalizedMarkdown(
223
- source: string,
224
- normalizedSource: string,
225
- annotations: readonly InlineTokenAnnotation[],
226
- ): InlineTokenAnnotation[] {
227
- if (source === normalizedSource) return [...annotations];
228
- return annotations.flatMap((annotation): InlineTokenAnnotation[] => {
229
- if (source.slice(annotation.start, annotation.end) !== annotation.text) return [];
230
- const start = normalizeLocalFileLinksInMarkdown(source.slice(0, annotation.start)).length;
231
- const end = normalizeLocalFileLinksInMarkdown(source.slice(0, annotation.end)).length;
232
- return normalizedSource.slice(start, end) === annotation.text ? [{ ...annotation, start, end }] : [];
233
- });
234
- }
235
-
236
- const STREAMING_CHUNK_SIZE = 10;
237
-
238
- function rehypeStreamingChunks() {
239
- return (tree: HastRoot): void => {
240
- function visit(node: HastRoot | HastElement, inCode: boolean): void {
241
- const newChildren: Array<(typeof node.children)[number]> = [];
242
- for (const child of node.children) {
243
- if (child.type === "text" && !inCode) {
244
- const value = (child as HastText).value;
245
- for (let index = 0; index < value.length; ) {
246
- const spaceMatch = /^\s+/.exec(value.slice(index));
247
- if (spaceMatch) {
248
- newChildren.push({ type: "text", value: spaceMatch[0] } as HastText);
249
- index += spaceMatch[0].length;
250
- continue;
251
- }
252
-
253
- const end = getSliceEnd(value, index, STREAMING_CHUNK_SIZE);
254
- newChildren.push({
255
- type: "element",
256
- tagName: "span",
257
- properties: { className: ["streaming-chunk"] },
258
- children: [{ type: "text", value: value.slice(index, end) } as HastText],
259
- });
260
- index = end;
261
- }
262
- } else {
263
- newChildren.push(child);
264
- if (child.type === "element") {
265
- const tag = child.tagName;
266
- // 表格也当字面量:把单元格文字拆成 inline-block 的 chunk span 会打乱
267
- // 列宽测量,流式期表格会逐帧抖动。
268
- visit(child, inCode || tag === "code" || tag === "pre" || tag === "table");
269
- }
270
- }
271
- }
272
- node.children = newChildren as typeof node.children;
273
- }
274
-
275
- visit(tree, false);
276
- };
277
- }
278
-
279
- const streamingRehypePlugins = [rehypeStreamingChunks];
280
- const STREAM_REVEAL_INTERVAL_MS = 500;
281
-
282
- function getSliceEnd(text: string, start: number, count: number): number {
283
- let end = Math.min(text.length, start + count);
284
- if (end < text.length) {
285
- const previous = text.charCodeAt(end - 1);
286
- const next = text.charCodeAt(end);
287
- if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
288
- end++;
289
- }
290
- }
291
- return end;
292
- }
293
-
294
- interface StreamingDisplayState {
295
- displayText: string;
296
- animateChunks: boolean;
297
- }
298
-
299
- function useStreamingDisplayText(text: string, active: boolean): StreamingDisplayState {
300
- const [displayText, setDisplayText] = useState(() => (active ? "" : text));
301
- const [animateChunks, setAnimateChunks] = useState(active);
302
- const displayRef = useRef(active ? "" : text);
303
- const targetRef = useRef(text);
304
- const rafRef = useRef<number | null>(null);
305
- const revealTimerRef = useRef<number | null>(null);
306
- const lastRevealRef = useRef<number | null>(null);
307
- const settleTimerRef = useRef<number | null>(null);
308
- const wasActiveRef = useRef(active);
309
-
310
- useEffect(() => {
311
- targetRef.current = text;
312
-
313
- function clearSettleTimer(): void {
314
- if (settleTimerRef.current !== null) {
315
- window.clearTimeout(settleTimerRef.current);
316
- settleTimerRef.current = null;
317
- }
318
- }
319
-
320
- function clearRevealTimer(): void {
321
- if (revealTimerRef.current !== null) {
322
- window.clearTimeout(revealTimerRef.current);
323
- revealTimerRef.current = null;
324
- }
325
- }
326
-
327
- function scheduleSettle(): void {
328
- clearSettleTimer();
329
- settleTimerRef.current = window.setTimeout(() => {
330
- setAnimateChunks(false);
331
- settleTimerRef.current = null;
332
- }, STREAM_REVEAL_INTERVAL_MS);
333
- }
334
-
335
- function scheduleReveal(delayMs: number): void {
336
- if (delayMs <= 0) {
337
- if (rafRef.current === null) {
338
- rafRef.current = requestAnimationFrame(tick);
339
- }
340
- return;
341
- }
342
- if (revealTimerRef.current !== null) return;
343
- revealTimerRef.current = window.setTimeout(() => {
344
- revealTimerRef.current = null;
345
- if (rafRef.current === null) {
346
- rafRef.current = requestAnimationFrame(tick);
347
- }
348
- }, delayMs);
349
- }
350
-
351
- /**
352
- * Non-tail mode (e.g. marketing story drives its own char reveal):
353
- * mirror `text` immediately. Do not 500ms-batch catch-up — that dumps
354
- * the whole backlog as one flash on top of the host’s progressive text.
355
- */
356
- if (!active) {
357
- if (rafRef.current !== null) {
358
- cancelAnimationFrame(rafRef.current);
359
- rafRef.current = null;
360
- }
361
- clearRevealTimer();
362
- clearSettleTimer();
363
- displayRef.current = text;
364
- setDisplayText(text);
365
- setAnimateChunks(false);
366
- lastRevealRef.current = null;
367
- wasActiveRef.current = active;
368
- return () => {
369
- clearRevealTimer();
370
- clearSettleTimer();
371
- };
372
- }
373
-
374
- if (!text.startsWith(displayRef.current)) {
375
- if (rafRef.current !== null) {
376
- cancelAnimationFrame(rafRef.current);
377
- rafRef.current = null;
378
- }
379
- clearRevealTimer();
380
- clearSettleTimer();
381
- setDisplayText(text);
382
- setAnimateChunks(false);
383
- displayRef.current = text;
384
- lastRevealRef.current = null;
385
- wasActiveRef.current = active;
386
- return;
387
- }
388
-
389
- function tick(timestamp: number): void {
390
- rafRef.current = null;
391
- const target = targetRef.current;
392
- const current = displayRef.current;
393
- const backlog = target.length - current.length;
394
-
395
- if (backlog <= 0) {
396
- lastRevealRef.current = timestamp;
397
- return;
398
- }
399
-
400
- const previousReveal = lastRevealRef.current;
401
- if (previousReveal !== null && timestamp - previousReveal < STREAM_REVEAL_INTERVAL_MS) {
402
- scheduleReveal(STREAM_REVEAL_INTERVAL_MS - (timestamp - previousReveal));
403
- return;
404
- }
405
- lastRevealRef.current = timestamp;
406
-
407
- // Catch up to the host target for this interval (chunk animation via rehype).
408
- const next = target;
409
- displayRef.current = next;
410
- setAnimateChunks(true);
411
- setDisplayText(next);
412
- }
413
-
414
- if (active && !wasActiveRef.current && displayRef.current.length >= text.length) {
415
- clearSettleTimer();
416
- displayRef.current = "";
417
- setDisplayText("");
418
- lastRevealRef.current = null;
419
- }
420
- wasActiveRef.current = active;
421
- clearRevealTimer();
422
- clearSettleTimer();
423
- setAnimateChunks(true);
424
-
425
- if (rafRef.current === null && displayRef.current.length < text.length) {
426
- const previousReveal = lastRevealRef.current;
427
- const delayMs =
428
- previousReveal === null
429
- ? 0
430
- : Math.max(0, STREAM_REVEAL_INTERVAL_MS - (performance.now() - previousReveal));
431
- scheduleReveal(delayMs);
432
- }
433
-
434
- return () => {
435
- if (rafRef.current !== null) {
436
- cancelAnimationFrame(rafRef.current);
437
- rafRef.current = null;
438
- }
439
- clearRevealTimer();
440
- clearSettleTimer();
441
- };
442
- }, [text, active]);
443
-
444
- return { displayText, animateChunks };
445
- }
446
-
447
- function cn(...parts: Array<string | false | null | undefined>): string {
448
- return parts.filter(Boolean).join(" ");
449
- }
450
-
451
- export interface TextBlockViewLabels {
452
- copy: string;
453
- copied: string;
454
- /** 表格工具条:复制成 GFM 表格 / CSV。 */
455
- }
456
-
457
- export interface TextBlockViewProps {
458
- text: string;
459
- isStreamingTail?: boolean;
460
- className?: string;
461
- theme: "light" | "dark";
462
- labels: TextBlockViewLabels;
463
- getFileIconClass: (fileName: string) => string;
464
- onOpenFile: (path: string) => void;
465
- onOpenUrl: (url: string) => void;
466
- /** 传入即启用行内 token 渲染;仅用户消息需要,助手 markdown 不受影响。 */
467
- inlineTokens?: InlineTokenSupport;
468
- }
469
-
470
- function basename(path: string): string {
471
- const normalized = path.replace(/[\\/]+$/, "");
472
- const idx = Math.max(normalized.lastIndexOf("/"), normalized.lastIndexOf("\\"));
473
- return idx === -1 ? normalized : normalized.slice(idx + 1);
474
- }
475
-
476
- function CodeBlockShell({
477
- lang,
478
- code,
479
- theme,
480
- labels,
481
- }: {
482
- lang: string;
483
- code: string;
484
- theme: "light" | "dark";
485
- labels: TextBlockViewLabels;
486
- }): JSX.Element {
487
- const [copied, setCopied] = useState(false);
488
- const timerRef = useRef<number | null>(null);
489
-
490
- useEffect(() => {
491
- return () => {
492
- if (timerRef.current !== null) window.clearTimeout(timerRef.current);
493
- };
494
- }, []);
495
-
496
- const onCopy = useCallback(() => {
497
- void navigator.clipboard.writeText(code).then(() => {
498
- setCopied(true);
499
- if (timerRef.current !== null) window.clearTimeout(timerRef.current);
500
- timerRef.current = window.setTimeout(() => setCopied(false), 1500);
501
- });
502
- }, [code]);
503
-
504
- return (
505
- <CodeBlockCopyButtonView copied={copied} onCopy={onCopy} labels={labels}>
506
- <div className="my-2 overflow-hidden rounded-lg border border-border bg-muted">
507
- {lang && (
508
- <div className="border-b border-border px-3 py-1 text-[10px] font-medium text-muted-foreground/50">
509
- {lang}
510
- </div>
511
- )}
512
- <SyntaxHighlightedCode code={code} lang={lang} theme={theme} fontSizeClass="text-[13px]" />
513
- </div>
514
- </CodeBlockCopyButtonView>
515
- );
516
- }
517
-
518
- /**
519
- * Memo'd markdown renderer for chat text blocks. Host injects file/url handlers and theme.
520
- *
521
- * `components` 映射的函数引用必须在 streaming 期间保持稳定:React 把 components.p 等
522
- * 当成元素类型;引用一变就会整树 remount,`.streaming-chunk` 的 CSS 入场动画对已有
523
- * 文本整段重播,表现为 text block 高频闪烁。labels / 回调通过 ref 读取,不进 deps。
524
- */
525
- export const TextBlockView = memo(function TextBlockView({
526
- text,
527
- isStreamingTail = false,
528
- className,
529
- theme,
530
- labels,
531
- getFileIconClass,
532
- onOpenFile,
533
- onOpenUrl,
534
- inlineTokens,
535
- }: TextBlockViewProps): JSX.Element {
536
- const { displayText, animateChunks } = useStreamingDisplayText(text, isStreamingTail);
537
-
538
- const labelsRef = useRef(labels);
539
- const getFileIconClassRef = useRef(getFileIconClass);
540
- const onOpenFileRef = useRef(onOpenFile);
541
- const onOpenUrlRef = useRef(onOpenUrl);
542
- const inlineTokensRef = useRef(inlineTokens);
543
- labelsRef.current = labels;
544
- getFileIconClassRef.current = getFileIconClass;
545
- onOpenFileRef.current = onOpenFile;
546
- onOpenUrlRef.current = onOpenUrl;
547
- inlineTokensRef.current = inlineTokens;
548
-
549
- const components = useMemo<Components>(
550
- () => ({
551
- h1: ({ children }) => (
552
- <h1 className="mb-3 mt-4 text-[20px] font-bold leading-tight text-foreground">{children}</h1>
553
- ),
554
- h2: ({ children }) => (
555
- <h2 className="mb-2 mt-3.5 text-[17px] font-bold leading-tight text-foreground">{children}</h2>
556
- ),
557
- h3: ({ children }) => (
558
- <h3 className="mb-2 mt-3 text-[15px] font-semibold leading-tight text-foreground">{children}</h3>
559
- ),
560
- h4: ({ children }) => (
561
- <h4 className="mb-1.5 mt-2.5 text-[14px] font-semibold text-foreground">{children}</h4>
562
- ),
563
- p: ({ children }) => <p className="my-1.5 text-[14px] leading-[1.6] text-foreground">{children}</p>,
564
- ul: ({ children }) => (
565
- <ul className="md-bullet-list my-1.5 text-[14px] leading-[1.6] text-foreground">{children}</ul>
566
- ),
567
- ol: ({ children }) => (
568
- <ol className="my-1.5 ml-4 list-decimal space-y-0.5 text-[14px] leading-[1.6] text-foreground marker:text-primary">
569
- {children}
570
- </ol>
571
- ),
572
- li: ({ children }) => <li>{children}</li>,
573
- code: ({ className: codeClassName, children }) => {
574
- const raw = String(children);
575
- const isBlock = (codeClassName?.startsWith("language-") ?? false) || raw.includes("\n");
576
- if (isBlock) {
577
- const lang = codeClassName?.replace("language-", "") ?? "";
578
- const code = raw.replace(/\n$/, "");
579
- return (
580
- <CodeBlockShell lang={lang} code={code} theme={theme} labels={labelsRef.current} />
581
- );
582
- }
583
- return <code className="rounded bg-muted px-1 py-0.5 text-[13px] text-foreground">{children}</code>;
584
- },
585
- pre: ({ children }) => <>{children}</>,
586
- blockquote: ({ children }) => (
587
- <blockquote className="my-2 border-l-2 border-primary/10 pl-3 text-[14px] italic text-muted-foreground">
588
- {children}
589
- </blockquote>
590
- ),
591
- table: ({ children }) => <MarkdownTable>{children}</MarkdownTable>,
592
- thead: ({ children }) => <MarkdownTableHead>{children}</MarkdownTableHead>,
593
- tbody: ({ children }) => <MarkdownTableBody>{children}</MarkdownTableBody>,
594
- tr: ({ children }) => <MarkdownTableRow>{children}</MarkdownTableRow>,
595
- // style 透传:remark-gfm 把 GFM 的列对齐(`|---:|`)写在这里。
596
- th: ({ children, style }) => (
597
- <MarkdownTableHeaderCell style={style}>{children}</MarkdownTableHeaderCell>
598
- ),
599
- td: ({ children, style }) => <MarkdownTableCell style={style}>{children}</MarkdownTableCell>,
600
- hr: () => <hr className="my-3 border-border" />,
601
- a: ({ href, children }) => {
602
- const kind = classifyMarkdownLink(href);
603
- if (kind.type === "file") {
604
- const fileName = basename(kind.path);
605
- return (
606
- <button
607
- type="button"
608
- title={kind.path}
609
- className={cn(LINK_BADGE_CLASS, "cursor-pointer")}
610
- onClick={() => onOpenFileRef.current(kind.path)}
611
- >
612
- <span
613
- className={cn(getFileIconClassRef.current(fileName), "h-3.5 w-3.5 shrink-0")}
614
- />
615
- <span className="truncate">{children}</span>
616
- </button>
617
- );
618
- }
619
- if (kind.type === "url") {
620
- return (
621
- <a
622
- href={kind.url}
623
- title={kind.url}
624
- className={LINK_BADGE_CLASS}
625
- onClick={(e) => {
626
- e.preventDefault();
627
- onOpenUrlRef.current(kind.url);
628
- }}
629
- >
630
- <span className="icon-[mdi--web] h-3.5 w-3.5 shrink-0" />
631
- <span className="truncate">{children}</span>
632
- </a>
633
- );
634
- }
635
- // mailto / fragment / unknown: never target=_blank — that opens the OS browser
636
- // for misclassified local paths. Keep visible but non-navigating.
637
- return (
638
- <span
639
- className="text-chart-2 underline decoration-chart-2/30"
640
- title={kind.href || undefined}
641
- >
642
- {children}
643
- </span>
644
- );
645
- },
646
- strong: ({ children }) => <strong className="font-semibold text-foreground">{children}</strong>,
647
- em: ({ children }) => <em className="italic">{children}</em>,
648
- // 行内 token:与输入框里的胶囊同款(半透明主题色底 + 描边,align-middle 对齐正文)。
649
- [INLINE_TOKEN_TAG]: ({ node }: { node?: HastElement }) => {
650
- const properties = node?.properties ?? {};
651
- const kind = String(properties["data-token-kind"] ?? "");
652
- const value = String(properties["data-token-value"] ?? "");
653
- if (!kind || !value) return null;
654
- if (kind === "image") {
655
- return (
656
- <InlineTokenChip
657
- icon="icon-[solar--gallery-linear]"
658
- label={inlineTokensRef.current?.getImageLabel(value) ?? basename(value)}
659
- title={basename(value)}
660
- />
661
- );
662
- }
663
- if (kind === "skill" || kind === "scene") {
664
- const ability =
665
- kind === "scene"
666
- ? inlineTokensRef.current?.getScene?.(value)
667
- : inlineTokensRef.current?.getSkill?.(value);
668
- return (
669
- <InlineTokenChip
670
- iconNode={<SkillTypeIcon type={kind} icon={ability?.icon} className="h-3 w-3" />}
671
- label={ability?.label ?? value}
672
- title={value}
673
- />
674
- );
675
- }
676
- if (kind === "connector") {
677
- const connector = inlineTokensRef.current?.getConnector?.(value);
678
- return (
679
- <InlineTokenChip
680
- icon="icon-[solar--plug-circle-linear]"
681
- iconUrl={connector?.iconUrl}
682
- label={connector?.label ?? value}
683
- title={value}
684
- />
685
- );
686
- }
687
- if (kind === "member") {
688
- const member = inlineTokensRef.current?.getMember?.(value);
689
- const handle = String(properties["data-token-handle"] ?? value);
690
- if (!member) return <>{`@${handle}`}</>;
691
- return (
692
- <InlineTokenChip
693
- iconNode={
694
- member.avatar ? (
695
- <img
696
- src={member.avatar}
697
- alt=""
698
- draggable={false}
699
- className="h-3 w-3 rounded-full object-cover"
700
- />
701
- ) : undefined
702
- }
703
- label={`@${member.label || handle}`}
704
- title={member.meta ? `${member.label || handle} · ${member.meta}` : handle}
705
- tone="member"
706
- />
707
- );
708
- }
709
- const isDirectory = properties["data-token-directory"] === "true";
710
- const fileName = basename(value);
711
- return (
712
- <InlineTokenChip
713
- asButton
714
- icon={
715
- isDirectory
716
- ? "icon-[solar--folder-linear]"
717
- : getFileIconClassRef.current(fileName)
718
- }
719
- label={fileName}
720
- title={value}
721
- onClick={() => onOpenFileRef.current(value)}
722
- />
723
- );
724
- },
725
- }),
726
- // theme 进 deps:代码块高亮主题变化时需要换组件树。其余 host 注入值走 ref。
727
- [theme],
728
- );
729
-
730
- const hasStructuredAnnotations = inlineTokens?.annotations !== undefined;
731
- const rehypePlugins = useMemo(() => {
732
- const plugins = [];
733
- if (animateChunks) plugins.push(rehypeStreamingChunks);
734
- // Exact editor/history annotations are complete. Falling back to text parsing
735
- // here would reinterpret plain text that only happens to look like a token.
736
- if (inlineTokens && !hasStructuredAnnotations) plugins.push(() => rehypeInlineTokens(inlineTokens.parse));
737
- return plugins.length > 0 ? plugins : undefined;
738
- }, [animateChunks, hasStructuredAnnotations, inlineTokens]);
739
- const markdownSource = useMemo(
740
- () => normalizeLocalFileLinksInMarkdown(displayText),
741
- [displayText],
742
- );
743
- const normalizedAnnotations = useMemo(
744
- () =>
745
- inlineTokens?.annotations
746
- ? projectAnnotationsToNormalizedMarkdown(displayText, markdownSource, inlineTokens.annotations)
747
- : undefined,
748
- [displayText, inlineTokens?.annotations, markdownSource],
749
- );
750
- const activeRemarkPlugins = useMemo(
751
- () =>
752
- normalizedAnnotations?.length
753
- ? [...remarkPlugins, () => remarkInlineTokenAnnotations(normalizedAnnotations)]
754
- : remarkPlugins,
755
- [normalizedAnnotations],
756
- );
757
-
758
- return (
759
- <div className={cn("markdown-body break-words", animateChunks && "markdown-streaming-tail", className)}>
760
- <ReactMarkdown
761
- remarkPlugins={activeRemarkPlugins}
762
- rehypePlugins={rehypePlugins}
763
- components={components}
764
- urlTransform={chatUrlTransform}
765
- >
766
- {markdownSource}
767
- </ReactMarkdown>
768
- </div>
769
- );
770
- });
1
+ /** Compatibility export for published chat consumers; implementation lives in ./markdown. */
2
+ export { MarkdownContent as TextBlockView } from "../markdown/MarkdownContent";
3
+ export type {
4
+ MarkdownContentProps as TextBlockViewProps,
5
+ MarkdownLabels as TextBlockViewLabels,
6
+ } from "../markdown/MarkdownContent";
7
+ export type { InlineTokenSupport, InlineTokenPiece, InlineTokenAnnotation } from "../markdown/inline-tokens";