跳转至

Ontology Function Client (openkms_functions)

Platform authoring and caller library for Ontology Functions. Aligns with Palantir’s @osdk/client layer: a stable Client API that uses string api names (client("WorkItem")), not a generated per-ontology package.

Related: Ontology Functions · Research

What ships

Package Role In git
openkms_functions @function, Client, create_edit_batch, testing helpers Yes

There is no openkms_ontology_sdk in openKMS. A Palantir-style generated ontology SDK (typed markers per OT / published query) is not supported; authors and external scripts use string api names on Client.

Authoring

from openkms_functions import Client, function

@function(uses=["helloGreeting"])
def execute(input: dict, client: Client) -> dict:
    greeting = client("helloGreeting").execute_function({"name": input.get("name", "")})
    rows = client("WorkItem").search(limit=10)
    return {"greeting": greeting, "count": len(rows)}
  • Publish validates uses= against published functions.
  • Nested execute_function is depth- and cycle-guarded.
  • client("…") resolves over the HTTP API: object/link types match api_name (the frozen identifier), then the display name (legacy rows predate api_name), then the row id. Functions match their api_name.

External callers (same Client)

import sys
sys.path.insert(0, "ontology-function-service")

from openkms_functions import Client

client = Client("http://localhost:8102", token="YOUR_API_KEY")
print(client("helloGreeting").execute_function({"name": "openKMS"}))

Use a personal API key (Authorization: Bearer). The Client talks to existing REST endpoints (/api/object-types/…, /api/ontology/functions/by-api-name/…/execute).

External services

@function()
def execute(input: dict, client) -> dict:
    return client.external("turtle").post("/api/jobs", {"type": "simulation", "portfolio": input.get("portfolio")})

client.external(name) resolves a service registered in the External services app (/external-services) and returns a small HTTP client: get/post/put/patch/delete. Absolute URLs are refused and the path must match a registered prefix — the registry decides where a Function may reach. The credential never appears in the source.

A service is either an http URL (the sandbox calls it) or a Kubernetes Service (k8s_service: the backend relays the call through the cluster, since the sandbox cannot resolve cluster DNS). The call site does not change — switching transport is a registry edit, not a code edit.

Edits (foundation)

from openkms_functions import create_edit_batch, function

@function(edits=["WorkItem"])
def execute(input: dict, client) -> dict:
    batch = create_edit_batch()
    batch.create("WorkItem", title=input.get("title") or "Untitled", status="backlog")
    # batch.modify("WorkItem", primary_key=input["id"], status="done")
    # batch.delete("WorkItem", primary_key=input["id"])
    return {"edits": batch.get_edits()}

When a Function returns {"edits": batch.get_edits()} from an Action execute, the platform applies create / modify / delete onto resolvable object instances. Omit primary_key on create to let apply assign a UUID (applied.created_ids). See Manager alignment · Kanban lab Understanding the ontology.

Input schema

When a version’s input_schema is a JSON Schema object with required / properties.type, execute rejects invalid input with HTTP 400 before calling ofs.