@kelpie/ui 0.21.0 → 0.23.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 (254) hide show
  1. package/dist/api/resource.d.ts +12 -0
  2. package/dist/api/resource.d.ts.map +1 -1
  3. package/dist/api/resource.js +11 -0
  4. package/dist/api/resource.js.map +1 -1
  5. package/dist/api/resources/decisions.d.ts +31 -0
  6. package/dist/api/resources/decisions.d.ts.map +1 -1
  7. package/dist/api/resources/decisions.js +51 -1
  8. package/dist/api/resources/decisions.js.map +1 -1
  9. package/dist/api/resources/forms.d.ts +21 -7
  10. package/dist/api/resources/forms.d.ts.map +1 -1
  11. package/dist/api/resources/forms.js +39 -1
  12. package/dist/api/resources/forms.js.map +1 -1
  13. package/dist/api/resources/oauth.d.ts +2 -0
  14. package/dist/api/resources/oauth.d.ts.map +1 -1
  15. package/dist/api/resources/oauth.js +13 -1
  16. package/dist/api/resources/oauth.js.map +1 -1
  17. package/dist/api/resources/personIntake.d.ts +15 -3
  18. package/dist/api/resources/personIntake.d.ts.map +1 -1
  19. package/dist/api/resources/personIntake.js +38 -9
  20. package/dist/api/resources/personIntake.js.map +1 -1
  21. package/dist/api/resources/session.d.ts.map +1 -1
  22. package/dist/api/resources/session.js +4 -0
  23. package/dist/api/resources/session.js.map +1 -1
  24. package/dist/api/resources/tags.d.ts +20 -0
  25. package/dist/api/resources/tags.d.ts.map +1 -0
  26. package/dist/api/resources/tags.js +52 -0
  27. package/dist/api/resources/tags.js.map +1 -0
  28. package/dist/app/KelpieApp.d.ts.map +1 -1
  29. package/dist/app/KelpieApp.js +2 -1
  30. package/dist/app/KelpieApp.js.map +1 -1
  31. package/dist/components/AddRecordPanel.d.ts +35 -0
  32. package/dist/components/AddRecordPanel.d.ts.map +1 -0
  33. package/dist/components/AddRecordPanel.js +35 -0
  34. package/dist/components/AddRecordPanel.js.map +1 -0
  35. package/dist/components/AiDrawer.d.ts.map +1 -1
  36. package/dist/components/AiDrawer.js +29 -6
  37. package/dist/components/AiDrawer.js.map +1 -1
  38. package/dist/components/ApiKeysPanel.d.ts.map +1 -1
  39. package/dist/components/ApiKeysPanel.js +101 -44
  40. package/dist/components/ApiKeysPanel.js.map +1 -1
  41. package/dist/components/Chip.d.ts +5 -1
  42. package/dist/components/Chip.d.ts.map +1 -1
  43. package/dist/components/Chip.js +8 -2
  44. package/dist/components/Chip.js.map +1 -1
  45. package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
  46. package/dist/components/CustomFieldsPanel.js +5 -2
  47. package/dist/components/CustomFieldsPanel.js.map +1 -1
  48. package/dist/components/DecisionProvenance.d.ts +27 -0
  49. package/dist/components/DecisionProvenance.d.ts.map +1 -0
  50. package/dist/components/DecisionProvenance.js +53 -0
  51. package/dist/components/DecisionProvenance.js.map +1 -0
  52. package/dist/components/DecisionsPanel.d.ts +3 -0
  53. package/dist/components/DecisionsPanel.d.ts.map +1 -1
  54. package/dist/components/DecisionsPanel.js +9 -5
  55. package/dist/components/DecisionsPanel.js.map +1 -1
  56. package/dist/components/MarkdownView.d.ts.map +1 -1
  57. package/dist/components/MarkdownView.js +18 -2
  58. package/dist/components/MarkdownView.js.map +1 -1
  59. package/dist/components/NotesPanel.d.ts.map +1 -1
  60. package/dist/components/NotesPanel.js +7 -3
  61. package/dist/components/NotesPanel.js.map +1 -1
  62. package/dist/components/OriginLabel.d.ts +5 -0
  63. package/dist/components/OriginLabel.d.ts.map +1 -0
  64. package/dist/components/OriginLabel.js +22 -0
  65. package/dist/components/OriginLabel.js.map +1 -0
  66. package/dist/components/Shell.d.ts.map +1 -1
  67. package/dist/components/Shell.js +17 -5
  68. package/dist/components/Shell.js.map +1 -1
  69. package/dist/components/TagInput.d.ts +29 -0
  70. package/dist/components/TagInput.d.ts.map +1 -0
  71. package/dist/components/TagInput.js +139 -0
  72. package/dist/components/TagInput.js.map +1 -0
  73. package/dist/components/aiDrawerState.d.ts +12 -0
  74. package/dist/components/aiDrawerState.d.ts.map +1 -1
  75. package/dist/components/aiDrawerState.js.map +1 -1
  76. package/dist/components/personIntakeTask.d.ts +15 -0
  77. package/dist/components/personIntakeTask.d.ts.map +1 -1
  78. package/dist/components/personIntakeTask.js +42 -0
  79. package/dist/components/personIntakeTask.js.map +1 -1
  80. package/dist/lib/personIntakeRunStorage.d.ts +15 -0
  81. package/dist/lib/personIntakeRunStorage.d.ts.map +1 -0
  82. package/dist/lib/personIntakeRunStorage.js +88 -0
  83. package/dist/lib/personIntakeRunStorage.js.map +1 -0
  84. package/dist/modules/PersonIntakeWizard.d.ts +1 -1
  85. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
  86. package/dist/modules/PersonIntakeWizard.js +243 -29
  87. package/dist/modules/PersonIntakeWizard.js.map +1 -1
  88. package/dist/modules/ai.d.ts +1 -1
  89. package/dist/modules/ai.js +1 -1
  90. package/dist/pages/CompaniesPage.d.ts.map +1 -1
  91. package/dist/pages/CompaniesPage.js +13 -6
  92. package/dist/pages/CompaniesPage.js.map +1 -1
  93. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  94. package/dist/pages/CompanyDetail.js +4 -3
  95. package/dist/pages/CompanyDetail.js.map +1 -1
  96. package/dist/pages/DealDetail.d.ts.map +1 -1
  97. package/dist/pages/DealDetail.js +4 -3
  98. package/dist/pages/DealDetail.js.map +1 -1
  99. package/dist/pages/DealsPage.d.ts.map +1 -1
  100. package/dist/pages/DealsPage.js +16 -8
  101. package/dist/pages/DealsPage.js.map +1 -1
  102. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  103. package/dist/pages/DecisionsPage.js +7 -3
  104. package/dist/pages/DecisionsPage.js.map +1 -1
  105. package/dist/pages/EnquiriesPage.d.ts.map +1 -1
  106. package/dist/pages/EnquiriesPage.js +14 -6
  107. package/dist/pages/EnquiriesPage.js.map +1 -1
  108. package/dist/pages/EnquiryDetail.js +4 -4
  109. package/dist/pages/EnquiryDetail.js.map +1 -1
  110. package/dist/pages/EventDetail.js +4 -4
  111. package/dist/pages/EventDetail.js.map +1 -1
  112. package/dist/pages/FundraisingPage.d.ts.map +1 -1
  113. package/dist/pages/FundraisingPage.js +16 -11
  114. package/dist/pages/FundraisingPage.js.map +1 -1
  115. package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
  116. package/dist/pages/OpportunitiesPage.js +14 -6
  117. package/dist/pages/OpportunitiesPage.js.map +1 -1
  118. package/dist/pages/OpportunityDetail.js +4 -4
  119. package/dist/pages/OpportunityDetail.js.map +1 -1
  120. package/dist/pages/PartnershipDetail.js +4 -4
  121. package/dist/pages/PartnershipDetail.js.map +1 -1
  122. package/dist/pages/PartnershipsPage.d.ts.map +1 -1
  123. package/dist/pages/PartnershipsPage.js +16 -11
  124. package/dist/pages/PartnershipsPage.js.map +1 -1
  125. package/dist/pages/PeoplePage.d.ts.map +1 -1
  126. package/dist/pages/PeoplePage.js +13 -8
  127. package/dist/pages/PeoplePage.js.map +1 -1
  128. package/dist/pages/PersonDetail.js +7 -7
  129. package/dist/pages/PersonDetail.js.map +1 -1
  130. package/dist/pages/RaiseDetail.js +4 -4
  131. package/dist/pages/RaiseDetail.js.map +1 -1
  132. package/dist/pages/SearchPage.d.ts.map +1 -1
  133. package/dist/pages/SearchPage.js +2 -1
  134. package/dist/pages/SearchPage.js.map +1 -1
  135. package/dist/pages/account/ConnectedAppsPage.d.ts +0 -5
  136. package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -1
  137. package/dist/pages/account/ConnectedAppsPage.js +38 -6
  138. package/dist/pages/account/ConnectedAppsPage.js.map +1 -1
  139. package/dist/pages/admin/AgentsPanel.d.ts +10 -0
  140. package/dist/pages/admin/AgentsPanel.d.ts.map +1 -0
  141. package/dist/pages/admin/AgentsPanel.js +81 -0
  142. package/dist/pages/admin/AgentsPanel.js.map +1 -0
  143. package/dist/pages/admin/AiAdminPage.d.ts.map +1 -1
  144. package/dist/pages/admin/AiAdminPage.js +9 -6
  145. package/dist/pages/admin/AiAdminPage.js.map +1 -1
  146. package/dist/pages/admin/AiPage.js +1 -1
  147. package/dist/pages/admin/TeamPage.d.ts.map +1 -1
  148. package/dist/pages/admin/TeamPage.js +16 -3
  149. package/dist/pages/admin/TeamPage.js.map +1 -1
  150. package/dist/pages/ai/AiAccessPage.d.ts +11 -0
  151. package/dist/pages/ai/AiAccessPage.d.ts.map +1 -0
  152. package/dist/pages/ai/AiAccessPage.js +16 -0
  153. package/dist/pages/ai/AiAccessPage.js.map +1 -0
  154. package/dist/pages/ai/McpPanel.d.ts +7 -0
  155. package/dist/pages/ai/McpPanel.d.ts.map +1 -0
  156. package/dist/pages/ai/McpPanel.js +86 -0
  157. package/dist/pages/ai/McpPanel.js.map +1 -0
  158. package/dist/pages/auth/nextPath.d.ts +6 -0
  159. package/dist/pages/auth/nextPath.d.ts.map +1 -1
  160. package/dist/pages/auth/nextPath.js +16 -1
  161. package/dist/pages/auth/nextPath.js.map +1 -1
  162. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  163. package/dist/pages/dashboard/sections.js +4 -2
  164. package/dist/pages/dashboard/sections.js.map +1 -1
  165. package/dist/pages/forms/EmbedPanel.js +1 -1
  166. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  167. package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
  168. package/dist/pages/forms/FieldsEditor.js +6 -7
  169. package/dist/pages/forms/FieldsEditor.js.map +1 -1
  170. package/dist/pages/forms/FormActions.d.ts.map +1 -1
  171. package/dist/pages/forms/FormActions.js +4 -11
  172. package/dist/pages/forms/FormActions.js.map +1 -1
  173. package/dist/pages/forms/FormEmails.d.ts.map +1 -1
  174. package/dist/pages/forms/FormEmails.js +6 -1
  175. package/dist/pages/forms/FormEmails.js.map +1 -1
  176. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  177. package/dist/pages/forms/FormSettings.js +6 -2
  178. package/dist/pages/forms/FormSettings.js.map +1 -1
  179. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  180. package/dist/pages/forms/SubmissionDetail.js +26 -6
  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 +81 -6
  184. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  185. package/dist/pages/forms/fieldList.d.ts +13 -5
  186. package/dist/pages/forms/fieldList.d.ts.map +1 -1
  187. package/dist/pages/forms/fieldList.js +12 -4
  188. package/dist/pages/forms/fieldList.js.map +1 -1
  189. package/dist/pages/oauth/ConsentPage.d.ts.map +1 -1
  190. package/dist/pages/oauth/ConsentPage.js +132 -15
  191. package/dist/pages/oauth/ConsentPage.js.map +1 -1
  192. package/dist/registry/contributions.d.ts +1 -1
  193. package/package.json +3 -3
  194. package/src/api/resource.ts +16 -0
  195. package/src/api/resources/decisions.ts +81 -1
  196. package/src/api/resources/forms.ts +68 -7
  197. package/src/api/resources/oauth.ts +15 -1
  198. package/src/api/resources/personIntake.ts +54 -13
  199. package/src/api/resources/session.ts +4 -0
  200. package/src/api/resources/tags.ts +71 -0
  201. package/src/app/KelpieApp.tsx +4 -2
  202. package/src/components/AddRecordPanel.tsx +143 -0
  203. package/src/components/AiDrawer.tsx +34 -7
  204. package/src/components/ApiKeysPanel.tsx +193 -75
  205. package/src/components/Chip.tsx +32 -1
  206. package/src/components/CustomFieldsPanel.tsx +15 -5
  207. package/src/components/DecisionProvenance.tsx +95 -0
  208. package/src/components/DecisionsPanel.tsx +30 -2
  209. package/src/components/MarkdownView.tsx +45 -11
  210. package/src/components/NotesPanel.tsx +15 -6
  211. package/src/components/OriginLabel.tsx +26 -0
  212. package/src/components/Shell.tsx +30 -6
  213. package/src/components/TagInput.tsx +285 -0
  214. package/src/components/aiDrawerState.ts +12 -0
  215. package/src/components/personIntakeTask.tsx +48 -0
  216. package/src/lib/personIntakeRunStorage.ts +97 -0
  217. package/src/modules/PersonIntakeWizard.tsx +391 -30
  218. package/src/modules/ai.tsx +1 -1
  219. package/src/pages/CompaniesPage.tsx +22 -5
  220. package/src/pages/CompanyDetail.tsx +6 -17
  221. package/src/pages/DealDetail.tsx +6 -17
  222. package/src/pages/DealsPage.tsx +25 -8
  223. package/src/pages/DecisionsPage.tsx +28 -1
  224. package/src/pages/EnquiriesPage.tsx +23 -5
  225. package/src/pages/EnquiryDetail.tsx +6 -18
  226. package/src/pages/EventDetail.tsx +6 -18
  227. package/src/pages/FundraisingPage.tsx +25 -11
  228. package/src/pages/OpportunitiesPage.tsx +23 -5
  229. package/src/pages/OpportunityDetail.tsx +6 -18
  230. package/src/pages/PartnershipDetail.tsx +6 -18
  231. package/src/pages/PartnershipsPage.tsx +25 -11
  232. package/src/pages/PeoplePage.tsx +22 -7
  233. package/src/pages/PersonDetail.tsx +11 -21
  234. package/src/pages/RaiseDetail.tsx +6 -18
  235. package/src/pages/SearchPage.tsx +3 -0
  236. package/src/pages/account/ConnectedAppsPage.tsx +97 -14
  237. package/src/pages/admin/{McpPanel.tsx → AgentsPanel.tsx} +11 -168
  238. package/src/pages/admin/AiAdminPage.tsx +16 -11
  239. package/src/pages/admin/AiPage.tsx +1 -1
  240. package/src/pages/admin/TeamPage.tsx +33 -0
  241. package/src/pages/ai/AiAccessPage.tsx +23 -0
  242. package/src/pages/ai/McpPanel.tsx +261 -0
  243. package/src/pages/auth/nextPath.ts +18 -1
  244. package/src/pages/dashboard/sections.tsx +4 -0
  245. package/src/pages/forms/EmbedPanel.tsx +3 -2
  246. package/src/pages/forms/FieldsEditor.tsx +6 -7
  247. package/src/pages/forms/FormActions.tsx +18 -20
  248. package/src/pages/forms/FormEmails.tsx +11 -2
  249. package/src/pages/forms/FormSettings.tsx +5 -0
  250. package/src/pages/forms/SubmissionDetail.tsx +47 -9
  251. package/src/pages/forms/SubmissionsTable.tsx +180 -5
  252. package/src/pages/forms/fieldList.ts +21 -7
  253. package/src/pages/oauth/ConsentPage.tsx +271 -33
  254. package/src/registry/contributions.ts +1 -1
