';
}
}
// ── Create form ──────────────────────────
function showCreateForm(defaults) {
var d = defaults || {};
var mount = document.getElementById('settingsTasksMount');
if (!mount) return;
var schedOpts = PRESETS.map(function(p) {
var sel = (d.schedule && d.schedule === p.cron) ? ' selected' : '';
return '';
}).join('');
mount.innerHTML =
'' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'' +
'
Used to sign outbound webhook payloads. Leave blank for auto-generated secret.
' +
'
' +
'
' +
'
' +
'' +
' Webhook-triggered task
' +
'
This task runs when an external service sends a POST request to its trigger URL. ' +
'The trigger URL will be shown after creation — copy it into your CI, cron, or another task\\u2019s webhook URL for task-to-task chaining.
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'' +
'' +
'
' +
'' +
'
';
document.getElementById('taskBackBtn').addEventListener('click', loadTaskList);
document.getElementById('taskCreateBtn').addEventListener('click', createTask);
// Toggle custom cron visibility
var preset = document.getElementById('taskPreset');
var customGroup = document.getElementById('taskCustomCronGroup');
var triggerInfo = document.getElementById('taskWebhookTriggerInfo');
preset.addEventListener('change', function() {
var isWebhook = preset.value === 'webhook';
var isCustom = preset.value === '';
customGroup.style.display = isCustom ? '' : 'none';
triggerInfo.style.display = isWebhook ? '' : 'none';
if (!isWebhook && !isCustom) document.getElementById('taskCron').value = preset.value;
if (isWebhook) document.getElementById('taskCron').value = 'webhook';
});
// Initial state
customGroup.style.display = preset.value === '' ? '' : 'none';
triggerInfo.style.display = preset.value === 'webhook' ? '' : 'none';
if (preset.value !== '' && preset.value !== 'webhook') document.getElementById('taskCron').value = preset.value;
// Toggle webhook URL and secret visibility
var output = document.getElementById('taskOutput');
var webhookGroup = document.getElementById('taskWebhookGroup');
var webhookSecretGroup = document.getElementById('taskWebhookSecretGroup');
output.addEventListener('change', function() {
var isWH = output.value === 'webhook';
webhookGroup.style.display = isWH ? '' : 'none';
webhookSecretGroup.style.display = isWH ? '' : 'none';
});
}
async function createTask() {
var schedule = document.getElementById('taskCron').value || document.getElementById('taskPreset').value;
if (!schedule) { UI.toast('Schedule is required', 'error'); return; }
var payload = {
name: document.getElementById('taskName').value,
task_type: 'prompt',
user_prompt: document.getElementById('taskPrompt').value,
schedule: schedule,
timezone: document.getElementById('taskTZ').value || 'UTC',
output_mode: document.getElementById('taskOutput').value,
notify_on_complete: document.getElementById('taskNotifyComplete').checked,
notify_on_failure: document.getElementById('taskNotifyFail').checked,
};
var model = document.getElementById('taskModel').value;
if (model) payload.model_id = model;
var maxTokens = parseInt(document.getElementById('taskMaxTokens').value);
if (maxTokens > 0) payload.max_tokens = maxTokens;
var maxTools = parseInt(document.getElementById('taskMaxToolCalls').value);
if (maxTools > 0) payload.max_tool_calls = maxTools;
var webhookURL = document.getElementById('taskWebhookURL')?.value;
if (payload.output_mode === 'webhook' && webhookURL) {
payload.webhook_url = webhookURL;
}
var webhookSecret = document.getElementById('taskWebhookSecret')?.value;
if (payload.output_mode === 'webhook' && webhookSecret) {
payload.webhook_secret = webhookSecret;
}
try {
var created = await API._post('/api/v1/tasks', payload);
UI.toast('Task created', 'success');
// Show trigger URL for webhook-scheduled tasks
if (created.schedule === 'webhook' && created.trigger_token) {
var triggerURL = location.origin + (window.__BASE__ || '') + '/api/v1/hooks/t/' + created.trigger_token;
UI.modal('Webhook Trigger URL',
'
POST to this URL to trigger the task. ' +
'You can use this in CI pipelines, cron jobs, or as another task\\u2019s webhook URL for chaining.
' +
'
' +
'' +
'' +
'
' +
'
The request body is passed to the task as trigger_payload. ' +
'For task-to-task chaining: set Task A\\u2019s webhook_url to Task B\\u2019s trigger URL.