()
| 10 | const OPENCLAW_STEPS = ['basicInfo', 'permissions'] as const; |
| 11 | |
| 12 | export default function AgentCreate() { |
| 13 | const { t } = useTranslation(); |
| 14 | const navigate = useNavigate(); |
| 15 | const location = useLocation(); |
| 16 | const queryClient = useQueryClient(); |
| 17 | const [step, setStep] = useState(0); |
| 18 | const [error, setError] = useState(''); |
| 19 | const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({}); |
| 20 | const [agentType, setAgentType] = useState<'native' | 'openclaw'>(() => { |
| 21 | const params = new URLSearchParams(location.search); |
| 22 | return params.get('type') === 'openclaw' ? 'openclaw' : 'native'; |
| 23 | }); |
| 24 | // Clear field error when user edits a field |
| 25 | const clearFieldError = (field: string) => setFieldErrors(prev => { const n = { ...prev }; delete n[field]; return n; }); |
| 26 | const [createdApiKey, setCreatedApiKey] = useState(''); |
| 27 | // Current company (tenant) selection from layout sidebar |
| 28 | const [currentTenant] = useState<string | null>(() => localStorage.getItem('current_tenant_id')); |
| 29 | |
| 30 | const [form, setForm] = useState({ |
| 31 | name: '', |
| 32 | role_description: '', |
| 33 | personality: '', |
| 34 | boundaries: '', |
| 35 | primary_model_id: '' as string, |
| 36 | fallback_model_id: '' as string, |
| 37 | permission_scope_type: 'company', |
| 38 | permission_access_level: 'use', |
| 39 | max_tokens_per_day: '', |
| 40 | max_tokens_per_month: '', |
| 41 | skill_ids: [] as string[], |
| 42 | }); |
| 43 | const [channelValues, setChannelValues] = useState<Record<string, string>>({}); |
| 44 | |
| 45 | // Fetch LLM models for step 1 |
| 46 | const { data: models = [] } = useQuery({ |
| 47 | queryKey: ['llm-models'], |
| 48 | queryFn: enterpriseApi.llmModels, |
| 49 | }); |
| 50 | |
| 51 | // Tenant default model — used to preselect the model step so the open-source |
| 52 | // default ("hire and go") path needs no clicks. User can override. |
| 53 | const { data: myTenant } = useQuery({ |
| 54 | queryKey: ['tenant', 'me'], |
| 55 | queryFn: () => tenantApi.me(), |
| 56 | staleTime: 5 * 60 * 1000, |
| 57 | }); |
| 58 | useEffect(() => { |
| 59 | if (!myTenant?.default_model_id) return; |
| 60 | const enabledModels = (models as any[]).filter((m: any) => m.enabled); |
| 61 | const exists = enabledModels.some((m: any) => m.id === myTenant.default_model_id); |
| 62 | if (exists) { |
| 63 | setForm(prev => prev.primary_model_id ? prev : { ...prev, primary_model_id: myTenant.default_model_id! }); |
| 64 | } |
| 65 | }, [myTenant?.default_model_id, models]); |
| 66 | |
| 67 | // Fetch global skills for step 3 |
| 68 | const { data: globalSkills = [] } = useQuery({ |
| 69 | queryKey: ['global-skills'], |
nothing calls this directly
no test coverage detected