@kelpie/ui 0.17.0 → 0.19.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 (189) hide show
  1. package/dist/api/resources/ai.d.ts +5 -0
  2. package/dist/api/resources/ai.d.ts.map +1 -1
  3. package/dist/api/resources/ai.js +9 -1
  4. package/dist/api/resources/ai.js.map +1 -1
  5. package/dist/api/resources/forms.d.ts +8 -0
  6. package/dist/api/resources/forms.d.ts.map +1 -1
  7. package/dist/api/resources/forms.js +39 -0
  8. package/dist/api/resources/forms.js.map +1 -1
  9. package/dist/api/resources/personIntake.d.ts +12 -0
  10. package/dist/api/resources/personIntake.d.ts.map +1 -0
  11. package/dist/api/resources/personIntake.js +54 -0
  12. package/dist/api/resources/personIntake.js.map +1 -0
  13. package/dist/app/KelpieApp.js +2 -2
  14. package/dist/app/KelpieApp.js.map +1 -1
  15. package/dist/components/AgentTasks.js +2 -2
  16. package/dist/components/AgentTasks.js.map +1 -1
  17. package/dist/components/AiDrawer.d.ts +13 -0
  18. package/dist/components/AiDrawer.d.ts.map +1 -0
  19. package/dist/components/AiDrawer.js +165 -0
  20. package/dist/components/AiDrawer.js.map +1 -0
  21. package/dist/components/ApiKeysPanel.js +1 -1
  22. package/dist/components/DataTable.js +1 -1
  23. package/dist/components/KanbanBoard.d.ts +5 -1
  24. package/dist/components/KanbanBoard.d.ts.map +1 -1
  25. package/dist/components/KanbanBoard.js +37 -2
  26. package/dist/components/KanbanBoard.js.map +1 -1
  27. package/dist/components/NotesPanel.js +2 -2
  28. package/dist/components/NotesPanel.js.map +1 -1
  29. package/dist/components/PageHeader.js +1 -1
  30. package/dist/components/PageHeader.js.map +1 -1
  31. package/dist/components/PersonIntakeDialog.d.ts +19 -0
  32. package/dist/components/PersonIntakeDialog.d.ts.map +1 -0
  33. package/dist/components/PersonIntakeDialog.js +87 -0
  34. package/dist/components/PersonIntakeDialog.js.map +1 -0
  35. package/dist/components/PersonIntakePanel.d.ts +21 -0
  36. package/dist/components/PersonIntakePanel.d.ts.map +1 -0
  37. package/dist/components/PersonIntakePanel.js +76 -0
  38. package/dist/components/PersonIntakePanel.js.map +1 -0
  39. package/dist/components/SegmentedControl.js +2 -2
  40. package/dist/components/SegmentedControl.js.map +1 -1
  41. package/dist/components/Shell.d.ts.map +1 -1
  42. package/dist/components/Shell.js +40 -4
  43. package/dist/components/Shell.js.map +1 -1
  44. package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
  45. package/dist/components/WorkspaceSwitcher.js +10 -2
  46. package/dist/components/WorkspaceSwitcher.js.map +1 -1
  47. package/dist/components/aiDrawerState.d.ts +45 -0
  48. package/dist/components/aiDrawerState.d.ts.map +1 -0
  49. package/dist/components/aiDrawerState.js +14 -0
  50. package/dist/components/aiDrawerState.js.map +1 -0
  51. package/dist/components/personIntakeTask.d.ts +5 -0
  52. package/dist/components/personIntakeTask.d.ts.map +1 -0
  53. package/dist/components/personIntakeTask.js +13 -0
  54. package/dist/components/personIntakeTask.js.map +1 -0
  55. package/dist/index.d.ts +5 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +5 -2
  58. package/dist/index.js.map +1 -1
  59. package/dist/lib/mediaQuery.d.ts +9 -0
  60. package/dist/lib/mediaQuery.d.ts.map +1 -0
  61. package/dist/lib/mediaQuery.js +24 -0
  62. package/dist/lib/mediaQuery.js.map +1 -0
  63. package/dist/modules/PersonIntakeWizard.d.ts +3 -0
  64. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -0
  65. package/dist/modules/PersonIntakeWizard.js +227 -0
  66. package/dist/modules/PersonIntakeWizard.js.map +1 -0
  67. package/dist/modules/ai.d.ts +4 -3
  68. package/dist/modules/ai.d.ts.map +1 -1
  69. package/dist/modules/ai.js +10 -6
  70. package/dist/modules/ai.js.map +1 -1
  71. package/dist/modules/aiRunner.d.ts.map +1 -1
  72. package/dist/modules/aiRunner.js +7 -5
  73. package/dist/modules/aiRunner.js.map +1 -1
  74. package/dist/modules/personIntakeSelection.d.ts +7 -0
  75. package/dist/modules/personIntakeSelection.d.ts.map +1 -0
  76. package/dist/modules/personIntakeSelection.js +21 -0
  77. package/dist/modules/personIntakeSelection.js.map +1 -0
  78. package/dist/pages/FormDetail.d.ts.map +1 -1
  79. package/dist/pages/FormDetail.js +7 -7
  80. package/dist/pages/FormDetail.js.map +1 -1
  81. package/dist/pages/FormsPage.js +4 -4
  82. package/dist/pages/FormsPage.js.map +1 -1
  83. package/dist/pages/ListDetail.d.ts.map +1 -1
  84. package/dist/pages/ListDetail.js +2 -2
  85. package/dist/pages/ListDetail.js.map +1 -1
  86. package/dist/pages/PeoplePage.d.ts.map +1 -1
  87. package/dist/pages/PeoplePage.js +9 -1
  88. package/dist/pages/PeoplePage.js.map +1 -1
  89. package/dist/pages/RoleDetail.d.ts.map +1 -1
  90. package/dist/pages/RoleDetail.js +3 -3
  91. package/dist/pages/RoleDetail.js.map +1 -1
  92. package/dist/pages/account/ConnectedAppsPage.js +1 -1
  93. package/dist/pages/admin/AiAdminPage.d.ts +2 -0
  94. package/dist/pages/admin/AiAdminPage.d.ts.map +1 -0
  95. package/dist/pages/admin/AiAdminPage.js +19 -0
  96. package/dist/pages/admin/AiAdminPage.js.map +1 -0
  97. package/dist/pages/admin/AiPage.d.ts +4 -1
  98. package/dist/pages/admin/AiPage.d.ts.map +1 -1
  99. package/dist/pages/admin/AiPage.js +77 -15
  100. package/dist/pages/admin/AiPage.js.map +1 -1
  101. package/dist/pages/admin/DataPage.js +2 -2
  102. package/dist/pages/admin/McpPanel.d.ts +3 -0
  103. package/dist/pages/admin/McpPanel.d.ts.map +1 -0
  104. package/dist/pages/admin/McpPanel.js +123 -0
  105. package/dist/pages/admin/McpPanel.js.map +1 -0
  106. package/dist/pages/admin/PrivacyPage.js +19 -3
  107. package/dist/pages/admin/PrivacyPage.js.map +1 -1
  108. package/dist/pages/forms/AddFieldMenu.js +2 -2
  109. package/dist/pages/forms/AddFieldMenu.js.map +1 -1
  110. package/dist/pages/forms/EmbedPanel.js +5 -2
  111. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  112. package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
  113. package/dist/pages/forms/FieldsEditor.js +90 -8
  114. package/dist/pages/forms/FieldsEditor.js.map +1 -1
  115. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  116. package/dist/pages/forms/FormSettings.js +73 -6
  117. package/dist/pages/forms/FormSettings.js.map +1 -1
  118. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  119. package/dist/pages/forms/SubmissionDetail.js +2 -1
  120. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  121. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  122. package/dist/pages/forms/SubmissionsTable.js +2 -1
  123. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  124. package/dist/pages/forms/fieldList.d.ts +2 -2
  125. package/dist/pages/forms/fieldList.d.ts.map +1 -1
  126. package/dist/pages/forms/fieldList.js +38 -10
  127. package/dist/pages/forms/fieldList.js.map +1 -1
  128. package/dist/pages/forms/template.d.ts.map +1 -1
  129. package/dist/pages/forms/template.js +13 -0
  130. package/dist/pages/forms/template.js.map +1 -1
  131. package/dist/pages/handbook/HandbookPage.js +4 -4
  132. package/dist/pages/handbook/HandbookPage.js.map +1 -1
  133. package/dist/registry/context.d.ts +5 -1
  134. package/dist/registry/context.d.ts.map +1 -1
  135. package/dist/registry/context.js +8 -0
  136. package/dist/registry/context.js.map +1 -1
  137. package/dist/registry/contributions.d.ts +37 -1
  138. package/dist/registry/contributions.d.ts.map +1 -1
  139. package/dist/registry/registry.d.ts +8 -1
  140. package/dist/registry/registry.d.ts.map +1 -1
  141. package/dist/registry/registry.js +13 -0
  142. package/dist/registry/registry.js.map +1 -1
  143. package/package.json +2 -2
  144. package/src/api/resources/ai.ts +11 -1
  145. package/src/api/resources/forms.ts +56 -0
  146. package/src/api/resources/personIntake.ts +95 -0
  147. package/src/app/KelpieApp.tsx +4 -2
  148. package/src/components/AgentTasks.tsx +2 -2
  149. package/src/components/AiDrawer.tsx +272 -0
  150. package/src/components/ApiKeysPanel.tsx +1 -1
  151. package/src/components/DataTable.tsx +1 -1
  152. package/src/components/KanbanBoard.tsx +119 -2
  153. package/src/components/NotesPanel.tsx +7 -4
  154. package/src/components/PageHeader.tsx +1 -1
  155. package/src/components/PersonIntakePanel.tsx +193 -0
  156. package/src/components/SegmentedControl.tsx +2 -2
  157. package/src/components/Shell.tsx +99 -13
  158. package/src/components/WorkspaceSwitcher.tsx +13 -2
  159. package/src/components/aiDrawerState.ts +61 -0
  160. package/src/components/personIntakeTask.tsx +14 -0
  161. package/src/index.ts +12 -1
  162. package/src/lib/mediaQuery.ts +32 -0
  163. package/src/modules/PersonIntakeWizard.tsx +638 -0
  164. package/src/modules/ai.tsx +10 -6
  165. package/src/modules/aiRunner.ts +8 -5
  166. package/src/modules/personIntakeSelection.ts +24 -0
  167. package/src/pages/FormDetail.tsx +18 -14
  168. package/src/pages/FormsPage.tsx +4 -4
  169. package/src/pages/ListDetail.tsx +5 -3
  170. package/src/pages/PeoplePage.tsx +18 -5
  171. package/src/pages/RoleDetail.tsx +10 -5
  172. package/src/pages/account/ConnectedAppsPage.tsx +1 -1
  173. package/src/pages/admin/AiAdminPage.tsx +52 -0
  174. package/src/pages/admin/AiPage.tsx +136 -32
  175. package/src/pages/admin/DataPage.tsx +2 -2
  176. package/src/pages/admin/{McpPage.tsx → McpPanel.tsx} +4 -6
  177. package/src/pages/admin/PrivacyPage.tsx +42 -0
  178. package/src/pages/forms/AddFieldMenu.tsx +2 -2
  179. package/src/pages/forms/EmbedPanel.tsx +5 -1
  180. package/src/pages/forms/FieldsEditor.tsx +204 -15
  181. package/src/pages/forms/FormSettings.tsx +156 -9
  182. package/src/pages/forms/SubmissionDetail.tsx +2 -1
  183. package/src/pages/forms/SubmissionsTable.tsx +2 -1
  184. package/src/pages/forms/fieldList.ts +39 -10
  185. package/src/pages/forms/template.ts +13 -0
  186. package/src/pages/handbook/HandbookPage.tsx +5 -5
  187. package/src/registry/context.ts +13 -0
  188. package/src/registry/contributions.ts +39 -1
  189. package/src/registry/registry.ts +30 -0
