Spaces:
Running
Running
Download frontend/src/utils/statedGoal.js from BrainForge/Cybersecurity-Panel: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/BrainForge/Cybersecurity-Panel/resolve/main/frontend/src/utils/statedGoal.js
- Command line
-
hf download hf://spaces/BrainForge/Cybersecurity-Panel/frontend/src/utils/statedGoal.js
-
curl -L -o statedGoal.js https://huggingface.co/spaces/BrainForge/Cybersecurity-Panel/resolve/main/frontend/src/utils/statedGoal.js
1.12 kB
| /** Resolve the user's stated goal from profile, facts, or guest label. */ | |
| const EMPTY = new Set(['', 'n/a', 'na', 'none', 'not specified', 'unknown', 'unspecified']); | |
| export function normalizeGoalText(value) { | |
| if (value == null) return ''; | |
| const text = String(value).replace(/\s+/g, ' ').trim(); | |
| if (!text || EMPTY.has(text.toLowerCase())) return ''; | |
| return text; | |
| } | |
| export function resolveStatedGoal({ profile, facts, user } = {}) { | |
| const fromFacts = (facts || []).find((fact) => { | |
| const key = String(fact?.key || '').toLowerCase(); | |
| return key === 'stated_goal' && normalizeGoalText(fact.value); | |
| }); | |
| if (fromFacts) return normalizeGoalText(fromFacts.value); | |
| const fromProfile = normalizeGoalText(profile?.current_goals); | |
| if (fromProfile) return fromProfile; | |
| if (user?.is_guest) { | |
| const label = normalizeGoalText(user.guest_label); | |
| if (label) return label; | |
| } | |
| return ''; | |
| } | |
| export function goalCacheKey(goal, userId) { | |
| const uid = userId || 'anon'; | |
| const g = (goal || '').trim().toLowerCase().slice(0, 180); | |
| return `${uid}::${g}`; | |
| } | |