[kimi-task] [feat] Add /api/matrix/bark endpoint — HTTP fallback for bark messages #675

Closed
opened 2026-03-21 03:12:08 +00:00 by kimi · 1 comment
Collaborator

Epic: Matrix Unification

Task

Add POST /api/matrix/bark endpoint that accepts a visitor message and returns Timmy's bark
response. This is the HTTP fallback for when WebSocket isn't available — the Matrix frontend
can POST a message and get a bark back.

Files

  • src/dashboard/routes/world.py — add /api/matrix/bark route
  • tests/timmy/test_world_api.py — add test

Acceptance Criteria

  • POST /api/matrix/bark accepts JSON {text: str, visitor_id: str}
  • Returns JSON bark message (same format as produce_bark())
  • Uses existing bark/chat engine to generate response
  • Rate-limited to 1 request per 3 seconds per visitor_id
  • Returns 429 if rate limited
  • tox -e unit passes
  • tox -e lint passes

Context

The Matrix chat panel currently shows demo barks. This endpoint connects it to Timmy's real
conversation engine. The bark engine uses conversation grounding and commitment tracking
from the Workshop to make responses feel alive.

## Epic: Matrix Unification ## Task Add POST /api/matrix/bark endpoint that accepts a visitor message and returns Timmy's bark response. This is the HTTP fallback for when WebSocket isn't available — the Matrix frontend can POST a message and get a bark back. ## Files - src/dashboard/routes/world.py — add /api/matrix/bark route - tests/timmy/test_world_api.py — add test ## Acceptance Criteria - [ ] POST /api/matrix/bark accepts JSON {text: str, visitor_id: str} - [ ] Returns JSON bark message (same format as produce_bark()) - [ ] Uses existing bark/chat engine to generate response - [ ] Rate-limited to 1 request per 3 seconds per visitor_id - [ ] Returns 429 if rate limited - [ ] tox -e unit passes - [ ] tox -e lint passes ## Context The Matrix chat panel currently shows demo barks. This endpoint connects it to Timmy's real conversation engine. The bark engine uses conversation grounding and commitment tracking from the Workshop to make responses feel alive.
kimi self-assigned this 2026-03-21 03:12:08 +00:00
Author
Collaborator

PR Created: #737

Implementation Complete

Changes Made

  1. Added POST /api/matrix/bark endpoint to src/dashboard/routes/world.py

    • Accepts JSON {text: str, visitor_id: str}
    • Returns bark message in produce_bark() format
    • Uses existing _generate_bark() for response generation
    • In-memory rate limiting: 1 request per 3 seconds per visitor_id
    • Returns 429 with Retry-After header when rate limited
    • Returns 422 for missing/invalid fields
    • Graceful fallback on LLM errors
  2. Added comprehensive tests to tests/dashboard/test_world_api.py

    • 10 new test cases covering all functionality
    • Validates request requirements, rate limiting, response format, error handling

Verification Results

Check Status
tox -e format ✓ Pass
tox -e unit ✓ 2501 passed, 1 skipped
tox -e lint ✓ Pass
tox -e pre-push ✓ Pass (full CI suite)

API Usage Example

# Normal request
curl -X POST http://localhost:8000/api/matrix/bark \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello Timmy!", "visitor_id": "visitor_123"}'

# Response
{
  "type": "bark",
  "agent_id": "timmy",
  "data": {
    "text": "Woof! Hello there!",
    "reply_to": null,
    "style": "speech"
  },
  "ts": 1742573952
}

Ready for review! 🚀

✅ **PR Created: #737** ## Implementation Complete ### Changes Made 1. **Added POST /api/matrix/bark endpoint** to `src/dashboard/routes/world.py` - Accepts JSON `{text: str, visitor_id: str}` - Returns bark message in `produce_bark()` format - Uses existing `_generate_bark()` for response generation - In-memory rate limiting: 1 request per 3 seconds per visitor_id - Returns 429 with `Retry-After` header when rate limited - Returns 422 for missing/invalid fields - Graceful fallback on LLM errors 2. **Added comprehensive tests** to `tests/dashboard/test_world_api.py` - 10 new test cases covering all functionality - Validates request requirements, rate limiting, response format, error handling ### Verification Results | Check | Status | |-------|--------| | `tox -e format` | ✓ Pass | | `tox -e unit` | ✓ 2501 passed, 1 skipped | | `tox -e lint` | ✓ Pass | | `tox -e pre-push` | ✓ Pass (full CI suite) | ### API Usage Example ```bash # Normal request curl -X POST http://localhost:8000/api/matrix/bark \ -H "Content-Type: application/json" \ -d '{"text": "Hello Timmy!", "visitor_id": "visitor_123"}' # Response { "type": "bark", "agent_id": "timmy", "data": { "text": "Woof! Hello there!", "reply_to": null, "style": "speech" }, "ts": 1742573952 } ``` Ready for review! 🚀
kimi closed this issue 2026-03-21 14:32:05 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#675