@sixb/sqlite 0.1.26 → 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/dist/agents/agent-storage.d.ts +8 -3
- package/dist/agents/agent-storage.d.ts.map +1 -1
- package/dist/agents/computers.d.ts +22 -0
- package/dist/agents/computers.d.ts.map +1 -0
- package/dist/agents/rows.d.ts +3 -0
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/agents/runs.d.ts.map +1 -1
- package/dist/agents/threads.d.ts +3 -1
- package/dist/agents/threads.d.ts.map +1 -1
- package/dist/agents/token-rates.d.ts +13 -0
- package/dist/agents/token-rates.d.ts.map +1 -0
- package/dist/ai-accounting-filters.d.ts +14 -0
- package/dist/ai-accounting-filters.d.ts.map +1 -0
- package/dist/ai-cost-groups.d.ts +1 -1
- package/dist/ai-cost-groups.d.ts.map +1 -1
- package/dist/ai-cost-storage.d.ts.map +1 -1
- package/dist/index.js +421 -75
- package/dist/index.js.map +18 -15
- package/dist/migrations.d.ts.map +1 -1
- package/dist/objects/query-compiler.d.ts.map +1 -1
- package/dist/ontology-storage/commits.d.ts.map +1 -1
- package/dist/ontology-storage/materializations.d.ts +2 -1
- package/dist/ontology-storage/materializations.d.ts.map +1 -1
- package/dist/pipeline-run-storage.d.ts.map +1 -1
- package/dist/sync-run-storage.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agents/agent-storage.ts +10 -3
- package/src/agents/computers.ts +112 -0
- package/src/agents/rows.ts +9 -1
- package/src/agents/runs.ts +25 -3
- package/src/agents/threads.ts +100 -22
- package/src/agents/token-rates.ts +90 -0
- package/src/ai-accounting-filters.ts +51 -0
- package/src/ai-cost-groups.ts +52 -14
- package/src/ai-cost-storage.ts +101 -39
- package/src/migrations/082-agent-token-rates.sql +17 -0
- package/src/migrations/083-agent-computer-sessions.sql +27 -0
- package/src/migrations.ts +6 -0
- package/src/objects/query-compiler.ts +26 -15
- package/src/ontology-storage/commits.ts +9 -0
- package/src/ontology-storage/materializations.ts +18 -1
- package/src/pipeline-run-storage.ts +5 -7
- package/src/sync-run-storage.ts +2 -7
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;AAmI3B,eAAO,MAAM,yBAAyB,sBAAsB,CAAA;AAC5D,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AAEnD,eAAO,MAAM,uBAAuB,
|
|
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;AAmI3B,eAAO,MAAM,yBAAyB,sBAAsB,CAAA;AAC5D,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AAEnD,eAAO,MAAM,uBAAuB,wBA6KlC,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;AAOD,mGAAmG;AACnG,wBAAgB,mBAAmB,IAAI,QAAQ,CAY9C;AAaD,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-compiler.d.ts","sourceRoot":"","sources":["../../src/objects/query-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,oBAAoB,EAG1B,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"query-compiler.d.ts","sourceRoot":"","sources":["../../src/objects/query-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,oBAAoB,EAG1B,MAAM,YAAY,CAAA;AAUnB,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,CAAA;AAEhF,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,WAAW,EAAE,CAAA;QACnB,KAAK,EAAE,MAAM,CAAA;QACb,gFAAgF;QAChF,QAAQ,EAAE,MAAM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gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,oBAAoB,GAAG,iBAAiB,CAgEnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commits.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/commits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EACV,sCAAsC,EACtC,0BAA0B,EAC1B,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,
|
|
1
|
+
{"version":3,"file":"commits.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/commits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EACV,sCAAsC,EACtC,0BAA0B,EAC1B,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAOL,KAAK,mBAAmB,EACzB,MAAM,UAAU,CAAA;AAEjB,qBAAa,2BAA4B,YAAW,qBAAqB;IAErE,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBADhB,EAAE,EAAE,QAAQ,EACZ,gBAAgB,EAAE,mBAAmB;IAGlD,mBAAmB,CACvB,KAAK,EAAE,sCAAsC,GAC5C,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAYjC,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAQhF,WAAW,CAAC,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAyBxF,IAAI,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAqD/E,OAAO,CAAC,OAAO;CAShB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
-
import type { AppliedMaterialization, ApplyMaterializationInput, ApplyMaterializationResult, FinalizeMaterializationInput, MaterializationPlanHeader, MaterializationSession, MaterializationStatePage, MaterializationVectorChangePage, OntologyMaterializationStorage, StageMaterializationWorkInput, StreamMaterializationStateInput, StreamMaterializationVectorChangesInput } from "@sixb/core/storage";
|
|
2
|
+
import type { AppliedMaterialization, ApplyMaterializationInput, ApplyMaterializationResult, FinalizeMaterializationInput, MaterializationPlanHeader, MaterializationSession, MaterializationState, MaterializationStatePage, MaterializationVectorChangePage, OntologyMaterializationStorage, ReadMaterializationStateInput, StageMaterializationWorkInput, StreamMaterializationStateInput, StreamMaterializationVectorChangesInput } from "@sixb/core/storage";
|
|
3
3
|
import { type SqliteOntologyTransactionContext } from "./materialization-session";
|
|
4
4
|
export declare class SqliteOntologyMaterializationStorage implements OntologyMaterializationStorage {
|
|
5
5
|
private readonly db;
|
|
@@ -9,6 +9,7 @@ export declare class SqliteOntologyMaterializationStorage implements OntologyMat
|
|
|
9
9
|
assertVectorSession(session: MaterializationSession, projectId: string, commitId?: string): void;
|
|
10
10
|
begin(input: MaterializationPlanHeader): Promise<MaterializationSession>;
|
|
11
11
|
streamState(input: StreamMaterializationStateInput): AsyncIterable<MaterializationStatePage>;
|
|
12
|
+
readState(input: ReadMaterializationStateInput): Promise<MaterializationState>;
|
|
12
13
|
stageWork(input: StageMaterializationWorkInput): Promise<void>;
|
|
13
14
|
streamVectorChanges(input: StreamMaterializationVectorChangesInput): AsyncIterable<MaterializationVectorChangePage>;
|
|
14
15
|
apply(input: ApplyMaterializationInput): Promise<AppliedMaterialization>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materializations.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materializations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"materializations.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/materializations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AA+B1C,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EAEzB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,+BAA+B,EAE/B,8BAA8B,EAC9B,6BAA6B,EAE7B,6BAA6B,EAC7B,+BAA+B,EAC/B,uCAAuC,EACxC,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAGL,KAAK,gCAAgC,EACtC,MAAM,2BAA2B,CAAA;AAmElC,qBAAa,oCAAqC,YAAW,8BAA8B;IAKvF,OAAO,CAAC,QAAQ,CAAC,EAAE;IAJrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;gBAGjC,EAAE,EAAE,QAAQ,EAC7B,OAAO,EAAE,gCAAgC,GAAG,IAAI;IAMlD,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAY1F,KAAK,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAqCvE,WAAW,CAChB,KAAK,EAAE,+BAA+B,GACrC,aAAa,CAAC,wBAAwB,CAAC;IA+DpC,SAAS,CAAC,KAAK,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAc9E,SAAS,CAAC,KAAK,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7D,mBAAmB,CACxB,KAAK,EAAE,uCAAuC,GAC7C,aAAa,CAAC,+BAA+B,CAAC;IAa3C,KAAK,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA2CxE,QAAQ,CAAC,KAAK,EAAE,4BAA4B,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAYxF,kBAAkB,IAAI,IAAI;IAI1B,OAAO,CAAC,kBAAkB;IA+C1B,OAAO,CAAC,YAAY;YAgBN,kBAAkB;IAsDhC,OAAO,CAAC,sBAAsB;IAkD9B,OAAO,CAAC,cAAc;IAsGtB,OAAO,CAAC,YAAY;IAkDpB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,SAAS;CAYlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-run-storage.d.ts","sourceRoot":"","sources":["../src/pipeline-run-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipeline-run-storage.d.ts","sourceRoot":"","sources":["../src/pipeline-run-storage.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,oBAAoB,CAAA;AAU3B,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,+BAA+B;IAC9C,8DAA8D;IAC9D,UAAU,EAAE,gBAAgB,CAAA;IAC5B,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC;AAED,qBAAa,wBAAyB,YAAW,kBAAkB;IACjE,OAAO,CAAC,QAAQ,C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uB;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;gBAEjC,OAAO,EAAE,2BAA2B;IAM1C,KAAK,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;YA2D/C,0BAA0B;IAgClC,KAAK,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAgCvD,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IAoEzD,OAAO,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAQjF,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8C3D,mBAAmB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAe5F,KAAK,IAAI,IAAI;CAGd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/sqlite",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "SQLite storage provider for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"prepack": "bun run build"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@sixb/core": "0.1
|
|
40
|
+
"@sixb/core": "0.2.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@sixb/core": "0.1
|
|
43
|
+
"@sixb/core": "0.2.1",
|
|
44
44
|
"@types/bun": "latest",
|
|
45
45
|
"typescript": "^5.7.0"
|
|
46
46
|
},
|
|
@@ -6,11 +6,13 @@ import {
|
|
|
6
6
|
} from "../transactions"
|
|
7
7
|
import { SqliteAgentApprovalStore } from "./approvals"
|
|
8
8
|
import { SqliteAgentContextCheckpointStore } from "./checkpoints"
|
|
9
|
+
import { SqliteAgentComputerSessionStore } from "./computers"
|
|
9
10
|
import { SqliteAgentMemoryStore } from "./memory"
|
|
10
11
|
import { SqliteAgentMessageStore } from "./messages"
|
|
11
12
|
import { SqliteAgentRunStore } from "./runs"
|
|
12
13
|
import { SqliteAgentApprovalModeStore } from "./settings"
|
|
13
14
|
import { SqliteAgentThreadStore } from "./threads"
|
|
15
|
+
import { SqliteAgentTokenRateStore } from "./token-rates"
|
|
14
16
|
|
|
15
17
|
export interface SqliteAgentStorageOptions {
|
|
16
18
|
/** Path to SQLite database file. Defaults to ':memory:' for in-memory database. */
|
|
@@ -22,9 +24,10 @@ export interface SqliteAgentStorageOptions {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* SQLite-backed agent persistence: thread, run, message, context-checkpoint, memory, approval
|
|
26
|
-
* approval-mode sub-stores sharing one connection. Cross-table writes run in
|
|
27
|
-
* serializes them for single-flight and
|
|
27
|
+
* SQLite-backed agent persistence: thread, run, message, context-checkpoint, memory, approval,
|
|
28
|
+
* approval-mode, computer-session and token-rate sub-stores sharing one connection. Cross-table writes run in
|
|
29
|
+
* SQLite transactions; the bundled {@link SqliteStorage} serializes them for single-flight and
|
|
30
|
+
* checkpoint compare-and-swap safety.
|
|
28
31
|
*/
|
|
29
32
|
export class SqliteAgentStorage implements AgentStorage {
|
|
30
33
|
readonly threads: SqliteAgentThreadStore
|
|
@@ -34,6 +37,8 @@ export class SqliteAgentStorage implements AgentStorage {
|
|
|
34
37
|
readonly memory: SqliteAgentMemoryStore
|
|
35
38
|
readonly approvals: SqliteAgentApprovalStore
|
|
36
39
|
readonly approvalModes: SqliteAgentApprovalModeStore
|
|
40
|
+
readonly computers: SqliteAgentComputerSessionStore
|
|
41
|
+
readonly tokenRates: SqliteAgentTokenRateStore
|
|
37
42
|
|
|
38
43
|
private readonly connection: SqliteStoreConnection
|
|
39
44
|
|
|
@@ -47,6 +52,8 @@ export class SqliteAgentStorage implements AgentStorage {
|
|
|
47
52
|
this.memory = new SqliteAgentMemoryStore(this.connection.db)
|
|
48
53
|
this.approvals = new SqliteAgentApprovalStore(this.connection.db)
|
|
49
54
|
this.approvalModes = new SqliteAgentApprovalModeStore(this.connection.db)
|
|
55
|
+
this.computers = new SqliteAgentComputerSessionStore(this.connection.db)
|
|
56
|
+
this.tokenRates = new SqliteAgentTokenRateStore(this.connection.db)
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
close(): void {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite"
|
|
2
|
+
import { assertAgentComputerSession } from "@sixb/core/internal/agent-run-storage-provider"
|
|
3
|
+
import type {
|
|
4
|
+
AgentComputerSessionRecord,
|
|
5
|
+
AgentComputerSessionStore,
|
|
6
|
+
Principal,
|
|
7
|
+
} from "@sixb/core/storage"
|
|
8
|
+
|
|
9
|
+
interface AgentComputerSessionRow {
|
|
10
|
+
project_id: string
|
|
11
|
+
owner_principal_type: Principal["type"]
|
|
12
|
+
owner_principal_id: string
|
|
13
|
+
id: string
|
|
14
|
+
computer_id: string
|
|
15
|
+
computer_name: string
|
|
16
|
+
folder: string
|
|
17
|
+
expires_at: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SqliteAgentComputerSessionStore implements AgentComputerSessionStore {
|
|
21
|
+
constructor(private readonly db: Database) {}
|
|
22
|
+
|
|
23
|
+
async hold(input: AgentComputerSessionRecord): Promise<void> {
|
|
24
|
+
assertAgentComputerSession(input, "SixbSqlite")
|
|
25
|
+
this.db
|
|
26
|
+
.query(
|
|
27
|
+
`INSERT INTO agent_computer_sessions (
|
|
28
|
+
project_id, owner_principal_type, owner_principal_id, id,
|
|
29
|
+
computer_id, computer_name, folder, expires_at
|
|
30
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
31
|
+
ON CONFLICT (project_id, owner_principal_type, owner_principal_id, id)
|
|
32
|
+
DO UPDATE SET
|
|
33
|
+
computer_id = excluded.computer_id,
|
|
34
|
+
computer_name = excluded.computer_name,
|
|
35
|
+
folder = excluded.folder,
|
|
36
|
+
expires_at = excluded.expires_at`
|
|
37
|
+
)
|
|
38
|
+
.run(
|
|
39
|
+
input.projectId,
|
|
40
|
+
input.ownerPrincipal.type,
|
|
41
|
+
input.ownerPrincipal.id,
|
|
42
|
+
input.id,
|
|
43
|
+
input.computer.id,
|
|
44
|
+
input.computer.name,
|
|
45
|
+
input.computer.folder,
|
|
46
|
+
input.expiresAt.toISOString()
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async release(input: {
|
|
51
|
+
readonly projectId: string
|
|
52
|
+
readonly id: string
|
|
53
|
+
readonly ownerPrincipal: Principal
|
|
54
|
+
}): Promise<AgentComputerSessionRecord | null> {
|
|
55
|
+
const row = this.db
|
|
56
|
+
.query(
|
|
57
|
+
`DELETE FROM agent_computer_sessions
|
|
58
|
+
WHERE project_id = ? AND owner_principal_type = ? AND owner_principal_id = ? AND id = ?
|
|
59
|
+
RETURNING *`
|
|
60
|
+
)
|
|
61
|
+
.get(
|
|
62
|
+
input.projectId,
|
|
63
|
+
input.ownerPrincipal.type,
|
|
64
|
+
input.ownerPrincipal.id,
|
|
65
|
+
input.id
|
|
66
|
+
) as AgentComputerSessionRow | null
|
|
67
|
+
return row && rowToSession(row)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async listLive(input: {
|
|
71
|
+
readonly projectId: string
|
|
72
|
+
readonly ownerPrincipal: Principal
|
|
73
|
+
readonly now: Date
|
|
74
|
+
}): Promise<readonly AgentComputerSessionRecord[]> {
|
|
75
|
+
const rows = this.db
|
|
76
|
+
.query(
|
|
77
|
+
`SELECT * FROM agent_computer_sessions
|
|
78
|
+
WHERE project_id = ? AND owner_principal_type = ? AND owner_principal_id = ?
|
|
79
|
+
AND expires_at > ?
|
|
80
|
+
ORDER BY id`
|
|
81
|
+
)
|
|
82
|
+
.all(
|
|
83
|
+
input.projectId,
|
|
84
|
+
input.ownerPrincipal.type,
|
|
85
|
+
input.ownerPrincipal.id,
|
|
86
|
+
input.now.toISOString()
|
|
87
|
+
) as AgentComputerSessionRow[]
|
|
88
|
+
return rows.map(rowToSession)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async removeLapsed(input: {
|
|
92
|
+
readonly projectId: string
|
|
93
|
+
readonly now: Date
|
|
94
|
+
}): Promise<readonly AgentComputerSessionRecord[]> {
|
|
95
|
+
const rows = this.db
|
|
96
|
+
.query(
|
|
97
|
+
`DELETE FROM agent_computer_sessions WHERE project_id = ? AND expires_at <= ? RETURNING *`
|
|
98
|
+
)
|
|
99
|
+
.all(input.projectId, input.now.toISOString()) as AgentComputerSessionRow[]
|
|
100
|
+
return rows.map(rowToSession)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function rowToSession(row: AgentComputerSessionRow): AgentComputerSessionRecord {
|
|
105
|
+
return {
|
|
106
|
+
projectId: row.project_id,
|
|
107
|
+
id: row.id,
|
|
108
|
+
ownerPrincipal: { type: row.owner_principal_type, id: row.owner_principal_id },
|
|
109
|
+
computer: { id: row.computer_id, name: row.computer_name, folder: row.folder },
|
|
110
|
+
expiresAt: new Date(row.expires_at),
|
|
111
|
+
}
|
|
112
|
+
}
|
package/src/agents/rows.ts
CHANGED
|
@@ -34,6 +34,9 @@ export interface AgentThreadRow {
|
|
|
34
34
|
sandbox_state: string | null
|
|
35
35
|
runs_on: "computer" | null
|
|
36
36
|
computer_id: string | null
|
|
37
|
+
computer_name: string | null
|
|
38
|
+
computer_folder: string | null
|
|
39
|
+
moved_at: string | null
|
|
37
40
|
status: AgentThreadRecord["status"]
|
|
38
41
|
active_run_id: string | null
|
|
39
42
|
last_message_at: string | null
|
|
@@ -137,7 +140,12 @@ export function rowToThreadRecord(row: AgentThreadRow): AgentThreadRecord {
|
|
|
137
140
|
? {}
|
|
138
141
|
: { sandboxParams: snapshotAgentThreadSandboxParams(JSON.parse(row.sandbox_params)) }),
|
|
139
142
|
...(row.runs_on == null ? {} : { runsOn: row.runs_on }),
|
|
140
|
-
...(row.computer_id == null
|
|
143
|
+
...(row.computer_id == null || row.computer_name == null || row.computer_folder == null
|
|
144
|
+
? {}
|
|
145
|
+
: {
|
|
146
|
+
computer: { id: row.computer_id, name: row.computer_name, folder: row.computer_folder },
|
|
147
|
+
}),
|
|
148
|
+
...(row.moved_at == null ? {} : { movedAt: new Date(row.moved_at) }),
|
|
141
149
|
status: row.status,
|
|
142
150
|
activeRunId: row.active_run_id,
|
|
143
151
|
lastMessageAt: row.last_message_at ? new Date(row.last_message_at) : undefined,
|
package/src/agents/runs.ts
CHANGED
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
assertConversationAgentRunSpec,
|
|
8
8
|
assertConversationThreadRow,
|
|
9
9
|
assertCreateSubagentRunInput,
|
|
10
|
+
assertStartsOnComputer,
|
|
10
11
|
assertSubagentThreadTakesRun,
|
|
12
|
+
assertTurnInThreadPlace,
|
|
11
13
|
newSubagentThreadRecord,
|
|
12
14
|
subagentRunMatchesCreateInput,
|
|
13
15
|
} from "@sixb/core/internal/agent-run-storage-provider"
|
|
@@ -63,10 +65,12 @@ export class SqliteAgentRunStore implements AgentRunStore {
|
|
|
63
65
|
|
|
64
66
|
return this.db.transaction(() => {
|
|
65
67
|
const thread = this.db
|
|
66
|
-
.query(
|
|
68
|
+
.query(
|
|
69
|
+
"SELECT id, kind, active_run_id, runs_on FROM agent_threads WHERE project_id = ? AND id = ?"
|
|
70
|
+
)
|
|
67
71
|
.get(input.projectId, input.threadId) as Pick<
|
|
68
72
|
AgentThreadRow,
|
|
69
|
-
"id" | "kind" | "active_run_id"
|
|
73
|
+
"id" | "kind" | "active_run_id" | "runs_on"
|
|
70
74
|
> | null
|
|
71
75
|
|
|
72
76
|
if (!thread) {
|
|
@@ -82,6 +86,7 @@ export class SqliteAgentRunStore implements AgentRunStore {
|
|
|
82
86
|
`[SixbSqlite] Agent thread '${input.threadId}' already has an active run '${thread.active_run_id}'.`
|
|
83
87
|
)
|
|
84
88
|
}
|
|
89
|
+
assertTurnInThreadPlace(thread.runs_on, input.spec, input.threadId, "SixbSqlite")
|
|
85
90
|
|
|
86
91
|
try {
|
|
87
92
|
this.db
|
|
@@ -271,7 +276,20 @@ export class SqliteAgentRunStore implements AgentRunStore {
|
|
|
271
276
|
async start(input: StartAgentRunInput): Promise<AgentRunRecord> {
|
|
272
277
|
const startedAt = input.startedAt ?? new Date()
|
|
273
278
|
return this.db.transaction(() => {
|
|
274
|
-
this.requireStatus(input.projectId, input.id, "queued")
|
|
279
|
+
const run = this.requireStatus(input.projectId, input.id, "queued")
|
|
280
|
+
if (input.onComputer) {
|
|
281
|
+
const thread = this.db
|
|
282
|
+
.query(
|
|
283
|
+
"SELECT computer_id AS id, computer_folder AS folder FROM agent_threads WHERE project_id = ? AND id = ?"
|
|
284
|
+
)
|
|
285
|
+
.get(input.projectId, run.thread_id) as { id: string; folder: string } | null
|
|
286
|
+
assertStartsOnComputer(
|
|
287
|
+
rowToRunRecord(run),
|
|
288
|
+
thread?.id ? thread : undefined,
|
|
289
|
+
input.onComputer,
|
|
290
|
+
"SixbSqlite"
|
|
291
|
+
)
|
|
292
|
+
}
|
|
275
293
|
this.db
|
|
276
294
|
.query(
|
|
277
295
|
`
|
|
@@ -586,6 +604,10 @@ export class SqliteAgentRunStore implements AgentRunStore {
|
|
|
586
604
|
args.push(input.parentRunId)
|
|
587
605
|
}
|
|
588
606
|
|
|
607
|
+
if (input.excludeComputerTurns) {
|
|
608
|
+
whereClauses.push("json_extract(spec, '$.runsOn') IS NOT 'computer'")
|
|
609
|
+
}
|
|
610
|
+
|
|
589
611
|
appendRunListFilters(whereClauses, args, input, "COALESCE(started_at, created_at)")
|
|
590
612
|
|
|
591
613
|
const { rows, total, hasMore } = queryRunList<AgentRunRow>({
|
package/src/agents/threads.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite"
|
|
2
2
|
import {
|
|
3
|
+
assertAgentThreadComputer,
|
|
3
4
|
assertAssignableComputer,
|
|
4
|
-
|
|
5
|
+
assertComputerPlace,
|
|
5
6
|
assertConversationThreadRow,
|
|
6
|
-
|
|
7
|
+
assertMovableToCloud,
|
|
8
|
+
movesComputerPlace,
|
|
7
9
|
participantsToAdd,
|
|
8
10
|
planAgentThreadFork,
|
|
11
|
+
queuedTurnInCloud,
|
|
9
12
|
remapArtifactIds,
|
|
10
13
|
snapshotAgentThreadSandboxParams,
|
|
11
14
|
transitionAgentThreadSandbox,
|
|
@@ -13,6 +16,7 @@ import {
|
|
|
13
16
|
import {
|
|
14
17
|
type AddAgentThreadParticipantsInput,
|
|
15
18
|
type AgentContextCheckpointRecord,
|
|
19
|
+
type AgentRunRecord,
|
|
16
20
|
AgentStorageError,
|
|
17
21
|
type AgentThreadParticipantRecord,
|
|
18
22
|
type AgentThreadRecord,
|
|
@@ -25,6 +29,8 @@ import {
|
|
|
25
29
|
type ListAgentThreadParticipantsInput,
|
|
26
30
|
type ListAgentThreadsInput,
|
|
27
31
|
type ListAgentThreadsResult,
|
|
32
|
+
type MoveAgentThreadToCloudInput,
|
|
33
|
+
type MoveAgentThreadToCloudResult,
|
|
28
34
|
type RemoveAgentThreadParticipantInput,
|
|
29
35
|
type TransitionAgentThreadSandboxInput,
|
|
30
36
|
} from "@sixb/core/storage"
|
|
@@ -68,7 +74,7 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
async create(input: CreateAgentThreadInput): Promise<AgentThreadRecord> {
|
|
71
|
-
|
|
77
|
+
assertComputerPlace(input.runsOn, input.computer, "SixbSqlite")
|
|
72
78
|
const sandboxParams =
|
|
73
79
|
input.sandboxParams === undefined
|
|
74
80
|
? null
|
|
@@ -88,13 +94,16 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
88
94
|
title,
|
|
89
95
|
sandbox_params,
|
|
90
96
|
runs_on,
|
|
97
|
+
computer_id,
|
|
98
|
+
computer_name,
|
|
99
|
+
computer_folder,
|
|
91
100
|
status,
|
|
92
101
|
active_run_id,
|
|
93
102
|
last_message_at,
|
|
94
103
|
message_count,
|
|
95
104
|
created_at,
|
|
96
105
|
updated_at
|
|
97
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, 0, ?, ?)
|
|
106
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, 0, ?, ?)
|
|
98
107
|
`
|
|
99
108
|
)
|
|
100
109
|
.run(
|
|
@@ -105,6 +114,9 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
105
114
|
input.title ?? null,
|
|
106
115
|
sandboxParams,
|
|
107
116
|
input.runsOn ?? null,
|
|
117
|
+
input.computer?.id ?? null,
|
|
118
|
+
input.computer?.name ?? null,
|
|
119
|
+
input.computer?.folder ?? null,
|
|
108
120
|
input.status ?? "active",
|
|
109
121
|
createdAt.toISOString(),
|
|
110
122
|
updatedAt.toISOString()
|
|
@@ -123,16 +135,25 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
123
135
|
return this.requireThread(input.projectId, input.id)
|
|
124
136
|
}
|
|
125
137
|
|
|
138
|
+
private activeRunOf(projectId: string, thread: AgentThreadRecord | null): AgentRunRecord | null {
|
|
139
|
+
const row = thread?.activeRunId
|
|
140
|
+
? (this.db
|
|
141
|
+
.query("SELECT * FROM agent_runs WHERE project_id = ? AND id = ?")
|
|
142
|
+
.get(projectId, thread.activeRunId) as AgentRunRow | null)
|
|
143
|
+
: null
|
|
144
|
+
return row ? rowToRunRecord(row) : null
|
|
145
|
+
}
|
|
146
|
+
|
|
126
147
|
async fork(input: ForkAgentThreadInput): Promise<AgentThreadRecord> {
|
|
127
148
|
return this.db
|
|
128
149
|
.transaction(() => {
|
|
129
150
|
const source = this.db
|
|
130
151
|
.query(
|
|
131
|
-
"SELECT id, kind, active_run_id FROM agent_threads WHERE project_id = ? AND id = ?"
|
|
152
|
+
"SELECT id, kind, active_run_id, runs_on, moved_at FROM agent_threads WHERE project_id = ? AND id = ?"
|
|
132
153
|
)
|
|
133
154
|
.get(input.projectId, input.sourceThreadId) as Pick<
|
|
134
155
|
AgentThreadRow,
|
|
135
|
-
"id" | "kind" | "active_run_id"
|
|
156
|
+
"id" | "kind" | "active_run_id" | "runs_on" | "moved_at"
|
|
136
157
|
> | null
|
|
137
158
|
|
|
138
159
|
if (!source) {
|
|
@@ -179,6 +200,7 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
179
200
|
const plan = planAgentThreadFork(
|
|
180
201
|
input,
|
|
181
202
|
{
|
|
203
|
+
workspace: { runsOn: source.runs_on, movedAt: source.moved_at },
|
|
182
204
|
...(activeRun?.trigger_message_id
|
|
183
205
|
? { triggerMessageId: activeRun.trigger_message_id }
|
|
184
206
|
: {}),
|
|
@@ -335,6 +357,11 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
335
357
|
args.push(input.participantPrincipal.type, input.participantPrincipal.id)
|
|
336
358
|
}
|
|
337
359
|
|
|
360
|
+
if (input.activeOnComputer) {
|
|
361
|
+
whereClauses.push("computer_id = ? AND computer_folder = ? AND active_run_id IS NOT NULL")
|
|
362
|
+
args.push(input.activeOnComputer.id, input.activeOnComputer.folder)
|
|
363
|
+
}
|
|
364
|
+
|
|
338
365
|
const dir = input.order === "asc" ? "ASC" : "DESC"
|
|
339
366
|
const { rows, total, hasMore } = queryAgentList<AgentThreadRow>({
|
|
340
367
|
db: this.db,
|
|
@@ -411,22 +438,71 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
411
438
|
}
|
|
412
439
|
|
|
413
440
|
async assignComputer(input: AssignAgentThreadComputerInput): Promise<AgentThreadRecord> {
|
|
414
|
-
|
|
415
|
-
this.db
|
|
416
|
-
.
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
441
|
+
assertAgentThreadComputer(input.computer, "SixbSqlite")
|
|
442
|
+
return this.db
|
|
443
|
+
.transaction(() => {
|
|
444
|
+
const row = this.db
|
|
445
|
+
.query("SELECT * FROM agent_threads WHERE project_id = ? AND id = ?")
|
|
446
|
+
.get(input.projectId, input.id) as AgentThreadRow | null
|
|
447
|
+
const thread = row ? rowToThreadRecord(row) : null
|
|
448
|
+
assertAssignableComputer(
|
|
449
|
+
thread,
|
|
450
|
+
this.activeRunOf(input.projectId, thread),
|
|
451
|
+
input.computer,
|
|
452
|
+
input.id,
|
|
453
|
+
"SixbSqlite"
|
|
454
|
+
)
|
|
455
|
+
const movedAt = movesComputerPlace(thread, input.computer)
|
|
456
|
+
? (input.movedAt ?? new Date()).toISOString()
|
|
457
|
+
: null
|
|
458
|
+
this.db
|
|
459
|
+
.query(`
|
|
460
|
+
UPDATE agent_threads
|
|
461
|
+
SET computer_id = ?, computer_name = ?, computer_folder = ?,
|
|
462
|
+
moved_at = COALESCE(?, moved_at)
|
|
463
|
+
WHERE project_id = ? AND id = ?
|
|
464
|
+
`)
|
|
465
|
+
.run(
|
|
466
|
+
input.computer.id,
|
|
467
|
+
input.computer.name,
|
|
468
|
+
input.computer.folder,
|
|
469
|
+
movedAt,
|
|
470
|
+
input.projectId,
|
|
471
|
+
input.id
|
|
472
|
+
)
|
|
473
|
+
return this.requireThread(input.projectId, input.id)
|
|
474
|
+
})
|
|
475
|
+
.immediate()
|
|
476
|
+
}
|
|
422
477
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
478
|
+
async moveToCloud(input: MoveAgentThreadToCloudInput): Promise<MoveAgentThreadToCloudResult> {
|
|
479
|
+
return this.db
|
|
480
|
+
.transaction(() => {
|
|
481
|
+
const row = this.db
|
|
482
|
+
.query("SELECT * FROM agent_threads WHERE project_id = ? AND id = ?")
|
|
483
|
+
.get(input.projectId, input.id) as AgentThreadRow | null
|
|
484
|
+
const thread = row ? rowToThreadRecord(row) : null
|
|
485
|
+
const active = this.activeRunOf(input.projectId, thread)
|
|
486
|
+
assertMovableToCloud(thread, active, input.id, "SixbSqlite")
|
|
487
|
+
|
|
488
|
+
const queued = queuedTurnInCloud(active)
|
|
489
|
+
if (queued) {
|
|
490
|
+
this.db
|
|
491
|
+
.query("UPDATE agent_runs SET spec = ? WHERE project_id = ? AND id = ?")
|
|
492
|
+
.run(JSON.stringify(queued.spec), input.projectId, queued.id)
|
|
493
|
+
}
|
|
494
|
+
this.db
|
|
495
|
+
.query(`
|
|
496
|
+
UPDATE agent_threads
|
|
497
|
+
SET runs_on = NULL, computer_id = NULL, computer_name = NULL, computer_folder = NULL,
|
|
498
|
+
moved_at = ?
|
|
499
|
+
WHERE project_id = ? AND id = ?
|
|
500
|
+
`)
|
|
501
|
+
.run((input.movedAt ?? new Date()).toISOString(), input.projectId, input.id)
|
|
502
|
+
const moved = this.requireThread(input.projectId, input.id)
|
|
503
|
+
return { thread: moved, ...(queued ? { queued } : {}) }
|
|
504
|
+
})
|
|
505
|
+
.immediate()
|
|
430
506
|
}
|
|
431
507
|
|
|
432
508
|
async listParticipants(
|
|
@@ -482,9 +558,10 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
482
558
|
active_run_id,
|
|
483
559
|
last_message_at,
|
|
484
560
|
message_count,
|
|
561
|
+
moved_at,
|
|
485
562
|
created_at,
|
|
486
563
|
updated_at
|
|
487
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?)
|
|
564
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?)
|
|
488
565
|
`
|
|
489
566
|
)
|
|
490
567
|
.run(
|
|
@@ -498,6 +575,7 @@ export class SqliteAgentThreadStore implements AgentThreadStore {
|
|
|
498
575
|
thread.status,
|
|
499
576
|
thread.lastMessageAt?.toISOString() ?? null,
|
|
500
577
|
thread.messageCount,
|
|
578
|
+
thread.movedAt?.toISOString() ?? null,
|
|
501
579
|
thread.createdAt.toISOString(),
|
|
502
580
|
thread.updatedAt.toISOString()
|
|
503
581
|
)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite"
|
|
2
|
+
import {
|
|
3
|
+
AGENT_TOKEN_RATE_SAMPLES,
|
|
4
|
+
assertAgentTokenRateRecord,
|
|
5
|
+
} from "@sixb/core/internal/agent-run-storage-provider"
|
|
6
|
+
import type { AgentTokenRateRecord, AgentTokenRateStore } from "@sixb/core/storage"
|
|
7
|
+
import { runImmediateTransaction } from "../transactions"
|
|
8
|
+
|
|
9
|
+
interface TokenRateRow {
|
|
10
|
+
readonly project_id: string
|
|
11
|
+
readonly run_id: string
|
|
12
|
+
readonly provider_id: string
|
|
13
|
+
readonly model_id: string
|
|
14
|
+
readonly bytes: number
|
|
15
|
+
readonly tokens: number
|
|
16
|
+
readonly measured_at: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SqliteAgentTokenRateStore implements AgentTokenRateStore {
|
|
20
|
+
constructor(private readonly db: Database) {}
|
|
21
|
+
|
|
22
|
+
async record(input: AgentTokenRateRecord): Promise<void> {
|
|
23
|
+
assertAgentTokenRateRecord(input, "SixbSqlite")
|
|
24
|
+
|
|
25
|
+
runImmediateTransaction(this.db, () => {
|
|
26
|
+
this.db
|
|
27
|
+
.query(
|
|
28
|
+
`INSERT INTO agent_token_rates (
|
|
29
|
+
project_id, run_id, provider_id, model_id, bytes, tokens, measured_at
|
|
30
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
31
|
+
ON CONFLICT (project_id, run_id) DO UPDATE SET
|
|
32
|
+
provider_id = excluded.provider_id, model_id = excluded.model_id,
|
|
33
|
+
bytes = excluded.bytes, tokens = excluded.tokens, measured_at = excluded.measured_at`
|
|
34
|
+
)
|
|
35
|
+
.run(
|
|
36
|
+
input.projectId,
|
|
37
|
+
input.runId,
|
|
38
|
+
input.providerId,
|
|
39
|
+
input.modelId,
|
|
40
|
+
input.bytes,
|
|
41
|
+
input.tokens,
|
|
42
|
+
input.measuredAt.toISOString()
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
this.db
|
|
46
|
+
.query(
|
|
47
|
+
`DELETE FROM agent_token_rates
|
|
48
|
+
WHERE project_id = ?1 AND provider_id = ?2 AND model_id = ?3
|
|
49
|
+
AND run_id NOT IN (
|
|
50
|
+
SELECT run_id FROM agent_token_rates
|
|
51
|
+
WHERE project_id = ?1 AND provider_id = ?2 AND model_id = ?3
|
|
52
|
+
ORDER BY measured_at DESC, run_id DESC
|
|
53
|
+
LIMIT ?4
|
|
54
|
+
)`
|
|
55
|
+
)
|
|
56
|
+
.run(input.projectId, input.providerId, input.modelId, AGENT_TOKEN_RATE_SAMPLES)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async listLatest(input: {
|
|
61
|
+
readonly projectId: string
|
|
62
|
+
readonly providerId: string
|
|
63
|
+
readonly modelId: string
|
|
64
|
+
}): Promise<readonly AgentTokenRateRecord[]> {
|
|
65
|
+
const rows = this.db
|
|
66
|
+
.query(
|
|
67
|
+
`SELECT project_id, run_id, provider_id, model_id, bytes, tokens, measured_at
|
|
68
|
+
FROM agent_token_rates
|
|
69
|
+
WHERE project_id = ? AND provider_id = ? AND model_id = ?
|
|
70
|
+
ORDER BY measured_at DESC, run_id DESC
|
|
71
|
+
LIMIT ?`
|
|
72
|
+
)
|
|
73
|
+
.all(
|
|
74
|
+
input.projectId,
|
|
75
|
+
input.providerId,
|
|
76
|
+
input.modelId,
|
|
77
|
+
AGENT_TOKEN_RATE_SAMPLES
|
|
78
|
+
) as TokenRateRow[]
|
|
79
|
+
|
|
80
|
+
return rows.map((row) => ({
|
|
81
|
+
projectId: row.project_id,
|
|
82
|
+
providerId: row.provider_id,
|
|
83
|
+
modelId: row.model_id,
|
|
84
|
+
runId: row.run_id,
|
|
85
|
+
bytes: row.bytes,
|
|
86
|
+
tokens: row.tokens,
|
|
87
|
+
measuredAt: new Date(row.measured_at),
|
|
88
|
+
}))
|
|
89
|
+
}
|
|
90
|
+
}
|