Add okf serve — local HTTP API for GUIs (okf-kit[serve])#15
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
okf-kit[serve]extra (fastapi+uvicorn+keyring), lazy-imported so non-serve users are unaffected.127.0.0.1, per-launch bearer token on every/api/*; prints a machine-readable{"event":"ready","url":…,"token":…,"pid":…}line;--parent-pidexits when the host shell dies.registry,bundle_reader,bundle_nav,chat.*):GET /api/registryGET /api/books,GET/DELETE /api/books/{name},POST …/install(SSE progress)GET …/toc,GET …/concept(markdown + heading anchors + prev/next)POST …/ask(SSE: tokens → cited sources → done)GET/PUT /api/settings(API key stored in the OS keychain via keyring, never returned){concept_id, title, section, anchor, snippet}so a UI can jump from a citation to that section in the reader.make_provider()gains an optionalapi_key(keychain key); env-var fallback kept.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).Ships as 0.3.0.