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