@@ -63,10 +63,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
63
63
  const activeRef = useRef<AiDrawerTask | undefined>(undefined)
64
64
  const { session } = useSession()
65
65
  const workspaceId = session?.workspaceId ?? null
66
- const workspaceRef = useRef<string | null>(workspaceId)
66
+ // The session's workspace, current before any child's effect runs, so a
67
+ // task opened from an effect during a switch is recorded against the new one.
68
+ const currentWorkspaceRef = useRef<string | null>(workspaceId)
69
+ // The workspace the active task belongs to.
70
+ const taskWorkspaceRef = useRef<string | null>(null)
71
+
72
+ useLayoutEffect(() => {
73
+ currentWorkspaceRef.current = workspaceId
74
+ }, [workspaceId])
67
75
 
68
76
  const finish = useCallback((): void => {
77
+ const ended = activeRef.current
78
+ const endedWorkspace = taskWorkspaceRef.current
69
79
  activeRef.current = undefined
80
+ taskWorkspaceRef.current = null
81
+ ended?.onEnd?.(endedWorkspace)
70
82
  setActiveTask(undefined)
71
83
  setIsOpen(false)
72
84
  setIsPending(false)
@@ -82,11 +94,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
82
94
  }
83
95
 
84
96
  activeRef.current = task
97
+ taskWorkspaceRef.current = currentWorkspaceRef.current
85
98
  setActiveTask(task)
86
99
  setBusyNotice(false)
87
100
  return true
88
101
  }, [])
