Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 46 additions & 15 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ import 'reactflow/dist/style.css';
import axios from 'axios';
import html2canvas from 'html2canvas';
import { saveAs } from 'file-saver';
import SettingsModal from './SettingsModal';

// 🧠 Initial State & Helpers
const initialNodes = [];
const initialEdges = [];
const defaultSystemPrompt = `You are an expert in cause-and-effect analysis.

Given a news headline or event, break it down into a chain of consequences, like a domino effect.

Each node must:
- Be short (max 15 words)
- Represent one specific consequence
- Be categorized as either: 'positive', 'neutral', or 'negative'
- Be logically linked to the prompt

Return only 3 outputs: one of each type.`;
let nodeId = 1;

const getColor = (type) => {
Expand All @@ -27,7 +39,7 @@ const getColor = (type) => {
};

// 🤖 AI Logic with Domino Effect Thinking (Updated: Using Puter AI API)
const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef) => {
const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef, systemPrompt) => {
try {
if (stopGenerationRef.current) return;
const res = await axios.post(
Expand All @@ -37,17 +49,7 @@ const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerati
messages: [
{
role: 'system',
content: `You are an expert in cause-and-effect analysis.

Given a news headline or event, break it down into a chain of consequences, like a domino effect.

Each node must:
- Be short (max 15 words)
- Represent one specific consequence
- Be categorized as either: 'positive', 'neutral', or 'negative'
- Be logically linked to the prompt

Return only 3 outputs: one of each type.`
content: systemPrompt,
},
{ role: 'user', content: text }
]
Expand Down Expand Up @@ -96,7 +98,7 @@ Return only 3 outputs: one of each type.`
// Recursively expand each child one level deep
for (const n of newNodes) {
if (stopGenerationRef.current) break;
await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef);
await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef, systemPrompt);
}

} catch (err) {
Expand All @@ -113,8 +115,17 @@ export default function App() {
const [edges, setEdges] = useState(initialEdges);
const [prompt, setPrompt] = useState('');
const [loading, setLoading] = useState(false);
const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false);
const stopGenerationRef = useRef(false);
const reactFlowWrapper = useRef(null);
const [systemPrompt, setSystemPrompt] = useState(
localStorage.getItem('systemPrompt') || defaultSystemPrompt
);

const handleSetSystemPrompt = (newPrompt) => {
setSystemPrompt(newPrompt);
localStorage.setItem('systemPrompt', newPrompt);
};

const handleExport = () => {
if (reactFlowWrapper.current) {
Expand Down Expand Up @@ -150,7 +161,7 @@ export default function App() {
setNodes([rootNode]);
setEdges([]);

await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef);
await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef, systemPrompt);

setPrompt('');
setLoading(false);
Expand All @@ -164,7 +175,7 @@ export default function App() {
const onNodeClick = async (_event, node) => {
stopGenerationRef.current = false;
setLoading(true);
await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef);
await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef, systemPrompt);
setLoading(false);
};

Expand Down Expand Up @@ -246,11 +257,31 @@ export default function App() {
>
Export as PNG
</button>
<button
onClick={() => setIsSettingsModalOpen(true)}
style={{
padding: '10px 20px',
backgroundColor: '#6c757d',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
}}
>
⚙️ Settings
</button>
</div>
</div>

{/* 🧠 ReactFlow Canvas */}
<div style={{ flexGrow: 1 }} ref={reactFlowWrapper}>
<SettingsModal
isOpen={isSettingsModalOpen}
onClose={() => setIsSettingsModalOpen(false)}
systemPrompt={systemPrompt}
setSystemPrompt={handleSetSystemPrompt}
/>
<ReactFlow
nodes={nodes}
edges={edges}
Expand Down
89 changes: 89 additions & 0 deletions src/SettingsModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// -–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-
// ⚙️ SettingsModal Component
// -–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-–-
import React, { useState } from 'react';

// 🎨 Styles for the modal
const modalStyles = {
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.7)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
zIndex: 1000,
},
modal: {
background: '#333',
padding: '2rem',
borderRadius: '12px',
width: '500px',
color: '#fff',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
},
textarea: {
width: '100%',
minHeight: '200px',
padding: '10px',
borderRadius: '8px',
border: '1px solid #ccc',
color: '#fff',
backgroundColor: '#444',
},
buttonContainer: {
display: 'flex',
justifyContent: 'flex-end',
gap: '0.5rem',
},
button: {
padding: '10px 20px',
borderRadius: '8px',
border: 'none',
fontWeight: 'bold',
cursor: 'pointer',
},
};

// component
const SettingsModal = ({ isOpen, onClose, systemPrompt, setSystemPrompt }) => {
const [prompt, setPrompt] = useState(systemPrompt);

const handleSave = () => {
setSystemPrompt(prompt);
onClose();
};

if (!isOpen) {
return null;
}

return (
<div style={modalStyles.overlay}>
<div style={modalStyles.modal}>
<h2 style={{ marginTop: 0 }}>⚙️ AI Settings</h2>
<p>Customize the AI's instructions. This will change how it generates new nodes.</p>
<textarea
style={modalStyles.textarea}
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
/>
<div style={modalStyles.buttonContainer}>
<button style={{ ...modalStyles.button, backgroundColor: '#555' }} onClick={onClose}>
Cancel
</button>
<button style={{ ...modalStyles.button, backgroundColor: '#00bcd4' }} onClick={handleSave}>
Save
</button>
</div>
</div>
</div>
);
};

export default SettingsModal;