MCPcopy Create free account
hub / github.com/Roy3838/Observer / handleFileSelect

Function handleFileSelect

app/src/components/CommunityTab.tsx:636–718  ·  view source on GitHub ↗
(event: React.ChangeEvent<HTMLInputElement>)

Source from the content-addressed store, hash-verified

634 };
635
636 const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
637 const files = event.target.files;
638 if (!files || files.length === 0) return;
639
640 try {
641 setIsUploading(true);
642 setError(null);
643
644 if (!isAuthenticated) {
645 throw new Error('You must be logged in to upload agents');
646 }
647
648 const file = files[0];
649 const fileContent = await file.text();
650 let agentData: Partial<AgentUpload>;
651
652 // Try to parse as JSON first
653 try {
654 agentData = JSON.parse(fileContent);
655 } catch (jsonError) {
656 // If JSON fails, try YAML
657 try {
658 const { load } = await import('js-yaml');
659 agentData = load(fileContent) as Partial<AgentUpload>;
660 } catch (yamlError) {
661 throw new Error('Invalid file format. Must be JSON or YAML.');
662 }
663 }
664
665 // Validate the required fields
666 if (!agentData.id || !agentData.name || !agentData.code) {
667 throw new Error('Invalid agent file. Missing required fields (id, name, code).');
668 }
669
670 // Create CompleteAgent for checking
671 const agent: CompleteAgent = {
672 id: agentData.id,
673 name: agentData.name,
674 description: agentData.description || '',
675 model_name: agentData.model_name || 'unknown',
676 system_prompt: agentData.system_prompt || '',
677 loop_interval_seconds: agentData.loop_interval_seconds || 10
678 };
679
680 const code = agentData.code;
681 const memory = agentData.memory || '';
682
683 // Check for sensitive data before uploading
684 const hasSensitiveData = checkForSensitiveData(code, agent, memory, 'file');
685 if (hasSensitiveData) {
686 setIsUploading(false);
687 return; // Stop here, warning modal will handle next steps
688 }
689
690 // Create a proper AgentUpload object with author info
691 const fullAgentData: AgentUpload = {
692 id: agent.id,
693 name: agent.name,

Callers

nothing calls this directly

Calls 4

checkForSensitiveDataFunction · 0.85
uploadAgentToServerFunction · 0.85
textMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected