@mnmal-ai/substrate 1.0.0-alpha.7 → 1.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/client.d.ts +3 -2
- package/dist/client.js +1 -1
- package/dist/{dataset-DuPv47JG.js → dataset-CqrqTYPz.js} +4 -4
- package/dist/{pg-edges-store-CKu6M8PU.js → pg-edges-store-KH_FQCxx.js} +1 -1
- package/dist/{plugin-0dPAYAEm.js → plugin-DpncES1p.js} +74 -1
- package/dist/proposals-bootstrap.js +2 -2
- package/dist/proposals.js +1 -1
- package/dist/recall-bootstrap.js +4 -2
- package/dist/recall.config.schema.json +6 -0
- package/dist/recall.d.ts +22 -0
- package/dist/recall.js +2 -2
- package/dist/{repl-DiBeGwIW.js → repl-DeKzfvNV.js} +28 -22
- package/dist/{row-ByLFE2Wx.d.ts → row-SRhura12.d.ts} +2 -0
- package/dist/sdk.d.ts +1 -1
- package/dist/sdk.js +1 -1
- package/dist/{src-CBV88iyK.js → src-BD27zeGF.js} +2 -2
- package/dist/{src-C9pC-AKI.js → src-C12EA0w9.js} +21 -3
- package/dist/{src-DgLqCklp.js → src-DCy7Iy2l.js} +1 -1
- package/dist/{src-Dk3Zlsgd.js → src-DiNTSaFk.js} +4 -0
- package/dist/{src-B0BJcyKb.js → src-DjIuRjzF.js} +17 -3
- package/dist/substrate-admin.js +3 -3
- package/dist/substrate.js +115 -18
- package/dist/testing.js +3 -3
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -56,13 +56,13 @@ Imports the script and calls its default export with a `ScriptContext` (`args`,
|
|
|
56
56
|
```ts
|
|
57
57
|
import type { ScriptContext } from '@mnmal-ai/substrate/client';
|
|
58
58
|
|
|
59
|
-
// substrate run
|
|
59
|
+
// substrate run titled.mts --args '{"title":"hello"}'
|
|
60
60
|
export default async function (s: ScriptContext) {
|
|
61
|
-
const
|
|
62
|
-
params: { where: {
|
|
63
|
-
fields: { id: true
|
|
61
|
+
const notes = await s.queryAll('notes/Note', {
|
|
62
|
+
params: { where: { title: { eq: s.args.title } }, limit: 100 },
|
|
63
|
+
fields: { id: true }
|
|
64
64
|
});
|
|
65
|
-
return {
|
|
65
|
+
return { count: notes.length };
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
|
|
@@ -72,7 +72,7 @@ Guardrails:
|
|
|
72
72
|
- **A rejected frame throws.** A query whose key is missing from `data`, or a mutate the server refused, fails the run with the server's error rather than reading as empty.
|
|
73
73
|
- **Truncation is reported.** `query` adds a warning when a result has `hasMore`; `queryAll` pages to the end.
|
|
74
74
|
|
|
75
|
-
`s.recall({ query, namespace, type
|
|
75
|
+
`s.recall({ query, namespace, type, k?, threshold?, where?, row? })` returns hits best first, through the `recall/Hit` frame. Each hit's `row` is `id` plus the handle fields; pass `row: { body: true }` (or `true`) for more, on the hits you will read.
|
|
76
76
|
|
|
77
77
|
`--args` takes a JSON object, which the script reads as `s.args` (`{}` when omitted), so one script serves many calls.
|
|
78
78
|
|
|
@@ -99,9 +99,9 @@ set -a && source .env && set +a
|
|
|
99
99
|
./node_modules/.bin/substrate serve
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
`substrate init` writes a `package.json` pinning `@mnmal-ai/substrate` and the chosen optional plugins, a
|
|
102
|
+
`substrate init` writes a `package.json` pinning `@mnmal-ai/substrate` and the chosen optional plugins, a `pnpm-workspace.yaml`, a `.env` with `SUBSTRATE_PLUGIN_DIR=.`, a `substrate-recall.config.json` for the embedder, and, unless `--store=memory`, a `docker-compose.yml` running `pgvector/pgvector:pg17`. Flags: `--store=memory|postgres`, `--port`, `--pg-port`, `--plugins=<csv>` (from `cortext`, `substrate-nl`, `substrate-sentinel`; none by default), `--embedder=bge-base|minilm|ollama|none` (default `bge-base`), `--tls --tls-cert-path --tls-key-path`, `--substrate-url`, `--yes`, `--force`.
|
|
103
103
|
|
|
104
|
-
`SUBSTRATE_PLUGIN_DIR` is the directory whose `node_modules/` holds the plugins; in a scaffolded runtime that is the runtime directory itself. Recall and proposals load from `@mnmal-ai/substrate` itself, so they are present whenever the binary is installed there. Kernel plugins (`substrate-recall`, `substrate-nl`) compose first, then coordinators (`substrate-proposals`, `substrate-sentinel`, …), alphabetical within each tier. Per-plugin overrides live at `<SUBSTRATE_PLUGIN_DIR>/<pkg-basename>.config.json`. With `SUBSTRATE_PLUGIN_DIR` unset the binary boots with only the `_system` admin namespace and `/health`.
|
|
104
|
+
`SUBSTRATE_PLUGIN_DIR` is the directory whose `node_modules/` holds the plugins; in a scaffolded runtime that is the runtime directory itself. Recall and proposals load from `@mnmal-ai/substrate` itself, so they are present whenever the binary is installed there. Kernel plugins (`substrate-recall`, `substrate-nl`) compose first, then coordinators (`substrate-proposals`, `substrate-sentinel`, …), alphabetical within each tier. Per-plugin overrides live at `<SUBSTRATE_PLUGIN_DIR>/<pkg-basename>.config.json`. With `SUBSTRATE_PLUGIN_DIR` unset the binary boots with only the `_system` admin namespace and `/health`. Set, it must hold a `package.json` listing the plugins under `dependencies`, installed into its `node_modules/`; a missing `package.json`, or listed plugins with no `node_modules/`, refuses boot with a message naming the fix.
|
|
105
105
|
|
|
106
106
|
### Adding a plugin
|
|
107
107
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { E as Row, l as PackEnvelope, u as Schema } from "./schema-g4FQLr0V.js";
|
|
2
2
|
import { a as RuntimeErrors, i as RuntimeErrorEntry, o as RuntimeMetrics, r as ResolverStat, s as SlowRequest, t as ProcessStat } from "./runtime-metrics-DwpDJ8vz.js";
|
|
3
3
|
import { C as QualifiedFrame } from "./plugin-t2g2wX0b.js";
|
|
4
|
-
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, J as NlAskRequest, 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, Y as NlAskResult, _ as newlyGrantedPairs, a as denyAll, b as capabilitiesFor, c as requireIdentity, d as KeyUpdateRefusal, f as checkRevocable, ft as NlWireEvent, g as newlyGranted, h as grantEntriesConfer, i as allowVerbs, j as not, k as encodeList, l as requireNamespace, lt as NlServedPack, m as grantCovers, n as row, o as denyVerbs, p as checkUpdatable, q as resolveDefaultKidPath, r as allowAll, rt as NlOutcome, s as requireCapability, t as applyRowFilters, u as KeyMutationRefusal, ut as NlTrailEvent, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-
|
|
4
|
+
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, J as NlAskRequest, 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, Y as NlAskResult, _ as newlyGrantedPairs, a as denyAll, b as capabilitiesFor, c as requireIdentity, d as KeyUpdateRefusal, f as checkRevocable, ft as NlWireEvent, g as newlyGranted, h as grantEntriesConfer, i as allowVerbs, j as not, k as encodeList, l as requireNamespace, lt as NlServedPack, m as grantCovers, n as row, o as denyVerbs, p as checkUpdatable, q as resolveDefaultKidPath, r as allowAll, rt as NlOutcome, s as requireCapability, t as applyRowFilters, u as KeyMutationRefusal, ut as NlTrailEvent, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-SRhura12.js";
|
|
5
5
|
import { s as SchemaDriftError } from "./index-D7mSOFlM.js";
|
|
6
6
|
import { Signal } from "@preact/signals-core";
|
|
7
7
|
//#region ../../packages/substrate-client/src/admin/surgery.d.ts
|
|
@@ -791,7 +791,8 @@ interface ScriptRecallInput {
|
|
|
791
791
|
query: string;
|
|
792
792
|
/** Required, as on every recall surface. */
|
|
793
793
|
namespace: string;
|
|
794
|
-
type
|
|
794
|
+
/** Required, as on every recall surface: there is no default type. */
|
|
795
|
+
type: string;
|
|
795
796
|
k?: number;
|
|
796
797
|
threshold?: number;
|
|
797
798
|
where?: Record<string, unknown>;
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire as __binCreateRequire } from 'node:module'; const require
|
|
|
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
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 "./row-DZ0Fnpc6.js";
|
|
4
4
|
import { g as SchemaDriftError } from "./src-BLgbLq2k.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-
|
|
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-DiNTSaFk.js";
|
|
6
6
|
import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-C6DSa_Na.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 };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { d as buildAuditRow, f as AUDIT_EVENT_TYPE } from "./src-
|
|
2
|
+
import { d as buildAuditRow, f as AUDIT_EVENT_TYPE } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { a as adminClaimCapabilities, d as resolveDefaultKidPath, l as resolveAdminCredential, n as trimTrailingSlashes, r as ADMIN_CAPABILITIES, s as makeAuthorizationProvider, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
|
|
4
4
|
import { D as isActiveAdminKeyRow, E as describeGrant, L as encodeList, M as grantEntryError, T as SYSTEM_NAMESPACE, v as grantEntriesConfer } from "./row-DZ0Fnpc6.js";
|
|
5
|
-
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-
|
|
6
|
-
import { i as pendingMigrations, o as runMigrations, t as PgDataset } from "./src-
|
|
5
|
+
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-DiNTSaFk.js";
|
|
6
|
+
import { i as pendingMigrations, o as runMigrations, t as PgDataset } from "./src-BD27zeGF.js";
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
@@ -11,7 +11,7 @@ import { createHash, createPublicKey, generateKeyPairSync, randomUUID } from "no
|
|
|
11
11
|
import postgres from "postgres";
|
|
12
12
|
|
|
13
13
|
//#region package.json
|
|
14
|
-
var version = "1.0.0-alpha.
|
|
14
|
+
var version = "1.0.0-alpha.9";
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/admin/errors.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { n as txScopeIdFor } from "./src-
|
|
2
|
+
import { n as txScopeIdFor } from "./src-BD27zeGF.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
|
|
5
5
|
//#region ../../packages/substrate-dataset-pg/src/pg-edges-store.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { L as applyObligations, Q as buildContext, et as jsonResponse, wt as ResolverFrameError } from "./src-
|
|
2
|
+
import { L as applyObligations, Q as buildContext, et as jsonResponse, wt as ResolverFrameError } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { Worker } from "node:worker_threads";
|
|
4
4
|
|
|
5
5
|
//#region ../../plugins/substrate-recall/src/candidate-selection.ts
|
|
@@ -2805,6 +2805,50 @@ async function alignLocked(s, opts) {
|
|
|
2805
2805
|
};
|
|
2806
2806
|
}
|
|
2807
2807
|
|
|
2808
|
+
//#endregion
|
|
2809
|
+
//#region ../../plugins/substrate-recall/src/embed-backfill.ts
|
|
2810
|
+
async function runEmbedBackfill(deps) {
|
|
2811
|
+
const result = {
|
|
2812
|
+
embedded: 0,
|
|
2813
|
+
unindexable: 0,
|
|
2814
|
+
failed: 0
|
|
2815
|
+
};
|
|
2816
|
+
const staleRowIds = deps.store.staleRowIds?.bind(deps.store);
|
|
2817
|
+
if (staleRowIds === void 0) return result;
|
|
2818
|
+
for (const { namespace, type } of deps.registry.types()) {
|
|
2819
|
+
const reembed = deps.registry.get(namespace, type)?.reembed;
|
|
2820
|
+
const dataset = deps.resolveDataset(namespace);
|
|
2821
|
+
if (reembed === void 0 || dataset === null) continue;
|
|
2822
|
+
const key = `${namespace}/${type}`;
|
|
2823
|
+
const ids = await staleRowIds({
|
|
2824
|
+
namespace,
|
|
2825
|
+
type,
|
|
2826
|
+
afterId: deps.cursors.get(key) ?? "",
|
|
2827
|
+
limit: deps.perTypeLimit
|
|
2828
|
+
});
|
|
2829
|
+
if (ids.length < deps.perTypeLimit) deps.cursors.delete(key);
|
|
2830
|
+
else deps.cursors.set(key, ids[ids.length - 1]);
|
|
2831
|
+
if (ids.length === 0) continue;
|
|
2832
|
+
const { rows } = await dataset.read(type, {
|
|
2833
|
+
ids,
|
|
2834
|
+
limit: ids.length
|
|
2835
|
+
});
|
|
2836
|
+
for (const row of rows) {
|
|
2837
|
+
const outcome = await reembed(row);
|
|
2838
|
+
if (outcome.status === "embedded") result.embedded++;
|
|
2839
|
+
else if (outcome.status === "unindexable") result.unindexable++;
|
|
2840
|
+
else if (outcome.status === "failed") {
|
|
2841
|
+
result.failed++;
|
|
2842
|
+
if (outcome.code === "unavailable") return {
|
|
2843
|
+
...result,
|
|
2844
|
+
stopped: outcome.error
|
|
2845
|
+
};
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
return result;
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2808
2852
|
//#endregion
|
|
2809
2853
|
//#region ../../plugins/substrate-recall/src/expansion-resolver.ts
|
|
2810
2854
|
function makeExpansionResolver(registry, edges, cfg) {
|
|
@@ -3654,6 +3698,9 @@ function makeSpreadResolver(registry, edges) {
|
|
|
3654
3698
|
//#endregion
|
|
3655
3699
|
//#region ../../plugins/substrate-recall/src/plugin.ts
|
|
3656
3700
|
const DEFAULT_CLUSTER_DIMENSION = 768;
|
|
3701
|
+
const DEFAULT_EMBED_BACKFILL_INTERVAL_MS = 6e4;
|
|
3702
|
+
/** Rows per embedded type per pass, so one pass stays a few seconds of embed work. */
|
|
3703
|
+
const EMBED_BACKFILL_PER_TYPE = 50;
|
|
3657
3704
|
const DEFAULT_QUERY_EMBED_TIMEOUT_MS = 3e4;
|
|
3658
3705
|
const DEFAULT_WRITE_EMBED_TIMEOUT_MS = 3e4;
|
|
3659
3706
|
/** `embedder` with `timeoutMs` applied to every call that does not set its own. */
|
|
@@ -3736,6 +3783,7 @@ function createRecallPlugin(cfg) {
|
|
|
3736
3783
|
contractVersion: ">=1.0.0-alpha.0 <2.0.0",
|
|
3737
3784
|
async onKernelReady(ctx) {
|
|
3738
3785
|
if (cfg.embedder === void 0 || ctx.sql === null) return;
|
|
3786
|
+
let dimensionMismatch = false;
|
|
3739
3787
|
const report = await alignVectorDimensions(ctx.sql, {
|
|
3740
3788
|
dimension: cfg.embedder.dimension,
|
|
3741
3789
|
...cfg.migration?.hnswM !== void 0 ? { hnswM: cfg.migration.hnswM } : {},
|
|
@@ -3743,6 +3791,7 @@ function createRecallPlugin(cfg) {
|
|
|
3743
3791
|
});
|
|
3744
3792
|
for (const [column, state] of [["embeddings.embedding", report.embeddings], ["recall_clusters.centroid", report.centroids]]) {
|
|
3745
3793
|
if (state !== "populated") continue;
|
|
3794
|
+
dimensionMismatch = true;
|
|
3746
3795
|
const found = column.startsWith("embeddings") ? report.found.embeddings : report.found.centroids;
|
|
3747
3796
|
ctx.metric("recall_dimension_mismatch", {
|
|
3748
3797
|
column,
|
|
@@ -3752,6 +3801,30 @@ function createRecallPlugin(cfg) {
|
|
|
3752
3801
|
});
|
|
3753
3802
|
process.emitWarning(`${column} is vector(${found}) and holds rows, but the embedder is ${cfg.embedder.modelId} at ${cfg.embedder.dimension}. Writes to it will fail until the rows are cleared (they are derived) and re-embedded: delete them, restart, then POST /substrate/v1/embed/reindex.`, { code: "RECALL_DIMENSION_MISMATCH" });
|
|
3754
3803
|
}
|
|
3804
|
+
const intervalMs = cfg.embedBackfillIntervalMs ?? DEFAULT_EMBED_BACKFILL_INTERVAL_MS;
|
|
3805
|
+
const resolveDataset = cfg.resolveDataset;
|
|
3806
|
+
if (dimensionMismatch || intervalMs === 0 || resolveDataset === void 0) return;
|
|
3807
|
+
const cursors = /* @__PURE__ */ new Map();
|
|
3808
|
+
let running = false;
|
|
3809
|
+
setInterval(() => {
|
|
3810
|
+
if (running) return;
|
|
3811
|
+
running = true;
|
|
3812
|
+
runEmbedBackfill({
|
|
3813
|
+
registry: embedSourceRegistry,
|
|
3814
|
+
store: cfg.store,
|
|
3815
|
+
resolveDataset,
|
|
3816
|
+
cursors,
|
|
3817
|
+
perTypeLimit: EMBED_BACKFILL_PER_TYPE
|
|
3818
|
+
}).then((r) => {
|
|
3819
|
+
if (r.embedded + r.failed === 0 && r.stopped === void 0) return;
|
|
3820
|
+
ctx.metric("recall_embed_backfill", r);
|
|
3821
|
+
process.stdout.write(`recall.embed_backfill ${JSON.stringify(r)}\n`);
|
|
3822
|
+
}).catch((err) => {
|
|
3823
|
+
process.stderr.write(`recall.embed_backfill failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
3824
|
+
}).finally(() => {
|
|
3825
|
+
running = false;
|
|
3826
|
+
});
|
|
3827
|
+
}, intervalMs).unref();
|
|
3755
3828
|
},
|
|
3756
3829
|
migrations: [
|
|
3757
3830
|
embeddingsMigration(cfg.migration ?? {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { Pt as defineBootstrap } from "./src-
|
|
3
|
-
import { n as createNoopPubSub, t as createProposalsPlugin } from "./src-
|
|
2
|
+
import { Pt as defineBootstrap } from "./src-DjIuRjzF.js";
|
|
3
|
+
import { n as createNoopPubSub, t as createProposalsPlugin } from "./src-DCy7Iy2l.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region ../../plugins/substrate-proposals/src/bootstrap.ts
|
package/dist/proposals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { n as createNoopPubSub, r as ProposalError, t as createProposalsPlugin } from "./src-
|
|
2
|
+
import { n as createNoopPubSub, r as ProposalError, t as createProposalsPlugin } from "./src-DCy7Iy2l.js";
|
|
3
3
|
|
|
4
4
|
export { ProposalError, createNoopPubSub, createProposalsPlugin };
|
package/dist/recall-bootstrap.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { Pt as defineBootstrap } from "./src-
|
|
2
|
+
import { Pt as defineBootstrap } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { t as FakeEmbedder } from "./fake-DUVtKVSE.js";
|
|
4
|
-
import { t as createRecallPlugin } from "./plugin-
|
|
4
|
+
import { t as createRecallPlugin } from "./plugin-DpncES1p.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
|
|
7
7
|
//#region ../../packages/substrate-embedder/src/types.ts
|
|
@@ -384,6 +384,7 @@ const RecallBootstrapConfigSchema = z.object({
|
|
|
384
384
|
embedder: EmbedderSchema.optional(),
|
|
385
385
|
queryEmbedTimeoutMs: z.number().int().positive().default(3e4),
|
|
386
386
|
writeEmbedTimeoutMs: z.number().int().positive().default(3e4),
|
|
387
|
+
embedBackfillIntervalMs: z.number().int().nonnegative().default(6e4),
|
|
387
388
|
hnswM: z.number().int().positive().default(16),
|
|
388
389
|
hnswEfConstruction: z.number().int().positive().default(64),
|
|
389
390
|
salience: SalienceSchema.default({
|
|
@@ -433,6 +434,7 @@ const bootstrap = defineBootstrap.kernel({
|
|
|
433
434
|
...embedder !== null ? { embedder } : {},
|
|
434
435
|
queryEmbedTimeoutMs: config.queryEmbedTimeoutMs,
|
|
435
436
|
writeEmbedTimeoutMs: config.writeEmbedTimeoutMs,
|
|
437
|
+
embedBackfillIntervalMs: config.embedBackfillIntervalMs,
|
|
436
438
|
...deps.lexicalStore !== void 0 ? { lexicalStore: deps.lexicalStore } : {},
|
|
437
439
|
store: deps.store,
|
|
438
440
|
...deps.stats !== void 0 ? { stats: deps.stats } : {},
|
|
@@ -124,6 +124,12 @@
|
|
|
124
124
|
"exclusiveMinimum": 0,
|
|
125
125
|
"maximum": 9007199254740991
|
|
126
126
|
},
|
|
127
|
+
"embedBackfillIntervalMs": {
|
|
128
|
+
"default": 60000,
|
|
129
|
+
"type": "integer",
|
|
130
|
+
"minimum": 0,
|
|
131
|
+
"maximum": 9007199254740991
|
|
132
|
+
},
|
|
127
133
|
"hnswM": {
|
|
128
134
|
"default": 16,
|
|
129
135
|
"type": "integer",
|
package/dist/recall.d.ts
CHANGED
|
@@ -305,6 +305,17 @@ interface EmbeddingsStore {
|
|
|
305
305
|
* mismatched vector surfaces as a substrate-level error.
|
|
306
306
|
*/
|
|
307
307
|
upsert(input: EmbeddingsStoreUpsertInput): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Ids of live rows of (namespace, type) whose vector is missing or older than
|
|
310
|
+
* the row, after `afterId` in id order: the writes whose embed failed. Optional;
|
|
311
|
+
* a store that cannot see the rows table omits it and nothing is backfilled.
|
|
312
|
+
*/
|
|
313
|
+
staleRowIds?(input: {
|
|
314
|
+
namespace: string;
|
|
315
|
+
type: string;
|
|
316
|
+
afterId: string;
|
|
317
|
+
limit: number;
|
|
318
|
+
}): Promise<string[]>;
|
|
308
319
|
/**
|
|
309
320
|
* Remove the embedding for one row, leaving the row itself untouched. Used
|
|
310
321
|
* to un-index a row whose `embed.source` returns the null sentinel.
|
|
@@ -1704,6 +1715,12 @@ export declare class PgEmbeddingsStore implements EmbeddingsStore {
|
|
|
1704
1715
|
*
|
|
1705
1716
|
* @returns number of orphaned embeddings deleted.
|
|
1706
1717
|
*/
|
|
1718
|
+
staleRowIds(input: {
|
|
1719
|
+
namespace: string;
|
|
1720
|
+
type: string;
|
|
1721
|
+
afterId: string;
|
|
1722
|
+
limit: number;
|
|
1723
|
+
}): Promise<string[]>;
|
|
1707
1724
|
purgeOrphans(): Promise<number>;
|
|
1708
1725
|
}
|
|
1709
1726
|
//#endregion
|
|
@@ -1758,6 +1775,11 @@ interface RecallPluginConfig {
|
|
|
1758
1775
|
* the row's previous vector until its next write or a reindex. Default 30000.
|
|
1759
1776
|
*/
|
|
1760
1777
|
writeEmbedTimeoutMs?: number;
|
|
1778
|
+
/**
|
|
1779
|
+
* How often to re-embed rows whose write-path embed failed or timed out (their
|
|
1780
|
+
* vector is missing or older than the row). 0 disables. Default 60000.
|
|
1781
|
+
*/
|
|
1782
|
+
embedBackfillIntervalMs?: number;
|
|
1761
1783
|
store: EmbeddingsStore;
|
|
1762
1784
|
/**
|
|
1763
1785
|
* Store for the lexical arm. Absent → types declaring `lexical.source`
|
package/dist/recall.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore, t as RECALL_VERSION } from "./src-
|
|
3
|
-
import { $ as CLUSTERER_BACKEND_VERSION, A as CLUSTER_MEMBER_FIELDS, C as EmbedSourceRegistry, D as makeReembed, E as makeEmbedPostWrite, F as unknownParams, G as DEFAULT_CRYSTALLISE_CONFIG, H as CRYSTALLISE_IN_FLIGHT_CODE, I as handleRecallRequest, J as runClusterer, K as handleCrystallise, L as RRF_K, M as recallRouteHandler, N as checkParams, O as crystalliseRouteHandler, P as unknownParamMessage, Q as CLUSTERER_BACKEND, R as armRanks, S as createEmbedStats, T as embedRowReporting, U as createCrystalliseGuard, X as l2normalize, _ as EMBEDDINGS_FETCH_MAX_REFS, a as REINDEX_MAX_LIMIT, b as handleLexicalCoverage, c as SALIENCE_BOOST_MAX_TARGETS, d as embeddingsMigration, et as memberKey, f as recallMcpTool, g as embeddingsFetchRouteHandler, h as embeddingSimilarOperator, i as REINDEX_DEFAULT_LIMIT, j as buildClusterSurface, k as CLUSTER_FIELDS, l as lexicalMigration, m as makeLexicalPostWrite, n as salienceBoostRouteHandler, nt as validateSelector, o as handleReindex, p as makeLexicalClassify, q as validateCrystalliseInput, r as reindexRouteHandler, s as validateReindexInput, t as createRecallPlugin, tt as SELECT_CANDIDATES_MAX_LIMIT, u as recallClustersMigration, v as embedStatsRouteHandler, w as embedAndStore, x as validateLexicalCoverageInput, y as handleEmbedStatsRequest, z as fuseByRank } from "./plugin-
|
|
2
|
+
import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore, t as RECALL_VERSION } from "./src-C12EA0w9.js";
|
|
3
|
+
import { $ as CLUSTERER_BACKEND_VERSION, A as CLUSTER_MEMBER_FIELDS, C as EmbedSourceRegistry, D as makeReembed, E as makeEmbedPostWrite, F as unknownParams, G as DEFAULT_CRYSTALLISE_CONFIG, H as CRYSTALLISE_IN_FLIGHT_CODE, I as handleRecallRequest, J as runClusterer, K as handleCrystallise, L as RRF_K, M as recallRouteHandler, N as checkParams, O as crystalliseRouteHandler, P as unknownParamMessage, Q as CLUSTERER_BACKEND, R as armRanks, S as createEmbedStats, T as embedRowReporting, U as createCrystalliseGuard, X as l2normalize, _ as EMBEDDINGS_FETCH_MAX_REFS, a as REINDEX_MAX_LIMIT, b as handleLexicalCoverage, c as SALIENCE_BOOST_MAX_TARGETS, d as embeddingsMigration, et as memberKey, f as recallMcpTool, g as embeddingsFetchRouteHandler, h as embeddingSimilarOperator, i as REINDEX_DEFAULT_LIMIT, j as buildClusterSurface, k as CLUSTER_FIELDS, l as lexicalMigration, m as makeLexicalPostWrite, n as salienceBoostRouteHandler, nt as validateSelector, o as handleReindex, p as makeLexicalClassify, q as validateCrystalliseInput, r as reindexRouteHandler, s as validateReindexInput, t as createRecallPlugin, tt as SELECT_CANDIDATES_MAX_LIMIT, u as recallClustersMigration, v as embedStatsRouteHandler, w as embedAndStore, x as validateLexicalCoverageInput, y as handleEmbedStatsRequest, z as fuseByRank } from "./plugin-DpncES1p.js";
|
|
4
4
|
|
|
5
5
|
export { CLUSTERER_BACKEND, CLUSTERER_BACKEND_VERSION, CLUSTER_FIELDS, CLUSTER_MEMBER_FIELDS, CRYSTALLISE_IN_FLIGHT_CODE, DEFAULT_CRYSTALLISE_CONFIG, EMBEDDINGS_FETCH_MAX_REFS, EmbedSourceRegistry, InMemoryClusterStore, InMemoryEmbeddingsStore, InMemoryLexicalStore, PgClusterStore, PgEmbeddingsStore, PgLexicalStore, RECALL_VERSION, REINDEX_DEFAULT_LIMIT, REINDEX_MAX_LIMIT, RRF_K, SALIENCE_BOOST_MAX_TARGETS, SELECT_CANDIDATES_MAX_LIMIT, armRanks, buildClusterSurface, checkParams, createCrystalliseGuard, createEmbedStats, createRecallPlugin, crystalliseRouteHandler, embedAndStore, embedRowReporting, embedStatsRouteHandler, embeddingSimilarOperator, embeddingsFetchRouteHandler, embeddingsMigration, fuseByRank, handleCrystallise, handleEmbedStatsRequest, handleLexicalCoverage, handleRecallRequest, handleReindex, l2normalize, lexicalMigration, makeEmbedPostWrite, makeLexicalClassify, makeLexicalPostWrite, makeReembed, memberKey, recallClustersMigration, recallMcpTool, recallRouteHandler, reindexRouteHandler, runClusterer, salienceBoostRouteHandler, unknownParamMessage, unknownParams, validateCrystalliseInput, validateLexicalCoverageInput, validateReindexInput, validateSelector };
|
|
@@ -36,7 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
39
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/key.js
|
|
40
40
|
const keybindingLookup = /* @__PURE__ */ new Set(["emacs", "vim"]);
|
|
41
41
|
function isKeybinding(value) {
|
|
42
42
|
return keybindingLookup.has(value);
|
|
@@ -55,7 +55,7 @@ const isNumberKey = (key) => "1234567890".includes(key.name);
|
|
|
55
55
|
const isEnterKey = (key) => key.name === "enter" || key.name === "return";
|
|
56
56
|
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
58
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/errors.js
|
|
59
59
|
var AbortPromptError = class extends Error {
|
|
60
60
|
name = "AbortPromptError";
|
|
61
61
|
message = "Prompt was aborted";
|
|
@@ -79,7 +79,7 @@ var ValidationError = class extends Error {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
//#endregion
|
|
82
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
82
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/hook-engine.js
|
|
83
83
|
const hookStorage = new AsyncLocalStorage();
|
|
84
84
|
function createStore(rl) {
|
|
85
85
|
return {
|
|
@@ -174,7 +174,7 @@ const effectScheduler = {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
//#endregion
|
|
177
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
177
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-state.js
|
|
178
178
|
function isFactory(value) {
|
|
179
179
|
return typeof value === "function";
|
|
180
180
|
}
|
|
@@ -199,7 +199,7 @@ function useState(defaultValue) {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
//#endregion
|
|
202
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
202
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-effect.js
|
|
203
203
|
function useEffect(cb, depArray) {
|
|
204
204
|
withPointer((pointer) => {
|
|
205
205
|
const oldDeps = pointer.get();
|
|
@@ -495,7 +495,7 @@ const figures = shouldUseMain ? mainSymbols : fallbackSymbols;
|
|
|
495
495
|
const replacements = Object.entries(specialMainSymbols);
|
|
496
496
|
|
|
497
497
|
//#endregion
|
|
498
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
498
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/theme.js
|
|
499
499
|
const defaultTheme = {
|
|
500
500
|
prefix: {
|
|
501
501
|
idle: styleText("blue", "?"),
|
|
@@ -535,7 +535,7 @@ function getDefaultTheme() {
|
|
|
535
535
|
}
|
|
536
536
|
|
|
537
537
|
//#endregion
|
|
538
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
538
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/make-theme.js
|
|
539
539
|
function isPlainObject(value) {
|
|
540
540
|
if (typeof value !== "object" || value === null) return false;
|
|
541
541
|
let proto = value;
|
|
@@ -555,7 +555,7 @@ function makeTheme(...themes) {
|
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
//#endregion
|
|
558
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
558
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-prefix.js
|
|
559
559
|
function usePrefix({ status = "idle", theme }) {
|
|
560
560
|
const [showLoader, setShowLoader] = useState(false);
|
|
561
561
|
const [tick, setTick] = useState(0);
|
|
@@ -582,7 +582,7 @@ function usePrefix({ status = "idle", theme }) {
|
|
|
582
582
|
}
|
|
583
583
|
|
|
584
584
|
//#endregion
|
|
585
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
585
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-memo.js
|
|
586
586
|
function useMemo(fn, dependencies) {
|
|
587
587
|
return withPointer((pointer) => {
|
|
588
588
|
const prev = pointer.get();
|
|
@@ -599,13 +599,13 @@ function useMemo(fn, dependencies) {
|
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
//#endregion
|
|
602
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
602
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-ref.js
|
|
603
603
|
function useRef(val) {
|
|
604
604
|
return useState({ current: val })[0];
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
//#endregion
|
|
608
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
608
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/use-keypress.js
|
|
609
609
|
function useKeypress(userHandler) {
|
|
610
610
|
const signal = useRef(userHandler);
|
|
611
611
|
signal.current = userHandler;
|
|
@@ -939,7 +939,7 @@ function wrapAnsi(string, columns, options) {
|
|
|
939
939
|
}
|
|
940
940
|
|
|
941
941
|
//#endregion
|
|
942
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
942
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/utils.js
|
|
943
943
|
var import_cli_width = /* @__PURE__ */ __toESM(require_cli_width(), 1);
|
|
944
944
|
/**
|
|
945
945
|
* Force line returns at specific width. This function is ANSI code friendly and it'll
|
|
@@ -966,7 +966,7 @@ function readlineWidth() {
|
|
|
966
966
|
}
|
|
967
967
|
|
|
968
968
|
//#endregion
|
|
969
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
969
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js
|
|
970
970
|
function usePointerPosition({ active, renderedItems, pageSize, loop }) {
|
|
971
971
|
const state = useRef({
|
|
972
972
|
lastPointer: active,
|
|
@@ -1393,7 +1393,7 @@ const eraseLine = "\x1B[2K";
|
|
|
1393
1393
|
const eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + "\x1B[2K\x1B[G" : "";
|
|
1394
1394
|
|
|
1395
1395
|
//#endregion
|
|
1396
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
1396
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/screen-manager.js
|
|
1397
1397
|
const height = (content) => content.split("\n").length;
|
|
1398
1398
|
const lastLine = (content) => content.split("\n").pop() ?? "";
|
|
1399
1399
|
var ScreenManager = class {
|
|
@@ -1451,9 +1451,10 @@ var ScreenManager = class {
|
|
|
1451
1451
|
};
|
|
1452
1452
|
|
|
1453
1453
|
//#endregion
|
|
1454
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
1454
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/create-prompt.js
|
|
1455
1455
|
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
1456
1456
|
const nativeSetImmediate = globalThis.setImmediate;
|
|
1457
|
+
const nativeClearImmediate = globalThis.clearImmediate;
|
|
1457
1458
|
/**
|
|
1458
1459
|
* Register an event listener and return its disposer, so registrations collapse
|
|
1459
1460
|
* into a single statement: `cleanups.add(listenTo(rl, 'close', handler))`.
|
|
@@ -1556,8 +1557,10 @@ function createPrompt(view) {
|
|
|
1556
1557
|
}
|
|
1557
1558
|
});
|
|
1558
1559
|
};
|
|
1559
|
-
if ("readableFlowing" in input)
|
|
1560
|
-
|
|
1560
|
+
if ("readableFlowing" in input) {
|
|
1561
|
+
const immediate = nativeSetImmediate(startCycle);
|
|
1562
|
+
cleanups.add(() => nativeClearImmediate(immediate));
|
|
1563
|
+
} else startCycle();
|
|
1561
1564
|
return promptPromise;
|
|
1562
1565
|
});
|
|
1563
1566
|
};
|
|
@@ -1565,7 +1568,7 @@ function createPrompt(view) {
|
|
|
1565
1568
|
}
|
|
1566
1569
|
|
|
1567
1570
|
//#endregion
|
|
1568
|
-
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.
|
|
1571
|
+
//#region ../../node_modules/.pnpm/@inquirer+core@12.0.5_@types+node@26.6.5/node_modules/@inquirer/core/dist/lib/Separator.js
|
|
1569
1572
|
/**
|
|
1570
1573
|
* Separator object
|
|
1571
1574
|
* Used to space/separate choices group
|
|
@@ -1582,7 +1585,7 @@ var Separator = class {
|
|
|
1582
1585
|
};
|
|
1583
1586
|
|
|
1584
1587
|
//#endregion
|
|
1585
|
-
//#region ../../node_modules/.pnpm/@inquirer+checkbox@5.2.
|
|
1588
|
+
//#region ../../node_modules/.pnpm/@inquirer+checkbox@5.2.7_@types+node@26.6.5/node_modules/@inquirer/checkbox/dist/index.js
|
|
1586
1589
|
const checkboxTheme = {
|
|
1587
1590
|
icon: {
|
|
1588
1591
|
checked: styleText("green", figures.circleFilled),
|
|
@@ -1676,9 +1679,12 @@ var dist_default$3 = createPrompt((config, done) => {
|
|
|
1676
1679
|
const [active, setActive] = useState(bounds.first);
|
|
1677
1680
|
const [errorMsg, setError] = useState();
|
|
1678
1681
|
useKeypress(async (key) => {
|
|
1682
|
+
if (status !== "idle") return;
|
|
1679
1683
|
if (isEnterKey(key)) {
|
|
1684
|
+
setStatus("loading");
|
|
1680
1685
|
const selection = items.filter(isChecked);
|
|
1681
1686
|
const isValid = await validate([...selection]);
|
|
1687
|
+
setStatus("idle");
|
|
1682
1688
|
if (required && !selection.length) setError("At least one choice must be selected");
|
|
1683
1689
|
else if (isValid === true) {
|
|
1684
1690
|
setStatus("done");
|
|
@@ -1767,7 +1773,7 @@ var dist_default$3 = createPrompt((config, done) => {
|
|
|
1767
1773
|
});
|
|
1768
1774
|
|
|
1769
1775
|
//#endregion
|
|
1770
|
-
//#region ../../node_modules/.pnpm/@inquirer+confirm@6.3.
|
|
1776
|
+
//#region ../../node_modules/.pnpm/@inquirer+confirm@6.3.4_@types+node@26.6.5/node_modules/@inquirer/confirm/dist/index.js
|
|
1771
1777
|
const confirmTheme = {
|
|
1772
1778
|
keywords: {
|
|
1773
1779
|
yes: "Yes",
|
|
@@ -1841,7 +1847,7 @@ var dist_default$2 = createPrompt((config, done) => {
|
|
|
1841
1847
|
});
|
|
1842
1848
|
|
|
1843
1849
|
//#endregion
|
|
1844
|
-
//#region ../../node_modules/.pnpm/@inquirer+input@5.1.
|
|
1850
|
+
//#region ../../node_modules/.pnpm/@inquirer+input@5.1.8_@types+node@26.6.5/node_modules/@inquirer/input/dist/index.js
|
|
1845
1851
|
const inputTheme = { validationFailureMode: "keep" };
|
|
1846
1852
|
var dist_default$1 = createPrompt((config, done) => {
|
|
1847
1853
|
const { prefill = "tab" } = config;
|
|
@@ -1911,7 +1917,7 @@ var dist_default$1 = createPrompt((config, done) => {
|
|
|
1911
1917
|
});
|
|
1912
1918
|
|
|
1913
1919
|
//#endregion
|
|
1914
|
-
//#region ../../node_modules/.pnpm/@inquirer+select@5.2.
|
|
1920
|
+
//#region ../../node_modules/.pnpm/@inquirer+select@5.2.7_@types+node@26.6.5/node_modules/@inquirer/select/dist/index.js
|
|
1915
1921
|
const selectTheme = {
|
|
1916
1922
|
icon: { cursor: figures.pointer },
|
|
1917
1923
|
style: {
|
|
@@ -82,6 +82,8 @@ type NlOutcome = {
|
|
|
82
82
|
answer: string;
|
|
83
83
|
/** Absent on the wire when the engine rejected the frame; `errors` then says why. */
|
|
84
84
|
data: unknown;
|
|
85
|
+
/** On a `count` answer: every row the frame matches, across pages; `data` holds only the first page. Absent when counting stopped short, with `errors` saying why. */
|
|
86
|
+
count?: number;
|
|
85
87
|
errors?: unknown[];
|
|
86
88
|
source: 'parser' | 'judge' | 'handoff';
|
|
87
89
|
handoff?: string;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { a as RuntimeErrors, c as BridgeClient, d as BridgeFrame, i as RuntimeEr
|
|
|
3
3
|
import { $ as PolicyProbeContext, A as ScheduledTask, B as StartOpts, C as QualifiedFrame, D as RegistryEntryInput, E as RegistryEntry, F as HttpMethod, G as WsConnection, H as SubstrateResponse, I as PluginRouter, J as AutoCrudVerb, K as WsHandler, L as RequestObservation, M as VirtualMutationDef, N as VirtualTypeDef, O as RegistryEntryKind, P as HttpHandler, Q as PolicyDecision, R as RequestObserver, S as PostWriteHook, St as WriteResult, T as RegistryBase, U as SubstrateServer, V as SubstrateRequest, W as TlsConfig, X as Obligation, Y as Identity, Z as Policy, _ as NamespaceDefinition, _t as ReadResult, a as EngineHandle, at as TypedResolver, b as PluginLifecycleContext, bt as WhereClause, c as FrameEntry, ct as Dataset, d as KernelMigrationContext, dt as DropResult, et as RequestContext, f as KernelNamespaceContribution, ft as FieldKind, g as NamespaceConfig, gt as ReadParams, h as McpToolRegistration, ht as OrderByClause, i as EncodeContext, it as RowFilterObligation, j as ScheduledTaskContext, k as RegistryEntryResolver, l as KernelLifecycleContext, lt as DatasetRegistry, m as KernelRouteClaim, mt as FilterCapabilities, n as DropParticipant, nt as ResolverArgs, o as EngineInput, ot as WriteEvent, p as KernelPlugin, pt as FieldPredicate, q as AfterTxWork, r as EmbedSourceContext, rt as ResolverReturn, s as FilterOperatorDef, st as ConditionalUpdateResult, t as CoordinatorPlugin, tt as Resolver, u as KernelMigration, ut as DeleteResult, v as NamespaceInstallContext, vt as TxScopeHandles, w as Registry, x as PluginRouteContext, xt as WriteOptions, y as NamespaceTypeDef, yt as UpdateFieldRef, z as RuntimeOp } from "./plugin-t2g2wX0b.js";
|
|
4
4
|
import { a as ResolverFrameError, c as isAuthCause, i as ReservedField, l as isResolverFrameError, n as MissingReferentError, o as RestrictViolation, r as NamespaceMismatch, s as UnsupportedFilterError, t as BridgeUnreachableError, u as isRestrictViolation } from "./errors-D4vKuwz8.js";
|
|
5
5
|
import { a as WsResponseFrame, c as ResolveTarget, d as TargetState, f as IdempotencyStore, i as WsRequestFrame, l as SweepDeps, n as WS_REASON_SERVER_RESTART, o as WsResponseKind, r as WS_REASON_SUBSCRIPTION_OVERLOADED, s as BridgeRegistry, t as WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, u as SweepState } from "./ws-C72iVS5T.js";
|
|
6
|
-
import { $ as NlJudgeStep, 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, J as NlAskRequest, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, Q as NlJudgeChoice, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlEvidence, Y as NlAskResult, Z as NlJudgeAction, _ as newlyGrantedPairs, a as denyAll, at as NlPackType, b as capabilitiesFor, c as requireIdentity, ct as NlParsedData, d as KeyUpdateRefusal, dt as NlValueAlias, et as NlJudgedStatus, f as checkRevocable, ft as NlWireEvent, g as newlyGranted, gt as Query, h as grantEntriesConfer, ht as NLVocabularyHint, i as allowVerbs, it as NlPackField, j as not, k as encodeList, l as requireNamespace, lt as NlServedPack, m as grantCovers, mt as NLResult, n as row, nt as NlNamespaceRulings, o as denyVerbs, ot as NlPackValueRef, p as checkUpdatable, pt as NLBase, q as resolveDefaultKidPath, r as allowAll, rt as NlOutcome, s as requireCapability, st as NlParseStatus, t as applyRowFilters, tt as NlNamespacePack, u as KeyMutationRefusal, ut as NlTrailEvent, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-
|
|
6
|
+
import { $ as NlJudgeStep, 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, J as NlAskRequest, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, Q as NlJudgeChoice, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlEvidence, Y as NlAskResult, Z as NlJudgeAction, _ as newlyGrantedPairs, a as denyAll, at as NlPackType, b as capabilitiesFor, c as requireIdentity, ct as NlParsedData, d as KeyUpdateRefusal, dt as NlValueAlias, et as NlJudgedStatus, f as checkRevocable, ft as NlWireEvent, g as newlyGranted, gt as Query, h as grantEntriesConfer, ht as NLVocabularyHint, i as allowVerbs, it as NlPackField, j as not, k as encodeList, l as requireNamespace, lt as NlServedPack, m as grantCovers, mt as NLResult, n as row, nt as NlNamespaceRulings, o as denyVerbs, ot as NlPackValueRef, p as checkUpdatable, pt as NLBase, q as resolveDefaultKidPath, r as allowAll, rt as NlOutcome, s as requireCapability, st as NlParseStatus, t as applyRowFilters, tt as NlNamespacePack, u as KeyMutationRefusal, ut as NlTrailEvent, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-SRhura12.js";
|
|
7
7
|
//#region ../../packages/substrate-types/src/assert-never.d.ts
|
|
8
8
|
/**
|
|
9
9
|
* Exhaustiveness guard for the `default:` arm of a `switch` over a
|
package/dist/sdk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { $ as error400, A as resolveIdentity, At as CLIENT_SUPPLIED_SERVER_FIELD, C as purgeResolver, Ct as ReservedField, D as deleteRow, Dt as isAuthCause, E as deleteResolver, Et as UnsupportedFilterError, M as resolveEntityRow, Mt as canonicalize, Nt as BootstrapConfigError, O as createResolver, Ot as isResolverFrameError, Pt as defineBootstrap, S as updateResolver, St as NamespaceMismatch, T as getResolver, Tt as RestrictViolation, Z as JSON_HEADERS, _ as field, _t as createKeyedMutex, at as WS_REASON_SERVER_RESTART, b as installAutoCrud, bt as BridgeUnreachableError, ct as normaliseVocabValues, dt as vocabImplication, et as jsonResponse, ft as RegistryBase, g as RESERVED_AUTOCRUD_FIELD_NAMES, gt as normaliseMetadataWhere, h as RESERVED_AUTOCRUD_FIELDS, ht as normaliseMetadataOrderBy, it as WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, j as resolveEntityId, jt as ROW_METADATA_FIELDS, k as UnattributedWriteError, kt as isRestrictViolation, lt as normaliseVocabWhere, m as defineNamespace, mt as METADATA_FILTER_FIELDS, ot as WS_REASON_SUBSCRIPTION_OVERLOADED, pt as METADATA_AUTHOR_FIELDS, st as canonicalVocabValue, tt as parseJsonBody, ut as storedVocabSpellings, v as autoCrudOptionsOf, vt as assertHardDeleteAllowed, w as listResolver, wt as ResolverFrameError, x as applyUpdatePatch, xt as MissingReferentError, y as createResolverWithEdges, yt as validateHardDeleteEnv } from "./src-
|
|
2
|
+
import { $ as error400, A as resolveIdentity, At as CLIENT_SUPPLIED_SERVER_FIELD, C as purgeResolver, Ct as ReservedField, D as deleteRow, Dt as isAuthCause, E as deleteResolver, Et as UnsupportedFilterError, M as resolveEntityRow, Mt as canonicalize, Nt as BootstrapConfigError, O as createResolver, Ot as isResolverFrameError, Pt as defineBootstrap, S as updateResolver, St as NamespaceMismatch, T as getResolver, Tt as RestrictViolation, Z as JSON_HEADERS, _ as field, _t as createKeyedMutex, at as WS_REASON_SERVER_RESTART, b as installAutoCrud, bt as BridgeUnreachableError, ct as normaliseVocabValues, dt as vocabImplication, et as jsonResponse, ft as RegistryBase, g as RESERVED_AUTOCRUD_FIELD_NAMES, gt as normaliseMetadataWhere, h as RESERVED_AUTOCRUD_FIELDS, ht as normaliseMetadataOrderBy, it as WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, j as resolveEntityId, jt as ROW_METADATA_FIELDS, k as UnattributedWriteError, kt as isRestrictViolation, lt as normaliseVocabWhere, m as defineNamespace, mt as METADATA_FILTER_FIELDS, ot as WS_REASON_SUBSCRIPTION_OVERLOADED, pt as METADATA_AUTHOR_FIELDS, st as canonicalVocabValue, tt as parseJsonBody, ut as storedVocabSpellings, v as autoCrudOptionsOf, vt as assertHardDeleteAllowed, w as listResolver, wt as ResolverFrameError, x as applyUpdatePatch, xt as MissingReferentError, y as createResolverWithEdges, yt as validateHardDeleteEnv } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { a as adminClaimCapabilities, c as makeTokenProvider, d as resolveDefaultKidPath, i as DEFAULT_CAPABILITIES, l as resolveAdminCredential, n as trimTrailingSlashes, o as isEncryptedKey, r as ADMIN_CAPABILITIES, s as makeAuthorizationProvider, t as parsePositiveInt, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
|
|
4
4
|
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, d as confersAnywhere, f as coversNamespace, g as checkUpdatable, h as checkRevocable, i as allowVerbs, j as flattenGrant, k as encodeGrant, l as requireNamespace, m as grantedIn, n as row, o as denyVerbs, p as grantOf, r as allowAll, s as requireCapability, t as applyRowFilters, u as allCapabilities, v as grantEntriesConfer, w as or, x as revokedAtIso, y as newlyGranted } from "./row-DZ0Fnpc6.js";
|
|
5
5
|
import { S as assertNever, b as formatQualifiedKey, x as parseQualifiedKey } from "./src-BLgbLq2k.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { Ct as ReservedField, Et as UnsupportedFilterError, H as assertJsonPathPredicate, J as fullBuiltinOperators, K as decodeCursor, St as NamespaceMismatch, U as isJsonPathPredicate, V as preResolveExtensionOperatorsDetailed, X as fieldRequested, Y as applyExtensionResultMeta, _t as createKeyedMutex, q as encodeCursor } from "./src-
|
|
2
|
+
import { Ct as ReservedField, Et as UnsupportedFilterError, H as assertJsonPathPredicate, J as fullBuiltinOperators, K as decodeCursor, St as NamespaceMismatch, U as isJsonPathPredicate, V as preResolveExtensionOperatorsDetailed, X as fieldRequested, Y as applyExtensionResultMeta, _t as createKeyedMutex, q as encodeCursor } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
|
|
5
5
|
//#region ../../packages/substrate-dataset-pg/src/advisory-lock.ts
|
|
@@ -652,7 +652,7 @@ var PgShortIdStore = class {
|
|
|
652
652
|
})), "namespace", "type", "short_id", "row_id")}
|
|
653
653
|
ON CONFLICT (namespace, type, short_id) DO NOTHING
|
|
654
654
|
`;
|
|
655
|
-
const max = entries.reduce((m, e) =>
|
|
655
|
+
const max = entries.reduce((m, e) => Math.max(m, e.shortId), 0);
|
|
656
656
|
const name = await this.ensureSequence(ns, type);
|
|
657
657
|
await this.sql.unsafe(`SELECT setval('"${name}"', GREATEST((SELECT last_value FROM "${name}"), ${max}))`);
|
|
658
658
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { n as txScopeIdFor } from "./src-
|
|
3
|
-
import { B as ROW_FILTER_FIELD, V as matchesRowFilter, W as inFlightError, Y as unresolvedRow, Z as cosineSimilarity, et as memberKey } from "./plugin-
|
|
2
|
+
import { n as txScopeIdFor } from "./src-BD27zeGF.js";
|
|
3
|
+
import { B as ROW_FILTER_FIELD, V as matchesRowFilter, W as inFlightError, Y as unresolvedRow, Z as cosineSimilarity, et as memberKey } from "./plugin-DpncES1p.js";
|
|
4
4
|
|
|
5
5
|
//#region ../../plugins/substrate-recall/package.json
|
|
6
|
-
var version = "1.0.0-alpha.
|
|
6
|
+
var version = "1.0.0-alpha.9";
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region ../../plugins/substrate-recall/src/in-memory-cluster-store.ts
|
|
@@ -870,6 +870,24 @@ var PgEmbeddingsStore = class {
|
|
|
870
870
|
*
|
|
871
871
|
* @returns number of orphaned embeddings deleted.
|
|
872
872
|
*/
|
|
873
|
+
async staleRowIds(input) {
|
|
874
|
+
return (await this.#sql`
|
|
875
|
+
SELECT r.id FROM rows r
|
|
876
|
+
WHERE r.namespace = ${input.namespace}
|
|
877
|
+
AND r.type = ${input.type}
|
|
878
|
+
AND r.deleted_at IS NULL
|
|
879
|
+
AND r.id > ${input.afterId}
|
|
880
|
+
AND NOT EXISTS (
|
|
881
|
+
SELECT 1 FROM embeddings e
|
|
882
|
+
WHERE e.row_namespace = r.namespace
|
|
883
|
+
AND e.row_type = r.type
|
|
884
|
+
AND e.row_id = r.id
|
|
885
|
+
AND (r.updated_at IS NULL OR e.updated_at >= r.updated_at)
|
|
886
|
+
)
|
|
887
|
+
ORDER BY r.id
|
|
888
|
+
LIMIT ${input.limit}
|
|
889
|
+
`).map((r) => r.id);
|
|
890
|
+
}
|
|
873
891
|
async purgeOrphans() {
|
|
874
892
|
return (await this.#sql`
|
|
875
893
|
DELETE FROM embeddings e
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { A as resolveIdentity, F as publishSchema, Z as JSON_HEADERS, _ as field, b as installAutoCrud, h as RESERVED_AUTOCRUD_FIELDS, l as migrateFieldValues, m as defineNamespace, v as autoCrudOptionsOf, wt as ResolverFrameError } from "./src-
|
|
2
|
+
import { A as resolveIdentity, F as publishSchema, Z as JSON_HEADERS, _ as field, b as installAutoCrud, h as RESERVED_AUTOCRUD_FIELDS, l as migrateFieldValues, m as defineNamespace, v as autoCrudOptionsOf, wt as ResolverFrameError } from "./src-DjIuRjzF.js";
|
|
3
3
|
import { s as requireCapability } from "./row-DZ0Fnpc6.js";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
|
|
@@ -1742,6 +1742,10 @@ var WsTransport = class {
|
|
|
1742
1742
|
if (this.#destroyed) throw new NetworkError("WsTransport destroyed", null);
|
|
1743
1743
|
try {
|
|
1744
1744
|
const mux = await this.#openOnce();
|
|
1745
|
+
if (this.#destroyed) {
|
|
1746
|
+
mux.close();
|
|
1747
|
+
throw new NetworkError("WsTransport destroyed", null);
|
|
1748
|
+
}
|
|
1745
1749
|
scheduler.reset();
|
|
1746
1750
|
this.#hasOpened = true;
|
|
1747
1751
|
this.#mux = mux;
|
|
@@ -5462,7 +5462,8 @@ var Engine = class {
|
|
|
5462
5462
|
const entry = frame[key];
|
|
5463
5463
|
if (entry === void 0) continue;
|
|
5464
5464
|
const parsed = parsedByKey.get(key) ?? null;
|
|
5465
|
-
|
|
5465
|
+
const errorsBefore = envelope.errors?.length ?? 0;
|
|
5466
|
+
if (await this.#runEntry(envelope, key, entry, ctx, "mutate", parsed === null ? null : txFor(parsed.ns), txEdges, parsed, (event) => pending.push(event), signal, (fn) => settled.push(fn)) || (envelope.errors ?? []).slice(errorsBefore).some((e) => e.path?.[0] === key)) {
|
|
5466
5467
|
refusedKey = key;
|
|
5467
5468
|
throw new SharedTxRefusal();
|
|
5468
5469
|
}
|
|
@@ -11636,6 +11637,18 @@ const WS_INSTRUCTIONS = {
|
|
|
11636
11637
|
]
|
|
11637
11638
|
}
|
|
11638
11639
|
};
|
|
11640
|
+
const CODE_MODE_INSTRUCTIONS = {
|
|
11641
|
+
command: "substrate run <script.mts> [--args <json>] [--dry-run | --write] [--max-writes <n>] [--out <file>]",
|
|
11642
|
+
summary: "For an agent with a shell: run a TypeScript script whose default export receives a signed client, so many reads and writes cost one call and return one small JSON report. It composes the operations above; it adds none, and every call meets the same grants and policy.",
|
|
11643
|
+
when: "a count or census over many rows, a join across types, recall followed by fetching the bodies of the hits worth reading, or a batch of writes chosen by what a read found. One lookup or one write is simpler as a direct query or mutate",
|
|
11644
|
+
context: "the default export gets `s` with `args`, `query(frame)`, `queryAll(key, { params, fields })`, `recall({ query, namespace, type, ... })`, `mutate(payload)` and `log(...)`; return a reduced result (counts, ids, a verdict), not whole rows",
|
|
11645
|
+
notes: [
|
|
11646
|
+
"signs from SUBSTRATE_URL, SUBSTRATE_AGENT_KEY_ID and SUBSTRATE_AGENT_KEY_PATH, and refuses to run unsigned",
|
|
11647
|
+
"read-only by default: `mutate` throws unless `--dry-run` (records each payload and sends nothing) or `--write` (sends up to `--max-writes` frames, default 50). Dry-run first, read the recorded mutations, then write",
|
|
11648
|
+
"a frame the server rejected fails the run with its error rather than reading as empty; a truncated `query` is reported in `warnings`, and `queryAll` pages to the end",
|
|
11649
|
+
"stdout is one report `{ ok, kid, mode, args, result, error?, mutations, warnings, stats }`; `mutations` lists every payload with `applied`, including those sent before a failure. Exit codes: 0 ok, 1 the script failed, 2 usage or configuration"
|
|
11650
|
+
]
|
|
11651
|
+
};
|
|
11639
11652
|
const AUTH_INSTRUCTIONS = {
|
|
11640
11653
|
summary: "Bearer-JWT auth (§5.12). Present `Authorization: Bearer <jwt>` on every request, onboard included. Only /health, /substrate/v1/whoami and /substrate/v1/_system/register answer without one. Two paths to a token: (a) the invite→register exchange for a namespace-scoped JWT, or (b) a pre-registered per-principal key you sign with directly (the agent-identity path — see `identity`). How a MISSING token is treated depends on `mode`.",
|
|
11641
11654
|
modes: {
|
|
@@ -11679,8 +11692,8 @@ function buildFrameGrammar(coordinators) {
|
|
|
11679
11692
|
return {
|
|
11680
11693
|
queryKey: "<ns>/<TypeName>",
|
|
11681
11694
|
mutationKey: "<ns>/<mutationName>",
|
|
11682
|
-
batched: "A mutate op-key MAY carry an Array<FrameEntry>. All frames under one op-key run serially inside the same transaction (all-or-nothing per op-key)
|
|
11683
|
-
example: `{ "${exampleNs}/Todo": { "params": {"status": "open"}, "fields": {"id": true, "title": true} }, "${exampleNs}/createTodo": [{ "params": {"title": "first"}, "fields": {"id": true} }, { "params": {"title": "second"}, "fields": {"id": true} }] }`
|
|
11695
|
+
batched: "A mutate op-key MAY carry an Array<FrameEntry>. All frames under one array op-key run serially inside the same transaction (all-or-nothing per op-key), and each array op-key commits independently of every other op-key. The single-frame op-keys of one call share their own transaction: if any of them is refused, all of them roll back with `frame_rolled_back`. Query/subscribe/stream op-keys reject array values.",
|
|
11696
|
+
example: `{ "${exampleNs}/Todo": { "params": {"where": {"status": {"eq": "open"}}}, "fields": {"id": true, "title": true} }, "${exampleNs}/createTodo": [{ "params": {"title": "first"}, "fields": {"id": true} }, { "params": {"title": "second"}, "fields": {"id": true} }] }`
|
|
11684
11697
|
};
|
|
11685
11698
|
}
|
|
11686
11699
|
function buildPluginContributions(plugins) {
|
|
@@ -11723,6 +11736,7 @@ function buildOnboardBody(deps) {
|
|
|
11723
11736
|
stream: WS_INSTRUCTIONS.stream,
|
|
11724
11737
|
substratePack: WS_INSTRUCTIONS.substratePack,
|
|
11725
11738
|
sse: WS_INSTRUCTIONS.sse,
|
|
11739
|
+
codeMode: CODE_MODE_INSTRUCTIONS,
|
|
11726
11740
|
plugins: buildPluginContributions(deps.coordinators),
|
|
11727
11741
|
pluginRoutes: buildPluginRoutes(deps.coordinators)
|
|
11728
11742
|
};
|
package/dist/substrate-admin.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
3
|
-
import { d as buildAuditRow, f as AUDIT_EVENT_TYPE } from "./src-
|
|
3
|
+
import { d as buildAuditRow, f as AUDIT_EVENT_TYPE } from "./src-DjIuRjzF.js";
|
|
4
4
|
import { d as resolveDefaultKidPath, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
|
|
5
5
|
import { E as describeGrant, I as decodeList, L as encodeList, M as grantEntryError, g as checkUpdatable, h as checkRevocable, y as newlyGranted } from "./row-DZ0Fnpc6.js";
|
|
6
|
-
import { w as reconcileIdentities } from "./src-
|
|
7
|
-
import { A as describeAdminTarget, B as version, C as CLI_ACTOR_KID, D as listActiveAdminKeys, E as generateAdminKeypair, F as RESTART_NOTE, I as USAGE, L as argvError, M as resolveAdminTarget, N as ARGV_SPEC, O as readEd25519PublicKey, P as validateArgv, S as BootstrapError, T as forUpdate, _ as REVOKE_EXIT_CODES, a as formatRegisterOutput, b as runKeyPatchViaRoute, c as runRegisterViaRoute, d as formatDoctorReport, f as runDoctor, g as bootstrapKidPath, h as runBootstrap, i as runOnboard, j as resolveAdminAuth, k as readKeyById, l as grantLines, m as parseBootstrapArgs, n as formatChecklist, o as parseRegisterArgs, p as formatBootstrapOutput, r as onboardCommand, s as runRegister, t as openPgDataset, u as doctorCommand, v as UPDATE_EXIT_CODES, w as base64Url, x as ACTOR_HINT, y as runKeyListViaRoute, z as AdminCliError } from "./dataset-
|
|
6
|
+
import { w as reconcileIdentities } from "./src-DiNTSaFk.js";
|
|
7
|
+
import { A as describeAdminTarget, B as version, C as CLI_ACTOR_KID, D as listActiveAdminKeys, E as generateAdminKeypair, F as RESTART_NOTE, I as USAGE, L as argvError, M as resolveAdminTarget, N as ARGV_SPEC, O as readEd25519PublicKey, P as validateArgv, S as BootstrapError, T as forUpdate, _ as REVOKE_EXIT_CODES, a as formatRegisterOutput, b as runKeyPatchViaRoute, c as runRegisterViaRoute, d as formatDoctorReport, f as runDoctor, g as bootstrapKidPath, h as runBootstrap, i as runOnboard, j as resolveAdminAuth, k as readKeyById, l as grantLines, m as parseBootstrapArgs, n as formatChecklist, o as parseRegisterArgs, p as formatBootstrapOutput, r as onboardCommand, s as runRegister, t as openPgDataset, u as doctorCommand, v as UPDATE_EXIT_CODES, w as base64Url, x as ACTOR_HINT, y as runKeyListViaRoute, z as AdminCliError } from "./dataset-CqrqTYPz.js";
|
|
8
8
|
import { existsSync, mkdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { dirname } from "node:path";
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
package/dist/substrate.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
3
|
-
import { B as saveSweepState, G as registerExtensionOperator, I as effectiveFilterOperators, N as MemoryEdgesStore, Q as buildContext, R as loadSweepState, W as getExtensionOperator, a as composeFromManifests, at as WS_REASON_SERVER_RESTART, bt as BridgeUnreachableError, c as MemoryDataset, d as buildAuditRow, f as AUDIT_EVENT_TYPE, i as PluginLoadError, n as kernelMigrationTracking, nt as parseAuthConfig, o as DEFAULT_NAMESPACE, p as INVITE_TYPE, r as mountKernelRoute, s as compose, t as composeKernelPlugins, u as runInviteSweep, yt as validateHardDeleteEnv, z as runSweep } from "./src-
|
|
3
|
+
import { B as saveSweepState, G as registerExtensionOperator, I as effectiveFilterOperators, N as MemoryEdgesStore, Q as buildContext, R as loadSweepState, W as getExtensionOperator, a as composeFromManifests, at as WS_REASON_SERVER_RESTART, bt as BridgeUnreachableError, c as MemoryDataset, d as buildAuditRow, f as AUDIT_EVENT_TYPE, i as PluginLoadError, n as kernelMigrationTracking, nt as parseAuthConfig, o as DEFAULT_NAMESPACE, p as INVITE_TYPE, r as mountKernelRoute, s as compose, t as composeKernelPlugins, u as runInviteSweep, yt as validateHardDeleteEnv, z as runSweep } from "./src-DjIuRjzF.js";
|
|
4
4
|
import { n as trimTrailingSlashes, s as makeAuthorizationProvider, t as parsePositiveInt } from "./env-utils-CGNazUNt.js";
|
|
5
5
|
import { L as encodeList, T as SYSTEM_NAMESPACE, f as coversNamespace, m as grantedIn, p as grantOf } from "./row-DZ0Fnpc6.js";
|
|
6
|
-
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-
|
|
6
|
+
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-DiNTSaFk.js";
|
|
7
7
|
import { n as runScript, t as DEFAULT_MAX_WRITES } from "./script-C6DSa_Na.js";
|
|
8
|
-
import { a as runDerivedMigrations, o as runMigrations, r as deriveListIndexMigration, s as tryWithPgAdvisoryLock, t as PgDataset } from "./src-
|
|
9
|
-
import { t as PgEdgesStore } from "./pg-edges-store-
|
|
10
|
-
import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore } from "./src-
|
|
11
|
-
import { B as version, R as openSql, t as openPgDataset, z as AdminCliError } from "./dataset-
|
|
8
|
+
import { a as runDerivedMigrations, o as runMigrations, r as deriveListIndexMigration, s as tryWithPgAdvisoryLock, t as PgDataset } from "./src-BD27zeGF.js";
|
|
9
|
+
import { t as PgEdgesStore } from "./pg-edges-store-KH_FQCxx.js";
|
|
10
|
+
import { a as InMemoryLexicalStore, i as PgClusterStore, n as PgLexicalStore, o as InMemoryEmbeddingsStore, r as PgEmbeddingsStore, s as InMemoryClusterStore } from "./src-C12EA0w9.js";
|
|
11
|
+
import { B as version, R as openSql, t as openPgDataset, z as AdminCliError } from "./dataset-CqrqTYPz.js";
|
|
12
12
|
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { homedir, hostname } from "node:os";
|
|
14
14
|
import { basename, dirname, join, resolve } from "node:path";
|
|
@@ -2622,24 +2622,29 @@ var PluginManifestError = class extends Error {
|
|
|
2622
2622
|
}
|
|
2623
2623
|
};
|
|
2624
2624
|
async function listPluginManifests(pluginDir) {
|
|
2625
|
+
const declared = await declaredDependencies(pluginDir);
|
|
2626
|
+
if (declared.size === 0) return [];
|
|
2625
2627
|
const nodeModulesDir = resolve(pluginDir, "node_modules");
|
|
2626
|
-
if (!await isDirectory(nodeModulesDir))
|
|
2627
|
-
const packageDirs = await listPackageDirs(nodeModulesDir,
|
|
2628
|
+
if (!await isDirectory(nodeModulesDir)) throw new PluginManifestError(void 0, `${pluginDir}/package.json lists ${[...declared].join(", ")} but there is no node_modules: run \`pnpm install\` in ${pluginDir}`);
|
|
2629
|
+
const packageDirs = await listPackageDirs(nodeModulesDir, declared);
|
|
2628
2630
|
const manifests = [];
|
|
2629
2631
|
for (const packageDir of packageDirs) manifests.push(...await readManifestsIfPresent(packageDir));
|
|
2632
|
+
if (manifests.length === 0) process.stderr.write(`substrate: SUBSTRATE_PLUGIN_DIR=${pluginDir} lists ${[...declared].join(", ")}, none of which is an installed substrate plugin; booting without plugins\n`);
|
|
2630
2633
|
return manifests;
|
|
2631
2634
|
}
|
|
2632
2635
|
/**
|
|
2633
2636
|
* The names `<pluginDir>/package.json` lists under `dependencies`. Only these
|
|
2634
2637
|
* are plugin candidates: a transitive package hoisted into `node_modules` is
|
|
2635
|
-
* not something the operator chose to run.
|
|
2638
|
+
* not something the operator chose to run. A missing package.json refuses
|
|
2639
|
+
* boot, since a plugin dir that can name no plugin is a misconfiguration.
|
|
2636
2640
|
*/
|
|
2637
2641
|
async function declaredDependencies(pluginDir) {
|
|
2638
2642
|
let raw;
|
|
2639
2643
|
try {
|
|
2640
2644
|
raw = await readFile(resolve(pluginDir, "package.json"), "utf8");
|
|
2641
|
-
} catch {
|
|
2642
|
-
|
|
2645
|
+
} catch (err) {
|
|
2646
|
+
if (err.code !== "ENOENT") throw err;
|
|
2647
|
+
throw new PluginManifestError(void 0, `SUBSTRATE_PLUGIN_DIR=${pluginDir} has no package.json, so no plugin can load. List each plugin under "dependencies" there (\`substrate init\` writes one) and run \`pnpm install\`, or unset SUBSTRATE_PLUGIN_DIR to boot without plugins`);
|
|
2643
2648
|
}
|
|
2644
2649
|
let parsed;
|
|
2645
2650
|
try {
|
|
@@ -4356,7 +4361,7 @@ async function runInit(argv) {
|
|
|
4356
4361
|
return 1;
|
|
4357
4362
|
}
|
|
4358
4363
|
if (!config.yes) try {
|
|
4359
|
-
const { runRepl } = await import("./repl-
|
|
4364
|
+
const { runRepl } = await import("./repl-DeKzfvNV.js");
|
|
4360
4365
|
config = await runRepl(config);
|
|
4361
4366
|
} catch (err) {
|
|
4362
4367
|
if (err.message?.includes("User force closed")) return 130;
|
|
@@ -4641,6 +4646,78 @@ function makeAgentJwtProvider(env, audience) {
|
|
|
4641
4646
|
return () => provider();
|
|
4642
4647
|
}
|
|
4643
4648
|
|
|
4649
|
+
//#endregion
|
|
4650
|
+
//#region src/mcp/schema-overview.ts
|
|
4651
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
4652
|
+
const ENUM_VALUE = /^[A-Za-z0-9_./-]{1,40}$/;
|
|
4653
|
+
const MAX_ENUM_VALUES = 20;
|
|
4654
|
+
const MAX_ENUM_TEXT = 200;
|
|
4655
|
+
function safe(text, pattern) {
|
|
4656
|
+
return typeof text === "string" && pattern.test(text) ? text : "<unsafe>";
|
|
4657
|
+
}
|
|
4658
|
+
function enumText(values) {
|
|
4659
|
+
const shown = [];
|
|
4660
|
+
let length = 0;
|
|
4661
|
+
for (const v of values.slice(0, MAX_ENUM_VALUES)) {
|
|
4662
|
+
const text = safe(v, ENUM_VALUE);
|
|
4663
|
+
if (length + text.length > MAX_ENUM_TEXT) break;
|
|
4664
|
+
shown.push(text);
|
|
4665
|
+
length += text.length + 1;
|
|
4666
|
+
}
|
|
4667
|
+
return [...shown, ...shown.length < values.length ? ["…"] : []].join("|");
|
|
4668
|
+
}
|
|
4669
|
+
function fieldType(f, ns) {
|
|
4670
|
+
let t;
|
|
4671
|
+
if (f.kind === "list" && f.of !== void 0) t = `${fieldType(f.of, ns)}[]`;
|
|
4672
|
+
else if (f.kind === "crossRef") t = `→${f.ns === ns || f.ns === void 0 ? "" : `${safe(f.ns, NAME)}/`}${safe(f.type, NAME)}`;
|
|
4673
|
+
else if (f.kind === "struct") t = `{${Object.keys(f.fields ?? {}).map((k) => safe(k, NAME)).join(", ")}}`;
|
|
4674
|
+
else if (Array.isArray(f.enum)) t = f.nullable ? `(${enumText(f.enum)})` : enumText(f.enum);
|
|
4675
|
+
else t = safe(f.type ?? f.kind, NAME);
|
|
4676
|
+
const tags = [];
|
|
4677
|
+
if (f.indexed === false) tags.push("unindexed");
|
|
4678
|
+
if (f.readonly === true || f.serverSet !== void 0 && f.serverSet !== false) tags.push("readonly");
|
|
4679
|
+
return `${t}${f.nullable ? "?" : ""}${tags.length > 0 ? ` [${tags.join(", ")}]` : ""}`;
|
|
4680
|
+
}
|
|
4681
|
+
const AUTO_CRUD = /^(get|create|update|delete)(.+)$/;
|
|
4682
|
+
function schemaOverview(federated) {
|
|
4683
|
+
const out = {};
|
|
4684
|
+
for (const [ns, schema] of Object.entries(federated)) {
|
|
4685
|
+
const typeDefs = schema.types ?? {};
|
|
4686
|
+
const types = {};
|
|
4687
|
+
for (const [name, def] of Object.entries(typeDefs)) types[safe(name, NAME)] = Object.entries(def.fields ?? {}).map(([field, shape]) => `${safe(field, NAME)}: ${fieldType(shape, ns)}`).join(", ");
|
|
4688
|
+
const mutations = Object.keys(schema.mutations ?? {}).filter((m) => {
|
|
4689
|
+
const crud = AUTO_CRUD.exec(m);
|
|
4690
|
+
return !(crud?.[2] !== void 0 && crud[2] in typeDefs);
|
|
4691
|
+
}).map((m) => safe(m, NAME));
|
|
4692
|
+
out[safe(ns, NAME)] = mutations.length > 0 ? {
|
|
4693
|
+
types,
|
|
4694
|
+
mutations
|
|
4695
|
+
} : { types };
|
|
4696
|
+
}
|
|
4697
|
+
return out;
|
|
4698
|
+
}
|
|
4699
|
+
/** How to read the overview; rides beside it in the tool result and the instructions. */
|
|
4700
|
+
const OVERVIEW_LEGEND = "Each type is `field: type` pairs. `a|b` is an enum, `?` nullable, `T[]` a list, `→Type` a reference (`→ns/Type` across namespaces). [unindexed] fields need `_allowTableScan` to filter on; [readonly] fields are server-set. Generated get/create/update/delete<Type> mutations are not listed; `mutations` holds the rest. For a type's exact write contract call `schema` with `namespace` and `type`.";
|
|
4701
|
+
/** Past this, the instructions carry only type names; the full overview is one `schema` call away. */
|
|
4702
|
+
const INSTRUCTIONS_OVERVIEW_MAX = 12e3;
|
|
4703
|
+
const CONVENTIONS = [
|
|
4704
|
+
"Substrate holds typed records. Every query and mutate key is qualified: `<namespace>/<Type>` or `<namespace>/<mutation>`.",
|
|
4705
|
+
"- Filters go in `params.where`, never top-level params: `{ \"ns/Type\": { \"params\": { \"where\": { \"status\": { \"eq\": \"open\" } }, \"limit\": 20 }, \"fields\": { \"id\": true } } }`. A refused operator is named with the field and its kind; read it rather than guessing.",
|
|
4706
|
+
"- Read `errors` before `data`. A refused frame is ABSENT from `data`; a present empty list means nothing matched. A read with `_pagination.hasMore` is truncated: page with `nextCursor` (default page 100, max 1000).",
|
|
4707
|
+
"- Lists, counts and joins are exact `query` frames; `recall` (similarity search) needs `query`, `namespace` and `type`, and is for finding records by meaning.",
|
|
4708
|
+
"- In one `mutate` call the single-frame keys commit together or not at all, and an array under one key is one transaction. Send unrelated writes as separate calls.",
|
|
4709
|
+
"- `createdAt`, `updatedAt`, `createdBy` and `updatedBy` are server-set: never send them; read them through `_metadata`.",
|
|
4710
|
+
"- `whoami` says which identity this session reads and writes as.",
|
|
4711
|
+
"- With a shell, `substrate run <script.mts>` runs many reads and writes in one call and returns one small report (GET /substrate/v1/onboard, `instructions.codeMode`)."
|
|
4712
|
+
].join("\n");
|
|
4713
|
+
/** The MCP `instructions` text: the conventions, then this server's types as of session start. */
|
|
4714
|
+
function buildInstructions(overview) {
|
|
4715
|
+
if (overview === null) return `${CONVENTIONS}\n\nThe type list was unavailable at session start; call \`schema\` with no arguments for it.`;
|
|
4716
|
+
const full = JSON.stringify(overview);
|
|
4717
|
+
const body = full.length <= INSTRUCTIONS_OVERVIEW_MAX ? `${OVERVIEW_LEGEND}\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)])))}`;
|
|
4718
|
+
return `${CONVENTIONS}\n\nTypes on this server at session start:\n${body}`;
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4644
4721
|
//#endregion
|
|
4645
4722
|
//#region src/mcp/server.ts
|
|
4646
4723
|
/**
|
|
@@ -4796,6 +4873,15 @@ function createSchemaHandler(endpoint) {
|
|
|
4796
4873
|
const ns = args?.namespace;
|
|
4797
4874
|
const type = args?.type;
|
|
4798
4875
|
const shape = args?.shape;
|
|
4876
|
+
if ((ns === void 0 || ns === "") && args?.full !== true) try {
|
|
4877
|
+
const federated = await getSubstrate(endpoint, "/substrate/v1/federated-schema");
|
|
4878
|
+
return okResult({
|
|
4879
|
+
legend: OVERVIEW_LEGEND,
|
|
4880
|
+
overview: schemaOverview(federated)
|
|
4881
|
+
});
|
|
4882
|
+
} catch (err) {
|
|
4883
|
+
return errorResult(toMessage(err));
|
|
4884
|
+
}
|
|
4799
4885
|
let path = "/substrate/v1/federated-schema";
|
|
4800
4886
|
if (ns !== void 0 && ns !== "") {
|
|
4801
4887
|
if (type !== void 0 && type !== "") {
|
|
@@ -4903,16 +4989,17 @@ function createMcpServer(endpoint, options = {}) {
|
|
|
4903
4989
|
const server = new McpServer({
|
|
4904
4990
|
name: "substrate",
|
|
4905
4991
|
version: MCP_SERVER_VERSION
|
|
4906
|
-
});
|
|
4992
|
+
}, options.instructions !== void 0 ? { instructions: options.instructions } : void 0);
|
|
4907
4993
|
const TOOLS = [
|
|
4908
4994
|
{
|
|
4909
4995
|
name: "schema",
|
|
4910
4996
|
config: {
|
|
4911
|
-
description: "Fetch the Substrate schema. No args →
|
|
4997
|
+
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.",
|
|
4912
4998
|
inputSchema: {
|
|
4913
4999
|
namespace: z.string().min(1).optional().describe("Scope to one namespace, e.g. \"notes\". Omit for the full federated schema."),
|
|
4914
5000
|
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`."),
|
|
4915
|
-
shape: z.enum(["full", "fields"]).optional().describe("Projection of the type contract; requires `namespace` + `type`. \"full\" (default) inlines every mutation's params and returns. \"fields\" returns the field defs plus `mutationNames`, about a sixth the size — use it to answer \"what fields does this type have\".")
|
|
5001
|
+
shape: z.enum(["full", "fields"]).optional().describe("Projection of the type contract; requires `namespace` + `type`. \"full\" (default) inlines every mutation's params and returns. \"fields\" returns the field defs plus `mutationNames`, about a sixth the size — use it to answer \"what fields does this type have\"."),
|
|
5002
|
+
full: z.boolean().optional().describe("With no `namespace`: true returns the whole federated schema instead of the overview.")
|
|
4916
5003
|
}
|
|
4917
5004
|
},
|
|
4918
5005
|
handler: createSchemaHandler(endpoint)
|
|
@@ -5064,6 +5151,12 @@ function resolveToolAllowlist(raw, known) {
|
|
|
5064
5151
|
for (const n of names) if (!known.includes(n)) throw new Error(`SUBSTRATE_MCP_TOOLS: unknown tool '${n}'. Valid names: ${[...known].sort().join(", ")}`);
|
|
5065
5152
|
return new Set(names);
|
|
5066
5153
|
}
|
|
5154
|
+
/** The overview for the session's instructions, or null when the server is slow or down. */
|
|
5155
|
+
async function fetchOverview(endpoint) {
|
|
5156
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve(null), 5e3).unref());
|
|
5157
|
+
const fetched = getSubstrate(endpoint, "/substrate/v1/federated-schema").then(schemaOverview, () => null);
|
|
5158
|
+
return Promise.race([fetched, timeout]);
|
|
5159
|
+
}
|
|
5067
5160
|
/**
|
|
5068
5161
|
* Boot the stdio MCP server. Resolves once the transport is connected; the
|
|
5069
5162
|
* process keeps running until the host (Claude Code, etc.) closes stdio.
|
|
@@ -5071,7 +5164,10 @@ function resolveToolAllowlist(raw, known) {
|
|
|
5071
5164
|
async function runMcp() {
|
|
5072
5165
|
const endpoint = process.env.SUBSTRATE_URL ?? "http://localhost:3100";
|
|
5073
5166
|
configureAgentAuth(process.env, endpoint);
|
|
5074
|
-
const server = createMcpServer(endpoint,
|
|
5167
|
+
const server = createMcpServer(endpoint, {
|
|
5168
|
+
...process.env.SUBSTRATE_MCP_TOOLS === void 0 ? {} : { tools: process.env.SUBSTRATE_MCP_TOOLS },
|
|
5169
|
+
instructions: buildInstructions(await fetchOverview(endpoint))
|
|
5170
|
+
});
|
|
5075
5171
|
const transport = new StdioServerTransport();
|
|
5076
5172
|
await server.connect(transport);
|
|
5077
5173
|
}
|
|
@@ -5114,8 +5210,9 @@ Subcommands:
|
|
|
5114
5210
|
run <script.mts> [--args <json>] [--dry-run | --write] [--max-writes <n>] [--out <file>]
|
|
5115
5211
|
Run a script's default export (s) => result against a client
|
|
5116
5212
|
signed from SUBSTRATE_URL + SUBSTRATE_AGENT_KEY_ID/_PATH, and
|
|
5117
|
-
print one JSON report. --args is a JSON object, read as
|
|
5118
|
-
|
|
5213
|
+
print one JSON report. --args is a JSON object, read as
|
|
5214
|
+
s.args. Read-only unless --dry-run (records mutations) or
|
|
5215
|
+
--write (sends up to --max-writes frames, 50).
|
|
5119
5216
|
check-enums [--json] [--record]
|
|
5120
5217
|
Report stored values outside a field's declared enum.
|
|
5121
5218
|
Read-only over HTTP (--record writes verdict rows); reads
|
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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-
|
|
3
|
-
import { a as runDerivedMigrations, o as runMigrations, r as deriveListIndexMigration, t as PgDataset } from "./src-
|
|
4
|
-
import { t as PgEdgesStore } from "./pg-edges-store-
|
|
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
5
|
import { t as FakeEmbedder } from "./fake-DUVtKVSE.js";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import postgres from "postgres";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnmal-ai/substrate",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
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": {
|
|
@@ -36,24 +36,24 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@inquirer/prompts": "^8.7.2",
|
|
39
|
-
"@mnmal-ai/substrate-bootstrap": "1.0.0-alpha.
|
|
40
|
-
"@mnmal-ai/substrate-client": "1.0.0-alpha.
|
|
41
|
-
"@mnmal-ai/substrate-compose": "1.0.0-alpha.
|
|
42
|
-
"@mnmal-ai/substrate-config": "1.0.0-alpha.
|
|
43
|
-
"@mnmal-ai/substrate-core": "1.0.0-alpha.
|
|
44
|
-
"@mnmal-ai/substrate-dataset-memory": "1.0.0-alpha.
|
|
45
|
-
"@mnmal-ai/substrate-dataset-pg": "1.0.0-alpha.
|
|
46
|
-
"@mnmal-ai/substrate-embedder": "1.0.0-alpha.
|
|
47
|
-
"@mnmal-ai/substrate-filter": "1.0.0-alpha.
|
|
48
|
-
"@mnmal-ai/substrate-pack": "1.0.0-alpha.
|
|
49
|
-
"@mnmal-ai/substrate-policy": "1.0.0-alpha.
|
|
50
|
-
"@mnmal-ai/substrate-proposals": "1.0.0-alpha.
|
|
51
|
-
"@mnmal-ai/substrate-recall": "1.0.0-alpha.
|
|
52
|
-
"@mnmal-ai/substrate-sdk": "1.0.0-alpha.
|
|
53
|
-
"@mnmal-ai/substrate-sentinel-client": "1.0.0-alpha.
|
|
54
|
-
"@mnmal-ai/substrate-server-fastify": "1.0.0-alpha.
|
|
55
|
-
"@mnmal-ai/substrate-server-memory": "1.0.0-alpha.
|
|
56
|
-
"@mnmal-ai/substrate-types": "1.0.0-alpha.
|
|
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",
|
|
57
57
|
"@types/node": "^26.6.4",
|
|
58
58
|
"@types/semver": "^7.5.0",
|
|
59
59
|
"@types/ws": "^8.18.1",
|