async function handleTask(sessionId, taskId, apiKey) {
// Poll for result
const result = await pollForResult(sessionId, taskId, apiKey);
if (result.type === "guardrail_trigger") {
console.log("Guardrail:", result.data.value);
// Get user input
const userInput = await promptUser(result.data.value);
// Respond to guardrail
await fetch("https://connect.enigma.click/start/send-message", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
sessionId,
message: {
actionType: "guardrail",
taskDetails: userInput,
newState: "resume"
}
})
});
// Continue polling for completion
return await pollForResult(sessionId, taskId, apiKey);
}
return result;
}