Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Bansify AI — working plan

Bansify AI is the Android chat client for the Gothwad ecosystem. This file records what is
real in the app today, which free AI providers it supports, and what is still missing.

## What works now

- **Real chat**: messages stream from a provider you choose, token by token, and are saved
to `chats.json` on the device, so history survives a restart.
- **Bring your own key**: one card-free API key per provider, stored on the device
(DataStore). Keys are sent only to that provider.
- **Gothwad sign-in**: native JSON sign-in against the live Accounts Worker
(`https://accounts.gothwadtech.com/api/mobile/auth/*`). Same account, sessions and
sign-out as Mail, Store and Drive. Password sign-in, sign-up, authenticator 2FA and
forgot-password are implemented.
- **Account control**: an account screen and sheet that list every signed-in account,
switch between them, add another, open the browser account page, and sign out one or all.
- **Guest mode**: works without an account; chats stay local.

## Bansify Cloud (built in)

The `bansifyai` Worker (`https://bansifyai.bansify.workers.dev`) is already deployed and is the
default route. It holds the provider keys as Worker secrets, ranks free providers, caches
answers in KV, records daily usage in D1 and enforces a per-IP daily quota. The app calls it
with `POST /v1/chat` (`{messages:[{role,content}], model:"auto"}`) and reads `{"delta": ...}`
SSE frames, so **no key is needed in the app**. `GET /v1/health`, `/v1/models` and
`/v1/providers` are available for status and quota display.

## Free providers (all card-free)

| Provider | Wire format | Free tier | Notes |
|---|---|---|---|
| Google Gemini | native `generateContent` | per-project limits in AI Studio | Start here. `gemini-3.5-flash-lite` and `gemini-3.8-flash` are on the free tier. |
| Groq | OpenAI-compatible | 30 req/min, 1,000 req/day per model | `openai/gpt-oss-120b`, `openai/gpt-oss-20b`, `qwen/qwen3.8-27b`. |
| OpenRouter | OpenAI-compatible | 20 req/min, 50 req/day (1,000 after 10 credits) | Free IDs end in `:free`; `openrouter/free` picks one for you. |
| Cloudflare Workers AI | OpenAI-compatible | 10,000 Neurons/day | Paste `ACCOUNT_ID:API_TOKEN`. Good fit because the ecosystem is already on Cloudflare. |
| Z.ai (GLM) | OpenAI-compatible | Flash models free | `glm-5.3-flash`, `glm-4.7-flash`. |
| Mistral | OpenAI-compatible | experiment tier | Check the console for current limits. |

**Recommended setup:** use Bansify Cloud as-is. Add your own Gemini key only if you want to
bypass the Worker's daily quota. Auto mode tries Bansify Cloud first, then the first provider
that has a key, in the order above.

**Dropped from the old prototype catalogue:** GitHub Models was retired on 30 July 2026 and
its inference API no longer exists. Groq retired the Llama model IDs, so
`llama-3.3-70b-versatile` and friends now return 404. The prototype also listed Cohere,
NVIDIA NIM, Together, SambaNova, Cerebras and Hugging Face; those are not wired yet.

## Not built yet

- Image and video generation (the composer shows a clear message instead of a fake render).
- Studio (repos, preview, integrations) is still a local prototype with sample data.
- Markdown export, share links and public chat sharing.
- Voice input uses a placeholder transcript.
- Keys are stored in DataStore, not EncryptedSharedPreferences or the Keystore. Move them
before a release build.

## Accounts integration notes

- The app signs in with the already-approved first-party client
`gothwad-accounts-android` and the scope `profile email offline_access`. No Worker or D1
change is needed for sign-in to work today.
- A dedicated `gothwad-ai` client (package `com.bansify.ai`, its own allowed scopes) is the
cleaner long-term setup. That needs a migration and a Worker deploy in `GothwadTech/accounts`.
- The Accounts Worker does not check the Android package name at sign-in; it checks that the
client is first-party and active. Package and certificate checks belong in a later
attestation step, not in this app.

## Build and test

```bash
./gradlew assembleDebug
```

The sandbox used to prepare this change had no JDK, Android SDK or Gradle, so the project was
not compiled there. Build it locally and send back any compiler output.
64 changes: 46 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
# Bansify AI

Bansify AI — a calm, roomy Android AI chat and developer Studio **UI prototype**,
with Hinglish-flavoured UX, a multi-provider model catalog, and mock streaming.
Built with Kotlin + Jetpack Compose (Material 3).
Bansify AI — a calm, roomy Android AI chat and developer Studio app for the Gothwad
ecosystem. Kotlin + Jetpack Compose (Material 3).

