moi-computer 0.1.4 → 0.3.0-next.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.
Files changed (40) hide show
  1. package/README.md +26 -52
  2. package/client/api/workspaces.ts +3 -5
  3. package/client/components/Scratchpad.tsx +169 -9
  4. package/client/components/layout/SidebarLayout.tsx +1 -12
  5. package/client/components/settings/SettingsPages.tsx +8 -60
  6. package/client/components/tool-group/fixtures.ts +60 -66
  7. package/client/hooks/useEnvVars.ts +20 -0
  8. package/client/hooks/useMeiEvents.ts +2 -0
  9. package/dist/chunk-07qf2tv1.css +1 -0
  10. package/dist/chunk-c3zjp9ez.js +672 -0
  11. package/dist/index.html +1 -1
  12. package/lib/scratchpad-skew.ts +64 -0
  13. package/lib/types.ts +5 -7
  14. package/package.json +3 -3
  15. package/server/api.ts +53 -54
  16. package/server/cc-session.ts +1 -1
  17. package/server/cli-colors.ts +6 -3
  18. package/server/cli-env.ts +237 -0
  19. package/server/cli-pc.ts +20 -0
  20. package/server/cli.ts +182 -3
  21. package/server/control.ts +11 -0
  22. package/server/data-dir.ts +9 -0
  23. package/server/env-apply.ts +16 -0
  24. package/server/functions-worker.ts +2 -0
  25. package/server/functions.ts +101 -3
  26. package/server/registry.ts +1 -2
  27. package/server/required-env.ts +19 -0
  28. package/server/scratchpad-assets.ts +223 -0
  29. package/server/scratchpad-executor.ts +88 -23
  30. package/server/scratchpad.ts +110 -20
  31. package/server/status.ts +54 -3
  32. package/server/thread-config.ts +2 -3
  33. package/server/vendor.ts +15 -8
  34. package/server/workspace-env.ts +69 -80
  35. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +5 -3
  36. package/workspace/.claude/skills/moi-workspace/SKILL.md +40 -6
  37. package/dist/chunk-kc6e9nd4.css +0 -1
  38. package/dist/chunk-yf3p7qg7.js +0 -673
  39. /package/client/{CLAUDE.md → AGENTS.md} +0 -0
  40. /package/server/{CLAUDE.md → AGENTS.md} +0 -0
package/server/cli.ts CHANGED
@@ -4,7 +4,7 @@ import { defineCommand, runMain, showUsage } from 'citty'
4
4
  import { existsSync, readFileSync } from 'node:fs'
5
5
  import { tmpdir } from 'node:os'
6
6
  import { join, resolve } from 'path'
7
- import pc from 'picocolors'
7
+ import pc from './cli-pc'
8
8
 
9
9
  import { COLOR_THEMES, FONT_THEMES } from '@/lib/themes'
10
10
  import type { ColorTheme, FontTheme } from '@/lib/themes'
@@ -18,6 +18,13 @@ import type {
18
18
  ScratchStyle
19
19
  } from '@/lib/types'
20
20
 
21
+ import {
22
+ execWithEnv,
23
+ notifyEnvChanged,
24
+ readSecretValue,
25
+ renderEnvView,
26
+ resolveCwdWorkspace
27
+ } from './cli-env'
21
28
  import { columns } from './cli-ui'
22
29
  import { CONTROL_PORT, PORT } from './constants'
23
30
  import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
@@ -32,6 +39,12 @@ import {
32
39
  staleSkillNotice
33
40
  } from './skill-version'
34
41
  import { installBundledSkills } from './skills-template'
42
+ import {
43
+ getWorkspaceEnvView,
44
+ isValidEnvKey,
45
+ secretBackend,
46
+ updateWorkspaceEnv
47
+ } from './workspace-env'
35
48
  import { provisionWorkspace, skillsDirFor } from './workspace-init'
36
49
 
37
50
  // ---- helpers ----------------------------------------------------------------
@@ -665,6 +678,164 @@ const status = defineCommand({
665
678
  }
666
679
  })
667
680
 
