@sixb/app 0.2.5 → 0.2.6

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 (111) hide show
  1. package/dist/agent/components/agent-threads.d.ts.map +1 -1
  2. package/dist/agent/components/composer-place.d.ts.map +1 -1
  3. package/dist/agent/components/computer-place.d.ts +24 -6
  4. package/dist/agent/components/computer-place.d.ts.map +1 -1
  5. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  6. package/dist/agent/components/message-view.d.ts +13 -3
  7. package/dist/agent/components/message-view.d.ts.map +1 -1
  8. package/dist/agent/components/pending-messages.d.ts.map +1 -1
  9. package/dist/agent/components/transcript.d.ts +13 -0
  10. package/dist/agent/components/transcript.d.ts.map +1 -1
  11. package/dist/agent/conversation.d.ts +4 -0
  12. package/dist/agent/conversation.d.ts.map +1 -1
  13. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  14. package/dist/agent/format.d.ts +7 -0
  15. package/dist/agent/format.d.ts.map +1 -1
  16. package/dist/agent/hooks/thread-queries.d.ts +1548 -0
  17. package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
  18. package/dist/agent/hooks/use-agent-conversation.d.ts +41 -2
  19. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  20. package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
  21. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  22. package/dist/agent/hooks/use-thread-place.d.ts +49 -0
  23. package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
  24. package/dist/agent/i18n/en.d.ts +39 -6
  25. package/dist/agent/i18n/en.d.ts.map +1 -1
  26. package/dist/agent/i18n/fr.d.ts.map +1 -1
  27. package/dist/agent/i18n/index.d.ts +66 -12
  28. package/dist/agent/i18n/index.d.ts.map +1 -1
  29. package/dist/agent/live-run.d.ts.map +1 -1
  30. package/dist/agent/model-selection.d.ts +3 -2
  31. package/dist/agent/model-selection.d.ts.map +1 -1
  32. package/dist/agent/moves.d.ts +40 -0
  33. package/dist/agent/moves.d.ts.map +1 -0
  34. package/dist/agent/thread-reader-state.d.ts +30 -0
  35. package/dist/agent/thread-reader-state.d.ts.map +1 -0
  36. package/dist/agent/types.d.ts +4 -0
  37. package/dist/agent/types.d.ts.map +1 -1
  38. package/dist/artifacts/live/session.d.ts.map +1 -1
  39. package/dist/artifacts/queries.d.ts.map +1 -1
  40. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -1
  41. package/dist/{chunk-5sgac68y.js → chunk-096d52h2.js} +1 -1
  42. package/dist/{chunk-4wm09prf.js → chunk-94d7enwc.js} +1 -1
  43. package/dist/{chunk-69qgh20f.js → chunk-ezntd3yy.js} +1 -1
  44. package/dist/{chunk-4fex83k2.js → chunk-qjw5r2vk.js} +2233 -732
  45. package/dist/{chunk-4fex83k2.js.map → chunk-qjw5r2vk.js.map} +28 -25
  46. package/dist/createCustomApp.d.ts +8 -1
  47. package/dist/createCustomApp.d.ts.map +1 -1
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +4 -2
  51. package/dist/index.js.map +3 -3
  52. package/dist/pages/console/data/accounts.d.ts +94 -0
  53. package/dist/pages/console/data/accounts.d.ts.map +1 -0
  54. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  55. package/dist/pages/console/data/live-updates.d.ts.map +1 -1
  56. package/dist/pages/console/data/messages.d.ts +46 -0
  57. package/dist/pages/console/data/messages.d.ts.map +1 -1
  58. package/dist/pages/console/data/sync-button.d.ts.map +1 -1
  59. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  60. package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
  61. package/dist/pages/settings/usage/page.d.ts +4 -1
  62. package/dist/pages/settings/usage/page.d.ts.map +1 -1
  63. package/dist/pages/settings/usage/spend-model.d.ts +43 -19
  64. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  65. package/dist/pages.js +23086 -22619
  66. package/dist/pages.js.map +13 -12
  67. package/dist/server.d.ts +1 -1
  68. package/dist/server.d.ts.map +1 -1
  69. package/dist/server.js +40 -3
  70. package/dist/server.js.map +3 -3
  71. package/package.json +3 -3
  72. package/src/agent/agent-chat.tsx +2 -2
  73. package/src/agent/components/agent-threads.tsx +42 -2
  74. package/src/agent/components/composer-place.tsx +2 -7
  75. package/src/agent/components/computer-place.tsx +415 -70
  76. package/src/agent/components/conversation-panel.tsx +31 -26
  77. package/src/agent/components/message-view.tsx +418 -9
  78. package/src/agent/components/pending-messages.tsx +5 -1
  79. package/src/agent/components/transcript.tsx +136 -5
  80. package/src/agent/conversation.ts +16 -1
  81. package/src/agent/format.ts +52 -0
  82. package/src/agent/hooks/thread-queries.ts +75 -0
  83. package/src/agent/hooks/use-agent-conversation.ts +454 -112
  84. package/src/agent/hooks/use-thread-lists.ts +72 -7
  85. package/src/agent/hooks/use-thread-place.ts +239 -0
  86. package/src/agent/i18n/en.ts +63 -16
  87. package/src/agent/i18n/fr.ts +65 -19
  88. package/src/agent/live-run.ts +38 -0
  89. package/src/agent/model-selection.ts +3 -2
  90. package/src/agent/moves.ts +174 -0
  91. package/src/agent/thread-reader-state.ts +75 -0
  92. package/src/agent/types.ts +6 -0
  93. package/src/artifacts/live/session.ts +5 -0
  94. package/src/createCustomApp.ts +57 -3
  95. package/src/index.ts +4 -0
  96. package/src/pages/console/data/accounts.tsx +509 -0
  97. package/src/pages/console/data/connectors.tsx +7 -15
  98. package/src/pages/console/data/live-updates.ts +2 -0
  99. package/src/pages/console/data/messages.ts +73 -0
  100. package/src/pages/console/data/sync-button.tsx +56 -16
  101. package/src/pages/console/data/syncs.tsx +66 -41
  102. package/src/pages/section-ui.tsx +1 -1
  103. package/src/pages/settings/usage/breakdown.tsx +5 -2
  104. package/src/pages/settings/usage/filter-menu.tsx +1 -1
  105. package/src/pages/settings/usage/page.tsx +32 -13
  106. package/src/pages/settings/usage/spend-chart.tsx +2 -2
  107. package/src/pages/settings/usage/spend-model.ts +118 -50
  108. package/src/server.ts +1 -0
  109. /package/dist/{chunk-5sgac68y.js.map → chunk-096d52h2.js.map} +0 -0
  110. /package/dist/{chunk-4wm09prf.js.map → chunk-94d7enwc.js.map} +0 -0
  111. /package/dist/{chunk-69qgh20f.js.map → chunk-ezntd3yy.js.map} +0 -0
