@sixb/sqlite 0.1.2 → 0.1.4
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/agents/agent-storage.d.ts +5 -3
- package/dist/agents/agent-storage.d.ts.map +1 -1
- package/dist/agents/checkpoints.d.ts +18 -0
- package/dist/agents/checkpoints.d.ts.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/messages.d.ts +2 -1
- package/dist/agents/messages.d.ts.map +1 -1
- package/dist/agents/rows.d.ts +18 -1
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/ai-cost-storage.d.ts +15 -0
- package/dist/ai-cost-storage.d.ts.map +1 -0
- package/dist/ai-usage-storage.d.ts +2 -1
- package/dist/ai-usage-storage.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +979 -74
- package/dist/index.js.map +15 -13
- package/dist/migrations.d.ts.map +1 -1
- package/dist/object-storage.d.ts +4 -3
- package/dist/object-storage.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-state.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-writer.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agents/agent-storage.ts +6 -3
- package/src/agents/checkpoints.ts +205 -0
- package/src/agents/index.ts +1 -0
- package/src/agents/messages.ts +59 -0
- package/src/agents/rows.ts +44 -0
- package/src/ai-cost-storage.ts +744 -0
- package/src/ai-usage-storage.ts +19 -0
- package/src/index.ts +8 -2
- package/src/migrations/026-ai-cost-accounting.sql +57 -0
- package/src/migrations/027-agent-context-checkpoints.sql +28 -0
- package/src/migrations/028-object-override-edit-times.sql +3 -0
- package/src/migrations.ts +10 -0
- package/src/object-query-compiler.ts +50 -0
- package/src/object-storage.ts +138 -34
- package/src/ontology-storage/materialization-state.ts +2 -0
- package/src/ontology-storage/materialization-writer.ts +6 -3
package/dist/migrations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAiF3B,eAAO,MAAM,yBAAyB,sBAAsB,CAAA;AAC5D,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AAEnD,eAAO,MAAM,uBAAuB,wBAmElC,CAAA;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAQ9E;AAED,wBAAgB,UAAU,CACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC1C,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAAC,QAAQ,CAAC,CAEzB;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAS3D;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAOzF;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAA;CAC5C,GAAG,eAAe,CAoBlB;AAED,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1E"}
|
package/dist/object-storage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CountObjectsInput, CountObjectsResult, ExistsObjectsInput, ExistsObjectsResult, FacetObjectsInput, FacetObjectsResult, LinkDirection, ObjectLinkRow, ObjectQueryCapabilities, ObjectRow, ObjectStorage, QueryObjectsInput, QueryObjectsResult } from "@sixb/core/storage";
|
|
1
|
+
import type { CountObjectsInput, CountObjectsResult, ExistsObjectsInput, ExistsObjectsResult, FacetObjectsInput, FacetObjectsResult, LinkBatchKey, LinkDirection, ObjectBatchKey, ObjectLinkRow, ObjectQueryCapabilities, ObjectRow, ObjectStorage, QueryObjectLinksInput, QueryObjectLinksResult, QueryObjectsInput, QueryObjectsResult } from "@sixb/core/storage";
|
|
2
2
|
import { type SqliteStoreConnection } from "./transactions";
|
|
3
3
|
export interface SqliteObjectStorageOptions {
|
|
4
4
|
/** Path to SQLite database file. Defaults to ':memory:' for in-memory database. */
|
|
@@ -39,7 +39,7 @@ export declare class SqliteObjectStorage implements ObjectStorage {
|
|
|
39
39
|
objectTypeId: string;
|
|
40
40
|
primaryId: string;
|
|
41
41
|
}[];
|
|
42
|
-
}): Promise<Map<
|
|
42
|
+
}): Promise<Map<ObjectBatchKey, ObjectRow>>;
|
|
43
43
|
listLinksBatch(params: {
|
|
44
44
|
projectId: string;
|
|
45
45
|
items: readonly {
|
|
@@ -47,7 +47,8 @@ export declare class SqliteObjectStorage implements ObjectStorage {
|
|
|
47
47
|
objectId: string;
|
|
48
48
|
linkId: string;
|
|
49
49
|
}[];
|
|
50
|
-
}): Promise<Map<
|
|
50
|
+
}): Promise<Map<LinkBatchKey, ObjectLinkRow[]>>;
|
|
51
|
+
queryLinks(params: QueryObjectLinksInput): Promise<QueryObjectLinksResult>;
|
|
51
52
|
listIncidentLinksBatch(params: {
|
|
52
53
|
projectId: string;
|
|
53
54
|
items: readonly {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-storage.d.ts","sourceRoot":"","sources":["../src/object-storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAGnB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,
|
|
1
|
+
{"version":3,"file":"object-storage.d.ts","sourceRoot":"","sources":["../src/object-storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAGnB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EAEd,aAAa,EACb,uBAAuB,EACvB,SAAS,EAET,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,0BAA0B;IACzC,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC;AAoED;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAU;gBAEjB,OAAO,GAAE,0BAA+B;IASpD,iBAAiB,IAAI,uBAAuB;IAItC,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsBpE,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,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|
-
{"version":3,"file":"materialization-state.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materialization-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAGV,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EACnB,MAAM,qCAAqC,CAAA;AAe5C,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAO5B,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAU3B,eAAO,MAAM,iCAAiC,kCAAkC,CAAA;AAChF,eAAO,MAAM,6BAA6B,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"materialization-state.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materialization-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAGV,eAAe,EACf,iBAAiB,EAEjB,kBAAkB,EACnB,MAAM,qCAAqC,CAAA;AAe5C,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAO5B,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAU3B,eAAO,MAAM,iCAAiC,kCAAkC,CAAA;AAChF,eAAO,MAAM,6BAA6B,8BAA8B,CAAA;AAoExE,MAAM,MAAM,mBAAmB,GAC3B;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAA;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAA;CAC5B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAA;IAC7B,QAAQ,CAAC,OAA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AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAQ1C,OAAO,KAAK,EAGV,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAa3B,iFAAiF;AACjF,qBAAa,2BAA2B;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,QAAQ;IAEzC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB,GAAG,IAAI;IAOjF,OAAO,CAAC,cAAc;
|
|
1
|
+
{"version":3,"file":"materialization-writer.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materialization-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAQ1C,OAAO,KAAK,EAGV,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAa3B,iFAAiF;AACjF,qBAAa,2BAA2B;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,QAAQ;IAEzC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB,GAAG,IAAI;IAOjF,OAAO,CAAC,cAAc;IA8KtB,OAAO,CAAC,cAAc;IA+CtB,OAAO,CAAC,WAAW;IA2DnB,OAAO,CAAC,SAAS;IA8DjB,OAAO,CAAC,eAAe;IA8DvB,OAAO,CAAC,WAAW;CA+BpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/sqlite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "SQLite storage provider for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"prepack": "bun run build"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@sixb/core": "0.1.
|
|
39
|
+
"@sixb/core": "0.1.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@sixb/core": "0.1.
|
|
42
|
+
"@sixb/core": "0.1.4",
|
|
43
43
|
"@types/bun": "latest",
|
|
44
44
|
"typescript": "^5.7.0"
|
|
45
45
|
},
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
openSqliteStoreConnection,
|
|
6
6
|
type SqliteStoreConnection,
|
|
7
7
|
} from "../transactions"
|
|
8
|
+
import { SqliteAgentContextCheckpointStore } from "./checkpoints"
|
|
8
9
|
import { SqliteAgentMessageStore } from "./messages"
|
|
9
10
|
import { SqliteAgentRunStore } from "./runs"
|
|
10
11
|
import { SqliteAgentThreadStore } from "./threads"
|
|
@@ -19,14 +20,15 @@ export interface SqliteAgentStorageOptions {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* SQLite-backed agent persistence: thread
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* SQLite-backed agent persistence: thread, run, message, and context-checkpoint sub-stores sharing
|
|
24
|
+
* one connection. Cross-table writes run in SQLite transactions; the bundled {@link SqliteStorage}
|
|
25
|
+
* serializes them for single-flight and checkpoint compare-and-swap safety.
|
|
25
26
|
*/
|
|
26
27
|
export class SqliteAgentStorage implements AgentStorage {
|
|
27
28
|
readonly threads: SqliteAgentThreadStore
|
|
28
29
|
readonly runs: SqliteAgentRunStore
|
|
29
30
|
readonly messages: SqliteAgentMessageStore
|
|
31
|
+
readonly checkpoints: SqliteAgentContextCheckpointStore
|
|
30
32
|
|
|
31
33
|
private readonly connection: SqliteStoreConnection
|
|
32
34
|
|
|
@@ -40,6 +42,7 @@ export class SqliteAgentStorage implements AgentStorage {
|
|
|
40
42
|
this.threads = new SqliteAgentThreadStore(this.connection.db)
|
|
41
43
|
this.runs = new SqliteAgentRunStore(this.connection.db, options.executions)
|
|
42
44
|
this.messages = new SqliteAgentMessageStore(this.connection.db)
|
|
45
|
+
this.checkpoints = new SqliteAgentContextCheckpointStore(this.connection.db)
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
close(): void {
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite"
|
|
2
|
+
import {
|
|
3
|
+
agentContextCheckpointMatchesCreateInput,
|
|
4
|
+
assertAgentContextCheckpointAnchors,
|
|
5
|
+
assertAgentContextCheckpointAuthority,
|
|
6
|
+
assertAgentContextCheckpointReplayState,
|
|
7
|
+
assertCreateAgentContextCheckpointInput,
|
|
8
|
+
} from "@sixb/core/internal/agent-run-storage-provider"
|
|
9
|
+
import {
|
|
10
|
+
type AgentContextCheckpointRecord,
|
|
11
|
+
type AgentContextCheckpointStore,
|
|
12
|
+
AgentStorageError,
|
|
13
|
+
type CreateAgentContextCheckpointInput,
|
|
14
|
+
} from "@sixb/core/storage"
|
|
15
|
+
import {
|
|
16
|
+
type AgentContextCheckpointRow,
|
|
17
|
+
type AgentMessageRow,
|
|
18
|
+
type AgentRunRow,
|
|
19
|
+
type AgentThreadRow,
|
|
20
|
+
rowToContextCheckpointRecord,
|
|
21
|
+
rowToMessageRecord,
|
|
22
|
+
rowToRunRecord,
|
|
23
|
+
rowToThreadRecord,
|
|
24
|
+
} from "./rows"
|
|
25
|
+
|
|
26
|
+
const SQLITE_CHECKPOINT_RUN_ID_BATCH_SIZE = 500
|
|
27
|
+
|
|
28
|
+
export class SqliteAgentContextCheckpointStore implements AgentContextCheckpointStore {
|
|
29
|
+
constructor(private readonly db: Database) {}
|
|
30
|
+
|
|
31
|
+
async create(input: CreateAgentContextCheckpointInput): Promise<AgentContextCheckpointRecord> {
|
|
32
|
+
assertCreateAgentContextCheckpointInput(input, "SixbSqlite")
|
|
33
|
+
|
|
34
|
+
return this.db.transaction(() => {
|
|
35
|
+
const runRow = this.db
|
|
36
|
+
.query("SELECT * FROM agent_runs WHERE project_id = ? AND id = ?")
|
|
37
|
+
.get(input.projectId, input.createdByRunId) as AgentRunRow | null
|
|
38
|
+
const threadRow = this.db
|
|
39
|
+
.query("SELECT * FROM agent_threads WHERE project_id = ? AND id = ?")
|
|
40
|
+
.get(input.projectId, input.threadId) as AgentThreadRow | null
|
|
41
|
+
assertAgentContextCheckpointAuthority({
|
|
42
|
+
create: input,
|
|
43
|
+
run: runRow ? rowToRunRecord(runRow) : null,
|
|
44
|
+
thread: threadRow ? rowToThreadRecord(threadRow) : null,
|
|
45
|
+
prefix: "SixbSqlite",
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const latest = this.findLatest(input.projectId, input.threadId)
|
|
49
|
+
const headRow = this.db
|
|
50
|
+
.query(
|
|
51
|
+
"SELECT COALESCE(MAX(seq), 0) AS seq FROM agent_messages WHERE project_id = ? AND thread_id = ?"
|
|
52
|
+
)
|
|
53
|
+
.get(input.projectId, input.threadId) as { seq: number }
|
|
54
|
+
|
|
55
|
+
const existingForRun = this.db
|
|
56
|
+
.query(
|
|
57
|
+
"SELECT * FROM agent_context_checkpoints WHERE project_id = ? AND created_by_run_id = ?"
|
|
58
|
+
)
|
|
59
|
+
.get(input.projectId, input.createdByRunId) as AgentContextCheckpointRow | null
|
|
60
|
+
if (existingForRun) {
|
|
61
|
+
const record = rowToContextCheckpointRecord(existingForRun)
|
|
62
|
+
if (agentContextCheckpointMatchesCreateInput(record, input)) {
|
|
63
|
+
assertAgentContextCheckpointReplayState({
|
|
64
|
+
create: input,
|
|
65
|
+
existing: record,
|
|
66
|
+
latest,
|
|
67
|
+
headSeq: headRow.seq,
|
|
68
|
+
prefix: "SixbSqlite",
|
|
69
|
+
})
|
|
70
|
+
return record
|
|
71
|
+
}
|
|
72
|
+
throw new AgentStorageError(
|
|
73
|
+
"invalid_state",
|
|
74
|
+
`[SixbSqlite] Agent run '${input.createdByRunId}' already created a different context checkpoint.`
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const duplicateId = this.db
|
|
79
|
+
.query("SELECT 1 FROM agent_context_checkpoints WHERE project_id = ? AND id = ?")
|
|
80
|
+
.get(input.projectId, input.id)
|
|
81
|
+
if (duplicateId) {
|
|
82
|
+
throw new AgentStorageError(
|
|
83
|
+
"duplicate_id",
|
|
84
|
+
`[SixbSqlite] Agent context checkpoint '${input.id}' already exists for project '${input.projectId}'.`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const firstRetainedRow = this.db
|
|
89
|
+
.query(
|
|
90
|
+
"SELECT * FROM agent_messages WHERE project_id = ? AND thread_id = ? AND seq > ? ORDER BY seq ASC LIMIT 1"
|
|
91
|
+
)
|
|
92
|
+
.get(input.projectId, input.threadId, input.summarizedThroughSeq) as AgentMessageRow | null
|
|
93
|
+
assertAgentContextCheckpointAnchors({
|
|
94
|
+
create: input,
|
|
95
|
+
latest,
|
|
96
|
+
headSeq: headRow.seq,
|
|
97
|
+
firstRetained: firstRetainedRow ? rowToMessageRecord(firstRetainedRow) : null,
|
|
98
|
+
prefix: "SixbSqlite",
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const createdAt = input.createdAt ?? new Date()
|
|
102
|
+
this.db
|
|
103
|
+
.query(
|
|
104
|
+
`
|
|
105
|
+
INSERT INTO agent_context_checkpoints (
|
|
106
|
+
project_id,
|
|
107
|
+
id,
|
|
108
|
+
thread_id,
|
|
109
|
+
created_by_run_id,
|
|
110
|
+
previous_checkpoint_id,
|
|
111
|
+
reason,
|
|
112
|
+
summary,
|
|
113
|
+
summary_format_version,
|
|
114
|
+
summarized_through_seq,
|
|
115
|
+
observed_head_seq,
|
|
116
|
+
estimated_input_tokens_before,
|
|
117
|
+
estimated_input_tokens_after,
|
|
118
|
+
summary_model_id,
|
|
119
|
+
created_at
|
|
120
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
121
|
+
`
|
|
122
|
+
)
|
|
123
|
+
.run(
|
|
124
|
+
input.projectId,
|
|
125
|
+
input.id,
|
|
126
|
+
input.threadId,
|
|
127
|
+
input.createdByRunId,
|
|
128
|
+
input.expectedPreviousCheckpointId,
|
|
129
|
+
input.reason,
|
|
130
|
+
input.summary,
|
|
131
|
+
input.summaryFormatVersion,
|
|
132
|
+
input.summarizedThroughSeq,
|
|
133
|
+
input.observedHeadSeq,
|
|
134
|
+
input.estimatedInputTokensBefore,
|
|
135
|
+
input.estimatedInputTokensAfter,
|
|
136
|
+
input.summaryModelId,
|
|
137
|
+
createdAt.toISOString()
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return this.requireById(input.projectId, input.id)
|
|
141
|
+
})()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async getLatest(input: {
|
|
145
|
+
readonly projectId: string
|
|
146
|
+
readonly threadId: string
|
|
147
|
+
}): Promise<AgentContextCheckpointRecord | null> {
|
|
148
|
+
return this.findLatest(input.projectId, input.threadId)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async getByRunIds(input: {
|
|
152
|
+
readonly projectId: string
|
|
153
|
+
readonly runIds: readonly string[]
|
|
154
|
+
}): Promise<readonly AgentContextCheckpointRecord[]> {
|
|
155
|
+
const runIds = [...new Set(input.runIds)]
|
|
156
|
+
if (runIds.length === 0) return []
|
|
157
|
+
|
|
158
|
+
const rows: AgentContextCheckpointRow[] = []
|
|
159
|
+
for (let offset = 0; offset < runIds.length; offset += SQLITE_CHECKPOINT_RUN_ID_BATCH_SIZE) {
|
|
160
|
+
const batch = runIds.slice(offset, offset + SQLITE_CHECKPOINT_RUN_ID_BATCH_SIZE)
|
|
161
|
+
const placeholders = batch.map(() => "?").join(", ")
|
|
162
|
+
rows.push(
|
|
163
|
+
...(this.db
|
|
164
|
+
.query(
|
|
165
|
+
`SELECT * FROM agent_context_checkpoints WHERE project_id = ? AND created_by_run_id IN (${placeholders})`
|
|
166
|
+
)
|
|
167
|
+
.all(input.projectId, ...batch) as AgentContextCheckpointRow[])
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
const byRunId = new Map(
|
|
171
|
+
rows.map((row) => [row.created_by_run_id, rowToContextCheckpointRecord(row)] as const)
|
|
172
|
+
)
|
|
173
|
+
return runIds.flatMap((runId) => {
|
|
174
|
+
const checkpoint = byRunId.get(runId)
|
|
175
|
+
return checkpoint ? [checkpoint] : []
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private findLatest(projectId: string, threadId: string): AgentContextCheckpointRecord | null {
|
|
180
|
+
const row = this.db
|
|
181
|
+
.query(
|
|
182
|
+
`
|
|
183
|
+
SELECT * FROM agent_context_checkpoints
|
|
184
|
+
WHERE project_id = ? AND thread_id = ?
|
|
185
|
+
ORDER BY summarized_through_seq DESC, created_at DESC, id DESC
|
|
186
|
+
LIMIT 1
|
|
187
|
+
`
|
|
188
|
+
)
|
|
189
|
+
.get(projectId, threadId) as AgentContextCheckpointRow | null
|
|
190
|
+
return row ? rowToContextCheckpointRecord(row) : null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private requireById(projectId: string, id: string): AgentContextCheckpointRecord {
|
|
194
|
+
const row = this.db
|
|
195
|
+
.query("SELECT * FROM agent_context_checkpoints WHERE project_id = ? AND id = ?")
|
|
196
|
+
.get(projectId, id) as AgentContextCheckpointRow | null
|
|
197
|
+
if (!row) {
|
|
198
|
+
throw new AgentStorageError(
|
|
199
|
+
"invalid_state",
|
|
200
|
+
`[SixbSqlite] Failed to load agent context checkpoint '${id}' for project '${projectId}'.`
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
return rowToContextCheckpointRecord(row)
|
|
204
|
+
}
|
|
205
|
+
}
|
package/src/agents/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { SqliteAgentStorageOptions } from "./agent-storage"
|
|
2
2
|
export { SqliteAgentStorage } from "./agent-storage"
|
|
3
|
+
export { SqliteAgentContextCheckpointStore } from "./checkpoints"
|
|
3
4
|
export { SqliteAgentMessageStore } from "./messages"
|
|
4
5
|
export { SqliteAgentRunStore } from "./runs"
|
|
5
6
|
export { SqliteAgentThreadStore } from "./threads"
|
package/src/agents/messages.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type AgentMessageStore,
|
|
6
6
|
AgentStorageError,
|
|
7
7
|
type AppendAgentMessageInput,
|
|
8
|
+
type DeleteAgentMessagesByRunInput,
|
|
8
9
|
type ListAgentMessagesInput,
|
|
9
10
|
type ListAgentMessagesResult,
|
|
10
11
|
} from "@sixb/core/storage"
|
|
@@ -110,6 +111,59 @@ export class SqliteAgentMessageStore implements AgentMessageStore {
|
|
|
110
111
|
})()
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
async deleteByRunId(input: DeleteAgentMessagesByRunInput): Promise<number> {
|
|
115
|
+
return this.db.transaction(() => {
|
|
116
|
+
const thread = this.db
|
|
117
|
+
.query("SELECT 1 AS present FROM agent_threads WHERE project_id = ? AND id = ?")
|
|
118
|
+
.get(input.projectId, input.threadId) as { present: number } | null
|
|
119
|
+
|
|
120
|
+
if (!thread) {
|
|
121
|
+
throw new AgentStorageError(
|
|
122
|
+
"thread_not_found",
|
|
123
|
+
`[SixbSqlite] Agent thread '${input.threadId}' not found for project '${input.projectId}'.`
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const deleted = this.db
|
|
128
|
+
.query("DELETE FROM agent_messages WHERE project_id = ? AND thread_id = ? AND run_id = ?")
|
|
129
|
+
.run(input.projectId, input.threadId, input.runId)
|
|
130
|
+
if (deleted.changes === 0) {
|
|
131
|
+
return 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const updatedAt = new Date().toISOString()
|
|
135
|
+
this.db
|
|
136
|
+
.query(
|
|
137
|
+
`
|
|
138
|
+
UPDATE agent_threads
|
|
139
|
+
SET
|
|
140
|
+
message_count = (
|
|
141
|
+
SELECT COUNT(*) FROM agent_messages WHERE project_id = ? AND thread_id = ?
|
|
142
|
+
),
|
|
143
|
+
last_message_at = (
|
|
144
|
+
SELECT created_at FROM agent_messages
|
|
145
|
+
WHERE project_id = ? AND thread_id = ?
|
|
146
|
+
ORDER BY seq DESC
|
|
147
|
+
LIMIT 1
|
|
148
|
+
),
|
|
149
|
+
updated_at = ?
|
|
150
|
+
WHERE project_id = ? AND id = ?
|
|
151
|
+
`
|
|
152
|
+
)
|
|
153
|
+
.run(
|
|
154
|
+
input.projectId,
|
|
155
|
+
input.threadId,
|
|
156
|
+
input.projectId,
|
|
157
|
+
input.threadId,
|
|
158
|
+
updatedAt,
|
|
159
|
+
input.projectId,
|
|
160
|
+
input.threadId
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
return deleted.changes
|
|
164
|
+
})()
|
|
165
|
+
}
|
|
166
|
+
|
|
113
167
|
async getById(params: { projectId: string; id: string }): Promise<AgentMessageRecord | null> {
|
|
114
168
|
const row = this.db
|
|
115
169
|
.query("SELECT * FROM agent_messages WHERE project_id = ? AND id = ?")
|
|
@@ -126,6 +180,11 @@ export class SqliteAgentMessageStore implements AgentMessageStore {
|
|
|
126
180
|
const whereClauses = ["project_id = ?", "thread_id = ?"]
|
|
127
181
|
const args: SqliteValue[] = [input.projectId, input.threadId]
|
|
128
182
|
|
|
183
|
+
if (input.afterSeq !== undefined) {
|
|
184
|
+
whereClauses.push("seq > ?")
|
|
185
|
+
args.push(input.afterSeq)
|
|
186
|
+
}
|
|
187
|
+
|
|
129
188
|
if (input.roles) {
|
|
130
189
|
whereClauses.push(`role IN (${input.roles.map(() => "?").join(", ")})`)
|
|
131
190
|
args.push(...input.roles)
|
package/src/agents/rows.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { AgentMessagePart, Principal } from "@sixb/core"
|
|
|
3
3
|
import { parseSixbFailure } from "@sixb/core/internal/errors"
|
|
4
4
|
import {
|
|
5
5
|
AGENT_RUN_FAILURE_CODES,
|
|
6
|
+
type AgentContextCheckpointRecord,
|
|
6
7
|
type AgentMessageRecord,
|
|
7
8
|
type AgentRunDiagnostic,
|
|
8
9
|
type AgentRunRecord,
|
|
@@ -65,6 +66,23 @@ export interface AgentMessageRow {
|
|
|
65
66
|
completed_at: string | null
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
export interface AgentContextCheckpointRow {
|
|
70
|
+
project_id: string
|
|
71
|
+
id: string
|
|
72
|
+
thread_id: string
|
|
73
|
+
created_by_run_id: string
|
|
74
|
+
previous_checkpoint_id: string | null
|
|
75
|
+
reason: AgentContextCheckpointRecord["reason"]
|
|
76
|
+
summary: string
|
|
77
|
+
summary_format_version: number
|
|
78
|
+
summarized_through_seq: number
|
|
79
|
+
observed_head_seq: number
|
|
80
|
+
estimated_input_tokens_before: number
|
|
81
|
+
estimated_input_tokens_after: number
|
|
82
|
+
summary_model_id: string
|
|
83
|
+
created_at: string
|
|
84
|
+
}
|
|
85
|
+
|
|
68
86
|
// ── row → record mappers ────────────────────────────────────────────────────────────────────────
|
|
69
87
|
|
|
70
88
|
export function rowToThreadRecord(row: AgentThreadRow): AgentThreadRecord {
|
|
@@ -131,6 +149,32 @@ export function rowToMessageRecord(row: AgentMessageRow): AgentMessageRecord {
|
|
|
131
149
|
}
|
|
132
150
|
}
|
|
133
151
|
|
|
152
|
+
export function rowToContextCheckpointRecord(
|
|
153
|
+
row: AgentContextCheckpointRow
|
|
154
|
+
): AgentContextCheckpointRecord {
|
|
155
|
+
if (row.summary_format_version !== 1) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`[SixbSqlite] Unsupported agent context checkpoint summary format version '${row.summary_format_version}'.`
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
id: row.id,
|
|
162
|
+
projectId: row.project_id,
|
|
163
|
+
threadId: row.thread_id,
|
|
164
|
+
createdByRunId: row.created_by_run_id,
|
|
165
|
+
previousCheckpointId: row.previous_checkpoint_id ?? undefined,
|
|
166
|
+
reason: row.reason,
|
|
167
|
+
summary: row.summary,
|
|
168
|
+
summaryFormatVersion: 1,
|
|
169
|
+
summarizedThroughSeq: row.summarized_through_seq,
|
|
170
|
+
observedHeadSeq: row.observed_head_seq,
|
|
171
|
+
estimatedInputTokensBefore: row.estimated_input_tokens_before,
|
|
172
|
+
estimatedInputTokensAfter: row.estimated_input_tokens_after,
|
|
173
|
+
summaryModelId: row.summary_model_id,
|
|
174
|
+
createdAt: new Date(row.created_at),
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
134
178
|
function principalFromColumns(
|
|
135
179
|
type: Principal["type"] | null | undefined,
|
|
136
180
|
id: string | null | undefined
|