@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
|
@@ -41,7 +41,7 @@ registration, a platform builder, live ingestion, tools, or a registry framework
|
|
|
41
41
|
## The rules that never bend
|
|
42
42
|
|
|
43
43
|
- **The schema is the deliverable.** A world with a faithful model and no tools is complete. Tools are added when wanted, by whoever wants them.
|
|
44
|
-
- **Every write goes through the schema.** Handlers use `gateway_env.store`; ingestion uses `store.apply_batch` or `store.ingest`; nothing else writes. Out-of-contract writes are rejected with the reason.
|
|
44
|
+
- **Every write goes through the schema.** Handlers use `gateway_env.store`; ingestion uses `store.apply_batch` or `store.ingest`; nothing else writes. Out-of-contract writes are rejected with the reason (one known gap: never name an ingest session's `TEMP` staging table after a world table; see `world-schema.md`, Raw ingestion).
|
|
45
45
|
- **Check the right boundary.** Compile/check validate compiled artifacts; materialization and store operations validate persisted data. Publication checks actual bundle bytes, handler declarations and initial state through the trusted runtime. Fidelity evidence and Environment Actions remain advisory.
|
|
46
46
|
- **Fidelity shape is decided by the vendor, not by a house rule.** A **base** connector is prebaked once (Slack). A **tenant-shaped** connector's model is mostly customer-defined, so describe at bind time is required (Salesforce, NetSuite, Workday). A **mixed** connector is a base plus an optional overlay (Okta, Entra, Google, LDAP, Jamf).
|
|
47
47
|
- **Surface parity is advisory.** If the world declares it mirrors an MCP surface, produce the parity report and show it. Never block on it, never shrink or bend the model to satisfy it.
|
|
@@ -55,7 +55,7 @@ registration, a platform builder, live ingestion, tools, or a registry framework
|
|
|
55
55
|
| Command or path | Status |
|
|
56
56
|
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
57
57
|
| `gateway worlds schema init PATH --connector <slug> [--name NAME] [--with-example-tool]` | exists (#219); `--connector custom` is the blank starting point for an arbitrary connector: its `$id` is derived from `--name` (`urn:gateway:connector:<name>`), it ships the `records` entity and a starter verifier but no tools unless `--with-example-tool` asks for the `list_records`/`get_record`/`create_record` example, and it writes no `data/records.json` (Brex retrospective, 2026-09-14) |
|
|
58
|
-
| `gateway worlds schema init PATH --from-openapi SOURCE [--plan-only] [--include GLOB\|TAG]… [--exclude GLOB\|TAG]…` | exists (2026-09-22); imports a Swagger 2.0 / OpenAPI 3.x document (JSON or YAML; a local path, `drive:<path>` read platform-side, or an http(s) URL) into `schema/world.json` + `connector.toml` + `schema/provenance.json`:
|
|
58
|
+
| `gateway worlds schema init PATH --from-openapi SOURCE [--plan-only] [--include GLOB\|TAG]… [--exclude GLOB\|TAG]…` | exists (2026-09-22); imports a Swagger 2.0 / OpenAPI 3.x document (JSON or YAML; a local path, `drive:<path>` read platform-side, or an http(s) URL) into `schema/world.json` + `connector.toml` + `schema/provenance.json`: the item schemas the selected operations' responses carry, read through the vendor's envelope, become entities (never the wrappers; keyed by a declared id, else the field the read route looks a row up by, nested as a JSON Pointer when it sits inside the row), every path+method a route that answers in the vendor's envelope (`envelope = "message.items"` + `wrapper`) and pages as the document says (passthrough when the response is not an entity), the plan is printed first and `--plan-only` writes nothing; a YAML document needs PyYAML in the Python that runs the runtime and is refused naming the fix without it; refusals (no `paths`, unknown `$ref`, cyclic entity root, undeclared path parameter) carry a JSON pointer. Rules: `worlds-getting-started` → `references/openapi-import.md` |
|
|
59
59
|
| `gateway worlds connector validate\|capture\|ingest PATH` | exists; a `connector.toml` in the world describes base URL, auth scheme, pacing, redaction and operations; `capture` records paced, redacted pages (errors included) under `captures/` with the secret never written; `ingest` seeds `data/initial.json` through the contract in a scratch copy first; `ingest --dry-run [--report refusals.jsonl]` lists every violation of every capture (the `data import --report` records plus `capture`), exit 2, nothing written |
|
|
60
60
|
| `gateway worlds schema reconcile PATH --from captures [--write]` | exists (runtime, offline CLI and `gateway worlds schema reconcile`); the contract against the captured rows: relaxes `required` for fields absent in captures, adds undocumented keys as optional properties typed from the values, drops formats the captured values fail; a report of every change, `schema/world.json` rewritten and recompiled only with `--write` |
|
|
61
61
|
| `gateway worlds connector conform PATH --openapi vendor.yaml` | exists; serves the world in-process, calls every declared operation with arguments from its own seed, and checks status + body against the vendor's OpenAPI response schemas; non-zero exit on any mismatch. Run it before calling a world 1:1; its FAIL list is the work list (unseeded entities → 404s, creates the contract rejects → 4xx, honest 501s). Reads OpenAPI 3.0 `nullable`, reference cycles and `discriminator` unions; `[operations.api] sample_headers` / `sample_body` shape a request the route demands (`Idempotency-Key`, a body) |
|
|
@@ -104,9 +104,9 @@ deliverable can finish with synthetic fixtures and explicitly skipped live valid
|
|
|
104
104
|
- [ ] Author `schema/world.json` and reusable sibling definitions from pinned vendor sources, following the type-mapping notes in [CONNECTORS.md](CONNECTORS.md). `gateway worlds schema entity add` declares an entity with its key, uniques and relationships in one command so the declaration shape is never wrong; hand-author only the payload definitions (`--schema` or `$defs`). Record source URLs, versions/retrieval dates, and hashes of the actual retrieved bytes in `schema/provenance.json`.
|
|
105
105
|
- [ ] Entities have the vendor's keys, relationships, enums, and nullability, and follow [CONVENTIONS.md](CONVENTIONS.md): one reserved prefix per template, plural snake_case names, vendor casing on fields, shared `base.json` primitives. Reserved prefixes and the `payload` name are avoided.
|
|
106
106
|
- [ ] Enforce supported required fields, types, enums, key uniqueness, and reference integrity. Document vendor rules the dialect cannot express, normalization choices, and constraints the future mapper must enforce; structural validation is not vendor behavior.
|
|
107
|
-
- [ ] Real vendor documents compile as they come (Brex retrospective, 2026-09-14): `format: int64`/`double` on numbers is ignored, not refused (string formats are still validated); a schema-valued `additionalProperties` types a map (`Record<string, string>`); a type nested in itself (`ExpandableExpense` holding an `ExpandableExpense`) compiles, with the nested occurrence validated as its bare type and stored as JSON, never projected to a column. A nested key or relationship field is a JSON Pointer, `/owner/user_id`, never `owner.user_id`; the compiler's refusal says so.
|
|
108
|
-
- [ ] Every property verifier SQL will name has a column: scalars and compositions whose non-null branches are scalar (`anyOf [{$ref Status}, {type: null}]`, the nullable-enum shape) project; a composition that may hold an object or array stays JSON-only. A verifier that names a column the contract never projected fails the grade with
|
|
109
|
-
- [ ] `gateway worlds schema compile PATH` then `check PATH` pass. Never edit generated files; SDK templates contain authored inputs and generate bundle artifacts at `init` time. Changing the root `$id` after `init` is fine: `compile` re-stamps an empty `data/initial.json` onto the new domain; a journal that holds rows is refused with the fix named (re-import its rows, or restore the schema it was written against).
|
|
107
|
+
- [ ] Real vendor documents compile as they come (Brex retrospective, 2026-09-14): `format: int64`/`double` on numbers is ignored, not refused (string formats are still validated); a schema-valued `additionalProperties` types a map (`Record<string, string>`); a type nested in itself (`ExpandableExpense` holding an `ExpandableExpense`) compiles, with the nested occurrence validated as its bare type and stored as JSON, never projected to a column. A contract whose inlined files would pass the 4 MB publication cap (Google Docs' recursive body) compiles each object/array definition once under `$defs` and references it instead; nothing to do in the template. A nested key or relationship field is a JSON Pointer, `/owner/user_id`, never `owner.user_id`; the compiler's refusal says so. A primary key may be nested too (`/protocolSection/identificationModule/nctId`) when every object on its path is required and non-null; lookups (`get`, `update`, `delete`) then pass it flat under the pointer itself. Field names keep the vendor's hyphens (`reference-count`); dots and slashes never belong to a name. A verifier's SQL double-quotes such a column (`"reference-count"`): unquoted, SQLite reads a subtraction.
|
|
108
|
+
- [ ] Every property verifier SQL will name has a column: scalars and compositions whose non-null branches are scalar (`anyOf [{$ref Status}, {type: null}]`, the nullable-enum shape) project; a composition that may hold an object or array stays JSON-only. A verifier that names a column the contract never projected fails the grade with the database engine's message and the statement; it never scores 0 quietly (double-quoted unknown names no longer fall back to string literals).
|
|
109
|
+
- [ ] `gateway worlds schema compile PATH` then `check PATH` pass. Never edit generated files; SDK templates contain authored inputs and generate bundle artifacts at `init` time. Changing the root `$id` after `init` is fine: `compile` re-stamps an empty `data/initial.json` onto the new domain; a journal that holds rows follows a change that only adds to its domain (a new entity, a new field that is not required) and is refused otherwise, with the fix named (re-import its rows, or restore the schema it was written against).
|
|
110
110
|
- [ ] Shared templates and committed fixtures hold synthetic data only. Tenant captures stay in their owning project; initial batches and refresh journals retain explicit capture/synthetic provenance.
|
|
111
111
|
|
|
112
112
|
### 2. Tenant overlay (required for tenant-shaped, optional for mixed, absent for base)
|
|
@@ -133,7 +133,8 @@ deliverable can finish with synthetic fixtures and explicitly skipped live valid
|
|
|
133
133
|
### 5. Tools (only if the world ships tools)
|
|
134
134
|
|
|
135
135
|
- [ ] Every tool in `x-gateway.tools` has exactly one handler in `tools/*.py` (the loader refuses a mismatch); generated defaults are fine.
|
|
136
|
-
- [ ]
|
|
136
|
+
- [ ] Routes are never tools. A call by a route's name is refused (`not_a_tool`, naming the session's api URL), and a task's `tools` lists declared tools only. A tool may share an operation's name: a call by that name runs the tool, and the route answers only over HTTP at its path.
|
|
137
|
+
- [ ] Handler reads use `gateway_env.store.get` / `list`; writes use `insert` / `update` / `delete`. Read-only SQL uses `gateway_env.db.one/all`; raw SQL writes are denied. The host's `WorldDatabase.query` is not exposed by the handler store proxy.
|
|
137
138
|
- [ ] Handlers never read `benchmark_runtime_context` or `benchmark_conversation_events`.
|
|
138
139
|
- [ ] A user attaching custom tools to this world needs nothing from this checklist beyond the store API; document any conventions the model expects (key formats, enum values).
|
|
139
140
|
|
|
@@ -143,7 +144,9 @@ Tool handlers (`tools/*.py`) reach the world's rows through `from gateway_env im
|
|
|
143
144
|
exactly these methods; `gateway worlds schema check .` refuses any other `store.<name>` at file:line
|
|
144
145
|
with this list, and a hosted call into such a handler answers 400 `{error: "handler", detail, handler}`
|
|
145
146
|
(an `AttributeError`/`TypeError`/`NameError` is the author's bug; anything else a handler raises is a
|
|
146
|
-
500 `{error: "engine", detail, handler}`; never a bare exception string).
|
|
147
|
+
500 `{error: "engine", detail, handler}`; never a bare exception string). A route's handler answers the
|
|
148
|
+
same way on every door, and an answer JSON cannot carry (a `datetime`, a set, NaN) is its 400; a route
|
|
149
|
+
answering bytes names its `Content-Type` (a vendor's `404 text/plain`), and the bytes go out as sent.
|
|
147
150
|
|
|
148
151
|
- `get(entity: str, key: dict) -> dict | None` — one row by primary key, or `None`.
|
|
149
152
|
- `list(entity: str) -> list[dict]` — every row, ordered by key.
|
|
@@ -235,7 +238,7 @@ Full procedure: `.llm_artifacts/plans/connector-implementation-orchestration.md`
|
|
|
235
238
|
- Treating descriptive resources as schema authority. `init` preserves flat supporting `.json`, `.md` and `.toml` files; only referenced schemas become compiler inputs. Slack capability defaults expand into self-contained entries; see [world-schema.md](../../../documentation/features/world-schema.md#connector-templates-and-init).
|
|
236
239
|
- Converting Slack message timestamps to floats or RFC3339. Preserve exact `(workspace_id, channel_id, ts)` keys; see the [Slack model guide](../../../gatewaysdk/sdk/src/gatewaysdk/environment/schema/connectors/slack/MODEL.md) for normalization and limits.
|
|
237
240
|
- Writing a nested field as `owner.user_id` in `unique` or `relationships`. Nested paths are JSON Pointers: `/owner/user_id`.
|
|
238
|
-
- Reading a verifier's 0 as "the agent failed". If the SQL names a column that does not exist the grade is now an error carrying
|
|
241
|
+
- Reading a verifier's 0 as "the agent failed". If the SQL names a column that does not exist the grade is now an error carrying the database engine's message; an older world that still scores 0 on every task has verifier SQL naming an unprojected property — recompile, the nullable-enum shape projects now.
|
|
239
242
|
|
|
240
243
|
## Where this skill is discoverable
|
|
241
244
|
|
|
@@ -389,7 +392,10 @@ them:
|
|
|
389
392
|
- `[api] envelope = "results"` wraps rows as `{"results": [...], "hits": N, "cursor": ""}`
|
|
390
393
|
(empty means a bare array); `hits_key = ""` leaves the count out and
|
|
391
394
|
`cursor_absent_when_done = true` (world-wide, or per route under `[operations.api]`)
|
|
392
|
-
leaves the cursor key out of the last page — Brex's `{items, next_cursor?}`.
|
|
395
|
+
leaves the cursor key out of the last page — Brex's `{items, next_cursor?}`. A dotted
|
|
396
|
+
`envelope = "message.items"` nests the page (`{message: {items, total-results, next-cursor}}`),
|
|
397
|
+
and `[operations.api] wrapper = '{"status": "ok", "message-type": "work-list"}'` lays it onto
|
|
398
|
+
the rest of the vendor's envelope; a single row is wrapped only by its route's own `envelope`.
|
|
393
399
|
- `unauthorized` / `not_found` / `invalid` are JSON strings replayed on 401 / 404 / 400, so
|
|
394
400
|
the vendor's own error bodies come back; `""` (or `'null'`) means no body at all. A route
|
|
395
401
|
whose missing row the vendor answers its own way sets `not_found` and `not_found_status`
|
|
@@ -405,8 +411,10 @@ them:
|
|
|
405
411
|
credential for it, the way it does for a bearer of the session token.
|
|
406
412
|
|
|
407
413
|
`gateway worlds serve PATH --port 8080 [--api-key K]` runs it locally; the runner's admin
|
|
408
|
-
endpoints (`/
|
|
409
|
-
|
|
414
|
+
endpoints (`/__world/seed`, `/__world/reset`, `/__world/state`) sit beside the vendor routes
|
|
415
|
+
and answer only the run's `X-World-Admin-Token` (`gateway worlds test` hands a world's pytest
|
|
416
|
+
files theirs as `WORLD_ADMIN_TOKEN`; by hand, use `/__session/*`); `/healthz` answers everyone,
|
|
417
|
+
and a World Host session's doors answer none of the others. `gateway bench push PATH` publishes the world: for a world carrying
|
|
410
418
|
`connector.toml` it packages the api-kind bundle the platform hosts on the way (root
|
|
411
419
|
legacy-shaped on purpose, since the api runner refuses a schema bundle there; `server/`
|
|
412
420
|
needs nothing installed). Open a session with `--surface api` and hand the client that
|
|
@@ -81,14 +81,23 @@ gateway worlds session open spycloud-world -t default --surface api # prints a
|
|
|
81
81
|
A hosted api session runs on a fresh Fargate pod. The first open of a version takes about
|
|
82
82
|
fifteen minutes (pod scheduling plus pulling the runner sidecar), during which the session
|
|
83
83
|
reads `PROVISIONING` and the URL answers 503; that is a cold start, not a fault, until
|
|
84
|
-
about twenty minutes have passed. `session open` waits
|
|
85
|
-
|
|
84
|
+
about twenty minutes have passed. `session open` waits `--timeout` seconds (default 600) and,
|
|
85
|
+
when that runs out, prints the session with `ready: false` and exits 1 while it keeps opening;
|
|
86
|
+
on a cold version pass `--no-wait` and poll `gateway worlds session status <sessionId>` until
|
|
87
|
+
`ready`.
|
|
86
88
|
|
|
87
89
|
The world's API honours the vendor's auth scheme: a hosted session accepts its own api token (as a
|
|
88
90
|
bearer or in the vendor's header), `worlds serve` the credential `--api-key` pins (default `conform`),
|
|
89
91
|
and `WORLD_API_KEY` applies only to a legacy api bundle. Anything else answers 401 with the body configured under
|
|
90
92
|
`[api].unauthorized` (`""` or `'null'` for a bare status with no body, the way some vendors answer).
|
|
91
93
|
|
|
94
|
+
The runner's own routes (`/__world/seed|reset|state|calls`) answer only `X-World-Admin-Token`. A session
|
|
95
|
+
pod and a Batch run mint that token themselves. A twin you host yourself (`hostedUrl`) gets it from
|
|
96
|
+
the world's secret `WORLD_ADMIN_TOKEN` (`gateway bench secrets set --env <slug> --key WORLD_ADMIN_TOKEN`,
|
|
97
|
+
the value on stdin), which a run or a session against the twin carries: start the twin's
|
|
98
|
+
`server/main.py` with the same `WORLD_ADMIN_TOKEN` in its environment, or every seed and grade is
|
|
99
|
+
refused with 403 `admin_token_required`.
|
|
100
|
+
|
|
92
101
|
**Data.** Captures are one way in. Any agent can put rows into the world without knowing its
|
|
93
102
|
layout: `gateway worlds data show ./spycloud-world` prints the kind and entity counts,
|
|
94
103
|
`gateway worlds data import ./spycloud-world rows.json [--entity NAME] [--mode append|replace]`
|
|
@@ -121,9 +130,9 @@ least one `[[operations]]` entry.
|
|
|
121
130
|
| `[capture]` | `requests_per_minute`, `timeout_seconds`, `max_pages`, `cursor_param`, `cursor_field`, `cursor_header` | Pacing between pages; providers ask us to be sparing. The next cursor is read from a body field or a response header (Torchlight sends `Cursor:`), never both, and is sent back as `cursor_param`; a cursor that is an absolute URL on the connection's host (DRF's `next`) is followed by its query. |
|
|
122
131
|
| `[redact]` | `hash`, `drop`, `round`, `preserve` | Applied before a body reaches disk. `preserve` hashes shape-preservingly (same length, digits stay digits, letters keep their case, separators stay; slug-salted, deterministic) so an account number still meets the field's format — `hash` made it a 71-char `sha256:` string the contract refused (Brex). `hash` writes `sha256:<hex>` salted with the slug so joins survive, element by element for arrays so the shape the contract expects survives too; `drop` removes; `round = { lat = 2, lon = 2 }` keeps numbers numeric but coarsens them. A bare name matches at any depth; a dotted path (`results.*.email`, `*` for list items) matches that place only, so a catalog's `assets` count map keeps its `email` key. Field names keep the vendor's casing. |
|
|
123
132
|
| `[api]` | `envelope`, `hits_key`, `cursor_key`, `page`, `limit_param`, `offset_param`, `cursor_param`, `page_size`, `previous_key`, `page_links`, `page_headers`, `cursor_absent_when_done`, `unauthorized`, `not_found`, `invalid`, `*_status`, `error_content_type`, `token_path`, `handlers`, `before` | `envelope = "results"` wraps rows as `{results, hits, cursor}` under the vendor's key names; empty means a bare array. `hits_key = ""` leaves the count out and `cursor_absent_when_done = true` leaves the cursor key out of the last page (instead of `""`), together the `{items, next_cursor?}` shape Brex-style vendors answer and clients test with `"next_cursor" in body`. `page` is `none`, `offset` or `cursor`, with the vendor's parameter names; `previous_key` adds the previous page and `page_links = true` renders next/previous as absolute URLs of the served host, the way Django REST Framework answers; `page_headers = { cursor = "Cursor", total = "Total-Count" }` sends the same values as response headers for vendors that page that way (Torchlight). Error bodies are JSON strings replayed verbatim with the vendor's statuses and content type (`application/problem+json` for RFC 7807 vendors); `""` (or `'null'`) means no body at all, for vendors that answer a bare 401. An oauth2 world mints bearers on `token_path` (default the spec's `token_url`) and honours only those. `handlers` names the world's Python module (default `api/handlers.py` when present); `before` names a gate in it that runs before every operation, declarative ones included, and returns `None` to let the request through or an answer (quota, allow-list, key state) to stop it. |
|
|
124
|
-
| `[[operations]]` | `name`, `method`, `path`, `params`, `entity`, `results` | `path` may carry `{args}`; a `params` name may end in `[]` (`expand[]`, `status[]`) for a key the vendor repeats, which capture then sends repeated and the served route filters on any value of; `results` is the dotted path to the row array (empty when the body is the row). An operation without `entity` never seeds and answers 501 `not_modelled`. An `entity` (or an `explode` target) that `schema/world.json` does not declare is refused by `connector validate`, `schema compile`, `schema check` and the platform's describe (`gateway worlds describe`, local or platform) alike — `operation X lands on entity Y, which schema/world.json does not declare (declared: …)` at `/operations/<i>/entity` — and nothing is written; hand-edited TOML meets the same gate `route add` applies. |
|
|
133
|
+
| `[[operations]]` | `name`, `method`, `path`, `params`, `entity`, `results` | `path` may carry `{args}`; a `params` name keeps the vendor's spelling, dots included (`query.bibliographic`, `filter.overallStatus`), and may end in `[]` (`expand[]`, `status[]`) for a key the vendor repeats, which capture then sends repeated and the served route filters on any value of; `results` is the dotted path to the row array (empty when the body is the row). An operation without `entity` never seeds and answers 501 `not_modelled`. Routes are never tools: an agent calls them over HTTP (the api url and token `session open --surface api` prints), and a tool exists only where `x-gateway.tools` declares one with a handler. An `entity` (or an `explode` target) that `schema/world.json` does not declare is refused by `connector validate`, `schema compile`, `schema check` and the platform's describe (`gateway worlds describe`, local or platform) alike — `operation X lands on entity Y, which schema/world.json does not declare (declared: …)` at `/operations/<i>/entity` — and nothing is written; hand-edited TOML meets the same gate `route add` applies. |
|
|
125
134
|
| `[operations.ingest]` | `drop`, `explode`, `carry_args` | `drop` removes vendor fields the entity does not carry; each `[[operations.ingest.explode]]` (`field`, `entity`, `carry`, `take`) turns a nested array into child rows; `carry_args = { account_id = "id" }` stamps the capture's path argument or query parameter onto every row before projection (a statement only knows its account from the URL it was fetched under). `connector ingest --dry-run [--report FILE]` lists every violation of every capture and writes nothing. |
|
|
126
|
-
| `[operations.api]` | `filter`, `match`, `action`, `status`, `single`, `envelope`, `page`, `body`, `defaults`, `generate`, `handler`, `sample`, `sample_headers`, `sample_body`, `not_found`, `not_found_status`, `cursor_absent_when_done` | `filter` maps a path argument or declared query parameter to the row field it selects on (case-insensitive, any depth; an absent parameter does not narrow, one sent more than once matches rows carrying any of its values); `match = { name = "contains" }` switches an argument from equality to substring or `prefix`, and a list field matches when any element does. `action` is `read` (default), `create`, `update`, `delete` or `handler`: writes persist through the contract, `body` maps row fields (dotted for nested) to request-body paths, `defaults` fixes constants, `generate` fills `uuid`, `int` or `now`; `update` and `delete` find their row through `filter` and answer the vendor's 404 otherwise
|
|
135
|
+
| `[operations.api]` | `filter`, `match`, `action`, `status`, `single`, `envelope`, `wrapper`, `page`, `body`, `defaults`, `generate`, `handler`, `sample`, `sample_headers`, `sample_body`, `not_found`, `not_found_status`, `cursor_absent_when_done` | `filter` maps a path argument or declared query parameter to the row field it selects on (case-insensitive, any depth; an absent parameter does not narrow, one sent more than once matches rows carrying any of its values); `match = { name = "contains" }` switches an argument from equality to substring or `prefix`, and a list field matches when any element does. `action` is `read` (default), `create`, `update`, `delete` or `handler`: writes persist through the contract, `body` maps row fields (dotted for nested) to request-body paths, `defaults` fixes constants, `generate` fills `uuid`, `int` or `now`; `update` and `delete` find their row through `filter` and answer the vendor's 404 otherwise; they, and a `single` read with a path argument, refuse (`finds its row by nothing`, 400) when neither `filter` nor a path argument naming a field selects a row, rather than act on some row; a singleton served under a scoped path answers through `action = "handler"`. `status` is the 2xx the vendor answers (201 for create, 204 for delete by default), `single` returns the row itself instead of an envelope, `envelope` and `page` override the world-wide setting per route. A dotted `envelope` nests the answer the way the vendor does (`message.items` answers `{message: {items, total-results, next-cursor}}`), and a single row is wrapped only by its own route's `envelope` (`message` answers `{message: row}`). `wrapper` is the rest of the vendor's envelope as a JSON object string (`'{"status": "ok", "message-type": "work-list"}'`), the answer laid onto it key by key; `schema init --from-openapi` writes it from the document. `handler` names a function `def name(ctx, args, query, body)` in the handlers module that returns a body, `(status, body)` or `(status, body, headers)`; `ctx` reads and writes the store (`rows`, `get`, `find`, `insert`, `update`, `delete`), keeps time (`now`, `elapsed`, `ladder` for status machines, frozen by `GATEWAY_WORLD_CLOCK`), mints ids (`uuid`) and shapes answers (`envelope`, `not_found`, `invalid`) and sees the request's `headers` and `query_all` (every value of every parameter, `{"expand[]": ["a", "b"]}`; the `query` argument keeps the first value only). `not_found` / `not_found_status` answer this route's missing row the vendor's own way (a 403 with its own message for one resource) and fall back to `[api]`; `cursor_absent_when_done` overrides `[api]` for this route. `sample = { ip = "203.0.113.5" }` gives the conformance run a value a validating route accepts when no seeded row can supply one; `sample_headers = { "Idempotency-Key" = "conform-1" }` and `sample_body = { reason = "conform" }` give it the headers and body a route demands (read by `connector conform` only; the served API never sends requests). |
|
|
127
136
|
|
|
128
137
|
### Scaffolding a route
|
|
129
138
|
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
## Scope and runtime support
|
|
6
6
|
|
|
7
|
-
`gateway-world/1` makes
|
|
7
|
+
`gateway-world/1` makes a mock-tools world's database state an executable
|
|
8
|
+
contract, stored by the `WorldDatabase` engine the manifest names (SQLite today). One
|
|
8
9
|
authored JSON Schema document declares payloads, entities, keys, relationships,
|
|
9
10
|
and tool shapes. A stdlib Python compiler generates artifacts and a lock;
|
|
10
11
|
store/world transactions enforce data and tool contracts.
|
|
11
12
|
|
|
12
13
|
The bounded JSON Schema 2020-12 compiler enforces contracts; connector handlers
|
|
13
14
|
implement vendor behavior. Slack now has a finite executable model and a
|
|
14
|
-
structured capture-to-batch mapper. Automatic migrations
|
|
15
|
-
|
|
15
|
+
structured capture-to-batch mapper. Automatic migrations and tenant overlays
|
|
16
|
+
remain outside this contract; SQLite is the only engine shipped today.
|
|
16
17
|
Ingestion code may write raw SQL through a [schema-gated
|
|
17
18
|
session](#raw-ingestion-schema-gated-sql), and connector
|
|
18
19
|
[templates](#connector-templates-and-init) initialize new worlds.
|
|
@@ -55,7 +56,7 @@ serve = ["list_accounts"]
|
|
|
55
56
|
| Supporting scope, provenance, fidelity and capability metadata | Descriptive resources; not payload schemas or proof of executed checks. |
|
|
56
57
|
| `data/initial.json` | Authored or mapper-produced initial mutation batch. |
|
|
57
58
|
| `tools/*.py`, `verifiers/*.sql` | Authored behavior and read-only grading. |
|
|
58
|
-
| `db/schema.sql` | Generated SQLite
|
|
59
|
+
| `db/schema.sql` | Generated storage DDL for the world's engine (SQLite today). |
|
|
59
60
|
| `schema/runtime.json` | Generated resolved contract; not authored. |
|
|
60
61
|
| `schema/README.md` | Generated entity and tool documentation. |
|
|
61
62
|
| `tool-schemas.json` | Generated `tools` map with `input_schema`, `output_schema`, and `description`. |
|
|
@@ -160,7 +161,7 @@ stays. Source: `gatewaysdk/sdk-ts/src/cli/runtime/scaffoldEntityRemove.ts`.
|
|
|
160
161
|
| Strings | `minLength`, `maxLength`; no regex/pattern constraints. |
|
|
161
162
|
| Numbers | `minimum`, `maximum`, numeric `exclusiveMinimum`/`exclusiveMaximum`. Every numeric value must be finite and within ±(2^53−1), including nonintegral numbers. A `format` on an integer or number (`int64`, `int32`, `double`, as vendor OpenAPI documents write them) is dropped, not refused; it asserts nothing. |
|
|
162
163
|
| Timestamps | Only `format: "date-time"`: RFC3339 profile with a real date, seconds, and explicit `Z` or numeric offset; fractional seconds and lowercase `t`/`z` accepted; leap seconds rejected. |
|
|
163
|
-
| Reuse | `$defs`, `$ref` to `#/$defs/Name` or `base.json#/$defs/Name` (including valid JSON Pointer paths beneath `$defs`). A definition may reference itself, directly or through a property, item or composition branch (Brex's `ExpandableExpense` holds an `ExpandableExpense`): the first occurrence is inlined in full, the nested occurrence keeps only the target's bare `type` (annotated with a `$comment` naming the target), so it is validated as that type and stored as JSON. A cycle of bare references or compositions, with no direct `type` to keep, is refused. |
|
|
164
|
+
| Reuse | `$defs`, `$ref` to `#/$defs/Name` or `base.json#/$defs/Name` (including valid JSON Pointer paths beneath `$defs`). A definition may reference itself, directly or through a property, item or composition branch (Brex's `ExpandableExpense` holds an `ExpandableExpense`): the first occurrence is inlined in full, the nested occurrence keeps only the target's bare `type` (annotated with a `$comment` naming the target), so it is validated as that type and stored as JSON. A cycle of bare references or compositions, with no direct `type` to keep, is refused. Compile inlines every reference while each generated file fits the 4 MB publication cap. When it would not (Google Docs: one body type reached along hundreds of paths, 24 MB inlined), each object or array definition is emitted once under the root's `$defs` as `{"$ref": "#/$defs/<file>.<Name>", "type": ...}`, a nested occurrence of a type in itself is a real reference (validated in full), scalar definitions stay inlined, and `schema/README.md` documents each definition once under Definitions. |
|
|
164
165
|
| Composition | `allOf`, `anyOf`, `oneOf`, with nonempty branch lists. These validate values; they do not merge entity declarations or implement inheritance. |
|
|
165
166
|
| Documentation | `title`, `description`, `$comment`, `examples`, `deprecated`, `readOnly`, `writeOnly` have no mutation/access-control semantics. `default` must validate but is never inserted. |
|
|
166
167
|
|
|
@@ -193,20 +194,25 @@ and inheritance/overrides are rejected. Reuse definitions by `$ref` and declare
|
|
|
193
194
|
each entity once in the root catalog.
|
|
194
195
|
|
|
195
196
|
Entity names use `[A-Za-z][A-Za-z0-9_]*`. Payload property names use
|
|
196
|
-
`[A-Za-z_][A-Za-z0-9_]*`, so
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
197
|
+
`[A-Za-z_][A-Za-z0-9_-]*`, so vendor fields such as `_links`, `_etag` and
|
|
198
|
+
`reference-count` keep the vendor's spelling. A dot or a slash is never part of a
|
|
199
|
+
name: nested fields are addressed by JSON Pointer. `_key`, `payload`, and the
|
|
200
|
+
`sqlite_`, `gateway_`, and `benchmark_` storage prefixes remain reserved
|
|
201
|
+
case-insensitively. Case-fold collisions are rejected. Domain prefixes such as
|
|
202
|
+
`crm_` avoid collisions when authoring one combined catalog.
|
|
203
|
+
|
|
204
|
+
Primary keys are ordered, nonempty lists of distinct, required, non-null
|
|
205
|
+
string/integer fields. A field is a direct property name or an RFC 6901 JSON
|
|
206
|
+
Pointer to a nested scalar, such as `/protocolSection/identificationModule/nctId`;
|
|
207
|
+
every object along the pointer must be required and non-null, so every row
|
|
208
|
+
carries its key. Unique keys may use direct field names or JSON Pointers such as
|
|
209
|
+
`/profile/email`; pointer escapes `~0` and `~1` are decoded. Their scalar leaves
|
|
210
|
+
may be optional or nullable: missing/null values do not conflict, while equal
|
|
211
|
+
present non-null values do. Composite keys work. Composition and duplicate key
|
|
212
|
+
declarations reject. Lookup objects contain exactly the primary-key fields, each
|
|
213
|
+
under its own name (the pointer itself for a nested field:
|
|
214
|
+
`{"/protocolSection/identificationModule/nctId": "NCT00000001"}`). Integral keys
|
|
215
|
+
share identity (`1` equals `1.0`) without rewriting payloads.
|
|
210
216
|
|
|
211
217
|
Relationships declare ordered `fields`, a target entity, and
|
|
212
218
|
`on_delete: "restrict"`, targeting its primary key with equal arity
|
|
@@ -232,15 +238,16 @@ Unresolved targets reject without fabricating placeholders. Mappers must choose
|
|
|
232
238
|
valid records or model external identifiers as ordinary fields without a relationship.
|
|
233
239
|
`ArtifactReference.logicalSourceId` identifies evidence, not universal entity keys.
|
|
234
240
|
|
|
235
|
-
##
|
|
241
|
+
## Storage representation and supported store API
|
|
236
242
|
|
|
237
|
-
|
|
243
|
+
The representation below is the SQLite engine's (the one shipped today). Tables
|
|
244
|
+
hold canonical `payload` JSON, a private encoded `_key`, and generated
|
|
238
245
|
scalar projections for verifiers and UNIQUE/FK constraints. A property projects
|
|
239
246
|
when it can only hold scalars: a scalar `type` (nullable or not), or a
|
|
240
247
|
composition whose non-null branches are all scalar, such as the nullable enum
|
|
241
248
|
reference `anyOf [{$ref Status}, {type: null}]`. Objects/arrays, and any
|
|
242
249
|
composition that may hold one, remain JSON only. SQL exposes booleans as SQLite
|
|
243
|
-
values; store reads restore JSON booleans. Query errors keep
|
|
250
|
+
values; store reads restore JSON booleans. Query errors keep the engine's message
|
|
244
251
|
(`no such column: status`), and the store disables SQLite's double-quoted
|
|
245
252
|
string-literal fallback, so a verifier naming a column that does not exist
|
|
246
253
|
fails the grade with the statement instead of comparing two literals and
|
|
@@ -249,11 +256,14 @@ Missing and null both project to SQL NULL but remain distinct in `payload`;
|
|
|
249
256
|
grade that distinction with JSON presence/type queries. Validation preserves
|
|
250
257
|
false, zero, empty values, null, and absence without coercion/default insertion.
|
|
251
258
|
|
|
252
|
-
Import `
|
|
259
|
+
Import `WorldDatabase` from `gatewaysdk.environment.schema`. `WorldDatabase.create` / `open` pick
|
|
260
|
+
the engine the contract was compiled for (its lock's `target`; SQLite today, `SQLiteWorldDatabase` in
|
|
261
|
+
`gatewaysdk.environment.schema.database`). Every method below lives on the base, which owns the
|
|
262
|
+
contract, the audit and the guard, so a later engine answers the same way.
|
|
253
263
|
|
|
254
264
|
| API | Behavior |
|
|
255
265
|
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
256
|
-
| `create(path, contract)` / `open(path, contract)` | Context-managed store; creation refuses an existing file; opening checks the
|
|
266
|
+
| `create(path, contract)` / `open(path, contract)` | Context-managed store; creation refuses an existing file; opening checks the storage contract, actual DDL, and state. |
|
|
257
267
|
| `get(entity, key)` / `list(entity)` | Returns decoded payloads; a missing key returns `None`; list order follows encoded primary keys. |
|
|
258
268
|
| `insert(entity, value, source=...)` | Validates a complete record; returns its payload. |
|
|
259
269
|
| `update(entity, key, patch, source=...)` | Shallow-merges the patch, validates the complete result, and forbids primary-key changes; returns the resulting payload. |
|
|
@@ -268,15 +278,15 @@ Import `SQLiteStore` from `gatewaysdk.environment.schema`:
|
|
|
268
278
|
A tool handler (`tools/handlers.py`) does not see this class. `from gateway_env import store` is a
|
|
269
279
|
facade over it admitting exactly `get, list, list_where, insert, update, delete, apply_batch,
|
|
270
280
|
lineage, counts` — the one list in `environment/schema/store_contract.py` (`STORE_METHODS`, read off
|
|
271
|
-
`
|
|
281
|
+
`WorldDatabase` so it cannot drift). `gateway worlds schema check` refuses any other `store.<name>`
|
|
272
282
|
statically at file:line with that list; a hosted call into a handler whose own code raises
|
|
273
283
|
`AttributeError`/`TypeError`/`NameError` answers 400 `{error: "handler", detail, handler}`, any other
|
|
274
284
|
handler failure 500 `{error: "engine", detail, handler}` — never a bare exception string. There is
|
|
275
285
|
no `upsert`: `get`, then `insert` or `update`.
|
|
276
286
|
|
|
277
287
|
Connections enable foreign keys, bind values, and quote identifiers. `World` copies the validated
|
|
278
|
-
template for branches/reset;
|
|
279
|
-
|
|
288
|
+
template for branches/reset; a snapshot reopens under any contract with the storage contract its
|
|
289
|
+
rows were stored under (below). A live `World`'s reset rejects any changed lock: its tools are bound.
|
|
280
290
|
|
|
281
291
|
`gateway_env.store` is that facade, bound to the currently executing schema world.
|
|
282
292
|
Lifecycle/transaction ownership stays with `World`. The legacy `db.one/all` and
|
|
@@ -347,7 +357,10 @@ Provider authorization, capture lifetime/fences, and schema compilation remain s
|
|
|
347
357
|
Ingestion code, including code an agent writes in a sandbox, may write SQL
|
|
348
358
|
straight into a world. The contract, not the API, decides what lands: the
|
|
349
359
|
session commits only when every persisted row satisfies the schema, keys and
|
|
350
|
-
relationships, and otherwise rolls back as a whole.
|
|
360
|
+
relationships, and otherwise rolls back as a whole. Known gap: a `TEMP` table named like a
|
|
361
|
+
domain or `_gateway_*` table shadows it for that check and for the batch and lineage rows, so
|
|
362
|
+
an invalid write can commit unrecorded (open bug, pinned in the guard matrix, to be fixed by
|
|
363
|
+
#474). Never name staging tables after world tables.
|
|
351
364
|
|
|
352
365
|
```python
|
|
353
366
|
with world.store.ingest(
|
|
@@ -366,7 +379,7 @@ print(conn.result) # {"status": "applied", "batch": ..., "inserted": n, ...}
|
|
|
366
379
|
| Inside a session | Rule |
|
|
367
380
|
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
368
381
|
| Domain tables | `INSERT`, `UPDATE`, `DELETE` allowed; `gateway_key(entity, payload)` computes `_key` in SQL and returns NULL for a payload without its primary key, so the NOT NULL constraint rejects the row with the reason attached. |
|
|
369
|
-
| `TEMP` tables, views
|
|
382
|
+
| `TEMP` tables, views | Allowed for staging; dropped when the session ends. A `TEMP` index is refused today (open bug, pinned in the guard matrix). |
|
|
370
383
|
| `conn.script(sql)` | Runs a multi-statement script one statement at a time. `executescript` is not exposed because it would commit early. |
|
|
371
384
|
| Transaction control, `PRAGMA`, `ATTACH`, persistent DDL | Denied by the authorizer (`ingest_sql`). The store owns the transaction. |
|
|
372
385
|
| `_gateway_*`, `benchmark_runtime_context`, `benchmark_conversation_events` | Neither readable nor writable. `benchmark_runtime_parameters` stays readable. |
|
|
@@ -381,7 +394,8 @@ carrying the code, schema/data paths, entity and encoded key. A rejected
|
|
|
381
394
|
session leaves state, lineage and its `batch_id` untouched. A committed session
|
|
382
395
|
is recorded as one batch (`kind: "ingest"`) with a lineage row per inserted,
|
|
383
396
|
updated or deleted key under the session's `source`, so raw ingestion keeps the
|
|
384
|
-
same provenance as `apply_batch`, attributed per key rather than per mutation
|
|
397
|
+
same provenance as `apply_batch`, attributed per key rather than per mutation
|
|
398
|
+
(except under the `TEMP`-shadow gap above, where the session commits with no batch or lineage).
|
|
385
399
|
Reusing a committed `batch_id` is an `idempotency_conflict`; raw sessions are
|
|
386
400
|
not replayable. Run `python samples/schema-worlds/ingest_example.py` for a
|
|
387
401
|
committed and a rejected session.
|
|
@@ -428,7 +442,9 @@ and a starter verifier but no tools unless `--with-example-tool`
|
|
|
428
442
|
holds only the recipe. Batches interchange only when the domain id, version and
|
|
429
443
|
hash match. Giving an authored world a new `$id` later is fine: `compile`
|
|
430
444
|
re-stamps an empty journal (`mutations == []`) onto the new domain, whatever
|
|
431
|
-
`$id` it named; a journal that holds rows
|
|
445
|
+
`$id` it named; a journal that holds rows follows a change that only adds to
|
|
446
|
+
the domain it was written under (a new entity, a new field that is not
|
|
447
|
+
required, another `domain_version`) and is refused otherwise, with the fix named
|
|
432
448
|
(re-import its rows against the new contract, or restore the schema it was
|
|
433
449
|
written against). The target is pure to compute:
|
|
434
450
|
`from gatewaysdk.environment.schema.compiler import build; build(world).target`.
|
|
@@ -444,17 +460,41 @@ gateway worlds schema init ./gh --from-openapi https://example.com/github.json -
|
|
|
444
460
|
gateway worlds schema init ./crm --from-openapi drive:specs/crm.json --plan-only
|
|
445
461
|
```
|
|
446
462
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
463
|
+
Entities are the rows the selected operations answer and take, read through the vendor's
|
|
464
|
+
envelope. A response that is an array of objects, or an object that declares no key and holds
|
|
465
|
+
exactly one array of objects (possibly behind objects holding nothing else, as Crossref's
|
|
466
|
+
`message` → `items`), lists that item schema. A single-row response is the row when it is some
|
|
467
|
+
list's item, declares a key, or names the field the route's own `{segment}` reads it by; else,
|
|
468
|
+
through a wrapper holding exactly one object, that object. A wrapper is never an entity: its path
|
|
469
|
+
becomes the route's dotted `envelope` (`message.items`) and the rest of it the route's `wrapper`
|
|
470
|
+
template, so the served world answers in the vendor's envelope again. An item's key is a
|
|
471
|
+
declared one (`id`, `<name>Id`, `<name>_id`, a `readOnly` field an `x-` extension marks unique),
|
|
472
|
+
else the field its single-row route reads it by: a top-level field spelled the vendor's way
|
|
473
|
+
(`/works/{doi}` → `DOI`), or one nested in the row's objects (never through an array or a
|
|
474
|
+
nullable object), which becomes a JSON Pointer key (`/studies/{nctId}` →
|
|
475
|
+
`/protocolSection/identificationModule/nctId`) and makes every object on that path required.
|
|
476
|
+
An item only lists carry falls back to its first required scalar, with a warning that rows
|
|
477
|
+
sharing it collapse. An item no planned route reads or writes is not an entity, and a schema
|
|
478
|
+
that is no item stays an inline `$def`; a document whose operations name no schema offers
|
|
479
|
+
every keyed schema instead. Each entity is a `$def` plus `x-gateway.entities[<snake_plural>]`
|
|
480
|
+
with `primary_key`; `allOf` is merged, `oneOf`/`anyOf` kept as unions the validator accepts;
|
|
481
|
+
entity names are snake_cased, bounded to 64 characters, and the original recorded in
|
|
482
|
+
`schema/provenance.json`; property names and query parameters keep the vendor's spelling
|
|
483
|
+
(`reference-count`, `query.bibliographic`). Every path+method becomes an operation in
|
|
484
|
+
`connector.toml`: `operationId` snake_cased and bounded to 64 characters (a duplicate gets a
|
|
485
|
+
numeric suffix and a warning), path and query parameters declared, a list response an entity
|
|
486
|
+
list route (declared query parameters that name entity fields filter it), a single-row response
|
|
487
|
+
the entity's read, and a write its create/update/delete by method; a single read whose path
|
|
488
|
+
argument names no field of the row, and a response that carries no entity, stay passthrough
|
|
489
|
+
operations (no `entity`, `501` when called), the reason in the plan. List routes page as the
|
|
490
|
+
document says: a cursor parameter (`cursor`, `pageToken`) beside a next-cursor field in the
|
|
491
|
+
envelope (`next-cursor`, `nextPageToken`) pages by cursor, an `offset` parameter by offset, and
|
|
492
|
+
the count beside the rows (`total-results`, `totalCount`) is the hits key. `[api]` pages the way
|
|
493
|
+
most list routes do, a route paging otherwise names its own `page`, and page-number paging
|
|
494
|
+
(`page` + `per_page`) is named in a warning, its route answering every row. An import declares
|
|
495
|
+
no tools: routes are never tools, so an agent reaches an imported world's routes over HTTP
|
|
496
|
+
(`session open --surface api`), and an author who wants a tool declares it in `x-gateway.tools`
|
|
497
|
+
with a handler.
|
|
458
498
|
`HEAD`/`OPTIONS`/`TRACE` (anything outside `GET POST PUT PATCH DELETE`), a path that repeats a
|
|
459
499
|
placeholder (`/a/{id}/{id}`), and operations
|
|
460
500
|
`--include` / `--exclude` leave out (a path glob or a tag,
|
|
@@ -465,7 +505,7 @@ cyclic entity root, a document without `paths`, a document over 64 MiB.
|
|
|
465
505
|
The command prints the plan (`entities`, `operations`, `skipped`, `warnings`, the document's
|
|
466
506
|
version, title and sha256) and, unless `--plan-only`, writes the tree through the same writer as
|
|
467
507
|
a template `init`, so a rejected import leaves nothing behind, then lists the `next` commands:
|
|
468
|
-
`schema compile`, `schema check`, `data import`, `serve`
|
|
508
|
+
`schema compile`, `schema check`, `data import`, `serve` and a `curl` of a list route, `sandbox commit` or `worlds
|
|
469
509
|
create`. `schema/provenance.json` records the source label (credentials and query strings
|
|
470
510
|
stripped), its sha256 and size, the importer version and each entity's and operation's source
|
|
471
511
|
pointer. `--connector` and `--with-example-tool` do not combine with it. The document's bytes
|
|
@@ -473,8 +513,14 @@ are read where the command runs: a local path directly; `drive:<path>` from the
|
|
|
473
513
|
with the caller's key, in memory; an `http(s)://` URL through a private-address guard (no
|
|
474
514
|
loopback, RFC 1918, link-local or metadata host, every redirect re-checked, five at most) — the
|
|
475
515
|
platform never fetches a caller-named URL, and the sandbox's `run_gateway_cli` accepts only a
|
|
476
|
-
`/workspace` path.
|
|
477
|
-
|
|
516
|
+
`/workspace` path. The import runs in this machine's schema runtime whenever it has one
|
|
517
|
+
(`GATEWAY_RUNTIME=local` demands it and sends nothing to the platform); only with none here, or
|
|
518
|
+
with `GATEWAY_RUNTIME=platform`, does the platform's `init-openapi` runtime command read the
|
|
519
|
+
staged bytes. A YAML document is read by PyYAML in the Python that runs the runtime: without it
|
|
520
|
+
the command is refused before anything is sent, naming the fix (install PyYAML there, point
|
|
521
|
+
`GATEWAY_PYTHON` at a Python that has it, or convert the document to JSON).
|
|
522
|
+
`gateway worlds connector conform <world> --openapi <same document>` then checks the served
|
|
523
|
+
world back against the document it came from.
|
|
478
524
|
|
|
479
525
|
**Build from connector** for Slack creates a durable populated world job in
|
|
480
526
|
Gateway. Other registered source kinds show their CLI twin under **Use the CLI instead**:
|
|
@@ -571,7 +617,7 @@ as a credential-free subprocess (`GATEWAY_SCHEMA_PYTHON`, `GATEWAY_SCHEMA_RUNTIM
|
|
|
571
617
|
| ------------------------------ | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
572
618
|
| `validate`, `validate-archive` | publication | Verify SHA-256, regenerated artifacts and exact lock of an existing tree/archive. |
|
|
573
619
|
| `init-template` | `create_connector_world`, `create_custom_world --template` | Scaffold a connector template into a tree. |
|
|
574
|
-
| `init-openapi` | `worlds schema init --from-openapi` (both CLIs)
|
|
620
|
+
| `init-openapi` | `worlds schema init --from-openapi` (both CLIs; the TypeScript CLI through `POST /api/public/worlds/runtime` only when no runtime is here) | `{source, document (base64), destination, plan_only?, include?, exclude?, name?}` → the import plan and, when written, the compiled tree as `files[]` (at most 2000). The bridge never opens a caller-named path or URL; the CLI stages the bytes. A YAML document needs PyYAML in the Python that reads it, and is refused naming the fix without it. |
|
|
575
621
|
| `compile` | `create_custom_world`, `ingest_to_world` on schema worlds | Compile an authored tree (`compileWorldFiles`): returns the full entry map with generated artifacts + lock, the schema report and which files were added/retargeted. |
|
|
576
622
|
| `apply-batch` | `ingest_records_to_world` | Apply `insert\|update\|delete` mutations as one batch (`applyWorldBatch`): validated row by row against the compiled schema, appended as `data/batches/<batchId>.json` with `source` provenance; replaying the same `batchId` is a no-op. |
|
|
577
623
|
| `build-slack`, `refresh-slack` | connector worlds | Slack capture → batches (durable job). |
|
|
@@ -609,11 +655,17 @@ and mutation order remain meaningful. No broader equivalence is promised.
|
|
|
609
655
|
| Domain | Root `$id`, `domain_version`, and compiled entity-contract hash. Batches must match all three; changed domains require regeneration and explicit state rebuilding. |
|
|
610
656
|
| Dependencies | Every resolved document's `$id` and normalized authored hash are locked. Missing, changed, or incompatible dependencies require an explicit fix/regeneration. |
|
|
611
657
|
| Mapping | Batch `mapping.id/version`, persisted with lineage; a new mapping does not change the domain or package contract. |
|
|
612
|
-
| Package/tool behavior | `x-gateway.package.id/version`, tool-contract hash, and generated artifact hashes. Tool/package changes require regeneration;
|
|
613
|
-
|
|
614
|
-
Opening
|
|
615
|
-
|
|
616
|
-
|
|
658
|
+
| Package/tool behavior | `x-gateway.package.id/version`, tool-contract hash, and generated artifact hashes. Tool/package changes require regeneration; stored state still opens (it is bound to the storage contract, not the lock). Authored handler bytes remain bound by package/bundle versioning, not compiled schema semantics. |
|
|
659
|
+
|
|
660
|
+
Opening state (a snapshot, an export, a session's store) requires the same **storage
|
|
661
|
+
contract** (`StorageContract`): the language, annotations, compiler and target, the domain's
|
|
662
|
+
`$id`, `domain_version` and compiled-entity hash (in either resolver form; an entity field's
|
|
663
|
+
description, title and examples are part of it), and the generated SQL, plus identical DDL. The
|
|
664
|
+
rest of the lock (package, tools, document and artifact hashes) may differ: none of it touches a
|
|
665
|
+
stored row, so a tool edit keeps every snapshot. A domain change has no minor-version shortcut
|
|
666
|
+
or automatic migration: retain the original bundle with old state or explicitly rebuild. Two
|
|
667
|
+
worlds of one domain open each other's state; which state a hosted version opens is the
|
|
668
|
+
platform's to scope. Version labels do not prove vendor fidelity.
|
|
617
669
|
|
|
618
670
|
## Offline example
|
|
619
671
|
|
|
@@ -292,9 +292,10 @@ A schema world's validated database is kept, not rebuilt. `gateway worlds schema
|
|
|
292
292
|
builds `db/state.sqlite` (the default snapshot: `data/initial.json` applied through the
|
|
293
293
|
contract) and `scenarios/<name>/state.sqlite` (the default with the scenario's overlays),
|
|
294
294
|
each with a `state.json` sidecar `{contractHash, batchDigest, entityCounts, builtAt,
|
|
295
|
-
runtime, fileSha256}`; the same
|
|
296
|
-
and a data batch the contract refuses leaves no
|
|
297
|
-
|
|
295
|
+
runtime, fileSha256}`; a snapshot that already holds the same data is never rebuilt,
|
|
296
|
+
`schema check` verifies the sidecars, and a data batch the contract refuses leaves no
|
|
297
|
+
snapshot behind. `gateway worlds serve` and
|
|
298
|
+
the api bundle open the snapshot (copy + `WorldDatabase.open`, no row replay) and reset by
|
|
298
299
|
copying it again; without one the JSON is replayed as before. A hosted pod gets
|
|
299
300
|
`WORLD_SNAPSHOT_URL` (presigned GET, `.gz` or `Content-Encoding: gzip` is gunzipped),
|
|
300
301
|
`WORLD_SNAPSHOT_SHA256` and `WORLD_SNAPSHOT_DIGEST`; the server downloads, verifies, writes
|
|
@@ -303,3 +304,28 @@ reports `"snapshot": {batchDigest, contractHash}` (or null) and `/__world/seed`
|
|
|
303
304
|
overlay form `{"base": digest, "rows": {...}, "mode": append|replace}` beside the legacy
|
|
304
305
|
whole-state body. Snapshot files are build outputs: gitignore `db/state.sqlite`,
|
|
305
306
|
`db/state.json`, `scenarios/*/state.*`.
|
|
307
|
+
|
|
308
|
+
**Which edits keep a snapshot.** Rows are bound to the domain they were stored under, not to
|
|
309
|
+
the whole contract: adding a tool, editing a handler, a route, a test, a documentation file or
|
|
310
|
+
the package version keeps every snapshot (local, hosted, pinned), with no re-import. A change
|
|
311
|
+
that only adds to the domain (a new entity, a new field that is not required, another
|
|
312
|
+
`domain_version`) carries the rows: compile migrates the snapshots the tree holds and keeps the
|
|
313
|
+
pin with the stored domain's `lock` and `entities`, `sandbox check` says the commit migrates the
|
|
314
|
+
hosted snapshot, and `sandbox commit` migrates it and re-pins the tree (a CLI push of such a
|
|
315
|
+
change is refused, naming the sandbox). Any other change to an entity, a field (its description
|
|
316
|
+
or title too), a key or a relationship refuses it, naming each change:
|
|
317
|
+
|
|
318
|
+
```text
|
|
319
|
+
snapshot_pinned at /db/snapshot.json: The rows here were stored under the previous domain, and
|
|
320
|
+
this change requires field users.age. Stored rows carry over only when a change adds to their
|
|
321
|
+
domain (a new entity, a new field that is not required, or another domain_version): ...
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Then keep those as they were, or remove `db/snapshot.json` and import every row again. A tree
|
|
325
|
+
pinned to a hosted snapshot (`db/snapshot.json`, what a data import publishes) compiles and checks
|
|
326
|
+
without the snapshot itself, as in a sandbox: compile keeps the pin, never rebuilds state from
|
|
327
|
+
the data files, and records in the pin (`lock`) the contract the snapshot was built under, which
|
|
328
|
+
is how the platform proves the next edit still fits it. If `schema/lock.json` was replaced by
|
|
329
|
+
artifacts compiled elsewhere before that, compile says the domain cannot be proven: restore
|
|
330
|
+
`schema/lock.json` from the version you started from and compile again. A `[redact]` change is
|
|
331
|
+
not part of it: the store never applies the policy; capture and `--redact apply` do.
|