From 25ed91ffeb93e8fa2e81765f422a9817037a8763 Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Thu, 12 Nov 2026 22:07:09 +0800 Subject: [PATCH] refactor: drop unreferenced dead code Every removed symbol has no reference anywhere in the tree (Python AST and TypeScript identifier scans over all tracked files, including tests, docs, WebUI/TUI clients, and JSON/YAML data): - nanobot/webui/settings_api.py: four aliases with no importer and no in-module use; the helpers that tests still import stay. - nanobot/sdk/types.py: snapshot_from_payload had no caller since session restore moved to snapshot_from_session. - nanobot/session/jsonl_migration.py: INTRODUCED_VERSION and LAST_SUPPORTED_RELEASE_LINE duplicated the module docstring. - nanobot/providers/transcription.py: StepFunTranscriptionProvider._DEFAULT_URL was superseded by _resolve_stepfun_asr_url. - nanobot/channels/whatsapp_agent/protocol.py: CODE_MISSING_AUTH is neither exported nor compared; validation still checks the wire value 190. - webui/src/lib/canonical-run-snapshot.ts: canonicalRunSnapshot had no caller. - webui/src/components/icons/product-icons.tsx: SendIcon and RunningTaskIcon are not rendered anywhere. - webui/src/components/thread/AgentActivityCluster.tsx: drop an unused isAgentActivityMember re-export and its import. - webui: drop the unused micromark-util-decode-string dependency. Framework-dispatched code (Typer commands, pydantic validators, pytest hooks and fixtures, channel runtime classes, ast visitor hooks) was excluded from the scans, so the change removes only code nothing references. --- nanobot/channels/whatsapp_agent/protocol.py | 1 - nanobot/providers/transcription.py | 2 -- nanobot/sdk/types.py | 24 +------------------ nanobot/session/jsonl_migration.py | 2 -- nanobot/webui/settings_api.py | 5 ---- webui/bun.lock | 1 - webui/package.json | 1 - webui/src/components/icons/product-icons.tsx | 2 -- .../thread/AgentActivityCluster.tsx | 3 --- webui/src/lib/canonical-run-snapshot.ts | 16 ------------- 10 files changed, 1 insertion(+), 56 deletions(-) diff --git a/nanobot/channels/whatsapp_agent/protocol.py b/nanobot/channels/whatsapp_agent/protocol.py index cca6ceb17..8f11f844a 100644 --- a/nanobot/channels/whatsapp_agent/protocol.py +++ b/nanobot/channels/whatsapp_agent/protocol.py @@ -29,7 +29,6 @@ RATE_LIMITS = { # error.code values that carry a specific recovery contract. CODE_INVALID_TOKEN = 100 -CODE_MISSING_AUTH = 190 CODE_RATE_LIMITED = 130429 CODE_NOT_CREATOR = 131005 CODE_BAD_REQUEST = 131009 diff --git a/nanobot/providers/transcription.py b/nanobot/providers/transcription.py index b318178e8..4d8f5b671 100644 --- a/nanobot/providers/transcription.py +++ b/nanobot/providers/transcription.py @@ -708,8 +708,6 @@ class XiaomiMiMoTranscriptionProvider: class StepFunTranscriptionProvider: """Voice transcription provider using StepFun ASR SSE endpoint.""" - _DEFAULT_URL = "https://api.stepfun.com/v1/audio/asr/sse" - def __init__( self, api_key: str | None = None, diff --git a/nanobot/sdk/types.py b/nanobot/sdk/types.py index be4f350e5..e6a3be794 100644 --- a/nanobot/sdk/types.py +++ b/nanobot/sdk/types.py @@ -2,7 +2,7 @@ from __future__ import annotations from copy import deepcopy from dataclasses import dataclass, field -from typing import Any, Literal, Mapping, TypeAlias, cast +from typing import Any, Literal, TypeAlias, cast from nanobot.providers.base import LLMUsage from nanobot.runtime_context import public_history_messages @@ -137,28 +137,6 @@ def snapshot_from_session( ) -def snapshot_from_payload( - payload: Mapping[str, Any], - *, - include_runtime_context: bool = False, -) -> SessionSnapshot: - raw_messages: list[Any] = list(payload.get("messages") or []) - messages: list[dict[str, Any]] = [ - deepcopy(dict(cast(Mapping[str, Any], message))) - for message in raw_messages - if isinstance(message, Mapping) - ] - if not include_runtime_context: - messages = public_history_messages(messages) - return SessionSnapshot( - key=str(payload.get("key") or ""), - created_at=payload.get("created_at"), - updated_at=payload.get("updated_at"), - metadata=deepcopy(dict(cast(Mapping[str, Any], payload.get("metadata") or {}))), - messages=messages, - ) - - def result_from_response(response: Any, capture: Any) -> RunResult: content = (response.content if response else None) or "" metadata = dict(response.metadata) if response and response.metadata else {} diff --git a/nanobot/session/jsonl_migration.py b/nanobot/session/jsonl_migration.py index 0b1a89b54..c46097251 100644 --- a/nanobot/session/jsonl_migration.py +++ b/nanobot/session/jsonl_migration.py @@ -26,8 +26,6 @@ from nanobot.session.manager import Session if TYPE_CHECKING: from nanobot.session.sqlite_store import SqliteSessionStore -INTRODUCED_VERSION = "0.3.6" -LAST_SUPPORTED_RELEASE_LINE = "0.4.x" SUNSET_VERSION = "0.5.0" WORKSPACE_BACKUP_DIR = "jsonl-backup" _WORKSPACE_SOURCES_KEY = "jsonl_workspace_sources" diff --git a/nanobot/webui/settings_api.py b/nanobot/webui/settings_api.py index 3e98423aa..3cfd4d8ec 100644 --- a/nanobot/webui/settings_api.py +++ b/nanobot/webui/settings_api.py @@ -31,14 +31,9 @@ RuntimeSurface = Literal["browser", "native"] # Preserve established direct imports of focused helpers. _docs_version = system.docs_version -_parse_bool = contracts.parse_bool _query_first = contracts.query_first -_query_first_alias = contracts.query_first_alias -_query_has_alias = contracts.query_has_alias _model_catalog_kind = models.model_catalog_kind _oauth_provider_status = models.oauth_provider_status -_provider_requires_api_key = models.provider_requires_api_key -_reasoning_effort_values_for = models.reasoning_effort_values_for _RUNTIME_CAPABILITIES = { diff --git a/webui/bun.lock b/webui/bun.lock index 9641a465e..2b372f8ee 100644 --- a/webui/bun.lock +++ b/webui/bun.lock @@ -23,7 +23,6 @@ "i18next": "^26.0.6", "lucide-react": "^0.469.0", "micromark-factory-space": "^2.0.1", - "micromark-util-decode-string": "^2.0.1", "motion": "^14.4.0", "pele": "1.9.0", "qrcode": "^1.5.4", diff --git a/webui/package.json b/webui/package.json index 236009a33..7a7be27a5 100644 --- a/webui/package.json +++ b/webui/package.json @@ -36,7 +36,6 @@ "i18next": "^26.0.6", "lucide-react": "^0.469.0", "micromark-factory-space": "^2.0.1", - "micromark-util-decode-string": "^2.0.1", "motion": "^14.4.0", "pele": "1.9.0", "qrcode": "^1.5.4", diff --git a/webui/src/components/icons/product-icons.tsx b/webui/src/components/icons/product-icons.tsx index 3673142fe..d142ef075 100644 --- a/webui/src/components/icons/product-icons.tsx +++ b/webui/src/components/icons/product-icons.tsx @@ -33,7 +33,6 @@ export const SystemIcon = productIcon("system", <>); export const AboutIcon = productIcon("about", <>); export const AttachIcon = productIcon("attach", ); -export const SendIcon = productIcon("send", <>); export const VoiceIcon = productIcon("voice", <>); export const StopIcon = productIcon("stop", ); export const RestrictedAccessIcon = productIcon("restricted-access", <>); @@ -46,7 +45,6 @@ export const DelegationIcon = productIcon("delegation", <>); export const TaskMessageIcon = productIcon("task-message", <>); export const QueuedTaskIcon = productIcon("task-queued", <>); -export const RunningTaskIcon = productIcon("task-running", <>); export const StoppingTaskIcon = productIcon("task-stopping", <>); export const CompletedTaskIcon = productIcon("task-completed", <>); export const CancelledTaskIcon = productIcon("task-cancelled", <>); diff --git a/webui/src/components/thread/AgentActivityCluster.tsx b/webui/src/components/thread/AgentActivityCluster.tsx index 2f16e0cb6..7ee840be3 100644 --- a/webui/src/components/thread/AgentActivityCluster.tsx +++ b/webui/src/components/thread/AgentActivityCluster.tsx @@ -44,7 +44,6 @@ import { import { WebSearchRun } from "@/components/thread/activity/WebSearchRun"; import { webSearchRunsByTraceLine } from "@/components/thread/activity/web-search-model"; import { - isAgentActivityMember, isReasoningOnlyAssistant, } from "@/lib/activity-timeline"; import { useFileEditDisplayMode } from "@/hooks/useFileEditDisplayMode"; @@ -68,8 +67,6 @@ import type { const EMPTY_CLI_APPS: CliAppInfo[] = []; const EMPTY_MCP_PRESETS: McpPresetInfo[] = []; -export { isAgentActivityMember }; - interface ActivityCounts { reasoningSteps: number; toolCalls: number; diff --git a/webui/src/lib/canonical-run-snapshot.ts b/webui/src/lib/canonical-run-snapshot.ts index 231cabf2e..ed32a952e 100644 --- a/webui/src/lib/canonical-run-snapshot.ts +++ b/webui/src/lib/canonical-run-snapshot.ts @@ -8,22 +8,6 @@ export function completedAssistantTurnIds(messages: UIMessage[]): string[] { )))); } -export function canonicalRunSnapshot( - messages: UIMessage[], - hasPendingToolCalls: boolean, - activeTurnId: string | null, - completionIdsProvided = false, -): CanonicalRunSnapshot { - return { - observedTurnIds: Array.from(new Set(messages.flatMap((message) => ( - message.role === "user" && message.turnId ? [message.turnId] : [] - )))), - hasPendingToolCalls, - activeTurnId, - completionIdsProvided, - }; -} - export function persistedCanonicalRunState(body: WebuiThreadPersistedPayload): { completedTurnIds: string[]; snapshot: CanonicalRunSnapshot;