fix(ui): avoid truncating workspace paths in assistant text (#14584)
This commit is contained in:
@@ -145,17 +145,22 @@ function createThrottledValue(getValue: () => string) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativizeProjectPaths(text: string, directory?: string) {
|
function relativizeProjectPath(path: string, directory?: string) {
|
||||||
if (!text) return ""
|
if (!path) return ""
|
||||||
if (!directory) return text
|
if (!directory) return path
|
||||||
if (directory === "/") return text
|
if (directory === "/") return path
|
||||||
if (directory === "\\") return text
|
if (directory === "\\") return path
|
||||||
return text.split(directory).join("")
|
if (path === directory) return ""
|
||||||
|
|
||||||
|
const separator = directory.includes("\\") ? "\\" : "/"
|
||||||
|
const prefix = directory.endsWith(separator) ? directory : directory + separator
|
||||||
|
if (!path.startsWith(prefix)) return path
|
||||||
|
return path.slice(directory.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDirectory(path: string | undefined) {
|
function getDirectory(path: string | undefined) {
|
||||||
const data = useData()
|
const data = useData()
|
||||||
return relativizeProjectPaths(_getDirectory(path), data.directory)
|
return relativizeProjectPath(_getDirectory(path), data.directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
import type { IconProps } from "./icon"
|
import type { IconProps } from "./icon"
|
||||||
@@ -1066,7 +1071,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
|
|||||||
return items.filter((x) => !!x).join(" \u00B7 ")
|
return items.filter((x) => !!x).join(" \u00B7 ")
|
||||||
})
|
})
|
||||||
|
|
||||||
const displayText = () => relativizeProjectPaths((part.text ?? "").trim(), data.directory)
|
const displayText = () => (part.text ?? "").trim()
|
||||||
const throttledText = createThrottledValue(displayText)
|
const throttledText = createThrottledValue(displayText)
|
||||||
const isLastTextPart = createMemo(() => {
|
const isLastTextPart = createMemo(() => {
|
||||||
const last = (data.store.part?.[props.message.id] ?? [])
|
const last = (data.store.part?.[props.message.id] ?? [])
|
||||||
@@ -1168,7 +1173,7 @@ ToolRegistry.register({
|
|||||||
<div data-component="tool-loaded-file">
|
<div data-component="tool-loaded-file">
|
||||||
<Icon name="enter" size="small" />
|
<Icon name="enter" size="small" />
|
||||||
<span>
|
<span>
|
||||||
{i18n.t("ui.tool.loaded")} {relativizeProjectPaths(filepath, data.directory)}
|
{i18n.t("ui.tool.loaded")} {relativizeProjectPath(filepath, data.directory)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user