@@ -0,0 +1,509 @@
1
+ import type { ListConnectorAccountsResponse, ListSyncsResponse } from "@sixb/client"
2
+ import {
3
+ listConnectorAccountsOptions,
4
+ listConnectorAccountsQueryKey,
5
+ listSyncRunsQueryKey,
6
+ listSyncsQueryKey,
7
+ requestSyncRunMutation,
8
+ } from "@sixb/client/hooks"
9
+ import { Button, Input } from "@sixb/ui/components"
10
+ import { cn } from "@sixb/ui/lib/utils"
11
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
12
+ import { Building2, RefreshCw, Search, Users } from "lucide-react"
13
+ import { Fragment, useState } from "react"
14
+ import { Link } from "react-router-dom"
15
+ import {
16
+ apiErrorMessage,
17
+ FailureSummary,
18
+ humanize,
19
+ IconTile,
20
+ MetaDot,
21
+ PageSection,
22
+ Panel,
23
+ PanelEmpty,
24
+ PanelRow,
25
+ PanelSkeleton,
26
+ Pill,
27
+ RunStatusPill,
28
+ useFormat,
29
+ useNumbers,
30
+ useRunStatusLabels,
31
+ } from "../../section-ui"
32
+ import { PersonAvatar } from "../../settings/controls"
33
+ import { TrailingSkeleton } from "../skeletons"
34
+ import { useDataMessages } from "./messages"
35
+
36
+ type ConnectorAccount = ListConnectorAccountsResponse["accounts"][number]
37
+ type AccountRun = ConnectorAccount["latestRuns"][number]
38
+ type Sync = ListSyncsResponse[number]
39
+ type AccountsSummary = NonNullable<Sync["accounts"]>
40
+
41
+ /** How many accounts show before "Show all". Problems sort first, so they always show. */
42
+ const SHOWN_ACCOUNTS = 8
43
+ /** Past this many accounts, the panel offers a search. */
44
+ const SEARCHABLE_ACCOUNTS = 20
45
+
46
+ export function isActiveRun(status: AccountRun["status"] | undefined): boolean {
47
+ return status === "queued" || status === "running"
48
+ }
49
+
50
+ export function needsReconnecting(run: AccountRun | null | undefined): boolean {
51
+ return run?.status === "failed" && run.error?.code === "connector.authorization_required"
52
+ }
53
+
54
+ /** The connector's accounts, kept fresh while one of their runs is under way. */
55
+ export function useConnectorAccounts(connectorId: string, enabled = true) {
56
+ return useQuery({
57
+ ...listConnectorAccountsOptions({ path: { connectorId } }),
58
+ enabled,
59
+ retry: false,
60
+ refetchInterval: (query) =>
61
+ query.state.data?.accounts.some(({ latestRuns }) =>
62
+ latestRuns.some((run) => isActiveRun(run.status))
63
+ )
64
+ ? 5000
65
+ : false,
66
+ })
67
+ }
68
+
69
+ type AccountState = "reconnect" | "failed" | "running" | "never" | "synced"
70
+
71
+ const stateOrder: Record<AccountState, number> = {
72
+ reconnect: 0,
73
+ failed: 1,
74
+ running: 2,
75
+ never: 3,
76
+ synced: 4,
77
+ }
78
+
79
+ /** One state for an account across its syncs: what most needs someone's attention. */
80
+ function accountState(account: ConnectorAccount): AccountState {
81
+ const runs = account.latestRuns
82
+ if (runs.some(needsReconnecting)) return "reconnect"
83
+ if (runs.some((run) => run.status === "failed")) return "failed"
84
+ if (runs.some((run) => isActiveRun(run.status))) return "running"
85
+ return runs.length === 0 ? "never" : "synced"
86
+ }
87
+
88
+ /**
89
+ * A sync of an OAuth connector as one state, from the accounts you see. Its latest run only says
90
+ * how the account that ran last went.
91
+ */
92
+ type SyncAccountsState = "running" | "attention" | "synced" | "never" | "empty"
93
+
94
+ function syncAccountsState(summary: AccountsSummary): SyncAccountsState {
95
+ if (summary.running > 0) return "running"
96
+ if (summary.needsReconnecting + summary.failing > 0) return "attention"
97
+ if (summary.synced > 0) return "synced"
98
+
99
+ return summary.total === 0 ? "empty" : "never"
100
+ }
101
+
102
+ /** The pill of a sync of an OAuth connector, on its row and its page. */
103
+ function AccountsStatusPill({ summary }: { readonly summary: AccountsSummary }) {
104
+ const messages = useDataMessages()
105
+
106
+ switch (syncAccountsState(summary)) {
107
+ case "running":
108
+ return <RunStatusPill status="running" />
109
+ case "attention":
110
+ return (
111
+ <Pill tone={summary.failing > 0 ? "error" : "warn"}>{messages.syncs.needsAttention}</Pill>
112
+ )
113
+ case "synced":
114
+ return <RunStatusPill status="succeeded" />
115
+ case "empty":
116
+ return <Pill tone="muted">{messages.syncs.noAccounts}</Pill>
117
+ case "never":
118
+ return <Pill tone="muted">{messages.common.neverRun}</Pill>
119
+ }
120
+ }
121
+
122
+ /**
123
+ * How a sync stands: its latest run, or on a sync of an OAuth connector, its accounts. There, the
124
+ * latest run is only the account that ran last.
125
+ */
126
+ export function SyncStatusPill({ sync }: { readonly sync: Sync }) {
127
+ const messages = useDataMessages()
128
+ if (sync.accounts) return <AccountsStatusPill summary={sync.accounts} />
129
+
130
+ return sync.latestRun ? (
131
+ <RunStatusPill status={sync.latestRun.status} />
132
+ ) : (
133
+ <Pill tone="muted">{messages.common.neverRun}</Pill>
134
+ )
135
+ }
136
+
137
+ /** On a sync's row: when it last ran, or on a sync of an OAuth connector, when an account synced. */
138
+ export function SyncTimeMeta({ sync }: { readonly sync: Sync }) {
139
+ const format = useFormat()
140
+ const at = sync.accounts
141
+ ? sync.accounts.lastSyncedAt
142
+ : (sync.latestRun?.startedAt ?? sync.latestRun?.queuedAt)
143
+ if (!at) return null
144
+
145
+ return (
146
+ <>
147
+ <MetaDot />
148
+ <span>{format.relative(at)}</span>
149
+ </>
150
+ )
151
+ }
152
+
153
+ /**
154
+ * A sync of an OAuth connector's figures: its accounts, rather than the run that ended last. Null
155
+ * for a sync of any other connector.
156
+ */
157
+ export function useAccountsStats(summary: AccountsSummary | undefined) {
158
+ const messages = useDataMessages().syncs
159
+ const numbers = useNumbers()
160
+ const format = useFormat()
161
+ if (!summary) return null
162
+
163
+ const attention = summary.needsReconnecting + summary.failing
164
+
165
+ return [
166
+ { label: messages.accountsStat, value: numbers.count(summary.total) },
167
+ { label: messages.syncedStat, value: numbers.count(summary.synced) },
168
+ {
169
+ label: messages.attentionStat,
170
+ value: (
171
+ <span
172
+ className={cn(
173
+ summary.failing > 0
174
+ ? "text-red-600 dark:text-red-400"
175
+ : attention > 0 && "text-amber-700 dark:text-amber-400"
176
+ )}
177
+ >
178
+ {numbers.count(attention)}
179
+ </span>
180
+ ),
181
+ },
182
+ {
183
+ label: messages.lastSynced,
184
+ value: summary.lastSyncedAt ? format.relative(summary.lastSyncedAt) : "—",
185
+ },
186
+ ]
187
+ }
188
+
189
+ /** On a sync's row or page: how many accounts it runs for, and how many are not syncing. */
190
+ export function AccountsMeta({
191
+ summary,
192
+ href,
193
+ }: {
194
+ readonly summary: NonNullable<Sync["accounts"]>
195
+ /** The connector's accounts, when the count should lead there. */
196
+ readonly href?: string
197
+ }) {
198
+ const messages = useDataMessages().syncs
199
+ const numbers = useNumbers()
200
+ const count = (
201
+ <span className="inline-flex items-center gap-1">
202
+ <Users aria-hidden className="size-3.5" />
203
+ {messages.accounts(summary.total, numbers.count(summary.total))}
204
+ </span>
205
+ )
206
+ return (
207
+ <>
208
+ <MetaDot />
209
+ {href ? (
210
+ <Link to={href} className="hover:text-foreground hover:underline">
211
+ {count}
212
+ </Link>
213
+ ) : (
214
+ count
215
+ )}
216
+ {summary.needsReconnecting > 0 ? (
217
+ <>
218
+ <MetaDot />
219
+ <span className="text-amber-700 dark:text-amber-400">
220
+ {messages.needReconnecting(summary.needsReconnecting)}
221
+ </span>
222
+ </>
223
+ ) : null}
224
+ {summary.failing > 0 ? (
225
+ <>
226
+ <MetaDot />
227
+ <span className="text-red-600 dark:text-red-400">
228
+ {messages.failingAccounts(summary.failing)}
229
+ </span>
230
+ </>
231
+ ) : null}
232
+ </>
233
+ )
234
+ }
235
+
236
+ /** An OAuth connector's connected accounts, the ones that need attention first. */
237
+ export function ConnectorAccountsSection({
238
+ connectorId,
239
+ syncs,
240
+ }: {
241
+ readonly connectorId: string
242
+ /** The connector's syncs the viewer may run. */
243
+ readonly syncs: readonly Sync[]
244
+ }) {
245
+ const messages = useDataMessages()
246
+ const numbers = useNumbers()
247
+ const query = useConnectorAccounts(connectorId)
248
+ const [showAll, setShowAll] = useState(false)
249
+ const [search, setSearch] = useState("")
250
+
251
+ const accounts = [...(query.data?.accounts ?? [])].sort(
252
+ (left, right) =>
253
+ stateOrder[accountState(left)] - stateOrder[accountState(right)] ||
254
+ left.connection.account.label.localeCompare(right.connection.account.label)
255
+ )
256
+ const needle = search.trim().toLowerCase()
257
+ const matching = needle
258
+ ? accounts.filter(({ connection }) => connection.account.label.toLowerCase().includes(needle))
259
+ : accounts
260
+ const shown = showAll || needle ? matching : matching.slice(0, SHOWN_ACCOUNTS)
261
+
262
+ return (
263
+ <PageSection
264
+ title={messages.connectors.accountsTitle}
265
+ description={messages.connectors.accountsDescription}
266
+ action={
267
+ accounts.length > SEARCHABLE_ACCOUNTS ? (
268
+ <div className="relative w-56">
269
+ <Search className="pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground" />
270
+ <Input
271
+ type="search"
272
+ value={search}
273
+ onChange={(event) => setSearch(event.target.value)}
274
+ placeholder={messages.connectors.searchAccounts}
275
+ aria-label={messages.connectors.searchAccounts}
276
+ className="h-8 pl-8 text-xs"
277
+ />
278
+ </div>
279
+ ) : null
280
+ }
281
+ >
282
+ <Panel>
283
+ {query.isPending ? (
284
+ <PanelSkeleton rows={2} leading="avatar" trailing={<TrailingSkeleton />} />
285
+ ) : query.isError ? (
286
+ <PanelEmpty
287
+ tone="error"
288
+ icon={Users}
289
+ title={messages.connectors.accountsTitle}
290
+ description={apiErrorMessage(query.error, messages.common.loadFailed)}
291
+ />
292
+ ) : accounts.length === 0 ? (
293
+ <PanelEmpty icon={Users} title={messages.connectors.noAccountsTitle} />
294
+ ) : matching.length === 0 ? (
295
+ <PanelEmpty icon={Search} title={messages.connectors.noMatchingAccounts} />
296
+ ) : (
297
+ <>
298
+ {shown.map((account) => (
299
+ <AccountRow
300
+ key={account.connection.id}
301
+ connectorId={connectorId}
302
+ account={account}
303
+ syncs={syncs}
304
+ />
305
+ ))}
306
+ {shown.length < matching.length ? (
307
+ <button
308
+ type="button"
309
+ onClick={() => setShowAll(true)}
310
+ className="w-full px-4 py-3 text-left text-[0.8125rem] text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground"
311
+ >
312
+ {messages.connectors.showAllAccounts(numbers.count(matching.length))}
313
+ </button>
314
+ ) : null}
315
+ </>
316
+ )}
317
+ </Panel>
318
+ </PageSection>
319
+ )
320
+ }
321
+
322
+ function AccountRow({
323
+ connectorId,
324
+ account,
325
+ syncs,
326
+ }: {
327
+ readonly connectorId: string
328
+ readonly account: ConnectorAccount
329
+ readonly syncs: readonly Sync[]
330
+ }) {
331
+ const messages = useDataMessages()
332
+ const format = useFormat()
333
+ const numbers = useNumbers()
334
+ const { connection, latestRuns } = account
335
+ const label = connection.account.label
336
+ const isProject = connection.owner.type === "project"
337
+ const state = accountState(account)
338
+ const failure = latestRuns.find((run) => run.status === "failed" && !needsReconnecting(run))
339
+ const when = (run: AccountRun) => format.relative(run.finishedAt ?? run.startedAt ?? run.queuedAt)
340
+ const [onlyRun] = latestRuns
341
+
342
+ return (
343
+ <PanelRow
344
+ leading={isProject ? <IconTile icon={Building2} /> : <PersonAvatar email={label} />}
345
+ // A narrow screen wraps the address rather than cut it: it says whose account this is.
346
+ title={<span className="min-w-0 wrap-anywhere sm:truncate">{label}</span>}
347
+ meta={
348
+ <>
349
+ <NarrowAccountState state={state} />
350
+ {isProject ? (
351
+ <>
352
+ <span>{messages.syncs.project}</span>
353
+ <MetaDot />
354
+ </>
355
+ ) : null}
356
+ {connection.slot !== "default" ? (
357
+ <>
358
+ <span>{messages.syncs.slot(connection.slot)}</span>
359
+ <MetaDot />
360
+ </>
361
+ ) : null}
362
+ {latestRuns.length === 0 ? (
363
+ <span>{messages.syncs.notSyncedYet}</span>
364
+ ) : syncs.length <= 1 && onlyRun ? (
365
+ // One sync: when it last ran, and what it read.
366
+ <>
367
+ <span>{when(onlyRun)}</span>
368
+ {onlyRun.rowsRead !== undefined ? (
369
+ <>
370
+ <MetaDot />
371
+ <span className="tabular-nums">
372
+ {messages.common.rows(onlyRun.rowsRead, numbers.count(onlyRun.rowsRead))}
373
+ </span>
374
+ </>
375
+ ) : null}
376
+ </>
377
+ ) : (
378
+ // Several syncs: each one's last run, by name. Stacked on a narrow screen.
379
+ <span className="flex min-w-0 flex-col sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1.5">
380
+ {latestRuns.map((run, index) => (
381
+ <Fragment key={run.syncId}>
382
+ {index > 0 ? (
383
+ <span className="hidden sm:inline">
384
+ <MetaDot />
385
+ </span>
386
+ ) : null}
387
+ <span
388
+ className={cn(
389
+ "truncate",
390
+ needsReconnecting(run)
391
+ ? "text-amber-700 dark:text-amber-400"
392
+ : run.status === "failed" && "text-red-600 dark:text-red-400"
393
+ )}
394
+ >
395
+ {humanize(run.syncId)} {when(run)}
396
+ </span>
397
+ </Fragment>
398
+ ))}
399
+ </span>
400
+ )}
401
+ </>
402
+ }
403
+ trailing={
404
+ <>
405
+ <AccountSyncButton connectorId={connectorId} account={account} syncs={syncs} />
406
+ <span className="hidden sm:inline-flex">
407
+ {state === "never" ? (
408
+ <Pill tone="muted">{messages.syncs.notSyncedYet}</Pill>
409
+ ) : state === "reconnect" ? (
410
+ <Pill tone="warn">{messages.syncs.needsReconnecting}</Pill>
411
+ ) : (
412
+ <RunStatusPill
413
+ status={
414
+ state === "failed" ? "failed" : state === "running" ? "running" : "succeeded"
415
+ }
416
+ />
417
+ )}
418
+ </span>
419
+ </>
420
+ }
421
+ >
422
+ {failure?.error ? <FailureSummary failure={failure.error} compact /> : null}
423
+ </PanelRow>
424
+ )
425
+ }
426
+
427
+ const narrowStates = {
428
+ reconnect: { dot: "bg-amber-500", text: "text-amber-700 dark:text-amber-400" },
429
+ failed: { dot: "bg-red-500", text: "text-red-600 dark:text-red-400" },
430
+ running: { dot: "bg-sky-500", text: "text-foreground/75" },
431
+ } as const
432
+
433
+ /**
434
+ * On a narrow screen, an account's state gets its own line under the address instead of taking
435
+ * the row's right side, which leaves the address room. A synced account says nothing, and one
436
+ * never synced says so already.
437
+ */
438
+ function NarrowAccountState({ state }: { readonly state: AccountState }) {
439
+ const messages = useDataMessages().syncs
440
+ const statusLabels = useRunStatusLabels()
441
+ if (state !== "reconnect" && state !== "failed" && state !== "running") return null
442
+
443
+ const tone = narrowStates[state]
444
+ const label = state === "reconnect" ? messages.needsReconnecting : statusLabels[state]
445
+
446
+ return (
447
+ <span className={cn("flex w-full items-center gap-1.5 font-medium sm:hidden", tone.text)}>
448
+ <span aria-hidden className={cn("size-1.5 rounded-full", tone.dot)} />
449
+ {label}
450
+ </span>
451
+ )
452
+ }
453
+
454
+ /** Runs every sync of one account now. Shown on hover, and always on touch screens. */
455
+ function AccountSyncButton({
456
+ connectorId,
457
+ account,
458
+ syncs,
459
+ }: {
460
+ readonly connectorId: string
461
+ readonly account: ConnectorAccount
462
+ readonly syncs: readonly Sync[]
463
+ }) {
464
+ const messages = useDataMessages().syncs
465
+ const queryClient = useQueryClient()
466
+ const label = account.connection.account.label
467
+ const request = useMutation({
468
+ ...requestSyncRunMutation(),
469
+ onSuccess: () =>
470
+ Promise.all([
471
+ queryClient.invalidateQueries({
472
+ queryKey: listConnectorAccountsQueryKey({ path: { connectorId } }),
473
+ }),
474
+ queryClient.invalidateQueries({ queryKey: listSyncsQueryKey() }),
475
+ queryClient.invalidateQueries({ queryKey: listSyncRunsQueryKey() }),
476
+ ]),
477
+ })
478
+ const working = request.isPending || account.latestRuns.some((run) => isActiveRun(run.status))
479
+ if (syncs.length === 0) return null
480
+
481
+ return (
482
+ <Button
483
+ type="button"
484
+ variant="ghost"
485
+ size="icon-sm"
486
+ aria-label={messages.syncAccount(label)}
487
+ title={messages.syncAccount(label)}
488
+ disabled={working}
489
+ onClick={async () => {
490
+ // One sync refusing, such as one this person may not run, leaves the others to run.
491
+ for (const sync of syncs) {
492
+ await request
493
+ .mutateAsync({
494
+ path: { syncId: sync.id },
495
+ body: { connectionId: account.connection.id },
496
+ })
497
+ .catch(() => undefined)
498
+ }
499
+ }}
500
+ className={cn(
501
+ "text-muted-foreground transition-opacity",
502
+ !working &&
503
+ "focus-visible:opacity-100 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover:opacity-100"
504
+ )}
505
+ >
506
+ <RefreshCw className={cn(working && "animate-spin")} />
507
+ </Button>
508
+ )
509
+ }
@@ -30,6 +30,7 @@ import {
30
30
  useNumbers,
31
31
  } from "../../section-ui"
