refactor: proper websocket message types

This commit is contained in:
Elian Doran
2025-09-13 12:54:53 +03:00
parent 998688573d
commit 4cd0702cbb
19 changed files with 164 additions and 170 deletions

View File

@@ -270,3 +270,96 @@ export interface EntityChangeRecord {
entityChange: EntityChange;
entity?: EntityRow;
}
type TaskStatus<TypeT, DataT> = {
type: "taskProgressCount",
taskId: string;
taskType: TypeT;
data: DataT,
progressCount: number
} | {
type: "taskError",
taskId: string;
taskType: TypeT;
data: DataT;
message: string;
} | {
type: "taskSucceeded",
taskId: string;
taskType: TypeT;
data: DataT;
result?: string | Record<string, string | undefined>
}
type TaskDefinitions =
TaskStatus<"protectNotes", { protect: boolean; }>
| TaskStatus<"importNotes", null>
| TaskStatus<"importAttachments", null>
| TaskStatus<"deleteNotes", null>
| TaskStatus<"undeleteNotes", null>
| TaskStatus<"export", null>
;
export interface OpenedFileUpdateStatus {
entityType: string;
entityId: string;
lastModifiedMs?: number;
filePath: string;
}
export type WebSocketMessage = TaskDefinitions | {
type: "ping"
} | {
type: "frontend-update",
data: {
lastSyncedPush: number,
entityChanges: EntityChange[]
}
} | {
type: "openNote",
noteId: string
} | OpenedFileUpdateStatus & {
type: "openedFileUpdated"
} | {
type: "protectedSessionLogin"
} | {
type: "protectedSessionLogout"
} | {
type: "toast",
message: string;
} | {
type: "api-log-messages",
noteId: string,
messages: string[]
} | {
type: "execute-script";
script: string;
params: unknown[];
startNoteId?: string;
currentNoteId: string;
originEntityName: string;
originEntityId?: string | null;
} | {
type: "reload-frontend";
reason: string;
} | {
type: "sync-pull-in-progress" | "sync-push-in-progress" | "sync-finished" | "sync-failed";
lastSyncedPush: number;
} | {
type: "consistency-checks-failed"
} | {
type: "llm-stream",
chatNoteId: string;
done?: boolean;
error?: string;
thinking?: string;
content?: string;
toolExecution?: {
action?: string;
tool?: string;
toolCallId?: string;
result?: string | Record<string, any>;
error?: string;
args?: Record<string, unknown>;
}
}