File size: 18,272 Bytes
5acc2e1 fd065cf 5acc2e1 19271de 5acc2e1 ee2c0b0 bd4ca2a 5acc2e1 210721f 51003be 210721f 5127cef e456a95 1caa766 fd065cf 2f0cd07 fd065cf de4bf02 fd065cf 2f0cd07 6321067 51003be 6321067 0b52074 5acc2e1 51003be 1caa766 8916217 1caa766 5127cef fd065cf 5127cef fd065cf 5127cef fd065cf 5127cef fd065cf c3b9d0c 849c8bb fd065cf 5127cef 1caa766 5acc2e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | # API Overview
## Base URLs
Local backend:
```text
http://127.0.0.1:8000
```
Local Docker:
```text
http://localhost:7860
```
Swagger:
```text
http://127.0.0.1:8000/docs
```
## FastAPI Entry Point
```text
backend.main:app
```
## Endpoints
| Method | Path | Auth | Purpose |
|---|---|---|---|
| GET | `/health` | No | Health check |
| GET | `/health/deployment` | No | Safe deployment readiness summary; reports configured/missing status without secret values |
| POST | `/api/auth/login` | No | Login and receive JWT |
| GET | `/api/auth/me` | Yes | Return current user profile |
| POST | `/api/chat` | Yes | Send chat message to Jeffy |
| GET | `/api/session/history` | Yes | Retrieve message history |
| GET | `/api/agents/status` | Yes | Return available agents for user role |
| GET | `/api/agents/catalog` | Yes | Return Phase 3 agent catalog and permission flags |
| POST | `/api/agents/route` | Yes | Route a message to a permitted lightweight agent and create a task |
| GET | `/api/tasks` | Yes | Return current user's recent agent tasks |
| GET | `/api/tasks/{task_id}` | Yes | Return one current-user agent task |
| POST | `/api/tasks/{task_id}/cancel` | Yes | Cancel a queued/running/waiting task |
| GET | `/api/kids/pet` | Child only | Return child pet stats |
| POST | `/api/kids/pet` | Child only | Apply pet action |
| POST | `/api/pet/feed` | Child only | Feed Jeffy |
| POST | `/api/pet/water` | Child only | Give Jeffy water |
| POST | `/api/location/share` | Yes | Explicitly share current user location |
| GET | `/api/location/latest` | Yes | Return own latest location for children, child locations for adults |
| GET | `/api/location/latest/{user_id}` | Yes | Return latest permitted location for a user |
| POST | `/api/sos/create` | Yes | Create a user-triggered SOS alert |
| GET | `/api/sos/active` | Yes | Return permitted active SOS alerts |
| POST | `/api/sos/{sos_id}/resolve` | Adult/admin | Resolve an active SOS alert |
| POST | `/api/voice/transcribe` | Yes | Canonical guarded voice transcription endpoint; returns `whisper-disabled` until a real provider is configured |
| POST | `/api/audio/transcribe` | Yes | Legacy compatibility route delegating to `/api/voice/transcribe` |
| POST | `/api/video/snapshot` | Yes | Placeholder for image/video snapshot |
| POST | `/api/rag/upload` | Adult/admin | Upload `.txt` or `.md` documents into an allowed RAG collection |
| GET | `/api/rag/documents` | Yes | List visible RAG documents |
| GET | `/api/rag/documents/{document_id}` | Yes | Return one visible RAG document |
| DELETE | `/api/rag/documents/{document_id}` | Adult/admin | Delete an allowed RAG document |
| POST | `/api/rag/query` | Yes | Query visible/curated RAG documents |
| POST | `/api/search/query` | Yes | Run permitted search with demo fallback, or saved-source search when `search_type=source_registry`, `source_id`, or `category` is provided. Saved-source search uses safe backend fetch/extraction for active public sources. |
| GET | `/api/search/history` | Yes | Return current user's search history |
| GET | `/api/admin/dashboard` | Admin | Return Admin Control Center summary data, dashboard widgets, agents, tasks, sources, events, runtime diagnostics, safe configuration registry, and management registry |
| GET | `/api/admin/release-readiness` | Admin | Return Development Monitor release-readiness status, Release Blockers, User Validation, Validation Results, Repository Status, Delivered, Backlog, and Archived categories without secret values or running release commands |
| GET | `/api/admin/repository-documents` | Admin | List allowlisted read-only repository documents for Development Monitor Repository Status |
| GET | `/api/admin/repository-documents/{doc_id}` | Admin | Return one allowlisted markdown/text repository document for read-only admin viewing |
| GET | `/api/admin/security/status` | Admin | Return whether Admin Console second verification is configured |
| POST | `/api/admin/security/verify` | Admin | Verify the configured admin code before opening Admin Console |
| GET | `/api/admin/commands` | Admin | Return backend-mediated Admin Command / Action Router commands |
| POST | `/api/admin/commands/run` | Admin | Resolve and run a supported admin command through FastAPI |
| GET | `/api/admin/users` | Admin | Return safe user management fields without password hashes or secrets |
| POST | `/api/admin/users` | Admin | Create an admin-managed user with validation |
| PATCH | `/api/admin/users/{user_id}` | Admin | Update safe user fields and status with current-admin/last-admin protection |
| DELETE | `/api/admin/users/{user_id}` | Admin | Archive a user where protected-user rules allow it |
| POST | `/api/admin/users/{user_id}/reset-access` | Admin | Reset user access without returning password hashes |
| GET | `/api/admin/events` | Admin | Return recent system events |
| GET | `/api/admin/agents` | Admin | List persisted admin agent registry records |
| POST | `/api/admin/agents` | Admin | Create an agent registry record |
| PATCH | `/api/admin/agents/{agent_id}` | Admin | Update an agent registry record |
| DELETE | `/api/admin/agents/{agent_id}` | Admin | Archive an agent registry record through permission/approval checks where configured |
| GET | `/api/admin/tools` | Admin | List tool registry records |
| POST | `/api/admin/tools` | Admin | Create a tool registry record |
| PATCH | `/api/admin/tools/{tool_id}` | Admin | Update a tool registry record |
| DELETE | `/api/admin/tools/{tool_id}` | Admin | Archive a tool registry record through permission/approval checks where configured |
| GET | `/api/admin/capabilities` | Admin | List Phase 15 capability safety-contract records |
| POST | `/api/admin/capabilities` | Admin | Create a capability safety-contract record; does not execute the capability |
| PATCH | `/api/admin/capabilities/{capability_id}` | Admin | Update a capability safety-contract record |
| DELETE | `/api/admin/capabilities/{capability_id}` | Admin | Archive a capability safety-contract record through permission/approval checks where configured |
| POST | `/api/admin/capabilities/{capability_id}/assign` | Admin | Assign a capability contract to an agent |
| DELETE | `/api/admin/capabilities/assignments/{assignment_id}` | Admin | Archive an agent capability assignment |
| POST | `/api/admin/capabilities/{capability_id}/policy-check` | Admin | Check capability safety policy without executing the capability |
| GET | `/api/admin/task-registry` | Admin | List task registry records |
| POST | `/api/admin/task-registry` | Admin | Create a task registry record |
| PATCH | `/api/admin/task-registry/{task_id}` | Admin | Update a task registry record |
| POST | `/api/admin/task-registry/{task_id}/run` | Admin | Run a task through permission/approval checks where configured |
| DELETE | `/api/admin/task-registry/{task_id}` | Admin | Archive a task registry record through permission/approval checks where configured |
| POST | `/api/admin/workflows/agent-diagnostic/run` | Admin | Run Agent Diagnostic Workflow behind FastAPI |
| POST | `/api/admin/workflows/storage-diagnostic/run` | Admin | Run Storage Diagnostic Workflow behind FastAPI |
| GET | `/api/admin/workflows/runs` | Admin | List workflow runs |
| GET | `/api/admin/workflows/runs/{run_id}` | Admin | Return workflow run detail |
| GET | `/api/admin/storage` | Admin | List provider-agnostic storage records |
| POST | `/api/admin/storage` | Admin | Create storage metadata/configuration record |
| PATCH | `/api/admin/storage/{storage_id}` | Admin | Update storage metadata/configuration record |
| DELETE | `/api/admin/storage/{storage_id}` | Admin | Archive storage record through permission/approval checks where configured |
| POST | `/api/admin/storage/{storage_id}/test-access` | Admin | Test safe storage access through backend adapter and permission checks |
| GET | `/api/admin/storage/activity` | Admin | List storage activity logs |
| GET | `/api/admin/credentials/status` | Admin | Return Credential Vault readiness without secrets |
| GET | `/api/admin/credentials` | Admin | List credential references with masked/encrypted status only |
| POST | `/api/admin/credentials` | Admin | Create credential reference or encrypted credential when encryption is configured |
| PATCH | `/api/admin/credentials/{credential_id}` | Admin | Update credential metadata/status without exposing decrypted values |
| DELETE | `/api/admin/credentials/{credential_id}` | Admin | Archive credential record through permission/approval checks where configured |
| POST | `/api/admin/credentials/{credential_id}/test` | Admin | Test credential usability without returning secret values |
| GET | `/api/admin/llm/providers` | Admin | List backend LLM provider configurations |
| POST | `/api/admin/llm/providers` | Admin | Create LLM provider configuration such as OpenRouter |
| PATCH | `/api/admin/llm/providers/{provider_config_id}` | Admin | Update LLM provider configuration |
| DELETE | `/api/admin/llm/providers/{provider_config_id}` | Admin | Archive LLM provider configuration through permission/approval checks where configured |
| POST | `/api/admin/llm/providers/{provider_config_id}/test` | Admin | Test provider configuration through backend adapter only |
| GET | `/api/admin/llm/models` | Admin | List LLM model definitions |
| POST | `/api/admin/llm/models` | Admin | Create LLM model definition |
| PATCH | `/api/admin/llm/models/{llm_config_id}` | Admin | Update LLM model definition |
| DELETE | `/api/admin/llm/models/{llm_config_id}` | Admin | Archive LLM model definition through permission/approval checks where configured |
| POST | `/api/admin/llm/models/{llm_config_id}/test` | Admin | Test model configuration through backend adapter only |
| GET | `/api/admin/llm/assignments` | Admin | List agent/model assignments |
| POST | `/api/admin/llm/assignments` | Admin | Assign model definition to an agent/task type through approval checks where configured |
| DELETE | `/api/admin/llm/assignments/{assignment_id}` | Admin | Archive model assignment through approval checks where configured |
| GET | `/api/admin/llm/activity` | Admin | List LLM activity logs without secrets |
| GET | `/api/admin/approvals` | Admin | List approval requests |
| POST | `/api/admin/approvals/{approval_id}/approve` | Admin | Approve an approval-gated action |
| POST | `/api/admin/approvals/{approval_id}/reject` | Admin | Reject an approval-gated action |
| POST | `/api/admin/approvals/{approval_id}/cancel` | Admin | Cancel own pending approval request where allowed |
| POST | `/api/events` | Yes | Record a frontend/system event for admin monitoring |
| GET | `/api/search/sources` | Admin | List admin website sources |
| POST | `/api/search/sources` | Admin | Add a public website source |
| PATCH | `/api/search/sources/{source_id}` | Admin | Update source metadata/status |
| DELETE | `/api/search/sources/{source_id}` | Admin | Disable a website source |
| POST | `/api/search/sources/{source_id}/refresh` | Admin | Refresh public page metadata/summary |
| POST | `/api/search/sources/refresh-all` | Admin | Refresh up to 25 active public sources and log diagnostics |
| POST | `/api/search/sources/search` | Admin | Canonical saved-source search endpoint. Loads active saved sources, validates public URLs, fetches bounded single-page text, extracts snippets, logs diagnostics, and returns Jeffy-formatted findings. |
| POST | `/api/search/assistant/inspect` | Admin | Inspect public website reachability, title, description, useful links, API/doc signals, source type, usefulness score, and diagnostics |
| POST | `/api/search/diagnostics/outbound` | Admin | Validate safe public outbound fetch reachability from the current runtime and log diagnostics |
| GET | `/{full_path:path}` | No | Serve React SPA if `frontend/dist` exists |
## Auth
Protected endpoints use Bearer token authentication.
Header:
```text
Authorization: Bearer <token>
```
## Login Request
```json
{
"username": "dkbash",
"password": "jeffy123"
}
```
## Login Response
```json
{
"access_token": "...",
"token_type": "bearer",
"user": {
"id": 1,
"username": "dkbash",
"display_name": "Danish",
"role": "admin",
"age_group": "adult",
"safety_level": "standard",
"mode": "admin"
}
}
```
## Chat Request
```json
{
"message": "Hello Jeffy",
"session_id": null,
"mode": null
}
```
## Chat Response
```json
{
"reply": "...",
"avatar_state": "speaking",
"agent": "conversation_agent",
"session_id": "...",
"safety_mode": "standard"
}
```
## Pet Action Request
```json
{
"action": "feed"
}
```
Allowed current actions:
- `feed`
- `water`
- `star`
## Saved-Source Search Behavior
Canonical endpoint:
```text
POST /api/search/sources/search
```
`/api/search/query` delegates to the same saved-source search path when `search_type` is `source_registry`, or when `source_id` or `category` is provided.
Current behavior:
- Loads active saved website sources for the admin user.
- Supports all active sources, a specific `source_id`, a `category`, or an explicit public URL included in the query.
- Validates URLs before fetch and blocks local/private/internal hosts.
- Fetches one public HTTP/HTTPS page per source with timeout and response-size guard.
- Extracts title, meta description, readable bounded text, useful links, snippets, HTTP status, response size, fetch duration, and extraction length.
- Updates existing source summary/status/error fields where available.
- Logs search/fetch/extraction/failure events for the Admin Command Center Event Monitor.
- Returns Jeffy-formatted `summary`, `key_findings`, `sources_used`, `limitations`, and `suggested_next_action`.
Known limitations:
- No multi-page crawling.
- No scheduled background crawler.
- No persistent vector index.
- Login-required/private pages are intentionally unsupported.
- Production fetch success still depends on target website behavior and Hugging Face outbound network access.
## Admin Console Security
Admin Console access now has two layers:
- Normal authenticated admin JWT session.
- A second Admin Console verification code.
Configure the second factor with:
```text
ADMIN_REAUTH_CODE_SHA256=<sha256 hash of the admin code>
```
Deployment status: configured in the deployment environment. The plain code is never hardcoded in the app and should not be committed. If the setting is missing in a local/dev environment, the frontend shows a setup warning and does not silently open the Admin Console.
## Admin Control Center
Admin users are routed toward the Admin Control Home after login through the admin second-verification flow. Non-admin users continue to land in the Family Area.
The Admin Control Center is a separate full-screen operations area with:
- left sidebar navigation
- fixed top command/search/voice control bar
- fixed bottom notification bar
- dashboard monitoring using real backend data
- controlled and assist agent sections
- operational agent, task, tool, storage, credential, LLM provider/model, assignment, user, and approval management where visible
- Management Configuration Center for Storage Configuration, Source Registry, LLM Configuration, Credential Vault, Tool Configuration, Agent Assignments, and runtime settings where data exists
- Logs and Events
- Reports using real available data only
- Settings
- reusable status badges
- detail drawer pattern
The `/api/admin/dashboard` response includes safe configuration visibility only. It reports configured/not configured/enabled/disabled status for environment-backed settings and never returns secret values, password hashes, tokens, `DATABASE_URL`, or `JEFFY_CREDENTIAL_ENCRYPTION_KEY`.
## Deployment Readiness
Required deployment secrets are:
```text
DATABASE_URL
JEFFY_CREDENTIAL_ENCRYPTION_KEY
```
Document names only. Do not document, print, commit, log, or return actual secret values.
The `/health/deployment` endpoint returns safe readiness statuses for runtime, database, credential vault, LangGraph/package availability, storage readiness, and frontend/dist presence. It must not include secret values.
The admin-only `/api/admin/release-readiness` endpoint reuses deployment readiness data and adds the current Phase 14.6 release-baseline status. It does not run git, npm, compile, Capacitor, APK, sync, upload, or destructive commands. Checks that cannot be automatically verified are returned as `manual_confirmation_required`.
## Admin Command Router
Admin commands are backend-mediated through `/api/admin/commands` and `/api/admin/commands/run`. The Family Area must not call admin command endpoints. Family-safe voice/text commands remain handled through family preference and voice-command paths.
## Workflows
LangGraph workflows run behind FastAPI only. The frontend calls Jeffy workflow endpoints and never calls LangGraph directly. Workflow runs are persisted and visible through Admin Logs/Events and workflow run detail views.
## Storage, Credential, and LLM Configuration
Storage is provider-agnostic and configurable. Hugging Face bucket or mounted-storage support is represented as storage records; no bucket URI is hardcoded.
Credential records use references and encrypted storage only when `JEFFY_CREDENTIAL_ENCRYPTION_KEY` is configured. Decrypted values are never returned to the frontend.
OpenRouter is represented as an LLM provider configuration plus model definitions and agent/model assignments. The frontend must not call OpenRouter directly.
## Voice Output Modes
Frontend voice controls support:
- `voice_and_chat`: speech input, chat text, and TTS output.
- `stt_only`: speech input and chat text, with TTS muted.
- `chat_only`: typed chat only.
The current implementation stores the selected output mode in browser local storage to avoid a database schema migration in Phase 9B.
## Family Area
The Family Area now exposes Pet and Learn modes. Pet Mode behavior is preserved. Learn Mode includes German, coding, homework, Story, Quiz, and Drawing actions. Pro/admin capabilities remain available through the separate Admin Console instead of the Family Area mode selector.
## API Change Rule
When endpoints change, update this file in the same task.
|