@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
@@ -0,0 +1,139 @@
1
+ import { splitRecordLinkTokens } from '@kelpie/schemas'
2
+ import type { RecordLinkToken, RecordReference } from '@kelpie/schemas'
3
+ import type { Link, Parent, PhrasingContent, Root, Text } from 'mdast'
4
+
5
+ import { referenceHref } from './recordLinks.ts'
6
+
7
+ /**
8
+ * Turning the record ids a text cites into something a person can follow.
9
+ *
10
+ * The server already found the ids and named them (`references` on an activity
11
+ * or a note). This side only finds each named id in the text by string match.
12
+ * An id the server did not name stays as it is: it is not a record in this
13
+ * workspace, and a link to it would go nowhere.
14
+ *
15
+ * Text cites a record in two ways, and one pass reads both. A `[[type:id|Label]]`
16
+ * link token is read first, so the id inside it is never matched a second time as
17
+ * a bare id. The text between tokens is then searched for bare ids. A token the
18
+ * server named shows the record's current name; one it did not name shows the
19
+ * token's label as plain text, because the record is gone.
20
+ */
21
+
22
+ export type TextSegment =
23
+ | { readonly kind: 'text'; readonly text: string }
24
+ | { readonly kind: 'reference'; readonly reference: RecordReference }
25
+ | { readonly kind: 'unresolved'; readonly token: RecordLinkToken }
26
+
27
+ /** What an unresolved token shows: its label, or its id when it has none. */
28
+ export function unresolvedLabel(token: RecordLinkToken): string {
29
+ return token.label ?? token.targetId
30
+ }
31
+
32
+ function escapeForPattern(value: string): string {
33
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
34
+ }
35
+
36
+ /**
37
+ * `text` cut into plain runs and cited records, in order.
38
+ *
39
+ * @returns One text segment holding all of `text` when nothing is cited.
40
+ */
41
+ export function splitOnReferences(
42
+ text: string,
43
+ references: readonly RecordReference[],
44
+ ): readonly TextSegment[] {
45
+ const byTokenId = new Map(references.map((reference) => [reference.targetId, reference]))
46
+
47
+ return splitRecordLinkTokens(text).flatMap((segment): readonly TextSegment[] => {
48
+ if (segment.kind === 'text') {
49
+ return splitOnBareIds(segment.text, references)
50
+ }
51
+
52
+ const reference = byTokenId.get(segment.token.targetId)
53
+
54
+ return reference === undefined
55
+ ? [{ kind: 'unresolved', token: segment.token }]
56
+ : [{ kind: 'reference', reference }]
57
+ })
58
+ }
59
+
60
+ /** Bare ids only. Every segment it returns is `text` or `reference`. */
61
+ function splitOnBareIds(text: string, references: readonly RecordReference[]): TextSegment[] {
62
+ if (references.length === 0) {
63
+ return text.length === 0 ? [] : [{ kind: 'text', text }]
64
+ }
65
+
66
+ const byId = new Map(references.map((reference) => [reference.targetId, reference]))
67
+ // Longest first, so an id can never lose to a shorter one it starts with.
68
+ const ids = [...byId.keys()].sort((left, right) => right.length - left.length)
69
+ const pattern = new RegExp(`(${ids.map(escapeForPattern).join('|')})`)
70
+ const segments: TextSegment[] = []
71
+
72
+ // `split` with one capture group puts each match at an odd index.
73
+ text.split(pattern).forEach((part, index) => {
74
+ const reference = index % 2 === 1 ? byId.get(part) : undefined
75
+
76
+ if (reference !== undefined) {
77
+ segments.push({ kind: 'reference', reference })
78
+ } else if (part.length > 0) {
79
+ segments.push({ kind: 'text', text: part })
80
+ }
81
+ })
82
+
83
+ return segments
84
+ }
85
+
86
+ /** A cited record as a Markdown node: a link to its page, or its name when it has none. */
87
+ function referenceNode(reference: RecordReference): Link | Text {
88
+ const href = referenceHref(reference)
89
+ const name: Text = { type: 'text', value: reference.name }
90
+
91
+ return href === undefined ? name : { type: 'link', url: href, title: null, children: [name] }
92
+ }
93
+
94
+ /** Node types whose text must stay as written: a link cannot hold a link, and code is literal. */
95
+ const LEAVE_ALONE = new Set(['link', 'linkReference', 'code', 'inlineCode'])
96
+
97
+ function isParent(node: { readonly type: string }): node is Parent {
98
+ return 'children' in node && Array.isArray(node.children)
99
+ }
100
+
101
+ function rewriteChildren(parent: Parent, references: readonly RecordReference[]): void {
102
+ const rewritten: Parent['children'] = []
103
+
104
+ for (const child of parent.children) {
105
+ if (child.type === 'text') {
106
+ for (const segment of splitOnReferences(child.value, references)) {
107
+ rewritten.push(
108
+ segment.kind === 'text'
109
+ ? ({ type: 'text', value: segment.text } satisfies PhrasingContent)
110
+ : segment.kind === 'reference'
111
+ ? referenceNode(segment.reference)
112
+ : ({ type: 'text', value: unresolvedLabel(segment.token) } satisfies PhrasingContent),
113
+ )
114
+ }
115
+ } else {
116
+ if (isParent(child) && !LEAVE_ALONE.has(child.type)) {
117
+ rewriteChildren(child, references)
118
+ }
119
+
120
+ rewritten.push(child)
121
+ }
122
+ }
123
+
124
+ parent.children = rewritten
125
+ }
126
+
127
+ /**
128
+ * A remark plugin: every cited record in the Markdown's text, bare id or link
129
+ * token, becomes a link to the record, labelled with its name. The source string
130
+ * is not touched, so what the author wrote is still what is stored and edited.
131
+ */
132
+ export function remarkRecordReferences(
133
+ references: readonly RecordReference[],
134
+ ): () => (tree: Root) => void {
135
+ // Runs even with no references: a token must still lose its brackets.
136
+ return () => (tree) => {
137
+ rewriteChildren(tree, references)
138
+ }
139
+ }
@@ -0,0 +1,23 @@
1
+ import { AiPage } from '../pages/admin/AiPage.tsx'
2
+ import type { UiModule } from '../registry/registry.ts'
3
+ import { aiRunner } from './aiRunner.ts'
4
+
5
+ /**
6
+ * The UI half of the optional `ai` module in `@kelpie/server`.
7
+ *
8
+ * Not registered by default. An assembly that lists `createAiModule()` on the
9
+ * server lists `aiUi` in `kelpie.ui.config.ts`, the same pairing any module
10
+ * uses. One Admin nav item, after MCP, and one page. On record pages it is the
11
+ * Agent menu's runner: Run dispatches straight to the "Kelpie AI" agent row, and
12
+ * stays disabled until AI is enabled and has a key. Preview's Run… still lists
13
+ * every registered agent, Kelpie AI included.
14
+ */
15
+ export const aiUi: UiModule = {
16
+ id: 'ai',
17
+
18
+ register(context) {
19
+ context.nav('admin', { id: 'ai', label: 'AI', to: '/admin/ai', order: 550 })
20
+ context.route({ path: 'admin/ai', element: <AiPage /> })
21
+ context.agentRunner(aiRunner)
22
+ },
23
+ }
@@ -0,0 +1,80 @@
1
+ import { ApiError } from '../api/client.ts'
2
+ import { useAiRunForAgentRun, useAiSettings } from '../api/resources/ai.ts'
3
+ import { useAgents } from '../api/resources/agentTasks.ts'
4
+ import type { AgentRunner, AgentRunnerAvailability, AgentRunnerProgress } from '../registry/contributions.ts'
5
+
6
+ /** The `managed_by` value the server module writes on its agent row. */
7
+ const AI_MODULE_ID = 'ai'
8
+
9
+ /**
10
+ * Kelpie AI as the Agent menu's runner.
11
+ *
12
+ * Ready only when the workspace can run a task now: the module answers (so it
13
+ * is in the assembly and switched on), AI is enabled, a provider and key are
14
+ * available (the workspace's own, or the deployment's), and the agent row the
15
+ * module manages exists to dispatch to.
16
+ */
17
+ function useAvailability(options: { readonly enabled: boolean }): AgentRunnerAvailability {
18
+ const settings = useAiSettings({ enabled: options.enabled })
19
+ const agents = useAgents({ enabled: options.enabled })
20
+
21
+ if (settings.isLoading || agents.isLoading || !options.enabled) {
22
+ return { status: 'loading' }
23
+ }
24
+
25
+ if (settings.error !== null) {
26
+ // The runtime answers 403 or 404 when the module is switched off.
27
+ return settings.error instanceof ApiError && (settings.error.status === 403 || settings.error.status === 404)
28
+ ? { status: 'unavailable', reason: 'Kelpie AI is switched off for this workspace.' }
29
+ : { status: 'unavailable', reason: 'Kelpie AI settings could not be read.' }
30
+ }
31
+
32
+ const record = settings.record
33
+
34
+ if (record === undefined || !record.enabled) {
35
+ return { status: 'unavailable', reason: 'Kelpie AI is not enabled. An admin can enable it under Admin → AI.' }
36
+ }
37
+
38
+ if (!record.configured) {
39
+ return {
40
+ status: 'unavailable',
41
+ reason: 'Kelpie AI has no provider key. An admin can add one under Admin → AI.',
42
+ }
43
+ }
44
+
45
+ const agent = agents.records.find((candidate) => candidate.managedBy === AI_MODULE_ID)
46
+
47
+ if (agent === undefined) {
48
+ return {
49
+ status: 'unavailable',
50
+ reason: 'The Kelpie AI agent is missing. An admin can save Admin → AI again to restore it.',
51
+ }
52
+ }
53
+
54
+ return { status: 'ready', agentId: agent.id }
55
+ }
56
+
57
+ function useProgress(agentRunId: string | undefined): AgentRunnerProgress | undefined {
58
+ const run = useAiRunForAgentRun(agentRunId)
59
+
60
+ if (agentRunId === undefined) {
61
+ return undefined
62
+ }
63
+
64
+ switch (run?.status) {
65
+ case 'succeeded':
66
+ return { status: 'succeeded' }
67
+ case 'failed':
68
+ return { status: 'failed', reason: run.failureReason ?? 'no reason recorded' }
69
+ case 'queued':
70
+ case 'running':
71
+ case undefined:
72
+ return { status: 'running' }
73
+ }
74
+ }
75
+
76
+ export const aiRunner: AgentRunner = {
77
+ id: AI_MODULE_ID,
78
+ useAvailability,
79
+ useProgress,
80
+ }
@@ -56,6 +56,7 @@ import { SidebarField } from '../components/SidebarField.tsx'
56
56
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
57
57
  import { useRecordTabs } from '../registry/context.ts'
