Open History to see the last commit
1import {
2 AuthOrchestrationOperateScope,
3 AuthOrchestrationReadScope,
4 PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES,
5 type ChatAttachment,
6 type EnvironmentId,
7} from "@t3tools/contracts";
8import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
9import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
10import {
11 deletePendingAttachmentUpload,
12 runAttachmentUploadCycle,
13 verifyPersistedAttachmentUpload,
14 type PersistedAttachmentVerification,
15} from "@t3tools/client-runtime/state/attachments";
16import { create } from "zustand";
17import * as Option from "effect/Option";
18import { AsyncResult } from "effect/reactivity";
19
20import {
21 DraftId,
22 useComposerDraftStore,
23 type ComposerFileAttachment,
24 type ComposerImageAttachment,
25 type ComposerThreadTarget,
26} from "../composerDraftStore";
27import { appAtomRegistry } from "../rpc/atomRegistry";
28import { environmentCatalog } from "../connection/catalog";
29import { assetEnvironment } from "../state/assets";
30import { attachmentEnvironment } from "../state/attachments";
31import { readEnvironmentScope, readPreparedConnection } from "../state/session";
32import type { AttachmentUploadState, ReadyAttachmentUpload } from "./attachmentUploadState";
33
34const MAX_UPLOADS_PER_ENVIRONMENT = 3;
35const UPLOAD_TIMEOUT_MS = 5 * 60_000;
36
37interface AttachmentUploadStore {
38 readonly uploadsByImageId: Readonly<Record<string, AttachmentUploadState>>;
39}
40
41export const useAttachmentUploadStore = create<AttachmentUploadStore>(() => ({
42 uploadsByImageId: {},
43}));
44
45interface UploadJob {
46 readonly image: ComposerImageAttachment | ComposerFileAttachment;
47 readonly environmentId: EnvironmentId;
48 /** Original owner; completion resolves the current owner because uploads can outlive draft moves. */
49 readonly draftTarget?: ComposerThreadTarget;
50 readonly previous?: ReadyAttachmentUpload;
51 /** Draft-owned; delete only through releasePersistedAttachmentUpload, never queue cancel/retry. */
52 readonly persistedAttachmentId?: string;
53 readonly settled: Promise<void>;
54 resolveSettled: () => void;
55 attachmentId: string | null;
56 cancelled: boolean;
57 abort: (() => void) | null;
58 stopWatchingConnection: () => void;
59}
60
61type DraftFileOwner = Pick<UploadJob, "image" | "environmentId" | "draftTarget">;
62
63const jobsByImageId = new Map<string, UploadJob>();
64const queue: UploadJob[] = [];
65const activeUploadsByEnvironment = new Map<EnvironmentId, number>();
66
67function setUploadState(imageId: string, upload: AttachmentUploadState): void {
68 useAttachmentUploadStore.setState((state) => ({
69 uploadsByImageId: { ...state.uploadsByImageId, [imageId]: upload },
70 }));
71}
72
73function clearUploadState(imageId: string): void {
74 useAttachmentUploadStore.setState((state) => {
75 if (!(imageId in state.uploadsByImageId)) {
76 return state;
77 }
78 const uploadsByImageId = { ...state.uploadsByImageId };
79 delete uploadsByImageId[imageId];
80 return { uploadsByImageId };
81 });
82}
83
84export function readAttachmentUpload(imageId: string): AttachmentUploadState | undefined {
85 return useAttachmentUploadStore.getState().uploadsByImageId[imageId];
86}
87
88function resolveCurrentFileDraftTarget(job: DraftFileOwner): ComposerThreadTarget | undefined {
89 if (job.draftTarget === undefined || job.image.type !== "file") {
90 return undefined;
91 }
92 const store = useComposerDraftStore.getState();
93 for (const [key, draft] of Object.entries(store.draftsByThreadKey)) {
94 if (!draft.files.some((file) => file.id === job.image.id)) {
95 continue;
96 }
97 const draftSession = store.draftThreadsByThreadKey[key];
98 if (draftSession !== undefined) {
99 if (draftSession.environmentId === job.environmentId) {
100 return DraftId.make(key);
101 }
102 continue;
103 }
104 if (typeof job.draftTarget === "string" && job.draftTarget === key) {
105 return DraftId.make(key);
106 }
107 const threadRef = parseScopedThreadKey(key);
108 if (threadRef?.environmentId === job.environmentId) {
109 return threadRef;
110 }
111 }
112 return undefined;
113}
114
115/** Persist background completions even when no composer is mounted. */
116function stampDraftFileUpload(job: DraftFileOwner, attachmentId: string): void {
117 const draftTarget = resolveCurrentFileDraftTarget(job);
118 if (draftTarget === undefined) {
119 return;
120 }
121 useComposerDraftStore
122 .getState()
123 .setFileUpload(draftTarget, job.image.id, job.environmentId, attachmentId);
124}
125
126function deletePendingUpload(environmentId: EnvironmentId, attachmentId: string): void {
127 if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return;
128 deletePendingAttachmentUpload({
129 registry: appAtomRegistry,
130 remove: attachmentEnvironment.remove,
131 environmentId,
132 attachmentId,
133 });
134}
135
136function uploadBytes(input: {
137 readonly url: string;
138 readonly file: File;
139 readonly mimeType: string;
140 readonly onProgress: (progress: number) => void;
141}): { readonly done: Promise<void>; readonly abort: () => void } {
142 const xhr = new XMLHttpRequest();
143 const done = new Promise<void>((resolve, reject) => {
144 xhr.open("POST", input.url, true);
145 xhr.timeout = UPLOAD_TIMEOUT_MS;
146 xhr.setRequestHeader("Content-Type", input.mimeType);
147 xhr.upload.addEventListener("progress", (event) => {
148 if (event.lengthComputable && event.total > 0) {
149 input.onProgress(event.loaded / event.total);
150 }
151 });
152 xhr.addEventListener("load", () => {
153 if (xhr.status >= 200 && xhr.status < 300) {
154 resolve();
155 } else {
156 reject(new Error(`Upload rejected (${xhr.status})`));
157 }
158 });
159 xhr.addEventListener("error", () => reject(new Error("Upload failed")));
160 xhr.addEventListener("timeout", () => reject(new Error("Upload timed out")));
161 xhr.addEventListener("abort", () => reject(new Error("Upload cancelled")));
162 xhr.send(input.file);
163 });
164
165 return { done, abort: () => xhr.abort() };
166}
167
168async function runUpload(job: UploadJob): Promise<void> {
169 if (!readEnvironmentScope(job.environmentId, AuthOrchestrationOperateScope)) {
170 setUploadState(job.image.id, {
171 status: "failed",
172 environmentId: job.environmentId,
173 reason: "This connection cannot upload attachments.",
174 ...(job.previous ? { previous: job.previous } : {}),
175 });
176 return;
177 }
178 if (job.persistedAttachmentId) {
179 const verification = await verifyPersistedAttachmentUpload({
180 registry: appAtomRegistry,
181 createAssetUrl: assetEnvironment.createUrl,
182 environmentId: job.environmentId,
183 attachmentId: job.persistedAttachmentId,
184 });
185 if (job.cancelled) {
186 return;
187 }
188 if (verification.status === "verified") {
189 setUploadState(job.image.id, {
190 status: "ready",
191 environmentId: job.environmentId,
192 attachmentId: job.persistedAttachmentId,
193 });
194 stampDraftFileUpload(job, job.persistedAttachmentId);
195 return;
196 }
197 if (verification.status === "missing" && !job.image.file && job.image.type === "file") {
198 const draftTarget = resolveCurrentFileDraftTarget(job);
199 if (
200 draftTarget !== undefined &&
201 useComposerDraftStore
202 .getState()
203 .markFileUploadMissing(
204 draftTarget,
205 job.image.id,
206 job.environmentId,
207 job.persistedAttachmentId,
208 )
209 ) {
210 clearUploadState(job.image.id);
211 return;
212 }
213 }
214 if (verification.status === "failed" || !job.image.file) {
215 // Failed-state ids get deleted on retry/release; exclude persisted ids after transient verification failure.
216 setUploadState(job.image.id, {
217 status: "failed",
218 environmentId: job.environmentId,
219 reason:
220 verification.status === "missing"
221 ? "Uploaded file expired. Remove it and attach it again."
222 : "Uploaded file could not be verified. Retry when the server reconnects.",
223 ...(job.previous ? { previous: job.previous } : {}),
224 });
225 return;
226 }
227 }
228
229 const mimeType =
230 job.image.type === "file"
231 ? job.image.mimeType.toLowerCase()
232 : PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES.find(
233 (supportedMimeType) => supportedMimeType === job.image.mimeType.toLowerCase(),
234 );
235 if (!mimeType) {
236 setUploadState(job.image.id, {
237 status: "failed",
238 environmentId: job.environmentId,
239 reason: "Unsupported image type",
240 ...(job.previous ? { previous: job.previous } : {}),
241 });
242 return;
243 }
244 const file = job.image.file;
245 if (!file) {
246 setUploadState(job.image.id, {
247 status: "failed",
248 environmentId: job.environmentId,
249 reason: "Original file is no longer available",
250 ...(job.previous ? { previous: job.previous } : {}),
251 });
252 return;
253 }
254
255 let lastStep = -1;
256 if (!readEnvironmentScope(job.environmentId, AuthOrchestrationOperateScope)) {
257 setUploadState(job.image.id, {
258 status: "failed",
259 environmentId: job.environmentId,
260 reason: "This connection cannot upload attachments.",
261 ...(job.previous ? { previous: job.previous } : {}),
262 });
263 return;
264 }
265 const result = await runAttachmentUploadCycle({
266 registry: appAtomRegistry,
267 createUploadUrl: attachmentEnvironment.createUploadUrl,
268 remove: attachmentEnvironment.remove,
269 environmentId: job.environmentId,
270 upload: {
271 ...(job.image.type === "file" ? { type: "file" as const } : {}),
272 name: job.image.name,
273 mimeType,
274 sizeBytes: file.size,
275 },
276 resolveUploadUrl: (relativeUrl) => {
277 if (
278 job.cancelled ||
279 !readEnvironmentScope(job.environmentId, AuthOrchestrationOperateScope)
280 ) {
281 return null;
282 }
283 const connection = readPreparedConnection(job.environmentId);
284 return connection ? resolveAssetUrl(connection.httpBaseUrl, relativeUrl) : null;
285 },
286 transport: (url) =>
287 uploadBytes({
288 url,
289 file,
290 mimeType,
291 onProgress: (progress) => {
292 const step = Math.floor(progress * 20);
293 if (step === lastStep || job.cancelled) {
294 return;
295 }
296 lastStep = step;
297 setUploadState(job.image.id, {
298 status: "uploading",
299 environmentId: job.environmentId,
300 progress,
301 ...(job.previous ? { previous: job.previous } : {}),
302 });
303 },
304 }),
305 onMinted: (attachmentId) => {
306 if (job.cancelled && readEnvironmentScope(job.environmentId, AuthOrchestrationOperateScope)) {
307 return "cancel";
308 }
309 job.attachmentId = attachmentId;
310 return "continue";
311 },
312 onTransferStart: (abort) => {
313 job.abort = abort;
314 },
315 });
316 job.abort = null;
317 if (result.status === "cancelled" || job.cancelled) {
318 return;
319 }
320 if (result.status === "uploaded") {
321 setUploadState(job.image.id, {
322 status: "ready",
323 environmentId: job.environmentId,
324 attachmentId: result.attachmentId,
325 });
326 stampDraftFileUpload(job, result.attachmentId);
327 if (job.previous) {
328 deletePendingUpload(job.previous.environmentId, job.previous.attachmentId);
329 }
330 return;
331 }
332 setUploadState(job.image.id, {
333 status: "failed",
334 environmentId: job.environmentId,
335 reason:
336 result.step === "mint"
337 ? "Upload could not start"
338 : result.step === "resolve-url"
339 ? readEnvironmentScope(job.environmentId, AuthOrchestrationOperateScope)
340 ? "Not connected"
341 : "This connection cannot upload attachments."
342 : result.error instanceof Error
343 ? result.error.message
344 : "Upload failed",
345 ...(result.attachmentId ? { attachmentId: result.attachmentId } : {}),
346 ...(job.previous ? { previous: job.previous } : {}),
347 });
348}
349
350function pumpUploads(): void {
351 for (let index = 0; index < queue.length;) {
352 const job = queue[index]!;
353 const active = activeUploadsByEnvironment.get(job.environmentId) ?? 0;
354 if (active >= MAX_UPLOADS_PER_ENVIRONMENT) {
355 index += 1;
356 continue;
357 }
358
359 queue.splice(index, 1);
360 if (job.cancelled) {
361 continue;
362 }
363 activeUploadsByEnvironment.set(job.environmentId, active + 1);
364 void runUpload(job)
365 .catch(() => {
366 if (!job.cancelled) {
367 setUploadState(job.image.id, {
368 status: "failed",
369 environmentId: job.environmentId,
370 reason: "Upload failed",
371 ...(job.previous ? { previous: job.previous } : {}),
372 });
373 }
374 })
375 .finally(() => {
376 if (
377 jobsByImageId.get(job.image.id) === job &&
378 readAttachmentUpload(job.image.id)?.status !== "failed"
379 ) {
380 job.stopWatchingConnection();
381 jobsByImageId.delete(job.image.id);
382 }
383 const remaining = (activeUploadsByEnvironment.get(job.environmentId) ?? 1) - 1;
384 if (remaining > 0) {
385 activeUploadsByEnvironment.set(job.environmentId, remaining);
386 } else {
387 activeUploadsByEnvironment.delete(job.environmentId);
388 }
389 job.resolveSettled();
390 pumpUploads();
391 });
392 }
393}
394
395export function startAttachmentUpload(input: {
396 readonly environmentId: EnvironmentId;
397 readonly image: ComposerImageAttachment | ComposerFileAttachment;
398 readonly draftTarget?: ComposerThreadTarget;
399 readonly force?: boolean;
400}): void {
401 if (!readEnvironmentScope(input.environmentId, AuthOrchestrationOperateScope)) return;
402 const existingJob = jobsByImageId.get(input.image.id);
403 if (existingJob?.environmentId === input.environmentId) {
404 return;
405 }
406
407 const existing = readAttachmentUpload(input.image.id);
408 if (
409 !input.force &&
410 existing?.status === "ready" &&
411 existing.environmentId === input.environmentId
412 ) {
413 // A file restored into a draft after its upload finished (stash, failed send) missed the
414 // completion stamp; stamping here keeps it from re-uploading after a reload.
415 stampDraftFileUpload(input, existing.attachmentId);
416 return;
417 }
418 if (existing?.status === "failed" && existing.environmentId === input.environmentId) {
419 return;
420 }
421 if (
422 existing &&
423 "previous" in existing &&
424 existing.previous?.environmentId === input.environmentId
425 ) {
426 cancelAttachmentUpload(input.image.id);
427 if (existing.status === "failed" && existing.attachmentId) {
428 deletePendingUpload(existing.environmentId, existing.attachmentId);
429 }
430 setUploadState(input.image.id, existing.previous);
431 // Retargeting a scratch draft cleared the file's upload stamp; restore it for reloads.
432 stampDraftFileUpload(input, existing.previous.attachmentId);
433 return;
434 }
435
436 if (existingJob) {
437 cancelAttachmentUpload(input.image.id);
438 }
439 const previous = existing?.status === "ready" ? existing : existing?.previous;
440 let resolveSettled: () => void = () => {};
441 const settled = new Promise<void>((resolve) => {
442 resolveSettled = resolve;
443 });
444 const job: UploadJob = {
445 image: input.image,
446 environmentId: input.environmentId,
447 ...(input.draftTarget !== undefined ? { draftTarget: input.draftTarget } : {}),
448 ...(previous ? { previous } : {}),
449 ...(!input.force &&
450 input.image.type === "file" &&
451 input.image.uploadEnvironmentId === input.environmentId &&
452 input.image.uploadedAttachmentId
453 ? { persistedAttachmentId: input.image.uploadedAttachmentId }
454 : {}),
455 settled,
456 resolveSettled,
457 attachmentId: null,
458 cancelled: false,
459 abort: null,
460 stopWatchingConnection: () => {},
461 };
462
463 jobsByImageId.set(input.image.id, job);
464 const connectionAtom = environmentCatalog.stateAtom(job.environmentId);
465 const isConnected = () =>
466 Option.exists(
467 AsyncResult.value(appAtomRegistry.get(connectionAtom)),
468 (state) => state.phase === "connected",
469 );
470 let wasConnected = isConnected();
471 job.stopWatchingConnection = appAtomRegistry.subscribe(connectionAtom, () => {
472 const connected = isConnected();
473 const reconnected = connected && !wasConnected;
474 wasConnected = connected;
475 if (!reconnected) return;
476 // HTTP failures can follow reconnection; await the attempt and retry only if this job still owns the file.
477 void job.settled.then(() => {
478 if (
479 jobsByImageId.get(job.image.id) === job &&
480 readAttachmentUpload(job.image.id)?.status === "failed" &&
481 isConnected()
482 ) {
483 retryAttachmentUpload(input);
484 }
485 });
486 });
487 queue.push(job);
488 setUploadState(input.image.id, {
489 status: "uploading",
490 environmentId: input.environmentId,
491 progress: 0,
492 ...(previous ? { previous } : {}),
493 });
494 pumpUploads();
495}
496
497function cancelAttachmentUpload(imageId: string): void {
498 const job = jobsByImageId.get(imageId);
499 if (!job) {
500 return;
501 }
502 job.cancelled = true;
503 job.stopWatchingConnection();
504 jobsByImageId.delete(imageId);
505 const queuedIndex = queue.indexOf(job);
506 if (queuedIndex !== -1) {
507 queue.splice(queuedIndex, 1);
508 }
509 job.abort?.();
510 if (job.attachmentId) {
511 deletePendingUpload(job.environmentId, job.attachmentId);
512 }
513 job.resolveSettled();
514}
515
516export function releaseAttachmentUpload(imageId: string): void {
517 const upload = readAttachmentUpload(imageId);
518 cancelAttachmentUpload(imageId);
519 if (upload?.status === "ready") {
520 deletePendingUpload(upload.environmentId, upload.attachmentId);
521 } else if (upload) {
522 if (upload.status === "failed" && upload.attachmentId) {
523 deletePendingUpload(upload.environmentId, upload.attachmentId);
524 }
525 if (upload.previous) {
526 deletePendingUpload(upload.previous.environmentId, upload.previous.attachmentId);
527 }
528 }
529 clearUploadState(imageId);
530}
531
532export function releasePersistedAttachmentUpload(input: {
533 readonly id: string;
534 readonly environmentId: EnvironmentId;
535 readonly attachmentId: string;
536}): void {
537 const upload = readAttachmentUpload(input.id);
538 if (
539 upload?.status === "ready" &&
540 upload.environmentId === input.environmentId &&
541 upload.attachmentId === input.attachmentId
542 ) {
543 releaseAttachmentUpload(input.id);
544 return;
545 }
546 const job = jobsByImageId.get(input.id);
547 if (
548 job?.environmentId === input.environmentId &&
549 job.persistedAttachmentId === input.attachmentId
550 ) {
551 releaseAttachmentUpload(input.id);
552 }
553 deletePendingUpload(input.environmentId, input.attachmentId);
554}
555
556export function retryAttachmentUpload(input: {
557 readonly environmentId: EnvironmentId;
558 readonly image: ComposerImageAttachment | ComposerFileAttachment;
559 readonly draftTarget?: ComposerThreadTarget;
560}): void {
561 if (!readEnvironmentScope(input.environmentId, AuthOrchestrationOperateScope)) return;
562 const previous = readAttachmentUpload(input.image.id);
563 cancelAttachmentUpload(input.image.id);
564 if (previous?.status === "failed" && previous.attachmentId) {
565 deletePendingUpload(previous.environmentId, previous.attachmentId);
566 }
567 if (previous && "previous" in previous && previous.previous) {
568 setUploadState(input.image.id, previous.previous);
569 } else {
570 clearUploadState(input.image.id);
571 }
572 startAttachmentUpload(input);
573}
574
575/** Verifies uploads before stash restore; pending uploads expire after 24 hours. */
576export function verifyStashedAttachmentUpload(input: {
577 readonly environmentId: EnvironmentId;
578 readonly attachmentId: string;
579}): Promise<PersistedAttachmentVerification> {
580 return verifyPersistedAttachmentUpload({
581 registry: appAtomRegistry,
582 createAssetUrl: assetEnvironment.createUrl,
583 environmentId: input.environmentId,
584 attachmentId: input.attachmentId,
585 });
586}
587
588export async function awaitAttachmentUploads(imageIds: ReadonlyArray<string>): Promise<void> {
589 await Promise.all(imageIds.map((imageId) => jobsByImageId.get(imageId)?.settled));
590}
591
592/** Revalidate ready uploads at send time; a long-lived draft can outlive server cleanup. */
593export async function refreshExpiredAttachmentUploads(input: {
594 readonly environmentId: EnvironmentId;
595 readonly images: ReadonlyArray<ComposerImageAttachment | ComposerFileAttachment>;
596 readonly draftTarget?: ComposerThreadTarget;
597}): Promise<void> {
598 const canVerify = readEnvironmentScope(input.environmentId, AuthOrchestrationReadScope);
599 await Promise.all(
600 input.images.map(async (image) => {
601 const upload = readAttachmentUpload(image.id);
602 if (upload?.status !== "ready" || upload.environmentId !== input.environmentId) return;
603 if (!canVerify) {
604 if (image.file) {
605 startAttachmentUpload({
606 environmentId: input.environmentId,
607 image,
608 force: true,
609 ...(input.draftTarget !== undefined ? { draftTarget: input.draftTarget } : {}),
610 });
611 } else {
612 setUploadState(image.id, {
613 status: "failed",
614 environmentId: input.environmentId,
615 previous: upload,
616 reason: "Uploaded attachment could not be verified. Attach the file again.",
617 });
618 }
619 return;
620 }
621 const verification = await verifyStashedAttachmentUpload({
622 environmentId: input.environmentId,
623 attachmentId: upload.attachmentId,
624 }).catch((error: unknown): PersistedAttachmentVerification => ({ status: "failed", error }));
625 // The user may have removed or replaced the attachment while verification was in flight.
626 if (readAttachmentUpload(image.id) !== upload) return;
627 if (verification.status === "verified") return;
628 if (verification.status === "missing" && image.file) {
629 clearUploadState(image.id);
630 startAttachmentUpload({
631 environmentId: input.environmentId,
632 image,
633 force: true,
634 ...(input.draftTarget !== undefined ? { draftTarget: input.draftTarget } : {}),
635 });
636 return;
637 }
638 setUploadState(image.id, {
639 status: "failed",
640 environmentId: input.environmentId,
641 previous: upload,
642 reason:
643 verification.status === "missing"
644 ? "Uploaded attachment expired. Remove it and attach it again."
645 : "Uploaded attachment could not be verified. Retry when the server reconnects.",
646 });
647 }),
648 );
649 await awaitAttachmentUploads(input.images.map((image) => image.id));
650}
651
652export function getUploadedAttachments(input: {
653 readonly environmentId: EnvironmentId;
654 readonly images: ReadonlyArray<ComposerImageAttachment | ComposerFileAttachment>;
655}): ChatAttachment[] | null {
656 const attachments: ChatAttachment[] = [];
657 for (const image of input.images) {
658 const upload = readAttachmentUpload(image.id);
659 if (upload?.status !== "ready" || upload.environmentId !== input.environmentId) {
660 return null;
661 }
662 attachments.push({
663 type: image.type,
664 id: upload.attachmentId,
665 name: image.name,
666 mimeType: image.mimeType,
667 sizeBytes: image.sizeBytes,
668 ...(image.source ? { source: image.source } : {}),
669 });
670 }
671 return attachments;
672}
673
674/** In-memory queue releases miss uploads after reload; every draft discard must use this path. */
675export function releaseDraftAttachment(
676 attachment: ComposerImageAttachment | ComposerFileAttachment,
677): void {
678 if (
679 attachment.type === "file" &&
680 attachment.uploadedAttachmentId !== undefined &&
681 attachment.uploadEnvironmentId !== undefined
682 ) {
683 releasePersistedAttachmentUpload({
684 id: attachment.id,
685 environmentId: attachment.uploadEnvironmentId,
686 attachmentId: attachment.uploadedAttachmentId,
687 });
688 if (jobsByImageId.has(attachment.id) || readAttachmentUpload(attachment.id)) {
689 releaseAttachmentUpload(attachment.id);
690 }
691 return;
692 }
693 releaseAttachmentUpload(attachment.id);
694}
695
696export function releaseDraftAttachments(
697 attachments: ReadonlyArray<ComposerImageAttachment | ComposerFileAttachment>,
698): void {
699 for (const attachment of attachments) {
700 releaseDraftAttachment(attachment);
701 }
702}