[kimi] Add /api/matrix/thoughts endpoint for recent thought stream (#677) #739

Merged
kimi merged 1 commits from kimi/issue-677 into main 2026-03-21 14:44:47 +00:00
Collaborator

Fixes #677

Summary

This PR adds the GET /api/matrix/thoughts endpoint that returns Timmy's recent thoughts formatted for Matrix display.

Changes

src/dashboard/routes/world.py

  • Added _MAX_THOUGHT_LIMIT (50), _DEFAULT_THOUGHT_LIMIT (10), and _MAX_THOUGHT_TEXT_LEN (500) constants
  • Added _build_matrix_thoughts_response() function to format thoughts for Matrix display
  • Added get_matrix_thoughts() endpoint at /api/matrix/thoughts:
    • Returns last 10 thoughts by default
    • Supports ?limit=N query param (capped at 50, min 1)
    • Each thought has: id, text (truncated to 500 chars), created_at, chain_id
    • Returns empty array if thinking engine is disabled or fails
    • Includes Cache-Control: no-cache, no-store headers

tests/dashboard/test_world_api.py

  • Added TestMatrixThoughtsEndpoint test class with comprehensive coverage:
    • Response format validation
    • Default and custom limit handling
    • Limit capping (max 50) and clamping (min 1)
    • Text truncation to 500 characters
    • Null parent_id handling
    • Empty list handling
    • Graceful degradation when thinking engine fails
    • Multiple thoughts ordering

Acceptance Criteria

  • GET /api/matrix/thoughts returns last 10 thoughts as JSON array
  • Each thought has: id, text (truncated to 500 chars), created_at, chain_id
  • Optional ?limit=N query param (max 50)
  • Reuses existing /thinking/api logic, just reformats output
  • Returns empty array if thinking engine is disabled
  • tox -e unit passes
  • tox -e lint passes
Fixes #677 ## Summary This PR adds the GET `/api/matrix/thoughts` endpoint that returns Timmy's recent thoughts formatted for Matrix display. ## Changes ### src/dashboard/routes/world.py - Added `_MAX_THOUGHT_LIMIT` (50), `_DEFAULT_THOUGHT_LIMIT` (10), and `_MAX_THOUGHT_TEXT_LEN` (500) constants - Added `_build_matrix_thoughts_response()` function to format thoughts for Matrix display - Added `get_matrix_thoughts()` endpoint at `/api/matrix/thoughts`: - Returns last 10 thoughts by default - Supports `?limit=N` query param (capped at 50, min 1) - Each thought has: `id`, `text` (truncated to 500 chars), `created_at`, `chain_id` - Returns empty array if thinking engine is disabled or fails - Includes `Cache-Control: no-cache, no-store` headers ### tests/dashboard/test_world_api.py - Added `TestMatrixThoughtsEndpoint` test class with comprehensive coverage: - Response format validation - Default and custom limit handling - Limit capping (max 50) and clamping (min 1) - Text truncation to 500 characters - Null parent_id handling - Empty list handling - Graceful degradation when thinking engine fails - Multiple thoughts ordering ## Acceptance Criteria - [x] GET `/api/matrix/thoughts` returns last 10 thoughts as JSON array - [x] Each thought has: id, text (truncated to 500 chars), created_at, chain_id - [x] Optional `?limit=N` query param (max 50) - [x] Reuses existing `/thinking/api` logic, just reformats output - [x] Returns empty array if thinking engine is disabled - [x] `tox -e unit` passes - [x] `tox -e lint` passes
kimi added 1 commit 2026-03-21 14:44:21 +00:00
feat: Add /api/matrix/thoughts endpoint for Matrix thought stream (#677)
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
2cfec1e01c
- Add GET /api/matrix/thoughts endpoint that returns recent thoughts
- Returns last 10 thoughts by default, with ?limit=N param (max 50)
- Each thought has: id, text (truncated to 500 chars), created_at, chain_id
- Reuses existing thinking_engine.get_recent_thoughts() logic
- Returns empty array if thinking engine is disabled or fails
- Add comprehensive test coverage

Fixes #677
kimi merged commit 8fc8e0fc3d into main 2026-03-21 14:44:47 +00:00
kimi deleted branch kimi/issue-677 2026-03-21 14:44:47 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#739