@mnmal-ai/substrate 1.0.0-alpha.9 → 1.0.0-beta.2

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 (52) hide show
  1. package/README.md +32 -14
  2. package/dist/boot-store-DpnnxRpR.js +4086 -0
  3. package/dist/{runtime-metrics-DwpDJ8vz.d.ts → bridge-DnToJedN.d.ts} +2 -87
  4. package/dist/cli-COS16L1Z.js +3449 -0
  5. package/dist/client.browser.js +2507 -0
  6. package/dist/client.d.ts +222 -171
  7. package/dist/client.js +6 -7
  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-CuCMwPpb.d.ts} +46 -4
  12. package/dist/{fake-DUVtKVSE.js → fake-DdXtb-m8.js} +0 -1
  13. package/dist/{index-D7mSOFlM.d.ts → index-BI4KqFiR.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/{plugin-DpncES1p.js → plugin-DWagHKxm.js} +78 -8
  19. package/dist/proposals-bootstrap.js +6 -5
  20. package/dist/proposals.config.schema.json +5 -0
  21. package/dist/proposals.d.ts +17 -5
  22. package/dist/proposals.default-config.json +2 -1
  23. package/dist/proposals.js +2 -3
  24. package/dist/recall-bootstrap.js +3 -4
  25. package/dist/recall.d.ts +11 -12
  26. package/dist/recall.js +2 -3
  27. package/dist/{repl-DeKzfvNV.js → repl-C8ZgDrQ7.js} +52 -26
  28. package/dist/{row-SRhura12.d.ts → row-D0If4qif.d.ts} +91 -13
  29. package/dist/run-D-4sXpTu.js +2443 -0
  30. package/dist/{plugin-t2g2wX0b.d.ts → schema-aIkY8sR3.d.ts} +1293 -63
  31. package/dist/{script-C6DSa_Na.js → script-ByQ9pzhC.js} +54 -26
  32. package/dist/script-runner.js +78 -0
  33. package/dist/sdk.d.ts +236 -38
  34. package/dist/sdk.js +5 -110
  35. package/dist/semver-D_zdq0hi.js +17 -0
  36. package/dist/{src-BLgbLq2k.js → src-B_kHkbsr.js} +780 -330
  37. package/dist/{src-DjIuRjzF.js → src-C0ylwQFC.js} +10243 -4238
  38. package/dist/{src-C12EA0w9.js → src-D1PgjgUg.js} +179 -96
  39. package/dist/{src-DCy7Iy2l.js → src-Db3XI_pn.js} +900 -77
  40. package/dist/{row-DZ0Fnpc6.js → src-DmiUWOLp.js} +2 -1
  41. package/dist/src-DxD3iktO.js +8307 -0
  42. package/dist/{src-DiNTSaFk.js → src-FXO5JPyk.js} +686 -856
  43. package/dist/substrate-admin.js +17 -782
  44. package/dist/substrate.js +4 -5302
  45. package/dist/testing.d.ts +473 -96
  46. package/dist/testing.js +19 -165
  47. package/dist/{ws-C72iVS5T.d.ts → ws-DW8ng02H.d.ts} +4 -5
  48. package/package.json +26 -26
  49. package/dist/dataset-CqrqTYPz.js +0 -1535
  50. package/dist/pg-edges-store-KH_FQCxx.js +0 -381
  51. package/dist/schema-g4FQLr0V.d.ts +0 -433
  52. package/dist/src-BD27zeGF.js +0 -2339
package/dist/testing.js CHANGED
@@ -1,9 +1,7 @@
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-DjIuRjzF.js";
3
- import { a as runDerivedMigrations, o as runMigrations, r as deriveListIndexMigration, t as PgDataset } from "./src-BD27zeGF.js";
4
- import { t as PgEdgesStore } from "./pg-edges-store-KH_FQCxx.js";
5
- import { t as FakeEmbedder } from "./fake-DUVtKVSE.js";
6
- import { randomUUID } from "node:crypto";
1
+ import { Gt as WS_REASON_SERVER_RESTART, Q as loadPlugins, Ut as signHs256, Z as MemoryEdgesStore, c as MemoryDataset, s as compose } from "./src-C0ylwQFC.js";
2
+ import "./src-B_kHkbsr.js";
3
+ import { b as runMigrations, g as deriveListIndexMigration, n as PgEdgesStore, r as PgDataset, y as runDerivedMigrations } from "./src-DxD3iktO.js";
4
+ import { t as FakeEmbedder } from "./fake-DdXtb-m8.js";
7
5
  import postgres from "postgres";
8
6
 
9
7
  //#region ../../packages/substrate-dataset-pg/src/testing.ts
@@ -265,110 +263,21 @@ async function preparePgTestSchema(url, opts) {
265
263
  if (warning !== void 0) (opts.warn ?? ((m) => void process.stderr.write(`${m}\n`)))(warning);
266
264
  return pgTestSchemaUrl(url, opts.packageName);
267
265
  }
268
-
269
- //#endregion
270
- //#region ../../packages/substrate-server-memory/src/memory-ws-connection.ts
271
- /**
272
- * In-process WebSocket pair. One end is the server-side `WsConnection`
273
- * handed to the user's `WsHandler`; the other is a `MemoryWsClient` returned
274
- * to test code so it can drive the connection without opening a socket.
275
- *
276
- * Per §4.8 transport symmetry, upgrade metadata (path, headers, query, params)
277
- * rides on `SubstrateRequest`, not on `WsConnection`. The pair only needs an
278
- * `id` — the caller (`MemorySubstrateServer`) builds the `SubstrateRequest` separately.
279
- *
280
- * Frames are normalised to Buffer on delivery so handlers see the same shape
281
- * they would over a real WS (the `WsConnection.onMessage` signature is
282
- * `(frame: Buffer) => void`). `send()` accepts Buffer / Uint8Array / string on
283
- * both sides and normalises before dispatch.
284
- *
285
- * Close semantics:
286
- * - First close from either side transitions the pair to closed and fires
287
- * both sides' onClose callbacks synchronously with the provided code.
288
- * - Subsequent close() calls are no-ops (no duplicate events).
289
- * - send() on a closed endpoint throws a named error — callers that race
290
- * a close against a send should handle this, mirroring real WS behaviour
291
- * where the underlying socket may have shut down mid-write.
292
- */
293
266
  /**
294
- * @internal — thrown when sending on a closed in-memory WS pair. Treat as
295
- * package-private.
267
+ * A `createSchema` for `preparePgTestSchema` that drops and recreates the
268
+ * schema, so every run builds its store from an empty database.
296
269
  */
297
- var WsClosedError = class extends Error {
298
- constructor() {
299
- super("WebSocket is closed");
300
- this.name = "WsClosedError";
270
+ async function recreatePgTestSchema(url, schema) {
271
+ const sql = postgres(url, {
272
+ max: 1,
273
+ onnotice: () => {}
274
+ });
275
+ try {
276
+ await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
277
+ await sql.unsafe(`CREATE SCHEMA "${schema}"`);
278
+ } finally {
279
+ await sql.end({ timeout: 5 });
301
280
  }
302
- };
303
- function toBuffer(frame) {
304
- if (typeof frame === "string") return Buffer.from(frame, "utf8");
305
- if (Buffer.isBuffer(frame)) return frame;
306
- return Buffer.from(frame);
307
- }
308
- /**
309
- * @internal — paired in-memory WS endpoints used by `MemorySubstrateServer`
310
- * for inject-style WS testing. Treat as package-private.
311
- */
312
- function createMemoryWsPair() {
313
- const serverSide = {
314
- messageListeners: [],
315
- closeListeners: []
316
- };
317
- const clientSide = {
318
- messageListeners: [],
319
- closeListeners: []
320
- };
321
- const state = { closed: false };
322
- const closePair = (code) => {
323
- if (state.closed) return;
324
- state.closed = true;
325
- const s = serverSide.closeListeners.slice();
326
- const c = clientSide.closeListeners.slice();
327
- for (const cb of s) try {
328
- cb(code);
329
- } catch {}
330
- for (const cb of c) try {
331
- cb(code);
332
- } catch {}
333
- };
334
- return {
335
- server: {
336
- id: randomUUID(),
337
- send(frame) {
338
- if (state.closed) throw new WsClosedError();
339
- const buf = toBuffer(frame);
340
- for (const cb of clientSide.messageListeners.slice()) cb(buf);
341
- },
342
- onMessage(cb) {
343
- serverSide.messageListeners.push(cb);
344
- },
345
- onClose(cb) {
346
- serverSide.closeListeners.push(cb);
347
- },
348
- close(code, _reason) {
349
- closePair(code);
350
- }
351
- },
352
- client: {
353
- send(frame) {
354
- if (state.closed) throw new WsClosedError();
355
- const buf = toBuffer(frame);
356
- for (const cb of serverSide.messageListeners.slice()) cb(buf);
357
- },
358
- onMessage(cb) {
359
- clientSide.messageListeners.push(cb);
360
- },
361
- onClose(cb) {
362
- clientSide.closeListeners.push(cb);
363
- },
364
- close(code, _reason) {
365
- closePair(code);
366
- },
367
- get closed() {
368
- return state.closed;
369
- }
370
- }
371
- };
372
281
  }
373
282
 
374
283
  //#endregion
@@ -435,12 +344,6 @@ function paramName(seg) {
435
344
 
436
345
  //#endregion
437
346
  //#region ../../packages/substrate-server-memory/src/memory-server.ts
438
- var UnknownWsPathError = class extends Error {
439
- constructor(path) {
440
- super(`No websocket route registered for path: ${path}`);
441
- this.name = "UnknownWsPathError";
442
- }
443
- };
444
347
  /**
445
348
  * @internal — thrown when `MemorySubstrateServer.start()` is called twice.
446
349
  * Re-exported from the package index; treat as package-private.
@@ -451,7 +354,7 @@ var AlreadyStartedError = class extends Error {
451
354
  this.name = "AlreadyStartedError";
452
355
  }
453
356
  };
454
- const JSON_HEADERS = Object.freeze({ "content-type": "application/json" });
357
+ const JSON_HEADERS = /* @__PURE__ */ Object.freeze({ "content-type": "application/json" });
455
358
  function jsonBody(obj) {
456
359
  return Buffer.from(JSON.stringify(obj), "utf8");
457
360
  }
@@ -485,7 +388,6 @@ function parseQuery(path) {
485
388
  }
486
389
  var MemorySubstrateServer = class {
487
390
  #routes = [];
488
- #wsRoutes = [];
489
391
  #inFlight = /* @__PURE__ */ new Set();
490
392
  #shutdownHooks = /* @__PURE__ */ new Set();
491
393
  #errorHook;
@@ -500,12 +402,6 @@ var MemorySubstrateServer = class {
500
402
  handler
501
403
  });
502
404
  }
503
- websocket(path, handler) {
504
- this.#wsRoutes.push({
505
- pattern: path,
506
- handler
507
- });
508
- }
509
405
  onError(hook) {
510
406
  this.#errorHook = hook;
511
407
  }
@@ -568,8 +464,7 @@ var MemorySubstrateServer = class {
568
464
  post: (path, handler) => this.route("POST", prefixed(path), handler),
569
465
  put: (path, handler) => this.route("PUT", prefixed(path), handler),
570
466
  delete: (path, handler) => this.route("DELETE", prefixed(path), handler),
571
- patch: (path, handler) => this.route("PATCH", prefixed(path), handler),
572
- websocket: (path, handler) => this.websocket(prefixed(path), handler)
467
+ patch: (path, handler) => this.route("PATCH", prefixed(path), handler)
573
468
  };
574
469
  }
