@withgateway/sdk 0.3.3 → 0.4.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.
Files changed (123) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +2221 -962
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +2212 -953
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.js +81 -19
  7. package/dist/files/index.js.map +1 -1
  8. package/dist/files/index.mjs +79 -17
  9. package/dist/files/index.mjs.map +1 -1
  10. package/dist/hooks/index.d.mts +1 -1
  11. package/dist/hooks/index.d.ts +1 -1
  12. package/dist/hooks/index.js +124 -11
  13. package/dist/hooks/index.js.map +1 -1
  14. package/dist/hooks/index.mjs +124 -11
  15. package/dist/hooks/index.mjs.map +1 -1
  16. package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
  17. package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +903 -221
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +868 -212
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/traces/index.js +78 -16
  25. package/dist/traces/index.js.map +1 -1
  26. package/dist/traces/index.mjs +76 -14
  27. package/dist/traces/index.mjs.map +1 -1
  28. package/dist/tracing/index.js +7 -1
  29. package/dist/tracing/index.js.map +1 -1
  30. package/dist/tracing/index.mjs +7 -1
  31. package/dist/tracing/index.mjs.map +1 -1
  32. package/dist/worlds/index.d.mts +692 -410
  33. package/dist/worlds/index.d.ts +692 -410
  34. package/dist/worlds/index.js +740 -197
  35. package/dist/worlds/index.js.map +1 -1
  36. package/dist/worlds/index.mjs +736 -193
  37. package/dist/worlds/index.mjs.map +1 -1
  38. package/package.json +1 -1
  39. package/runtime/gatewaysdk/environment/_materialize.py +5 -25
  40. package/runtime/gatewaysdk/environment/_world.py +58 -65
  41. package/runtime/gatewaysdk/environment/backing.py +20 -24
  42. package/runtime/gatewaysdk/environment/core.py +1 -16
  43. package/runtime/gatewaysdk/environment/legacy_sqlite.py +14 -27
  44. package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
  45. package/runtime/gatewaysdk/environment/schema/api.py +174 -471
  46. package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
  47. package/runtime/gatewaysdk/environment/schema/batch.py +3 -3
  48. package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
  49. package/runtime/gatewaysdk/environment/schema/call_capture.py +309 -0
  50. package/runtime/gatewaysdk/environment/schema/call_log.py +230 -18
  51. package/runtime/gatewaysdk/environment/schema/call_redaction.py +201 -19
  52. package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
  53. package/runtime/gatewaysdk/environment/schema/conform.py +6 -27
  54. package/runtime/gatewaysdk/environment/schema/connector.py +89 -152
  55. package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
  56. package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +1 -0
  57. package/runtime/gatewaysdk/environment/schema/connectors/servicenow/connector.toml +2 -5
  58. package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
  59. package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
  60. package/runtime/gatewaysdk/environment/schema/data.py +14 -13
  61. package/runtime/gatewaysdk/environment/schema/database/base.py +106 -165
  62. package/runtime/gatewaysdk/environment/schema/database/guard.py +43 -36
  63. package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
  64. package/runtime/gatewaysdk/environment/schema/database/sqlite.py +57 -31
  65. package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
  66. package/runtime/gatewaysdk/environment/schema/door.py +899 -0
  67. package/runtime/gatewaysdk/environment/schema/envelope.py +86 -28
  68. package/runtime/gatewaysdk/environment/schema/grading.py +58 -86
  69. package/runtime/gatewaysdk/environment/schema/handler_errors.py +25 -4
  70. package/runtime/gatewaysdk/environment/schema/host.py +229 -1695
  71. package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
  72. package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
  73. package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
  74. package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
  75. package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
  76. package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
  77. package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
  78. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
  79. package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
  80. package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
  81. package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
  82. package/runtime/gatewaysdk/environment/schema/journal.py +437 -0
  83. package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
  84. package/runtime/gatewaysdk/environment/schema/local.py +31 -116
  85. package/runtime/gatewaysdk/environment/schema/platform.py +15 -17
  86. package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
  87. package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
  88. package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
  89. package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
  90. package/runtime/gatewaysdk/environment/schema/runtime.py +129 -176
  91. package/runtime/gatewaysdk/environment/schema/session_files.py +133 -24
  92. package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
  93. package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
  94. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +8 -9
  95. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +31 -6
  96. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +12 -8
  97. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +13 -13
  98. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +23 -23
  99. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
  100. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +35 -2
  101. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
  102. package/runtime/gatewaysdk/environment/schema/snapshot.py +149 -29
  103. package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
  104. package/runtime/gatewaysdk/environment/schema/tasks.py +229 -323
  105. package/runtime/gatewaysdk/environment/schema/tools_world.py +84 -203
  106. package/runtime/gatewaysdk/environment/schema/validation.py +69 -1
  107. package/runtime/gatewaysdk/environment/schema/verbs.py +32 -36
  108. package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
  109. package/runtime/gatewaysdk/environment/schema/workers.py +203 -39
  110. package/runtime/gatewaysdk/environment/schema/world_host.py +953 -0
  111. package/runtime/gatewaysdk/environment/schema/world_tests.py +9 -11
  112. package/runtime/gatewaysdk/environment/world.py +1 -1
  113. package/runtime/gatewaysdk/environment/world_session_contract.py +14 -0
  114. package/skills/agents/connector-template-author.md +5 -1
  115. package/skills/benchmarks-getting-started/SKILL.md +8 -9
  116. package/skills/connector-schema-authoring/SKILL.md +31 -6
  117. package/skills/connector-schema-authoring/connector-worlds.md +129 -7
  118. package/skills/world-data-ingestion/ROWS.md +12 -8
  119. package/skills/world-data-ingestion/SKILL.md +13 -13
  120. package/skills/worlds-getting-started/SKILL.md +23 -23
  121. package/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
  122. package/skills/worlds-getting-started/references/gotchas.md +35 -2
  123. package/skills/worlds-getting-started/references/journal-checks.md +182 -0
