All files / shared/src/types/data improved-response.ts

100% Statements 60/60
100% Branches 3/3
100% Functions 1/1
100% Lines 60/60

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x                          
import { v4 as uuidv4 } from 'uuid';
import { z } from 'zod';
 
// Define Zod schemas for validation
export const ImprovedResponse = z
  .object({
    id: z.string().uuid(),
    agent_id: z.string().uuid(),
    skill_id: z.string().uuid(),
    log_id: z.string().uuid(),
    original_response_body: z.record(z.string(), z.unknown()),
    improved_response_body: z.record(z.string(), z.unknown()),
    created_at: z.string().datetime({ offset: true }),
    updated_at: z.string().datetime({ offset: true }),
  })
  .strict();
 
// Input schema for creating an improved response
export const ImprovedResponseCreateParams = z
  .object({
    agent_id: z.string().uuid(),
    skill_id: z.string().uuid(),
    log_id: z.string().uuid(),
    original_response_body: z.record(z.string(), z.unknown()),
    improved_response_body: z.record(z.string(), z.unknown()),
  })
  .strict()
  .transform((data) => {
    const timestamp = new Date().toISOString();
    return {
      ...data,
      id: uuidv4(),
      created_at: timestamp,
      updated_at: timestamp,
    };
  });
 
// Query parameters schema for the combined GET endpoint
export const ImprovedResponseQueryParams = z
  .object({
    id: z.string().uuid().optional(),
    agent_id: z.string().uuid().optional(),
    skill_id: z.string().uuid().optional(),
    log_id: z.string().uuid().optional(),
    limit: z.coerce.number().int().positive().optional(),
    offset: z.coerce.number().int().min(0).optional(),
  })
  .strict();
 
// Input schema for updating an improved response
export const ImprovedResponseUpdateParams = z
  .object({
    improved_response_body: z.record(z.string(), z.unknown()).optional(),
  })
  .strict()
  .refine(
    (data) =>
      Object.keys(data).length > 0 && data.improved_response_body !== undefined,
    {
      message: 'At least one field must be provided for update',
      path: ['improved_response_body'],
    },
  );
 
// Query params for DELETE operations
export const ImprovedResponseIdQueryParams = z
  .object({
    id: z.string().uuid(),
  })
  .strict();
 
// Define the types based on the schemas
export type ImprovedResponse = z.infer<typeof ImprovedResponse>;
export type ImprovedResponseUpdateParams = z.infer<
  typeof ImprovedResponseUpdateParams
>;
export type ImprovedResponseQueryParams = z.infer<
  typeof ImprovedResponseQueryParams
>;
export type ImprovedResponseIdQueryParams = z.infer<
  typeof ImprovedResponseIdQueryParams
>;