Scheduled on the server's real routes: runs in full, the models, the push
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
api/Schedules.kt and ApiClient now follow /api/v2 exactly (src/lembas/api/v2/schedules.py):
the schedule's enabled/description/request/rule, a run's model object, error class and
text, waiting and retry, preview; compile returns ok/reason and the rule in words; a run
in full (GET runs/{run}, Markdown through Markwon); the scheduling models (GET/PUT) with
a tick per model; /events keeps the list current while it is on screen.
Notifications are built from the payload notify.py sends (ids, status, private, actions,
ask): VISIBILITY_PRIVATE with a public version, Open always, Pause when the server offers
it, a tap opens the run (switching to the instance it came from).
ScheduleContractTest reads all eight fixtures and the push payload; shots for the run and
the models screen, fakes shaped like the fixtures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
25 files changed
+1335
-208
No files matched your search
+17
-8
@@ -29,14 +29,23 @@ is in alpha and releases come off `main`.
|
||||
### Added
|
||||
|
||||
- **Scheduled**: in the drawer. Each scheduled task with its rule in words, how its last run
|
||||
went and when it runs next, and a switch to pause it. A task's page has Run now, Pause, its
|
||||
next runs and its history (each run's result, the model that ran it -- and when another one
|
||||
stood in because the first was busy -- and Open for the result). A new task is said in words;
|
||||
the instance shows what it understood and the next five runs before anything is saved. Needs
|
||||
a LLeMbas server with scheduling (2.0.0-beta.6); an older one says so.
|
||||
- **Notifications for scheduled tasks**, on two channels of their own (results, and failures):
|
||||
on the lock screen they say only that a task finished or failed; unlocked, they show the
|
||||
result's first lines, with **Open** (the run's result) and **Pause**.
|
||||
went (or that it is running now) and when it runs next, and a switch to pause it; the list
|
||||
keeps itself current while it is open. A task's page has Run now (which does not use up the
|
||||
next scheduled run), Pause, its next runs and its history: each run's status, when, the model
|
||||
that ran it -- and which one it stood in for when the first was busy -- the first lines of its
|
||||
result, or why it failed or what it is waiting for and when it tries again. **A run opens its
|
||||
result in full**, with Open its chat. A new task is said in words; the instance shows what it
|
||||
understood -- the title, the rule in words, the instruction and the next five runs -- before
|
||||
anything is saved, and says why when it could not make out all of it. Editing starts from
|
||||
the words the task was made from. **Models for scheduled tasks** (the button at the top of
|
||||
Scheduled): the models scheduled work runs on, in the order they are tried, which are free
|
||||
right now, and a tick to leave one out. Needs a LLeMbas server with scheduling (2.0.0-beta.6);
|
||||
an older one says so.
|
||||
- **Notifications for scheduled tasks**, on two channels of their own (results, and failures).
|
||||
They carry no content -- the instance sends only that a task finished or failed, and which
|
||||
run -- and on the lock screen they show only the app's name and that sentence. A tap, or
|
||||
**Open**, goes to the run's result; a failure offers **Pause**, and after three failures in
|
||||
a row the notification asks whether to pause the task.
|
||||
- **Screenshots of every screen on each change**: the CI run renders the screens with made-up
|
||||
data, light and dark, on a large and a small phone and with large type, and keeps the
|
||||
pictures with the run.
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
@@ -34,24 +35,28 @@ import eu.llembas.android.api.Chat
|
||||
import eu.llembas.android.auth.Instance
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.push.Notifications
|
||||
import eu.llembas.android.push.Push
|
||||
import eu.llembas.android.ui.chat.ChatScreen
|
||||
import eu.llembas.android.ui.files.FilesScreen
|
||||
import eu.llembas.android.ui.home.ChatsViewModel
|
||||
import eu.llembas.android.ui.home.DrawerActions
|
||||
import eu.llembas.android.ui.home.DrawerContent
|
||||
import eu.llembas.android.ui.scheduled.RunScreen
|
||||
import eu.llembas.android.ui.scheduled.ScheduleEditScreen
|
||||
import eu.llembas.android.ui.scheduled.ScheduleScreen
|
||||
import eu.llembas.android.ui.scheduled.ScheduledScreen
|
||||
import eu.llembas.android.ui.scheduled.SchedulingModelsScreen
|
||||
import eu.llembas.android.ui.settings.SettingsScreen
|
||||
import eu.llembas.android.ui.signin.SignInScreen
|
||||
import eu.llembas.android.ui.theme.LembasTheme
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private data class Loaded(val instance: Instance?)
|
||||
|
||||
/** Where a notification (or the assistant, or a share) asked the app to open. */
|
||||
private data class Opening(val chat: String?, val schedule: String?)
|
||||
private data class Opening(val chat: String?, val schedule: String?, val run: String? = null, val instance: String? = null)
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
/** A chat or a schedule a notification, the assistant or a share asked to open; consumed once. */
|
||||
@@ -82,7 +87,19 @@ class MainActivity : ComponentActivity() {
|
||||
private fun take(intent: Intent?) {
|
||||
val chat = intent?.getStringExtra(Notifications.EXTRA_CHAT)
|
||||
val schedule = intent?.getStringExtra(Notifications.EXTRA_SCHEDULE)
|
||||
if (chat != null || schedule != null) opening.value = Opening(chat, schedule)
|
||||
val run = intent?.getStringExtra(Notifications.EXTRA_RUN)
|
||||
val instance = intent?.getStringExtra(Notifications.EXTRA_INSTANCE)
|
||||
if (chat == null && schedule == null) return
|
||||
opening.value = Opening(chat, schedule, run, instance)
|
||||
// A notification from another of the person's instances: that one comes into use, and
|
||||
// its pages (keyed by the instance) open what was asked.
|
||||
if (instance != null) {
|
||||
lifecycleScope.launch {
|
||||
if (lembas.instances.active.first()?.id != instance && Push.instance(this@MainActivity, instance) != null) {
|
||||
lembas.instances.use(instance)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -129,9 +146,15 @@ class MainActivity : ComponentActivity() {
|
||||
LaunchedEffect(drawer.isOpen) { if (drawer.isOpen) chats.load() }
|
||||
LaunchedEffect(open) {
|
||||
open?.let {
|
||||
// Meant for another instance: left for that one's pages, once it is in use.
|
||||
if (it.instance != null && it.instance != instance.id) return@let
|
||||
when {
|
||||
it.chat != null -> top("chat/${it.chat}")
|
||||
it.schedule != null -> over("schedule/${it.schedule}")
|
||||
|
||||
it.schedule != null -> {
|
||||
over("schedule/${it.schedule}")
|
||||
it.run?.let { run -> over("schedule/${it.schedule}/run/$run") }
|
||||
}
|
||||
}
|
||||
opened()
|
||||
}
|
||||
@@ -196,11 +219,32 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
composable("files") { FilesScreen(onBack = { nav.popBackStack() }) }
|
||||
composable("scheduled") {
|
||||
ScheduledScreen(onBack = { nav.popBackStack() }, onOpen = { over("schedule/$it") }, onNew = { over("schedule-new") })
|
||||
ScheduledScreen(
|
||||
onBack = { nav.popBackStack() },
|
||||
onOpen = { over("schedule/$it") },
|
||||
onNew = { over("schedule-new") },
|
||||
onModels = { over("scheduled-models") },
|
||||
)
|
||||
}
|
||||
composable("scheduled-models") {
|
||||
SchedulingModelsScreen(onBack = { nav.popBackStack() })
|
||||
}
|
||||
composable("schedule/{id}") { e ->
|
||||
val id = e.arguments?.getString("id").orEmpty()
|
||||
ScheduleScreen(id, onBack = { nav.popBackStack() }, onEdit = { over("schedule-edit/$it") }, onOpenChat = { top("chat/$it") })
|
||||
ScheduleScreen(
|
||||
id,
|
||||
onBack = { nav.popBackStack() },
|
||||
onEdit = { over("schedule-edit/$it") },
|
||||
onOpenRun = { run -> over("schedule/$id/run/$run") },
|
||||
)
|
||||
}
|
||||
composable("schedule/{id}/run/{run}") { e ->
|
||||
RunScreen(
|
||||
e.arguments?.getString("id").orEmpty(),
|
||||
e.arguments?.getString("run").orEmpty(),
|
||||
onBack = { nav.popBackStack() },
|
||||
onOpenChat = { top("chat/$it") },
|
||||
)
|
||||
}
|
||||
composable("schedule-new") {
|
||||
ScheduleEditScreen(null, onBack = { nav.popBackStack() }, onSaved = { id ->
|
||||
|
||||
@@ -252,24 +252,44 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
|
||||
suspend fun stopMember(chatId: String, name: String): List<String> = send<Stopped>("POST", "/chats/$chatId/team/${segment(name)}/stop", null).stopped
|
||||
|
||||
// --- Scheduled tasks (provisional routes; see api/Schedules.kt) ---------------------------
|
||||
// --- Scheduled tasks (`/api/v2/schedules`; shapes in api/Schedules.kt) ----------------------
|
||||
|
||||
/** Every schedule of this person, newest first, each with its last run. */
|
||||
suspend fun schedules(): List<Schedule> = get<ScheduleList>("/schedules").schedules
|
||||
|
||||
suspend fun schedule(id: String): Schedule = get<ScheduleEnvelope>("/schedules/${segment(id)}").schedule
|
||||
|
||||
suspend fun scheduleRuns(id: String, before: String? = null): ScheduleRuns =
|
||||
get("/schedules/${segment(id)}/runs" + (before?.let { "?before=${segment(it)}" } ?: ""))
|
||||
/** A page of a schedule's runs, newest first; [before] is the last run's id of the page before. */
|
||||
suspend fun scheduleRuns(id: String, before: String? = null, limit: Int = 20): ScheduleRuns =
|
||||
get("/schedules/${segment(id)}/runs?limit=$limit" + (before?.let { "&before=${segment(it)}" } ?: ""))
|
||||
|
||||
/** Words to a rule, an instruction and the next runs; nothing is saved. */
|
||||
suspend fun compileSchedule(words: String): SchedulePreview =
|
||||
send<SchedulePreviewEnvelope>("POST", "/schedules/compile", buildJsonObject { put("text", words) }).preview
|
||||
/** One run and its result in full (Markdown a model wrote: untrusted). */
|
||||
suspend fun scheduleRun(id: String, runId: String): RunResult = get("/schedules/${segment(id)}/runs/${segment(runId)}")
|
||||
|
||||
/** Save a preview: a new schedule, or (with [id]) the one being edited. */
|
||||
suspend fun saveSchedule(preview: SchedulePreview, id: String? = null): Schedule {
|
||||
/** Words to a schedule: title, instruction, rule, the rule in words, the next runs. Saves nothing. */
|
||||
suspend fun compileSchedule(words: String, model: String? = null): ScheduleCompiled = send(
|
||||
"POST",
|
||||
"/schedules/compile",
|
||||
buildJsonObject {
|
||||
put("text", words)
|
||||
model?.let { put("model", it) }
|
||||
},
|
||||
)
|
||||
|
||||
/** A rule read back: cleaned, in words, and its next runs. An empty rule cannot run. */
|
||||
suspend fun previewRule(rule: JsonObject): RulePreview = send("POST", "/schedules/preview", buildJsonObject { put("rule", rule) })
|
||||
|
||||
/**
|
||||
* Save what the compile made of [words]: a new schedule (201), or with [id] the one being
|
||||
* edited. The words go along as the schedule's `request`, so editing starts from them.
|
||||
*/
|
||||
suspend fun saveSchedule(compiled: ScheduleCompiled, words: String, id: String? = null): Schedule {
|
||||
val body = buildJsonObject {
|
||||
put("title", preview.title)
|
||||
put("instruction", preview.instruction)
|
||||
preview.rule?.let { put("rule", it) }
|
||||
put("title", compiled.title)
|
||||
put("instruction", compiled.instruction)
|
||||
put("rule", compiled.rule)
|
||||
put("target", compiled.target)
|
||||
if (id == null) put("request", words)
|
||||
}
|
||||
return if (id == null) {
|
||||
send<ScheduleEnvelope>("POST", "/schedules", body).schedule
|
||||
@@ -281,11 +301,21 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
suspend fun pauseSchedule(id: String, paused: Boolean): Schedule =
|
||||
send<ScheduleEnvelope>("POST", "/schedules/${segment(id)}/" + if (paused) "pause" else "resume", null).schedule
|
||||
|
||||
suspend fun runScheduleNow(id: String) {
|
||||
send<JsonObject>("POST", "/schedules/${segment(id)}/run", null)
|
||||
}
|
||||
/** Run it now (202); the next scheduled run is not used up by this one. */
|
||||
suspend fun runScheduleNow(id: String): ScheduleRun = send<RunEnvelope>("POST", "/schedules/${segment(id)}/run", null).run
|
||||
|
||||
suspend fun deleteSchedule(id: String) = empty(authed("$v2/schedules/${segment(id)}").delete().build())
|
||||
/** Delete it; [keepChat] keeps the chat its results went to. */
|
||||
suspend fun deleteSchedule(id: String, keepChat: Boolean = true) = empty(authed("$v2/schedules/${segment(id)}?keep_chat=$keepChat").delete().build())
|
||||
|
||||
/** The models scheduled work may run on, in the order they are tried, and which are free. */
|
||||
suspend fun schedulingModels(): SchedulingModels = get("/schedules/models")
|
||||
|
||||
/** The person's narrowing of that list ([ids] empty: all of them). */
|
||||
suspend fun chooseSchedulingModels(ids: List<String>): SchedulingModels =
|
||||
send("PUT", "/schedules/models", buildJsonObject { put("models", JsonArray(ids.map { JsonPrimitive(it) })) })
|
||||
|
||||
/** The person's events route: a `schedules` frame with the whole list whenever it changes. */
|
||||
fun events(): Request = authed("$v2/events").header("Accept", "text/event-stream").build()
|
||||
|
||||
// --- Model pictures --------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -486,9 +486,17 @@ data class PushPayload(
|
||||
@SerialName("message_id") val messageId: String? = null,
|
||||
@SerialName("interaction_id") val interactionId: String? = null,
|
||||
val ask: String? = null,
|
||||
/** A scheduled task's result or failure (`kind` `schedule` or `schedule_failed`). */
|
||||
/**
|
||||
* A scheduled run's result or failure (`kind` `schedule` or `schedule_failed`,
|
||||
* services/schedule/notify.py): the ids, the run's [status], `private` [visibility] (the
|
||||
* text stays off the lock screen), the [actions] the notification may offer (`open`,
|
||||
* `pause`), and [ask] `pause` when it failed so often that it asks whether to pause it.
|
||||
*/
|
||||
@SerialName("schedule_id") val scheduleId: String? = null,
|
||||
@SerialName("run_id") val runId: String? = null,
|
||||
val status: String? = null,
|
||||
val visibility: String? = null,
|
||||
val actions: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
// --- The activity panel (`GET /chats/{chat}/activity`) -------------------------------------
|
||||
|
||||
@@ -6,56 +6,100 @@ import kotlinx.serialization.json.JsonObject
|
||||
|
||||
// --- Scheduled tasks (`/api/v2/schedules`) ------------------------------------------------
|
||||
//
|
||||
// Provisional: written against the server's scheduling plan before its routes and contract
|
||||
// fixtures landed. Every field has a default, so a server that says less still parses; the
|
||||
// contract re-pin is where these meet the server's real shapes (and `ContractTest` holds them).
|
||||
// The server's shapes, as its contract fixtures pin them (`contract/schedule*.json`,
|
||||
// `event_schedules.json`; `ContractTest` reads every one). Every field has a default, so a
|
||||
// server that says less still parses.
|
||||
|
||||
/** The model a run used: [reason] `switched` when it stood in for [switchedFrom], which was busy. */
|
||||
@Serializable
|
||||
data class RunModel(
|
||||
val id: String? = null,
|
||||
val name: String? = null,
|
||||
val reason: String? = null,
|
||||
@SerialName("switched_from") val switchedFrom: String? = null,
|
||||
) {
|
||||
/** What to call it: its name, else its id. */
|
||||
val label: String? get() = name ?: id
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class RunTokens(val prompt: Long = 0, val completion: Long = 0)
|
||||
|
||||
@Serializable
|
||||
data class RunCost(val micro: Long = 0, val currency: String = "")
|
||||
|
||||
/** Why a run failed or waits: [kind] a class the app may read, [text] the server's own sentence. */
|
||||
@Serializable
|
||||
data class RunError(@SerialName("class") val kind: String = "", val text: String = "")
|
||||
|
||||
/**
|
||||
* One run of a schedule: when it was due and how it went. [status] is `ok`, `silent` (nothing
|
||||
* worth saying), `failed`, `missed`, `skipped`, `waiting` (no model free yet) or `running`;
|
||||
* [timing] `on_time`, `late` or `catch_up`. [error] is the server's sentence, never a model's.
|
||||
* One run of a schedule: when it was due and how it went. [status] is `running`, `waiting` (no
|
||||
* model free yet, or a retry: [waitingFor], [retryAt]), `ok`, `silent` (nothing worth saying),
|
||||
* `failed`, `skipped` or `missed`; [timing] `on_time`, `late`, `catch_up` or `manual`.
|
||||
* [preview] is the result's first lines -- model output, shown as plain text and never as markup.
|
||||
*/
|
||||
@Serializable
|
||||
data class ScheduleRun(
|
||||
val id: String = "",
|
||||
@SerialName("schedule_id") val scheduleId: String = "",
|
||||
val status: String = "",
|
||||
val timing: String = "",
|
||||
/** How many runs were missed before this one (`missed ×N`). */
|
||||
val missed: Int = 0,
|
||||
@SerialName("due_at") val dueAt: String? = null,
|
||||
@SerialName("started_at") val startedAt: String? = null,
|
||||
@SerialName("finished_at") val finishedAt: String? = null,
|
||||
val status: String = "",
|
||||
val timing: String = "",
|
||||
val model: String = "",
|
||||
/** `pinned`, or the reason another model ran it (`switched: <from> busy`). */
|
||||
@SerialName("model_reason") val modelReason: String = "",
|
||||
@SerialName("waiting_for") val waitingFor: String? = null,
|
||||
@SerialName("retry_at") val retryAt: String? = null,
|
||||
val attempts: Int = 0,
|
||||
val model: RunModel = RunModel(),
|
||||
val tokens: RunTokens = RunTokens(),
|
||||
val cost: RunCost? = null,
|
||||
@SerialName("chat_id") val chatId: String? = null,
|
||||
@SerialName("message_id") val messageId: String? = null,
|
||||
@SerialName("report_path") val reportPath: String? = null,
|
||||
val error: String = "",
|
||||
/** How many runs were missed before this one (`missed ×N`). */
|
||||
val missed: Int = 0,
|
||||
val preview: String = "",
|
||||
val error: RunError? = null,
|
||||
val notified: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* A scheduled task. [rule] is the recurrence in words, as the server says it ("Every weekday at
|
||||
* 08:00"); [instruction] what the model is asked each time. [notify] is `always`, `matters` or
|
||||
* `never`; [mode] `fresh` (a chat per run) or `continue` (one growing chat).
|
||||
* A scheduled task. [description] is the rule in words, as the server says it ("On the second
|
||||
* Monday of each month at 07:30"), in [timezone]; [rule] the server's own form of it; [request]
|
||||
* the person's words it was made from; [instruction] what the model is asked each time.
|
||||
* [notify] is `always`, `matters` or `never`; [mode] `fresh` (a chat per run) or `continue`.
|
||||
*/
|
||||
@Serializable
|
||||
data class Schedule(
|
||||
val id: String,
|
||||
val title: String = "",
|
||||
val instruction: String = "",
|
||||
val rule: String = "",
|
||||
val paused: Boolean = false,
|
||||
val request: String = "",
|
||||
val rule: JsonObject = JsonObject(emptyMap()),
|
||||
val description: String? = null,
|
||||
val timezone: String = "",
|
||||
val enabled: Boolean = true,
|
||||
@SerialName("next_run") val nextRun: String? = null,
|
||||
@SerialName("next_runs") val nextRuns: List<String> = emptyList(),
|
||||
@SerialName("last_run") val lastRun: ScheduleRun? = null,
|
||||
val model: String = "",
|
||||
val notify: String = "",
|
||||
val target: String = "chat",
|
||||
val mode: String = "",
|
||||
@SerialName("failure_streak") val failureStreak: Int = 0,
|
||||
val notify: String = "",
|
||||
@SerialName("catch_up") val catchUp: String = "",
|
||||
@SerialName("grace_minutes") val graceMinutes: Int? = null,
|
||||
val model: String? = null,
|
||||
val effort: String? = null,
|
||||
val agents: Int? = null,
|
||||
val tools: List<String> = emptyList(),
|
||||
val origin: String = "",
|
||||
@SerialName("chat_id") val chatId: String? = null,
|
||||
@SerialName("fired_count") val firedCount: Int = 0,
|
||||
@SerialName("failure_streak") val failureStreak: Int = 0,
|
||||
@SerialName("last_error") val lastError: String? = null,
|
||||
@SerialName("last_run") val lastRun: ScheduleRun? = null,
|
||||
val running: Boolean = false,
|
||||
@SerialName("created_at") val createdAt: String? = null,
|
||||
) {
|
||||
val nextRun: String? get() = nextRuns.firstOrNull()
|
||||
val paused: Boolean get() = !enabled
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -64,22 +108,64 @@ data class ScheduleList(val schedules: List<Schedule> = emptyList())
|
||||
@Serializable
|
||||
data class ScheduleEnvelope(val schedule: Schedule)
|
||||
|
||||
@Serializable
|
||||
data class RunEnvelope(val run: ScheduleRun)
|
||||
|
||||
@Serializable
|
||||
data class ScheduleRuns(val runs: List<ScheduleRun> = emptyList(), val more: Boolean = false)
|
||||
|
||||
/** One run and its result in full: Markdown a model wrote, rendered as untrusted. Null: none. */
|
||||
@Serializable
|
||||
data class RunResult(val run: ScheduleRun, val text: String? = null)
|
||||
|
||||
/** `GET /events`, frame `schedules`: the whole list whenever [version] moves. */
|
||||
@Serializable
|
||||
data class SchedulesFrame(val version: String = "", val schedules: List<Schedule> = emptyList())
|
||||
|
||||
/**
|
||||
* What the server made of a person's words: a title, the rule in words, the instruction the
|
||||
* model will be given, and the next five runs -- shown before anything is saved. [rule] is the
|
||||
* server's own form of the rule, handed back unchanged when the preview is saved.
|
||||
* What the server made of a person's words (`POST /schedules/compile`): a title, the
|
||||
* instruction, the rule and the rule in words, and the next runs -- shown before anything is
|
||||
* saved. [ok] false: the rest is filled as far as it went, and [reason] says why. An empty
|
||||
* [rule] cannot run, so it cannot be saved.
|
||||
*/
|
||||
@Serializable
|
||||
data class SchedulePreview(
|
||||
data class ScheduleCompiled(
|
||||
val ok: Boolean = false,
|
||||
val reason: String? = null,
|
||||
val title: String = "",
|
||||
@SerialName("rule_text") val ruleText: String = "",
|
||||
val instruction: String = "",
|
||||
val target: String = "chat",
|
||||
val rule: JsonObject = JsonObject(emptyMap()),
|
||||
val description: String? = null,
|
||||
@SerialName("next_runs") val nextRuns: List<String> = emptyList(),
|
||||
val rule: JsonObject? = null,
|
||||
val timezone: String = "",
|
||||
) {
|
||||
val savable: Boolean get() = rule.isNotEmpty() && instruction.isNotBlank()
|
||||
}
|
||||
|
||||
/** A rule read back (`POST /schedules/preview`): cleaned, in words, and its next runs. */
|
||||
@Serializable
|
||||
data class RulePreview(
|
||||
val rule: JsonObject = JsonObject(emptyMap()),
|
||||
val description: String? = null,
|
||||
@SerialName("next_runs") val nextRuns: List<String> = emptyList(),
|
||||
val timezone: String = "",
|
||||
)
|
||||
|
||||
/**
|
||||
* A model scheduled work may run on, in the order they are tried: [free] now or [busy] (the
|
||||
* server's words), and [chosen] when it is in the person's narrowing (all are, without one).
|
||||
*/
|
||||
@Serializable
|
||||
data class SchedulePreviewEnvelope(val preview: SchedulePreview)
|
||||
data class SchedulingModel(
|
||||
val id: String,
|
||||
val name: String = "",
|
||||
val image: String? = null,
|
||||
val free: Boolean = false,
|
||||
val busy: String? = null,
|
||||
val chosen: Boolean = true,
|
||||
)
|
||||
|
||||
/** `GET`/`PUT /schedules/models`: the models, the instance's order, and the person's narrowing. */
|
||||
@Serializable
|
||||
data class SchedulingModels(val models: List<SchedulingModel> = emptyList(), val instance: List<String> = emptyList(), val mine: List<String> = emptyList())
|
||||
@@ -99,6 +99,7 @@ object Notifications {
|
||||
const val EXTRA_INSTANCE = "eu.llembas.android.INSTANCE"
|
||||
|
||||
const val EXTRA_SCHEDULE = "eu.llembas.android.SCHEDULE"
|
||||
const val EXTRA_RUN = "eu.llembas.android.RUN"
|
||||
|
||||
fun show(context: Context, instance: String, payload: PushPayload) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return
|
||||
@@ -130,48 +131,50 @@ object Notifications {
|
||||
}
|
||||
|
||||
/**
|
||||
* A scheduled task's result or failure, on its own channel. The result's first lines are
|
||||
* the account's, so the lock screen gets the public version instead: the app's name and
|
||||
* "a scheduled task finished" (or failed), nothing of what it said. Open goes to the run's
|
||||
* result (its chat) or else the schedule; Pause pauses the schedule from here.
|
||||
* A scheduled run's result or failure, on its own channel, built from the server's payload
|
||||
* alone ([ScheduledNotice]): the payload carries ids and one of the server's own fixed
|
||||
* sentences, never the result. Unlocked: the instance's name and that sentence. On the lock
|
||||
* screen the public version: the app's name and "a scheduled task has a result" (or failed).
|
||||
* A tap and Open go to the run; Pause is there when the server offers it.
|
||||
*/
|
||||
private fun scheduled(context: Context, instance: String, payload: PushPayload) {
|
||||
val failed = payload.kind == "schedule_failed"
|
||||
val id = (payload.runId ?: payload.scheduleId ?: payload.url).hashCode()
|
||||
val channel = if (failed) LembasApp.CHANNEL_SCHEDULED_FAILURES else LembasApp.CHANNEL_SCHEDULED
|
||||
val open = opener(context, instance, id, chatId = payload.chatId, scheduleId = payload.scheduleId.takeIf { payload.chatId == null })
|
||||
val notice = ScheduledNotice.from(payload) ?: return
|
||||
val channel = if (notice.failed) LembasApp.CHANNEL_SCHEDULED_FAILURES else LembasApp.CHANNEL_SCHEDULED
|
||||
val fixed = context.getString(if (notice.failed) R.string.scheduled_failed_public else R.string.scheduled_result_public)
|
||||
val open = opener(context, instance, notice.id, chatId = null, scheduleId = notice.scheduleId, runId = notice.runId)
|
||||
val public = NotificationCompat.Builder(context, channel)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setContentText(context.getString(if (failed) R.string.scheduled_failed_public else R.string.scheduled_result_public))
|
||||
.setContentText(fixed)
|
||||
.build()
|
||||
val body = payload.body.ifBlank { fixed }
|
||||
val builder = NotificationCompat.Builder(context, channel)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(payload.title)
|
||||
.setContentText(payload.body)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(payload.body))
|
||||
.setContentTitle(payload.title.ifBlank { context.getString(R.string.scheduled) })
|
||||
.setContentText(body)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(open)
|
||||
.setCategory(if (failed) Notification.CATEGORY_ERROR else Notification.CATEGORY_STATUS)
|
||||
.setCategory(if (notice.failed) Notification.CATEGORY_ERROR else Notification.CATEGORY_STATUS)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||
.setPublicVersion(public)
|
||||
.addAction(0, context.getString(R.string.viewer_open), open)
|
||||
payload.scheduleId?.let { schedule ->
|
||||
builder.addAction(0, context.getString(R.string.schedule_pause), pause(context, instance, schedule, id))
|
||||
}
|
||||
NotificationManagerCompat.from(context).notify(id, builder.build())
|
||||
if (notice.open) builder.addAction(0, context.getString(R.string.viewer_open), open)
|
||||
if (notice.pause) builder.addAction(0, context.getString(R.string.schedule_pause), pause(context, instance, notice.scheduleId, notice.id))
|
||||
NotificationManagerCompat.from(context).notify(notice.id, builder.build())
|
||||
}
|
||||
|
||||
private fun opener(context: Context, instance: String, id: Int, chatId: String?, scheduleId: String? = null): PendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
id,
|
||||
Intent(context, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(EXTRA_CHAT, chatId)
|
||||
.putExtra(EXTRA_SCHEDULE, scheduleId)
|
||||
.putExtra(EXTRA_INSTANCE, instance),
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||
)
|
||||
private fun opener(context: Context, instance: String, id: Int, chatId: String?, scheduleId: String? = null, runId: String? = null): PendingIntent =
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
id,
|
||||
Intent(context, MainActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(EXTRA_CHAT, chatId)
|
||||
.putExtra(EXTRA_SCHEDULE, scheduleId)
|
||||
.putExtra(EXTRA_RUN, runId)
|
||||
.putExtra(EXTRA_INSTANCE, instance),
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||
)
|
||||
|
||||
private fun pause(context: Context, instance: String, schedule: String, notification: Int): PendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package eu.llembas.android.push
|
||||
|
||||
import eu.llembas.android.api.PushPayload
|
||||
|
||||
/**
|
||||
* What a scheduled run's push asks the app to show, read from the server's payload alone
|
||||
* (services/schedule/notify.py `payload`): the schedule and the run it is about, whether it
|
||||
* failed, and the actions the server offers. A payload without ids falls back to its `url`
|
||||
* (`/scheduled/{schedule}?run={run}`), as a browser would open it.
|
||||
*/
|
||||
data class ScheduledNotice(
|
||||
val scheduleId: String,
|
||||
val runId: String?,
|
||||
val failed: Boolean,
|
||||
/** The server asks whether to pause it (it failed several times in a row). */
|
||||
val askPause: Boolean,
|
||||
val open: Boolean,
|
||||
val pause: Boolean,
|
||||
) {
|
||||
/** One notification per run: a later push about the same run replaces it. */
|
||||
val id: Int get() = "scheduled:${runId ?: scheduleId}".hashCode()
|
||||
|
||||
companion object {
|
||||
const val KIND_RESULT = "schedule"
|
||||
const val KIND_FAILED = "schedule_failed"
|
||||
|
||||
fun from(payload: PushPayload): ScheduledNotice? {
|
||||
if (payload.kind != KIND_RESULT && payload.kind != KIND_FAILED) return null
|
||||
val (urlSchedule, urlRun) = fromUrl(payload.url)
|
||||
val schedule = payload.scheduleId?.takeIf { it.isNotBlank() } ?: urlSchedule ?: return null
|
||||
val run = payload.runId?.takeIf { it.isNotBlank() } ?: urlRun
|
||||
val failed = payload.kind == KIND_FAILED
|
||||
val askPause = payload.ask == "pause"
|
||||
// An older payload named no actions: Open always, Pause for a failure.
|
||||
val actions = payload.actions.ifEmpty { if (failed) listOf("open", "pause") else listOf("open") }
|
||||
return ScheduledNotice(
|
||||
scheduleId = schedule,
|
||||
runId = run,
|
||||
failed = failed,
|
||||
askPause = askPause,
|
||||
open = "open" in actions,
|
||||
pause = "pause" in actions || askPause,
|
||||
)
|
||||
}
|
||||
|
||||
/** `/scheduled/{schedule}?run={run}` → the two ids; nulls for anything else. */
|
||||
fun fromUrl(url: String): Pair<String?, String?> {
|
||||
if (!url.startsWith("/scheduled/")) return null to null
|
||||
val rest = url.removePrefix("/scheduled/")
|
||||
val schedule = rest.substringBefore('?').substringBefore('/').takeIf { it.isNotBlank() }
|
||||
val run = rest.substringAfter('?', "").split('&').firstOrNull { it.startsWith("run=") }?.removePrefix("run=")?.takeIf { it.isNotBlank() }
|
||||
return schedule to run
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package eu.llembas.android.ui.scheduled
|
||||
|
||||
import android.app.Application
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.compose.LifecycleResumeEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.ApiException
|
||||
import eu.llembas.android.api.RunResult
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.ui.chat.LocalCopy
|
||||
import eu.llembas.android.ui.chat.RichMarkdown
|
||||
import eu.llembas.android.ui.explain
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class RunState(val title: String = "", val result: RunResult? = null, val loading: Boolean = false, val error: String? = null)
|
||||
|
||||
class RunViewModel(app: Application) : AndroidViewModel(app) {
|
||||
private val _state = MutableStateFlow(RunState())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
/** The run and its result; the schedule's title too, for the bar (without it, "Scheduled"). */
|
||||
fun open(schedule: String, run: String) {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(loading = true, error = null) }
|
||||
try {
|
||||
val api = getApplication<Application>().lembas.instances.client() ?: throw ApiException(401, "Not signed in.")
|
||||
val result = api.scheduleRun(schedule, run)
|
||||
val title = runCatching { api.schedule(schedule).title }.getOrDefault("")
|
||||
_state.update { it.copy(result = result, title = title, loading = false) }
|
||||
} catch (e: Exception) {
|
||||
_state.update { it.copy(loading = false, error = getApplication<Application>().explain(e)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RunScreen(
|
||||
scheduleId: String,
|
||||
runId: String,
|
||||
onBack: () -> Unit,
|
||||
onOpenChat: (String) -> Unit,
|
||||
model: RunViewModel = viewModel(key = "run-$scheduleId-$runId"),
|
||||
) {
|
||||
val state by model.state.collectAsStateWithLifecycle()
|
||||
LifecycleResumeEffect(runId) {
|
||||
model.open(scheduleId, runId)
|
||||
onPauseOrDispose { }
|
||||
}
|
||||
RunContent(state, onBack = onBack, onOpenChat = onOpenChat)
|
||||
}
|
||||
|
||||
/**
|
||||
* One run, where a notification's tap lands: its status and when, the model and why, and the
|
||||
* result in full -- Markdown a model wrote, drawn by the app's Markwon (no images, no HTML,
|
||||
* links only outside) -- or why there is none. Open its chat goes on from there.
|
||||
*/
|
||||
@Composable
|
||||
fun RunContent(state: RunState, onBack: () -> Unit = {}, onOpenChat: (String) -> Unit = {}) {
|
||||
val palette = LocalPalette.current
|
||||
val context = LocalContext.current
|
||||
val copy: (String) -> Unit = remember(context) {
|
||||
{ text -> context.getSystemService(ClipboardManager::class.java)?.setPrimaryClip(ClipData.newPlainText("LLeMbas", text)) }
|
||||
}
|
||||
val result = state.result
|
||||
CompositionLocalProvider(LocalCopy provides copy) {
|
||||
Scaffold(
|
||||
containerColor = palette.bg,
|
||||
topBar = { BackBar(state.title.ifBlank { stringResource(R.string.scheduled) }, onBack) },
|
||||
) { padding ->
|
||||
if (result == null) {
|
||||
Box(Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {
|
||||
if (state.loading) CircularProgressIndicator() else state.error?.let { Message(it) }
|
||||
}
|
||||
return@Scaffold
|
||||
}
|
||||
val run = result.run
|
||||
Column(
|
||||
Modifier.fillMaxSize().padding(padding).verticalScroll(rememberScrollState()).padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Surface(shape = RoundedCornerShape(20.dp), color = palette.surfaceRaised, contentColor = palette.ink, modifier = Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
StatusChip(run.status, run.missed)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
ScheduleLogic.moment(run.finishedAt ?: run.startedAt ?: run.dueAt) ?: "—",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
RunFacts(run, withPreview = false)
|
||||
}
|
||||
}
|
||||
Header(stringResource(R.string.run_result))
|
||||
val text = result.text
|
||||
if (text.isNullOrBlank()) {
|
||||
Text(stringResource(R.string.run_no_text), style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
|
||||
} else {
|
||||
RichMarkdown(text)
|
||||
}
|
||||
run.chatId?.let { chat ->
|
||||
FilledTonalButton(onClick = { onOpenChat(chat) }, modifier = Modifier.fillMaxWidth().heightIn(min = 48.dp).padding(top = 8.dp)) {
|
||||
Text(stringResource(R.string.run_open_chat))
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.heightIn(min = 24.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import androidx.compose.material.icons.filled.Edit
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Schedule
|
||||
import androidx.compose.material.icons.filled.Tune
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
@@ -73,13 +74,18 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.ApiClient
|
||||
import eu.llembas.android.api.ApiException
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.Schedule
|
||||
import eu.llembas.android.api.SchedulePreview
|
||||
import eu.llembas.android.api.ScheduleCompiled
|
||||
import eu.llembas.android.api.ScheduleRun
|
||||
import eu.llembas.android.api.SchedulesFrame
|
||||
import eu.llembas.android.api.StreamClient
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.ui.explain
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import eu.llembas.android.ui.theme.Palette
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -103,11 +109,14 @@ class ScheduledViewModel(app: Application) : AndroidViewModel(app) {
|
||||
private val _state = MutableStateFlow(ScheduledState())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
private var live: Job? = null
|
||||
|
||||
fun load() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(loading = true, error = null) }
|
||||
try {
|
||||
_state.value = ScheduledState(schedules = getApplication<Application>().api().schedules())
|
||||
watch()
|
||||
} catch (e: Exception) {
|
||||
_state.update {
|
||||
if (e.unsupported()) {
|
||||
@@ -123,9 +132,37 @@ class ScheduledViewModel(app: Application) : AndroidViewModel(app) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The person's events route while the list is on screen: the whole list again whenever it
|
||||
* changes (a run starting, waiting or finishing, a schedule made or paused elsewhere).
|
||||
* Without it the list is what the last read said, and a pull reads it again.
|
||||
*/
|
||||
private fun watch() {
|
||||
if (live?.isActive == true) return
|
||||
live = viewModelScope.launch {
|
||||
val client = runCatching { getApplication<Application>().api() }.getOrNull() ?: return@launch
|
||||
try {
|
||||
StreamClient(client).watch { client.events() }.collect { frame ->
|
||||
if (frame.event != "schedules") return@collect
|
||||
val read = runCatching { LembasJson.decodeFromString(SchedulesFrame.serializer(), frame.data) }.getOrNull() ?: return@collect
|
||||
_state.update { it.copy(schedules = read.schedules) }
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (_: Exception) {
|
||||
// An older server, or the stream refused: the list stays as last read.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
live?.cancel()
|
||||
live = null
|
||||
}
|
||||
|
||||
/** Pause or resume; the switch moves at once and comes back if the server says no. */
|
||||
fun pause(schedule: Schedule, paused: Boolean) {
|
||||
_state.update { s -> s.copy(schedules = s.schedules.map { if (it.id == schedule.id) it.copy(paused = paused) else it }) }
|
||||
_state.update { s -> s.copy(schedules = s.schedules.map { if (it.id == schedule.id) it.copy(enabled = !paused) else it }) }
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val saved = getApplication<Application>().api().pauseSchedule(schedule.id, paused)
|
||||
@@ -143,13 +180,13 @@ class ScheduledViewModel(app: Application) : AndroidViewModel(app) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ScheduledScreen(onBack: () -> Unit, onOpen: (String) -> Unit, onNew: () -> Unit, model: ScheduledViewModel = viewModel()) {
|
||||
fun ScheduledScreen(onBack: () -> Unit, onOpen: (String) -> Unit, onNew: () -> Unit, onModels: () -> Unit, model: ScheduledViewModel = viewModel()) {
|
||||
val state by model.state.collectAsStateWithLifecycle()
|
||||
LifecycleResumeEffect(Unit) {
|
||||
model.load()
|
||||
onPauseOrDispose { }
|
||||
onPauseOrDispose { model.stop() }
|
||||
}
|
||||
ScheduledContent(state, onBack = onBack, onOpen = onOpen, onNew = onNew, onPause = model::pause, onRetry = model::load)
|
||||
ScheduledContent(state, onBack = onBack, onOpen = onOpen, onNew = onNew, onModels = onModels, onPause = model::pause, onRetry = model::load)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,13 +199,20 @@ fun ScheduledContent(
|
||||
onBack: () -> Unit = {},
|
||||
onOpen: (String) -> Unit = {},
|
||||
onNew: () -> Unit = {},
|
||||
onModels: () -> Unit = {},
|
||||
onPause: (Schedule, Boolean) -> Unit = { _, _ -> },
|
||||
onRetry: () -> Unit = {},
|
||||
) {
|
||||
val palette = LocalPalette.current
|
||||
Scaffold(
|
||||
containerColor = palette.bg,
|
||||
topBar = { BackBar(stringResource(R.string.scheduled), onBack) },
|
||||
topBar = {
|
||||
BackBar(stringResource(R.string.scheduled), onBack) {
|
||||
if (!state.unsupported) {
|
||||
IconButton(onClick = onModels) { Icon(Icons.Filled.Tune, contentDescription = stringResource(R.string.schedule_models)) }
|
||||
}
|
||||
}
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (!state.unsupported) {
|
||||
ExtendedFloatingActionButton(
|
||||
@@ -220,11 +264,12 @@ private fun ScheduleCard(schedule: Schedule, onOpen: () -> Unit, onPause: (Boole
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (schedule.rule.isNotBlank()) {
|
||||
Text(schedule.rule, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
|
||||
schedule.description?.takeIf { it.isNotBlank() }?.let {
|
||||
Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 4.dp)) {
|
||||
schedule.lastRun?.let { StatusChip(it.status, it.missed) }
|
||||
val shown = if (schedule.running) "running" else schedule.lastRun?.status
|
||||
shown?.let { StatusChip(it, schedule.lastRun?.missed ?: 0) }
|
||||
val next = when {
|
||||
schedule.paused -> stringResource(R.string.schedule_paused)
|
||||
else -> ScheduleLogic.moment(schedule.nextRun)?.let { stringResource(R.string.schedule_next, it) }
|
||||
@@ -236,7 +281,7 @@ private fun ScheduleCard(schedule: Schedule, onOpen: () -> Unit, onPause: (Boole
|
||||
color = palette.inkFaint,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(start = if (schedule.lastRun != null) 8.dp else 0.dp),
|
||||
modifier = Modifier.padding(start = if (shown != null) 8.dp else 0.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -275,7 +320,7 @@ private fun toneColours(palette: Palette, tone: Tone): Pair<Color, Color> = when
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BackBar(title: String, onBack: () -> Unit, actions: @Composable () -> Unit = {}) {
|
||||
internal fun BackBar(title: String, onBack: () -> Unit, actions: @Composable () -> Unit = {}) {
|
||||
val palette = LocalPalette.current
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.topAppBarColors(containerColor = palette.bg, scrolledContainerColor = palette.bg),
|
||||
@@ -286,7 +331,7 @@ private fun BackBar(title: String, onBack: () -> Unit, actions: @Composable () -
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Message(text: String, retry: (() -> Unit)? = null) {
|
||||
internal fun Message(text: String, retry: (() -> Unit)? = null) {
|
||||
val palette = LocalPalette.current
|
||||
Column(
|
||||
Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(32.dp),
|
||||
@@ -341,9 +386,10 @@ class ScheduleViewModel(app: Application) : AndroidViewModel(app) {
|
||||
}
|
||||
|
||||
fun runNow() = act { api, s ->
|
||||
api.runScheduleNow(s.id)
|
||||
_state.update { it.copy(notice = getApplication<Application>().getString(R.string.schedule_started)) }
|
||||
id?.let(::open)
|
||||
val run = api.runScheduleNow(s.id)
|
||||
_state.update { st ->
|
||||
st.copy(runs = listOf(run) + st.runs.filter { it.id != run.id }, notice = getApplication<Application>().getString(R.string.schedule_started))
|
||||
}
|
||||
}
|
||||
|
||||
fun pause(paused: Boolean) = act { api, s -> _state.update { it.copy(schedule = api.pauseSchedule(s.id, paused)) } }
|
||||
@@ -372,7 +418,7 @@ fun ScheduleScreen(
|
||||
id: String,
|
||||
onBack: () -> Unit,
|
||||
onEdit: (String) -> Unit,
|
||||
onOpenChat: (String) -> Unit,
|
||||
onOpenRun: (String) -> Unit,
|
||||
model: ScheduleViewModel = viewModel(key = "schedule-$id"),
|
||||
) {
|
||||
val state by model.state.collectAsStateWithLifecycle()
|
||||
@@ -395,15 +441,15 @@ fun ScheduleScreen(
|
||||
onDelete = { model.delete(onBack) },
|
||||
onRunNow = model::runNow,
|
||||
onPause = model::pause,
|
||||
onOpenRun = { run -> run.chatId?.let(onOpenChat) },
|
||||
onOpenRun = { run -> onOpenRun(run.id) },
|
||||
onMore = model::more,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* One schedule: what it does and when, Run now and Pause side by side (equal halves), the next
|
||||
* runs, and its history -- each run's status, when, the model that ran it and why, and Open for
|
||||
* its result.
|
||||
* runs, and its history -- each run's status, when, the model that ran it and why, the first
|
||||
* lines of its result; a run opens its result in full.
|
||||
*/
|
||||
@Composable
|
||||
fun ScheduleContent(
|
||||
@@ -477,11 +523,12 @@ private fun ScheduleBody(
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Schedule, contentDescription = null, tint = palette.accent, modifier = Modifier.size(20.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(schedule.rule, style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f))
|
||||
Text(schedule.description.orEmpty(), style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f))
|
||||
}
|
||||
Text(schedule.instruction, style = MaterialTheme.typography.bodyMedium)
|
||||
val facts = listOfNotNull(
|
||||
schedule.model.ifBlank { null }?.let { stringResource(R.string.schedule_model, it) },
|
||||
schedule.model?.takeIf { it.isNotBlank() }?.let { stringResource(R.string.schedule_model, it) },
|
||||
modeWords(schedule.mode),
|
||||
notifyWords(schedule.notify),
|
||||
)
|
||||
if (facts.isNotEmpty()) {
|
||||
@@ -540,13 +587,20 @@ private fun ScheduleBody(
|
||||
@Composable
|
||||
private fun notifyWords(notify: String): String? = when (notify) {
|
||||
"always" -> stringResource(R.string.notify_always)
|
||||
"matters", "when_matters" -> stringResource(R.string.notify_matters)
|
||||
"matters" -> stringResource(R.string.notify_matters)
|
||||
"never" -> stringResource(R.string.notify_never)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Header(text: String) {
|
||||
private fun modeWords(mode: String): String? = when (mode) {
|
||||
"fresh" -> stringResource(R.string.mode_fresh)
|
||||
"continue" -> stringResource(R.string.mode_continue)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Header(text: String) {
|
||||
Text(
|
||||
text,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
@@ -555,35 +609,62 @@ private fun Header(text: String) {
|
||||
)
|
||||
}
|
||||
|
||||
/** A run: its status (a fixed column, so the times line up), when, the model, and Open. */
|
||||
/**
|
||||
* A run: its status (a fixed column, so the times line up), when, the model, and the first
|
||||
* lines of its result (model output: plain text, never markup) or why it failed or waits. The
|
||||
* whole row opens the run.
|
||||
*/
|
||||
@Composable
|
||||
private fun RunRow(run: ScheduleRun, onOpen: () -> Unit) {
|
||||
val palette = LocalPalette.current
|
||||
Surface(shape = RoundedCornerShape(16.dp), color = palette.surfaceRaised, contentColor = palette.ink, modifier = Modifier.fillMaxWidth()) {
|
||||
Row(Modifier.heightIn(min = 64.dp).padding(start = 12.dp, end = 4.dp, top = 8.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Surface(
|
||||
onClick = onOpen,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = palette.surfaceRaised,
|
||||
contentColor = palette.ink,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Row(Modifier.heightIn(min = 64.dp).padding(horizontal = 12.dp, vertical = 10.dp), verticalAlignment = Alignment.Top) {
|
||||
Box(Modifier.width(112.dp)) { StatusChip(run.status, run.missed) }
|
||||
Column(Modifier.weight(1f)) {
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
Text(ScheduleLogic.moment(run.startedAt ?: run.dueAt) ?: "—", style = MaterialTheme.typography.bodyMedium)
|
||||
val model = when {
|
||||
run.model.isBlank() -> null
|
||||
run.modelReason.startsWith("switched") -> stringResource(R.string.run_model_switched, run.model)
|
||||
else -> run.model
|
||||
}
|
||||
model?.let { Text(it, style = MaterialTheme.typography.bodySmall, color = palette.inkMuted, maxLines = 1, overflow = TextOverflow.Ellipsis) }
|
||||
if (run.error.isNotBlank()) {
|
||||
Text(run.error, style = MaterialTheme.typography.bodySmall, color = palette.danger, maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
RunFacts(run, maxLines = 2)
|
||||
}
|
||||
if (run.chatId != null) TextButton(onClick = onOpen) { Text(stringResource(R.string.viewer_open)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Under a run's time: the model and why, then the result's first lines, or the trouble. */
|
||||
@Composable
|
||||
internal fun RunFacts(run: ScheduleRun, maxLines: Int = Int.MAX_VALUE, withPreview: Boolean = true) {
|
||||
val palette = LocalPalette.current
|
||||
val name = run.model.label
|
||||
val from = run.model.switchedFrom
|
||||
val model = when {
|
||||
name == null -> null
|
||||
run.model.reason == "switched" && from != null -> stringResource(R.string.run_model_instead, name, from)
|
||||
else -> name
|
||||
}
|
||||
model?.let { Text(it, style = MaterialTheme.typography.bodySmall, color = palette.inkMuted, maxLines = 1, overflow = TextOverflow.Ellipsis) }
|
||||
if (run.status == "waiting") {
|
||||
ScheduleLogic.moment(run.retryAt)?.let {
|
||||
Text(stringResource(R.string.run_retry_at, it), style = MaterialTheme.typography.bodySmall, color = palette.warning, maxLines = 1)
|
||||
}
|
||||
}
|
||||
run.error?.text?.takeIf { it.isNotBlank() }?.let {
|
||||
val tone = if (run.status == "waiting") palette.inkMuted else palette.danger
|
||||
Text(it, style = MaterialTheme.typography.bodySmall, color = tone, maxLines = maxLines, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
if (withPreview && run.preview.isNotBlank()) {
|
||||
Text(run.preview, style = MaterialTheme.typography.bodySmall, color = palette.ink, maxLines = maxLines, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Create and edit ------------------------------------------------------------------------
|
||||
|
||||
data class EditState(
|
||||
val words: String = "",
|
||||
val preview: SchedulePreview? = null,
|
||||
val compiled: ScheduleCompiled? = null,
|
||||
val compiling: Boolean = false,
|
||||
val saving: Boolean = false,
|
||||
val error: String? = null,
|
||||
@@ -596,7 +677,7 @@ class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
|
||||
private var editing: String? = null
|
||||
private var started = false
|
||||
|
||||
/** Begin: empty for a new schedule, the schedule's own words for one being edited. */
|
||||
/** Begin: empty for a new schedule, the words a schedule was made from for one being edited. */
|
||||
fun start(id: String?) {
|
||||
if (started) return
|
||||
started = true
|
||||
@@ -604,22 +685,22 @@ class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
|
||||
if (id == null) return
|
||||
viewModelScope.launch {
|
||||
runCatching { getApplication<Application>().api().schedule(id) }.onSuccess { s ->
|
||||
_state.update { it.copy(words = listOf(s.rule, s.instruction).filter { w -> w.isNotBlank() }.joinToString(": ")) }
|
||||
_state.update { it.copy(words = s.request.ifBlank { s.instruction }) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun words(text: String) = _state.update { it.copy(words = text, preview = null) }
|
||||
fun words(text: String) = _state.update { it.copy(words = text, compiled = null) }
|
||||
|
||||
/** The server reads the words: the rule, the instruction and the next runs come back. */
|
||||
/** The server reads the words: the title, the instruction, the rule and the next runs. */
|
||||
fun preview() {
|
||||
val words = _state.value.words.trim()
|
||||
if (words.isEmpty()) return
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(compiling = true, error = null) }
|
||||
try {
|
||||
val preview = getApplication<Application>().api().compileSchedule(words)
|
||||
_state.update { it.copy(preview = preview, compiling = false) }
|
||||
val compiled = getApplication<Application>().api().compileSchedule(words)
|
||||
_state.update { it.copy(compiled = compiled, compiling = false) }
|
||||
} catch (e: Exception) {
|
||||
_state.update {
|
||||
it.copy(compiling = false, unsupported = e.unsupported(), error = if (e.unsupported()) null else getApplication<Application>().explain(e))
|
||||
@@ -629,11 +710,11 @@ class ScheduleEditViewModel(app: Application) : AndroidViewModel(app) {
|
||||
}
|
||||
|
||||
fun save(then: (String) -> Unit) {
|
||||
val preview = _state.value.preview ?: return
|
||||
val compiled = _state.value.compiled?.takeIf { it.savable } ?: return
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(saving = true, error = null) }
|
||||
try {
|
||||
val saved = getApplication<Application>().api().saveSchedule(preview, editing)
|
||||
val saved = getApplication<Application>().api().saveSchedule(compiled, _state.value.words.trim(), editing)
|
||||
then(saved.id)
|
||||
} catch (e: Exception) {
|
||||
_state.update { it.copy(saving = false, error = getApplication<Application>().explain(e)) }
|
||||
@@ -656,8 +737,9 @@ fun ScheduleEditScreen(
|
||||
|
||||
/**
|
||||
* A schedule in words: the person says when and what, the server reads it, and the preview
|
||||
* shows what it understood -- the rule in words, the instruction, the next five runs -- before
|
||||
* anything is saved. Save stays at the foot, out of the way of the keyboard.
|
||||
* shows what it understood -- the title, the rule in words, the instruction, the next five runs
|
||||
* -- before anything is saved. When it could not make out all of it, it says why, and Save
|
||||
* waits for words it can. Save stays at the foot, out of the way of the keyboard.
|
||||
*/
|
||||
@Composable
|
||||
fun ScheduleEditContent(
|
||||
@@ -676,7 +758,7 @@ fun ScheduleEditContent(
|
||||
Box(Modifier.background(palette.bg).navigationBarsPadding().imePadding().padding(16.dp)) {
|
||||
Button(
|
||||
onClick = onSave,
|
||||
enabled = state.preview != null && !state.saving,
|
||||
enabled = state.compiled?.savable == true && !state.saving,
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 52.dp),
|
||||
) { Text(stringResource(R.string.save)) }
|
||||
}
|
||||
@@ -708,30 +790,38 @@ fun ScheduleEditContent(
|
||||
}
|
||||
if (state.unsupported) Text(stringResource(R.string.scheduled_unsupported), color = palette.inkMuted)
|
||||
state.error?.let { Text(it, color = palette.danger, style = MaterialTheme.typography.bodyMedium) }
|
||||
state.preview?.let { p ->
|
||||
Surface(shape = RoundedCornerShape(20.dp), color = palette.surfaceRaised, contentColor = palette.ink, modifier = Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(stringResource(R.string.schedule_understood), style = MaterialTheme.typography.labelLarge, color = palette.accent)
|
||||
if (p.title.isNotBlank()) Text(p.title, style = MaterialTheme.typography.titleMedium)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Schedule, contentDescription = null, tint = palette.inkMuted, modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(p.ruleText, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f))
|
||||
}
|
||||
Text(p.instruction, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
|
||||
val next = ScheduleLogic.upcoming(p.nextRuns)
|
||||
if (next.isNotEmpty()) {
|
||||
Text(
|
||||
stringResource(R.string.schedule_next_runs),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
)
|
||||
next.forEach { Text(it, style = MaterialTheme.typography.bodyMedium) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
state.compiled?.let { Understood(it) }
|
||||
Spacer(Modifier.height(24.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** What the server made of the words. The title and instruction are a model's: plain text. */
|
||||
@Composable
|
||||
private fun Understood(c: ScheduleCompiled) {
|
||||
val palette = LocalPalette.current
|
||||
Surface(shape = RoundedCornerShape(20.dp), color = palette.surfaceRaised, contentColor = palette.ink, modifier = Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(stringResource(R.string.schedule_understood), style = MaterialTheme.typography.labelLarge, color = palette.accent)
|
||||
c.reason?.takeIf { it.isNotBlank() }?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.warning) }
|
||||
if (c.title.isNotBlank()) Text(c.title, style = MaterialTheme.typography.titleMedium)
|
||||
c.description?.takeIf { it.isNotBlank() }?.let { words ->
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Schedule, contentDescription = null, tint = palette.inkMuted, modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(words, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
if (c.instruction.isNotBlank()) Text(c.instruction, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
|
||||
val next = ScheduleLogic.upcoming(c.nextRuns)
|
||||
if (next.isNotEmpty()) {
|
||||
Text(
|
||||
stringResource(R.string.schedule_next_runs),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
modifier = Modifier.padding(top = 8.dp),
|
||||
)
|
||||
next.forEach { Text(it, style = MaterialTheme.typography.bodyMedium) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package eu.llembas.android.ui.scheduled
|
||||
|
||||
import android.app.Application
|
||||
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.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CheckboxDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.compose.LifecycleResumeEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.ApiException
|
||||
import eu.llembas.android.api.SchedulingModel
|
||||
import eu.llembas.android.api.SchedulingModels
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.ui.explain
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class ModelsState(val models: SchedulingModels? = null, val loading: Boolean = false, val error: String? = null)
|
||||
|
||||
class SchedulingModelsViewModel(app: Application) : AndroidViewModel(app) {
|
||||
private val _state = MutableStateFlow(ModelsState())
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
private suspend fun api() = getApplication<Application>().lembas.instances.client() ?: throw ApiException(401, "Not signed in.")
|
||||
|
||||
fun load() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(loading = true, error = null) }
|
||||
try {
|
||||
val models = api().schedulingModels()
|
||||
_state.update { it.copy(models = models, loading = false) }
|
||||
} catch (e: Exception) {
|
||||
_state.update { it.copy(loading = false, error = getApplication<Application>().explain(e)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Tick or untick one; the server keeps the person's narrowing and answers the whole list. */
|
||||
fun toggle(model: SchedulingModel) {
|
||||
val now = _state.value.models ?: return
|
||||
val chosen = SchedulingLogic.toggled(now.models, model.id) ?: return
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val saved = api().chooseSchedulingModels(chosen)
|
||||
_state.update { it.copy(models = saved, error = null) }
|
||||
} catch (e: Exception) {
|
||||
_state.update { it.copy(error = getApplication<Application>().explain(e)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The narrowing a tick makes, pure so it can be tested. */
|
||||
object SchedulingLogic {
|
||||
/**
|
||||
* The ids to send after ticking or unticking [id]: in the list's order; empty when every
|
||||
* one is ticked (the server's "no narrowing"). Null when it would untick the last one --
|
||||
* scheduled work needs at least one model.
|
||||
*/
|
||||
fun toggled(models: List<SchedulingModel>, id: String): List<String>? {
|
||||
val chosen = models.filter { if (it.id == id) !it.chosen else it.chosen }.map { it.id }
|
||||
return when {
|
||||
chosen.isEmpty() -> null
|
||||
chosen.size == models.size -> emptyList()
|
||||
else -> chosen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SchedulingModelsScreen(onBack: () -> Unit, model: SchedulingModelsViewModel = viewModel()) {
|
||||
val state by model.state.collectAsStateWithLifecycle()
|
||||
LifecycleResumeEffect(Unit) {
|
||||
model.load()
|
||||
onPauseOrDispose { }
|
||||
}
|
||||
SchedulingModelsContent(state, onBack = onBack, onToggle = model::toggle, onRetry = model::load)
|
||||
}
|
||||
|
||||
/**
|
||||
* The models scheduled tasks run on, in the order they are tried -- each with whether it is free
|
||||
* now or busy (the server's words) -- and a tick for the person's own narrowing of the list.
|
||||
*/
|
||||
@Composable
|
||||
fun SchedulingModelsContent(state: ModelsState, onBack: () -> Unit = {}, onToggle: (SchedulingModel) -> Unit = {}, onRetry: () -> Unit = {}) {
|
||||
val palette = LocalPalette.current
|
||||
val models = state.models?.models.orEmpty()
|
||||
Scaffold(containerColor = palette.bg, topBar = { BackBar(stringResource(R.string.schedule_models), onBack) }) { padding ->
|
||||
PullToRefreshBox(isRefreshing = state.loading, onRefresh = onRetry, modifier = Modifier.fillMaxSize().padding(padding)) {
|
||||
if (models.isEmpty() && state.error != null) {
|
||||
Message(state.error, retry = onRetry)
|
||||
return@PullToRefreshBox
|
||||
}
|
||||
LazyColumn(
|
||||
Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 4.dp, bottom = 32.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
item {
|
||||
Text(
|
||||
stringResource(R.string.schedule_models_hint),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = palette.inkMuted,
|
||||
modifier = Modifier.padding(start = 4.dp, end = 4.dp, bottom = 8.dp),
|
||||
)
|
||||
}
|
||||
state.error?.let { item { Text(it, color = palette.danger, style = MaterialTheme.typography.bodyMedium) } }
|
||||
items(models, key = { it.id }) { m -> ModelRow(m, onToggle = { onToggle(m) }) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ModelRow(model: SchedulingModel, onToggle: () -> Unit) {
|
||||
val palette = LocalPalette.current
|
||||
Surface(
|
||||
onClick = onToggle,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = palette.surfaceRaised,
|
||||
contentColor = palette.ink,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Row(Modifier.heightIn(min = 64.dp).padding(start = 4.dp, end = 16.dp, top = 8.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Checkbox(
|
||||
checked = model.chosen,
|
||||
onCheckedChange = { onToggle() },
|
||||
colors = CheckboxDefaults.colors(checkedColor = palette.accent, checkmarkColor = palette.accentInk, uncheckedColor = palette.inkMuted),
|
||||
)
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
Text(model.name.ifBlank { model.id }, style = MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
val (line, tone) = if (model.free) {
|
||||
stringResource(R.string.model_free) to palette.success
|
||||
} else {
|
||||
stringResource(R.string.model_busy, model.busy.orEmpty()).trimEnd(' ', ':') to palette.inkMuted
|
||||
}
|
||||
Text(line, style = MaterialTheme.typography.bodySmall, color = tone, maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Vynecháno</string>
|
||||
<string name="run_waiting">Čeká na model</string>
|
||||
<string name="run_running">Běží</string>
|
||||
<string name="run_model_switched">%1$s (první volba byla zaneprázdněná)</string>
|
||||
<string name="run_model_instead">%1$s, místo %2$s</string>
|
||||
<string name="run_retry_at">Zkusí to znovu v %1$s</string>
|
||||
<string name="run_result">Výsledek</string>
|
||||
<string name="run_no_text">Tento běh nezanechal žádný text.</string>
|
||||
<string name="run_open_chat">Otevřít jeho konverzaci</string>
|
||||
<string name="mode_fresh">Pokaždé nový chat</string>
|
||||
<string name="mode_continue">Jeden chat, který roste</string>
|
||||
<string name="schedule_models">Modely pro naplánované úlohy</string>
|
||||
<string name="schedule_models_hint">Naplánované úlohy vezmou první z nich, který je volný, v tomto pořadí. Zrušte zaškrtnutí, chcete-li některý vynechat.</string>
|
||||
<string name="model_free">Teď volný</string>
|
||||
<string name="model_busy">Zaneprázdněný: %1$s</string>
|
||||
<string name="channel_scheduled">Výsledky naplánovaných úloh</string>
|
||||
<string name="channel_scheduled_failures">Selhání naplánovaných úloh</string>
|
||||
<string name="scheduled_result_public">Naplánovaná úloha má výsledek.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Übersprungen</string>
|
||||
<string name="run_waiting">Wartet auf ein Modell</string>
|
||||
<string name="run_running">Läuft</string>
|
||||
<string name="run_model_switched">%1$s (die erste Wahl war beschäftigt)</string>
|
||||
<string name="run_model_instead">%1$s statt %2$s</string>
|
||||
<string name="run_retry_at">Neuer Versuch um %1$s</string>
|
||||
<string name="run_result">Ergebnis</string>
|
||||
<string name="run_no_text">Dieser Lauf hat keinen Text hinterlassen.</string>
|
||||
<string name="run_open_chat">Seinen Chat öffnen</string>
|
||||
<string name="mode_fresh">Jedes Mal ein neuer Chat</string>
|
||||
<string name="mode_continue">Ein Chat, der wächst</string>
|
||||
<string name="schedule_models">Modelle für geplante Aufgaben</string>
|
||||
<string name="schedule_models_hint">Geplante Aufgaben nehmen das erste davon, das frei ist, in dieser Reihenfolge. Entfernen Sie den Haken, um eines auszulassen.</string>
|
||||
<string name="model_free">Jetzt frei</string>
|
||||
<string name="model_busy">Belegt: %1$s</string>
|
||||
<string name="channel_scheduled">Geplante Ergebnisse</string>
|
||||
<string name="channel_scheduled_failures">Geplante Fehler</string>
|
||||
<string name="scheduled_result_public">Eine geplante Aufgabe hat ein Ergebnis.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Omitida</string>
|
||||
<string name="run_waiting">Esperando un modelo</string>
|
||||
<string name="run_running">En ejecución</string>
|
||||
<string name="run_model_switched">%1$s (la primera opción estaba ocupada)</string>
|
||||
<string name="run_model_instead">%1$s, en lugar de %2$s</string>
|
||||
<string name="run_retry_at">Lo intenta de nuevo a las %1$s</string>
|
||||
<string name="run_result">Resultado</string>
|
||||
<string name="run_no_text">Esta ejecución no dejó texto.</string>
|
||||
<string name="run_open_chat">Abrir su chat</string>
|
||||
<string name="mode_fresh">Un chat nuevo cada vez</string>
|
||||
<string name="mode_continue">Un chat que crece</string>
|
||||
<string name="schedule_models">Modelos para tareas programadas</string>
|
||||
<string name="schedule_models_hint">Las tareas programadas toman el primero de estos que esté libre, en este orden. Desmarque uno para dejarlo fuera.</string>
|
||||
<string name="model_free">Libre ahora</string>
|
||||
<string name="model_busy">Ocupado: %1$s</string>
|
||||
<string name="channel_scheduled">Resultados programados</string>
|
||||
<string name="channel_scheduled_failures">Fallos programados</string>
|
||||
<string name="scheduled_result_public">Una tarea programada tiene un resultado.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Sautée</string>
|
||||
<string name="run_waiting">En attente d’un modèle</string>
|
||||
<string name="run_running">En cours</string>
|
||||
<string name="run_model_switched">%1$s (le premier choix était occupé)</string>
|
||||
<string name="run_model_instead">%1$s, au lieu de %2$s</string>
|
||||
<string name="run_retry_at">Nouvel essai à %1$s</string>
|
||||
<string name="run_result">Résultat</string>
|
||||
<string name="run_no_text">Cette exécution n’a laissé aucun texte.</string>
|
||||
<string name="run_open_chat">Ouvrir sa conversation</string>
|
||||
<string name="mode_fresh">Une nouvelle discussion à chaque fois</string>
|
||||
<string name="mode_continue">Une discussion qui s’allonge</string>
|
||||
<string name="schedule_models">Modèles pour les tâches planifiées</string>
|
||||
<string name="schedule_models_hint">Les tâches planifiées prennent le premier de ces modèles qui est libre, dans cet ordre. Décochez-en un pour l’écarter.</string>
|
||||
<string name="model_free">Libre maintenant</string>
|
||||
<string name="model_busy">Occupé : %1$s</string>
|
||||
<string name="channel_scheduled">Résultats planifiés</string>
|
||||
<string name="channel_scheduled_failures">Échecs planifiés</string>
|
||||
<string name="scheduled_result_public">Une tâche planifiée a un résultat.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Kihagyva</string>
|
||||
<string name="run_waiting">Modellre vár</string>
|
||||
<string name="run_running">Fut</string>
|
||||
<string name="run_model_switched">%1$s (az első választás foglalt volt)</string>
|
||||
<string name="run_model_instead">%1$s, %2$s helyett</string>
|
||||
<string name="run_retry_at">Újrapróbálja: %1$s</string>
|
||||
<string name="run_result">Eredmény</string>
|
||||
<string name="run_no_text">Ez a futás nem hagyott szöveget.</string>
|
||||
<string name="run_open_chat">Csevegésének megnyitása</string>
|
||||
<string name="mode_fresh">Minden alkalommal új csevegés</string>
|
||||
<string name="mode_continue">Egy csevegés, amely bővül</string>
|
||||
<string name="schedule_models">Modellek az ütemezett feladatokhoz</string>
|
||||
<string name="schedule_models_hint">Az ütemezett feladatok ebben a sorrendben az első szabadot veszik. Vegye ki a pipát, hogy kihagyjon egyet.</string>
|
||||
<string name="model_free">Most szabad</string>
|
||||
<string name="model_busy">Foglalt: %1$s</string>
|
||||
<string name="channel_scheduled">Ütemezett eredmények</string>
|
||||
<string name="channel_scheduled_failures">Ütemezett hibák</string>
|
||||
<string name="scheduled_result_public">Egy ütemezett feladatnak eredménye van.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Ignorata</string>
|
||||
<string name="run_waiting">In attesa di un modello</string>
|
||||
<string name="run_running">In esecuzione</string>
|
||||
<string name="run_model_switched">%1$s (la prima scelta era occupata)</string>
|
||||
<string name="run_model_instead">%1$s, invece di %2$s</string>
|
||||
<string name="run_retry_at">Riprova alle %1$s</string>
|
||||
<string name="run_result">Risultato</string>
|
||||
<string name="run_no_text">Questa esecuzione non ha lasciato testo.</string>
|
||||
<string name="run_open_chat">Apri la sua chat</string>
|
||||
<string name="mode_fresh">Una nuova chat ogni volta</string>
|
||||
<string name="mode_continue">Una chat che cresce</string>
|
||||
<string name="schedule_models">Modelli per le attività pianificate</string>
|
||||
<string name="schedule_models_hint">Le attività pianificate usano il primo di questi che è libero, in quest’ordine. Togli la spunta per escluderne uno.</string>
|
||||
<string name="model_free">Libero ora</string>
|
||||
<string name="model_busy">Occupato: %1$s</string>
|
||||
<string name="channel_scheduled">Risultati pianificati</string>
|
||||
<string name="channel_scheduled_failures">Errori pianificati</string>
|
||||
<string name="scheduled_result_public">Un’attività pianificata ha un risultato.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Pominięto</string>
|
||||
<string name="run_waiting">Czeka na model</string>
|
||||
<string name="run_running">Działa</string>
|
||||
<string name="run_model_switched">%1$s (pierwszy wybór był zajęty)</string>
|
||||
<string name="run_model_instead">%1$s zamiast %2$s</string>
|
||||
<string name="run_retry_at">Ponowi próbę o %1$s</string>
|
||||
<string name="run_result">Wynik</string>
|
||||
<string name="run_no_text">To uruchomienie nie zostawiło tekstu.</string>
|
||||
<string name="run_open_chat">Otwórz jego czat</string>
|
||||
<string name="mode_fresh">Za każdym razem nowy czat</string>
|
||||
<string name="mode_continue">Jeden czat, który rośnie</string>
|
||||
<string name="schedule_models">Modele dla zaplanowanych zadań</string>
|
||||
<string name="schedule_models_hint">Zaplanowane zadania biorą pierwszy wolny z nich, w tej kolejności. Odznacz, aby któryś pominąć.</string>
|
||||
<string name="model_free">Teraz wolny</string>
|
||||
<string name="model_busy">Zajęty: %1$s</string>
|
||||
<string name="channel_scheduled">Wyniki zaplanowanych zadań</string>
|
||||
<string name="channel_scheduled_failures">Błędy zaplanowanych zadań</string>
|
||||
<string name="scheduled_result_public">Zaplanowane zadanie ma wynik.</string>
|
||||
|
||||
@@ -178,7 +178,17 @@
|
||||
<string name="run_skipped">Vynechané</string>
|
||||
<string name="run_waiting">Čaká na model</string>
|
||||
<string name="run_running">Beží</string>
|
||||
<string name="run_model_switched">%1$s (prvá voľba bola zaneprázdnená)</string>
|
||||
<string name="run_model_instead">%1$s, namiesto %2$s</string>
|
||||
<string name="run_retry_at">Skúsi to znova o %1$s</string>
|
||||
<string name="run_result">Výsledok</string>
|
||||
<string name="run_no_text">Tento beh nezanechal žiadny text.</string>
|
||||
<string name="run_open_chat">Otvoriť jeho konverzáciu</string>
|
||||
<string name="mode_fresh">Zakaždým nová konverzácia</string>
|
||||
<string name="mode_continue">Jedna konverzácia, ktorá rastie</string>
|
||||
<string name="schedule_models">Modely pre naplánované úlohy</string>
|
||||
<string name="schedule_models_hint">Naplánované úlohy vezmú prvý z nich, ktorý je voľný, v tomto poradí. Zrušte začiarknutie, ak niektorý chcete vynechať.</string>
|
||||
<string name="model_free">Teraz voľný</string>
|
||||
<string name="model_busy">Obsadený: %1$s</string>
|
||||
<string name="channel_scheduled">Výsledky naplánovaných úloh</string>
|
||||
<string name="channel_scheduled_failures">Zlyhania naplánovaných úloh</string>
|
||||
<string name="scheduled_result_public">Naplánovaná úloha má výsledok.</string>
|
||||
|
||||
@@ -179,7 +179,17 @@
|
||||
<string name="run_skipped">Skipped</string>
|
||||
<string name="run_waiting">Waiting for a model</string>
|
||||
<string name="run_running">Running</string>
|
||||
<string name="run_model_switched">%1$s (the first choice was busy)</string>
|
||||
<string name="run_model_instead">%1$s, instead of %2$s</string>
|
||||
<string name="run_retry_at">Tries again at %1$s</string>
|
||||
<string name="run_result">Result</string>
|
||||
<string name="run_no_text">This run left no text.</string>
|
||||
<string name="run_open_chat">Open its chat</string>
|
||||
<string name="mode_fresh">A new chat each time</string>
|
||||
<string name="mode_continue">One chat that grows</string>
|
||||
<string name="schedule_models">Models for scheduled tasks</string>
|
||||
<string name="schedule_models_hint">Scheduled tasks take the first of these that is free, in this order. Untick one to leave it out.</string>
|
||||
<string name="model_free">Free now</string>
|
||||
<string name="model_busy">Busy: %1$s</string>
|
||||
<string name="channel_scheduled">Scheduled results</string>
|
||||
<string name="channel_scheduled_failures">Scheduled failures</string>
|
||||
<string name="scheduled_result_public">A scheduled task has a result.</string>
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.PushPayload
|
||||
import eu.llembas.android.api.RulePreview
|
||||
import eu.llembas.android.api.RunEnvelope
|
||||
import eu.llembas.android.api.RunResult
|
||||
import eu.llembas.android.api.Schedule
|
||||
import eu.llembas.android.api.ScheduleCompiled
|
||||
import eu.llembas.android.api.ScheduleEnvelope
|
||||
import eu.llembas.android.api.ScheduleList
|
||||
import eu.llembas.android.api.ScheduleRuns
|
||||
import eu.llembas.android.api.SchedulesFrame
|
||||
import eu.llembas.android.api.SchedulingModels
|
||||
import eu.llembas.android.push.ScheduledNotice
|
||||
import eu.llembas.android.ui.scheduled.SchedulingLogic
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* The server's scheduling contract (`contract/schedule*.json`, `event_schedules.json`, written
|
||||
* by its serialisers): every shape parses into this app's models and says what it said. And the
|
||||
* push a scheduled run sends (services/schedule/notify.py `payload`), read into a notification.
|
||||
*/
|
||||
class ScheduleContractTest {
|
||||
private fun text(name: String): String = requireNotNull(javaClass.classLoader!!.getResource("$name.json")) { "contract/$name.json is missing" }.readText()
|
||||
|
||||
private fun <T> read(name: String, serializer: KSerializer<T>): T = LembasJson.decodeFromString(serializer, text(name))
|
||||
|
||||
/** The schedule every fixture carries: sched1, "Waybread check", with run1 as its last run. */
|
||||
private fun assertWaybread(s: Schedule) {
|
||||
assertEquals("sched1", s.id)
|
||||
assertEquals("Waybread check", s.title)
|
||||
assertEquals("Check the waybread is wrapped.", s.instruction)
|
||||
assertEquals("every second Monday at 7:30", s.request)
|
||||
assertEquals("On the second Monday of each month at 07:30", s.description)
|
||||
assertEquals("UTC", s.timezone)
|
||||
assertTrue(s.enabled)
|
||||
assertFalse(s.paused)
|
||||
assertEquals("2026-01-12T07:30:00+00:00", s.nextRun)
|
||||
assertEquals(5, s.nextRuns.size)
|
||||
assertEquals("fresh", s.mode)
|
||||
assertEquals("matters", s.notify)
|
||||
assertEquals("one", s.catchUp)
|
||||
assertNull(s.graceMinutes)
|
||||
assertEquals("qwen", s.model)
|
||||
assertEquals("high", s.effort)
|
||||
assertNull(s.agents)
|
||||
assertTrue("plan" in s.tools)
|
||||
assertEquals("chat1", s.chatId)
|
||||
assertEquals(3, s.firedCount)
|
||||
assertEquals(0, s.failureStreak)
|
||||
assertFalse(s.running)
|
||||
// The rule is the server's own form, kept whole to be handed back.
|
||||
val nth = s.rule.getValue("at").jsonObject.getValue("nth").jsonArray.single().jsonObject
|
||||
assertEquals(2, nth.getValue("n").jsonPrimitive.int)
|
||||
|
||||
val run = s.lastRun!!
|
||||
assertEquals("run1", run.id)
|
||||
assertEquals("sched1", run.scheduleId)
|
||||
assertEquals("ok", run.status)
|
||||
assertEquals("late", run.timing)
|
||||
assertEquals("GPT-OSS", run.model.label)
|
||||
assertEquals("switched", run.model.reason)
|
||||
assertEquals("Qwen", run.model.switchedFrom)
|
||||
assertEquals(1200L, run.tokens.prompt)
|
||||
assertNull(run.cost)
|
||||
assertNull(run.error)
|
||||
assertEquals("msg2", run.messageId)
|
||||
assertEquals("All the waybread is wrapped.", run.preview)
|
||||
assertTrue(run.notified)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theListOneScheduleAndTheEventFrame() {
|
||||
assertWaybread(read("schedules", ScheduleList.serializer()).schedules.single())
|
||||
assertWaybread(read("schedule", ScheduleEnvelope.serializer()).schedule)
|
||||
val frame = read("event_schedules", SchedulesFrame.serializer())
|
||||
assertEquals("597aab1ff7b62194", frame.version)
|
||||
assertWaybread(frame.schedules.single())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theRunsAWaitingOneAndOneInFull() {
|
||||
val page = read("schedule_runs", ScheduleRuns.serializer())
|
||||
assertFalse(page.more)
|
||||
val (waiting, done) = page.runs
|
||||
assertEquals("waiting", waiting.status)
|
||||
assertEquals("model", waiting.waitingFor)
|
||||
assertEquals("2026-01-02T03:09:05+00:00", waiting.retryAt)
|
||||
assertEquals(2, waiting.missed)
|
||||
assertEquals(2, waiting.attempts)
|
||||
assertNull(waiting.model.label)
|
||||
assertNull(waiting.chatId)
|
||||
assertEquals("no_model", waiting.error?.kind)
|
||||
assertEquals("Waiting for a free model: Qwen: it is answering someone.", waiting.error?.text)
|
||||
assertEquals("run1", done.id)
|
||||
|
||||
val one = read("schedule_run", RunResult.serializer())
|
||||
assertEquals("run1", one.run.id)
|
||||
assertEquals("chat1", one.run.chatId)
|
||||
assertEquals("All the waybread is *wrapped*.", one.text)
|
||||
|
||||
// `POST /schedules/{id}/run` answers 202 with the run alone.
|
||||
val started = LembasJson.decodeFromString(RunEnvelope.serializer(), """{"run":{"id":"run3","status":"running","timing":"manual"}}""")
|
||||
assertEquals("manual", started.run.timing)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theCompileAndThePreview() {
|
||||
val compiled = read("schedule_compile", ScheduleCompiled.serializer())
|
||||
assertTrue(compiled.ok)
|
||||
assertNull(compiled.reason)
|
||||
assertEquals("Waybread check", compiled.title)
|
||||
assertEquals("chat", compiled.target)
|
||||
assertEquals("On the second Monday of each month at 07:30", compiled.description)
|
||||
assertEquals(5, compiled.nextRuns.size)
|
||||
assertTrue(compiled.savable)
|
||||
|
||||
// A rule that cannot run comes back empty, in no words, with no runs: not savable.
|
||||
val preview = read("schedule_preview", RulePreview.serializer())
|
||||
assertTrue(preview.rule.isEmpty())
|
||||
assertNull(preview.description)
|
||||
assertTrue(preview.nextRuns.isEmpty())
|
||||
assertFalse(ScheduleCompiled(ok = false, reason = "Say what you want to happen.", instruction = "x").savable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSchedulingModelsAndANarrowing() {
|
||||
val models = read("schedule_models", SchedulingModels.serializer())
|
||||
val (gpt, qwen) = models.models
|
||||
assertEquals("gpt-oss", gpt.id)
|
||||
assertFalse(gpt.free)
|
||||
assertEquals("it is answering someone", gpt.busy)
|
||||
assertTrue(gpt.chosen)
|
||||
assertTrue(qwen.free)
|
||||
assertNull(qwen.busy)
|
||||
assertFalse(qwen.chosen)
|
||||
assertEquals("/api/v2/models/images/0a1b2c3d4e5f.png", qwen.image)
|
||||
assertEquals(listOf("gpt-oss", "qwen"), models.instance)
|
||||
assertEquals(listOf("gpt-oss"), models.mine)
|
||||
|
||||
// Ticking Qwen ticks every one: no narrowing at all. Unticking the last one: refused.
|
||||
assertEquals(emptyList<String>(), SchedulingLogic.toggled(models.models, "qwen"))
|
||||
assertNull(SchedulingLogic.toggled(models.models, "gpt-oss"))
|
||||
val all = models.models.map { it.copy(chosen = true) }
|
||||
assertEquals(listOf("gpt-oss"), SchedulingLogic.toggled(all, "qwen"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aResultsPushOpensTheRun() {
|
||||
// What notify.payload and push.announce send for a run that finished: ids, a fixed
|
||||
// sentence, never the result.
|
||||
val payload = LembasJson.decodeFromString(
|
||||
PushPayload.serializer(),
|
||||
"""{"schedule_id":"sched1","run_id":"run1","chat_id":"chat1","status":"ok","visibility":"private",
|
||||
"actions":["open"],"ask":"","pause_label":"Pause","title":"LLeMbas",
|
||||
"body":"A scheduled task has finished.","url":"/scheduled/sched1?run=run1","kind":"schedule"}""",
|
||||
)
|
||||
val notice = ScheduledNotice.from(payload)!!
|
||||
assertEquals("sched1", notice.scheduleId)
|
||||
assertEquals("run1", notice.runId)
|
||||
assertFalse(notice.failed)
|
||||
assertTrue(notice.open)
|
||||
assertFalse(notice.pause)
|
||||
assertEquals("private", payload.visibility)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailurePushOffersPauseAndAsksAfterThree() {
|
||||
val failed = LembasJson.decodeFromString(
|
||||
PushPayload.serializer(),
|
||||
"""{"schedule_id":"sched1","run_id":"run2","status":"failed","visibility":"private","actions":["open","pause"],
|
||||
"ask":"pause","body":"A scheduled task failed 3 times in a row. Pause it?","url":"/scheduled/sched1?run=run2",
|
||||
"kind":"schedule_failed"}""",
|
||||
)
|
||||
val notice = ScheduledNotice.from(failed)!!
|
||||
assertTrue(notice.failed)
|
||||
assertTrue(notice.askPause)
|
||||
assertTrue(notice.pause)
|
||||
// A push about the same run replaces its notification; another run gets its own.
|
||||
assertEquals(notice.id, notice.copy(failed = false).id)
|
||||
assertTrue(notice.id != notice.copy(runId = "run3").id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aPushWithOnlyItsUrlAndOneThatIsNotScheduled() {
|
||||
val bare = PushPayload(kind = "schedule", url = "/scheduled/sched1?run=run1")
|
||||
val notice = ScheduledNotice.from(bare)!!
|
||||
assertEquals("sched1", notice.scheduleId)
|
||||
assertEquals("run1", notice.runId)
|
||||
assertTrue(notice.open)
|
||||
assertNull(ScheduledNotice.from(PushPayload(kind = "reply", chatId = "chat1")))
|
||||
assertNull(ScheduledNotice.from(PushPayload(kind = "schedule", url = "/chat/chat1")))
|
||||
assertEquals(null to null, ScheduledNotice.fromUrl("/elsewhere"))
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import eu.llembas.android.ui.scheduled.ScheduleLogic
|
||||
import eu.llembas.android.ui.scheduled.Tone
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.time.ZoneId
|
||||
import java.util.Locale
|
||||
@@ -38,8 +39,11 @@ class ScheduleLogicTest {
|
||||
|
||||
@Test
|
||||
fun aScheduleListThatSaysLittleStillParses() {
|
||||
val list = LembasJson.decodeFromString(ScheduleList.serializer(), """{"schedules":[{"id":"s1","paused":true,"later":1}]}""")
|
||||
assertEquals("s1", list.schedules.single().id)
|
||||
assertNull(list.schedules.single().nextRun)
|
||||
val list = LembasJson.decodeFromString(ScheduleList.serializer(), """{"schedules":[{"id":"s1","enabled":false,"model":null,"later":1}]}""")
|
||||
val one = list.schedules.single()
|
||||
assertEquals("s1", one.id)
|
||||
assertTrue(one.paused)
|
||||
assertNull(one.nextRun)
|
||||
assertNull(one.model)
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,15 @@ import eu.llembas.android.api.LiveReply
|
||||
import eu.llembas.android.api.Message
|
||||
import eu.llembas.android.api.Metrics
|
||||
import eu.llembas.android.api.ModelList
|
||||
import eu.llembas.android.api.RunError
|
||||
import eu.llembas.android.api.RunModel
|
||||
import eu.llembas.android.api.RunResult
|
||||
import eu.llembas.android.api.RunTokens
|
||||
import eu.llembas.android.api.Schedule
|
||||
import eu.llembas.android.api.SchedulePreview
|
||||
import eu.llembas.android.api.ScheduleCompiled
|
||||
import eu.llembas.android.api.ScheduleRun
|
||||
import eu.llembas.android.api.SchedulingModel
|
||||
import eu.llembas.android.api.SchedulingModels
|
||||
import eu.llembas.android.api.Step
|
||||
import eu.llembas.android.api.Tail
|
||||
import eu.llembas.android.api.ToolBlock
|
||||
@@ -23,9 +29,12 @@ import eu.llembas.android.ui.chat.ChatState
|
||||
import eu.llembas.android.ui.chat.Draft
|
||||
import eu.llembas.android.ui.home.ChatsState
|
||||
import eu.llembas.android.ui.scheduled.EditState
|
||||
import eu.llembas.android.ui.scheduled.ModelsState
|
||||
import eu.llembas.android.ui.scheduled.RunState
|
||||
import eu.llembas.android.ui.scheduled.ScheduleState
|
||||
import eu.llembas.android.ui.scheduled.ScheduledState
|
||||
import eu.llembas.android.ui.settings.SettingsState
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import java.time.LocalDate
|
||||
|
||||
/** Made-up data for the screenshots: the server's own contract files where they fit. */
|
||||
@@ -141,8 +150,25 @@ object Fakes {
|
||||
selfUpdate = true,
|
||||
)
|
||||
|
||||
private val ok =
|
||||
ScheduleRun(id = "r1", dueAt = "2026-03-10T07:30:00+00:00", startedAt = "2026-03-10T07:30:02+00:00", status = "ok", model = "qwen", chatId = "c9")
|
||||
// Scheduled: shaped as the server's contract fixtures are (contract/schedule*.json).
|
||||
private fun rule(text: String) = LembasJson.parseToJsonElement(text).jsonObject
|
||||
|
||||
private val ok = ScheduleRun(
|
||||
id = "r1",
|
||||
scheduleId = "s1",
|
||||
status = "ok",
|
||||
timing = "on_time",
|
||||
dueAt = "2026-03-10T07:30:00+00:00",
|
||||
startedAt = "2026-03-10T07:30:02+00:00",
|
||||
finishedAt = "2026-03-10T07:31:40+00:00",
|
||||
attempts = 1,
|
||||
model = RunModel(id = "qwen", name = "Qwen", reason = "pinned"),
|
||||
tokens = RunTokens(prompt = 1200, completion = 340),
|
||||
chatId = "c9",
|
||||
messageId = "m9",
|
||||
preview = "1. Two new offshore wind farms approved in the North Sea. 2. Solar output hit a March record in Spain.",
|
||||
notified = true,
|
||||
)
|
||||
private val nextRuns = listOf(11, 12, 13, 16, 17).map { "2026-03-${it}T07:30:00+00:00" }
|
||||
|
||||
val schedules = listOf(
|
||||
@@ -150,71 +176,137 @@ object Fakes {
|
||||
id = "s1",
|
||||
title = "Morning news on renewables",
|
||||
instruction = "Sum up the news about renewable energy from the last day, in five points.",
|
||||
rule = "Every weekday at 07:30",
|
||||
request = "Every weekday at 7:30, sum up the news about renewable energy in five points",
|
||||
rule = rule("""{"at":{"weekdays":[0,1,2,3,4],"times":["07:30"]}}"""),
|
||||
description = "Every weekday at 07:30",
|
||||
timezone = "Europe/Bratislava",
|
||||
nextRun = nextRuns.first(),
|
||||
nextRuns = nextRuns,
|
||||
lastRun = ok,
|
||||
model = "qwen",
|
||||
mode = "fresh",
|
||||
notify = "matters",
|
||||
model = "qwen",
|
||||
chatId = "c9",
|
||||
firedCount = 41,
|
||||
lastRun = ok,
|
||||
),
|
||||
Schedule(
|
||||
id = "s2",
|
||||
title = "Check the garden sensors",
|
||||
instruction = "Read the sensors and tell me if the soil is too dry.",
|
||||
rule = "Every 3 hours",
|
||||
rule = rule("""{"every":{"hours":3}}"""),
|
||||
description = "Every 3 hours",
|
||||
nextRun = "2026-03-10T12:00:00+00:00",
|
||||
nextRuns = listOf("2026-03-10T12:00:00+00:00"),
|
||||
lastRun = ScheduleRun(id = "r2", status = "silent"),
|
||||
mode = "continue",
|
||||
notify = "matters",
|
||||
running = true,
|
||||
lastRun = ScheduleRun(id = "r2", scheduleId = "s2", status = "silent", timing = "on_time"),
|
||||
),
|
||||
Schedule(
|
||||
id = "s3",
|
||||
title = "Weekly backup report",
|
||||
instruction = "Summarise last week's backups and anything that failed.",
|
||||
rule = "Every Monday at 09:00",
|
||||
paused = true,
|
||||
lastRun = ScheduleRun(id = "r3", status = "failed", error = "The model could not be reached."),
|
||||
description = "Every Monday at 09:00",
|
||||
enabled = false,
|
||||
failureStreak = 3,
|
||||
lastRun = ScheduleRun(
|
||||
id = "r3",
|
||||
scheduleId = "s3",
|
||||
status = "failed",
|
||||
error = RunError(kind = "unreachable", text = "The model could not be reached."),
|
||||
),
|
||||
),
|
||||
Schedule(
|
||||
id = "s4",
|
||||
title = "Dentist",
|
||||
instruction = "Remind me to call the dentist.",
|
||||
rule = "Once, on Thursday at 10:00",
|
||||
description = "Once, on Thursday 12 March at 10:00",
|
||||
nextRun = "2026-03-12T09:00:00+00:00",
|
||||
nextRuns = listOf("2026-03-12T09:00:00+00:00"),
|
||||
lastRun = ScheduleRun(id = "r4", status = "waiting"),
|
||||
notify = "always",
|
||||
lastRun = ScheduleRun(
|
||||
id = "r4",
|
||||
scheduleId = "s4",
|
||||
status = "waiting",
|
||||
waitingFor = "model",
|
||||
retryAt = "2026-03-10T07:35:00+00:00",
|
||||
attempts = 2,
|
||||
error = RunError(kind = "no_model", text = "Waiting for a free model: Qwen: it is answering someone."),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val scheduled = ScheduledState(schedules = schedules)
|
||||
|
||||
private val switched = ScheduleRun(
|
||||
id = "r0",
|
||||
scheduleId = "s1",
|
||||
status = "ok",
|
||||
timing = "late",
|
||||
dueAt = "2026-03-09T07:30:00+00:00",
|
||||
startedAt = "2026-03-09T07:41:00+00:00",
|
||||
model = RunModel(id = "gpt-oss", name = "GPT-OSS", reason = "switched", switchedFrom = "Qwen"),
|
||||
chatId = "c8",
|
||||
preview = "Little happened over the weekend: one grid-storage tender in Austria.",
|
||||
)
|
||||
|
||||
val schedule = ScheduleState(
|
||||
schedule = schedules[0],
|
||||
runs = listOf(
|
||||
ok,
|
||||
ScheduleRun(
|
||||
id = "r0",
|
||||
startedAt = "2026-03-09T07:41:00+00:00",
|
||||
status = "ok",
|
||||
model = "gpt-oss",
|
||||
modelReason = "switched: qwen busy",
|
||||
chatId = "c8",
|
||||
),
|
||||
ScheduleRun(id = "r-1", dueAt = "2026-03-06T07:30:00+00:00", status = "silent", model = "qwen"),
|
||||
ScheduleRun(id = "r-2", dueAt = "2026-03-05T07:30:00+00:00", status = "missed", missed = 2),
|
||||
switched,
|
||||
ScheduleRun(id = "r-1", scheduleId = "s1", dueAt = "2026-03-06T07:30:00+00:00", status = "silent", model = RunModel(id = "qwen", name = "Qwen")),
|
||||
ScheduleRun(id = "r-2", scheduleId = "s1", dueAt = "2026-03-05T07:30:00+00:00", status = "missed", missed = 2),
|
||||
ScheduleRun(
|
||||
id = "r-3",
|
||||
scheduleId = "s1",
|
||||
startedAt = "2026-03-04T07:30:00+00:00",
|
||||
status = "failed",
|
||||
model = "qwen",
|
||||
error = "The model stopped answering after 10 minutes.",
|
||||
model = RunModel(id = "qwen", name = "Qwen"),
|
||||
error = RunError(kind = "timeout", text = "The model stopped answering after 10 minutes."),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val run = RunState(
|
||||
title = "Morning news on renewables",
|
||||
result = RunResult(
|
||||
run = switched,
|
||||
text = """
|
||||
|Little happened over the weekend. **One thing** worth knowing:
|
||||
|
|
||||
|1. Austria opened a tender for **200 MW** of grid storage, bids due in May.
|
||||
|2. A [report](https://example.org/report) puts Europe's March solar output 18 % above last year.
|
||||
|
|
||||
|```text
|
||||
|storage tender: 200 MW, deadline 2026-05-15
|
||||
|```
|
||||
""".trimMargin(),
|
||||
),
|
||||
)
|
||||
|
||||
val schedulingModels = ModelsState(
|
||||
models = SchedulingModels(
|
||||
models = listOf(
|
||||
SchedulingModel(id = "gpt-oss", name = "GPT-OSS", free = false, busy = "it is answering someone", chosen = true),
|
||||
SchedulingModel(id = "qwen", name = "Qwen", free = true, chosen = true),
|
||||
SchedulingModel(id = "gemma", name = "Gemma 3 27B", free = true, chosen = false),
|
||||
),
|
||||
instance = listOf("gpt-oss", "qwen", "gemma"),
|
||||
mine = listOf("gpt-oss", "qwen"),
|
||||
),
|
||||
)
|
||||
|
||||
val editing = EditState(
|
||||
words = "Every weekday at 7:30, sum up the news about renewable energy in five points",
|
||||
preview = SchedulePreview(
|
||||
compiled = ScheduleCompiled(
|
||||
ok = true,
|
||||
title = "Morning news on renewables",
|
||||
ruleText = "Every weekday at 07:30",
|
||||
instruction = "Sum up the news about renewable energy from the last day, in five points.",
|
||||
rule = rule("""{"at":{"weekdays":[0,1,2,3,4],"times":["07:30"]}}"""),
|
||||
description = "Every weekday at 07:30",
|
||||
nextRuns = nextRuns,
|
||||
timezone = "Europe/Bratislava",
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -23,9 +23,11 @@ import eu.llembas.android.ui.chat.TuneContent
|
||||
import eu.llembas.android.ui.chat.modelId
|
||||
import eu.llembas.android.ui.home.DrawerActions
|
||||
import eu.llembas.android.ui.home.DrawerContent
|
||||
import eu.llembas.android.ui.scheduled.RunContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduleContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduleEditContent
|
||||
import eu.llembas.android.ui.scheduled.ScheduledContent
|
||||
import eu.llembas.android.ui.scheduled.SchedulingModelsContent
|
||||
import eu.llembas.android.ui.settings.SettingsActions
|
||||
import eu.llembas.android.ui.settings.SettingsContent
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
@@ -118,6 +120,15 @@ class ScreenShots {
|
||||
|
||||
@Test
|
||||
fun scheduleEdit() = shoot("11-schedule-edit") { ScheduleEditContent(Fakes.editing, editing = false) }
|
||||
|
||||
@Test
|
||||
fun scheduleRun() {
|
||||
shoot("12-schedule-run") { RunContent(Fakes.run) }
|
||||
shoot("12-schedule-run", Phone.Small) { RunContent(Fakes.run) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun schedulingModels() = shoot("13-scheduling-models") { SchedulingModelsContent(Fakes.schedulingModels) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-1
@@ -194,7 +194,17 @@ STRINGS: dict[str, str] = {
|
||||
"run_skipped": "Skipped",
|
||||
"run_waiting": "Waiting for a model",
|
||||
"run_running": "Running",
|
||||
"run_model_switched": "%1$s (the first choice was busy)",
|
||||
"run_model_instead": "%1$s, instead of %2$s",
|
||||
"run_retry_at": "Tries again at %1$s",
|
||||
"run_result": "Result",
|
||||
"run_no_text": "This run left no text.",
|
||||
"run_open_chat": "Open its chat",
|
||||
"mode_fresh": "A new chat each time",
|
||||
"mode_continue": "One chat that grows",
|
||||
"schedule_models": "Models for scheduled tasks",
|
||||
"schedule_models_hint": "Scheduled tasks take the first of these that is free, in this order. Untick one to leave it out.",
|
||||
"model_free": "Free now",
|
||||
"model_busy": "Busy: %1$s",
|
||||
"channel_scheduled": "Scheduled results",
|
||||
"channel_scheduled_failures": "Scheduled failures",
|
||||
"scheduled_result_public": "A scheduled task has a result.",
|
||||
|
||||
@@ -48,8 +48,12 @@
|
||||
"instance_in_use": "Používá se",
|
||||
"listening": "Naslouchám…",
|
||||
"loading_line": "Pečou se lembasy…",
|
||||
"mode_continue": "Jeden chat, který roste",
|
||||
"mode_fresh": "Pokaždé nový chat",
|
||||
"mode_manual": "Ručně",
|
||||
"model_busy": "Zaneprázdněný: %1$s",
|
||||
"model_context": "kontext %1$s",
|
||||
"model_free": "Teď volný",
|
||||
"model_in_use": "Používá se",
|
||||
"model_levels": "Úsilí: %1$s",
|
||||
"model_thinking_switchable": "Přemýšlení zapnout či vypnout",
|
||||
@@ -76,7 +80,10 @@
|
||||
"push_on": "Upozornění jsou pro tuto instanci zapnutá.",
|
||||
"regenerate": "Vygenerovat znovu",
|
||||
"run_missed": "Zmeškáno ×%1$s",
|
||||
"run_model_switched": "%1$s (první volba byla zaneprázdněná)",
|
||||
"run_model_instead": "%1$s, místo %2$s",
|
||||
"run_no_text": "Tento běh nezanechal žádný text.",
|
||||
"run_result": "Výsledek",
|
||||
"run_retry_at": "Zkusí to znovu v %1$s",
|
||||
"run_silent": "Nic nového",
|
||||
"run_skipped": "Vynecháno",
|
||||
"run_waiting": "Čeká na model",
|
||||
@@ -84,6 +91,8 @@
|
||||
"schedule_edit": "Upravit plán",
|
||||
"schedule_history": "Historie",
|
||||
"schedule_model": "Model: %1$s",
|
||||
"schedule_models": "Modely pro naplánované úlohy",
|
||||
"schedule_models_hint": "Naplánované úlohy vezmou první z nich, který je volný, v tomto pořadí. Zrušte zaškrtnutí, chcete-li některý vynechat.",
|
||||
"schedule_new": "Nový plán",
|
||||
"schedule_next": "Příště: %1$s",
|
||||
"schedule_next_runs": "Příští spuštění",
|
||||
@@ -190,9 +199,13 @@
|
||||
"instance_in_use": "In Verwendung",
|
||||
"listening": "Hört zu…",
|
||||
"loading_line": "Lembas wird gebacken…",
|
||||
"mode_continue": "Ein Chat, der wächst",
|
||||
"mode_fresh": "Jedes Mal ein neuer Chat",
|
||||
"mode_manual": "Manuell",
|
||||
"mode_plan": "Plan",
|
||||
"model_busy": "Belegt: %1$s",
|
||||
"model_context": "%1$s Kontext",
|
||||
"model_free": "Jetzt frei",
|
||||
"model_in_use": "In Verwendung",
|
||||
"model_levels": "Aufwand: %1$s",
|
||||
"model_thinking_switchable": "Nachdenken an oder aus",
|
||||
@@ -219,7 +232,10 @@
|
||||
"push_on": "Benachrichtigungen sind für diese Instanz eingeschaltet.",
|
||||
"regenerate": "Neu generieren",
|
||||
"run_missed": "Verpasst ×%1$s",
|
||||
"run_model_switched": "%1$s (die erste Wahl war beschäftigt)",
|
||||
"run_model_instead": "%1$s statt %2$s",
|
||||
"run_no_text": "Dieser Lauf hat keinen Text hinterlassen.",
|
||||
"run_result": "Ergebnis",
|
||||
"run_retry_at": "Neuer Versuch um %1$s",
|
||||
"run_silent": "Nichts Neues",
|
||||
"run_skipped": "Übersprungen",
|
||||
"run_waiting": "Wartet auf ein Modell",
|
||||
@@ -227,6 +243,8 @@
|
||||
"schedule_edit": "Zeitplan bearbeiten",
|
||||
"schedule_history": "Verlauf",
|
||||
"schedule_model": "Modell: %1$s",
|
||||
"schedule_models": "Modelle für geplante Aufgaben",
|
||||
"schedule_models_hint": "Geplante Aufgaben nehmen das erste davon, das frei ist, in dieser Reihenfolge. Entfernen Sie den Haken, um eines auszulassen.",
|
||||
"schedule_new": "Neuer Zeitplan",
|
||||
"schedule_next": "Nächstes Mal: %1$s",
|
||||
"schedule_next_runs": "Nächste Läufe",
|
||||
@@ -333,8 +351,12 @@
|
||||
"instance_in_use": "En uso",
|
||||
"listening": "Escuchando…",
|
||||
"loading_line": "Horneando lembas…",
|
||||
"mode_continue": "Un chat que crece",
|
||||
"mode_fresh": "Un chat nuevo cada vez",
|
||||
"mode_manual": "Manual",
|
||||
"model_busy": "Ocupado: %1$s",
|
||||
"model_context": "contexto de %1$s",
|
||||
"model_free": "Libre ahora",
|
||||
"model_in_use": "En uso",
|
||||
"model_levels": "Esfuerzo: %1$s",
|
||||
"model_thinking_switchable": "Razonamiento sí o no",
|
||||
@@ -361,7 +383,10 @@
|
||||
"push_on": "Las notificaciones están activadas para esta instancia.",
|
||||
"regenerate": "Regenerar",
|
||||
"run_missed": "Perdida ×%1$s",
|
||||
"run_model_switched": "%1$s (la primera opción estaba ocupada)",
|
||||
"run_model_instead": "%1$s, en lugar de %2$s",
|
||||
"run_no_text": "Esta ejecución no dejó texto.",
|
||||
"run_result": "Resultado",
|
||||
"run_retry_at": "Lo intenta de nuevo a las %1$s",
|
||||
"run_silent": "Nada nuevo",
|
||||
"run_skipped": "Omitida",
|
||||
"run_waiting": "Esperando un modelo",
|
||||
@@ -369,6 +394,8 @@
|
||||
"schedule_edit": "Editar programación",
|
||||
"schedule_history": "Historial",
|
||||
"schedule_model": "Modelo: %1$s",
|
||||
"schedule_models": "Modelos para tareas programadas",
|
||||
"schedule_models_hint": "Las tareas programadas toman el primero de estos que esté libre, en este orden. Desmarque uno para dejarlo fuera.",
|
||||
"schedule_new": "Nueva programación",
|
||||
"schedule_next": "Próxima: %1$s",
|
||||
"schedule_next_runs": "Próximas ejecuciones",
|
||||
@@ -475,9 +502,13 @@
|
||||
"instance_in_use": "Utilisée",
|
||||
"listening": "Écoute…",
|
||||
"loading_line": "Cuisson des lembas…",
|
||||
"mode_continue": "Une discussion qui s’allonge",
|
||||
"mode_fresh": "Une nouvelle discussion à chaque fois",
|
||||
"mode_manual": "Manuel",
|
||||
"mode_plan": "Plan",
|
||||
"model_busy": "Occupé : %1$s",
|
||||
"model_context": "contexte de %1$s",
|
||||
"model_free": "Libre maintenant",
|
||||
"model_in_use": "Utilisé",
|
||||
"model_levels": "Effort : %1$s",
|
||||
"model_thinking_switchable": "Réflexion activable",
|
||||
@@ -504,7 +535,10 @@
|
||||
"push_on": "Les notifications sont activées pour cette instance.",
|
||||
"regenerate": "Régénérer",
|
||||
"run_missed": "Manquée ×%1$s",
|
||||
"run_model_switched": "%1$s (le premier choix était occupé)",
|
||||
"run_model_instead": "%1$s, au lieu de %2$s",
|
||||
"run_no_text": "Cette exécution n’a laissé aucun texte.",
|
||||
"run_result": "Résultat",
|
||||
"run_retry_at": "Nouvel essai à %1$s",
|
||||
"run_silent": "Rien de neuf",
|
||||
"run_skipped": "Sautée",
|
||||
"run_waiting": "En attente d’un modèle",
|
||||
@@ -512,6 +546,8 @@
|
||||
"schedule_edit": "Modifier la planification",
|
||||
"schedule_history": "Historique",
|
||||
"schedule_model": "Modèle : %1$s",
|
||||
"schedule_models": "Modèles pour les tâches planifiées",
|
||||
"schedule_models_hint": "Les tâches planifiées prennent le premier de ces modèles qui est libre, dans cet ordre. Décochez-en un pour l’écarter.",
|
||||
"schedule_new": "Nouvelle planification",
|
||||
"schedule_next": "Prochaine : %1$s",
|
||||
"schedule_next_runs": "Prochaines exécutions",
|
||||
@@ -618,9 +654,13 @@
|
||||
"instance_in_use": "Használatban",
|
||||
"listening": "Hallgatja…",
|
||||
"loading_line": "Lembas sül…",
|
||||
"mode_continue": "Egy csevegés, amely bővül",
|
||||
"mode_fresh": "Minden alkalommal új csevegés",
|
||||
"mode_manual": "Kézi",
|
||||
"mode_plan": "Terv",
|
||||
"model_busy": "Foglalt: %1$s",
|
||||
"model_context": "%1$s kontextus",
|
||||
"model_free": "Most szabad",
|
||||
"model_in_use": "Használatban",
|
||||
"model_levels": "Ráfordítás: %1$s",
|
||||
"model_thinking_switchable": "Gondolkodás be- vagy kikapcsolva",
|
||||
@@ -647,7 +687,10 @@
|
||||
"push_on": "Az értesítések be vannak kapcsolva ehhez a példányhoz.",
|
||||
"regenerate": "Újragenerálás",
|
||||
"run_missed": "Kimaradt ×%1$s",
|
||||
"run_model_switched": "%1$s (az első választás foglalt volt)",
|
||||
"run_model_instead": "%1$s, %2$s helyett",
|
||||
"run_no_text": "Ez a futás nem hagyott szöveget.",
|
||||
"run_result": "Eredmény",
|
||||
"run_retry_at": "Újrapróbálja: %1$s",
|
||||
"run_silent": "Semmi új",
|
||||
"run_skipped": "Kihagyva",
|
||||
"run_waiting": "Modellre vár",
|
||||
@@ -655,6 +698,8 @@
|
||||
"schedule_edit": "Ütemezés szerkesztése",
|
||||
"schedule_history": "Előzmények",
|
||||
"schedule_model": "Modell: %1$s",
|
||||
"schedule_models": "Modellek az ütemezett feladatokhoz",
|
||||
"schedule_models_hint": "Az ütemezett feladatok ebben a sorrendben az első szabadot veszik. Vegye ki a pipát, hogy kihagyjon egyet.",
|
||||
"schedule_new": "Új ütemezés",
|
||||
"schedule_next": "Következő: %1$s",
|
||||
"schedule_next_runs": "Következő futások",
|
||||
@@ -761,8 +806,12 @@
|
||||
"instance_in_use": "In uso",
|
||||
"listening": "In ascolto…",
|
||||
"loading_line": "I lembas stanno cuocendo…",
|
||||
"mode_continue": "Una chat che cresce",
|
||||
"mode_fresh": "Una nuova chat ogni volta",
|
||||
"mode_manual": "Manuale",
|
||||
"model_busy": "Occupato: %1$s",
|
||||
"model_context": "contesto di %1$s",
|
||||
"model_free": "Libero ora",
|
||||
"model_in_use": "In uso",
|
||||
"model_levels": "Impegno: %1$s",
|
||||
"model_thinking_switchable": "Ragionamento attivabile",
|
||||
@@ -789,7 +838,10 @@
|
||||
"push_on": "Le notifiche sono attive per questa istanza.",
|
||||
"regenerate": "Rigenera",
|
||||
"run_missed": "Saltata ×%1$s",
|
||||
"run_model_switched": "%1$s (la prima scelta era occupata)",
|
||||
"run_model_instead": "%1$s, invece di %2$s",
|
||||
"run_no_text": "Questa esecuzione non ha lasciato testo.",
|
||||
"run_result": "Risultato",
|
||||
"run_retry_at": "Riprova alle %1$s",
|
||||
"run_silent": "Niente di nuovo",
|
||||
"run_skipped": "Ignorata",
|
||||
"run_waiting": "In attesa di un modello",
|
||||
@@ -797,6 +849,8 @@
|
||||
"schedule_edit": "Modifica pianificazione",
|
||||
"schedule_history": "Cronologia",
|
||||
"schedule_model": "Modello: %1$s",
|
||||
"schedule_models": "Modelli per le attività pianificate",
|
||||
"schedule_models_hint": "Le attività pianificate usano il primo di questi che è libero, in quest’ordine. Togli la spunta per escluderne uno.",
|
||||
"schedule_new": "Nuova pianificazione",
|
||||
"schedule_next": "Prossima: %1$s",
|
||||
"schedule_next_runs": "Prossime esecuzioni",
|
||||
@@ -903,8 +957,12 @@
|
||||
"instance_in_use": "W użyciu",
|
||||
"listening": "Słucham…",
|
||||
"loading_line": "Lembasy się pieczą…",
|
||||
"mode_continue": "Jeden czat, który rośnie",
|
||||
"mode_fresh": "Za każdym razem nowy czat",
|
||||
"mode_manual": "Ręcznie",
|
||||
"model_busy": "Zajęty: %1$s",
|
||||
"model_context": "kontekst %1$s",
|
||||
"model_free": "Teraz wolny",
|
||||
"model_in_use": "W użyciu",
|
||||
"model_levels": "Wysiłek: %1$s",
|
||||
"model_thinking_switchable": "Myślenie włączane lub wyłączane",
|
||||
@@ -931,7 +989,10 @@
|
||||
"push_on": "Powiadomienia są włączone dla tej instancji.",
|
||||
"regenerate": "Wygeneruj ponownie",
|
||||
"run_missed": "Pominięto ×%1$s",
|
||||
"run_model_switched": "%1$s (pierwszy wybór był zajęty)",
|
||||
"run_model_instead": "%1$s zamiast %2$s",
|
||||
"run_no_text": "To uruchomienie nie zostawiło tekstu.",
|
||||
"run_result": "Wynik",
|
||||
"run_retry_at": "Ponowi próbę o %1$s",
|
||||
"run_silent": "Nic nowego",
|
||||
"run_skipped": "Pominięto",
|
||||
"run_waiting": "Czeka na model",
|
||||
@@ -939,6 +1000,8 @@
|
||||
"schedule_edit": "Edytuj harmonogram",
|
||||
"schedule_history": "Historia",
|
||||
"schedule_model": "Model: %1$s",
|
||||
"schedule_models": "Modele dla zaplanowanych zadań",
|
||||
"schedule_models_hint": "Zaplanowane zadania biorą pierwszy wolny z nich, w tej kolejności. Odznacz, aby któryś pominąć.",
|
||||
"schedule_new": "Nowy harmonogram",
|
||||
"schedule_next": "Następnie: %1$s",
|
||||
"schedule_next_runs": "Następne uruchomienia",
|
||||
@@ -1045,8 +1108,12 @@
|
||||
"instance_in_use": "Používa sa",
|
||||
"listening": "Počúvam…",
|
||||
"loading_line": "Pečú sa lembasy…",
|
||||
"mode_continue": "Jedna konverzácia, ktorá rastie",
|
||||
"mode_fresh": "Zakaždým nová konverzácia",
|
||||
"mode_manual": "Ručne",
|
||||
"model_busy": "Obsadený: %1$s",
|
||||
"model_context": "kontext %1$s",
|
||||
"model_free": "Teraz voľný",
|
||||
"model_in_use": "Používa sa",
|
||||
"model_levels": "Úsilie: %1$s",
|
||||
"model_thinking_switchable": "Premýšľanie zapnúť alebo vypnúť",
|
||||
@@ -1073,7 +1140,10 @@
|
||||
"push_on": "Upozornenia sú pre túto inštanciu zapnuté.",
|
||||
"regenerate": "Vygenerovať znova",
|
||||
"run_missed": "Zmeškané ×%1$s",
|
||||
"run_model_switched": "%1$s (prvá voľba bola zaneprázdnená)",
|
||||
"run_model_instead": "%1$s, namiesto %2$s",
|
||||
"run_no_text": "Tento beh nezanechal žiadny text.",
|
||||
"run_result": "Výsledok",
|
||||
"run_retry_at": "Skúsi to znova o %1$s",
|
||||
"run_silent": "Nič nové",
|
||||
"run_skipped": "Vynechané",
|
||||
"run_waiting": "Čaká na model",
|
||||
@@ -1081,6 +1151,8 @@
|
||||
"schedule_edit": "Upraviť plán",
|
||||
"schedule_history": "História",
|
||||
"schedule_model": "Model: %1$s",
|
||||
"schedule_models": "Modely pre naplánované úlohy",
|
||||
"schedule_models_hint": "Naplánované úlohy vezmú prvý z nich, ktorý je voľný, v tomto poradí. Zrušte začiarknutie, ak niektorý chcete vynechať.",
|
||||
"schedule_new": "Nový plán",
|
||||
"schedule_next": "Nabudúce: %1$s",
|
||||
"schedule_next_runs": "Ďalšie spustenia",
|
||||
|
||||
Reference in new issue
Block a user