Open source CapCut alternative.
TypeScript
feat(app): notch file attachments — drag-drop staging chips and per-row file pills
David Le6a9b6d85344a
diff --git a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swiftindex 9bb8f538..5127b450 100644--- a/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryCommandHandler.swift@@ -138,15 +138,25 @@ protocol UserQueryCommandHandling: Sendable {context: UserQueryCommandContext?) async -> UserQueryCommandHandlingResult?/// Queue a follow-up instruction onto a task whose loop is still running so it folds it in at its- /// next step. Returns true when the task is live (a loop will pick it up); false means the caller- /// should fall back to resuming the task with the instruction as a fresh turn.- func injectFollowUp(conversationID: String, text: String) async -> Bool+ /// next step. Files the user attached with the follow-up are registered onto the conversation's+ /// workspace so the running planner sees them. Returns true when the task is live (a loop will pick+ /// it up); false means the caller should fall back to resuming the task with the instruction as a+ /// fresh turn.+ func injectFollowUp(+ conversationID: String,+ text: String,+ assets: [UserQueryConversationAsset]+ ) async -> Bool/// Re-run a previously-interrupted task in the BACKGROUND (no focus steal), for unattended/// auto-resume on relaunch. Returns nil when the task is unknown or has no goal to resume.func autoResumeCommand(conversationID: String,context: UserQueryCommandContext?) async -> UserQueryCommandHandlingResult?+ /// The files the conversation's runs have produced (its workspace deliverables) that still exist on+ /// disk, plus the folder they live in — for the conversation row's output pills. Nil when the+ /// conversation has no workspace record.+ func workspaceOutputs(conversationID: String) async -> UserQueryWorkspaceOutputs?/// Set by the overlay so a mid-run hosted 401 (an expired session) surfaces re-login. The inference/// client fires it off the main actor, so the hook hops back to the main actor itself.var onAuthenticationRequired: (@MainActor @Sendable () -> Void)? { get set }@@ -164,10 +174,18 @@ extension UserQueryCommandHandling {nil}- func injectFollowUp(conversationID: String, text: String) async -> Bool {+ func injectFollowUp(+ conversationID: String,+ text: String,+ assets: [UserQueryConversationAsset]+ ) async -> Bool {false}+ func workspaceOutputs(conversationID: String) async -> UserQueryWorkspaceOutputs? {+ nil+ }+func autoResumeCommand(conversationID: String,context: UserQueryCommandContext?@@ -321,19 +339,32 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {await genericHarnessLifecycle.coordinator.rootAgents(conversationID: conversationID).first?.id ?? conversationID}- func injectFollowUp(conversationID: String, text: String) async -> Bool {+ func injectFollowUp(+ conversationID: String,+ text: String,+ assets: [UserQueryConversationAsset]+ ) async -> Bool {let agentID = await managingAgentID(forConversation: conversationID)guard let task = await genericHarnessLifecycle.agentState(agentID: agentID) else { return false }switch task.status {case .running, .resuming:// A live loop drains the queue. The returned flag is authoritative — false means the loop- // ended in the meantime, so the caller resumes the task instead (which drains it on start).- return await genericHarnessLifecycle.coordinator.enqueueUserMessage(agentID: agentID, text: text)+ // ended in the meantime, so the caller resumes the task instead (which drains it on start;+ // the assets are already persisted on the conversation, so that run loads them itself).+ await registerFollowUpAttachments(assets, conversationID: conversationID, agentID: agentID)+ return await genericHarnessLifecycle.coordinator.enqueueUserMessage(+ agentID: agentID,+ text: Self.followUpText(text, assets: assets)+ )case .waitingForPermission:// Blocked on the user at a permission gate. Queue the follow-up WITHOUT resuming, so the gate// is preserved; it drains when the user approves and the loop resumes. Report accepted so the// caller does not start a competing run that would clear the pending gate.- _ = await genericHarnessLifecycle.coordinator.enqueueUserMessage(agentID: agentID, text: text)+ await registerFollowUpAttachments(assets, conversationID: conversationID, agentID: agentID)+ _ = await genericHarnessLifecycle.coordinator.enqueueUserMessage(+ agentID: agentID,+ text: Self.followUpText(text, assets: assets)+ )return truedefault:// No live or gated loop (paused, timedOut, completed, failedSafe, interrupted, cancelled, or a@@ -342,6 +373,80 @@ struct LocalAppUserQueryCommandHandler: UserQueryCommandHandling {}}+ func workspaceOutputs(conversationID: String) async -> UserQueryWorkspaceOutputs? {+ guard let workspace = await genericHarnessLifecycle.coordinator.conversationWorkspace(+ conversationID: conversationID+ ) else {+ return nil+ }++ // A run that produced nothing renders nothing (its empty working folder is removed at run end).+ guard !workspace.deliverables.isEmpty else { return nil }++ // Deliverable paths are recorded at first creation; the planner may later promote them into a+ // project folder (mv), leaving the recorded loose path stale. Only paths still on disk render+ // as pills — a moved file's home is still reachable through the folder pill.+ var existingFiles = workspace.deliverables+ .map(\.path)+ .filter { FileManager.default.fileExists(atPath: $0) }+ var isFolder = ObjCBool(false)+ let folderPath = [workspace.folderPath, workspace.root, workspace.anchorBase]+ .compactMap { $0 }+ .first { FileManager.default.fileExists(atPath: $0, isDirectory: &isFolder) && isFolder.boolValue }+ // Every recorded path went stale (promoted into the folder under a new path). When the folder+ // holds exactly one visible file, that file IS the run's output — link it directly rather than+ // pointing at its folder.+ if existingFiles.isEmpty, let folderPath {+ let visibleEntries = ((try? FileManager.default.contentsOfDirectory(atPath: folderPath)) ?? [])+ .filter { !$0.hasPrefix(".") }+ if visibleEntries.count == 1 {+ let soleEntryPath = folderPath + "/" + visibleEntries[0]+ var entryIsFolder = ObjCBool(false)+ if FileManager.default.fileExists(atPath: soleEntryPath, isDirectory: &entryIsFolder),+ !entryIsFolder.boolValue {+ existingFiles = [soleEntryPath]+ }+ }+ }+ guard !existingFiles.isEmpty || folderPath != nil else { return nil }++ return UserQueryWorkspaceOutputs(+ folderPath: folderPath,+ files: existingFiles.map { UserQueryWorkspaceOutputs.File(path: $0) }+ )+ }++ /// Register files attached to a mid-run follow-up onto the conversation workspace — the same path a+ /// fresh turn takes at its start — and reproject the workspace fact so the running planner sees the+ /// new inputs at its next step rather than after the run.+ private func registerFollowUpAttachments(+ _ assets: [UserQueryConversationAsset],+ conversationID: String,+ agentID: String+ ) async {+ let records = assets+ .filter { $0.source == .userUploaded }+ .compactMap { asset -> (path: String, displayName: String, contentType: String, byteCount: Int?)? in+ guard let path = Self.localPath(forAssetURLString: asset.urlString) else { return nil }+ return (path, asset.displayName, asset.contentType, asset.byteCount.map(Int.init))+ }+ guard !records.isEmpty else { return }++ await genericHarnessLifecycle.coordinator.recordWorkspaceAttachments(+ conversationID: conversationID, attachments: records, at: Date()+ )+ await genericHarnessLifecycle.coordinator.refreshWorkspaceFact(agentID: agentID)+ }++ /// The queued follow-up names its attachments (name only, never contents) so the planner reads the+ /// instruction against them; their paths arrive through the workspace fact.+ private static func followUpText(_ text: String, assets: [UserQueryConversationAsset]) -> String {+ let names = assets.filter { $0.source == .userUploaded }.map(\.displayName)+ guard !names.isEmpty else { return text }++ return text + "\n\nAttached files: " + names.joined(separator: ", ")+ }+func autoResumeCommand(conversationID: String,context: UserQueryCommandContext?diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swiftindex 8ee64513..d6c528e8 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift@@ -653,7 +653,10 @@ final class UserQueryOverlayController {selectedSpawnID: model.selectedSpawnID,replyTargetConversationID: model.replyTargetConversationID,selectedConversationID: model.selectedConversationID,- needsLogin: model.needsLogin+ needsLogin: model.needsLogin,+ stagedAssets: model.stagedNotchAssets,+ conversationAssets: model.notchConversationAssets,+ conversationOutputs: model.notchConversationOutputs)}@@ -696,6 +699,19 @@ final class UserQueryOverlayController {assetsDropped: { [weak self] drafts inself?.model.handleDroppedAssets(drafts)},+ stagedAssets: model.stagedNotchAssets,+ stagedAssetRemoved: { [weak self] stagedID in+ self?.model.removeStagedAsset(id: stagedID)+ },+ conversationAssets: model.notchConversationAssets,+ assetOpenRequested: { asset in+ guard let url = URL(string: asset.urlString), url.isFileURL else { return }+ NSWorkspace.shared.open(url)+ },+ conversationOutputs: model.notchConversationOutputs,+ outputOpenRequested: { path in+ NSWorkspace.shared.open(URL(fileURLWithPath: path))+ },pauseRequested: { [weak self] conversationID inself?.model.pauseAgent(id: conversationID)},@@ -1158,11 +1174,16 @@ final class UserQueryOverlayController {return NotchMetrics.loginExpandedContentHeight}+ // Staged drops render a chip row above the composer; the surface grows to seat it so the+ // conversation list and composer keep their height.+ let stagedAssetsExtraHeight = model.stagedNotchAssets.isEmpty ? 0 : NotchMetrics.stagedAssetsRowExtraHeightif hasStatusConversationDisplayText || !model.notchConversations.isEmpty || model.updateState.headerButtonTitle != nil {- return NotchMetrics.expandedConversationContentHeight+ return NotchMetrics.expandedConversationContentHeight + stagedAssetsExtraHeight}- return model.notchCommandInputSurfaceHeight + NotchMetrics.compactCommandContentVerticalPadding+ return model.notchCommandInputSurfaceHeight+ + NotchMetrics.compactCommandContentVerticalPadding+ + stagedAssetsExtraHeight}private var hasStatusConversationDisplayText: Bool {@@ -1624,6 +1645,9 @@ private struct StatusPanelViewSnapshot: Equatable {var replyTargetConversationID: String?var selectedConversationID: String?var needsLogin: Bool+ var stagedAssets: [UserQueryStagedAsset]+ var conversationAssets: [String: [UserQueryConversationAsset]]+ var conversationOutputs: [String: UserQueryWorkspaceOutputs]}private enum StatusHoverPhase {diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swiftindex c49c21eb..dd4f18a4 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift@@ -33,6 +33,18 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {@Published private(set) var notchConversations: [UserQueryConversation]@Published private(set) var spawnStates: [UserQuerySpawnState] = []@Published private(set) var selectedSpawnID: String?+ /// Files dropped on the notch, staged as removable preview chips above the composer. They are+ /// committed to a conversation — and onto its workspace, where the planner reads them — only when+ /// the next message is submitted; the chip's ✕ takes a drop back before then.+ @Published private(set) var stagedNotchAssets: [UserQueryStagedAsset] = []+ /// The files the user attached to each displayed conversation (keyed by conversation id), rendered+ /// as clickable pills in the conversation's row. Loaded when a conversation enters the rail and+ /// appended to as staged drops commit.+ @Published private(set) var notchConversationAssets: [String: [UserQueryConversationAsset]] = [:]+ /// The files each conversation's runs produced (keyed by conversation id), rendered as output pills+ /// in the row — one file as its own pill, several as one folder pill. Refreshed when a run finishes+ /// and once at launch for restored conversations.+ @Published private(set) var notchConversationOutputs: [String: UserQueryWorkspaceOutputs] = [:]/// Logged out: the notch renders a login call-to-action instead of the conversation surface. The app/// delegate pushes this from the auth coordinator's session state (true while signed out after a/// prior sign-in, i.e. an expired session) and clears it once sign-in completes.@@ -138,6 +150,13 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {)let restoredConversations = restoration.conversationsnotchConversations = restoredConversations+ var restoredAssets: [String: [UserQueryConversationAsset]] = [:]+ for conversation in restoredConversations {+ restoredAssets[conversation.id] = conversationStore+ .loadAssets(conversationID: conversation.id)+ .filter { $0.source == .userUploaded }+ }+ notchConversationAssets = restoredAssetsnotchAccentIndex = restoredConversations.first.map { UserQueryAccentPalette.normalizedIndex($0.accentIndex) }?? UserQueryAccentPalette.firstIndexisCurrentConversationPaused = restoredConversations.first?.status == .paused@@ -156,6 +175,8 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {self?.updateState = state}updateChecker.start()+ // Staged drops never outlive the session that staged them; clear leftovers from a prior run.+ Self.purgeStagedAssets()SQLiteAgentMemoryStore.shared?.prewarmDefaultLocalItemsInBackground()appCatalogRefreshLoop.start()checkForUpdates()@@ -166,6 +187,9 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {self?.handleSessionExpired()}autoResumeInterruptedConversations(restoration.autoResumeIDs)+ for conversation in restoredConversations {+ refreshConversationOutputs(conversationID: conversation.id)+ }}/// Resume conversations that were actively running when the app last quit (see `restoredConversations`). Each runs as@@ -668,6 +692,10 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {}private func runLocalCommand(_ text: String, source: AppHarnessTurnSource = .typedPrompt) {+ // The submitted message takes the staged drops with it: drained here, committed onto whichever+ // conversation the turn resolves to, so the chips clear the moment the message leaves.+ let stagedAssets = stagedNotchAssets+ stagedNotchAssets = []let candidates = followUpCandidates()let promptFollowUpTarget = promptSubmissionFollowUpTarget()let replyTargetConversationID = consumePendingReplyTarget()@@ -721,39 +749,80 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {text: text,matchedConversationID: matchedConversationID,source: source,- spawnID: spawnID+ spawnID: spawnID,+ stagedAssets: stagedAssets)}}}+ /// Stage dropped files as chips above the composer. Each file is copied into a staging directory+ /// immediately — drags out of browsers and mail hand over temporary files that can vanish before the+ /// user submits — so the chip and the eventual commit always read from a stable copy.func handleDroppedAssets(_ drafts: [UserQueryConversationAssetDraft]) {- guard !drafts.isEmpty else { return }-- let targetConversation = conversationForDroppedAssets()- let assetNames = drafts.map(\.displayName)- let eventText = Self.assetUploadEventText(assetNames)- let eventID = appendAgentEvent(conversationID: targetConversation.id, role: .user, text: eventText)for draft in drafts {- let assetID = UUID().uuidString- conversationStore.appendAsset(- Self.persistedAsset(- from: draft,- assetID: assetID,- conversationID: targetConversation.id,- eventID: eventID- )- )+ let stagedID = UUID().uuidString+ var stagedDraft = draft+ if let sourceURL = URL(string: draft.urlString),+ sourceURL.isFileURL,+ let stagedURL = Self.copyAssetToStaging(+ sourceURL: sourceURL,+ stagedID: stagedID,+ displayName: draft.displayName+ ) {+ stagedDraft.urlString = stagedURL.absoluteString+ }+ stagedNotchAssets.append(UserQueryStagedAsset(id: stagedID, draft: stagedDraft))}+ }- var updatedConversation = targetConversation- updatedConversation.detail = drafts.count == 1 ? "1 asset attached" : "\(drafts.count) assets attached"- updatedConversation.updatedAt = Date()- prependConversation(updatedConversation)- lastActiveConversationID = updatedConversation.id- promptState.promptText = updatedConversation.title- promptState.leadingSignalLevel = updatedConversation.status == .running ? .thinking : .ready- syncPrimaryConversationPausedFlag()+ func removeStagedAsset(id: String) {+ guard let index = stagedNotchAssets.firstIndex(where: { $0.id == id }) else { return }++ Self.deleteStagedAssetFile(urlString: stagedNotchAssets[index].draft.urlString)+ stagedNotchAssets.remove(at: index)+ }++ /// Re-read what the conversation's runs have produced and publish it for the row's output pills.+ /// Fired when a run finishes and once per restored conversation at launch.+ private func refreshConversationOutputs(conversationID: String) {+ Task { [weak self, commandHandler] in+ let outputs = await commandHandler.workspaceOutputs(conversationID: conversationID)+ await MainActor.run {+ guard let self else { return }+ if let outputs {+ self.notchConversationOutputs[conversationID] = outputs+ } else {+ self.notchConversationOutputs.removeValue(forKey: conversationID)+ }+ }+ }+ }++ /// Move staged drops onto the conversation the submitted turn resolved to: each becomes a persisted+ /// user-uploaded asset (copied into the conversation's asset directory) and its staging copy is+ /// deleted. Returns the persisted assets so a live loop can register them onto its workspace.+ @discardableResult+ private func commitStagedAssets(+ _ stagedAssets: [UserQueryStagedAsset],+ conversationID: String,+ eventID: String?+ ) -> [UserQueryConversationAsset] {+ let committedAssets = stagedAssets.map { staged in+ let asset = Self.persistedAsset(+ from: staged.draft,+ assetID: staged.id,+ conversationID: conversationID,+ eventID: eventID+ )+ conversationStore.appendAsset(asset)+ Self.deleteStagedAssetFile(urlString: staged.draft.urlString)+ return asset+ }+ if !committedAssets.isEmpty {+ notchConversationAssets[conversationID, default: []].append(contentsOf: committedAssets)+ }+ return committedAssets}func markSpawnDesktopEmerged(id spawnID: String) {@@ -802,7 +871,8 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {text: String,matchedConversationID: String?,source: AppHarnessTurnSource = .typedPrompt,- spawnID: String? = nil+ spawnID: String? = nil,+ stagedAssets: [UserQueryStagedAsset] = []) {// A follow-up to a conversation whose loop is still running — or one blocked at a permission gate — is// queued into that conversation: the running loop folds it in at its next step, and a gated conversation keeps its@@ -811,10 +881,22 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {// the fresh/resume path below, which runs concurrently with any other in-flight conversation.let matchedStatus = matchedConversationID.flatMap { conversation(withID: $0)?.status }if let matchedConversationID, matchedStatus == .running || matchedStatus == .waitingForPermission {- queueFollowUpIntoRunningConversation(text: text, conversationID: matchedConversationID, source: source, spawnID: spawnID)+ queueFollowUpIntoRunningConversation(+ text: text,+ conversationID: matchedConversationID,+ source: source,+ spawnID: spawnID,+ stagedAssets: stagedAssets+ )return}- runFreshOrResumedCommand(text: text, matchedConversationID: matchedConversationID, source: source, spawnID: spawnID)+ runFreshOrResumedCommand(+ text: text,+ matchedConversationID: matchedConversationID,+ source: source,+ spawnID: spawnID,+ stagedAssets: stagedAssets+ )}/// Queue a follow-up onto a conversation whose loop is still running. The live loop picks it up at its next@@ -823,9 +905,13 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {text: String,conversationID: String,source: AppHarnessTurnSource,- spawnID: String?+ spawnID: String?,+ stagedAssets: [UserQueryStagedAsset] = []) {- appendAgentEvent(conversationID: conversationID, role: .user, text: text)+ let eventID = appendAgentEvent(conversationID: conversationID, role: .user, text: text)+ // Commit the drops now and hand them to the live loop, which registers them onto the running+ // conversation's workspace so the planner sees the new inputs at its next step.+ let committedAssets = commitStagedAssets(stagedAssets, conversationID: conversationID, eventID: eventID)updateSpawn(id: spawnID, conversationID: conversationID)clearSubmissionInputs()lastActiveConversationID = conversationID@@ -835,10 +921,15 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {promptState.promptText = conversation(withID: conversationID)?.title ?? Self.collapsedDisplayText(for: text)syncPrimaryConversationPausedFlag()Task { [weak self, commandHandler] in- let injected = await commandHandler.injectFollowUp(conversationID: conversationID, text: text)+ let injected = await commandHandler.injectFollowUp(+ conversationID: conversationID,+ text: text,+ assets: committedAssets+ )guard !injected else { return }// Race: the loop finished between the live check and the enqueue. Resume the conversation with the- // instruction instead. The user event is already recorded, so it is not appended again.+ // instruction instead. The user event and assets are already recorded, so neither is added again;+ // the resumed run picks the assets up from the conversation store.await MainActor.run {self?.runFreshOrResumedCommand(text: text,@@ -856,7 +947,8 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {matchedConversationID: String?,source: AppHarnessTurnSource = .typedPrompt,spawnID: String? = nil,- appendUserEvent: Bool = true+ appendUserEvent: Bool = true,+ stagedAssets: [UserQueryStagedAsset] = []) {let isFollowUp = matchedConversationID != nillet reservedAccentIndex = spawnID.flatMap { spawn(withID: $0)?.accentIndex }@@ -872,9 +964,13 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {)activeAgentIDs.insert(conversation.id)lastActiveConversationID = conversation.id+ var userEventID: String?if appendUserEvent {- appendAgentEvent(conversationID: conversation.id, role: .user, text: text)+ userEventID = appendAgentEvent(conversationID: conversation.id, role: .user, text: text)}+ // Committed before the run context is built below, so the turn's asset load already includes+ // the drops and the harness registers them onto the conversation workspace for the planner.+ commitStagedAssets(stagedAssets, conversationID: conversation.id, eventID: userEventID)clearSubmissionInputs()promptState.isActive = falsepromptState.leadingSignalLevel = .thinking@@ -916,6 +1012,7 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {)appendAgentEvent(conversationID: conversationID, role: .assistant, text: result.summary)activeAgentIDs.remove(conversationID)+ refreshConversationOutputs(conversationID: conversationID)refreshPromptStateAfterRunResult(conversationID: conversationID, result: result)let cursorOverlayRequest = result.cursorOverlayRequestif let cursorOverlayRequest {@@ -1132,6 +1229,8 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {notchConversations.removeAll { $0.id == conversationID }activeAgentIDs.remove(conversationID)+ notchConversationAssets.removeValue(forKey: conversationID)+ notchConversationOutputs.removeValue(forKey: conversationID)// Closing the targeted conversation ends reply mode so the remaining rows don't stay dimmed.if replyTargetConversationID == conversationID {replyTargetConversationID = nil@@ -1487,6 +1586,13 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {if notchConversations.count > Self.notchConversationDisplayLimit {notchConversations = Array(notchConversations.prefix(Self.notchConversationDisplayLimit))}+ // An older conversation re-entering the rail (a matched follow-up) brings its attached files+ // back with it; a brand-new conversation just seeds an empty entry.+ if notchConversationAssets[conversation.id] == nil {+ notchConversationAssets[conversation.id] = conversationStore+ .loadAssets(conversationID: conversation.id)+ .filter { $0.source == .userUploaded }+ }conversationStore.upsertConversation(conversation)}@@ -1554,38 +1660,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {return conversation}- private func conversationForDroppedAssets() -> UserQueryConversation {- // A drop only ever attaches to one of the user's own conversations — never to a system-driven row- // like tool setup, which has no goal to fold an asset into.- if let lastActiveConversationID,- activeAgentIDs.contains(lastActiveConversationID),- let conversation = conversation(withID: lastActiveConversationID),- conversation.isUserControllable {- return conversation- }-- if let activeConversation = notchConversations.first(where: { $0.isUserControllable && ($0.status == .running || $0.status == .paused) }) {- return activeConversation- }-- if let recentConversation = notchConversations.first(where: { $0.isUserControllable }) {- return recentConversation- }-- let nextAccentIndex = nextRoundRobinAccentIndex()- notchAccentIndex = nextAccentIndex- let conversation = UserQueryConversation(- id: UUID().uuidString,- title: "Uploaded assets",- detail: "Assets attached",- commandText: "",- status: .needsAttention,- accentIndex: nextAccentIndex- )- prependConversation(conversation)- return conversation- }-private func conversation(withID conversationID: String) -> UserQueryConversation? {if let conversation = notchConversations.first(where: { $0.id == conversationID }) {return conversation@@ -1984,15 +2058,6 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {return truncated(collapsed, maxLength: maxSpawnLabelLength)}- private static func assetUploadEventText(_ assetNames: [String]) -> String {- let displayNames = assetNames- .map { truncated($0, maxLength: 80) }- .joined(separator: ", ")- guard !displayNames.isEmpty else { return "Uploaded assets" }-- return "Uploaded assets: \(displayNames)"- }-private static func persistedAsset(from draft: UserQueryConversationAssetDraft,assetID: String,@@ -2051,6 +2116,65 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {}}+ /// Where drops wait between the drag and the submit. Distinct from any conversation's asset+ /// directory (those are keyed by conversation UUID) and purged on launch, since staged chips+ /// don't survive a restart.+ private static func stagedAssetsDirectory() -> URL? {+ FileManager.default.urls(+ for: .applicationSupportDirectory,+ in: .userDomainMask+ ).first?+ .appendingPathComponent("Donkey", isDirectory: true)+ .appendingPathComponent("UserQueryAssets", isDirectory: true)+ .appendingPathComponent("Staged", isDirectory: true)+ }++ private static func copyAssetToStaging(+ sourceURL: URL,+ stagedID: String,+ displayName: String+ ) -> URL? {+ guard let stagingDirectory = stagedAssetsDirectory() else { return nil }++ do {+ try FileManager.default.createDirectory(+ at: stagingDirectory,+ withIntermediateDirectories: true+ )+ let fileName = "\(stagedID)-\(safeAssetFileName(displayName))"+ let destinationURL = stagingDirectory.appendingPathComponent(fileName, isDirectory: false)+ let didStartAccess = sourceURL.startAccessingSecurityScopedResource()+ defer {+ if didStartAccess {+ sourceURL.stopAccessingSecurityScopedResource()+ }+ }+ try FileManager.default.copyItem(at: sourceURL, to: destinationURL)+ return destinationURL+ } catch {+ return nil+ }+ }++ /// Deletes a staged file. Guarded to the staging directory: when the copy-to-staging failed, the+ /// chip still points at the user's original file, which must never be touched.+ private static func deleteStagedAssetFile(urlString: String) {+ guard let url = URL(string: urlString),+ url.isFileURL,+ let stagingDirectory = stagedAssetsDirectory(),+ url.standardizedFileURL.path.hasPrefix(stagingDirectory.standardizedFileURL.path + "/") else {+ return+ }++ try? FileManager.default.removeItem(at: url)+ }++ static func purgeStagedAssets() {+ guard let stagingDirectory = stagedAssetsDirectory() else { return }++ try? FileManager.default.removeItem(at: stagingDirectory)+ }+private static func conversationAssetDirectory(conversationID: String) -> URL? {guard let applicationSupportURL = FileManager.default.urls(for: .applicationSupportDirectory,diff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swiftindex dc4bc056..4b71eb77 100644--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryConversationContracts.swift@@ -263,6 +263,46 @@ public struct UserQueryConversationAsset: Codable, Equatable, Identifiable, Send}}+/// What a conversation's agent produced on disk: the output files still present, and the folder+/// they live in. Rendered in the conversation's notch row — one file as its own pill, several as+/// a single folder pill — so the user can open what the run made.+public struct UserQueryWorkspaceOutputs: Equatable, Sendable {+ public struct File: Equatable, Sendable {+ public var path: String++ public init(path: String) {+ self.path = path+ }++ public var displayName: String {+ URL(fileURLWithPath: path).lastPathComponent+ }+ }++ /// The folder holding the outputs (the promoted project folder, else the conversation's working+ /// directory) — what a multi-file pill opens.+ public var folderPath: String?+ public var files: [File]++ public init(folderPath: String? = nil, files: [File] = []) {+ self.folderPath = folderPath+ self.files = files+ }+}++/// A dropped file staged in the notch composer: it renders as a removable preview chip and is+/// committed to a conversation only when the user submits the next message, so a drop can still+/// be taken back with the chip's ✕.+public struct UserQueryStagedAsset: Equatable, Identifiable, Sendable {+ public var id: String+ public var draft: UserQueryConversationAssetDraft++ public init(id: String, draft: UserQueryConversationAssetDraft) {+ self.id = id+ self.draft = draft+ }+}+public struct UserQueryConversationAssetDraft: Codable, Equatable, Sendable {public var source: UserQueryConversationAssetSourcepublic var displayName: Stringdiff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swiftindex 95f79aa8..166f1b94 100644--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift@@ -103,6 +103,11 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {public static let expandedConversationContentHeight: CGFloat = 280public static let inputHorizontalMargin: CGFloat = 14public static let compactCommandContentVerticalPadding: CGFloat = 30+ /// Side of a staged-attachment preview chip in the expanded notch.+ public static let stagedAssetChipSide: CGFloat = 84+ /// Extra expanded-content height while staged attachments render above the composer:+ /// one chip row plus the row's spacing to the composer.+ public static let stagedAssetsRowExtraHeight: CGFloat = stagedAssetChipSide + 8/// How long the open host window lingers after the surface starts collapsing, before it snaps to/// the notch size. Timed just past the surface close animation (0.22s) so the host always stays/// large enough to contain the still-shrinking surface, then closes once it has reached the notch.diff --git a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swiftindex 205b86fe..6eea0616 100644--- a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift+++ b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift@@ -1,5 +1,7 @@+import AppKitimport DonkeyContractsimport Foundation+import QuickLookThumbnailingimport SwiftUIimport UniformTypeIdentifiers@@ -12,6 +14,8 @@ public struct UserQueryNotchStatusView: View {/// the open state into `@State` and flipping it in `.onChange` moves the animation onto SwiftUI's own/// fresh transaction, so the surface always interpolates from the committed collapsed notch.@State private var surfaceIsOpen = false+ /// True while a drag hovers over the surface; drives the "Add anything" drop overlay.+ @State private var isDropTargeted = falseprivate let state: UserQueryStateprivate let updateState: UserQueryUpdateState@@ -40,6 +44,20 @@ public struct UserQueryNotchStatusView: View {private let commandInputTextHeightChanged: @MainActor (CGFloat) -> Voidprivate let commandInputExpansionChanged: @MainActor (Bool) -> Voidprivate let assetsDropped: @MainActor ([UserQueryConversationAssetDraft]) -> Void+ /// Dropped files staged for the next message; each renders as a preview chip above the composer.+ private let stagedAssets: [UserQueryStagedAsset]+ /// The chip's ✕ — removes that staged asset before it is ever committed to a conversation.+ private let stagedAssetRemoved: @MainActor (String) -> Void+ /// Files the user attached to each conversation, keyed by conversation id; they render as+ /// clickable pills under the row's subtext.+ private let conversationAssets: [String: [UserQueryConversationAsset]]+ /// Tapping an attachment pill — opens the persisted copy of the file.+ private let assetOpenRequested: @MainActor (UserQueryConversationAsset) -> Void+ /// What each conversation's runs produced, keyed by conversation id. One output file renders as its+ /// own pill; several collapse into a single pill that opens their folder.+ private let conversationOutputs: [String: UserQueryWorkspaceOutputs]+ /// Tapping an output pill — opens the produced file, or the outputs folder (absolute path).+ private let outputOpenRequested: @MainActor (String) -> Voidprivate let pauseRequested: @MainActor (String) -> Voidprivate let resumeRequested: @MainActor (String) -> Voidprivate let dismissRequested: @MainActor (String) -> Void@@ -90,6 +108,12 @@ public struct UserQueryNotchStatusView: View {commandInputTextHeightChanged: @escaping @MainActor (CGFloat) -> Void,commandInputExpansionChanged: @escaping @MainActor (Bool) -> Void,assetsDropped: @escaping @MainActor ([UserQueryConversationAssetDraft]) -> Void,+ stagedAssets: [UserQueryStagedAsset] = [],+ stagedAssetRemoved: @escaping @MainActor (String) -> Void = { _ in },+ conversationAssets: [String: [UserQueryConversationAsset]] = [:],+ assetOpenRequested: @escaping @MainActor (UserQueryConversationAsset) -> Void = { _ in },+ conversationOutputs: [String: UserQueryWorkspaceOutputs] = [:],+ outputOpenRequested: @escaping @MainActor (String) -> Void = { _ in },pauseRequested: @escaping @MainActor (String) -> Void,resumeRequested: @escaping @MainActor (String) -> Void,dismissRequested: @escaping @MainActor (String) -> Void,@@ -126,6 +150,12 @@ public struct UserQueryNotchStatusView: View {self.commandInputTextHeightChanged = commandInputTextHeightChangedself.commandInputExpansionChanged = commandInputExpansionChangedself.assetsDropped = assetsDropped+ self.stagedAssets = stagedAssets+ self.stagedAssetRemoved = stagedAssetRemoved+ self.conversationAssets = conversationAssets+ self.assetOpenRequested = assetOpenRequested+ self.conversationOutputs = conversationOutputs+ self.outputOpenRequested = outputOpenRequestedself.pauseRequested = pauseRequestedself.resumeRequested = resumeRequestedself.dismissRequested = dismissRequested@@ -223,14 +253,25 @@ public struct UserQueryNotchStatusView: View {if let renderedSpawnCue {spawnCueArrow(renderedSpawnCue)}++ // While a drag hovers, a translucent scrim dims the whole surface and invites the drop.+ // Hover expansion is location-driven (the controller's tick reads the pointer every frame),+ // so by the time the overlay shows, the surface is already opening. Hit testing stays off:+ // the overlay narrates the drop, the canvas underneath receives it.+ if isDropTargeted && !needsLogin {+ dropTargetOverlay+ .allowsHitTesting(false)+ .transition(.opacity)+ }}+ .animation(.easeOut(duration: 0.16), value: isDropTargeted)// The canvas is laid out once at the full expanded size and pinned to the top, so every layer// holds its final position. The growing clip in `body` reveals more of it; nothing reflows..frame(width: expandedSurfaceWidth, height: expandedSurfaceHeight, alignment: .top).contentShape(Rectangle()).onDrop(of: [UTType.fileURL],- isTargeted: nil,+ isTargeted: $isDropTargeted,perform: handleDroppedFileProviders).onAppear(perform: updateRenderedSpawnCue)@@ -642,6 +683,10 @@ public struct UserQueryNotchStatusView: View {}}+ if !stagedAssets.isEmpty {+ stagedAssetChipsRow+ }+commandRow}.padding(.horizontal, Self.contentInset)@@ -649,10 +694,61 @@ public struct UserQueryNotchStatusView: View {}private var expandedCommandOnlyContent: some View {- commandRow- .padding(.top, expandedCommandOnlyTopPadding)- .padding(.horizontal, Self.contentInset)- .padding(.bottom, Self.contentInset)+ VStack(spacing: Self.conversationListCommandSpacing) {+ if !stagedAssets.isEmpty {+ stagedAssetChipsRow+ }++ commandRow+ }+ .padding(.top, expandedCommandOnlyTopPadding)+ .padding(.horizontal, Self.contentInset)+ .padding(.bottom, Self.contentInset)+ }++ /// The staged attachments, one preview chip per dropped file, seated directly above the composer+ /// (the row scrolls sideways when the drops outgrow the surface). The row's height is mirrored into+ /// the expanded-surface metrics (`UserQueryNotchMetrics.stagedAssetsRowExtraHeight`) so the surface+ /// grows to seat it instead of squeezing the composer.+ private var stagedAssetChipsRow: some View {+ ScrollView(.horizontal, showsIndicators: false) {+ HStack(spacing: 8) {+ ForEach(stagedAssets) { asset in+ StagedAssetChip(asset: asset) {+ stagedAssetRemoved(asset.id)+ }+ }+ }+ }+ .frame(height: UserQueryNotchMetrics.stagedAssetChipSide)+ .frame(maxWidth: .infinity, alignment: .leading)+ }++ /// The drag-hover scrim: the surface dims and reads back what a drop will do. Centered over the+ /// expanded content frame so it seats correctly beside a physical notch's void and on a no-notch+ /// display alike.+ private var dropTargetOverlay: some View {+ ZStack(alignment: .top) {+ Color.black.opacity(0.6)++ VStack(spacing: 5) {+ Text("Add anything")+ .font(.system(size: 17, weight: .semibold))+ .foregroundStyle(Color.white)+ Text("Drop any file here to add it to the conversation")+ .font(.system(size: 13))+ .foregroundStyle(Color.white.opacity(0.7))+ }+ .frame(+ width: layout.expandedContentFrame.width,+ height: layout.expandedContentFrame.height+ )+ .offset(+ x: layout.expandedContentFrame.minX,+ y: layout.expandedContentFrame.minY+ )+ }+ .accessibilityHidden(true)}/// The leading arrow over the expanded composer-only surface. It renders only while the notch holds no@@ -953,6 +1049,65 @@ public struct UserQueryNotchStatusView: View {/// Trailing room the subtext leaves for the bottom-pinned elapsed time at its widest (e.g. "59m 59s").private static let conversationTimeColumnReserve: CGFloat = 52+ private func hasFilePills(for conversation: UserQueryConversation) -> Bool {+ conversationAssets[conversation.id]?.isEmpty == false || conversationOutputs[conversation.id] != nil+ }++ /// The row's file pills — one per file the user attached, then the run's outputs — wrapping onto+ /// additional lines when they outgrow the row's width (the row grows; nothing clips). Sits under+ /// the subtext with the same trailing reserve, so pills never run beneath the pinned controls or+ /// elapsed time.+ private func conversationFilesRow(for conversation: UserQueryConversation) -> some View {+ PillFlowLayout(spacing: 6) {+ ForEach(conversationAssets[conversation.id] ?? []) { asset in+ RowFilePill(urlString: asset.urlString, label: asset.displayName) {+ assetOpenRequested(asset)+ }+ }++ if let outputs = conversationOutputs[conversation.id] {+ outputPills(outputs)+ }+ }+ .padding(.top, 2)+ .padding(.trailing, max(controlsReserve(for: conversation), Self.conversationTimeColumnReserve))+ .frame(maxWidth: .infinity, alignment: .leading)+ }++ /// The produced-files pill(s): a lone output renders as its own pill; several collapse into one+ /// pill that opens the outputs folder (labeled with the count, or the folder's name once every+ /// recorded file has been moved or renamed away from its recorded path).+ @ViewBuilder+ private func outputPills(_ outputs: UserQueryWorkspaceOutputs) -> some View {+ if outputs.files.count == 1, let file = outputs.files.first {+ RowFilePill(+ urlString: URL(fileURLWithPath: file.path).absoluteString,+ label: file.displayName+ ) {+ outputOpenRequested(file.path)+ }+ } else if let folderPath = outputs.folderPath {+ RowFilePill(+ urlString: URL(fileURLWithPath: folderPath).absoluteString,+ label: outputs.files.count > 1+ ? "\(outputs.files.count) files"+ : URL(fileURLWithPath: folderPath).lastPathComponent+ ) {+ outputOpenRequested(folderPath)+ }+ } else {+ // Several loose files with no recorded folder — each opens individually.+ ForEach(outputs.files, id: \.path) { file in+ RowFilePill(+ urlString: URL(fileURLWithPath: file.path).absoluteString,+ label: file.displayName+ ) {+ outputOpenRequested(file.path)+ }+ }+ }+ }+/// Full opacity normally; while a reply is targeted, every row except the targeted one dims back so/// the user sees which thread their next message answers.private func rowReplyDimOpacity(for conversation: UserQueryConversation) -> Double {@@ -1018,6 +1173,13 @@ public struct UserQueryNotchStatusView: View {// Subtext runs to just left of the controls, or the bottom-pinned elapsed time..padding(.trailing, max(controlsReserve(for: conversation), Self.conversationTimeColumnReserve))}++ // The thread's files, as clickable pills: what the user attached, then what the run+ // produced. The row grows to seat them, and a pill's tap opens the file (or outputs+ // folder) before the row's own select tap sees the click.+ if hasFilePills(for: conversation) {+ conversationFilesRow(for: conversation)+ }}.frame(maxWidth: .infinity, alignment: .leading).opacity(contentDim)@@ -1942,6 +2104,227 @@ private struct DonkeyAttentionGlyph: View {}}+/// Preview image for an on-disk asset: a QuickLook thumbnail when the type has a visual+/// representation, otherwise the file's Finder icon (flagged so callers can restyle around it).+private enum AssetThumbnailLoader {+ struct Thumbnail {+ let image: NSImage+ let isFileIcon: Bool+ }++ static func load(urlString: String, side: CGFloat) async -> Thumbnail? {+ guard let url = URL(string: urlString), url.isFileURL else { return nil }++ let request = QLThumbnailGenerator.Request(+ fileAt: url,+ size: CGSize(width: side, height: side),+ scale: 2,+ representationTypes: .thumbnail+ )+ if let representation = try? await QLThumbnailGenerator.shared.generateBestRepresentation(for: request) {+ return Thumbnail(image: representation.nsImage, isFileIcon: false)+ }++ return Thumbnail(image: NSWorkspace.shared.icon(forFile: url.path), isFileIcon: true)+ }+}++/// Left-to-right pill flow that wraps to a new line when the next pill would overflow the proposed+/// width, so a row's attachments stack into as many lines as they need instead of clipping.+private struct PillFlowLayout: Layout {+ var spacing: CGFloat = 6++ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {+ arrangement(proposal: proposal, subviews: subviews).size+ }++ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {+ let positions = arrangement(proposal: proposal, subviews: subviews).positions+ for (subview, position) in zip(subviews, positions) {+ subview.place(+ at: CGPoint(x: bounds.minX + position.x, y: bounds.minY + position.y),+ proposal: .unspecified+ )+ }+ }++ private func arrangement(+ proposal: ProposedViewSize,+ subviews: Subviews+ ) -> (positions: [CGPoint], size: CGSize) {+ let maxWidth = proposal.width ?? .infinity+ var positions: [CGPoint] = []+ var x: CGFloat = 0+ var y: CGFloat = 0+ var lineHeight: CGFloat = 0+ var totalWidth: CGFloat = 0+ for subview in subviews {+ let size = subview.sizeThatFits(.unspecified)+ if x > 0, x + size.width > maxWidth {+ x = 0+ y += lineHeight + spacing+ lineHeight = 0+ }+ positions.append(CGPoint(x: x, y: y))+ lineHeight = max(lineHeight, size.height)+ totalWidth = max(totalWidth, x + size.width)+ x += size.width + spacing+ }+ return (positions, CGSize(width: totalWidth, height: y + lineHeight))+ }+}++/// A file (or folder) inside a conversation row: a small thumbnail-and-name pill. Tapping it opens the+/// target; the pill's click takes precedence over the row's own select tap. Hover brightens the fill+/// and label, and the press dims-and-shrinks it, so the pill visibly reads as clickable.+private struct RowFilePill: View {+ let urlString: String+ let label: String+ let open: @MainActor () -> Void++ @State private var thumbnail: NSImage?+ @State private var isHovering = false++ var body: some View {+ Button(action: open) {+ HStack(spacing: 6) {+ Group {+ if let thumbnail {+ Image(nsImage: thumbnail)+ .resizable()+ .aspectRatio(contentMode: .fill)+ } else {+ Image(systemName: "doc")+ .font(.system(size: 10))+ .foregroundStyle(Color.white.opacity(0.6))+ }+ }+ .frame(width: 20, height: 20)+ .clipShape(RoundedRectangle(cornerRadius: 4, style: .continuous))++ Text(label)+ .font(.system(size: 11))+ .foregroundStyle(Color.white.opacity(isHovering ? 0.92 : 0.75))+ .lineLimit(1)+ .truncationMode(.middle)+ .frame(maxWidth: 180, alignment: .leading)+ .fixedSize(horizontal: true, vertical: false)+ }+ .padding(.leading, 4)+ .padding(.trailing, 8)+ .padding(.vertical, 4)+ }+ .buttonStyle(RowFilePillButtonStyle(isHovering: isHovering))+ .onHover { hovering in+ isHovering = hovering+ }+ .animation(.easeOut(duration: 0.12), value: isHovering)+ .task(id: urlString) {+ thumbnail = await AssetThumbnailLoader.load(urlString: urlString, side: 20)?.image+ }+ .accessibilityElement(children: .ignore)+ .accessibilityLabel("Open \(label)")+ }+}++/// The pill's fill and press feedback: idle 0.08 white, brightening on hover, brighter still and+/// slightly shrunken while pressed — the same enabled/hover tinting scale the notch controls use.+private struct RowFilePillButtonStyle: ButtonStyle {+ let isHovering: Bool++ func makeBody(configuration: Configuration) -> some View {+ configuration.label+ .background(Color.white.opacity(configuration.isPressed ? 0.22 : (isHovering ? 0.14 : 0.08)))+ .clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))+ .contentShape(RoundedRectangle(cornerRadius: 6, style: .continuous))+ .scaleEffect(configuration.isPressed ? 0.97 : 1)+ .animation(.easeOut(duration: 0.1), value: configuration.isPressed)+ }+}++/// One staged attachment: a square preview (QuickLook thumbnail, falling back to the file's icon over+/// the file name) with a ✕ in the top-right corner that removes the asset before it is committed.+private struct StagedAssetChip: View {+ let asset: UserQueryStagedAsset+ let remove: @MainActor () -> Void++ @State private var thumbnail: NSImage?+ @State private var thumbnailIsFileIcon = false++ private static let side = UserQueryNotchMetrics.stagedAssetChipSide++ var body: some View {+ ZStack(alignment: .topTrailing) {+ preview+ .frame(width: Self.side, height: Self.side)+ .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))+ .overlay(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .strokeBorder(Color.white.opacity(0.14), lineWidth: 1)+ )++ removeButton+ .padding(5)+ }+ .frame(width: Self.side, height: Self.side)+ .task(id: asset.draft.urlString) { await loadThumbnail() }+ .accessibilityElement(children: .ignore)+ .accessibilityLabel("Attached file \(asset.draft.displayName)")+ }++ @ViewBuilder+ private var preview: some View {+ if let thumbnail, !thumbnailIsFileIcon {+ Image(nsImage: thumbnail)+ .resizable()+ .aspectRatio(contentMode: .fill)+ } else {+ VStack(spacing: 6) {+ if let thumbnail {+ Image(nsImage: thumbnail)+ .resizable()+ .aspectRatio(contentMode: .fit)+ .frame(width: 30, height: 30)+ }+ Text(asset.draft.displayName)+ .font(.system(size: 10))+ .foregroundStyle(Color.white.opacity(0.7))+ .lineLimit(2)+ .multilineTextAlignment(.center)+ .padding(.horizontal, 6)+ }+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .background(Color.white.opacity(0.085))+ }+ }++ private var removeButton: some View {+ Button(action: remove) {+ ZStack {+ Circle()+ .fill(Color.white)+ .frame(width: 18, height: 18)+ .shadow(color: Color.black.opacity(0.35), radius: 2, y: 1)++ Image(systemName: "xmark")+ .font(.system(size: 8, weight: .bold))+ .foregroundStyle(Color.black.opacity(0.8))+ }+ }+ .buttonStyle(.plain)+ .accessibilityLabel("Remove attached file \(asset.draft.displayName)")+ }++ private func loadThumbnail() async {+ guard let loaded = await AssetThumbnailLoader.load(urlString: asset.draft.urlString, side: Self.side) else {+ return+ }++ thumbnail = loaded.image+ thumbnailIsFileIcon = loaded.isFileIcon+ }+}+private final class DroppedAssetCollector: @unchecked Sendable {private let lock = NSLock()private var drafts: [UserQueryConversationAssetDraft] = []