@adecore/agent-contracts 0.0.1 → 0.17.0-beta.2

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.
@@ -0,0 +1,392 @@
1
+ import { z } from 'zod';
2
+ export declare const UsageProviderSchema: z.ZodEnum<{
3
+ claude: "claude";
4
+ codex: "codex";
5
+ }>;
6
+ export type UsageProvider = z.infer<typeof UsageProviderSchema>;
7
+ export declare const USAGE_PROVIDERS: ("claude" | "codex")[];
8
+ export declare const UsageResolutionSchema: z.ZodEnum<{
9
+ day: "day";
10
+ hour: "hour";
11
+ }>;
12
+ export type UsageResolution = z.infer<typeof UsageResolutionSchema>;
13
+ export declare const UsageTotalsSchema: z.ZodObject<{
14
+ calls: z.ZodNumber;
15
+ input: z.ZodNumber;
16
+ cacheRead: z.ZodNumber;
17
+ cacheWrite: z.ZodNumber;
18
+ cacheWrite1h: z.ZodNumber;
19
+ output: z.ZodNumber;
20
+ reasoning: z.ZodNumber;
21
+ }, z.core.$strip>;
22
+ export type UsageTotals = z.infer<typeof UsageTotalsSchema>;
23
+ export declare const EMPTY_TOTALS: UsageTotals;
24
+ export declare function totalTokensOf(totals: UsageTotals): number;
25
+ export declare function addTotals(first: UsageTotals, second: UsageTotals): UsageTotals;
26
+ export declare const UsageAccountSchema: z.ZodObject<{
27
+ id: z.ZodString;
28
+ kind: z.ZodEnum<{
29
+ claude: "claude";
30
+ codex: "codex";
31
+ }>;
32
+ label: z.ZodString;
33
+ color: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strip>;
35
+ export type UsageAccount = z.infer<typeof UsageAccountSchema>;
36
+ export declare const UsageBucketSchema: z.ZodObject<{
37
+ slot: z.ZodString;
38
+ provider: z.ZodEnum<{
39
+ claude: "claude";
40
+ codex: "codex";
41
+ }>;
42
+ model: z.ZodString;
43
+ account: z.ZodOptional<z.ZodString>;
44
+ totals: z.ZodObject<{
45
+ calls: z.ZodNumber;
46
+ input: z.ZodNumber;
47
+ cacheRead: z.ZodNumber;
48
+ cacheWrite: z.ZodNumber;
49
+ cacheWrite1h: z.ZodNumber;
50
+ output: z.ZodNumber;
51
+ reasoning: z.ZodNumber;
52
+ }, z.core.$strip>;
53
+ costUsd: z.ZodNullable<z.ZodNumber>;
54
+ cacheSavingsUsd: z.ZodNumber;
55
+ sessions: z.ZodNumber;
56
+ }, z.core.$strip>;
57
+ export type UsageBucket = z.infer<typeof UsageBucketSchema>;
58
+ export declare const UsagePriceBasisSchema: z.ZodEnum<{
59
+ exact: "exact";
60
+ family: "family";
61
+ override: "override";
62
+ unknown: "unknown";
63
+ }>;
64
+ export type UsagePriceBasis = z.infer<typeof UsagePriceBasisSchema>;
65
+ export declare const UsageModelSchema: z.ZodObject<{
66
+ provider: z.ZodEnum<{
67
+ claude: "claude";
68
+ codex: "codex";
69
+ }>;
70
+ model: z.ZodString;
71
+ account: z.ZodOptional<z.ZodString>;
72
+ totals: z.ZodObject<{
73
+ calls: z.ZodNumber;
74
+ input: z.ZodNumber;
75
+ cacheRead: z.ZodNumber;
76
+ cacheWrite: z.ZodNumber;
77
+ cacheWrite1h: z.ZodNumber;
78
+ output: z.ZodNumber;
79
+ reasoning: z.ZodNumber;
80
+ }, z.core.$strip>;
81
+ costUsd: z.ZodNullable<z.ZodNumber>;
82
+ priceBasis: z.ZodEnum<{
83
+ exact: "exact";
84
+ family: "family";
85
+ override: "override";
86
+ unknown: "unknown";
87
+ }>;
88
+ pricedAs: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ export type UsageModel = z.infer<typeof UsageModelSchema>;
91
+ export declare const UsageProjectSchema: z.ZodObject<{
92
+ folder: z.ZodString;
93
+ name: z.ZodString;
94
+ projectId: z.ZodNullable<z.ZodString>;
95
+ byProvider: z.ZodRecord<z.ZodEnum<{
96
+ claude: "claude";
97
+ codex: "codex";
98
+ }> & z.core.$partial, z.ZodObject<{
99
+ costUsd: z.ZodNumber;
100
+ tokens: z.ZodNumber;
101
+ }, z.core.$strip>>;
102
+ totals: z.ZodObject<{
103
+ calls: z.ZodNumber;
104
+ input: z.ZodNumber;
105
+ cacheRead: z.ZodNumber;
106
+ cacheWrite: z.ZodNumber;
107
+ cacheWrite1h: z.ZodNumber;
108
+ output: z.ZodNumber;
109
+ reasoning: z.ZodNumber;
110
+ }, z.core.$strip>;
111
+ costUsd: z.ZodNumber;
112
+ }, z.core.$strip>;
113
+ export type UsageProject = z.infer<typeof UsageProjectSchema>;
114
+ export declare const UsageSummaryPayloadSchema: z.ZodObject<{
115
+ from: z.ZodString;
116
+ to: z.ZodString;
117
+ resolution: z.ZodEnum<{
118
+ day: "day";
119
+ hour: "hour";
120
+ }>;
121
+ timeZone: z.ZodString;
122
+ accounts: z.ZodOptional<z.ZodArray<z.ZodString>>;
123
+ }, z.core.$strip>;
124
+ export type UsageSummaryPayload = z.infer<typeof UsageSummaryPayloadSchema>;
125
+ export declare const UsageScanSchema: z.ZodObject<{
126
+ at: z.ZodNumber;
127
+ files: z.ZodNumber;
128
+ changedFiles: z.ZodNumber;
129
+ durationMs: z.ZodNumber;
130
+ running: z.ZodBoolean;
131
+ failed: z.ZodBoolean;
132
+ }, z.core.$strip>;
133
+ export type UsageScan = z.infer<typeof UsageScanSchema>;
134
+ export declare const UsagePricingSchema: z.ZodObject<{
135
+ source: z.ZodEnum<{
136
+ litellm: "litellm";
137
+ none: "none";
138
+ snapshot: "snapshot";
139
+ }>;
140
+ fetchedAt: z.ZodNullable<z.ZodNumber>;
141
+ models: z.ZodNumber;
142
+ }, z.core.$strip>;
143
+ export type UsagePricing = z.infer<typeof UsagePricingSchema>;
144
+ export declare const UsageRootSchema: z.ZodObject<{
145
+ provider: z.ZodEnum<{
146
+ claude: "claude";
147
+ codex: "codex";
148
+ }>;
149
+ path: z.ZodString;
150
+ status: z.ZodEnum<{
151
+ failed: "failed";
152
+ missing: "missing";
153
+ ok: "ok";
154
+ }>;
155
+ message: z.ZodNullable<z.ZodString>;
156
+ }, z.core.$strip>;
157
+ export type UsageRoot = z.infer<typeof UsageRootSchema>;
158
+ export declare const UsageRateSchema: z.ZodObject<{
159
+ currency: z.ZodString;
160
+ rate: z.ZodNumber;
161
+ date: z.ZodString;
162
+ fetchedAt: z.ZodNumber;
163
+ }, z.core.$strip>;
164
+ export type UsageRate = z.infer<typeof UsageRateSchema>;
165
+ export declare const UsageSummaryResultSchema: z.ZodObject<{
166
+ from: z.ZodString;
167
+ to: z.ZodString;
168
+ resolution: z.ZodEnum<{
169
+ day: "day";
170
+ hour: "hour";
171
+ }>;
172
+ timeZone: z.ZodString;
173
+ buckets: z.ZodArray<z.ZodObject<{
174
+ slot: z.ZodString;
175
+ provider: z.ZodEnum<{
176
+ claude: "claude";
177
+ codex: "codex";
178
+ }>;
179
+ model: z.ZodString;
180
+ account: z.ZodOptional<z.ZodString>;
181
+ totals: z.ZodObject<{
182
+ calls: z.ZodNumber;
183
+ input: z.ZodNumber;
184
+ cacheRead: z.ZodNumber;
185
+ cacheWrite: z.ZodNumber;
186
+ cacheWrite1h: z.ZodNumber;
187
+ output: z.ZodNumber;
188
+ reasoning: z.ZodNumber;
189
+ }, z.core.$strip>;
190
+ costUsd: z.ZodNullable<z.ZodNumber>;
191
+ cacheSavingsUsd: z.ZodNumber;
192
+ sessions: z.ZodNumber;
193
+ }, z.core.$strip>>;
194
+ models: z.ZodArray<z.ZodObject<{
195
+ provider: z.ZodEnum<{
196
+ claude: "claude";
197
+ codex: "codex";
198
+ }>;
199
+ model: z.ZodString;
200
+ account: z.ZodOptional<z.ZodString>;
201
+ totals: z.ZodObject<{
202
+ calls: z.ZodNumber;
203
+ input: z.ZodNumber;
204
+ cacheRead: z.ZodNumber;
205
+ cacheWrite: z.ZodNumber;
206
+ cacheWrite1h: z.ZodNumber;
207
+ output: z.ZodNumber;
208
+ reasoning: z.ZodNumber;
209
+ }, z.core.$strip>;
210
+ costUsd: z.ZodNullable<z.ZodNumber>;
211
+ priceBasis: z.ZodEnum<{
212
+ exact: "exact";
213
+ family: "family";
214
+ override: "override";
215
+ unknown: "unknown";
216
+ }>;
217
+ pricedAs: z.ZodNullable<z.ZodString>;
218
+ }, z.core.$strip>>;
219
+ projects: z.ZodArray<z.ZodObject<{
220
+ folder: z.ZodString;
221
+ name: z.ZodString;
222
+ projectId: z.ZodNullable<z.ZodString>;
223
+ byProvider: z.ZodRecord<z.ZodEnum<{
224
+ claude: "claude";
225
+ codex: "codex";
226
+ }> & z.core.$partial, z.ZodObject<{
227
+ costUsd: z.ZodNumber;
228
+ tokens: z.ZodNumber;
229
+ }, z.core.$strip>>;
230
+ totals: z.ZodObject<{
231
+ calls: z.ZodNumber;
232
+ input: z.ZodNumber;
233
+ cacheRead: z.ZodNumber;
234
+ cacheWrite: z.ZodNumber;
235
+ cacheWrite1h: z.ZodNumber;
236
+ output: z.ZodNumber;
237
+ reasoning: z.ZodNumber;
238
+ }, z.core.$strip>;
239
+ costUsd: z.ZodNumber;
240
+ }, z.core.$strip>>;
241
+ sessions: z.ZodNumber;
242
+ scan: z.ZodObject<{
243
+ at: z.ZodNumber;
244
+ files: z.ZodNumber;
245
+ changedFiles: z.ZodNumber;
246
+ durationMs: z.ZodNumber;
247
+ running: z.ZodBoolean;
248
+ failed: z.ZodBoolean;
249
+ }, z.core.$strip>;
250
+ pricing: z.ZodObject<{
251
+ source: z.ZodEnum<{
252
+ litellm: "litellm";
253
+ none: "none";
254
+ snapshot: "snapshot";
255
+ }>;
256
+ fetchedAt: z.ZodNullable<z.ZodNumber>;
257
+ models: z.ZodNumber;
258
+ }, z.core.$strip>;
259
+ rate: z.ZodNullable<z.ZodObject<{
260
+ currency: z.ZodString;
261
+ rate: z.ZodNumber;
262
+ date: z.ZodString;
263
+ fetchedAt: z.ZodNumber;
264
+ }, z.core.$strip>>;
265
+ roots: z.ZodArray<z.ZodObject<{
266
+ provider: z.ZodEnum<{
267
+ claude: "claude";
268
+ codex: "codex";
269
+ }>;
270
+ path: z.ZodString;
271
+ status: z.ZodEnum<{
272
+ failed: "failed";
273
+ missing: "missing";
274
+ ok: "ok";
275
+ }>;
276
+ message: z.ZodNullable<z.ZodString>;
277
+ }, z.core.$strip>>;
278
+ accounts: z.ZodOptional<z.ZodArray<z.ZodObject<{
279
+ id: z.ZodString;
280
+ kind: z.ZodEnum<{
281
+ claude: "claude";
282
+ codex: "codex";
283
+ }>;
284
+ label: z.ZodString;
285
+ color: z.ZodOptional<z.ZodString>;
286
+ }, z.core.$strip>>>;
287
+ }, z.core.$strip>;
288
+ export type UsageSummaryResult = z.infer<typeof UsageSummaryResultSchema>;
289
+ export declare const UsageChangedEventSchema: z.ZodObject<{
290
+ scannedAt: z.ZodNumber;
291
+ }, z.core.$strip>;
292
+ export type UsageChangedEvent = z.infer<typeof UsageChangedEventSchema>;
293
+ export declare const UsageWindowSchema: z.ZodObject<{
294
+ id: z.ZodString;
295
+ kind: z.ZodEnum<{
296
+ monthly: "monthly";
297
+ other: "other";
298
+ session: "session";
299
+ weekly: "weekly";
300
+ }>;
301
+ label: z.ZodString;
302
+ used: z.ZodNumber;
303
+ resetsAt: z.ZodNullable<z.ZodNumber>;
304
+ durationMs: z.ZodNullable<z.ZodNumber>;
305
+ }, z.core.$strip>;
306
+ export type UsageWindow = z.infer<typeof UsageWindowSchema>;
307
+ export declare const UsageLimitsProviderSchema: z.ZodObject<{
308
+ kind: z.ZodEnum<{
309
+ claude: "claude";
310
+ codex: "codex";
311
+ }>;
312
+ account: z.ZodOptional<z.ZodObject<{
313
+ id: z.ZodString;
314
+ label: z.ZodString;
315
+ color: z.ZodOptional<z.ZodString>;
316
+ }, z.core.$strip>>;
317
+ plan: z.ZodNullable<z.ZodString>;
318
+ checkedAt: z.ZodNumber;
319
+ source: z.ZodEnum<{
320
+ event: "event";
321
+ probe: "probe";
322
+ }>;
323
+ windows: z.ZodArray<z.ZodObject<{
324
+ id: z.ZodString;
325
+ kind: z.ZodEnum<{
326
+ monthly: "monthly";
327
+ other: "other";
328
+ session: "session";
329
+ weekly: "weekly";
330
+ }>;
331
+ label: z.ZodString;
332
+ used: z.ZodNumber;
333
+ resetsAt: z.ZodNullable<z.ZodNumber>;
334
+ durationMs: z.ZodNullable<z.ZodNumber>;
335
+ }, z.core.$strip>>;
336
+ cost: z.ZodNullable<z.ZodObject<{
337
+ sessionUsd: z.ZodNumber;
338
+ }, z.core.$strip>>;
339
+ unavailable: z.ZodNullable<z.ZodObject<{
340
+ reason: z.ZodEnum<{
341
+ failed: "failed";
342
+ "no-subscription": "no-subscription";
343
+ "not-installed": "not-installed";
344
+ }>;
345
+ message: z.ZodNullable<z.ZodString>;
346
+ }, z.core.$strip>>;
347
+ }, z.core.$strip>;
348
+ export type UsageLimitsProvider = z.infer<typeof UsageLimitsProviderSchema>;
349
+ export declare const UsageLimitsSnapshotSchema: z.ZodObject<{
350
+ providers: z.ZodArray<z.ZodObject<{
351
+ kind: z.ZodEnum<{
352
+ claude: "claude";
353
+ codex: "codex";
354
+ }>;
355
+ account: z.ZodOptional<z.ZodObject<{
356
+ id: z.ZodString;
357
+ label: z.ZodString;
358
+ color: z.ZodOptional<z.ZodString>;
359
+ }, z.core.$strip>>;
360
+ plan: z.ZodNullable<z.ZodString>;
361
+ checkedAt: z.ZodNumber;
362
+ source: z.ZodEnum<{
363
+ event: "event";
364
+ probe: "probe";
365
+ }>;
366
+ windows: z.ZodArray<z.ZodObject<{
367
+ id: z.ZodString;
368
+ kind: z.ZodEnum<{
369
+ monthly: "monthly";
370
+ other: "other";
371
+ session: "session";
372
+ weekly: "weekly";
373
+ }>;
374
+ label: z.ZodString;
375
+ used: z.ZodNumber;
376
+ resetsAt: z.ZodNullable<z.ZodNumber>;
377
+ durationMs: z.ZodNullable<z.ZodNumber>;
378
+ }, z.core.$strip>>;
379
+ cost: z.ZodNullable<z.ZodObject<{
380
+ sessionUsd: z.ZodNumber;
381
+ }, z.core.$strip>>;
382
+ unavailable: z.ZodNullable<z.ZodObject<{
383
+ reason: z.ZodEnum<{
384
+ failed: "failed";
385
+ "no-subscription": "no-subscription";
386
+ "not-installed": "not-installed";
387
+ }>;
388
+ message: z.ZodNullable<z.ZodString>;
389
+ }, z.core.$strip>>;
390
+ }, z.core.$strip>>;
391
+ }, z.core.$strip>;
392
+ export type UsageLimitsSnapshot = z.infer<typeof UsageLimitsSnapshotSchema>;
package/dist/usage.js ADDED
@@ -0,0 +1,165 @@
1
+ import { z } from 'zod';
2
+ import { ProviderAccountIdSchema } from './provider-accounts.js';
3
+ /* The CLIs whose transcripts the daemon reads. A subset of `AgentKindSchema`: it grows with the readers. */
4
+ export const UsageProviderSchema = z.enum(['claude', 'codex']);
5
+ export const USAGE_PROVIDERS = UsageProviderSchema.options;
6
+ export const UsageResolutionSchema = z.enum(['hour', 'day']);
7
+ /* Token kinds are disjoint, so a total is their sum. Reasoning is a part of output and never counted twice. */
8
+ export const UsageTotalsSchema = z.object({
9
+ calls: z.number().int().nonnegative(),
10
+ /* Input that was neither read from nor written to the cache. */
11
+ input: z.number().int().nonnegative(),
12
+ cacheRead: z.number().int().nonnegative(),
13
+ /* Every cache creation, the one hour kind included. */
14
+ cacheWrite: z.number().int().nonnegative(),
15
+ cacheWrite1h: z.number().int().nonnegative(),
16
+ output: z.number().int().nonnegative(),
17
+ reasoning: z.number().int().nonnegative()
18
+ });
19
+ export const EMPTY_TOTALS = { calls: 0, input: 0, cacheRead: 0, cacheWrite: 0, cacheWrite1h: 0, output: 0, reasoning: 0 };
20
+ export function totalTokensOf(totals) {
21
+ return totals.input + totals.cacheRead + totals.cacheWrite + totals.output;
22
+ }
23
+ /* A sum of two rather than a change to either, so a total a client holds stays the one it drew. */
24
+ export function addTotals(first, second) {
25
+ return {
26
+ calls: first.calls + second.calls,
27
+ input: first.input + second.input,
28
+ cacheRead: first.cacheRead + second.cacheRead,
29
+ cacheWrite: first.cacheWrite + second.cacheWrite,
30
+ cacheWrite1h: first.cacheWrite1h + second.cacheWrite1h,
31
+ output: first.output + second.output,
32
+ reasoning: first.reasoning + second.reasoning
33
+ };
34
+ }
35
+ /* An account a record can belong to, for the page to filter by and color with. The default account of a CLI has its kind as its id. */
36
+ export const UsageAccountSchema = z.object({
37
+ id: ProviderAccountIdSchema,
38
+ kind: UsageProviderSchema,
39
+ label: z.string(),
40
+ // A node accent name, as the account has it; absent on an account nobody gave one.
41
+ color: z.string().optional()
42
+ });
43
+ export const UsageBucketSchema = z.object({
44
+ /* `YYYY-MM-DD` for a day, an ISO hour start for an hour, both in the time zone of the request. */
45
+ slot: z.string(),
46
+ provider: UsageProviderSchema,
47
+ model: z.string(),
48
+ // Only on a summary asked for with `accounts`, which splits every bucket per account.
49
+ account: ProviderAccountIdSchema.optional(),
50
+ totals: UsageTotalsSchema,
51
+ /* Null when no price is known for the model, which is not the same as free. */
52
+ costUsd: z.number().nullable(),
53
+ cacheSavingsUsd: z.number(),
54
+ sessions: z.number().int().nonnegative()
55
+ });
56
+ /* Where a model's price came from, so the page can say so instead of showing a number of unknown origin. */
57
+ export const UsagePriceBasisSchema = z.enum(['exact', 'family', 'override', 'unknown']);
58
+ export const UsageModelSchema = z.object({
59
+ provider: UsageProviderSchema,
60
+ model: z.string(),
61
+ // Only on a summary asked for with `accounts`, which splits every model per account.
62
+ account: ProviderAccountIdSchema.optional(),
63
+ totals: UsageTotalsSchema,
64
+ costUsd: z.number().nullable(),
65
+ priceBasis: UsagePriceBasisSchema,
66
+ /* The family key or the override the price came from, for the tooltip. */
67
+ pricedAs: z.string().nullable()
68
+ });
69
+ export const UsageProjectSchema = z.object({
70
+ /* The git root of the working directory the calls were made in, or that directory itself. */
71
+ folder: z.string(),
72
+ name: z.string(),
73
+ /* Set when the folder is a project the daemon knows, so the page can wear its name and icon. */
74
+ projectId: z.string().nullable(),
75
+ byProvider: z.partialRecord(UsageProviderSchema, z.object({ costUsd: z.number(), tokens: z.number().int() })),
76
+ totals: UsageTotalsSchema,
77
+ costUsd: z.number()
78
+ });
79
+ export const UsageSummaryPayloadSchema = z.object({
80
+ /* `YYYY-MM-DD`, both ends included, read in `timeZone`. */
81
+ from: z.string(),
82
+ to: z.string(),
83
+ resolution: UsageResolutionSchema,
84
+ /* IANA name. The daemon may stand on another machine, so the viewer's days travel with the request. */
85
+ timeZone: z.string(),
86
+ /* Only the usage of these accounts, with buckets and models apart per account. Absent is every account, folded as before accounts. */
87
+ accounts: z.array(ProviderAccountIdSchema).optional()
88
+ });
89
+ export const UsageScanSchema = z.object({
90
+ at: z.number(),
91
+ files: z.number().int().nonnegative(),
92
+ changedFiles: z.number().int().nonnegative(),
93
+ durationMs: z.number().int().nonnegative(),
94
+ running: z.boolean(),
95
+ failed: z.boolean()
96
+ });
97
+ export const UsagePricingSchema = z.object({
98
+ source: z.enum(['litellm', 'snapshot', 'none']),
99
+ fetchedAt: z.number().nullable(),
100
+ models: z.number().int().nonnegative()
101
+ });
102
+ export const UsageRootSchema = z.object({
103
+ provider: UsageProviderSchema,
104
+ path: z.string(),
105
+ status: z.enum(['ok', 'missing', 'failed']),
106
+ message: z.string().nullable()
107
+ });
108
+ /* The day's ECB reference rate for one dollar, so a page can show what a call cost in its own money. */
109
+ export const UsageRateSchema = z.object({
110
+ currency: z.string(),
111
+ rate: z.number().positive(),
112
+ /* The day the rate is of, as the bank publishes it: `YYYY-MM-DD`. */
113
+ date: z.string(),
114
+ fetchedAt: z.number()
115
+ });
116
+ export const UsageSummaryResultSchema = z.object({
117
+ from: z.string(),
118
+ to: z.string(),
119
+ resolution: UsageResolutionSchema,
120
+ timeZone: z.string(),
121
+ buckets: z.array(UsageBucketSchema),
122
+ models: z.array(UsageModelSchema),
123
+ projects: z.array(UsageProjectSchema),
124
+ /* Distinct over the whole period; a session spans days and models, so the buckets cannot say it. */
125
+ sessions: z.number().int().nonnegative(),
126
+ scan: UsageScanSchema,
127
+ pricing: UsagePricingSchema,
128
+ /* Null while no rate has been fetched, which is how the page knows to stay in dollars. */
129
+ rate: UsageRateSchema.nullable(),
130
+ roots: z.array(UsageRootSchema),
131
+ // Every account of the machine, and any a record still names after it was removed.
132
+ accounts: z.array(UsageAccountSchema).optional()
133
+ });
134
+ /* Only the moment: whoever cares asks for the period it has open. */
135
+ export const UsageChangedEventSchema = z.object({ scannedAt: z.number() });
136
+ export const UsageWindowSchema = z.object({
137
+ /* Stable per provider, so a sparse mid-turn event lands on the row a full read drew. */
138
+ id: z.string(),
139
+ kind: z.enum(['session', 'weekly', 'monthly', 'other']),
140
+ label: z.string(),
141
+ /* A fraction, like the context meter; a percent is a view concern. */
142
+ used: z.number().min(0).max(1),
143
+ /* Epoch milliseconds, null when the provider named none. */
144
+ resetsAt: z.number().int().nullable(),
145
+ durationMs: z.number().int().nullable()
146
+ });
147
+ export const UsageLimitsProviderSchema = z.object({
148
+ kind: UsageProviderSchema,
149
+ /* The account these numbers are of. The default account of a kind comes first, in the shape an entry had before accounts. */
150
+ account: UsageAccountSchema.omit({ kind: true }).optional(),
151
+ /* As the provider names it: `max`, `pro`, `ChatGPT Pro`. */
152
+ plan: z.string().nullable(),
153
+ checkedAt: z.number().int(),
154
+ /* What produced these numbers: a read of our own, or an event from a running turn. */
155
+ source: z.enum(['probe', 'event']),
156
+ windows: z.array(UsageWindowSchema),
157
+ cost: z.object({ sessionUsd: z.number().nonnegative() }).nullable(),
158
+ unavailable: z
159
+ .object({
160
+ reason: z.enum(['not-installed', 'no-subscription', 'failed']),
161
+ message: z.string().nullable()
162
+ })
163
+ .nullable()
164
+ });
165
+ export const UsageLimitsSnapshotSchema = z.object({ providers: z.array(UsageLimitsProviderSchema) });
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ export declare const WorktreeWorkSchema: z.ZodObject<{
3
+ changed: z.ZodNumber;
4
+ untracked: z.ZodNumber;
5
+ ahead: z.ZodNumber;
6
+ operation: z.ZodOptional<z.ZodString>;
7
+ behind: z.ZodOptional<z.ZodNumber>;
8
+ }, z.core.$strip>;
9
+ export type WorktreeWork = z.infer<typeof WorktreeWorkSchema>;
10
+ export declare const WorktreeSchema: z.ZodObject<{
11
+ path: z.ZodString;
12
+ branch: z.ZodString;
13
+ from: z.ZodOptional<z.ZodObject<{
14
+ branch: z.ZodOptional<z.ZodString>;
15
+ commit: z.ZodString;
16
+ }, z.core.$strip>>;
17
+ projectId: z.ZodOptional<z.ZodString>;
18
+ nodeId: z.ZodOptional<z.ZodString>;
19
+ madeAt: z.ZodOptional<z.ZodNumber>;
20
+ missing: z.ZodOptional<z.ZodBoolean>;
21
+ locked: z.ZodOptional<z.ZodBoolean>;
22
+ work: z.ZodOptional<z.ZodObject<{
23
+ changed: z.ZodNumber;
24
+ untracked: z.ZodNumber;
25
+ ahead: z.ZodNumber;
26
+ operation: z.ZodOptional<z.ZodString>;
27
+ behind: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strip>>;
29
+ }, z.core.$strip>;
30
+ export type Worktree = z.infer<typeof WorktreeSchema>;
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ // What a worktree holds that its target branch does not: removing it without force refuses while any count is above zero.
3
+ export const WorktreeWorkSchema = z.object({
4
+ // Tracked files changed or staged against the worktree's own HEAD.
5
+ changed: z.number().int().nonnegative(),
6
+ // Untracked files, one per file; ignored files are not work.
7
+ untracked: z.number().int().nonnegative(),
8
+ // Commits on the worktree that the branch it was made from lacks.
9
+ ahead: z.number().int().nonnegative(),
10
+ // A rebase, merge, cherry-pick or revert that stopped halfway, by git's own word for it; that is work too.
11
+ operation: z.string().optional(),
12
+ // Commits the branch it was made from gained since the worktree left it; not work, only how far behind it is.
13
+ behind: z.number().int().nonnegative().optional()
14
+ });
15
+ export const WorktreeSchema = z.object({
16
+ path: z.string(),
17
+ branch: z.string(),
18
+ // Hand-made and legacy worktrees may lack all registered metadata below.
19
+ // Where the worktree was made from; `branch` is absent when HEAD was detached then.
20
+ from: z.object({ branch: z.string().optional(), commit: z.string() }).optional(),
21
+ projectId: z.string().optional(),
22
+ nodeId: z.string().optional(),
23
+ madeAt: z.number().optional(),
24
+ // The folder is gone while git or the register still knows the worktree; only commits can be counted then.
25
+ missing: z.boolean().optional(),
26
+ // Locked with `git worktree lock`; removing it takes force.
27
+ locked: z.boolean().optional(),
28
+ // Only with `inspect` on the list.
29
+ work: WorktreeWorkSchema.optional()
30
+ });