core/apps/webapp/app/routes/api.v1.integration_account.tsx
Harshith Mullapudi f39c7cc6d0
feat: remove trigger and run base on bullmq (#126)
* feat: remove trigger and run base on bullmq
* fix: telemetry and trigger deploymen
* feat: add Ollama container and update ingestion status for unchanged documents
* feat: add logger to bullmq workers
* 1. Remove chat and deep-search from trigger
2. Add ai/sdk for chat UI
3. Added a better model manager

* refactor: simplify clustered graph query and add stop conditions for AI responses

* fix: streaming

* fix: docker docs

---------

Co-authored-by: Manoj <saimanoj58@gmail.com>
2025-10-26 12:56:12 +05:30

94 lines
2.8 KiB
TypeScript

import { json } from "@remix-run/node";
import { z } from "zod";
import { createHybridActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { IntegrationEventType } from "@core/types";
import { runIntegrationTrigger } from "~/services/integration.server";
import { getIntegrationDefinitionWithId } from "~/services/integrationDefinition.server";
import { logger } from "~/services/logger.service";
import { getWorkspaceByUser } from "~/models/workspace.server";
import { tasks } from "@trigger.dev/sdk";
import { type scheduler } from "~/trigger/integrations/scheduler";
import { isTriggerDeployment } from "~/lib/queue-adapter.server";
// Schema for creating an integration account with API key
const IntegrationAccountBodySchema = z.object({
integrationDefinitionId: z.string(),
apiKey: z.string(),
});
// Route for creating an integration account directly with an API key
const { action, loader } = createHybridActionApiRoute(
{
body: IntegrationAccountBodySchema,
allowJWT: true,
authorization: {
action: "integrationaccount:create",
},
corsStrategy: "all",
},
async ({ body, authentication }) => {
const { integrationDefinitionId, apiKey } = body;
const { userId } = authentication;
const workspace = await getWorkspaceByUser(authentication.userId);
try {
// Get the integration definition
const integrationDefinition = await getIntegrationDefinitionWithId(
integrationDefinitionId,
);
if (!integrationDefinition) {
return json(
{ error: "Integration definition not found" },
{ status: 404 },
);
}
// Trigger the SETUP event for the integration
const setupResult = await runIntegrationTrigger(
integrationDefinition,
{
event: IntegrationEventType.SETUP,
eventBody: {
apiKey,
},
},
userId,
workspace?.id,
);
if (!setupResult.account || !setupResult.account.id) {
return json(
{ error: "Failed to setup integration with the provided API key" },
{ status: 400 },
);
}
if (!isTriggerDeployment()) {
return json(
{ error: "Integrations don't work in non trigger deployment" },
{ status: 400 },
);
}
await tasks.trigger<typeof scheduler>("scheduler", {
integrationAccountId: setupResult?.account?.id,
});
return json({ success: true, setupResult });
} catch (error) {
logger.error("Error creating integration account", {
error,
userId,
integrationDefinitionId,
});
return json(
{ error: "Failed to create integration account" },
{ status: 500 },
);
}
},
);
export { action, loader };