@mnmal-ai/substrate 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (53) hide show
  1. package/README.md +64 -14
  2. package/dist/boot-store-Dz6PGwNY.js +4079 -0
  3. package/dist/{runtime-metrics-DwpDJ8vz.d.ts → bridge-BeVye_Oj.d.ts} +2 -87
  4. package/dist/cli-CH7M6ZTQ.js +3383 -0
  5. package/dist/client.browser.js +2485 -0
  6. package/dist/client.d.ts +273 -135
  7. package/dist/client.js +6 -6
  8. package/dist/cluster-worker.js +0 -1
  9. package/dist/{content-type-C7T28xNb.js → content-type-wLljot5M.js} +0 -1
  10. package/dist/{env-utils-CGNazUNt.js → env-utils-s25Z1YSA.js} +0 -1
  11. package/dist/{errors-D4vKuwz8.d.ts → errors-CoHLKAX0.d.ts} +44 -4
  12. package/dist/{fake-DUVtKVSE.js → fake-DdXtb-m8.js} +0 -1
  13. package/dist/{index-D7mSOFlM.d.ts → index-D7XRAGC6.d.ts} +7 -11
  14. package/dist/msgpackr-Dq18g6Ds.js +16 -0
  15. package/dist/node-version-BtK_Nq6z.js +32 -0
  16. package/dist/pack.d.ts +75 -11
  17. package/dist/pack.js +4 -4
  18. package/dist/pg-edges-store-Dnaxesmy.js +443 -0
  19. package/dist/{plugin-QuJN9pG_.js → plugin-BIz4Pr5-.js} +132 -8
  20. package/dist/proposals-bootstrap.js +6 -5
  21. package/dist/proposals.config.schema.json +5 -0
  22. package/dist/proposals.d.ts +17 -5
  23. package/dist/proposals.default-config.json +2 -1
  24. package/dist/proposals.js +2 -3
  25. package/dist/recall-bootstrap.js +5 -4
  26. package/dist/recall.config.schema.json +6 -0
  27. package/dist/recall.d.ts +35 -6
  28. package/dist/recall.js +2 -3
  29. package/dist/{repl-C52wyfMs.js → repl-BUkd9DPZ.js} +65 -33
  30. package/dist/{row-ByLFE2Wx.d.ts → row-aEWVHEsf.d.ts} +92 -12
  31. package/dist/run-Cu9w5Y10.js +2435 -0
  32. package/dist/{plugin-t2g2wX0b.d.ts → schema-DwnXxdjk.d.ts} +1293 -63
  33. package/dist/script-A9dxMRZA.js +143 -0
  34. package/dist/script-runner.js +77 -0
  35. package/dist/sdk.d.ts +227 -38
  36. package/dist/sdk.js +5 -110
  37. package/dist/semver-D_zdq0hi.js +17 -0
  38. package/dist/{src-DWm0iA88.js → src--accZ5Ka.js} +188 -87
  39. package/dist/{src-DMzc3HfW.js → src-BNdhH_Hx.js} +745 -851
  40. package/dist/{src-CG7giuHr.js → src-BQnDrs_E.js} +793 -75
  41. package/dist/{src-BLgbLq2k.js → src-B_kHkbsr.js} +780 -330
  42. package/dist/src-BbCUeMsI.js +7723 -0
  43. package/dist/{src-CHp3QyqB.js → src-BmJD4ScT.js} +9215 -3376
  44. package/dist/{row-DZ0Fnpc6.js → src-DmiUWOLp.js} +2 -1
  45. package/dist/substrate-admin.js +17 -782
  46. package/dist/substrate.js +4 -5487
  47. package/dist/testing.d.ts +730 -53
  48. package/dist/testing.js +20 -163
  49. package/dist/{ws-C72iVS5T.d.ts → ws-DJaKruX-.d.ts} +4 -5
  50. package/package.json +26 -26
  51. package/dist/dataset-BQ8egGl5.js +0 -1535
  52. package/dist/schema-g4FQLr0V.d.ts +0 -433
  53. package/dist/src-CXKnqeTW.js +0 -2339
