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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ android {
value.toInt().also { require(it > 0) { "hapiVersionCode must be positive" } }
}.orElse(1).get()
// Tracks the hapi CLI/hub release train.
versionName = providers.gradleProperty("hapiVersionName").orElse("0.34.4").get()
versionName = providers.gradleProperty("hapiVersionName").orElse("0.34.5").get()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import app.hapi.data.push.PushPayload
* heads-up + sound interruption is the point.
* - `input_requests` — HIGH: an agent needs an answer, not tool approval.
* - `ready` — DEFAULT: the agent finished and is waiting for input.
* - `task_notifications` — DEFAULT: task completed/failed; also the bucket
* for unknown types / contract versions (never heads-up for those).
* - [PushPayload.CHANNEL_OTHER] — DEFAULT: the bucket for unknown types /
* contract versions (never heads-up for those).
*
* minSdk is 26, so the channel APIs are unconditionally available. Importance
* is only a creation-time default — operators can retune per channel in
Expand Down Expand Up @@ -50,11 +50,11 @@ object NotificationChannels {
description = context.getString(R.string.channel_ready_desc)
},
NotificationChannel(
PushPayload.CHANNEL_TASK_NOTIFICATIONS,
context.getString(R.string.channel_task_notifications),
PushPayload.CHANNEL_OTHER,
context.getString(R.string.channel_other),
NotificationManager.IMPORTANCE_DEFAULT,
).apply {
description = context.getString(R.string.channel_task_notifications_desc)
description = context.getString(R.string.channel_other_desc)
},
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import app.hapi.data.push.PushType
* Actions (contract v1, known types only):
* - `permission-request` → Allow / Deny → [NotificationActionReceiver] →
* expedited [PermissionActionWorker].
* - `ready` / `task-notification` → inline Reply (RemoteInput) →
* - `ready` → inline Reply (RemoteInput) →
* [SendMessageWorker]; plus a mark-as-read style Dismiss.
*
* Unknown types / contract versions render title+body with tap-to-open only.
Expand All @@ -40,12 +40,10 @@ object PushNotifications {

const val KEY_REMOTE_INPUT = "hapi_reply"

/** Severity accents per `hub/src/fcm/fcmService.ts` (blue/green/amber/red). */
/** Severity accents per `hub/src/fcm/fcmService.ts` (blue/amber). */
private fun severityColor(severity: PushSeverity?): Int? = when (severity) {
PushSeverity.INFO -> 0xFF3B82F6.toInt()
PushSeverity.SUCCESS -> 0xFF22C55E.toInt()
PushSeverity.WARNING -> 0xFFF59E0B.toInt()
PushSeverity.ERROR -> 0xFFEF4444.toInt()
null -> null
}

Expand All @@ -63,7 +61,7 @@ object PushNotifications {
if (payload.supportsActions) {
when (payload.type) {
PushType.PERMISSION_REQUEST -> addPermissionActions(context, builder, payload)
PushType.READY, PushType.TASK_NOTIFICATION -> addReplyActions(context, builder, payload)
PushType.READY -> addReplyActions(context, builder, payload)
PushType.INPUT_REQUEST, null -> Unit
}
}
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@
<string name="channel_input_requests_desc">Агенту нужен ваш ответ на вопрос в сессии</string>
<string name="channel_ready">Агент готов</string>
<string name="channel_ready_desc">Агент завершил работу и ждёт ввода</string>
<string name="channel_task_notifications">Уведомления о задачах</string>
<string name="channel_task_notifications_desc">Задача выполнена или завершилась с ошибкой, а также другие обновления</string>
<string name="channel_other">Другие уведомления</string>
<string name="channel_other_desc">Прочие обновления от HAPI</string>
<string name="notif_action_allow">Разрешить</string>
<string name="notif_action_deny">Отклонить</string>
<string name="notif_action_reply">Ответить</string>
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@
<string name="channel_input_requests_desc">智能体需要您进入会话回答问题</string>
<string name="channel_ready">代理就绪</string>
<string name="channel_ready_desc">智能体已完成并正在等待输入</string>
<string name="channel_task_notifications">任务通知</string>
<string name="channel_task_notifications_desc">任务完成或失败等更新</string>
<string name="channel_other">其他通知</string>
<string name="channel_other_desc">来自 HAPI 的其他更新</string>
<string name="notif_action_allow">允许</string>
<string name="notif_action_deny">拒绝</string>
<string name="notif_action_reply">回复</string>
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@
<string name="channel_input_requests_desc">An agent needs you to answer a question in the session</string>
<string name="channel_ready">Agent ready</string>
<string name="channel_ready_desc">An agent finished and is waiting for input</string>
<string name="channel_task_notifications">Task notifications</string>
<string name="channel_task_notifications_desc">Task completed or failed, and other updates</string>
<string name="channel_other">Other notifications</string>
<string name="channel_other_desc">Other updates from HAPI</string>
<string name="notif_action_allow">Allow</string>
<string name="notif_action_deny">Deny</string>
<string name="notif_action_reply">Reply</string>
Expand Down
24 changes: 13 additions & 11 deletions android/core/data/src/main/kotlin/app/hapi/data/push/PushPayload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import kotlinx.serialization.Serializable
enum class PushType(val wire: String) {
READY("ready"),
PERMISSION_REQUEST("permission-request"),
INPUT_REQUEST("input-request"),
TASK_NOTIFICATION("task-notification");
INPUT_REQUEST("input-request");

companion object {
fun fromWire(value: String): PushType? = entries.firstOrNull { it.wire == value }
Expand All @@ -23,9 +22,7 @@ enum class PushType(val wire: String) {
/** `data.severity` — visual urgency accent (`hub/src/fcm/fcmService.ts`). */
enum class PushSeverity(val wire: String) {
INFO("info"),
SUCCESS("success"),
WARNING("warning"),
ERROR("error");
WARNING("warning");

companion object {
fun fromWire(value: String?): PushSeverity? =
Expand Down Expand Up @@ -96,23 +93,23 @@ data class PushPayload(
get() = isKnownContractVersion && when (type) {
PushType.PERMISSION_REQUEST -> requestId != null
PushType.INPUT_REQUEST -> false // Answer in the session, not via approval or message Reply.
PushType.READY, PushType.TASK_NOTIFICATION -> true
PushType.READY -> true
null -> false
}

/**
* Notification channel routing: `permission_requests` / `input_requests` (HIGH) /
* `ready` (DEFAULT) / `task_notifications` (DEFAULT). Unknown types and
* `ready` (DEFAULT) / [CHANNEL_OTHER] (DEFAULT). Unknown types and
* unknown contract versions land in the default-importance
* `task_notifications` bucket — never in the heads-up channel.
* [CHANNEL_OTHER] bucket — never in the heads-up channel.
*/
val channelId: String
get() = when {
!isKnownContractVersion -> CHANNEL_TASK_NOTIFICATIONS
!isKnownContractVersion -> CHANNEL_OTHER
type == PushType.PERMISSION_REQUEST -> CHANNEL_PERMISSION_REQUESTS
type == PushType.INPUT_REQUEST -> CHANNEL_INPUT_REQUESTS
type == PushType.READY -> CHANNEL_READY
else -> CHANNEL_TASK_NOTIFICATIONS
else -> CHANNEL_OTHER
}

/**
Expand Down Expand Up @@ -155,7 +152,12 @@ data class PushPayload(
const val CHANNEL_PERMISSION_REQUESTS = "permission_requests"
const val CHANNEL_INPUT_REQUESTS = "input_requests"
const val CHANNEL_READY = "ready"
const val CHANNEL_TASK_NOTIFICATIONS = "task_notifications"
/**
* Fallback bucket for unknown types / contract versions. The ID is
* kept from the former task-notification channel so operators'
* per-channel system settings survive.
*/
const val CHANNEL_OTHER = "task_notifications"

private const val DEFAULT_TITLE = "HAPI"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PushEnvelopeTest {
@Test
fun `encrypted and direct pushes retain the same rendering and actions`() {
val decoder = PushMessageDecoder { key }
for (type in listOf("permission-request", "input-request", "ready", "task-notification")) {
for (type in listOf("permission-request", "input-request", "ready")) {
val plain = mapOf("type" to type, "sessionId" to "s1", "requestId" to "r1", "contractVersion" to "1",
"title" to "请求权限", "body" to "完成 😀", "severity" to "warning")
val encrypted = mapOf("hapi_v" to "1", "hapi_e" to encrypt(Json.encodeToString(plain)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PushPayloadTest {
assertFalse(payload.supportsActions)
assertEquals("input-request-${payload.sessionId}", payload.notificationTag)
assertEquals(if (version == "1") PushPayload.CHANNEL_INPUT_REQUESTS
else PushPayload.CHANNEL_TASK_NOTIFICATIONS, payload.channelId)
else PushPayload.CHANNEL_OTHER, payload.channelId)
}
}

Expand All @@ -80,9 +80,7 @@ class PushPayloadTest {
@Test
fun `all severities decode and unknown severity degrades to null`() {
assertEquals(PushSeverity.INFO, PushPayload.parse(permissionData("severity" to "info"))!!.severity)
assertEquals(PushSeverity.SUCCESS, PushPayload.parse(permissionData("severity" to "success"))!!.severity)
assertEquals(PushSeverity.WARNING, PushPayload.parse(permissionData("severity" to "warning"))!!.severity)
assertEquals(PushSeverity.ERROR, PushPayload.parse(permissionData("severity" to "error"))!!.severity)
assertNull(PushPayload.parse(permissionData("severity" to "catastrophic"))!!.severity)
assertNull(PushPayload.parse(permissionData().minus("severity"))!!.severity)
}
Expand All @@ -99,10 +97,6 @@ class PushPayloadTest {
PushPayload.CHANNEL_READY,
PushPayload.parse(permissionData("type" to "ready"))!!.channelId,
)
assertEquals(
PushPayload.CHANNEL_TASK_NOTIFICATIONS,
PushPayload.parse(permissionData("type" to "task-notification"))!!.channelId,
)
}

@Test
Expand All @@ -111,7 +105,7 @@ class PushPayloadTest {

assertNull(payload.type)
assertEquals("mystery-event", payload.rawType)
assertEquals(PushPayload.CHANNEL_TASK_NOTIFICATIONS, payload.channelId)
assertEquals(PushPayload.CHANNEL_OTHER, payload.channelId)
assertEquals("mystery-event-11111111-2222-3333-4444-555555555555", payload.notificationTag)
assertEquals("Permission Request", payload.displayTitle)
assertFalse(payload.supportsActions)
Expand All @@ -123,7 +117,7 @@ class PushPayloadTest {

assertFalse(payload.isKnownContractVersion)
assertFalse(payload.supportsActions) // v2 action semantics are unknowable
assertEquals(PushPayload.CHANNEL_TASK_NOTIFICATIONS, payload.channelId) // never heads-up
assertEquals(PushPayload.CHANNEL_OTHER, payload.channelId) // never heads-up
assertEquals("Permission Request", payload.displayTitle)
assertEquals("Claude Edit: hub/server.ts\nSession: Claude - hapi", payload.displayBody)
}
Expand Down
Loading
Loading