Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(chat): refine sandbox artifact panel interactions

wizardchen0f3ffbe4924d
diff --git a/frontend/src/components/chat/SandboxSidePanel.vue b/frontend/src/components/chat/SandboxSidePanel.vue
index 29d9922ce..049e5560f 100644
--- a/frontend/src/components/chat/SandboxSidePanel.vue
+++ b/frontend/src/components/chat/SandboxSidePanel.vue
@@ -297,8 +297,14 @@ function startResize(event: MouseEvent) {
}
&.is-active {
- color: var(--td-brand-color);
- background: var(--td-brand-color-light);
+ color: var(--td-text-color-primary);
+ background: var(--td-bg-color-secondarycontainer);
+ font-weight: 500;
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--td-text-color-secondary);
+ outline-offset: -2px;
}
}
@@ -307,11 +313,12 @@ function startResize(event: MouseEvent) {
height: 16px;
padding: 0 5px;
border-radius: 8px;
- background: var(--td-brand-color);
- color: #fff;
+ background: color-mix(in srgb, var(--td-text-color-primary) 8%, transparent);
+ color: var(--td-text-color-secondary);
font-size: 11px;
line-height: 16px;
text-align: center;
+ font-variant-numeric: tabular-nums;
}
.chat-sandbox-panel__body {
diff --git a/frontend/src/composables/useChatSandboxPanel.test.mjs b/frontend/src/composables/useChatSandboxPanel.test.mjs
new file mode 100644
index 000000000..68456e063
--- /dev/null
+++ b/frontend/src/composables/useChatSandboxPanel.test.mjs
@@ -0,0 +1,73 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+import vm from 'node:vm'
+import ts from 'typescript'
+import { ref } from 'vue'
+
+const source = readFileSync(new URL('./useChatSandboxPanel.ts', import.meta.url), 'utf8')
+const start = source.indexOf('export function provideChatSandboxPanel(')
+const end = source.indexOf('\nexport function useChatSandboxPanel(', start)
+assert.ok(start >= 0 && end > start)
+const factory = ts.transpile(source.slice(start, end).replace('export function', 'function'))
+
+function createPanel() {
+ return vm.runInNewContext(`${factory}; provideChatSandboxPanel()`, {
+ ref,
+ initialPanelWidth: () => 420,
+ provide() {},
+ CHAT_SANDBOX_PANEL_KEY: Symbol(),
+ })
+}
+
+test('clicking the same folder opens, closes, and reopens its artifacts', () => {
+ const panel = createPanel()
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.artifactFocus.value.messageId, 'a')
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, false)
+ assert.equal(panel.artifactFocus.value, null)
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.artifactFocus.value.messageId, 'a')
+})
+
+test('clicking another message folder switches focus without closing', () => {
+ const panel = createPanel()
+ panel.toggleArtifacts('a')
+ panel.toggleArtifacts('b')
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.artifactFocus.value.messageId, 'b')
+})
+
+test('folder entry switches from terminal or an unfocused header entry to its files', () => {
+ const panel = createPanel()
+ panel.open()
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.artifactFocus.value.messageId, 'a')
+ panel.open('terminal')
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.activeTab.value, 'artifacts')
+})
+
+test('inline preview requests stay open even when repeated; folder click closes them', () => {
+ const panel = createPanel()
+ for (let i = 0; i < 2; i++) {
+ panel.open('artifacts', { messageId: 'a', previewIndex: 0 })
+ assert.equal(panel.visible.value, true)
+ assert.equal(panel.artifactFocus.value.previewIndex, 0)
+ }
+ panel.toggleArtifacts('a')
+ assert.equal(panel.visible.value, false)
+})
+
+test('both answer renderers toggle folders while retaining explicit preview opening', () => {
+ for (const file of ['botmsg.vue', 'AgentStreamDisplay.vue']) {
+ const component = readFileSync(new URL(`../views/chat/components/${file}`, import.meta.url), 'utf8')
+ assert.match(component, /if \(previewIndex == null\)\s*\{\s*sandboxPanel\.toggleArtifacts\(messageIdForArtifacts\.value\)/)
+ assert.match(component, /else\s*\{\s*sandboxPanel\.open\('artifacts',/)
+ }
+})
diff --git a/frontend/src/composables/useChatSandboxPanel.ts b/frontend/src/composables/useChatSandboxPanel.ts
index 9c313a491..8cc3fbc0a 100644
--- a/frontend/src/composables/useChatSandboxPanel.ts
+++ b/frontend/src/composables/useChatSandboxPanel.ts
@@ -38,6 +38,7 @@ export type ChatSandboxPanelContext = {
setWidth: (width: number) => void
artifactFocus: Ref<ArtifactPanelFocusState | null>
open: (tab?: SandboxPanelTab, focus?: ArtifactPanelFocus) => void
+ toggleArtifacts: (messageId: string) => void
close: () => void
clearArtifactFocus: () => void
}
@@ -71,6 +72,18 @@ export function provideChatSandboxPanel(): ChatSandboxPanelContext {
artifactFocus.value = null
}
+ const toggleArtifacts = (messageId: string) => {
+ if (
+ visible.value &&
+ activeTab.value === 'artifacts' &&
+ artifactFocus.value?.messageId === messageId
+ ) {
+ close()
+ return
+ }
+ open('artifacts', { messageId })
+ }
+
const clearArtifactFocus = () => {
artifactFocus.value = null
}
@@ -82,6 +95,7 @@ export function provideChatSandboxPanel(): ChatSandboxPanelContext {
setWidth,
artifactFocus,
open,
+ toggleArtifacts,
close,
clearArtifactFocus,
}
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts
index e0f74e051..6f40b5f9d 100755
--- a/frontend/src/i18n/locales/en-US.ts
+++ b/frontend/src/i18n/locales/en-US.ts
@@ -3414,6 +3414,11 @@ export default {
tabTerminal: 'Terminal',
tabDesktop: 'Desktop',
artifactsEmpty: 'No generated files in this conversation yet.',
+ artifactScope: 'File scope',
+ artifactsCurrent: 'This turn',
+ artifactsAll: 'All files',
+ artifactsSearch: 'Search filenames',
+ artifactsNoMatches: 'No matching files',
desktopPlaceholder: 'Desktop visualization coming soon',
notStarted: 'The terminal is not running yet. Starting it connects to this conversation\'s sandbox, creating or resuming one if none is available.',
paused: 'This conversation\'s sandbox is paused. Starting the terminal resumes it.',
diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts
index d752683f1..bb76732e1 100644
--- a/frontend/src/i18n/locales/ja-JP.ts
+++ b/frontend/src/i18n/locales/ja-JP.ts
@@ -3414,6 +3414,11 @@ export default {
tabTerminal: 'ターミナル',
tabDesktop: 'デスクトップ',
artifactsEmpty: 'この会話で生成されたファイルはまだありません',
+ artifactScope: 'ファイルの範囲',
+ artifactsCurrent: 'このターン',
+ artifactsAll: 'すべて',
+ artifactsSearch: 'ファイル名を検索',
+ artifactsNoMatches: '一致するファイルがありません',
desktopPlaceholder: 'デスクトップの可視化は近日対応予定です',
notStarted: 'ターミナルはまだ起動していません。起動するとこの会話のサンドボックスに接続し、存在しないか一時停止中の場合は作成または再開します。',
paused: 'この会話のサンドボックスは一時停止中です。ターミナルを起動すると再開します。',
diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts
index 8b5fdbf5f..5188e2361 100755
--- a/frontend/src/i18n/locales/ko-KR.ts
+++ b/frontend/src/i18n/locales/ko-KR.ts
@@ -3461,6 +3461,11 @@ export default {
tabTerminal: '터미널',
tabDesktop: '데스크톱',
artifactsEmpty: '이 대화에서 생성된 파일이 없습니다',
+ artifactScope: '파일 범위',
+ artifactsCurrent: '이번 응답',
+ artifactsAll: '전체',
+ artifactsSearch: '파일 이름 검색',
+ artifactsNoMatches: '일치하는 파일이 없습니다',
desktopPlaceholder: '데스크톱 시각화는 곧 지원될 예정입니다',
notStarted: '터미널이 아직 실행되지 않았습니다. 시작하면 이 대화의 샌드박스에 연결하며, 샌드박스가 없거나 일시 중지된 경우 생성하거나 다시 시작합니다.',
paused: '이 대화의 샌드박스가 일시 중지되었습니다. 터미널을 시작하면 다시 시작됩니다.',
diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts
index 8d1b3f16b..9a8ea70d1 100755
--- a/frontend/src/i18n/locales/ru-RU.ts
+++ b/frontend/src/i18n/locales/ru-RU.ts
@@ -3461,6 +3461,11 @@ export default {
tabTerminal: 'Терминал',
tabDesktop: 'Рабочий стол',
artifactsEmpty: 'В этом диалоге пока нет созданных файлов',
+ artifactScope: 'Область файлов',
+ artifactsCurrent: 'Этот ответ',
+ artifactsAll: 'Все файлы',
+ artifactsSearch: 'Поиск по имени файла',
+ artifactsNoMatches: 'Нет подходящих файлов',
desktopPlaceholder: 'Визуализация рабочего стола скоро появится',
notStarted: 'Терминал ещё не запущен. Запуск подключит его к песочнице этого диалога, создав или возобновив её при необходимости.',
paused: 'Песочница этого диалога приостановлена. Запуск терминала возобновит её.',
diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts
index b00f390ba..cbf979365 100755
--- a/frontend/src/i18n/locales/zh-CN.ts
+++ b/frontend/src/i18n/locales/zh-CN.ts
@@ -3463,6 +3463,11 @@ export default {
tabTerminal: '终端',
tabDesktop: '桌面',
artifactsEmpty: '本会话尚未生成可下载的文件',
+ artifactScope: '产物范围',
+ artifactsCurrent: '本轮',
+ artifactsAll: '全部',
+ artifactsSearch: '搜索文件名',
+ artifactsNoMatches: '没有匹配的文件',
desktopPlaceholder: '桌面可视化即将支持',
notStarted: '终端尚未启动。启动后会连接本会话的沙箱环境;若沙箱不存在或已暂停,将为你创建或唤醒它。',
paused: '本会话的沙箱已暂停。启动终端会唤醒它。',
diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue
index 3df5311cb..079c3ff87 100644
--- a/frontend/src/views/chat/components/AgentStreamDisplay.vue
+++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue
@@ -1033,10 +1033,14 @@ const artifactPreviewIndex = ref<number | null>(null);
function openArtifactDrawer(previewIndex: number | null = null) {
if (!hasArtifacts.value) return;
if (sandboxPanel && !props.embeddedMode) {
- sandboxPanel.open('artifacts', {
- messageId: messageIdForArtifacts.value,
- previewIndex,
- });
+ if (previewIndex == null) {
+ sandboxPanel.toggleArtifacts(messageIdForArtifacts.value);
+ } else {
+ sandboxPanel.open('artifacts', {
+ messageId: messageIdForArtifacts.value,
+ previewIndex,
+ });
+ }
return;
}
artifactPreviewIndex.value = previewIndex;
diff --git a/frontend/src/views/chat/components/ArtifactFileIcon.vue b/frontend/src/views/chat/components/ArtifactFileIcon.vue
new file mode 100644
index 000000000..411d18ce0
--- /dev/null
+++ b/frontend/src/views/chat/components/ArtifactFileIcon.vue
@@ -0,0 +1,64 @@
+<template>
+ <svg class="artifact-file-icon" :class="`kind-${kind}`" viewBox="0 0 32 38" fill="none" aria-hidden="true">
+ <path class="file-sheet" d="M6 1.5h13L28.5 11v22A3.5 3.5 0 0 1 25 36.5H6A3.5 3.5 0 0 1 2.5 33V5A3.5 3.5 0 0 1 6 1.5Z" />
+ <path class="file-fold" d="M19 1.5V8a3 3 0 0 0 3 3h6.5" />
+ <path class="file-lines" d="M8 14h9M8 18h14" />
+ <rect x="5" y="23" width="24" height="11" rx="3" fill="currentColor" />
+ <text x="17" y="30.8" text-anchor="middle">{{ label }}</text>
+ </svg>
+</template>
+
+<script setup lang="ts">
+import { computed } from 'vue'
+import { getFileIcon } from '@/utils/files'
+import { resolveFilePreviewExt } from '@/utils/filePreview'
+
+const props = defineProps<{ fileName: string }>()
+const kind = computed(() => getFileIcon(props.fileName))
+const label = computed(() => {
+ const ext = resolveFilePreviewExt(props.fileName)
+ return /^[a-z0-9]{1,4}$/i.test(ext) ? ext.toUpperCase() : 'FILE'
+})
+</script>
+
+<style scoped lang="less">
+.artifact-file-icon {
+ flex-shrink: 0;
+ width: 32px;
+ height: 38px;
+ color: var(--td-text-color-secondary);
+
+ &.kind-file-word { color: #5381c4; }
+ &.kind-file-excel { color: #419781; }
+ &.kind-file-powerpoint { color: #c18a4e; }
+ &.kind-file-pdf { color: #c56868; }
+ &.kind-image,
+ &.kind-video { color: #9273bd; }
+ &.kind-code,
+ &.kind-sound { color: #5d95ad; }
+
+ .file-sheet {
+ fill: var(--td-bg-color-container);
+ stroke: currentColor;
+ stroke-opacity: 0.35;
+ stroke-width: 1.2;
+ }
+
+ .file-fold,
+ .file-lines {
+ stroke: currentColor;
+ stroke-opacity: 0.35;
+ stroke-width: 1.2;
+ stroke-linecap: round;
+ stroke-linejoin: round;
+ }
+
+ text {
+ fill: #fff;
+ font-family: ui-sans-serif, system-ui, sans-serif;
+ font-size: 7px;
+ font-weight: 650;
+ letter-spacing: 0.2px;
+ }
+}
+</style>
diff --git a/frontend/src/views/chat/components/ChatArtifactsPanel.test.mjs b/frontend/src/views/chat/components/ChatArtifactsPanel.test.mjs
new file mode 100644
index 000000000..8a7d2f322
--- /dev/null
+++ b/frontend/src/views/chat/components/ChatArtifactsPanel.test.mjs
@@ -0,0 +1,164 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+import vm from 'node:vm'
+import ts from 'typescript'
+import { computed, effectScope, nextTick, reactive, ref, watch } from 'vue'
+
+const source = readFileSync(new URL('./ChatArtifactsPanel.vue', import.meta.url), 'utf8')
+const start = source.indexOf('function applyFocus(')
+const end = source.indexOf('\nwatch(', start)
+assert.ok(start >= 0 && end > start)
+const applyFocusSource = ts.transpile(source.slice(start, end))
+
+function setup({ top = 120, bottom = 180, left = 1600 } = {}) {
+ const pending = []
+ const scrolls = []
+ const target = { messageId: 'target', index: 0 }
+ const row = {
+ getAttribute: () => 'target',
+ getBoundingClientRect: () => ({ top, bottom, left, right: left + 400 }),
+ scrollIntoView: () => assert.fail('Artifact focus must not scroll outer ancestors'),
+ }
+ const list = {
+ scrollTop: 200,
+ getBoundingClientRect: () => ({ top: 100, bottom: 400, left, right: left + 420 }),
+ querySelectorAll: () => [row],
+ scrollTo: ({ top }) => scrolls.push(top),
+ }
+ const previewItem = { value: null }
+ const focusedMessageId = { value: null }
+ const applyFocus = vm.runInNewContext(`${applyFocusSource}; applyFocus`, {
+ listRef: { value: list }, previewItem, focusedMessageId,
+ nextTick: (fn) => pending.push(fn),
+ findItem: () => target,
+ })
+ return {
+ applyFocus, scrolls, previewItem, focusedMessageId, target,
+ flush: () => pending.splice(0).forEach((fn) => fn()),
+ }
+}
+
+test('folder focus during panel entry locates a visible file without scrolling ancestors', () => {
+ const ctx = setup()
+ ctx.applyFocus({ messageId: 'target', nonce: 1 })
+ ctx.flush()
+ assert.equal(ctx.focusedMessageId.value, 'target')
+ assert.deepEqual(ctx.scrolls, [])
+})
+
+test('folder focus reveals files above or below the list using only list scrolling', () => {
+ for (const [top, bottom, expected] of [[40, 100, 140], [380, 440, 240]]) {
+ const ctx = setup({ top, bottom })
+ ctx.applyFocus({ messageId: 'target', nonce: 1 })
+ ctx.flush()
+ assert.deepEqual(ctx.scrolls, [expected])
+ }
+})
+
+test('folder entry exits a preview and repeated clicks locate the file again', () => {
+ const ctx = setup({ top: 380, bottom: 440 })
+ ctx.applyFocus({ messageId: 'target', previewIndex: 0, nonce: 1 })
+ assert.equal(ctx.previewItem.value, ctx.target)
+ ctx.flush()
+ assert.deepEqual(ctx.scrolls, [])
+ for (const nonce of [2, 3]) {
+ ctx.applyFocus({ messageId: 'target', nonce })
+ ctx.flush()
+ assert.equal(ctx.previewItem.value, null)
+ }
+ assert.deepEqual(ctx.scrolls, [240, 240])
+})
+
+test('header entry without a message focus does not scroll the artifact list', () => {
+ const ctx = setup()
+ ctx.applyFocus(null)
+ ctx.flush()
+ assert.deepEqual(ctx.scrolls, [])
+ assert.equal(ctx.focusedMessageId.value, null)
+})
+
+const stateStart = source.indexOf('const listRef = ')
+const stateEnd = source.indexOf('async function handleDownload(', stateStart)
+assert.ok(stateStart >= 0 && stateEnd > stateStart)
+const stateSource = ts.transpile(source.slice(stateStart, stateEnd))
+
+function setupFilters(t) {
+ const effects = effectScope()
+ t.after(() => effects.stop())
+ const props = reactive({
+ sessionId: 'session-a',
+ items: [
+ { messageId: 'a', index: 0, file_name: 'Report.docx' },
+ { messageId: 'b', index: 3, file_name: 'Report.docx' },
+ { messageId: 'b', index: 7, file_name: 'chart.png' },
+ ],
+ })
+ const panel = {
+ artifactFocus: ref(null),
+ clearArtifactFocus() { this.artifactFocus.value = null },
+ }
+ const state = effects.run(() => vm.runInNewContext(`${stateSource}; ({
+ scope, searchQuery, currentItems, visibleItems, previewItem, openPreview, closePreview,
+ })`, {
+ computed, nextTick, reactive, ref, watch, props, panel,
+ resolveFilePreviewExt: () => '',
+ }))
+ return { ...state, props, panel }
+}
+
+test('header entry shows all files; folder entry filters by message without changing artifact indexes', async (t) => {
+ const ctx = setupFilters(t)
+ assert.equal(ctx.scope.value, 'all')
+ assert.equal(ctx.visibleItems.value.length, 3)
+ ctx.panel.artifactFocus.value = { messageId: 'b', nonce: 1 }
+ await nextTick()
+ assert.equal(ctx.scope.value, 'current')
+ assert.deepEqual(ctx.visibleItems.value.map((item) => item.index), [3, 7])
+ ctx.scope.value = 'all'
+ assert.equal(ctx.visibleItems.value.length, 3)
+})
+
+test('filename search combines with scope and survives incoming files', async (t) => {
+ const ctx = setupFilters(t)
+ ctx.panel.artifactFocus.value = { messageId: 'b', nonce: 1 }
+ await nextTick()
+ ctx.searchQuery.value = ' REPORT.DOCX '
+ assert.equal(ctx.visibleItems.value.length, 1)
+ ctx.scope.value = 'all'
+ assert.equal(ctx.visibleItems.value.length, 2)
+ ctx.props.items = [...ctx.props.items, { messageId: 'c', index: 0, file_name: 'Report.docx' }]
+ await nextTick()
+ assert.equal(ctx.scope.value, 'all')
+ assert.equal(ctx.searchQuery.value, ' REPORT.DOCX ')
+ assert.equal(ctx.visibleItems.value.length, 3)
+ ctx.searchQuery.value = 'missing'
+ assert.equal(ctx.visibleItems.value.length, 0)
+})
+
+test('switching message focus or session resets stale filters', async (t) => {
+ const ctx = setupFilters(t)
+ ctx.searchQuery.value = 'chart'
+ ctx.panel.artifactFocus.value = { messageId: 'a', nonce: 1 }
+ await nextTick()
+ assert.equal(ctx.searchQuery.value, '')
+ assert.equal(ctx.visibleItems.value[0].messageId, 'a')
+ ctx.props.sessionId = 'session-b'
+ await nextTick()
+ assert.equal(ctx.scope.value, 'all')
+ assert.equal(ctx.panel.artifactFocus.value, null)
+})
+
+test('preview returns to the selected scope and search', async (t) => {
+ const ctx = setupFilters(t)
+ ctx.panel.artifactFocus.value = { messageId: 'b', nonce: 1 }
+ await nextTick()
+ ctx.searchQuery.value = 'png'
+ ctx.openPreview(ctx.visibleItems.value[0])
+ assert.equal(ctx.previewItem.value.messageId, 'b')
+ assert.equal(ctx.previewItem.value.index, 7)
+ ctx.closePreview()
+ assert.equal(ctx.scope.value, 'current')
+ assert.equal(ctx.searchQuery.value, 'png')
+ assert.equal(ctx.visibleItems.value.length, 1)
+})
diff --git a/frontend/src/views/chat/components/ChatArtifactsPanel.vue b/frontend/src/views/chat/components/ChatArtifactsPanel.vue
index 59c1bfe98..ae493864f 100644
--- a/frontend/src/views/chat/components/ChatArtifactsPanel.vue
+++ b/frontend/src/views/chat/components/ChatArtifactsPanel.vue
@@ -14,9 +14,7 @@
<t-icon name="chevron-left" size="18px" />
</template>
</t-button>
- <div class="artifact-panel-header-icon">
- <t-icon :name="getFileIcon(previewItem.file_name)" />
- </div>
+ <ArtifactFileIcon class="artifact-panel-header-icon" :file-name="previewItem.file_name" />
<div class="artifact-panel-header-title" :title="previewItem.file_name">{{ previewItem.file_name }}</div>
<t-button
class="artifact-download"
@@ -24,6 +22,7 @@
shape="square"
size="small"
:title="$t('agent.artifactDrawer.download')"
+ :aria-label="$t('agent.artifactDrawer.download')"
:loading="isDownloading(previewItem)"
@click="handleDownload(previewItem)"
>
@@ -54,49 +53,67 @@
<span>{{ $t('chat.sandbox.artifactsEmpty') }}</span>
</div>
<template v-else>
+ <div class="artifact-filters">
+ <div class="artifact-scope" role="group" :aria-label="$t('chat.sandbox.artifactScope')">
+ <button
+ v-if="focusedMessageId"
+ type="button"
+ :aria-pressed="scope === 'current'"
+ @click="scope = 'current'"
+ >
+ {{ $t('chat.sandbox.artifactsCurrent') }}
+ <span>{{ currentItems.length }}</span>
+ </button>
+ <button type="button" :aria-pressed="scope === 'all'" @click="scope = 'all'">
+ {{ $t('chat.sandbox.artifactsAll') }}
+ <span>{{ items.length }}</span>
+ </button>
+ </div>
+ <t-input
+ v-model="searchQuery"
+ class="artifact-search"
+ :placeholder="$t('chat.sandbox.artifactsSearch')"
+ :aria-label="$t('chat.sandbox.artifactsSearch')"
+ clearable
+ >
+ <template #prefix-icon><t-icon name="search" size="16px" /></template>
+ </t-input>
+ </div>
<div v-if="collecting" class="artifact-panel-banner">
<t-icon name="loading" class="artifact-panel-banner-spin" />
<span>{{ $t('agent.artifactDrawer.collecting') }}</span>
</div>
- <ul ref="listRef" class="artifact-list">
+ <div v-if="!visibleItems.length" class="artifact-panel-empty">
+ <t-icon name="search" size="24px" />
+ <span>{{ $t('chat.sandbox.artifactsNoMatches') }}</span>
+ </div>
+ <ul v-show="visibleItems.length" ref="listRef" class="artifact-list">
<li
- v-for="item in items"
+ v-for="item in visibleItems"
:key="`${item.messageId}:${item.index}-${item.file_name}`"
class="artifact-item is-previewable"
- :class="{ 'is-focused': isFocused(item) }"
:data-message-id="item.messageId"
:data-artifact-index="item.index"
@click="openPreview(item)"
>
- <span class="artifact-icon">
- <t-icon :name="getFileIcon(item.file_name)" />
- </span>
- <div class="artifact-body">
- <div class="artifact-name" :title="item.file_name">{{ item.file_name }}</div>
- <div class="artifact-meta">
- <span>{{ formatArtifactSize(item.file_size) }}</span>
- <span class="artifact-meta-sep">·</span>
- <span>{{ formatArtifactDateTime(item.created_at) }}</span>
- </div>
- </div>
- <t-button
- class="artifact-preview-btn"
- variant="text"
- shape="square"
- size="small"
- :title="$t('agent.artifactDrawer.preview')"
- @click.stop="openPreview(item)"
- >
- <template #icon>
- <t-icon name="browse" size="16px" />
- </template>
- </t-button>
+ <button type="button" class="artifact-open" :title="$t('agent.artifactDrawer.preview')">
+ <ArtifactFileIcon :file-name="item.file_name" />
+ <span class="artifact-body">
+ <span class="artifact-name" :title="item.file_name">{{ item.file_name }}</span>
+ <span class="artifact-meta">
+ <span>{{ formatArtifactSize(item.file_size) }}</span>
+ <span class="artifact-meta-sep">·</span>
+ <span>{{ formatArtifactDateTime(item.created_at) }}</span>
+ </span>
+ </span>
+ </button>
<t-button
class="artifact-download"
variant="text"
shape="square"
size="small"
:title="$t('agent.artifactDrawer.download')"
+ :aria-label="$t('agent.artifactDrawer.download')"
:loading="isDownloading(item)"
@click.stop="handleDownload(item)"
>
@@ -115,7 +132,6 @@ import { computed, nextTick, reactive, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { MessagePlugin } from 'tdesign-vue-next'
import { downloadArtifact } from '@/api/chat'
-import { getFileIcon } from '@/utils/files'
import { resolveFilePreviewExt } from '@/utils/filePreview'
import {
formatArtifactDateTime,
@@ -124,6 +140,7 @@ import {
} from '@/utils/sessionArtifacts'
import { useChatSandboxPanel, type ArtifactPanelFocusState } from '@/composables/useChatSandboxPanel'
import DocumentPreview from '@/components/document-preview.vue'
+import ArtifactFileIcon from './ArtifactFileIcon.vue'
const props = withDefaults(
defineProps<{
@@ -144,6 +161,14 @@ const listRef = ref<HTMLElement | null>(null)
const previewItem = ref<SessionArtifactItem | null>(null)
const downloading = reactive<Record<string, boolean>>({})
const focusedMessageId = ref<string | null>(null)
+const scope = ref<'current' | 'all'>('all')
+const searchQuery = ref('')
+const currentItems = computed(() => props.items.filter((item) => item.messageId === focusedMessageId.value))
+const visibleItems = computed(() => {
+ const items = scope.value === 'current' ? currentItems.value : props.items
+ const query = searchQuery.value.trim().toLocaleLowerCase()
+ return query ? items.filter((item) => item.file_name.toLocaleLowerCase().includes(query)) : items
+})
const previewFileType = computed(() => {
const item = previewItem.value
@@ -159,10 +184,6 @@ function isDownloading(item: SessionArtifactItem): boolean {
return !!downloading[downloadKey(item)]
}
-function isFocused(item: SessionArtifactItem): boolean {
- return !!focusedMessageId.value && item.messageId === focusedMessageId.value
-}
-
function findItem(messageId: string, previewIndex?: number | null): SessionArtifactItem | undefined {
if (previewIndex != null && Number.isInteger(previewIndex)) {
return props.items.find((item) => item.messageId === messageId && item.index === previewIndex)
@@ -181,11 +202,24 @@ function applyFocus(focus: ArtifactPanelFocusState | null | undefined) {
}
previewItem.value = null
void nextTick(() => {
- const rows = listRef.value?.querySelectorAll<HTMLElement>('[data-message-id]')
- if (!rows) return
+ const container = listRef.value
+ if (!container) return
+ const rows = container.querySelectorAll<HTMLElement>('[data-message-id]')
for (const row of rows) {
if (row.getAttribute('data-message-id') === focus.messageId) {
- row.scrollIntoView({ block: 'nearest' })
+ // Keep positioning inside the list: scrollIntoView can also scroll the
+ // outer page horizontally while the fixed panel is sliding into view.
+ const itemRect = row.getBoundingClientRect()
+ const containerRect = container.getBoundingClientRect()
+ let nextTop: number | null = null
+ if (itemRect.top < containerRect.top) {
+ nextTop = container.scrollTop + itemRect.top - containerRect.top
+ } else if (itemRect.bottom > containerRect.bottom) {
+ nextTop = container.scrollTop + itemRect.bottom - containerRect.bottom
+ }
+ if (nextTop !== null) {
+ container.scrollTo({ top: Math.max(0, nextTop), behavior: 'instant' })
+ }
break
}
}
@@ -194,7 +228,11 @@ function applyFocus(focus: ArtifactPanelFocusState | null | undefined) {
watch(
() => panel?.artifactFocus.value,
- (focus) => applyFocus(focus),
+ (focus) => {
+ scope.value = focus?.messageId ? 'current' : 'all'
+ searchQuery.value = ''
+ applyFocus(focus)
+ },
{ immediate: true },
)
@@ -203,6 +241,8 @@ watch(
() => {
previewItem.value = null
focusedMessageId.value = null
+ scope.value = 'all'
+ searchQuery.value = ''
panel?.clearArtifactFocus()
},
)
@@ -218,7 +258,9 @@ watch(
if (!next) previewItem.value = null
return
}
- applyFocus(panel?.artifactFocus.value)
+ if (scope.value === 'current' && !searchQuery.value.trim()) {
+ applyFocus(panel?.artifactFocus.value)
+ }
},
)
@@ -286,16 +328,8 @@ async function handleDownload(item: SessionArtifactItem) {
}
.artifact-panel-header-icon {
- flex-shrink: 0;
- width: 28px;
- height: 28px;
- border-radius: 8px;
- display: flex;
- align-items: center;
- justify-content: center;
- background: rgba(7, 192, 95, 0.1);
- color: var(--td-brand-color);
- font-size: 15px;
+ width: 26px;
+ height: 32px;
}
.artifact-panel-header-title {
@@ -353,7 +387,7 @@ async function handleDownload(item: SessionArtifactItem) {
.artifact-list {
margin: 0;
- padding: 4px 8px 12px;
+ padding: 0 4px 12px;
list-style: none;
overflow: auto;
flex: 1;
@@ -363,15 +397,10 @@ async function handleDownload(item: SessionArtifactItem) {
.artifact-item {
display: flex;
align-items: center;
- gap: 10px;
- padding: 10px 6px;
- border-bottom: 1px solid var(--td-component-stroke);
+ gap: 12px;
+ padding: 12px 8px;
border-radius: 8px;
- &:last-child {
- border-bottom: none;
- }
-
&.is-previewable {
cursor: pointer;
}
@@ -380,27 +409,58 @@ async function handleDownload(item: SessionArtifactItem) {
background: var(--td-bg-color-container-hover);
}
- &:hover .artifact-icon {
- color: var(--td-brand-color);
- }
-
- &.is-focused {
- background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
- }
}
-.artifact-icon {
+.artifact-filters {
flex-shrink: 0;
- width: 28px;
- height: 28px;
- border-radius: 6px;
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ padding: 16px 12px 12px;
+}
+
+.artifact-scope {
display: inline-flex;
- align-items: center;
- justify-content: center;
- font-size: 16px;
+ align-self: flex-start;
+ gap: 2px;
+ padding: 3px;
+ border-radius: 8px;
background: var(--td-bg-color-secondarycontainer);
- color: var(--td-text-color-secondary);
- transition: color 0.15s ease;
+
+ button {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ padding: 5px 10px;
+ border: 0;
+ border-radius: 5px;
+ background: transparent;
+ color: var(--td-text-color-secondary);
+ font: inherit;
+ font-size: 12px;
+ cursor: pointer;
+
+ &[aria-pressed='true'] {
+ background: var(--td-bg-color-container);
+ color: var(--td-text-color-primary);
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--td-brand-color);
+ outline-offset: 2px;
+ }
+
+ span {
+ color: var(--td-text-color-placeholder);
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ }
+ }
+}
+
+.artifact-search :deep(.t-input) {
+ border-radius: 7px;
}
.artifact-body {
@@ -408,9 +468,31 @@ async function handleDownload(item: SessionArtifactItem) {
min-width: 0;
}
+.artifact-open {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 0;
+ border: 0;
+ border-radius: 4px;
+ background: transparent;
+ color: inherit;
+ font: inherit;
+ text-align: left;
+ cursor: pointer;
+
+ &:focus-visible {
+ outline: 2px solid var(--td-text-color-secondary);
+ outline-offset: 4px;
+ }
+}
+
.artifact-name {
+ display: block;
font-size: 13px;
- font-weight: 600;
+ font-weight: 500;
letter-spacing: 0.01em;
line-height: 1.35;
color: var(--td-text-color-primary);
@@ -433,10 +515,27 @@ async function handleDownload(item: SessionArtifactItem) {
opacity: 0.6;
}
-.artifact-preview-btn,
-.artifact-download {
+.artifact-download.t-button {
flex-shrink: 0;
+ width: 30px;
+ height: 30px;
+ border-radius: 7px;
color: var(--td-text-color-secondary);
+ transition: background-color 0.15s ease, color 0.15s ease;
+
+ &:not(.t-is-disabled):not(.t-is-loading):hover {
+ background: color-mix(in srgb, var(--td-text-color-primary) 10%, var(--td-bg-color-container));
+ color: var(--td-text-color-primary);
+ }
+
+ &:not(.t-is-disabled):not(.t-is-loading):active {
+ background: color-mix(in srgb, var(--td-text-color-primary) 16%, var(--td-bg-color-container));
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--td-text-color-secondary);
+ outline-offset: 2px;
+ }
:deep(.t-button__icon) {
margin: 0;
diff --git a/frontend/src/views/chat/components/botmsg.vue b/frontend/src/views/chat/components/botmsg.vue
index 529f3fbb8..245263a4e 100644
--- a/frontend/src/views/chat/components/botmsg.vue
+++ b/frontend/src/views/chat/components/botmsg.vue
@@ -243,10 +243,14 @@ const artifactPreviewIndex = ref(null);
function openArtifactDrawer(previewIndex = null) {
if (!hasArtifacts.value) return;
if (sandboxPanel && !props.embeddedMode) {
- sandboxPanel.open('artifacts', {
- messageId: messageIdForArtifacts.value,
- previewIndex,
- });
+ if (previewIndex == null) {
+ sandboxPanel.toggleArtifacts(messageIdForArtifacts.value);
+ } else {
+ sandboxPanel.open('artifacts', {
+ messageId: messageIdForArtifacts.value,
+ previewIndex,
+ });
+ }
return;
}
artifactPreviewIndex.value = previewIndex;