@withgateway/sdk 0.6.0 → 0.9.3

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 (150) hide show
  1. package/dist/agents/index.d.mts +581 -0
  2. package/dist/agents/index.d.ts +581 -0
  3. package/dist/agents/index.js +1473 -0
  4. package/dist/agents/index.js.map +1 -0
  5. package/dist/agents/index.mjs +1424 -0
  6. package/dist/agents/index.mjs.map +1 -0
  7. package/dist/apiError-DHpfbmdx.d.mts +17 -0
  8. package/dist/apiError-DHpfbmdx.d.ts +17 -0
  9. package/dist/cli.js +11611 -6845
  10. package/dist/cli.js.map +1 -1
  11. package/dist/cli.mjs +10090 -5325
  12. package/dist/cli.mjs.map +1 -1
  13. package/dist/files/index.d.mts +3 -1
  14. package/dist/files/index.d.ts +3 -1
  15. package/dist/files/index.js +371 -102
  16. package/dist/files/index.js.map +1 -1
  17. package/dist/files/index.mjs +371 -102
  18. package/dist/files/index.mjs.map +1 -1
  19. package/dist/hooks/index.js +346 -136
  20. package/dist/hooks/index.js.map +1 -1
  21. package/dist/hooks/index.mjs +346 -136
  22. package/dist/hooks/index.mjs.map +1 -1
  23. package/dist/{index-LA-PMRJT.d.ts → index-DIN14Lhg.d.ts} +1 -1
  24. package/dist/{index-Di9nNqOY.d.mts → index-DuB-eQ0Z.d.mts} +1 -1
  25. package/dist/index.d.mts +7 -4
  26. package/dist/index.d.ts +7 -4
  27. package/dist/index.js +3177 -748
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +2987 -590
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/media-CQUC7TkS.d.mts +39 -0
  32. package/dist/media-DQnBloaX.d.ts +39 -0
  33. package/dist/traces/index.d.mts +3 -1
  34. package/dist/traces/index.d.ts +3 -1
  35. package/dist/traces/index.js +371 -102
  36. package/dist/traces/index.js.map +1 -1
  37. package/dist/traces/index.mjs +371 -102
  38. package/dist/traces/index.mjs.map +1 -1
  39. package/dist/tracing/index.d.mts +3 -2
  40. package/dist/tracing/index.d.ts +3 -2
  41. package/dist/tracing/index.js +257 -16
  42. package/dist/tracing/index.js.map +1 -1
  43. package/dist/tracing/index.mjs +257 -16
  44. package/dist/tracing/index.mjs.map +1 -1
  45. package/dist/transport-CpRe7zgd.d.mts +123 -0
  46. package/dist/transport-CpRe7zgd.d.ts +123 -0
  47. package/dist/worlds/index.d.mts +1986 -1746
  48. package/dist/worlds/index.d.ts +1986 -1746
  49. package/dist/worlds/index.js +1470 -290
  50. package/dist/worlds/index.js.map +1 -1
  51. package/dist/worlds/index.mjs +1465 -286
  52. package/dist/worlds/index.mjs.map +1 -1
  53. package/package.json +6 -1
  54. package/runtime/gatewaysdk/environment/bundle_manifest.py +531 -0
  55. package/runtime/gatewaysdk/environment/factory_documents.py +670 -0
  56. package/runtime/gatewaysdk/environment/factory_rules.py +973 -0
  57. package/runtime/gatewaysdk/environment/factory_shapes.py +253 -0
  58. package/runtime/gatewaysdk/environment/factory_spine.py +1155 -0
  59. package/runtime/gatewaysdk/environment/factory_spine_shapes.py +480 -0
  60. package/runtime/gatewaysdk/environment/schema/__main__.py +2 -2
  61. package/runtime/gatewaysdk/environment/schema/_slack_fidelity.py +8 -23
  62. package/runtime/gatewaysdk/environment/schema/admission.py +61 -59
  63. package/runtime/gatewaysdk/environment/schema/api.py +3 -4
  64. package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
  65. package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
  66. package/runtime/gatewaysdk/environment/schema/call_log.py +20 -0
  67. package/runtime/gatewaysdk/environment/schema/cast.py +133 -67
  68. package/runtime/gatewaysdk/environment/schema/compiler.py +16 -17
  69. package/runtime/gatewaysdk/environment/schema/database/base.py +2 -2
  70. package/runtime/gatewaysdk/environment/schema/handler_errors.py +58 -4
  71. package/runtime/gatewaysdk/environment/schema/host.py +94 -12
  72. package/runtime/gatewaysdk/environment/schema/host_browser.py +48 -0
  73. package/runtime/gatewaysdk/environment/schema/host_control.py +35 -2
  74. package/runtime/gatewaysdk/environment/schema/host_handoff.py +4 -1
  75. package/runtime/gatewaysdk/environment/schema/host_loops.py +27 -4
  76. package/runtime/gatewaysdk/environment/schema/host_metrics.py +69 -0
  77. package/runtime/gatewaysdk/environment/schema/host_requests.py +35 -0
  78. package/runtime/gatewaysdk/environment/schema/host_session.py +20 -2
  79. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +6 -0
  80. package/runtime/gatewaysdk/environment/schema/host_versions.py +100 -19
  81. package/runtime/gatewaysdk/environment/schema/host_workers.py +172 -50
  82. package/runtime/gatewaysdk/environment/schema/ingest.py +12 -3
  83. package/runtime/gatewaysdk/environment/schema/journal.py +7 -2
  84. package/runtime/gatewaysdk/environment/schema/local.py +32 -7
  85. package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
  86. package/runtime/gatewaysdk/environment/schema/measured_tests.py +187 -0
  87. package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
  88. package/runtime/gatewaysdk/environment/schema/platform.py +80 -270
  89. package/runtime/gatewaysdk/environment/schema/platform_query.py +4 -3
  90. package/runtime/gatewaysdk/environment/schema/platform_templates.py +420 -0
  91. package/runtime/gatewaysdk/environment/schema/process_memory.py +76 -0
  92. package/runtime/gatewaysdk/environment/schema/redaction.py +13 -0
  93. package/runtime/gatewaysdk/environment/schema/request_ledger.py +4 -1
  94. package/runtime/gatewaysdk/environment/schema/run_parameters.py +25 -0
  95. package/runtime/gatewaysdk/environment/schema/runtime.py +57 -5
  96. package/runtime/gatewaysdk/environment/schema/scaffold.py +386 -219
  97. package/runtime/gatewaysdk/environment/schema/session_files.py +13 -2
  98. package/runtime/gatewaysdk/environment/schema/shape_catalog.py +493 -0
  99. package/runtime/gatewaysdk/environment/schema/shape_declarations.py +219 -0
  100. package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
  101. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +1 -1
  102. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +2 -2
  103. package/runtime/gatewaysdk/environment/schema/skills/factory-orchestrator/SKILL.md +147 -0
  104. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +5 -1
  105. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +8 -6
  106. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +9 -9
  107. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +33 -2
  108. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +6 -6
  109. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +17 -2
  110. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
  111. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/shape-catalog.md +59 -0
  112. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/ui-map.md +3 -2
  113. package/runtime/gatewaysdk/environment/schema/slack.py +55 -10
  114. package/runtime/gatewaysdk/environment/schema/snapshot.py +28 -2
  115. package/runtime/gatewaysdk/environment/schema/tasks.py +25 -2
  116. package/runtime/gatewaysdk/environment/schema/template_record.py +131 -0
  117. package/runtime/gatewaysdk/environment/schema/tools_world.py +7 -5
  118. package/runtime/gatewaysdk/environment/schema/ui.py +54 -33
  119. package/runtime/gatewaysdk/environment/schema/ui_interactions.py +419 -0
  120. package/runtime/gatewaysdk/environment/schema/ui_recorder.js +895 -0
  121. package/runtime/gatewaysdk/environment/schema/ui_replay.py +366 -0
  122. package/runtime/gatewaysdk/environment/schema/ui_replay_record.LICENSE +25 -0
  123. package/runtime/gatewaysdk/environment/schema/ui_replay_record.js +109 -0
  124. package/runtime/gatewaysdk/environment/schema/validation.py +24 -1
  125. package/runtime/gatewaysdk/environment/schema/worker.py +12 -5
  126. package/runtime/gatewaysdk/environment/schema/worker_key.py +38 -0
  127. package/runtime/gatewaysdk/environment/schema/worker_peaks.py +38 -0
  128. package/runtime/gatewaysdk/environment/schema/worker_watch.py +50 -0
  129. package/runtime/gatewaysdk/environment/schema/workers.py +245 -69
  130. package/runtime/gatewaysdk/environment/schema/world_host.py +96 -73
  131. package/runtime/gatewaysdk/environment/schema/world_tests.py +3 -1
  132. package/runtime/gatewaysdk/environment/secret_values.py +1 -1
  133. package/runtime/gatewaysdk/environment/world.py +34 -43
  134. package/runtime/gatewaysdk/environment/world_session_contract.py +7 -34
  135. package/skills/benchmarks-getting-started/SKILL.md +1 -1
  136. package/skills/connector-schema-authoring/SKILL.md +2 -2
  137. package/skills/connector-schema-authoring/connector-worlds.md +3 -2
  138. package/skills/connector-schema-authoring/world-schema.md +36 -23
  139. package/skills/factory-orchestrator/SKILL.md +147 -0
  140. package/skills/world-data-ingestion/ROWS.md +5 -1
  141. package/skills/world-data-ingestion/SKILL.md +8 -6
  142. package/skills/worlds-getting-started/SKILL.md +9 -9
  143. package/skills/worlds-getting-started/references/cli-mcp-map.md +33 -2
  144. package/skills/worlds-getting-started/references/gotchas.md +6 -6
  145. package/skills/worlds-getting-started/references/journal-checks.md +17 -2
  146. package/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
  147. package/skills/worlds-getting-started/references/shape-catalog.md +59 -0
  148. package/skills/worlds-getting-started/references/ui-map.md +3 -2
  149. package/dist/media-BIApiPzS.d.mts +0 -102
  150. package/dist/media-BIApiPzS.d.ts +0 -102
