@withgateway/sdk 0.6.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 +5019 -1599
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +5003 -1584
- 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 +371 -102
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +371 -102
- 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-LA-PMRJT.d.ts → index-DIN14Lhg.d.ts} +1 -1
- package/dist/{index-Di9nNqOY.d.mts → index-DuB-eQ0Z.d.mts} +1 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +2689 -401
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2650 -394
- 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/traces/index.d.mts +3 -1
- package/dist/traces/index.d.ts +3 -1
- package/dist/traces/index.js +371 -102
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +371 -102
- 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 +1983 -1745
- package/dist/worlds/index.d.ts +1983 -1745
- package/dist/worlds/index.js +1295 -226
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1290 -222
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +6 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +243 -0
- 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 +3 -4
- package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
- package/runtime/gatewaysdk/environment/schema/call_log.py +20 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +2 -2
- 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 +7 -2
- package/runtime/gatewaysdk/environment/schema/local.py +32 -7
- package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +23 -267
- 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 +43 -5
- package/runtime/gatewaysdk/environment/schema/scaffold.py +367 -217
- 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/SKILL.md +1 -2
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +7 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +32 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +6 -6
- 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 +28 -2
- 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 +7 -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/worker.py +5 -1
- package/runtime/gatewaysdk/environment/schema/workers.py +8 -1
- package/runtime/gatewaysdk/environment/schema/world_host.py +44 -15
- 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/SKILL.md +1 -2
- package/skills/connector-schema-authoring/connector-worlds.md +2 -2
- package/skills/connector-schema-authoring/world-schema.md +29 -23
- package/skills/world-data-ingestion/SKILL.md +4 -2
- package/skills/worlds-getting-started/SKILL.md +7 -7
- package/skills/worlds-getting-started/references/cli-mcp-map.md +32 -2
- package/skills/worlds-getting-started/references/gotchas.md +6 -6
- 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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""``schema/template.json``: the template a world was built from, the template's digest, the compiler outputs the
|
|
2
|
+
build produced, and the sha256 of every other file the built world holds. A reader trusts the digest only while the
|
|
3
|
+
world still holds exactly those files (twin: ``TemplateRecord`` in gateway/packages/shared/src/world/templateRecord.ts;
|
|
4
|
+
the outputs a record may name are pinned by conformance/template-record.json)."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
import json
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from pathlib import Path, PurePosixPath
|
|
12
|
+
from typing import Any, Mapping
|
|
13
|
+
|
|
14
|
+
from ..world import WorldTree
|
|
15
|
+
from .compiler import GENERATED, LOCK
|
|
16
|
+
from .snapshot import is_snapshot_output
|
|
17
|
+
from .ui import GENERATED_FILES, is_generated, read_ui_declaration
|
|
18
|
+
from .validation import fail, tree_path
|
|
19
|
+
|
|
20
|
+
RECORD = "schema/template.json"
|
|
21
|
+
COMPILED_OUTPUTS = (*GENERATED, LOCK)
|
|
22
|
+
_SHA256 = frozenset("0123456789abcdef")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def is_template_output(path: str) -> bool:
|
|
26
|
+
return path in COMPILED_OUTPUTS or PurePosixPath(path).name in GENERATED_FILES
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class TemplateRecord:
|
|
31
|
+
connector: str
|
|
32
|
+
digest: str
|
|
33
|
+
outputs: tuple[str, ...]
|
|
34
|
+
sources: Mapping[str, str]
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def of_world(cls, root: Path, *, connector: str, digest: str) -> "TemplateRecord":
|
|
38
|
+
outputs = tuple(sorted(_compiled_outputs(root)))
|
|
39
|
+
sources = {
|
|
40
|
+
path: hashlib.sha256((root / path).read_bytes()).hexdigest()
|
|
41
|
+
for path in WorldTree.from_dir(root).hashed_paths()
|
|
42
|
+
if _covered(path, outputs)
|
|
43
|
+
}
|
|
44
|
+
return cls(connector, digest, outputs, sources)
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def parse(cls, files: Mapping[str, bytes], location: str) -> "TemplateRecord":
|
|
48
|
+
where = f"{location}/{RECORD}"
|
|
49
|
+
try:
|
|
50
|
+
raw = json.loads(files[RECORD].decode("utf-8")) if RECORD in files else None
|
|
51
|
+
except (UnicodeDecodeError, ValueError):
|
|
52
|
+
raw = None
|
|
53
|
+
if not isinstance(raw, dict):
|
|
54
|
+
fail("template", f"The world carries no readable {RECORD}", where)
|
|
55
|
+
return cls(
|
|
56
|
+
_text(raw.get("connector"), "connector", where),
|
|
57
|
+
_sha256(raw.get("digest"), "digest", where),
|
|
58
|
+
_outputs(raw.get("outputs"), where),
|
|
59
|
+
_sources(raw.get("sources"), where),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def verify(self, files: Mapping[str, bytes], location: str) -> None:
|
|
63
|
+
"""Refuse a world that no longer holds, byte for byte, every file it was built with: an edit in place."""
|
|
64
|
+
held = {path for path in files if _covered(path, self.outputs)}
|
|
65
|
+
changed = sorted(
|
|
66
|
+
path
|
|
67
|
+
for path in held | set(self.sources)
|
|
68
|
+
if path not in held
|
|
69
|
+
or path not in self.sources
|
|
70
|
+
or hashlib.sha256(files[path]).hexdigest() != self.sources[path]
|
|
71
|
+
)
|
|
72
|
+
if changed:
|
|
73
|
+
fail(
|
|
74
|
+
"template",
|
|
75
|
+
f"The world no longer holds the files it was built with from its template ({', '.join(changed[:5])}); "
|
|
76
|
+
"rebuild it from its template",
|
|
77
|
+
location,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def write(self, root: Path) -> None:
|
|
81
|
+
document = {
|
|
82
|
+
"connector": self.connector,
|
|
83
|
+
"digest": self.digest,
|
|
84
|
+
"outputs": list(self.outputs),
|
|
85
|
+
"sources": dict(sorted(self.sources.items())),
|
|
86
|
+
}
|
|
87
|
+
(root / RECORD).write_bytes((json.dumps(document, indent=2) + "\n").encode("utf-8"))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _covered(path: str, outputs: tuple[str, ...]) -> bool:
|
|
91
|
+
return path != RECORD and path not in outputs and not is_snapshot_output(path)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _compiled_outputs(root: Path) -> list[str]:
|
|
95
|
+
outputs = [path for path in COMPILED_OUTPUTS if (root / path).is_file()]
|
|
96
|
+
ui = read_ui_declaration(root)
|
|
97
|
+
static = PurePosixPath(ui.static).as_posix() if ui is not None else None
|
|
98
|
+
if static is None or ui.generated is not True or not is_generated(root / static / "index.html"):
|
|
99
|
+
return outputs
|
|
100
|
+
return [*outputs, *(f"{static}/{name}" for name in GENERATED_FILES if (root / static / name).is_file())]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _text(value: Any, field: str, where: str) -> str:
|
|
104
|
+
if not isinstance(value, str) or not value:
|
|
105
|
+
fail("template", f"{RECORD} names no {field}", where)
|
|
106
|
+
return value
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _sha256(value: Any, field: str, where: str) -> str:
|
|
110
|
+
if not isinstance(value, str) or len(value) != 64 or not set(value) <= _SHA256:
|
|
111
|
+
fail("template", f"{RECORD} {field} is not a sha256 hex digest", where)
|
|
112
|
+
return value
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _outputs(value: Any, where: str) -> tuple[str, ...]:
|
|
116
|
+
if not isinstance(value, list) or not all(isinstance(path, str) for path in value):
|
|
117
|
+
fail("template", f"{RECORD} names no outputs list", where)
|
|
118
|
+
for path in value:
|
|
119
|
+
tree_path(path, where)
|
|
120
|
+
if not is_template_output(path):
|
|
121
|
+
fail("template", f"{RECORD} names {path} as an output; only compiler outputs are", where)
|
|
122
|
+
return tuple(value)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _sources(value: Any, where: str) -> dict[str, str]:
|
|
126
|
+
if not isinstance(value, dict) or not value:
|
|
127
|
+
fail("template", f"{RECORD} names no source files", where)
|
|
128
|
+
for path, digest in value.items():
|
|
129
|
+
tree_path(path, where)
|
|
130
|
+
_sha256(digest, f"source {path}", where)
|
|
131
|
+
return dict(value)
|
|
@@ -208,7 +208,7 @@ def _scenario_task(name: str, scenario: Path) -> ToolsTask:
|
|
|
208
208
|
table = tomllib.loads((scenario / "scenario.toml").read_text(encoding="utf-8"))
|
|
209
209
|
instruction = scenario / "instruction.md"
|
|
210
210
|
prompt = instruction.read_text(encoding="utf-8") if instruction.is_file() else str(table.get("instruction") or "")
|
|
211
|
-
verify = scenario /
|
|
211
|
+
verify = scenario / snapshots.SCENARIO_GRADERS / "verify.py"
|
|
212
212
|
return ToolsTask(
|
|
213
213
|
id=name,
|
|
214
214
|
prompt=prompt.strip() or f"Drive the world into the state the scenario '{name}' checks.",
|
|
@@ -262,8 +262,8 @@ def load_tasks(bundle: Path, manifest: _bundle.EnvManifest, verifiers: list[str]
|
|
|
262
262
|
def load_tools_version(
|
|
263
263
|
bundle: Path,
|
|
264
264
|
template: Path,
|
|
265
|
-
snapshot: dict[str, str] | None,
|
|
266
265
|
*,
|
|
266
|
+
fetched: bool,
|
|
267
267
|
run_handlers: bool,
|
|
268
268
|
) -> ToolsVersion:
|
|
269
269
|
if not is_tools_bundle(bundle):
|
|
@@ -278,15 +278,13 @@ def load_tools_version(
|
|
|
278
278
|
"`gateway worlds schema init` starts one that does",
|
|
279
279
|
)
|
|
280
280
|
contract = check_bundle(bundle)
|
|
281
|
-
if snapshot:
|
|
282
|
-
snapshots.fetch(bundle, contract, snapshot["url"], snapshot["sha256"], snapshot["digest"])
|
|
283
281
|
# connector.toml is read as the api runtime reads it, so an unservable route is refused at cache time.
|
|
284
282
|
spec = settings = None
|
|
285
283
|
if (bundle / SPEC).is_file():
|
|
286
284
|
spec = load_spec(bundle)
|
|
287
285
|
settings = load_api_settings(bundle, spec)
|
|
288
286
|
read_fields = RouteBindings.served(spec, settings, contract)
|
|
289
|
-
proven = ProvenTemplate.prove(bundle, template, contract, fetched=
|
|
287
|
+
proven = ProvenTemplate.prove(bundle, template, contract, fetched=fetched, read_fields=read_fields)
|
|
290
288
|
verifiers = verifier_names(bundle)
|
|
291
289
|
if REWARD in verifiers:
|
|
292
290
|
fail("host", f"verifier name '{REWARD}' is reserved for the scalar grade")
|
|
@@ -351,6 +349,7 @@ class ToolsWorld:
|
|
|
351
349
|
allowed: frozenset[str] | None = None,
|
|
352
350
|
dependencies: dict[str, DependencyWorld] | None = None,
|
|
353
351
|
calls: CallLog | None = None,
|
|
352
|
+
parameters: dict[str, str] | None = None,
|
|
354
353
|
) -> None:
|
|
355
354
|
if version.handlers is None:
|
|
356
355
|
fail("host", "a mock-tools session runs world-authored handlers; only a version worker opens one")
|
|
@@ -361,6 +360,7 @@ class ToolsWorld:
|
|
|
361
360
|
self.task = self._task_of(version, task)
|
|
362
361
|
self.allowed = allowed
|
|
363
362
|
self.calls = calls
|
|
363
|
+
self.parameters = dict(parameters or {})
|
|
364
364
|
self.dependencies = dict(dependencies or {})
|
|
365
365
|
self.served = served_with_dependencies(version, self.dependencies)
|
|
366
366
|
self._task_seed = seed
|
|
@@ -429,6 +429,8 @@ class ToolsWorld:
|
|
|
429
429
|
scenario_id = str(self.task.metadata.get("scenario_id") or self.task.id)
|
|
430
430
|
for world in (self.world, *self.worlds.values()):
|
|
431
431
|
world.set_task_context(scenario_id)
|
|
432
|
+
if self.parameters:
|
|
433
|
+
self.world.set_run_parameters(self.parameters)
|
|
432
434
|
self._attach()
|
|
433
435
|
|
|
434
436
|
def _attach(self) -> None:
|
|
@@ -40,6 +40,7 @@ STATIC_SOURCE = Path(__file__).with_name("ui_static")
|
|
|
40
40
|
#: overwrites an index.html only when it carries it.
|
|
41
41
|
GENERATED_MARK = "<!-- gateway-world-ui: generated -->"
|
|
42
42
|
DEFAULT_ENTRY = "/"
|
|
43
|
+
UI_RESERVED = "/__world-ui"
|
|
43
44
|
GENERATED_FILES = ("index.html", "app.js", "contract.json")
|
|
44
45
|
#: What ``ui init`` adds to a connector.toml that declares no ui.
|
|
45
46
|
UI_SECTION = """
|
|
@@ -54,6 +55,17 @@ generated = true
|
|
|
54
55
|
"""
|
|
55
56
|
|
|
56
57
|
|
|
58
|
+
def checked_api_path(api_path: Any) -> str:
|
|
59
|
+
"""``[ui] api_path`` as both readers of ``[ui]`` keep it: a same-origin prefix, never the
|
|
60
|
+
root and never under :data:`UI_RESERVED`."""
|
|
61
|
+
if not isinstance(api_path, str) or not api_path.startswith("/") or api_path == "/":
|
|
62
|
+
fail("spec", "ui.api_path is the same-origin prefix the ui calls the api at", "/ui/api_path")
|
|
63
|
+
kept = api_path.rstrip("/")
|
|
64
|
+
if kept == UI_RESERVED or kept.startswith(f"{UI_RESERVED}/"):
|
|
65
|
+
fail("spec", f"ui.api_path is under {UI_RESERVED}, the prefix the ui origin keeps for itself", "/ui/api_path")
|
|
66
|
+
return kept
|
|
67
|
+
|
|
68
|
+
|
|
57
69
|
@dataclass(frozen=True)
|
|
58
70
|
class UiDeclaration:
|
|
59
71
|
static: str
|
|
@@ -72,6 +84,44 @@ class UiDeclaration:
|
|
|
72
84
|
contract at compile time). What the connector pages badge and label."""
|
|
73
85
|
return "product" if self.generated is False else "generated"
|
|
74
86
|
|
|
87
|
+
@staticmethod
|
|
88
|
+
def kind_of(spec: bytes | None) -> str:
|
|
89
|
+
"""The ui a connector.toml's bytes declare, as the connector pages show it:
|
|
90
|
+
``product``, ``generated``, or ``none`` without the file or its ``[ui]``."""
|
|
91
|
+
declaration = UiDeclaration.parse(spec) if spec is not None else None
|
|
92
|
+
return declaration.kind if declaration is not None else "none"
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def parse(spec: bytes) -> UiDeclaration | None:
|
|
96
|
+
"""``[ui]`` of a connector.toml, or None when it declares none. Read
|
|
97
|
+
without the api runtime's index.html check, which is what compile is
|
|
98
|
+
about to satisfy."""
|
|
99
|
+
try:
|
|
100
|
+
raw = tomllib.loads(spec.decode("utf-8"))
|
|
101
|
+
except ValueError as error:
|
|
102
|
+
fail("spec", f"Cannot parse connector.toml: {error}", "/connector.toml")
|
|
103
|
+
ui = raw.get("ui")
|
|
104
|
+
if ui is None:
|
|
105
|
+
return None
|
|
106
|
+
if not isinstance(ui, dict):
|
|
107
|
+
fail("spec", "[ui] must be a table", "/ui")
|
|
108
|
+
# No default here: api.py (the runtime that answers `[ui] api_path` requests)
|
|
109
|
+
# fails hard on a missing `static`, so this reader agrees rather than quietly
|
|
110
|
+
# picking a directory the api side would never have looked in.
|
|
111
|
+
static = ui.get("static")
|
|
112
|
+
if not isinstance(static, str) or not static or static.startswith("/") or ".." in static.split("/"):
|
|
113
|
+
fail("spec", "ui.static is a directory inside the world holding the ui", "/ui/static")
|
|
114
|
+
entry = ui.get("entry", DEFAULT_ENTRY)
|
|
115
|
+
# `//host` and `/\host` are paths only in form: a browser resolves them to
|
|
116
|
+
# another origin, which would carry the session token off the ui's own.
|
|
117
|
+
if not isinstance(entry, str) or not entry.startswith("/") or entry.startswith("//") or "\\" in entry:
|
|
118
|
+
fail("spec", "ui.entry is the path the agent lands on, starting with / on the ui's own origin", "/ui/entry")
|
|
119
|
+
api_path = checked_api_path(ui.get("api_path", "/__world-api"))
|
|
120
|
+
generated = ui.get("generated")
|
|
121
|
+
if generated is not None and not isinstance(generated, bool):
|
|
122
|
+
fail("spec", "ui.generated is true (compile writes the ui) or false (hand-written)", "/ui/generated")
|
|
123
|
+
return UiDeclaration(static=static.rstrip("/"), entry=entry, api_path=api_path, generated=generated)
|
|
124
|
+
|
|
75
125
|
|
|
76
126
|
def ui_kind(world: Path) -> str:
|
|
77
127
|
"""The world's ui as the connector pages show it: ``product``,
|
|
@@ -82,38 +132,15 @@ def ui_kind(world: Path) -> str:
|
|
|
82
132
|
|
|
83
133
|
def read_ui_declaration(world: Path) -> UiDeclaration | None:
|
|
84
134
|
"""``[ui]`` of the world's connector.toml, or None when the world declares
|
|
85
|
-
none (no connector.toml, or no section).
|
|
86
|
-
runtime's index.html check, which is what compile is about to satisfy."""
|
|
135
|
+
none (no connector.toml, or no section)."""
|
|
87
136
|
path = world / "connector.toml"
|
|
88
137
|
if not path.is_file():
|
|
89
138
|
return None
|
|
90
139
|
try:
|
|
91
|
-
|
|
92
|
-
except
|
|
140
|
+
spec = path.read_bytes()
|
|
141
|
+
except OSError as error:
|
|
93
142
|
fail("spec", f"Cannot parse connector.toml: {error}", "/connector.toml")
|
|
94
|
-
|
|
95
|
-
if ui is None:
|
|
96
|
-
return None
|
|
97
|
-
if not isinstance(ui, dict):
|
|
98
|
-
fail("spec", "[ui] must be a table", "/ui")
|
|
99
|
-
# No default here: api.py (the runtime that answers `[ui] api_path` requests)
|
|
100
|
-
# fails hard on a missing `static`, so this reader agrees rather than quietly
|
|
101
|
-
# picking a directory the api side would never have looked in.
|
|
102
|
-
static = ui.get("static")
|
|
103
|
-
if not isinstance(static, str) or not static or static.startswith("/") or ".." in static.split("/"):
|
|
104
|
-
fail("spec", "ui.static is a directory inside the world holding the ui", "/ui/static")
|
|
105
|
-
entry = ui.get("entry", DEFAULT_ENTRY)
|
|
106
|
-
# `//host` and `/\host` are paths only in form: a browser resolves them to
|
|
107
|
-
# another origin, which would carry the session token off the ui's own.
|
|
108
|
-
if not isinstance(entry, str) or not entry.startswith("/") or entry.startswith("//") or "\\" in entry:
|
|
109
|
-
fail("spec", "ui.entry is the path the agent lands on, starting with / on the ui's own origin", "/ui/entry")
|
|
110
|
-
api_path = ui.get("api_path", "/__world-api")
|
|
111
|
-
if not isinstance(api_path, str) or not api_path.startswith("/") or api_path == "/":
|
|
112
|
-
fail("spec", "ui.api_path is the same-origin prefix the ui calls the api at", "/ui/api_path")
|
|
113
|
-
generated = ui.get("generated")
|
|
114
|
-
if generated is not None and not isinstance(generated, bool):
|
|
115
|
-
fail("spec", "ui.generated is true (compile writes the ui) or false (hand-written)", "/ui/generated")
|
|
116
|
-
return UiDeclaration(static=static.rstrip("/"), entry=entry, api_path=api_path.rstrip("/"), generated=generated)
|
|
143
|
+
return UiDeclaration.parse(spec)
|
|
117
144
|
|
|
118
145
|
|
|
119
146
|
def is_generated(index: Path) -> bool:
|
|
@@ -187,8 +214,6 @@ def init_ui(world: str | Path) -> dict:
|
|
|
187
214
|
if not declared:
|
|
188
215
|
text = spec_path.read_text(encoding="utf-8")
|
|
189
216
|
first_route = re.search(r"^\[\[operations\]\]", text, re.M)
|
|
190
|
-
# Before the first route so the section reads with the other tables,
|
|
191
|
-
# at the end when the file declares no routes yet.
|
|
192
217
|
text = (
|
|
193
218
|
text[: first_route.start()] + UI_SECTION.lstrip("\n") + "\n" + text[first_route.start() :]
|
|
194
219
|
if first_route
|
|
@@ -208,10 +233,6 @@ def init_ui(world: str | Path) -> dict:
|
|
|
208
233
|
}
|
|
209
234
|
|
|
210
235
|
|
|
211
|
-
# --------------------------------------------------------------------------- #
|
|
212
|
-
# contract.json: the world as the page renders it.
|
|
213
|
-
# --------------------------------------------------------------------------- #
|
|
214
|
-
|
|
215
236
|
VERBS = ("list", "get", "create", "update", "delete")
|
|
216
237
|
|
|
217
238
|
|