mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-10-06 14:33:11 +08:00
chore: remove orphaned legacy modules left over from the frontend port (#1227)
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
import { describe, expect, it, test } from "vitest";
|
||||
import { hasAdvancedSettingsSet } from "#/utils/has-advanced-settings-set";
|
||||
import { DEFAULT_SETTINGS } from "#/services/settings";
|
||||
|
||||
describe("hasAdvancedSettingsSet", () => {
|
||||
it("should return false by default", () => {
|
||||
expect(hasAdvancedSettingsSet(DEFAULT_SETTINGS)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if an empty object", () => {
|
||||
expect(hasAdvancedSettingsSet({})).toBe(false);
|
||||
});
|
||||
|
||||
describe("should be true if", () => {
|
||||
test("llm.base_url is set", () => {
|
||||
const as = DEFAULT_SETTINGS.agent_settings as Record<string, unknown>;
|
||||
const llm = (as?.llm ?? {}) as Record<string, unknown>;
|
||||
expect(
|
||||
hasAdvancedSettingsSet({
|
||||
...DEFAULT_SETTINGS,
|
||||
agent_settings: {
|
||||
...as,
|
||||
llm: { ...llm, base_url: "test" },
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("agent is not default value", () => {
|
||||
expect(
|
||||
hasAdvancedSettingsSet({
|
||||
...DEFAULT_SETTINGS,
|
||||
agent_settings: {
|
||||
...DEFAULT_SETTINGS.agent_settings,
|
||||
agent: "test",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("condenser.enabled is disabled", () => {
|
||||
const as = DEFAULT_SETTINGS.agent_settings as Record<string, unknown>;
|
||||
const condenser = (as?.condenser ?? {}) as Record<string, unknown>;
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
agent_settings: {
|
||||
...as,
|
||||
condenser: { ...condenser, enabled: false },
|
||||
},
|
||||
};
|
||||
|
||||
const result = hasAdvancedSettingsSet(settings);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("condenser.max_size is customized above default", () => {
|
||||
const as = DEFAULT_SETTINGS.agent_settings as Record<string, unknown>;
|
||||
const condenser = (as?.condenser ?? {}) as Record<string, unknown>;
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
agent_settings: {
|
||||
...as,
|
||||
condenser: { ...condenser, max_size: 200 },
|
||||
},
|
||||
};
|
||||
|
||||
const result = hasAdvancedSettingsSet(settings);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("condenser.max_size is customized below default", () => {
|
||||
const as = DEFAULT_SETTINGS.agent_settings as Record<string, unknown>;
|
||||
const condenser = (as?.condenser ?? {}) as Record<string, unknown>;
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
agent_settings: {
|
||||
...as,
|
||||
condenser: { ...condenser, max_size: 50 },
|
||||
},
|
||||
};
|
||||
|
||||
const result = hasAdvancedSettingsSet(settings);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("search_api_key is set to non-empty value", () => {
|
||||
// Arrange
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
search_api_key: "test-api-key-123",
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = hasAdvancedSettingsSet(settings);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("search_api_key with whitespace is treated as set", () => {
|
||||
// Arrange
|
||||
const settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
search_api_key: " test-key ",
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = hasAdvancedSettingsSet(settings);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
import ActionType from "#/types/action-type";
|
||||
|
||||
export function getTerminalCommand(command: string, hidden: boolean = false) {
|
||||
const event = { action: ActionType.RUN, args: { command, hidden } };
|
||||
return event;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
enum ArgConfigType {
|
||||
LLM_MODEL = "LLM_MODEL",
|
||||
AGENT = "AGENT",
|
||||
LANGUAGE = "LANGUAGE",
|
||||
LLM_API_KEY_SET = "LLM_API_KEY_SET",
|
||||
}
|
||||
|
||||
const SupportedSettings: string[] = [
|
||||
ArgConfigType.LLM_MODEL,
|
||||
ArgConfigType.AGENT,
|
||||
ArgConfigType.LANGUAGE,
|
||||
ArgConfigType.LLM_API_KEY_SET,
|
||||
];
|
||||
|
||||
export { ArgConfigType, SupportedSettings };
|
||||
@@ -1,5 +0,0 @@
|
||||
import { ActionMessage, ObservationMessage, StatusMessage } from "./message";
|
||||
|
||||
type SocketMessage = ActionMessage | ObservationMessage | StatusMessage;
|
||||
|
||||
export { type SocketMessage };
|
||||
@@ -1,10 +0,0 @@
|
||||
enum TabOption {
|
||||
PLANNER = "planner",
|
||||
BROWSER = "browser",
|
||||
VSCODE = "vscode",
|
||||
}
|
||||
|
||||
type TabType = TabOption.PLANNER | TabOption.BROWSER | TabOption.VSCODE;
|
||||
const AllTabs = [TabOption.VSCODE, TabOption.BROWSER, TabOption.PLANNER];
|
||||
|
||||
export { AllTabs, TabOption, type TabType };
|
||||
@@ -1,13 +0,0 @@
|
||||
export const downloadJSON = (data: object, filename: string) => {
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
import { downloadJSON } from "./download-json";
|
||||
|
||||
function isSaveFilePickerSupported(): boolean {
|
||||
return typeof window !== "undefined" && "showSaveFilePicker" in window;
|
||||
}
|
||||
|
||||
export async function downloadTrajectory(
|
||||
conversationId: string,
|
||||
data: unknown[] | null,
|
||||
): Promise<void> {
|
||||
// Ensure data is an object for downloadJSON
|
||||
const jsonData = data || {};
|
||||
|
||||
if (!isSaveFilePickerSupported()) {
|
||||
// Fallback for browsers that don't support File System Access API (Safari, Firefox)
|
||||
// This method dumps the JSON data right into the download folder
|
||||
downloadJSON(jsonData as object, `trajectory-${conversationId}.json`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const options: SaveFilePickerOptions = {
|
||||
suggestedName: `trajectory-${conversationId}.json`,
|
||||
types: [
|
||||
{
|
||||
description: "JSON File", // This is a file type description, not user-facing text
|
||||
accept: {
|
||||
"application/json": [".json"],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const fileHandle = await window.showSaveFilePicker(options);
|
||||
const writable = await fileHandle.createWritable();
|
||||
await writable.write(JSON.stringify(data, null, 2));
|
||||
await writable.close();
|
||||
} catch (error) {
|
||||
// If an error occurs, fall back to the downloadJSON method
|
||||
if (error instanceof Error && error.name !== "AbortError") {
|
||||
downloadJSON(jsonData as object, `trajectory-${conversationId}.json`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { DEFAULT_SETTINGS } from "#/services/settings";
|
||||
import { Settings } from "#/types/settings";
|
||||
import { getAgentSettingValue } from "#/utils/sdk-settings-schema";
|
||||
|
||||
/**
|
||||
* Determines if any advanced-only settings are configured.
|
||||
* Advanced-only settings are those that appear only in the Advanced Settings view
|
||||
* and not in the Basic Settings view.
|
||||
*
|
||||
* Advanced-only fields:
|
||||
* - llm_base_url: Custom base URL for LLM API
|
||||
* - agent: Custom agent selection (when not using default)
|
||||
* - enable_default_condenser: Memory condenser toggle (when disabled, as default is enabled)
|
||||
* - condenser_max_size: Custom condenser size (when different from default)
|
||||
* - search_api_key: Search API key (when set)
|
||||
*/
|
||||
export const hasAdvancedSettingsSet = (
|
||||
settings: Partial<Settings>,
|
||||
): boolean => {
|
||||
if (Object.keys(settings).length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasBaseUrl =
|
||||
typeof getAgentSettingValue(settings as Settings, "llm.base_url") ===
|
||||
"string" &&
|
||||
getAgentSettingValue(settings as Settings, "llm.base_url") !== "";
|
||||
const hasCustomAgent =
|
||||
getAgentSettingValue(settings as Settings, "agent") !==
|
||||
getAgentSettingValue(DEFAULT_SETTINGS, "agent");
|
||||
const hasDisabledCondenser =
|
||||
getAgentSettingValue(settings as Settings, "condenser.enabled") === false;
|
||||
const hasCustomCondenserSize =
|
||||
getAgentSettingValue(settings as Settings, "condenser.max_size") !==
|
||||
getAgentSettingValue(DEFAULT_SETTINGS, "condenser.max_size");
|
||||
const hasSearchApiKey =
|
||||
settings.search_api_key !== undefined &&
|
||||
settings.search_api_key !== null &&
|
||||
settings.search_api_key.trim() !== "";
|
||||
|
||||
return (
|
||||
hasBaseUrl ||
|
||||
hasCustomAgent ||
|
||||
hasDisabledCondenser ||
|
||||
hasCustomCondenserSize ||
|
||||
hasSearchApiKey
|
||||
);
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
import toast from "react-hot-toast";
|
||||
import { UseMutationResult } from "@tanstack/react-query";
|
||||
import i18n from "#/i18n";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import {
|
||||
TOAST_OPTIONS,
|
||||
displaySuccessToast,
|
||||
displayErrorToast,
|
||||
} from "./custom-toast-handlers";
|
||||
|
||||
export type ToastMessages<TData> = {
|
||||
success?: string | ((data: TData) => string) | false;
|
||||
error?: string | ((error: Error) => string) | false;
|
||||
loading?: string;
|
||||
};
|
||||
|
||||
export async function mutateWithToast<TData, TVariables>(
|
||||
mutation: UseMutationResult<TData, Error, TVariables>,
|
||||
variables: TVariables,
|
||||
messages: ToastMessages<TData>,
|
||||
): Promise<TData> {
|
||||
const { success, error, loading } = messages;
|
||||
|
||||
let loadingToastId: string | undefined;
|
||||
if (loading) {
|
||||
loadingToastId = toast.loading(loading, TOAST_OPTIONS);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await mutation.mutateAsync(variables);
|
||||
|
||||
if (loadingToastId) toast.dismiss(loadingToastId);
|
||||
|
||||
if (success !== false) {
|
||||
const message = typeof success === "function" ? success(result) : success;
|
||||
if (message) displaySuccessToast(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (err) {
|
||||
if (loadingToastId) toast.dismiss(loadingToastId);
|
||||
|
||||
if (error !== false) {
|
||||
let message: string;
|
||||
if (typeof error === "function") {
|
||||
message = error(err as Error);
|
||||
} else if (error) {
|
||||
message = error;
|
||||
} else if (err instanceof Error) {
|
||||
message = err.message;
|
||||
} else {
|
||||
message = i18n.t(I18nKey.ERROR$GENERIC);
|
||||
}
|
||||
displayErrorToast(message);
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user