@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
@@ -0,0 +1,457 @@
1
+ import { AI_DEFAULT_MODELS, AI_PROVIDER_LABELS, AI_PROVIDERS, AI_SERVICE_LABELS } from '@kelpie/schemas'
2
+ import type { AgentTaskTargetType, AiProvider, AiRun, AiSettings, AiSettingsInput } from '@kelpie/schemas'
3
+ import { useState } from 'react'
4
+ import type { FormEvent } from 'react'
5
+ import { Link } from 'react-router'
6
+
7
+ import { useTimezone } from '../../api/resources/account.ts'
8
+ import { useAiRuns, useAiServiceLabel, useAiSettings, useDisableAi, useSaveAiSettings } from '../../api/resources/ai.ts'
9
+ import { Chip } from '../../components/Chip.tsx'
10
+ import type { ChipTone } from '../../components/Chip.tsx'
11
+ import { LinkedText } from '../../components/LinkedText.tsx'
12
+ import { Paginator } from '../../components/Paginator.tsx'
13
+ import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
14
+ import { formatRelativeTime } from '../../lib/dates.ts'
15
+ import { targetHref } from '../../lib/recordLinks.ts'
16
+
17
+ /**
18
+ * The optional `ai` module's two tabs on Admin → AI, the core page at
19
+ * `/admin/ai` (`AiAdminPage`), beside core's MCP tab.
20
+ *
21
+ * Settings for Kelpie AI in this workspace, and its run log. Both read the
22
+ * same `/v1/ai/*` endpoints an agent would use.
23
+ *
24
+ * What the settings part shows depends on the module's key mode. In
25
+ * `workspace` mode an admin picks a provider, pastes their own API key, and
26
+ * may name a model. The key is write-only: the page shows its last four
27
+ * characters and never the key. In `deployment` mode the operator's
28
+ * environment decides all three, and the page offers only enable and disable.
29
+ */
30
+
31
+ const STATUS_TONES: Readonly<Record<AiRun['status'], ChipTone>> = {
32
+ queued: 'neutral',
33
+ running: 'accent',
34
+ succeeded: 'success',
35
+ failed: 'danger',
36
+ }
37
+
38
+ const OPERATION_TONES: Readonly<Record<string, ChipTone>> = {
39
+ applied: 'success',
40
+ failed: 'danger',
41
+ skipped: 'neutral',
42
+ }
43
+
44
+ /** A `workspace` target is not shown: every run is in this workspace. */
45
+ const TARGET_TYPE_LABELS: Readonly<Record<Exclude<AgentTaskTargetType, 'workspace'>, string>> = {
46
+ person: 'Person',
47
+ company: 'Company',
48
+ deal: 'Deal',
49
+ opportunity: 'Opportunity',
50
+ partnership: 'Partnership',
51
+ raise: 'Raise',
52
+ enquiry: 'Enquiry',
53
+ event: 'Event',
54
+ candidate: 'Candidate',
55
+ role: 'Role',
56
+ handbook: 'Handbook page',
57
+ }
58
+
59
+ const inputClass =
60
+ 'w-full max-w-md rounded-md border border-border bg-surface px-3 py-2 text-[13px] outline-none focus:border-accent focus:ring-2 focus:ring-accent/20'
61
+ const primaryButtonClass =
62
+ 'rounded-md bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover disabled:opacity-50'
63
+ const secondaryButtonClass =
64
+ 'rounded-md border border-border px-3.5 py-2 text-[12px] font-medium text-ink transition hover:border-border-strong disabled:opacity-50'
65
+
66
+ function keyDescription(settings: AiSettings): string {
67
+ if (settings.keySource === 'workspace') {
68
+ return settings.keyHint === null ? 'Your key is stored.' : `Your key ending in ${settings.keyHint} is stored.`
69
+ }
70
+ if (settings.keySource === 'environment') {
71
+ return 'This install supplies a key. Enter your own to use it instead.'
72
+ }
73
+
74
+ return 'No key is stored.'
75
+ }
76
+
77
+ /**
78
+ * Provider, key and model for `workspace` key mode.
79
+ *
80
+ * Only changed fields are sent. The server keeps what is omitted, and drops the
81
+ * stored key and model when the provider changes, so this form clears the model
82
+ * field on a provider change to match.
83
+ */
84
+ function WorkspaceKeyForm({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
85
+ const save = useSaveAiSettings()
86
+ const [provider, setProvider] = useState<AiProvider>(settings.provider ?? 'openai')
87
+ const [apiKey, setApiKey] = useState('')
88
+ const [model, setModel] = useState(settings.provider === null ? '' : settings.model)
89
+
90
+ const providerChanged = provider !== settings.provider
91
+ const defaultModel = AI_DEFAULT_MODELS[provider]
92
+
93
+ /** `undefined` keeps the stored model, `null` clears it back to the default. */
94
+ function modelChange(): string | null | undefined {
95
+ const trimmed = model.trim()
96
+
97
+ if (trimmed === '') {
98
+ // Nothing to clear when the workspace has not chosen a provider yet.
99
+ if (settings.provider === null) return undefined
100
+ return providerChanged || settings.model !== defaultModel ? null : undefined
101
+ }
102
+
103
+ return !providerChanged && trimmed === settings.model ? undefined : trimmed
104
+ }
105
+
106
+ function changes(): AiSettingsInput {
107
+ const nextModel = modelChange()
108
+
109
+ return {
110
+ ...(providerChanged ? { provider } : {}),
111
+ ...(apiKey.trim() === '' ? {} : { apiKey: apiKey.trim() }),
112
+ ...(nextModel === undefined ? {} : { model: nextModel }),
113
+ }
114
+ }
115
+
116
+ function submit(formEvent: FormEvent): void {
117
+ formEvent.preventDefault()
118
+ save
119
+ .runAsync(changes())
120
+ .then(() => {
121
+ setApiKey('')
122
+ })
123
+ .catch(() => undefined)
124
+ }
125
+
126
+ return (
127
+ <form onSubmit={submit} className="mt-4 space-y-3">
128
+ <label className="block">
129
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">Provider</span>
130
+ <select
131
+ value={provider}
132
+ onChange={(event) => {
133
+ setProvider(event.target.value as AiProvider)
134
+ setModel('')
135
+ }}
136
+ className="w-48 rounded-md border border-border bg-surface-raised px-3 py-2 text-[13px] outline-none focus:border-accent"
137
+ >
138
+ {AI_PROVIDERS.map((option) => (
139
+ <option key={option} value={option}>
140
+ {AI_PROVIDER_LABELS[option]}
141
+ </option>
142
+ ))}
143
+ </select>
144
+ </label>
145
+
146
+ <label className="block">
147
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">API key</span>
148
+ <input
149
+ type="password"
150
+ autoComplete="off"
151
+ value={apiKey}
152
+ onChange={(event) => {
153
+ setApiKey(event.target.value)
154
+ }}
155
+ placeholder={providerChanged ? `Paste your ${AI_PROVIDER_LABELS[provider]} API key` : 'Paste a new key to replace it'}
156
+ className={`${inputClass} font-mono`}
157
+ />
158
+ <span className="mt-1.5 block text-[12px] text-ink-muted">
159
+ {providerChanged && settings.keySource === 'workspace'
160
+ ? 'Changing provider removes the stored key.'
161
+ : keyDescription(settings)}{' '}
162
+ The key is stored encrypted and is never shown again.
163
+ </span>
164
+ </label>
165
+
166
+ <label className="block">
167
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">Model</span>
168
+ <input
169
+ value={model}
170
+ onChange={(event) => {
171
+ setModel(event.target.value)
172
+ }}
173
+ placeholder={defaultModel}
174
+ className={`${inputClass} font-mono`}
175
+ />
176
+ <span className="mt-1.5 block text-[12px] text-ink-muted">Leave it empty to use {defaultModel}.</span>
177
+ </label>
178
+
179
+ {save.error !== null && <ErrorPanel error={save.error} />}
180
+
181
+ <div className="flex flex-wrap gap-2">
182
+ <button type="submit" disabled={save.isPending} className={primaryButtonClass}>
183
+ {save.isPending ? 'Saving…' : settings.enabled ? 'Save' : 'Enable AI'}
184
+ </button>
185
+ {settings.enabled && settings.keySource === 'workspace' && !providerChanged && (
186
+ <button
187
+ type="button"
188
+ disabled={save.isPending}
189
+ onClick={() => {
190
+ save.run({ apiKey: null })
191
+ }}
192
+ className={secondaryButtonClass}
193
+ >
194
+ Remove stored key
195
+ </button>
196
+ )}
197
+ </div>
198
+ </form>
199
+ )
200
+ }
201
+
202
+ function DeploymentKeyControls({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
203
+ const save = useSaveAiSettings()
204
+
205
+ if (!settings.configured) {
206
+ return (
207
+ <p className="mt-3 text-[13px] text-ink-muted">
208
+ The operator has not set up a provider for this install. Set
209
+ <code className="mx-1 rounded bg-surface px-1">AI_PROVIDER</code>
210
+ and
211
+ <code className="mx-1 rounded bg-surface px-1">AI_API_KEY</code>
212
+ in the environment to turn on AI runs.
213
+ </p>
214
+ )
215
+ }
216
+ if (settings.monthlyLimit === 0) {
217
+ return <p className="mt-4 text-[13px] text-ink-muted">AI runs are not included for this workspace. Your own agent still works over MCP.</p>
218
+ }
219
+ if (settings.enabled) {
220
+ return <></>
221
+ }
222
+
223
+ return (
224
+ <div className="mt-4 space-y-2">
225
+ {save.error !== null && <ErrorPanel error={save.error} />}
226
+ <button
227
+ type="button"
228
+ disabled={save.isPending}
229
+ onClick={() => {
230
+ save.run({})
231
+ }}
232
+ className={primaryButtonClass}
233
+ >
234
+ {save.isPending ? 'Saving…' : 'Enable AI'}
235
+ </button>
236
+ </div>
237
+ )
238
+ }
239
+
240
+ /**
241
+ * Whether Add from notes may search the web. Saves on change: it is one
242
+ * switch, and the provider and key are untouched, so either key mode sends it.
243
+ */
244
+ function WebSearchToggle({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
245
+ const save = useSaveAiSettings()
246
+
247
+ return (
248
+ <div className="mt-4 space-y-2 border-t border-border pt-4">
249
+ <label className="flex items-start gap-2 text-[13px] text-ink">
250
+ <input
251
+ type="checkbox"
252
+ className="mt-0.5"
253
+ checked={settings.webSearch}
254
+ disabled={save.isPending}
255
+ onChange={(event) => {
256
+ save.run({ webSearch: event.target.checked })
257
+ }}
258
+ />
259
+ <span>
260
+ <span className="font-medium">Web search</span>
261
+ <span className="block text-[12px] text-ink-muted">
262
+ Add from notes on People may use the provider's web search to research a person. Agent-task runs never
263
+ search. Turn this off to work from pasted notes and the CRM only.
264
+ </span>
265
+ </span>
266
+ </label>
267
+ {save.error !== null && <ErrorPanel error={save.error} />}
268
+ </div>
269
+ )
270
+ }
271
+
272
+ /**
273
+ * Kelpie AI is a hosted service: its provider and model are its own, so the
274
+ * panel names the service and leaves them out. A custom provider is the
275
+ * workspace's own, so the panel shows which one and which model.
276
+ */
277
+ function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
278
+ const disable = useDisableAi()
279
+ const label = AI_SERVICE_LABELS[settings.service]
280
+ const isHosted = settings.service === 'kelpie_ai'
281
+
282
+ return (
283
+ <section className="rounded-md border border-border p-5">
284
+ <div className="flex flex-wrap items-center gap-2">
285
+ <h2 className="text-[15px] font-semibold text-ink">{label}</h2>
286
+ <Chip tone={settings.enabled ? 'success' : 'neutral'}>{settings.enabled ? 'Enabled' : 'Not enabled'}</Chip>
287
+ </div>
288
+ <p className="mt-2 max-w-2xl text-[13px] leading-relaxed text-ink-muted">
289
+ {isHosted
290
+ ? 'Kelpie AI runs agent tasks for you: enrichment, summaries, follow-ups and notes.'
291
+ : 'Run agent tasks on your own OpenAI or Anthropic key: enrichment, summaries, follow-ups and notes.'}{' '}
292
+ Kelpie reads the record and its neighbours, asks the model for a reply, and applies that reply through the
293
+ same tools any agent uses.
294
+ </p>
295
+
296
+ <dl className="mt-4 grid max-w-md grid-cols-2 gap-y-2 text-[13px]">
297
+ {!isHosted && settings.provider !== null && (
298
+ <>
299
+ <dt className="text-ink-muted">Provider</dt>
300
+ <dd className="text-ink">{AI_PROVIDER_LABELS[settings.provider]}</dd>
301
+ <dt className="text-ink-muted">Model</dt>
302
+ <dd className="font-mono text-ink">{settings.model}</dd>
303
+ </>
304
+ )}
305
+ <dt className="text-ink-muted">Runs this month</dt>
306
+ <dd className="text-ink">
307
+ {settings.runsThisMonth}
308
+ {settings.monthlyLimit === null ? '' : ` / ${String(settings.monthlyLimit)}`}
309
+ </dd>
310
+ </dl>
311
+
312
+ {settings.keyMode === 'workspace' ? (
313
+ <WorkspaceKeyForm
314
+ // Remount on a saved change, so the form starts from what the server now holds.
315
+ key={`${settings.provider ?? 'none'}:${settings.model}:${settings.keySource ?? 'none'}:${settings.keyHint ?? ''}`}
316
+ settings={settings}
317
+ />
318
+ ) : (
319
+ <DeploymentKeyControls settings={settings} />
320
+ )}
321
+
322
+ {settings.enabled && settings.configured && <WebSearchToggle settings={settings} />}
323
+
324
+ {settings.enabled && (
325
+ <div className="mt-4 space-y-2 border-t border-border pt-4">
326
+ {disable.error !== null && <ErrorPanel error={disable.error} />}
327
+ <button
328
+ type="button"
329
+ disabled={disable.isPending}
330
+ onClick={() => {
331
+ disable.run()
332
+ }}
333
+ className="rounded-md border border-danger px-3.5 py-2 text-[12px] font-medium text-danger disabled:opacity-50"
334
+ >
335
+ {disable.isPending ? 'Disabling…' : 'Disable AI'}
336
+ </button>
337
+ <p className="text-[12px] text-ink-muted">
338
+ Disabling removes {label} from the Run menu
339
+ {settings.keySource === 'workspace' ? ' and deletes the stored key' : ''}. The run log is kept.
340
+ </p>
341
+ </div>
342
+ )}
343
+ </section>
344
+ )
345
+ }
346
+
347
+ /** `22012 in · 1576 out`, or null when the run recorded no token counts. */
348
+ function tokens(run: AiRun): string | null {
349
+ return run.inputTokens === null || run.outputTokens === null
350
+ ? null
351
+ : `${String(run.inputTokens)} in · ${String(run.outputTokens)} out`
352
+ }
353
+
354
+ /**
355
+ * `Company · Acme`, with the name linked to the record's page, as an Activity
356
+ * row names its record. Nothing for a `workspace` target. The type alone when
357
+ * the record has no name, because it has since been deleted.
358
+ */
359
+ function RunTarget({ run }: { readonly run: AiRun }): React.JSX.Element | null {
360
+ if (run.targetType === 'workspace') {
361
+ return null
362
+ }
363
+
364
+ const href = targetHref(run.targetType === 'handbook' ? 'handbook_page' : run.targetType, run.targetId)
365
+
366
+ return (
367
+ <span className="text-[12px] text-ink-muted">
368
+ {TARGET_TYPE_LABELS[run.targetType]}
369
+ {run.targetName !== null && (
370
+ <>
371
+ {' · '}
372
+ {href === undefined ? (
373
+ run.targetName
374
+ ) : (
375
+ <Link to={href} title={run.targetId} className="hover:text-accent hover:underline">
376
+ {run.targetName}
377
+ </Link>
378
+ )}
379
+ </>
380
+ )}
381
+ </span>
382
+ )
383
+ }
384
+
385
+ function RunLog(): React.JSX.Element {
386
+ const list = useAiRuns()
387
+ const serviceLabel = useAiServiceLabel()
388
+ // Kelpie AI's model is the hosted service's own, as on the Settings tab.
389
+ const showModel = useAiSettings().record?.service !== 'kelpie_ai'
390
+ const { records: runs, isLoading, error } = list
391
+ const timezone = useTimezone()
392
+
393
+ return (
394
+ <section className="rounded-md border border-border p-5">
395
+ <h2 className="text-[15px] font-semibold text-ink">Run log</h2>
396
+ {isLoading && <LoadingPanel label="Loading runs…" />}
397
+ {error !== null && <ErrorPanel error={error} />}
398
+ {!isLoading && error === null && runs.length === 0 && (
399
+ <p className="mt-2 text-[13px] text-ink-muted">
400
+ No runs yet. Start one from the Agent menu on any record page and pick <em>{serviceLabel}</em>.
401
+ </p>
402
+ )}
403
+ {runs.length > 0 && (
404
+ <ul className="mt-3 flex flex-col gap-2">
405
+ {runs.map((run) => (
406
+ <li key={run.id} className="rounded-md border border-border bg-surface p-3">
407
+ <div className="flex flex-wrap items-center gap-2">
408
+ <Chip tone={STATUS_TONES[run.status]}>{run.status}</Chip>
409
+ <span className="text-[13px] font-medium text-ink">{run.taskId}</span>
410
+ <RunTarget run={run} />
411
+ <span className="ml-auto text-[12px] text-ink-faint">{formatRelativeTime(run.createdAt, timezone)}</span>
412
+ </div>
413
+ <p className="mt-1 text-[12px] text-ink-muted">
414
+ {showModel && <span className="font-mono">{run.model}</span>}
415
+ {showModel && tokens(run) !== null && ' · '}
416
+ {tokens(run)}
417
+ </p>
418
+ {run.failureReason !== null && <p className="mt-2 text-[12px] text-danger">{run.failureReason}</p>}
419
+ {run.operations !== null && run.operations.length > 0 && (
420
+ <ul className="mt-2 flex flex-col gap-1">
421
+ {run.operations.map((operation, index) => (
422
+ <li key={`${run.id}-op-${String(index)}`} className="flex flex-wrap items-center gap-2 text-[12px]">
423
+ <Chip tone={OPERATION_TONES[operation.status] ?? 'neutral'}>{operation.status}</Chip>
424
+ <span className="font-medium text-ink">{operation.kind}</span>
425
+ <span className="text-ink-muted">
426
+ <LinkedText text={operation.detail} references={operation.references} />
427
+ </span>
428
+ </li>
429
+ ))}
430
+ </ul>
431
+ )}
432
+ </li>
433
+ ))}
434
+ </ul>
435
+ )}
436
+ {runs.length > 0 && <Paginator list={list} />}
437
+ </section>
438
+ )
439
+ }
440
+
441
+ /** The Settings tab the `ai` module adds to Admin → AI. */
442
+ export function AiSettingsTab(): React.JSX.Element {
443
+ const { record: settings, isLoading, error } = useAiSettings()
444
+
445
+ return (
446
+ <>
447
+ {isLoading && <LoadingPanel label="Loading AI settings…" />}
448
+ {error !== null && <ErrorPanel error={error} />}
449
+ {settings !== undefined && <SettingsPanel settings={settings} />}
450
+ </>
451
+ )
452
+ }
453
+
454
+ /** The Run log tab the `ai` module adds to Admin → AI. */
455
+ export function AiRunLogTab(): React.JSX.Element {
456
+ return <RunLog />
457
+ }
@@ -12,14 +12,13 @@ import {
12
12
  useDeleteAgent,
13
13
  } from '../../api/resources/agentTasks.ts'
14
14
  import { useMcpTools } from '../../api/resources/mcpTools.ts'
15
- import { PageHeader } from '../../components/PageHeader.tsx'
16
15
  import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
17
16
  import { CopyButton } from '../../components/CopyButton.tsx'
18
17
  import { formatRelativeTime } from '../../lib/dates.ts'
19
18
  import { mcpClientConfig, mcpEndpoint } from '../../lib/mcpConfig.ts'
20
19
 
21
20
  /**
22
- * How an agent connects to this workspace.
21
+ * How an agent connects to this workspace: the MCP tab on Admin → AI.
23
22
  *
24
23
  * Everything on the page is derived rather than written down. The endpoint comes
25
24
  * from the origin the browser reached the app on, the same way a form's embed URL
@@ -50,21 +49,20 @@ function matches(tool: McpTool, term: string): boolean {
50
49
  )
51
50
  }
52
51
 
53
- export function McpPage(): React.JSX.Element {
52
+ /** The MCP tab on Admin → AI. Core, so every install has it. */
53
+ export function McpPanel(): React.JSX.Element {
54
54
  const endpoint = mcpEndpoint()
55
55
  const config = mcpClientConfig(endpoint, 'kp_live_…')
56
56
 
57
57
  return (
58
- <div className="animate-slide-in mx-auto max-w-4xl space-y-6">
59
- <PageHeader title="MCP" description="Connect agents to this workspace over Streamable HTTP." />
60
-
58
+ <div className="space-y-6">
61
59
  <section className="rounded-md border border-border p-5">
62
60
  <h2 className="text-[15px] font-semibold text-ink">How agents use Kelpie</h2>
63
61
  <p className="mt-2 max-w-2xl text-[13px] leading-relaxed text-ink-muted">
64
62
  Kelpie is a CRM and a company brain. Every REST operation is also an MCP tool over
65
63
  Streamable HTTP, so an agent reads and writes the same records the app does, through the
66
- same API. Point Claude, Cursor, or any MCP client at this workspace. There is no bundled
67
- AI: bring your own agent.
64
+ same API. Point Claude, Cursor, or any MCP client at this workspace: bring your own agent.
65
+ An install with the AI module can also run tasks on your own OpenAI or Anthropic key.
68
66
  </p>
69
67
  <ul className="mt-4 space-y-2 text-[13px] text-ink">
70
68
  <li className="flex gap-2">
@@ -251,9 +249,15 @@ function RegisteredAgents(): React.JSX.Element {
251
249
  <li key={agent.id} className="flex flex-wrap items-center justify-between gap-3 px-3 py-2.5">
252
250
  <div className="min-w-0">
253
251
  <div className="text-[13px] font-medium text-ink">{agent.name}</div>
254
- <code className="font-mono text-[11px] break-all text-ink-muted">
255
- {agent.endpoint}
256
- </code>
252
+ {agent.managedBy === null ? (
253
+ <code className="font-mono text-[11px] break-all text-ink-muted">
254
+ {agent.endpoint}
255
+ </code>
256
+ ) : (
257
+ // A module-managed agent is dispatched in-process; its stored
258
+ // endpoint is not an address anything calls.
259
+ <span className="text-[11px] text-ink-muted">Runs inside Kelpie ({agent.managedBy} module)</span>
260
+ )}
257
261
  </div>
258
262
  <div className="flex shrink-0 items-center gap-3 text-[11px] text-ink-faint">
259
263
  {agent.hasAuthHeader && <span>Auth header set</span>}
@@ -58,12 +58,15 @@ function PurposesAdmin(): React.JSX.Element {
58
58
  slug: 'contact',
59
59
  label: 'Contact',
60
60
  description: 'Being contacted by the workspace about our work together.',
61
+ statement:
62
+ 'I consent to {{workspace}} contacting me and retaining my information for the purpose of handling my enquiry.',
61
63
  defaultStatus: 'unknown',
62
64
  })
63
65
  await create.runAsync({
64
66
  slug: 'marketing',
65
67
  label: 'Marketing',
66
68
  description: 'Marketing communications — newsletters, product updates, and campaigns.',
69
+ statement: 'I consent to {{workspace}} retaining my information for marketing purposes.',
67
70
  defaultStatus: 'unknown',
68
71
  })
69
72
  } catch {
@@ -165,6 +168,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
165
168
  const [slug, setSlug] = useState('')
166
169
  const [slugEdited, setSlugEdited] = useState(false)
167
170
  const [description, setDescription] = useState('')
171
+ const [statement, setStatement] = useState('')
168
172
  const [defaultStatus, setDefaultStatus] = useState<ConsentPurposeStatus>('unknown')
169
173
 
170
174
  const derivedSlug = useMemo(
@@ -183,6 +187,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
183
187
  slug: derivedSlug,
184
188
  label: trimmedLabel,
185
189
  description: description.trim(),
190
+ statement: statement.trim(),
186
191
  defaultStatus,
187
192
  })
188
193
  .then(() => {
@@ -190,6 +195,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
190
195
  setSlug('')
191
196
  setSlugEdited(false)
192
197
  setDescription('')
198
+ setStatement('')
193
199
  setDefaultStatus('unknown')
194
200
  onDone()
195
201
  })
@@ -252,6 +258,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
252
258
  }}
253
259
  />
254
260
  </Field>
261
+ <StatementField value={statement} onChange={setStatement} />
255
262
 
256
263
  {create.error !== null && <ErrorPanel error={create.error} />}
257
264
 
@@ -277,6 +284,32 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
277
284
  )
