@mnmal-ai/substrate 1.0.0-alpha.16 → 1.0.0-alpha.18

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.
Files changed (40) hide show
  1. package/README.md +5 -4
  2. package/dist/{boot-store-HxCgbvNl.js → boot-store-C8KrACZ5.js} +51 -72
  3. package/dist/{bridge-CvZGzNIO.d.ts → bridge-5VHZiH9o.d.ts} +1 -1
  4. package/dist/{cli-6mjAWiEZ.js → cli-zZ7nHhY5.js} +235 -16
  5. package/dist/client.d.ts +8 -3
  6. package/dist/client.js +4 -4
  7. package/dist/{errors-BXxm9eZF.d.ts → errors-DHgT7Fa8.d.ts} +8 -2
  8. package/dist/{index-EN-nQsX8.d.ts → index-DKJXQ031.d.ts} +1 -1
  9. package/dist/{node-version-C5FSmwJX.js → node-version-CxqcqECU.js} +1 -1
  10. package/dist/pack.d.ts +18 -2
  11. package/dist/pack.js +2 -2
  12. package/dist/{pg-edges-store-De5F1tUf.js → pg-edges-store-D7etFxNK.js} +1 -1
  13. package/dist/{plugin-Dpa_Y7Ep.js → plugin-DcoJGEMM.js} +2 -2
  14. package/dist/proposals-bootstrap.js +2 -2
  15. package/dist/proposals.d.ts +5 -3
  16. package/dist/proposals.js +1 -1
  17. package/dist/recall-bootstrap.js +2 -2
  18. package/dist/recall.d.ts +1 -1
  19. package/dist/recall.js +2 -2
  20. package/dist/{repl-2WfRPUb0.js → repl-SY8cLOZl.js} +1 -1
  21. package/dist/{row-Dh57ShWL.d.ts → row-DHxnCnhA.d.ts} +10 -8
  22. package/dist/{run-ChcHBIN3.js → run-Cr-53N3F.js} +142 -106
  23. package/dist/{schema-B--_bHjn.d.ts → schema-B5WBO8yh.d.ts} +79 -19
  24. package/dist/{script-C6DSa_Na.js → script-B-32wZGY.js} +11 -1
  25. package/dist/script-runner.js +78 -0
  26. package/dist/sdk.d.ts +51 -8
  27. package/dist/sdk.js +4 -4
  28. package/dist/{src-B4sqnLRy.js → src-B4dTiEWw.js} +77 -28
  29. package/dist/{src-DHLw3eCn.js → src-BcuotITf.js} +1016 -231
  30. package/dist/{src-DWqzrm3O.js → src-CdbUzLhB.js} +209 -36
  31. package/dist/{src-BMHI_rTJ.js → src-D55T3ZcP.js} +2203 -499
  32. package/dist/{src-Bi3NhEsT.js → src-DR_hUj2p.js} +1 -1
  33. package/dist/{src-CHND7-Pm.js → src-DV6PcXym.js} +2 -2
  34. package/dist/{src--uyAqssS.js → src-DZfgQ2gR.js} +3 -3
  35. package/dist/substrate-admin.js +2 -2
  36. package/dist/substrate.js +2 -2
  37. package/dist/testing.d.ts +5 -3
  38. package/dist/testing.js +4 -4
  39. package/dist/{ws-CpHWxwp9.d.ts → ws-BL9nSELO.d.ts} +2 -2
  40. package/package.json +21 -21
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `substrate` binary: the server, the stdio MCP server, and the runtime scaffolder, plus `substrate-admin` for key management. The same package carries the libraries for plugin authors and clients, and two built-in plugins: `substrate-recall` (kernel) and `substrate-proposals` (coordinator).
4
4
 