681
+ // ---- env subcommands --------------------------------------------------------
682
+
683
+ function envFail(message: string): never {
684
+ console.error('\n' + pc.red('✗') + ' ' + message + '\n')
685
+ process.exit(1)
686
+ }
687
+
688
+ const envSet = defineCommand({
689
+ meta: {
690
+ name: 'set',
691
+ description:
692
+ 'Set custom secrets: `moi env set KEY=value [KEY=value...]`, or `moi env set KEY` to read one value from stdin'
693
+ },
694
+ args: {
695
+ key: {
696
+ type: 'positional',
697
+ required: true,
698
+ description: 'KEY=value pair(s), or a single bare KEY to read the value from stdin'
699
+ }
700
+ },
701
+ async run({ args }) {
702
+ const entry = await resolveCwdWorkspace()
703
+ const pairs = args._
704
+ const set: Record<string, string> = {}
705
+
706
+ if (pairs.length === 1 && !pairs[0].includes('=')) {
707
+ // Bare-KEY form: one key, value from stdin (hidden prompt on a TTY).
708
+ const key = pairs[0]
709
+ if (!isValidEnvKey(key)) envFail(`Invalid env key: ${key}`)
710
+ let value: string
711
+ try {
712
+ value = await readSecretValue(key)
713
+ } catch {
714
+ // Ctrl-C at the hidden prompt.
715
+ process.exit(1)
716
+ }
717
+ // An empty value is almost always an unset variable on the piping side —
718
+ // storing '' would silently shadow a real .env value with nothing.
719
+ if (value === '')
720
+ envFail(`Empty value for ${key} — pipe a non-empty value or pass ${key}=value`)
721
+ set[key] = value
722
+ } else {
723
+ for (const pair of pairs) {
724
+ const eq = pair.indexOf('=')
725
+ if (eq === -1) {
726
+ envFail(
727
+ `Missing value for ${pair} — use KEY=value (bare KEY reads stdin only when set alone)`
728
+ )
729
+ }
730
+ const key = pair.slice(0, eq)
731
+ const value = pair.slice(eq + 1)
732
+ if (!isValidEnvKey(key)) envFail(`Invalid env key: ${key}`)
733
+ if (value === '')
734
+ envFail(`Empty value for ${key} — use \`moi env unset ${key}\` to remove a key`)
735
+ set[key] = value
736
+ }
737
+ }
738
+
739
+ await updateWorkspaceEnv(entry.path, { set })
740
+ await notifyEnvChanged(entry.path)
741
+ for (const key of Object.keys(set)) {
742
+ console.log(pc.green('✓') + ` Set ${pc.bold(key)} ${pc.dim('(custom)')}`)
743
+ }
744
+ // A plaintext fallback should never go unnoticed at write time.
745
+ if ((await secretBackend()) === 'file') {
746
+ console.log(pc.dim(' Stored in a 0600 file — OS keychain unavailable.'))
747
+ }
748
+ process.exit(0)
749
+ }
750
+ })
751
+
752
+ const envUnset = defineCommand({
753
+ meta: { name: 'unset', description: 'Remove custom secrets: `moi env unset KEY [KEY...]`' },
754
+ args: {
755
+ key: { type: 'positional', required: true, description: 'Key(s) to remove' }
756
+ },
757
+ async run({ args }) {
758
+ const entry = await resolveCwdWorkspace()
759
+ const view = await getWorkspaceEnvView(entry.path)
760
+ const byKey = new Map(view.vars.map(v => [v.key, v]))
761
+
762
+ // Only custom secrets are removable; a dotenv-sourced key lives in its file.
763
+ const removable: string[] = []
764
+ let hadError = false
765
+ for (const key of args._) {
766
+ const v = byKey.get(key)
767
+ if (!v) {
768
+ console.warn(pc.yellow('!') + ` ${key} is not set — skipping`)
769
+ continue
770
+ }
771
+ if (v.source === 'dotenv') {
772
+ console.error(
773
+ pc.red('✗') +
774
+ ` ${key} comes from ${(v.files ?? []).join(', ')} — edit that file instead` +
775
+ pc.dim(' (moi env unset only removes custom secrets)')
776
+ )
777
+ hadError = true
778
+ continue
779
+ }
780
+ removable.push(key)
781
+ }
782
+
783
+ if (removable.length > 0) {
784
+ await updateWorkspaceEnv(entry.path, { remove: removable })
785
+ await notifyEnvChanged(entry.path)
786
+ for (const key of removable) {
787
+ const v = byKey.get(key)
788
+ const unshadow =
789
+ v?.source === 'both' ? pc.dim(` (falls back to ${(v.files ?? []).join(', ')})`) : ''
790
+ console.log(pc.green('✓') + ` Removed ${pc.bold(key)}${unshadow}`)
791
+ }
792
+ }
793
+ process.exit(hadError ? 1 : 0)
794
+ }
795
+ })
796
+
797
+ const envExec = defineCommand({
798
+ meta: {
799
+ name: 'exec',
800
+ description: 'Run a command with the workspace env: `moi env exec -- <cmd> [args...]`'
801
+ },
802
+ async run({ rawArgs }) {
803
+ // Everything after `--` is the child command, untouched by flag parsing.
804
+ const sep = rawArgs.indexOf('--')
805
+ const cmd = sep === -1 ? [] : rawArgs.slice(sep + 1)
806
+ if (cmd.length === 0) {
807
+ console.error('\n' + pc.red('✗') + ' Usage: moi env exec -- <cmd> [args...]\n')
808
+ process.exit(1)
809
+ }
810
+ const entry = await resolveCwdWorkspace()
811
+ process.exit(await execWithEnv(entry.path, cmd))
812
+ }
813
+ })
814
+
815
+ const envSubCommands = { set: envSet, unset: envUnset, exec: envExec }
816
+
817
+ const env = defineCommand({
818
+ meta: {
819
+ name: 'env',
820
+ description: 'Show the workspace env (key names only — never values)'
821
+ },
822
+ subCommands: envSubCommands,
823
+ async run({ rawArgs }) {
824
+ // citty invokes the parent run even after dispatching a subcommand — only
825
+ // render the table when no subcommand ran. Object.hasOwn so prototype
826
+ // names ('constructor', 'toString') never count as a dispatched command.
827
+ const first = rawArgs.find(a => !a.startsWith('-'))
828
+ if (first && Object.hasOwn(envSubCommands, first)) return
829
+ const entry = await resolveCwdWorkspace()
830
+ // Lazy: required-env pulls the widget/view bundler chain (TS compiler),
831
+ // which must not load for every other `moi` command's startup.
832
+ const { requiredEnvFor } = await import('./required-env')
833
+ const view = await getWorkspaceEnvView(entry.path, requiredEnvFor(entry.path))
834
+ console.log('\n' + renderEnvView(entry, view) + '\n')
835
+ process.exit(0)
836
+ }
837
+ })
838
+
668
839
  // ---- openclaw subcommands ---------------------------------------------------
