config-fields.ts 1.2 KB

123456789101112131415161718192021222324252627
  1. import { SAFETY_SCENE, reviewBlocks, type ContentSafetyChecker } from './api.js';
  2. /**
  3. * Review non-empty user-controllable config text (agent display name /
  4. * description / persona / system prompt / avatar, and user skill name /
  5. * description / content) at the shared `ConfigField` scene, returning `true`
  6. * when a field must block the write.
  7. *
  8. * The fail policy lives in one place — `reviewBlocks` — and the checker always
  9. * resolves to a `SafetyCheckResult` (never throws), so this helper just walks the
  10. * fields and routes each verdict through the shared predicate. Empty / whitespace
  11. * values and the no-checker case (dev/test) never block. Callers own the
  12. * user-facing error shape (agent throws a 422, skill returns a sentinel), so no
  13. * review detail leaks from here.
  14. */
  15. export async function configReviewBlocks(
  16. review: ContentSafetyChecker | undefined,
  17. values: ReadonlyArray<string | null | undefined>,
  18. ): Promise<boolean> {
  19. if (!review) return false;
  20. for (const raw of values) {
  21. const value = raw?.trim() || '';
  22. if (!value) continue;
  23. if (reviewBlocks(await review(value, SAFETY_SCENE.ConfigField))) return true;
  24. }
  25. return false;
  26. }