89
102
 
103
+ const restore = useCallback((task: AiDrawerTask): boolean => {
104
+ if (activeRef.current !== undefined) return false
105
+
106
+ activeRef.current = task
107
+ taskWorkspaceRef.current = currentWorkspaceRef.current
108
+ setActiveTask(task)
109
+ setIsOpen(false)
110
+ return true
111
+ }, [])
112
+
90
113
  const reopen = useCallback((): void => {
91
114
  if (activeRef.current !== undefined) setIsOpen(true)
92
115
  }, [])
@@ -97,18 +120,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
97
120
  }, [])
98
121
 
99
122
  // A task belongs to one workspace. The switcher asks first when a request is
100
- // pending; this is the backstop for any other way the session moves.
123
+ // pending; this is the backstop for any other way the session moves. It ends
124
+ // only a task of another workspace, so a task restored for the new one in
125
+ // the same commit stays.
101
126
  useEffect(() => {
102
- if (workspaceRef.current !== null && workspaceId !== null && workspaceRef.current !== workspaceId) {
127
+ const taskWorkspace = taskWorkspaceRef.current
128
+
129
+ const otherWorkspace = taskWorkspace !== null && workspaceId !== null && taskWorkspace !== workspaceId
130
+
131
+ if (activeRef.current !== undefined && otherWorkspace) {
103
132
  finish()
104
133
  }
105
-
106
- if (workspaceId !== null) workspaceRef.current = workspaceId
107
134
  }, [workspaceId, finish])
108
135
 
109
136
  const state = useMemo<AiDrawerState>(
110
- () => ({ activeTask, isOpen, isPending, open, reopen, close, finish }),
111
- [activeTask, isOpen, isPending, open, reopen, close, finish],
137
+ () => ({ activeTask, isOpen, isPending, open, restore, reopen, close, finish }),
138
+ [activeTask, isOpen, isPending, open, restore, reopen, close, finish],
112
139
  )
113
140
 
114
141
  return (
@@ -1,19 +1,24 @@
1
1
  import type { ApiKey, ApiKeyGranularScope, ApiKeyKind, ApiKeyScope, CreatedApiKey } from '@kelpie/schemas'
2
2
  import {
3
+ API_KEY_DEFAULT_SCOPES,
4
+ API_KEY_OPT_IN_SCOPES,
3
5
  API_KEY_PRESET_SCOPES,
4
6
  API_KEY_SCOPE_GROUPS,
5
7
  API_KEY_SCOPE_LABELS,
8
+ apiKeyScopeRisk,
6
9
  expandApiKeyScopes,
7
- isApiKeyGranularScope,
8
10
  isApiKeyPresetScope,
11
+ isSensitiveApiKeyScope,
12
+ sensitiveApiKeyScopesHeld,
9
13
  } from '@kelpie/schemas'
10
- import { useMemo, useState } from 'react'
14
+ import { useId, useMemo, useState } from 'react'
11
15
  import type { FormEvent } from 'react'
12
16
 
13
17
  import { useTimezone } from '../api/resources/account.ts'
14
18
  import { useApiKeys, useCreateApiKey, useRevokeApiKey } from '../api/resources/apiKeys.ts'
15
19
  import { formatDate } from '../lib/dates.ts'
16
20
  import { mcpClientConfig, mcpEndpoint } from '../lib/mcpConfig.ts'
21
+ import { Chip } from './Chip.tsx'
17
22
  import { CopyButton } from './CopyButton.tsx'
18
23
  import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
19
24
 
@@ -29,7 +34,25 @@ export interface ApiKeysPanelProps {
29
34
  readonly emptyMessage: string
30
35
  }
31
36
 
32
- const PRESET_OPTIONS = API_KEY_PRESET_SCOPES.filter((scope) => scope !== 'write:all')
37
+ const OPT_IN_SCOPES: readonly ApiKeyScope[] = API_KEY_OPT_IN_SCOPES
38
+
39
+ /**
40
+ * The presets with a tick box in the Presets list. `write:all` is not offered
41
+ * as a preset, and a preset that is an extra permission has its tick box in
42
+ * that section, where it is beside what it risks.
43
+ */
44
+ const PRESET_OPTIONS = API_KEY_PRESET_SCOPES.filter((scope) => scope !== 'write:all' && !OPT_IN_SCOPES.includes(scope))
45
+
46
+ const GRID_SCOPES: ReadonlySet<ApiKeyScope> = new Set(API_KEY_SCOPE_GROUPS.flatMap((group) => group.scopes))
47
+
48
+ /**
49
+ * The extra permissions that the custom grid has no tick box for, by name or
50
+ * by the scopes they expand to. With custom scopes these are the only extras
51
+ * shown: a second tick box for a scope in the grid could disagree with it.
52
+ */
53
+ const EXTRAS_OUTSIDE_GRID = API_KEY_OPT_IN_SCOPES.filter((scope) =>
54
+ [...expandApiKeyScopes([scope])].some((granular) => !GRID_SCOPES.has(granular)),
55
+ )
33
56
 
34
57
  export function ApiKeysPanel({
35
58
  kind,
@@ -117,46 +140,89 @@ function CreateKeyModal({
117
140
  }): React.JSX.Element {
118
141
  const createApiKey = useCreateApiKey()
119
142
  const [name, setName] = useState('')
120
- const [accessMode, setAccessMode] = useState<AccessMode>('full')
121
- const [selectedPresets, setSelectedPresets] = useState<readonly ApiKeyScope[]>([])
143
+ // The form opens on the scopes the server gives a key that names none, so
144
+ // what a person sees ticked is what a person who only clicks Create gets.
145
+ const [accessMode, setAccessMode] = useState<AccessMode>('presets')
146
+ const [selectedPresets, setSelectedPresets] = useState<readonly ApiKeyScope[]>(API_KEY_DEFAULT_SCOPES)
122
147
  const [selectedCustom, setSelectedCustom] = useState<readonly ApiKeyScope[]>([])
148
+ // Apart from the presets and the custom grid: no preset in the list above
149
+ // them includes one, so a person adds it to either.
150
+ const [selectedExtras, setSelectedExtras] = useState<readonly ApiKeyScope[]>([])
123
151
  const [showCustom, setShowCustom] = useState(false)
152
+ const hintId = useId()
153
+ const offeredExtras = accessMode === 'custom' ? EXTRAS_OUTSIDE_GRID : API_KEY_OPT_IN_SCOPES
124
154
 
125
155
  const presetExpandedScopes = useMemo(
126
- () => expandApiKeyScopes(selectedPresets),
127
- [selectedPresets],
156
+ () => expandApiKeyScopes([...selectedPresets, ...selectedExtras]),
157
+ [selectedPresets, selectedExtras],
128
158
  )
129
159
 
160
+ /**
161
+ * Moves to the custom grid. Every extra that the grid can show goes into
162
+ * it, so nothing stays ticked in a place the person can no longer see.
163
+ */
164
+ function enterCustomMode(scopes: readonly ApiKeyScope[]): void {
165
+ const outsideGrid: readonly ApiKeyScope[] = EXTRAS_OUTSIDE_GRID
166
+
167
+ setAccessMode('custom')
168
+ setSelectedPresets([])
169
+ setSelectedCustom(scopes.filter((scope) => GRID_SCOPES.has(scope)))
170
+ setSelectedExtras((current) => current.filter((scope) => outsideGrid.includes(scope)))
171
+ }
172
+
173
+ // The grid stays open while it holds a tick. What the form sends must be on
174
+ // the page: a hidden grid with ticks in it would send scopes nobody can see.
130
175
  const showScopeGrid =
131
- (accessMode === 'custom' && showCustom) ||
176
+ (accessMode === 'custom' && (showCustom || selectedCustom.length > 0)) ||
132
177
  (accessMode === 'presets' && selectedPresets.length > 0)
133
178
 
134
- function scopesForCreate(): readonly ApiKeyScope[] | undefined {
135
- if (accessMode === 'full') {
136
- return undefined
137
- }
179
+ const chosenScopes: readonly ApiKeyScope[] =
180
+ accessMode === 'full'
181
+ ? []
182
+ : [...(accessMode === 'presets' ? selectedPresets : selectedCustom), ...selectedExtras]
183
+ // A request with no scopes gets the server's default ones. The form never
184
+ // sends that: it would create a key that differs from what is ticked.
185
+ const nothingChosen = accessMode !== 'full' && chosenScopes.length === 0
138
186
 
139
- if (accessMode === 'presets') {
140
- return selectedPresets.length === 0 ? undefined : selectedPresets
141
- }
142
-
143
- return selectedCustom.length === 0 ? undefined : selectedCustom
187
+ function toggleExtra(scope: ApiKeyScope): void {
188
+ setSelectedExtras((current) =>
189
+ current.includes(scope) ? current.filter((entry) => entry !== scope) : [...current, scope],
190
+ )
144
191
  }
145
192
 
146
193
  function submit(event: FormEvent): void {
147
194
  event.preventDefault()
148
- const scopes = scopesForCreate()
195
+
196
+ if (nothingChosen) {
197
+ return
198
+ }
149
199
 
150
200
  createApiKey
151
201
  .runAsync({
152
202
  name: name.trim(),
153
203
  kind,
154
- ...(scopes === undefined ? {} : { scopes }),
204
+ ...(accessMode === 'full' ? { fullAccess: true } : { scopes: chosenScopes }),
155
205
  })
156
206
  .then(onCreated)
157
207
  .catch(() => undefined)
158
208
  }
159
209
 
210
+ function toggleFullAccess(): void {
211
+ setSelectedCustom([])
212
+ setSelectedExtras([])
213
+ setShowCustom(false)
214
+
215
+ if (accessMode === 'full') {
216
+ setAccessMode('presets')
217
+ setSelectedPresets(API_KEY_DEFAULT_SCOPES)
218
+
219
+ return
220
+ }
221
+
222
+ setAccessMode('full')
223
+ setSelectedPresets([])
224
+ }
225
+
160
226
  function togglePreset(scope: ApiKeyScope): void {
161
227
  setAccessMode('presets')
162
228
  setSelectedCustom([])
@@ -208,52 +274,40 @@ function CreateKeyModal({
208
274
  <fieldset className="mt-4">
209
275
  <legend className="mb-2 text-[12px] font-medium text-ink">Access</legend>
210
276
  <div className="space-y-2">
211
- <label className="flex items-center gap-2 text-[13px] text-ink">
212
- <input
213
- type="radio"
214
- name="access"
215
- checked={accessMode === 'full'}
216
- onChange={() => {
217
- setAccessMode('full')
218
- setSelectedPresets([])
219
- setSelectedCustom([])
220
- setShowCustom(false)
221
- }}
222
- />
223
- Full access
224
- </label>
225
- <div className="rounded-md border border-border p-3">
226
- <p className="mb-2 text-[11px] font-medium tracking-wide text-ink-muted uppercase">
227
- Presets
228
- </p>
229
- <div className="space-y-1.5">
230
- {PRESET_OPTIONS.map((scope) => (
231
- <label key={scope} className="flex items-center gap-2 text-[13px] text-ink">
232
- <input
233
- type="checkbox"
234
- checked={accessMode === 'presets' && selectedPresets.includes(scope)}
235
- onChange={() => {
236
- togglePreset(scope)
237
- }}
238
- />
239
- {API_KEY_SCOPE_LABELS[scope]}
240
- </label>
241
- ))}
277
+ {accessMode !== 'full' && (
278
+ <div className="rounded-md border border-border p-3">
279
+ <p className="mb-2 text-[11px] font-medium tracking-wide text-ink-muted uppercase">
280
+ Presets
281
+ </p>
282
+ <div className="space-y-1.5">
283
+ {PRESET_OPTIONS.map((scope) => (
284
+ <label key={scope} className="flex items-center gap-2 text-[13px] text-ink">
285
+ <input
286
+ type="checkbox"
287
+ checked={accessMode === 'presets' && selectedPresets.includes(scope)}
288
+ onChange={() => {
289
+ togglePreset(scope)
290
+ }}
291
+ />
292
+ {API_KEY_SCOPE_LABELS[scope]}
293
+ </label>
294
+ ))}
295
+ </div>
242
296
  </div>
243
- </div>
244
- {accessMode !== 'presets' && (
297
+ )}
298
+ {((accessMode === 'custom' && selectedCustom.length === 0) ||
299
+ (accessMode === 'presets' && selectedPresets.length === 0)) && (
245
300
  <button
246
301
  type="button"
247
302
  onClick={() => {
248
303
  setShowCustom((open) => !open)
249
- if (!showCustom) {
250
- setAccessMode('custom')
251
- setSelectedPresets([])
304
+ if (!showCustom && accessMode !== 'custom') {
305
+ enterCustomMode([...presetExpandedScopes])
252
306
  }
253
307
  }}
254
308
  className="text-[12px] font-medium text-accent hover:underline"
255
309
  >
256
- {showCustom ? 'Hide custom scopes' : 'Custom scopes…'}
310
+ {showCustom && accessMode === 'custom' ? 'Hide custom scopes' : 'Custom scopes…'}
257
311
  </button>
258
312
  )}
259
313
  {showScopeGrid && (
@@ -294,9 +348,7 @@ function CreateKeyModal({
294
348
  <button
295
349
  type="button"
296
350
  onClick={() => {
297
- setAccessMode('custom')
298
- setSelectedPresets([])
299
- setSelectedCustom([...presetExpandedScopes])
351
+ enterCustomMode([...presetExpandedScopes])
300
352
  setShowCustom(true)
301
353
  }}
302
354
  className="text-[12px] font-medium text-accent hover:underline"
@@ -306,9 +358,48 @@ function CreateKeyModal({
306
358
  )}
307
359
  </div>
308
360
  )}
361
+ {accessMode !== 'full' && (
362
+ <div role="group" aria-label="Extra permissions" className="rounded-md border border-border p-3">
363
+ <p aria-hidden className="mb-2 text-[11px] font-medium tracking-wide text-ink-muted uppercase">
364
+ Extra permissions
365
+ </p>
366
+ <div className="space-y-2">
367
+ {offeredExtras.map((scope) => (
368
+ <label key={scope} className="flex items-start gap-2 text-[13px] text-ink">
369
+ <input
370
+ type="checkbox"
371
+ className="mt-0.5"
372
+ checked={selectedExtras.includes(scope)}
373
+ onChange={() => {
374
+ toggleExtra(scope)
375
+ }}
376
+ />
377
+ <span>
378
+ {API_KEY_SCOPE_LABELS[scope]}
379
+ <span className="block text-[11px] text-ink-muted">{apiKeyScopeRisk(scope)}</span>
380
+ </span>
381
+ </label>
382
+ ))}
383
+ </div>
384
+ </div>
385
+ )}
386
+ <div className="rounded-md border border-warning/40 bg-warning-soft p-3">
387
+ <label className="flex items-center gap-2 text-[13px] font-medium text-ink">
388
+ <input type="checkbox" checked={accessMode === 'full'} onChange={toggleFullAccess} />
389
+ Full access
390
+ </label>
391
+ <p className="mt-1 text-[11px] text-warning">
392
+ {kind === 'workspace'
393
+ ? 'A full-access workspace key can do everything an admin can in this workspace: delete records, change the handbook, and manage members, keys and webhooks.'
394
+ : 'A full-access personal key can do everything you can do in this workspace, now and after your role changes. That includes deleting records.'}{' '}
395
+ Choose it only for a program that you control completely.
396
+ </p>
397
+ </div>
309
398
  </div>
310
- <p className="mt-2 text-[11px] text-ink-faint">
311
- Write includes read for the same resource. Presets cover many scopes at once.
399
+ <p id={hintId} className="mt-2 text-[11px] text-ink-faint">
400
+ {nothingChosen
401
+ ? 'Choose at least one permission, or full access.'
402
+ : 'Write includes read for the same resource, and does not include delete. Presets cover many scopes at once. No preset includes an extra permission.'}
312
403
  </p>
313
404
  </fieldset>
314
405
 
@@ -328,7 +419,10 @@ function CreateKeyModal({
328
419
  </button>
329
420
  <button
330
421
  type="submit"
331
- disabled={createApiKey.isPending}
422
+ disabled={createApiKey.isPending || nothingChosen}
423
+ // The hint says why the button is off. A screen reader reads it
424
+ // with the button, which is otherwise only greyed out.
425
+ aria-describedby={nothingChosen ? hintId : undefined}
332
426
  className="rounded-md bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
333
427
  >
334
428
  {createApiKey.isPending ? 'Creating…' : 'Create'}
@@ -385,24 +479,46 @@ function SecretOnce({
385
479
  )
386
480
  }
387
481
 
482
+ /**
483
+ * The scopes of a key that give no sensitive power, in a few words: each
484
+ * preset by name, and the per-resource ones as a count.
485
+ */
388
486
  function formatScopeSummary(scopes: readonly ApiKeyScope[]): string {
389
- if (scopes.length === 0) {
390
- return 'Full access'
391
- }
487
+ const plain = scopes.filter((scope) => !isSensitiveApiKeyScope(scope) || scope === 'write:all')
488
+ const presets = plain.filter(isApiKeyPresetScope)
489
+ const granular = plain.filter((scope) => !isApiKeyPresetScope(scope))
490
+ const custom =
491
+ presets.length === 0 ? `Custom (${String(granular.length)} scopes)` : `Custom (${String(granular.length)})`
392
492
 
393
- const presets = scopes.filter(isApiKeyPresetScope)
394
- const granular = scopes.filter(isApiKeyGranularScope)
493
+ return [...presets.map((scope) => API_KEY_SCOPE_LABELS[scope]), ...(granular.length === 0 ? [] : [custom])].join(', ')
494
+ }
395
495
 
396
- if (granular.length === 0) {
397
- return presets.map((scope) => API_KEY_SCOPE_LABELS[scope]).join(', ')
496
+ /**
497
+ * What a key can reach, for the list. A sensitive power is always named and
498
+ * never counted into "Custom": a count would hide that a key can delete
499
+ * records or change the handbook. `write:all` stays in the words, and what it
500
+ * holds that is sensitive is named beside it.
501
+ */
502
+ function ScopeSummary({ scopes }: { readonly scopes: readonly ApiKeyScope[] }): React.JSX.Element {
503
+ if (scopes.length === 0) {
504
+ return <Chip tone="warning">Full access</Chip>
398
505
  }
399
506
 
400
- if (presets.length === 0) {
401
- return `Custom (${String(scopes.length)} scopes)`
402
- }
507
+ const sensitive = sensitiveApiKeyScopesHeld(scopes)
403
508
 
404
- return [...presets.map((scope) => API_KEY_SCOPE_LABELS[scope]), `Custom (${String(granular.length)})`].join(
405
- ', ',
509
+ return (
510
+ <>
511
+ {formatScopeSummary(scopes)}
512
+ {sensitive.length > 0 && (
513
+ <ul aria-label="Extra permissions" className="mt-1 flex flex-wrap gap-1">
514
+ {sensitive.map((scope) => (
515
+ <li key={scope}>
516
+ <Chip tone="warning">{API_KEY_SCOPE_LABELS[scope]}</Chip>
517
+ </li>
518
+ ))}
519
+ </ul>
520
+ )}
521
+ </>
406
522
  )
407
523
  }
408
524
 
@@ -463,7 +579,9 @@ function ApiKeyRow({
463
579
  return (
464
580
  <tr className="border-b border-border last:border-0">
465
581
  <td className="px-4 py-3 font-medium">{apiKey.name}</td>
466
- <td className="px-4 py-3 text-ink-muted">{formatScopeSummary(apiKey.scopes)}</td>
582
+ <td className="px-4 py-3 text-ink-muted">
583
+ <ScopeSummary scopes={apiKey.scopes} />
584
+ </td>
467
585
  <td className="px-4 py-3 font-mono text-[12px] text-ink-muted">{apiKey.displayPrefix}</td>
468
586
  <td className="px-4 py-3 text-ink-muted">{formatDate(apiKey.createdAt, timezone)}</td>
469
587
  <td className="px-4 py-3 text-ink-muted">
@@ -6,6 +6,10 @@ export interface ChipProps {
6
6
  readonly children: ReactNode
7
7
  readonly tone?: ChipTone
8
8
  readonly onClick?: () => void
9
+ /** Adds an × button after the label. Takes precedence over `onClick`. */
10
+ readonly onRemove?: () => void
11
+ /** The × button's accessible name. Defaults to "Remove". */
12
+ readonly removeLabel?: string
9
13
  }
10
14
 
11
15
  const toneClasses: Readonly<Record<ChipTone, string>> = {
@@ -17,7 +21,34 @@ const toneClasses: Readonly<Record<ChipTone, string>> = {
17
21
  }
18
22
 
19
23
  /** A small status pill. Ported from `RecordHeader.tsx` in the mockups. */
20
- export function Chip({ children, tone = 'neutral', onClick }: ChipProps): React.JSX.Element {
24
+ export function Chip({
25
+ children,
26
+ tone = 'neutral',
27
+ onClick,
28
+ onRemove,
29
+ removeLabel = 'Remove',
30
+ }: ChipProps): React.JSX.Element {
31
+ if (onRemove !== undefined) {
32
+ return (
33
+ <span
34
+ className={[
35
+ 'inline-flex items-center gap-1 rounded border py-0.5 pr-0.5 pl-1.5 text-[10px] font-medium leading-none',
36
+ toneClasses[tone],
37
+ ].join(' ')}
38
+ >
39
+ {children}
40
+ <button
41
+ type="button"
42
+ onClick={onRemove}
43
+ aria-label={removeLabel}
44
+ className="rounded px-0.5 text-[11px] leading-none opacity-60 hover:bg-surface hover:opacity-100"
45
+ >
46
+ ×
47
+ </button>
48
+ </span>
49
+ )
50
+ }
51
+
21
52
  const className = [
22
53
  'inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium leading-none',
23
54
  toneClasses[tone],
@@ -10,6 +10,7 @@ import { useMemo, useState } from 'react'
10
10
  import { Link } from 'react-router'
11
11
 
12
12
  import { useCustomFields } from '../api/resources/customFields.ts'
13
+ import { useSession } from '../api/resources/session.ts'
13
14
  import { InlineEdit } from './InlineEdit.tsx'
14
15
 
15
16
  /**
@@ -42,6 +43,8 @@ export function CustomFieldsPanel({
42
43
  onPatch,
43
44
  }: CustomFieldsPanelProps): React.JSX.Element {
44
45
  const definitions = useCustomFields({ objectType, sort: 'sort_order', limit: 200 })
46
+ const { session } = useSession()
47
+ const isAdmin = session?.role === 'owner' || session?.role === 'admin'
45
48
 
46
49
  if (definitions.isLoading) {
47
50
  return <p className="text-[13px] text-ink-muted">Loading fields…</p>
@@ -50,11 +53,18 @@ export function CustomFieldsPanel({
50
53
  if (definitions.records.length === 0) {
51
54
  return (
52
55
  <p className="text-[13px] text-ink-muted">
53
- No custom fields yet. Add them at{' '}
54
- <Link to="/admin/fields" className="text-accent hover:text-accent-hover">
55
- Admin → Fields
56
- </Link>
57
- .
56
+ No custom fields yet.
57
+ {/* Admin is closed to a member, so only an admin gets the link. */}
58
+ {isAdmin && (
59
+ <>
60
+ {' '}
61
+ Add them at{' '}
62
+ <Link to="/admin/fields" className="text-accent hover:text-accent-hover">
63
+ Admin → Fields
64
+ </Link>
65
+ .
66
+ </>
67
+ )}
58
68
  </p>
59
69
  )
60
70
  }
@@ -0,0 +1,95 @@
1
+ import type { WriteOrigin } from '@kelpie/schemas'
2
+
3
+ import { Chip } from './Chip.tsx'
4
+ import { OriginLabel } from './OriginLabel.tsx'
5
+
6
+ /**
7
+ * What a reader must know before trusting a Decision: whether a member has
8
+ * confirmed it, and what wrote it.
9
+ *
10
+ * A Decision with no `confirmedAt` is a proposal. A hosted AI run writes one,
11
+ * and so does an agent whose connection cannot commit Decisions. It is shown as
12
+ * not confirmed until a member confirms it. A confirmed one shows only its
13
+ * origin, and nothing at all when a member wrote it.
14
+ */
15
+
16
+ const NAME_EXCERPT_LENGTH = 60
17
+
18
+ function excerpt(body: string): string {
19
+ const line = body.replace(/\s+/gu, ' ').trim()
20
+
21
+ return line.length <= NAME_EXCERPT_LENGTH ? line : `${line.slice(0, NAME_EXCERPT_LENGTH)}…`
22
+ }
23
+
24
+ /**
25
+ * Says that a confirm succeeded, for a screen reader. A sighted reader sees the
26
+ * row lose its "not confirmed" label; nothing else would tell a reader who
27
+ * cannot. Always in the page, so that the change of its text is announced.
28
+ */
29
+ export function ConfirmedAnnouncement({ count }: { readonly count: number }): React.JSX.Element {
30
+ return (
31
+ <p role="status" className="sr-only">
32
+ {count === 0 ? '' : count === 1 ? 'Decision confirmed.' : `${String(count)} decisions confirmed.`}
33
+ </p>
34
+ )
35
+ }
36
+
37
+ /**
38
+ * What a proposal says about itself. The server writes no proposal with
39
+ * `member` or `unknown` today: a member's own Decision is confirmed as it is
40
+ * written, and an agent's rewrite changes the origin to `agent`. The label
41
+ * for those two claims nothing about who proposed it.
42
+ */
43
+ const PROPOSAL_LABELS: Readonly<Record<WriteOrigin, string>> = {
44
+ ai: 'Proposed by AI — not confirmed',
45
+ agent: 'Proposed by an agent — not confirmed',
46
+ member: 'Not confirmed',
47
+ unknown: 'Not confirmed',
48
+ }
49
+
50
+ export interface DecisionProvenanceProps {
51
+ readonly origin: WriteOrigin
52
+ readonly confirmedAt: Date | null
53
+ }
54
+
55
+ export function DecisionProvenance({ origin, confirmedAt }: DecisionProvenanceProps): React.JSX.Element | null {
56
+ if (confirmedAt !== null) {
57
+ return <OriginLabel origin={origin} />
58
+ }
59
+
60
+ return <Chip tone="warning">{PROPOSAL_LABELS[origin]}</Chip>
61
+ }
62
+
63
+ /**
64
+ * Confirms a proposal. Shown only on a Decision that is not confirmed.
65
+ *
66
+ * The API refuses every caller but a signed-in member, so this button is the
67
+ * one place a proposal becomes a commitment.
68
+ */
69
+ export function ConfirmDecisionButton({
70
+ body,
71
+ onConfirm,
72
+ isPending,
73
+ }: {
74
+ /** The Decision's text. Its start goes into the button's name. */
75
+ readonly body: string
76
+ readonly onConfirm: () => void
77
+ readonly isPending: boolean
78
+ }): React.JSX.Element {
79
+ return (
80
+ <button
81
+ type="button"
82
+ onClick={onConfirm}
83
+ disabled={isPending}
84
+ // A page can hold several of these. A screen reader lists buttons by
85
+ // name, and "Confirm" five times does not say what each one confirms.
86
+ // The name replaces the visible text for a screen reader, so it has to
87
+ // change with it while the confirm is in flight.
88
+ aria-label={`${isPending ? 'Confirming' : 'Confirm'} decision: ${excerpt(body)}`}
89
+ aria-busy={isPending}
90
+ className="shrink-0 rounded-md bg-accent px-2 py-0.5 text-[11px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
91
+ >
92
+ {isPending ? 'Confirming…' : 'Confirm'}
93
+ </button>
94
+ )
95
+ }