@kelpie/ui 0.16.0 → 0.18.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 (258) hide show
  1. package/dist/api/client.d.ts +1 -1
  2. package/dist/api/resources/ai.d.ts +21 -0
  3. package/dist/api/resources/ai.d.ts.map +1 -0
  4. package/dist/api/resources/ai.js +101 -0
  5. package/dist/api/resources/ai.js.map +1 -0
  6. package/dist/api/resources/conversions.js +1 -1
  7. package/dist/api/resources/conversions.js.map +1 -1
  8. package/dist/api/resources/forms.d.ts +8 -0
  9. package/dist/api/resources/forms.d.ts.map +1 -1
  10. package/dist/api/resources/forms.js +39 -0
  11. package/dist/api/resources/forms.js.map +1 -1
  12. package/dist/api/resources/personIntake.d.ts +12 -0
  13. package/dist/api/resources/personIntake.d.ts.map +1 -0
  14. package/dist/api/resources/personIntake.js +54 -0
  15. package/dist/api/resources/personIntake.js.map +1 -0
  16. package/dist/api/resources/session.d.ts.map +1 -1
  17. package/dist/api/resources/session.js +3 -1
  18. package/dist/api/resources/session.js.map +1 -1
  19. package/dist/api/resources/workspace.d.ts +2 -2
  20. package/dist/api/resources/workspace.js +2 -2
  21. package/dist/app/KelpieApp.js +2 -2
  22. package/dist/app/KelpieApp.js.map +1 -1
  23. package/dist/components/ActivitiesPanel.d.ts +7 -4
  24. package/dist/components/ActivitiesPanel.d.ts.map +1 -1
  25. package/dist/components/ActivitiesPanel.js +12 -2
  26. package/dist/components/ActivitiesPanel.js.map +1 -1
  27. package/dist/components/ActivityAction.d.ts +15 -0
  28. package/dist/components/ActivityAction.d.ts.map +1 -0
  29. package/dist/components/ActivityAction.js +20 -0
  30. package/dist/components/ActivityAction.js.map +1 -0
  31. package/dist/components/AgentTasks.d.ts +5 -0
  32. package/dist/components/AgentTasks.d.ts.map +1 -1
  33. package/dist/components/AgentTasks.js +88 -10
  34. package/dist/components/AgentTasks.js.map +1 -1
  35. package/dist/components/DecisionsPanel.d.ts.map +1 -1
  36. package/dist/components/DecisionsPanel.js +3 -1
  37. package/dist/components/DecisionsPanel.js.map +1 -1
  38. package/dist/components/LinkedText.d.ts +12 -0
  39. package/dist/components/LinkedText.d.ts.map +1 -0
  40. package/dist/components/LinkedText.js +25 -0
  41. package/dist/components/LinkedText.js.map +1 -0
  42. package/dist/components/MarkdownView.d.ts +3 -1
  43. package/dist/components/MarkdownView.d.ts.map +1 -1
  44. package/dist/components/MarkdownView.js +17 -3
  45. package/dist/components/MarkdownView.js.map +1 -1
  46. package/dist/components/NotesPanel.d.ts +2 -1
  47. package/dist/components/NotesPanel.d.ts.map +1 -1
  48. package/dist/components/NotesPanel.js +6 -7
  49. package/dist/components/NotesPanel.js.map +1 -1
  50. package/dist/components/PersonIntakeDialog.d.ts +19 -0
  51. package/dist/components/PersonIntakeDialog.d.ts.map +1 -0
  52. package/dist/components/PersonIntakeDialog.js +87 -0
  53. package/dist/components/PersonIntakeDialog.js.map +1 -0
  54. package/dist/components/PlanPanel.d.ts.map +1 -1
  55. package/dist/components/PlanPanel.js +3 -1
  56. package/dist/components/PlanPanel.js.map +1 -1
  57. package/dist/components/RecordLinkTextarea.d.ts +12 -0
  58. package/dist/components/RecordLinkTextarea.d.ts.map +1 -0
  59. package/dist/components/RecordLinkTextarea.js +142 -0
  60. package/dist/components/RecordLinkTextarea.js.map +1 -0
  61. package/dist/components/Shell.js +1 -1
  62. package/dist/components/Shell.js.map +1 -1
  63. package/dist/components/WorkspaceSwitcher.d.ts +2 -1
  64. package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
  65. package/dist/components/WorkspaceSwitcher.js +7 -2
  66. package/dist/components/WorkspaceSwitcher.js.map +1 -1
  67. package/dist/index.d.ts +5 -2
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +6 -1
  70. package/dist/index.js.map +1 -1
  71. package/dist/lib/fragmentTarget.d.ts +18 -0
  72. package/dist/lib/fragmentTarget.d.ts.map +1 -0
  73. package/dist/lib/fragmentTarget.js +73 -0
  74. package/dist/lib/fragmentTarget.js.map +1 -0
  75. package/dist/lib/recordLinks.d.ts +17 -0
  76. package/dist/lib/recordLinks.d.ts.map +1 -0
  77. package/dist/lib/recordLinks.js +48 -0
  78. package/dist/lib/recordLinks.js.map +1 -0
  79. package/dist/lib/recordReferences.d.ts +41 -0
  80. package/dist/lib/recordReferences.d.ts.map +1 -0
  81. package/dist/lib/recordReferences.js +92 -0
  82. package/dist/lib/recordReferences.js.map +1 -0
  83. package/dist/modules/PersonIntakeWizard.d.ts +3 -0
  84. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -0
  85. package/dist/modules/PersonIntakeWizard.js +223 -0
  86. package/dist/modules/PersonIntakeWizard.js.map +1 -0
  87. package/dist/modules/ai.d.ts +14 -0
  88. package/dist/modules/ai.d.ts.map +1 -0
  89. package/dist/modules/ai.js +26 -0
  90. package/dist/modules/ai.js.map +1 -0
  91. package/dist/modules/aiRunner.d.ts +3 -0
  92. package/dist/modules/aiRunner.d.ts.map +1 -0
  93. package/dist/modules/aiRunner.js +68 -0
  94. package/dist/modules/aiRunner.js.map +1 -0
  95. package/dist/modules/personIntakeSelection.d.ts +7 -0
  96. package/dist/modules/personIntakeSelection.d.ts.map +1 -0
  97. package/dist/modules/personIntakeSelection.js +21 -0
  98. package/dist/modules/personIntakeSelection.js.map +1 -0
  99. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  100. package/dist/pages/CompanyDetail.js +2 -1
  101. package/dist/pages/CompanyDetail.js.map +1 -1
  102. package/dist/pages/DealDetail.d.ts.map +1 -1
  103. package/dist/pages/DealDetail.js +2 -1
  104. package/dist/pages/DealDetail.js.map +1 -1
  105. package/dist/pages/EnquiryDetail.d.ts.map +1 -1
  106. package/dist/pages/EnquiryDetail.js +2 -1
  107. package/dist/pages/EnquiryDetail.js.map +1 -1
  108. package/dist/pages/EventDetail.d.ts.map +1 -1
  109. package/dist/pages/EventDetail.js +2 -1
  110. package/dist/pages/EventDetail.js.map +1 -1
  111. package/dist/pages/FormsPage.js +4 -4
  112. package/dist/pages/FormsPage.js.map +1 -1
  113. package/dist/pages/OpportunityDetail.d.ts.map +1 -1
  114. package/dist/pages/OpportunityDetail.js +2 -1
  115. package/dist/pages/OpportunityDetail.js.map +1 -1
  116. package/dist/pages/PartnershipDetail.d.ts.map +1 -1
  117. package/dist/pages/PartnershipDetail.js +2 -1
  118. package/dist/pages/PartnershipDetail.js.map +1 -1
  119. package/dist/pages/PeoplePage.d.ts.map +1 -1
  120. package/dist/pages/PeoplePage.js +7 -1
  121. package/dist/pages/PeoplePage.js.map +1 -1
  122. package/dist/pages/PersonDetail.d.ts.map +1 -1
  123. package/dist/pages/PersonDetail.js +2 -1
  124. package/dist/pages/PersonDetail.js.map +1 -1
  125. package/dist/pages/RaiseDetail.d.ts.map +1 -1
  126. package/dist/pages/RaiseDetail.js +2 -1
  127. package/dist/pages/RaiseDetail.js.map +1 -1
  128. package/dist/pages/SearchPage.d.ts.map +1 -1
  129. package/dist/pages/SearchPage.js +26 -14
  130. package/dist/pages/SearchPage.js.map +1 -1
  131. package/dist/pages/admin/AiAdminPage.d.ts +2 -0
  132. package/dist/pages/admin/AiAdminPage.d.ts.map +1 -0
  133. package/dist/pages/admin/AiAdminPage.js +19 -0
  134. package/dist/pages/admin/AiAdminPage.js.map +1 -0
  135. package/dist/pages/admin/AiPage.d.ts +5 -0
  136. package/dist/pages/admin/AiPage.d.ts.map +1 -0
  137. package/dist/pages/admin/AiPage.js +196 -0
  138. package/dist/pages/admin/AiPage.js.map +1 -0
  139. package/dist/pages/admin/McpPage.js +2 -2
  140. package/dist/pages/admin/McpPage.js.map +1 -1
  141. package/dist/pages/admin/McpPanel.d.ts +3 -0
  142. package/dist/pages/admin/McpPanel.d.ts.map +1 -0
  143. package/dist/pages/admin/McpPanel.js +123 -0
  144. package/dist/pages/admin/McpPanel.js.map +1 -0
  145. package/dist/pages/admin/PrivacyPage.js +19 -3
  146. package/dist/pages/admin/PrivacyPage.js.map +1 -1
  147. package/dist/pages/admin/WorkspaceSettingsPage.d.ts +5 -6
  148. package/dist/pages/admin/WorkspaceSettingsPage.d.ts.map +1 -1
  149. package/dist/pages/admin/WorkspaceSettingsPage.js +12 -17
  150. package/dist/pages/admin/WorkspaceSettingsPage.js.map +1 -1
  151. package/dist/pages/dashboard/attention.d.ts +0 -5
  152. package/dist/pages/dashboard/attention.d.ts.map +1 -1
  153. package/dist/pages/dashboard/attention.js +1 -21
  154. package/dist/pages/dashboard/attention.js.map +1 -1
  155. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  156. package/dist/pages/dashboard/sections.js +6 -3
  157. package/dist/pages/dashboard/sections.js.map +1 -1
  158. package/dist/pages/forms/EmbedPanel.js +5 -2
  159. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  160. package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
  161. package/dist/pages/forms/FieldsEditor.js +90 -8
  162. package/dist/pages/forms/FieldsEditor.js.map +1 -1
  163. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  164. package/dist/pages/forms/FormSettings.js +73 -6
  165. package/dist/pages/forms/FormSettings.js.map +1 -1
  166. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  167. package/dist/pages/forms/SubmissionDetail.js +2 -1
  168. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  169. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  170. package/dist/pages/forms/SubmissionsTable.js +2 -1
  171. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  172. package/dist/pages/forms/fieldList.d.ts +2 -2
  173. package/dist/pages/forms/fieldList.d.ts.map +1 -1
  174. package/dist/pages/forms/fieldList.js +38 -10
  175. package/dist/pages/forms/fieldList.js.map +1 -1
  176. package/dist/pages/forms/template.d.ts.map +1 -1
  177. package/dist/pages/forms/template.js +13 -0
  178. package/dist/pages/forms/template.js.map +1 -1
  179. package/dist/pages/handbook/HandbookPage.d.ts.map +1 -1
  180. package/dist/pages/handbook/HandbookPage.js +2 -3
  181. package/dist/pages/handbook/HandbookPage.js.map +1 -1
  182. package/dist/pages/onboarding/WorkspaceStepPage.d.ts.map +1 -1
  183. package/dist/pages/onboarding/WorkspaceStepPage.js +9 -27
  184. package/dist/pages/onboarding/WorkspaceStepPage.js.map +1 -1
  185. package/dist/pages/onboarding/onboardingRerun.d.ts +9 -0
  186. package/dist/pages/onboarding/onboardingRerun.d.ts.map +1 -1
  187. package/dist/pages/onboarding/onboardingRerun.js +11 -0
  188. package/dist/pages/onboarding/onboardingRerun.js.map +1 -1
  189. package/dist/registry/context.d.ts +7 -1
  190. package/dist/registry/context.d.ts.map +1 -1
  191. package/dist/registry/context.js +12 -0
  192. package/dist/registry/context.js.map +1 -1
  193. package/dist/registry/contributions.d.ts +70 -1
  194. package/dist/registry/contributions.d.ts.map +1 -1
  195. package/dist/registry/registry.d.ts +12 -1
  196. package/dist/registry/registry.d.ts.map +1 -1
  197. package/dist/registry/registry.js +21 -0
  198. package/dist/registry/registry.js.map +1 -1
  199. package/package.json +2 -2
  200. package/src/api/client.ts +1 -1
  201. package/src/api/resources/ai.ts +120 -0
  202. package/src/api/resources/conversions.ts +1 -1
  203. package/src/api/resources/forms.ts +56 -0
  204. package/src/api/resources/personIntake.ts +95 -0
  205. package/src/api/resources/session.ts +3 -1
  206. package/src/api/resources/workspace.ts +4 -4
  207. package/src/app/KelpieApp.tsx +4 -2
  208. package/src/components/ActivitiesPanel.tsx +39 -10
  209. package/src/components/ActivityAction.tsx +33 -0
  210. package/src/components/AgentTasks.tsx +138 -10
  211. package/src/components/DecisionsPanel.tsx +9 -1
  212. package/src/components/LinkedText.tsx +51 -0
  213. package/src/components/MarkdownView.tsx +37 -7
  214. package/src/components/NotesPanel.tsx +18 -12
  215. package/src/components/PersonIntakeDialog.tsx +226 -0
  216. package/src/components/PlanPanel.tsx +9 -1
  217. package/src/components/RecordLinkTextarea.tsx +257 -0
  218. package/src/components/Shell.tsx +1 -1
  219. package/src/components/WorkspaceSwitcher.tsx +15 -1
  220. package/src/index.ts +16 -0
  221. package/src/lib/fragmentTarget.ts +96 -0
  222. package/src/lib/recordLinks.ts +57 -0
  223. package/src/lib/recordReferences.ts +139 -0
  224. package/src/modules/PersonIntakeWizard.tsx +633 -0
  225. package/src/modules/ai.tsx +27 -0
  226. package/src/modules/aiRunner.ts +83 -0
  227. package/src/modules/personIntakeSelection.ts +24 -0
  228. package/src/pages/CompanyDetail.tsx +2 -1
  229. package/src/pages/DealDetail.tsx +2 -1
  230. package/src/pages/EnquiryDetail.tsx +2 -1
  231. package/src/pages/EventDetail.tsx +2 -1
  232. package/src/pages/FormsPage.tsx +4 -4
  233. package/src/pages/OpportunityDetail.tsx +2 -1
  234. package/src/pages/PartnershipDetail.tsx +2 -1
  235. package/src/pages/PeoplePage.tsx +21 -5
  236. package/src/pages/PersonDetail.tsx +2 -1
  237. package/src/pages/RaiseDetail.tsx +2 -1
  238. package/src/pages/SearchPage.tsx +30 -15
  239. package/src/pages/admin/AiAdminPage.tsx +52 -0
  240. package/src/pages/admin/AiPage.tsx +457 -0
  241. package/src/pages/admin/{McpPage.tsx → McpPanel.tsx} +15 -11
  242. package/src/pages/admin/PrivacyPage.tsx +42 -0
  243. package/src/pages/admin/WorkspaceSettingsPage.tsx +13 -28
  244. package/src/pages/dashboard/attention.ts +1 -24
  245. package/src/pages/dashboard/sections.tsx +9 -4
  246. package/src/pages/forms/EmbedPanel.tsx +5 -1
  247. package/src/pages/forms/FieldsEditor.tsx +204 -15
  248. package/src/pages/forms/FormSettings.tsx +156 -9
  249. package/src/pages/forms/SubmissionDetail.tsx +2 -1
  250. package/src/pages/forms/SubmissionsTable.tsx +2 -1
  251. package/src/pages/forms/fieldList.ts +39 -10
  252. package/src/pages/forms/template.ts +13 -0
  253. package/src/pages/handbook/HandbookPage.tsx +5 -6
  254. package/src/pages/onboarding/WorkspaceStepPage.tsx +19 -43
  255. package/src/pages/onboarding/onboardingRerun.ts +14 -0
  256. package/src/registry/context.ts +19 -0
  257. package/src/registry/contributions.ts +64 -1
  258. package/src/registry/registry.ts +48 -0
