@cortexkit/pi-magic-context 0.45.0 → 0.46.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/dist/embedding-worker.js +4 -4
- package/dist/{index-j0mbc5vj.js → index-266qrgss.js} +59 -1
- package/dist/index-2p1e8706.js +30 -0
- package/dist/{index-k0yd1ph9.js → index-4vfrjwf6.js} +129 -166
- package/dist/{index-g0xfx1c2.js → index-phh7e055.js} +16 -1
- package/dist/{index-ttf0cqq8.js → index-r01b1b78.js} +25 -24
- package/dist/index-td885aah.js +576 -0
- package/dist/index-vf38qhee.js +150 -0
- package/dist/{index-2pbbk3en.js → index-wv28nczk.js} +55 -1
- package/dist/{index-vxjgsr9m.js → index-xvw8zptx.js} +3565 -3349
- package/dist/{index-2bw9k8nx.js → index-ykb8kkm3.js} +1310 -1021
- package/dist/index.js +3309 -1480
- package/dist/{message-time-backfill-g83dkh8m.js → message-time-backfill-4688z1k2.js} +2 -2
- package/dist/migration-worker.js +11 -6
- package/dist/{read-session-chunk-kmt7a6zj.js → read-session-chunk-tc6yn2pe.js} +5 -5
- package/dist/subagent-entry.js +10 -10
- package/package.json +4 -3
- package/dist/index-4d3cba70.js +0 -10
- package/dist/index-7s5yk3za.js +0 -16
- package/dist/index-e16q5sd7.js +0 -240
package/dist/embedding-worker.js
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
resolveLocalEmbeddingWorkerRuntime,
|
|
7
7
|
getLocalEmbeddingNativeMemoryStats,
|
|
8
8
|
LocalEmbeddingProvider
|
|
9
|
-
} from "./index-
|
|
10
|
-
import"./index-
|
|
11
|
-
import"./index-
|
|
9
|
+
} from "./index-r01b1b78.js";
|
|
10
|
+
import"./index-phh7e055.js";
|
|
11
|
+
import"./index-266qrgss.js";
|
|
12
12
|
import {
|
|
13
13
|
setStoragePrivatePermissionEnforcement
|
|
14
|
-
} from "./index-
|
|
14
|
+
} from "./index-vf38qhee.js";
|
|
15
15
|
|
|
16
16
|
// ../plugin/src/features/magic-context/memory/embedding-worker.ts
|
|
17
17
|
import { parentPort, workerData } from "node:worker_threads";
|
|
@@ -287,6 +287,9 @@ function getTokenEstimatorFingerprint() {
|
|
|
287
287
|
function hasTokenizerForFit() {
|
|
288
288
|
return getTokenizer() !== undefined;
|
|
289
289
|
}
|
|
290
|
+
function tokenCountUsesByteBound(text) {
|
|
291
|
+
return text.length > 1024 * 1024 || /[\p{L}\p{N}]{16385}/u.test(text);
|
|
292
|
+
}
|
|
290
293
|
function estimateTokens(text) {
|
|
291
294
|
if (!text)
|
|
292
295
|
return 0;
|
|
@@ -302,6 +305,61 @@ function estimateTokens(text) {
|
|
|
302
305
|
return estimateTokensHeuristically(text);
|
|
303
306
|
}
|
|
304
307
|
}
|
|
308
|
+
function createTokenCountMemo(maxEntries, maxBytes) {
|
|
309
|
+
const counts = new Map;
|
|
310
|
+
let bytes = 0;
|
|
311
|
+
return (text) => {
|
|
312
|
+
const cached = counts.get(text);
|
|
313
|
+
if (cached && cached.tokenizer === getTokenizer())
|
|
314
|
+
return cached.tokens;
|
|
315
|
+
const tokens = estimateTokens(text);
|
|
316
|
+
if (cached) {
|
|
317
|
+
bytes -= text.length * 2;
|
|
318
|
+
counts.delete(text);
|
|
319
|
+
}
|
|
320
|
+
if (text.length * 2 <= maxBytes) {
|
|
321
|
+
while (counts.size >= maxEntries || bytes + text.length * 2 > maxBytes) {
|
|
322
|
+
const oldest = counts.keys().next().value;
|
|
323
|
+
if (oldest === undefined)
|
|
324
|
+
break;
|
|
325
|
+
bytes -= oldest.length * 2;
|
|
326
|
+
counts.delete(oldest);
|
|
327
|
+
}
|
|
328
|
+
counts.set(text, { tokenizer: getTokenizer(), tokens });
|
|
329
|
+
bytes += text.length * 2;
|
|
330
|
+
}
|
|
331
|
+
return tokens;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
var promptTokenCounts = new Map;
|
|
335
|
+
var promptTokenCountBytes = 0;
|
|
336
|
+
var PROMPT_TOKEN_COUNT_BYTES = 8 * 1024 * 1024;
|
|
337
|
+
function estimateFixedPromptTokens(text) {
|
|
338
|
+
const activeTokenizer = getTokenizer();
|
|
339
|
+
const cached = promptTokenCounts.get(text);
|
|
340
|
+
if (cached && cached.tokenizer === activeTokenizer) {
|
|
341
|
+
promptTokenCounts.delete(text);
|
|
342
|
+
promptTokenCounts.set(text, cached);
|
|
343
|
+
return cached.tokens;
|
|
344
|
+
}
|
|
345
|
+
const tokens = estimateTokens(text);
|
|
346
|
+
if (cached) {
|
|
347
|
+
promptTokenCountBytes -= text.length * 2;
|
|
348
|
+
promptTokenCounts.delete(text);
|
|
349
|
+
}
|
|
350
|
+
if (text.length * 2 <= PROMPT_TOKEN_COUNT_BYTES) {
|
|
351
|
+
while (promptTokenCounts.size >= 64 || promptTokenCountBytes + text.length * 2 > PROMPT_TOKEN_COUNT_BYTES) {
|
|
352
|
+
const oldest = promptTokenCounts.keys().next().value;
|
|
353
|
+
if (oldest === undefined)
|
|
354
|
+
break;
|
|
355
|
+
promptTokenCountBytes -= oldest.length * 2;
|
|
356
|
+
promptTokenCounts.delete(oldest);
|
|
357
|
+
}
|
|
358
|
+
promptTokenCounts.set(text, { tokenizer: getTokenizer(), tokens });
|
|
359
|
+
promptTokenCountBytes += text.length * 2;
|
|
360
|
+
}
|
|
361
|
+
return tokens;
|
|
362
|
+
}
|
|
305
363
|
function normalizeText(text) {
|
|
306
364
|
return text.replace(/\s+/g, " ").trim();
|
|
307
365
|
}
|
|
@@ -356,4 +414,4 @@ function mergeCommitHashes(existing, next) {
|
|
|
356
414
|
return merged;
|
|
357
415
|
}
|
|
358
416
|
|
|
359
|
-
export { textMentionsRecentCommit, OMO_INTERNAL_INITIATOR_MARKER, isSystemDirective, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, extractToolResultBodyTokens, extractToolCallSummaries, preloadTokenizer, getTokenEstimatorFingerprint, hasTokenizerForFit, estimateTokens, normalizeText, compactRole, formatBlock, compactTextForSummary, mergeCommitHashes };
|
|
417
|
+
export { textMentionsRecentCommit, OMO_INTERNAL_INITIATOR_MARKER, isSystemDirective, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, extractToolResultBodyTokens, extractToolCallSummaries, preloadTokenizer, getTokenEstimatorFingerprint, hasTokenizerForFit, tokenCountUsesByteBound, estimateTokens, createTokenCountMemo, estimateFixedPromptTokens, normalizeText, compactRole, formatBlock, compactTextForSummary, mergeCommitHashes };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
log
|
|
3
|
+
} from "./index-7n8gb6j3.js";
|
|
4
|
+
|
|
5
|
+
// ../plugin/src/shared/write-transaction-timing.ts
|
|
6
|
+
var SLOW_WRITE_TRANSACTION_THRESHOLD_MS = 1000;
|
|
7
|
+
function logSlowWriteTransaction(site, startedAt, thresholdMs = SLOW_WRITE_TRANSACTION_THRESHOLD_MS, completedAtMs = performance.now(), steps) {
|
|
8
|
+
try {
|
|
9
|
+
const durationMs = completedAtMs - startedAt;
|
|
10
|
+
if (durationMs < thresholdMs)
|
|
11
|
+
return;
|
|
12
|
+
const detail = steps ? Object.entries(steps).map(([name, ms]) => `${name}=${ms.toFixed(1)}ms`).join(" ") : "";
|
|
13
|
+
log(`[magic-context] slow write transaction: site=${site} held=${durationMs.toFixed(1)}ms${detail ? ` ${detail}` : ""}`);
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class WriteTransactionSteps {
|
|
18
|
+
durations = {};
|
|
19
|
+
last = performance.now();
|
|
20
|
+
mark(name) {
|
|
21
|
+
const now = performance.now();
|
|
22
|
+
this.durations[name] = now - this.last;
|
|
23
|
+
this.last = now;
|
|
24
|
+
}
|
|
25
|
+
reset() {
|
|
26
|
+
this.last = performance.now();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { logSlowWriteTransaction, WriteTransactionSteps };
|