π OpenHands: AI-Driven Development
chore: remove unused utility functions (#560)
Hiep Le37d5c1dfa078
diff --git a/.pr/README.md b/.pr/README.mddeleted file mode 100644index cf36399c7b..0000000000--- a/.pr/README.md+++ /dev/null@@ -1,3 +0,0 @@-# PR Artifacts--This directory contains generated PR-only QA artifacts. The PR Artifacts workflow removes it after approval so these files do not enter the final squash merge.diff --git a/.pr/live-e2e/25966377319/live-agent-recording.gif b/.pr/live-e2e/25966377319/live-agent-recording.gifdeleted file mode 100644index e5a716910e..0000000000Binary files a/.pr/live-e2e/25966377319/live-agent-recording.gif and /dev/null differdiff --git a/.pr/live-e2e/25966377319/live-agent-recording.webm b/.pr/live-e2e/25966377319/live-agent-recording.webmdeleted file mode 100644index 475f43859c..0000000000Binary files a/.pr/live-e2e/25966377319/live-agent-recording.webm and /dev/null differdiff --git a/.pr/live-e2e/25966377319/live-agent-response.png b/.pr/live-e2e/25966377319/live-agent-response.pngdeleted file mode 100644index a41eba9250..0000000000Binary files a/.pr/live-e2e/25966377319/live-agent-response.png and /dev/null differdiff --git a/__tests__/parse-pr-url.test.ts b/__tests__/parse-pr-url.test.tsdeleted file mode 100644index 477a40c255..0000000000--- a/__tests__/parse-pr-url.test.ts+++ /dev/null@@ -1,142 +0,0 @@-import { describe, it, expect } from "vitest";-import {- extractPRUrls,- containsPRUrl,- getFirstPRUrl,-} from "#/utils/parse-pr-url";--describe("parse-pr-url", () => {- describe("extractPRUrls", () => {- it("should extract GitHub PR URLs", () => {- const text = "Check out this PR: https://github.com/owner/repo/pull/123";- const urls = extractPRUrls(text);- expect(urls).toEqual(["https://github.com/owner/repo/pull/123"]);- });-- it("should extract GitLab MR URLs", () => {- const text =- "Merge request: https://gitlab.com/owner/repo/-/merge_requests/456";- const urls = extractPRUrls(text);- expect(urls).toEqual([- "https://gitlab.com/owner/repo/-/merge_requests/456",- ]);- });-- it("should extract Bitbucket PR URLs", () => {- const text =- "PR link: https://bitbucket.org/owner/repo/pull-requests/789";- const urls = extractPRUrls(text);- expect(urls).toEqual([- "https://bitbucket.org/owner/repo/pull-requests/789",- ]);- });-- it("should extract Azure DevOps PR URLs", () => {- const text =- "Azure PR: https://dev.azure.com/org/project/_git/repo/pullrequest/101";- const urls = extractPRUrls(text);- expect(urls).toEqual([- "https://dev.azure.com/org/project/_git/repo/pullrequest/101",- ]);- });-- it("should extract multiple PR URLs", () => {- const text = `- GitHub: https://github.com/owner/repo/pull/123- GitLab: https://gitlab.com/owner/repo/-/merge_requests/456- `;- const urls = extractPRUrls(text);- expect(urls).toHaveLength(2);- expect(urls).toContain("https://github.com/owner/repo/pull/123");- expect(urls).toContain(- "https://gitlab.com/owner/repo/-/merge_requests/456",- );- });-- it("should handle self-hosted GitLab URLs", () => {- const text =- "Self-hosted: https://gitlab.example.com/owner/repo/-/merge_requests/123";- const urls = extractPRUrls(text);- expect(urls).toEqual([- "https://gitlab.example.com/owner/repo/-/merge_requests/123",- ]);- });-- it("should return empty array when no PR URLs found", () => {- const text = "This is just regular text with no PR URLs";- const urls = extractPRUrls(text);- expect(urls).toEqual([]);- });-- it("should handle URLs with HTTP instead of HTTPS", () => {- const text = "HTTP PR: http://github.com/owner/repo/pull/123";- const urls = extractPRUrls(text);- expect(urls).toEqual(["http://github.com/owner/repo/pull/123"]);- });-- it("should remove duplicate URLs", () => {- const text = `- Same PR mentioned twice:- https://github.com/owner/repo/pull/123- https://github.com/owner/repo/pull/123- `;- const urls = extractPRUrls(text);- expect(urls).toEqual(["https://github.com/owner/repo/pull/123"]);- });- });-- describe("containsPRUrl", () => {- it("should return true when PR URL is present", () => {- const text = "Check out this PR: https://github.com/owner/repo/pull/123";- expect(containsPRUrl(text)).toBe(true);- });-- it("should return false when no PR URL is present", () => {- const text = "This is just regular text";- expect(containsPRUrl(text)).toBe(false);- });- });-- describe("getFirstPRUrl", () => {- it("should return the first PR URL found", () => {- const text = `- First: https://github.com/owner/repo/pull/123- Second: https://gitlab.com/owner/repo/-/merge_requests/456- `;- const url = getFirstPRUrl(text);- expect(url).toBe("https://github.com/owner/repo/pull/123");- });-- it("should return null when no PR URL is found", () => {- const text = "This is just regular text";- const url = getFirstPRUrl(text);- expect(url).toBeNull();- });- });-- describe("real-world scenarios", () => {- it("should handle typical microagent finish messages", () => {- const text = `- I have successfully created a pull request with the requested changes.- You can view the PR here: https://github.com/OpenHands/OpenHands/pull/1234-- The changes include:- - Updated the component- - Added tests- - Fixed the issue- `;- const url = getFirstPRUrl(text);- expect(url).toBe("https://github.com/OpenHands/OpenHands/pull/1234");- });-- it("should handle messages with PR URLs in the middle", () => {- const text = `- Task completed successfully! I've created a pull request at- https://github.com/owner/repo/pull/567 with all the requested changes.- Please review when you have a chance.- `;- const url = getFirstPRUrl(text);- expect(url).toBe("https://github.com/owner/repo/pull/567");- });- });-});diff --git a/__tests__/utils/amount-is-valid.test.ts b/__tests__/utils/amount-is-valid.test.tsdeleted file mode 100644index 3a940f77e0..0000000000--- a/__tests__/utils/amount-is-valid.test.ts+++ /dev/null@@ -1,38 +0,0 @@-import { describe, expect, test } from "vitest";-import { amountIsValid } from "#/utils/amount-is-valid";--describe("amountIsValid", () => {- describe("fails", () => {- test("when the amount is negative", () => {- expect(amountIsValid("-5")).toBe(false);- expect(amountIsValid("-25")).toBe(false);- });-- test("when the amount is zero", () => {- expect(amountIsValid("0")).toBe(false);- });-- test("when an empty string is passed", () => {- expect(amountIsValid("")).toBe(false);- expect(amountIsValid(" ")).toBe(false);- });-- test("when a non-numeric value is passed", () => {- expect(amountIsValid("abc")).toBe(false);- expect(amountIsValid("1abc")).toBe(false);- expect(amountIsValid("abc1")).toBe(false);- });-- test("when an amount less than the minimum is passed", () => {- // test assumes the minimum is 10- expect(amountIsValid("9")).toBe(false);- expect(amountIsValid("9.99")).toBe(false);- });-- test("when an amount more than the maximum is passed", () => {- // test assumes the minimum is 25000- expect(amountIsValid("25001")).toBe(false);- expect(amountIsValid("25000.01")).toBe(false);- });- });-});diff --git a/__tests__/utils/error-handler.test.ts b/__tests__/utils/error-handler.test.tsindex b0cf26bc64..33e4747fd3 100644--- a/__tests__/utils/error-handler.test.ts+++ b/__tests__/utils/error-handler.test.ts@@ -1,12 +1,6 @@import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";import posthog from "posthog-js";-import {- trackError,- showErrorToast,- showChatError,-} from "#/utils/error-handler";-import * as Actions from "#/services/actions";-import * as CustomToast from "#/utils/custom-toast-handlers";+import { trackError } from "#/utils/error-handler";vi.mock("posthog-js", () => ({default: {@@ -14,10 +8,6 @@ vi.mock("posthog-js", () => ({},}));-vi.mock("#/services/actions", () => ({- handleStatusMessage: vi.fn(),-}));-describe("Error Handler", () => {beforeEach(() => {vi.clearAllMocks();@@ -68,129 +58,4 @@ describe("Error Handler", () => {);});});-- describe("showErrorToast", () => {- const errorToastSpy = vi.spyOn(CustomToast, "displayErrorToast");- it("should log error and show toast", () => {- const error = {- message: "Toast error",- source: "toast-test",- posthog,- };-- showErrorToast(error);-- // Verify PostHog logging- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Toast error"),- {- error_source: "toast-test",- },- );-- // Verify toast was shown- expect(errorToastSpy).toHaveBeenCalled();- });-- it("should include metadata in PostHog event when showing toast", () => {- const error = {- message: "Toast error",- source: "toast-test",- metadata: { context: "testing" },- posthog,- };-- showErrorToast(error);-- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Toast error"),- {- error_source: "toast-test",- context: "testing",- },- );- });-- it("should log errors from different sources with appropriate metadata", () => {- // Test agent status error- showErrorToast({- message: "Agent error",- source: "agent-status",- metadata: { id: "error.agent" },- posthog,- });-- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Agent error"),- {- error_source: "agent-status",- id: "error.agent",- },- );-- showErrorToast({- message: "Server error",- source: "server",- metadata: { error_code: 500, details: "Internal error" },- posthog,- });-- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Server error"),- {- error_source: "server",- error_code: 500,- details: "Internal error",- },- );- });-- it("should log feedback submission errors with conversation context", () => {- const error = new Error("Feedback submission failed");- showErrorToast({- message: error.message,- source: "feedback",- metadata: { conversationId: "123", error },- posthog,- });-- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Feedback submission failed"),- {- error_source: "feedback",- conversationId: "123",- error,- },- );- });- });-- describe("showChatError", () => {- it("should log error and show chat error message", () => {- const error = {- message: "Chat error",- source: "chat-test",- msgId: "123",- posthog,- };-- showChatError(error);-- // Verify PostHog logging- expect(posthog.captureException).toHaveBeenCalledWith(- new Error("Chat error"),- {- error_source: "chat-test",- },- );-- // Verify error message was shown in chat- expect(Actions.handleStatusMessage).toHaveBeenCalledWith({- type: "error",- message: "Chat error",- id: "123",- status_update: true,- });- });- });});diff --git a/__tests__/utils/extract-next-page-from-link.test.ts b/__tests__/utils/extract-next-page-from-link.test.tsdeleted file mode 100644index a7541f95a0..0000000000--- a/__tests__/utils/extract-next-page-from-link.test.ts+++ /dev/null@@ -1,13 +0,0 @@-import { expect, test } from "vitest";-import { extractNextPageFromLink } from "#/utils/extract-next-page-from-link";--test("extractNextPageFromLink", () => {- const link = `<https://api.github.com/repositories/1300192/issues?page=2>; rel="prev", <https://api.github.com/repositories/1300192/issues?page=4>; rel="next", <https://api.github.com/repositories/1300192/issues?page=515>; rel="last", <https://api.github.com/repositories/1300192/issues?page=1>; rel="first"`;- expect(extractNextPageFromLink(link)).toBe(4);-- const noNextLink = `<https://api.github.com/repositories/1300192/issues?page=2>; rel="prev", <https://api.github.com/repositories/1300192/issues?page=1>; rel="first"`;- expect(extractNextPageFromLink(noNextLink)).toBeNull();-- const extra = `<https://api.github.com/user/repos?sort=pushed&page=2&per_page=3>; rel="next", <https://api.github.com/user/repos?sort=pushed&page=22&per_page=3>; rel="last"`;- expect(extractNextPageFromLink(extra)).toBe(2);-});diff --git a/__tests__/utils/input-validation.test.ts b/__tests__/utils/input-validation.test.tsdeleted file mode 100644index 4d35121a48..0000000000--- a/__tests__/utils/input-validation.test.ts+++ /dev/null@@ -1,179 +0,0 @@-import { describe, expect, test } from "vitest";-import {- isValidEmail,- getInvalidEmails,- areAllEmailsValid,- hasDuplicates,-} from "#/utils/input-validation";--describe("isValidEmail", () => {- describe("valid email formats", () => {- test("accepts standard email formats", () => {- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- });-- test("accepts emails with numbers", () => {- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- });-- test("accepts emails with special characters in local part", () => {- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("user%[email protected]")).toBe(true);- });-- test("accepts emails with various TLDs", () => {- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- expect(isValidEmail("[email protected]")).toBe(true);- });- });-- describe("invalid email formats", () => {- test("rejects empty strings", () => {- expect(isValidEmail("")).toBe(false);- });-- test("rejects strings without @", () => {- expect(isValidEmail("userexample.com")).toBe(false);- expect(isValidEmail("user.example.com")).toBe(false);- });-- test("rejects strings without domain", () => {- expect(isValidEmail("user@")).toBe(false);- expect(isValidEmail("[email protected]")).toBe(false);- });-- test("rejects strings without local part", () => {- expect(isValidEmail("@example.com")).toBe(false);- });-- test("rejects strings without TLD", () => {- expect(isValidEmail("user@example")).toBe(false);- expect(isValidEmail("user@example.")).toBe(false);- });-- test("rejects strings with single character TLD", () => {- expect(isValidEmail("[email protected]")).toBe(false);- });-- test("rejects plain text", () => {- expect(isValidEmail("test")).toBe(false);- expect(isValidEmail("just some text")).toBe(false);- });-- test("rejects emails with spaces", () => {- expect(isValidEmail("user @example.com")).toBe(false);- expect(isValidEmail("user@ example.com")).toBe(false);- expect(isValidEmail(" [email protected]")).toBe(false);- expect(isValidEmail("[email protected] ")).toBe(false);- });-- test("rejects emails with multiple @ symbols", () => {- expect(isValidEmail("user@@example.com")).toBe(false);- expect(isValidEmail("user@[email protected]")).toBe(false);- });- });-});--describe("getInvalidEmails", () => {- test("returns empty array when all emails are valid", () => {- const emails = ["[email protected]", "[email protected]"];- expect(getInvalidEmails(emails)).toEqual([]);- });-- test("returns all invalid emails", () => {- const emails = [- "[email protected]",- "invalid",- "test@",- "[email protected]",- ];- expect(getInvalidEmails(emails)).toEqual(["invalid", "test@"]);- });-- test("returns all emails when none are valid", () => {- const emails = ["invalid", "also-invalid", "no-at-symbol"];- expect(getInvalidEmails(emails)).toEqual(emails);- });-- test("handles empty array", () => {- expect(getInvalidEmails([])).toEqual([]);- });-- test("handles array with single invalid email", () => {- expect(getInvalidEmails(["invalid"])).toEqual(["invalid"]);- });-- test("handles array with single valid email", () => {- expect(getInvalidEmails(["[email protected]"])).toEqual([]);- });-});--describe("areAllEmailsValid", () => {- test("returns true when all emails are valid", () => {- expect(areAllEmailsValid(emails)).toBe(true);- });-- test("returns false when any email is invalid", () => {- const emails = ["[email protected]", "invalid", "[email protected]"];- expect(areAllEmailsValid(emails)).toBe(false);- });-- test("returns false when all emails are invalid", () => {- const emails = ["invalid", "also-invalid"];- expect(areAllEmailsValid(emails)).toBe(false);- });-- test("returns true for empty array", () => {- expect(areAllEmailsValid([])).toBe(true);- });-- test("returns true for single valid email", () => {- expect(areAllEmailsValid(["[email protected]"])).toBe(true);- });-- test("returns false for single invalid email", () => {- expect(areAllEmailsValid(["invalid"])).toBe(false);- });-});--describe("hasDuplicates", () => {- test("returns false when all values are unique", () => {- false,- );- });-- test("returns true when duplicates exist", () => {- true,- );- });-- test("returns true for case-insensitive duplicates", () => {- expect(hasDuplicates(["[email protected]", "[email protected]"])).toBe(true);- expect(hasDuplicates(["[email protected]", "[email protected]"])).toBe(true);- });-- test("returns false for empty array", () => {- expect(hasDuplicates([])).toBe(false);- });-- test("returns false for single item array", () => {- expect(hasDuplicates(["[email protected]"])).toBe(false);- });-- test("handles multiple duplicates", () => {- expect(- hasDuplicates(["[email protected]", "[email protected]", "[email protected]", "[email protected]"]),- ).toBe(true);- });-});diff --git a/__tests__/utils/is-custom-model.test.ts b/__tests__/utils/is-custom-model.test.tsdeleted file mode 100644index f011a1c71c..0000000000--- a/__tests__/utils/is-custom-model.test.ts+++ /dev/null@@ -1,25 +0,0 @@-import { describe, expect, it } from "vitest";-import { isCustomModel } from "#/utils/is-custom-model";--describe("isCustomModel", () => {- const models = ["anthropic/claude-3.5", "openai/gpt-3.5-turbo", "gpt-4o"];- const prefixedModels = ["anthropic/claude-3.5", "openai/gpt-4o"];-- it("should return false by default", () => {- expect(isCustomModel(models, "")).toBe(false);- });-- it("should be true if it is a custom model", () => {- expect(isCustomModel(models, "some/model")).toBe(true);- });-- it("should be false if it is not a custom model", () => {- expect(isCustomModel(models, "anthropic/claude-3.5")).toBe(false);- expect(isCustomModel(models, "openai/gpt-3.5-turbo")).toBe(false);- expect(isCustomModel(models, "openai/gpt-4o")).toBe(false);- });-- it("treats bare and prefixed OpenAI models as the same model", () => {- expect(isCustomModel(prefixedModels, "gpt-4o")).toBe(false);- });-});diff --git a/__tests__/utils/organize-models-and-providers.test.ts b/__tests__/utils/organize-models-and-providers.test.tsdeleted file mode 100644index 7df8be9cea..0000000000--- a/__tests__/utils/organize-models-and-providers.test.ts+++ /dev/null@@ -1,57 +0,0 @@-import { expect, test } from "vitest";-import { organizeModelsAndProviders } from "../../src/utils/organize-models-and-providers";--test("organizeModelsAndProviders β models already prefixed by backend", () => {- // The backend now assigns provider prefixes to bare LiteLLM names.- // The frontend only needs to parse slash-prefixed provider/model strings.- const models = [- "azure/ada",- "azure/gpt-35-turbo",- "azure/gpt-3-turbo",- "azure/standard/1024-x-1024/dall-e-2",- "vertex_ai_beta/chat-bison",- "vertex_ai_beta/chat-bison-32k",- "sagemaker/meta-textgeneration-llama-2-13b",- "cohere.command-r-v1:0",- "cloudflare/@cf/mistral/mistral-7b-instruct-v0.1",- "openai/gpt-4o",- "openai/gpt-4o-mini",- "anthropic/claude-3-5-sonnet-20241022",- "together-ai-21.1b-41b",- ];-- const object = organizeModelsAndProviders(models);-- expect(object).toEqual({- azure: {- separator: "/",- models: [- "ada",- "gpt-35-turbo",- "gpt-3-turbo",- "standard/1024-x-1024/dall-e-2",- ],- },- vertex_ai_beta: {- separator: "/",- models: ["chat-bison", "chat-bison-32k"],- },- sagemaker: { separator: "/", models: ["meta-textgeneration-llama-2-13b"] },- cloudflare: {- separator: "/",- models: ["@cf/mistral/mistral-7b-instruct-v0.1"],- },- openai: {- separator: "/",- models: ["gpt-4o", "gpt-4o-mini"],- },- anthropic: {- separator: "/",- models: ["claude-3-5-sonnet-20241022"],- },- other: {- separator: "",- models: ["cohere.command-r-v1:0", "together-ai-21.1b-41b"],- },- });-});diff --git a/__tests__/utils/status.test.ts b/__tests__/utils/status.test.tsindex 9b22451910..0517ce17fb 100644--- a/__tests__/utils/status.test.ts+++ b/__tests__/utils/status.test.ts@@ -1,10 +1,5 @@import { describe, it, expect } from "vitest";-import {- getStatusCode,- getIndicatorColor,- IndicatorColor,-} from "#/utils/status";-import { AgentState } from "#/types/agent-state";+import { getStatusCode } from "#/utils/status";import { I18nKey } from "#/i18n/declaration";import { ExecutionStatus } from "#/types/agent-server/core";import type { AppConversationStartTaskStatus } from "#/api/conversation-service/agent-server-conversation-service.types";@@ -52,55 +47,3 @@ describe("getStatusCode", () => {expect(result).toBe(I18nKey.CONVERSATION$STARTING_CONVERSATION);});});--describe("getIndicatorColor", () => {- it("prioritises agent readiness over stale runtime status for AWAITING_USER_INPUT", () => {- const result = getIndicatorColor(- "OPEN",- "RUNNING",- "STATUS$STARTING_RUNTIME",- AgentState.AWAITING_USER_INPUT,- );- expect(result).toBe(IndicatorColor.BLUE);- });-- it("returns red when websocket is closed", () => {- const result = getIndicatorColor(- "CLOSED",- "STOPPED",- "STATUS$STOPPED",- AgentState.RUNNING,- );- expect(result).toBe(IndicatorColor.RED);- });-- it("returns yellow when agent is loading", () => {- const result = getIndicatorColor(- "OPEN",- "STARTING",- "STATUS$STARTING_RUNTIME",- AgentState.LOADING,- );- expect(result).toBe(IndicatorColor.YELLOW);- });-- it("returns orange for AWAITING_USER_CONFIRMATION", () => {- const result = getIndicatorColor(- "OPEN",- "RUNNING",- "STATUS$STARTING_RUNTIME",- AgentState.AWAITING_USER_CONFIRMATION,- );- expect(result).toBe(IndicatorColor.ORANGE);- });-- it("returns green for FINISHED state", () => {- const result = getIndicatorColor(- "OPEN",- "RUNNING",- "STATUS$SETTING_UP_WORKSPACE",- AgentState.FINISHED,- );- expect(result).toBe(IndicatorColor.GREEN);- });-});diff --git a/__tests__/utils/websocket-url.test.ts b/__tests__/utils/websocket-url.test.tsindex a5b9e13fc2..132bdd26c5 100644--- a/__tests__/utils/websocket-url.test.ts+++ b/__tests__/utils/websocket-url.test.ts@@ -1,10 +1,5 @@import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";-import {- extractBaseHost,- extractPathPrefix,- buildHttpBaseUrl,- buildWebSocketUrl,-} from "#/utils/websocket-url";+import { buildHttpBaseUrl, buildWebSocketUrl } from "#/utils/websocket-url";describe("websocket-url utilities", () => {beforeEach(() => {@@ -18,78 +13,6 @@ describe("websocket-url utilities", () => {vi.unstubAllGlobals();});- describe("extractBaseHost", () => {- it("should extract host from a standard URL", () => {- const result = extractBaseHost(- "https://example.com/api/conversations/123",- );- expect(result).toBe("example.com");- });-- it("should extract host with port from URL", () => {- const result = extractBaseHost(- "http://localhost:3000/api/conversations/123",- );- expect(result).toBe("localhost:3000");- });-- it("should extract host from proxy deployment URL", () => {- const result = extractBaseHost(- "https://openhands.example.com/runtime/55313/api/conversations/abc123",- );- expect(result).toBe("openhands.example.com");- });-- it("should return window.location.host for relative URLs", () => {- const result = extractBaseHost("/api/conversations/123");- expect(result).toBe("localhost:3001");- });-- it("should return window.location.host for null, undefined, or invalid URL", () => {- expect(extractBaseHost(null)).toBe("localhost:3001");- expect(extractBaseHost(undefined)).toBe("localhost:3001");- expect(extractBaseHost("not-a-valid-url")).toBe("localhost:3001");- });- });-- describe("extractPathPrefix", () => {- it("should return empty string for URL without path prefix", () => {- const result = extractPathPrefix(- "https://example.com/api/conversations/123",- );- expect(result).toBe("");- });-- it("should extract path prefix from proxy deployment URL", () => {- const result = extractPathPrefix(- "https://openhands.example.com/runtime/55313/api/conversations/abc123",- );- expect(result).toBe("/runtime/55313");- });-- it("should handle multiple path segments before /api/conversations", () => {- const result = extractPathPrefix(- "https://example.com/prefix/sub/path/api/conversations/123",- );- expect(result).toBe("/prefix/sub/path");- });-- it("should remove trailing slash from path prefix", () => {- // This test ensures the function handles URLs where the path ends with /- const result = extractPathPrefix(- "https://example.com/runtime/55313/api/conversations/123",- );- expect(result).not.toMatch(/\/$/);- });-- it("should return empty string for relative URLs, null, undefined, or invalid URL", () => {- expect(extractPathPrefix("/api/conversations/123")).toBe("");- expect(extractPathPrefix(null)).toBe("");- expect(extractPathPrefix(undefined)).toBe("");- expect(extractPathPrefix("not-a-valid-url")).toBe("");- });- });-describe("buildHttpBaseUrl", () => {it("should build HTTP URL without path prefix", () => {const result = buildHttpBaseUrl(diff --git a/src/utils/amount-is-valid.ts b/src/utils/amount-is-valid.tsdeleted file mode 100644index 513fb85660..0000000000--- a/src/utils/amount-is-valid.ts+++ /dev/null@@ -1,13 +0,0 @@-const MINIMUM_AMOUNT = 10;-const MAXIMUM_AMOUNT = 25_000;--export const amountIsValid = (amount: string) => {- const value = parseInt(amount, 10);- if (Number.isNaN(value)) return false;- if (value < 0) return false;- if (value < MINIMUM_AMOUNT) return false;- if (value > MAXIMUM_AMOUNT) return false;- if (value !== parseFloat(amount)) return false; // Ensure it's an integer-- return true;-};diff --git a/src/utils/error-handler.ts b/src/utils/error-handler.tsindex 385881e0ce..c870521bdc 100644--- a/src/utils/error-handler.ts+++ b/src/utils/error-handler.ts@@ -1,6 +1,4 @@import type { PostHog } from "posthog-js";-import { handleStatusMessage } from "#/services/actions";-import { displayErrorToast } from "./custom-toast-handlers";interface ErrorDetails {message: string;@@ -24,29 +22,3 @@ export function trackError({...metadata,});}--export function showErrorToast({- message,- source,- metadata = {},- posthog,-}: ErrorDetails) {- trackError({ message, source, metadata, posthog });- displayErrorToast(message);-}--export function showChatError({- message,- source,- metadata = {},- msgId,- posthog,-}: ErrorDetails) {- trackError({ message, source, metadata, posthog });- handleStatusMessage({- type: "error",- message,- id: msgId,- status_update: true,- });-}diff --git a/src/utils/extract-next-page-from-link.ts b/src/utils/extract-next-page-from-link.tsdeleted file mode 100644index 98fe5a7da9..0000000000--- a/src/utils/extract-next-page-from-link.ts+++ /dev/null@@ -1,11 +0,0 @@-/**- * Extracts the next page number from a GitHub API link header.- * @param link The GitHub API link header- * @returns The next page number or null if there is no next page- */-export const extractNextPageFromLink = (link: string): number | null => {- const regex = /<[^>]*[?&]page=(\d+)(?:&[^>]*)?>; rel="next"/;- const match = link.match(regex);-- return match ? parseInt(match[1], 10) : null;-};diff --git a/src/utils/feature-flags.ts b/src/utils/feature-flags.tsindex b7637cb224..f61ff18806 100644--- a/src/utils/feature-flags.ts+++ b/src/utils/feature-flags.ts@@ -1,4 +1,4 @@-export function loadFeatureFlag(+function loadFeatureFlag(flagName: string,defaultValue: boolean = false,): boolean {@@ -12,7 +12,4 @@ export function loadFeatureFlag(}}-export const HIDE_LLM_SETTINGS = () => loadFeatureFlag("HIDE_LLM_SETTINGS");export const VSCODE_IN_NEW_TAB = () => loadFeatureFlag("VSCODE_IN_NEW_TAB");-export const ENABLE_TRAJECTORY_REPLAY = () =>- loadFeatureFlag("TRAJECTORY_REPLAY");diff --git a/src/utils/file-processing.ts b/src/utils/file-processing.tsindex 50465afc14..e1cc15985f 100644--- a/src/utils/file-processing.ts+++ b/src/utils/file-processing.ts@@ -7,7 +7,7 @@* Process a regular file by reading its content into memory* For large files (1GB+), this will take significant time*/-export const processFile = async (file: File): Promise<void> =>+const processFile = async (file: File): Promise<void> =>new Promise((resolve, reject) => {const reader = new FileReader();@@ -33,7 +33,7 @@ export const processFile = async (file: File): Promise<void> =>* Process an image file by reading its content* This validates the image can be read and prepares it for display*/-export const processImage = async (image: File): Promise<void> =>+const processImage = async (image: File): Promise<void> =>new Promise((resolve, reject) => {const reader = new FileReader();diff --git a/src/utils/format-time-delta.ts b/src/utils/format-time-delta.tsindex 6785d9c845..1501e8fa92 100644--- a/src/utils/format-time-delta.ts+++ b/src/utils/format-time-delta.ts@@ -55,19 +55,3 @@ export const formatTimeDelta = (date: Date | string) => {if (months < 12) return `${months}mo`;return `${years}y`;};--/**- * Formats a date into a MM/DD/YYYY string format.- * @param date The date to format- * @returns A string in MM/DD/YYYY format- *- * @example- * formatDateMMDDYYYY(new Date("2025-05-30T00:15:08")); // "05/30/2025"- * formatDateMMDDYYYY(new Date("2024-12-25T10:30:00")); // "12/25/2024"- */-export const formatDateMMDDYYYY = (date: Date) =>- date.toLocaleDateString("en-US", {- month: "2-digit",- day: "2-digit",- year: "numeric",- });diff --git a/src/utils/get-component-prop-types.ts b/src/utils/get-component-prop-types.tsdeleted file mode 100644index 8309441283..0000000000--- a/src/utils/get-component-prop-types.ts+++ /dev/null@@ -1,2 +0,0 @@-export type GetComponentPropTypes<T> =- T extends React.ComponentType<infer P> ? P : never;diff --git a/src/utils/input-validation.ts b/src/utils/input-validation.tsdeleted file mode 100644index 1c9df98021..0000000000--- a/src/utils/input-validation.ts+++ /dev/null@@ -1,35 +0,0 @@-// Email validation regex pattern-const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;--/**- * Validates if a string is a valid email address format- * @param email The email string to validate- * @returns true if the email format is valid, false otherwise- */-export const isValidEmail = (email: string): boolean => EMAIL_REGEX.test(email);--/**- * Validates an array of email addresses and returns the invalid ones- * @param emails Array of email strings to validate- * @returns Array of invalid email addresses- */-export const getInvalidEmails = (emails: string[]): string[] =>- emails.filter((email) => !isValidEmail(email));--/**- * Checks if all emails in an array are valid- * @param emails Array of email strings to validate- * @returns true if all emails are valid, false otherwise- */-export const areAllEmailsValid = (emails: string[]): boolean =>- emails.every((email) => isValidEmail(email));--/**- * Checks if an array contains duplicate values (case-insensitive for emails)- * @param values Array of strings to check- * @returns true if duplicates exist, false otherwise- */-export const hasDuplicates = (values: string[]): boolean => {- const lowercased = values.map((v) => v.toLowerCase());- return new Set(lowercased).size !== lowercased.length;-};diff --git a/src/utils/is-custom-model.ts b/src/utils/is-custom-model.tsdeleted file mode 100644index 42bc692d9d..0000000000--- a/src/utils/is-custom-model.ts+++ /dev/null@@ -1,30 +0,0 @@-import { extractModelAndProvider } from "./extract-model-and-provider";--const isEquivalentOpenAIModel = (left: string, right: string) => {- const leftParts = extractModelAndProvider(left);- const rightParts = extractModelAndProvider(right);-- return (- leftParts.model === rightParts.model &&- ((leftParts.provider === "openai" && !rightParts.provider) ||- (!leftParts.provider && rightParts.provider === "openai"))- );-};--/**- * Check if a model is a custom model. A custom model is a model that is not part of the default models.- * @param models Full list of models- * @param model Model to check- * @returns Whether the model is a custom model- */-export const isCustomModel = (models: string[], model: string): boolean => {- if (!model) return false;-- const isKnownModel = models.some(- (availableModel) =>- availableModel === model ||- isEquivalentOpenAIModel(availableModel, model),- );-- return !isKnownModel;-};diff --git a/src/utils/is-on-tos-page.ts b/src/utils/is-on-tos-page.tsdeleted file mode 100644index f98655a3ac..0000000000--- a/src/utils/is-on-tos-page.ts+++ /dev/null@@ -1,20 +0,0 @@-/**- * Checks if the current page is the Terms of Service acceptance page.- * This function works outside of React Router context by checking window.location directly.- *- * @param {string} [pathname] - Optional pathname from React Router's useLocation hook- * @returns {boolean} True if the current page is the TOS acceptance page, false otherwise.- */-export const isOnTosPage = (pathname?: string): boolean => {- // If pathname is provided (from React Router), use it- if (pathname !== undefined) {- return pathname === "/accept-tos";- }-- // Otherwise check window.location (works outside React Router context)- if (typeof window !== "undefined") {- return window.location.pathname === "/accept-tos";- }-- return false;-};diff --git a/src/utils/organize-models-and-providers.ts b/src/utils/organize-models-and-providers.tsdeleted file mode 100644index 3f2f9843e1..0000000000--- a/src/utils/organize-models-and-providers.ts+++ /dev/null@@ -1,41 +0,0 @@-import { extractModelAndProvider } from "./extract-model-and-provider";--/**- * Given a list of models, organize them by provider.- * @param models The list of models- * @returns An object containing the provider and models- *- * @example- * const models = ["azure/ada", "azure/gpt-35-turbo", "gpt-4o"];- *- * organizeModelsAndProviders(models);- * // returns {- * // azure: {- * // separator: "/",- * // models: ["ada", "gpt-35-turbo"],- * // },- * // other: {- * // separator: "",- * // models: ["gpt-4o"],- * // },- * // }- */-export const organizeModelsAndProviders = (models: string[]) => {- const object: Record<string, { separator: string; models: string[] }> = {};-- models.forEach((model) => {- const {- separator,- provider,- model: modelId,- } = extractModelAndProvider(model);-- const key = provider || "other";- if (!object[key]) {- object[key] = { separator, models: [] };- }- object[key].models.push(modelId);- });-- return object;-};diff --git a/src/utils/parse-pr-url.ts b/src/utils/parse-pr-url.tsdeleted file mode 100644index 482c61b5a4..0000000000--- a/src/utils/parse-pr-url.ts+++ /dev/null@@ -1,57 +0,0 @@-/**- * Utility function to parse Pull Request URLs from text- */--// Common PR URL patterns for different Git providers-const PR_URL_PATTERNS = [- // GitHub: https://github.com/owner/repo/pull/123- /https?:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/gi,- // GitLab: https://gitlab.com/owner/repo/-/merge_requests/123- /https?:\/\/gitlab\.com\/[^/\s]+\/[^/\s]+\/-\/merge_requests\/\d+/gi,- // GitLab self-hosted: https://gitlab.example.com/owner/repo/-/merge_requests/123- /https?:\/\/[^/\s]*gitlab[^/\s]*\/[^/\s]+\/[^/\s]+\/-\/merge_requests\/\d+/gi,- // Bitbucket: https://bitbucket.org/owner/repo/pull-requests/123- /https?:\/\/bitbucket\.org\/[^/\s]+\/[^/\s]+\/pull-requests\/\d+/gi,- // Azure DevOps: https://dev.azure.com/org/project/_git/repo/pullrequest/123- /https?:\/\/dev\.azure\.com\/[^/\s]+\/[^/\s]+\/_git\/[^/\s]+\/pullrequest\/\d+/gi,- // Generic pattern for other providers that might use /pull/ or /pr/- /https?:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/(?:pull|pr)\/\d+/gi,-];--/**- * Extracts PR URLs from a given text- * @param text - The text to search for PR URLs- * @returns Array of found PR URLs- */-export function extractPRUrls(text: string): string[] {- const urls: string[] = [];-- for (const pattern of PR_URL_PATTERNS) {- const matches = text.match(pattern);- if (matches) {- urls.push(...matches);- }- }-- // Remove duplicates and return- return [...new Set(urls)];-}--/**- * Checks if the text contains any PR URLs- * @param text - The text to check- * @returns True if PR URLs are found, false otherwise- */-export function containsPRUrl(text: string): boolean {- return extractPRUrls(text).length > 0;-}--/**- * Gets the first PR URL found in the text- * @param text - The text to search- * @returns The first PR URL found, or null if none found- */-export function getFirstPRUrl(text: string): string | null {- const urls = extractPRUrls(text);- return urls.length > 0 ? urls[0] : null;-}diff --git a/src/utils/status.ts b/src/utils/status.tsindex 1f45b0f172..f0789cf552 100644--- a/src/utils/status.ts+++ b/src/utils/status.ts@@ -1,7 +1,4 @@import { I18nKey } from "#/i18n/declaration";-import { AgentState } from "#/types/agent-state";-import { ConversationStatus } from "#/types/conversation-status";-import { RuntimeStatus } from "#/types/runtime-status";import { AppConversationStartTaskStatus } from "#/api/conversation-service/agent-server-conversation-service.types";import { ExecutionStatus } from "#/types/agent-server/core/base/common";import { WebSocketConnectionState } from "#/contexts/conversation-websocket-context";@@ -31,98 +28,6 @@ export function isExecutionErrored(return status === ExecutionStatus.ERROR || status === ExecutionStatus.STUCK;}-export enum IndicatorColor {- BLUE = "bg-blue-500",- GREEN = "bg-green-500",- ORANGE = "bg-orange-500",- YELLOW = "bg-yellow-500",- RED = "bg-red-500",- DARK_ORANGE = "bg-orange-800",-}--export const AGENT_STATUS_MAP: {- [k: string]: string;-} = {- // Initializing states- [AgentState.LOADING]: I18nKey.AGENT_STATUS$INITIALIZING,- [AgentState.INIT]: I18nKey.AGENT_STATUS$INITIALIZING,-- // Ready/Idle/Waiting for user input states- [AgentState.AWAITING_USER_INPUT]: I18nKey.AGENT_STATUS$WAITING_FOR_TASK,- [AgentState.AWAITING_USER_CONFIRMATION]:- I18nKey.AGENT_STATUS$WAITING_FOR_USER_CONFIRMATION,- [AgentState.USER_CONFIRMED]: I18nKey.AGENT_STATUS$WAITING_FOR_TASK,- [AgentState.USER_REJECTED]: I18nKey.AGENT_STATUS$WAITING_FOR_TASK,- [AgentState.FINISHED]: I18nKey.AGENT_STATUS$WAITING_FOR_TASK,-- // Actively working states- [AgentState.RUNNING]: I18nKey.AGENT_STATUS$RUNNING_TASK,-- // Agent stopped/paused states- [AgentState.PAUSED]: I18nKey.AGENT_STATUS$AGENT_STOPPED,- [AgentState.STOPPED]: I18nKey.AGENT_STATUS$AGENT_STOPPED,- [AgentState.REJECTED]: I18nKey.AGENT_STATUS$AGENT_STOPPED,-- // Agent error states- [AgentState.ERROR]: I18nKey.AGENT_STATUS$ERROR_OCCURRED,- [AgentState.RATE_LIMITED]: I18nKey.AGENT_STATUS$ERROR_OCCURRED,-};--export function getIndicatorColor(- webSocketStatus: WebSocketConnectionState,- conversationStatus: ConversationStatus | null,- runtimeStatus: RuntimeStatus | null,- agentState: AgentState | null,-) {- if (- webSocketStatus === "CLOSED" ||- conversationStatus === "STOPPED" ||- runtimeStatus === "STATUS$STOPPED" ||- agentState === AgentState.STOPPED ||- agentState === AgentState.ERROR- ) {- return IndicatorColor.RED;- }-- // Prioritize agent state when it indicates readiness, even if runtime status is stale- const agentIsReady =- agentState &&- [- AgentState.AWAITING_USER_INPUT,- AgentState.RUNNING,- AgentState.FINISHED,- AgentState.AWAITING_USER_CONFIRMATION,- AgentState.USER_CONFIRMED,- AgentState.USER_REJECTED,- ].includes(agentState);-- // Display a yellow working icon while the runtime is starting- if (- conversationStatus === "STARTING" ||- (!["STATUS$READY", null].includes(runtimeStatus) && !agentIsReady) ||- (agentState != null &&- [- AgentState.LOADING,- AgentState.PAUSED,- AgentState.REJECTED,- AgentState.RATE_LIMITED,- ].includes(agentState))- ) {- return IndicatorColor.YELLOW;- }-- if (agentState === AgentState.AWAITING_USER_CONFIRMATION) {- return IndicatorColor.ORANGE;- }-- if (agentState === AgentState.AWAITING_USER_INPUT) {- return IndicatorColor.BLUE;- }-- // All other agent states are green- return IndicatorColor.GREEN;-}-export function getStatusCode(webSocketConnectionState: WebSocketConnectionState,executionStatus: ExecutionStatus | null,diff --git a/src/utils/websocket-url.ts b/src/utils/websocket-url.tsindex cd008d5e36..21cdf524f9 100644--- a/src/utils/websocket-url.ts+++ b/src/utils/websocket-url.ts@@ -3,9 +3,7 @@* @param conversationUrl The conversation URL containing host/port (e.g., "http://localhost:3000/api/conversations/123")* @returns Base host (e.g., "localhost:3000") or window.location.host as fallback*/-export function extractBaseHost(- conversationUrl: string | null | undefined,-): string {+function extractBaseHost(conversationUrl: string | null | undefined): string {if (conversationUrl && !conversationUrl.startsWith("/")) {try {const url = new URL(conversationUrl);@@ -36,9 +34,7 @@ export function extractBaseHost(* @param conversationUrl The conversation URL (e.g., "http://localhost:3000/runtime/55313/api/conversations/123")* @returns Path prefix without trailing slash (e.g., "/runtime/55313") or empty string*/-export function extractPathPrefix(- conversationUrl: string | null | undefined,-): string {+function extractPathPrefix(conversationUrl: string | null | undefined): string {if (conversationUrl && !conversationUrl.startsWith("/")) {try {const url = new URL(conversationUrl);