@@ -0,0 +1,253 @@
1
+ """Stdlib only: the runner vendors this package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import math
7
+ import re
8
+ from collections.abc import Callable, Mapping
9
+ from types import MappingProxyType
10
+ from typing import Any
11
+
12
+ from .bundle_manifest import _utf16_length, _world_slug
13
+
14
+ FACTORY_LIMITS: Mapping[str, int] = MappingProxyType(
15
+ {
16
+ "nodesPerFactory": 5000,
17
+ "nodeBytes": 256 * 1024,
18
+ "factoryBytes": 64 * 1024 * 1024,
19
+ "refsPerNode": 200,
20
+ "relationsPerNode": 200,
21
+ "nodesPerEdit": 500,
22
+ "codeBytes": 64 * 1024,
23
+ "nameLength": 120,
24
+ "sentenceLength": 2000,
25
+ "kindLength": 64,
26
+ "tableRows": 20_000,
27
+ "rowBytes": 16 * 1024,
28
+ "columnsPerTable": 64,
29
+ "keyLength": 256,
30
+ "pageRows": 500,
31
+ "checksPerNode": 50,
32
+ "formulaBytes": 4 * 1024,
33
+ "spineRowsPage": 200,
34
+ "rowEditsPerEdit": 20_000,
35
+ }
36
+ )
37
+ FACTORY_NODE_ID = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$")
38
+ Check = Callable[[Any], bool]
39
+
40
+
41
+ def _string(min_length: int = 0, max_length: int | None = None) -> Check:
42
+ def check(value: Any) -> bool:
43
+ if not isinstance(value, str):
44
+ return False
45
+ length = _utf16_length(value)
46
+ return length >= min_length and (max_length is None or length <= max_length)
47
+
48
+ return check
49
+
50
+
51
+ def _node_id(value: Any) -> bool:
52
+ return isinstance(value, str) and FACTORY_NODE_ID.fullmatch(value) is not None
53
+
54
+
55
+ def _slug(value: Any) -> bool:
56
+ return isinstance(value, str) and _world_slug(value)
57
+
58
+
59
+ def _source(value: Any) -> bool:
60
+ return isinstance(value, str) and len(value.encode("utf-8", "surrogatepass")) <= FACTORY_LIMITS["codeBytes"]
61
+
62
+
63
+ def _number(value: Any) -> bool:
64
+ return isinstance(value, (int, float)) and not isinstance(value, bool) and math.isfinite(value)
65
+
66
+
67
+ def _json(value: Any) -> bool:
68
+ if isinstance(value, dict):
69
+ return all(isinstance(key, str) and _json(item) for key, item in value.items())
70
+ if isinstance(value, list):
71
+ return all(_json(item) for item in value)
72
+ return value is None or isinstance(value, (str, bool)) or _number(value)
73
+
74
+
75
+ def _literal(expected: str) -> Check:
76
+ return lambda value: value == expected
77
+
78
+
79
+ def _one_of(*allowed: str) -> Check:
80
+ return lambda value: isinstance(value, str) and value in allowed
81
+
82
+
83
+ def _array(item: Check, min_items: int = 0, max_items: int | None = None) -> Check:
84
+ def check(value: Any) -> bool:
85
+ if not isinstance(value, list):
86
+ return False
87
+ sized = len(value) >= min_items and (max_items is None or len(value) <= max_items)
88
+ return sized and all(item(element) for element in value)
89
+
90
+ return check
91
+
92
+
93
+ def _record(item: Check, key: Check = _string()) -> Check:
94
+ return lambda value: isinstance(value, dict) and all(key(k) and item(v) for k, v in value.items())
95
+
96
+
97
+ def _strict(required: Mapping[str, Check], optional: Mapping[str, Check] | None = None) -> Check:
98
+ allowed = {**required, **(optional or {})}
99
+
100
+ def check(value: Any) -> bool:
101
+ if not isinstance(value, dict) or not set(required) <= set(value) <= set(allowed):
102
+ return False
103
+ return all(allowed[key](item) for key, item in value.items())
104
+
105
+ return check
106
+
107
+
108
+ def _any_of(*checks: Check) -> Check:
109
+ return lambda value: any(check(value) for check in checks)
110
+
111
+
112
+ def _tagged(tag: str, shapes: Mapping[str, Check]) -> Check:
113
+ def check(value: Any) -> bool:
114
+ tagged = value.get(tag) if isinstance(value, dict) else None
115
+ shape = shapes.get(tagged) if isinstance(tagged, str) else None
116
+ return shape is not None and shape(value)
117
+
118
+ return check
119
+
120
+
121
+ _TEXT = _string(1)
122
+ _KIND = _string(1, FACTORY_LIMITS["kindLength"])
123
+
124
+ _REF = _tagged(
125
+ "kind",
126
+ {
127
+ "node": _strict({"kind": _literal("node"), "id": _node_id}),
128
+ "row": _strict({"kind": _literal("row"), "node": _node_id, "key": _string(1)}),
129
+ "world": _strict({"kind": _literal("world"), "slug": _slug}),
130
+ "schema": _strict(
131
+ {"kind": _literal("schema"), "world": _slug, "entity": _TEXT},
132
+ {"field": _TEXT},
133
+ ),
134
+ "object": _strict(
135
+ {
136
+ "kind": _literal("object"),
137
+ "world": _slug,
138
+ "entity": _TEXT,
139
+ "key": lambda key: bool(key) and _record(lambda v: isinstance(v, str) or _number(v), _TEXT)(key),
140
+ }
141
+ ),
142
+ "statement": _strict({"kind": _literal("statement"), "id": _TEXT}),
143
+ "file": _strict({"kind": _literal("file"), "path": _TEXT}),
144
+ },
145
+ )
146
+ _REFS = _array(_REF, max_items=FACTORY_LIMITS["refsPerNode"])
147
+
148
+ _BASE_REQUIRED: dict[str, Check] = {
149
+ "id": _node_id,
150
+ "name": _string(1, FACTORY_LIMITS["nameLength"]),
151
+ "sentence": _string(0, FACTORY_LIMITS["sentenceLength"]),
152
+ }
153
+ _BASE_OPTIONAL: dict[str, Check] = {"properties": _record(_json), "refs": _REFS}
154
+
155
+
156
+ def _node_shape(doc: str, required: Mapping[str, Check], optional: Mapping[str, Check]) -> Check:
157
+ return _strict(
158
+ {**_BASE_REQUIRED, "doc": _literal(doc), **required},
159
+ {**_BASE_OPTIONAL, **optional},
160
+ )
161
+
162
+
163
+ # diff3 conflicts on edits to one line or to adjacent lines: a blank line between fields and between items
164
+ # lets different ones merge, and each array item is one line, so two edits of one item conflict. A node's
165
+ # `entity` pointer is one line too, so a world edited on one side and an entity on the other never blend.
166
+ _PARAGRAPH = ",\n\n"
167
+ _ONE_LINE_FIELDS = frozenset({"entity"})
168
+ _LONE_SURROGATE = re.compile("[\ud800-\udfff]")
169
+ _FIXED_DIGITS = 21
170
+
171
+
172
+ def _javascript_number(value: int | float) -> str:
173
+ try:
174
+ number = float(value)
175
+ except OverflowError:
176
+ return "null"
177
+ if not math.isfinite(number):
178
+ return "null"
179
+ if number == 0:
180
+ return "0"
181
+ sign = "-" if number < 0 else ""
182
+ return sign + _javascript_magnitude(abs(number))
183
+
184
+
185
+ def _javascript_magnitude(number: float) -> str:
186
+ mantissa, _, exponent = repr(number).partition("e")
187
+ whole, _, fraction = mantissa.partition(".")
188
+ combined = whole + fraction
189
+ digits = combined.lstrip("0").rstrip("0")
190
+ point = len(whole) + int(exponent or 0) - (len(combined) - len(combined.lstrip("0")))
191
+ return _javascript_layout(digits, point)
192
+
193
+
194
+ def _javascript_layout(digits: str, point: int) -> str:
195
+ if len(digits) <= point <= _FIXED_DIGITS:
196
+ return digits + "0" * (point - len(digits))
197
+ if 0 < point <= _FIXED_DIGITS:
198
+ return f"{digits[:point]}.{digits[point:]}"
199
+ if -6 < point <= 0:
200
+ return "0." + "0" * -point + digits
201
+ exponent = point - 1
202
+ mantissa = digits if len(digits) == 1 else f"{digits[0]}.{digits[1:]}"
203
+ return f"{mantissa}e{'+' if exponent >= 0 else '-'}{abs(exponent)}"
204
+
205
+
206
+ def _javascript_json(value: Any) -> str:
207
+ if isinstance(value, bool) or value is None or isinstance(value, str):
208
+ return json.dumps(value, ensure_ascii=False)
209
+ if isinstance(value, (int, float)):
210
+ return _javascript_number(value)
211
+ if isinstance(value, list):
212
+ return "[" + ", ".join(_javascript_json(item) for item in value) + "]"
213
+ return (
214
+ "{"
215
+ + ", ".join(f"{json.dumps(key, ensure_ascii=False)}: {_javascript_json(value[key])}" for key in sorted(value))
216
+ + "}"
217
+ )
218
+
219
+
220
+ def _json_text(value: Any) -> str:
221
+ return _LONE_SURROGATE.sub(lambda char: f"\\u{ord(char.group()):04x}", _javascript_json(value))
222
+
223
+
224
+ def _canonical_text(value: Any, indent: str, one_line: frozenset[str] = frozenset()) -> str:
225
+ if isinstance(value, list):
226
+ return _canonical_array(value, indent)
227
+ if isinstance(value, dict):
228
+ return _canonical_object(value, indent, one_line)
229
+ return _json_text(value)
230
+
231
+
232
+ def _canonical_array(items: list[Any], indent: str) -> str:
233
+ if not items:
234
+ return "[]"
235
+ inner = indent + " "
236
+ lines = [inner + _json_text(item) for item in items]
237
+ return f"[\n{_PARAGRAPH.join(lines)}\n{indent}]"
238
+
239
+
240
+ def _canonical_object(record: dict[str, Any], indent: str, one_line: frozenset[str]) -> str:
241
+ if not record:
242
+ return "{}"
243
+ inner = indent + " "
244
+
245
+ def value_text(key: str) -> str:
246
+ return _json_text(record[key]) if key in one_line else _canonical_text(record[key], inner)
247
+
248
+ fields = [f"{inner}{_json_text(key)}: {value_text(key)}" for key in sorted(record)]
249
+ return f"{{\n{_PARAGRAPH.join(fields)}\n{indent}}}"
250
+
251
+
252
+ def canonical(value: Any) -> str:
253
+ return _canonical_text(value, "", _ONE_LINE_FIELDS) + "\n"