-
Notifications
You must be signed in to change notification settings - Fork 176
feat: add typed prompt relationships #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| import { ipcMain } from 'electron'; | ||
| import { IPC_CHANNELS } from '@prompthub/shared/constants'; | ||
| import { PromptDB } from '../database/prompt'; | ||
| import { PromptRelationDB } from '../database'; | ||
| import { FolderDB } from '../database/folder'; | ||
| import type Database from '../database/sqlite'; | ||
| import type { | ||
| CreatePromptRelationDTO, | ||
| CreatePromptDTO, | ||
| Folder, | ||
| Prompt, | ||
| PromptRelationQuery, | ||
| PromptVersion, | ||
| SearchQuery, | ||
| UpdatePromptRelationDTO, | ||
| UpdatePromptDTO, | ||
| } from '@prompthub/shared/types'; | ||
| import { syncPromptWorkspaceFromDatabase } from "../services/prompt-workspace"; | ||
|
|
@@ -18,6 +22,7 @@ import { syncPromptWorkspaceFromDatabase } from "../services/prompt-workspace"; | |
| * 注册 Prompt 相关 IPC 处理器 | ||
| */ | ||
| export function registerPromptIPC(db: PromptDB, folderDb: FolderDB, rawDb: Database.Database): void { | ||
| const relationDb = new PromptRelationDB(rawDb); | ||
| const syncWorkspace = () => { | ||
| syncPromptWorkspaceFromDatabase(db, folderDb); | ||
| }; | ||
|
|
@@ -275,4 +280,30 @@ export function registerPromptIPC(db: PromptDB, folderDb: FolderDB, rawDb: Datab | |
| syncWorkspace(); | ||
| return true; | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.PROMPT_RELATION_CREATE, async (_, data: CreatePromptRelationDTO) => { | ||
| const relation = relationDb.create(data); | ||
| syncWorkspace(); | ||
| return relation; | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.PROMPT_RELATION_LIST, async (_, query?: PromptRelationQuery) => { | ||
| return relationDb.list(query); | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.PROMPT_RELATION_UPDATE, async (_, id: string, data: UpdatePromptRelationDTO) => { | ||
| const relation = relationDb.update(id, data); | ||
| if (relation) { | ||
| syncWorkspace(); | ||
| } | ||
| return relation; | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.PROMPT_RELATION_DELETE, async (_, id: string) => { | ||
| const deleted = relationDb.delete(id); | ||
| if (deleted) { | ||
| syncWorkspace(); | ||
| } | ||
| return deleted; | ||
| }); | ||
|
Comment on lines
+284
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请在关系 IPC 处理器中补齐入参校验与结构化错误返回。 Line 284-308 的 4 个新增 handler 直接信任 renderer 传入数据,且未做统一 try/catch。建议先校验 建议修复(示例)+ const toIpcError = (error: unknown) => ({
+ ok: false as const,
+ error: { message: error instanceof Error ? error.message : "Unknown error" },
+ });
+
+ const assertRelationId = (value: unknown): string => {
+ if (typeof value !== "string" || value.trim().length === 0) {
+ throw new Error("Relation id is required");
+ }
+ return value;
+ };
+
ipcMain.handle(IPC_CHANNELS.PROMPT_RELATION_CREATE, async (_, data: CreatePromptRelationDTO) => {
- const relation = relationDb.create(data);
- syncWorkspace();
- return relation;
+ try {
+ // TODO: 替换为仓库统一的 runtime DTO 校验函数
+ const relation = relationDb.create(data);
+ syncWorkspace();
+ return { ok: true as const, data: relation };
+ } catch (error) {
+ return toIpcError(error);
+ }
});As per coding guidelines, “apps/desktop/src/main/ipc/**: All IPC handlers must validate input types and reject malformed payloads before processing” and “IPC handlers must catch errors and return structured error responses, never crash the main process silently”. 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Relation ipc lacks validation
📘 Rule violation⛨ Security8.2Agent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools