@kelpie/ui 0.22.0 → 0.24.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 (196) hide show
  1. package/dist/api/resource.d.ts +12 -0
  2. package/dist/api/resource.d.ts.map +1 -1
  3. package/dist/api/resource.js +11 -0
  4. package/dist/api/resource.js.map +1 -1
  5. package/dist/api/resources/decisions.d.ts +31 -0
  6. package/dist/api/resources/decisions.d.ts.map +1 -1
  7. package/dist/api/resources/decisions.js +51 -1
  8. package/dist/api/resources/decisions.js.map +1 -1
  9. package/dist/api/resources/oauth.d.ts +2 -0
  10. package/dist/api/resources/oauth.d.ts.map +1 -1
  11. package/dist/api/resources/oauth.js +13 -1
  12. package/dist/api/resources/oauth.js.map +1 -1
  13. package/dist/api/resources/personIntake.d.ts +15 -3
  14. package/dist/api/resources/personIntake.d.ts.map +1 -1
  15. package/dist/api/resources/personIntake.js +38 -9
  16. package/dist/api/resources/personIntake.js.map +1 -1
  17. package/dist/api/resources/session.d.ts.map +1 -1
  18. package/dist/api/resources/session.js +4 -0
  19. package/dist/api/resources/session.js.map +1 -1
  20. package/dist/app/KelpieApp.d.ts.map +1 -1
  21. package/dist/app/KelpieApp.js +2 -1
  22. package/dist/app/KelpieApp.js.map +1 -1
  23. package/dist/components/AddRecordPanel.d.ts +35 -0
  24. package/dist/components/AddRecordPanel.d.ts.map +1 -0
  25. package/dist/components/AddRecordPanel.js +35 -0
  26. package/dist/components/AddRecordPanel.js.map +1 -0
  27. package/dist/components/AiDrawer.d.ts.map +1 -1
  28. package/dist/components/AiDrawer.js +29 -6
  29. package/dist/components/AiDrawer.js.map +1 -1
  30. package/dist/components/ApiKeysPanel.d.ts.map +1 -1
  31. package/dist/components/ApiKeysPanel.js +101 -44
  32. package/dist/components/ApiKeysPanel.js.map +1 -1
  33. package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
  34. package/dist/components/CustomFieldsPanel.js +5 -2
  35. package/dist/components/CustomFieldsPanel.js.map +1 -1
  36. package/dist/components/DecisionProvenance.d.ts +27 -0
  37. package/dist/components/DecisionProvenance.d.ts.map +1 -0
  38. package/dist/components/DecisionProvenance.js +53 -0
  39. package/dist/components/DecisionProvenance.js.map +1 -0
  40. package/dist/components/DecisionsPanel.d.ts +3 -0
  41. package/dist/components/DecisionsPanel.d.ts.map +1 -1
  42. package/dist/components/DecisionsPanel.js +9 -5
  43. package/dist/components/DecisionsPanel.js.map +1 -1
  44. package/dist/components/MarkdownView.d.ts.map +1 -1
  45. package/dist/components/MarkdownView.js +18 -2
  46. package/dist/components/MarkdownView.js.map +1 -1
  47. package/dist/components/NotesPanel.d.ts.map +1 -1
  48. package/dist/components/NotesPanel.js +7 -3
  49. package/dist/components/NotesPanel.js.map +1 -1
  50. package/dist/components/OriginLabel.d.ts +5 -0
  51. package/dist/components/OriginLabel.d.ts.map +1 -0
  52. package/dist/components/OriginLabel.js +22 -0
  53. package/dist/components/OriginLabel.js.map +1 -0
  54. package/dist/components/Shell.d.ts.map +1 -1
  55. package/dist/components/Shell.js +17 -5
  56. package/dist/components/Shell.js.map +1 -1
  57. package/dist/components/aiDrawerState.d.ts +12 -0
  58. package/dist/components/aiDrawerState.d.ts.map +1 -1
  59. package/dist/components/aiDrawerState.js.map +1 -1
  60. package/dist/components/personIntakeTask.d.ts +15 -0
  61. package/dist/components/personIntakeTask.d.ts.map +1 -1
  62. package/dist/components/personIntakeTask.js +42 -0
  63. package/dist/components/personIntakeTask.js.map +1 -1
  64. package/dist/lib/personIntakeRunStorage.d.ts +15 -0
  65. package/dist/lib/personIntakeRunStorage.d.ts.map +1 -0
  66. package/dist/lib/personIntakeRunStorage.js +88 -0
  67. package/dist/lib/personIntakeRunStorage.js.map +1 -0
  68. package/dist/modules/PersonIntakeWizard.d.ts +1 -1
  69. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
  70. package/dist/modules/PersonIntakeWizard.js +243 -29
  71. package/dist/modules/PersonIntakeWizard.js.map +1 -1
  72. package/dist/modules/ai.d.ts +1 -1
  73. package/dist/modules/ai.js +1 -1
  74. package/dist/pages/CompaniesPage.d.ts.map +1 -1
  75. package/dist/pages/CompaniesPage.js +13 -6
  76. package/dist/pages/CompaniesPage.js.map +1 -1
  77. package/dist/pages/DealsPage.d.ts.map +1 -1
  78. package/dist/pages/DealsPage.js +16 -8
  79. package/dist/pages/DealsPage.js.map +1 -1
  80. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  81. package/dist/pages/DecisionsPage.js +7 -3
  82. package/dist/pages/DecisionsPage.js.map +1 -1
  83. package/dist/pages/EnquiriesPage.d.ts.map +1 -1
  84. package/dist/pages/EnquiriesPage.js +14 -6
  85. package/dist/pages/EnquiriesPage.js.map +1 -1
  86. package/dist/pages/FundraisingPage.d.ts.map +1 -1
  87. package/dist/pages/FundraisingPage.js +16 -11
  88. package/dist/pages/FundraisingPage.js.map +1 -1
  89. package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
  90. package/dist/pages/OpportunitiesPage.js +14 -6
  91. package/dist/pages/OpportunitiesPage.js.map +1 -1
  92. package/dist/pages/PartnershipsPage.d.ts.map +1 -1
  93. package/dist/pages/PartnershipsPage.js +16 -11
  94. package/dist/pages/PartnershipsPage.js.map +1 -1
  95. package/dist/pages/PeoplePage.d.ts.map +1 -1
  96. package/dist/pages/PeoplePage.js +13 -8
  97. package/dist/pages/PeoplePage.js.map +1 -1
  98. package/dist/pages/PersonDetail.js +2 -2
  99. package/dist/pages/PersonDetail.js.map +1 -1
  100. package/dist/pages/SearchPage.d.ts.map +1 -1
  101. package/dist/pages/SearchPage.js +2 -1
  102. package/dist/pages/SearchPage.js.map +1 -1
  103. package/dist/pages/account/ConnectedAppsPage.d.ts +0 -5
  104. package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -1
  105. package/dist/pages/account/ConnectedAppsPage.js +38 -6
  106. package/dist/pages/account/ConnectedAppsPage.js.map +1 -1
  107. package/dist/pages/admin/AgentsPanel.d.ts +10 -0
  108. package/dist/pages/admin/AgentsPanel.d.ts.map +1 -0
  109. package/dist/pages/admin/AgentsPanel.js +81 -0
  110. package/dist/pages/admin/AgentsPanel.js.map +1 -0
  111. package/dist/pages/admin/AiAdminPage.d.ts.map +1 -1
  112. package/dist/pages/admin/AiAdminPage.js +9 -6
  113. package/dist/pages/admin/AiAdminPage.js.map +1 -1
  114. package/dist/pages/admin/AiPage.js +1 -1
  115. package/dist/pages/admin/TeamPage.d.ts.map +1 -1
  116. package/dist/pages/admin/TeamPage.js +16 -3
  117. package/dist/pages/admin/TeamPage.js.map +1 -1
  118. package/dist/pages/ai/AiAccessPage.d.ts +11 -0
  119. package/dist/pages/ai/AiAccessPage.d.ts.map +1 -0
  120. package/dist/pages/ai/AiAccessPage.js +16 -0
  121. package/dist/pages/ai/AiAccessPage.js.map +1 -0
  122. package/dist/pages/ai/McpPanel.d.ts +7 -0
  123. package/dist/pages/ai/McpPanel.d.ts.map +1 -0
  124. package/dist/pages/ai/McpPanel.js +86 -0
  125. package/dist/pages/ai/McpPanel.js.map +1 -0
  126. package/dist/pages/auth/nextPath.d.ts +6 -0
  127. package/dist/pages/auth/nextPath.d.ts.map +1 -1
  128. package/dist/pages/auth/nextPath.js +16 -1
  129. package/dist/pages/auth/nextPath.js.map +1 -1
  130. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  131. package/dist/pages/dashboard/sections.js +4 -2
  132. package/dist/pages/dashboard/sections.js.map +1 -1
  133. package/dist/pages/forms/EmbedPanel.js +1 -1
  134. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  135. package/dist/pages/forms/FormEmails.d.ts.map +1 -1
  136. package/dist/pages/forms/FormEmails.js +6 -1
  137. package/dist/pages/forms/FormEmails.js.map +1 -1
  138. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  139. package/dist/pages/forms/FormSettings.js +6 -2
  140. package/dist/pages/forms/FormSettings.js.map +1 -1
  141. package/dist/pages/forms/SubmissionDetail.js +15 -3
  142. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  143. package/dist/pages/forms/SubmissionsTable.js +5 -2
  144. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  145. package/dist/pages/oauth/ConsentPage.d.ts.map +1 -1
  146. package/dist/pages/oauth/ConsentPage.js +132 -15
  147. package/dist/pages/oauth/ConsentPage.js.map +1 -1
  148. package/dist/registry/contributions.d.ts +1 -1
  149. package/package.json +4 -4
  150. package/src/api/resource.ts +16 -0
  151. package/src/api/resources/decisions.ts +81 -1
  152. package/src/api/resources/oauth.ts +15 -1
  153. package/src/api/resources/personIntake.ts +54 -13
  154. package/src/api/resources/session.ts +4 -0
  155. package/src/app/KelpieApp.tsx +4 -2
  156. package/src/components/AddRecordPanel.tsx +143 -0
  157. package/src/components/AiDrawer.tsx +34 -7
  158. package/src/components/ApiKeysPanel.tsx +193 -75
  159. package/src/components/CustomFieldsPanel.tsx +15 -5
  160. package/src/components/DecisionProvenance.tsx +95 -0
  161. package/src/components/DecisionsPanel.tsx +30 -2
  162. package/src/components/MarkdownView.tsx +45 -11
  163. package/src/components/NotesPanel.tsx +15 -6
  164. package/src/components/OriginLabel.tsx +26 -0
  165. package/src/components/Shell.tsx +30 -6
  166. package/src/components/aiDrawerState.ts +12 -0
  167. package/src/components/personIntakeTask.tsx +48 -0
  168. package/src/lib/personIntakeRunStorage.ts +97 -0
  169. package/src/modules/PersonIntakeWizard.tsx +391 -30
  170. package/src/modules/ai.tsx +1 -1
  171. package/src/pages/CompaniesPage.tsx +22 -5
  172. package/src/pages/DealsPage.tsx +25 -8
  173. package/src/pages/DecisionsPage.tsx +28 -1
  174. package/src/pages/EnquiriesPage.tsx +23 -5
  175. package/src/pages/FundraisingPage.tsx +25 -11
  176. package/src/pages/OpportunitiesPage.tsx +23 -5
  177. package/src/pages/PartnershipsPage.tsx +25 -11
  178. package/src/pages/PeoplePage.tsx +22 -7
  179. package/src/pages/PersonDetail.tsx +4 -2
  180. package/src/pages/SearchPage.tsx +3 -0
  181. package/src/pages/account/ConnectedAppsPage.tsx +97 -14
  182. package/src/pages/admin/{McpPanel.tsx → AgentsPanel.tsx} +11 -168
  183. package/src/pages/admin/AiAdminPage.tsx +16 -11
  184. package/src/pages/admin/AiPage.tsx +1 -1
  185. package/src/pages/admin/TeamPage.tsx +33 -0
  186. package/src/pages/ai/AiAccessPage.tsx +23 -0
  187. package/src/pages/ai/McpPanel.tsx +261 -0
  188. package/src/pages/auth/nextPath.ts +18 -1
  189. package/src/pages/dashboard/sections.tsx +4 -0
  190. package/src/pages/forms/EmbedPanel.tsx +3 -2
  191. package/src/pages/forms/FormEmails.tsx +11 -2
  192. package/src/pages/forms/FormSettings.tsx +5 -0
  193. package/src/pages/forms/SubmissionDetail.tsx +23 -4
  194. package/src/pages/forms/SubmissionsTable.tsx +9 -1
  195. package/src/pages/oauth/ConsentPage.tsx +271 -33
  196. package/src/registry/contributions.ts +1 -1
