@kelpie/ui 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/resources/ai.d.ts +5 -0
- package/dist/api/resources/ai.d.ts.map +1 -1
- package/dist/api/resources/ai.js +9 -1
- package/dist/api/resources/ai.js.map +1 -1
- package/dist/api/resources/forms.d.ts +8 -0
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +39 -0
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/api/resources/personIntake.d.ts +12 -0
- package/dist/api/resources/personIntake.d.ts.map +1 -0
- package/dist/api/resources/personIntake.js +54 -0
- package/dist/api/resources/personIntake.js.map +1 -0
- package/dist/app/KelpieApp.js +2 -2
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/AgentTasks.js +2 -2
- package/dist/components/AgentTasks.js.map +1 -1
- package/dist/components/PersonIntakeDialog.d.ts +19 -0
- package/dist/components/PersonIntakeDialog.d.ts.map +1 -0
- package/dist/components/PersonIntakeDialog.js +87 -0
- package/dist/components/PersonIntakeDialog.js.map +1 -0
- package/dist/components/Shell.js +1 -1
- package/dist/components/Shell.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/PersonIntakeWizard.d.ts +3 -0
- package/dist/modules/PersonIntakeWizard.d.ts.map +1 -0
- package/dist/modules/PersonIntakeWizard.js +223 -0
- package/dist/modules/PersonIntakeWizard.js.map +1 -0
- package/dist/modules/ai.d.ts +4 -3
- package/dist/modules/ai.d.ts.map +1 -1
- package/dist/modules/ai.js +10 -6
- package/dist/modules/ai.js.map +1 -1
- package/dist/modules/aiRunner.d.ts.map +1 -1
- package/dist/modules/aiRunner.js +7 -5
- package/dist/modules/aiRunner.js.map +1 -1
- package/dist/modules/personIntakeSelection.d.ts +7 -0
- package/dist/modules/personIntakeSelection.d.ts.map +1 -0
- package/dist/modules/personIntakeSelection.js +21 -0
- package/dist/modules/personIntakeSelection.js.map +1 -0
- package/dist/pages/FormsPage.js +4 -4
- package/dist/pages/FormsPage.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +7 -1
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/admin/AiAdminPage.d.ts +2 -0
- package/dist/pages/admin/AiAdminPage.d.ts.map +1 -0
- package/dist/pages/admin/AiAdminPage.js +19 -0
- package/dist/pages/admin/AiAdminPage.js.map +1 -0
- package/dist/pages/admin/AiPage.d.ts +4 -1
- package/dist/pages/admin/AiPage.d.ts.map +1 -1
- package/dist/pages/admin/AiPage.js +77 -15
- package/dist/pages/admin/AiPage.js.map +1 -1
- package/dist/pages/admin/McpPanel.d.ts +3 -0
- package/dist/pages/admin/McpPanel.d.ts.map +1 -0
- package/dist/pages/admin/McpPanel.js +123 -0
- package/dist/pages/admin/McpPanel.js.map +1 -0
- package/dist/pages/admin/PrivacyPage.js +19 -3
- package/dist/pages/admin/PrivacyPage.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +5 -2
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
- package/dist/pages/forms/FieldsEditor.js +90 -8
- package/dist/pages/forms/FieldsEditor.js.map +1 -1
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +73 -6
- package/dist/pages/forms/FormSettings.js.map +1 -1
- package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +2 -1
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +2 -1
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/fieldList.d.ts +2 -2
- package/dist/pages/forms/fieldList.d.ts.map +1 -1
- package/dist/pages/forms/fieldList.js +38 -10
- package/dist/pages/forms/fieldList.js.map +1 -1
- package/dist/pages/forms/template.d.ts.map +1 -1
- package/dist/pages/forms/template.js +13 -0
- package/dist/pages/forms/template.js.map +1 -1
- package/dist/registry/context.d.ts +5 -1
- package/dist/registry/context.d.ts.map +1 -1
- package/dist/registry/context.js +8 -0
- package/dist/registry/context.js.map +1 -1
- package/dist/registry/contributions.d.ts +32 -1
- package/dist/registry/contributions.d.ts.map +1 -1
- package/dist/registry/registry.d.ts +8 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +13 -0
- package/dist/registry/registry.js.map +1 -1
- package/package.json +2 -2
- package/src/api/resources/ai.ts +11 -1
- package/src/api/resources/forms.ts +56 -0
- package/src/api/resources/personIntake.ts +95 -0
- package/src/app/KelpieApp.tsx +4 -2
- package/src/components/AgentTasks.tsx +2 -2
- package/src/components/PersonIntakeDialog.tsx +226 -0
- package/src/components/Shell.tsx +1 -1
- package/src/index.ts +7 -1
- package/src/modules/PersonIntakeWizard.tsx +633 -0
- package/src/modules/ai.tsx +10 -6
- package/src/modules/aiRunner.ts +8 -5
- package/src/modules/personIntakeSelection.ts +24 -0
- package/src/pages/FormsPage.tsx +4 -4
- package/src/pages/PeoplePage.tsx +21 -5
- package/src/pages/admin/AiAdminPage.tsx +52 -0
- package/src/pages/admin/AiPage.tsx +136 -32
- package/src/pages/admin/{McpPage.tsx → McpPanel.tsx} +4 -6
- package/src/pages/admin/PrivacyPage.tsx +42 -0
- package/src/pages/forms/EmbedPanel.tsx +5 -1
- package/src/pages/forms/FieldsEditor.tsx +204 -15
- package/src/pages/forms/FormSettings.tsx +156 -9
- package/src/pages/forms/SubmissionDetail.tsx +2 -1
- package/src/pages/forms/SubmissionsTable.tsx +2 -1
- package/src/pages/forms/fieldList.ts +39 -10
- package/src/pages/forms/template.ts +13 -0
- package/src/registry/context.ts +13 -0
- package/src/registry/contributions.ts +34 -1
- package/src/registry/registry.ts +30 -0
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PERSON_INTAKE_KIND_LABELS,
|
|
3
|
+
PERSON_INTAKE_KINDS,
|
|
4
|
+
PERSON_INTAKE_PERSON_KEY,
|
|
5
|
+
personIntakeDependencies,
|
|
6
|
+
} from '@kelpie/schemas'
|
|
7
|
+
import type {
|
|
8
|
+
PersonIntakeCandidate,
|
|
9
|
+
PersonIntakeIdentifyResult,
|
|
10
|
+
PersonIntakeItem,
|
|
11
|
+
PersonIntakeKind,
|
|
12
|
+
PersonIntakeResearchResult,
|
|
13
|
+
PersonIntakeResult,
|
|
14
|
+
PersonIntakeResultStatus,
|
|
15
|
+
PersonIntakeSource,
|
|
16
|
+
} from '@kelpie/schemas'
|
|
17
|
+
import { useState } from 'react'
|
|
18
|
+
import { Link } from 'react-router'
|
|
19
|
+
|
|
20
|
+
import { useAiServiceLabel } from '../api/resources/ai.ts'
|
|
21
|
+
import { useApplyPersonIntake, useIdentifyPerson, useResearchPerson } from '../api/resources/personIntake.ts'
|
|
22
|
+
import { Chip } from '../components/Chip.tsx'
|
|
23
|
+
import type { ChipTone } from '../components/Chip.tsx'
|
|
24
|
+
import { IntakeFrame, NotesField } from '../components/PersonIntakeDialog.tsx'
|
|
25
|
+
import { ErrorPanel } from '../components/QueryState.tsx'
|
|
26
|
+
import type { PersonIntakeWizardProps } from '../registry/contributions.ts'
|
|
27
|
+
import { effectiveSelection } from './personIntakeSelection.ts'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The `ai` module's wizard behind People's **Add from notes**: notes, confirm the
|
|
31
|
+
* person, choose what to create, done. Spec: person intake, in the `ai`
|
|
32
|
+
* module's docs (`docs/agents/kelpie-ai.md`).
|
|
33
|
+
*
|
|
34
|
+
* The wizard holds no records of its own. Each step is one call to
|
|
35
|
+
* `/v1/ai/person-intake/*`, and the last writes only the ticked items.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
type Step =
|
|
39
|
+
| { readonly kind: 'notes' }
|
|
40
|
+
| { readonly kind: 'confirm'; readonly identified: PersonIntakeIdentifyResult }
|
|
41
|
+
| { readonly kind: 'choose'; readonly research: PersonIntakeResearchResult }
|
|
42
|
+
| { readonly kind: 'done'; readonly results: readonly PersonIntakeResult[] }
|
|
43
|
+
|
|
44
|
+
const STEP_LABELS = ['Notes', 'Confirm', 'Choose', 'Done'] as const
|
|
45
|
+
|
|
46
|
+
const STEP_INDEX: Readonly<Record<Step['kind'], number>> = { notes: 0, confirm: 1, choose: 2, done: 3 }
|
|
47
|
+
|
|
48
|
+
/** Pipeline records start unticked: the model suggests them, the user decides. */
|
|
49
|
+
const OFF_BY_DEFAULT: ReadonlySet<PersonIntakeKind> = new Set(['partnership', 'deal', 'enquiry'])
|
|
50
|
+
|
|
51
|
+
const primaryButton =
|
|
52
|
+
'rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50'
|
|
53
|
+
const secondaryButton =
|
|
54
|
+
'rounded-md px-2.5 py-1.5 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50'
|
|
55
|
+
|
|
56
|
+
export function PersonIntakeWizard({ onClose }: PersonIntakeWizardProps): React.JSX.Element {
|
|
57
|
+
const [step, setStep] = useState<Step>({ kind: 'notes' })
|
|
58
|
+
const [text, setText] = useState('')
|
|
59
|
+
const identify = useIdentifyPerson()
|
|
60
|
+
const research = useResearchPerson()
|
|
61
|
+
const apply = useApplyPersonIntake()
|
|
62
|
+
|
|
63
|
+
async function runIdentify(): Promise<void> {
|
|
64
|
+
const identified = await identify.runAsync(text.trim())
|
|
65
|
+
setStep({ kind: 'confirm', identified })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function runResearch(candidate: PersonIntakeCandidate, existingPersonId: string | null): Promise<void> {
|
|
69
|
+
const researched = await research.runAsync({ text: text.trim(), candidate, existingPersonId })
|
|
70
|
+
setStep({ kind: 'choose', research: researched })
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function runApply(items: readonly PersonIntakeItem[]): Promise<void> {
|
|
74
|
+
const applied = await apply.runAsync(items)
|
|
75
|
+
setStep({ kind: 'done', results: applied.results })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<StepBar current={STEP_INDEX[step.kind]} />
|
|
81
|
+
{step.kind === 'notes' && (
|
|
82
|
+
<NotesStep
|
|
83
|
+
text={text}
|
|
84
|
+
onChange={setText}
|
|
85
|
+
pending={identify.isPending}
|
|
86
|
+
error={identify.error}
|
|
87
|
+
onNext={() => {
|
|
88
|
+
void runIdentify().catch(() => undefined)
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
{step.kind === 'confirm' && (
|
|
93
|
+
<ConfirmStep
|
|
94
|
+
identified={step.identified}
|
|
95
|
+
pending={research.isPending}
|
|
96
|
+
error={research.error}
|
|
97
|
+
onBack={() => {
|
|
98
|
+
setStep({ kind: 'notes' })
|
|
99
|
+
}}
|
|
100
|
+
onNext={(candidate, existingPersonId) => {
|
|
101
|
+
void runResearch(candidate, existingPersonId).catch(() => undefined)
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
{step.kind === 'choose' && (
|
|
106
|
+
<ChooseStep
|
|
107
|
+
research={step.research}
|
|
108
|
+
pending={apply.isPending}
|
|
109
|
+
error={apply.error}
|
|
110
|
+
onBack={() => {
|
|
111
|
+
setStep({ kind: 'notes' })
|
|
112
|
+
}}
|
|
113
|
+
onNext={(items) => {
|
|
114
|
+
void runApply(items).catch(() => undefined)
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
{step.kind === 'done' && <DoneStep results={step.results} onClose={onClose} />}
|
|
119
|
+
</>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function StepBar({ current }: { readonly current: number }): React.JSX.Element {
|
|
124
|
+
return (
|
|
125
|
+
<ol className="flex gap-4 border-b border-border px-4 py-2 text-[11px]">
|
|
126
|
+
{STEP_LABELS.map((label, index) => (
|
|
127
|
+
<li
|
|
128
|
+
key={label}
|
|
129
|
+
aria-current={index === current ? 'step' : undefined}
|
|
130
|
+
className={index === current ? 'font-semibold text-ink' : index < current ? 'text-ink-muted' : 'text-ink-faint'}
|
|
131
|
+
>
|
|
132
|
+
{String(index + 1)}. {label}
|
|
133
|
+
</li>
|
|
134
|
+
))}
|
|
135
|
+
</ol>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function NotesStep({
|
|
140
|
+
text,
|
|
141
|
+
onChange,
|
|
142
|
+
pending,
|
|
143
|
+
error,
|
|
144
|
+
onNext,
|
|
145
|
+
}: {
|
|
146
|
+
readonly text: string
|
|
147
|
+
readonly onChange: (value: string) => void
|
|
148
|
+
readonly pending: boolean
|
|
149
|
+
readonly error: Error | null
|
|
150
|
+
readonly onNext: () => void
|
|
151
|
+
}): React.JSX.Element {
|
|
152
|
+
const serviceLabel = useAiServiceLabel()
|
|
153
|
+
return (
|
|
154
|
+
<IntakeFrame
|
|
155
|
+
footer={
|
|
156
|
+
<button type="button" className={primaryButton} disabled={pending || text.trim().length === 0} onClick={onNext}>
|
|
157
|
+
{pending ? 'Looking them up…' : 'Find this person'}
|
|
158
|
+
</button>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
<NotesField value={text} onChange={onChange} disabled={pending} />
|
|
162
|
+
{pending && (
|
|
163
|
+
<p className="mt-2 text-[12px] text-ink-muted">
|
|
164
|
+
{serviceLabel} is looking this person up. With web search on, this can take a minute.
|
|
165
|
+
</p>
|
|
166
|
+
)}
|
|
167
|
+
{error !== null && (
|
|
168
|
+
<div className="mt-3">
|
|
169
|
+
<ErrorPanel error={error} />
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
</IntakeFrame>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const CONFIDENCE_TONES: Readonly<Record<PersonIntakeCandidate['confidence'], ChipTone>> = {
|
|
177
|
+
high: 'success',
|
|
178
|
+
medium: 'warning',
|
|
179
|
+
low: 'neutral',
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** `'new'`, or the id of the existing Person to add to. */
|
|
183
|
+
type Target = string
|
|
184
|
+
|
|
185
|
+
function ConfirmStep({
|
|
186
|
+
identified,
|
|
187
|
+
pending,
|
|
188
|
+
error,
|
|
189
|
+
onBack,
|
|
190
|
+
onNext,
|
|
191
|
+
}: {
|
|
192
|
+
readonly identified: PersonIntakeIdentifyResult
|
|
193
|
+
readonly pending: boolean
|
|
194
|
+
readonly error: Error | null
|
|
195
|
+
readonly onBack: () => void
|
|
196
|
+
readonly onNext: (candidate: PersonIntakeCandidate, existingPersonId: string | null) => void
|
|
197
|
+
}): React.JSX.Element {
|
|
198
|
+
const serviceLabel = useAiServiceLabel()
|
|
199
|
+
const first = identified.candidates[0]
|
|
200
|
+
const [candidateKey, setCandidateKey] = useState(first?.key ?? '')
|
|
201
|
+
const [target, setTarget] = useState<Target>(first?.existingPeople[0]?.id ?? 'new')
|
|
202
|
+
const candidate = identified.candidates.find((entry) => entry.key === candidateKey)
|
|
203
|
+
|
|
204
|
+
if (identified.candidates.length === 0) {
|
|
205
|
+
return (
|
|
206
|
+
<IntakeFrame
|
|
207
|
+
footer={
|
|
208
|
+
<button type="button" className={primaryButton} onClick={onBack}>
|
|
209
|
+
Add more detail
|
|
210
|
+
</button>
|
|
211
|
+
}
|
|
212
|
+
>
|
|
213
|
+
<p className="text-[13px] font-medium text-ink">{serviceLabel} could not tell who this is.</p>
|
|
214
|
+
{identified.question !== null && <p className="mt-1 text-[13px] text-ink-muted">{identified.question}</p>}
|
|
215
|
+
</IntakeFrame>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<IntakeFrame
|
|
221
|
+
footer={
|
|
222
|
+
<>
|
|
223
|
+
<button type="button" className={secondaryButton} disabled={pending} onClick={onBack}>
|
|
224
|
+
Back
|
|
225
|
+
</button>
|
|
226
|
+
<button
|
|
227
|
+
type="button"
|
|
228
|
+
className={primaryButton}
|
|
229
|
+
disabled={pending || candidate === undefined}
|
|
230
|
+
onClick={() => {
|
|
231
|
+
if (candidate !== undefined) onNext(candidate, target === 'new' ? null : target)
|
|
232
|
+
}}
|
|
233
|
+
>
|
|
234
|
+
{pending ? 'Researching…' : 'This is them: research'}
|
|
235
|
+
</button>
|
|
236
|
+
</>
|
|
237
|
+
}
|
|
238
|
+
>
|
|
239
|
+
<fieldset disabled={pending}>
|
|
240
|
+
<legend className="mb-2 text-[12px] font-medium text-ink-muted">
|
|
241
|
+
{identified.candidates.length === 1 ? 'Is this the right person?' : 'Which of these is the right person?'}
|
|
242
|
+
</legend>
|
|
243
|
+
<div className="space-y-2">
|
|
244
|
+
{identified.candidates.map((entry) => (
|
|
245
|
+
<label
|
|
246
|
+
key={entry.key}
|
|
247
|
+
className={[
|
|
248
|
+
'block cursor-pointer rounded-md border px-3 py-2',
|
|
249
|
+
entry.key === candidateKey ? 'border-accent bg-accent-soft/40' : 'border-border hover:border-border-strong',
|
|
250
|
+
].join(' ')}
|
|
251
|
+
>
|
|
252
|
+
<span className="flex items-start gap-2">
|
|
253
|
+
<input
|
|
254
|
+
type="radio"
|
|
255
|
+
name="candidate"
|
|
256
|
+
className="mt-1"
|
|
257
|
+
checked={entry.key === candidateKey}
|
|
258
|
+
onChange={() => {
|
|
259
|
+
setCandidateKey(entry.key)
|
|
260
|
+
setTarget(entry.existingPeople[0]?.id ?? 'new')
|
|
261
|
+
}}
|
|
262
|
+
/>
|
|
263
|
+
<span className="min-w-0 flex-1">
|
|
264
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
265
|
+
<span className="text-[13px] font-semibold text-ink">{entry.name}</span>
|
|
266
|
+
<Chip tone={CONFIDENCE_TONES[entry.confidence]}>{entry.confidence} confidence</Chip>
|
|
267
|
+
</span>
|
|
268
|
+
{entry.headline !== '' && <span className="block text-[12px] text-ink">{entry.headline}</span>}
|
|
269
|
+
<span className="block text-[12px] text-ink-muted">
|
|
270
|
+
{[entry.location, entry.email].filter((part) => part !== null && part !== '').join(' · ')}
|
|
271
|
+
</span>
|
|
272
|
+
{entry.profileUrls.length > 0 && (
|
|
273
|
+
<span className="mt-0.5 flex flex-wrap gap-x-3 text-[12px]">
|
|
274
|
+
{entry.profileUrls.map((url) => (
|
|
275
|
+
<a key={url} href={url} target="_blank" rel="noreferrer noopener" className="text-accent hover:underline">
|
|
276
|
+
{hostOf(url)}
|
|
277
|
+
</a>
|
|
278
|
+
))}
|
|
279
|
+
</span>
|
|
280
|
+
)}
|
|
281
|
+
{entry.evidence !== '' && <span className="mt-1 block text-[12px] text-ink-muted">{entry.evidence}</span>}
|
|
282
|
+
</span>
|
|
283
|
+
</span>
|
|
284
|
+
</label>
|
|
285
|
+
))}
|
|
286
|
+
</div>
|
|
287
|
+
|
|
288
|
+
{candidate !== undefined && candidate.existingPeople.length > 0 && (
|
|
289
|
+
<div className="mt-4 rounded-md border border-warning/40 bg-warning-soft px-3 py-2">
|
|
290
|
+
<p className="text-[12px] font-medium text-ink">This may already be in Kelpie.</p>
|
|
291
|
+
<div className="mt-1 space-y-1">
|
|
292
|
+
{candidate.existingPeople.map((person) => (
|
|
293
|
+
<label key={person.id} className="flex items-center gap-2 text-[12px] text-ink">
|
|
294
|
+
<input
|
|
295
|
+
type="radio"
|
|
296
|
+
name="target"
|
|
297
|
+
checked={target === person.id}
|
|
298
|
+
onChange={() => {
|
|
299
|
+
setTarget(person.id)
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
Update{' '}
|
|
303
|
+
<Link to={`/people/${person.id}`} target="_blank" className="font-medium text-accent hover:underline">
|
|
304
|
+
{person.name}
|
|
305
|
+
</Link>
|
|
306
|
+
{person.email !== null && <span className="text-ink-muted">{person.email}</span>}
|
|
307
|
+
</label>
|
|
308
|
+
))}
|
|
309
|
+
<label className="flex items-center gap-2 text-[12px] text-ink">
|
|
310
|
+
<input
|
|
311
|
+
type="radio"
|
|
312
|
+
name="target"
|
|
313
|
+
checked={target === 'new'}
|
|
314
|
+
onChange={() => {
|
|
315
|
+
setTarget('new')
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
Create a new person
|
|
319
|
+
</label>
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
)}
|
|
323
|
+
</fieldset>
|
|
324
|
+
{pending && (
|
|
325
|
+
<p className="mt-3 text-[12px] text-ink-muted">
|
|
326
|
+
{serviceLabel} is researching this person. With web search on, this can take a minute.
|
|
327
|
+
</p>
|
|
328
|
+
)}
|
|
329
|
+
<Sources sources={identified.sources} />
|
|
330
|
+
{error !== null && (
|
|
331
|
+
<div className="mt-3">
|
|
332
|
+
<ErrorPanel error={error} />
|
|
333
|
+
</div>
|
|
334
|
+
)}
|
|
335
|
+
</IntakeFrame>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function ChooseStep({
|
|
340
|
+
research,
|
|
341
|
+
pending,
|
|
342
|
+
error,
|
|
343
|
+
onBack,
|
|
344
|
+
onNext,
|
|
345
|
+
}: {
|
|
346
|
+
readonly research: PersonIntakeResearchResult
|
|
347
|
+
readonly pending: boolean
|
|
348
|
+
readonly error: Error | null
|
|
349
|
+
readonly onBack: () => void
|
|
350
|
+
readonly onNext: (items: readonly PersonIntakeItem[]) => void
|
|
351
|
+
}): React.JSX.Element {
|
|
352
|
+
const [ticked, setTicked] = useState<ReadonlySet<string>>(
|
|
353
|
+
() => new Set(research.items.filter((item) => !OFF_BY_DEFAULT.has(item.kind)).map((item) => item.key)),
|
|
354
|
+
)
|
|
355
|
+
const effective = effectiveSelection(research.items, ticked)
|
|
356
|
+
const chosen = research.items.filter((item) => effective.has(item.key))
|
|
357
|
+
const companyNames = new Map(
|
|
358
|
+
research.items.flatMap((item) => (item.kind === 'company' ? [[item.key, item.fields.name] as const] : [])),
|
|
359
|
+
)
|
|
360
|
+
const ordered = [...research.items].sort(
|
|
361
|
+
(left, right) => PERSON_INTAKE_KINDS.indexOf(left.kind) - PERSON_INTAKE_KINDS.indexOf(right.kind),
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
function toggle(key: string): void {
|
|
365
|
+
setTicked((current) => {
|
|
366
|
+
const next = new Set(current)
|
|
367
|
+
if (next.has(key)) next.delete(key)
|
|
368
|
+
else next.add(key)
|
|
369
|
+
return next
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<IntakeFrame
|
|
375
|
+
footer={
|
|
376
|
+
<>
|
|
377
|
+
<button type="button" className={secondaryButton} disabled={pending} onClick={onBack}>
|
|
378
|
+
Start again
|
|
379
|
+
</button>
|
|
380
|
+
<button
|
|
381
|
+
type="button"
|
|
382
|
+
className={primaryButton}
|
|
383
|
+
disabled={pending || chosen.length === 0}
|
|
384
|
+
onClick={() => {
|
|
385
|
+
onNext(chosen)
|
|
386
|
+
}}
|
|
387
|
+
>
|
|
388
|
+
{pending ? 'Creating…' : `Create ${String(chosen.length)} ${chosen.length === 1 ? 'item' : 'items'}`}
|
|
389
|
+
</button>
|
|
390
|
+
</>
|
|
391
|
+
}
|
|
392
|
+
>
|
|
393
|
+
{research.summary !== '' && <p className="mb-3 text-[13px] text-ink">{research.summary}</p>}
|
|
394
|
+
<p className="mb-2 text-[12px] font-medium text-ink-muted">Kelpie will create what you tick.</p>
|
|
395
|
+
<ul className="space-y-1.5">
|
|
396
|
+
{ordered.map((item) => {
|
|
397
|
+
const blocked = ticked.has(item.key) && !effective.has(item.key)
|
|
398
|
+
const missing = personIntakeDependencies(item).filter((key) => !effective.has(key))
|
|
399
|
+
|
|
400
|
+
return (
|
|
401
|
+
<li key={item.key}>
|
|
402
|
+
<label
|
|
403
|
+
className={[
|
|
404
|
+
'flex cursor-pointer items-start gap-2 rounded-md border px-3 py-2',
|
|
405
|
+
effective.has(item.key) ? 'border-border-strong' : 'border-border',
|
|
406
|
+
missing.length > 0 ? 'opacity-60' : '',
|
|
407
|
+
].join(' ')}
|
|
408
|
+
>
|
|
409
|
+
<input
|
|
410
|
+
type="checkbox"
|
|
411
|
+
className="mt-0.5"
|
|
412
|
+
checked={effective.has(item.key)}
|
|
413
|
+
disabled={pending || missing.length > 0}
|
|
414
|
+
onChange={() => {
|
|
415
|
+
toggle(item.key)
|
|
416
|
+
}}
|
|
417
|
+
/>
|
|
418
|
+
<span className="min-w-0 flex-1">
|
|
419
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
420
|
+
<Chip tone={item.kind === 'person' ? 'accent' : 'neutral'}>{PERSON_INTAKE_KIND_LABELS[item.kind]}</Chip>
|
|
421
|
+
<span className="text-[13px] font-medium text-ink">{itemTitle(item, companyNames)}</span>
|
|
422
|
+
{actionNote(item) !== null && <span className="text-[11px] text-ink-muted">{actionNote(item)}</span>}
|
|
423
|
+
</span>
|
|
424
|
+
<ItemDetail item={item} />
|
|
425
|
+
{(missing.length > 0 || blocked) && (
|
|
426
|
+
<span className="mt-0.5 block text-[11px] text-ink-muted">
|
|
427
|
+
Needs the {missing.map((key) => describeKey(key, research.items)).join(' and ')} ticked.
|
|
428
|
+
</span>
|
|
429
|
+
)}
|
|
430
|
+
</span>
|
|
431
|
+
</label>
|
|
432
|
+
</li>
|
|
433
|
+
)
|
|
434
|
+
})}
|
|
435
|
+
</ul>
|
|
436
|
+
<Sources sources={research.sources} />
|
|
437
|
+
{error !== null && (
|
|
438
|
+
<div className="mt-3">
|
|
439
|
+
<ErrorPanel error={error} />
|
|
440
|
+
</div>
|
|
441
|
+
)}
|
|
442
|
+
</IntakeFrame>
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function describeKey(key: string, items: readonly PersonIntakeItem[]): string {
|
|
447
|
+
const item = items.find((entry) => entry.key === key)
|
|
448
|
+
|
|
449
|
+
if (item === undefined) return key === PERSON_INTAKE_PERSON_KEY ? 'person' : 'company'
|
|
450
|
+
|
|
451
|
+
return item.kind === 'company' || item.kind === 'person' ? `${item.kind} ${item.fields.name}` : item.kind
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function itemTitle(item: PersonIntakeItem, companyNames: ReadonlyMap<string, string>): string {
|
|
455
|
+
switch (item.kind) {
|
|
456
|
+
case 'person':
|
|
457
|
+
case 'company':
|
|
458
|
+
case 'partnership':
|
|
459
|
+
case 'deal':
|
|
460
|
+
case 'enquiry':
|
|
461
|
+
return item.fields.name
|
|
462
|
+
case 'position': {
|
|
463
|
+
const company = companyNames.get(item.companyKey) ?? 'the company'
|
|
464
|
+
return item.title === '' ? `At ${company}` : `${item.title} at ${company}`
|
|
465
|
+
}
|
|
466
|
+
case 'note':
|
|
467
|
+
return 'Pinned research note'
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function actionNote(item: PersonIntakeItem): string | null {
|
|
472
|
+
if (item.kind === 'person' && item.action === 'update') return 'Adds to the existing record'
|
|
473
|
+
if (item.kind === 'company' && item.action === 'existing') return 'Already in Kelpie; links to it'
|
|
474
|
+
return null
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function ItemDetail({ item }: { readonly item: PersonIntakeItem }): React.JSX.Element | null {
|
|
478
|
+
const muted = 'mt-0.5 block text-[12px] text-ink-muted'
|
|
479
|
+
|
|
480
|
+
switch (item.kind) {
|
|
481
|
+
case 'person': {
|
|
482
|
+
const fields = item.fields
|
|
483
|
+
const facts = [
|
|
484
|
+
fields.email ?? null,
|
|
485
|
+
fields.phones !== undefined && fields.phones.length > 0 ? fields.phones.join(', ') : null,
|
|
486
|
+
fields.socialProfiles !== undefined && fields.socialProfiles.length > 0
|
|
487
|
+
? fields.socialProfiles.map((profile) => profile.network).join(', ')
|
|
488
|
+
: null,
|
|
489
|
+
fields.tags !== undefined && fields.tags.length > 0 ? `Tags: ${fields.tags.join(', ')}` : null,
|
|
490
|
+
].filter((fact): fact is string => fact !== null && fact !== '')
|
|
491
|
+
|
|
492
|
+
return (
|
|
493
|
+
<>
|
|
494
|
+
{facts.length > 0 && <span className={muted}>{facts.join(' · ')}</span>}
|
|
495
|
+
{fields.summary !== undefined && fields.summary !== '' && <span className={muted}>{fields.summary}</span>}
|
|
496
|
+
</>
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
case 'company': {
|
|
500
|
+
if (item.action === 'existing') return null
|
|
501
|
+
const fields = item.fields
|
|
502
|
+
const facts = [fields.domain ?? null, fields.industry ?? null, fields.sizeBand ?? null].filter(
|
|
503
|
+
(fact): fact is string => fact !== null && fact !== '',
|
|
504
|
+
)
|
|
505
|
+
return (
|
|
506
|
+
<>
|
|
507
|
+
{facts.length > 0 && <span className={muted}>{facts.join(' · ')}</span>}
|
|
508
|
+
{fields.description !== undefined && fields.description !== '' && (
|
|
509
|
+
<span className={muted}>{fields.description}</span>
|
|
510
|
+
)}
|
|
511
|
+
</>
|
|
512
|
+
)
|
|
513
|
+
}
|
|
514
|
+
case 'position':
|
|
515
|
+
return null
|
|
516
|
+
case 'note':
|
|
517
|
+
return <span className={`${muted} line-clamp-4 whitespace-pre-wrap`}>{item.body}</span>
|
|
518
|
+
case 'partnership':
|
|
519
|
+
case 'deal':
|
|
520
|
+
case 'enquiry':
|
|
521
|
+
return item.reason === '' ? null : <span className={`${muted} italic`}>Why: {item.reason}</span>
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function Sources({ sources }: { readonly sources: readonly PersonIntakeSource[] }): React.JSX.Element | null {
|
|
526
|
+
if (sources.length === 0) return null
|
|
527
|
+
|
|
528
|
+
return (
|
|
529
|
+
<div className="mt-4">
|
|
530
|
+
<p className="text-[11px] font-medium uppercase tracking-wide text-ink-faint">Sources</p>
|
|
531
|
+
<ul className="mt-1 space-y-0.5">
|
|
532
|
+
{sources.map((source) => (
|
|
533
|
+
<li key={source.url} className="truncate text-[12px]">
|
|
534
|
+
<a href={source.url} target="_blank" rel="noreferrer noopener" className="text-accent hover:underline">
|
|
535
|
+
{source.title === source.url ? hostOf(source.url) : source.title}
|
|
536
|
+
</a>{' '}
|
|
537
|
+
<span className="text-ink-faint">{hostOf(source.url)}</span>
|
|
538
|
+
</li>
|
|
539
|
+
))}
|
|
540
|
+
</ul>
|
|
541
|
+
</div>
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const STATUS_TONES: Readonly<Record<PersonIntakeResultStatus, ChipTone>> = {
|
|
546
|
+
created: 'success',
|
|
547
|
+
updated: 'success',
|
|
548
|
+
linked: 'neutral',
|
|
549
|
+
skipped: 'warning',
|
|
550
|
+
failed: 'danger',
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** Where a written item lives. Positions and notes show on their Person. */
|
|
554
|
+
function pathFor(result: PersonIntakeResult, personId: string | null): string | null {
|
|
555
|
+
if (result.id === null) return null
|
|
556
|
+
|
|
557
|
+
switch (result.kind) {
|
|
558
|
+
case 'person':
|
|
559
|
+
return `/people/${result.id}`
|
|
560
|
+
case 'company':
|
|
561
|
+
return `/companies/${result.id}`
|
|
562
|
+
case 'position':
|
|
563
|
+
case 'note':
|
|
564
|
+
return personId === null ? null : `/people/${personId}`
|
|
565
|
+
case 'partnership':
|
|
566
|
+
return `/partnerships/${result.id}`
|
|
567
|
+
case 'deal':
|
|
568
|
+
return `/deals/${result.id}`
|
|
569
|
+
case 'enquiry':
|
|
570
|
+
return `/enquiries/${result.id}`
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function DoneStep({
|
|
575
|
+
results,
|
|
576
|
+
onClose,
|
|
577
|
+
}: {
|
|
578
|
+
readonly results: readonly PersonIntakeResult[]
|
|
579
|
+
readonly onClose: () => void
|
|
580
|
+
}): React.JSX.Element {
|
|
581
|
+
const person = results.find((result) => result.kind === 'person' && result.id !== null)
|
|
582
|
+
const personId = person?.id ?? null
|
|
583
|
+
const problems = results.filter((result) => result.status === 'failed' || result.status === 'skipped').length
|
|
584
|
+
|
|
585
|
+
return (
|
|
586
|
+
<IntakeFrame
|
|
587
|
+
footer={
|
|
588
|
+
<>
|
|
589
|
+
<button type="button" className={secondaryButton} onClick={onClose}>
|
|
590
|
+
Close
|
|
591
|
+
</button>
|
|
592
|
+
{person !== undefined && personId !== null && (
|
|
593
|
+
<Link to={`/people/${personId}`} className={primaryButton}>
|
|
594
|
+
Open {person.label}
|
|
595
|
+
</Link>
|
|
596
|
+
)}
|
|
597
|
+
</>
|
|
598
|
+
}
|
|
599
|
+
>
|
|
600
|
+
<p className="mb-2 text-[13px] text-ink">
|
|
601
|
+
{problems === 0 ? 'Done. Kelpie wrote these records.' : 'Done, with problems. Check the items marked below.'}
|
|
602
|
+
</p>
|
|
603
|
+
<ul className="space-y-1.5">
|
|
604
|
+
{results.map((result) => {
|
|
605
|
+
const path = pathFor(result, personId)
|
|
606
|
+
|
|
607
|
+
return (
|
|
608
|
+
<li key={result.key} className="flex flex-wrap items-center gap-2 text-[13px]">
|
|
609
|
+
<Chip tone={STATUS_TONES[result.status]}>{result.status}</Chip>
|
|
610
|
+
<span className="text-[11px] text-ink-muted">{PERSON_INTAKE_KIND_LABELS[result.kind]}</span>
|
|
611
|
+
{path === null ? (
|
|
612
|
+
<span className="text-ink">{result.label}</span>
|
|
613
|
+
) : (
|
|
614
|
+
<Link to={path} className="font-medium text-accent hover:underline">
|
|
615
|
+
{result.label}
|
|
616
|
+
</Link>
|
|
617
|
+
)}
|
|
618
|
+
{result.detail !== null && <span className="w-full pl-1 text-[12px] text-ink-muted">{result.detail}</span>}
|
|
619
|
+
</li>
|
|
620
|
+
)
|
|
621
|
+
})}
|
|
622
|
+
</ul>
|
|
623
|
+
</IntakeFrame>
|
|
624
|
+
)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function hostOf(url: string): string {
|
|
628
|
+
try {
|
|
629
|
+
return new URL(url).hostname.replace(/^www\./u, '')
|
|
630
|
+
} catch {
|
|
631
|
+
return url
|
|
632
|
+
}
|
|
633
|
+
}
|
package/src/modules/ai.tsx
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AiRunLogTab, AiSettingsTab } from '../pages/admin/AiPage.tsx'
|
|
2
2
|
import type { UiModule } from '../registry/registry.ts'
|
|
3
3
|
import { aiRunner } from './aiRunner.ts'
|
|
4
|
+
import { PersonIntakeWizard } from './PersonIntakeWizard.tsx'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The UI half of the optional `ai` module in `@kelpie/server`.
|
|
7
8
|
*
|
|
8
9
|
* Not registered by default. An assembly that lists `createAiModule()` on the
|
|
9
10
|
* server lists `aiUi` in `kelpie.ui.config.ts`, the same pairing any module
|
|
10
|
-
* uses.
|
|
11
|
-
* Agent menu's runner: Run dispatches straight to the "Kelpie AI" agent row, and
|
|
11
|
+
* uses. Two tabs on core's Admin → AI page, Settings and Run log, before
|
|
12
|
+
* core's MCP tab. On record pages it is the Agent menu's runner: Run dispatches straight to the "Kelpie AI" agent row, and
|
|
12
13
|
* stays disabled until AI is enabled and has a key. Preview's Run… still lists
|
|
13
|
-
* every registered agent, Kelpie AI included.
|
|
14
|
+
* every registered agent, Kelpie AI included. On People it is the wizard behind
|
|
15
|
+
* Add from notes.
|
|
14
16
|
*/
|
|
15
17
|
export const aiUi: UiModule = {
|
|
16
18
|
id: 'ai',
|
|
17
19
|
|
|
18
20
|
register(context) {
|
|
19
|
-
context.
|
|
20
|
-
context.
|
|
21
|
+
context.adminTab('ai', { id: 'settings', label: 'Settings', order: 100, render: () => <AiSettingsTab /> })
|
|
22
|
+
context.adminTab('ai', { id: 'runs', label: 'Run log', order: 200, render: () => <AiRunLogTab /> })
|
|
21
23
|
context.agentRunner(aiRunner)
|
|
24
|
+
// Ready on exactly the terms Run is: enabled, keyed, and its agent row in place.
|
|
25
|
+
context.personIntake({ id: 'ai', useAvailability: aiRunner.useAvailability, Wizard: PersonIntakeWizard })
|
|
22
26
|
},
|
|
23
27
|
}
|