@soffits/dsh-notify-inbox 0.1.0 → 0.1.1

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ - Buttons come from the shared action bar (`client.actions.js`, the same one the card board uses), so both pages look and behave alike; buttons without a label get the shared words.
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  - First release: per-person inbox from JSON lines, read and unread kept on the server, Web Push (RFC 8291 encryption and VAPID on node:crypto) with deep links, buttons on notifications (ask about this, done, snooze, event, link) whose presses become `ui.action.<kind>` events, English and Chinese.
@@ -0,0 +1,259 @@
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; the
8
+ * file has no imports and takes React and the client context as arguments.
9
+ *
10
+ * const { createActions } = await require.async('./client.actions.js')
11
+ * const ui = createActions({ React, ctx, locale: 'en', press })
12
+ * h(ui.ActionBar, { actions, states, chat, onPress })
13
+ *
14
+ * `press(action, extra)` is the plugin's own server call for done, snooze and
15
+ * event (extra carries `until` for a snooze); it should resolve once the
16
+ * server has accepted the press. `chat` and `link` never reach the server:
17
+ * chat opens a conversation with a prefilled, editable draft through the Web
18
+ * UI's own workspace service (so the person sends it themselves, signed in as
19
+ * themselves), and link opens the URL.
20
+ */
21
+ const OWNER = '@soffits/dsh-notify-inbox'
22
+
23
+ const WORDS = {
24
+ en: {
25
+ chat: 'Ask',
26
+ chatAbout: 'Chat about this',
27
+ done: 'Done',
28
+ snooze: 'Snooze',
29
+ open: 'Open',
30
+ in3h: 'In 3 hours',
31
+ tomorrow: 'Tomorrow 9:00',
32
+ pick: 'Pick a time…',
33
+ set: 'Snooze',
34
+ cancel: 'Cancel',
35
+ sending: 'Sending…',
36
+ pending: 'Waiting for it to be picked up',
37
+ handled: 'Done',
38
+ unhandled: 'Nothing picked this up yet',
39
+ failed: 'Didn’t go through: {message}',
40
+ noWorkspace: 'Open a conversation once first, then try again.',
41
+ },
42
+ zh: {
43
+ chat: '问问',
44
+ chatAbout: '聊聊这个',
45
+ done: '完成',
46
+ snooze: '稍后提醒',
47
+ open: '打开',
48
+ in3h: '3 小时后',
49
+ tomorrow: '明天 9:00',
50
+ pick: '选个时间…',
51
+ set: '稍后提醒',
52
+ cancel: '取消',
53
+ sending: '发送中…',
54
+ pending: '等待处理',
55
+ handled: '已处理',
56
+ unhandled: '还没有被处理',
57
+ failed: '没有成功:{message}',
58
+ noWorkspace: '请先打开一次对话,再试一次。',
59
+ },
60
+ }
61
+
62
+ const CSS = `
63
+ .ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
64
+ .ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;gap:5px;height:28px;padding:0 10px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;white-space:nowrap;text-decoration:none;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3)}
65
+ .ua-btn svg{flex:none;width:14px;height:14px}
66
+ .ua-btn:disabled{cursor:default;opacity:.7}
67
+ @media (hover:hover){.ua-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
68
+ .ua-icon{width:26px;height:26px;padding:0;justify-content:center;box-shadow:none;color:var(--dsw-alias-label-tertiary)}
69
+ .ua-btn[data-state=pending] svg,.ua-btn[data-state=sending] svg{animation:ua-pulse 1.2s ease-in-out infinite}
70
+ .ua-btn[data-state=done]{color:var(--dsw-alias-state-success-primary)}
71
+ .ua-btn[data-state=unhandled]{color:var(--dsw-alias-state-warn-label,var(--dsw-alias-state-warn-primary))}
72
+ @keyframes ua-pulse{50%{opacity:.35}}
73
+ .ua-wrap{position:relative;display:inline-flex}
74
+ .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}
75
+ .ua-menu button{display:flex;align-items:center;gap:8px;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}
76
+ @media (hover:hover){.ua-menu button:hover{background:var(--dsw-alias-interactive-bg-hover)}}
77
+ .ua-menu input{margin:4px 6px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:13px}
78
+ .ua-menuRow{display:flex;justify-content:flex-end;gap:4px;padding:2px 4px}
79
+ .ua-error{color:var(--dsw-alias-state-error-primary);font-size:12px}
80
+ `
81
+
82
+ const ICONS = {
83
+ 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',
84
+ done: 'M3.5 8.5l3 3 6-7',
85
+ 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',
86
+ event: 'M8.8 2.5 4 9h4l-.8 4.5L12 7H8z',
87
+ link: 'M6 3.5H3.5v9h9V10M9 3h4v4M13 3 7.5 8.5',
88
+ pending: 'M8 8m-2 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0',
89
+ unhandled: 'M8 3.5v5.5M8 12v.5',
90
+ }
91
+
92
+ function fill(text, params) {
93
+ return String(text).replace(/\{(\w+)\}/g, (match, key) => (key in params ? String(params[key]) : match))
94
+ }
95
+
96
+ /** The next 09:00 after now, as an ISO string. */
97
+ function tomorrowMorning(now = new Date()) {
98
+ const date = new Date(now)
99
+ date.setDate(date.getDate() + 1)
100
+ date.setHours(9, 0, 0, 0)
101
+ return date.toISOString()
102
+ }
103
+
104
+ /**
105
+ * The draft for a chat about an item: the person's question goes first (a
106
+ * prompt from the data, or nothing yet), then the item quoted, then its
107
+ * context as JSON for the agent.
108
+ */
109
+ function chatText({ prompt = '', title, lines = [], context }) {
110
+ const quote = [title ? `**${title}**` : null, ...lines].filter(Boolean).map(line => `> ${line}`).join('\n')
111
+ const parts = [prompt, quote]
112
+ if (context !== undefined) parts.push(`\`\`\`json\n${JSON.stringify(context, null, 2)}\n\`\`\``)
113
+ return `${parts.filter(Boolean).join('\n\n')}\n`
114
+ }
115
+
116
+ /**
117
+ * @param {object} options
118
+ * @param {object} options.React - the page's React
119
+ * @param {object} options.ctx - the plugin's client context (ctx.get reaches the Web UI's services)
120
+ * @param {string} [options.locale] - 'zh…' picks Chinese words, anything else English
121
+ * @param {(action: object, extra: object) => Promise<unknown>} [options.press] - the server call for done, snooze and event
122
+ */
123
+ function createActions({ React, ctx, locale = 'en', press }) {
124
+ const h = React.createElement
125
+ const { useState, useEffect, useRef } = React
126
+ const words = WORDS[String(locale).toLowerCase().startsWith('zh') ? 'zh' : 'en']
127
+ const t = key => words[key] ?? WORDS.en[key] ?? key
128
+
129
+ if (typeof document !== 'undefined' && !document.getElementById('dsh-actions-ui-style')) {
130
+ const style = document.createElement('style')
131
+ style.id = 'dsh-actions-ui-style'
132
+ style.dataset.plugin = OWNER
133
+ style.textContent = CSS
134
+ document.head.appendChild(style)
135
+ }
136
+
137
+ function Icon({ name }) {
138
+ 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 }))
139
+ }
140
+
141
+ /**
142
+ * Open a conversation with `text` as its editable draft: a new one in the
143
+ * current (or most recent) workspace, or the given session.
144
+ */
145
+ async function startChat({ text, session }) {
146
+ const workspace = ctx.get('uiWorkspace')
147
+ if (workspace === undefined) throw new Error(t('noWorkspace'))
148
+ if (session === undefined || session === 'new') {
149
+ workspace.startSession(undefined, { prompt: text, whenDraftExists: 'replace' })
150
+ return
151
+ }
152
+ workspace.openSession(session)
153
+ const sessions = ctx.get('sessions')
154
+ const conversation = ctx.get('conversation')
155
+ for (let i = 0; i < 30 && sessions && conversation; i += 1) {
156
+ const binding = sessions.binding(session)
157
+ if (binding !== undefined) {
158
+ try {
159
+ conversation.input.requestDraftInitialization(binding, { prompt: text, whenDraftExists: 'append' })
160
+ } catch {
161
+ // the session moved on before the draft landed; it is open, the person can type
162
+ }
163
+ return
164
+ }
165
+ await new Promise(resolve => setTimeout(resolve, 100))
166
+ }
167
+ }
168
+
169
+ function SnoozeMenu({ onPick, onClose }) {
170
+ const [picking, setPicking] = useState(false)
171
+ const [value, setValue] = useState('')
172
+ const ref = useRef(null)
173
+ useEffect(() => {
174
+ const away = event => { if (ref.current && !ref.current.contains(event.target)) onClose() }
175
+ const escape = event => { if (event.key === 'Escape') onClose() }
176
+ document.addEventListener('pointerdown', away)
177
+ document.addEventListener('keydown', escape)
178
+ return () => { document.removeEventListener('pointerdown', away); document.removeEventListener('keydown', escape) }
179
+ }, [onClose])
180
+ return h('div', { className: 'ua-menu', ref, role: 'menu' },
181
+ !picking && h('button', { type: 'button', role: 'menuitem', onClick: () => onPick(new Date(Date.now() + 3 * 3600 * 1000).toISOString()) }, t('in3h')),
182
+ !picking && h('button', { type: 'button', role: 'menuitem', onClick: () => onPick(tomorrowMorning()) }, t('tomorrow')),
183
+ !picking && h('button', { type: 'button', role: 'menuitem', onClick: () => setPicking(true) }, t('pick')),
184
+ picking && h('input', { type: 'datetime-local', value, autoFocus: true, onChange: event => setValue(event.target.value) }),
185
+ picking && h('div', { className: 'ua-menuRow' },
186
+ h('button', { type: 'button', onClick: onClose }, t('cancel')),
187
+ h('button', { type: 'button', disabled: value === '', onClick: () => onPick(new Date(value).toISOString()) }, t('set'))))
188
+ }
189
+
190
+ /**
191
+ * One action as a button. `state` is the server's view of the last press
192
+ * (pending, done, unhandled); `compact` draws an icon only.
193
+ */
194
+ function ActionButton({ action, state, compact, chat, onPress }) {
195
+ const [local, setLocal] = useState(null)
196
+ const [error, setError] = useState(null)
197
+ const [menu, setMenu] = useState(false)
198
+ useEffect(() => { if (state) setLocal(null) }, [state])
199
+ const shown = local ?? state
200
+ const label = action.label ?? t(action.kind === 'chat' ? 'chat' : action.kind === 'link' ? 'open' : action.kind)
201
+ const title = shown === 'sending' ? t('sending') : shown === 'pending' ? t('pending') : shown === 'done' ? t('handled') : shown === 'unhandled' ? t('unhandled') : error ?? label
202
+ const icon = shown === 'done' ? 'done' : shown === 'unhandled' ? 'unhandled' : action.kind
203
+ const className = `ua-btn${compact ? ' ua-icon' : ''}`
204
+ const content = [h(Icon, { key: 'i', name: icon }), !compact && h('span', { key: 'l' }, label)]
205
+
206
+ if (action.kind === 'link') {
207
+ const url = action.payload?.url
208
+ const external = /^https?:/i.test(url ?? '')
209
+ return h('a', { className, href: url, title: label, 'aria-label': label, ...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {}) }, content)
210
+ }
211
+ const send = async extra => {
212
+ setMenu(false)
213
+ setError(null)
214
+ setLocal('sending')
215
+ try {
216
+ if (action.kind === 'chat') {
217
+ await chat(action)
218
+ setLocal(null)
219
+ } else {
220
+ await (onPress ?? press)(action, extra ?? {})
221
+ setLocal('pending')
222
+ }
223
+ } catch (reason) {
224
+ setLocal(null)
225
+ setError(fill(t('failed'), { message: reason?.message ?? String(reason) }))
226
+ }
227
+ }
228
+ const onClick = () => {
229
+ if (action.kind === 'snooze' && action.payload?.until === undefined) setMenu(open => !open)
230
+ else send()
231
+ }
232
+ const busy = shown === 'sending' || shown === 'pending'
233
+ return h('span', { className: 'ua-wrap' },
234
+ h('button', { type: 'button', className, title, 'aria-label': `${label}${title !== label ? ` (${title})` : ''}`, 'data-state': shown ?? undefined, disabled: busy, onClick }, content),
235
+ menu && h(SnoozeMenu, { onPick: until => send({ until }), onClose: () => setMenu(false) }),
236
+ error && !compact && h('span', { className: 'ua-error', role: 'alert' }, error))
237
+ }
238
+
239
+ /**
240
+ * A row of action buttons.
241
+ * @param {object} props
242
+ * @param {object[]} props.actions - the item's actions, as the data declares them
243
+ * @param {Record<string, string>} [props.states] - press state by action id
244
+ * @param {boolean} [props.compact] - icons only (for rows)
245
+ * @param {(action: object) => Promise<void>} props.chat - opens the chat for a chat action
246
+ * @param {(action: object, extra: object) => Promise<unknown>} [props.onPress] - this bar's press call, instead of the one given to createActions
247
+ */
248
+ function ActionBar({ actions, states = {}, compact = false, chat, onPress }) {
249
+ if (!actions || actions.length === 0) return null
250
+ return h('div', { className: 'ua-bar' }, actions.map(action =>
251
+ h(ActionButton, { key: action.id, action, state: states[action.id], compact, chat, onPress })))
252
+ }
253
+
254
+ return { ActionBar, ActionButton, Icon, startChat, chatText, t }
255
+ }
256
+
257
+ if (typeof window !== 'undefined' && window.__ModuleLoader__) {
258
+ window.__ModuleLoader__.load({ id: `${OWNER}/client.actions.js`, factory: () => ({ createActions, chatText }) })
259
+ }
package/client.js CHANGED
@@ -37,20 +37,10 @@ window.__ModuleLoader__.load({
37
37
  'notSent': 'Not sent anywhere else',
38
38
  'files': 'Attachments',
39
39
  'notStored': 'not kept: {reason}',
40
- 'action.chat': 'Ask about this',
41
- 'action.done': 'Done',
42
- 'action.snooze': 'Remind me later',
43
- 'action.event': 'Send',
44
- 'action.link': 'Open',
45
- 'snooze.hour': 'In an hour',
46
- 'snooze.evening': 'This evening',
47
- 'snooze.tomorrow': 'Tomorrow morning',
48
40
  'press.pending': 'Sent, waiting…',
49
41
  'press.unhandled': 'Nobody picked this up yet',
50
42
  'press.done': 'Marked done',
51
43
  'press.snoozed': 'Will remind you {time}',
52
- 'chat.intro': 'About this notification:',
53
- 'chat.unavailable': 'Open a workspace first, then try again.',
54
44
  'push.title': 'Notifications on this device',
55
45
  'push.on': 'On',
56
46
  'push.off': 'Off',
@@ -79,20 +69,10 @@ window.__ModuleLoader__.load({
79
69
  'notSent': '没有发到别处',
80
70
  'files': '附件',
81
71
  'notStored': '未保存:{reason}',
82
- 'action.chat': '问问这条',
83
- 'action.done': '完成',
84
- 'action.snooze': '稍后提醒',
85
- 'action.event': '发送',
86
- 'action.link': '打开',
87
- 'snooze.hour': '一小时后',
88
- 'snooze.evening': '今晚',
89
- 'snooze.tomorrow': '明早',
90
72
  'press.pending': '已发出,等待处理…',
91
73
  'press.unhandled': '暂时没有人处理',
92
74
  'press.done': '已标为完成',
93
75
  'press.snoozed': '会在{time}再提醒',
94
- 'chat.intro': '关于这条通知:',
95
- 'chat.unavailable': '先打开一个工作区,再试一次。',
96
76
  'push.title': '本设备的通知',
97
77
  'push.on': '已开启',
98
78
  'push.off': '未开启',
@@ -151,7 +131,6 @@ window.__ModuleLoader__.load({
151
131
  .nib-ok{color:var(--dsw-alias-state-success-primary)}
152
132
  .nib-bad{color:var(--dsw-alias-state-error-primary)}
153
133
  .nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
154
- .nib-menu{display:flex;flex-wrap:wrap;gap:6px;padding:6px;border-radius:10px;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3)}
155
134
  .nib-status{color:var(--dsw-alias-label-tertiary);font-size:12px}
156
135
  .nib-empty{color:var(--dsw-alias-label-tertiary);padding:24px 12px}
157
136
  .nib-error{color:var(--dsw-alias-state-error-primary);padding:12px}
@@ -211,24 +190,6 @@ window.__ModuleLoader__.load({
211
190
  }
212
191
  const absolute = (iso, t) => new Date(iso).toLocaleString(t('time.locale'), { dateStyle: 'medium', timeStyle: 'short' })
213
192
 
214
- /** Snooze choices as ISO times with this browser's offset. */
215
- function snoozeTimes() {
216
- const now = new Date()
217
- const hour = new Date(now.getTime() + 3600 * 1000)
218
- const evening = new Date(now)
219
- evening.setHours(19, 0, 0, 0)
220
- if (evening.getTime() - now.getTime() < 2 * 3600 * 1000) evening.setTime(now.getTime() + 3 * 3600 * 1000)
221
- const tomorrow = new Date(now)
222
- tomorrow.setDate(tomorrow.getDate() + 1)
223
- tomorrow.setHours(9, 0, 0, 0)
224
- const iso = date => {
225
- const offset = -date.getTimezoneOffset()
226
- const pad = n => String(Math.floor(Math.abs(n))).padStart(2, '0')
227
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:00${offset >= 0 ? '+' : '-'}${pad(offset / 60)}:${pad(offset % 60)}`
228
- }
229
- return [['snooze.hour', iso(hour)], ['snooze.evening', iso(evening)], ['snooze.tomorrow', iso(tomorrow)]]
230
- }
231
-
232
193
  /** What happened to this item's latest press, in words, or null. */
233
194
  function pressStatus(item, t) {
234
195
  const press = item.presses[item.presses.length - 1]
@@ -242,58 +203,42 @@ window.__ModuleLoader__.load({
242
203
  return Date.now() - Date.parse(press.at) < PENDING_MS ? t('press.pending') : t('press.unhandled')
243
204
  }
244
205
 
245
- function chatPrompt(item, t) {
246
- const quoted = [item.title, item.text || item.spoken].filter(Boolean).join('\n\n').split('\n').map(line => `> ${line}`).join('\n')
247
- const context = { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined, links: item.links.length ? item.links : undefined }
248
- return `${t('chat.intro')}\n\n${quoted}\n\n\`\`\`json\n${JSON.stringify(context)}\n\`\`\`\n\n`
249
- }
206
+ // ---- the buttons: the shared action bar (client.actions.js, also used by the card board) ----
250
207
 
251
- // ---- the actions row (a thin local adapter until a shared actions module exists) ----
208
+ let actionsModule
209
+ const loadActions = () => (actionsModule ??= require.async('./client.actions.js'))
252
210
 
253
- function Actions({ item, t, startChat }) {
254
- const [snoozing, setSnoozing] = useState(false)
255
- const [busy, setBusy] = useState(false)
256
- const [error, setError] = useState(null)
257
- const press = async (action, until) => {
258
- setBusy(true)
259
- setError(null)
260
- try {
261
- await call('action', { record: item.id, action: action.id, ...(until ? { until } : {}) })
262
- setSnoozing(false)
263
- changed()
264
- } catch (reason) {
265
- setError(reason.message)
266
- } finally {
267
- setBusy(false)
268
- }
211
+ /** The server's view of each button's last press: pending, done or unhandled. */
212
+ function pressStates(item) {
213
+ const states = {}
214
+ for (const press of item.presses) {
215
+ const action = item.actions.find(row => row.kind === press.action) ?? { id: press.action }
216
+ const handled = item.handled.some(row => row.press === press.press)
217
+ states[action.id] = handled ? 'done' : Date.now() - Date.parse(press.at) < PENDING_MS ? 'pending' : 'unhandled'
218
+ }
219
+ return states
220
+ }
221
+
222
+ function Actions({ item, t, ui }) {
223
+ if (ui === null) return null
224
+ const declared = item.actions.some(action => action.kind === 'chat') ? item.actions : [{ kind: 'chat', id: 'chat', payload: {} }, ...item.actions]
225
+ const chat = action => ui.startChat({
226
+ text: ui.chatText({ prompt: action.payload?.prompt ?? '', title: item.title || item.spoken, lines: (item.text || item.spoken).split('\n'),
227
+ context: { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined, links: item.links.length ? item.links : undefined } }),
228
+ session: action.payload?.session,
229
+ })
230
+ const onPress = async (action, extra) => {
231
+ await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
232
+ changed()
269
233
  }
270
- const declared = item.actions.filter(action => action.kind !== 'chat')
271
- const chat = item.actions.find(action => action.kind === 'chat') ?? { kind: 'chat', id: 'chat', label: '', payload: {} }
272
- const label = action => action.label || t(`action.${action.kind}`)
273
- const buttons = [
274
- h('button', { key: 'chat', type: 'button', className: 'nib-btn', onClick: () => startChat(chat.payload?.prompt ? `${chat.payload.prompt}\n\n${chatPrompt(item, t)}` : chatPrompt(item, t)) }, label(chat)),
275
- ...declared.map(action => {
276
- if (action.kind === 'link') {
277
- return h('a', { key: action.id, className: 'nib-btn', href: action.payload.url, target: action.payload.url.startsWith('/') ? undefined : '_blank', rel: 'noopener noreferrer' }, label(action))
278
- }
279
- if (action.kind === 'snooze' && !action.payload.until) {
280
- return h('button', { key: action.id, type: 'button', className: 'nib-btn', disabled: busy, 'aria-expanded': snoozing, onClick: () => setSnoozing(!snoozing) }, label(action))
281
- }
282
- return h('button', { key: action.id, type: 'button', className: `nib-btn${action.kind === 'done' ? ' nib-primary' : ''}`, disabled: busy, onClick: () => press(action) }, label(action))
283
- }),
284
- ]
285
- const snooze = declared.find(action => action.kind === 'snooze')
286
234
  const status = pressStatus(item, t)
287
- return h(React.Fragment, null,
288
- h('div', { className: 'nib-actions' }, ...buttons, status && h('span', { className: 'nib-status' }, status)),
289
- snoozing && snooze && h('div', { className: 'nib-menu', role: 'group' },
290
- snoozeTimes().map(([key, until]) => h('button', { key, type: 'button', className: 'nib-btn', disabled: busy, onClick: () => press(snooze, until) }, t(key)))),
291
- error && h('div', { className: 'nib-error', role: 'alert' }, error))
235
+ return h('div', { className: 'nib-actions' }, h(ui.ActionBar, { actions: declared, states: pressStates(item), chat, onPress }),
236
+ status && h('span', { className: 'nib-status' }, status))
292
237
  }
293
238
 
294
239
  // ---- one notification ----
295
240
 
296
- function Item({ item, t, open, onToggle, startChat }) {
241
+ function Item({ item, t, open, onToggle, ui }) {
297
242
  const urgent = item.lane === 'interrupt'
298
243
  const className = ['nib-item', item.read ? '' : 'nib-unread', urgent ? 'nib-urgent' : '', open ? 'nib-open' : ''].filter(Boolean).join(' ')
299
244
  const title = item.title || item.spoken || item.text.slice(0, 80)
@@ -317,7 +262,7 @@ window.__ModuleLoader__.load({
317
262
  item.files.map(file => file.stored
318
263
  ? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
319
264
  : h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
320
- h(Actions, { item, t, startChat }),
265
+ h(Actions, { item, t, ui }),
321
266
  h('div', { className: 'nib-meta' },
322
267
  item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
323
268
  item.routed.map(row => h('span', { key: row.destination, className: 'nib-route', title: row.detail || '' },
@@ -414,7 +359,7 @@ window.__ModuleLoader__.load({
414
359
 
415
360
  // ---- the page ----
416
361
 
417
- function InboxPage({ translate: t, startChat }) {
362
+ function InboxPage({ translate: t, makeActions }) {
418
363
  const version = useShared(s => s.version)
419
364
  const unread = useShared(s => s.unread)
420
365
  const linked = useShared(s => s.linked)
@@ -423,6 +368,12 @@ window.__ModuleLoader__.load({
423
368
  const [more, setMore] = useState(false)
424
369
  const [error, setError] = useState(null)
425
370
  const [open, setOpen] = useState(() => shared.linked)
371
+ const [ui, setUi] = useState(null)
372
+ useEffect(() => {
373
+ let live = true
374
+ makeActions(t('time.locale')).then(made => { if (live) setUi(made) }, reason => { if (live) setError(reason.message) })
375
+ return () => { live = false }
376
+ }, [])
426
377
 
427
378
  const load = useCallback(async (append) => {
428
379
  try {
@@ -470,7 +421,7 @@ window.__ModuleLoader__.load({
470
421
  error && h('p', { className: 'nib-error', role: 'alert' }, t('error', { message: error })),
471
422
  items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(filter === 'unread' ? 'empty.unread' : 'empty.all')),
472
423
  items !== null && h('ul', { className: 'nib-list' },
473
- items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, startChat }))),
424
+ items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, ui }))),
474
425
  more && h('button', { type: 'button', className: 'nib-btn nib-more', onClick: () => load(true) }, t('loadMore')))))
475
426
  }
476
427
 
@@ -502,20 +453,13 @@ window.__ModuleLoader__.load({
502
453
  return () => tag.remove()
503
454
  }, 'notify-inbox: styles')
504
455
 
505
- const startChat = prompt => {
506
- const workspace = ctx.get('uiWorkspace')
507
- if (workspace === undefined) {
508
- window.alert(t('chat.unavailable'))
509
- return
510
- }
511
- workspace.startSession(undefined, { prompt, whenDraftExists: 'replace' })
512
- }
456
+ const makeActions = locale => loadActions().then(module => module.createActions({ React, ctx, locale }))
513
457
 
514
458
  ctx.slots.inject('main', () => ctx.slots.register({
515
459
  name: 'main',
516
460
  key: PANEL,
517
461
  locale: NS,
518
- inject: () => ({ translate: t, startChat }),
462
+ inject: () => ({ translate: t, makeActions }),
519
463
  }, InboxPage))
520
464
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
521
465
  name: 'sidebar.panellist',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soffits/dsh-notify-inbox",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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,11 +18,12 @@
18
18
  "exports": {
19
19
  ".": "./index.js",
20
20
  "./client": "./client.js",
21
+ "./client.actions.js": "./client.actions.js",
21
22
  "./locale/*.json": "./locale/*.json",
22
23
  "./icon": "./icon.svg",
23
24
  "./package.json": "./package.json"
24
25
  },
25
- "files": ["src", "client.js", "index.js", "cordis.patch.yml", "locale/*.json", "icon.svg", "README.md", "CHANGELOG.md", "LICENSE"],
26
+ "files": ["src", "client.js", "client.actions.js", "index.js", "cordis.patch.yml", "locale/*.json", "icon.svg", "README.md", "CHANGELOG.md", "LICENSE"],
26
27
  "dsh": {
27
28
  "bundle": {
28
29
  "patch": "./cordis.patch.yml"
@@ -38,7 +39,7 @@
38
39
  }
39
40
  },
40
41
  "scripts": {
41
- "check": "for f in index.js client.js src/*.js test/*.js; do node --check \"$f\" || exit 1; done",
42
+ "check": "for f in index.js client.js client.actions.js src/*.js test/*.js; do node --check \"$f\" || exit 1; done",
42
43
  "test": "node --test test/*.test.js"
43
44
  },
44
45
  "dependencies": {
package/src/store.js CHANGED
@@ -48,7 +48,7 @@ export function normalize(raw, person) {
48
48
  actions: list(raw.actions).filter(action => typeof action?.kind === 'string' && typeof action?.id === 'string').map(action => ({
49
49
  kind: action.kind,
50
50
  id: action.id,
51
- label: text(action.label),
51
+ label: text(action.label) || undefined,
52
52
  payload: typeof action.payload === 'object' && action.payload !== null && !Array.isArray(action.payload) ? action.payload : {},
53
53
  })),
54
54
  test: raw.test === true,