package/dist/testing.js CHANGED
@@ -1,7 +1,8 @@
1
- import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
2
- import { N as MemoryEdgesStore, P as loadPlugins, at as WS_REASON_SERVER_RESTART, c as MemoryDataset, rt as signHs256, s as compose } from "./src-CHp3QyqB.js";
3
- import { t as FakeEmbedder } from "./fake-DUVtKVSE.js";
4
- import { randomUUID } from "node:crypto";
1
+ import { Ht as signHs256, Q as loadPlugins, Wt as WS_REASON_SERVER_RESTART, Z as MemoryEdgesStore, c as MemoryDataset, s as compose } from "./src-BmJD4ScT.js";
2
+ import "./src-B_kHkbsr.js";
3
+ import { h as deriveListIndexMigration, n as PgDataset, v as runDerivedMigrations, y as runMigrations } from "./src-BbCUeMsI.js";
4
+ import { t as PgEdgesStore } from "./pg-edges-store-Dnaxesmy.js";
5
+ import { t as FakeEmbedder } from "./fake-DdXtb-m8.js";
5
6
  import postgres from "postgres";
6
7
 
7
8
  //#region ../../packages/substrate-dataset-pg/src/testing.ts
@@ -263,110 +264,21 @@ async function preparePgTestSchema(url, opts) {
263
264
  if (warning !== void 0) (opts.warn ?? ((m) => void process.stderr.write(`${m}\n`)))(warning);
264
265
  return pgTestSchemaUrl(url, opts.packageName);
265
266
  }
266
-
267
- //#endregion
268
- //#region ../../packages/substrate-server-memory/src/memory-ws-connection.ts
269
- /**
270
- * In-process WebSocket pair. One end is the server-side `WsConnection`
271
- * handed to the user's `WsHandler`; the other is a `MemoryWsClient` returned
272
- * to test code so it can drive the connection without opening a socket.
273
- *
274
- * Per §4.8 transport symmetry, upgrade metadata (path, headers, query, params)
275
- * rides on `SubstrateRequest`, not on `WsConnection`. The pair only needs an
276
- * `id` — the caller (`MemorySubstrateServer`) builds the `SubstrateRequest` separately.
277
- *
278
- * Frames are normalised to Buffer on delivery so handlers see the same shape
279
- * they would over a real WS (the `WsConnection.onMessage` signature is
280
- * `(frame: Buffer) => void`). `send()` accepts Buffer / Uint8Array / string on
281
- * both sides and normalises before dispatch.
282
- *
283
- * Close semantics:
284
- * - First close from either side transitions the pair to closed and fires
285
- * both sides' onClose callbacks synchronously with the provided code.
286
- * - Subsequent close() calls are no-ops (no duplicate events).
287
- * - send() on a closed endpoint throws a named error — callers that race
288
- * a close against a send should handle this, mirroring real WS behaviour
289
- * where the underlying socket may have shut down mid-write.
290
- */
291
267
  /**
292
- * @internal — thrown when sending on a closed in-memory WS pair. Treat as
293
- * package-private.
268
+ * A `createSchema` for `preparePgTestSchema` that drops and recreates the
269
+ * schema, so every run builds its store from an empty database.
294
270
  */
