Files
CatoandClaude Opus 5.5 9dde8fbee9 feat(forms): prose fields on chatkit DictationField, with a working microphone (#330)
* wip: prose fields on chatkit DictationField (awaits chatkit 0.45)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuMRAXYWNkfowAXVfi

* feat(forms): prose fields on chatkit DictationField, with a working microphone

- Bump @bitbaum/chatkit to ^0.45.0.
- One app wrapper, components/forms/TextBox, around DictationField. Used by
  the bot builder (name, description, knowledge topic and content, system
  prompt), the custom-bot edit page (name, description, system prompt,
  greeting), the contact message, the demo intake questions, quick-create
  (name, relationship, memories) and the consultation form's
  react-hook-form message field ({...register('message')}).
- app/api/transcribe: dictation server leg on ai-kit's speechChain and
  transcribe(), rate limited, recordings and transcripts neither stored nor
  logged. Every field and every in-page chat points voice at it, so the
  microphone works where the browser has no recogniser of its own.
- Permissions-Policy allowed no microphone at all (microphone=()), which
  blocked every mic on the site; it now allows the site itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuMRAXYWNkfowAXVfi

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-19 14:23:42 +01:00

207 lines
6.7 KiB
TypeScript

'use client';
import { type FC, useState } from 'react';
import { type BotTemplate } from '@/lib/bot-templates';
import { TextBox } from '@/components/forms/TextBox';
interface NameStepProps {
template: BotTemplate;
onSubmit: (name: string, additionalContext?: string) => void;
onBack: () => void;
}
export const NameStep: FC<NameStepProps> = ({ template, onSubmit, onBack }) => {
const [name, setName] = useState('');
const [showOptional, setShowOptional] = useState(false);
const [additionalContext, setAdditionalContext] = useState('');
const [relationship, setRelationship] = useState('');
const needsRelationship = template.requiredFields.includes('relationship');
const canSubmit =
name.trim().length > 0 && (!needsRelationship || relationship.trim().length > 0);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!canSubmit) return;
let context = additionalContext;
if (relationship) {
context = `Relationship: ${relationship}. ${context}`.trim();
}
onSubmit(name.trim(), context.trim() || undefined);
};
const getPlaceholder = () => {
if (template.category === 'memorial') {
if (
template.id.includes('dog') ||
template.id.includes('cat') ||
template.id.includes('pet')
) {
return 'What was their name?';
}
return 'What should I call them?';
}
if (template.category === 'helpers') {
return 'Give them a name (e.g., Alfred, Jeeves)';
}
return template.name;
};
const getContextPlaceholder = () => {
if (template.category === 'memorial') {
return 'Share a memory, their personality, things they used to say, or anything that made them special...';
}
return 'Add any specific traits, knowledge, or context you want them to have...';
};
return (
<div className="max-w-2xl mx-auto">
{/* Selected Template Display */}
<div className="text-center mb-8">
<div className="inline-flex items-center gap-4 bg-white rounded-2xl px-6 py-4 shadow-lg border border-gray-100 mb-6">
<span className="text-5xl">{template.emoji}</span>
<div className="text-left">
<div className="text-sm text-gray-500">Creating a</div>
<div className="text-xl font-semibold text-gray-900">{template.name}</div>
</div>
</div>
<h1 className="text-3xl font-bold text-gray-900 mb-2">
{template.category === 'memorial' ? 'Who are you remembering?' : 'Give them a name'}
</h1>
<p className="text-gray-600">{template.description}</p>
</div>
{/* Form */}
<form onSubmit={handleSubmit} className="space-y-6">
{/* Name Input */}
<div>
<TextBox
label={
<>
Name <span className="text-red-500">*</span>
</>
}
multiline={false}
id="name"
value={name}
onValueChange={setName}
placeholder={getPlaceholder()}
required
autoFocus
/>
</div>
{/* Relationship (if required) */}
{needsRelationship && (
<div>
<TextBox
label={
<>
Relationship <span className="text-red-500">*</span>
</>
}
multiline={false}
id="relationship"
value={relationship}
onValueChange={setRelationship}
placeholder="e.g., my brother, my best friend, my mentor"
required
/>
</div>
)}
{/* Optional Context Toggle */}
<div>
<button
type="button"
onClick={() => setShowOptional(!showOptional)}
className="text-purple-600 hover:text-purple-700 text-sm font-medium flex items-center gap-2"
>
<svg
className={`w-4 h-4 transition-transform ${showOptional ? 'rotate-90' : ''}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
{showOptional ? 'Hide' : 'Add'} memories or details (optional)
</button>
{showOptional && (
<div className="mt-4">
<TextBox
label="Memories or details"
value={additionalContext}
onValueChange={setAdditionalContext}
placeholder={getContextPlaceholder()}
rows={4}
hint="The more details you add, the more personalized the experience."
/>
</div>
)}
</div>
{/* Actions */}
<div className="flex items-center justify-between pt-4">
<button
type="button"
onClick={onBack}
className="text-gray-500 hover:text-gray-700 font-medium flex items-center gap-2"
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M15 19l-7-7 7-7"
/>
</svg>
Choose Different
</button>
<button
type="submit"
disabled={!canSubmit}
className={`inline-flex items-center gap-2 px-8 py-3 rounded-xl font-semibold transition-all ${
canSubmit
? 'bg-gradient-to-r from-purple-600 to-pink-600 text-white hover:shadow-lg hover:scale-105'
: 'bg-gray-200 text-gray-400 cursor-not-allowed'
}`}
>
<span>Create & Chat</span>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M13 7l5 5m0 0l-5 5m5-5H6"
/>
</svg>
</button>
</div>
</form>
{/* Starter Questions Preview */}
<div className="mt-12 pt-8 border-t border-gray-200">
<h3 className="text-sm font-medium text-gray-500 mb-4">
Example conversations you can have:
</h3>
<div className="flex flex-wrap gap-2">
{template.starterQuestions.map((question, index) => (
<span
key={index}
className="inline-block bg-gray-100 text-gray-600 px-4 py-2 rounded-full text-sm"
>
"{question}"
</span>
))}
</div>
</div>
</div>
);
};