@@ -1,9 +1,13 @@
1
1
  import type { Activity, ActivityKind, RecordTargetType } from '@kelpie/schemas'
2
+ import { Link } from 'react-router'
2
3
 
3
4
  import { useTimezone } from '../api/resources/account.ts'
4
5
  import { useActivities } from '../api/resources/activities.ts'
5
6
  import { useMembers } from '../api/resources/members.ts'
6
7
  import { formatRelativeTime, monthLabel } from '../lib/dates.ts'
8
+ import { targetHref } from '../lib/recordLinks.ts'
9
+ import { ActivityAction } from './ActivityAction.tsx'
10
+ import { LinkedText } from './LinkedText.tsx'
7
11
  import { Paginator } from './Paginator.tsx'
8
12
  import { ErrorPanel } from './QueryState.tsx'
9
13
  import { SectionHeader } from './SectionHeader.tsx'
@@ -17,10 +21,13 @@ import { SectionHeader } from './SectionHeader.tsx'
17
21
  * The roll-up is the server's: a person's timeline already carries the deals and
18
22
  * partnerships they are on, so nothing here fetches related records to merge in.
19
23
  *
20
- * A rolled-up row says which kind of record it came from and stops there. The
21
- * mockup also names it and links to it, which needs the Deals, Opportunities and
22
- * Partnerships endpoints. Naming a record this page cannot fetch would mean
23
- * printing an id or inventing a label, and both are worse than the type alone.
24
+ * A rolled-up row says which kind of record it came from, names it, and links
25
+ * to it, as the mockup does. The name comes with the row (`targetName`), so the
26
+ * page fetches nothing more for it. A record the server could not name shows
27
+ * its type alone rather than an id.
28
+ *
29
+ * Record ids that the detail cites become links to those records too
30
+ * (`references`).
24
31
  */