295
- var WsClosedError = class extends Error {
296
- constructor() {
297
- super("WebSocket is closed");
298
- this.name = "WsClosedError";
271
+ async function recreatePgTestSchema(url, schema) {
272
+ const sql = postgres(url, {
273
+ max: 1,
274
+ onnotice: () => {}
275
+ });
276
+ try {
277
+ await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
278
+ await sql.unsafe(`CREATE SCHEMA "${schema}"`);
279
+ } finally {
280
+ await sql.end({ timeout: 5 });
299
281
  }
300
- };
301
- function toBuffer(frame) {
302
- if (typeof frame === "string") return Buffer.from(frame, "utf8");
303
- if (Buffer.isBuffer(frame)) return frame;
304
- return Buffer.from(frame);
305
- }
306
- /**
307
- * @internal — paired in-memory WS endpoints used by `MemorySubstrateServer`
308
- * for inject-style WS testing. Treat as package-private.
309
- */
310
- function createMemoryWsPair() {
311
- const serverSide = {
312
- messageListeners: [],
313
- closeListeners: []
314
- };
315
- const clientSide = {
316
- messageListeners: [],
317
- closeListeners: []
318
- };
319
- const state = { closed: false };
320
- const closePair = (code) => {
321
- if (state.closed) return;
322
- state.closed = true;
323
- const s = serverSide.closeListeners.slice();
324
- const c = clientSide.closeListeners.slice();
325
- for (const cb of s) try {
326
- cb(code);
327
- } catch {}
328
- for (const cb of c) try {
329
- cb(code);
330
- } catch {}
331
- };
332
- return {
333
- server: {
334
- id: randomUUID(),
335
- send(frame) {
336
- if (state.closed) throw new WsClosedError();
337
- const buf = toBuffer(frame);
338
- for (const cb of clientSide.messageListeners.slice()) cb(buf);
339
- },
340
- onMessage(cb) {
341
- serverSide.messageListeners.push(cb);
342
- },
343
- onClose(cb) {
344
- serverSide.closeListeners.push(cb);
345
- },
346
- close(code, _reason) {
347
- closePair(code);
348
- }
349
- },
350
- client: {
351
- send(frame) {
352
- if (state.closed) throw new WsClosedError();
353
- const buf = toBuffer(frame);
354
- for (const cb of serverSide.messageListeners.slice()) cb(buf);
355
- },
356
- onMessage(cb) {
357
- clientSide.messageListeners.push(cb);
358
- },
359
- onClose(cb) {
360
- clientSide.closeListeners.push(cb);
361
- },
362
- close(code, _reason) {
363
- closePair(code);
364
- },
365
- get closed() {
366
- return state.closed;
367
- }
368
- }
369
- };
370
282
  }
371
283
 
372
284
  //#endregion
@@ -433,12 +345,6 @@ function paramName(seg) {
433
345
 
434
346
  //#endregion
435
347
  //#region ../../packages/substrate-server-memory/src/memory-server.ts
436
- var UnknownWsPathError = class extends Error {
437
- constructor(path) {
438
- super(`No websocket route registered for path: ${path}`);
439
- this.name = "UnknownWsPathError";
440
- }
441
- };
442
348
  /**
443
349
  * @internal — thrown when `MemorySubstrateServer.start()` is called twice.
444
350
  * Re-exported from the package index; treat as package-private.
@@ -449,7 +355,7 @@ var AlreadyStartedError = class extends Error {
449
355
  this.name = "AlreadyStartedError";
450
356
  }
451
357
  };
452
- const JSON_HEADERS = Object.freeze({ "content-type": "application/json" });
358
+ const JSON_HEADERS = /* @__PURE__ */ Object.freeze({ "content-type": "application/json" });
453
359
  function jsonBody(obj) {
454
360
  return Buffer.from(JSON.stringify(obj), "utf8");
455
361
  }
@@ -483,7 +389,6 @@ function parseQuery(path) {
483
389
  }
484
390
  var MemorySubstrateServer = class {
485
391
  #routes = [];
486
- #wsRoutes = [];
487
392
  #inFlight = /* @__PURE__ */ new Set();
488
393
  #shutdownHooks = /* @__PURE__ */ new Set();
489
394
  #errorHook;
@@ -498,12 +403,6 @@ var MemorySubstrateServer = class {
498
403
  handler
499
404
  });
500
405
  }
501
- websocket(path, handler) {
502
- this.#wsRoutes.push({
503
- pattern: path,
504
- handler
505
- });
506
- }
507
406
  onError(hook) {
508
407
  this.#errorHook = hook;
509
408
  }
@@ -566,8 +465,7 @@ var MemorySubstrateServer = class {
566
465
  post: (path, handler) => this.route("POST", prefixed(path), handler),
567
466
  put: (path, handler) => this.route("PUT", prefixed(path), handler),
568
467
  delete: (path, handler) => this.route("DELETE", prefixed(path), handler),
569
- patch: (path, handler) => this.route("PATCH", prefixed(path), handler),
570
- websocket: (path, handler) => this.websocket(prefixed(path), handler)
468
+ patch: (path, handler) => this.route("PATCH", prefixed(path), handler)
571
469
  };
572
470
  }
573
471
  async inject(req) {
@@ -655,48 +553,7 @@ var MemorySubstrateServer = class {
655
553
  if (ownedController !== null) this.#inFlight.delete(ownedController);
656
554
  }
657
555
  }
658
- #reportWsError(err) {
659
- const error = err instanceof Error ? err : new Error(String(err));
660
- if (!this.#errorHook) return;
661
- try {
662
- this.#errorHook(error);
663
- } catch {}
664
- }
665
- connectWebsocket(path, headers = {}) {
666
- const parsed = parseQuery(path);
667
- let matched;
668
- let params = {};
669
- for (const entry of this.#wsRoutes) {
670
- const m = matchRoute(entry.pattern, parsed.pathname);
671
- if (m !== null) {
672
- matched = entry;
673
- params = m;
674
- break;
675
- }
676
- }
677
- if (!matched) throw new UnknownWsPathError(parsed.pathname);
678
- const substrateReq = {
679
- method: "GET",
680
- path: parsed.pathname,
681
- headers,
682
- query: parsed.query,
683
- params,
684
- body: null
685
- };
686
- const { server, client } = createMemoryWsPair();
687
- queueMicrotask(() => {
688
- try {
689
- const result = matched.handler(substrateReq, server);
690
- if (result && typeof result.then === "function") result.catch((err) => {
691
- this.#reportWsError(err);
692
- });
693
- } catch (err) {
694
- this.#reportWsError(err);
695
- }
696
- });
697
- return client;
698
- }
699
556
  };
