Esta página fue traducida por una máquina y aún no ha sido revisada por una persona. El inglés es la referencia; las correcciones son bienvenidas en GitHub. GitHub

Cookwala / SDK y escenarios / 080

A delivery runner receives the window and the door, nothing else

The recipient-roles table gives the delivery role three constraint types. Derive them from the example household and see that every health, schedule and device fact is withheld with a reason.

Audiencia: developer · Objetivo: Robots para las personas, Hacer que las personas estén más sanas · Nivel: beginner

Leer primero: /docs/HOUSEHOLD-CONTEXT/ /trust/

Pasos

  1. Derive what a delivery service may receive from the twelve facets of the example household. deriveConstraints

  2. Both constraints come from one facet, the household's receiving rules; the facet's own value (the hour, the door) is not in the answer.

  3. The child's allergy is the first withheld facet, because the role is not allowed that constraint type; the robot's firmware is withheld because no consent names a delivery service.

Resultado

You know that a role's allow-list in profiles/household/recipient-roles.json decides what travels, and that the answer carries facet ids and reasons, never values. Next: 081 derives the richest role, the meal planner.

Línea de comandos

cookwala constraints examples/household/context.json --role delivery
curl -s -X POST ${COOKWALA_HUB:-http://localhost:7878}/v1/tools/constraints -H 'Content-Type: application/json' -d "{\"facets\": $(jq .facets examples/household/context.json), \"role\": \"delivery\"}"

Salida grabada

Estado: ok

[1] deriveConstraints: {"constraints": [{"type": "delivery_window", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}, {"type": "access_point", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.people.schedule", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.space.environment.foot_traffic", "re…

Código

Ejecutar: python scenarios/out/080-delivery-runner-gets-window-and-door/python.py

# Scenario 080: A delivery runner receives the window and the door, nothing else
# The recipient-roles table gives the delivery role three constraint types. Derive them from the example household and see that every health, schedule and device fact is withheld with a reason.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem

def load(path):
    with open(path, encoding="utf-8") as f:
        return json.load(f)

def pick(obj, path):
    for part in path.replace("]", "").replace("[", ".").split("."):
        obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
    return obj

c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))


# Step 1: Derive what a delivery service may receive from the twelve facets of the example household.
delivery = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "delivery")
assert pick(delivery, "constraints.length") == 2, pick(delivery, "constraints.length")
print("ok", "constraints.length", "=", 2)
assert pick(delivery, "constraints[0].type") == "delivery_window", pick(delivery, "constraints[0].type")
print("ok", "constraints[0].type", "=", "delivery_window")
assert pick(delivery, "constraints[1].type") == "access_point", pick(delivery, "constraints[1].type")
print("ok", "constraints[1].type", "=", "access_point")
assert pick(delivery, "disclosed.length") == 0, pick(delivery, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(delivery, "withheld.length") == 11, pick(delivery, "withheld.length")
print("ok", "withheld.length", "=", 11)

# Step 2: Both constraints come from one facet, the household's receiving rules; the facet's own value (the hour, the door) is not in the answer.
assert pick(delivery, "constraints[0].derivedFrom") == ["cw.facet.commerce.receiving_rules"], pick(delivery, "constraints[0].derivedFrom")
print("ok", "constraints[0].derivedFrom", "=", ["cw.facet.commerce.receiving_rules"])
assert pick(delivery, "constraints[1].derivedFrom") == ["cw.facet.commerce.receiving_rules"], pick(delivery, "constraints[1].derivedFrom")
print("ok", "constraints[1].derivedFrom", "=", ["cw.facet.commerce.receiving_rules"])

# Step 3: The child's allergy is the first withheld facet, because the role is not allowed that constraint type; the robot's firmware is withheld because no consent names a delivery service.
assert pick(delivery, "withheld[0].facet") == "cw.facet.household.health.allergies", pick(delivery, "withheld[0].facet")
print("ok", "withheld[0].facet", "=", "cw.facet.household.health.allergies")
assert pick(delivery, "withheld[0].reason") == "not_allowed_for_role", pick(delivery, "withheld[0].reason")
print("ok", "withheld[0].reason", "=", "not_allowed_for_role")
assert pick(delivery, "withheld[9].facet") == "cw.facet.self.firmware", pick(delivery, "withheld[9].facet")
print("ok", "withheld[9].facet", "=", "cw.facet.self.firmware")
assert pick(delivery, "withheld[9].reason") == "no_consent", pick(delivery, "withheld[9].reason")
print("ok", "withheld[9].reason", "=", "no_consent")

print("scenario complete")

scenarios/080-delivery-runner-gets-window-and-door.json

Anterior: 079 Siguiente: 081