ENG-3160: BE - Access policy agent chat (types + prompt explorer)#7992
ENG-3160: BE - Access policy agent chat (types + prompt explorer)#7992thabofletcher wants to merge 39 commits intomainfrom
Conversation
…lis-agent-chat-for-policy-building
…lis-agent-chat-for-policy-building
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
c02560e to
698134e
Compare
@ant-design/x bundles refractor (and react-syntax-highlighter) which ship as ESM-only packages. Jest's CJS transform config can't handle them without a full transform exception chain. Instead, mock @ant-design/x entirely in unit tests — Bubble/Sender are not exercised there anyway.
This reverts commit a414408.
This reverts commit d92cd67.
69ba60d to
2a9794e
Compare
Change `*/api/v1/plus/llm/access-policy-chat` to `*/api/v1/plus/access-policy/agent` to match the endpoint defined in the route.
|
/code-review |
There was a problem hiding this comment.
Code Review: PR #7992 — BE - Access policy agent chat (types + prompt explorer)
Overall this is a clean, focused change — the URL fix is correct and the new prompt-explorer wiring works logically. Two themes run through most of the findings:
1. Enum members vs. raw strings (all files)
The PR defines PromptCategory.ACCESS_POLICIES and PromptType.ACCESS_POLICY_CHAT in types.ts, then doesn't use them for any of the comparisons it adds. Every new conditional (=== "access_policy_chat", === "access_policies", === "questionnaire") should use the corresponding enum member. See inline comments on utils.ts:68, QuestionnaireControls.tsx:75, prompt-explorer.tsx:175, and prompt-explorer.tsx:321.
2. Generated enum divergence
types/api/models/PromptCategory.ts and PromptType.ts (auto-generated) do not include the new ACCESS_POLICIES / ACCESS_POLICY_CHAT values. The comment in types.ts notes these are "hardcoded until openapi:generate properly generates them," which is an acceptable short-term workaround — but it's worth tracking. If any code path uses the generated enums for comparison (e.g., via PromptInfo.category from the API response), those checks will silently miss the new values. The fix is to re-run npm run openapi:generate once the backend OpenAPI spec includes the new enum members.
3. QuestionnaireControls scope creep
The component now handles two unrelated prompt categories under one name and interface. The 4 new props are irrelevant to all non-access-policy paths. See inline comment on QuestionnaireControls.tsx:265 for a grouping option that keeps the interface manageable without a full refactor.
Minor
- Default
agentPromptstate vs. placeholder text duplication (see inline onprompt-explorer.tsx:82) — nit for a dev-tool page.
🔬 Codegraph: connected (47303 nodes)
💡 Write /code-review in a comment to re-run this review.
The backend uses control (singular string) but the frontend had controls (plural array) throughout. This caused 422s on create/update because extra="forbid" on the request schema rejected the unknown field. - Rename AccessPolicy.controls to control throughout - Map SidebarFormValues.controls[0] to control in save handlers - Fix list filtering, grouping, and table column to use control - Fix MSW mock data to match Note: AccessPolicyYaml.controls (the YAML content field) remains a list — that is a separate concept from the API metadata field.
The API contract uses `control: str | None` (singular) but the canvas editor's internal data model was still `controls: string[]` everywhere. This renames the field end-to-end so the save path no longer needs the `controls?.[0]` workaround and the PolicyNode Select is single-select. YAML documents still emit `controls: [value]` (list) per the schema.
…errors
Changes the "Controls" label to "Control" to match the single-select model,
and adds handling for structured { message, errors } API responses so save
failures show an actionable message instead of the generic fallback.
.unwrap() throws the FetchBaseQueryError directly, not wrapped in
{ error: ... }. The cast was accessing .error on undefined, causing
every save failure to show the generic fallback message.
The backend wraps structured errors as { detail: { message, errors } },
so the check needs to inspect error.data.detail, not error.data directly.
- Resolve add/add conflicts in agent-chat.slice.ts and agent-chat-handlers.ts keeping the correct /plus/access-policy/agent URL - Resolve content conflict in AccessPolicyEditor.tsx keeping single-control refactor - Replace raw string literals with PromptCategory/PromptType enum members in utils.ts, QuestionnaireControls.tsx, and prompt-explorer.tsx - Use empty string default for agentPrompt state (placeholder is sufficient)
…changelog - Fix prettier formatting in PoliciesTable.tsx and useAccessPolicyGroups.ts introduced by merge from main - Import PromptCategory directly from types.ts instead of the slice (re-exported as `export type` making it unusable as a value) - Add changelog entry for PR 7992
PolicyNodeData.control changed from controls: string[] to control?: string. Update yamlToNodesAndEdges test to assert on the singular field and value, and update nodesToYaml test to pass control (string) in node data instead of the old controls (array) shape.
Ticket ENG-3160
Description Of Changes
Backend support changes for the access policy agent chat feature. This PR adds the TypeScript types needed by the UI, wires the agent chat RTK Query slice, fixes save/edit error handling, and extends the prompt explorer developer tool to support the new chat prompt.
To test with the fidesplus APIs required, use this branch
https://github.com/ethyca/fidesplus/pull/3447
Code Changes
Types
AccessPoliciesApplicationConfigTypeScript type withagent_enabledfieldAccessPoliciesApplicationConfigintoPlusApplicationConfigtypes/api/index.tsAgent chat wiring
agent-chat.slice.ts— RTK Query mutation forPOST /plus/access-policy/agentmocks/access-policies/agent-chat-handlers.ts— MSW handler for local dev / testsError handling
helpers.ts— fixgetErrorMessageto read fromerror.data.detail(FastAPI wraps validation errors one level deeper than previously assumed)pages/access-policies/new/andedit/[id]/— fix RTK.unwrap()error cast so save/delete failures show the real message instead of "An unexpected error occurred"Prompt explorer
ACCESS_POLICY_CHATprompt type andACCESS_POLICIEScategory to prompt explorer typesagentPrompt/currentPolicyYamleditable inputs toQuestionnaireControlsfor the chat prompt typebuildQuestionnaireVariablesto handleaccess_policy_chatAccess Policiescategory to the prompt explorer filterSingle-control refactor (merge conflict resolution)
AccessPolicyEditor.tsx,policy-yaml.ts,PolicyNode.tsx— resolved conflicts from the controls → single control refactor on main; updated tests accordinglySteps to Confirm
FIDESPLUS__ACCESS_POLICIES__AGENT_ENABLED=true/poc/prompt-explorer), select "Access Policy Agent Chat" — editable User Prompt and Current Policy YAML fields should appear before clicking Render PromptPre-Merge Checklist
CHANGELOG.mdupdated