@mnmal-ai/substrate 0.0.0 → 1.0.0-alpha.0

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 (46) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +118 -1
  3. package/dist/agent-token-BIboWOU0.js +200 -0
  4. package/dist/client.d.ts +782 -0
  5. package/dist/client.js +7 -0
  6. package/dist/cluster-worker.js +35 -0
  7. package/dist/content-type-C7T28xNb.js +25 -0
  8. package/dist/dataset-BXkus75W.js +1527 -0
  9. package/dist/env-utils-B7SGmoeJ.js +21 -0
  10. package/dist/errors-D4vKuwz8.d.ts +130 -0
  11. package/dist/fake-DUVtKVSE.js +36 -0
  12. package/dist/index-D7mSOFlM.d.ts +69 -0
  13. package/dist/pack.d.ts +192 -0
  14. package/dist/pack.js +5 -0
  15. package/dist/plugin-j1jt1l3n.js +3844 -0
  16. package/dist/plugin-t2g2wX0b.d.ts +1568 -0
  17. package/dist/proposals-bootstrap.js +37 -0
  18. package/dist/proposals.config.schema.json +20 -0
  19. package/dist/proposals.d.ts +118 -0
  20. package/dist/proposals.default-config.json +4 -0
  21. package/dist/proposals.js +4 -0
  22. package/dist/recall-bootstrap.js +451 -0
  23. package/dist/recall.config.schema.json +232 -0
  24. package/dist/recall.d.ts +1981 -0
  25. package/dist/recall.default-config.json +4 -0
  26. package/dist/recall.js +5 -0
  27. package/dist/repl-C52wyfMs.js +2213 -0
  28. package/dist/row-ByLFE2Wx.d.ts +719 -0
  29. package/dist/row-DK7lPZVe.js +732 -0
  30. package/dist/runtime-metrics-DwpDJ8vz.d.ts +159 -0
  31. package/dist/schema-g4FQLr0V.d.ts +433 -0
  32. package/dist/sdk.d.ts +694 -0
  33. package/dist/sdk.js +112 -0
  34. package/dist/src-C4DzaIQZ.js +837 -0
  35. package/dist/src-CrEgiMJQ.js +1015 -0
  36. package/dist/src-CzxvmhFn.js +2327 -0
  37. package/dist/src-D88LvCX8.js +1797 -0
  38. package/dist/src-D91yij6C.js +13523 -0
  39. package/dist/src-DuopV8u7.js +2408 -0
  40. package/dist/substrate-admin.js +808 -0
  41. package/dist/substrate.js +5477 -0
  42. package/dist/testing.d.ts +1240 -0
  43. package/dist/testing.js +702 -0
  44. package/dist/types-8c0gtnd2.d.ts +35 -0
  45. package/dist/ws-C72iVS5T.d.ts +143 -0
  46. package/package.json +117 -4
