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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
import {
  Article as ArticleIcon,
  Assessment as AssessmentIcon,
  Book as BookIcon,
  Download as DownloadIcon,
  Hub as HubIcon,
  EmojiEvents as LeaderboardIcon,
  RestartAlt as RestartIcon,
  RocketLaunch as RocketLaunchIcon,
} from "@mui/icons-material";
import {
  alpha,
  Box,
  Button,
  Chip,
  CircularProgress,
  IconButton,
  Link,
  Paper,
  Stack,
  Tooltip,
  Typography,
} from "@mui/material";
import React, { useCallback, useState } from "react";
import { FormData, UserInfo } from "../types";
import { DevModeLoginButton } from "./DevModeLoginButton";
import { HuggingFaceLoginButton } from "./HuggingFaceLoginButton";
import { ModelProviderSelector } from "./ModelProviderSelector";
import { TooltipIcon } from "./TooltipIcon";
import { McpConfigurationWarningDialog } from "./dialogs";

const TRANSITION = "all 0.3s ease-in-out";

interface InitialFormProps {
  formData: FormData;
  userInfo: UserInfo | null;
  accessToken: string | null;
  loginLabel: string;
  isStarting: boolean;
  defaultMcpFile: File | null;
  onFormChange: (formData: FormData) => void;
  onSubmit: () => void;
  onLoginStateChange: (
    userInfo: UserInfo | null,
    accessToken: string | null,
    loginLabel: string,
  ) => void;
}