278
285
  }
279
286
 
287
+ /**
288
+ * The consent statement a form shows beside this purpose's checkbox. The
289
+ * Person record keeps showing the label.
290
+ */
291
+ function StatementField({
292
+ value,
293
+ onChange,
294
+ }: {
295
+ readonly value: string
296
+ readonly onChange: (value: string) => void
297
+ }): React.JSX.Element {
298
+ return (
299
+ <Field label="Consent statement (shown on forms instead of the label; {{workspace}} becomes the workspace name)">
300
+ <textarea
301
+ className="min-h-[60px] w-full rounded-md border border-border bg-transparent px-2 py-1 text-[13px] outline-none focus:border-accent"
302
+ value={value}
303
+ maxLength={1000}
304
+ placeholder="I consent to {{workspace}} …"
305
+ onChange={(event) => {
306
+ onChange(event.target.value)
307
+ }}
308
+ />
309
+ </Field>
310
+ )
311
+ }
312
+
280
313
  interface PurposeRowProps {
281
314
  readonly purpose: ConsentPurpose
282
315
  }
@@ -287,6 +320,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
287
320
  const [editing, setEditing] = useState(false)
288
321
  const [label, setLabel] = useState(purpose.label)
289
322
  const [description, setDescription] = useState(purpose.description)