58
58
  import { inSlotOrder } from '../registry/registry.ts'
59
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
59
60
  import { toOptions, toTags } from './fields.ts'
60
61
 
61
62
  /**
@@ -87,7 +88,7 @@ export function CompanyDetail(): React.JSX.Element {
87
88
  const moduleTabs = inSlotOrder(useRecordTabs('company'))
88
89
  const hasCustomFields = useHasCustomFields('company')
89
90
  const eventsEnabled = useModuleEnabled('events')
90
- const [activeTab, setActiveTab] = useState('overview')
91
+ const [activeTab, setActiveTab] = useRecordTab()
91
92
  const formSubmissions = useFormSubmissionsForRecord('company', id)
92
93
 
93
94
  if (isNotFound) {
@@ -42,6 +42,7 @@ import { SidebarField } from '../components/SidebarField.tsx'
42
42
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
43
43
  import { formatDay } from '../lib/dates.ts'
44
44
  import { formatMoney } from '../lib/money.ts'
45
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
45
46
  import { useRecordTabs } from '../registry/context.ts'
46
47
  import { inSlotOrder } from '../registry/registry.ts'
47
48
  import { toTags } from './fields.ts'
@@ -68,7 +69,7 @@ export function DealDetail(): React.JSX.Element {
68
69
  const moduleTabs = inSlotOrder(useRecordTabs('deal'))
69
70
  const hasCustomFields = useHasCustomFields('deal')
70
71
  const eventsEnabled = useModuleEnabled('events')
71
- const [activeTab, setActiveTab] = useState('overview')
72
+ const [activeTab, setActiveTab] = useRecordTab()
72
73
  const [showConvert, setShowConvert] = useState(false)
73
74
  const formSubmissions = useFormSubmissionsForRecord('deal', id)
74
75
 
@@ -113,7 +113,7 @@ export function DealsPage(): React.JSX.Element {
113
113
  const visibleDeals = deals.records.filter((deal) => visibleStageIds.has(deal.stageId))
114
114
 
115
115
  // The next-step column asks about the deals on screen by id. `?target_id=`
116
- // takes at most one page of them (`api.md`), so past that ceiling the rest
116
+ // takes at most one page of them (`docs/agents/api-and-webhooks.md`), so past that ceiling the rest
117
117
  // read as having no plan; the note under the table says so.
118
118
  const askedDealIds = visibleDeals.slice(0, MAX_PAGE_SIZE).map((deal) => deal.id)
119
119
  const planItems = usePlanItems(
@@ -29,13 +29,15 @@ import { useListView } from '../lib/listView.ts'
29
29
  * matches target names the loaded page may not even hold.
30
30
  *
31
31
  * The "Linked to" column joins client-side against one page each of people,
32
- * companies, deals, opportunities, raises and partnerships, because `api.md`
33
- * has no include-expansion and no list takes a set of bare ids. A target past
32
+ * companies, deals, opportunities, raises and partnerships, because the API
33
+ * has no include-expansion. The repeatable id filters (`?person_id=`,
34
+ * `?company_id=`, …) match a foreign key; no list filters on its own `?id=`,
35
+ * so there is no way to fetch just the targets by id. A target past
34
36
  * those pages, or one whose type has no page yet (candidate), names its record
35
37
  * type instead — better than a raw id or a link to a route that does not exist.
36
38
  */
