Skip to content

Add okf serve — local HTTP API for GUIs (okf-kit[serve])#15

Merged
vinodborole merged 2 commits into
mainfrom
v0.3.0-serve
Jul 8, 2026
Merged

Add okf serve — local HTTP API for GUIs (okf-kit[serve])#15
vinodborole merged 2 commits into
mainfrom
v0.3.0-serve

Conversation

@vinodborole

Copy link
Copy Markdown
Owner

Adds okf serve, a loopback-only HTTP API that wraps registry / read / chat / settings — the foundation for a desktop app (and any web UI) to be pure UI over an API, with no okf-kit logic duplicated.

What's in it

  • New okf-kit[serve] extra (fastapi + uvicorn + keyring), lazy-imported so non-serve users are unaffected.
  • Security: binds 127.0.0.1, per-launch bearer token on every /api/*; prints a machine-readable {"event":"ready","url":…,"token":…,"pid":…} line; --parent-pid exits when the host shell dies.
  • Endpoints (map 1:1 to existing functions — registry, bundle_reader, bundle_nav, chat.*):
    • Discover: GET /api/registry
    • Library: GET /api/books, GET/DELETE /api/books/{name}, POST …/install (SSE progress)
    • Read: GET …/toc, GET …/concept (markdown + heading anchors + prev/next)
    • Chat: sessions CRUD + POST …/ask (SSE: tokens → cited sources → done)
    • Settings: GET/PUT /api/settings (API key stored in the OS keychain via keyring, never returned)
  • Deep-linkable citations: chat sources resolve to {concept_id, title, section, anchor, snippet} so a UI can jump from a citation to that section in the reader.
  • Consume-only: pulls no crawl deps, so it stays light to bundle in an app.
  • make_provider() gains an optional api_key (keychain key); env-var fallback kept.

Tests

  • 6 new tests (tests/test_serve.py) covering auth, status, books+delete, toc+concept, the retrieval chat SSE flow with deep-linkable sources, and settings roundtrip (key never returned).
  • Full suite: 66 passed, 1 skipped. Live subprocess smoke verified end-to-end (ready line, token 401, health/books/toc/concept/settings).

Ships as 0.3.0.

vinodborole and others added 2 commits July 8, 2026 22:49
A loopback-only FastAPI service that wraps registry / read / chat / settings so a
desktop app or web UI can be pure UI over an API, with no duplicated logic.

- Guarded by a per-launch bearer token; prints a machine-readable `ready` line
  ({url, token, pid}) for a host shell; `--parent-pid` exits with the shell.
- Endpoints: /registry, /books (list/get/install SSE/remove), /books/{n}/toc,
  /books/{n}/concept (heading anchors + prev/next), chat sessions + /ask (SSE:
  tokens → cited sources → done), /settings (API key in the OS keychain).
- Deep-linkable chat citations: sources resolve to
  {concept_id, title, section, anchor, snippet}.
- Consume-only: no crawl deps, so it stays light to bundle in an app.
- make_provider() gains an optional api_key (keychain key), env fallback kept.
- New extra okf-kit[serve] = fastapi + uvicorn + keyring; lazy-imported so
  non-serve users are unaffected. 6 tests; full suite 66 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vinodborole vinodborole merged commit 65efde1 into main Jul 8, 2026
5 checks passed
@vinodborole vinodborole deleted the v0.3.0-serve branch July 8, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant