(input: ScheduleCronInput)
| 29 | | { ok: false; error: string }; |
| 30 | |
| 31 | export async function scheduleCronAction(input: ScheduleCronInput): Promise<ScheduleCronResult> { |
| 32 | const nameSlug = slugify(input.name); |
| 33 | if (!nameSlug.ok) return { ok: false, error: `Invalid name: ${nameSlug.reason}` }; |
| 34 | |
| 35 | const briefTrimmed = input.brief.trim(); |
| 36 | if (!briefTrimmed) return { ok: false, error: "Brief is required." }; |
| 37 | |
| 38 | const scheduleValueTrimmed = input.schedule_value.trim(); |
| 39 | if (!scheduleValueTrimmed) return { ok: false, error: "Schedule is required." }; |
| 40 | |
| 41 | // Look up the agent's actual id/slug from the project — agent_ids now |
| 42 | // encode the personal name (e.g. `demo3-cmo-greg`) so we can't |
| 43 | // synthesize them from the template key alone. |
| 44 | const projectAgents = await listProjectAgents(input.project_slug); |
| 45 | const target = projectAgents.find((a) => a.template_key === input.specialist); |
| 46 | if (!target) { |
| 47 | return { |
| 48 | ok: false, |
| 49 | error: `No '${input.specialist}' agent found in project ${input.project_slug}.`, |
| 50 | }; |
| 51 | } |
| 52 | const agent_slug = target.slug; |
| 53 | const agent_full_id = target.agent_id; |
| 54 | |
| 55 | try { |
| 56 | const result = await createCron({ |
| 57 | project_slug: input.project_slug, |
| 58 | agent_slug, |
| 59 | agent_full_id, |
| 60 | cron_name: nameSlug.slug, |
| 61 | schedule: { kind: "cron", expr: scheduleValueTrimmed, tz: input.tz }, |
| 62 | message: briefTrimmed, |
| 63 | }); |
| 64 | logAgentAction({ |
| 65 | project_slug: input.project_slug, |
| 66 | agent_id: agent_full_id, |
| 67 | action_type: "cron_created", |
| 68 | summary: `Scheduled '${nameSlug.slug}' (${input.schedule_kind} ${scheduleValueTrimmed})`, |
| 69 | payload: { cron_id: result.id, cron_name: result.name, brief: briefTrimmed }, |
| 70 | }); |
| 71 | revalidatePath("/", "layout"); |
| 72 | revalidatePath("/", "layout"); |
| 73 | return { ok: true, cron_id: result.id, cron_name: result.name }; |
| 74 | } catch (err) { |
| 75 | return { ok: false, error: err instanceof Error ? err.message : String(err) }; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | export async function pauseCronAction(id: string): Promise<{ ok: boolean; error?: string }> { |
| 80 | try { |
no test coverage detected