37
39
 
38
- /** `api.md`: `?limit=` maxes out at 200. */
40
+ /** `?limit=` maxes out at 200 (`docs/agents/api-and-webhooks.md`). */
39
41
  const MAX_PAGE = 200
40
42
 
41
43
  const TARGET_LABELS: Readonly<Record<RecordTargetType, string>> = {
@@ -46,6 +46,7 @@ import { SidebarField } from '../components/SidebarField.tsx'
46
46
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
47
  import { useRecordTabs } from '../registry/context.ts'
48
48
  import { inSlotOrder } from '../registry/registry.ts'
49
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
49
50
  import { toTags } from './fields.ts'
50
51
 
51
52
  /**
@@ -71,7 +72,7 @@ export function EnquiryDetail(): React.JSX.Element {
71
72
  const moduleTabs = inSlotOrder(useRecordTabs('enquiry'))
72
73
  const hasCustomFields = useHasCustomFields('enquiry')
73
74
  const eventsEnabled = useModuleEnabled('events')
74
- const [activeTab, setActiveTab] = useState('overview')
75
+ const [activeTab, setActiveTab] = useRecordTab()
75
76
  const [showConvert, setShowConvert] = useState(false)
76
77
  const formSubmissions = useFormSubmissionsForRecord('enquiry', id)
77
78
 
@@ -64,6 +64,7 @@ import { SidebarField } from '../components/SidebarField.tsx'
64
64
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
65
65
  import { TimezoneSearch } from '../components/TimezoneSearch.tsx'
66
66
  import { formatDateTime } from '../lib/dates.ts'
67
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
67
68
  import { useRecordTabs } from '../registry/context.ts'
68
69
  import { inSlotOrder } from '../registry/registry.ts'
69
70
  import { toTags } from './fields.ts'
@@ -106,7 +107,7 @@ export function EventDetail(): React.JSX.Element {
106
107
  const deleteEvent = useDeleteEvent()
107
108
  const moduleTabs = inSlotOrder(useRecordTabs('event'))
108
109
  const hasCustomFields = useHasCustomFields('event')
109
- const [activeTab, setActiveTab] = useState('overview')
110
+ const [activeTab, setActiveTab] = useRecordTab()
110
111
 
111
112
  if (isNotFound) {
112
113
  return <NotFoundPanel label="Event" backTo="/events" />
@@ -24,7 +24,7 @@ import { CONTACT_FORM_FIELDS } from './forms/template.ts'
24
24
  * loaded array, so they match forms this page has not paged to yet.
25
25
  *
26
26
  * There is no submissions count column. The mockup had one because its seed data
27
- * was a local array; here it would be one request per row, and `api.md` has no
27
+ * was a local array; here it would be one request per row, and the API has no
28
28
  * expansion to fold that into the list. The count lives on the detail page,
29
29
  * where the submissions are already being fetched.
30
30
  */
@@ -109,7 +109,7 @@ export function FundraisingPage(): React.JSX.Element {
109
109
  const visibleRaises = raises.records.filter((raise) => visibleStageIds.has(raise.stageId))
110
110
 
111
111
  // The next-step column asks about the records on screen by id. `?target_id=`
112
- // takes at most one page of them (`api.md`), so past that ceiling the rest
112
+ // takes at most one page of them (`docs/agents/api-and-webhooks.md`), so past that ceiling the rest
113
113
  // read as having no plan; the note under the table says so.
114
114
  const askedIds = visibleRaises.slice(0, MAX_PAGE_SIZE).map((raise) => raise.id)
115
115
  const planItems = usePlanItems(
@@ -109,7 +109,7 @@ export function OpportunitiesPage(): React.JSX.Element {
109
109
  )
110
110
 
111
111
  // The next-step column asks about the records on screen by id. `?target_id=`
112
- // takes at most one page of them (`api.md`), so past that ceiling the rest
112
+ // takes at most one page of them (`docs/agents/api-and-webhooks.md`), so past that ceiling the rest
113
113
  // read as having no plan; the note under the table says so.
114
114
  const askedIds = visibleOpportunities.slice(0, MAX_PAGE_SIZE).map((opportunity) => opportunity.id)
115
115
  const planItems = usePlanItems(
@@ -45,6 +45,7 @@ import { SectionHeader } from '../components/SectionHeader.tsx'
45
45
  import { SidebarField } from '../components/SidebarField.tsx'
46
46
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
47
  import { formatDay } from '../lib/dates.ts'
48
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
48
49
  import { useRecordTabs } from '../registry/context.ts'
49
50
  import { inSlotOrder } from '../registry/registry.ts'
50
51
  import { toTags } from './fields.ts'
@@ -73,7 +74,7 @@ export function OpportunityDetail(): React.JSX.Element {
73
74
  const moduleTabs = inSlotOrder(useRecordTabs('opportunity'))
74
75
  const hasCustomFields = useHasCustomFields('opportunity')
75
76
  const eventsEnabled = useModuleEnabled('events')
76
- const [activeTab, setActiveTab] = useState('overview')
77
+ const [activeTab, setActiveTab] = useRecordTab()
77
78
  const [showConvert, setShowConvert] = useState(false)
78
79
  const formSubmissions = useFormSubmissionsForRecord('opportunity', id)
79
80
 
@@ -45,6 +45,7 @@ import { SectionHeader } from '../components/SectionHeader.tsx'
45
45
  import { SidebarField } from '../components/SidebarField.tsx'
46
46
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
47
47
  import { formatDay } from '../lib/dates.ts'
48
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
48
49
  import { useRecordTabs } from '../registry/context.ts'
49
50
  import { inSlotOrder } from '../registry/registry.ts'
50
51
  import { toTags } from './fields.ts'
@@ -73,7 +74,7 @@ export function PartnershipDetail(): React.JSX.Element {
73
74
  const moduleTabs = inSlotOrder(useRecordTabs('partnership'))
74
75
  const hasCustomFields = useHasCustomFields('partnership')
75
76
  const eventsEnabled = useModuleEnabled('events')
76
- const [activeTab, setActiveTab] = useState('overview')
77
+ const [activeTab, setActiveTab] = useRecordTab()
77
78
  const [showConvert, setShowConvert] = useState(false)
78
79
  const formSubmissions = useFormSubmissionsForRecord('partnership', id)
79
80
 
@@ -110,7 +110,7 @@ export function PartnershipsPage(): React.JSX.Element {
110
110
  )
111
111
 
112
112
  // The next-step column asks about the records on screen by id. `?target_id=`
113
- // takes at most one page of them (`api.md`), so past that ceiling the rest
113
+ // takes at most one page of them (`docs/agents/api-and-webhooks.md`), so past that ceiling the rest
114
114
  // read as having no plan; the note under the table says so.
115
115
  const askedIds = visiblePartnerships.slice(0, MAX_PAGE_SIZE).map((partnership) => partnership.id)
116
116
  const planItems = usePlanItems(
@@ -55,6 +55,7 @@ import { PhonesField } from '../components/PhonesField.tsx'
55
55
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
56
56
  import { useRecordTabs } from '../registry/context.ts'
57
57
  import { inSlotOrder } from '../registry/registry.ts'
58
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
58
59
  import {
59
60
  CandidateReferrerField,
60
61
  CandidateStageField,
@@ -91,7 +92,7 @@ export function PersonDetail(): React.JSX.Element {
91
92
  const moduleTabs = inSlotOrder(useRecordTabs('person'))
92
93
  const hasCustomFields = useHasCustomFields('person')
93
94
  const eventsEnabled = useModuleEnabled('events')
94
- const [activeTab, setActiveTab] = useState('overview')
95
+ const [activeTab, setActiveTab] = useRecordTab()
95
96
  const candidacies = useCandidates({ personIds: id === undefined ? [] : [id] }, {
96
97
  enabled: id !== undefined,
97
98
  })
@@ -209,7 +210,7 @@ export function PersonDetail(): React.JSX.Element {
209
210
  )
210
211
  }
211
212
 
212
- /** A committed inline edit is one `PATCH` of one field, which is what `api.md` asks for. */
213
+ /** A committed inline edit is one `PATCH` of one field. */
213
214
  function usePersonPatch(person: Person): PatchResult<PersonInput> {
214
215
  return usePatch(useUpdatePerson, person)
215
216
  }
@@ -672,7 +673,7 @@ function PersonFields({ person }: { readonly person: Person }): React.JSX.Elemen
672
673
  * The companies this person holds a title at.
673
674
  *
674
675
  * Two requests, not one per position: `?person_id=` on both lists is exactly the
675
- * filter `api.md` documents for this, and it exists so a detail page is not N+1.
676
+ * filter `docs/api-reference.md` documents for this, and it exists so a detail page is not N+1.
676
677
  */
677
678
  function PersonPositions({ person }: { readonly person: Person }): React.JSX.Element {
678
679
  const positions = usePositions({ personIds: [person.id] })
@@ -40,6 +40,7 @@ import { SidebarField } from '../components/SidebarField.tsx'
40
40
  import { SummaryBlock } from '../components/SummaryBlock.tsx'
41
41
  import { formatDay } from '../lib/dates.ts'
42
42
  import { formatMoney } from '../lib/money.ts'
43
+ import { useRecordTab } from '../lib/fragmentTarget.ts'
43
44
  import { useRecordTabs } from '../registry/context.ts'
44
45
  import { inSlotOrder } from '../registry/registry.ts'
45
46
  import { toTags } from './fields.ts'
@@ -72,7 +73,7 @@ export function RaiseDetail(): React.JSX.Element {
72
73
  const moduleTabs = inSlotOrder(useRecordTabs('raise'))
73
74
  const hasCustomFields = useHasCustomFields('raise')
74
75
  const eventsEnabled = useModuleEnabled('events')
75
- const [activeTab, setActiveTab] = useState('overview')
76
+ const [activeTab, setActiveTab] = useRecordTab()
76
77
  const [showConvert, setShowConvert] = useState(false)
77
78
 
78
79
  if (isNotFound) {
@@ -4,6 +4,7 @@ import { Link, useSearchParams } from 'react-router'
4
4
  import { useSearch } from '../api/resources/search.ts'
5
5
  import { ErrorPanel, LoadingPanel } from '../components/QueryState.tsx'
6
6
  import { PageHeader } from '../components/PageHeader.tsx'
7
+ import { attachedHref } from '../lib/recordLinks.ts'
7
8
 
8
9
  /**
9
10
  * `/search?q=`, the destination of the box in the application shell.
@@ -13,21 +14,35 @@ import { PageHeader } from '../components/PageHeader.tsx'
13
14
  * renderer, and the only thing it still owns is where a result links to.
14
15
  */
15
16
 
17
+ /**
18
+ * Where a Decision, Note or Plan item result opens: the page of the record it is
19
+ * on, at the item. With no record to open, the fallback.
20
+ */
21
+ function onItsRecord(fallback: string): (item: SearchResult) => string {
22
+ return (item) => (item.target === null ? fallback : (attachedHref(item.id, item.target) ?? fallback))
23
+ }
24
+
16
25
  /** What each collection is called on screen, and where one of its results lives. */
17
- const COLLECTIONS: Readonly<Record<SearchCollection, { label: string; path: (id: string) => string }>> = {
18
- handbook_page: { label: 'Handbook', path: (id) => `/handbook/${id}` },
19
- person: { label: 'People', path: (id) => `/people/${id}` },
20
- role: { label: 'Roles', path: (id) => `/hiring/${id}` },
21
- company: { label: 'Companies', path: (id) => `/companies/${id}` },
22
- enquiry: { label: 'Enquiries', path: (id) => `/enquiries/${id}` },
23
- deal: { label: 'Deals', path: (id) => `/deals/${id}` },
24
- opportunity: { label: 'Opportunities', path: (id) => `/opportunities/${id}` },
25
- raise: { label: 'Fundraising', path: (id) => `/fundraising/${id}` },
26
- partnership: { label: 'Partnerships', path: (id) => `/partnerships/${id}` },
27
- event: { label: 'Events', path: (id) => `/events/${id}` },
28
- // Decisions have no detail page of their own, in the mockup or here. The global
29
- // list is where one is read.
30
- decision: { label: 'Decisions', path: () => '/decisions' },
26
+ const COLLECTIONS: Readonly<
27
+ Record<SearchCollection, { label: string; path: (item: SearchResult) => string }>
28
+ > = {
29
+ handbook_page: { label: 'Handbook', path: (item) => `/handbook/${item.id}` },
30
+ person: { label: 'People', path: (item) => `/people/${item.id}` },
31
+ role: { label: 'Roles', path: (item) => `/hiring/${item.id}` },
32
+ company: { label: 'Companies', path: (item) => `/companies/${item.id}` },
33
+ enquiry: { label: 'Enquiries', path: (item) => `/enquiries/${item.id}` },
34
+ deal: { label: 'Deals', path: (item) => `/deals/${item.id}` },
35
+ opportunity: { label: 'Opportunities', path: (item) => `/opportunities/${item.id}` },
36
+ raise: { label: 'Fundraising', path: (item) => `/fundraising/${item.id}` },
37
+ partnership: { label: 'Partnerships', path: (item) => `/partnerships/${item.id}` },
38
+ event: { label: 'Events', path: (item) => `/events/${item.id}` },
39
+ // Decisions, Notes and Plan items have no page of their own. Each opens on the
40
+ // record it is on; the global list is where a decision with none is read.
41
+ decision: { label: 'Decisions', path: onItsRecord('/decisions') },
42
+ note: { label: 'Notes', path: onItsRecord('/dashboard') },
43
+ plan_item: { label: 'Plan items', path: onItsRecord('/planning') },
44
+ list: { label: 'Lists', path: (item) => `/lists/${item.id}` },
45
+ form: { label: 'Forms', path: (item) => `/forms/${item.id}` },
31
46
  }
32
47
 
33
48
  export function SearchPage(): React.JSX.Element {
@@ -120,7 +135,7 @@ function ResultRow({
120
135
  }): React.JSX.Element {
121
136
  return (
122
137
  <Link
123
- to={COLLECTIONS[collection].path(item.id)}
138
+ to={COLLECTIONS[collection].path(item)}
124
139
  className="block px-4 py-2.5 transition hover:bg-accent-soft/30"
125
140
  >
126
141
  <div className="flex items-center justify-between gap-3">
@@ -7,7 +7,7 @@ import { useVisibleNavItems } from '../../registry/visibleNav.ts'
7
7
  /**
8
8
  * Tabs across the account's own settings, from the mockup's `AccountNav`.
9
9
  *
10
- * Three of its five tabs are core's. The rest come from `nav.account`, which is
10
+ * Five tabs are core's. The rest come from `nav.account`, which is
11
11
  * where a module's own account page announces itself: a module route mounts as
12
12
  * a sibling of `/account` rather than a child of it, so without this the page
13
13
  * would render with no tab strip and nothing anywhere pointing at it.
@@ -21,6 +21,7 @@ const CORE_TABS: readonly NavItem[] = [
21
21
  { id: 'security', to: '/account/security', label: 'Security', order: 200 },
22
22
  { id: 'preferences', to: '/account/preferences', label: 'Preferences', order: 300 },
23
23
  { id: 'api-keys', to: '/account/api-keys', label: 'API keys', order: 400 },
24
+ { id: 'connected-apps', to: '/account/connected-apps', label: 'Connected apps', order: 500 },
24
25
  ]
25
26
 
26
27
  function tabClass({ isActive }: { isActive: boolean }): string {