File size: 4,312 Bytes
7df213d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, { useState } from 'react';
import axios from 'axios';

const TextRequest = () => {
    const [input, setInput] = useState('');
    const [response, setResponse] = useState(null);
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(null);

    const handleSubmit = async () => {
        setLoading(true);
        setError(null);
        try {
            const result = await axios.post('http://localhost:8000/execute', {
                task: {
                    type: "text_task",
                    input: input,
                    auto_team: true  // Let the system select appropriate agents
                }
            });

            setResponse(result.data);
            setInput('');  // Clear input after successful submission
        } catch (err) {
            setError(err.response?.data?.error || 'Error processing request');
            console.error('Request error:', err);
        }
        setLoading(false);
    };

    return (
        <div className="text-request-container">
            <div className="input-section">
                <textarea
                    value={input}
                    onChange={(e) => setInput(e.target.value)}
                    placeholder="Enter your request (e.g., 'Search for Disney hotels and email me the results')"
                    rows={4}
                    className="text-input"
                />
                <button 
                    onClick={handleSubmit} 
                    disabled={loading || !input.trim()}
                    className="submit-button"
                >
                    {loading ? 'Processing...' : 'Submit'}
                </button>
            </div>

            {error && (
                <div className="error-message">
                    {error}
                </div>
            )}

            {response && (
                <div className="response-section">
                    <h3>Response:</h3>
                    <pre className="response-content">
                        {response.formatted_output || JSON.stringify(response, null, 2)}
                    </pre>
                    {response.team && (
                        <div className="team-info">
                            <p>Team: {response.team.join(', ')}</p>
                            {response.leader && <p>Leader: {response.leader}</p>}
                        </div>
                    )}
                </div>
            )}

            <style jsx>{`
                .text-request-container {
                    padding: 20px;
                    max-width: 800px;
                    margin: 0 auto;
                }
                .input-section {
                    margin-bottom: 20px;
                }
                .text-input {
                    width: 100%;
                    padding: 10px;
                    margin-bottom: 10px;
                    border: 1px solid #ccc;
                    border-radius: 4px;
                }
                .submit-button {
                    padding: 10px 20px;
                    background-color: #007bff;
                    color: white;
                    border: none;
                    border-radius: 4px;
                    cursor: pointer;
                }
                .submit-button:disabled {
                    background-color: #ccc;
                }
                .error-message {
                    color: red;
                    margin: 10px 0;
                    padding: 10px;
                    border: 1px solid red;
                    border-radius: 4px;
                }
                .response-section {
                    margin-top: 20px;
                    padding: 15px;
                    border: 1px solid #ddd;
                    border-radius: 4px;
                }
                .response-content {
                    white-space: pre-wrap;
                    background-color: #f5f5f5;
                    padding: 10px;
                    border-radius: 4px;
                }
                .team-info {
                    margin-top: 10px;
                    padding-top: 10px;
                    border-top: 1px solid #ddd;
                }
            `}</style>
        </div>
    );
};

export default TextRequest;