@@ -1,3 +1,5 @@
1
+ import { AI_SERVICE_LABELS } from '@kelpie/schemas'
2
+
1
3
  import { ApiError } from '../api/client.ts'
2
4
  import { useAiRunForAgentRun, useAiSettings } from '../api/resources/ai.ts'
3
5
  import { useAgents } from '../api/resources/agentTasks.ts'
@@ -25,20 +27,21 @@ function useAvailability(options: { readonly enabled: boolean }): AgentRunnerAva
25
27
  if (settings.error !== null) {
26
28
  // The runtime answers 403 or 404 when the module is switched off.
27
29
  return settings.error instanceof ApiError && (settings.error.status === 403 || settings.error.status === 404)
28
- ? { status: 'unavailable', reason: 'Kelpie AI is switched off for this workspace.' }
29
- : { status: 'unavailable', reason: 'Kelpie AI settings could not be read.' }
30
+ ? { status: 'unavailable', reason: 'AI is switched off for this workspace.' }
31
+ : { status: 'unavailable', reason: 'AI settings could not be read.' }
30
32
  }
31
33
 
32
34
  const record = settings.record
35
+ const label = record === undefined ? 'AI' : AI_SERVICE_LABELS[record.service]
33
36
 
34
37
  if (record === undefined || !record.enabled) {
35
- return { status: 'unavailable', reason: 'Kelpie AI is not enabled. An admin can enable it under Admin → AI.' }
38
+ return { status: 'unavailable', reason: `${label} is not enabled. An admin can enable it under Admin → AI.` }
36
39
  }
