@cortexkit/pi-magic-context 0.49.35 → 0.49.36
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 +163 -160
- package/dist/chunk-embedding-write-worker.js +59 -57
- package/dist/{compaction-marker-candidates-hk2frhac.js → compaction-marker-candidates-9fzqg6y0.js} +4 -2
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-5j1d1e3v.js → compartment-chunk-embedding-jpcme6tz.js} +6 -5
- package/dist/{embedding-backfill-jt459ady.js → embedding-backfill-002vyexq.js} +8 -7
- package/dist/{index-399p688g.js → index-8sqebjzk.js} +4 -1
- package/dist/{index-11knwv2h.js → index-a7sj2bam.js} +6 -3
- package/dist/{index-mkh1cm5k.js → index-c1dqxr10.js} +34 -4
- package/dist/{index-rgvqh5x7.js → index-ck8wj35v.js} +1 -1
- package/dist/{index-fzm8fm4z.js → index-dgqjq8sg.js} +143 -64
- package/dist/{index-yg42q9bc.js → index-f6y7mdq9.js} +8 -7
- package/dist/{index-2p691ayw.js → index-f9qet7y8.js} +1 -1
- package/dist/{index-6y6v2wvn.js → index-gxqmh9hq.js} +6 -6
- package/dist/{index-vgfk2xa5.js → index-jbkwszd5.js} +1 -1
- package/dist/{index-8m82cez2.js → index-kj49vs41.js} +2 -2
- package/dist/{index-svqk0701.js → index-mx757f3g.js} +13 -5
- package/dist/index-nypgv96r.js +58 -0
- package/dist/{index-d21rhpbd.js → index-p9jfa33t.js} +5 -5
- package/dist/{index-yhsmjvqa.js → index-pwp6zyx3.js} +12 -1
- package/dist/{index-m68qfjte.js → index-ry84c8dr.js} +1 -1
- package/dist/index-wfqysrwq.js +204 -0
- package/dist/{index-0rvn6vhq.js → index-wwsfevck.js} +6 -3
- package/dist/{index-54wmg4rj.js → index-x2n261wp.js} +16 -14
- package/dist/{index-d0w84hy5.js → index-y90fxz4t.js} +9 -3
- package/dist/{index-a11nmw5t.js → index-z7dktknj.js} +6 -4
- package/dist/index.js +846 -305
- package/dist/{message-fts-rowid-map-aw4xa05a.js → message-fts-rowid-map-hmgyfxxa.js} +5 -4
- package/dist/{message-index-bounded-da34vhs4.js → message-index-bounded-82sergz7.js} +8 -7
- package/dist/migration-worker.js +46 -41
- package/dist/{project-embedding-registry-davzvsz9.js → project-embedding-registry-16pj4vyf.js} +7 -6
- package/dist/raw-ordinal-warmup-worker.js +114 -118
- package/dist/{read-session-chunk-nbcznexm.js → read-session-chunk-jxq427v6.js} +6 -5
- package/dist/{read-session-raw-zb8kpa2y.js → read-session-raw-a9ntjqap.js} +4 -3
- package/dist/{render-d931g2vv.js → render-2wan3bfh.js} +11 -10
- package/dist/{search-atp7g95j.js → search-3p18trsb.js} +12 -11
- package/dist/{search-archive-a76pp30g.js → search-archive-pgrv04gv.js} +8 -7
- package/dist/{storage-tags-jy8b0xsy.js → storage-tags-p9y3bnw7.js} +1 -1
- package/dist/{store-kabezr25.js → store-v60q7dje.js} +1 -2
- package/dist/subagent-entry.js +18 -17
- package/dist/tag-snapshot-worker-pi.js +208 -202
- package/dist/{v2-archive-reader-wcjcfdzq.js → v2-archive-reader-5zpj8hrg.js} +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// ../plugin/src/shared/reusable-worker-entry.ts
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
+
function serveWorkerJobs(run, autoClose = true) {
|
|
5
|
+
if (!parentPort)
|
|
6
|
+
throw new Error("worker requires a parent port");
|
|
7
|
+
const parent = parentPort;
|
|
8
|
+
if (!workerData?.reusableWorker) {
|
|
9
|
+
Promise.resolve(run(workerData, parent)).catch(rethrow);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let active;
|
|
13
|
+
parent.on("message", (message) => {
|
|
14
|
+
if (!("start" in message)) {
|
|
15
|
+
if (active?.id === message.jobId)
|
|
16
|
+
active.port.emit("message", message.value);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (active)
|
|
20
|
+
throw new Error("reusable worker received overlapping jobs");
|
|
21
|
+
const id = message.jobId;
|
|
22
|
+
let closed = false;
|
|
23
|
+
const port = Object.assign(new EventEmitter, {
|
|
24
|
+
postMessage(value, transferList) {
|
|
25
|
+
if (!closed)
|
|
26
|
+
parent.postMessage({ jobId: id, value }, transferList);
|
|
27
|
+
},
|
|
28
|
+
close() {
|
|
29
|
+
if (closed)
|
|
30
|
+
return;
|
|
31
|
+
closed = true;
|
|
32
|
+
port.removeAllListeners();
|
|
33
|
+
active = undefined;
|
|
34
|
+
parent.postMessage({
|
|
35
|
+
jobId: id,
|
|
36
|
+
finished: true,
|
|
37
|
+
code: Number(process.exitCode) || 0
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
active = { id, port };
|
|
42
|
+
try {
|
|
43
|
+
Promise.resolve(run(message.start, port)).then(() => {
|
|
44
|
+
if (autoClose)
|
|
45
|
+
port.close();
|
|
46
|
+
}).catch(rethrow);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
rethrow(error);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function rethrow(error) {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
throw error;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { serveWorkerJobs };
|
|
@@ -39,12 +39,12 @@ import {
|
|
|
39
39
|
expandToolPart,
|
|
40
40
|
visitRawSessionMessages2,
|
|
41
41
|
readRawSessionMessageById2
|
|
42
|
-
} from "./index-
|
|
42
|
+
} from "./index-mx757f3g.js";
|
|
43
43
|
import {
|
|
44
44
|
isRecord,
|
|
45
45
|
providerVisibleMessage,
|
|
46
46
|
getTagById2
|
|
47
|
-
} from "./index-
|
|
47
|
+
} from "./index-pwp6zyx3.js";
|
|
48
48
|
import {
|
|
49
49
|
estimateTokens
|
|
50
50
|
} from "./index-wt7vmyj4.js";
|
|
@@ -64,17 +64,17 @@ import {
|
|
|
64
64
|
import {
|
|
65
65
|
isPidAlive,
|
|
66
66
|
readProcessStartTime
|
|
67
|
-
} from "./index-
|
|
67
|
+
} from "./index-a7sj2bam.js";
|
|
68
68
|
import {
|
|
69
69
|
gaDatabasePath2,
|
|
70
70
|
V2StoreReader2
|
|
71
71
|
} from "./index-ea37qn4x.js";
|
|
72
72
|
import {
|
|
73
73
|
deleteUnmappedMessageFtsRows2
|
|
74
|
-
} from "./index-
|
|
74
|
+
} from "./index-ck8wj35v.js";
|
|
75
75
|
import {
|
|
76
76
|
deleteChunkEmbedBackoffForSession2
|
|
77
|
-
} from "./index-
|
|
77
|
+
} from "./index-f9qet7y8.js";
|
|
78
78
|
import {
|
|
79
79
|
invalidateAutoEmbedSession,
|
|
80
80
|
drainBackgroundBatches
|
|
@@ -2178,7 +2178,9 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2178
2178
|
FROM tags
|
|
2179
2179
|
WHERE session_id = ?`).all(sessionId);
|
|
2180
2180
|
const totals = new Map;
|
|
2181
|
+
const summaryRemovedTotals = new Map;
|
|
2181
2182
|
const nullMessageIds = new Set;
|
|
2183
|
+
const nullSummaryRemovedMessageIds = new Set;
|
|
2182
2184
|
for (const row of rows) {
|
|
2183
2185
|
if (row.type === "tool" && row.tool_owner_message_id === null)
|
|
2184
2186
|
continue;
|
|
@@ -2188,6 +2190,7 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2188
2190
|
if (row.token_count === null) {
|
|
2189
2191
|
nullMessageIds.add(owner);
|
|
2190
2192
|
totals.delete(owner);
|
|
2193
|
+
summaryRemovedTotals.delete(owner);
|
|
2191
2194
|
continue;
|
|
2192
2195
|
}
|
|
2193
2196
|
if (nullMessageIds.has(owner))
|
|
@@ -2195,8 +2198,16 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2195
2198
|
const ratio = row.type === "tool" ? calibration.toolsRatio : calibration.proseRatio;
|
|
2196
2199
|
const weight = ((row.token_count ?? 0) + (row.input_token_count ?? 0)) * ratio + (row.reasoning_token_count ?? 0) * calibration.proseRatio;
|
|
2197
2200
|
totals.set(owner, (totals.get(owner) ?? 0) + weight);
|
|
2201
|
+
if (row.type === "tool" && row.input_token_count === null) {
|
|
2202
|
+
nullSummaryRemovedMessageIds.add(owner);
|
|
2203
|
+
summaryRemovedTotals.delete(owner);
|
|
2204
|
+
}
|
|
2205
|
+
if (!nullSummaryRemovedMessageIds.has(owner)) {
|
|
2206
|
+
const removedWeight = row.type === "tool" ? (row.input_token_count ?? 0) * calibration.toolsRatio : row.type === "message" ? row.token_count * calibration.proseRatio : 0;
|
|
2207
|
+
summaryRemovedTotals.set(owner, (summaryRemovedTotals.get(owner) ?? 0) + removedWeight);
|
|
2208
|
+
}
|
|
2198
2209
|
}
|
|
2199
|
-
return { totals, nullMessageIds };
|
|
2210
|
+
return { totals, summaryRemovedTotals, nullMessageIds };
|
|
2200
2211
|
}
|
|
2201
2212
|
function getReasoningTokenEstimatesByMessage2(db, sessionId, proseRatio) {
|
|
2202
2213
|
const summary = readTagOwnerSummary(db, sessionId, proseRatio);
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort,
|
|
3
|
+
unregisterExitAbort
|
|
4
|
+
} from "./index-8sqebjzk.js";
|
|
5
|
+
import {
|
|
6
|
+
inRootAsyncContext2
|
|
7
|
+
} from "./index-2qtx0q6h.js";
|
|
8
|
+
|
|
9
|
+
// ../plugin/src/shared/reusable-worker.ts
|
|
10
|
+
import { EventEmitter } from "node:events";
|
|
11
|
+
import * as timers from "node:timers";
|
|
12
|
+
import {
|
|
13
|
+
MessageChannel,
|
|
14
|
+
receiveMessageOnPort,
|
|
15
|
+
Worker
|
|
16
|
+
} from "node:worker_threads";
|
|
17
|
+
var pools = new Map;
|
|
18
|
+
var liveSlots = new Set;
|
|
19
|
+
var nextId = 0;
|
|
20
|
+
var IDLE_MS = 60000;
|
|
21
|
+
var sharedCloneWorks = (() => {
|
|
22
|
+
const source = new SharedArrayBuffer(1);
|
|
23
|
+
const clone = structuredClone(source);
|
|
24
|
+
new Uint8Array(source)[0] = 1;
|
|
25
|
+
return new Uint8Array(clone)[0] === 1;
|
|
26
|
+
})();
|
|
27
|
+
var cloneChannel;
|
|
28
|
+
function cloneJobValue(value, transferList) {
|
|
29
|
+
if (sharedCloneWorks)
|
|
30
|
+
return structuredClone(value, { transfer: transferList });
|
|
31
|
+
if (!cloneChannel) {
|
|
32
|
+
cloneChannel = inRootAsyncContext2(() => new MessageChannel);
|
|
33
|
+
cloneChannel.port1.unref();
|
|
34
|
+
cloneChannel.port2.unref();
|
|
35
|
+
}
|
|
36
|
+
cloneChannel.port1.postMessage(value, transferList);
|
|
37
|
+
const packet = receiveMessageOnPort(cloneChannel.port2);
|
|
38
|
+
if (!packet)
|
|
39
|
+
throw new Error("worker input clone did not arrive synchronously");
|
|
40
|
+
return packet.message;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Lease extends EventEmitter {
|
|
44
|
+
slot;
|
|
45
|
+
data;
|
|
46
|
+
id = ++nextId;
|
|
47
|
+
ended = false;
|
|
48
|
+
referenced = true;
|
|
49
|
+
outbox = [];
|
|
50
|
+
constructor(slot, data) {
|
|
51
|
+
super();
|
|
52
|
+
this.slot = slot;
|
|
53
|
+
this.data = data;
|
|
54
|
+
}
|
|
55
|
+
postMessage(value, transferList) {
|
|
56
|
+
if (this.ended)
|
|
57
|
+
return;
|
|
58
|
+
if (this.slot.active === this)
|
|
59
|
+
this.slot.worker.postMessage({ jobId: this.id, value }, transferList);
|
|
60
|
+
else
|
|
61
|
+
this.outbox.push(cloneJobValue({ value, transferList }, transferList));
|
|
62
|
+
}
|
|
63
|
+
start() {
|
|
64
|
+
if (this.referenced)
|
|
65
|
+
this.slot.worker.ref();
|
|
66
|
+
else
|
|
67
|
+
this.slot.worker.unref();
|
|
68
|
+
this.emit("online");
|
|
69
|
+
this.slot.worker.postMessage({ jobId: this.id, start: this.data });
|
|
70
|
+
for (const { value, transferList } of this.outbox.splice(0))
|
|
71
|
+
this.postMessage(value, transferList);
|
|
72
|
+
}
|
|
73
|
+
ref() {
|
|
74
|
+
this.referenced = true;
|
|
75
|
+
if (this.slot.active === this)
|
|
76
|
+
this.slot.worker.ref();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
unref() {
|
|
80
|
+
this.referenced = false;
|
|
81
|
+
if (this.slot.active === this)
|
|
82
|
+
this.slot.worker.unref();
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
async terminate() {
|
|
86
|
+
if (this.ended)
|
|
87
|
+
return 0;
|
|
88
|
+
if (this.slot.active === this)
|
|
89
|
+
return await this.slot.worker.terminate();
|
|
90
|
+
this.ended = true;
|
|
91
|
+
this.slot.queue.splice(this.slot.queue.indexOf(this), 1);
|
|
92
|
+
this.emit("exit", 0);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function reuseWorker(entry, options, idleMs = IDLE_MS) {
|
|
97
|
+
const data = cloneJobValue(options.workerData);
|
|
98
|
+
const slot = acquireSlot(entry, options, idleMs);
|
|
99
|
+
const lease = new Lease(slot, data);
|
|
100
|
+
enqueue(slot, lease);
|
|
101
|
+
return lease;
|
|
102
|
+
}
|
|
103
|
+
function enqueue(slot, lease) {
|
|
104
|
+
timers.clearTimeout(slot.idle);
|
|
105
|
+
lease.slot = slot;
|
|
106
|
+
slot.queue.push(lease);
|
|
107
|
+
queueMicrotask(() => slot.advance());
|
|
108
|
+
}
|
|
109
|
+
function acquireSlot(entry, options, idleMs) {
|
|
110
|
+
const data = options.workerData;
|
|
111
|
+
const key = JSON.stringify([
|
|
112
|
+
String(entry),
|
|
113
|
+
data?.path ?? data?.dbPath,
|
|
114
|
+
data?.harness,
|
|
115
|
+
data?.job
|
|
116
|
+
]);
|
|
117
|
+
let slot = pools.get(key);
|
|
118
|
+
if (!slot) {
|
|
119
|
+
const worker = inRootAsyncContext2(() => new Worker(entry, { ...options, workerData: { reusableWorker: true } }));
|
|
120
|
+
const controller = new AbortController;
|
|
121
|
+
slot = { worker, controller, queue: [], advance: () => {} };
|
|
122
|
+
pools.set(key, slot);
|
|
123
|
+
liveSlots.add(slot);
|
|
124
|
+
const owned = slot;
|
|
125
|
+
const advance = () => {
|
|
126
|
+
if (controller.signal.aborted || owned.active)
|
|
127
|
+
return;
|
|
128
|
+
timers.clearTimeout(owned.idle);
|
|
129
|
+
const lease = owned.queue.shift();
|
|
130
|
+
owned.active = lease;
|
|
131
|
+
if (!lease) {
|
|
132
|
+
worker.unref();
|
|
133
|
+
owned.idle = timers.setTimeout(() => {
|
|
134
|
+
if (pools.get(key) === owned)
|
|
135
|
+
pools.delete(key);
|
|
136
|
+
worker.terminate();
|
|
137
|
+
}, idleMs);
|
|
138
|
+
owned.idle.unref();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
lease.start();
|
|
142
|
+
};
|
|
143
|
+
owned.advance = advance;
|
|
144
|
+
worker.on("message", (message) => {
|
|
145
|
+
const lease = owned.active;
|
|
146
|
+
if (!lease || message.jobId !== lease.id)
|
|
147
|
+
return;
|
|
148
|
+
if (!message.finished) {
|
|
149
|
+
lease.emit("message", message.value);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
lease.ended = true;
|
|
153
|
+
owned.active = undefined;
|
|
154
|
+
if (message.code) {
|
|
155
|
+
if (pools.get(key) === owned)
|
|
156
|
+
pools.delete(key);
|
|
157
|
+
lease.emit("exit", message.code);
|
|
158
|
+
worker.terminate();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
lease.emit("exit", 0);
|
|
162
|
+
advance();
|
|
163
|
+
});
|
|
164
|
+
worker.on("error", (error) => {
|
|
165
|
+
if (pools.get(key) === owned)
|
|
166
|
+
pools.delete(key);
|
|
167
|
+
owned.active?.emit("error", error);
|
|
168
|
+
});
|
|
169
|
+
worker.on("exit", (code) => {
|
|
170
|
+
liveSlots.delete(owned);
|
|
171
|
+
timers.clearTimeout(owned.idle);
|
|
172
|
+
if (pools.get(key) === owned)
|
|
173
|
+
pools.delete(key);
|
|
174
|
+
const active = owned.active;
|
|
175
|
+
owned.active = undefined;
|
|
176
|
+
if (active && !active.ended) {
|
|
177
|
+
active.ended = true;
|
|
178
|
+
active.emit("exit", code);
|
|
179
|
+
}
|
|
180
|
+
for (const lease of owned.queue.splice(0)) {
|
|
181
|
+
if (controller.signal.aborted) {
|
|
182
|
+
lease.ended = true;
|
|
183
|
+
lease.emit("exit", code);
|
|
184
|
+
} else {
|
|
185
|
+
try {
|
|
186
|
+
enqueue(acquireSlot(entry, options, idleMs), lease);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
lease.ended = true;
|
|
189
|
+
lease.emit("error", error);
|
|
190
|
+
lease.emit("exit", 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
controller.signal.addEventListener("abort", () => {
|
|
196
|
+
worker.terminate();
|
|
197
|
+
}, { once: true });
|
|
198
|
+
registerExitAbort(controller);
|
|
199
|
+
worker.once("exit", () => unregisterExitAbort(controller));
|
|
200
|
+
}
|
|
201
|
+
return slot;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { reuseWorker };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
getTagsBySession2,
|
|
9
9
|
getTagsByNumbers2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-pwp6zyx3.js";
|
|
11
11
|
import {
|
|
12
12
|
inRootAsyncContext2,
|
|
13
13
|
getSqliteDatabasePath2,
|
|
@@ -16,9 +16,12 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
createFailClosedBlockingError
|
|
18
18
|
} from "./index-3bb24eb6.js";
|
|
19
|
+
import {
|
|
20
|
+
reuseWorker
|
|
21
|
+
} from "./index-wfqysrwq.js";
|
|
19
22
|
import {
|
|
20
23
|
createWorkerShutdown
|
|
21
|
-
} from "./index-
|
|
24
|
+
} from "./index-x2n261wp.js";
|
|
22
25
|
|
|
23
26
|
// src/pi-context-budget.ts
|
|
24
27
|
var PI_CONTEXT_BUDGET = {
|
|
@@ -348,7 +351,7 @@ function startPiTagSnapshotWorker(request, options = {}) {
|
|
|
348
351
|
const entry = options.entry ?? new URL(import.meta.url.endsWith(".ts") ? "./tag-snapshot-worker-pi.ts" : "./tag-snapshot-worker-pi.js", import.meta.url);
|
|
349
352
|
const started = performance.now();
|
|
350
353
|
const consumer = createPiHydrationPacketConsumer(request, options.cached, options.byteLimit, options.cachedFallback);
|
|
351
|
-
const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: request }));
|
|
354
|
+
const worker = inRootAsyncContext2(() => options.entry ? new Worker(entry, { workerData: request }) : reuseWorker(entry, { workerData: request }));
|
|
352
355
|
const shutdown = createWorkerShutdown(worker, "pi-tag-snapshot", 1000);
|
|
353
356
|
let exited = false;
|
|
354
357
|
let settled = false;
|
|
@@ -3,31 +3,33 @@ var WORKER_CLOSE_MESSAGE = { kind: "close" };
|
|
|
3
3
|
function isWorkerCloseMessage(message) {
|
|
4
4
|
return typeof message === "object" && message !== null && message.kind === WORKER_CLOSE_MESSAGE.kind;
|
|
5
5
|
}
|
|
6
|
-
function exitOnWorkerClose(port, closeConnections) {
|
|
6
|
+
function exitOnWorkerClose(port, closeConnections, exitThread = true) {
|
|
7
7
|
const listener = (message) => {
|
|
8
8
|
if (!isWorkerCloseMessage(message))
|
|
9
9
|
return;
|
|
10
10
|
try {
|
|
11
11
|
closeConnections();
|
|
12
12
|
} finally {
|
|
13
|
-
|
|
13
|
+
if (exitThread)
|
|
14
|
+
process.exit(0);
|
|
15
|
+
closePort();
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
if (!port)
|
|
17
19
|
return { closePort() {} };
|
|
18
|
-
port
|
|
20
|
+
const owner = port;
|
|
21
|
+
owner.on("message", listener);
|
|
19
22
|
let closed = false;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
23
|
+
function closePort() {
|
|
24
|
+
if (closed)
|
|
25
|
+
return;
|
|
26
|
+
closed = true;
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
owner.off("message", listener);
|
|
29
|
+
owner.close();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return { closePort };
|
|
31
33
|
}
|
|
32
34
|
var outcomes = new Map;
|
|
33
35
|
function createWorkerShutdown(worker, site, deadlineMs) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
registerExitAbort
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-8sqebjzk.js";
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
6
|
} from "./index-gymgz20n.js";
|
|
@@ -8,6 +8,12 @@ import {
|
|
|
8
8
|
inRootAsyncContext2,
|
|
9
9
|
getSqliteDatabasePath2
|
|
10
10
|
} from "./index-2qtx0q6h.js";
|
|
11
|
+
import {
|
|
12
|
+
reuseWorker
|
|
13
|
+
} from "./index-wfqysrwq.js";
|
|
14
|
+
import {
|
|
15
|
+
createWorkerShutdown
|
|
16
|
+
} from "./index-x2n261wp.js";
|
|
11
17
|
|
|
12
18
|
// ../plugin/src/features/magic-context/compaction-marker-candidates.ts
|
|
13
19
|
import { existsSync, realpathSync } from "node:fs";
|
|
@@ -140,7 +146,7 @@ function runCandidateWorker(path, sessionId, options) {
|
|
|
140
146
|
return;
|
|
141
147
|
}
|
|
142
148
|
workers.delete(worker);
|
|
143
|
-
const stopped = worker.terminate();
|
|
149
|
+
const stopped = snapshot ? createWorkerShutdown(worker, "marker-candidates", 1000).close() : worker.terminate();
|
|
144
150
|
worker.unref();
|
|
145
151
|
stopped.then(() => resolve(snapshot), () => resolve(snapshot));
|
|
146
152
|
};
|
|
@@ -153,7 +159,7 @@ function runCandidateWorker(path, sessionId, options) {
|
|
|
153
159
|
timer.unref?.();
|
|
154
160
|
};
|
|
155
161
|
try {
|
|
156
|
-
worker = inRootAsyncContext2(() => new Worker(entry, { workerData: { path, sessionId } }));
|
|
162
|
+
worker = inRootAsyncContext2(() => options.entry ? new Worker(entry, { workerData: { path, sessionId } }) : reuseWorker(entry, { workerData: { path, sessionId } }));
|
|
157
163
|
workers.add(worker);
|
|
158
164
|
worker.unref();
|
|
159
165
|
deadline(options.acceptMs ?? 2000);
|
|
@@ -20,9 +20,12 @@ import {
|
|
|
20
20
|
inRootAsyncContext2,
|
|
21
21
|
getSqliteDatabasePath2
|
|
22
22
|
} from "./index-2qtx0q6h.js";
|
|
23
|
+
import {
|
|
24
|
+
reuseWorker
|
|
25
|
+
} from "./index-wfqysrwq.js";
|
|
23
26
|
import {
|
|
24
27
|
createWorkerShutdown
|
|
25
|
-
} from "./index-
|
|
28
|
+
} from "./index-x2n261wp.js";
|
|
26
29
|
import {
|
|
27
30
|
DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2,
|
|
28
31
|
CHUNK_WINDOW_SAFETY_RATIO2,
|
|
@@ -40,7 +43,7 @@ import {
|
|
|
40
43
|
countSessionCompartmentEmbedCoverage2,
|
|
41
44
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
42
45
|
countUnembeddedSessionCompartmentsPolite2
|
|
43
|
-
} from "./index-
|
|
46
|
+
} from "./index-f9qet7y8.js";
|
|
44
47
|
import {
|
|
45
48
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
46
49
|
} from "./index-ccanzg8p.js";
|
|
@@ -611,7 +614,6 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
611
614
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
612
615
|
|
|
613
616
|
// ../plugin/src/features/magic-context/chunk-embedding-writer.ts
|
|
614
|
-
import { Worker } from "node:worker_threads";
|
|
615
617
|
function createChunkEmbeddingWriter(db) {
|
|
616
618
|
const path = getSqliteDatabasePath2(db);
|
|
617
619
|
if (!path)
|
|
@@ -620,7 +622,7 @@ function createChunkEmbeddingWriter(db) {
|
|
|
620
622
|
throw new Error("chunk embedding writer requires a filesystem path");
|
|
621
623
|
const entry = new URL(import.meta.url.endsWith(".ts") ? "./chunk-embedding-write-worker.ts" : "./chunk-embedding-write-worker.js", import.meta.url);
|
|
622
624
|
const timeout = db.prepare("PRAGMA busy_timeout").get().timeout;
|
|
623
|
-
const worker = inRootAsyncContext2(() =>
|
|
625
|
+
const worker = inRootAsyncContext2(() => reuseWorker(entry, { workerData: { path, harness: getHarness2(), timeout } }));
|
|
624
626
|
const shutdown = createWorkerShutdown(worker, "chunk-embedding-writer", timeout + 2000);
|
|
625
627
|
let pending;
|
|
626
628
|
let failure;
|