feat(pilot): Phase 6 — post-resolve templatize prompt + draft accept/reject
All checks were successful
Mirror to GitHub / mirror (push) Successful in 11s
All checks were successful
Mirror to GitHub / mirror (push) Successful in 11s
Closes the loop on the Phase 5 "Run now, templatize after resolve" path.
After a session resolves, drafts queued by the three-option dialog surface
as a modal that lets the engineer review the AI-proposed parameterization
and either save as a reusable team template or skip. A "don't ask again"
toggle writes to account_settings.preferences so the next resolve won't
pop the modal.
Backend:
- /api/v1/draft-templates:
* GET — list account drafts (pending_only default true; pass false for
audit view including accepted/rejected)
* GET /{id} — single draft
* POST /{id}/accept — promotes to a new script_templates row with
source_session_id / source_user_id / source_ticket_ref populated
(drives the Script Library "generated from CW #X · resolved by Y"
provenance chip). Draft flips to status=accepted,
promoted_template_id set, resolved_at stamped. 409 on re-accept /
already-rejected. 400 on unknown category_id.
* POST /{id}/reject — flips to status=rejected. 409 on re-reject.
- /api/v1/accounts/me/preferences (GET/PATCH) — thin wrapper over
AccountSettings.get_setting/set_setting. PATCH merges keys into the
JSONB column, preserving existing keys the client didn't touch.
Used by the "Don't ask again for this team" checkbox
(templatize_prompt_enabled=false) and, forward-looking, by
cw_resolved_status_id / cw_escalated_status_id from Phase 4.
- 13 tests: list filter, accept with/without edited_body, provenance
copy-through, reject, 409 on re-accept / re-reject, 400 on unknown
category, prefs round-trip with merge semantics.
Frontend:
- src/components/pilot/script/TemplatizePrompt.tsx — modal showing the
drafted script with proposed parameters in the Phase 5
ParameterizationPreview, editable name/category/description, an
individual-parameter remove button, and the "don't ask again" opt-out.
Accept posts to /draft-templates/{id}/accept + optionally PATCHes
preferences. Skip posts /reject.
- src/api/draftTemplates.ts — typed client plus accountPreferencesApi.
- AssistantChatPage: after a successful Resolve (external OR local),
fetches preferences + pending drafts for the session and queues the
modal one draft at a time. Escalate does not trigger this flow.
- Sidebar: Scripts nav shows the pending-draft count as a badge. Fetched
independently of the main sidebar stats so endpoint flakes don't
break the rest of the sidebar.
Verified live 2026-04-22: seed two drafts → GET sees both pending →
accept draft A (template created, provenance CW #99123 populated) →
reject draft B → pending count drops → PATCH opt-out → GET confirms
persistence.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ from app.models.refresh_token import RefreshToken
|
||||
from app.core.email import EmailService
|
||||
from app.models.account import Account
|
||||
from app.models.account_invite import AccountInvite
|
||||
from app.models.account_settings import AccountSettings
|
||||
from app.models.subscription import Subscription
|
||||
from app.models.user import User
|
||||
from app.schemas.account import AccountResponse, AccountUpdate, AccountInviteCreate, AccountInviteResponse, TransferOwnershipRequest
|
||||
@@ -559,3 +560,65 @@ async def get_sso_status(
|
||||
sso_enabled=account.sso_enabled,
|
||||
sso_provider=account.sso_provider,
|
||||
)
|
||||
|
||||
|
||||
# ─── Account Preferences (FlowPilot Phase 6) ──────────────────────────────────
|
||||
#
|
||||
# Preferences live in `account_settings.preferences` as a JSONB grab-bag
|
||||
# (per FLOWPILOT-MIGRATION.md Section 4.6). Rows are lazily created on first
|
||||
# write. Any engineer-role user can read + update preferences because the
|
||||
# keys stored here (templatize_prompt_enabled, cw_resolved_status_id, etc.)
|
||||
# are team-level toggles rather than account-owner-gated admin settings.
|
||||
|
||||
|
||||
class AccountPreferencesResponse(BaseModel):
|
||||
preferences: dict
|
||||
|
||||
|
||||
class AccountPreferencesUpdate(BaseModel):
|
||||
"""Merge-style update — each key in `preferences` overwrites that key in
|
||||
the stored JSONB, other keys are preserved. Omit the body entirely to
|
||||
no-op.
|
||||
"""
|
||||
preferences: dict
|
||||
|
||||
|
||||
@router.get("/me/preferences", response_model=AccountPreferencesResponse)
|
||||
async def get_my_preferences(
|
||||
db: Annotated[AsyncSession, Depends(get_db)],
|
||||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
):
|
||||
"""Return the current account's preferences JSONB (empty dict if no row)."""
|
||||
result = await db.execute(
|
||||
select(AccountSettings.preferences).where(
|
||||
AccountSettings.account_id == current_user.account_id
|
||||
)
|
||||
)
|
||||
prefs = result.scalar_one_or_none() or {}
|
||||
return AccountPreferencesResponse(preferences=prefs)
|
||||
|
||||
|
||||
@router.patch("/me/preferences", response_model=AccountPreferencesResponse)
|
||||
async def update_my_preferences(
|
||||
data: AccountPreferencesUpdate,
|
||||
db: Annotated[AsyncSession, Depends(get_db)],
|
||||
current_user: Annotated[User, Depends(get_current_active_user)],
|
||||
):
|
||||
"""Upsert preference keys. Existing keys not present in the payload are kept.
|
||||
|
||||
Example: posting `{"preferences": {"templatize_prompt_enabled": false}}`
|
||||
from the post-resolve "Don't ask me again for this team" checkbox sets
|
||||
just that key without clobbering any other preferences.
|
||||
"""
|
||||
for key, value in data.preferences.items():
|
||||
await AccountSettings.set_setting(db, current_user.account_id, key, value)
|
||||
await db.commit()
|
||||
|
||||
# Return the merged state so the client doesn't need a second GET.
|
||||
result = await db.execute(
|
||||
select(AccountSettings.preferences).where(
|
||||
AccountSettings.account_id == current_user.account_id
|
||||
)
|
||||
)
|
||||
prefs = result.scalar_one_or_none() or {}
|
||||
return AccountPreferencesResponse(preferences=prefs)
|
||||
|
||||
Reference in New Issue
Block a user