export const InitialForm: React.FC<InitialFormProps> = ({
  formData,
  userInfo,
  accessToken,
  loginLabel,
  isStarting,
  defaultMcpFile,
  onFormChange,
  onSubmit,
  onLoginStateChange,
}) => {
  const [dialogOpen, setDialogOpen] = useState(false);
  const [pendingFile, setPendingFile] = useState<File | null>(null);
  const [selectedOption, setSelectedOption] = useState<"suggested" | "custom">(
    "suggested",
  );
  const [selectedSuggestion, setSelectedSuggestion] = useState("0");
  const [customProvider, setCustomProvider] = useState("");
  const [customModel, setCustomModel] = useState("");

  // Define the suggested models
  const suggestedModels = [
    {
      provider: "novita",
      model: "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
      label: "Llama-4-Maverick-17B-128E-Instruct-FP8",
    },
    {
      provider: "novita",
      model: "zai-org/GLM-4.5",
      label: "GLM-4.5",
    },
    {
      provider: "novita",
      model: "moonshotai/Kimi-K2-Instruct-0905",
      label: "Kimi-K2-Instruct-0905",
    },
    {
      provider: "novita",
      model: "deepseek-ai/DeepSeek-V3.1",
      label: "DeepSeek-V3.1",
    },
    {
      provider: "novita",
      model: "Qwen/Qwen3-Next-80B-A3B-Instruct",
      label: "Qwen3-Next-80B-A3B-Instruct",
    },
    {
      provider: "novita",
      model: "Qwen/Qwen3-Coder-480B-A35B-Instruct",
      label: "Qwen3-Coder-480B-A35B-Instruct",
    },
  ];

  // Initialize form with first suggested model only when form is empty on mount
  React.useEffect(() => {
    if (
      selectedOption === "suggested" &&
      suggestedModels[0] &&
      !formData.provider &&
      !formData.model
    ) {
      onFormChange({
        ...formData,
        provider: suggestedModels[0].provider,
        model: suggestedModels[0].model,
      });
    }
  }, []); // Only run once on mount

  const isFormValid = Boolean(
    formData.model.trim() && formData.provider.trim() && userInfo?.sub,
  );

  const isLoggedIn = Boolean(userInfo?.sub);

  const handleFileChange = useCallback(
    (event: React.ChangeEvent<HTMLInputElement>) => {
      const file = event.target.files?.[0] || null;
      if (file) {
        setPendingFile(file);
        setDialogOpen(true);
      } else {
        onFormChange({ ...formData, mcpFile: null });
      }
    },
    [formData, onFormChange],
  );

  const resetFile = useCallback(() => {
    setPendingFile(null);
    onFormChange({ ...formData, mcpFile: defaultMcpFile });
  }, [formData, onFormChange]);

  const handleDialogClose = useCallback(() => {
    setDialogOpen(false);
    setPendingFile(null);
    // Clear the file input element to reset the UI
    const fileInput = document.querySelector(
      'input[type="file"]',
    ) as HTMLInputElement;
    if (fileInput) {
      fileInput.value = "";
    }
  }, []);

  const handleDialogConfirm = useCallback(() => {
    if (pendingFile) {
      onFormChange({ ...formData, mcpFile: pendingFile });
    }
    setDialogOpen(false);
    setPendingFile(null);
  }, [formData, onFormChange, pendingFile]);

  return (
    <>
      <Box
        sx={{
          minHeight: "100vh",
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          bgcolor: "background.paper",
          p: 2,
          transition: TRANSITION,
        }}
      >
        <Stack
          direction={"row"}
          spacing={4}
          alignItems={"center"}
          sx={{
            transition: TRANSITION,
          }}
        >
          <Box
            sx={{
              height: "100%",
              display: "flex",
              p: 4,
              maxWidth: 600,
              width: "100%",
              flexDirection: "column",
              transition: TRANSITION,
            }}
          >
            <Typography variant="h4" component="h1" gutterBottom sx={{ mb: 3 }}>
              Meta Agents Research Environments
            </Typography>

            <Typography sx={{ mb: 2 }}>
              Welcome to the Meta ARE (Agents Research Environments) and Gaia2
              demo! ARE is a research platform to easily interact with and
              evaluate agents. In this demo, you can:
            </Typography>
            <Stack component="ul" spacing={2} sx={{ mb: 3, pl: 3 }}>
              <Typography component="li">
                Test a simulated universe with apps representing a smartphone
                agent, similar to Gaia2. Find out which agent is the best
                assistant by trying different models!
              </Typography>
              <Typography component="li">
                Visualize Gaia2 scenarios, to better understand the benchmark
                and debug your agent! Check out the{" "}
                <Link
                  href="https://facebookresearch.github.io/meta-agents-research-environments/"
                  target="_blank"
                  rel="noopener noreferrer"
                  color="info"
                  sx={{
                    fontWeight: 500,
                    textDecoration: "none",
                    "&:hover": { textDecoration: "underline" },
                  }}
                >
                  documentation
                </Link>{" "}
                to find out how to run the Gaia2 benchmark with ARE.
              </Typography>
            </Stack>

            {/* Mobile warning message - only shown on xs screens */}
            <Box
              sx={{
                display: { xs: "block", sm: "none" },
                mb: 3,
                p: 2,
                bgcolor: "info.light",
                borderRadius: 1,
                border: "1px solid",
                borderColor: "info.main",
              }}
            >
              <Typography
                variant="body2"
                color="info.dark"
                align="center"
                sx={{ fontWeight: 500 }}
              >
                📱 This demo is not optimized for mobile devices. Please use a
                desktop or tablet for the best experience.
              </Typography>
            </Box>
            {/* Informational links */}
            <Typography variant="overline" color="textSecondary" sx={{ mb: 1 }}>
              Additional links
            </Typography>
            <Stack spacing={1} direction={"row"}>
              <Chip
                icon={<BookIcon fontSize="inherit" />}
                label="Docs"
                component="a"
                href="https://facebookresearch.github.io/meta-agents-research-environments/"
                target="_blank"
                variant="outlined"
                clickable
                sx={{
                  pl: 0.5,
                }}
              />
              <Chip
                icon={<HubIcon fontSize="inherit" />}
                label="Gaia2"
                component="a"
                href="https://huggingface.co/datasets/meta-agents-research-environments/gaia2"
                target="_blank"
                variant="outlined"
                clickable
                sx={{
                  pl: 0.5,
                }}
              />
              <Chip
                icon={<AssessmentIcon fontSize="inherit" />}
                label="Paper"
                component="a"
                href="https://arxiv.org/abs/2509.17158"
                target="_blank"
                variant="outlined"
                clickable
                sx={{
                  pl: 0.5,
                }}
              />
              <Chip
                icon={<LeaderboardIcon fontSize="inherit" />}
                label="Leaderboard"
                component="a"
                href="https://huggingface.co/spaces/meta-agents-research-environments/leaderboard"
                target="_blank"
                variant="outlined"
                clickable
                sx={{
                  pl: 0.5,
                }}
              />
              <Chip
                icon={<ArticleIcon fontSize="inherit" />}
                label="Blog"
                component="a"
                href="https://huggingface.co/blog/gaia2"
                target="_blank"
                variant="outlined"
                clickable
                sx={{
                  pl: 0.5,
                }}
              />
            </Stack>
          </Box>
          <Paper
            elevation={3}
            sx={{
              p: 1,
              maxWidth: 400,
              width: "100%",
              borderRadius: 2,
              transition: TRANSITION,
            }}
          >
            <Stack
              sx={{
                height: "100%",
                transition: TRANSITION,
              }}
            >
              <Typography variant="h5" sx={{ p: 1 }}>
                Get started
              </Typography>
              {/* Login Section */}
              <Stack
                spacing={2}
                sx={{
                  p: 1.5,
                  m: 1,
                  border: "2px solid",
                  borderColor: (theme) =>
                    isLoggedIn
                      ? alpha(theme.palette.action.disabled, 0.1)
                      : "primary.main",
                  borderRadius: 1.5,
                  transition: TRANSITION,
                }}
              >
                <Typography variant="body2" color="text.info" sx={{ mb: 2 }}>
                  Sign in with your Hugging Face account to access the inference
                  providers.{" "}
                  <strong>
                    This demo is free to use - we've provided credits to cover
                    the inference costs for your agent runs.
                  </strong>{" "}
                  We only use your Hugging Face account for authentication and do not access any of your other data or resources.
                </Typography>
                {process.env.NODE_ENV === "development" ? (
                  <DevModeLoginButton
                    userInfo={userInfo}
                    accessToken={accessToken}
                    loginLabel={loginLabel}
                    onLoginStateChange={onLoginStateChange}
                    isDisabled={isStarting}
                  />
                ) : (
                  <HuggingFaceLoginButton
                    userInfo={userInfo}
                    accessToken={accessToken}
                    loginLabel={loginLabel}
                    onLoginStateChange={onLoginStateChange}
                    isDisabled={isStarting}
                  />
                )}
              </Stack>
              {/* Model and Provider Selection */}
              <Stack spacing={0.5} sx={{ p: 1, mt: 0 }}>
                {/* Model Suggestions with two boxes */}
                <ModelProviderSelector
                  variant="suggestions"
                  model={formData.model}
                  provider={formData.provider}
                  onModelChange={() => {}}
                  onProviderChange={() => {}}
                  suggestedModels={suggestedModels}
                  selectedSuggestion={selectedSuggestion}
                  onSuggestionChange={(value, provider, model) => {
                    setSelectedSuggestion(value);
                    onFormChange({ ...formData, provider, model });
                  }}
                  customProvider={customProvider}
                  customModel={customModel}
                  onCustomProviderChange={(provider) => {
                    setCustomProvider(provider);
                    if (customModel) {
                      onFormChange({
                        ...formData,
                        provider,
                        model: customModel,
                      });
                    }
                  }}
                  onCustomModelChange={(model) => {
                    setCustomModel(model);
                    if (customProvider) {
                      onFormChange({
                        ...formData,
                        provider: customProvider,
                        model,
                      });
                    }
                  }}
                  selectedOption={selectedOption}
                  onOptionChange={(option) => {
                    setSelectedOption(option);
                    if (option === "suggested") {
                      // Use currently selected suggestion, or default to first one if none selected
                      const selectedIndex =
                        selectedSuggestion !== ""
                          ? parseInt(selectedSuggestion)
                          : 0;
                      const model = suggestedModels[selectedIndex];
                      if (model) {
                        onFormChange({
                          ...formData,
                          provider: model.provider,
                          model: model.model,
                        });
                      }
                    }
                  }}
                  isDisabled={!isLoggedIn || isStarting}
                />
                <Box
                  sx={{
                    display: "flex",
                    alignItems: "center",
                    justifyContent: "space-between",
                    mb: 1,
                    mt: 0,
                  }}
                >
                  <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
                    <Typography>Upload an MCP configuration</Typography>
                    <Typography variant="body2" color="textDisabled">
                      Optional
                    </Typography>
                  </Box>
                  <Stack spacing={1} direction="row" alignItems="center">
                    <TooltipIcon
                      title="This demo comes with preloaded simulated apps like Messages,
                  Shopping and more. Optionally upload an MCP (Model Context
                  Protocol) file (.json) that defines the tools and capabilities
                  for your agent. If the value 'HF_TOKEN' appears in headers, it
                  will be replaced with your token automatically."
                    />
                  </Stack>
                </Box>
                <Button
                  variant="outlined"
                  component="label"
                  fullWidth
                  disabled={!isLoggedIn || isStarting}
                  sx={{
                    py: 1.5,
                    px: 2,
                    justifyContent: "flex-start",
                    textAlign: "left",
                    borderWidth: "2px !important",
                    borderColor: (theme) => theme.palette.grey[700],
                    "&:hover": {
                      borderColor: (theme) => theme.palette.action.active,
                    },
                    borderRadius: 1.5,
                  }}
                  color="inherit"
                >
                  <Box
                    sx={{
                      overflow: "hidden",
                      textOverflow: "ellipsis",
                      whiteSpace: "nowrap",
                      width: "100%",
                    }}
                  >
                    {formData.mcpFile
                      ? formData.mcpFile.name
                      : "Click to upload MCP file (.json)"}
                  </Box>
                  <input
                    type="file"
                    hidden
                    accept=".json"
                    onChange={handleFileChange}
                    disabled={!isLoggedIn || isStarting}
                  />
                </Button>
                <Stack
                  direction="row"
                  alignItems="center"
                  justifyContent={"flex-end"}
                >
                  <Tooltip title="Reset to demo MCP configuration file">
                    <span>
                      <IconButton
                        size="small"
                        onClick={resetFile}
                        color="inherit"
                        disabled={formData.mcpFile === defaultMcpFile}
                      >
                        <RestartIcon fontSize="inherit" />
                      </IconButton>
                    </span>
                  </Tooltip>
                  <Tooltip title="Download demo MCP configuration file">
                    <span>
                      <IconButton href="/demo-mcp.json" download size="small">
                        <DownloadIcon fontSize="inherit" />
                      </IconButton>
                    </span>
                  </Tooltip>
                </Stack>
              </Stack>
              {/* Start Button */}
              <Box sx={{ p: 2, mt: 0, pt: 1 }}>
                <Button
                  fullWidth
                  variant="contained"
                  color="secondary"
                  size="large"
                  startIcon={
                    isStarting ? (
                      <CircularProgress size={20} color="inherit" />
                    ) : (
                      <RocketLaunchIcon />
                    )
                  }
                  onClick={onSubmit}
                  disabled={!isFormValid || isStarting}
                  sx={{ py: 1.5 }}
                >
                  {isStarting ? "Launching demo…" : "Launch demo"}
                </Button>
              </Box>
            </Stack>
          </Paper>
        </Stack>
      </Box>

      {/* MCP File Upload Warning Dialog */}
      <McpConfigurationWarningDialog
        open={dialogOpen}
        onClose={handleDialogClose}
        onConfirm={handleDialogConfirm}
      />
    </>
  );
};