@@ -0,0 +1,95 @@
1
+ import type { WriteOrigin } from '@kelpie/schemas'
2
+
3
+ import { Chip } from './Chip.tsx'
4
+ import { OriginLabel } from './OriginLabel.tsx'
5
+
6
+ /**
7
+ * What a reader must know before trusting a Decision: whether a member has
8
+ * confirmed it, and what wrote it.
9
+ *
10
+ * A Decision with no `confirmedAt` is a proposal. A hosted AI run writes one,
11
+ * and so does an agent whose connection cannot commit Decisions. It is shown as
12
+ * not confirmed until a member confirms it. A confirmed one shows only its
13
+ * origin, and nothing at all when a member wrote it.
14
+ */
15
+
16
+ const NAME_EXCERPT_LENGTH = 60
17
+
18
+ function excerpt(body: string): string {
19
+ const line = body.replace(/\s+/gu, ' ').trim()
20
+
21
+ return line.length <= NAME_EXCERPT_LENGTH ? line : `${line.slice(0, NAME_EXCERPT_LENGTH)}…`
22
+ }
23
+
24
+ /**
25
+ * Says that a confirm succeeded, for a screen reader. A sighted reader sees the
26
+ * row lose its "not confirmed" label; nothing else would tell a reader who
27
+ * cannot. Always in the page, so that the change of its text is announced.
28
+ */
29
+ export function ConfirmedAnnouncement({ count }: { readonly count: number }): React.JSX.Element {
30
+ return (
31
+ <p role="status" className="sr-only">
32
+ {count === 0 ? '' : count === 1 ? 'Decision confirmed.' : `${String(count)} decisions confirmed.`}
33
+ </p>
34
+ )
35
+ }
36
+
37
+ /**
38
+ * What a proposal says about itself. The server writes no proposal with
39
+ * `member` or `unknown` today: a member's own Decision is confirmed as it is
40
+ * written, and an agent's rewrite changes the origin to `agent`. The label
41
+ * for those two claims nothing about who proposed it.
42
+ */
43
+ const PROPOSAL_LABELS: Readonly<Record<WriteOrigin, string>> = {
44
+ ai: 'Proposed by AI — not confirmed',
45
+ agent: 'Proposed by an agent — not confirmed',
46
+ member: 'Not confirmed',
47
+ unknown: 'Not confirmed',
48
+ }
49
+
50
+ export interface DecisionProvenanceProps {
51
+ readonly origin: WriteOrigin
52
+ readonly confirmedAt: Date | null
53
+ }
54
+
55
+ export function DecisionProvenance({ origin, confirmedAt }: DecisionProvenanceProps): React.JSX.Element | null {
56
+ if (confirmedAt !== null) {
57
+ return <OriginLabel origin={origin} />
58
+ }
59
+
60
+ return <Chip tone="warning">{PROPOSAL_LABELS[origin]}</Chip>
61
+ }
62
+
63
+ /**
64
+ * Confirms a proposal. Shown only on a Decision that is not confirmed.
65
+ *
66
+ * The API refuses every caller but a signed-in member, so this button is the
67
+ * one place a proposal becomes a commitment.
68
+ */
69
+ export function ConfirmDecisionButton({
70
+ body,
71
+ onConfirm,
72
+ isPending,
73
+ }: {
74
+ /** The Decision's text. Its start goes into the button's name. */
75
+ readonly body: string
76
+ readonly onConfirm: () => void
77
+ readonly isPending: boolean
78
+ }): React.JSX.Element {
79
+ return (
80
+ <button
81
+ type="button"
82
+ onClick={onConfirm}
83
+ disabled={isPending}
84
+ // A page can hold several of these. A screen reader lists buttons by
85
+ // name, and "Confirm" five times does not say what each one confirms.
86
+ // The name replaces the visible text for a screen reader, so it has to
87
+ // change with it while the confirm is in flight.
88
+ aria-label={`${isPending ? 'Confirming' : 'Confirm'} decision: ${excerpt(body)}`}
89
+ aria-busy={isPending}
90
+ className="shrink-0 rounded-md bg-accent px-2 py-0.5 text-[11px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
91
+ >
92
+ {isPending ? 'Confirming…' : 'Confirm'}
93
+ </button>
94
+ )
95
+ }
@@ -4,10 +4,16 @@ import type { FormEvent } from 'react'
4
4
  import { Link } from 'react-router'
