module.exports=[19078,a=>{"use strict";var b=a.i(66680),c=a.i(80026);function d(a){return(0,c.getDb)().prepare("SELECT * FROM tasks WHERE id = ? OR display_id = ?").get(a,a)??null}a.s(["claimProposedTask",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare("UPDATE tasks SET status = 'working', updated_at = ? WHERE id = ? AND status = 'proposed'").run(e,a).changes?null:d(a)},"clearBlockerAndPromote",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare("UPDATE tasks SET status = 'proposed', blocked_by_task_id = NULL, updated_at = ? WHERE id = ? AND status = 'blocked'").run(e,a).changes?null:d(a)},"createTask",0,function(a){var e,f;let g,h,i=(0,c.getDb)(),j=new Date().toISOString(),k=a.status??"proposed",l=a.blocked_by_task_id??null;if(l){let a=d(l);a&&"done"!==(f=a.status)&&"failed"!==f&&"cancelled"!==f?k="blocked":l=null}let m={id:(0,b.randomUUID)(),display_id:(e=a.project_slug,g=(0,c.getDb)().prepare(`SELECT COALESCE(MAX(CAST(substr(display_id, ?) AS INTEGER)), 0) AS max_n
       FROM tasks
       WHERE project_slug = ? AND display_id LIKE ?`).get(e.length+2,e,`${e}-%`),h=(g?.max_n??0)+1,`${e}-${h}`),project_slug:a.project_slug,agent_id:a.agent_id,title:a.title??null,brief:a.brief,success_criteria:a.success_criteria??null,deadline_iso:a.deadline_iso??null,status:k,result_json:null,error_message:null,thread_id:null,assigner_agent_id:a.assigner_agent_id??null,blocked_by_task_id:l,created_at:j,updated_at:j};return i.prepare(`INSERT INTO tasks
       (id, display_id, project_slug, agent_id, title, brief, success_criteria, deadline_iso,
        status, result_json, error_message, thread_id, assigner_agent_id, blocked_by_task_id, created_at, updated_at)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, NULL, ?, ?, ?, ?)`).run(m.id,m.display_id,m.project_slug,m.agent_id,m.title,m.brief,m.success_criteria,m.deadline_iso,m.status,m.assigner_agent_id,m.blocked_by_task_id,m.created_at,m.updated_at),m},"getTask",0,d,"inFlightCountsByAgent",0,function(a){let b=(0,c.getDb)().prepare(`SELECT agent_id, COUNT(*) as count
       FROM tasks
       WHERE project_slug = ? AND status IN ('proposed', 'approved', 'working', 'blocked')
       GROUP BY agent_id`).all(a),d=new Map;for(let a of b)d.set(a.agent_id,a.count);return d},"listTasks",0,function(a,b){let d=(0,c.getDb)();return b?d.prepare("SELECT * FROM tasks WHERE project_slug = ? AND status = ? ORDER BY created_at DESC").all(a,b):d.prepare("SELECT * FROM tasks WHERE project_slug = ? ORDER BY created_at DESC").all(a)},"listTasksBlockedBy",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM tasks WHERE blocked_by_task_id = ? AND status = 'blocked' ORDER BY created_at ASC").all(a)},"listTasksByAgent",0,function(a,b){let d=(0,c.getDb)();return b?d.prepare("SELECT * FROM tasks WHERE agent_id = ? AND status = ? ORDER BY created_at DESC").all(a,b):d.prepare("SELECT * FROM tasks WHERE agent_id = ? ORDER BY created_at DESC").all(a)},"markTaskBlocked",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return b.prepare("UPDATE tasks SET status = 'blocked', updated_at = ? WHERE id = ? AND status IN ('working','proposed','approved')").run(e,a),d(a)},"setTaskThreadIfMissing",0,function(a,b){let e=(0,c.getDb)(),f=d(a);return f?f.thread_id?f:(e.prepare("UPDATE tasks SET thread_id = ?, updated_at = ? WHERE id = ? AND thread_id IS NULL").run(b,new Date().toISOString(),a),d(a)):null},"unblockTask",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return b.prepare("UPDATE tasks SET status = 'working', updated_at = ? WHERE id = ? AND status = 'blocked'").run(e,a),d(a)},"updateTask",0,function(a,b){let e=(0,c.getDb)(),f=new Date().toISOString(),g=d(a);if(!g)return null;let h=void 0!==b.result?JSON.stringify(b.result):g.result_json,i=void 0!==b.error_message?b.error_message:g.error_message,j=b.status??g.status;return e.prepare("UPDATE tasks SET status = ?, result_json = ?, error_message = ?, updated_at = ? WHERE id = ?").run(j,h,i,f,a),d(a)}])}];

//# sourceMappingURL=src_server_db_tasks_ts_0u-1znn._.js.map