/**
* Example HTTP Client for Sequential Thinking (Cloudflare Workers)
* This demonstrates how to use the REST API
*/
const BASE_URL = 'http://localhost:3000'; // Change to your deployed URL
async function main() {
console.log('=== Sequential Thinking HTTP Client Example ===\n');
// Check server health
const healthResponse = await fetch(`${BASE_URL}/health`);
const health = await healthResponse.json();
console.log('Server health:', health);
// Get server info
const infoResponse = await fetch(`${BASE_URL}/info`);
const info = await infoResponse.json();
console.log('\nServer info:', info);
console.log('\n=== Adding Sequential Thoughts ===\n');
// Add thought 1
const thought1 = await fetch(`${BASE_URL}/think`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
thought: 'Analyze the problem: Building a recommendation system',
nextThoughtNeeded: true,
thoughtNumber: 1,
totalThoughts: 4,
}),
});
const result1 = await thought1.json();
console.log('Thought 1:', result1.message);
// Add thought 2
const thought2 = await fetch(`${BASE_URL}/think`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
thought: 'Choose approach: Collaborative filtering vs Content-based filtering',
nextThoughtNeeded: true,
thoughtNumber: 2,
totalThoughts: 4,
}),
});
const result2 = await thought2.json();
console.log('Thought 2:', result2.message);
// Add thought 3
const thought3 = await fetch(`${BASE_URL}/think`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
thought: 'Implement hybrid approach combining both methods',
nextThoughtNeeded: true,
thoughtNumber: 3,
totalThoughts: 4,
}),
});
const result3 = await thought3.json();
console.log('Thought 3:', result3.message);
// Add thought 4
const thought4 = await fetch(`${BASE_URL}/think`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
thought: 'Use matrix factorization with neural networks for better accuracy',
nextThoughtNeeded: false,
thoughtNumber: 4,
totalThoughts: 4,
}),
});
const result4 = await thought4.json();
console.log('Thought 4:', result4.message);
// Get the sequence
console.log('\n=== Retrieving Thought Sequence ===\n');
const sequenceResponse = await fetch(`${BASE_URL}/sequence`);
const sequence = await sequenceResponse.json();
console.log(`Session: ${sequence.sessionId}`);
console.log(`Total thoughts: ${sequence.thoughtCount}\n`);
sequence.thoughts.forEach((thought, index) => {
console.log(`${index + 1}. ${thought.thought}`);
});
// Reset session
console.log('\n=== Resetting Session ===\n');
const resetResponse = await fetch(`${BASE_URL}/reset`, { method: 'POST' });
const resetResult = await resetResponse.json();
console.log(resetResult.message);
console.log('New session ID:', resetResult.sessionId);
}
main().catch(console.error);