@cortexkit/pi-magic-context 0.42.6 → 0.43.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.
@@ -0,0 +1,16 @@
1
+ import {
2
+ log
3
+ } from "./index-bfd52y8p.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()) {
8
+ try {
9
+ const durationMs = completedAtMs - startedAt;
10
+ if (durationMs < thresholdMs)
11
+ return;
12
+ log(`[magic-context] slow write transaction: site=${site} held=${durationMs.toFixed(1)}ms`);
13
+ } catch {}
14
+ }
15
+
16
+ export { logSlowWriteTransaction };
@@ -0,0 +1,40 @@
1
+ import {
2
+ log
3
+ } from "./index-bfd52y8p.js";
4
+
5
+ // ../plugin/src/shared/safe-notification-target.ts
6
+ var DEFAULT_TITLE_RE = /^(New session - |Child session - )\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
7
+ function isDefaultSessionTitle2(title) {
8
+ return DEFAULT_TITLE_RE.test(title);
9
+ }
10
+ async function readSessionTitle(client, sessionId) {
11
+ try {
12
+ const c = client;
13
+ if (typeof c.session?.get !== "function")
14
+ return null;
15
+ const raw = await Promise.resolve(c.session.get({ path: { id: sessionId } }));
16
+ const obj = raw;
17
+ const title = obj && typeof obj === "object" ? obj.data?.title ?? obj.title : undefined;
18
+ return typeof title === "string" ? title : null;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ async function waitForSafeNotificationTarget2(client, sessionId, options) {
24
+ const attempts = Math.max(1, options?.attempts ?? 4);
25
+ const delayMs = options?.delayMs ?? 15000;
26
+ for (let attempt = 0;attempt < attempts; attempt += 1) {
27
+ const title = await readSessionTitle(client, sessionId);
28
+ if (title === null)
29
+ return "safe";
30
+ if (!isDefaultSessionTitle2(title))
31
+ return "safe";
32
+ if (attempt < attempts - 1) {
33
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
34
+ }
35
+ }
36
+ log(`[magic-context] notification skipped: session ${sessionId} still has its default title (would suppress title generation); will retry on a later startup`);
37
+ return "skip";
38
+ }
39
+
40
+ export { isDefaultSessionTitle2, waitForSafeNotificationTarget2 };