All files / shared/src/types/data skill-event.ts

100% Statements 44/44
100% Branches 1/1
100% Functions 0/0
100% Lines 44/44

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 801x         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';
 
/**
 * Event types for tracking skill optimization events
 */
export enum SkillEventType {
  /** System prompt regeneration for a specific cluster */
  REFLECTION = 'reflection',
  /** Model added to skill (affects all clusters) */
  MODEL_ADDED = 'model_added',
  /** Model removed from skill (affects all clusters) */
  MODEL_REMOVED = 'model_removed',
  /** Evaluation added to skill */
  EVALUATION_ADDED = 'evaluation_added',
  /** Evaluation removed from skill */
  EVALUATION_REMOVED = 'evaluation_removed',
  /** Evaluations regenerated with context */
  EVALUATION_REGENERATED = 'evaluation_regenerated',
  /** Partition manually reset by user */
  PARTITION_RESET = 'partition_reset',
  /** Skill description updated */
  DESCRIPTION_UPDATED = 'description_updated',
  /** Number of partitions (clusters) changed - triggers reclustering */
  PARTITIONS_RECLUSTERED = 'partitions_reclustered',
  /** Optimization enabled for skill */
  OPTIMIZATION_ENABLED = 'optimization_enabled',
  /** Optimization disabled for skill */
  OPTIMIZATION_DISABLED = 'optimization_disabled',
  /** Automatic reclustering triggered after accumulating enough logs */
  CLUSTERS_UPDATED = 'clusters_updated',
  /** Initial context generation after reaching 5 logs */
  CONTEXT_GENERATED = 'context_generated',
}
 
/**
 * A skill event tracks important changes that affect skill optimization
 */
export const SkillEvent = z.object({
  id: z.uuid(),
  agent_id: z.uuid(),
  skill_id: z.uuid(),
  /** NULL for skill-wide events, NOT NULL for cluster-specific events */
  cluster_id: z.uuid().nullable(),
 
  event_type: z.nativeEnum(SkillEventType),
 
  /** Flexible metadata field for event-specific data */
  metadata: z.record(z.string(), z.unknown()).default({}),
 
  created_at: z.string().datetime({ offset: true }),
});
 
export type SkillEvent = z.infer<typeof SkillEvent>;
 
export const SkillEventQueryParams = z
  .object({
    id: z.uuid().optional(),
    agent_id: z.uuid().optional(),
    skill_id: z.uuid().optional(),
    cluster_id: z.uuid().optional(),
    event_type: z.nativeEnum(SkillEventType).optional(),
    limit: z.coerce.number().int().positive().optional(),
    offset: z.coerce.number().int().min(0).optional(),
  })
  .strict();
 
export type SkillEventQueryParams = z.infer<typeof SkillEventQueryParams>;
 
export const SkillEventCreateParams = z
  .object({
    agent_id: z.uuid(),
    skill_id: z.uuid(),
    cluster_id: z.uuid().nullable().optional(),
    event_type: z.nativeEnum(SkillEventType),
    metadata: z.record(z.string(), z.unknown()).optional(),
  })
  .strict();
 
export type SkillEventCreateParams = z.infer<typeof SkillEventCreateParams>;