nutria-plugin 0.6.3__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/CHANGELOG.md +51 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/PKG-INFO +3 -3
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/README.md +2 -2
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/capability-authoring.md +2 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/conversation-ownership.md +6 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/index.md +2 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/manifest.md +1 -1
- nutria_plugin-0.8.0/docs/outside-audience.md +47 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/python-api.md +37 -3
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/quickstart.md +1 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/reviewable-actions.md +45 -4
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/pyproject.toml +1 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/__init__.py +71 -3
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/capabilities.py +57 -8
- nutria_plugin-0.8.0/src/nutria_plugin/conversation_scope.py +50 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/manifest.py +0 -20
- nutria_plugin-0.8.0/src/nutria_plugin/prepared_preview.py +530 -0
- nutria_plugin-0.8.0/tests/test_audience_contract.py +72 -0
- nutria_plugin-0.8.0/tests/test_conversation_scope.py +120 -0
- nutria_plugin-0.8.0/tests/test_receipts.py +180 -0
- nutria_plugin-0.8.0/tests/test_version.py +15 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/uv.lock +1 -1
- nutria_plugin-0.6.3/src/nutria_plugin/prepared_preview.py +0 -163
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/.github/workflows/publish.yml +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/.gitignore +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/admin-extensions.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/admin-flows.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/cli.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/connection-types.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/migration-6.0.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/security.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/docs/skill-format.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/examples/my-first-plugin/README.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/examples/my-first-plugin/hooks/hooks.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/examples/my-first-plugin/plugin.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/examples/my-first-plugin/settings.schema.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/bundle.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/cli.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/domains.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/hierarchy.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/mcp_results.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/migrate.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/operation_facts.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/ownership.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/packaging.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/signing.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/src/nutria_plugin/skills.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/__init__.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_bundle.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_capability_contracts.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_cli.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_contract_vnext.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_hierarchy.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_manifest.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_mcp_results.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_ownership.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_packaging.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_prepared_preview.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_reviewable_actions.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_signing.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.8.0}/tests/test_skill_format_docs.py +0 -0
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
Breaking for manifests that relied on the older, looser audience rules; additive for receipt-aware plugins.
|
|
6
|
+
|
|
7
|
+
- Model the prepared-preview receipt. `PluginReceipt` describes the top-level `receipt` object;
|
|
8
|
+
`HOST_CONTROL_RECEIPT_FIELDS` maps `prepared_action.state_fingerprint` and
|
|
9
|
+
`prepared_action.normalized_effect_fingerprint` to `state_fingerprint` and
|
|
10
|
+
`normalized_effect_fingerprint`; `required_receipt_fields` reads both per-argument
|
|
11
|
+
`x-nutria-host-control` markers and projected `metadata.host_control_bindings`.
|
|
12
|
+
- Add `check_receipt_bindings` and `assert_receipt_bindings`; the latter raises `ReceiptBindingError`
|
|
13
|
+
naming every missing or empty field. Add `RECEIPT_CONFORMANCE_VECTORS` next to the existing preview
|
|
14
|
+
vectors.
|
|
15
|
+
- Add `assert_server_receipt_bindings`/`host_controlled_tools` for plugin tests over every tool whose
|
|
16
|
+
schema declares a host-control marker, and dependency-free `assert_host_preserves_receipt` for Host
|
|
17
|
+
adapter tests.
|
|
18
|
+
- Enforce the closed audience vocabulary (`public_customer`, `private_internal`, `team_internal`).
|
|
19
|
+
Unknown audience values now fail validation.
|
|
20
|
+
- Treat `personal_identifier` as a private output class, like the Host. A `public_customer` capability
|
|
21
|
+
returning `personal_identifier`, `personal_content`, or `special_category` must scope an input to the
|
|
22
|
+
conversation contact.
|
|
23
|
+
- Require the `public_customer` audience when an input declares `scope: "conversation_contact"`.
|
|
24
|
+
- `__version__` now comes from package metadata (or the adjacent `pyproject.toml` in a source
|
|
25
|
+
checkout), with a test that it equals the project version.
|
|
26
|
+
- Remove unused `PreparationToolContract` and `normalize_capability_map`.
|
|
27
|
+
|
|
28
|
+
### Migration notes
|
|
29
|
+
|
|
30
|
+
- A `public_customer` capability that returns `personal_identifier` without a conversation-scoped input
|
|
31
|
+
is now rejected. Either scope the contact input or drop `public_customer` from its audience. MRW
|
|
32
|
+
`mrw.shipments.status` is one such capability in 0.8.9-beta.
|
|
33
|
+
- A capability that declares `scope: "conversation_contact"` must also declare `public_customer`;
|
|
34
|
+
internal-only capabilities cannot use the scope.
|
|
35
|
+
- Replace any audience value outside the three-name vocabulary; `everyone` and similar values are
|
|
36
|
+
invalid.
|
|
37
|
+
- Plugins importing `PreparationToolContract` or calling `normalize_capability_map` must remove those
|
|
38
|
+
references; both were unused and are gone.
|
|
39
|
+
- A plugin that had pinned `nutria-plugin>=0.6.1` inherits these stricter rules on upgrade; validate
|
|
40
|
+
before publishing.
|
|
41
|
+
|
|
42
|
+
## 0.7.0
|
|
43
|
+
|
|
44
|
+
Additive; manifests that do not use the new field are unchanged.
|
|
45
|
+
|
|
46
|
+
- Add `scope: "conversation_contact"` on a capability value input: the argument that names the person the conversation is with.
|
|
47
|
+
In a `public_customer` turn the host sets it itself, so neither the model nor the outside person chooses whose data is read.
|
|
48
|
+
- New validators: only a `personal_identifier` value input of a read capability can be scoped (one per capability); a
|
|
49
|
+
`public_customer` capability must be a read, must not take another person-identifying input, and must scope an input when it
|
|
50
|
+
returns personal or special-category content.
|
|
51
|
+
- Add `nutria_plugin.conversation_scope` (`scoped_argument`, `offered_to_outside_audience`, `apply_conversation_scope`): the one
|
|
52
|
+
definition of the pinning rule for hosts and plugin tests. See `docs/outside-audience.md`.
|
|
53
|
+
|
|
3
54
|
## 0.6.3
|
|
4
55
|
|
|
5
56
|
Additive.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nutria-plugin
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: SDK for building, validating, signing, and packaging Nutria plugins
|
|
5
5
|
Project-URL: Homepage, https://github.com/AlRos14/nutria-plugin-sdk
|
|
6
6
|
Project-URL: Repository, https://github.com/AlRos14/nutria-plugin-sdk
|
|
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
|
|
|
22
22
|
|
|
23
23
|
SDK for building, validating, signing, and packaging Nutria plugins.
|
|
24
24
|
|
|
25
|
-
Release `0.
|
|
25
|
+
Release `0.8.0` accepts only manifest schema `6.0`. Capabilities use their real
|
|
26
26
|
business effect (`read`, `write`, or `external_write`); preparation is expressed
|
|
27
27
|
by producing `prepared_action`, not by a workflow-phase effect. Every parsed
|
|
28
28
|
requirement resolves `task_context` to `required`, `optional`, or `forbidden`,
|
|
@@ -35,7 +35,7 @@ and exact delivery of an approved snapshot.
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
uv add nutria-plugin==0.
|
|
38
|
+
uv add nutria-plugin==0.8.0
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Scaffold and validate
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SDK for building, validating, signing, and packaging Nutria plugins.
|
|
4
4
|
|
|
5
|
-
Release `0.
|
|
5
|
+
Release `0.8.0` accepts only manifest schema `6.0`. Capabilities use their real
|
|
6
6
|
business effect (`read`, `write`, or `external_write`); preparation is expressed
|
|
7
7
|
by producing `prepared_action`, not by a workflow-phase effect. Every parsed
|
|
8
8
|
requirement resolves `task_context` to `required`, `optional`, or `forbidden`,
|
|
@@ -15,7 +15,7 @@ and exact delivery of an approved snapshot.
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
uv add nutria-plugin==0.
|
|
18
|
+
uv add nutria-plugin==0.8.0
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Scaffold and validate
|
|
@@ -103,6 +103,8 @@ implementation.
|
|
|
103
103
|
|
|
104
104
|
Schema extension keys the host understands on a tool argument: `x-nutria-host-control` (the host
|
|
105
105
|
supplies the value, for example a state fingerprint). Anything else under `x-nutria-` is host-private.
|
|
106
|
+
A tool with a host-control argument must also return the matching fingerprint in its preview's
|
|
107
|
+
top-level `receipt`; see `reviewable-actions.md` and `assert_receipt_bindings`.
|
|
106
108
|
|
|
107
109
|
## 6. Hierarchical attribute operations
|
|
108
110
|
|
|
@@ -27,3 +27,9 @@ A plugin that knows only who is a human (as the WhatsApp plugin did with `owners
|
|
|
27
27
|
## What a host must do
|
|
28
28
|
Resolve the answering agent from the plugin's report and its own ownership record, with the priority above; release agent ownership when the agent closes the
|
|
29
29
|
conversation, the contact asks to stop, a person takes over, or the conversation has been idle for the host's configured time.
|
|
30
|
+
|
|
31
|
+
## Ids and granularity (new channels)
|
|
32
|
+
- `contact_id` in the event is the unit that has one owner. Choose it per channel: a user for direct messages, a thread for channel threads.
|
|
33
|
+
- Outbound recipients must use the same form as `contact_id`, so a message an agent sends is matched with the replies it receives.
|
|
34
|
+
- The host keeps ids as written (trimmed, lowercased). Emails and phone numbers get a canonical form; nothing else is rewritten.
|
|
35
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# nutria-plugin SDK documentation
|
|
2
2
|
|
|
3
|
-
Developer reference for SDK `0.
|
|
3
|
+
Developer reference for SDK `0.8.0` and manifest schema `6.0`.
|
|
4
4
|
|
|
5
5
|
| Document | Purpose |
|
|
6
6
|
|---|---|
|
|
@@ -8,6 +8,7 @@ Developer reference for SDK `0.6.2` and manifest schema `6.0`.
|
|
|
8
8
|
| [migration-6.0.md](migration-6.0.md) | Migrate a 5.0 plugin to 6.0 |
|
|
9
9
|
| [manifest.md](manifest.md) | Manifest, capability, and provider contracts |
|
|
10
10
|
| [capability-authoring.md](capability-authoring.md) | Effect scope, completion, operation facts, data classes, PreparedActions, validation errors |
|
|
11
|
+
| [outside-audience.md](outside-audience.md) | Capabilities offered to an outside audience, scoped to the conversation contact |
|
|
11
12
|
| [reviewable-actions.md](reviewable-actions.md) | Host-owned drafts and external delivery |
|
|
12
13
|
| [python-api.md](python-api.md) | Public Python API |
|
|
13
14
|
| [connection-types.md](connection-types.md) | Supported runtime/connection types |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# plugin.json manifest reference
|
|
2
2
|
|
|
3
3
|
`plugin.json` is the single source of truth for plugin identity, runtime,
|
|
4
|
-
capability authority, prepared-action provider defaults, and provider topology. SDK 0.
|
|
4
|
+
capability authority, prepared-action provider defaults, and provider topology. SDK 0.8.0 accepts exactly schema
|
|
5
5
|
`6.0`; older schemas and unknown fields fail validation.
|
|
6
6
|
|
|
7
7
|
## Required top-level fields
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Capabilities for an outside audience
|
|
2
|
+
|
|
3
|
+
An agent that answers a person outside the company works in a `public_customer` turn. A capability is offered to that
|
|
4
|
+
audience only if its manifest says so (`requirements.audience` contains `public_customer`). Most capabilities are not.
|
|
5
|
+
|
|
6
|
+
## Audience vocabulary
|
|
7
|
+
|
|
8
|
+
`requirements.audience` accepts exactly `public_customer`, `private_internal`, and `team_internal`. The SDK rejects any
|
|
9
|
+
other value; the Host uses the same closed vocabulary.
|
|
10
|
+
|
|
11
|
+
## The rule
|
|
12
|
+
|
|
13
|
+
A capability offered to `public_customer`:
|
|
14
|
+
|
|
15
|
+
- is a **read** (`effect: read`); writes and sends go through the host's own approval path;
|
|
16
|
+
- takes **no person-identifying input** (`data_class: personal_identifier`) except the one scoped to the conversation contact;
|
|
17
|
+
- if it returns `personal_identifier`, `personal_content`, or `special_category` data, **must scope an input to the
|
|
18
|
+
conversation contact**. Those three classes are private outputs.
|
|
19
|
+
|
|
20
|
+
A capability **not** offered to `public_customer` must not declare `scope: "conversation_contact"`: the scope exists only
|
|
21
|
+
to pin an outside-audience turn.
|
|
22
|
+
|
|
23
|
+
## Scoping an input
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{"kind": "value", "semantic_field": "chat", "argument_name": "chat", "required": false,
|
|
27
|
+
"data_class": "personal_identifier", "accepted_origins": ["current_user"], "scope": "conversation_contact"}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`scope: "conversation_contact"` means: this argument names the one person the conversation is with. In an outside-audience
|
|
31
|
+
turn the host **sets it itself**, replacing whatever the model sent and filling it when the model left it out. The person
|
|
32
|
+
writing to the agent cannot choose another chat by mentioning it. Only a `value` input of class `personal_identifier` can carry
|
|
33
|
+
the scope, and a capability has at most one.
|
|
34
|
+
|
|
35
|
+
`nutria_plugin.apply_conversation_scope(capability, arguments, contact)` is the reference rule hosts and plugin tests share.
|
|
36
|
+
|
|
37
|
+
## What the plugin must guarantee
|
|
38
|
+
|
|
39
|
+
The host fixes the argument; the plugin must make sure that, when the argument is given, **every** result belongs to that
|
|
40
|
+
person: a search with a chat never returns another chat, an item fetched by id is refused when it is not part of that chat,
|
|
41
|
+
and a list is limited to that chat. A capability that cannot guarantee this must not declare `public_customer`.
|
|
42
|
+
|
|
43
|
+
## What is not covered
|
|
44
|
+
|
|
45
|
+
A capability that needs no contact (for example public pickup points) declares `public_customer` without a scope. It must not
|
|
46
|
+
return personal content. A resource a person quotes (such as a tracking number) is not a conversation scope: decide whether the
|
|
47
|
+
data behind it is safe to show to whoever sends that number.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Python API reference
|
|
2
2
|
|
|
3
|
-
SDK 0.
|
|
3
|
+
SDK 0.8.0 exposes the strict schema 6.0 API.
|
|
4
4
|
|
|
5
5
|
```python
|
|
6
6
|
from nutria_plugin import (
|
|
@@ -11,15 +11,19 @@ from nutria_plugin import (
|
|
|
11
11
|
ResourceBinding, ResourceType, ResourceTypeDescriptor,
|
|
12
12
|
WorldProjectionDescriptor, WorldProviderDescriptor,
|
|
13
13
|
PreparedActionDescriptor, IdempotencyDescriptor, CompletionDescriptor,
|
|
14
|
-
NonCallableReason,
|
|
14
|
+
NonCallableReason, AUDIENCE_VOCABULARY, PRIVATE_OUTPUT_CLASSES,
|
|
15
15
|
ReviewableActionContract, ReviewableActionField, ReviewableActionMode,
|
|
16
|
-
PreparationToolContract,
|
|
17
16
|
PluginAdminExtension, PluginAdminExtensionKind,
|
|
18
17
|
PluginAdminExtensionPlacement,
|
|
19
18
|
PluginAdminFlow, PluginAdminFlowKind, PluginAdminFlowPlacement,
|
|
20
19
|
PluginBundleError, load_plugin_bundle, extract_plugin_bundle, validate_zip,
|
|
21
20
|
PackagingError, scaffold_plugin, pack_plugin, validate_plugin_dir,
|
|
22
21
|
SignatureStatus, generate_keypair, sign_manifest, verify_manifest,
|
|
22
|
+
PluginReceipt, ReceiptBindingError, HOST_CONTROL_RECEIPT_FIELDS,
|
|
23
|
+
RECEIPT_CONFORMANCE_VECTORS, required_receipt_fields,
|
|
24
|
+
check_receipt_bindings, assert_receipt_bindings,
|
|
25
|
+
assert_server_receipt_bindings, host_controlled_tools,
|
|
26
|
+
assert_host_preserves_receipt,
|
|
23
27
|
)
|
|
24
28
|
```
|
|
25
29
|
|
|
@@ -76,3 +80,33 @@ status = verify_manifest(payload)
|
|
|
76
80
|
```
|
|
77
81
|
|
|
78
82
|
Signing uses ECDSA P-256 over canonical JSON with the `signature` field removed.
|
|
83
|
+
|
|
84
|
+
## Conversation scope
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from nutria_plugin import apply_conversation_scope, scoped_argument
|
|
88
|
+
|
|
89
|
+
arguments = apply_conversation_scope(capability, {"chat": "whatever the model sent"}, contact="34600000000")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
For a capability offered to `public_customer`, the argument declared with `scope: "conversation_contact"` is replaced by the
|
|
93
|
+
conversation contact. See `outside-audience.md`.
|
|
94
|
+
|
|
95
|
+
## Preview receipts
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from nutria_plugin import (
|
|
99
|
+
PluginReceipt, ReceiptBindingError,
|
|
100
|
+
assert_receipt_bindings, assert_server_receipt_bindings,
|
|
101
|
+
assert_host_preserves_receipt,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
receipt = PluginReceipt.model_validate(preview["receipt"])
|
|
105
|
+
assert_receipt_bindings(tool_input_schema, preview)
|
|
106
|
+
checked = assert_server_receipt_bindings(server_tools, {"create_shipment": preview})
|
|
107
|
+
assert_host_preserves_receipt(host_tool_result, preview, input_schema=tool_input_schema)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A tool argument marked `x-nutria-host-control` binds a top-level `receipt` field. The shared
|
|
111
|
+
`RECEIPT_CONFORMANCE_VECTORS` cover a populated receipt, a missing receipt, and empty fields. See
|
|
112
|
+
`reviewable-actions.md`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reviewable actions and external writes
|
|
2
2
|
|
|
3
|
-
SDK 0.
|
|
3
|
+
SDK 0.8.0 schema 6.0 defines one reviewable-action architecture:
|
|
4
4
|
|
|
5
5
|
```text
|
|
6
6
|
ChatBotNutralia -> task context, encrypted draft, revision, approval, idempotency, receipts
|
|
@@ -36,9 +36,9 @@ requirements, input bindings, and `reviewable_action_id`:
|
|
|
36
36
|
},
|
|
37
37
|
"reviewable_action_id": "whatsapp-text",
|
|
38
38
|
"inputs": [
|
|
39
|
-
{"kind": "value", "semantic_field": "recipient", "argument_name": "recipient", "
|
|
40
|
-
{"kind": "value", "semantic_field": "body", "argument_name": "body", "
|
|
41
|
-
{"kind": "value", "semantic_field": "idempotency_key", "argument_name": "idempotency_key", "
|
|
39
|
+
{"kind": "value", "semantic_field": "recipient", "argument_name": "recipient", "data_class": "personal_identifier", "accepted_origins": ["current_user", "world_resource"]},
|
|
40
|
+
{"kind": "value", "semantic_field": "body", "argument_name": "body", "data_class": "personal_content", "accepted_origins": ["current_user"]},
|
|
41
|
+
{"kind": "value", "semantic_field": "idempotency_key", "argument_name": "idempotency_key", "data_class": "non_personal", "accepted_origins": ["current_user"]}
|
|
42
42
|
]
|
|
43
43
|
}
|
|
44
44
|
```
|
|
@@ -76,6 +76,47 @@ recipient/thread/source fingerprints, or `write` when it mutates local durable
|
|
|
76
76
|
state. The action's `prepare_capability` and `execute_capability` must be
|
|
77
77
|
distinct and use the same connection.
|
|
78
78
|
|
|
79
|
+
## Preview receipts and host-control bindings
|
|
80
|
+
|
|
81
|
+
A preparation tool whose input schema marks an argument with `x-nutria-host-control` must return
|
|
82
|
+
the matching fingerprint in the preview's **top-level `receipt` object**:
|
|
83
|
+
|
|
84
|
+
| Schema marker | Receipt field |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `prepared_action.state_fingerprint` | `state_fingerprint` |
|
|
87
|
+
| `prepared_action.normalized_effect_fingerprint` | `normalized_effect_fingerprint` |
|
|
88
|
+
|
|
89
|
+
The Host projects the same markers into `metadata.host_control_bindings` and refuses a preview
|
|
90
|
+
that omits or blanks a bound field. `nutria_plugin.PluginReceipt` models the object; the Host may
|
|
91
|
+
add its own fields (`policy_set_fingerprint`, `review_state`), so unknown keys are preserved.
|
|
92
|
+
|
|
93
|
+
`nutria_plugin.assert_receipt_bindings(input_schema, preview_result)` raises
|
|
94
|
+
`ReceiptBindingError` naming every missing or empty field. `check_receipt_bindings` returns the
|
|
95
|
+
same findings as stable `missing_receipt_field:<field>` / `empty_receipt_field:<field>` codes.
|
|
96
|
+
`RECEIPT_CONFORMANCE_VECTORS` are shared positive and negative cases for plugin tests and hosts.
|
|
97
|
+
|
|
98
|
+
A plugin test can check every tool of its MCP server without importing the SDK's MCP stack:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from nutria_plugin import assert_server_receipt_bindings
|
|
102
|
+
|
|
103
|
+
tools = mcp._tool_manager.list_tools() # or any objects with name + parameters/inputSchema
|
|
104
|
+
previews = {"create_shipment": await create_shipment(..., preview_only=True)}
|
|
105
|
+
checked = assert_server_receipt_bindings(tools, previews)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Only tools whose schema declares a host-control marker are checked; a host-controlled tool with
|
|
109
|
+
no supplied preview is an error. A Host test can prove its adapter still carries the receipt:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from nutria_plugin import assert_host_preserves_receipt
|
|
113
|
+
|
|
114
|
+
assert_host_preserves_receipt(host_tool_result, provider_preview, input_schema=tool_schema)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The helper is dependency-free: it accepts the Host's `ToolResult` shape (a `receipt` attribute or
|
|
118
|
+
a `data` mapping) and fails when a bound field was dropped, blanked, or changed.
|
|
119
|
+
|
|
79
120
|
## Host lifecycle
|
|
80
121
|
|
|
81
122
|
The host exposes generic prepare, inspect, revise, and send operations. A
|
|
@@ -15,9 +15,13 @@ Signing:
|
|
|
15
15
|
generate_keypair, sign_manifest, verify_manifest, SignatureStatus
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import tomllib
|
|
19
|
+
from importlib.metadata import PackageNotFoundError, version as _distribution_version
|
|
20
|
+
from pathlib import Path
|
|
19
21
|
|
|
20
22
|
from .capabilities import (
|
|
23
|
+
AUDIENCE_VOCABULARY,
|
|
24
|
+
PRIVATE_OUTPUT_CLASSES,
|
|
21
25
|
CapabilityDescriptor,
|
|
22
26
|
CapabilityEffect,
|
|
23
27
|
CapabilityExposure,
|
|
@@ -37,6 +41,12 @@ from .capabilities import (
|
|
|
37
41
|
WorldProjectionDescriptor,
|
|
38
42
|
WorldProviderDescriptor,
|
|
39
43
|
)
|
|
44
|
+
from .conversation_scope import (
|
|
45
|
+
CONVERSATION_CONTACT,
|
|
46
|
+
apply_conversation_scope,
|
|
47
|
+
offered_to_outside_audience,
|
|
48
|
+
scoped_argument,
|
|
49
|
+
)
|
|
40
50
|
from .ownership import (
|
|
41
51
|
OWNER_PRIORITY,
|
|
42
52
|
ConversationOwnership,
|
|
@@ -44,8 +54,19 @@ from .ownership import (
|
|
|
44
54
|
ownership_from_event_payload,
|
|
45
55
|
)
|
|
46
56
|
from .prepared_preview import (
|
|
57
|
+
HOST_CONTROL_RECEIPT_FIELDS,
|
|
47
58
|
PREVIEW_CONFORMANCE_VECTORS,
|
|
59
|
+
RECEIPT_CONFORMANCE_VECTORS,
|
|
60
|
+
PluginReceipt,
|
|
61
|
+
ReceiptBindingError,
|
|
62
|
+
assert_host_preserves_receipt,
|
|
63
|
+
assert_receipt_bindings,
|
|
64
|
+
assert_server_receipt_bindings,
|
|
48
65
|
check_prepared_preview,
|
|
66
|
+
check_receipt_bindings,
|
|
67
|
+
host_controlled_tools,
|
|
68
|
+
receipt_field_for_control,
|
|
69
|
+
required_receipt_fields,
|
|
49
70
|
)
|
|
50
71
|
from .domains import CapabilityDomain, CAPABILITY_DOMAIN_IDS, DOMAIN_LABELS
|
|
51
72
|
from .hierarchy import (
|
|
@@ -67,7 +88,6 @@ from .manifest import (
|
|
|
67
88
|
PluginAdminFlowPlacement,
|
|
68
89
|
PluginManifest,
|
|
69
90
|
PluginPaths,
|
|
70
|
-
PreparationToolContract,
|
|
71
91
|
ReviewableActionContract,
|
|
72
92
|
ReviewableActionField,
|
|
73
93
|
ReviewableActionMode,
|
|
@@ -88,8 +108,44 @@ from .mcp_results import (
|
|
|
88
108
|
from .operation_facts import OPERATION_FACTS_KEY, OperationFacts, TargetFact, extract_operation_facts
|
|
89
109
|
from .skills import SkillFrontmatter, parse_skill_frontmatter
|
|
90
110
|
|
|
111
|
+
_FALLBACK_VERSION = "0.8.0"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _source_checkout_version() -> str | None:
|
|
115
|
+
"""Read the adjacent pyproject.toml when this module is imported from a source tree."""
|
|
116
|
+
pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
|
|
117
|
+
if not pyproject.is_file():
|
|
118
|
+
return None
|
|
119
|
+
try:
|
|
120
|
+
project = tomllib.loads(pyproject.read_text(encoding="utf-8")).get("project") or {}
|
|
121
|
+
except (OSError, ValueError, tomllib.TOMLDecodeError):
|
|
122
|
+
return None
|
|
123
|
+
value = str(project.get("version") or "").strip()
|
|
124
|
+
return value or None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _distribution_version_fallback() -> str:
|
|
128
|
+
try:
|
|
129
|
+
return _distribution_version("nutria-plugin")
|
|
130
|
+
except PackageNotFoundError:
|
|
131
|
+
return _FALLBACK_VERSION
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _resolve_version() -> str:
|
|
135
|
+
# A source checkout is authoritative: an unrelated installed distribution (for example a
|
|
136
|
+
# host venv's older SDK) must not make this tree report a different version.
|
|
137
|
+
return _source_checkout_version() or _distribution_version_fallback()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
__version__ = _resolve_version()
|
|
141
|
+
|
|
91
142
|
__all__ = [
|
|
92
143
|
"__version__",
|
|
144
|
+
# Conversation scope for outside audiences
|
|
145
|
+
"CONVERSATION_CONTACT",
|
|
146
|
+
"apply_conversation_scope",
|
|
147
|
+
"offered_to_outside_audience",
|
|
148
|
+
"scoped_argument",
|
|
93
149
|
# Conversation ownership
|
|
94
150
|
"OWNER_PRIORITY",
|
|
95
151
|
"ConversationOwnership",
|
|
@@ -112,7 +168,8 @@ __all__ = [
|
|
|
112
168
|
"ReviewableActionContract",
|
|
113
169
|
"ReviewableActionMode",
|
|
114
170
|
"ReviewableActionField",
|
|
115
|
-
"
|
|
171
|
+
"AUDIENCE_VOCABULARY",
|
|
172
|
+
"PRIVATE_OUTPUT_CLASSES",
|
|
116
173
|
"CapabilityDescriptor",
|
|
117
174
|
"CapabilityEffect",
|
|
118
175
|
"CapabilityExposure",
|
|
@@ -156,7 +213,18 @@ __all__ = [
|
|
|
156
213
|
"MCPResultContractError",
|
|
157
214
|
# Prepared-preview conformance
|
|
158
215
|
"PREVIEW_CONFORMANCE_VECTORS",
|
|
216
|
+
"RECEIPT_CONFORMANCE_VECTORS",
|
|
217
|
+
"HOST_CONTROL_RECEIPT_FIELDS",
|
|
218
|
+
"PluginReceipt",
|
|
219
|
+
"ReceiptBindingError",
|
|
220
|
+
"receipt_field_for_control",
|
|
221
|
+
"required_receipt_fields",
|
|
159
222
|
"check_prepared_preview",
|
|
223
|
+
"check_receipt_bindings",
|
|
224
|
+
"assert_receipt_bindings",
|
|
225
|
+
"assert_server_receipt_bindings",
|
|
226
|
+
"host_controlled_tools",
|
|
227
|
+
"assert_host_preserves_receipt",
|
|
160
228
|
"normalize_mcp_result",
|
|
161
229
|
"project_result_path",
|
|
162
230
|
"validate_capability_result",
|
|
@@ -13,6 +13,9 @@ from .hierarchy import HierarchicalAttributeDescriptor
|
|
|
13
13
|
|
|
14
14
|
_RESOURCE_TYPE_PATTERN = r"^[a-z][a-z0-9_.-]{0,127}$"
|
|
15
15
|
|
|
16
|
+
#: The audience vocabulary shared with the Host. Unknown values fail validation.
|
|
17
|
+
AUDIENCE_VOCABULARY = frozenset({"public_customer", "private_internal", "team_internal"})
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
class CapabilityEffect(str, Enum):
|
|
18
21
|
READ = "read"
|
|
@@ -44,6 +47,12 @@ class DataClass(str, Enum):
|
|
|
44
47
|
SPECIAL_CATEGORY = "special_category"
|
|
45
48
|
|
|
46
49
|
|
|
50
|
+
#: Output classes the Host treats as private for an outside audience.
|
|
51
|
+
PRIVATE_OUTPUT_CLASSES = frozenset(
|
|
52
|
+
{DataClass.PERSONAL_IDENTIFIER, DataClass.PERSONAL_CONTENT, DataClass.SPECIAL_CATEGORY}
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
47
56
|
class CapabilityExposure(str, Enum):
|
|
48
57
|
"""Who may invoke a graph-visible capability."""
|
|
49
58
|
|
|
@@ -182,7 +191,16 @@ class CapabilityRequirement(BaseModel):
|
|
|
182
191
|
@field_validator("audience")
|
|
183
192
|
@classmethod
|
|
184
193
|
def _validate_audience(cls, value: list[str]) -> list[str]:
|
|
185
|
-
|
|
194
|
+
cleaned = list(dict.fromkeys(item.strip() for item in value if item.strip()))
|
|
195
|
+
unknown = sorted(set(cleaned) - AUDIENCE_VOCABULARY)
|
|
196
|
+
if unknown:
|
|
197
|
+
raise ValueError(
|
|
198
|
+
"capability audience must use "
|
|
199
|
+
+ ", ".join(sorted(AUDIENCE_VOCABULARY))
|
|
200
|
+
+ "; unknown: "
|
|
201
|
+
+ ", ".join(unknown)
|
|
202
|
+
)
|
|
203
|
+
return cleaned
|
|
186
204
|
|
|
187
205
|
|
|
188
206
|
class ResourceBinding(BaseModel):
|
|
@@ -213,6 +231,10 @@ class CapabilityInputBinding(BaseModel):
|
|
|
213
231
|
data_class: DataClass
|
|
214
232
|
requires_provenance: bool = False
|
|
215
233
|
accepted_origins: list[Literal["current_user", "world_resource"]] = Field(min_length=1)
|
|
234
|
+
# ``conversation_contact``: this argument names the one person the conversation is with. When the host
|
|
235
|
+
# runs the capability for an outside audience it sets the argument itself, whatever the model sent
|
|
236
|
+
# or left empty. See ``nutria_plugin.conversation_scope``.
|
|
237
|
+
scope: Literal["conversation_contact"] | None = None
|
|
216
238
|
|
|
217
239
|
model_config = {"extra": "forbid"}
|
|
218
240
|
|
|
@@ -225,6 +247,11 @@ class CapabilityInputBinding(BaseModel):
|
|
|
225
247
|
|
|
226
248
|
@model_validator(mode="after")
|
|
227
249
|
def _validate_kind(self) -> "CapabilityInputBinding":
|
|
250
|
+
if self.scope is not None:
|
|
251
|
+
if self.kind != "value":
|
|
252
|
+
raise ValueError("a conversation-scoped input must be a value input")
|
|
253
|
+
if self.data_class != DataClass.PERSONAL_IDENTIFIER:
|
|
254
|
+
raise ValueError("a conversation-scoped input must have data_class personal_identifier")
|
|
228
255
|
if self.kind == "resource" and self.resource_type is None:
|
|
229
256
|
raise ValueError("resource inputs require resource_type")
|
|
230
257
|
if self.kind == "value" and self.resource_type is not None:
|
|
@@ -405,6 +432,35 @@ class CapabilityDescriptor(BaseModel):
|
|
|
405
432
|
input_names = [item.semantic_field for item in self.inputs]
|
|
406
433
|
if len(input_names) != len(set(input_names)):
|
|
407
434
|
raise ValueError("capability inputs must not repeat semantic fields")
|
|
435
|
+
scoped = [item for item in self.inputs if item.scope is not None]
|
|
436
|
+
if len(scoped) > 1:
|
|
437
|
+
raise ValueError("a capability may scope only one input to the conversation contact")
|
|
438
|
+
if scoped and self.effect != CapabilityEffect.READ:
|
|
439
|
+
raise ValueError("only read capabilities may scope an input to the conversation contact")
|
|
440
|
+
if scoped and "public_customer" not in self.requirements.audience:
|
|
441
|
+
raise ValueError(
|
|
442
|
+
"a conversation-scoped input requires the public_customer audience"
|
|
443
|
+
)
|
|
444
|
+
if "public_customer" in self.requirements.audience:
|
|
445
|
+
if self.effect != CapabilityEffect.READ:
|
|
446
|
+
raise ValueError("only read capabilities may be offered to the public_customer audience")
|
|
447
|
+
others = [
|
|
448
|
+
item
|
|
449
|
+
for item in self.inputs
|
|
450
|
+
if item.scope is None and item.data_class == DataClass.PERSONAL_IDENTIFIER
|
|
451
|
+
]
|
|
452
|
+
if others:
|
|
453
|
+
raise ValueError(
|
|
454
|
+
"a public_customer capability must not take another person-identifying input: "
|
|
455
|
+
"scope it to the conversation contact"
|
|
456
|
+
)
|
|
457
|
+
if not scoped and any(
|
|
458
|
+
out.data_class in PRIVATE_OUTPUT_CLASSES for out in self.produces
|
|
459
|
+
):
|
|
460
|
+
raise ValueError(
|
|
461
|
+
"a public_customer capability that returns personal or identifying content "
|
|
462
|
+
"must scope an input to the conversation contact"
|
|
463
|
+
)
|
|
408
464
|
output_names = [item.output_name for item in self.produces]
|
|
409
465
|
if len(output_names) != len(set(output_names)):
|
|
410
466
|
raise ValueError("capability outputs must not repeat output names")
|
|
@@ -448,10 +504,3 @@ class CapabilityDescriptor(BaseModel):
|
|
|
448
504
|
if not self.inputs:
|
|
449
505
|
raise ValueError("model-selectable writes require declared inputs")
|
|
450
506
|
return self
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
def normalize_capability_map(value: Any) -> list[CapabilityDescriptor]:
|
|
454
|
-
"""Parse a manifest capability list with a useful validation error."""
|
|
455
|
-
if not isinstance(value, list):
|
|
456
|
-
raise ValueError("capabilities must be a list of capability descriptors")
|
|
457
|
-
return [CapabilityDescriptor.model_validate(item) for item in value]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Pin a capability to the person a conversation is with.
|
|
2
|
+
|
|
3
|
+
A capability offered to an outside audience (``public_customer``) must never let the model, or the person
|
|
4
|
+
writing to it, choose whose data is read. The capability declares which argument names that person
|
|
5
|
+
(``scope: "conversation_contact"`` on the input); a host runs this rule before every call in such a turn.
|
|
6
|
+
It is pure (no I/O) so a plugin's tests and every host share one definition.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
CONVERSATION_CONTACT = "conversation_contact"
|
|
15
|
+
OUTSIDE_AUDIENCE = "public_customer"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def scoped_argument(capability: Mapping[str, Any]) -> str | None:
|
|
19
|
+
"""The argument that names the conversation contact, or None when the capability declares none."""
|
|
20
|
+
for item in capability.get("inputs") or []:
|
|
21
|
+
if isinstance(item, Mapping) and item.get("scope") == CONVERSATION_CONTACT:
|
|
22
|
+
name = item.get("argument_name")
|
|
23
|
+
return str(name) if name else None
|
|
24
|
+
return None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def offered_to_outside_audience(capability: Mapping[str, Any]) -> bool:
|
|
28
|
+
requirements = capability.get("requirements")
|
|
29
|
+
audience = requirements.get("audience") if isinstance(requirements, Mapping) else None
|
|
30
|
+
return isinstance(audience, list) and OUTSIDE_AUDIENCE in audience
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def apply_conversation_scope(
|
|
34
|
+
capability: Mapping[str, Any], arguments: Mapping[str, Any], contact: str
|
|
35
|
+
) -> dict[str, Any]:
|
|
36
|
+
"""Arguments for one call in an outside-audience turn: the contact replaces whatever was sent.
|
|
37
|
+
|
|
38
|
+
Raises ``ValueError`` when the capability is not offered to the outside audience, when it declares a
|
|
39
|
+
person-identifying input without scope, or when the contact is empty. A capability that declares no
|
|
40
|
+
scoped input is returned unchanged (it reads nothing about a person).
|
|
41
|
+
"""
|
|
42
|
+
if not offered_to_outside_audience(capability):
|
|
43
|
+
raise ValueError("capability is not offered to the public_customer audience")
|
|
44
|
+
if not str(contact or "").strip():
|
|
45
|
+
raise ValueError("an outside-audience call needs the conversation contact")
|
|
46
|
+
argument = scoped_argument(capability)
|
|
47
|
+
result = dict(arguments)
|
|
48
|
+
if argument is not None:
|
|
49
|
+
result[argument] = str(contact).strip()
|
|
50
|
+
return result
|
|
@@ -93,26 +93,6 @@ class ReviewableActionField(str, Enum):
|
|
|
93
93
|
MODE = "mode"
|
|
94
94
|
|
|
95
95
|
|
|
96
|
-
class PreparationToolContract(BaseModel):
|
|
97
|
-
"""Optional pure adapter used to resolve a reply envelope.
|
|
98
|
-
|
|
99
|
-
Preparation may read a connector and return structured provenance, but it
|
|
100
|
-
can never persist a draft or perform an external write.
|
|
101
|
-
"""
|
|
102
|
-
|
|
103
|
-
name: str = Field(..., pattern=r"^[a-zA-Z][a-zA-Z0-9_-]{0,127}$")
|
|
104
|
-
external_write: bool = False
|
|
105
|
-
side_effect: str = Field(default="read", pattern=r"^(read|pure|none)$")
|
|
106
|
-
|
|
107
|
-
model_config = {"extra": "forbid"}
|
|
108
|
-
|
|
109
|
-
@model_validator(mode="after")
|
|
110
|
-
def _must_be_pure(self) -> "PreparationToolContract":
|
|
111
|
-
if self.external_write:
|
|
112
|
-
raise ValueError("preparation tools must be pure/read-only and cannot write externally")
|
|
113
|
-
return self
|
|
114
|
-
|
|
115
|
-
|
|
116
96
|
class ReviewableActionContract(BaseModel):
|
|
117
97
|
"""Contract between ChatBotNutralia's draft store and a plugin delivery tool."""
|
|
118
98
|
|