669
840
 
670
841
  // Match an `agent` argument against `agentId` (exact) or `name`
@@ -1139,14 +1310,21 @@ const scratchView = defineCommand({
1139
1310
  }
1140
1311
  })
1141
1312
 
1142
- // Image data URL mime → file extension, for naming the saved file.
1313
+ // Image/video data URL mime → file extension, for naming the saved file. Kept in
1314
+ // sync with the server's MIME_EXT (scratchpad-assets.ts) so avif/apng/video assets
1315
+ // round-trip through `read-image` with a real extension instead of `.bin`.
1143
1316
  const IMAGE_EXT: Record<string, string> = {
1144
1317
  'image/png': 'png',
1145
1318
  'image/jpeg': 'jpg',
1146
1319
  'image/jpg': 'jpg',
1147
1320
  'image/webp': 'webp',
1148
1321
  'image/gif': 'gif',
1149
- 'image/svg+xml': 'svg'
1322
+ 'image/svg+xml': 'svg',
1323
+ 'image/avif': 'avif',
1324
+ 'image/apng': 'apng',
1325
+ 'video/mp4': 'mp4',
1326
+ 'video/webm': 'webm',
1327
+ 'video/quicktime': 'mov'
1150
1328
  }
1151
1329
 
1152
1330
  const scratchReadImage = defineCommand({
@@ -1549,6 +1727,7 @@ const main = defineCommand({
1549
1727
  refresh,
1550
1728
  theme,
1551
1729
  config,
1730
+ env,
1552
1731
  status,
1553
1732
  openclaw,
1554
1733
  scratch,
package/server/control.ts CHANGED
@@ -3,6 +3,7 @@ import { resolve } from 'path'
3
3
  import type { WorkspaceEntry } from '@/lib/types'
4
4
 
5
5
  import { CONTROL_PORT } from './constants'
6
+ import { applyEnvChanged } from './env-apply'
6
7
  import { processIcon } from './icon'
7
8
  import { loadLayout, saveLayout } from './layout'
8
9
  import { publishEvent } from './events'
@@ -114,6 +115,16 @@ export const control = Bun.serve({
114
115
  return
115
116
  }
116
117
 
118
+ if (data.type === 'env:changed') {
119
+ // A CLI env write (`moi env set`/`unset`) already landed on disk —
120
+ // reap + broadcast so it takes effect (same path as PUT /env).
121
+ const match = await resolveWorkspace(ws, data.path)
122
+ if (!match) return
123
+ applyEnvChanged(match)
124
+ ws.send(JSON.stringify({ ok: true }))
125
+ return
126
+ }
127
+
117
128
  if (data.type === 'theme') {
118
129
  // Theme is per-workspace — resolve to the real root (subdir-safe).
119
130
  const match = await resolveWorkspace(ws, data.path)
@@ -0,0 +1,9 @@
1
+ // Single source of truth for the OS data dir holding moi's global state
2
+ // (workspaces.json, thread-config.json, workspace-env.json, …).
3
+ //
4
+ // MOI_DATA_DIR overrides it wholesale. This is the isolation seam for CLI
5
+ // e2e tests: env-paths only honors XDG_DATA_HOME on Linux, so on macOS a
6
+ // spawned CLI would otherwise read the developer's real data dir.
7
+ import envPaths from 'env-paths'
8
+
9
+ export const DATA_DIR = process.env.MOI_DATA_DIR || envPaths('moi', { suffix: false }).data
@@ -0,0 +1,16 @@
1
+ // The one place an env change takes effect. Env is frozen at spawn, so after
2
+ // any write — the settings UI's PUT /env or a CLI `moi env set`/`unset`
3
+ // relayed over the control port — the workspace's processes must be reaped and
4
+ // every connected client told to refetch. Both entry points call this so the
5
+ // side effects can never drift apart.
6
+ import { restartWorkspaceSessions } from './cc-session'
7
+ import { publishEvent } from './events'
8
+ import { restartWorker } from './functions'
9
+
10
+ export function applyEnvChanged(workspace: { id: string; path: string }): void {
11
+ // Kill the cached widget worker (next RPC respawns with fresh env) and tear
12
+ // down idle agent sessions (busy ones keep their snapshot until turn end).
13
+ restartWorker(workspace.path)
14
+ restartWorkspaceSessions(workspace.path)
15
+ publishEvent({ type: 'env:updated', workspaceId: workspace.id })
16
+ }
@@ -45,6 +45,8 @@ async function loadModule(name: string): Promise<Record<string, unknown>> {
45
45
 
46
46
  const mod = (await import(filePath + `?t=${file.lastModified}`)) as Record<string, unknown>
47
47
  moduleCache.set(name, mod)
48
+ // Tell the parent what's cached here — introspection only, shown in /status.
49
+ send({ type: 'loaded', module: name })
48
50
  return mod
49
51
  }
50
52
 
@@ -16,6 +16,7 @@
16
16
  // are paths relative to it (`"widgets/hello"` → `.moi/widgets/hello.server.ts`).
17
17
  // This is the contract documented in the widgets SKILL.
18
18
  import { LRUCache } from 'lru-cache'
19
+ import { readFileSync } from 'node:fs'
19
20
  import { tmpdir } from 'node:os'
20
21
  import { join } from 'path'
21
22
 
@@ -38,6 +39,16 @@ type Slot = {
38
39
  readyPromise: Promise<void>
39
40
  pending: Map<string, Pending>
40
41
  killed: boolean
42
+ // Introspection only (surfaced by /status) — not load-bearing.
43
+ ready: boolean
44
+ spawnedAt: number
45
+ lastCallAt: number | null
46
+ calls: number
47
+ errors: number
48
+ timeouts: number
49
+ // Module keys the worker has loaded and cached (reported via 'loaded' IPC,
50
+ // pruned when reloadModules evicts them).
51
+ modules: Set<string>
41
52
  }
42
53
 
43
54
  function rejectAndClearPending(slot: Slot, reason: string) {
@@ -76,7 +87,14 @@ function spawnSlot(workspacePath: string, workspaceEnv: Record<string, string>):
76
87
  worker: undefined as never,
77
88
  readyPromise,
78
89
  pending: new Map(),
79
- killed: false
90
+ killed: false,
91
+ ready: false,
92
+ spawnedAt: Date.now(),
93
+ lastCallAt: null,
94
+ calls: 0,
95
+ errors: 0,
96
+ timeouts: 0,
97
+ modules: new Set()
80
98
  }
81
99
 
82
100
  slot.worker = Bun.spawn([process.execPath, WORKER_PATH], {
@@ -106,13 +124,25 @@ function spawnSlot(workspacePath: string, workspaceEnv: Record<string, string>):
106
124
  if (slots.peek(workspacePath) === slot) slots.delete(workspacePath)
107
125
  },
108
126
  ipc(message) {
109
- const msg = message as { type: string; id?: string; data?: string; message?: string }
127
+ const msg = message as {
128
+ type: string
129
+ id?: string
130
+ data?: string
131
+ message?: string
132
+ module?: string
133
+ }
110
134
 
111
135
  if (msg.type === 'ready') {
136
+ slot.ready = true
112
137
  readyResolve()
113
138
  return
114
139
  }
115
140
 
141
+ if (msg.type === 'loaded' && msg.module) {
142
+ slot.modules.add(msg.module)
143
+ return
144
+ }
145
+
116
146
  if (msg.id) {
117
147
  const p = slot.pending.get(msg.id)
118
148
  if (!p) return
@@ -122,6 +152,7 @@ function spawnSlot(workspacePath: string, workspaceEnv: Record<string, string>):
122
152
  if (msg.type === 'result') {
123
153
  p.resolve(msg.data!)
124
154
  } else if (msg.type === 'error') {
155
+ slot.errors++
125
156
  p.reject(new Error(msg.message ?? 'Unknown error'))
126
157
  }
127
158
  }
@@ -165,14 +196,18 @@ export async function callFunction(
165
196
  // up current .env + custom overrides. Env is fixed at spawn — an already-warm
166
197
  // worker keeps its snapshot until restartWorker() reaps it. Widgets only see
167
198
  // secrets scoped to the 'widgets' sink.
168
- const workspaceEnv = await resolveWorkspaceEnv(workspacePath, 'widgets')
199
+ const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
169
200
  const slot = getOrSpawn(workspacePath, workspaceEnv)
170
201
  await slot.readyPromise
171
202
 
203
+ slot.calls++
204
+ slot.lastCallAt = Date.now()
205
+
172
206
  const id = crypto.randomUUID()
173
207
  return new Promise((resolve, reject) => {
174
208
  const timer = setTimeout(() => {
175
209
  slot.pending.delete(id)
210
+ slot.timeouts++
176
211
  reject(new Error(`Function call timed out: ${module}/${name}`))
177
212
  }, CALL_TIMEOUT_MS)
178
213
 
@@ -206,6 +241,66 @@ export function restartWorker(workspacePath: string) {
206
241
  slots.delete(workspacePath)
207
242
  }
208
243
 
244
+ // Caps surfaced in /status so the numbers there are self-explanatory.
245
+ export const WORKER_LIMITS = {
246
+ maxWorkers: MAX_WORKERS,
247
+ idleTtlMs: WORKER_IDLE_TTL_MS,
248
+ callTimeoutMs: CALL_TIMEOUT_MS
249
+ } as const
250
+
251
+ export type WorkerDebugInfo = {
252
+ workspacePath: string
253
+ pid: number | undefined
254
+ ready: boolean
255
+ spawnedAt: number
256
+ lastCallAt: number | null
257
+ calls: number
258
+ errors: number
259
+ timeouts: number
260
+ pending: number
261
+ // ms until the LRU idle TTL reaps this worker (refreshed on every call)
262
+ ttlRemainingMs: number
263
+ // Resident memory of the worker process; null when /proc isn't available (macOS)
264
+ rssBytes: number | null
265
+ modules: string[]
266
+ }
267
+
268
+ // Best-effort RSS from /proc — Linux only, returns null elsewhere. VmRSS is in
269
+ // kB, so no page-size assumptions. Sync read of a tiny procfs file is cheap.
270
+ function readRss(pid: number | undefined): number | null {
271
+ if (!pid || process.platform !== 'linux') return null
272
+ try {
273
+ const m = readFileSync(`/proc/${pid}/status`, 'utf8').match(/^VmRSS:\s+(\d+)\s+kB/m)
274
+ return m ? Number(m[1]) * 1024 : null
275
+ } catch {
276
+ return null
277
+ }
278
+ }
279
+
280
+ // A snapshot of the live worker pool, for the /status page. Iteration and
281
+ // getRemainingTTL don't refresh LRU recency, so peeking is side-effect free.
282
+ export function getWorkersDebugSnapshot(): WorkerDebugInfo[] {
283
+ const out: WorkerDebugInfo[] = []
284
+ for (const [workspacePath, slot] of slots.entries()) {
285
+ if (slot.killed) continue
286
+ out.push({
287
+ workspacePath,
288
+ pid: slot.worker.pid,
289
+ ready: slot.ready,
290
+ spawnedAt: slot.spawnedAt,
291
+ lastCallAt: slot.lastCallAt,
292
+ calls: slot.calls,
293
+ errors: slot.errors,
294
+ timeouts: slot.timeouts,
295
+ pending: slot.pending.size,
296
+ ttlRemainingMs: slots.getRemainingTTL(workspacePath),
297
+ rssBytes: readRss(slot.worker.pid),
298
+ modules: [...slot.modules].sort()
299
+ })
300
+ }
301
+ return out
302
+ }
303
+
209
304
  export function reloadModules(modules: string[], workspacePath: string) {
210
305
  if (modules.length === 0) return
211
306
  // peek: don't refresh TTL just because files changed. If the worker was
@@ -214,5 +309,8 @@ export function reloadModules(modules: string[], workspacePath: string) {
214
309
  if (!slot || slot.killed) return
215
310
  try {
216
311
  slot.worker.send({ type: 'reload', modules })
312
+ // The worker evicts these from its module cache; it re-reports 'loaded'
313
+ // on the next call, so drop them from the introspection set too.
314
+ for (const m of modules) slot.modules.delete(m)
217
315
  } catch {}
218
316
  }
@@ -1,10 +1,10 @@
1
- import envPaths from 'env-paths'
2
1
  import { mkdir } from 'node:fs/promises'
3
2
  import { homedir } from 'node:os'
4
3
  import { join, resolve, sep } from 'path'
5
4
 
6
5
  import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
7
6
 
7
+ import { DATA_DIR } from './data-dir'
8
8
  import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
9
9
 
10
10
  // Replace the home-dir prefix with `~` for display. Keeps the original
@@ -22,7 +22,6 @@ function withDisplayPath<T extends { path: string }>(entry: T): T & { displayPat
22
22
  return { ...entry, displayPath: tildify(entry.path) }
23
23
  }
24
24
 
25
- const DATA_DIR = envPaths('moi', { suffix: false }).data
26
25
  export const DEFAULT_REGISTRY_PATH = join(DATA_DIR, 'workspaces.json')
27
26
 
28
27
  // Overridable for tests
@@ -0,0 +1,19 @@
1
+ // The env "required" view aggregates `config.requiredEnv` declared by both
2
+ // widgets and views, each key mapped to the bundle ids that asked for it.
3
+ // Shared by the env API (api.ts) and the `moi env` CLI (cli-env.ts).
4
+ import { collectViewRequiredEnv } from './views'
5
+ import { collectRequiredEnv } from './widgets'
6
+
7
+ export async function requiredEnvFor(workspacePath: string): Promise<Record<string, string[]>> {
8
+ const [widgets, views] = await Promise.all([
9
+ collectRequiredEnv(workspacePath),
10
+ collectViewRequiredEnv(workspacePath)
11
+ ])
12
+ const out: Record<string, string[]> = {}
13
+ for (const map of [widgets, views]) {
14
+ for (const [key, ids] of Object.entries(map)) {
15
+ out[key] = [...(out[key] ?? []), ...ids]
16
+ }
17
+ }
18
+ return out
19
+ }