@cortexkit/pi-magic-context 0.49.70 → 0.49.72
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/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{embedding-backfill-3g3cm51d.js → embedding-backfill-p0qszhx7.js} +2 -2
- package/dist/{index-73fw4cd4.js → index-6gwasf0v.js} +17 -3
- package/dist/{index-sg6tdkqh.js → index-9a92hc6c.js} +1 -1
- package/dist/{index-2kb65n0s.js → index-apff8dej.js} +1 -1
- package/dist/{index-2bavnrw8.js → index-cevw58nn.js} +99 -8
- package/dist/{index-4dqwxb7k.js → index-cyzsn2hb.js} +1 -1
- package/dist/{index-bcwy4wm1.js → index-dw9x7k2b.js} +8 -8
- package/dist/{index-tcrd11cb.js → index-kqekqrzw.js} +3 -3
- package/dist/{index-d7yx4ymd.js → index-mm9y1m77.js} +1 -1
- package/dist/{index-zgj2mxrn.js → index-r4qt07th.js} +3 -3
- package/dist/index-w2snpk0j.js +65 -0
- package/dist/{index-51xr6g7s.js → index-wmkkxwvf.js} +1 -1
- package/dist/{index-e9wkbh8y.js → index-yk0ve8hn.js} +4 -3
- package/dist/index.js +169 -98
- package/dist/{message-index-bounded-fqeqp76p.js → message-index-bounded-cv87994v.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-63wsm3a8.js → project-embedding-registry-2natnvdf.js} +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-tjj2wzxs.js → read-session-chunk-ygwyfvtr.js} +2 -2
- package/dist/{render-793jtz3r.js → render-bsdcxgaq.js} +5 -5
- package/dist/{search-archive-gmyvkadj.js → search-archive-3hh7ycvm.js} +4 -4
- package/dist/{search-7tpgsnbs.js → search-hm8dc1e8.js} +6 -6
- package/dist/{storage-tags-wq8p5wrh.js → storage-tags-zzttnzn6.js} +1 -1
- package/dist/subagent-entry.js +11 -11
- package/dist/tag-snapshot-worker-pi.js +3 -3
- package/dist/{v2-archive-reader-99stcer0.js → v2-archive-reader-b7spmyqa.js} +1 -1
- package/package.json +1 -1
- package/dist/index-qdy49kwk.js +0 -155
|
@@ -27,11 +27,11 @@ serveWorkerJobs(async (initial, port) => {
|
|
|
27
27
|
{ Database, registerSqliteDiagnosticSink },
|
|
28
28
|
{ log }
|
|
29
29
|
] = await Promise.all([
|
|
30
|
-
import("./embedding-backfill-
|
|
30
|
+
import("./embedding-backfill-p0qszhx7.js"),
|
|
31
31
|
import("./embedding-cache-7rp4gqzr.js"),
|
|
32
32
|
import("./storage-memory-0ndn65fm.js"),
|
|
33
|
-
import("./project-embedding-registry-
|
|
34
|
-
import("./search-
|
|
33
|
+
import("./project-embedding-registry-2natnvdf.js"),
|
|
34
|
+
import("./search-hm8dc1e8.js"),
|
|
35
35
|
import("./compartment-chunk-embedding-avkyp2df.js"),
|
|
36
36
|
import("./embedding-activity-ew6dshfd.js"),
|
|
37
37
|
import("./harness-9872e0ym.js"),
|
|
@@ -2770,16 +2770,30 @@ function isAnthropicFamilyRoute(providerID, modelID) {
|
|
|
2770
2770
|
var REMOVED_REASONING_MARK = Symbol.for("magic-context.removed-reasoning");
|
|
2771
2771
|
var NEUTRALIZED_ORIGINALS = new WeakMap;
|
|
2772
2772
|
var VARIANT_CACHE_PRESERVING_MODELS = {
|
|
2773
|
-
"anthropic/claude-fable-5-1": "2026-09-02",
|
|
2774
|
-
"openai/gpt-6-astra": "2026-09-05",
|
|
2775
|
-
"anthropic/claude-opus-5-5": "2026-09-23"
|
|
2773
|
+
"anthropic/claude-fable-5-1": ["2026-09-02"],
|
|
2774
|
+
"openai/gpt-6-astra": ["2026-09-05"],
|
|
2775
|
+
"anthropic/claude-opus-5-5": ["2026-09-23", true],
|
|
2776
|
+
"anthropic/claude-sonnet-5-5": ["2026-11-23", true],
|
|
2777
|
+
"anthropic/claude-haiku-5-5": ["2026-11-23", true],
|
|
2778
|
+
"anthropic/claude-fable-5-2": ["2026-11-23", true],
|
|
2779
|
+
"anthropic/claude-mythos-5-1": ["2026-11-23", true],
|
|
2780
|
+
"anthropic/claude-mythos-5-2": ["2026-11-23", true]
|
|
2776
2781
|
};
|
|
2782
|
+
var CLAUDE_VARIANT_ALIAS = /^(?:(?:[a-z0-9-]+\.)?anthropic\.)?(?:claude-)?([a-z]+)[-_.]?([0-9]+)[-_.]([0-9]+)(?:[-@][0-9]{8})?(?:-v[0-9]+:[0-9]+)?$/i;
|
|
2777
2783
|
function canonicalVariantModelIdentity(providerID, modelID) {
|
|
2778
2784
|
const normalizedProviderID = providerID.toLowerCase();
|
|
2779
2785
|
const isAnthropicFamily = normalizedProviderID === "anthropic" || normalizedProviderID === "google-vertex-anthropic" || normalizedProviderID.includes("bedrock");
|
|
2780
2786
|
if (isAnthropicFamily && isFable51ThinkingBindingModel("anthropic", modelID)) {
|
|
2781
2787
|
return "anthropic/claude-fable-5-1";
|
|
2782
2788
|
}
|
|
2789
|
+
if (isAnthropicFamily) {
|
|
2790
|
+
const alias = CLAUDE_VARIANT_ALIAS.exec(modelID.split("/").at(-1) ?? "");
|
|
2791
|
+
if (alias) {
|
|
2792
|
+
const identity = `anthropic/claude-${alias[1].toLowerCase()}-${alias[2]}-${alias[3]}`;
|
|
2793
|
+
if (VARIANT_CACHE_PRESERVING_MODELS[identity]?.[1])
|
|
2794
|
+
return identity;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2783
2797
|
return canonicalModelIdentity(`${providerID}/${modelID}`).toLowerCase();
|
|
2784
2798
|
}
|
|
2785
2799
|
function variantChangeBustsProviderCache(providerID, modelID) {
|
|
@@ -1787,7 +1787,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1787
1787
|
state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
|
|
1788
1788
|
if (signal.aborted || !readsOpenCodeStore)
|
|
1789
1789
|
return;
|
|
1790
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1790
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-ygwyfvtr.js"));
|
|
1791
1791
|
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-8zwv9byv.js"));
|
|
1792
1792
|
if (signal.aborted)
|
|
1793
1793
|
return;
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
PROMOTABLE_CATEGORIES,
|
|
6
6
|
CATEGORY_DEFAULT_TTL
|
|
7
7
|
} from "./index-135e8hvg.js";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
10
|
+
} from "./index-vcegxfwg.js";
|
|
8
11
|
import {
|
|
9
12
|
getHarness2
|
|
10
13
|
} from "./index-0h2mkab2.js";
|
|
@@ -14,7 +17,9 @@ import {
|
|
|
14
17
|
sessionLog2
|
|
15
18
|
} from "./index-tm11k42a.js";
|
|
16
19
|
import {
|
|
17
|
-
SubcClient
|
|
20
|
+
SubcClient,
|
|
21
|
+
isSynapseEmbeddingTruncated,
|
|
22
|
+
SynapseEmbeddingProvider
|
|
18
23
|
} from "./index-5rcjs14a.js";
|
|
19
24
|
import {
|
|
20
25
|
inRootAsyncContext2,
|
|
@@ -32,6 +37,10 @@ import {
|
|
|
32
37
|
warmCompartmentChunkSearchPool2
|
|
33
38
|
} from "./index-cxczethe.js";
|
|
34
39
|
import {
|
|
40
|
+
LocalEmbeddingProvider
|
|
41
|
+
} from "./index-txcs0vnj.js";
|
|
42
|
+
import {
|
|
43
|
+
OpenAICompatibleEmbeddingProvider,
|
|
35
44
|
saveCommitEmbedding,
|
|
36
45
|
loadProjectCommitEmbeddings,
|
|
37
46
|
loadUnembeddedCommits,
|
|
@@ -47,7 +56,7 @@ import {
|
|
|
47
56
|
getProjectEmbeddingSnapshot2,
|
|
48
57
|
embedTextForProject2,
|
|
49
58
|
embedItemsForProject2
|
|
50
|
-
} from "./index-
|
|
59
|
+
} from "./index-yk0ve8hn.js";
|
|
51
60
|
import {
|
|
52
61
|
recordEmbeddingMeasurement
|
|
53
62
|
} from "./index-hgd00nas.js";
|
|
@@ -59,11 +68,8 @@ import {
|
|
|
59
68
|
getProjectEmbeddings2
|
|
60
69
|
} from "./index-yhzhdp3m.js";
|
|
61
70
|
import {
|
|
62
|
-
cosineSimilarity,
|
|
63
|
-
isEmbeddingEnabled,
|
|
64
|
-
embedText,
|
|
65
71
|
ensureMemoryEmbeddings2
|
|
66
|
-
} from "./index-
|
|
72
|
+
} from "./index-w2snpk0j.js";
|
|
67
73
|
import {
|
|
68
74
|
getMemorySelectColumns2,
|
|
69
75
|
isMemoryRow2,
|
|
@@ -91,7 +97,7 @@ import {
|
|
|
91
97
|
clearIndexedMessages,
|
|
92
98
|
indexSingleMessage,
|
|
93
99
|
indexMessagesAfterOrdinal
|
|
94
|
-
} from "./index-
|
|
100
|
+
} from "./index-mm9y1m77.js";
|
|
95
101
|
import {
|
|
96
102
|
MESSAGE_FTS_SESSION_FILTER_SQL,
|
|
97
103
|
withMessageFtsSessionFilter
|
|
@@ -463,6 +469,91 @@ function projectNeedsSingleStoreMigration(db, projectPath) {
|
|
|
463
469
|
const table = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'authority_managed'").get();
|
|
464
470
|
return Boolean(table && db.prepare("SELECT 1 FROM authority_managed WHERE project_path = ?").get(projectPath));
|
|
465
471
|
}
|
|
472
|
+
// ../plugin/src/features/magic-context/memory/cosine-similarity.ts
|
|
473
|
+
function cosineSimilarity(a, b) {
|
|
474
|
+
if (a.length !== b.length) {
|
|
475
|
+
return 0;
|
|
476
|
+
}
|
|
477
|
+
let dotProduct = 0;
|
|
478
|
+
let normA = 0;
|
|
479
|
+
let normB = 0;
|
|
480
|
+
for (let index = 0;index < a.length; index++) {
|
|
481
|
+
dotProduct += a[index] * b[index];
|
|
482
|
+
normA += a[index] * a[index];
|
|
483
|
+
normB += b[index] * b[index];
|
|
484
|
+
}
|
|
485
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
486
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// ../plugin/src/features/magic-context/memory/embedding.ts
|
|
490
|
+
var DEFAULT_EMBEDDING_CONFIG = {
|
|
491
|
+
provider: "local",
|
|
492
|
+
model: DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
493
|
+
local_runtime: "auto"
|
|
494
|
+
};
|
|
495
|
+
var embeddingConfig = DEFAULT_EMBEDDING_CONFIG;
|
|
496
|
+
var provider = null;
|
|
497
|
+
function createProvider(config) {
|
|
498
|
+
if (config.provider === "off") {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
if (config.provider === "openai-compatible") {
|
|
502
|
+
return new OpenAICompatibleEmbeddingProvider({
|
|
503
|
+
endpoint: config.endpoint,
|
|
504
|
+
model: config.model,
|
|
505
|
+
apiKey: config.api_key,
|
|
506
|
+
inputType: config.input_type,
|
|
507
|
+
queryInputType: config.query_input_type,
|
|
508
|
+
queryInstruction: config.query_instruction,
|
|
509
|
+
documentPrefix: config.document_prefix,
|
|
510
|
+
truncate: config.truncate,
|
|
511
|
+
dimensions: config.dimensions,
|
|
512
|
+
maxInputTokens: config.max_input_tokens
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (config.provider === "local") {
|
|
516
|
+
return new LocalEmbeddingProvider(config.model, config.max_input_tokens, config.local_dtype, config.local_runtime);
|
|
517
|
+
}
|
|
518
|
+
if (config.provider === "synapse") {
|
|
519
|
+
const synapse = config;
|
|
520
|
+
return new SynapseEmbeddingProvider({
|
|
521
|
+
connectionFile: synapse.synapse_connection_file ?? "",
|
|
522
|
+
projectRoot: "",
|
|
523
|
+
session: "embedding",
|
|
524
|
+
model: synapse.model,
|
|
525
|
+
fingerprint: synapse.synapse_fingerprint,
|
|
526
|
+
tableEpoch: synapse.synapse_table_epoch,
|
|
527
|
+
dims: synapse.synapse_dims,
|
|
528
|
+
recommendedBatch: synapse.synapse_recommended_batch,
|
|
529
|
+
recommendedTokenBudget: synapse.synapse_recommended_token_budget,
|
|
530
|
+
descriptor: synapse.synapse_descriptor,
|
|
531
|
+
provenance: synapse.synapse_provenance
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
throw new Error("Unknown embedding provider");
|
|
535
|
+
}
|
|
536
|
+
function getOrCreateProvider() {
|
|
537
|
+
if (provider) {
|
|
538
|
+
return provider;
|
|
539
|
+
}
|
|
540
|
+
provider = createProvider(embeddingConfig);
|
|
541
|
+
return provider;
|
|
542
|
+
}
|
|
543
|
+
function isEmbeddingEnabled() {
|
|
544
|
+
return embeddingConfig.provider !== "off";
|
|
545
|
+
}
|
|
546
|
+
async function embedText(text, signal) {
|
|
547
|
+
const currentProvider = getOrCreateProvider();
|
|
548
|
+
if (!currentProvider) {
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
if (!await currentProvider.initialize()) {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
const vector = await currentProvider.embed(text, signal);
|
|
555
|
+
return vector && !isSynapseEmbeddingTruncated(vector) ? vector : null;
|
|
556
|
+
}
|
|
466
557
|
// ../plugin/src/features/magic-context/memory/promotion.ts
|
|
467
558
|
function isPromotableCategory(category) {
|
|
468
559
|
return PROMOTABLE_CATEGORIES.some((promotableCategory) => promotableCategory === category);
|
|
@@ -3891,4 +3982,4 @@ ${bodyParts.join(`
|
|
|
3891
3982
|
`)}`;
|
|
3892
3983
|
}
|
|
3893
3984
|
|
|
3894
|
-
export { USER_FACING_FAILURES, renderUserFacingFailure, userFacingFailureCode, renderCapabilityRefusal, renderDreamFailure, dreamFailureCode, renderEmbeddingFailure, renderSingleStoreMigrationRequiredRefusal, SingleStoreMigrationRequiredError, projectNeedsSingleStoreMigration, promoteSessionFactsDurable, embedPromotedFacts, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, indexCommitsForProject, embedUnembeddedCommits, getMessageIndexEpoch, isMessageIndexSearchable, scheduleReconciliation, scheduleIncrementalIndex, scheduleClearAndReindex, clearSessionTracking, createAutoSearchDiagnostics, createUnifiedSearchDiagnostics2, searchMessageHistory2, parseIdShapedQuery2, resolveMemoriesByIdsForSearch2, unifiedSearch2, formatSearchResults2 };
|
|
3985
|
+
export { USER_FACING_FAILURES, renderUserFacingFailure, userFacingFailureCode, renderCapabilityRefusal, renderDreamFailure, dreamFailureCode, renderEmbeddingFailure, renderSingleStoreMigrationRequiredRefusal, SingleStoreMigrationRequiredError, projectNeedsSingleStoreMigration, cosineSimilarity, promoteSessionFactsDurable, embedPromotedFacts, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, indexCommitsForProject, embedUnembeddedCommits, getMessageIndexEpoch, isMessageIndexSearchable, scheduleReconciliation, scheduleIncrementalIndex, scheduleClearAndReindex, clearSessionTracking, createAutoSearchDiagnostics, createUnifiedSearchDiagnostics2, searchMessageHistory2, parseIdShapedQuery2, resolveMemoriesByIdsForSearch2, unifiedSearch2, formatSearchResults2 };
|
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
import {
|
|
57
57
|
piHarnessKindFromExecutable,
|
|
58
58
|
getErrorMessage
|
|
59
|
-
} from "./index-
|
|
59
|
+
} from "./index-9a92hc6c.js";
|
|
60
60
|
import {
|
|
61
61
|
getOrCreateSessionMeta,
|
|
62
62
|
updateSessionMeta,
|
|
@@ -70,10 +70,10 @@ import {
|
|
|
70
70
|
renderMessageByOrdinal2,
|
|
71
71
|
renderVerboseRange2,
|
|
72
72
|
renderItemByTag2
|
|
73
|
-
} from "./index-
|
|
73
|
+
} from "./index-kqekqrzw.js";
|
|
74
74
|
import {
|
|
75
75
|
getLastIndexedOrdinal
|
|
76
|
-
} from "./index-
|
|
76
|
+
} from "./index-mm9y1m77.js";
|
|
77
77
|
import {
|
|
78
78
|
TODO_STATUSES,
|
|
79
79
|
TODO_PRIORITIES,
|
|
@@ -89,7 +89,7 @@ import {
|
|
|
89
89
|
getCompactionMarkerPublicationState,
|
|
90
90
|
compareAndSetCompactionMarkerPublicationState,
|
|
91
91
|
getDeferredClearedCompactionMarkerState
|
|
92
|
-
} from "./index-
|
|
92
|
+
} from "./index-6gwasf0v.js";
|
|
93
93
|
import {
|
|
94
94
|
stableStringify,
|
|
95
95
|
BoundedSessionMap
|
|
@@ -129,7 +129,7 @@ import {
|
|
|
129
129
|
unregisterProjectEmbedding2,
|
|
130
130
|
getProjectEmbeddingSnapshot2,
|
|
131
131
|
embedTextForProject2
|
|
132
|
-
} from "./index-
|
|
132
|
+
} from "./index-yk0ve8hn.js";
|
|
133
133
|
import {
|
|
134
134
|
directoryHasGitMetadata,
|
|
135
135
|
resolveProjectIdentityForSession,
|
|
@@ -142,7 +142,7 @@ import {
|
|
|
142
142
|
resolveMemoriesByIdsForSearch2,
|
|
143
143
|
unifiedSearch2,
|
|
144
144
|
formatSearchResults2
|
|
145
|
-
} from "./index-
|
|
145
|
+
} from "./index-cevw58nn.js";
|
|
146
146
|
import {
|
|
147
147
|
resolveOpenCodeDbPath,
|
|
148
148
|
assertOpenCodeStoreGeneration
|
|
@@ -151,7 +151,7 @@ import {
|
|
|
151
151
|
hasRawMessageProvider2,
|
|
152
152
|
setRawMessageProvider2,
|
|
153
153
|
readSessionChunk2
|
|
154
|
-
} from "./index-
|
|
154
|
+
} from "./index-apff8dej.js";
|
|
155
155
|
import {
|
|
156
156
|
resolveWorkspaceShareCategories,
|
|
157
157
|
resolveWorkspaceIdentitySet,
|
|
@@ -184,7 +184,7 @@ import {
|
|
|
184
184
|
} from "./index-3s39a1md.js";
|
|
185
185
|
import {
|
|
186
186
|
renderSearchArchive2
|
|
187
|
-
} from "./index-
|
|
187
|
+
} from "./index-cyzsn2hb.js";
|
|
188
188
|
import {
|
|
189
189
|
computeNormalizedHash
|
|
190
190
|
} from "./index-9x1f96r8.js";
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
serializeProcessedImageMarkers,
|
|
41
41
|
getPendingPiCompactionMarkerState,
|
|
42
42
|
logPiCompactionMarkerClear
|
|
43
|
-
} from "./index-
|
|
43
|
+
} from "./index-6gwasf0v.js";
|
|
44
44
|
import {
|
|
45
45
|
estimateTokens
|
|
46
46
|
} from "./index-pefn1gt5.js";
|
|
@@ -61,13 +61,13 @@ import {
|
|
|
61
61
|
import {
|
|
62
62
|
isPidAlive,
|
|
63
63
|
readProcessStartTime
|
|
64
|
-
} from "./index-
|
|
64
|
+
} from "./index-9a92hc6c.js";
|
|
65
65
|
import {
|
|
66
66
|
withReadOnlySessionDb,
|
|
67
67
|
expandToolPart,
|
|
68
68
|
visitRawSessionMessages2,
|
|
69
69
|
readRawSessionMessageById2
|
|
70
|
-
} from "./index-
|
|
70
|
+
} from "./index-apff8dej.js";
|
|
71
71
|
import {
|
|
72
72
|
gaDatabasePath2,
|
|
73
73
|
V2StoreReader2
|
|
@@ -139,9 +139,9 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
139
139
|
import("./sqlite-v89bj0yy.js"),
|
|
140
140
|
import("./store-reader-mmfw2h48.js"),
|
|
141
141
|
import("./store-grcwn6hs.js"),
|
|
142
|
-
import("./read-session-chunk-
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
142
|
+
import("./read-session-chunk-ygwyfvtr.js"),
|
|
143
|
+
import("./render-bsdcxgaq.js"),
|
|
144
|
+
import("./search-archive-3hh7ycvm.js"),
|
|
145
145
|
import("./expand-attachments-8sxeyj26.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEmbeddingHostBusy2
|
|
3
|
+
} from "./index-9p40dgkm.js";
|
|
4
|
+
import {
|
|
5
|
+
log2
|
|
6
|
+
} from "./index-tm11k42a.js";
|
|
7
|
+
import {
|
|
8
|
+
contentSha2562,
|
|
9
|
+
getProjectEmbeddingSnapshot2,
|
|
10
|
+
embedItemsWindowBounded2
|
|
11
|
+
} from "./index-yk0ve8hn.js";
|
|
12
|
+
import {
|
|
13
|
+
saveEmbeddingIfHashMatches
|
|
14
|
+
} from "./index-yhzhdp3m.js";
|
|
15
|
+
|
|
16
|
+
// ../plugin/src/features/magic-context/memory/embedding-backfill.ts
|
|
17
|
+
var SEARCH_BACKFILL_LIMIT = 50;
|
|
18
|
+
var SEARCH_BACKFILL_REQUEST_SIZE = 10;
|
|
19
|
+
async function ensureMemoryEmbeddings2(args) {
|
|
20
|
+
if (isEmbeddingHostBusy2())
|
|
21
|
+
return args.existingEmbeddings;
|
|
22
|
+
const snapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
23
|
+
if (!snapshot?.enabled) {
|
|
24
|
+
return args.existingEmbeddings;
|
|
25
|
+
}
|
|
26
|
+
const missingMemories = args.memories.filter((memory) => !args.existingEmbeddings.has(memory.id)).sort((a, b) => a.id - b.id).slice(0, SEARCH_BACKFILL_LIMIT);
|
|
27
|
+
if (missingMemories.length === 0) {
|
|
28
|
+
return args.existingEmbeddings;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const result = await embedItemsWindowBounded2(args.projectIdentity, missingMemories.map((memory) => ({
|
|
32
|
+
id: `memory:${memory.id}`,
|
|
33
|
+
text: memory.content,
|
|
34
|
+
contentSha256: contentSha2562(memory.content)
|
|
35
|
+
})), undefined, args.db, args.projectIdentity, { maxItemsPerCall: SEARCH_BACKFILL_REQUEST_SIZE });
|
|
36
|
+
if (!result) {
|
|
37
|
+
return args.existingEmbeddings;
|
|
38
|
+
}
|
|
39
|
+
const staged = new Map;
|
|
40
|
+
args.db.transaction(() => {
|
|
41
|
+
for (const memory of missingMemories) {
|
|
42
|
+
const embedding = result.vectors.get(`memory:${memory.id}`);
|
|
43
|
+
if (!embedding) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const saved = saveEmbeddingIfHashMatches(args.db, memory.id, embedding, result.modelId, memory.normalizedHash);
|
|
47
|
+
if (saved) {
|
|
48
|
+
staged.set(memory.id, { embedding, modelId: result.modelId });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}).immediate();
|
|
52
|
+
const currentSnapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
53
|
+
if (!currentSnapshot || currentSnapshot.generation !== result.generation) {
|
|
54
|
+
return args.existingEmbeddings;
|
|
55
|
+
}
|
|
56
|
+
for (const [id, embedding] of staged) {
|
|
57
|
+
args.existingEmbeddings.set(id, embedding);
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
log2("[magic-context] failed to backfill memory embeddings:", error);
|
|
61
|
+
}
|
|
62
|
+
return args.existingEmbeddings;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ensureMemoryEmbeddings2 };
|
|
@@ -2558,14 +2558,15 @@ async function embedItemsForProject2(projectIdentity, items, signal, db, session
|
|
|
2558
2558
|
return { vectors, modelId, generation };
|
|
2559
2559
|
}
|
|
2560
2560
|
async function embedItemsWindowBounded2(projectIdentity, items, signal, db, sessionId = projectIdentity, options = {}) {
|
|
2561
|
-
|
|
2561
|
+
const maxItemsPerCall = options.maxItemsPerCall ?? MAX_WINDOWS_PER_EMBED_CALL;
|
|
2562
|
+
if (items.length <= maxItemsPerCall) {
|
|
2562
2563
|
return embedItemsForProject2(projectIdentity, items, signal, db, sessionId);
|
|
2563
2564
|
}
|
|
2564
2565
|
const vectors = new Map;
|
|
2565
2566
|
let modelId = null;
|
|
2566
2567
|
let generation = null;
|
|
2567
|
-
for (let start = 0;start < items.length; start +=
|
|
2568
|
-
const slice = items.slice(start, start +
|
|
2568
|
+
for (let start = 0;start < items.length; start += maxItemsPerCall) {
|
|
2569
|
+
const slice = items.slice(start, start + maxItemsPerCall);
|
|
2569
2570
|
const result = await embedItemsForProject2(projectIdentity, slice, signal, db, sessionId);
|
|
2570
2571
|
if (!result)
|
|
2571
2572
|
return null;
|