Skip to content

Complete KE client to cover all OpenAPI spec operations #39

Description

@DaviddeBest-TNO

Summary

The KE client (src/knowledge_mapper/ke/client.py) implements most of the Knowledge Engine REST API, but three operations from the OpenAPI spec are missing. Additionally, the KnowledgeBaseInfo model is missing fields that the spec defines.

Current state

Implemented:

  • GET /sc — get one or all Knowledge Bases ✅
  • POST /sc — register a Knowledge Base ✅
  • DELETE /sc — unregister a Knowledge Base ✅
  • GET /sc/ki — get all Knowledge Interactions ✅
  • POST /sc/ki — register a Knowledge Interaction ✅
  • GET /sc/handle — poll for incoming KI calls ✅
  • POST /sc/handle — respond to a KI call ✅
  • POST /sc/ask — execute an ASK interaction ✅
  • POST /sc/post — execute a POST interaction ✅
  • GET /version — get KE runtime version ✅

Missing:

  • DELETE /sc/ki — unregister a single Knowledge Interaction
  • PUT /sc/lease/renew — renew a Smart Connector lease
  • POST /sc/knowledge — load domain knowledge (Jena rules/facts) into a Smart Connector

Scope

1. Update Pydantic models (ke/models.py)

Add missing optional fields to KnowledgeBaseInfo:

  • leaseRenewalTime: int | None (min 30, max 3600) — enables automatic SC cleanup
  • reasonerLevel: int | None (1-5) — controls reasoning level for the SC

Add a SmartConnectorLease model for the lease renewal response.

2. Implement missing client methods

unregister_ki(kb_id, ki_id)DELETE /sc/ki

  • Headers: Knowledge-Base-Id, Knowledge-Interaction-Id
  • 200: success
  • 400/404: error

renew_lease(kb_id)PUT /sc/lease/renew

  • Header: Knowledge-Base-Id
  • 200: returns SmartConnectorLease
  • 400/404: error

load_domain_knowledge(kb_id, knowledge: str)POST /sc/knowledge

  • Header: Knowledge-Base-Id
  • Body: plain text (Jena rules syntax)
  • Content-Type: text/plain; charset=UTF-8
  • 200: success
  • 400/404: error

3. Update all three layers

  • ClientProtocol: add method signatures with docstrings
  • Client: implement the HTTP calls
  • TestClient (ke/testing/fake_client.py): add fake/in-memory implementations

4. Integrate into KnowledgeBase

Wire the new client methods into the high-level KnowledgeBase class:

  • kb.renew_lease() — renew the SC lease
  • kb.load_domain_knowledge(knowledge: str) — load domain knowledge
  • kb.unregister_ki(ki_name: str) — unregister a specific KI by name (resolves to KI ID internally)

5. Tests

Add tests for the three new operations in tests/test_client.py (or a new test file), using the existing TestClient infrastructure.

Acceptance Criteria

  • unregister_ki is implemented in ClientProtocol, Client, and TestClient
  • renew_lease is implemented in ClientProtocol, Client, and TestClient
  • load_domain_knowledge is implemented in ClientProtocol, Client, and TestClient
  • KnowledgeBaseInfo model includes leaseRenewalTime and reasonerLevel fields
  • KnowledgeBase exposes renew_lease(), load_domain_knowledge(), and unregister_ki()
  • Tests exist for all three new operations
  • All existing tests still pass
  • Linting passes (ruff check)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions