mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-11 02:46:45 +08:00
* feat: add issue event and time wakeups (MUL-7418) Co-authored-by: multica-agent <[email protected]> * feat(wakeups): capture issue collaboration event lifecycle Co-authored-by: multica-agent <[email protected]> * fix(wakeups): preserve reply source when reopening threads Co-authored-by: multica-agent <[email protected]> * feat(wakeups): summarize sidebar and issue activity cues Co-authored-by: multica-agent <[email protected]> * fix(wakeups): restore disabled configurations with a two-way toggle Co-authored-by: multica-agent <[email protected]> * feat(wakeups): manage workspace wakeups in Autopilot Co-authored-by: multica-agent <[email protected]> * chore(wakeups): reserve migrations after current main Co-authored-by: multica-agent <[email protected]> * test(wakeups): align inventory fixtures with shared contracts Co-authored-by: multica-agent <[email protected]> * fix(wakeups): distinguish trigger conditions and execution results Co-authored-by: multica-agent <[email protected]> * fix(wakeups): suppress registration feedback and drain bounded evidence Co-authored-by: multica-agent <[email protected]> * fix(wakeups): align sidebar actions with titles Co-authored-by: multica-agent <[email protected]> * fix(wakeups): bound database work and unify shared issue visibility Co-authored-by: multica-agent <[email protected]> * feat(wakeups): filter mutation events by member or agent actor Co-authored-by: multica-agent <[email protected]> * refactor(wakeups): merge structured evidence and narrow receipt locks Co-authored-by: multica-agent <[email protected]> * feat(wakeups): let people edit wakeup instructions Co-authored-by: multica-agent <[email protected]> * fix(wakeups): align inventory controls and compact prompt editing Co-authored-by: multica-agent <[email protected]> * fix(mobile): handle deferred agent run status Co-authored-by: multica-agent <[email protected]> --------- Co-authored-by: Lambda <[email protected]> Co-authored-by: multica-agent <[email protected]>
116 lines
7.7 KiB
Go
116 lines
7.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: workspace_wakeup.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const listWorkspaceWakeups = `-- name: ListWorkspaceWakeups :one
|
|
WITH base AS MATERIALIZED (
|
|
SELECT w.id,w.issue_id,i.title AS issue_title,ws.issue_prefix||'-'||i.number AS issue_identifier,
|
|
w.agent_id,a.name AS agent_name,w.kind,w.mode,w.event_types,w.filter_actor_type,
|
|
(CASE WHEN actor_agent.id IS NOT NULL OR actor_member.user_id IS NOT NULL THEN w.filter_actor_id END)::uuid AS filter_actor_id,
|
|
COALESCE(actor_agent.name,actor_user.name,'')::text AS filter_actor_name,
|
|
CASE WHEN source.id IS NOT NULL THEN w.filter_agent_id END AS filter_agent_id,
|
|
source.name AS filter_agent_name,
|
|
CASE WHEN EXISTS(SELECT 1 FROM agent_task_queue ft JOIN agent fa ON fa.id=ft.agent_id AND fa.workspace_id=w.workspace_id
|
|
WHERE ft.id=w.filter_task_id AND ft.issue_id=w.issue_id AND fa.id=ANY($1::uuid[])) THEN w.filter_task_id END AS filter_task_id,
|
|
w.interval_seconds,w.cron_expression,w.timezone,
|
|
w.next_fire_at,w.enabled,w.revision,w.disabled_at,w.last_task_id,w.last_error,w.created_at,
|
|
(i.status IN ('done','cancelled') OR EXISTS(SELECT 1 FROM issue_status s WHERE s.workspace_id=i.workspace_id AND s.key=i.status AND s.category IN ('done','closed'))) AS issue_closed,
|
|
COALESCE((w.created_by= $2::uuid OR $3::boolean),false) AS can_manage,
|
|
COALESCE(r.active_runs,0)::int AS active_runs
|
|
FROM issue_wakeup w
|
|
JOIN workspace ws ON ws.id=w.workspace_id
|
|
JOIN issue i ON i.id=w.issue_id AND i.workspace_id=w.workspace_id
|
|
JOIN agent a ON a.id=w.agent_id AND a.workspace_id=w.workspace_id
|
|
LEFT JOIN agent actor_agent ON w.filter_actor_type='agent' AND actor_agent.id=w.filter_actor_id AND actor_agent.workspace_id=w.workspace_id AND actor_agent.id=ANY($1::uuid[])
|
|
LEFT JOIN member actor_member ON w.filter_actor_type='member' AND actor_member.user_id=w.filter_actor_id AND actor_member.workspace_id=w.workspace_id
|
|
LEFT JOIN "user" actor_user ON actor_user.id=actor_member.user_id
|
|
LEFT JOIN agent source ON source.id=w.filter_agent_id AND source.workspace_id=w.workspace_id AND source.id=ANY($1::uuid[])
|
|
LEFT JOIN LATERAL (
|
|
SELECT count(*) AS active_runs FROM agent_task_queue t
|
|
WHERE t.context->>'wakeup_id'=w.id::text AND t.issue_id=w.issue_id AND t.agent_id=w.agent_id
|
|
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
|
|
) r ON true
|
|
WHERE w.workspace_id= $4
|
|
), classified AS (
|
|
SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, issue_closed, can_manage, active_runs,CASE WHEN (enabled AND NOT issue_closed) OR active_runs>0 THEN 'active'
|
|
WHEN NOT issue_closed AND disabled_at IS NOT NULL THEN 'disabled' ELSE 'ended' END AS scope
|
|
FROM base
|
|
), filtered AS (
|
|
SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, issue_closed, can_manage, active_runs, scope FROM classified WHERE ($5::text='all' OR scope= $5)
|
|
AND ($6::text='all' OR ($6='event' AND kind='event') OR ($6='at' AND kind='at') OR ($6='recurring' AND kind IN ('every','cron')))
|
|
AND ($7::text='' OR agent_id::text= $7)
|
|
AND ($8::text='' OR strpos(lower(issue_title||' '||issue_identifier||' '||agent_name),lower($8))>0)
|
|
), page AS (
|
|
SELECT id, issue_id, issue_title, issue_identifier, agent_id, agent_name, kind, mode, event_types, filter_actor_type, filter_actor_id, filter_actor_name, filter_agent_id, filter_agent_name, filter_task_id, interval_seconds, cron_expression, timezone, next_fire_at, enabled, revision, disabled_at, last_task_id, last_error, created_at, issue_closed, can_manage, active_runs, scope FROM filtered ORDER BY created_at DESC,id DESC LIMIT $10::int OFFSET $9::int
|
|
), details AS (
|
|
SELECT p.id, p.issue_id, p.issue_title, p.issue_identifier, p.agent_id, p.agent_name, p.kind, p.mode, p.event_types, p.filter_actor_type, p.filter_actor_id, p.filter_actor_name, p.filter_agent_id, p.filter_agent_name, p.filter_task_id, p.interval_seconds, p.cron_expression, p.timezone, p.next_fire_at, p.enabled, p.revision, p.disabled_at, p.last_task_id, p.last_error, p.created_at, p.issue_closed, p.can_manage, p.active_runs, p.scope,r.status AS last_task_status,
|
|
CASE WHEN r.id IS NOT NULL THEN jsonb_build_object(
|
|
'id',r.id,'agent_id',r.agent_id,'runtime_id',r.runtime_id,'issue_id',r.issue_id,'wakeup_id',p.id,
|
|
'status',r.status,'priority',r.priority,'created_at',r.created_at,'started_at',r.started_at,
|
|
'dispatched_at',r.dispatched_at,'completed_at',r.completed_at
|
|
) END AS task
|
|
FROM page p
|
|
LEFT JOIN LATERAL (
|
|
SELECT candidate.id, candidate.agent_id, candidate.runtime_id, candidate.issue_id, candidate.status, candidate.priority, candidate.created_at, candidate.started_at, candidate.dispatched_at, candidate.completed_at, candidate.active FROM (
|
|
(SELECT t.id,t.agent_id,t.runtime_id,t.issue_id,t.status,t.priority,t.created_at,t.started_at,t.dispatched_at,t.completed_at,1 AS active
|
|
FROM agent_task_queue t WHERE t.context->>'wakeup_id'=p.id::text AND t.issue_id=p.issue_id AND t.agent_id=p.agent_id
|
|
AND t.status IN ('queued','deferred','dispatched','running','waiting_local_directory')
|
|
ORDER BY (t.status IN ('running','waiting_local_directory','dispatched')) DESC,t.created_at DESC,t.id DESC LIMIT 1)
|
|
UNION ALL
|
|
(SELECT t.id,t.agent_id,t.runtime_id,t.issue_id,t.status,t.priority,t.created_at,t.started_at,t.dispatched_at,t.completed_at,0 AS active
|
|
FROM agent_task_queue t WHERE t.context->>'wakeup_id'=p.id::text AND t.issue_id=p.issue_id AND t.agent_id=p.agent_id
|
|
AND t.status NOT IN ('queued','deferred','dispatched','running','waiting_local_directory')
|
|
ORDER BY t.created_at DESC,t.id DESC LIMIT 1)
|
|
) candidate ORDER BY active DESC LIMIT 1
|
|
) r ON true
|
|
)
|
|
SELECT jsonb_build_object(
|
|
'items',COALESCE((SELECT jsonb_agg(to_jsonb(details)-'created_at'-'scope' ORDER BY created_at DESC,id DESC) FROM details),'[]'::jsonb),
|
|
'total',(SELECT count(*) FROM filtered),
|
|
'counts',jsonb_build_object('all',(SELECT count(*) FROM classified),'active',(SELECT count(*) FROM classified WHERE scope='active'),
|
|
'disabled',(SELECT count(*) FROM classified WHERE scope='disabled'),'ended',(SELECT count(*) FROM classified WHERE scope='ended')),
|
|
'agents',COALESCE((SELECT jsonb_agg(x ORDER BY x.name,x.id) FROM (SELECT DISTINCT agent_id AS id,agent_name AS name FROM base) x),'[]'::jsonb)
|
|
) AS result
|
|
`
|
|
|
|
type ListWorkspaceWakeupsParams struct {
|
|
AgentIds []pgtype.UUID `json:"agent_ids"`
|
|
MemberID pgtype.UUID `json:"member_id"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
Scope string `json:"scope"`
|
|
Kind string `json:"kind"`
|
|
AgentID string `json:"agent_id"`
|
|
Search string `json:"search"`
|
|
PageOffset int32 `json:"page_offset"`
|
|
PageLimit int32 `json:"page_limit"`
|
|
}
|
|
|
|
// Counts, filter choices, and page share one snapshot and the same access scope.
|
|
func (q *Queries) ListWorkspaceWakeups(ctx context.Context, arg ListWorkspaceWakeupsParams) ([]byte, error) {
|
|
row := q.db.QueryRow(ctx, listWorkspaceWakeups,
|
|
arg.AgentIds,
|
|
arg.MemberID,
|
|
arg.IsAdmin,
|
|
arg.WorkspaceID,
|
|
arg.Scope,
|
|
arg.Kind,
|
|
arg.AgentID,
|
|
arg.Search,
|
|
arg.PageOffset,
|
|
arg.PageLimit,
|
|
)
|
|
var result []byte
|
|
err := row.Scan(&result)
|
|
return result, err
|
|
}
|