All files / shared/src/types/data skill-optimization-cluster.ts

100% Statements 47/47
100% Branches 0/0
100% Functions 0/0
100% Lines 47/47

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 83 84 85 86 87 88 89 90 91 92 93 94 951x             1x 1x 1x 1x     1x               1x           1x         1x     1x       1x   1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x          
import { z } from 'zod';
 
/** An optimization cluster.
 *
 * A skill optimization cluster is a group of logs that have similar
 * semantic meaning.
 */
export const SkillOptimizationCluster = z.object({
  id: z.uuid(),
  agent_id: z.uuid(),
  skill_id: z.uuid(),
 
  /** An auto-generated name for the cluster. */
  name: z.string(),
 
  /**
   * The total number of requests that have been processed by the algorithm
   * in this cluster since the last optimization cycle.
   * This counter resets to 0 during reflection and evaluation regeneration.
   * Used by Thompson Sampling algorithm to decide when to trigger optimization.
   */
  total_steps: z.number().min(0),
 
  /**
   * The total number of requests routed to this cluster for observability.
   * This counter never resets and provides historical tracking of cluster usage.
   */
  observability_total_requests: z.number().min(0),
 
  /** An array representing the center of the cluster of the logs in
   * n-dimensional space.
   */
  centroid: z.array(z.number()),
 
  /** The embedding model used for computing centroids in this cluster. */
  embedding_model_id: z.uuid().nullable(),
 
  /** Lock timestamp to prevent concurrent system prompt reflection for this cluster.
   * If set and recent (< 10 minutes old), reflection is in progress. */
  reflection_lock_acquired_at: z.iso.datetime({ offset: true }).nullable(),
 
  created_at: z.iso.datetime({ offset: true }),
  updated_at: z.iso.datetime({ offset: true }),
});
export type SkillOptimizationCluster = z.infer<typeof SkillOptimizationCluster>;
 
export const SkillOptimizationClusterQueryParams = z
  .object({
    id: z.uuid().optional(),
    agent_id: z.uuid().optional(),
    skill_id: z.uuid().optional(),
    name: z.string().optional(),
    limit: z.coerce.number().int().positive().optional(),
    offset: z.coerce.number().int().min(0).optional(),
  })
  .strict();
 
export type SkillOptimizationClusterQueryParams = z.infer<
  typeof SkillOptimizationClusterQueryParams
>;
 
export const SkillOptimizationClusterCreateParams = z
  .object({
    agent_id: z.uuid(),
    skill_id: z.uuid(),
    name: z.string(),
    total_steps: z.number().min(0),
    observability_total_requests: z.number().min(0).default(0),
    centroid: z.array(z.number()),
    embedding_model_id: z.uuid().nullable().optional(),
  })
  .strict();
 
export type SkillOptimizationClusterCreateParams = z.infer<
  typeof SkillOptimizationClusterCreateParams
>;
 
// Name is an auto-generated constant defined at creation time
export const SkillOptimizationClusterUpdateParams = z
  .object({
    total_steps: z.number().min(0).optional(),
    observability_total_requests: z.number().min(0).optional(),
    centroid: z.array(z.number()).optional(),
    embedding_model_id: z.uuid().nullable().optional(),
    reflection_lock_acquired_at: z.iso
      .datetime({ offset: true })
      .nullable()
      .optional(),
  })
  .strict();
 
export type SkillOptimizationClusterUpdateParams = z.infer<
  typeof SkillOptimizationClusterUpdateParams
>;