fix(chat): hide raw permission metadata
This commit is contained in:
@@ -27,32 +27,6 @@ import VerifiedUserRounded from "@mui/icons-material/VerifiedUserRounded";
|
||||
import type { PermissionReply } from "@/lib/chatStream";
|
||||
import type { Message } from "./GlobalChatbox.types";
|
||||
|
||||
const formatMetadataValue = (value: unknown) => {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(value);
|
||||
} catch {
|
||||
return "[unserializable]";
|
||||
}
|
||||
};
|
||||
|
||||
const truncateText = (value: string, maxLength: number) =>
|
||||
value.length > maxLength ? `${value.slice(0, maxLength - 3)}...` : value;
|
||||
|
||||
const formatMetadata = (metadata: Record<string, unknown>) => {
|
||||
const entries = Object.entries(metadata)
|
||||
.filter(([key]) => !["command", "path", "file", "directory"].includes(key))
|
||||
.slice(0, 3);
|
||||
if (!entries.length) {
|
||||
return "";
|
||||
}
|
||||
return entries
|
||||
.map(([key, value]) => `${key}: ${truncateText(formatMetadataValue(value), 64)}`)
|
||||
.join(";");
|
||||
};
|
||||
|
||||
const getPermissionTitle = (permission: NonNullable<Message["permissions"]>[number]) => {
|
||||
if (permission.permission === "external_directory") return "访问工作区外目录";
|
||||
if (permission.permission === "bash") return "执行终端命令";
|
||||
@@ -63,15 +37,8 @@ const getPermissionTitle = (permission: NonNullable<Message["permissions"]>[numb
|
||||
const getPermissionPrimaryValue = (
|
||||
permission: NonNullable<Message["permissions"]>[number],
|
||||
) => {
|
||||
const command = permission.metadata.command;
|
||||
if (typeof command === "string" && command.trim()) {
|
||||
return command.trim();
|
||||
}
|
||||
for (const key of ["path", "file", "directory"]) {
|
||||
const value = permission.metadata[key];
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
return value.trim();
|
||||
}
|
||||
if (typeof permission.target === "string" && permission.target.trim()) {
|
||||
return permission.target.trim();
|
||||
}
|
||||
return permission.patterns[0] ?? permission.permission;
|
||||
};
|
||||
@@ -139,7 +106,6 @@ const PermissionRequestCard = ({
|
||||
isRunning && (permission.status === "pending" || permission.status === "error");
|
||||
const isSubmitting = isRunning && permission.status === "submitting";
|
||||
const primaryValue = getPermissionPrimaryValue(permission);
|
||||
const metadataText = formatMetadata(permission.metadata);
|
||||
const accentColor = getPermissionStatusColor(permission.status, theme);
|
||||
const statusTextColor = getPermissionStatusTextColor(permission.status, theme);
|
||||
const statusLabel = getPermissionStatusLabel(permission.status);
|
||||
@@ -237,12 +203,6 @@ const PermissionRequestCard = ({
|
||||
{primaryValue}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
{metadataText ? (
|
||||
<Typography variant="caption" color="text.secondary" sx={{ wordBreak: "break-word" }}>
|
||||
{metadataText}
|
||||
</Typography>
|
||||
) : null}
|
||||
</Stack>
|
||||
|
||||
{permission.error ? (
|
||||
|
||||
Reference in New Issue
Block a user