@@ -27,7 +27,7 @@ from __future__ import annotations
27
27
  from dataclasses import dataclass
28
28
  from pathlib import Path
29
29
 
30
- from .api import FILTER_KEY, OperationSettings, operation_api_settings
30
+ from .api import FILTER_KEY, ApiSettings, OperationSettings, operation_api_settings
31
31
  from .compiler import Contract
32
32
  from .connector import SPEC, Operation, Spec, spec_from
33
33
  from .validation import fail, parse_toml
@@ -67,8 +67,8 @@ def implied_filters(
67
67
  ) -> dict[str, str]:
68
68
  """Argument -> row field the served route filters on without an explicit
69
69
  ``filter``: each path segment, and on a read route each declared query
70
- parameter, naming a top-level field of the entity (``api._segment_filter``
71
- and ``api._query_field_filter``). The pager's names (``paging``) and names
70
+ parameter, naming a top-level field of the entity (``DeclaredRoute._segment_filter``
71
+ and ``DeclaredRoute._query_field_filter``). The pager's names (``paging``) and names
72
72
  the entity does not declare imply nothing."""
73
73
  if op.filter or not operation.entity:
74
74
  return {}
@@ -161,6 +161,28 @@ class RouteBindings:
161
161
  for binding in self:
162
162
  binding.check()
163
163
 
164
+ @classmethod
165
+ def served(
166
+ cls, spec: Spec | None, settings: ApiSettings | None, contract: Contract
167
+ ) -> list[tuple[str, tuple[str]]]:
168
+ """Every (entity, (field,)) a version's declared routes filter their rows on, as the
169
+ host serves them: what its read indexes cover beside the contract's keys."""
170
+ if spec is None or settings is None:
171
+ return []
172
+ return cls(spec, settings.operations, contract, settings.paging.params).read_fields()
173
+
174
+ def read_fields(self) -> list[tuple[str, tuple[str]]]:
175
+ keys = [
176
+ (binding.operation.entity, (field,))
177
+ for binding in self
178
+ if binding.op.action != "handler" and binding.operation.entity
179
+ for field in (
180
+ *binding.op.filter.values(),
181
+ *implied_filters(binding.operation, binding.op, self.contract, self.paging).values(),
182
+ )
183
+ ]
184
+ return list(dict.fromkeys(keys))
185
+
164
186
  def filters(self) -> dict[str, dict[str, str]]:
165
187
  """Operation -> the query filters it implies (:func:`implied_filters`), for the
166
188
  operations that imply any."""
@@ -0,0 +1,54 @@
1
+ """A request no declared route takes, and the world's answer to it: a path the world does not
2
+ serve answers its ``not_found``; a path it serves, called with a method none of its routes
3
+ answer, answers ``wrong_method`` (405 by default, with the ``Allow`` header RFC 9110 requires)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from collections.abc import Iterable
8
+ from dataclasses import dataclass
9
+ from typing import TYPE_CHECKING, Any
10
+
11
+ from .connector import METHODS, Operation
12
+
13
+ if TYPE_CHECKING:
14
+ from .api import ApiSettings
15
+
16
+ Answer = tuple[int, Any, "dict[str, str] | None"]
17
+
18
+
19
+ def served_methods(operations: Iterable[Operation]) -> tuple[str, ...]:
20
+ """The methods these operations answer, in :data:`~.connector.METHODS` order."""
21
+ answered = {method for operation in operations for method in operation.methods}
22
+ return tuple(method for method in METHODS if method in answered)
23
+
24
+
25
+ class RouteMiss:
26
+ """How a request missed every route; :meth:`of` is the one place the kind is decided."""
27
+
28
+ @staticmethod
29
+ def of(on_path: list[Operation]) -> RouteMiss:
30
+ """The miss for a request whose path the operations ``on_path`` take, none by its method."""
31
+ return WrongMethod(served_methods(on_path)) if on_path else NoRoute()
32
+
33
+ def answer(self, settings: ApiSettings) -> Answer:
34
+ raise NotImplementedError
35
+
36
+
37
+ @dataclass(frozen=True)
38
+ class NoRoute(RouteMiss):
39
+ """A path the world does not serve."""
40
+
41
+ def answer(self, settings: ApiSettings) -> Answer:
42
+ return settings.not_found_status, settings.not_found, None
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class WrongMethod(RouteMiss):
47
+ """A path the world serves, called with a method none of its routes answer."""
48
+
49
+ allowed: tuple[str, ...]
50
+
51
+ def answer(self, settings: ApiSettings) -> Answer:
52
+ status = settings.wrong_method_status
53
+ allow = {"Allow": ", ".join(self.allowed)} if status == 405 else None
54
+ return status, settings.wrong_method, allow