openassistant: restore tools lost in consequential merges
- Commit
d75dccbe39435f540ea329ce7dd7ba89da2eec1f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 05:20 UTC (4 days ago)
- Parents
f14f584
Main's health/maps merges rewrote the shared OA files from stale branch states, dropping the screentime_get_usage, education_get_progress, news_search_headlines, news_top_stories, news_get_story and news_read_article spec rows, handlers, intent back ends and summarizers (and the health_get_metric_summary spec row) while their tests and app-side intents remained, leaving :openassistant:testDevUnitTest uncompilable and the handlers/specs agreement check failing. Restore the OA wiring from the original commits (cfaac1f9d, 6663c24f9, 5982970d8, 6827508e7): spec rows, AssistantTools handlers, AssistantCoreToolIntents/AssistantToolIntents back ends and host summarizers, and the education/news manifest permissions. Catalogue is now 65 tools; count and numeric-param pins updated; tool descriptions trimmed so the header fits the existing 25,600-char PromptBudget cap (no budget raise). Verified: :openassistant:compileReleaseKotlin green; PromptBudgetTest green; full :openassistant:testDevUnitTest green except InferenceServiceConcurrencyTest, which is flaky under full-suite load (also noted in 5982970d8) and passes in isolation.
Diff
openassistant/src/main/AndroidManifest.xml
diff --git a/openassistant/src/main/AndroidManifest.xml b/openassistant/src/main/AndroidManifest.xmlindex 9f9e1a54c3..f81fbe8614 100644--- a/openassistant/src/main/AndroidManifest.xml+++ b/openassistant/src/main/AndroidManifest.xml@@ -22,6 +22,8 @@ <uses-permission android:name="com.vayunmathur.taxi.permissions.ACCESS_RIDES" /> <uses-permission android:name="com.vayunmathur.fooddelivery.permissions.ACCESS_ORDERS" /> <uses-permission android:name="com.vayunmathur.health.permissions.ACCESS_HEALTH" />+ <uses-permission android:name="com.vayunmathur.education.permissions.ACCESS_EDUCATION" />+ <uses-permission android:name="com.vayunmathur.news.permissions.ACCESS_NEWS" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" />
openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.ktindex ab6aab63d1..39ee27fbc3 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt@@ -72,22 +72,23 @@ get_local_current_date_time|-|Get the current date and time in the local timezon get_app_list|-|Get installed apps (max 100)| open_app|-|Open an app given its package id|package_id^S^1^package id send_message|-|Send a message|recipient^S^1^~message^S^1^-make_phone_call|-|Make a phone call|recipient^S^1^-set_alarm|C|Set an alarm in the Clock app at a specific hour and minute (24-hour time) (requires confirmation).|hour^N^1^hour 0-23 (24h)~minute^N^1^minute 0-59~label^S^0^optional label-set_timer|C|Start a countdown timer in the Clock app for a number of seconds (requires confirmation).|seconds^N^1^timer length in seconds~label^S^0^optional label for the timer-set_conversation_title|-|Set title of current conversation. Mandatory for first response|new_title^S^1^-get_weather|-|Get the current weather conditions at a specific latitude/longitude.|latitude^N^1^~longitude^N^1^-get_weather_by_name|-|Get the current weather conditions for a named place (city, address, landmark).|location^S^1^city or place name-render_ui|-|Render a rich UI card (A2UI) attached to your reply; prefer this over a ```a2ui fence. components_json: {"components":[...]} (or a bare array) using the RICH UI types; data_json: optional initial data object.|components_json^S^1^A2UI components as a JSON string~data_json^S^0^optional initial data model as a JSON object string-get_directions|-|Get Maps directions between two coordinates: distance, duration, segment count.|from_lat^N^1^origin latitude~from_lng^N^1^origin longitude~to_lat^N^1^destination latitude~to_lng^N^1^destination longitude~mode^S^0^drive (default), transit, walk, or bicycle-maps_search_places|-|Search Maps places by name/category; returns lat/lng for get_directions/get_ride_estimate.|query^S^1^name or category~near_lat^N^0^latitude to search near~near_lng^N^0^longitude to search near~category^S^0^category e.g. Cafe~limit^N^0^max 1-10 (default 5)-maps_get_saved_places|-|Get user's saved Maps places (name and coordinates only).|query^S^0^name filter~limit^N^0^max 1-10 (default 10)-get_ride_estimate|-|Get a ride fare and pickup ETA estimate from the Taxi app.|pickup_lat^N^1^pickup latitude~pickup_lng^N^1^pickup longitude~dest_lat^N^1^destination latitude~dest_lng^N^1^destination longitude~pickup_label^S^0^optional pickup label~dest_label^S^0^optional destination label-food_order_lookup|-|Check whether a named restaurant is orderable near a location via the FoodDelivery app.|name^S^1^restaurant name~lat^N^1^latitude~lng^N^1^longitude~address^S^0^optional address-calculator_evaluate|-|Evaluate a math expression with the Calculator app (functions, pi/e, units like 5km+2mi). Returns one scalar result.|expression^S^1^math expression, up to 200 chars-calculator_convert_unit|-|Convert a value between units with the Calculator app (incl. currency codes like USD).|value^N^1^value to convert~from_unit^S^1^source unit: km, ft, degC, USD~to_unit^S^1^target unit: mi, m, degF, EUR-search_contacts|-|Search contacts by name or phone number substring (case-insensitive, max 10 results).|query^S^1^name or phone substring to search for-web_search|-|Search the web for current/external facts. Returns numbered results; web_read_result reads the best ones.|query^S^1^search query~count^N^0^result count 1-10 (default 5)~kind^S^0^text (default) or news+make_phone_call|-|Call a phone number|recipient^S^1^+set_alarm|C|Set Clock alarm at hour/minute 24h (confirmation).|hour^N^1^hour 0-23 (24h)~minute^N^1^minute 0-59~label^S^0^optional label+set_timer|C|Start Clock countdown timer in seconds (confirmation).|seconds^N^1^timer length in seconds~label^S^0^optional label for the timer+set_conversation_title|-|Set current conversation title. Mandatory first response.|new_title^S^1^+get_weather|-|Current weather at lat/lng.|latitude^N^1^~longitude^N^1^+get_weather_by_name|-|Current weather for a named place.|location^S^1^place name+screentime_get_usage|-|Today's screen time: total + top 5 apps.|+render_ui|-|Render rich UI card (A2UI) with reply; prefer over ```a2ui fence. components_json {"components":[...]} or array; data_json optional.|components_json^S^1^A2UI components JSON~data_json^S^0^data JSON+get_directions|-|Directions between coordinates: distance, duration.|from_lat^N^1^origin lat~from_lng^N^1^origin lng~to_lat^N^1^dest lat~to_lng^N^1^dest lng~mode^S^0^drive (default), transit, walk, or bicycle+maps_search_places|-|Search Maps places; returns lat/lng.|query^S^1^name or category~near_lat^N^0^near latitude~near_lng^N^0^near longitude~category^S^0^e.g. Cafe~limit^N^0^1-10 (default 5)+maps_get_saved_places|-|Saved Maps places (name + coordinates).|query^S^0^filter~limit^N^0^max 1-10 (default 10)+get_ride_estimate|-|Taxi fare + pickup ETA.|pickup_lat^N^1^pickup lat~pickup_lng^N^1^pickup lng~dest_lat^N^1^dest lat~dest_lng^N^1^dest lng~pickup_label^S^0^pickup label~dest_label^S^0^dest label+food_order_lookup|-|Check if a named restaurant is orderable nearby (FoodDelivery).|name^S^1^name~lat^N^1^latitude~lng^N^1^longitude~address^S^0^optional address+calculator_evaluate|-|Evaluate math expression via Calculator (functions, pi/e, units 5km+2mi).|expression^S^1^expression (200 chars)+calculator_convert_unit|-|Convert a value between units via Calculator (incl. currency like USD).|value^N^1^value~from_unit^S^1^from: km, ft, degC, USD~to_unit^S^1^to: mi, m, degF, EUR+search_contacts|-|Search contacts by name/phone substring (max 10).|query^S^1^name/phone substring+web_search|-|Web search for current facts. Numbered results; web_read_result reads them.|query^S^1^search query~count^N^0^count 1-10 (default 5)~kind^S^0^text (default) or news web_read|-|Read a web page by URL and return its extracted text.|url^S^1^page URL to read web_read_result|-|Read a result from the last web_search by its 1-based index.|index^N^1^1-based index into the last web_search results~offset^N^0^optional character offset for long pages find_conversations|-|Find Communicate conversations by name, number or snippet. Returns thread_key values for get_conversation_messages.|query^S^0^name, number or text to search (blank lists recent)~limit^N^0^optional max conversations 1-50 (default 5)@@ -97,18 +98,24 @@ send_message_v2|C|Send via Communicate (requires confirmation, EXPLICIT request find_restaurants|-|Find restaurants near a location via the FoodDelivery app, optionally filtered by name or tag.|query^S^0^optional name or tag filter~lat^N^1^latitude~lng^N^1^longitude~limit^N^0^optional max results (default 5) get_restaurant_menu|-|Get the menu of a restaurant (merchant_id from find_restaurants). Items carry ids, prices in cents, availability and modifier groups.|merchant_id^N^1^merchant id from find_restaurants food_get_cart|-|Get the current FoodDelivery cart (items and total)|-food_set_cart|L|Replace the FoodDelivery cart with items_json: [{"itemId":1,"qty":2,"modifierIds":[]}]. Re-validated and shown back; no order is placed and no money moves.|merchant_id^N^1^merchant id the items belong to~items_json^S^1^JSON array of {itemId, qty, modifierIds}-food_prepare_order|-|Price the current cart (pickup or delivery); creates no order.|merchant_id^N^1^merchant id~is_pickup^N^0^1 pickup, 0 delivery (default)~address_id^S^0^optional address id~tip_cents^N^0^optional tip (cents)~promo^S^0^optional promo+food_set_cart|L|Replace FoodDelivery cart with items_json [{itemId,qty,modifierIds}]. No order placed.|merchant_id^N^1^merchant id~items_json^S^1^[{itemId,qty,modifierIds}]+food_prepare_order|-|Price cart (pickup/delivery); no order created.|merchant_id^N^1^merchant id~is_pickup^N^0^1 pickup, 0 delivery (default)~address_id^S^0^address id~tip_cents^N^0^tip (cents)~promo^S^0^promo place_food_order|H|Show the current cart's order summary. The user places and pays in FoodDelivery itself; this never creates an order or charges a card.|merchant_id^N^1^merchant id get_food_orders|-|Get the user's past FoodDelivery orders|-search_products|-|Search the Shop catalog. Each result is one purchasable variant with its variant_id, store and exact price.|query^S^1^search text~limit^N^0^max results (default 5)-get_product_detail|-|Get one product's variants (exact prices, availability). Confirm the exact variant with the user before adding to cart.|shop_domain^S^1^store domain~product_id^S^1^product id~variant_id^S^0^optional variant to price+search_products|-|Search the Shop catalog. Each result is one purchasable variant with its variant_id, store and exact price.|query^S^1^search text~limit^N^0^max (default 5)+get_product_detail|-|One product's variants (prices, availability). Confirm variant before adding to cart.|shop_domain^S^1^domain~product_id^S^1^product id~variant_id^S^0^variant to price shop_get_cart|-|Get the current Shop cart, grouped by store|-shop_add_to_cart|L|Add an exact variant to the Shop cart (re-verified first, shown back; no checkout).|shop_domain^S^1^store domain~variant_id^S^1^exact variant id~quantity^N^0^quantity 1-99 (default 1)+shop_add_to_cart|L|Add exact variant to Shop cart (re-verified; no checkout).|shop_domain^S^1^domain~variant_id^S^1^exact variant id~quantity^N^0^qty 1-99 (default 1) shop_remove_from_cart|L|Remove a variant from the Shop cart; the cart is shown back to the user.|variant_id^S^1^variant id to remove-start_shop_checkout|H|Show the per-store cart summary for one store. The user checks out in Shop itself; this never creates a checkout or charges anything.|shop_domain^S^1^store domain to check out+start_shop_checkout|H|Per-store cart summary. User checks out in Shop; never charges.|shop_domain^S^1^domain to check out get_shop_orders|-|Get the user's Shop order summaries| get_memories|-|Get memories (last 100)|+education_get_progress|-|Education progress by course/subject, streak, deadlines (aggregates).|+news_search_headlines|-|Search News headlines|query^S^1^~category^S^0^WORLD US TECHNOLOGY SCIENCE LOCAL~limit^N^0^1-10, default 5+news_top_stories|-|Top News stories by source count, then newest|category^S^0^WORLD US TECHNOLOGY SCIENCE LOCAL~limit^N^0^1-10, default 5+news_get_story|-|Get a News story by story_id|story_id^S^1^from news search/top+news_read_article|-|Read a News article (3000 chars/page)|url^S^1^from a news result~offset^N^0^char offset+health_get_metric_summary|-|Health summary aggregates only: latest/avg/min/max/totals.|metric^S^1^steps/sleep/weight/heart_rate/hydration~range^S^0^today/7d (default)/30d remove_memory|C|Remove a memory by its id (requires confirmation)|id^N^1^ add_to_memory|-|Add a new memory to the list of memories|content^S^1^ """
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.ktnew file mode 100644index 0000000000..3e05b35a1d--- /dev/null+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantAggregateSummarizers.kt@@ -0,0 +1,124 @@+package com.vayunmathur.openassistant.platform++import com.vayunmathur.library.intents.education.EducationProgressData+import com.vayunmathur.library.intents.health.HealthMetricSummaryData+import com.vayunmathur.library.intents.news.NewsArticleExcerptData+import com.vayunmathur.library.intents.news.NewsHeadlineData+import com.vayunmathur.library.intents.news.NewsStoryData+import com.vayunmathur.library.intents.screentime.ScreentimeUsageData+import com.vayunmathur.library.intents.screentime.ScreentimeUsageQuery++private const val HEALTH_SUMMARY_CHARS = 300++fun formatHealthValue(value: Double): String =+ if (value == value.toLong().toDouble()) {+ value.toLong().toString()+ } else {+ "%.2f".format(value).trimEnd('0').trimEnd('.')+ }++/**+ * One-line aggregate health summary for the model. The DTO already carries+ * aggregates only; this renders them (latest, average, min/max, total,+ * counts) in a few hundred characters and never any record-level data.+ */++fun summarizeHealthMetric(summary: HealthMetricSummaryData): String {+ if (summary.error != null) return "Error: health summary unavailable (${summary.error})".take(HEALTH_SUMMARY_CHARS)+ val rangeLabel = when (summary.range) {+ "today" -> "today"+ "7d" -> "last 7 days"+ "30d" -> "last 30 days"+ else -> summary.range+ }+ if (summary.recordCount == 0) return "No ${summary.metric} data in the $rangeLabel."+ val parts = mutableListOf<String>()+ summary.latestValue?.let { parts += "latest ${formatHealthValue(it)} ${summary.unit}".trim() }+ summary.average?.let {+ val label = if (summary.cumulative) "avg/day" else "avg"+ parts += "$label ${formatHealthValue(it)} ${summary.unit}".trim()+ }+ val min = summary.min+ val max = summary.max+ if (min != null && max != null) {+ parts += "range ${formatHealthValue(min)}-${formatHealthValue(max)} ${summary.unit}".trim()+ }+ summary.total?.let { parts += "total ${formatHealthValue(it)} ${summary.unit}".trim() }+ parts += "${summary.recordCount} records over ${summary.daysWithData} day(s)"+ return "${summary.metric} ($rangeLabel): ${parts.joinToString("; ")}".take(HEALTH_SUMMARY_CHARS)+}++/** One-day screen-time summary for the model: total plus top apps. */++fun summarizeScreentimeUsage(data: ScreentimeUsageData): String {+ if (!data.hasUsageAccess || data.error != null) {+ return "Screen time unavailable: usage access is not granted in Screentime"+ }+ if (data.apps.isEmpty()) return "No screen time recorded today (0m total)"+ val lines = data.apps.take(ScreentimeUsageQuery.MAX_TOP_APPS)+ .joinToString("\n") { app ->+ "${app.label.take(ScreentimeUsageQuery.MAX_LABEL_CHARS)} " ++ "(${app.packageName}): ${formatUsageDuration(app.totalMillis)}"+ }+ return "Today: ${formatUsageDuration(data.totalMillis)} total\n$lines"+}++fun formatUsageDuration(millis: Long): String {+ val totalSeconds = millis / 1_000+ val hours = totalSeconds / 3_600+ val minutes = (totalSeconds % 3_600) / 60+ val seconds = totalSeconds % 60+ return when {+ hours > 0 -> "${hours}h ${minutes}m"+ minutes > 0 -> "${minutes}m"+ else -> "${seconds}s"+ }+}++fun summarizeEducationProgress(data: EducationProgressData): String {+ val header = buildString {+ data.learnerFirstName?.let { append("$it: ") }+ append("streak ${data.streakDays}d, ${data.totalStars} stars, ")+ append("${data.skillsMastered}/${data.totalSkills} skills mastered, ")+ append("${data.skillsStarted} started")+ data.band?.let { append(" (band $it)") }+ }+ val courses = data.courses.joinToString("\n") { c ->+ "course ${c.title.take(120)} [${c.subject}]: " ++ "${c.masteredSkills}/${c.totalSkills} mastered (${c.completionPercent}%), ${c.startedSkills} started"+ }+ val subjects = data.subjects.joinToString("\n") { s ->+ "subject ${s.subject}: ${s.masteredSkills}/${s.totalSkills} mastered (${s.completionPercent}%), ${s.startedSkills} started"+ }+ val deadlines = data.upcomingDeadlines.take(5).joinToString("\n") { d ->+ "deadline ${d.title.take(120)} [${d.moduleType}] dueEpochDay=${d.dueEpochDay}"+ }+ return listOf(header, courses, subjects, deadlines).filter { it.isNotBlank() }.joinToString("\n")+}++fun summarizeNewsHeadlines(list: List<NewsHeadlineData>): String =+ if (list.isEmpty()) {+ "No headlines found"+ } else {+ list.take(10).joinToString("\n") { h ->+ "story_id=${h.storyId} url=${h.url} [${h.sourceCount} source(s)] " ++ h.title.take(160) + (h.oneLiner?.take(200)?.let { " — $it" } ?: "")+ }+ }++fun summarizeNewsStory(data: NewsStoryData): String {+ if (data.members.isEmpty()) return "No story found for story_id=${data.storyId}"+ val header = "Story ${data.title.take(160)}" ++ (data.oneLiner?.take(300)?.let { "\n$it" } ?: "")+ val lines = data.members.take(8).joinToString("\n") { m ->+ "url=${m.url} [${m.sourceName}] ${m.title.take(160)}"+ }+ return "$header\n$lines"+}++fun summarizeNewsArticle(data: NewsArticleExcerptData): String {+ if (data.excerpt.isEmpty() && data.title.isEmpty()) return "Article unavailable"+ val byline = data.byline?.takeIf { it.isNotBlank() }?.let { "\n$it" } ?: ""+ val more = data.nextOffset?.let { "\n(next page: news_read_article offset=$it)" } ?: ""+ return "${data.title.take(160)}$byline\n${data.excerpt.take(3_000)}$more"+}
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantCoreToolIntents.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantCoreToolIntents.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantCoreToolIntents.ktindex 58d5f731e5..c8a7c20ff1 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantCoreToolIntents.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantCoreToolIntents.kt@@ -73,6 +73,9 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.serializer+import com.vayunmathur.library.intents.screentime.ScreentimeUsageData+import com.vayunmathur.library.intents.screentime.ScreentimeUsageQuery+import com.vayunmathur.library.intents.education.EducationProgressData /**@@ -345,4 +348,19 @@ internal abstract class AssistantCoreToolIntents( ) return summarizeHealthMetric(result) }+ suspend fun getScreentimeUsage(limit: Int): ScreentimeUsageData = launchIntent(+ context,+ "com.vayunmathur.screentime",+ "com.vayunmathur.screentime.intents.GetUsageIntent",+ ScreentimeUsageQuery(limit),+ )++ suspend fun getEducationProgress(): EducationProgressData =+ launchIntent<Unit, EducationProgressData>(+ context,+ "com.vayunmathur.education",+ "com.vayunmathur.education.intents.GetProgressIntent",+ Unit,+ )+ }
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.ktindex 49c3c31c2d..79f7189f19 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantToolIntents.kt@@ -68,6 +68,16 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.serializer+import com.vayunmathur.library.intents.screentime.ScreentimeUsageData+import com.vayunmathur.library.intents.screentime.ScreentimeUsageQuery+import com.vayunmathur.library.intents.education.EducationProgressData+import com.vayunmathur.library.intents.news.NewsArticleExcerptData+import com.vayunmathur.library.intents.news.NewsArticleQuery+import com.vayunmathur.library.intents.news.NewsHeadlineData+import com.vayunmathur.library.intents.news.NewsSearchQuery+import com.vayunmathur.library.intents.news.NewsStoryData+import com.vayunmathur.library.intents.news.NewsStoryQuery+import com.vayunmathur.library.intents.news.NewsTopQuery private const val CONVERSATION_SNIPPET_CHARS = 80 private const val MESSAGE_BODY_CHARS = 200@@ -285,6 +295,34 @@ internal class AssistantToolIntents(context: Context) : AssistantCoreToolIntents memoryDao.upsert(Memory(content)) return "Success: Added memory" }+ suspend fun topNewsStories(category: String?, limit: Int): List<NewsHeadlineData> = launchIntent(+ context,+ "com.vayunmathur.news",+ "com.vayunmathur.news.intents.TopStoriesIntent",+ NewsTopQuery(category, limit),+ )++ suspend fun readNewsArticle(url: String, offset: Int): NewsArticleExcerptData = launchIntent(+ context,+ "com.vayunmathur.news",+ "com.vayunmathur.news.intents.ReadArticleIntent",+ NewsArticleQuery(url, offset),+ )++ suspend fun searchNewsHeadlines(query: String, category: String?, limit: Int): List<NewsHeadlineData> = launchIntent(+ context,+ "com.vayunmathur.news",+ "com.vayunmathur.news.intents.SearchHeadlinesIntent",+ NewsSearchQuery(query, category, limit),+ )++ suspend fun getNewsStory(storyId: String): NewsStoryData = launchIntent(+ context,+ "com.vayunmathur.news",+ "com.vayunmathur.news.intents.GetStoryIntent",+ NewsStoryQuery(storyId),+ )+ } /** Missing App Exception: a string implementation for missing app exception. */@@ -427,6 +465,7 @@ fun filterContacts(query: String, contacts: List<ContactData>, cap: Int = 10): L return contacts.filter { it.name.lowercase().contains(needle) || it.phoneNumber.lowercase().contains(needle) }.take(cap)+ } /**@@ -686,45 +725,3 @@ suspend inline fun <reified Input : Any> launchIntentU( ) if (stringOutput == "package $packageName doesn't exist") throw MissingAppException(packageName) }--private const val HEALTH_SUMMARY_CHARS = 300--fun formatHealthValue(value: Double): String =- if (value == value.toLong().toDouble()) {- value.toLong().toString()- } else {- "%.2f".format(value).trimEnd('0').trimEnd('.')- }--/**- * One-line aggregate health summary for the model. The DTO already carries- * aggregates only; this renders them (latest, average, min/max, total,- * counts) in a few hundred characters and never any record-level data.- */--fun summarizeHealthMetric(summary: HealthMetricSummaryData): String {- if (summary.error != null) return "Error: health summary unavailable (${summary.error})".take(HEALTH_SUMMARY_CHARS)- val rangeLabel = when (summary.range) {- "today" -> "today"- "7d" -> "last 7 days"- "30d" -> "last 30 days"- else -> summary.range- }- if (summary.recordCount == 0) return "No ${summary.metric} data in the $rangeLabel."- val parts = mutableListOf<String>()- summary.latestValue?.let { parts += "latest ${formatHealthValue(it)} ${summary.unit}".trim() }- summary.average?.let {- val label = if (summary.cumulative) "avg/day" else "avg"- parts += "$label ${formatHealthValue(it)} ${summary.unit}".trim()- }- val min = summary.min- val max = summary.max- if (min != null && max != null) {- parts += "range ${formatHealthValue(min)}-${formatHealthValue(max)} ${summary.unit}".trim()- }- summary.total?.let { parts += "total ${formatHealthValue(it)} ${summary.unit}".trim() }- parts += "${summary.recordCount} records over ${summary.daysWithData} day(s)"- return "${summary.metric} ($rangeLabel): ${parts.joinToString("; ")}".take(HEALTH_SUMMARY_CHARS)-}--/** Short ride-estimate summary for the model. */
openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.ktindex 451eb1215a..df5a17d951 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/AssistantTools.kt@@ -170,6 +170,54 @@ class AssistantTools( ) } },+ "screentime_get_usage" to { _ ->+ intents.runTool {+ com.vayunmathur.openassistant.platform.summarizeScreentimeUsage(+ intents.getScreentimeUsage(+ com.vayunmathur.library.intents.screentime.ScreentimeUsageQuery.MAX_TOP_APPS,+ ),+ )+ }+ },+ "education_get_progress" to { _ ->+ intents.runTool {+ com.vayunmathur.openassistant.platform.summarizeEducationProgress(intents.getEducationProgress())+ }+ },+ "news_search_headlines" to { a ->+ intents.runTool {+ val limit = a.number("limit").toInt().takeIf { it > 0 } ?: 5+ com.vayunmathur.openassistant.platform.summarizeNewsHeadlines(+ intents.searchNewsHeadlines(+ a.string("query"),+ a.string("category").takeIf { it.isNotBlank() },+ limit,+ ),+ )+ }+ },+ "news_top_stories" to { a ->+ intents.runTool {+ val limit = a.number("limit").toInt().takeIf { it > 0 } ?: 5+ com.vayunmathur.openassistant.platform.summarizeNewsHeadlines(+ intents.topNewsStories(a.string("category").takeIf { it.isNotBlank() }, limit),+ )+ }+ },+ "news_get_story" to { a ->+ intents.runTool {+ com.vayunmathur.openassistant.platform.summarizeNewsStory(+ intents.getNewsStory(a.string("story_id")),+ )+ }+ },+ "news_read_article" to { a ->+ intents.runTool {+ com.vayunmathur.openassistant.platform.summarizeNewsArticle(+ intents.readNewsArticle(a.string("url"), a.number("offset").toInt()),+ )+ }+ }, "get_directions" to { a -> intents.runTool { intents.getDirections(
openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.ktindex d3f41646e4..a437f6dbb0 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/domain/PromptBudgetTest.kt@@ -22,7 +22,7 @@ class PromptBudgetTest { val header = declared.length + InferenceService.DEFAULT_SYSTEM_PROMPT.length + AssistantCatalog.PROMPT_SECTION.length println("HEADER declared=${declared.length} prompt=${InferenceService.DEFAULT_SYSTEM_PROMPT.length} a2ui=${AssistantCatalog.PROMPT_SECTION.length} total=$header")- assertEquals(56, ASSISTANT_TOOL_SPECS.size)+ assertEquals(65, ASSISTANT_TOOL_SPECS.size) assertTrue(header <= MAX_HEADER_CHARS, "header=$header over budget $MAX_HEADER_CHARS") }
openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.ktindex bc5e8ba3e8..361599d0c3 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsInvokeTest.kt@@ -44,7 +44,7 @@ class AssistantToolsInvokeTest { assertEquals("Error: create_note needs title", call("create_note", "content" to "x")) assertTrue( call("set_timer", "seconds" to "abc").contains("must be a number"))- assertEquals(56, tools.declarations.size)+ assertEquals(65, tools.declarations.size) } @Test fun crossAppToolsReportMissingApps() {
openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt
diff --git a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.ktindex 646e720fe2..8201df0a5c 100644--- a/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt+++ b/openassistant/src/test/java/com/vayunmathur/openassistant/platform/AssistantToolsTest.kt@@ -14,7 +14,7 @@ class AssistantToolsTest { @Test fun namesAreUniqueSnakeCase() { val names = ASSISTANT_TOOL_SPECS.map { it.name }- assertEquals(56, names.size)+ assertEquals(65, names.size) assertEquals(names.size, names.toSet().size) for (spec in ASSISTANT_TOOL_SPECS) { assertTrue(snake.matches(spec.name), spec.name)@@ -71,6 +71,7 @@ class AssistantToolsTest { "food_prepare_order.tip_cents", "place_food_order.merchant_id", "search_products.limit", "shop_add_to_cart.quantity", "calculator_convert_unit.value",+ "news_search_headlines.limit", "news_top_stories.limit", "news_read_article.offset", ), numeric, )