5
5
 
6
6
  import { useTimezone } from '../api/resources/account.ts'
7
- import { useCreateDecision, useDecisions, useDeleteDecision } from '../api/resources/decisions.ts'
7
+ import {
8
+ useConfirmDecision,
9
+ useCreateDecision,
10
+ useDecisions,
11
+ useDeleteDecision,
12
+ } from '../api/resources/decisions.ts'
8
13
  import { useMembers } from '../api/resources/members.ts'
9
14
  import { formatDate } from '../lib/dates.ts'
10
15
  import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
16
+ import { ConfirmDecisionButton, ConfirmedAnnouncement, DecisionProvenance } from './DecisionProvenance.tsx'
11
17
  import { Paginator } from './Paginator.tsx'
12
18
  import { ErrorPanel } from './QueryState.tsx'
13
19
  import { SectionHeader } from './SectionHeader.tsx'
@@ -18,6 +24,9 @@ import { SectionHeader } from './SectionHeader.tsx'
18
24
  * Ports the mockup's panel: add, remove, and the workspace-list link. The
19
25
  * decision's owner defaults server-side to whoever records it, which is what
20
26
  * the mockup's `members[0]` stood in for, so the form does not send one.
27
+ *
28
+ * A Decision a hosted AI run wrote is a proposal until a member confirms it.
29
+ * It is labelled as one and carries a Confirm button; Remove rejects it.
21
30
  */
