()
| 28 | const content = t`With Flowchart Fun's Pro version, you can use natural language comamnds to quickly flesh out your flowchart details, ideal for creating diagrams on the go. For $6/month, get the ease of accessible AI editing to enhance your flowcharting experience.`; |
| 29 | |
| 30 | export function EditWithAI() { |
| 31 | const [message, setMessage] = useState<string | null>(null); |
| 32 | const [isOpen, setIsOpen] = useState(false); |
| 33 | const [transcriptionLoading, setTranscriptionLoading] = useState(false); |
| 34 | const hasProAccess = useHasProAccess(); |
| 35 | |
| 36 | const { mutate: edit, isLoading: editIsLoading } = useMutation({ |
| 37 | mutationFn: async (body: { prompt: string; graph: GraphForAI }) => { |
| 38 | // /api/prompt/edit |
| 39 | const response = await fetch("/api/prompt/edit", { |
| 40 | method: "POST", |
| 41 | body: JSON.stringify(body), |
| 42 | headers: { |
| 43 | "Content-Type": "application/json", |
| 44 | }, |
| 45 | }); |
| 46 | const data = await response.json(); |
| 47 | |
| 48 | return data as { |
| 49 | message: string; |
| 50 | toolCalls: { |
| 51 | name: "updateGraph"; |
| 52 | args: GraphForAI; |
| 53 | }[]; |
| 54 | }; |
| 55 | }, |
| 56 | onSuccess(data) { |
| 57 | if (data.message) { |
| 58 | setMessage(data.message); |
| 59 | } |
| 60 | |
| 61 | for (const { name, args } of data.toolCalls) { |
| 62 | switch (name) { |
| 63 | case "updateGraph": { |
| 64 | const newText = toGraphSelector(args); |
| 65 | useDoc.setState({ text: newText }, false, "EditWithAI"); |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | }, |
| 71 | onSettled() { |
| 72 | setTranscriptionLoading(false); |
| 73 | }, |
| 74 | }); |
| 75 | |
| 76 | const submitPrompt = useCallback( |
| 77 | (prompt: string) => { |
| 78 | if (!hasProAccess) { |
| 79 | showPaywall({ |
| 80 | title, |
| 81 | content, |
| 82 | imgUrl: "/images/ai-edit.png", |
| 83 | toPricingCode: "EditWithAI", |
| 84 | }); |
| 85 | return; |
| 86 | } |
| 87 |
nothing calls this directly
no test coverage detected