Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ evolve; changes are additive and backwards-compatible where possible.

## [Unreleased]

### T0 `minder_api` step
Additive.
- A declarative step may be `minder_api: {route, method, query, body}`
instead of `request`. It calls Minder's own API through the invocation's
`ctx.minder` (capability `minder.api`) and is not egress. Its parsed answer
is the step's result, as with an HTTP step (`select`, `when`, `foreach`,
`steps.<name>`). It counts toward the per-invocation request cap. A
`minder_api` result can feed a later `request` step, so the data can reach
the plugin's egress hosts. A tool whose plugin declares egress counts as
egressing for local-only content.
- Only a tool that declares `minder_scopes` (new on a declarative tool,
from `context.MINDER_SCOPES`) can use it. The route must start with `/v1/`
and the method must be GET or POST, with a body on POST only (the schema
refuses a body on GET too). Actions, the
schedule and tools without `minder_scopes` are refused at load.
- `minder_t0_engine.Invocation` gains `minder` (the `ctx.minder` handle).
Without it a `minder_api` step raises `CapabilityDenied`. `Operation`
gains `minder_scopes`. The declarative schema gains the `minderApi`
definition, `step.minder_api` and `operation.minder_scopes`.

### `ctx.minder`: Minder's own API for AI tools
Additive.
- `await ctx.minder.call(route, *, method="GET", query=None, json=None)` calls
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,34 @@ minder-plugin try manifest.yml convert --args '...' --replay fixtures/
- Recordings keep response headers except cookies and hop-by-hop headers;
review them before you commit them.

A tool may also call Minder's own API with a `minder_api` step instead of a
`request`. The tool must declare `minder_scopes`, and the step runs through
`ctx.minder.call` (capability `minder.api`) as the invoking user. It is not
egress, so no egress rule applies to it. Its parsed answer is the step's result,
as with an HTTP step, so `select`, `when`, `foreach` and later steps work the same
way. Actions and the schedule can't use it. `minder-plugin try` binds no
`ctx.minder`, so a `minder_api` step is denied there.

A `minder_api` result can feed a later `request` step, so the data it reads can
reach the plugin's egress hosts. Minder therefore treats a tool whose plugin
declares any egress as egressing when it decides about local-only content.

```yaml
tools:
passages:
description: Search the knowledge base.
minder_scopes: [kb.search]
parameters: {type: object, properties: {kb: {type: string}, q: {type: string}}}
steps:
- name: hits
minder_api:
route: "/v1/knowledge-bases/{params.kb}/search" # starts with /v1/
method: POST # GET (default) or POST
query: {limit: 5}
body: {query: "{params.q}"} # POST only
select: results
```

## Worked example

[`examples/weather_plugin.py`](examples/weather_plugin.py) is a complete,
Expand Down
146 changes: 138 additions & 8 deletions src/minder_plugin_sdk/schemas/declarative-manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://minderhq.github.io/docs/schemas/declarative-manifest.v1alpha1.json",
"title": "Minder Declarative Connector Manifest",
"description": "A declarative (T0) connector: HTTP tools, actions, a schedule and an inbound webhook expressed as data, run by Minder's connector engine with no plugin code. This schema checks the structure. At load the engine also checks what JSON Schema cannot express: every base host is in the declared egress, placeholders and JMESPath expressions compile, auth fields fit the auth type, step names are unique, measurements are declared, a webhook action exists and takes a 'body' parameter, and at most 32 tools and actions in total.",
"description": "A declarative (T0) connector: HTTP tools, actions, a schedule and an inbound webhook expressed as data, run by Minder's connector engine with no plugin code. This schema checks the structure. At load the engine also checks what JSON Schema cannot express: every base host is in the declared egress, placeholders and JMESPath expressions compile, auth fields fit the auth type, step names are unique, a minder_api step appears only in a tool that declares minder_scopes and its route has no empty, '.' or '..' segment, no minder_scopes entry is listed twice, measurements are declared, a webhook action exists and takes a 'body' parameter, and at most 32 tools and actions in total.",
"type": "object",
"required": [
"apiVersion",
Expand Down Expand Up @@ -225,12 +225,25 @@
"properties": {
"effect": {
"type": "null"
},
"minder_scopes": {
"maxItems": 0
},
"steps": {
"type": "array",
"items": {
"properties": {
"minder_api": {
"type": "null"
}
}
}
}
}
}
]
},
"description": "Actions (not exposed as AI tools). An action declares no effect."
"description": "Actions (not exposed as AI tools). An action declares no effect, no minder_scopes and no minder_api step."
},
"schedule": {
"anyOf": [
Expand Down Expand Up @@ -632,19 +645,86 @@
},
"additionalProperties": false
},
"minderApi": {
"type": "object",
"description": "A call to Minder's own API through the platform's minder.api capability, as the invoking user and for the tool's approved minder_scopes. Not external egress.",
"required": [
"route"
],
"properties": {
"route": {
"type": "string",
"minLength": 4,
"maxLength": 2048,
"pattern": "^/v1/[^?#]*$",
"description": "A plugin-callable Minder route, starting with '/v1/'; placeholders are path-encoded."
},
"method": {
"enum": [
"GET",
"POST"
],
"default": "GET"
},
"query": {
"type": "object",
"additionalProperties": {
"type": [
"string",
"number",
"boolean"
]
}
},
"body": {
"description": "The JSON request body (POST only); string values are placeholders."
}
},
"additionalProperties": false,
"if": {
"properties": {
"method": {
"const": "GET"
}
}
},
"then": {
"properties": {
"body": {
"type": "null"
}
}
}
},
"step": {
"type": "object",
"required": [
"name",
"request"
"name"
],
"properties": {
"name": {
"type": "string",
"pattern": "^[a-z][a-z0-9_]{0,63}$"
},
"request": {
"$ref": "#/definitions/request"
"anyOf": [
{
"$ref": "#/definitions/request"
},
{
"type": "null"
}
]
},
"minder_api": {
"anyOf": [
{
"$ref": "#/definitions/minderApi"
},
{
"type": "null"
}
]
},
"when": {
"anyOf": [
Expand Down Expand Up @@ -686,7 +766,30 @@
]
}
},
"additionalProperties": false
"additionalProperties": false,
"oneOf": [
{
"required": [
"request"
],
"properties": {
"request": {
"type": "object"
}
}
},
{
"required": [
"minder_api"
],
"properties": {
"minder_api": {
"type": "object"
}
}
}
],
"description": "One step: an HTTP 'request' through the plugin's egress, or a 'minder_api' call to Minder's own API (not egress). Exactly one of the two."
},
"timeseriesWrite": {
"type": "object",
Expand Down Expand Up @@ -831,6 +934,21 @@
"type": "null"
}
]
},
"minder_scopes": {
"type": "array",
"uniqueItems": true,
"items": {
"enum": [
"conversation.read_current",
"kb.documents.ingest",
"kb.read_passage",
"kb.search",
"ticket.create_internal",
"user.profile.basic"
]
},
"description": "Tools only: the Minder API scopes its minder_api steps use."
}
},
"additionalProperties": false
Expand Down Expand Up @@ -872,8 +990,20 @@
"minItems": 1,
"maxItems": 3,
"items": {
"$ref": "#/definitions/step"
}
"allOf": [
{
"$ref": "#/definitions/step"
},
{
"properties": {
"minder_api": {
"type": "null"
}
}
}
]
},
"description": "The schedule's steps; no minder_api step (that is for AI tools only)."
},
"measurement": {
"type": "string",
Expand Down
50 changes: 49 additions & 1 deletion src/minder_t0_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
written}``. The schedule's collect (:meth:`Engine.run_collect`) does the same:
its result is that object, or its declared ``output`` mapped over the same
context; its ``error_output`` stands in for a failure like an operation's.

