feat: add agent task schema and CRUD API (closes #96, closes #97)

This commit is contained in:
Jason Woltje
2026-01-29 23:26:22 -06:00
parent 59aec28d5c
commit da4fb72902
13 changed files with 2534 additions and 4 deletions

View File

@@ -0,0 +1,48 @@
import { AgentTaskStatus, AgentTaskPriority } from "@prisma/client";
import {
IsString,
IsOptional,
IsEnum,
IsObject,
MinLength,
MaxLength,
} from "class-validator";
/**
* DTO for creating a new agent task
*/
export class CreateAgentTaskDto {
@IsString({ message: "title must be a string" })
@MinLength(1, { message: "title must not be empty" })
@MaxLength(255, { message: "title must not exceed 255 characters" })
title!: string;
@IsOptional()
@IsString({ message: "description must be a string" })
@MaxLength(10000, { message: "description must not exceed 10000 characters" })
description?: string;
@IsOptional()
@IsEnum(AgentTaskStatus, { message: "status must be a valid AgentTaskStatus" })
status?: AgentTaskStatus;
@IsOptional()
@IsEnum(AgentTaskPriority, { message: "priority must be a valid AgentTaskPriority" })
priority?: AgentTaskPriority;
@IsString({ message: "agentType must be a string" })
@MinLength(1, { message: "agentType must not be empty" })
agentType!: string;
@IsOptional()
@IsObject({ message: "agentConfig must be an object" })
agentConfig?: Record<string, unknown>;
@IsOptional()
@IsObject({ message: "result must be an object" })
result?: Record<string, unknown>;
@IsOptional()
@IsString({ message: "error must be a string" })
error?: string;
}

View File

@@ -0,0 +1,3 @@
export * from "./create-agent-task.dto";
export * from "./update-agent-task.dto";
export * from "./query-agent-tasks.dto";

View File

@@ -0,0 +1,48 @@
import { AgentTaskStatus, AgentTaskPriority } from "@prisma/client";
import {
IsOptional,
IsEnum,
IsInt,
Min,
Max,
IsString,
IsUUID,
} from "class-validator";
import { Type } from "class-transformer";
/**
* DTO for querying agent tasks with pagination and filters
*/
export class QueryAgentTasksDto {
@IsOptional()
@Type(() => Number)
@IsInt({ message: "page must be an integer" })
@Min(1, { message: "page must be at least 1" })
page?: number;
@IsOptional()
@Type(() => Number)
@IsInt({ message: "limit must be an integer" })
@Min(1, { message: "limit must be at least 1" })
@Max(100, { message: "limit must not exceed 100" })
limit?: number;
@IsOptional()
@IsEnum(AgentTaskStatus, { message: "status must be a valid AgentTaskStatus" })
status?: AgentTaskStatus;
@IsOptional()
@IsEnum(AgentTaskPriority, { message: "priority must be a valid AgentTaskPriority" })
priority?: AgentTaskPriority;
@IsOptional()
@IsString({ message: "agentType must be a string" })
agentType?: string;
@IsOptional()
@IsUUID("4", { message: "createdById must be a valid UUID" })
createdById?: string;
// Internal field set by controller/guard
workspaceId?: string;
}

View File

@@ -0,0 +1,51 @@
import { AgentTaskStatus, AgentTaskPriority } from "@prisma/client";
import {
IsString,
IsOptional,
IsEnum,
IsObject,
MinLength,
MaxLength,
} from "class-validator";
/**
* DTO for updating an existing agent task
* All fields are optional to support partial updates
*/
export class UpdateAgentTaskDto {
@IsOptional()
@IsString({ message: "title must be a string" })
@MinLength(1, { message: "title must not be empty" })
@MaxLength(255, { message: "title must not exceed 255 characters" })
title?: string;
@IsOptional()
@IsString({ message: "description must be a string" })
@MaxLength(10000, { message: "description must not exceed 10000 characters" })
description?: string | null;
@IsOptional()
@IsEnum(AgentTaskStatus, { message: "status must be a valid AgentTaskStatus" })
status?: AgentTaskStatus;
@IsOptional()
@IsEnum(AgentTaskPriority, { message: "priority must be a valid AgentTaskPriority" })
priority?: AgentTaskPriority;
@IsOptional()
@IsString({ message: "agentType must be a string" })
@MinLength(1, { message: "agentType must not be empty" })
agentType?: string;
@IsOptional()
@IsObject({ message: "agentConfig must be an object" })
agentConfig?: Record<string, unknown>;
@IsOptional()
@IsObject({ message: "result must be an object" })
result?: Record<string, unknown> | null;
@IsOptional()
@IsString({ message: "error must be a string" })
error?: string | null;
}