Files
openchamber/packages/ui/src/components/chat/revertedMessageDockState.ts
T
00821700de chore: remove dead code (59 unused files + ~125 unused exports) (#1835)
* chore: remove dead/unreferenced files across ui, vscode

Remove 59 unused source files (components, hooks, lib utils, stores,
barrels, and orphaned vscode github modules) that are not imported by
any entry-reachable code. Also drop a stale test mock for the removed
execCommands module.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>

* refactor: remove unused exported symbols (types, functions, consts, hooks)

Remove exported symbols whose identifier is referenced nowhere in the
repository (verified via repo-wide search), across ui types/contracts,
lib utilities, sync layer, stores, and components. Also drop the few
imports/private helpers orphaned by these removals.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>

* refactor: remove more unused exports (desktop, shortcuts, worktree, vscode)

Continue removing repo-wide unreferenced exported functions, consts and
types across lib/desktop, shortcuts, worktreeSessionCreator, sync, and
vscode gitService, with cascading orphaned helpers/imports cleaned up.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>

* chore: add dead-code cleanup tooling

* refactor: checkpoint dead-code cleanup

* refactor: remove dead-code suppressions

---------

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-06-26 19:27:53 +03:00

74 lines
2.3 KiB
TypeScript

import type { Message, Part } from '@opencode-ai/sdk/v2/client';
import type { State } from '@/sync/types';
type RevertedMessageRecord = {
message: Message & { role: 'user' };
parts: Part[];
};
export type RevertedMessageDockState = {
revertMessageID?: string;
records: RevertedMessageRecord[];
};
const EMPTY_PARTS: Part[] = [];
const EMPTY_REVERTED_RECORDS: RevertedMessageRecord[] = [];
export const EMPTY_REVERTED_MESSAGE_DOCK_STATE: RevertedMessageDockState = {
revertMessageID: undefined,
records: EMPTY_REVERTED_RECORDS,
};
const isUserMessage = (message: Message): message is Message & { role: 'user' } => {
return message.role === 'user';
};
const areRecordsEqual = (left: RevertedMessageRecord[], right: RevertedMessageRecord[]): boolean => {
if (left === right) return true;
if (left.length !== right.length) return false;
for (let index = 0; index < left.length; index += 1) {
if (left[index]?.message !== right[index]?.message || left[index]?.parts !== right[index]?.parts) {
return false;
}
}
return true;
};
export const buildRevertedMessageDockState = (
state: Pick<State, 'session' | 'message' | 'part'>,
sessionId: string | null,
previous: RevertedMessageDockState = EMPTY_REVERTED_MESSAGE_DOCK_STATE,
): RevertedMessageDockState => {
if (!sessionId) {
return EMPTY_REVERTED_MESSAGE_DOCK_STATE;
}
const session = state.session.find((item) => item.id === sessionId);
const revertMessageID = (session as { revert?: { messageID?: string } } | undefined)?.revert?.messageID;
if (!revertMessageID) {
return EMPTY_REVERTED_MESSAGE_DOCK_STATE;
}
const messages = state.message[sessionId] ?? [];
const records: RevertedMessageRecord[] = [];
for (const message of messages) {
if (!isUserMessage(message) || message.id < revertMessageID) {
continue;
}
records.push({
message,
parts: state.part[message.id] ?? EMPTY_PARTS,
});
}
const next = records.length === 0 ? EMPTY_REVERTED_RECORDS : records;
if (previous.revertMessageID === revertMessageID && areRecordsEqual(previous.records, next)) {
return previous;
}
return {
revertMessageID,
records: next,
};
};