Skip to content

Commit db94ee6

Browse files
committed
chore: formatting
1 parent 3dc02a0 commit db94ee6

18 files changed

Lines changed: 223 additions & 108 deletions

app/src/main/kotlin/me/nanova/summaryexpressive/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class MainActivity : ComponentActivity() {
7676
viewModel.onEvent(AppStartAction(content))
7777
}
7878
}
79+
7980
Intent.ACTION_VIEW -> {
8081
if (intent.data?.host != "clipboard") return
8182
// To avoid re-triggering on configuration change, we clear the data.

app/src/main/kotlin/me/nanova/summaryexpressive/data/AIProviderConfigDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface AIProviderConfigDao {
1616

1717
@Query("SELECT * FROM ai_provider_config")
1818
fun getAllConfigsFlow(): Flow<List<AIProviderConfigEntity>>
19-
19+
2020
@Query("SELECT * FROM ai_provider_config")
2121
suspend fun getAllConfigs(): List<AIProviderConfigEntity>
2222

app/src/main/kotlin/me/nanova/summaryexpressive/data/repository/UserPreferencesRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ open class UserPreferencesRepository @Inject constructor(
4444
open suspend fun setIsOnboarded(value: Boolean) =
4545
updatePreferences { it.copy(isOnboarded = value) }
4646

47-
open suspend fun setShowLength(value: Boolean) = updatePreferences { it.copy(showLength = value) }
47+
open suspend fun setShowLength(value: Boolean) =
48+
updatePreferences { it.copy(showLength = value) }
4849

4950
open suspend fun setSummaryLength(value: String) =
5051
updatePreferences { it.copy(summaryLength = value) }

app/src/main/kotlin/me/nanova/summaryexpressive/exception/SummaryException.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ sealed class SummaryException(message: String) : Exception(message) {
8282
ignoreCase = true
8383
) -> NoContentException()
8484

85-
message.contains("Unsupported file type", ignoreCase = true) -> InvalidLinkException()
85+
message.contains(
86+
"Unsupported file type",
87+
ignoreCase = true
88+
) -> InvalidLinkException()
89+
8690
message.contains(
8791
"Extracted text from file is empty",
8892
ignoreCase = true

app/src/main/kotlin/me/nanova/summaryexpressive/llm/GeminiSanitizingHttpClientEngine.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import kotlin.coroutines.CoroutineContext
3333
*/
3434
@OptIn(InternalAPI::class)
3535
class GeminiSanitizingHttpClientEngine(
36-
private val delegate: HttpClientEngine
36+
private val delegate: HttpClientEngine,
3737
) : HttpClientEngineBase("gemini-sanitizing-engine") {
3838

3939
override val config: HttpClientEngineConfig = delegate.config
@@ -55,11 +55,13 @@ class GeminiSanitizingHttpClientEngine(
5555
val sanitized = sanitizeGeminiRequestBody(original)
5656
val bytes = sanitized.toByteArray(Charsets.UTF_8)
5757
object : OutgoingContent.ByteArrayContent() {
58-
override val contentType: ContentType = body.contentType ?: ContentType.Application.Json
58+
override val contentType: ContentType =
59+
body.contentType ?: ContentType.Application.Json
5960
override val contentLength: Long = bytes.size.toLong()
6061
override fun bytes(): ByteArray = bytes
6162
}
6263
}
64+
6365
else -> body
6466
}
6567

app/src/main/kotlin/me/nanova/summaryexpressive/llm/LLMHandler.kt

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ class LLMHandler(
9292
articleToolRegistry + youtubeToolRegistry + bilibiliToolRegistry + fileToolRegistry
9393

9494
val agentConfig =
95-
createAgentConfig(provider, model, summaryLength, showLength, useContentLanguage, appLanguage, isAppendMode, customBasePrompt, additionalSystemPrompt)
95+
createAgentConfig(
96+
provider,
97+
model,
98+
summaryLength,
99+
showLength,
100+
useContentLanguage,
101+
appLanguage,
102+
isAppendMode,
103+
customBasePrompt,
104+
additionalSystemPrompt
105+
)
96106

97107
return AIAgent(
98108
promptExecutor = executor,
@@ -151,47 +161,85 @@ class LLMHandler(
151161

152162
val lang = appLanguage.getDisplayLanguage(Locale.ENGLISH)
153163
return AIAgentConfig(
154-
prompt = createSummarizationPrompt(summaryLength, showLength, useContentLanguage, lang, isAppendMode, customBasePrompt, additionalSystemPrompt),
164+
prompt = createSummarizationPrompt(
165+
summaryLength,
166+
showLength,
167+
useContentLanguage,
168+
lang,
169+
isAppendMode,
170+
customBasePrompt,
171+
additionalSystemPrompt
172+
),
155173
model = llmModel,
156174
maxAgentIterations = 10,
157175
)
158176
}
159177

160178
private fun createOpenAIExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
161179
val client = baseUrl?.takeIf { it.isNotBlank() }
162-
?.let { OpenAILLMClient(apiKey, settings = OpenAIClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
180+
?.let {
181+
OpenAILLMClient(
182+
apiKey,
183+
settings = OpenAIClientSettings(baseUrl = it),
184+
httpClientFactory = koogHttpClientFactory
185+
)
186+
}
163187
?: OpenAILLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
164188

165189
return MultiLLMPromptExecutor(client)
166190
}
167191

168192
private fun createGeminiExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
169193
val client = baseUrl?.takeIf { it.isNotBlank() }
170-
?.let { GoogleLLMClient(apiKey, settings = GoogleClientSettings(baseUrl = it), httpClientFactory = geminiKoogHttpClientFactory) }
194+
?.let {
195+
GoogleLLMClient(
196+
apiKey,
197+
settings = GoogleClientSettings(baseUrl = it),
198+
httpClientFactory = geminiKoogHttpClientFactory
199+
)
200+
}
171201
?: GoogleLLMClient(apiKey, httpClientFactory = geminiKoogHttpClientFactory)
172202

173203
return MultiLLMPromptExecutor(client)
174204
}
175205

176206
private fun createClaudExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
177207
val client = baseUrl?.takeIf { it.isNotBlank() }
178-
?.let { AnthropicLLMClient(apiKey, settings = AnthropicClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
208+
?.let {
209+
AnthropicLLMClient(
210+
apiKey,
211+
settings = AnthropicClientSettings(baseUrl = it),
212+
httpClientFactory = koogHttpClientFactory
213+
)
214+
}
179215
?: AnthropicLLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
180216

181217
return MultiLLMPromptExecutor(client)
182218
}
183219

184220
private fun createDeepSeekExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
185221
val client = baseUrl?.takeIf { it.isNotBlank() }
186-
?.let { DeepSeekLLMClient(apiKey, settings = DeepSeekClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
222+
?.let {
223+
DeepSeekLLMClient(
224+
apiKey,
225+
settings = DeepSeekClientSettings(baseUrl = it),
226+
httpClientFactory = koogHttpClientFactory
227+
)
228+
}
187229
?: DeepSeekLLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
188230

189231
return MultiLLMPromptExecutor(client)
190232
}
191233

192234
private fun createMistralExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
193235
val client = baseUrl?.takeIf { it.isNotBlank() }
194-
?.let { MistralAILLMClient(apiKey, settings = MistralAIClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
236+
?.let {
237+
MistralAILLMClient(
238+
apiKey,
239+
settings = MistralAIClientSettings(baseUrl = it),
240+
httpClientFactory = koogHttpClientFactory
241+
)
242+
}
195243
?: MistralAILLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
196244

197245
return MultiLLMPromptExecutor(client)
@@ -211,7 +259,13 @@ class LLMHandler(
211259
baseUrl
212260
}
213261
val client = finalBaseUrl?.takeIf { it.isNotBlank() }
214-
?.let { DashscopeLLMClient(apiKey, settings = DashscopeClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
262+
?.let {
263+
DashscopeLLMClient(
264+
apiKey,
265+
settings = DashscopeClientSettings(baseUrl = it),
266+
httpClientFactory = koogHttpClientFactory
267+
)
268+
}
215269
?: DashscopeLLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
216270

217271
return MultiLLMPromptExecutor(client)
@@ -227,7 +281,13 @@ class LLMHandler(
227281

228282
private fun createOpenRouterExecutor(apiKey: String, baseUrl: String?): PromptExecutor {
229283
val client = baseUrl?.takeIf { it.isNotBlank() }
230-
?.let { OpenRouterLLMClient(apiKey, settings = OpenRouterClientSettings(baseUrl = it), httpClientFactory = koogHttpClientFactory) }
284+
?.let {
285+
OpenRouterLLMClient(
286+
apiKey,
287+
settings = OpenRouterClientSettings(baseUrl = it),
288+
httpClientFactory = koogHttpClientFactory
289+
)
290+
}
231291
?: OpenRouterLLMClient(apiKey, httpClientFactory = koogHttpClientFactory)
232292

233293
return MultiLLMPromptExecutor(client)
@@ -272,30 +332,38 @@ class LLMHandler(
272332
nodeStart forwardTo nodeExtractArticle
273333
onCondition { it is SummarySource.Article }
274334
transformed { source ->
275-
val url = (source as SummarySource.Article).url
276-
sourceLink = url
277-
Article(url)
278-
}
335+
val url = (source as SummarySource.Article).url
336+
sourceLink = url
337+
Article(url)
338+
}
279339
)
280340
edge(
281341
nodeStart forwardTo nodeExtractYoutube
282-
onCondition { it is SummarySource.Video && YouTubeTranscriptTool.isYouTubeLink((it).url) }
342+
onCondition {
343+
it is SummarySource.Video && YouTubeTranscriptTool.isYouTubeLink(
344+
(it).url
345+
)
346+
}
283347
transformed { source ->
284-
val url = (source as SummarySource.Video).url
285-
isYoutube = true
286-
sourceLink = url
287-
YouTubeTranscript(url)
288-
}
348+
val url = (source as SummarySource.Video).url
349+
isYoutube = true
350+
sourceLink = url
351+
YouTubeTranscript(url)
352+
}
289353
)
290354
edge(
291355
nodeStart forwardTo nodeExtractBiliBili
292-
onCondition { it is SummarySource.Video && BiliBiliSubtitleTool.isBiliBiliLink((it).url) }
356+
onCondition {
357+
it is SummarySource.Video && BiliBiliSubtitleTool.isBiliBiliLink(
358+
(it).url
359+
)
360+
}
293361
transformed { source ->
294-
val url = (source as SummarySource.Video).url
295-
isBiliBili = true
296-
sourceLink = url
297-
BiliBiliVideo(url)
298-
}
362+
val url = (source as SummarySource.Video).url
363+
isBiliBili = true
364+
sourceLink = url
365+
BiliBiliVideo(url)
366+
}
299367
)
300368
edge(
301369
nodeStart forwardTo nodeExtractFile
@@ -308,9 +376,21 @@ class LLMHandler(
308376
transformed { (it as SummarySource.Text).content })
309377

310378
// Tool-based paths
311-
edge(nodeExtractArticle forwardTo nodePreLLMRequest transformed { processToolResult(it) })
312-
edge(nodeExtractYoutube forwardTo nodePreLLMRequest transformed { processToolResult(it) })
313-
edge(nodeExtractBiliBili forwardTo nodePreLLMRequest transformed { processToolResult(it) })
379+
edge(nodeExtractArticle forwardTo nodePreLLMRequest transformed {
380+
processToolResult(
381+
it
382+
)
383+
})
384+
edge(nodeExtractYoutube forwardTo nodePreLLMRequest transformed {
385+
processToolResult(
386+
it
387+
)
388+
})
389+
edge(nodeExtractBiliBili forwardTo nodePreLLMRequest transformed {
390+
processToolResult(
391+
it
392+
)
393+
})
314394
edge(nodeExtractFile forwardTo nodePreLLMRequest transformed { processToolResult(it) })
315395
edge(nodePreLLMRequest forwardTo nodeFinish)
316396

app/src/main/kotlin/me/nanova/summaryexpressive/llm/Prompts.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fun generateFinalPromptString(
2828
appLanguage: String,
2929
isAppendMode: Boolean,
3030
customBasePrompt: String,
31-
additionalSystemPrompt: String
31+
additionalSystemPrompt: String,
3232
): String {
3333
val lengthInstruction = when (length) {
3434
SummaryLength.SHORT -> "a few sentences(better within 100 words)"
@@ -60,7 +60,7 @@ fun generateFinalPromptString(
6060

6161
append("\n\n")
6262
append(languageInstruction)
63-
63+
6464
if (showLength) {
6565
append("\n")
6666
append("The summary should be about $lengthInstruction long, and must not exceed the length of the original content.")
@@ -78,7 +78,13 @@ fun createSummarizationPrompt(
7878
additionalSystemPrompt: String = "",
7979
): Prompt {
8080
val finalPrompt = generateFinalPromptString(
81-
length, showLength, useContentLanguage, appLanguage, isAppendMode, customBasePrompt, additionalSystemPrompt
81+
length,
82+
showLength,
83+
useContentLanguage,
84+
appLanguage,
85+
isAppendMode,
86+
customBasePrompt,
87+
additionalSystemPrompt
8288
)
8389

8490
return prompt("summarizer-prompt") {

app/src/main/kotlin/me/nanova/summaryexpressive/llm/tools/FileExtractorTool.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class FileExtractorTool(private val context: Context) : Tool<File, ExtractedCont
182182
filename.endsWith(".jpg", ignoreCase = true) ||
183183
filename.endsWith(".jpeg", ignoreCase = true) ||
184184
filename.endsWith(".png", ignoreCase = true)
185-
-> ImageTextExtractor
185+
-> ImageTextExtractor
186+
186187
else -> null
187188
}
188189

app/src/main/kotlin/me/nanova/summaryexpressive/ui/Nav.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import kotlinx.serialization.Serializable
77
sealed interface Nav : NavKey {
88
@Serializable
99
data object Home : Nav
10+
1011
@Serializable
1112
data object Onboarding : Nav
13+
1214
@Serializable
1315
data object History : Nav
16+
1417
@Serializable
1518
data class Settings(val highlight: String? = null) : Nav
19+
1620
@Serializable
1721
data object AdvancedSummarySetup : Nav
1822
}

app/src/main/kotlin/me/nanova/summaryexpressive/ui/component/SummaryCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ fun SummaryCard(
149149
modifier = Modifier.padding(top = 1.dp)
150150
)
151151
}
152-
152+
153153
Spacer(modifier = Modifier.weight(1f))
154-
154+
155155
val aiProvider = summary.provider?.let { providerName ->
156156
AIProvider.entries.find { it.name == providerName }
157157
}

0 commit comments

Comments
 (0)