@soffits/dsh-matrix-bot 0.1.0 → 0.2.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
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.1
6
+
7
+ - `!model` and `!effort` switch only the room's session. They used to go through the Web UI's model picker, which also saves every pick as the default for new sessions, so a switch in one room changed the model every other new session started on. The model is still checked with the host before the switch, and `/reset` in the room still starts on the room's pick.
8
+
9
+ ## 0.2.0
10
+
11
+ - Prompts carry metadata only: the sender on `source.principal` (the room is now `chat: { id, name }`, was `room`), and the send time and the replied-to message on `source.envelope` (`sentAt`, `replyTo`), the shape [dsh-message-context](https://github.com/soffits/dsh-message-context) reads. The bot no longer adds its own `matrix-sender` notice or reply text; install dsh-message-context to show the model who wrote each message.
12
+
5
13
  ## 0.1.0
6
14
 
7
15
  First release: a Matrix bot for DSH with end-to-end encryption (cross-signing, recovery key, key backup), a private Space per allowed person with one room per session, rooms joined from the Space or made with `!new`, streamed answers, typing notices and working reactions, files and voice messages, tool approvals and agent questions answered with reactions, Telegram-style commands published for bot command completion, `Matrix-<person>-<task>` session titles, the `matrixRooms` send service, the `matrix_send` tool and the `dsh-matrix` command.
package/README.md CHANGED
@@ -78,7 +78,7 @@ Commands start with `!`, which works in every Matrix client. `/` works too in cl
78
78
  | `!allow`, `!deny` | Answer the waiting tool request |
79
79
  | `!id`, `!ping`, `!restart` | Ids, a check, and reconnecting |
80
80
 
81
- Lists such as `!model` are numbered; the same command with the numbers picks one (`!model 2 5`).
81
+ Lists such as `!model` are numbered; the same command with the numbers picks one (`!model 2 5`). A model or effort picked in a room applies to that room's session only; the default for new sessions stays as it is.
82
82
 
83
83
  ## Sending from scripts, agents and other plugins
84
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soffits/dsh-matrix-bot",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Matrix bot for DeepSeek Harness: an end-to-end encrypted Matrix account, a private Space per person with one room per DSH session, streamed answers, commands, files, voice messages, tool approvals and agent questions.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/controls.js CHANGED
@@ -2,8 +2,8 @@
2
2
  * Session controls from a room: model, reasoning effort, access mode and
3
3
  * context use, picked from numbered lists.
4
4
  */
5
- import { defaultModelOf, effortChoices, effortName, findModel, modelName, pickedSelection, sessionModelOf } from './models.js'
6
- import { controllerOf, currentPermission, permissionOptions, setPermission } from './sessions.js'
5
+ import { defaultModelOf, effortChoices, effortName, findModel, modelName, pickedSelection, selectSessionModel, sessionModelOf } from './models.js'
6
+ import { currentPermission, permissionOptions, setPermission } from './sessions.js'
7
7
 
8
8
  /** @returns `n` as a 1-based list index into `items`, or undefined. */
9
9
  export function pick(items, value) {
@@ -81,18 +81,12 @@ async function contextUse(bridge, roomId, current) {
81
81
  return { windowSize, used }
82
82
  }
83
83
 
84
- /** Apply a model selection the way the Web picker does, and remember it for /new. */
84
+ /** Switch the room's session to a model, and remember it for /new; the default for new sessions stays. */
85
85
  async function selectModel(bridge, roomId, selection) {
86
86
  const store = bridge.store()
87
87
  store.data.picks[roomId] = selection
88
88
  await store.save()
89
- const agent = await bridge.ensureAgent(roomId, { claim: true })
90
- const controller = controllerOf(bridge.ctx)
91
- if (typeof controller?.selectModel === 'function') {
92
- await controller.selectModel({ sessionId: agent.session?.id ?? agent.id, ...selection })
93
- return
94
- }
95
- agent.model.select(selection)
89
+ await selectSessionModel(bridge.ctx, await bridge.ensureAgent(roomId, { claim: true }), selection)
96
90
  }
97
91
 
98
92
  /** Handlers of the control commands, merged into the command table. */
package/src/events.js CHANGED
@@ -6,11 +6,11 @@ import { randomUUID } from 'node:crypto'
6
6
  import { join } from 'node:path'
7
7
  import { parseCommand, runCommand } from './commands.js'
8
8
  import { dataDir, POST_SOURCE_KIND, REQUEST_PREFIX } from './constants.js'
9
- import { composePrompt, describeReply, hasMedia, ownText, replyTargetOf } from './inbound.js'
9
+ import { composePrompt, hasMedia, ownText, replyInfo, replyTargetOf } from './inbound.js'
10
10
  import { allowedEntry } from './operations.js'
11
11
  import { matrixUserPrincipal, withPrincipal } from './sender.js'
12
12
  import { admitPrompt, hasRequest, recordMessage, unarchive } from './sessions.js'
13
- import { clip, formatMoment } from './text.js'
13
+ import { clip } from './text.js'
14
14
 
15
15
  /** @returns a short message for any thrown value. */
16
16
  function messageOf(error) {
@@ -185,7 +185,7 @@ export function createEvents({ ctx, getStore, storeReady, getMatrix, setting, sp
185
185
  if (react) await reactions.mark(roomId, event.event_id, reactions.emojiFor(live?.status !== undefined && live.status !== 'idle', steer))
186
186
  const replyTo = replyTargetOf(event.content)
187
187
  const target = replyTo === undefined ? undefined : await getMatrix().getEvent(roomId, replyTo).catch(() => undefined)
188
- const context = describeReply(target, { botId: getMatrix().userId, sentRecord: replyTo === undefined ? undefined : getStore().sentRecord(replyTo), names: { [sender.userId]: sender.name } })
188
+ const reply = replyInfo(target, { botId: getMatrix().userId, senderId: sender.userId, sentRecord: replyTo === undefined ? undefined : getStore().sentRecord(replyTo), names: { [sender.userId]: sender.name } })
189
189
  const prompt = await composePrompt(event, {
190
190
  download: (content) => getMatrix().download(content),
191
191
  mediaDir: join(dataDir(), 'media'),
@@ -206,8 +206,13 @@ export function createEvents({ ctx, getStore, storeReady, getMatrix, setting, sp
206
206
  const running = agent.status !== undefined && agent.status !== 'idle'
207
207
  const mode = running && steer ? 'steer' : 'queue'
208
208
  const principal = matrixUserPrincipal(sender.userId, { name: sender.name, roomId, room: getStore().room(roomId)?.roomName })
209
- principals.remember(requestId, { principal, context, sentAt: formatMoment(event.origin_server_ts) })
210
- const admitted = await admitPrompt(ctx, agent, { requestId, text: prompt.text, attachments: prompt.attachments, mode, principal }, signal)
209
+ const envelope = {
210
+ ...(typeof event.origin_server_ts === 'number' ? { sentAt: event.origin_server_ts } : {}),
211
+ ...(reply === undefined ? {} : { replyTo: reply }),
212
+ }
213
+ const metadata = { principal, ...(Object.keys(envelope).length === 0 ? {} : { envelope }) }
214
+ principals.remember(requestId, metadata)
215
+ const admitted = await admitPrompt(ctx, agent, { requestId, text: prompt.text, attachments: prompt.attachments, mode, ...metadata }, signal)
211
216
  if (!react) return
212
217
  if (admitted) reactions.admitted(event.event_id)
213
218
  else await reactions.release([event.event_id])
package/src/inbound.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Turn one incoming Matrix message into a DSH prompt: its text, its media as
3
- * an attachment (pictures as images, voice messages transcribed), and the
4
- * context the sender notice carries (what it replies to).
3
+ * an attachment (pictures as images, voice messages transcribed), and what it
4
+ * replies to as metadata for the message's `source.envelope`.
5
5
  */
6
6
  import { mkdir, writeFile } from 'node:fs/promises'
7
7
  import { extname, join } from 'node:path'
@@ -9,10 +9,6 @@ import { MAX_FILE_BYTES } from './constants.js'
9
9
  import { clip } from './text.js'
10
10
  import { transcribe, transcriptNote } from './voice.js'
11
11
 
12
- /** Longest replied-to text passed to the agent. */
13
- const QUOTE_LIMIT = 2000
14
- /** Longest text of a message sent on someone's behalf passed to the agent. */
15
- const SENT_TEXT_LIMIT = 8000
16
12
  /** Image types the DSH attachment store takes as pictures. */
17
13
  const IMAGE_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/gif'])
18
14
  /** Message types that carry media. */
@@ -46,25 +42,39 @@ export function hasMedia(content) {
46
42
  }
47
43
 
48
44
  /**
49
- * Describe what a message replies to.
45
+ * What a message replies to, as `envelope.replyTo` (the shape dsh-message-context reads).
50
46
  * @param target - the replied-to event, or undefined when it could not be read.
51
- * @param options - `{ botId, sentRecord, names }`: the bot's user id, the send
52
- * record the target belongs to, and names by user id.
53
- * @returns a context block, or undefined.
47
+ * @param options - `{ botId, senderId, sentRecord, names }`: the bot's user id,
48
+ * the replying user's id, the send record the target belongs to, and names by user id.
49
+ * @returns `{ from, sentAt, text, details }` (fields only when known), or undefined.
54
50
  */
55
- export function describeReply(target, { botId, sentRecord, names = {} } = {}) {
51
+ export function replyInfo(target, { botId, senderId, sentRecord, names = {} } = {}) {
56
52
  if (target === undefined) return undefined
57
53
  const content = target.content ?? {}
58
- const text = clip(hasMedia(content) ? `[${content.msgtype.slice(2)} "${content.body ?? ''}"]` : ownText(content), QUOTE_LIMIT)
54
+ const details = []
55
+ let text = hasMedia(content) ? undefined : ownText(content)
56
+ if (hasMedia(content)) details.push(`contains ${content.msgtype.slice(2)} "${content.body ?? ''}"`)
57
+ let from
59
58
  if (target.sender === botId) {
59
+ from = { role: 'assistant' }
60
60
  if (sentRecord !== undefined) {
61
- const by = sentRecord.job ? `job "${sentRecord.job}"` : sentRecord.fromSession ? `session ${sentRecord.fromSession}` : sentRecord.label || 'another sender'
62
- const full = typeof sentRecord.text === 'string' && sentRecord.text.length > 0 ? clip(sentRecord.text, SENT_TEXT_LIMIT) : text
63
- return `[Replying to a message ${by} sent here:]\n${full}`
61
+ details.unshift('posted by the bot on behalf of another sender')
62
+ if (sentRecord.job) from = { kind: 'cron-job', channel: 'cron', id: sentRecord.job, name: sentRecord.job }
63
+ else if (sentRecord.fromSession) from = { kind: 'dsh-session', channel: 'dsh', id: sentRecord.fromSession }
64
+ else if (sentRecord.label) from = { kind: 'external', channel: 'external', id: sentRecord.label, name: sentRecord.label }
65
+ if (typeof sentRecord.text === 'string' && sentRecord.text.length > 0) text = sentRecord.text
64
66
  }
65
- return `[Replying to your earlier message:]\n${text}`
67
+ } else if (target.sender === senderId) {
68
+ from = { role: 'sender' }
69
+ } else {
70
+ from = { kind: 'matrix-user', channel: 'matrix', id: target.sender, ...(names[target.sender] ? { name: names[target.sender] } : {}) }
71
+ }
72
+ return {
73
+ from,
74
+ ...(typeof target.origin_server_ts === 'number' ? { sentAt: target.origin_server_ts } : {}),
75
+ ...(text ? { text } : {}),
76
+ ...(details.length > 0 ? { details } : {}),
66
77
  }
67
- return `[Replying to ${names[target.sender] || target.sender}:]\n${text}`
68
78
  }
69
79
 
70
80
  /** @returns a safe file name for a download. */
package/src/models.js CHANGED
@@ -48,6 +48,24 @@ export async function sessionModelOf(ctx, sessionId) {
48
48
  }
49
49
  }
50
50
 
51
+ /**
52
+ * Switch one session to a model without touching the default for new
53
+ * sessions. The Web picker's `sessionController.selectModel` saves every pick
54
+ * as that default, so a switch in one room would move every room's next
55
+ * session; this takes its other steps instead: the host checks it can route
56
+ * the model (`llm.resolveCallConfig`, which throws with the reason when it
57
+ * cannot), then the live agent records it.
58
+ * @param ctx - Host context.
59
+ * @param agent - the session's live agent.
60
+ * @param selection - provider, model and optional effort.
61
+ */
62
+ export async function selectSessionModel(ctx, agent, selection) {
63
+ const picked = toSelection(selection)
64
+ const llm = ctx.get('llm')
65
+ if (typeof llm?.resolveCallConfig === 'function') await llm.resolveCallConfig({ ...picked })
66
+ agent.model.select(picked)
67
+ }
68
+
51
69
  /**
52
70
  * Read the deployment default model (the one the Web UI saves).
53
71
  * @param ctx - Host context.
package/src/sender.js CHANGED
@@ -11,15 +11,12 @@
11
11
  * known; the other fields depend on the kind. None carries a credential, so
12
12
  * all are safe in a session log.
13
13
  *
14
- * The model learns the sender, when the message was sent, and the context of
15
- * the message (what it replies to, where a forward comes from), from a notice
16
- * message placed right before the prompt, not from lines inside the prompt: DSH titles a session
17
- * from the first words of its first human message, and those must be the
18
- * person's own.
14
+ * When the message was sent and what it replies to go on `source.envelope`,
15
+ * the metadata dsh-message-context renders for the model. The bot never adds
16
+ * them to the text: DSH titles a session from the first words of its first
17
+ * human message, and those must be the person's own.
19
18
  */
20
19
 
21
- import { randomUUID } from 'node:crypto'
22
-
23
20
  /** Remembered prompts waiting for their step; the oldest go first past this. */
24
21
  export const MAX_PENDING_PRINCIPALS = 1024
25
22
 
@@ -30,7 +27,8 @@ function nonEmpty(value) {
30
27
  /**
31
28
  * The Matrix user who wrote a message, and where.
32
29
  * @param userId - their Matrix user id.
33
- * @param where - `{ name, roomId, room }`: their name from the allowlist, the room and its name.
30
+ * @param where - `{ name, roomId, room }`: their name from the allowlist, the room and its name,
31
+ * recorded as `chat` (where the message was sent), the field renderers read.
34
32
  * @returns the principal, or undefined without a sender.
35
33
  */
36
34
  export function matrixUserPrincipal(userId, { name, roomId, room } = {}) {
@@ -40,7 +38,7 @@ export function matrixUserPrincipal(userId, { name, roomId, room } = {}) {
40
38
  channel: 'matrix',
41
39
  id: userId,
42
40
  ...(nonEmpty(name) === undefined ? {} : { name: nonEmpty(name) }),
43
- ...(nonEmpty(roomId) === undefined ? {} : { room: { id: roomId, ...(nonEmpty(room) === undefined ? {} : { name: nonEmpty(room) }) } }),
41
+ ...(nonEmpty(roomId) === undefined ? {} : { chat: { id: roomId, ...(nonEmpty(room) === undefined ? {} : { name: nonEmpty(room) }) } }),
44
42
  }
45
43
  }
46
44
 
@@ -82,47 +80,24 @@ export function withPrincipal(message, principal) {
82
80
  return Object.freeze({ ...message, source: Object.freeze({ ...message.source, principal: deepFreeze(principal) }) })
83
81
  }
84
82
 
85
- /** Source kind of the sender notice before each Matrix prompt. */
86
- export const SENDER_NOTICE_KIND = 'matrix-sender'
87
-
88
83
  /**
89
- * The line that tells the model who wrote a Matrix message and when. A
90
- * message can reach the agent long after it was sent (a queued message, a
91
- * backlog after a restart), so the time is the server's own.
92
- * @param principal - a `matrix-user` principal.
93
- * @param sentAt - when the message was sent, as text.
94
- * @returns a one-line label, or undefined with neither a Matrix sender nor a time.
95
- */
96
- export function senderLabel(principal, sentAt) {
97
- const time = nonEmpty(sentAt) === undefined ? '' : `, sent ${sentAt.trim()}`
98
- if (principal?.kind !== 'matrix-user' || principal.id === undefined) {
99
- return time === '' ? undefined : `[Matrix message${time}]`
100
- }
101
- const name = nonEmpty(principal.name)
102
- return name !== undefined ? `[Matrix message from ${name} (${principal.id})${time}]` : `[Matrix message from ${principal.id}${time}]`
103
- }
104
-
105
- /**
106
- * The notice that comes before a prompt: who sent it, when, and the context
107
- * the bot adds around it. It is its own message with a producer source, so
108
- * DSH's title input and readers of human messages see only what the person
109
- * wrote.
110
- * @param message - a user message entering a step.
111
- * @param details - `{ context, sentAt }`: context blocks for this prompt (see
112
- * `composePrompt`) and when it was sent, as text; both optional.
113
- * @returns the notice, or undefined with no sender, time or context.
84
+ * A frozen copy of a message whose source records its sender and envelope.
85
+ * Fields the message already has are kept.
86
+ * @param message - the user message.
87
+ * @param metadata - `{ principal, envelope }`, each optional.
88
+ * @returns the copy; the message itself when there is nothing to add.
114
89
  */
115
- export function senderNotice(message, { context, sentAt } = {}) {
116
- if (message?.source?.kind !== 'user') return undefined
117
- const label = senderLabel(message.source.principal, sentAt)
118
- const extra = typeof context === 'string' && context.trim().length > 0 ? context : undefined
119
- if (label === undefined && extra === undefined) return undefined
120
- const text = [label, extra].filter((part) => part !== undefined).join('\n')
121
- return deepFreeze({
122
- id: randomUUID(),
123
- role: 'user',
124
- content: [{ type: 'text', text }],
125
- source: { kind: SENDER_NOTICE_KIND, form: 'notice', summary: label ?? text.split('\n')[0] },
90
+ export function withMetadata(message, { principal, envelope } = {}) {
91
+ const addPrincipal = principal !== undefined && message.source.principal === undefined
92
+ const addEnvelope = envelope !== undefined && message.source.envelope === undefined
93
+ if (!addPrincipal && !addEnvelope) return message
94
+ return Object.freeze({
95
+ ...message,
96
+ source: Object.freeze({
97
+ ...message.source,
98
+ ...(addPrincipal ? { principal: deepFreeze(principal) } : {}),
99
+ ...(addEnvelope ? { envelope: deepFreeze(envelope) } : {}),
100
+ }),
126
101
  })
127
102
  }
128
103
 
@@ -138,23 +113,24 @@ function deepFreeze(value) {
138
113
  * Principals for prompts the bot hands to DSH's session controller, which
139
114
  * builds the message itself. The bot remembers the sender by request id
140
115
  * before the hand-over; `preStep`, an `agent/pre-step` listener, records it
141
- * on the message as it enters a step, so it is in the session log with the
142
- * message (DSH lets that hook replace the messages of a step).
116
+ * and the envelope on the message as it enters a step, so they are in the
117
+ * session log with the message (DSH lets that hook replace the messages of a
118
+ * step). It is registered without `prepend`, so a prepended renderer sees them.
143
119
  * @param limit - most principals remembered at once.
144
120
  */
145
121
  export function createPrincipalTagger(limit = MAX_PENDING_PRINCIPALS) {
146
122
  const pending = new Map()
147
123
  return {
148
124
  /**
149
- * Remember the sender, send time and context of the prompt with this
150
- * request id (or, for a message the bot builds itself, this message id).
125
+ * Remember the sender and envelope of the prompt with this request id
126
+ * (or, for a message the bot builds itself, this message id).
151
127
  * @param requestId - the request or message id.
152
- * @param details - `{ principal, context, sentAt }`, each optional.
128
+ * @param metadata - `{ principal, envelope }`, each optional.
153
129
  */
154
- remember(requestId, { principal, context, sentAt } = {}) {
155
- if (typeof requestId !== 'string' || (principal === undefined && context === undefined && sentAt === undefined)) return
130
+ remember(requestId, { principal, envelope } = {}) {
131
+ if (typeof requestId !== 'string' || (principal === undefined && envelope === undefined)) return
156
132
  pending.delete(requestId)
157
- pending.set(requestId, { principal, context, sentAt })
133
+ pending.set(requestId, { principal, envelope })
158
134
  if (pending.size > limit) pending.delete(pending.keys().next().value)
159
135
  },
160
136
  /** Pending prompts, for tests. */
@@ -162,8 +138,8 @@ export function createPrincipalTagger(limit = MAX_PENDING_PRINCIPALS) {
162
138
  return pending.size
163
139
  },
164
140
  /**
165
- * `agent/pre-step` listener: record remembered senders on the step's
166
- * messages and put each prompt's notice (sender, time and context) before it.
141
+ * `agent/pre-step` listener: record remembered senders and envelopes on
142
+ * the step's messages.
167
143
  */
168
144
  async preStep(_payload, next) {
169
145
  const decision = await next()
@@ -176,14 +152,10 @@ export function createPrincipalTagger(limit = MAX_PENDING_PRINCIPALS) {
176
152
  const key = !user ? undefined : (typeof message.source.rpcId === 'string' && pending.has(message.source.rpcId) ? message.source.rpcId : message.id)
177
153
  const entry = typeof key === 'string' ? pending.get(key) : undefined
178
154
  if (entry !== undefined) pending.delete(key)
179
- if (entry?.principal !== undefined && message.source.principal === undefined) {
180
- message = withPrincipal(message, entry.principal)
181
- changed = true
182
- }
183
- const notice = senderNotice(message, entry)
184
- if (notice !== undefined) {
185
- messages.push(notice)
186
- changed = true
155
+ if (entry !== undefined) {
156
+ const tagged = withMetadata(message, entry)
157
+ if (tagged !== message) changed = true
158
+ message = tagged
187
159
  }
188
160
  messages.push(message)
189
161
  }
package/src/sessions.js CHANGED
@@ -182,7 +182,7 @@ export function hasRequest(agent, requestId) {
182
182
  * @param signal - request lifetime.
183
183
  * @returns whether the prompt was handed over (false for a duplicate or an empty one).
184
184
  */
185
- export async function admitPrompt(ctx, agent, { requestId, text, attachments = [], mode, principal }, signal) {
185
+ export async function admitPrompt(ctx, agent, { requestId, text, attachments = [], mode, principal, envelope }, signal) {
186
186
  if (hasRequest(agent, requestId)) return false
187
187
  const content = [...(text.trim().length === 0 ? [] : [{ type: 'text', text }]), ...attachments]
188
188
  if (content.length === 0) return false
@@ -192,7 +192,7 @@ export async function admitPrompt(ctx, agent, { requestId, text, attachments = [
192
192
  await controller.prompt({ sessionId, requestId, mode, content }, signal)
193
193
  return true
194
194
  }
195
- const message = { id: randomUUID(), role: 'user', content, source: { kind: 'user', rpcId: requestId, ...(principal === undefined ? {} : { principal }) } }
195
+ const message = { id: randomUUID(), role: 'user', content, source: { kind: 'user', rpcId: requestId, ...(principal === undefined ? {} : { principal }), ...(envelope === undefined ? {} : { envelope }) } }
196
196
  if (mode === 'steer' && typeof agent.steer === 'function') agent.steer(message)
197
197
  else if (typeof agent.followup === 'function') agent.followup(message)
198
198
  else agent.send(message, mode === 'steer' ? 'next-step' : 'next-turn', true)
package/src/text.js CHANGED
@@ -87,20 +87,6 @@ export function mayBeSilent(text) {
87
87
  return trimmed.length === 0 || SILENT_REPLY.startsWith(trimmed)
88
88
  }
89
89
 
90
- /**
91
- * When a message was sent, for the agent: the date and time in this
92
- * process's time zone, with the zone's name.
93
- * @param timestamp - milliseconds since the epoch.
94
- * @returns the time as text, or undefined without a timestamp.
95
- */
96
- export function formatMoment(timestamp) {
97
- if (!Number.isFinite(timestamp)) return undefined
98
- const zone = Intl.DateTimeFormat().resolvedOptions().timeZone
99
- const parts = new Intl.DateTimeFormat('en-CA', { timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23', weekday: 'short' }).formatToParts(new Date(timestamp))
100
- const part = (type) => parts.find((entry) => entry.type === type)?.value ?? ''
101
- return `${part('weekday')} ${part('year')}-${part('month')}-${part('day')} ${part('hour')}:${part('minute')} (${zone})`
102
- }
103
-
104
90
  /**
105
91
  * Split text into messages no longer than the limit, preferring paragraph,
106
92
  * then line, then word boundaries.