575
470
  async inject(req) {
@@ -657,48 +552,7 @@ var MemorySubstrateServer = class {
657
552
  if (ownedController !== null) this.#inFlight.delete(ownedController);
658
553
  }
659
554
  }
660
- #reportWsError(err) {
661
- const error = err instanceof Error ? err : new Error(String(err));
662
- if (!this.#errorHook) return;
663
- try {
664
- this.#errorHook(error);
665
- } catch {}
666
- }
667
- connectWebsocket(path, headers = {}) {
668
- const parsed = parseQuery(path);
669
- let matched;
670
- let params = {};
671
- for (const entry of this.#wsRoutes) {
672
- const m = matchRoute(entry.pattern, parsed.pathname);
673
- if (m !== null) {
674
- matched = entry;
675
- params = m;
676
- break;
677
- }
678
- }
679
- if (!matched) throw new UnknownWsPathError(parsed.pathname);
680
- const substrateReq = {
681
- method: "GET",
682
- path: parsed.pathname,
683
- headers,
684
- query: parsed.query,
685
- params,
686
- body: null
687
- };
688
- const { server, client } = createMemoryWsPair();
689
- queueMicrotask(() => {
690
- try {
691
- const result = matched.handler(substrateReq, server);
692
- if (result && typeof result.then === "function") result.catch((err) => {
693
- this.#reportWsError(err);
694
- });
695
- } catch (err) {
696
- this.#reportWsError(err);
697
- }
698
- });
699
- return client;
700
- }
701
555
  };
