Open History to see the last commit
1import Foundation
2
3public struct FeatureConnection: Sendable, Equatable, Codable {
4 public enum State: String, Sendable, Hashable, Codable {
5 case disconnected
6 case connecting
7 case connected
8 case reconnecting
9 }
10
11 public var state: State
12 public var environmentName: String?
13 public var endpoint: String?
14 public var detail: String?
15
16 public init(
17 state: State = .disconnected,
18 environmentName: String? = nil,
19 endpoint: String? = nil,
20 detail: String? = nil
21 ) {
22 self.state = state
23 self.environmentName = environmentName
24 self.endpoint = endpoint
25 self.detail = detail
26 }
27}
28
29public struct FeatureEnvironment: Identifiable, Sendable, Equatable, Hashable, Codable {
30 public enum Source: String, Sendable, Equatable, Hashable, Codable {
31 case direct
32 case t3Connect
33 }
34
35 public let id: String
36 public var name: String
37 public var endpoint: String
38 /// Internal stream-leader compatibility. Product routing must use the
39 /// project or thread environment instead.
40 public var isActive: Bool
41 public var isEnabled: Bool
42 public var source: Source
43 /// Reachability from the latest aggregate refresh. `nil` means the client
44 /// has not probed this saved environment yet.
45 public var connectionState: FeatureConnection.State?
46 public var connectionDetail: String?
47 public var machineIcon: String? = nil
48 public var canCustomizeIcon: Bool? = nil
49
50 public var systemImage: String {
51 switch machineIcon {
52 case "cloud": "cloud"
53 case "desktop": "desktopcomputer"
54 case "laptop": "laptopcomputer"
55 case "mac-mini": "macmini"
56 case "mac-studio": "macstudio"
57 default: "server.rack"
58 }
59 }
60
61 public init(
62 id: String,
63 name: String,
64 endpoint: String,
65 isActive: Bool = false,
66 isEnabled: Bool = true,
67 source: Source = .direct,
68 connectionState: FeatureConnection.State? = nil,
69 connectionDetail: String? = nil
70 ) {
71 self.id = id
72 self.name = name
73 self.endpoint = endpoint
74 self.isActive = isActive
75 self.isEnabled = isEnabled
76 self.source = source
77 self.connectionState = connectionState
78 self.connectionDetail = connectionDetail
79 }
80
81 private enum CodingKeys: String, CodingKey {
82 case id
83 case name
84 case endpoint
85 case isActive
86 case isEnabled
87 case source
88 case connectionState
89 case connectionDetail
90 case machineIcon
91 case canCustomizeIcon
92 }
93
94 public init(from decoder: any Decoder) throws {
95 let container = try decoder.container(keyedBy: CodingKeys.self)
96 id = try container.decode(String.self, forKey: .id)
97 name = try container.decode(String.self, forKey: .name)
98 endpoint = try container.decode(String.self, forKey: .endpoint)
99 isActive = try container.decodeIfPresent(Bool.self, forKey: .isActive) ?? false
100 isEnabled = try container.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? true
101 source = try container.decodeIfPresent(Source.self, forKey: .source) ?? .direct
102 connectionState = try container.decodeIfPresent(
103 FeatureConnection.State.self,
104 forKey: .connectionState
105 )
106 connectionDetail = try container.decodeIfPresent(String.self, forKey: .connectionDetail)
107 machineIcon = try container.decodeIfPresent(String.self, forKey: .machineIcon)
108 canCustomizeIcon = try container.decodeIfPresent(Bool.self, forKey: .canCustomizeIcon)
109 }
110}
111
112public struct FeatureRepositoryIdentity: Sendable, Equatable, Hashable, Codable {
113 public var canonicalKey: String
114 public var rootPath: String?
115 public var displayName: String?
116 public var name: String?
117
118 public init(
119 canonicalKey: String,
120 rootPath: String? = nil,
121 displayName: String? = nil,
122 name: String? = nil
123 ) {
124 self.canonicalKey = canonicalKey
125 self.rootPath = rootPath
126 self.displayName = displayName
127 self.name = name
128 }
129}
130
131public struct FeatureProject: Identifiable, Sendable, Equatable, Hashable, Codable {
132 public let id: String
133 /// The environment-local identifier sent over the wire. Native aggregate
134 /// snapshots scope `id` by environment so cloned databases remain distinct.
135 public var wireID: String?
136 public var environmentID: String
137 public var name: String
138 public var path: String
139 public var threadCount: Int
140 public var defaultSelection: FeatureSelection?
141 public var repositoryIdentity: FeatureRepositoryIdentity?
142 public var createdAt: String?
143 public var updatedAt: String?
144 public var projectIcon: ProjectIconOverride? = nil
145
146 public init(
147 id: String,
148 wireID: String? = nil,
149 environmentID: String,
150 name: String,
151 path: String,
152 threadCount: Int = 0,
153 defaultSelection: FeatureSelection? = nil,
154 repositoryIdentity: FeatureRepositoryIdentity? = nil,
155 createdAt: String? = nil,
156 updatedAt: String? = nil
157 ) {
158 self.id = id
159 self.wireID = wireID
160 self.environmentID = environmentID
161 self.name = name
162 self.path = path
163 self.threadCount = threadCount
164 self.defaultSelection = defaultSelection
165 self.repositoryIdentity = repositoryIdentity
166 self.createdAt = createdAt
167 self.updatedAt = updatedAt
168 }
169}
170
171public enum FeatureThreadState: String, Sendable, Codable {
172 case idle
173 case queued
174 case working
175 case monitoring
176 case waitingForApproval
177 case waitingForInput
178 case failed
179 case completed
180}
181
182public enum FeatureRuntimeMode: String, CaseIterable, Sendable, Codable {
183 case approvalRequired
184 case autoAcceptEdits
185 case automatic
186 case fullAccess
187
188 /// Mobile offers the two current modes. Legacy modes remain distinct so
189 /// existing threads keep their exact server permission.
190 public static let allCases: [FeatureRuntimeMode] = [.automatic, .fullAccess]
191}
192
193public enum FeatureInteractionMode: String, CaseIterable, Sendable, Codable {
194 case standard
195 case plan
196
197 /// Plan remains decodable for existing server state, but is no longer a
198 /// mobile prompt choice.
199 public static let allCases: [FeatureInteractionMode] = [.standard]
200
201 public var mobileNormalized: FeatureInteractionMode { .standard }
202}
203
204public enum FeatureThreadSettlementOverride: String, Sendable, Equatable, Hashable, Codable {
205 case settled
206 case active
207}
208
209public struct FeatureThreadSettlementFacts: Sendable, Equatable, Hashable, Codable {
210 public struct LatestTurn: Sendable, Equatable, Hashable, Codable {
211 public var requestedAt: Date?
212 public var startedAt: Date?
213 public var completedAt: Date?
214 public var requestedAtIsInvalid: Bool
215 public var startedAtIsInvalid: Bool
216 public var completedAtIsInvalid: Bool
217
218 public init(
219 requestedAt: Date? = nil,
220 startedAt: Date? = nil,
221 completedAt: Date? = nil,
222 requestedAtIsInvalid: Bool = false,
223 startedAtIsInvalid: Bool = false,
224 completedAtIsInvalid: Bool = false
225 ) {
226 self.requestedAt = requestedAt
227 self.startedAt = startedAt
228 self.completedAt = completedAt
229 self.requestedAtIsInvalid = requestedAtIsInvalid
230 self.startedAtIsInvalid = startedAtIsInvalid
231 self.completedAtIsInvalid = completedAtIsInvalid
232 }
233 }
234
235 public var settlementOverride: FeatureThreadSettlementOverride?
236 public var sessionStatus: String?
237 public var hasPendingApprovals: Bool
238 public var hasPendingUserInput: Bool
239 public var latestUserMessageAt: Date?
240 public var latestTurn: LatestTurn?
241
242 public init(
243 settlementOverride: FeatureThreadSettlementOverride? = nil,
244 sessionStatus: String? = nil,
245 hasPendingApprovals: Bool = false,
246 hasPendingUserInput: Bool = false,
247 latestUserMessageAt: Date? = nil,
248 latestTurn: LatestTurn? = nil
249 ) {
250 self.settlementOverride = settlementOverride
251 self.sessionStatus = sessionStatus
252 self.hasPendingApprovals = hasPendingApprovals
253 self.hasPendingUserInput = hasPendingUserInput
254 self.latestUserMessageAt = latestUserMessageAt
255 self.latestTurn = latestTurn
256 }
257}
258
259public struct FeatureThread: Identifiable, Sendable, Equatable, Hashable, Codable {
260 public let id: String
261 /// The environment-local identifier sent over the wire.
262 public var wireID: String?
263 public var projectID: String
264 public var environmentID: String?
265 public var environmentName: String?
266 public var title: String
267 public var preview: String?
268 public var branch: String?
269 public var worktreePath: String?
270 public var linkedPullRequest: ThreadLinkedPullRequest?
271 public var createdAt: Date
272 public var updatedAt: Date
273 public var state: FeatureThreadState
274 public var providerID: String?
275 public var providerName: String?
276 public var modelID: String?
277 public var modelOptions: [FeatureModelOptionSelection]
278 public var isArchived: Bool
279 public var isSettled: Bool
280 public var keepsActive: Bool
281 public var settledAt: Date?
282 public var unsettledAt: Date?
283 public var lastActivityAt: Date?
284 public var snoozedUntil: Date?
285 public var snoozedAt: Date?
286 public var pinnedAt: Date?
287 public var supportsSettlement: Bool?
288 public var supportsSnooze: Bool?
289 public var supportsPinning: Bool?
290 public var supportsTitleRegeneration: Bool?
291 public var supportsPullRequestLinking: Bool?
292 public var attentionAt: Date?
293 public var workingStartedAt: Date?
294 public var latestTurnCompletedAt: Date?
295 public var settlementFacts: FeatureThreadSettlementFacts?
296 public var runtimeMode: FeatureRuntimeMode
297 public var interactionMode: FeatureInteractionMode
298
299 public init(
300 id: String,
301 wireID: String? = nil,
302 projectID: String,
303 environmentID: String? = nil,
304 environmentName: String? = nil,
305 title: String,
306 preview: String? = nil,
307 branch: String? = nil,
308 worktreePath: String? = nil,
309 linkedPullRequest: ThreadLinkedPullRequest? = nil,
310 createdAt: Date = .now,
311 updatedAt: Date = .now,
312 state: FeatureThreadState = .idle,
313 providerID: String? = nil,
314 providerName: String? = nil,
315 modelID: String? = nil,
316 modelOptions: [FeatureModelOptionSelection] = [],
317 isArchived: Bool = false,
318 isSettled: Bool = false,
319 keepsActive: Bool = false,
320 settledAt: Date? = nil,
321 unsettledAt: Date? = nil,
322 lastActivityAt: Date? = nil,
323 snoozedUntil: Date? = nil,
324 snoozedAt: Date? = nil,
325 pinnedAt: Date? = nil,
326 supportsSettlement: Bool? = nil,
327 supportsSnooze: Bool? = nil,
328 supportsPinning: Bool? = nil,
329 supportsTitleRegeneration: Bool? = nil,
330 supportsPullRequestLinking: Bool? = nil,
331 attentionAt: Date? = nil,
332 workingStartedAt: Date? = nil,
333 latestTurnCompletedAt: Date? = nil,
334 settlementFacts: FeatureThreadSettlementFacts? = nil,
335 runtimeMode: FeatureRuntimeMode = .fullAccess,
336 interactionMode: FeatureInteractionMode = .standard
337 ) {
338 self.id = id
339 self.wireID = wireID
340 self.projectID = projectID
341 self.environmentID = environmentID
342 self.environmentName = environmentName
343 self.title = title
344 self.preview = preview
345 self.branch = branch
346 self.worktreePath = worktreePath
347 self.linkedPullRequest = linkedPullRequest
348 self.createdAt = createdAt
349 self.updatedAt = updatedAt
350 self.state = state
351 self.providerID = providerID
352 self.providerName = providerName
353 self.modelID = modelID
354 self.modelOptions = modelOptions
355 self.isArchived = isArchived
356 self.isSettled = isSettled
357 self.keepsActive = keepsActive
358 self.settledAt = settledAt
359 self.unsettledAt = unsettledAt
360 self.lastActivityAt = lastActivityAt
361 self.snoozedUntil = snoozedUntil
362 self.snoozedAt = snoozedAt
363 self.pinnedAt = pinnedAt
364 self.supportsSettlement = supportsSettlement
365 self.supportsSnooze = supportsSnooze
366 self.supportsPinning = supportsPinning
367 self.supportsTitleRegeneration = supportsTitleRegeneration
368 self.supportsPullRequestLinking = supportsPullRequestLinking
369 self.attentionAt = attentionAt
370 self.workingStartedAt = workingStartedAt
371 self.latestTurnCompletedAt = latestTurnCompletedAt
372 self.settlementFacts = settlementFacts
373 self.runtimeMode = runtimeMode
374 self.interactionMode = interactionMode
375 }
376
377 /// Missing capabilities mean unsupported. Existing states remain reversible
378 /// so older cached snapshots cannot trap a thread in its current state.
379 public var canTogglePin: Bool {
380 pinnedAt != nil || supportsPinning == true
381 }
382
383 public var canToggleSettlement: Bool {
384 isSettled || supportsSettlement == true
385 }
386
387 public var canToggleSnooze: Bool {
388 snoozedUntil != nil || supportsSnooze == true
389 }
390
391}
392
393public enum FeatureMessageRole: String, Sendable, Codable {
394 case user
395 case assistant
396 case system
397 case tool
398}
399
400public enum FeatureMessageState: String, Sendable, Codable {
401 case queued
402 case streaming
403 case complete
404 case failed
405}
406
407public struct FeatureMessageAttachment: Identifiable, Sendable, Equatable, Hashable, Codable {
408 public let id: String
409 public var name: String
410 public var mimeType: String
411 public var sizeBytes: Int
412 public var url: URL?
413 /// Small local preview retained only while an optimistic message is replaced
414 /// by its server-backed attachment URL.
415 public var previewData: Data?
416
417 public init(
418 id: String,
419 name: String,
420 mimeType: String,
421 sizeBytes: Int,
422 url: URL? = nil,
423 previewData: Data? = nil
424 ) {
425 self.id = id
426 self.name = name
427 self.mimeType = mimeType
428 self.sizeBytes = sizeBytes
429 self.url = url
430 self.previewData = previewData
431 }
432}
433
434public struct FeatureUploadAttachment: Sendable, Equatable {
435 public let id: UUID
436 private var inlineData: Data?
437 public var ownedFile: FeatureOwnedAttachmentFile?
438 public var name: String
439 public var mimeType: String
440 public var uploadedReference: FeatureUploadedAttachmentReference?
441
442 public init(
443 id: UUID = UUID(),
444 data: Data,
445 name: String,
446 mimeType: String,
447 uploadedReference: FeatureUploadedAttachmentReference? = nil
448 ) {
449 self.id = id
450 inlineData = data
451 ownedFile = nil
452 self.name = name
453 self.mimeType = mimeType
454 self.uploadedReference = uploadedReference
455 }
456
457 public init(
458 id: UUID = UUID(),
459 ownedFile: FeatureOwnedAttachmentFile,
460 name: String,
461 mimeType: String,
462 uploadedReference: FeatureUploadedAttachmentReference? = nil
463 ) {
464 self.id = id
465 inlineData = nil
466 self.ownedFile = ownedFile
467 self.name = name
468 self.mimeType = mimeType
469 self.uploadedReference = uploadedReference
470 }
471
472 public init(_ draft: FeatureDraftAttachment) {
473 id = draft.id
474 inlineData = draft.ownedFile == nil ? draft.data : nil
475 ownedFile = draft.ownedFile
476 name = draft.filename
477 mimeType = draft.mimeType
478 uploadedReference = draft.uploadedReference
479 }
480
481 public var data: Data {
482 get { inlineData ?? Data() }
483 set {
484 inlineData = newValue
485 ownedFile = nil
486 }
487 }
488
489 public var byteCount: Int {
490 inlineData?.count ?? ownedFile?.byteCount ?? 0
491 }
492}
493
494public struct FeatureMessage: Identifiable, Sendable, Equatable, Hashable, Codable {
495 public let id: String
496 public var role: FeatureMessageRole
497 public var text: String
498 public var createdAt: Date
499 public var state: FeatureMessageState
500 public var toolName: String?
501 public var attachments: [FeatureMessageAttachment]
502 public var workLogImagePaths: [String]?
503 public var activeWorkLabel: String?
504 public var toolPresentation: ToolActivityPresentation? = nil
505
506 public init(
507 id: String,
508 role: FeatureMessageRole,
509 text: String,
510 createdAt: Date = .now,
511 state: FeatureMessageState = .complete,
512 toolName: String? = nil,
513 attachments: [FeatureMessageAttachment] = [],
514 workLogImagePaths: [String]? = nil,
515 activeWorkLabel: String? = nil
516 ) {
517 self.id = id
518 self.role = role
519 self.text = text
520 self.createdAt = createdAt
521 self.state = state
522 self.toolName = toolName
523 self.attachments = attachments
524 self.workLogImagePaths = workLogImagePaths
525 self.activeWorkLabel = activeWorkLabel
526 }
527}
528
529public enum FeatureApprovalKind: String, Sendable, Codable {
530 case command
531 case fileRead
532 case fileChange
533 case mcpElicitation
534 case patch
535 case other
536}
537
538public struct FeatureApprovalOption: Identifiable, Sendable, Equatable, Hashable, Codable {
539 public var id: FeatureApprovalDecision { decision }
540 public let decision: FeatureApprovalDecision
541 public let label: String
542
543 public init(decision: FeatureApprovalDecision, label: String) {
544 self.decision = decision
545 self.label = label
546 }
547}
548
549public struct FeatureApproval: Identifiable, Sendable, Equatable, Hashable, Codable {
550 public let id: String
551 /// The provider request identifier sent over the wire.
552 public var wireID: String?
553 public var threadID: String
554 public var kind: FeatureApprovalKind
555 public var title: String
556 public var detail: String
557 public var appName: String?
558 public var options: [FeatureApprovalOption]?
559
560 public init(
561 id: String,
562 wireID: String? = nil,
563 threadID: String,
564 kind: FeatureApprovalKind,
565 title: String,
566 detail: String,
567 appName: String? = nil,
568 options: [FeatureApprovalOption]? = nil
569 ) {
570 self.id = id
571 self.wireID = wireID
572 self.threadID = threadID
573 self.kind = kind
574 self.title = title
575 self.detail = detail
576 self.appName = appName
577 self.options = options
578 }
579}
580
581public struct FeatureInputOption: Sendable, Equatable, Hashable, Codable {
582 public var label: String
583 public var detail: String
584
585 public init(label: String, detail: String) {
586 self.label = label
587 self.detail = detail
588 }
589}
590
591/// A provider answer is either free-form/single-select text or the selected
592/// labels for a multi-select question. Its Codable shape intentionally matches
593/// the provider wire contract: a JSON string or an array of JSON strings.
594public enum FeatureInputAnswer: Sendable, Equatable, Hashable, Codable {
595 case text(String)
596 case selections([String])
597
598 public init(from decoder: any Decoder) throws {
599 let container = try decoder.singleValueContainer()
600 if let value = try? container.decode(String.self) {
601 self = .text(value)
602 } else {
603 self = try .selections(container.decode([String].self))
604 }
605 }
606
607 public func encode(to encoder: any Encoder) throws {
608 var container = encoder.singleValueContainer()
609 switch self {
610 case let .text(value):
611 try container.encode(value)
612 case let .selections(values):
613 try container.encode(values)
614 }
615 }
616}
617
618extension FeatureInputAnswer {
619 var normalized: FeatureInputAnswer? {
620 switch self {
621 case let .text(value):
622 let normalized = value.trimmingCharacters(in: .whitespacesAndNewlines)
623 return normalized.isEmpty ? nil : .text(normalized)
624 case let .selections(values):
625 var seen: Set<String> = []
626 let normalized = values.compactMap { value -> String? in
627 let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
628 guard !trimmed.isEmpty, seen.insert(trimmed).inserted else { return nil }
629 return trimmed
630 }
631 return normalized.isEmpty ? nil : .selections(normalized)
632 }
633 }
634
635 func togglingOption(_ label: String, allowsMultiple: Bool) -> FeatureInputAnswer {
636 guard allowsMultiple else { return .text(label) }
637
638 let current: [String]
639 if case let .selections(values) = self {
640 current = values
641 } else {
642 current = []
643 }
644
645 if current.contains(label) {
646 return .selections(current.filter { $0 != label })
647 }
648 return .selections(current + [label])
649 }
650}
651
652public struct FeatureInputQuestion: Identifiable, Sendable, Equatable, Hashable, Codable {
653 public let id: String
654 public var header: String
655 public var question: String
656 public var options: [FeatureInputOption]
657 public var allowsMultiple: Bool
658
659 public init(
660 id: String,
661 header: String,
662 question: String,
663 options: [FeatureInputOption] = [],
664 allowsMultiple: Bool = false
665 ) {
666 self.id = id
667 self.header = header
668 self.question = question
669 self.options = options
670 self.allowsMultiple = allowsMultiple
671 }
672}
673
674public struct FeatureUserInput: Identifiable, Sendable, Equatable, Hashable, Codable {
675 public let id: String
676 /// The provider request identifier sent over the wire.
677 public var wireID: String?
678 public var threadID: String
679 public var questions: [FeatureInputQuestion]
680
681 public init(
682 id: String,
683 wireID: String? = nil,
684 threadID: String,
685 questions: [FeatureInputQuestion]
686 ) {
687 self.id = id
688 self.wireID = wireID
689 self.threadID = threadID
690 self.questions = questions
691 }
692}
693
694/// Stable UI identity for entities merged from independent environments.
695/// Length-prefixing avoids separator collisions without requiring IDs to be parsed.
696enum FeatureScopedID {
697 static func project(environmentID: String, wireID: String) -> String {
698 make(kind: "project", environmentID: environmentID, wireID: wireID)
699 }
700
701 static func thread(environmentID: String, wireID: String) -> String {
702 make(kind: "thread", environmentID: environmentID, wireID: wireID)
703 }
704
705 static func approval(environmentID: String, wireID: String) -> String {
706 make(kind: "approval", environmentID: environmentID, wireID: wireID)
707 }
708
709 static func input(environmentID: String, wireID: String) -> String {
710 make(kind: "input", environmentID: environmentID, wireID: wireID)
711 }
712
713 private static func make(kind: String, environmentID: String, wireID: String) -> String {
714 "\(kind):\(environmentID.utf8.count):\(environmentID)\(wireID)"
715 }
716}
717
718public struct FeatureThreadDetail: Sendable, Equatable, Codable {
719 public var thread: FeatureThread
720 public var messages: [FeatureMessage]
721 public var approvals: [FeatureApproval]
722 public var userInputs: [FeatureUserInput]
723 public var page: FeatureThreadPage?
724 public var activeSubagentCount: Int
725 public var backgroundWorkIsActive: Bool
726
727 public init(
728 thread: FeatureThread,
729 messages: [FeatureMessage] = [],
730 approvals: [FeatureApproval] = [],
731 userInputs: [FeatureUserInput] = [],
732 page: FeatureThreadPage? = nil,
733 activeSubagentCount: Int = 0,
734 backgroundWorkIsActive: Bool = false
735 ) {
736 self.thread = thread
737 self.messages = messages
738 self.approvals = approvals
739 self.userInputs = userInputs
740 self.page = page
741 self.activeSubagentCount = activeSubagentCount
742 self.backgroundWorkIsActive = backgroundWorkIsActive
743 }
744}
745
746public struct FeatureThreadPage: Sendable, Equatable, Codable {
747 public var beforeCursor: String?
748 public var hasMore: Bool
749 public var isLoading: Bool
750
751 public init(beforeCursor: String?, hasMore: Bool, isLoading: Bool = false) {
752 self.beforeCursor = beforeCursor
753 self.hasMore = hasMore
754 self.isLoading = isLoading
755 }
756}
757
758/// The small rendered-message delta produced by the native thread stream.
759/// Keeping this beside the authoritative detail lets recycled transcript rows
760/// update in proportion to an event instead of rescanning the full history.
761public struct FeatureDetailDelta: Sendable, Equatable {
762 public var changedMessages: [FeatureMessage]
763 public var appendedMessageIDs: [String]
764
765 public init(
766 changedMessages: [FeatureMessage],
767 appendedMessageIDs: [String] = []
768 ) {
769 self.changedMessages = changedMessages
770 self.appendedMessageIDs = appendedMessageIDs
771 }
772}
773
774public struct FeatureModel: Identifiable, Sendable, Equatable, Hashable, Codable {
775 public let id: String
776 public var name: String
777 public var detail: String?
778 public var supportsImages: Bool
779 public var imageSupportIsUnknown: Bool? = nil
780 public var supportsReasoning: Bool
781 public var isDefault: Bool
782 public var isLegacy: Bool?
783 public var options: [FeatureModelOptionDescriptor]
784
785 public init(
786 id: String,
787 name: String,
788 detail: String? = nil,
789 supportsImages: Bool = false,
790 supportsReasoning: Bool = false,
791 isDefault: Bool = false,
792 isLegacy: Bool? = nil,
793 options: [FeatureModelOptionDescriptor] = []
794 ) {
795 self.id = id
796 self.name = name
797 self.detail = detail
798 self.supportsImages = supportsImages
799 self.supportsReasoning = supportsReasoning
800 self.isDefault = isDefault
801 self.isLegacy = isLegacy
802 self.options = options
803 }
804}
805
806public enum FeatureModelOptionKind: String, Sendable, Equatable, Hashable, Codable {
807 case select
808 case boolean
809}
810
811public struct FeatureModelOptionChoice: Identifiable, Sendable, Equatable, Hashable, Codable {
812 public let id: String
813 public var label: String
814 public var detail: String?
815 public var isDefault: Bool
816
817 public init(
818 id: String,
819 label: String,
820 detail: String? = nil,
821 isDefault: Bool = false
822 ) {
823 self.id = id
824 self.label = label
825 self.detail = detail
826 self.isDefault = isDefault
827 }
828}
829
830public struct FeatureModelOptionDescriptor: Identifiable, Sendable, Equatable, Hashable, Codable {
831 public let id: String
832 public var label: String
833 public var detail: String?
834 public var kind: FeatureModelOptionKind
835 public var choices: [FeatureModelOptionChoice]
836 public var defaultValue: FeatureModelOptionValue?
837
838 public init(
839 id: String,
840 label: String,
841 detail: String? = nil,
842 kind: FeatureModelOptionKind,
843 choices: [FeatureModelOptionChoice] = [],
844 defaultValue: FeatureModelOptionValue? = nil
845 ) {
846 self.id = id
847 self.label = label
848 self.detail = detail
849 self.kind = kind
850 self.choices = choices
851 self.defaultValue = defaultValue
852 }
853}
854
855public enum FeatureModelOptionValue: Sendable, Equatable, Hashable, Codable {
856 case string(String)
857 case boolean(Bool)
858
859 private enum CodingKeys: String, CodingKey {
860 case type
861 case value
862 }
863
864 private enum ValueType: String, Codable {
865 case string
866 case boolean
867 }
868
869 public init(from decoder: any Decoder) throws {
870 let container = try decoder.container(keyedBy: CodingKeys.self)
871 switch try container.decode(ValueType.self, forKey: .type) {
872 case .string:
873 self = try .string(container.decode(String.self, forKey: .value))
874 case .boolean:
875 self = try .boolean(container.decode(Bool.self, forKey: .value))
876 }
877 }
878
879 public func encode(to encoder: any Encoder) throws {
880 var container = encoder.container(keyedBy: CodingKeys.self)
881 switch self {
882 case let .string(value):
883 try container.encode(ValueType.string, forKey: .type)
884 try container.encode(value, forKey: .value)
885 case let .boolean(value):
886 try container.encode(ValueType.boolean, forKey: .type)
887 try container.encode(value, forKey: .value)
888 }
889 }
890}
891
892public struct FeatureModelOptionSelection: Identifiable, Sendable, Equatable, Hashable, Codable {
893 public let id: String
894 public var value: FeatureModelOptionValue
895
896 public init(id: String, value: FeatureModelOptionValue) {
897 self.id = id
898 self.value = value
899 }
900}
901
902public struct FeatureProviderWorkspace: Sendable, Equatable, Hashable, Codable {
903 public let cwd: String
904 public let slashCommands: [FeatureProviderSlashCommand]
905 public let skills: [FeatureProviderSkill]
906}
907
908public struct FeatureProvider: Identifiable, Sendable, Equatable, Hashable, Codable {
909 public let id: String
910 public var name: String
911 public var isAvailable: Bool
912 public var driver: String
913 public var requiresNewThreadForModelChange: Bool
914 public var models: [FeatureModel]
915 public var slashCommands: [FeatureProviderSlashCommand]?
916 public var skills: [FeatureProviderSkill]?
917 public var workspaceSnapshots: [FeatureProviderWorkspace]? = nil
918 public var setup: ProviderSetupCapabilities? = nil
919 public var isEnabled: Bool? = nil
920 public var isInstalled: Bool? = nil
921 public var authStatus: String? = nil
922 public var statusMessage: String? = nil
923
924 func workspaceCatalog(cwd: String?) -> FeatureProviderWorkspace {
925 if let cwd, let workspace = workspaceSnapshots?.first(where: { $0.cwd == cwd }) {
926 return workspace
927 }
928 // A catalog from another workspace must not leak into this composer.
929 return FeatureProviderWorkspace(
930 cwd: cwd ?? "",
931 slashCommands: workspaceSnapshots == nil ? slashCommands ?? [] : [],
932 skills: workspaceSnapshots == nil ? skills ?? [] : []
933 )
934 }
935
936 public init(
937 id: String,
938 name: String,
939 isAvailable: Bool = true,
940 driver: String = "",
941 requiresNewThreadForModelChange: Bool = false,
942 models: [FeatureModel] = [],
943 slashCommands: [FeatureProviderSlashCommand] = [],
944 skills: [FeatureProviderSkill] = []
945 ) {
946 self.id = id
947 self.name = name
948 self.isAvailable = isAvailable
949 self.driver = driver
950 self.requiresNewThreadForModelChange = requiresNewThreadForModelChange
951 self.models = models
952 self.slashCommands = slashCommands
953 self.skills = skills
954 }
955}
956
957public struct FeatureSelection: Sendable, Equatable, Hashable, Codable {
958 public var providerID: String
959 public var modelID: String
960 public var options: [FeatureModelOptionSelection]
961
962 public init(
963 providerID: String,
964 modelID: String,
965 options: [FeatureModelOptionSelection] = []
966 ) {
967 self.providerID = providerID
968 self.modelID = modelID
969 self.options = options
970 }
971}
972
973public enum FeatureAppearance: String, CaseIterable, Sendable, Codable {
974 case system
975 case light
976 case dark
977}
978
979public struct FeatureSettings: Sendable, Equatable, Codable {
980 public var appearance: FeatureAppearance
981 public var hapticsEnabled: Bool
982 public var notificationsEnabled: Bool
983 public var liveActivitiesEnabled: Bool
984 public var defaultSelection: FeatureSelection?
985
986 public init(
987 appearance: FeatureAppearance = .system,
988 hapticsEnabled: Bool = true,
989 notificationsEnabled: Bool = true,
990 liveActivitiesEnabled: Bool = true,
991 defaultSelection: FeatureSelection? = nil
992 ) {
993 self.appearance = appearance
994 self.hapticsEnabled = hapticsEnabled
995 self.notificationsEnabled = notificationsEnabled
996 self.liveActivitiesEnabled = liveActivitiesEnabled
997 self.defaultSelection = defaultSelection
998 }
999
1000 private enum CodingKeys: String, CodingKey {
1001 case appearance
1002 case hapticsEnabled
1003 case notificationsEnabled
1004 case liveActivitiesEnabled
1005 case defaultSelection
1006 }
1007
1008 public init(from decoder: any Decoder) throws {
1009 let container = try decoder.container(keyedBy: CodingKeys.self)
1010 appearance = try container.decodeIfPresent(
1011 FeatureAppearance.self,
1012 forKey: .appearance
1013 ) ?? .system
1014 hapticsEnabled = try container.decodeIfPresent(
1015 Bool.self,
1016 forKey: .hapticsEnabled
1017 ) ?? true
1018 notificationsEnabled = try container.decodeIfPresent(
1019 Bool.self,
1020 forKey: .notificationsEnabled
1021 ) ?? true
1022 liveActivitiesEnabled = try container.decodeIfPresent(
1023 Bool.self,
1024 forKey: .liveActivitiesEnabled
1025 ) ?? true
1026 defaultSelection = try container.decodeIfPresent(
1027 FeatureSelection.self,
1028 forKey: .defaultSelection
1029 )
1030 }
1031
1032 public func encode(to encoder: any Encoder) throws {
1033 var container = encoder.container(keyedBy: CodingKeys.self)
1034 try container.encode(appearance, forKey: .appearance)
1035 try container.encode(hapticsEnabled, forKey: .hapticsEnabled)
1036 try container.encode(notificationsEnabled, forKey: .notificationsEnabled)
1037 try container.encode(liveActivitiesEnabled, forKey: .liveActivitiesEnabled)
1038 try container.encodeIfPresent(defaultSelection, forKey: .defaultSelection)
1039 }
1040}
1041
1042public struct FeatureEnvironmentPreferences: Sendable, Equatable, Codable {
1043 public enum ProjectGroupingMode: String, Sendable, Equatable, Codable {
1044 case repository
1045 case repositoryPath = "repository_path"
1046 case separate
1047 }
1048
1049 public var defaultWorkspaceMode: FeatureWorkspaceMode
1050 public var newWorktreesStartFromOrigin: Bool
1051 public var projectGroupingMode: ProjectGroupingMode
1052 public var projectGroupingOverrides: [String: ProjectGroupingMode]
1053 public var automaticSettlement: FeatureAutomaticSettlementSettings?
1054 public var supportsImageUploads: Bool
1055 public var maxFileAttachmentBytes: Int?
1056
1057 public init(
1058 defaultWorkspaceMode: FeatureWorkspaceMode = .local,
1059 newWorktreesStartFromOrigin: Bool = true,
1060 projectGroupingMode: ProjectGroupingMode = .repository,
1061 projectGroupingOverrides: [String: ProjectGroupingMode] = [:],
1062 automaticSettlement: FeatureAutomaticSettlementSettings? = nil,
1063 supportsImageUploads: Bool = false,
1064 maxFileAttachmentBytes: Int? = nil
1065 ) {
1066 self.defaultWorkspaceMode = defaultWorkspaceMode
1067 self.newWorktreesStartFromOrigin = newWorktreesStartFromOrigin
1068 self.projectGroupingMode = projectGroupingMode
1069 self.projectGroupingOverrides = projectGroupingOverrides
1070 self.automaticSettlement = automaticSettlement
1071 self.supportsImageUploads = supportsImageUploads
1072 self.maxFileAttachmentBytes = maxFileAttachmentBytes
1073 }
1074
1075 private enum CodingKeys: String, CodingKey {
1076 case defaultWorkspaceMode
1077 case newWorktreesStartFromOrigin
1078 case projectGroupingMode
1079 case projectGroupingOverrides
1080 case automaticSettlement
1081 case supportsImageUploads
1082 case maxFileAttachmentBytes
1083 }
1084
1085 public init(from decoder: any Decoder) throws {
1086 let container = try decoder.container(keyedBy: CodingKeys.self)
1087 defaultWorkspaceMode = try container.decodeIfPresent(
1088 FeatureWorkspaceMode.self,
1089 forKey: .defaultWorkspaceMode
1090 ) ?? .local
1091 newWorktreesStartFromOrigin = try container.decodeIfPresent(
1092 Bool.self,
1093 forKey: .newWorktreesStartFromOrigin
1094 ) ?? true
1095 projectGroupingMode = try container.decodeIfPresent(
1096 ProjectGroupingMode.self,
1097 forKey: .projectGroupingMode
1098 ) ?? .repository
1099 supportsImageUploads = try container.decodeIfPresent(
1100 Bool.self,
1101 forKey: .supportsImageUploads
1102 ) ?? false
1103 maxFileAttachmentBytes = try container.decodeIfPresent(
1104 Int.self,
1105 forKey: .maxFileAttachmentBytes
1106 )
1107 projectGroupingOverrides = try container.decodeIfPresent(
1108 [String: ProjectGroupingMode].self,
1109 forKey: .projectGroupingOverrides
1110 ) ?? [:]
1111 automaticSettlement = try container.decodeIfPresent(
1112 FeatureAutomaticSettlementSettings.self,
1113 forKey: .automaticSettlement
1114 )
1115 }
1116
1117 public func encode(to encoder: any Encoder) throws {
1118 var container = encoder.container(keyedBy: CodingKeys.self)
1119 try container.encode(defaultWorkspaceMode, forKey: .defaultWorkspaceMode)
1120 try container.encode(newWorktreesStartFromOrigin, forKey: .newWorktreesStartFromOrigin)
1121 try container.encode(projectGroupingMode, forKey: .projectGroupingMode)
1122 try container.encode(projectGroupingOverrides, forKey: .projectGroupingOverrides)
1123 try container.encodeIfPresent(automaticSettlement, forKey: .automaticSettlement)
1124 try container.encode(supportsImageUploads, forKey: .supportsImageUploads)
1125 try container.encodeIfPresent(maxFileAttachmentBytes, forKey: .maxFileAttachmentBytes)
1126 }
1127}
1128
1129public struct FeatureAutomaticSettlementSettings: Sendable, Equatable, Codable {
1130 public var onMerge: Bool
1131 public var afterDays: Double?
1132
1133 public init(onMerge: Bool, afterDays: Double?) {
1134 self.onMerge = onMerge
1135 self.afterDays = afterDays
1136 }
1137}
1138
1139public enum FeatureAutomaticSettlementChange: Sendable, Equatable {
1140 case onMerge(Bool)
1141 case afterDays(Double?)
1142}
1143
1144public struct FeatureSnapshot: Sendable, Equatable, Codable {
1145 public var connection: FeatureConnection
1146 public var environments: [FeatureEnvironment]
1147 public var projects: [FeatureProject]
1148 public var threads: [FeatureThread]
1149 public var providers: [FeatureProvider]
1150 /// Provider catalogues are environment-scoped. `providers` remains only
1151 /// for decoding older cached snapshots and must not drive product choices.
1152 public var providersByEnvironment: [String: [FeatureProvider]]?
1153 /// Server-authoritative new-thread defaults keyed by saved environment.
1154 public var preferencesByEnvironment: [String: FeatureEnvironmentPreferences]?
1155 public var settings: FeatureSettings
1156
1157 public init(
1158 connection: FeatureConnection = .init(),
1159 environments: [FeatureEnvironment] = [],
1160 projects: [FeatureProject] = [],
1161 threads: [FeatureThread] = [],
1162 providers: [FeatureProvider] = [],
1163 providersByEnvironment: [String: [FeatureProvider]]? = nil,
1164 preferencesByEnvironment: [String: FeatureEnvironmentPreferences]? = nil,
1165 settings: FeatureSettings = .init()
1166 ) {
1167 self.connection = connection
1168 self.environments = environments
1169 self.projects = projects
1170 self.threads = threads
1171 self.providers = providers
1172 self.providersByEnvironment = providersByEnvironment
1173 self.preferencesByEnvironment = preferencesByEnvironment
1174 self.settings = settings
1175 }
1176}
1177
1178public enum FeatureApprovalDecision: String, Sendable, Codable {
1179 case allowOnce
1180 case allowForSession
1181 case allowAlways
1182 case deny
1183 case cancel
1184
1185 init?(wireValue: String) {
1186 switch wireValue {
1187 case "accept": self = .allowOnce
1188 case "acceptForSession": self = .allowForSession
1189 case "acceptAlways": self = .allowAlways
1190 case "decline": self = .deny
1191 case "cancel": self = .cancel
1192 default: return nil
1193 }
1194 }
1195
1196 var wireValue: String {
1197 switch self {
1198 case .allowOnce: "accept"
1199 case .allowForSession: "acceptForSession"
1200 case .allowAlways: "acceptAlways"
1201 case .deny: "decline"
1202 case .cancel: "cancel"
1203 }
1204 }
1205}
1206
1207public enum FeatureThreadSyncState: Sendable, Equatable {
1208 case catchingUp
1209 case reconnecting
1210 case live
1211 case failed(String)
1212}
1213
1214public enum FeatureEvent: Sendable {
1215 case snapshot(FeatureSnapshot)
1216 case connection(FeatureConnection)
1217 case thread(FeatureThread)
1218 case threadRemoved(id: String)
1219 case detail(FeatureThreadDetail)
1220 case detailDelta(FeatureThreadDetail, FeatureDetailDelta)
1221 case threadSync(id: String, state: FeatureThreadSyncState?)
1222 case failure(String)
1223}