Download src/stores/pending-task-attachments-store.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/stores/pending-task-attachments-store.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/stores/pending-task-attachments-store.ts
-
curl -L -o pending-task-attachments-store.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/stores/pending-task-attachments-store.ts
1.46 kB
| import { create } from "zustand"; | |
| export interface PendingTaskAttachments { | |
| content: string; | |
| images: File[]; | |
| files: File[]; | |
| imagesMarkedUploadAsFile: string[]; | |
| } | |
| interface PendingTaskAttachmentsState { | |
| byTaskId: Record<string, PendingTaskAttachments>; | |
| setPendingTaskAttachments: ( | |
| taskId: string, | |
| payload: PendingTaskAttachments, | |
| ) => void; | |
| consumePendingTaskAttachments: ( | |
| taskId: string, | |
| ) => PendingTaskAttachments | null; | |
| } | |
| export const usePendingTaskAttachmentsStore = | |
| create<PendingTaskAttachmentsState>()((set, get) => ({ | |
| byTaskId: {}, | |
| setPendingTaskAttachments: (taskId, payload) => | |
| set((state) => ({ | |
| byTaskId: { ...state.byTaskId, [taskId]: payload }, | |
| })), | |
| consumePendingTaskAttachments: (taskId) => { | |
| const payload = get().byTaskId[taskId]; | |
| if (!payload) { | |
| return null; | |
| } | |
| set((state) => { | |
| const { [taskId]: _removed, ...rest } = state.byTaskId; | |
| return { byTaskId: rest }; | |
| }); | |
| return payload; | |
| }, | |
| })); | |
| export function setPendingTaskAttachments( | |
| taskId: string, | |
| payload: PendingTaskAttachments, | |
| ): void { | |
| usePendingTaskAttachmentsStore | |
| .getState() | |
| .setPendingTaskAttachments(taskId, payload); | |
| } | |
| export function consumePendingTaskAttachments( | |
| taskId: string, | |
| ): PendingTaskAttachments | null { | |
| return usePendingTaskAttachmentsStore | |
| .getState() | |
| .consumePendingTaskAttachments(taskId); | |
| } | |