mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 02:20:38 +09:00
Add routines automation workflows
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
7a652b8998
commit
8f5196f7d6
35 changed files with 25977 additions and 5 deletions
|
|
@ -22,7 +22,14 @@ export interface IssueForRun {
|
|||
}
|
||||
|
||||
export const activityApi = {
|
||||
list: (companyId: string) => api.get<ActivityEvent[]>(`/companies/${companyId}/activity`),
|
||||
list: (companyId: string, filters?: { entityType?: string; entityId?: string; agentId?: string }) => {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.entityType) params.set("entityType", filters.entityType);
|
||||
if (filters?.entityId) params.set("entityId", filters.entityId);
|
||||
if (filters?.agentId) params.set("agentId", filters.agentId);
|
||||
const qs = params.toString();
|
||||
return api.get<ActivityEvent[]>(`/companies/${companyId}/activity${qs ? `?${qs}` : ""}`);
|
||||
},
|
||||
forIssue: (issueId: string) => api.get<ActivityEvent[]>(`/issues/${issueId}/activity`),
|
||||
runsForIssue: (issueId: string) => api.get<RunForIssue[]>(`/issues/${issueId}/runs`),
|
||||
issuesForRun: (runId: string) => api.get<IssueForRun[]>(`/heartbeat-runs/${runId}/issues`),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ export { companiesApi } from "./companies";
|
|||
export { agentsApi } from "./agents";
|
||||
export { projectsApi } from "./projects";
|
||||
export { issuesApi } from "./issues";
|
||||
export { routinesApi } from "./routines";
|
||||
export { goalsApi } from "./goals";
|
||||
export { approvalsApi } from "./approvals";
|
||||
export { costsApi } from "./costs";
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ export const issuesApi = {
|
|||
touchedByUserId?: string;
|
||||
unreadForUserId?: string;
|
||||
labelId?: string;
|
||||
originKind?: string;
|
||||
originId?: string;
|
||||
includeRoutineExecutions?: boolean;
|
||||
q?: string;
|
||||
},
|
||||
) => {
|
||||
|
|
@ -33,6 +36,9 @@ export const issuesApi = {
|
|||
if (filters?.touchedByUserId) params.set("touchedByUserId", filters.touchedByUserId);
|
||||
if (filters?.unreadForUserId) params.set("unreadForUserId", filters.unreadForUserId);
|
||||
if (filters?.labelId) params.set("labelId", filters.labelId);
|
||||
if (filters?.originKind) params.set("originKind", filters.originKind);
|
||||
if (filters?.originId) params.set("originId", filters.originId);
|
||||
if (filters?.includeRoutineExecutions) params.set("includeRoutineExecutions", "true");
|
||||
if (filters?.q) params.set("q", filters.q);
|
||||
const qs = params.toString();
|
||||
return api.get<Issue[]>(`/companies/${companyId}/issues${qs ? `?${qs}` : ""}`);
|
||||
|
|
|
|||
57
ui/src/api/routines.ts
Normal file
57
ui/src/api/routines.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import type {
|
||||
ActivityEvent,
|
||||
Routine,
|
||||
RoutineDetail,
|
||||
RoutineListItem,
|
||||
RoutineRun,
|
||||
RoutineRunSummary,
|
||||
RoutineTrigger,
|
||||
RoutineTriggerSecretMaterial,
|
||||
} from "@paperclipai/shared";
|
||||
import { activityApi } from "./activity";
|
||||
import { api } from "./client";
|
||||
|
||||
export interface RoutineTriggerResponse {
|
||||
trigger: RoutineTrigger;
|
||||
secretMaterial: RoutineTriggerSecretMaterial | null;
|
||||
}
|
||||
|
||||
export interface RotateRoutineTriggerResponse {
|
||||
trigger: RoutineTrigger;
|
||||
secretMaterial: RoutineTriggerSecretMaterial;
|
||||
}
|
||||
|
||||
export const routinesApi = {
|
||||
list: (companyId: string) => api.get<RoutineListItem[]>(`/companies/${companyId}/routines`),
|
||||
create: (companyId: string, data: Record<string, unknown>) =>
|
||||
api.post<Routine>(`/companies/${companyId}/routines`, data),
|
||||
get: (id: string) => api.get<RoutineDetail>(`/routines/${id}`),
|
||||
update: (id: string, data: Record<string, unknown>) => api.patch<Routine>(`/routines/${id}`, data),
|
||||
listRuns: (id: string, limit: number = 50) => api.get<RoutineRunSummary[]>(`/routines/${id}/runs?limit=${limit}`),
|
||||
createTrigger: (id: string, data: Record<string, unknown>) =>
|
||||
api.post<RoutineTriggerResponse>(`/routines/${id}/triggers`, data),
|
||||
updateTrigger: (id: string, data: Record<string, unknown>) =>
|
||||
api.patch<RoutineTrigger>(`/routine-triggers/${id}`, data),
|
||||
rotateTriggerSecret: (id: string) =>
|
||||
api.post<RotateRoutineTriggerResponse>(`/routine-triggers/${id}/rotate-secret`, {}),
|
||||
run: (id: string, data?: Record<string, unknown>) =>
|
||||
api.post<RoutineRun>(`/routines/${id}/run`, data ?? {}),
|
||||
activity: async (
|
||||
companyId: string,
|
||||
routineId: string,
|
||||
related?: { triggerIds?: string[]; runIds?: string[] },
|
||||
) => {
|
||||
const requests = [
|
||||
activityApi.list(companyId, { entityType: "routine", entityId: routineId }),
|
||||
...(related?.triggerIds ?? []).map((triggerId) =>
|
||||
activityApi.list(companyId, { entityType: "routine_trigger", entityId: triggerId })),
|
||||
...(related?.runIds ?? []).map((runId) =>
|
||||
activityApi.list(companyId, { entityType: "routine_run", entityId: runId })),
|
||||
];
|
||||
const events = (await Promise.all(requests)).flat();
|
||||
const deduped = new Map(events.map((event) => [event.id, event]));
|
||||
return [...deduped.values()].sort(
|
||||
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
|
||||
);
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue