// AN AGENT IN A CHAT ON IPHONE (chat CONTRACT.md "An agent in a chat", "The iPhone's half"; the core in 34001566a5).// A person's connected assistant may join a Cotton group as an agent: Add an agent on the group's page (the core's// `chat.agent.choices`, or the line that says to connect one), the agents in the group's own list with Remove where// the core allows it, and an agent's words drawn on the left with the agent's square mark, its name and whose agent// it is. The feed, the acts and the done report are the core's; the phone only draws and asks.#if os(iOS)importCottonKitimportSwiftUIenumChatAgentMethod {/// `{ thread }` → `{ agents: [{ agent, name, in }], connect, line }`.staticlet choices = "chat.agent.choices"/// `{ thread, agent }` → `{ ok }`.staticlet add = "chat.agent.add"/// `{ thread, agent }` → `{ ok }`.staticlet remove = "chat.agent.remove"}/// `chat.agent.choices`: his connected assistants, each saying whether it is in the chat; `connect` with the line that/// says to connect one first.structChatAgentChoices: Decodable, Equatable, Sendable {structAgent: Decodable, Equatable, Sendable, Identifiable {var agent: Stringvar name: Stringvar `in`: Boolvar id: String { agent } }var agents: [Agent]var connect: Boolvar line: String?}/// The agent mark: its name's first letter on the ink's rounded square, so an agent is never read as a person.structChatAgentMark: View {let name: Stringlet side: CGFloat @Environment(\.chatLook) privatevar lookvar body: someView {Text(verbatim: String(name.prefix(1)).uppercased()) .font(.system(size: side * 0.42, weight: .bold)) .foregroundStyle(look.colours.ground) .frame(width: side, height: side) .background(RoundedRectangle(cornerRadius: side * 0.28, style: .continuous).fill(look.colours.text)) .accessibilityHidden(true) }}/// Add an agent: his assistants, one tap adding it (one already in says so), or the line to connect one first.structChatAgentChoicesSheet: View {let choices: ChatAgentChoiceslet add: (String) -> Void @Environment(\.chatLook) privatevar lookvar body: someView { VStack(alignment: .leading, spacing: 0) {if choices.connect, let line = choices.line {Text(verbatim: line).font(look.font(15)).foregroundStyle(look.colours.dim) .fixedSize(horizontal: false, vertical: true) .padding(.vertical, 10) .accessibilityIdentifier("chat-group-agent-connect") }ForEach(choices.agents) { agent inif agent.in { HStack(spacing: 12) {ChatAgentMark(name: agent.name, side: 36 * min(look.scale, 1.3))Text(verbatim: agent.name).font(look.font(16)).foregroundStyle(look.colours.text)Spacer(minLength: 8)Text(verbatim: ChatWords.line("group.agent_in")).font(look.font(13)).foregroundStyle(look.colours.dim) } .frame(minHeight: 52) .accessibilityElement(children: .combine) .accessibilityIdentifier("chat-group-agent-choice-\(agent.agent)") } else {Button { add(agent.agent) } label: { HStack(spacing: 12) {ChatAgentMark(name: agent.name, side: 36 * min(look.scale, 1.3))Text(verbatim: agent.name).font(look.font(16)).foregroundStyle(look.colours.text)Spacer(minLength: 8)Image(systemName: "plus").font(.system(size: 15, weight: .semibold)).foregroundStyle(look.colours.accent) .accessibilityHidden(true) } .frame(minHeight: 52) .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityElement(children: .combine) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("chat-group-agent-choice-\(agent.agent)") } } } .padding(.horizontal, Warm.side) .padding(.bottom, 12) .accessibilityElement(children: .contain) .accessibilityIdentifier("chat-group-agent-choices") }}#endif