@vetta-org/theme-ui 0.1.0 → 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 +735 -7
  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
@@ -0,0 +1,45 @@
1
+ import { memo, useMemo, useState } from "react";
2
+ import { MAX_PREVIEW_LENGTH, svgImageSource } from "./preview-policy";
3
+ import { useRichVisibility } from "./use-rich-visibility";
4
+ import { useRenderSnapshot } from "./use-render-snapshot";
5
+
6
+ export const SvgPreview = memo(function SvgPreview({
7
+ source,
8
+ live = false,
9
+ label,
10
+ failed,
11
+ }: {
12
+ source: string;
13
+ live?: boolean;
14
+ label: string;
15
+ failed: string;
16
+ }) {
17
+ const { ref, active } = useRichVisibility();
18
+ const snapshot = useRenderSnapshot(source, active, live, 500);
19
+ const src = useMemo(() => (active ? svgImageSource(snapshot) : null), [snapshot, active]);
20
+ const [failedSource, setFailedSource] = useState<string | null>(null);
21
+ const [size, setSize] = useState<{ width: number; height: number } | undefined>(undefined);
22
+ return (
23
+ <span ref={ref} className="inline-block max-w-full align-middle" style={!active ? size : undefined}>
24
+ {source.length > MAX_PREVIEW_LENGTH || failedSource === snapshot || (active && src === null) ? (
25
+ <span>
26
+ <span className="text-muted-foreground">{failed}</span>
27
+ <code>{source}</code>
28
+ </span>
29
+ ) : src ? (
30
+ <img
31
+ src={src}
32
+ alt={label}
33
+ className="max-h-96 max-w-full"
34
+ onError={() => setFailedSource(snapshot)}
35
+ onLoad={(event) => {
36
+ const { width, height } = event.currentTarget.getBoundingClientRect();
37
+ setSize({ width, height });
38
+ }}
39
+ />
40
+ ) : (
41
+ <span className="text-muted-foreground">{label}</span>
42
+ )}
43
+ </span>
44
+ );
45
+ });
@@ -0,0 +1,94 @@
1
+ import { useMarkdownHost } from "./host";
2
+ import { useRichVisibility } from "./use-rich-visibility";
3
+ import { memo, useEffect, useState } from "react";
4
+ import type { JSX } from "react";
5
+
6
+ const failedIcons = new Map<string, number>();
7
+ const FAILURE_TTL_MS = 5 * 60 * 1000;
8
+ const MAX_FAILED_ICONS = 128;
9
+
10
+ function faviconUrl(href: string): string | null {
11
+ try {
12
+ const url = new URL(href);
13
+ if (url.protocol !== "https:" && url.protocol !== "http:") return null;
14
+ // Only request the site's conventional icon, never the page path, query or credentials.
15
+ return `${url.origin}/favicon.ico`;
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * 图标尺寸框。favicon、兜底的通用地球图标共用同一套盒模型与垂直对齐:
23
+ * 缺省 `<span>` 是行内元素,若只有 favicon 分支带 `align-text-bottom`、兜底分支不带,
24
+ * 未取到网站图标的链接(内网、加载失败、站点未发布 favicon)会让图标比文字高几个像素。
25
+ */
26
+ const ICON_BOX_CLASS = "relative inline-block h-3.5 w-3.5 shrink-0 align-text-bottom";
27
+
28
+ function IconImage({ src }: { src: string }): JSX.Element {
29
+ const [status, setStatus] = useState<"loading" | "loaded" | "failed">(() =>
30
+ (failedIcons.get(src) ?? 0) > Date.now() ? "failed" : "loading",
31
+ );
32
+ return (
33
+ <span aria-hidden="true" className={ICON_BOX_CLASS}>
34
+ {status !== "loaded" && <span className="icon-[solar--global-linear] block h-full w-full" />}
35
+ {status !== "failed" && (
36
+ <img
37
+ src={src}
38
+ alt=""
39
+ width={14}
40
+ height={14}
41
+ loading="lazy"
42
+ decoding="async"
43
+ fetchPriority="low"
44
+ referrerPolicy="no-referrer"
45
+ draggable={false}
46
+ className={`absolute inset-0 h-full w-full object-contain ${status === "loaded" ? "opacity-100" : "opacity-0"}`}
47
+ onLoad={() => {
48
+ failedIcons.delete(src);
49
+ setStatus("loaded");
50
+ }}
51
+ onError={() => {
52
+ // Bound negative caching so virtualized history does not repeatedly retry missing icons.
53
+ failedIcons.delete(src);
54
+ failedIcons.set(src, Date.now() + FAILURE_TTL_MS);
55
+ if (failedIcons.size > MAX_FAILED_ICONS) {
56
+ const oldest = failedIcons.keys().next().value;
57
+ if (oldest !== undefined) failedIcons.delete(oldest);
58
+ }
59
+ setStatus("failed");
60
+ }}
61
+ />
62
+ )}
63
+ </span>
64
+ );
65
+ }
66
+
67
+ /** Decorative leaf shared by chat and file previews; navigation remains owned by the host. */
68
+ export const WebsiteIcon = memo(function WebsiteIcon({ href }: { href: string }): JSX.Element | null {
69
+ const fallback = faviconUrl(href);
70
+ const host = useMarkdownHost();
71
+ const { ref, active } = useRichVisibility();
72
+ const [resolved, setResolved] = useState<{ key: string; url: string | null }>();
73
+ useEffect(() => {
74
+ if (!host || !active || !fallback) return;
75
+ let cancelled = false;
76
+ void host.favicon(new URL(fallback).origin).then((url) => {
77
+ if (!cancelled) setResolved({ key: fallback, url });
78
+ }, () => { if (!cancelled) setResolved({ key: fallback, url: null }); });
79
+ return () => { cancelled = true; };
80
+ }, [host, active, fallback]);
81
+ // The host already tried /favicon.ico; do not issue a second, credentialed browser request on failure.
82
+ const src = host ? (resolved?.key === fallback ? resolved.url : null) : fallback;
83
+ return fallback ? (
84
+ <span ref={ref}>
85
+ {src ? (
86
+ <IconImage key={src} src={src} />
87
+ ) : (
88
+ <span aria-hidden="true" className={ICON_BOX_CLASS}>
89
+ <span className="icon-[solar--global-linear] block h-full w-full" />
90
+ </span>
91
+ )}
92
+ </span>
93
+ ) : null;
94
+ });
@@ -0,0 +1,43 @@
1
+ import type { MarkdownLabels } from "./rich-labels";
2
+ import { lazy, Suspense } from "react";
3
+ import { CodeBlock, DefaultCodeBlock } from "./CodeBlock";
4
+ import type { MarkdownCodeBlockProps } from "./definition";
5
+
6
+ const LazyMath = lazy(() => import("./MathFormula").then((module) => ({ default: module.MathFormula })));
7
+ const LazyRichCode = lazy(() => import("./RichCodeBlock").then((module) => ({ default: module.RichCodeBlock })));
8
+ const LazyMermaid = lazy(() => import("./MermaidBlock").then((module) => ({ default: module.MermaidBlock })));
9
+
10
+ export function Formula(props: { source: string; display: boolean; live?: boolean; labels?: MarkdownLabels }) {
11
+ return (
12
+ <Suspense fallback={<code>{props.source}</code>}>
13
+ <LazyMath {...props} />
14
+ </Suspense>
15
+ );
16
+ }
17
+
18
+ export function BuiltinCodeBlock(props: MarkdownCodeBlockProps) {
19
+ if (/^mermaid$/i.test(props.lang)) return <Suspense fallback={<DefaultCodeBlock {...props} live />}><LazyMermaid {...props} /></Suspense>;
20
+ if (/^(?:html|svg)$/i.test(props.lang)) {
21
+ return (
22
+ <Suspense fallback={<DefaultCodeBlock {...props} live />}>
23
+ <LazyRichCode {...props} />
24
+ </Suspense>
25
+ );
26
+ }
27
+ if (/^(?:math|latex|tex)$/i.test(props.lang))
28
+ return (
29
+ <CodeBlock.Root {...props}>
30
+ <CodeBlock.Copy>
31
+ <CodeBlock.Frame>
32
+ {/* 公式块没有语言栏,内边距在这里补齐,保持与表格/代码正文同一左侧光学边线。 */}
33
+ <CodeBlock.Body>
34
+ <div className="py-3 pr-4 pl-5">
35
+ <Formula source={props.code} display live={props.live} />
36
+ </div>
37
+ </CodeBlock.Body>
38
+ </CodeBlock.Frame>
39
+ </CodeBlock.Copy>
40
+ </CodeBlock.Root>
41
+ );
42
+ return <DefaultCodeBlock {...props} />;
43
+ }
@@ -0,0 +1,49 @@
1
+ import { createContext, useContext } from "react";
2
+ import type { ComponentType, ReactNode } from "react";
3
+ import type { Components, ExtraProps, Options } from "react-markdown";
4
+ import type { MarkdownLabels } from "./rich-labels";
5
+
6
+ export type MarkdownElementProps = ExtraProps & { children?: ReactNode };
7
+
8
+ export interface MarkdownCodeBlockProps {
9
+ code: string;
10
+ lang: string;
11
+ theme: "light" | "dark";
12
+ labels: MarkdownLabels;
13
+ /** 流式尾块:代码仍可能增长时跳过 Shiki,只显示等宽纯文本。 */
14
+ live?: boolean;
15
+ }
16
+
17
+ /** Definitions are immutable, local to a React subtree, and contain no host state. */
18
+ export interface MarkdownDefinition {
19
+ readonly components?: Components;
20
+ /** Custom hast elements emitted by a remark/rehype extension. */
21
+ readonly elements?: Readonly<Record<string, ComponentType<MarkdownElementProps>>>;
22
+ readonly codeBlock?: ComponentType<MarkdownCodeBlockProps>;
23
+ readonly remarkPlugins?: Options["remarkPlugins"];
24
+ readonly rehypePlugins?: Options["rehypePlugins"];
25
+ }
26
+
27
+ export const defaultMarkdown: MarkdownDefinition = Object.freeze({});
28
+
29
+ /** Renderer keys explicitly replace the base; syntax plugins run in declared order. */
30
+ export function extendMarkdown(base: MarkdownDefinition, extension: MarkdownDefinition): MarkdownDefinition {
31
+ return Object.freeze({
32
+ components: Object.freeze({ ...base.components, ...extension.components }),
33
+ elements: Object.freeze({ ...base.elements, ...extension.elements }),
34
+ codeBlock: extension.codeBlock ?? base.codeBlock,
35
+ remarkPlugins: [...(base.remarkPlugins ?? []), ...(extension.remarkPlugins ?? [])],
36
+ rehypePlugins: [...(base.rehypePlugins ?? []), ...(extension.rehypePlugins ?? [])],
37
+ });
38
+ }
39
+
40
+ const MarkdownContext = createContext(defaultMarkdown);
41
+
42
+ /** Use extendMarkdown explicitly when inheriting a parent definition. */
43
+ export function MarkdownProvider({ definition, children }: { definition: MarkdownDefinition; children: ReactNode }) {
44
+ return <MarkdownContext.Provider value={definition}>{children}</MarkdownContext.Provider>;
45
+ }
46
+
47
+ export function useMarkdownDefinition(): MarkdownDefinition {
48
+ return useContext(MarkdownContext);
49
+ }
@@ -0,0 +1,18 @@
1
+ import { createContext, useContext } from "react";
2
+ import type { ReactNode } from "react";
3
+
4
+ /** Optional host capabilities. Renderers never import Electron, IPC or application state. */
5
+ export interface MarkdownHost {
6
+ openHtml(source: string): Promise<() => void>;
7
+ renderMermaid(source: string, theme: "light" | "dark"): Promise<string>;
8
+ favicon(origin: string): Promise<string | null>;
9
+ resolveImage(source: string): Promise<string>;
10
+ copyImage(source: string): Promise<void>;
11
+ saveImage(source: string): Promise<void>;
12
+ openImage(source: string, name: string): void;
13
+ }
14
+ const MarkdownHostContext = createContext<MarkdownHost | undefined>(undefined);
15
+ export function MarkdownHostProvider({ host, children }: { host?: MarkdownHost; children: ReactNode }) {
16
+ return <MarkdownHostContext.Provider value={host}>{children}</MarkdownHostContext.Provider>;
17
+ }
18
+ export function useMarkdownHost() { return useContext(MarkdownHostContext); }
@@ -0,0 +1,11 @@
1
+ export { CodeBlock, DefaultCodeBlock } from "./CodeBlock";
2
+ export type { MarkdownCodeBlockProps, MarkdownDefinition, MarkdownElementProps } from "./definition";
3
+ export { defaultMarkdown, extendMarkdown, MarkdownProvider, useMarkdownDefinition } from "./definition";
4
+ export type { MarkdownHost } from "./host";
5
+ export { MarkdownHostProvider } from "./host";
6
+ export type { InlineTokenAnnotation, InlineTokenPiece, InlineTokenSupport } from "./inline-tokens";
7
+ export type { MarkdownContentProps, MarkdownLabels } from "./MarkdownContent";
8
+ export { MarkdownContent } from "./MarkdownContent";
9
+ export type { RichContentLabels } from "./rich-labels";
10
+ export type { StableMarkdownSplit } from "./stable-blocks";
11
+ export { splitStableMarkdownBlocks } from "./stable-blocks";
@@ -0,0 +1,187 @@
1
+ import { normalizeLocalFileLinksInMarkdown } from "./markdown-link";
2
+ import type { HastElement, HastRoot, HastText } from "./nodes";
3
+ /**
4
+ * 用户消息里的行内 token(skill 引用、文件、图片)。
5
+ * 语法归宿主所有——theme-ui 只负责渲染,解析函数由 inlineTokens.parse 注入。
6
+ */
7
+ export type InlineTokenPiece =
8
+ | { kind: "text"; text: string }
9
+ | { kind: "skill"; name: string }
10
+ | { kind: "connector"; name: string }
11
+ | { kind: "member"; participantId: string; handle: string }
12
+ | { kind: "file"; path: string; isDirectory?: boolean }
13
+ | { kind: "image"; path: string };
14
+
15
+ export interface InlineTokenSupport {
16
+ parse: (text: string) => InlineTokenPiece[];
17
+ /** Structured annotations into the original Markdown source; never inferred from display text. */
18
+ annotations?: readonly InlineTokenAnnotation[];
19
+ /**
20
+ * 图片 token 的胶囊文案(如「图 1」)。缩略图不在文本流里渲染,
21
+ * 它们集中在气泡上方并带同样的编号,因此这里只要一个标签。
22
+ */
23
+ getImageLabel: (path: string) => string;
24
+ /** 连接器的展示名与 logo;查不到时回退成真实名 + 通用图标。 */
25
+ getConnector?: (name: string) => { label: string; iconUrl?: string } | undefined;
26
+ /**
27
+ * skill 的展示名与图标。文本流里只有 slug,别名/图标要宿主回查,
28
+ * 否则气泡里的胶囊与输入框里刚插入的那枚对不上。查不到时回退成 slug + 默认图。
29
+ */
30
+ getSkill?: (name: string) => { label: string; icon?: string } | undefined;
31
+ /** Team member metadata resolved by stable participant identity. */
32
+ getMember?: (participantId: string) => { label: string; avatar?: string; meta?: string } | undefined;
33
+ }
34
+
35
+ interface InlineTokenAnnotationRange {
36
+ /** Exact serialized token text, used to reject stale or mismatched offsets. */
37
+ readonly text: string;
38
+ /** UTF-16 offsets into the original Markdown source. */
39
+ readonly start: number;
40
+ readonly end: number;
41
+ }
42
+
43
+ export type InlineTokenAnnotation =
44
+ | ({ readonly kind: "skill" | "connector"; readonly name: string } & InlineTokenAnnotationRange)
45
+ | ({
46
+ readonly kind: "file" | "image";
47
+ readonly path: string;
48
+ readonly isDirectory?: boolean;
49
+ } & InlineTokenAnnotationRange)
50
+ | ({
51
+ readonly kind: "member";
52
+ readonly participantId: string;
53
+ readonly handle: string;
54
+ } & InlineTokenAnnotationRange);
55
+
56
+ export const INLINE_TOKEN_TAG = "vetta-inline-token";
57
+
58
+ /** 把文本节点里的 token 换成自定义元素;代码块与链接文本内不处理。 */
59
+ export function rehypeInlineTokens(parse: (text: string) => InlineTokenPiece[]) {
60
+ return (tree: HastRoot): void => {
61
+ function visit(node: HastRoot | HastElement, inLiteral: boolean): void {
62
+ const newChildren: Array<(typeof node.children)[number]> = [];
63
+ for (const child of node.children) {
64
+ if (child.type === "text" && !inLiteral) {
65
+ const pieces = parse((child as HastText).value);
66
+ if (pieces.length === 1 && pieces[0].kind === "text") {
67
+ newChildren.push(child);
68
+ continue;
69
+ }
70
+ for (const piece of pieces) {
71
+ if (piece.kind === "text") {
72
+ newChildren.push({ type: "text", value: piece.text } as HastText);
73
+ continue;
74
+ }
75
+ newChildren.push({
76
+ type: "element",
77
+ tagName: INLINE_TOKEN_TAG,
78
+ properties: {
79
+ "data-token-kind": piece.kind,
80
+ "data-token-value":
81
+ piece.kind === "skill" || piece.kind === "connector"
82
+ ? piece.name
83
+ : piece.kind === "member"
84
+ ? piece.participantId
85
+ : piece.path,
86
+ "data-token-directory": piece.kind === "file" && piece.isDirectory ? "true" : "false",
87
+ },
88
+ children: [],
89
+ });
90
+ }
91
+ continue;
92
+ }
93
+ newChildren.push(child);
94
+ if (child.type === "element") {
95
+ const tag = child.tagName;
96
+ visit(child, inLiteral || tag === "code" || tag === "pre" || tag === "a");
97
+ }
98
+ }
99
+ node.children = newChildren as typeof node.children;
100
+ }
101
+
102
+ visit(tree, false);
103
+ };
104
+ }
105
+
106
+ interface MdastNode {
107
+ type: string;
108
+ value?: string;
109
+ children?: MdastNode[];
110
+ position?: { start?: { offset?: number }; end?: { offset?: number } };
111
+ data?: { hName?: string; hProperties?: Record<string, unknown> };
112
+ }
113
+
114
+ export function remarkInlineTokenAnnotations(annotations: readonly InlineTokenAnnotation[]) {
115
+ const ordered = [...annotations].sort((left, right) => left.start - right.start || left.end - right.end);
116
+ return (tree: MdastNode): void => {
117
+ function visit(node: MdastNode, inLiteral: boolean): void {
118
+ if (!node.children) return;
119
+ const nextChildren: MdastNode[] = [];
120
+ for (const child of node.children) {
121
+ const literal = inLiteral || child.type === "code" || child.type === "inlineCode" || child.type === "link";
122
+ const nodeStart = child.position?.start?.offset;
123
+ const nodeEnd = child.position?.end?.offset;
124
+ if (child.type !== "text" || literal || nodeStart === undefined || nodeEnd === undefined) {
125
+ nextChildren.push(child);
126
+ visit(child, literal);
127
+ continue;
128
+ }
129
+ const value = child.value ?? "";
130
+ const contained = ordered.filter(
131
+ (annotation) => annotation.start >= nodeStart && annotation.end <= nodeEnd,
132
+ );
133
+ if (contained.length === 0) {
134
+ nextChildren.push(child);
135
+ continue;
136
+ }
137
+ let cursor = 0;
138
+ for (const annotation of contained) {
139
+ const start = annotation.start - nodeStart;
140
+ const end = annotation.end - nodeStart;
141
+ if (start < cursor || end <= start || value.slice(start, end) !== annotation.text) continue;
142
+ if (annotation.kind === "member" && annotation.text !== `@${annotation.handle}`) continue;
143
+ if (start > cursor) nextChildren.push({ type: "text", value: value.slice(cursor, start) });
144
+ const tokenValue =
145
+ "name" in annotation
146
+ ? annotation.name
147
+ : "participantId" in annotation
148
+ ? annotation.participantId
149
+ : annotation.path;
150
+ nextChildren.push({
151
+ type: "inlineToken",
152
+ data: {
153
+ hName: INLINE_TOKEN_TAG,
154
+ hProperties: {
155
+ "data-token-kind": annotation.kind,
156
+ "data-token-value": tokenValue,
157
+ ...(annotation.kind === "member" ? { "data-token-handle": annotation.handle } : {}),
158
+ ...(annotation.kind === "file"
159
+ ? { "data-token-directory": annotation.isDirectory ? "true" : "false" }
160
+ : {}),
161
+ },
162
+ },
163
+ });
164
+ cursor = end;
165
+ }
166
+ if (cursor < value.length) nextChildren.push({ type: "text", value: value.slice(cursor) });
167
+ }
168
+ node.children = nextChildren;
169
+ }
170
+
171
+ visit(tree, false);
172
+ };
173
+ }
174
+
175
+ export function projectAnnotationsToNormalizedMarkdown(
176
+ source: string,
177
+ normalizedSource: string,
178
+ annotations: readonly InlineTokenAnnotation[],
179
+ ): InlineTokenAnnotation[] {
180
+ if (source === normalizedSource) return [...annotations];
181
+ return annotations.flatMap((annotation): InlineTokenAnnotation[] => {
182
+ if (source.slice(annotation.start, annotation.end) !== annotation.text) return [];
183
+ const start = normalizeLocalFileLinksInMarkdown(source.slice(0, annotation.start)).length;
184
+ const end = normalizeLocalFileLinksInMarkdown(source.slice(0, annotation.end)).length;
185
+ return normalizedSource.slice(start, end) === annotation.text ? [{ ...annotation, start, end }] : [];
186
+ });
187
+ }