AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
refactor(frontend): delete the functions nothing calls from the shared utility modules (#15929)
Reinier van der Leerd45dfe0a0311
diff --git a/.secrets.baseline b/.secrets.baselineindex 705ae50425..359933dbb2 100644--- a/.secrets.baseline+++ b/.secrets.baseline@@ -576,49 +576,49 @@"filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "9c486c92f1a7420e1045c7ad963fbb7ba3621025","is_verified": false,- "line_number": 73+ "line_number": 38},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "9277508c7a6effc8fb59163efbfada189e35425c","is_verified": false,- "line_number": 75+ "line_number": 40},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "8dc7e2cb1d0935897d541bf5facab389b8a50340","is_verified": false,- "line_number": 77+ "line_number": 42},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "79a26ad48775944299be6aaf9fb1d5302c1ed75b","is_verified": false,- "line_number": 79+ "line_number": 44},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "a3b62b44500a1612e48d4cab8294df81561b3b1a","is_verified": false,- "line_number": 81+ "line_number": 46},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "a58979bd0b21ef4f50417d001008e60dd7a85c64","is_verified": false,- "line_number": 83+ "line_number": 48},{"type": "Base64 High Entropy String","filename": "autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts","hashed_secret": "6cb6e075f8e8c7c850f9d128d6608e5dbe209a79","is_verified": false,- "line_number": 85+ "line_number": 50}],"autogpt_platform/frontend/src/lib/constants.ts": [diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/utils.tsindex 4c7e9b9bca..df829612ff 100644--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/utils.ts@@ -1,40 +1,5 @@-import { Connection } from "@xyflow/react";-import { Block, BlockUIType, Link } from "./types";import { Graph } from "@/app/api/__generated__/models/graph";-export function removeAgentInputBlockValues(graph: Graph, blocks: Block[]) {- const inputBlocks = graph.nodes?.filter(- (node) =>- blocks.find((b) => b.id === node.block_id)?.uiType === BlockUIType.INPUT,- );-- const modifiedNodes = graph.nodes?.map((node) => {- if (inputBlocks?.find((inputNode) => inputNode.id === node.id)) {- return {- ...node,- input_default: {- ...node.input_default,- value: "",- },- };- }- return node;- });-- return {- ...graph,- nodes: modifiedNodes,- };-}--export function formatEdgeID(conn: Link | Connection): string {- if ("sink_id" in conn) {- return `${conn.source_id}_${conn.source_name}_${conn.sink_id}_${conn.sink_name}`;- } else {- return `${conn.source}_${conn.sourceHandle}_${conn.target}_${conn.targetHandle}`;- }-}-/** Sanitizes a graph object in place so it can "safely" be imported into the system.** **⚠️ Note:** not an actual safety feature, just intended to make the import UX more reliable.diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.tsindex 3b88b5646c..030649e8f4 100644--- a/autogpt_platform/frontend/src/lib/utils.ts+++ b/autogpt_platform/frontend/src/lib/utils.ts@@ -6,7 +6,6 @@ import {BlockIOObjectSubSchema,BlockIORootSchema,BlockIOSubSchema,- Category,GraphInputSubSchema,GraphOutputSubSchema,} from "@/lib/autogpt-server-api/types";@@ -15,19 +14,6 @@ export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));}-/** Derived from https://stackoverflow.com/a/7616484 */-export function hashString(str: string): number {- let hash = 0,- chr: number;- if (str.length === 0) return hash;- for (let i = 0; i < str.length; i++) {- chr = str.charCodeAt(i);- hash = (hash << 5) - hash + chr;- hash |= 0; // Convert to 32bit integer- }- return hash;-}-/** Derived from https://stackoverflow.com/a/32922084 */export function deepEquals(x: any, y: any): boolean {const ok = (obj: any) => Object.keys(obj).filter((key) => obj[key] !== null),@@ -42,58 +28,6 @@ export function deepEquals(x: any, y: any): boolean {return res;}-/** Get tailwind text color class from type name */-export function getTypeTextColor(type: string | null): string {- if (type === null) return "text-gray-500";- return (- {- string: "text-green-500",- number: "text-blue-500",- integer: "text-blue-500",- boolean: "text-yellow-500",- object: "text-purple-500",- array: "text-indigo-500",- null: "text-gray-500",- any: "text-gray-500",- "": "text-gray-500",- }[type] || "text-gray-500"- );-}--/** Get tailwind bg color class from type name */-export function getTypeBgColor(type: string | null): string {- if (type === null) return "border-gray-500";- return (- {- string: "border-green-500",- number: "border-blue-500",- integer: "border-blue-500",- boolean: "border-yellow-500",- object: "border-purple-500",- array: "border-indigo-500",- null: "border-gray-500",- any: "border-gray-500",- "": "border-gray-500",- }[type] || "border-gray-500"- );-}--export function getTypeColor(type: string | undefined): string {- if (!type) return "#6b7280";- return (- {- string: "#22c55e",- number: "#3b82f6",- integer: "#3b82f6",- boolean: "#eab308",- object: "#a855f7",- array: "#6366f1",- null: "#6b7280",- any: "#6b7280",- }[type] || "#6b7280"- );-}-/*** Extracts the effective type from a JSON schema, handling anyOf/oneOf/allOf wrappers.* Returns the first non-null type found in the schema structure.@@ -331,28 +265,6 @@ export function fillObjectDefaultsFromSchema(return obj;}-export const categoryColorMap: Record<string, string> = {- AI: "bg-orange-300 dark:bg-orange-700",- SOCIAL: "bg-yellow-300 dark:bg-yellow-700",- TEXT: "bg-green-300 dark:bg-green-700",- SEARCH: "bg-blue-300 dark:bg-blue-700",- BASIC: "bg-purple-300 dark:bg-purple-700",- INPUT: "bg-cyan-300 dark:bg-cyan-700",- OUTPUT: "bg-red-300 dark:bg-red-700",- LOGIC: "bg-teal-300 dark:bg-teal-700",- DEVELOPER_TOOLS: "bg-fuchsia-300 dark:bg-fuchsia-700",- AGENT: "bg-lime-300 dark:bg-lime-700",-};--export function getPrimaryCategoryColor(categories: Category[]): string {- if (categories.length === 0) {- return "bg-gray-300 dark:bg-slate-700";- }- return (- categoryColorMap[categories[0].category] || "bg-gray-300 dark:bg-slate-700"- );-}-export function hasNonNullNonObjectValue(obj: any): boolean {if (obj !== null && typeof obj === "object") {return Object.values(obj).some((value) => hasNonNullNonObjectValue(value));@@ -361,56 +273,6 @@ export function hasNonNullNonObjectValue(obj: any): boolean {}}-type ParsedKey = { key: string; index?: number };--export function parseKeys(key: string): ParsedKey[] {- const splits = key.split(/_@_|_#_|_\$_|\./);- const keys: ParsedKey[] = [];- let currentKey: string | null = null;-- splits.forEach((split) => {- const isInteger = /^\d+$/.test(split);- if (!isInteger) {- if (currentKey !== null) {- keys.push({ key: currentKey });- }- currentKey = split;- } else {- if (currentKey !== null) {- keys.push({ key: currentKey, index: parseInt(split, 10) });- currentKey = null;- } else {- throw new Error("Invalid key format: array index without a key");- }- }- });-- if (currentKey !== null) {- keys.push({ key: currentKey });- }-- return keys;-}--/**- * Get the value of a nested key in an object, handles arrays and objects.- */-export function getValue(key: string, value: any) {- const keys = parseKeys(key);- return keys.reduce((acc, k) => {- if (acc === undefined) return undefined;- if (k.index !== undefined) {- return Array.isArray(acc[k.key]) ? acc[k.key][k.index] : undefined;- }- return acc[k.key];- }, value);-}--/** Check if a string is empty or whitespace */-export function isEmptyOrWhitespace(str: string | undefined | null): boolean {- return !str || str.trim().length === 0;-}-export function isEmpty(value: any): boolean {return (value === undefined ||@@ -421,11 +283,6 @@ export function isEmpty(value: any): boolean {);}-/** Check if a value is an object or not */-export function isObject(value: unknown): value is Record<string, unknown> {- return typeof value === "object" && value !== null && !Array.isArray(value);-}-/** Validate YouTube URL */export function validateYouTubeUrl(val: string): boolean {if (!val) return true;diff --git a/autogpt_platform/frontend/src/playwright/utils/assertion.ts b/autogpt_platform/frontend/src/playwright/utils/assertion.tsindex 272792e1a5..c11a068a48 100644--- a/autogpt_platform/frontend/src/playwright/utils/assertion.ts+++ b/autogpt_platform/frontend/src/playwright/utils/assertion.ts@@ -1,55 +1,5 @@-import { Locator, Page, expect } from "@playwright/test";+import { Locator, expect } from "@playwright/test";export async function isVisible(el: Locator, timeout?: number) {await expect(el).toBeVisible(timeout ? { timeout } : undefined);}--export async function hasAttribute(- el: Locator,- label: string,- val: string | RegExp,-) {- await expect(el).toHaveAttribute(label, val);-}--export async function hasTextContent(el: Locator, text: string | RegExp) {- await expect(el).toContainText(text);-}--export async function isHidden(el: Locator, timeout?: number) {- await expect(el).toBeHidden(timeout ? { timeout } : undefined);-}--export async function hasUrl(- page: Page,- url: string | RegExp,- opts?: { decoded?: boolean },-) {- if (opts?.decoded) {- return expect(decodeURIComponent(page.url())).toBe(url);- }-- await expect(page).toHaveURL(url);-}--export async function hasFieldValue(el: Locator, value: string | RegExp) {- await expect(el).toHaveValue(value);-}--export async function isDisabled(el: Locator) {- await expect(el).toBeDisabled();-}--export async function isEnabled(el: Locator) {- await expect(el).toBeEnabled();-}--export async function hasMinCount(el: Locator, minCount: number) {- await expect- .poll(async () => await el.count(), { timeout: 10000 })- .toBeGreaterThanOrEqual(minCount);-}--export async function matchesUrl(page: Page, pattern: RegExp) {- expect(page.url()).toMatch(pattern);-}