@@ -0,0 +1,35 @@
1
+ //#region ../../packages/substrate-embedder/src/types.d.ts
2
+ /**
3
+ * Embedder interface: pluggable text-to-vector backend for Substrate's
4
+ * semantic-recall surface. Implementations live
5
+ * alongside this type (`./ollama.ts` for local Ollama, `./fake.ts` for
6
+ * tests). Writers / readers depend on this interface, never on a concrete
7
+ * class.
8
+ */
9
+ interface Embedder {
10
+ /**
11
+ * Identity of the model, INCLUDING dimension. Stored alongside each vector
12
+ * in `embeddings.model`. MUST encode dimension so same-family-
13
+ * different-dim (e.g. bge-small 384 vs bge-base 768) never collide in
14
+ * the model column.
15
+ *
16
+ * Format: `<family>:<version>:<dim>`.
17
+ * Examples: `bge-small-en:v1.5:384`, `fake:v1:384`.
18
+ */
19
+ readonly modelId: string;
20
+ /** Must match the pgvector column type AND the suffix of modelId. */
21
+ readonly dimension: number;
22
+ /**
23
+ * Embed a single text. Throws EmbedError on transport failure, timeout,
24
+ * non-2xx response, malformed vector shape, or dimension mismatch.
25
+ * Callers decide whether to continue on failure (write-path) or surface
26
+ * to user (read-path).
27
+ */
28
+ embed(text: string, opts?: EmbedOptions): Promise<Float32Array>;
29
+ }
30
+ interface EmbedOptions {
31
+ /** Per-call timeout in ms, overriding the embedder's own default. */
32
+ timeoutMs?: number;
33
+ }
34
+ //#endregion
35
+ export { Embedder as t };
@@ -0,0 +1,143 @@
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";
4
+ //#region ../../packages/substrate-types/src/idempotency.d.ts
5
+ interface IdempotencyStore {
6
+ /**
7
+ * Fetch a cached envelope by dedup key. MUST return `undefined` for expired
8
+ * entries — lazy expiry is acceptable, but the caller MUST NOT observe
9
+ * stale results.
10
+ */
11
+ get(key: string): Promise<PackEnvelope | undefined>;
12
+ /**
13
+ * Cache `envelope` under `key` with `ttlMs` lifetime. The engine invokes this
14
+ * only on a successful, error-free mutate frame.
15
+ */
16
+ put(key: string, envelope: PackEnvelope, ttlMs: number): Promise<void>;
17
+ /**
18
+ * Reap expired entries. Returns the count deleted. Implementations may
19
+ * no-op (e.g. `MemoryIdempotencyStore` already expires lazily on `get`)
20
+ * or actively delete (e.g. pg implementations need to free row space).
21
+ * Called on an interval by the binary; not in the request path.
22
+ */
23
+ reapExpired(): Promise<{
24
+ deleted: number;
25
+ }>;
26
+ }
27
+ //#endregion
28
+ //#region ../../packages/substrate-types/src/sweep.d.ts
29
+ type TargetState = 'EXISTS' | 'DELETED' | 'MISSING';
30
+ /**
31
+ * Registry of bridged namespaces. §5.8.
32
+ *
33
+ * Keys are local namespace aliases: the string a caller puts on a frame key
34
+ * (`<alias>/<type>`) resolves to the bridge client responsible for proxying
35
+ * to the remote. Aliasing happens at registration; the remote's internal
36
+ * namespace names are opaque to this registry.
37
+ */
38
+ interface BridgeRegistry {
39
+ /** True iff `ns` is bridged (registered under that alias). */
40
+ has(ns: string): boolean;
41
+ /** Return the bridge client for `ns` or undefined. */
42
+ get(ns: string): BridgeClient | undefined;
43
+ /** Fast-path reachability. True iff the bridge for `ns` is currently unreachable. */
44
+ isUnreachable(ns: string): boolean;
45
+ /** Iterate every (ns, bridge) pair. Used by the engine's schema merge at init. */
46
+ entries(): Array<[string, BridgeClient]>;
47
+ }
48
+ interface SweepDeps {
49
+ datasets: DatasetRegistry;
50
+ bridges: BridgeRegistry;
51
+ edges: EdgesStore;
52
+ now(): Date;
53
+ metric(name: string, payload?: unknown): void;
54
+ }
55
+ interface SweepState {
56
+ lastSweptCursor: string | null;
57
+ }
58
+ type ResolveTarget = (ref: EdgeRef, deps: SweepDeps) => Promise<TargetState>;
59
+ //#endregion
60
+ //#region ../../packages/substrate-types/src/ws.d.ts
61
+ /**
62
+ * Client→server frame. `frame` is a map of qualified keys (`<ns>/<name>`, §4.7)
63
+ * to selection entries. `subscribe` and `stream` require the selection map;
64
+ * `cancel` addresses a prior subscription by `id` and omits `frame`.
65
+ */
66
+ interface WsRequestFrame {
67
+ id: string;
68
+ /**
69
+ * `whoami` carries no `frame` and opens no session. It reports the
70
+ * socket's own authentication, which is a different code path from HTTP's,
71
+ * so asking over HTTP does not answer it.
72
+ */
73
+ op: 'subscribe' | 'stream' | 'cancel' | 'whoami';
74
+ frame?: Record<string, {
75
+ params?: Record<string, unknown>;
76
+ fields?: FieldInput;
77
+ }>;
78
+ }
79
+ /**
80
+ * Response kinds covering the full §5.4 + §5.5 surface. `chunk` carries
81
+ * streaming output; subscription pushes use `snapshot` / `add` / `update` / `remove`
82
+ * plus `end` on cancel and `error` on validation / policy / resolver failure.
83
+ */
84
+ type WsResponseKind = 'snapshot' | 'add' | 'update' | 'remove' | 'chunk' | 'end' | 'error' | 'whoami';
85
+ /**
86
+ * Server→client frame. `data` is the payload a route layer serialises per the
87
+ * connection's negotiated encoding (named objects → JSON, or positional tuples
88
+ * via substrate-pack). `removedId` replaces `data` for the `remove` kind so remove
89
+ * frames can fire cheaply without re-encoding the dropped row.
90
+ */
91
+ interface WsResponseFrame {
92
+ id: string;
93
+ kind: WsResponseKind;
94
+ schemaVersion?: string;
95
+ data?: unknown;
96
+ shapes?: Record<string, 'single' | 'list'>;
97
+ removedId?: Id;
98
+ errors?: Array<{
99
+ message: string;
100
+ code?: string;
101
+ path?: string[];
102
+ }>;
103
+ /** §5.5 streaming: last-chunk marker; also set on `end` from a `cancel`. */
104
+ final?: boolean;
105
+ /** §5.5 streaming: monotonic per-subscription sequence on chunks. */
106
+ sequence?: number;
107
+ /**
108
+ * Frame-level metadata bag. Currently carries `cancelled: true` on `end`
109
+ * frames emitted because a stream was cancelled (vs natural completion),
110
+ * letting the client disambiguate when cancellation races completion. The
111
+ * exact wire key (`_meta.cancelled`) is part of the on-wire contract — do
112
+ * not rename it.
113
+ */
114
+ _meta?: {
115
+ cancelled?: boolean;
116
+ };
117
+ /**
118
+ * Terminal-cause token on `end` frames. One vocabulary, one token per
119
+ * condition, reused verbatim wherever that condition appears (so the
120
+ * overload token matches the `code` on the preceding `error` frame).
121
+ * Known values: `WS_REASON_SUBSCRIPTION_OVERLOADED` (queue-limit teardown),
122
+ * `WS_REASON_SERVER_RESTART` (graceful shutdown). Absent on a cancel ack.
123
+ * Stays `string` on the wire for forward compatibility — clients must
124
+ * tolerate unknown tokens. Contract: docs/ws-subscription-contract.md.
125
+ */
126
+ reason?: string;
127
+ }
128
+ /**
129
+ * Terminal-cause vocabulary (docs/ws-subscription-contract.md). The overload
130
+ * token is BOTH the `code` of the terminal `error` frame and the `reason` of
131
+ * the following `end` frame — one token per condition, no second spelling.
132
+ */
133
+ declare const WS_REASON_SUBSCRIPTION_OVERLOADED: 'subscription_overloaded';
134
+ declare const WS_REASON_SERVER_RESTART: 'server_restart';
135
+ /**
136
+ * Error `code` for a subscribe/stream frame the engine refuses to register
137
+ * because the targeted surface is one-shot-only: a virtual (dataset-less)
138
+ * namespace has no write stream to subscribe to, and a semantic
139
+ * (extension-operator) where-clause has no incremental evaluation.
140
+ */
141
+ declare const WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME: 'subscription_unsupported_frame';
142
+ //#endregion
143
+ export { WsResponseFrame as a, ResolveTarget as c, TargetState as d, IdempotencyStore as f, WsRequestFrame as i, SweepDeps as l, WS_REASON_SERVER_RESTART as n, WsResponseKind as o, WS_REASON_SUBSCRIPTION_OVERLOADED as r, BridgeRegistry as s, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME as t, SweepState as u };
package/package.json CHANGED
@@ -1,7 +1,120 @@
1
1
  {
2
2
  "name": "@mnmal-ai/substrate",
3
- "version": "0.0.0",
4
- "description": "Reserved by MNMAL. Not yet released.",
3
+ "version": "1.0.0-alpha.0",
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
- "files": ["README.md"]
7
- }
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/mnmal-ai/substrate.git",
9
+ "directory": "apps/substrate"
10
+ },
11
+ "type": "module",
12
+ "bin": {
13
+ "substrate": "dist/substrate.js",
14
+ "substrate-admin": "dist/substrate-admin.js"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "registry": "https://registry.npmjs.org/",
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "@fastify/compress": "^9.2.0",
25
+ "@fastify/cors": "^11.3.0",
26
+ "@fastify/websocket": "^11.3.1",
27
+ "@mnmal-ai/holomap-clusterer": "0.2.1",
28
+ "@modelcontextprotocol/sdk": "^1.32.0",
29
+ "@preact/signals-core": "^1.14.4",
30
+ "fastify": "^5.12.5",
31
+ "msgpackr": "^2.1.0",
32
+ "postgres": "3.4.9",
33
+ "semver": "^7.8.5",
34
+ "ws": "^8.22.0",
35
+ "zod": "^4.6.5"
36
+ },
37
+ "devDependencies": {
38
+ "@inquirer/prompts": "^8.7.2",
39
+ "@mnmal-ai/substrate-bootstrap": "1.0.0-alpha.0",
40
+ "@mnmal-ai/substrate-client": "1.0.0-alpha.0",
41
+ "@mnmal-ai/substrate-compose": "1.0.0-alpha.0",
42
+ "@mnmal-ai/substrate-config": "1.0.0-alpha.0",
43
+ "@mnmal-ai/substrate-core": "1.0.0-alpha.0",
44
+ "@mnmal-ai/substrate-dataset-memory": "1.0.0-alpha.0",
45
+ "@mnmal-ai/substrate-dataset-pg": "1.0.0-alpha.0",
46
+ "@mnmal-ai/substrate-embedder": "1.0.0-alpha.0",
47
+ "@mnmal-ai/substrate-filter": "1.0.0-alpha.0",
48
+ "@mnmal-ai/substrate-pack": "1.0.0-alpha.0",
49
+ "@mnmal-ai/substrate-policy": "1.0.0-alpha.0",
50
+ "@mnmal-ai/substrate-proposals": "1.0.0-alpha.0",
51
+ "@mnmal-ai/substrate-recall": "1.0.0-alpha.0",
52
+ "@mnmal-ai/substrate-sdk": "1.0.0-alpha.0",
53
+ "@mnmal-ai/substrate-sentinel-client": "1.0.0-alpha.0",
54
+ "@mnmal-ai/substrate-server-fastify": "1.0.0-alpha.0",
55
+ "@mnmal-ai/substrate-server-memory": "1.0.0-alpha.0",
56
+ "@mnmal-ai/substrate-types": "1.0.0-alpha.0",
57
+ "@types/node": "^26.6.4",
58
+ "@types/semver": "^7.5.0",
59
+ "@types/ws": "^8.18.1",
60
+ "msw": "^3.0.1",
61
+ "tsdown": "^0.23.0",
62
+ "tsx": "^4.23.15",
63
+ "typescript": "^7.0.2",
64
+ "vitest": "^5.0.3"
65
+ },
66
+ "engines": {
67
+ "node": ">=26.2.0"
68
+ },
69
+ "exports": {
70
+ "./sdk": {
71
+ "types": "./dist/sdk.d.ts",
72
+ "import": "./dist/sdk.js"
73
+ },
74
+ "./client": {
75
+ "types": "./dist/client.d.ts",
76
+ "import": "./dist/client.js"
77
+ },
78
+ "./pack": {
79
+ "types": "./dist/pack.d.ts",
80
+ "import": "./dist/pack.js"
81
+ },
82
+ "./testing": {
83
+ "types": "./dist/testing.d.ts",
84
+ "import": "./dist/testing.js"
85
+ },
86
+ "./recall": {
87
+ "types": "./dist/recall.d.ts",
88
+ "import": "./dist/recall.js"
89
+ },
90
+ "./proposals": {
91
+ "types": "./dist/proposals.d.ts",
92
+ "import": "./dist/proposals.js"
93
+ }
94
+ },
95
+ "substrate": {
96
+ "plugins": [
97
+ {
98
+ "name": "recall",
99
+ "tier": "kernel",
100
+ "entry": "./dist/recall-bootstrap.js",
101
+ "defaultConfig": "./dist/recall.default-config.json",
102
+ "configSchema": "./dist/recall.config.schema.json"
103
+ },
104
+ {
105
+ "name": "proposals",
106
+ "tier": "coordinator",
107
+ "entry": "./dist/proposals-bootstrap.js",
108
+ "defaultConfig": "./dist/proposals.default-config.json",
109
+ "configSchema": "./dist/proposals.config.schema.json"
110
+ }
111
+ ]
112
+ },
113
+ "scripts": {
114
+ "build": "tsdown && node scripts/copy-plugin-configs.mjs",
115
+ "dev": "tsx src/bin/substrate.ts serve",
116
+ "test": "vitest run",
117
+ "check-types": "tsc -p tsconfig.json --noEmit",
118
+ "lint": "biome check ."
119
+ }
120
+ }