memorix 1.6.3 → 1.7.1
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 +31 -0
- package/dist/cli/index.js +1029 -643
- package/dist/cli/memcode.js +0 -0
- package/dist/dashboard/static/app.js +298 -37
- package/dist/dashboard/static/index.html +17 -0
- package/dist/dashboard/static/style.css +328 -0
- package/dist/index.js +902 -394
- package/dist/memcode-runtime/CHANGELOG.md +31 -0
- package/dist/sdk.js +901 -393
- package/docs/ARCHITECTURE.md +3 -0
- package/docs/DASHBOARD.md +54 -0
- package/docs/README.md +2 -0
- package/package.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/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/commands/cleanup.ts +13 -114
- package/src/cli/commands/memory.ts +12 -43
- package/src/dashboard/maintenance.ts +303 -0
- package/src/dashboard/server.ts +100 -2
- package/src/dashboard/static/index.html +17 -0
- package/src/dashboard/static/style.css +328 -0
- package/src/memory/cleanup.ts +143 -0
- package/src/memory/deduplication.ts +178 -0
- package/src/server.ts +12 -46
package/dist/index.js
CHANGED
|
@@ -2685,29 +2685,29 @@ function sharedAgentIds(record80) {
|
|
|
2685
2685
|
return [];
|
|
2686
2686
|
}
|
|
2687
2687
|
}
|
|
2688
|
-
function canReadObservation(record80,
|
|
2689
|
-
if (!
|
|
2690
|
-
const sameProject =
|
|
2688
|
+
function canReadObservation(record80, reader2) {
|
|
2689
|
+
if (!reader2) return true;
|
|
2690
|
+
const sameProject = reader2.projectId === record80.projectId;
|
|
2691
2691
|
const visibility = resolveObservationVisibility(record80);
|
|
2692
|
-
if (visibility === "project") return !
|
|
2693
|
-
if (!sameProject || !
|
|
2694
|
-
if (visibility === "team") return
|
|
2695
|
-
return record80.createdByAgentId ===
|
|
2696
|
-
}
|
|
2697
|
-
function canManageObservation(record80,
|
|
2698
|
-
if (!
|
|
2699
|
-
if (!
|
|
2692
|
+
if (visibility === "project") return !reader2.projectId || sameProject;
|
|
2693
|
+
if (!sameProject || !reader2.agentId) return false;
|
|
2694
|
+
if (visibility === "team") return reader2.isTeamMember === true;
|
|
2695
|
+
return record80.createdByAgentId === reader2.agentId || sharedAgentIds(record80).includes(reader2.agentId);
|
|
2696
|
+
}
|
|
2697
|
+
function canManageObservation(record80, reader2) {
|
|
2698
|
+
if (!reader2) return true;
|
|
2699
|
+
if (!reader2.projectId || reader2.projectId !== record80.projectId) return false;
|
|
2700
2700
|
switch (resolveObservationVisibility(record80)) {
|
|
2701
2701
|
case "project":
|
|
2702
2702
|
return true;
|
|
2703
2703
|
case "team":
|
|
2704
|
-
return
|
|
2704
|
+
return reader2.isTeamMember === true;
|
|
2705
2705
|
case "personal":
|
|
2706
|
-
return Boolean(
|
|
2706
|
+
return Boolean(reader2.agentId && record80.createdByAgentId === reader2.agentId);
|
|
2707
2707
|
}
|
|
2708
2708
|
}
|
|
2709
|
-
function filterReadableObservations(observations2,
|
|
2710
|
-
return
|
|
2709
|
+
function filterReadableObservations(observations2, reader2) {
|
|
2710
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(observation, reader2)) : [...observations2];
|
|
2711
2711
|
}
|
|
2712
2712
|
var init_visibility = __esm({
|
|
2713
2713
|
"src/memory/visibility.ts"() {
|
|
@@ -5704,8 +5704,8 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5704
5704
|
if (contentLength && Number(contentLength) > maxBytes) {
|
|
5705
5705
|
throw new Error(`LLM response too large (${contentLength} bytes)`);
|
|
5706
5706
|
}
|
|
5707
|
-
const
|
|
5708
|
-
if (!
|
|
5707
|
+
const reader2 = response.body?.getReader();
|
|
5708
|
+
if (!reader2) {
|
|
5709
5709
|
signal?.throwIfAborted();
|
|
5710
5710
|
return response.text();
|
|
5711
5711
|
}
|
|
@@ -5713,19 +5713,19 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5713
5713
|
const chunks = [];
|
|
5714
5714
|
let bytesRead = 0;
|
|
5715
5715
|
const abortReader = () => {
|
|
5716
|
-
void
|
|
5716
|
+
void reader2.cancel(signal?.reason).catch(() => void 0);
|
|
5717
5717
|
};
|
|
5718
5718
|
signal?.addEventListener("abort", abortReader, { once: true });
|
|
5719
5719
|
try {
|
|
5720
5720
|
while (true) {
|
|
5721
5721
|
signal?.throwIfAborted();
|
|
5722
|
-
const { value, done } = await
|
|
5722
|
+
const { value, done } = await reader2.read();
|
|
5723
5723
|
if (done) break;
|
|
5724
5724
|
signal?.throwIfAborted();
|
|
5725
5725
|
if (!value) continue;
|
|
5726
5726
|
bytesRead += value.byteLength;
|
|
5727
5727
|
if (bytesRead > maxBytes) {
|
|
5728
|
-
await
|
|
5728
|
+
await reader2.cancel("response too large").catch(() => void 0);
|
|
5729
5729
|
throw new Error(`LLM response exceeded ${maxBytes} bytes`);
|
|
5730
5730
|
}
|
|
5731
5731
|
chunks.push(decoder.decode(value, { stream: true }));
|
|
@@ -5735,7 +5735,7 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5735
5735
|
return chunks.join("");
|
|
5736
5736
|
} finally {
|
|
5737
5737
|
signal?.removeEventListener("abort", abortReader);
|
|
5738
|
-
|
|
5738
|
+
reader2.releaseLock();
|
|
5739
5739
|
}
|
|
5740
5740
|
}
|
|
5741
5741
|
async function readResponseJson(response, signal, maxBytes = MAX_LLM_RESPONSE_BYTES) {
|
|
@@ -6065,8 +6065,8 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6065
6065
|
const error = await response.text().catch(() => "unknown error");
|
|
6066
6066
|
throw new Error(`LLM streaming API error (${response.status}): ${error}`);
|
|
6067
6067
|
}
|
|
6068
|
-
const
|
|
6069
|
-
if (!
|
|
6068
|
+
const reader2 = response.body?.getReader();
|
|
6069
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
6070
6070
|
const decoder = new TextDecoder();
|
|
6071
6071
|
let fullContent = "";
|
|
6072
6072
|
const toolCallMap = /* @__PURE__ */ new Map();
|
|
@@ -6074,7 +6074,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6074
6074
|
let buffer = "";
|
|
6075
6075
|
try {
|
|
6076
6076
|
while (true) {
|
|
6077
|
-
const { done, value } = await
|
|
6077
|
+
const { done, value } = await reader2.read();
|
|
6078
6078
|
if (done) break;
|
|
6079
6079
|
buffer += decoder.decode(value, { stream: true });
|
|
6080
6080
|
const lines = buffer.split("\n");
|
|
@@ -6116,7 +6116,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6116
6116
|
}
|
|
6117
6117
|
}
|
|
6118
6118
|
} finally {
|
|
6119
|
-
|
|
6119
|
+
reader2.releaseLock();
|
|
6120
6120
|
}
|
|
6121
6121
|
const toolCalls = [...toolCallMap.values()].map((tc) => ({
|
|
6122
6122
|
id: tc.id,
|
|
@@ -6197,8 +6197,8 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6197
6197
|
const error = await response.text().catch(() => "unknown error");
|
|
6198
6198
|
throw new Error(`Anthropic streaming API error (${response.status}): ${error}`);
|
|
6199
6199
|
}
|
|
6200
|
-
const
|
|
6201
|
-
if (!
|
|
6200
|
+
const reader2 = response.body?.getReader();
|
|
6201
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
6202
6202
|
const decoder = new TextDecoder();
|
|
6203
6203
|
let fullContent = "";
|
|
6204
6204
|
const toolCalls = [];
|
|
@@ -6209,7 +6209,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6209
6209
|
let buffer = "";
|
|
6210
6210
|
try {
|
|
6211
6211
|
while (true) {
|
|
6212
|
-
const { done, value } = await
|
|
6212
|
+
const { done, value } = await reader2.read();
|
|
6213
6213
|
if (done) break;
|
|
6214
6214
|
buffer += decoder.decode(value, { stream: true });
|
|
6215
6215
|
const lines = buffer.split("\n");
|
|
@@ -6257,7 +6257,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6257
6257
|
}
|
|
6258
6258
|
}
|
|
6259
6259
|
} finally {
|
|
6260
|
-
|
|
6260
|
+
reader2.releaseLock();
|
|
6261
6261
|
}
|
|
6262
6262
|
const mappedStopReason = stopReason === "tool_use" ? "tool_use" : stopReason === "end_turn" ? "end_turn" : "unknown";
|
|
6263
6263
|
yield {
|
|
@@ -7664,11 +7664,11 @@ async function getObservationsByIds(ids, projectId) {
|
|
|
7664
7664
|
}
|
|
7665
7665
|
return results;
|
|
7666
7666
|
}
|
|
7667
|
-
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
7667
|
+
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2) {
|
|
7668
7668
|
const { withFreshIndex: withFreshIndex2 } = await Promise.resolve().then(() => (init_freshness(), freshness_exports));
|
|
7669
7669
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
7670
7670
|
const rawObs = await withFreshIndex2(() => getAllObservations2());
|
|
7671
|
-
const allObs = (projectId ? rawObs.filter((o) => o.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation,
|
|
7671
|
+
const allObs = (projectId ? rawObs.filter((o) => o.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation, reader2));
|
|
7672
7672
|
const sorted = allObs.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
7673
7673
|
const anchorIndex = sorted.findIndex((o) => o.id === anchorId);
|
|
7674
7674
|
if (anchorIndex === -1) {
|
|
@@ -18893,12 +18893,12 @@ async function readBoundedImageResponse(response) {
|
|
|
18893
18893
|
}
|
|
18894
18894
|
if (!response.body)
|
|
18895
18895
|
throw new Error("MiniMax image generation returned an empty image response");
|
|
18896
|
-
const
|
|
18896
|
+
const reader2 = response.body.getReader();
|
|
18897
18897
|
const chunks = [];
|
|
18898
18898
|
let total = 0;
|
|
18899
18899
|
try {
|
|
18900
18900
|
while (true) {
|
|
18901
|
-
const { done, value } = await
|
|
18901
|
+
const { done, value } = await reader2.read();
|
|
18902
18902
|
if (done)
|
|
18903
18903
|
break;
|
|
18904
18904
|
if (!value)
|
|
@@ -18910,7 +18910,7 @@ async function readBoundedImageResponse(response) {
|
|
|
18910
18910
|
chunks.push(value);
|
|
18911
18911
|
}
|
|
18912
18912
|
} finally {
|
|
18913
|
-
|
|
18913
|
+
reader2.releaseLock();
|
|
18914
18914
|
}
|
|
18915
18915
|
return Buffer.concat(chunks);
|
|
18916
18916
|
}
|
|
@@ -19434,22 +19434,22 @@ function ReadableStreamFrom(iterable) {
|
|
|
19434
19434
|
function ReadableStreamToAsyncIterable(stream2) {
|
|
19435
19435
|
if (stream2[Symbol.asyncIterator])
|
|
19436
19436
|
return stream2;
|
|
19437
|
-
const
|
|
19437
|
+
const reader2 = stream2.getReader();
|
|
19438
19438
|
return {
|
|
19439
19439
|
async next() {
|
|
19440
19440
|
try {
|
|
19441
|
-
const result = await
|
|
19441
|
+
const result = await reader2.read();
|
|
19442
19442
|
if (result?.done)
|
|
19443
|
-
|
|
19443
|
+
reader2.releaseLock();
|
|
19444
19444
|
return result;
|
|
19445
19445
|
} catch (e2) {
|
|
19446
|
-
|
|
19446
|
+
reader2.releaseLock();
|
|
19447
19447
|
throw e2;
|
|
19448
19448
|
}
|
|
19449
19449
|
},
|
|
19450
19450
|
async return() {
|
|
19451
|
-
const cancelPromise =
|
|
19452
|
-
|
|
19451
|
+
const cancelPromise = reader2.cancel();
|
|
19452
|
+
reader2.releaseLock();
|
|
19453
19453
|
await cancelPromise;
|
|
19454
19454
|
return { done: true, value: void 0 };
|
|
19455
19455
|
},
|
|
@@ -19465,9 +19465,9 @@ async function CancelReadableStream(stream2) {
|
|
|
19465
19465
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
19466
19466
|
return;
|
|
19467
19467
|
}
|
|
19468
|
-
const
|
|
19469
|
-
const cancelPromise =
|
|
19470
|
-
|
|
19468
|
+
const reader2 = stream2.getReader();
|
|
19469
|
+
const cancelPromise = reader2.cancel();
|
|
19470
|
+
reader2.releaseLock();
|
|
19471
19471
|
await cancelPromise;
|
|
19472
19472
|
}
|
|
19473
19473
|
var init_shims = __esm({
|
|
@@ -22206,31 +22206,31 @@ var init_ChatCompletionStream = __esm({
|
|
|
22206
22206
|
const readQueue = [];
|
|
22207
22207
|
let done = false;
|
|
22208
22208
|
this.on("chunk", (chunk) => {
|
|
22209
|
-
const
|
|
22210
|
-
if (
|
|
22211
|
-
|
|
22209
|
+
const reader2 = readQueue.shift();
|
|
22210
|
+
if (reader2) {
|
|
22211
|
+
reader2.resolve(chunk);
|
|
22212
22212
|
} else {
|
|
22213
22213
|
pushQueue.push(chunk);
|
|
22214
22214
|
}
|
|
22215
22215
|
});
|
|
22216
22216
|
this.on("end", () => {
|
|
22217
22217
|
done = true;
|
|
22218
|
-
for (const
|
|
22219
|
-
|
|
22218
|
+
for (const reader2 of readQueue) {
|
|
22219
|
+
reader2.resolve(void 0);
|
|
22220
22220
|
}
|
|
22221
22221
|
readQueue.length = 0;
|
|
22222
22222
|
});
|
|
22223
22223
|
this.on("abort", (err) => {
|
|
22224
22224
|
done = true;
|
|
22225
|
-
for (const
|
|
22226
|
-
|
|
22225
|
+
for (const reader2 of readQueue) {
|
|
22226
|
+
reader2.reject(err);
|
|
22227
22227
|
}
|
|
22228
22228
|
readQueue.length = 0;
|
|
22229
22229
|
});
|
|
22230
22230
|
this.on("error", (err) => {
|
|
22231
22231
|
done = true;
|
|
22232
|
-
for (const
|
|
22233
|
-
|
|
22232
|
+
for (const reader2 of readQueue) {
|
|
22233
|
+
reader2.reject(err);
|
|
22234
22234
|
}
|
|
22235
22235
|
readQueue.length = 0;
|
|
22236
22236
|
});
|
|
@@ -23189,31 +23189,31 @@ var init_AssistantStream = __esm({
|
|
|
23189
23189
|
const readQueue = [];
|
|
23190
23190
|
let done = false;
|
|
23191
23191
|
this.on("event", (event) => {
|
|
23192
|
-
const
|
|
23193
|
-
if (
|
|
23194
|
-
|
|
23192
|
+
const reader2 = readQueue.shift();
|
|
23193
|
+
if (reader2) {
|
|
23194
|
+
reader2.resolve(event);
|
|
23195
23195
|
} else {
|
|
23196
23196
|
pushQueue.push(event);
|
|
23197
23197
|
}
|
|
23198
23198
|
});
|
|
23199
23199
|
this.on("end", () => {
|
|
23200
23200
|
done = true;
|
|
23201
|
-
for (const
|
|
23202
|
-
|
|
23201
|
+
for (const reader2 of readQueue) {
|
|
23202
|
+
reader2.resolve(void 0);
|
|
23203
23203
|
}
|
|
23204
23204
|
readQueue.length = 0;
|
|
23205
23205
|
});
|
|
23206
23206
|
this.on("abort", (err) => {
|
|
23207
23207
|
done = true;
|
|
23208
|
-
for (const
|
|
23209
|
-
|
|
23208
|
+
for (const reader2 of readQueue) {
|
|
23209
|
+
reader2.reject(err);
|
|
23210
23210
|
}
|
|
23211
23211
|
readQueue.length = 0;
|
|
23212
23212
|
});
|
|
23213
23213
|
this.on("error", (err) => {
|
|
23214
23214
|
done = true;
|
|
23215
|
-
for (const
|
|
23216
|
-
|
|
23215
|
+
for (const reader2 of readQueue) {
|
|
23216
|
+
reader2.reject(err);
|
|
23217
23217
|
}
|
|
23218
23218
|
readQueue.length = 0;
|
|
23219
23219
|
});
|
|
@@ -25478,31 +25478,31 @@ var init_ResponseStream = __esm({
|
|
|
25478
25478
|
const readQueue = [];
|
|
25479
25479
|
let done = false;
|
|
25480
25480
|
this.on("event", (event) => {
|
|
25481
|
-
const
|
|
25482
|
-
if (
|
|
25483
|
-
|
|
25481
|
+
const reader2 = readQueue.shift();
|
|
25482
|
+
if (reader2) {
|
|
25483
|
+
reader2.resolve(event);
|
|
25484
25484
|
} else {
|
|
25485
25485
|
pushQueue.push(event);
|
|
25486
25486
|
}
|
|
25487
25487
|
});
|
|
25488
25488
|
this.on("end", () => {
|
|
25489
25489
|
done = true;
|
|
25490
|
-
for (const
|
|
25491
|
-
|
|
25490
|
+
for (const reader2 of readQueue) {
|
|
25491
|
+
reader2.resolve(void 0);
|
|
25492
25492
|
}
|
|
25493
25493
|
readQueue.length = 0;
|
|
25494
25494
|
});
|
|
25495
25495
|
this.on("abort", (err) => {
|
|
25496
25496
|
done = true;
|
|
25497
|
-
for (const
|
|
25498
|
-
|
|
25497
|
+
for (const reader2 of readQueue) {
|
|
25498
|
+
reader2.reject(err);
|
|
25499
25499
|
}
|
|
25500
25500
|
readQueue.length = 0;
|
|
25501
25501
|
});
|
|
25502
25502
|
this.on("error", (err) => {
|
|
25503
25503
|
done = true;
|
|
25504
|
-
for (const
|
|
25505
|
-
|
|
25504
|
+
for (const reader2 of readQueue) {
|
|
25505
|
+
reader2.reject(err);
|
|
25506
25506
|
}
|
|
25507
25507
|
readQueue.length = 0;
|
|
25508
25508
|
});
|
|
@@ -46218,22 +46218,22 @@ function ReadableStreamFrom2(iterable) {
|
|
|
46218
46218
|
function ReadableStreamToAsyncIterable2(stream2) {
|
|
46219
46219
|
if (stream2[Symbol.asyncIterator])
|
|
46220
46220
|
return stream2;
|
|
46221
|
-
const
|
|
46221
|
+
const reader2 = stream2.getReader();
|
|
46222
46222
|
return {
|
|
46223
46223
|
async next() {
|
|
46224
46224
|
try {
|
|
46225
|
-
const result = await
|
|
46225
|
+
const result = await reader2.read();
|
|
46226
46226
|
if (result?.done)
|
|
46227
|
-
|
|
46227
|
+
reader2.releaseLock();
|
|
46228
46228
|
return result;
|
|
46229
46229
|
} catch (e2) {
|
|
46230
|
-
|
|
46230
|
+
reader2.releaseLock();
|
|
46231
46231
|
throw e2;
|
|
46232
46232
|
}
|
|
46233
46233
|
},
|
|
46234
46234
|
async return() {
|
|
46235
|
-
const cancelPromise =
|
|
46236
|
-
|
|
46235
|
+
const cancelPromise = reader2.cancel();
|
|
46236
|
+
reader2.releaseLock();
|
|
46237
46237
|
await cancelPromise;
|
|
46238
46238
|
return { done: true, value: void 0 };
|
|
46239
46239
|
},
|
|
@@ -46249,9 +46249,9 @@ async function CancelReadableStream2(stream2) {
|
|
|
46249
46249
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
46250
46250
|
return;
|
|
46251
46251
|
}
|
|
46252
|
-
const
|
|
46253
|
-
const cancelPromise =
|
|
46254
|
-
|
|
46252
|
+
const reader2 = stream2.getReader();
|
|
46253
|
+
const cancelPromise = reader2.cancel();
|
|
46254
|
+
reader2.releaseLock();
|
|
46255
46255
|
await cancelPromise;
|
|
46256
46256
|
}
|
|
46257
46257
|
var init_shims2 = __esm({
|
|
@@ -49278,31 +49278,31 @@ var init_BetaMessageStream = __esm({
|
|
|
49278
49278
|
const readQueue = [];
|
|
49279
49279
|
let done = false;
|
|
49280
49280
|
this.on("streamEvent", (event) => {
|
|
49281
|
-
const
|
|
49282
|
-
if (
|
|
49283
|
-
|
|
49281
|
+
const reader2 = readQueue.shift();
|
|
49282
|
+
if (reader2) {
|
|
49283
|
+
reader2.resolve(event);
|
|
49284
49284
|
} else {
|
|
49285
49285
|
pushQueue.push(event);
|
|
49286
49286
|
}
|
|
49287
49287
|
});
|
|
49288
49288
|
this.on("end", () => {
|
|
49289
49289
|
done = true;
|
|
49290
|
-
for (const
|
|
49291
|
-
|
|
49290
|
+
for (const reader2 of readQueue) {
|
|
49291
|
+
reader2.resolve(void 0);
|
|
49292
49292
|
}
|
|
49293
49293
|
readQueue.length = 0;
|
|
49294
49294
|
});
|
|
49295
49295
|
this.on("abort", (err) => {
|
|
49296
49296
|
done = true;
|
|
49297
|
-
for (const
|
|
49298
|
-
|
|
49297
|
+
for (const reader2 of readQueue) {
|
|
49298
|
+
reader2.reject(err);
|
|
49299
49299
|
}
|
|
49300
49300
|
readQueue.length = 0;
|
|
49301
49301
|
});
|
|
49302
49302
|
this.on("error", (err) => {
|
|
49303
49303
|
done = true;
|
|
49304
|
-
for (const
|
|
49305
|
-
|
|
49304
|
+
for (const reader2 of readQueue) {
|
|
49305
|
+
reader2.reject(err);
|
|
49306
49306
|
}
|
|
49307
49307
|
readQueue.length = 0;
|
|
49308
49308
|
});
|
|
@@ -51714,31 +51714,31 @@ var init_MessageStream = __esm({
|
|
|
51714
51714
|
const readQueue = [];
|
|
51715
51715
|
let done = false;
|
|
51716
51716
|
this.on("streamEvent", (event) => {
|
|
51717
|
-
const
|
|
51718
|
-
if (
|
|
51719
|
-
|
|
51717
|
+
const reader2 = readQueue.shift();
|
|
51718
|
+
if (reader2) {
|
|
51719
|
+
reader2.resolve(event);
|
|
51720
51720
|
} else {
|
|
51721
51721
|
pushQueue.push(event);
|
|
51722
51722
|
}
|
|
51723
51723
|
});
|
|
51724
51724
|
this.on("end", () => {
|
|
51725
51725
|
done = true;
|
|
51726
|
-
for (const
|
|
51727
|
-
|
|
51726
|
+
for (const reader2 of readQueue) {
|
|
51727
|
+
reader2.resolve(void 0);
|
|
51728
51728
|
}
|
|
51729
51729
|
readQueue.length = 0;
|
|
51730
51730
|
});
|
|
51731
51731
|
this.on("abort", (err) => {
|
|
51732
51732
|
done = true;
|
|
51733
|
-
for (const
|
|
51734
|
-
|
|
51733
|
+
for (const reader2 of readQueue) {
|
|
51734
|
+
reader2.reject(err);
|
|
51735
51735
|
}
|
|
51736
51736
|
readQueue.length = 0;
|
|
51737
51737
|
});
|
|
51738
51738
|
this.on("error", (err) => {
|
|
51739
51739
|
done = true;
|
|
51740
|
-
for (const
|
|
51741
|
-
|
|
51740
|
+
for (const reader2 of readQueue) {
|
|
51741
|
+
reader2.reject(err);
|
|
51742
51742
|
}
|
|
51743
51743
|
readQueue.length = 0;
|
|
51744
51744
|
});
|
|
@@ -53408,7 +53408,7 @@ function consumeLine(text2) {
|
|
|
53408
53408
|
};
|
|
53409
53409
|
}
|
|
53410
53410
|
async function* iterateSseMessages(body, signal) {
|
|
53411
|
-
const
|
|
53411
|
+
const reader2 = body.getReader();
|
|
53412
53412
|
const decoder = new TextDecoder();
|
|
53413
53413
|
const state = { event: null, data: [], raw: [] };
|
|
53414
53414
|
let buffer = "";
|
|
@@ -53417,7 +53417,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
53417
53417
|
if (signal?.aborted) {
|
|
53418
53418
|
throw new Error("Request was aborted");
|
|
53419
53419
|
}
|
|
53420
|
-
const { value, done } = await
|
|
53420
|
+
const { value, done } = await reader2.read();
|
|
53421
53421
|
if (done) {
|
|
53422
53422
|
break;
|
|
53423
53423
|
}
|
|
@@ -53453,7 +53453,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
53453
53453
|
yield trailingEvent;
|
|
53454
53454
|
}
|
|
53455
53455
|
} finally {
|
|
53456
|
-
|
|
53456
|
+
reader2.releaseLock();
|
|
53457
53457
|
}
|
|
53458
53458
|
}
|
|
53459
53459
|
async function* iterateAnthropicEvents(response, signal) {
|
|
@@ -56296,7 +56296,7 @@ var require_supports_color = __commonJS({
|
|
|
56296
56296
|
return 1;
|
|
56297
56297
|
}
|
|
56298
56298
|
if ("CI" in env2) {
|
|
56299
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((
|
|
56299
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign2) => sign2 in env2) || env2.CI_NAME === "codeship") {
|
|
56300
56300
|
return 1;
|
|
56301
56301
|
}
|
|
56302
56302
|
return min;
|
|
@@ -57225,68 +57225,68 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57225
57225
|
const CancelSteps = /* @__PURE__ */ Symbol("[[CancelSteps]]");
|
|
57226
57226
|
const PullSteps = /* @__PURE__ */ Symbol("[[PullSteps]]");
|
|
57227
57227
|
const ReleaseSteps = /* @__PURE__ */ Symbol("[[ReleaseSteps]]");
|
|
57228
|
-
function ReadableStreamReaderGenericInitialize(
|
|
57229
|
-
|
|
57230
|
-
stream2._reader =
|
|
57228
|
+
function ReadableStreamReaderGenericInitialize(reader2, stream2) {
|
|
57229
|
+
reader2._ownerReadableStream = stream2;
|
|
57230
|
+
stream2._reader = reader2;
|
|
57231
57231
|
if (stream2._state === "readable") {
|
|
57232
|
-
defaultReaderClosedPromiseInitialize(
|
|
57232
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57233
57233
|
} else if (stream2._state === "closed") {
|
|
57234
|
-
defaultReaderClosedPromiseInitializeAsResolved(
|
|
57234
|
+
defaultReaderClosedPromiseInitializeAsResolved(reader2);
|
|
57235
57235
|
} else {
|
|
57236
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
57236
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, stream2._storedError);
|
|
57237
57237
|
}
|
|
57238
57238
|
}
|
|
57239
|
-
function ReadableStreamReaderGenericCancel(
|
|
57240
|
-
const stream2 =
|
|
57239
|
+
function ReadableStreamReaderGenericCancel(reader2, reason) {
|
|
57240
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57241
57241
|
return ReadableStreamCancel(stream2, reason);
|
|
57242
57242
|
}
|
|
57243
|
-
function ReadableStreamReaderGenericRelease(
|
|
57244
|
-
const stream2 =
|
|
57243
|
+
function ReadableStreamReaderGenericRelease(reader2) {
|
|
57244
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57245
57245
|
if (stream2._state === "readable") {
|
|
57246
|
-
defaultReaderClosedPromiseReject(
|
|
57246
|
+
defaultReaderClosedPromiseReject(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
57247
57247
|
} else {
|
|
57248
|
-
defaultReaderClosedPromiseResetToRejected(
|
|
57248
|
+
defaultReaderClosedPromiseResetToRejected(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
57249
57249
|
}
|
|
57250
57250
|
stream2._readableStreamController[ReleaseSteps]();
|
|
57251
57251
|
stream2._reader = void 0;
|
|
57252
|
-
|
|
57252
|
+
reader2._ownerReadableStream = void 0;
|
|
57253
57253
|
}
|
|
57254
57254
|
function readerLockException(name) {
|
|
57255
57255
|
return new TypeError("Cannot " + name + " a stream using a released reader");
|
|
57256
57256
|
}
|
|
57257
|
-
function defaultReaderClosedPromiseInitialize(
|
|
57258
|
-
|
|
57259
|
-
|
|
57260
|
-
|
|
57257
|
+
function defaultReaderClosedPromiseInitialize(reader2) {
|
|
57258
|
+
reader2._closedPromise = newPromise((resolve2, reject) => {
|
|
57259
|
+
reader2._closedPromise_resolve = resolve2;
|
|
57260
|
+
reader2._closedPromise_reject = reject;
|
|
57261
57261
|
});
|
|
57262
57262
|
}
|
|
57263
|
-
function defaultReaderClosedPromiseInitializeAsRejected(
|
|
57264
|
-
defaultReaderClosedPromiseInitialize(
|
|
57265
|
-
defaultReaderClosedPromiseReject(
|
|
57263
|
+
function defaultReaderClosedPromiseInitializeAsRejected(reader2, reason) {
|
|
57264
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57265
|
+
defaultReaderClosedPromiseReject(reader2, reason);
|
|
57266
57266
|
}
|
|
57267
|
-
function defaultReaderClosedPromiseInitializeAsResolved(
|
|
57268
|
-
defaultReaderClosedPromiseInitialize(
|
|
57269
|
-
defaultReaderClosedPromiseResolve(
|
|
57267
|
+
function defaultReaderClosedPromiseInitializeAsResolved(reader2) {
|
|
57268
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57269
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
57270
57270
|
}
|
|
57271
|
-
function defaultReaderClosedPromiseReject(
|
|
57272
|
-
if (
|
|
57271
|
+
function defaultReaderClosedPromiseReject(reader2, reason) {
|
|
57272
|
+
if (reader2._closedPromise_reject === void 0) {
|
|
57273
57273
|
return;
|
|
57274
57274
|
}
|
|
57275
|
-
setPromiseIsHandledToTrue(
|
|
57276
|
-
|
|
57277
|
-
|
|
57278
|
-
|
|
57275
|
+
setPromiseIsHandledToTrue(reader2._closedPromise);
|
|
57276
|
+
reader2._closedPromise_reject(reason);
|
|
57277
|
+
reader2._closedPromise_resolve = void 0;
|
|
57278
|
+
reader2._closedPromise_reject = void 0;
|
|
57279
57279
|
}
|
|
57280
|
-
function defaultReaderClosedPromiseResetToRejected(
|
|
57281
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
57280
|
+
function defaultReaderClosedPromiseResetToRejected(reader2, reason) {
|
|
57281
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, reason);
|
|
57282
57282
|
}
|
|
57283
|
-
function defaultReaderClosedPromiseResolve(
|
|
57284
|
-
if (
|
|
57283
|
+
function defaultReaderClosedPromiseResolve(reader2) {
|
|
57284
|
+
if (reader2._closedPromise_resolve === void 0) {
|
|
57285
57285
|
return;
|
|
57286
57286
|
}
|
|
57287
|
-
|
|
57288
|
-
|
|
57289
|
-
|
|
57287
|
+
reader2._closedPromise_resolve(void 0);
|
|
57288
|
+
reader2._closedPromise_resolve = void 0;
|
|
57289
|
+
reader2._closedPromise_reject = void 0;
|
|
57290
57290
|
}
|
|
57291
57291
|
const NumberIsFinite = Number.isFinite || function(x2) {
|
|
57292
57292
|
return typeof x2 === "number" && isFinite(x2);
|
|
@@ -57363,8 +57363,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57363
57363
|
stream2._reader._readRequests.push(readRequest);
|
|
57364
57364
|
}
|
|
57365
57365
|
function ReadableStreamFulfillReadRequest(stream2, chunk, done) {
|
|
57366
|
-
const
|
|
57367
|
-
const readRequest =
|
|
57366
|
+
const reader2 = stream2._reader;
|
|
57367
|
+
const readRequest = reader2._readRequests.shift();
|
|
57368
57368
|
if (done) {
|
|
57369
57369
|
readRequest._closeSteps();
|
|
57370
57370
|
} else {
|
|
@@ -57375,11 +57375,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57375
57375
|
return stream2._reader._readRequests.length;
|
|
57376
57376
|
}
|
|
57377
57377
|
function ReadableStreamHasDefaultReader(stream2) {
|
|
57378
|
-
const
|
|
57379
|
-
if (
|
|
57378
|
+
const reader2 = stream2._reader;
|
|
57379
|
+
if (reader2 === void 0) {
|
|
57380
57380
|
return false;
|
|
57381
57381
|
}
|
|
57382
|
-
if (!IsReadableStreamDefaultReader(
|
|
57382
|
+
if (!IsReadableStreamDefaultReader(reader2)) {
|
|
57383
57383
|
return false;
|
|
57384
57384
|
}
|
|
57385
57385
|
return true;
|
|
@@ -57485,8 +57485,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57485
57485
|
}
|
|
57486
57486
|
return x2 instanceof ReadableStreamDefaultReader;
|
|
57487
57487
|
}
|
|
57488
|
-
function ReadableStreamDefaultReaderRead(
|
|
57489
|
-
const stream2 =
|
|
57488
|
+
function ReadableStreamDefaultReaderRead(reader2, readRequest) {
|
|
57489
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57490
57490
|
stream2._disturbed = true;
|
|
57491
57491
|
if (stream2._state === "closed") {
|
|
57492
57492
|
readRequest._closeSteps();
|
|
@@ -57496,14 +57496,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57496
57496
|
stream2._readableStreamController[PullSteps](readRequest);
|
|
57497
57497
|
}
|
|
57498
57498
|
}
|
|
57499
|
-
function ReadableStreamDefaultReaderRelease(
|
|
57500
|
-
ReadableStreamReaderGenericRelease(
|
|
57499
|
+
function ReadableStreamDefaultReaderRelease(reader2) {
|
|
57500
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57501
57501
|
const e2 = new TypeError("Reader was released");
|
|
57502
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
57502
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e2);
|
|
57503
57503
|
}
|
|
57504
|
-
function ReadableStreamDefaultReaderErrorReadRequests(
|
|
57505
|
-
const readRequests =
|
|
57506
|
-
|
|
57504
|
+
function ReadableStreamDefaultReaderErrorReadRequests(reader2, e2) {
|
|
57505
|
+
const readRequests = reader2._readRequests;
|
|
57506
|
+
reader2._readRequests = new SimpleQueue();
|
|
57507
57507
|
readRequests.forEach((readRequest) => {
|
|
57508
57508
|
readRequest._errorSteps(e2);
|
|
57509
57509
|
});
|
|
@@ -57514,10 +57514,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57514
57514
|
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
|
|
57515
57515
|
}).prototype);
|
|
57516
57516
|
class ReadableStreamAsyncIteratorImpl {
|
|
57517
|
-
constructor(
|
|
57517
|
+
constructor(reader2, preventCancel) {
|
|
57518
57518
|
this._ongoingPromise = void 0;
|
|
57519
57519
|
this._isFinished = false;
|
|
57520
|
-
this._reader =
|
|
57520
|
+
this._reader = reader2;
|
|
57521
57521
|
this._preventCancel = preventCancel;
|
|
57522
57522
|
}
|
|
57523
57523
|
next() {
|
|
@@ -57533,7 +57533,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57533
57533
|
if (this._isFinished) {
|
|
57534
57534
|
return Promise.resolve({ value: void 0, done: true });
|
|
57535
57535
|
}
|
|
57536
|
-
const
|
|
57536
|
+
const reader2 = this._reader;
|
|
57537
57537
|
let resolvePromise;
|
|
57538
57538
|
let rejectPromise;
|
|
57539
57539
|
const promise = newPromise((resolve2, reject) => {
|
|
@@ -57548,17 +57548,17 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57548
57548
|
_closeSteps: () => {
|
|
57549
57549
|
this._ongoingPromise = void 0;
|
|
57550
57550
|
this._isFinished = true;
|
|
57551
|
-
ReadableStreamReaderGenericRelease(
|
|
57551
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57552
57552
|
resolvePromise({ value: void 0, done: true });
|
|
57553
57553
|
},
|
|
57554
57554
|
_errorSteps: (reason) => {
|
|
57555
57555
|
this._ongoingPromise = void 0;
|
|
57556
57556
|
this._isFinished = true;
|
|
57557
|
-
ReadableStreamReaderGenericRelease(
|
|
57557
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57558
57558
|
rejectPromise(reason);
|
|
57559
57559
|
}
|
|
57560
57560
|
};
|
|
57561
|
-
ReadableStreamDefaultReaderRead(
|
|
57561
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
57562
57562
|
return promise;
|
|
57563
57563
|
}
|
|
57564
57564
|
_returnSteps(value) {
|
|
@@ -57566,13 +57566,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57566
57566
|
return Promise.resolve({ value, done: true });
|
|
57567
57567
|
}
|
|
57568
57568
|
this._isFinished = true;
|
|
57569
|
-
const
|
|
57569
|
+
const reader2 = this._reader;
|
|
57570
57570
|
if (!this._preventCancel) {
|
|
57571
|
-
const result = ReadableStreamReaderGenericCancel(
|
|
57572
|
-
ReadableStreamReaderGenericRelease(
|
|
57571
|
+
const result = ReadableStreamReaderGenericCancel(reader2, value);
|
|
57572
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57573
57573
|
return transformPromiseWith(result, () => ({ value, done: true }));
|
|
57574
57574
|
}
|
|
57575
|
-
ReadableStreamReaderGenericRelease(
|
|
57575
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57576
57576
|
return promiseResolvedWith({ value, done: true });
|
|
57577
57577
|
}
|
|
57578
57578
|
}
|
|
@@ -57592,8 +57592,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57592
57592
|
};
|
|
57593
57593
|
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
|
57594
57594
|
function AcquireReadableStreamAsyncIterator(stream2, preventCancel) {
|
|
57595
|
-
const
|
|
57596
|
-
const impl = new ReadableStreamAsyncIteratorImpl(
|
|
57595
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
57596
|
+
const impl = new ReadableStreamAsyncIteratorImpl(reader2, preventCancel);
|
|
57597
57597
|
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
57598
57598
|
iterator._asyncIteratorImpl = impl;
|
|
57599
57599
|
return iterator;
|
|
@@ -58097,12 +58097,12 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58097
58097
|
}
|
|
58098
58098
|
}
|
|
58099
58099
|
function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
|
|
58100
|
-
const
|
|
58101
|
-
while (
|
|
58100
|
+
const reader2 = controller._controlledReadableByteStream._reader;
|
|
58101
|
+
while (reader2._readRequests.length > 0) {
|
|
58102
58102
|
if (controller._queueTotalSize === 0) {
|
|
58103
58103
|
return;
|
|
58104
58104
|
}
|
|
58105
|
-
const readRequest =
|
|
58105
|
+
const readRequest = reader2._readRequests.shift();
|
|
58106
58106
|
ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
|
|
58107
58107
|
}
|
|
58108
58108
|
}
|
|
@@ -58462,8 +58462,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58462
58462
|
stream2._reader._readIntoRequests.push(readIntoRequest);
|
|
58463
58463
|
}
|
|
58464
58464
|
function ReadableStreamFulfillReadIntoRequest(stream2, chunk, done) {
|
|
58465
|
-
const
|
|
58466
|
-
const readIntoRequest =
|
|
58465
|
+
const reader2 = stream2._reader;
|
|
58466
|
+
const readIntoRequest = reader2._readIntoRequests.shift();
|
|
58467
58467
|
if (done) {
|
|
58468
58468
|
readIntoRequest._closeSteps(chunk);
|
|
58469
58469
|
} else {
|
|
@@ -58474,11 +58474,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58474
58474
|
return stream2._reader._readIntoRequests.length;
|
|
58475
58475
|
}
|
|
58476
58476
|
function ReadableStreamHasBYOBReader(stream2) {
|
|
58477
|
-
const
|
|
58478
|
-
if (
|
|
58477
|
+
const reader2 = stream2._reader;
|
|
58478
|
+
if (reader2 === void 0) {
|
|
58479
58479
|
return false;
|
|
58480
58480
|
}
|
|
58481
|
-
if (!IsReadableStreamBYOBReader(
|
|
58481
|
+
if (!IsReadableStreamBYOBReader(reader2)) {
|
|
58482
58482
|
return false;
|
|
58483
58483
|
}
|
|
58484
58484
|
return true;
|
|
@@ -58611,8 +58611,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58611
58611
|
}
|
|
58612
58612
|
return x2 instanceof ReadableStreamBYOBReader;
|
|
58613
58613
|
}
|
|
58614
|
-
function ReadableStreamBYOBReaderRead(
|
|
58615
|
-
const stream2 =
|
|
58614
|
+
function ReadableStreamBYOBReaderRead(reader2, view, min, readIntoRequest) {
|
|
58615
|
+
const stream2 = reader2._ownerReadableStream;
|
|
58616
58616
|
stream2._disturbed = true;
|
|
58617
58617
|
if (stream2._state === "errored") {
|
|
58618
58618
|
readIntoRequest._errorSteps(stream2._storedError);
|
|
@@ -58620,14 +58620,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58620
58620
|
ReadableByteStreamControllerPullInto(stream2._readableStreamController, view, min, readIntoRequest);
|
|
58621
58621
|
}
|
|
58622
58622
|
}
|
|
58623
|
-
function ReadableStreamBYOBReaderRelease(
|
|
58624
|
-
ReadableStreamReaderGenericRelease(
|
|
58623
|
+
function ReadableStreamBYOBReaderRelease(reader2) {
|
|
58624
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
58625
58625
|
const e2 = new TypeError("Reader was released");
|
|
58626
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
58626
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2);
|
|
58627
58627
|
}
|
|
58628
|
-
function ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
58629
|
-
const readIntoRequests =
|
|
58630
|
-
|
|
58628
|
+
function ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2) {
|
|
58629
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
58630
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
58631
58631
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
58632
58632
|
readIntoRequest._errorSteps(e2);
|
|
58633
58633
|
});
|
|
@@ -59642,7 +59642,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59642
59642
|
}
|
|
59643
59643
|
const DOMException3 = getFromGlobal() || createPolyfill();
|
|
59644
59644
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
59645
|
-
const
|
|
59645
|
+
const reader2 = AcquireReadableStreamDefaultReader(source);
|
|
59646
59646
|
const writer = AcquireWritableStreamDefaultWriter(dest);
|
|
59647
59647
|
source._disturbed = true;
|
|
59648
59648
|
let shuttingDown = false;
|
|
@@ -59695,7 +59695,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59695
59695
|
}
|
|
59696
59696
|
return PerformPromiseThen(writer._readyPromise, () => {
|
|
59697
59697
|
return newPromise((resolveRead, rejectRead) => {
|
|
59698
|
-
ReadableStreamDefaultReaderRead(
|
|
59698
|
+
ReadableStreamDefaultReaderRead(reader2, {
|
|
59699
59699
|
_chunkSteps: (chunk) => {
|
|
59700
59700
|
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop5);
|
|
59701
59701
|
resolveRead(false);
|
|
@@ -59706,7 +59706,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59706
59706
|
});
|
|
59707
59707
|
});
|
|
59708
59708
|
}
|
|
59709
|
-
isOrBecomesErrored(source,
|
|
59709
|
+
isOrBecomesErrored(source, reader2._closedPromise, (storedError) => {
|
|
59710
59710
|
if (!preventAbort) {
|
|
59711
59711
|
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
|
59712
59712
|
} else {
|
|
@@ -59722,7 +59722,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59722
59722
|
}
|
|
59723
59723
|
return null;
|
|
59724
59724
|
});
|
|
59725
|
-
isOrBecomesClosed(source,
|
|
59725
|
+
isOrBecomesClosed(source, reader2._closedPromise, () => {
|
|
59726
59726
|
if (!preventClose) {
|
|
59727
59727
|
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
|
59728
59728
|
} else {
|
|
@@ -59785,7 +59785,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59785
59785
|
}
|
|
59786
59786
|
function finalize(isError, error) {
|
|
59787
59787
|
WritableStreamDefaultWriterRelease(writer);
|
|
59788
|
-
ReadableStreamReaderGenericRelease(
|
|
59788
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
59789
59789
|
if (signal !== void 0) {
|
|
59790
59790
|
signal.removeEventListener("abort", abortAlgorithm);
|
|
59791
59791
|
}
|
|
@@ -60063,7 +60063,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60063
60063
|
return ReadableStreamDefaultTee(stream2);
|
|
60064
60064
|
}
|
|
60065
60065
|
function ReadableStreamDefaultTee(stream2, cloneForBranch2) {
|
|
60066
|
-
const
|
|
60066
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60067
60067
|
let reading = false;
|
|
60068
60068
|
let readAgain = false;
|
|
60069
60069
|
let canceled1 = false;
|
|
@@ -60116,7 +60116,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60116
60116
|
reading = false;
|
|
60117
60117
|
}
|
|
60118
60118
|
};
|
|
60119
|
-
ReadableStreamDefaultReaderRead(
|
|
60119
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
60120
60120
|
return promiseResolvedWith(void 0);
|
|
60121
60121
|
}
|
|
60122
60122
|
function cancel1Algorithm(reason) {
|
|
@@ -60143,7 +60143,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60143
60143
|
}
|
|
60144
60144
|
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
60145
60145
|
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
60146
|
-
uponRejection(
|
|
60146
|
+
uponRejection(reader2._closedPromise, (r2) => {
|
|
60147
60147
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r2);
|
|
60148
60148
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r2);
|
|
60149
60149
|
if (!canceled1 || !canceled2) {
|
|
@@ -60154,7 +60154,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60154
60154
|
return [branch1, branch2];
|
|
60155
60155
|
}
|
|
60156
60156
|
function ReadableByteStreamTee(stream2) {
|
|
60157
|
-
let
|
|
60157
|
+
let reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60158
60158
|
let reading = false;
|
|
60159
60159
|
let readAgainForBranch1 = false;
|
|
60160
60160
|
let readAgainForBranch2 = false;
|
|
@@ -60170,7 +60170,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60170
60170
|
});
|
|
60171
60171
|
function forwardReaderError(thisReader) {
|
|
60172
60172
|
uponRejection(thisReader._closedPromise, (r2) => {
|
|
60173
|
-
if (thisReader !==
|
|
60173
|
+
if (thisReader !== reader2) {
|
|
60174
60174
|
return null;
|
|
60175
60175
|
}
|
|
60176
60176
|
ReadableByteStreamControllerError(branch1._readableStreamController, r2);
|
|
@@ -60182,10 +60182,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60182
60182
|
});
|
|
60183
60183
|
}
|
|
60184
60184
|
function pullWithDefaultReader() {
|
|
60185
|
-
if (IsReadableStreamBYOBReader(
|
|
60186
|
-
ReadableStreamReaderGenericRelease(
|
|
60187
|
-
|
|
60188
|
-
forwardReaderError(
|
|
60185
|
+
if (IsReadableStreamBYOBReader(reader2)) {
|
|
60186
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
60187
|
+
reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60188
|
+
forwardReaderError(reader2);
|
|
60189
60189
|
}
|
|
60190
60190
|
const readRequest = {
|
|
60191
60191
|
_chunkSteps: (chunk) => {
|
|
@@ -60240,13 +60240,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60240
60240
|
reading = false;
|
|
60241
60241
|
}
|
|
60242
60242
|
};
|
|
60243
|
-
ReadableStreamDefaultReaderRead(
|
|
60243
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
60244
60244
|
}
|
|
60245
60245
|
function pullWithBYOBReader(view, forBranch2) {
|
|
60246
|
-
if (IsReadableStreamDefaultReader(
|
|
60247
|
-
ReadableStreamReaderGenericRelease(
|
|
60248
|
-
|
|
60249
|
-
forwardReaderError(
|
|
60246
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60247
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
60248
|
+
reader2 = AcquireReadableStreamBYOBReader(stream2);
|
|
60249
|
+
forwardReaderError(reader2);
|
|
60250
60250
|
}
|
|
60251
60251
|
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
60252
60252
|
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
@@ -60308,7 +60308,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60308
60308
|
reading = false;
|
|
60309
60309
|
}
|
|
60310
60310
|
};
|
|
60311
|
-
ReadableStreamBYOBReaderRead(
|
|
60311
|
+
ReadableStreamBYOBReaderRead(reader2, view, 1, readIntoRequest);
|
|
60312
60312
|
}
|
|
60313
60313
|
function pull1Algorithm() {
|
|
60314
60314
|
if (reading) {
|
|
@@ -60363,7 +60363,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60363
60363
|
}
|
|
60364
60364
|
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
60365
60365
|
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
60366
|
-
forwardReaderError(
|
|
60366
|
+
forwardReaderError(reader2);
|
|
60367
60367
|
return [branch1, branch2];
|
|
60368
60368
|
}
|
|
60369
60369
|
function isReadableStreamLike(stream2) {
|
|
@@ -60428,13 +60428,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60428
60428
|
stream2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
|
60429
60429
|
return stream2;
|
|
60430
60430
|
}
|
|
60431
|
-
function ReadableStreamFromDefaultReader(
|
|
60431
|
+
function ReadableStreamFromDefaultReader(reader2) {
|
|
60432
60432
|
let stream2;
|
|
60433
60433
|
const startAlgorithm = noop5;
|
|
60434
60434
|
function pullAlgorithm() {
|
|
60435
60435
|
let readPromise;
|
|
60436
60436
|
try {
|
|
60437
|
-
readPromise =
|
|
60437
|
+
readPromise = reader2.read();
|
|
60438
60438
|
} catch (e2) {
|
|
60439
60439
|
return promiseRejectedWith(e2);
|
|
60440
60440
|
}
|
|
@@ -60452,7 +60452,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60452
60452
|
}
|
|
60453
60453
|
function cancelAlgorithm(reason) {
|
|
60454
60454
|
try {
|
|
60455
|
-
return promiseResolvedWith(
|
|
60455
|
+
return promiseResolvedWith(reader2.cancel(reason));
|
|
60456
60456
|
} catch (e2) {
|
|
60457
60457
|
return promiseRejectedWith(e2);
|
|
60458
60458
|
}
|
|
@@ -60740,10 +60740,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60740
60740
|
return promiseRejectedWith(stream2._storedError);
|
|
60741
60741
|
}
|
|
60742
60742
|
ReadableStreamClose(stream2);
|
|
60743
|
-
const
|
|
60744
|
-
if (
|
|
60745
|
-
const readIntoRequests =
|
|
60746
|
-
|
|
60743
|
+
const reader2 = stream2._reader;
|
|
60744
|
+
if (reader2 !== void 0 && IsReadableStreamBYOBReader(reader2)) {
|
|
60745
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
60746
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
60747
60747
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
60748
60748
|
readIntoRequest._closeSteps(void 0);
|
|
60749
60749
|
});
|
|
@@ -60753,14 +60753,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60753
60753
|
}
|
|
60754
60754
|
function ReadableStreamClose(stream2) {
|
|
60755
60755
|
stream2._state = "closed";
|
|
60756
|
-
const
|
|
60757
|
-
if (
|
|
60756
|
+
const reader2 = stream2._reader;
|
|
60757
|
+
if (reader2 === void 0) {
|
|
60758
60758
|
return;
|
|
60759
60759
|
}
|
|
60760
|
-
defaultReaderClosedPromiseResolve(
|
|
60761
|
-
if (IsReadableStreamDefaultReader(
|
|
60762
|
-
const readRequests =
|
|
60763
|
-
|
|
60760
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
60761
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60762
|
+
const readRequests = reader2._readRequests;
|
|
60763
|
+
reader2._readRequests = new SimpleQueue();
|
|
60764
60764
|
readRequests.forEach((readRequest) => {
|
|
60765
60765
|
readRequest._closeSteps();
|
|
60766
60766
|
});
|
|
@@ -60769,15 +60769,15 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60769
60769
|
function ReadableStreamError(stream2, e2) {
|
|
60770
60770
|
stream2._state = "errored";
|
|
60771
60771
|
stream2._storedError = e2;
|
|
60772
|
-
const
|
|
60773
|
-
if (
|
|
60772
|
+
const reader2 = stream2._reader;
|
|
60773
|
+
if (reader2 === void 0) {
|
|
60774
60774
|
return;
|
|
60775
60775
|
}
|
|
60776
|
-
defaultReaderClosedPromiseReject(
|
|
60777
|
-
if (IsReadableStreamDefaultReader(
|
|
60778
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
60776
|
+
defaultReaderClosedPromiseReject(reader2, e2);
|
|
60777
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60778
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e2);
|
|
60779
60779
|
} else {
|
|
60780
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
60780
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2);
|
|
60781
60781
|
}
|
|
60782
60782
|
}
|
|
60783
60783
|
function streamBrandCheckException$1(name) {
|
|
@@ -64417,7 +64417,7 @@ var require_bignumber = __commonJS({
|
|
|
64417
64417
|
}
|
|
64418
64418
|
return arr.reverse();
|
|
64419
64419
|
}
|
|
64420
|
-
return function(str2, baseIn, baseOut,
|
|
64420
|
+
return function(str2, baseIn, baseOut, sign2, callerIsToString) {
|
|
64421
64421
|
var alphabet, d, e2, k, r2, x2, xc, y, i2 = str2.indexOf("."), dp = DECIMAL_PLACES, rm2 = ROUNDING_MODE;
|
|
64422
64422
|
if (i2 >= 0) {
|
|
64423
64423
|
k = POW_PRECISION;
|
|
@@ -64443,7 +64443,7 @@ var require_bignumber = __commonJS({
|
|
|
64443
64443
|
} else {
|
|
64444
64444
|
x2.c = xc;
|
|
64445
64445
|
x2.e = e2;
|
|
64446
|
-
x2.s =
|
|
64446
|
+
x2.s = sign2;
|
|
64447
64447
|
x2 = div(x2, y, dp, rm2, baseOut);
|
|
64448
64448
|
xc = x2.c;
|
|
64449
64449
|
r2 = x2.r;
|
|
@@ -68662,7 +68662,7 @@ var require_jwa = __commonJS({
|
|
|
68662
68662
|
return thing;
|
|
68663
68663
|
}
|
|
68664
68664
|
function createHmacSigner(bits) {
|
|
68665
|
-
return function
|
|
68665
|
+
return function sign2(thing, secret) {
|
|
68666
68666
|
checkIsSecretKey(secret);
|
|
68667
68667
|
thing = normalizeInput(thing);
|
|
68668
68668
|
var hmac = crypto2.createHmac("sha" + bits, secret);
|
|
@@ -68671,25 +68671,25 @@ var require_jwa = __commonJS({
|
|
|
68671
68671
|
};
|
|
68672
68672
|
}
|
|
68673
68673
|
var bufferEqual;
|
|
68674
|
-
var
|
|
68674
|
+
var timingSafeEqual2 = "timingSafeEqual" in crypto2 ? function timingSafeEqual3(a, b) {
|
|
68675
68675
|
if (a.byteLength !== b.byteLength) {
|
|
68676
68676
|
return false;
|
|
68677
68677
|
}
|
|
68678
68678
|
return crypto2.timingSafeEqual(a, b);
|
|
68679
|
-
} : function
|
|
68679
|
+
} : function timingSafeEqual3(a, b) {
|
|
68680
68680
|
if (!bufferEqual) {
|
|
68681
68681
|
bufferEqual = require_buffer_equal_constant_time();
|
|
68682
68682
|
}
|
|
68683
68683
|
return bufferEqual(a, b);
|
|
68684
68684
|
};
|
|
68685
68685
|
function createHmacVerifier(bits) {
|
|
68686
|
-
return function
|
|
68686
|
+
return function verify2(thing, signature, secret) {
|
|
68687
68687
|
var computedSig = createHmacSigner(bits)(thing, secret);
|
|
68688
|
-
return
|
|
68688
|
+
return timingSafeEqual2(Buffer5.from(signature), Buffer5.from(computedSig));
|
|
68689
68689
|
};
|
|
68690
68690
|
}
|
|
68691
68691
|
function createKeySigner(bits) {
|
|
68692
|
-
return function
|
|
68692
|
+
return function sign2(thing, privateKey) {
|
|
68693
68693
|
checkIsPrivateKey(privateKey);
|
|
68694
68694
|
thing = normalizeInput(thing);
|
|
68695
68695
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -68698,7 +68698,7 @@ var require_jwa = __commonJS({
|
|
|
68698
68698
|
};
|
|
68699
68699
|
}
|
|
68700
68700
|
function createKeyVerifier(bits) {
|
|
68701
|
-
return function
|
|
68701
|
+
return function verify2(thing, signature, publicKey) {
|
|
68702
68702
|
checkIsPublicKey(publicKey);
|
|
68703
68703
|
thing = normalizeInput(thing);
|
|
68704
68704
|
signature = toBase64(signature);
|
|
@@ -68708,7 +68708,7 @@ var require_jwa = __commonJS({
|
|
|
68708
68708
|
};
|
|
68709
68709
|
}
|
|
68710
68710
|
function createPSSKeySigner(bits) {
|
|
68711
|
-
return function
|
|
68711
|
+
return function sign2(thing, privateKey) {
|
|
68712
68712
|
checkIsPrivateKey(privateKey);
|
|
68713
68713
|
thing = normalizeInput(thing);
|
|
68714
68714
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -68721,7 +68721,7 @@ var require_jwa = __commonJS({
|
|
|
68721
68721
|
};
|
|
68722
68722
|
}
|
|
68723
68723
|
function createPSSKeyVerifier(bits) {
|
|
68724
|
-
return function
|
|
68724
|
+
return function verify2(thing, signature, publicKey) {
|
|
68725
68725
|
checkIsPublicKey(publicKey);
|
|
68726
68726
|
thing = normalizeInput(thing);
|
|
68727
68727
|
signature = toBase64(signature);
|
|
@@ -68736,7 +68736,7 @@ var require_jwa = __commonJS({
|
|
|
68736
68736
|
}
|
|
68737
68737
|
function createECDSASigner(bits) {
|
|
68738
68738
|
var inner = createKeySigner(bits);
|
|
68739
|
-
return function
|
|
68739
|
+
return function sign2() {
|
|
68740
68740
|
var signature = inner.apply(null, arguments);
|
|
68741
68741
|
signature = formatEcdsa.derToJose(signature, "ES" + bits);
|
|
68742
68742
|
return signature;
|
|
@@ -68744,19 +68744,19 @@ var require_jwa = __commonJS({
|
|
|
68744
68744
|
}
|
|
68745
68745
|
function createECDSAVerifer(bits) {
|
|
68746
68746
|
var inner = createKeyVerifier(bits);
|
|
68747
|
-
return function
|
|
68747
|
+
return function verify2(thing, signature, publicKey) {
|
|
68748
68748
|
signature = formatEcdsa.joseToDer(signature, "ES" + bits).toString("base64");
|
|
68749
68749
|
var result = inner(thing, signature, publicKey);
|
|
68750
68750
|
return result;
|
|
68751
68751
|
};
|
|
68752
68752
|
}
|
|
68753
68753
|
function createNoneSigner() {
|
|
68754
|
-
return function
|
|
68754
|
+
return function sign2() {
|
|
68755
68755
|
return "";
|
|
68756
68756
|
};
|
|
68757
68757
|
}
|
|
68758
68758
|
function createNoneVerifier() {
|
|
68759
|
-
return function
|
|
68759
|
+
return function verify2(thing, signature) {
|
|
68760
68760
|
return signature === "";
|
|
68761
68761
|
};
|
|
68762
68762
|
}
|
|
@@ -68857,7 +68857,7 @@ var require_sign_stream = __commonJS({
|
|
|
68857
68857
|
}.bind(this));
|
|
68858
68858
|
}
|
|
68859
68859
|
util.inherits(SignStream, Stream6);
|
|
68860
|
-
SignStream.prototype.sign = function
|
|
68860
|
+
SignStream.prototype.sign = function sign2() {
|
|
68861
68861
|
try {
|
|
68862
68862
|
var signature = jwsSign({
|
|
68863
68863
|
header: this.header,
|
|
@@ -68976,7 +68976,7 @@ var require_verify_stream = __commonJS({
|
|
|
68976
68976
|
}.bind(this));
|
|
68977
68977
|
}
|
|
68978
68978
|
util.inherits(VerifyStream, Stream6);
|
|
68979
|
-
VerifyStream.prototype.verify = function
|
|
68979
|
+
VerifyStream.prototype.verify = function verify2() {
|
|
68980
68980
|
try {
|
|
68981
68981
|
var valid = jwsVerify(this.signature.buffer, this.algorithm, this.key.buffer);
|
|
68982
68982
|
var obj = jwsDecode(this.signature.buffer, this.encoding);
|
|
@@ -71333,14 +71333,14 @@ var require_awsrequestsigner = __commonJS({
|
|
|
71333
71333
|
}
|
|
71334
71334
|
};
|
|
71335
71335
|
exports.AwsRequestSigner = AwsRequestSigner;
|
|
71336
|
-
async function
|
|
71336
|
+
async function sign2(crypto2, key, msg) {
|
|
71337
71337
|
return await crypto2.signWithHmacSha256(key, msg);
|
|
71338
71338
|
}
|
|
71339
71339
|
async function getSigningKey(crypto2, key, dateStamp, region, serviceName) {
|
|
71340
|
-
const kDate = await
|
|
71341
|
-
const kRegion = await
|
|
71342
|
-
const kService = await
|
|
71343
|
-
const kSigning = await
|
|
71340
|
+
const kDate = await sign2(crypto2, `AWS4${key}`, dateStamp);
|
|
71341
|
+
const kRegion = await sign2(crypto2, kDate, region);
|
|
71342
|
+
const kService = await sign2(crypto2, kRegion, serviceName);
|
|
71343
|
+
const kSigning = await sign2(crypto2, kService, "aws4_request");
|
|
71344
71344
|
return kSigning;
|
|
71345
71345
|
}
|
|
71346
71346
|
async function generateAuthenticationHeaderMap(options) {
|
|
@@ -71384,7 +71384,7 @@ ${amzDate}
|
|
|
71384
71384
|
${credentialScope}
|
|
71385
71385
|
` + await options.crypto.sha256DigestHex(canonicalRequest);
|
|
71386
71386
|
const signingKey = await getSigningKey(options.crypto, options.securityCredentials.secretAccessKey, dateStamp, options.region, serviceName);
|
|
71387
|
-
const signature = await
|
|
71387
|
+
const signature = await sign2(options.crypto, signingKey, stringToSign);
|
|
71388
71388
|
const authorizationHeader = `${AWS_ALGORITHM} Credential=${options.securityCredentials.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${(0, crypto_1.fromArrayBufferToHex)(signature)}`;
|
|
71389
71389
|
return {
|
|
71390
71390
|
// Do not return x-amz-date if date is available.
|
|
@@ -73369,8 +73369,8 @@ var require_googleauth = __commonJS({
|
|
|
73369
73369
|
}
|
|
73370
73370
|
const crypto2 = (0, crypto_1.createCrypto)();
|
|
73371
73371
|
if (client instanceof jwtclient_1.JWT && client.key) {
|
|
73372
|
-
const
|
|
73373
|
-
return
|
|
73372
|
+
const sign2 = await crypto2.sign(client.key, data);
|
|
73373
|
+
return sign2;
|
|
73374
73374
|
}
|
|
73375
73375
|
const creds = await this.getCredentials();
|
|
73376
73376
|
if (!creds.client_email) {
|
|
@@ -76053,7 +76053,7 @@ var require_websocket = __commonJS({
|
|
|
76053
76053
|
var http3 = __require("http");
|
|
76054
76054
|
var net = __require("net");
|
|
76055
76055
|
var tls = __require("tls");
|
|
76056
|
-
var { randomBytes, createHash: createHash16 } = __require("crypto");
|
|
76056
|
+
var { randomBytes: randomBytes2, createHash: createHash16 } = __require("crypto");
|
|
76057
76057
|
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
76058
76058
|
var { URL: URL2 } = __require("url");
|
|
76059
76059
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -76591,7 +76591,7 @@ var require_websocket = __commonJS({
|
|
|
76591
76591
|
}
|
|
76592
76592
|
}
|
|
76593
76593
|
const defaultPort = isSecure ? 443 : 80;
|
|
76594
|
-
const key =
|
|
76594
|
+
const key = randomBytes2(16).toString("base64");
|
|
76595
76595
|
const request = isSecure ? https2.request : http3.request;
|
|
76596
76596
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
76597
76597
|
let perMessageDeflate;
|
|
@@ -86902,22 +86902,22 @@ function ReadableStreamFrom3(iterable) {
|
|
|
86902
86902
|
function ReadableStreamToAsyncIterable3(stream2) {
|
|
86903
86903
|
if (stream2[Symbol.asyncIterator])
|
|
86904
86904
|
return stream2;
|
|
86905
|
-
const
|
|
86905
|
+
const reader2 = stream2.getReader();
|
|
86906
86906
|
return {
|
|
86907
86907
|
async next() {
|
|
86908
86908
|
try {
|
|
86909
|
-
const result = await
|
|
86909
|
+
const result = await reader2.read();
|
|
86910
86910
|
if (result === null || result === void 0 ? void 0 : result.done)
|
|
86911
|
-
|
|
86911
|
+
reader2.releaseLock();
|
|
86912
86912
|
return result;
|
|
86913
86913
|
} catch (e2) {
|
|
86914
|
-
|
|
86914
|
+
reader2.releaseLock();
|
|
86915
86915
|
throw e2;
|
|
86916
86916
|
}
|
|
86917
86917
|
},
|
|
86918
86918
|
async return() {
|
|
86919
|
-
const cancelPromise =
|
|
86920
|
-
|
|
86919
|
+
const cancelPromise = reader2.cancel();
|
|
86920
|
+
reader2.releaseLock();
|
|
86921
86921
|
await cancelPromise;
|
|
86922
86922
|
return { done: true, value: void 0 };
|
|
86923
86923
|
},
|
|
@@ -86934,9 +86934,9 @@ async function CancelReadableStream3(stream2) {
|
|
|
86934
86934
|
await ((_b = (_a5 = stream2[Symbol.asyncIterator]()).return) === null || _b === void 0 ? void 0 : _b.call(_a5));
|
|
86935
86935
|
return;
|
|
86936
86936
|
}
|
|
86937
|
-
const
|
|
86938
|
-
const cancelPromise =
|
|
86939
|
-
|
|
86937
|
+
const reader2 = stream2.getReader();
|
|
86938
|
+
const cancelPromise = reader2.cancel();
|
|
86939
|
+
reader2.releaseLock();
|
|
86940
86940
|
await cancelPromise;
|
|
86941
86941
|
}
|
|
86942
86942
|
function stringifyQuery3(query) {
|
|
@@ -90810,9 +90810,9 @@ var init_node = __esm({
|
|
|
90810
90810
|
processStreamResponse(response) {
|
|
90811
90811
|
return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
|
|
90812
90812
|
var _a5;
|
|
90813
|
-
const
|
|
90813
|
+
const reader2 = (_a5 = response === null || response === void 0 ? void 0 : response.body) === null || _a5 === void 0 ? void 0 : _a5.getReader();
|
|
90814
90814
|
const decoder = new TextDecoder("utf-8");
|
|
90815
|
-
if (!
|
|
90815
|
+
if (!reader2) {
|
|
90816
90816
|
throw new Error("Response body is empty");
|
|
90817
90817
|
}
|
|
90818
90818
|
try {
|
|
@@ -90820,7 +90820,7 @@ var init_node = __esm({
|
|
|
90820
90820
|
const dataPrefix = "data:";
|
|
90821
90821
|
const delimiters = ["\n\n", "\r\r", "\r\n\r\n"];
|
|
90822
90822
|
while (true) {
|
|
90823
|
-
const { done, value } = yield __await(
|
|
90823
|
+
const { done, value } = yield __await(reader2.read());
|
|
90824
90824
|
if (done) {
|
|
90825
90825
|
if (buffer.trim().length > 0) {
|
|
90826
90826
|
throw new Error("Incomplete JSON segment at the end");
|
|
@@ -90884,7 +90884,7 @@ var init_node = __esm({
|
|
|
90884
90884
|
}
|
|
90885
90885
|
}
|
|
90886
90886
|
} finally {
|
|
90887
|
-
|
|
90887
|
+
reader2.releaseLock();
|
|
90888
90888
|
}
|
|
90889
90889
|
});
|
|
90890
90890
|
}
|
|
@@ -96592,12 +96592,12 @@ var init_config3 = __esm({
|
|
|
96592
96592
|
|
|
96593
96593
|
// node_modules/@mistralai/mistralai/esm/lib/files.js
|
|
96594
96594
|
async function readableStreamToArrayBuffer(readable) {
|
|
96595
|
-
const
|
|
96595
|
+
const reader2 = readable.getReader();
|
|
96596
96596
|
const chunks = [];
|
|
96597
96597
|
let totalLength = 0;
|
|
96598
96598
|
let done = false;
|
|
96599
96599
|
while (!done) {
|
|
96600
|
-
const { value, done: doneReading } = await
|
|
96600
|
+
const { value, done: doneReading } = await reader2.read();
|
|
96601
96601
|
if (doneReading) {
|
|
96602
96602
|
done = true;
|
|
96603
96603
|
} else {
|
|
@@ -111681,24 +111681,24 @@ var init_event_streams = __esm({
|
|
|
111681
111681
|
const fn = ReadableStream.prototype[Symbol.asyncIterator];
|
|
111682
111682
|
if (typeof fn === "function")
|
|
111683
111683
|
return fn.call(this);
|
|
111684
|
-
const
|
|
111684
|
+
const reader2 = this.getReader();
|
|
111685
111685
|
return {
|
|
111686
111686
|
next: async () => {
|
|
111687
|
-
const r2 = await
|
|
111687
|
+
const r2 = await reader2.read();
|
|
111688
111688
|
if (r2.done) {
|
|
111689
|
-
|
|
111689
|
+
reader2.releaseLock();
|
|
111690
111690
|
return { done: true, value: void 0 };
|
|
111691
111691
|
}
|
|
111692
111692
|
return { done: false, value: r2.value };
|
|
111693
111693
|
},
|
|
111694
111694
|
throw: async (e2) => {
|
|
111695
|
-
await
|
|
111696
|
-
|
|
111695
|
+
await reader2.cancel(e2);
|
|
111696
|
+
reader2.releaseLock();
|
|
111697
111697
|
return { done: true, value: void 0 };
|
|
111698
111698
|
},
|
|
111699
111699
|
return: async () => {
|
|
111700
|
-
await
|
|
111701
|
-
|
|
111700
|
+
await reader2.cancel("done");
|
|
111701
|
+
reader2.releaseLock();
|
|
111702
111702
|
return { done: true, value: void 0 };
|
|
111703
111703
|
},
|
|
111704
111704
|
[Symbol.asyncIterator]() {
|
|
@@ -135220,11 +135220,11 @@ function normalizeCodexStatus(status) {
|
|
|
135220
135220
|
async function* parseSSE(response, signal) {
|
|
135221
135221
|
if (!response.body)
|
|
135222
135222
|
return;
|
|
135223
|
-
const
|
|
135223
|
+
const reader2 = response.body.getReader();
|
|
135224
135224
|
const decoder = new TextDecoder();
|
|
135225
135225
|
let buffer = "";
|
|
135226
135226
|
const onAbort = () => {
|
|
135227
|
-
void
|
|
135227
|
+
void reader2.cancel().catch(() => {
|
|
135228
135228
|
});
|
|
135229
135229
|
};
|
|
135230
135230
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -135233,7 +135233,7 @@ async function* parseSSE(response, signal) {
|
|
|
135233
135233
|
if (signal?.aborted) {
|
|
135234
135234
|
throw new Error("Request was aborted");
|
|
135235
135235
|
}
|
|
135236
|
-
const { done, value } = await
|
|
135236
|
+
const { done, value } = await reader2.read();
|
|
135237
135237
|
if (signal?.aborted) {
|
|
135238
135238
|
throw new Error("Request was aborted");
|
|
135239
135239
|
}
|
|
@@ -135264,11 +135264,11 @@ async function* parseSSE(response, signal) {
|
|
|
135264
135264
|
} finally {
|
|
135265
135265
|
signal?.removeEventListener("abort", onAbort);
|
|
135266
135266
|
try {
|
|
135267
|
-
await
|
|
135267
|
+
await reader2.cancel();
|
|
135268
135268
|
} catch {
|
|
135269
135269
|
}
|
|
135270
135270
|
try {
|
|
135271
|
-
|
|
135271
|
+
reader2.releaseLock();
|
|
135272
135272
|
} catch {
|
|
135273
135273
|
}
|
|
135274
135274
|
}
|
|
@@ -144031,12 +144031,12 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
144031
144031
|
throw new Error(`Provider media download exceeds the ${maxBytes}-byte limit`);
|
|
144032
144032
|
}
|
|
144033
144033
|
if (!response.body) throw new Error("Provider media download returned an empty response");
|
|
144034
|
-
const
|
|
144034
|
+
const reader2 = response.body.getReader();
|
|
144035
144035
|
const chunks = [];
|
|
144036
144036
|
let total = 0;
|
|
144037
144037
|
try {
|
|
144038
144038
|
while (true) {
|
|
144039
|
-
const { done, value } = await
|
|
144039
|
+
const { done, value } = await reader2.read();
|
|
144040
144040
|
if (done) break;
|
|
144041
144041
|
if (!value) continue;
|
|
144042
144042
|
total += value.byteLength;
|
|
@@ -144044,7 +144044,7 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
144044
144044
|
chunks.push(value);
|
|
144045
144045
|
}
|
|
144046
144046
|
} finally {
|
|
144047
|
-
|
|
144047
|
+
reader2.releaseLock();
|
|
144048
144048
|
}
|
|
144049
144049
|
if (total === 0) throw new Error("Provider media download returned an empty response");
|
|
144050
144050
|
return Buffer.concat(chunks);
|
|
@@ -144893,7 +144893,7 @@ async function archiveExpiredBatch(_projectDir, options) {
|
|
|
144893
144893
|
const nextCursor = hasMore && scanned.length > 0 ? scanned[scanned.length - 1].id : void 0;
|
|
144894
144894
|
return nextCursor === void 0 ? { archived, scanned: scanned.length } : { archived, scanned: scanned.length, nextCursor };
|
|
144895
144895
|
}
|
|
144896
|
-
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
144896
|
+
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId, reader2) {
|
|
144897
144897
|
const store = getObservationStore();
|
|
144898
144898
|
if (projectId) {
|
|
144899
144899
|
let afterId;
|
|
@@ -144904,13 +144904,13 @@ async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
|
144904
144904
|
afterId,
|
|
144905
144905
|
referenceTime,
|
|
144906
144906
|
accessMap,
|
|
144907
|
-
reader
|
|
144907
|
+
reader: reader2
|
|
144908
144908
|
});
|
|
144909
144909
|
archived += batch.archived;
|
|
144910
144910
|
afterId = batch.nextCursor;
|
|
144911
144911
|
} while (afterId !== void 0);
|
|
144912
144912
|
const remainingObservations = await store.loadByProject(projectId, { status: "active" });
|
|
144913
|
-
const remaining =
|
|
144913
|
+
const remaining = reader2 ? remainingObservations.filter((observation) => canManageObservation(observation, reader2)).length : remainingObservations.length;
|
|
144914
144914
|
return { archived, remaining };
|
|
144915
144915
|
}
|
|
144916
144916
|
return await store.atomic(async (tx) => {
|
|
@@ -145366,21 +145366,21 @@ function assertPortableEvidence(scope, portability, evidence) {
|
|
|
145366
145366
|
throw new Error("Portable user memory may only use manual or user-confirmed evidence; project code, Git, observation, test, session, claim, and workflow evidence must remain project-bound.");
|
|
145367
145367
|
}
|
|
145368
145368
|
}
|
|
145369
|
-
function requireTeamReader(scope,
|
|
145370
|
-
if (scope === "team" &&
|
|
145369
|
+
function requireTeamReader(scope, reader2) {
|
|
145370
|
+
if (scope === "team" && reader2?.isTeamMember !== true) {
|
|
145371
145371
|
throw new Error("Team long-term memory requires an explicit active team identity for this project.");
|
|
145372
145372
|
}
|
|
145373
145373
|
}
|
|
145374
|
-
function matchesScope(memory,
|
|
145375
|
-
if (memory.scope === "project") return memory.originProjectId ===
|
|
145374
|
+
function matchesScope(memory, reader2) {
|
|
145375
|
+
if (memory.scope === "project") return memory.originProjectId === reader2.projectId;
|
|
145376
145376
|
if (memory.scope === "team") {
|
|
145377
|
-
return memory.originProjectId ===
|
|
145377
|
+
return memory.originProjectId === reader2.projectId && reader2.isTeamMember === true;
|
|
145378
145378
|
}
|
|
145379
|
-
if (!
|
|
145380
|
-
return memory.portability === "portable" || memory.originProjectId ===
|
|
145379
|
+
if (!reader2.ownerId || memory.ownerId !== reader2.ownerId) return false;
|
|
145380
|
+
return memory.portability === "portable" || memory.originProjectId === reader2.projectId;
|
|
145381
145381
|
}
|
|
145382
|
-
function canReadLongTermMemory(memory,
|
|
145383
|
-
return matchesScope(memory,
|
|
145382
|
+
function canReadLongTermMemory(memory, reader2) {
|
|
145383
|
+
return matchesScope(memory, reader2);
|
|
145384
145384
|
}
|
|
145385
145385
|
function isEligibleLongTermMemory(memory) {
|
|
145386
145386
|
return memory.state === "qualified" || memory.state === "approved";
|
|
@@ -145766,14 +145766,14 @@ async function selectLongTermMemoriesForTask(input) {
|
|
|
145766
145766
|
const task = input.task?.trim();
|
|
145767
145767
|
if (!task) return [];
|
|
145768
145768
|
const owner = await resolveLocalMemoryOwner(input.dataDir, { create: false });
|
|
145769
|
-
const
|
|
145769
|
+
const reader2 = {
|
|
145770
145770
|
projectId: input.projectId,
|
|
145771
145771
|
...owner ? { ownerId: owner.id } : {},
|
|
145772
145772
|
...input.agentId ? { agentId: input.agentId } : {},
|
|
145773
145773
|
...input.isTeamMember ? { isTeamMember: true } : {}
|
|
145774
145774
|
};
|
|
145775
145775
|
const store = await createStore(input.dataDir);
|
|
145776
|
-
const eligible = store.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory,
|
|
145776
|
+
const eligible = store.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory, reader2));
|
|
145777
145777
|
let selected = eligible.map((memory) => {
|
|
145778
145778
|
const ranked = scoreForTask(memory, task);
|
|
145779
145779
|
return ranked ? {
|
|
@@ -152637,8 +152637,8 @@ This project does have stored Memorix memories, but none matched the current que
|
|
|
152637
152637
|
const totalTokens = countTextTokens(formatted);
|
|
152638
152638
|
return { entries, formatted, totalTokens };
|
|
152639
152639
|
}
|
|
152640
|
-
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
152641
|
-
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter,
|
|
152640
|
+
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2, surface = "mcp") {
|
|
152641
|
+
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter, reader2);
|
|
152642
152642
|
const timeline = {
|
|
152643
152643
|
anchorId,
|
|
152644
152644
|
anchorEntry: result.anchor,
|
|
@@ -152987,7 +152987,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
152987
152987
|
const lowEvidence = active.filter((obs) => evidenceScore(obs) <= 2).map((obs) => makeEntry(obs, `Low evidence score (${evidenceScore(obs)}/5)`));
|
|
152988
152988
|
const hookNoise = active.filter((obs) => isHookNoise(obs) || isCommandLog(obs)).map((obs) => makeEntry(obs, isCommandLog(obs) ? "Command log noise" : "Hook-generated noise"));
|
|
152989
152989
|
const orphans = active.filter((obs) => isOrphan(obs)).map((obs) => makeEntry(obs, "Weakly connected or isolated memory"));
|
|
152990
|
-
const
|
|
152990
|
+
const retentionCandidates2 = active.filter((obs) => getRetentionZone({
|
|
152991
152991
|
id: `obs-${obs.id}`,
|
|
152992
152992
|
observationId: obs.id,
|
|
152993
152993
|
entityName: obs.entityName,
|
|
@@ -153027,7 +153027,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
153027
153027
|
if (orphans.length > 0) {
|
|
153028
153028
|
recommendations.push("Promote or attach isolated memories only if they have clear evidence value.");
|
|
153029
153029
|
}
|
|
153030
|
-
if (
|
|
153030
|
+
if (retentionCandidates2.length > 0) {
|
|
153031
153031
|
recommendations.push("Run `memorix retention stale` or `memorix retention archive` to inspect aged memories.");
|
|
153032
153032
|
}
|
|
153033
153033
|
if (recommendations.length === 0) {
|
|
@@ -153041,7 +153041,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
153041
153041
|
lowEvidence,
|
|
153042
153042
|
hookNoise,
|
|
153043
153043
|
orphans,
|
|
153044
|
-
retentionCandidates
|
|
153044
|
+
retentionCandidates: retentionCandidates2
|
|
153045
153045
|
},
|
|
153046
153046
|
recommendations
|
|
153047
153047
|
};
|
|
@@ -156033,6 +156033,125 @@ var init_tool_profile = __esm({
|
|
|
156033
156033
|
}
|
|
156034
156034
|
});
|
|
156035
156035
|
|
|
156036
|
+
// src/memory/deduplication.ts
|
|
156037
|
+
function chronological(left, right) {
|
|
156038
|
+
const byTime = new Date(left.createdAt).getTime() - new Date(right.createdAt).getTime();
|
|
156039
|
+
return byTime || left.id - right.id;
|
|
156040
|
+
}
|
|
156041
|
+
function actionFromDecision(older, newer, decision) {
|
|
156042
|
+
let resolveId;
|
|
156043
|
+
let keepId;
|
|
156044
|
+
if (decision.action === "NONE") {
|
|
156045
|
+
resolveId = newer.id;
|
|
156046
|
+
keepId = older.id;
|
|
156047
|
+
} else if (decision.action === "UPDATE") {
|
|
156048
|
+
resolveId = decision.targetId ?? older.id;
|
|
156049
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
156050
|
+
} else if (decision.action === "DELETE") {
|
|
156051
|
+
resolveId = decision.targetId ?? older.id;
|
|
156052
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
156053
|
+
} else {
|
|
156054
|
+
return null;
|
|
156055
|
+
}
|
|
156056
|
+
const records = /* @__PURE__ */ new Map([[older.id, older], [newer.id, newer]]);
|
|
156057
|
+
const resolved = records.get(resolveId);
|
|
156058
|
+
const kept = records.get(keepId);
|
|
156059
|
+
if (!resolved || !kept || resolved.id === kept.id) return null;
|
|
156060
|
+
return {
|
|
156061
|
+
resolveId,
|
|
156062
|
+
keepId,
|
|
156063
|
+
entityName: newer.entityName,
|
|
156064
|
+
resolveTitle: resolved.title,
|
|
156065
|
+
keepTitle: kept.title,
|
|
156066
|
+
reason: decision.reason,
|
|
156067
|
+
decision: decision.action,
|
|
156068
|
+
usedLLM: decision.usedLLM
|
|
156069
|
+
};
|
|
156070
|
+
}
|
|
156071
|
+
async function planMemoryDeduplication(observations2, options = {}) {
|
|
156072
|
+
const limit2 = Math.min(100, Math.max(2, Math.floor(options.limit ?? 20)));
|
|
156073
|
+
const candidates = observations2.filter((observation) => (observation.status ?? "active") === "active").sort(chronological).slice(-limit2);
|
|
156074
|
+
const byEntity = /* @__PURE__ */ new Map();
|
|
156075
|
+
for (const observation of candidates) {
|
|
156076
|
+
const group = byEntity.get(observation.entityName) ?? [];
|
|
156077
|
+
group.push(observation);
|
|
156078
|
+
byEntity.set(observation.entityName, group);
|
|
156079
|
+
}
|
|
156080
|
+
const decide = options.decide ?? deduplicateMemory;
|
|
156081
|
+
const actions = /* @__PURE__ */ new Map();
|
|
156082
|
+
let comparisons = 0;
|
|
156083
|
+
let failedComparisons = 0;
|
|
156084
|
+
for (const group of byEntity.values()) {
|
|
156085
|
+
if (group.length < 2) continue;
|
|
156086
|
+
group.sort(chronological);
|
|
156087
|
+
for (let index = 0; index < group.length; index += 1) {
|
|
156088
|
+
for (let compareIndex = index + 1; compareIndex < group.length; compareIndex += 1) {
|
|
156089
|
+
const older = group[index];
|
|
156090
|
+
const newer = group[compareIndex];
|
|
156091
|
+
comparisons += 1;
|
|
156092
|
+
let decision;
|
|
156093
|
+
try {
|
|
156094
|
+
decision = await decide(
|
|
156095
|
+
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
156096
|
+
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
156097
|
+
);
|
|
156098
|
+
} catch {
|
|
156099
|
+
failedComparisons += 1;
|
|
156100
|
+
continue;
|
|
156101
|
+
}
|
|
156102
|
+
if (!decision) continue;
|
|
156103
|
+
const action = actionFromDecision(older, newer, decision);
|
|
156104
|
+
if (action && !actions.has(action.resolveId)) actions.set(action.resolveId, action);
|
|
156105
|
+
}
|
|
156106
|
+
}
|
|
156107
|
+
}
|
|
156108
|
+
const planned = [...actions.values()];
|
|
156109
|
+
for (const [entityName, group] of byEntity) {
|
|
156110
|
+
const resolvedIds = new Set(
|
|
156111
|
+
planned.filter((action) => action.entityName === entityName).map((action) => action.resolveId)
|
|
156112
|
+
);
|
|
156113
|
+
if (group.length > 0 && group.every((observation) => resolvedIds.has(observation.id))) {
|
|
156114
|
+
const survivor = group[group.length - 1];
|
|
156115
|
+
const unsafeIndex = planned.findIndex((action) => action.resolveId === survivor.id);
|
|
156116
|
+
if (unsafeIndex >= 0) planned.splice(unsafeIndex, 1);
|
|
156117
|
+
}
|
|
156118
|
+
}
|
|
156119
|
+
return {
|
|
156120
|
+
scanned: candidates.length,
|
|
156121
|
+
entities: byEntity.size,
|
|
156122
|
+
comparisons,
|
|
156123
|
+
failedComparisons,
|
|
156124
|
+
actions: planned,
|
|
156125
|
+
resolveIds: planned.map((action) => action.resolveId)
|
|
156126
|
+
};
|
|
156127
|
+
}
|
|
156128
|
+
async function applyDeduplicationPlan(store, projectId, resolveIds, reader2 = { projectId }) {
|
|
156129
|
+
const uniqueIds = [...new Set(resolveIds)];
|
|
156130
|
+
const manageable = [];
|
|
156131
|
+
const skipped = [];
|
|
156132
|
+
for (const id of uniqueIds) {
|
|
156133
|
+
const observation = await store.getById(id);
|
|
156134
|
+
if (observation && observation.projectId === projectId && (observation.status ?? "active") === "active" && canManageObservation(observation, reader2)) {
|
|
156135
|
+
manageable.push(id);
|
|
156136
|
+
} else {
|
|
156137
|
+
skipped.push(id);
|
|
156138
|
+
}
|
|
156139
|
+
}
|
|
156140
|
+
const resolved = skipped.length > 0 || manageable.length === 0 ? [] : await store.atomic(async (tx) => {
|
|
156141
|
+
const updates = await Promise.all(manageable.map((id) => tx.setStatus(id, "resolved", "active")));
|
|
156142
|
+
return manageable.filter((_, index) => updates[index]);
|
|
156143
|
+
});
|
|
156144
|
+
return { resolved, skipped };
|
|
156145
|
+
}
|
|
156146
|
+
var init_deduplication = __esm({
|
|
156147
|
+
"src/memory/deduplication.ts"() {
|
|
156148
|
+
"use strict";
|
|
156149
|
+
init_esm_shims();
|
|
156150
|
+
init_memory_manager();
|
|
156151
|
+
init_visibility();
|
|
156152
|
+
}
|
|
156153
|
+
});
|
|
156154
|
+
|
|
156036
156155
|
// src/memory/formation/extract.ts
|
|
156037
156156
|
function extractFacts2(narrative, existingFacts) {
|
|
156038
156157
|
const existingLower = new Set(existingFacts.map((f3) => f3.toLowerCase().trim()));
|
|
@@ -157291,14 +157410,14 @@ function isSystemSelfObservation(obs) {
|
|
|
157291
157410
|
const text2 = stringifyObservation(obs, false);
|
|
157292
157411
|
return SYSTEM_SELF_PATTERNS.some((pattern) => pattern.test(text2));
|
|
157293
157412
|
}
|
|
157294
|
-
function readerForAlias(
|
|
157295
|
-
if (!
|
|
157296
|
-
return
|
|
157413
|
+
function readerForAlias(reader2, aliases, observation) {
|
|
157414
|
+
if (!reader2) return void 0;
|
|
157415
|
+
return reader2.projectId && aliases.has(observation.projectId) ? { ...reader2, projectId: observation.projectId } : reader2;
|
|
157297
157416
|
}
|
|
157298
|
-
function readableAliasObservations(observations2, aliases,
|
|
157299
|
-
return
|
|
157417
|
+
function readableAliasObservations(observations2, aliases, reader2) {
|
|
157418
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(
|
|
157300
157419
|
observation,
|
|
157301
|
-
readerForAlias(
|
|
157420
|
+
readerForAlias(reader2, aliases, observation)
|
|
157302
157421
|
)) : observations2;
|
|
157303
157422
|
}
|
|
157304
157423
|
function isUsefulSessionSummary(summary) {
|
|
@@ -157317,13 +157436,13 @@ function continuationScore(observation, projectTokens, task) {
|
|
|
157317
157436
|
score += Math.min(matches, 2) * 2;
|
|
157318
157437
|
return score;
|
|
157319
157438
|
}
|
|
157320
|
-
async function getSessionResumeBrief(projectId, task,
|
|
157439
|
+
async function getSessionResumeBrief(projectId, task, reader2) {
|
|
157321
157440
|
const aliasSet = await resolveProjectIds(projectId);
|
|
157322
157441
|
const [sessions, allObs] = await Promise.all([
|
|
157323
157442
|
loadAliasSessions(aliasSet),
|
|
157324
157443
|
loadAliasActiveObservations(aliasSet)
|
|
157325
157444
|
]);
|
|
157326
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
157445
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
157327
157446
|
const previous = sessions.filter((session) => session.status === "completed").sort((a, b) => new Date(b.endedAt || b.startedAt).getTime() - new Date(a.endedAt || a.startedAt).getTime()).find((session) => session.summary && session.summary !== "(session ended implicitly by new session start)" && isUsefulSessionSummary(session.summary));
|
|
157328
157447
|
const projectTokens = tokenizeProjectId(projectId);
|
|
157329
157448
|
const memories = readableObs.filter((observation) => RESUME_TYPES.has(observation.type)).filter((observation) => classifyLayer(observation) === "L2").filter((observation) => !isNoiseObservation(observation) && !isSystemSelfObservation(observation)).map((observation) => ({
|
|
@@ -157434,13 +157553,13 @@ async function endSession(projectDir2, sessionId, summary) {
|
|
|
157434
157553
|
await sessionStore.update(session);
|
|
157435
157554
|
return session;
|
|
157436
157555
|
}
|
|
157437
|
-
async function getSessionContext(projectDir2, projectId, limit2 = 3,
|
|
157556
|
+
async function getSessionContext(projectDir2, projectId, limit2 = 3, reader2) {
|
|
157438
157557
|
const aliasSet = await resolveProjectIds(projectId);
|
|
157439
157558
|
const [sessions, allObs] = await Promise.all([
|
|
157440
157559
|
loadAliasSessions(aliasSet),
|
|
157441
157560
|
loadAliasActiveObservations(aliasSet, SESSION_CONTEXT_OBSERVATION_LIMIT)
|
|
157442
157561
|
]);
|
|
157443
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
157562
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
157444
157563
|
const isNoisySummary = (summary) => {
|
|
157445
157564
|
if (!summary) return false;
|
|
157446
157565
|
return NOISE_PATTERNS2.some((p) => p.test(summary)) || SYSTEM_SELF_PATTERNS.some((p) => p.test(summary));
|
|
@@ -157477,7 +157596,7 @@ async function getSessionContext(projectDir2, projectId, limit2 = 3, reader) {
|
|
|
157477
157596
|
const hasL1Content = l1HookObs.length > 0 || l3GitCount > 0;
|
|
157478
157597
|
if (hasL1Content) {
|
|
157479
157598
|
let graphNeighbors = [];
|
|
157480
|
-
if (!
|
|
157599
|
+
if (!reader2 && activeEntities.length > 0) {
|
|
157481
157600
|
try {
|
|
157482
157601
|
const graphMgr = new KnowledgeGraphManager(projectDir2);
|
|
157483
157602
|
await graphMgr.init();
|
|
@@ -161985,13 +162104,13 @@ __export(export_import_exports, {
|
|
|
161985
162104
|
exportAsMarkdown: () => exportAsMarkdown,
|
|
161986
162105
|
importFromJson: () => importFromJson
|
|
161987
162106
|
});
|
|
161988
|
-
async function exportAsJson(projectDir2, projectId,
|
|
162107
|
+
async function exportAsJson(projectDir2, projectId, reader2) {
|
|
161989
162108
|
const store = getObservationStore();
|
|
161990
162109
|
const allObs = await store.loadAll();
|
|
161991
162110
|
const allSessions = await getSessionStore().loadAll();
|
|
161992
162111
|
const projectObs = filterReadableObservations(
|
|
161993
162112
|
allObs.filter((o) => o.projectId === projectId),
|
|
161994
|
-
|
|
162113
|
+
reader2
|
|
161995
162114
|
);
|
|
161996
162115
|
const projectSessions = allSessions.filter((s2) => s2.projectId === projectId);
|
|
161997
162116
|
const typeBreakdown = {};
|
|
@@ -162011,8 +162130,8 @@ async function exportAsJson(projectDir2, projectId, reader) {
|
|
|
162011
162130
|
}
|
|
162012
162131
|
};
|
|
162013
162132
|
}
|
|
162014
|
-
async function exportAsMarkdown(projectDir2, projectId,
|
|
162015
|
-
const data = await exportAsJson(projectDir2, projectId,
|
|
162133
|
+
async function exportAsMarkdown(projectDir2, projectId, reader2) {
|
|
162134
|
+
const data = await exportAsJson(projectDir2, projectId, reader2);
|
|
162016
162135
|
const lines = [];
|
|
162017
162136
|
lines.push(`# Memorix Export: ${projectId}`);
|
|
162018
162137
|
lines.push(`Exported: ${data.exportedAt}`);
|
|
@@ -162131,6 +162250,350 @@ var init_export_import = __esm({
|
|
|
162131
162250
|
}
|
|
162132
162251
|
});
|
|
162133
162252
|
|
|
162253
|
+
// src/memory/cleanup.ts
|
|
162254
|
+
function isLowQualityObservation(title) {
|
|
162255
|
+
return LOW_QUALITY_PATTERNS.some((pattern) => pattern.test(title.trim()));
|
|
162256
|
+
}
|
|
162257
|
+
function classifyNoiseObservation(observation) {
|
|
162258
|
+
const title = observation.title?.trim() ?? "";
|
|
162259
|
+
const entityName = observation.entityName?.trim().toLowerCase() ?? "";
|
|
162260
|
+
const concepts = (observation.concepts ?? []).map((concept) => concept.trim().toLowerCase());
|
|
162261
|
+
if (entityName === "memorix.demo" || entityName.startsWith("for_memmcp_test") || concepts.some((concept) => EXPLICIT_NOISE_MARKERS.has(concept))) {
|
|
162262
|
+
return { isNoise: true, reason: "system-self" };
|
|
162263
|
+
}
|
|
162264
|
+
if (EXPLICIT_NOISE_TITLE_PATTERNS.some((pattern) => pattern.test(title))) {
|
|
162265
|
+
return { isNoise: true, reason: "demo/test/noise" };
|
|
162266
|
+
}
|
|
162267
|
+
return { isNoise: false };
|
|
162268
|
+
}
|
|
162269
|
+
function analyzeCleanupObservations(observations2, options = {}) {
|
|
162270
|
+
const active = observations2.filter((observation) => (observation.status ?? "active") === "active");
|
|
162271
|
+
const lowQuality = active.filter((observation) => isLowQualityObservation(observation.title ?? ""));
|
|
162272
|
+
const lowQualityIds = new Set(lowQuality.map((observation) => observation.id));
|
|
162273
|
+
const highQuality = active.filter((observation) => !lowQualityIds.has(observation.id));
|
|
162274
|
+
const groups = /* @__PURE__ */ new Map();
|
|
162275
|
+
for (const observation of highQuality) {
|
|
162276
|
+
const key = `${observation.type}|${observation.title}|${observation.entityName}`;
|
|
162277
|
+
const existing = groups.get(key);
|
|
162278
|
+
if (existing) existing.duplicates.push(observation);
|
|
162279
|
+
else groups.set(key, { canonical: observation, duplicates: [] });
|
|
162280
|
+
}
|
|
162281
|
+
const duplicateGroups = [...groups.values()].filter((group) => group.duplicates.length > 0);
|
|
162282
|
+
const duplicates = duplicateGroups.flatMap((group) => group.duplicates);
|
|
162283
|
+
const excludedIds = new Set([...lowQuality, ...duplicates].map((observation) => observation.id));
|
|
162284
|
+
const noise = [];
|
|
162285
|
+
if (options.includeNoise) {
|
|
162286
|
+
for (const observation of active) {
|
|
162287
|
+
if (excludedIds.has(observation.id)) continue;
|
|
162288
|
+
const classification = classifyNoiseObservation(observation);
|
|
162289
|
+
if (classification.isNoise && classification.reason) {
|
|
162290
|
+
noise.push({ observation, reason: classification.reason });
|
|
162291
|
+
}
|
|
162292
|
+
}
|
|
162293
|
+
}
|
|
162294
|
+
const toRemove = [...lowQuality, ...duplicates];
|
|
162295
|
+
const toArchive = noise.map((hit) => hit.observation);
|
|
162296
|
+
return {
|
|
162297
|
+
totalActive: active.length,
|
|
162298
|
+
highQuality: highQuality.length - duplicates.length - toArchive.length,
|
|
162299
|
+
lowQuality,
|
|
162300
|
+
duplicateGroups,
|
|
162301
|
+
duplicates,
|
|
162302
|
+
noise,
|
|
162303
|
+
toRemove,
|
|
162304
|
+
toArchive
|
|
162305
|
+
};
|
|
162306
|
+
}
|
|
162307
|
+
function requireObservationIds(observations2, action) {
|
|
162308
|
+
const ids = observations2.map((observation) => observation.id);
|
|
162309
|
+
if (ids.some((id) => typeof id !== "number")) {
|
|
162310
|
+
throw new Error(`Cannot ${action}: an observation has no persisted ID.`);
|
|
162311
|
+
}
|
|
162312
|
+
return ids;
|
|
162313
|
+
}
|
|
162314
|
+
async function applyCleanupMutations(store, toArchive, toRemove) {
|
|
162315
|
+
const archiveIds = requireObservationIds(toArchive, "archive");
|
|
162316
|
+
const removeIds = requireObservationIds(toRemove, "delete");
|
|
162317
|
+
const removals = new Set(removeIds);
|
|
162318
|
+
if (archiveIds.some((id) => removals.has(id))) {
|
|
162319
|
+
throw new Error("Cleanup cannot archive and delete the same observation.");
|
|
162320
|
+
}
|
|
162321
|
+
await store.atomic(async (tx) => {
|
|
162322
|
+
await Promise.all(archiveIds.map((id) => tx.setStatus(id, "archived", "active")));
|
|
162323
|
+
await Promise.all(removeIds.map((id) => tx.remove(id)));
|
|
162324
|
+
});
|
|
162325
|
+
return { archived: archiveIds.length, removed: removeIds.length };
|
|
162326
|
+
}
|
|
162327
|
+
var LOW_QUALITY_PATTERNS, EXPLICIT_NOISE_TITLE_PATTERNS, EXPLICIT_NOISE_MARKERS;
|
|
162328
|
+
var init_cleanup = __esm({
|
|
162329
|
+
"src/memory/cleanup.ts"() {
|
|
162330
|
+
"use strict";
|
|
162331
|
+
init_esm_shims();
|
|
162332
|
+
LOW_QUALITY_PATTERNS = [
|
|
162333
|
+
/^Session activity/i,
|
|
162334
|
+
/^Updated \S+\.\w+$/i,
|
|
162335
|
+
/^Created \S+\.\w+$/i,
|
|
162336
|
+
/^Deleted \S+\.\w+$/i,
|
|
162337
|
+
/^Modified \S+\.\w+$/i,
|
|
162338
|
+
/^Ran command:/i,
|
|
162339
|
+
/^Read file:/i
|
|
162340
|
+
];
|
|
162341
|
+
EXPLICIT_NOISE_TITLE_PATTERNS = [
|
|
162342
|
+
/^\s*\[(?:test|demo|benchmark|sandbox|playground|测试|演示)\]/i,
|
|
162343
|
+
/^\s*(?:Used\s+(?:mcp__\S+|apply_patch)|Ran:)\s*/i
|
|
162344
|
+
];
|
|
162345
|
+
EXPLICIT_NOISE_MARKERS = /* @__PURE__ */ new Set([
|
|
162346
|
+
"test-fixture",
|
|
162347
|
+
"demo-fixture",
|
|
162348
|
+
"benchmark-fixture",
|
|
162349
|
+
"sandbox-fixture",
|
|
162350
|
+
"cleanup-noise"
|
|
162351
|
+
]);
|
|
162352
|
+
}
|
|
162353
|
+
});
|
|
162354
|
+
|
|
162355
|
+
// src/dashboard/maintenance.ts
|
|
162356
|
+
import { createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
162357
|
+
function reader(projectId) {
|
|
162358
|
+
return { projectId };
|
|
162359
|
+
}
|
|
162360
|
+
function summarize(observation) {
|
|
162361
|
+
return {
|
|
162362
|
+
id: observation.id,
|
|
162363
|
+
title: observation.title,
|
|
162364
|
+
type: observation.type,
|
|
162365
|
+
entityName: observation.entityName
|
|
162366
|
+
};
|
|
162367
|
+
}
|
|
162368
|
+
function normalizeIds(ids) {
|
|
162369
|
+
return [...new Set(ids)].sort((left, right) => left - right);
|
|
162370
|
+
}
|
|
162371
|
+
function normalizeClusters(clusters) {
|
|
162372
|
+
return clusters.map((ids) => normalizeIds(ids)).sort((left, right) => left.join(",").localeCompare(right.join(",")));
|
|
162373
|
+
}
|
|
162374
|
+
function payloadRecord(payload) {
|
|
162375
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
162376
|
+
throw new DashboardMaintenanceError("The maintenance preview payload is missing.", 400);
|
|
162377
|
+
}
|
|
162378
|
+
return payload;
|
|
162379
|
+
}
|
|
162380
|
+
function payloadIds(value, field) {
|
|
162381
|
+
if (!Array.isArray(value) || value.some((id) => !Number.isSafeInteger(id) || Number(id) <= 0)) {
|
|
162382
|
+
throw new DashboardMaintenanceError(`Invalid ${field} in maintenance preview.`, 400);
|
|
162383
|
+
}
|
|
162384
|
+
return normalizeIds(value);
|
|
162385
|
+
}
|
|
162386
|
+
function sign(action, projectId, payload) {
|
|
162387
|
+
return createHmac("sha256", previewSecret).update(JSON.stringify({ action, projectId, payload })).digest("hex");
|
|
162388
|
+
}
|
|
162389
|
+
function verify(action, projectId, payload, token) {
|
|
162390
|
+
if (typeof token !== "string" || !/^[a-f0-9]{64}$/.test(token)) {
|
|
162391
|
+
throw new DashboardMaintenanceError("Preview this maintenance action before executing it.", 400);
|
|
162392
|
+
}
|
|
162393
|
+
const expected = Buffer.from(sign(action, projectId, payload), "hex");
|
|
162394
|
+
const received = Buffer.from(token, "hex");
|
|
162395
|
+
if (!timingSafeEqual(expected, received)) {
|
|
162396
|
+
throw new DashboardMaintenanceError("The maintenance preview is invalid or belongs to another project.", 409);
|
|
162397
|
+
}
|
|
162398
|
+
}
|
|
162399
|
+
function assertCurrent(expected, actual) {
|
|
162400
|
+
if (JSON.stringify(normalizeIds(expected)) !== JSON.stringify(normalizeIds(actual))) {
|
|
162401
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh the preview before executing.", 409);
|
|
162402
|
+
}
|
|
162403
|
+
}
|
|
162404
|
+
async function manageableActiveObservations(context) {
|
|
162405
|
+
const scope = reader(context.projectId);
|
|
162406
|
+
return filterReadableObservations(
|
|
162407
|
+
await context.store.loadByProject(context.projectId, { status: "active" }),
|
|
162408
|
+
scope
|
|
162409
|
+
).filter((observation) => canManageObservation(observation, scope));
|
|
162410
|
+
}
|
|
162411
|
+
function cleanupPayload(includeNoise, analysis) {
|
|
162412
|
+
return {
|
|
162413
|
+
includeNoise,
|
|
162414
|
+
removeIds: normalizeIds(analysis.toRemove.map((observation) => observation.id)),
|
|
162415
|
+
archiveIds: normalizeIds(analysis.toArchive.map((observation) => observation.id))
|
|
162416
|
+
};
|
|
162417
|
+
}
|
|
162418
|
+
async function previewCleanup(context, includeNoise) {
|
|
162419
|
+
const analysis = analyzeCleanupObservations(await manageableActiveObservations(context), { includeNoise });
|
|
162420
|
+
const payload = cleanupPayload(includeNoise, analysis);
|
|
162421
|
+
return {
|
|
162422
|
+
action: "cleanup",
|
|
162423
|
+
projectId: context.projectId,
|
|
162424
|
+
includeNoise,
|
|
162425
|
+
summary: {
|
|
162426
|
+
totalActive: analysis.totalActive,
|
|
162427
|
+
highQuality: analysis.highQuality,
|
|
162428
|
+
lowQuality: analysis.lowQuality.length,
|
|
162429
|
+
duplicates: analysis.duplicates.length,
|
|
162430
|
+
noise: analysis.noise.length,
|
|
162431
|
+
delete: analysis.toRemove.length,
|
|
162432
|
+
archive: analysis.toArchive.length
|
|
162433
|
+
},
|
|
162434
|
+
lowQuality: analysis.lowQuality.map(summarize),
|
|
162435
|
+
duplicateGroups: analysis.duplicateGroups.map((group) => ({
|
|
162436
|
+
canonical: summarize(group.canonical),
|
|
162437
|
+
duplicates: group.duplicates.map(summarize)
|
|
162438
|
+
})),
|
|
162439
|
+
noise: analysis.noise.map((hit) => ({ ...summarize(hit.observation), reason: hit.reason })),
|
|
162440
|
+
payload,
|
|
162441
|
+
token: sign("cleanup", context.projectId, payload)
|
|
162442
|
+
};
|
|
162443
|
+
}
|
|
162444
|
+
async function executeCleanup(context, payload, token) {
|
|
162445
|
+
const record80 = payloadRecord(payload);
|
|
162446
|
+
const normalized = {
|
|
162447
|
+
includeNoise: record80.includeNoise === true,
|
|
162448
|
+
removeIds: payloadIds(record80.removeIds, "removeIds"),
|
|
162449
|
+
archiveIds: payloadIds(record80.archiveIds, "archiveIds")
|
|
162450
|
+
};
|
|
162451
|
+
verify("cleanup", context.projectId, normalized, token);
|
|
162452
|
+
const observations2 = await manageableActiveObservations(context);
|
|
162453
|
+
const analysis = analyzeCleanupObservations(observations2, { includeNoise: normalized.includeNoise });
|
|
162454
|
+
const current = cleanupPayload(normalized.includeNoise, analysis);
|
|
162455
|
+
assertCurrent(normalized.removeIds, current.removeIds);
|
|
162456
|
+
assertCurrent(normalized.archiveIds, current.archiveIds);
|
|
162457
|
+
const result = await applyCleanupMutations(context.store, analysis.toArchive, analysis.toRemove);
|
|
162458
|
+
return { action: "cleanup", projectId: context.projectId, ...result };
|
|
162459
|
+
}
|
|
162460
|
+
async function previewDeduplicate(context) {
|
|
162461
|
+
if (!isLLMEnabled()) {
|
|
162462
|
+
return {
|
|
162463
|
+
action: "deduplicate",
|
|
162464
|
+
projectId: context.projectId,
|
|
162465
|
+
available: false,
|
|
162466
|
+
reason: "Intelligent deduplication requires a configured memory LLM."
|
|
162467
|
+
};
|
|
162468
|
+
}
|
|
162469
|
+
const plan = await planMemoryDeduplication(await manageableActiveObservations(context));
|
|
162470
|
+
const payload = { resolveIds: normalizeIds(plan.resolveIds) };
|
|
162471
|
+
return {
|
|
162472
|
+
action: "deduplicate",
|
|
162473
|
+
projectId: context.projectId,
|
|
162474
|
+
available: true,
|
|
162475
|
+
summary: {
|
|
162476
|
+
scanned: plan.scanned,
|
|
162477
|
+
entities: plan.entities,
|
|
162478
|
+
comparisons: plan.comparisons,
|
|
162479
|
+
failedComparisons: plan.failedComparisons,
|
|
162480
|
+
resolve: payload.resolveIds.length
|
|
162481
|
+
},
|
|
162482
|
+
actions: plan.actions,
|
|
162483
|
+
payload,
|
|
162484
|
+
token: sign("deduplicate", context.projectId, payload)
|
|
162485
|
+
};
|
|
162486
|
+
}
|
|
162487
|
+
async function executeDeduplicate(context, payload, token) {
|
|
162488
|
+
const record80 = payloadRecord(payload);
|
|
162489
|
+
const normalized = { resolveIds: payloadIds(record80.resolveIds, "resolveIds") };
|
|
162490
|
+
verify("deduplicate", context.projectId, normalized, token);
|
|
162491
|
+
const result = await applyDeduplicationPlan(
|
|
162492
|
+
context.store,
|
|
162493
|
+
context.projectId,
|
|
162494
|
+
normalized.resolveIds,
|
|
162495
|
+
reader(context.projectId)
|
|
162496
|
+
);
|
|
162497
|
+
if (result.skipped.length > 0) {
|
|
162498
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before applying deduplication.", 409);
|
|
162499
|
+
}
|
|
162500
|
+
return { action: "deduplicate", projectId: context.projectId, ...result };
|
|
162501
|
+
}
|
|
162502
|
+
async function previewConsolidate(context) {
|
|
162503
|
+
const clusters = await findConsolidationCandidates(
|
|
162504
|
+
context.projectRoot ?? context.dataDir,
|
|
162505
|
+
context.projectId
|
|
162506
|
+
);
|
|
162507
|
+
const payload = { clusterIds: normalizeClusters(clusters.map((cluster) => cluster.ids)) };
|
|
162508
|
+
return {
|
|
162509
|
+
action: "consolidate",
|
|
162510
|
+
projectId: context.projectId,
|
|
162511
|
+
summary: {
|
|
162512
|
+
clusters: clusters.length,
|
|
162513
|
+
observations: normalizeIds(clusters.flatMap((cluster) => cluster.ids)).length
|
|
162514
|
+
},
|
|
162515
|
+
clusters,
|
|
162516
|
+
payload,
|
|
162517
|
+
token: sign("consolidate", context.projectId, payload)
|
|
162518
|
+
};
|
|
162519
|
+
}
|
|
162520
|
+
async function executeConsolidate(context, payload, token) {
|
|
162521
|
+
const record80 = payloadRecord(payload);
|
|
162522
|
+
if (!Array.isArray(record80.clusterIds)) {
|
|
162523
|
+
throw new DashboardMaintenanceError("Invalid clusterIds in maintenance preview.", 400);
|
|
162524
|
+
}
|
|
162525
|
+
const clusterIds = record80.clusterIds.map((ids, index) => payloadIds(ids, `clusterIds[${index}]`));
|
|
162526
|
+
const normalized = { clusterIds: normalizeClusters(clusterIds) };
|
|
162527
|
+
verify("consolidate", context.projectId, normalized, token);
|
|
162528
|
+
const current = await findConsolidationCandidates(context.projectRoot ?? context.dataDir, context.projectId);
|
|
162529
|
+
if (JSON.stringify(normalized.clusterIds) !== JSON.stringify(normalizeClusters(current.map((cluster) => cluster.ids)))) {
|
|
162530
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before consolidating.", 409);
|
|
162531
|
+
}
|
|
162532
|
+
const result = await executeConsolidation(context.projectRoot ?? context.dataDir, context.projectId);
|
|
162533
|
+
return { action: "consolidate", projectId: context.projectId, ...result };
|
|
162534
|
+
}
|
|
162535
|
+
async function retentionCandidates(context) {
|
|
162536
|
+
return (await manageableActiveObservations(context)).map((observation) => ({
|
|
162537
|
+
observation,
|
|
162538
|
+
retention: projectObservationRetention(observation)
|
|
162539
|
+
})).filter((row) => row.retention.zone === "archive-candidate");
|
|
162540
|
+
}
|
|
162541
|
+
async function previewRetentionArchive(context) {
|
|
162542
|
+
const candidates = await retentionCandidates(context);
|
|
162543
|
+
const payload = {
|
|
162544
|
+
archiveIds: normalizeIds(candidates.map((candidate) => candidate.observation.id))
|
|
162545
|
+
};
|
|
162546
|
+
return {
|
|
162547
|
+
action: "retention-archive",
|
|
162548
|
+
projectId: context.projectId,
|
|
162549
|
+
summary: { archive: payload.archiveIds.length },
|
|
162550
|
+
candidates: candidates.map(({ observation, retention }) => ({
|
|
162551
|
+
...summarize(observation),
|
|
162552
|
+
score: retention.displayScore,
|
|
162553
|
+
zone: retention.zone,
|
|
162554
|
+
ageHours: retention.ageHours
|
|
162555
|
+
})),
|
|
162556
|
+
payload,
|
|
162557
|
+
token: sign("retention-archive", context.projectId, payload)
|
|
162558
|
+
};
|
|
162559
|
+
}
|
|
162560
|
+
async function executeRetentionArchive(context, payload, token) {
|
|
162561
|
+
const record80 = payloadRecord(payload);
|
|
162562
|
+
const normalized = { archiveIds: payloadIds(record80.archiveIds, "archiveIds") };
|
|
162563
|
+
verify("retention-archive", context.projectId, normalized, token);
|
|
162564
|
+
const current = await retentionCandidates(context);
|
|
162565
|
+
assertCurrent(normalized.archiveIds, current.map((candidate) => candidate.observation.id));
|
|
162566
|
+
const result = await archiveExpired(
|
|
162567
|
+
context.dataDir,
|
|
162568
|
+
void 0,
|
|
162569
|
+
void 0,
|
|
162570
|
+
context.projectId,
|
|
162571
|
+
reader(context.projectId)
|
|
162572
|
+
);
|
|
162573
|
+
return { action: "retention-archive", projectId: context.projectId, ...result };
|
|
162574
|
+
}
|
|
162575
|
+
var previewSecret, DashboardMaintenanceError;
|
|
162576
|
+
var init_maintenance = __esm({
|
|
162577
|
+
"src/dashboard/maintenance.ts"() {
|
|
162578
|
+
"use strict";
|
|
162579
|
+
init_esm_shims();
|
|
162580
|
+
init_provider2();
|
|
162581
|
+
init_cleanup();
|
|
162582
|
+
init_consolidation();
|
|
162583
|
+
init_deduplication();
|
|
162584
|
+
init_retention();
|
|
162585
|
+
init_visibility();
|
|
162586
|
+
previewSecret = randomBytes(32);
|
|
162587
|
+
DashboardMaintenanceError = class extends Error {
|
|
162588
|
+
constructor(message, status) {
|
|
162589
|
+
super(message);
|
|
162590
|
+
this.status = status;
|
|
162591
|
+
}
|
|
162592
|
+
status;
|
|
162593
|
+
};
|
|
162594
|
+
}
|
|
162595
|
+
});
|
|
162596
|
+
|
|
162134
162597
|
// src/dashboard/project-classification.ts
|
|
162135
162598
|
var project_classification_exports = {};
|
|
162136
162599
|
__export(project_classification_exports, {
|
|
@@ -162733,6 +163196,56 @@ function filterDashboardObservations(observations2, projectId) {
|
|
|
162733
163196
|
function isActiveStatus(status) {
|
|
162734
163197
|
return (status ?? "active") === "active";
|
|
162735
163198
|
}
|
|
163199
|
+
async function handleMaintenanceMutation(apiPath, req, res, context) {
|
|
163200
|
+
if (req.method !== "POST") {
|
|
163201
|
+
throw new DashboardMaintenanceError("Maintenance actions require POST.", 405);
|
|
163202
|
+
}
|
|
163203
|
+
let body = {};
|
|
163204
|
+
const raw = await readBody(req);
|
|
163205
|
+
if (raw.trim()) {
|
|
163206
|
+
try {
|
|
163207
|
+
const parsed = JSON.parse(raw);
|
|
163208
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("object required");
|
|
163209
|
+
body = parsed;
|
|
163210
|
+
} catch {
|
|
163211
|
+
throw new DashboardMaintenanceError("Invalid maintenance request body.", 400);
|
|
163212
|
+
}
|
|
163213
|
+
}
|
|
163214
|
+
const maintenanceContext = {
|
|
163215
|
+
...context,
|
|
163216
|
+
store: getObservationStore()
|
|
163217
|
+
};
|
|
163218
|
+
let result;
|
|
163219
|
+
switch (apiPath) {
|
|
163220
|
+
case "/maintenance/cleanup/preview":
|
|
163221
|
+
result = await previewCleanup(maintenanceContext, body.includeNoise === true);
|
|
163222
|
+
break;
|
|
163223
|
+
case "/maintenance/cleanup/execute":
|
|
163224
|
+
result = await executeCleanup(maintenanceContext, body.payload, body.token);
|
|
163225
|
+
break;
|
|
163226
|
+
case "/maintenance/deduplicate/preview":
|
|
163227
|
+
result = await previewDeduplicate(maintenanceContext);
|
|
163228
|
+
break;
|
|
163229
|
+
case "/maintenance/deduplicate/execute":
|
|
163230
|
+
result = await executeDeduplicate(maintenanceContext, body.payload, body.token);
|
|
163231
|
+
break;
|
|
163232
|
+
case "/maintenance/consolidate/preview":
|
|
163233
|
+
result = await previewConsolidate(maintenanceContext);
|
|
163234
|
+
break;
|
|
163235
|
+
case "/maintenance/consolidate/execute":
|
|
163236
|
+
result = await executeConsolidate(maintenanceContext, body.payload, body.token);
|
|
163237
|
+
break;
|
|
163238
|
+
case "/maintenance/retention/preview":
|
|
163239
|
+
result = await previewRetentionArchive(maintenanceContext);
|
|
163240
|
+
break;
|
|
163241
|
+
case "/maintenance/retention/execute":
|
|
163242
|
+
result = await executeRetentionArchive(maintenanceContext, body.payload, body.token);
|
|
163243
|
+
break;
|
|
163244
|
+
default:
|
|
163245
|
+
throw new DashboardMaintenanceError("Unknown maintenance action.", 404);
|
|
163246
|
+
}
|
|
163247
|
+
sendJson(res, result);
|
|
163248
|
+
}
|
|
162736
163249
|
function prepareDashboardConfig(projectRoot) {
|
|
162737
163250
|
if (!projectRoot) {
|
|
162738
163251
|
if (preparedDashboardProjectRoot !== null) {
|
|
@@ -162775,6 +163288,21 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
162775
163288
|
prepareDashboardConfig(effectiveProjectRoot);
|
|
162776
163289
|
try {
|
|
162777
163290
|
switch (apiPath) {
|
|
163291
|
+
case "/maintenance/cleanup/preview":
|
|
163292
|
+
case "/maintenance/cleanup/execute":
|
|
163293
|
+
case "/maintenance/deduplicate/preview":
|
|
163294
|
+
case "/maintenance/deduplicate/execute":
|
|
163295
|
+
case "/maintenance/consolidate/preview":
|
|
163296
|
+
case "/maintenance/consolidate/execute":
|
|
163297
|
+
case "/maintenance/retention/preview":
|
|
163298
|
+
case "/maintenance/retention/execute": {
|
|
163299
|
+
await handleMaintenanceMutation(apiPath, req, res, {
|
|
163300
|
+
dataDir: effectiveDataDir,
|
|
163301
|
+
projectId: effectiveProjectId,
|
|
163302
|
+
projectRoot: effectiveProjectRoot
|
|
163303
|
+
});
|
|
163304
|
+
break;
|
|
163305
|
+
}
|
|
162778
163306
|
case "/projects": {
|
|
162779
163307
|
try {
|
|
162780
163308
|
const allObs = filterReadableObservations(
|
|
@@ -163298,7 +163826,8 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
163298
163826
|
}
|
|
163299
163827
|
} catch (err) {
|
|
163300
163828
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
163301
|
-
|
|
163829
|
+
const status = err instanceof DashboardMaintenanceError ? err.status : 500;
|
|
163830
|
+
sendError(res, message, status);
|
|
163302
163831
|
}
|
|
163303
163832
|
}
|
|
163304
163833
|
async function serveStatic(req, res, staticDir) {
|
|
@@ -163469,7 +163998,15 @@ async function buildTeamSnapshot(dataDir, projectId, scope, mode) {
|
|
|
163469
163998
|
function readBody(req) {
|
|
163470
163999
|
return new Promise((resolve2, reject) => {
|
|
163471
164000
|
const chunks = [];
|
|
163472
|
-
|
|
164001
|
+
let size = 0;
|
|
164002
|
+
req.on("data", (c) => {
|
|
164003
|
+
size += c.length;
|
|
164004
|
+
if (size > 64 * 1024) {
|
|
164005
|
+
reject(new DashboardMaintenanceError("Request body is too large.", 413));
|
|
164006
|
+
return;
|
|
164007
|
+
}
|
|
164008
|
+
chunks.push(c);
|
|
164009
|
+
});
|
|
163473
164010
|
req.on("end", () => resolve2(Buffer.concat(chunks).toString("utf-8")));
|
|
163474
164011
|
req.on("error", reject);
|
|
163475
164012
|
});
|
|
@@ -163602,6 +164139,7 @@ var init_server = __esm({
|
|
|
163602
164139
|
init_graph_scope();
|
|
163603
164140
|
init_retention();
|
|
163604
164141
|
init_visibility();
|
|
164142
|
+
init_maintenance();
|
|
163605
164143
|
MIME_TYPES = {
|
|
163606
164144
|
".html": "text/html; charset=utf-8",
|
|
163607
164145
|
".css": "text/css; charset=utf-8",
|
|
@@ -166747,7 +167285,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
166747
167285
|
};
|
|
166748
167286
|
const server = existingServer ?? new McpServer({
|
|
166749
167287
|
name: "memorix",
|
|
166750
|
-
version: true ? "1.
|
|
167288
|
+
version: true ? "1.7.1" : "1.0.1"
|
|
166751
167289
|
});
|
|
166752
167290
|
const originalRegisterTool = server.registerTool.bind(server);
|
|
166753
167291
|
server.registerTool = ((name, ...args) => {
|
|
@@ -166877,20 +167415,20 @@ The path should point to a directory containing a .git folder.`
|
|
|
166877
167415
|
if (readOnlyBoundary) return readOnlyBoundary;
|
|
166878
167416
|
const requestedVisibility = longTerm?.scope === "user" ? "personal" : longTerm?.scope === "team" ? "team" : visibility;
|
|
166879
167417
|
const effectiveVisibility = requestedVisibility ?? "project";
|
|
166880
|
-
const
|
|
167418
|
+
const reader2 = getObservationReader();
|
|
166881
167419
|
if (effectiveVisibility !== "project" && !currentAgentId) {
|
|
166882
167420
|
return {
|
|
166883
167421
|
content: [{ type: "text", text: "Personal or team memory requires memorix_session_start with joinTeam=true so Memorix can bind an owner." }],
|
|
166884
167422
|
isError: true
|
|
166885
167423
|
};
|
|
166886
167424
|
}
|
|
166887
|
-
if (effectiveVisibility === "team" && !
|
|
167425
|
+
if (effectiveVisibility === "team" && !reader2.isTeamMember) {
|
|
166888
167426
|
return {
|
|
166889
167427
|
content: [{ type: "text", text: "Team memory requires an active coordination membership in the current project." }],
|
|
166890
167428
|
isError: true
|
|
166891
167429
|
};
|
|
166892
167430
|
}
|
|
166893
|
-
if (longTerm?.scope === "team" && !
|
|
167431
|
+
if (longTerm?.scope === "team" && !reader2.isTeamMember) {
|
|
166894
167432
|
return {
|
|
166895
167433
|
content: [{ type: "text", text: "Team long-term memory requires an active coordination membership in the current project." }],
|
|
166896
167434
|
isError: true
|
|
@@ -166937,9 +167475,9 @@ The path should point to a directory containing a .git folder.`
|
|
|
166937
167475
|
useLLM: isLLMEnabled(),
|
|
166938
167476
|
minValueScore: 0.3,
|
|
166939
167477
|
searchMemories: async (q, limit2, pid, signal) => {
|
|
166940
|
-
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
167478
|
+
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
166941
167479
|
if (result.entries.length === 0) return [];
|
|
166942
|
-
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader });
|
|
167480
|
+
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader: reader2 });
|
|
166943
167481
|
return details.documents.map((d, i2) => ({
|
|
166944
167482
|
id: Number(d.id.replace("obs-", "")),
|
|
166945
167483
|
observationId: d.observationId,
|
|
@@ -166953,7 +167491,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
166953
167491
|
},
|
|
166954
167492
|
getObservation: (id) => {
|
|
166955
167493
|
const o = getObservation(id);
|
|
166956
|
-
if (!o || o.projectId !== project.id || !canReadObservation(o,
|
|
167494
|
+
if (!o || o.projectId !== project.id || !canReadObservation(o, reader2)) return null;
|
|
166957
167495
|
return {
|
|
166958
167496
|
id: o.id,
|
|
166959
167497
|
entityName: o.entityName,
|
|
@@ -167010,7 +167548,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167010
167548
|
const { action: action2, targetId, reason } = formationResult.resolution;
|
|
167011
167549
|
if (action2 === "merge" && targetId) {
|
|
167012
167550
|
const targetObs = getObservation(targetId);
|
|
167013
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167551
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
167014
167552
|
await storeObservation({
|
|
167015
167553
|
entityName: targetObs.entityName,
|
|
167016
167554
|
type: targetObs.type,
|
|
@@ -167025,7 +167563,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167025
167563
|
sourceDetail: "explicit",
|
|
167026
167564
|
createdByAgentId: currentAgentId,
|
|
167027
167565
|
visibility,
|
|
167028
|
-
visibilityReader:
|
|
167566
|
+
visibilityReader: reader2
|
|
167029
167567
|
});
|
|
167030
167568
|
return {
|
|
167031
167569
|
content: [{
|
|
@@ -167036,7 +167574,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167036
167574
|
}
|
|
167037
167575
|
} else if (action2 === "evolve" && targetId) {
|
|
167038
167576
|
const targetObs = getObservation(targetId);
|
|
167039
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167577
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
167040
167578
|
await storeObservation({
|
|
167041
167579
|
entityName: targetObs.entityName,
|
|
167042
167580
|
type: targetObs.type,
|
|
@@ -167051,7 +167589,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167051
167589
|
sourceDetail: "explicit",
|
|
167052
167590
|
createdByAgentId: currentAgentId,
|
|
167053
167591
|
visibility,
|
|
167054
|
-
visibilityReader:
|
|
167592
|
+
visibilityReader: reader2
|
|
167055
167593
|
});
|
|
167056
167594
|
return {
|
|
167057
167595
|
content: [{
|
|
@@ -167078,12 +167616,12 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167078
167616
|
limit: 5,
|
|
167079
167617
|
projectId: project.id,
|
|
167080
167618
|
status: "active",
|
|
167081
|
-
reader
|
|
167619
|
+
reader: reader2
|
|
167082
167620
|
});
|
|
167083
167621
|
const similarEntries = searchResult.entries.map((e2) => e2);
|
|
167084
167622
|
if (similarEntries.length > 0) {
|
|
167085
167623
|
const similarIds = similarEntries.map((e2) => e2.id);
|
|
167086
|
-
const details = await compactDetail(similarIds, { reader });
|
|
167624
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
167087
167625
|
const existingMemories = details.documents.map((d, i2) => ({
|
|
167088
167626
|
id: d.observationId,
|
|
167089
167627
|
title: d.title,
|
|
@@ -167101,7 +167639,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167101
167639
|
);
|
|
167102
167640
|
if (decision.action === "UPDATE" && decision.targetId) {
|
|
167103
167641
|
const targetObs = getObservation(decision.targetId);
|
|
167104
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167642
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
167105
167643
|
await storeObservation({
|
|
167106
167644
|
entityName: targetObs.entityName,
|
|
167107
167645
|
type: targetObs.type,
|
|
@@ -167116,7 +167654,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
167116
167654
|
sourceDetail: "explicit",
|
|
167117
167655
|
createdByAgentId: currentAgentId,
|
|
167118
167656
|
visibility,
|
|
167119
|
-
visibilityReader:
|
|
167657
|
+
visibilityReader: reader2
|
|
167120
167658
|
});
|
|
167121
167659
|
compactAction = `[UPDATED] Compact UPDATE: merged into #${decision.targetId} (${decision.reason})`;
|
|
167122
167660
|
compactMerged = true;
|
|
@@ -167203,7 +167741,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
167203
167741
|
const attrCheck = await checkProjectAttribution(
|
|
167204
167742
|
entityName,
|
|
167205
167743
|
project.id,
|
|
167206
|
-
filterReadableObservations(getAllObservations(),
|
|
167744
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
167207
167745
|
);
|
|
167208
167746
|
if (attrCheck.suspicious) {
|
|
167209
167747
|
attributionWarning = `
|
|
@@ -167230,7 +167768,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
167230
167768
|
valueCategory: formationResult?.evaluation.category,
|
|
167231
167769
|
createdByAgentId: currentAgentId,
|
|
167232
167770
|
visibility: requestedVisibility,
|
|
167233
|
-
visibilityReader:
|
|
167771
|
+
visibilityReader: reader2
|
|
167234
167772
|
});
|
|
167235
167773
|
let longTermNote = "";
|
|
167236
167774
|
if (longTerm) {
|
|
@@ -167245,8 +167783,8 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
167245
167783
|
applicability: longTerm.applicability,
|
|
167246
167784
|
reader: {
|
|
167247
167785
|
projectId: project.id,
|
|
167248
|
-
...
|
|
167249
|
-
...
|
|
167786
|
+
...reader2.agentId ? { agentId: reader2.agentId } : {},
|
|
167787
|
+
...reader2.isTeamMember ? { isTeamMember: true } : {}
|
|
167250
167788
|
}
|
|
167251
167789
|
});
|
|
167252
167790
|
const autoQualified = await maybeAutoQualifyLongTermMemory2({
|
|
@@ -167299,12 +167837,12 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167299
167837
|
limit: 5,
|
|
167300
167838
|
projectId: project.id,
|
|
167301
167839
|
status: "active",
|
|
167302
|
-
reader
|
|
167840
|
+
reader: reader2
|
|
167303
167841
|
});
|
|
167304
167842
|
const similarEntries = searchResult.entries.map((e2) => e2);
|
|
167305
167843
|
if (similarEntries.length > 0) {
|
|
167306
167844
|
const similarIds = similarEntries.map((e2) => e2.id);
|
|
167307
|
-
const details = await compactDetail(similarIds, { reader });
|
|
167845
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
167308
167846
|
const existingMemories = details.documents.map((d, i2) => ({
|
|
167309
167847
|
id: d.observationId,
|
|
167310
167848
|
title: d.title,
|
|
@@ -167330,9 +167868,9 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167330
167868
|
useLLM: isLLMEnabled(),
|
|
167331
167869
|
minValueScore: 0.3,
|
|
167332
167870
|
searchMemories: async (q, limit2, pid, signal) => {
|
|
167333
|
-
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
167871
|
+
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
167334
167872
|
if (result.entries.length === 0) return [];
|
|
167335
|
-
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader });
|
|
167873
|
+
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader: reader2 });
|
|
167336
167874
|
return details.documents.map((d, i2) => ({
|
|
167337
167875
|
id: Number(d.id.replace("obs-", "")),
|
|
167338
167876
|
observationId: d.observationId,
|
|
@@ -167346,7 +167884,7 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167346
167884
|
},
|
|
167347
167885
|
getObservation: (id) => {
|
|
167348
167886
|
const o = getObservation(id);
|
|
167349
|
-
if (!o || o.projectId !== project.id || !canReadObservation(o,
|
|
167887
|
+
if (!o || o.projectId !== project.id || !canReadObservation(o, reader2)) return null;
|
|
167350
167888
|
return { id: o.id, entityName: o.entityName, type: o.type, title: o.title, narrative: o.narrative, facts: o.facts, topicKey: o.topicKey };
|
|
167351
167889
|
},
|
|
167352
167890
|
getEntityNames: () => graphManager.getEntityNames()
|
|
@@ -168114,10 +168652,10 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
168114
168652
|
async ({ ids, status }) => {
|
|
168115
168653
|
const { resolveObservations: resolveObservations2, getObservation: getObservation2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
168116
168654
|
const safeIds = (Array.isArray(ids) ? ids : [ids]).map((id) => coerceNumber(id, 0)).filter((id) => id > 0);
|
|
168117
|
-
const
|
|
168655
|
+
const reader2 = getObservationReader();
|
|
168118
168656
|
const authorizedIds = safeIds.filter((id) => {
|
|
168119
168657
|
const observation = getObservation2(id, project.id);
|
|
168120
|
-
return observation ? canManageObservation(observation,
|
|
168658
|
+
return observation ? canManageObservation(observation, reader2) : false;
|
|
168121
168659
|
});
|
|
168122
168660
|
const result = await resolveObservations2(authorizedIds, status ?? "resolved");
|
|
168123
168661
|
const deniedCount = safeIds.length - authorizedIds.length;
|
|
@@ -168160,7 +168698,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
168160
168698
|
async ({ entityName, decision, alternatives, rationale, constraints, expectedOutcome, risks, concepts, filesModified, relatedCommits, relatedEntities }) => {
|
|
168161
168699
|
const unresolved = requireResolvedProject("store reasoning in the current project");
|
|
168162
168700
|
if (unresolved) return unresolved;
|
|
168163
|
-
const
|
|
168701
|
+
const reader2 = getObservationReader();
|
|
168164
168702
|
return withFreshIndex(async () => {
|
|
168165
168703
|
const narrativeParts = [rationale];
|
|
168166
168704
|
if (alternatives && alternatives.length > 0) {
|
|
@@ -168186,7 +168724,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
168186
168724
|
const attrCheck = await checkProjectAttribution(
|
|
168187
168725
|
entityName,
|
|
168188
168726
|
project.id,
|
|
168189
|
-
filterReadableObservations(getAllObservations(),
|
|
168727
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
168190
168728
|
);
|
|
168191
168729
|
if (attrCheck.suspicious) {
|
|
168192
168730
|
reasoningAttributionWarning = `
|
|
@@ -168335,11 +168873,11 @@ ${result.formatted}` }]
|
|
|
168335
168873
|
},
|
|
168336
168874
|
async ({ query, dryRun }) => {
|
|
168337
168875
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
168338
|
-
const
|
|
168876
|
+
const reader2 = getObservationReader();
|
|
168339
168877
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
168340
168878
|
getAllObservations2().filter((o) => (o.status ?? "active") === "active" && o.projectId === project.id),
|
|
168341
|
-
|
|
168342
|
-
).filter((observation) => canManageObservation(observation,
|
|
168879
|
+
reader2
|
|
168880
|
+
).filter((observation) => canManageObservation(observation, reader2)));
|
|
168343
168881
|
if (allObs.length < 2) {
|
|
168344
168882
|
return { content: [{ type: "text", text: "Not enough active memories to deduplicate." }] };
|
|
168345
168883
|
}
|
|
@@ -168353,7 +168891,7 @@ ${result.formatted}` }]
|
|
|
168353
168891
|
}
|
|
168354
168892
|
let candidates;
|
|
168355
168893
|
if (query) {
|
|
168356
|
-
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader });
|
|
168894
|
+
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader: reader2 });
|
|
168357
168895
|
const idSet = new Set(searchResult.entries.map((e2) => e2.id));
|
|
168358
168896
|
candidates = allObs.filter((o) => idSet.has(o.id));
|
|
168359
168897
|
} else {
|
|
@@ -168362,64 +168900,33 @@ ${result.formatted}` }]
|
|
|
168362
168900
|
if (candidates.length < 2) {
|
|
168363
168901
|
return { content: [{ type: "text", text: "Not enough memories in scope to deduplicate." }] };
|
|
168364
168902
|
}
|
|
168365
|
-
const
|
|
168366
|
-
|
|
168367
|
-
|
|
168368
|
-
|
|
168369
|
-
|
|
168370
|
-
|
|
168371
|
-
|
|
168372
|
-
const toResolve = [];
|
|
168373
|
-
for (const [entity, group] of byEntity) {
|
|
168374
|
-
if (group.length < 2) continue;
|
|
168375
|
-
for (let i2 = 0; i2 < group.length; i2++) {
|
|
168376
|
-
for (let j = i2 + 1; j < group.length; j++) {
|
|
168377
|
-
const newer = group[j];
|
|
168378
|
-
const older = group[i2];
|
|
168379
|
-
try {
|
|
168380
|
-
const decision = await deduplicateMemory(
|
|
168381
|
-
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
168382
|
-
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
168383
|
-
);
|
|
168384
|
-
if (decision && decision.action === "UPDATE" && decision.targetId) {
|
|
168385
|
-
actions.push(`[UPDATED] #${older.id} "${older.title}" \u2192 superseded by #${newer.id} (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168386
|
-
toResolve.push(older.id);
|
|
168387
|
-
} else if (decision && decision.action === "NONE") {
|
|
168388
|
-
actions.push(`[DELETE] #${newer.id} "${newer.title}" \u2192 redundant (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168389
|
-
toResolve.push(newer.id);
|
|
168390
|
-
} else if (decision && decision.action === "DELETE") {
|
|
168391
|
-
actions.push(`[ERROR] #${decision.targetId ?? older.id} \u2192 outdated (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168392
|
-
toResolve.push(decision.targetId ?? older.id);
|
|
168393
|
-
}
|
|
168394
|
-
} catch (dedupErr) {
|
|
168395
|
-
actions.push(`[WARN] comparison failed: ${dedupErr?.message ?? dedupErr}`);
|
|
168396
|
-
}
|
|
168397
|
-
}
|
|
168398
|
-
}
|
|
168399
|
-
}
|
|
168400
|
-
if (actions.length === 0) {
|
|
168401
|
-
return { content: [{ type: "text", text: `[OK] Scanned ${candidates.length} memories across ${byEntity.size} entities \u2014 no duplicates found.` }] };
|
|
168903
|
+
const manageableCandidates = candidates.filter((observation) => canManageObservation(observation, reader2));
|
|
168904
|
+
const plan = await planMemoryDeduplication(manageableCandidates);
|
|
168905
|
+
const actionLines = plan.actions.map(
|
|
168906
|
+
(item) => `Resolve #${item.resolveId} "${item.resolveTitle}"; keep #${item.keepId} "${item.keepTitle}" (${item.reason})${item.usedLLM ? " [LLM]" : " [heuristic]"}`
|
|
168907
|
+
);
|
|
168908
|
+
if (actionLines.length === 0) {
|
|
168909
|
+
return { content: [{ type: "text", text: `[OK] Scanned ${plan.scanned} memories across ${plan.entities} entities \u2014 no duplicates found.` }] };
|
|
168402
168910
|
}
|
|
168403
168911
|
if (dryRun) {
|
|
168404
168912
|
return {
|
|
168405
168913
|
content: [{
|
|
168406
168914
|
type: "text",
|
|
168407
|
-
text: `[SEARCH] DRY RUN \u2014 ${
|
|
168915
|
+
text: `[SEARCH] DRY RUN \u2014 ${actionLines.length} action(s) found:
|
|
168408
168916
|
|
|
168409
|
-
${
|
|
168917
|
+
${actionLines.join("\n")}
|
|
168410
168918
|
|
|
168411
168919
|
Run with dryRun=false to apply.`
|
|
168412
168920
|
}]
|
|
168413
168921
|
};
|
|
168414
168922
|
}
|
|
168415
|
-
const
|
|
168416
|
-
await resolveObservations2(unique2, "resolved");
|
|
168923
|
+
const result = await applyDeduplicationPlan(getObservationStore(), project.id, plan.resolveIds, reader2);
|
|
168417
168924
|
return {
|
|
168418
168925
|
content: [{
|
|
168419
168926
|
type: "text",
|
|
168420
|
-
text: `[CLEANUP] Deduplicated: resolved ${
|
|
168927
|
+
text: `[CLEANUP] Deduplicated: resolved ${result.resolved.length} memory(ies)
|
|
168421
168928
|
|
|
168422
|
-
${
|
|
168929
|
+
${actionLines.join("\n")}`
|
|
168423
168930
|
}]
|
|
168424
168931
|
};
|
|
168425
168932
|
}
|
|
@@ -168527,8 +169034,8 @@ ${actions.join("\n")}`
|
|
|
168527
169034
|
formatted.push(JSON.stringify({ durableMemory: details }, null, 2));
|
|
168528
169035
|
}
|
|
168529
169036
|
if (observationTypedRefs.length > 0 || safeRefs.length > 0 || safeIds.length > 0) {
|
|
168530
|
-
const
|
|
168531
|
-
const result = observationTypedRefs.length > 0 ? await compactDetail(observationTypedRefs, { reader }) : safeRefs.length > 0 ? await compactDetail(safeRefs, { reader }) : await compactDetail(safeIds.map((id) => ({ id, projectId: project.id })), { reader });
|
|
169037
|
+
const reader2 = getObservationReader(hasCrossProjectRef ? "global" : "project");
|
|
169038
|
+
const result = observationTypedRefs.length > 0 ? await compactDetail(observationTypedRefs, { reader: reader2 }) : safeRefs.length > 0 ? await compactDetail(safeRefs, { reader: reader2 }) : await compactDetail(safeIds.map((id) => ({ id, projectId: project.id })), { reader: reader2 });
|
|
168532
169039
|
formatted.push(
|
|
168533
169040
|
result.documents.length > 0 ? result.formatted : observationTypedRefs.length > 0 ? `No memories found for refs: ${observationTypedRefs.join(", ")}` : safeRefs.length > 0 ? `No memories found for refs: ${safeRefs.map((ref) => `${ref.projectId ?? "current"}#${ref.id}`).join(", ")}` : `No memories found for IDs: ${safeIds.join(", ")}`
|
|
168534
169041
|
);
|
|
@@ -168561,10 +169068,10 @@ ${actions.join("\n")}`
|
|
|
168561
169068
|
const { getDb: getDb2 } = await Promise.resolve().then(() => (init_orama_store(), orama_store_exports));
|
|
168562
169069
|
const { search: search2 } = await import("@orama/orama");
|
|
168563
169070
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
168564
|
-
const
|
|
169071
|
+
const reader2 = getObservationReader();
|
|
168565
169072
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
168566
169073
|
getAllObservations2().filter((observation) => observation.projectId === project.id),
|
|
168567
|
-
|
|
169074
|
+
reader2
|
|
168568
169075
|
));
|
|
168569
169076
|
const accessMap = /* @__PURE__ */ new Map();
|
|
168570
169077
|
try {
|
|
@@ -168614,7 +169121,7 @@ ${actions.join("\n")}`
|
|
|
168614
169121
|
}
|
|
168615
169122
|
if (action === "archive") {
|
|
168616
169123
|
const managedIds = new Set(
|
|
168617
|
-
allObs.filter((observation) => canManageObservation(observation,
|
|
169124
|
+
allObs.filter((observation) => canManageObservation(observation, reader2)).map((observation) => observation.id)
|
|
168618
169125
|
);
|
|
168619
169126
|
const candidates2 = getArchiveCandidates2(docs).filter((document2) => managedIds.has(document2.observationId));
|
|
168620
169127
|
if (candidates2.length === 0) {
|
|
@@ -169328,10 +169835,10 @@ ${skill2.content}` }]
|
|
|
169328
169835
|
}
|
|
169329
169836
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
169330
169837
|
const allObs = await withFreshIndex(() => getAllObservations2());
|
|
169331
|
-
const
|
|
169838
|
+
const reader2 = getObservationReader();
|
|
169332
169839
|
const matched = filterReadableObservations(
|
|
169333
169840
|
allObs.filter((observation) => observation.projectId === project.id && observationIds.includes(observation.id)),
|
|
169334
|
-
|
|
169841
|
+
reader2
|
|
169335
169842
|
);
|
|
169336
169843
|
if (matched.length === 0) {
|
|
169337
169844
|
return { content: [{ type: "text", text: `No observations found for IDs: [${observationIds.join(", ")}]. Use \`memorix_search\` to find valid IDs.` }], isError: true };
|
|
@@ -171039,6 +171546,7 @@ var init_server2 = __esm({
|
|
|
171039
171546
|
init_tool_profile();
|
|
171040
171547
|
init_provider2();
|
|
171041
171548
|
init_memory_manager();
|
|
171549
|
+
init_deduplication();
|
|
171042
171550
|
init_formation();
|
|
171043
171551
|
init_formation_timeout();
|
|
171044
171552
|
init_timeout();
|
|
@@ -171217,7 +171725,7 @@ var init_serve_shared = __esm({
|
|
|
171217
171725
|
|
|
171218
171726
|
// src/cli/version.ts
|
|
171219
171727
|
function getCliVersion() {
|
|
171220
|
-
return true ? "1.
|
|
171728
|
+
return true ? "1.7.1" : pkg.version;
|
|
171221
171729
|
}
|
|
171222
171730
|
var init_version3 = __esm({
|
|
171223
171731
|
"src/cli/version.ts"() {
|