@phosphorco/bb-thread-metrics 0.0.0-stage → 0.2.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.
@@ -0,0 +1,710 @@
1
+ import type { BbPluginApi } from '@get-bb/plugin-sdk';
2
+ import type { PluginBrowserBbSdk } from '@get-bb/plugin-sdk/app';
3
+ import type { RecentSnapshotInput, RecentSnapshotResult, ReadInput, ReadResult, DetailInput, DetailResult, Capabilities, OwnerErrorKind } from './index.js';
4
+ export type MetricsSdk = {
5
+ readonly plugins: Pick<BbPluginApi['sdk']['plugins'], 'list' | 'callRpc'>;
6
+ } | {
7
+ readonly plugins: Pick<PluginBrowserBbSdk['plugins'], 'list' | 'callRpc'>;
8
+ };
9
+ export interface MetricsPort {
10
+ capabilities: Capabilities;
11
+ read(input: ReadInput): Promise<ReadResult>;
12
+ detail?(input: DetailInput): Promise<DetailResult>;
13
+ recentSnapshot?(input: RecentSnapshotInput): Promise<RecentSnapshotResult>;
14
+ }
15
+ export declare function registerThreadMetricsOwner(bb: Pick<BbPluginApi, 'rpc'>, port: MetricsPort): void;
16
+ export declare function createThreadMetricsClient(sdk: MetricsSdk, pluginId: string): {
17
+ pluginId: string;
18
+ describe(signal?: AbortSignal): Promise<{
19
+ kind: "ready";
20
+ version: 1;
21
+ capabilities: Capabilities;
22
+ } | {
23
+ kind: "incompatible";
24
+ }>;
25
+ recentSnapshot(raw?: RecentSnapshotInput, signal?: AbortSignal): Promise<{
26
+ version: 1;
27
+ revision: string;
28
+ unchanged: false;
29
+ currency: "USD";
30
+ estimated: true;
31
+ cutoffLastFoldAt: number | null;
32
+ asOf: number;
33
+ rankAsOf: number;
34
+ recentWindowMs: number;
35
+ config: {
36
+ revision: string;
37
+ value: {
38
+ mode: "percentile";
39
+ gates: {
40
+ m20: number;
41
+ h24: number;
42
+ d7: number;
43
+ };
44
+ schemaVersion: 2;
45
+ providerWeights: Record<string, number>;
46
+ } | {
47
+ mode: "absolute";
48
+ thresholds: {
49
+ m20: number;
50
+ h24: number;
51
+ d7: number;
52
+ lifetime: number;
53
+ };
54
+ schemaVersion: 2;
55
+ providerWeights: Record<string, number>;
56
+ };
57
+ };
58
+ coverage: "complete" | "partial" | "unknown";
59
+ coverageReasons: string[];
60
+ materializationPending: number;
61
+ omittedRows: {
62
+ count: number;
63
+ exact: boolean;
64
+ };
65
+ population: {
66
+ own: {
67
+ dollars: {
68
+ m20: {
69
+ count: number;
70
+ coverage: "complete" | "partial" | "unknown";
71
+ };
72
+ h24: {
73
+ count: number;
74
+ coverage: "complete" | "partial" | "unknown";
75
+ };
76
+ d7: {
77
+ count: number;
78
+ coverage: "complete" | "partial" | "unknown";
79
+ };
80
+ };
81
+ scores: {
82
+ m20: {
83
+ count: number;
84
+ coverage: "complete" | "partial" | "unknown";
85
+ };
86
+ h24: {
87
+ count: number;
88
+ coverage: "complete" | "partial" | "unknown";
89
+ };
90
+ d7: {
91
+ count: number;
92
+ coverage: "complete" | "partial" | "unknown";
93
+ };
94
+ };
95
+ };
96
+ family: {
97
+ dollars: {
98
+ m20: {
99
+ count: number;
100
+ coverage: "complete" | "partial" | "unknown";
101
+ };
102
+ h24: {
103
+ count: number;
104
+ coverage: "complete" | "partial" | "unknown";
105
+ };
106
+ d7: {
107
+ count: number;
108
+ coverage: "complete" | "partial" | "unknown";
109
+ };
110
+ };
111
+ scores: {
112
+ m20: {
113
+ count: number;
114
+ coverage: "complete" | "partial" | "unknown";
115
+ };
116
+ h24: {
117
+ count: number;
118
+ coverage: "complete" | "partial" | "unknown";
119
+ };
120
+ d7: {
121
+ count: number;
122
+ coverage: "complete" | "partial" | "unknown";
123
+ };
124
+ };
125
+ };
126
+ };
127
+ rows: {
128
+ threadId: string;
129
+ revision: string;
130
+ configRevision: string;
131
+ asOf: number;
132
+ ownLastFoldAt: number | null;
133
+ familyLastFoldAt: number | null;
134
+ own: {
135
+ memberCount: number;
136
+ coverage: "complete" | "partial" | "unknown";
137
+ coverageReasons: string[];
138
+ priceVersion: string;
139
+ approximation: {
140
+ approximate: boolean;
141
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
142
+ };
143
+ windows: {
144
+ m20: {
145
+ kind: "estimate";
146
+ amount: number;
147
+ } | {
148
+ kind: "floor";
149
+ amount: number;
150
+ } | {
151
+ kind: "unavailable";
152
+ amount: null;
153
+ };
154
+ h24: {
155
+ kind: "estimate";
156
+ amount: number;
157
+ } | {
158
+ kind: "floor";
159
+ amount: number;
160
+ } | {
161
+ kind: "unavailable";
162
+ amount: null;
163
+ };
164
+ d7: {
165
+ kind: "estimate";
166
+ amount: number;
167
+ } | {
168
+ kind: "floor";
169
+ amount: number;
170
+ } | {
171
+ kind: "unavailable";
172
+ amount: null;
173
+ };
174
+ lifetime: {
175
+ kind: "estimate";
176
+ amount: number;
177
+ } | {
178
+ kind: "floor";
179
+ amount: number;
180
+ } | {
181
+ kind: "unavailable";
182
+ amount: null;
183
+ };
184
+ };
185
+ scores: {
186
+ m20: {
187
+ kind: "estimate";
188
+ amount: number;
189
+ } | {
190
+ kind: "floor";
191
+ amount: number;
192
+ } | {
193
+ kind: "unavailable";
194
+ amount: null;
195
+ };
196
+ h24: {
197
+ kind: "estimate";
198
+ amount: number;
199
+ } | {
200
+ kind: "floor";
201
+ amount: number;
202
+ } | {
203
+ kind: "unavailable";
204
+ amount: null;
205
+ };
206
+ d7: {
207
+ kind: "estimate";
208
+ amount: number;
209
+ } | {
210
+ kind: "floor";
211
+ amount: number;
212
+ } | {
213
+ kind: "unavailable";
214
+ amount: null;
215
+ };
216
+ lifetime: {
217
+ kind: "estimate";
218
+ amount: number;
219
+ } | {
220
+ kind: "floor";
221
+ amount: number;
222
+ } | {
223
+ kind: "unavailable";
224
+ amount: null;
225
+ };
226
+ };
227
+ providers: {
228
+ providerId: string;
229
+ windows: {
230
+ m20: {
231
+ kind: "estimate";
232
+ amount: number;
233
+ } | {
234
+ kind: "floor";
235
+ amount: number;
236
+ } | {
237
+ kind: "unavailable";
238
+ amount: null;
239
+ };
240
+ h24: {
241
+ kind: "estimate";
242
+ amount: number;
243
+ } | {
244
+ kind: "floor";
245
+ amount: number;
246
+ } | {
247
+ kind: "unavailable";
248
+ amount: null;
249
+ };
250
+ d7: {
251
+ kind: "estimate";
252
+ amount: number;
253
+ } | {
254
+ kind: "floor";
255
+ amount: number;
256
+ } | {
257
+ kind: "unavailable";
258
+ amount: null;
259
+ };
260
+ lifetime: {
261
+ kind: "estimate";
262
+ amount: number;
263
+ } | {
264
+ kind: "floor";
265
+ amount: number;
266
+ } | {
267
+ kind: "unavailable";
268
+ amount: null;
269
+ };
270
+ };
271
+ approximation: {
272
+ approximate: boolean;
273
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
274
+ };
275
+ }[];
276
+ omittedProviders: number;
277
+ dollarRanks: {
278
+ m20: number | null;
279
+ h24: number | null;
280
+ d7: number | null;
281
+ };
282
+ scoreRanks: {
283
+ m20: number | null;
284
+ h24: number | null;
285
+ d7: number | null;
286
+ };
287
+ };
288
+ family: {
289
+ memberCount: number;
290
+ coverage: "complete" | "partial" | "unknown";
291
+ coverageReasons: string[];
292
+ priceVersion: string;
293
+ approximation: {
294
+ approximate: boolean;
295
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
296
+ };
297
+ windows: {
298
+ m20: {
299
+ kind: "estimate";
300
+ amount: number;
301
+ } | {
302
+ kind: "floor";
303
+ amount: number;
304
+ } | {
305
+ kind: "unavailable";
306
+ amount: null;
307
+ };
308
+ h24: {
309
+ kind: "estimate";
310
+ amount: number;
311
+ } | {
312
+ kind: "floor";
313
+ amount: number;
314
+ } | {
315
+ kind: "unavailable";
316
+ amount: null;
317
+ };
318
+ d7: {
319
+ kind: "estimate";
320
+ amount: number;
321
+ } | {
322
+ kind: "floor";
323
+ amount: number;
324
+ } | {
325
+ kind: "unavailable";
326
+ amount: null;
327
+ };
328
+ lifetime: {
329
+ kind: "estimate";
330
+ amount: number;
331
+ } | {
332
+ kind: "floor";
333
+ amount: number;
334
+ } | {
335
+ kind: "unavailable";
336
+ amount: null;
337
+ };
338
+ };
339
+ scores: {
340
+ m20: {
341
+ kind: "estimate";
342
+ amount: number;
343
+ } | {
344
+ kind: "floor";
345
+ amount: number;
346
+ } | {
347
+ kind: "unavailable";
348
+ amount: null;
349
+ };
350
+ h24: {
351
+ kind: "estimate";
352
+ amount: number;
353
+ } | {
354
+ kind: "floor";
355
+ amount: number;
356
+ } | {
357
+ kind: "unavailable";
358
+ amount: null;
359
+ };
360
+ d7: {
361
+ kind: "estimate";
362
+ amount: number;
363
+ } | {
364
+ kind: "floor";
365
+ amount: number;
366
+ } | {
367
+ kind: "unavailable";
368
+ amount: null;
369
+ };
370
+ lifetime: {
371
+ kind: "estimate";
372
+ amount: number;
373
+ } | {
374
+ kind: "floor";
375
+ amount: number;
376
+ } | {
377
+ kind: "unavailable";
378
+ amount: null;
379
+ };
380
+ };
381
+ providers: {
382
+ providerId: string;
383
+ windows: {
384
+ m20: {
385
+ kind: "estimate";
386
+ amount: number;
387
+ } | {
388
+ kind: "floor";
389
+ amount: number;
390
+ } | {
391
+ kind: "unavailable";
392
+ amount: null;
393
+ };
394
+ h24: {
395
+ kind: "estimate";
396
+ amount: number;
397
+ } | {
398
+ kind: "floor";
399
+ amount: number;
400
+ } | {
401
+ kind: "unavailable";
402
+ amount: null;
403
+ };
404
+ d7: {
405
+ kind: "estimate";
406
+ amount: number;
407
+ } | {
408
+ kind: "floor";
409
+ amount: number;
410
+ } | {
411
+ kind: "unavailable";
412
+ amount: null;
413
+ };
414
+ lifetime: {
415
+ kind: "estimate";
416
+ amount: number;
417
+ } | {
418
+ kind: "floor";
419
+ amount: number;
420
+ } | {
421
+ kind: "unavailable";
422
+ amount: null;
423
+ };
424
+ };
425
+ approximation: {
426
+ approximate: boolean;
427
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
428
+ };
429
+ }[];
430
+ omittedProviders: number;
431
+ dollarRanks: {
432
+ m20: number | null;
433
+ h24: number | null;
434
+ d7: number | null;
435
+ };
436
+ scoreRanks: {
437
+ m20: number | null;
438
+ h24: number | null;
439
+ d7: number | null;
440
+ };
441
+ };
442
+ }[];
443
+ } | {
444
+ version: 1;
445
+ revision: string;
446
+ unchanged: true;
447
+ }>;
448
+ read(raw: ReadInput, signal?: AbortSignal): Promise<{
449
+ version: 1;
450
+ rows: ({
451
+ changed: true;
452
+ windows: {
453
+ m20: {
454
+ tokens: {
455
+ inputUncached: number;
456
+ cacheRead: number;
457
+ cacheWrite: number;
458
+ output: number;
459
+ };
460
+ amount: number | null;
461
+ };
462
+ h24: {
463
+ tokens: {
464
+ inputUncached: number;
465
+ cacheRead: number;
466
+ cacheWrite: number;
467
+ output: number;
468
+ };
469
+ amount: number | null;
470
+ };
471
+ d7: {
472
+ tokens: {
473
+ inputUncached: number;
474
+ cacheRead: number;
475
+ cacheWrite: number;
476
+ output: number;
477
+ };
478
+ amount: number | null;
479
+ };
480
+ lifetime: {
481
+ tokens: {
482
+ inputUncached: number;
483
+ cacheRead: number;
484
+ cacheWrite: number;
485
+ output: number;
486
+ };
487
+ amount: number | null;
488
+ };
489
+ };
490
+ threadId: string;
491
+ scope: "own" | "family";
492
+ memberCount: number;
493
+ coverage: "complete" | "partial" | "unknown";
494
+ coverageReasons: ("source-gap" | "unpriced" | "root-unattested" | "history-unavailable" | "missing-thread" | "member-cap" | "depth-cap" | "edge-cap" | "retention" | "row-cap" | "pagination" | "population-incomplete")[];
495
+ asOf: number;
496
+ revision: string;
497
+ priceVersion: string;
498
+ currency: "USD";
499
+ estimated: true;
500
+ approximation: {
501
+ approximate: boolean;
502
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
503
+ rates?: {
504
+ providerId: string;
505
+ modelId: string;
506
+ rateId: string | null;
507
+ basis: "closest-model" | "provider-default" | "unpriced" | "matched";
508
+ }[] | undefined;
509
+ };
510
+ ranks: {
511
+ m20: number | null;
512
+ h24: number | null;
513
+ d7: number | null;
514
+ };
515
+ rankPopulation: {
516
+ m20: {
517
+ asOf: number;
518
+ count: number;
519
+ coverage: "complete" | "partial" | "unknown";
520
+ };
521
+ h24: {
522
+ asOf: number;
523
+ count: number;
524
+ coverage: "complete" | "partial" | "unknown";
525
+ };
526
+ d7: {
527
+ asOf: number;
528
+ count: number;
529
+ coverage: "complete" | "partial" | "unknown";
530
+ };
531
+ };
532
+ buckets?: {
533
+ start: number;
534
+ amount: number | null;
535
+ }[] | undefined;
536
+ excluded?: number | undefined;
537
+ reported?: {
538
+ amount: number;
539
+ currency: string;
540
+ asOf: number;
541
+ } | undefined;
542
+ } | {
543
+ changed: false;
544
+ threadId: string;
545
+ scope: "own" | "family";
546
+ memberCount: number;
547
+ coverage: "complete" | "partial" | "unknown";
548
+ coverageReasons: ("source-gap" | "unpriced" | "root-unattested" | "history-unavailable" | "missing-thread" | "member-cap" | "depth-cap" | "edge-cap" | "retention" | "row-cap" | "pagination" | "population-incomplete")[];
549
+ asOf: number;
550
+ revision: string;
551
+ priceVersion: string;
552
+ currency: "USD";
553
+ estimated: true;
554
+ approximation: {
555
+ approximate: boolean;
556
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
557
+ rates?: {
558
+ providerId: string;
559
+ modelId: string;
560
+ rateId: string | null;
561
+ basis: "closest-model" | "provider-default" | "unpriced" | "matched";
562
+ }[] | undefined;
563
+ };
564
+ ranks: {
565
+ m20: number | null;
566
+ h24: number | null;
567
+ d7: number | null;
568
+ };
569
+ rankPopulation: {
570
+ m20: {
571
+ asOf: number;
572
+ count: number;
573
+ coverage: "complete" | "partial" | "unknown";
574
+ };
575
+ h24: {
576
+ asOf: number;
577
+ count: number;
578
+ coverage: "complete" | "partial" | "unknown";
579
+ };
580
+ d7: {
581
+ asOf: number;
582
+ count: number;
583
+ coverage: "complete" | "partial" | "unknown";
584
+ };
585
+ };
586
+ windows?: undefined;
587
+ buckets?: undefined;
588
+ excluded?: number | undefined;
589
+ reported?: {
590
+ amount: number;
591
+ currency: string;
592
+ asOf: number;
593
+ } | undefined;
594
+ })[];
595
+ }>;
596
+ detail(raw: DetailInput, signal?: AbortSignal): Promise<{
597
+ version: 1;
598
+ threadId: string;
599
+ scope: "own" | "family";
600
+ axis: "time" | "model";
601
+ window: "m20" | "h24" | "d7" | "lifetime";
602
+ asOf: number;
603
+ revision: string;
604
+ priceVersion: string;
605
+ currency: "USD";
606
+ estimated: true;
607
+ coverage: "complete" | "partial" | "unknown";
608
+ coverageReasons: ("source-gap" | "unpriced" | "root-unattested" | "history-unavailable" | "missing-thread" | "member-cap" | "depth-cap" | "edge-cap" | "retention" | "row-cap" | "pagination" | "population-incomplete")[];
609
+ approximation: {
610
+ approximate: boolean;
611
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
612
+ rates?: {
613
+ providerId: string;
614
+ modelId: string;
615
+ rateId: string | null;
616
+ basis: "closest-model" | "provider-default" | "unpriced" | "matched";
617
+ }[] | undefined;
618
+ };
619
+ total: {
620
+ tokens: {
621
+ inputUncached: number;
622
+ cacheRead: number;
623
+ cacheWrite: number;
624
+ output: number;
625
+ };
626
+ amount: number | null;
627
+ };
628
+ rows: ({
629
+ axis: "time";
630
+ start: number;
631
+ end: number;
632
+ amount: number | null;
633
+ tokens: {
634
+ inputUncached: number;
635
+ cacheRead: number;
636
+ cacheWrite: number;
637
+ output: number;
638
+ };
639
+ approximation: {
640
+ approximate: boolean;
641
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
642
+ rates?: {
643
+ providerId: string;
644
+ modelId: string;
645
+ rateId: string | null;
646
+ basis: "closest-model" | "provider-default" | "unpriced" | "matched";
647
+ }[] | undefined;
648
+ };
649
+ } | {
650
+ axis: "model";
651
+ providerId: string;
652
+ modelId: string;
653
+ amount: number | null;
654
+ tokens: {
655
+ inputUncached: number;
656
+ cacheRead: number;
657
+ cacheWrite: number;
658
+ output: number;
659
+ };
660
+ approximation: {
661
+ approximate: boolean;
662
+ reasons: ("closest-model" | "provider-default" | "model-attribution" | "bucket-boundary" | "missing-price" | "source-gap")[];
663
+ rates?: {
664
+ providerId: string;
665
+ modelId: string;
666
+ rateId: string | null;
667
+ basis: "closest-model" | "provider-default" | "unpriced" | "matched";
668
+ }[] | undefined;
669
+ };
670
+ })[];
671
+ excluded?: number | undefined;
672
+ nextCursor?: string | undefined;
673
+ }>;
674
+ };
675
+ export type DiscoveryRow = {
676
+ pluginId: string;
677
+ state: 'ready';
678
+ version: 1;
679
+ capabilities: Capabilities;
680
+ } | {
681
+ pluginId: string;
682
+ state: 'incompatible';
683
+ } | {
684
+ pluginId: string;
685
+ state: 'error';
686
+ error: OwnerErrorKind;
687
+ };
688
+ export interface DiscoveryResult {
689
+ rows: DiscoveryRow[];
690
+ omittedCount: number;
691
+ complete: boolean;
692
+ listError?: OwnerErrorKind | 'busy';
693
+ }
694
+ export interface DiscoveryOptions {
695
+ sdk: MetricsSdk;
696
+ signal?: AbortSignal;
697
+ maxCandidates?: number;
698
+ concurrency?: number;
699
+ callMs?: number;
700
+ deadlineMs?: number;
701
+ onRow?: (row: DiscoveryRow) => void;
702
+ }
703
+ /** One instance per mounted demand coordinator, retained across refresh/reconnect passes.
704
+ * A completed local deadline does not free underlying reads. Busy passes do no I/O.
705
+ * No queue, retries, timers or global singleton are created by the coordinator itself.
706
+ */
707
+ export declare function createThreadMetricsDiscovery(sdk: MetricsSdk): {
708
+ readonly outstandingReads: number;
709
+ discover(options?: Omit<DiscoveryOptions, "sdk">): Promise<DiscoveryResult>;
710
+ };