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 ? (
|
||||
|
||||
@@ -41,7 +41,7 @@ export type AgentPermissionRequest = {
|
||||
sessionId: string;
|
||||
permission: string;
|
||||
patterns: string[];
|
||||
metadata: Record<string, unknown>;
|
||||
target?: string;
|
||||
always: string[];
|
||||
tool?: {
|
||||
messageID: string;
|
||||
|
||||
@@ -88,7 +88,6 @@ export const cloneMessage = (message: Message): Message => ({
|
||||
? [...permission.patterns]
|
||||
: [],
|
||||
always: Array.isArray(permission.always) ? [...permission.always] : [],
|
||||
metadata: permission.metadata ?? {},
|
||||
}))
|
||||
: undefined,
|
||||
questions: normalizeQuestionRequests(message.questions),
|
||||
|
||||
@@ -115,7 +115,7 @@ export const upsertPermission = (
|
||||
sessionId: event.sessionId,
|
||||
permission: event.permission,
|
||||
patterns: event.patterns,
|
||||
metadata: event.metadata,
|
||||
target: event.target,
|
||||
always: event.always,
|
||||
tool: event.tool,
|
||||
createdAt: event.createdAt,
|
||||
|
||||
@@ -99,7 +99,7 @@ describe("useAgentChatSession actions", () => {
|
||||
requestId: "perm-1",
|
||||
permission: "bash",
|
||||
patterns: ["rm *"],
|
||||
metadata: { command: "rm tmp.txt" },
|
||||
target: "rm tmp.txt",
|
||||
always: ["rm *"],
|
||||
createdAt: 123,
|
||||
});
|
||||
@@ -163,7 +163,7 @@ describe("useAgentChatSession actions", () => {
|
||||
requestId: "perm-abort",
|
||||
permission: "bash",
|
||||
patterns: ["npm test"],
|
||||
metadata: { command: "npm test" },
|
||||
target: "npm test",
|
||||
always: ["npm test"],
|
||||
createdAt: 1002,
|
||||
} satisfies StreamEvent);
|
||||
|
||||
Reference in New Issue
Block a user