Merge feature/bootstrap-refactor #2

Closed
blightbow wants to merge 0 commits from feature/bootstrap-refactor into main
Owner
No description provided.
Removed redundant 'Status:' prefix from JavaScript since the template
already includes it.

Changed:
- evennia/contrib/ai/static/ai/dashboard.js lines 150, 153:
  * 'Status: Active' → 'Active'
  * 'Status: Disabled' → 'Disabled'

Reasoning:
- Template at dashboard.html:94 already has "Status: " hardcoded
- JavaScript was appending "Status: Active/Disabled"
- Result was "Status: Status: Active" (doubled prefix)
- Now renders correctly as "Status: Active" or "Status: Disabled"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace custom function-based API views with DRF ViewSets to align
with Evennia's standard REST API patterns (used in evennia/web/api/).
This improves maintainability and provides future Claudes with
consistent patterns to extend.

Created DRF infrastructure:
- evennia/contrib/ai/api/serializers.py: 10 serializers for all
  endpoints, reusing existing helper functions from web_views.py
- evennia/contrib/ai/api/permissions.py: StaffOnlyPermission class
- evennia/contrib/ai/api/views.py: AssistantViewSet with registry-
  based lookup (not ModelViewSet - uses assistant keys not DB PKs)
- evennia/contrib/ai/api/urls.py: DefaultRouter configuration

Updated routing:
- evennia/contrib/ai/urls.py: Added DRF API routes, removed all old
  function-based API endpoints

Cleaned up old code:
- evennia/contrib/ai/web_views.py: Deleted 10 old API functions,
  kept template views and helper functions (reused by serializers)

Updated frontend to new URL structure:
- dashboard.js: 3 URL updates (assistants list, metrics, logs)
- prompt_preview.js: 4 URL updates (assistants list, prompt preview,
  project slots, update-text)

URL structure changes:
- /ai/api/assistants → /api/ai-assistants/
- /ai/api/metrics?assistant_key=X → /api/ai-assistants/X/metrics/
- /ai/api/logs?assistant_key=X → /api/ai-assistants/X/execution-log/
- /ai/api/prompt-preview?assistant_key=X → /api/ai-assistants/X/prompt-preview/
- /ai/api/project-slots?assistant_key=X → /api/ai-assistants/X/project-slots/
- /ai/api/update-text (POST) → /api/ai-assistants/X/update-text/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update embedded JavaScript in 4 dashboard templates to use new DRF
API endpoints instead of old function-based API URLs.

Updated templates:
- projects.html: 2 endpoints (assistants list, projects)
- goals.html: 2 endpoints (assistants list, goals)
- journal.html: 2 endpoints (assistants list, journal)
- session_memory.html: 2 endpoints (assistants list, session-memory)

All templates now use consistent DRF URL pattern:
/api/ai-assistants/ and /api/ai-assistants/:key/:action/

Note: These 4 templates have embedded JavaScript (131-153 lines each)
with duplicated loadAssistants() function. Future improvement: extract
to external JS files like dashboard.js and prompt_preview.js for
consistency and code reuse.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Bug 1 - Goals serializer:
Frontend expects active_goals to be an array for .map() iteration, but
serializer was returning the entire current_goals dict. Fixed by
extracting the "goals" array from the dict structure.

Bug 2 - Journal serializer:
Serializer was deserializing journal as a list (or []), but actual
data structure is a dict with an "entries" key (or {}). This caused
AttributeError when trying to call .get() on strings. Fixed by using
correct data structure and extracting entries array.

Frontend errors fixed:
- Goals: TypeError: goals.map is not a function
- Journal: 500 error - AttributeError: 'str' object has no attribute 'get'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Frontend expects data.projects to be an array for .map() iteration,
but serializer was returning the entire projects dict. Fixed by
extracting slots dict and converting to array format matching old API.

Old format (restored):
{
  "active_project": "project_key",
  "projects": [
    {"key": "...", "summary": "...", "is_active": true, ...},
    ...
  ],
  "total_projects": 3
}

Frontend error fixed:
- Projects: TypeError: data.projects.map is not a function

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Created shared utilities and page-specific JavaScript files to
eliminate code duplication across dashboard templates.

New Files:
- shared_utils.js: Common utilities (loadAssistants, escapeHtml,
  setupAssistantSelector, updateTimestamp)
- goals.js: Goal hierarchy rendering
- journal.js: Journal with pagination and search
- projects.js: Project slots and active project banner
- session_memory.js: Memory items rendering (facts/patterns/tasks)

Updated Templates:
- goals.html, journal.html, projects.html, session_memory.html
- Removed ~540 lines of embedded JavaScript
- Added references to shared_utils.js and page-specific JS files

Benefits:
- Eliminates ~80% of duplicate code (loadAssistants, escapeHtml)
- Consistent patterns across all 6 dashboard pages
- Better browser caching (JS cached separately from HTML)
- Easier maintenance and debugging
- Follows patterns established by dashboard.js and prompt_preview.js

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Created comprehensive test suite for Django Rest Framework endpoints
following Evennia core patterns and updated README with complete
REST API reference.

New Test File:
- test_api.py: 230 lines of API endpoint tests
- Tests authentication (staff-only permissions)
- Tests all 11 REST endpoints (list, retrieve, metrics, logs, etc.)
- Includes regression tests for serializer bug fixes
- Follows evennia/web/api/tests.py patterns

Test Coverage:
- Authentication: StaffOnlyPermission enforced
- Basic endpoints: list, retrieve, 404 handling
- Complex endpoints: metrics, goals, journal, projects
- Pagination: execution-log, journal
- Filtering: journal tag/search
- Data structure validation: goals/projects return arrays (regression tests)
- Mutations: update-text endpoint

README Updates:
- Added "REST API Reference" section (135 lines)
- Documented all 11 endpoints with examples
- Authentication requirements
- Request/response formats
- Pagination and filtering parameters
- Error response formats
- Separated "Python API Reference" section

Note: Tests require Python 3.11-3.13 (Python 3.14 has pkgutil
compatibility issue with django-filters). Run on testing site.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
blightbow closed this pull request 2025-11-16 05:37:47 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blightbow/evennia_ai!2
No description provided.