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)}])},81181,a=>{"use strict";var b=a.i(66680),c=a.i(80026);function d(a){let d=(0,c.getDb)(),e={id:(0,b.randomUUID)(),approval_id:a.approval_id,author_kind:a.author_kind,author_id:a.author_id??null,body:a.body,created_at:new Date().toISOString()};return d.prepare(`INSERT INTO approval_comments (id, approval_id, author_kind, author_id, body, created_at)
     VALUES (?, ?, ?, ?, ?, ?)`).run(e.id,e.approval_id,e.author_kind,e.author_id,e.body,e.created_at),e}a.s(["actionableApprovalCount",0,function(a){return(0,c.getDb)().prepare(`SELECT COUNT(*) AS n FROM approvals
        WHERE project_slug = ? AND status IN ('pending','revision_requested')`).get(a).n},"appendComment",0,d,"createApproval",0,function(a){var e,f,g,h;let i=(0,c.getDb)(),j=(0,b.randomUUID)(),k=new Date().toISOString(),l=(e=a.project_slug,f=a.action_type,g=a.agent_id,h=a.cost_estimate_usd,(0,c.getDb)().prepare(`SELECT * FROM approval_policies
        WHERE project_slug = ?
          AND action_type = ?
          AND (agent_id IS NULL OR agent_id = ?)
          AND (max_cost_usd IS NULL OR max_cost_usd >= ?)
        ORDER BY
          CASE WHEN agent_id IS NULL THEN 1 ELSE 0 END,
          CASE WHEN max_cost_usd IS NULL THEN 1 ELSE 0 END,
          max_cost_usd ASC NULLS LAST,
          created_at DESC`).all(e,f,g,h)[0]??null),m=l?"approve"===l.auto_decision?"approved":"rejected":"pending";return i.prepare(`INSERT INTO approvals
       (id, project_slug, agent_id, task_id, action_summary, action_type,
        cost_estimate_usd, reasoning, payload_json, status,
        decision_note, decided_by_kind, decided_by_id,
        created_at, resolved_at)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(j,a.project_slug,a.agent_id,a.task_id??null,a.action_summary,a.action_type,a.cost_estimate_usd,a.reasoning??null,JSON.stringify(a.payload??{}),m,l?l.note??"Auto-decided by policy.":null,l?"policy":null,l?l.id:null,k,l?k:null),l&&d({approval_id:j,author_kind:"system",author_id:l.id,body:`Auto-${"approve"===l.auto_decision?"approved":"rejected"} by policy: ${l.note??"(no note)"}`}),i.prepare("SELECT * FROM approvals WHERE id = ?").get(j)},"createPolicy",0,function(a){let d=(0,c.getDb)(),e={id:(0,b.randomUUID)(),project_slug:a.project_slug,action_type:a.action_type,agent_id:a.agent_id??null,max_cost_usd:a.max_cost_usd??null,auto_decision:a.auto_decision,note:a.note??null,created_at:new Date().toISOString(),created_by_kind:a.created_by_kind,created_by_id:a.created_by_id??null};return d.prepare(`INSERT INTO approval_policies
       (id, project_slug, action_type, agent_id, max_cost_usd, auto_decision, note, created_at, created_by_kind, created_by_id)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(e.id,e.project_slug,e.action_type,e.agent_id,e.max_cost_usd,e.auto_decision,e.note,e.created_at,e.created_by_kind,e.created_by_id),e},"deletePolicy",0,function(a){return(0,c.getDb)().prepare("DELETE FROM approval_policies WHERE id = ?").run(a).changes>0},"getApproval",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM approvals WHERE id = ?").get(a)??null},"listActionableApprovals",0,function(a){return(0,c.getDb)().prepare(`SELECT * FROM approvals
        WHERE project_slug = ?
          AND status IN ('pending','revision_requested')
        ORDER BY created_at DESC`).all(a)},"listApprovalsForTask",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM approvals WHERE task_id = ? ORDER BY created_at DESC").all(a)},"listComments",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM approval_comments WHERE approval_id = ? ORDER BY created_at ASC").all(a)},"listPendingApprovals",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM approvals WHERE project_slug = ? AND status = 'pending' ORDER BY created_at DESC").all(a)},"listPolicies",0,function(a){return(0,c.getDb)().prepare("SELECT * FROM approval_policies WHERE project_slug = ? ORDER BY created_at DESC").all(a)},"listResolvedApprovals",0,function(a,b=50){return(0,c.getDb)().prepare(`SELECT * FROM approvals
        WHERE project_slug = ?
          AND status IN ('approved','rejected','expired')
        ORDER BY resolved_at DESC NULLS LAST, created_at DESC
        LIMIT ?`).all(a,b)},"requestApprovalRevision",0,function(a,b){let d=(0,c.getDb)();return d.prepare(`UPDATE approvals
        SET status = 'revision_requested',
            decision_note = ?,
            decided_by_kind = COALESCE(?, decided_by_kind),
            decided_by_id = COALESCE(?, decided_by_id)
      WHERE id = ?
        AND status = 'pending'`).run(b.decision_note,b.decided_by_kind??null,b.decided_by_id??null,a),d.prepare("SELECT * FROM approvals WHERE id = ?").get(a)??null},"resolveApproval",0,function(a,b,d={}){let e=(0,c.getDb)(),f=new Date().toISOString();return e.prepare(`UPDATE approvals
        SET status = ?,
            resolved_at = ?,
            decision_note = COALESCE(?, decision_note),
            decided_by_kind = COALESCE(?, decided_by_kind),
            decided_by_id = COALESCE(?, decided_by_id)
      WHERE id = ?
        AND status IN ('pending','revision_requested')`).run(b,f,d.decision_note??null,d.decided_by_kind??null,d.decided_by_id??null,a),e.prepare("SELECT * FROM approvals WHERE id = ?").get(a)??null}])},53974,a=>{"use strict";var b=a.i(66680),c=a.i(80026);function d(a){return(0,c.getDb)().prepare("SELECT * FROM questions WHERE id = ?").get(a)??null}a.s(["answerQuestion",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare(`UPDATE questions
          SET status = 'answered',
              answer_option_index = ?,
              answer_text = ?,
              resolved_by_kind = 'user',
              resolved_at = ?
        WHERE id = ? AND status = 'pending'`).run(a.answer_option_index??null,a.answer_text??null,e,a.id).changes?null:d(a.id)},"cancelQuestion",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare(`UPDATE questions
          SET status = 'cancelled',
              resolved_by_kind = 'user',
              resolved_at = ?
        WHERE id = ? AND status = 'pending'`).run(e,a).changes?null:d(a)},"createQuestion",0,function(a){let e=(0,c.getDb)(),f=(0,b.randomUUID)(),g=new Date().toISOString();return e.prepare(`INSERT INTO questions
       (id, project_slug, agent_id, task_id, prompt, options_json,
        status, answer_option_index, answer_text, resolved_by_kind,
        created_at, resolved_at)
     VALUES (?, ?, ?, ?, ?, ?, 'pending', NULL, NULL, NULL, ?, NULL)`).run(f,a.project_slug,a.agent_id,a.task_id??null,a.prompt,JSON.stringify(a.options??[]),g),d(f)},"getQuestion",0,d,"listQuestionsForTask",0,function(a){return(0,c.getDb)().prepare(`SELECT * FROM questions
        WHERE task_id = ?
        ORDER BY created_at DESC, rowid DESC`).all(a)},"parseQuestionOptions",0,function(a){try{let b=JSON.parse(a.options_json);if(Array.isArray(b)&&b.every(a=>"string"==typeof a))return b}catch{}return[]}])},11040,a=>{a.v(b=>Promise.all(["server/chunks/ssr/src_server_0qqxdxg._.js"].map(b=>a.l(b))).then(()=>b(28151)))}];

//# sourceMappingURL=src_server_0evrgsv._.js.map