@kelpie/ui 0.15.0 → 0.17.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 (287) hide show
  1. package/dist/api/client.d.ts +6 -5
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +2 -2
  4. package/dist/api/client.js.map +1 -1
  5. package/dist/api/resource.d.ts +4 -4
  6. package/dist/api/resource.d.ts.map +1 -1
  7. package/dist/api/resource.js +4 -5
  8. package/dist/api/resource.js.map +1 -1
  9. package/dist/api/resources/ai.d.ts +16 -0
  10. package/dist/api/resources/ai.d.ts.map +1 -0
  11. package/dist/api/resources/ai.js +93 -0
  12. package/dist/api/resources/ai.js.map +1 -0
  13. package/dist/api/resources/conversions.js +1 -1
  14. package/dist/api/resources/conversions.js.map +1 -1
  15. package/dist/api/resources/members.d.ts +2 -2
  16. package/dist/api/resources/oauth.d.ts +21 -0
  17. package/dist/api/resources/oauth.d.ts.map +1 -0
  18. package/dist/api/resources/oauth.js +74 -0
  19. package/dist/api/resources/oauth.js.map +1 -0
  20. package/dist/api/resources/planItems.d.ts +1 -1
  21. package/dist/api/resources/planItems.d.ts.map +1 -1
  22. package/dist/api/resources/planItems.js +1 -1
  23. package/dist/api/resources/planItems.js.map +1 -1
  24. package/dist/api/resources/session.d.ts +1 -1
  25. package/dist/api/resources/session.d.ts.map +1 -1
  26. package/dist/api/resources/session.js +4 -2
  27. package/dist/api/resources/session.js.map +1 -1
  28. package/dist/api/resources/workspace.d.ts +2 -2
  29. package/dist/api/resources/workspace.js +2 -2
  30. package/dist/app/KelpieApp.d.ts.map +1 -1
  31. package/dist/app/KelpieApp.js +3 -1
  32. package/dist/app/KelpieApp.js.map +1 -1
  33. package/dist/components/ActivitiesPanel.d.ts +7 -4
  34. package/dist/components/ActivitiesPanel.d.ts.map +1 -1
  35. package/dist/components/ActivitiesPanel.js +12 -2
  36. package/dist/components/ActivitiesPanel.js.map +1 -1
  37. package/dist/components/ActivityAction.d.ts +15 -0
  38. package/dist/components/ActivityAction.d.ts.map +1 -0
  39. package/dist/components/ActivityAction.js +20 -0
  40. package/dist/components/ActivityAction.js.map +1 -0
  41. package/dist/components/AgentTasks.d.ts +5 -0
  42. package/dist/components/AgentTasks.d.ts.map +1 -1
  43. package/dist/components/AgentTasks.js +88 -10
  44. package/dist/components/AgentTasks.js.map +1 -1
  45. package/dist/components/ApiKeysPanel.d.ts.map +1 -1
  46. package/dist/components/ApiKeysPanel.js +4 -1
  47. package/dist/components/ApiKeysPanel.js.map +1 -1
  48. package/dist/components/DecisionsPanel.d.ts.map +1 -1
  49. package/dist/components/DecisionsPanel.js +3 -1
  50. package/dist/components/DecisionsPanel.js.map +1 -1
  51. package/dist/components/LinkedText.d.ts +12 -0
  52. package/dist/components/LinkedText.d.ts.map +1 -0
  53. package/dist/components/LinkedText.js +25 -0
  54. package/dist/components/LinkedText.js.map +1 -0
  55. package/dist/components/MarkdownView.d.ts +3 -1
  56. package/dist/components/MarkdownView.d.ts.map +1 -1
  57. package/dist/components/MarkdownView.js +17 -3
  58. package/dist/components/MarkdownView.js.map +1 -1
  59. package/dist/components/NotesPanel.d.ts +2 -1
  60. package/dist/components/NotesPanel.d.ts.map +1 -1
  61. package/dist/components/NotesPanel.js +6 -7
  62. package/dist/components/NotesPanel.js.map +1 -1
  63. package/dist/components/Paginator.d.ts +1 -1
  64. package/dist/components/PlanPanel.d.ts.map +1 -1
  65. package/dist/components/PlanPanel.js +3 -1
  66. package/dist/components/PlanPanel.js.map +1 -1
  67. package/dist/components/RecordLinkTextarea.d.ts +12 -0
  68. package/dist/components/RecordLinkTextarea.d.ts.map +1 -0
  69. package/dist/components/RecordLinkTextarea.js +142 -0
  70. package/dist/components/RecordLinkTextarea.js.map +1 -0
  71. package/dist/components/Shell.js +1 -1
  72. package/dist/components/SummaryBlock.d.ts +1 -1
  73. package/dist/components/SummaryBlock.js +1 -1
  74. package/dist/components/WorkspaceSwitcher.d.ts +2 -1
  75. package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
  76. package/dist/components/WorkspaceSwitcher.js +7 -2
  77. package/dist/components/WorkspaceSwitcher.js.map +1 -1
  78. package/dist/index.d.ts +5 -2
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +6 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/lib/fragmentTarget.d.ts +18 -0
  83. package/dist/lib/fragmentTarget.d.ts.map +1 -0
  84. package/dist/lib/fragmentTarget.js +73 -0
  85. package/dist/lib/fragmentTarget.js.map +1 -0
  86. package/dist/lib/mcpConfig.d.ts +10 -0
  87. package/dist/lib/mcpConfig.d.ts.map +1 -0
  88. package/dist/lib/mcpConfig.js +23 -0
  89. package/dist/lib/mcpConfig.js.map +1 -0
  90. package/dist/lib/money.d.ts +2 -2
  91. package/dist/lib/money.js +2 -2
  92. package/dist/lib/recordLinks.d.ts +17 -0
  93. package/dist/lib/recordLinks.d.ts.map +1 -0
  94. package/dist/lib/recordLinks.js +48 -0
  95. package/dist/lib/recordLinks.js.map +1 -0
  96. package/dist/lib/recordReferences.d.ts +41 -0
  97. package/dist/lib/recordReferences.d.ts.map +1 -0
  98. package/dist/lib/recordReferences.js +92 -0
  99. package/dist/lib/recordReferences.js.map +1 -0
  100. package/dist/modules/ai.d.ts +13 -0
  101. package/dist/modules/ai.d.ts.map +1 -0
  102. package/dist/modules/ai.js +22 -0
  103. package/dist/modules/ai.js.map +1 -0
  104. package/dist/modules/aiRunner.d.ts +3 -0
  105. package/dist/modules/aiRunner.d.ts.map +1 -0
  106. package/dist/modules/aiRunner.js +66 -0
  107. package/dist/modules/aiRunner.js.map +1 -0
  108. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  109. package/dist/pages/CompanyDetail.js +2 -1
  110. package/dist/pages/CompanyDetail.js.map +1 -1
  111. package/dist/pages/DealDetail.d.ts.map +1 -1
  112. package/dist/pages/DealDetail.js +2 -1
  113. package/dist/pages/DealDetail.js.map +1 -1
  114. package/dist/pages/DealsPage.js +1 -1
  115. package/dist/pages/DealsPage.js.map +1 -1
  116. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  117. package/dist/pages/DecisionsPage.js +5 -3
  118. package/dist/pages/DecisionsPage.js.map +1 -1
  119. package/dist/pages/EnquiryDetail.d.ts.map +1 -1
  120. package/dist/pages/EnquiryDetail.js +2 -1
  121. package/dist/pages/EnquiryDetail.js.map +1 -1
  122. package/dist/pages/EventDetail.d.ts.map +1 -1
  123. package/dist/pages/EventDetail.js +2 -1
  124. package/dist/pages/EventDetail.js.map +1 -1
  125. package/dist/pages/FundraisingPage.js +1 -1
  126. package/dist/pages/FundraisingPage.js.map +1 -1
  127. package/dist/pages/OpportunitiesPage.js +1 -1
  128. package/dist/pages/OpportunitiesPage.js.map +1 -1
  129. package/dist/pages/OpportunityDetail.d.ts.map +1 -1
  130. package/dist/pages/OpportunityDetail.js +2 -1
  131. package/dist/pages/OpportunityDetail.js.map +1 -1
  132. package/dist/pages/PartnershipDetail.d.ts.map +1 -1
  133. package/dist/pages/PartnershipDetail.js +2 -1
  134. package/dist/pages/PartnershipDetail.js.map +1 -1
  135. package/dist/pages/PartnershipsPage.js +1 -1
  136. package/dist/pages/PartnershipsPage.js.map +1 -1
  137. package/dist/pages/PersonDetail.d.ts.map +1 -1
  138. package/dist/pages/PersonDetail.js +4 -3
  139. package/dist/pages/PersonDetail.js.map +1 -1
  140. package/dist/pages/RaiseDetail.d.ts.map +1 -1
  141. package/dist/pages/RaiseDetail.js +2 -1
  142. package/dist/pages/RaiseDetail.js.map +1 -1
  143. package/dist/pages/SearchPage.d.ts.map +1 -1
  144. package/dist/pages/SearchPage.js +26 -14
  145. package/dist/pages/SearchPage.js.map +1 -1
  146. package/dist/pages/account/AccountLayout.d.ts.map +1 -1
  147. package/dist/pages/account/AccountLayout.js +2 -1
  148. package/dist/pages/account/AccountLayout.js.map +1 -1
  149. package/dist/pages/account/ConnectedAppsPage.d.ts +7 -0
  150. package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -0
  151. package/dist/pages/account/ConnectedAppsPage.js +32 -0
  152. package/dist/pages/account/ConnectedAppsPage.js.map +1 -0
  153. package/dist/pages/admin/AiPage.d.ts +2 -0
  154. package/dist/pages/admin/AiPage.d.ts.map +1 -0
  155. package/dist/pages/admin/AiPage.js +134 -0
  156. package/dist/pages/admin/AiPage.js.map +1 -0
  157. package/dist/pages/admin/McpPage.d.ts.map +1 -1
  158. package/dist/pages/admin/McpPage.js +7 -15
  159. package/dist/pages/admin/McpPage.js.map +1 -1
  160. package/dist/pages/admin/ModulesPage.d.ts.map +1 -1
  161. package/dist/pages/admin/ModulesPage.js +5 -4
  162. package/dist/pages/admin/ModulesPage.js.map +1 -1
  163. package/dist/pages/admin/WorkspaceSettingsPage.d.ts +5 -6
  164. package/dist/pages/admin/WorkspaceSettingsPage.d.ts.map +1 -1
  165. package/dist/pages/admin/WorkspaceSettingsPage.js +12 -17
  166. package/dist/pages/admin/WorkspaceSettingsPage.js.map +1 -1
  167. package/dist/pages/auth/AuthLayout.d.ts +1 -1
  168. package/dist/pages/auth/AuthLayout.d.ts.map +1 -1
  169. package/dist/pages/auth/AuthLayout.js +1 -1
  170. package/dist/pages/auth/AuthLayout.js.map +1 -1
  171. package/dist/pages/auth/SignUpPage.d.ts +1 -1
  172. package/dist/pages/auth/SignUpPage.js +1 -1
  173. package/dist/pages/dashboard/attention.d.ts +0 -5
  174. package/dist/pages/dashboard/attention.d.ts.map +1 -1
  175. package/dist/pages/dashboard/attention.js +1 -21
  176. package/dist/pages/dashboard/attention.js.map +1 -1
  177. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  178. package/dist/pages/dashboard/sections.js +6 -3
  179. package/dist/pages/dashboard/sections.js.map +1 -1
  180. package/dist/pages/forms/SubmissionDetail.js +1 -1
  181. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  182. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  183. package/dist/pages/forms/SubmissionsTable.js +4 -3
  184. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  185. package/dist/pages/handbook/HandbookPage.d.ts.map +1 -1
  186. package/dist/pages/handbook/HandbookPage.js +2 -3
  187. package/dist/pages/handbook/HandbookPage.js.map +1 -1
  188. package/dist/pages/hiringDirectory.js +2 -2
  189. package/dist/pages/hiringDirectory.js.map +1 -1
  190. package/dist/pages/oauth/ConsentPage.d.ts +14 -0
  191. package/dist/pages/oauth/ConsentPage.d.ts.map +1 -0
  192. package/dist/pages/oauth/ConsentPage.js +87 -0
  193. package/dist/pages/oauth/ConsentPage.js.map +1 -0
  194. package/dist/pages/onboarding/WorkspaceStepPage.d.ts.map +1 -1
  195. package/dist/pages/onboarding/WorkspaceStepPage.js +9 -27
  196. package/dist/pages/onboarding/WorkspaceStepPage.js.map +1 -1
  197. package/dist/pages/onboarding/onboardingModules.d.ts +1 -1
  198. package/dist/pages/onboarding/onboardingRerun.d.ts +10 -1
  199. package/dist/pages/onboarding/onboardingRerun.d.ts.map +1 -1
  200. package/dist/pages/onboarding/onboardingRerun.js +12 -1
  201. package/dist/pages/onboarding/onboardingRerun.js.map +1 -1
  202. package/dist/pages/positionDirectory.js +2 -2
  203. package/dist/pages/positionDirectory.js.map +1 -1
  204. package/dist/registry/context.d.ts +3 -1
  205. package/dist/registry/context.d.ts.map +1 -1
  206. package/dist/registry/context.js +4 -0
  207. package/dist/registry/context.js.map +1 -1
  208. package/dist/registry/contributions.d.ts +39 -1
  209. package/dist/registry/contributions.d.ts.map +1 -1
  210. package/dist/registry/contributions.js +1 -1
  211. package/dist/registry/overridable.d.ts +1 -1
  212. package/dist/registry/registry.d.ts +8 -4
  213. package/dist/registry/registry.d.ts.map +1 -1
  214. package/dist/registry/registry.js +9 -1
  215. package/dist/registry/registry.js.map +1 -1
  216. package/package.json +2 -2
  217. package/src/api/client.ts +7 -6
  218. package/src/api/resource.ts +6 -7
  219. package/src/api/resources/ai.ts +110 -0
  220. package/src/api/resources/conversions.ts +1 -1
  221. package/src/api/resources/members.ts +2 -2
  222. package/src/api/resources/oauth.ts +112 -0
  223. package/src/api/resources/planItems.ts +1 -1
  224. package/src/api/resources/session.ts +4 -2
  225. package/src/api/resources/workspace.ts +4 -4
  226. package/src/app/KelpieApp.tsx +6 -0
  227. package/src/components/ActivitiesPanel.tsx +39 -10
  228. package/src/components/ActivityAction.tsx +33 -0
  229. package/src/components/AgentTasks.tsx +138 -10
  230. package/src/components/ApiKeysPanel.tsx +17 -0
  231. package/src/components/DecisionsPanel.tsx +9 -1
  232. package/src/components/LinkedText.tsx +51 -0
  233. package/src/components/MarkdownView.tsx +37 -7
  234. package/src/components/NotesPanel.tsx +18 -12
  235. package/src/components/Paginator.tsx +1 -1
  236. package/src/components/PlanPanel.tsx +9 -1
  237. package/src/components/RecordLinkTextarea.tsx +257 -0
  238. package/src/components/Shell.tsx +1 -1
  239. package/src/components/SummaryBlock.tsx +1 -1
  240. package/src/components/WorkspaceSwitcher.tsx +15 -1
  241. package/src/index.ts +10 -0
  242. package/src/lib/fragmentTarget.ts +96 -0
  243. package/src/lib/mcpConfig.ts +24 -0
  244. package/src/lib/money.ts +2 -2
  245. package/src/lib/recordLinks.ts +57 -0
  246. package/src/lib/recordReferences.ts +139 -0
  247. package/src/modules/ai.tsx +23 -0
  248. package/src/modules/aiRunner.ts +80 -0
  249. package/src/pages/CompanyDetail.tsx +2 -1
  250. package/src/pages/DealDetail.tsx +2 -1
  251. package/src/pages/DealsPage.tsx +1 -1
  252. package/src/pages/DecisionsPage.tsx +5 -3
  253. package/src/pages/EnquiryDetail.tsx +2 -1
  254. package/src/pages/EventDetail.tsx +2 -1
  255. package/src/pages/FormsPage.tsx +1 -1
  256. package/src/pages/FundraisingPage.tsx +1 -1
  257. package/src/pages/OpportunitiesPage.tsx +1 -1
  258. package/src/pages/OpportunityDetail.tsx +2 -1
  259. package/src/pages/PartnershipDetail.tsx +2 -1
  260. package/src/pages/PartnershipsPage.tsx +1 -1
  261. package/src/pages/PersonDetail.tsx +4 -3
  262. package/src/pages/RaiseDetail.tsx +2 -1
  263. package/src/pages/SearchPage.tsx +30 -15
  264. package/src/pages/account/AccountLayout.tsx +2 -1
  265. package/src/pages/account/ConnectedAppsPage.tsx +131 -0
  266. package/src/pages/admin/AiPage.tsx +353 -0
  267. package/src/pages/admin/McpPage.tsx +48 -27
  268. package/src/pages/admin/ModulesPage.tsx +5 -4
  269. package/src/pages/admin/WorkspaceSettingsPage.tsx +13 -28
  270. package/src/pages/auth/AuthLayout.tsx +1 -1
  271. package/src/pages/auth/SignUpPage.tsx +1 -1
  272. package/src/pages/dashboard/attention.ts +1 -24
  273. package/src/pages/dashboard/sections.tsx +9 -4
  274. package/src/pages/forms/SubmissionDetail.tsx +1 -1
  275. package/src/pages/forms/SubmissionsTable.tsx +4 -3
  276. package/src/pages/handbook/HandbookPage.tsx +5 -6
  277. package/src/pages/hiringDirectory.ts +2 -2
  278. package/src/pages/oauth/ConsentPage.tsx +219 -0
  279. package/src/pages/onboarding/InvitesStepPage.tsx +1 -1
  280. package/src/pages/onboarding/WorkspaceStepPage.tsx +19 -43
  281. package/src/pages/onboarding/onboardingModules.ts +1 -1
  282. package/src/pages/onboarding/onboardingRerun.ts +15 -1
  283. package/src/pages/positionDirectory.ts +2 -2
  284. package/src/registry/context.ts +6 -0
  285. package/src/registry/contributions.ts +31 -1
  286. package/src/registry/overridable.ts +1 -1
  287. package/src/registry/registry.ts +21 -3
