mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 08:26:22 +02:00
- Store conversations and turns for: - playground chat - api - New DDD code organisation with container dependency injection - sdk update - streaming api support
46 lines
No EOL
1.6 KiB
TypeScript
46 lines
No EOL
1.6 KiB
TypeScript
import { BadRequestError } from "@/src/entities/errors/common";
|
|
import z from "zod";
|
|
import { ICreateConversationUseCase } from "@/src/application/use-cases/conversations/create-conversation.use-case";
|
|
import { Conversation } from "@/src/entities/models/conversation";
|
|
import { Workflow } from "@/app/lib/types/workflow_types";
|
|
|
|
const inputSchema = z.object({
|
|
userId: z.string(),
|
|
projectId: z.string(),
|
|
workflow: Workflow,
|
|
isLiveWorkflow: z.boolean(),
|
|
});
|
|
|
|
export interface ICreatePlaygroundConversationController {
|
|
execute(request: z.infer<typeof inputSchema>): Promise<z.infer<typeof Conversation>>;
|
|
}
|
|
|
|
export class CreatePlaygroundConversationController implements ICreatePlaygroundConversationController {
|
|
private readonly createConversationUseCase: ICreateConversationUseCase;
|
|
|
|
constructor({
|
|
createConversationUseCase,
|
|
}: {
|
|
createConversationUseCase: ICreateConversationUseCase,
|
|
}) {
|
|
this.createConversationUseCase = createConversationUseCase;
|
|
}
|
|
|
|
async execute(request: z.infer<typeof inputSchema>): Promise<z.infer<typeof Conversation>> {
|
|
// parse input
|
|
const result = inputSchema.safeParse(request);
|
|
if (!result.success) {
|
|
throw new BadRequestError(`Invalid request: ${JSON.stringify(result.error)}`);
|
|
}
|
|
const { userId, projectId, workflow, isLiveWorkflow } = result.data;
|
|
|
|
// execute use case
|
|
return await this.createConversationUseCase.execute({
|
|
caller: "user",
|
|
userId,
|
|
projectId,
|
|
workflow,
|
|
isLiveWorkflow,
|
|
});
|
|
}
|
|
} |