32
32
  import { MetaSkeleton, SkeletonBlock, TrailingSkeleton } from "../skeletons"
33
+ import { ConnectorAccountsSection, SyncStatusPill, SyncTimeMeta } from "./accounts"
33
34
  import { useDataMessages } from "./messages"
34
35
  import { ConnectorIcon } from "./shared"
35
36
 
@@ -196,29 +197,20 @@ export function ConsoleConnectorPage() {
196
197
  meta={
197
198
  <>
198
199
  <span>{messages.common.writes(sync.target.dataset.id)}</span>
199
- {sync.latestRun ? (
200
- <>
201
- <MetaDot />
202
- <span>
203
- {format.relative(sync.latestRun.startedAt ?? sync.latestRun.queuedAt)}
204
- </span>
205
- </>
206
- ) : null}
200
+ <SyncTimeMeta sync={sync} />
207
201
  </>
208
202
  }
209
- trailing={
210
- sync.latestRun ? (
211
- <RunStatusPill status={sync.latestRun.status} />
212
- ) : (
213
- <Pill tone="muted">{messages.common.neverRun}</Pill>
214
- )
215
- }
203
+ trailing={<SyncStatusPill sync={sync} />}
216
204
  />
217
205
  ))
218
206
  )}
219
207
  </Panel>
