diff --git a/src/components/assistants/AssistantConfigView.tsx b/src/components/assistants/AssistantConfigView.tsx new file mode 100644 index 0000000..357452c --- /dev/null +++ b/src/components/assistants/AssistantConfigView.tsx @@ -0,0 +1,188 @@ +import { ChevronDown } from 'lucide-react' +import { useDraftAssistant } from '../../context/DraftAssistantContext' +import { useKeyboardShortcuts } from '../../hooks/useKeyboardShortcut' +import { SHORTCUTS } from '../../constants/keyboard-shortcuts' + +const inputClassName = "w-full h-6 text-[11px] px-1.5 rounded-md border border-input bg-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring" +const inputStyle = { boxShadow: 'inset 0 1px 2px 0 rgb(0 0 0 / 0.05)' } + +export function AssistantConfigView() { + const { + draftAssistant, + isEditing, + isSubmitting, + validationErrors, + updateDraft, + cancelDraft, + saveDraft, + } = useDraftAssistant() + + const handleSave = () => { + if (draftAssistant) saveDraft() + } + + // Keyboard shortcuts + useKeyboardShortcuts([ + { shortcut: SHORTCUTS.SAVE, handler: handleSave, options: { skipInputs: false } }, + { shortcut: SHORTCUTS.SAVE_ENTER, handler: handleSave, options: { skipInputs: false } }, + { shortcut: SHORTCUTS.CANCEL, handler: cancelDraft }, + ]) + + if (!draftAssistant) return null + + const isNameValid = !validationErrors.name + const canSubmit = isEditing + ? !isSubmitting && isNameValid + : !isSubmitting && isNameValid && draftAssistant.name.trim().length > 0 + + return ( +
+ {/* Header */} +
+

+ {isEditing ? 'Edit Assistant' : 'Create Assistant'} +

+

+ {isEditing + ? 'Update assistant configuration' + : 'Configure a new Pinecone Assistant'} +

+
+ + {/* Configuration Form */} +
+ {/* Form error */} + {validationErrors._form && ( +
+

{validationErrors._form}

+
+ )} + + {/* Assistant Name */} +
+ + updateDraft({ name: e.target.value.toLowerCase() })} + placeholder="my-assistant" + className={inputClassName} + style={inputStyle} + autoFocus={!isEditing} + disabled={isEditing} + /> + {validationErrors.name && ( +

{validationErrors.name}

+ )} + {!isEditing && ( +

+ 1-63 characters, lowercase letters, numbers, and hyphens only +

+ )} +
+ + {/* Instructions */} +
+ +