@knpkv/agent-usage 0.1.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/client/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/client/assets/index-CUuLXODk.css +1 -0
- package/dist/client/assets/index-DB-VXWqy.js +55 -0
- package/dist/client/index.html +15 -0
- package/dist/core/Attribution.d.ts +59 -0
- package/dist/core/Attribution.js +108 -0
- package/dist/core/Attribution.js.map +1 -0
- package/dist/core/Balances.d.ts +27 -0
- package/dist/core/Balances.js +63 -0
- package/dist/core/Balances.js.map +1 -0
- package/dist/core/ClaudeLimits.d.ts +58 -0
- package/dist/core/ClaudeLimits.js +125 -0
- package/dist/core/ClaudeLimits.js.map +1 -0
- package/dist/core/ClaudeLimitsLive.d.ts +18 -0
- package/dist/core/ClaudeLimitsLive.js +36 -0
- package/dist/core/ClaudeLimitsLive.js.map +1 -0
- package/dist/core/ClaudeReader.d.ts +27 -0
- package/dist/core/ClaudeReader.js +154 -0
- package/dist/core/ClaudeReader.js.map +1 -0
- package/dist/core/CodexReader.d.ts +91 -0
- package/dist/core/CodexReader.js +365 -0
- package/dist/core/CodexReader.js.map +1 -0
- package/dist/core/Database.d.ts +4 -0
- package/dist/core/Database.js +65 -0
- package/dist/core/Database.js.map +1 -0
- package/dist/core/Ingest.d.ts +55 -0
- package/dist/core/Ingest.js +267 -0
- package/dist/core/Ingest.js.map +1 -0
- package/dist/core/Model.d.ts +160 -0
- package/dist/core/Model.js +125 -0
- package/dist/core/Model.js.map +1 -0
- package/dist/core/Pricing.d.ts +42 -0
- package/dist/core/Pricing.js +126 -0
- package/dist/core/Pricing.js.map +1 -0
- package/dist/core/Readers.d.ts +42 -0
- package/dist/core/Readers.js +18 -0
- package/dist/core/Readers.js.map +1 -0
- package/dist/core/Report.d.ts +53 -0
- package/dist/core/Report.js +270 -0
- package/dist/core/Report.js.map +1 -0
- package/dist/core/Store.d.ts +94 -0
- package/dist/core/Store.js +376 -0
- package/dist/core/Store.js.map +1 -0
- package/dist/core/Tickets.d.ts +42 -0
- package/dist/core/Tickets.js +125 -0
- package/dist/core/Tickets.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +65 -0
- package/dist/main.js.map +1 -0
- package/dist/server/Api.d.ts +304 -0
- package/dist/server/Api.js +20 -0
- package/dist/server/Api.js.map +1 -0
- package/dist/server/Config.d.ts +27 -0
- package/dist/server/Config.js +49 -0
- package/dist/server/Config.js.map +1 -0
- package/dist/server/Handlers.d.ts +5 -0
- package/dist/server/Handlers.js +48 -0
- package/dist/server/Handlers.js.map +1 -0
- package/dist/server/HttpApplication.d.ts +7 -0
- package/dist/server/HttpApplication.js +70 -0
- package/dist/server/HttpApplication.js.map +1 -0
- package/dist/server/OwnerSession.d.ts +60 -0
- package/dist/server/OwnerSession.js +206 -0
- package/dist/server/OwnerSession.js.map +1 -0
- package/dist/server/Runtime.d.ts +57 -0
- package/dist/server/Runtime.js +85 -0
- package/dist/server/Runtime.js.map +1 -0
- package/dist/server/Server.d.ts +15 -0
- package/dist/server/Server.js +39 -0
- package/dist/server/Server.js.map +1 -0
- package/dist/shared/contracts.d.ts +309 -0
- package/dist/shared/contracts.js +105 -0
- package/dist/shared/contracts.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What crosses the HTTP boundary, shared by the server and the browser so both decode with the same
|
|
3
|
+
* schemas. Browser-safe: no Node imports.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { Schema } from "effect";
|
|
8
|
+
declare const ApiError_base: Schema.Class<ApiError, Schema.TaggedStruct<"ApiError", {
|
|
9
|
+
readonly message: Schema.String;
|
|
10
|
+
}>, import("effect/Cause").YieldableError>;
|
|
11
|
+
export declare class ApiError extends ApiError_base {
|
|
12
|
+
}
|
|
13
|
+
declare const UnauthorizedApiError_base: Schema.Class<UnauthorizedApiError, Schema.TaggedStruct<"UnauthorizedApiError", {
|
|
14
|
+
readonly message: Schema.String;
|
|
15
|
+
}>, import("effect/Cause").YieldableError>;
|
|
16
|
+
export declare class UnauthorizedApiError extends UnauthorizedApiError_base {
|
|
17
|
+
}
|
|
18
|
+
declare const ForbiddenApiError_base: Schema.Class<ForbiddenApiError, Schema.TaggedStruct<"ForbiddenApiError", {
|
|
19
|
+
readonly message: Schema.String;
|
|
20
|
+
}>, import("effect/Cause").YieldableError>;
|
|
21
|
+
export declare class ForbiddenApiError extends ForbiddenApiError_base {
|
|
22
|
+
}
|
|
23
|
+
export declare const Bucket: Schema.Literals<readonly ["hour", "day", "week"]>;
|
|
24
|
+
export type Bucket = typeof Bucket.Type;
|
|
25
|
+
export declare const AgentFilter: Schema.Literals<readonly ["all", "claude", "codex"]>;
|
|
26
|
+
export type AgentFilter = typeof AgentFilter.Type;
|
|
27
|
+
export declare const RangeQuery: Schema.Struct<{
|
|
28
|
+
readonly from: Schema.compose<Schema.Int, Schema.NumberFromString>;
|
|
29
|
+
readonly to: Schema.compose<Schema.Int, Schema.NumberFromString>;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const UsageQuery: Schema.Struct<{
|
|
32
|
+
readonly from: Schema.compose<Schema.Int, Schema.NumberFromString>;
|
|
33
|
+
readonly to: Schema.compose<Schema.Int, Schema.NumberFromString>;
|
|
34
|
+
readonly timeZone: Schema.String;
|
|
35
|
+
readonly bucket: Schema.Literals<readonly ["hour", "day", "week"]>;
|
|
36
|
+
readonly agent: Schema.Literals<readonly ["all", "claude", "codex"]>;
|
|
37
|
+
}>;
|
|
38
|
+
export type UsageQuery = typeof UsageQuery.Type;
|
|
39
|
+
export declare const Booking: Schema.Union<readonly [Schema.TaggedStruct<"Ticket", {
|
|
40
|
+
readonly key: Schema.String;
|
|
41
|
+
}>, Schema.TaggedStruct<"Repo", {
|
|
42
|
+
readonly name: Schema.String;
|
|
43
|
+
}>]>;
|
|
44
|
+
/** One local hour, day or week: its key (`2026-09-01`, `2026-09-01T10`) and first instant. */
|
|
45
|
+
export declare const Period: Schema.Struct<{
|
|
46
|
+
readonly key: Schema.String;
|
|
47
|
+
readonly start: Schema.Int;
|
|
48
|
+
}>;
|
|
49
|
+
export type Period = typeof Period.Type;
|
|
50
|
+
export declare const BookingSummary: Schema.Struct<{
|
|
51
|
+
readonly id: Schema.String;
|
|
52
|
+
readonly booking: Schema.Union<readonly [Schema.TaggedStruct<"Ticket", {
|
|
53
|
+
readonly key: Schema.String;
|
|
54
|
+
}>, Schema.TaggedStruct<"Repo", {
|
|
55
|
+
readonly name: Schema.String;
|
|
56
|
+
}>]>;
|
|
57
|
+
/** Null for a repo; a ticket's title is Known or Unknown with a reason. */
|
|
58
|
+
readonly title: Schema.NullOr<Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
59
|
+
readonly summary: Schema.String;
|
|
60
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
61
|
+
readonly reason: Schema.Literals<readonly ["NotFound", "NotLookedUp"]>;
|
|
62
|
+
}>]>>;
|
|
63
|
+
readonly agents: Schema.$Array<Schema.Literals<readonly ["claude", "codex"]>>;
|
|
64
|
+
readonly requests: Schema.Int;
|
|
65
|
+
readonly tokens: Schema.Struct<{
|
|
66
|
+
readonly input: Schema.Int;
|
|
67
|
+
readonly output: Schema.Int;
|
|
68
|
+
readonly reasoning: Schema.Int;
|
|
69
|
+
readonly cacheRead: Schema.Int;
|
|
70
|
+
readonly cacheWrite5m: Schema.Int;
|
|
71
|
+
readonly cacheWrite1h: Schema.Int;
|
|
72
|
+
}>;
|
|
73
|
+
/** API-Equivalent Cost of the priced tokens only. */
|
|
74
|
+
readonly costUsd: Schema.Finite;
|
|
75
|
+
/** Tokens of models with no price; their cost is unknown, not zero. */
|
|
76
|
+
readonly unpricedTokens: Schema.Int;
|
|
77
|
+
readonly unpricedModels: Schema.$Array<Schema.String>;
|
|
78
|
+
}>;
|
|
79
|
+
export type BookingSummary = typeof BookingSummary.Type;
|
|
80
|
+
export declare const UsageCell: Schema.Struct<{
|
|
81
|
+
/** Index into `periods`. */
|
|
82
|
+
readonly period: Schema.Int;
|
|
83
|
+
readonly booking: Schema.String;
|
|
84
|
+
readonly tokens: Schema.Int;
|
|
85
|
+
readonly costUsd: Schema.Finite;
|
|
86
|
+
readonly unpricedTokens: Schema.Int;
|
|
87
|
+
}>;
|
|
88
|
+
export type UsageCell = typeof UsageCell.Type;
|
|
89
|
+
export declare const UsageReport: Schema.Struct<{
|
|
90
|
+
readonly periods: Schema.$Array<Schema.Struct<{
|
|
91
|
+
readonly key: Schema.String;
|
|
92
|
+
readonly start: Schema.Int;
|
|
93
|
+
}>>;
|
|
94
|
+
/** Most API-Equivalent Cost first, then most tokens. */
|
|
95
|
+
readonly bookings: Schema.$Array<Schema.Struct<{
|
|
96
|
+
readonly id: Schema.String;
|
|
97
|
+
readonly booking: Schema.Union<readonly [Schema.TaggedStruct<"Ticket", {
|
|
98
|
+
readonly key: Schema.String;
|
|
99
|
+
}>, Schema.TaggedStruct<"Repo", {
|
|
100
|
+
readonly name: Schema.String;
|
|
101
|
+
}>]>;
|
|
102
|
+
/** Null for a repo; a ticket's title is Known or Unknown with a reason. */
|
|
103
|
+
readonly title: Schema.NullOr<Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
104
|
+
readonly summary: Schema.String;
|
|
105
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
106
|
+
readonly reason: Schema.Literals<readonly ["NotFound", "NotLookedUp"]>;
|
|
107
|
+
}>]>>;
|
|
108
|
+
readonly agents: Schema.$Array<Schema.Literals<readonly ["claude", "codex"]>>;
|
|
109
|
+
readonly requests: Schema.Int;
|
|
110
|
+
readonly tokens: Schema.Struct<{
|
|
111
|
+
readonly input: Schema.Int;
|
|
112
|
+
readonly output: Schema.Int;
|
|
113
|
+
readonly reasoning: Schema.Int;
|
|
114
|
+
readonly cacheRead: Schema.Int;
|
|
115
|
+
readonly cacheWrite5m: Schema.Int;
|
|
116
|
+
readonly cacheWrite1h: Schema.Int;
|
|
117
|
+
}>;
|
|
118
|
+
/** API-Equivalent Cost of the priced tokens only. */
|
|
119
|
+
readonly costUsd: Schema.Finite;
|
|
120
|
+
/** Tokens of models with no price; their cost is unknown, not zero. */
|
|
121
|
+
readonly unpricedTokens: Schema.Int;
|
|
122
|
+
readonly unpricedModels: Schema.$Array<Schema.String>;
|
|
123
|
+
}>>;
|
|
124
|
+
readonly cells: Schema.$Array<Schema.Struct<{
|
|
125
|
+
/** Index into `periods`. */
|
|
126
|
+
readonly period: Schema.Int;
|
|
127
|
+
readonly booking: Schema.String;
|
|
128
|
+
readonly tokens: Schema.Int;
|
|
129
|
+
readonly costUsd: Schema.Finite;
|
|
130
|
+
readonly unpricedTokens: Schema.Int;
|
|
131
|
+
}>>;
|
|
132
|
+
readonly unpriced: Schema.Struct<{
|
|
133
|
+
readonly tokens: Schema.Int;
|
|
134
|
+
readonly models: Schema.$Array<Schema.String>;
|
|
135
|
+
}>;
|
|
136
|
+
/** Typed keys whose project is not a Known Project, by prefix, with the requests they did not book. */
|
|
137
|
+
readonly ignoredKeys: Schema.$Array<Schema.Struct<{
|
|
138
|
+
readonly prefix: Schema.String;
|
|
139
|
+
readonly requests: Schema.Int;
|
|
140
|
+
}>>;
|
|
141
|
+
}>;
|
|
142
|
+
export type UsageReport = typeof UsageReport.Type;
|
|
143
|
+
export declare const LimitPoint: Schema.Struct<{
|
|
144
|
+
readonly at: Schema.Int;
|
|
145
|
+
readonly reading: Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
146
|
+
readonly usedPercent: Schema.Finite;
|
|
147
|
+
readonly resetsAt: Schema.NullOr<Schema.Int>;
|
|
148
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
149
|
+
readonly reason: Schema.Literals<readonly ["NoAuth", "AuthExpired", "NotSupported", "Fetch", "Parse", "NoData"]>;
|
|
150
|
+
}>]>;
|
|
151
|
+
}>;
|
|
152
|
+
export declare const LimitSeries: Schema.Struct<{
|
|
153
|
+
readonly agent: Schema.Literals<readonly ["claude", "codex"]>;
|
|
154
|
+
readonly label: Schema.String;
|
|
155
|
+
readonly windowMinutes: Schema.NullOr<Schema.Int>;
|
|
156
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
157
|
+
readonly at: Schema.Int;
|
|
158
|
+
readonly reading: Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
159
|
+
readonly usedPercent: Schema.Finite;
|
|
160
|
+
readonly resetsAt: Schema.NullOr<Schema.Int>;
|
|
161
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
162
|
+
readonly reason: Schema.Literals<readonly ["NoAuth", "AuthExpired", "NotSupported", "Fetch", "Parse", "NoData"]>;
|
|
163
|
+
}>]>;
|
|
164
|
+
}>>;
|
|
165
|
+
}>;
|
|
166
|
+
export type LimitSeries = typeof LimitSeries.Type;
|
|
167
|
+
export declare const LimitsReport: Schema.Struct<{
|
|
168
|
+
readonly series: Schema.$Array<Schema.Struct<{
|
|
169
|
+
readonly agent: Schema.Literals<readonly ["claude", "codex"]>;
|
|
170
|
+
readonly label: Schema.String;
|
|
171
|
+
readonly windowMinutes: Schema.NullOr<Schema.Int>;
|
|
172
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
173
|
+
readonly at: Schema.Int;
|
|
174
|
+
readonly reading: Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
175
|
+
readonly usedPercent: Schema.Finite;
|
|
176
|
+
readonly resetsAt: Schema.NullOr<Schema.Int>;
|
|
177
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
178
|
+
readonly reason: Schema.Literals<readonly ["NoAuth", "AuthExpired", "NotSupported", "Fetch", "Parse", "NoData"]>;
|
|
179
|
+
}>]>;
|
|
180
|
+
}>>;
|
|
181
|
+
}>>;
|
|
182
|
+
/** The newest snapshot of every series up to the range's end: what the tiles show. */
|
|
183
|
+
readonly latest: Schema.$Array<Schema.Struct<{
|
|
184
|
+
readonly agent: Schema.Literals<readonly ["claude", "codex"]>;
|
|
185
|
+
readonly machine: Schema.NonEmptyString;
|
|
186
|
+
readonly source: Schema.Literals<readonly ["claude-oauth-usage", "codex-rollout"]>;
|
|
187
|
+
readonly label: Schema.NonEmptyString;
|
|
188
|
+
readonly windowMinutes: Schema.NullOr<Schema.Int>;
|
|
189
|
+
readonly observedAt: Schema.Int;
|
|
190
|
+
readonly reading: Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
191
|
+
readonly usedPercent: Schema.Finite;
|
|
192
|
+
readonly resetsAt: Schema.NullOr<Schema.Int>;
|
|
193
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
194
|
+
readonly reason: Schema.Literals<readonly ["NoAuth", "AuthExpired", "NotSupported", "Fetch", "Parse", "NoData"]>;
|
|
195
|
+
}>]>;
|
|
196
|
+
}>>;
|
|
197
|
+
readonly balances: Schema.$Array<Schema.Struct<{
|
|
198
|
+
readonly kind: Schema.Literals<readonly ["claude-extra-usage", "codex-credits"]>;
|
|
199
|
+
readonly machine: Schema.NonEmptyString;
|
|
200
|
+
readonly observedAt: Schema.Int;
|
|
201
|
+
readonly value: Schema.Union<readonly [Schema.TaggedStruct<"Known", {
|
|
202
|
+
readonly balance: Schema.Union<readonly [Schema.TaggedStruct<"Amount", {
|
|
203
|
+
readonly leftMinor: Schema.Finite;
|
|
204
|
+
readonly limitMinor: Schema.Finite;
|
|
205
|
+
readonly decimals: Schema.Int;
|
|
206
|
+
readonly currency: Schema.String;
|
|
207
|
+
}>, Schema.TaggedStruct<"Credits", {
|
|
208
|
+
readonly credits: Schema.Finite;
|
|
209
|
+
}>, Schema.TaggedStruct<"Unlimited", {}>, Schema.TaggedStruct<"Exhausted", {}>, Schema.TaggedStruct<"Disabled", {}>]>;
|
|
210
|
+
}>, Schema.TaggedStruct<"Unknown", {
|
|
211
|
+
readonly reason: Schema.Literals<readonly ["NoAuth", "AuthExpired", "NotSupported", "Fetch", "Parse", "NoData"]>;
|
|
212
|
+
}>]>;
|
|
213
|
+
}>>;
|
|
214
|
+
}>;
|
|
215
|
+
export type LimitsReport = typeof LimitsReport.Type;
|
|
216
|
+
export declare const SourceStatus: Schema.Struct<{
|
|
217
|
+
readonly rootMissing: Schema.Boolean;
|
|
218
|
+
readonly filesScanned: Schema.Int;
|
|
219
|
+
readonly filesRead: Schema.Int;
|
|
220
|
+
readonly eventsAdded: Schema.Int;
|
|
221
|
+
readonly skipped: Schema.Struct<{
|
|
222
|
+
readonly unparseableLine: Schema.Int;
|
|
223
|
+
readonly missingTimestamp: Schema.Int;
|
|
224
|
+
readonly oversizedLine: Schema.Int;
|
|
225
|
+
}>;
|
|
226
|
+
readonly unreadable: Schema.$Array<Schema.Struct<{
|
|
227
|
+
readonly fileKey: Schema.String;
|
|
228
|
+
readonly reason: Schema.String;
|
|
229
|
+
}>>;
|
|
230
|
+
}>;
|
|
231
|
+
export declare const IngestStatus: Schema.Struct<{
|
|
232
|
+
readonly startedAt: Schema.Int;
|
|
233
|
+
readonly finishedAt: Schema.Int;
|
|
234
|
+
readonly claude: Schema.Struct<{
|
|
235
|
+
readonly rootMissing: Schema.Boolean;
|
|
236
|
+
readonly filesScanned: Schema.Int;
|
|
237
|
+
readonly filesRead: Schema.Int;
|
|
238
|
+
readonly eventsAdded: Schema.Int;
|
|
239
|
+
readonly skipped: Schema.Struct<{
|
|
240
|
+
readonly unparseableLine: Schema.Int;
|
|
241
|
+
readonly missingTimestamp: Schema.Int;
|
|
242
|
+
readonly oversizedLine: Schema.Int;
|
|
243
|
+
}>;
|
|
244
|
+
readonly unreadable: Schema.$Array<Schema.Struct<{
|
|
245
|
+
readonly fileKey: Schema.String;
|
|
246
|
+
readonly reason: Schema.String;
|
|
247
|
+
}>>;
|
|
248
|
+
}>;
|
|
249
|
+
readonly codex: Schema.Struct<{
|
|
250
|
+
readonly rootMissing: Schema.Boolean;
|
|
251
|
+
readonly filesScanned: Schema.Int;
|
|
252
|
+
readonly filesRead: Schema.Int;
|
|
253
|
+
readonly eventsAdded: Schema.Int;
|
|
254
|
+
readonly skipped: Schema.Struct<{
|
|
255
|
+
readonly unparseableLine: Schema.Int;
|
|
256
|
+
readonly missingTimestamp: Schema.Int;
|
|
257
|
+
readonly oversizedLine: Schema.Int;
|
|
258
|
+
}>;
|
|
259
|
+
readonly unreadable: Schema.$Array<Schema.Struct<{
|
|
260
|
+
readonly fileKey: Schema.String;
|
|
261
|
+
readonly reason: Schema.String;
|
|
262
|
+
}>>;
|
|
263
|
+
}>;
|
|
264
|
+
}>;
|
|
265
|
+
export declare const ServerStatus: Schema.Struct<{
|
|
266
|
+
readonly machine: Schema.String;
|
|
267
|
+
/** The latest finished pass; null until the first one ends. */
|
|
268
|
+
readonly ingest: Schema.NullOr<Schema.Struct<{
|
|
269
|
+
readonly startedAt: Schema.Int;
|
|
270
|
+
readonly finishedAt: Schema.Int;
|
|
271
|
+
readonly claude: Schema.Struct<{
|
|
272
|
+
readonly rootMissing: Schema.Boolean;
|
|
273
|
+
readonly filesScanned: Schema.Int;
|
|
274
|
+
readonly filesRead: Schema.Int;
|
|
275
|
+
readonly eventsAdded: Schema.Int;
|
|
276
|
+
readonly skipped: Schema.Struct<{
|
|
277
|
+
readonly unparseableLine: Schema.Int;
|
|
278
|
+
readonly missingTimestamp: Schema.Int;
|
|
279
|
+
readonly oversizedLine: Schema.Int;
|
|
280
|
+
}>;
|
|
281
|
+
readonly unreadable: Schema.$Array<Schema.Struct<{
|
|
282
|
+
readonly fileKey: Schema.String;
|
|
283
|
+
readonly reason: Schema.String;
|
|
284
|
+
}>>;
|
|
285
|
+
}>;
|
|
286
|
+
readonly codex: Schema.Struct<{
|
|
287
|
+
readonly rootMissing: Schema.Boolean;
|
|
288
|
+
readonly filesScanned: Schema.Int;
|
|
289
|
+
readonly filesRead: Schema.Int;
|
|
290
|
+
readonly eventsAdded: Schema.Int;
|
|
291
|
+
readonly skipped: Schema.Struct<{
|
|
292
|
+
readonly unparseableLine: Schema.Int;
|
|
293
|
+
readonly missingTimestamp: Schema.Int;
|
|
294
|
+
readonly oversizedLine: Schema.Int;
|
|
295
|
+
}>;
|
|
296
|
+
readonly unreadable: Schema.$Array<Schema.Struct<{
|
|
297
|
+
readonly fileKey: Schema.String;
|
|
298
|
+
readonly reason: Schema.String;
|
|
299
|
+
}>>;
|
|
300
|
+
}>;
|
|
301
|
+
}>>;
|
|
302
|
+
/** Why the latest pass failed outright, if it did. */
|
|
303
|
+
readonly ingestFailure: Schema.NullOr<Schema.String>;
|
|
304
|
+
/** Why the latest Claude limit poll could not be stored, if it could not. */
|
|
305
|
+
readonly limitsFailure: Schema.NullOr<Schema.String>;
|
|
306
|
+
readonly ticketLookupFailures: Schema.$Array<Schema.String>;
|
|
307
|
+
}>;
|
|
308
|
+
export type ServerStatus = typeof ServerStatus.Type;
|
|
309
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What crosses the HTTP boundary, shared by the server and the browser so both decode with the same
|
|
3
|
+
* schemas. Browser-safe: no Node imports.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { Schema } from "effect";
|
|
8
|
+
import { Agent, BalanceReading, Count, LimitReading, LimitSnapshot, TicketTitleValue, Tokens, WindowMinutes } from "../core/Model.js";
|
|
9
|
+
export class ApiError extends Schema.TaggedError()("ApiError", {
|
|
10
|
+
message: Schema.String
|
|
11
|
+
}, { httpApiStatus: 400 }) {
|
|
12
|
+
}
|
|
13
|
+
export class UnauthorizedApiError extends Schema.TaggedError()("UnauthorizedApiError", { message: Schema.String }, { httpApiStatus: 401 }) {
|
|
14
|
+
}
|
|
15
|
+
export class ForbiddenApiError extends Schema.TaggedError()("ForbiddenApiError", { message: Schema.String }, { httpApiStatus: 403 }) {
|
|
16
|
+
}
|
|
17
|
+
export const Bucket = Schema.Literals(["hour", "day", "week"]);
|
|
18
|
+
export const AgentFilter = Schema.Literals(["all", "claude", "codex"]);
|
|
19
|
+
const Millis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
20
|
+
export const RangeQuery = Schema.Struct({
|
|
21
|
+
from: Schema.NumberFromString.pipe(Schema.decodeTo(Millis)),
|
|
22
|
+
to: Schema.NumberFromString.pipe(Schema.decodeTo(Millis))
|
|
23
|
+
});
|
|
24
|
+
export const UsageQuery = Schema.Struct({
|
|
25
|
+
...RangeQuery.fields,
|
|
26
|
+
timeZone: Schema.String,
|
|
27
|
+
bucket: Bucket,
|
|
28
|
+
agent: AgentFilter
|
|
29
|
+
});
|
|
30
|
+
export const Booking = Schema.Union([
|
|
31
|
+
Schema.TaggedStruct("Ticket", { key: Schema.String }),
|
|
32
|
+
Schema.TaggedStruct("Repo", { name: Schema.String })
|
|
33
|
+
]);
|
|
34
|
+
/** One local hour, day or week: its key (`2026-09-01`, `2026-09-01T10`) and first instant. */
|
|
35
|
+
export const Period = Schema.Struct({ key: Schema.String, start: Millis });
|
|
36
|
+
export const BookingSummary = Schema.Struct({
|
|
37
|
+
id: Schema.String,
|
|
38
|
+
booking: Booking,
|
|
39
|
+
/** Null for a repo; a ticket's title is Known or Unknown with a reason. */
|
|
40
|
+
title: Schema.NullOr(TicketTitleValue),
|
|
41
|
+
agents: Schema.Array(Agent),
|
|
42
|
+
requests: Count,
|
|
43
|
+
tokens: Tokens,
|
|
44
|
+
/** API-Equivalent Cost of the priced tokens only. */
|
|
45
|
+
costUsd: Schema.Finite,
|
|
46
|
+
/** Tokens of models with no price; their cost is unknown, not zero. */
|
|
47
|
+
unpricedTokens: Count,
|
|
48
|
+
unpricedModels: Schema.Array(Schema.String)
|
|
49
|
+
});
|
|
50
|
+
export const UsageCell = Schema.Struct({
|
|
51
|
+
/** Index into `periods`. */
|
|
52
|
+
period: Count,
|
|
53
|
+
booking: Schema.String,
|
|
54
|
+
tokens: Count,
|
|
55
|
+
costUsd: Schema.Finite,
|
|
56
|
+
unpricedTokens: Count
|
|
57
|
+
});
|
|
58
|
+
export const UsageReport = Schema.Struct({
|
|
59
|
+
periods: Schema.Array(Period),
|
|
60
|
+
/** Most API-Equivalent Cost first, then most tokens. */
|
|
61
|
+
bookings: Schema.Array(BookingSummary),
|
|
62
|
+
cells: Schema.Array(UsageCell),
|
|
63
|
+
unpriced: Schema.Struct({ tokens: Count, models: Schema.Array(Schema.String) }),
|
|
64
|
+
/** Typed keys whose project is not a Known Project, by prefix, with the requests they did not book. */
|
|
65
|
+
ignoredKeys: Schema.Array(Schema.Struct({ prefix: Schema.String, requests: Count }))
|
|
66
|
+
});
|
|
67
|
+
export const LimitPoint = Schema.Struct({ at: Millis, reading: LimitReading });
|
|
68
|
+
export const LimitSeries = Schema.Struct({
|
|
69
|
+
agent: Agent,
|
|
70
|
+
label: Schema.String,
|
|
71
|
+
windowMinutes: WindowMinutes,
|
|
72
|
+
points: Schema.Array(LimitPoint)
|
|
73
|
+
});
|
|
74
|
+
export const LimitsReport = Schema.Struct({
|
|
75
|
+
series: Schema.Array(LimitSeries),
|
|
76
|
+
/** The newest snapshot of every series up to the range's end: what the tiles show. */
|
|
77
|
+
latest: Schema.Array(LimitSnapshot),
|
|
78
|
+
balances: Schema.Array(BalanceReading)
|
|
79
|
+
});
|
|
80
|
+
const SkipCounts = Schema.Struct({ unparseableLine: Count, missingTimestamp: Count, oversizedLine: Count });
|
|
81
|
+
export const SourceStatus = Schema.Struct({
|
|
82
|
+
rootMissing: Schema.Boolean,
|
|
83
|
+
filesScanned: Count,
|
|
84
|
+
filesRead: Count,
|
|
85
|
+
eventsAdded: Count,
|
|
86
|
+
skipped: SkipCounts,
|
|
87
|
+
unreadable: Schema.Array(Schema.Struct({ fileKey: Schema.String, reason: Schema.String }))
|
|
88
|
+
});
|
|
89
|
+
export const IngestStatus = Schema.Struct({
|
|
90
|
+
startedAt: Millis,
|
|
91
|
+
finishedAt: Millis,
|
|
92
|
+
claude: SourceStatus,
|
|
93
|
+
codex: SourceStatus
|
|
94
|
+
});
|
|
95
|
+
export const ServerStatus = Schema.Struct({
|
|
96
|
+
machine: Schema.String,
|
|
97
|
+
/** The latest finished pass; null until the first one ends. */
|
|
98
|
+
ingest: Schema.NullOr(IngestStatus),
|
|
99
|
+
/** Why the latest pass failed outright, if it did. */
|
|
100
|
+
ingestFailure: Schema.NullOr(Schema.String),
|
|
101
|
+
/** Why the latest Claude limit poll could not be stored, if it could not. */
|
|
102
|
+
limitsFailure: Schema.NullOr(Schema.String),
|
|
103
|
+
ticketLookupFailures: Schema.Array(Schema.String)
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/shared/contracts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EACL,KAAK,EACL,cAAc,EACd,KAAK,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,MAAM,EACN,aAAa,EACd,MAAM,kBAAkB,CAAA;AAEzB,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,WAAW,EAAY,CAAC,UAAU,EAAE;IACvE,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;CAAG;AAE7B,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAClF,sBAAsB,EACtB,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,EAC1B,EAAE,aAAa,EAAE,GAAG,EAAE,CACvB;CAAG;AAEJ,MAAM,OAAO,iBAAkB,SAAQ,MAAM,CAAC,WAAW,EAAqB,CAC5E,mBAAmB,EACnB,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