add composio triggers (#192)

This commit is contained in:
Ramnique Singh 2025-08-08 02:27:42 +05:30 committed by GitHub
parent 5e706f0684
commit 3552302f4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
72 changed files with 4887 additions and 111 deletions

View file

@ -22,6 +22,19 @@ import {
import { ComposioConnectedAccount } from "@/app/lib/types/project_types";
import { getProjectConfig, projectAuthCheck } from "./project_actions";
import { projectsCollection } from "../lib/mongodb";
import { container } from "@/di/container";
import { ICreateComposioTriggerDeploymentController } from "@/src/interface-adapters/controllers/composio-trigger-deployments/create-composio-trigger-deployment.controller";
import { IListComposioTriggerDeploymentsController } from "@/src/interface-adapters/controllers/composio-trigger-deployments/list-composio-trigger-deployments.controller";
import { IDeleteComposioTriggerDeploymentController } from "@/src/interface-adapters/controllers/composio-trigger-deployments/delete-composio-trigger-deployment.controller";
import { IListComposioTriggerTypesController } from "@/src/interface-adapters/controllers/composio-trigger-deployments/list-composio-trigger-types.controller";
import { IDeleteComposioConnectedAccountController } from "@/src/interface-adapters/controllers/composio/delete-composio-connected-account.controller";
import { authCheck } from "./auth_actions";
const createComposioTriggerDeploymentController = container.resolve<ICreateComposioTriggerDeploymentController>("createComposioTriggerDeploymentController");
const listComposioTriggerDeploymentsController = container.resolve<IListComposioTriggerDeploymentsController>("listComposioTriggerDeploymentsController");
const deleteComposioTriggerDeploymentController = container.resolve<IDeleteComposioTriggerDeploymentController>("deleteComposioTriggerDeploymentController");
const listComposioTriggerTypesController = container.resolve<IListComposioTriggerTypesController>("listComposioTriggerTypesController");
const deleteComposioConnectedAccountController = container.resolve<IDeleteComposioConnectedAccountController>("deleteComposioConnectedAccountController");
const ZCreateCustomConnectedAccountRequest = z.object({
toolkitSlug: z.string(),
@ -191,29 +204,77 @@ export async function syncConnectedAccount(projectId: string, toolkitSlug: strin
}
export async function deleteConnectedAccount(projectId: string, toolkitSlug: string, connectedAccountId: string): Promise<boolean> {
await projectAuthCheck(projectId);
const user = await authCheck();
// ensure that the connected account belongs to this project
const project = await getProjectConfig(projectId);
const account = project.composioConnectedAccounts?.[toolkitSlug];
if (!account || account.id !== connectedAccountId) {
throw new Error(`Connected account ${connectedAccountId} not found in project ${projectId} for toolkit ${toolkitSlug}`);
}
// delete the connected account
await libDeleteConnectedAccount(connectedAccountId);
// get auth config data
const authConfig = await libGetAuthConfig(account.authConfigId);
// delete the auth config if it is NOT managed by composio
if (!authConfig.is_composio_managed) {
await libDeleteAuthConfig(account.authConfigId);
}
// update project with deleted connected account
const key = `composioConnectedAccounts.${toolkitSlug}`;
await projectsCollection.updateOne({ _id: projectId }, { $unset: { [key]: "" } });
await deleteComposioConnectedAccountController.execute({
caller: 'user',
userId: user._id,
projectId,
toolkitSlug,
connectedAccountId,
});
return true;
}
export async function listComposioTriggerTypes(toolkitSlug: string, cursor?: string) {
await authCheck();
return await listComposioTriggerTypesController.execute({
toolkitSlug,
cursor,
});
}
export async function createComposioTriggerDeployment(request: {
projectId: string,
toolkitSlug: string,
triggerTypeSlug: string,
connectedAccountId: string,
triggerConfig?: Record<string, unknown>,
}) {
const user = await authCheck();
// create trigger deployment
return await createComposioTriggerDeploymentController.execute({
caller: 'user',
userId: user._id,
data: {
projectId: request.projectId,
toolkitSlug: request.toolkitSlug,
triggerTypeSlug: request.triggerTypeSlug,
connectedAccountId: request.connectedAccountId,
triggerConfig: request.triggerConfig ?? {},
},
});
}
export async function listComposioTriggerDeployments(request: {
projectId: string,
cursor?: string,
}) {
const user = await authCheck();
// list trigger deployments
return await listComposioTriggerDeploymentsController.execute({
caller: 'user',
userId: user._id,
projectId: request.projectId,
cursor: request.cursor,
});
}
export async function deleteComposioTriggerDeployment(request: {
projectId: string,
deploymentId: string,
}) {
const user = await authCheck();
// delete trigger deployment
return await deleteComposioTriggerDeploymentController.execute({
caller: 'user',
userId: user._id,
projectId: request.projectId,
deploymentId: request.deploymentId,
});
}

View file

@ -0,0 +1,37 @@
"use server";
import { container } from "@/di/container";
import { IListConversationsController } from "@/src/interface-adapters/controllers/conversations/list-conversations.controller";
import { IFetchConversationController } from "@/src/interface-adapters/controllers/conversations/fetch-conversation.controller";
import { authCheck } from "./auth_actions";
const listConversationsController = container.resolve<IListConversationsController>('listConversationsController');
const fetchConversationController = container.resolve<IFetchConversationController>('fetchConversationController');
export async function listConversations(request: {
projectId: string,
cursor?: string,
limit?: number,
}) {
const user = await authCheck();
return await listConversationsController.execute({
caller: 'user',
userId: user._id,
projectId: request.projectId,
cursor: request.cursor,
limit: request.limit,
});
}
export async function fetchConversation(request: {
conversationId: string,
}) {
const user = await authCheck();
return await fetchConversationController.execute({
caller: 'user',
userId: user._id,
conversationId: request.conversationId,
});
}

View file

@ -0,0 +1,37 @@
"use server";
import { container } from "@/di/container";
import { IListJobsController } from "@/src/interface-adapters/controllers/jobs/list-jobs.controller";
import { IFetchJobController } from "@/src/interface-adapters/controllers/jobs/fetch-job.controller";
import { authCheck } from "./auth_actions";
const listJobsController = container.resolve<IListJobsController>('listJobsController');
const fetchJobController = container.resolve<IFetchJobController>('fetchJobController');
export async function listJobs(request: {
projectId: string,
cursor?: string,
limit?: number,
}) {
const user = await authCheck();
return await listJobsController.execute({
caller: 'user',
userId: user._id,
projectId: request.projectId,
cursor: request.cursor,
limit: request.limit,
});
}
export async function fetchJob(request: {
jobId: string,
}) {
const user = await authCheck();
return await fetchJobController.execute({
caller: 'user',
userId: user._id,
jobId: request.jobId,
});
}