700
557
 
701
558
  //#endregion
702
- export { AlreadyStartedError, FakeEmbedder, MemoryDataset, MemoryEdgesStore, MemorySubstrateServer, UnknownWsPathError, WsClosedError, announcePgGating, assertCannotWriteOutsideTestDatabases, assertNotSuperuser, assertTestDatabase, compose, createMemoryWsPair, interpretSuperuserProbe, loadPlugins, matchRoute, pgTestSchemaName, pgTestSchemaUrl, preparePgTestSchema, publicLeftoverWarning, reachFailureMessage, signHs256 };
559
+ export { AlreadyStartedError, FakeEmbedder, MemoryDataset, MemoryEdgesStore, MemorySubstrateServer, PgDataset, PgEdgesStore, announcePgGating, assertCannotWriteOutsideTestDatabases, assertNotSuperuser, assertTestDatabase, compose, deriveListIndexMigration, interpretSuperuserProbe, loadPlugins, matchRoute, pgTestSchemaName, pgTestSchemaUrl, preparePgTestSchema, publicLeftoverWarning, reachFailureMessage, recreatePgTestSchema, runDerivedMigrations, runMigrations, signHs256 };
@@ -1,6 +1,5 @@
1
- import { C as Id, _ as EdgesStore, h as EdgeRef, l as PackEnvelope, s as FieldInput } from "./schema-g4FQLr0V.js";
2
- import { c as BridgeClient } from "./runtime-metrics-DwpDJ8vz.js";
3
- import { lt as DatasetRegistry } from "./plugin-t2g2wX0b.js";
1
+ import { At as DatasetRegistry, En as EdgeRef, On as EdgesStore, Pn as Id, f as PackEnvelope, l as FieldInput } from "./schema-DwnXxdjk.js";
2
+ import { t as BridgeClient } from "./bridge-BeVye_Oj.js";
4
3
  //#region ../../packages/substrate-types/src/idempotency.d.ts
5
4
  interface IdempotencyStore {
6
5
  /**
@@ -121,12 +120,12 @@ interface WsResponseFrame {
121
120
  * Known values: `WS_REASON_SUBSCRIPTION_OVERLOADED` (queue-limit teardown),
122
121
  * `WS_REASON_SERVER_RESTART` (graceful shutdown). Absent on a cancel ack.
123
122
  * Stays `string` on the wire for forward compatibility — clients must
124
- * tolerate unknown tokens. Contract: docs/ws-subscription-contract.md.
123
+ * tolerate unknown tokens. Contract: docs/stream-contract.md.
125
124
  */
126
125
  reason?: string;
127
126
  }