323
+ const [statement, setStatement] = useState(purpose.statement)
290
324
  const [defaultStatus, setDefaultStatus] = useState<ConsentPurposeStatus>(purpose.defaultStatus)
291
325
  const [confirmingDelete, setConfirmingDelete] = useState(false)
292
326
 
@@ -298,6 +332,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
298
332
  changes: {
299
333
  label: label.trim(),
300
334
  description: description.trim(),
335
+ statement: statement.trim(),
301
336
  defaultStatus,
302
337
  },
303
338
  })
@@ -325,6 +360,12 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
325
360
  {purpose.description.length > 0 && (
326
361
  <p className="mt-1 text-[12px] text-ink-muted">{purpose.description}</p>
327
362
  )}
363
+ {purpose.statement.length > 0 && (
364
+ <p className="mt-1 text-[12px] text-ink">
365
+ <span className="text-ink-faint">On forms: </span>
366
+ {purpose.statement}
367
+ </p>
368
+ )}
328
369
  </div>
329
370
  <div className="flex shrink-0 gap-2">
330
371
  <button
@@ -384,6 +425,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
384
425
  }}
385
426
  />
386
427
  </Field>
428
+ <StatementField value={statement} onChange={setStatement} />
387
429
  {update.error !== null && <ErrorPanel error={update.error} />}
388
430
  <div className="flex justify-end">
389
431
  <button