bingocode 1.0.2 → 1.0.3
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.
- package/desktop/README.md +30 -0
- package/desktop/bunfig.toml +1 -0
- package/desktop/index.html +17 -0
- package/desktop/package.json +55 -0
- package/desktop/pnpm-lock.yaml +3832 -0
- package/desktop/public/app-icon.jpg +0 -0
- package/desktop/public/fonts/inter-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/inter-latin.woff2 +0 -0
- package/desktop/public/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/desktop/public/fonts/manrope-latin-ext.woff2 +0 -0
- package/desktop/public/fonts/manrope-latin.woff2 +0 -0
- package/desktop/public/fonts/material-symbols-outlined.woff2 +0 -0
- package/desktop/public/icons/bilibili.svg +1 -0
- package/desktop/public/icons/douyin.svg +1 -0
- package/desktop/public/icons/github.svg +3 -0
- package/desktop/public/icons/xiaohongshu.svg +1 -0
- package/desktop/scripts/build-macos-arm64.sh +270 -0
- package/desktop/scripts/build-sidecars.ts +183 -0
- package/desktop/scripts/build-windows-x64.ps1 +295 -0
- package/desktop/scripts/scan-missing-imports.ts +235 -0
- package/desktop/sidecars/claude-sidecar.ts +156 -0
- package/desktop/src/App.tsx +5 -0
- package/desktop/src/__tests__/agentsSettings.test.tsx +349 -0
- package/desktop/src/__tests__/pages.test.tsx +290 -0
- package/desktop/src/__tests__/skillsSettings.test.tsx +205 -0
- package/desktop/src/api/adapters.ts +12 -0
- package/desktop/src/api/agents.ts +36 -0
- package/desktop/src/api/cliTasks.ts +28 -0
- package/desktop/src/api/client.ts +63 -0
- package/desktop/src/api/computerUse.ts +76 -0
- package/desktop/src/api/filesystem.ts +30 -0
- package/desktop/src/api/hahaOAuth.ts +38 -0
- package/desktop/src/api/models.ts +28 -0
- package/desktop/src/api/providers.ts +63 -0
- package/desktop/src/api/search.ts +29 -0
- package/desktop/src/api/sessions.ts +56 -0
- package/desktop/src/api/settings.ts +20 -0
- package/desktop/src/api/skills.ts +19 -0
- package/desktop/src/api/tasks.ts +36 -0
- package/desktop/src/api/teams.ts +44 -0
- package/desktop/src/api/websocket.ts +164 -0
- package/desktop/src/components/chat/AskUserQuestion.tsx +268 -0
- package/desktop/src/components/chat/AssistantMessage.tsx +29 -0
- package/desktop/src/components/chat/AttachmentGallery.tsx +113 -0
- package/desktop/src/components/chat/ChatInput.tsx +622 -0
- package/desktop/src/components/chat/CodeViewer.tsx +161 -0
- package/desktop/src/components/chat/ComputerUsePermissionModal.test.tsx +174 -0
- package/desktop/src/components/chat/ComputerUsePermissionModal.tsx +311 -0
- package/desktop/src/components/chat/DiffViewer.tsx +157 -0
- package/desktop/src/components/chat/FileSearchMenu.tsx +198 -0
- package/desktop/src/components/chat/ImageGalleryModal.tsx +91 -0
- package/desktop/src/components/chat/InlineImageGallery.tsx +106 -0
- package/desktop/src/components/chat/InlineTaskSummary.tsx +60 -0
- package/desktop/src/components/chat/MermaidRenderer.test.tsx +98 -0
- package/desktop/src/components/chat/MermaidRenderer.tsx +361 -0
- package/desktop/src/components/chat/MessageActionBar.tsx +27 -0
- package/desktop/src/components/chat/MessageList.test.tsx +313 -0
- package/desktop/src/components/chat/MessageList.tsx +249 -0
- package/desktop/src/components/chat/PermissionDialog.tsx +262 -0
- package/desktop/src/components/chat/SessionTaskBar.test.tsx +99 -0
- package/desktop/src/components/chat/SessionTaskBar.tsx +159 -0
- package/desktop/src/components/chat/StreamingIndicator.tsx +41 -0
- package/desktop/src/components/chat/TerminalChrome.tsx +35 -0
- package/desktop/src/components/chat/ThinkingBlock.tsx +87 -0
- package/desktop/src/components/chat/ToolCallBlock.tsx +247 -0
- package/desktop/src/components/chat/ToolCallGroup.tsx +617 -0
- package/desktop/src/components/chat/ToolResultBlock.tsx +107 -0
- package/desktop/src/components/chat/UserMessage.tsx +38 -0
- package/desktop/src/components/chat/chatBlocks.test.tsx +136 -0
- package/desktop/src/components/chat/clipboard.ts +25 -0
- package/desktop/src/components/chat/composerUtils.test.ts +55 -0
- package/desktop/src/components/chat/composerUtils.ts +149 -0
- package/desktop/src/components/controls/ModelSelector.tsx +156 -0
- package/desktop/src/components/controls/PermissionModeSelector.tsx +229 -0
- package/desktop/src/components/layout/AppShell.tsx +107 -0
- package/desktop/src/components/layout/ContentRouter.tsx +27 -0
- package/desktop/src/components/layout/ProjectFilter.tsx +126 -0
- package/desktop/src/components/layout/Sidebar.test.tsx +158 -0
- package/desktop/src/components/layout/Sidebar.tsx +384 -0
- package/desktop/src/components/layout/StatusBar.tsx +31 -0
- package/desktop/src/components/layout/TabBar.test.tsx +136 -0
- package/desktop/src/components/layout/TabBar.tsx +318 -0
- package/desktop/src/components/layout/TitleBar.tsx +96 -0
- package/desktop/src/components/layout/WindowControls.test.tsx +69 -0
- package/desktop/src/components/layout/WindowControls.tsx +89 -0
- package/desktop/src/components/markdown/MarkdownRenderer.test.tsx +100 -0
- package/desktop/src/components/markdown/MarkdownRenderer.tsx +229 -0
- package/desktop/src/components/settings/ClaudeOfficialLogin.tsx +107 -0
- package/desktop/src/components/shared/Button.tsx +63 -0
- package/desktop/src/components/shared/CopyButton.tsx +58 -0
- package/desktop/src/components/shared/DirectoryPicker.tsx +316 -0
- package/desktop/src/components/shared/Dropdown.tsx +91 -0
- package/desktop/src/components/shared/Input.tsx +38 -0
- package/desktop/src/components/shared/Modal.tsx +65 -0
- package/desktop/src/components/shared/ProjectContextChip.tsx +30 -0
- package/desktop/src/components/shared/Spinner.tsx +30 -0
- package/desktop/src/components/shared/Textarea.tsx +38 -0
- package/desktop/src/components/shared/Toast.tsx +47 -0
- package/desktop/src/components/shared/UpdateChecker.tsx +90 -0
- package/desktop/src/components/skills/SkillDetail.test.tsx +89 -0
- package/desktop/src/components/skills/SkillDetail.tsx +403 -0
- package/desktop/src/components/skills/SkillList.tsx +254 -0
- package/desktop/src/components/tasks/DayOfWeekPicker.tsx +57 -0
- package/desktop/src/components/tasks/NewTaskModal.tsx +407 -0
- package/desktop/src/components/tasks/PromptEditor.tsx +74 -0
- package/desktop/src/components/tasks/TaskEmptyState.tsx +30 -0
- package/desktop/src/components/tasks/TaskList.tsx +46 -0
- package/desktop/src/components/tasks/TaskRow.tsx +253 -0
- package/desktop/src/components/tasks/TaskRunsPanel.tsx +195 -0
- package/desktop/src/components/teams/TeamStatusBar.tsx +147 -0
- package/desktop/src/config/providerPresets.ts +78 -0
- package/desktop/src/config/spinnerVerbs.ts +193 -0
- package/desktop/src/hooks/useKeyboardShortcuts.ts +60 -0
- package/desktop/src/i18n/index.ts +54 -0
- package/desktop/src/i18n/locales/en.ts +670 -0
- package/desktop/src/i18n/locales/zh.ts +670 -0
- package/desktop/src/lib/__tests__/cronDescribe.test.ts +93 -0
- package/desktop/src/lib/cronDescribe.ts +188 -0
- package/desktop/src/lib/desktopRuntime.ts +54 -0
- package/desktop/src/lib/parseRunOutput.ts +79 -0
- package/desktop/src/main.tsx +13 -0
- package/desktop/src/mocks/data.ts +202 -0
- package/desktop/src/pages/ActiveSession.test.tsx +181 -0
- package/desktop/src/pages/ActiveSession.tsx +219 -0
- package/desktop/src/pages/AdapterSettings.tsx +375 -0
- package/desktop/src/pages/AgentTeams.tsx +200 -0
- package/desktop/src/pages/ComputerUseSettings.tsx +420 -0
- package/desktop/src/pages/EmptySession.tsx +518 -0
- package/desktop/src/pages/NewTaskModal.tsx +346 -0
- package/desktop/src/pages/ScheduledTasks.tsx +66 -0
- package/desktop/src/pages/ScheduledTasksEmpty.tsx +152 -0
- package/desktop/src/pages/ScheduledTasksList.tsx +416 -0
- package/desktop/src/pages/SessionControls.tsx +460 -0
- package/desktop/src/pages/Settings.tsx +1448 -0
- package/desktop/src/pages/ToolInspection.tsx +235 -0
- package/desktop/src/stores/adapterStore.ts +106 -0
- package/desktop/src/stores/agentStore.ts +34 -0
- package/desktop/src/stores/chatStore.test.ts +505 -0
- package/desktop/src/stores/chatStore.ts +850 -0
- package/desktop/src/stores/cliTaskStore.ts +152 -0
- package/desktop/src/stores/hahaOAuthStore.test.ts +77 -0
- package/desktop/src/stores/hahaOAuthStore.ts +97 -0
- package/desktop/src/stores/providerStore.ts +101 -0
- package/desktop/src/stores/sessionStore.test.ts +63 -0
- package/desktop/src/stores/sessionStore.ts +102 -0
- package/desktop/src/stores/settingsStore.ts +120 -0
- package/desktop/src/stores/skillStore.ts +51 -0
- package/desktop/src/stores/tabStore.ts +169 -0
- package/desktop/src/stores/taskStore.ts +68 -0
- package/desktop/src/stores/teamStore.ts +344 -0
- package/desktop/src/stores/uiStore.ts +100 -0
- package/desktop/src/stores/updateStore.test.ts +71 -0
- package/desktop/src/stores/updateStore.ts +221 -0
- package/desktop/src/theme/globals.css +465 -0
- package/desktop/src/types/adapter.ts +33 -0
- package/desktop/src/types/chat.ts +152 -0
- package/desktop/src/types/cliTask.ts +24 -0
- package/desktop/src/types/provider.ts +62 -0
- package/desktop/src/types/session.ts +27 -0
- package/desktop/src/types/settings.ts +22 -0
- package/desktop/src/types/skill.ts +38 -0
- package/desktop/src/types/task.ts +56 -0
- package/desktop/src/types/team.ts +38 -0
- package/desktop/src-tauri/Cargo.lock +5549 -0
- package/desktop/src-tauri/Cargo.toml +20 -0
- package/desktop/src-tauri/app-icon.svg +13 -0
- package/desktop/src-tauri/build.rs +3 -0
- package/desktop/src-tauri/capabilities/default.json +106 -0
- package/desktop/src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml +5 -0
- package/desktop/src-tauri/icons/android/values/ic_launcher_background.xml +4 -0
- package/desktop/src-tauri/icons/icon.icns +0 -0
- package/desktop/src-tauri/icons/icon.ico +0 -0
- package/desktop/src-tauri/src/lib.rs +408 -0
- package/desktop/src-tauri/src/main.rs +6 -0
- package/desktop/src-tauri/tauri.conf.json +78 -0
- package/desktop/src-tauri/tauri.macos.conf.json +18 -0
- package/desktop/src-tauri/tauri.release-ci.json +5 -0
- package/desktop/src-tauri/tauri.windows.conf.json +16 -0
- package/desktop/src-tauri/windows-installer-hooks.nsh +17 -0
- package/desktop/tsconfig.json +25 -0
- package/desktop/vite.config.ts +26 -0
- package/desktop/vitest.config.ts +18 -0
- package/package.json +1 -1
- package/src/commands/desktop/desktop.tsx +9 -0
- package/src/commands/desktop/index.ts +26 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { useMemo, useCallback } from 'react'
|
|
2
|
+
import DOMPurify from 'dompurify'
|
|
3
|
+
import { marked, type Tokens } from 'marked'
|
|
4
|
+
import { CodeViewer } from '../chat/CodeViewer'
|
|
5
|
+
import { MermaidRenderer } from '../chat/MermaidRenderer'
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
content: string
|
|
9
|
+
variant?: 'default' | 'document'
|
|
10
|
+
className?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type CodeBlock = {
|
|
14
|
+
id: string
|
|
15
|
+
code: string
|
|
16
|
+
language: string | undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MERMAID_LANGUAGE = 'mermaid'
|
|
20
|
+
const PLAINTEXT_LANGUAGES = new Set(['', 'text', 'plaintext', 'plain'])
|
|
21
|
+
const MERMAID_DIAGRAM_START = /^(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|gitGraph|mindmap|timeline|requirementDiagram|quadrantChart|xychart-beta|sankey-beta|block-beta|packet-beta|architecture|kanban)\b/i
|
|
22
|
+
|
|
23
|
+
function normalizeCodeLanguage(language: string | undefined): string | undefined {
|
|
24
|
+
const normalized = language?.trim().split(/\s+/)[0]?.toLowerCase()
|
|
25
|
+
return normalized || undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function looksLikeMermaid(code: string): boolean {
|
|
29
|
+
const firstMeaningfulLine = code
|
|
30
|
+
.split('\n')
|
|
31
|
+
.map((line) => line.trim())
|
|
32
|
+
.find(Boolean)
|
|
33
|
+
|
|
34
|
+
return firstMeaningfulLine ? MERMAID_DIAGRAM_START.test(firstMeaningfulLine) : false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function shouldRenderAsMermaid(block: CodeBlock): boolean {
|
|
38
|
+
const normalizedLanguage = normalizeCodeLanguage(block.language)
|
|
39
|
+
|
|
40
|
+
if (normalizedLanguage === MERMAID_LANGUAGE) {
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!PLAINTEXT_LANGUAGES.has(normalizedLanguage ?? '')) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return looksLikeMermaid(block.code)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const renderer = new marked.Renderer()
|
|
52
|
+
|
|
53
|
+
let pendingCodeBlocks: CodeBlock[] = []
|
|
54
|
+
|
|
55
|
+
renderer.code = function ({ text, lang }: Tokens.Code) {
|
|
56
|
+
const id = `cb-${pendingCodeBlocks.length}`
|
|
57
|
+
pendingCodeBlocks.push({
|
|
58
|
+
id,
|
|
59
|
+
code: text,
|
|
60
|
+
language: normalizeCodeLanguage(lang || undefined),
|
|
61
|
+
})
|
|
62
|
+
return `<div data-codeblock-id="${id}"></div>`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
marked.setOptions({
|
|
66
|
+
breaks: true,
|
|
67
|
+
gfm: true,
|
|
68
|
+
})
|
|
69
|
+
marked.use({ renderer })
|
|
70
|
+
|
|
71
|
+
function enhanceMarkdownHtml(html: string): string {
|
|
72
|
+
const cleanHtml = DOMPurify.sanitize(html, {
|
|
73
|
+
ADD_TAGS: ['use'],
|
|
74
|
+
ADD_ATTR: ['xlink:href'],
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (typeof document === 'undefined') {
|
|
78
|
+
return cleanHtml
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const container = document.createElement('div')
|
|
82
|
+
container.innerHTML = cleanHtml
|
|
83
|
+
|
|
84
|
+
container.querySelectorAll('table').forEach((table) => {
|
|
85
|
+
if (table.parentElement?.classList.contains('md-table-wrap')) return
|
|
86
|
+
const wrapper = document.createElement('div')
|
|
87
|
+
wrapper.className = 'md-table-wrap'
|
|
88
|
+
table.parentNode?.insertBefore(wrapper, table)
|
|
89
|
+
wrapper.appendChild(table)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
container.querySelectorAll('a[href]').forEach((link) => {
|
|
93
|
+
link.setAttribute('target', '_blank')
|
|
94
|
+
link.setAttribute('rel', 'noreferrer noopener')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
return container.innerHTML
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function parseMarkdown(content: string): { html: string; codeBlocks: CodeBlock[] } {
|
|
101
|
+
pendingCodeBlocks = []
|
|
102
|
+
const html = marked.parse(content) as string
|
|
103
|
+
const codeBlocks = [...pendingCodeBlocks]
|
|
104
|
+
pendingCodeBlocks = []
|
|
105
|
+
return { html, codeBlocks }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const BASE_PROSE_CLASSES = `markdown-prose prose prose-sm max-w-none text-[var(--color-text-primary)]
|
|
109
|
+
prose-headings:text-[var(--color-text-primary)] prose-headings:font-semibold
|
|
110
|
+
prose-p:my-2 prose-p:leading-relaxed
|
|
111
|
+
prose-p:break-words
|
|
112
|
+
prose-code:text-[13px] prose-code:text-[var(--color-primary-fixed)] prose-code:font-[var(--font-mono)] prose-code:bg-[var(--color-surface-container-high)] prose-code:border prose-code:border-[var(--color-border)] prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded-md prose-code:before:hidden prose-code:after:hidden
|
|
113
|
+
prose-pre:!bg-transparent prose-pre:!p-0 prose-pre:!shadow-none
|
|
114
|
+
prose-a:text-[var(--color-text-accent)] prose-a:no-underline hover:prose-a:underline
|
|
115
|
+
prose-strong:text-[var(--color-text-primary)]
|
|
116
|
+
prose-ul:my-2 prose-ol:my-2
|
|
117
|
+
prose-li:my-0.5
|
|
118
|
+
prose-table:my-0 prose-table:w-full prose-table:table-auto prose-table:text-sm
|
|
119
|
+
prose-th:bg-[var(--color-surface-info)] prose-th:px-3 prose-th:py-2 prose-th:text-left prose-th:whitespace-normal prose-th:break-words prose-th:align-top prose-th:border-b prose-th:border-[var(--color-border)]
|
|
120
|
+
prose-td:px-3 prose-td:py-2 prose-td:border-b prose-td:border-[var(--color-border)] prose-td:whitespace-normal prose-td:break-words prose-td:align-top prose-td:bg-[var(--color-surface)]
|
|
121
|
+
[&_.md-table-wrap]:my-5 [&_.md-table-wrap]:overflow-x-auto [&_.md-table-wrap]:rounded-xl [&_.md-table-wrap]:border [&_.md-table-wrap]:border-[var(--color-border)] [&_.md-table-wrap]:bg-[var(--color-surface-container-lowest)]`
|
|
122
|
+
|
|
123
|
+
const DOCUMENT_PROSE_CLASSES = `
|
|
124
|
+
prose-p:text-[15px] prose-p:leading-7
|
|
125
|
+
prose-headings:scroll-mt-6 prose-headings:tracking-[-0.01em]
|
|
126
|
+
prose-h1:mb-4 prose-h1:text-2xl prose-h1:font-semibold prose-h1:leading-tight
|
|
127
|
+
prose-h2:mt-8 prose-h2:mb-3 prose-h2:border-b prose-h2:border-[var(--color-border)] prose-h2:pb-2 prose-h2:text-xl prose-h2:font-semibold
|
|
128
|
+
prose-h3:mt-6 prose-h3:mb-2 prose-h3:text-base prose-h3:font-semibold
|
|
129
|
+
prose-h4:mt-5 prose-h4:mb-2 prose-h4:text-sm prose-h4:font-semibold
|
|
130
|
+
prose-blockquote:my-4 prose-blockquote:rounded-r-lg prose-blockquote:border-l-4 prose-blockquote:border-[var(--color-outline-variant)] prose-blockquote:bg-[var(--color-surface-container-low)] prose-blockquote:px-4 prose-blockquote:py-2 prose-blockquote:italic
|
|
131
|
+
prose-hr:my-6 prose-hr:border-[var(--color-border)]
|
|
132
|
+
prose-img:rounded-lg prose-img:border prose-img:border-[var(--color-border)]
|
|
133
|
+
prose-kbd:rounded prose-kbd:border prose-kbd:border-[var(--color-border)] prose-kbd:bg-[var(--color-surface-container-lowest)] prose-kbd:px-1.5 prose-kbd:py-0.5 prose-kbd:font-[var(--font-mono)] prose-kbd:text-[12px] prose-kbd:font-normal prose-kbd:text-[var(--color-text-secondary)] prose-kbd:shadow-none
|
|
134
|
+
prose-ul:pl-5 prose-ul:[&>li]:marker:text-[var(--color-text-tertiary)]
|
|
135
|
+
prose-ol:pl-5 prose-ol:[&>li]:marker:text-[var(--color-text-tertiary)]
|
|
136
|
+
prose-li:my-1.5
|
|
137
|
+
prose-table:my-0`
|
|
138
|
+
|
|
139
|
+
function getProseClasses(variant: 'default' | 'document', className?: string) {
|
|
140
|
+
return [BASE_PROSE_CLASSES, variant === 'document' ? DOCUMENT_PROSE_CLASSES : '', className ?? '']
|
|
141
|
+
.filter(Boolean)
|
|
142
|
+
.join(' ')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function MarkdownRenderer({ content, variant = 'default', className }: Props) {
|
|
146
|
+
const { html, codeBlocks } = useMemo(() => parseMarkdown(content), [content])
|
|
147
|
+
const proseClasses = useMemo(
|
|
148
|
+
() => getProseClasses(variant, className),
|
|
149
|
+
[variant, className],
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
const parts = useMemo(() => {
|
|
153
|
+
if (codeBlocks.length === 0) {
|
|
154
|
+
return [{ type: 'html' as const, content: html }]
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const result: Array<{ type: 'html'; content: string } | { type: 'code'; block: CodeBlock }> = []
|
|
158
|
+
let remaining = html
|
|
159
|
+
|
|
160
|
+
for (const block of codeBlocks) {
|
|
161
|
+
const marker = `<div data-codeblock-id="${block.id}"></div>`
|
|
162
|
+
const idx = remaining.indexOf(marker)
|
|
163
|
+
if (idx === -1) continue
|
|
164
|
+
|
|
165
|
+
const before = remaining.slice(0, idx)
|
|
166
|
+
if (before) {
|
|
167
|
+
result.push({ type: 'html', content: before })
|
|
168
|
+
}
|
|
169
|
+
result.push({ type: 'code', block })
|
|
170
|
+
remaining = remaining.slice(idx + marker.length)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (remaining) {
|
|
174
|
+
result.push({ type: 'html', content: remaining })
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return result
|
|
178
|
+
}, [html, codeBlocks])
|
|
179
|
+
|
|
180
|
+
const handleClick = useCallback(async (event: React.MouseEvent<HTMLDivElement>) => {
|
|
181
|
+
const target = event.target as HTMLElement | null
|
|
182
|
+
const button = target?.closest<HTMLButtonElement>('[data-copy-code]')
|
|
183
|
+
if (!button) return
|
|
184
|
+
|
|
185
|
+
const text = button.getAttribute('data-copy-code')
|
|
186
|
+
if (!text) return
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await navigator.clipboard.writeText(text)
|
|
190
|
+
const original = button.textContent
|
|
191
|
+
button.textContent = 'Copied'
|
|
192
|
+
window.setTimeout(() => {
|
|
193
|
+
button.textContent = original
|
|
194
|
+
}, 1500)
|
|
195
|
+
} catch {
|
|
196
|
+
// Ignore clipboard errors
|
|
197
|
+
}
|
|
198
|
+
}, [])
|
|
199
|
+
|
|
200
|
+
if (codeBlocks.length === 0) {
|
|
201
|
+
const cleanHtml = enhanceMarkdownHtml(html)
|
|
202
|
+
return (
|
|
203
|
+
<div
|
|
204
|
+
className={proseClasses}
|
|
205
|
+
dangerouslySetInnerHTML={{ __html: cleanHtml }}
|
|
206
|
+
onClick={handleClick}
|
|
207
|
+
/>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<div className={proseClasses} onClick={handleClick}>
|
|
213
|
+
{parts.map((part, i) =>
|
|
214
|
+
part.type === 'html' ? (
|
|
215
|
+
<div key={i} dangerouslySetInnerHTML={{ __html: enhanceMarkdownHtml(part.content) }} />
|
|
216
|
+
) : shouldRenderAsMermaid(part.block) ? (
|
|
217
|
+
<MermaidRenderer key={part.block.id} code={part.block.code} />
|
|
218
|
+
) : (
|
|
219
|
+
<div key={part.block.id} className="my-4">
|
|
220
|
+
<CodeViewer
|
|
221
|
+
code={part.block.code}
|
|
222
|
+
language={part.block.language}
|
|
223
|
+
/>
|
|
224
|
+
</div>
|
|
225
|
+
)
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// desktop/src/components/settings/ClaudeOfficialLogin.tsx
|
|
2
|
+
//
|
|
3
|
+
// 显示当前 Claude Official OAuth 登录状态,提供 Login / Logout 按钮。
|
|
4
|
+
// 点击 Login 调 Tauri shell.open 打开浏览器走 OAuth flow;浏览器回 callback
|
|
5
|
+
// 到 haha server 后,store 的 polling 自动刷新 UI 展示"已登录"。
|
|
6
|
+
|
|
7
|
+
import { useEffect } from 'react'
|
|
8
|
+
import { open as shellOpen } from '@tauri-apps/plugin-shell'
|
|
9
|
+
import { useHahaOAuthStore } from '../../stores/hahaOAuthStore'
|
|
10
|
+
import { useTranslation } from '../../i18n'
|
|
11
|
+
|
|
12
|
+
export function ClaudeOfficialLogin() {
|
|
13
|
+
const t = useTranslation()
|
|
14
|
+
const {
|
|
15
|
+
status,
|
|
16
|
+
isLoading,
|
|
17
|
+
error,
|
|
18
|
+
fetchStatus,
|
|
19
|
+
login,
|
|
20
|
+
logout,
|
|
21
|
+
startPolling,
|
|
22
|
+
stopPolling,
|
|
23
|
+
} = useHahaOAuthStore()
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
fetchStatus()
|
|
27
|
+
return () => stopPolling()
|
|
28
|
+
}, [fetchStatus, stopPolling])
|
|
29
|
+
|
|
30
|
+
const handleLogin = async () => {
|
|
31
|
+
try {
|
|
32
|
+
const { authorizeUrl } = await login()
|
|
33
|
+
try {
|
|
34
|
+
await shellOpen(authorizeUrl)
|
|
35
|
+
startPolling()
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error('[ClaudeOfficialLogin] shellOpen failed:', err)
|
|
38
|
+
useHahaOAuthStore.setState({
|
|
39
|
+
error: t('settings.claudeOfficialLogin.openBrowserFailed'),
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
// store.login() errors are already captured into store.error
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (status === null) {
|
|
48
|
+
if (error) {
|
|
49
|
+
return (
|
|
50
|
+
<div className="text-xs text-[var(--color-error)]">
|
|
51
|
+
{t('settings.claudeOfficialLogin.errorPrefix')}{error}
|
|
52
|
+
</div>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<div className="text-xs text-[var(--color-text-tertiary)]">
|
|
57
|
+
{t('common.loading')}
|
|
58
|
+
</div>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (status.loggedIn) {
|
|
63
|
+
const subTypeLabel = status.subscriptionType
|
|
64
|
+
? status.subscriptionType.toUpperCase()
|
|
65
|
+
: t('settings.claudeOfficialLogin.subTypeUnknown')
|
|
66
|
+
return (
|
|
67
|
+
<div className="flex items-center gap-3 text-sm">
|
|
68
|
+
<span className="text-[var(--color-success)]">
|
|
69
|
+
✓ {t('settings.claudeOfficialLogin.loggedInPrefix')} {subTypeLabel})
|
|
70
|
+
</span>
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
onClick={logout}
|
|
74
|
+
disabled={isLoading}
|
|
75
|
+
className="px-3 py-1 text-xs rounded-md border border-[var(--color-border-separator)] bg-[var(--color-surface)] hover:bg-[var(--color-surface-hover)] disabled:opacity-50 transition-colors"
|
|
76
|
+
>
|
|
77
|
+
{isLoading
|
|
78
|
+
? t('settings.claudeOfficialLogin.logoutProcessing')
|
|
79
|
+
: t('settings.claudeOfficialLogin.logoutButton')}
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div className="flex flex-col gap-2">
|
|
87
|
+
<div className="text-sm text-[var(--color-text-secondary)]">
|
|
88
|
+
{t('settings.claudeOfficialLogin.intro')}
|
|
89
|
+
</div>
|
|
90
|
+
<button
|
|
91
|
+
type="button"
|
|
92
|
+
onClick={handleLogin}
|
|
93
|
+
disabled={isLoading}
|
|
94
|
+
className="self-start rounded-md bg-[image:var(--gradient-btn-primary)] px-4 py-2 text-sm text-[var(--color-btn-primary-fg)] shadow-[var(--shadow-button-primary)] hover:brightness-105 disabled:opacity-50 transition-opacity"
|
|
95
|
+
>
|
|
96
|
+
{isLoading
|
|
97
|
+
? t('settings.claudeOfficialLogin.loginStarting')
|
|
98
|
+
: t('settings.claudeOfficialLogin.loginButton')}
|
|
99
|
+
</button>
|
|
100
|
+
{error && (
|
|
101
|
+
<div className="text-xs text-[var(--color-error)]">
|
|
102
|
+
{t('settings.claudeOfficialLogin.errorPrefix')}{error}
|
|
103
|
+
</div>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'ghost'
|
|
4
|
+
|
|
5
|
+
type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
6
|
+
variant?: ButtonVariant
|
|
7
|
+
size?: 'sm' | 'md' | 'lg'
|
|
8
|
+
loading?: boolean
|
|
9
|
+
icon?: ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const variantStyles: Record<ButtonVariant, string> = {
|
|
13
|
+
primary:
|
|
14
|
+
'bg-[image:var(--gradient-btn-primary)] text-[var(--color-btn-primary-fg)] shadow-[var(--shadow-button-primary)] hover:bg-[image:var(--gradient-btn-primary-hover)] hover:brightness-105 active:translate-y-[1px]',
|
|
15
|
+
secondary:
|
|
16
|
+
'bg-[var(--color-surface)] text-[var(--color-text-primary)] border border-[var(--color-border)] hover:bg-[var(--color-surface-hover)]',
|
|
17
|
+
danger:
|
|
18
|
+
'bg-[var(--color-error)] text-white hover:opacity-90',
|
|
19
|
+
ghost:
|
|
20
|
+
'bg-transparent text-[var(--color-text-secondary)] hover:bg-[var(--color-surface-hover)] hover:text-[var(--color-text-primary)]',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const sizeStyles = {
|
|
24
|
+
sm: 'px-2 py-1 text-xs',
|
|
25
|
+
md: 'px-4 py-2 text-sm',
|
|
26
|
+
lg: 'px-5 py-2.5 text-sm',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function Button({
|
|
30
|
+
variant = 'primary',
|
|
31
|
+
size = 'md',
|
|
32
|
+
loading = false,
|
|
33
|
+
icon,
|
|
34
|
+
disabled,
|
|
35
|
+
children,
|
|
36
|
+
className = '',
|
|
37
|
+
...props
|
|
38
|
+
}: ButtonProps) {
|
|
39
|
+
return (
|
|
40
|
+
<button
|
|
41
|
+
disabled={disabled || loading}
|
|
42
|
+
className={`
|
|
43
|
+
inline-flex items-center justify-center gap-1.5 rounded-[var(--radius-md)]
|
|
44
|
+
font-medium transition-colors duration-150 cursor-pointer
|
|
45
|
+
disabled:opacity-50 disabled:cursor-not-allowed
|
|
46
|
+
${variantStyles[variant]} ${sizeStyles[size]} ${className}
|
|
47
|
+
`}
|
|
48
|
+
{...props}
|
|
49
|
+
>
|
|
50
|
+
{loading ? <Spinner /> : icon}
|
|
51
|
+
{children}
|
|
52
|
+
</button>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Spinner() {
|
|
57
|
+
return (
|
|
58
|
+
<svg className="animate-spin h-4 w-4" viewBox="0 0 24 24" fill="none">
|
|
59
|
+
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
60
|
+
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
|
61
|
+
</svg>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { copyTextToClipboard } from '../chat/clipboard'
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
text: string
|
|
6
|
+
label?: string
|
|
7
|
+
copiedLabel?: string
|
|
8
|
+
displayLabel?: string
|
|
9
|
+
displayCopiedLabel?: string
|
|
10
|
+
className?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function CopyButton({
|
|
14
|
+
text,
|
|
15
|
+
label = 'Copy',
|
|
16
|
+
copiedLabel = 'Copied',
|
|
17
|
+
displayLabel,
|
|
18
|
+
displayCopiedLabel,
|
|
19
|
+
className = '',
|
|
20
|
+
}: Props) {
|
|
21
|
+
const [copied, setCopied] = useState(false)
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!copied) return
|
|
25
|
+
const timer = window.setTimeout(() => setCopied(false), 1500)
|
|
26
|
+
return () => window.clearTimeout(timer)
|
|
27
|
+
}, [copied])
|
|
28
|
+
|
|
29
|
+
const handleCopy = async () => {
|
|
30
|
+
try {
|
|
31
|
+
const ok = await copyTextToClipboard(text)
|
|
32
|
+
if (!ok) {
|
|
33
|
+
setCopied(false)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
setCopied(true)
|
|
37
|
+
} catch {
|
|
38
|
+
setCopied(false)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const currentLabel = copied ? copiedLabel : label
|
|
43
|
+
const buttonText = copied
|
|
44
|
+
? (displayCopiedLabel ?? copiedLabel)
|
|
45
|
+
: (displayLabel ?? label)
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<button
|
|
49
|
+
type="button"
|
|
50
|
+
onClick={handleCopy}
|
|
51
|
+
className={className}
|
|
52
|
+
aria-label={currentLabel}
|
|
53
|
+
title={currentLabel}
|
|
54
|
+
>
|
|
55
|
+
{buttonText}
|
|
56
|
+
</button>
|
|
57
|
+
)
|
|
58
|
+
}
|