5
- It runs as a real install: the binary and its plugins resolve from one shared `node_modules`, so every plugin sees the same copy of every shared package. `substrate init` scaffolds such a runtime directory. Node `>=26.12.1` is required; a durable deployment also needs PostgreSQL 18 or newer with the `pgvector` extension. Walkthrough: [`docs/getting-started.md`](https://github.com/mnmal-ai/substrate/blob/main/docs/getting-started.md).
5
+ It runs as a real install: the binary and its plugins resolve from one shared `node_modules`, so every plugin sees the same copy of every shared package. `substrate init` scaffolds such a runtime directory. Node `>=26.13.1` is required; a durable deployment also needs PostgreSQL 18 or newer with the `pgvector` extension. Walkthrough: [`docs/getting-started.md`](https://github.com/mnmal-ai/substrate/blob/main/docs/getting-started.md).
6
6
 
7
7
  ## Library subpaths
8
8
 
@@ -35,7 +35,7 @@ A plugin package declares `@mnmal-ai/substrate` as a peer dependency and as a de
35
35
 
36
36
  ### MCP tools
37
37
 
38
- `substrate mcp` serves `schema`, `query`, `mutate`, `recall`, `ask`, `whoami`, `propose_type`, `propose_field`, and the admin-gated `drop_namespace` / `drop_type`. It talks to a running server at `SUBSTRATE_URL` and signs requests when `SUBSTRATE_AGENT_KEY_ID` and `SUBSTRATE_AGENT_KEY_PATH` are set. [`docs/surface-parity.md`](https://github.com/mnmal-ai/substrate/blob/main/docs/surface-parity.md) maps what each surface (HTTP, MCP, WS, SSE) offers.
38
+ `substrate mcp` serves `schema`, `query`, `mutate`, `run`, `recall`, `ask`, `whoami`, `propose_type`, `propose_field`, `propose_index`, and the admin-gated `drop_namespace` / `drop_type`. `run` executes a short script against the store in one call (the same context as `substrate run`), in a child process with no file, network, process or environment access. It talks to a running server at `SUBSTRATE_URL` and signs requests when `SUBSTRATE_AGENT_KEY_ID` and `SUBSTRATE_AGENT_KEY_PATH` are set. [`docs/surface-parity.md`](https://github.com/mnmal-ai/substrate/blob/main/docs/surface-parity.md) maps what each surface (HTTP, MCP, WS, SSE) offers.
39
39
 
40
40
  ### `substrate ask`
41
41
 
@@ -139,9 +139,9 @@ The main ones; `substrate --help` and the header of `apps/substrate/src/main.ts`
139
139
  | `SUBSTRATE_AUTH_KEY_REGISTRY` | Path to a JSON key registry file. Without it, auth reads keys registered in Postgres with `substrate-admin`. |
140
140
  | `SUBSTRATE_PUBLIC_ORIGIN` | The origins callers reach this server by, comma-separated (`https://host:3100,https://alias`). A token whose `aud` names none of them is refused. **Required when auth is enabled and `HOST` is not loopback**; on loopback it defaults to the loopback origins. |
141
141
  | `SUBSTRATE_STREAM_TICKET_SECRET` | HMAC key signing SSE stream tickets. **Required when auth is enabled**; at least 16 characters. The ticket signature is the only authentication on `GET /substrate/v1/stream` and `GET /substrate/v1/subscribe`, because `EventSource` can send no header or body. Rotating it invalidates every outstanding ticket. |
142
- | `SUBSTRATE_TLS_KEY_PATH` / `SUBSTRATE_TLS_CERT_PATH` / `SUBSTRATE_TLS_CA_PATH` | Serve HTTPS. Key and cert are required together. |
142
+ | `SUBSTRATE_TLS_KEY_PATH` / `SUBSTRATE_TLS_CERT_PATH` / `SUBSTRATE_TLS_CA_PATH` | Serve HTTPS, over HTTP/2 with an HTTP/1.1 fallback. Key and cert are required together. |
143
143
  | `SUBSTRATE_NAMESPACE` | Default namespace for recall requests that omit one; with neither, recall refuses with `missing_namespace`. |
144
- | `SUBSTRATE_STATEMENT_TIMEOUT_MS` | Statement timeout for typed edge walk reads (default 30000). A read it cancels is refused `query_timeout`. |
144
+ | `SUBSTRATE_STATEMENT_TIMEOUT_MS` | Statement timeout for typed edge walk reads (default 30000). A read it cancels is refused `query_timeout`. It also bounds the wait for a free database connection; a request that waits longer is refused `store_busy`. |
145
145
  | `SUBSTRATE_PAGE_LIMIT_DEFAULT` / `SUBSTRATE_PAGE_LIMIT_MAX` | Page size for a remote query that names no `limit` (default 100), and the largest `limit` accepted (default 1000). |
146
146
  | `SUBSTRATE_FILTER_WRITE_MAX_MATCH` / `SUBSTRATE_FILTER_WRITE_IDS_CAP` | `updateMany<Type>` / `deleteMany<Type>`: a filter matching more rows than the max is refused `filter_too_broad` (default 10000); the result lists at most the cap of ids (default 1000). |
147
147
  | `SUBSTRATE_SWEEP_INTERVAL_MS` | Edge-sweep cadence (default 300000) |
@@ -162,6 +162,7 @@ Natural-language query and the recall embedder are not configured by environment
162
162
  - [Design spec](https://github.com/mnmal-ai/substrate/blob/main/docs/substrate-from-first-principles.md)
163
163
  - [Operator decisions](https://github.com/mnmal-ai/substrate/blob/main/docs/operator-decisions.md)
164
164
  - [Upgrading to per-type tables](https://github.com/mnmal-ai/substrate/blob/main/docs/upgrading-to-type-tables.md)
165
+ - [Upgrading to the warehouse grammar](https://github.com/mnmal-ai/substrate/blob/main/docs/upgrading-to-warehouse-grammar.md)
165
166
  - [Plugin author guide](https://github.com/mnmal-ai/substrate/blob/main/docs/plugin-author-guide.md)
166
167
 
167
168
  ## License
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
2
- import { Dt as buildContext, Pt as WS_REASON_SERVER_RESTART, Q as effectiveFilterOperators, Tt as HttpBridgeClient, Y as MemoryEdgesStore, _ as AUDIT_EVENT_TYPE, _t as unregisterExtensionOperator, a as composeFromManifests, c as MemoryDataset, g as buildAuditRow, gt as registerExtensionOperator, h as SYSTEM_TYPE_DEFS, ht as listExtensionOperators, i as PluginLoadError, jt as parseAuthConfig, k as isReservedAutoCrudField, mt as getExtensionOperator, n as kernelMigrationTracking, o as DEFAULT_NAMESPACE, r as mountKernelRoute, s as compose, t as composeKernelPlugins, u as isStoreProfileName } from "./src-BMHI_rTJ.js";
2
+ import { A as isReservedAutoCrudField, Ft as HttpBridgeClient, Lt as buildContext, Vt as parseAuthConfig, Wt as WS_REASON_SERVER_RESTART, Z as MemoryEdgesStore, _ as AUDIT_EVENT_TYPE, _t as getExtensionOperator, a as composeFromManifests, bt as unregisterExtensionOperator, c as MemoryDataset, et as effectiveFilterOperators, g as buildAuditRow, h as SYSTEM_TYPE_DEFS, i as PluginLoadError, n as kernelMigrationTracking, o as DEFAULT_NAMESPACE, r as mountKernelRoute, s as compose, t as composeKernelPlugins, u as isStoreProfileName, vt as listExtensionOperators, yt as registerExtensionOperator } from "./src-D55T3ZcP.js";
3
3
  import { a as adminClaimCapabilities, d as resolveDefaultKidPath, l as resolveAdminCredential, n as trimTrailingSlashes, r as ADMIN_CAPABILITIES, s as makeAuthorizationProvider, t as parsePositiveInt, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
4
- import { D as isActiveAdminKeyRow, E as describeGrant, L as encodeList, M as grantEntryError, T as SYSTEM_NAMESPACE, v as grantEntriesConfer } from "./src-Bi3NhEsT.js";
5
- import { T as DEFAULT_FILTER_WRITE_LIMITS } from "./src-DWqzrm3O.js";
6
- import { C as diagnose, S as DIAGNOSE_CHECKS, _ as SKIPPABLE_STEPS, b as planOnboarding, h as CURRENT_MARK, i as tokenAudience, v as STEP_MARKS, x as requiredOutstanding, y as currentStep } from "./src-CHND7-Pm.js";
7
- import { _ as runDerivedMigrations, d as assertNotMigrating, g as pendingMigrations, m as deriveListIndexMigration, p as assertTablesLayout, t as PgDataset, v as runMigrations } from "./src-DHLw3eCn.js";
8
- import { t as PgEdgesStore } from "./pg-edges-store-De5F1tUf.js";
9
- import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore } from "./src--uyAqssS.js";
10
- import { et as memberKey } from "./plugin-Dpa_Y7Ep.js";
4
+ import { D as isActiveAdminKeyRow, E as describeGrant, L as encodeList, M as grantEntryError, T as SYSTEM_NAMESPACE, v as grantEntriesConfer } from "./src-DR_hUj2p.js";
5
+ import { L as DEFAULT_FILTER_WRITE_LIMITS } from "./src-CdbUzLhB.js";
6
+ import { C as diagnose, S as DIAGNOSE_CHECKS, _ as SKIPPABLE_STEPS, b as planOnboarding, h as CURRENT_MARK, i as tokenAudience, v as STEP_MARKS, x as requiredOutstanding, y as currentStep } from "./src-DV6PcXym.js";
7
+ import { _ as pendingMigrations, f as assertNotMigrating, h as deriveListIndexMigration, m as assertTablesLayout, n as PgDataset, t as PgIdempotencyStore, v as runDerivedMigrations, y as runMigrations } from "./src-BcuotITf.js";
8
+ import { t as PgEdgesStore } from "./pg-edges-store-D7etFxNK.js";
9
+ import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore } from "./src-DZfgQ2gR.js";
10
+ import { et as memberKey } from "./plugin-DcoJGEMM.js";
11
11
  import { existsSync, linkSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
12
12
  import { homedir } from "node:os";
13
13
  import { basename, dirname, join, resolve } from "node:path";
@@ -17,6 +17,7 @@ import WebSocket$1 from "ws";
17
17
  import { readFile, readdir, stat, statfs } from "node:fs/promises";
18
18
  import postgres from "postgres";
19
19
  import { pathToFileURL } from "node:url";
20
+ import { constants } from "node:http2";
20
21
  import compressPlugin from "@fastify/compress";
21
22
  import corsPlugin from "@fastify/cors";
22
23
  import websocketPlugin from "@fastify/websocket";
@@ -138,60 +139,6 @@ function makeDiskGuard(opts) {
138
139
  };
139
140
  }
140
141
 
141
- //#endregion
142
- //#region ../../packages/substrate-dataset-pg/src/pg-idempotency-store.ts
143
- var PgIdempotencyStore = class {
144
- #sql;
145
- constructor(options) {
146
- this.#sql = options.sql;
147
- }
148
- async get(key) {
149
- const row = (await this.#sql`
150
- SELECT envelope
151
- FROM idempotency
152
- WHERE key = ${key}
153
- AND expires_at > now()
154
- LIMIT 1
155
- `)[0];
156
- if (row === void 0) return void 0;
157
- return row.envelope;
158
- }
159
- async put(key, envelope, ttlMs) {
160
- const sql = this.#sql;
161
- await sql`
162
- INSERT INTO idempotency (key, envelope, expires_at)
163
- VALUES (
164
- ${key},
165
- ${sql.json(envelope)},
166
- now() + (${ttlMs}::bigint || ' milliseconds')::interval
167
- )
168
- ON CONFLICT (key) DO UPDATE SET
169
- -- The envelope is IMMUTABLE while the entry is live: an idempotency key
170
- -- must resolve to one stable answer for its whole window, or two
171
- -- retries of the same request can get different results, which is the
172
- -- thing the store exists to prevent.
173
- --
174
- -- Once it has EXPIRED that rule inverts. The dedupe window closed, the
175
- -- mutation legitimately re-executed, and the new envelope is the real
176
- -- result. Keeping the old one would hand back a stale answer wrapped in
177
- -- a fresh TTL, to a caller who was never deduped at all.
178
- envelope = CASE
179
- WHEN idempotency.expires_at <= now() THEN EXCLUDED.envelope
180
- ELSE idempotency.envelope
181
- END,
182
- -- GREATEST rather than a WHERE guard: extends a live window, never
183
- -- shortens it, and takes the new value outright when the old is past.
184
- expires_at = GREATEST(idempotency.expires_at, EXCLUDED.expires_at)
185
- `;
186
- }
187
- async reapExpired() {
188
- return { deleted: (await this.#sql`
189
- DELETE FROM idempotency
190
- WHERE expires_at <= now()
191
- `).count };
192
- }
193
- };
194
-
195
142
  //#endregion
196
143
  //#region src/pg-client.ts
197
144
  function formatPgNotice(notice) {
@@ -210,9 +157,16 @@ function pgNoticeOptions(write = (s) => void process.stderr.write(s)) {
210
157
  * Open a pg client with substrate's standard options. Prefer this over calling
211
158
  * `postgres()` directly so NOTICE routing stays consistent across `serve`, the
212
159
  * admin CLI, `substrate federate`, and the migrate CLI.
160
+ *
161
+ * `queueTimeoutMs` bounds how long a query, transaction or reserve waits for a
162
+ * free connection before it rejects with the driver's `QUEUE_TIMEOUT`. Unset,
163
+ * it waits as long as it takes.
213
164
  */
214
- function openSql(url) {
215
- return postgres(url, pgNoticeOptions());
165
+ function openSql(url, opts = {}) {
166
+ return postgres(url, {
167
+ ...pgNoticeOptions(),
168
+ ...opts.queueTimeoutMs !== void 0 ? { queue_timeout: opts.queueTimeoutMs / 1e3 } : {}
169
+ });
216
170
  }
217
171
 
218
172
  //#endregion
@@ -1794,7 +1748,7 @@ async function closeQuietly(sql) {
1794
1748
 
1795
1749
  //#endregion
1796
1750
  //#region package.json
1797
- var version = "1.0.0-alpha.16";
1751
+ var version = "1.0.0-alpha.18";
1798
1752
 
1799
1753
  //#endregion
1800
1754
  //#region src/plugin-manifest.ts
@@ -2190,6 +2144,8 @@ async function applySubstrateResponse(reply, res) {
2190
2144
  * caller's intent is ambiguous, fail loudly.
2191
2145
  */
2192
2146
  const DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
2147
+ /** Streams one HTTP/2 connection may have open at once. Node's default is unbounded. */
2148
+ const H2_MAX_CONCURRENT_STREAMS = 128;
2193
2149
  const DEFAULT_WS_MAX_PAYLOAD = 1 << 20;
2194
2150
  const DEFAULT_WS_MAX_BUFFERED = 16 << 20;
2195
2151
  /** How long a buffer-full socket gets to finish its close handshake before it is dropped. */
@@ -2218,15 +2174,19 @@ var FastifySubstrateServer = class {
2218
2174
  ...bodyLimit !== void 0 ? { bodyLimit } : {}
2219
2175
  };
2220
2176
  if (tls) {
2221
- const httpsOptions = {
2222
- cert: tls.cert,
2223
- key: tls.key,
2224
- ...tls.ca !== void 0 ? { ca: tls.ca } : {}
2225
- };
2226
2177
  this.fastify = Fastify({
2227
2178
  ...common,
2228
- https: httpsOptions
2179
+ http2: true,
2180
+ https: {
2181
+ allowHTTP1: true,
2182
+ cert: tls.cert,
2183
+ key: tls.key,
2184
+ ...tls.ca !== void 0 ? { ca: tls.ca } : {},
2185
+ settings: { maxConcurrentStreams: H2_MAX_CONCURRENT_STREAMS }
2186
+ }
2229
2187
  });
2188
+ this.fastify.server.requestTimeout = requestTimeout;
2189
+ if (requestTimeout > 0) boundH2Requests(this.fastify, requestTimeout);
2230
2190
  } else this.fastify = Fastify(common);
2231
2191
  this.fastify.addContentTypeParser("application/octet-stream", { parseAs: "buffer" }, (_req, body, done) => done(null, body));
2232
2192
  this.fastify.addContentTypeParser("application/vnd.substrate.pack", { parseAs: "buffer" }, (_req, body, done) => done(null, body));
@@ -2600,6 +2560,25 @@ function registerWsRoute(fastify, path, handler, inFlightWs, onHandlerError, max
2600
2560
  wsHandler
2601
2561
  });
2602
2562
  }
2563
+ /**
2564
+ * HTTP/2 has no `requestTimeout`: give each h2 request `ms` to arrive in full
2565
+ * (headers and body), then reset its stream. The clock stops once the handler
2566
+ * runs, so a streamed response is not bounded by it.
2567
+ */
2568
+ function boundH2Requests(fastify, ms) {
2569
+ const timers = /* @__PURE__ */ new WeakMap();
2570
+ fastify.addHook("onRequest", async (req) => {
2571
+ const stream = req.raw.stream;
2572
+ if (stream === void 0) return;
2573
+ const timer = setTimeout(() => stream.close(constants.NGHTTP2_CANCEL), ms);
2574
+ timers.set(req.raw, timer);
2575
+ stream.once("close", () => clearTimeout(timer));
2576
+ });
2577
+ fastify.addHook("preHandler", async (req, reply) => {
2578
+ clearTimeout(timers.get(req.raw));
2579
+ if (req.raw.stream?.closed === true) return reply.code(408).send();
2580
+ });
2581
+ }
2603
2582
 
2604
2583
  //#endregion
2605
2584
  //#region ../../packages/substrate-sentinel-client/src/client.ts
@@ -2878,7 +2857,7 @@ async function wireStore(storeSpec, fieldDefLookupFor, typeDefLookupFor, diskGua
2878
2857
  close: null
2879
2858
  };
2880
2859
  if (storeSpec.startsWith("postgres://") || storeSpec.startsWith("postgresql://")) {
2881
- const sql = openSql(storeSpec);
2860
+ const sql = openSql(storeSpec, statementTimeoutMs !== void 0 ? { queueTimeoutMs: statementTimeoutMs } : {});
2882
2861
  try {
2883
2862
  await runMigrations(sql);
2884
2863
  } catch (err) {
@@ -1,4 +1,4 @@
1
- import { Mn as Row, f as PackEnvelope, m as Schema, xn as EdgeRef } from "./schema-B--_bHjn.js";
1
+ import { On as EdgeRef, f as PackEnvelope, m as Schema, zn as Row } from "./schema-B5WBO8yh.js";
2
2
  //#region ../../packages/substrate-types/src/bridge.d.ts
3
3
  /**
4
4
  * Per-frame bucket sent to a bridge. Same shape as `QualifiedFrame` in the
@@ -1,21 +1,22 @@
1
1
  import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
2
- import { Qt as validateHardDeleteEnv, _ as AUDIT_EVENT_TYPE, et as loadSweepState, g as buildAuditRow, m as runInviteSweep, nt as saveSweepState, tt as runSweep, u as isStoreProfileName, v as INVITE_TYPE } from "./src-BMHI_rTJ.js";
2
+ import { _ as AUDIT_EVENT_TYPE, cn as validateHardDeleteEnv, g as buildAuditRow, it as saveSweepState, m as runInviteSweep, nt as loadSweepState, rt as runSweep, u as isStoreProfileName, v as INVITE_TYPE } from "./src-D55T3ZcP.js";
3
3
  import { n as trimTrailingSlashes, s as makeAuthorizationProvider } from "./env-utils-CGNazUNt.js";
4
- import { L as encodeList, T as SYSTEM_NAMESPACE, f as coversNamespace, m as grantedIn, p as grantOf } from "./src-Bi3NhEsT.js";
5
- import "./src-DWqzrm3O.js";
6
- import { Y as AdminCliError, _ as openPgDataset, a as parseBridgeCreds, f as reportUnguardedIndexBuilds, g as version, i as MS_PER_DAY, m as startSentinelClient, n as resolvePluginDir, o as parseBridges, p as runDeferredIndexBuilds, s as parseEnv, t as bootStore, u as redactStoreSpec } from "./boot-store-HxCgbvNl.js";
7
- import { a as SubstrateClient, d as NetworkError, i as tokenAudience, n as resolveAgentCapabilities, p as AdminBackfillError, r as noRedirectFetch, t as createClientFromEnv, u as AuthError } from "./src-CHND7-Pm.js";
8
- import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-C6DSa_Na.js";
9
- import { w as tryWithPgAdvisoryLock } from "./src-DHLw3eCn.js";
10
- import { n as PgLexicalStore, r as PgEmbeddingsStore } from "./src--uyAqssS.js";
11
- import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
12
- import { homedir, hostname } from "node:os";
4
+ import { L as encodeList, T as SYSTEM_NAMESPACE, f as coversNamespace, m as grantedIn, p as grantOf } from "./src-DR_hUj2p.js";
5
+ import { F as EXPR_FUNCTIONS, I as EXPR_LIMITS, N as DATE_UNITS, P as EXPR_AGGREGATES } from "./src-CdbUzLhB.js";
6
+ import { Y as AdminCliError, _ as openPgDataset, a as parseBridgeCreds, f as reportUnguardedIndexBuilds, g as version, i as MS_PER_DAY, m as startSentinelClient, n as resolvePluginDir, o as parseBridges, p as runDeferredIndexBuilds, s as parseEnv, t as bootStore, u as redactStoreSpec } from "./boot-store-C8KrACZ5.js";
7
+ import { a as SubstrateClient, d as NetworkError, i as tokenAudience, n as resolveAgentCapabilities, p as AdminBackfillError, r as noRedirectFetch, t as createClientFromEnv, u as AuthError } from "./src-DV6PcXym.js";
8
+ import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-B-32wZGY.js";
9
+ import { T as tryWithPgAdvisoryLock } from "./src-BcuotITf.js";
10
+ import { n as PgLexicalStore, r as PgEmbeddingsStore } from "./src-DZfgQ2gR.js";
11
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
12
+ import { homedir, hostname, tmpdir } from "node:os";
13
13
  import { basename, dirname, join, resolve } from "node:path";
14
14
  import { createHash, generateKeyPairSync, randomBytes } from "node:crypto";
15
- import { pathToFileURL } from "node:url";
15
+ import { fileURLToPath, pathToFileURL } from "node:url";
16
16
  import { z } from "zod";
17
17
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
18
18
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
19
+ import { fork } from "node:child_process";
19
20
 
20
21
  //#region ../../node_modules/.pnpm/@mnmal-ai+surface-kit@0.17.1_ink@8.0.0_@types+react@19.3.0_react@19.3.1__react@19.3.1/node_modules/@mnmal-ai/surface-kit/dist/cells.js
21
22
  const graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
@@ -2163,7 +2164,7 @@ async function runInit(argv) {
2163
2164
  return 1;
2164
2165
  }
2165
2166
  if (!config.yes) try {
2166
- const { runRepl } = await import("./repl-2WfRPUb0.js");
2167
+ const { runRepl } = await import("./repl-SY8cLOZl.js");
2167
2168
  config = await runRepl(config);
2168
2169
  } catch (err) {
2169
2170
  if (err.message?.includes("User force closed")) return 130;
@@ -2455,8 +2456,134 @@ function makeAgentJwtProvider(env, audience) {
2455
2456
  return () => provider();
2456
2457
  }
2457
2458
 
2459
+ //#endregion
2460
+ //#region src/mcp/run-sandbox.ts
2461
+ /**
2462
+ * Runs agent-supplied script text in a sandboxed child process (Decision #642).
2463
+ *
2464
+ * The child runs under Node's permission model: it may read only its runner and
2465
+ * the script, and has no network, child processes, workers or environment. Each
2466
+ * ScriptContext call it makes is relayed to a real one from `runScript`, so the
2467
+ * read / dry-run / write modes, `maxWrites`, signing and the report are exactly
2468
+ * the CLI's.
2469
+ */
2470
+ const DEFAULT_RUN_TIMEOUT_MS = 6e4;
2471
+ /** Heap ceiling for one script's child, in MiB. */
2472
+ const CHILD_HEAP_MB = 256;
2473
+ const OPS = /* @__PURE__ */ new Set([
2474
+ "query",
2475
+ "queryAll",
2476
+ "recall",
2477
+ "schema",
2478
+ "mutate",
2479
+ "log"
2480
+ ]);
2481
+ /** The runner beside this module: `.js` in the built package, `.ts` when run from source. */
2482
+ function runnerPath() {
2483
+ const js = fileURLToPath(new URL("./script-runner.js", import.meta.url));
2484
+ return existsSync(js) ? js : fileURLToPath(new URL("./script-runner.ts", import.meta.url));
2485
+ }
2486
+ async function runSandboxed(source, opts) {
2487
+ const dir = mkdtempSync(join(tmpdir(), "substrate-run-"));
2488
+ const script = join(dir, "script.mts");
2489
+ writeFileSync(script, source);
2490
+ const runner = runnerPath();
2491
+ const timeoutMs = opts.timeoutMs ?? 6e4;
2492
+ try {
2493
+ return await runScript((s) => inChild(s, runner, script, timeoutMs), {
2494
+ client: opts.client,
2495
+ kid: opts.kid,
2496
+ ...opts.mode !== void 0 ? { mode: opts.mode } : {},
2497
+ ...opts.args !== void 0 ? { args: opts.args } : {},
2498
+ ...opts.maxWrites !== void 0 ? { maxWrites: opts.maxWrites } : {},
2499
+ ...opts.log !== void 0 ? { log: opts.log } : {}
2500
+ });
2501
+ } finally {
2502
+ rmSync(dir, {
2503
+ recursive: true,
2504
+ force: true
2505
+ });
2506
+ }
2507
+ }
2508
+ function inChild(s, runner, script, timeoutMs) {
2509
+ return new Promise((resolve, reject) => {
2510
+ const child = fork(runner, [], {
2511
+ execArgv: [
2512
+ "--permission",
2513
+ `--allow-fs-read=${runner}`,
2514
+ `--allow-fs-read=${script}`,
2515
+ `--max-old-space-size=${CHILD_HEAP_MB}`
2516
+ ],
2517
+ env: {},
2518
+ stdio: [
2519
+ "ignore",
2520
+ "ignore",
2521
+ "ignore",
2522
+ "ipc"
2523
+ ],
2524
+ serialization: "advanced"
2525
+ });
2526
+ let settled = false;
2527
+ const finish = (err, value) => {
2528
+ if (settled) return;
2529
+ settled = true;
2530
+ clearTimeout(timer);
2531
+ child.kill("SIGKILL");
2532
+ if (err !== null) reject(err);
2533
+ else resolve(value);
2534
+ };
2535
+ const timer = setTimeout(() => finish(/* @__PURE__ */ new Error(`script timed out after ${timeoutMs} ms`)), timeoutMs);
2536
+ child.on("error", (err) => finish(err));
2537
+ child.on("exit", (code, signal) => finish(/* @__PURE__ */ new Error(`script process exited (${signal ?? `code ${code}`}) before finishing`)));
2538
+ child.on("message", (m) => {
2539
+ if (m.type === "done") {
2540
+ if (m.ok === true) finish(null, m.result);
2541
+ else finish(new Error(m.error ?? "script failed"));
2542
+ return;
2543
+ }
2544
+ if (m.type !== "call" || m.id === void 0) return;
2545
+ const id = m.id;
2546
+ const reply = (r) => {
2547
+ if (!settled) child.send({
2548
+ type: "reply",
2549
+ id,
2550
+ ...r
2551
+ });
2552
+ };
2553
+ if (m.op === void 0 || !OPS.has(m.op)) {
2554
+ reply({
2555
+ ok: false,
2556
+ error: `unknown context call '${String(m.op)}'`
2557
+ });
2558
+ return;
2559
+ }
2560
+ const fn = s[m.op];
2561
+ Promise.resolve().then(() => fn(...m.input ?? [])).then((value) => reply({
2562
+ ok: true,
2563
+ value
2564
+ }), (err) => reply({
2565
+ ok: false,
2566
+ error: err instanceof Error ? err.message : String(err)
2567
+ }));
2568
+ });
2569
+ child.send({
2570
+ type: "start",
2571
+ script,
2572
+ kid: s.kid,
2573
+ mode: s.mode,
2574
+ args: { ...s.args }
2575
+ });
2576
+ });
2577
+ }
2578
+
2458
2579
  //#endregion
2459
2580
  //#region src/mcp/schema-overview.ts
2581
+ /**
2582
+ * A compact map of the federated schema for agents: every namespace's types,
2583
+ * each as one line of `field: type`, plus the mutations autoCRUD did not
2584
+ * generate. Enough to pick a type and write a query; a write contract is
2585
+ * still one scoped `schema { namespace, type }` away.
2586
+ */
2460
2587
  const NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
2461
2588
  const ENUM_VALUE = /^[A-Za-z0-9_./-]{1,40}$/;
2462
2589
  const MAX_ENUM_VALUES = 20;
@@ -2524,6 +2651,32 @@ function buildInstructions(overview) {
2524
2651
  const body = full.length <= INSTRUCTIONS_OVERVIEW_MAX ? `${overviewLegend}\n${full}` : `Type names only (the full overview is large; call \`schema\` with no arguments for fields):\n${JSON.stringify(Object.fromEntries(Object.entries(overview).map(([ns, o]) => [ns, Object.keys(o.types)])))}`;
2525
2652
  return `${CONVENTIONS}\n\nTypes on this server at session start:\n${body}`;
2526
2653
  }
2654
+ /** This binary's own catalogue: the fallback when the server publishes none. */
2655
+ const localExpressions = {
2656
+ functions: EXPR_FUNCTIONS,
2657
+ aggregates: EXPR_AGGREGATES,
2658
+ limits: EXPR_LIMITS,
2659
+ dateUnits: DATE_UNITS
2660
+ };
2661
+ /** The `expressions` section of an unscoped schema reply, or undefined when it has none. */
2662
+ function serverExpressions(schema) {
2663
+ const e = schema?.expressions;
2664
+ return Array.isArray(e?.functions) && Array.isArray(e?.aggregates) && Array.isArray(e?.dateUnits) && e?.limits ? e : void 0;
2665
+ }
2666
+ /** The expression catalogue as compact lines for the no-args overview: one per function, then aggregates, limits and date units. */
2667
+ function expressionLines(c) {
2668
+ return [
2669
+ ...c.functions.map((f) => {
2670
+ const args = f.args === "variadic" ? "..." : f.args.join(", ");
2671
+ return `${f.name}(${args}) → ${f.returns}: ${f.description}`;
2672
+ }),
2673
+ `aggregates: ${c.aggregates.join(", ")}`,
2674
+ `limits: maxDepth ${c.limits.maxDepth}, maxNodesPerExpr ${c.limits.maxNodesPerExpr}, maxNodesPerFrame ${c.limits.maxNodesPerFrame}`,
2675
+ `dateUnits: ${c.dateUnits.join(", ")}`
2676
+ ];
2677
+ }
2678
+ /** Said beside a catalogue that is this binary's own, which may differ from what the server accepts. */
2679
+ const LOCAL_EXPRESSIONS_NOTE = "The server published no expression catalogue (GET /substrate/v1/schema), so this is the local binary's; the server may accept a different set.";
2527
2680
 
2528
2681
  //#endregion
2529
2682
  //#region src/mcp/server.ts
@@ -2675,21 +2828,43 @@ async function getSubstrate(endpoint, path) {
2675
2828
  async function recall(endpoint, body) {
2676
2829
  return postSubstrate(endpoint, "/substrate/v1/recall", body, "parsedError");
2677
2830
  }
2831
+ /** The server's expression catalogue, or undefined when it publishes none (an older server, or no default namespace). */
2832
+ async function expressionsOf(endpoint) {
2833
+ try {
2834
+ return serverExpressions(await getSubstrate(endpoint, "/substrate/v1/schema"));
2835
+ } catch {
2836
+ return;
2837
+ }
2838
+ }
2678
2839
  function createSchemaHandler(endpoint) {
2679
2840
  return async (args) => {
2680
2841
  const ns = args?.namespace;
2681
2842
  const type = args?.type;
2682
2843
  const shape = args?.shape;
2683
2844
  if ((ns === void 0 || ns === "") && args?.full !== true) try {
2684
- const federated = await getSubstrate(endpoint, "/substrate/v1/federated-schema");
2845
+ const [federated, catalogue] = await Promise.all([getSubstrate(endpoint, "/substrate/v1/federated-schema"), expressionsOf(endpoint)]);
2685
2846
  return okResult({
2686
2847
  legend: overviewLegend,
2687
- overview: schemaOverview(federated)
2848
+ overview: schemaOverview(federated),
2849
+ expressions: expressionLines(catalogue ?? localExpressions),
2850
+ ...catalogue === void 0 ? { expressionsNote: LOCAL_EXPRESSIONS_NOTE } : {}
2688
2851
  });
2689
2852
  } catch (err) {
2690
2853
  return errorResult(toMessage(err));
2691
2854
  }
2692
2855
  let path = "/substrate/v1/federated-schema";
2856
+ if ((ns === void 0 || ns === "") && args?.full === true) try {
2857
+ const [federated, catalogue] = await Promise.all([getSubstrate(endpoint, path), expressionsOf(endpoint)]);
2858
+ return okResult({
2859
+ ...federated,
2860
+ $expressions: catalogue ?? {
2861
+ ...localExpressions,
2862
+ note: "The server published no expression catalogue (GET /substrate/v1/schema), so this is the local binary's; the server may accept a different set."
2863
+ }
2864
+ });
2865
+ } catch (err) {
2866
+ return errorResult(toMessage(err));
2867
+ }
2693
2868
  if (ns !== void 0 && ns !== "") {
2694
2869
  if (type !== void 0 && type !== "") {
2695
2870
  const q = shape !== void 0 && shape !== "" ? `?shape=${encodeURIComponent(shape)}` : "";
@@ -2807,6 +2982,33 @@ function createDropTypeHandler(endpoint) {
2807
2982
  }
2808
2983
  };
2809
2984
  }
2985
+ /**
2986
+ * `run`: one script, sandboxed (Decision #642), signed as this MCP server's
2987
+ * agent. The client is made on first use and kept: building it reads the key.
2988
+ */
2989
+ function createRunHandler(env = process.env) {
2990
+ let signed;
2991
+ return async (input) => {
2992
+ try {
2993
+ signed ??= createClientFromEnv({ env });
2994
+ if (signed.kid === null) return errorResult("run needs an agent identity: set SUBSTRATE_AGENT_KEY_ID and SUBSTRATE_AGENT_KEY_PATH");
2995
+ const report = await runSandboxed(input.script, {
2996
+ client: signed.client,
2997
+ kid: signed.kid,
2998
+ mode: input.mode ?? "read",
2999
+ args: input.args ?? {},
3000
+ maxWrites: input.maxWrites ?? 50,
3001
+ log: () => {}
3002
+ });
3003
+ return report.ok ? okResult(report) : {
3004
+ ...okResult(report),
3005
+ isError: true
3006
+ };
3007
+ } catch (err) {
3008
+ return errorResult(toMessage(err));
3009
+ }
3010
+ };
3011
+ }
2810
3012
  function createMcpServer(endpoint, options = {}) {
2811
3013
  const server = new McpServer({
2812
3014
  name: "substrate",
@@ -2816,7 +3018,7 @@ function createMcpServer(endpoint, options = {}) {
2816
3018
  {
2817
3019
  name: "schema",
2818
3020
  config: {
2819
- description: "Fetch the Substrate schema. No args → a compact overview: every namespace's types, one line of `field: type` each, enough to write a query. `full: true` → the whole federated schema (large; rarely needed). SCOPED + CHEAP: pass `namespace` for one namespace, or `namespace` + `type` for a single type's write contract ({ fields, mutations }). Mine the scoped shape BEFORE a create/update so you send only declared fields — autoCRUD rejects undeclared fields with `unknown_field`. CHEAPER STILL: add `shape: \"fields\"` when you only need the type's field names and kinds — for an autoCRUD type the mutations restate the field block five times over, so the default answer costs about 6x the question.",
3021
+ description: "Fetch the Substrate schema. No args → a compact overview: every namespace's types, one line of `field: type` each, enough to write a query. `full: true` → the whole federated schema plus the full expression catalogue under `$expressions` (large; rarely needed). SCOPED + CHEAP: pass `namespace` for one namespace, or `namespace` + `type` for a single type's write contract ({ fields, mutations }). Mine the scoped shape BEFORE a create/update so you send only declared fields — autoCRUD rejects undeclared fields with `unknown_field`. CHEAPER STILL: add `shape: \"fields\"` when you only need the type's field names and kinds — for an autoCRUD type the mutations restate the field block five times over, so the default answer costs about 6x the question.",
2820
3022
  inputSchema: {
2821
3023
  namespace: z.string().min(1).optional().describe("Scope to one namespace, e.g. \"notes\". Omit for the full federated schema."),
2822
3024
  type: z.string().min(1).optional().describe("Scope to one type within `namespace`, e.g. \"Todo\" — returns its field defs + create/update param shapes. Requires `namespace`."),
@@ -2829,7 +3031,7 @@ function createMcpServer(endpoint, options = {}) {
2829
3031
  {
2830
3032
  name: "query",
2831
3033
  config: {
2832
- description: "Query Substrate. payload is a single frame object mapping qualified keys (<ns>/<Type>) to { params, fields }. ONE call can span multiple namespaces — e.g. { \"prices/Price\": {...}, \"products/Product\": {...} }. WALKS: a reference field is followed backwards with `_walk`, which names the inbound field as \"ns/Type.field\" (the schema overview marks it `←Type.field`). It filters in `where`, aggregates in `fields._agg`, or nests rows in `fields`. Example: orders with an item priced over 50, and their item count: { \"shop/Order\": { \"params\": { \"where\": { \"_walk\": { \"in\": \"shop/Item.order\", \"where\": { \"price\": { \"gt\": 50 } } } } }, \"fields\": { \"id\": true, \"_agg\": { \"items\": { \"in\": \"shop/Item.order\", \"count\": true } } } } }. `out: \"field\"` follows a reference forwards. A `_walk` takes `quantifier` \"any\" (default), \"none\" or \"all\", or `pick` one neighbour by { \"latest\": <date> }, { \"max\": <f> } or { \"min\": <f> }; an \"any\" walk binds `as: \"L\"`, and a later comparison reads it as { \"$ref\": \"L.price\", \"times\": 1.25 } (`$.f` is the seed row, `_agg.<name>` an aggregate; `times`/`plus` scale numbers, `plus` shifts a date in ms). `_agg` also takes avg/sum/min/max: <field> or latest: { by, value }, and in `where` compares beside a comparison: { \"_agg\": { \"in\": ..., \"count\": true }, \"gte\": 3 }. Frame params: `count: true` answers { count }; `aggregate: { name: { sum: \"price\" } }` with optional `bucket: { field, by: \"day\"|\"hour\" }` answers groups; `derive: { m: { diff|ratio: [\"_agg.x\", \"$.f\"] } }` (or one operand as it is, `{ value: \"_agg.x\" }`) is ordered by `orderBy: [{ \"$m\": \"desc\" }]`. Walks are query-only: subscribe, stream and mutate refuse them, as does a store without walks (walks_unsupported_store).",
3034
+ description: "Query Substrate. payload is a single frame object mapping qualified keys (<ns>/<Type>) to { params, fields }. ONE call can span multiple namespaces — e.g. { \"prices/Price\": {...}, \"products/Product\": {...} }. The expression functions for select, where.$expr, groupBy and having are listed by the `schema` tool. WALKS: a reference field is followed backwards with `_walk`, which names the inbound field as \"ns/Type.field\" (the schema overview marks it `←Type.field`). It filters in `where`, aggregates in `fields._agg`, or nests rows in `fields`. Example: orders with an item priced over 50, and their item count: { \"shop/Order\": { \"params\": { \"where\": { \"_walk\": { \"in\": \"shop/Item.order\", \"where\": { \"price\": { \"gt\": 50 } } } } }, \"fields\": { \"id\": true, \"_agg\": { \"items\": { \"in\": \"shop/Item.order\", \"count\": true } } } } }. `out: \"field\"` follows a reference forwards. A `_walk` takes `quantifier` \"any\" (default), \"none\" or \"all\", or `pick` one neighbour by { \"latest\": <date> }, { \"max\": <f> } or { \"min\": <f> }; an \"any\" walk binds `as: \"L\"`, and a later comparison reads it as { \"$ref\": \"L.price\", \"times\": 1.25 } (`$.f` is the seed row, `_agg.<name>` an aggregate; `times`/`plus` scale numbers, `plus` shifts a date in ms). `_agg` also takes avg/sum/min/max: <field> or latest: { by, value }, and in `where` compares beside a comparison: { \"_agg\": { \"in\": ..., \"count\": true }, \"gte\": 3 }. Frame params: `count: true` answers { count }; `aggregate: { name: { sum: \"price\" } }` answers one group, or one per key of `groupBy: { day: { dateTrunc: [{ \"lit\": \"day\" }, \"seenAt\"] } }` (a map of names to expressions; `having` filters the groups, `offset` skips them, `orderBy` names their outputs). `select: { m: { sub: [\"_agg.x\", \"price\"] } }` adds a computed value to each row, ordered by `orderBy: [{ \"m\": \"desc\" }]`. An expression is a field name, a literal, `{ \"lit\": \"text\" }` or `{ \"fn\": [args] }`. Walks are query-only: subscribe, stream and mutate refuse them, as does a store without walks (walks_unsupported_store).",
2833
3035
  inputSchema: { payload: payloadSchema("Query frame. Example: { \"default/Todo\": { \"params\": { \"limit\": 20 }, \"fields\": { \"id\": true, \"title\": true } } }") }
2834
3036
  },
2835
3037
  handler: createQueryHandler(endpoint)
@@ -2842,6 +3044,23 @@ function createMcpServer(endpoint, options = {}) {
2842
3044
  },
2843
3045
  handler: createMutateHandler(endpoint)
2844
3046
  },
3047
+ {
3048
+ name: "run",
3049
+ config: {
3050
+ description: "Run a short script against Substrate in one call: many queries and writes, one small report back. Use it when the work takes three or more dependent calls (ids passed from one call to the next, a census that must page, a join, recall-then-hydrate, a batch of writes chosen by a read). `script` is a JS/TS module whose default export is `async (s) => result`; type syntax is stripped. `s` has: kid, mode, args; query(frame) (throws on a refused frame); queryAll(key, { params, fields }) (pages to the end); recall({ query, namespace, type, k?, where?, row? }); schema(namespace?, type?); mutate(frame); log(...). Return counts, ids and short handles, not whole rows. Modes: \"read\" (default) refuses mutate; \"dry-run\" records each mutate payload in the report without sending it; \"write\" sends up to maxWrites frames (default 50; an array element counts one). Dry-run first, read report.mutations, then write. The script runs sandboxed: no files, network, processes or environment; it reaches only the store, as this agent. Report: { ok, kid, mode, result, error?, mutations[{ frame, applied, errors? }], warnings, stats }.",
3051
+ inputSchema: {
3052
+ script: z.string().min(1).describe("Module text, e.g. \"export default async (s) => (await s.queryAll('cortext/Todo', { params: { where: { status: { eq: 'open' } } }, fields: { id: true } })).length\""),
3053
+ args: z.record(z.string(), z.unknown()).optional().describe("Passed to the script as s.args."),
3054
+ mode: z.enum([
3055
+ "read",
3056
+ "dry-run",
3057
+ "write"
3058
+ ]).optional().describe("Default \"read\"."),
3059
+ maxWrites: z.number().int().nonnegative().optional().describe("Write mode: most mutate frames to send. Default 50.")
3060
+ }
3061
+ },
3062
+ handler: createRunHandler()
3063
+ },
2845
3064
  {
2846
3065
  name: "ask",
2847
3066
  config: {
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Mn as Row, W as QualifiedFrame, f as PackEnvelope, fn as ResolverStat, gn as SlowRequest, hn as RuntimeMetrics, m as Schema, mn as RuntimeErrors, pn as RuntimeErrorEntry, un as ProcessStat } from "./schema-B--_bHjn.js";
2
- import { A as and, B as SYSTEM_NAMESPACE, C as flattenGrant, D as parseGrantEntries, E as intersectGrants, F as TokenProviderOpts, G as resolveAdminCredential, H as isActiveAdminKeyRow, I as adminClaimCapabilities, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlAskResult, Y as NlAskRequest, _ as newlyGrantedPairs, a as denyAll, at as NlOutcome, b as capabilitiesFor, c as requireIdentity, d as KeyUpdateRefusal, dt as NlServedPack, f as checkRevocable, ft as NlTrailEvent, g as newlyGranted, h as grantEntriesConfer, i as allowVerbs, j as not, k as encodeList, l as requireNamespace, m as grantCovers, mt as NlWireEvent, n as row, o as denyVerbs, p as checkUpdatable, q as resolveDefaultKidPath, r as allowAll, s as requireCapability, t as applyRowFilters, u as KeyMutationRefusal, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-Dh57ShWL.js";
3
- import { s as SchemaDriftError } from "./index-EN-nQsX8.js";
1
+ import { W as QualifiedFrame, dn as ResolverStat, f as PackEnvelope, fn as RuntimeErrorEntry, hn as SlowRequest, ln as ProcessStat, m as Schema, mn as RuntimeMetrics, pn as RuntimeErrors, zn as Row } from "./schema-B5WBO8yh.js";
2
+ import { A as and, B as SYSTEM_NAMESPACE, C as flattenGrant, D as parseGrantEntries, E as intersectGrants, F as TokenProviderOpts, G as resolveAdminCredential, H as isActiveAdminKeyRow, I as adminClaimCapabilities, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlAskResult, Y as NlAskRequest, _ as newlyGrantedPairs, a as denyAll, at as NlOutcome, b as capabilitiesFor, c as requireIdentity, d as KeyUpdateRefusal, dt as NlServedPack, f as checkRevocable, ft as NlTrailEvent, g as newlyGranted, h as grantEntriesConfer, i as allowVerbs, j as not, k as encodeList, l as requireNamespace, m as grantCovers, mt as NlWireEvent, n as row, o as denyVerbs, p as checkUpdatable, q as resolveDefaultKidPath, r as allowAll, s as requireCapability, t as applyRowFilters, u as KeyMutationRefusal, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-DHxnCnhA.js";
3
+ import { s as SchemaDriftError } from "./index-DKJXQ031.js";
4
4
  import { Signal } from "@preact/signals-core";
5
5
  //#region ../../packages/substrate-client/src/admin/surgery.d.ts
6
6
  type AdminDropCascade = 'refuse' | 'delete';
@@ -824,6 +824,11 @@ interface ScriptContext {
824
824
  }): Promise<Record<string, unknown>[]>;
825
825
  /** Recall hits, best first, through the `recall/Hit` frame. */
826
826
  recall(input: ScriptRecallInput): Promise<ScriptRecallHit[]>;
827
+ /**
828
+ * The federated schema, one namespace's schema, or one type's. Throws naming
829
+ * an unknown namespace or type.
830
+ */
831
+ schema(namespace?: string, type?: string): Promise<unknown>;
827
832
  /**
828
833
  * One mutate payload (one transaction). Returns null in `dry-run`, and throws
829
834
  * in `read`, past `maxWrites`, or when the server refuses any frame.
package/dist/client.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
2
2
  import { a as adminClaimCapabilities, c as makeTokenProvider, d as resolveDefaultKidPath, i as DEFAULT_CAPABILITIES, l as resolveAdminCredential, o as isEncryptedKey, r as ADMIN_CAPABILITIES, s as makeAuthorizationProvider, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
3
- import { A as expandFlat, C as not, D as isActiveAdminKeyRow, E as describeGrant, F as parseGrantEntries, I as decodeList, L as encodeList, M as grantEntryError, N as grantIsUniform, O as capabilitiesFor, P as intersectGrants, S as and, T as SYSTEM_NAMESPACE, _ as grantCovers, a as denyAll, b as newlyGrantedPairs, c as requireIdentity, g as checkUpdatable, h as checkRevocable, i as allowVerbs, j as flattenGrant, k as encodeGrant, l as requireNamespace, n as row, o as denyVerbs, r as allowAll, s as requireCapability, t as applyRowFilters, v as grantEntriesConfer, w as or, x as revokedAtIso, y as newlyGranted } from "./src-Bi3NhEsT.js";
4
- import { f as SchemaDriftError } from "./src-DWqzrm3O.js";
5
- import { C as diagnose, S as DIAGNOSE_CHECKS, _ as SKIPPABLE_STEPS, a as SubstrateClient, b as planOnboarding, c as reduceSubscribeRows, d as NetworkError, f as SubscribeError, g as ONBOARD_STEPS, h as CURRENT_MARK, i as tokenAudience, l as watchRows, m as BACKFILL_CHUNK, n as resolveAgentCapabilities, o as collectDiagnostics, p as AdminBackfillError, r as noRedirectFetch, s as createDefaultDiagnosticsSink, t as createClientFromEnv, u as AuthError, v as STEP_MARKS, w as reconcileIdentities, x as requiredOutstanding, y as currentStep } from "./src-CHND7-Pm.js";
6
- import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-C6DSa_Na.js";
3
+ import { A as expandFlat, C as not, D as isActiveAdminKeyRow, E as describeGrant, F as parseGrantEntries, I as decodeList, L as encodeList, M as grantEntryError, N as grantIsUniform, O as capabilitiesFor, P as intersectGrants, S as and, T as SYSTEM_NAMESPACE, _ as grantCovers, a as denyAll, b as newlyGrantedPairs, c as requireIdentity, g as checkUpdatable, h as checkRevocable, i as allowVerbs, j as flattenGrant, k as encodeGrant, l as requireNamespace, n as row, o as denyVerbs, r as allowAll, s as requireCapability, t as applyRowFilters, v as grantEntriesConfer, w as or, x as revokedAtIso, y as newlyGranted } from "./src-DR_hUj2p.js";
4
+ import { f as SchemaDriftError } from "./src-CdbUzLhB.js";
5
+ import { C as diagnose, S as DIAGNOSE_CHECKS, _ as SKIPPABLE_STEPS, a as SubstrateClient, b as planOnboarding, c as reduceSubscribeRows, d as NetworkError, f as SubscribeError, g as ONBOARD_STEPS, h as CURRENT_MARK, i as tokenAudience, l as watchRows, m as BACKFILL_CHUNK, n as resolveAgentCapabilities, o as collectDiagnostics, p as AdminBackfillError, r as noRedirectFetch, s as createDefaultDiagnosticsSink, t as createClientFromEnv, u as AuthError, v as STEP_MARKS, w as reconcileIdentities, x as requiredOutstanding, y as currentStep } from "./src-DV6PcXym.js";
6
+ import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-B-32wZGY.js";
7
7
 
8
8
  export { ADMIN_CAPABILITIES, AdminBackfillError, AuthError, BACKFILL_CHUNK, CURRENT_MARK, DEFAULT_CAPABILITIES, DEFAULT_MAX_WRITES, DIAGNOSE_CHECKS, NetworkError, ONBOARD_STEPS, SKIPPABLE_STEPS, STEP_MARKS, SYSTEM_NAMESPACE, SchemaDriftError, SubscribeError, SubstrateClient, adminClaimCapabilities, allowAll, allowVerbs, and, applyRowFilters, capabilitiesFor, checkRevocable, checkUpdatable, collectDiagnostics, createClientFromEnv, createDefaultDiagnosticsSink, currentStep, decodeList, denyAll, denyVerbs, describeGrant, diagnose, encodeGrant, encodeList, expandFlat, flattenGrant, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, intersectGrants, isActiveAdminKeyRow, isEncryptedKey, makeAuthorizationProvider, makeTokenProvider, newlyGranted, newlyGrantedPairs, noRedirectFetch, not, or, parseGrantEntries, planOnboarding, reconcileIdentities, reduceSubscribeRows, requireCapability, requireIdentity, requireNamespace, requiredOutstanding, resolveAdminCredential, resolveAgentCapabilities, resolveDefaultKeyPath, resolveDefaultKidPath, revokedAtIso, row, runScript, tokenAudience, watchRows };