@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
@@ -1,4 +1,10 @@
1
- import { API_KEY_SCOPE_LABELS } from '@kelpie/schemas'
1
+ import {
2
+ API_KEY_SCOPE_LABELS,
3
+ apiKeyScopeRisk,
4
+ expandApiKeyScopes,
5
+ isApiKeyPresetScope,
6
+ isApiKeyRiskScope,
7
+ } from '@kelpie/schemas'
2
8
  import type { ApiKeyScope, OAuthRequest } from '@kelpie/schemas'
3
9
  import { useState } from 'react'
4
10
  import { Link, Navigate, useParams } from 'react-router'
@@ -22,7 +28,7 @@ import { AuthLayout } from '../auth/AuthLayout.tsx'
22
28
  */
23
29
  export function ConsentPage(): React.JSX.Element {
24
30
  const { requestId = '' } = useParams()
25
- const { isLoading: sessionLoading, isSignedOut, error: sessionError } = useSession()
31
+ const { session, isLoading: sessionLoading, isSignedOut, error: sessionError } = useSession()
26
32
 
27
33
  if (isSignedOut) {
28
34
  return <Navigate to={`/login?next=${encodeURIComponent(`/consent/${requestId}`)}`} replace />
@@ -42,10 +48,16 @@ export function ConsentPage(): React.JSX.Element {
42
48
  return <LoadingPanel />
43
49
  }
44
50
 
45
- return <ConsentForRequest requestId={requestId} />
51
+ return <ConsentForRequest requestId={requestId} activeWorkspaceId={session?.workspaceId ?? null} />
46
52
  }
47
53
 
48
- function ConsentForRequest({ requestId }: { readonly requestId: string }): React.JSX.Element {
54
+ interface ConsentForRequestProps {
55
+ readonly requestId: string
56
+ /** The workspace the session is in, which is the one ticked at the start. */
57
+ readonly activeWorkspaceId: string | null
58
+ }
59
+
60
+ function ConsentForRequest({ requestId, activeWorkspaceId }: ConsentForRequestProps): React.JSX.Element {
49
61
  const { request, isLoading, error } = useOAuthRequest(requestId)
50
62
 
51
63
  if (error !== null) {
@@ -65,14 +77,140 @@ function ConsentForRequest({ requestId }: { readonly requestId: string }): React
65
77
  return <LoadingPanel label="Loading the request…" />
66
78
  }
67
79
 
68
- return <ConsentForm request={request} />
80
+ return <ConsentForm request={request} activeWorkspaceId={activeWorkspaceId} />
81
+ }
82
+
83
+ interface ConsentFormProps {
84
+ readonly request: OAuthRequest
85
+ readonly activeWorkspaceId: string | null
86
+ }
87
+
88
+ /**
89
+ * The workspaces ticked when the page opens.
90
+ *
91
+ * When the app is connected already, they are the workspaces it is connected
92
+ * to, whichever workspace the session is in. The app is then asking for more
93
+ * access, and an approval that named another workspace would make a new
94
+ * connection there and end the one that asked.
95
+ *
96
+ * For an app that is new to this person: the workspace the session is in, or
97
+ * the first when the session has none the person can connect. One, never all:
98
+ * a person who only clicks Allow gives the app the workspace they are working in.
99
+ */
100
+ function initialWorkspaceIds(request: OAuthRequest, activeWorkspaceId: string | null): readonly string[] {
101
+ const connected = request.workspaces.filter((workspace) => workspace.connected)
102
+
103
+ if (connected.length > 0) {
104
+ return connected.map((workspace) => workspace.id)
105
+ }
106
+
107
+ const active = request.workspaces.find((workspace) => workspace.id === activeWorkspaceId)
108
+ const first = active ?? request.workspaces[0]
109
+
110
+ return first === undefined ? [] : [first.id]
69
111
  }
70
112
 
71
- function ConsentForm({ request }: { readonly request: OAuthRequest }): React.JSX.Element {
113
+ /**
114
+ * The scopes the page offers: each preset the app asked for, then each
115
+ * per-resource scope that none of those presets includes.
116
+ *
117
+ * A per-resource scope inside a requested preset is not listed. The preset
118
+ * grants it, so a separate tick box for it would change nothing. Only the
119
+ * listed scopes are approved: clearing a preset also drops what it included.
120
+ *
121
+ * A scope that gives a sensitive power is not listed here, also when the app
122
+ * asked for it. The server names those in `extraScopes`; they are in their
123
+ * own section and start clear.
124
+ */
125
+ function offeredScopes(request: OAuthRequest): readonly ApiKeyScope[] {
126
+ const requested = request.scopes.filter((scope) => !request.extraScopes.includes(scope))
127
+ const presets = requested.filter(isApiKeyPresetScope)
128
+ const included: ReadonlySet<ApiKeyScope> = expandApiKeyScopes(presets)
129
+
130
+ return [...presets, ...requested.filter((scope) => !isApiKeyPresetScope(scope) && !included.has(scope))]
131
+ }
132
+
133
+ function ConsentForm({ request, activeWorkspaceId }: ConsentFormProps): React.JSX.Element {
72
134
  const approve = useApproveOAuthRequest()
73
135
  const deny = useDenyOAuthRequest()
74
- const [workspaceId, setWorkspaceId] = useState(request.workspaces[0]?.id ?? '')
75
- const [scopes, setScopes] = useState<readonly ApiKeyScope[]>(request.scopes)
136
+ const [workspaceIds, setWorkspaceIds] = useState<readonly string[]>(() =>
137
+ initialWorkspaceIds(request, activeWorkspaceId),
138
+ )
139
+ const [onlyWorkspace] = request.workspaces
140
+ const offered = offeredScopes(request)
141
+ const [scopes, setScopes] = useState<readonly ApiKeyScope[]>(offered)
142
+ // Only what the person changed by hand. An extra they did not touch is
143
+ // ticked when the app has it already in every selected workspace, and
144
+ // clear otherwise, so it follows the workspaces as they are ticked.
145
+ const [extraChoices, setExtraChoices] = useState<ReadonlyMap<ApiKeyScope, boolean>>(new Map())
146
+ const selectedWorkspaces = request.workspaces.filter((workspace) => workspaceIds.includes(workspace.id))
147
+
148
+ /**
149
+ * True when an approval with this extra ticked gives nothing new: each
150
+ * selected workspace has it from an earlier approval. The server says what
151
+ * each workspace holds. One workspace that lacks it makes this false, so a
152
+ * tick that nobody made never gives a new power anywhere.
153
+ */
154
+ function alreadyAllowed(scope: ApiKeyScope): boolean {
155
+ return (
156
+ selectedWorkspaces.length > 0 && selectedWorkspaces.every((workspace) => workspace.heldScopes.includes(scope))
157
+ )
158
+ }
159
+
160
+ function extraTicked(scope: ApiKeyScope): boolean {
161
+ return extraChoices.get(scope) ?? alreadyAllowed(scope)
162
+ }
163
+
164
+ /**
165
+ * The selected workspaces that have this extra now, when some have it and
166
+ * some do not. The row then starts clear, and an approval takes the extra
167
+ * away where the app had it. The row has to say so.
168
+ */
169
+ function allowedOnlyIn(scope: ApiKeyScope): readonly string[] {
170
+ const holders = selectedWorkspaces.filter((workspace) => workspace.heldScopes.includes(scope))
171
+
172
+ return holders.length === selectedWorkspaces.length ? [] : holders.map((workspace) => workspace.name)
173
+ }
174
+
175
+ /**
176
+ * For an app on this computer: every workspace where it has this extra
177
+ * now, ticked on this page or not. Read from the display fields and shown
178
+ * as words. No tick on this page is ever taken from them.
179
+ */
180
+ function shownAsAllowedIn(scope: ApiKeyScope): readonly string[] {
181
+ if (!request.localClient) {
182
+ return []
183
+ }
184
+
185
+ return request.workspaces
186
+ .filter((workspace) => workspace.displayHeldScopes.includes(scope))
187
+ .map((workspace) => workspace.name)
188
+ }
189
+
190
+ function connectedNow(workspace: OAuthRequest['workspaces'][number]): boolean {
191
+ return request.localClient && workspace.displayConnected
192
+ }
193
+
194
+ /**
195
+ * The ticked extra that gives everything this one gives and more, if there
196
+ * is one: "Delete objects" for `people:delete`, "Write all" for "Handbook
197
+ * (write)". The narrower row is then shown ticked and locked. Clear, it
198
+ * would say the app does not get a power that the wider row gives it.
199
+ */
200
+ function widerTickedExtra(scope: ApiKeyScope): ApiKeyScope | undefined {
201
+ const needed = [...expandApiKeyScopes([scope])]
202
+
203
+ return request.extraScopes.find((other) => {
204
+ const given = expandApiKeyScopes([other])
205
+
206
+ return other !== scope && extraTicked(other) && given.size > needed.length && needed.every((entry) => given.has(entry))
207
+ })
208
+ }
209
+
210
+ // Only the rows the person ticked, or left ticked. A row that is shown
211
+ // ticked because a wider one covers it is not sent: the wider one gives it.
212
+ const extras = request.extraScopes.filter(extraTicked)
213
+ const nothingTicked = scopes.length + extras.length === 0
76
214
  const [leaving, setLeaving] = useState(false)
77
215
  const busy = approve.isPending || deny.isPending || leaving
78
216
 
@@ -87,11 +225,19 @@ function ConsentForm({ request }: { readonly request: OAuthRequest }): React.JSX
87
225
  setScopes((current) => (current.includes(scope) ? current.filter((entry) => entry !== scope) : [...current, scope]))
88
226
  }
89
227
 
228
+ function toggleExtra(scope: ApiKeyScope): void {
229
+ setExtraChoices((current) => new Map(current).set(scope, !extraTicked(scope)))
230
+ }
231
+
232
+ function toggleWorkspace(id: string): void {
233
+ setWorkspaceIds((current) => (current.includes(id) ? current.filter((entry) => entry !== id) : [...current, id]))
234
+ }
235
+
90
236
  if (request.workspaces.length === 0) {
91
237
  return (
92
238
  <AuthLayout
93
239
  title={`Connect ${request.clientName}`}
94
- description="A connection is made to one workspace, and this account is not a member of any."
240
+ description="A connection is made to a workspace, and this account is not a member of any."
95
241
  >
96
242
  <p className="mt-4 text-[13px] text-ink-muted">
97
243
  <Link to="/onboarding/workspace" className="text-accent hover:underline">
@@ -137,30 +283,59 @@ function ConsentForm({ request }: { readonly request: OAuthRequest }): React.JSX
137
283
  )}
138
284
  </div>
139
285
 
140
- <label className="block">
141
- <span className="mb-1.5 block text-[12px] font-medium text-ink">Workspace</span>
142
- <select
143
- value={workspaceId}
144
- onChange={(event) => {
145
- setWorkspaceId(event.target.value)
146
- }}
147
- className="w-full rounded-md border border-border bg-surface px-3 py-2 text-[13px] text-ink outline-none focus:border-accent"
148
- >
149
- {request.workspaces.map((workspace) => (
150
- <option key={workspace.id} value={workspace.id}>
151
- {workspace.name}
152
- </option>
153
- ))}
154
- </select>
155
- <span className="mt-1 block text-[11px] text-ink-faint">
156
- The app sees this workspace only. To use another, connect again.
157
- </span>
158
- </label>
286
+ {request.localClient && (
287
+ <p className="rounded-md border border-border bg-surface px-3 py-2.5 text-[12px] text-ink-muted">
288
+ This app runs on your computer, so Kelpie does not use what you allowed it before. Tick each
289
+ workspace and each extra permission that it needs. What it has now is marked. After you select
290
+ Allow, the app uses only the workspaces that you tick here. Tick a connected workspace again to
291
+ keep it.
292
+ </p>
293
+ )}
294
+
295
+ {request.workspaces.length === 1 && onlyWorkspace !== undefined ? (
296
+ <div>
297
+ <p className="mb-1.5 text-[12px] font-medium text-ink">Workspace</p>
298
+ <p className="text-[13px] text-ink">
299
+ {onlyWorkspace.name}{' '}
300
+ <span className="text-ink-muted capitalize">({onlyWorkspace.role})</span>
301
+ {connectedNow(onlyWorkspace) && <span className="text-[11px] text-ink-muted"> · connected now</span>}
302
+ </p>
303
+ <p className="mt-1 text-[11px] text-ink-faint">The app sees this workspace only.</p>
304
+ </div>
305
+ ) : (
306
+ <fieldset>
307
+ <legend className="mb-1.5 text-[12px] font-medium text-ink">Workspaces</legend>
308
+ <div className="space-y-1.5">
309
+ {request.workspaces.map((workspace) => (
310
+ <label key={workspace.id} className="flex items-center gap-2 text-[13px] text-ink">
311
+ <input
312
+ type="checkbox"
313
+ checked={workspaceIds.includes(workspace.id)}
314
+ onChange={() => {
315
+ toggleWorkspace(workspace.id)
316
+ }}
317
+ />
318
+ <span className="min-w-0 flex-1 truncate">
319
+ {workspace.name}
320
+ {connectedNow(workspace) && <span className="text-[11px] text-ink-muted"> · connected now</span>}
321
+ </span>
322
+ <span className="shrink-0 text-[11px] text-ink-muted capitalize">{workspace.role}</span>
323
+ </label>
324
+ ))}
325
+ </div>
326
+ <p className="mt-1.5 text-[11px] text-ink-faint">
327
+ {workspaceIds.length > 1
328
+ ? 'The app can read and write in each of these workspaces.'
329
+ : 'The app sees only the workspaces you select.'}
330
+ </p>
331
+ </fieldset>
332
+ )}
159
333
 
160
- <fieldset>
334
+ {/* A request for sensitive scopes only has nothing to list here. */}
335
+ <fieldset hidden={offered.length === 0}>
161
336
  <legend className="mb-1.5 text-[12px] font-medium text-ink">Access</legend>
162
337
  <div className="space-y-1.5">
163
- {request.scopes.map((scope) => (
338
+ {offered.map((scope) => (
164
339
  <label key={scope} className="flex items-center gap-2 text-[13px] text-ink">
165
340
  <input
166
341
  type="checkbox"
@@ -174,10 +349,73 @@ function ConsentForm({ request }: { readonly request: OAuthRequest }): React.JSX
174
349
  ))}
175
350
  </div>
176
351
  <p className="mt-1.5 text-[11px] text-ink-faint">
177
- The app can do no more than your own role allows. Clear an item to give less access.
352
+ The app can do no more than your own role allows. Clear an item to give less access. A wider item,
353
+ such as Read all, includes the narrower ones.
178
354
  </p>
179
355
  </fieldset>
180
356
 
357
+ {request.extraScopes.length > 0 && (
358
+ <fieldset className="rounded-md border border-border px-3 py-2.5">
359
+ <legend className="px-1 text-[12px] font-medium text-ink">Extra permissions</legend>
360
+ <p className="mb-2 text-[11px] text-ink-muted">
361
+ Not part of the access above. Tick one only if you want this app to have it.
362
+ </p>
363
+ <div className="space-y-2">
364
+ {request.extraScopes.map((scope) => {
365
+ const wider = widerTickedExtra(scope)
366
+ const partly = allowedOnlyIn(scope)
367
+ const shown = shownAsAllowedIn(scope)
368
+
369
+ return (
370
+ <label key={scope} className="flex items-start gap-2 text-[13px] text-ink">
371
+ <input
372
+ type="checkbox"
373
+ className="mt-0.5"
374
+ checked={wider !== undefined || extraTicked(scope)}
375
+ disabled={wider !== undefined}
376
+ onChange={() => {
377
+ toggleExtra(scope)
378
+ }}
379
+ />
380
+ <span>
381
+ {API_KEY_SCOPE_LABELS[scope]}
382
+ {request.scopes.includes(scope) && (
383
+ <span className="text-[11px] text-ink-muted"> · this app asks for it</span>
384
+ )}
385
+ {alreadyAllowed(scope) && (
386
+ <span className="text-[11px] text-ink-muted"> · already allowed</span>
387
+ )}
388
+ {wider !== undefined && (
389
+ <span className="text-[11px] text-ink-muted"> · included in {API_KEY_SCOPE_LABELS[wider]}</span>
390
+ )}
391
+ {isApiKeyRiskScope(scope) && (
392
+ <span className="block text-[11px] text-ink-muted">{apiKeyScopeRisk(scope)}</span>
393
+ )}
394
+ {shown.length > 0 && (
395
+ <span className="block text-[11px] text-warning">
396
+ Allowed now in {shown.join(', ')}. Tick it to allow it in the workspaces you select.
397
+ </span>
398
+ )}
399
+ {partly.length > 0 && (
400
+ <span className="block text-[11px] text-warning">
401
+ Allowed now in {partly.join(', ')}.{' '}
402
+ {extraTicked(scope) || wider !== undefined
403
+ ? 'Ticked, it is allowed in every selected workspace.'
404
+ : 'If you leave it clear, it is removed there.'}
405
+ </span>
406
+ )}
407
+ </span>
408
+ </label>
409
+ )
410
+ })}
411
+ </div>
412
+ <p className="mt-2 text-[11px] text-ink-faint">
413
+ What you allow here replaces what this app had. Clear an item that is already allowed to take
414
+ it away.
415
+ </p>
416
+ </fieldset>
417
+ )}
418
+
181
419
  {approve.error !== null && <ErrorPanel error={approve.error} />}
182
420
  {deny.error !== null && <ErrorPanel error={deny.error} />}
183
421
 
@@ -199,10 +437,10 @@ function ConsentForm({ request }: { readonly request: OAuthRequest }): React.JSX
199
437
  </button>
200
438
  <button
201
439
  type="button"
202
- disabled={busy || scopes.length === 0 || workspaceId.length === 0}
440
+ disabled={busy || nothingTicked || workspaceIds.length === 0}
203
441
  onClick={() => {
204
442
  approve
205
- .runAsync({ requestId: request.id, workspaceId, scopes })
443
+ .runAsync({ requestId: request.id, workspaceIds, scopes: [...scopes, ...extras] })
206
444
  .then((decision) => {
207
445
  leaveTo(decision.redirectUrl)
208
446
  })
@@ -84,7 +84,7 @@ export interface RecordTab {
84
84
 
85
85
  /**
86
86
  * An admin page whose tabs modules may add to. `ai` is Admin → AI: core owns
87
- * the page and its MCP tab, and the optional `ai` module adds Kelpie AI's
87
+ * the page and its Agents tab, and the optional `ai` module adds Kelpie AI's
88
88
  * settings and run log.
89
89
  */
90
90
  export type ExtensibleAdminPage = 'ai'