@withgateway/sdk 0.3.3 → 0.6.0
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/README.md +4 -3
- package/dist/cli.js +3005 -1401
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2996 -1392
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +128 -37
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +126 -35
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +124 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +124 -11
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
- package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
- package/dist/{index-mJhG3vZU.d.mts → index-Di9nNqOY.d.mts} +26 -3
- package/dist/{index-DUHmS74p.d.ts → index-LA-PMRJT.d.ts} +26 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1078 -260
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1040 -251
- package/dist/index.mjs.map +1 -1
- 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.js +125 -34
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +123 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +7 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +7 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +819 -438
- package/dist/worlds/index.d.ts +819 -438
- package/dist/worlds/index.js +912 -236
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +908 -232
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_materialize.py +5 -25
- package/runtime/gatewaysdk/environment/_world.py +82 -66
- package/runtime/gatewaysdk/environment/backing.py +20 -24
- package/runtime/gatewaysdk/environment/core.py +1 -16
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +14 -27
- package/runtime/gatewaysdk/environment/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
- package/runtime/gatewaysdk/environment/schema/api.py +198 -474
- package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
- package/runtime/gatewaysdk/environment/schema/batch.py +3 -3
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
- package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +321 -0
- package/runtime/gatewaysdk/environment/schema/call_log.py +276 -18
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +207 -19
- package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +38 -35
- package/runtime/gatewaysdk/environment/schema/connector.py +94 -152
- package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
- 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 +10 -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/connectors/servicenow/connector.toml +2 -5
- package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
- package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
- package/runtime/gatewaysdk/environment/schema/data.py +14 -13
- package/runtime/gatewaysdk/environment/schema/database/base.py +106 -165
- package/runtime/gatewaysdk/environment/schema/database/guard.py +45 -37
- package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +57 -31
- package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
- package/runtime/gatewaysdk/environment/schema/door.py +899 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +86 -28
- package/runtime/gatewaysdk/environment/schema/grading.py +58 -86
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +52 -5
- package/runtime/gatewaysdk/environment/schema/host.py +229 -1695
- package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
- package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
- package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
- package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
- package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
- package/runtime/gatewaysdk/environment/schema/journal.py +438 -0
- package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
- package/runtime/gatewaysdk/environment/schema/local.py +32 -116
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/platform.py +29 -234
- package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
- package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
- package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +136 -176
- package/runtime/gatewaysdk/environment/schema/scaffold.py +2 -1
- package/runtime/gatewaysdk/environment/schema/session_files.py +133 -24
- package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
- package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +8 -9
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +50 -28
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +12 -8
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +20 -22
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +25 -25
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +24 -16
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +71 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
- package/runtime/gatewaysdk/environment/schema/snapshot.py +150 -30
- package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
- package/runtime/gatewaysdk/environment/schema/tasks.py +229 -323
- package/runtime/gatewaysdk/environment/schema/tools_world.py +103 -203
- package/runtime/gatewaysdk/environment/schema/validation.py +69 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +38 -36
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
- package/runtime/gatewaysdk/environment/schema/workers.py +203 -39
- package/runtime/gatewaysdk/environment/schema/world_host.py +970 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +83 -11
- package/runtime/gatewaysdk/environment/world.py +1 -1
- package/runtime/gatewaysdk/environment/world_session_contract.py +14 -0
- package/skills/agents/connector-template-author.md +5 -1
- package/skills/benchmarks-getting-started/SKILL.md +8 -9
- package/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +50 -28
- package/skills/connector-schema-authoring/connector-worlds.md +282 -18
- package/skills/connector-schema-authoring/world-schema.md +7 -6
- package/skills/world-data-ingestion/ROWS.md +12 -8
- package/skills/world-data-ingestion/SKILL.md +20 -22
- package/skills/worlds-getting-started/SKILL.md +25 -25
- package/skills/worlds-getting-started/references/cli-mcp-map.md +24 -16
- package/skills/worlds-getting-started/references/gotchas.md +71 -7
- package/skills/worlds-getting-started/references/journal-checks.md +182 -0
|
@@ -7,13 +7,14 @@ use; unsupported assertions fail rather than becoming unenforced promises.
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import datetime as dt
|
|
10
|
+
import functools
|
|
10
11
|
import hashlib
|
|
11
12
|
import json
|
|
12
13
|
import math
|
|
13
14
|
import re
|
|
14
15
|
import struct
|
|
15
16
|
from pathlib import Path
|
|
16
|
-
from typing import Any, NoReturn
|
|
17
|
+
from typing import Any, Mapping, NoReturn
|
|
17
18
|
|
|
18
19
|
from .._toml import tomllib
|
|
19
20
|
|
|
@@ -283,6 +284,63 @@ OPERATION_NAME = re.compile(r"^[a-z][a-z0-9_]*$")
|
|
|
283
284
|
#: hyphens kept (``reference-count``), never a dot or slash, which address nested fields.
|
|
284
285
|
#: The TypeScript ``schema entity add`` pins the same rule (``PROPERTY_NAME`` in scaffoldJson.ts).
|
|
285
286
|
FIELD_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_-]*$")
|
|
287
|
+
METHODS = ("GET", "POST", "PUT", "PATCH", "DELETE")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def table_of(value: Any, location: str) -> dict:
|
|
291
|
+
"""A connector.toml table, or the refusal naming where one was expected."""
|
|
292
|
+
if not isinstance(value, dict):
|
|
293
|
+
fail("spec", "Expected a table", location)
|
|
294
|
+
return value
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def string_of(table: dict, key: str, location: str, *, default: str | None = None, required: bool = True) -> str | None:
|
|
298
|
+
"""``table[key]`` as a non-empty string, stripped; ``default`` when an optional key is absent."""
|
|
299
|
+
if key not in table and required:
|
|
300
|
+
fail("spec", f"Missing {key}", location)
|
|
301
|
+
if key not in table:
|
|
302
|
+
return default
|
|
303
|
+
value = table[key]
|
|
304
|
+
if not isinstance(value, str) or not value.strip():
|
|
305
|
+
fail("spec", f"{key} must be a non-empty string", f"{location}/{key}")
|
|
306
|
+
return value.strip()
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
PLACEHOLDER = re.compile(r"\{([A-Za-z_][A-Za-z0-9_]*)\}")
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def route_path(path: str, location: str) -> str:
|
|
313
|
+
"""``path`` as a route declares it: from ``/``, with no query or fragment, each
|
|
314
|
+
``{argument}`` a segment of its own at most once."""
|
|
315
|
+
if not path.startswith("/") or "?" in path or "#" in path:
|
|
316
|
+
fail("spec", "path must start with / and carry no query", location)
|
|
317
|
+
placeholders = PLACEHOLDER.findall(path)
|
|
318
|
+
repeated = [p for p in placeholders if placeholders.count(p) > 1]
|
|
319
|
+
if repeated:
|
|
320
|
+
fail(
|
|
321
|
+
"spec",
|
|
322
|
+
f"{{{repeated[0]}}} appears twice in path {path}; each path argument may appear once",
|
|
323
|
+
location,
|
|
324
|
+
argument=repeated[0],
|
|
325
|
+
)
|
|
326
|
+
return path
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
@functools.lru_cache(maxsize=4096)
|
|
330
|
+
def path_pattern(path: str) -> re.Pattern:
|
|
331
|
+
"""A declared path as a pattern over a request's path, each ``{name}`` one segment."""
|
|
332
|
+
escaped = re.escape(path)
|
|
333
|
+
return re.compile("^" + re.sub(r"\\\{([A-Za-z_][A-Za-z0-9_]*)\\\}", r"(?P<\1>[^/]+)", escaped) + "$")
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def names_of(table: dict, key: str, location: str, pattern: re.Pattern = FIELD_NAME) -> tuple[str, ...]:
|
|
337
|
+
"""``table[key]`` as a list of distinct names ``pattern`` accepts, empty when absent."""
|
|
338
|
+
value = table.get(key, [])
|
|
339
|
+
if not isinstance(value, list) or not all(isinstance(v, str) and pattern.match(v) for v in value):
|
|
340
|
+
fail("spec", f"{key} must be a list of field names", f"{location}/{key}")
|
|
341
|
+
if len(set(value)) != len(value):
|
|
342
|
+
fail("spec", f"{key} repeats a name", f"{location}/{key}")
|
|
343
|
+
return tuple(value)
|
|
286
344
|
|
|
287
345
|
|
|
288
346
|
def parse_toml(text: str) -> dict:
|
|
@@ -784,3 +842,13 @@ class Resolver:
|
|
|
784
842
|
name = sorted(set(self.documents) - self.checked)[0]
|
|
785
843
|
self.resolve(self.documents[name], name, f"{name}#", root=True)
|
|
786
844
|
self.checked.add(name)
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
def ttl_seconds_of(table: Mapping[str, Any], location: str) -> int | None:
|
|
848
|
+
"""``ttl_seconds`` when a world opts in to expiry, else None: it never expires."""
|
|
849
|
+
value = table.get("ttl_seconds")
|
|
850
|
+
if value is None:
|
|
851
|
+
return None
|
|
852
|
+
if isinstance(value, bool) or not isinstance(value, int) or value < 1:
|
|
853
|
+
fail("spec", "ttl_seconds is a positive whole number of seconds", f"{location}/ttl_seconds")
|
|
854
|
+
return value
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
"""The
|
|
2
|
-
|
|
3
|
-
through this table — the local session (``local.py``, ``/__session/<verb>``)
|
|
4
|
-
and the World Host control plane (``host.py``, ``/__host/sessions/<sid>/
|
|
5
|
-
<verb>``) — so the two cannot drift: a verb added here is served by both, a
|
|
6
|
-
body shape accepted here is accepted by both. The transports stay distinct
|
|
7
|
-
(loopback with no secret against a fleet with leases, workers and exports);
|
|
8
|
-
only the verbs are shared.
|
|
9
|
-
|
|
10
|
-
A verb marked ``hosted`` is the platform's rendezvous with a session it keeps
|
|
11
|
-
alive across hosts (the lease, the state export, DELETE as the platform's
|
|
12
|
-
close); the local session, which lives as long as the process serving it,
|
|
13
|
-
refuses them by name."""
|
|
1
|
+
"""The one verb table local.py and host.py both dispatch through, so the transports cannot drift; a ``hosted`` verb
|
|
2
|
+
is control plane only (lease, export, DELETE, the ledger's flush and outbox), refused by name locally."""
|
|
14
3
|
|
|
15
4
|
from __future__ import annotations
|
|
16
5
|
|
|
@@ -18,17 +7,15 @@ from collections.abc import Callable
|
|
|
18
7
|
from dataclasses import dataclass
|
|
19
8
|
from typing import Any
|
|
20
9
|
|
|
10
|
+
from ..world_session_contract import REQUEST_LOG_PAGE_MAX
|
|
21
11
|
from .redaction import parse_mode
|
|
12
|
+
from .request_ledger import OUTBOX_CURSOR
|
|
22
13
|
from .validation import ContractError, fail
|
|
14
|
+
from .webhooks import WebhookPoll
|
|
23
15
|
|
|
24
16
|
|
|
25
17
|
@dataclass(frozen=True)
|
|
26
18
|
class SessionVerb:
|
|
27
|
-
"""One row of the protocol: ``method`` and ``name`` are the route (``name``
|
|
28
|
-
None addresses the session itself, as ``DELETE`` does); ``read`` turns the
|
|
29
|
-
request body into the keyword arguments the session operation takes, or
|
|
30
|
-
refuses the shape (a :class:`ContractError` the transport answers 400)."""
|
|
31
|
-
|
|
32
19
|
method: str
|
|
33
20
|
name: str | None
|
|
34
21
|
read: Callable[[dict], dict[str, Any]]
|
|
@@ -47,9 +34,8 @@ def read_nothing(_body: dict) -> dict[str, Any]:
|
|
|
47
34
|
|
|
48
35
|
|
|
49
36
|
def read_seed(body: dict) -> dict[str, Any]:
|
|
50
|
-
"""``{rows, mode, redact}``, the same under ``args``
|
|
51
|
-
|
|
52
|
-
file has — taken as the rows of an append."""
|
|
37
|
+
"""``{rows, mode, redact}``, the same under ``args`` as the platform forwards it, or a bare rows file
|
|
38
|
+
``{entity: [row, ...]}`` taken as an append."""
|
|
53
39
|
args = body["args"] if isinstance(body.get("args"), dict) else body
|
|
54
40
|
if "rows" not in args and "mode" not in args and args and all(isinstance(v, list) for v in args.values()):
|
|
55
41
|
args = {"rows": args}
|
|
@@ -67,18 +53,20 @@ def read_seed(body: dict) -> dict[str, Any]:
|
|
|
67
53
|
|
|
68
54
|
|
|
69
55
|
def read_grade(body: dict) -> dict[str, Any]:
|
|
70
|
-
"""``report``
|
|
71
|
-
|
|
72
|
-
anything but a string is not. ``context`` is the evidence of the task's
|
|
73
|
-
other worlds (``{alias: state}``, each what that session's ``evidence``
|
|
74
|
-
answers), read by the cross-world verifiers anchored on this session."""
|
|
56
|
+
"""``report`` the agent's own account (a string), ``context`` the task's other worlds as ``{alias: state}``,
|
|
57
|
+
``journal`` the session's journal as the platform stored it, ``grader`` a candidate graded instead."""
|
|
75
58
|
report = body.get("report")
|
|
76
59
|
if report is not None and not isinstance(report, str):
|
|
77
60
|
fail("input", "report must be a string", "/report")
|
|
78
61
|
context = body.get("context")
|
|
79
|
-
if context is not None and (
|
|
62
|
+
if context is not None and (
|
|
63
|
+
not isinstance(context, dict) or any(not isinstance(v, dict) for v in context.values())
|
|
64
|
+
):
|
|
80
65
|
fail("input", "context must be {alias: state} of the task's other worlds", "/context")
|
|
81
|
-
|
|
66
|
+
for key in ("journal", "grader"):
|
|
67
|
+
if body.get(key) is not None and not isinstance(body[key], dict):
|
|
68
|
+
fail("input", f"{key} must be an object", f"/{key}")
|
|
69
|
+
return {"report": report, "context": context, "journal": body.get("journal"), "grader": body.get("grader")}
|
|
82
70
|
|
|
83
71
|
|
|
84
72
|
def read_call(body: dict) -> dict[str, Any]:
|
|
@@ -92,8 +80,26 @@ def read_call(body: dict) -> dict[str, Any]:
|
|
|
92
80
|
|
|
93
81
|
|
|
94
82
|
def read_export(body: dict) -> dict[str, Any]:
|
|
83
|
+
"""``knownSha256``: the platform's last export of the session; ``handoff``: this is the final
|
|
84
|
+
export of a session its host is handing off, which only that host takes."""
|
|
95
85
|
known = body.get("knownSha256")
|
|
96
|
-
return {"known_sha256": known if isinstance(known, str) else None}
|
|
86
|
+
return {"known_sha256": known if isinstance(known, str) else None, "handoff": body.get("handoff") is True}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def read_requests(body: dict) -> dict[str, Any]:
|
|
90
|
+
"""``cursor`` names the last outbox page that was stored (absent before the first); ``limit`` is 1 to
|
|
91
|
+
REQUEST_LOG_PAGE_MAX, the max when absent."""
|
|
92
|
+
cursor = body.get("cursor")
|
|
93
|
+
limit = body.get("limit", REQUEST_LOG_PAGE_MAX)
|
|
94
|
+
if cursor is not None and not (isinstance(cursor, str) and OUTBOX_CURSOR.fullmatch(cursor)):
|
|
95
|
+
fail("input", "cursor must be the cursor a page of the request ledger outbox answered", "/cursor")
|
|
96
|
+
if type(limit) is not int or not 1 <= limit <= REQUEST_LOG_PAGE_MAX:
|
|
97
|
+
fail("input", f"limit must be an integer from 1 to {REQUEST_LOG_PAGE_MAX}", "/limit")
|
|
98
|
+
return {"cursor": cursor, "limit": limit}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def read_webhooks(body: dict) -> dict[str, Any]:
|
|
102
|
+
return {"poll": WebhookPoll.parse(body)}
|
|
97
103
|
|
|
98
104
|
|
|
99
105
|
SESSION_VERBS: tuple[SessionVerb, ...] = (
|
|
@@ -101,6 +107,9 @@ SESSION_VERBS: tuple[SessionVerb, ...] = (
|
|
|
101
107
|
SessionVerb("GET", "task", read_nothing),
|
|
102
108
|
SessionVerb("GET", "state", read_nothing),
|
|
103
109
|
SessionVerb("GET", "evidence", read_nothing),
|
|
110
|
+
SessionVerb("POST", "requests", read_requests, hosted=True),
|
|
111
|
+
SessionVerb("POST", "flush", read_nothing, hosted=True),
|
|
112
|
+
SessionVerb("POST", "webhooks", read_webhooks),
|
|
104
113
|
SessionVerb("POST", "grade", read_grade),
|
|
105
114
|
SessionVerb("POST", "reset", read_nothing),
|
|
106
115
|
SessionVerb("POST", "seed", read_seed),
|
|
@@ -117,14 +126,10 @@ def session_verb(method: str, name: str | None) -> SessionVerb | None:
|
|
|
117
126
|
|
|
118
127
|
|
|
119
128
|
def served_verbs(*, hosted: bool) -> tuple[SessionVerb, ...]:
|
|
120
|
-
"""The rows a transport answers: every one on the host, the session's own
|
|
121
|
-
(not the lease's) locally."""
|
|
122
129
|
return tuple(verb for verb in SESSION_VERBS if hosted or not verb.hosted)
|
|
123
130
|
|
|
124
131
|
|
|
125
132
|
def unknown_verb(method: str, name: str | None, *, hosted: bool, prefix: str) -> dict:
|
|
126
|
-
"""The 404 body for a route off the table, naming what is on it. A hosted
|
|
127
|
-
verb sent to the local session is refused by name, not as unknown."""
|
|
128
133
|
verb = session_verb(method, name)
|
|
129
134
|
if verb is not None and verb.hosted and not hosted:
|
|
130
135
|
return {"error": f"{verb.route} is a hosted session's verb (the platform's lease); the local session has none"}
|
|
@@ -136,7 +141,4 @@ def unknown_verb(method: str, name: str | None, *, hosted: bool, prefix: str) ->
|
|
|
136
141
|
|
|
137
142
|
|
|
138
143
|
def refusal(error: ContractError) -> dict:
|
|
139
|
-
"""A refused call as the answer a session gives it: an unknown tool,
|
|
140
|
-
arguments off the schema, a tool outside the task's allow-list, a write the
|
|
141
|
-
store will not take, all ``{status: 400, body: {error, detail}}``."""
|
|
142
144
|
return {"status": 400, "body": {"error": error.detail.get("code", "host"), "detail": str(error)}}
|