mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
export interface ChatDraftImage {
|
||||
data: string;
|
||||
mimeType: string;
|
||||
}
|
||||
|
||||
export interface ChatDraft {
|
||||
value: string;
|
||||
images: ChatDraftImage[];
|
||||
}
|
||||
|
||||
const drafts = new Map<string, ChatDraft>();
|
||||
|
||||
function cloneDraft(draft: ChatDraft): ChatDraft {
|
||||
return {
|
||||
value: draft.value,
|
||||
images: draft.images.map((image) => ({ ...image })),
|
||||
};
|
||||
}
|
||||
|
||||
function isEmptyDraft(draft: ChatDraft): boolean {
|
||||
return !draft.value && draft.images.length === 0;
|
||||
}
|
||||
|
||||
export function getDraft(key: string): ChatDraft | null {
|
||||
const draft = drafts.get(key);
|
||||
return draft ? cloneDraft(draft) : null;
|
||||
}
|
||||
|
||||
export function setDraft(key: string, draft: ChatDraft): void {
|
||||
if (isEmptyDraft(draft)) {
|
||||
drafts.delete(key);
|
||||
return;
|
||||
}
|
||||
drafts.set(key, cloneDraft(draft));
|
||||
}
|
||||
|
||||
export function clearDraft(key: string): void {
|
||||
drafts.delete(key);
|
||||
}
|
||||
Reference in New Issue
Block a user