Inkspring / app · inkspring.ai / native-mac / Sources / Inkspring / AgentConnectionGuide.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | /// When the agent setup banner may show. "Later" hides it for a week; "Don't show again" hides it for good. |
| 4 | enum AgentGuideInvitationSchedule { |
| 5 | static let dismissedKey = "inkspringAgentGuideInvitationSeen" |
| 6 | static let snoozedUntilKey = "inkspringAgentGuideInvitationSnoozedUntil" |
| 7 | static let laterInterval: TimeInterval = 7 * 24 * 60 * 60 |
| 8 | |
| 9 | static func isVisible(dismissed: Bool, snoozedUntil: Double, now: Date = .now) -> Bool { |
| 10 | !dismissed && now.timeIntervalSince1970 >= snoozedUntil |
| 11 | } |
| 12 | |
| 13 | static func later(from now: Date = .now) -> Double { |
| 14 | now.timeIntervalSince1970 + laterInterval |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | struct AgentGuideInvitation: View { |
| 19 | @Environment(\.studioPalette) private var palette |
| 20 | let open: () -> Void |
| 21 | let later: () -> Void |
| 22 | let dismissForever: () -> Void |
| 23 | |
| 24 | var body: some View { |
| 25 | HStack(spacing: 14) { |
| 26 | Image(systemName: "bubble.left.and.text.bubble.right").foregroundStyle(palette.iconAccent) |
| 27 | .accessibilityHidden(true) |
| 28 | Text("Bring your AI agent into your writing workspace.") |
| 29 | .font(InkspringTypography.interface(14)) |
| 30 | Button("Don’t show again", action: dismissForever) |
| 31 | .buttonStyle(.plain) |
| 32 | .font(InkspringTypography.interface(12)) |
| 33 | .foregroundStyle(palette.muted) |
| 34 | .padding(.leading, 10) |
| 35 | .accessibilityIdentifier("agentInvitation.dontShowAgain") |
| 36 | Spacer() |
| 37 | Button("Later", action: later) |
| 38 | .buttonStyle(StudioActionStyle()) |
| 39 | .accessibilityIdentifier("agentInvitation.later") |
| 40 | Button("Set up AI agents", action: open).buttonStyle(StudioActionStyle(prominent: true)) |
| 41 | } |
| 42 | .padding(.horizontal, 22).padding(.vertical, 10) |
| 43 | .background(palette.panel) |
| 44 | .overlay(alignment: .bottom) { StudioRule() } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | struct AgentConnectionGuide: View { |
| 49 | enum Step: Int, CaseIterable { |
| 50 | case access, client, verify |
| 51 | |
| 52 | var name: String { |
| 53 | switch self { |
| 54 | case .access: "Workspace access" |
| 55 | case .client: "Connect a client" |
| 56 | case .verify: "Try it out" |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | var heading: String { |
| 61 | switch self { |
| 62 | case .access: "Choose what your agent can do" |
| 63 | case .client: "Connect your writing workspace" |
| 64 | case .verify: "Ask about your projects" |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | let workspace: Workspace |
| 70 | @Environment(\.studioPalette) private var palette |
| 71 | @Environment(\.dismiss) private var dismiss |
| 72 | @State private var step: Step = .access |
| 73 | @State private var copied = false |
| 74 | private let sample = "List my Inkspring projects." |
| 75 | |
| 76 | var body: some View { |
| 77 | VStack(alignment: .leading, spacing: 0) { |
| 78 | HStack { |
| 79 | Text("AI agent setup").font(InkspringTypography.interface(15).weight(.semibold)) |
| 80 | Spacer() |
| 81 | Button("Close") { dismiss() }.keyboardShortcut(.cancelAction) |
| 82 | }.padding(.horizontal, 28).padding(.vertical, 18) |
| 83 | StudioRule() |
| 84 | ScrollView { |
| 85 | VStack(alignment: .leading, spacing: 18) { |
| 86 | Text("Step \(step.rawValue + 1) of 3 · \(step.name)").foregroundStyle(palette.muted) |
| 87 | Text(step.heading).font(InkspringTypography.interface(27).weight(.semibold)) |
| 88 | .accessibilityAddTraits(.isHeader) |
| 89 | switch step { |
| 90 | case .access: |
| 91 | Text("MCP connects an AI client to this Mac so you can ask about drafts or save a new idea. Your AI provider may receive content your agent reads.") |
| 92 | AgentSettings(workspace: workspace, section: .access) |
| 93 | case .client: |
| 94 | Text("Use the client you’ll write in. Open a fresh session after saving the connection, and approve the connector there if prompted.") |
| 95 | AgentSettings(workspace: workspace, section: .client) |
| 96 | if !workspace.agentAccessEnabled { |
| 97 | Text("To use the connector, turn on workspace access in the previous step.").foregroundStyle(palette.muted) |
| 98 | } |
| 99 | case .verify: |
| 100 | Text("Test the local connector first. Then ask your AI client this question to check the whole connection.") |
| 101 | AgentSettings(workspace: workspace, section: .test) |
| 102 | StudioRule() |
| 103 | Text(sample).font(InkspringTypography.interface(18).weight(.medium)).textSelection(.enabled) |
| 104 | Button(copied ? "Copied" : "Copy question", systemImage: "doc.on.doc") { |
| 105 | copy(sample) |
| 106 | copied = true |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | .frame(maxWidth: .infinity, alignment: .leading) |
| 111 | .padding(28) |
| 112 | } |
| 113 | StudioRule() |
| 114 | HStack { |
| 115 | if step != .access { |
| 116 | Button("Back") { step = step == .verify ? .client : .access } |
| 117 | } |
| 118 | Spacer() |
| 119 | Button(step == .verify ? "Done" : "Continue") { |
| 120 | switch step { |
| 121 | case .access: step = .client |
| 122 | case .client: step = .verify |
| 123 | case .verify: dismiss() |
| 124 | } |
| 125 | } |
| 126 | .buttonStyle(StudioActionStyle(prominent: true)) |
| 127 | .keyboardShortcut(.defaultAction) |
| 128 | }.padding(.horizontal, 28).padding(.vertical, 16) |
| 129 | } |
| 130 | .frame(width: 580, height: 550) |
| 131 | .background(palette.canvas) |
| 132 | .studioAppearance(palette) |
| 133 | } |
| 134 | } |