chore: remove unused dead code

This commit is contained in:
chengyongru
2026-07-07 15:41:27 +08:00
committed by Xubin Ren
parent 29e99d3742
commit 3f33ff3143
12 changed files with 7 additions and 154 deletions
+1 -37
View File
@@ -4,7 +4,7 @@ import { logoFallbackUrls } from "@/lib/provider-brand";
import type { CliAppInfo, McpPresetInfo } from "@/lib/types";
import { cn } from "@/lib/utils";
export type CliAppMentionSegment =
type CliAppMentionSegment =
| { kind: "text"; text: string }
| { kind: "cli"; text: string; app: CliAppInfo };
@@ -36,42 +36,6 @@ export function mcpPresetInitials(preset: Pick<McpPresetInfo, "name" | "display_
);
}
export function splitCliAppMentionSegments(
value: string,
cliApps: CliAppInfo[],
): CliAppMentionSegment[] {
if (!value || cliApps.length === 0) return value ? [{ kind: "text", text: value }] : [];
const appsByName = new Map(
cliApps
.filter((app) => app.installed)
.map((app) => [app.name.toLowerCase(), app]),
);
if (appsByName.size === 0) return [{ kind: "text", text: value }];
const segments: CliAppMentionSegment[] = [];
const mentionRe = /(^|[\s([{])@([a-z0-9_-]+)\b/gi;
let cursor = 0;
let match: RegExpExecArray | null;
while ((match = mentionRe.exec(value)) !== null) {
const prefix = match[1] ?? "";
const name = match[2] ?? "";
const app = appsByName.get(name.toLowerCase());
if (!app) continue;
const mentionStart = match.index + prefix.length;
const mentionEnd = mentionStart + name.length + 1;
if (mentionStart > cursor) {
segments.push({ kind: "text", text: value.slice(cursor, mentionStart) });
}
segments.push({ kind: "cli", text: value.slice(mentionStart, mentionEnd), app });
cursor = mentionEnd;
}
if (cursor < value.length) {
segments.push({ kind: "text", text: value.slice(cursor) });
}
return segments.length ? segments : [{ kind: "text", text: value }];
}
export function splitCapabilityMentionSegments(
value: string,
cliApps: CliAppInfo[],
@@ -19,21 +19,6 @@ interface ThreadMessagesProps {
export type DisplayUnit = TurnUnit;
/** True when this unit index is the last assistant text slice before the next user message (or end of thread). */
export function isFinalAssistantSliceBeforeNextUser(
units: DisplayUnit[],
index: number,
): boolean {
const u = units[index];
if (u.type !== "message" || u.message.role !== "assistant") return true;
for (let j = index + 1; j < units.length; j++) {
const v = units[j];
if (v.type === "message" && v.message.role === "user") break;
return false;
}
return true;
}
export function buildDisplayUnits(
messages: UIMessage[],
isStreaming = false,
-13
View File
@@ -57,19 +57,6 @@ export function readStoredLocale(): SupportedLocale | null {
}
}
export function detectNavigatorLocale(): SupportedLocale {
if (typeof navigator === "undefined") return defaultLocale;
const candidates = [
...(navigator.languages ?? []),
navigator.language,
].filter(Boolean);
for (const locale of candidates) {
const normalized = normalizeLocale(locale);
if (normalized) return normalized;
}
return defaultLocale;
}
export function resolveInitialLocale(): SupportedLocale {
return readStoredLocale() ?? defaultLocale;
}
-14
View File
@@ -12,7 +12,6 @@ import {
} from "@/workers/imageEncode.worker";
export type { EncodeResponse, EncodeSuccess, EncodeFailure } from "@/workers/imageEncode.worker";
export { TARGET_MAX_BYTES } from "@/workers/imageEncode.worker";
type Pending = {
resolve: (r: EncodeResponse) => void;
@@ -82,16 +81,3 @@ export async function encodeImage(file: File): Promise<EncodeResponse> {
}
});
}
/** Release the singleton Worker (tests / teardown). */
export function disposeImageEncoder(): void {
if (worker) {
worker.terminate();
worker = null;
}
bootAttempted = false;
for (const [, entry] of pending) {
entry.reject(new Error("image encoder disposed"));
}
pending.clear();
}
-21
View File
@@ -1,26 +1,5 @@
import type { ToolProgressEvent } from "@/lib/types";
/** Drop duplicate tool_call objects (same id or identical formatted trace). */
export function dedupeToolCallsForUi(calls: unknown): unknown[] {
if (!Array.isArray(calls) || calls.length === 0) return [];
const seen = new Set<string>();
const out: unknown[] = [];
for (const c of calls) {
let key: string | null = null;
if (c && typeof c === "object" && "id" in c) {
const id = (c as { id?: unknown }).id;
if (typeof id === "string" && id.length > 0) key = `id:${id}`;
}
if (key == null) {
key = formatToolCallTrace(c) ?? "";
}
if (!key || seen.has(key)) continue;
seen.add(key);
out.push(c);
}
return out;
}
export function formatToolCallTrace(call: unknown): string | null {
if (!call || typeof call !== "object") return null;
const item = call as {