mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 20:33:59 +02:00
refactor: remove confirmed dead helpers
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, test, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { applyAgentDefaultPrimaryModel } from "../plugins/provider-model-primary.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
buildCleanupPlan,
|
||||
removeStateAndLinkedPaths,
|
||||
removeWorkspaceDirs,
|
||||
} from "./cleanup-utils.js";
|
||||
import { applyAgentDefaultPrimaryModel } from "./model-default.js";
|
||||
|
||||
describe("buildCleanupPlan", () => {
|
||||
test("resolves inside-state flags and workspace dirs", () => {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export {
|
||||
applyAgentDefaultPrimaryModel,
|
||||
resolvePrimaryModel,
|
||||
} from "../plugins/provider-model-primary.js";
|
||||
@@ -1,11 +1,11 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||
import {
|
||||
applyOpencodeZenModelDefault,
|
||||
OPENCODE_ZEN_DEFAULT_MODEL,
|
||||
} from "./opencode-zen-model-default.js";
|
||||
} from "../plugins/provider-model-defaults.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||
|
||||
function makePrompter(): WizardPrompter {
|
||||
return {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export {
|
||||
applyOpencodeGoModelDefault,
|
||||
OPENCODE_GO_DEFAULT_MODEL_REF,
|
||||
} from "../plugins/provider-model-defaults.js";
|
||||
@@ -1,4 +0,0 @@
|
||||
export {
|
||||
applyOpencodeZenModelDefault,
|
||||
OPENCODE_ZEN_DEFAULT_MODEL,
|
||||
} from "../plugins/provider-model-defaults.js";
|
||||
@@ -21,7 +21,7 @@ export type NodeHostConfig = {
|
||||
|
||||
const NODE_HOST_FILE = "node.json";
|
||||
|
||||
export function resolveNodeHostConfigPath(): string {
|
||||
function resolveNodeHostConfigPath(): string {
|
||||
return path.join(resolveStateDir(), NODE_HOST_FILE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function toSnakeCaseKey(key: string): string {
|
||||
function toSnakeCaseKey(key: string): string {
|
||||
return key
|
||||
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
||||
|
||||
@@ -50,8 +50,8 @@ describe("plugin activation boundary", () => {
|
||||
function importAmbientModules() {
|
||||
ambientImportsPromise ??= Promise.all([
|
||||
import("./commands/onboard-custom.js"),
|
||||
import("./commands/opencode-go-model-default.js"),
|
||||
import("./commands/opencode-zen-model-default.js"),
|
||||
import("./plugins/provider-model-defaults.js"),
|
||||
import("./plugins/provider-model-primary.js"),
|
||||
]).then(() => undefined);
|
||||
return ambientImportsPromise;
|
||||
}
|
||||
|
||||
@@ -103,14 +103,6 @@ export function createNonExitingRuntime(): OutputRuntimeEnv {
|
||||
};
|
||||
}
|
||||
|
||||
export function writeRuntimeStdout(runtime: RuntimeEnv | OutputRuntimeEnv, value: string): void {
|
||||
if (hasRuntimeOutputWriter(runtime)) {
|
||||
runtime.writeStdout(value);
|
||||
return;
|
||||
}
|
||||
runtime.log(value);
|
||||
}
|
||||
|
||||
export function writeRuntimeJson(
|
||||
runtime: RuntimeEnv | OutputRuntimeEnv,
|
||||
value: unknown,
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { formatTerminalLink } from "./terminal-link.js";
|
||||
|
||||
export function resolveDocsRoot(): string {
|
||||
function resolveDocsRoot(): string {
|
||||
return "https://docs.openclaw.ai";
|
||||
}
|
||||
|
||||
export const DOCS_ROOT = resolveDocsRoot();
|
||||
|
||||
export function formatDocsLink(
|
||||
path: string,
|
||||
label?: string,
|
||||
@@ -21,10 +19,3 @@ export function formatDocsLink(
|
||||
force: opts?.force,
|
||||
});
|
||||
}
|
||||
|
||||
export function formatDocsRootLink(label?: string): string {
|
||||
const docsRoot = resolveDocsRoot();
|
||||
return formatTerminalLink(label ?? docsRoot, docsRoot, {
|
||||
fallback: docsRoot,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { type SelectItem, SelectList, type SettingItem, SettingsList } from "@mariozechner/pi-tui";
|
||||
import { type SelectItem, type SettingItem, SettingsList } from "@mariozechner/pi-tui";
|
||||
import {
|
||||
filterableSelectListTheme,
|
||||
searchableSelectListTheme,
|
||||
selectListTheme,
|
||||
settingsListTheme,
|
||||
} from "../theme/theme.js";
|
||||
import { FilterableSelectList, type FilterableSelectItem } from "./filterable-select-list.js";
|
||||
import { SearchableSelectList } from "./searchable-select-list.js";
|
||||
|
||||
export function createSelectList(items: SelectItem[], maxVisible = 7) {
|
||||
return new SelectList(items, maxVisible, selectListTheme);
|
||||
}
|
||||
|
||||
export function createSearchableSelectList(items: SelectItem[], maxVisible = 7) {
|
||||
return new SearchableSelectList(items, maxVisible, searchableSelectListTheme);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ import { loadSessions } from "./controllers/sessions.ts";
|
||||
import { icons } from "./icons.ts";
|
||||
import { iconForTab, pathForTab, titleForTab, type Tab } from "./navigation.ts";
|
||||
import { parseAgentSessionKey } from "./session-key.ts";
|
||||
import type { ThemeTransitionContext } from "./theme-transition.ts";
|
||||
import type { ThemeMode, ThemeName } from "./theme.ts";
|
||||
import type { ThemeMode } from "./theme.ts";
|
||||
import {
|
||||
listThinkingLevelLabels,
|
||||
normalizeThinkLevel,
|
||||
@@ -1088,13 +1087,6 @@ function resolveSessionScopedOptionLabel(
|
||||
return base;
|
||||
}
|
||||
|
||||
type ThemeOption = { id: ThemeName; label: string; icon: string };
|
||||
const THEME_OPTIONS: ThemeOption[] = [
|
||||
{ id: "claw", label: "Claw", icon: "🦀" },
|
||||
{ id: "knot", label: "Knot", icon: "🪢" },
|
||||
{ id: "dash", label: "Dash", icon: "📊" },
|
||||
];
|
||||
|
||||
type ThemeModeOption = { id: ThemeMode; label: string; short: string };
|
||||
const THEME_MODE_OPTIONS: ThemeModeOption[] = [
|
||||
{ id: "system", label: "System", short: "SYS" },
|
||||
@@ -1102,10 +1094,6 @@ const THEME_MODE_OPTIONS: ThemeModeOption[] = [
|
||||
{ id: "dark", label: "Dark", short: "DARK" },
|
||||
];
|
||||
|
||||
function currentThemeIcon(theme: ThemeName): string {
|
||||
return THEME_OPTIONS.find((o) => o.id === theme)?.icon ?? "🎨";
|
||||
}
|
||||
|
||||
export function renderTopbarThemeModeToggle(state: AppViewState) {
|
||||
const modeIcon = (mode: ThemeMode) => {
|
||||
if (mode === "system") {
|
||||
@@ -1162,78 +1150,3 @@ export function renderSidebarConnectionStatus(state: AppViewState) {
|
||||
></span>
|
||||
`;
|
||||
}
|
||||
|
||||
export function renderThemeToggle(state: AppViewState) {
|
||||
const setOpen = (orb: HTMLElement, nextOpen: boolean) => {
|
||||
orb.classList.toggle("theme-orb--open", nextOpen);
|
||||
const trigger = orb.querySelector<HTMLButtonElement>(".theme-orb__trigger");
|
||||
const menu = orb.querySelector<HTMLElement>(".theme-orb__menu");
|
||||
if (trigger) {
|
||||
trigger.setAttribute("aria-expanded", nextOpen ? "true" : "false");
|
||||
}
|
||||
if (menu) {
|
||||
menu.setAttribute("aria-hidden", nextOpen ? "false" : "true");
|
||||
}
|
||||
};
|
||||
|
||||
const toggleOpen = (e: Event) => {
|
||||
const orb = (e.currentTarget as HTMLElement).closest<HTMLElement>(".theme-orb");
|
||||
if (!orb) {
|
||||
return;
|
||||
}
|
||||
const isOpen = orb.classList.contains("theme-orb--open");
|
||||
if (isOpen) {
|
||||
setOpen(orb, false);
|
||||
} else {
|
||||
setOpen(orb, true);
|
||||
const close = (ev: MouseEvent) => {
|
||||
if (!orb.contains(ev.target as Node)) {
|
||||
setOpen(orb, false);
|
||||
document.removeEventListener("click", close);
|
||||
}
|
||||
};
|
||||
requestAnimationFrame(() => document.addEventListener("click", close));
|
||||
}
|
||||
};
|
||||
|
||||
const pick = (opt: ThemeOption, e: Event) => {
|
||||
const orb = (e.currentTarget as HTMLElement).closest<HTMLElement>(".theme-orb");
|
||||
if (orb) {
|
||||
setOpen(orb, false);
|
||||
}
|
||||
if (opt.id !== state.theme) {
|
||||
const context: ThemeTransitionContext = { element: orb ?? undefined };
|
||||
state.setTheme(opt.id, context);
|
||||
}
|
||||
};
|
||||
|
||||
return html`
|
||||
<div class="theme-orb" aria-label="Theme">
|
||||
<button
|
||||
type="button"
|
||||
class="theme-orb__trigger"
|
||||
title="Theme"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded="false"
|
||||
@click=${toggleOpen}
|
||||
>
|
||||
${currentThemeIcon(state.theme)}
|
||||
</button>
|
||||
<div class="theme-orb__menu" role="menu" aria-hidden="true">
|
||||
${THEME_OPTIONS.map(
|
||||
(opt) => html` <button
|
||||
type="button"
|
||||
class="theme-orb__option ${opt.id === state.theme ? "theme-orb__option--active" : ""}"
|
||||
title=${opt.label}
|
||||
role="menuitemradio"
|
||||
aria-checked=${opt.id === state.theme}
|
||||
aria-label=${opt.label}
|
||||
@click=${(e: Event) => pick(opt, e)}
|
||||
>
|
||||
${opt.icon}
|
||||
</button>`,
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -49,13 +49,6 @@ export function toNumber(value: string, fallback: number): number {
|
||||
return Number.isFinite(n) ? n : fallback;
|
||||
}
|
||||
|
||||
export function parseList(input: string): string[] {
|
||||
return input
|
||||
.split(/[,\n]/)
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.length > 0);
|
||||
}
|
||||
|
||||
export function stripThinkingTags(value: string): string {
|
||||
return stripAssistantInternalScaffolding(value);
|
||||
}
|
||||
@@ -90,10 +83,3 @@ export function formatTokens(tokens: number | null | undefined, fallback = "0"):
|
||||
const m = tokens / 1_000_000;
|
||||
return m < 10 ? `${m.toFixed(1)}M` : `${Math.round(m)}M`;
|
||||
}
|
||||
|
||||
export function formatPercent(value: number | null | undefined, fallback = "—"): string {
|
||||
if (value == null || !Number.isFinite(value)) {
|
||||
return fallback;
|
||||
}
|
||||
return `${(value * 100).toFixed(1)}%`;
|
||||
}
|
||||
|
||||
@@ -152,8 +152,3 @@ export function resolveToolDisplay(params: {
|
||||
export function formatToolDetail(display: ToolDisplay): string | undefined {
|
||||
return formatToolDetailText(display.detail, { prefixWithWith: true });
|
||||
}
|
||||
|
||||
export function formatToolSummary(display: ToolDisplay): string {
|
||||
const detail = formatToolDetail(display);
|
||||
return detail ? `${display.label}: ${detail}` : display.label;
|
||||
}
|
||||
|
||||
@@ -139,10 +139,7 @@ const getSessionModels = (session: UsageSessionQueryTarget): string[] => {
|
||||
const getSessionTools = (session: UsageSessionQueryTarget): string[] =>
|
||||
(session.usage?.toolUsage?.tools ?? []).map((tool) => tool.name.toLowerCase());
|
||||
|
||||
export const matchesUsageQuery = (
|
||||
session: UsageSessionQueryTarget,
|
||||
term: UsageQueryTerm,
|
||||
): boolean => {
|
||||
const matchesUsageQuery = (session: UsageSessionQueryTarget, term: UsageQueryTerm): boolean => {
|
||||
const value = normalizeQueryText(term.value ?? "");
|
||||
if (!value) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user