fix: 修复 .gitignore 未锚定目录规则误伤源码(幽灵bug)
deploy-hxtesting / build-and-deploy (push) Successful in 1m52s
deploy-hxtesting / build-and-deploy (push) Successful in 1m52s
- artifacts/ 等未锚定规则会命中任意层级同名目录,导致 frontend/src/views/artifacts/ArtifactLibrary.vue(路由动态导入)、 cli/internal/build/(cli 模块源码)、cmd/desktop/build/(桌面构建资产) 从未入库——本机正常、他人克隆后构建必挂 - 修复: 锚定仓库根 /artifacts/ /dist/ /build/ /tmp/ /temp/ /logs/;补 frontend/dist/ - 找回 6 个被吞文件;顺带清理改名产生的重复规则行
This commit is contained in:
1 parent
04e93935a5
commit
746ecfaa34
7 files changed
+1021
-11
No files matched your search
+8
-11
@@ -6,7 +6,6 @@
|
||||
!.gitignore
|
||||
!.gitattributes
|
||||
!.github/
|
||||
!.gitea/
|
||||
!.dockerignore
|
||||
!.golangci.yml
|
||||
!.air.toml
|
||||
@@ -23,22 +22,22 @@
|
||||
*.swo
|
||||
|
||||
# 构建和依赖文件
|
||||
# 注意:目录规则锚定仓库根(/dist/),避免误伤源码目录(如 frontend/src/views/artifacts/)
|
||||
node_modules/
|
||||
dist/
|
||||
build/
|
||||
/dist/
|
||||
frontend/dist/
|
||||
/build/
|
||||
*.log
|
||||
|
||||
# 临时文件
|
||||
tmp/
|
||||
temp/
|
||||
logs/
|
||||
/tmp/
|
||||
/temp/
|
||||
/logs/
|
||||
*.pid
|
||||
|
||||
# 本机构建产物(不入库;仅限仓库根目录,勿误伤 frontend/src/views/artifacts/ 等源码目录)
|
||||
# 本机构建产物(不入库)
|
||||
/artifacts/
|
||||
Academy
|
||||
Academy
|
||||
Academy-lite
|
||||
Academy-lite
|
||||
cmd/desktop/build/bin/
|
||||
/models/
|
||||
@@ -57,7 +56,6 @@ web/
|
||||
frontend/.vite
|
||||
frontend/chrome-extension/
|
||||
Academy-Chrome-Extension
|
||||
Academy-Chrome-Extension
|
||||
packages/protoc-3.19.4-linux-x86_64.zip
|
||||
|
||||
Claude.md
|
||||
@@ -71,7 +69,6 @@ miniprogram/project.private.config.json
|
||||
|
||||
# Staging dir for the Docker sandbox self-check probe (removed after each run)
|
||||
.academy-sandbox-check-*
|
||||
.academy-sandbox-check-*
|
||||
|
||||
# Locally built BrowserSkill runtime and extension bundles
|
||||
/artifacts/browserskill/
|
||||
@@ -0,0 +1,16 @@
|
||||
// Package build holds compile-time-injected build metadata.
|
||||
//
|
||||
// Values are set via -ldflags="-X github.com/Tencent/WeKnora/cli/internal/build.Version=..." at link time;
|
||||
// the Makefile's `version` target wires them up.
|
||||
package build
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
Commit = "none"
|
||||
Date = "unknown"
|
||||
)
|
||||
|
||||
// Info returns a snapshot of the build metadata.
|
||||
func Info() (version, commit, date string) {
|
||||
return Version, Commit, Date
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInfo_DefaultDevValues(t *testing.T) {
|
||||
v, c, d := Info()
|
||||
// In a non-ldflags-injected build, these are the package defaults; tests
|
||||
// that vary them need to assign at run time, not via -ldflags (testing
|
||||
// here only that Info returns whatever is current).
|
||||
assert.NotEmpty(t, v)
|
||||
assert.NotEmpty(t, c)
|
||||
assert.NotEmpty(t, d)
|
||||
}
|
||||
|
||||
func TestInfo_ReflectsInjectedValues(t *testing.T) {
|
||||
old := Version
|
||||
t.Cleanup(func() { Version = old })
|
||||
Version = "v0.0.0-test"
|
||||
v, _, _ := Info()
|
||||
assert.Equal(t, "v0.0.0-test", v)
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>{{.Info.ProductName}}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{.OutputFilename}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{.Name}}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>{{.Info.Comments}}</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>iconfile</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.13.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>{{.Info.Copyright}}</string>
|
||||
{{if .Info.FileAssociations}}
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
{{range .Info.FileAssociations}}
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>{{.Ext}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>{{.Name}}</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>{{.IconName}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
{{if .Info.Protocols}}
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
{{range .Info.Protocols}}
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>com.wails.{{.Scheme}}</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>{{.Scheme}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,123 @@
|
||||
; Based on the Wails v2.12.0 default installer (MIT).
|
||||
; See licenses/Wails-MIT.txt. Local change: install the notice/source bundle.
|
||||
Unicode true
|
||||
|
||||
####
|
||||
## Please note: Template replacements don't work in this file. They are provided with default defines like
|
||||
## mentioned underneath.
|
||||
## If the keyword is not defined, "wails_tools.nsh" will populate them with the values from ProjectInfo.
|
||||
## If they are defined here, "wails_tools.nsh" will not touch them. This allows to use this project.nsi manually
|
||||
## from outside of Wails for debugging and development of the installer.
|
||||
##
|
||||
## For development first make a wails nsis build to populate the "wails_tools.nsh":
|
||||
## > wails build --target windows/amd64 --nsis
|
||||
## Then you can call makensis on this file with specifying the path to your binary:
|
||||
## For a AMD64 only installer:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app.exe
|
||||
## For a ARM64 only installer:
|
||||
## > makensis -DARG_WAILS_ARM64_BINARY=..\..\bin\app.exe
|
||||
## For a installer with both architectures:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app-amd64.exe -DARG_WAILS_ARM64_BINARY=..\..\bin\app-arm64.exe
|
||||
####
|
||||
## The following information is taken from the ProjectInfo file, but they can be overwritten here.
|
||||
####
|
||||
## !define INFO_PROJECTNAME "MyProject" # Default "{{.Name}}"
|
||||
## !define INFO_COMPANYNAME "MyCompany" # Default "{{.Info.CompanyName}}"
|
||||
## !define INFO_PRODUCTNAME "MyProduct" # Default "{{.Info.ProductName}}"
|
||||
## !define INFO_PRODUCTVERSION "1.0.0" # Default "{{.Info.ProductVersion}}"
|
||||
## !define INFO_COPYRIGHT "Copyright" # Default "{{.Info.Copyright}}"
|
||||
###
|
||||
## !define PRODUCT_EXECUTABLE "Application.exe" # Default "${INFO_PROJECTNAME}.exe"
|
||||
## !define UNINST_KEY_NAME "UninstKeyInRegistry" # Default "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
|
||||
####
|
||||
## !define REQUEST_EXECUTION_LEVEL "admin" # Default "admin" see also https://nsis.sourceforge.io/Docs/Chapter4.html
|
||||
####
|
||||
## Include the wails tools
|
||||
####
|
||||
!include "wails_tools.nsh"
|
||||
|
||||
# The version information for this two must consist of 4 parts
|
||||
VIProductVersion "${INFO_PRODUCTVERSION}.0"
|
||||
VIFileVersion "${INFO_PRODUCTVERSION}.0"
|
||||
|
||||
VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}"
|
||||
VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer"
|
||||
VIAddVersionKey "ProductVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "FileVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "LegalCopyright" "${INFO_COPYRIGHT}"
|
||||
VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
|
||||
|
||||
# Enable HiDPI support. https://nsis.sourceforge.io/Reference/ManifestDPIAware
|
||||
ManifestDPIAware true
|
||||
|
||||
!include "MUI.nsh"
|
||||
|
||||
!define MUI_ICON "..\icon.ico"
|
||||
!define MUI_UNICON "..\icon.ico"
|
||||
# !define MUI_WELCOMEFINISHPAGE_BITMAP "resources\leftimage.bmp" #Include this to add a bitmap on the left side of the Welcome Page. Must be a size of 164x314
|
||||
!define MUI_FINISHPAGE_NOAUTOCLOSE # Wait on the INSTFILES page so the user can take a look into the details of the installation steps
|
||||
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
|
||||
# !insertmacro MUI_PAGE_LICENSE "resources\eula.txt" # Adds a EULA page to the installer
|
||||
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
|
||||
!insertmacro MUI_PAGE_INSTFILES # Installing page.
|
||||
!insertmacro MUI_PAGE_FINISH # Finished installation page.
|
||||
|
||||
!insertmacro MUI_UNPAGE_INSTFILES # Uinstalling page
|
||||
|
||||
!insertmacro MUI_LANGUAGE "English" # Set the Language of the installer
|
||||
|
||||
## The following two statements can be used to sign the installer and the uninstaller. The path to the binaries are provided in %1
|
||||
#!uninstfinalize 'signtool --file "%1"'
|
||||
#!finalize 'signtool --file "%1"'
|
||||
|
||||
Name "${INFO_PRODUCTNAME}"
|
||||
OutFile "..\..\bin\${INFO_PROJECTNAME}-${ARCH}-installer.exe" # Name of the installer's file.
|
||||
InstallDir "$PROGRAMFILES64\${INFO_COMPANYNAME}\${INFO_PRODUCTNAME}" # Default installing folder ($PROGRAMFILES is Program Files folder).
|
||||
ShowInstDetails show # This will always show the installation details.
|
||||
|
||||
Function .onInit
|
||||
!insertmacro wails.checkArchitecture
|
||||
FunctionEnd
|
||||
|
||||
Section
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
!insertmacro wails.webview2runtime
|
||||
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
!insertmacro wails.files
|
||||
|
||||
; Paths are relative to cmd/desktop/build/windows/installer.
|
||||
File "..\..\..\..\..\LICENSE"
|
||||
File "..\..\..\..\..\THIRD_PARTY_NOTICES.md"
|
||||
SetOutPath "$INSTDIR\licenses"
|
||||
File /r "..\..\..\..\..\licenses\*"
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
CreateShortcut "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
|
||||
!insertmacro wails.associateFiles
|
||||
!insertmacro wails.associateCustomProtocols
|
||||
|
||||
!insertmacro wails.writeUninstaller
|
||||
SectionEnd
|
||||
|
||||
Section "uninstall"
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
RMDir /r "$AppData\${PRODUCT_EXECUTABLE}" # Remove the WebView2 DataPath
|
||||
|
||||
RMDir /r $INSTDIR
|
||||
|
||||
Delete "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk"
|
||||
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"
|
||||
|
||||
!insertmacro wails.unassociateFiles
|
||||
!insertmacro wails.unassociateCustomProtocols
|
||||
|
||||
!insertmacro wails.deleteUninstaller
|
||||
SectionEnd
|
||||
@@ -0,0 +1,786 @@
|
||||
<template>
|
||||
<div class="artifact-library">
|
||||
<div class="header" style="--wails-draggable: drag">
|
||||
<div class="header-title" style="--wails-draggable: drag">
|
||||
<h2 style="--wails-draggable: drag">
|
||||
<ResourceIcon type="artifact" :size="24" />
|
||||
{{ $t('artifactLibrary.title') }}
|
||||
</h2>
|
||||
<p class="header-subtitle" style="--wails-draggable: drag">{{ $t('artifactLibrary.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="category-tabs" role="tablist" :aria-label="$t('artifactLibrary.typeFilter')">
|
||||
<button
|
||||
v-for="c in ARTIFACT_CATEGORIES"
|
||||
:key="c"
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="category === c"
|
||||
@click="setCategory(c)"
|
||||
>
|
||||
{{ $t(`artifactLibrary.categories.${c}`) }}
|
||||
</button>
|
||||
</div>
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
class="search-input"
|
||||
:placeholder="$t('artifactLibrary.searchPlaceholder')"
|
||||
:aria-label="$t('artifactLibrary.searchPlaceholder')"
|
||||
clearable
|
||||
>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
</div>
|
||||
|
||||
<div ref="scrollRoot" class="library-main">
|
||||
<div v-if="loading && !items.length" class="artifact-rows">
|
||||
<div v-for="n in 6" :key="'skel-' + n" class="artifact-row is-skeleton">
|
||||
<t-skeleton animation="gradient" :row-col="[[{ width: '32px', height: '38px', type: 'rect' },
|
||||
{ width: '40%', height: '14px' }]]" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<EmptyState
|
||||
v-else-if="loadError && !items.length"
|
||||
icon="error-circle"
|
||||
:title="$t('artifactLibrary.loadFailed')"
|
||||
>
|
||||
<t-button variant="outline" @click="reload">{{ $t('artifactLibrary.retry') }}</t-button>
|
||||
</EmptyState>
|
||||
|
||||
<EmptyState
|
||||
v-else-if="!items.length && isFiltered"
|
||||
icon="search"
|
||||
:title="$t('artifactLibrary.noMatches.title')"
|
||||
:description="$t('artifactLibrary.noMatches.description')"
|
||||
>
|
||||
<t-button variant="outline" @click="clearFilters">{{ $t('artifactLibrary.clearFilters') }}</t-button>
|
||||
</EmptyState>
|
||||
|
||||
<EmptyState
|
||||
v-else-if="!items.length"
|
||||
icon="folder-open"
|
||||
:title="$t('artifactLibrary.empty.title')"
|
||||
:description="$t('artifactLibrary.empty.description')"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div class="result-count">{{ $t('artifactLibrary.total', { count: total }) }}</div>
|
||||
<section v-for="section in sections" :key="section.group" class="date-section">
|
||||
<h3 class="date-heading">{{ $t(`artifactLibrary.groups.${section.group}`) }}</h3>
|
||||
<ul class="artifact-rows">
|
||||
<li
|
||||
v-for="item in section.items"
|
||||
:key="`${item.message_id}:${item.index}`"
|
||||
class="artifact-row"
|
||||
@click="openPreview(item)"
|
||||
>
|
||||
<button type="button" class="artifact-open" :title="$t('artifactLibrary.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="meta-sep">·</span>
|
||||
<span>{{ formatArtifactDateTime(item.created_at) }}</span>
|
||||
<template v-if="item.version_count > 1">
|
||||
<span class="meta-sep">·</span>
|
||||
<span class="version-badge">
|
||||
{{ $t('artifactLibrary.versions', { count: item.version_count }) }}
|
||||
</span>
|
||||
</template>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="session-link"
|
||||
:title="$t('artifactLibrary.openSession')"
|
||||
@click.stop="openSession(item)"
|
||||
>
|
||||
<t-icon name="chat" size="14px" />
|
||||
<span>{{ item.session_title || $t('artifactLibrary.untitledSession') }}</span>
|
||||
</button>
|
||||
<t-button
|
||||
class="row-action"
|
||||
variant="text"
|
||||
shape="square"
|
||||
size="small"
|
||||
:title="$t('artifactLibrary.download')"
|
||||
:aria-label="$t('artifactLibrary.download')"
|
||||
:loading="isDownloading(item)"
|
||||
@click.stop="handleDownload(item)"
|
||||
>
|
||||
<template #icon><t-icon name="download" size="16px" /></template>
|
||||
</t-button>
|
||||
<t-button
|
||||
class="row-action row-action--danger"
|
||||
variant="text"
|
||||
shape="square"
|
||||
size="small"
|
||||
:title="$t('artifactLibrary.delete')"
|
||||
:aria-label="$t('artifactLibrary.delete')"
|
||||
:loading="isDeleting(item)"
|
||||
@click.stop="handleDelete(item)"
|
||||
>
|
||||
<template #icon><t-icon name="delete" size="16px" /></template>
|
||||
</t-button>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<div ref="sentinel" class="list-footer">
|
||||
<t-loading v-if="loading" size="small" />
|
||||
<t-button v-else-if="hasMore" variant="text" @click="loadMore">
|
||||
{{ $t('artifactLibrary.loadMore') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<t-drawer
|
||||
v-model:visible="previewVisible"
|
||||
class="artifact-library-preview"
|
||||
placement="right"
|
||||
size="min(880px, 92vw)"
|
||||
attach="body"
|
||||
:footer="false"
|
||||
:close-on-overlay-click="true"
|
||||
:close-on-esc-keydown="true"
|
||||
@closed="previewItem = null"
|
||||
>
|
||||
<template #header>
|
||||
<div v-if="previewItem" class="preview-header">
|
||||
<ArtifactFileIcon class="preview-header-icon" :file-name="previewItem.file_name" />
|
||||
<div class="preview-header-text">
|
||||
<div class="preview-header-title" :title="previewItem.file_name">{{ previewItem.file_name }}</div>
|
||||
<button type="button" class="session-link session-link--inline" @click="openSession(previewItem)">
|
||||
<t-icon name="chat" size="12px" />
|
||||
<span>{{ previewItem.session_title || $t('artifactLibrary.untitledSession') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div ref="previewActions" class="preview-actions" />
|
||||
<t-button
|
||||
class="row-action"
|
||||
variant="text"
|
||||
shape="square"
|
||||
size="small"
|
||||
:title="$t('artifactLibrary.download')"
|
||||
:aria-label="$t('artifactLibrary.download')"
|
||||
:loading="isDownloading(previewItem)"
|
||||
@click="handleDownload(previewItem)"
|
||||
>
|
||||
<template #icon><t-icon name="download" size="16px" /></template>
|
||||
</t-button>
|
||||
<t-button
|
||||
class="row-action row-action--danger"
|
||||
variant="text"
|
||||
shape="square"
|
||||
size="small"
|
||||
:title="$t('artifactLibrary.delete')"
|
||||
:aria-label="$t('artifactLibrary.delete')"
|
||||
:loading="isDeleting(previewItem)"
|
||||
@click="handleDelete(previewItem)"
|
||||
>
|
||||
<template #icon><t-icon name="delete" size="16px" /></template>
|
||||
</t-button>
|
||||
<t-button
|
||||
class="row-action"
|
||||
variant="text"
|
||||
shape="square"
|
||||
size="small"
|
||||
:title="$t('common.close')"
|
||||
:aria-label="$t('common.close')"
|
||||
@click="previewVisible = false"
|
||||
>
|
||||
<template #icon><t-icon name="close" size="16px" /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="previewItem" class="preview-body">
|
||||
<DocumentPreview
|
||||
:key="`${previewItem.message_id}:${previewItem.index}`"
|
||||
:toolbar-target="previewActions"
|
||||
:session-id="previewItem.session_id"
|
||||
:message-id="previewItem.message_id"
|
||||
:artifact-index="previewItem.index"
|
||||
:file-type="previewFileType"
|
||||
:file-name="previewItem.file_name"
|
||||
:active="previewVisible"
|
||||
fill-height
|
||||
/>
|
||||
</div>
|
||||
</t-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { downloadArtifact } from '@/api/chat'
|
||||
import { deleteArtifactLibraryItem, listArtifactLibrary, type ArtifactLibraryItem } from '@/api/artifacts'
|
||||
import {
|
||||
ARTIFACT_CATEGORIES,
|
||||
artifactCategoryExtensions,
|
||||
groupArtifactsByDate,
|
||||
parseArtifactCategory,
|
||||
type ArtifactCategory,
|
||||
} from '@/utils/artifactLibrary'
|
||||
import { formatArtifactDateTime, formatArtifactSize } from '@/utils/sessionArtifacts'
|
||||
import { resolveFilePreviewExt } from '@/utils/filePreview'
|
||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
|
||||
import DocumentPreview from '@/components/document-preview.vue'
|
||||
import ArtifactFileIcon from '@/views/chat/components/ArtifactFileIcon.vue'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
const SEARCH_DEBOUNCE_MS = 300
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const confirmDelete = useConfirmDelete()
|
||||
|
||||
const category = ref<ArtifactCategory>(parseArtifactCategory(route.query.type))
|
||||
const keyword = ref(typeof route.query.q === 'string' ? route.query.q : '')
|
||||
const items = ref<ArtifactLibraryItem[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(0)
|
||||
const loading = ref(false)
|
||||
const loadError = ref(false)
|
||||
const downloading = reactive<Record<string, boolean>>({})
|
||||
const deleting = reactive<Record<string, boolean>>({})
|
||||
const previewItem = ref<ArtifactLibraryItem | null>(null)
|
||||
const previewVisible = ref(false)
|
||||
const previewActions = ref<HTMLElement | null>(null)
|
||||
const scrollRoot = ref<HTMLElement | null>(null)
|
||||
const sentinel = ref<HTMLElement | null>(null)
|
||||
|
||||
const sections = computed(() => groupArtifactsByDate(items.value))
|
||||
const hasMore = computed(() => items.value.length < total.value)
|
||||
const isFiltered = computed(() => category.value !== 'all' || keyword.value.trim() !== '')
|
||||
const previewFileType = computed(() => {
|
||||
const item = previewItem.value
|
||||
return item ? resolveFilePreviewExt(item.file_name, item.file_type) : ''
|
||||
})
|
||||
|
||||
// Every fetch takes a ticket; a response whose ticket is stale (the filters
|
||||
// changed while it was in flight) is dropped.
|
||||
let ticket = 0
|
||||
|
||||
async function fetchPage(nextPage: number) {
|
||||
const mine = ++ticket
|
||||
loading.value = true
|
||||
loadError.value = false
|
||||
try {
|
||||
const res = await listArtifactLibrary({
|
||||
keyword: keyword.value,
|
||||
fileTypes: artifactCategoryExtensions(category.value),
|
||||
page: nextPage,
|
||||
pageSize: PAGE_SIZE,
|
||||
})
|
||||
if (mine !== ticket) return
|
||||
const rows = Array.isArray(res?.data) ? res.data : []
|
||||
// Deleting a row shifts every later row one page-offset earlier, so an
|
||||
// appended page can overlap what is already shown. Drop the repeats rather
|
||||
// than rendering an item twice under the same key.
|
||||
if (nextPage === 1) {
|
||||
items.value = rows
|
||||
} else {
|
||||
const shown = new Set(items.value.map(itemKey))
|
||||
items.value = [...items.value, ...rows.filter((row) => !shown.has(itemKey(row)))]
|
||||
}
|
||||
total.value = typeof res?.total === 'number' ? res.total : items.value.length
|
||||
page.value = nextPage
|
||||
} catch (err) {
|
||||
if (mine !== ticket) return
|
||||
console.error('[ArtifactLibrary] load failed:', err)
|
||||
loadError.value = true
|
||||
if (nextPage > 1) MessagePlugin.error(t('artifactLibrary.loadFailed'))
|
||||
} finally {
|
||||
if (mine === ticket) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function reload() {
|
||||
items.value = []
|
||||
total.value = 0
|
||||
page.value = 0
|
||||
void fetchPage(1)
|
||||
}
|
||||
|
||||
function loadMore() {
|
||||
if (loading.value || !hasMore.value) return
|
||||
// Page from how many rows are actually shown, not from the last page number:
|
||||
// after a delete those differ, and paging by number would skip a row.
|
||||
void fetchPage(Math.floor(items.value.length / PAGE_SIZE) + 1)
|
||||
}
|
||||
|
||||
function syncQuery() {
|
||||
const query = { ...route.query }
|
||||
if (category.value === 'all') delete query.type
|
||||
else query.type = category.value
|
||||
const q = keyword.value.trim()
|
||||
if (q) query.q = q
|
||||
else delete query.q
|
||||
void router.replace({ query })
|
||||
}
|
||||
|
||||
function setCategory(next: ArtifactCategory) {
|
||||
if (category.value === next) return
|
||||
category.value = next
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
category.value = 'all'
|
||||
keyword.value = ''
|
||||
}
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
watch(keyword, () => {
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(() => {
|
||||
searchTimer = null
|
||||
syncQuery()
|
||||
reload()
|
||||
}, SEARCH_DEBOUNCE_MS)
|
||||
})
|
||||
watch(category, () => {
|
||||
syncQuery()
|
||||
reload()
|
||||
})
|
||||
|
||||
function openPreview(item: ArtifactLibraryItem) {
|
||||
previewItem.value = item
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
function openSession(item: ArtifactLibraryItem) {
|
||||
previewVisible.value = false
|
||||
void router.push(`/platform/chat/${item.session_id}`)
|
||||
}
|
||||
|
||||
function itemKey(item: ArtifactLibraryItem) {
|
||||
return `${item.message_id}:${item.index}`
|
||||
}
|
||||
|
||||
function isDownloading(item: ArtifactLibraryItem) {
|
||||
return !!downloading[itemKey(item)]
|
||||
}
|
||||
|
||||
async function handleDownload(item: ArtifactLibraryItem) {
|
||||
const key = itemKey(item)
|
||||
if (downloading[key]) return
|
||||
downloading[key] = true
|
||||
try {
|
||||
const blob = await downloadArtifact(item.session_id, item.message_id, item.index)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = item.file_name || 'artifact'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
||||
} catch (err) {
|
||||
console.error('[ArtifactLibrary] download failed:', err)
|
||||
MessagePlugin.error(t('artifactLibrary.downloadFailed'))
|
||||
} finally {
|
||||
downloading[key] = false
|
||||
}
|
||||
}
|
||||
|
||||
function isDeleting(item: ArtifactLibraryItem) {
|
||||
return !!deleting[itemKey(item)]
|
||||
}
|
||||
|
||||
// A library row is the file, not one regeneration of it, so the confirmation
|
||||
// says how many versions go with it. The bytes are reclaimed server side, which
|
||||
// is why this asks at all.
|
||||
function handleDelete(item: ArtifactLibraryItem) {
|
||||
if (isDeleting(item)) return
|
||||
confirmDelete({
|
||||
title: t('artifactLibrary.deleteTitle'),
|
||||
body:
|
||||
item.version_count > 1
|
||||
? t('artifactLibrary.deleteConfirmVersions', { name: item.file_name, count: item.version_count })
|
||||
: t('artifactLibrary.deleteConfirm', { name: item.file_name }),
|
||||
onConfirm: () => performDelete(item),
|
||||
})
|
||||
}
|
||||
|
||||
async function performDelete(item: ArtifactLibraryItem) {
|
||||
const key = itemKey(item)
|
||||
if (deleting[key]) return
|
||||
deleting[key] = true
|
||||
try {
|
||||
await deleteArtifactLibraryItem(item)
|
||||
// Splice the row out instead of reloading: this is an infinite list, and a
|
||||
// reload would throw away everything the user has scrolled past.
|
||||
const at = items.value.findIndex((row) => itemKey(row) === key)
|
||||
if (at >= 0) {
|
||||
items.value.splice(at, 1)
|
||||
total.value = Math.max(0, total.value - 1)
|
||||
}
|
||||
if (previewItem.value && itemKey(previewItem.value) === key) previewVisible.value = false
|
||||
MessagePlugin.success(t('artifactLibrary.deleted'))
|
||||
} catch (err) {
|
||||
console.error('[ArtifactLibrary] delete failed:', err)
|
||||
MessagePlugin.error(t('artifactLibrary.deleteFailed'))
|
||||
} finally {
|
||||
deleting[key] = false
|
||||
}
|
||||
}
|
||||
|
||||
// Load the next page as the footer scrolls into view; the footer button
|
||||
// covers browsers without IntersectionObserver and failed auto-loads.
|
||||
let observer: IntersectionObserver | null = null
|
||||
watch(sentinel, (el, prev) => {
|
||||
if (prev) observer?.unobserve(prev)
|
||||
if (el) observer?.observe(el)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (typeof IntersectionObserver !== 'undefined') {
|
||||
observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries.some((e) => e.isIntersecting) && !loadError.value) loadMore()
|
||||
},
|
||||
{ root: scrollRoot.value, rootMargin: '200px' },
|
||||
)
|
||||
if (sentinel.value) observer.observe(sentinel.value)
|
||||
}
|
||||
void fetchPage(1)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
observer?.disconnect()
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
ticket++
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@import '@/components/css/artifact-filter-tabs.less';
|
||||
@import (reference) '@/components/css/resource-card.less';
|
||||
|
||||
.artifact-library { .resource-list-content(); }
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.header-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
color: var(--td-text-color-primary);
|
||||
font-family: var(--app-font-family);
|
||||
font-size: var(--app-text-4xl);
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
|
||||
.header-subtitle {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-base);
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--app-space-3);
|
||||
padding-bottom: var(--app-space-3);
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
}
|
||||
|
||||
// 与右侧 32px 的搜索框同高:3px 内边距 × 2 + 26px 按钮
|
||||
.category-tabs {
|
||||
.artifact-filter-tabs();
|
||||
button { display: inline-flex; align-items: center; height: 26px; padding: 0 12px; }
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 260px;
|
||||
max-width: 100%;
|
||||
:deep(.t-input) { border-radius: var(--app-radius-sm); }
|
||||
}
|
||||
|
||||
.library-main {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--app-space-3) 0 var(--app-space-6);
|
||||
}
|
||||
|
||||
.result-count {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
padding: 0 var(--app-space-2) var(--app-space-1);
|
||||
}
|
||||
|
||||
.date-section + .date-section {
|
||||
margin-top: var(--app-space-3);
|
||||
}
|
||||
|
||||
.date-heading {
|
||||
margin: 0;
|
||||
padding: var(--app-space-2) var(--app-space-2) var(--app-space-1);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.artifact-rows {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.artifact-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--app-space-3);
|
||||
padding: 10px var(--app-space-2);
|
||||
border-radius: var(--app-radius-md);
|
||||
cursor: pointer;
|
||||
transition: background var(--app-motion-fast) ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&.is-skeleton {
|
||||
cursor: default;
|
||||
|
||||
&:hover {
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.artifact-open {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--app-space-3);
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-text-color-secondary);
|
||||
outline-offset: 4px;
|
||||
border-radius: var(--app-radius-xs);
|
||||
}
|
||||
}
|
||||
|
||||
.artifact-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artifact-name {
|
||||
display: block;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-base);
|
||||
font-weight: 500;
|
||||
line-height: 1.4;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.artifact-meta {
|
||||
margin-top: 2px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--app-space-1);
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.meta-sep {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.version-badge {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.session-link {
|
||||
flex: 0 1 240px;
|
||||
min-width: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--app-space-1);
|
||||
padding: 4px 8px;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-sm);
|
||||
cursor: pointer;
|
||||
transition: background var(--app-motion-fast) ease, color var(--app-motion-fast) ease;
|
||||
|
||||
span {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.t-icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--td-brand-color);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
&--inline {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
padding: 0;
|
||||
margin-top: 2px;
|
||||
|
||||
&:hover {
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.row-action.t-button {
|
||||
flex-shrink: 0;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&: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);
|
||||
}
|
||||
|
||||
:deep(.t-button__icon) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&--danger:not(.t-is-disabled):not(.t-is-loading):hover {
|
||||
background: var(--td-error-color-1);
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.list-footer {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
min-height: 40px;
|
||||
padding-top: var(--app-space-3);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.artifact-library {
|
||||
margin: 0;
|
||||
padding: var(--app-space-4) var(--app-space-4) 0;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.session-link:not(.session-link--inline) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
.artifact-library-preview {
|
||||
.t-drawer__header {
|
||||
padding: 10px 16px;
|
||||
}
|
||||
|
||||
.t-drawer__body {
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.preview-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--app-space-2);
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.preview-header-icon {
|
||||
width: 26px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.preview-header-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.preview-header-title {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.preview-actions {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.preview-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user