mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor: extract WS API into separate file
This commit is contained in:
parent
39fecb3ffe
commit
777d5ab3b7
@ -8,3 +8,4 @@ export * from "./lib/mime_type.js";
|
|||||||
export * from "./lib/bulk_actions.js";
|
export * from "./lib/bulk_actions.js";
|
||||||
export * from "./lib/server_api.js";
|
export * from "./lib/server_api.js";
|
||||||
export * from "./lib/shared_constants.js";
|
export * from "./lib/shared_constants.js";
|
||||||
|
export * from "./lib/ws_api.js";
|
||||||
|
@ -242,126 +242,3 @@ export interface SchemaResponse {
|
|||||||
type: string;
|
type: string;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityChange {
|
|
||||||
id?: number | null;
|
|
||||||
noteId?: string;
|
|
||||||
entityName: string;
|
|
||||||
entityId: string;
|
|
||||||
entity?: any;
|
|
||||||
positions?: Record<string, number>;
|
|
||||||
hash: string;
|
|
||||||
utcDateChanged?: string;
|
|
||||||
utcDateModified?: string;
|
|
||||||
utcDateCreated?: string;
|
|
||||||
isSynced: boolean | 1 | 0;
|
|
||||||
isErased: boolean | 1 | 0;
|
|
||||||
componentId?: string | null;
|
|
||||||
changeId?: string | null;
|
|
||||||
instanceId?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityRow {
|
|
||||||
isDeleted?: boolean;
|
|
||||||
content?: Buffer | string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityChangeRecord {
|
|
||||||
entityChange: EntityChange;
|
|
||||||
entity?: EntityRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskStatus<TypeT, DataT, ResultT> = {
|
|
||||||
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: ResultT;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskDefinitions =
|
|
||||||
TaskStatus<"protectNotes", { protect: boolean; }, null>
|
|
||||||
| TaskStatus<"importNotes", null, { importedNoteId: string }>
|
|
||||||
| TaskStatus<"importAttachments", null, { parentNoteId?: string; importedNoteId: string }>
|
|
||||||
| TaskStatus<"deleteNotes", null, null>
|
|
||||||
| TaskStatus<"undeleteNotes", null, null>
|
|
||||||
| TaskStatus<"export", null, null>
|
|
||||||
;
|
|
||||||
|
|
||||||
export type TaskType = TaskDefinitions["taskType"];
|
|
||||||
|
|
||||||
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>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
122
packages/commons/src/lib/ws_api.ts
Normal file
122
packages/commons/src/lib/ws_api.ts
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
export interface EntityChange {
|
||||||
|
id?: number | null;
|
||||||
|
noteId?: string;
|
||||||
|
entityName: string;
|
||||||
|
entityId: string;
|
||||||
|
entity?: any;
|
||||||
|
positions?: Record<string, number>;
|
||||||
|
hash: string;
|
||||||
|
utcDateChanged?: string;
|
||||||
|
utcDateModified?: string;
|
||||||
|
utcDateCreated?: string;
|
||||||
|
isSynced: boolean | 1 | 0;
|
||||||
|
isErased: boolean | 1 | 0;
|
||||||
|
componentId?: string | null;
|
||||||
|
changeId?: string | null;
|
||||||
|
instanceId?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityRow {
|
||||||
|
isDeleted?: boolean;
|
||||||
|
content?: Buffer | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityChangeRecord {
|
||||||
|
entityChange: EntityChange;
|
||||||
|
entity?: EntityRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskStatus<TypeT, DataT, ResultT> = {
|
||||||
|
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: ResultT;
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskDefinitions =
|
||||||
|
TaskStatus<"protectNotes", { protect: boolean; }, null>
|
||||||
|
| TaskStatus<"importNotes", null, { importedNoteId: string }>
|
||||||
|
| TaskStatus<"importAttachments", null, { parentNoteId?: string; importedNoteId: string }>
|
||||||
|
| TaskStatus<"deleteNotes", null, null>
|
||||||
|
| TaskStatus<"undeleteNotes", null, null>
|
||||||
|
| TaskStatus<"export", null, null>
|
||||||
|
;
|
||||||
|
|
||||||
|
export type TaskType = TaskDefinitions["taskType"];
|
||||||
|
|
||||||
|
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>;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user