@mnmal-ai/substrate 1.0.0-alpha.1 → 1.0.0-alpha.3
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 +1 -1
- package/dist/client.js +4 -4
- package/dist/{dataset-DOXGRz50.js → dataset-BBZuhrsL.js} +9 -9
- package/dist/{agent-token-BIboWOU0.js → env-utils-CGNazUNt.js} +31 -2
- package/dist/pack.js +1 -1
- package/dist/pg-edges-store-DKPYyd8l.js +381 -0
- package/dist/{plugin-BuQQEzL-.js → plugin-QuJN9pG_.js} +40 -12
- package/dist/proposals-bootstrap.js +2 -2
- package/dist/proposals.js +1 -1
- package/dist/recall-bootstrap.js +11 -4
- package/dist/recall.config.schema.json +6 -0
- package/dist/recall.d.ts +21 -6
- package/dist/recall.js +2 -2
- package/dist/{row-DK7lPZVe.js → row-DZ0Fnpc6.js} +9 -11
- package/dist/sdk.d.ts +6 -0
- package/dist/sdk.js +5 -6
- package/dist/{src-zcyUofMJ.js → src-B-wkCHYL.js} +17 -11
- package/dist/{src-C4DzaIQZ.js → src-BLgbLq2k.js} +2 -0
- package/dist/{src-5hVbeiAu.js → src-CG7giuHr.js} +2 -2
- package/dist/{src-YXlv_RyL.js → src-CHp3QyqB.js} +232 -161
- package/dist/{src-CjEwiKXw.js → src-CXKnqeTW.js} +100 -88
- package/dist/{src-DuopV8u7.js → src-DMzc3HfW.js} +53 -11
- package/dist/substrate-admin.js +5 -5
- package/dist/substrate.js +29 -394
- package/dist/testing.d.ts +318 -3
- package/dist/testing.js +5 -3
- package/package.json +19 -19
- package/dist/env-utils-B7SGmoeJ.js +0 -21
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-CHp3QyqB.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-QuJN9pG_.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
|
|
7
7
|
//#region ../../packages/substrate-embedder/src/types.ts
|
|
@@ -49,7 +49,7 @@ var OllamaEmbedder = class {
|
|
|
49
49
|
async embed(text, opts) {
|
|
50
50
|
const timeoutMs = opts?.timeoutMs ?? this.timeoutMs;
|
|
51
51
|
const contextLength = await this.resolveContextLength(timeoutMs);
|
|
52
|
-
const url = `${this.baseUrl
|
|
52
|
+
const url = `${trimTrailingSlashes(this.baseUrl)}/api/embed`;
|
|
53
53
|
const controller = new AbortController();
|
|
54
54
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
55
55
|
let res;
|
|
@@ -98,7 +98,7 @@ var OllamaEmbedder = class {
|
|
|
98
98
|
return this.contextLength;
|
|
99
99
|
}
|
|
100
100
|
async fetchContextLength(timeoutMs) {
|
|
101
|
-
const url = `${this.baseUrl
|
|
101
|
+
const url = `${trimTrailingSlashes(this.baseUrl)}/api/show`;
|
|
102
102
|
const controller = new AbortController();
|
|
103
103
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
104
104
|
let body;
|
|
@@ -137,6 +137,11 @@ var OllamaEmbedder = class {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
/** `unavailable` for a failed request, naming the timeout when it was the abort. */
|
|
140
|
+
function trimTrailingSlashes(url) {
|
|
141
|
+
let end = url.length;
|
|
142
|
+
while (end > 0 && url.charCodeAt(end - 1) === 47) end--;
|
|
143
|
+
return url.slice(0, end);
|
|
144
|
+
}
|
|
140
145
|
function transportError(url, controller, timeoutMs, err) {
|
|
141
146
|
const detail = controller.signal.aborted ? `timed out after ${timeoutMs}ms` : `failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
142
147
|
return new EmbedError("unavailable", `OllamaEmbedder: POST ${url} ${detail}`, { cause: err });
|
|
@@ -378,6 +383,7 @@ const CrystalliseSchema = z.object({
|
|
|
378
383
|
const RecallBootstrapConfigSchema = z.object({
|
|
379
384
|
embedder: EmbedderSchema.optional(),
|
|
380
385
|
queryEmbedTimeoutMs: z.number().int().positive().default(3e4),
|
|
386
|
+
writeEmbedTimeoutMs: z.number().int().positive().default(3e4),
|
|
381
387
|
hnswM: z.number().int().positive().default(16),
|
|
382
388
|
hnswEfConstruction: z.number().int().positive().default(64),
|
|
383
389
|
salience: SalienceSchema.default({
|
|
@@ -426,6 +432,7 @@ const bootstrap = defineBootstrap.kernel({
|
|
|
426
432
|
return createRecallPlugin({
|
|
427
433
|
...embedder !== null ? { embedder } : {},
|
|
428
434
|
queryEmbedTimeoutMs: config.queryEmbedTimeoutMs,
|
|
435
|
+
writeEmbedTimeoutMs: config.writeEmbedTimeoutMs,
|
|
429
436
|
...deps.lexicalStore !== void 0 ? { lexicalStore: deps.lexicalStore } : {},
|
|
430
437
|
store: deps.store,
|
|
431
438
|
...deps.stats !== void 0 ? { stats: deps.stats } : {},
|
|
@@ -118,6 +118,12 @@
|
|
|
118
118
|
"exclusiveMinimum": 0,
|
|
119
119
|
"maximum": 9007199254740991
|
|
120
120
|
},
|
|
121
|
+
"writeEmbedTimeoutMs": {
|
|
122
|
+
"default": 30000,
|
|
123
|
+
"type": "integer",
|
|
124
|
+
"exclusiveMinimum": 0,
|
|
125
|
+
"maximum": 9007199254740991
|
|
126
|
+
},
|
|
121
127
|
"hnswM": {
|
|
122
128
|
"default": 16,
|
|
123
129
|
"type": "integer",
|
package/dist/recall.d.ts
CHANGED
|
@@ -150,8 +150,11 @@ interface ClusterStore {
|
|
|
150
150
|
includeRetired?: boolean;
|
|
151
151
|
}): Promise<ClusterRecord[]>;
|
|
152
152
|
getCluster(id: string): Promise<ClusterRecord | null>;
|
|
153
|
-
/**
|
|
154
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Members of one cluster, or of each of several in one read. Departed
|
|
155
|
+
* members excluded unless asked for.
|
|
156
|
+
*/
|
|
157
|
+
listMembers(clusterId: string | readonly string[], opts?: {
|
|
155
158
|
includeDeparted?: boolean;
|
|
156
159
|
}): Promise<ClusterMemberRecord[]>;
|
|
157
160
|
/**
|
|
@@ -242,6 +245,11 @@ interface EmbeddingsStoreKnnInput {
|
|
|
242
245
|
* store shared by several still fills k. Equality family only.
|
|
243
246
|
*/
|
|
244
247
|
rowFilter?: KnnRowFilter;
|
|
248
|
+
/**
|
|
249
|
+
* Return each row's salience decayed to now by this half-life, the decay
|
|
250
|
+
* `boostSalience` applies. Absent: the stored value, as of its last boost.
|
|
251
|
+
*/
|
|
252
|
+
salienceHalfLifeHours?: number;
|
|
245
253
|
}
|
|
246
254
|
type KnnScalar = string | number | boolean | null;
|
|
247
255
|
/** Field -> `{ eq }` or `{ in }`; every field must match. `eq: null` matches a missing or null field. */
|
|
@@ -1451,7 +1459,7 @@ export declare class InMemoryClusterStore implements ClusterStore {
|
|
|
1451
1459
|
includeRetired?: boolean;
|
|
1452
1460
|
}): Promise<ClusterRecord[]>;
|
|
1453
1461
|
getCluster(id: string): Promise<ClusterRecord | null>;
|
|
1454
|
-
listMembers(clusterId: string, opts?: {
|
|
1462
|
+
listMembers(clusterId: string | readonly string[], opts?: {
|
|
1455
1463
|
includeDeparted?: boolean;
|
|
1456
1464
|
}): Promise<ClusterMemberRecord[]>;
|
|
1457
1465
|
listAllMembers(): Promise<ClusterMemberRecord[]>;
|
|
@@ -1651,7 +1659,7 @@ export declare class PgClusterStore implements ClusterStore {
|
|
|
1651
1659
|
includeRetired?: boolean;
|
|
1652
1660
|
}): Promise<ClusterRecord[]>;
|
|
1653
1661
|
getCluster(id: string): Promise<ClusterRecord | null>;
|
|
1654
|
-
listMembers(clusterId: string, opts?: {
|
|
1662
|
+
listMembers(clusterId: string | readonly string[], opts?: {
|
|
1655
1663
|
includeDeparted?: boolean;
|
|
1656
1664
|
}): Promise<ClusterMemberRecord[]>;
|
|
1657
1665
|
listAllMembers(): Promise<ClusterMemberRecord[]>;
|
|
@@ -1731,10 +1739,17 @@ export declare class PgLexicalStore implements LexicalStore {
|
|
|
1731
1739
|
interface RecallPluginConfig {
|
|
1732
1740
|
embedder?: Embedder;
|
|
1733
1741
|
/**
|
|
1734
|
-
* Timeout for embedding a recall or `embeddingSimilar` query, in ms.
|
|
1735
|
-
*
|
|
1742
|
+
* Timeout for embedding a recall or `embeddingSimilar` query, in ms.
|
|
1743
|
+
* Reindex embeds keep the embedder's own timeout. Default 30000.
|
|
1736
1744
|
*/
|
|
1737
1745
|
queryEmbedTimeoutMs?: number;
|
|
1746
|
+
/**
|
|
1747
|
+
* Timeout for the embed that follows a write, in ms. The engine awaits
|
|
1748
|
+
* after-commit work before it replies, so this bounds how long an already
|
|
1749
|
+
* committed write can be held by a slow embedder. A timed-out embed keeps
|
|
1750
|
+
* the row's previous vector until its next write or a reindex. Default 30000.
|
|
1751
|
+
*/
|
|
1752
|
+
writeEmbedTimeoutMs?: number;
|
|
1738
1753
|
store: EmbeddingsStore;
|
|
1739
1754
|
/**
|
|
1740
1755
|
* 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-B-wkCHYL.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-QuJN9pG_.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 };
|
|
@@ -388,18 +388,16 @@ function newlyGranted(prev, next) {
|
|
|
388
388
|
* facing refusal message.
|
|
389
389
|
*/
|
|
390
390
|
function newlyGrantedPairs(prev, next) {
|
|
391
|
-
const
|
|
392
|
-
const direct = prev[ns];
|
|
393
|
-
if (Array.isArray(direct) && direct.includes(cap)) return true;
|
|
394
|
-
const wild = prev["*"];
|
|
395
|
-
return Array.isArray(wild) && wild.includes(cap);
|
|
396
|
-
};
|
|
391
|
+
const effective = (grant, ns) => grant[ns] ?? grant["*"] ?? [];
|
|
397
392
|
const byNs = /* @__PURE__ */ new Map();
|
|
398
|
-
for (const
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
393
|
+
for (const ns of /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)])) {
|
|
394
|
+
const had = effective(prev, ns);
|
|
395
|
+
for (const cap of effective(next, ns)) {
|
|
396
|
+
if (had.includes(cap)) continue;
|
|
397
|
+
const bucket = byNs.get(ns);
|
|
398
|
+
if (bucket === void 0) byNs.set(ns, [cap]);
|
|
399
|
+
else bucket.push(cap);
|
|
400
|
+
}
|
|
403
401
|
}
|
|
404
402
|
return [...byNs.entries()].map(([ns, caps]) => `${ns}:${[...caps].sort().join("+")}`).sort();
|
|
405
403
|
}
|
package/dist/sdk.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export declare function canonicalize(value: unknown): unknown;
|
|
|
32
32
|
* a config typo fails at boot.
|
|
33
33
|
*/
|
|
34
34
|
export declare function parsePositiveInt(raw: string | undefined, envVar: string, fallback: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* `url` with its trailing slashes removed, for joining a configured base URL
|
|
37
|
+
* to a path. A loop rather than `/\/+$/`, which backtracks quadratically on a
|
|
38
|
+
* long run of slashes that does not end the string.
|
|
39
|
+
*/
|
|
40
|
+
export declare function trimTrailingSlashes(url: string): string;
|
|
35
41
|
//#endregion
|
|
36
42
|
//#region ../../packages/substrate-types/src/hard-delete-gate.d.ts
|
|
37
43
|
/**
|
package/dist/sdk.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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-
|
|
3
|
-
import { a as
|
|
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-
|
|
5
|
-
import { S as assertNever, b as formatQualifiedKey, x as parseQualifiedKey } from "./src-
|
|
6
|
-
import { t as parsePositiveInt } from "./env-utils-B7SGmoeJ.js";
|
|
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-CHp3QyqB.js";
|
|
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
|
+
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
|
+
import { S as assertNever, b as formatQualifiedKey, x as parseQualifiedKey } from "./src-BLgbLq2k.js";
|
|
7
6
|
|
|
8
7
|
//#region ../../packages/substrate-sdk/src/engine-helpers.ts
|
|
9
8
|
/**
|
|
@@ -109,4 +108,4 @@ async function queryOne(engine, namespace, typeName, params, fields, identity =
|
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
//#endregion
|
|
112
|
-
export { ADMIN_CAPABILITIES, BootstrapConfigError, BridgeUnreachableError, CLIENT_SUPPLIED_SERVER_FIELD, DEFAULT_CAPABILITIES, EngineQueryError, JSON_HEADERS, METADATA_AUTHOR_FIELDS, METADATA_FILTER_FIELDS, MissingReferentError, NamespaceMismatch, RESERVED_AUTOCRUD_FIELDS, RESERVED_AUTOCRUD_FIELD_NAMES, ROW_METADATA_FIELDS, RegistryBase, ReservedField, ResolverFrameError, RestrictViolation, SYSTEM_NAMESPACE, UnattributedWriteError, UnsupportedFilterError, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, adminClaimCapabilities, allCapabilities, allowAll, allowVerbs, and, applyRowFilters, applyUpdatePatch, assertHardDeleteAllowed, assertNever, autoCrudOptionsOf, canonicalVocabValue, canonicalize, capabilitiesFor, checkRevocable, checkUpdatable, confersAnywhere, coversNamespace, createKeyedMutex, createResolver, createResolverWithEdges, decodeList, defineBootstrap, defineNamespace, deleteResolver, deleteRow, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, error400, expandFlat, field, flattenGrant, formatQualifiedKey, getResolver, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, grantOf, grantedIn, installAutoCrud, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isResolverFrameError, isRestrictViolation, jsonResponse, listResolver, makeAuthorizationProvider, makeCtx, makeTokenProvider, newlyGranted, newlyGrantedPairs, normaliseMetadataOrderBy, normaliseMetadataWhere, normaliseVocabValues, normaliseVocabWhere, not, or, parseGrantEntries, parseJsonBody, parsePositiveInt, parseQualifiedKey, purgeResolver, queryAll, queryOne, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, resolveEntityId, resolveEntityRow, resolveIdentity, revokedAtIso, row, selectAll, storedVocabSpellings, updateResolver, validateHardDeleteEnv, vocabImplication };
|
|
111
|
+
export { ADMIN_CAPABILITIES, BootstrapConfigError, BridgeUnreachableError, CLIENT_SUPPLIED_SERVER_FIELD, DEFAULT_CAPABILITIES, EngineQueryError, JSON_HEADERS, METADATA_AUTHOR_FIELDS, METADATA_FILTER_FIELDS, MissingReferentError, NamespaceMismatch, RESERVED_AUTOCRUD_FIELDS, RESERVED_AUTOCRUD_FIELD_NAMES, ROW_METADATA_FIELDS, RegistryBase, ReservedField, ResolverFrameError, RestrictViolation, SYSTEM_NAMESPACE, UnattributedWriteError, UnsupportedFilterError, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, adminClaimCapabilities, allCapabilities, allowAll, allowVerbs, and, applyRowFilters, applyUpdatePatch, assertHardDeleteAllowed, assertNever, autoCrudOptionsOf, canonicalVocabValue, canonicalize, capabilitiesFor, checkRevocable, checkUpdatable, confersAnywhere, coversNamespace, createKeyedMutex, createResolver, createResolverWithEdges, decodeList, defineBootstrap, defineNamespace, deleteResolver, deleteRow, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, error400, expandFlat, field, flattenGrant, formatQualifiedKey, getResolver, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, grantOf, grantedIn, installAutoCrud, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isResolverFrameError, isRestrictViolation, jsonResponse, listResolver, makeAuthorizationProvider, makeCtx, makeTokenProvider, newlyGranted, newlyGrantedPairs, normaliseMetadataOrderBy, normaliseMetadataWhere, normaliseVocabValues, normaliseVocabWhere, not, or, parseGrantEntries, parseJsonBody, parsePositiveInt, parseQualifiedKey, purgeResolver, queryAll, queryOne, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, resolveEntityId, resolveEntityRow, resolveIdentity, revokedAtIso, row, selectAll, storedVocabSpellings, trimTrailingSlashes, updateResolver, validateHardDeleteEnv, vocabImplication };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { n as txScopeIdFor } from "./src-CXKnqeTW.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-QuJN9pG_.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.3";
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region ../../plugins/substrate-recall/src/in-memory-cluster-store.ts
|
|
@@ -68,7 +68,8 @@ var InMemoryClusterStore = class {
|
|
|
68
68
|
return found === void 0 ? null : this.#copyCluster(found);
|
|
69
69
|
}
|
|
70
70
|
async listMembers(clusterId, opts = {}) {
|
|
71
|
-
|
|
71
|
+
const ids = new Set(typeof clusterId === "string" ? [clusterId] : clusterId);
|
|
72
|
+
return this.#members.filter((m) => ids.has(m.clusterId)).filter((m) => opts.includeDeparted === true || m.departedAt === null).map((m) => ({ ...m }));
|
|
72
73
|
}
|
|
73
74
|
async listAllMembers() {
|
|
74
75
|
return this.#members.filter((m) => m.departedAt === null).map((m) => ({ ...m }));
|
|
@@ -195,6 +196,8 @@ var InMemoryEmbeddingsStore = class {
|
|
|
195
196
|
async knnSearch(input) {
|
|
196
197
|
const threshold = typeof input.threshold === "number" ? input.threshold : 0;
|
|
197
198
|
const candidates = [];
|
|
199
|
+
const now = Date.now();
|
|
200
|
+
const halfLife = input.salienceHalfLifeHours;
|
|
198
201
|
for (const entry of this.#entries.values()) {
|
|
199
202
|
if (entry.rowNamespace !== input.namespace) continue;
|
|
200
203
|
if (entry.rowType !== input.type) continue;
|
|
@@ -218,7 +221,7 @@ var InMemoryEmbeddingsStore = class {
|
|
|
218
221
|
results.push({
|
|
219
222
|
row,
|
|
220
223
|
score,
|
|
221
|
-
salience: entry.salience,
|
|
224
|
+
salience: halfLife !== void 0 && halfLife > 0 ? decayed(entry.salience, now - entry.salienceUpdatedAt.getTime(), halfLife) : entry.salience,
|
|
222
225
|
...input.returnVector === true ? { vector: Array.from(entry.vector) } : {}
|
|
223
226
|
});
|
|
224
227
|
}
|
|
@@ -227,14 +230,12 @@ var InMemoryEmbeddingsStore = class {
|
|
|
227
230
|
async boostSalience(targets, halfLifeHours, bump = 1) {
|
|
228
231
|
if (targets.length === 0) return [];
|
|
229
232
|
const now = /* @__PURE__ */ new Date();
|
|
230
|
-
const halfLifeMs = halfLifeHours * 3600 * 1e3;
|
|
231
233
|
const applied = [];
|
|
232
234
|
for (const t of targets) {
|
|
233
235
|
const entry = this.#entries.get(key(t.namespace, t.type, t.id));
|
|
234
236
|
if (entry === void 0) continue;
|
|
235
|
-
const elapsedMs =
|
|
236
|
-
|
|
237
|
-
entry.salience = entry.salience * decay + bump;
|
|
237
|
+
const elapsedMs = now.getTime() - entry.salienceUpdatedAt.getTime();
|
|
238
|
+
entry.salience = decayed(entry.salience, elapsedMs, halfLifeHours) + bump;
|
|
238
239
|
entry.salienceUpdatedAt = now;
|
|
239
240
|
applied.push({
|
|
240
241
|
namespace: t.namespace,
|
|
@@ -297,6 +298,10 @@ var InMemoryEmbeddingsStore = class {
|
|
|
297
298
|
return out;
|
|
298
299
|
}
|
|
299
300
|
};
|
|
301
|
+
/** `salience` after `elapsedMs` of exponential decay at `halfLifeHours`. */
|
|
302
|
+
function decayed(salience, elapsedMs, halfLifeHours) {
|
|
303
|
+
return salience * Math.exp(-Math.LN2 * Math.max(0, elapsedMs) / (halfLifeHours * 3600 * 1e3));
|
|
304
|
+
}
|
|
300
305
|
|
|
301
306
|
//#endregion
|
|
302
307
|
//#region ../../plugins/substrate-recall/src/in-memory-lexical-store.ts
|
|
@@ -556,7 +561,7 @@ var PgClusterStore = class {
|
|
|
556
561
|
const sql = this.#sql;
|
|
557
562
|
return (await sql`
|
|
558
563
|
SELECT * FROM recall_cluster_members
|
|
559
|
-
WHERE cluster_id = ${clusterId}
|
|
564
|
+
WHERE cluster_id = ANY(${typeof clusterId === "string" ? [clusterId] : [...clusterId]}::text[])
|
|
560
565
|
${opts.includeDeparted === true ? sql`` : sql`AND departed_at IS NULL`}
|
|
561
566
|
ORDER BY short_id ASC
|
|
562
567
|
`).map(toMember);
|
|
@@ -729,6 +734,7 @@ var PgEmbeddingsStore = class {
|
|
|
729
734
|
const k = clampK(input.k);
|
|
730
735
|
const threshold = typeof input.threshold === "number" ? input.threshold : 0;
|
|
731
736
|
const wantVector = input.returnVector === true;
|
|
737
|
+
const halfLife = input.salienceHalfLifeHours;
|
|
732
738
|
return (await sql.begin(async (tx) => {
|
|
733
739
|
await tx`SET LOCAL hnsw.iterative_scan = 'strict_order'`;
|
|
734
740
|
await tx.unsafe(`SET LOCAL hnsw.ef_search = ${DEFAULT_HNSW_EF_SEARCH}`);
|
|
@@ -736,7 +742,7 @@ var PgEmbeddingsStore = class {
|
|
|
736
742
|
SELECT
|
|
737
743
|
${tx.unsafe(ROW_BODY_SQL)} AS row,
|
|
738
744
|
1 - (e.embedding <=> ${literal}::vector) AS score,
|
|
739
|
-
e.salience
|
|
745
|
+
e.salience ${halfLife !== void 0 && halfLife > 0 ? tx`* exp(-ln(2) * GREATEST(0, EXTRACT(EPOCH FROM (now() - e.salience_updated_at))) / ${halfLife * 3600})` : tx``} AS salience
|
|
740
746
|
${wantVector ? tx`, e.embedding::text AS embedding` : tx``}
|
|
741
747
|
FROM embeddings e
|
|
742
748
|
JOIN rows r
|
|
@@ -208,6 +208,7 @@ function decodeEnvelope(bytes, ctx) {
|
|
|
208
208
|
if (raw._meta !== void 0) out._meta = raw._meta;
|
|
209
209
|
if (raw._pagination !== void 0) out._pagination = raw._pagination;
|
|
210
210
|
if (raw._completeness !== void 0) out._completeness = raw._completeness;
|
|
211
|
+
if (raw._diagnostics !== void 0) out._diagnostics = raw._diagnostics;
|
|
211
212
|
if (raw.errors !== void 0) out.errors = raw.errors;
|
|
212
213
|
return out;
|
|
213
214
|
}
|
|
@@ -482,6 +483,7 @@ function encodeEnvelope(envelope, ctx) {
|
|
|
482
483
|
if (envelope._meta !== void 0) out._meta = envelope._meta;
|
|
483
484
|
if (envelope._pagination !== void 0) out._pagination = envelope._pagination;
|
|
484
485
|
if (envelope._completeness !== void 0) out._completeness = envelope._completeness;
|
|
486
|
+
if (envelope._diagnostics !== void 0) out._diagnostics = envelope._diagnostics;
|
|
485
487
|
if (envelope.errors !== void 0) out.errors = envelope.errors;
|
|
486
488
|
return Buffer.from(pack(out));
|
|
487
489
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
3
|
-
import { s as requireCapability } from "./row-
|
|
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-CHp3QyqB.js";
|
|
3
|
+
import { s as requireCapability } from "./row-DZ0Fnpc6.js";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
|
|
6
6
|
//#region ../../plugins/substrate-proposals/src/capability.ts
|