22
31
 
23
32
  export interface DecisionsPanelProps {
@@ -30,6 +39,7 @@ export function DecisionsPanel({ targetType, targetId }: DecisionsPanelProps): R
30
39
  const members = useMembers()
31
40
  const createDecision = useCreateDecision()
32
41
  const deleteDecision = useDeleteDecision()
42
+ const confirmDecision = useConfirmDecision()
33
43
  const [adding, setAdding] = useState(false)
34
44
  const [body, setBody] = useState('')
35
45
  const [rationale, setRationale] = useState('')
@@ -94,6 +104,12 @@ export function DecisionsPanel({ targetType, targetId }: DecisionsPanelProps): R
94
104
  <ErrorPanel error={deleteDecision.error} />
95
105
  </div>
96
106
  )}
107
+ <ConfirmedAnnouncement count={confirmDecision.confirmedCount} />
108
+ {confirmDecision.error !== null && (
109
+ <div className="mb-3">
110
+ <ErrorPanel error={confirmDecision.error} />
111
+ </div>
112
+ )}
97
113
  {decisions.error !== null && <ErrorPanel error={decisions.error} />}
98
114
 
99
115
  {adding && (
@@ -163,6 +179,10 @@ export function DecisionsPanel({ targetType, targetId }: DecisionsPanelProps): R
163
179
  onRemove={() => {
164
180
  deleteDecision.run(decision.id)
165
181
  }}
182
+ onConfirm={() => {
183
+ confirmDecision.run({ id: decision.id, updatedAt: decision.updatedAt })
184
+ }}
185
+ isConfirming={confirmDecision.pendingIds.has(decision.id)}
166
186
  />
167
187
  ))}
168
188
  </ul>
