Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
refactor(ios): split marketplace view into files
leepokai866545e3c351
diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentIcon.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentIcon.swiftnew file mode 100644index 00000000..61b092c8--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentIcon.swift@@ -0,0 +1,45 @@+import CodyncKit+import SwiftUI+import UIKit++/// A coding agent's logo from the ACP registry, tinted like text; a terminal glyph otherwise.+public struct AgentIcon: View {+ let registry: String?+ let size: CGFloat++ public init(registry: String?, size: CGFloat = 20) {+ self.registry = registry+ self.size = size+ }++ public var body: some View {+ Group {+ if let name = registry.map({ "agent-\($0)" }), Self.exists(name) {+ Image(name, bundle: .module).resizable().scaledToFit()+ } else {+ Image(systemName: "terminal").resizable().scaledToFit().padding(size * 0.1)+ }+ }+ .frame(width: size, height: size)+ .foregroundStyle(tint)+ }++ /// Registry logos are one-color; paint the ones with a known brand color in it.+ private var tint: AnyShapeStyle {+ switch registry {+ case "claude-acp": AnyShapeStyle(Color(red: 0.85, green: 0.47, blue: 0.34))+ case "gemini": AnyShapeStyle(LinearGradient(colors: [Color(red: 0.28, green: 0.59, blue: 0.89), Color(red: 0.57, green: 0.47, blue: 0.78), Color(red: 0.79, green: 0.40, blue: 0.45)], startPoint: .bottomLeading, endPoint: .topTrailing))+ case "antigravity-acp": AnyShapeStyle(Color(red: 0.26, green: 0.52, blue: 0.96))+ case "mistral-vibe": AnyShapeStyle(Color(red: 0.98, green: 0.32, blue: 0.06))+ case "qwen-code": AnyShapeStyle(Color(red: 0.38, green: 0.36, blue: 0.93))+ case "amp-acp": AnyShapeStyle(Color(red: 0.95, green: 0.31, blue: 0.25))+ case "kiro": AnyShapeStyle(Color(red: 0.56, green: 0.27, blue: 1.0))+ case "cortex-code": AnyShapeStyle(Color(red: 0.16, green: 0.71, blue: 0.91))+ default: AnyShapeStyle(Palette.text)+ }+ }++ private static func exists(_ name: String) -> Bool {+ UIImage(named: name, in: .module, with: nil) != nil+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentSheet.swiftnew file mode 100644index 00000000..14bec910--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/AgentSheet.swift@@ -0,0 +1,349 @@+import CodyncKit+import SwiftUI++/// Getting an agent ready on the computer: install it, then sign in. Sign-in+/// options come from the agent itself (ACP), plus Codync's own command for+/// CLIs it knows. Bots are made from New chat, not here.+struct AgentSheet: View {+ let initial: Backend+ @Environment(BotStore.self) private var model+ @State private var route: SetupRoute?+ @State private var auth: AgentAuth?+ @State private var checking = false+ @State private var authenticating: String?+ @State private var error: String?++ /// Live: an install or sign-in updates the host's list.+ private var backend: Backend { model.hello?.backends.first { $0.id == initial.id } ?? initial }+ private var installed: Bool { backend.installed == true }+ private var curated: Bool { backend.curated == true }+ private var signedIn: Bool? { auth?.signedIn ?? backend.signedIn }++ var body: some View {+ ZStack {+ if let route {+ routed(route).transition(.move(edge: .trailing).combined(with: .opacity))+ } else {+ VStack(spacing: 0) {+ ModalHeader(backend.name)+ overview+ }+ .transition(.move(edge: .leading).combined(with: .opacity))+ }+ }+ .frame(minWidth: 0, minHeight: 0)+ // A known "signed in" needs no agent start; everything else asks the agent.+ .task { if backend.signedIn != true { await check() } }+ .onChange(of: route) { old, new in+ // Back from a terminal or key form: see what changed.+ if new == nil, old != nil { Task { await check() } }+ }+ }++ @ViewBuilder private func routed(_ route: SetupRoute) -> some View {+ let back = { withAnimation(Motion.layout) { self.route = nil } }+ switch route {+ case .install: SetupTerminalView(backend: backend, step: .install, back: back)+ case .terminal(let method): SetupTerminalView(backend: backend, step: .login, method: method, back: back)+ case .keys(let method): AgentKeysForm(backend: backend, method: method, saved: auth?.savedEnv ?? [], back: back) { auth = $0 }+ }+ }++ private func go(_ route: SetupRoute) {+ withAnimation(Motion.layout) { self.route = route }+ }++ private var overview: some View {+ CardForm {+ CardSection {+ HStack(spacing: 14) {+ AgentIcon(registry: backend.registry, size: 30)+ .frame(width: 52, height: 52)+ .background(Palette.bubbleAgent, in: RoundedRectangle(cornerRadius: 14, style: .continuous))+ VStack(alignment: .leading, spacing: 2) {+ Text(backend.name).font(.title3.weight(.semibold))+ if let d = backend.description, !d.isEmpty {+ Text(d).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(3)+ }+ }+ }+ .padding(.vertical, 4)+ }+ if curated {+ CardSection {+ SetupStepRow(+ number: 1,+ title: "Install",+ detail: installed+ ? "Installed on \(model.hostName)."+ : backend.canInstall == true ? "Runs the official installer on \(model.hostName)." : backend.installHint,+ done: installed,+ action: installed || backend.canInstall != true ? nil : ("Install", { go(.install) })+ )+ }+ }+ signInSection+ if let error {+ CardSection { Text(error).foregroundStyle(Palette.danger).textSelection(.enabled) }+ }+ }+ }++ private var signInSection: some View {+ CardSection(footer: signedIn != true && auth?.methods.contains(where: { $0.kind == .agent }) == true+ ? "Browser sign-ins open on \(model.hostName) itself. Away from it? Use Remote screen to finish there."+ : nil) {+ HStack(spacing: 0) {+ SetupStepRow(number: curated ? 2 : 1, title: "Sign in", detail: statusText, done: signedIn == true, action: nil)+ if checking {+ ThinkingOrb(state: .connecting, size: 16, color: Palette.secondary)+ } else {+ Button("Check again", systemImage: "arrow.clockwise") { Task { await check() } }+ .labelStyle(.iconOnly)+ .buttonStyle(.plain)+ .foregroundStyle(Palette.secondary)+ .help("Check again")+ }+ }+ if signedIn != true, let detail = auth?.detail, !detail.isEmpty {+ Text(detail).font(.footnote).foregroundStyle(Palette.secondary).textSelection(.enabled)+ }+ // Some CLIs drop the current sign-in the moment a new one starts: no options once signed in.+ if signedIn != true, !checking {+ if auth?.login == true {+ optionRow("Sign in", detail: "In a terminal on \(model.hostName). Links open here.", icon: "terminal") {+ go(.terminal(nil))+ }+ }+ ForEach(auth?.methods ?? []) { m in+ switch m.kind {+ case .terminal?:+ optionRow(m.name, detail: m.description ?? "In a terminal on \(model.hostName).", icon: "terminal") {+ go(.terminal(m))+ }+ case .envVar?:+ optionRow(m.name, detail: m.description ?? "Saved on \(model.hostName) only.", icon: "key") {+ go(.keys(m))+ }+ case .agent?, nil:+ optionRow(+ m.name,+ detail: authenticating == m.id+ ? "Finish signing in in the browser on \(model.hostName)…"+ : m.description ?? "Opens a browser on \(model.hostName).",+ icon: "safari",+ busy: authenticating == m.id+ ) {+ Task { await authenticate(m) }+ }+ }+ }+ }+ }+ }++ private var statusText: String {+ if checking { return auth == nil ? "Checking with \(backend.name)… The first check can download it." : "Checking…" }+ switch signedIn {+ case true?: return "Signed in."+ case false?: return "Not signed in yet."+ case nil: return "Couldn't tell. Skip this if you've already signed in on \(model.hostName)."+ }+ }++ private func optionRow(_ title: String, detail: String, icon: String, busy: Bool = false, action: @escaping () -> Void) -> some View {+ Button(action: action) {+ HStack(spacing: 12) {+ Image(systemName: icon)+ .font(.body)+ .foregroundStyle(Palette.secondary)+ .frame(width: 26)+ .accessibilityHidden(true)+ VStack(alignment: .leading, spacing: 2) {+ Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text)+ Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(3)+ }+ Spacer(minLength: 8)+ if busy {+ ThinkingOrb(size: 16, color: Palette.secondary)+ } else {+ Image(systemName: "chevron.right").font(.caption.weight(.semibold)).foregroundStyle(Palette.tertiary)+ }+ }+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .disabled(authenticating != nil)+ }++ private func check() async {+ guard let client = model.client, !checking else { return }+ checking = true+ defer { checking = false }+ do {+ auth = try await client.agentAuth(backend.id)+ error = nil+ } catch {+ self.error = error.localizedDescription+ }+ await model.refreshBackends()+ }++ private func authenticate(_ m: AuthMethod) async {+ guard let client = model.client else { return }+ authenticating = m.id+ defer { authenticating = nil }+ do {+ auth = try await client.agentAuthenticate(backend.id, method: m.id)+ error = nil+ } catch {+ self.error = error.localizedDescription+ }+ await model.refreshBackends()+ }+}++private enum SetupRoute: Hashable {+ case install+ case terminal(AuthMethod?)+ case keys(AuthMethod)+}++/// Keys an agent reads from its environment, kept on the computer.+private struct AgentKeysForm: View {+ let backend: Backend+ let method: AuthMethod+ let saved: [String]+ let back: () -> Void+ let done: (AgentAuth) -> Void+ @Environment(BotStore.self) private var model+ @State private var values: [String: String] = [:]+ @State private var saving = false+ @State private var error: String?++ private var vars: [AuthMethod.Var] { method.vars ?? [] }++ var body: some View {+ VStack(spacing: 0) {+ ScreenHeader {+ BackButton(action: back).keyboardShortcut(.cancelAction)+ } title: {+ Text(method.name).font(.body.weight(.semibold)).foregroundStyle(Palette.text).lineLimit(1)+ } trailing: {+ if saving {+ Spinner()+ } else {+ IconButton("Save", systemImage: "checkmark") { save(values.filter { !$0.value.isEmpty }) }+ .disabled(vars.contains { !$0.optional && (values[$0.name] ?? "").isEmpty && !saved.contains($0.name) })+ }+ }+ form+ }+ .background(Palette.background)+ }++ private var form: some View {+ CardForm {+ VStack(alignment: .leading, spacing: 6) {+ CardSection(method.name) {+ ForEach(vars, id: \.name) { v in+ VStack(alignment: .leading, spacing: 4) {+ let prompt = Text(saved.contains(v.name) ? "Saved (type to replace)" : v.name)+ Group {+ if v.secret {+ SecureField(v.label, text: binding(v.name), prompt: prompt)+ } else {+ TextField(v.label, text: binding(v.name), prompt: prompt)+ }+ }+ .plainTextInput()+ Text(v.label + (v.optional ? " (optional)" : "")).font(.caption).foregroundStyle(Palette.secondary)+ }+ }+ }+ VStack(alignment: .leading, spacing: 6) {+ if let d = method.description { Text(d) }+ Text("Saved on \(model.hostName) only and given to \(backend.name) when it starts.")+ if let link = method.link, let url = URL(string: link) {+ WebLink("Get a key", url: url)+ }+ }+ .font(.caption)+ .foregroundStyle(Palette.tertiary)+ .padding(.horizontal, 4)+ }+ if !saved.isEmpty {+ CardSection {+ Button("Remove saved keys", role: .destructive) {+ save(Dictionary(uniqueKeysWithValues: vars.map { ($0.name, "") }))+ }+ .buttonStyle(.plain)+ .foregroundStyle(Palette.danger)+ }+ }+ if let error {+ CardSection { Text(error).foregroundStyle(Palette.danger) }+ }+ }+ .textFieldStyle(.plain)+ }++ private func binding(_ name: String) -> Binding<String> {+ Binding(get: { values[name] ?? "" }, set: { values[name] = $0 })+ }++ private func save(_ vars: [String: String]) {+ guard let client = model.client else { return }+ saving = true+ Task {+ defer { saving = false }+ do {+ done(try await client.setAgentEnv(backend.id, vars: vars))+ back()+ } catch {+ self.error = error.localizedDescription+ }+ }+ }+}++private struct SetupStepRow: View {+ let number: Int+ let title: String+ let detail: String+ let done: Bool+ let action: (label: String, run: () -> Void)?++ var body: some View {+ HStack(spacing: 12) {+ ZStack {+ Circle().fill(done ? Palette.accentFill : Palette.bubbleAgent)+ if done {+ Image(systemName: "checkmark").font(.caption.weight(.bold)).foregroundStyle(Palette.onAccent)+ } else {+ Text("\(number)").font(.caption.weight(.semibold)).foregroundStyle(Palette.secondary)+ }+ }+ .frame(width: 26, height: 26)+ .accessibilityHidden(true)+ VStack(alignment: .leading, spacing: 2) {+ Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text)+ Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).textSelection(.enabled)+ }+ Spacer(minLength: 8)+ if let action {+ Button(action.label, action: action.run)+ .buttonStyle(.plain)+ .font(.subheadline.weight(.semibold))+ .foregroundStyle(Palette.text)+ .padding(.horizontal, 14)+ .padding(.vertical, 7)+ .background(Palette.bubbleAgent, in: Capsule())+ .fixedSize()+ }+ }+ .padding(.vertical, 4)+ .accessibilityElement(children: .combine)+ .accessibilityValue(done ? "Done" : "")+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swiftnew file mode 100644index 00000000..0547496e--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/CustomConnectorSheet.swift@@ -0,0 +1,115 @@+import CodyncKit+import SwiftUI++struct CustomConnectorSheet: View {+ private enum Mode: Hashable { case command, url, config }++ @Environment(BotStore.self) private var model+ @Environment(\.dismissModal) private var dismiss+ @Environment(\.webAuthenticationSession) private var webAuthenticationSession+ @Environment(\.openURL) private var openURL+ @State private var name = ""+ @State private var mode = Mode.command+ @State private var target = ""+ @State private var envText = ""+ @State private var config = ""+ @State private var saving = false+ @State private var error: String?++ private var ready: Bool {+ mode == .config+ ? !config.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty+ : !name.trimmingCharacters(in: .whitespaces).isEmpty && !target.trimmingCharacters(in: .whitespaces).isEmpty+ }++ var body: some View {+ VStack(spacing: 0) {+ ModalHeader("Custom connector") {+ if saving {+ Spinner()+ } else {+ IconButton("Add", systemImage: "plus") { save() }+ .disabled(!ready)+ }+ }+ form+ }+ .background(Palette.background)+ }++ private var footer: String {+ switch mode {+ case .command: "Runs on \(model.hostName) in the bot's project folder. Quotes work like in a shell."+ case .url: "A remote MCP server, streamable HTTP or SSE."+ case .config: "Paste the MCP config from a README or another app (Claude, Cursor, VS Code). Every server in it is added. Saved on \(model.hostName) only."+ }+ }++ private var form: some View {+ CardForm {+ CardSection(footer: footer) {+ SegmentedChoice(selection: $mode, options: [(id: .command, label: "Command"), (id: .url, label: "URL"), (id: .config, label: "Config")])+ if mode == .config {+ TextField("{ \"mcpServers\": { … } }", text: $config, axis: .vertical)+ .lineLimit(6...16)+ .font(.callout.monospaced())+ .plainTextInput()+ } else {+ TextField("Name", text: $name)+ TextField(mode == .url ? "https://example.com/mcp" : "npx -y @scope/server", text: $target)+ .font(.callout.monospaced())+ .plainTextInput()+ }+ }+ if mode == .url {+ CardSection("Headers", footer: "Optional, one Name: value per line. Leave empty if the service has you sign in. Saved on \(model.hostName) only.") {+ TextField("Authorization: Bearer …", text: $envText, axis: .vertical)+ .lineLimit(2...6)+ .font(.callout.monospaced())+ .plainTextInput()+ }+ } else if mode == .command {+ CardSection("Environment", footer: "One KEY=value per line. Saved on \(model.hostName) only.") {+ TextField("API_KEY=…", text: $envText, axis: .vertical)+ .lineLimit(2...6)+ .font(.callout.monospaced())+ .plainTextInput()+ }+ }+ if let error {+ CardSection { Text(error).foregroundStyle(Palette.danger) }+ }+ }+ .textFieldStyle(.plain)+ .animation(Motion.layout, value: mode)+ }++ private func save() {+ saving = true+ error = nil+ let remote = mode == .url+ var pairs: [String: String] = [:]+ for line in envText.split(separator: "\n") {+ let parts = line.split(separator: remote ? ":" : "=", maxSplits: 1).map { $0.trimmingCharacters(in: .whitespaces) }+ if parts.count == 2, !parts[0].isEmpty { pairs[parts[0]] = parts[1] }+ }+ Task {+ do {+ let added = mode == .config+ ? try await model.importConnectors(config: config)+ : [try await model.addConnector(+ name: name, command: remote ? nil : target, url: remote ? target : nil,+ env: remote ? [:] : pairs, headers: remote ? pairs : [:]+ )]+ let signIn = ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL)+ for c in added where c.needsSignIn {+ try await signIn.signIn(c.id)+ }+ dismiss()+ } catch {+ self.error = error.localizedDescription+ }+ saving = false+ }+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swiftnew file mode 100644index 00000000..cd72038c--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstallConnectorSheet.swift@@ -0,0 +1,131 @@+import CodyncKit+import SwiftUI++struct InstallConnectorSheet: View {+ let item: MarketConnector+ var requestId: String? = nil+ let done: () -> Void+ @Environment(BotStore.self) private var model+ @Environment(\.dismissModal) private var dismiss+ @Environment(\.webAuthenticationSession) private var webAuthenticationSession+ @Environment(\.openURL) private var openURL+ @State private var optionId = ""+ @State private var values: [String: String] = [:]+ @State private var installed: InstalledConnector?+ @State private var started = false+ @State private var saving = false+ @State private var error: String?++ private var option: MarketConnector.InstallOption? {+ item.options.first { $0.id == optionId } ?? item.options.first+ }++ var body: some View {+ VStack(spacing: 0) {+ ModalHeader("Add connector") {+ if saving {+ Spinner()+ } else {+ IconButton("Add", systemImage: "plus") { install() }+ .disabled(installed == nil && (option?.inputs.contains { $0.required && (values[$0.name] ?? $0.default ?? "").isEmpty } ?? true))+ }+ }+ form+ }+ .background(Palette.background)+ .task {+ guard !started else { return }+ started = true+ if item.options.count == 1 && item.options[0].inputs.isEmpty { install() }+ }+ .onDisappear { values.removeAll() }+ }++ private var form: some View {+ CardForm {+ CardSection {+ VStack(alignment: .leading, spacing: 6) {+ Text(item.title).font(.title3.weight(.semibold))+ if let d = item.description { Text(d).foregroundStyle(Palette.secondary) }+ if let w = item.website, let url = URL(string: w) {+ WebLink(w, url: url).font(.footnote).lineLimit(1)+ }+ }+ .padding(.vertical, 4)+ }+ if item.options.count > 1 {+ CardSection("Runs") {+ ChoiceList(selection: $optionId, options: item.options.map { o in+ (id: o.id, label: o.kind == "remote" ? "Hosted by \(item.title)" : "On \(model.hostName) (\(o.kind))", detail: nil)+ })+ }+ }+ if let option {+ CardSection("Setup", footer: "Keys are saved on \(model.hostName) only.") {+ if option.inputs.isEmpty {+ Text(option.kind == "remote"+ ? "No keys needed here. If \(item.title) wants you to sign in, its sign-in page opens next."+ : "No setup needed.")+ .foregroundStyle(Palette.secondary)+ }+ ForEach(option.inputs) { input in+ VStack(alignment: .leading, spacing: 4) {+ Group {+ if input.secret {+ SecureField(input.name, text: binding(input))+ } else {+ TextField(input.name, text: binding(input), prompt: Text(input.default ?? input.placeholder ?? input.name))+ }+ }+ .plainTextInput()+ if let d = input.description {+ Text(d + (input.required ? "" : " (optional)")).font(.caption).foregroundStyle(Palette.secondary)+ }+ }+ }+ }+ }+ if let error {+ CardSection { Text(error).foregroundStyle(Palette.danger) }+ }+ }+ .textFieldStyle(.plain)+ .onAppear { optionId = item.options.first?.id ?? "" }+ }++ private func binding(_ input: MarketConnector.Input) -> Binding<String> {+ Binding(get: { values[input.name] ?? "" }, set: { values[input.name] = $0 })+ }++ private func install() {+ guard let option else { return }+ saving = true+ error = nil+ Task {+ do {+ guard let client = model.client else { return }+ let c: InstalledConnector+ if let installed { c = try await client.connectors().first(where: { $0.id == installed.id }) ?? installed }+ else {+ c = try await model.installConnector(item, option: option.id, inputs: values)+ installed = c+ values.removeAll()+ }+ if c.needsSignIn {+ try await ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL).signIn(c.id)+ }+ if let requestId {+ try await client.finishConnectionRequest(requestId, connectorId: c.id)+ } else {+ try await client.verifyConnector(c.id)+ }+ await model.refreshPlugins()+ done()+ dismiss()+ } catch {+ self.error = error.localizedDescription+ }+ saving = false+ }+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swiftnew file mode 100644index 00000000..006b99bf--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/InstalledView.swift@@ -0,0 +1,148 @@+import CodyncKit+import SwiftUI++struct InstalledView: View {+ let back: () -> Void+ @Environment(BotStore.self) private var model+ @Environment(\.webAuthenticationSession) private var webAuthenticationSession+ @Environment(\.openURL) private var openURL+ @State private var removing: Removal?+ @State private var signingIn: String?++ private struct Removal: Identifiable {+ let id: String+ let name: String+ let isSkill: Bool+ }++ var body: some View {+ VStack(spacing: 0) {+ ScreenHeader {+ BackButton(action: back).keyboardShortcut(.cancelAction)+ } title: {+ Text("Installed").font(.body.weight(.semibold)).foregroundStyle(Palette.text)+ } trailing: {+ EmptyView()+ }+ list+ }+ .background(Palette.background)+ }++ private var list: some View {+ CardForm {+ if model.installedConnectors.isEmpty && model.installedSkills.isEmpty {+ EmptyState(icon: "shippingbox", title: "Nothing installed", detail: "Connectors and skills you add show up here.")+ }+ if !model.installedConnectors.isEmpty {+ CardSection("Connectors") {+ ForEach(model.installedConnectors) { c in+ InstalledRow(title: c.name, subtitle: c.needsSignIn ? "Sign in so bots can use it" : c.command ?? c.url ?? c.description) {+ if c.kind == "composio" {+ AppLogo(url: c.logo, name: c.name, size: 32)+ } else {+ ServiceLogo(website: nil, name: c.name, registryName: c.registryName, size: 32)+ }+ } accessory: {+ if signingIn == c.id {+ Spinner()+ } else if c.needsSignIn {+ Button("Sign in") { signIn(c.id) }+ .buttonStyle(PrimaryButtonStyle())+ .controlSize(.small)+ }+ } remove: {+ removing = Removal(id: c.id, name: c.name, isSkill: false)+ }+ }+ }+ }+ if !model.installedSkills.isEmpty {+ CardSection("Skills") {+ ForEach(model.installedSkills) { s in+ InstalledRow(title: s.name, subtitle: s.description) {+ SkillGlyph().frame(width: 32, height: 32)+ } accessory: {+ EmptyView()+ } remove: {+ removing = Removal(id: s.id, name: s.name, isSkill: true)+ }+ }+ }+ }+ }+ .codyncDialog(+ "Remove \(removing?.name ?? "")?",+ isPresented: Binding(get: { removing != nil }, set: { if !$0 { removing = nil } }),+ message: removing.map { $0.isSkill ? "Bots stop using this skill." : "Bots lose this connector, and the keys saved for it are deleted." }+ ) {+ guard let r = removing else { return [] }+ return [DialogAction("Remove", destructive: true) {+ Task {+ do {+ if r.isSkill { try await model.removeSkill(r.id) } else { try await model.removeConnector(r.id) }+ } catch {+ model.lastError = error.localizedDescription+ }+ }+ }]+ }+ }++ private func signIn(_ id: String) {+ signingIn = id+ Task {+ do {+ try await ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL).signIn(id)+ } catch {+ model.lastError = error.localizedDescription+ }+ signingIn = nil+ }+ }+}++/// A quiet "nothing here" message (replaces `ContentUnavailableView`).+private struct EmptyState: View {+ let icon: String+ let title: String+ let detail: String++ var body: some View {+ VStack(spacing: 8) {+ Image(systemName: icon).font(.system(size: 28)).foregroundStyle(Palette.tertiary).accessibilityHidden(true)+ Text(title).font(.body.weight(.semibold)).foregroundStyle(Palette.text)+ Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).multilineTextAlignment(.center)+ }+ .frame(maxWidth: .infinity)+ .padding(.vertical, 40)+ }+}++private struct InstalledRow<Icon: View, Accessory: View>: View {+ let title: String+ let subtitle: String+ @ViewBuilder let icon: Icon+ @ViewBuilder let accessory: Accessory+ let remove: () -> Void++ var body: some View {+ HStack(spacing: 12) {+ icon+ VStack(alignment: .leading, spacing: 2) {+ Text(title).foregroundStyle(Palette.text).lineLimit(1)+ Text(subtitle).font(.caption).foregroundStyle(Palette.secondary).lineLimit(1)+ }+ Spacer(minLength: 12)+ accessory+ Button("Remove \(title)", systemImage: "trash", role: .destructive, action: remove)+ .labelStyle(.iconOnly)+ .buttonStyle(.plain)+ .foregroundStyle(Palette.secondary)+ .frame(minWidth: 44, minHeight: 44)+ .contentShape(Rectangle())+ .help("Remove")+ }+ .help(subtitle)+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketRows.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketRows.swiftnew file mode 100644index 00000000..8fa448e8--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketRows.swift@@ -0,0 +1,216 @@+import CodyncKit+import SwiftUI++struct MarketSection<Content: View>: View {+ let title: String+ @ViewBuilder let content: Content++ var body: some View {+ VStack(alignment: .leading, spacing: 12) {+ Text(title).font(.headline).foregroundStyle(Palette.text).padding(.leading, 4)+ content+ }+ }+}++/// Two columns on wide screens, one on a phone.+struct ItemGrid<Content: View>: View {+ @ViewBuilder let content: Content++ var body: some View {+ LazyVGrid(columns: [GridItem(.adaptive(minimum: 300), spacing: 10)], spacing: 4) { content }+ }+}++struct AgentCard: View {+ let backend: Backend+ let action: () -> Void+ @State private var hovering = false++ private var status: String {+ switch (backend.installed == true, backend.signedIn) {+ case (true, false?): "Not signed in"+ case (true, _): "Installed"+ case (false, _): backend.curated == true ? "Not installed" : "Sets up on first use"+ }+ }++ var body: some View {+ Button(action: action) {+ VStack(spacing: 12) {+ AgentIcon(registry: backend.registry, size: 34)+ .frame(width: 64, height: 64)+ .background(Palette.bubbleAgent, in: RoundedRectangle(cornerRadius: 18, style: .continuous))+ VStack(spacing: 2) {+ Text(backend.name).font(.subheadline.weight(.semibold)).foregroundStyle(Palette.text).lineLimit(1)+ Text(status)+ .font(.caption)+ .foregroundStyle(Palette.secondary)+ .lineLimit(1)+ }+ }+ .frame(maxWidth: .infinity)+ .padding(.vertical, 18)+ .padding(.horizontal, 10)+ .background(Palette.bubbleAgent.opacity(hovering ? 0.8 : 0.45), in: RoundedRectangle(cornerRadius: 18, style: .continuous))+ .contentShape(RoundedRectangle(cornerRadius: 18, style: .continuous))+ }+ .buttonStyle(PressScale())+ .onHover { h in withAnimation(Motion.hover) { hovering = h } }+ .help(backend.name)+ }+}++struct MarketRow<Icon: View>: View {+ let title: String+ let subtitle: String+ let added: Bool+ var busy = false+ var addLabel = "Add"+ @ViewBuilder let icon: Icon+ let add: () -> Void+ @State private var hovering = false++ var body: some View {+ HStack(spacing: 14) {+ icon.frame(width: 46, height: 46)+ VStack(alignment: .leading, spacing: 2) {+ Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text).lineLimit(1)+ Text(subtitle).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(1)+ }+ Spacer(minLength: 8)+ if busy {+ ThinkingOrb(size: 18, color: Palette.secondary).frame(width: 60)+ } else if added {+ Label("Added", systemImage: "checkmark")+ .labelStyle(.iconOnly)+ .font(.subheadline.weight(.semibold))+ .foregroundStyle(Palette.secondary)+ .frame(width: 60)+ .accessibilityLabel("Added")+ } else {+ Button(addLabel, action: add)+ .buttonStyle(.plain)+ .font(.subheadline.weight(.semibold))+ .foregroundStyle(Palette.text)+ .padding(.horizontal, 16)+ .padding(.vertical, 7)+ .background(Palette.bubbleAgent, in: Capsule())+ }+ }+ .padding(.horizontal, 12)+ .padding(.vertical, 10)+ .background(hovering ? Palette.bubbleAgent.opacity(0.6) : .clear, in: RoundedRectangle(cornerRadius: 16, style: .continuous))+ .onHover { h in withAnimation(Motion.hover) { hovering = h } }+ }+}++/// Placeholder rows while a list loads, shaped like the real ones.+struct SkeletonGrid: View {+ @State private var dim = false++ var body: some View {+ ItemGrid {+ ForEach(0..<4, id: \.self) { _ in+ HStack(spacing: 14) {+ RoundedRectangle(cornerRadius: 12, style: .continuous).frame(width: 46, height: 46)+ VStack(alignment: .leading, spacing: 8) {+ Capsule().frame(width: 120, height: 12)+ Capsule().frame(width: 190, height: 10)+ }+ Spacer()+ }+ .foregroundStyle(Palette.bubbleAgent)+ .padding(.horizontal, 12)+ .padding(.vertical, 10)+ }+ }+ .opacity(dim ? 0.5 : 1)+ .animation(.easeInOut(duration: 0.9).repeatForever(), value: dim)+ .onAppear { dim = true }+ }+}++/// A service's logo from its website favicon, on a white tile; its initial otherwise.+struct ServiceLogo: View {+ let website: String?+ let name: String+ /// MCP Registry names are reverse-DNS ("com.notion/mcp"): the owner's domain.+ var registryName: String?+ var size: CGFloat = 46++ private var domain: String? {+ if let website, let host = URL(string: website)?.host(), host != "github.com" { return host }+ guard let owner = registryName?.split(separator: "/").first else { return nil }+ let labels = owner.split(separator: ".")+ // io.github.<user> is a GitHub account, not the service's own site.+ guard labels.count >= 2, !(labels[0] == "io" && labels[1] == "github") else {+ return name.localizedCaseInsensitiveContains("github") ? "github.com" : nil+ }+ return "\(labels[1]).\(labels[0])"+ }++ private var faviconURL: URL? {+ domain.flatMap { URL(string: "https://www.google.com/s2/favicons?domain=\($0)&sz=128") }+ }++ var body: some View {+ let shape = RoundedRectangle(cornerRadius: size * 0.26, style: .continuous)+ ZStack {+ shape.fill(Palette.bubbleAgent)+ Text(name.first.map { String($0).uppercased() } ?? "?")+ .font(.system(size: size * 0.4, weight: .semibold, design: .rounded))+ .foregroundStyle(Palette.text)+ if let faviconURL {+ AsyncImage(url: faviconURL) { phase in+ if let image = phase.image {+ ZStack {+ shape.fill(.white)+ image.resizable().interpolation(.high).scaledToFit().padding(size * 0.2)+ }+ }+ }+ }+ }+ .frame(width: size, height: size)+ .clipShape(shape)+ }+}++struct TileIcon: View {+ let systemName: String++ var body: some View {+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(Palette.bubbleAgent)+ .overlay(Image(systemName: systemName).font(.system(size: 18, weight: .medium)).foregroundStyle(Palette.text))+ }+}++struct SkillGlyph: View {+ var body: some View {+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(Palette.bubbleAgent)+ .overlay(Image(systemName: "book.pages").foregroundStyle(Palette.text))+ }+}++/// Text that opens a web page (replaces the system `Link`).+struct WebLink: View {+ let title: String+ let url: URL+ @Environment(\.openURL) private var openURL++ init(_ title: String, url: URL) {+ self.title = title+ self.url = url+ }++ var body: some View {+ Button(title) { openURL(url) }+ .buttonStyle(.plain)+ .foregroundStyle(Palette.text)+ .underline()+ .help(url.absoluteString)+ }+}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplaceView.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplaceView.swiftindex 314b71f8..dd8cbeb3 100644--- a/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplaceView.swift+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/MarketplaceView.swift@@ -1,6 +1,6 @@import CodyncKitimport SwiftUI-import UIKit+/// The Marketplace (Grok Bot's layout): one page of agents, connectors and/// skills for the bots on one computer (the store in the environment). Installing happens on that/// computer; each bot turns connectors and skills on in its settings.@@ -316,1051 +316,3 @@ public struct MarketplaceView: View {}}--// MARK: - Installed--private struct InstalledView: View {- let back: () -> Void- @Environment(BotStore.self) private var model- @Environment(\.webAuthenticationSession) private var webAuthenticationSession- @Environment(\.openURL) private var openURL- @State private var removing: Removal?- @State private var signingIn: String?-- private struct Removal: Identifiable {- let id: String- let name: String- let isSkill: Bool- }-- var body: some View {- VStack(spacing: 0) {- ScreenHeader {- BackButton(action: back).keyboardShortcut(.cancelAction)- } title: {- Text("Installed").font(.body.weight(.semibold)).foregroundStyle(Palette.text)- } trailing: {- EmptyView()- }- list- }- .background(Palette.background)- }-- private var list: some View {- CardForm {- if model.installedConnectors.isEmpty && model.installedSkills.isEmpty {- EmptyState(icon: "shippingbox", title: "Nothing installed", detail: "Connectors and skills you add show up here.")- }- if !model.installedConnectors.isEmpty {- CardSection("Connectors") {- ForEach(model.installedConnectors) { c in- InstalledRow(title: c.name, subtitle: c.needsSignIn ? "Sign in so bots can use it" : c.command ?? c.url ?? c.description) {- if c.kind == "composio" {- AppLogo(url: c.logo, name: c.name, size: 32)- } else {- ServiceLogo(website: nil, name: c.name, registryName: c.registryName, size: 32)- }- } accessory: {- if signingIn == c.id {- Spinner()- } else if c.needsSignIn {- Button("Sign in") { signIn(c.id) }- .buttonStyle(PrimaryButtonStyle())- .controlSize(.small)- }- } remove: {- removing = Removal(id: c.id, name: c.name, isSkill: false)- }- }- }- }- if !model.installedSkills.isEmpty {- CardSection("Skills") {- ForEach(model.installedSkills) { s in- InstalledRow(title: s.name, subtitle: s.description) {- SkillGlyph().frame(width: 32, height: 32)- } accessory: {- EmptyView()- } remove: {- removing = Removal(id: s.id, name: s.name, isSkill: true)- }- }- }- }- }- .codyncDialog(- "Remove \(removing?.name ?? "")?",- isPresented: Binding(get: { removing != nil }, set: { if !$0 { removing = nil } }),- message: removing.map { $0.isSkill ? "Bots stop using this skill." : "Bots lose this connector, and the keys saved for it are deleted." }- ) {- guard let r = removing else { return [] }- return [DialogAction("Remove", destructive: true) {- Task {- do {- if r.isSkill { try await model.removeSkill(r.id) } else { try await model.removeConnector(r.id) }- } catch {- model.lastError = error.localizedDescription- }- }- }]- }- }-- private func signIn(_ id: String) {- signingIn = id- Task {- do {- try await ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL).signIn(id)- } catch {- model.lastError = error.localizedDescription- }- signingIn = nil- }- }-}--/// Text that opens a web page (replaces the system `Link`).-struct WebLink: View {- let title: String- let url: URL- @Environment(\.openURL) private var openURL-- init(_ title: String, url: URL) {- self.title = title- self.url = url- }-- var body: some View {- Button(title) { openURL(url) }- .buttonStyle(.plain)- .foregroundStyle(Palette.text)- .underline()- .help(url.absoluteString)- }-}--/// A quiet "nothing here" message (replaces `ContentUnavailableView`).-private struct EmptyState: View {- let icon: String- let title: String- let detail: String-- var body: some View {- VStack(spacing: 8) {- Image(systemName: icon).font(.system(size: 28)).foregroundStyle(Palette.tertiary).accessibilityHidden(true)- Text(title).font(.body.weight(.semibold)).foregroundStyle(Palette.text)- Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).multilineTextAlignment(.center)- }- .frame(maxWidth: .infinity)- .padding(.vertical, 40)- }-}--private struct InstalledRow<Icon: View, Accessory: View>: View {- let title: String- let subtitle: String- @ViewBuilder let icon: Icon- @ViewBuilder let accessory: Accessory- let remove: () -> Void-- var body: some View {- HStack(spacing: 12) {- icon- VStack(alignment: .leading, spacing: 2) {- Text(title).foregroundStyle(Palette.text).lineLimit(1)- Text(subtitle).font(.caption).foregroundStyle(Palette.secondary).lineLimit(1)- }- Spacer(minLength: 12)- accessory- Button("Remove \(title)", systemImage: "trash", role: .destructive, action: remove)- .labelStyle(.iconOnly)- .buttonStyle(.plain)- .foregroundStyle(Palette.secondary)- .frame(minWidth: 44, minHeight: 44)- .contentShape(Rectangle())- .help("Remove")- }- .help(subtitle)- }-}--// MARK: - Pieces--struct MarketSection<Content: View>: View {- let title: String- @ViewBuilder let content: Content-- var body: some View {- VStack(alignment: .leading, spacing: 12) {- Text(title).font(.headline).foregroundStyle(Palette.text).padding(.leading, 4)- content- }- }-}--/// Two columns on wide screens, one on a phone.-struct ItemGrid<Content: View>: View {- @ViewBuilder let content: Content-- var body: some View {- LazyVGrid(columns: [GridItem(.adaptive(minimum: 300), spacing: 10)], spacing: 4) { content }- }-}--private struct AgentCard: View {- let backend: Backend- let action: () -> Void- @State private var hovering = false-- private var status: String {- switch (backend.installed == true, backend.signedIn) {- case (true, false?): "Not signed in"- case (true, _): "Installed"- case (false, _): backend.curated == true ? "Not installed" : "Sets up on first use"- }- }-- var body: some View {- Button(action: action) {- VStack(spacing: 12) {- AgentIcon(registry: backend.registry, size: 34)- .frame(width: 64, height: 64)- .background(Palette.bubbleAgent, in: RoundedRectangle(cornerRadius: 18, style: .continuous))- VStack(spacing: 2) {- Text(backend.name).font(.subheadline.weight(.semibold)).foregroundStyle(Palette.text).lineLimit(1)- Text(status)- .font(.caption)- .foregroundStyle(Palette.secondary)- .lineLimit(1)- }- }- .frame(maxWidth: .infinity)- .padding(.vertical, 18)- .padding(.horizontal, 10)- .background(Palette.bubbleAgent.opacity(hovering ? 0.8 : 0.45), in: RoundedRectangle(cornerRadius: 18, style: .continuous))- .contentShape(RoundedRectangle(cornerRadius: 18, style: .continuous))- }- .buttonStyle(PressScale())- .onHover { h in withAnimation(Motion.hover) { hovering = h } }- .help(backend.name)- }-}--/// Getting an agent ready on the computer: install it, then sign in. Sign-in-/// options come from the agent itself (ACP), plus Codync's own command for-/// CLIs it knows. Bots are made from New chat, not here.-private struct AgentSheet: View {- let initial: Backend- @Environment(BotStore.self) private var model- @State private var route: SetupRoute?- @State private var auth: AgentAuth?- @State private var checking = false- @State private var authenticating: String?- @State private var error: String?-- /// Live: an install or sign-in updates the host's list.- private var backend: Backend { model.hello?.backends.first { $0.id == initial.id } ?? initial }- private var installed: Bool { backend.installed == true }- private var curated: Bool { backend.curated == true }- private var signedIn: Bool? { auth?.signedIn ?? backend.signedIn }-- var body: some View {- ZStack {- if let route {- routed(route).transition(.move(edge: .trailing).combined(with: .opacity))- } else {- VStack(spacing: 0) {- ModalHeader(backend.name)- overview- }- .transition(.move(edge: .leading).combined(with: .opacity))- }- }- .frame(minWidth: 0, minHeight: 0)- // A known "signed in" needs no agent start; everything else asks the agent.- .task { if backend.signedIn != true { await check() } }- .onChange(of: route) { old, new in- // Back from a terminal or key form: see what changed.- if new == nil, old != nil { Task { await check() } }- }- }-- @ViewBuilder private func routed(_ route: SetupRoute) -> some View {- let back = { withAnimation(Motion.layout) { self.route = nil } }- switch route {- case .install: SetupTerminalView(backend: backend, step: .install, back: back)- case .terminal(let method): SetupTerminalView(backend: backend, step: .login, method: method, back: back)- case .keys(let method): AgentKeysForm(backend: backend, method: method, saved: auth?.savedEnv ?? [], back: back) { auth = $0 }- }- }-- private func go(_ route: SetupRoute) {- withAnimation(Motion.layout) { self.route = route }- }-- private var overview: some View {- CardForm {- CardSection {- HStack(spacing: 14) {- AgentIcon(registry: backend.registry, size: 30)- .frame(width: 52, height: 52)- .background(Palette.bubbleAgent, in: RoundedRectangle(cornerRadius: 14, style: .continuous))- VStack(alignment: .leading, spacing: 2) {- Text(backend.name).font(.title3.weight(.semibold))- if let d = backend.description, !d.isEmpty {- Text(d).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(3)- }- }- }- .padding(.vertical, 4)- }- if curated {- CardSection {- SetupStepRow(- number: 1,- title: "Install",- detail: installed- ? "Installed on \(model.hostName)."- : backend.canInstall == true ? "Runs the official installer on \(model.hostName)." : backend.installHint,- done: installed,- action: installed || backend.canInstall != true ? nil : ("Install", { go(.install) })- )- }- }- signInSection- if let error {- CardSection { Text(error).foregroundStyle(Palette.danger).textSelection(.enabled) }- }- }- }-- private var signInSection: some View {- CardSection(footer: signedIn != true && auth?.methods.contains(where: { $0.kind == .agent }) == true- ? "Browser sign-ins open on \(model.hostName) itself. Away from it? Use Remote screen to finish there."- : nil) {- HStack(spacing: 0) {- SetupStepRow(number: curated ? 2 : 1, title: "Sign in", detail: statusText, done: signedIn == true, action: nil)- if checking {- ThinkingOrb(state: .connecting, size: 16, color: Palette.secondary)- } else {- Button("Check again", systemImage: "arrow.clockwise") { Task { await check() } }- .labelStyle(.iconOnly)- .buttonStyle(.plain)- .foregroundStyle(Palette.secondary)- .help("Check again")- }- }- if signedIn != true, let detail = auth?.detail, !detail.isEmpty {- Text(detail).font(.footnote).foregroundStyle(Palette.secondary).textSelection(.enabled)- }- // Some CLIs drop the current sign-in the moment a new one starts: no options once signed in.- if signedIn != true, !checking {- if auth?.login == true {- optionRow("Sign in", detail: "In a terminal on \(model.hostName). Links open here.", icon: "terminal") {- go(.terminal(nil))- }- }- ForEach(auth?.methods ?? []) { m in- switch m.kind {- case .terminal?:- optionRow(m.name, detail: m.description ?? "In a terminal on \(model.hostName).", icon: "terminal") {- go(.terminal(m))- }- case .envVar?:- optionRow(m.name, detail: m.description ?? "Saved on \(model.hostName) only.", icon: "key") {- go(.keys(m))- }- case .agent?, nil:- optionRow(- m.name,- detail: authenticating == m.id- ? "Finish signing in in the browser on \(model.hostName)…"- : m.description ?? "Opens a browser on \(model.hostName).",- icon: "safari",- busy: authenticating == m.id- ) {- Task { await authenticate(m) }- }- }- }- }- }- }-- private var statusText: String {- if checking { return auth == nil ? "Checking with \(backend.name)… The first check can download it." : "Checking…" }- switch signedIn {- case true?: return "Signed in."- case false?: return "Not signed in yet."- case nil: return "Couldn't tell. Skip this if you've already signed in on \(model.hostName)."- }- }-- private func optionRow(_ title: String, detail: String, icon: String, busy: Bool = false, action: @escaping () -> Void) -> some View {- Button(action: action) {- HStack(spacing: 12) {- Image(systemName: icon)- .font(.body)- .foregroundStyle(Palette.secondary)- .frame(width: 26)- .accessibilityHidden(true)- VStack(alignment: .leading, spacing: 2) {- Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text)- Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(3)- }- Spacer(minLength: 8)- if busy {- ThinkingOrb(size: 16, color: Palette.secondary)- } else {- Image(systemName: "chevron.right").font(.caption.weight(.semibold)).foregroundStyle(Palette.tertiary)- }- }- .contentShape(Rectangle())- }- .buttonStyle(.plain)- .disabled(authenticating != nil)- }-- private func check() async {- guard let client = model.client, !checking else { return }- checking = true- defer { checking = false }- do {- auth = try await client.agentAuth(backend.id)- error = nil- } catch {- self.error = error.localizedDescription- }- await model.refreshBackends()- }-- private func authenticate(_ m: AuthMethod) async {- guard let client = model.client else { return }- authenticating = m.id- defer { authenticating = nil }- do {- auth = try await client.agentAuthenticate(backend.id, method: m.id)- error = nil- } catch {- self.error = error.localizedDescription- }- await model.refreshBackends()- }-}--private enum SetupRoute: Hashable {- case install- case terminal(AuthMethod?)- case keys(AuthMethod)-}--/// Keys an agent reads from its environment, kept on the computer.-private struct AgentKeysForm: View {- let backend: Backend- let method: AuthMethod- let saved: [String]- let back: () -> Void- let done: (AgentAuth) -> Void- @Environment(BotStore.self) private var model- @State private var values: [String: String] = [:]- @State private var saving = false- @State private var error: String?-- private var vars: [AuthMethod.Var] { method.vars ?? [] }-- var body: some View {- VStack(spacing: 0) {- ScreenHeader {- BackButton(action: back).keyboardShortcut(.cancelAction)- } title: {- Text(method.name).font(.body.weight(.semibold)).foregroundStyle(Palette.text).lineLimit(1)- } trailing: {- if saving {- Spinner()- } else {- IconButton("Save", systemImage: "checkmark") { save(values.filter { !$0.value.isEmpty }) }- .disabled(vars.contains { !$0.optional && (values[$0.name] ?? "").isEmpty && !saved.contains($0.name) })- }- }- form- }- .background(Palette.background)- }-- private var form: some View {- CardForm {- VStack(alignment: .leading, spacing: 6) {- CardSection(method.name) {- ForEach(vars, id: \.name) { v in- VStack(alignment: .leading, spacing: 4) {- let prompt = Text(saved.contains(v.name) ? "Saved (type to replace)" : v.name)- Group {- if v.secret {- SecureField(v.label, text: binding(v.name), prompt: prompt)- } else {- TextField(v.label, text: binding(v.name), prompt: prompt)- }- }- .plainTextInput()- Text(v.label + (v.optional ? " (optional)" : "")).font(.caption).foregroundStyle(Palette.secondary)- }- }- }- VStack(alignment: .leading, spacing: 6) {- if let d = method.description { Text(d) }- Text("Saved on \(model.hostName) only and given to \(backend.name) when it starts.")- if let link = method.link, let url = URL(string: link) {- WebLink("Get a key", url: url)- }- }- .font(.caption)- .foregroundStyle(Palette.tertiary)- .padding(.horizontal, 4)- }- if !saved.isEmpty {- CardSection {- Button("Remove saved keys", role: .destructive) {- save(Dictionary(uniqueKeysWithValues: vars.map { ($0.name, "") }))- }- .buttonStyle(.plain)- .foregroundStyle(Palette.danger)- }- }- if let error {- CardSection { Text(error).foregroundStyle(Palette.danger) }- }- }- .textFieldStyle(.plain)- }-- private func binding(_ name: String) -> Binding<String> {- Binding(get: { values[name] ?? "" }, set: { values[name] = $0 })- }-- private func save(_ vars: [String: String]) {- guard let client = model.client else { return }- saving = true- Task {- defer { saving = false }- do {- done(try await client.setAgentEnv(backend.id, vars: vars))- back()- } catch {- self.error = error.localizedDescription- }- }- }-}--private struct SetupStepRow: View {- let number: Int- let title: String- let detail: String- let done: Bool- let action: (label: String, run: () -> Void)?-- var body: some View {- HStack(spacing: 12) {- ZStack {- Circle().fill(done ? Palette.accentFill : Palette.bubbleAgent)- if done {- Image(systemName: "checkmark").font(.caption.weight(.bold)).foregroundStyle(Palette.onAccent)- } else {- Text("\(number)").font(.caption.weight(.semibold)).foregroundStyle(Palette.secondary)- }- }- .frame(width: 26, height: 26)- .accessibilityHidden(true)- VStack(alignment: .leading, spacing: 2) {- Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text)- Text(detail).font(.subheadline).foregroundStyle(Palette.secondary).textSelection(.enabled)- }- Spacer(minLength: 8)- if let action {- Button(action.label, action: action.run)- .buttonStyle(.plain)- .font(.subheadline.weight(.semibold))- .foregroundStyle(Palette.text)- .padding(.horizontal, 14)- .padding(.vertical, 7)- .background(Palette.bubbleAgent, in: Capsule())- .fixedSize()- }- }- .padding(.vertical, 4)- .accessibilityElement(children: .combine)- .accessibilityValue(done ? "Done" : "")- }-}--struct MarketRow<Icon: View>: View {- let title: String- let subtitle: String- let added: Bool- var busy = false- var addLabel = "Add"- @ViewBuilder let icon: Icon- let add: () -> Void- @State private var hovering = false-- var body: some View {- HStack(spacing: 14) {- icon.frame(width: 46, height: 46)- VStack(alignment: .leading, spacing: 2) {- Text(title).font(.body.weight(.medium)).foregroundStyle(Palette.text).lineLimit(1)- Text(subtitle).font(.subheadline).foregroundStyle(Palette.secondary).lineLimit(1)- }- Spacer(minLength: 8)- if busy {- ThinkingOrb(size: 18, color: Palette.secondary).frame(width: 60)- } else if added {- Label("Added", systemImage: "checkmark")- .labelStyle(.iconOnly)- .font(.subheadline.weight(.semibold))- .foregroundStyle(Palette.secondary)- .frame(width: 60)- .accessibilityLabel("Added")- } else {- Button(addLabel, action: add)- .buttonStyle(.plain)- .font(.subheadline.weight(.semibold))- .foregroundStyle(Palette.text)- .padding(.horizontal, 16)- .padding(.vertical, 7)- .background(Palette.bubbleAgent, in: Capsule())- }- }- .padding(.horizontal, 12)- .padding(.vertical, 10)- .background(hovering ? Palette.bubbleAgent.opacity(0.6) : .clear, in: RoundedRectangle(cornerRadius: 16, style: .continuous))- .onHover { h in withAnimation(Motion.hover) { hovering = h } }- }-}--/// Placeholder rows while a list loads, shaped like the real ones.-struct SkeletonGrid: View {- @State private var dim = false-- var body: some View {- ItemGrid {- ForEach(0..<4, id: \.self) { _ in- HStack(spacing: 14) {- RoundedRectangle(cornerRadius: 12, style: .continuous).frame(width: 46, height: 46)- VStack(alignment: .leading, spacing: 8) {- Capsule().frame(width: 120, height: 12)- Capsule().frame(width: 190, height: 10)- }- Spacer()- }- .foregroundStyle(Palette.bubbleAgent)- .padding(.horizontal, 12)- .padding(.vertical, 10)- }- }- .opacity(dim ? 0.5 : 1)- .animation(.easeInOut(duration: 0.9).repeatForever(), value: dim)- .onAppear { dim = true }- }-}--/// A service's logo from its website favicon, on a white tile; its initial otherwise.-private struct ServiceLogo: View {- let website: String?- let name: String- /// MCP Registry names are reverse-DNS ("com.notion/mcp"): the owner's domain.- var registryName: String?- var size: CGFloat = 46-- private var domain: String? {- if let website, let host = URL(string: website)?.host(), host != "github.com" { return host }- guard let owner = registryName?.split(separator: "/").first else { return nil }- let labels = owner.split(separator: ".")- // io.github.<user> is a GitHub account, not the service's own site.- guard labels.count >= 2, !(labels[0] == "io" && labels[1] == "github") else {- return name.localizedCaseInsensitiveContains("github") ? "github.com" : nil- }- return "\(labels[1]).\(labels[0])"- }-- private var faviconURL: URL? {- domain.flatMap { URL(string: "https://www.google.com/s2/favicons?domain=\($0)&sz=128") }- }-- var body: some View {- let shape = RoundedRectangle(cornerRadius: size * 0.26, style: .continuous)- ZStack {- shape.fill(Palette.bubbleAgent)- Text(name.first.map { String($0).uppercased() } ?? "?")- .font(.system(size: size * 0.4, weight: .semibold, design: .rounded))- .foregroundStyle(Palette.text)- if let faviconURL {- AsyncImage(url: faviconURL) { phase in- if let image = phase.image {- ZStack {- shape.fill(.white)- image.resizable().interpolation(.high).scaledToFit().padding(size * 0.2)- }- }- }- }- }- .frame(width: size, height: size)- .clipShape(shape)- }-}--struct TileIcon: View {- let systemName: String-- var body: some View {- RoundedRectangle(cornerRadius: 12, style: .continuous)- .fill(Palette.bubbleAgent)- .overlay(Image(systemName: systemName).font(.system(size: 18, weight: .medium)).foregroundStyle(Palette.text))- }-}--struct InstallConnectorSheet: View {- let item: MarketConnector- var requestId: String? = nil- let done: () -> Void- @Environment(BotStore.self) private var model- @Environment(\.dismissModal) private var dismiss- @Environment(\.webAuthenticationSession) private var webAuthenticationSession- @Environment(\.openURL) private var openURL- @State private var optionId = ""- @State private var values: [String: String] = [:]- @State private var installed: InstalledConnector?- @State private var started = false- @State private var saving = false- @State private var error: String?-- private var option: MarketConnector.InstallOption? {- item.options.first { $0.id == optionId } ?? item.options.first- }-- var body: some View {- VStack(spacing: 0) {- ModalHeader("Add connector") {- if saving {- Spinner()- } else {- IconButton("Add", systemImage: "plus") { install() }- .disabled(installed == nil && (option?.inputs.contains { $0.required && (values[$0.name] ?? $0.default ?? "").isEmpty } ?? true))- }- }- form- }- .background(Palette.background)- .task {- guard !started else { return }- started = true- if item.options.count == 1 && item.options[0].inputs.isEmpty { install() }- }- .onDisappear { values.removeAll() }- }-- private var form: some View {- CardForm {- CardSection {- VStack(alignment: .leading, spacing: 6) {- Text(item.title).font(.title3.weight(.semibold))- if let d = item.description { Text(d).foregroundStyle(Palette.secondary) }- if let w = item.website, let url = URL(string: w) {- WebLink(w, url: url).font(.footnote).lineLimit(1)- }- }- .padding(.vertical, 4)- }- if item.options.count > 1 {- CardSection("Runs") {- ChoiceList(selection: $optionId, options: item.options.map { o in- (id: o.id, label: o.kind == "remote" ? "Hosted by \(item.title)" : "On \(model.hostName) (\(o.kind))", detail: nil)- })- }- }- if let option {- CardSection("Setup", footer: "Keys are saved on \(model.hostName) only.") {- if option.inputs.isEmpty {- Text(option.kind == "remote"- ? "No keys needed here. If \(item.title) wants you to sign in, its sign-in page opens next."- : "No setup needed.")- .foregroundStyle(Palette.secondary)- }- ForEach(option.inputs) { input in- VStack(alignment: .leading, spacing: 4) {- Group {- if input.secret {- SecureField(input.name, text: binding(input))- } else {- TextField(input.name, text: binding(input), prompt: Text(input.default ?? input.placeholder ?? input.name))- }- }- .plainTextInput()- if let d = input.description {- Text(d + (input.required ? "" : " (optional)")).font(.caption).foregroundStyle(Palette.secondary)- }- }- }- }- }- if let error {- CardSection { Text(error).foregroundStyle(Palette.danger) }- }- }- .textFieldStyle(.plain)- .onAppear { optionId = item.options.first?.id ?? "" }- }-- private func binding(_ input: MarketConnector.Input) -> Binding<String> {- Binding(get: { values[input.name] ?? "" }, set: { values[input.name] = $0 })- }-- private func install() {- guard let option else { return }- saving = true- error = nil- Task {- do {- guard let client = model.client else { return }- let c: InstalledConnector- if let installed { c = try await client.connectors().first(where: { $0.id == installed.id }) ?? installed }- else {- c = try await model.installConnector(item, option: option.id, inputs: values)- installed = c- values.removeAll()- }- if c.needsSignIn {- try await ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL).signIn(c.id)- }- if let requestId {- try await client.finishConnectionRequest(requestId, connectorId: c.id)- } else {- try await client.verifyConnector(c.id)- }- await model.refreshPlugins()- done()- dismiss()- } catch {- self.error = error.localizedDescription- }- saving = false- }- }-}--private struct CustomConnectorSheet: View {- private enum Mode: Hashable { case command, url, config }-- @Environment(BotStore.self) private var model- @Environment(\.dismissModal) private var dismiss- @Environment(\.webAuthenticationSession) private var webAuthenticationSession- @Environment(\.openURL) private var openURL- @State private var name = ""- @State private var mode = Mode.command- @State private var target = ""- @State private var envText = ""- @State private var config = ""- @State private var saving = false- @State private var error: String?-- private var ready: Bool {- mode == .config- ? !config.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty- : !name.trimmingCharacters(in: .whitespaces).isEmpty && !target.trimmingCharacters(in: .whitespaces).isEmpty- }-- var body: some View {- VStack(spacing: 0) {- ModalHeader("Custom connector") {- if saving {- Spinner()- } else {- IconButton("Add", systemImage: "plus") { save() }- .disabled(!ready)- }- }- form- }- .background(Palette.background)- }-- private var footer: String {- switch mode {- case .command: "Runs on \(model.hostName) in the bot's project folder. Quotes work like in a shell."- case .url: "A remote MCP server, streamable HTTP or SSE."- case .config: "Paste the MCP config from a README or another app (Claude, Cursor, VS Code). Every server in it is added. Saved on \(model.hostName) only."- }- }-- private var form: some View {- CardForm {- CardSection(footer: footer) {- SegmentedChoice(selection: $mode, options: [(id: .command, label: "Command"), (id: .url, label: "URL"), (id: .config, label: "Config")])- if mode == .config {- TextField("{ \"mcpServers\": { … } }", text: $config, axis: .vertical)- .lineLimit(6...16)- .font(.callout.monospaced())- .plainTextInput()- } else {- TextField("Name", text: $name)- TextField(mode == .url ? "https://example.com/mcp" : "npx -y @scope/server", text: $target)- .font(.callout.monospaced())- .plainTextInput()- }- }- if mode == .url {- CardSection("Headers", footer: "Optional, one Name: value per line. Leave empty if the service has you sign in. Saved on \(model.hostName) only.") {- TextField("Authorization: Bearer …", text: $envText, axis: .vertical)- .lineLimit(2...6)- .font(.callout.monospaced())- .plainTextInput()- }- } else if mode == .command {- CardSection("Environment", footer: "One KEY=value per line. Saved on \(model.hostName) only.") {- TextField("API_KEY=…", text: $envText, axis: .vertical)- .lineLimit(2...6)- .font(.callout.monospaced())- .plainTextInput()- }- }- if let error {- CardSection { Text(error).foregroundStyle(Palette.danger) }- }- }- .textFieldStyle(.plain)- .animation(Motion.layout, value: mode)- }-- private func save() {- saving = true- error = nil- let remote = mode == .url- var pairs: [String: String] = [:]- for line in envText.split(separator: "\n") {- let parts = line.split(separator: remote ? ":" : "=", maxSplits: 1).map { $0.trimmingCharacters(in: .whitespaces) }- if parts.count == 2, !parts[0].isEmpty { pairs[parts[0]] = parts[1] }- }- Task {- do {- let added = mode == .config- ? try await model.importConnectors(config: config)- : [try await model.addConnector(- name: name, command: remote ? nil : target, url: remote ? target : nil,- env: remote ? [:] : pairs, headers: remote ? pairs : [:]- )]- let signIn = ConnectorSignInFlow(model: model, webAuthenticationSession: webAuthenticationSession, openURL: openURL)- for c in added where c.needsSignIn {- try await signIn.signIn(c.id)- }- dismiss()- } catch {- self.error = error.localizedDescription- }- saving = false- }- }-}--private struct NewSkillSheet: View {- @Environment(BotStore.self) private var model- @Environment(\.dismissModal) private var dismiss- @State private var name = ""- @State private var summary = ""- @State private var instructions = ""- @State private var saving = false- @State private var error: String?-- var body: some View {- VStack(spacing: 0) {- ModalHeader("New skill") {- if saving {- Spinner()- } else {- IconButton("Save", systemImage: "checkmark") {- saving = true- Task {- do {- try await model.addSkill(name: name, description: summary, instructions: instructions)- dismiss()- } catch {- self.error = error.localizedDescription- }- saving = false- }- }- .disabled(name.trimmingCharacters(in: .whitespaces).isEmpty || instructions.trimmingCharacters(in: .whitespaces).isEmpty)- }- }- form- }- .background(Palette.background)- }-- private var form: some View {- CardForm {- CardSection(footer: "The bot sees the name and when to use it, and reads the instructions only when a task fits.") {- TextField("Name", text: $name)- TextField("When to use it", text: $summary, axis: .vertical).lineLimit(2...4)- }- CardSection("Instructions") {- TextField("Step by step, in plain words…", text: $instructions, axis: .vertical)- .lineLimit(6...20)- }- if let error {- CardSection { Text(error).foregroundStyle(Palette.danger) }- }- }- .textFieldStyle(.plain)- }-}--private struct SkillGlyph: View {- var body: some View {- RoundedRectangle(cornerRadius: 12, style: .continuous)- .fill(Palette.bubbleAgent)- .overlay(Image(systemName: "book.pages").foregroundStyle(Palette.text))- }-}--/// A coding agent's logo from the ACP registry, tinted like text; a terminal glyph otherwise.-public struct AgentIcon: View {- let registry: String?- let size: CGFloat-- public init(registry: String?, size: CGFloat = 20) {- self.registry = registry- self.size = size- }-- public var body: some View {- Group {- if let name = registry.map({ "agent-\($0)" }), Self.exists(name) {- Image(name, bundle: .module).resizable().scaledToFit()- } else {- Image(systemName: "terminal").resizable().scaledToFit().padding(size * 0.1)- }- }- .frame(width: size, height: size)- .foregroundStyle(tint)- }-- /// Registry logos are one-color; paint the ones with a known brand color in it.- private var tint: AnyShapeStyle {- switch registry {- case "claude-acp": AnyShapeStyle(Color(red: 0.85, green: 0.47, blue: 0.34))- case "gemini": AnyShapeStyle(LinearGradient(colors: [Color(red: 0.28, green: 0.59, blue: 0.89), Color(red: 0.57, green: 0.47, blue: 0.78), Color(red: 0.79, green: 0.40, blue: 0.45)], startPoint: .bottomLeading, endPoint: .topTrailing))- case "antigravity-acp": AnyShapeStyle(Color(red: 0.26, green: 0.52, blue: 0.96))- case "mistral-vibe": AnyShapeStyle(Color(red: 0.98, green: 0.32, blue: 0.06))- case "qwen-code": AnyShapeStyle(Color(red: 0.38, green: 0.36, blue: 0.93))- case "amp-acp": AnyShapeStyle(Color(red: 0.95, green: 0.31, blue: 0.25))- case "kiro": AnyShapeStyle(Color(red: 0.56, green: 0.27, blue: 1.0))- case "cortex-code": AnyShapeStyle(Color(red: 0.16, green: 0.71, blue: 0.91))- default: AnyShapeStyle(Palette.text)- }- }-- private static func exists(_ name: String) -> Bool {- UIImage(named: name, in: .module, with: nil) != nil- }-}diff --git a/apps/ios/Kit/Sources/CodyncUI/Marketplace/NewSkillSheet.swift b/apps/ios/Kit/Sources/CodyncUI/Marketplace/NewSkillSheet.swiftnew file mode 100644index 00000000..f747be71--- /dev/null+++ b/apps/ios/Kit/Sources/CodyncUI/Marketplace/NewSkillSheet.swift@@ -0,0 +1,55 @@+import CodyncKit+import SwiftUI++struct NewSkillSheet: View {+ @Environment(BotStore.self) private var model+ @Environment(\.dismissModal) private var dismiss+ @State private var name = ""+ @State private var summary = ""+ @State private var instructions = ""+ @State private var saving = false+ @State private var error: String?++ var body: some View {+ VStack(spacing: 0) {+ ModalHeader("New skill") {+ if saving {+ Spinner()+ } else {+ IconButton("Save", systemImage: "checkmark") {+ saving = true+ Task {+ do {+ try await model.addSkill(name: name, description: summary, instructions: instructions)+ dismiss()+ } catch {+ self.error = error.localizedDescription+ }+ saving = false+ }+ }+ .disabled(name.trimmingCharacters(in: .whitespaces).isEmpty || instructions.trimmingCharacters(in: .whitespaces).isEmpty)+ }+ }+ form+ }+ .background(Palette.background)+ }++ private var form: some View {+ CardForm {+ CardSection(footer: "The bot sees the name and when to use it, and reads the instructions only when a task fits.") {+ TextField("Name", text: $name)+ TextField("When to use it", text: $summary, axis: .vertical).lineLimit(2...4)+ }+ CardSection("Instructions") {+ TextField("Step by step, in plain words…", text: $instructions, axis: .vertical)+ .lineLimit(6...20)+ }+ if let error {+ CardSection { Text(error).foregroundStyle(Palette.danger) }+ }+ }+ .textFieldStyle(.plain)+ }+}