@agentknight/sdk 0.9.57 → 0.9.61
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/chunks/{acp-adapter-WYDK3PLS.js → acp-adapter-MBYKOCA2.js} +4 -4
- package/dist/chunks/{chunk-OOCAIULD.js → chunk-3AMFPDE5.js} +435 -21
- package/dist/chunks/{chunk-3LEPYV7Y.js → chunk-7CNBPLNE.js} +2 -2
- package/dist/chunks/{chunk-7ZYBES47.js → chunk-7OGTK7KB.js} +1 -1
- package/dist/chunks/{chunk-WPVH7HKC.js → chunk-A4YCCQ3I.js} +1 -1
- package/dist/chunks/{chunk-EDZPP6SJ.js → chunk-ALUQLM54.js} +2 -3
- package/dist/chunks/{chunk-USI66MEF.js → chunk-CHKNC6PD.js} +3 -2
- package/dist/chunks/{chunk-ZLKFFKAX.js → chunk-CM5LVXVL.js} +4 -3
- package/dist/chunks/{chunk-IPJWNGNK.js → chunk-H4SHMWQ6.js} +1 -1
- package/dist/chunks/{chunk-KBI5IWPR.js → chunk-P2PH5KMV.js} +842 -557
- package/dist/chunks/{chunk-DAKDVZ7X.js → chunk-SIFCCGXF.js} +7 -5
- package/dist/chunks/{chunk-LT5ULDVT.js → chunk-ZNQ2I5EF.js} +1 -1
- package/dist/chunks/{claude-adapter-GCH36EZ6.js → claude-adapter-D3JWXMNX.js} +209 -59
- package/dist/chunks/{codex-adapter-CXD4SVCE.js → codex-adapter-655KHW7H.js} +4 -4
- package/dist/chunks/{copilot-adapter-SYFGOAGE.js → copilot-adapter-EZUXHBE3.js} +155 -25
- package/dist/chunks/{managed-agent-adapter-ODCNYYO6.js → managed-agent-adapter-BOJNEJ75.js} +25 -7
- package/dist/chunks/{pi-adapter-XLY46UDL.js → pi-adapter-LAD5GOCP.js} +4 -4
- package/dist/configuration.js +4 -4
- package/dist/index.d.ts +142 -1
- package/dist/index.js +1487 -578
- package/dist/runtime.js +2 -2
- package/dist/session-analytics-worker.js +162 -51
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
PEER_CHAT_TIMEOUT_MS,
|
|
4
4
|
PeerChatRequestSchema,
|
|
5
5
|
PeerChatResultSchema
|
|
6
|
-
} from "./chunks/chunk-
|
|
7
|
-
import "./chunks/chunk-
|
|
6
|
+
} from "./chunks/chunk-CHKNC6PD.js";
|
|
7
|
+
import "./chunks/chunk-P2PH5KMV.js";
|
|
8
8
|
export {
|
|
9
9
|
DataDirectoryLease,
|
|
10
10
|
PEER_CHAT_TIMEOUT_MS,
|
|
@@ -2,28 +2,32 @@ import {
|
|
|
2
2
|
AnalyticsCommandSchema,
|
|
3
3
|
AnalyticsEventSchema,
|
|
4
4
|
openSessionEventLog
|
|
5
|
-
} from "./chunks/chunk-
|
|
6
|
-
import "./chunks/chunk-
|
|
7
|
-
import "./chunks/chunk-
|
|
5
|
+
} from "./chunks/chunk-CM5LVXVL.js";
|
|
6
|
+
import "./chunks/chunk-ZNQ2I5EF.js";
|
|
7
|
+
import "./chunks/chunk-H4SHMWQ6.js";
|
|
8
8
|
import {
|
|
9
9
|
SessionOperationError
|
|
10
|
-
} from "./chunks/chunk-
|
|
10
|
+
} from "./chunks/chunk-7OGTK7KB.js";
|
|
11
11
|
import {
|
|
12
12
|
SessionAnalyticsResultSchema,
|
|
13
|
-
SessionSkillInfoSchema
|
|
14
|
-
|
|
13
|
+
SessionSkillInfoSchema,
|
|
14
|
+
WorkbenchCompactionSchema,
|
|
15
|
+
WorkbenchContextSampleSchema,
|
|
16
|
+
WorkbenchTelemetrySchema,
|
|
17
|
+
WorkbenchUsageCallSchema
|
|
18
|
+
} from "./chunks/chunk-P2PH5KMV.js";
|
|
15
19
|
|
|
16
20
|
// src/session-analytics-worker.ts
|
|
17
21
|
import { parentPort, workerData, isMainThread as isMainThread2 } from "node:worker_threads";
|
|
18
|
-
import { z as
|
|
22
|
+
import { z as z3 } from "zod";
|
|
19
23
|
|
|
20
24
|
// src/session-analytics-store.ts
|
|
21
|
-
import { createHash } from "node:crypto";
|
|
25
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
22
26
|
import { chmod, lstat, mkdir, open, realpath } from "node:fs/promises";
|
|
23
27
|
import { join } from "node:path";
|
|
24
28
|
import { DatabaseSync } from "node:sqlite";
|
|
25
29
|
import { isMainThread } from "node:worker_threads";
|
|
26
|
-
import { z } from "zod";
|
|
30
|
+
import { z as z2 } from "zod";
|
|
27
31
|
|
|
28
32
|
// src/session-keywords.ts
|
|
29
33
|
var segmenter = new Intl.Segmenter(["zh", "en"], { granularity: "word" });
|
|
@@ -55,46 +59,102 @@ function messageKeywords(content) {
|
|
|
55
59
|
return { terms, truncated };
|
|
56
60
|
}
|
|
57
61
|
|
|
62
|
+
// src/session-usage-telemetry.ts
|
|
63
|
+
import { createHash } from "node:crypto";
|
|
64
|
+
import { z } from "zod";
|
|
65
|
+
function projectUsageTelemetry(event) {
|
|
66
|
+
const base = {
|
|
67
|
+
id: createHash("sha256").update(event.id).digest("hex"),
|
|
68
|
+
timestamp: new Date(event.timestamp).toISOString()
|
|
69
|
+
};
|
|
70
|
+
const data = event.data;
|
|
71
|
+
if (event.type === "session.usage_info" && event.agentId === void 0) {
|
|
72
|
+
return { kind: "context", identity: base.id, value: WorkbenchContextSampleSchema.parse({
|
|
73
|
+
...base,
|
|
74
|
+
tokens: data.currentTokens,
|
|
75
|
+
limit: data.tokenLimit,
|
|
76
|
+
messages: data.messagesLength
|
|
77
|
+
}) };
|
|
78
|
+
}
|
|
79
|
+
if (event.type === "session.compaction_complete" && event.agentId === void 0) {
|
|
80
|
+
const usage = z.record(z.string(), z.unknown()).optional().parse(data.compactionTokensUsed);
|
|
81
|
+
return { kind: "compaction", identity: base.id, value: WorkbenchCompactionSchema.parse({
|
|
82
|
+
...base,
|
|
83
|
+
success: data.success,
|
|
84
|
+
before: data.preCompactionTokens,
|
|
85
|
+
after: data.postCompactionTokens,
|
|
86
|
+
removed: data.tokensRemoved,
|
|
87
|
+
messagesRemoved: data.messagesRemoved,
|
|
88
|
+
trigger: data.trigger,
|
|
89
|
+
basis: data.tokenAccountingBasis,
|
|
90
|
+
durationMs: usage?.duration,
|
|
91
|
+
inputTokens: usage?.inputTokens,
|
|
92
|
+
outputTokens: usage?.outputTokens
|
|
93
|
+
}) };
|
|
94
|
+
}
|
|
95
|
+
if (event.type === "assistant.usage") {
|
|
96
|
+
const accounting = data.accounting;
|
|
97
|
+
const identity = typeof accounting === "object" && accounting !== null && "sourceSessionId" in accounting && "usageId" in accounting ? JSON.stringify([accounting.sourceSessionId, accounting.usageId]) : JSON.stringify([event.agentId, data.apiCallId ?? event.id]);
|
|
98
|
+
return {
|
|
99
|
+
kind: "call",
|
|
100
|
+
identity: createHash("sha256").update(identity).digest("hex"),
|
|
101
|
+
value: WorkbenchUsageCallSchema.parse({
|
|
102
|
+
...base,
|
|
103
|
+
model: data.model,
|
|
104
|
+
...event.agentId === void 0 ? {} : { agentId: event.agentId },
|
|
105
|
+
input: data.inputTokens,
|
|
106
|
+
output: data.outputTokens,
|
|
107
|
+
cache: data.cacheReadTokens,
|
|
108
|
+
requestBytes: data.requestBodyBytes,
|
|
109
|
+
wireBytes: data.requestBodyWireBytes,
|
|
110
|
+
durationMs: data.duration,
|
|
111
|
+
firstOutputMs: data.outputTtftMs
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
58
118
|
// src/session-analytics-store.ts
|
|
59
119
|
var RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
60
120
|
var MAX_RECORDS = 5e4;
|
|
61
121
|
var INDEX_BYTES = 8 * 1024 * 1024;
|
|
62
122
|
var KEYWORD_VERSION = 1;
|
|
63
|
-
var Count =
|
|
64
|
-
var Usage =
|
|
65
|
-
id:
|
|
66
|
-
timestamp:
|
|
67
|
-
model:
|
|
123
|
+
var Count = z2.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
124
|
+
var Usage = z2.object({
|
|
125
|
+
id: z2.string().min(1).max(2048),
|
|
126
|
+
timestamp: z2.iso.datetime({ offset: true }),
|
|
127
|
+
model: z2.string().min(1).max(256),
|
|
68
128
|
inputTokens: Count.optional(),
|
|
69
129
|
outputTokens: Count.optional(),
|
|
70
130
|
cacheReadTokens: Count.optional()
|
|
71
131
|
});
|
|
72
|
-
var SessionRow =
|
|
73
|
-
started_at:
|
|
74
|
-
observed_since:
|
|
75
|
-
dropped:
|
|
76
|
-
gap_since:
|
|
77
|
-
usage_lost:
|
|
78
|
-
history_lost:
|
|
79
|
-
fingerprint:
|
|
80
|
-
head_hash:
|
|
81
|
-
head_bytes:
|
|
82
|
-
offset:
|
|
83
|
-
skipping:
|
|
84
|
-
indexed_at:
|
|
85
|
-
skills:
|
|
86
|
-
skills_at:
|
|
132
|
+
var SessionRow = z2.object({
|
|
133
|
+
started_at: z2.number(),
|
|
134
|
+
observed_since: z2.number(),
|
|
135
|
+
dropped: z2.number(),
|
|
136
|
+
gap_since: z2.number().nullable(),
|
|
137
|
+
usage_lost: z2.number().nullable(),
|
|
138
|
+
history_lost: z2.number().nullable(),
|
|
139
|
+
fingerprint: z2.string().nullable(),
|
|
140
|
+
head_hash: z2.string().nullable(),
|
|
141
|
+
head_bytes: z2.number(),
|
|
142
|
+
offset: z2.number(),
|
|
143
|
+
skipping: z2.number(),
|
|
144
|
+
indexed_at: z2.number().nullable(),
|
|
145
|
+
skills: z2.string().nullable(),
|
|
146
|
+
skills_at: z2.string().nullable()
|
|
87
147
|
});
|
|
88
|
-
var ReceiptRow =
|
|
89
|
-
kind:
|
|
90
|
-
occurred_at:
|
|
91
|
-
manual:
|
|
92
|
-
model:
|
|
93
|
-
input:
|
|
94
|
-
output:
|
|
95
|
-
cache:
|
|
96
|
-
keywords:
|
|
97
|
-
shortened:
|
|
148
|
+
var ReceiptRow = z2.object({
|
|
149
|
+
kind: z2.enum(["user", "assistant", "usage"]),
|
|
150
|
+
occurred_at: z2.number(),
|
|
151
|
+
manual: z2.number(),
|
|
152
|
+
model: z2.string().nullable(),
|
|
153
|
+
input: z2.number().nullable(),
|
|
154
|
+
output: z2.number().nullable(),
|
|
155
|
+
cache: z2.number().nullable(),
|
|
156
|
+
keywords: z2.string().nullable(),
|
|
157
|
+
shortened: z2.number()
|
|
98
158
|
});
|
|
99
159
|
var AnalyticsStore = class {
|
|
100
160
|
#directory;
|
|
@@ -125,7 +185,7 @@ var AnalyticsStore = class {
|
|
|
125
185
|
const db = new DatabaseSync(path);
|
|
126
186
|
try {
|
|
127
187
|
db.exec("PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON; PRAGMA secure_delete=ON;");
|
|
128
|
-
const version =
|
|
188
|
+
const version = z2.object({ user_version: z2.number() }).parse(db.prepare("PRAGMA user_version").get()).user_version;
|
|
129
189
|
if (version > 1) throw new Error("Analytics database requires a newer PC Agent");
|
|
130
190
|
db.exec(`
|
|
131
191
|
BEGIN IMMEDIATE;
|
|
@@ -146,6 +206,12 @@ var AnalyticsStore = class {
|
|
|
146
206
|
);
|
|
147
207
|
CREATE INDEX IF NOT EXISTS receipts_time ON receipts(occurred_at);
|
|
148
208
|
CREATE INDEX IF NOT EXISTS receipts_session_time ON receipts(session,occurred_at);
|
|
209
|
+
CREATE TABLE IF NOT EXISTS telemetry (
|
|
210
|
+
session TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
211
|
+
kind TEXT NOT NULL, identity TEXT NOT NULL, occurred_at INTEGER NOT NULL, payload TEXT NOT NULL,
|
|
212
|
+
PRIMARY KEY(session,kind,identity)
|
|
213
|
+
);
|
|
214
|
+
CREATE INDEX IF NOT EXISTS telemetry_session_time ON telemetry(session,kind,occurred_at);
|
|
149
215
|
CREATE UNIQUE INDEX IF NOT EXISTS receipts_message_event ON receipts(session,kind,event_id)
|
|
150
216
|
WHERE kind IN ('user','assistant');
|
|
151
217
|
PRAGMA user_version=1;
|
|
@@ -159,7 +225,7 @@ var AnalyticsStore = class {
|
|
|
159
225
|
}
|
|
160
226
|
}
|
|
161
227
|
#key(sessionId) {
|
|
162
|
-
return
|
|
228
|
+
return createHash2("sha256").update(sessionId).digest("hex");
|
|
163
229
|
}
|
|
164
230
|
#transaction(db, work) {
|
|
165
231
|
db.exec("BEGIN IMMEDIATE");
|
|
@@ -186,8 +252,20 @@ var AnalyticsStore = class {
|
|
|
186
252
|
#event(db, key, event) {
|
|
187
253
|
const time = Date.parse(event.timestamp);
|
|
188
254
|
if (time < Date.now() - RETENTION_MS) return;
|
|
255
|
+
const telemetry = projectUsageTelemetry(event);
|
|
256
|
+
if (telemetry !== void 0) {
|
|
257
|
+
const previous = z2.object({ payload: z2.string() }).optional().parse(db.prepare(
|
|
258
|
+
"SELECT payload FROM telemetry WHERE session=? AND kind=? AND identity=?"
|
|
259
|
+
).get(key, telemetry.kind, telemetry.identity));
|
|
260
|
+
const payload = previous === void 0 ? telemetry.value : {
|
|
261
|
+
...Object.fromEntries(Object.entries(telemetry.value).filter(([, value]) => value !== void 0)),
|
|
262
|
+
...z2.record(z2.string(), z2.unknown()).parse(JSON.parse(previous.payload))
|
|
263
|
+
};
|
|
264
|
+
db.prepare(`INSERT INTO telemetry(session,kind,identity,occurred_at,payload) VALUES(?,?,?,?,?)
|
|
265
|
+
ON CONFLICT(session,kind,identity) DO UPDATE SET payload=excluded.payload`).run(key, telemetry.kind, telemetry.identity, time, JSON.stringify(payload));
|
|
266
|
+
}
|
|
189
267
|
if (event.type === "assistant.usage") {
|
|
190
|
-
const accounting =
|
|
268
|
+
const accounting = z2.object({ sourceSessionId: z2.string(), usageId: z2.string() }).optional().parse(event.data.accounting);
|
|
191
269
|
const callId = event.data.apiCallId ?? event.id;
|
|
192
270
|
const identity2 = accounting === void 0 ? event.agentId === void 0 ? callId : JSON.stringify([event.agentId, callId]) : JSON.stringify([accounting.sourceSessionId, accounting.usageId]);
|
|
193
271
|
const value = Usage.parse({ ...event.data, id: identity2, timestamp: event.timestamp });
|
|
@@ -211,7 +289,7 @@ var AnalyticsStore = class {
|
|
|
211
289
|
}
|
|
212
290
|
if (event.agentId !== void 0) return;
|
|
213
291
|
if (event.type === "session.skills_loaded") {
|
|
214
|
-
const skills =
|
|
292
|
+
const skills = z2.array(SessionSkillInfoSchema).max(512).parse(event.data.skills);
|
|
215
293
|
const timestamp = new Date(time).toISOString();
|
|
216
294
|
db.prepare("UPDATE sessions SET skills=?,skills_at=? WHERE id=? AND (skills_at IS NULL OR skills_at<=?)").run(JSON.stringify(skills), timestamp, key, timestamp);
|
|
217
295
|
return;
|
|
@@ -259,8 +337,8 @@ var AnalyticsStore = class {
|
|
|
259
337
|
#prune(db) {
|
|
260
338
|
if (Date.now() - this.#prunedAt < 6e4) return;
|
|
261
339
|
const cutoff = Date.now() - RETENTION_MS;
|
|
262
|
-
const overflow =
|
|
263
|
-
const lost =
|
|
340
|
+
const overflow = z2.object({ count: z2.number() }).parse(db.prepare("SELECT COUNT(*) AS count FROM receipts").get()).count - MAX_RECORDS;
|
|
341
|
+
const lost = z2.array(z2.object({ session: z2.string(), kind: z2.string(), latest: z2.number() })).parse(db.prepare(`
|
|
264
342
|
SELECT session,kind,MAX(occurred_at) AS latest FROM receipts
|
|
265
343
|
WHERE occurred_at<? OR rowid IN (SELECT rowid FROM receipts ORDER BY occurred_at LIMIT ?)
|
|
266
344
|
GROUP BY session,kind`).all(cutoff, Math.max(0, overflow)));
|
|
@@ -270,6 +348,17 @@ var AnalyticsStore = class {
|
|
|
270
348
|
}
|
|
271
349
|
db.prepare(`DELETE FROM receipts WHERE occurred_at<? OR rowid IN (
|
|
272
350
|
SELECT rowid FROM receipts ORDER BY occurred_at LIMIT ?)`).run(cutoff, Math.max(0, overflow));
|
|
351
|
+
const extra = z2.object({ count: z2.number() }).parse(
|
|
352
|
+
db.prepare("SELECT COUNT(*) AS count FROM telemetry").get()
|
|
353
|
+
).count - MAX_RECORDS;
|
|
354
|
+
const telemetryLost = z2.array(z2.object({ session: z2.string(), latest: z2.number() })).parse(db.prepare(`
|
|
355
|
+
SELECT session,MAX(occurred_at) AS latest FROM telemetry WHERE occurred_at<? OR rowid IN (
|
|
356
|
+
SELECT rowid FROM telemetry ORDER BY occurred_at LIMIT ?) GROUP BY session`).all(cutoff, Math.max(0, extra)));
|
|
357
|
+
for (const item of telemetryLost) db.prepare(
|
|
358
|
+
"UPDATE sessions SET gap_since=MIN(COALESCE(gap_since,?),?) WHERE id=?"
|
|
359
|
+
).run(item.latest, item.latest, item.session);
|
|
360
|
+
db.prepare(`DELETE FROM telemetry WHERE occurred_at<? OR rowid IN (
|
|
361
|
+
SELECT rowid FROM telemetry ORDER BY occurred_at LIMIT ?)`).run(cutoff, Math.max(0, extra));
|
|
273
362
|
this.#prunedAt = Date.now();
|
|
274
363
|
}
|
|
275
364
|
async index(sessionId, environment, allowMissingEventLog) {
|
|
@@ -281,8 +370,8 @@ var AnalyticsStore = class {
|
|
|
281
370
|
const fingerprint = `${info.dev}:${info.ino}:${info.birthtimeMs}`;
|
|
282
371
|
const head = Buffer.alloc(Math.min(256, info.size));
|
|
283
372
|
const headRead = await file.read(head, 0, head.length, 0);
|
|
284
|
-
const headHash =
|
|
285
|
-
const previousHash =
|
|
373
|
+
const headHash = createHash2("sha256").update(head.subarray(0, headRead.bytesRead)).digest("hex");
|
|
374
|
+
const previousHash = createHash2("sha256").update(head.subarray(0, Math.min(row.head_bytes, headRead.bytesRead))).digest("hex");
|
|
286
375
|
const changed = row.fingerprint !== null && (row.fingerprint !== fingerprint || info.size < row.offset || row.head_bytes > 0 && row.head_hash !== null && row.head_hash !== previousHash);
|
|
287
376
|
if (!changed && row.fingerprint !== null && row.offset === info.size) {
|
|
288
377
|
return { complete: true, catchUp: false };
|
|
@@ -342,7 +431,7 @@ var AnalyticsStore = class {
|
|
|
342
431
|
}
|
|
343
432
|
const { complete } = await this.index(sessionId, environment, allowMissingEventLog);
|
|
344
433
|
const { db, key, row } = await this.#session(sessionId);
|
|
345
|
-
const records =
|
|
434
|
+
const records = z2.array(ReceiptRow).parse(db.prepare(
|
|
346
435
|
"SELECT * FROM receipts WHERE session=? AND occurred_at>=? AND occurred_at<? ORDER BY occurred_at"
|
|
347
436
|
).all(key, since, until));
|
|
348
437
|
const days = /* @__PURE__ */ new Map();
|
|
@@ -365,7 +454,7 @@ var AnalyticsStore = class {
|
|
|
365
454
|
}
|
|
366
455
|
user.messages++;
|
|
367
456
|
user.shortened ||= record.shortened === 1;
|
|
368
|
-
for (const term of
|
|
457
|
+
for (const term of z2.array(z2.string()).parse(JSON.parse(record.keywords ?? "[]"))) {
|
|
369
458
|
user.keywords.set(term, (user.keywords.get(term) ?? 0) + 1);
|
|
370
459
|
}
|
|
371
460
|
}
|
|
@@ -422,6 +511,25 @@ var AnalyticsStore = class {
|
|
|
422
511
|
this.#seen.delete(this.#key(sessionId));
|
|
423
512
|
db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
424
513
|
}
|
|
514
|
+
async telemetry(sessionId, environment, allowMissingEventLog) {
|
|
515
|
+
const indexed = await this.index(sessionId, environment, allowMissingEventLog);
|
|
516
|
+
const { db, key, row } = await this.#session(sessionId);
|
|
517
|
+
const since = Date.now() - 7 * 24 * 60 * 60 * 1e3;
|
|
518
|
+
const read = (kind, limit) => z2.array(z2.object({ payload: z2.string() })).parse(db.prepare(
|
|
519
|
+
"SELECT payload FROM telemetry WHERE session=? AND kind=? AND occurred_at>=? ORDER BY occurred_at DESC,rowid DESC LIMIT ?"
|
|
520
|
+
).all(key, kind, since, limit + 1)).reverse().map((item) => JSON.parse(item.payload));
|
|
521
|
+
const samples = read("context", 120), calls = read("call", 120), compactions = read("compaction", 40);
|
|
522
|
+
return WorkbenchTelemetrySchema.parse({
|
|
523
|
+
since: new Date(since).toISOString(),
|
|
524
|
+
observedSince: new Date(row.observed_since).toISOString(),
|
|
525
|
+
dropped: row.dropped,
|
|
526
|
+
...row.gap_since === null ? {} : { gapSince: new Date(row.gap_since).toISOString() },
|
|
527
|
+
truncated: !indexed.complete || samples.length > 120 || calls.length > 120 || compactions.length > 40 || row.history_lost !== null && row.history_lost >= since,
|
|
528
|
+
samples: samples.slice(-120),
|
|
529
|
+
calls: calls.slice(-120),
|
|
530
|
+
compactions: compactions.slice(-40)
|
|
531
|
+
});
|
|
532
|
+
}
|
|
425
533
|
close() {
|
|
426
534
|
if (this.#database !== void 0) {
|
|
427
535
|
this.#database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
@@ -434,12 +542,12 @@ var AnalyticsStore = class {
|
|
|
434
542
|
// src/session-analytics-worker.ts
|
|
435
543
|
if (isMainThread2 || parentPort === null) throw new Error("Analytics storage requires a background worker");
|
|
436
544
|
var port = parentPort;
|
|
437
|
-
var settings =
|
|
545
|
+
var settings = z3.object({ directory: z3.string() }).parse(workerData);
|
|
438
546
|
var store = new AnalyticsStore(settings.directory);
|
|
439
547
|
var pending = Promise.resolve();
|
|
440
548
|
port.on("message", (value) => {
|
|
441
549
|
pending = pending.then(async () => {
|
|
442
|
-
const { id, command } =
|
|
550
|
+
const { id, command } = z3.object({ id: z3.number().int(), command: AnalyticsCommandSchema }).parse(value);
|
|
443
551
|
try {
|
|
444
552
|
let result;
|
|
445
553
|
switch (command.operation) {
|
|
@@ -452,6 +560,9 @@ port.on("message", (value) => {
|
|
|
452
560
|
case "read":
|
|
453
561
|
result = await store.read(command.sessionId, command.request, command.environment, command.allowMissingEventLog);
|
|
454
562
|
break;
|
|
563
|
+
case "telemetry":
|
|
564
|
+
result = await store.telemetry(command.sessionId, command.environment, command.allowMissingEventLog);
|
|
565
|
+
break;
|
|
455
566
|
case "remove":
|
|
456
567
|
result = await store.remove(command.sessionId);
|
|
457
568
|
break;
|