Add conversations and turns foundation + DDD (#188)

- Store conversations and turns for:
   - playground chat
   - api
 - New DDD code organisation with container dependency injection
 - sdk update
 - streaming api support
This commit is contained in:
Ramnique Singh 2025-08-05 14:40:48 +05:30 committed by GitHub
parent 659b23ae2b
commit 51a33ab2df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 1474 additions and 525 deletions

View file

@ -1,38 +0,0 @@
'use server';
import { z } from 'zod';
import { getAgenticResponseStreamId } from "../lib/utils";
import { check_query_limit } from "../lib/rate_limiting";
import { QueryLimitError } from "../lib/client_utils";
import { projectAuthCheck } from "./project_actions";
import { authorizeUserAction } from "./billing_actions";
import { Workflow } from "../lib/types/workflow_types";
import { Message } from "@/app/lib/types/types";
export async function getAssistantResponseStreamId(
projectId: string,
workflow: z.infer<typeof Workflow>,
messages: z.infer<typeof Message>[],
): Promise<{ streamId: string } | { billingError: string }> {
await projectAuthCheck(projectId);
if (!await check_query_limit(projectId)) {
throw new QueryLimitError();
}
// Check billing authorization
const agentModels = workflow.agents.reduce((acc, agent) => {
acc.push(agent.model);
return acc;
}, [] as string[]);
const { success, error } = await authorizeUserAction({
type: 'agent_response',
data: {
agentModels,
},
});
if (!success) {
return { billingError: error || 'Billing error' };
}
const response = await getAgenticResponseStreamId(projectId, workflow, messages);
return response;
}

View file

@ -8,7 +8,7 @@ import {
import { DataSource } from "../lib/types/datasource_types";
import { z } from 'zod';
import { check_query_limit } from "../lib/rate_limiting";
import { QueryLimitError } from "../lib/client_utils";
import { QueryLimitError } from "@/src/entities/errors/common";
import { projectAuthCheck } from "./project_actions";
import { redisClient } from "../lib/redis";
import { authorizeUserAction, logUsage } from "./billing_actions";

View file

@ -0,0 +1,54 @@
'use server';
import { z } from 'zod';
import { Workflow } from "../lib/types/workflow_types";
import { Message } from "@/app/lib/types/types";
import { authCheck } from './auth_actions';
import { container } from '@/di/container';
import { Conversation } from '@/src/entities/models/conversation';
import { ICreatePlaygroundConversationController } from '@/src/interface-adapters/controllers/conversations/create-playground-conversation.controller';
import { ICreateCachedTurnController } from '@/src/interface-adapters/controllers/conversations/create-cached-turn.controller';
export async function createConversation({
projectId,
workflow,
isLiveWorkflow,
}: {
projectId: string;
workflow: z.infer<typeof Workflow>;
isLiveWorkflow: boolean;
}): Promise<z.infer<typeof Conversation>> {
const user = await authCheck();
const controller = container.resolve<ICreatePlaygroundConversationController>("createPlaygroundConversationController");
return await controller.execute({
userId: user._id,
projectId,
workflow,
isLiveWorkflow,
});
}
export async function createCachedTurn({
conversationId,
messages,
}: {
conversationId: string;
messages: z.infer<typeof Message>[];
}): Promise<{ key: string }> {
const user = await authCheck();
const createCachedTurnController = container.resolve<ICreateCachedTurnController>("createCachedTurnController");
const { key } = await createCachedTurnController.execute({
caller: "user",
userId: user._id,
conversationId,
input: {
messages,
},
});
return {
key,
};
}