mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 10:50: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
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