37
40
 
38
41
  if (!record.configured) {
39
42
  return {
40
43
  status: 'unavailable',
41
- reason: 'Kelpie AI has no provider key. An admin can add one under Admin → AI.',
44
+ reason: `${label} has no provider key. An admin can add one under Admin → AI.`,
42
45
  }
43
46
  }
44
47
 
@@ -47,7 +50,7 @@ function useAvailability(options: { readonly enabled: boolean }): AgentRunnerAva
47
50
  if (agent === undefined) {
48
51
  return {
49
52
  status: 'unavailable',
50
- reason: 'The Kelpie AI agent is missing. An admin can save Admin → AI again to restore it.',
53
+ reason: `The ${label} agent is missing. An admin can save Admin → AI again to restore it.`,
51
54
  }
52
55
  }
53
56
 
@@ -0,0 +1,24 @@
1
+ import { personIntakeDependencies } from '@kelpie/schemas'
2
+ import type { PersonIntakeItem } from '@kelpie/schemas'
3
+
4
+ /**
5
+ * The items that can be written given what is ticked: an item whose
6
+ * dependency is unticked, or cannot be written, drops out too.
7
+ */
8
+ export function effectiveSelection(items: readonly PersonIntakeItem[], ticked: ReadonlySet<string>): ReadonlySet<string> {
9
+ const keys = new Set(items.map((item) => item.key))
10
+ const effective = new Set([...ticked].filter((key) => keys.has(key)))
11
+ let changed = true
12
+
13
+ while (changed) {
14
+ changed = false
15
+ for (const item of items) {
16
+ if (effective.has(item.key) && personIntakeDependencies(item).some((key) => !effective.has(key))) {
17
+ effective.delete(item.key)
18
+ changed = true
19
+ }
20
+ }
21
+ }
22
+
23
+ return effective
24
+ }
@@ -53,20 +53,24 @@ export function FormDetail(): React.JSX.Element {
53
53
  ← Forms
54
54
  </Link>
55
55
 
56
- <div className="mb-6 flex flex-wrap items-start justify-between gap-3">
56
+ {/* On a phone the controls go under the heading, so a long title keeps
57
+ the full width and does not break over several lines. */}
58
+ <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
57
59
  <FormHeading form={record} />
58
- <DeleteRecord
59
- recordLabel="Form"
60
- recordName={record.name}
61
- isPending={deleteForm.isPending}
62
- error={deleteForm.error}
63
- onConfirm={() => {
64
- deleteForm
65
- .runAsync(record.id)
66
- .then(() => navigate('/forms'))
67
- .catch(() => undefined)
68
- }}
69
- />
60
+ <div className="flex flex-wrap items-center gap-3">
61
+ <DeleteRecord
62
+ recordLabel="Form"
63
+ recordName={record.name}
64
+ isPending={deleteForm.isPending}
65
+ error={deleteForm.error}
66
+ onConfirm={() => {
67
+ deleteForm
68
+ .runAsync(record.id)
69
+ .then(() => navigate('/forms'))
70
+ .catch(() => undefined)
71
+ }}
72
+ />
73
+ </div>
70
74
  </div>
71
75
 
72
76
  <RecordTabs
@@ -118,7 +122,7 @@ function FormHeading({ form }: { readonly form: Form }): React.JSX.Element {
118
122
  }
119
123
 
120
124
  return (
121
- <div className="min-w-0 flex-1">
125
+ <div className="min-w-[12rem] flex-1">
122
126
  <div className="flex flex-wrap items-center gap-2">
123
127
  <div className="min-w-0 flex-1">
124
128
  <InlineEdit
@@ -136,11 +136,11 @@ export function FormsPage(): React.JSX.Element {
136
136
  ),
137
137
  },
138
138
  {
139
- key: 'publicKey',
140
- header: 'Public key',
141
- getSortValue: (form) => form.publicKey,
139
+ key: 'slug',
140
+ header: 'Slug',
141
+ getSortValue: (form) => form.slug,
142
142
  render: (form) => (
143
- <span className="font-mono text-[12px] text-ink-muted">{form.publicKey}</span>
143
+ <span className="font-mono text-[12px] text-ink-muted">{form.slug}</span>
144
144
  ),
145
145
  },
146
146
  {
@@ -65,9 +65,11 @@ export function ListDetail(): React.JSX.Element {
65
65
  ← Lists
66
66
  </Link>
67
67
 
68
- <div className="mb-6 flex flex-wrap items-start justify-between gap-3">
68
+ {/* On a phone the controls go under the heading, so a long title keeps
69
+ the full width and does not break over several lines. */}
70
+ <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
69
71
  <ListHeading list={record} />
70
- <div className="flex shrink-0 flex-wrap items-center gap-3">
72
+ <div className="flex flex-wrap items-center gap-3">
71
73
  <Chip>{RECORD_TARGET_TYPE_LABELS[record.targetType]}</Chip>
72
74
  <DeleteRecord
73
75
  recordLabel="List"
@@ -99,7 +101,7 @@ function ListHeading({ list }: { readonly list: List }): React.JSX.Element {
99
101
  const { patch, error } = useListPatch(list)
100
102
 
101
103
  return (
102
- <div className="min-w-0 flex-1">
104
+ <div className="min-w-[12rem] flex-1">
103
105
  {error !== null && (
104
106
  <div className="mb-2">
105
107
  <ErrorPanel error={error} />
@@ -5,10 +5,13 @@ import { useNavigate } from 'react-router'
5
5
 
6
6
  import { useTimezone } from '../api/resources/account.ts'
7
7
  import { useCreatePerson, usePeople } from '../api/resources/people.ts'
8
+ import { useAiDrawer } from '../components/aiDrawerState.ts'
8
9
  import { Chip } from '../components/Chip.tsx'
9
10
  import { SocialNetworkIcon } from '../components/SocialNetworkIcon.tsx'
10
11
  import { ColumnPicker } from '../components/ColumnPicker.tsx'
11
12
  import { DataTable } from '../components/DataTable.tsx'
13
+ import { AddFromNotesButton } from '../components/PersonIntakePanel.tsx'
14
+ import { personIntakeTask } from '../components/personIntakeTask.tsx'
12
15
  import type { Column } from '../components/DataTable.tsx'
13
16
  import { FilterBar, PageHeader } from '../components/PageHeader.tsx'
14
17
  import { Paginator } from '../components/Paginator.tsx'
@@ -59,6 +62,7 @@ export function PeoplePage(): React.JSX.Element {
59
62
  })
60
63
  const directory = usePeopleDirectory(people.records.map((person) => person.id))
61
64
  const createPerson = useCreatePerson()
65
+ const aiDrawer = useAiDrawer()
62
66
 
63
67
  async function addPerson(): Promise<void> {
64
68
  // The same defaults the API applies, so a person created here and one
@@ -194,6 +198,8 @@ export function PeoplePage(): React.JSX.Element {
194
198
  {
195
199
  key: 'tags',
196
200
  header: 'Tags',
201
+ // On a phone the tag chips wrap one per line and make every row tall.
202
+ className: 'hidden md:table-cell',
197
203
  getSortValue: (person) => person.tags.join(', ') || null,
198
204
  render: (person) =>
199
205
  person.tags.length > 0 ? (
@@ -242,11 +248,18 @@ export function PeoplePage(): React.JSX.Element {
242
248
  }}
243
249
  addLabel="Add person"
244
250
  actions={
245
- <ColumnPicker
246
- options={pickerOptions}
247
- visibleKeys={listView.visibleKeys}
248
- onChange={listView.setVisibleKeys}
249
- />
251
+ <>
252
+ <ColumnPicker
253
+ options={pickerOptions}
254
+ visibleKeys={listView.visibleKeys}
255
+ onChange={listView.setVisibleKeys}
256
+ />
257
+ <AddFromNotesButton
258
+ onClick={() => {
259
+ aiDrawer.open(personIntakeTask())
260
+ }}
261
+ />
262
+ </>
250
263
  }
251
264
  />
252
265
  <FilterBar
@@ -71,9 +71,11 @@ export function RoleDetail(): React.JSX.Element {
71
71
  ← Hiring
72
72
  </Link>
73
73
 
74
- <div className="mb-6 flex flex-wrap items-start justify-between gap-3">
74
+ {/* On a phone the controls go under the heading, so a long role title
75
+ keeps the full width and does not break over several lines. */}
76
+ <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
75
77
  <RoleHeading role={record} />
76
- <div className="flex shrink-0 flex-wrap items-center gap-3">
78
+ <div className="flex flex-wrap items-center gap-3">
77
79
  <RoleStatusField role={record} />
78
80
  <AgentTasks targetType="role" targetId={record.id} targetLabel={record.title} />
79
81
  <DeleteRecord
@@ -109,7 +111,7 @@ function RoleHeading({ role }: { readonly role: Role }): React.JSX.Element {
109
111
  const { patch, error } = useRolePatch(role)
110
112
 
111
113
  return (
112
- <div className="min-w-0 flex-1">
114
+ <div className="min-w-[12rem] flex-1">
113
115
  {error !== null && (
114
116
  <div className="mb-2">
115
117
  <ErrorPanel error={error} />
@@ -292,10 +294,13 @@ function CandidateRow({
292
294
 
293
295
  return (
294
296
  <li className="border-b border-border px-4 py-3.5 last:border-0">
295
- <div className="flex flex-wrap items-start justify-between gap-3">
297
+ {/* On a phone the controls always take their own line under the name.
298
+ Left to wrap, whether they fit beside it depends on the name length
299
+ and on the stage field, so rows in one list came out different. */}
300
+ <div className="flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between sm:gap-3">
296
301
  <Link
297
302
  to={`/people/${candidate.personId}`}
298
- className="text-left text-[13px] font-medium text-ink hover:text-accent"
303
+ className="self-start text-left text-[13px] font-medium text-ink hover:text-accent"
299
304
  >
300
305
  {personName ?? candidate.personId}
301
306
  </Link>
@@ -34,7 +34,7 @@ export function ConnectedAppsPage(): React.JSX.Element {
34
34
  No connected apps. When an MCP client asks you to sign in to Kelpie, it shows up here.
35
35
  </p>
36
36
  ) : (
37
- <div className="overflow-hidden rounded-md border border-border">
37
+ <div className="overflow-x-auto rounded-md border border-border">
38
38
  <table className="w-full text-left text-[13px]">
39
39
  <thead>
40
40
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -0,0 +1,52 @@
1
+ import type { ReactNode } from 'react'
2
+ import { useSearchParams } from 'react-router'
3
+
4
+ import { PageHeader } from '../../components/PageHeader.tsx'
5
+ import { RecordTabs } from '../../components/RecordTabs.tsx'
6
+ import { useAdminTabs } from '../../registry/context.ts'
7
+ import { inSlotOrder } from '../../registry/registry.ts'
8
+ import { McpPanel } from './McpPanel.tsx'
9
+
10
+ /**
11
+ * Admin → AI at `/admin/ai`: how agents reach this workspace.
12
+ *
13
+ * Core owns the page and its MCP tab, so every install has both. The optional
14
+ * `ai` module adds Kelpie AI's Settings and Run log tabs through `adminTab`,
15
+ * ordered before MCP. Without that module the page is MCP alone.
16
+ *
17
+ * The open tab is `?tab=`, so a link can open one; `/admin/mcp` redirects to
18
+ * `?tab=mcp`. With no `tab`, or one no module provides, the first tab opens.
19
+ */
20
+
21
+ interface PageTab {
22
+ readonly id: string
23
+ readonly label: string
24
+ readonly order?: number
25
+ readonly render: () => ReactNode
26
+ }
27
+
28
+ const MCP_TAB: PageTab = { id: 'mcp', label: 'MCP', order: 300, render: () => <McpPanel /> }
29
+
30
+ export function AiAdminPage(): React.JSX.Element {
31
+ const moduleTabs = useAdminTabs('ai')
32
+ const tabs = inSlotOrder<PageTab>([...moduleTabs, MCP_TAB])
33
+ const [searchParams, setSearchParams] = useSearchParams()
34
+ const requested = searchParams.get('tab')
35
+ const active = tabs.find((tab) => tab.id === requested) ?? tabs[0] ?? MCP_TAB
36
+
37
+ return (
38
+ <div className="animate-slide-in mx-auto max-w-4xl space-y-6">
39
+ <PageHeader title="AI" description="Connect agents to this workspace, and run agent tasks." />
40
+ <RecordTabs
41
+ tabs={tabs.map((tab) => ({ id: tab.id, label: tab.label }))}
42
+ active={active.id}
43
+ onChange={(id) => {
44
+ setSearchParams({ tab: id }, { replace: true })
45
+ }}
46
+ ariaLabel="AI sections"
47
+ >
48
+ {active.render()}
49
+ </RecordTabs>
50
+ </div>
51
+ )
52
+ }
@@ -1,21 +1,25 @@
1
- import { AI_DEFAULT_MODELS, AI_PROVIDER_LABELS, AI_PROVIDERS } from '@kelpie/schemas'
2
- import type { AiProvider, AiRun, AiSettings, AiSettingsInput } from '@kelpie/schemas'
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
3
  import { useState } from 'react'
4
4
  import type { FormEvent } from 'react'
5
+ import { Link } from 'react-router'
5
6
 
6
7
  import { useTimezone } from '../../api/resources/account.ts'
7
- import { useAiRuns, useAiSettings, useDisableAi, useSaveAiSettings } from '../../api/resources/ai.ts'
8
+ import { useAiRuns, useAiServiceLabel, useAiSettings, useDisableAi, useSaveAiSettings } from '../../api/resources/ai.ts'
8
9
  import { Chip } from '../../components/Chip.tsx'
9
10
  import type { ChipTone } from '../../components/Chip.tsx'
10
- import { PageHeader } from '../../components/PageHeader.tsx'
11
+ import { LinkedText } from '../../components/LinkedText.tsx'
12
+ import { Paginator } from '../../components/Paginator.tsx'
11
13
  import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
12
14
  import { formatRelativeTime } from '../../lib/dates.ts'
15
+ import { targetHref } from '../../lib/recordLinks.ts'
13
16
 
14
17
  /**
15
- * The AI admin page at `/admin/ai`, from the optional `ai` module.
18
+ * The optional `ai` module's two tabs on Admin → AI, the core page at
19
+ * `/admin/ai` (`AiAdminPage`), beside core's MCP tab.
16
20
  *
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.
21
+ * Settings for Kelpie AI in this workspace, and its run log. Both read the
22
+ * same `/v1/ai/*` endpoints an agent would use.
19
23
  *
20
24
  * What the settings part shows depends on the module's key mode. In
21
25
  * `workspace` mode an admin picks a provider, pastes their own API key, and
@@ -37,6 +41,21 @@ const OPERATION_TONES: Readonly<Record<string, ChipTone>> = {
37
41
  skipped: 'neutral',
38
42
  }
39
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
+
40
59
  const inputClass =
41
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'
42
61
  const primaryButtonClass =
@@ -218,22 +237,64 @@ function DeploymentKeyControls({ settings }: { readonly settings: AiSettings }):
218
237
  )
219
238
  }
220
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
+ */
221
277
  function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.JSX.Element {
222
278
  const disable = useDisableAi()
279
+ const label = AI_SERVICE_LABELS[settings.service]
280
+ const isHosted = settings.service === 'kelpie_ai'
223
281
 
224
282
  return (
225
283
  <section className="rounded-md border border-border p-5">
226
284
  <div className="flex flex-wrap items-center gap-2">
227
- <h2 className="text-[15px] font-semibold text-ink">Kelpie AI</h2>
285
+ <h2 className="text-[15px] font-semibold text-ink">{label}</h2>
228
286
  <Chip tone={settings.enabled ? 'success' : 'neutral'}>{settings.enabled ? 'Enabled' : 'Not enabled'}</Chip>
229
287
  </div>
230
288
  <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.
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.
233
294
  </p>
234
295
 
235
296
  <dl className="mt-4 grid max-w-md grid-cols-2 gap-y-2 text-[13px]">
236
- {settings.provider !== null && (
297
+ {!isHosted && settings.provider !== null && (
237
298
  <>
238
299
  <dt className="text-ink-muted">Provider</dt>
239
300
  <dd className="text-ink">{AI_PROVIDER_LABELS[settings.provider]}</dd>
@@ -258,6 +319,8 @@ function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.J
258
319
  <DeploymentKeyControls settings={settings} />
259
320
  )}
260
321
 
322
+ {settings.enabled && settings.configured && <WebSearchToggle settings={settings} />}
323
+
261
324
  {settings.enabled && (
262
325
  <div className="mt-4 space-y-2 border-t border-border pt-4">
263
326
  {disable.error !== null && <ErrorPanel error={disable.error} />}
@@ -272,7 +335,7 @@ function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.J
272
335
  {disable.isPending ? 'Disabling…' : 'Disable AI'}
273
336
  </button>
274
337
  <p className="text-[12px] text-ink-muted">
275
- Disabling removes Kelpie AI from the Run menu
338
+ Disabling removes {label} from the Run menu
276
339
  {settings.keySource === 'workspace' ? ' and deletes the stored key' : ''}. The run log is kept.
277
340
  </p>
278
341
  </div>
@@ -281,8 +344,50 @@ function SettingsPanel({ settings }: { readonly settings: AiSettings }): React.J
281
344
  )
282
345
  }
283
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
+
284
385
  function RunLog(): React.JSX.Element {
285
- const { records: runs, isLoading, error } = useAiRuns()
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
286
391
  const timezone = useTimezone()
287
392
 
288
393
  return (
@@ -292,7 +397,7 @@ function RunLog(): React.JSX.Element {
292
397
  {error !== null && <ErrorPanel error={error} />}
293
398
  {!isLoading && error === null && runs.length === 0 && (
294
399
  <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>.
400
+ No runs yet. Start one from the Agent menu on any record page and pick <em>{serviceLabel}</em>.
296
401
  </p>
297
402
  )}
298
403
  {runs.length > 0 && (
@@ -302,30 +407,24 @@ function RunLog(): React.JSX.Element {
302
407
  <div className="flex flex-wrap items-center gap-2">
303
408
  <Chip tone={STATUS_TONES[run.status]}>{run.status}</Chip>
304
409
  <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>
410
+ <RunTarget run={run} />
308
411
  <span className="ml-auto text-[12px] text-ink-faint">{formatRelativeTime(run.createdAt, timezone)}</span>
309
412
  </div>
310
413
  <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
- : ''}
414
+ {showModel && <span className="font-mono">{run.model}</span>}
415
+ {showModel && tokens(run) !== null && ' · '}
416
+ {tokens(run)}
315
417
  </p>
316
418
  {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
419
  {run.operations !== null && run.operations.length > 0 && (
323
420
  <ul className="mt-2 flex flex-col gap-1">
324
421
  {run.operations.map((operation, index) => (
325
422
  <li key={`${run.id}-op-${String(index)}`} className="flex flex-wrap items-center gap-2 text-[12px]">
326
423
  <Chip tone={OPERATION_TONES[operation.status] ?? 'neutral'}>{operation.status}</Chip>
327
424
  <span className="font-medium text-ink">{operation.kind}</span>
328
- <span className="text-ink-muted">{operation.detail}</span>
425
+ <span className="text-ink-muted">
426
+ <LinkedText text={operation.detail} references={operation.references} />
427
+ </span>
329
428
  </li>
330
429
  ))}
331
430
  </ul>
@@ -334,20 +433,25 @@ function RunLog(): React.JSX.Element {
334
433
  ))}
335
434
  </ul>
336
435
  )}
436
+ {runs.length > 0 && <Paginator list={list} />}
337
437
  </section>
338
438
  )
339
439
  }
340
440
 
341
- export function AiPage(): React.JSX.Element {
441
+ /** The Settings tab the `ai` module adds to Admin → AI. */
442
+ export function AiSettingsTab(): React.JSX.Element {
342
443
  const { record: settings, isLoading, error } = useAiSettings()
343
444
 
344
445
  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." />
446
+ <>
347
447
  {isLoading && <LoadingPanel label="Loading AI settings…" />}
348
448
  {error !== null && <ErrorPanel error={error} />}
349
449
  {settings !== undefined && <SettingsPanel settings={settings} />}
350
- <RunLog />
351
- </div>
450
+ </>
352
451
  )
353
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
+ }
@@ -571,7 +571,7 @@ function MappingForm(props: MappingFormProps): ReactNode {
571
571
  : 'A company that is not here yet is left unlinked and reported as a warning.'}
572
572
  </p>
573
573
  ) : null}
574
- <div className="overflow-hidden rounded-md border border-border">
574
+ <div className="overflow-x-auto rounded-md border border-border">
575
575
  <table className="w-full text-left text-[13px]">
576
576
  <thead>
577
577
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -810,7 +810,7 @@ function DonePanel({ job, object, onAgain }: DonePanelProps): ReactNode {
810
810
  /** The row / field / message table shared by the error and warning lists. */
811
811
  function IssueTable({ rows }: { readonly rows: readonly ImportRowError[] }): ReactNode {
812
812
  return (
813
- <div className="overflow-hidden rounded-md border border-border">
813
+ <div className="overflow-x-auto rounded-md border border-border">
814
814
  <table className="w-full text-left text-[13px]">
815
815
  <thead>
816
816
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -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,14 +49,13 @@ 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">