Skip to content

Commit

Permalink
Remove unwanted (large) keys when sharing feedback (All-Hands-AI#3766)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape authored Sep 6, 2024
1 parent c376b81 commit 8392a3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/modals/feedback/FeedbackModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Feedback, sendFeedback } from "#/services/feedbackService";
import toast from "#/utils/toast";
import { getToken } from "#/services/auth";
import Session from "#/services/session";
import { removeApiKey } from "#/utils/utils";
import { removeApiKey, removeUnwantedKeys } from "#/utils/utils";

const isEmailValid = (email: string) => {
// Regular expression to validate email format
Expand Down Expand Up @@ -95,7 +95,7 @@ function FeedbackModal({
email,
permissions,
token: getToken(),
trajectory: removeApiKey(Session._history),
trajectory: removeApiKey(removeUnwantedKeys(Session._history)),
};

try {
Expand Down
41 changes: 41 additions & 0 deletions frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,50 @@ interface EventActionHistory {
LLM_API_KEY?: string;
[key: string]: unknown;
};
extras?: {
open_page_urls: string[];
active_page_index: number;
dom_object: Record<string, unknown>;
axtree_object: Record<string, unknown>;
extra_element_properties: Record<string, unknown>;
last_browser_action: string;
last_browser_action_error: unknown;
focused_element_bid: string;
};
[key: string]: unknown;
}

export const removeUnwantedKeys = (
data: EventActionHistory[],
): EventActionHistory[] => {
const UNDESIRED_KEYS = [
"open_page_urls",
"active_page_index",
"dom_object",
"axtree_object",
"extra_element_properties",
"last_browser_action",
"last_browser_action_error",
"focused_element_bid",
];

return data.map((item) => {
// Create a shallow copy of item
const newItem = { ...item };

// Check if extras exists and delete it from a new extras object
if (newItem.extras) {
const newExtras = { ...newItem.extras };
UNDESIRED_KEYS.forEach((key) => {
delete newExtras[key as keyof typeof newExtras];
});
newItem.extras = newExtras;
}

return newItem;
});
};

export const removeApiKey = (
data: EventActionHistory[],
): EventActionHistory[] =>
Expand Down

0 comments on commit 8392a3f

Please sign in to comment.