mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-08 06:42:39 +02:00
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:
parent
659b23ae2b
commit
51a33ab2df
39 changed files with 1474 additions and 525 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
54
apps/rowboat/app/actions/playground-chat.actions.ts
Normal file
54
apps/rowboat/app/actions/playground-chat.actions.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue