pi-session-memory 0.1.4 → 0.2.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/README.md +101 -12
- package/extensions/index.ts +254 -19
- package/package.json +6 -2
- package/src/backfill.ts +102 -24
- package/src/db.ts +254 -4
- package/src/helper.ts +44 -0
- package/src/retriever.ts +213 -48
- package/src/session-migration.ts +188 -0
- package/src/writer.ts +3 -0
- package/spec.md +0 -172
- package/tests/core.test.ts +0 -68
- package/tsconfig.json +0 -10
package/tests/core.test.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync, rmSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
const dbPath = join(tmpdir(), `pi-session-memory-${process.pid}.db`);
|
|
7
|
-
process.env.MEMORY_DB_PATH = dbPath;
|
|
8
|
-
|
|
9
|
-
const { getDb, insertTurn, upsertSession } = await import("../src/db.ts");
|
|
10
|
-
const { recallTurns } = await import("../src/retriever.ts");
|
|
11
|
-
|
|
12
|
-
function cleanup(): void {
|
|
13
|
-
for (const suffix of ["", "-wal", "-shm"]) {
|
|
14
|
-
const path = `${dbPath}${suffix}`;
|
|
15
|
-
if (existsSync(path)) rmSync(path);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
cleanup();
|
|
20
|
-
|
|
21
|
-
upsertSession({
|
|
22
|
-
session_id: "pi:test",
|
|
23
|
-
source: "pi",
|
|
24
|
-
cwd: "/tmp",
|
|
25
|
-
started_at: 1,
|
|
26
|
-
model_id: null,
|
|
27
|
-
jsonl_path: "/tmp/test.jsonl",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
assert.equal(insertTurn({
|
|
31
|
-
turn_id: "pi:test:user-1",
|
|
32
|
-
session_id: "pi:test",
|
|
33
|
-
turn_index: 0,
|
|
34
|
-
ts: 1,
|
|
35
|
-
user_text: "literal 100% and a_b",
|
|
36
|
-
reply_text: "first reply",
|
|
37
|
-
tool_names: null,
|
|
38
|
-
user_message_id: "user-1",
|
|
39
|
-
}), true);
|
|
40
|
-
|
|
41
|
-
assert.equal(insertTurn({
|
|
42
|
-
turn_id: "pi:test:user-2",
|
|
43
|
-
session_id: "pi:test",
|
|
44
|
-
turn_index: 1,
|
|
45
|
-
ts: 2,
|
|
46
|
-
user_text: "wildcard 100x and acb",
|
|
47
|
-
reply_text: "second reply",
|
|
48
|
-
tool_names: null,
|
|
49
|
-
user_message_id: "user-2",
|
|
50
|
-
}), true);
|
|
51
|
-
|
|
52
|
-
assert.equal(insertTurn({
|
|
53
|
-
turn_id: "pi:test:user-1",
|
|
54
|
-
session_id: "pi:test",
|
|
55
|
-
turn_index: 0,
|
|
56
|
-
ts: 1,
|
|
57
|
-
user_text: "duplicate",
|
|
58
|
-
reply_text: "duplicate",
|
|
59
|
-
tool_names: null,
|
|
60
|
-
user_message_id: "user-1",
|
|
61
|
-
}), false);
|
|
62
|
-
|
|
63
|
-
assert.deepEqual(recallTurns(["100%"], 10).map((result) => result.turn_id), ["pi:test:user-1"]);
|
|
64
|
-
assert.deepEqual(recallTurns(["a_b"], 10).map((result) => result.turn_id), ["pi:test:user-1"]);
|
|
65
|
-
assert.equal(getDb().prepare("SELECT count(*) AS count FROM turns").get().count, 2);
|
|
66
|
-
|
|
67
|
-
cleanup();
|
|
68
|
-
console.log("core.test.ts: passed");
|