MCPcopy Create free account
hub / github.com/SKaplanOfficial/Raycast-PromptLab / ModelForm

Function ModelForm

src/components/Models/ModelForm.tsx:40–238  ·  view source on GitHub ↗
(props: { models: ModelManager; currentModel?: Model; duplicate?: boolean })

Source from the content-addressed store, hash-verified

38}
39
40export default function ModelForm(props: { models: ModelManager; currentModel?: Model; duplicate?: boolean }) {
41 const { models, currentModel, duplicate } = props;
42 const { pop } = useNavigation();
43 const [uuid, setUUID] = useState<string>("");
44
45 const getDefaultValues = () => {
46 try {
47 const advancedSettingsValues = JSON.parse(
48 fs.readFileSync(path.join(environment.supportPath, ADVANCED_SETTINGS_FILENAME), "utf-8"),
49 );
50 if ("modelDefaults" in advancedSettingsValues) {
51 return advancedSettingsValues.modelDefaults;
52 }
53 } catch (error) {
54 console.error(error);
55 }
56
57 return models.dummyModel();
58 };
59
60 useEffect(() => {
61 const id = randomUUID();
62 setUUID(id);
63 if (currentModel && !currentModel.id) {
64 Promise.resolve(updateModel(currentModel, { ...currentModel, id: id })).then(() => models.revalidate());
65 }
66 }, []);
67
68 const { handleSubmit, itemProps, values } = useForm<ModelFormValues>({
69 async onSubmit(values) {
70 await LocalStorage.setItem(`--model-${values.name}`, JSON.stringify(values));
71 if (currentModel && currentModel.name != values.name) {
72 await LocalStorage.removeItem(`--model-${currentModel.name}`);
73 }
74
75 models.revalidate();
76
77 if (currentModel && !duplicate) {
78 await showToast({ title: "Models Saved" });
79 } else {
80 await showToast({ title: "Added Model" });
81 }
82
83 pop();
84 },
85 initialValues: currentModel || getDefaultValues(),
86 validation: {
87 name: FormValidation.Required,
88 },
89 });
90
91 return (
92 <Form
93 actions={
94 <ActionPanel>
95 <Action.SubmitForm title="Save" onSubmit={handleSubmit} />
96 </ActionPanel>
97 }

Callers

nothing calls this directly

Calls 2

updateModelFunction · 0.90
getDefaultValuesFunction · 0.70

Tested by

no test coverage detected