nutria-plugin 0.6.3__tar.gz → 0.7.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.7.0}/CHANGELOG.md +12 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/PKG-INFO +1 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/conversation-ownership.md +6 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/index.md +2 -1
- nutria_plugin-0.7.0/docs/outside-audience.md +38 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/python-api.md +11 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/pyproject.toml +1 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/__init__.py +11 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/capabilities.py +35 -0
- nutria_plugin-0.7.0/src/nutria_plugin/conversation_scope.py +50 -0
- nutria_plugin-0.7.0/tests/test_conversation_scope.py +120 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/uv.lock +1 -1
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/.github/workflows/publish.yml +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/.gitignore +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/README.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/admin-extensions.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/admin-flows.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/capability-authoring.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/cli.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/connection-types.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/manifest.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/migration-6.0.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/quickstart.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/reviewable-actions.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/security.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/docs/skill-format.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/examples/my-first-plugin/README.md +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/examples/my-first-plugin/hooks/hooks.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/examples/my-first-plugin/plugin.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/examples/my-first-plugin/settings.schema.json +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/bundle.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/cli.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/domains.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/hierarchy.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/manifest.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/mcp_results.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/migrate.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/operation_facts.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/ownership.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/packaging.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/prepared_preview.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/signing.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/src/nutria_plugin/skills.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/__init__.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_bundle.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_capability_contracts.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_cli.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_contract_vnext.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_hierarchy.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_manifest.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_mcp_results.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_ownership.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_packaging.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_prepared_preview.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_reviewable_actions.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_signing.py +0 -0
- {nutria_plugin-0.6.3 → nutria_plugin-0.7.0}/tests/test_skill_format_docs.py +0 -0
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
Additive; manifests that do not use the new field are unchanged.
|
|
6
|
+
|
|
7
|
+
- Add `scope: "conversation_contact"` on a capability value input: the argument that names the person the conversation is with.
|
|
8
|
+
In a `public_customer` turn the host sets it itself, so neither the model nor the outside person chooses whose data is read.
|
|
9
|
+
- New validators: only a `personal_identifier` value input of a read capability can be scoped (one per capability); a
|
|
10
|
+
`public_customer` capability must be a read, must not take another person-identifying input, and must scope an input when it
|
|
11
|
+
returns personal or special-category content.
|
|
12
|
+
- Add `nutria_plugin.conversation_scope` (`scoped_argument`, `offered_to_outside_audience`, `apply_conversation_scope`): the one
|
|
13
|
+
definition of the pinning rule for hosts and plugin tests. See `docs/outside-audience.md`.
|
|
14
|
+
|
|
3
15
|
## 0.6.3
|
|
4
16
|
|
|
5
17
|
Additive.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nutria-plugin
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.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
|
|
@@ -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.7.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 |
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
## The rule
|
|
7
|
+
|
|
8
|
+
A capability offered to `public_customer`:
|
|
9
|
+
|
|
10
|
+
- is a **read** (`effect: read`); writes and sends go through the host's own approval path;
|
|
11
|
+
- takes **no person-identifying input** (`data_class: personal_identifier`) except the one scoped to the conversation contact;
|
|
12
|
+
- if it returns `personal_content` or `special_category` data, **must scope an input to the conversation contact**.
|
|
13
|
+
|
|
14
|
+
## Scoping an input
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{"kind": "value", "semantic_field": "chat", "argument_name": "chat", "required": false,
|
|
18
|
+
"data_class": "personal_identifier", "accepted_origins": ["current_user"], "scope": "conversation_contact"}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`scope: "conversation_contact"` means: this argument names the one person the conversation is with. In an outside-audience
|
|
22
|
+
turn the host **sets it itself**, replacing whatever the model sent and filling it when the model left it out. The person
|
|
23
|
+
writing to the agent cannot choose another chat by mentioning it. Only a `value` input of class `personal_identifier` can carry
|
|
24
|
+
the scope, and a capability has at most one.
|
|
25
|
+
|
|
26
|
+
`nutria_plugin.apply_conversation_scope(capability, arguments, contact)` is the reference rule hosts and plugin tests share.
|
|
27
|
+
|
|
28
|
+
## What the plugin must guarantee
|
|
29
|
+
|
|
30
|
+
The host fixes the argument; the plugin must make sure that, when the argument is given, **every** result belongs to that
|
|
31
|
+
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,
|
|
32
|
+
and a list is limited to that chat. A capability that cannot guarantee this must not declare `public_customer`.
|
|
33
|
+
|
|
34
|
+
## What is not covered
|
|
35
|
+
|
|
36
|
+
A capability that needs no contact (for example public pickup points) declares `public_customer` without a scope. It must not
|
|
37
|
+
return personal content. A resource a person quotes (such as a tracking number) is not a conversation scope: decide whether the
|
|
38
|
+
data behind it is safe to show to whoever sends that number.
|
|
@@ -76,3 +76,14 @@ status = verify_manifest(payload)
|
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
Signing uses ECDSA P-256 over canonical JSON with the `signature` field removed.
|
|
79
|
+
|
|
80
|
+
## Conversation scope
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from nutria_plugin import apply_conversation_scope, scoped_argument
|
|
84
|
+
|
|
85
|
+
arguments = apply_conversation_scope(capability, {"chat": "whatever the model sent"}, contact="34600000000")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For a capability offered to `public_customer`, the argument declared with `scope: "conversation_contact"` is replaced by the
|
|
89
|
+
conversation contact. See `outside-audience.md`.
|
|
@@ -37,6 +37,12 @@ from .capabilities import (
|
|
|
37
37
|
WorldProjectionDescriptor,
|
|
38
38
|
WorldProviderDescriptor,
|
|
39
39
|
)
|
|
40
|
+
from .conversation_scope import (
|
|
41
|
+
CONVERSATION_CONTACT,
|
|
42
|
+
apply_conversation_scope,
|
|
43
|
+
offered_to_outside_audience,
|
|
44
|
+
scoped_argument,
|
|
45
|
+
)
|
|
40
46
|
from .ownership import (
|
|
41
47
|
OWNER_PRIORITY,
|
|
42
48
|
ConversationOwnership,
|
|
@@ -90,6 +96,11 @@ from .skills import SkillFrontmatter, parse_skill_frontmatter
|
|
|
90
96
|
|
|
91
97
|
__all__ = [
|
|
92
98
|
"__version__",
|
|
99
|
+
# Conversation scope for outside audiences
|
|
100
|
+
"CONVERSATION_CONTACT",
|
|
101
|
+
"apply_conversation_scope",
|
|
102
|
+
"offered_to_outside_audience",
|
|
103
|
+
"scoped_argument",
|
|
93
104
|
# Conversation ownership
|
|
94
105
|
"OWNER_PRIORITY",
|
|
95
106
|
"ConversationOwnership",
|
|
@@ -213,6 +213,10 @@ class CapabilityInputBinding(BaseModel):
|
|
|
213
213
|
data_class: DataClass
|
|
214
214
|
requires_provenance: bool = False
|
|
215
215
|
accepted_origins: list[Literal["current_user", "world_resource"]] = Field(min_length=1)
|
|
216
|
+
# ``conversation_contact``: this argument names the one person the conversation is with. When the host
|
|
217
|
+
# runs the capability for an outside audience it sets the argument itself, whatever the model sent
|
|
218
|
+
# or left empty. See ``nutria_plugin.conversation_scope``.
|
|
219
|
+
scope: Literal["conversation_contact"] | None = None
|
|
216
220
|
|
|
217
221
|
model_config = {"extra": "forbid"}
|
|
218
222
|
|
|
@@ -225,6 +229,11 @@ class CapabilityInputBinding(BaseModel):
|
|
|
225
229
|
|
|
226
230
|
@model_validator(mode="after")
|
|
227
231
|
def _validate_kind(self) -> "CapabilityInputBinding":
|
|
232
|
+
if self.scope is not None:
|
|
233
|
+
if self.kind != "value":
|
|
234
|
+
raise ValueError("a conversation-scoped input must be a value input")
|
|
235
|
+
if self.data_class != DataClass.PERSONAL_IDENTIFIER:
|
|
236
|
+
raise ValueError("a conversation-scoped input must have data_class personal_identifier")
|
|
228
237
|
if self.kind == "resource" and self.resource_type is None:
|
|
229
238
|
raise ValueError("resource inputs require resource_type")
|
|
230
239
|
if self.kind == "value" and self.resource_type is not None:
|
|
@@ -405,6 +414,32 @@ class CapabilityDescriptor(BaseModel):
|
|
|
405
414
|
input_names = [item.semantic_field for item in self.inputs]
|
|
406
415
|
if len(input_names) != len(set(input_names)):
|
|
407
416
|
raise ValueError("capability inputs must not repeat semantic fields")
|
|
417
|
+
scoped = [item for item in self.inputs if item.scope is not None]
|
|
418
|
+
if len(scoped) > 1:
|
|
419
|
+
raise ValueError("a capability may scope only one input to the conversation contact")
|
|
420
|
+
if scoped and self.effect != CapabilityEffect.READ:
|
|
421
|
+
raise ValueError("only read capabilities may scope an input to the conversation contact")
|
|
422
|
+
if "public_customer" in self.requirements.audience:
|
|
423
|
+
if self.effect != CapabilityEffect.READ:
|
|
424
|
+
raise ValueError("only read capabilities may be offered to the public_customer audience")
|
|
425
|
+
others = [
|
|
426
|
+
item
|
|
427
|
+
for item in self.inputs
|
|
428
|
+
if item.scope is None and item.data_class == DataClass.PERSONAL_IDENTIFIER
|
|
429
|
+
]
|
|
430
|
+
if others:
|
|
431
|
+
raise ValueError(
|
|
432
|
+
"a public_customer capability must not take another person-identifying input: "
|
|
433
|
+
"scope it to the conversation contact"
|
|
434
|
+
)
|
|
435
|
+
if not scoped and any(
|
|
436
|
+
out.data_class in {DataClass.PERSONAL_CONTENT, DataClass.SPECIAL_CATEGORY}
|
|
437
|
+
for out in self.produces
|
|
438
|
+
):
|
|
439
|
+
raise ValueError(
|
|
440
|
+
"a public_customer capability that returns personal content must scope an input "
|
|
441
|
+
"to the conversation contact"
|
|
442
|
+
)
|
|
408
443
|
output_names = [item.output_name for item in self.produces]
|
|
409
444
|
if len(output_names) != len(set(output_names)):
|
|
410
445
|
raise ValueError("capability outputs must not repeat output names")
|
|
@@ -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
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""A capability offered to an outside audience is pinned to the person the conversation is with."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from nutria_plugin import (
|
|
9
|
+
CapabilityDescriptor,
|
|
10
|
+
apply_conversation_scope,
|
|
11
|
+
offered_to_outside_audience,
|
|
12
|
+
scoped_argument,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _read(
|
|
17
|
+
audience=("private_internal", "public_customer"), inputs=None, data_class="personal_content"
|
|
18
|
+
):
|
|
19
|
+
return {
|
|
20
|
+
"id": "chat.recent",
|
|
21
|
+
"title": "Recent messages",
|
|
22
|
+
"description": "Recent messages of one chat.",
|
|
23
|
+
"domains": ["whatsapp"],
|
|
24
|
+
"effect": "read",
|
|
25
|
+
"effect_scope": "world",
|
|
26
|
+
"tool": "recent",
|
|
27
|
+
"requirements": {"authority": "read", "audience": list(audience)},
|
|
28
|
+
"exposure": "model",
|
|
29
|
+
"produces": [
|
|
30
|
+
{
|
|
31
|
+
"result_path": ".messages",
|
|
32
|
+
"resource_type": "whatsapp_message",
|
|
33
|
+
"output_name": "messages",
|
|
34
|
+
"many": True,
|
|
35
|
+
"data_class": data_class,
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"inputs": inputs
|
|
39
|
+
if inputs is not None
|
|
40
|
+
else [
|
|
41
|
+
{
|
|
42
|
+
"kind": "value",
|
|
43
|
+
"semantic_field": "chat",
|
|
44
|
+
"argument_name": "chat",
|
|
45
|
+
"required": False,
|
|
46
|
+
"data_class": "personal_identifier",
|
|
47
|
+
"accepted_origins": ["current_user"],
|
|
48
|
+
"scope": "conversation_contact",
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_a_scoped_read_is_valid_and_names_its_argument():
|
|
55
|
+
payload = _read()
|
|
56
|
+
CapabilityDescriptor.model_validate(payload)
|
|
57
|
+
|
|
58
|
+
assert scoped_argument(payload) == "chat" and offered_to_outside_audience(payload)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_the_contact_replaces_what_the_model_sent_or_left_empty():
|
|
62
|
+
payload = _read()
|
|
63
|
+
|
|
64
|
+
assert apply_conversation_scope(
|
|
65
|
+
payload, {"chat": "34600000000", "limit": 5}, " 34611111111 "
|
|
66
|
+
) == {
|
|
67
|
+
"chat": "34611111111",
|
|
68
|
+
"limit": 5,
|
|
69
|
+
}
|
|
70
|
+
assert apply_conversation_scope(payload, {}, "34611111111") == {"chat": "34611111111"}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_a_capability_not_offered_to_the_outside_is_never_pinned():
|
|
74
|
+
with pytest.raises(ValueError):
|
|
75
|
+
apply_conversation_scope(_read(audience=("private_internal",)), {}, "34611111111")
|
|
76
|
+
with pytest.raises(ValueError):
|
|
77
|
+
apply_conversation_scope(_read(), {}, " ")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_personal_content_for_the_outside_needs_a_scoped_input():
|
|
81
|
+
with pytest.raises(ValidationError, match="scope an input"):
|
|
82
|
+
CapabilityDescriptor.model_validate(_read(inputs=[]))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_another_person_identifying_input_is_refused_for_the_outside():
|
|
86
|
+
other = {
|
|
87
|
+
"kind": "value",
|
|
88
|
+
"semantic_field": "recipient",
|
|
89
|
+
"argument_name": "recipient",
|
|
90
|
+
"data_class": "personal_identifier",
|
|
91
|
+
"accepted_origins": ["current_user"],
|
|
92
|
+
}
|
|
93
|
+
scoped = _read()["inputs"][0]
|
|
94
|
+
|
|
95
|
+
with pytest.raises(ValidationError, match="another person-identifying input"):
|
|
96
|
+
CapabilityDescriptor.model_validate(_read(inputs=[scoped, other]))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_only_a_personal_identifier_value_can_be_scoped_and_only_one():
|
|
100
|
+
base = _read()["inputs"][0]
|
|
101
|
+
|
|
102
|
+
with pytest.raises(ValidationError, match="personal_identifier"):
|
|
103
|
+
CapabilityDescriptor.model_validate(_read(inputs=[{**base, "data_class": "non_personal"}]))
|
|
104
|
+
with pytest.raises(ValidationError, match="only one input"):
|
|
105
|
+
CapabilityDescriptor.model_validate(
|
|
106
|
+
_read(inputs=[base, {**base, "semantic_field": "peer", "argument_name": "peer"}])
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_a_write_cannot_be_scoped_or_offered_to_the_outside():
|
|
111
|
+
payload = _read()
|
|
112
|
+
payload.update(effect="write", effect_scope="internal_state", produces=[])
|
|
113
|
+
payload["requirements"]["authority"] = "write_internal"
|
|
114
|
+
|
|
115
|
+
with pytest.raises(ValidationError):
|
|
116
|
+
CapabilityDescriptor.model_validate(payload)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_a_capability_without_scope_keeps_working_for_internal_audiences():
|
|
120
|
+
CapabilityDescriptor.model_validate(_read(audience=("private_internal",), inputs=[]))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|