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/sdk.js
CHANGED
|
@@ -81,29 +81,29 @@ function sharedAgentIds(record80) {
|
|
|
81
81
|
return [];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
function canReadObservation(record80,
|
|
85
|
-
if (!
|
|
86
|
-
const sameProject =
|
|
84
|
+
function canReadObservation(record80, reader2) {
|
|
85
|
+
if (!reader2) return true;
|
|
86
|
+
const sameProject = reader2.projectId === record80.projectId;
|
|
87
87
|
const visibility = resolveObservationVisibility(record80);
|
|
88
|
-
if (visibility === "project") return !
|
|
89
|
-
if (!sameProject || !
|
|
90
|
-
if (visibility === "team") return
|
|
91
|
-
return record80.createdByAgentId ===
|
|
92
|
-
}
|
|
93
|
-
function canManageObservation(record80,
|
|
94
|
-
if (!
|
|
95
|
-
if (!
|
|
88
|
+
if (visibility === "project") return !reader2.projectId || sameProject;
|
|
89
|
+
if (!sameProject || !reader2.agentId) return false;
|
|
90
|
+
if (visibility === "team") return reader2.isTeamMember === true;
|
|
91
|
+
return record80.createdByAgentId === reader2.agentId || sharedAgentIds(record80).includes(reader2.agentId);
|
|
92
|
+
}
|
|
93
|
+
function canManageObservation(record80, reader2) {
|
|
94
|
+
if (!reader2) return true;
|
|
95
|
+
if (!reader2.projectId || reader2.projectId !== record80.projectId) return false;
|
|
96
96
|
switch (resolveObservationVisibility(record80)) {
|
|
97
97
|
case "project":
|
|
98
98
|
return true;
|
|
99
99
|
case "team":
|
|
100
|
-
return
|
|
100
|
+
return reader2.isTeamMember === true;
|
|
101
101
|
case "personal":
|
|
102
|
-
return Boolean(
|
|
102
|
+
return Boolean(reader2.agentId && record80.createdByAgentId === reader2.agentId);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
function filterReadableObservations(observations2,
|
|
106
|
-
return
|
|
105
|
+
function filterReadableObservations(observations2, reader2) {
|
|
106
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(observation, reader2)) : [...observations2];
|
|
107
107
|
}
|
|
108
108
|
var init_visibility = __esm({
|
|
109
109
|
"src/memory/visibility.ts"() {
|
|
@@ -5692,8 +5692,8 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5692
5692
|
if (contentLength && Number(contentLength) > maxBytes) {
|
|
5693
5693
|
throw new Error(`LLM response too large (${contentLength} bytes)`);
|
|
5694
5694
|
}
|
|
5695
|
-
const
|
|
5696
|
-
if (!
|
|
5695
|
+
const reader2 = response.body?.getReader();
|
|
5696
|
+
if (!reader2) {
|
|
5697
5697
|
signal?.throwIfAborted();
|
|
5698
5698
|
return response.text();
|
|
5699
5699
|
}
|
|
@@ -5701,19 +5701,19 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5701
5701
|
const chunks = [];
|
|
5702
5702
|
let bytesRead = 0;
|
|
5703
5703
|
const abortReader = () => {
|
|
5704
|
-
void
|
|
5704
|
+
void reader2.cancel(signal?.reason).catch(() => void 0);
|
|
5705
5705
|
};
|
|
5706
5706
|
signal?.addEventListener("abort", abortReader, { once: true });
|
|
5707
5707
|
try {
|
|
5708
5708
|
while (true) {
|
|
5709
5709
|
signal?.throwIfAborted();
|
|
5710
|
-
const { value, done } = await
|
|
5710
|
+
const { value, done } = await reader2.read();
|
|
5711
5711
|
if (done) break;
|
|
5712
5712
|
signal?.throwIfAborted();
|
|
5713
5713
|
if (!value) continue;
|
|
5714
5714
|
bytesRead += value.byteLength;
|
|
5715
5715
|
if (bytesRead > maxBytes) {
|
|
5716
|
-
await
|
|
5716
|
+
await reader2.cancel("response too large").catch(() => void 0);
|
|
5717
5717
|
throw new Error(`LLM response exceeded ${maxBytes} bytes`);
|
|
5718
5718
|
}
|
|
5719
5719
|
chunks.push(decoder.decode(value, { stream: true }));
|
|
@@ -5723,7 +5723,7 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
5723
5723
|
return chunks.join("");
|
|
5724
5724
|
} finally {
|
|
5725
5725
|
signal?.removeEventListener("abort", abortReader);
|
|
5726
|
-
|
|
5726
|
+
reader2.releaseLock();
|
|
5727
5727
|
}
|
|
5728
5728
|
}
|
|
5729
5729
|
async function readResponseJson(response, signal, maxBytes = MAX_LLM_RESPONSE_BYTES) {
|
|
@@ -6053,8 +6053,8 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6053
6053
|
const error = await response.text().catch(() => "unknown error");
|
|
6054
6054
|
throw new Error(`LLM streaming API error (${response.status}): ${error}`);
|
|
6055
6055
|
}
|
|
6056
|
-
const
|
|
6057
|
-
if (!
|
|
6056
|
+
const reader2 = response.body?.getReader();
|
|
6057
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
6058
6058
|
const decoder = new TextDecoder();
|
|
6059
6059
|
let fullContent = "";
|
|
6060
6060
|
const toolCallMap = /* @__PURE__ */ new Map();
|
|
@@ -6062,7 +6062,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6062
6062
|
let buffer = "";
|
|
6063
6063
|
try {
|
|
6064
6064
|
while (true) {
|
|
6065
|
-
const { done, value } = await
|
|
6065
|
+
const { done, value } = await reader2.read();
|
|
6066
6066
|
if (done) break;
|
|
6067
6067
|
buffer += decoder.decode(value, { stream: true });
|
|
6068
6068
|
const lines = buffer.split("\n");
|
|
@@ -6104,7 +6104,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
6104
6104
|
}
|
|
6105
6105
|
}
|
|
6106
6106
|
} finally {
|
|
6107
|
-
|
|
6107
|
+
reader2.releaseLock();
|
|
6108
6108
|
}
|
|
6109
6109
|
const toolCalls = [...toolCallMap.values()].map((tc) => ({
|
|
6110
6110
|
id: tc.id,
|
|
@@ -6185,8 +6185,8 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6185
6185
|
const error = await response.text().catch(() => "unknown error");
|
|
6186
6186
|
throw new Error(`Anthropic streaming API error (${response.status}): ${error}`);
|
|
6187
6187
|
}
|
|
6188
|
-
const
|
|
6189
|
-
if (!
|
|
6188
|
+
const reader2 = response.body?.getReader();
|
|
6189
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
6190
6190
|
const decoder = new TextDecoder();
|
|
6191
6191
|
let fullContent = "";
|
|
6192
6192
|
const toolCalls = [];
|
|
@@ -6197,7 +6197,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6197
6197
|
let buffer = "";
|
|
6198
6198
|
try {
|
|
6199
6199
|
while (true) {
|
|
6200
|
-
const { done, value } = await
|
|
6200
|
+
const { done, value } = await reader2.read();
|
|
6201
6201
|
if (done) break;
|
|
6202
6202
|
buffer += decoder.decode(value, { stream: true });
|
|
6203
6203
|
const lines = buffer.split("\n");
|
|
@@ -6245,7 +6245,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
6245
6245
|
}
|
|
6246
6246
|
}
|
|
6247
6247
|
} finally {
|
|
6248
|
-
|
|
6248
|
+
reader2.releaseLock();
|
|
6249
6249
|
}
|
|
6250
6250
|
const mappedStopReason = stopReason === "tool_use" ? "tool_use" : stopReason === "end_turn" ? "end_turn" : "unknown";
|
|
6251
6251
|
yield {
|
|
@@ -7652,11 +7652,11 @@ async function getObservationsByIds(ids, projectId) {
|
|
|
7652
7652
|
}
|
|
7653
7653
|
return results;
|
|
7654
7654
|
}
|
|
7655
|
-
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
7655
|
+
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2) {
|
|
7656
7656
|
const { withFreshIndex: withFreshIndex2 } = await Promise.resolve().then(() => (init_freshness(), freshness_exports));
|
|
7657
7657
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
7658
7658
|
const rawObs = await withFreshIndex2(() => getAllObservations2());
|
|
7659
|
-
const allObs = (projectId ? rawObs.filter((o) => o.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation,
|
|
7659
|
+
const allObs = (projectId ? rawObs.filter((o) => o.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation, reader2));
|
|
7660
7660
|
const sorted = allObs.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
7661
7661
|
const anchorIndex = sorted.findIndex((o) => o.id === anchorId);
|
|
7662
7662
|
if (anchorIndex === -1) {
|
|
@@ -18881,12 +18881,12 @@ async function readBoundedImageResponse(response) {
|
|
|
18881
18881
|
}
|
|
18882
18882
|
if (!response.body)
|
|
18883
18883
|
throw new Error("MiniMax image generation returned an empty image response");
|
|
18884
|
-
const
|
|
18884
|
+
const reader2 = response.body.getReader();
|
|
18885
18885
|
const chunks = [];
|
|
18886
18886
|
let total = 0;
|
|
18887
18887
|
try {
|
|
18888
18888
|
while (true) {
|
|
18889
|
-
const { done, value } = await
|
|
18889
|
+
const { done, value } = await reader2.read();
|
|
18890
18890
|
if (done)
|
|
18891
18891
|
break;
|
|
18892
18892
|
if (!value)
|
|
@@ -18898,7 +18898,7 @@ async function readBoundedImageResponse(response) {
|
|
|
18898
18898
|
chunks.push(value);
|
|
18899
18899
|
}
|
|
18900
18900
|
} finally {
|
|
18901
|
-
|
|
18901
|
+
reader2.releaseLock();
|
|
18902
18902
|
}
|
|
18903
18903
|
return Buffer.concat(chunks);
|
|
18904
18904
|
}
|
|
@@ -19422,22 +19422,22 @@ function ReadableStreamFrom(iterable) {
|
|
|
19422
19422
|
function ReadableStreamToAsyncIterable(stream2) {
|
|
19423
19423
|
if (stream2[Symbol.asyncIterator])
|
|
19424
19424
|
return stream2;
|
|
19425
|
-
const
|
|
19425
|
+
const reader2 = stream2.getReader();
|
|
19426
19426
|
return {
|
|
19427
19427
|
async next() {
|
|
19428
19428
|
try {
|
|
19429
|
-
const result = await
|
|
19429
|
+
const result = await reader2.read();
|
|
19430
19430
|
if (result?.done)
|
|
19431
|
-
|
|
19431
|
+
reader2.releaseLock();
|
|
19432
19432
|
return result;
|
|
19433
19433
|
} catch (e2) {
|
|
19434
|
-
|
|
19434
|
+
reader2.releaseLock();
|
|
19435
19435
|
throw e2;
|
|
19436
19436
|
}
|
|
19437
19437
|
},
|
|
19438
19438
|
async return() {
|
|
19439
|
-
const cancelPromise =
|
|
19440
|
-
|
|
19439
|
+
const cancelPromise = reader2.cancel();
|
|
19440
|
+
reader2.releaseLock();
|
|
19441
19441
|
await cancelPromise;
|
|
19442
19442
|
return { done: true, value: void 0 };
|
|
19443
19443
|
},
|
|
@@ -19453,9 +19453,9 @@ async function CancelReadableStream(stream2) {
|
|
|
19453
19453
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
19454
19454
|
return;
|
|
19455
19455
|
}
|
|
19456
|
-
const
|
|
19457
|
-
const cancelPromise =
|
|
19458
|
-
|
|
19456
|
+
const reader2 = stream2.getReader();
|
|
19457
|
+
const cancelPromise = reader2.cancel();
|
|
19458
|
+
reader2.releaseLock();
|
|
19459
19459
|
await cancelPromise;
|
|
19460
19460
|
}
|
|
19461
19461
|
var init_shims = __esm({
|
|
@@ -22194,31 +22194,31 @@ var init_ChatCompletionStream = __esm({
|
|
|
22194
22194
|
const readQueue = [];
|
|
22195
22195
|
let done = false;
|
|
22196
22196
|
this.on("chunk", (chunk) => {
|
|
22197
|
-
const
|
|
22198
|
-
if (
|
|
22199
|
-
|
|
22197
|
+
const reader2 = readQueue.shift();
|
|
22198
|
+
if (reader2) {
|
|
22199
|
+
reader2.resolve(chunk);
|
|
22200
22200
|
} else {
|
|
22201
22201
|
pushQueue.push(chunk);
|
|
22202
22202
|
}
|
|
22203
22203
|
});
|
|
22204
22204
|
this.on("end", () => {
|
|
22205
22205
|
done = true;
|
|
22206
|
-
for (const
|
|
22207
|
-
|
|
22206
|
+
for (const reader2 of readQueue) {
|
|
22207
|
+
reader2.resolve(void 0);
|
|
22208
22208
|
}
|
|
22209
22209
|
readQueue.length = 0;
|
|
22210
22210
|
});
|
|
22211
22211
|
this.on("abort", (err) => {
|
|
22212
22212
|
done = true;
|
|
22213
|
-
for (const
|
|
22214
|
-
|
|
22213
|
+
for (const reader2 of readQueue) {
|
|
22214
|
+
reader2.reject(err);
|
|
22215
22215
|
}
|
|
22216
22216
|
readQueue.length = 0;
|
|
22217
22217
|
});
|
|
22218
22218
|
this.on("error", (err) => {
|
|
22219
22219
|
done = true;
|
|
22220
|
-
for (const
|
|
22221
|
-
|
|
22220
|
+
for (const reader2 of readQueue) {
|
|
22221
|
+
reader2.reject(err);
|
|
22222
22222
|
}
|
|
22223
22223
|
readQueue.length = 0;
|
|
22224
22224
|
});
|
|
@@ -23177,31 +23177,31 @@ var init_AssistantStream = __esm({
|
|
|
23177
23177
|
const readQueue = [];
|
|
23178
23178
|
let done = false;
|
|
23179
23179
|
this.on("event", (event) => {
|
|
23180
|
-
const
|
|
23181
|
-
if (
|
|
23182
|
-
|
|
23180
|
+
const reader2 = readQueue.shift();
|
|
23181
|
+
if (reader2) {
|
|
23182
|
+
reader2.resolve(event);
|
|
23183
23183
|
} else {
|
|
23184
23184
|
pushQueue.push(event);
|
|
23185
23185
|
}
|
|
23186
23186
|
});
|
|
23187
23187
|
this.on("end", () => {
|
|
23188
23188
|
done = true;
|
|
23189
|
-
for (const
|
|
23190
|
-
|
|
23189
|
+
for (const reader2 of readQueue) {
|
|
23190
|
+
reader2.resolve(void 0);
|
|
23191
23191
|
}
|
|
23192
23192
|
readQueue.length = 0;
|
|
23193
23193
|
});
|
|
23194
23194
|
this.on("abort", (err) => {
|
|
23195
23195
|
done = true;
|
|
23196
|
-
for (const
|
|
23197
|
-
|
|
23196
|
+
for (const reader2 of readQueue) {
|
|
23197
|
+
reader2.reject(err);
|
|
23198
23198
|
}
|
|
23199
23199
|
readQueue.length = 0;
|
|
23200
23200
|
});
|
|
23201
23201
|
this.on("error", (err) => {
|
|
23202
23202
|
done = true;
|
|
23203
|
-
for (const
|
|
23204
|
-
|
|
23203
|
+
for (const reader2 of readQueue) {
|
|
23204
|
+
reader2.reject(err);
|
|
23205
23205
|
}
|
|
23206
23206
|
readQueue.length = 0;
|
|
23207
23207
|
});
|
|
@@ -25466,31 +25466,31 @@ var init_ResponseStream = __esm({
|
|
|
25466
25466
|
const readQueue = [];
|
|
25467
25467
|
let done = false;
|
|
25468
25468
|
this.on("event", (event) => {
|
|
25469
|
-
const
|
|
25470
|
-
if (
|
|
25471
|
-
|
|
25469
|
+
const reader2 = readQueue.shift();
|
|
25470
|
+
if (reader2) {
|
|
25471
|
+
reader2.resolve(event);
|
|
25472
25472
|
} else {
|
|
25473
25473
|
pushQueue.push(event);
|
|
25474
25474
|
}
|
|
25475
25475
|
});
|
|
25476
25476
|
this.on("end", () => {
|
|
25477
25477
|
done = true;
|
|
25478
|
-
for (const
|
|
25479
|
-
|
|
25478
|
+
for (const reader2 of readQueue) {
|
|
25479
|
+
reader2.resolve(void 0);
|
|
25480
25480
|
}
|
|
25481
25481
|
readQueue.length = 0;
|
|
25482
25482
|
});
|
|
25483
25483
|
this.on("abort", (err) => {
|
|
25484
25484
|
done = true;
|
|
25485
|
-
for (const
|
|
25486
|
-
|
|
25485
|
+
for (const reader2 of readQueue) {
|
|
25486
|
+
reader2.reject(err);
|
|
25487
25487
|
}
|
|
25488
25488
|
readQueue.length = 0;
|
|
25489
25489
|
});
|
|
25490
25490
|
this.on("error", (err) => {
|
|
25491
25491
|
done = true;
|
|
25492
|
-
for (const
|
|
25493
|
-
|
|
25492
|
+
for (const reader2 of readQueue) {
|
|
25493
|
+
reader2.reject(err);
|
|
25494
25494
|
}
|
|
25495
25495
|
readQueue.length = 0;
|
|
25496
25496
|
});
|
|
@@ -46206,22 +46206,22 @@ function ReadableStreamFrom2(iterable) {
|
|
|
46206
46206
|
function ReadableStreamToAsyncIterable2(stream2) {
|
|
46207
46207
|
if (stream2[Symbol.asyncIterator])
|
|
46208
46208
|
return stream2;
|
|
46209
|
-
const
|
|
46209
|
+
const reader2 = stream2.getReader();
|
|
46210
46210
|
return {
|
|
46211
46211
|
async next() {
|
|
46212
46212
|
try {
|
|
46213
|
-
const result = await
|
|
46213
|
+
const result = await reader2.read();
|
|
46214
46214
|
if (result?.done)
|
|
46215
|
-
|
|
46215
|
+
reader2.releaseLock();
|
|
46216
46216
|
return result;
|
|
46217
46217
|
} catch (e2) {
|
|
46218
|
-
|
|
46218
|
+
reader2.releaseLock();
|
|
46219
46219
|
throw e2;
|
|
46220
46220
|
}
|
|
46221
46221
|
},
|
|
46222
46222
|
async return() {
|
|
46223
|
-
const cancelPromise =
|
|
46224
|
-
|
|
46223
|
+
const cancelPromise = reader2.cancel();
|
|
46224
|
+
reader2.releaseLock();
|
|
46225
46225
|
await cancelPromise;
|
|
46226
46226
|
return { done: true, value: void 0 };
|
|
46227
46227
|
},
|
|
@@ -46237,9 +46237,9 @@ async function CancelReadableStream2(stream2) {
|
|
|
46237
46237
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
46238
46238
|
return;
|
|
46239
46239
|
}
|
|
46240
|
-
const
|
|
46241
|
-
const cancelPromise =
|
|
46242
|
-
|
|
46240
|
+
const reader2 = stream2.getReader();
|
|
46241
|
+
const cancelPromise = reader2.cancel();
|
|
46242
|
+
reader2.releaseLock();
|
|
46243
46243
|
await cancelPromise;
|
|
46244
46244
|
}
|
|
46245
46245
|
var init_shims2 = __esm({
|
|
@@ -49266,31 +49266,31 @@ var init_BetaMessageStream = __esm({
|
|
|
49266
49266
|
const readQueue = [];
|
|
49267
49267
|
let done = false;
|
|
49268
49268
|
this.on("streamEvent", (event) => {
|
|
49269
|
-
const
|
|
49270
|
-
if (
|
|
49271
|
-
|
|
49269
|
+
const reader2 = readQueue.shift();
|
|
49270
|
+
if (reader2) {
|
|
49271
|
+
reader2.resolve(event);
|
|
49272
49272
|
} else {
|
|
49273
49273
|
pushQueue.push(event);
|
|
49274
49274
|
}
|
|
49275
49275
|
});
|
|
49276
49276
|
this.on("end", () => {
|
|
49277
49277
|
done = true;
|
|
49278
|
-
for (const
|
|
49279
|
-
|
|
49278
|
+
for (const reader2 of readQueue) {
|
|
49279
|
+
reader2.resolve(void 0);
|
|
49280
49280
|
}
|
|
49281
49281
|
readQueue.length = 0;
|
|
49282
49282
|
});
|
|
49283
49283
|
this.on("abort", (err) => {
|
|
49284
49284
|
done = true;
|
|
49285
|
-
for (const
|
|
49286
|
-
|
|
49285
|
+
for (const reader2 of readQueue) {
|
|
49286
|
+
reader2.reject(err);
|
|
49287
49287
|
}
|
|
49288
49288
|
readQueue.length = 0;
|
|
49289
49289
|
});
|
|
49290
49290
|
this.on("error", (err) => {
|
|
49291
49291
|
done = true;
|
|
49292
|
-
for (const
|
|
49293
|
-
|
|
49292
|
+
for (const reader2 of readQueue) {
|
|
49293
|
+
reader2.reject(err);
|
|
49294
49294
|
}
|
|
49295
49295
|
readQueue.length = 0;
|
|
49296
49296
|
});
|
|
@@ -51702,31 +51702,31 @@ var init_MessageStream = __esm({
|
|
|
51702
51702
|
const readQueue = [];
|
|
51703
51703
|
let done = false;
|
|
51704
51704
|
this.on("streamEvent", (event) => {
|
|
51705
|
-
const
|
|
51706
|
-
if (
|
|
51707
|
-
|
|
51705
|
+
const reader2 = readQueue.shift();
|
|
51706
|
+
if (reader2) {
|
|
51707
|
+
reader2.resolve(event);
|
|
51708
51708
|
} else {
|
|
51709
51709
|
pushQueue.push(event);
|
|
51710
51710
|
}
|
|
51711
51711
|
});
|
|
51712
51712
|
this.on("end", () => {
|
|
51713
51713
|
done = true;
|
|
51714
|
-
for (const
|
|
51715
|
-
|
|
51714
|
+
for (const reader2 of readQueue) {
|
|
51715
|
+
reader2.resolve(void 0);
|
|
51716
51716
|
}
|
|
51717
51717
|
readQueue.length = 0;
|
|
51718
51718
|
});
|
|
51719
51719
|
this.on("abort", (err) => {
|
|
51720
51720
|
done = true;
|
|
51721
|
-
for (const
|
|
51722
|
-
|
|
51721
|
+
for (const reader2 of readQueue) {
|
|
51722
|
+
reader2.reject(err);
|
|
51723
51723
|
}
|
|
51724
51724
|
readQueue.length = 0;
|
|
51725
51725
|
});
|
|
51726
51726
|
this.on("error", (err) => {
|
|
51727
51727
|
done = true;
|
|
51728
|
-
for (const
|
|
51729
|
-
|
|
51728
|
+
for (const reader2 of readQueue) {
|
|
51729
|
+
reader2.reject(err);
|
|
51730
51730
|
}
|
|
51731
51731
|
readQueue.length = 0;
|
|
51732
51732
|
});
|
|
@@ -53396,7 +53396,7 @@ function consumeLine(text2) {
|
|
|
53396
53396
|
};
|
|
53397
53397
|
}
|
|
53398
53398
|
async function* iterateSseMessages(body, signal) {
|
|
53399
|
-
const
|
|
53399
|
+
const reader2 = body.getReader();
|
|
53400
53400
|
const decoder = new TextDecoder();
|
|
53401
53401
|
const state = { event: null, data: [], raw: [] };
|
|
53402
53402
|
let buffer = "";
|
|
@@ -53405,7 +53405,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
53405
53405
|
if (signal?.aborted) {
|
|
53406
53406
|
throw new Error("Request was aborted");
|
|
53407
53407
|
}
|
|
53408
|
-
const { value, done } = await
|
|
53408
|
+
const { value, done } = await reader2.read();
|
|
53409
53409
|
if (done) {
|
|
53410
53410
|
break;
|
|
53411
53411
|
}
|
|
@@ -53441,7 +53441,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
53441
53441
|
yield trailingEvent;
|
|
53442
53442
|
}
|
|
53443
53443
|
} finally {
|
|
53444
|
-
|
|
53444
|
+
reader2.releaseLock();
|
|
53445
53445
|
}
|
|
53446
53446
|
}
|
|
53447
53447
|
async function* iterateAnthropicEvents(response, signal) {
|
|
@@ -56284,7 +56284,7 @@ var require_supports_color = __commonJS({
|
|
|
56284
56284
|
return 1;
|
|
56285
56285
|
}
|
|
56286
56286
|
if ("CI" in env2) {
|
|
56287
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((
|
|
56287
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign2) => sign2 in env2) || env2.CI_NAME === "codeship") {
|
|
56288
56288
|
return 1;
|
|
56289
56289
|
}
|
|
56290
56290
|
return min;
|
|
@@ -57213,68 +57213,68 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57213
57213
|
const CancelSteps = /* @__PURE__ */ Symbol("[[CancelSteps]]");
|
|
57214
57214
|
const PullSteps = /* @__PURE__ */ Symbol("[[PullSteps]]");
|
|
57215
57215
|
const ReleaseSteps = /* @__PURE__ */ Symbol("[[ReleaseSteps]]");
|
|
57216
|
-
function ReadableStreamReaderGenericInitialize(
|
|
57217
|
-
|
|
57218
|
-
stream2._reader =
|
|
57216
|
+
function ReadableStreamReaderGenericInitialize(reader2, stream2) {
|
|
57217
|
+
reader2._ownerReadableStream = stream2;
|
|
57218
|
+
stream2._reader = reader2;
|
|
57219
57219
|
if (stream2._state === "readable") {
|
|
57220
|
-
defaultReaderClosedPromiseInitialize(
|
|
57220
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57221
57221
|
} else if (stream2._state === "closed") {
|
|
57222
|
-
defaultReaderClosedPromiseInitializeAsResolved(
|
|
57222
|
+
defaultReaderClosedPromiseInitializeAsResolved(reader2);
|
|
57223
57223
|
} else {
|
|
57224
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
57224
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, stream2._storedError);
|
|
57225
57225
|
}
|
|
57226
57226
|
}
|
|
57227
|
-
function ReadableStreamReaderGenericCancel(
|
|
57228
|
-
const stream2 =
|
|
57227
|
+
function ReadableStreamReaderGenericCancel(reader2, reason) {
|
|
57228
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57229
57229
|
return ReadableStreamCancel(stream2, reason);
|
|
57230
57230
|
}
|
|
57231
|
-
function ReadableStreamReaderGenericRelease(
|
|
57232
|
-
const stream2 =
|
|
57231
|
+
function ReadableStreamReaderGenericRelease(reader2) {
|
|
57232
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57233
57233
|
if (stream2._state === "readable") {
|
|
57234
|
-
defaultReaderClosedPromiseReject(
|
|
57234
|
+
defaultReaderClosedPromiseReject(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
57235
57235
|
} else {
|
|
57236
|
-
defaultReaderClosedPromiseResetToRejected(
|
|
57236
|
+
defaultReaderClosedPromiseResetToRejected(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
57237
57237
|
}
|
|
57238
57238
|
stream2._readableStreamController[ReleaseSteps]();
|
|
57239
57239
|
stream2._reader = void 0;
|
|
57240
|
-
|
|
57240
|
+
reader2._ownerReadableStream = void 0;
|
|
57241
57241
|
}
|
|
57242
57242
|
function readerLockException(name) {
|
|
57243
57243
|
return new TypeError("Cannot " + name + " a stream using a released reader");
|
|
57244
57244
|
}
|
|
57245
|
-
function defaultReaderClosedPromiseInitialize(
|
|
57246
|
-
|
|
57247
|
-
|
|
57248
|
-
|
|
57245
|
+
function defaultReaderClosedPromiseInitialize(reader2) {
|
|
57246
|
+
reader2._closedPromise = newPromise((resolve2, reject) => {
|
|
57247
|
+
reader2._closedPromise_resolve = resolve2;
|
|
57248
|
+
reader2._closedPromise_reject = reject;
|
|
57249
57249
|
});
|
|
57250
57250
|
}
|
|
57251
|
-
function defaultReaderClosedPromiseInitializeAsRejected(
|
|
57252
|
-
defaultReaderClosedPromiseInitialize(
|
|
57253
|
-
defaultReaderClosedPromiseReject(
|
|
57251
|
+
function defaultReaderClosedPromiseInitializeAsRejected(reader2, reason) {
|
|
57252
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57253
|
+
defaultReaderClosedPromiseReject(reader2, reason);
|
|
57254
57254
|
}
|
|
57255
|
-
function defaultReaderClosedPromiseInitializeAsResolved(
|
|
57256
|
-
defaultReaderClosedPromiseInitialize(
|
|
57257
|
-
defaultReaderClosedPromiseResolve(
|
|
57255
|
+
function defaultReaderClosedPromiseInitializeAsResolved(reader2) {
|
|
57256
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
57257
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
57258
57258
|
}
|
|
57259
|
-
function defaultReaderClosedPromiseReject(
|
|
57260
|
-
if (
|
|
57259
|
+
function defaultReaderClosedPromiseReject(reader2, reason) {
|
|
57260
|
+
if (reader2._closedPromise_reject === void 0) {
|
|
57261
57261
|
return;
|
|
57262
57262
|
}
|
|
57263
|
-
setPromiseIsHandledToTrue(
|
|
57264
|
-
|
|
57265
|
-
|
|
57266
|
-
|
|
57263
|
+
setPromiseIsHandledToTrue(reader2._closedPromise);
|
|
57264
|
+
reader2._closedPromise_reject(reason);
|
|
57265
|
+
reader2._closedPromise_resolve = void 0;
|
|
57266
|
+
reader2._closedPromise_reject = void 0;
|
|
57267
57267
|
}
|
|
57268
|
-
function defaultReaderClosedPromiseResetToRejected(
|
|
57269
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
57268
|
+
function defaultReaderClosedPromiseResetToRejected(reader2, reason) {
|
|
57269
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, reason);
|
|
57270
57270
|
}
|
|
57271
|
-
function defaultReaderClosedPromiseResolve(
|
|
57272
|
-
if (
|
|
57271
|
+
function defaultReaderClosedPromiseResolve(reader2) {
|
|
57272
|
+
if (reader2._closedPromise_resolve === void 0) {
|
|
57273
57273
|
return;
|
|
57274
57274
|
}
|
|
57275
|
-
|
|
57276
|
-
|
|
57277
|
-
|
|
57275
|
+
reader2._closedPromise_resolve(void 0);
|
|
57276
|
+
reader2._closedPromise_resolve = void 0;
|
|
57277
|
+
reader2._closedPromise_reject = void 0;
|
|
57278
57278
|
}
|
|
57279
57279
|
const NumberIsFinite = Number.isFinite || function(x2) {
|
|
57280
57280
|
return typeof x2 === "number" && isFinite(x2);
|
|
@@ -57351,8 +57351,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57351
57351
|
stream2._reader._readRequests.push(readRequest);
|
|
57352
57352
|
}
|
|
57353
57353
|
function ReadableStreamFulfillReadRequest(stream2, chunk, done) {
|
|
57354
|
-
const
|
|
57355
|
-
const readRequest =
|
|
57354
|
+
const reader2 = stream2._reader;
|
|
57355
|
+
const readRequest = reader2._readRequests.shift();
|
|
57356
57356
|
if (done) {
|
|
57357
57357
|
readRequest._closeSteps();
|
|
57358
57358
|
} else {
|
|
@@ -57363,11 +57363,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57363
57363
|
return stream2._reader._readRequests.length;
|
|
57364
57364
|
}
|
|
57365
57365
|
function ReadableStreamHasDefaultReader(stream2) {
|
|
57366
|
-
const
|
|
57367
|
-
if (
|
|
57366
|
+
const reader2 = stream2._reader;
|
|
57367
|
+
if (reader2 === void 0) {
|
|
57368
57368
|
return false;
|
|
57369
57369
|
}
|
|
57370
|
-
if (!IsReadableStreamDefaultReader(
|
|
57370
|
+
if (!IsReadableStreamDefaultReader(reader2)) {
|
|
57371
57371
|
return false;
|
|
57372
57372
|
}
|
|
57373
57373
|
return true;
|
|
@@ -57473,8 +57473,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57473
57473
|
}
|
|
57474
57474
|
return x2 instanceof ReadableStreamDefaultReader;
|
|
57475
57475
|
}
|
|
57476
|
-
function ReadableStreamDefaultReaderRead(
|
|
57477
|
-
const stream2 =
|
|
57476
|
+
function ReadableStreamDefaultReaderRead(reader2, readRequest) {
|
|
57477
|
+
const stream2 = reader2._ownerReadableStream;
|
|
57478
57478
|
stream2._disturbed = true;
|
|
57479
57479
|
if (stream2._state === "closed") {
|
|
57480
57480
|
readRequest._closeSteps();
|
|
@@ -57484,14 +57484,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57484
57484
|
stream2._readableStreamController[PullSteps](readRequest);
|
|
57485
57485
|
}
|
|
57486
57486
|
}
|
|
57487
|
-
function ReadableStreamDefaultReaderRelease(
|
|
57488
|
-
ReadableStreamReaderGenericRelease(
|
|
57487
|
+
function ReadableStreamDefaultReaderRelease(reader2) {
|
|
57488
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57489
57489
|
const e2 = new TypeError("Reader was released");
|
|
57490
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
57490
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e2);
|
|
57491
57491
|
}
|
|
57492
|
-
function ReadableStreamDefaultReaderErrorReadRequests(
|
|
57493
|
-
const readRequests =
|
|
57494
|
-
|
|
57492
|
+
function ReadableStreamDefaultReaderErrorReadRequests(reader2, e2) {
|
|
57493
|
+
const readRequests = reader2._readRequests;
|
|
57494
|
+
reader2._readRequests = new SimpleQueue();
|
|
57495
57495
|
readRequests.forEach((readRequest) => {
|
|
57496
57496
|
readRequest._errorSteps(e2);
|
|
57497
57497
|
});
|
|
@@ -57502,10 +57502,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57502
57502
|
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
|
|
57503
57503
|
}).prototype);
|
|
57504
57504
|
class ReadableStreamAsyncIteratorImpl {
|
|
57505
|
-
constructor(
|
|
57505
|
+
constructor(reader2, preventCancel) {
|
|
57506
57506
|
this._ongoingPromise = void 0;
|
|
57507
57507
|
this._isFinished = false;
|
|
57508
|
-
this._reader =
|
|
57508
|
+
this._reader = reader2;
|
|
57509
57509
|
this._preventCancel = preventCancel;
|
|
57510
57510
|
}
|
|
57511
57511
|
next() {
|
|
@@ -57521,7 +57521,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57521
57521
|
if (this._isFinished) {
|
|
57522
57522
|
return Promise.resolve({ value: void 0, done: true });
|
|
57523
57523
|
}
|
|
57524
|
-
const
|
|
57524
|
+
const reader2 = this._reader;
|
|
57525
57525
|
let resolvePromise;
|
|
57526
57526
|
let rejectPromise;
|
|
57527
57527
|
const promise = newPromise((resolve2, reject) => {
|
|
@@ -57536,17 +57536,17 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57536
57536
|
_closeSteps: () => {
|
|
57537
57537
|
this._ongoingPromise = void 0;
|
|
57538
57538
|
this._isFinished = true;
|
|
57539
|
-
ReadableStreamReaderGenericRelease(
|
|
57539
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57540
57540
|
resolvePromise({ value: void 0, done: true });
|
|
57541
57541
|
},
|
|
57542
57542
|
_errorSteps: (reason) => {
|
|
57543
57543
|
this._ongoingPromise = void 0;
|
|
57544
57544
|
this._isFinished = true;
|
|
57545
|
-
ReadableStreamReaderGenericRelease(
|
|
57545
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57546
57546
|
rejectPromise(reason);
|
|
57547
57547
|
}
|
|
57548
57548
|
};
|
|
57549
|
-
ReadableStreamDefaultReaderRead(
|
|
57549
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
57550
57550
|
return promise;
|
|
57551
57551
|
}
|
|
57552
57552
|
_returnSteps(value) {
|
|
@@ -57554,13 +57554,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57554
57554
|
return Promise.resolve({ value, done: true });
|
|
57555
57555
|
}
|
|
57556
57556
|
this._isFinished = true;
|
|
57557
|
-
const
|
|
57557
|
+
const reader2 = this._reader;
|
|
57558
57558
|
if (!this._preventCancel) {
|
|
57559
|
-
const result = ReadableStreamReaderGenericCancel(
|
|
57560
|
-
ReadableStreamReaderGenericRelease(
|
|
57559
|
+
const result = ReadableStreamReaderGenericCancel(reader2, value);
|
|
57560
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57561
57561
|
return transformPromiseWith(result, () => ({ value, done: true }));
|
|
57562
57562
|
}
|
|
57563
|
-
ReadableStreamReaderGenericRelease(
|
|
57563
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
57564
57564
|
return promiseResolvedWith({ value, done: true });
|
|
57565
57565
|
}
|
|
57566
57566
|
}
|
|
@@ -57580,8 +57580,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
57580
57580
|
};
|
|
57581
57581
|
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
|
57582
57582
|
function AcquireReadableStreamAsyncIterator(stream2, preventCancel) {
|
|
57583
|
-
const
|
|
57584
|
-
const impl = new ReadableStreamAsyncIteratorImpl(
|
|
57583
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
57584
|
+
const impl = new ReadableStreamAsyncIteratorImpl(reader2, preventCancel);
|
|
57585
57585
|
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
57586
57586
|
iterator._asyncIteratorImpl = impl;
|
|
57587
57587
|
return iterator;
|
|
@@ -58085,12 +58085,12 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58085
58085
|
}
|
|
58086
58086
|
}
|
|
58087
58087
|
function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
|
|
58088
|
-
const
|
|
58089
|
-
while (
|
|
58088
|
+
const reader2 = controller._controlledReadableByteStream._reader;
|
|
58089
|
+
while (reader2._readRequests.length > 0) {
|
|
58090
58090
|
if (controller._queueTotalSize === 0) {
|
|
58091
58091
|
return;
|
|
58092
58092
|
}
|
|
58093
|
-
const readRequest =
|
|
58093
|
+
const readRequest = reader2._readRequests.shift();
|
|
58094
58094
|
ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
|
|
58095
58095
|
}
|
|
58096
58096
|
}
|
|
@@ -58450,8 +58450,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58450
58450
|
stream2._reader._readIntoRequests.push(readIntoRequest);
|
|
58451
58451
|
}
|
|
58452
58452
|
function ReadableStreamFulfillReadIntoRequest(stream2, chunk, done) {
|
|
58453
|
-
const
|
|
58454
|
-
const readIntoRequest =
|
|
58453
|
+
const reader2 = stream2._reader;
|
|
58454
|
+
const readIntoRequest = reader2._readIntoRequests.shift();
|
|
58455
58455
|
if (done) {
|
|
58456
58456
|
readIntoRequest._closeSteps(chunk);
|
|
58457
58457
|
} else {
|
|
@@ -58462,11 +58462,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58462
58462
|
return stream2._reader._readIntoRequests.length;
|
|
58463
58463
|
}
|
|
58464
58464
|
function ReadableStreamHasBYOBReader(stream2) {
|
|
58465
|
-
const
|
|
58466
|
-
if (
|
|
58465
|
+
const reader2 = stream2._reader;
|
|
58466
|
+
if (reader2 === void 0) {
|
|
58467
58467
|
return false;
|
|
58468
58468
|
}
|
|
58469
|
-
if (!IsReadableStreamBYOBReader(
|
|
58469
|
+
if (!IsReadableStreamBYOBReader(reader2)) {
|
|
58470
58470
|
return false;
|
|
58471
58471
|
}
|
|
58472
58472
|
return true;
|
|
@@ -58599,8 +58599,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58599
58599
|
}
|
|
58600
58600
|
return x2 instanceof ReadableStreamBYOBReader;
|
|
58601
58601
|
}
|
|
58602
|
-
function ReadableStreamBYOBReaderRead(
|
|
58603
|
-
const stream2 =
|
|
58602
|
+
function ReadableStreamBYOBReaderRead(reader2, view, min, readIntoRequest) {
|
|
58603
|
+
const stream2 = reader2._ownerReadableStream;
|
|
58604
58604
|
stream2._disturbed = true;
|
|
58605
58605
|
if (stream2._state === "errored") {
|
|
58606
58606
|
readIntoRequest._errorSteps(stream2._storedError);
|
|
@@ -58608,14 +58608,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
58608
58608
|
ReadableByteStreamControllerPullInto(stream2._readableStreamController, view, min, readIntoRequest);
|
|
58609
58609
|
}
|
|
58610
58610
|
}
|
|
58611
|
-
function ReadableStreamBYOBReaderRelease(
|
|
58612
|
-
ReadableStreamReaderGenericRelease(
|
|
58611
|
+
function ReadableStreamBYOBReaderRelease(reader2) {
|
|
58612
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
58613
58613
|
const e2 = new TypeError("Reader was released");
|
|
58614
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
58614
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2);
|
|
58615
58615
|
}
|
|
58616
|
-
function ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
58617
|
-
const readIntoRequests =
|
|
58618
|
-
|
|
58616
|
+
function ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2) {
|
|
58617
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
58618
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
58619
58619
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
58620
58620
|
readIntoRequest._errorSteps(e2);
|
|
58621
58621
|
});
|
|
@@ -59630,7 +59630,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59630
59630
|
}
|
|
59631
59631
|
const DOMException3 = getFromGlobal() || createPolyfill();
|
|
59632
59632
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
59633
|
-
const
|
|
59633
|
+
const reader2 = AcquireReadableStreamDefaultReader(source);
|
|
59634
59634
|
const writer = AcquireWritableStreamDefaultWriter(dest);
|
|
59635
59635
|
source._disturbed = true;
|
|
59636
59636
|
let shuttingDown = false;
|
|
@@ -59683,7 +59683,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59683
59683
|
}
|
|
59684
59684
|
return PerformPromiseThen(writer._readyPromise, () => {
|
|
59685
59685
|
return newPromise((resolveRead, rejectRead) => {
|
|
59686
|
-
ReadableStreamDefaultReaderRead(
|
|
59686
|
+
ReadableStreamDefaultReaderRead(reader2, {
|
|
59687
59687
|
_chunkSteps: (chunk) => {
|
|
59688
59688
|
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop5);
|
|
59689
59689
|
resolveRead(false);
|
|
@@ -59694,7 +59694,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59694
59694
|
});
|
|
59695
59695
|
});
|
|
59696
59696
|
}
|
|
59697
|
-
isOrBecomesErrored(source,
|
|
59697
|
+
isOrBecomesErrored(source, reader2._closedPromise, (storedError) => {
|
|
59698
59698
|
if (!preventAbort) {
|
|
59699
59699
|
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
|
59700
59700
|
} else {
|
|
@@ -59710,7 +59710,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59710
59710
|
}
|
|
59711
59711
|
return null;
|
|
59712
59712
|
});
|
|
59713
|
-
isOrBecomesClosed(source,
|
|
59713
|
+
isOrBecomesClosed(source, reader2._closedPromise, () => {
|
|
59714
59714
|
if (!preventClose) {
|
|
59715
59715
|
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
|
59716
59716
|
} else {
|
|
@@ -59773,7 +59773,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
59773
59773
|
}
|
|
59774
59774
|
function finalize(isError, error) {
|
|
59775
59775
|
WritableStreamDefaultWriterRelease(writer);
|
|
59776
|
-
ReadableStreamReaderGenericRelease(
|
|
59776
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
59777
59777
|
if (signal !== void 0) {
|
|
59778
59778
|
signal.removeEventListener("abort", abortAlgorithm);
|
|
59779
59779
|
}
|
|
@@ -60051,7 +60051,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60051
60051
|
return ReadableStreamDefaultTee(stream2);
|
|
60052
60052
|
}
|
|
60053
60053
|
function ReadableStreamDefaultTee(stream2, cloneForBranch2) {
|
|
60054
|
-
const
|
|
60054
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60055
60055
|
let reading = false;
|
|
60056
60056
|
let readAgain = false;
|
|
60057
60057
|
let canceled1 = false;
|
|
@@ -60104,7 +60104,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60104
60104
|
reading = false;
|
|
60105
60105
|
}
|
|
60106
60106
|
};
|
|
60107
|
-
ReadableStreamDefaultReaderRead(
|
|
60107
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
60108
60108
|
return promiseResolvedWith(void 0);
|
|
60109
60109
|
}
|
|
60110
60110
|
function cancel1Algorithm(reason) {
|
|
@@ -60131,7 +60131,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60131
60131
|
}
|
|
60132
60132
|
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
60133
60133
|
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
60134
|
-
uponRejection(
|
|
60134
|
+
uponRejection(reader2._closedPromise, (r2) => {
|
|
60135
60135
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r2);
|
|
60136
60136
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r2);
|
|
60137
60137
|
if (!canceled1 || !canceled2) {
|
|
@@ -60142,7 +60142,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60142
60142
|
return [branch1, branch2];
|
|
60143
60143
|
}
|
|
60144
60144
|
function ReadableByteStreamTee(stream2) {
|
|
60145
|
-
let
|
|
60145
|
+
let reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60146
60146
|
let reading = false;
|
|
60147
60147
|
let readAgainForBranch1 = false;
|
|
60148
60148
|
let readAgainForBranch2 = false;
|
|
@@ -60158,7 +60158,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60158
60158
|
});
|
|
60159
60159
|
function forwardReaderError(thisReader) {
|
|
60160
60160
|
uponRejection(thisReader._closedPromise, (r2) => {
|
|
60161
|
-
if (thisReader !==
|
|
60161
|
+
if (thisReader !== reader2) {
|
|
60162
60162
|
return null;
|
|
60163
60163
|
}
|
|
60164
60164
|
ReadableByteStreamControllerError(branch1._readableStreamController, r2);
|
|
@@ -60170,10 +60170,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60170
60170
|
});
|
|
60171
60171
|
}
|
|
60172
60172
|
function pullWithDefaultReader() {
|
|
60173
|
-
if (IsReadableStreamBYOBReader(
|
|
60174
|
-
ReadableStreamReaderGenericRelease(
|
|
60175
|
-
|
|
60176
|
-
forwardReaderError(
|
|
60173
|
+
if (IsReadableStreamBYOBReader(reader2)) {
|
|
60174
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
60175
|
+
reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
60176
|
+
forwardReaderError(reader2);
|
|
60177
60177
|
}
|
|
60178
60178
|
const readRequest = {
|
|
60179
60179
|
_chunkSteps: (chunk) => {
|
|
@@ -60228,13 +60228,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60228
60228
|
reading = false;
|
|
60229
60229
|
}
|
|
60230
60230
|
};
|
|
60231
|
-
ReadableStreamDefaultReaderRead(
|
|
60231
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
60232
60232
|
}
|
|
60233
60233
|
function pullWithBYOBReader(view, forBranch2) {
|
|
60234
|
-
if (IsReadableStreamDefaultReader(
|
|
60235
|
-
ReadableStreamReaderGenericRelease(
|
|
60236
|
-
|
|
60237
|
-
forwardReaderError(
|
|
60234
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60235
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
60236
|
+
reader2 = AcquireReadableStreamBYOBReader(stream2);
|
|
60237
|
+
forwardReaderError(reader2);
|
|
60238
60238
|
}
|
|
60239
60239
|
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
60240
60240
|
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
@@ -60296,7 +60296,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60296
60296
|
reading = false;
|
|
60297
60297
|
}
|
|
60298
60298
|
};
|
|
60299
|
-
ReadableStreamBYOBReaderRead(
|
|
60299
|
+
ReadableStreamBYOBReaderRead(reader2, view, 1, readIntoRequest);
|
|
60300
60300
|
}
|
|
60301
60301
|
function pull1Algorithm() {
|
|
60302
60302
|
if (reading) {
|
|
@@ -60351,7 +60351,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60351
60351
|
}
|
|
60352
60352
|
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
60353
60353
|
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
60354
|
-
forwardReaderError(
|
|
60354
|
+
forwardReaderError(reader2);
|
|
60355
60355
|
return [branch1, branch2];
|
|
60356
60356
|
}
|
|
60357
60357
|
function isReadableStreamLike(stream2) {
|
|
@@ -60416,13 +60416,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60416
60416
|
stream2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
|
60417
60417
|
return stream2;
|
|
60418
60418
|
}
|
|
60419
|
-
function ReadableStreamFromDefaultReader(
|
|
60419
|
+
function ReadableStreamFromDefaultReader(reader2) {
|
|
60420
60420
|
let stream2;
|
|
60421
60421
|
const startAlgorithm = noop5;
|
|
60422
60422
|
function pullAlgorithm() {
|
|
60423
60423
|
let readPromise;
|
|
60424
60424
|
try {
|
|
60425
|
-
readPromise =
|
|
60425
|
+
readPromise = reader2.read();
|
|
60426
60426
|
} catch (e2) {
|
|
60427
60427
|
return promiseRejectedWith(e2);
|
|
60428
60428
|
}
|
|
@@ -60440,7 +60440,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60440
60440
|
}
|
|
60441
60441
|
function cancelAlgorithm(reason) {
|
|
60442
60442
|
try {
|
|
60443
|
-
return promiseResolvedWith(
|
|
60443
|
+
return promiseResolvedWith(reader2.cancel(reason));
|
|
60444
60444
|
} catch (e2) {
|
|
60445
60445
|
return promiseRejectedWith(e2);
|
|
60446
60446
|
}
|
|
@@ -60728,10 +60728,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60728
60728
|
return promiseRejectedWith(stream2._storedError);
|
|
60729
60729
|
}
|
|
60730
60730
|
ReadableStreamClose(stream2);
|
|
60731
|
-
const
|
|
60732
|
-
if (
|
|
60733
|
-
const readIntoRequests =
|
|
60734
|
-
|
|
60731
|
+
const reader2 = stream2._reader;
|
|
60732
|
+
if (reader2 !== void 0 && IsReadableStreamBYOBReader(reader2)) {
|
|
60733
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
60734
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
60735
60735
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
60736
60736
|
readIntoRequest._closeSteps(void 0);
|
|
60737
60737
|
});
|
|
@@ -60741,14 +60741,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60741
60741
|
}
|
|
60742
60742
|
function ReadableStreamClose(stream2) {
|
|
60743
60743
|
stream2._state = "closed";
|
|
60744
|
-
const
|
|
60745
|
-
if (
|
|
60744
|
+
const reader2 = stream2._reader;
|
|
60745
|
+
if (reader2 === void 0) {
|
|
60746
60746
|
return;
|
|
60747
60747
|
}
|
|
60748
|
-
defaultReaderClosedPromiseResolve(
|
|
60749
|
-
if (IsReadableStreamDefaultReader(
|
|
60750
|
-
const readRequests =
|
|
60751
|
-
|
|
60748
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
60749
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60750
|
+
const readRequests = reader2._readRequests;
|
|
60751
|
+
reader2._readRequests = new SimpleQueue();
|
|
60752
60752
|
readRequests.forEach((readRequest) => {
|
|
60753
60753
|
readRequest._closeSteps();
|
|
60754
60754
|
});
|
|
@@ -60757,15 +60757,15 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
60757
60757
|
function ReadableStreamError(stream2, e2) {
|
|
60758
60758
|
stream2._state = "errored";
|
|
60759
60759
|
stream2._storedError = e2;
|
|
60760
|
-
const
|
|
60761
|
-
if (
|
|
60760
|
+
const reader2 = stream2._reader;
|
|
60761
|
+
if (reader2 === void 0) {
|
|
60762
60762
|
return;
|
|
60763
60763
|
}
|
|
60764
|
-
defaultReaderClosedPromiseReject(
|
|
60765
|
-
if (IsReadableStreamDefaultReader(
|
|
60766
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
60764
|
+
defaultReaderClosedPromiseReject(reader2, e2);
|
|
60765
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
60766
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e2);
|
|
60767
60767
|
} else {
|
|
60768
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
60768
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e2);
|
|
60769
60769
|
}
|
|
60770
60770
|
}
|
|
60771
60771
|
function streamBrandCheckException$1(name) {
|
|
@@ -64405,7 +64405,7 @@ var require_bignumber = __commonJS({
|
|
|
64405
64405
|
}
|
|
64406
64406
|
return arr.reverse();
|
|
64407
64407
|
}
|
|
64408
|
-
return function(str2, baseIn, baseOut,
|
|
64408
|
+
return function(str2, baseIn, baseOut, sign2, callerIsToString) {
|
|
64409
64409
|
var alphabet, d, e2, k, r2, x2, xc, y, i2 = str2.indexOf("."), dp = DECIMAL_PLACES, rm2 = ROUNDING_MODE;
|
|
64410
64410
|
if (i2 >= 0) {
|
|
64411
64411
|
k = POW_PRECISION;
|
|
@@ -64431,7 +64431,7 @@ var require_bignumber = __commonJS({
|
|
|
64431
64431
|
} else {
|
|
64432
64432
|
x2.c = xc;
|
|
64433
64433
|
x2.e = e2;
|
|
64434
|
-
x2.s =
|
|
64434
|
+
x2.s = sign2;
|
|
64435
64435
|
x2 = div(x2, y, dp, rm2, baseOut);
|
|
64436
64436
|
xc = x2.c;
|
|
64437
64437
|
r2 = x2.r;
|
|
@@ -68650,7 +68650,7 @@ var require_jwa = __commonJS({
|
|
|
68650
68650
|
return thing;
|
|
68651
68651
|
}
|
|
68652
68652
|
function createHmacSigner(bits) {
|
|
68653
|
-
return function
|
|
68653
|
+
return function sign2(thing, secret) {
|
|
68654
68654
|
checkIsSecretKey(secret);
|
|
68655
68655
|
thing = normalizeInput(thing);
|
|
68656
68656
|
var hmac = crypto2.createHmac("sha" + bits, secret);
|
|
@@ -68659,25 +68659,25 @@ var require_jwa = __commonJS({
|
|
|
68659
68659
|
};
|
|
68660
68660
|
}
|
|
68661
68661
|
var bufferEqual;
|
|
68662
|
-
var
|
|
68662
|
+
var timingSafeEqual2 = "timingSafeEqual" in crypto2 ? function timingSafeEqual3(a, b) {
|
|
68663
68663
|
if (a.byteLength !== b.byteLength) {
|
|
68664
68664
|
return false;
|
|
68665
68665
|
}
|
|
68666
68666
|
return crypto2.timingSafeEqual(a, b);
|
|
68667
|
-
} : function
|
|
68667
|
+
} : function timingSafeEqual3(a, b) {
|
|
68668
68668
|
if (!bufferEqual) {
|
|
68669
68669
|
bufferEqual = require_buffer_equal_constant_time();
|
|
68670
68670
|
}
|
|
68671
68671
|
return bufferEqual(a, b);
|
|
68672
68672
|
};
|
|
68673
68673
|
function createHmacVerifier(bits) {
|
|
68674
|
-
return function
|
|
68674
|
+
return function verify2(thing, signature, secret) {
|
|
68675
68675
|
var computedSig = createHmacSigner(bits)(thing, secret);
|
|
68676
|
-
return
|
|
68676
|
+
return timingSafeEqual2(Buffer5.from(signature), Buffer5.from(computedSig));
|
|
68677
68677
|
};
|
|
68678
68678
|
}
|
|
68679
68679
|
function createKeySigner(bits) {
|
|
68680
|
-
return function
|
|
68680
|
+
return function sign2(thing, privateKey) {
|
|
68681
68681
|
checkIsPrivateKey(privateKey);
|
|
68682
68682
|
thing = normalizeInput(thing);
|
|
68683
68683
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -68686,7 +68686,7 @@ var require_jwa = __commonJS({
|
|
|
68686
68686
|
};
|
|
68687
68687
|
}
|
|
68688
68688
|
function createKeyVerifier(bits) {
|
|
68689
|
-
return function
|
|
68689
|
+
return function verify2(thing, signature, publicKey) {
|
|
68690
68690
|
checkIsPublicKey(publicKey);
|
|
68691
68691
|
thing = normalizeInput(thing);
|
|
68692
68692
|
signature = toBase64(signature);
|
|
@@ -68696,7 +68696,7 @@ var require_jwa = __commonJS({
|
|
|
68696
68696
|
};
|
|
68697
68697
|
}
|
|
68698
68698
|
function createPSSKeySigner(bits) {
|
|
68699
|
-
return function
|
|
68699
|
+
return function sign2(thing, privateKey) {
|
|
68700
68700
|
checkIsPrivateKey(privateKey);
|
|
68701
68701
|
thing = normalizeInput(thing);
|
|
68702
68702
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -68709,7 +68709,7 @@ var require_jwa = __commonJS({
|
|
|
68709
68709
|
};
|
|
68710
68710
|
}
|
|
68711
68711
|
function createPSSKeyVerifier(bits) {
|
|
68712
|
-
return function
|
|
68712
|
+
return function verify2(thing, signature, publicKey) {
|
|
68713
68713
|
checkIsPublicKey(publicKey);
|
|
68714
68714
|
thing = normalizeInput(thing);
|
|
68715
68715
|
signature = toBase64(signature);
|
|
@@ -68724,7 +68724,7 @@ var require_jwa = __commonJS({
|
|
|
68724
68724
|
}
|
|
68725
68725
|
function createECDSASigner(bits) {
|
|
68726
68726
|
var inner = createKeySigner(bits);
|
|
68727
|
-
return function
|
|
68727
|
+
return function sign2() {
|
|
68728
68728
|
var signature = inner.apply(null, arguments);
|
|
68729
68729
|
signature = formatEcdsa.derToJose(signature, "ES" + bits);
|
|
68730
68730
|
return signature;
|
|
@@ -68732,19 +68732,19 @@ var require_jwa = __commonJS({
|
|
|
68732
68732
|
}
|
|
68733
68733
|
function createECDSAVerifer(bits) {
|
|
68734
68734
|
var inner = createKeyVerifier(bits);
|
|
68735
|
-
return function
|
|
68735
|
+
return function verify2(thing, signature, publicKey) {
|
|
68736
68736
|
signature = formatEcdsa.joseToDer(signature, "ES" + bits).toString("base64");
|
|
68737
68737
|
var result = inner(thing, signature, publicKey);
|
|
68738
68738
|
return result;
|
|
68739
68739
|
};
|
|
68740
68740
|
}
|
|
68741
68741
|
function createNoneSigner() {
|
|
68742
|
-
return function
|
|
68742
|
+
return function sign2() {
|
|
68743
68743
|
return "";
|
|
68744
68744
|
};
|
|
68745
68745
|
}
|
|
68746
68746
|
function createNoneVerifier() {
|
|
68747
|
-
return function
|
|
68747
|
+
return function verify2(thing, signature) {
|
|
68748
68748
|
return signature === "";
|
|
68749
68749
|
};
|
|
68750
68750
|
}
|
|
@@ -68845,7 +68845,7 @@ var require_sign_stream = __commonJS({
|
|
|
68845
68845
|
}.bind(this));
|
|
68846
68846
|
}
|
|
68847
68847
|
util.inherits(SignStream, Stream6);
|
|
68848
|
-
SignStream.prototype.sign = function
|
|
68848
|
+
SignStream.prototype.sign = function sign2() {
|
|
68849
68849
|
try {
|
|
68850
68850
|
var signature = jwsSign({
|
|
68851
68851
|
header: this.header,
|
|
@@ -68964,7 +68964,7 @@ var require_verify_stream = __commonJS({
|
|
|
68964
68964
|
}.bind(this));
|
|
68965
68965
|
}
|
|
68966
68966
|
util.inherits(VerifyStream, Stream6);
|
|
68967
|
-
VerifyStream.prototype.verify = function
|
|
68967
|
+
VerifyStream.prototype.verify = function verify2() {
|
|
68968
68968
|
try {
|
|
68969
68969
|
var valid = jwsVerify(this.signature.buffer, this.algorithm, this.key.buffer);
|
|
68970
68970
|
var obj = jwsDecode(this.signature.buffer, this.encoding);
|
|
@@ -71321,14 +71321,14 @@ var require_awsrequestsigner = __commonJS({
|
|
|
71321
71321
|
}
|
|
71322
71322
|
};
|
|
71323
71323
|
exports.AwsRequestSigner = AwsRequestSigner;
|
|
71324
|
-
async function
|
|
71324
|
+
async function sign2(crypto2, key, msg) {
|
|
71325
71325
|
return await crypto2.signWithHmacSha256(key, msg);
|
|
71326
71326
|
}
|
|
71327
71327
|
async function getSigningKey(crypto2, key, dateStamp, region, serviceName) {
|
|
71328
|
-
const kDate = await
|
|
71329
|
-
const kRegion = await
|
|
71330
|
-
const kService = await
|
|
71331
|
-
const kSigning = await
|
|
71328
|
+
const kDate = await sign2(crypto2, `AWS4${key}`, dateStamp);
|
|
71329
|
+
const kRegion = await sign2(crypto2, kDate, region);
|
|
71330
|
+
const kService = await sign2(crypto2, kRegion, serviceName);
|
|
71331
|
+
const kSigning = await sign2(crypto2, kService, "aws4_request");
|
|
71332
71332
|
return kSigning;
|
|
71333
71333
|
}
|
|
71334
71334
|
async function generateAuthenticationHeaderMap(options) {
|
|
@@ -71372,7 +71372,7 @@ ${amzDate}
|
|
|
71372
71372
|
${credentialScope}
|
|
71373
71373
|
` + await options.crypto.sha256DigestHex(canonicalRequest);
|
|
71374
71374
|
const signingKey = await getSigningKey(options.crypto, options.securityCredentials.secretAccessKey, dateStamp, options.region, serviceName);
|
|
71375
|
-
const signature = await
|
|
71375
|
+
const signature = await sign2(options.crypto, signingKey, stringToSign);
|
|
71376
71376
|
const authorizationHeader = `${AWS_ALGORITHM} Credential=${options.securityCredentials.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${(0, crypto_1.fromArrayBufferToHex)(signature)}`;
|
|
71377
71377
|
return {
|
|
71378
71378
|
// Do not return x-amz-date if date is available.
|
|
@@ -73357,8 +73357,8 @@ var require_googleauth = __commonJS({
|
|
|
73357
73357
|
}
|
|
73358
73358
|
const crypto2 = (0, crypto_1.createCrypto)();
|
|
73359
73359
|
if (client instanceof jwtclient_1.JWT && client.key) {
|
|
73360
|
-
const
|
|
73361
|
-
return
|
|
73360
|
+
const sign2 = await crypto2.sign(client.key, data);
|
|
73361
|
+
return sign2;
|
|
73362
73362
|
}
|
|
73363
73363
|
const creds = await this.getCredentials();
|
|
73364
73364
|
if (!creds.client_email) {
|
|
@@ -76041,7 +76041,7 @@ var require_websocket = __commonJS({
|
|
|
76041
76041
|
var http3 = __require("http");
|
|
76042
76042
|
var net = __require("net");
|
|
76043
76043
|
var tls = __require("tls");
|
|
76044
|
-
var { randomBytes, createHash: createHash16 } = __require("crypto");
|
|
76044
|
+
var { randomBytes: randomBytes2, createHash: createHash16 } = __require("crypto");
|
|
76045
76045
|
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
76046
76046
|
var { URL: URL2 } = __require("url");
|
|
76047
76047
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -76579,7 +76579,7 @@ var require_websocket = __commonJS({
|
|
|
76579
76579
|
}
|
|
76580
76580
|
}
|
|
76581
76581
|
const defaultPort = isSecure ? 443 : 80;
|
|
76582
|
-
const key =
|
|
76582
|
+
const key = randomBytes2(16).toString("base64");
|
|
76583
76583
|
const request = isSecure ? https2.request : http3.request;
|
|
76584
76584
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
76585
76585
|
let perMessageDeflate;
|
|
@@ -86890,22 +86890,22 @@ function ReadableStreamFrom3(iterable) {
|
|
|
86890
86890
|
function ReadableStreamToAsyncIterable3(stream2) {
|
|
86891
86891
|
if (stream2[Symbol.asyncIterator])
|
|
86892
86892
|
return stream2;
|
|
86893
|
-
const
|
|
86893
|
+
const reader2 = stream2.getReader();
|
|
86894
86894
|
return {
|
|
86895
86895
|
async next() {
|
|
86896
86896
|
try {
|
|
86897
|
-
const result = await
|
|
86897
|
+
const result = await reader2.read();
|
|
86898
86898
|
if (result === null || result === void 0 ? void 0 : result.done)
|
|
86899
|
-
|
|
86899
|
+
reader2.releaseLock();
|
|
86900
86900
|
return result;
|
|
86901
86901
|
} catch (e2) {
|
|
86902
|
-
|
|
86902
|
+
reader2.releaseLock();
|
|
86903
86903
|
throw e2;
|
|
86904
86904
|
}
|
|
86905
86905
|
},
|
|
86906
86906
|
async return() {
|
|
86907
|
-
const cancelPromise =
|
|
86908
|
-
|
|
86907
|
+
const cancelPromise = reader2.cancel();
|
|
86908
|
+
reader2.releaseLock();
|
|
86909
86909
|
await cancelPromise;
|
|
86910
86910
|
return { done: true, value: void 0 };
|
|
86911
86911
|
},
|
|
@@ -86922,9 +86922,9 @@ async function CancelReadableStream3(stream2) {
|
|
|
86922
86922
|
await ((_b = (_a5 = stream2[Symbol.asyncIterator]()).return) === null || _b === void 0 ? void 0 : _b.call(_a5));
|
|
86923
86923
|
return;
|
|
86924
86924
|
}
|
|
86925
|
-
const
|
|
86926
|
-
const cancelPromise =
|
|
86927
|
-
|
|
86925
|
+
const reader2 = stream2.getReader();
|
|
86926
|
+
const cancelPromise = reader2.cancel();
|
|
86927
|
+
reader2.releaseLock();
|
|
86928
86928
|
await cancelPromise;
|
|
86929
86929
|
}
|
|
86930
86930
|
function stringifyQuery3(query) {
|
|
@@ -90798,9 +90798,9 @@ var init_node = __esm({
|
|
|
90798
90798
|
processStreamResponse(response) {
|
|
90799
90799
|
return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
|
|
90800
90800
|
var _a5;
|
|
90801
|
-
const
|
|
90801
|
+
const reader2 = (_a5 = response === null || response === void 0 ? void 0 : response.body) === null || _a5 === void 0 ? void 0 : _a5.getReader();
|
|
90802
90802
|
const decoder = new TextDecoder("utf-8");
|
|
90803
|
-
if (!
|
|
90803
|
+
if (!reader2) {
|
|
90804
90804
|
throw new Error("Response body is empty");
|
|
90805
90805
|
}
|
|
90806
90806
|
try {
|
|
@@ -90808,7 +90808,7 @@ var init_node = __esm({
|
|
|
90808
90808
|
const dataPrefix = "data:";
|
|
90809
90809
|
const delimiters = ["\n\n", "\r\r", "\r\n\r\n"];
|
|
90810
90810
|
while (true) {
|
|
90811
|
-
const { done, value } = yield __await(
|
|
90811
|
+
const { done, value } = yield __await(reader2.read());
|
|
90812
90812
|
if (done) {
|
|
90813
90813
|
if (buffer.trim().length > 0) {
|
|
90814
90814
|
throw new Error("Incomplete JSON segment at the end");
|
|
@@ -90872,7 +90872,7 @@ var init_node = __esm({
|
|
|
90872
90872
|
}
|
|
90873
90873
|
}
|
|
90874
90874
|
} finally {
|
|
90875
|
-
|
|
90875
|
+
reader2.releaseLock();
|
|
90876
90876
|
}
|
|
90877
90877
|
});
|
|
90878
90878
|
}
|
|
@@ -96580,12 +96580,12 @@ var init_config3 = __esm({
|
|
|
96580
96580
|
|
|
96581
96581
|
// node_modules/@mistralai/mistralai/esm/lib/files.js
|
|
96582
96582
|
async function readableStreamToArrayBuffer(readable) {
|
|
96583
|
-
const
|
|
96583
|
+
const reader2 = readable.getReader();
|
|
96584
96584
|
const chunks = [];
|
|
96585
96585
|
let totalLength = 0;
|
|
96586
96586
|
let done = false;
|
|
96587
96587
|
while (!done) {
|
|
96588
|
-
const { value, done: doneReading } = await
|
|
96588
|
+
const { value, done: doneReading } = await reader2.read();
|
|
96589
96589
|
if (doneReading) {
|
|
96590
96590
|
done = true;
|
|
96591
96591
|
} else {
|
|
@@ -111669,24 +111669,24 @@ var init_event_streams = __esm({
|
|
|
111669
111669
|
const fn = ReadableStream.prototype[Symbol.asyncIterator];
|
|
111670
111670
|
if (typeof fn === "function")
|
|
111671
111671
|
return fn.call(this);
|
|
111672
|
-
const
|
|
111672
|
+
const reader2 = this.getReader();
|
|
111673
111673
|
return {
|
|
111674
111674
|
next: async () => {
|
|
111675
|
-
const r2 = await
|
|
111675
|
+
const r2 = await reader2.read();
|
|
111676
111676
|
if (r2.done) {
|
|
111677
|
-
|
|
111677
|
+
reader2.releaseLock();
|
|
111678
111678
|
return { done: true, value: void 0 };
|
|
111679
111679
|
}
|
|
111680
111680
|
return { done: false, value: r2.value };
|
|
111681
111681
|
},
|
|
111682
111682
|
throw: async (e2) => {
|
|
111683
|
-
await
|
|
111684
|
-
|
|
111683
|
+
await reader2.cancel(e2);
|
|
111684
|
+
reader2.releaseLock();
|
|
111685
111685
|
return { done: true, value: void 0 };
|
|
111686
111686
|
},
|
|
111687
111687
|
return: async () => {
|
|
111688
|
-
await
|
|
111689
|
-
|
|
111688
|
+
await reader2.cancel("done");
|
|
111689
|
+
reader2.releaseLock();
|
|
111690
111690
|
return { done: true, value: void 0 };
|
|
111691
111691
|
},
|
|
111692
111692
|
[Symbol.asyncIterator]() {
|
|
@@ -135208,11 +135208,11 @@ function normalizeCodexStatus(status) {
|
|
|
135208
135208
|
async function* parseSSE(response, signal) {
|
|
135209
135209
|
if (!response.body)
|
|
135210
135210
|
return;
|
|
135211
|
-
const
|
|
135211
|
+
const reader2 = response.body.getReader();
|
|
135212
135212
|
const decoder = new TextDecoder();
|
|
135213
135213
|
let buffer = "";
|
|
135214
135214
|
const onAbort = () => {
|
|
135215
|
-
void
|
|
135215
|
+
void reader2.cancel().catch(() => {
|
|
135216
135216
|
});
|
|
135217
135217
|
};
|
|
135218
135218
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -135221,7 +135221,7 @@ async function* parseSSE(response, signal) {
|
|
|
135221
135221
|
if (signal?.aborted) {
|
|
135222
135222
|
throw new Error("Request was aborted");
|
|
135223
135223
|
}
|
|
135224
|
-
const { done, value } = await
|
|
135224
|
+
const { done, value } = await reader2.read();
|
|
135225
135225
|
if (signal?.aborted) {
|
|
135226
135226
|
throw new Error("Request was aborted");
|
|
135227
135227
|
}
|
|
@@ -135252,11 +135252,11 @@ async function* parseSSE(response, signal) {
|
|
|
135252
135252
|
} finally {
|
|
135253
135253
|
signal?.removeEventListener("abort", onAbort);
|
|
135254
135254
|
try {
|
|
135255
|
-
await
|
|
135255
|
+
await reader2.cancel();
|
|
135256
135256
|
} catch {
|
|
135257
135257
|
}
|
|
135258
135258
|
try {
|
|
135259
|
-
|
|
135259
|
+
reader2.releaseLock();
|
|
135260
135260
|
} catch {
|
|
135261
135261
|
}
|
|
135262
135262
|
}
|
|
@@ -144019,12 +144019,12 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
144019
144019
|
throw new Error(`Provider media download exceeds the ${maxBytes}-byte limit`);
|
|
144020
144020
|
}
|
|
144021
144021
|
if (!response.body) throw new Error("Provider media download returned an empty response");
|
|
144022
|
-
const
|
|
144022
|
+
const reader2 = response.body.getReader();
|
|
144023
144023
|
const chunks = [];
|
|
144024
144024
|
let total = 0;
|
|
144025
144025
|
try {
|
|
144026
144026
|
while (true) {
|
|
144027
|
-
const { done, value } = await
|
|
144027
|
+
const { done, value } = await reader2.read();
|
|
144028
144028
|
if (done) break;
|
|
144029
144029
|
if (!value) continue;
|
|
144030
144030
|
total += value.byteLength;
|
|
@@ -144032,7 +144032,7 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
144032
144032
|
chunks.push(value);
|
|
144033
144033
|
}
|
|
144034
144034
|
} finally {
|
|
144035
|
-
|
|
144035
|
+
reader2.releaseLock();
|
|
144036
144036
|
}
|
|
144037
144037
|
if (total === 0) throw new Error("Provider media download returned an empty response");
|
|
144038
144038
|
return Buffer.concat(chunks);
|
|
@@ -144881,7 +144881,7 @@ async function archiveExpiredBatch(_projectDir, options) {
|
|
|
144881
144881
|
const nextCursor = hasMore && scanned.length > 0 ? scanned[scanned.length - 1].id : void 0;
|
|
144882
144882
|
return nextCursor === void 0 ? { archived, scanned: scanned.length } : { archived, scanned: scanned.length, nextCursor };
|
|
144883
144883
|
}
|
|
144884
|
-
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
144884
|
+
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId, reader2) {
|
|
144885
144885
|
const store = getObservationStore();
|
|
144886
144886
|
if (projectId) {
|
|
144887
144887
|
let afterId;
|
|
@@ -144892,13 +144892,13 @@ async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
|
144892
144892
|
afterId,
|
|
144893
144893
|
referenceTime,
|
|
144894
144894
|
accessMap,
|
|
144895
|
-
reader
|
|
144895
|
+
reader: reader2
|
|
144896
144896
|
});
|
|
144897
144897
|
archived += batch.archived;
|
|
144898
144898
|
afterId = batch.nextCursor;
|
|
144899
144899
|
} while (afterId !== void 0);
|
|
144900
144900
|
const remainingObservations = await store.loadByProject(projectId, { status: "active" });
|
|
144901
|
-
const remaining =
|
|
144901
|
+
const remaining = reader2 ? remainingObservations.filter((observation) => canManageObservation(observation, reader2)).length : remainingObservations.length;
|
|
144902
144902
|
return { archived, remaining };
|
|
144903
144903
|
}
|
|
144904
144904
|
return await store.atomic(async (tx) => {
|
|
@@ -145354,21 +145354,21 @@ function assertPortableEvidence(scope, portability, evidence) {
|
|
|
145354
145354
|
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.");
|
|
145355
145355
|
}
|
|
145356
145356
|
}
|
|
145357
|
-
function requireTeamReader(scope,
|
|
145358
|
-
if (scope === "team" &&
|
|
145357
|
+
function requireTeamReader(scope, reader2) {
|
|
145358
|
+
if (scope === "team" && reader2?.isTeamMember !== true) {
|
|
145359
145359
|
throw new Error("Team long-term memory requires an explicit active team identity for this project.");
|
|
145360
145360
|
}
|
|
145361
145361
|
}
|
|
145362
|
-
function matchesScope(memory,
|
|
145363
|
-
if (memory.scope === "project") return memory.originProjectId ===
|
|
145362
|
+
function matchesScope(memory, reader2) {
|
|
145363
|
+
if (memory.scope === "project") return memory.originProjectId === reader2.projectId;
|
|
145364
145364
|
if (memory.scope === "team") {
|
|
145365
|
-
return memory.originProjectId ===
|
|
145365
|
+
return memory.originProjectId === reader2.projectId && reader2.isTeamMember === true;
|
|
145366
145366
|
}
|
|
145367
|
-
if (!
|
|
145368
|
-
return memory.portability === "portable" || memory.originProjectId ===
|
|
145367
|
+
if (!reader2.ownerId || memory.ownerId !== reader2.ownerId) return false;
|
|
145368
|
+
return memory.portability === "portable" || memory.originProjectId === reader2.projectId;
|
|
145369
145369
|
}
|
|
145370
|
-
function canReadLongTermMemory(memory,
|
|
145371
|
-
return matchesScope(memory,
|
|
145370
|
+
function canReadLongTermMemory(memory, reader2) {
|
|
145371
|
+
return matchesScope(memory, reader2);
|
|
145372
145372
|
}
|
|
145373
145373
|
function isEligibleLongTermMemory(memory) {
|
|
145374
145374
|
return memory.state === "qualified" || memory.state === "approved";
|
|
@@ -145754,14 +145754,14 @@ async function selectLongTermMemoriesForTask(input) {
|
|
|
145754
145754
|
const task = input.task?.trim();
|
|
145755
145755
|
if (!task) return [];
|
|
145756
145756
|
const owner = await resolveLocalMemoryOwner(input.dataDir, { create: false });
|
|
145757
|
-
const
|
|
145757
|
+
const reader2 = {
|
|
145758
145758
|
projectId: input.projectId,
|
|
145759
145759
|
...owner ? { ownerId: owner.id } : {},
|
|
145760
145760
|
...input.agentId ? { agentId: input.agentId } : {},
|
|
145761
145761
|
...input.isTeamMember ? { isTeamMember: true } : {}
|
|
145762
145762
|
};
|
|
145763
145763
|
const store = await createStore(input.dataDir);
|
|
145764
|
-
const eligible = store.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory,
|
|
145764
|
+
const eligible = store.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory, reader2));
|
|
145765
145765
|
let selected = eligible.map((memory) => {
|
|
145766
145766
|
const ranked = scoreForTask(memory, task);
|
|
145767
145767
|
return ranked ? {
|
|
@@ -152172,6 +152172,125 @@ var init_governor = __esm({
|
|
|
152172
152172
|
}
|
|
152173
152173
|
});
|
|
152174
152174
|
|
|
152175
|
+
// src/memory/deduplication.ts
|
|
152176
|
+
function chronological(left, right) {
|
|
152177
|
+
const byTime = new Date(left.createdAt).getTime() - new Date(right.createdAt).getTime();
|
|
152178
|
+
return byTime || left.id - right.id;
|
|
152179
|
+
}
|
|
152180
|
+
function actionFromDecision(older, newer, decision) {
|
|
152181
|
+
let resolveId;
|
|
152182
|
+
let keepId;
|
|
152183
|
+
if (decision.action === "NONE") {
|
|
152184
|
+
resolveId = newer.id;
|
|
152185
|
+
keepId = older.id;
|
|
152186
|
+
} else if (decision.action === "UPDATE") {
|
|
152187
|
+
resolveId = decision.targetId ?? older.id;
|
|
152188
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
152189
|
+
} else if (decision.action === "DELETE") {
|
|
152190
|
+
resolveId = decision.targetId ?? older.id;
|
|
152191
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
152192
|
+
} else {
|
|
152193
|
+
return null;
|
|
152194
|
+
}
|
|
152195
|
+
const records = /* @__PURE__ */ new Map([[older.id, older], [newer.id, newer]]);
|
|
152196
|
+
const resolved = records.get(resolveId);
|
|
152197
|
+
const kept = records.get(keepId);
|
|
152198
|
+
if (!resolved || !kept || resolved.id === kept.id) return null;
|
|
152199
|
+
return {
|
|
152200
|
+
resolveId,
|
|
152201
|
+
keepId,
|
|
152202
|
+
entityName: newer.entityName,
|
|
152203
|
+
resolveTitle: resolved.title,
|
|
152204
|
+
keepTitle: kept.title,
|
|
152205
|
+
reason: decision.reason,
|
|
152206
|
+
decision: decision.action,
|
|
152207
|
+
usedLLM: decision.usedLLM
|
|
152208
|
+
};
|
|
152209
|
+
}
|
|
152210
|
+
async function planMemoryDeduplication(observations2, options = {}) {
|
|
152211
|
+
const limit2 = Math.min(100, Math.max(2, Math.floor(options.limit ?? 20)));
|
|
152212
|
+
const candidates = observations2.filter((observation) => (observation.status ?? "active") === "active").sort(chronological).slice(-limit2);
|
|
152213
|
+
const byEntity = /* @__PURE__ */ new Map();
|
|
152214
|
+
for (const observation of candidates) {
|
|
152215
|
+
const group = byEntity.get(observation.entityName) ?? [];
|
|
152216
|
+
group.push(observation);
|
|
152217
|
+
byEntity.set(observation.entityName, group);
|
|
152218
|
+
}
|
|
152219
|
+
const decide = options.decide ?? deduplicateMemory;
|
|
152220
|
+
const actions = /* @__PURE__ */ new Map();
|
|
152221
|
+
let comparisons = 0;
|
|
152222
|
+
let failedComparisons = 0;
|
|
152223
|
+
for (const group of byEntity.values()) {
|
|
152224
|
+
if (group.length < 2) continue;
|
|
152225
|
+
group.sort(chronological);
|
|
152226
|
+
for (let index = 0; index < group.length; index += 1) {
|
|
152227
|
+
for (let compareIndex = index + 1; compareIndex < group.length; compareIndex += 1) {
|
|
152228
|
+
const older = group[index];
|
|
152229
|
+
const newer = group[compareIndex];
|
|
152230
|
+
comparisons += 1;
|
|
152231
|
+
let decision;
|
|
152232
|
+
try {
|
|
152233
|
+
decision = await decide(
|
|
152234
|
+
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
152235
|
+
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
152236
|
+
);
|
|
152237
|
+
} catch {
|
|
152238
|
+
failedComparisons += 1;
|
|
152239
|
+
continue;
|
|
152240
|
+
}
|
|
152241
|
+
if (!decision) continue;
|
|
152242
|
+
const action = actionFromDecision(older, newer, decision);
|
|
152243
|
+
if (action && !actions.has(action.resolveId)) actions.set(action.resolveId, action);
|
|
152244
|
+
}
|
|
152245
|
+
}
|
|
152246
|
+
}
|
|
152247
|
+
const planned = [...actions.values()];
|
|
152248
|
+
for (const [entityName, group] of byEntity) {
|
|
152249
|
+
const resolvedIds = new Set(
|
|
152250
|
+
planned.filter((action) => action.entityName === entityName).map((action) => action.resolveId)
|
|
152251
|
+
);
|
|
152252
|
+
if (group.length > 0 && group.every((observation) => resolvedIds.has(observation.id))) {
|
|
152253
|
+
const survivor = group[group.length - 1];
|
|
152254
|
+
const unsafeIndex = planned.findIndex((action) => action.resolveId === survivor.id);
|
|
152255
|
+
if (unsafeIndex >= 0) planned.splice(unsafeIndex, 1);
|
|
152256
|
+
}
|
|
152257
|
+
}
|
|
152258
|
+
return {
|
|
152259
|
+
scanned: candidates.length,
|
|
152260
|
+
entities: byEntity.size,
|
|
152261
|
+
comparisons,
|
|
152262
|
+
failedComparisons,
|
|
152263
|
+
actions: planned,
|
|
152264
|
+
resolveIds: planned.map((action) => action.resolveId)
|
|
152265
|
+
};
|
|
152266
|
+
}
|
|
152267
|
+
async function applyDeduplicationPlan(store, projectId, resolveIds, reader2 = { projectId }) {
|
|
152268
|
+
const uniqueIds = [...new Set(resolveIds)];
|
|
152269
|
+
const manageable = [];
|
|
152270
|
+
const skipped = [];
|
|
152271
|
+
for (const id of uniqueIds) {
|
|
152272
|
+
const observation = await store.getById(id);
|
|
152273
|
+
if (observation && observation.projectId === projectId && (observation.status ?? "active") === "active" && canManageObservation(observation, reader2)) {
|
|
152274
|
+
manageable.push(id);
|
|
152275
|
+
} else {
|
|
152276
|
+
skipped.push(id);
|
|
152277
|
+
}
|
|
152278
|
+
}
|
|
152279
|
+
const resolved = skipped.length > 0 || manageable.length === 0 ? [] : await store.atomic(async (tx) => {
|
|
152280
|
+
const updates = await Promise.all(manageable.map((id) => tx.setStatus(id, "resolved", "active")));
|
|
152281
|
+
return manageable.filter((_, index) => updates[index]);
|
|
152282
|
+
});
|
|
152283
|
+
return { resolved, skipped };
|
|
152284
|
+
}
|
|
152285
|
+
var init_deduplication = __esm({
|
|
152286
|
+
"src/memory/deduplication.ts"() {
|
|
152287
|
+
"use strict";
|
|
152288
|
+
init_esm_shims();
|
|
152289
|
+
init_memory_manager();
|
|
152290
|
+
init_visibility();
|
|
152291
|
+
}
|
|
152292
|
+
});
|
|
152293
|
+
|
|
152175
152294
|
// src/memory/formation/extract.ts
|
|
152176
152295
|
function extractFacts2(narrative, existingFacts) {
|
|
152177
152296
|
const existingLower = new Set(existingFacts.map((f3) => f3.toLowerCase().trim()));
|
|
@@ -153294,14 +153413,14 @@ function isSystemSelfObservation(obs) {
|
|
|
153294
153413
|
const text2 = stringifyObservation(obs, false);
|
|
153295
153414
|
return SYSTEM_SELF_PATTERNS.some((pattern) => pattern.test(text2));
|
|
153296
153415
|
}
|
|
153297
|
-
function readerForAlias(
|
|
153298
|
-
if (!
|
|
153299
|
-
return
|
|
153416
|
+
function readerForAlias(reader2, aliases, observation) {
|
|
153417
|
+
if (!reader2) return void 0;
|
|
153418
|
+
return reader2.projectId && aliases.has(observation.projectId) ? { ...reader2, projectId: observation.projectId } : reader2;
|
|
153300
153419
|
}
|
|
153301
|
-
function readableAliasObservations(observations2, aliases,
|
|
153302
|
-
return
|
|
153420
|
+
function readableAliasObservations(observations2, aliases, reader2) {
|
|
153421
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(
|
|
153303
153422
|
observation,
|
|
153304
|
-
readerForAlias(
|
|
153423
|
+
readerForAlias(reader2, aliases, observation)
|
|
153305
153424
|
)) : observations2;
|
|
153306
153425
|
}
|
|
153307
153426
|
function isUsefulSessionSummary(summary) {
|
|
@@ -153320,13 +153439,13 @@ function continuationScore(observation, projectTokens, task) {
|
|
|
153320
153439
|
score += Math.min(matches, 2) * 2;
|
|
153321
153440
|
return score;
|
|
153322
153441
|
}
|
|
153323
|
-
async function getSessionResumeBrief(projectId, task,
|
|
153442
|
+
async function getSessionResumeBrief(projectId, task, reader2) {
|
|
153324
153443
|
const aliasSet = await resolveProjectIds(projectId);
|
|
153325
153444
|
const [sessions, allObs] = await Promise.all([
|
|
153326
153445
|
loadAliasSessions(aliasSet),
|
|
153327
153446
|
loadAliasActiveObservations(aliasSet)
|
|
153328
153447
|
]);
|
|
153329
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
153448
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
153330
153449
|
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));
|
|
153331
153450
|
const projectTokens = tokenizeProjectId(projectId);
|
|
153332
153451
|
const memories = readableObs.filter((observation) => RESUME_TYPES.has(observation.type)).filter((observation) => classifyLayer(observation) === "L2").filter((observation) => !isNoiseObservation(observation) && !isSystemSelfObservation(observation)).map((observation) => ({
|
|
@@ -153437,13 +153556,13 @@ async function endSession(projectDir2, sessionId, summary) {
|
|
|
153437
153556
|
await sessionStore.update(session);
|
|
153438
153557
|
return session;
|
|
153439
153558
|
}
|
|
153440
|
-
async function getSessionContext(projectDir2, projectId, limit2 = 3,
|
|
153559
|
+
async function getSessionContext(projectDir2, projectId, limit2 = 3, reader2) {
|
|
153441
153560
|
const aliasSet = await resolveProjectIds(projectId);
|
|
153442
153561
|
const [sessions, allObs] = await Promise.all([
|
|
153443
153562
|
loadAliasSessions(aliasSet),
|
|
153444
153563
|
loadAliasActiveObservations(aliasSet, SESSION_CONTEXT_OBSERVATION_LIMIT)
|
|
153445
153564
|
]);
|
|
153446
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
153565
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
153447
153566
|
const isNoisySummary = (summary) => {
|
|
153448
153567
|
if (!summary) return false;
|
|
153449
153568
|
return NOISE_PATTERNS2.some((p) => p.test(summary)) || SYSTEM_SELF_PATTERNS.some((p) => p.test(summary));
|
|
@@ -153480,7 +153599,7 @@ async function getSessionContext(projectDir2, projectId, limit2 = 3, reader) {
|
|
|
153480
153599
|
const hasL1Content = l1HookObs.length > 0 || l3GitCount > 0;
|
|
153481
153600
|
if (hasL1Content) {
|
|
153482
153601
|
let graphNeighbors = [];
|
|
153483
|
-
if (!
|
|
153602
|
+
if (!reader2 && activeEntities.length > 0) {
|
|
153484
153603
|
try {
|
|
153485
153604
|
const graphMgr = new KnowledgeGraphManager(projectDir2);
|
|
153486
153605
|
await graphMgr.init();
|
|
@@ -157988,13 +158107,13 @@ __export(export_import_exports, {
|
|
|
157988
158107
|
exportAsMarkdown: () => exportAsMarkdown,
|
|
157989
158108
|
importFromJson: () => importFromJson
|
|
157990
158109
|
});
|
|
157991
|
-
async function exportAsJson(projectDir2, projectId,
|
|
158110
|
+
async function exportAsJson(projectDir2, projectId, reader2) {
|
|
157992
158111
|
const store = getObservationStore();
|
|
157993
158112
|
const allObs = await store.loadAll();
|
|
157994
158113
|
const allSessions = await getSessionStore().loadAll();
|
|
157995
158114
|
const projectObs = filterReadableObservations(
|
|
157996
158115
|
allObs.filter((o) => o.projectId === projectId),
|
|
157997
|
-
|
|
158116
|
+
reader2
|
|
157998
158117
|
);
|
|
157999
158118
|
const projectSessions = allSessions.filter((s2) => s2.projectId === projectId);
|
|
158000
158119
|
const typeBreakdown = {};
|
|
@@ -158014,8 +158133,8 @@ async function exportAsJson(projectDir2, projectId, reader) {
|
|
|
158014
158133
|
}
|
|
158015
158134
|
};
|
|
158016
158135
|
}
|
|
158017
|
-
async function exportAsMarkdown(projectDir2, projectId,
|
|
158018
|
-
const data = await exportAsJson(projectDir2, projectId,
|
|
158136
|
+
async function exportAsMarkdown(projectDir2, projectId, reader2) {
|
|
158137
|
+
const data = await exportAsJson(projectDir2, projectId, reader2);
|
|
158019
158138
|
const lines = [];
|
|
158020
158139
|
lines.push(`# Memorix Export: ${projectId}`);
|
|
158021
158140
|
lines.push(`Exported: ${data.exportedAt}`);
|
|
@@ -158134,6 +158253,350 @@ var init_export_import = __esm({
|
|
|
158134
158253
|
}
|
|
158135
158254
|
});
|
|
158136
158255
|
|
|
158256
|
+
// src/memory/cleanup.ts
|
|
158257
|
+
function isLowQualityObservation(title) {
|
|
158258
|
+
return LOW_QUALITY_PATTERNS.some((pattern) => pattern.test(title.trim()));
|
|
158259
|
+
}
|
|
158260
|
+
function classifyNoiseObservation(observation) {
|
|
158261
|
+
const title = observation.title?.trim() ?? "";
|
|
158262
|
+
const entityName = observation.entityName?.trim().toLowerCase() ?? "";
|
|
158263
|
+
const concepts = (observation.concepts ?? []).map((concept) => concept.trim().toLowerCase());
|
|
158264
|
+
if (entityName === "memorix.demo" || entityName.startsWith("for_memmcp_test") || concepts.some((concept) => EXPLICIT_NOISE_MARKERS.has(concept))) {
|
|
158265
|
+
return { isNoise: true, reason: "system-self" };
|
|
158266
|
+
}
|
|
158267
|
+
if (EXPLICIT_NOISE_TITLE_PATTERNS.some((pattern) => pattern.test(title))) {
|
|
158268
|
+
return { isNoise: true, reason: "demo/test/noise" };
|
|
158269
|
+
}
|
|
158270
|
+
return { isNoise: false };
|
|
158271
|
+
}
|
|
158272
|
+
function analyzeCleanupObservations(observations2, options = {}) {
|
|
158273
|
+
const active = observations2.filter((observation) => (observation.status ?? "active") === "active");
|
|
158274
|
+
const lowQuality = active.filter((observation) => isLowQualityObservation(observation.title ?? ""));
|
|
158275
|
+
const lowQualityIds = new Set(lowQuality.map((observation) => observation.id));
|
|
158276
|
+
const highQuality = active.filter((observation) => !lowQualityIds.has(observation.id));
|
|
158277
|
+
const groups = /* @__PURE__ */ new Map();
|
|
158278
|
+
for (const observation of highQuality) {
|
|
158279
|
+
const key = `${observation.type}|${observation.title}|${observation.entityName}`;
|
|
158280
|
+
const existing = groups.get(key);
|
|
158281
|
+
if (existing) existing.duplicates.push(observation);
|
|
158282
|
+
else groups.set(key, { canonical: observation, duplicates: [] });
|
|
158283
|
+
}
|
|
158284
|
+
const duplicateGroups = [...groups.values()].filter((group) => group.duplicates.length > 0);
|
|
158285
|
+
const duplicates = duplicateGroups.flatMap((group) => group.duplicates);
|
|
158286
|
+
const excludedIds = new Set([...lowQuality, ...duplicates].map((observation) => observation.id));
|
|
158287
|
+
const noise = [];
|
|
158288
|
+
if (options.includeNoise) {
|
|
158289
|
+
for (const observation of active) {
|
|
158290
|
+
if (excludedIds.has(observation.id)) continue;
|
|
158291
|
+
const classification = classifyNoiseObservation(observation);
|
|
158292
|
+
if (classification.isNoise && classification.reason) {
|
|
158293
|
+
noise.push({ observation, reason: classification.reason });
|
|
158294
|
+
}
|
|
158295
|
+
}
|
|
158296
|
+
}
|
|
158297
|
+
const toRemove = [...lowQuality, ...duplicates];
|
|
158298
|
+
const toArchive = noise.map((hit) => hit.observation);
|
|
158299
|
+
return {
|
|
158300
|
+
totalActive: active.length,
|
|
158301
|
+
highQuality: highQuality.length - duplicates.length - toArchive.length,
|
|
158302
|
+
lowQuality,
|
|
158303
|
+
duplicateGroups,
|
|
158304
|
+
duplicates,
|
|
158305
|
+
noise,
|
|
158306
|
+
toRemove,
|
|
158307
|
+
toArchive
|
|
158308
|
+
};
|
|
158309
|
+
}
|
|
158310
|
+
function requireObservationIds(observations2, action) {
|
|
158311
|
+
const ids = observations2.map((observation) => observation.id);
|
|
158312
|
+
if (ids.some((id) => typeof id !== "number")) {
|
|
158313
|
+
throw new Error(`Cannot ${action}: an observation has no persisted ID.`);
|
|
158314
|
+
}
|
|
158315
|
+
return ids;
|
|
158316
|
+
}
|
|
158317
|
+
async function applyCleanupMutations(store, toArchive, toRemove) {
|
|
158318
|
+
const archiveIds = requireObservationIds(toArchive, "archive");
|
|
158319
|
+
const removeIds = requireObservationIds(toRemove, "delete");
|
|
158320
|
+
const removals = new Set(removeIds);
|
|
158321
|
+
if (archiveIds.some((id) => removals.has(id))) {
|
|
158322
|
+
throw new Error("Cleanup cannot archive and delete the same observation.");
|
|
158323
|
+
}
|
|
158324
|
+
await store.atomic(async (tx) => {
|
|
158325
|
+
await Promise.all(archiveIds.map((id) => tx.setStatus(id, "archived", "active")));
|
|
158326
|
+
await Promise.all(removeIds.map((id) => tx.remove(id)));
|
|
158327
|
+
});
|
|
158328
|
+
return { archived: archiveIds.length, removed: removeIds.length };
|
|
158329
|
+
}
|
|
158330
|
+
var LOW_QUALITY_PATTERNS, EXPLICIT_NOISE_TITLE_PATTERNS, EXPLICIT_NOISE_MARKERS;
|
|
158331
|
+
var init_cleanup = __esm({
|
|
158332
|
+
"src/memory/cleanup.ts"() {
|
|
158333
|
+
"use strict";
|
|
158334
|
+
init_esm_shims();
|
|
158335
|
+
LOW_QUALITY_PATTERNS = [
|
|
158336
|
+
/^Session activity/i,
|
|
158337
|
+
/^Updated \S+\.\w+$/i,
|
|
158338
|
+
/^Created \S+\.\w+$/i,
|
|
158339
|
+
/^Deleted \S+\.\w+$/i,
|
|
158340
|
+
/^Modified \S+\.\w+$/i,
|
|
158341
|
+
/^Ran command:/i,
|
|
158342
|
+
/^Read file:/i
|
|
158343
|
+
];
|
|
158344
|
+
EXPLICIT_NOISE_TITLE_PATTERNS = [
|
|
158345
|
+
/^\s*\[(?:test|demo|benchmark|sandbox|playground|测试|演示)\]/i,
|
|
158346
|
+
/^\s*(?:Used\s+(?:mcp__\S+|apply_patch)|Ran:)\s*/i
|
|
158347
|
+
];
|
|
158348
|
+
EXPLICIT_NOISE_MARKERS = /* @__PURE__ */ new Set([
|
|
158349
|
+
"test-fixture",
|
|
158350
|
+
"demo-fixture",
|
|
158351
|
+
"benchmark-fixture",
|
|
158352
|
+
"sandbox-fixture",
|
|
158353
|
+
"cleanup-noise"
|
|
158354
|
+
]);
|
|
158355
|
+
}
|
|
158356
|
+
});
|
|
158357
|
+
|
|
158358
|
+
// src/dashboard/maintenance.ts
|
|
158359
|
+
import { createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
158360
|
+
function reader(projectId) {
|
|
158361
|
+
return { projectId };
|
|
158362
|
+
}
|
|
158363
|
+
function summarize(observation) {
|
|
158364
|
+
return {
|
|
158365
|
+
id: observation.id,
|
|
158366
|
+
title: observation.title,
|
|
158367
|
+
type: observation.type,
|
|
158368
|
+
entityName: observation.entityName
|
|
158369
|
+
};
|
|
158370
|
+
}
|
|
158371
|
+
function normalizeIds(ids) {
|
|
158372
|
+
return [...new Set(ids)].sort((left, right) => left - right);
|
|
158373
|
+
}
|
|
158374
|
+
function normalizeClusters(clusters) {
|
|
158375
|
+
return clusters.map((ids) => normalizeIds(ids)).sort((left, right) => left.join(",").localeCompare(right.join(",")));
|
|
158376
|
+
}
|
|
158377
|
+
function payloadRecord(payload) {
|
|
158378
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
158379
|
+
throw new DashboardMaintenanceError("The maintenance preview payload is missing.", 400);
|
|
158380
|
+
}
|
|
158381
|
+
return payload;
|
|
158382
|
+
}
|
|
158383
|
+
function payloadIds(value, field) {
|
|
158384
|
+
if (!Array.isArray(value) || value.some((id) => !Number.isSafeInteger(id) || Number(id) <= 0)) {
|
|
158385
|
+
throw new DashboardMaintenanceError(`Invalid ${field} in maintenance preview.`, 400);
|
|
158386
|
+
}
|
|
158387
|
+
return normalizeIds(value);
|
|
158388
|
+
}
|
|
158389
|
+
function sign(action, projectId, payload) {
|
|
158390
|
+
return createHmac("sha256", previewSecret).update(JSON.stringify({ action, projectId, payload })).digest("hex");
|
|
158391
|
+
}
|
|
158392
|
+
function verify(action, projectId, payload, token) {
|
|
158393
|
+
if (typeof token !== "string" || !/^[a-f0-9]{64}$/.test(token)) {
|
|
158394
|
+
throw new DashboardMaintenanceError("Preview this maintenance action before executing it.", 400);
|
|
158395
|
+
}
|
|
158396
|
+
const expected = Buffer.from(sign(action, projectId, payload), "hex");
|
|
158397
|
+
const received = Buffer.from(token, "hex");
|
|
158398
|
+
if (!timingSafeEqual(expected, received)) {
|
|
158399
|
+
throw new DashboardMaintenanceError("The maintenance preview is invalid or belongs to another project.", 409);
|
|
158400
|
+
}
|
|
158401
|
+
}
|
|
158402
|
+
function assertCurrent(expected, actual) {
|
|
158403
|
+
if (JSON.stringify(normalizeIds(expected)) !== JSON.stringify(normalizeIds(actual))) {
|
|
158404
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh the preview before executing.", 409);
|
|
158405
|
+
}
|
|
158406
|
+
}
|
|
158407
|
+
async function manageableActiveObservations(context) {
|
|
158408
|
+
const scope = reader(context.projectId);
|
|
158409
|
+
return filterReadableObservations(
|
|
158410
|
+
await context.store.loadByProject(context.projectId, { status: "active" }),
|
|
158411
|
+
scope
|
|
158412
|
+
).filter((observation) => canManageObservation(observation, scope));
|
|
158413
|
+
}
|
|
158414
|
+
function cleanupPayload(includeNoise, analysis) {
|
|
158415
|
+
return {
|
|
158416
|
+
includeNoise,
|
|
158417
|
+
removeIds: normalizeIds(analysis.toRemove.map((observation) => observation.id)),
|
|
158418
|
+
archiveIds: normalizeIds(analysis.toArchive.map((observation) => observation.id))
|
|
158419
|
+
};
|
|
158420
|
+
}
|
|
158421
|
+
async function previewCleanup(context, includeNoise) {
|
|
158422
|
+
const analysis = analyzeCleanupObservations(await manageableActiveObservations(context), { includeNoise });
|
|
158423
|
+
const payload = cleanupPayload(includeNoise, analysis);
|
|
158424
|
+
return {
|
|
158425
|
+
action: "cleanup",
|
|
158426
|
+
projectId: context.projectId,
|
|
158427
|
+
includeNoise,
|
|
158428
|
+
summary: {
|
|
158429
|
+
totalActive: analysis.totalActive,
|
|
158430
|
+
highQuality: analysis.highQuality,
|
|
158431
|
+
lowQuality: analysis.lowQuality.length,
|
|
158432
|
+
duplicates: analysis.duplicates.length,
|
|
158433
|
+
noise: analysis.noise.length,
|
|
158434
|
+
delete: analysis.toRemove.length,
|
|
158435
|
+
archive: analysis.toArchive.length
|
|
158436
|
+
},
|
|
158437
|
+
lowQuality: analysis.lowQuality.map(summarize),
|
|
158438
|
+
duplicateGroups: analysis.duplicateGroups.map((group) => ({
|
|
158439
|
+
canonical: summarize(group.canonical),
|
|
158440
|
+
duplicates: group.duplicates.map(summarize)
|
|
158441
|
+
})),
|
|
158442
|
+
noise: analysis.noise.map((hit) => ({ ...summarize(hit.observation), reason: hit.reason })),
|
|
158443
|
+
payload,
|
|
158444
|
+
token: sign("cleanup", context.projectId, payload)
|
|
158445
|
+
};
|
|
158446
|
+
}
|
|
158447
|
+
async function executeCleanup(context, payload, token) {
|
|
158448
|
+
const record80 = payloadRecord(payload);
|
|
158449
|
+
const normalized = {
|
|
158450
|
+
includeNoise: record80.includeNoise === true,
|
|
158451
|
+
removeIds: payloadIds(record80.removeIds, "removeIds"),
|
|
158452
|
+
archiveIds: payloadIds(record80.archiveIds, "archiveIds")
|
|
158453
|
+
};
|
|
158454
|
+
verify("cleanup", context.projectId, normalized, token);
|
|
158455
|
+
const observations2 = await manageableActiveObservations(context);
|
|
158456
|
+
const analysis = analyzeCleanupObservations(observations2, { includeNoise: normalized.includeNoise });
|
|
158457
|
+
const current = cleanupPayload(normalized.includeNoise, analysis);
|
|
158458
|
+
assertCurrent(normalized.removeIds, current.removeIds);
|
|
158459
|
+
assertCurrent(normalized.archiveIds, current.archiveIds);
|
|
158460
|
+
const result = await applyCleanupMutations(context.store, analysis.toArchive, analysis.toRemove);
|
|
158461
|
+
return { action: "cleanup", projectId: context.projectId, ...result };
|
|
158462
|
+
}
|
|
158463
|
+
async function previewDeduplicate(context) {
|
|
158464
|
+
if (!isLLMEnabled()) {
|
|
158465
|
+
return {
|
|
158466
|
+
action: "deduplicate",
|
|
158467
|
+
projectId: context.projectId,
|
|
158468
|
+
available: false,
|
|
158469
|
+
reason: "Intelligent deduplication requires a configured memory LLM."
|
|
158470
|
+
};
|
|
158471
|
+
}
|
|
158472
|
+
const plan = await planMemoryDeduplication(await manageableActiveObservations(context));
|
|
158473
|
+
const payload = { resolveIds: normalizeIds(plan.resolveIds) };
|
|
158474
|
+
return {
|
|
158475
|
+
action: "deduplicate",
|
|
158476
|
+
projectId: context.projectId,
|
|
158477
|
+
available: true,
|
|
158478
|
+
summary: {
|
|
158479
|
+
scanned: plan.scanned,
|
|
158480
|
+
entities: plan.entities,
|
|
158481
|
+
comparisons: plan.comparisons,
|
|
158482
|
+
failedComparisons: plan.failedComparisons,
|
|
158483
|
+
resolve: payload.resolveIds.length
|
|
158484
|
+
},
|
|
158485
|
+
actions: plan.actions,
|
|
158486
|
+
payload,
|
|
158487
|
+
token: sign("deduplicate", context.projectId, payload)
|
|
158488
|
+
};
|
|
158489
|
+
}
|
|
158490
|
+
async function executeDeduplicate(context, payload, token) {
|
|
158491
|
+
const record80 = payloadRecord(payload);
|
|
158492
|
+
const normalized = { resolveIds: payloadIds(record80.resolveIds, "resolveIds") };
|
|
158493
|
+
verify("deduplicate", context.projectId, normalized, token);
|
|
158494
|
+
const result = await applyDeduplicationPlan(
|
|
158495
|
+
context.store,
|
|
158496
|
+
context.projectId,
|
|
158497
|
+
normalized.resolveIds,
|
|
158498
|
+
reader(context.projectId)
|
|
158499
|
+
);
|
|
158500
|
+
if (result.skipped.length > 0) {
|
|
158501
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before applying deduplication.", 409);
|
|
158502
|
+
}
|
|
158503
|
+
return { action: "deduplicate", projectId: context.projectId, ...result };
|
|
158504
|
+
}
|
|
158505
|
+
async function previewConsolidate(context) {
|
|
158506
|
+
const clusters = await findConsolidationCandidates(
|
|
158507
|
+
context.projectRoot ?? context.dataDir,
|
|
158508
|
+
context.projectId
|
|
158509
|
+
);
|
|
158510
|
+
const payload = { clusterIds: normalizeClusters(clusters.map((cluster) => cluster.ids)) };
|
|
158511
|
+
return {
|
|
158512
|
+
action: "consolidate",
|
|
158513
|
+
projectId: context.projectId,
|
|
158514
|
+
summary: {
|
|
158515
|
+
clusters: clusters.length,
|
|
158516
|
+
observations: normalizeIds(clusters.flatMap((cluster) => cluster.ids)).length
|
|
158517
|
+
},
|
|
158518
|
+
clusters,
|
|
158519
|
+
payload,
|
|
158520
|
+
token: sign("consolidate", context.projectId, payload)
|
|
158521
|
+
};
|
|
158522
|
+
}
|
|
158523
|
+
async function executeConsolidate(context, payload, token) {
|
|
158524
|
+
const record80 = payloadRecord(payload);
|
|
158525
|
+
if (!Array.isArray(record80.clusterIds)) {
|
|
158526
|
+
throw new DashboardMaintenanceError("Invalid clusterIds in maintenance preview.", 400);
|
|
158527
|
+
}
|
|
158528
|
+
const clusterIds = record80.clusterIds.map((ids, index) => payloadIds(ids, `clusterIds[${index}]`));
|
|
158529
|
+
const normalized = { clusterIds: normalizeClusters(clusterIds) };
|
|
158530
|
+
verify("consolidate", context.projectId, normalized, token);
|
|
158531
|
+
const current = await findConsolidationCandidates(context.projectRoot ?? context.dataDir, context.projectId);
|
|
158532
|
+
if (JSON.stringify(normalized.clusterIds) !== JSON.stringify(normalizeClusters(current.map((cluster) => cluster.ids)))) {
|
|
158533
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before consolidating.", 409);
|
|
158534
|
+
}
|
|
158535
|
+
const result = await executeConsolidation(context.projectRoot ?? context.dataDir, context.projectId);
|
|
158536
|
+
return { action: "consolidate", projectId: context.projectId, ...result };
|
|
158537
|
+
}
|
|
158538
|
+
async function retentionCandidates(context) {
|
|
158539
|
+
return (await manageableActiveObservations(context)).map((observation) => ({
|
|
158540
|
+
observation,
|
|
158541
|
+
retention: projectObservationRetention(observation)
|
|
158542
|
+
})).filter((row) => row.retention.zone === "archive-candidate");
|
|
158543
|
+
}
|
|
158544
|
+
async function previewRetentionArchive(context) {
|
|
158545
|
+
const candidates = await retentionCandidates(context);
|
|
158546
|
+
const payload = {
|
|
158547
|
+
archiveIds: normalizeIds(candidates.map((candidate) => candidate.observation.id))
|
|
158548
|
+
};
|
|
158549
|
+
return {
|
|
158550
|
+
action: "retention-archive",
|
|
158551
|
+
projectId: context.projectId,
|
|
158552
|
+
summary: { archive: payload.archiveIds.length },
|
|
158553
|
+
candidates: candidates.map(({ observation, retention }) => ({
|
|
158554
|
+
...summarize(observation),
|
|
158555
|
+
score: retention.displayScore,
|
|
158556
|
+
zone: retention.zone,
|
|
158557
|
+
ageHours: retention.ageHours
|
|
158558
|
+
})),
|
|
158559
|
+
payload,
|
|
158560
|
+
token: sign("retention-archive", context.projectId, payload)
|
|
158561
|
+
};
|
|
158562
|
+
}
|
|
158563
|
+
async function executeRetentionArchive(context, payload, token) {
|
|
158564
|
+
const record80 = payloadRecord(payload);
|
|
158565
|
+
const normalized = { archiveIds: payloadIds(record80.archiveIds, "archiveIds") };
|
|
158566
|
+
verify("retention-archive", context.projectId, normalized, token);
|
|
158567
|
+
const current = await retentionCandidates(context);
|
|
158568
|
+
assertCurrent(normalized.archiveIds, current.map((candidate) => candidate.observation.id));
|
|
158569
|
+
const result = await archiveExpired(
|
|
158570
|
+
context.dataDir,
|
|
158571
|
+
void 0,
|
|
158572
|
+
void 0,
|
|
158573
|
+
context.projectId,
|
|
158574
|
+
reader(context.projectId)
|
|
158575
|
+
);
|
|
158576
|
+
return { action: "retention-archive", projectId: context.projectId, ...result };
|
|
158577
|
+
}
|
|
158578
|
+
var previewSecret, DashboardMaintenanceError;
|
|
158579
|
+
var init_maintenance = __esm({
|
|
158580
|
+
"src/dashboard/maintenance.ts"() {
|
|
158581
|
+
"use strict";
|
|
158582
|
+
init_esm_shims();
|
|
158583
|
+
init_provider2();
|
|
158584
|
+
init_cleanup();
|
|
158585
|
+
init_consolidation();
|
|
158586
|
+
init_deduplication();
|
|
158587
|
+
init_retention();
|
|
158588
|
+
init_visibility();
|
|
158589
|
+
previewSecret = randomBytes(32);
|
|
158590
|
+
DashboardMaintenanceError = class extends Error {
|
|
158591
|
+
constructor(message, status) {
|
|
158592
|
+
super(message);
|
|
158593
|
+
this.status = status;
|
|
158594
|
+
}
|
|
158595
|
+
status;
|
|
158596
|
+
};
|
|
158597
|
+
}
|
|
158598
|
+
});
|
|
158599
|
+
|
|
158137
158600
|
// src/dashboard/project-classification.ts
|
|
158138
158601
|
var project_classification_exports = {};
|
|
158139
158602
|
__export(project_classification_exports, {
|
|
@@ -158736,6 +159199,56 @@ function filterDashboardObservations(observations2, projectId) {
|
|
|
158736
159199
|
function isActiveStatus(status) {
|
|
158737
159200
|
return (status ?? "active") === "active";
|
|
158738
159201
|
}
|
|
159202
|
+
async function handleMaintenanceMutation(apiPath, req, res, context) {
|
|
159203
|
+
if (req.method !== "POST") {
|
|
159204
|
+
throw new DashboardMaintenanceError("Maintenance actions require POST.", 405);
|
|
159205
|
+
}
|
|
159206
|
+
let body = {};
|
|
159207
|
+
const raw = await readBody(req);
|
|
159208
|
+
if (raw.trim()) {
|
|
159209
|
+
try {
|
|
159210
|
+
const parsed = JSON.parse(raw);
|
|
159211
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("object required");
|
|
159212
|
+
body = parsed;
|
|
159213
|
+
} catch {
|
|
159214
|
+
throw new DashboardMaintenanceError("Invalid maintenance request body.", 400);
|
|
159215
|
+
}
|
|
159216
|
+
}
|
|
159217
|
+
const maintenanceContext = {
|
|
159218
|
+
...context,
|
|
159219
|
+
store: getObservationStore()
|
|
159220
|
+
};
|
|
159221
|
+
let result;
|
|
159222
|
+
switch (apiPath) {
|
|
159223
|
+
case "/maintenance/cleanup/preview":
|
|
159224
|
+
result = await previewCleanup(maintenanceContext, body.includeNoise === true);
|
|
159225
|
+
break;
|
|
159226
|
+
case "/maintenance/cleanup/execute":
|
|
159227
|
+
result = await executeCleanup(maintenanceContext, body.payload, body.token);
|
|
159228
|
+
break;
|
|
159229
|
+
case "/maintenance/deduplicate/preview":
|
|
159230
|
+
result = await previewDeduplicate(maintenanceContext);
|
|
159231
|
+
break;
|
|
159232
|
+
case "/maintenance/deduplicate/execute":
|
|
159233
|
+
result = await executeDeduplicate(maintenanceContext, body.payload, body.token);
|
|
159234
|
+
break;
|
|
159235
|
+
case "/maintenance/consolidate/preview":
|
|
159236
|
+
result = await previewConsolidate(maintenanceContext);
|
|
159237
|
+
break;
|
|
159238
|
+
case "/maintenance/consolidate/execute":
|
|
159239
|
+
result = await executeConsolidate(maintenanceContext, body.payload, body.token);
|
|
159240
|
+
break;
|
|
159241
|
+
case "/maintenance/retention/preview":
|
|
159242
|
+
result = await previewRetentionArchive(maintenanceContext);
|
|
159243
|
+
break;
|
|
159244
|
+
case "/maintenance/retention/execute":
|
|
159245
|
+
result = await executeRetentionArchive(maintenanceContext, body.payload, body.token);
|
|
159246
|
+
break;
|
|
159247
|
+
default:
|
|
159248
|
+
throw new DashboardMaintenanceError("Unknown maintenance action.", 404);
|
|
159249
|
+
}
|
|
159250
|
+
sendJson(res, result);
|
|
159251
|
+
}
|
|
158739
159252
|
function prepareDashboardConfig(projectRoot) {
|
|
158740
159253
|
if (!projectRoot) {
|
|
158741
159254
|
if (preparedDashboardProjectRoot !== null) {
|
|
@@ -158778,6 +159291,21 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
158778
159291
|
prepareDashboardConfig(effectiveProjectRoot);
|
|
158779
159292
|
try {
|
|
158780
159293
|
switch (apiPath) {
|
|
159294
|
+
case "/maintenance/cleanup/preview":
|
|
159295
|
+
case "/maintenance/cleanup/execute":
|
|
159296
|
+
case "/maintenance/deduplicate/preview":
|
|
159297
|
+
case "/maintenance/deduplicate/execute":
|
|
159298
|
+
case "/maintenance/consolidate/preview":
|
|
159299
|
+
case "/maintenance/consolidate/execute":
|
|
159300
|
+
case "/maintenance/retention/preview":
|
|
159301
|
+
case "/maintenance/retention/execute": {
|
|
159302
|
+
await handleMaintenanceMutation(apiPath, req, res, {
|
|
159303
|
+
dataDir: effectiveDataDir,
|
|
159304
|
+
projectId: effectiveProjectId,
|
|
159305
|
+
projectRoot: effectiveProjectRoot
|
|
159306
|
+
});
|
|
159307
|
+
break;
|
|
159308
|
+
}
|
|
158781
159309
|
case "/projects": {
|
|
158782
159310
|
try {
|
|
158783
159311
|
const allObs = filterReadableObservations(
|
|
@@ -159301,7 +159829,8 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
159301
159829
|
}
|
|
159302
159830
|
} catch (err) {
|
|
159303
159831
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
159304
|
-
|
|
159832
|
+
const status = err instanceof DashboardMaintenanceError ? err.status : 500;
|
|
159833
|
+
sendError(res, message, status);
|
|
159305
159834
|
}
|
|
159306
159835
|
}
|
|
159307
159836
|
async function serveStatic(req, res, staticDir) {
|
|
@@ -159472,7 +160001,15 @@ async function buildTeamSnapshot(dataDir, projectId, scope, mode) {
|
|
|
159472
160001
|
function readBody(req) {
|
|
159473
160002
|
return new Promise((resolve2, reject) => {
|
|
159474
160003
|
const chunks = [];
|
|
159475
|
-
|
|
160004
|
+
let size = 0;
|
|
160005
|
+
req.on("data", (c) => {
|
|
160006
|
+
size += c.length;
|
|
160007
|
+
if (size > 64 * 1024) {
|
|
160008
|
+
reject(new DashboardMaintenanceError("Request body is too large.", 413));
|
|
160009
|
+
return;
|
|
160010
|
+
}
|
|
160011
|
+
chunks.push(c);
|
|
160012
|
+
});
|
|
159476
160013
|
req.on("end", () => resolve2(Buffer.concat(chunks).toString("utf-8")));
|
|
159477
160014
|
req.on("error", reject);
|
|
159478
160015
|
});
|
|
@@ -159605,6 +160142,7 @@ var init_server = __esm({
|
|
|
159605
160142
|
init_graph_scope();
|
|
159606
160143
|
init_retention();
|
|
159607
160144
|
init_visibility();
|
|
160145
|
+
init_maintenance();
|
|
159608
160146
|
MIME_TYPES = {
|
|
159609
160147
|
".html": "text/html; charset=utf-8",
|
|
159610
160148
|
".css": "text/css; charset=utf-8",
|
|
@@ -162921,8 +163459,8 @@ This project does have stored Memorix memories, but none matched the current que
|
|
|
162921
163459
|
const totalTokens = countTextTokens(formatted);
|
|
162922
163460
|
return { entries, formatted, totalTokens };
|
|
162923
163461
|
}
|
|
162924
|
-
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
162925
|
-
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter,
|
|
163462
|
+
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2, surface = "mcp") {
|
|
163463
|
+
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter, reader2);
|
|
162926
163464
|
const timeline = {
|
|
162927
163465
|
anchorId,
|
|
162928
163466
|
anchorEntry: result.anchor,
|
|
@@ -163260,7 +163798,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
163260
163798
|
const lowEvidence = active.filter((obs) => evidenceScore(obs) <= 2).map((obs) => makeEntry(obs, `Low evidence score (${evidenceScore(obs)}/5)`));
|
|
163261
163799
|
const hookNoise = active.filter((obs) => isHookNoise(obs) || isCommandLog(obs)).map((obs) => makeEntry(obs, isCommandLog(obs) ? "Command log noise" : "Hook-generated noise"));
|
|
163262
163800
|
const orphans = active.filter((obs) => isOrphan(obs)).map((obs) => makeEntry(obs, "Weakly connected or isolated memory"));
|
|
163263
|
-
const
|
|
163801
|
+
const retentionCandidates2 = active.filter((obs) => getRetentionZone({
|
|
163264
163802
|
id: `obs-${obs.id}`,
|
|
163265
163803
|
observationId: obs.id,
|
|
163266
163804
|
entityName: obs.entityName,
|
|
@@ -163300,7 +163838,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
163300
163838
|
if (orphans.length > 0) {
|
|
163301
163839
|
recommendations.push("Promote or attach isolated memories only if they have clear evidence value.");
|
|
163302
163840
|
}
|
|
163303
|
-
if (
|
|
163841
|
+
if (retentionCandidates2.length > 0) {
|
|
163304
163842
|
recommendations.push("Run `memorix retention stale` or `memorix retention archive` to inspect aged memories.");
|
|
163305
163843
|
}
|
|
163306
163844
|
if (recommendations.length === 0) {
|
|
@@ -163314,7 +163852,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
163314
163852
|
lowEvidence,
|
|
163315
163853
|
hookNoise,
|
|
163316
163854
|
orphans,
|
|
163317
|
-
retentionCandidates
|
|
163855
|
+
retentionCandidates: retentionCandidates2
|
|
163318
163856
|
},
|
|
163319
163857
|
recommendations
|
|
163320
163858
|
};
|
|
@@ -166018,6 +166556,7 @@ function describeProfile(profile) {
|
|
|
166018
166556
|
// src/server.ts
|
|
166019
166557
|
init_provider2();
|
|
166020
166558
|
init_memory_manager();
|
|
166559
|
+
init_deduplication();
|
|
166021
166560
|
init_formation();
|
|
166022
166561
|
|
|
166023
166562
|
// src/server/formation-timeout.ts
|
|
@@ -166541,7 +167080,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
166541
167080
|
};
|
|
166542
167081
|
const server = existingServer ?? new McpServer({
|
|
166543
167082
|
name: "memorix",
|
|
166544
|
-
version: true ? "1.
|
|
167083
|
+
version: true ? "1.7.1" : "1.0.1"
|
|
166545
167084
|
});
|
|
166546
167085
|
const originalRegisterTool = server.registerTool.bind(server);
|
|
166547
167086
|
server.registerTool = ((name, ...args) => {
|
|
@@ -166671,20 +167210,20 @@ The path should point to a directory containing a .git folder.`
|
|
|
166671
167210
|
if (readOnlyBoundary) return readOnlyBoundary;
|
|
166672
167211
|
const requestedVisibility = longTerm?.scope === "user" ? "personal" : longTerm?.scope === "team" ? "team" : visibility;
|
|
166673
167212
|
const effectiveVisibility = requestedVisibility ?? "project";
|
|
166674
|
-
const
|
|
167213
|
+
const reader2 = getObservationReader();
|
|
166675
167214
|
if (effectiveVisibility !== "project" && !currentAgentId) {
|
|
166676
167215
|
return {
|
|
166677
167216
|
content: [{ type: "text", text: "Personal or team memory requires memorix_session_start with joinTeam=true so Memorix can bind an owner." }],
|
|
166678
167217
|
isError: true
|
|
166679
167218
|
};
|
|
166680
167219
|
}
|
|
166681
|
-
if (effectiveVisibility === "team" && !
|
|
167220
|
+
if (effectiveVisibility === "team" && !reader2.isTeamMember) {
|
|
166682
167221
|
return {
|
|
166683
167222
|
content: [{ type: "text", text: "Team memory requires an active coordination membership in the current project." }],
|
|
166684
167223
|
isError: true
|
|
166685
167224
|
};
|
|
166686
167225
|
}
|
|
166687
|
-
if (longTerm?.scope === "team" && !
|
|
167226
|
+
if (longTerm?.scope === "team" && !reader2.isTeamMember) {
|
|
166688
167227
|
return {
|
|
166689
167228
|
content: [{ type: "text", text: "Team long-term memory requires an active coordination membership in the current project." }],
|
|
166690
167229
|
isError: true
|
|
@@ -166731,9 +167270,9 @@ The path should point to a directory containing a .git folder.`
|
|
|
166731
167270
|
useLLM: isLLMEnabled(),
|
|
166732
167271
|
minValueScore: 0.3,
|
|
166733
167272
|
searchMemories: async (q, limit2, pid, signal) => {
|
|
166734
|
-
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
167273
|
+
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
166735
167274
|
if (result.entries.length === 0) return [];
|
|
166736
|
-
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader });
|
|
167275
|
+
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader: reader2 });
|
|
166737
167276
|
return details.documents.map((d, i2) => ({
|
|
166738
167277
|
id: Number(d.id.replace("obs-", "")),
|
|
166739
167278
|
observationId: d.observationId,
|
|
@@ -166747,7 +167286,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
166747
167286
|
},
|
|
166748
167287
|
getObservation: (id) => {
|
|
166749
167288
|
const o = getObservation(id);
|
|
166750
|
-
if (!o || o.projectId !== project.id || !canReadObservation(o,
|
|
167289
|
+
if (!o || o.projectId !== project.id || !canReadObservation(o, reader2)) return null;
|
|
166751
167290
|
return {
|
|
166752
167291
|
id: o.id,
|
|
166753
167292
|
entityName: o.entityName,
|
|
@@ -166804,7 +167343,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166804
167343
|
const { action: action2, targetId, reason } = formationResult.resolution;
|
|
166805
167344
|
if (action2 === "merge" && targetId) {
|
|
166806
167345
|
const targetObs = getObservation(targetId);
|
|
166807
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167346
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
166808
167347
|
await storeObservation({
|
|
166809
167348
|
entityName: targetObs.entityName,
|
|
166810
167349
|
type: targetObs.type,
|
|
@@ -166819,7 +167358,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166819
167358
|
sourceDetail: "explicit",
|
|
166820
167359
|
createdByAgentId: currentAgentId,
|
|
166821
167360
|
visibility,
|
|
166822
|
-
visibilityReader:
|
|
167361
|
+
visibilityReader: reader2
|
|
166823
167362
|
});
|
|
166824
167363
|
return {
|
|
166825
167364
|
content: [{
|
|
@@ -166830,7 +167369,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166830
167369
|
}
|
|
166831
167370
|
} else if (action2 === "evolve" && targetId) {
|
|
166832
167371
|
const targetObs = getObservation(targetId);
|
|
166833
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167372
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
166834
167373
|
await storeObservation({
|
|
166835
167374
|
entityName: targetObs.entityName,
|
|
166836
167375
|
type: targetObs.type,
|
|
@@ -166845,7 +167384,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166845
167384
|
sourceDetail: "explicit",
|
|
166846
167385
|
createdByAgentId: currentAgentId,
|
|
166847
167386
|
visibility,
|
|
166848
|
-
visibilityReader:
|
|
167387
|
+
visibilityReader: reader2
|
|
166849
167388
|
});
|
|
166850
167389
|
return {
|
|
166851
167390
|
content: [{
|
|
@@ -166872,12 +167411,12 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166872
167411
|
limit: 5,
|
|
166873
167412
|
projectId: project.id,
|
|
166874
167413
|
status: "active",
|
|
166875
|
-
reader
|
|
167414
|
+
reader: reader2
|
|
166876
167415
|
});
|
|
166877
167416
|
const similarEntries = searchResult.entries.map((e2) => e2);
|
|
166878
167417
|
if (similarEntries.length > 0) {
|
|
166879
167418
|
const similarIds = similarEntries.map((e2) => e2.id);
|
|
166880
|
-
const details = await compactDetail(similarIds, { reader });
|
|
167419
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
166881
167420
|
const existingMemories = details.documents.map((d, i2) => ({
|
|
166882
167421
|
id: d.observationId,
|
|
166883
167422
|
title: d.title,
|
|
@@ -166895,7 +167434,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166895
167434
|
);
|
|
166896
167435
|
if (decision.action === "UPDATE" && decision.targetId) {
|
|
166897
167436
|
const targetObs = getObservation(decision.targetId);
|
|
166898
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
167437
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
166899
167438
|
await storeObservation({
|
|
166900
167439
|
entityName: targetObs.entityName,
|
|
166901
167440
|
type: targetObs.type,
|
|
@@ -166910,7 +167449,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
166910
167449
|
sourceDetail: "explicit",
|
|
166911
167450
|
createdByAgentId: currentAgentId,
|
|
166912
167451
|
visibility,
|
|
166913
|
-
visibilityReader:
|
|
167452
|
+
visibilityReader: reader2
|
|
166914
167453
|
});
|
|
166915
167454
|
compactAction = `[UPDATED] Compact UPDATE: merged into #${decision.targetId} (${decision.reason})`;
|
|
166916
167455
|
compactMerged = true;
|
|
@@ -166997,7 +167536,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
166997
167536
|
const attrCheck = await checkProjectAttribution(
|
|
166998
167537
|
entityName,
|
|
166999
167538
|
project.id,
|
|
167000
|
-
filterReadableObservations(getAllObservations(),
|
|
167539
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
167001
167540
|
);
|
|
167002
167541
|
if (attrCheck.suspicious) {
|
|
167003
167542
|
attributionWarning = `
|
|
@@ -167024,7 +167563,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
167024
167563
|
valueCategory: formationResult?.evaluation.category,
|
|
167025
167564
|
createdByAgentId: currentAgentId,
|
|
167026
167565
|
visibility: requestedVisibility,
|
|
167027
|
-
visibilityReader:
|
|
167566
|
+
visibilityReader: reader2
|
|
167028
167567
|
});
|
|
167029
167568
|
let longTermNote = "";
|
|
167030
167569
|
if (longTerm) {
|
|
@@ -167039,8 +167578,8 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
167039
167578
|
applicability: longTerm.applicability,
|
|
167040
167579
|
reader: {
|
|
167041
167580
|
projectId: project.id,
|
|
167042
|
-
...
|
|
167043
|
-
...
|
|
167581
|
+
...reader2.agentId ? { agentId: reader2.agentId } : {},
|
|
167582
|
+
...reader2.isTeamMember ? { isTeamMember: true } : {}
|
|
167044
167583
|
}
|
|
167045
167584
|
});
|
|
167046
167585
|
const autoQualified = await maybeAutoQualifyLongTermMemory2({
|
|
@@ -167093,12 +167632,12 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167093
167632
|
limit: 5,
|
|
167094
167633
|
projectId: project.id,
|
|
167095
167634
|
status: "active",
|
|
167096
|
-
reader
|
|
167635
|
+
reader: reader2
|
|
167097
167636
|
});
|
|
167098
167637
|
const similarEntries = searchResult.entries.map((e2) => e2);
|
|
167099
167638
|
if (similarEntries.length > 0) {
|
|
167100
167639
|
const similarIds = similarEntries.map((e2) => e2.id);
|
|
167101
|
-
const details = await compactDetail(similarIds, { reader });
|
|
167640
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
167102
167641
|
const existingMemories = details.documents.map((d, i2) => ({
|
|
167103
167642
|
id: d.observationId,
|
|
167104
167643
|
title: d.title,
|
|
@@ -167124,9 +167663,9 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167124
167663
|
useLLM: isLLMEnabled(),
|
|
167125
167664
|
minValueScore: 0.3,
|
|
167126
167665
|
searchMemories: async (q, limit2, pid, signal) => {
|
|
167127
|
-
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
167666
|
+
const result = await compactSearch({ query: q, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
167128
167667
|
if (result.entries.length === 0) return [];
|
|
167129
|
-
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader });
|
|
167668
|
+
const details = await compactDetail(result.entries.map((e2) => e2.id), { reader: reader2 });
|
|
167130
167669
|
return details.documents.map((d, i2) => ({
|
|
167131
167670
|
id: Number(d.id.replace("obs-", "")),
|
|
167132
167671
|
observationId: d.observationId,
|
|
@@ -167140,7 +167679,7 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
167140
167679
|
},
|
|
167141
167680
|
getObservation: (id) => {
|
|
167142
167681
|
const o = getObservation(id);
|
|
167143
|
-
if (!o || o.projectId !== project.id || !canReadObservation(o,
|
|
167682
|
+
if (!o || o.projectId !== project.id || !canReadObservation(o, reader2)) return null;
|
|
167144
167683
|
return { id: o.id, entityName: o.entityName, type: o.type, title: o.title, narrative: o.narrative, facts: o.facts, topicKey: o.topicKey };
|
|
167145
167684
|
},
|
|
167146
167685
|
getEntityNames: () => graphManager.getEntityNames()
|
|
@@ -167908,10 +168447,10 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
167908
168447
|
async ({ ids, status }) => {
|
|
167909
168448
|
const { resolveObservations: resolveObservations2, getObservation: getObservation2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
167910
168449
|
const safeIds = (Array.isArray(ids) ? ids : [ids]).map((id) => coerceNumber(id, 0)).filter((id) => id > 0);
|
|
167911
|
-
const
|
|
168450
|
+
const reader2 = getObservationReader();
|
|
167912
168451
|
const authorizedIds = safeIds.filter((id) => {
|
|
167913
168452
|
const observation = getObservation2(id, project.id);
|
|
167914
|
-
return observation ? canManageObservation(observation,
|
|
168453
|
+
return observation ? canManageObservation(observation, reader2) : false;
|
|
167915
168454
|
});
|
|
167916
168455
|
const result = await resolveObservations2(authorizedIds, status ?? "resolved");
|
|
167917
168456
|
const deniedCount = safeIds.length - authorizedIds.length;
|
|
@@ -167954,7 +168493,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
167954
168493
|
async ({ entityName, decision, alternatives, rationale, constraints, expectedOutcome, risks, concepts, filesModified, relatedCommits, relatedEntities }) => {
|
|
167955
168494
|
const unresolved = requireResolvedProject("store reasoning in the current project");
|
|
167956
168495
|
if (unresolved) return unresolved;
|
|
167957
|
-
const
|
|
168496
|
+
const reader2 = getObservationReader();
|
|
167958
168497
|
return withFreshIndex(async () => {
|
|
167959
168498
|
const narrativeParts = [rationale];
|
|
167960
168499
|
if (alternatives && alternatives.length > 0) {
|
|
@@ -167980,7 +168519,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
167980
168519
|
const attrCheck = await checkProjectAttribution(
|
|
167981
168520
|
entityName,
|
|
167982
168521
|
project.id,
|
|
167983
|
-
filterReadableObservations(getAllObservations(),
|
|
168522
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
167984
168523
|
);
|
|
167985
168524
|
if (attrCheck.suspicious) {
|
|
167986
168525
|
reasoningAttributionWarning = `
|
|
@@ -168129,11 +168668,11 @@ ${result.formatted}` }]
|
|
|
168129
168668
|
},
|
|
168130
168669
|
async ({ query, dryRun }) => {
|
|
168131
168670
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
168132
|
-
const
|
|
168671
|
+
const reader2 = getObservationReader();
|
|
168133
168672
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
168134
168673
|
getAllObservations2().filter((o) => (o.status ?? "active") === "active" && o.projectId === project.id),
|
|
168135
|
-
|
|
168136
|
-
).filter((observation) => canManageObservation(observation,
|
|
168674
|
+
reader2
|
|
168675
|
+
).filter((observation) => canManageObservation(observation, reader2)));
|
|
168137
168676
|
if (allObs.length < 2) {
|
|
168138
168677
|
return { content: [{ type: "text", text: "Not enough active memories to deduplicate." }] };
|
|
168139
168678
|
}
|
|
@@ -168147,7 +168686,7 @@ ${result.formatted}` }]
|
|
|
168147
168686
|
}
|
|
168148
168687
|
let candidates;
|
|
168149
168688
|
if (query) {
|
|
168150
|
-
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader });
|
|
168689
|
+
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader: reader2 });
|
|
168151
168690
|
const idSet = new Set(searchResult.entries.map((e2) => e2.id));
|
|
168152
168691
|
candidates = allObs.filter((o) => idSet.has(o.id));
|
|
168153
168692
|
} else {
|
|
@@ -168156,64 +168695,33 @@ ${result.formatted}` }]
|
|
|
168156
168695
|
if (candidates.length < 2) {
|
|
168157
168696
|
return { content: [{ type: "text", text: "Not enough memories in scope to deduplicate." }] };
|
|
168158
168697
|
}
|
|
168159
|
-
const
|
|
168160
|
-
|
|
168161
|
-
|
|
168162
|
-
|
|
168163
|
-
|
|
168164
|
-
|
|
168165
|
-
|
|
168166
|
-
const toResolve = [];
|
|
168167
|
-
for (const [entity, group] of byEntity) {
|
|
168168
|
-
if (group.length < 2) continue;
|
|
168169
|
-
for (let i2 = 0; i2 < group.length; i2++) {
|
|
168170
|
-
for (let j = i2 + 1; j < group.length; j++) {
|
|
168171
|
-
const newer = group[j];
|
|
168172
|
-
const older = group[i2];
|
|
168173
|
-
try {
|
|
168174
|
-
const decision = await deduplicateMemory(
|
|
168175
|
-
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
168176
|
-
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
168177
|
-
);
|
|
168178
|
-
if (decision && decision.action === "UPDATE" && decision.targetId) {
|
|
168179
|
-
actions.push(`[UPDATED] #${older.id} "${older.title}" \u2192 superseded by #${newer.id} (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168180
|
-
toResolve.push(older.id);
|
|
168181
|
-
} else if (decision && decision.action === "NONE") {
|
|
168182
|
-
actions.push(`[DELETE] #${newer.id} "${newer.title}" \u2192 redundant (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168183
|
-
toResolve.push(newer.id);
|
|
168184
|
-
} else if (decision && decision.action === "DELETE") {
|
|
168185
|
-
actions.push(`[ERROR] #${decision.targetId ?? older.id} \u2192 outdated (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
168186
|
-
toResolve.push(decision.targetId ?? older.id);
|
|
168187
|
-
}
|
|
168188
|
-
} catch (dedupErr) {
|
|
168189
|
-
actions.push(`[WARN] comparison failed: ${dedupErr?.message ?? dedupErr}`);
|
|
168190
|
-
}
|
|
168191
|
-
}
|
|
168192
|
-
}
|
|
168193
|
-
}
|
|
168194
|
-
if (actions.length === 0) {
|
|
168195
|
-
return { content: [{ type: "text", text: `[OK] Scanned ${candidates.length} memories across ${byEntity.size} entities \u2014 no duplicates found.` }] };
|
|
168698
|
+
const manageableCandidates = candidates.filter((observation) => canManageObservation(observation, reader2));
|
|
168699
|
+
const plan = await planMemoryDeduplication(manageableCandidates);
|
|
168700
|
+
const actionLines = plan.actions.map(
|
|
168701
|
+
(item) => `Resolve #${item.resolveId} "${item.resolveTitle}"; keep #${item.keepId} "${item.keepTitle}" (${item.reason})${item.usedLLM ? " [LLM]" : " [heuristic]"}`
|
|
168702
|
+
);
|
|
168703
|
+
if (actionLines.length === 0) {
|
|
168704
|
+
return { content: [{ type: "text", text: `[OK] Scanned ${plan.scanned} memories across ${plan.entities} entities \u2014 no duplicates found.` }] };
|
|
168196
168705
|
}
|
|
168197
168706
|
if (dryRun) {
|
|
168198
168707
|
return {
|
|
168199
168708
|
content: [{
|
|
168200
168709
|
type: "text",
|
|
168201
|
-
text: `[SEARCH] DRY RUN \u2014 ${
|
|
168710
|
+
text: `[SEARCH] DRY RUN \u2014 ${actionLines.length} action(s) found:
|
|
168202
168711
|
|
|
168203
|
-
${
|
|
168712
|
+
${actionLines.join("\n")}
|
|
168204
168713
|
|
|
168205
168714
|
Run with dryRun=false to apply.`
|
|
168206
168715
|
}]
|
|
168207
168716
|
};
|
|
168208
168717
|
}
|
|
168209
|
-
const
|
|
168210
|
-
await resolveObservations2(unique2, "resolved");
|
|
168718
|
+
const result = await applyDeduplicationPlan(getObservationStore(), project.id, plan.resolveIds, reader2);
|
|
168211
168719
|
return {
|
|
168212
168720
|
content: [{
|
|
168213
168721
|
type: "text",
|
|
168214
|
-
text: `[CLEANUP] Deduplicated: resolved ${
|
|
168722
|
+
text: `[CLEANUP] Deduplicated: resolved ${result.resolved.length} memory(ies)
|
|
168215
168723
|
|
|
168216
|
-
${
|
|
168724
|
+
${actionLines.join("\n")}`
|
|
168217
168725
|
}]
|
|
168218
168726
|
};
|
|
168219
168727
|
}
|
|
@@ -168321,8 +168829,8 @@ ${actions.join("\n")}`
|
|
|
168321
168829
|
formatted.push(JSON.stringify({ durableMemory: details }, null, 2));
|
|
168322
168830
|
}
|
|
168323
168831
|
if (observationTypedRefs.length > 0 || safeRefs.length > 0 || safeIds.length > 0) {
|
|
168324
|
-
const
|
|
168325
|
-
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 });
|
|
168832
|
+
const reader2 = getObservationReader(hasCrossProjectRef ? "global" : "project");
|
|
168833
|
+
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 });
|
|
168326
168834
|
formatted.push(
|
|
168327
168835
|
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(", ")}`
|
|
168328
168836
|
);
|
|
@@ -168355,10 +168863,10 @@ ${actions.join("\n")}`
|
|
|
168355
168863
|
const { getDb: getDb2 } = await Promise.resolve().then(() => (init_orama_store(), orama_store_exports));
|
|
168356
168864
|
const { search: search2 } = await import("@orama/orama");
|
|
168357
168865
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
168358
|
-
const
|
|
168866
|
+
const reader2 = getObservationReader();
|
|
168359
168867
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
168360
168868
|
getAllObservations2().filter((observation) => observation.projectId === project.id),
|
|
168361
|
-
|
|
168869
|
+
reader2
|
|
168362
168870
|
));
|
|
168363
168871
|
const accessMap = /* @__PURE__ */ new Map();
|
|
168364
168872
|
try {
|
|
@@ -168408,7 +168916,7 @@ ${actions.join("\n")}`
|
|
|
168408
168916
|
}
|
|
168409
168917
|
if (action === "archive") {
|
|
168410
168918
|
const managedIds = new Set(
|
|
168411
|
-
allObs.filter((observation) => canManageObservation(observation,
|
|
168919
|
+
allObs.filter((observation) => canManageObservation(observation, reader2)).map((observation) => observation.id)
|
|
168412
168920
|
);
|
|
168413
168921
|
const candidates2 = getArchiveCandidates2(docs).filter((document2) => managedIds.has(document2.observationId));
|
|
168414
168922
|
if (candidates2.length === 0) {
|
|
@@ -169122,10 +169630,10 @@ ${skill2.content}` }]
|
|
|
169122
169630
|
}
|
|
169123
169631
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
169124
169632
|
const allObs = await withFreshIndex(() => getAllObservations2());
|
|
169125
|
-
const
|
|
169633
|
+
const reader2 = getObservationReader();
|
|
169126
169634
|
const matched = filterReadableObservations(
|
|
169127
169635
|
allObs.filter((observation) => observation.projectId === project.id && observationIds.includes(observation.id)),
|
|
169128
|
-
|
|
169636
|
+
reader2
|
|
169129
169637
|
);
|
|
169130
169638
|
if (matched.length === 0) {
|
|
169131
169639
|
return { content: [{ type: "text", text: `No observations found for IDs: [${observationIds.join(", ")}]. Use \`memorix_search\` to find valid IDs.` }], isError: true };
|