sideby 0.28.3 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +12 -0
- package/dist/src/cli/commands.js +337 -13
- package/dist/src/cli/json-schemas.js +87 -1
- package/dist/src/cli/main.js +65 -4
- package/dist/src/core/config.d.ts +25 -0
- package/dist/src/core/config.js +34 -0
- package/dist/src/core/fs-safe.d.ts +22 -1
- package/dist/src/core/fs-safe.js +68 -1
- package/dist/src/core/handoff-run.d.ts +2 -0
- package/dist/src/core/handoff-run.js +12 -6
- package/dist/src/core/launch.d.ts +6 -1
- package/dist/src/core/live-sessions.d.ts +2 -0
- package/dist/src/core/messages.d.ts +2 -0
- package/dist/src/core/messages.js +12 -34
- package/dist/src/core/network.d.ts +5 -2
- package/dist/src/core/network.js +15 -45
- package/dist/src/core/run-link.d.ts +6 -1
- package/dist/src/core/run-link.js +62 -22
- package/dist/src/core/search-catalog.d.ts +1 -1
- package/dist/src/core/search-catalog.js +37 -0
- package/dist/src/core/session-handoffs.d.ts +22 -0
- package/dist/src/core/session-handoffs.js +110 -0
- package/dist/src/core/session-hooks.d.ts +33 -0
- package/dist/src/core/session-hooks.js +92 -0
- package/dist/src/core/session-select.d.ts +18 -3
- package/dist/src/core/session-select.js +82 -8
- package/dist/src/core/unattended-ended.d.ts +62 -0
- package/dist/src/core/unattended-ended.js +275 -0
- package/dist/src/core/unattended-pending.d.ts +56 -0
- package/dist/src/core/unattended-pending.js +182 -0
- package/dist/src/core/unattended-state.d.ts +129 -0
- package/dist/src/core/unattended-state.js +373 -0
- package/dist/src/core/unattended.d.ts +142 -0
- package/dist/src/core/unattended.js +349 -0
- package/dist/src/panel/background.js +8 -0
- package/dist/src/panel/handler.d.ts +37 -0
- package/dist/src/panel/handler.js +156 -2
- package/dist/src/panel/i18n.d.ts +97 -0
- package/dist/src/panel/i18n.js +194 -0
- package/dist/src/panel/page-logic.d.ts +129 -0
- package/dist/src/panel/page-logic.js +166 -0
- package/dist/src/panel/page-script.js +638 -7
- package/dist/src/panel/page-styles.js +69 -0
- package/dist/src/panel/page.js +2 -0
- package/dist/src/plugins/bus.js +1 -0
- package/dist/src/runtime.d.ts +17 -1
- package/dist/src/runtime.js +78 -15
- package/dist/src/types.d.ts +48 -0
- package/dist/src/unattended/hook.d.ts +46 -0
- package/dist/src/unattended/hook.js +288 -0
- package/package.json +1 -1
- package/schemas/config.json +76 -0
- package/schemas/messages.json +4 -0
- package/schemas/send.json +4 -0
- package/schemas/sessions-copy.json +4 -0
- package/schemas/sessions-open-run.json +4 -0
- package/schemas/sessions.json +7 -0
- package/schemas/unattended-defer.json +143 -0
- package/schemas/unattended-pending.json +154 -0
- package/schemas/unattended.json +291 -0
- package/skills/sideby/SKILL.md +3 -2
- package/skills/sideby/references/sessions.md +1 -1
- package/skills/sideby/references/unattended.md +58 -0
|
@@ -4,7 +4,7 @@ import { groupsToAccept } from '../core/inbound.js';
|
|
|
4
4
|
import { quotaIsStale } from '../core/quota-levels.js';
|
|
5
5
|
import { remoteControlTodo } from '../core/remote-control.js';
|
|
6
6
|
import { catalogMatchLevel, catalogNorm, searchCatalog } from '../core/search-catalog.js';
|
|
7
|
-
import { aiTaskAccounts, aliasArgsOf, aliasIssue, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, networkTaskFacts, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaHighLevel, quotaPressure, radioStep, reloadForBuild, remoteControlSummary, reorder, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, shortCwd, shortSessionLabel, sortAccounts, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, updatedAge, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
|
|
7
|
+
import { aiTaskAccounts, aliasArgsOf, aliasIssue, askBridge, askBridged, askCopy, attentionReasons, attentionWhy, autostartNote, bindingWindow, cacheHitRate, canLeaveLocal, categoryOrder, codeSwapOutcome, dotsKeepKeyboard, enableOutcome, fileSize, fixPrompt, foldSkips, foldToolCalls, formatDuration, handoffChangeOf, handoffHintAccount, handoffTaskFacts, hiddenIn, highlightParts, histFilters, historyEmpty, historyWhen, hotkeyFromKey, hotkeyPressKind, inDisplayOrder, loginClusters, loginKey, maskEmail, matchesQuery, mdBlocks, mdInline, menuPlacement, mergeDaily, mergeUsage, messageChip, messageNews, networkTaskFacts, newAccountDir, nextReset, panelFixes, panelHint, panelLang, panelMigration, panelPrefs, passedWindow, pinnedIn, quotaAskable, quotaHighLevel, quotaPressure, radioStep, reloadForBuild, remoteControlSummary, reorder, rowBadge, runCodeSwap, saveHandoffChange, sendBlock, sendFileProblem, sendResultView, sessionAge, sessionLabelParts, shortCwd, shortSessionLabel, sortAccounts, sortSessions, steadyOrder, stripSecrets, suggestAlias, suggestName, switchFailure, tailInView, taskFindings, uaDayRuns, uaGroupPending, uaOnChoices, uaParseClock, uaPickTime, uaSameSlot, uaShouldRead, uaSlotNight, uaStatusParts, uaStepClock, uaToggleDay, uaWaitingCount, uaWhen, updatedAge, widthFollower, widthTier, windowState, withPinned, } from './page-logic.js';
|
|
8
8
|
const LOGIC = [
|
|
9
9
|
quotaIsStale,
|
|
10
10
|
catalogNorm,
|
|
@@ -96,6 +96,19 @@ const LOGIC = [
|
|
|
96
96
|
windowState,
|
|
97
97
|
bindingWindow,
|
|
98
98
|
withPinned,
|
|
99
|
+
uaWhen,
|
|
100
|
+
uaStatusParts,
|
|
101
|
+
uaOnChoices,
|
|
102
|
+
uaPickTime,
|
|
103
|
+
uaSlotNight,
|
|
104
|
+
uaDayRuns,
|
|
105
|
+
uaToggleDay,
|
|
106
|
+
uaSameSlot,
|
|
107
|
+
uaGroupPending,
|
|
108
|
+
uaParseClock,
|
|
109
|
+
uaStepClock,
|
|
110
|
+
uaShouldRead,
|
|
111
|
+
uaWaitingCount,
|
|
99
112
|
]
|
|
100
113
|
.map((fn) => fn.toString())
|
|
101
114
|
.join('\n');
|
|
@@ -1137,6 +1150,7 @@ const MAIN = String.raw `
|
|
|
1137
1150
|
renderUpdated()
|
|
1138
1151
|
renderSettingsButton()
|
|
1139
1152
|
renderUpdateButton()
|
|
1153
|
+
renderUaBadge()
|
|
1140
1154
|
const u = updState()
|
|
1141
1155
|
$('foot-text').textContent = t(u && !u.checksOff ? 'foot.textChecks' : 'foot.text')
|
|
1142
1156
|
// A background refresh keeps the button still; only one the viewer asked for spins it.
|
|
@@ -2856,7 +2870,7 @@ const MAIN = String.raw `
|
|
|
2856
2870
|
// What each card's size menu shows while the user is choosing, by group id; dropped once a change is made.
|
|
2857
2871
|
const tuneSel = {}
|
|
2858
2872
|
const tp = { data: null, loading: false, error: null, at: 0 }
|
|
2859
|
-
function pageFromHash() { return location.hash === '#tuning' ? 'tuning' : location.hash === '#handoff' ? 'handoff' : location.hash === '#sessions' || location.hash === '#history' || location.hash === '#live' ? 'sessions' : 'accounts' }
|
|
2873
|
+
function pageFromHash() { return location.hash === '#tuning' ? 'tuning' : location.hash === '#handoff' ? 'handoff' : location.hash === '#unattended' ? 'unattended' : location.hash === '#sessions' || location.hash === '#history' || location.hash === '#live' ? 'sessions' : 'accounts' }
|
|
2860
2874
|
let curPage = pageFromHash()
|
|
2861
2875
|
function tuneSize(n) { return n === null || n === undefined ? t('tune.hostDefault') : tokens(n) }
|
|
2862
2876
|
// "Default" with the size it means, only where that size is documented: Claude models with a native 1M window
|
|
@@ -3082,6 +3096,17 @@ const MAIN = String.raw `
|
|
|
3082
3096
|
})
|
|
3083
3097
|
return
|
|
3084
3098
|
}
|
|
3099
|
+
// The Unattended page also opens once its Pending Decisions are in, at its final size.
|
|
3100
|
+
if (next === 'unattended' && !ua.data && !ua.error && !ua.opening && !ready) {
|
|
3101
|
+
ua.opening = true
|
|
3102
|
+
renderPageChrome()
|
|
3103
|
+
loadUa().finally(() => {
|
|
3104
|
+
ua.opening = false
|
|
3105
|
+
if (seq === navSeq) setPage('unattended', true)
|
|
3106
|
+
else renderPageChrome()
|
|
3107
|
+
})
|
|
3108
|
+
return
|
|
3109
|
+
}
|
|
3085
3110
|
if (next !== 'sessions') leaveHistory()
|
|
3086
3111
|
curPage = next
|
|
3087
3112
|
try { history.replaceState(null, '', next === 'accounts' ? location.pathname + location.search : '#' + (next === 'sessions' && hs.mode === 'live' ? 'live' : next)) } catch {}
|
|
@@ -3096,27 +3121,41 @@ const MAIN = String.raw `
|
|
|
3096
3121
|
const canHandoff = Boolean(ahState())
|
|
3097
3122
|
// Always offered, so the tabs do not change when the last account goes; the page has its own empty state.
|
|
3098
3123
|
const canSessions = Boolean(S.state)
|
|
3099
|
-
if (S.state && ((curPage === 'tuning' && !canTune) || (curPage === 'handoff' && !canHandoff) || (curPage === 'sessions' && !canSessions))) curPage = 'accounts'
|
|
3124
|
+
if (S.state && ((curPage === 'tuning' && !canTune) || (curPage === 'handoff' && !canHandoff) || ((curPage === 'sessions' || curPage === 'unattended') && !canSessions))) curPage = 'accounts'
|
|
3100
3125
|
const tabs = [['accounts', t('page.accounts')]]
|
|
3101
3126
|
if (canSessions) tabs.push(['sessions', t('page.sessions')])
|
|
3102
3127
|
if (canTune) tabs.push(['tuning', t('page.tuning')])
|
|
3103
3128
|
if (canHandoff) tabs.push(['handoff', t('page.handoff')])
|
|
3129
|
+
if (canSessions) tabs.push(['unattended', t('page.unattended')])
|
|
3104
3130
|
nav.hidden = tabs.length < 2
|
|
3105
3131
|
// Underline tabs: each page has its mark, the Accounts tab its count and Auto Handoff a dot while it is on.
|
|
3106
|
-
const tabIcon = { accounts: 'tabAccounts', sessions: 'tabSessions', tuning: 'tabTuning', handoff: 'tabHandoff' }
|
|
3132
|
+
const tabIcon = { accounts: 'tabAccounts', sessions: 'tabSessions', tuning: 'tabTuning', handoff: 'tabHandoff', unattended: 'moon' }
|
|
3107
3133
|
// The tab counts what the list shows: Hidden Accounts (spec §3.25) are counted on the line under it.
|
|
3108
3134
|
const nAccounts = S.state ? visibleAccounts().length : 0
|
|
3109
3135
|
const handoffOn = Boolean(ahState() && ahState().settings.auto)
|
|
3110
3136
|
// Redrawn only when something on it changes, so a refresh never replays the underline.
|
|
3111
|
-
|
|
3137
|
+
// Unattended Mode: a dot while it is on, and how many Pending Decisions wait.
|
|
3138
|
+
const uaNow = S.state && S.state.unattended ? uaStatusParts(S.state.unattended).state === 'on' : false
|
|
3139
|
+
const uaWait = uaPendingCount()
|
|
3140
|
+
const navShape = JSON.stringify([lang, curPage, tabs, nAccounts, handoffOn, sp.opening, pasteCount(), uaNow, uaWait, ua.opening])
|
|
3112
3141
|
if (nav._drawn !== navShape) {
|
|
3113
3142
|
nav._drawn = navShape
|
|
3114
3143
|
swapKids(nav, [h('div', { class: 'tabs', role: 'presentation' }, tabs.map(([id, label]) =>
|
|
3115
3144
|
h('button', { class: 'tab', type: 'button', role: 'tab', 'data-key': 'tab:' + id, 'aria-selected': curPage === id ? 'true' : 'false', 'aria-busy': id === 'sessions' && sp.opening ? 'true' : null, onclick: () => setPage(id) },
|
|
3116
|
-
id === 'sessions' && sp.opening ? spinner() : icon(tabIcon[id]), h('span', { class: 'tab-label', 'data-label': label }, label),
|
|
3145
|
+
(id === 'sessions' && sp.opening) || (id === 'unattended' && ua.opening) ? spinner() : icon(tabIcon[id]), h('span', { class: 'tab-label', 'data-label': label }, label),
|
|
3117
3146
|
id === 'accounts' && nAccounts ? h('span', { class: 'tab-count' }, String(nAccounts)) : null,
|
|
3118
3147
|
id === 'handoff' && handoffOn ? h('span', { class: 'tab-dot', 'aria-label': t('ah.on') }) : null,
|
|
3148
|
+
id === 'unattended' && uaNow ? h('span', { class: 'tab-dot', 'aria-label': t('ua.on') }) : null,
|
|
3149
|
+
id === 'unattended' && uaWait ? h('span', { class: 'seg-badge', 'data-tip': tn('ua.waiting', uaWait), 'aria-label': tn('ua.waiting', uaWait) }, String(uaWait)) : null,
|
|
3119
3150
|
id === 'sessions' && pasteCount() ? h('span', { class: 'seg-badge', 'data-tip': t('msgn.badge', { n: pasteCount() }), 'aria-label': t('msgn.badge', { n: pasteCount() }) }, String(pasteCount())) : null)))])
|
|
3151
|
+
// In a narrow window the tabs scroll sideways: the one shown is brought into view, never the page moved.
|
|
3152
|
+
const row = nav.firstChild
|
|
3153
|
+
const sel = row && row.querySelector('.tab[aria-selected=true]')
|
|
3154
|
+
if (sel && row.scrollWidth > row.clientWidth) {
|
|
3155
|
+
const left = sel.offsetLeft - row.offsetLeft
|
|
3156
|
+
if (left < row.scrollLeft) row.scrollLeft = left
|
|
3157
|
+
else if (left + sel.offsetWidth > row.scrollLeft + row.clientWidth) row.scrollLeft = left + sel.offsetWidth - row.clientWidth
|
|
3158
|
+
}
|
|
3120
3159
|
}
|
|
3121
3160
|
const away = curPage !== 'accounts' && tabs.some(([id]) => id === curPage)
|
|
3122
3161
|
// With no account yet the empty state is the whole page: no summary, no health check.
|
|
@@ -3125,9 +3164,18 @@ const MAIN = String.raw `
|
|
|
3125
3164
|
const onTune = away && curPage === 'tuning'
|
|
3126
3165
|
const onHandoff = away && curPage === 'handoff'
|
|
3127
3166
|
const onSessions = away && curPage === 'sessions'
|
|
3167
|
+
const onUa = away && curPage === 'unattended'
|
|
3128
3168
|
$('tuning-page').hidden = !onTune
|
|
3129
3169
|
$('handoff-page').hidden = !onHandoff
|
|
3130
3170
|
$('sessions-page').hidden = !onSessions
|
|
3171
|
+
$('unattended-page').hidden = !onUa
|
|
3172
|
+
if (onUa) {
|
|
3173
|
+
// Read again when the list may have changed (a new Pending Decision) or a while after the last read; never
|
|
3174
|
+
// before ua.nextAt, which a failed read puts a full refresh round away, so a failing read is not repeated at once.
|
|
3175
|
+
const st = S.state && S.state.unattended
|
|
3176
|
+
if (uaShouldRead({ now: Date.now(), at: ua.at, nextAt: ua.nextAt, everyMs: UA_MS, loading: Boolean(ua.loading), hasData: Boolean(ua.data), failed: Boolean(ua.error), statusCount: st ? st.pending : undefined, listCount: ua.data ? ua.data.pending.length : undefined })) loadUa()
|
|
3177
|
+
renderUaPage()
|
|
3178
|
+
}
|
|
3131
3179
|
if (onSessions) {
|
|
3132
3180
|
if (!sp.data && !sp.error) loadSessions()
|
|
3133
3181
|
renderSessionsPage()
|
|
@@ -5627,6 +5675,586 @@ const MAIN = String.raw `
|
|
|
5627
5675
|
swapKids(box, kids)
|
|
5628
5676
|
}
|
|
5629
5677
|
|
|
5678
|
+
// ---------- the Unattended page (spec §3.37, ADR-0058) ----------
|
|
5679
|
+
// The status in one sentence (as Android's Do Not Disturb says it) with the one action that changes it, the Schedule
|
|
5680
|
+
// edited in place (each change is written at once and its toast carries the undo), what sessions left for the user,
|
|
5681
|
+
// and where it works. The status comes with the Panel state; the Pending Decisions are read when the page opens, so
|
|
5682
|
+
// it opens at its final size. Parts that appear grow in and parts that go away shrink out (uaPatch).
|
|
5683
|
+
const UA_MS = 15000
|
|
5684
|
+
const UA_DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
|
|
5685
|
+
const UA_PRESET = { name: 'Weeknights', days: ['mon', 'tue', 'wed', 'thu', 'fri'], start: '23:00', end: '08:00' }
|
|
5686
|
+
const ua = { data: null, error: null, loading: null, at: 0, nextAt: 0, inflight: new Map(), opening: false, choosing: false, choice: null, time: '08:00', timeInit: '08:00', busy: false, local: null, saves: 0, rows: [], seq: 0, gone: {}, open: {}, firstUse: false, focus: null }
|
|
5687
|
+
let uaSaving = Promise.resolve()
|
|
5688
|
+
function uaStatusNow() { return (S.state && S.state.unattended) || null }
|
|
5689
|
+
// The latest status's count, less the ones being marked done right now (the page shows them gone already).
|
|
5690
|
+
function uaPendingCount() {
|
|
5691
|
+
return uaWaitingCount(uaStatusNow(), [...ua.inflight].map(([id, on]) => ({ id, on })))
|
|
5692
|
+
}
|
|
5693
|
+
function loadUa() {
|
|
5694
|
+
if (ua.loading) return ua.loading
|
|
5695
|
+
ua.loading = (async () => {
|
|
5696
|
+
try {
|
|
5697
|
+
const d = await api('/api/unattended', {})
|
|
5698
|
+
ua.data = d
|
|
5699
|
+
ua.error = null
|
|
5700
|
+
ua.at = Date.now()
|
|
5701
|
+
ua.nextAt = ua.at + 1000
|
|
5702
|
+
// What came back is newer than the state the page loaded before it.
|
|
5703
|
+
uaKeepStatus(d.status)
|
|
5704
|
+
for (const id of Object.keys(ua.gone)) if (!d.pending.some((x) => x.id === id)) delete ua.gone[id]
|
|
5705
|
+
} catch (e) {
|
|
5706
|
+
// The next try waits a full refresh round, whatever the counts say meanwhile.
|
|
5707
|
+
ua.error = e
|
|
5708
|
+
ua.at = Date.now()
|
|
5709
|
+
ua.nextAt = ua.at + AUTO_MS
|
|
5710
|
+
}
|
|
5711
|
+
ua.loading = null
|
|
5712
|
+
uaRedraw()
|
|
5713
|
+
})()
|
|
5714
|
+
return ua.loading
|
|
5715
|
+
}
|
|
5716
|
+
function uaKeepStatus(st) {
|
|
5717
|
+
if (!st) return
|
|
5718
|
+
if (S.state) S.state.unattended = st
|
|
5719
|
+
if (ua.data) ua.data.status = st
|
|
5720
|
+
}
|
|
5721
|
+
// Everything that shows the status: the header badge, the tab and the page.
|
|
5722
|
+
function uaRedraw() {
|
|
5723
|
+
renderUaBadge()
|
|
5724
|
+
// Draws the page too while it shows.
|
|
5725
|
+
renderPageChrome()
|
|
5726
|
+
}
|
|
5727
|
+
|
|
5728
|
+
// ---------- words ----------
|
|
5729
|
+
// A moment relative to now: "08:00" today, else "tomorrow 08:00", "Mon 08:00" or "Nov 3 08:00".
|
|
5730
|
+
function uaDayWord(ms, now) {
|
|
5731
|
+
const w = uaWhen(ms, now)
|
|
5732
|
+
if (w.day === 'today') return ''
|
|
5733
|
+
if (w.day === 'tomorrow') return t('ua.tomorrow')
|
|
5734
|
+
return new Date(ms).toLocaleDateString(locale(), w.day === 'week' ? { weekday: 'short' } : { month: 'short', day: 'numeric' })
|
|
5735
|
+
}
|
|
5736
|
+
// kind: until ("until 08:00"), back ("back on at 08:00") or next ("next: Mon 23:00"; today is said too).
|
|
5737
|
+
function uaAt(kind, ms) {
|
|
5738
|
+
const now = Date.now()
|
|
5739
|
+
const time = uaWhen(ms, now).hhmm
|
|
5740
|
+
const day = uaDayWord(ms, now) || (kind === 'next' ? t('ua.today') : '')
|
|
5741
|
+
return day ? t('ua.' + kind + 'Day', { day, time }) : t('ua.' + kind + 'Today', { time })
|
|
5742
|
+
}
|
|
5743
|
+
// A Slot as the page calls it: its name (the preset in the page's language), else its number.
|
|
5744
|
+
function uaSlotName(slot, i) {
|
|
5745
|
+
if (slot && slot.name) return slot.name === UA_PRESET.name ? t('ua.presetName') : slot.name
|
|
5746
|
+
return t('ua.slotN', { n: i + 1 })
|
|
5747
|
+
}
|
|
5748
|
+
// In the status sentence: "Slot “Weeknights”", or "Slot 2" for one without a name.
|
|
5749
|
+
function uaSlotWord(slot, i) {
|
|
5750
|
+
return slot.name ? t('ua.slotQuoted', { name: uaSlotName(slot, i) }) : t('ua.slotN', { n: i + 1 })
|
|
5751
|
+
}
|
|
5752
|
+
function uaDayNames(style) {
|
|
5753
|
+
// 2024-01-01 was a Monday.
|
|
5754
|
+
return UA_DAYS.map((d, i) => new Date(2024, 0, 1 + i).toLocaleDateString(locale(), { weekday: style }))
|
|
5755
|
+
}
|
|
5756
|
+
// The status sentence, its parts joined by dots: "On · Slot “Weeknights” · until 08:00".
|
|
5757
|
+
function uaSentence(st) {
|
|
5758
|
+
const p = uaStatusParts(st)
|
|
5759
|
+
const schedule = st.schedule || []
|
|
5760
|
+
const slotWord = p.slot !== null && schedule[p.slot] ? uaSlotWord(schedule[p.slot], p.slot) : null
|
|
5761
|
+
if (p.state === 'on') return [t('ua.on'), p.byHand ? t('ua.byHand') : slotWord, p.noEnd ? t('ua.noEnd') : uaAt('until', p.until)]
|
|
5762
|
+
if (p.state === 'paused') return [t('ua.paused'), p.noEnd ? t('ua.pausedOpen') : uaAt('back', p.until)]
|
|
5763
|
+
return [t('ua.off'), p.next ? uaAt('next', p.next.at) : null]
|
|
5764
|
+
}
|
|
5765
|
+
|
|
5766
|
+
// ---------- the header badge ----------
|
|
5767
|
+
// "Unattended · until 08:00" while it is on, to the page in one click. It fades in and out; a refresh with the same
|
|
5768
|
+
// words leaves it alone.
|
|
5769
|
+
function renderUaBadge() {
|
|
5770
|
+
const b = $('ua-badge')
|
|
5771
|
+
const st = uaStatusNow()
|
|
5772
|
+
const p = st && uaStatusParts(st)
|
|
5773
|
+
const on = Boolean(p && p.state === 'on')
|
|
5774
|
+
if (!on) {
|
|
5775
|
+
if (b.hidden || b._leaving) return
|
|
5776
|
+
b._drawn = ''
|
|
5777
|
+
if (!moving()) { b.hidden = true; return }
|
|
5778
|
+
const a = b.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, easing: 'ease-in', fill: 'forwards' })
|
|
5779
|
+
b._leaving = a
|
|
5780
|
+
a.finished.then(() => { if (b._leaving === a) { b.hidden = true; b._leaving = null; a.cancel() } }, () => {})
|
|
5781
|
+
return
|
|
5782
|
+
}
|
|
5783
|
+
if (b._leaving) { b._leaving.cancel(); b._leaving = null }
|
|
5784
|
+
const text = p.noEnd ? t('ua.badgeOn') : t('ua.badge', { until: uaAt('until', p.until) })
|
|
5785
|
+
const shape = lang + '|' + text
|
|
5786
|
+
if (b._drawn !== shape) {
|
|
5787
|
+
b._drawn = shape
|
|
5788
|
+
setKids(b, [icon('moon'), h('span', null, text)])
|
|
5789
|
+
b.setAttribute('aria-label', text + ' · ' + t('ua.badgeTitle'))
|
|
5790
|
+
b.title = t('ua.badgeTitle')
|
|
5791
|
+
}
|
|
5792
|
+
if (b.hidden) {
|
|
5793
|
+
b.hidden = false
|
|
5794
|
+
if (moving()) b.animate([{ opacity: 0, transform: 'translateY(-2px)' }, { opacity: 1, transform: 'none' }], { duration: 180, easing: 'ease-out' })
|
|
5795
|
+
}
|
|
5796
|
+
}
|
|
5797
|
+
|
|
5798
|
+
// ---------- motion ----------
|
|
5799
|
+
// Like patch, and a [data-ua] part that was not there grows in while one that went away shrinks out where it was.
|
|
5800
|
+
// A first draw animates nothing; reduced motion only switches.
|
|
5801
|
+
function uaPatch(box, kids) {
|
|
5802
|
+
// Parts still shrinking out sit outside the redraw and go back where they were, so a second draw right after
|
|
5803
|
+
// the first (the answer to a change) does not cut their motion short.
|
|
5804
|
+
const ghosts = [...box.querySelectorAll('[data-ua-ghost]')].map((el) => ({ el, parent: el.parentElement, next: el.nextElementSibling }))
|
|
5805
|
+
for (const g of ghosts) g.el.remove()
|
|
5806
|
+
const shown = Array.from(box.childNodes).some((n) => !keepsToasts(n))
|
|
5807
|
+
const old = shown && moving() ? [...box.querySelectorAll('[data-ua]')].map((el) => ({ el, key: el.getAttribute('data-ua'), parent: el.parentElement, next: el.nextElementSibling })) : []
|
|
5808
|
+
const before = new Set(old.map((o) => o.key))
|
|
5809
|
+
patch(box, kids)
|
|
5810
|
+
for (const g of ghosts.reverse()) {
|
|
5811
|
+
if (!g.parent.isConnected) continue
|
|
5812
|
+
if (g.next && g.next.parentElement === g.parent) g.parent.insertBefore(g.el, g.next)
|
|
5813
|
+
else g.parent.append(g.el)
|
|
5814
|
+
}
|
|
5815
|
+
if (!old.length) return
|
|
5816
|
+
const here = new Set([...box.querySelectorAll('[data-ua]')].map((x) => x.getAttribute('data-ua')))
|
|
5817
|
+
for (const x of box.querySelectorAll('[data-ua]')) if (!before.has(x.getAttribute('data-ua'))) uaGrow(x)
|
|
5818
|
+
// Last first, so a part that went away with the one after it goes back before that one.
|
|
5819
|
+
for (const o of old.reverse()) {
|
|
5820
|
+
if (here.has(o.key) || o.el.isConnected || !o.parent.isConnected) continue
|
|
5821
|
+
if (o.next && o.next.parentElement === o.parent) o.parent.insertBefore(o.el, o.next)
|
|
5822
|
+
else o.parent.append(o.el)
|
|
5823
|
+
uaShrink(o.el)
|
|
5824
|
+
}
|
|
5825
|
+
}
|
|
5826
|
+
function uaBox(el) {
|
|
5827
|
+
const cs = getComputedStyle(el)
|
|
5828
|
+
return { height: el.getBoundingClientRect().height + 'px', opacity: 1, marginTop: cs.marginTop, marginBottom: cs.marginBottom, paddingTop: cs.paddingTop, paddingBottom: cs.paddingBottom, overflow: 'hidden' }
|
|
5829
|
+
}
|
|
5830
|
+
const UA_FLAT = { height: '0px', opacity: 0, marginTop: '0px', marginBottom: '0px', paddingTop: '0px', paddingBottom: '0px', overflow: 'hidden' }
|
|
5831
|
+
function uaGrow(el) {
|
|
5832
|
+
if (!el.getBoundingClientRect().height) return
|
|
5833
|
+
el.animate([UA_FLAT, uaBox(el)], { duration: 180, easing: EASE })
|
|
5834
|
+
}
|
|
5835
|
+
function uaShrink(el) {
|
|
5836
|
+
// A part on its way out takes no clicks and is not read out.
|
|
5837
|
+
el.setAttribute('inert', '')
|
|
5838
|
+
el.setAttribute('aria-hidden', 'true')
|
|
5839
|
+
el.setAttribute('data-ua-ghost', '')
|
|
5840
|
+
el.removeAttribute('data-key')
|
|
5841
|
+
folding.add(el)
|
|
5842
|
+
const a = el.animate([uaBox(el), UA_FLAT], { duration: 160, easing: EASE, fill: 'forwards' })
|
|
5843
|
+
const end = () => { folding.delete(el); el.remove() }
|
|
5844
|
+
a.finished.then(end, end)
|
|
5845
|
+
}
|
|
5846
|
+
|
|
5847
|
+
// ---------- turning it on and off ----------
|
|
5848
|
+
function uaOpenChooser() {
|
|
5849
|
+
const st = uaStatusNow()
|
|
5850
|
+
if (!st) return
|
|
5851
|
+
if (ua.choosing) { uaCloseChooser(); return }
|
|
5852
|
+
ua.choosing = true
|
|
5853
|
+
ua.choice = uaOnChoices(st.slotEnd, Date.now()).chosen
|
|
5854
|
+
ua.time = ua.timeInit = '08:00'
|
|
5855
|
+
ua.focus = 'ua-opt-' + ua.choice
|
|
5856
|
+
renderUaPage()
|
|
5857
|
+
}
|
|
5858
|
+
function uaCloseChooser() {
|
|
5859
|
+
ua.choosing = false
|
|
5860
|
+
ua.focus = 'ua-main'
|
|
5861
|
+
renderUaPage()
|
|
5862
|
+
}
|
|
5863
|
+
function uaPick(id, keepFocus) {
|
|
5864
|
+
if (ua.choice === id) return
|
|
5865
|
+
ua.choice = id
|
|
5866
|
+
if (!keepFocus) ua.focus = 'ua-opt-' + id
|
|
5867
|
+
renderUaPage()
|
|
5868
|
+
}
|
|
5869
|
+
function uaRadioKeys(e) {
|
|
5870
|
+
if (e.key === 'Enter') { e.preventDefault(); uaTurnOn(); return }
|
|
5871
|
+
const radios = [...document.querySelectorAll('#unattended-page .ua-radio')]
|
|
5872
|
+
const i = radioStep(radios.length, radios.indexOf(e.currentTarget), e.key)
|
|
5873
|
+
if (i < 0) return
|
|
5874
|
+
e.preventDefault()
|
|
5875
|
+
uaPick(radios[i].getAttribute('data-key').slice('ua-opt-'.length))
|
|
5876
|
+
}
|
|
5877
|
+
function uaChoiceBody() {
|
|
5878
|
+
if (ua.choice === 'slot') return { slotEnd: true }
|
|
5879
|
+
if (ua.choice === '4h' || ua.choice === '12h') return { for: ua.choice }
|
|
5880
|
+
return { until: uaParseClock(ua.time) }
|
|
5881
|
+
}
|
|
5882
|
+
function uaPicked(now) {
|
|
5883
|
+
const clock = uaParseClock(ua.time)
|
|
5884
|
+
return clock ? uaPickTime(clock, now) : null
|
|
5885
|
+
}
|
|
5886
|
+
function uaToastFor(r) {
|
|
5887
|
+
const p = uaStatusParts(r.status)
|
|
5888
|
+
const text = p.state === 'on' ? (p.noEnd ? t('ua.toastOnAlways') : t('ua.toastOn', { until: uaAt('until', p.until) }))
|
|
5889
|
+
: p.state === 'paused' ? (p.noEnd ? t('ua.toastPausedOpen') : t('ua.toastPaused', { back: uaAt('back', p.until) }))
|
|
5890
|
+
: t('ua.toastOff')
|
|
5891
|
+
toast(text, r.undo ? { key: 'ua', action: { label: t('toast.undo'), run: () => uaUndo(r.undo) }, duration: 10000 } : { key: 'ua' })
|
|
5892
|
+
}
|
|
5893
|
+
async function uaChange(route, body, after) {
|
|
5894
|
+
if (ua.busy) return
|
|
5895
|
+
const first = !(uaStatusNow() || {}).configured
|
|
5896
|
+
ua.busy = true
|
|
5897
|
+
renderUaPage()
|
|
5898
|
+
try {
|
|
5899
|
+
const r = await api(route, body)
|
|
5900
|
+
if (first) ua.firstUse = true
|
|
5901
|
+
if (after) after()
|
|
5902
|
+
uaKeepStatus(r.status)
|
|
5903
|
+
ua.focus = 'ua-main'
|
|
5904
|
+
uaToastFor(r)
|
|
5905
|
+
} catch (e) { toast(e.message, { kind: 'fail' }) }
|
|
5906
|
+
ua.busy = false
|
|
5907
|
+
uaRedraw()
|
|
5908
|
+
}
|
|
5909
|
+
function uaTurnOn() {
|
|
5910
|
+
if (ua.choice === 'time' && !uaPicked(Date.now())) return
|
|
5911
|
+
uaChange('/api/unattended/on', uaChoiceBody(), () => { ua.choosing = false })
|
|
5912
|
+
}
|
|
5913
|
+
function uaTurnOff() { uaChange('/api/unattended/off', {}, () => { ua.choosing = false }) }
|
|
5914
|
+
async function uaUndo(undo) {
|
|
5915
|
+
try {
|
|
5916
|
+
const r = await api(undo.route, undo.body)
|
|
5917
|
+
uaKeepStatus(r.status)
|
|
5918
|
+
toast(t('ua.undone'), { key: 'ua' })
|
|
5919
|
+
} catch (e) { toast(e.message, { kind: 'fail' }) }
|
|
5920
|
+
uaRedraw()
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5923
|
+
// ---------- the Schedule ----------
|
|
5924
|
+
// Each row keeps an id while the page shows it, so a removed Slot is the row that leaves and an edited one stays the
|
|
5925
|
+
// same element (focus stays in its time field). A Schedule changed elsewhere matches rows by what they cover.
|
|
5926
|
+
function uaSchedule() {
|
|
5927
|
+
const st = uaStatusNow()
|
|
5928
|
+
return ua.local || (st && st.schedule) || []
|
|
5929
|
+
}
|
|
5930
|
+
function uaRowsFor(list) {
|
|
5931
|
+
const prev = ua.rows
|
|
5932
|
+
let rows
|
|
5933
|
+
if (prev.length === list.length) rows = list.map((slot, i) => ({ id: prev[i].id, slot }))
|
|
5934
|
+
else {
|
|
5935
|
+
const used = new Set()
|
|
5936
|
+
rows = list.map((slot) => {
|
|
5937
|
+
const same = prev.find((r) => !used.has(r.id) && uaSameSlot(r.slot, slot) && (r.slot.name || '') === (slot.name || ''))
|
|
5938
|
+
const id = same ? same.id : 'n' + ++ua.seq
|
|
5939
|
+
used.add(id)
|
|
5940
|
+
return { id, slot }
|
|
5941
|
+
})
|
|
5942
|
+
}
|
|
5943
|
+
ua.rows = rows
|
|
5944
|
+
return rows
|
|
5945
|
+
}
|
|
5946
|
+
function uaSaveSchedule(next, message, opts) {
|
|
5947
|
+
opts = opts || {}
|
|
5948
|
+
ua.local = next.map((s) => Object.assign({}, s, { days: [...s.days] }))
|
|
5949
|
+
ua.saves++
|
|
5950
|
+
if (!(uaStatusNow() || {}).configured) ua.firstUse = true
|
|
5951
|
+
renderUaPage()
|
|
5952
|
+
uaSaving = uaSaving.then(async () => {
|
|
5953
|
+
try {
|
|
5954
|
+
const r = await api('/api/unattended/schedule', { schedule: next })
|
|
5955
|
+
uaKeepStatus(r.status)
|
|
5956
|
+
if (r.changed)
|
|
5957
|
+
toast(opts.undone ? t('ua.undone') : message, opts.undone ? { key: 'ua-schedule' } : { key: 'ua-schedule', action: { label: t('toast.undo'), run: () => uaSaveSchedule(r.previous, '', { undone: true }) }, duration: 10000 })
|
|
5958
|
+
} catch (e) { toast(e.message, { kind: 'fail' }) }
|
|
5959
|
+
// The page shows what the config holds once every change is written; a failed one goes back.
|
|
5960
|
+
if (!--ua.saves) ua.local = null
|
|
5961
|
+
uaRedraw()
|
|
5962
|
+
})
|
|
5963
|
+
}
|
|
5964
|
+
function uaEdit(id, change, message) {
|
|
5965
|
+
const rows = uaRowsFor(uaSchedule())
|
|
5966
|
+
const i = rows.findIndex((r) => r.id === id)
|
|
5967
|
+
if (i < 0) return
|
|
5968
|
+
const next = rows.map((r) => r.slot)
|
|
5969
|
+
const slot = change(Object.assign({}, next[i], { days: [...next[i].days] }))
|
|
5970
|
+
if (!slot) return
|
|
5971
|
+
next[i] = slot
|
|
5972
|
+
uaSaveSchedule(next, message)
|
|
5973
|
+
}
|
|
5974
|
+
function uaTimeSave(input, id, which) {
|
|
5975
|
+
const rows = uaRowsFor(uaSchedule())
|
|
5976
|
+
const row = rows.find((r) => r.id === id)
|
|
5977
|
+
if (!row) return
|
|
5978
|
+
// A field emptied or half typed goes back to what is saved; 730 or 7:30 is written as 07:30.
|
|
5979
|
+
const v = uaParseClock(input.value)
|
|
5980
|
+
input.value = v || row.slot[which]
|
|
5981
|
+
if (!v || v === row.slot[which]) return
|
|
5982
|
+
uaEdit(id, (s) => { s[which] = v; return s }, t('ua.saved'))
|
|
5983
|
+
}
|
|
5984
|
+
// The page's own 24-hour field (the browser's time field follows its language: 11:00 PM on a Chinese page). HH:MM
|
|
5985
|
+
// typed (730, 7:30 and 07:30 all work), the arrow keys step the hour or the minute the caret is in, Enter commits.
|
|
5986
|
+
// What it accepts is its pattern, so a value it cannot take is marked while typing, without a redraw.
|
|
5987
|
+
const UA_CLOCK = ' *([01]?[0-9]|2[0-3])([::.]?[0-5][0-9])? *'
|
|
5988
|
+
function uaClockField(value, props, commit) {
|
|
5989
|
+
return h('input', Object.assign({ type: 'text', class: 'ua-time', value, inputmode: 'numeric', maxlength: '5', autocomplete: 'off', spellcheck: 'false', placeholder: 'HH:MM', pattern: UA_CLOCK,
|
|
5990
|
+
onkeydown: (e) => uaClockKeys(e, commit) }, props))
|
|
5991
|
+
}
|
|
5992
|
+
function uaClockKeys(e, commit) {
|
|
5993
|
+
const el = e.currentTarget
|
|
5994
|
+
if (e.key === 'Enter') { e.preventDefault(); commit(el); return }
|
|
5995
|
+
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return
|
|
5996
|
+
e.preventDefault()
|
|
5997
|
+
const part = (el.selectionStart || 0) <= 2 ? 'h' : 'm'
|
|
5998
|
+
const step = e.key === 'ArrowUp' ? 1 : -1
|
|
5999
|
+
el.value = uaStepClock(el.value, part, step) || uaStepClock(el.getAttribute('value') || '00:00', part, step)
|
|
6000
|
+
el.setSelectionRange(part === 'h' ? 0 : 3, part === 'h' ? 2 : 5)
|
|
6001
|
+
el.dispatchEvent(new Event('input', { bubbles: true }))
|
|
6002
|
+
}
|
|
6003
|
+
function uaRemove(id) {
|
|
6004
|
+
const rows = uaRowsFor(uaSchedule())
|
|
6005
|
+
const i = rows.findIndex((r) => r.id === id)
|
|
6006
|
+
if (i < 0) return
|
|
6007
|
+
ua.rows = rows.filter((r) => r.id !== id)
|
|
6008
|
+
const after = ua.rows[i] || ua.rows[i - 1]
|
|
6009
|
+
ua.focus = after ? 'ua-del-' + after.id : 'ua-add'
|
|
6010
|
+
uaSaveSchedule(ua.rows.map((r) => r.slot), t('ua.slotRemoved'))
|
|
6011
|
+
}
|
|
6012
|
+
function uaAdd(slot, message) {
|
|
6013
|
+
const rows = uaRowsFor(uaSchedule())
|
|
6014
|
+
const id = 'n' + ++ua.seq
|
|
6015
|
+
ua.rows = rows.concat([{ id, slot }])
|
|
6016
|
+
uaSaveSchedule(ua.rows.map((r) => r.slot), message)
|
|
6017
|
+
}
|
|
6018
|
+
// A new Slot covers the days no Slot has yet (all of them when none is left), overnight.
|
|
6019
|
+
function uaNewSlot() {
|
|
6020
|
+
const taken = new Set(uaSchedule().flatMap((s) => s.days))
|
|
6021
|
+
const free = UA_DAYS.filter((d) => !taken.has(d))
|
|
6022
|
+
return { days: free.length ? free : [...UA_DAYS], start: '23:00', end: '08:00' }
|
|
6023
|
+
}
|
|
6024
|
+
function uaSlotRow(r, i, names, short) {
|
|
6025
|
+
const s = r.slot
|
|
6026
|
+
const label = uaSlotName(s, i)
|
|
6027
|
+
const off = BOOT.readOnly
|
|
6028
|
+
const night = uaSlotNight(s)
|
|
6029
|
+
const time = (which) => uaClockField(s[which], { disabled: off, 'data-key': 'ua-' + which + '-' + r.id,
|
|
6030
|
+
'aria-label': t(which === 'start' ? 'ua.startOf' : 'ua.endOf', { slot: label }),
|
|
6031
|
+
onblur: (e) => uaTimeSave(e.target, r.id, which) }, (el) => uaTimeSave(el, r.id, which))
|
|
6032
|
+
return h('li', { class: 'ua-slot', 'data-key': 'ua-slot-' + r.id, 'data-ua': 'slot-' + r.id, 'data-patch': '' },
|
|
6033
|
+
h('span', { class: 'ua-slot-name' }, label),
|
|
6034
|
+
h('div', { class: 'ua-days', role: 'group', 'aria-label': t('ua.daysOf', { slot: label }), 'data-patch': '' }, UA_DAYS.map((d, k) => {
|
|
6035
|
+
const on = s.days.includes(d)
|
|
6036
|
+
const last = on && s.days.length === 1
|
|
6037
|
+
return h('button', { class: 'ua-day', type: 'button', 'data-key': 'ua-day-' + r.id + '-' + d, 'aria-pressed': String(on), 'aria-label': names[k], 'data-tip': last ? t('ua.keepDay') : names[k], disabled: off || last,
|
|
6038
|
+
onclick: () => uaEdit(r.id, (x) => { const days = uaToggleDay(x.days, d); return days ? Object.assign(x, { days }) : null }, t('ua.saved')) }, short[k])
|
|
6039
|
+
})),
|
|
6040
|
+
h('div', { class: 'ua-times', 'data-patch': '' }, time('start'), h('span', { class: 'ua-dash', 'aria-hidden': 'true' }, '–'), time('end'),
|
|
6041
|
+
night ? h('span', { class: 'ua-night chip chip-sm' }, t(night === 'next' ? 'ua.overnight' : 'ua.allDay')) : null),
|
|
6042
|
+
h('button', { class: 'icon-btn ua-del', type: 'button', 'data-key': 'ua-del-' + r.id, 'aria-label': t('ua.remove', { slot: label }), 'data-tip': t('ua.remove', { slot: label }), disabled: off, onclick: () => uaRemove(r.id) }, icon('x')))
|
|
6043
|
+
}
|
|
6044
|
+
function uaScheduleBlock() {
|
|
6045
|
+
const list = uaSchedule()
|
|
6046
|
+
const rows = uaRowsFor(list)
|
|
6047
|
+
const names = uaDayNames('long')
|
|
6048
|
+
const short = t('ua.days').split(',')
|
|
6049
|
+
const hasPreset = list.some((s) => uaSameSlot(s, UA_PRESET))
|
|
6050
|
+
const off = BOOT.readOnly
|
|
6051
|
+
const out = [h('div', { class: 'page-sec-head' }, h('h3', { class: 'page-sec' }, t('ua.schedule')), h('p', { class: 'muted small' }, t('ua.scheduleNote')))]
|
|
6052
|
+
out.push(rows.length
|
|
6053
|
+
? h('ul', { class: 'ua-slots', 'data-key': 'ua-slots', 'data-ua': 'slots', 'data-patch': '' }, rows.map((r, i) => uaSlotRow(r, i, names, short)))
|
|
6054
|
+
: h('p', { class: 'note ua-empty', 'data-key': 'ua-slots-none', 'data-ua': 'slots-none' }, t('ua.scheduleEmpty')))
|
|
6055
|
+
out.push(h('div', { class: 'row-actions ua-add-row', 'data-key': 'ua-add-row', 'data-patch': '' },
|
|
6056
|
+
fm('ua-add', h('button', { class: 'btn btn-sm', type: 'button', 'data-key': 'ua-add', disabled: off, onclick: () => uaAdd(uaNewSlot(), t('ua.slotAdded')) }, icon('plus'), t('ua.addSlot'))),
|
|
6057
|
+
hasPreset ? null : h('button', { class: 'btn btn-sm', type: 'button', 'data-key': 'ua-preset', disabled: off,
|
|
6058
|
+
onclick: () => uaAdd(Object.assign({}, UA_PRESET, { days: [...UA_PRESET.days] }), t('ua.presetAdded')) }, icon('moon'), t('ua.preset'))))
|
|
6059
|
+
return out
|
|
6060
|
+
}
|
|
6061
|
+
|
|
6062
|
+
// ---------- Pending Decisions ----------
|
|
6063
|
+
function uaWhenShort(iso) {
|
|
6064
|
+
const ms = Date.parse(iso)
|
|
6065
|
+
const now = Date.now()
|
|
6066
|
+
const w = uaWhen(ms, now)
|
|
6067
|
+
return w.day === 'today' ? w.hhmm : new Date(ms).toLocaleDateString(locale(), { month: 'short', day: 'numeric' }) + ' ' + w.hhmm
|
|
6068
|
+
}
|
|
6069
|
+
async function uaDone(ids, all) {
|
|
6070
|
+
const before = uaStatusNow()
|
|
6071
|
+
for (const id of ids) { ua.gone[id] = true; ua.inflight.set(id, before) }
|
|
6072
|
+
uaRedraw()
|
|
6073
|
+
try {
|
|
6074
|
+
const r = await api('/api/unattended/pending', all ? { all: true } : { id: ids[0] })
|
|
6075
|
+
const done = r.ids
|
|
6076
|
+
// A status read meanwhile already counts without them; only the one from before is lowered.
|
|
6077
|
+
if (before && uaStatusNow() === before) {
|
|
6078
|
+
before.pending = Math.max(0, before.pending - done.length)
|
|
6079
|
+
if (Array.isArray(before.pendingIds)) before.pendingIds = before.pendingIds.filter((id) => !done.includes(id))
|
|
6080
|
+
}
|
|
6081
|
+
for (const id of ids) ua.inflight.delete(id)
|
|
6082
|
+
toast(done.length > 1 ? tn('ua.doneMany', done.length) : t('ua.doneOne'), { key: 'ua-done', duration: 10000, action: BOOT.readOnly ? undefined : { label: t('toast.undo'), run: () => uaReopen(done) } })
|
|
6083
|
+
} catch (e) {
|
|
6084
|
+
for (const id of ids) { delete ua.gone[id]; ua.inflight.delete(id) }
|
|
6085
|
+
toast(e.message, { kind: 'fail' })
|
|
6086
|
+
}
|
|
6087
|
+
uaRedraw()
|
|
6088
|
+
}
|
|
6089
|
+
async function uaReopen(ids) {
|
|
6090
|
+
try {
|
|
6091
|
+
for (const id of ids) await api('/api/unattended/pending', { id, done: false })
|
|
6092
|
+
for (const id of ids) delete ua.gone[id]
|
|
6093
|
+
toast(t('ua.undone'), { key: 'ua-done' })
|
|
6094
|
+
} catch (e) { toast(e.message, { kind: 'fail' }) }
|
|
6095
|
+
await load({ silent: true })
|
|
6096
|
+
await loadUa()
|
|
6097
|
+
}
|
|
6098
|
+
// "Back to the session": a running one is on the Sessions page; an ended one resumes with the copied command.
|
|
6099
|
+
function uaBack(d) {
|
|
6100
|
+
if (d.live) {
|
|
6101
|
+
hs.mode = 'live'
|
|
6102
|
+
sp.drawn = ''
|
|
6103
|
+
setPage('sessions')
|
|
6104
|
+
const find = () => {
|
|
6105
|
+
const row = document.querySelector('#sessions-page [data-session="' + CSS.escape(d.sessionId) + '"]')
|
|
6106
|
+
if (!row) return false
|
|
6107
|
+
row.scrollIntoView({ behavior: REDUCED ? 'auto' : 'smooth', block: 'center' })
|
|
6108
|
+
palFlash(row)
|
|
6109
|
+
return true
|
|
6110
|
+
}
|
|
6111
|
+
// The Sessions page may still be reading its first answer.
|
|
6112
|
+
let tries = 0
|
|
6113
|
+
const look = () => { if (!find() && ++tries < 20) setTimeout(look, 150) }
|
|
6114
|
+
requestAnimationFrame(look)
|
|
6115
|
+
return
|
|
6116
|
+
}
|
|
6117
|
+
if (d.resume) copyText(d.resume, t('ua.resumeWhat'))
|
|
6118
|
+
}
|
|
6119
|
+
function uaPendingBlock(st) {
|
|
6120
|
+
const off = BOOT.readOnly || Boolean(st.problem)
|
|
6121
|
+
const head = h('div', { class: 'page-sec-head ua-pending-head' },
|
|
6122
|
+
h('h3', { class: 'page-sec' }, t('ua.pending')),
|
|
6123
|
+
h('p', { class: 'muted small' }, t('ua.pendingNote')))
|
|
6124
|
+
if (ua.error && !ua.data) return [head, errorNote(ua.error, () => { ua.error = null; loadUa() })]
|
|
6125
|
+
if (!ua.data) return [head, h('p', { class: 'muted' }, spinner(), ' ', t('ua.loading'))]
|
|
6126
|
+
// Until the folder is fixed nothing is read; "nothing waits" would not be true.
|
|
6127
|
+
if (st.problem) return [head, h('p', { class: 'note', 'data-key': 'ua-blocked' }, t('ua.pendingBlocked'))]
|
|
6128
|
+
const list = ua.data.pending.filter((d) => !ua.gone[d.id])
|
|
6129
|
+
if (!list.length) return [head, h('p', { class: 'note ua-empty', 'data-key': 'ua-none', 'data-ua': 'none' }, icon('check'), t('ua.pendingEmpty'))]
|
|
6130
|
+
const groups = uaGroupPending(list)
|
|
6131
|
+
const box = h('div', { class: 'ua-groups', 'data-key': 'ua-groups', 'data-ua': 'groups', 'data-patch': '' }, groups.map((g) => {
|
|
6132
|
+
const d = g.first
|
|
6133
|
+
// Kept outside a session (a defer typed in a terminal): no account or tool to name.
|
|
6134
|
+
const known = d.account || (d.family && d.family !== 'unknown')
|
|
6135
|
+
const who = d.accountLabel || d.account || (known ? family(d.family).title : t('ua.noSession'))
|
|
6136
|
+
const where = d.cwd ? h('code', { class: 'ua-cwd' }, d.cwd) : null
|
|
6137
|
+
const state = !d.sessionId ? (known ? t('ua.noSession') : null) : d.live ? t('ua.liveIn', { account: d.live.accountLabel || who }) : t('ua.ended')
|
|
6138
|
+
const back = d.sessionId && (d.live || d.resume)
|
|
6139
|
+
? h('button', { class: 'btn btn-sm', type: 'button', 'data-key': 'ua-back-' + g.key, 'data-tip': d.live ? t('ua.backLive') : d.resume, onclick: () => uaBack(d) }, icon(d.live ? 'messages' : 'copy'), t('ua.back'))
|
|
6140
|
+
: null
|
|
6141
|
+
return h('section', { class: 'ua-group', 'data-key': 'ua-g-' + g.key, 'data-ua': 'g-' + g.key, 'data-patch': '', 'aria-label': who },
|
|
6142
|
+
h('div', { class: 'ua-group-head', 'data-patch': '' },
|
|
6143
|
+
h('div', { class: 'ua-group-who' }, h('b', null, who), where, state ? h('span', { class: 'muted small' }, state) : null),
|
|
6144
|
+
back),
|
|
6145
|
+
h('ul', { class: 'ua-items', 'data-patch': '' }, g.items.map((x) => {
|
|
6146
|
+
const long = x.text.length > 280 || x.text.split('\n').length > 5
|
|
6147
|
+
const open = Boolean(ua.open[x.id])
|
|
6148
|
+
return h('li', { class: 'ua-item', 'data-key': 'ua-i-' + x.id, 'data-ua': 'i-' + x.id, 'data-patch': '' },
|
|
6149
|
+
h('div', { class: 'ua-item-meta' },
|
|
6150
|
+
h('span', { class: 'chip chip-sm' + (x.kind === 'question' ? ' chip-accent' : x.kind === 'permission' ? ' chip-warn' : '') }, t('ua.kind.' + x.kind)),
|
|
6151
|
+
h('time', { class: 'muted small', datetime: x.at }, uaWhenShort(x.at)),
|
|
6152
|
+
x.agentType ? h('span', { class: 'muted small' }, t('ua.agent', { type: x.agentType })) : null),
|
|
6153
|
+
h('p', { class: 'ua-text' + (long && !open ? ' is-clamped' : '') }, x.text),
|
|
6154
|
+
h('div', { class: 'ua-item-actions' },
|
|
6155
|
+
long ? h('button', { class: 'link-btn small', type: 'button', 'data-key': 'ua-more-' + x.id, 'aria-expanded': String(open), onclick: () => { ua.open[x.id] = !open; renderUaPage() } }, t(open ? 'ua.less' : 'ua.more')) : null,
|
|
6156
|
+
h('button', { class: 'btn btn-sm', type: 'button', 'data-key': 'ua-done-' + x.id, disabled: off, onclick: () => uaDone([x.id]) }, icon('check'), t('ua.done'))))
|
|
6157
|
+
})))
|
|
6158
|
+
}))
|
|
6159
|
+
const all = list.length > 1 ? h('button', { class: 'link-btn small', type: 'button', 'data-key': 'ua-all', disabled: off, onclick: () => uaDone(list.map((x) => x.id), true) }, t('ua.allDone')) : null
|
|
6160
|
+
return [h('div', { class: 'page-sec-head ua-pending-head' },
|
|
6161
|
+
h('div', { class: 'ua-sec-row' }, h('h3', { class: 'page-sec' }, t('ua.pending'), ' ', h('span', { class: 'tab-count' }, String(list.length))), all),
|
|
6162
|
+
h('p', { class: 'muted small' }, t('ua.pendingNote'))), box]
|
|
6163
|
+
}
|
|
6164
|
+
|
|
6165
|
+
// ---------- the page ----------
|
|
6166
|
+
function uaCoverage(st) {
|
|
6167
|
+
const have = new Set(S.state.accounts.map((a) => a.family))
|
|
6168
|
+
const lines = [h('li', null, t('ua.coverLine'))]
|
|
6169
|
+
if (have.has('codex') && st.coverage.codex !== 'covered') lines.push(h('li', { 'data-key': 'ua-cov-codex' }, tx('ua.codexTrust', { cmd: h('code', null, '/hooks') })))
|
|
6170
|
+
const other = [...have].filter((f) => f !== 'claude' && f !== 'codex').map((f) => family(f).title)
|
|
6171
|
+
if (other.length) lines.push(h('li', { 'data-key': 'ua-cov-other' }, t('ua.notSupported', { hosts: other.join(t('ua.listSep')) })))
|
|
6172
|
+
return [h('h3', { class: 'page-sec' }, t('ua.cover')), h('ul', { class: 'ua-cover', 'data-patch': '' }, lines)]
|
|
6173
|
+
}
|
|
6174
|
+
function uaChooser(st) {
|
|
6175
|
+
const now = Date.now()
|
|
6176
|
+
const { options } = uaOnChoices(st.slotEnd, now)
|
|
6177
|
+
const picked = uaPicked(now)
|
|
6178
|
+
const rows = options.map((o) => {
|
|
6179
|
+
const on = ua.choice === o.id
|
|
6180
|
+
const label = o.id === 'slot' ? t(st.slotNumber ? 'ua.choice.slotNow' : 'ua.choice.slotNext') : t('ua.choice.' + o.id)
|
|
6181
|
+
const until = o.id === 'time' ? (picked ? picked.until : null) : o.until
|
|
6182
|
+
return h('div', { class: 'ua-opt' + (on ? ' is-on' : ''), 'data-key': 'ua-row-' + o.id, 'data-patch': '', onclick: (e) => { if (!e.target.closest('input, button')) { uaPick(o.id) } } },
|
|
6183
|
+
h('button', { class: 'ua-radio', type: 'button', role: 'radio', 'aria-checked': String(on), tabindex: on ? '0' : '-1', 'data-key': 'ua-opt-' + o.id, onclick: () => uaPick(o.id), onkeydown: uaRadioKeys },
|
|
6184
|
+
h('span', { class: 'ua-dot', 'aria-hidden': 'true' }), label),
|
|
6185
|
+
o.id === 'time' ? uaClockField(ua.timeInit, { 'data-key': 'ua-pick', 'aria-label': t('ua.pickTime'),
|
|
6186
|
+
onfocus: () => uaPick('time', true),
|
|
6187
|
+
oninput: (e) => { ua.time = e.target.value; ua.choice = 'time'; renderUaPage() } }, () => uaTurnOn()) : null,
|
|
6188
|
+
h('span', { class: 'ua-when muted' }, until ? uaAt('until', until) : o.id === 'time' ? t('ua.pickHint') : ''))
|
|
6189
|
+
})
|
|
6190
|
+
const ok = !(ua.choice === 'time' && !picked)
|
|
6191
|
+
return h('div', { class: 'ua-chooser', id: 'ua-chooser', 'data-key': 'ua-chooser', 'data-ua': 'chooser', 'data-patch': '', onkeydown: (e) => { if (e.key === 'Escape') { e.stopPropagation(); uaCloseChooser() } } },
|
|
6192
|
+
h('div', { class: 'ua-chooser-title', id: 'ua-for' }, t('ua.for')),
|
|
6193
|
+
h('div', { class: 'ua-opts', role: 'radiogroup', 'aria-labelledby': 'ua-for', 'data-patch': '' }, rows),
|
|
6194
|
+
h('div', { class: 'row-actions', 'data-patch': '' },
|
|
6195
|
+
h('button', { class: 'btn btn-primary', type: 'button', 'data-key': 'ua-go', disabled: ua.busy || !ok, 'aria-busy': ua.busy ? 'true' : null, onclick: uaTurnOn }, ua.busy ? spinner() : null, t('ua.turnOnGo')),
|
|
6196
|
+
h('button', { class: 'btn', type: 'button', 'data-key': 'ua-cancel', disabled: ua.busy, onclick: uaCloseChooser }, t('btn.cancel'))))
|
|
6197
|
+
}
|
|
6198
|
+
// The Search Catalog's actions: to the page, then the chooser open, or the "Add a Slot" button shown.
|
|
6199
|
+
function uaGo(what) {
|
|
6200
|
+
setPage('unattended')
|
|
6201
|
+
let tries = 0
|
|
6202
|
+
const look = () => {
|
|
6203
|
+
const box = $('unattended-page')
|
|
6204
|
+
if (box.hidden || (!ua.data && !ua.error)) { if (++tries < 40) setTimeout(look, 100); return }
|
|
6205
|
+
const st = uaStatusNow()
|
|
6206
|
+
if (what === 'on' && st && uaStatusParts(st).state !== 'on' && !BOOT.readOnly && !st.problem) { if (!ua.choosing) uaOpenChooser(); return }
|
|
6207
|
+
const el = box.querySelector(what === 'on' ? '[data-key="ua-main"]' : '[data-find="ua-add"]')
|
|
6208
|
+
if (!el) return
|
|
6209
|
+
el.scrollIntoView({ behavior: REDUCED ? 'auto' : 'smooth', block: 'center' })
|
|
6210
|
+
palFlash(el)
|
|
6211
|
+
if (!el.disabled) el.focus({ preventScroll: true })
|
|
6212
|
+
}
|
|
6213
|
+
requestAnimationFrame(look)
|
|
6214
|
+
}
|
|
6215
|
+
function renderUaPage() {
|
|
6216
|
+
const box = $('unattended-page')
|
|
6217
|
+
if (box.hidden || !S.state) return
|
|
6218
|
+
const st = uaStatusNow()
|
|
6219
|
+
const kids = [h('div', { class: 'section-head', 'data-key': 'ua-head' },
|
|
6220
|
+
h('h2', { id: 'h-unattended' }, t('ua.title')),
|
|
6221
|
+
h('div', { class: 'row-actions' },
|
|
6222
|
+
// No spinner for the background reread: a refresh with the same answer redraws nothing.
|
|
6223
|
+
askBridged(BOOT, window) ? null : h('button', { class: 'btn btn-sm', type: 'button', 'data-key': 'ua-ask', onclick: () => openAsk({ text: t('ai.ask.unattended') }) }, icon('bot'), t('ua.ask')))),
|
|
6224
|
+
h('p', { 'data-key': 'ua-intro' }, t('ua.intro'))]
|
|
6225
|
+
if (!st) {
|
|
6226
|
+
kids.push(h('div', { class: 'note note-fail', role: 'alert', 'data-key': 'ua-unread' }, t('ua.unreadable'), h('button', { class: 'btn btn-sm', type: 'button', onclick: () => load({ announce: true }) }, t('btn.retry'))))
|
|
6227
|
+
uaPatch(box, kids)
|
|
6228
|
+
return
|
|
6229
|
+
}
|
|
6230
|
+
if (BOOT.readOnly) kids.push(h('p', { class: 'note', 'data-key': 'ua-ro' }, t('ua.readOnly')))
|
|
6231
|
+
if (st.problem) kids.push(h('div', { class: 'note note-fail', role: 'alert', 'data-key': 'ua-problem', 'data-ua': 'problem' }, t('ua.problem', { msg: st.problem })))
|
|
6232
|
+
const p = uaStatusParts(st)
|
|
6233
|
+
const parts = uaSentence(st).filter(Boolean)
|
|
6234
|
+
const noWrite = BOOT.readOnly || Boolean(st.problem) || ua.busy
|
|
6235
|
+
// One button: on (with the chooser) while off or paused; off, or a pause inside a Slot, while on.
|
|
6236
|
+
const main = p.state === 'on'
|
|
6237
|
+
? h('button', { class: 'btn', type: 'button', 'data-key': 'ua-main', disabled: noWrite, 'aria-busy': ua.busy ? 'true' : null, onclick: uaTurnOff }, ua.busy ? spinner() : null, t(p.noEnd ? 'ua.pause' : st.slotNumber ? 'ua.pauseSlot' : 'ua.turnOff'))
|
|
6238
|
+
: h('button', { class: 'btn btn-primary', type: 'button', 'data-key': 'ua-main', disabled: BOOT.readOnly || Boolean(st.problem), 'aria-expanded': String(ua.choosing), 'aria-controls': 'ua-chooser', onclick: uaOpenChooser }, t('ua.turnOn'))
|
|
6239
|
+
kids.push(h('div', { class: 'hp-status ua-status' + (p.state === 'on' ? ' is-on' : p.state === 'paused' ? ' is-paused' : ''), 'data-key': 'ua-status', 'data-patch': '', role: 'status' },
|
|
6240
|
+
h('span', { class: 'hp-status-ic' }, icon('moon')),
|
|
6241
|
+
h('div', { class: 'hp-status-text' },
|
|
6242
|
+
h('b', null, parts[0], parts.length > 1 ? h('span', { class: 'ua-status-rest' }, ' · ' + parts.slice(1).join(' · ')) : null),
|
|
6243
|
+
h('p', { class: 'muted' }, t(p.state === 'on' ? 'ua.onNote' : p.state === 'paused' ? 'ua.pausedNote' : 'ua.offNote'))),
|
|
6244
|
+
main))
|
|
6245
|
+
if (ua.choosing && p.state !== 'on') kids.push(uaChooser(st))
|
|
6246
|
+
if (!st.configured || ua.firstUse) kids.push(h('p', { class: 'note ua-first', 'data-key': 'ua-first', 'data-ua': 'first' }, icon('clock'), t('ua.firstUse')))
|
|
6247
|
+
kids.push(...uaScheduleBlock())
|
|
6248
|
+
kids.push(...uaPendingBlock(st))
|
|
6249
|
+
kids.push(...uaCoverage(st))
|
|
6250
|
+
uaPatch(box, kids)
|
|
6251
|
+
if (ua.focus) {
|
|
6252
|
+
const el = box.querySelector('[data-key="' + CSS.escape(ua.focus) + '"]')
|
|
6253
|
+
ua.focus = null
|
|
6254
|
+
if (el && !el.disabled) el.focus({ preventScroll: true })
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
|
|
5630
6258
|
// ---------- Remote Control (spec §3.22) ----------
|
|
5631
6259
|
// Shown while some Claude settings file turns Remote Control on. "Turn all off" first lists each file, the change
|
|
5632
6260
|
// and the accounts it reaches, in the banner itself; the toast after it carries the undo.
|
|
@@ -5927,6 +6555,8 @@ const MAIN = String.raw `
|
|
|
5927
6555
|
ask: { run: () => openAsk(), ok: () => !askBridged(BOOT, window) },
|
|
5928
6556
|
health: { run: palHealth, ok: () => Boolean(S.state && S.state.accounts.length), nav: true },
|
|
5929
6557
|
inbound: { run: openInbound, ok: () => Boolean(S.state) },
|
|
6558
|
+
'unattended-on': { run: () => uaGo('on'), ok: () => Boolean(uaStatusNow()), nav: true },
|
|
6559
|
+
'unattended-add-slot': { run: () => uaGo('add'), ok: () => Boolean(uaStatusNow()), nav: true },
|
|
5930
6560
|
}
|
|
5931
6561
|
function palHealth() {
|
|
5932
6562
|
setPage('accounts')
|
|
@@ -6454,7 +7084,7 @@ const MAIN = String.raw `
|
|
|
6454
7084
|
return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
|
|
6455
7085
|
}
|
|
6456
7086
|
// Example phrases: a click puts one in the Let AI do it box (spec §3.28).
|
|
6457
|
-
const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.network', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.tool']
|
|
7087
|
+
const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.tool']
|
|
6458
7088
|
// Network Guard (spec §3.35): one dialog with the switch, the allowed countries and the newest result per address.
|
|
6459
7089
|
// Countries are never ticked for the user, the current one included: a wrong network would allow itself.
|
|
6460
7090
|
const NET_COMMON = ['US', 'JP', 'SG', 'GB', 'DE', 'FR', 'NL', 'CA', 'AU', 'KR', 'TW', 'HK']
|
|
@@ -8003,6 +8633,7 @@ const MAIN = String.raw `
|
|
|
8003
8633
|
$('ver').disabled = !BOOT.updates
|
|
8004
8634
|
$('ver').addEventListener('click', () => openVerPop($('ver')))
|
|
8005
8635
|
$('update').addEventListener('click', openUpdate)
|
|
8636
|
+
$('ua-badge').addEventListener('click', () => setPage('unattended'))
|
|
8006
8637
|
$('ver-top').addEventListener('click', () => openVerPop($('ver-top')))
|
|
8007
8638
|
$('refresh').addEventListener('click', refreshAll)
|
|
8008
8639
|
$('ask-ai').addEventListener('click', () => openAsk())
|