bingocode 1.0.3 → 1.0.4
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/package.json +1 -1
- package/desktop/README.md +0 -30
- package/desktop/bunfig.toml +0 -1
- package/desktop/index.html +0 -17
- package/desktop/package.json +0 -55
- package/desktop/pnpm-lock.yaml +0 -3832
- 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 +0 -1
- package/desktop/public/icons/douyin.svg +0 -1
- package/desktop/public/icons/github.svg +0 -3
- package/desktop/public/icons/xiaohongshu.svg +0 -1
- package/desktop/scripts/build-macos-arm64.sh +0 -270
- package/desktop/scripts/build-sidecars.ts +0 -183
- package/desktop/scripts/build-windows-x64.ps1 +0 -295
- package/desktop/scripts/scan-missing-imports.ts +0 -235
- package/desktop/sidecars/claude-sidecar.ts +0 -156
- package/desktop/src/App.tsx +0 -5
- package/desktop/src/__tests__/agentsSettings.test.tsx +0 -349
- package/desktop/src/__tests__/pages.test.tsx +0 -290
- package/desktop/src/__tests__/skillsSettings.test.tsx +0 -205
- package/desktop/src/api/adapters.ts +0 -12
- package/desktop/src/api/agents.ts +0 -36
- package/desktop/src/api/cliTasks.ts +0 -28
- package/desktop/src/api/client.ts +0 -63
- package/desktop/src/api/computerUse.ts +0 -76
- package/desktop/src/api/filesystem.ts +0 -30
- package/desktop/src/api/hahaOAuth.ts +0 -38
- package/desktop/src/api/models.ts +0 -28
- package/desktop/src/api/providers.ts +0 -63
- package/desktop/src/api/search.ts +0 -29
- package/desktop/src/api/sessions.ts +0 -56
- package/desktop/src/api/settings.ts +0 -20
- package/desktop/src/api/skills.ts +0 -19
- package/desktop/src/api/tasks.ts +0 -36
- package/desktop/src/api/teams.ts +0 -44
- package/desktop/src/api/websocket.ts +0 -164
- package/desktop/src/components/chat/AskUserQuestion.tsx +0 -268
- package/desktop/src/components/chat/AssistantMessage.tsx +0 -29
- package/desktop/src/components/chat/AttachmentGallery.tsx +0 -113
- package/desktop/src/components/chat/ChatInput.tsx +0 -622
- package/desktop/src/components/chat/CodeViewer.tsx +0 -161
- package/desktop/src/components/chat/ComputerUsePermissionModal.test.tsx +0 -174
- package/desktop/src/components/chat/ComputerUsePermissionModal.tsx +0 -311
- package/desktop/src/components/chat/DiffViewer.tsx +0 -157
- package/desktop/src/components/chat/FileSearchMenu.tsx +0 -198
- package/desktop/src/components/chat/ImageGalleryModal.tsx +0 -91
- package/desktop/src/components/chat/InlineImageGallery.tsx +0 -106
- package/desktop/src/components/chat/InlineTaskSummary.tsx +0 -60
- package/desktop/src/components/chat/MermaidRenderer.test.tsx +0 -98
- package/desktop/src/components/chat/MermaidRenderer.tsx +0 -361
- package/desktop/src/components/chat/MessageActionBar.tsx +0 -27
- package/desktop/src/components/chat/MessageList.test.tsx +0 -313
- package/desktop/src/components/chat/MessageList.tsx +0 -249
- package/desktop/src/components/chat/PermissionDialog.tsx +0 -262
- package/desktop/src/components/chat/SessionTaskBar.test.tsx +0 -99
- package/desktop/src/components/chat/SessionTaskBar.tsx +0 -159
- package/desktop/src/components/chat/StreamingIndicator.tsx +0 -41
- package/desktop/src/components/chat/TerminalChrome.tsx +0 -35
- package/desktop/src/components/chat/ThinkingBlock.tsx +0 -87
- package/desktop/src/components/chat/ToolCallBlock.tsx +0 -247
- package/desktop/src/components/chat/ToolCallGroup.tsx +0 -617
- package/desktop/src/components/chat/ToolResultBlock.tsx +0 -107
- package/desktop/src/components/chat/UserMessage.tsx +0 -38
- package/desktop/src/components/chat/chatBlocks.test.tsx +0 -136
- package/desktop/src/components/chat/clipboard.ts +0 -25
- package/desktop/src/components/chat/composerUtils.test.ts +0 -55
- package/desktop/src/components/chat/composerUtils.ts +0 -149
- package/desktop/src/components/controls/ModelSelector.tsx +0 -156
- package/desktop/src/components/controls/PermissionModeSelector.tsx +0 -229
- package/desktop/src/components/layout/AppShell.tsx +0 -107
- package/desktop/src/components/layout/ContentRouter.tsx +0 -27
- package/desktop/src/components/layout/ProjectFilter.tsx +0 -126
- package/desktop/src/components/layout/Sidebar.test.tsx +0 -158
- package/desktop/src/components/layout/Sidebar.tsx +0 -384
- package/desktop/src/components/layout/StatusBar.tsx +0 -31
- package/desktop/src/components/layout/TabBar.test.tsx +0 -136
- package/desktop/src/components/layout/TabBar.tsx +0 -318
- package/desktop/src/components/layout/TitleBar.tsx +0 -96
- package/desktop/src/components/layout/WindowControls.test.tsx +0 -69
- package/desktop/src/components/layout/WindowControls.tsx +0 -89
- package/desktop/src/components/markdown/MarkdownRenderer.test.tsx +0 -100
- package/desktop/src/components/markdown/MarkdownRenderer.tsx +0 -229
- package/desktop/src/components/settings/ClaudeOfficialLogin.tsx +0 -107
- package/desktop/src/components/shared/Button.tsx +0 -63
- package/desktop/src/components/shared/CopyButton.tsx +0 -58
- package/desktop/src/components/shared/DirectoryPicker.tsx +0 -316
- package/desktop/src/components/shared/Dropdown.tsx +0 -91
- package/desktop/src/components/shared/Input.tsx +0 -38
- package/desktop/src/components/shared/Modal.tsx +0 -65
- package/desktop/src/components/shared/ProjectContextChip.tsx +0 -30
- package/desktop/src/components/shared/Spinner.tsx +0 -30
- package/desktop/src/components/shared/Textarea.tsx +0 -38
- package/desktop/src/components/shared/Toast.tsx +0 -47
- package/desktop/src/components/shared/UpdateChecker.tsx +0 -90
- package/desktop/src/components/skills/SkillDetail.test.tsx +0 -89
- package/desktop/src/components/skills/SkillDetail.tsx +0 -403
- package/desktop/src/components/skills/SkillList.tsx +0 -254
- package/desktop/src/components/tasks/DayOfWeekPicker.tsx +0 -57
- package/desktop/src/components/tasks/NewTaskModal.tsx +0 -407
- package/desktop/src/components/tasks/PromptEditor.tsx +0 -74
- package/desktop/src/components/tasks/TaskEmptyState.tsx +0 -30
- package/desktop/src/components/tasks/TaskList.tsx +0 -46
- package/desktop/src/components/tasks/TaskRow.tsx +0 -253
- package/desktop/src/components/tasks/TaskRunsPanel.tsx +0 -195
- package/desktop/src/components/teams/TeamStatusBar.tsx +0 -147
- package/desktop/src/config/providerPresets.ts +0 -78
- package/desktop/src/config/spinnerVerbs.ts +0 -193
- package/desktop/src/hooks/useKeyboardShortcuts.ts +0 -60
- package/desktop/src/i18n/index.ts +0 -54
- package/desktop/src/i18n/locales/en.ts +0 -670
- package/desktop/src/i18n/locales/zh.ts +0 -670
- package/desktop/src/lib/__tests__/cronDescribe.test.ts +0 -93
- package/desktop/src/lib/cronDescribe.ts +0 -188
- package/desktop/src/lib/desktopRuntime.ts +0 -54
- package/desktop/src/lib/parseRunOutput.ts +0 -79
- package/desktop/src/main.tsx +0 -13
- package/desktop/src/mocks/data.ts +0 -202
- package/desktop/src/pages/ActiveSession.test.tsx +0 -181
- package/desktop/src/pages/ActiveSession.tsx +0 -219
- package/desktop/src/pages/AdapterSettings.tsx +0 -375
- package/desktop/src/pages/AgentTeams.tsx +0 -200
- package/desktop/src/pages/ComputerUseSettings.tsx +0 -420
- package/desktop/src/pages/EmptySession.tsx +0 -518
- package/desktop/src/pages/NewTaskModal.tsx +0 -346
- package/desktop/src/pages/ScheduledTasks.tsx +0 -66
- package/desktop/src/pages/ScheduledTasksEmpty.tsx +0 -152
- package/desktop/src/pages/ScheduledTasksList.tsx +0 -416
- package/desktop/src/pages/SessionControls.tsx +0 -460
- package/desktop/src/pages/Settings.tsx +0 -1448
- package/desktop/src/pages/ToolInspection.tsx +0 -235
- package/desktop/src/stores/adapterStore.ts +0 -106
- package/desktop/src/stores/agentStore.ts +0 -34
- package/desktop/src/stores/chatStore.test.ts +0 -505
- package/desktop/src/stores/chatStore.ts +0 -850
- package/desktop/src/stores/cliTaskStore.ts +0 -152
- package/desktop/src/stores/hahaOAuthStore.test.ts +0 -77
- package/desktop/src/stores/hahaOAuthStore.ts +0 -97
- package/desktop/src/stores/providerStore.ts +0 -101
- package/desktop/src/stores/sessionStore.test.ts +0 -63
- package/desktop/src/stores/sessionStore.ts +0 -102
- package/desktop/src/stores/settingsStore.ts +0 -120
- package/desktop/src/stores/skillStore.ts +0 -51
- package/desktop/src/stores/tabStore.ts +0 -169
- package/desktop/src/stores/taskStore.ts +0 -68
- package/desktop/src/stores/teamStore.ts +0 -344
- package/desktop/src/stores/uiStore.ts +0 -100
- package/desktop/src/stores/updateStore.test.ts +0 -71
- package/desktop/src/stores/updateStore.ts +0 -221
- package/desktop/src/theme/globals.css +0 -465
- package/desktop/src/types/adapter.ts +0 -33
- package/desktop/src/types/chat.ts +0 -152
- package/desktop/src/types/cliTask.ts +0 -24
- package/desktop/src/types/provider.ts +0 -62
- package/desktop/src/types/session.ts +0 -27
- package/desktop/src/types/settings.ts +0 -22
- package/desktop/src/types/skill.ts +0 -38
- package/desktop/src/types/task.ts +0 -56
- package/desktop/src/types/team.ts +0 -38
- package/desktop/src-tauri/Cargo.lock +0 -5549
- package/desktop/src-tauri/Cargo.toml +0 -20
- package/desktop/src-tauri/app-icon.svg +0 -13
- package/desktop/src-tauri/build.rs +0 -3
- package/desktop/src-tauri/capabilities/default.json +0 -106
- package/desktop/src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml +0 -5
- package/desktop/src-tauri/icons/android/values/ic_launcher_background.xml +0 -4
- 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 +0 -408
- package/desktop/src-tauri/src/main.rs +0 -6
- package/desktop/src-tauri/tauri.conf.json +0 -78
- package/desktop/src-tauri/tauri.macos.conf.json +0 -18
- package/desktop/src-tauri/tauri.release-ci.json +0 -5
- package/desktop/src-tauri/tauri.windows.conf.json +0 -16
- package/desktop/src-tauri/windows-installer-hooks.nsh +0 -17
- package/desktop/tsconfig.json +0 -25
- package/desktop/vite.config.ts +0 -26
- package/desktop/vitest.config.ts +0 -18
|
@@ -1,229 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|