@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
@@ -8,8 +8,9 @@ import {
8
8
  } from "@sixb/client/hooks"
9
9
  import { useQuery } from "@tanstack/react-query"
10
10
  import { Activity, ArrowRight, Box, ChevronRight, Layers, Link2 } from "lucide-react"
11
- import { type ComponentType, type ReactNode, useState } from "react"
11
+ import { type ComponentType, type ReactNode, useMemo, useState } from "react"
12
12
  import { Link, useParams } from "react-router-dom"
13
+ import { FolderContents, folderBack, noItems, useFolderBrowser } from "../../folders"
13
14
  import { DetailFallback, SectionPage } from "../../section-page"
14
15
  import {
15
16
  apiErrorMessage,
@@ -82,102 +83,127 @@ export function projectionRunsPollInterval(
82
83
  /** Console › Projections: how datasets become objects, links and telemetry. */
83
84
  export function ConsoleProjectionsPage() {
84
85
  const messages = useDataMessages()
85
- const format = useFormat()
86
86
  const [tab, setTab] = useState<Tab>("all")
87
87
  const projectionsQuery = useQuery({ ...listProjectionsOptions(), retry: false })
88
88
  const data = projectionsQuery.data
89
- const all: readonly Projection[] = data
90
- ? [...data.objectProjections, ...data.linkProjections, ...data.telemetryProjections]
91
- : []
92
- const shown = tab === "all" ? all : all.filter((projection) => kindOf(projection) === tab)
93
- const count = (kind: ProjectionKind) => all.filter((p) => kindOf(p) === kind).length
94
- // A kind the project has none of gets no tab, so no tab is ever empty.
89
+ const all = useMemo<readonly Projection[]>(
90
+ () =>
91
+ data
92
+ ? [...data.objectProjections, ...data.linkProjections, ...data.telemetryProjections]
93
+ : noItems,
94
+ [data]
95
+ )
96
+ const browser = useFolderBrowser({
97
+ items: all,
98
+ title: messages.projections.title,
99
+ description: messages.projections.description,
100
+ })
101
+
102
+ return (
103
+ <SectionPage section="console" page="projections" {...browser.frame}>
104
+ {all.length > 0 ? (
105
+ <FolderContents browser={browser} rootLabel={messages.projections.title}>
106
+ {(projections) => (
107
+ <ProjectionsPanel projections={projections} tab={tab} onTabChange={setTab} />
108
+ )}
109
+ </FolderContents>
110
+ ) : (
111
+ <Panel
112
+ toolbar={projectionsQuery.isPending ? <SkeletonBlock className="h-7 w-56" /> : undefined}
113
+ >
114
+ {projectionsQuery.isPending ? (
115
+ <PanelSkeleton rows={3} interactive trailing={<TrailingSkeleton chevron />} />
116
+ ) : projectionsQuery.isError ? (
117
+ <PanelEmpty
118
+ tone="error"
119
+ icon={Layers}
120
+ title={messages.projections.title}
121
+ description={apiErrorMessage(projectionsQuery.error, messages.common.loadFailed)}
122
+ />
123
+ ) : (
124
+ <PanelEmpty
125
+ icon={Layers}
126
+ title={messages.projections.emptyTitle}
127
+ description={messages.projections.emptyDescription}
128
+ />
129
+ )}
130
+ </Panel>
131
+ )}
132
+ </SectionPage>
133
+ )
134
+ }
135
+
136
+ /** Projections with a tab for each kind among them, so no tab is ever empty. */
137
+ function ProjectionsPanel({
138
+ projections,
139
+ tab: chosen,
140
+ onTabChange,
141
+ }: {
142
+ readonly projections: readonly Projection[]
143
+ readonly tab: Tab
144
+ readonly onTabChange: (tab: Tab) => void
145
+ }) {
146
+ const messages = useDataMessages()
147
+ const format = useFormat()
148
+ const count = (kind: ProjectionKind) => projections.filter((p) => kindOf(p) === kind).length
95
149
  const tabs = (
96
150
  [
97
- { id: "all", label: messages.projections.tabs.all, count: all.length },
151
+ { id: "all", label: messages.projections.tabs.all, count: projections.length },
98
152
  { id: "object", label: messages.projections.tabs.object, count: count("object") },
99
153
  { id: "link", label: messages.projections.tabs.link, count: count("link") },
100
154
  { id: "telemetry", label: messages.projections.tabs.telemetry, count: count("telemetry") },
101
155
  ] satisfies { id: Tab; label: string; count: number }[]
102
156
  ).filter((entry) => entry.id === "all" || entry.count > 0)
157
+ // A folder without the chosen kind shows all of its own.
158
+ const tab = tabs.some((entry) => entry.id === chosen) ? chosen : "all"
159
+ const shown =
160
+ tab === "all" ? projections : projections.filter((projection) => kindOf(projection) === tab)
103
161
 
104
162
  return (
105
- <SectionPage
106
- section="console"
107
- page="projections"
108
- title={messages.projections.title}
109
- description={messages.projections.description}
110
- >
111
- <Panel
112
- toolbar={
113
- projectionsQuery.isPending ? (
114
- <SkeletonBlock className="h-7 w-56" />
115
- ) : all.length > 0 ? (
116
- <ToolbarTabs value={tab} onChange={setTab} tabs={tabs} />
117
- ) : undefined
118
- }
119
- >
120
- {projectionsQuery.isPending ? (
121
- <PanelSkeleton rows={3} interactive trailing={<TrailingSkeleton chevron />} />
122
- ) : projectionsQuery.isError ? (
123
- <PanelEmpty
124
- tone="error"
125
- icon={Layers}
126
- title={messages.projections.title}
127
- description={apiErrorMessage(projectionsQuery.error, messages.common.loadFailed)}
128
- />
129
- ) : shown.length === 0 ? (
130
- <PanelEmpty
131
- icon={Layers}
132
- title={messages.projections.emptyTitle}
133
- description={messages.projections.emptyDescription}
134
- />
135
- ) : (
136
- shown.map((projection) => {
137
- const kind = kindOf(projection)
138
- return (
139
- <PanelRow
140
- key={projection.id}
141
- href={`/console/projections/${encodeURIComponent(projection.id)}`}
142
- leading={<IconTile icon={kindIcons[kind]} />}
143
- title={<span className="truncate">{humanize(projection.id)}</span>}
144
- meta={
163
+ <Panel toolbar={<ToolbarTabs value={tab} onChange={onTabChange} tabs={tabs} />}>
164
+ {shown.map((projection) => {
165
+ const kind = kindOf(projection)
166
+ return (
167
+ <PanelRow
168
+ key={projection.id}
169
+ href={`/console/projections/${encodeURIComponent(projection.id)}`}
170
+ leading={<IconTile icon={kindIcons[kind]} />}
171
+ title={<span className="truncate">{humanize(projection.id)}</span>}
172
+ meta={
173
+ <>
174
+ <span>{messages.projections.kinds[kind]}</span>
175
+ <MetaDot />
176
+ <span className="inline-flex min-w-0 items-center gap-1">
177
+ <span className="truncate font-mono text-xs">{projection.datasetId}</span>
178
+ <ArrowRight className="size-3 shrink-0" />
179
+ <span className="truncate">{targetOf(projection)}</span>
180
+ </span>
181
+ {projection.latestRun ? (
145
182
  <>
146
- <span>{messages.projections.kinds[kind]}</span>
147
183
  <MetaDot />
148
- <span className="inline-flex min-w-0 items-center gap-1">
149
- <span className="truncate font-mono text-xs">{projection.datasetId}</span>
150
- <ArrowRight className="size-3 shrink-0" />
151
- <span className="truncate">{targetOf(projection)}</span>
184
+ <span>
185
+ {format.relative(
186
+ projection.latestRun.startedAt ?? projection.latestRun.queuedAt
187
+ )}
152
188
  </span>
153
- {projection.latestRun ? (
154
- <>
155
- <MetaDot />
156
- <span>
157
- {format.relative(
158
- projection.latestRun.startedAt ?? projection.latestRun.queuedAt
159
- )}
160
- </span>
161
- </>
162
- ) : null}
163
- </>
164
- }
165
- trailing={
166
- <>
167
- {projection.latestRun ? (
168
- <RunStatusPill status={projection.latestRun.status} />
169
- ) : (
170
- <Pill tone="muted">{messages.common.neverRun}</Pill>
171
- )}
172
- <ChevronRight className="size-4 text-muted-foreground/60" />
173
189
  </>
174
- }
175
- />
176
- )
177
- })
178
- )}
179
- </Panel>
180
- </SectionPage>
190
+ ) : null}
191
+ </>
192
+ }
193
+ trailing={
194
+ <>
195
+ {projection.latestRun ? (
196
+ <RunStatusPill status={projection.latestRun.status} />
197
+ ) : (
198
+ <Pill tone="muted">{messages.common.neverRun}</Pill>
199
+ )}
200
+ <ChevronRight className="size-4 text-muted-foreground/60" />
201
+ </>
202
+ }
203
+ />
204
+ )
205
+ })}
206
+ </Panel>
181
207
  )
182
208
  }
183
209
 
@@ -209,7 +235,10 @@ export function ConsoleProjectionPage() {
209
235
  })
210
236
 
211
237
  const projection = projectionQuery.data
212
- const back = { href: "/console/projections", label: messages.projections.title }
238
+ const back = folderBack(
239
+ { href: "/console/projections", label: messages.projections.title },
240
+ projection?.folder
241
+ )
213
242
 
214
243
  if (!projection) {
215
244
  return (
@@ -1,3 +1,4 @@
1
+ import type { GetSyncResponse } from "@sixb/client"
1
2
  import {
2
3
  getSyncOptions,
3
4
  getSyncQueryKey,
@@ -13,6 +14,9 @@ import { apiErrorMessage, useFormat } from "../../section-ui"
13
14
  import { useSyncLiveUpdates } from "./live-updates"
14
15
  import { useDataMessages } from "./messages"
15
16
 
17
+ type Sync = GetSyncResponse
18
+ type SyncStatus = { readonly text: string; readonly failed: boolean }
19
+
16
20
  export interface SyncButtonProps {
17
21
  /** The sync's id, as named in `syncs/`. */
18
22
  readonly sync: string
@@ -44,10 +48,7 @@ export function SyncButton({
44
48
  ...getSyncOptions({ path }),
45
49
  retry: false,
46
50
  // Live updates refresh it as the run moves; polling covers a dropped event stream.
47
- refetchInterval: (query) => {
48
- const status = query.state.data?.latestRun?.status
49
- return status === "queued" || status === "running" ? 5000 : false
50
- },
51
+ refetchInterval: (query) => (query.state.data && isSyncing(query.state.data) ? 5000 : false),
51
52
  })
52
53
  const request = useMutation({
53
54
  ...requestSyncRunMutation(),
@@ -56,24 +57,17 @@ export function SyncButton({
56
57
  queryClient.invalidateQueries({ queryKey: getSyncQueryKey({ path }) }),
57
58
  queryClient.invalidateQueries({ queryKey: listSyncsQueryKey() }),
58
59
  queryClient.invalidateQueries({ queryKey: listSyncRunsQueryKey() }),
60
+ queryClient.invalidateQueries({ queryKey: [{ _id: "listConnectorAccounts" }] }),
59
61
  ]),
60
62
  })
61
63
 
62
- const latestRun = syncQuery.data?.latestRun ?? null
63
- const working =
64
- request.isPending || latestRun?.status === "queued" || latestRun?.status === "running"
64
+ const working = request.isPending || (syncQuery.data ? isSyncing(syncQuery.data) : false)
65
65
 
66
- let status: { readonly text: string; readonly failed: boolean } | null = null
66
+ let status: SyncStatus | null = null
67
67
  if (request.isError) {
68
68
  status = { text: apiErrorMessage(request.error, messages.requestFailed), failed: true }
69
- } else if (!working && syncQuery.isSuccess) {
70
- if (!latestRun) status = { text: messages.never, failed: false }
71
- else if (latestRun.status === "failed") status = { text: messages.failed, failed: true }
72
- else if (latestRun.status === "succeeded")
73
- status = {
74
- text: messages.synced(format.relative(latestRun.finishedAt ?? latestRun.queuedAt)),
75
- failed: false,
76
- }
69
+ } else if (!working && syncQuery.data) {
70
+ status = syncStatus(syncQuery.data, messages, format)
77
71
  }
78
72
 
79
73
  return (
@@ -101,3 +95,49 @@ export function SyncButton({
101
95
  </div>
102
96
  )
103
97
  }
98
+
99
+ /** Whether a run is under way: the latest one, or on a sync of an OAuth connector, any account's. */
100
+ function isSyncing(sync: Sync): boolean {
101
+ if (sync.accounts) return sync.accounts.running > 0
102
+
103
+ const status = sync.latestRun?.status
104
+ return status === "queued" || status === "running"
105
+ }
106
+
107
+ /**
108
+ * When it last synced, or that it failed. On a sync of an OAuth connector, the accounts you see
109
+ * tell: the latest run is only the account that ran last.
110
+ */
111
+ function syncStatus(
112
+ sync: Sync,
113
+ messages: ReturnType<typeof useDataMessages>["syncButton"],
114
+ format: ReturnType<typeof useFormat>
115
+ ): SyncStatus | null {
116
+ const accounts = sync.accounts
117
+
118
+ if (accounts) {
119
+ if (accounts.needsReconnecting > 0) {
120
+ return { text: messages.accountsNeedReconnecting(accounts.needsReconnecting), failed: true }
121
+ }
122
+ if (accounts.failing > 0) {
123
+ return { text: messages.accountsFailed(accounts.failing), failed: true }
124
+ }
125
+ if (accounts.lastSyncedAt) {
126
+ return { text: messages.synced(format.relative(accounts.lastSyncedAt)), failed: false }
127
+ }
128
+
129
+ return { text: accounts.total === 0 ? messages.noAccounts : messages.never, failed: false }
130
+ }
131
+
132
+ const latestRun = sync.latestRun
133
+ if (!latestRun) return { text: messages.never, failed: false }
134
+ if (latestRun.status === "failed") return { text: messages.failed, failed: true }
135
+ if (latestRun.status === "succeeded") {
136
+ return {
137
+ text: messages.synced(format.relative(latestRun.finishedAt ?? latestRun.queuedAt)),
138
+ failed: false,
139
+ }
140
+ }
141
+
142
+ return null
143
+ }
@@ -2,6 +2,7 @@ import { getSyncOptions, listSyncRunsOptions, listSyncsOptions } from "@sixb/cli
2
2
  import { useQuery } from "@tanstack/react-query"
3
3
  import { CalendarClock, ChevronRight, RefreshCw } from "lucide-react"
4
4
  import { Link, useParams } from "react-router-dom"
5
+ import { FolderContents, folderBack, noItems, useFolderBrowser } from "../../folders"
5
6
  import { DetailFallback, SectionPage } from "../../section-page"
6
7
  import {
7
8
  apiErrorMessage,
@@ -25,6 +26,14 @@ import {
25
26
  useRunStatusLabels,
26
27
  } from "../../section-ui"
27
28
  import { MetaSkeleton, SkeletonBlock, StatsSkeleton, TrailingSkeleton } from "../skeletons"
29
+ import {
30
+ AccountsMeta,
31
+ needsReconnecting,
32
+ SyncStatusPill,
33
+ SyncTimeMeta,
34
+ useAccountsStats,
35
+ useConnectorAccounts,
36
+ } from "./accounts"
28
37
  import { useSyncLiveUpdates } from "./live-updates"
29
38
  import { useDataMessages } from "./messages"
30
39
  import { SchemaPanel } from "./schema"
@@ -34,73 +43,71 @@ import { SyncButton } from "./sync-button"
34
43
  /** Console › Syncs: what copies each connector's data into the project, and how it last went. */
35
44
  export function ConsoleSyncsPage() {
36
45
  const messages = useDataMessages()
37
- const format = useFormat()
38
46
  useSyncLiveUpdates()
39
47
  const syncsQuery = useQuery({ ...listSyncsOptions(), retry: false })
40
- const syncs = syncsQuery.data ?? []
48
+ const browser = useFolderBrowser({
49
+ items: syncsQuery.data ?? noItems,
50
+ title: messages.syncs.title,
51
+ description: messages.syncs.description,
52
+ })
41
53
 
42
54
  return (
43
- <SectionPage
44
- section="console"
45
- page="syncs"
46
- title={messages.syncs.title}
47
- description={messages.syncs.description}
48
- >
49
- <Panel>
50
- {syncsQuery.isPending ? (
51
- <PanelSkeleton rows={3} interactive trailing={<TrailingSkeleton chevron />} />
52
- ) : syncsQuery.isError ? (
53
- <PanelEmpty
54
- tone="error"
55
- icon={RefreshCw}
56
- title={messages.syncs.title}
57
- description={apiErrorMessage(syncsQuery.error, messages.common.loadFailed)}
58
- />
59
- ) : syncs.length === 0 ? (
60
- <PanelEmpty
61
- icon={RefreshCw}
62
- title={messages.syncs.emptyTitle}
63
- description={messages.syncs.emptyDescription}
64
- />
65
- ) : (
66
- syncs.map((sync) => (
67
- <PanelRow
68
- key={sync.id}
69
- href={`/console/syncs/${encodeURIComponent(sync.id)}`}
70
- leading={<ConnectorIcon type={sync.connector.type} />}
71
- title={<span className="truncate">{humanize(sync.id)}</span>}
72
- meta={
73
- <>
74
- <span>{messages.common.modes[sync.mode]}</span>
75
- <MetaDot />
76
- <span className="truncate">{messages.common.writes(sync.target.dataset.id)}</span>
77
- {sync.triggers.map((trigger) => (
78
- <ScheduleMeta key={trigger.scheduleId} id={trigger.scheduleId} />
79
- ))}
80
- {sync.latestRun ? (
55
+ <SectionPage section="console" page="syncs" {...browser.frame}>
56
+ {syncsQuery.isSuccess && syncsQuery.data.length > 0 ? (
57
+ <FolderContents browser={browser} rootLabel={messages.syncs.title}>
58
+ {(syncs) => (
59
+ <Panel>
60
+ {syncs.map((sync) => (
61
+ <PanelRow
62
+ key={sync.id}
63
+ href={`/console/syncs/${encodeURIComponent(sync.id)}`}
64
+ leading={<ConnectorIcon type={sync.connector.type} />}
65
+ title={<span className="truncate">{humanize(sync.id)}</span>}
66
+ meta={
81
67
  <>
68
+ <span>{messages.common.modes[sync.mode]}</span>
82
69
  <MetaDot />
83
- <span>
84
- {format.relative(sync.latestRun.startedAt ?? sync.latestRun.queuedAt)}
70
+ <span className="truncate">
71
+ {messages.common.writes(sync.target.dataset.id)}
85
72
  </span>
73
+ {sync.triggers.map((trigger) => (
74
+ <ScheduleMeta key={trigger.scheduleId} id={trigger.scheduleId} />
75
+ ))}
76
+ <SyncTimeMeta sync={sync} />
77
+ {sync.accounts ? <AccountsMeta summary={sync.accounts} /> : null}
86
78
  </>
87
- ) : null}
88
- </>
89
- }
90
- trailing={
91
- <>
92
- {sync.latestRun ? (
93
- <RunStatusPill status={sync.latestRun.status} />
94
- ) : (
95
- <Pill tone="muted">{messages.common.neverRun}</Pill>
96
- )}
97
- <ChevronRight className="size-4 text-muted-foreground/60" />
98
- </>
99
- }
79
+ }
80
+ trailing={
81
+ <>
82
+ <SyncStatusPill sync={sync} />
83
+ <ChevronRight className="size-4 text-muted-foreground/60" />
84
+ </>
85
+ }
86
+ />
87
+ ))}
88
+ </Panel>
89
+ )}
90
+ </FolderContents>
91
+ ) : (
92
+ <Panel>
93
+ {syncsQuery.isPending ? (
94
+ <PanelSkeleton rows={3} interactive trailing={<TrailingSkeleton chevron />} />
95
+ ) : syncsQuery.isError ? (
96
+ <PanelEmpty
97
+ tone="error"
98
+ icon={RefreshCw}
99
+ title={messages.syncs.title}
100
+ description={apiErrorMessage(syncsQuery.error, messages.common.loadFailed)}
101
+ />
102
+ ) : (
103
+ <PanelEmpty
104
+ icon={RefreshCw}
105
+ title={messages.syncs.emptyTitle}
106
+ description={messages.syncs.emptyDescription}
100
107
  />
101
- ))
102
- )}
103
- </Panel>
108
+ )}
109
+ </Panel>
110
+ )}
104
111
  </SectionPage>
105
112
  )
106
113
  }
@@ -124,7 +131,16 @@ export function ConsoleSyncPage() {
124
131
  : false,
125
132
  })
126
133
  const sync = syncQuery.data
127
- const back = { href: "/console/syncs", label: messages.syncs.title }
134
+ const accountsStats = useAccountsStats(sync?.accounts)
135
+ // Runs name their account: the connector's accounts give their labels.
136
+ const accountsQuery = useConnectorAccounts(sync?.connector.id ?? "", sync?.accounts !== undefined)
137
+ const accountLabels = new Map(
138
+ accountsQuery.data?.accounts.map(({ connection }) => [
139
+ connection.id,
140
+ connection.account.label,
141
+ ]) ?? []
142
+ )
143
+ const back = folderBack({ href: "/console/syncs", label: messages.syncs.title }, sync?.folder)
128
144
 
129
145
  if (!sync) {
130
146
  return (
@@ -165,7 +181,8 @@ export function ConsoleSyncPage() {
165
181
  )
166
182
  }
167
183
 
168
- const latestRun = sync.latestRun
184
+ // On a sync of an OAuth connector, the latest run is one account's: the accounts describe it.
185
+ const latestRun = sync.accounts ? null : sync.latestRun
169
186
  // A failed latest run gets its own panel; its row leaves the failure out rather than repeat it.
170
187
  const failedLatest = latestRun?.status === "failed" && latestRun.error ? latestRun : null
171
188
  const dataset = sync.target.dataset
@@ -180,40 +197,44 @@ export function ConsoleSyncPage() {
180
197
  title={humanize(sync.id)}
181
198
  meta={
182
199
  <>
183
- {latestRun ? (
184
- <RunStatusPill status={latestRun.status} />
185
- ) : (
186
- <Pill tone="muted">{messages.common.neverRun}</Pill>
187
- )}
200
+ <SyncStatusPill sync={sync} />
188
201
  <span>{messages.common.modes[sync.mode]}</span>
189
202
  <MetaDot />
190
203
  <Link to={datasetHref} className="hover:text-foreground hover:underline">
191
204
  {messages.common.writes(dataset.id)}
192
205
  </Link>
206
+ {sync.accounts ? (
207
+ <AccountsMeta
208
+ summary={sync.accounts}
209
+ href={`/console/connectors/${encodeURIComponent(sync.connector.id)}`}
210
+ />
211
+ ) : null}
193
212
  </>
194
213
  }
195
214
  actions={<SyncButton sync={sync.id} variant="default" />}
196
215
  >
197
216
  <Stats
198
- items={[
199
- {
200
- label: messages.common.lastRun,
201
- value: latestRun ? (
202
- statusLabels[latestRun.status]
203
- ) : (
204
- <span className="text-muted-foreground">{messages.common.neverRun}</span>
205
- ),
206
- },
207
- {
208
- label: messages.common.started,
209
- value: latestRun ? format.relative(latestRun.startedAt ?? latestRun.queuedAt) : "—",
210
- },
211
- {
212
- label: messages.common.took,
213
- value: formatDuration(latestRun?.startedAt, latestRun?.finishedAt),
214
- },
215
- { label: messages.syncs.rowsRead, value: numbers.count(latestRun?.rowsRead) },
216
- ]}
217
+ items={
218
+ accountsStats ?? [
219
+ {
220
+ label: messages.common.lastRun,
221
+ value: latestRun ? (
222
+ statusLabels[latestRun.status]
223
+ ) : (
224
+ <span className="text-muted-foreground">{messages.common.neverRun}</span>
225
+ ),
226
+ },
227
+ {
228
+ label: messages.common.started,
229
+ value: latestRun ? format.relative(latestRun.startedAt ?? latestRun.queuedAt) : "—",
230
+ },
231
+ {
232
+ label: messages.common.took,
233
+ value: formatDuration(latestRun?.startedAt, latestRun?.finishedAt),
234
+ },
235
+ { label: messages.syncs.rowsRead, value: numbers.count(latestRun?.rowsRead) },
236
+ ]
237
+ }
217
238
  />
218
239
 
219
240
  {failedLatest?.error ? (
@@ -250,6 +271,14 @@ export function ConsoleSyncPage() {
250
271
  title={format.dateTime(run.startedAt ?? run.queuedAt)}
251
272
  meta={
252
273
  <>
274
+ {run.connectionId ? (
275
+ <>
276
+ <span className="truncate">
277
+ {accountLabels.get(run.connectionId) ?? run.connectionId}
278
+ </span>
279
+ <MetaDot />
280
+ </>
281
+ ) : null}
253
282
  <span>{messages.common.modes[run.mode]}</span>
254
283
  {run.finishedAt ? (
255
284
  <>
@@ -292,9 +321,15 @@ export function ConsoleSyncPage() {
292
321
  ) : null}
293
322
  </>
294
323
  }
295
- trailing={<RunStatusPill status={run.status} />}
324
+ trailing={
325
+ needsReconnecting(run) ? (
326
+ <Pill tone="warn">{messages.syncs.needsReconnecting}</Pill>
327
+ ) : (
328
+ <RunStatusPill status={run.status} />
329
+ )
330
+ }
296
331
  >
297
- {run.error && run.id !== failedLatest?.id ? (
332
+ {run.error && run.id !== failedLatest?.id && !needsReconnecting(run) ? (
298
333
  <FailureSummary failure={run.error} compact />
299
334
  ) : null}
300
335
  </PanelRow>