memorix 1.10.4 → 1.10.5
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/CHANGELOG.md +26 -0
- package/dist/cli/index.js +418 -74
- package/dist/index.js +227 -55
- package/dist/maintenance-runner.js +225 -53
- package/dist/media-audio-runner.js +225 -53
- package/dist/media-video-runner.js +225 -53
- package/dist/memcode-runtime/CHANGELOG.md +44 -0
- package/dist/sdk.js +242 -56
- package/dist/vector-backfill-runner.js +225 -53
- package/docs/AGENT_OPERATOR_PLAYBOOK.md +7 -0
- package/docs/ARCHITECTURE.md +19 -0
- package/docs/CONFIGURATION.md +2 -0
- package/docs/DEVELOPMENT.md +8 -1
- package/docs/MODULES.md +1 -1
- package/docs/PERFORMANCE.md +7 -0
- package/docs/README.md +3 -1
- package/docs/ROADMAP-1.9.12-2.0.md +1 -1
- package/package.json +1 -1
- package/plugins/antigravity/memorix/plugin.json +1 -1
- package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
- package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/copilot/memorix/plugin.json +1 -1
- package/plugins/gemini/memorix/gemini-extension.json +1 -1
- package/plugins/hermes/memorix/plugin.yaml +1 -1
- package/plugins/omp/memorix/package.json +1 -1
- package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/pi/memorix/package.json +1 -1
- package/server.json +2 -2
- package/src/cli/command-guide.ts +3 -1
- package/src/cli/commands/http-session-stream-watch.ts +138 -0
- package/src/cli/commands/memory.ts +3 -1
- package/src/cli/commands/project-detection-cache.ts +61 -0
- package/src/cli/commands/serve-http.ts +63 -13
- package/src/cli/index.ts +1 -1
- package/src/core/derived-view-registry.ts +33 -0
- package/src/embedding/api-provider.ts +14 -2
- package/src/embedding/ollama-embed.ts +118 -0
- package/src/memory/observations.ts +28 -6
- package/src/search/semantic-index.ts +38 -6
- package/src/store/orama-store.ts +46 -30
|
@@ -4249,6 +4249,96 @@ var init_transformers_provider = __esm({
|
|
|
4249
4249
|
}
|
|
4250
4250
|
});
|
|
4251
4251
|
|
|
4252
|
+
// src/embedding/ollama-embed.ts
|
|
4253
|
+
async function routeOllamaEmbedding(url, body, fetchImpl = fetch, probeOptions) {
|
|
4254
|
+
const parsed = parseUrl(url);
|
|
4255
|
+
if (!parsed) return { url, body, rewritten: false };
|
|
4256
|
+
const openAIRoute = parsed.pathname.endsWith("/v1/embeddings");
|
|
4257
|
+
const nativeRoute = parsed.pathname.endsWith("/api/embed");
|
|
4258
|
+
if (!openAIRoute && !nativeRoute) return { url, body, rewritten: false };
|
|
4259
|
+
if (!await originServesOllama(parsed.origin, fetchImpl, probeOptions)) return { url, body, rewritten: false };
|
|
4260
|
+
if (nativeRoute) return { url, body, rewritten: true };
|
|
4261
|
+
parsed.pathname = parsed.pathname.replace(/\/v1\/embeddings$/, "/api/embed");
|
|
4262
|
+
return { url: parsed.toString(), body: withEmbeddingKeepAlive(body), rewritten: true };
|
|
4263
|
+
}
|
|
4264
|
+
async function originServesOllama(origin, fetchImpl = fetch, probeOptions) {
|
|
4265
|
+
const cached = ollamaOrigins.get(origin);
|
|
4266
|
+
if (cached != null) return cached;
|
|
4267
|
+
if (probeOptions?.signal?.aborted) return false;
|
|
4268
|
+
try {
|
|
4269
|
+
const response = await fetchImpl(`${origin}/api/version`, {
|
|
4270
|
+
method: "GET",
|
|
4271
|
+
signal: buildProbeSignal(probeOptions)
|
|
4272
|
+
});
|
|
4273
|
+
if (!response.ok) {
|
|
4274
|
+
ollamaOrigins.set(origin, false);
|
|
4275
|
+
return false;
|
|
4276
|
+
}
|
|
4277
|
+
const detected = isOllamaVersionPayload(await response.json());
|
|
4278
|
+
ollamaOrigins.set(origin, detected);
|
|
4279
|
+
return detected;
|
|
4280
|
+
} catch (err) {
|
|
4281
|
+
if (isAbortError(err) || probeOptions?.signal?.aborted) return false;
|
|
4282
|
+
ollamaOrigins.set(origin, false);
|
|
4283
|
+
return false;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
function mapOllamaEmbeddingResponse(payload) {
|
|
4287
|
+
if (!payload || typeof payload !== "object") return payload;
|
|
4288
|
+
const record80 = payload;
|
|
4289
|
+
if (Array.isArray(record80.data) || !Array.isArray(record80.embeddings)) return payload;
|
|
4290
|
+
const embeddings = record80.embeddings.filter((item) => Array.isArray(item));
|
|
4291
|
+
return {
|
|
4292
|
+
...record80,
|
|
4293
|
+
object: "list",
|
|
4294
|
+
data: embeddings.map((embedding, index) => ({
|
|
4295
|
+
object: "embedding",
|
|
4296
|
+
index,
|
|
4297
|
+
embedding
|
|
4298
|
+
}))
|
|
4299
|
+
};
|
|
4300
|
+
}
|
|
4301
|
+
function withEmbeddingKeepAlive(body) {
|
|
4302
|
+
if (body.keep_alive != null && body.keep_alive !== "") return body;
|
|
4303
|
+
return { ...body, keep_alive: OLLAMA_EMBED_KEEP_ALIVE };
|
|
4304
|
+
}
|
|
4305
|
+
function isOllamaVersionPayload(payload) {
|
|
4306
|
+
if (!payload || typeof payload !== "object") return false;
|
|
4307
|
+
const version = payload.version;
|
|
4308
|
+
return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version);
|
|
4309
|
+
}
|
|
4310
|
+
function parseUrl(url) {
|
|
4311
|
+
try {
|
|
4312
|
+
return new URL(url);
|
|
4313
|
+
} catch {
|
|
4314
|
+
return null;
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
function buildProbeSignal(probeOptions) {
|
|
4318
|
+
const timeoutMs = Math.max(
|
|
4319
|
+
1,
|
|
4320
|
+
Math.min(
|
|
4321
|
+
typeof probeOptions?.probeTimeoutMs === "number" && Number.isFinite(probeOptions.probeTimeoutMs) ? Math.floor(probeOptions.probeTimeoutMs) : 1e3,
|
|
4322
|
+
6e4
|
|
4323
|
+
)
|
|
4324
|
+
);
|
|
4325
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
4326
|
+
if (probeOptions?.signal) return AbortSignal.any([probeOptions.signal, timeoutSignal]);
|
|
4327
|
+
return timeoutSignal;
|
|
4328
|
+
}
|
|
4329
|
+
function isAbortError(err) {
|
|
4330
|
+
return err instanceof Error && err.name === "AbortError";
|
|
4331
|
+
}
|
|
4332
|
+
var OLLAMA_EMBED_KEEP_ALIVE, ollamaOrigins;
|
|
4333
|
+
var init_ollama_embed = __esm({
|
|
4334
|
+
"src/embedding/ollama-embed.ts"() {
|
|
4335
|
+
"use strict";
|
|
4336
|
+
init_esm_shims();
|
|
4337
|
+
OLLAMA_EMBED_KEEP_ALIVE = "5m";
|
|
4338
|
+
ollamaOrigins = /* @__PURE__ */ new Map();
|
|
4339
|
+
}
|
|
4340
|
+
});
|
|
4341
|
+
|
|
4252
4342
|
// src/embedding/api-provider.ts
|
|
4253
4343
|
var api_provider_exports = {};
|
|
4254
4344
|
__export(api_provider_exports, {
|
|
@@ -4950,8 +5040,18 @@ function parseBatchLimit(error) {
|
|
|
4950
5040
|
return null;
|
|
4951
5041
|
}
|
|
4952
5042
|
async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nativeGemini = false) {
|
|
4953
|
-
const controller = new AbortController();
|
|
4954
5043
|
const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(100, Math.min(Math.floor(options.timeoutMs), 6e4)) : 1e4;
|
|
5044
|
+
let rewritten = false;
|
|
5045
|
+
if (!nativeGemini) {
|
|
5046
|
+
const routed = await routeOllamaEmbedding(url, body, fetch, {
|
|
5047
|
+
signal: options.signal,
|
|
5048
|
+
probeTimeoutMs: Math.min(1e3, timeoutMs)
|
|
5049
|
+
});
|
|
5050
|
+
url = routed.url;
|
|
5051
|
+
body = routed.body;
|
|
5052
|
+
rewritten = routed.rewritten;
|
|
5053
|
+
}
|
|
5054
|
+
const controller = new AbortController();
|
|
4955
5055
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
4956
5056
|
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
4957
5057
|
let response;
|
|
@@ -4977,10 +5077,11 @@ async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nati
|
|
|
4977
5077
|
}
|
|
4978
5078
|
try {
|
|
4979
5079
|
if (response.ok) {
|
|
4980
|
-
|
|
5080
|
+
const payload = await raceWithAbort(
|
|
4981
5081
|
response.json(),
|
|
4982
5082
|
signal
|
|
4983
5083
|
);
|
|
5084
|
+
return rewritten ? mapOllamaEmbeddingResponse(payload) : payload;
|
|
4984
5085
|
}
|
|
4985
5086
|
if (options.retry !== false && (response.status === 429 || response.status >= 500) && attempt < MAX_RETRIES2) {
|
|
4986
5087
|
const delay3 = BASE_DELAY_MS * Math.pow(2, attempt);
|
|
@@ -5057,6 +5158,7 @@ var init_api_provider = __esm({
|
|
|
5057
5158
|
"use strict";
|
|
5058
5159
|
init_esm_shims();
|
|
5059
5160
|
init_provider();
|
|
5161
|
+
init_ollama_embed();
|
|
5060
5162
|
cache3 = /* @__PURE__ */ new Map();
|
|
5061
5163
|
MAX_CACHE_ENTRIES = 2e5;
|
|
5062
5164
|
MAX_CACHE_PAYLOAD_BYTES = 256 * 1024 * 1024;
|
|
@@ -7632,6 +7734,9 @@ async function openState(dataDir, profile) {
|
|
|
7632
7734
|
const table = names.includes(name) ? await connection.openTable(name) : null;
|
|
7633
7735
|
return { key: stateKey(dataDir, profile), dataDir, profile, connection, table };
|
|
7634
7736
|
}
|
|
7737
|
+
function semanticVectorKey(projectId, observationId2) {
|
|
7738
|
+
return `${projectId}:${Math.trunc(observationId2)}`;
|
|
7739
|
+
}
|
|
7635
7740
|
function toLanceRow(record80) {
|
|
7636
7741
|
return {
|
|
7637
7742
|
observation_id: record80.observationId,
|
|
@@ -7702,7 +7807,7 @@ async function mergeVectors(dataDir, profile, records) {
|
|
|
7702
7807
|
const state = await getState(dataDir, profile, records);
|
|
7703
7808
|
if (!state?.table) return;
|
|
7704
7809
|
const rows = records.map(toLanceRow);
|
|
7705
|
-
await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
7810
|
+
await state.table.mergeInsert(["project_id", "observation_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
7706
7811
|
const key = stateKey(dataDir, profile);
|
|
7707
7812
|
const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
|
|
7708
7813
|
if (mutationCount >= semanticOptimizeEvery()) {
|
|
@@ -7742,11 +7847,18 @@ function upsertSemanticVector(dataDir, profile, record80) {
|
|
|
7742
7847
|
function upsertSemanticVectors(dataDir, profile, records) {
|
|
7743
7848
|
return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
|
|
7744
7849
|
}
|
|
7745
|
-
async function
|
|
7850
|
+
async function listSemanticVectorKeys(dataDir, profile) {
|
|
7746
7851
|
const state = await getState(dataDir, profile);
|
|
7747
7852
|
if (!state?.table) return null;
|
|
7748
|
-
const rows = await state.table.query().select(["observation_id"]).toArray();
|
|
7749
|
-
|
|
7853
|
+
const rows = await state.table.query().select(["observation_id", "project_id"]).toArray();
|
|
7854
|
+
const keys = /* @__PURE__ */ new Set();
|
|
7855
|
+
for (const row of rows) {
|
|
7856
|
+
const observationId2 = Number(row.observation_id);
|
|
7857
|
+
const projectId = String(row.project_id ?? "");
|
|
7858
|
+
if (!Number.isSafeInteger(observationId2) || !projectId) continue;
|
|
7859
|
+
keys.add(semanticVectorKey(projectId, observationId2));
|
|
7860
|
+
}
|
|
7861
|
+
return keys;
|
|
7750
7862
|
}
|
|
7751
7863
|
async function getSemanticIndexStats(dataDir, profile) {
|
|
7752
7864
|
const state = await getState(dataDir, profile);
|
|
@@ -7939,6 +8051,37 @@ var init_derived_view_receipt = __esm({
|
|
|
7939
8051
|
}
|
|
7940
8052
|
});
|
|
7941
8053
|
|
|
8054
|
+
// src/core/derived-view-registry.ts
|
|
8055
|
+
var DerivedViewRegistry;
|
|
8056
|
+
var init_derived_view_registry = __esm({
|
|
8057
|
+
"src/core/derived-view-registry.ts"() {
|
|
8058
|
+
"use strict";
|
|
8059
|
+
init_esm_shims();
|
|
8060
|
+
DerivedViewRegistry = class {
|
|
8061
|
+
readers = /* @__PURE__ */ new Map();
|
|
8062
|
+
register(name, reader) {
|
|
8063
|
+
const normalized = name.trim();
|
|
8064
|
+
if (!normalized) throw new Error("Derived view name must not be empty");
|
|
8065
|
+
this.readers.set(normalized, reader);
|
|
8066
|
+
return () => {
|
|
8067
|
+
if (this.readers.get(normalized) === reader) this.readers.delete(normalized);
|
|
8068
|
+
};
|
|
8069
|
+
}
|
|
8070
|
+
snapshot() {
|
|
8071
|
+
const result = {};
|
|
8072
|
+
for (const [name, reader] of this.readers) {
|
|
8073
|
+
try {
|
|
8074
|
+
result[name] = reader();
|
|
8075
|
+
} catch {
|
|
8076
|
+
result[name] = { state: "degraded", reason: "derived view reader failed" };
|
|
8077
|
+
}
|
|
8078
|
+
}
|
|
8079
|
+
return result;
|
|
8080
|
+
}
|
|
8081
|
+
};
|
|
8082
|
+
}
|
|
8083
|
+
});
|
|
8084
|
+
|
|
7942
8085
|
// src/project/aliases.ts
|
|
7943
8086
|
var aliases_exports = {};
|
|
7944
8087
|
__export(aliases_exports, {
|
|
@@ -8590,15 +8733,17 @@ function getLastSearchDiagnostics(projectId) {
|
|
|
8590
8733
|
return diagnostics ? { ...diagnostics } : void 0;
|
|
8591
8734
|
}
|
|
8592
8735
|
function getSearchDerivedViews() {
|
|
8593
|
-
|
|
8736
|
+
return searchDerivedViewRegistry.snapshot();
|
|
8737
|
+
}
|
|
8738
|
+
function readFtsDerivedViewReceipt() {
|
|
8594
8739
|
const store = getOptionalObservationStore();
|
|
8595
8740
|
if (store) {
|
|
8596
8741
|
try {
|
|
8597
8742
|
const generation = store.getGeneration();
|
|
8598
8743
|
if (store.hasLexicalIndex?.()) {
|
|
8599
|
-
|
|
8744
|
+
return { generation, freshness: "current", rebuildStatus: "idle" };
|
|
8600
8745
|
} else {
|
|
8601
|
-
|
|
8746
|
+
return {
|
|
8602
8747
|
generation,
|
|
8603
8748
|
freshness: "unknown",
|
|
8604
8749
|
rebuildStatus: "unavailable",
|
|
@@ -8608,32 +8753,34 @@ function getSearchDerivedViews() {
|
|
|
8608
8753
|
};
|
|
8609
8754
|
}
|
|
8610
8755
|
} catch (error) {
|
|
8611
|
-
|
|
8756
|
+
return {
|
|
8612
8757
|
freshness: "unknown",
|
|
8613
8758
|
rebuildStatus: "failed",
|
|
8614
8759
|
failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
|
|
8615
8760
|
};
|
|
8616
8761
|
}
|
|
8617
|
-
} else {
|
|
8618
|
-
views.fts = {
|
|
8619
|
-
freshness: "unknown",
|
|
8620
|
-
rebuildStatus: "unavailable",
|
|
8621
|
-
failureReason: "observation store is not initialized"
|
|
8622
|
-
};
|
|
8623
8762
|
}
|
|
8624
|
-
|
|
8763
|
+
return {
|
|
8764
|
+
freshness: "unknown",
|
|
8765
|
+
rebuildStatus: "unavailable",
|
|
8766
|
+
failureReason: "observation store is not initialized"
|
|
8767
|
+
};
|
|
8768
|
+
}
|
|
8769
|
+
function readOramaDerivedViewReceipt() {
|
|
8770
|
+
return db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
|
|
8625
8771
|
generation: dbGeneration,
|
|
8626
8772
|
freshness: "unknown",
|
|
8627
8773
|
rebuildStatus: "unavailable",
|
|
8628
8774
|
failureReason: "Orama index is not initialized"
|
|
8629
8775
|
};
|
|
8776
|
+
}
|
|
8777
|
+
function readEmbeddingDerivedViewReceipt() {
|
|
8630
8778
|
let embeddingHealth;
|
|
8631
8779
|
try {
|
|
8632
8780
|
embeddingHealth = getEmbeddingRuntimeHealth?.();
|
|
8633
8781
|
} catch {
|
|
8634
8782
|
}
|
|
8635
|
-
|
|
8636
|
-
return views;
|
|
8783
|
+
return embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
|
|
8637
8784
|
}
|
|
8638
8785
|
function rememberSearchDiagnostics(key, value) {
|
|
8639
8786
|
if (!lastSearchDiagnosticsByProject.has(key) && lastSearchDiagnosticsByProject.size >= MAX_SEARCH_MODE_KEYS) {
|
|
@@ -8770,10 +8917,12 @@ async function searchLanceInVectorOrder(options, projectIds, limit2, queryVector
|
|
|
8770
8917
|
const hits = [];
|
|
8771
8918
|
const seen = /* @__PURE__ */ new Set();
|
|
8772
8919
|
for (const hit of vectorHits) {
|
|
8773
|
-
if (
|
|
8774
|
-
|
|
8920
|
+
if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) continue;
|
|
8921
|
+
const key = semanticVectorKey(hit.projectId, hit.observationId);
|
|
8922
|
+
if (seen.has(key)) continue;
|
|
8923
|
+
seen.add(key);
|
|
8775
8924
|
const observation = await store.getById(hit.observationId);
|
|
8776
|
-
if (!observation) continue;
|
|
8925
|
+
if (!observation || observation.projectId !== hit.projectId) continue;
|
|
8777
8926
|
if (projectIds && !projectIds.includes(observation.projectId)) continue;
|
|
8778
8927
|
if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) continue;
|
|
8779
8928
|
if (options.type && observation.type !== options.type) continue;
|
|
@@ -8819,14 +8968,15 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
8819
8968
|
documents.set(makeEntryKey(hit.document.projectId, hit.document.observationId), hit.document);
|
|
8820
8969
|
}
|
|
8821
8970
|
const vectorObservations = await Promise.all(vectorHits.map(async (hit) => {
|
|
8971
|
+
if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) return null;
|
|
8822
8972
|
const observation = await store.getById(hit.observationId);
|
|
8823
|
-
if (!observation) return null;
|
|
8973
|
+
if (!observation || observation.projectId !== hit.projectId) return null;
|
|
8824
8974
|
if (projectIds && !projectIds.includes(observation.projectId)) return null;
|
|
8825
8975
|
if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) return null;
|
|
8826
8976
|
if (options.type && observation.type !== options.type) return null;
|
|
8827
8977
|
if (options.source && observation.source !== options.source) return null;
|
|
8828
8978
|
addObservation(observation);
|
|
8829
|
-
vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
|
|
8979
|
+
vectorDocumentKeys.set(semanticVectorKey(hit.projectId, hit.observationId), makeEntryKey(observation.projectId, observation.id));
|
|
8830
8980
|
return observation;
|
|
8831
8981
|
}));
|
|
8832
8982
|
const RRF_K = 60;
|
|
@@ -8836,7 +8986,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
8836
8986
|
scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
|
|
8837
8987
|
}
|
|
8838
8988
|
for (const [index, hit] of vectorHits.entries()) {
|
|
8839
|
-
const key = vectorDocumentKeys.get(
|
|
8989
|
+
const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
|
|
8990
|
+
if (!key) continue;
|
|
8840
8991
|
if (!documents.has(key)) continue;
|
|
8841
8992
|
scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
|
|
8842
8993
|
}
|
|
@@ -8849,8 +9000,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
8849
9000
|
return {
|
|
8850
9001
|
count: vectorHits.length,
|
|
8851
9002
|
hits: vectorHits.map((hit, index) => {
|
|
8852
|
-
const key = vectorDocumentKeys.get(
|
|
8853
|
-
const document2 = documents.get(key);
|
|
9003
|
+
const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
|
|
9004
|
+
const document2 = key ? documents.get(key) : void 0;
|
|
8854
9005
|
return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
|
|
8855
9006
|
}).filter((hit) => hit !== null).slice(0, limit2)
|
|
8856
9007
|
};
|
|
@@ -8981,7 +9132,7 @@ function getActiveSemanticIndexProfile() {
|
|
|
8981
9132
|
}
|
|
8982
9133
|
async function getPersistentSemanticVectorIds(dataDir) {
|
|
8983
9134
|
if (!indexEmbeddingProvider) return null;
|
|
8984
|
-
return
|
|
9135
|
+
return listSemanticVectorKeys(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
|
|
8985
9136
|
}
|
|
8986
9137
|
async function queueSemanticVector(dataDir, record80) {
|
|
8987
9138
|
const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
|
|
@@ -9050,7 +9201,7 @@ function isCompatibleCachedVector(vector) {
|
|
|
9050
9201
|
async function attachCachedVectors(database, observations2) {
|
|
9051
9202
|
const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
|
|
9052
9203
|
const semanticProfile = getActiveSemanticIndexProfile();
|
|
9053
|
-
const persistedSemanticIds = semanticDataDir && semanticProfile ? await
|
|
9204
|
+
const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorKeys(semanticDataDir, semanticProfile).catch(() => null) : null;
|
|
9054
9205
|
const batchSize = 200;
|
|
9055
9206
|
for (let start = 0; start < observations2.length; start += batchSize) {
|
|
9056
9207
|
const batch = observations2.slice(start, start + batchSize);
|
|
@@ -9061,7 +9212,7 @@ async function attachCachedVectors(database, observations2) {
|
|
|
9061
9212
|
const vector = cachedVectors[index];
|
|
9062
9213
|
if (!isCompatibleCachedVector(vector)) continue;
|
|
9063
9214
|
const observation = batch[index];
|
|
9064
|
-
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
|
|
9215
|
+
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(semanticVectorKey(observation.projectId, observation.id))) {
|
|
9065
9216
|
semanticRecords.push({
|
|
9066
9217
|
observationId: observation.id,
|
|
9067
9218
|
projectId: observation.projectId,
|
|
@@ -9851,7 +10002,7 @@ function formatTime(isoDate) {
|
|
|
9851
10002
|
return isoDate;
|
|
9852
10003
|
}
|
|
9853
10004
|
}
|
|
9854
|
-
var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
|
|
10005
|
+
var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, searchDerivedViewRegistry, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
|
|
9855
10006
|
var init_orama_store = __esm({
|
|
9856
10007
|
"src/store/orama-store.ts"() {
|
|
9857
10008
|
"use strict";
|
|
@@ -9873,6 +10024,7 @@ var init_orama_store = __esm({
|
|
|
9873
10024
|
init_retrieval_contracts();
|
|
9874
10025
|
init_semantic_index();
|
|
9875
10026
|
init_derived_view_receipt();
|
|
10027
|
+
init_derived_view_registry();
|
|
9876
10028
|
db = null;
|
|
9877
10029
|
dbInitPromise = null;
|
|
9878
10030
|
dbGeneration = 0;
|
|
@@ -9884,8 +10036,12 @@ var init_orama_store = __esm({
|
|
|
9884
10036
|
CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
|
|
9885
10037
|
lastSearchModeByProject = /* @__PURE__ */ new Map();
|
|
9886
10038
|
lastSearchDiagnosticsByProject = /* @__PURE__ */ new Map();
|
|
10039
|
+
searchDerivedViewRegistry = new DerivedViewRegistry();
|
|
9887
10040
|
SEARCH_MODE_DEFAULT_KEY = "__global__";
|
|
9888
10041
|
MAX_SEARCH_MODE_KEYS = 4096;
|
|
10042
|
+
searchDerivedViewRegistry.register("fts", readFtsDerivedViewReceipt);
|
|
10043
|
+
searchDerivedViewRegistry.register("orama", readOramaDerivedViewReceipt);
|
|
10044
|
+
searchDerivedViewRegistry.register("embedding", readEmbeddingDerivedViewReceipt);
|
|
9889
10045
|
COMMAND_LOG_TITLE = /^(Ran:|Command:|Executed:)\s/i;
|
|
9890
10046
|
COMMAND_STYLE_TITLE = /(\bfindstr\b|\bSelect-String\b|\bGet-Content\b|\bnpx\s+vitest\b|\bnpx\s+tsc\b|\b2>&1\b)/i;
|
|
9891
10047
|
COMMAND_LIKE_QUERY2 = /\b(git|npm|npx|pnpm|yarn|node|bash|powershell|curl|memorix)\b/i;
|
|
@@ -19527,7 +19683,7 @@ var init_uuid = __esm({
|
|
|
19527
19683
|
});
|
|
19528
19684
|
|
|
19529
19685
|
// node_modules/openai/internal/errors.mjs
|
|
19530
|
-
function
|
|
19686
|
+
function isAbortError2(err) {
|
|
19531
19687
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
19532
19688
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
19533
19689
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -20707,7 +20863,7 @@ var init_streaming = __esm({
|
|
|
20707
20863
|
}
|
|
20708
20864
|
done = true;
|
|
20709
20865
|
} catch (e2) {
|
|
20710
|
-
if (
|
|
20866
|
+
if (isAbortError2(e2))
|
|
20711
20867
|
return;
|
|
20712
20868
|
throw e2;
|
|
20713
20869
|
} finally {
|
|
@@ -20750,7 +20906,7 @@ var init_streaming = __esm({
|
|
|
20750
20906
|
}
|
|
20751
20907
|
done = true;
|
|
20752
20908
|
} catch (e2) {
|
|
20753
|
-
if (
|
|
20909
|
+
if (isAbortError2(e2))
|
|
20754
20910
|
return;
|
|
20755
20911
|
throw e2;
|
|
20756
20912
|
} finally {
|
|
@@ -27299,7 +27455,7 @@ var init_client = __esm({
|
|
|
27299
27455
|
if (options.signal?.aborted) {
|
|
27300
27456
|
throw new APIUserAbortError();
|
|
27301
27457
|
}
|
|
27302
|
-
const isTimeout =
|
|
27458
|
+
const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
27303
27459
|
if (retriesRemaining) {
|
|
27304
27460
|
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
27305
27461
|
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
|
|
@@ -46388,7 +46544,7 @@ var init_uuid2 = __esm({
|
|
|
46388
46544
|
});
|
|
46389
46545
|
|
|
46390
46546
|
// node_modules/@anthropic-ai/sdk/internal/errors.mjs
|
|
46391
|
-
function
|
|
46547
|
+
function isAbortError3(err) {
|
|
46392
46548
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
46393
46549
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
46394
46550
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -47159,7 +47315,7 @@ var init_streaming3 = __esm({
|
|
|
47159
47315
|
}
|
|
47160
47316
|
done = true;
|
|
47161
47317
|
} catch (e2) {
|
|
47162
|
-
if (
|
|
47318
|
+
if (isAbortError3(e2))
|
|
47163
47319
|
return;
|
|
47164
47320
|
throw e2;
|
|
47165
47321
|
} finally {
|
|
@@ -47202,7 +47358,7 @@ var init_streaming3 = __esm({
|
|
|
47202
47358
|
}
|
|
47203
47359
|
done = true;
|
|
47204
47360
|
} catch (e2) {
|
|
47205
|
-
if (
|
|
47361
|
+
if (isAbortError3(e2))
|
|
47206
47362
|
return;
|
|
47207
47363
|
throw e2;
|
|
47208
47364
|
} finally {
|
|
@@ -49324,7 +49480,7 @@ var init_BetaMessageStream = __esm({
|
|
|
49324
49480
|
_BetaMessageStream_logger.set(this, void 0);
|
|
49325
49481
|
_BetaMessageStream_handleError.set(this, (error) => {
|
|
49326
49482
|
__classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
|
|
49327
|
-
if (
|
|
49483
|
+
if (isAbortError3(error)) {
|
|
49328
49484
|
error = new APIUserAbortError2();
|
|
49329
49485
|
}
|
|
49330
49486
|
if (error instanceof APIUserAbortError2) {
|
|
@@ -51785,7 +51941,7 @@ var init_MessageStream = __esm({
|
|
|
51785
51941
|
_MessageStream_logger.set(this, void 0);
|
|
51786
51942
|
_MessageStream_handleError.set(this, (error) => {
|
|
51787
51943
|
__classPrivateFieldSet2(this, _MessageStream_errored, true, "f");
|
|
51788
|
-
if (
|
|
51944
|
+
if (isAbortError3(error)) {
|
|
51789
51945
|
error = new APIUserAbortError2();
|
|
51790
51946
|
}
|
|
51791
51947
|
if (error instanceof APIUserAbortError2) {
|
|
@@ -52915,7 +53071,7 @@ var init_client2 = __esm({
|
|
|
52915
53071
|
if (options.signal?.aborted) {
|
|
52916
53072
|
throw new APIUserAbortError2();
|
|
52917
53073
|
}
|
|
52918
|
-
const isTimeout =
|
|
53074
|
+
const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
52919
53075
|
if (retriesRemaining) {
|
|
52920
53076
|
loggerFor2(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
52921
53077
|
loggerFor2(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails2({
|
|
@@ -87423,7 +87579,7 @@ function listDocumentsResponseFromMldev(fromObject) {
|
|
|
87423
87579
|
}
|
|
87424
87580
|
return toObject;
|
|
87425
87581
|
}
|
|
87426
|
-
function
|
|
87582
|
+
function isAbortError4(err) {
|
|
87427
87583
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
87428
87584
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
87429
87585
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -94637,7 +94793,7 @@ ${underline}`);
|
|
|
94637
94793
|
}
|
|
94638
94794
|
done = true;
|
|
94639
94795
|
} catch (e2) {
|
|
94640
|
-
if (
|
|
94796
|
+
if (isAbortError4(e2))
|
|
94641
94797
|
return yield __await(void 0);
|
|
94642
94798
|
throw e2;
|
|
94643
94799
|
} finally {
|
|
@@ -94712,7 +94868,7 @@ ${underline}`);
|
|
|
94712
94868
|
}
|
|
94713
94869
|
done = true;
|
|
94714
94870
|
} catch (e2) {
|
|
94715
|
-
if (
|
|
94871
|
+
if (isAbortError4(e2))
|
|
94716
94872
|
return yield __await(void 0);
|
|
94717
94873
|
throw e2;
|
|
94718
94874
|
} finally {
|
|
@@ -95088,7 +95244,7 @@ ${underline}`);
|
|
|
95088
95244
|
if ((_d = options.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
|
|
95089
95245
|
throw new APIUserAbortError3();
|
|
95090
95246
|
}
|
|
95091
|
-
const isTimeout =
|
|
95247
|
+
const isTimeout = isAbortError4(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
95092
95248
|
if (retriesRemaining) {
|
|
95093
95249
|
loggerFor3(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
95094
95250
|
loggerFor3(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails3({
|
|
@@ -97312,7 +97468,7 @@ function isTimeoutError(err) {
|
|
|
97312
97468
|
const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
|
|
97313
97469
|
return isNative || isLegacyNative || isGenericErr;
|
|
97314
97470
|
}
|
|
97315
|
-
function
|
|
97471
|
+
function isAbortError5(err) {
|
|
97316
97472
|
if (typeof err !== "object" || err == null) {
|
|
97317
97473
|
return false;
|
|
97318
97474
|
}
|
|
@@ -98324,7 +98480,7 @@ var init_sdks = __esm({
|
|
|
98324
98480
|
return response;
|
|
98325
98481
|
}, { config: options.retryConfig, statusCodes: options.retryCodes }).then((r2) => OK(r2), (err) => {
|
|
98326
98482
|
switch (true) {
|
|
98327
|
-
case
|
|
98483
|
+
case isAbortError5(err):
|
|
98328
98484
|
return ERR(new RequestAbortedError("Request aborted by client", {
|
|
98329
98485
|
cause: err
|
|
98330
98486
|
}));
|
|
@@ -151911,13 +152067,17 @@ async function enqueueObservationDerivedWork(tx, observation) {
|
|
|
151911
152067
|
payload: { observationId: observation.id }
|
|
151912
152068
|
});
|
|
151913
152069
|
}
|
|
152070
|
+
await enqueueObservationProjectionWork(tx, observation);
|
|
152071
|
+
return true;
|
|
152072
|
+
}
|
|
152073
|
+
async function enqueueObservationProjectionWork(tx, observation) {
|
|
152074
|
+
if (!tx.enqueueMaintenanceJob) return;
|
|
151914
152075
|
await tx.enqueueMaintenanceJob({
|
|
151915
152076
|
projectId: observation.projectId,
|
|
151916
152077
|
kind: "observation-project",
|
|
151917
152078
|
dedupeKey: "observation-project:" + observation.id,
|
|
151918
152079
|
payload: { observationId: observation.id }
|
|
151919
152080
|
});
|
|
151920
|
-
return true;
|
|
151921
152081
|
}
|
|
151922
152082
|
function isVectorCompatibleWithCurrentIndex(embedding) {
|
|
151923
152083
|
if (!embedding) return false;
|
|
@@ -152451,6 +152611,7 @@ async function updateObservationAdmission(input) {
|
|
|
152451
152611
|
const next = apply(current);
|
|
152452
152612
|
if (!next) return;
|
|
152453
152613
|
await tx.update(next);
|
|
152614
|
+
await enqueueObservationProjectionWork(tx, next);
|
|
152454
152615
|
updated = next;
|
|
152455
152616
|
});
|
|
152456
152617
|
} else {
|
|
@@ -152468,6 +152629,9 @@ async function updateObservationAdmission(input) {
|
|
|
152468
152629
|
});
|
|
152469
152630
|
} catch {
|
|
152470
152631
|
}
|
|
152632
|
+
if (await persistEvidenceCard(updated)) {
|
|
152633
|
+
await acknowledgeObservationProjection(updated);
|
|
152634
|
+
}
|
|
152471
152635
|
if (updated.admissionState === "qualified" && resolveObservationVisibility(updated) === "project") {
|
|
152472
152636
|
queueClaimDerivation(updated);
|
|
152473
152637
|
}
|
|
@@ -152538,10 +152702,17 @@ async function resolveObservations(ids, status = "resolved") {
|
|
|
152538
152702
|
if (projectDir && resolved.length > 0) {
|
|
152539
152703
|
const store = getObservationStore();
|
|
152540
152704
|
await store.atomic(async (tx) => {
|
|
152541
|
-
await Promise.all(changed.map((observation) =>
|
|
152705
|
+
await Promise.all(changed.map(async (observation) => {
|
|
152706
|
+
await tx.update(observation);
|
|
152707
|
+
await enqueueObservationProjectionWork(tx, observation);
|
|
152708
|
+
}));
|
|
152542
152709
|
});
|
|
152543
152710
|
}
|
|
152544
|
-
for (const observation of changed)
|
|
152711
|
+
for (const observation of changed) {
|
|
152712
|
+
if (await persistEvidenceCard(observation)) {
|
|
152713
|
+
await acknowledgeObservationProjection(observation);
|
|
152714
|
+
}
|
|
152715
|
+
}
|
|
152545
152716
|
return { resolved, notFound };
|
|
152546
152717
|
}
|
|
152547
152718
|
function getProjectObservations(projectId) {
|
|
@@ -152694,9 +152865,9 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152694
152865
|
for (const projectId of projects) {
|
|
152695
152866
|
const projectObservations = await store.loadByProject(projectId);
|
|
152696
152867
|
for (const observation of projectObservations) {
|
|
152697
|
-
if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
|
|
152868
|
+
if (!persistedIds?.has(semanticVectorKey(observation.projectId, observation.id))) markVectorMissing(observation.id, observation.projectId);
|
|
152698
152869
|
}
|
|
152699
|
-
if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
|
|
152870
|
+
if (projectObservations.some((observation) => !persistedIds?.has(semanticVectorKey(observation.projectId, observation.id)))) {
|
|
152700
152871
|
queueVectorBackfill(projectId);
|
|
152701
152872
|
}
|
|
152702
152873
|
}
|
|
@@ -152718,7 +152889,7 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152718
152889
|
const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
|
|
152719
152890
|
const projectsWithMissingVectors = /* @__PURE__ */ new Set();
|
|
152720
152891
|
for (const obs of observations) {
|
|
152721
|
-
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
|
|
152892
|
+
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(semanticVectorKey(obs.projectId, obs.id))) {
|
|
152722
152893
|
markVectorMissing(obs.id, obs.projectId);
|
|
152723
152894
|
projectsWithMissingVectors.add(obs.projectId);
|
|
152724
152895
|
}
|
|
@@ -152922,6 +153093,7 @@ var init_observations = __esm({
|
|
|
152922
153093
|
init_token_budget();
|
|
152923
153094
|
init_entity_extractor();
|
|
152924
153095
|
init_provider();
|
|
153096
|
+
init_semantic_index();
|
|
152925
153097
|
init_secret_filter();
|
|
152926
153098
|
init_lifecycle();
|
|
152927
153099
|
init_visibility();
|