@soffits/dsh-notify-inbox 0.2.0 → 0.3.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/CHANGELOG.md +12 -0
- package/README.md +4 -2
- package/client.js +78 -51
- package/locale/en.json +1 -17
- package/locale/fr.json +1 -17
- package/locale/zh.json +1 -17
- package/package.json +4 -4
- package/src/routes.js +11 -5
- package/src/store.js +30 -11
- package/client.actions.js +0 -234
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- The buttons come from [@soffits/dsh-ui-actions](https://github.com/soffits/dsh-ui-actions), installed as its own plugin, instead of a copy of the card board's chunk. "Ask" now opens a conversation with the notification attached as a card the person can remove and write beside; the sent message shows the same card, and the agent gets the notification as compact text with its id. Without the package the page works and shows no buttons.
|
|
6
|
+
- The buttons' words moved to that package; the page's locale files keep only its own.
|
|
7
|
+
|
|
8
|
+
## 0.2.1
|
|
9
|
+
|
|
10
|
+
- Under Unread, a notification you open, mark done or snooze stays where it is, shown as read, until you leave the view or tap Unread again, so the list never moves under your finger. Mark all read works the same way.
|
|
11
|
+
- Read notifications have a Mark unread button, in the row and in the open notification. It works on ones that Mark all read covered too.
|
|
12
|
+
- A done or snoozed notification shows its state in the collapsed row.
|
|
13
|
+
- On narrow screens the header wraps under the title instead of squeezing it.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
- Every word on the page comes from `locale/<tag>.json`, one file per language, picked up by what files exist; a missing key falls back to the primary language, then English. French joins English and Chinese.
|
package/README.md
CHANGED
|
@@ -62,7 +62,9 @@ A line `{"v": 1, "type": "handled", "record": "<id>", "press": "<press id>", "ac
|
|
|
62
62
|
|
|
63
63
|
## Buttons
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
The buttons come from [@soffits/dsh-ui-actions](https://github.com/soffits/dsh-ui-actions); install it as a plugin too (`dsh plugin --profile web add @soffits/dsh-ui-actions`). Without it the inbox works and shows no buttons.
|
|
66
|
+
|
|
67
|
+
Every notification gets **Ask**: it opens a new session with the notification attached to the message box as a card (removable), and the person writes their own words beside it. The sent message shows the same card; the agent gets the notification as a short quote with its id. Since the person sends it from the Web UI, the sign-in plugin records them as the sender.
|
|
66
68
|
|
|
67
69
|
Declared `actions` add more: `done`, `snooze` (a small picker: in an hour, this evening, tomorrow morning; or a fixed `payload.until`), `event` (anything else) and `link` (`payload.url`). A press on `done`, `snooze` or `event` is checked on the server (the record must be the caller's and declare that button), appended to `<dataDir>/<person>/actions.jsonl`, and published on the event channel `ui.action.<kind>` when [dsh-cron-jobs](https://github.com/soffits/dsh-cron-jobs) is installed, so a job listening there can act on it:
|
|
68
70
|
|
|
@@ -90,7 +92,7 @@ The page follows DSH's language. Its words live in `locale/<tag>.json` (`ui` for
|
|
|
90
92
|
|
|
91
93
|
## Files the plugin writes
|
|
92
94
|
|
|
93
|
-
All under `dataDir`: `<person>/read.json` (read marks), `<person>/actions.jsonl` (presses), `.push/subscriptions.json` and `.push/cursor.json` (how far each inbox was pushed, so a restart doesn't push the backlog), and the VAPID key unless `vapidFile` says otherwise. It never rewrites `inbox.jsonl`.
|
|
95
|
+
All under `dataDir`: `<person>/read.json` (read and unread marks), `<person>/actions.jsonl` (presses), `.push/subscriptions.json` and `.push/cursor.json` (how far each inbox was pushed, so a restart doesn't push the backlog), and the VAPID key unless `vapidFile` says otherwise. It never rewrites `inbox.jsonl`.
|
|
94
96
|
|
|
95
97
|
## Removing it
|
|
96
98
|
|
package/client.js
CHANGED
|
@@ -28,7 +28,7 @@ window.__ModuleLoader__.load({
|
|
|
28
28
|
.nib-content{max-width:820px;margin:0 auto;padding:0 clamp(16px,4vw,48px) 48px}
|
|
29
29
|
.nib-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;padding-top:28px;margin-bottom:16px}
|
|
30
30
|
[data-platform=darwin] .nib-head{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
|
|
31
|
-
.nib-head h1{margin:0;font-size:20px;font-weight:500;line-height:28px;flex:1;
|
|
31
|
+
.nib-head h1{margin:0;font-size:20px;font-weight:500;line-height:28px;flex:1 0 auto;max-width:100%}
|
|
32
32
|
.nib-count{color:var(--dsw-alias-label-tertiary);font-size:13px;margin-left:8px;font-weight:400}
|
|
33
33
|
.nib-tabs{display:inline-flex;gap:2px;padding:2px;border-radius:10px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
|
|
34
34
|
.nib-tab{border:none;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:13px;padding:2px 12px;border-radius:8px;cursor:pointer}
|
|
@@ -44,6 +44,9 @@ window.__ModuleLoader__.load({
|
|
|
44
44
|
.nib-list{display:flex;flex-direction:column;gap:2px;margin:0;padding:0;list-style:none}
|
|
45
45
|
.nib-item{border-radius:12px;padding:10px 12px;position:relative}
|
|
46
46
|
.nib-item.nib-open{background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
|
|
47
|
+
.nib-line{display:flex;align-items:flex-start;gap:4px}
|
|
48
|
+
.nib-mark{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;margin:-3px -6px -3px 0;border:none;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}
|
|
49
|
+
@media (hover:hover){.nib-mark:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
47
50
|
.nib-row{display:flex;gap:10px;align-items:flex-start;width:100%;border:none;background:transparent;color:inherit;font:inherit;text-align:left;padding:0;cursor:pointer}
|
|
48
51
|
.nib-dot{flex:none;width:8px;height:8px;border-radius:50%;margin-top:8px;background:transparent}
|
|
49
52
|
.nib-unread .nib-dot{background:var(--dsw-alias-state-business-primary)}
|
|
@@ -56,7 +59,7 @@ window.__ModuleLoader__.load({
|
|
|
56
59
|
.nib-time{flex:none;color:var(--dsw-alias-label-caption);font-size:12px}
|
|
57
60
|
.nib-spoken{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow-wrap:anywhere}
|
|
58
61
|
.nib-chip{display:inline-block;flex:none;padding:0 6px;border-radius:6px;font-size:11px;line-height:18px;font-weight:500;color:var(--dsw-alias-state-error-primary);box-shadow:inset 0 0 0 .5px currentColor}
|
|
59
|
-
.nib-chip.nib-muted{color:var(--dsw-alias-label-tertiary)}
|
|
62
|
+
.nib-chip.nib-muted{color:var(--dsw-alias-label-tertiary);font-weight:400;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
60
63
|
.nib-body{margin:8px 0 0 18px;display:flex;flex-direction:column;gap:10px}
|
|
61
64
|
.nib-text{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:22px}
|
|
62
65
|
.nib-links{display:flex;flex-direction:column;gap:2px;font-size:13px}
|
|
@@ -66,19 +69,20 @@ window.__ModuleLoader__.load({
|
|
|
66
69
|
.nib-ok{color:var(--dsw-alias-state-success-primary)}
|
|
67
70
|
.nib-bad{color:var(--dsw-alias-state-error-primary)}
|
|
68
71
|
.nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
72
|
+
.nib-actions .nib-btn{height:32px;padding:0 12px}
|
|
69
73
|
.nib-status{color:var(--dsw-alias-label-tertiary);font-size:12px}
|
|
70
74
|
.nib-empty{color:var(--dsw-alias-label-tertiary);padding:24px 12px}
|
|
71
75
|
.nib-error{color:var(--dsw-alias-state-error-primary);padding:12px}
|
|
72
76
|
.nib-more{margin:12px auto 0;display:flex}
|
|
73
77
|
.nib-icon{position:relative;display:inline-flex}
|
|
74
78
|
.nib-badge{position:absolute;top:-5px;right:-8px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dsw-alias-state-error-primary);color:#fff;font-size:9px;font-weight:600;line-height:14px;text-align:center;pointer-events:none}
|
|
75
|
-
@media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
|
|
79
|
+
@media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-mark{width:40px;height:40px;margin:-10px -8px -10px 0}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
|
|
76
80
|
@media (width<=640px){.nib-content{padding-inline:12px}.nib-head{padding-top:16px}.nib-body{margin-left:0}.nib-item{padding:10px 8px}}
|
|
77
81
|
`
|
|
78
82
|
|
|
79
83
|
// ---- shared state: the unread count and a version that bumps when anything changes ----
|
|
80
84
|
|
|
81
|
-
const shared = { unread: 0, version: 0, pollSeconds: 30, linked: null }
|
|
85
|
+
const shared = { unread: 0, version: 0, pollSeconds: 30, linked: null, ui: null }
|
|
82
86
|
const listeners = new Set()
|
|
83
87
|
const emit = () => { for (const listener of listeners) listener() }
|
|
84
88
|
const subscribe = listener => { listeners.add(listener); return () => listeners.delete(listener) }
|
|
@@ -139,10 +143,9 @@ window.__ModuleLoader__.load({
|
|
|
139
143
|
return Date.now() - Date.parse(press.at) < PENDING_MS ? t('press.pending') : t('press.unhandled')
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
// ---- the buttons:
|
|
146
|
+
// ---- the buttons: @soffits/dsh-ui-actions (ctx.uiActions), shared with other plugin pages ----
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
const loadActions = () => (actionsModule ??= require.async('./client.actions.js').catch(error => { actionsModule = undefined; throw error }))
|
|
148
|
+
const OWNER = '@soffits/dsh-notify-inbox'
|
|
146
149
|
|
|
147
150
|
/** The server's view of each button's last press: pending, done or unhandled. */
|
|
148
151
|
function pressStates(item) {
|
|
@@ -155,31 +158,42 @@ window.__ModuleLoader__.load({
|
|
|
155
158
|
return states
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
function Actions({ item, t, ui }) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
function Actions({ item, t, ui, onMark }) {
|
|
162
|
+
const markUnread = item.read && h('button', { type: 'button', className: 'nib-btn', onClick: () => onMark(item, false) }, t('markUnread'))
|
|
163
|
+
if (ui === null) return markUnread ? h('div', { className: 'nib-actions' }, markUnread) : null
|
|
164
|
+
// What "Ask" attaches to the conversation: the notification as a card, its ids for the agent.
|
|
165
|
+
const about = {
|
|
166
|
+
source: OWNER,
|
|
167
|
+
title: item.title || item.spoken || item.text,
|
|
168
|
+
lines: [item.title && item.spoken !== item.title ? item.spoken : '', ...(item.text || '').split('\n'), ...item.links].filter(line => line && line !== item.title),
|
|
169
|
+
context: { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined },
|
|
170
|
+
}
|
|
166
171
|
const onPress = async (action, extra) => {
|
|
167
172
|
await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
|
|
168
173
|
changed()
|
|
169
174
|
}
|
|
170
175
|
const status = pressStatus(item, t)
|
|
171
|
-
return h('div', { className: 'nib-actions' }, h(ui.ActionBar, { actions:
|
|
176
|
+
return h('div', { className: 'nib-actions' }, h(ui.ActionBar, { actions: item.actions, states: pressStates(item), about, defaultChat: true, onPress }),
|
|
177
|
+
markUnread,
|
|
172
178
|
status && h('span', { className: 'nib-status' }, status))
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
// ---- one notification ----
|
|
176
182
|
|
|
177
|
-
function
|
|
183
|
+
function MarkUnreadIcon() {
|
|
184
|
+
return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false' },
|
|
185
|
+
h('path', { d: 'M9.5 3.5H3A1.5 1.5 0 0 0 1.5 5v6.5A1.5 1.5 0 0 0 3 13h9a1.5 1.5 0 0 0 1.5-1.5V8' }),
|
|
186
|
+
h('path', { d: 'M1.8 4.6 7.5 8.6l2.3-1.6' }),
|
|
187
|
+
h('circle', { cx: 12.5, cy: 3.5, r: 2, fill: 'currentColor', stroke: 'none' }))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function Item({ item, t, open, onToggle, onMark, ui }) {
|
|
178
191
|
const urgent = item.lane === 'interrupt'
|
|
179
192
|
const className = ['nib-item', item.read ? '' : 'nib-unread', urgent ? 'nib-urgent' : '', open ? 'nib-open' : ''].filter(Boolean).join(' ')
|
|
180
193
|
const title = item.title || item.spoken || item.text.slice(0, 80)
|
|
181
194
|
const sub = item.spoken && item.spoken !== title ? item.spoken : item.text !== title ? item.text : ''
|
|
182
195
|
return h('li', { className, id: `nib-${item.id}` },
|
|
196
|
+
h('div', { className: 'nib-line' },
|
|
183
197
|
h('button', { type: 'button', className: 'nib-row', 'aria-expanded': open, onClick: () => onToggle(item) },
|
|
184
198
|
h('span', { className: 'nib-dot', 'aria-hidden': true }),
|
|
185
199
|
h('span', { className: 'nib-main' },
|
|
@@ -187,8 +201,10 @@ window.__ModuleLoader__.load({
|
|
|
187
201
|
urgent && h('span', { className: 'nib-chip' }, t('urgent')),
|
|
188
202
|
item.test && h('span', { className: 'nib-chip nib-muted' }, t('test')),
|
|
189
203
|
h('span', { className: 'nib-title' }, title),
|
|
204
|
+
!open && item.presses.length > 0 && h('span', { className: 'nib-chip nib-muted' }, pressStatus(item, t)),
|
|
190
205
|
h('span', { className: 'nib-time', title: absolute(item.time, t) }, relative(item.time, t))),
|
|
191
206
|
!open && sub && h('span', { className: 'nib-spoken' }, sub))),
|
|
207
|
+
item.read && !open && h('button', { type: 'button', className: 'nib-mark', title: t('markUnread'), 'aria-label': t('markUnread'), onClick: () => onMark(item, false) }, h(MarkUnreadIcon))),
|
|
192
208
|
open && h('div', { className: 'nib-body' },
|
|
193
209
|
item.text && item.text !== title && h('div', { className: 'nib-text' }, item.text),
|
|
194
210
|
item.links.length > 0 && h('div', { className: 'nib-links' },
|
|
@@ -198,7 +214,7 @@ window.__ModuleLoader__.load({
|
|
|
198
214
|
item.files.map(file => file.stored
|
|
199
215
|
? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
|
|
200
216
|
: h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
|
|
201
|
-
h(Actions, { item, t, ui }),
|
|
217
|
+
h(Actions, { item, t, ui, onMark }),
|
|
202
218
|
h('div', { className: 'nib-meta' },
|
|
203
219
|
item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
|
|
204
220
|
item.routed.map(row => h('span', { key: row.destination, className: 'nib-route', title: row.detail || '' },
|
|
@@ -295,7 +311,7 @@ window.__ModuleLoader__.load({
|
|
|
295
311
|
|
|
296
312
|
// ---- the page ----
|
|
297
313
|
|
|
298
|
-
function InboxPage({ translate: t
|
|
314
|
+
function InboxPage({ translate: t }) {
|
|
299
315
|
const version = useShared(s => s.version)
|
|
300
316
|
const unread = useShared(s => s.unread)
|
|
301
317
|
const linked = useShared(s => s.linked)
|
|
@@ -304,30 +320,23 @@ window.__ModuleLoader__.load({
|
|
|
304
320
|
const [more, setMore] = useState(false)
|
|
305
321
|
const [error, setError] = useState(null)
|
|
306
322
|
const [open, setOpen] = useState(() => shared.linked)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
makeActions().then(made => { if (live) setUi(made) }, reason => { console.warn('notify-inbox: buttons unavailable', reason) })
|
|
313
|
-
return () => { live = false }
|
|
314
|
-
}, [])
|
|
323
|
+
// Rows shown under Unread during this visit stay on screen as they turn read, done or snoozed,
|
|
324
|
+
// so the list never moves under the person's finger; leaving the view (or tapping its tab again) lets them go.
|
|
325
|
+
const shown = useRef(new Set())
|
|
326
|
+
const [visit, setVisit] = useState(0)
|
|
327
|
+
const ui = useShared(s => s.ui)
|
|
315
328
|
|
|
316
329
|
const load = useCallback(async (append) => {
|
|
317
330
|
try {
|
|
318
331
|
const params = new URLSearchParams()
|
|
319
|
-
if (filter === 'unread')
|
|
332
|
+
if (filter === 'unread') {
|
|
333
|
+
params.set('unread', '1')
|
|
334
|
+
if (shown.current.size > 0) params.set('keep', [...shown.current].join(','))
|
|
335
|
+
}
|
|
320
336
|
if (append && items?.length) params.set('before', items[items.length - 1].id)
|
|
321
337
|
const page = await call(`items?${params}`)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// The open item stays where it was even when it no longer matches the filter (opening marks it read).
|
|
325
|
-
const kept = previous?.findIndex(row => row.id === openRef.current) ?? -1
|
|
326
|
-
if (kept < 0 || page.items.some(row => row.id === openRef.current)) return page.items
|
|
327
|
-
const next = [...page.items]
|
|
328
|
-
next.splice(Math.min(kept, next.length), 0, { ...previous[kept], read: true })
|
|
329
|
-
return next
|
|
330
|
-
})
|
|
338
|
+
if (filter === 'unread') for (const row of page.items) shown.current.add(row.id)
|
|
339
|
+
setItems(previous => (append && previous ? [...previous, ...page.items] : page.items))
|
|
331
340
|
setMore(page.more)
|
|
332
341
|
setError(null)
|
|
333
342
|
} catch (reason) {
|
|
@@ -335,23 +344,29 @@ window.__ModuleLoader__.load({
|
|
|
335
344
|
}
|
|
336
345
|
}, [filter, items])
|
|
337
346
|
|
|
338
|
-
useEffect(() => { load(false) }, [filter, version])
|
|
347
|
+
useEffect(() => { load(false) }, [filter, version, visit])
|
|
348
|
+
const showView = key => {
|
|
349
|
+
shown.current = new Set()
|
|
350
|
+
if (key === filter) setVisit(n => n + 1)
|
|
351
|
+
else setFilter(key)
|
|
352
|
+
}
|
|
339
353
|
useEffect(() => {
|
|
340
354
|
if (!linked) return
|
|
341
|
-
|
|
355
|
+
showView('all')
|
|
342
356
|
setOpen(linked)
|
|
343
357
|
shared.linked = null
|
|
344
358
|
call('read', { ids: [linked] }).then(changed, () => {})
|
|
345
359
|
setTimeout(() => document.getElementById(`nib-${linked}`)?.scrollIntoView({ block: 'center' }), 300)
|
|
346
360
|
}, [linked])
|
|
347
361
|
|
|
362
|
+
const mark = (item, read) => {
|
|
363
|
+
setItems(list => list.map(row => (row.id === item.id ? { ...row, read } : row)))
|
|
364
|
+
call('read', { ids: [item.id], read }).then(changed, reason => setError(reason.message))
|
|
365
|
+
}
|
|
348
366
|
const toggle = item => {
|
|
349
367
|
const next = open === item.id ? null : item.id
|
|
350
368
|
setOpen(next)
|
|
351
|
-
if (next !== null && !item.read)
|
|
352
|
-
setItems(list => list.map(row => (row.id === item.id ? { ...row, read: true } : row)))
|
|
353
|
-
call('read', { ids: [item.id] }).then(changed, () => {})
|
|
354
|
-
}
|
|
369
|
+
if (next !== null && !item.read) mark(item, true)
|
|
355
370
|
}
|
|
356
371
|
const markAll = () => call('read', { all: true }).then(changed, reason => setError(reason.message))
|
|
357
372
|
|
|
@@ -361,23 +376,27 @@ window.__ModuleLoader__.load({
|
|
|
361
376
|
h('div', { className: 'nib-head' },
|
|
362
377
|
h('h1', null, t('title'), unread > 0 && h('span', { className: 'nib-count' }, unread)),
|
|
363
378
|
h('div', { className: 'nib-tabs', role: 'group' },
|
|
364
|
-
['unread', 'all'].map(key => h('button', { key, type: 'button', className: 'nib-tab', 'aria-pressed': filter === key, onClick: () =>
|
|
379
|
+
['unread', 'all'].map(key => h('button', { key, type: 'button', className: 'nib-tab', 'aria-pressed': filter === key, onClick: () => showView(key) }, t(`filter.${key}`)))),
|
|
365
380
|
h('button', { type: 'button', className: 'nib-btn', disabled: unread === 0, onClick: markAll }, t('markAll'))),
|
|
366
381
|
h(PushControl, { t }),
|
|
367
382
|
error && h('p', { className: 'nib-error', role: 'alert' }, t('error', { message: error })),
|
|
368
383
|
items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(filter === 'unread' ? 'empty.unread' : 'empty.all')),
|
|
369
384
|
items !== null && h('ul', { className: 'nib-list' },
|
|
370
|
-
items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, ui }))),
|
|
385
|
+
items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, onMark: mark, ui }))),
|
|
371
386
|
more && h('button', { type: 'button', className: 'nib-btn nib-more', onClick: () => load(true) }, t('loadMore')))))
|
|
372
387
|
}
|
|
373
388
|
|
|
389
|
+
function BellIcon({ size }) {
|
|
390
|
+
const stroke = { stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round', strokeLinejoin: 'round' }
|
|
391
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, focusable: 'false' },
|
|
392
|
+
h('path', { d: 'M8 2.2c-2.3 0-3.9 1.8-3.9 4v2.3L3 10.4c-.2.4.1.9.5.9h9c.4 0 .7-.5.5-.9l-1.1-1.9V6.2c0-2.2-1.6-4-3.9-4Z', ...stroke }),
|
|
393
|
+
h('path', { d: 'M6.5 13.2c.3.7.9 1.1 1.5 1.1s1.2-.4 1.5-1.1', ...stroke }))
|
|
394
|
+
}
|
|
395
|
+
|
|
374
396
|
function SidebarIcon({ size }) {
|
|
375
397
|
const unread = useShared(s => s.unread)
|
|
376
|
-
const stroke = { stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round', strokeLinejoin: 'round' }
|
|
377
398
|
return h('span', { className: 'nib-icon' },
|
|
378
|
-
h(
|
|
379
|
-
h('path', { d: 'M8 2.2c-2.3 0-3.9 1.8-3.9 4v2.3L3 10.4c-.2.4.1.9.5.9h9c.4 0 .7-.5.5-.9l-1.1-1.9V6.2c0-2.2-1.6-4-3.9-4Z', ...stroke }),
|
|
380
|
-
h('path', { d: 'M6.5 13.2c.3.7.9 1.1 1.5 1.1s1.2-.4 1.5-1.1', ...stroke })),
|
|
399
|
+
h(BellIcon, { size }),
|
|
381
400
|
unread > 0 && h('span', { className: 'nib-badge' }, unread > 99 ? '99+' : String(unread)))
|
|
382
401
|
}
|
|
383
402
|
|
|
@@ -405,13 +424,21 @@ window.__ModuleLoader__.load({
|
|
|
405
424
|
return () => tag.remove()
|
|
406
425
|
}, 'notify-inbox: styles')
|
|
407
426
|
|
|
408
|
-
|
|
427
|
+
// The buttons, when @soffits/dsh-ui-actions is installed; without it the page shows no buttons.
|
|
428
|
+
ctx.inject(['uiActions'], scope => {
|
|
429
|
+
scope.effect(() => {
|
|
430
|
+
shared.ui = scope.uiActions
|
|
431
|
+
emit()
|
|
432
|
+
const unregister = scope.uiActions.registerSource({ id: OWNER, name: () => t('panel'), icon: BellIcon })
|
|
433
|
+
return () => { unregister(); shared.ui = null; emit() }
|
|
434
|
+
}, 'notify-inbox: buttons')
|
|
435
|
+
})
|
|
409
436
|
|
|
410
437
|
ctx.slots.inject('main', () => ctx.slots.register({
|
|
411
438
|
name: 'main',
|
|
412
439
|
key: PANEL,
|
|
413
440
|
locale: NS,
|
|
414
|
-
inject: () => ({ translate: t
|
|
441
|
+
inject: () => ({ translate: t }),
|
|
415
442
|
}, InboxPage))
|
|
416
443
|
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
417
444
|
name: 'sidebar.panellist',
|
package/locale/en.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"filter.unread": "Unread",
|
|
10
10
|
"filter.all": "All",
|
|
11
11
|
"markAll": "Mark all read",
|
|
12
|
+
"markUnread": "Mark unread",
|
|
12
13
|
"empty.unread": "Nothing unread.",
|
|
13
14
|
"empty.all": "No notifications yet.",
|
|
14
15
|
"loadMore": "Show older",
|
|
@@ -34,23 +35,6 @@
|
|
|
34
35
|
"push.ios": "On iPhone or iPad, add this site to the Home Screen and open it from there to turn notifications on.",
|
|
35
36
|
"error": "Couldn’t load: {message}",
|
|
36
37
|
"time.locale": "en-US",
|
|
37
|
-
"action.chat": "Ask",
|
|
38
|
-
"action.chatAbout": "Chat about this",
|
|
39
|
-
"action.done": "Done",
|
|
40
|
-
"action.snooze": "Snooze",
|
|
41
|
-
"action.event": "Go",
|
|
42
|
-
"action.link": "Open",
|
|
43
|
-
"action.in3h": "In 3 hours",
|
|
44
|
-
"action.tomorrow": "Tomorrow 9:00",
|
|
45
|
-
"action.pick": "Pick a time…",
|
|
46
|
-
"action.set": "Snooze",
|
|
47
|
-
"action.cancel": "Cancel",
|
|
48
|
-
"action.sending": "Sending…",
|
|
49
|
-
"action.pending": "Waiting for it to be picked up",
|
|
50
|
-
"action.handled": "Done",
|
|
51
|
-
"action.unhandled": "Nothing picked this up yet",
|
|
52
|
-
"action.failed": "Didn’t go through: {message}",
|
|
53
|
-
"action.noWorkspace": "Open a conversation once first, then try again.",
|
|
54
38
|
"push.testTitle": "Inbox",
|
|
55
39
|
"push.testBody": "Notifications reach this device."
|
|
56
40
|
}
|
package/locale/fr.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"filter.unread": "Non lues",
|
|
10
10
|
"filter.all": "Toutes",
|
|
11
11
|
"markAll": "Tout marquer comme lu",
|
|
12
|
+
"markUnread": "Marquer comme non lu",
|
|
12
13
|
"empty.unread": "Rien de non lu.",
|
|
13
14
|
"empty.all": "Pas encore de notifications.",
|
|
14
15
|
"loadMore": "Plus anciennes",
|
|
@@ -34,23 +35,6 @@
|
|
|
34
35
|
"push.ios": "Sur iPhone ou iPad, ajoutez ce site à l’écran d’accueil et ouvrez-le depuis là pour activer les notifications.",
|
|
35
36
|
"error": "Chargement impossible : {message}",
|
|
36
37
|
"time.locale": "fr-FR",
|
|
37
|
-
"action.chat": "Demander",
|
|
38
|
-
"action.chatAbout": "En discuter",
|
|
39
|
-
"action.done": "Fait",
|
|
40
|
-
"action.snooze": "Plus tard",
|
|
41
|
-
"action.event": "Lancer",
|
|
42
|
-
"action.link": "Ouvrir",
|
|
43
|
-
"action.in3h": "Dans 3 heures",
|
|
44
|
-
"action.tomorrow": "Demain 9:00",
|
|
45
|
-
"action.pick": "Choisir une heure…",
|
|
46
|
-
"action.set": "Rappeler",
|
|
47
|
-
"action.cancel": "Annuler",
|
|
48
|
-
"action.sending": "Envoi…",
|
|
49
|
-
"action.pending": "En attente de traitement",
|
|
50
|
-
"action.handled": "Fait",
|
|
51
|
-
"action.unhandled": "Personne ne l’a encore pris en charge",
|
|
52
|
-
"action.failed": "Échec : {message}",
|
|
53
|
-
"action.noWorkspace": "Ouvrez d’abord une conversation, puis réessayez.",
|
|
54
38
|
"push.testTitle": "Notifications",
|
|
55
39
|
"push.testBody": "Les notifications arrivent sur cet appareil."
|
|
56
40
|
}
|
package/locale/zh.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"filter.unread": "未读",
|
|
10
10
|
"filter.all": "全部",
|
|
11
11
|
"markAll": "全部已读",
|
|
12
|
+
"markUnread": "标为未读",
|
|
12
13
|
"empty.unread": "没有未读通知。",
|
|
13
14
|
"empty.all": "还没有通知。",
|
|
14
15
|
"loadMore": "更早的",
|
|
@@ -34,23 +35,6 @@
|
|
|
34
35
|
"push.ios": "iPhone 或 iPad 上,先把这个网站添加到主屏幕,再从主屏幕打开,才能开启通知。",
|
|
35
36
|
"error": "加载失败:{message}",
|
|
36
37
|
"time.locale": "zh-CN",
|
|
37
|
-
"action.chat": "问问",
|
|
38
|
-
"action.chatAbout": "聊聊这个",
|
|
39
|
-
"action.done": "完成",
|
|
40
|
-
"action.snooze": "稍后提醒",
|
|
41
|
-
"action.event": "执行",
|
|
42
|
-
"action.link": "打开",
|
|
43
|
-
"action.in3h": "3 小时后",
|
|
44
|
-
"action.tomorrow": "明天 9:00",
|
|
45
|
-
"action.pick": "选个时间…",
|
|
46
|
-
"action.set": "稍后提醒",
|
|
47
|
-
"action.cancel": "取消",
|
|
48
|
-
"action.sending": "发送中…",
|
|
49
|
-
"action.pending": "等待处理",
|
|
50
|
-
"action.handled": "已处理",
|
|
51
|
-
"action.unhandled": "还没有被处理",
|
|
52
|
-
"action.failed": "没有成功:{message}",
|
|
53
|
-
"action.noWorkspace": "请先打开一次对话,再试一次。",
|
|
54
38
|
"push.testTitle": "收件箱",
|
|
55
39
|
"push.testBody": "这台设备能收到通知了。"
|
|
56
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-notify-inbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A notification inbox for DeepSeek Harness: each person sees their own notifications with read and unread, gets Web Push on their phone or browser, and can act on them.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./index.js",
|
|
20
20
|
"./client": "./client.js",
|
|
21
|
-
"./client.actions.js": "./client.actions.js",
|
|
22
21
|
"./locale/*.json": "./locale/*.json",
|
|
23
22
|
"./icon": "./icon.svg",
|
|
24
23
|
"./package.json": "./package.json"
|
|
25
24
|
},
|
|
26
|
-
"files": ["src", "client.js", "
|
|
25
|
+
"files": ["src", "client.js", "index.js", "cordis.patch.yml", "locale/*.json", "icon.svg", "README.md", "CHANGELOG.md", "LICENSE"],
|
|
27
26
|
"dsh": {
|
|
28
27
|
"bundle": {
|
|
29
28
|
"patch": "./cordis.patch.yml"
|
|
@@ -33,13 +32,14 @@
|
|
|
33
32
|
"immediately": true,
|
|
34
33
|
"inject": [
|
|
35
34
|
"@deepseek-ai/dsh-client-locale",
|
|
35
|
+
"@soffits/dsh-ui-actions",
|
|
36
36
|
"@deepseek-ai/dsh-client-ui-layout",
|
|
37
37
|
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
38
38
|
]
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"check": "for f in index.js client.js
|
|
42
|
+
"check": "for f in index.js client.js src/*.js test/*.js; do node --check \"$f\" || exit 1; done",
|
|
43
43
|
"test": "node --test test/*.test.js"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
package/src/routes.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* answer is decided here, per request, from who is asking.
|
|
5
5
|
*
|
|
6
6
|
* GET /api/notify-inbox/summary unread count and newest time (badge)
|
|
7
|
-
* GET /api/notify-inbox/items?unread=1&before=&limit=
|
|
8
|
-
* POST /api/notify-inbox/read { ids: [...] } or { all: true }
|
|
7
|
+
* GET /api/notify-inbox/items?unread=1&keep=&before=&limit=
|
|
8
|
+
* POST /api/notify-inbox/read { ids: [...], read?: false } or { all: true }
|
|
9
9
|
* POST /api/notify-inbox/action { record, action, until? } a done/snooze/event press
|
|
10
10
|
* GET /api/notify-inbox/file?id=&name= a stored attachment
|
|
11
11
|
* GET /api/notify-inbox/push/config { publicKey }
|
|
@@ -24,6 +24,8 @@ import { PERSON_PATTERN, RECORD_ID_PATTERN } from './store.js'
|
|
|
24
24
|
export const PREFIX = '/api/notify-inbox'
|
|
25
25
|
const MAX_BODY = 16 * 1024
|
|
26
26
|
const PAGE = 50
|
|
27
|
+
/** Most rows the Unread view keeps on screen after they turn read (ids in `keep`). */
|
|
28
|
+
const KEEP_MAX = 200
|
|
27
29
|
|
|
28
30
|
const HEADERS = {
|
|
29
31
|
'content-type': 'application/json; charset=utf-8',
|
|
@@ -99,7 +101,11 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
99
101
|
const params = new URL(request.url).searchParams
|
|
100
102
|
const limit = Math.min(Math.max(Number(params.get('limit')) || PAGE, 1), 200)
|
|
101
103
|
let { items } = await store.view(who.folders)
|
|
102
|
-
if (params.get('unread') === '1')
|
|
104
|
+
if (params.get('unread') === '1') {
|
|
105
|
+
// `keep` holds what the page already shows under Unread, so those rows stay put as they turn read.
|
|
106
|
+
const keep = new Set((params.get('keep') ?? '').split(',').filter(id => RECORD_ID_PATTERN.test(id)).slice(0, KEEP_MAX))
|
|
107
|
+
items = items.filter(item => !item.read || keep.has(item.id))
|
|
108
|
+
}
|
|
103
109
|
const before = params.get('before')
|
|
104
110
|
if (before) {
|
|
105
111
|
const at = items.findIndex(item => item.id === before)
|
|
@@ -125,7 +131,7 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
125
131
|
for (const person of who.folders) await store.markAllRead(person)
|
|
126
132
|
} else if (Array.isArray(value.ids)) {
|
|
127
133
|
const ids = value.ids.filter(id => typeof id === 'string').slice(0, 500)
|
|
128
|
-
for (const person of who.folders) await store.
|
|
134
|
+
for (const person of who.folders) await store.setRead(person, ids, value.read !== false)
|
|
129
135
|
} else {
|
|
130
136
|
return json(400, { error: 'Send ids or all.' })
|
|
131
137
|
}
|
|
@@ -140,7 +146,7 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
140
146
|
if (declared === undefined) return json(400, { error: 'This notification has no such button.' })
|
|
141
147
|
if (!['done', 'snooze', 'event'].includes(declared.kind)) return json(400, { error: 'This button acts in the page.' })
|
|
142
148
|
const result = await actions.press(record.person, record, declared, { until: value.until })
|
|
143
|
-
await store.
|
|
149
|
+
await store.setRead(record.person, [record.id], true)
|
|
144
150
|
return json(200, { press: result.event.press, published: result.published, matched: result.matched ?? 0 })
|
|
145
151
|
})
|
|
146
152
|
|
package/src/store.js
CHANGED
|
@@ -118,8 +118,13 @@ async function atomicWrite(path, value) {
|
|
|
118
118
|
await rename(tmp, path)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Read marks: everything up to `readBefore` (ISO time) is read, plus the ids in
|
|
123
|
+
* `read`, except the ids in `unread` (marked unread again after the watermark
|
|
124
|
+
* passed them).
|
|
125
|
+
*/
|
|
122
126
|
export function isRead(marks, record) {
|
|
127
|
+
if (marks.unread.includes(record.id)) return false
|
|
123
128
|
return (marks.readBefore !== '' && record.time <= marks.readBefore) || marks.read.includes(record.id)
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -164,9 +169,10 @@ export function createStore(dataDir) {
|
|
|
164
169
|
async function marks(person) {
|
|
165
170
|
try {
|
|
166
171
|
const value = JSON.parse(await readFile(join(dataDir, person, READ), 'utf8'))
|
|
167
|
-
|
|
172
|
+
const ids = key => list(value[key]).filter(id => typeof id === 'string')
|
|
173
|
+
return { readBefore: text(value.readBefore), read: ids('read'), unread: ids('unread') }
|
|
168
174
|
} catch {
|
|
169
|
-
return { readBefore: '', read: [] }
|
|
175
|
+
return { readBefore: '', read: [], unread: [] }
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
|
|
@@ -175,22 +181,35 @@ export function createStore(dataDir) {
|
|
|
175
181
|
await atomicWrite(join(dataDir, person, READ), value)
|
|
176
182
|
}
|
|
177
183
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Mark some records read or unread; ids that aren't this person's are ignored.
|
|
186
|
+
* Each list keeps only what the watermark doesn't already say.
|
|
187
|
+
*/
|
|
188
|
+
async function setRead(person, ids, value) {
|
|
189
|
+
const byId = new Map((await records(person)).records.map(record => [record.id, record]))
|
|
181
190
|
const current = await marks(person)
|
|
182
|
-
const read =
|
|
183
|
-
|
|
191
|
+
const read = new Set(current.read)
|
|
192
|
+
const unread = new Set(current.unread)
|
|
193
|
+
for (const id of ids) {
|
|
194
|
+
const record = byId.get(id)
|
|
195
|
+
if (record === undefined) continue
|
|
196
|
+
const covered = current.readBefore !== '' && record.time <= current.readBefore
|
|
197
|
+
read.delete(id)
|
|
198
|
+
unread.delete(id)
|
|
199
|
+
if (value && !covered) read.add(id)
|
|
200
|
+
if (!value && covered) unread.add(id)
|
|
201
|
+
}
|
|
202
|
+
await saveMarks(person, { readBefore: current.readBefore, read: [...read], unread: [...unread] })
|
|
184
203
|
}
|
|
185
204
|
|
|
186
|
-
/** Mark everything up to the newest record read; the per-id
|
|
205
|
+
/** Mark everything up to the newest record read; the per-id lists drop what the watermark covers. */
|
|
187
206
|
async function markAllRead(person) {
|
|
188
207
|
const all = (await records(person)).records
|
|
189
208
|
if (all.length === 0) return
|
|
190
209
|
const readBefore = all.reduce((latest, record) => (record.time > latest ? record.time : latest), '')
|
|
191
210
|
const current = await marks(person)
|
|
192
211
|
const byId = new Map(all.map(record => [record.id, record]))
|
|
193
|
-
await saveMarks(person, { readBefore, read: current.read.filter(id => byId.has(id) && byId.get(id).time > readBefore) })
|
|
212
|
+
await saveMarks(person, { readBefore, read: current.read.filter(id => byId.has(id) && byId.get(id).time > readBefore), unread: [] })
|
|
194
213
|
}
|
|
195
214
|
|
|
196
215
|
/** The records of these people, newest first, each with `read`. */
|
|
@@ -219,5 +238,5 @@ export function createStore(dataDir) {
|
|
|
219
238
|
return undefined
|
|
220
239
|
}
|
|
221
240
|
|
|
222
|
-
return { persons, records, marks,
|
|
241
|
+
return { persons, records, marks, setRead, markAllRead, view, file }
|
|
223
242
|
}
|
package/client.actions.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Action buttons for DSH Web UI plugins: chat, done, snooze, event and link,
|
|
3
|
-
* the same look and behaviour wherever an item offers them.
|
|
4
|
-
*
|
|
5
|
-
* A DSH client chunk: dsh-card-board's client loads it with
|
|
6
|
-
* `require.async('./client.actions.js')`. Another plugin can ship a copy as
|
|
7
|
-
* its own `client.actions.js`, changing OWNER below to its package name.
|
|
8
|
-
*
|
|
9
|
-
* DSH runs a chunk as a classic script, so everything sits inside one function
|
|
10
|
-
* (a top-level `const` would clash with another plugin's copy and the second
|
|
11
|
-
* chunk would never register).
|
|
12
|
-
*
|
|
13
|
-
* const { createActions } = await require.async('./client.actions.js')
|
|
14
|
-
* const ui = createActions({ React, ctx, t, press })
|
|
15
|
-
* h(ui.ActionBar, { actions, states, chat, onPress })
|
|
16
|
-
*
|
|
17
|
-
* `t(key, params)` gives the words in the person's language; the host plugin
|
|
18
|
-
* keeps them in its one message table. The keys it must know are exported as
|
|
19
|
-
* `KEYS`: chat, chatAbout, done, snooze, event, link, in3h, tomorrow, pick,
|
|
20
|
-
* set, cancel, sending, pending, handled, unhandled, failed ({message}),
|
|
21
|
-
* noWorkspace. `t` is called while rendering, so a language switch shows up
|
|
22
|
-
* without building the buttons again.
|
|
23
|
-
*
|
|
24
|
-
* `press(action, extra)` is the plugin's own server call for done, snooze and
|
|
25
|
-
* event (extra carries `until` for a snooze); it should resolve once the
|
|
26
|
-
* server has accepted the press. `chat` and `link` never reach the server:
|
|
27
|
-
* chat opens a conversation with a prefilled, editable draft through the Web
|
|
28
|
-
* UI's own workspace service (so the person sends it themselves, signed in as
|
|
29
|
-
* themselves), and link opens the URL.
|
|
30
|
-
*/
|
|
31
|
-
(() => {
|
|
32
|
-
const OWNER = '@soffits/dsh-notify-inbox'
|
|
33
|
-
|
|
34
|
-
const KEYS = ['chat', 'chatAbout', 'done', 'snooze', 'event', 'link', 'in3h', 'tomorrow', 'pick', 'set', 'cancel', 'sending', 'pending', 'handled', 'unhandled', 'failed', 'noWorkspace']
|
|
35
|
-
|
|
36
|
-
const CSS = `
|
|
37
|
-
.ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center;min-width:0}
|
|
38
|
-
.ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;max-width:100%;padding:0 12px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;text-decoration:none;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3)}
|
|
39
|
-
.ua-btn span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
40
|
-
.ua-btn svg{flex:none;width:14px;height:14px}
|
|
41
|
-
.ua-btn:disabled{cursor:default;opacity:.7}
|
|
42
|
-
@media (hover:hover){.ua-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
43
|
-
.ua-icon{width:32px;padding:0;box-shadow:none;color:var(--dsw-alias-label-tertiary)}
|
|
44
|
-
.ua-btn[data-state=pending] svg,.ua-btn[data-state=sending] svg{animation:ua-pulse 1.2s ease-in-out infinite}
|
|
45
|
-
.ua-btn[data-state=done]{color:var(--dsw-alias-state-success-primary)}
|
|
46
|
-
.ua-btn[data-state=unhandled]{color:var(--dsw-alias-state-warn-label,var(--dsw-alias-state-warn-primary))}
|
|
47
|
-
@keyframes ua-pulse{50%{opacity:.35}}
|
|
48
|
-
.ua-wrap{position:relative;display:inline-flex;max-width:100%;flex-wrap:wrap;align-items:center;gap:4px 8px}
|
|
49
|
-
.ua-menu{position:absolute;z-index:20;top:calc(100% + 4px);right:0;min-width:168px;padding:4px;border-radius:12px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-base));box-shadow:0 6px 24px #0000001f,inset 0 0 0 .5px var(--dsw-alias-border-l2);display:flex;flex-direction:column}
|
|
50
|
-
.ua-menu button{display:flex;align-items:center;gap:8px;min-height:36px;padding:7px 10px;border:0;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
51
|
-
@media (hover:hover){.ua-menu button:hover{background:var(--dsw-alias-interactive-bg-hover)}}
|
|
52
|
-
.ua-menu input{margin:4px 6px;min-height:36px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:16px}
|
|
53
|
-
.ua-menuRow{display:flex;justify-content:flex-end;gap:4px;padding:2px 4px}
|
|
54
|
-
.ua-error{flex-basis:100%;color:var(--dsw-alias-state-error-primary);font-size:12px;overflow-wrap:anywhere}
|
|
55
|
-
@media (width<=768px),(pointer:coarse){
|
|
56
|
-
.ua-btn{min-height:40px}
|
|
57
|
-
.ua-icon{width:40px}
|
|
58
|
-
.ua-menu{position:fixed;z-index:1000;top:auto;left:12px;right:12px;bottom:12px;max-height:60vh;overflow:auto;padding:8px;box-shadow:0 8px 40px #00000040,inset 0 0 0 .5px var(--dsw-alias-border-l2)}
|
|
59
|
-
.ua-menu button{min-height:44px;font-size:15px}
|
|
60
|
-
.ua-menu input{min-height:44px}
|
|
61
|
-
}
|
|
62
|
-
`
|
|
63
|
-
|
|
64
|
-
const ICONS = {
|
|
65
|
-
chat: 'M3 4.5A1.5 1.5 0 0 1 4.5 3h7A1.5 1.5 0 0 1 13 4.5v5A1.5 1.5 0 0 1 11.5 11H7l-3 2.5V11h.5A1.5 1.5 0 0 1 3 9.5z',
|
|
66
|
-
done: 'M3.5 8.5l3 3 6-7',
|
|
67
|
-
snooze: 'M8 4.5V8l2.2 1.4M13.5 8a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z',
|
|
68
|
-
event: 'M8.8 2.5 4 9h4l-.8 4.5L12 7H8z',
|
|
69
|
-
link: 'M6 3.5H3.5v9h9V10M9 3h4v4M13 3 7.5 8.5',
|
|
70
|
-
pending: 'M8 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0',
|
|
71
|
-
unhandled: 'M8 3.5v5.5M8 12v.5',
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** The next 09:00 after now, as an ISO string. */
|
|
75
|
-
function tomorrowMorning(now = new Date()) {
|
|
76
|
-
const date = new Date(now)
|
|
77
|
-
date.setDate(date.getDate() + 1)
|
|
78
|
-
date.setHours(9, 0, 0, 0)
|
|
79
|
-
return date.toISOString()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The draft for a chat about an item: the person's question goes first (a
|
|
84
|
-
* prompt from the data, or nothing yet), then the item quoted, then its
|
|
85
|
-
* context as JSON for the agent.
|
|
86
|
-
*/
|
|
87
|
-
function chatText({ prompt = '', title, lines = [], context }) {
|
|
88
|
-
const quote = [title ? `**${title}**` : null, ...lines].filter(Boolean).map(line => `> ${line}`).join('\n')
|
|
89
|
-
const parts = [prompt, quote]
|
|
90
|
-
if (context !== undefined) parts.push(`\`\`\`json\n${JSON.stringify(context, null, 2)}\n\`\`\``)
|
|
91
|
-
return `${parts.filter(Boolean).join('\n\n')}\n`
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @param {object} options
|
|
96
|
-
* @param {object} options.React - the page's React
|
|
97
|
-
* @param {object} options.ctx - the plugin's client context (ctx.get reaches the Web UI's services)
|
|
98
|
-
* @param {(key: string, params?: object) => string} options.t - the words in the person's language, one of KEYS
|
|
99
|
-
* @param {(action: object, extra: object) => Promise<unknown>} [options.press] - the server call for done, snooze and event
|
|
100
|
-
*/
|
|
101
|
-
function createActions({ React, ctx, t, press }) {
|
|
102
|
-
const h = React.createElement
|
|
103
|
-
const { useState, useEffect, useRef } = React
|
|
104
|
-
|
|
105
|
-
if (typeof document !== 'undefined' && !document.getElementById('dsh-actions-ui-style')) {
|
|
106
|
-
const style = document.createElement('style')
|
|
107
|
-
style.id = 'dsh-actions-ui-style'
|
|
108
|
-
style.dataset.plugin = OWNER
|
|
109
|
-
style.textContent = CSS
|
|
110
|
-
document.head.appendChild(style)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function Icon({ name }) {
|
|
114
|
-
return h('svg', { viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, h('path', { d: ICONS[name] ?? ICONS.event }))
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Open a conversation with `text` as its editable draft: a new one in the
|
|
119
|
-
* current (or most recent) workspace, or the given session.
|
|
120
|
-
*/
|
|
121
|
-
async function startChat({ text, session }) {
|
|
122
|
-
const workspace = ctx.get('uiWorkspace')
|
|
123
|
-
if (workspace === undefined) throw new Error(t('noWorkspace'))
|
|
124
|
-
if (session === undefined || session === 'new') {
|
|
125
|
-
workspace.startSession(undefined, { prompt: text, whenDraftExists: 'replace' })
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
workspace.openSession(session)
|
|
129
|
-
const sessions = ctx.get('sessions')
|
|
130
|
-
const conversation = ctx.get('conversation')
|
|
131
|
-
for (let i = 0; i < 30 && sessions && conversation; i += 1) {
|
|
132
|
-
const binding = sessions.binding(session)
|
|
133
|
-
if (binding !== undefined) {
|
|
134
|
-
try {
|
|
135
|
-
conversation.input.requestDraftInitialization(binding, { prompt: text, whenDraftExists: 'append' })
|
|
136
|
-
} catch {
|
|
137
|
-
// the session moved on before the draft landed; it is open, the person can type
|
|
138
|
-
}
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
await new Promise(resolve => setTimeout(resolve, 100))
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function SnoozeMenu({ onPick, onClose }) {
|
|
146
|
-
const [picking, setPicking] = useState(false)
|
|
147
|
-
const [value, setValue] = useState('')
|
|
148
|
-
const ref = useRef(null)
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
const away = event => { if (ref.current && !ref.current.contains(event.target)) onClose() }
|
|
151
|
-
const escape = event => { if (event.key === 'Escape') onClose() }
|
|
152
|
-
document.addEventListener('pointerdown', away)
|
|
153
|
-
document.addEventListener('keydown', escape)
|
|
154
|
-
return () => { document.removeEventListener('pointerdown', away); document.removeEventListener('keydown', escape) }
|
|
155
|
-
}, [onClose])
|
|
156
|
-
return h('div', { className: 'ua-menu', ref, role: 'menu' },
|
|
157
|
-
!picking && h('button', { type: 'button', role: 'menuitem', onClick: () => onPick(new Date(Date.now() + 3 * 3600 * 1000).toISOString()) }, t('in3h')),
|
|
158
|
-
!picking && h('button', { type: 'button', role: 'menuitem', onClick: () => onPick(tomorrowMorning()) }, t('tomorrow')),
|
|
159
|
-
!picking && h('button', { type: 'button', role: 'menuitem', onClick: () => setPicking(true) }, t('pick')),
|
|
160
|
-
picking && h('input', { type: 'datetime-local', value, autoFocus: true, onChange: event => setValue(event.target.value) }),
|
|
161
|
-
picking && h('div', { className: 'ua-menuRow' },
|
|
162
|
-
h('button', { type: 'button', onClick: onClose }, t('cancel')),
|
|
163
|
-
h('button', { type: 'button', disabled: value === '', onClick: () => onPick(new Date(value).toISOString()) }, t('set'))))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* One action as a button. `state` is the server's view of the last press
|
|
168
|
-
* (pending, done, unhandled); `compact` draws an icon only.
|
|
169
|
-
*/
|
|
170
|
-
function ActionButton({ action, state, compact, chat, onPress }) {
|
|
171
|
-
const [local, setLocal] = useState(null)
|
|
172
|
-
const [error, setError] = useState(null)
|
|
173
|
-
const [menu, setMenu] = useState(false)
|
|
174
|
-
useEffect(() => { if (state) setLocal(null) }, [state])
|
|
175
|
-
const shown = local ?? state
|
|
176
|
-
const label = action.label ?? t(action.kind)
|
|
177
|
-
const title = shown === 'sending' ? t('sending') : shown === 'pending' ? t('pending') : shown === 'done' ? t('handled') : shown === 'unhandled' ? t('unhandled') : error ?? label
|
|
178
|
-
const icon = shown === 'done' ? 'done' : shown === 'unhandled' ? 'unhandled' : action.kind
|
|
179
|
-
const className = `ua-btn${compact ? ' ua-icon' : ''}`
|
|
180
|
-
const content = [h(Icon, { key: 'i', name: icon }), !compact && h('span', { key: 'l' }, label)]
|
|
181
|
-
|
|
182
|
-
if (action.kind === 'link') {
|
|
183
|
-
const url = action.payload?.url
|
|
184
|
-
const external = /^https?:/i.test(url ?? '')
|
|
185
|
-
return h('a', { className, href: url, title: label, 'aria-label': label, ...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {}) }, content)
|
|
186
|
-
}
|
|
187
|
-
const send = async extra => {
|
|
188
|
-
setMenu(false)
|
|
189
|
-
setError(null)
|
|
190
|
-
setLocal('sending')
|
|
191
|
-
try {
|
|
192
|
-
if (action.kind === 'chat') {
|
|
193
|
-
await chat(action)
|
|
194
|
-
setLocal(null)
|
|
195
|
-
} else {
|
|
196
|
-
await (onPress ?? press)(action, extra ?? {})
|
|
197
|
-
setLocal('pending')
|
|
198
|
-
}
|
|
199
|
-
} catch (reason) {
|
|
200
|
-
setLocal(null)
|
|
201
|
-
setError(t('failed', { message: reason?.message ?? String(reason) }))
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const onClick = () => {
|
|
205
|
-
if (action.kind === 'snooze' && action.payload?.until === undefined) setMenu(open => !open)
|
|
206
|
-
else send()
|
|
207
|
-
}
|
|
208
|
-
const busy = shown === 'sending' || shown === 'pending'
|
|
209
|
-
return h('span', { className: 'ua-wrap' },
|
|
210
|
-
h('button', { type: 'button', className, title, 'aria-label': `${label}${title !== label ? ` (${title})` : ''}`, 'data-state': shown ?? undefined, disabled: busy, onClick }, content),
|
|
211
|
-
menu && h(SnoozeMenu, { onPick: until => send({ until }), onClose: () => setMenu(false) }),
|
|
212
|
-
error && !compact && h('span', { className: 'ua-error', role: 'alert' }, error))
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* A row of action buttons.
|
|
217
|
-
* @param {object} props
|
|
218
|
-
* @param {object[]} props.actions - the item's actions, as the data declares them
|
|
219
|
-
* @param {Record<string, string>} [props.states] - press state by action id
|
|
220
|
-
* @param {boolean} [props.compact] - icons only (for rows)
|
|
221
|
-
* @param {(action: object) => Promise<void>} props.chat - opens the chat for a chat action
|
|
222
|
-
* @param {(action: object, extra: object) => Promise<unknown>} [props.onPress] - this bar's press call, instead of the one given to createActions
|
|
223
|
-
*/
|
|
224
|
-
function ActionBar({ actions, states = {}, compact = false, chat, onPress }) {
|
|
225
|
-
if (!actions || actions.length === 0) return null
|
|
226
|
-
return h('div', { className: 'ua-bar' }, actions.map(action =>
|
|
227
|
-
h(ActionButton, { key: action.id, action, state: states[action.id], compact, chat, onPress })))
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return { ActionBar, ActionButton, Icon, startChat, chatText, t }
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
window.__ModuleLoader__.load({ id: OWNER, chunk: 'client.actions.js', factory: () => ({ createActions, chatText, KEYS }) })
|
|
234
|
-
})()
|