@withgateway/sdk 0.9.1 → 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.
- package/dist/agents/index.d.mts +12 -4
- package/dist/agents/index.d.ts +12 -4
- package/dist/agents/index.js +30 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +30 -0
- package/dist/agents/index.mjs.map +1 -1
- package/dist/cli.js +2291 -945
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2290 -944
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs.map +1 -1
- package/dist/index.js +325 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -183
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +1 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +1 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +3 -1
- package/dist/worlds/index.d.ts +3 -1
- package/dist/worlds/index.js +178 -67
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +177 -66
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +297 -9
- package/runtime/gatewaysdk/environment/factory_documents.py +670 -0
- package/runtime/gatewaysdk/environment/factory_rules.py +973 -0
- package/runtime/gatewaysdk/environment/factory_shapes.py +253 -0
- package/runtime/gatewaysdk/environment/factory_spine.py +1155 -0
- package/runtime/gatewaysdk/environment/factory_spine_shapes.py +480 -0
- package/runtime/gatewaysdk/environment/schema/admission.py +61 -59
- package/runtime/gatewaysdk/environment/schema/cast.py +133 -67
- package/runtime/gatewaysdk/environment/schema/compiler.py +16 -17
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +58 -4
- package/runtime/gatewaysdk/environment/schema/host.py +21 -2
- package/runtime/gatewaysdk/environment/schema/host_control.py +3 -1
- package/runtime/gatewaysdk/environment/schema/host_loops.py +27 -4
- package/runtime/gatewaysdk/environment/schema/host_metrics.py +69 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +21 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +7 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +4 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +172 -50
- package/runtime/gatewaysdk/environment/schema/ingest.py +12 -3
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/measured_tests.py +187 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +57 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +4 -3
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +105 -17
- package/runtime/gatewaysdk/environment/schema/process_memory.py +76 -0
- package/runtime/gatewaysdk/environment/schema/redaction.py +13 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +14 -0
- package/runtime/gatewaysdk/environment/schema/scaffold.py +21 -4
- package/runtime/gatewaysdk/environment/schema/shape_catalog.py +493 -0
- package/runtime/gatewaysdk/environment/schema/shape_declarations.py +219 -0
- package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/factory-orchestrator/SKILL.md +147 -0
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -4
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/shape-catalog.md +59 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +14 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +7 -4
- package/runtime/gatewaysdk/environment/schema/worker_key.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_peaks.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_watch.py +50 -0
- package/runtime/gatewaysdk/environment/schema/workers.py +237 -68
- package/runtime/gatewaysdk/environment/schema/world_host.py +56 -62
- package/runtime/gatewaysdk/environment/schema/world_tests.py +3 -1
- package/skills/connector-schema-authoring/SKILL.md +1 -0
- package/skills/connector-schema-authoring/connector-worlds.md +1 -0
- package/skills/connector-schema-authoring/world-schema.md +7 -0
- package/skills/factory-orchestrator/SKILL.md +147 -0
- package/skills/world-data-ingestion/ROWS.md +5 -1
- package/skills/world-data-ingestion/SKILL.md +4 -4
- package/skills/worlds-getting-started/SKILL.md +2 -2
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/skills/worlds-getting-started/references/shape-catalog.md +59 -0
|
@@ -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"
|