Skip to content

Commit bb33222

Browse files
author
linyuan.yang
committed
chat view 优化
1 parent 41f2c36 commit bb33222

10 files changed

Lines changed: 151 additions & 103 deletions

File tree

‎packages/chat-ui/src/components/ChatArea.vue‎

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ref, computed, watch, nextTick, onBeforeUnmount } from 'vue'
33
import type {
44
StoredMessage, ContentPart, Attachment, ChatLabels,
55
ToolCallEvent, ToolApprovalPayload, AskEvent, AskAnswerPayload,
6-
DisplayContent, UsageInfo,
6+
DisplayContent,
77
} from '../types'
88
import type { CommandInfo } from '../transport'
99
import { SSelect } from 'sbot-ui'
@@ -28,27 +28,26 @@ const props = withDefaults(defineProps<{
2828
showAttachments?: boolean
2929
hasSaver: boolean
3030
fetchThinks?: (url: string) => Promise<any>
31-
usage?: UsageInfo | null
32-
contextWindow?: number
3331
autoApprove?: boolean
3432
commands?: CommandInfo[]
3533
agent?: string
3634
agentOptions?: { value: string; label: string }[]
3735
saver?: string
3836
saverOptions?: { value: string; label: string }[]
3937
workPath?: string
38+
workPathReadonly?: boolean
4039
}>(), {
4140
showAttachments: false,
4241
thinksUrlPrefix: null,
4342
tasksUrlPrefix: null,
44-
usage: null,
4543
autoApprove: false,
4644
commands: () => [],
4745
agent: '',
4846
agentOptions: () => [],
4947
saver: '',
5048
saverOptions: () => [],
5149
workPath: '',
50+
workPathReadonly: false,
5251
})
5352
5453
const emit = defineEmits<{
@@ -75,30 +74,6 @@ let scrollFrame = 0
7574
7675
const { attachments, add: addFiles, remove: removeAttachment, drain: drainAttachments, isImageMime } = useAttachments()
7776
78-
const contextPercent = computed(() => {
79-
if (!props.contextWindow || !props.usage?.lastInputTokens) return null
80-
return Math.min(100, Math.round(props.usage.lastInputTokens / props.contextWindow * 100))
81-
})
82-
83-
const cachePercent = computed(() => {
84-
if (!props.usage) return null
85-
const read = props.usage.cacheReadTokens ?? 0
86-
if (read === 0) return null
87-
const total = props.usage.inputTokens + read + (props.usage.cacheCreationTokens ?? 0)
88-
if (total === 0) return null
89-
return Math.round(read / total * 100)
90-
})
91-
92-
function fmtCompact(n: number): string {
93-
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + 'M'
94-
if (n >= 1_000) return (n / 1_000).toFixed(1) + 'K'
95-
return String(n)
96-
}
97-
98-
function fmtFull(n: number): string {
99-
return n.toLocaleString()
100-
}
101-
10277
// ── Scrolling ──
10378
10479
function isAtBottom(): boolean {
@@ -212,26 +187,6 @@ defineExpose({ scrollToBottom })
212187
/>
213188
</div>
214189

215-
<!-- Compact usage strip -->
216-
<div
217-
v-if="isCompact && usage && usage.totalTokens > 0"
218-
class="chatui-input-usage-strip"
219-
:title="`Last: ${fmtFull(usage.lastTotalTokens)} / Total: ${fmtFull(usage.totalTokens)} tokens`"
220-
>
221-
<span v-if="contextPercent != null" class="chatui-input-usage-chip chatui-input-usage-chip--context">
222-
{{ contextPercent }}% context
223-
</span>
224-
<span class="chatui-input-usage-chip">
225-
Last {{ fmtCompact(usage.lastTotalTokens) }}
226-
</span>
227-
<span class="chatui-input-usage-chip">
228-
Total {{ fmtCompact(usage.totalTokens) }}
229-
</span>
230-
<span v-if="cachePercent != null" class="chatui-input-usage-chip chatui-input-usage-chip--cache">
231-
Cache {{ cachePercent }}%
232-
</span>
233-
</div>
234-
235190
<!-- Input bar (card) -->
236191
<div class="chatui-input-wrap" :class="{ 'chatui-compact': isCompact }">
237192
<div
@@ -342,16 +297,18 @@ defineExpose({ scrollToBottom })
342297
<div class="chatui-input-config-item chatui-input-config-path-wrap">
343298
<button
344299
class="chatui-input-config-path"
300+
:class="{ 'chatui-input-config-path--readonly': workPathReadonly }"
301+
:disabled="workPathReadonly"
345302
:title="workPath || L.workpathPlaceholder"
346-
@click="emit('open-path-picker', workPath)"
303+
@click="!workPathReadonly && emit('open-path-picker', workPath)"
347304
>
348305
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
349306
<path d="M2 5.5A1.5 1.5 0 0 1 3.5 4h3l1.2 1.5H12.5A1.5 1.5 0 0 1 14 7v4.5A1.5 1.5 0 0 1 12.5 13h-9A1.5 1.5 0 0 1 2 11.5Z" />
350307
</svg>
351308
<span class="chatui-input-config-path-text">{{ workPath || L.workpathPlaceholder }}</span>
352309
</button>
353310
<button
354-
v-if="workPath"
311+
v-if="workPath && !workPathReadonly"
355312
class="chatui-input-config-clear"
356313
:title="L.close"
357314
@click="emit('update-config', 'workPath', undefined)"
@@ -369,34 +326,6 @@ defineExpose({ scrollToBottom })
369326
.chatui-messages-scroll {
370327
flex: 1; overflow-y: auto;
371328
}
372-
.chatui-input-usage-strip {
373-
display: flex; align-items: center; justify-content: flex-end; gap: 6px;
374-
min-height: 28px;
375-
padding: 4px 8px;
376-
border-top: 1px solid var(--chatui-border-subtle);
377-
background: var(--chatui-bg-surface);
378-
color: var(--chatui-fg-secondary);
379-
font-size: 11px;
380-
font-variant-numeric: tabular-nums;
381-
line-height: 1;
382-
flex-wrap: wrap;
383-
flex-shrink: 0;
384-
}
385-
.chatui-input-usage-chip {
386-
display: inline-flex; align-items: center;
387-
min-height: 20px;
388-
padding: 0 7px;
389-
border: 1px solid var(--chatui-border-subtle);
390-
border-radius: 999px;
391-
background: var(--chatui-bg);
392-
white-space: nowrap;
393-
}
394-
.chatui-input-usage-chip--context {
395-
color: var(--chatui-fg);
396-
}
397-
.chatui-input-usage-chip--cache {
398-
color: var(--chatui-usage-cache, #22c55e);
399-
}
400329
/* Card-style input */
401330
.chatui-input-wrap {
402331
flex-shrink: 0;
@@ -556,6 +485,16 @@ defineExpose({ scrollToBottom })
556485
background: var(--chatui-bg-hover);
557486
color: var(--chatui-fg);
558487
}
488+
.chatui-input-config-path:disabled,
489+
.chatui-input-config-path--readonly {
490+
cursor: default;
491+
opacity: 1;
492+
}
493+
.chatui-input-config-path:disabled:hover,
494+
.chatui-input-config-path--readonly:hover {
495+
background: transparent;
496+
color: var(--chatui-fg-secondary);
497+
}
559498
.chatui-input-config-path-text {
560499
overflow: hidden;
561500
text-overflow: ellipsis;

‎packages/chat-ui/src/components/ChatView.vue‎

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import type {
55
StoredMessage, UsageInfo, UsageData, ContentPart, Attachment,
66
ToolCallEvent, ToolApprovalPayload,
77
AskEvent, AskAnswerPayload,
8-
DisplayContent, ChatEvent,
8+
DisplayContent, ChatEvent, ChatLayoutMode,
99
} from '../types'
1010
import { MessageRole, ChatEventType, MessageKind } from '../types'
1111
import type { IChatTransport, CommandInfo } from '../transport'
1212
import { resolveLabels, tpl } from '../labels'
13-
import { useCompactProvider } from '../composables/useCompact'
13+
import { provideCompact, useCompactProvider } from '../composables/useCompact'
1414
import SessionBar from './SessionBar.vue'
1515
import ConfigToolbar from './ConfigToolbar.vue'
1616
import StatusBar from './StatusBar.vue'
@@ -24,9 +24,15 @@ const props = withDefaults(defineProps<{
2424
labels?: ChatLabels
2525
showAttachments?: boolean
2626
alwaysCompact?: boolean
27+
layoutMode?: ChatLayoutMode
28+
fixedWorkPath?: string
29+
workPathLocked?: boolean
2730
}>(), {
2831
showAttachments: true,
2932
alwaysCompact: false,
33+
layoutMode: 'auto',
34+
fixedWorkPath: '',
35+
workPathLocked: false,
3036
})
3137
3238
const L = computed(() => resolveLabels(props.labels))
@@ -75,6 +81,12 @@ const sessionSearchInputEl = ref<HTMLInputElement | null>(null)
7581
const renameDialogVisible = ref(false)
7682
const renameDraft = ref('')
7783
const renameInputEl = ref<InstanceType<typeof SInput> | null>(null)
84+
const compactMode = computed(() => {
85+
if (props.layoutMode === 'compact') return true
86+
if (props.layoutMode === 'wide') return false
87+
return props.alwaysCompact || isCompact.value
88+
})
89+
provideCompact(compactMode)
7890
7991
// ── Derived ──
8092
@@ -98,6 +110,10 @@ const contextWindow = computed<number | undefined>(() => {
98110
return modelId ? settings.value.models?.[modelId]?.contextWindow : undefined
99111
})
100112
113+
const effectiveWorkPath = computed(() =>
114+
props.workPathLocked ? props.fixedWorkPath : (activeSession.value?.workPath || ''),
115+
)
116+
101117
const fetchThinks = computed(() => props.transport.fetchThinks?.bind(props.transport))
102118
103119
const agentOptions = computed(() => [
@@ -139,7 +155,7 @@ const displayedMessages = computed<StoredMessage[]>(() =>
139155
)
140156
141157
const rightPanelStyle = computed(() =>
142-
isCompact.value || props.alwaysCompact
158+
compactMode.value
143159
? undefined
144160
: { width: `${rightPanelWidth.value}px` },
145161
)
@@ -373,12 +389,12 @@ function onRenameDialogKeydown(e: KeyboardEvent) {
373389
374390
function setRightPanelOpen(open: boolean, persist = true) {
375391
rightPanelOpen.value = open
376-
if (persist && !(isCompact.value || props.alwaysCompact)) saveRightPanelOpenState(open)
392+
if (persist && !compactMode.value) saveRightPanelOpenState(open)
377393
}
378394
379395
function toggleRightPanel() {
380396
setRightPanelOpen(!rightPanelOpen.value)
381-
if (rightPanelOpen.value && (isCompact.value || props.alwaysCompact)) {
397+
if (rightPanelOpen.value && compactMode.value) {
382398
sidebarOpen.value = false
383399
settingsOpen.value = false
384400
compactMenuOpen.value = false
@@ -394,7 +410,7 @@ function clampRightPanelWidth(width: number): number {
394410
}
395411
396412
function startRightPanelResize(e: PointerEvent) {
397-
if (isCompact.value || props.alwaysCompact) return
413+
if (compactMode.value) return
398414
e.preventDefault()
399415
rightPanelResizing.value = true
400416
window.addEventListener('pointermove', onRightPanelResize)
@@ -420,7 +436,7 @@ function clampSessionBarWidth(width: number): number {
420436
}
421437
422438
function startSessionBarResize(e: PointerEvent) {
423-
if (isCompact.value || props.alwaysCompact) return
439+
if (compactMode.value) return
424440
e.preventDefault()
425441
sessionBarResizing.value = true
426442
window.addEventListener('pointermove', onSessionBarResize)
@@ -448,7 +464,7 @@ watch(activeProfileId, async (id) => {
448464
await Promise.all([loadHistory(gen), loadUsage(gen), restoreSessionStatus(gen)])
449465
})
450466
451-
watch(() => isCompact.value || props.alwaysCompact, (compact) => {
467+
watch(compactMode, (compact) => {
452468
rightPanelOpen.value = compact ? false : loadRightPanelOpenState()
453469
}, { immediate: true })
454470
@@ -583,10 +599,12 @@ async function onUpdateConfig(field: string, value: unknown) {
583599
}
584600
585601
function onOpenPathPicker(currentPath: string) {
602+
if (props.workPathLocked) return
586603
pathPickerRef.value?.open(currentPath)
587604
}
588605
589606
async function onPathConfirmed(path: string) {
607+
if (props.workPathLocked) return
590608
await onUpdateConfig('workPath', path || undefined)
591609
}
592610
@@ -718,9 +736,9 @@ function saveRightPanelOpenState(open: boolean): void {
718736
</script>
719737

720738
<template>
721-
<div ref="rootEl" class="chatui-root" :class="{ 'chatui-compact': isCompact || alwaysCompact, 'chatui-session-resizing': sessionBarResizing }">
722-
<!-- Compact mode (narrow screen or alwaysCompact): title opens the session drawer -->
723-
<template v-if="isCompact || alwaysCompact">
739+
<div ref="rootEl" class="chatui-root" :class="{ 'chatui-compact': compactMode, 'chatui-session-resizing': sessionBarResizing }">
740+
<!-- Compact mode: title opens the session drawer -->
741+
<template v-if="compactMode">
724742
<div class="chatui-compact-header">
725743
<button
726744
type="button"
@@ -899,7 +917,7 @@ function saveRightPanelOpenState(open: boolean): void {
899917
<div class="chatui-main">
900918
<!-- Config toolbar -->
901919
<ConfigToolbar
902-
v-if="!(isCompact || alwaysCompact)"
920+
v-if="!compactMode"
903921
:session="activeSession"
904922
:settings="settings"
905923
:labels="labels"
@@ -908,7 +926,7 @@ function saveRightPanelOpenState(open: boolean): void {
908926

909927
<!-- Status bar -->
910928
<StatusBar
911-
v-if="activeProfileId && !(isCompact || alwaysCompact)"
929+
v-if="activeProfileId && !compactMode"
912930
:usage="usage"
913931
:context-window="contextWindow"
914932
:labels="labels"
@@ -951,15 +969,14 @@ function saveRightPanelOpenState(open: boolean): void {
951969
:show-attachments="showAttachments"
952970
:has-saver="hasSaver"
953971
:fetch-thinks="fetchThinks"
954-
:usage="usage"
955-
:context-window="contextWindow"
956972
:auto-approve="!!activeSession?.autoApproveAllTools"
957973
:commands="commands"
958974
:agent="activeSession?.agent || ''"
959975
:agent-options="agentOptions"
960976
:saver="activeSession?.saver || ''"
961977
:saver-options="saverOptions"
962-
:work-path="activeSession?.workPath || ''"
978+
:work-path="effectiveWorkPath"
979+
:work-path-readonly="workPathLocked"
963980
@send="onSend"
964981
@approve="onApprove"
965982
@answer="onAnswer"
@@ -971,18 +988,18 @@ function saveRightPanelOpenState(open: boolean): void {
971988
/>
972989
<div v-if="rightPanelOpen" class="chatui-right-panel-pane" :style="rightPanelStyle">
973990
<div
974-
v-if="!(isCompact || alwaysCompact)"
991+
v-if="!compactMode"
975992
class="chatui-right-panel-resizer"
976993
:title="L.rightPanelToggle"
977994
@pointerdown="startRightPanelResize"
978995
/>
979-
<div v-if="isCompact || alwaysCompact" class="chatui-right-panel-header">
996+
<div v-if="compactMode" class="chatui-right-panel-header">
980997
<span class="chatui-right-panel-title">{{ L.rightPanelToggle }}</span>
981998
<button class="chatui-right-panel-close" :title="L.close" @click="setRightPanelOpen(false, false)">×</button>
982999
</div>
9831000
<WorkbenchPanel
9841001
:transport="transport"
985-
:root="activeSession?.workPath"
1002+
:root="effectiveWorkPath"
9861003
:labels="labels"
9871004
:persist-key="activeProfileId ?? undefined"
9881005
editable

‎packages/chat-ui/src/components/ServerChatShell.vue‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
3-
import type { ChatLabels, RemoteEntry } from '../types'
3+
import type { ChatLabels, ChatLayoutMode, RemoteEntry } from '../types'
44
import type { IChatTransport } from '../transport'
55
import type { ServerSelectionPhase } from '../composables/useServerSelection'
66
import { resolveLabels } from '../labels'
@@ -17,11 +17,17 @@ const props = withDefaults(defineProps<{
1717
labels?: ChatLabels
1818
showAttachments?: boolean
1919
alwaysCompact?: boolean
20+
layoutMode?: ChatLayoutMode
21+
fixedWorkPath?: string
22+
workPathLocked?: boolean
2023
}>(), {
2124
connectError: '',
2225
connecting: false,
2326
showAttachments: true,
2427
alwaysCompact: false,
28+
layoutMode: 'auto',
29+
fixedWorkPath: '',
30+
workPathLocked: false,
2531
})
2632
2733
const emit = defineEmits<{
@@ -67,6 +73,9 @@ const L = computed(() => resolveLabels(props.labels))
6773
:labels="labels"
6874
:show-attachments="showAttachments"
6975
:always-compact="alwaysCompact"
76+
:layout-mode="layoutMode"
77+
:fixed-work-path="fixedWorkPath"
78+
:work-path-locked="workPathLocked"
7079
/>
7180
</template>
7281
</div>

0 commit comments

Comments
 (0)