mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Agent management: hire endpoint with permission gates and pending_approval status, config revision tracking with rollback, agent duplicate route, permission CRUD. Block pending_approval agents from auth, heartbeat, and assignments. Approvals: revision request/resubmit flow, approval comments CRUD, issue-approval linking, auto-wake agents on approval decisions with context snapshot. Costs: per-agent breakdown, period filtering (month/week/day/all), cost by agent list endpoint. Adapters: agentConfigurationDoc on all adapters, /llms/agent-configuration.txt reflection routes. Inject PAPERCLIP_APPROVAL_ID, PAPERCLIP_APPROVAL_STATUS, PAPERCLIP_LINKED_ISSUE_IDS into adapter environments. Sidebar badges endpoint for pending approval/inbox counts. Dashboard and company settings extensions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
936 B
TypeScript
29 lines
936 B
TypeScript
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
import type { Db } from "@paperclip/db";
|
|
import { approvals } from "@paperclip/db";
|
|
import type { SidebarBadges } from "@paperclip/shared";
|
|
|
|
const ACTIONABLE_APPROVAL_STATUSES = ["pending", "revision_requested"];
|
|
|
|
export function sidebarBadgeService(db: Db) {
|
|
return {
|
|
get: async (companyId: string): Promise<SidebarBadges> => {
|
|
const actionableApprovals = await db
|
|
.select({ count: sql<number>`count(*)` })
|
|
.from(approvals)
|
|
.where(
|
|
and(
|
|
eq(approvals.companyId, companyId),
|
|
inArray(approvals.status, ACTIONABLE_APPROVAL_STATUSES),
|
|
),
|
|
)
|
|
.then((rows) => Number(rows[0]?.count ?? 0));
|
|
|
|
return {
|
|
// Inbox currently mirrors actionable approvals; expand as inbox categories grow.
|
|
inbox: actionableApprovals,
|
|
approvals: actionableApprovals,
|
|
};
|
|
},
|
|
};
|
|
}
|