220
208
  </PageSection>
221
209
 
210
+ {connector.connection && syncs.length > 0 ? (
211
+ <ConnectorAccountsSection connectorId={connector.id} syncs={syncs} />
212
+ ) : null}
213
+
222
214
  {webhooks.length > 0 ? (
223
215
  <>
224
216
  <PageSection
@@ -27,6 +27,8 @@ export function useSyncLiveUpdates(options: { syncId?: string } = {}) {
27
27
  key("listSyncs"),
28
28
  key("listSyncRuns"),
29
29
  key("getSync", { syncId: event.payload.syncId }),
30
+ // Which connector a sync reads isn't in its events: refresh every connector's accounts.
31
+ key("listConnectorAccounts"),
30
32
  ]
31
33
  if ("datasetId" in event.payload && event.payload.datasetId) {
32
34
  keys.push(...datasetChangedKeys(event.payload.datasetId))
@@ -41,6 +41,17 @@ export const en = {
41
41
  synced: (when: string) => `Synced ${when}`,
42
42
  failed: "Last sync failed",
43
43
  never: "Never synced",
44
+ noAccounts: "No account connected",
45
+ accountsNeedReconnecting: (count: number) =>
46
+ plural("en", count, {
47
+ one: "An account needs reconnecting",
48
+ other: `${count} accounts need reconnecting`,
49
+ }),
50
+ accountsFailed: (count: number) =>
51
+ plural("en", count, {
52
+ one: "An account failed to sync",
53
+ other: `${count} accounts failed to sync`,
54
+ }),
44
55
  requestFailed: "The sync could not be started.",
45
56
  },
46
57
  connectors: {
@@ -52,6 +63,12 @@ export const en = {
52
63
  webhookCount: (count: number) =>
53
64
  plural("en", count, { one: "1 webhook", other: `${count} webhooks` }),
54
65
  oauth: "Connects with OAuth",
66
+ accountsTitle: "Accounts",
67
+ accountsDescription: "Each connected account, and how its syncs last ran.",
68
+ noAccountsTitle: "No accounts connected",
69
+ searchAccounts: "Search accounts",
70
+ noMatchingAccounts: "No accounts match",
71
+ showAllAccounts: (count: string) => `Show all ${count} accounts`,
55
72
  syncsTitle: "Syncs",
56
73
  syncsDescription: "What this connector copies into the project.",
57
74
  noSyncsTitle: "No syncs",
@@ -80,6 +97,25 @@ export const en = {
80
97
  connector: "Connector",
81
98
  dataset: "Dataset",
82
99
  runWhat: "Sync runs",
100
+ accounts: (count: number, formatted: string) =>
101
+ plural("en", count, { one: `${formatted} account`, other: `${formatted} accounts` }),
102
+ needReconnecting: (count: number) =>
103
+ plural("en", count, {
104
+ one: "1 needs reconnecting",
105
+ other: `${count} need reconnecting`,
106
+ }),
107
+ failingAccounts: (count: number) => `${count} failing`,
108
+ project: "Project",
109
+ slot: (slot: string) => `Slot ${slot}`,
110
+ notSyncedYet: "Not synced yet",
111
+ needsReconnecting: "Needs reconnecting",
112
+ syncAccount: (account: string) => `Sync ${account}`,
113
+ needsAttention: "Needs attention",
114
+ noAccounts: "No accounts",
115
+ accountsStat: "Accounts",
116
+ syncedStat: "Synced",
117
+ attentionStat: "Need attention",
118
+ lastSynced: "Last synced",
83
119
  },
84
120
  datasets: {
85
121
  title: "Datasets",
@@ -283,6 +319,17 @@ export const fr: Translation<DataMessages> = {
283
319
  synced: (when: string) => `Synchronisé ${when}`,
284
320
  failed: "La dernière synchronisation a échoué",
285
321
  never: "Jamais synchronisé",
322
+ noAccounts: "Aucun compte connecté",
323
+ accountsNeedReconnecting: (count: number) =>
324
+ plural("fr", count, {
325
+ one: "Un compte à reconnecter",
326
+ other: `${count} comptes à reconnecter`,
327
+ }),
328
+ accountsFailed: (count: number) =>
329
+ plural("fr", count, {
330
+ one: "Un compte en échec",
331
+ other: `${count} comptes en échec`,
332
+ }),
286
333
  requestFailed: "Impossible de lancer la synchronisation.",
287
334
  },
288
335
  connectors: {
@@ -295,6 +342,12 @@ export const fr: Translation<DataMessages> = {
295
342
  webhookCount: (count: number) =>
296
343
  plural("fr", count, { one: "1 webhook", other: `${count} webhooks` }),
297
344
  oauth: "Se connecte avec OAuth",
345
+ accountsTitle: "Comptes",
346
+ accountsDescription: "Chaque compte connecté, et le dernier passage de ses synchronisations.",
347
+ noAccountsTitle: "Aucun compte connecté",
348
+ searchAccounts: "Rechercher un compte",
349
+ noMatchingAccounts: "Aucun compte ne correspond",
350
+ showAllAccounts: (count: string) => `Afficher les ${count} comptes`,
298
351
  syncsTitle: "Synchronisations",
299
352
  syncsDescription: "Ce que ce connecteur copie dans le projet.",
300
353
  noSyncsTitle: "Aucune synchronisation",
@@ -324,6 +377,26 @@ export const fr: Translation<DataMessages> = {
324
377
  connector: "Connecteur",
325
378
  dataset: "Jeu de données",
326
379
  runWhat: "Les synchronisations",
380
+ accounts: (count: number, formatted: string) =>
381
+ plural("fr", count, { one: `${formatted} compte`, other: `${formatted} comptes` }),
382
+ needReconnecting: (count: number) =>
383
+ plural("fr", count, {
384
+ one: "1 à reconnecter",
385
+ other: `${count} à reconnecter`,
386
+ }),
387
+ failingAccounts: (count: number) =>
388
+ plural("fr", count, { one: "1 en échec", other: `${count} en échec` }),
389
+ project: "Projet",
390
+ slot: (slot: string) => `Emplacement ${slot}`,
391
+ notSyncedYet: "Pas encore synchronisé",
392
+ needsReconnecting: "À reconnecter",
393
+ syncAccount: (account: string) => `Synchroniser ${account}`,
394
+ needsAttention: "À traiter",
395
+ noAccounts: "Aucun compte",
396
+ accountsStat: "Comptes",
397
+ syncedStat: "Synchronisés",
398
+ attentionStat: "À traiter",
399
+ lastSynced: "Dernière synchronisation",
327
400
  },
328
401
  datasets: {
329
402
  title: "Jeux de données",