Originally prototyped in Google AI Studio, now maintained in this repository.
Originally prototyped in Google AI Studio. The chat side is now **live**: replies stream
from a real provider, and sign-in uses the same Gothwad account as Mail, Store and Drive.
Studio and the workspace screens are still a **mock** prototype (`data/mock/`), and so are
image/video generation, export and sharing.

All data is **mock data** (`data/mock/`) — there is no backend wired up yet.
See [PLAN.md](PLAN.md) for the provider list, free tiers and the remaining gaps.

## Screens & features

- **Sign-in** — native Gothwad account sign-in, sign-up, authenticator 2FA, forgot password,
or continue as guest
- **Accounts** — up to six signed-in accounts, switch, add another, manage in the browser,
sign out of one or all
- **Onboarding** — welcome, name, profession, goals
- **Chat** — composer with mock streaming, markdown-lite rendering, model picker sheet, add-to-chat sheet
- **History** — past conversations
- **Models** — multi-provider model catalog (grouped by provider)
- **Studio** — repo browsing, file viewer with code/preview panes, integrations sheet, zip upload
- **Workspace** — library, scheduled items
- **Chat** — live streaming replies, markdown-lite rendering, model picker sheet, per-message
regenerate and feedback, history saved on the device
- **History** — past conversations, pinned and searchable
- **Models** — provider catalogue with free-tier notes and key status
- **AI providers & keys** — Bansify Cloud is built in; add your own free key for Gemini,
Groq, OpenRouter, Cloudflare Workers AI, Z.ai or Mistral
- **Studio** — repo browsing, file viewer with code/preview panes, integrations sheet, zip
upload (mock data)
- **Workspace** — library, scheduled items (mock data)
- **Drawer** — navigation drawer
- **Settings** — appearance, memory, persona, data, about
- **Splash**

## How chat works

`POST /v1/chat` on the Bansify Cloud Worker (`https://bansifyai.bansify.workers.dev`) with
`{messages:[{role,content}], model:"auto"}`; the Worker ranks a free provider, streams
`{"delta": ...}` SSE frames and enforces a daily quota. The app needs no key for that route.
Adding your own provider key in Settings bypasses the Worker quota and calls the provider
directly. Keys are stored on the device only.

## Project structure

```
app/src/main/java/com/bansify/ai/
├── MainActivity.kt
├── core/ # design system (colors, type, shapes, theme, components) + shared UI
├── data/ # mock data + repositories (Chat, Model, Studio, UserPreferences)
├── feature/ # chat, history, models, onboarding, profile, settings,
│ # splash, studio, workspace, drawer
├── core/ # design system (colors, type, shapes, theme, components), shared UI, HTTP
├── data/ # ai providers, auth, chat store, mock data, repositories
├── feature/ # auth, account, chat, history, models, onboarding, profile,
│ # settings, splash, studio, workspace, drawer
├── nav/ # NavGraph + routes
└── state/ # shared UI state
public/assets/ # design reference screenshots
Expand Down Expand Up @@ -80,12 +98,22 @@ unsigned release APK/AAB** instead — it never falls back to the debug key.

## Manual device checks

There are no automated UI tests yet (UI prototype), so before shipping a build verify on
an emulator/device: cold start → onboarding flow (name, profession, goals) → drawer
navigation → new chat with mock streaming response → stop streaming → models sheet →
Studio repo/file screens render → Settings screens open.
There are no automated UI tests yet, so before shipping a build verify on an
emulator/device:

1. Cold start → sign-in screen → sign in with a Gothwad account (or continue as guest).
2. Onboarding (name, profession, goals) → chat.
3. Send a message and confirm a real streamed reply, then Stop mid-stream.
4. Kill and reopen the app: the conversation is still in History.
5. Settings → AI providers & keys: add a key, remove it, and check that Auto still routes.
6. Accounts: add a second account, switch, sign out one, sign out all.
7. Models sheet, Studio repo/file screens and the Settings screens render.

## Notes

- `metadata.json` describes the AI Studio prototype this was exported from.
- `public/assets/` holds reference screenshots from the design phase.
- Sign-in uses the first-party client `gothwad-accounts-android` against
`https://accounts.gothwadtech.com/api/mobile/auth/*`; no Worker or D1 change is required.
- API keys are stored in DataStore, not EncryptedSharedPreferences or the Keystore. Move
them before a production release.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
68 changes: 52 additions & 16 deletions app/src/main/java/com/bansify/ai/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import com.bansify.ai.core.designsystem.BansifyTheme
import com.bansify.ai.core.designsystem.ThemeMode
import com.bansify.ai.data.ai.AiChatClient
import com.bansify.ai.data.ai.ApiKeyStore
import com.bansify.ai.data.auth.AccountStore
import com.bansify.ai.data.auth.AccountsClient
import com.bansify.ai.data.auth.AuthRepository
import com.bansify.ai.data.mock.AppSettings
import com.bansify.ai.data.mock.UserProfile
import com.bansify.ai.data.repo.ChatRepository
import com.bansify.ai.data.repo.ModelRepository
import com.bansify.ai.data.repo.StudioRepository
import com.bansify.ai.data.repo.UserPreferencesRepository
import com.bansify.ai.feature.account.AuthViewModel
import com.bansify.ai.feature.auth.LoginScreen
import com.bansify.ai.feature.auth.LoginViewModel
import com.bansify.ai.feature.chat.ChatViewModel
import com.bansify.ai.feature.history.HistoryViewModel
import com.bansify.ai.feature.models.ModelsViewModel
Expand All @@ -27,6 +38,7 @@ import com.bansify.ai.feature.settings.SettingsViewModel
import com.bansify.ai.feature.studio.StudioViewModel
import com.bansify.ai.nav.BansifyNavGraph
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -35,22 +47,34 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()