25
32
 
26
33
  export interface ActivitiesPanelProps {
@@ -224,7 +231,7 @@ function ActivityEvent({
224
231
  <div className="flex items-baseline justify-between gap-3">
225
232
  <p className="min-w-0 text-[12px] leading-snug text-ink">
226
233
  <span className="font-semibold">{actorName}</span>{' '}
227
- <span className="text-ink-muted">{activity.action}</span>
234
+ <ActivityAction action={activity.action} subject={activity.subject} />
228
235
  </p>
229
236
  <time
230
237
  dateTime={activity.createdAt.toISOString()}
@@ -233,15 +240,37 @@ function ActivityEvent({
233
240
  {formatRelativeTime(activity.createdAt, timezone)}
234
241
  </time>
235
242
  </div>
236
- {isRolledUp && (
243
+ {isRolledUp && <RolledUpTarget activity={activity} />}
244
+ {activity.detail !== null && (
237
245
  <p className="text-[11px] leading-snug text-ink-faint">
238
- on <span className="text-ink-muted">{TARGET_TYPE_LABELS[activity.targetType]}</span>
246
+ <LinkedText text={activity.detail} references={activity.references} />
239
247
  </p>
240
248
  )}
241
- {activity.detail !== null && (
242
- <p className="text-[11px] leading-snug text-ink-faint">{activity.detail}</p>
243
- )}
244
249
  </div>
245
250
  </li>
246
251
  )
247
252
  }
253
+
254
+ /** `on Partnership · Sandbox`, with the name linked to the record when it has a page. */
255
+ function RolledUpTarget({ activity }: { readonly activity: Activity }): React.JSX.Element {
256
+ const href = targetHref(activity.targetType, activity.targetId)
257
+ const name = activity.targetName
258
+
259
+ return (
260
+ <p className="text-[11px] leading-snug text-ink-faint">
261
+ on <span className="text-ink-muted">{TARGET_TYPE_LABELS[activity.targetType]}</span>
262
+ {name !== null && (
263
+ <>
264
+ {' · '}
265
+ {href === undefined ? (
266
+ <span className="text-ink-muted">{name}</span>
267
+ ) : (
268
+ <Link to={href} className="text-ink-muted hover:text-accent hover:underline">
269
+ {name}
270
+ </Link>
271
+ )}
272
+ </>
273
+ )}
274
+ </p>
275
+ )
276
+ }
@@ -0,0 +1,33 @@
1
+ import type { RecordReference } from '@kelpie/schemas'
2
+ import { Link } from 'react-router'
3
+
4
+ import { referenceHref } from '../lib/recordLinks.ts'
5
+
6
+ /**
7
+ * An activity's action — `added a note`, `linked to company`, `converted to
8
+ * Deal` — linked to the record the row is about, when it has one.
9
+ *
10
+ * The subject is the note that was added, the record linked to, the form
11
+ * something came in through. The server names it with its current name, which
12
+ * the tooltip shows; a subject that is gone arrives as null and the action stays
13
+ * plain text. A Note, Decision or Plan item opens on the record it is on.
14
+ */
15
+ export function ActivityAction({
16
+ action,
17
+ subject,
18
+ }: {
19
+ readonly action: string
20
+ readonly subject: RecordReference | null
21
+ }): React.JSX.Element {
22
+ const href = subject === null ? undefined : referenceHref(subject)
23
+
24
+ if (subject === null || href === undefined) {
25
+ return <span className="text-ink-muted">{action}</span>
26
+ }
27
+
28
+ return (
29
+ <Link to={href} title={subject.name} className="text-ink-muted hover:text-accent hover:underline">
30
+ {action}
31
+ </Link>
32
+ )
33
+ }
@@ -1,3 +1,4 @@
1
+ import { useQueryClient } from '@tanstack/react-query'
1
2
  import { useEffect, useId, useRef, useState } from 'react'
2
3
  import type { AgentRun, AgentTaskDefinition, AgentTaskTargetType, ResolvedAgentTask } from '@kelpie/schemas'
3
4
 
@@ -8,6 +9,8 @@ import {
8
9
  useResolveAgentTask,
9
10
  useRunAgentTask,
10
11
  } from '../api/resources/agentTasks.ts'
12
+ import { useAgentRunner } from '../registry/context.ts'
13
+ import type { AgentRunner, AgentRunnerProgress } from '../registry/contributions.ts'
11
14
  import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
12
15
 
13
16
  /**
@@ -15,6 +18,11 @@ import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
15
18
  * prompt, Preview, and Run. Ported from the mockup with the in-memory resolve
16
19
  * swapped for `POST …/resolve` and the pretend status ladder swapped for the
17
20
  * run record the server settles, polled until it does.
21
+ *
22
+ * Run dispatches straight to the assembly's agent runner (Kelpie AI, from the
23
+ * optional `ai` module) with no dialog, and reports progress on the task's
24
+ * row. With no runner, or one that cannot run now, Run is disabled and says
25
+ * why. Preview's Run… still dispatches to any registered agent.
18
26
  */
19
27
  export interface AgentTasksProps {
20
28
  readonly targetType: AgentTaskTargetType
@@ -28,6 +36,55 @@ type PanelMode = 'preview' | 'run' | null
28
36
 
29
37
  const COPIED_MS = 1800
30
38
 
39
+ /** What the menu uses when no module registered a runner: Run stays disabled. */
40
+ const NO_RUNNER: AgentRunner = {
41
+ id: 'none',
42
+ useAvailability: () => ({
43
+ status: 'unavailable',
44
+ reason: 'Running needs the AI module, which this deployment does not include. Use Preview to dispatch to a registered agent.',
45
+ }),
46
+ useProgress: () => undefined,
47
+ }
48
+
49
+ /** The one Run the menu started, and the core agent run it created once the POST returns. */
50
+ interface DirectRun {
51
+ readonly taskId: string
52
+ readonly runId: string | null
53
+ }
54
+
55
+ type DirectRunStatus =
56
+ | { readonly tone: 'busy'; readonly text: string }
57
+ | { readonly tone: 'done'; readonly text: string }
58
+ | { readonly tone: 'failed'; readonly text: string }
59
+
60
+ function directRunStatus(
61
+ dispatchError: Error | null,
62
+ run: AgentRun | undefined,
63
+ progress: AgentRunnerProgress | undefined,
64
+ ): DirectRunStatus {
65
+ if (dispatchError !== null) {
66
+ return { tone: 'failed', text: `Failed: ${dispatchError.message}` }
67
+ }
68
+
69
+ if (run === undefined || run.status === 'queued' || run.status === 'running') {
70
+ return { tone: 'busy', text: 'Running…' }
71
+ }
72
+
73
+ if (run.status === 'failed') {
74
+ return { tone: 'failed', text: `Failed: ${run.failureReason ?? 'no reason recorded'}` }
75
+ }
76
+
77
+ switch (progress?.status) {
78
+ case 'succeeded':
79
+ return { tone: 'done', text: 'Done.' }
80
+ case 'failed':
81
+ return { tone: 'failed', text: `Failed: ${progress.reason}` }
82
+ case 'running':
83
+ case undefined:
84
+ return { tone: 'busy', text: 'Running…' }
85
+ }
86
+ }
87
+
31
88
  export function AgentTasks({
32
89
  targetType,
33
90
  targetId,
@@ -44,13 +101,26 @@ export function AgentTasks({
44
101
  const [copiedId, setCopiedId] = useState<string | null>(null)
45
102
  const [agentId, setAgentId] = useState('')
46
103
  const [runId, setRunId] = useState<string | null>(null)
104
+ const [directRun, setDirectRun] = useState<DirectRun | null>(null)
47
105
  const rootRef = useRef<HTMLDivElement>(null)
106
+ const refreshedRunId = useRef<string | null>(null)
48
107
  const menuId = useId()
108
+ const queryClient = useQueryClient()
109
+ const runner = useAgentRunner() ?? NO_RUNNER
110
+ const directDispatch = useRunAgentTask()
49
111
 
50
112
  // Fetched only once the run pane opens: the trigger sits on every detail
51
113
  // page, and most visits never dispatch anything.
52
114
  const agents = useAgents({ enabled: panel === 'run' })
53
115
  const { record: run } = useAgentRun(runId ?? undefined)
116
+ // Checked only once the menu has opened, for the same reason as `agents`.
117
+ const availability = runner.useAvailability({ enabled: menuOpen || directRun !== null })
118
+ const { record: directAgentRun } = useAgentRun(directRun?.runId ?? undefined)
119
+ const progress = runner.useProgress(
120
+ directAgentRun?.status === 'succeeded' ? directAgentRun.id : undefined,
121
+ )
122
+ const directStatus =
123
+ directRun === null ? null : directRunStatus(directDispatch.error, directAgentRun, progress)
54
124
 
55
125
  useEffect(() => {
56
126
  if (!menuOpen) {
@@ -83,9 +153,21 @@ export function AgentTasks({
83
153
  setActiveTaskId(null)
84
154
  setResolved(null)
85
155
  setRunId(null)
156
+ setDirectRun(null)
86
157
  setMenuOpen(false)
87
158
  }, [targetType, targetId])
88
159
 
160
+ // The agent wrote to this record, or to records around it. Refetch what is on
161
+ // screen, once per run.
162
+ useEffect(() => {
163
+ const id = directAgentRun?.id
164
+
165
+ if (progress?.status === 'succeeded' && id !== undefined && refreshedRunId.current !== id) {
166
+ refreshedRunId.current = id
167
+ void queryClient.invalidateQueries()
168
+ }
169
+ }, [progress?.status, directAgentRun?.id, queryClient])
170
+
89
171
  useEffect(() => {
90
172
  if (agentId === '' && agents.records.length > 0) {
91
173
  setAgentId(agents.records[0]?.id ?? '')
@@ -131,6 +213,22 @@ export function AgentTasks({
131
213
  }
132
214
  }
133
215
 
216
+ function runDirectly(taskId: string): void {
217
+ if (availability.status !== 'ready') {
218
+ return
219
+ }
220
+
221
+ setDirectRun({ taskId, runId: null })
222
+ directDispatch
223
+ .runAsync({ taskId, targetType, targetId, agentId: availability.agentId })
224
+ .then((created) => {
225
+ setDirectRun({ taskId, runId: created.id })
226
+ })
227
+ .catch(() => {
228
+ // The task's row renders `directDispatch.error`.
229
+ })
230
+ }
231
+
134
232
  function startRun(): void {
135
233
  if (activeTaskId === null || agentId === '') {
136
234
  return
@@ -149,6 +247,19 @@ export function AgentTasks({
149
247
  const activeTask = catalog.records.find((task) => task.id === activeTaskId)
150
248
  const settled = run?.status === 'succeeded' || run?.status === 'failed'
151
249
  const dispatching = dispatch.isPending || (run !== undefined && !settled)
250
+ const runControl: RunControl = {
251
+ disabledReason:
252
+ availability.status === 'ready'
253
+ ? directStatus?.tone === 'busy'
254
+ ? 'A task is running.'
255
+ : null
256
+ : availability.status === 'loading'
257
+ ? 'Checking AI…'
258
+ : availability.reason,
259
+ activeTaskId: directRun?.taskId ?? null,
260
+ status: directStatus,
261
+ onRun: runDirectly,
262
+ }
152
263
 
153
264
  return (
154
265
  <div className="relative shrink-0" ref={rootRef}>
@@ -189,9 +300,7 @@ export function AgentTasks({
189
300
  onPreview={(id) => {
190
301
  openResolved(id, 'preview')
191
302
  }}
192
- onRun={(id) => {
193
- openResolved(id, 'run')
194
- }}
303
+ run={runControl}
195
304
  />
196
305
  )}
197
306
  {overflow.length > 0 && (
@@ -204,9 +313,7 @@ export function AgentTasks({
204
313
  onPreview={(id) => {
205
314
  openResolved(id, 'preview')
206
315
  }}
207
- onRun={(id) => {
208
- openResolved(id, 'run')
209
- }}
316
+ run={runControl}
210
317
  />
211
318
  )}
212
319
  </div>
@@ -388,6 +495,20 @@ function RunControls({
388
495
  )
389
496
  }
390
497
 
498
+ interface RunControl {
499
+ /** Why Run is disabled, shown as its tooltip. Null when it is enabled. */
500
+ readonly disabledReason: string | null
501
+ readonly activeTaskId: string | null
502
+ readonly status: DirectRunStatus | null
503
+ readonly onRun: (id: string) => void
504
+ }
505
+
506
+ const STATUS_TONE_CLASS: Readonly<Record<DirectRunStatus['tone'], string>> = {
507
+ busy: 'text-ink-muted',
508
+ done: 'text-ink-muted',
509
+ failed: 'text-danger',
510
+ }
511
+
391
512
  function TaskGroup({
392
513
  label,
393
514
  tasks,
@@ -395,7 +516,7 @@ function TaskGroup({
395
516
  bordered = false,
396
517
  onCopy,
397
518
  onPreview,
398
- onRun,
519
+ run,
399
520
  }: {
400
521
  readonly label: string
401
522
  readonly tasks: readonly AgentTaskDefinition[]
@@ -403,7 +524,7 @@ function TaskGroup({
403
524
  readonly bordered?: boolean
404
525
  readonly onCopy: (id: string) => void
405
526
  readonly onPreview: (id: string) => void
406
- readonly onRun: (id: string) => void
527
+ readonly run: RunControl
407
528
  }): React.JSX.Element {
408
529
  return (
409
530
  <div className={bordered ? 'border-t border-border pt-1' : undefined}>
@@ -436,14 +557,21 @@ function TaskGroup({
436
557
  </button>
437
558
  <button
438
559
  type="button"
439
- className="rounded border border-border px-1.5 py-0.5 text-[11px] font-medium text-ink-muted transition hover:border-accent hover:text-accent"
560
+ className="rounded border border-border px-1.5 py-0.5 text-[11px] font-medium text-ink-muted transition hover:border-accent hover:text-accent disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-border disabled:hover:text-ink-muted"
561
+ disabled={run.disabledReason !== null}
562
+ title={run.disabledReason ?? undefined}
440
563
  onClick={() => {
441
- onRun(task.id)
564
+ run.onRun(task.id)
442
565
  }}
443
566
  >
444
567
  Run
445
568
  </button>
446
569
  </div>
570
+ {run.activeTaskId === task.id && run.status !== null && (
571
+ <p role="status" className={`mt-1.5 text-[11px] leading-snug ${STATUS_TONE_CLASS[run.status.tone]}`}>
572
+ {run.status.text}
573
+ </p>
574
+ )}
447
575
  </li>
448
576
  ))}
449
577
  </ul>
@@ -7,6 +7,7 @@ import { useTimezone } from '../api/resources/account.ts'
7
7
  import { useCreateDecision, useDecisions, useDeleteDecision } from '../api/resources/decisions.ts'
8
8
  import { useMembers } from '../api/resources/members.ts'
9
9
  import { formatDate } from '../lib/dates.ts'
10
+ import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
10
11
  import { Paginator } from './Paginator.tsx'
11
12
  import { ErrorPanel } from './QueryState.tsx'
12
13
  import { SectionHeader } from './SectionHeader.tsx'
@@ -202,9 +203,16 @@ function DecisionItem({
202
203
  readonly onRemove: () => void
203
204
  }): React.JSX.Element {
204
205
  const timezone = useTimezone()
206
+ const target = useFragmentTarget<HTMLLIElement>(decision.id)
205
207
 
206
208
  return (
207
- <li className="border-b border-border px-4 py-3 last:border-0">
209
+ <li
210
+ id={decision.id}
211
+ ref={target.ref}
212
+ className={`border-b border-border px-4 py-3 transition-colors last:border-0 ${
213
+ target.highlighted ? FRAGMENT_HIGHLIGHT : ''
214
+ }`}
215
+ >
208
216
  <div className="flex items-start justify-between gap-2">
209
217
  <p className="min-w-0 flex-1 text-[13px] font-medium text-ink">{decision.body}</p>
210
218
  <button
@@ -0,0 +1,51 @@
1
+ import type { RecordReference } from '@kelpie/schemas'
2
+ import { Link } from 'react-router'
3
+
4
+ import { referenceHref } from '../lib/recordLinks.ts'
5
+ import { splitOnReferences, unresolvedLabel } from '../lib/recordReferences.ts'
6
+
7
+ /**
8
+ * Plain text with each cited record id shown as the record's name, linked to
9
+ * its page. A record with no page of its own shows its name without a link.
10
+ * The id stays in the tooltip, so nothing the author wrote is lost. A
11
+ * `[[type:id|Label]]` token for a record that is gone shows its label.
12
+ */
13
+ export function LinkedText({
14
+ text,
15
+ references,
16
+ }: {
17
+ readonly text: string
18
+ readonly references: readonly RecordReference[]
19
+ }): React.JSX.Element {
20
+ return (
21
+ <>
22
+ {splitOnReferences(text, references).map((segment, index) => {
23
+ if (segment.kind === 'text') {
24
+ return segment.text
25
+ }
26
+
27
+ if (segment.kind === 'unresolved') {
28
+ return (
29
+ <span key={`${String(index)}-${segment.token.targetId}`} title={segment.token.targetId}>
30
+ {unresolvedLabel(segment.token)}
31
+ </span>
32
+ )
33
+ }
34
+
35
+ const { reference } = segment
36
+ const href = referenceHref(reference)
37
+ const key = `${String(index)}-${reference.targetId}`
38
+
39
+ return href === undefined ? (
40
+ <span key={key} title={reference.targetId} className="text-ink-muted">
41
+ {reference.name}
42
+ </span>
43
+ ) : (
44
+ <Link key={key} to={href} title={reference.targetId} className="text-accent hover:underline">
45
+ {reference.name}
46
+ </Link>
47
+ )
48
+ })}
49
+ </>
50
+ )
51
+ }
@@ -1,7 +1,12 @@
1
+ import type { RecordReference } from '@kelpie/schemas'
2
+ import { useMemo } from 'react'
1
3
  import Markdown from 'react-markdown'
2
4
  import type { Components } from 'react-markdown'
5
+ import { Link } from 'react-router'
3
6
  import remarkGfm from 'remark-gfm'
4
7
 
8
+ import { remarkRecordReferences } from '../lib/recordReferences.ts'
9
+
5
10
  /**
6
11
  * Handbook markdown, rendered by a library rather than by hand (roadmap
7
12
  * decision 5).
@@ -20,8 +25,16 @@ import remarkGfm from 'remark-gfm'
20
25
  *
21
26
  * The class names are the mockup's, element for element, so a page reads the
22
27
  * same as it did before the swap.
28
+ *
29
+ * `references` are the records the source cites by id, as the server named
30
+ * them. Each cited id renders as a link to the record, labelled with its name.
23
31
  */
24
32
 
33
+ /** An app path such as `/partnerships/prt_…`. `//host` is another site, so it does not count. */
34
+ function isAppPath(href: string | undefined): href is string {
35
+ return href !== undefined && href.startsWith('/') && !href.startsWith('//')
36
+ }
37
+
25
38
  const components: Components = {
26
39
  h1: ({ children }) => (
27
40
  <h1 className="text-[22px] font-semibold tracking-tight text-ink">{children}</h1>
@@ -41,11 +54,18 @@ const components: Components = {
41
54
  blockquote: ({ children }) => (
42
55
  <blockquote className="border-l-2 border-border pl-3 text-ink-muted">{children}</blockquote>
43
56
  ),
44
- a: ({ href, children }) => (
45
- <a href={href} className="text-accent hover:underline" target="_blank" rel="noreferrer">
46
- {children}
47
- </a>
48
- ),
57
+ // A path inside the app stays in this tab and in the router; anything else
58
+ // 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
+ ),
49
69
  hr: () => <hr className="border-border" />,
50
70
  // The wrapper scrolls rather than the page, so a wide table cannot push the
51
71
  // sidebar off screen.
@@ -62,10 +82,20 @@ const components: Components = {
62
82
  td: ({ children }) => <td className="px-3 py-2">{children}</td>,
63
83
  }
64
84
 
65
- export function MarkdownView({ source }: { readonly source: string }): React.JSX.Element {
85
+ const NO_REFERENCES: readonly RecordReference[] = []
86
+
87
+ export function MarkdownView({
88
+ source,
89
+ references = NO_REFERENCES,
90
+ }: {
91
+ readonly source: string
92
+ readonly references?: readonly RecordReference[]
93
+ }): React.JSX.Element {
94
+ const plugins = useMemo(() => [remarkGfm, remarkRecordReferences(references)], [references])
95
+
66
96
  return (
67
97
  <div className="markdown space-y-3 text-[13px] leading-relaxed text-ink">
68
- <Markdown remarkPlugins={[remarkGfm]} components={components}>
98
+ <Markdown remarkPlugins={plugins} components={components}>
69
99
  {source}
70
100
  </Markdown>
71
101
  </div>
@@ -6,15 +6,18 @@ import { useTimezone } from '../api/resources/account.ts'
6
6
  import { useMembers } from '../api/resources/members.ts'
7
7
  import { useCreateNote, useDeleteNote, useNotes, useUpdateNote } from '../api/resources/notes.ts'
8
8
  import { formatDateTime } from '../lib/dates.ts'
9
+ import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
9
10
  import { MarkdownView } from './MarkdownView.tsx'
10
11
  import { Paginator } from './Paginator.tsx'
12
+ import { RecordLinkTextarea } from './RecordLinkTextarea.tsx'
11
13
  import { ErrorPanel } from './QueryState.tsx'
12
14
  import { SectionHeader } from './SectionHeader.tsx'
13
15
 
14
16
  /**
15
17
  * The notes on one record.
16
18
  *
17
- * Bodies are markdown, rendered with the same component as the handbook.
19
+ * Bodies are markdown, rendered with the same component as the handbook. Typing
20
+ * `[[` in the editor links a record; see `RecordLinkTextarea`.
18
21
  * Notes can be created, edited, and deleted here. There is no pin control: the
19
22
  * mockup renders the badge on a note that carries the flag and offers no way to
20
23
  * set it. `PATCH /v1/notes/:id` takes `pinned`, so an agent can still pin.
@@ -76,12 +79,10 @@ export function NotesPanel({ targetType, targetId }: NotesPanelProps): React.JSX
76
79
 
77
80
  {adding && (
78
81
  <form onSubmit={submit} className="mb-3 space-y-2">
79
- <textarea
82
+ <RecordLinkTextarea
80
83
  value={body}
81
- onChange={(event) => {
82
- setBody(event.target.value)
83
- }}
84
- placeholder="Write a note… (Markdown supported)"
84
+ onChange={setBody}
85
+ placeholder="Write a note… (Markdown supported, [[ to link a record)"
85
86
  rows={3}
86
87
  autoFocus
87
88
  className="w-full resize-y rounded-md border border-border bg-surface-raised px-3 py-2 text-[13px] outline-none focus:border-accent focus:ring-2 focus:ring-accent/20"
@@ -147,6 +148,7 @@ function NoteItem({
147
148
  const [editing, setEditing] = useState(false)
148
149
  const [confirmingDelete, setConfirmingDelete] = useState(false)
149
150
  const [draft, setDraft] = useState(note.body)
151
+ const target = useFragmentTarget<HTMLLIElement>(note.id)
150
152
 
151
153
  function cancelEdit(): void {
152
154
  setDraft(note.body)
@@ -173,11 +175,9 @@ function NoteItem({
173
175
  return (
174
176
  <li className="rounded-md border border-border bg-surface-raised px-3.5 py-3">
175
177
  <form onSubmit={submitEdit} className="space-y-2">
176
- <textarea
178
+ <RecordLinkTextarea
177
179
  value={draft}
178
- onChange={(event) => {
179
- setDraft(event.target.value)
180
- }}
180
+ onChange={setDraft}
181
181
  rows={3}
182
182
  autoFocus
183
183
  className="w-full resize-y rounded-md border border-border bg-surface-raised px-3 py-2 text-[13px] outline-none focus:border-accent focus:ring-2 focus:ring-accent/20"
@@ -208,10 +208,16 @@ function NoteItem({
208
208
  }
209
209
 
210
210
  return (
211
- <li className="group rounded-md border border-border bg-surface-raised px-3.5 py-3">
211
+ <li
212
+ id={note.id}
213
+ ref={target.ref}
214
+ className={`group rounded-md border border-border bg-surface-raised px-3.5 py-3 transition-colors ${
215
+ target.highlighted ? FRAGMENT_HIGHLIGHT : ''
216
+ }`}
217
+ >
212
218
  <div className="flex items-start justify-between gap-2">
213
219
  <div className="min-w-0 flex-1">
214
- <MarkdownView source={note.body} />
220
+ <MarkdownView source={note.body} references={note.references} />
215
221
  </div>
216
222
  <div className="flex shrink-0 flex-col items-end gap-1">
217
223
  {note.pinned && (