theokit 0.55.0 → 0.56.0
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/{actions-virtual-module-TZFLCIIR.js → actions-virtual-module-3V7VG2YL.js} +3 -3
- package/dist/{actions-virtual-module-PREAJNIS.js → actions-virtual-module-KJBCM7PP.js} +21 -21
- package/dist/adapters/agent-mount.d.ts +1 -1
- package/dist/adapters/agent-mount.js +9 -9
- package/dist/{agent-2AELELAC.js → agent-NLG77PFN.js} +3 -3
- package/dist/{agents-typed-client-INR2E7B3.js → agents-typed-client-PVUZU65B.js} +3 -3
- package/dist/{app-typed-client-KSFGMOQ6.js → app-typed-client-XSXAORG6.js} +21 -21
- package/dist/{app-typed-client-NEKRXPAQ.js → app-typed-client-ZO3VKJ3O.js} +3 -3
- package/dist/boot/index.js +3 -3
- package/dist/{build-ESSQS5F5.js → build-4GQLIFTD.js} +3 -3
- package/dist/{bun-L7PP6ID5.js → bun-POLTY2HK.js} +118 -3
- package/dist/bun-POLTY2HK.js.map +1 -0
- package/dist/{chunk-DADMEW4G.js → chunk-22ZZSUKD.js} +2 -2
- package/dist/{chunk-5YPXXSYY.js → chunk-35QIWOHT.js} +9 -8
- package/dist/chunk-35QIWOHT.js.map +1 -0
- package/dist/{chunk-JDN5SAAD.js → chunk-44E7XIZC.js} +6 -6
- package/dist/{chunk-OQCRCXCP.js → chunk-4ERYQBL6.js} +2 -2
- package/dist/{chunk-52PDWL5S.js → chunk-5KRMDP46.js} +2 -2
- package/dist/{chunk-VRELW5NF.js → chunk-5TPBOAAH.js} +8 -8
- package/dist/{chunk-QZUIF64G.js → chunk-6PFF5HMY.js} +3 -3
- package/dist/{chunk-VQPHPQ5L.js → chunk-7NRFZBAL.js} +3 -3
- package/dist/{chunk-3PBAN2YE.js → chunk-CF2DNN5R.js} +9 -8
- package/dist/{chunk-3PBAN2YE.js.map → chunk-CF2DNN5R.js.map} +1 -1
- package/dist/{chunk-HK4AZBKX.js → chunk-D5KBBTVD.js} +7 -7
- package/dist/{chunk-BU6RJPPJ.js → chunk-GO7UWJ47.js} +2 -2
- package/dist/{chunk-BU6RJPPJ.js.map → chunk-GO7UWJ47.js.map} +1 -1
- package/dist/{chunk-VZTYCAO6.js → chunk-IDEZ7FU2.js} +3 -3
- package/dist/{chunk-ITSNTHWN.js → chunk-JW5UFKQ3.js} +17 -17
- package/dist/{chunk-IRASEXOG.js → chunk-KDP2HURW.js} +6 -6
- package/dist/{chunk-GWE4MUKQ.js → chunk-KQ27YDLG.js} +8 -8
- package/dist/{chunk-WX6NHGKS.js → chunk-M357ILK5.js} +10 -10
- package/dist/{chunk-ZQO37YQJ.js → chunk-PELXWPDF.js} +5 -5
- package/dist/{chunk-2OEN3YTE.js → chunk-PVNMLZ5G.js} +2 -2
- package/dist/{chunk-5K4TDLRG.js → chunk-SOYOYGWY.js} +3 -3
- package/dist/{chunk-2PSKQWGM.js → chunk-TUO2FE3S.js} +3 -3
- package/dist/{chunk-4X6H2BXP.js → chunk-U3SPBLJF.js} +3 -3
- package/dist/{chunk-BX6EUYHU.js → chunk-V6Y2SMRG.js} +3 -3
- package/dist/{chunk-I2UN46ZX.js → chunk-XJOU425Y.js} +17 -17
- package/dist/{chunk-3DRALT3J.js → chunk-XYVZJCZU.js} +4 -4
- package/dist/{chunk-BND4YZTQ.js → chunk-ZDCCILMP.js} +2 -2
- package/dist/{chunk-F6P6S5YS.js → chunk-ZTIB4QSV.js} +63 -63
- package/dist/cli/index.js +6 -6
- package/dist/{controller-swc-transform-T7ZTD55V.js → controller-swc-transform-7EZKG2IS.js} +2 -2
- package/dist/cost-types-BALTuBpG.d.ts +79 -0
- package/dist/{dev-MWGPBGQP.js → dev-ZNTHPBBN.js} +5 -5
- package/dist/{dev-emit-W27J3DLU.js → dev-emit-FIQASO3D.js} +7 -7
- package/dist/index.js +23 -23
- package/dist/{internal-api-XSUP3NDI.js → internal-api-D76JZGSC.js} +3 -3
- package/dist/{internal-api-J3BYA3VU.js → internal-api-JNX3MTIM.js} +26 -26
- package/dist/{mcp-6IPY275L.js → mcp-IMY3NUCL.js} +3 -3
- package/dist/{preview-KPAKWBRW.js → preview-K4NIQLAK.js} +3 -3
- package/dist/{provider-resolver-Dx6QuWrw.d.ts → provider-resolver-VS61zqsw.d.ts} +0 -11
- package/dist/{registry-KBZDCFVQ.js → registry-3LUHO4IB.js} +2 -2
- package/dist/server/agent/index.d.ts +1 -1
- package/dist/server/agent/index.js +3 -3
- package/dist/server/cost/index.d.ts +3 -80
- package/dist/server/cost/sqlite/index.d.ts +21 -0
- package/dist/server/cost/sqlite/index.js +102 -0
- package/dist/server/cost/sqlite/index.js.map +1 -0
- package/dist/server/cron/index.js +4 -4
- package/dist/server/http/index.js +7 -7
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +79 -79
- package/dist/server/jobs/index.d.ts +2 -2
- package/dist/server/jobs/index.js +4 -4
- package/dist/server/observability/index.js +2 -2
- package/dist/server/scan/index.js +6 -6
- package/dist/server/storage/index.d.ts +2 -2
- package/dist/server/webhook/index.js +1 -1
- package/dist/{server-boundary-7ZO4FZIV.js → server-boundary-654WC5SA.js} +23 -23
- package/dist/{server-boundary-PGPFBJBH.js → server-boundary-NW6LNNGK.js} +3 -3
- package/dist/{server-routes-hmr-BWN3WIGR.js → server-routes-hmr-TNI3FNGM.js} +2 -2
- package/dist/{services-typed-client-IXNOPVZA.js → services-typed-client-ACTJHAEP.js} +2 -2
- package/dist/{start-F3T2ZPPI.js → start-ONZXIWEG.js} +4 -4
- package/dist/{storage-manager-C6hmsaer.d.ts → storage-manager-BtG38jYl.d.ts} +1 -1
- package/dist/{storage-types-DsDTCPbp.d.ts → storage-types-CFGPFIdB.d.ts} +1 -1
- package/dist/vite-plugin/index.js +21 -21
- package/dist/{vite-plugin-5O3D472R.js → vite-plugin-UET2BUFW.js} +5 -5
- package/package.json +7 -3
- package/dist/bun-L7PP6ID5.js.map +0 -1
- package/dist/chunk-5YPXXSYY.js.map +0 -1
- /package/dist/{actions-virtual-module-TZFLCIIR.js.map → actions-virtual-module-3V7VG2YL.js.map} +0 -0
- /package/dist/{actions-virtual-module-PREAJNIS.js.map → actions-virtual-module-KJBCM7PP.js.map} +0 -0
- /package/dist/{agent-2AELELAC.js.map → agent-NLG77PFN.js.map} +0 -0
- /package/dist/{agents-typed-client-INR2E7B3.js.map → agents-typed-client-PVUZU65B.js.map} +0 -0
- /package/dist/{app-typed-client-KSFGMOQ6.js.map → app-typed-client-XSXAORG6.js.map} +0 -0
- /package/dist/{app-typed-client-NEKRXPAQ.js.map → app-typed-client-ZO3VKJ3O.js.map} +0 -0
- /package/dist/{build-ESSQS5F5.js.map → build-4GQLIFTD.js.map} +0 -0
- /package/dist/{chunk-DADMEW4G.js.map → chunk-22ZZSUKD.js.map} +0 -0
- /package/dist/{chunk-JDN5SAAD.js.map → chunk-44E7XIZC.js.map} +0 -0
- /package/dist/{chunk-OQCRCXCP.js.map → chunk-4ERYQBL6.js.map} +0 -0
- /package/dist/{chunk-52PDWL5S.js.map → chunk-5KRMDP46.js.map} +0 -0
- /package/dist/{chunk-VRELW5NF.js.map → chunk-5TPBOAAH.js.map} +0 -0
- /package/dist/{chunk-QZUIF64G.js.map → chunk-6PFF5HMY.js.map} +0 -0
- /package/dist/{chunk-VQPHPQ5L.js.map → chunk-7NRFZBAL.js.map} +0 -0
- /package/dist/{chunk-HK4AZBKX.js.map → chunk-D5KBBTVD.js.map} +0 -0
- /package/dist/{chunk-VZTYCAO6.js.map → chunk-IDEZ7FU2.js.map} +0 -0
- /package/dist/{chunk-ITSNTHWN.js.map → chunk-JW5UFKQ3.js.map} +0 -0
- /package/dist/{chunk-IRASEXOG.js.map → chunk-KDP2HURW.js.map} +0 -0
- /package/dist/{chunk-GWE4MUKQ.js.map → chunk-KQ27YDLG.js.map} +0 -0
- /package/dist/{chunk-WX6NHGKS.js.map → chunk-M357ILK5.js.map} +0 -0
- /package/dist/{chunk-ZQO37YQJ.js.map → chunk-PELXWPDF.js.map} +0 -0
- /package/dist/{chunk-2OEN3YTE.js.map → chunk-PVNMLZ5G.js.map} +0 -0
- /package/dist/{chunk-5K4TDLRG.js.map → chunk-SOYOYGWY.js.map} +0 -0
- /package/dist/{chunk-2PSKQWGM.js.map → chunk-TUO2FE3S.js.map} +0 -0
- /package/dist/{chunk-4X6H2BXP.js.map → chunk-U3SPBLJF.js.map} +0 -0
- /package/dist/{chunk-BX6EUYHU.js.map → chunk-V6Y2SMRG.js.map} +0 -0
- /package/dist/{chunk-I2UN46ZX.js.map → chunk-XJOU425Y.js.map} +0 -0
- /package/dist/{chunk-3DRALT3J.js.map → chunk-XYVZJCZU.js.map} +0 -0
- /package/dist/{chunk-BND4YZTQ.js.map → chunk-ZDCCILMP.js.map} +0 -0
- /package/dist/{chunk-F6P6S5YS.js.map → chunk-ZTIB4QSV.js.map} +0 -0
- /package/dist/{controller-swc-transform-T7ZTD55V.js.map → controller-swc-transform-7EZKG2IS.js.map} +0 -0
- /package/dist/{dev-MWGPBGQP.js.map → dev-ZNTHPBBN.js.map} +0 -0
- /package/dist/{dev-emit-W27J3DLU.js.map → dev-emit-FIQASO3D.js.map} +0 -0
- /package/dist/{internal-api-XSUP3NDI.js.map → internal-api-D76JZGSC.js.map} +0 -0
- /package/dist/{internal-api-J3BYA3VU.js.map → internal-api-JNX3MTIM.js.map} +0 -0
- /package/dist/{mcp-6IPY275L.js.map → mcp-IMY3NUCL.js.map} +0 -0
- /package/dist/{preview-KPAKWBRW.js.map → preview-K4NIQLAK.js.map} +0 -0
- /package/dist/{registry-KBZDCFVQ.js.map → registry-3LUHO4IB.js.map} +0 -0
- /package/dist/{server-boundary-7ZO4FZIV.js.map → server-boundary-654WC5SA.js.map} +0 -0
- /package/dist/{server-boundary-PGPFBJBH.js.map → server-boundary-NW6LNNGK.js.map} +0 -0
- /package/dist/{server-routes-hmr-BWN3WIGR.js.map → server-routes-hmr-TNI3FNGM.js.map} +0 -0
- /package/dist/{services-typed-client-IXNOPVZA.js.map → services-typed-client-ACTJHAEP.js.map} +0 -0
- /package/dist/{start-F3T2ZPPI.js.map → start-ONZXIWEG.js.map} +0 -0
- /package/dist/{vite-plugin-5O3D472R.js.map → vite-plugin-UET2BUFW.js.map} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost tracking types (R0.5.11).
|
|
3
|
+
*
|
|
4
|
+
* Phase 5 — Production-Readiness #4: adds `ToolUsageRecord` for per-tool
|
|
5
|
+
* latency / error tracking via SDK's onToolStart/onToolEnd/onToolError hooks.
|
|
6
|
+
* Same UsageStorageAdapter handles both via discriminated union.
|
|
7
|
+
*
|
|
8
|
+
* EC-9 (SHOULD TEST): backward compat — record() input without `kind` is
|
|
9
|
+
* normalized to 'llm' by the framework so external adapters from older
|
|
10
|
+
* versions keep working.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Per-LLM-call cost record (existing — gains optional `kind` discriminator).
|
|
14
|
+
*/
|
|
15
|
+
interface UsageRecord {
|
|
16
|
+
/** Discriminator. Optional for backward-compat; defaults to 'llm'. */
|
|
17
|
+
kind?: 'llm';
|
|
18
|
+
/** User identifier (e.g., session userId, tenantId, apiKey hash). */
|
|
19
|
+
userId: string;
|
|
20
|
+
/** Model id (e.g., 'claude-sonnet-4-5-20250929'). */
|
|
21
|
+
model: string;
|
|
22
|
+
/** Token counts per direction. */
|
|
23
|
+
tokens: {
|
|
24
|
+
input: number;
|
|
25
|
+
output: number;
|
|
26
|
+
};
|
|
27
|
+
/** USD cost in fractional dollars. */
|
|
28
|
+
costUsd: number;
|
|
29
|
+
/** When the run happened. */
|
|
30
|
+
timestamp: Date;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Per-tool-invocation record (Phase 5 — Production-Readiness #4).
|
|
34
|
+
*
|
|
35
|
+
* Emitted by `trackAgentTools` on every `onToolEnd` / `onToolError`. The same
|
|
36
|
+
* `UsageStorageAdapter.record` accepts both record kinds via union.
|
|
37
|
+
*/
|
|
38
|
+
interface ToolUsageRecord {
|
|
39
|
+
kind: 'tool';
|
|
40
|
+
userId: string;
|
|
41
|
+
conversationId: string;
|
|
42
|
+
toolName: string;
|
|
43
|
+
/**
|
|
44
|
+
* Unique per invocation; correlates onToolStart with onToolEnd / onToolError.
|
|
45
|
+
* EC-16 (DOCUMENT): callId uniqueness is SDK contract — if SDK ever reuses
|
|
46
|
+
* a callId, `trackAgentTools`'s Map uses last-write-wins (defensive).
|
|
47
|
+
*/
|
|
48
|
+
callId: string;
|
|
49
|
+
/** True when the tool handler returned; false when it threw. */
|
|
50
|
+
success: boolean;
|
|
51
|
+
/** Milliseconds from onToolStart to onToolEnd / onToolError. */
|
|
52
|
+
durationMs: number;
|
|
53
|
+
/** Populated only when success === false. */
|
|
54
|
+
errorMessage?: string;
|
|
55
|
+
timestamp: Date;
|
|
56
|
+
}
|
|
57
|
+
interface UsageQuery {
|
|
58
|
+
userId: string;
|
|
59
|
+
period: {
|
|
60
|
+
from: Date;
|
|
61
|
+
to: Date;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface UsageResult {
|
|
65
|
+
totalTokens: number;
|
|
66
|
+
totalCostUsd: number;
|
|
67
|
+
runs: number;
|
|
68
|
+
}
|
|
69
|
+
interface UsageStorageAdapter {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
/**
|
|
72
|
+
* Record a usage event. Accepts both kinds; framework normalizes input
|
|
73
|
+
* without `kind` to 'llm' before calling adapter (EC-9 backward compat).
|
|
74
|
+
*/
|
|
75
|
+
record(input: UsageRecord | ToolUsageRecord): Promise<void>;
|
|
76
|
+
getUsage(query: UsageQuery): Promise<UsageResult>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type { ToolUsageRecord as T, UsageStorageAdapter as U, UsageRecord as a, UsageQuery as b, UsageResult as c };
|
|
@@ -11,14 +11,14 @@ import {
|
|
|
11
11
|
} from "./chunk-KTMQUYED.js";
|
|
12
12
|
import {
|
|
13
13
|
theoPluginAsync
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-5TPBOAAH.js";
|
|
15
|
+
import "./chunk-6PFF5HMY.js";
|
|
16
16
|
import "./chunk-2CVV6CNN.js";
|
|
17
17
|
import "./chunk-3PWQQWT6.js";
|
|
18
18
|
import "./chunk-FDOOBTXJ.js";
|
|
19
19
|
import "./chunk-47MM2JUK.js";
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
import "./chunk-22ZZSUKD.js";
|
|
21
|
+
import "./chunk-35QIWOHT.js";
|
|
22
22
|
import "./chunk-MWWFXYW3.js";
|
|
23
23
|
import "./chunk-RPET332G.js";
|
|
24
24
|
import "./chunk-5VLP3GQ2.js";
|
|
@@ -123,4 +123,4 @@ export {
|
|
|
123
123
|
devCommand,
|
|
124
124
|
startDevServer
|
|
125
125
|
};
|
|
126
|
-
//# sourceMappingURL=dev-
|
|
126
|
+
//# sourceMappingURL=dev-ZNTHPBBN.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateManifest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XJOU425Y.js";
|
|
4
|
+
import "./chunk-KDP2HURW.js";
|
|
4
5
|
import "./chunk-DV34VG3N.js";
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-5K4TDLRG.js";
|
|
6
|
+
import "./chunk-SOYOYGWY.js";
|
|
7
7
|
import "./chunk-ZWN3AODA.js";
|
|
8
8
|
import "./chunk-XTHN6JBX.js";
|
|
9
9
|
|
|
10
10
|
// src/vite-plugin/openapi-emit/emit.ts
|
|
11
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
12
|
-
import { join } from "path";
|
|
11
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
13
|
|
|
14
14
|
// src/vite-plugin/openapi-emit/zod-to-openapi.ts
|
|
15
15
|
import { z } from "zod";
|
|
@@ -235,7 +235,7 @@ function applyServerOverride(servers) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
// src/vite-plugin/openapi-emit/load-routes.ts
|
|
238
|
-
import { resolve } from "path";
|
|
238
|
+
import { resolve } from "node:path";
|
|
239
239
|
var HTTP_METHOD_KEYS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
240
240
|
async function loadRoutesForOpenApi(options) {
|
|
241
241
|
const { serverDir, routes } = options;
|
|
@@ -339,4 +339,4 @@ export {
|
|
|
339
339
|
_resetInFlightForTests,
|
|
340
340
|
reEmitOpenApi
|
|
341
341
|
};
|
|
342
|
-
//# sourceMappingURL=dev-emit-
|
|
342
|
+
//# sourceMappingURL=dev-emit-FIQASO3D.js.map
|
package/dist/index.js
CHANGED
|
@@ -8,44 +8,44 @@ import {
|
|
|
8
8
|
scanRoutes,
|
|
9
9
|
theoConfigSchema,
|
|
10
10
|
theoPlugin
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-ZTIB4QSV.js";
|
|
12
|
+
import "./chunk-7NRFZBAL.js";
|
|
13
13
|
import "./chunk-SSYDEKWF.js";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-XYVZJCZU.js";
|
|
15
|
+
import "./chunk-M357ILK5.js";
|
|
15
16
|
import "./chunk-OIGJOYX6.js";
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-U3SPBLJF.js";
|
|
18
|
+
import "./chunk-BPYMC7SU.js";
|
|
19
|
+
import "./chunk-IRQGAC4L.js";
|
|
18
20
|
import "./chunk-OGLS76RN.js";
|
|
19
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-JW5UFKQ3.js";
|
|
22
|
+
import "./chunk-P6OS7652.js";
|
|
20
23
|
import "./chunk-ZDUO4IYN.js";
|
|
24
|
+
import "./chunk-D4VP2QPR.js";
|
|
25
|
+
import "./chunk-YN4W7LCX.js";
|
|
21
26
|
import "./chunk-47FFT43U.js";
|
|
22
27
|
import "./chunk-NTDN54XO.js";
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
28
|
+
import "./chunk-PVNMLZ5G.js";
|
|
29
|
+
import "./chunk-ZDCCILMP.js";
|
|
25
30
|
import "./chunk-CHTAWXC2.js";
|
|
31
|
+
import "./chunk-AVQU5CQF.js";
|
|
26
32
|
import "./chunk-VSLTKX5L.js";
|
|
27
33
|
import "./chunk-TNI4MARH.js";
|
|
28
|
-
import "./chunk-
|
|
29
|
-
import "./chunk-
|
|
34
|
+
import "./chunk-4ERYQBL6.js";
|
|
35
|
+
import "./chunk-XJOU425Y.js";
|
|
36
|
+
import "./chunk-KDP2HURW.js";
|
|
30
37
|
import "./chunk-DV34VG3N.js";
|
|
31
|
-
import "./chunk-
|
|
32
|
-
import "./chunk-BX6EUYHU.js";
|
|
33
|
-
import "./chunk-BPYMC7SU.js";
|
|
34
|
-
import "./chunk-IRQGAC4L.js";
|
|
35
|
-
import "./chunk-P6OS7652.js";
|
|
36
|
-
import "./chunk-AVQU5CQF.js";
|
|
38
|
+
import "./chunk-V6Y2SMRG.js";
|
|
37
39
|
import "./chunk-ACKBVBUI.js";
|
|
38
40
|
import "./chunk-IZ3TIL6K.js";
|
|
39
41
|
import "./chunk-YOIVCCZT.js";
|
|
40
|
-
import "./chunk-
|
|
42
|
+
import "./chunk-CF2DNN5R.js";
|
|
41
43
|
import "./chunk-YSJOZEI6.js";
|
|
42
44
|
import "./chunk-Z4PJMZLM.js";
|
|
43
45
|
import "./chunk-UMNXCU3K.js";
|
|
44
|
-
import "./chunk-
|
|
45
|
-
import "./chunk-
|
|
46
|
+
import "./chunk-5KRMDP46.js";
|
|
47
|
+
import "./chunk-SOYOYGWY.js";
|
|
46
48
|
import "./chunk-ZWN3AODA.js";
|
|
47
|
-
import "./chunk-D4VP2QPR.js";
|
|
48
|
-
import "./chunk-YN4W7LCX.js";
|
|
49
49
|
import "./chunk-XTHN6JBX.js";
|
|
50
50
|
|
|
51
51
|
// src/config/define-config.ts
|
|
@@ -74,8 +74,8 @@ function config() {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/config/validate-structure.ts
|
|
77
|
-
import { existsSync } from "fs";
|
|
78
|
-
import { join } from "path";
|
|
77
|
+
import { existsSync } from "node:fs";
|
|
78
|
+
import { join } from "node:path";
|
|
79
79
|
|
|
80
80
|
// src/core/errors.ts
|
|
81
81
|
var TheoProjectError = class extends Error {
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
handleCspReport,
|
|
17
17
|
handleCsrfReadiness,
|
|
18
18
|
mountAgent
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-22ZZSUKD.js";
|
|
20
20
|
import {
|
|
21
21
|
resolveProvider
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-35QIWOHT.js";
|
|
23
23
|
import {
|
|
24
24
|
dispatchControllerRequest,
|
|
25
25
|
incomingMessageToHandlerRequest,
|
|
@@ -87,4 +87,4 @@ export {
|
|
|
87
87
|
scanWebSocketRoutes,
|
|
88
88
|
sendError
|
|
89
89
|
};
|
|
90
|
-
//# sourceMappingURL=internal-api-
|
|
90
|
+
//# sourceMappingURL=internal-api-D76JZGSC.js.map
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dispatchControllerRequest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XYVZJCZU.js";
|
|
4
4
|
import {
|
|
5
5
|
mountAgent
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-M357ILK5.js";
|
|
7
|
+
import {
|
|
8
|
+
CSP_REPORT_PATH,
|
|
9
|
+
CsrfReadinessStore,
|
|
10
|
+
applySecurityHeaders,
|
|
11
|
+
handleCspReport,
|
|
12
|
+
handleCsrfReadiness
|
|
13
|
+
} from "./chunk-BPYMC7SU.js";
|
|
14
|
+
import "./chunk-IRQGAC4L.js";
|
|
7
15
|
import {
|
|
8
16
|
BATCH_PATH,
|
|
9
17
|
createCorsHandler,
|
|
@@ -12,19 +20,23 @@ import {
|
|
|
12
20
|
handleBatchRequest,
|
|
13
21
|
incomingMessageToHandlerRequest,
|
|
14
22
|
sendError
|
|
15
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-JW5UFKQ3.js";
|
|
24
|
+
import "./chunk-P6OS7652.js";
|
|
16
25
|
import "./chunk-ZDUO4IYN.js";
|
|
26
|
+
import "./chunk-D4VP2QPR.js";
|
|
27
|
+
import "./chunk-YN4W7LCX.js";
|
|
17
28
|
import "./chunk-47FFT43U.js";
|
|
18
29
|
import {
|
|
19
30
|
findSuggestion
|
|
20
31
|
} from "./chunk-NTDN54XO.js";
|
|
21
|
-
import "./chunk-
|
|
32
|
+
import "./chunk-PVNMLZ5G.js";
|
|
22
33
|
import {
|
|
23
34
|
TRACE_HEADER,
|
|
24
35
|
extractTraceId,
|
|
25
36
|
logRequest
|
|
26
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-ZDCCILMP.js";
|
|
27
38
|
import "./chunk-CHTAWXC2.js";
|
|
39
|
+
import "./chunk-AVQU5CQF.js";
|
|
28
40
|
import {
|
|
29
41
|
createPluginRunnerFromConfig
|
|
30
42
|
} from "./chunk-VSLTKX5L.js";
|
|
@@ -33,7 +45,7 @@ import {
|
|
|
33
45
|
} from "./chunk-TNI4MARH.js";
|
|
34
46
|
import {
|
|
35
47
|
createViteLoader
|
|
36
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-4ERYQBL6.js";
|
|
37
49
|
import {
|
|
38
50
|
ACTION_SCHEMAS_DIR,
|
|
39
51
|
generateManifest,
|
|
@@ -42,37 +54,25 @@ import {
|
|
|
42
54
|
scanServerActionsEnriched,
|
|
43
55
|
scanServerRoutes,
|
|
44
56
|
scanWebSocketRoutes
|
|
45
|
-
} from "./chunk-
|
|
46
|
-
import "./chunk-DV34VG3N.js";
|
|
57
|
+
} from "./chunk-XJOU425Y.js";
|
|
47
58
|
import {
|
|
48
59
|
scanAgents
|
|
49
|
-
} from "./chunk-
|
|
50
|
-
import "./chunk-
|
|
51
|
-
import
|
|
52
|
-
CSP_REPORT_PATH,
|
|
53
|
-
CsrfReadinessStore,
|
|
54
|
-
applySecurityHeaders,
|
|
55
|
-
handleCspReport,
|
|
56
|
-
handleCsrfReadiness
|
|
57
|
-
} from "./chunk-BPYMC7SU.js";
|
|
58
|
-
import "./chunk-IRQGAC4L.js";
|
|
59
|
-
import "./chunk-P6OS7652.js";
|
|
60
|
-
import "./chunk-AVQU5CQF.js";
|
|
60
|
+
} from "./chunk-KDP2HURW.js";
|
|
61
|
+
import "./chunk-DV34VG3N.js";
|
|
62
|
+
import "./chunk-V6Y2SMRG.js";
|
|
61
63
|
import "./chunk-ACKBVBUI.js";
|
|
62
64
|
import "./chunk-IZ3TIL6K.js";
|
|
63
65
|
import {
|
|
64
66
|
resolveProvider
|
|
65
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-CF2DNN5R.js";
|
|
66
68
|
import "./chunk-YSJOZEI6.js";
|
|
67
69
|
import {
|
|
68
70
|
generateNonce
|
|
69
71
|
} from "./chunk-Z4PJMZLM.js";
|
|
70
72
|
import "./chunk-UMNXCU3K.js";
|
|
71
|
-
import "./chunk-
|
|
72
|
-
import "./chunk-
|
|
73
|
+
import "./chunk-5KRMDP46.js";
|
|
74
|
+
import "./chunk-SOYOYGWY.js";
|
|
73
75
|
import "./chunk-ZWN3AODA.js";
|
|
74
|
-
import "./chunk-D4VP2QPR.js";
|
|
75
|
-
import "./chunk-YN4W7LCX.js";
|
|
76
76
|
import "./chunk-XTHN6JBX.js";
|
|
77
77
|
export {
|
|
78
78
|
ACTION_SCHEMAS_DIR,
|
|
@@ -107,4 +107,4 @@ export {
|
|
|
107
107
|
scanWebSocketRoutes,
|
|
108
108
|
sendError
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=internal-api-
|
|
110
|
+
//# sourceMappingURL=internal-api-JNX3MTIM.js.map
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import "tsx/esm";
|
|
3
3
|
import {
|
|
4
4
|
createAgentSsrLoader
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TUO2FE3S.js";
|
|
6
6
|
import {
|
|
7
7
|
extractAppResources,
|
|
8
8
|
handleMcpJsonRpc
|
|
9
9
|
} from "./chunk-2CVV6CNN.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-35QIWOHT.js";
|
|
11
11
|
import {
|
|
12
12
|
scanAgents
|
|
13
13
|
} from "./chunk-5NNFO7R7.js";
|
|
@@ -75,4 +75,4 @@ async function mcpCommand(name, deps = {}) {
|
|
|
75
75
|
export {
|
|
76
76
|
mcpCommand
|
|
77
77
|
};
|
|
78
|
-
//# sourceMappingURL=mcp-
|
|
78
|
+
//# sourceMappingURL=mcp-IMY3NUCL.js.map
|
|
@@ -4,8 +4,8 @@ import "tsx/esm";
|
|
|
4
4
|
// src/cli/commands/preview.ts
|
|
5
5
|
async function defaultSteps() {
|
|
6
6
|
const [{ buildCommand }, { startCommand }] = await Promise.all([
|
|
7
|
-
import("./build-
|
|
8
|
-
import("./start-
|
|
7
|
+
import("./build-4GQLIFTD.js"),
|
|
8
|
+
import("./start-ONZXIWEG.js")
|
|
9
9
|
]);
|
|
10
10
|
return {
|
|
11
11
|
build: (opts) => buildCommand(opts),
|
|
@@ -20,4 +20,4 @@ async function previewCommand(options = {}, steps) {
|
|
|
20
20
|
export {
|
|
21
21
|
previewCommand
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=preview-
|
|
23
|
+
//# sourceMappingURL=preview-K4NIQLAK.js.map
|
|
@@ -105,17 +105,6 @@ declare function resetProviderRegistry(): void;
|
|
|
105
105
|
* @public
|
|
106
106
|
*/
|
|
107
107
|
declare function listProviders(): readonly ProviderDescriptor[];
|
|
108
|
-
/**
|
|
109
|
-
* Resolve the provider for a model.
|
|
110
|
-
*
|
|
111
|
-
* When `modelId` declares a registered provider (`anthropic/…`), THAT provider's key is
|
|
112
|
-
* required — no substitution. Otherwise the registry is walked by priority, first match wins.
|
|
113
|
-
*
|
|
114
|
-
* @returns ResolvedProvider with apiKey + baseUrl + name
|
|
115
|
-
* @throws Error if NO provider env var is set (actionable message)
|
|
116
|
-
*
|
|
117
|
-
* @public
|
|
118
|
-
*/
|
|
119
108
|
declare function resolveProvider(modelId?: string, options?: ResolveOptions): ResolvedProvider;
|
|
120
109
|
/**
|
|
121
110
|
* Try to resolve — does NOT throw. Returns null if no provider available.
|
|
@@ -7,7 +7,7 @@ var adapterRegistry = {
|
|
|
7
7
|
vercel: async () => (await import("./vercel-BMCQKCWE.js")).vercelAdapter,
|
|
8
8
|
cloudflare: async () => (await import("./cloudflare-SIG42OIW.js")).cloudflareAdapter,
|
|
9
9
|
static: async () => (await import("./static-SVDWIOXJ.js")).staticAdapter,
|
|
10
|
-
bun: async () => (await import("./bun-
|
|
10
|
+
bun: async () => (await import("./bun-POLTY2HK.js")).bunAdapter,
|
|
11
11
|
"deno-deploy": async () => (await import("./deno-deploy-LQAYOOPW.js")).denoDeployAdapter,
|
|
12
12
|
netlify: async () => (await import("./netlify-C2IRCZKI.js")).netlifyAdapter,
|
|
13
13
|
"aws-lambda": async () => (await import("./aws-lambda-VKMYUMP2.js")).awsLambdaAdapter,
|
|
@@ -20,4 +20,4 @@ async function resolveAdapter(target) {
|
|
|
20
20
|
export {
|
|
21
21
|
resolveAdapter
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=registry-
|
|
23
|
+
//# sourceMappingURL=registry-3LUHO4IB.js.map
|
|
@@ -4,7 +4,7 @@ import { AcpTransport } from '@theokit/agents';
|
|
|
4
4
|
export { InProcessApprovalRequest, InProcessApprovalRequiredError, InProcessAwaitApproval, StreamAgentTurnDeps, StreamAgentTurnInProcessInput, streamAgentTurnInProcess } from '@theokit/agents';
|
|
5
5
|
import { CustomTool as CustomTool$1 } from '@theokit/sdk';
|
|
6
6
|
import { V as VerifyFn } from '../../webhook-types-DGIjjcaI.js';
|
|
7
|
-
export { P as ProviderDescriptor, R as ResolvedProvider, l as listProviders, a as registerProvider, b as resetProviderRegistry, r as resolveProvider, t as tryResolveProvider } from '../../provider-resolver-
|
|
7
|
+
export { P as ProviderDescriptor, R as ResolvedProvider, l as listProviders, a as registerProvider, b as resetProviderRegistry, r as resolveProvider, t as tryResolveProvider } from '../../provider-resolver-VS61zqsw.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* M26 (ADR-0041) — `createWorkflowTool`: wrap an SDK `Workflow` as a `CustomTool`.
|
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
parseChannelPath,
|
|
13
13
|
serveMcpStdio,
|
|
14
14
|
streamAgentTurnInProcess
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-PELXWPDF.js";
|
|
16
|
+
import "../../chunk-BZF76LFM.js";
|
|
16
17
|
import {
|
|
17
18
|
buildResourceDescriptors,
|
|
18
19
|
defineAppResource,
|
|
@@ -25,8 +26,7 @@ import {
|
|
|
25
26
|
resetProviderRegistry,
|
|
26
27
|
resolveProvider,
|
|
27
28
|
tryResolveProvider
|
|
28
|
-
} from "../../chunk-
|
|
29
|
-
import "../../chunk-BZF76LFM.js";
|
|
29
|
+
} from "../../chunk-CF2DNN5R.js";
|
|
30
30
|
import "../../chunk-XTHN6JBX.js";
|
|
31
31
|
export {
|
|
32
32
|
CodeModePermissionDeniedError,
|
|
@@ -1,84 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { U as UsageStorageAdapter, a as UsageRecord, T as ToolUsageRecord, b as UsageQuery, c as UsageResult } from '../../cost-types-BALTuBpG.js';
|
|
2
|
+
import { S as StorageAdapter } from '../../storage-types-CFGPFIdB.js';
|
|
2
3
|
export { InMemoryUsageStorage as NeutralUsageStorage } from '@theokit/agents/usage';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Cost tracking types (R0.5.11).
|
|
6
|
-
*
|
|
7
|
-
* Phase 5 — Production-Readiness #4: adds `ToolUsageRecord` for per-tool
|
|
8
|
-
* latency / error tracking via SDK's onToolStart/onToolEnd/onToolError hooks.
|
|
9
|
-
* Same UsageStorageAdapter handles both via discriminated union.
|
|
10
|
-
*
|
|
11
|
-
* EC-9 (SHOULD TEST): backward compat — record() input without `kind` is
|
|
12
|
-
* normalized to 'llm' by the framework so external adapters from older
|
|
13
|
-
* versions keep working.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Per-LLM-call cost record (existing — gains optional `kind` discriminator).
|
|
17
|
-
*/
|
|
18
|
-
interface UsageRecord {
|
|
19
|
-
/** Discriminator. Optional for backward-compat; defaults to 'llm'. */
|
|
20
|
-
kind?: 'llm';
|
|
21
|
-
/** User identifier (e.g., session userId, tenantId, apiKey hash). */
|
|
22
|
-
userId: string;
|
|
23
|
-
/** Model id (e.g., 'claude-sonnet-4-5-20250929'). */
|
|
24
|
-
model: string;
|
|
25
|
-
/** Token counts per direction. */
|
|
26
|
-
tokens: {
|
|
27
|
-
input: number;
|
|
28
|
-
output: number;
|
|
29
|
-
};
|
|
30
|
-
/** USD cost in fractional dollars. */
|
|
31
|
-
costUsd: number;
|
|
32
|
-
/** When the run happened. */
|
|
33
|
-
timestamp: Date;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Per-tool-invocation record (Phase 5 — Production-Readiness #4).
|
|
37
|
-
*
|
|
38
|
-
* Emitted by `trackAgentTools` on every `onToolEnd` / `onToolError`. The same
|
|
39
|
-
* `UsageStorageAdapter.record` accepts both record kinds via union.
|
|
40
|
-
*/
|
|
41
|
-
interface ToolUsageRecord {
|
|
42
|
-
kind: 'tool';
|
|
43
|
-
userId: string;
|
|
44
|
-
conversationId: string;
|
|
45
|
-
toolName: string;
|
|
46
|
-
/**
|
|
47
|
-
* Unique per invocation; correlates onToolStart with onToolEnd / onToolError.
|
|
48
|
-
* EC-16 (DOCUMENT): callId uniqueness is SDK contract — if SDK ever reuses
|
|
49
|
-
* a callId, `trackAgentTools`'s Map uses last-write-wins (defensive).
|
|
50
|
-
*/
|
|
51
|
-
callId: string;
|
|
52
|
-
/** True when the tool handler returned; false when it threw. */
|
|
53
|
-
success: boolean;
|
|
54
|
-
/** Milliseconds from onToolStart to onToolEnd / onToolError. */
|
|
55
|
-
durationMs: number;
|
|
56
|
-
/** Populated only when success === false. */
|
|
57
|
-
errorMessage?: string;
|
|
58
|
-
timestamp: Date;
|
|
59
|
-
}
|
|
60
|
-
interface UsageQuery {
|
|
61
|
-
userId: string;
|
|
62
|
-
period: {
|
|
63
|
-
from: Date;
|
|
64
|
-
to: Date;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
interface UsageResult {
|
|
68
|
-
totalTokens: number;
|
|
69
|
-
totalCostUsd: number;
|
|
70
|
-
runs: number;
|
|
71
|
-
}
|
|
72
|
-
interface UsageStorageAdapter {
|
|
73
|
-
readonly name: string;
|
|
74
|
-
/**
|
|
75
|
-
* Record a usage event. Accepts both kinds; framework normalizes input
|
|
76
|
-
* without `kind` to 'llm' before calling adapter (EC-9 backward compat).
|
|
77
|
-
*/
|
|
78
|
-
record(input: UsageRecord | ToolUsageRecord): Promise<void>;
|
|
79
|
-
getUsage(query: UsageQuery): Promise<UsageResult>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
5
|
interface TrackAgentRunInput {
|
|
83
6
|
userId: string;
|
|
84
7
|
model: string;
|
|
@@ -172,4 +95,4 @@ interface TrackAgentToolsHooks {
|
|
|
172
95
|
*/
|
|
173
96
|
declare function trackAgentTools(opts: TrackAgentToolsOptions): TrackAgentToolsHooks;
|
|
174
97
|
|
|
175
|
-
export { InMemoryUsageStorage, type ToolHookEvent,
|
|
98
|
+
export { InMemoryUsageStorage, type ToolHookEvent, ToolUsageRecord, type TrackAgentRunInput, type TrackAgentRunOptions, type TrackAgentToolsHooks, type TrackAgentToolsOptions, UsageQuery, UsageRecord, UsageResult, UsageStorageAdapter, trackAgentRun, trackAgentTools };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { S as StorageAdapter } from '../../../storage-types-CFGPFIdB.js';
|
|
2
|
+
import { U as UsageStorageAdapter, a as UsageRecord, T as ToolUsageRecord, b as UsageQuery, c as UsageResult } from '../../../cost-types-BALTuBpG.js';
|
|
3
|
+
|
|
4
|
+
declare class SqliteUsageStorage implements UsageStorageAdapter, StorageAdapter {
|
|
5
|
+
#private;
|
|
6
|
+
readonly name = "sqlite";
|
|
7
|
+
/**
|
|
8
|
+
* @param filename path to the database file. `':memory:'` is accepted and is a legitimate choice
|
|
9
|
+
* for a test, but note that it defeats the entire purpose of this class in a deployment.
|
|
10
|
+
*/
|
|
11
|
+
constructor(filename: string);
|
|
12
|
+
record(input: UsageRecord | ToolUsageRecord): Promise<void>;
|
|
13
|
+
getUsage(query: UsageQuery): Promise<UsageResult>;
|
|
14
|
+
/**
|
|
15
|
+
* `StorageAdapter` lifecycle (ADR-0007 D6). Unlike the in-memory adapter's noop, this one has a
|
|
16
|
+
* file handle to release — a graceful shutdown that left it open would leave the WAL unmerged.
|
|
17
|
+
*/
|
|
18
|
+
dispose(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { SqliteUsageStorage };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import "../../../chunk-XTHN6JBX.js";
|
|
2
|
+
|
|
3
|
+
// src/server/cost/usage-storage-sqlite.ts
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
function loadSqlite() {
|
|
6
|
+
try {
|
|
7
|
+
const require_ = createRequire(import.meta.url);
|
|
8
|
+
const mod = require_("node:sqlite");
|
|
9
|
+
return mod.DatabaseSync;
|
|
10
|
+
} catch {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`SqliteUsageStorage needs \`node:sqlite\`, which this Node does not provide (running ${process.version}). It is not available at this package's engine floor of 22.12 \u2014 upgrade Node, or use a different UsageStorageAdapter: the interface is two methods and \`InMemoryUsageStorage\` shows the shape.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var SqliteUsageStorage = class {
|
|
17
|
+
name = "sqlite";
|
|
18
|
+
#db;
|
|
19
|
+
/**
|
|
20
|
+
* @param filename path to the database file. `':memory:'` is accepted and is a legitimate choice
|
|
21
|
+
* for a test, but note that it defeats the entire purpose of this class in a deployment.
|
|
22
|
+
*/
|
|
23
|
+
constructor(filename) {
|
|
24
|
+
const DatabaseSync = loadSqlite();
|
|
25
|
+
this.#db = new DatabaseSync(filename);
|
|
26
|
+
this.#db.exec("PRAGMA journal_mode = WAL");
|
|
27
|
+
this.#db.exec(`
|
|
28
|
+
CREATE TABLE IF NOT EXISTS usage (
|
|
29
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
+
kind TEXT NOT NULL,
|
|
31
|
+
user_id TEXT NOT NULL,
|
|
32
|
+
at_ms INTEGER NOT NULL,
|
|
33
|
+
model TEXT,
|
|
34
|
+
input_tok INTEGER,
|
|
35
|
+
output_tok INTEGER,
|
|
36
|
+
cost_usd REAL,
|
|
37
|
+
tool_name TEXT,
|
|
38
|
+
call_id TEXT,
|
|
39
|
+
success INTEGER,
|
|
40
|
+
duration_ms INTEGER,
|
|
41
|
+
error TEXT
|
|
42
|
+
)
|
|
43
|
+
`);
|
|
44
|
+
this.#db.exec("CREATE INDEX IF NOT EXISTS usage_lookup ON usage (user_id, kind, at_ms)");
|
|
45
|
+
}
|
|
46
|
+
record(input) {
|
|
47
|
+
if ("kind" in input && input.kind === "tool") {
|
|
48
|
+
this.#db.prepare(
|
|
49
|
+
`INSERT INTO usage (kind, user_id, at_ms, tool_name, call_id, success, duration_ms, error)
|
|
50
|
+
VALUES ('tool', ?, ?, ?, ?, ?, ?, ?)`
|
|
51
|
+
).run(
|
|
52
|
+
input.userId,
|
|
53
|
+
input.timestamp.getTime(),
|
|
54
|
+
input.toolName,
|
|
55
|
+
input.callId,
|
|
56
|
+
input.success ? 1 : 0,
|
|
57
|
+
input.durationMs,
|
|
58
|
+
input.errorMessage ?? null
|
|
59
|
+
);
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
}
|
|
62
|
+
const llm = input;
|
|
63
|
+
this.#db.prepare(
|
|
64
|
+
`INSERT INTO usage (kind, user_id, at_ms, model, input_tok, output_tok, cost_usd)
|
|
65
|
+
VALUES ('llm', ?, ?, ?, ?, ?, ?)`
|
|
66
|
+
).run(
|
|
67
|
+
llm.userId,
|
|
68
|
+
llm.timestamp.getTime(),
|
|
69
|
+
llm.model,
|
|
70
|
+
llm.tokens.input,
|
|
71
|
+
llm.tokens.output,
|
|
72
|
+
llm.costUsd
|
|
73
|
+
);
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
}
|
|
76
|
+
getUsage(query) {
|
|
77
|
+
const row = this.#db.prepare(
|
|
78
|
+
`SELECT COALESCE(SUM(input_tok + output_tok), 0) AS tokens,
|
|
79
|
+
COALESCE(SUM(cost_usd), 0) AS cost,
|
|
80
|
+
COUNT(*) AS runs
|
|
81
|
+
FROM usage
|
|
82
|
+
WHERE kind = 'llm' AND user_id = ? AND at_ms >= ? AND at_ms <= ?`
|
|
83
|
+
).get(query.userId, query.period.from.getTime(), query.period.to.getTime());
|
|
84
|
+
return Promise.resolve({
|
|
85
|
+
totalTokens: row?.tokens ?? 0,
|
|
86
|
+
totalCostUsd: row?.cost ?? 0,
|
|
87
|
+
runs: row?.runs ?? 0
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* `StorageAdapter` lifecycle (ADR-0007 D6). Unlike the in-memory adapter's noop, this one has a
|
|
92
|
+
* file handle to release — a graceful shutdown that left it open would leave the WAL unmerged.
|
|
93
|
+
*/
|
|
94
|
+
dispose() {
|
|
95
|
+
this.#db.close();
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export {
|
|
100
|
+
SqliteUsageStorage
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/server/cost/usage-storage-sqlite.ts"],"mappings":";;;AAAA,SAAS,qBAAqB;AAoE9B,SAAS,aAAuD;AAC9D,MAAI;AACF,UAAM,WAAW,cAAc,YAAY,GAAG;AAC9C,UAAM,MAAM,SAAS,aAAa;AAClC,WAAO,IAAI;AAAA,EACb,QAAQ;AACN,UAAM,IAAI;AAAA,MACR,uFACc,QAAQ,OAAO;AAAA,IAG/B;AAAA,EACF;AACF;AAEO,IAAM,qBAAN,MAAwE;AAAA,EACpE,OAAO;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA,EAMT,YAAY,UAAkB;AAC5B,UAAM,eAAe,WAAW;AAChC,SAAK,MAAM,IAAI,aAAa,QAAQ;AAGpC,SAAK,IAAI,KAAK,2BAA2B;AACzC,SAAK,IAAI,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAgBb;AAED,SAAK,IAAI,KAAK,yEAAyE;AAAA,EACzF;AAAA,EAEA,OAAO,OAAqD;AAG1D,QAAI,UAAU,SAAS,MAAM,SAAS,QAAQ;AAC5C,WAAK,IACF;AAAA,QACC;AAAA;AAAA,MAEF,EACC;AAAA,QACC,MAAM;AAAA,QACN,MAAM,UAAU,QAAQ;AAAA,QACxB,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM,UAAU,IAAI;AAAA,QACpB,MAAM;AAAA,QACN,MAAM,gBAAgB;AAAA,MACxB;AACF,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,UAAM,MAAM;AACZ,SAAK,IACF;AAAA,MACC;AAAA;AAAA,IAEF,EACC;AAAA,MACC,IAAI;AAAA,MACJ,IAAI,UAAU,QAAQ;AAAA,MACtB,IAAI;AAAA,MACJ,IAAI,OAAO;AAAA,MACX,IAAI,OAAO;AAAA,MACX,IAAI;AAAA,IACN;AACF,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,SAAS,OAAyC;AAChD,UAAM,MAAM,KAAK,IACd;AAAA,MACC;AAAA;AAAA;AAAA;AAAA;AAAA,IAKF,EACC,IAAI,MAAM,QAAQ,MAAM,OAAO,KAAK,QAAQ,GAAG,MAAM,OAAO,GAAG,QAAQ,CAAC;AAQ3E,WAAO,QAAQ,QAAQ;AAAA,MACrB,aAAa,KAAK,UAAU;AAAA,MAC5B,cAAc,KAAK,QAAQ;AAAA,MAC3B,MAAM,KAAK,QAAQ;AAAA,IACrB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAyB;AACvB,SAAK,IAAI,MAAM;AACf,WAAO,QAAQ,QAAQ;AAAA,EACzB;AACF;","names":[]}
|