@@ -11,6 +11,7 @@ import {
11
11
  useUpdatePlanItem,
12
12
  } from '../api/resources/planItems.ts'
13
13
  import { formatDay } from '../lib/dates.ts'
14
+ import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
14
15
  import { planStatusTone } from '../lib/plan.ts'
15
16
  import { Chip } from './Chip.tsx'
16
17
  import { Paginator } from './Paginator.tsx'
@@ -113,6 +114,7 @@ function PlanItemRow({ item }: { readonly item: PlanItem }): React.JSX.Element {
113
114
  const updateItem = useUpdatePlanItem()
114
115
  const deleteItem = useDeletePlanItem()
115
116
  const [editing, setEditing] = useState(false)
117
+ const target = useFragmentTarget<HTMLLIElement>(item.id)
116
118
 
117
119
  function save(fields: PlanFields): void {
118
120
  updateItem.run({
@@ -148,7 +150,13 @@ function PlanItemRow({ item }: { readonly item: PlanItem }): React.JSX.Element {
148
150
  }
149
151
 
150
152
  return (
151
- <li className="group flex flex-wrap items-baseline gap-x-3 gap-y-1 border-b border-border px-4 py-2.5 last:border-0">
153
+ <li
154
+ id={item.id}
155
+ ref={target.ref}
156
+ className={`group flex flex-wrap items-baseline gap-x-3 gap-y-1 border-b border-border px-4 py-2.5 transition-colors last:border-0 ${
157
+ target.highlighted ? FRAGMENT_HIGHLIGHT : ''
158
+ }`}
159
+ >
152
160
  <time dateTime={item.date} className="shrink-0 text-[12px] font-medium text-ink tabular-nums">
153
161
  {formatDay(item.date)}
154
162
  </time>
@@ -0,0 +1,257 @@
1
+ import { formatRecordLinkToken, isRecordReferenceType } from '@kelpie/schemas'
2
+ import type { RecordReferenceType } from '@kelpie/schemas'
3
+ import { useEffect, useId, useRef, useState } from 'react'
4
+ import type { KeyboardEvent } from 'react'
5
+
6
+ import { useSearch } from '../api/resources/search.ts'
7
+
8
+ /**
9
+ * A textarea that links records: type `[[` and a few letters, pick a record, and
10
+ * a `[[type:id|Label]]` token goes in where the brackets were.
11
+ *
12
+ * The choices come from `GET /v1/search`, the same public endpoint the search
13
+ * page uses, so anything search finds can be linked. `@` is not a trigger. It is
14
+ * kept for naming workspace members.
15
+ */
16
+
17
+ /** How many choices the list shows. Search ranks them, so the best come first. */
18
+ const MAX_CHOICES = 8
19
+
20
+ const TYPE_LABELS: Readonly<Partial<Record<RecordReferenceType, string>>> = {
21
+ handbook_page: 'Handbook',
22
+ person: 'Person',
23
+ role: 'Role',
24
+ company: 'Company',
25
+ enquiry: 'Enquiry',
26
+ deal: 'Deal',
27
+ opportunity: 'Opportunity',
28
+ raise: 'Raise',
29
+ partnership: 'Partnership',
30
+ event: 'Event',
31
+ decision: 'Decision',
32
+ note: 'Note',
33
+ plan_item: 'Plan item',
34
+ list: 'List',
35
+ form: 'Form',
36
+ }
37
+
38
+ interface Choice {
39
+ readonly targetType: RecordReferenceType
40
+ readonly targetId: string
41
+ readonly title: string
42
+ readonly subtitle: string | null
43
+ }
44
+
45
+ /** An open `[[`: where it starts, and what has been typed after it. */
46
+ interface Trigger {
47
+ readonly start: number
48
+ readonly query: string
49
+ }
50
+
51
+ /**
52
+ * The `[[` the caret is in, if any. A `]` or a line break after the brackets
53
+ * closes it, so finished tokens and ordinary brackets never reopen the list.
54
+ */
55
+ function openTrigger(value: string, caret: number): Trigger | null {
56
+ const before = value.slice(0, caret)
57
+ const start = before.lastIndexOf('[[')
58
+
59
+ if (start === -1) {
60
+ return null
61
+ }
62
+
63
+ const query = before.slice(start + 2)
64
+
65
+ return /[\]\n]/u.test(query) ? null : { start, query }
66
+ }
67
+
68
+ export interface RecordLinkTextareaProps {
69
+ readonly value: string
70
+ readonly onChange: (value: string) => void
71
+ readonly rows?: number
72
+ readonly placeholder?: string
73
+ readonly autoFocus?: boolean
74
+ readonly className?: string
75
+ readonly ariaLabel?: string
76
+ readonly spellCheck?: boolean
77
+ }
78
+
79
+ export function RecordLinkTextarea({
80
+ value,
81
+ onChange,
82
+ rows,
83
+ placeholder,
84
+ autoFocus,
85
+ className,
86
+ ariaLabel,
87
+ spellCheck,
88
+ }: RecordLinkTextareaProps): React.JSX.Element {
89
+ const textarea = useRef<HTMLTextAreaElement>(null)
90
+ const listId = useId()
91
+ const [caret, setCaret] = useState(0)
92
+ const [active, setActive] = useState(0)
93
+ // The `[[` the user closed with Escape. It stays closed until they type
94
+ // somewhere else, so Escape is not undone by the next keystroke.
95
+ const [dismissedAt, setDismissedAt] = useState<number | null>(null)
96
+ const [pendingCaret, setPendingCaret] = useState<number | null>(null)
97
+
98
+ const trigger = openTrigger(value, caret)
99
+ const open = trigger !== null && trigger.start !== dismissedAt
100
+ const search = useSearch(open ? trigger.query : '')
101
+
102
+ const choices: Choice[] = open
103
+ ? (search.results?.groups ?? [])
104
+ .flatMap((group): Choice[] => {
105
+ const targetType = group.collection
106
+
107
+ return isRecordReferenceType(targetType)
108
+ ? group.items.map((item) => ({
109
+ targetType,
110
+ targetId: item.id,
111
+ title: item.title,
112
+ subtitle: item.subtitle,
113
+ }))
114
+ : []
115
+ })
116
+ .slice(0, MAX_CHOICES)
117
+ : []
118
+
119
+ // Put the caret after an inserted token once React has written the new value.
120
+ useEffect(() => {
121
+ if (pendingCaret !== null && textarea.current !== null) {
122
+ textarea.current.setSelectionRange(pendingCaret, pendingCaret)
123
+ setCaret(pendingCaret)
124
+ setPendingCaret(null)
125
+ }
126
+ }, [pendingCaret, value])
127
+
128
+ function readCaret(): void {
129
+ const element = textarea.current
130
+
131
+ if (element !== null) {
132
+ setCaret(element.selectionStart)
133
+ }
134
+ }
135
+
136
+ function choose(choice: Choice): void {
137
+ if (trigger === null) {
138
+ return
139
+ }
140
+
141
+ const token = formatRecordLinkToken({
142
+ targetType: choice.targetType,
143
+ targetId: choice.targetId,
144
+ label: choice.title,
145
+ })
146
+ const next = value.slice(0, trigger.start) + token + value.slice(caret)
147
+
148
+ onChange(next)
149
+ setPendingCaret(trigger.start + token.length)
150
+ setActive(0)
151
+ }
152
+
153
+ function onKeyDown(event: KeyboardEvent<HTMLTextAreaElement>): void {
154
+ if (!open) {
155
+ return
156
+ }
157
+
158
+ if (event.key === 'Escape') {
159
+ event.preventDefault()
160
+ setDismissedAt(trigger.start)
161
+
162
+ return
163
+ }
164
+
165
+ if (choices.length === 0) {
166
+ return
167
+ }
168
+
169
+ if (event.key === 'ArrowDown') {
170
+ event.preventDefault()
171
+ setActive((current) => (current + 1) % choices.length)
172
+ } else if (event.key === 'ArrowUp') {
173
+ event.preventDefault()
174
+ setActive((current) => (current - 1 + choices.length) % choices.length)
175
+ } else if (event.key === 'Enter' || event.key === 'Tab') {
176
+ const choice = choices[Math.min(active, choices.length - 1)]
177
+
178
+ if (choice !== undefined) {
179
+ event.preventDefault()
180
+ choose(choice)
181
+ }
182
+ }
183
+ }
184
+
185
+ const activeChoice = open && choices.length > 0 ? Math.min(active, choices.length - 1) : null
186
+
187
+ return (
188
+ <div className="relative">
189
+ <textarea
190
+ ref={textarea}
191
+ value={value}
192
+ onChange={(event) => {
193
+ onChange(event.target.value)
194
+ setCaret(event.target.selectionStart)
195
+ setActive(0)
196
+ }}
197
+ onKeyDown={onKeyDown}
198
+ onKeyUp={readCaret}
199
+ onClick={readCaret}
200
+ onSelect={readCaret}
201
+ rows={rows}
202
+ placeholder={placeholder}
203
+ autoFocus={autoFocus}
204
+ className={className}
205
+ aria-label={ariaLabel}
206
+ spellCheck={spellCheck}
207
+ role="combobox"
208
+ aria-autocomplete="list"
209
+ aria-expanded={open}
210
+ aria-controls={listId}
211
+ aria-activedescendant={activeChoice === null ? undefined : `${listId}-${String(activeChoice)}`}
212
+ />
213
+ {open && (
214
+ <div
215
+ id={listId}
216
+ role="listbox"
217
+ aria-label="Link a record"
218
+ className="absolute right-0 left-0 z-20 mt-1 max-h-64 overflow-y-auto rounded-md border border-border bg-surface-raised py-1 shadow-lg"
219
+ >
220
+ {trigger.query.trim().length === 0 ? (
221
+ <p className="px-3 py-1.5 text-[12px] text-ink-faint">Type to find a record to link</p>
222
+ ) : search.isLoading ? (
223
+ <p className="px-3 py-1.5 text-[12px] text-ink-faint">Searching…</p>
224
+ ) : choices.length === 0 ? (
225
+ <p className="px-3 py-1.5 text-[12px] text-ink-faint">No records match</p>
226
+ ) : (
227
+ choices.map((choice, index) => (
228
+ <div
229
+ key={`${choice.targetType}:${choice.targetId}`}
230
+ id={`${listId}-${String(index)}`}
231
+ role="option"
232
+ aria-selected={index === activeChoice}
233
+ // mousedown, not click: a click would blur the textarea first.
234
+ onMouseDown={(event) => {
235
+ event.preventDefault()
236
+ choose(choice)
237
+ }}
238
+ onMouseEnter={() => {
239
+ setActive(index)
240
+ }}
241
+ className={`flex cursor-pointer items-baseline gap-2 px-3 py-1.5 text-[13px] ${
242
+ index === activeChoice ? 'bg-surface-sunken' : ''
243
+ }`}
244
+ >
245
+ <span className="truncate text-ink">{choice.title}</span>
246
+ <span className="shrink-0 text-[11px] text-ink-faint">
247
+ {TYPE_LABELS[choice.targetType] ?? choice.targetType}
248
+ {choice.subtitle === null ? '' : ` · ${choice.subtitle}`}
249
+ </span>
250
+ </div>
251
+ ))
252
+ )}
253
+ </div>
254
+ )}
255
+ </div>
256
+ )
257
+ }
@@ -52,7 +52,7 @@ const CORE_NAV: readonly NavItem[] = [
52
52
  ]
53
53
 
54
54
  /**
55
- * `nav.primary` is one flat slot (`modules.md`); the shell renders it as visual
55
+ * `nav.primary` is one flat slot; the shell renders it as visual
56
56
  * groups: an unheaded top section, an unheaded directory pair (People,
57
57
  * Companies), a headed "CRM" section for pipeline objects, then a headed
58
58
  * "Tools" section for Lists and Forms. Presentation only — it stays here rather
@@ -9,7 +9,7 @@ export interface SummaryBlockProps {
9
9
  * The agent-facing summary, at the top of a record's overview.
10
10
  *
11
11
  * It sits above everything else because it is the field an agent reads first;
12
- * `brief.md` makes it a record field rather than something buried in notes.
12
+ * it is a record field rather than something buried in notes.
13
13
  */
14
14
  export function SummaryBlock({ value, onChange }: SummaryBlockProps): React.JSX.Element {
15
15
  return (
@@ -2,12 +2,14 @@ import { useEffect, useRef, useState } from 'react'
2
2
  import { useNavigate } from 'react-router'
3
3
 
4
4
  import { useAccountWorkspaces, useSession, useSwitchWorkspace } from '../api/resources/session.ts'
5
+ import { ONBOARDING_NEW_WORKSPACE_ENTRY } from '../pages/onboarding/onboardingRerun.ts'
5
6
 
6
7
  /**
7
8
  * Header control: the workspace this session is in, and a menu to move it.
8
9
  *
9
10
  * The list and the switch both live under `/v1/auth`, so a suspended current
10
- * workspace still lets the reader see the other memberships and leave.
11
+ * workspace still lets the reader see the other memberships and leave. The
12
+ * last item opens the create form for another workspace.
11
13
  */
12
14
 
13
15
  export function WorkspaceSwitcher(): React.JSX.Element | null {
@@ -124,6 +126,18 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
124
126
  </button>
125
127
  )
126
128
  })}
129
+ <button
130
+ type="button"
131
+ role="menuitem"
132
+ disabled={switchWorkspace.isPending}
133
+ onClick={() => {
134
+ setOpen(false)
135
+ void navigate(ONBOARDING_NEW_WORKSPACE_ENTRY)
136
+ }}
137
+ className="mt-1 block w-full border-t border-border px-3 py-1.5 pt-2 text-left text-[13px] text-ink hover:bg-surface-sunken disabled:opacity-60"
138
+ >
139
+ New workspace
140
+ </button>
127
141
  {switchWorkspace.error !== null && (
128
142
  <p className="border-t border-border px-3 py-1.5 text-[12px] text-danger">
129
143
  {switchWorkspace.error.message}
package/src/index.ts CHANGED
@@ -208,6 +208,9 @@ export type { ThemePreference } from './lib/theme.ts'
208
208
 
209
209
  export { EXTENSIBLE_RECORD_TYPES, NAV_SLOTS } from './registry/contributions.ts'
210
210
  export type {
211
+ AgentRunner,
212
+ AgentRunnerAvailability,
213
+ AgentRunnerProgress,
211
214
  AuthMethod,
212
215
  AuthMethodContext,
213
216
  DashboardCard,
@@ -227,6 +230,7 @@ export { NO_UI_MODULES, UiModuleError, inSlotOrder, registerUiModules } from './
227
230
  export type { UiExtensions, UiModule, UiModuleContext } from './registry/registry.ts'
228
231
 
229
232
  export {
233
+ useAgentRunner,
230
234
  useAuthMethods,
231
235
  useDashboardCards,
232
236
  useModuleRoutes,
@@ -239,3 +243,9 @@ export {
239
243
 
240
244
  export { UiExtensionProvider } from './registry/UiExtensionProvider.tsx'
241
245
  export type { UiExtensionProviderProps } from './registry/UiExtensionProvider.tsx'
246
+
247
+ // The optional `ai` module's UI. An assembly that lists `createAiModule()` on
248
+ // the server lists `aiUi` in its `uiModules`.
249
+ export { aiUi } from './modules/ai.tsx'
250
+ export { AiPage } from './pages/admin/AiPage.tsx'
251
+ export { useAiRuns, useAiSettings, useDisableAi, useSaveAiSettings } from './api/resources/ai.ts'
@@ -0,0 +1,96 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import type { RefObject } from 'react'
3
+ import { useLocation } from 'react-router'
4
+
5
+ /**
6
+ * A row a link can point at: `/companies/com_1#note_1` opens the company and
7
+ * brings note `note_1` into view.
8
+ *
9
+ * Notes, Decisions and Plan items have no page of their own, so a link to one
10
+ * opens the record it is on with the item's id as the fragment. The row whose id
11
+ * matches scrolls to the middle of the screen and is highlighted for a moment, so
12
+ * the reader sees which one was meant. A row on a later page of its panel is not
13
+ * on screen, and nothing happens.
14
+ */
15
+
16
+ /** How long the highlight stays, in milliseconds. */
17
+ const HIGHLIGHT_MS = 2000
18
+
19
+ export interface FragmentTarget<T extends HTMLElement> {
20
+ readonly ref: RefObject<T | null>
21
+ readonly highlighted: boolean
22
+ }
23
+
24
+ export function useFragmentTarget<T extends HTMLElement>(id: string): FragmentTarget<T> {
25
+ const { hash } = useLocation()
26
+ const ref = useRef<T>(null)
27
+ const [highlighted, setHighlighted] = useState(false)
28
+ const targeted = hash === `#${id}`
29
+
30
+ useEffect(() => {
31
+ if (!targeted) {
32
+ return undefined
33
+ }
34
+
35
+ const element = ref.current
36
+
37
+ // jsdom has no layout, and so no `scrollIntoView`.
38
+ if (element !== null && typeof element.scrollIntoView === 'function') {
39
+ element.scrollIntoView({ block: 'center', behavior: 'smooth' })
40
+ }
41
+
42
+ setHighlighted(true)
43
+
44
+ const timer = window.setTimeout(() => {
45
+ setHighlighted(false)
46
+ }, HIGHLIGHT_MS)
47
+
48
+ return () => {
49
+ window.clearTimeout(timer)
50
+ }
51
+ }, [targeted])
52
+
53
+ return { ref, highlighted }
54
+ }
55
+
56
+ /**
57
+ * The detail-page tab that holds a row with this id prefix. Every record page
58
+ * names these three tabs the same.
59
+ */
60
+ const TAB_BY_PREFIX: readonly (readonly [string, string])[] = [
61
+ ['note_', 'notes'],
62
+ ['dec_', 'decisions'],
63
+ ['plan_', 'plan'],
64
+ ]
65
+
66
+ function tabForHash(hash: string): string | undefined {
67
+ const id = hash.startsWith('#') ? hash.slice(1) : hash
68
+
69
+ return TAB_BY_PREFIX.find(([prefix]) => id.startsWith(prefix))?.[1]
70
+ }
71
+
72
+ /**
73
+ * A detail page's active tab, opened on the tab a fragment points into.
74
+ *
75
+ * `/companies/com_1#note_1` must land on Notes, or the row it names is not on
76
+ * screen to scroll to. The fragment picks the tab on the first render and again
77
+ * whenever it changes, so a link to another note on the same page switches too.
78
+ * Anything else starts on Overview, and a click on a tab still wins.
79
+ */
80
+ export function useRecordTab(): readonly [string, (tab: string) => void] {
81
+ const { hash } = useLocation()
82
+ const [tab, setTab] = useState(() => tabForHash(hash) ?? 'overview')
83
+
84
+ useEffect(() => {
85
+ const fromHash = tabForHash(hash)
86
+
87
+ if (fromHash !== undefined) {
88
+ setTab(fromHash)
89
+ }
90
+ }, [hash])
91
+
92
+ return [tab, setTab]
93
+ }
94
+
95
+ /** The classes a highlighted row adds. */
96
+ export const FRAGMENT_HIGHLIGHT = 'bg-accent-soft/40 ring-2 ring-accent/40'
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How an MCP client reaches this workspace.
3
+ *
4
+ * The endpoint comes from the origin the browser reached the app on, so it is
5
+ * right for a self-hosted install on any hostname. The MCP page shows the config
6
+ * with a placeholder token; a freshly minted API key shows it with the real one.
7
+ */
8
+
9
+ export function mcpEndpoint(): string {
10
+ return new URL('/mcp', window.location.origin).toString()
11
+ }
12
+
13
+ export function mcpClientConfig(endpoint: string, bearerToken: string): string {
14
+ return `{
15
+ "mcpServers": {
16
+ "kelpie": {
17
+ "url": "${endpoint}",
18
+ "headers": {
19
+ "Authorization": "Bearer ${bearerToken}"
20
+ }
21
+ }
22
+ }
23
+ }`
24
+ }
package/src/lib/money.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * How the app writes a deal's value. `api.md` stores money as integer cents plus
3
- * an ISO 4217 code; the board and the sidebar both render whole units, as the
2
+ * How the app writes a deal's value. The API stores money as integer cents plus
3
+ * an ISO 4217 code (`docs/agents/api-and-webhooks.md`); the board and the sidebar both render whole units, as the
4
4
  * mockup did.
5
5
  */
6
6
  export function formatMoney(valueCents: number, currency: string | null): string {
@@ -0,0 +1,57 @@
1
+ import type { RecordReference, RecordReferenceType, RecordTargetType } from '@kelpie/schemas'
2
+
3
+ /**
4
+ * Where each kind of record lives. A Candidate has no page of its own: it is
5
+ * reached through its Role. An Attendance is reached through its Event. A Note,
6
+ * Decision or Plan item is reached on the page of the record it is on; see
7
+ * `attachedHref`.
8
+ */
9
+ const ROUTES: Readonly<Record<RecordReferenceType, string | undefined>> = {
10
+ person: '/people',
11
+ company: '/companies',
12
+ deal: '/deals',
13
+ opportunity: '/opportunities',
14
+ partnership: '/partnerships',
15
+ raise: '/fundraising',
16
+ enquiry: '/enquiries',
17
+ candidate: undefined,
18
+ event: '/events',
19
+ attendance: undefined,
20
+ role: '/hiring',
21
+ handbook_page: '/handbook',
22
+ list: '/lists',
23
+ form: '/forms',
24
+ note: undefined,
25
+ decision: undefined,
26
+ plan_item: undefined,
27
+ }
28
+
29
+ /**
30
+ * @returns The record's page, or undefined when it has none. A row without a
31
+ * link renders as plain text rather than as a link to nowhere.
32
+ */
33
+ export function targetHref(targetType: RecordReferenceType, targetId: string): string | undefined {
34
+ const route = ROUTES[targetType]
35
+
36
+ return route === undefined ? undefined : `${route}/${targetId}`
37
+ }
38
+
39
+ /**
40
+ * A Note, Decision or Plan item: the page of the record it is on, with its own
41
+ * id as the fragment, which the panel on that page scrolls to and highlights.
42
+ */
43
+ export function attachedHref(
44
+ id: string,
45
+ parent: { readonly type: RecordTargetType; readonly id: string },
46
+ ): string | undefined {
47
+ const page = targetHref(parent.type, parent.id)
48
+
49
+ return page === undefined ? undefined : `${page}#${id}`
50
+ }
51
+
52
+ /** Where a cited record opens, or undefined when it has nowhere to open. */
53
+ export function referenceHref(reference: RecordReference): string | undefined {
54
+ return reference.parent === null
55
+ ? targetHref(reference.targetType, reference.targetId)
56
+ : attachedHref(reference.targetId, reference.parent)
57
+ }