vidnavigator 1.0.4 → 1.0.5

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.
@@ -1,5 +1,132 @@
1
1
  export type UnlimitedOrNumber = number | 'unlimited';
2
2
 
3
+ /** Meters that can appear in a per-call {@link UsageBlock}. */
4
+ export type UsageServiceType =
5
+ | 'standard_request'
6
+ | 'residential_request'
7
+ | 'transcription_hour'
8
+ | 'analysis_request'
9
+ | 'search_request'
10
+ | 'scene_analysis_hour';
11
+
12
+ export interface UsageTokens {
13
+ prompt_tokens?: number;
14
+ completion_tokens?: number;
15
+ total_tokens?: number;
16
+ }
17
+
18
+ export interface UsageChargeJSON {
19
+ service_type: UsageServiceType;
20
+ quantity: number;
21
+ credits: number;
22
+ waived?: boolean;
23
+ credits_saved?: number;
24
+ tokens?: UsageTokens;
25
+ }
26
+
27
+ /** A single consolidated meter charge within a per-call usage block. */
28
+ export class UsageCharge {
29
+ service_type: UsageServiceType;
30
+ quantity: number;
31
+ credits: number;
32
+ waived?: boolean;
33
+ credits_saved?: number;
34
+ tokens?: UsageTokens;
35
+
36
+ constructor(data: UsageChargeJSON) {
37
+ this.service_type = data.service_type;
38
+ this.quantity = data.quantity;
39
+ this.credits = data.credits;
40
+ this.waived = data.waived;
41
+ this.credits_saved = data.credits_saved;
42
+ this.tokens = data.tokens;
43
+ }
44
+
45
+ static fromJSON(json: UsageChargeJSON): UsageCharge {
46
+ return new UsageCharge(json);
47
+ }
48
+ }
49
+
50
+ export interface UsageBlockJSON {
51
+ charges?: UsageChargeJSON[];
52
+ total_credits?: number;
53
+ credits_remaining_after?: number;
54
+ waived?: { credits_saved: number };
55
+ /** Legacy flat token fields. Some /extract/* responses may still echo these. */
56
+ prompt_tokens?: number;
57
+ completion_tokens?: number;
58
+ total_tokens?: number;
59
+ }
60
+
61
+ /**
62
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
63
+ * Lists every meter charged during the request plus the credits actually deducted.
64
+ *
65
+ * LLM token counts live nested inside the `analysis_request` charge; use the
66
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
67
+ * legacy flat token fields when present).
68
+ */
69
+ export class UsageBlock {
70
+ charges: UsageCharge[];
71
+ total_credits?: number;
72
+ credits_remaining_after?: number;
73
+ waived?: { credits_saved: number };
74
+ /** Legacy flat token fields, only present on some /extract/* responses. */
75
+ prompt_tokens?: number;
76
+ completion_tokens?: number;
77
+ total_tokens?: number;
78
+
79
+ constructor(data: UsageBlockJSON) {
80
+ this.charges = (data.charges ?? []).map(UsageCharge.fromJSON);
81
+ this.total_credits = data.total_credits;
82
+ this.credits_remaining_after = data.credits_remaining_after;
83
+ this.waived = data.waived;
84
+ this.prompt_tokens = data.prompt_tokens;
85
+ this.completion_tokens = data.completion_tokens;
86
+ this.total_tokens = data.total_tokens;
87
+ }
88
+
89
+ /** Return the consolidated charge entry for a given meter, if present. */
90
+ charge_for(service_type: UsageServiceType): UsageCharge | undefined {
91
+ return this.charges.find((c) => c.service_type === service_type);
92
+ }
93
+
94
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
95
+ chargeFor(service_type: UsageServiceType): UsageCharge | undefined {
96
+ return this.charge_for(service_type);
97
+ }
98
+
99
+ /**
100
+ * LLM token tally for this request. Reads the `tokens` object from the
101
+ * `analysis_request` charge, falling back to legacy flat token fields.
102
+ */
103
+ get analysis_tokens(): UsageTokens | undefined {
104
+ const analysis = this.charge_for('analysis_request');
105
+ if (analysis?.tokens) return analysis.tokens;
106
+ if (
107
+ this.prompt_tokens !== undefined ||
108
+ this.completion_tokens !== undefined ||
109
+ this.total_tokens !== undefined
110
+ ) {
111
+ return {
112
+ prompt_tokens: this.prompt_tokens,
113
+ completion_tokens: this.completion_tokens,
114
+ total_tokens: this.total_tokens,
115
+ };
116
+ }
117
+ return undefined;
118
+ }
119
+
120
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
121
+ get analysisTokens(): UsageTokens | undefined {
122
+ return this.analysis_tokens;
123
+ }
124
+
125
+ static fromJSON(json: UsageBlockJSON): UsageBlock {
126
+ return new UsageBlock(json);
127
+ }
128
+ }
129
+
3
130
  export interface CreditsInfoJSON {
4
131
  monthly_total: UnlimitedOrNumber;
5
132
  monthly_remaining: UnlimitedOrNumber;