Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[ensu] Add knowledge attribution and terms screens

setalp631d79d58bb9
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
index 26e6b489d1..844ab5d6c7 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeNavigation.kt
@@ -38,6 +38,7 @@ import io.ente.ensu.logging.LogViewerScreen
import io.ente.ensu.settings.SettingsScreen
import io.ente.ensu.settings.SystemPromptSettingsScreen
import io.ente.ensu.settings.KnowledgeSettingsScreen
+import io.ente.ensu.settings.TermsAndConditionsScreen
import io.ente.ensu.device.isChatSupported
@Composable
@@ -93,7 +94,10 @@ internal fun HomeNavigation(
SimpleTopBar(title = "Settings") { navController.popBackStack() }
}
HomeRoute.Knowledge -> {
- SimpleTopBar(title = "Knowledge") { navController.popBackStack() }
+ SimpleTopBar(title = "Ensu Packs") { navController.popBackStack() }
+ }
+ HomeRoute.Terms -> {
+ SimpleTopBar(title = "Terms and Conditions") { navController.popBackStack() }
}
else -> Unit
}
@@ -152,6 +156,7 @@ internal fun HomeNavigation(
isAdvancedUnlocked = appState.developerSettings.isAdvancedUnlocked,
onOpenLogs = { navController.navigate(HomeRoute.Logs) },
onOpenKnowledge = { navController.navigate(HomeRoute.Knowledge) },
+ onOpenTerms = { navController.navigate(HomeRoute.Terms) },
onOpenModelSettings = { navController.navigate(HomeRoute.ModelSettings) },
onOpenSystemPromptSettings = { navController.navigate(HomeRoute.SystemPromptSettings) },
onUnlockAdvanced = {
@@ -176,6 +181,15 @@ internal fun HomeNavigation(
onSetEnabled = store::setKnowledgePackEnabled
)
}
+ composable(
+ route = HomeRoute.Terms,
+ enterTransition = { forwardEnter() },
+ exitTransition = { forwardExit() },
+ popEnterTransition = { backEnter() },
+ popExitTransition = { backExit() }
+ ) {
+ TermsAndConditionsScreen()
+ }
composable(
route = HomeRoute.Logs,
enterTransition = { forwardEnter() },
@@ -244,6 +258,7 @@ internal object HomeRoute {
const val ModelSettings = "model-settings"
const val SystemPromptSettings = "system-prompt-settings"
const val Knowledge = "knowledge"
+ const val Terms = "terms"
}
internal fun AnimatedContentTransitionScope<NavBackStackEntry>.forwardEnter() =
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
index 8312af7099..6269401079 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt
@@ -10,6 +10,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.scrollBy
import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -37,6 +39,7 @@ import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenuItem
+import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Surface
@@ -410,88 +413,92 @@ private fun DownloadOnboarding(
val downloadAccent = EnsuColor.accentDark
val downloadButtonTextColor = Color.Black
val sizeText = modelDownloadSizeBytes?.let { "Approx. ${formatBytes(it)}" } ?: "Approx. size varies by model"
- Box(
- modifier = modifier.fillMaxSize(),
- contentAlignment = Alignment.Center
- ) {
- Column(horizontalAlignment = Alignment.CenterHorizontally) {
- Text(
- text = "Download models to begin using Chat",
- style = EnsuTypography.large,
- color = EnsuColor.textPrimary(),
- textAlign = TextAlign.Center
- )
- Spacer(modifier = Modifier.height(EnsuSpacing.md.dp))
- if (isDownloading) {
- val isLoadingModel = downloadPhase == DownloadPhase.Loading
- val showProgress = downloadPercent != null || isLoadingModel
- val statusText = when {
- isLoadingModel -> downloadStatus
- modelDownloadSizeBytes != null && downloadPercent != null && downloadPercent >= 0 -> {
- val downloadedBytes = (modelDownloadSizeBytes * (downloadPercent / 100f)).roundToLong()
- "Downloading... ${formatBytes(downloadedBytes)} / ${formatBytes(modelDownloadSizeBytes)}"
- }
- !downloadStatus.isNullOrBlank() -> downloadStatus
- else -> "Downloading..."
- }
+ Column(modifier = modifier.fillMaxSize()) {
+ Box(
+ modifier = Modifier
+ .weight(1f)
+ .fillMaxWidth(),
+ contentAlignment = Alignment.Center
+ ) {
+ Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
- text = statusText ?: "Downloading...",
- style = EnsuTypography.body.copy(fontFeatureSettings = "tnum"),
- color = EnsuColor.textMuted(),
+ text = "Download models to begin using Chat",
+ style = EnsuTypography.large,
+ color = EnsuColor.textPrimary(),
textAlign = TextAlign.Center
)
- if (showProgress) {
- Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
- val clamped = downloadPercent?.coerceIn(0, 100)
- if (clamped != null) {
- LinearProgressIndicator(
- progress = { clamped / 100f },
- color = downloadAccent,
- trackColor = EnsuColor.border(),
- modifier = Modifier
- .fillMaxWidth(0.6f)
- .height(6.dp)
- )
- } else {
- LinearProgressIndicator(
- color = downloadAccent,
- trackColor = EnsuColor.border(),
- modifier = Modifier
- .fillMaxWidth(0.6f)
- .height(6.dp)
- )
+ Spacer(modifier = Modifier.height(EnsuSpacing.md.dp))
+ if (isDownloading) {
+ val isLoadingModel = downloadPhase == DownloadPhase.Loading
+ val showProgress = downloadPercent != null || isLoadingModel
+ val statusText = when {
+ isLoadingModel -> downloadStatus
+ modelDownloadSizeBytes != null && downloadPercent != null && downloadPercent >= 0 -> {
+ val downloadedBytes = (modelDownloadSizeBytes * (downloadPercent / 100f)).roundToLong()
+ "Downloading... ${formatBytes(downloadedBytes)} / ${formatBytes(modelDownloadSizeBytes)}"
+ }
+ !downloadStatus.isNullOrBlank() -> downloadStatus
+ else -> "Downloading..."
}
- }
- } else {
- if (!downloadStatus.isNullOrBlank()) {
Text(
- text = downloadStatus,
- style = EnsuTypography.body,
- color = if (downloadPhase == DownloadPhase.Failed) {
- EnsuColor.error
- } else {
- EnsuColor.textMuted()
- },
+ text = statusText ?: "Downloading...",
+ style = EnsuTypography.body.copy(fontFeatureSettings = "tnum"),
+ color = EnsuColor.textMuted(),
textAlign = TextAlign.Center
)
+ if (showProgress) {
+ Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
+ val clamped = downloadPercent?.coerceIn(0, 100)
+ if (clamped != null) {
+ LinearProgressIndicator(
+ progress = { clamped / 100f },
+ color = downloadAccent,
+ trackColor = EnsuColor.border(),
+ modifier = Modifier
+ .fillMaxWidth(0.6f)
+ .height(6.dp)
+ )
+ } else {
+ LinearProgressIndicator(
+ color = downloadAccent,
+ trackColor = EnsuColor.border(),
+ modifier = Modifier
+ .fillMaxWidth(0.6f)
+ .height(6.dp)
+ )
+ }
+ }
+ } else {
+ if (!downloadStatus.isNullOrBlank()) {
+ Text(
+ text = downloadStatus,
+ style = EnsuTypography.body,
+ color = if (downloadPhase == DownloadPhase.Failed) {
+ EnsuColor.error
+ } else {
+ EnsuColor.textMuted()
+ },
+ textAlign = TextAlign.Center
+ )
+ Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
+ }
+ Button(
+ onClick = {
+ haptic.perform(HapticFeedbackType.TextHandleMove)
+ onDownload()
+ },
+ shape = RoundedCornerShape(EnsuCornerRadius.button.dp),
+ colors = ButtonDefaults.buttonColors(containerColor = downloadAccent)
+ ) {
+ Text(text = "Download", style = EnsuTypography.body, color = downloadButtonTextColor)
+ }
Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
+ Text(
+ text = sizeText,
+ style = EnsuTypography.small,
+ color = EnsuColor.textMuted()
+ )
}
- Button(
- onClick = {
- haptic.perform(HapticFeedbackType.TextHandleMove)
- onDownload()
- },
- shape = RoundedCornerShape(EnsuCornerRadius.button.dp),
- colors = ButtonDefaults.buttonColors(containerColor = downloadAccent)
- ) {
- Text(text = "Download models", style = EnsuTypography.body, color = downloadButtonTextColor)
- }
- Spacer(modifier = Modifier.height(EnsuSpacing.sm.dp))
- Text(
- text = sizeText,
- style = EnsuTypography.small,
- color = EnsuColor.textMuted()
- )
}
}
}
@@ -762,40 +769,67 @@ private fun KnowledgeSourcesDialog(
onDismissRequest = onDismiss,
title = { Text("Sources", style = EnsuTypography.h3) },
text = {
- Column(verticalArrangement = Arrangement.spacedBy(EnsuSpacing.lg.dp)) {
- citations.forEach { citation ->
- Column {
+ Column(
+ modifier = Modifier.verticalScroll(rememberScrollState()),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.lg.dp)
+ ) {
+ Text(
+ text = if (citations.size == 1) {
+ "1 source used in this response"
+ } else {
+ "${citations.size} sources used in this response"
+ },
+ style = EnsuTypography.small,
+ color = EnsuColor.textMuted()
+ )
+
+ citations.forEachIndexed { index, citation ->
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(
+ EnsuColor.fillFaint(),
+ RoundedCornerShape(EnsuCornerRadius.card.dp)
+ )
+ .padding(EnsuSpacing.md.dp),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)
+ ) {
Text(
- text = buildString {
- append(citation.title)
- citation.section?.takeIf { it.isNotBlank() }?.let {
- append(" β€” ").append(it)
- }
- },
+ text = "SOURCE ${index + 1} Β· ${citation.datasetLabel.uppercase()}",
+ style = EnsuTypography.mini,
+ color = EnsuColor.textMuted()
+ )
+ Text(
+ text = citation.title,
style = EnsuTypography.large,
color = EnsuColor.textPrimary()
)
+ citation.section?.trim()?.takeIf { it.isNotEmpty() }?.let { section ->
+ Text(
+ text = section,
+ style = EnsuTypography.small,
+ color = EnsuColor.textMuted()
+ )
+ }
+ HorizontalDivider(color = EnsuColor.border())
Text(
- citation.credit,
- style = EnsuTypography.small,
+ text = "Attribution",
+ style = EnsuTypography.mini,
color = EnsuColor.textMuted()
)
Text(
- citation.licenseLabel,
+ citation.credit,
style = EnsuTypography.small,
- color = EnsuColor.accent(),
- modifier = Modifier.clickable {
+ color = EnsuColor.textPrimary()
+ )
+ Row(horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.lg.dp)) {
+ SourceAttributionLink("Open source β†—") {
+ uriHandler.openUri(citation.sourceUrl)
+ }
+ SourceAttributionLink("${citation.licenseLabel} β†—") {
uriHandler.openUri(citation.licenseUrl)
}
- )
- Text(
- "View source",
- style = EnsuTypography.body,
- color = EnsuColor.accent(),
- modifier = Modifier
- .clickable { uriHandler.openUri(citation.sourceUrl) }
- .padding(top = EnsuSpacing.xs.dp)
- )
+ }
}
}
}
@@ -807,6 +841,18 @@ private fun KnowledgeSourcesDialog(
)
}
+@Composable
+private fun SourceAttributionLink(label: String, onClick: () -> Unit) {
+ Text(
+ text = label,
+ style = EnsuTypography.small,
+ color = EnsuColor.accent(),
+ modifier = Modifier
+ .clickable(onClick = onClick)
+ .padding(vertical = EnsuSpacing.xs.dp)
+ )
+}
+
private data class MessageAction(
val label: String,
val iconRes: Int,
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/HugeIcons.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/HugeIcons.kt
index c9c70c82a9..d28d63c32b 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/HugeIcons.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/designsystem/HugeIcons.kt
@@ -13,6 +13,7 @@ object HugeIcons {
val Edit01Icon = R.drawable.hugeicon_edit01
val Menu01Icon = R.drawable.hugeicon_menu01
val PlusSignIcon = R.drawable.hugeicon_plus_sign
+ val PackageIcon = R.drawable.hugeicon_package
val RepeatIcon = R.drawable.hugeicon_repeat
val Search01Icon = R.drawable.hugeicon_search01
val Settings01Icon = R.drawable.hugeicon_settings01
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/KnowledgeSettingsScreen.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/KnowledgeSettingsScreen.kt
index 130220307f..21eb6e0863 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/KnowledgeSettingsScreen.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/KnowledgeSettingsScreen.kt
@@ -4,21 +4,32 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Info
+import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
@@ -27,6 +38,7 @@ import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuCornerRadius
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
+import io.ente.ensu.format.formatBytes
import io.ente.ensu.knowledge.KnowledgePackState
import io.ente.ensu.knowledge.KnowledgePackStatus
import io.ente.ensu.knowledge.KnowledgeState
@@ -39,18 +51,12 @@ fun KnowledgeSettingsScreen(
onCancel: (String) -> Unit,
onSetEnabled: (String, Boolean) -> Unit
) {
- val uriHandler = LocalUriHandler.current
+ var attributionPack by remember { mutableStateOf<KnowledgePackState?>(null) }
+
LazyColumn(
modifier = Modifier.padding(horizontal = EnsuSpacing.pageHorizontal.dp),
verticalArrangement = Arrangement.spacedBy(EnsuSpacing.md.dp)
) {
- item {
- Text(
- text = "Download public knowledge packs for private, on-device answers. Queries never leave this device.",
- style = EnsuTypography.body,
- color = EnsuColor.textMuted()
- )
- }
items(state.packs.values.toList(), key = { it.config.stableId }) { pack ->
KnowledgePackCard(
pack = pack,
@@ -58,18 +64,17 @@ fun KnowledgeSettingsScreen(
onDownloadOrUpdate = { onDownloadOrUpdate(pack.config.stableId) },
onCancel = { onCancel(pack.config.stableId) },
onSetEnabled = { enabled -> onSetEnabled(pack.config.stableId, enabled) },
- onOpenUrl = uriHandler::openUri
- )
- }
- item {
- Text(
- text = "Wikimedia and Ensu are not affiliated. Wikimedia project names identify the source material only.",
- style = EnsuTypography.small,
- color = EnsuColor.textMuted(),
- modifier = Modifier.padding(vertical = EnsuSpacing.md.dp)
+ onOpenAttribution = { attributionPack = pack }
)
}
}
+
+ attributionPack?.let { pack ->
+ PackAttributionDialog(
+ pack = pack,
+ onDismiss = { attributionPack = null }
+ )
+ }
}
@Composable
@@ -79,9 +84,8 @@ private fun KnowledgePackCard(
onDownloadOrUpdate: () -> Unit,
onCancel: () -> Unit,
onSetEnabled: (Boolean) -> Unit,
- onOpenUrl: (String) -> Unit
+ onOpenAttribution: () -> Unit
) {
- val attribution = pack.config.attribution
Column(
modifier = Modifier
.fillMaxWidth()
@@ -92,23 +96,21 @@ private fun KnowledgePackCard(
.padding(EnsuSpacing.lg.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
- Column(modifier = Modifier.weight(1f)) {
+ Column(
+ modifier = Modifier.weight(1f),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.xs.dp)
+ ) {
Text(pack.config.label, style = EnsuTypography.large, color = EnsuColor.textPrimary())
- Text(
- text = pack.status.label,
- style = EnsuTypography.small,
- color = EnsuColor.textMuted()
- )
- pack.activeIdentity?.let { identity ->
- Text(
- text = "Installed revision: $identity",
- style = EnsuTypography.small,
- color = EnsuColor.textMuted()
- )
- }
+ PackMetadataLine(pack = pack, onOpenAttribution = onOpenAttribution)
}
if (pack.activeIdentity != null && !pack.isMutating) {
Switch(checked = pack.enabled, onCheckedChange = onSetEnabled)
+ } else if (
+ packDownloadsAllowed &&
+ pack.status == KnowledgePackStatus.Download &&
+ !pack.isMutating
+ ) {
+ CompactPackButton(label = "Download", onClick = onDownloadOrUpdate)
}
}
@@ -126,46 +128,138 @@ private fun KnowledgePackCard(
color = EnsuColor.textMuted()
)
TextButton(onClick = onCancel) { Text("Cancel") }
- } else if (
- packDownloadsAllowed &&
- (pack.status == KnowledgePackStatus.Download ||
- pack.status == KnowledgePackStatus.UpdateAvailable)
- ) {
+ } else if (packDownloadsAllowed && pack.status == KnowledgePackStatus.UpdateAvailable) {
Spacer(Modifier.height(EnsuSpacing.md.dp))
- Button(
- onClick = onDownloadOrUpdate,
- colors = ButtonDefaults.buttonColors(containerColor = EnsuColor.accent())
- ) {
- Text(if (pack.status == KnowledgePackStatus.Download) "Download" else "Update")
- }
+ CompactPackButton(label = "Update", onClick = onDownloadOrUpdate)
}
pack.errorMessage?.let {
Text(it, style = EnsuTypography.small, color = EnsuColor.error)
}
- Spacer(Modifier.height(EnsuSpacing.md.dp))
- Text(attribution.credit, style = EnsuTypography.small, color = EnsuColor.textPrimary())
- Text(attribution.buildProvenance, style = EnsuTypography.small, color = EnsuColor.textMuted())
- Text(attribution.modificationNotice, style = EnsuTypography.small, color = EnsuColor.textMuted())
- ActionText(attribution.licenseLabel) { onOpenUrl(attribution.licenseUrl) }
- ActionText("Public pack") { onOpenUrl(attribution.publicPackUrl) }
}
}
-private val KnowledgePackStatus.label: String
- get() = when (this) {
- KnowledgePackStatus.Checking -> "Checking..."
- KnowledgePackStatus.Download -> "Not downloaded"
- KnowledgePackStatus.Ready -> "Ready"
- KnowledgePackStatus.UpdateAvailable -> "Ready Β· update available"
+@Composable
+private fun PackMetadataLine(
+ pack: KnowledgePackState,
+ onOpenAttribution: () -> Unit
+) {
+ val attribution = pack.config.attribution
+ Row(
+ horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.xs.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text(
+ text = formatBytes(pack.config.downloadSizeBytes),
+ style = EnsuTypography.mini,
+ color = EnsuColor.textMuted()
+ )
+ Text("Β·", style = EnsuTypography.mini, color = EnsuColor.textMuted())
+ Row(
+ modifier = Modifier.clickable(onClick = onOpenAttribution),
+ horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.xs.dp),
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text(
+ text = attribution.licenseLabel,
+ style = EnsuTypography.mini,
+ color = EnsuColor.accent()
+ )
+ Icon(
+ imageVector = Icons.Outlined.Info,
+ contentDescription = "View attribution for ${pack.config.label}",
+ tint = EnsuColor.accent(),
+ modifier = Modifier.size(14.dp)
+ )
+ }
+ }
+}
+
+@Composable
+private fun CompactPackButton(label: String, onClick: () -> Unit) {
+ Button(
+ onClick = onClick,
+ colors = ButtonDefaults.buttonColors(containerColor = EnsuColor.accent()),
+ contentPadding = PaddingValues(
+ horizontal = EnsuSpacing.md.dp,
+ vertical = EnsuSpacing.xs.dp
+ )
+ ) {
+ Text(label, style = EnsuTypography.mini)
}
+}
+
+@Composable
+private fun PackAttributionDialog(
+ pack: KnowledgePackState,
+ onDismiss: () -> Unit
+) {
+ val attribution = pack.config.attribution
+ val uriHandler = LocalUriHandler.current
+
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = { Text("Attribution", style = EnsuTypography.h3) },
+ text = {
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(
+ EnsuColor.fillFaint(),
+ RoundedCornerShape(EnsuCornerRadius.card.dp)
+ )
+ .padding(EnsuSpacing.md.dp),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)
+ ) {
+ Text(
+ text = pack.config.label,
+ style = EnsuTypography.large,
+ color = EnsuColor.textPrimary()
+ )
+ HorizontalDivider(color = EnsuColor.border())
+ Text(
+ text = "From ${attribution.credit}",
+ style = EnsuTypography.small,
+ color = EnsuColor.textPrimary()
+ )
+ Text(
+ text = attribution.modificationNotice,
+ style = EnsuTypography.small,
+ color = EnsuColor.textPrimary()
+ )
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(EnsuSpacing.md.dp)
+ ) {
+ AttributionLink("Source β†—") {
+ uriHandler.openUri(attribution.publicPackUrl)
+ }
+ AttributionLink("License β†—") {
+ uriHandler.openUri(attribution.licenseUrl)
+ }
+ }
+ HorizontalDivider(color = EnsuColor.border())
+ Text(
+ text = "Wikimedia and Ensu are not affiliated. Wikimedia project names identify the source material only.",
+ style = EnsuTypography.small,
+ color = EnsuColor.textMuted()
+ )
+ }
+ },
+ confirmButton = {
+ TextButton(onClick = onDismiss) { Text("Done") }
+ },
+ containerColor = EnsuColor.backgroundBase()
+ )
+}
@Composable
-private fun ActionText(label: String, onClick: () -> Unit) {
+private fun AttributionLink(label: String, onClick: () -> Unit) {
Text(
text = label,
- style = EnsuTypography.small,
+ style = EnsuTypography.mini,
color = EnsuColor.accent(),
+ maxLines = 1,
modifier = Modifier
.clickable(onClick = onClick)
.padding(vertical = EnsuSpacing.xs.dp)
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt
index 962378cc99..6759490017 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt
@@ -49,6 +49,7 @@ fun SettingsScreen(
isAdvancedUnlocked: Boolean,
onOpenLogs: () -> Unit,
onOpenKnowledge: () -> Unit,
+ onOpenTerms: () -> Unit,
onOpenModelSettings: () -> Unit,
onOpenSystemPromptSettings: () -> Unit,
onUnlockAdvanced: () -> Unit,
@@ -59,19 +60,19 @@ fun SettingsScreen(
var lastBuildVersionTapAt by remember { mutableStateOf<Long?>(null) }
val context = LocalContext.current
- val allItems = remember(context, onOpenLogs, onOpenKnowledge, onSignIn) {
+ val allItems = remember(context, onOpenLogs, onOpenKnowledge, onOpenTerms, onSignIn) {
buildList {
add(
SettingsItem(
- title = "Knowledge",
- iconRes = HugeIcons.Search01Icon,
+ title = "Ensu Packs",
+ iconRes = HugeIcons.PackageIcon,
onClick = onOpenKnowledge
)
)
add(
SettingsItem(
- title = "About",
+ title = "About Ensu",
iconVector = Icons.Outlined.Info,
onClick = { context.openExternalLink("https://ente.com/blog/ensu/") }
)
@@ -95,16 +96,14 @@ fun SettingsScreen(
add(
SettingsItem(
- title = "Privacy Policy",
- iconRes = HugeIcons.ViewIcon,
- onClick = { context.openExternalLink("https://ente.com/privacy") }
- )
- )
- add(
- SettingsItem(
- title = "Terms of Service",
+ title = "Terms and Conditions",
iconVector = Icons.Outlined.Description,
- onClick = { context.openExternalLink("https://ente.com/terms") }
+ searchTerms = listOf(
+ "Privacy Policy",
+ "Ente Terms and Conditions",
+ "Terms of Service"
+ ),
+ onClick = onOpenTerms
)
)
}
@@ -114,7 +113,8 @@ fun SettingsScreen(
val q = query.trim().lowercase()
if (q.isEmpty()) return@remember allItems
allItems.filter { item ->
- item.title.lowercase().contains(q)
+ item.title.lowercase().contains(q) ||
+ item.searchTerms.any { it.lowercase().contains(q) }
}
}
@@ -206,16 +206,17 @@ fun SettingsScreen(
}
}
-private data class SettingsItem(
+internal data class SettingsItem(
val title: String,
val iconRes: Int? = null,
val iconVector: ImageVector? = null,
+ val searchTerms: List<String> = emptyList(),
val onClick: () -> Unit,
val isDestructive: Boolean = false
)
@Composable
-private fun SettingsRow(item: SettingsItem) {
+internal fun SettingsRow(item: SettingsItem) {
val iconAndTextColor = if (item.isDestructive) EnsuColor.error else EnsuColor.textPrimary()
Row(
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/TermsAndConditionsScreen.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/TermsAndConditionsScreen.kt
new file mode 100644
index 0000000000..e2c137362f
--- /dev/null
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/TermsAndConditionsScreen.kt
@@ -0,0 +1,44 @@
+package io.ente.ensu.settings
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.outlined.Description
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalUriHandler
+import androidx.compose.ui.unit.dp
+import io.ente.ensu.designsystem.EnsuSpacing
+import io.ente.ensu.designsystem.HugeIcons
+
+@Composable
+fun TermsAndConditionsScreen() {
+ val uriHandler = LocalUriHandler.current
+
+ LazyColumn(
+ modifier = Modifier.padding(horizontal = EnsuSpacing.pageHorizontal.dp),
+ contentPadding = PaddingValues(vertical = EnsuSpacing.lg.dp),
+ verticalArrangement = Arrangement.spacedBy(EnsuSpacing.sm.dp)
+ ) {
+ item(key = "privacy") {
+ SettingsRow(
+ SettingsItem(
+ title = "Privacy Policy",
+ iconRes = HugeIcons.ViewIcon,
+ onClick = { uriHandler.openUri("https://ente.com/privacy/") }
+ )
+ )
+ }
+ item(key = "ente-terms") {
+ SettingsRow(
+ SettingsItem(
+ title = "Ente Terms and Conditions",
+ iconVector = Icons.Outlined.Description,
+ onClick = { uriHandler.openUri("https://ente.com/terms/") }
+ )
+ )
+ }
+ }
+}
diff --git a/mobile/native/android/apps/ensu/app/src/main/res/drawable/hugeicon_package.xml b/mobile/native/android/apps/ensu/app/src/main/res/drawable/hugeicon_package.xml
new file mode 100644
index 0000000000..cbfdce87a2
--- /dev/null
+++ b/mobile/native/android/apps/ensu/app/src/main/res/drawable/hugeicon_package.xml
@@ -0,0 +1,27 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#00000000"
+ android:strokeColor="#FF000000"
+ android:strokeWidth="2"
+ android:strokeLineCap="round"
+ android:strokeLineJoin="round"
+ android:pathData="M4,7 L12,3 L20,7 L12,11 Z" />
+ <path
+ android:fillColor="#00000000"
+ android:strokeColor="#FF000000"
+ android:strokeWidth="2"
+ android:strokeLineCap="round"
+ android:strokeLineJoin="round"
+ android:pathData="M4,7 L4,17 L12,21 L20,17 L20,7" />
+ <path
+ android:fillColor="#00000000"
+ android:strokeColor="#FF000000"
+ android:strokeWidth="2"
+ android:strokeLineCap="round"
+ android:strokeLineJoin="round"
+ android:pathData="M12,11 L12,21" />
+</vector>
diff --git a/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/Contents.json b/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/Contents.json
new file mode 100644
index 0000000000..4eba8db189
--- /dev/null
+++ b/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/Contents.json
@@ -0,0 +1,16 @@
+{
+ "images" : [
+ {
+ "filename" : "PackageIcon.svg",
+ "idiom" : "universal"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ },
+ "properties" : {
+ "preserves-vector-representation" : true,
+ "template-rendering-intent" : "template"
+ }
+}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/PackageIcon.svg b/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/PackageIcon.svg
new file mode 100644
index 0000000000..8512b66a41
--- /dev/null
+++ b/mobile/native/apple/apps/ensu/Ensu/Assets.xcassets/PackageIcon.imageset/PackageIcon.svg
@@ -0,0 +1,5 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path d="M4 7L12 3L20 7L12 11L4 7Z" stroke-linecap="round" stroke-linejoin="round" />
+ <path d="M4 7V17L12 21L20 17V7" stroke-linecap="round" stroke-linejoin="round" />
+ <path d="M12 11V21" stroke-linecap="round" stroke-linejoin="round" />
+</svg>
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
index 47794fb02d..a8235e53dd 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/Components/ChatViewComponents.swift
@@ -10,52 +10,55 @@ struct DownloadOnboardingView: View {
let onDownload: () -> Void
var body: some View {
- VStack(spacing: EnsuSpacing.md) {
- Text("Download models to begin using Chat")
- .font(EnsuTypography.large)
- .foregroundStyle(EnsuColor.textPrimary)
- .multilineTextAlignment(.center)
-
- if isDownloading {
- let statusLine: String = {
- if let statusText, isLoadingModel {
- return statusText
- }
- if let totalBytes, let percent = downloadPercent {
- let clamped = min(max(percent, 0), 100)
- let downloaded = Int64(Double(totalBytes) * Double(clamped) / 100.0)
- return "Downloading... \(downloaded.formattedFileSize) / \(totalBytes.formattedFileSize)"
- }
- if let statusText, !statusText.isEmpty {
- return statusText
- }
- return "Downloading..."
- }()
+ VStack(spacing: 0) {
+ VStack(spacing: EnsuSpacing.md) {
+ Text("Download models to begin using Chat")
+ .font(EnsuTypography.large)
+ .foregroundStyle(EnsuColor.textPrimary)
+ .multilineTextAlignment(.center)
- StableDownloadStatusText(
- text: statusLine,
- font: EnsuTypography.body,
- color: EnsuColor.textMuted
- )
+ if isDownloading {
+ let statusLine: String = {
+ if let statusText, isLoadingModel {
+ return statusText
+ }
+ if let totalBytes, let percent = downloadPercent {
+ let clamped = min(max(percent, 0), 100)
+ let downloaded = Int64(Double(totalBytes) * Double(clamped) / 100.0)
+ return "Downloading... \(downloaded.formattedFileSize) / \(totalBytes.formattedFileSize)"
+ }
+ if let statusText, !statusText.isEmpty {
+ return statusText
+ }
+ return "Downloading..."
+ }()
- progressView
- } else {
- Button("Download models") {
- hapticMedium()
- onDownload()
- }
- .font(EnsuTypography.body)
- .foregroundStyle(Color.black)
- .frame(maxWidth: 200)
- .padding(.vertical, EnsuSpacing.md)
- .background(EnsuColor.accent)
- .clipShape(RoundedRectangle(cornerRadius: EnsuCornerRadius.button))
+ StableDownloadStatusText(
+ text: statusLine,
+ font: EnsuTypography.body,
+ color: EnsuColor.textMuted
+ )
- Text(sizeText)
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
+ progressView
+ } else {
+ Button("Download") {
+ hapticMedium()
+ onDownload()
+ }
+ .font(EnsuTypography.body)
+ .foregroundStyle(Color.black)
+ .frame(maxWidth: 200)
+ .padding(.vertical, EnsuSpacing.md)
+ .background(EnsuColor.accent)
+ .clipShape(RoundedRectangle(cornerRadius: EnsuCornerRadius.button))
+ Text(sizeText)
+ .font(EnsuTypography.small)
+ .foregroundStyle(EnsuColor.textMuted)
+ }
}
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, EnsuSpacing.pageHorizontal)
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
index e3e84c4ecc..4da0308c9a 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift
@@ -331,24 +331,55 @@ private struct KnowledgeSourcesSheet: View {
NavigationStack {
ScrollView {
VStack(alignment: .leading, spacing: EnsuSpacing.lg) {
- ForEach(Array(citations.enumerated()), id: \.offset) { _, citation in
- VStack(alignment: .leading, spacing: EnsuSpacing.xs) {
- Text(citationTitle(citation))
+ Text(sourceCountLabel)
+ .font(EnsuTypography.small)
+ .foregroundStyle(EnsuColor.textMuted)
+
+ ForEach(Array(citations.enumerated()), id: \.offset) { index, citation in
+ VStack(alignment: .leading, spacing: EnsuSpacing.sm) {
+ Text("SOURCE \(index + 1) Β· \(citation.datasetLabel.uppercased())")
+ .font(EnsuTypography.mini)
+ .foregroundStyle(EnsuColor.textMuted)
+
+ Text(citation.title)
.font(EnsuTypography.large)
.foregroundStyle(EnsuColor.textPrimary)
+
+ if let section = citationSection(citation) {
+ Text(section)
+ .font(EnsuTypography.small)
+ .foregroundStyle(EnsuColor.textMuted)
+ }
+
+ Divider()
+
+ Text("Attribution")
+ .font(EnsuTypography.mini)
+ .foregroundStyle(EnsuColor.textMuted)
+
Text(citation.credit)
.font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
- Link(
- citation.licenseLabel,
- destination: URL(string: citation.licenseUrl)!
- )
- Link(
- "View source",
- destination: URL(string: citation.sourceUrl)!
- )
+ .foregroundStyle(EnsuColor.textPrimary)
+
+ HStack(spacing: EnsuSpacing.lg) {
+ Link(destination: URL(string: citation.sourceUrl)!) {
+ Label("Open source", systemImage: "arrow.up.right.square")
+ }
+ Link(destination: URL(string: citation.licenseUrl)!) {
+ Label(citation.licenseLabel, systemImage: "doc.text")
+ }
+ }
+ .font(EnsuTypography.small)
}
+ .padding(EnsuSpacing.md)
.frame(maxWidth: .infinity, alignment: .leading)
+ .background(EnsuColor.fillFaint)
+ .clipShape(
+ RoundedRectangle(
+ cornerRadius: EnsuCornerRadius.card,
+ style: .continuous
+ )
+ )
}
}
.padding(EnsuSpacing.lg)
@@ -362,14 +393,24 @@ private struct KnowledgeSourcesSheet: View {
}
}
}
+ .presentationDetents([.medium, .large])
+ .presentationDragIndicator(.visible)
}
- private func citationTitle(_ citation: SourceCitation) -> String {
- guard let section = citation.section?.trimmingCharacters(in: .whitespacesAndNewlines),
- !section.isEmpty else {
- return citation.title
- }
- return "\(citation.title) β€” \(section)"
+ private var sourceCountLabel: String {
+ citations.count == 1
+ ? "1 source used in this response"
+ : "\(citations.count) sources used in this response"
+ }
+
+ private func citationSection(_ citation: SourceCitation) -> String? {
+ citation.section?.trimmingCharacters(in: .whitespacesAndNewlines).nilIfEmpty
+ }
+}
+
+private extension String {
+ var nilIfEmpty: String? {
+ isEmpty ? nil : self
}
}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/KnowledgeSettingsView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/KnowledgeSettingsView.swift
index 3f37ae12cd..ca21871980 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Settings/KnowledgeSettingsView.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/KnowledgeSettingsView.swift
@@ -5,29 +5,23 @@ struct KnowledgeSettingsView: View {
let onDownloadOrUpdate: (String) -> Void
let onCancel: (String) -> Void
let onSetEnabled: (String, Bool) -> Void
+ @State private var attributionPack: KnowledgePackState?
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: EnsuSpacing.md) {
- Text("Download public knowledge packs for private, on-device answers. Queries never leave this device.")
- .font(EnsuTypography.body)
- .foregroundStyle(EnsuColor.textMuted)
-
ForEach(state.packs) { pack in
packCard(pack)
}
-
- Text("Wikimedia and Ensu are not affiliated. Wikimedia project names identify the source material only.")
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
- .padding(.vertical, EnsuSpacing.md)
-
}
.padding(EnsuSpacing.lg)
}
.background(EnsuColor.backgroundBase)
- .navigationTitle("Knowledge")
+ .navigationTitle("Ensu Packs")
.navigationBarTitleDisplayMode(.inline)
+ .sheet(item: $attributionPack) { pack in
+ PackAttributionSheet(config: pack.config)
+ }
}
@ViewBuilder
@@ -39,13 +33,26 @@ struct KnowledgeSettingsView: View {
Text(pack.config.label)
.font(EnsuTypography.large)
.foregroundStyle(EnsuColor.textPrimary)
- Text(pack.status.label)
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
- if let activeIdentity = pack.activeIdentity {
- Text("Installed revision: \(activeIdentity)")
- .font(EnsuTypography.small)
+ HStack(spacing: EnsuSpacing.xs) {
+ Text(pack.config.downloadSizeBytes.formattedFileSize)
+ .font(EnsuTypography.mini)
.foregroundStyle(EnsuColor.textMuted)
+ Text("Β·")
+ .font(EnsuTypography.mini)
+ .foregroundStyle(EnsuColor.textMuted)
+ Button {
+ attributionPack = pack
+ } label: {
+ HStack(spacing: EnsuSpacing.xs) {
+ Text(attribution.licenseLabel)
+ .font(EnsuTypography.mini)
+ Image(systemName: "info.circle")
+ .font(.system(size: 12, weight: .medium))
+ }
+ .foregroundStyle(EnsuColor.accent)
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel("View attribution for \(pack.config.label)")
}
}
Spacer()
@@ -58,6 +65,17 @@ struct KnowledgeSettingsView: View {
)
)
.labelsHidden()
+ } else if state.downloadsAllowed && pack.status == .download && !pack.isMutating {
+ Button {
+ onDownloadOrUpdate(pack.id)
+ } label: {
+ Text("Download")
+ .font(EnsuTypography.small)
+ .padding(.horizontal, EnsuSpacing.xs)
+ }
+ .buttonStyle(.borderedProminent)
+ .controlSize(.small)
+ .tint(EnsuColor.accent)
}
}
@@ -70,12 +88,16 @@ struct KnowledgeSettingsView: View {
Button("Cancel") {
onCancel(pack.id)
}
- } else if state.downloadsAllowed &&
- (pack.status == .download || pack.status == .updateAvailable) {
- Button(pack.status == .download ? "Download" : "Update") {
+ } else if state.downloadsAllowed && pack.status == .updateAvailable {
+ Button {
onDownloadOrUpdate(pack.id)
+ } label: {
+ Text("Update")
+ .font(EnsuTypography.small)
+ .padding(.horizontal, EnsuSpacing.xs)
}
.buttonStyle(.borderedProminent)
+ .controlSize(.small)
.tint(EnsuColor.accent)
}
@@ -84,18 +106,6 @@ struct KnowledgeSettingsView: View {
.font(EnsuTypography.small)
.foregroundStyle(.red)
}
-
- Divider()
- Text(attribution.credit)
- .font(EnsuTypography.small)
- Text(attribution.buildProvenance)
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
- Text(attribution.modificationNotice)
- .font(EnsuTypography.small)
- .foregroundStyle(EnsuColor.textMuted)
- Link(attribution.licenseLabel, destination: URL(string: attribution.licenseUrl)!)
- Link("Public pack", destination: URL(string: attribution.publicPackUrl)!)
}
.padding(EnsuSpacing.lg)
.frame(maxWidth: .infinity, alignment: .leading)
@@ -103,14 +113,3 @@ struct KnowledgeSettingsView: View {
.clipShape(RoundedRectangle(cornerRadius: EnsuCornerRadius.card, style: .continuous))
}
}
-
-private extension KnowledgePackStatus {
- var label: String {
- switch self {
- case .checking: "Checking..."
- case .download: "Not downloaded"
- case .ready: "Ready"
- case .updateAvailable: "Ready Β· update available"
- }
- }
-}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/PackAttributionView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/PackAttributionView.swift
new file mode 100644
index 0000000000..abe5d3c6ad
--- /dev/null
+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/PackAttributionView.swift
@@ -0,0 +1,68 @@
+import SwiftUI
+
+struct PackAttributionSheet: View {
+ let config: KnowledgeDatasetConfig
+ @Environment(\.dismiss) private var dismiss
+
+ var body: some View {
+ let attribution = config.attribution
+ NavigationStack {
+ ScrollView {
+ VStack(alignment: .leading, spacing: EnsuSpacing.sm) {
+ Text(config.label)
+ .font(EnsuTypography.large)
+ .foregroundStyle(EnsuColor.textPrimary)
+
+ Divider()
+
+ Text("From \(attribution.credit)")
+ .font(EnsuTypography.body)
+ .foregroundStyle(EnsuColor.textPrimary)
+
+ Text(attribution.modificationNotice)
+ .font(EnsuTypography.body)
+ .foregroundStyle(EnsuColor.textPrimary)
+
+ HStack(spacing: EnsuSpacing.md) {
+ Link(destination: URL(string: attribution.publicPackUrl)!) {
+ Label("Source", systemImage: "arrow.up.right.square")
+ }
+ Link(destination: URL(string: attribution.licenseUrl)!) {
+ Label("License", systemImage: "doc.text")
+ }
+ }
+ .font(EnsuTypography.mini)
+ .lineLimit(1)
+ .frame(maxWidth: .infinity, alignment: .leading)
+
+ Divider()
+
+ Text("Wikimedia and Ensu are not affiliated. Wikimedia project names identify the source material only.")
+ .font(EnsuTypography.small)
+ .foregroundStyle(EnsuColor.textMuted)
+ }
+ .padding(EnsuSpacing.md)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(EnsuColor.fillFaint)
+ .clipShape(
+ RoundedRectangle(
+ cornerRadius: EnsuCornerRadius.card,
+ style: .continuous
+ )
+ )
+ .padding(EnsuSpacing.lg)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+ .background(EnsuColor.backgroundBase)
+ .navigationTitle("Attribution")
+ .navigationBarTitleDisplayMode(.inline)
+ .toolbar {
+ ToolbarItem(placement: .primaryAction) {
+ Button("Done") { dismiss() }
+ }
+ }
+ }
+ .presentationDetents([.medium, .large])
+ .presentationDragIndicator(.visible)
+ }
+}
diff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift
index 33a3d9fbc5..fc6b5d6630 100644
--- a/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift
+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift
@@ -22,32 +22,43 @@ struct SettingsView: View {
NavigationStack {
ScrollView {
VStack(alignment: .leading, spacing: EnsuSpacing.lg) {
+ ForEach(filteredItems) { item in
+ NavigationLink {
+ item.destination
+ } label: {
+ SettingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
+ }
+ .buttonStyle(.plain)
+ }
+
if let aboutItem = filteredAboutItem {
Button(action: aboutItem.action) {
- settingsCard(title: aboutItem.title, iconName: aboutItem.iconName, showsChevron: true)
+ SettingsCard(title: aboutItem.title, iconName: aboutItem.iconName, showsChevron: true)
}
.buttonStyle(.plain)
}
- ForEach(filteredItems) { item in
+ ForEach(filteredUtilityItems) { item in
NavigationLink {
item.destination
} label: {
- settingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
+ SettingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
}
.buttonStyle(.plain)
}
if shouldShowSignInRow {
Button(action: onSignIn) {
- settingsCard(title: signInTitle, iconName: "Upload01Icon", showsChevron: true)
+ SettingsCard(title: signInTitle, iconName: "Upload01Icon", showsChevron: true)
}
.buttonStyle(.plain)
}
- ForEach(filteredLegalLinkItems) { item in
- Button(action: item.action) {
- settingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
+ ForEach(filteredTermsItems) { item in
+ NavigationLink {
+ item.destination
+ } label: {
+ SettingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
}
.buttonStyle(.plain)
}
@@ -62,7 +73,7 @@ struct SettingsView: View {
NavigationLink {
item.destination
} label: {
- settingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
+ SettingsCard(title: item.title, iconName: item.iconName, showsChevron: true)
}
.buttonStyle(.plain)
}
@@ -104,59 +115,36 @@ struct SettingsView: View {
}
private var filteredItems: [SettingsItem] {
- guard !trimmedQuery.isEmpty else { return allItems }
- let q = trimmedQuery.lowercased()
- return allItems.filter { item in
- item.title.lowercased().contains(q)
- }
+ filtered(allItems)
+ }
+
+ private var filteredUtilityItems: [SettingsItem] {
+ filtered(utilityItems)
+ }
+
+ private var filteredTermsItems: [SettingsItem] {
+ filtered(termsItems)
}
private var filteredAdvancedItems: [SettingsItem] {
guard isAdvancedUnlocked else { return [] }
- guard !trimmedQuery.isEmpty else { return advancedItems }
- let q = trimmedQuery.lowercased()
- return advancedItems.filter { item in
- item.title.lowercased().contains(q)
- }
+ return filtered(advancedItems)
}
private var aboutItem: SettingsActionItem {
SettingsActionItem(
- title: "About",
+ title: "About Ensu",
iconName: "InformationCircleIcon",
action: { openExternalLink("https://ente.com/blog/ensu/") }
)
}
- private var legalLinkItems: [SettingsActionItem] {
- [
- SettingsActionItem(
- title: "Privacy Policy",
- iconName: "ViewIcon",
- action: { openExternalLink("https://ente.com/privacy") }
- ),
- SettingsActionItem(
- title: "Terms of Service",
- iconName: "DescriptionIcon",
- action: { openExternalLink("https://ente.com/terms") }
- )
- ]
- }
-
private var filteredAboutItem: SettingsActionItem? {
guard !trimmedQuery.isEmpty else { return aboutItem }
let q = trimmedQuery.lowercased()
return aboutItem.title.lowercased().contains(q) ? aboutItem : nil
}
- private var filteredLegalLinkItems: [SettingsActionItem] {
- guard !trimmedQuery.isEmpty else { return legalLinkItems }
- let q = trimmedQuery.lowercased()
- return legalLinkItems.filter { item in
- item.title.lowercased().contains(q)
- }
- }
-
private var shouldShowSignInRow: Bool {
guard !trimmedQuery.isEmpty else { return true }
let q = trimmedQuery.lowercased()
@@ -168,8 +156,8 @@ struct SettingsView: View {
private var allItems: [SettingsItem] {
[
SettingsItem(
- title: "Knowledge",
- iconName: "Search01Icon",
+ title: "Ensu Packs",
+ iconName: "PackageIcon",
destination: AnyView(
KnowledgeSettingsView(
state: knowledgeState,
@@ -178,7 +166,12 @@ struct SettingsView: View {
onSetEnabled: onSetKnowledgePackEnabled
)
)
- ),
+ )
+ ]
+ }
+
+ private var utilityItems: [SettingsItem] {
+ [
SettingsItem(
title: "Logs",
iconName: "Bug01Icon",
@@ -187,6 +180,27 @@ struct SettingsView: View {
]
}
+ private var termsItems: [SettingsItem] {
+ [
+ SettingsItem(
+ title: "Terms and Conditions",
+ iconName: "DescriptionIcon",
+ destination: AnyView(TermsAndConditionsView()),
+ searchTerms: [
+ "Privacy Policy",
+ "Ente Terms and Conditions",
+ "Terms of Service"
+ ]
+ )
+ ]
+ }
+
+ private func filtered(_ items: [SettingsItem]) -> [SettingsItem] {
+ guard !trimmedQuery.isEmpty else { return items }
+ let q = trimmedQuery.lowercased()
+ return items.filter { $0.matches(q) }
+ }
+
private var advancedItems: [SettingsItem] {
[
SettingsItem(
@@ -239,8 +253,14 @@ struct SettingsView: View {
guard let url = URL(string: urlString) else { return }
openURL(url)
}
+}
- private func settingsCard(title: String, iconName: String, showsChevron: Bool) -> some View {
+struct SettingsCard: View {
+ let title: String
+ let iconName: String
+ let showsChevron: Bool
+
+ var body: some View {
HStack(spacing: EnsuSpacing.md) {
Image(iconName)
.resizable()
@@ -402,6 +422,24 @@ private struct SettingsItem: Identifiable {
let title: String
let iconName: String
let destination: AnyView
+ let searchTerms: [String]
+
+ init(
+ title: String,
+ iconName: String,
+ destination: AnyView,
+ searchTerms: [String] = []
+ ) {
+ self.title = title
+ self.iconName = iconName
+ self.destination = destination
+ self.searchTerms = searchTerms
+ }
+
+ func matches(_ query: String) -> Bool {
+ title.lowercased().contains(query) ||
+ searchTerms.contains { $0.lowercased().contains(query) }
+ }
}
private struct SettingsActionItem: Identifiable {
diff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/TermsAndConditionsView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/TermsAndConditionsView.swift
new file mode 100644
index 0000000000..ab76818a7f
--- /dev/null
+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/TermsAndConditionsView.swift
@@ -0,0 +1,27 @@
+import SwiftUI
+
+struct TermsAndConditionsView: View {
+ var body: some View {
+ ScrollView {
+ VStack(alignment: .leading, spacing: EnsuSpacing.lg) {
+ Link(destination: URL(string: "https://ente.com/privacy/")!) {
+ SettingsCard(title: "Privacy Policy", iconName: "ViewIcon", showsChevron: true)
+ }
+ .buttonStyle(.plain)
+
+ Link(destination: URL(string: "https://ente.com/terms/")!) {
+ SettingsCard(
+ title: "Ente Terms and Conditions",
+ iconName: "DescriptionIcon",
+ showsChevron: true
+ )
+ }
+ .buttonStyle(.plain)
+ }
+ .padding(EnsuSpacing.lg)
+ }
+ .background(EnsuColor.backgroundBase)
+ .navigationTitle("Terms and Conditions")
+ .navigationBarTitleDisplayMode(.inline)
+ }
+}
diff --git a/rust/bindings/uniffi/ensu/src/config.rs b/rust/bindings/uniffi/ensu/src/config.rs
index bce57b80cc..c0bad5a7ef 100644
--- a/rust/bindings/uniffi/ensu/src/config.rs
+++ b/rust/bindings/uniffi/ensu/src/config.rs
@@ -40,6 +40,7 @@ pub struct KnowledgeDatasetConfig {
pub label: String,
pub current_download_identity: String,
pub artifact_base_url: String,
+ pub download_size_bytes: i64,
pub max_chars: u32,
pub source_url_template: String,
pub relevance_threshold: f32,
@@ -125,6 +126,7 @@ impl From<config::KnowledgeDatasetConfig> for KnowledgeDatasetConfig {
label: value.label,
current_download_identity: value.current_download_identity,
artifact_base_url: value.artifact_base_url,
+ download_size_bytes: value.download_size_bytes,
max_chars: value.max_chars,
source_url_template: value.source_url_template,
relevance_threshold: value.relevance_threshold,
@@ -140,6 +142,7 @@ impl From<KnowledgeDatasetConfig> for config::KnowledgeDatasetConfig {
label: value.label,
current_download_identity: value.current_download_identity,
artifact_base_url: value.artifact_base_url,
+ download_size_bytes: value.download_size_bytes,
max_chars: value.max_chars,
source_url_template: value.source_url_template,
relevance_threshold: value.relevance_threshold,
diff --git a/rust/crates/ensu/src/config/knowledge.rs b/rust/crates/ensu/src/config/knowledge.rs
index c9d9ee4b53..271d907b05 100644
--- a/rust/crates/ensu/src/config/knowledge.rs
+++ b/rust/crates/ensu/src/config/knowledge.rs
@@ -16,7 +16,7 @@ const MAX_HITS: u32 = 3;
const MAX_CONTEXT_UTF8_BYTES: u32 = 6_000;
pub(crate) const KNOWLEDGE_LICENSE_LABEL: &str = "CC BY-SA 4.0";
pub(crate) const KNOWLEDGE_LICENSE_URL: &str = "https://creativecommons.org/licenses/by-sa/4.0/";
-const MODIFICATION_NOTICE: &str = "Selected, cleaned, excerpted, chunked, and embedded by Ente";
+const MODIFICATION_NOTICE: &str = "Adapted by Ente";
const MAX_DATASETS: usize = 32;
const MAX_PATH_COMPONENT_BYTES: usize = 96;
const MAX_DISPLAY_BYTES: usize = 256;
@@ -58,6 +58,7 @@ pub struct KnowledgeDatasetConfig {
pub label: String,
pub current_download_identity: String,
pub artifact_base_url: String,
+ pub download_size_bytes: i64,
pub max_chars: u32,
pub source_url_template: String,
pub relevance_threshold: f32,
@@ -128,6 +129,7 @@ pub(super) fn knowledge_datasets() -> Vec<KnowledgeDatasetConfig> {
label: "Simple English Wikipedia".to_owned(),
current_download_identity: "simplewiki-2026-07-02".to_owned(),
artifact_base_url: "https://huggingface.co/datasets/ente-ai/ensu-knowledge-packs/resolve/a13b90e443dcdc1561ac777ea17ee6ed4703e35f/simplewiki/data/".to_owned(),
+ download_size_bytes: 167_849_446,
max_chars: 600,
source_url_template: "https://simple.wikipedia.org/wiki/{title}".to_owned(),
relevance_threshold: 0.46,
@@ -145,6 +147,7 @@ pub(super) fn knowledge_datasets() -> Vec<KnowledgeDatasetConfig> {
label: "Wikibooks".to_owned(),
current_download_identity: "enwikibooks-2026-07-02".to_owned(),
artifact_base_url: "https://huggingface.co/datasets/ente-ai/ensu-knowledge-packs/resolve/a13b90e443dcdc1561ac777ea17ee6ed4703e35f/wikibooks/data/".to_owned(),
+ download_size_bytes: 202_595_475,
max_chars: 1_400,
source_url_template: "https://en.wikibooks.org/wiki/{title}".to_owned(),
relevance_threshold: 0.50,
@@ -205,6 +208,12 @@ pub fn validate_knowledge_datasets(
&dataset.artifact_base_url,
&format!("{prefix}.artifact_base_url"),
)?;
+ if dataset.download_size_bytes <= 0 {
+ return Err(KnowledgeConfigError::invalid(
+ &format!("{prefix}.download_size_bytes"),
+ "must be greater than zero",
+ ));
+ }
validate_source_url_template(
&dataset.source_url_template,
&format!("{prefix}.source_url_template"),
@@ -465,6 +474,13 @@ mod tests {
assert_eq!(datasets[0].stable_id, "simplewiki");
assert_eq!(datasets[1].stable_id, "wikibooks");
+ assert!(
+ datasets
+ .iter()
+ .all(|dataset| dataset.attribution.modification_notice == "Adapted by Ente")
+ );
+ assert_eq!(datasets[0].download_size_bytes, 167_849_446);
+ assert_eq!(datasets[1].download_size_bytes, 202_595_475);
assert_eq!(knowledge_index_contract().source_dim, 768);
assert_eq!(knowledge_index_contract().dim, 512);
}
@@ -546,6 +562,12 @@ mod tests {
datasets[0].max_chars = 4_097;
assert!(validate_knowledge_datasets(&datasets).is_err());
+ let mut datasets = valid_datasets();
+ datasets[0].download_size_bytes = 0;
+ assert!(validate_knowledge_datasets(&datasets).is_err());
+ datasets[0].download_size_bytes = -1;
+ assert!(validate_knowledge_datasets(&datasets).is_err());
+
let mut datasets = valid_datasets();
datasets[0].relevance_threshold = f32::NAN;
assert!(validate_knowledge_datasets(&datasets).is_err());