A ``minder_api`` step (only in a tool that declares ``minder_scopes``) calls
Minder's own API through the invocation's ``minder`` handle (the platform
context's ``minder.api`` capability), not through the plugin's egress: no
egress rule, rate or concurrency limit applies, but it counts toward the
per-invocation request cap. Its parsed answer is the step's result, like an
HTTP response. Without a bound handle the step raises ``CapabilityDenied``;
the capability's own errors propagate unchanged.
"""

import asyncio
Expand All @@ -48,6 +56,8 @@
import httpx
from jmespath.parser import ParsedResult
from minder_plugin_sdk import line_protocol
from minder_plugin_sdk.context import CAP_MINDER_API
from minder_plugin_sdk.errors import CapabilityDenied

from .egress import AuthInjection, Fetched, PluginEgress
from .errors import (
Expand All @@ -67,6 +77,7 @@
MAX_REQUESTS_PER_INVOCATION,
Base,
DeclarativeManifest,
MinderCall,
Operation,
Request,
Step,
Expand Down Expand Up @@ -167,14 +178,30 @@ class TimeseriesSink(Protocol):
async def write(self, lines: Any, precision: str = "s") -> int: ...


class MinderCaller(Protocol):
"""The platform context's ``minder`` handle (``ctx.minder``), granted for
the invoking tool call's scopes."""

async def call(
self,
route: str,
*,
method: str = "GET",
query: Optional[Mapping[str, Any]] = None,
json: Any = None,
) -> Any: ...


@dataclass
class Invocation:
"""What one call runs with. Built per call; never stored by the engine.
``timeseries`` is where an action's points go (none: nothing written)."""
``timeseries`` is where an action's points go (none: nothing written);
``minder`` is what a ``minder_api`` step calls (none: denied)."""

config: Mapping[str, Any]
secrets: SecretSource
timeseries: Optional[TimeseriesSink] = None
minder: Optional[MinderCaller] = None


def scrub(value: Any, secrets: Iterable[str]) -> Any:
Expand Down Expand Up @@ -355,8 +382,29 @@ async def _fetch(
)
return body, fetched

async def _minder(self, call: MinderCall, ctx: Mapping[str, Any]) -> Any:
if self.inv.minder is None:
raise CapabilityDenied(CAP_MINDER_API, "not bound to this invocation")
route = render(call.route, ctx, PATH) or ""
# The load check again, on the rendered route: an empty value can
# still leave an empty segment.
if any(seg in ("", ".", "..") for seg in route[1:].split("/")):
raise MappingError("minder_api route has an empty, '.' or '..' segment")
query = self._pairs(call.query, ctx, QUERY)
body = self._json(call.json_body, ctx) if call.has_json else None
self.requests += 1
if self.requests > MAX_REQUESTS_PER_INVOCATION:
raise LimitExceeded("requests per invocation")
return await self.inv.minder.call(
route, method=call.method, query=query or None, json=body
)

async def request(self, step: Step, ctx: Mapping[str, Any]) -> Any:
if step.minder is not None:
data = await self._minder(step.minder, ctx)
return search(step.select, data) if step.select is not None else data
req = step.request
assert req is not None # compile: exactly one of request / minder_api
url, origin = self._url(req, ctx)
query = self._pairs(req.query, ctx, QUERY)
headers = self._pairs(req.headers, ctx, HEADER)
Expand Down
Loading
Loading