@@ -25,7 +25,7 @@ private struct T3ConnectManagedCleanupError: LocalizedError {
2525@ MainActor
2626final class NativeFeatureClient : FeatureClient , FeatureDeviceManaging ,
2727 FeatureProjectCreationClient , FeatureWorkspaceAssetResolving , FeatureAttachmentAssetResolving ,
28- FeatureFeedbackSubmitting , T3ConnectCapable
28+ FeatureFeedbackSubmitting , FeatureContextAttachmentResolving , T3ConnectCapable
2929{
3030 private static let maximumRetainedThreadDetails = 6
3131 private static let t3ConnectLogger = Logger (
@@ -1529,7 +1529,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
15291529 shell : shellsByEnvironmentID [ environment . id ]
15301530 )
15311531 let title = Self . title ( from : prompt , hasAttachments : ! attachments . isEmpty )
1532- let uploads = try makeUploadAttachments ( attachments )
1532+ let uploads = try await makeUploadAttachments ( attachments )
15331533 if ! uploads . isEmpty { _ = try await client . serverConfig ( ) }
15341534 let runtime = coreRuntimeMode ( runtimeMode )
15351535 let interaction = coreInteractionMode ( interactionMode )
@@ -2208,7 +2208,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
22082208 throw NativeFeatureClientError . threadNotFound
22092209 }
22102210 let model = selection . map ( coreModelSelection )
2211- let uploads = try makeUploadAttachments ( attachments )
2211+ let uploads = try await makeUploadAttachments ( attachments )
22122212 if ! uploads . isEmpty { _ = try await client . serverConfig ( ) }
22132213 let runtimeMode = coreRuntimeMode (
22142214 requestedRuntimeMode ?? mapRuntimeMode ( shellThread . runtimeMode )
@@ -2474,11 +2474,15 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
24742474 throw NativeFeatureClientError . inputRequestNotFound
24752475 }
24762476 let route = try threadRoute ( for : request . threadID )
2477+ var uploads : [ String : [ UploadChatAttachment ] ] = [ : ]
2478+ for ( questionID , attachments ) in attachmentsByQuestionID {
2479+ uploads [ questionID ] = try await makeUploadAttachments ( attachments )
2480+ }
24772481 _ = try await route . client . respondToUserInput (
24782482 threadID : route . wireID ,
24792483 requestID : request . wireID ,
24802484 answers : answers . mapValues ( \. jsonValue ) ,
2481- attachmentsByQuestionID : try attachmentsByQuestionID . mapValues ( makeUploadAttachments )
2485+ attachmentsByQuestionID : uploads
24822486 )
24832487 inputRoutes [ id ] = nil
24842488 removeCachedInput ( id : id , threadID : route . uiID )
@@ -3433,9 +3437,8 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
34333437 ) async throws -> FeatureUploadedAttachmentReference ? {
34343438 let client = try await projectCreationClient ( environmentID : environmentID )
34353439 _ = try await client . serverConfig ( )
3436- let prepared = try await client . prepareAttachment (
3437- makeUploadAttachments ( [ attachment ] ) [ 0 ]
3438- )
3440+ let uploads = try await makeUploadAttachments ( [ attachment ] )
3441+ let prepared = try await client . prepareAttachment ( uploads [ 0 ] )
34393442 return prepared . map {
34403443 FeatureUploadedAttachmentReference (
34413444 environmentID : $0 . environmentID ,
@@ -7097,6 +7100,25 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
70977100 return resolved . url
70987101 }
70997102
7103+ func contextAttachmentAssetURL (
7104+ environmentID : String , attachment : ComposerContextRecord . Attachment
7105+ ) async throws -> URL {
7106+ try Task . checkCancellation ( )
7107+ guard try await runtime . environments ( ) . contains ( where : { $0 . id == environmentID && $0 . isEnabled } ) else {
7108+ throw ComposerContextClipboardError . sourceUnavailable
7109+ }
7110+ let client = try await projectCreationClient ( environmentID : environmentID )
7111+ let generation = environmentGeneration
7112+ let resolved = try await client . resolvedAsset ( resource : . attachment (
7113+ id : attachment . attachmentId , fileName : attachment . name , mimeType : attachment . mimeType
7114+ ) )
7115+ try Task . checkCancellation ( )
7116+ guard isKnownClient ( client , environmentID : environmentID , generation : generation ) else {
7117+ throw CancellationError ( )
7118+ }
7119+ return resolved . url
7120+ }
7121+
71007122 private func lastActivityDate (
71017123 latestUserMessageAt : String ? ,
71027124 latestTurn : OrchestrationLatestTurn ?
@@ -7161,37 +7183,47 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
71617183
71627184 private func makeUploadAttachments (
71637185 _ attachments : [ FeatureUploadAttachment ]
7164- ) throws -> [ UploadChatAttachment ] {
7186+ ) async throws -> [ UploadChatAttachment ] {
71657187 guard attachments . count <= 8 else {
71667188 throw NativeFeatureClientError . tooManyAttachments
71677189 }
7168- return try attachments . map {
7169- let reference = $0 . uploadedReference . map {
7170- UploadedAttachmentReference (
7171- environmentID : $0 . environmentID ,
7172- attachmentID : $0 . attachmentID
7173- )
7174- }
7175- if let ownedFile = $0 . ownedFile {
7190+ let uploads = try await Task . detached ( priority : . userInitiated ) {
7191+ try attachments . map {
7192+ let reference = $0 . uploadedReference . map {
7193+ UploadedAttachmentReference (
7194+ environmentID : $0 . environmentID ,
7195+ attachmentID : $0 . attachmentID
7196+ )
7197+ }
7198+ if let ownedFile = $0 . ownedFile {
7199+ if $0 . mimeType . trimmingCharacters ( in : . whitespacesAndNewlines ) . lowercased ( ) . hasPrefix ( " image/ " ) {
7200+ return try UploadChatAttachment (
7201+ id : $0 . id , data : Data ( contentsOf : ownedFile . url ) ,
7202+ name : $0 . name , mimeType : $0 . mimeType , uploadedReference : reference
7203+ )
7204+ }
7205+ return try UploadChatAttachment (
7206+ id : $0 . id ,
7207+ fileURL : ownedFile . url ,
7208+ name : $0 . name ,
7209+ mimeType : $0 . mimeType ,
7210+ sizeBytes : ownedFile . byteCount ,
7211+ uploadedReference : reference ,
7212+ contextSource : $0 . source
7213+ )
7214+ }
71767215 return try UploadChatAttachment (
71777216 id : $0 . id ,
7178- fileURL : ownedFile . url ,
7217+ data : $0 . data ,
71797218 name : $0 . name ,
71807219 mimeType : $0 . mimeType ,
7181- sizeBytes : ownedFile . byteCount ,
71827220 uploadedReference : reference ,
71837221 contextSource : $0 . source
71847222 )
71857223 }
7186- return try UploadChatAttachment (
7187- id : $0 . id ,
7188- data : $0 . data ,
7189- name : $0 . name ,
7190- mimeType : $0 . mimeType ,
7191- uploadedReference : reference ,
7192- contextSource : $0 . source
7193- )
7194- }
7224+ } . value
7225+ try Task . checkCancellation ( )
7226+ return uploads
71957227 }
71967228
71977229 private func requireScope ( _ scope : String , client : T3Client ) async throws {
0 commit comments