All files / src/entities/context schema.ts

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

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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135                            16x                 16x                 16x             16x                 16x               16x                   16x                               16x                   16x                                   16x                                                
/**
 * Schema definitions for manage_context tool
 *
 * CQRS pattern with 8 actions:
 * - show: Display current context (Query)
 * - list_presets: List available presets (Query)
 * - list_profiles: List available profiles - OAuth only (Query)
 * - whoami: Token introspection and capability discovery (Query)
 * - switch_preset: Change active preset (Command)
 * - switch_profile: Change active profile - OAuth only (Command)
 * - set_scope: Set namespace scope with auto-detection (Command)
 * - reset: Restore initial context (Command)
 */
 
import { z } from "zod";
 
// ============================================================================
// Action Schemas
// ============================================================================
 
/**
 * Show current context - returns complete session information
 */
const ShowContextSchema = z.object({
  action: z
    .literal("show")
    .describe("Display current context including host, preset, scope, and mode"),
});
 
/**
 * List available presets (built-in + user-defined)
 */
const ListPresetsSchema = z.object({
  action: z.literal("list_presets").describe("List all available presets with descriptions"),
});
 
/**
 * List available profiles (OAuth mode only)
 */
const ListProfilesSchema = z.object({
  action: z
    .literal("list_profiles")
    .describe("List available OAuth profiles - only works in OAuth mode"),
});
 
/**
 * Switch to a different preset
 */
const SwitchPresetSchema = z.object({
  action: z.literal("switch_preset").describe("Switch to a different preset configuration"),
  preset: z.string().min(1).describe("Name of the preset to activate"),
});
 
/**
 * Switch to a different profile (OAuth mode only)
 */
const SwitchProfileSchema = z.object({
  action: z
    .literal("switch_profile")
    .describe("Switch to a different OAuth profile - OAuth mode only"),
  profile: z.string().min(1).describe("Name of the profile to activate"),
});
 
/**
 * Set namespace scope with auto-detection
 */
const SetScopeSchema = z.object({
  action: z.literal("set_scope").describe("Set scope to restrict operations to a namespace"),
  namespace: z
    .string()
    .min(1)
    .describe("Namespace path (e.g., 'my-group' or 'group/project') - type is auto-detected"),
  includeSubgroups: z
    .boolean()
    .optional()
    .default(true)
    .describe("Include subgroups when scope is a group (default: true)"),
});
 
/**
 * Reset context to initial state
 */
const ResetContextSchema = z.object({
  action: z.literal("reset").describe("Reset context to initial state from session start"),
});
 
/**
 * Get current authentication status, token capabilities, and server configuration.
 * Re-introspects the token to detect permission changes and automatically refreshes
 * available tools if scopes have changed. Use to diagnose access issues or verify
 * that new token permissions are active.
 */
const WhoamiSchema = z.object({
  action: z
    .literal("whoami")
    .describe(
      "Get authentication status, token capabilities, and server configuration. " +
        "Re-introspects token to detect permission changes - if scopes changed, " +
        "automatically refreshes available tools (scopesRefreshed=true in response). " +
        "Use to diagnose access issues or verify new token permissions are active."
    ),
});
 
// ============================================================================
// Combined Schema (Discriminated Union)
// ============================================================================
 
/**
 * ManageContextSchema - discriminated union of all context management actions
 */
export const ManageContextSchema = z.discriminatedUnion("action", [
  ShowContextSchema,
  ListPresetsSchema,
  ListProfilesSchema,
  SwitchPresetSchema,
  SwitchProfileSchema,
  SetScopeSchema,
  ResetContextSchema,
  WhoamiSchema,
]);
 
// ============================================================================
// TypeScript Types
// ============================================================================
 
export type ManageContextInput = z.infer<typeof ManageContextSchema>;
export type ShowContextInput = z.infer<typeof ShowContextSchema>;
export type ListPresetsInput = z.infer<typeof ListPresetsSchema>;
export type ListProfilesInput = z.infer<typeof ListProfilesSchema>;
export type SwitchPresetInput = z.infer<typeof SwitchPresetSchema>;
export type SwitchProfileInput = z.infer<typeof SwitchProfileSchema>;
export type SetScopeInput = z.infer<typeof SetScopeSchema>;
export type ResetContextInput = z.infer<typeof ResetContextSchema>;
export type WhoamiInput = z.infer<typeof WhoamiSchema>;