@@ -197,10 +217,14 @@ function DecisionItem({
197
217
  decision,
198
218
  ownerName,
199
219
  onRemove,
220
+ onConfirm,
221
+ isConfirming,
200
222
  }: {
201
223
  readonly decision: Decision
202
224
  readonly ownerName: string | undefined
203
225
  readonly onRemove: () => void
226
+ readonly onConfirm: () => void
227
+ readonly isConfirming: boolean
204
228
  }): React.JSX.Element {
205
229
  const timezone = useTimezone()
206
230
  const target = useFragmentTarget<HTMLLIElement>(decision.id)
@@ -215,6 +239,9 @@ function DecisionItem({
215
239
  >
216
240
  <div className="flex items-start justify-between gap-2">
217
241
  <p className="min-w-0 flex-1 text-[13px] font-medium text-ink">{decision.body}</p>
242
+ {decision.confirmedAt === null && (
243
+ <ConfirmDecisionButton body={decision.body} onConfirm={onConfirm} isPending={isConfirming} />
244
+ )}
218
245
  <button
219
246
  type="button"
220
247
  onClick={onRemove}
@@ -226,10 +253,11 @@ function DecisionItem({
226
253
  {decision.rationale !== null && (
227
254
  <p className="mt-1 text-[12px] text-ink-muted">{decision.rationale}</p>
228
255
  )}
229
- <div className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-ink-faint">
256
+ <div className="mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-ink-faint">
230
257
  <span>Decided {formatDate(decision.decidedAt, timezone)}</span>
231
258
  {decision.dueAt !== null && <span>By {formatDate(decision.dueAt, timezone)}</span>}
232
259
  {ownerName !== undefined && <span>{ownerName}</span>}
260
+ <DecisionProvenance origin={decision.origin} confirmedAt={decision.confirmedAt} />
233
261
  </div>
234
262
  </li>
235
263
  )
@@ -1,5 +1,5 @@
1
1
  import type { RecordReference } from '@kelpie/schemas'
2
- import { useMemo } from 'react'
2
+ import { createContext, useContext, useMemo } from 'react'
3
3
  import Markdown from 'react-markdown'
4
4
  import type { Components } from 'react-markdown'
5
5
  import { Link } from 'react-router'
@@ -23,6 +23,13 @@ import { remarkRecordReferences } from '../lib/recordReferences.ts'
23
23
  * written by workspace members but read by everyone in the workspace, and an
24
24
  * agent with write access to the handbook is another author again.
25
25
  *
26
+ * **Nothing here loads an image.** Markdown image syntax renders as a link to
27
+ * the image, not as an `<img>`. A browser fetches an `<img>` the moment the
28
+ * page draws it, with no click, so an image URL in a note or a handbook page
29
+ * would tell another server who opened the page and when, and can carry data
30
+ * out in its query string. Kelpie has no image upload, so each image is on
31
+ * another server.
32
+ *
26
33
  * The class names are the mockup's, element for element, so a page reads the
27
34
  * same as it did before the swap.
28
35
  *
@@ -35,6 +42,28 @@ function isAppPath(href: string | undefined): href is string {
35
42
  return href !== undefined && href.startsWith('/') && !href.startsWith('//')
36
43
  }
37
44
 
45
+ /** True for what a markdown link holds. A link inside a link is not valid HTML. */
46
+ const InsideLink = createContext(false)
47
+
48
+ function ImageLink({
49
+ src,
50
+ alt,
51
+ }: {
52
+ readonly src: unknown
53
+ readonly alt: string | undefined
54
+ }): React.JSX.Element {
55
+ const insideLink = useContext(InsideLink)
56
+ const label = alt === undefined || alt === '' ? 'Image' : `Image: ${alt}`
57
+
58
+ return typeof src === 'string' && src !== '' && !insideLink ? (
59
+ <a href={src} className="text-accent hover:underline" target="_blank" rel="noreferrer">
60
+ {label}
61
+ </a>
62
+ ) : (
63
+ <span>{label}</span>
64
+ )
65
+ }
66
+
38
67
  const components: Components = {
39
68
  h1: ({ children }) => (
40
69
  <h1 className="text-[22px] font-semibold tracking-tight text-ink">{children}</h1>
@@ -56,16 +85,21 @@ const components: Components = {
56
85
  ),
57
86
  // A path inside the app stays in this tab and in the router; anything else
58
87
  // opens beside it.
59
- a: ({ href, children }) =>
60
- isAppPath(href) ? (
61
- <Link to={href} className="text-accent hover:underline">
62
- {children}
63
- </Link>
64
- ) : (
65
- <a href={href} className="text-accent hover:underline" target="_blank" rel="noreferrer">
66
- {children}
67
- </a>
68
- ),
88
+ a: ({ href, children }) => (
89
+ <InsideLink value={true}>
90
+ {isAppPath(href) ? (
91
+ <Link to={href} className="text-accent hover:underline">
92
+ {children}
93
+ </Link>
94
+ ) : (
95
+ <a href={href} className="text-accent hover:underline" target="_blank" rel="noreferrer">
96
+ {children}
97
+ </a>
98
+ )}
99
+ </InsideLink>
100
+ ),
101
+ // Never an `<img>`: see the note on images above.
102
+ img: ({ src, alt }) => <ImageLink src={src} alt={alt} />,
69
103
  hr: () => <hr className="border-border" />,
70
104
  // The wrapper scrolls rather than the page, so a wide table cannot push the
71
105
  // sidebar off screen.
@@ -8,6 +8,7 @@ import { useCreateNote, useDeleteNote, useNotes, useUpdateNote } from '../api/re
8
8
  import { formatDateTime } from '../lib/dates.ts'
9
9
  import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
10
10
  import { MarkdownView } from './MarkdownView.tsx'
11
+ import { OriginLabel } from './OriginLabel.tsx'
11
12
  import { Paginator } from './Paginator.tsx'
12
13
  import { RecordLinkTextarea } from './RecordLinkTextarea.tsx'
13
14
  import { ErrorPanel } from './QueryState.tsx'
@@ -126,10 +127,13 @@ export function NotesPanel({ targetType, targetId }: NotesPanelProps): React.JSX
126
127
  * A null author is a note written by a workspace API key, which belongs to the
127
128
  * workspace rather than to a person. An id with no matching member is one whose
128
129
  * membership was removed.
130
+ *
131
+ * A hosted AI run has no author and no key either, so it gets no name: the
132
+ * origin label beside the date says what wrote the note.
129
133
  */
130
- function authorNameFor(note: Note, nameById: ReadonlyMap<string, string>): string {
134
+ function authorNameFor(note: Note, nameById: ReadonlyMap<string, string>): string | undefined {
131
135
  if (note.authorId === null) {
132
- return 'API key'
136
+ return note.origin === 'ai' ? undefined : 'API key'
133
137
  }
134
138
 
135
139
  return nameById.get(note.authorId) ?? 'Unknown'
@@ -140,7 +144,7 @@ function NoteItem({
140
144
  authorName,
141
145
  }: {
142
146
  readonly note: Note
143
- readonly authorName: string
147
+ readonly authorName: string | undefined
144
148
  }): React.JSX.Element {
145
149
  const timezone = useTimezone()
146
150
  const updateNote = useUpdateNote()
@@ -275,10 +279,15 @@ function NoteItem({
275
279
  )}
276
280
  </div>
277
281
  </div>
278
- <div className="mt-2 flex items-center gap-2 text-[11px] text-ink-faint">
279
- <span>{authorName}</span>
280
- <span>·</span>
282
+ <div className="mt-2 flex flex-wrap items-center gap-2 text-[11px] text-ink-faint">
283
+ {authorName !== undefined && (
284
+ <>
285
+ <span>{authorName}</span>
286
+ <span>·</span>
287
+ </>
288
+ )}
281
289
  <span>{formatDateTime(note.createdAt, timezone)}</span>
290
+ <OriginLabel origin={note.origin} />
282
291
  </div>
283
292
  {deleteNote.error !== null && (
284
293
  <div className="mt-2">
@@ -0,0 +1,26 @@
1
+ import type { WriteOrigin } from '@kelpie/schemas'
2
+
3
+ import { Chip } from './Chip.tsx'
4
+
5
+ /**
6
+ * Says when a Note or a Decision was not written by a member.
7
+ *
8
+ * A member's row shows nothing: that is the ordinary case, and a label on
9
+ * every row would hide the ones that matter. A row from before origin was
10
+ * recorded (`unknown`) shows nothing either: there is nothing true to say
11
+ * about it. The server sets `origin` from the caller, so the label does not
12
+ * depend on what the text says about itself.
13
+ */
14
+
15
+ const ORIGIN_LABELS: Readonly<Record<WriteOrigin, string | null>> = {
16
+ member: null,
17
+ unknown: null,
18
+ agent: 'Written by an agent',
19
+ ai: 'Written by AI',
20
+ }
21
+
22
+ export function OriginLabel({ origin }: { readonly origin: WriteOrigin }): React.JSX.Element | null {
23
+ const label = ORIGIN_LABELS[origin]
24
+
25
+ return label === null ? null : <Chip>{label}</Chip>
26
+ }
@@ -1,8 +1,8 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
- import { Link, NavLink, Outlet, useLocation, useNavigate } from 'react-router'
2
+ import { Link, NavLink, Navigate, Outlet, useLocation, useNavigate } from 'react-router'
3
3
 
4
4
  import { useAccount, useTheme } from '../api/resources/account.ts'
5
- import { useLogOut } from '../api/resources/session.ts'
5
+ import { useLogOut, useSession } from '../api/resources/session.ts'
6
6
  import { initialsOf } from '../lib/names.ts'
7
7
  import type { ThemePreference } from '../lib/theme.ts'
8
8
  import { ONBOARDING_RERUN_ENTRY } from '../pages/onboarding/onboardingRerun.ts'
@@ -10,6 +10,7 @@ import { useNavItems } from '../registry/context.ts'
10
10
  import type { NavItem } from '../registry/contributions.ts'
11
11
  import { useVisibleNavItems } from '../registry/visibleNav.ts'
12
12
  import { AiDrawerLauncher, AiDrawerPanel, AiDrawerProvider } from './AiDrawer.tsx'
13
+ import { useRestorePersonIntake } from './personIntakeTask.tsx'
13
14
  import { ErrorBoundary } from './ErrorBoundary.tsx'
14
15
  import { WorkspaceSwitcher } from './WorkspaceSwitcher.tsx'
15
16
 
@@ -64,6 +65,7 @@ const DIRECTORY_NAV_IDS: ReadonlySet<string> = new Set(['people', 'companies'])
64
65
  const TOOLS_NAV_IDS: ReadonlySet<string> = new Set(['lists', 'forms'])
65
66
 
66
67
  const ADMIN_ENTRY_PATH = '/admin/workspace'
68
+ const AI_ENTRY_PATH = '/ai'
67
69
 
68
70
  function isAdminRoute(pathname: string): boolean {
69
71
  return pathname.startsWith('/admin/')
@@ -101,6 +103,9 @@ export function Shell(): React.JSX.Element {
101
103
  }
102
104
 
103
105
  function ShellLayout(): React.JSX.Element {
106
+ // A reload finds a person-intake run this tab started, and shows it in the
107
+ // header with the drawer closed.
108
+ useRestorePersonIntake()
104
109
  const navigate = useNavigate()
105
110
  const location = useLocation()
106
111
  const { account } = useAccount()
@@ -170,7 +175,14 @@ function ShellLayout(): React.JSX.Element {
170
175
  (item) => !DIRECTORY_NAV_IDS.has(item.id) && !TOOLS_NAV_IDS.has(item.id),
171
176
  )
172
177
  const adminItems = useVisibleNavItems(CORE_ADMIN_NAV, moduleAdminNav)
173
- const inAdminNav = isAdminRoute(location.pathname)
178
+ // Admin is for owners and admins. A member gets no link to it, and an admin
179
+ // address sends a member back to the dashboard. The check is on the path, so
180
+ // an admin page that a module adds is covered too. The API refuses the same
181
+ // work on its own; this only keeps a member off pages that cannot work.
182
+ const { session } = useSession()
183
+ const isAdmin = session?.role === 'owner' || session?.role === 'admin'
184
+ const onAdminRoute = isAdminRoute(location.pathname)
185
+ const inAdminNav = onAdminRoute && isAdmin
174
186
 
175
187
  return (
176
188
  <div className="flex min-h-screen bg-surface">
@@ -284,9 +296,16 @@ function ShellLayout(): React.JSX.Element {
284
296
  </div>
285
297
  )}
286
298
 
299
+ {/* AI is how a member connects an agent, so every member gets
300
+ the link. Admin is for owners and admins. */}
287
301
  <div className="flex flex-col gap-0.5">
288
- <NavLink to={ADMIN_ENTRY_PATH} className={linkClass}>
289
- Admin
302
+ {isAdmin && (
303
+ <NavLink to={ADMIN_ENTRY_PATH} className={linkClass}>
304
+ Admin
305
+ </NavLink>
306
+ )}
307
+ <NavLink to={AI_ENTRY_PATH} className={linkClass}>
308
+ AI
290
309
  </NavLink>
291
310
  </div>
292
311
  </>
@@ -429,7 +448,12 @@ function ShellLayout(): React.JSX.Element {
429
448
  {/* Keyed on the path so navigating away from a crashed page remounts
430
449
  the boundary instead of leaving it stuck showing the old error. */}
431
450
  <ErrorBoundary key={location.pathname}>
432
- <Outlet />
451
+ {/* Nothing shows on an admin address until the role is known. */}
452
+ {!onAdminRoute || isAdmin ? (
453
+ <Outlet />
454
+ ) : session === undefined ? null : (
455
+ <Navigate to="/dashboard" replace />
456
+ )}
433
457
  </ErrorBoundary>
434
458
  </main>
435
459
  {/* Outside the route boundary, so a page that throws does not take a
@@ -24,6 +24,12 @@ export interface AiDrawerTask {
24
24
  /** A line under the title. */
25
25
  readonly description?: string
26
26
  readonly render: (controls: AiDrawerControls) => ReactNode
27
+ /**
28
+ * Called once when the task ends: Done, Discard, or a workspace switch.
29
+ * `workspaceId` is the workspace the task belonged to. For clearing
30
+ * anything the task saved outside React state.
31
+ */
32
+ readonly onEnd?: (workspaceId: string | null) => void
27
33
  }
28
34
 
29
35
  export interface AiDrawerState {
@@ -35,6 +41,12 @@ export interface AiDrawerState {
35
41
  * one instead, says so, and returns `false`. Nothing is replaced silently.
36
42
  */
37
43
  readonly open: (task: AiDrawerTask) => boolean
44
+ /**
45
+ * Makes `task` the active task with the drawer closed, so the header button
46
+ * shows it. For a task found again after a reload. Returns `false`, and
47
+ * changes nothing, when a task is active.
48
+ */
49
+ readonly restore: (task: AiDrawerTask) => boolean
38
50
  /** Shows the active task again. */
39
51
  readonly reopen: () => void
40
52
  readonly close: () => void
@@ -1,3 +1,12 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ import { useSession } from '../api/resources/session.ts'
4
+ import {
5
+ clearOtherUsersIntakeRuns,
6
+ clearSavedIntakeRuns,
7
+ readSavedIntakeRun,
8
+ } from '../lib/personIntakeRunStorage.ts'
9
+ import { useAiDrawer } from './aiDrawerState.ts'
1
10
  import type { AiDrawerTask } from './aiDrawerState.ts'
2
11
  import { PersonIntakePanel } from './PersonIntakePanel.tsx'
3
12
 
@@ -10,5 +19,44 @@ export function personIntakeTask(): AiDrawerTask {
10
19
  title: 'Add a person from notes',
11
20
  description: 'Paste what you know. Kelpie builds the record from it.',
12
21
  render: (controls) => <PersonIntakePanel onClose={controls.finish} onPendingChange={controls.setPending} />,
22
+ // Done, Discard and a workspace switch all end the task, and none of them
23
+ // should bring it back on the next reload.
24
+ onEnd: (workspaceId) => {
25
+ if (workspaceId !== null) clearSavedIntakeRuns(workspaceId)
26
+ },
13
27
  }
14
28
  }
29
+
30
+ /**
31
+ * Finds a person-intake run this tab saved before a reload, and makes it the
32
+ * drawer's task again with the drawer closed. The header button shows it, and
33
+ * the page stays uncovered. The wizard reads the saved run when it mounts and
34
+ * picks up on the saved step.
35
+ *
36
+ * Once per workspace the session lands in, so a task the user ended is not
37
+ * brought back while the page stays loaded. A workspace counts as checked
38
+ * only once nothing is saved there or the restore took: on a switch this runs
39
+ * before the drawer ends the old workspace's task, `restore` refuses while
40
+ * that task is active, and the check runs again when the drawer is free.
41
+ *
42
+ * A saved run another user left in this tab is deleted first.
43
+ */
44
+ export function useRestorePersonIntake(): void {
45
+ const { session } = useSession()
46
+ const { restore, activeTask } = useAiDrawer()
47
+ const workspaceId = session?.workspaceId ?? null
48
+ const userId = session?.userId ?? null
49
+ const checked = useRef<string | null>(null)
50
+
51
+ useEffect(() => {
52
+ if (userId !== null) clearOtherUsersIntakeRuns(userId)
53
+ }, [userId])
54
+
55
+ useEffect(() => {
56
+ if (workspaceId === null || userId === null || checked.current === workspaceId) return
57
+
58
+ if (readSavedIntakeRun(workspaceId, userId) === undefined || restore(personIntakeTask())) {
59
+ checked.current = workspaceId
60
+ }
61
+ }, [workspaceId, userId, restore, activeTask])
62
+ }
@@ -0,0 +1,97 @@
1
+ import { personIntakeSavedRunSchema } from '@kelpie/schemas'
2
+ import type { PersonIntakeSavedRun } from '@kelpie/schemas'
3
+
4
+ /**
5
+ * The person-intake run a tab is working on, kept in `sessionStorage` so a
6
+ * reload finds it again. One entry per workspace and user, because a task
7
+ * belongs to one workspace, and the notes in it belong to the person who
8
+ * typed them: a sign-out, or another user signing in to the same tab, must
9
+ * not show them.
10
+ *
11
+ * A convenience, not a record: storage can be blocked, full or cleared, and
12
+ * every read and write here treats a failure as "no saved run". The run itself
13
+ * lives on the server, which keeps its result for an hour.
14
+ */
15
+
16
+ const KEY_PREFIX = 'kelpie.personIntake.run.'
17
+
18
+ function keyFor(workspaceId: string, userId: string): string {
19
+ return `${KEY_PREFIX}${workspaceId}.${userId}`
20
+ }
21
+
22
+ /** Every saved-run key in this tab's storage. Empty when storage cannot be read. */
23
+ function savedKeys(): string[] {
24
+ try {
25
+ const keys: string[] = []
26
+
27
+ for (let index = 0; index < sessionStorage.length; index += 1) {
28
+ const key = sessionStorage.key(index)
29
+ if (key !== null && key.startsWith(KEY_PREFIX)) keys.push(key)
30
+ }
31
+
32
+ return keys
33
+ } catch {
34
+ // Blocked storage holds nothing to clear.
35
+ return []
36
+ }
37
+ }
38
+
39
+ function removeKeys(keys: readonly string[]): void {
40
+ for (const key of keys) {
41
+ try {
42
+ sessionStorage.removeItem(key)
43
+ } catch {
44
+ // Blocked storage: nothing could have been saved either.
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * The saved run for this workspace and user, or undefined when there is none
51
+ * or it cannot be read. An entry whose `user_id` is not this user's reads as
52
+ * none.
53
+ */
54
+ export function readSavedIntakeRun(workspaceId: string, userId: string): PersonIntakeSavedRun | undefined {
55
+ let stored: string | null
56
+
57
+ try {
58
+ stored = sessionStorage.getItem(keyFor(workspaceId, userId))
59
+ } catch {
60
+ // Blocked storage (a private window, a sandboxed frame) means no saved run.
61
+ return undefined
62
+ }
63
+
64
+ if (stored === null) return undefined
65
+
66
+ try {
67
+ const parsed = personIntakeSavedRunSchema.safeParse(JSON.parse(stored))
68
+
69
+ return parsed.success && parsed.data.user_id === userId ? parsed.data : undefined
70
+ } catch {
71
+ // Not JSON: written by hand or by something else. Treat it as no saved run.
72
+ return undefined
73
+ }
74
+ }
75
+
76
+ export function saveIntakeRun(workspaceId: string, run: PersonIntakeSavedRun): void {
77
+ try {
78
+ sessionStorage.setItem(keyFor(workspaceId, run.user_id), JSON.stringify(run))
79
+ } catch {
80
+ // Not saving costs only the reload case: the task still runs in this tab.
81
+ }
82
+ }
83
+
84
+ /** Forgets the workspace's saved run, whoever saved it. */
85
+ export function clearSavedIntakeRuns(workspaceId: string): void {
86
+ removeKeys(savedKeys().filter((key) => key.startsWith(`${KEY_PREFIX}${workspaceId}.`)))
87
+ }
88
+
89
+ /** Forgets every saved run in this tab. Called on sign-out. */
90
+ export function clearAllSavedIntakeRuns(): void {
91
+ removeKeys(savedKeys())
92
+ }
93
+
94
+ /** Forgets every saved run another user left in this tab. Called when the signed-in user is known. */
95
+ export function clearOtherUsersIntakeRuns(userId: string): void {
96
+ removeKeys(savedKeys().filter((key) => !key.endsWith(`.${userId}`)))
97
+ }