@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,131 @@
1
+ import { API_KEY_SCOPE_LABELS } from '@kelpie/schemas'
2
+ import type { OAuthGrant } from '@kelpie/schemas'
3
+ import { useState } from 'react'
4
+
5
+ import { useTimezone } from '../../api/resources/account.ts'
6
+ import { useOAuthGrants, useRevokeOAuthGrant } from '../../api/resources/oauth.ts'
7
+ import { PageHeader } from '../../components/PageHeader.tsx'
8
+ import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
9
+ import { formatDate } from '../../lib/dates.ts'
10
+
11
+ /**
12
+ * MCP clients this person connected through OAuth, across every workspace they
13
+ * belong to. Private to them, as personal API keys are: an admin's control is
14
+ * removing the member, which ends every connection in that workspace.
15
+ */
16
+ export function ConnectedAppsPage(): React.JSX.Element {
17
+ const { grants, isLoading, error } = useOAuthGrants()
18
+ const revoke = useRevokeOAuthGrant()
19
+
20
+ return (
21
+ <div className="animate-slide-in space-y-4">
22
+ <PageHeader
23
+ title="Connected apps"
24
+ description="Apps you connected through MCP sign-in. Each one acts as you, in one workspace."
25
+ />
26
+
27
+ {error !== null && <ErrorPanel error={error} />}
28
+ {revoke.error !== null && <ErrorPanel error={revoke.error} />}
29
+
30
+ {isLoading ? (
31
+ <LoadingPanel label="Loading connected apps…" />
32
+ ) : grants.length === 0 ? (
33
+ <p className="rounded-md border border-border px-4 py-10 text-center text-[13px] text-ink-faint">
34
+ No connected apps. When an MCP client asks you to sign in to Kelpie, it shows up here.
35
+ </p>
36
+ ) : (
37
+ <div className="overflow-hidden rounded-md border border-border">
38
+ <table className="w-full text-left text-[13px]">
39
+ <thead>
40
+ <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
41
+ <th className="px-4 py-2.5">App</th>
42
+ <th className="px-4 py-2.5">Workspace</th>
43
+ <th className="px-4 py-2.5">Access</th>
44
+ <th className="px-4 py-2.5">Connected</th>
45
+ <th className="px-4 py-2.5">Last used</th>
46
+ <th className="px-4 py-2.5 text-right">Actions</th>
47
+ </tr>
48
+ </thead>
49
+ <tbody>
50
+ {grants.map((grant) => (
51
+ <GrantRow
52
+ key={grant.id}
53
+ grant={grant}
54
+ onRevoke={(id) => {
55
+ revoke.run(id)
56
+ }}
57
+ isRevoking={revoke.isPending}
58
+ />
59
+ ))}
60
+ </tbody>
61
+ </table>
62
+ </div>
63
+ )}
64
+ </div>
65
+ )
66
+ }
67
+
68
+ function GrantRow({
69
+ grant,
70
+ onRevoke,
71
+ isRevoking,
72
+ }: {
73
+ readonly grant: OAuthGrant
74
+ readonly onRevoke: (id: string) => void
75
+ readonly isRevoking: boolean
76
+ }): React.JSX.Element {
77
+ const [isConfirming, setIsConfirming] = useState(false)
78
+ const timezone = useTimezone()
79
+
80
+ return (
81
+ <tr className="border-b border-border last:border-0">
82
+ <td className="px-4 py-3">
83
+ <div className="font-medium">{grant.clientName}</div>
84
+ <div className="font-mono text-[11px] text-ink-muted">{grant.clientHost}</div>
85
+ </td>
86
+ <td className="px-4 py-3 text-ink-muted">{grant.workspaceName}</td>
87
+ <td className="px-4 py-3 text-ink-muted">
88
+ {grant.scopes.map((scope) => API_KEY_SCOPE_LABELS[scope]).join(', ')}
89
+ </td>
90
+ <td className="px-4 py-3 text-ink-muted">{formatDate(grant.createdAt, timezone)}</td>
91
+ <td className="px-4 py-3 text-ink-muted">
92
+ {grant.lastUsedAt === null ? 'Never' : formatDate(grant.lastUsedAt, timezone)}
93
+ </td>
94
+ <td className="px-4 py-3 text-right">
95
+ {isConfirming ? (
96
+ <span className="inline-flex items-center gap-3">
97
+ <button
98
+ type="button"
99
+ onClick={() => {
100
+ setIsConfirming(false)
101
+ }}
102
+ className="text-[12px] font-medium text-ink-muted hover:text-ink"
103
+ >
104
+ Cancel
105
+ </button>
106
+ <button
107
+ type="button"
108
+ disabled={isRevoking}
109
+ onClick={() => {
110
+ onRevoke(grant.id)
111
+ }}
112
+ className="text-[12px] font-medium text-danger hover:underline disabled:opacity-50"
113
+ >
114
+ {isRevoking ? 'Disconnecting…' : 'Disconnect'}
115
+ </button>
116
+ </span>
117
+ ) : (
118
+ <button
119
+ type="button"
120
+ onClick={() => {
121
+ setIsConfirming(true)
122
+ }}
123
+ className="text-[12px] font-medium text-danger hover:underline"
124
+ >
125
+ Disconnect
126
+ </button>
127
+ )}
128
+ </td>
129
+ </tr>
130
+ )
131
+ }
@@ -0,0 +1,353 @@
1
+ import { AI_DEFAULT_MODELS, AI_PROVIDER_LABELS, AI_PROVIDERS } from '@kelpie/schemas'
2
+ import type { AiProvider, AiRun, AiSettings, AiSettingsInput } from '@kelpie/schemas'
3
+ import { useState } from 'react'
4
+ import type { FormEvent } from 'react'
5
+
6
+ import { useTimezone } from '../../api/resources/account.ts'
7
+ import { useAiRuns, useAiSettings, useDisableAi, useSaveAiSettings } from '../../api/resources/ai.ts'
8
+ import { Chip } from '../../components/Chip.tsx'
9
+ import type { ChipTone } from '../../components/Chip.tsx'
10
+ import { PageHeader } from '../../components/PageHeader.tsx'
11
+ import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
12
+ import { formatRelativeTime } from '../../lib/dates.ts'
13
+
14
+ /**
15
+ * The AI admin page at `/admin/ai`, from the optional `ai` module.
16
+ *
17
+ * Two parts: the settings for Kelpie AI in this workspace, and its run log.
18
+ * Both read the same `/v1/ai/*` endpoints an agent would use.
19
+ *
20
+ * What the settings part shows depends on the module's key mode. In
21
+ * `workspace` mode an admin picks a provider, pastes their own API key, and
22
+ * may name a model. The key is write-only: the page shows its last four
23
+ * characters and never the key. In `deployment` mode the operator's
24
+ * environment decides all three, and the page offers only enable and disable.
25
+ */
26
+
27
+ const STATUS_TONES: Readonly<Record<AiRun['status'], ChipTone>> = {
28
+ queued: 'neutral',
29
+ running: 'accent',
30
+ succeeded: 'success',
31
+ failed: 'danger',
32
+ }
33
+
34
+ const OPERATION_TONES: Readonly<Record<string, ChipTone>> = {
35
+ applied: 'success',
36
+ failed: 'danger',
37
+ skipped: 'neutral',
38
+ }
39
+
40
+ const inputClass =
41
+ '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'
42
+ const primaryButtonClass =
43
+ 'rounded-md bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover disabled:opacity-50'
44
+ const secondaryButtonClass =
45
+ 'rounded-md border border-border px-3.5 py-2 text-[12px] font-medium text-ink transition hover:border-border-strong disabled:opacity-50'
46
+
47
+ function keyDescription(settings: AiSettings): string {
48
+ if (settings.keySource === 'workspace') {
49
+ return settings.keyHint === null ? 'Your key is stored.' : `Your key ending in ${settings.keyHint} is stored.`
50
+ }
51
+ if (settings.keySource === 'environment') {
52
+ return 'This install supplies a key. Enter your own to use it instead.'
53
+ }
54
+
55
+ return 'No key is stored.'
56
+ }
57
+
58
+ /**
59
+ * Provider, key and model for `workspace` key mode.
60
+ *
61
+ * Only changed fields are sent. The server keeps what is omitted, and drops the
62
+ * stored key and model when the provider changes, so this form clears the model
63
+ * field on a provider change to match.
64
+ */
65
+ function WorkspaceKeyForm({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
66
+ const save = useSaveAiSettings()
67
+ const [provider, setProvider] = useState<AiProvider>(settings.provider ?? 'openai')
68
+ const [apiKey, setApiKey] = useState('')
69
+ const [model, setModel] = useState(settings.provider === null ? '' : settings.model)
70
+
71
+ const providerChanged = provider !== settings.provider
72
+ const defaultModel = AI_DEFAULT_MODELS[provider]
73
+
74
+ /** `undefined` keeps the stored model, `null` clears it back to the default. */
75
+ function modelChange(): string | null | undefined {
76
+ const trimmed = model.trim()
77
+
78
+ if (trimmed === '') {
79
+ // Nothing to clear when the workspace has not chosen a provider yet.
80
+ if (settings.provider === null) return undefined
81
+ return providerChanged || settings.model !== defaultModel ? null : undefined
82
+ }
83
+
84
+ return !providerChanged && trimmed === settings.model ? undefined : trimmed
85
+ }
86
+
87
+ function changes(): AiSettingsInput {
88
+ const nextModel = modelChange()
89
+
90
+ return {
91
+ ...(providerChanged ? { provider } : {}),
92
+ ...(apiKey.trim() === '' ? {} : { apiKey: apiKey.trim() }),
93
+ ...(nextModel === undefined ? {} : { model: nextModel }),
94
+ }
95
+ }
96
+
97
+ function submit(formEvent: FormEvent): void {
98
+ formEvent.preventDefault()
99
+ save
100
+ .runAsync(changes())
101
+ .then(() => {
102
+ setApiKey('')
103
+ })
104
+ .catch(() => undefined)
105
+ }
106
+
107
+ return (
108
+ <form onSubmit={submit} className="mt-4 space-y-3">
109
+ <label className="block">
110
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">Provider</span>
111
+ <select
112
+ value={provider}
113
+ onChange={(event) => {
114
+ setProvider(event.target.value as AiProvider)
115
+ setModel('')
116
+ }}
117
+ className="w-48 rounded-md border border-border bg-surface-raised px-3 py-2 text-[13px] outline-none focus:border-accent"
118
+ >
119
+ {AI_PROVIDERS.map((option) => (
120
+ <option key={option} value={option}>
121
+ {AI_PROVIDER_LABELS[option]}
122
+ </option>
123
+ ))}
124
+ </select>
125
+ </label>
126
+
127
+ <label className="block">
128
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">API key</span>
129
+ <input
130
+ type="password"
131
+ autoComplete="off"
132
+ value={apiKey}
133
+ onChange={(event) => {
134
+ setApiKey(event.target.value)
135
+ }}
136
+ placeholder={providerChanged ? `Paste your ${AI_PROVIDER_LABELS[provider]} API key` : 'Paste a new key to replace it'}
137
+ className={`${inputClass} font-mono`}
138
+ />
139
+ <span className="mt-1.5 block text-[12px] text-ink-muted">
140
+ {providerChanged && settings.keySource === 'workspace'
141
+ ? 'Changing provider removes the stored key.'
142
+ : keyDescription(settings)}{' '}
143
+ The key is stored encrypted and is never shown again.
144
+ </span>
145
+ </label>
146
+
147
+ <label className="block">
148
+ <span className="mb-1.5 block text-[12px] font-medium text-ink">Model</span>
149
+ <input
150
+ value={model}
151
+ onChange={(event) => {
152
+ setModel(event.target.value)
153
+ }}
154
+ placeholder={defaultModel}
155
+ className={`${inputClass} font-mono`}
156
+ />
157
+ <span className="mt-1.5 block text-[12px] text-ink-muted">Leave it empty to use {defaultModel}.</span>
158
+ </label>
159
+
160
+ {save.error !== null && <ErrorPanel error={save.error} />}
161
+
162
+ <div className="flex flex-wrap gap-2">
163
+ <button type="submit" disabled={save.isPending} className={primaryButtonClass}>
164
+ {save.isPending ? 'Saving…' : settings.enabled ? 'Save' : 'Enable AI'}
165
+ </button>
166
+ {settings.enabled && settings.keySource === 'workspace' && !providerChanged && (
167
+ <button
168
+ type="button"
169
+ disabled={save.isPending}
170
+ onClick={() => {
171
+ save.run({ apiKey: null })
172
+ }}
173
+ className={secondaryButtonClass}
174
+ >
175
+ Remove stored key
176
+ </button>
177
+ )}
178
+ </div>
179
+ </form>
180
+ )
181
+ }
182
+
183
+ function DeploymentKeyControls({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
184
+ const save = useSaveAiSettings()
185
+
186
+ if (!settings.configured) {
187
+ return (
188
+ <p className="mt-3 text-[13px] text-ink-muted">
189
+ The operator has not set up a provider for this install. Set
190
+ <code className="mx-1 rounded bg-surface px-1">AI_PROVIDER</code>
191
+ and
192
+ <code className="mx-1 rounded bg-surface px-1">AI_API_KEY</code>
193
+ in the environment to turn on AI runs.
194
+ </p>
195
+ )
196
+ }
197
+ if (settings.monthlyLimit === 0) {
198
+ 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>
199
+ }
200
+ if (settings.enabled) {
201
+ return <></>
202
+ }
203
+
204
+ return (
205
+ <div className="mt-4 space-y-2">
206
+ {save.error !== null && <ErrorPanel error={save.error} />}
207
+ <button
208
+ type="button"
209
+ disabled={save.isPending}
210
+ onClick={() => {
211
+ save.run({})
212
+ }}
213
+ className={primaryButtonClass}
214
+ >
215
+ {save.isPending ? 'Saving…' : 'Enable AI'}
216
+ </button>
217
+ </div>
218
+ )
219
+ }
220
+
221
+ function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
222
+ const disable = useDisableAi()
223
+
224
+ return (
225
+ <section className="rounded-md border border-border p-5">
226
+ <div className="flex flex-wrap items-center gap-2">
227
+ <h2 className="text-[15px] font-semibold text-ink">Kelpie AI</h2>
228
+ <Chip tone={settings.enabled ? 'success' : 'neutral'}>{settings.enabled ? 'Enabled' : 'Not enabled'}</Chip>
229
+ </div>
230
+ <p className="mt-2 max-w-2xl text-[13px] leading-relaxed text-ink-muted">
231
+ Kelpie AI runs agent tasks for you: enrichment, summaries, follow-ups and notes. It reads the record and its
232
+ neighbours, asks the model for a reply, and applies that reply through the same tools any agent uses.
233
+ </p>
234
+
235
+ <dl className="mt-4 grid max-w-md grid-cols-2 gap-y-2 text-[13px]">
236
+ {settings.provider !== null && (
237
+ <>
238
+ <dt className="text-ink-muted">Provider</dt>
239
+ <dd className="text-ink">{AI_PROVIDER_LABELS[settings.provider]}</dd>
240
+ <dt className="text-ink-muted">Model</dt>
241
+ <dd className="font-mono text-ink">{settings.model}</dd>
242
+ </>
243
+ )}
244
+ <dt className="text-ink-muted">Runs this month</dt>
245
+ <dd className="text-ink">
246
+ {settings.runsThisMonth}
247
+ {settings.monthlyLimit === null ? '' : ` / ${String(settings.monthlyLimit)}`}
248
+ </dd>
249
+ </dl>
250
+
251
+ {settings.keyMode === 'workspace' ? (
252
+ <WorkspaceKeyForm
253
+ // Remount on a saved change, so the form starts from what the server now holds.
254
+ key={`${settings.provider ?? 'none'}:${settings.model}:${settings.keySource ?? 'none'}:${settings.keyHint ?? ''}`}
255
+ settings={settings}
256
+ />
257
+ ) : (
258
+ <DeploymentKeyControls settings={settings} />
259
+ )}
260
+
261
+ {settings.enabled && (
262
+ <div className="mt-4 space-y-2 border-t border-border pt-4">
263
+ {disable.error !== null && <ErrorPanel error={disable.error} />}
264
+ <button
265
+ type="button"
266
+ disabled={disable.isPending}
267
+ onClick={() => {
268
+ disable.run()
269
+ }}
270
+ className="rounded-md border border-danger px-3.5 py-2 text-[12px] font-medium text-danger disabled:opacity-50"
271
+ >
272
+ {disable.isPending ? 'Disabling…' : 'Disable AI'}
273
+ </button>
274
+ <p className="text-[12px] text-ink-muted">
275
+ Disabling removes Kelpie AI from the Run menu
276
+ {settings.keySource === 'workspace' ? ' and deletes the stored key' : ''}. The run log is kept.
277
+ </p>
278
+ </div>
279
+ )}
280
+ </section>
281
+ )
282
+ }
283
+
284
+ function RunLog(): React.JSX.Element {
285
+ const { records: runs, isLoading, error } = useAiRuns()
286
+ const timezone = useTimezone()
287
+
288
+ return (
289
+ <section className="rounded-md border border-border p-5">
290
+ <h2 className="text-[15px] font-semibold text-ink">Run log</h2>
291
+ {isLoading && <LoadingPanel label="Loading runs…" />}
292
+ {error !== null && <ErrorPanel error={error} />}
293
+ {!isLoading && error === null && runs.length === 0 && (
294
+ <p className="mt-2 text-[13px] text-ink-muted">
295
+ No runs yet. Start one from the Agent menu on any record page and pick <em>Kelpie AI</em>.
296
+ </p>
297
+ )}
298
+ {runs.length > 0 && (
299
+ <ul className="mt-3 flex flex-col gap-2">
300
+ {runs.map((run) => (
301
+ <li key={run.id} className="rounded-md border border-border bg-surface p-3">
302
+ <div className="flex flex-wrap items-center gap-2">
303
+ <Chip tone={STATUS_TONES[run.status]}>{run.status}</Chip>
304
+ <span className="text-[13px] font-medium text-ink">{run.taskId}</span>
305
+ <span className="text-[12px] text-ink-muted">
306
+ {run.targetType} · {run.targetId}
307
+ </span>
308
+ <span className="ml-auto text-[12px] text-ink-faint">{formatRelativeTime(run.createdAt, timezone)}</span>
309
+ </div>
310
+ <p className="mt-1 text-[12px] text-ink-muted">
311
+ <span className="font-mono">{run.model}</span>
312
+ {run.inputTokens !== null && run.outputTokens !== null
313
+ ? ` · ${String(run.inputTokens)} in · ${String(run.outputTokens)} out`
314
+ : ''}
315
+ </p>
316
+ {run.failureReason !== null && <p className="mt-2 text-[12px] text-danger">{run.failureReason}</p>}
317
+ {run.output !== null && (
318
+ <pre className="mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded bg-surface-raised p-2 text-[12px] text-ink">
319
+ {run.output}
320
+ </pre>
321
+ )}
322
+ {run.operations !== null && run.operations.length > 0 && (
323
+ <ul className="mt-2 flex flex-col gap-1">
324
+ {run.operations.map((operation, index) => (
325
+ <li key={`${run.id}-op-${String(index)}`} className="flex flex-wrap items-center gap-2 text-[12px]">
326
+ <Chip tone={OPERATION_TONES[operation.status] ?? 'neutral'}>{operation.status}</Chip>
327
+ <span className="font-medium text-ink">{operation.kind}</span>
328
+ <span className="text-ink-muted">{operation.detail}</span>
329
+ </li>
330
+ ))}
331
+ </ul>
332
+ )}
333
+ </li>
334
+ ))}
335
+ </ul>
336
+ )}
337
+ </section>
338
+ )
339
+ }
340
+
341
+ export function AiPage(): React.JSX.Element {
342
+ const { record: settings, isLoading, error } = useAiSettings()
343
+
344
+ return (
345
+ <div className="animate-slide-in mx-auto max-w-4xl space-y-6">
346
+ <PageHeader title="AI" description="Run agent tasks with your own model provider." />
347
+ {isLoading && <LoadingPanel label="Loading AI settings…" />}
348
+ {error !== null && <ErrorPanel error={error} />}
349
+ {settings !== undefined && <SettingsPanel settings={settings} />}
350
+ <RunLog />
351
+ </div>
352
+ )
353
+ }
@@ -16,6 +16,7 @@ import { PageHeader } from '../../components/PageHeader.tsx'
16
16
  import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
17
17
  import { CopyButton } from '../../components/CopyButton.tsx'
18
18
  import { formatRelativeTime } from '../../lib/dates.ts'
19
+ import { mcpClientConfig, mcpEndpoint } from '../../lib/mcpConfig.ts'
19
20
 
20
21
  /**
21
22
  * How an agent connects to this workspace.
@@ -50,17 +51,8 @@ function matches(tool: McpTool, term: string): boolean {
50
51
  }
51
52
 
52
53
  export function McpPage(): React.JSX.Element {
53
- const endpoint = new URL('/mcp', window.location.origin).toString()
54
- const config = `{
55
- "mcpServers": {
56
- "kelpie": {
57
- "url": "${endpoint}",
58
- "headers": {
59
- "Authorization": "Bearer kp_live_…"
60
- }
61
- }
62
- }
63
- }`
54
+ const endpoint = mcpEndpoint()
55
+ const config = mcpClientConfig(endpoint, 'kp_live_…')
64
56
 
65
57
  return (
66
58
  <div className="animate-slide-in mx-auto max-w-4xl space-y-6">
@@ -71,8 +63,8 @@ export function McpPage(): React.JSX.Element {
71
63
  <p className="mt-2 max-w-2xl text-[13px] leading-relaxed text-ink-muted">
72
64
  Kelpie is a CRM and a company brain. Every REST operation is also an MCP tool over
73
65
  Streamable HTTP, so an agent reads and writes the same records the app does, through the
74
- same API. Point Claude, Cursor, or any MCP client at this workspace. There is no bundled
75
- AI: bring your own agent.
66
+ same API. Point Claude, Cursor, or any MCP client at this workspace: bring your own agent.
67
+ An install with the AI module can also run tasks on your own OpenAI or Anthropic key.
76
68
  </p>
77
69
  <ul className="mt-4 space-y-2 text-[13px] text-ink">
78
70
  <li className="flex gap-2">
@@ -85,8 +77,8 @@ export function McpPage(): React.JSX.Element {
85
77
  </li>
86
78
  <li className="flex gap-2">
87
79
  <span className="text-accent">→</span>
88
- Signing in with a browser session does not work here. The endpoint takes bearer keys
89
- only.
80
+ A browser session does not work here. The endpoint takes an API key, or a token from
81
+ OAuth sign-in.
90
82
  </li>
91
83
  </ul>
92
84
  </section>
@@ -101,6 +93,19 @@ export function McpPage(): React.JSX.Element {
101
93
  </code>
102
94
  </section>
103
95
 
96
+ <section className="rounded-md border border-border p-5">
97
+ <h2 className="text-[13px] font-semibold text-ink">Sign in with OAuth</h2>
98
+ <p className="mt-1 max-w-2xl text-[12px] text-ink-muted">
99
+ A client that supports MCP sign-in, such as a Claude.ai connector, needs only the endpoint
100
+ URL above. It opens a Kelpie page where you choose a workspace and approve the access. You
101
+ can disconnect it at any time under{' '}
102
+ <Link to="/account/connected-apps" className="text-accent hover:underline">
103
+ Connected apps
104
+ </Link>
105
+ .
106
+ </p>
107
+ </section>
108
+
104
109
  <section className="rounded-md border border-border p-5">
105
110
  <div className="flex items-center justify-between gap-3">
106
111
  <h2 className="text-[13px] font-semibold text-ink">Claude / Cursor config</h2>
@@ -246,9 +251,15 @@ function RegisteredAgents(): React.JSX.Element {
246
251
  <li key={agent.id} className="flex flex-wrap items-center justify-between gap-3 px-3 py-2.5">
247
252
  <div className="min-w-0">
248
253
  <div className="text-[13px] font-medium text-ink">{agent.name}</div>
249
- <code className="font-mono text-[11px] break-all text-ink-muted">
250
- {agent.endpoint}
251
- </code>
254
+ {agent.managedBy === null ? (
255
+ <code className="font-mono text-[11px] break-all text-ink-muted">
256
+ {agent.endpoint}
257
+ </code>
258
+ ) : (
259
+ // A module-managed agent is dispatched in-process; its stored
260
+ // endpoint is not an address anything calls.
261
+ <span className="text-[11px] text-ink-muted">Runs inside Kelpie ({agent.managedBy} module)</span>
262
+ )}
252
263
  </div>
253
264
  <div className="flex shrink-0 items-center gap-3 text-[11px] text-ink-faint">
254
265
  {agent.hasAuthHeader && <span>Auth header set</span>}
@@ -257,15 +268,25 @@ function RegisteredAgents(): React.JSX.Element {
257
268
  ? 'Never run'
258
269
  : `Last run ${formatRelativeTime(agent.lastRunAt, timezone)}`}
259
270
  </span>
260
- <button
261
- type="button"
262
- onClick={() => {
263
- deleteAgent.run(agent.id)
264
- }}
265
- className="font-medium text-danger hover:underline"
266
- >
267
- Remove
268
- </button>
271
+ {agent.managedBy === null ? (
272
+ <button
273
+ type="button"
274
+ onClick={() => {
275
+ deleteAgent.run(agent.id)
276
+ }}
277
+ className="font-medium text-danger hover:underline"
278
+ >
279
+ Remove
280
+ </button>
281
+ ) : agent.settingsPath === null ? (
282
+ // The API refuses to change a row a module owns, so there is
283
+ // no Remove to offer; the module's own settings manage it.
284
+ <span>Managed by a module</span>
285
+ ) : (
286
+ <Link to={agent.settingsPath} className="font-medium text-accent hover:underline">
287
+ Manage in settings
288
+ </Link>
289
+ )}
269
290
  </div>
270
291
  </li>
271
292
  ))}
@@ -8,10 +8,11 @@ import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
8
8
  /**
9
9
  * Turns optional modules on or off for this workspace.
10
10
  *
11
- * A module a deploy-time config file locks (`modules.md`) shows as disabled
12
- * with a note rather than being left out of the list: a workspace admin should
13
- * see that the choice exists and is not theirs, not wonder why a module they
14
- * expect is simply missing from the page.
11
+ * A module a deploy-time config file locks
12
+ * (`docs/self-hosting/configuration.md`) shows as disabled with a note rather
13
+ * than being left out of the list: a workspace admin should see that the
14
+ * choice exists and is not theirs, not wonder why a module they expect is
15
+ * simply missing from the page.
15
16
  *
16
17
  * Known ids get a friendlier label; an id this page has never heard of still
17
18
  * renders, title-cased, because the module catalog is meant to grow without