import type { AppShotCapture, FileAsset, FileResourceRef } from "@opengeni/sdk"; import { type EmbeddedFileAttachmentClientOverride } from "../session-context.js"; export type UseFileAttachmentsOptions = EmbeddedFileAttachmentClientOverride & { /** * Only files matching this predicate are accepted by {@link * UseFileAttachmentsResult.addFromPaste} (the clipboard path). Defaults to * `image/*` — the console's historical paste filter. {@link * UseFileAttachmentsResult.addFiles} (the explicit picker / drop path) * bypasses it. */ /** Retain original uploads in the chat owner’s personal scope when private. */ scope?: "workspace" | "personal"; pasteFilter?: ((file: File) => boolean) | undefined; }; export type FileAttachment = { id: string; name: string; contentType: string; sizeBytes: number; status: "uploading" | "ready" | "failed"; /** The SDK `FileAsset` once the upload finishes. */ file?: FileAsset | undefined; /** Object-URL for an inline preview; minted for `image/*` files only. */ previewUrl?: string | undefined; /** Stable SDK failure code for UI behavior that must not parse error copy. */ errorCode?: "secure_context_required" | undefined; error?: string | undefined; /** Original diagnostic failure; presentation copy is kept separately in `error`. */ errorCause?: unknown; /** * An app-shot: a screenshot of another app's window with the window it * shows and the text it exposed, sent to the agent with the image. */ appShot?: AppShotCapture | undefined; }; export type UseFileAttachmentsResult = { attachments: FileAttachment[]; /** * `FileResourceRef[]` for every attachment that finished uploading — feed * straight into `useComposer`'s `sendExtras.resources`. */ readyResources: FileResourceRef[]; /** True while any attachment is still uploading (drives progress UI). */ uploading: boolean; /** * True while any attachment still needs an explicit outcome: wait for an * upload, retry a failure, or remove it. This is the loss-prevention send * gate; failed cards must never be silently omitted from a message. */ hasUnresolved: boolean; /** Explicit picker / drop path — uploads every file, no filter. */ addFiles: (files: Iterable) => void; /** * Attach a window screenshot as an app-shot: the image plus the window it * shows and the text it exposed, stored with the file. Optional so custom * attachment stores written before app-shots keep satisfying this type. */ addAppShot?: ((image: File, appShot: AppShotCapture) => void) | undefined; /** Clipboard path — applies `pasteFilter` (default `image/*`) then uploads. */ addFromPaste: (event: { clipboardData: DataTransfer | null; }) => void; /** Restore already-ready server assets without recreating browser-local bytes. */ restoreReadyFiles: (files: Iterable) => void; /** * Resolve a ready image's short-lived server preview URL on demand. Optional * for upload-only embedded clients; local object-URL previews remain usable * without it. */ loadPreview?: ((id: string, signal?: AbortSignal) => Promise) | undefined; /** * Re-run the upload for a `failed` attachment, in place (same id, same * source file). No-op for an id that isn't a known failed upload. */ retry: (id: string) => void; /** * Keep an attachment's object-URL alive for a consumer that outlives its * queue entry (for example, an open route-level lightbox). The returned * release is idempotent; pending revocation finishes after the last holder * releases. Returns `undefined` when the attachment has no local preview. */ retainPreview: (id: string) => (() => void) | undefined; /** Remove one attachment; revokes its object-URL after retained users finish. */ remove: (id: string) => void; /** * Remove only finalized files whose durable ids were accepted by a send. * Attachments added while that request was in flight remain queued for the * next message. */ removeReadyFiles: (fileIds: Iterable) => void; /** Remove all attachments and revoke every unretained object-URL. */ clear: () => void; }; /** * Upload-and-track state for files attached to the next message. Owns the * full client-side upload layer: a per-file `uploading | ready | failed` * status machine driven by the SDK's `client.uploadFile`, object-URL image * previews with create/revoke lifecycle, the `image/*` clipboard paste filter, * and a `FileResourceRef[]` projection that drops straight into a message's * `resources`. Workspace-scoped, so it resolves both client and workspace from * the {@link OpenGeniProvider} (or a per-call `{ client, workspaceId }`). */ export declare function useFileAttachments(options?: UseFileAttachmentsOptions): UseFileAttachmentsResult;