Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Bots open a website's sign-in page instead of refusing a login (#269)
Oleksandr Ivanchenkoa5c5e39dd31c
diff --git a/src/server/connection_suggest.rs b/src/server/connection_suggest.rsindex fe6f989a..9f53bfc2 100644--- a/src/server/connection_suggest.rs+++ b/src/server/connection_suggest.rs@@ -73,7 +73,7 @@ impl ComposioReady {}}-async fn composio_ready(state: &AppState, space: &SpaceId) -> ComposioReady {+pub(crate) async fn composio_ready(state: &AppState, space: &SpaceId) -> ComposioReady {let servers = state.db.list_mcp_servers(space).await.unwrap_or_default();let Some(server) = servers.iter().find(|s| super::connections::is_composio(s)) else {return ComposioReady::NotAdded;diff --git a/src/server/continuity.rs b/src/server/continuity.rsindex c5a1d3fe..62af8146 100644--- a/src/server/continuity.rs+++ b/src/server/continuity.rs@@ -84,6 +84,21 @@ pub async fn prompt_block_with(channel_id: Option<&str>,with_tools: bool,lessons: &str,+) -> String {+ prompt_block_full(state, kwant, team_id, channel_id, with_tools, false, lessons).await+}++/// [`prompt_block_with`] for a turn that may also have the bot browser and `request_human_step`+/// ([`offers_browser_sign_in`]): then the tools section says to use a website the person has an+/// account on through a browser sign-in ([`browser_sign_in_rule`]).+pub async fn prompt_block_full(+ state: &AppState,+ kwant: &Kwant,+ team_id: Option<&str>,+ channel_id: Option<&str>,+ with_tools: bool,+ browser_sign_in: bool,+ lessons: &str,) -> String {let db = &state.db;let mut out = String::new();@@ -113,6 +128,12 @@ pub async fn prompt_block_with(out.push_str(lessons);if with_tools {out.push_str(crate::drivers::APP_TOOLS_MARKER);+ let sign_in = if browser_sign_in {+ let space = crate::db::spaces::SpaceId::new(&kwant.space_id);+ browser_sign_in_rule(super::connection_suggest::composio_ready(state, &space).await)+ } else {+ String::new()+ };out.push_str(&format!("\n\If you have the `{SELF_SERVER_NAME}` tools:\n\@@ -129,6 +150,7 @@ pub async fn prompt_block_with(- `page_source` reads a public page's HTML source: the <head> (title, meta description, canonical, robots, \hreflang, Open Graph), headings, image alt text, links and structured data, none of which WebFetch or the browser \shows. It never needs the user's approval.\n\+ {sign_in}\- When a request needs an app you can't reach (Google Search Console, Google Analytics, a CRM…), \`connection_suggest` posts a one-tap connection card. Post it in the same turn rather than asking whether to: \it connects nothing until the user signs in. Never end with an offer to post one (\"I can suggest a connection if \@@ -147,8 +169,9 @@ pub async fn prompt_block_with(and `space_*` and `channel_*` manage your space and its channels. Each change applies at once and the user sees a card \with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools \before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. \- Never handle keys, passwords or sign-ins, answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools \- tell you where in Settings the user does it. Bots' own tools are the user's switch in Settings › All spaces → \+ Never handle kwant's own keys and engine sign-ins (API keys, AI accounts, connector keys), answer approvals, install tool servers, \+ switch bots' tools on or off or change the computer: those tools tell you where in Settings the user does it. \+ Never ask for a password or one-time code in chat. Bots' own tools are the user's switch in Settings › All spaces → \\"Bots can use their own tools\"; say that outright.\n\- `propose_hire` proposes a new bot for work a specialist would do better; the person decides. `hire_status` shows \the space's hire policy and decisions.\n\n\@@ -183,6 +206,33 @@ pub async fn prompt_block_with(out}+/// Whether `scope`'s turns get the bot browser and `request_human_step` together (see+/// [`tool_list`]): only then may the prompt send the bot to a website's own sign-in page.+pub fn offers_browser_sign_in(scope: &SelfScope) -> bool {+ scope.sandbox_target.is_some() && scope.origin.is_some() && scope.cancel.is_some()+}++/// The tools-section bullet for a turn with the bot browser and `request_human_step`: a website+/// or account of the person's (TikTok, a shop, a dashboard) is reached by opening its sign-in+/// page and handing the person a sign_in step, not refused and not sent through Composio setup.+/// A connection card is an extra only when the space's Composio is `ready`. Ends in a newline.+pub fn browser_sign_in_rule(composio: super::connection_suggest::ComposioReady) -> String {+ let extra = if composio == super::connection_suggest::ComposioReady::Ready {+ "If the app also has a Composio integration, you may add a `connection_suggest` card as an extra, after the sign-in step."+ } else {+ "Composio isn't set up in this space, so don't post a `connection_suggest` card or Composio setup steps for a website you can open in the browser."+ };+ format!(+ "- When the person wants you to log in to or use a website or an account of theirs (TikTok, Instagram, a shop, \+ a dashboard), use your browser: never refuse and never send them elsewhere first. In the same turn, open its \+ sign-in page with `{BROWSER_OPEN}`; if the page shows they're already signed in, carry on. Otherwise call `{step}` \+ with kind sign_in and a one-line reason. They sign in themselves in the live browser (a password they saved in kwant for \+ that exact site is filled in by the browser, never shown to you), and the sign-in is kept for next time. After Done, \+ look at the page again and carry on with the task; after Decline, say what you couldn't do. {extra}\n",+ step = super::human_steps::TOOL,+ )+}+/// Whether turns get the agents' own tools; the `agent_tools` setting "off" turns them off.pub async fn agent_tools_enabled(state: &AppState) -> bool {state@@ -553,9 +603,9 @@ fn tool_list(scope: &SelfScope, board: bool) -> Value {list.extend(super::connection_suggest::tools());if scope.cancel.is_some() {list.extend(super::questions::tools());- if scope.sandbox_target.is_some() {- list.extend(super::human_steps::tools());- }+ }+ if offers_browser_sign_in(scope) {+ list.extend(super::human_steps::tools());}}}@@ -1921,4 +1971,71 @@ mod tests {NOTIFY_BODY_CHARS);}++ fn sign_in_scope(origin: bool, cancel: bool, browser: bool) -> SelfScope {+ SelfScope {+ kwant_id: "k".into(),+ kwant_name: "TikTokLead".into(),+ origin: origin.then(|| TurnOrigin {+ channel_id: Some("c".into()),+ direct_kwant_id: None,+ thread_id: None,+ team_id: Some("t".into()),+ member_ids: vec!["k".into()],+ depth: 0,+ message_id: None,+ }),+ cancel: cancel.then(tokio_util::sync::CancellationToken::new),+ turn_id: Some("turn".into()),+ workspace: None,+ sandbox_target: browser.then(|| "t".into()),+ }+ }++ fn names(scope: &SelfScope) -> Vec<String> {+ tool_list(scope, false)+ .as_array()+ .unwrap()+ .iter()+ .filter_map(|t| t["name"].as_str().map(String::from))+ .collect()+ }++ #[test]+ fn browser_sign_in_is_offered_with_both_tools_in_a_chat_turn() {+ // A chat turn, team lead included (routes.rs sets origin, cancel and the browser for every one)+ let chat = sign_in_scope(true, true, true);+ assert!(offers_browser_sign_in(&chat));+ let list = names(&chat);+ assert!(list.iter().any(|n| n == BROWSER_OPEN), "{list:?}");+ assert!(list.iter().any(|n| n == super::super::human_steps::TOOL), "{list:?}");+ // No browser, no chat or no stop button: no sign-in step, so the prompt keeps quiet about it+ for scope in [sign_in_scope(true, true, false), sign_in_scope(false, true, true), sign_in_scope(true, false, true)] {+ assert!(!offers_browser_sign_in(&scope));+ assert!(!names(&scope).iter().any(|n| n == super::super::human_steps::TOOL));+ }+ }++ #[test]+ fn browser_sign_in_rule_opens_the_login_page_and_asks_for_a_sign_in_step() {+ use super::super::connection_suggest::ComposioReady;+ for ready in [ComposioReady::Ready, ComposioReady::NotAdded, ComposioReady::NeedsKey, ComposioReady::Off] {+ let rule = browser_sign_in_rule(ready);+ assert!(rule.starts_with("- When the person wants you to log in to or use a website"), "{rule}");+ assert!(rule.contains("TikTok"));+ assert!(rule.contains("never refuse"));+ assert!(rule.contains("open its sign-in page with `browser_open`"), "{rule}");+ assert!(rule.contains("call `request_human_step` with kind sign_in"), "{rule}");+ assert!(rule.contains("kept for next time"));+ assert!(rule.ends_with('\n'));+ assert!(!rule.contains(" "), "no stray continuation spaces: {rule}");+ }+ // A connection card is only an extra, and only when Composio can start a sign-in+ assert!(browser_sign_in_rule(ComposioReady::Ready).contains("may add a `connection_suggest` card as an extra, after the sign-in step"));+ for ready in [ComposioReady::NotAdded, ComposioReady::NeedsKey, ComposioReady::Off] {+ let rule = browser_sign_in_rule(ready);+ assert!(rule.contains("don't post a `connection_suggest` card or Composio setup steps"), "{rule}");+ assert!(!rule.contains("as an extra"));+ }+ }}diff --git a/src/server/routes.rs b/src/server/routes.rsindex 80f88b28..cac4bf21 100644--- a/src/server/routes.rs+++ b/src/server/routes.rs@@ -2400,6 +2400,7 @@ async fn run_kwant_turn_inner(sandbox_target: Some(sandbox_target.clone()),}});+ let browser_sign_in = self_scope.as_ref().is_some_and(super::continuity::offers_browser_sign_in);let card_opts = super::mcp_runtime::TurnApprovalOpts {routed: Some((target_model.clone(), effort_level.clone())),always_ask: opts.always_ask,@@ -2428,12 +2429,13 @@ async fn run_kwant_turn_inner(} else {String::new()};- let continuity = super::continuity::prompt_block_with(+ let continuity = super::continuity::prompt_block_full(state,target_kwant,scope.team_context.as_ref().map(|t| t.id.as_str()),channel_id.as_deref(),with_tools,+ browser_sign_in,&lessons,).await;diff --git a/tests/continuity_test.rs b/tests/continuity_test.rsindex 7da077c1..0ee9be06 100644--- a/tests/continuity_test.rs+++ b/tests/continuity_test.rs@@ -1812,3 +1812,34 @@ async fn notifications_are_filtered_and_content_free() {}assert!(rx.try_recv().is_err());}++#[tokio::test]+async fn prompt_sends_website_logins_to_a_browser_sign_in_only_with_the_browser() {+ let (_app, state, _tmp) = setup().await;+ let kwants = state.db.list_kwants(&kwnt::db::spaces::SpaceId::default_space()).await.unwrap();+ let k = &kwants[0];+ let rule = "- When the person wants you to log in to or use a website or an account of theirs";++ // A chat turn with the bot browser and request_human_step: the rule, before connection_suggest+ let with = continuity::prompt_block_full(&state, k, None, None, true, true, "").await;+ let at = with.find(rule).expect("browser sign-in rule");+ assert!(at < with.find("`connection_suggest` posts a one-tap connection card").unwrap(), "browser sign-in comes first");+ assert!(with.contains("open its sign-in page with `browser_open`"));+ assert!(with.contains("call `request_human_step` with kind sign_in"));+ // No Composio in this space: no Composio setup for a website the browser can open+ assert!(with.contains("Composio isn't set up in this space"));++ // Tools but no browser (a routine, a task), and no tools at all: no rule+ let tools_only = continuity::prompt_block_full(&state, k, None, None, true, false, "").await;+ assert!(!tools_only.contains(rule));+ assert!(!tools_only.contains("request_human_step"));+ assert_eq!(tools_only, continuity::prompt_block(&state, k, None, None, true).await);+ assert!(!continuity::prompt_block_full(&state, k, None, None, false, true, "").await.contains(rule));++ // The settings rule is about kwant's own keys and engine sign-ins, not the person's websites+ for block in [&with, &tools_only] {+ assert!(block.contains("Never handle kwant's own keys and engine sign-ins (API keys, AI accounts, connector keys)"));+ assert!(block.contains("Never ask for a password or one-time code in chat."));+ assert!(!block.contains("Never handle keys, passwords or sign-ins"));+ }+}diff --git a/tests/fixtures/truth_ledger_off_prompt.txt b/tests/fixtures/truth_ledger_off_prompt.txtindex b2319b82..bf2a4b34 100644--- a/tests/fixtures/truth_ledger_off_prompt.txt+++ b/tests/fixtures/truth_ledger_off_prompt.txt@@ -15,7 +15,7 @@ If you have the `kwnt_tools` tools:- `page_source` reads a public page's HTML source: the <head> (title, meta description, canonical, robots, hreflang, Open Graph), headings, image alt text, links and structured data, none of which WebFetch or the browser shows. It never needs the user's approval.- When a request needs an app you can't reach (Google Search Console, Google Analytics, a CRM…), `connection_suggest` posts a one-tap connection card. Post it in the same turn rather than asking whether to: it connects nothing until the user signs in. Never end with an offer to post one ("I can suggest a connection if you'd like"): post it, then carry on with everything you can do without it.- Before you call anything impossible, try the fallback: `page_source` for a page's tags and attributes, the browser for a site's own free tool (pagespeed.web.dev when the PageSpeed API is rate-limited), web search for public data. When access is truly missing, offer the concrete fix: `connection_suggest` for an app, `mcp_search` and `mcp_suggest` for a tool server, or the exact key and where the user adds it. A bare "not possible" with no offered fix is the exception; then say what you tried.-- You can set up and manage the app yourself; when asked, do it in that same turn instead of telling the user how. When the user wants something to happen on its own ("every morning", "each Friday", "remind me at 5"), `routine_create` schedules it (it runs as you and replies in this chat by default; calendar rules like "the 1st of each month" use a monthly or cron schedule); `follow_up_create` schedules a one-off check-in by you here; `routine_list`, `routine_update`, `routine_pause`, `routine_resume`, `routine_run_now` and `routine_delete` manage routines. `bot_list`, `bot_create` and `bot_update` add and change bots, `settings_get`/`settings_update` change non-secret settings such as the time zone, and `space_*` and `channel_*` manage your space and its channels. Each change applies at once and the user sees a card with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. Never handle keys, passwords or sign-ins, answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools tell you where in Settings the user does it. Bots' own tools are the user's switch in Settings › All spaces → "Bots can use their own tools"; say that outright.+- You can set up and manage the app yourself; when asked, do it in that same turn instead of telling the user how. When the user wants something to happen on its own ("every morning", "each Friday", "remind me at 5"), `routine_create` schedules it (it runs as you and replies in this chat by default; calendar rules like "the 1st of each month" use a monthly or cron schedule); `follow_up_create` schedules a one-off check-in by you here; `routine_list`, `routine_update`, `routine_pause`, `routine_resume`, `routine_run_now` and `routine_delete` manage routines. `bot_list`, `bot_create` and `bot_update` add and change bots, `settings_get`/`settings_update` change non-secret settings such as the time zone, and `space_*` and `channel_*` manage your space and its channels. Each change applies at once and the user sees a card with Undo; afterwards say in one sentence what will happen. The user may undo a change later, so check with the list tools before relying on an earlier one. Deleting a bot, a space or an account only asks the user to confirm. Never handle kwant's own keys and engine sign-ins (API keys, AI accounts, connector keys), answer approvals, install tool servers, switch bots' tools on or off or change the computer: those tools tell you where in Settings the user does it. Never ask for a password or one-time code in chat. Bots' own tools are the user's switch in Settings › All spaces → "Bots can use their own tools"; say that outright.- `propose_hire` proposes a new bot for work a specialist would do better; the person decides. `hire_status` shows the space's hire policy and decisions.[How to work]diff --git a/tests/truth_ledger_on_test.rs b/tests/truth_ledger_on_test.rsindex c130530d..e5074a30 100644--- a/tests/truth_ledger_on_test.rs+++ b/tests/truth_ledger_on_test.rs@@ -249,7 +249,7 @@ async fn off_and_shadow_prompts_are_byte_identical_and_switching_off_restores_thlet off = prompt(&e, &a).await;// Off is today's prompt, not just this build's: the fixture is this exact setup's prompt (with// ids as {id}), first taken on main 895a96c before C2 and updated only when the prompt itself- // changes on main. It last changed for the chat-correction sentence (0.6.8, after c9d5cd7).+ // changes on main. It last changed for the narrowed key and sign-in sentence (0.6.9, browser sign-in).// The off == shadow == fixture check proves the ledger setting adds nothing to the prompt.let golden = include_str!("fixtures/truth_ledger_off_prompt.txt");assert_eq!(without_ids(&off), golden, "off differs from today's prompt");