PermissionRule.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import z from 'zod/v4'
  2. // Types extracted to src/types/permissions.ts to break import cycles
  3. import type {
  4. PermissionBehavior,
  5. PermissionRule,
  6. PermissionRuleSource,
  7. PermissionRuleValue,
  8. } from '../../types/permissions.js'
  9. import { lazySchema } from '../lazySchema.js'
  10. // Re-export for backwards compatibility
  11. export type {
  12. PermissionBehavior,
  13. PermissionRule,
  14. PermissionRuleSource,
  15. PermissionRuleValue,
  16. }
  17. /**
  18. * ToolPermissionBehavior is the behavior associated with a permission rule.
  19. * 'allow' means the rule allows the tool to run.
  20. * 'deny' means the rule denies the tool from running.
  21. * 'ask' means the rule forces a prompt to be shown to the user.
  22. */
  23. export const permissionBehaviorSchema = lazySchema(() =>
  24. z.enum(['allow', 'deny', 'ask']),
  25. )
  26. /**
  27. * PermissionRuleValue is the content of a permission rule.
  28. * @param toolName - The name of the tool this rule applies to
  29. * @param ruleContent - The optional content of the rule.
  30. * Each tool may implement custom handling in `checkPermissions()`
  31. */
  32. export const permissionRuleValueSchema = lazySchema(() =>
  33. z.object({
  34. toolName: z.string(),
  35. ruleContent: z.string().optional(),
  36. }),
  37. )