diff --git a/Bighelp/App/RootHome.swift b/Bighelp/App/RootHome.swift index d54f5fc4..66bfc41d 100644 --- a/Bighelp/App/RootHome.swift +++ b/Bighelp/App/RootHome.swift @@ -261,6 +261,7 @@ extension RootShellView { onProfile: { appState.open(.simpleBotProfile(agentID: id)) }, onSwitchAgent: {}, onAsk: { askSimpleBot(id, $0, fillsBlanks: false) }, onSend: { askSimpleBot(id, $0, fillsBlanks: false, sendsAtOnce: true) }, + onAskNewChat: { startNewChat(withBot: id, text: $0) }, onBlueprint: { askSimpleBot(id, $0, fillsBlanks: true) }) }, shellBoardKey: { agentBoardClientKey }, diff --git a/Bighelp/App/RootNewChat.swift b/Bighelp/App/RootNewChat.swift index 51be025a..e78b491d 100644 --- a/Bighelp/App/RootNewChat.swift +++ b/Bighelp/App/RootNewChat.swift @@ -13,6 +13,14 @@ extension RootShellView { startNewChat(explicitAgentID: nil, tracksNewChat: true) } + /// A new chat with this bot, the text in its message box to add notes before sending: an + /// idea that was said Let's do it to starts a job of its own, not a turn in the bot's chat. + func startNewChat(withBot agentID: String, text: String) { + appState.leaveComposerText(text) + newChatSession.start() + startNewChat(explicitAgentID: agentID, tracksNewChat: true) + } + /// New chat's parts for its own blank chat, and nil for every other chat. Decided from the /// chat's id, never from its messages: the chat stops drawing them once something is sent. func newChatSlot(forChat id: String, model: ChatModel) -> ChatNewChatSlot? { diff --git a/Bighelp/App/RootSimpleBots.swift b/Bighelp/App/RootSimpleBots.swift index d4b1d11c..12b8c629 100644 --- a/Bighelp/App/RootSimpleBots.swift +++ b/Bighelp/App/RootSimpleBots.swift @@ -320,6 +320,7 @@ extension RootShellView { configureShellBoard: { await configureAgentBoard($0) }, onAsk: { id, text in askSimpleBot(id, text, fillsBlanks: false) }, onSend: { id, text in askSimpleBot(id, text, fillsBlanks: false, sendsAtOnce: true) }, + onAskNewChat: { id, text in startNewChat(withBot: id, text: text) }, onBlueprint: { id, text in askSimpleBot(id, text, fillsBlanks: true) }), editUnavailableReason: editReason, makeEditor: { profile in diff --git a/Bighelp/Board/AgentBoardViews.swift b/Bighelp/Board/AgentBoardViews.swift index 3f4de157..2ec7e18f 100644 --- a/Bighelp/Board/AgentBoardViews.swift +++ b/Bighelp/Board/AgentBoardViews.swift @@ -13,8 +13,11 @@ struct AgentBoardContext { let onSwitchAgent: () -> Void /// Opens a chat with this agent with the text in its message box. let onAsk: (String) -> Void - /// Opens a chat with this agent and sends the text there (Let's do it). + /// Opens a chat with this agent and sends the text there (Do it on a post). let onSend: (String) -> Void + /// Opens a NEW chat with this agent, the text in its message box to add to before sending + /// (Let's do it on an idea: an idea started is a job of its own). Nil asks in the bot's chat. + var onAskNewChat: ((String) -> Void)? = nil /// Opens a chat with this agent with a blueprint in its message box, its blanks as chips. let onBlueprint: (String) -> Void /// Opens this agent's chat, from New chat on a board in a sheet. @@ -1161,15 +1164,16 @@ private struct IdeaHeroTile: View { .accessibilityIdentifier("board.idea.lets-do-it.\(idea.id)") } - /// As on the idea's page: the yes is recorded by the idea's ID, and the chat that opens gets - /// only the readable text. Older plugins go straight to the chat. + /// As on the idea's page: the yes is recorded by the idea's ID, and a new chat opens with + /// only the readable text in its message box, so notes can be added before it is sent. + /// Older plugins go straight to the chat. private func letsDoIt() async { isAccepting = true let outcome = await context.store.accept(idea) isAccepting = false guard outcome != .failed else { acceptFailed = true; return } acceptFailed = false - context.onSend(idea.letsDoItMessage) + (context.onAskNewChat ?? context.onAsk)(idea.letsDoItMessage) } } @@ -1343,15 +1347,16 @@ struct IdeaDetailSheet: View { } } - /// The yes is recorded when the person taps, by the idea's ID; then "Let's do it!" goes to - /// the chat with the idea as a card. Older plugins skip straight to the chat, as before. + /// The yes is recorded when the person taps, by the idea's ID; then a new chat opens with + /// "Let's do it!" and the idea as a card in its message box, to add notes before sending. + /// Older plugins skip straight to the chat, as before. private func letsDoIt() async { isAccepting = true let outcome = await context.store.accept(idea) isAccepting = false guard outcome != .failed else { acceptFailed = true; return } dismiss() - context.onSend(idea.letsDoItMessage) + (context.onAskNewChat ?? context.onAsk)(idea.letsDoItMessage) } @BighelpThemeReader private var theme diff --git a/Bighelp/SimpleBots/SimpleBotProfileView.swift b/Bighelp/SimpleBots/SimpleBotProfileView.swift index 20ba9540..61350b4d 100644 --- a/Bighelp/SimpleBots/SimpleBotProfileView.swift +++ b/Bighelp/SimpleBots/SimpleBotProfileView.swift @@ -87,8 +87,10 @@ struct SimpleBotDashboardHooks { let configureShellBoard: @MainActor (RootShellView.AgentBoardClientKey) async -> Void /// Opens the bot's chat with the text in its message box (bot ID, text); nothing is sent. let onAsk: (String, String) -> Void - /// Opens the bot's chat and sends the text there (Let's do it). + /// Opens the bot's chat and sends the text there (Do it on a post). let onSend: (String, String) -> Void + /// Opens a new chat with the bot, the text in its message box (Let's do it on an idea). + var onAskNewChat: ((String, String) -> Void)? = nil /// Opens the bot's chat with a blueprint in its message box, its blanks as chips. let onBlueprint: (String, String) -> Void } @@ -1271,7 +1273,9 @@ struct SimpleBotProfileView: View { agentID: id, agentName: profile.name, imageURL: context.agents.avatarURL(for: profile), activity: .idle, store: store, onProfile: {}, onSwitchAgent: {}, - onAsk: { hooks.onAsk(id, $0) }, onSend: { hooks.onSend(id, $0) }, onBlueprint: { hooks.onBlueprint(id, $0) }, + onAsk: { hooks.onAsk(id, $0) }, onSend: { hooks.onSend(id, $0) }, + onAskNewChat: hooks.onAskNewChat.map { send in { text in send(id, text) } }, + onBlueprint: { hooks.onBlueprint(id, $0) }, onNewChat: { context.onOpenChat(id) }) }