val prefsRepo = UserPreferencesRepository(applicationContext)
val modelRepo = ModelRepository()
val chatRepo = ChatRepository()
val keyStore = ApiKeyStore(applicationContext)
val modelRepo = ModelRepository(keyStore)
val chatRepo = ChatRepository(applicationContext)
val studioRepo = StudioRepository()
val chatEngine = AiChatClient()
val authRepo = AuthRepository(AccountsClient(), AccountStore(applicationContext))

// TODO(pawan): Replace manual container with Hilt when real backend/network layers are added.
val onboardingViewModel = OnboardingViewModel(prefsRepo, chatRepo)
val chatViewModel = ChatViewModel(chatRepo, modelRepo, prefsRepo)
val chatViewModel = ChatViewModel(chatRepo, modelRepo, prefsRepo, chatEngine)
val historyViewModel = HistoryViewModel(chatRepo)
val modelsViewModel = ModelsViewModel(modelRepo, prefsRepo)
val studioViewModel = StudioViewModel(studioRepo)
val settingsViewModel = SettingsViewModel(prefsRepo, chatRepo, modelRepo)
val authViewModel = AuthViewModel(authRepo)
val loginViewModel = LoginViewModel(authRepo)

lifecycleScope.launch { authRepo.restore() }

setContent {
val settings by prefsRepo.appSettings.collectAsStateWithLifecycle(initialValue = AppSettings())
val profile by prefsRepo.userProfile.collectAsStateWithLifecycle(initialValue = UserProfile())
val authState by authViewModel.state.collectAsStateWithLifecycle()
val isOnboardedFlow = remember { prefsRepo.userProfile.map { it.onboardingCompleted } }
val isOnboarded by isOnboardedFlow.collectAsStateWithLifecycle(initialValue = null)
val isOnboardedValue by isOnboardedFlow.collectAsStateWithLifecycle(initialValue = null)
val isOnboarded = isOnboardedValue ?: if (authState.isSignedIn) true else null
val scope = rememberCoroutineScope()
val showLogin = !authState.isRestoring && !authState.isSignedIn && !profile.isGuest

val systemDark = isSystemInDarkTheme()
val isDark = when (settings.themeMode) {
Expand All @@ -70,18 +94,30 @@ class MainActivity : ComponentActivity() {
dynamicColor = settings.dynamicColor,
fontScaleMultiplier = settings.fontScale
) {
val navController = rememberNavController()
BansifyNavGraph(
navController = navController,
isOnboarded = isOnboarded,
modelRepo = modelRepo,
onboardingViewModel = onboardingViewModel,
chatViewModel = chatViewModel,
historyViewModel = historyViewModel,
modelsViewModel = modelsViewModel,
studioViewModel = studioViewModel,
settingsViewModel = settingsViewModel
)
if (showLogin) {
LoginScreen(
viewModel = loginViewModel,
onSignedIn = {},
onContinueAsGuest = {
scope.launch { prefsRepo.setGuestMode(true) }
}
)
} else {
val navController = rememberNavController()
BansifyNavGraph(
navController = navController,
isOnboarded = isOnboarded,
modelRepo = modelRepo,
onboardingViewModel = onboardingViewModel,
chatViewModel = chatViewModel,
historyViewModel = historyViewModel,
modelsViewModel = modelsViewModel,
studioViewModel = studioViewModel,
settingsViewModel = settingsViewModel,
authViewModel = authViewModel,
loginViewModel = loginViewModel
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -214,11 +215,13 @@ fun TextFieldOutlined(
trailingIcon: @Composable (() -> Unit)? = null,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
visualTransformation: VisualTransformation = VisualTransformation.None,
testTag: String? = null
) {
OutlinedTextField(
value = value,
onValueChange = onValueChange,
visualTransformation = visualTransformation,
placeholder = {
Text(
text = placeholder,
Expand Down
Loading
Loading