@sixb/app 0.2.5 → 0.2.7

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 (136) 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/sandbox-recovery.d.ts +8 -2
  10. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  11. package/dist/agent/components/transcript.d.ts +13 -0
  12. package/dist/agent/components/transcript.d.ts.map +1 -1
  13. package/dist/agent/conversation.d.ts +4 -0
  14. package/dist/agent/conversation.d.ts.map +1 -1
  15. package/dist/agent/delegation/use-children.d.ts +5 -5
  16. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  17. package/dist/agent/format.d.ts +7 -0
  18. package/dist/agent/format.d.ts.map +1 -1
  19. package/dist/agent/hooks/thread-queries.d.ts +1548 -0
  20. package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
  21. package/dist/agent/hooks/use-agent-conversation.d.ts +41 -2
  22. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  23. package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
  24. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  25. package/dist/agent/hooks/use-thread-place.d.ts +49 -0
  26. package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
  27. package/dist/agent/i18n/en.d.ts +44 -6
  28. package/dist/agent/i18n/en.d.ts.map +1 -1
  29. package/dist/agent/i18n/fr.d.ts.map +1 -1
  30. package/dist/agent/i18n/index.d.ts +76 -12
  31. package/dist/agent/i18n/index.d.ts.map +1 -1
  32. package/dist/agent/live-run.d.ts.map +1 -1
  33. package/dist/agent/model-selection.d.ts +3 -2
  34. package/dist/agent/model-selection.d.ts.map +1 -1
  35. package/dist/agent/moves.d.ts +40 -0
  36. package/dist/agent/moves.d.ts.map +1 -0
  37. package/dist/agent/thread-reader-state.d.ts +30 -0
  38. package/dist/agent/thread-reader-state.d.ts.map +1 -0
  39. package/dist/agent/types.d.ts +4 -0
  40. package/dist/agent/types.d.ts.map +1 -1
  41. package/dist/artifacts/live/session.d.ts.map +1 -1
  42. package/dist/artifacts/queries.d.ts.map +1 -1
  43. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -1
  44. package/dist/{chunk-69qgh20f.js → chunk-1f4h75n3.js} +1 -1
  45. package/dist/{chunk-4fex83k2.js → chunk-7v9622qb.js} +2254 -739
  46. package/dist/{chunk-4fex83k2.js.map → chunk-7v9622qb.js.map} +29 -26
  47. package/dist/{chunk-5sgac68y.js → chunk-dntecmwb.js} +1 -1
  48. package/dist/{chunk-4wm09prf.js → chunk-qmka6aea.js} +1 -1
  49. package/dist/createCustomApp.d.ts +8 -1
  50. package/dist/createCustomApp.d.ts.map +1 -1
  51. package/dist/index.d.ts +3 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +4 -2
  54. package/dist/index.js.map +3 -3
  55. package/dist/pages/console/data/accounts.d.ts +94 -0
  56. package/dist/pages/console/data/accounts.d.ts.map +1 -0
  57. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  58. package/dist/pages/console/data/datasets.d.ts.map +1 -1
  59. package/dist/pages/console/data/live-updates.d.ts.map +1 -1
  60. package/dist/pages/console/data/messages.d.ts +46 -0
  61. package/dist/pages/console/data/messages.d.ts.map +1 -1
  62. package/dist/pages/console/data/pipelines.d.ts.map +1 -1
  63. package/dist/pages/console/data/projections.d.ts.map +1 -1
  64. package/dist/pages/console/data/sync-button.d.ts.map +1 -1
  65. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  66. package/dist/pages/console/ontology/actions.d.ts.map +1 -1
  67. package/dist/pages/console/ontology/object-type.d.ts.map +1 -1
  68. package/dist/pages/console/ontology/object-types.d.ts.map +1 -1
  69. package/dist/pages/console/ontology/rules.d.ts.map +1 -1
  70. package/dist/pages/console/ontology/workflow.d.ts.map +1 -1
  71. package/dist/pages/console/ontology/workflows.d.ts.map +1 -1
  72. package/dist/pages/folders.d.ts +106 -0
  73. package/dist/pages/folders.d.ts.map +1 -0
  74. package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
  75. package/dist/pages/settings/usage/page.d.ts +4 -1
  76. package/dist/pages/settings/usage/page.d.ts.map +1 -1
  77. package/dist/pages/settings/usage/spend-model.d.ts +43 -19
  78. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  79. package/dist/pages.js +23453 -22656
  80. package/dist/pages.js.map +23 -21
  81. package/dist/server.d.ts +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +40 -3
  84. package/dist/server.js.map +3 -3
  85. package/package.json +3 -3
  86. package/src/agent/agent-chat.tsx +2 -2
  87. package/src/agent/components/agent-threads.tsx +42 -2
  88. package/src/agent/components/composer-place.tsx +2 -7
  89. package/src/agent/components/computer-place.tsx +415 -70
  90. package/src/agent/components/conversation-panel.tsx +31 -26
  91. package/src/agent/components/message-view.tsx +418 -9
  92. package/src/agent/components/pending-messages.tsx +5 -1
  93. package/src/agent/components/sandbox-recovery.tsx +24 -6
  94. package/src/agent/components/transcript.tsx +136 -5
  95. package/src/agent/conversation.ts +16 -1
  96. package/src/agent/format.ts +52 -0
  97. package/src/agent/hooks/thread-queries.ts +75 -0
  98. package/src/agent/hooks/use-agent-conversation.ts +461 -112
  99. package/src/agent/hooks/use-thread-lists.ts +72 -7
  100. package/src/agent/hooks/use-thread-place.ts +239 -0
  101. package/src/agent/i18n/en.ts +69 -16
  102. package/src/agent/i18n/fr.ts +71 -19
  103. package/src/agent/live-run.ts +38 -0
  104. package/src/agent/model-selection.ts +3 -2
  105. package/src/agent/moves.ts +174 -0
  106. package/src/agent/thread-reader-state.ts +75 -0
  107. package/src/agent/types.ts +6 -0
  108. package/src/artifacts/live/session.ts +5 -0
  109. package/src/createCustomApp.ts +57 -3
  110. package/src/index.ts +4 -0
  111. package/src/pages/console/data/accounts.tsx +509 -0
  112. package/src/pages/console/data/connectors.tsx +67 -64
  113. package/src/pages/console/data/datasets.tsx +79 -68
  114. package/src/pages/console/data/live-updates.ts +2 -0
  115. package/src/pages/console/data/messages.ts +73 -0
  116. package/src/pages/console/data/pipelines.tsx +80 -69
  117. package/src/pages/console/data/projections.tsx +111 -82
  118. package/src/pages/console/data/sync-button.tsx +56 -16
  119. package/src/pages/console/data/syncs.tsx +121 -86
  120. package/src/pages/console/ontology/actions.tsx +51 -24
  121. package/src/pages/console/ontology/object-type.tsx +5 -1
  122. package/src/pages/console/ontology/object-types.tsx +41 -32
  123. package/src/pages/console/ontology/rules.tsx +48 -38
  124. package/src/pages/console/ontology/workflow.tsx +9 -3
  125. package/src/pages/console/ontology/workflows.tsx +55 -67
  126. package/src/pages/folders.tsx +335 -0
  127. package/src/pages/section-ui.tsx +1 -1
  128. package/src/pages/settings/usage/breakdown.tsx +5 -2
  129. package/src/pages/settings/usage/filter-menu.tsx +1 -1
  130. package/src/pages/settings/usage/page.tsx +32 -13
  131. package/src/pages/settings/usage/spend-chart.tsx +2 -2
  132. package/src/pages/settings/usage/spend-model.ts +118 -50
  133. package/src/server.ts +1 -0
  134. /package/dist/{chunk-69qgh20f.js.map → chunk-1f4h75n3.js.map} +0 -0
  135. /package/dist/{chunk-5sgac68y.js.map → chunk-dntecmwb.js.map} +0 -0
  136. /package/dist/{chunk-4wm09prf.js.map → chunk-qmka6aea.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
+ }
@@ -8,6 +8,7 @@ import {
8
8
  import { useQuery } from "@tanstack/react-query"
9
9
  import { Cable, ChevronRight, RefreshCw, Webhook } from "lucide-react"
10
10
  import { useParams } from "react-router-dom"
11
+ import { FolderContents, folderBack, noItems, useFolderBrowser } from "../../folders"
11
12
  import { DetailFallback, SectionPage } from "../../section-page"
12
13
  import {
13
14
  apiErrorMessage,
@@ -30,6 +31,7 @@ import {
30
31
  useNumbers,
31
32
  } from "../../section-ui"
32
33
  import { MetaSkeleton, SkeletonBlock, TrailingSkeleton } from "../skeletons"
34
+ import { ConnectorAccountsSection, SyncStatusPill, SyncTimeMeta } from "./accounts"
33
35
  import { useDataMessages } from "./messages"
34
36
  import { ConnectorIcon } from "./shared"
35
37
 
@@ -37,60 +39,67 @@ import { ConnectorIcon } from "./shared"
37
39
  export function ConsoleConnectorsPage() {
38
40
  const messages = useDataMessages()
39
41
  const connectorsQuery = useQuery({ ...listConnectorsOptions(), retry: false })
40
- const connectors = connectorsQuery.data ?? []
42
+ const browser = useFolderBrowser({
43
+ items: connectorsQuery.data ?? noItems,
44
+ title: messages.connectors.title,
45
+ description: messages.connectors.description,
46
+ })
41
47
 
42
48
  return (
43
- <SectionPage
44
- section="console"
45
- page="connectors"
46
- title={messages.connectors.title}
47
- description={messages.connectors.description}
48
- >
49
- <Panel>
50
- {connectorsQuery.isPending ? (
51
- <PanelSkeleton
52
- rows={3}
53
- interactive
54
- trailing={<TrailingSkeleton pill={false} chevron />}
55
- />
56
- ) : connectorsQuery.isError ? (
57
- <PanelEmpty
58
- tone="error"
59
- icon={Cable}
60
- title={messages.connectors.title}
61
- description={apiErrorMessage(connectorsQuery.error, messages.common.loadFailed)}
62
- />
63
- ) : connectors.length === 0 ? (
64
- <PanelEmpty
65
- icon={Cable}
66
- title={messages.connectors.emptyTitle}
67
- description={messages.connectors.emptyDescription}
68
- />
69
- ) : (
70
- connectors.map((connector) => (
71
- <PanelRow
72
- key={connector.id}
73
- href={`/console/connectors/${encodeURIComponent(connector.id)}`}
74
- leading={<ConnectorIcon type={connector.type} />}
75
- title={<span className="truncate">{humanize(connector.id)}</span>}
76
- meta={
77
- <>
78
- <span className="font-mono text-xs">{connector.type}</span>
79
- <MetaDot />
80
- <span>{messages.connectors.syncCount(connector.syncIds.length)}</span>
81
- {connector.webhooks.length > 0 ? (
49
+ <SectionPage section="console" page="connectors" {...browser.frame}>
50
+ {connectorsQuery.isSuccess && connectorsQuery.data.length > 0 ? (
51
+ <FolderContents browser={browser} rootLabel={messages.connectors.title}>
52
+ {(connectors) => (
53
+ <Panel>
54
+ {connectors.map((connector) => (
55
+ <PanelRow
56
+ key={connector.id}
57
+ href={`/console/connectors/${encodeURIComponent(connector.id)}`}
58
+ leading={<ConnectorIcon type={connector.type} />}
59
+ title={<span className="truncate">{humanize(connector.id)}</span>}
60
+ meta={
82
61
  <>
62
+ <span className="font-mono text-xs">{connector.type}</span>
83
63
  <MetaDot />
84
- <span>{messages.connectors.webhookCount(connector.webhooks.length)}</span>
64
+ <span>{messages.connectors.syncCount(connector.syncIds.length)}</span>
65
+ {connector.webhooks.length > 0 ? (
66
+ <>
67
+ <MetaDot />
68
+ <span>{messages.connectors.webhookCount(connector.webhooks.length)}</span>
69
+ </>
70
+ ) : null}
85
71
  </>
86
- ) : null}
87
- </>
88
- }
89
- trailing={<ChevronRight className="size-4 text-muted-foreground/60" />}
72
+ }
73
+ trailing={<ChevronRight className="size-4 text-muted-foreground/60" />}
74
+ />
75
+ ))}
76
+ </Panel>
77
+ )}
78
+ </FolderContents>
79
+ ) : (
80
+ <Panel>
81
+ {connectorsQuery.isPending ? (
82
+ <PanelSkeleton
83
+ rows={3}
84
+ interactive
85
+ trailing={<TrailingSkeleton pill={false} chevron />}
86
+ />
87
+ ) : connectorsQuery.isError ? (
88
+ <PanelEmpty
89
+ tone="error"
90
+ icon={Cable}
91
+ title={messages.connectors.title}
92
+ description={apiErrorMessage(connectorsQuery.error, messages.common.loadFailed)}
90
93
  />
91
- ))
92
- )}
93
- </Panel>
94
+ ) : (
95
+ <PanelEmpty
96
+ icon={Cable}
97
+ title={messages.connectors.emptyTitle}
98
+ description={messages.connectors.emptyDescription}
99
+ />
100
+ )}
101
+ </Panel>
102
+ )}
94
103
  </SectionPage>
95
104
  )
96
105
  }
@@ -117,7 +126,10 @@ export function ConsoleConnectorPage() {
117
126
  })
118
127
  const syncs = (syncsQuery.data ?? []).filter((sync) => sync.connector.id === connectorId)
119
128
  const apiUrl = (client.getConfig().baseUrl ?? window.location.origin).replace(/\/$/, "")
120
- const back = { href: "/console/connectors", label: messages.connectors.title }
129
+ const back = folderBack(
130
+ { href: "/console/connectors", label: messages.connectors.title },
131
+ connector?.folder
132
+ )
121
133
 
122
134
  if (!connector) {
123
135
  return (
@@ -196,29 +208,20 @@ export function ConsoleConnectorPage() {
196
208
  meta={
197
209
  <>
198
210
  <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}
211
+ <SyncTimeMeta sync={sync} />
207
212
  </>
208
213
  }
209
- trailing={
210
- sync.latestRun ? (
211
- <RunStatusPill status={sync.latestRun.status} />
212
- ) : (
213
- <Pill tone="muted">{messages.common.neverRun}</Pill>
214
- )
215
- }
214
+ trailing={<SyncStatusPill sync={sync} />}
216
215
  />
217
216
  ))
218
217
  )}
219
218
  </Panel>
220
219
  </PageSection>
221
220
 
221
+ {connector.connection && syncs.length > 0 ? (
222
+ <ConnectorAccountsSection connectorId={connector.id} syncs={syncs} />
223
+ ) : null}
224
+
222
225
  {webhooks.length > 0 ? (
223
226
  <>
224
227
  <PageSection