128
127
  /**
129
- * Terminal-cause vocabulary (docs/ws-subscription-contract.md). The overload
128
+ * Terminal-cause vocabulary (docs/stream-contract.md). The overload
130
129
  * token is BOTH the `code` of the terminal `error` frame and the `reason` of
131
130
  * the following `end` frame — one token per condition, no second spelling.
132
131
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnmal-ai/substrate",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.21",
4
4
  "description": "Substrate — an agent-first typed-data server: the substrate and substrate-admin binaries, the built-in plugins and the SDK subpaths.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -9,6 +9,7 @@
9
9
  "directory": "apps/substrate"
10
10
  },
11
11
  "type": "module",
12
+ "sideEffects": false,
12
13
  "bin": {
13
14
  "substrate": "dist/substrate.js",
14
15
  "substrate-admin": "dist/substrate-admin.js"
@@ -23,40 +24,38 @@
23
24
  "dependencies": {
24
25
  "@fastify/compress": "^9.2.0",
25
26
  "@fastify/cors": "^11.3.0",
26
- "@fastify/websocket": "^11.3.1",
27
27
  "@mnmal-ai/holomap-clusterer": "0.2.1",
28
28
  "@modelcontextprotocol/sdk": "^1.32.0",
29
29
  "@preact/signals-core": "^1.14.4",
30
30
  "fastify": "^5.12.5",
31
31
  "msgpackr": "^2.1.0",
32
- "postgres": "3.4.9",
32
+ "postgres": "4.1.0",
33
33
  "semver": "^7.8.5",
34
- "ws": "^8.22.0",
35
- "zod": "^4.6.5"
34
+ "zod": "^4.6.7"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@inquirer/prompts": "^8.7.2",
39
- "@mnmal-ai/substrate-bootstrap": "1.0.0-alpha.2",
40
- "@mnmal-ai/substrate-client": "1.0.0-alpha.2",
41
- "@mnmal-ai/substrate-compose": "1.0.0-alpha.2",
42
- "@mnmal-ai/substrate-config": "1.0.0-alpha.2",
43
- "@mnmal-ai/substrate-core": "1.0.0-alpha.2",
44
- "@mnmal-ai/substrate-dataset-memory": "1.0.0-alpha.2",
45
- "@mnmal-ai/substrate-dataset-pg": "1.0.0-alpha.2",
46
- "@mnmal-ai/substrate-embedder": "1.0.0-alpha.2",
47
- "@mnmal-ai/substrate-filter": "1.0.0-alpha.2",
48
- "@mnmal-ai/substrate-pack": "1.0.0-alpha.2",
49
- "@mnmal-ai/substrate-policy": "1.0.0-alpha.2",
50
- "@mnmal-ai/substrate-proposals": "1.0.0-alpha.2",
51
- "@mnmal-ai/substrate-recall": "1.0.0-alpha.2",
52
- "@mnmal-ai/substrate-sdk": "1.0.0-alpha.2",
53
- "@mnmal-ai/substrate-sentinel-client": "1.0.0-alpha.2",
54
- "@mnmal-ai/substrate-server-fastify": "1.0.0-alpha.2",
55
- "@mnmal-ai/substrate-server-memory": "1.0.0-alpha.2",
56
- "@mnmal-ai/substrate-types": "1.0.0-alpha.2",
38
+ "@mnmal-ai/substrate-bootstrap": "1.0.0-alpha.21",
39
+ "@mnmal-ai/substrate-client": "1.0.0-alpha.21",
40
+ "@mnmal-ai/substrate-compose": "1.0.0-alpha.21",
41
+ "@mnmal-ai/substrate-config": "1.0.0-alpha.21",
42
+ "@mnmal-ai/substrate-core": "1.0.0-alpha.21",
43
+ "@mnmal-ai/substrate-dataset-memory": "1.0.0-alpha.21",
44
+ "@mnmal-ai/substrate-dataset-pg": "1.0.0-alpha.21",
45
+ "@mnmal-ai/substrate-embedder": "1.0.0-alpha.21",
46
+ "@mnmal-ai/substrate-filter": "1.0.0-alpha.21",
47
+ "@mnmal-ai/substrate-pack": "1.0.0-alpha.21",
48
+ "@mnmal-ai/substrate-policy": "1.0.0-alpha.21",
49
+ "@mnmal-ai/substrate-proposals": "1.0.0-alpha.21",
50
+ "@mnmal-ai/substrate-recall": "1.0.0-alpha.21",
51
+ "@mnmal-ai/substrate-sdk": "1.0.0-alpha.21",
52
+ "@mnmal-ai/substrate-sentinel-client": "1.0.0-alpha.21",
53
+ "@mnmal-ai/substrate-server-fastify": "1.0.0-alpha.21",
54
+ "@mnmal-ai/substrate-server-memory": "1.0.0-alpha.21",
55
+ "@mnmal-ai/substrate-types": "1.0.0-alpha.21",
56
+ "@mnmal-ai/surface-core": "0.17.1",
57
57
  "@types/node": "^26.6.4",
58
58
  "@types/semver": "^7.5.0",
59
- "@types/ws": "^8.18.1",
60
59
  "msw": "^3.0.1",
61
60
  "tsdown": "^0.23.0",
62
61
  "tsx": "^4.23.15",
@@ -64,7 +63,7 @@
64
63
  "vitest": "^5.0.3"
65
64
  },
66
65
  "engines": {
67
- "node": ">=26.2.0"
66
+ "node": ">=26.13.1"
68
67
  },
69
68
  "exports": {
70
69
  "./sdk": {
@@ -73,6 +72,7 @@
73
72
  },
74
73
  "./client": {
75
74
  "types": "./dist/client.d.ts",
75
+ "browser": "./dist/client.browser.js",
76
76
  "import": "./dist/client.js"
77
77
  },
78
78
  "./pack": {
@@ -111,7 +111,7 @@
111
111
  ]
112
112
  },
113
113
  "scripts": {
114
- "build": "tsdown && node scripts/copy-plugin-configs.mjs",
114
+ "build": "tsdown && node scripts/copy-plugin-configs.mjs && node scripts/check-browser-bundle.mjs && node scripts/check-entry-sizes.mjs",
115
115
  "dev": "tsx src/bin/substrate.ts serve",
116
116
  "test": "vitest run",
117
117
  "check-types": "tsc -p tsconfig.json --noEmit",