@withgateway/sdk 0.4.0 → 0.9.1
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.
- package/dist/agents/index.d.mts +573 -0
- package/dist/agents/index.d.ts +573 -0
- package/dist/agents/index.js +1443 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/index.mjs +1394 -0
- package/dist/agents/index.mjs.map +1 -0
- package/dist/apiError-DHpfbmdx.d.mts +17 -0
- package/dist/apiError-DHpfbmdx.d.ts +17 -0
- package/dist/cli.js +5655 -1890
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +5769 -2005
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +3 -1
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +418 -120
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +418 -120
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.js +346 -136
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +346 -136
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-DUHmS74p.d.ts → index-DIN14Lhg.d.ts} +27 -4
- package/dist/{index-mJhG3vZU.d.mts → index-DuB-eQ0Z.d.mts} +27 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +2862 -438
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2820 -431
- package/dist/index.mjs.map +1 -1
- package/dist/media-CQUC7TkS.d.mts +39 -0
- package/dist/media-DQnBloaX.d.ts +39 -0
- package/dist/replay/index.d.mts +1 -1
- package/dist/replay/index.d.ts +1 -1
- package/dist/replay/index.js.map +1 -1
- package/dist/replay/index.mjs.map +1 -1
- package/dist/traces/index.d.mts +3 -1
- package/dist/traces/index.d.ts +3 -1
- package/dist/traces/index.js +418 -120
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +418 -120
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +3 -2
- package/dist/tracing/index.d.ts +3 -2
- package/dist/tracing/index.js +257 -16
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +257 -16
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/transport-CpRe7zgd.d.mts +123 -0
- package/dist/transport-CpRe7zgd.d.ts +123 -0
- package/dist/worlds/index.d.mts +2086 -1749
- package/dist/worlds/index.d.ts +2086 -1749
- package/dist/worlds/index.js +1471 -269
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1466 -265
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +6 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_world.py +24 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +243 -0
- package/runtime/gatewaysdk/environment/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/__main__.py +2 -2
- package/runtime/gatewaysdk/environment/schema/_slack_fidelity.py +8 -23
- package/runtime/gatewaysdk/environment/schema/api.py +27 -7
- package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +2 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +13 -1
- package/runtime/gatewaysdk/environment/schema/call_log.py +66 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +6 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +32 -8
- package/runtime/gatewaysdk/environment/schema/connector.py +5 -0
- package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +2 -1
- package/runtime/gatewaysdk/environment/schema/connectors/github/api/handlers.py +217 -58
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +9 -19
- package/runtime/gatewaysdk/environment/schema/connectors/github/scenarios/default/seed/github_webhooks.json +10 -2
- package/runtime/gatewaysdk/environment/schema/connectors/github/tests/webhooks.json +47 -0
- package/runtime/gatewaysdk/environment/schema/connectors/github/world.json +21 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/api/handlers.py +185 -18
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/connector.toml +29 -14
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/provenance.json +43 -12
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scenarios/default/seed/jamf_webhooks.json +2 -2
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scope.toml +4 -17
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/tests/webhooks.json +107 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/vendor-openapi.json +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/api/handlers.py +85 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/connector.toml +19 -31
- package/runtime/gatewaysdk/environment/schema/connectors/linear/provenance.json +18 -8
- package/runtime/gatewaysdk/environment/schema/connectors/linear/scenarios/default/seed/webhooks.json +19 -3
- package/runtime/gatewaysdk/environment/schema/connectors/linear/tests/test_webhooks.py +71 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +2 -2
- package/runtime/gatewaysdk/environment/schema/database/guard.py +2 -1
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +27 -1
- package/runtime/gatewaysdk/environment/schema/host.py +74 -11
- package/runtime/gatewaysdk/environment/schema/host_browser.py +48 -0
- package/runtime/gatewaysdk/environment/schema/host_control.py +33 -2
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +4 -1
- package/runtime/gatewaysdk/environment/schema/host_requests.py +14 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +13 -2
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +96 -19
- package/runtime/gatewaysdk/environment/schema/journal.py +10 -4
- package/runtime/gatewaysdk/environment/schema/local.py +33 -7
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +33 -480
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +332 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +4 -1
- package/runtime/gatewaysdk/environment/schema/run_parameters.py +25 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +49 -4
- package/runtime/gatewaysdk/environment/schema/scaffold.py +369 -218
- package/runtime/gatewaysdk/environment/schema/session_files.py +13 -2
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +20 -24
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/slack.py +55 -10
- package/runtime/gatewaysdk/environment/schema/snapshot.py +30 -4
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -2
- package/runtime/gatewaysdk/environment/schema/template_record.py +131 -0
- package/runtime/gatewaysdk/environment/schema/tools_world.py +26 -5
- package/runtime/gatewaysdk/environment/schema/ui.py +54 -33
- package/runtime/gatewaysdk/environment/schema/ui_interactions.py +419 -0
- package/runtime/gatewaysdk/environment/schema/ui_recorder.js +895 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay.py +366 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.LICENSE +25 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.js +109 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +10 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +6 -0
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +5 -1
- package/runtime/gatewaysdk/environment/schema/workers.py +8 -1
- package/runtime/gatewaysdk/environment/schema/world_host.py +64 -18
- package/runtime/gatewaysdk/environment/schema/world_tests.py +74 -0
- package/runtime/gatewaysdk/environment/secret_values.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +34 -43
- package/runtime/gatewaysdk/environment/world_session_contract.py +7 -34
- package/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +20 -24
- package/skills/connector-schema-authoring/connector-worlds.md +155 -13
- package/skills/connector-schema-authoring/world-schema.md +36 -29
- package/skills/world-data-ingestion/SKILL.md +11 -11
- package/skills/worlds-getting-started/SKILL.md +9 -9
- package/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/dist/media-BIApiPzS.d.mts +0 -102
- package/dist/media-BIApiPzS.d.ts +0 -102
|
@@ -36,11 +36,14 @@ from __future__ import annotations
|
|
|
36
36
|
import json
|
|
37
37
|
from dataclasses import dataclass, replace
|
|
38
38
|
from http.server import BaseHTTPRequestHandler
|
|
39
|
-
from typing import Any
|
|
39
|
+
from typing import TYPE_CHECKING, Any
|
|
40
40
|
|
|
41
41
|
from ..world_session_contract import REQUEST_BODY_CAPTURE_BYTES
|
|
42
42
|
from .call_redaction import SCRUB_MARGIN, CallRedaction
|
|
43
43
|
|
|
44
|
+
if TYPE_CHECKING:
|
|
45
|
+
from .webhooks import Delivery, WebhookAnswer
|
|
46
|
+
|
|
44
47
|
CAPTURE_BYTES = REQUEST_BODY_CAPTURE_BYTES
|
|
45
48
|
CONTENT_TYPE_CHARS = 256
|
|
46
49
|
JSON_TYPE = "application/json"
|
|
@@ -284,6 +287,15 @@ class Exchange:
|
|
|
284
287
|
"""A tool called by name: its arguments are what was asked, its answer what came back."""
|
|
285
288
|
return cls({}, CapturedBody.of_document(args, redaction), status, CapturedBody.of_document(answer, redaction))
|
|
286
289
|
|
|
290
|
+
@classmethod
|
|
291
|
+
def of_webhook(cls, delivery: Delivery, answer: WebhookAnswer, redaction: CallRedaction) -> Exchange:
|
|
292
|
+
"""A delivery the world sent: its signed headers and body, and the receiver's answer
|
|
293
|
+
(status 0 and no body until one answered; an error it never answered with as the body)."""
|
|
294
|
+
headers = redaction.headers(delivery.headers, redaction.secret, CAPTURE_BYTES)
|
|
295
|
+
error = None if answer.error is None else {"error": answer.error}
|
|
296
|
+
sent = CapturedBody.of_document(delivery.event.body, redaction)
|
|
297
|
+
return cls(headers, sent, answer.status, CapturedBody.of_document(error, redaction))
|
|
298
|
+
|
|
287
299
|
@classmethod
|
|
288
300
|
def from_json(cls, data: dict) -> Exchange:
|
|
289
301
|
request, response = data.get("request") or {}, data.get("response") or {}
|
|
@@ -21,7 +21,10 @@ from .connector import Operation, Spec, _dig
|
|
|
21
21
|
from .handler_errors import log_line
|
|
22
22
|
from .tasks import WITHHELD_FIELD
|
|
23
23
|
|
|
24
|
+
from .webhooks import ANSWER_SUFFIX, SUBSCRIPTIONS_SHOWN, WebhookAnswer, WebhookFeed, WebhookPoll
|
|
25
|
+
|
|
24
26
|
if TYPE_CHECKING:
|
|
27
|
+
from .webhooks import Delivery, WebhookOutbox
|
|
25
28
|
from .request_ledger import RequestOutbox
|
|
26
29
|
|
|
27
30
|
METHOD_CHARS = 32
|
|
@@ -31,6 +34,7 @@ LINE_BOUNDS = {"method": METHOD_CHARS, "operation": OPERATION_CHARS, "path": PAT
|
|
|
31
34
|
DEFAULT_CALL_LOG_MAX = 5000
|
|
32
35
|
DEFAULT_CALL_LOG_VALUES = 200_000
|
|
33
36
|
DEFAULT_CALL_LOG_CHARS = 8 << 20
|
|
37
|
+
INTERACTION_STATUS = 204
|
|
34
38
|
WITHHELD_ROUTE = {
|
|
35
39
|
"args": REDACTED,
|
|
36
40
|
"query": {},
|
|
@@ -129,6 +133,8 @@ class Via(StrEnum):
|
|
|
129
133
|
API = "api"
|
|
130
134
|
UI = "ui"
|
|
131
135
|
TOOL = "tool"
|
|
136
|
+
WEBHOOK = "webhook"
|
|
137
|
+
PAGE = "page"
|
|
132
138
|
|
|
133
139
|
|
|
134
140
|
@dataclass(frozen=True)
|
|
@@ -302,6 +308,7 @@ class CallLog:
|
|
|
302
308
|
self.total = 0
|
|
303
309
|
self.journal = journal
|
|
304
310
|
self.outbox = outbox
|
|
311
|
+
self.webhooks = WebhookFeed()
|
|
305
312
|
self._lock = threading.Lock()
|
|
306
313
|
|
|
307
314
|
@classmethod
|
|
@@ -423,6 +430,65 @@ class CallLog:
|
|
|
423
430
|
request, budget = dict(WITHHELD_TOOL), RequestBudget()
|
|
424
431
|
self._append({**heading, **request, "via": str(Via.TOOL)}, answered, budget)
|
|
425
432
|
|
|
433
|
+
def record_interaction(self, operation: str, page: str, summary: dict, detail: dict, graded: bool = True) -> None:
|
|
434
|
+
"""One interaction on a UI world's page (:mod:`.ui_interactions`): a ``via`` page call named
|
|
435
|
+
``operation`` at ``page`` with no method, ``summary`` as its query and ``detail`` as what was
|
|
436
|
+
asked, kept by the request ledger and, ``graded``, by the grader's log."""
|
|
437
|
+
secret = self.redaction.secret
|
|
438
|
+
heading = {"operation": operation, "method": None, "path": self.redaction.raw_path(page, secret)}
|
|
439
|
+
query = self.redaction.value(summary)
|
|
440
|
+
answered = _answered(INTERACTION_STATUS, None, 0.0)
|
|
441
|
+
exchange = partial(Exchange.of_tool, detail, INTERACTION_STATUS, None, self.redaction)
|
|
442
|
+
self._send({**heading, "query": query, "via": str(Via.PAGE)}, answered, exchange)
|
|
443
|
+
if self.maximum == 0 or not graded:
|
|
444
|
+
return
|
|
445
|
+
try:
|
|
446
|
+
request, budget = self._tool_request(detail)
|
|
447
|
+
except (RecursionError, RequestTooLarge):
|
|
448
|
+
request, budget = dict(WITHHELD_TOOL), RequestBudget()
|
|
449
|
+
self._append({**heading, **request, "query": query, "via": str(Via.PAGE)}, answered, budget)
|
|
450
|
+
|
|
451
|
+
def record_webhooks(self, deliveries: Iterable[Delivery]) -> None:
|
|
452
|
+
"""Each delivery the world sent, kept by the request ledger with ``via`` webhook and no
|
|
453
|
+
answer yet (status 0); the grader's call log keeps only what the agent called."""
|
|
454
|
+
sent = list(deliveries)
|
|
455
|
+
self.webhooks.append(sent)
|
|
456
|
+
for delivery in sent:
|
|
457
|
+
self._send_webhook(delivery, WebhookAnswer(delivery.id, 0, None, None), {"delivery": delivery.id}, "")
|
|
458
|
+
|
|
459
|
+
def answer_webhooks(self, answers: Iterable[WebhookAnswer]) -> int:
|
|
460
|
+
"""Each receiver's answer to a forwarded delivery, kept by the request ledger as one more
|
|
461
|
+
``via`` webhook entry under ``<event type>.answer`` (so a check counting the event never counts
|
|
462
|
+
it) with the receiver's status and ``query.answer`` naming the delivery; the
|
|
463
|
+
first answer to each delivery only, and none for an id the feed no longer holds."""
|
|
464
|
+
kept = 0
|
|
465
|
+
for answer in answers:
|
|
466
|
+
delivery = self.webhooks.answer(answer.delivery_id)
|
|
467
|
+
if delivery is None:
|
|
468
|
+
continue
|
|
469
|
+
self._send_webhook(delivery, answer, {"answer": delivery.id}, ANSWER_SUFFIX)
|
|
470
|
+
kept += 1
|
|
471
|
+
return kept
|
|
472
|
+
|
|
473
|
+
def webhook_page(self, outbox: WebhookOutbox | None, poll: WebhookPoll) -> dict:
|
|
474
|
+
"""A forwarder's poll: its answers kept first, then the subscriptions ``outbox`` reads (none
|
|
475
|
+
declared: ``declared`` false; at most :data:`SUBSCRIPTIONS_SHOWN`, each with how many deliveries
|
|
476
|
+
this feed sent it) and the page of deliveries."""
|
|
477
|
+
declared = outbox is not None and outbox.webhooks is not None
|
|
478
|
+
kept = self.answer_webhooks(poll.answers)
|
|
479
|
+
found = outbox.subscriptions() if outbox is not None and poll.subscriptions else []
|
|
480
|
+
shown = [{**sub, "sent": self.webhooks.sent_to(sub["key"])} for sub in found[:SUBSCRIPTIONS_SHOWN]]
|
|
481
|
+
page = self.webhooks.after(poll.after, poll.limit, poll.epoch, poll.tail, poll.targets)
|
|
482
|
+
listed = {"subscriptions": shown, "truncated": len(found) > len(shown)}
|
|
483
|
+
return {"declared": declared, **listed, "answered": kept, **page}
|
|
484
|
+
|
|
485
|
+
def _send_webhook(self, delivery: Delivery, answer: WebhookAnswer, query: dict, suffix: str) -> None:
|
|
486
|
+
path = self.redaction.raw_path(delivery.endpoint, self.redaction.secret)
|
|
487
|
+
line = {"operation": f"{delivery.event.type}{suffix}", "method": "POST", "path": path, "query": query}
|
|
488
|
+
exchange = partial(Exchange.of_webhook, delivery, answer, self.redaction)
|
|
489
|
+
answered = _answered(answer.status, None, (answer.duration_ms or 0.0) / 1000)
|
|
490
|
+
self._send({**line, "via": str(Via.WEBHOOK)}, answered, exchange)
|
|
491
|
+
|
|
426
492
|
def _tool_request(self, args: Any) -> tuple[dict, RequestBudget]:
|
|
427
493
|
budget = RequestBudget()
|
|
428
494
|
logged_args = self.redaction.value(args, budget)
|
|
@@ -179,8 +179,14 @@ KEPT_HEADERS = frozenset(
|
|
|
179
179
|
"content-type",
|
|
180
180
|
"host",
|
|
181
181
|
"idempotency-key",
|
|
182
|
+
"linear-delivery",
|
|
183
|
+
"linear-event",
|
|
182
184
|
"origin",
|
|
185
|
+
"svix-id",
|
|
186
|
+
"svix-timestamp",
|
|
183
187
|
"user-agent",
|
|
188
|
+
"x-github-delivery",
|
|
189
|
+
"x-github-event",
|
|
184
190
|
"x-forwarded-proto",
|
|
185
191
|
"x-request-id",
|
|
186
192
|
}
|
|
@@ -899,7 +899,10 @@ def bind_connection(bundle: Path, contract: Contract) -> None:
|
|
|
899
899
|
return
|
|
900
900
|
from .connector import parse_spec
|
|
901
901
|
|
|
902
|
-
parse_spec(spec_path.read_text(encoding="utf-8"))
|
|
902
|
+
spec = parse_spec(spec_path.read_text(encoding="utf-8"))
|
|
903
|
+
spec.check_entities(contract.entities)
|
|
904
|
+
if spec.webhooks is not None:
|
|
905
|
+
spec.webhooks.check_contract(contract.entities)
|
|
903
906
|
|
|
904
907
|
|
|
905
908
|
def check_bundle(bundle: str | Path) -> Contract:
|
|
@@ -44,6 +44,9 @@ from .validation import fail
|
|
|
44
44
|
PIN = "conform"
|
|
45
45
|
|
|
46
46
|
|
|
47
|
+
BODILESS_STATUSES = (204, 205)
|
|
48
|
+
|
|
49
|
+
|
|
47
50
|
def load_openapi(path: str | Path) -> dict:
|
|
48
51
|
return parse_openapi(Path(path).read_text(encoding="utf-8"), str(path))
|
|
49
52
|
|
|
@@ -316,7 +319,7 @@ class Outcome:
|
|
|
316
319
|
self.documented
|
|
317
320
|
and self.status is not None
|
|
318
321
|
and str(self.status) in self.expected
|
|
319
|
-
and self.schema in ("ok", "no-schema")
|
|
322
|
+
and self.schema in ("ok", "no-schema", "no-body")
|
|
320
323
|
)
|
|
321
324
|
|
|
322
325
|
|
|
@@ -399,13 +402,28 @@ def _first_value(rows: list[dict], path: str) -> Any:
|
|
|
399
402
|
return None
|
|
400
403
|
|
|
401
404
|
|
|
405
|
+
def _keyed_value(state: WorldState, name: str) -> Any:
|
|
406
|
+
for entity, declaration in state.contract.entities.items():
|
|
407
|
+
if name in declaration["primary_key"]:
|
|
408
|
+
value = _first_value(state.rows(entity), name)
|
|
409
|
+
if value is not None:
|
|
410
|
+
return value
|
|
411
|
+
return None
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _own_key_value(state: WorldState, entity: str) -> Any:
|
|
415
|
+
key = state.contract.entities[entity]["primary_key"]
|
|
416
|
+
return _first_value(state.rows(entity), key[0]) if len(key) == 1 else None
|
|
417
|
+
|
|
418
|
+
|
|
402
419
|
def _sample_args(
|
|
403
420
|
operation: Operation, spec, settings, state: WorldState, checker: Checker, documented: dict | None
|
|
404
421
|
) -> tuple[dict[str, str], dict[str, str]]:
|
|
405
422
|
"""Path arguments from the world's own rows — the operation's declared ``sample``
|
|
406
423
|
first (a value a validating handler accepts), then this operation's filter, then any
|
|
407
|
-
operation's filter on the same placeholder, then
|
|
408
|
-
|
|
424
|
+
operation's filter on the same placeholder, then a row of this operation's entity holding a field of that
|
|
425
|
+
name, then the first row of any entity keyed by it, then (for the path's last placeholder only) the entity's
|
|
426
|
+
primary key — else the document's examples. The point is to hit data, not to probe 404s."""
|
|
409
427
|
op = settings.for_operation(operation.name)
|
|
410
428
|
hints = _hints(spec, settings)
|
|
411
429
|
args: dict[str, str] = {}
|
|
@@ -422,9 +440,11 @@ def _sample_args(
|
|
|
422
440
|
entity, path = hints[name]
|
|
423
441
|
value = _first_value(state.rows(entity), path)
|
|
424
442
|
if value is None and operation.entity:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
443
|
+
value = _first_value(state.rows(operation.entity), name)
|
|
444
|
+
if value is None:
|
|
445
|
+
value = _keyed_value(state, name)
|
|
446
|
+
if value is None and operation.entity and name == list(operation.placeholders)[-1]:
|
|
447
|
+
value = _own_key_value(state, operation.entity)
|
|
428
448
|
if value is None and name in documented_params:
|
|
429
449
|
value = checker.example(documented_params[name].get("schema") or {})
|
|
430
450
|
args[name] = str(value if value is not None else "1")
|
|
@@ -448,7 +468,9 @@ def conform(world: str | Path, openapi: list[str | Path], *, max_operations: int
|
|
|
448
468
|
outcomes: list[Outcome] = []
|
|
449
469
|
try:
|
|
450
470
|
door = Door.of(spec, settings, PIN)
|
|
451
|
-
|
|
471
|
+
operations = list(spec.operations.values())[:max_operations]
|
|
472
|
+
operations.sort(key=lambda operation: operation.method == "DELETE")
|
|
473
|
+
for operation in operations:
|
|
452
474
|
located = None
|
|
453
475
|
checker = None
|
|
454
476
|
for document in documents:
|
|
@@ -495,7 +517,9 @@ def conform(world: str | Path, openapi: list[str | Path], *, max_operations: int
|
|
|
495
517
|
outcome.status = status
|
|
496
518
|
answer = responses.get(str(status)) or responses.get("default") or {}
|
|
497
519
|
schema = ((answer.get("content") or {}).get("application/json") or {}).get("schema")
|
|
498
|
-
if
|
|
520
|
+
if status in BODILESS_STATUSES and not raw:
|
|
521
|
+
outcome.schema = "no-body"
|
|
522
|
+
elif schema is None:
|
|
499
523
|
outcome.schema = "no-schema"
|
|
500
524
|
else:
|
|
501
525
|
try:
|
|
@@ -93,6 +93,7 @@ from .validation import (
|
|
|
93
93
|
string_of,
|
|
94
94
|
table_of,
|
|
95
95
|
)
|
|
96
|
+
from .webhooks import Webhooks
|
|
96
97
|
|
|
97
98
|
SPEC = "connector.toml"
|
|
98
99
|
CAPTURES = "captures"
|
|
@@ -175,6 +176,7 @@ class Spec:
|
|
|
175
176
|
round_fields: dict[str, int] = field(default_factory=dict)
|
|
176
177
|
preserve_fields: frozenset[str] = frozenset()
|
|
177
178
|
operations: dict[str, Operation] = field(default_factory=dict)
|
|
179
|
+
webhooks: Webhooks | None = None
|
|
178
180
|
|
|
179
181
|
@property
|
|
180
182
|
def scheme(self) -> str:
|
|
@@ -208,6 +210,8 @@ class Spec:
|
|
|
208
210
|
"`gateway worlds schema entity add`, or point the route at one that exists",
|
|
209
211
|
location,
|
|
210
212
|
)
|
|
213
|
+
if self.webhooks is not None:
|
|
214
|
+
self.webhooks.check_entity(known)
|
|
211
215
|
|
|
212
216
|
|
|
213
217
|
RedactTable = tuple[frozenset[str], frozenset[str], dict[str, int], frozenset[str]]
|
|
@@ -343,6 +347,7 @@ def spec_from(raw: dict) -> Spec:
|
|
|
343
347
|
round_fields=round_fields,
|
|
344
348
|
preserve_fields=preserve_fields,
|
|
345
349
|
operations=operations,
|
|
350
|
+
webhooks=Webhooks.parse(raw.get("webhooks")),
|
|
346
351
|
)
|
|
347
352
|
|
|
348
353
|
|
|
@@ -33,7 +33,8 @@ hosted call into such a handler answers 400 {error: "handler", detail, handler}:
|
|
|
33
33
|
Rows per entity, as {entity: count}.
|
|
34
34
|
|
|
35
35
|
A handler that raises AttributeError, TypeError or NameError is answered 400 with
|
|
36
|
-
that structured body;
|
|
36
|
+
that structured body; `raise Refusal(404, body)` (from gateway_env) answers that 4xx
|
|
37
|
+
and body as the vendor's refusal; any other exception is answered 500 {error: "engine", ...}.
|
|
37
38
|
`schema init --connector custom --with-example-tool` writes the example in full.
|
|
38
39
|
"""
|
|
39
40
|
|