All files / src/entities/workitems schema-readonly.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12

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 95 96 973x           3x   3x   12x                             3x   1x       3x   1x                       3x     3x                                                           3x           3x                        
import { z } from "zod";
 
// ============================================================================
// Base schemas for work items
// ============================================================================
 
export const WorkItemIdSchema = z.string().min(1).describe("Work item ID");
 
export const WorkItemTypeEnumSchema = z
  .string()
  .transform(val => val.toUpperCase().replace(/\s+/g, "_"))
  .pipe(
    z.enum([
      "EPIC",
      "ISSUE",
      "TASK",
      "INCIDENT",
      "TEST_CASE",
      "REQUIREMENT",
      "OBJECTIVE",
      "KEY_RESULT",
    ])
  )
  .describe("Type of work item");
 
export const WorkItemStateSchema = z
  .string()
  .transform(val => val.toUpperCase())
  .pipe(z.enum(["OPEN", "CLOSED"]))
  .describe("State of work item");
 
export const WorkItemStateEventSchema = z
  .string()
  .transform(val => val.toUpperCase())
  .pipe(z.enum(["CLOSE", "REOPEN"]))
  .describe("State event for updating work item");
 
// ============================================================================
// browse_work_items - CQRS Query Tool (discriminated union schema)
// Actions: list, get
// Uses z.discriminatedUnion() for type-safe action handling.
// Schema pipeline flattens to flat JSON Schema for AI clients that don't support oneOf.
// ============================================================================
 
// --- Shared fields ---
const workItemIdField = WorkItemIdSchema.describe("Work item ID to retrieve");
 
// --- Action: list ---
const ListWorkItemsSchema = z.object({
  action: z.literal("list").describe("List work items with filtering"),
  namespace: z
    .string()
    .describe(
      "Namespace path (group or project). Groups return epics, projects return issues/tasks."
    ),
  types: z.array(WorkItemTypeEnumSchema).optional().describe("Filter by work item types"),
  state: z
    .array(WorkItemStateSchema)
    .optional()
    .default(["OPEN"])
    .describe(
      'Filter by work item state. Defaults to OPEN items only. Use ["OPEN", "CLOSED"] for all items.'
    ),
  first: z.number().optional().default(20).describe("Number of items to return"),
  after: z
    .string()
    .optional()
    .describe("Cursor for pagination (use endCursor from previous response)"),
  simple: z
    .boolean()
    .optional()
    .default(true)
    .describe(
      "Return simplified structure with essential fields only. RECOMMENDED: Use default true for most cases."
    ),
});
 
// --- Action: get ---
const GetWorkItemSchema = z.object({
  action: z.literal("get").describe("Get single work item details"),
  id: workItemIdField,
});
 
// --- Discriminated union combining all actions ---
export const BrowseWorkItemsSchema = z.discriminatedUnion("action", [
  ListWorkItemsSchema,
  GetWorkItemSchema,
]);
 
// ============================================================================
// Type exports
// ============================================================================
 
export type BrowseWorkItemsInput = z.infer<typeof BrowseWorkItemsSchema>;
export type WorkItemTypeEnum = z.infer<typeof WorkItemTypeEnumSchema>;
export type WorkItemState = z.infer<typeof WorkItemStateSchema>;