702
556
 
703
557
  //#endregion
704
- export { AlreadyStartedError, FakeEmbedder, MemoryDataset, MemoryEdgesStore, MemorySubstrateServer, PgDataset, PgEdgesStore, UnknownWsPathError, WsClosedError, announcePgGating, assertCannotWriteOutsideTestDatabases, assertNotSuperuser, assertTestDatabase, compose, createMemoryWsPair, deriveListIndexMigration, interpretSuperuserProbe, loadPlugins, matchRoute, pgTestSchemaName, pgTestSchemaUrl, preparePgTestSchema, publicLeftoverWarning, reachFailureMessage, runDerivedMigrations, runMigrations, signHs256 };
558
+ 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-aIkY8sR3.js";
2
+ import { t as BridgeClient } from "./bridge-DnToJedN.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.9",
3
+ "version": "1.0.0-beta.2",
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.9",
40
- "@mnmal-ai/substrate-client": "1.0.0-alpha.9",
41
- "@mnmal-ai/substrate-compose": "1.0.0-alpha.9",
42
- "@mnmal-ai/substrate-config": "1.0.0-alpha.9",
43
- "@mnmal-ai/substrate-core": "1.0.0-alpha.9",
44
- "@mnmal-ai/substrate-dataset-memory": "1.0.0-alpha.9",
45
- "@mnmal-ai/substrate-dataset-pg": "1.0.0-alpha.9",
46
- "@mnmal-ai/substrate-embedder": "1.0.0-alpha.9",
47
- "@mnmal-ai/substrate-filter": "1.0.0-alpha.9",
48
- "@mnmal-ai/substrate-pack": "1.0.0-alpha.9",
49
- "@mnmal-ai/substrate-policy": "1.0.0-alpha.9",
50
- "@mnmal-ai/substrate-proposals": "1.0.0-alpha.9",
51
- "@mnmal-ai/substrate-recall": "1.0.0-alpha.9",
52
- "@mnmal-ai/substrate-sdk": "1.0.0-alpha.9",
53
- "@mnmal-ai/substrate-sentinel-client": "1.0.0-alpha.9",
54
- "@mnmal-ai/substrate-server-fastify": "1.0.0-alpha.9",
55
- "@mnmal-ai/substrate-server-memory": "1.0.0-alpha.9",
56
- "@mnmal-ai/substrate-types": "1.0.0-alpha.9",
38
+ "@mnmal-ai/substrate-bootstrap": "1.0.0-beta.2",
39
+ "@mnmal-ai/substrate-client": "1.0.0-beta.2",
40
+ "@mnmal-ai/substrate-compose": "1.0.0-beta.2",
41
+ "@mnmal-ai/substrate-config": "1.0.0-beta.2",
42
+ "@mnmal-ai/substrate-core": "1.0.0-beta.2",
43
+ "@mnmal-ai/substrate-dataset-memory": "1.0.0-beta.2",
44
+ "@mnmal-ai/substrate-dataset-pg": "1.0.0-beta.2",
45
+ "@mnmal-ai/substrate-embedder": "1.0.0-beta.2",
46
+ "@mnmal-ai/substrate-filter": "1.0.0-beta.2",
47
+ "@mnmal-ai/substrate-pack": "1.0.0-beta.2",
48
+ "@mnmal-ai/substrate-policy": "1.0.0-beta.2",
49
+ "@mnmal-ai/substrate-proposals": "1.0.0-beta.2",
50
+ "@mnmal-ai/substrate-recall": "1.0.0-beta.2",
51
+ "@mnmal-ai/substrate-sdk": "1.0.0-beta.2",
52
+ "@mnmal-ai/substrate-sentinel-client": "1.0.0-beta.2",
53
+ "@mnmal-ai/substrate-server-fastify": "1.0.0-beta.2",
54
+ "@mnmal-ai/substrate-server-memory": "1.0.0-beta.2",
55
+ "@mnmal-ai/substrate-types": "1.0.0-beta.2",
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",