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.
38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import type { CanonicalRunSnapshot } from "./nanobot-client";
|
|
import { projectThreadEvents } from "./thread-event-projection";
|
|
import type { UIMessage, WebuiThreadPersistedPayload } from "./types";
|
|
|
|
export function completedAssistantTurnIds(messages: UIMessage[]): string[] {
|
|
return Array.from(new Set(messages.flatMap((message) => (
|
|
message.role === "assistant" && message.turnId ? [message.turnId] : []
|
|
))));
|
|
}
|
|
|
|
export function persistedCanonicalRunState(body: WebuiThreadPersistedPayload): {
|
|
completedTurnIds: string[];
|
|
snapshot: CanonicalRunSnapshot;
|
|
} {
|
|
const suppliedCompletionIds = Array.isArray(body.completed_turn_ids) ? body.completed_turn_ids : null;
|
|
// User identities and explicit completion are wire facts, not rendered messages.
|
|
const snapshot: CanonicalRunSnapshot = {
|
|
observedTurnIds: Array.from(new Set(body.events.flatMap((event) => (
|
|
event.event === "user_message" && event.turn_id ? [event.turn_id] : []
|
|
)))),
|
|
hasPendingToolCalls: body.has_pending_tool_calls !== false,
|
|
activeTurnId: typeof body.active_turn_id === "string" ? body.active_turn_id : null,
|
|
completionIdsProvided: suppliedCompletionIds !== null,
|
|
};
|
|
const completedTurnIds = suppliedCompletionIds?.filter(
|
|
(turnId) => typeof turnId === "string" && turnId.length > 0,
|
|
) ?? [];
|
|
// The gateway excludes incomplete transcript turns even when their display
|
|
// projection contains turn_end. Only older hosts need idle-state inference.
|
|
if (suppliedCompletionIds === null && !snapshot.hasPendingToolCalls && !snapshot.activeTurnId) {
|
|
completedTurnIds.push(...body.events.flatMap((event) => (
|
|
event.event === "turn_end" && event.turn_id ? [event.turn_id] : []
|
|
)));
|
|
completedTurnIds.push(...completedAssistantTurnIds(projectThreadEvents(body.events)));
|
|
}
|
|
return { completedTurnIds: Array.from(new Set(completedTurnIds)), snapshot };
|
|
}
|