@withgateway/sdk 0.3.1 → 0.3.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/README.md +4 -3
- package/dist/cli.js +2880 -2032
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2982 -2135
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +180 -41
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +172 -35
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-CBqbB_0J.d.ts → index-DUHmS74p.d.ts} +1 -1
- package/dist/{index-D-AMnAMa.d.mts → index-mJhG3vZU.d.mts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1309 -540
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1287 -532
- package/dist/index.mjs.map +1 -1
- package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
- package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
- package/dist/traces/index.d.mts +1 -1
- package/dist/traces/index.d.ts +1 -1
- package/dist/traces/index.js +177 -38
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +169 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -2
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +69 -13
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +69 -13
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +249 -120
- package/dist/worlds/index.d.ts +249 -120
- package/dist/worlds/index.js +1240 -484
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1231 -476
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +2 -27
- package/runtime/gatewaysdk/environment/_materialize.py +49 -69
- package/runtime/gatewaysdk/environment/_world.py +122 -197
- package/runtime/gatewaysdk/environment/backing.py +137 -0
- package/runtime/gatewaysdk/environment/core.py +1 -1
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +301 -0
- package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
- package/runtime/gatewaysdk/environment/runtime.py +8 -13
- package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
- package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
- package/runtime/gatewaysdk/environment/schema/api.py +266 -514
- package/runtime/gatewaysdk/environment/schema/batch.py +42 -37
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
- package/runtime/gatewaysdk/environment/schema/call_log.py +291 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +344 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
- package/runtime/gatewaysdk/environment/schema/conform.py +8 -12
- package/runtime/gatewaysdk/environment/schema/connector.py +27 -62
- package/runtime/gatewaysdk/environment/schema/data.py +50 -207
- package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
- package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +995 -0
- package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
- package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
- package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +208 -0
- package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
- package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
- package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
- package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
- package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +367 -0
- package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +169 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
- package/runtime/gatewaysdk/environment/schema/grading.py +45 -30
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +142 -12
- package/runtime/gatewaysdk/environment/schema/host.py +158 -250
- package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
- package/runtime/gatewaysdk/environment/schema/local.py +44 -71
- package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
- package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
- package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
- package/runtime/gatewaysdk/environment/schema/platform.py +123 -171
- package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
- package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
- package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
- package/runtime/gatewaysdk/environment/schema/runtime.py +77 -160
- package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
- package/runtime/gatewaysdk/environment/schema/session_files.py +166 -0
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +19 -11
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +29 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +14 -14
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +12 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
- package/runtime/gatewaysdk/environment/schema/snapshot.py +385 -129
- package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
- package/runtime/gatewaysdk/environment/schema/tasks.py +140 -55
- package/runtime/gatewaysdk/environment/schema/tools_world.py +110 -87
- package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
- package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
- package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
- package/runtime/gatewaysdk/environment/schema/validation.py +166 -40
- package/runtime/gatewaysdk/environment/schema/workers.py +142 -57
- package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +71 -39
- package/runtime/gatewaysdk/environment/score.py +57 -0
- package/runtime/gatewaysdk/environment/secret_values.py +36 -0
- package/runtime/gatewaysdk/environment/world.py +42 -3
- package/runtime/gatewaysdk/environment/world_session_contract.py +32 -5
- package/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/skills/connector-schema-authoring/SKILL.md +19 -11
- package/skills/connector-schema-authoring/connector-worlds.md +13 -4
- package/skills/connector-schema-authoring/world-schema.md +103 -51
- package/skills/world-data-ingestion/ROWS.md +29 -3
- package/skills/world-data-ingestion/SKILL.md +14 -14
- package/skills/worlds-getting-started/SKILL.md +12 -12
- package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
|
@@ -26,10 +26,10 @@ from typing import TYPE_CHECKING, Any
|
|
|
26
26
|
|
|
27
27
|
from .._materialize import materialize_template
|
|
28
28
|
from ..world import WorldTree
|
|
29
|
-
from . import ContractError,
|
|
29
|
+
from . import ContractError, WorldDatabase, bundle_mode, check_bundle, compile_bundle, platform_import, platform_query
|
|
30
30
|
from . import snapshot as snapshots
|
|
31
31
|
from .cast import world_fields
|
|
32
|
-
from .compiler import
|
|
32
|
+
from .compiler import CompilePlan, retarget_journals
|
|
33
33
|
from .handler_scan import HandlerScan
|
|
34
34
|
from .redaction import check_world_redaction
|
|
35
35
|
from .scaffold import request_files
|
|
@@ -73,6 +73,8 @@ COMMANDS = (
|
|
|
73
73
|
"reconcile",
|
|
74
74
|
"counts",
|
|
75
75
|
"query",
|
|
76
|
+
"sql",
|
|
77
|
+
"verify-legacy",
|
|
76
78
|
"api-bundle",
|
|
77
79
|
"templates",
|
|
78
80
|
"validate-rows",
|
|
@@ -90,20 +92,15 @@ def compile_world(root: Path) -> dict:
|
|
|
90
92
|
|
|
91
93
|
The platform stores compiled trees, so a world whose authored inputs changed
|
|
92
94
|
(``schema/world.json``, ``gateway-env.toml``, handlers) is recompiled here
|
|
93
|
-
rather than rejected with ``lock_mismatch``.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
the rows against the new schema). The snapshots are then rebuilt loudly:
|
|
98
|
-
data the contract refuses is a rejection, not a dropped snapshot.
|
|
95
|
+
rather than rejected with ``lock_mismatch``. A journal follows the contract when
|
|
96
|
+
its rows carry over (``retarget_journals``) and is refused otherwise, before
|
|
97
|
+
anything is written. The snapshots are then rebuilt loudly: data the contract
|
|
98
|
+
refuses is a rejection, not a dropped snapshot.
|
|
99
99
|
"""
|
|
100
100
|
from .snapshot import build_all
|
|
101
101
|
|
|
102
102
|
if bundle_mode(root) is None:
|
|
103
|
-
fail(
|
|
104
|
-
"mode",
|
|
105
|
-
"Expected a schema-backed mock-tools world (gateway-env.toml with [schema] language)",
|
|
106
|
-
)
|
|
103
|
+
fail("mode", "Expected a schema-backed mock-tools world (gateway-env.toml with [schema] language)")
|
|
107
104
|
added = []
|
|
108
105
|
base = root / "schema/base.json"
|
|
109
106
|
if not base.exists():
|
|
@@ -112,7 +109,9 @@ def compile_world(root: Path) -> dict:
|
|
|
112
109
|
base.parent.mkdir(parents=True, exist_ok=True)
|
|
113
110
|
base.write_bytes((TEMPLATES / "base.json").read_bytes())
|
|
114
111
|
added.append("schema/base.json")
|
|
115
|
-
|
|
112
|
+
plan = CompilePlan.of(root)
|
|
113
|
+
retargeted = retarget_journals(root, plan.contract)
|
|
114
|
+
contract = plan.write()
|
|
116
115
|
initial = root / "data/initial.json"
|
|
117
116
|
if not initial.exists():
|
|
118
117
|
initial.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -128,7 +127,6 @@ def compile_world(root: Path) -> dict:
|
|
|
128
127
|
)
|
|
129
128
|
)
|
|
130
129
|
added.append("data/initial.json")
|
|
131
|
-
retargeted = retarget_empty_journals(root, contract)
|
|
132
130
|
build_all(root, contract)
|
|
133
131
|
return {"added": added, "retargeted": retargeted}
|
|
134
132
|
|
|
@@ -143,6 +141,7 @@ def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
|
143
141
|
Replaying every prior journal first makes a repeated batch id idempotent and
|
|
144
142
|
a reused id with different content a conflict, exactly as in the store.
|
|
145
143
|
"""
|
|
144
|
+
snapshots.refuse_pinned_rows(root)
|
|
146
145
|
contract = check_bundle(root)
|
|
147
146
|
members(
|
|
148
147
|
batch,
|
|
@@ -151,7 +150,7 @@ def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
|
151
150
|
"/batch",
|
|
152
151
|
)
|
|
153
152
|
nonempty(batch["id"], "/batch/id")
|
|
154
|
-
if "target" in batch and batch["target"]
|
|
153
|
+
if "target" in batch and not contract.targets(batch["target"]):
|
|
155
154
|
fail(
|
|
156
155
|
"batch_target",
|
|
157
156
|
"Batch targets a different domain identity/version/hash",
|
|
@@ -182,7 +181,7 @@ def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
|
182
181
|
journals = journal_paths(root)
|
|
183
182
|
with (
|
|
184
183
|
tempfile.TemporaryDirectory(prefix="gateway-apply-batch-") as temporary,
|
|
185
|
-
|
|
184
|
+
WorldDatabase.create(Path(temporary) / "world.db", contract) as store,
|
|
186
185
|
):
|
|
187
186
|
for path in journals:
|
|
188
187
|
store.apply_batch(read_json(path))
|
|
@@ -195,9 +194,8 @@ def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
|
195
194
|
existing = len(journals) - 1
|
|
196
195
|
target = batches / f"{existing + 1:06d}-{digest(batch['id'].encode())[:16]}.json"
|
|
197
196
|
target.write_bytes(encoded(resolved))
|
|
198
|
-
if snapshots.
|
|
199
|
-
#
|
|
200
|
-
# over them. Rebuild so the tree stays one thing (default + scenarios).
|
|
197
|
+
if snapshots.has_default_snapshot(root):
|
|
198
|
+
# A snapshot built before this batch would be served over the grown journals.
|
|
201
199
|
from .compiler import build
|
|
202
200
|
from .snapshot import build_all
|
|
203
201
|
|
|
@@ -205,38 +203,6 @@ def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
|
205
203
|
return {**result, "journal": str(target.relative_to(root))}
|
|
206
204
|
|
|
207
205
|
|
|
208
|
-
def _pinned_state(bundle: Path, contract) -> dict[str, int] | None:
|
|
209
|
-
"""The entity counts of a data-only version whose hosted snapshot is not in the
|
|
210
|
-
tree: ``db/snapshot.json`` alone. The platform audited that snapshot through
|
|
211
|
-
this contract when it built it, so the pin stands in for the state check —
|
|
212
|
-
provided it names this contract; a snapshot built through another contract
|
|
213
|
-
is refused, since the tree's data files cannot reproduce it either. A tree
|
|
214
|
-
that carries its snapshot, or no pin at all, materializes as usual."""
|
|
215
|
-
from .snapshot import contract_hash, current_default, pinned_default
|
|
216
|
-
|
|
217
|
-
pin = pinned_default(bundle)
|
|
218
|
-
if pin is None or current_default(bundle, contract) is not None:
|
|
219
|
-
return None
|
|
220
|
-
if pin.get("contractHash") != contract_hash(contract):
|
|
221
|
-
fail(
|
|
222
|
-
"snapshot_pinned",
|
|
223
|
-
"db/snapshot.json pins a hosted snapshot built through a different contract; "
|
|
224
|
-
"re-import its rows against the current schema (import_world_data, "
|
|
225
|
-
"gateway worlds data import) or restore the schema it was built against",
|
|
226
|
-
"/db/snapshot.json",
|
|
227
|
-
)
|
|
228
|
-
counts = pin.get("entityCounts")
|
|
229
|
-
if not isinstance(counts, dict) or any(
|
|
230
|
-
not isinstance(value, int) or isinstance(value, bool) for value in counts.values()
|
|
231
|
-
):
|
|
232
|
-
fail(
|
|
233
|
-
"snapshot_pin",
|
|
234
|
-
"db/snapshot.json must carry the hosted snapshot's entityCounts",
|
|
235
|
-
"/db/snapshot.json",
|
|
236
|
-
)
|
|
237
|
-
return {entity: int(counts.get(entity, 0)) for entity in contract.entities}
|
|
238
|
-
|
|
239
|
-
|
|
240
206
|
def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
241
207
|
"""Check a schema world: the contract, the handlers by syntax and by name, the
|
|
242
208
|
initial state, every verifier over it, the tasks and the links. ``execute``
|
|
@@ -255,14 +221,13 @@ def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
|
255
221
|
load_api_settings(bundle, parse_spec((bundle / "connector.toml").read_text(encoding="utf-8")))
|
|
256
222
|
_check_mappings(bundle, contract)
|
|
257
223
|
check_world_redaction(bundle)
|
|
258
|
-
pinned =
|
|
224
|
+
pinned = snapshots.pinned_counts(bundle, contract)
|
|
259
225
|
verifiers: dict[str, Any] = {}
|
|
260
226
|
if pinned is not None:
|
|
261
227
|
counts, initial_state = pinned, "pinned"
|
|
262
|
-
# The pinned snapshot is not in the tree
|
|
263
|
-
# bare schema: an error still surfaces; a score means nothing here.
|
|
228
|
+
# The pinned snapshot is not in the tree: an error still surfaces, a score means nothing.
|
|
264
229
|
with tempfile.TemporaryDirectory(prefix="gateway-state-check-") as staging:
|
|
265
|
-
with
|
|
230
|
+
with WorldDatabase.create(Path(staging) / "world.db", contract) as store:
|
|
266
231
|
unattached = _attach_dependencies(bundle, store, Path(staging))
|
|
267
232
|
verifiers = _check_verifiers(bundle, store, unattached, scored=False)
|
|
268
233
|
else:
|
|
@@ -270,7 +235,7 @@ def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
|
270
235
|
with tempfile.TemporaryDirectory(prefix="gateway-state-check-") as staging:
|
|
271
236
|
database = Path(staging) / "world.db"
|
|
272
237
|
materialize_template(bundle, database)
|
|
273
|
-
with
|
|
238
|
+
with WorldDatabase.open(database, contract) as store:
|
|
274
239
|
store.audit()
|
|
275
240
|
counts = {entity: len(store.list(entity)) for entity in contract.entities}
|
|
276
241
|
unattached = _attach_dependencies(bundle, store, Path(staging))
|
|
@@ -280,8 +245,9 @@ def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
|
280
245
|
"domain": contract.target,
|
|
281
246
|
"package": contract.metadata["package"],
|
|
282
247
|
"initial_state": initial_state,
|
|
283
|
-
"handler_execution": _handler_execution(bundle, execute, declared),
|
|
248
|
+
"handler_execution": _handler_execution(bundle, execute, declared, hosted=pinned is not None),
|
|
284
249
|
"entity_counts": counts,
|
|
250
|
+
"data_migration": snapshots.migration_view(bundle, contract),
|
|
285
251
|
"tools": sorted(declared),
|
|
286
252
|
"verifiers": verifiers,
|
|
287
253
|
"tasks": _check_tasks(bundle, sorted(verifiers)),
|
|
@@ -294,7 +260,7 @@ def _check_mappings(bundle: Path, contract: Contract) -> None:
|
|
|
294
260
|
"""Each ``[dependencies.<alias>.entities]`` mapping against this contract
|
|
295
261
|
and, for a dependency whose ``path`` is here, against that contract too."""
|
|
296
262
|
from .. import _bundle
|
|
297
|
-
from .dependencies import
|
|
263
|
+
from .dependencies import check_mappings, parse_dependencies
|
|
298
264
|
|
|
299
265
|
dependencies = parse_dependencies(_bundle.parse_manifest(bundle).raw)
|
|
300
266
|
deps: dict[str, FieldMap] = {}
|
|
@@ -311,7 +277,7 @@ def _field_map(contract: Contract) -> FieldMap:
|
|
|
311
277
|
return {name: set(entity["schema"].get("properties", {})) for name, entity in contract.entities.items()}
|
|
312
278
|
|
|
313
279
|
|
|
314
|
-
def _attach_dependencies(bundle: Path, store:
|
|
280
|
+
def _attach_dependencies(bundle: Path, store: WorldDatabase, staging: Path) -> dict[str, str]:
|
|
315
281
|
"""Each ``[dependencies]`` entry whose local ``path`` is on this machine,
|
|
316
282
|
materialized beside the root's store and attached as ``<alias>.<table>``,
|
|
317
283
|
so a cross-world verifier runs here the way it runs in a session. Returns
|
|
@@ -343,7 +309,7 @@ def _attach_dependencies(bundle: Path, store: SQLiteStore, staging: Path) -> dic
|
|
|
343
309
|
return unattached
|
|
344
310
|
|
|
345
311
|
|
|
346
|
-
def _check_verifiers(bundle: Path, store:
|
|
312
|
+
def _check_verifiers(bundle: Path, store: WorldDatabase, unattached: dict[str, str], *, scored: bool) -> dict[str, Any]:
|
|
347
313
|
"""Every ``verifiers/*.sql`` run over the template through the store's
|
|
348
314
|
read-only authorizer, the way a session grades. A verifier that names a
|
|
349
315
|
table or column the contract lacks is refused here — at check — not at
|
|
@@ -362,11 +328,13 @@ def _check_verifiers(bundle: Path, store: SQLiteStore, unattached: dict[str, str
|
|
|
362
328
|
return out
|
|
363
329
|
|
|
364
330
|
|
|
365
|
-
def _check_verifier(path: Path, store:
|
|
331
|
+
def _check_verifier(path: Path, store: WorldDatabase, unattached: dict[str, str], *, scored: bool) -> dict[str, Any]:
|
|
366
332
|
from .._world import SqlVerifier, VerifierError
|
|
367
333
|
|
|
368
334
|
try:
|
|
369
|
-
score, _sql = SqlVerifier.read(path).score(
|
|
335
|
+
score, _sql = SqlVerifier.read(path, store.split_statements).score(
|
|
336
|
+
lambda statement: store.query(statement, private=True)
|
|
337
|
+
)
|
|
370
338
|
except ContractError as error:
|
|
371
339
|
alias = _refuse_verifier(path, store, unattached, error)
|
|
372
340
|
return {
|
|
@@ -381,15 +349,16 @@ def _check_verifier(path: Path, store: SQLiteStore, unattached: dict[str, str],
|
|
|
381
349
|
return {"status": "ok", "initial_score": score}
|
|
382
350
|
|
|
383
351
|
|
|
384
|
-
def _refuse_verifier(path: Path, store:
|
|
352
|
+
def _refuse_verifier(path: Path, store: WorldDatabase, unattached: dict[str, str], error: ContractError) -> str:
|
|
385
353
|
"""The unattached dependency alias the failure names — the one refusal
|
|
386
354
|
check reports rather than raises; every other failure is refused here."""
|
|
387
355
|
reason = error.__cause__ if error.__cause__ is not None else error.detail["message"]
|
|
388
|
-
|
|
356
|
+
missing = store.missing_table(reason)
|
|
357
|
+
alias = _missing_dependency_alias(missing, unattached)
|
|
389
358
|
if alias is not None:
|
|
390
359
|
return alias
|
|
391
360
|
hint = ""
|
|
392
|
-
if
|
|
361
|
+
if missing is not None:
|
|
393
362
|
tables = sorted(store.contract.entities)
|
|
394
363
|
tables += [f"{a}.{t}" for a, ts in sorted(store.attached.items()) for t in sorted(ts)]
|
|
395
364
|
hint = f"; the world's entities are {', '.join(tables) or '(none)'}"
|
|
@@ -400,14 +369,9 @@ def _refuse_verifier(path: Path, store: SQLiteStore, unattached: dict[str, str],
|
|
|
400
369
|
)
|
|
401
370
|
|
|
402
371
|
|
|
403
|
-
def _missing_dependency_alias(
|
|
404
|
-
"""The alias of an unattached dependency a ``
|
|
405
|
-
|
|
406
|
-
marker = "no such table: "
|
|
407
|
-
if marker not in reason:
|
|
408
|
-
return None
|
|
409
|
-
table = reason.split(marker, 1)[1].strip()
|
|
410
|
-
alias, dot, _ = table.partition(".")
|
|
372
|
+
def _missing_dependency_alias(table: str | None, unattached: dict[str, str]) -> str | None:
|
|
373
|
+
"""The alias of an unattached dependency a missing ``alias.table`` names, else ``None``."""
|
|
374
|
+
alias, dot, _ = (table or "").partition(".")
|
|
411
375
|
if dot and alias in unattached:
|
|
412
376
|
return alias
|
|
413
377
|
return None
|
|
@@ -420,7 +384,7 @@ def _check_tasks(bundle: Path, verifiers: list[str]) -> list[dict[str, Any]]:
|
|
|
420
384
|
from .tools_world import load_tasks
|
|
421
385
|
|
|
422
386
|
manifest = _bundle.parse_manifest(bundle)
|
|
423
|
-
tasks = load_tasks(bundle, manifest, verifiers
|
|
387
|
+
tasks = load_tasks(bundle, manifest, verifiers)
|
|
424
388
|
out = []
|
|
425
389
|
for task in tasks.values():
|
|
426
390
|
unknown = sorted(set(task.selected(verifiers)) - set(verifiers))
|
|
@@ -475,9 +439,7 @@ def describe_dependencies(bundle: Path) -> list[dict[str, Any]]:
|
|
|
475
439
|
return out
|
|
476
440
|
|
|
477
441
|
|
|
478
|
-
|
|
479
|
-
#: runtime on the author's machine. The platform's bridge never sets it, so a
|
|
480
|
-
#: request that asks for execution there gets ``not_run`` and the reason.
|
|
442
|
+
# Only the CLI's bundled runtime sets this; the platform's bridge never runs the world's own Python.
|
|
481
443
|
EXECUTE_ENV = "GATEWAY_RUNTIME_EXECUTE"
|
|
482
444
|
|
|
483
445
|
|
|
@@ -485,14 +447,15 @@ def may_execute() -> bool:
|
|
|
485
447
|
return os.environ.get(EXECUTE_ENV) == "1"
|
|
486
448
|
|
|
487
449
|
|
|
488
|
-
def _handler_execution(bundle: Path, execute: bool, declared: set[str]) -> dict[str, Any]:
|
|
450
|
+
def _handler_execution(bundle: Path, execute: bool, declared: set[str], *, hosted: bool) -> dict[str, Any]:
|
|
489
451
|
"""Whether the handlers were run: imported, every declared tool bound, the
|
|
490
452
|
``[dependencies]`` opened from their paths — one session of the world,
|
|
491
|
-
opened and closed. Only where authored code may run
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
453
|
+
opened and closed. Only where authored code may run, and only over rows this
|
|
454
|
+
tree holds (``hosted``: its data is a snapshot the platform keeps). ``tools`` is
|
|
455
|
+
the declared handlers the session bound (the report's top-level ``tools``);
|
|
456
|
+
``served`` every name ``worlds call`` answers there — the handlers and a
|
|
457
|
+
dependency's ``alias.tool``; a connector route answers over HTTP, never by
|
|
458
|
+
name — so the two lists differ by design and say what each counts."""
|
|
496
459
|
if not execute:
|
|
497
460
|
return {
|
|
498
461
|
"status": "not_run",
|
|
@@ -505,6 +468,12 @@ def _handler_execution(bundle: Path, execute: bool, declared: set[str]) -> dict[
|
|
|
505
468
|
"reason": "this runtime does not run a world's Python (the platform's "
|
|
506
469
|
"bridge); check with the CLI's bundled runtime on your machine",
|
|
507
470
|
}
|
|
471
|
+
if hosted:
|
|
472
|
+
return {
|
|
473
|
+
"status": "not_run",
|
|
474
|
+
"reason": "this world's rows are the hosted snapshot db/snapshot.json pins, which "
|
|
475
|
+
"is not in this tree; `gateway worlds session open <slug>` runs the handlers over it",
|
|
476
|
+
}
|
|
508
477
|
from .local import open_world
|
|
509
478
|
|
|
510
479
|
with open_world(bundle, http=False) as session:
|
|
@@ -520,11 +489,10 @@ def _handler_execution(bundle: Path, execute: bool, declared: set[str]) -> dict[
|
|
|
520
489
|
|
|
521
490
|
|
|
522
491
|
def world_root(root: Path) -> Path:
|
|
523
|
-
"""The world inside the tree the platform holds (``WorldTree.world``).
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
commands operate on. A plain tree is its own root."""
|
|
492
|
+
"""The world inside the tree the platform holds (``WorldTree.world``). A
|
|
493
|
+
version stored as an api bundle is ``gateway-api-world.toml`` + ``seed/`` +
|
|
494
|
+
``scenarios/`` + ``server/world/<the authoring world>``: that nested world
|
|
495
|
+
is what data commands operate on. A plain tree is its own root."""
|
|
528
496
|
return WorldTree.from_dir(root).world
|
|
529
497
|
|
|
530
498
|
|
|
@@ -626,8 +594,7 @@ def _capture(request: dict) -> dict:
|
|
|
626
594
|
fail("input", "Expected the connector.toml text and an operation name")
|
|
627
595
|
if not isinstance(args, dict) or not all(isinstance(k, str) and isinstance(v, str) for k, v in args.items()):
|
|
628
596
|
fail("input", "args map names to strings")
|
|
629
|
-
#
|
|
630
|
-
# {name: value} form older callers send is accepted too.
|
|
597
|
+
# Pairs so a repeated key survives the wire; older callers still send a mapping.
|
|
631
598
|
try:
|
|
632
599
|
params = pairs_of(request.get("params"))
|
|
633
600
|
except ContractError:
|
|
@@ -691,7 +658,6 @@ def _template_summary(files: dict[str, bytes]) -> dict:
|
|
|
691
658
|
from .redaction import parse_env_policy
|
|
692
659
|
from .scaffold import template_digest
|
|
693
660
|
|
|
694
|
-
# A template keeps world.json at its root; an initialized world keeps it under schema/.
|
|
695
661
|
world_path = next((path for path in ("world.json", "schema/world.json") if path in files), None)
|
|
696
662
|
if world_path is None:
|
|
697
663
|
fail(
|
|
@@ -759,8 +725,6 @@ def _template_summary(files: dict[str, bytes]) -> dict:
|
|
|
759
725
|
|
|
760
726
|
|
|
761
727
|
COMPILED_MARKERS = ("schema/world.json", "tool-schemas.json")
|
|
762
|
-
# The compiled world's files a description is read from; the rest of a bundle
|
|
763
|
-
# (seed data, verifiers, tool sources) says nothing about the contract.
|
|
764
728
|
DESCRIBE_PATHS = (
|
|
765
729
|
"schema/world.json",
|
|
766
730
|
"tool-schemas.json",
|
|
@@ -781,13 +745,13 @@ def _describe(request: dict) -> dict:
|
|
|
781
745
|
straight through. Never runs the connector's Python."""
|
|
782
746
|
from .connector import load_spec, parse_spec
|
|
783
747
|
from .redaction import env_policy
|
|
784
|
-
from .ui import ui_kind
|
|
785
748
|
from .scaffold import (
|
|
786
749
|
TEMPLATES,
|
|
787
750
|
init_bundle,
|
|
788
751
|
init_bundle_from_files,
|
|
789
752
|
template_digest,
|
|
790
753
|
)
|
|
754
|
+
from .ui import ui_kind
|
|
791
755
|
|
|
792
756
|
connector = request.get("connector")
|
|
793
757
|
with tempfile.TemporaryDirectory(prefix="gateway-schema-") as directory:
|
|
@@ -841,8 +805,7 @@ def _describe(request: dict) -> dict:
|
|
|
841
805
|
try:
|
|
842
806
|
settings = load_api_settings(root, spec)
|
|
843
807
|
except ContractError:
|
|
844
|
-
# A template without its handlers still has a shape worth showing
|
|
845
|
-
# the routes render with the default action and status.
|
|
808
|
+
# A template without its handlers still has a shape worth showing.
|
|
846
809
|
settings = None
|
|
847
810
|
_annotate_redaction(summary["entities"], spec)
|
|
848
811
|
summary["connection"] = {
|
|
@@ -914,7 +877,7 @@ def _ingest_calls(request: dict) -> dict:
|
|
|
914
877
|
)
|
|
915
878
|
answer: dict = {"status": "ok", **report}
|
|
916
879
|
if report["changed"] and report.get("kind") == KIND_SCHEMA:
|
|
917
|
-
if snapshots.
|
|
880
|
+
if snapshots.has_default_snapshot(world):
|
|
918
881
|
from .compiler import build
|
|
919
882
|
from .snapshot import build_all
|
|
920
883
|
|
|
@@ -952,7 +915,7 @@ def _chunk_specs(workdir: Path, request: dict) -> list:
|
|
|
952
915
|
from .batch import ChunkSpec
|
|
953
916
|
|
|
954
917
|
listed = request.get("chunks")
|
|
955
|
-
if not isinstance(listed, list)
|
|
918
|
+
if not isinstance(listed, list):
|
|
956
919
|
fail("input", "Expected chunks as [{ordinal, path, entity?}]")
|
|
957
920
|
specs = []
|
|
958
921
|
seen = set()
|
|
@@ -1035,14 +998,16 @@ def _redactor(root: Path, request: dict):
|
|
|
1035
998
|
|
|
1036
999
|
|
|
1037
1000
|
def _snapshot_build(request: dict) -> dict:
|
|
1038
|
-
"""``snapshot-build``: the parent snapshot (or the tree's default)
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1001
|
+
"""``snapshot-build``: the parent snapshot (or the tree's default), carried to the
|
|
1002
|
+
tree's contract when that only adds to the domain its rows were stored under, with
|
|
1003
|
+
the chunks applied in dependency order, one transaction (atomic) or one per chunk;
|
|
1004
|
+
the new snapshot saved under workdir with its sidecar (its absolute path answered),
|
|
1005
|
+
or nothing on dryRun or an atomic refusal."""
|
|
1042
1006
|
from .batch import build_batch
|
|
1043
1007
|
from .compiler import check_bundle
|
|
1044
1008
|
from .data import MERGES, MODES
|
|
1045
|
-
from .
|
|
1009
|
+
from .domain_migration import DomainMigration
|
|
1010
|
+
from .snapshot import EMPTY_DIGEST, SIDECAR, build_default, default_snapshot, snapshot_name
|
|
1046
1011
|
|
|
1047
1012
|
workdir = _workdir(request)
|
|
1048
1013
|
mode = request.get("mode", "append")
|
|
@@ -1063,21 +1028,21 @@ def _snapshot_build(request: dict) -> dict:
|
|
|
1063
1028
|
contract = check_bundle(root)
|
|
1064
1029
|
redactor = _redactor(root, request)
|
|
1065
1030
|
chunks = _chunk_specs(workdir, request)
|
|
1066
|
-
# One directory per batch, so a parent built by an earlier call
|
|
1067
|
-
# workdir is never the file being written.
|
|
1031
|
+
# One directory per batch, so a parent built by an earlier call is never the file being written.
|
|
1068
1032
|
out_dir = workdir / "snapshot" / batch_id
|
|
1069
1033
|
out_dir.mkdir(parents=True, exist_ok=True)
|
|
1070
|
-
out = out_dir /
|
|
1034
|
+
out = out_dir / snapshot_name(contract)
|
|
1071
1035
|
out.unlink(missing_ok=True)
|
|
1072
|
-
out.with_name(
|
|
1036
|
+
out.with_name(SIDECAR).unlink(missing_ok=True)
|
|
1073
1037
|
if request.get("parentSnapshot") is not None:
|
|
1074
1038
|
parent = _under(workdir, request["parentSnapshot"], "parentSnapshot")
|
|
1075
1039
|
if not parent.is_file():
|
|
1076
1040
|
fail("input", "parentSnapshot is missing under workdir")
|
|
1077
|
-
|
|
1041
|
+
WorldDatabase.clone_file(parent, out)
|
|
1042
|
+
DomainMigration.carry(out, contract, root)
|
|
1078
1043
|
else:
|
|
1079
1044
|
build_default(root, contract)
|
|
1080
|
-
|
|
1045
|
+
WorldDatabase.clone_file(default_snapshot(root, contract), out)
|
|
1081
1046
|
result = build_batch(
|
|
1082
1047
|
contract,
|
|
1083
1048
|
out,
|
|
@@ -1091,7 +1056,6 @@ def _snapshot_build(request: dict) -> dict:
|
|
|
1091
1056
|
redactor=redactor,
|
|
1092
1057
|
)
|
|
1093
1058
|
if "snapshot" in result:
|
|
1094
|
-
# Absolute, under workdir: the caller opens it as it is.
|
|
1095
1059
|
result["snapshot"] = str(result["snapshot"])
|
|
1096
1060
|
return {"status": "ok", **result}
|
|
1097
1061
|
|
|
@@ -1100,20 +1064,20 @@ def _snapshot_default(request: dict) -> dict:
|
|
|
1100
1064
|
"""``snapshot-default``: the tree's default snapshot and every scenario snapshot,
|
|
1101
1065
|
built under ``workdir/tree``; the sidecars come back with absolute paths."""
|
|
1102
1066
|
from .compiler import check_bundle
|
|
1103
|
-
from .snapshot import build_all, default_snapshot, scenario_snapshot
|
|
1067
|
+
from .snapshot import build_all, build_default, default_snapshot, scenario_snapshot
|
|
1104
1068
|
|
|
1105
1069
|
workdir = _workdir(request)
|
|
1106
1070
|
root = _write_tree(workdir, request)
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1071
|
+
contract = check_bundle(root)
|
|
1072
|
+
build_default(root, contract)
|
|
1073
|
+
built = build_all(root, contract)
|
|
1110
1074
|
return {
|
|
1111
1075
|
"status": "ok",
|
|
1112
|
-
"snapshot": str(default_snapshot(root)),
|
|
1076
|
+
"snapshot": str(default_snapshot(root, contract)),
|
|
1113
1077
|
"sidecar": built["default"],
|
|
1114
1078
|
"sidecars": {"db/state.json": built["default"]},
|
|
1115
1079
|
"scenarios": {
|
|
1116
|
-
name: {"snapshot": str(scenario_snapshot(root, name)), "sidecar": sidecar}
|
|
1080
|
+
name: {"snapshot": str(scenario_snapshot(root, name, contract)), "sidecar": sidecar}
|
|
1117
1081
|
for name, sidecar in built["scenarios"].items()
|
|
1118
1082
|
},
|
|
1119
1083
|
}
|
|
@@ -1154,7 +1118,6 @@ def _ingest(request: dict) -> dict:
|
|
|
1154
1118
|
root.mkdir()
|
|
1155
1119
|
_write_files(root, request.get("files"))
|
|
1156
1120
|
if dry_run:
|
|
1157
|
-
# Every violation of every capture, grouped; no files come back since none changed.
|
|
1158
1121
|
return {"status": "ok", "result": check(world_root(root))}
|
|
1159
1122
|
result = ingest(world_root(root), batch_id=batch_id)
|
|
1160
1123
|
return {"status": "ok", "result": result, "files": _tree(root)}
|
|
@@ -1323,7 +1286,7 @@ def _dry_run(request: dict) -> dict:
|
|
|
1323
1286
|
task card (prompt, tools, verifiers), the state's rows per entity, and
|
|
1324
1287
|
``grade`` — or, when a verifier cannot run (bad SQL, a missing entity),
|
|
1325
1288
|
``grade: null`` and ``verifier_errors`` naming each verifier that failed
|
|
1326
|
-
with
|
|
1289
|
+
with the database engine's own words. That is the point of the dry run: a benchmark
|
|
1327
1290
|
whose grader dies is found here, not on the runner. Only where this
|
|
1328
1291
|
runtime may run a world's Python (:func:`may_execute`)."""
|
|
1329
1292
|
from ..errors import VerifierError
|
|
@@ -1364,7 +1327,7 @@ def _dry_run(request: dict) -> dict:
|
|
|
1364
1327
|
return answer
|
|
1365
1328
|
except (ContractError, VerifierError):
|
|
1366
1329
|
pass
|
|
1367
|
-
#
|
|
1330
|
+
# The grade runs the verifiers together, so run each alone to name the failing one.
|
|
1368
1331
|
errors: dict[str, str] = {}
|
|
1369
1332
|
for name in card["verifiers"]:
|
|
1370
1333
|
try:
|
|
@@ -1409,66 +1372,54 @@ def _templates(request: dict) -> dict:
|
|
|
1409
1372
|
return {"status": "ok", "templates": templates}
|
|
1410
1373
|
|
|
1411
1374
|
|
|
1375
|
+
def _answering_commands() -> dict:
|
|
1376
|
+
"""The commands that answer on their own, without the shared write-validate-return tree below."""
|
|
1377
|
+
return {
|
|
1378
|
+
"validate-rows": _validate_rows,
|
|
1379
|
+
"snapshot-build": _snapshot_build,
|
|
1380
|
+
"snapshot-default": _snapshot_default,
|
|
1381
|
+
"capture": _capture,
|
|
1382
|
+
"import-data": platform_import.import_data,
|
|
1383
|
+
"import-files": lambda request: platform_import.import_files(request, _world_for),
|
|
1384
|
+
"chunk-files": lambda request: platform_import.chunk_files(request, _world_for),
|
|
1385
|
+
"ingest": _ingest,
|
|
1386
|
+
"ingest-calls": _ingest_calls,
|
|
1387
|
+
"conform": _conform,
|
|
1388
|
+
"reconcile": _reconcile,
|
|
1389
|
+
"run-tests": _run_tests,
|
|
1390
|
+
"call": _call,
|
|
1391
|
+
"dry-run": _dry_run,
|
|
1392
|
+
"counts": lambda request: platform_query.counts(request, _world_for),
|
|
1393
|
+
"query": lambda request: platform_query.query(request, _world_for),
|
|
1394
|
+
"sql": lambda request: platform_query.sql(request, _world_for),
|
|
1395
|
+
"verify-legacy": lambda request: platform_query.verify_legacy(request, _world_for),
|
|
1396
|
+
"templates": _templates,
|
|
1397
|
+
"api-bundle": _api_bundle,
|
|
1398
|
+
"template-summary": lambda request: _template_summary(request_files(request)),
|
|
1399
|
+
"describe": _describe,
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
|
|
1412
1403
|
def execute(request: dict) -> dict:
|
|
1413
1404
|
if not isinstance(request, dict) or request.get("command") not in COMMANDS:
|
|
1414
1405
|
fail(
|
|
1415
1406
|
"command",
|
|
1416
1407
|
"Expected one of " + ", ".join(COMMANDS[:-1]) + " or " + COMMANDS[-1],
|
|
1417
1408
|
)
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
return _snapshot_build(request)
|
|
1422
|
-
if request["command"] == "snapshot-default":
|
|
1423
|
-
return _snapshot_default(request)
|
|
1424
|
-
if request["command"] == "capture":
|
|
1425
|
-
return _capture(request)
|
|
1426
|
-
if request["command"] == "import-data":
|
|
1427
|
-
return platform_import.import_data(request)
|
|
1428
|
-
if request["command"] == "import-files":
|
|
1429
|
-
return platform_import.import_files(request, _world_for)
|
|
1430
|
-
if request["command"] == "chunk-files":
|
|
1431
|
-
return platform_import.chunk_files(request, _world_for)
|
|
1432
|
-
if request["command"] == "ingest":
|
|
1433
|
-
return _ingest(request)
|
|
1434
|
-
if request["command"] == "ingest-calls":
|
|
1435
|
-
return _ingest_calls(request)
|
|
1436
|
-
if request["command"] == "conform":
|
|
1437
|
-
return _conform(request)
|
|
1438
|
-
if request["command"] == "reconcile":
|
|
1439
|
-
return _reconcile(request)
|
|
1440
|
-
if request["command"] == "run-tests":
|
|
1441
|
-
return _run_tests(request)
|
|
1442
|
-
if request["command"] == "call":
|
|
1443
|
-
return _call(request)
|
|
1444
|
-
if request["command"] == "dry-run":
|
|
1445
|
-
return _dry_run(request)
|
|
1446
|
-
if request["command"] == "counts":
|
|
1447
|
-
return platform_query.counts(request, _world_for)
|
|
1448
|
-
if request["command"] == "query":
|
|
1449
|
-
return platform_query.query(request, _world_for)
|
|
1450
|
-
if request["command"] == "templates":
|
|
1451
|
-
return _templates(request)
|
|
1452
|
-
if request["command"] == "api-bundle":
|
|
1453
|
-
return _api_bundle(request)
|
|
1454
|
-
if request["command"] == "template-summary":
|
|
1455
|
-
return _template_summary(request_files(request))
|
|
1456
|
-
if request["command"] == "describe":
|
|
1457
|
-
return _describe(request)
|
|
1409
|
+
handler = _answering_commands().get(request["command"])
|
|
1410
|
+
if handler is not None:
|
|
1411
|
+
return handler(request)
|
|
1458
1412
|
extra: dict = {}
|
|
1459
1413
|
with tempfile.TemporaryDirectory(prefix="gateway-schema-") as directory:
|
|
1460
1414
|
root = Path(directory) / "bundle"
|
|
1461
1415
|
root.mkdir()
|
|
1462
1416
|
if request["command"] == "validate-archive":
|
|
1463
1417
|
_write_files(root, _archive_files(request.get("archive")))
|
|
1464
|
-
# A stored version may be the api bundle of a schema world: the
|
|
1465
|
-
# world lives under server/world, and that is what gets validated.
|
|
1466
1418
|
root = world_root(root)
|
|
1467
1419
|
if bundle_mode(root) is None:
|
|
1468
1420
|
return {"status": "ok", "mode": "legacy"}
|
|
1469
1421
|
if request["command"] == "validate" and request.get("world") is not None:
|
|
1470
|
-
#
|
|
1471
|
-
# ``[dependencies]`` paths beside it resolve and its handlers may run.
|
|
1422
|
+
# Checked in place, so the ``[dependencies]`` paths beside it resolve.
|
|
1472
1423
|
root = _world_for(request, Path(directory))
|
|
1473
1424
|
elif request["command"] in (
|
|
1474
1425
|
"validate",
|
|
@@ -1477,13 +1428,10 @@ def execute(request: dict) -> dict:
|
|
|
1477
1428
|
"refresh-slack",
|
|
1478
1429
|
):
|
|
1479
1430
|
_write_files(root, request.get("files"))
|
|
1480
|
-
#
|
|
1481
|
-
# world itself sits under server/world and is what compiles, takes a
|
|
1482
|
-
# batch and validates. The whole tree still travels back.
|
|
1431
|
+
# A schema world's api bundle keeps the world under server/world; the whole tree still travels back.
|
|
1483
1432
|
world = world_root(root)
|
|
1484
1433
|
if request["command"] == "compile":
|
|
1485
|
-
#
|
|
1486
|
-
# handlers, journals); the trusted compiler owns every generated artifact.
|
|
1434
|
+
# The agent authors schema/world.json; the trusted compiler owns every generated artifact.
|
|
1487
1435
|
extra["compile"] = compile_world(world)
|
|
1488
1436
|
if world != root and (world / "data/initial.json").is_file():
|
|
1489
1437
|
from .api import write_base_seed
|
|
@@ -1511,8 +1459,7 @@ def execute(request: dict) -> dict:
|
|
|
1511
1459
|
with_example_tool=request.get("with_example_tool") is True,
|
|
1512
1460
|
)
|
|
1513
1461
|
if request["command"] == "init-template-files":
|
|
1514
|
-
#
|
|
1515
|
-
# the request chose, and the world is built exactly as from an installed one.
|
|
1462
|
+
# The template arrives as files, never as a path the request chose.
|
|
1516
1463
|
from .scaffold import init_bundle_from_files
|
|
1517
1464
|
|
|
1518
1465
|
connector = request.get("connector")
|
|
@@ -1558,11 +1505,16 @@ def main():
|
|
|
1558
1505
|
raw = sys.stdin.buffer.read(2 * MAX_BYTES + 1)
|
|
1559
1506
|
if len(raw) > 2 * MAX_BYTES:
|
|
1560
1507
|
fail("size", "Bridge request is too large")
|
|
1561
|
-
|
|
1508
|
+
request = json.loads(raw)
|
|
1509
|
+
platform_query.cap_memory_for(request)
|
|
1510
|
+
result = execute(request)
|
|
1562
1511
|
print(json.dumps(result, sort_keys=True))
|
|
1563
1512
|
except ContractError as error:
|
|
1564
1513
|
print(json.dumps({"status": "rejected", "error": error.detail}, sort_keys=True))
|
|
1565
1514
|
return 1
|
|
1515
|
+
except MemoryError:
|
|
1516
|
+
print(json.dumps({"status": "rejected", "error": {"code": "size", "message": "Out of memory"}}))
|
|
1517
|
+
return 1
|
|
1566
1518
|
except (OSError, ValueError, TypeError):
|
|
1567
1519
|
# Never dump request content or provider records in process diagnostics.
|
|
1568
1520
|
print(
|