Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

fix(connectors): announce connected accounts so a mid-chat connect is noticed

Durganshu Mishra3de430eef4ba
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index 1fbcb78..e9407e4 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -514,8 +514,15 @@ class MainActivity : ComponentActivity() {
)
}
Route.CONNECTORS -> {
- BackHandler { currentRoute = Route.HOME }
- ConnectorsScreen(onBack = { currentRoute = Route.HOME })
+ // refreshSettings() on the way out, like every other route: the
+ // enable/disable toggles write disabledConnectors, and the agent
+ // reads it from ChatViewModel's cached Settings.
+ val leaveConnectors = {
+ chatViewModel.refreshSettings()
+ currentRoute = Route.HOME
+ }
+ BackHandler { leaveConnectors() }
+ ConnectorsScreen(onBack = leaveConnectors)
}
Route.HOME -> {
// Back from an active chat returns to a fresh home (new session,
diff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
index 4718605..c75aca9 100644
--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt
+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt
@@ -999,11 +999,21 @@ class AgentEngine(
appendLine(" (Relative paths in read_file/write_file/list_files resolve against the working directory.)")
appendLine(" Preferred language: ${settings.preferredLanguage}")
appendLine(" Preferred currency: ${settings.preferredCurrency}")
- // Discovery hint for connectors the user has never set up. Costs ~20
- // tokens and is the only way the model can suggest connecting Notion
- // or To Do, whose tools are hidden and which — unlike email — have no
- // no-connector fallback tool. Connectors that are configured but
- // switched off are omitted: the user already decided.
+ // Connector state, rebuilt every call. The active list is what lets the
+ // model notice a connector that appeared mid-conversation: its own
+ // earlier turns may say "no account is connected", and a tool quietly
+ // materialising in the schema list is too weak a signal to overturn
+ // that. The unconfigured list is the only way it can suggest connecting
+ // Notion or To Do, whose tools are hidden and which — unlike email —
+ // have no no-connector fallback tool. Connectors that are configured
+ // but switched off appear in neither: the user already decided.
+ val active = ConnectorRegistry.active(settings.disabledConnectors)
+ if (active.isNotEmpty()) {
+ appendLine(
+ " Connected accounts, usable right now via their tools: " +
+ active.joinToString(", ") { it.displayName }
+ )
+ }
val unconfigured = ConnectorRegistry.unconfigured()
if (unconfigured.isNotEmpty()) {
appendLine(
diff --git a/app/src/main/java/com/gotcha/connectors/ConnectorRegistry.kt b/app/src/main/java/com/gotcha/connectors/ConnectorRegistry.kt
index e0f0798..d84f9c4 100644
--- a/app/src/main/java/com/gotcha/connectors/ConnectorRegistry.kt
+++ b/app/src/main/java/com/gotcha/connectors/ConnectorRegistry.kt
@@ -66,9 +66,13 @@ object ConnectorRegistry {
fun byId(id: String): Connector? = connectors.firstOrNull { it.id == id }
+ /** Connectors that are connected and not switched off by the user. */
+ fun active(disabledConnectors: Set<String>): List<Connector> =
+ connectors.filter { it.isActive(disabledConnectors) }
+
/** Ids of connectors that are connected and not switched off by the user. */
fun activeIds(disabledConnectors: Set<String>): Set<String> =
- connectors.filter { it.isActive(disabledConnectors) }.mapTo(mutableSetOf()) { it.id }
+ active(disabledConnectors).mapTo(mutableSetOf()) { it.id }
/**
* Tool names to withhold from the model right now, because every connector
diff --git a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
index 88055ea..6f77250 100644
--- a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
+++ b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
@@ -1909,7 +1909,8 @@ object ToolDefinitions {
val composeEmail = tool(
"compose_email",
"Open the user's email app with a pre-filled draft they review and send themselves. " +
- "Needs no connector, so it is the fallback when send_email is unavailable.",
+ "Only a fallback: whenever send_email is in your tool list, use that instead — " +
+ "it sends directly, and it confirms with the user anyway.",
schema {
putJsonObject("properties") {
putJsonObject("to") {
diff --git a/app/src/test/java/com/gotcha/connectors/ConnectorGatingTest.kt b/app/src/test/java/com/gotcha/connectors/ConnectorGatingTest.kt
index f6c94a1..6a0c4ca 100644
--- a/app/src/test/java/com/gotcha/connectors/ConnectorGatingTest.kt
+++ b/app/src/test/java/com/gotcha/connectors/ConnectorGatingTest.kt
@@ -160,6 +160,22 @@ class ConnectorGatingTest {
assertFalse(notion.isActive(setOf("notion")))
}
+ @Test
+ fun `connecting a connector flips it from unconfigured to active`() {
+ // The env block reports these two lists, and that flip is what tells the
+ // model a capability appeared mid-conversation — its own earlier turns may
+ // still claim no account is connected.
+ val off = FakeConnector(ConnectorCatalog.GOOGLE, connected = false)
+ val on = FakeConnector(ConnectorCatalog.GOOGLE, connected = true)
+
+ assertFalse(off.isActive(emptySet()))
+ assertTrue(on.isActive(emptySet()))
+ // A connected-but-disabled connector belongs to neither list: it is not
+ // usable, and re-offering setup would nag about a decision already made.
+ assertFalse(on.isActive(setOf("google")))
+ assertTrue(on.isConnected())
+ }
+
@Test
fun `catalog ids match the connector ids the registry uses`() {
assertEquals(