@withgateway/sdk 0.4.0 → 0.9.1
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 +573 -0
- package/dist/agents/index.d.ts +573 -0
- package/dist/agents/index.js +1443 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/index.mjs +1394 -0
- package/dist/agents/index.mjs.map +1 -0
- package/dist/apiError-DHpfbmdx.d.mts +17 -0
- package/dist/apiError-DHpfbmdx.d.ts +17 -0
- package/dist/cli.js +5655 -1890
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +5769 -2005
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +3 -1
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +418 -120
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +418 -120
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.js +346 -136
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +346 -136
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-DUHmS74p.d.ts → index-DIN14Lhg.d.ts} +27 -4
- package/dist/{index-mJhG3vZU.d.mts → index-DuB-eQ0Z.d.mts} +27 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +2862 -438
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2820 -431
- package/dist/index.mjs.map +1 -1
- package/dist/media-CQUC7TkS.d.mts +39 -0
- package/dist/media-DQnBloaX.d.ts +39 -0
- 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.d.mts +3 -1
- package/dist/traces/index.d.ts +3 -1
- package/dist/traces/index.js +418 -120
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +418 -120
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +3 -2
- package/dist/tracing/index.d.ts +3 -2
- package/dist/tracing/index.js +257 -16
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +257 -16
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/transport-CpRe7zgd.d.mts +123 -0
- package/dist/transport-CpRe7zgd.d.ts +123 -0
- package/dist/worlds/index.d.mts +2086 -1749
- package/dist/worlds/index.d.ts +2086 -1749
- package/dist/worlds/index.js +1471 -269
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1466 -265
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +6 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_world.py +24 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +243 -0
- package/runtime/gatewaysdk/environment/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/__main__.py +2 -2
- package/runtime/gatewaysdk/environment/schema/_slack_fidelity.py +8 -23
- package/runtime/gatewaysdk/environment/schema/api.py +27 -7
- package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +2 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +13 -1
- package/runtime/gatewaysdk/environment/schema/call_log.py +66 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +6 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +32 -8
- package/runtime/gatewaysdk/environment/schema/connector.py +5 -0
- 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 +9 -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/database/base.py +2 -2
- package/runtime/gatewaysdk/environment/schema/database/guard.py +2 -1
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +27 -1
- package/runtime/gatewaysdk/environment/schema/host.py +74 -11
- package/runtime/gatewaysdk/environment/schema/host_browser.py +48 -0
- package/runtime/gatewaysdk/environment/schema/host_control.py +33 -2
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +4 -1
- package/runtime/gatewaysdk/environment/schema/host_requests.py +14 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +13 -2
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +96 -19
- package/runtime/gatewaysdk/environment/schema/journal.py +10 -4
- package/runtime/gatewaysdk/environment/schema/local.py +33 -7
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +33 -480
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +332 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +4 -1
- package/runtime/gatewaysdk/environment/schema/run_parameters.py +25 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +49 -4
- package/runtime/gatewaysdk/environment/schema/scaffold.py +369 -218
- package/runtime/gatewaysdk/environment/schema/session_files.py +13 -2
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +20 -24
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/slack.py +55 -10
- package/runtime/gatewaysdk/environment/schema/snapshot.py +30 -4
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -2
- package/runtime/gatewaysdk/environment/schema/template_record.py +131 -0
- package/runtime/gatewaysdk/environment/schema/tools_world.py +26 -5
- package/runtime/gatewaysdk/environment/schema/ui.py +54 -33
- package/runtime/gatewaysdk/environment/schema/ui_interactions.py +419 -0
- package/runtime/gatewaysdk/environment/schema/ui_recorder.js +895 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay.py +366 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.LICENSE +25 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.js +109 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +10 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +6 -0
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +5 -1
- package/runtime/gatewaysdk/environment/schema/workers.py +8 -1
- package/runtime/gatewaysdk/environment/schema/world_host.py +64 -18
- package/runtime/gatewaysdk/environment/schema/world_tests.py +74 -0
- package/runtime/gatewaysdk/environment/secret_values.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +34 -43
- package/runtime/gatewaysdk/environment/world_session_contract.py +7 -34
- package/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +20 -24
- package/skills/connector-schema-authoring/connector-worlds.md +155 -13
- package/skills/connector-schema-authoring/world-schema.md +36 -29
- package/skills/world-data-ingestion/SKILL.md +11 -11
- package/skills/worlds-getting-started/SKILL.md +9 -9
- package/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/dist/media-BIApiPzS.d.mts +0 -102
- package/dist/media-BIApiPzS.d.ts +0 -102
|
@@ -7,8 +7,9 @@ The stdio protocol deliberately contains bundle bytes and mapping context only.
|
|
|
7
7
|
|
|
8
8
|
# file limit exception: the bridge's command dispatcher and its import/snapshot/
|
|
9
9
|
# check handlers share one request-validation vocabulary (_workdir, _under,
|
|
10
|
-
# _write_tree, fail); the read commands
|
|
11
|
-
# the next split is the import/snapshot
|
|
10
|
+
# _write_tree, fail); the read commands live in platform_query.py, the template
|
|
11
|
+
# commands in platform_templates.py, and the next split is the import/snapshot
|
|
12
|
+
# half. This file must not grow.
|
|
12
13
|
|
|
13
14
|
from __future__ import annotations
|
|
14
15
|
|
|
@@ -26,28 +27,25 @@ from typing import TYPE_CHECKING, Any
|
|
|
26
27
|
|
|
27
28
|
from .._materialize import materialize_template
|
|
28
29
|
from ..world import WorldTree
|
|
29
|
-
from . import
|
|
30
|
+
from . import (
|
|
31
|
+
ContractError,
|
|
32
|
+
WorldDatabase,
|
|
33
|
+
bundle_mode,
|
|
34
|
+
check_bundle,
|
|
35
|
+
platform_import,
|
|
36
|
+
platform_query,
|
|
37
|
+
platform_templates,
|
|
38
|
+
)
|
|
30
39
|
from . import snapshot as snapshots
|
|
31
|
-
from .cast import world_fields
|
|
32
40
|
from .compiler import CompilePlan, retarget_journals
|
|
33
41
|
from .handler_scan import HandlerScan
|
|
34
42
|
from .redaction import check_world_redaction
|
|
35
43
|
from .scaffold import request_files
|
|
36
|
-
from .validation import
|
|
37
|
-
digest,
|
|
38
|
-
encoded,
|
|
39
|
-
fail,
|
|
40
|
-
journal_paths,
|
|
41
|
-
members,
|
|
42
|
-
nonempty,
|
|
43
|
-
read_json,
|
|
44
|
-
)
|
|
44
|
+
from .validation import encoded, fail, tree_path
|
|
45
45
|
|
|
46
46
|
if TYPE_CHECKING:
|
|
47
47
|
from .compiler import Contract
|
|
48
|
-
from .connector import Spec
|
|
49
48
|
from .dependencies import FieldMap
|
|
50
|
-
from .redaction import RedactPolicy
|
|
51
49
|
|
|
52
50
|
MAX_BYTES = 64 * 1024 * 1024
|
|
53
51
|
MAX_FILES = 2000
|
|
@@ -56,11 +54,11 @@ COMMANDS = (
|
|
|
56
54
|
"validate-archive",
|
|
57
55
|
"init-template",
|
|
58
56
|
"init-template-files",
|
|
57
|
+
"init-world-files",
|
|
59
58
|
"init-openapi",
|
|
60
59
|
"template-summary",
|
|
61
60
|
"describe",
|
|
62
61
|
"compile",
|
|
63
|
-
"apply-batch",
|
|
64
62
|
"build-slack",
|
|
65
63
|
"refresh-slack",
|
|
66
64
|
"capture",
|
|
@@ -84,7 +82,6 @@ COMMANDS = (
|
|
|
84
82
|
"call",
|
|
85
83
|
"dry-run",
|
|
86
84
|
)
|
|
87
|
-
PLATFORM_MAPPING = {"id": "platform-agent", "version": "1"}
|
|
88
85
|
|
|
89
86
|
|
|
90
87
|
def compile_world(root: Path) -> dict:
|
|
@@ -131,78 +128,6 @@ def compile_world(root: Path) -> dict:
|
|
|
131
128
|
return {"added": added, "retargeted": retargeted}
|
|
132
129
|
|
|
133
130
|
|
|
134
|
-
def append_batch(root: Path, batch: dict, *, source: str | None = None) -> dict:
|
|
135
|
-
"""Validate then append one platform batch as an immutable refresh journal.
|
|
136
|
-
|
|
137
|
-
``target`` is filled from the compiled contract (a caller-supplied one must
|
|
138
|
-
match); ``mapping`` and ``coverage`` default to the platform mapping and
|
|
139
|
-
``partial``. Mutations without ``source`` take ``{"record": "<source>#<n>"}``
|
|
140
|
-
when a source prefix is given, otherwise provenance is required per mutation.
|
|
141
|
-
Replaying every prior journal first makes a repeated batch id idempotent and
|
|
142
|
-
a reused id with different content a conflict, exactly as in the store.
|
|
143
|
-
"""
|
|
144
|
-
snapshots.refuse_pinned_rows(root)
|
|
145
|
-
contract = check_bundle(root)
|
|
146
|
-
members(
|
|
147
|
-
batch,
|
|
148
|
-
{"id", "target", "mapping", "coverage", "mutations"},
|
|
149
|
-
{"id", "mutations"},
|
|
150
|
-
"/batch",
|
|
151
|
-
)
|
|
152
|
-
nonempty(batch["id"], "/batch/id")
|
|
153
|
-
if "target" in batch and not contract.targets(batch["target"]):
|
|
154
|
-
fail(
|
|
155
|
-
"batch_target",
|
|
156
|
-
"Batch targets a different domain identity/version/hash",
|
|
157
|
-
"/batch/target",
|
|
158
|
-
)
|
|
159
|
-
if not isinstance(batch["mutations"], list) or not batch["mutations"]:
|
|
160
|
-
fail("batch", "mutations must be a non-empty array", "/batch/mutations")
|
|
161
|
-
mutations = []
|
|
162
|
-
for index, mutation in enumerate(batch["mutations"]):
|
|
163
|
-
if not isinstance(mutation, dict):
|
|
164
|
-
fail("batch", "Each mutation must be an object", f"/batch/mutations/{index}")
|
|
165
|
-
if "source" not in mutation:
|
|
166
|
-
if source is None:
|
|
167
|
-
fail(
|
|
168
|
-
"provenance",
|
|
169
|
-
"Mutation has no source; pass a source prefix or a source.record per mutation",
|
|
170
|
-
f"/batch/mutations/{index}/source",
|
|
171
|
-
)
|
|
172
|
-
mutation = {**mutation, "source": {"record": f"{source}#{index}"}}
|
|
173
|
-
mutations.append(mutation)
|
|
174
|
-
resolved = {
|
|
175
|
-
"id": batch["id"],
|
|
176
|
-
"target": contract.target,
|
|
177
|
-
"mapping": batch.get("mapping", PLATFORM_MAPPING),
|
|
178
|
-
"coverage": batch.get("coverage", "partial"),
|
|
179
|
-
"mutations": mutations,
|
|
180
|
-
}
|
|
181
|
-
journals = journal_paths(root)
|
|
182
|
-
with (
|
|
183
|
-
tempfile.TemporaryDirectory(prefix="gateway-apply-batch-") as temporary,
|
|
184
|
-
WorldDatabase.create(Path(temporary) / "world.db", contract) as store,
|
|
185
|
-
):
|
|
186
|
-
for path in journals:
|
|
187
|
-
store.apply_batch(read_json(path))
|
|
188
|
-
result = store.apply_batch(resolved)
|
|
189
|
-
store.audit()
|
|
190
|
-
if result["status"] == "already_applied":
|
|
191
|
-
return result
|
|
192
|
-
batches = root / "data/batches"
|
|
193
|
-
batches.mkdir(exist_ok=True)
|
|
194
|
-
existing = len(journals) - 1
|
|
195
|
-
target = batches / f"{existing + 1:06d}-{digest(batch['id'].encode())[:16]}.json"
|
|
196
|
-
target.write_bytes(encoded(resolved))
|
|
197
|
-
if snapshots.has_default_snapshot(root):
|
|
198
|
-
# A snapshot built before this batch would be served over the grown journals.
|
|
199
|
-
from .compiler import build
|
|
200
|
-
from .snapshot import build_all
|
|
201
|
-
|
|
202
|
-
build_all(root, build(root))
|
|
203
|
-
return {**result, "journal": str(target.relative_to(root))}
|
|
204
|
-
|
|
205
|
-
|
|
206
131
|
def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
207
132
|
"""Check a schema world: the contract, the handlers by syntax and by name, the
|
|
208
133
|
initial state, every verifier over it, the tasks and the links. ``execute``
|
|
@@ -257,8 +182,6 @@ def validate_bundle(bundle: str | Path, *, execute: bool = False) -> dict:
|
|
|
257
182
|
|
|
258
183
|
|
|
259
184
|
def _check_mappings(bundle: Path, contract: Contract) -> None:
|
|
260
|
-
"""Each ``[dependencies.<alias>.entities]`` mapping against this contract
|
|
261
|
-
and, for a dependency whose ``path`` is here, against that contract too."""
|
|
262
185
|
from .. import _bundle
|
|
263
186
|
from .dependencies import check_mappings, parse_dependencies
|
|
264
187
|
|
|
@@ -278,12 +201,6 @@ def _field_map(contract: Contract) -> FieldMap:
|
|
|
278
201
|
|
|
279
202
|
|
|
280
203
|
def _attach_dependencies(bundle: Path, store: WorldDatabase, staging: Path) -> dict[str, str]:
|
|
281
|
-
"""Each ``[dependencies]`` entry whose local ``path`` is on this machine,
|
|
282
|
-
materialized beside the root's store and attached as ``<alias>.<table>``,
|
|
283
|
-
so a cross-world verifier runs here the way it runs in a session. Returns
|
|
284
|
-
the aliases left unattached, each with why: a pin without a path is the
|
|
285
|
-
platform's to resolve; a path that is not here (the platform checking a
|
|
286
|
-
pushed tree) resolves there too."""
|
|
287
204
|
from .. import _bundle
|
|
288
205
|
from .dependencies import parse_dependencies
|
|
289
206
|
|
|
@@ -310,13 +227,7 @@ def _attach_dependencies(bundle: Path, store: WorldDatabase, staging: Path) -> d
|
|
|
310
227
|
|
|
311
228
|
|
|
312
229
|
def _check_verifiers(bundle: Path, store: WorldDatabase, unattached: dict[str, str], *, scored: bool) -> dict[str, Any]:
|
|
313
|
-
"""
|
|
314
|
-
read-only authorizer, the way a session grades. A verifier that names a
|
|
315
|
-
table or column the contract lacks is refused here — at check — not at
|
|
316
|
-
the first grade. ``scored`` reports the score over the initial state by
|
|
317
|
-
the one :class:`SqlVerifier` rule a grade applies. A verifier that reads
|
|
318
|
-
a dependency the check could not attach (a pin without a local path) is
|
|
319
|
-
reported, not refused: it runs where the platform opens the link."""
|
|
230
|
+
"""A verifier over a dependency the check could not attach is reported, not refused: it runs on the platform."""
|
|
320
231
|
verifiers_dir = bundle / "verifiers"
|
|
321
232
|
if not verifiers_dir.is_dir():
|
|
322
233
|
return {}
|
|
@@ -350,8 +261,6 @@ def _check_verifier(path: Path, store: WorldDatabase, unattached: dict[str, str]
|
|
|
350
261
|
|
|
351
262
|
|
|
352
263
|
def _refuse_verifier(path: Path, store: WorldDatabase, unattached: dict[str, str], error: ContractError) -> str:
|
|
353
|
-
"""The unattached dependency alias the failure names — the one refusal
|
|
354
|
-
check reports rather than raises; every other failure is refused here."""
|
|
355
264
|
reason = error.__cause__ if error.__cause__ is not None else error.detail["message"]
|
|
356
265
|
missing = store.missing_table(reason)
|
|
357
266
|
alias = _missing_dependency_alias(missing, unattached)
|
|
@@ -370,7 +279,6 @@ def _refuse_verifier(path: Path, store: WorldDatabase, unattached: dict[str, str
|
|
|
370
279
|
|
|
371
280
|
|
|
372
281
|
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
282
|
alias, dot, _ = (table or "").partition(".")
|
|
375
283
|
if dot and alias in unattached:
|
|
376
284
|
return alias
|
|
@@ -378,8 +286,6 @@ def _missing_dependency_alias(table: str | None, unattached: dict[str, str]) ->
|
|
|
378
286
|
|
|
379
287
|
|
|
380
288
|
def _check_tasks(bundle: Path, verifiers: list[str]) -> list[dict[str, Any]]:
|
|
381
|
-
"""The tasks the world declares (``[[tasks]]``, ``tasks.jsonl``/``.json``,
|
|
382
|
-
else one per verifier), each checked to name verifiers the world has."""
|
|
383
289
|
from .. import _bundle
|
|
384
290
|
from .tools_world import load_tasks
|
|
385
291
|
|
|
@@ -448,14 +354,7 @@ def may_execute() -> bool:
|
|
|
448
354
|
|
|
449
355
|
|
|
450
356
|
def _handler_execution(bundle: Path, execute: bool, declared: set[str], *, hosted: bool) -> dict[str, Any]:
|
|
451
|
-
"""
|
|
452
|
-
``[dependencies]`` opened from their paths — one session of the world,
|
|
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."""
|
|
357
|
+
"""``tools`` counts bound declared handlers, ``served`` each name ``worlds call`` answers: they differ by design."""
|
|
459
358
|
if not execute:
|
|
460
359
|
return {
|
|
461
360
|
"status": "not_run",
|
|
@@ -505,11 +404,9 @@ def _write_files(root: Path, entries: list) -> None:
|
|
|
505
404
|
if not isinstance(entry, dict) or set(entry) != {"path", "content"}:
|
|
506
405
|
fail("input", "Expected path and base64 content")
|
|
507
406
|
name = entry["path"]
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if path.is_absolute() or any(p in ("", ".", "..") for p in name.split("/")) or name in seen:
|
|
512
|
-
fail("path", "Bundle paths must be unique relative file paths")
|
|
407
|
+
path = tree_path(name)
|
|
408
|
+
if name in seen:
|
|
409
|
+
fail("path", "Bundle paths must be unique")
|
|
513
410
|
seen.add(name)
|
|
514
411
|
try:
|
|
515
412
|
data = base64.b64decode(entry["content"], validate=True)
|
|
@@ -580,10 +477,7 @@ def _archive_files(encoded: str) -> list:
|
|
|
580
477
|
|
|
581
478
|
|
|
582
479
|
def _capture(request: dict) -> dict:
|
|
583
|
-
"""
|
|
584
|
-
egress the vendor allow-listed. The spec arrives as text, the credential as the
|
|
585
|
-
environment variable it names (set by the caller, never in the request), and every
|
|
586
|
-
recorded page comes back redacted the way the CLI would have written it."""
|
|
480
|
+
"""The credential is the env variable the spec names, never in the request; pages come back redacted."""
|
|
587
481
|
from .connector import CAPTURES, MANIFEST, capture, pairs_of, parse_spec
|
|
588
482
|
|
|
589
483
|
spec_text = request.get("spec")
|
|
@@ -623,233 +517,8 @@ def _capture(request: dict) -> dict:
|
|
|
623
517
|
}
|
|
624
518
|
|
|
625
519
|
|
|
626
|
-
def _redact_summary(spec: "Spec | RedactPolicy") -> dict:
|
|
627
|
-
"""The ``[redact]`` table as describe reports it, so a caller can compute a
|
|
628
|
-
stored form from these lists without running Python. ``slug`` is the SALT —
|
|
629
|
-
the connector's slug from connector.toml (``[environment].name`` for a tools-only
|
|
630
|
-
world's gateway-env.toml), which is what ``_digest`` hashes under — and not the
|
|
631
|
-
platform world slug, which may differ (``spycloud`` vs ``spycloud-world``); a caller
|
|
632
|
-
that salts with the wrong one never matches a row."""
|
|
633
|
-
return {
|
|
634
|
-
"slug": spec.slug,
|
|
635
|
-
"hash": sorted(spec.hash_fields),
|
|
636
|
-
"drop": sorted(spec.drop_fields),
|
|
637
|
-
"preserve": sorted(spec.preserve_fields),
|
|
638
|
-
"round": dict(spec.round_fields),
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
def _annotate_redaction(entities: list[dict], spec: "Spec | RedactPolicy | None") -> None:
|
|
643
|
-
"""Stamp every field with the policy it is stored under (``hash``, ``drop``,
|
|
644
|
-
``preserve``, ``round:<n>`` or None), so a reader knows whether it can be looked
|
|
645
|
-
up by plaintext, by digest, or not at all."""
|
|
646
|
-
from .connector import redaction_of
|
|
647
|
-
|
|
648
|
-
for entity in entities:
|
|
649
|
-
for field in entity["fields"]:
|
|
650
|
-
field["redaction"] = redaction_of(spec, field["name"]) if spec else None
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
def _template_summary(files: dict[str, bytes]) -> dict:
|
|
654
|
-
"""What a workspace connector is, read from its files: the vendor connection
|
|
655
|
-
(connector.toml) and the data model (world.json), plus the digest the platform
|
|
656
|
-
pins worlds to. Never runs the template's Python."""
|
|
657
|
-
from .connector import bind_spec, parse_spec
|
|
658
|
-
from .redaction import parse_env_policy
|
|
659
|
-
from .scaffold import template_digest
|
|
660
|
-
|
|
661
|
-
world_path = next((path for path in ("world.json", "schema/world.json") if path in files), None)
|
|
662
|
-
if world_path is None:
|
|
663
|
-
fail(
|
|
664
|
-
"template",
|
|
665
|
-
"No world.json (template) or schema/world.json (world) among the files",
|
|
666
|
-
)
|
|
667
|
-
try:
|
|
668
|
-
world = json.loads(files[world_path].decode("utf-8"))
|
|
669
|
-
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
670
|
-
fail("template", f"{world_path} is not valid JSON: {error}")
|
|
671
|
-
gateway = world.get("x-gateway") if isinstance(world, dict) else None
|
|
672
|
-
if not isinstance(gateway, dict):
|
|
673
|
-
fail("template", f"{world_path} is not a gateway-world document")
|
|
674
|
-
spec = bind_spec(parse_spec(files["connector.toml"].decode("utf-8")), world) if "connector.toml" in files else None
|
|
675
|
-
policy = spec
|
|
676
|
-
if policy is None and "gateway-env.toml" in files:
|
|
677
|
-
policy = parse_env_policy(files["gateway-env.toml"].decode("utf-8"))
|
|
678
|
-
entities = []
|
|
679
|
-
fields_by_entity = world_fields(world)
|
|
680
|
-
for name, entity in sorted((gateway.get("entities") or {}).items()):
|
|
681
|
-
entities.append(
|
|
682
|
-
{
|
|
683
|
-
"name": name,
|
|
684
|
-
"primaryKey": list(entity.get("primary_key") or []) if isinstance(entity, dict) else [],
|
|
685
|
-
"unique": list(entity.get("unique") or []) if isinstance(entity, dict) else [],
|
|
686
|
-
"relationships": list(entity.get("relationships") or []) if isinstance(entity, dict) else [],
|
|
687
|
-
"fields": [field.describe() for field in fields_by_entity.get(name, [])],
|
|
688
|
-
}
|
|
689
|
-
)
|
|
690
|
-
_annotate_redaction(entities, policy)
|
|
691
|
-
connection = None
|
|
692
|
-
if spec is not None:
|
|
693
|
-
connection = {
|
|
694
|
-
"slug": spec.slug,
|
|
695
|
-
"baseUrl": spec.base_url,
|
|
696
|
-
"auth": spec.scheme,
|
|
697
|
-
"redact": _redact_summary(spec),
|
|
698
|
-
"operations": [
|
|
699
|
-
{
|
|
700
|
-
"name": op.name,
|
|
701
|
-
"method": op.method,
|
|
702
|
-
"path": op.path,
|
|
703
|
-
"params": list(op.params),
|
|
704
|
-
"entity": op.entity,
|
|
705
|
-
"results": op.results,
|
|
706
|
-
}
|
|
707
|
-
for op in spec.operations.values()
|
|
708
|
-
],
|
|
709
|
-
}
|
|
710
|
-
package = gateway.get("package") or {}
|
|
711
|
-
return {
|
|
712
|
-
"status": "ok",
|
|
713
|
-
"summary": {
|
|
714
|
-
"packageVersion": package.get("version"),
|
|
715
|
-
"domainVersion": gateway.get("domain_version"),
|
|
716
|
-
"domainId": world.get("$id"),
|
|
717
|
-
"digest": template_digest(files),
|
|
718
|
-
"entities": entities,
|
|
719
|
-
"connection": connection,
|
|
720
|
-
"redact": _redact_summary(policy) if policy is not None else None,
|
|
721
|
-
"tools": sorted((gateway.get("tools") or {}).keys()),
|
|
722
|
-
"files": sorted(files),
|
|
723
|
-
},
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
COMPILED_MARKERS = ("schema/world.json", "tool-schemas.json")
|
|
728
|
-
DESCRIBE_PATHS = (
|
|
729
|
-
"schema/world.json",
|
|
730
|
-
"tool-schemas.json",
|
|
731
|
-
"connector.toml",
|
|
732
|
-
"gateway-env.toml",
|
|
733
|
-
"api/handlers.py",
|
|
734
|
-
)
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
def _describe(request: dict) -> dict:
|
|
738
|
-
"""One description for the connector page and a world's Schema tab: the data
|
|
739
|
-
model, the tools with their schemas, and — when the connector declares a vendor
|
|
740
|
-
connection — the OpenAPI document the served world answers to.
|
|
741
|
-
|
|
742
|
-
The connector is compiled exactly as a world build compiles it (an installed
|
|
743
|
-
template by slug, or a template's files), so the page shows what a world gets;
|
|
744
|
-
a compiled world's own files (``schema/world.json`` + ``tool-schemas.json``) pass
|
|
745
|
-
straight through. Never runs the connector's Python."""
|
|
746
|
-
from .connector import load_spec, parse_spec
|
|
747
|
-
from .redaction import env_policy
|
|
748
|
-
from .scaffold import (
|
|
749
|
-
TEMPLATES,
|
|
750
|
-
init_bundle,
|
|
751
|
-
init_bundle_from_files,
|
|
752
|
-
template_digest,
|
|
753
|
-
)
|
|
754
|
-
from .ui import ui_kind
|
|
755
|
-
|
|
756
|
-
connector = request.get("connector")
|
|
757
|
-
with tempfile.TemporaryDirectory(prefix="gateway-schema-") as directory:
|
|
758
|
-
root = Path(directory) / "bundle"
|
|
759
|
-
if connector is not None:
|
|
760
|
-
if not isinstance(connector, str):
|
|
761
|
-
fail("input", "Expected an installed connector template slug")
|
|
762
|
-
init_bundle(root, connector=connector)
|
|
763
|
-
template_dir = TEMPLATES / connector
|
|
764
|
-
authored = {
|
|
765
|
-
str(path.relative_to(template_dir)): path.read_bytes()
|
|
766
|
-
for path in sorted(template_dir.rglob("*"))
|
|
767
|
-
if path.is_file() and "__pycache__" not in path.parts
|
|
768
|
-
}
|
|
769
|
-
else:
|
|
770
|
-
authored = request_files(request)
|
|
771
|
-
if all(marker in authored for marker in COMPILED_MARKERS):
|
|
772
|
-
root.mkdir()
|
|
773
|
-
for path, data in authored.items():
|
|
774
|
-
if path in DESCRIBE_PATHS:
|
|
775
|
-
target = root / path
|
|
776
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
777
|
-
target.write_bytes(data)
|
|
778
|
-
else:
|
|
779
|
-
slug = request.get("slug") if isinstance(request.get("slug"), str) else None
|
|
780
|
-
if slug is None and "connector.toml" in authored:
|
|
781
|
-
slug = parse_spec(authored["connector.toml"].decode("utf-8")).slug
|
|
782
|
-
init_bundle_from_files(root, authored, connector=slug or "custom")
|
|
783
|
-
summary = _template_summary({"world.json": (root / "schema/world.json").read_bytes()})["summary"]
|
|
784
|
-
summary["digest"] = template_digest(authored)
|
|
785
|
-
summary["files"] = sorted(authored)
|
|
786
|
-
summary["ui"] = ui_kind(root)
|
|
787
|
-
tool_schemas = {}
|
|
788
|
-
if (root / "tool-schemas.json").is_file():
|
|
789
|
-
tool_schemas = json.loads((root / "tool-schemas.json").read_text(encoding="utf-8")).get("tools") or {}
|
|
790
|
-
summary["tools"] = [
|
|
791
|
-
{
|
|
792
|
-
"name": name,
|
|
793
|
-
"description": str(entry.get("description") or ""),
|
|
794
|
-
"inputSchema": entry.get("input_schema"),
|
|
795
|
-
"outputSchema": entry.get("output_schema"),
|
|
796
|
-
}
|
|
797
|
-
for name, entry in sorted(tool_schemas.items())
|
|
798
|
-
]
|
|
799
|
-
summary["connection"] = None
|
|
800
|
-
summary["openapi"] = None
|
|
801
|
-
if (root / "connector.toml").is_file():
|
|
802
|
-
from .api import load_api_settings, openapi_document
|
|
803
|
-
|
|
804
|
-
spec = load_spec(root)
|
|
805
|
-
try:
|
|
806
|
-
settings = load_api_settings(root, spec)
|
|
807
|
-
except ContractError:
|
|
808
|
-
# A template without its handlers still has a shape worth showing.
|
|
809
|
-
settings = None
|
|
810
|
-
_annotate_redaction(summary["entities"], spec)
|
|
811
|
-
summary["connection"] = {
|
|
812
|
-
"slug": spec.slug,
|
|
813
|
-
"baseUrl": spec.base_url,
|
|
814
|
-
"auth": spec.scheme,
|
|
815
|
-
"redact": _redact_summary(spec),
|
|
816
|
-
"operations": [
|
|
817
|
-
{
|
|
818
|
-
"name": op.name,
|
|
819
|
-
"method": op.method,
|
|
820
|
-
"path": op.path,
|
|
821
|
-
"params": list(op.params),
|
|
822
|
-
"entity": op.entity,
|
|
823
|
-
"results": op.results,
|
|
824
|
-
"action": settings.for_operation(op.name).action if settings else None,
|
|
825
|
-
"status": settings.for_operation(op.name).status if settings else None,
|
|
826
|
-
}
|
|
827
|
-
for op in spec.operations.values()
|
|
828
|
-
],
|
|
829
|
-
}
|
|
830
|
-
summary["openapi"] = openapi_document(spec, summary.get("domainId") or spec.slug, settings)
|
|
831
|
-
summary["redact"] = summary["connection"]["redact"]
|
|
832
|
-
else:
|
|
833
|
-
policy = env_policy(root / "gateway-env.toml")
|
|
834
|
-
_annotate_redaction(summary["entities"], policy)
|
|
835
|
-
summary["redact"] = _redact_summary(policy) if policy else None
|
|
836
|
-
summary["dependencies"] = describe_dependencies(root) if (root / "gateway-env.toml").is_file() else []
|
|
837
|
-
return {"status": "ok", "description": summary}
|
|
838
|
-
|
|
839
|
-
|
|
840
520
|
def _ingest_calls(request: dict) -> dict:
|
|
841
|
-
"""
|
|
842
|
-
of ``import-data`` for the record contract of :mod:`.ingest`. The tree arrives
|
|
843
|
-
as ``[{path, content}]``, the records as a list, with ``redact`` (off by
|
|
844
|
-
default), ``dry_run``, ``mode`` and optionally ``map`` — an ``ingest.toml``
|
|
845
|
-
text or its parsed table (:mod:`.mapping`). Without ``map`` the world's own
|
|
846
|
-
``ingest.toml`` applies when it has one, else each record's tool resolves to
|
|
847
|
-
an operation of ``connector.toml`` and its result is projected the way a
|
|
848
|
-
capture is (:func:`ingest.ingest_records`). Transforms never run here: they
|
|
849
|
-
are the agent's code and run where the agent is. The answer is the report
|
|
850
|
-
plus the projected ``rows`` (``{entity: [row, …]}``, so a caller can push
|
|
851
|
-
them through the batch lane itself) and, when the tree changed, every file
|
|
852
|
-
of the updated tree the way ``import-data`` returns one."""
|
|
521
|
+
"""Transforms never run here: they are the caller's code and run where the caller is."""
|
|
853
522
|
from .data import KIND_SCHEMA, MODES
|
|
854
523
|
from .ingest import ingest_records
|
|
855
524
|
from .redaction import parse_mode
|
|
@@ -892,7 +561,6 @@ def _ingest_calls(request: dict) -> dict:
|
|
|
892
561
|
|
|
893
562
|
|
|
894
563
|
def _workdir(request: dict) -> Path:
|
|
895
|
-
"""The absolute directory the caller prepared; every path in the request is under it."""
|
|
896
564
|
workdir = request.get("workdir")
|
|
897
565
|
if not isinstance(workdir, str) or not workdir or not Path(workdir).is_absolute() or not Path(workdir).is_dir():
|
|
898
566
|
fail(
|
|
@@ -940,8 +608,6 @@ def _chunk_specs(workdir: Path, request: dict) -> list:
|
|
|
940
608
|
|
|
941
609
|
|
|
942
610
|
def _tree(root: Path) -> list:
|
|
943
|
-
"""Every file under ``root`` as ``[{path, content}]``, the encoding ``init-template``
|
|
944
|
-
returns, so the platform commits a version without knowing which file changed."""
|
|
945
611
|
return [
|
|
946
612
|
{
|
|
947
613
|
"path": path.relative_to(root).as_posix(),
|
|
@@ -953,8 +619,7 @@ def _tree(root: Path) -> list:
|
|
|
953
619
|
|
|
954
620
|
|
|
955
621
|
def _write_tree(workdir: Path, request: dict) -> Path:
|
|
956
|
-
"""
|
|
957
|
-
contract alone is enough: generated artifacts are regenerated, snapshots are not)."""
|
|
622
|
+
"""Compiled from the contract alone: generated artifacts are regenerated, snapshots are not."""
|
|
958
623
|
from .compiler import compile_bundle
|
|
959
624
|
|
|
960
625
|
root = workdir / "tree"
|
|
@@ -975,8 +640,6 @@ def _flag(request: dict, name: str, default: bool) -> bool:
|
|
|
975
640
|
|
|
976
641
|
|
|
977
642
|
def _validate_rows(request: dict) -> dict:
|
|
978
|
-
"""``validate-rows``: shape-only validation of every row in the chunks (type, bounds,
|
|
979
|
-
required, unknown property, primary key present); no reference checks."""
|
|
980
643
|
from .batch import validate_chunks
|
|
981
644
|
from .compiler import check_bundle
|
|
982
645
|
from .data import MODES
|
|
@@ -990,7 +653,6 @@ def _validate_rows(request: dict) -> dict:
|
|
|
990
653
|
|
|
991
654
|
|
|
992
655
|
def _redactor(root: Path, request: dict):
|
|
993
|
-
"""The batch's redaction hook from ``request.redact`` (off | apply | refuse)."""
|
|
994
656
|
from .redaction import parse_mode, require_policy, row_redactor
|
|
995
657
|
|
|
996
658
|
redact = parse_mode(request.get("redact"))
|
|
@@ -998,11 +660,6 @@ def _redactor(root: Path, request: dict):
|
|
|
998
660
|
|
|
999
661
|
|
|
1000
662
|
def _snapshot_build(request: dict) -> dict:
|
|
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."""
|
|
1006
663
|
from .batch import build_batch
|
|
1007
664
|
from .compiler import check_bundle
|
|
1008
665
|
from .data import MERGES, MODES
|
|
@@ -1061,8 +718,6 @@ def _snapshot_build(request: dict) -> dict:
|
|
|
1061
718
|
|
|
1062
719
|
|
|
1063
720
|
def _snapshot_default(request: dict) -> dict:
|
|
1064
|
-
"""``snapshot-default``: the tree's default snapshot and every scenario snapshot,
|
|
1065
|
-
built under ``workdir/tree``; the sidecars come back with absolute paths."""
|
|
1066
721
|
from .compiler import check_bundle
|
|
1067
722
|
from .snapshot import build_all, build_default, default_snapshot, scenario_snapshot
|
|
1068
723
|
|
|
@@ -1084,8 +739,6 @@ def _snapshot_default(request: dict) -> dict:
|
|
|
1084
739
|
|
|
1085
740
|
|
|
1086
741
|
def _api_bundle(request: dict) -> dict:
|
|
1087
|
-
"""The api-kind bundle that hosts a world's API, built from the world's files:
|
|
1088
|
-
what `gateway worlds schema api-bundle` writes locally, for a CLI with no Python."""
|
|
1089
742
|
from .api import build_api_bundle
|
|
1090
743
|
|
|
1091
744
|
files = request_files(request)
|
|
@@ -1102,9 +755,7 @@ def _api_bundle(request: dict) -> dict:
|
|
|
1102
755
|
|
|
1103
756
|
|
|
1104
757
|
def _ingest(request: dict) -> dict:
|
|
1105
|
-
"""
|
|
1106
|
-
seeded from those captures through the contract exactly as the CLI does, and the
|
|
1107
|
-
whole updated tree handed back. Runs no Python of the world's own."""
|
|
758
|
+
"""Runs no Python of the world's own."""
|
|
1108
759
|
from .connector import check, ingest
|
|
1109
760
|
|
|
1110
761
|
batch_id = request.get("batch_id")
|
|
@@ -1124,9 +775,6 @@ def _ingest(request: dict) -> dict:
|
|
|
1124
775
|
|
|
1125
776
|
|
|
1126
777
|
def _reconcile(request: dict) -> dict:
|
|
1127
|
-
"""``reconcile``: the world's contract against its captured rows (see
|
|
1128
|
-
:mod:`reconcile`); the report of every change, and with ``write`` the updated
|
|
1129
|
-
tree (``schema/world.json`` rewritten and recompiled)."""
|
|
1130
778
|
from .reconcile import SOURCES, reconcile
|
|
1131
779
|
|
|
1132
780
|
source = request.get("from", "captures")
|
|
@@ -1148,9 +796,7 @@ def _reconcile(request: dict) -> dict:
|
|
|
1148
796
|
|
|
1149
797
|
|
|
1150
798
|
def _conform(request: dict) -> dict:
|
|
1151
|
-
"""``
|
|
1152
|
-
against the vendor's OpenAPI documents. The report is the one ``connector conform
|
|
1153
|
-
--out`` writes; ``world`` names the bundle, never the bridge's scratch path."""
|
|
799
|
+
"""``world`` names the bundle, never the bridge's scratch path."""
|
|
1154
800
|
from .conform import conform
|
|
1155
801
|
|
|
1156
802
|
documents = request.get("openapi")
|
|
@@ -1175,10 +821,6 @@ def _conform(request: dict) -> dict:
|
|
|
1175
821
|
|
|
1176
822
|
|
|
1177
823
|
def _run_tests(request: dict) -> dict:
|
|
1178
|
-
"""``run-tests``: serve the world at these files in the bridge and run the tests it
|
|
1179
|
-
ships under ``tests/`` (see :mod:`world_tests`). ``scenario`` starts the world in one
|
|
1180
|
-
of its scenarios; ``snapshot`` ({url, sha256, digest}) lays a pinned data snapshot
|
|
1181
|
-
into the tree first, so a data-only version is tested with its rows."""
|
|
1182
824
|
from .snapshot import fetch as fetch_snapshot
|
|
1183
825
|
from .world_tests import run
|
|
1184
826
|
|
|
@@ -1200,10 +842,7 @@ def _run_tests(request: dict) -> dict:
|
|
|
1200
842
|
|
|
1201
843
|
|
|
1202
844
|
def _prepared_tree(request: dict) -> Path:
|
|
1203
|
-
"""The
|
|
1204
|
-
relative path under it, beside any snapshot it checked out — opened in place.
|
|
1205
|
-
Every path is validated against the workdir (:func:`_under`); the workdir is
|
|
1206
|
-
the caller's to remove."""
|
|
845
|
+
"""The workdir is the caller's to remove; Python never deletes it."""
|
|
1207
846
|
if request.get("files") is not None or request.get("world") is not None:
|
|
1208
847
|
fail("input", "a request opens its world through one of workdir, files or world")
|
|
1209
848
|
workdir = _workdir(request)
|
|
@@ -1214,12 +853,6 @@ def _prepared_tree(request: dict) -> Path:
|
|
|
1214
853
|
|
|
1215
854
|
|
|
1216
855
|
def _world_for(request: dict, staging: Path) -> Path:
|
|
1217
|
-
"""The world a run-style command works on: ``files`` laid into ``staging``
|
|
1218
|
-
(what the platform sends for a small tree), the tree under a ``workdir`` the
|
|
1219
|
-
platform prepared (:func:`_prepared_tree`, for a large one), or — where this
|
|
1220
|
-
runtime may run authored code — ``world``, an absolute directory on this
|
|
1221
|
-
machine, opened in place so its ``[dependencies]`` paths resolve and nothing
|
|
1222
|
-
is copied."""
|
|
1223
856
|
if request.get("workdir") is not None:
|
|
1224
857
|
return _prepared_tree(request)
|
|
1225
858
|
if request.get("world") is None:
|
|
@@ -1231,7 +864,6 @@ def _world_for(request: dict, staging: Path) -> Path:
|
|
|
1231
864
|
|
|
1232
865
|
|
|
1233
866
|
def _local_tree(request: dict) -> Path:
|
|
1234
|
-
"""``world``, opened in place: an absolute directory on this machine, only where this runtime may run authored code."""
|
|
1235
867
|
world = request.get("world")
|
|
1236
868
|
if not may_execute():
|
|
1237
869
|
fail("input", "world is a local-runtime field; this runtime takes files")
|
|
@@ -1241,12 +873,6 @@ def _local_tree(request: dict) -> Path:
|
|
|
1241
873
|
|
|
1242
874
|
|
|
1243
875
|
def _call(request: dict) -> dict:
|
|
1244
|
-
"""``call``: open the world at ``world`` (a local directory; ``files`` for a
|
|
1245
|
-
tree without dependencies) as one session and call ``tool`` with ``args``,
|
|
1246
|
-
the way the host would — root tools by name, a dependency's as
|
|
1247
|
-
``alias.tool``. The answer is the tool's ``{status, body}``, the state
|
|
1248
|
-
afterwards when ``state`` is asked for, and the grade when ``grade`` is.
|
|
1249
|
-
Only where this runtime may run a world's Python (:func:`may_execute`)."""
|
|
1250
876
|
from .local import open_world
|
|
1251
877
|
|
|
1252
878
|
if not may_execute():
|
|
@@ -1285,15 +911,6 @@ def _call(request: dict) -> dict:
|
|
|
1285
911
|
|
|
1286
912
|
|
|
1287
913
|
def _dry_run(request: dict) -> dict:
|
|
1288
|
-
"""``dry-run``: open the world at ``world`` under ``task`` exactly as a
|
|
1289
|
-
hosted session would (the task's seed laid, its tools served), grade the
|
|
1290
|
-
UNTOUCHED state with the task's verifiers, and close. The answer is the
|
|
1291
|
-
task card (prompt, tools, verifiers), the state's rows per entity, and
|
|
1292
|
-
``grade`` — or, when a verifier cannot run (bad SQL, a missing entity),
|
|
1293
|
-
``grade: null`` and ``verifier_errors`` naming each verifier that failed
|
|
1294
|
-
with the database engine's own words. That is the point of the dry run: a benchmark
|
|
1295
|
-
whose grader dies is found here, not on the runner. Only where this
|
|
1296
|
-
runtime may run a world's Python (:func:`may_execute`)."""
|
|
1297
914
|
from ..errors import VerifierError
|
|
1298
915
|
from .local import open_world
|
|
1299
916
|
|
|
@@ -1350,35 +967,7 @@ def _dry_run(request: dict) -> dict:
|
|
|
1350
967
|
return answer
|
|
1351
968
|
|
|
1352
969
|
|
|
1353
|
-
def _templates(request: dict) -> dict:
|
|
1354
|
-
"""``templates``: every installed connector template, read from its ``world.json``
|
|
1355
|
-
(name and description when the document carries them) and whether it declares a
|
|
1356
|
-
vendor connection. Never runs a template's Python."""
|
|
1357
|
-
from .scaffold import TEMPLATES, list_templates
|
|
1358
|
-
from .ui import ui_kind
|
|
1359
|
-
|
|
1360
|
-
templates = []
|
|
1361
|
-
for slug in list_templates():
|
|
1362
|
-
world = json.loads((TEMPLATES / slug / "world.json").read_text(encoding="utf-8"))
|
|
1363
|
-
gateway = world.get("x-gateway") if isinstance(world, dict) else None
|
|
1364
|
-
if not isinstance(gateway, dict):
|
|
1365
|
-
fail("template", f"{slug}/world.json is not a gateway-world document")
|
|
1366
|
-
templates.append(
|
|
1367
|
-
{
|
|
1368
|
-
"slug": slug,
|
|
1369
|
-
"name": world.get("title") if isinstance(world.get("title"), str) else None,
|
|
1370
|
-
"description": world.get("description") if isinstance(world.get("description"), str) else None,
|
|
1371
|
-
"entities": sorted(gateway.get("entities") or {}),
|
|
1372
|
-
"tools": sorted(gateway.get("tools") or {}),
|
|
1373
|
-
"hasConnection": (TEMPLATES / slug / "connector.toml").is_file(),
|
|
1374
|
-
"ui": ui_kind(TEMPLATES / slug),
|
|
1375
|
-
}
|
|
1376
|
-
)
|
|
1377
|
-
return {"status": "ok", "templates": templates}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
970
|
def _answering_commands() -> dict:
|
|
1381
|
-
"""The commands that answer on their own, without the shared write-validate-return tree below."""
|
|
1382
971
|
return {
|
|
1383
972
|
"validate-rows": _validate_rows,
|
|
1384
973
|
"snapshot-build": _snapshot_build,
|
|
@@ -1398,10 +987,10 @@ def _answering_commands() -> dict:
|
|
|
1398
987
|
"query": lambda request: platform_query.query(request, _world_for),
|
|
1399
988
|
"sql": lambda request: platform_query.sql(request, _world_for),
|
|
1400
989
|
"verify-legacy": lambda request: platform_query.verify_legacy(request, _world_for),
|
|
1401
|
-
"templates":
|
|
990
|
+
"templates": platform_templates.templates,
|
|
1402
991
|
"api-bundle": _api_bundle,
|
|
1403
|
-
"template-summary": lambda request:
|
|
1404
|
-
"describe":
|
|
992
|
+
"template-summary": lambda request: platform_templates.template_summary(request_files(request)),
|
|
993
|
+
"describe": platform_templates.describe,
|
|
1405
994
|
}
|
|
1406
995
|
|
|
1407
996
|
|
|
@@ -1424,47 +1013,19 @@ def execute(request: dict) -> dict:
|
|
|
1424
1013
|
if in_place:
|
|
1425
1014
|
# In place, so the ``[dependencies]`` paths beside it resolve and its snapshots are compiled where they are.
|
|
1426
1015
|
root = _local_tree(request)
|
|
1427
|
-
elif request["command"] in ("validate", "compile", "
|
|
1016
|
+
elif request["command"] in ("validate", "compile", "refresh-slack"):
|
|
1428
1017
|
_write_files(root, request.get("files"))
|
|
1429
|
-
# A schema world's api bundle keeps the world under server/world; the whole tree still travels back.
|
|
1430
1018
|
world = world_root(root)
|
|
1431
1019
|
if request["command"] == "compile":
|
|
1432
|
-
# The
|
|
1020
|
+
# The caller authors schema/world.json; the trusted compiler owns every generated artifact.
|
|
1433
1021
|
extra["compile"] = compile_world(world)
|
|
1434
1022
|
if world != root and (world / "data/initial.json").is_file():
|
|
1435
1023
|
from .api import write_base_seed
|
|
1436
1024
|
|
|
1437
1025
|
write_base_seed(world, root)
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
fail(
|
|
1442
|
-
"input",
|
|
1443
|
-
"Expected a batch object and an optional source prefix string",
|
|
1444
|
-
)
|
|
1445
|
-
extra["batch"] = append_batch(world, batch, source=source)
|
|
1446
|
-
if request["command"] == "init-template":
|
|
1447
|
-
from .scaffold import init_bundle
|
|
1448
|
-
|
|
1449
|
-
connector = request.get("connector")
|
|
1450
|
-
name = request.get("name")
|
|
1451
|
-
if not isinstance(connector, str) or (name is not None and not isinstance(name, str)):
|
|
1452
|
-
fail("input", "Expected a connector template slug and an optional name")
|
|
1453
|
-
init_bundle(
|
|
1454
|
-
root,
|
|
1455
|
-
connector=connector,
|
|
1456
|
-
name=name,
|
|
1457
|
-
with_example_tool=request.get("with_example_tool") is True,
|
|
1458
|
-
)
|
|
1459
|
-
if request["command"] == "init-template-files":
|
|
1460
|
-
# The template arrives as files, never as a path the request chose.
|
|
1461
|
-
from .scaffold import init_bundle_from_files
|
|
1462
|
-
|
|
1463
|
-
connector = request.get("connector")
|
|
1464
|
-
name = request.get("name")
|
|
1465
|
-
if not isinstance(connector, str) or (name is not None and not isinstance(name, str)):
|
|
1466
|
-
fail("input", "Expected the connector slug and an optional name")
|
|
1467
|
-
init_bundle_from_files(root, request_files(request), connector=connector, name=name)
|
|
1026
|
+
writer = platform_templates.WRITERS.get(request["command"])
|
|
1027
|
+
if writer is not None:
|
|
1028
|
+
writer(request, root)
|
|
1468
1029
|
if request["command"] == "init-openapi":
|
|
1469
1030
|
from .openapi_import import OpenApiImport
|
|
1470
1031
|
|
|
@@ -1472,14 +1033,6 @@ def execute(request: dict) -> dict:
|
|
|
1472
1033
|
if not planned["written"]:
|
|
1473
1034
|
return planned
|
|
1474
1035
|
extra.update(planned)
|
|
1475
|
-
if request["command"] == "build-slack":
|
|
1476
|
-
from .slack import build_slack_bundle
|
|
1477
|
-
|
|
1478
|
-
build_slack_bundle(root, evidence=request.get("evidence"), name=request.get("name"))
|
|
1479
|
-
if request["command"] == "refresh-slack":
|
|
1480
|
-
from .slack import refresh_slack_bundle
|
|
1481
|
-
|
|
1482
|
-
refresh_slack_bundle(root, request.get("evidence"), batch_id=request.get("batch_id"))
|
|
1483
1036
|
report = {
|
|
1484
1037
|
**validate_bundle(world_root(root), execute=_flag(request, "execute", False)),
|
|
1485
1038
|
**extra,
|