@yaks/spend 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +159 -2
- package/_dist/graph.d.ts +26 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +11 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/routes.d.ts +10 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/service.d.ts +41 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/tally.d.ts +111 -0
- package/_dist/tally.d.ts.map +1 -0
- package/_dist/tools.d.ts +52 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/use.d.ts +31 -0
- package/_dist/use.d.ts.map +1 -0
- package/_dist/views.d.ts +27 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/window.d.ts +132 -0
- package/_dist/window.d.ts.map +1 -0
- package/_dist/words.d.ts +40 -0
- package/_dist/words.d.ts.map +1 -0
- package/budget.js +131 -0
- package/budget.js.map +1 -0
- package/budget.ts +128 -0
- package/day.js +336 -0
- package/day.js.map +1 -0
- package/day.ts +364 -0
- package/deno.json +1 -0
- package/graph.js +59 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/mod.js +11 -0
- package/mod.js.map +1 -0
- package/mod.ts +34 -0
- package/package.json +57 -4
- package/page.js +352 -0
- package/page.js.map +1 -0
- package/page.ts +491 -0
- package/routes.js +22 -0
- package/routes.js.map +1 -0
- package/routes.ts +19 -0
- package/service.js +124 -0
- package/service.js.map +1 -0
- package/service.ts +149 -0
- package/tally.js +385 -0
- package/tally.js.map +1 -0
- package/tally.ts +424 -0
- package/tools.js +243 -0
- package/tools.js.map +1 -0
- package/tools.ts +357 -0
- package/use.js +172 -0
- package/use.js.map +1 -0
- package/use.ts +226 -0
- package/views.js +79 -0
- package/views.js.map +1 -0
- package/views.ts +96 -0
- package/vocab.js +17 -0
- package/vocab.js.map +1 -0
- package/vocab.json +237 -0
- package/vocab.ts +18 -0
- package/window.js +259 -0
- package/window.js.map +1 -0
- package/window.ts +336 -0
- package/words.js +47 -0
- package/words.js.map +1 -0
- package/words.ts +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/spend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Where model tokens go. Every model request an agent makes here is an entry in
|
|
4
|
+
the graph with its `usage` (@yaks/model) and, where the importer or the native
|
|
5
|
+
runner recorded it, its `context_parts` (@yaks/session/parts): its input laid
|
|
6
|
+
out part by part in the order it was sent, and the provider's measured totals
|
|
7
|
+
split across the parts by their sizes. This package tallies those requests into
|
|
8
|
+
one row per UTC day and draws the tallies, so looking at where the tokens went
|
|
9
|
+
reads a few rows and spends nothing.
|
|
10
|
+
|
|
11
|
+
A **part** is one piece of what a request carried: a piece of the fixed part
|
|
12
|
+
every request of a session carries (`system`, `tool <name>`, `persona <id>`,
|
|
13
|
+
`skills`, `mcp instructions`, …, from the session's `fixed`), or a kind of
|
|
14
|
+
conversation (`input`, `output`, `reasoning`, `notice`, `checkpoint`,
|
|
15
|
+
`call <tool>`, `result <tool>`). A part is paid for on every request it rides
|
|
16
|
+
in, as it was paid that time: read from the provider cache, written to it, sent
|
|
17
|
+
fresh, or generated. A request whose context was not recorded is one part,
|
|
18
|
+
`unrecorded`.
|
|
19
|
+
|
|
20
|
+
## The tally
|
|
21
|
+
|
|
22
|
+
A day's tally is a `spend` row on an eid derived from its `day`, holding its
|
|
23
|
+
`requests`, its `tokens` and `dollars`, and:
|
|
24
|
+
|
|
25
|
+
- `parts`: `[read, written, fresh, generated, dollars]` by part;
|
|
26
|
+
- `sessions`: `[tokens, dollars, requests]` by session;
|
|
27
|
+
- `tasks`: `[tokens, dollars]` by task, each session split evenly across the
|
|
28
|
+
tasks it claimed, commented on, filed or finished that day or the next, and a
|
|
29
|
+
subagent across the tasks its brief names, else as the session that started
|
|
30
|
+
it;
|
|
31
|
+
- `models`: `[read, written, fresh, generated, dollars, requests]` by model;
|
|
32
|
+
- `entries`: `[tokens, dollars]` for the fifty transcript entries that cost most
|
|
33
|
+
as they were carried request after request.
|
|
34
|
+
- `plans`: by the account whose plan the requests billed against
|
|
35
|
+
(`account{home, provider}`, @yaks/model), the dollars they ran up on it, in
|
|
36
|
+
all and by part, session, task, model and entry. A request read from a Claude
|
|
37
|
+
Code transcript or a Codex rollout bills the account whose directory holds it;
|
|
38
|
+
one the native harness sent bills the account its `using` provider's CLI signs
|
|
39
|
+
in with here (Claude's CLI Claude Code's; Codex's CLI, and OpenAI signed in
|
|
40
|
+
with ChatGPT, Codex's); a managed run's transcript is its command's output, in
|
|
41
|
+
no account's directory, so its requests bill the account of the provider its
|
|
42
|
+
session asked for; a request paid by the token (OpenRouter, OpenAI with an API
|
|
43
|
+
key) bills none (`PLANS`, `planOf` in ./day.ts).
|
|
44
|
+
|
|
45
|
+
Dollars are what the provider reported, else the tokens at the `price` of the
|
|
46
|
+
model that answered (`ask.served`: a Claude Code alias such as `fable` is
|
|
47
|
+
answered by a release such as `claude-fable-5-2`), else of the model asked. The
|
|
48
|
+
totals are measured; the split across parts, and across a session's tasks, is
|
|
49
|
+
estimated.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { merged, tally } from '@yaks/spend'
|
|
53
|
+
import { equal } from '@yaks/testing'
|
|
54
|
+
|
|
55
|
+
let ask = {
|
|
56
|
+
entity: { eid: 'a' },
|
|
57
|
+
entry: { session: 's' },
|
|
58
|
+
ask: { to: 'm' },
|
|
59
|
+
usage: { input_tokens: 1000, output_tokens: 10 },
|
|
60
|
+
context_parts: { parts: { input: [0, 0, 1000, 0], output: [0, 0, 0, 10] } },
|
|
61
|
+
}
|
|
62
|
+
let day = tally('2026-10-20', [ask], {
|
|
63
|
+
prices: new Map([['m', { input: 4, output: 20 }]]),
|
|
64
|
+
fixed: new Map(),
|
|
65
|
+
tasks: new Map(),
|
|
66
|
+
})
|
|
67
|
+
equal(merged([day, day]).parts.input, [0, 0, 2000, 0, 0.008])
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
A request whose model has no `price` and which reported no dollars is weighed at
|
|
71
|
+
nothing, and its model is named in the tally's `unpriced` (and its plan's): what
|
|
72
|
+
it cost is missing, not zero. The duty tells the tracker of each such model once
|
|
73
|
+
while the server runs. The page says `unpriced: <model>` in place of that
|
|
74
|
+
model's dollars and of any week % or "1% of it is about" built on a plan whose
|
|
75
|
+
week holds one. Give the model a `price` row and the next tally heals it.
|
|
76
|
+
|
|
77
|
+
## The duty and the tools
|
|
78
|
+
|
|
79
|
+
`@yaks/spend/service` is a duty: every ten minutes it tallies today again (and
|
|
80
|
+
yesterday, for the first hours of a day), and keeps the Claude plan's newest
|
|
81
|
+
limits as `rate_limit` rows, read from the cache claude-status writes
|
|
82
|
+
(`~/.cache/claude-usage`, or `$CLAUDE_USAGE_DIR`): the limits of the account
|
|
83
|
+
`yak serve`'s environment signs in with, or of the one a `CLAUDE_CONFIG_DIR=`
|
|
84
|
+
line in the reading names. That cache is filled by an interactive session's
|
|
85
|
+
status line alone. A `claude -p` run reports the same limits in its own stream,
|
|
86
|
+
and they arrive with the run (@yaks/session's `claude` reader), so the readings
|
|
87
|
+
stay fresh with nobody in Claude Code. Codex's limits arrive with its sessions,
|
|
88
|
+
each account's with its own. Options: `every` (milliseconds) and `usage` (the
|
|
89
|
+
cache directory).
|
|
90
|
+
|
|
91
|
+
`@yaks/spend/graph` is what marks a day `untallied`: a request written after its
|
|
92
|
+
day ended, as every request of a transcript read in after the fact is, marks its
|
|
93
|
+
day's row in the same transaction, and the duty tallies every marked day within
|
|
94
|
+
a minute. So the first `yak serve` on a machine with months of Claude Code and
|
|
95
|
+
Codex transcripts fills every one of those days as the transcripts are read,
|
|
96
|
+
with no command. The duty takes the mark off before it tallies the day, so a
|
|
97
|
+
request arriving during the tally marks the day again.
|
|
98
|
+
|
|
99
|
+
- `yak spend show [since] [--until day] [--top n]` reports a span of days, by
|
|
100
|
+
default the Claude plan's week. A day is written in the time grammar
|
|
101
|
+
(@yaks/vocab `timeSpan`): `2026-10-13`, `yesterday`, `3 days ago`.
|
|
102
|
+
- `yak spend show [since] --done` reports only the cost per completed task in
|
|
103
|
+
each UTC week (Monday to Sunday) from the one `since` falls in: the dollars
|
|
104
|
+
every tally charged the tasks completed that week, over those of them charged
|
|
105
|
+
any, as cash and as usage at list price, never one total. The charge is the
|
|
106
|
+
`tasks` split above, so it is an estimate; decisions are not counted.
|
|
107
|
+
- `yak spend tally [since]` tallies each day since a day (default today) again
|
|
108
|
+
from the requests the graph holds, in a few seconds a day: a changed price or
|
|
109
|
+
plan shows without waiting for the duty's next pass.
|
|
110
|
+
- `yak spend backfill <since>` measures the requests of every transcript,
|
|
111
|
+
managed run and graph session written since a day (@yaks/session and
|
|
112
|
+
@yaks/spawn `recounted`), then tallies each day. It reads every one of those
|
|
113
|
+
transcripts whole, so a busy day takes about half a minute.
|
|
114
|
+
|
|
115
|
+
## A topic's share
|
|
116
|
+
|
|
117
|
+
A topic can have a share of each plan's week (`attended{share}`,
|
|
118
|
+
[@yaks/topic](../topic)). `shared(graph)` from `@yaks/spend/tools` reads how
|
|
119
|
+
much of each share is used, and `yak spend show` prints its rows, a line each:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
Q-12 Funnel keeps 7.5% of each plan's week (its 10% less 2.5% given below): claude 4.1% used ($118 of usage at list price), 30% of its week gone
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- A session's dollars are charged to the topic it was opened on
|
|
126
|
+
(`session.topic`), else to the topic the session that started it
|
|
127
|
+
(`spawned.parent`) is charged to, up its line however long. A topic with no
|
|
128
|
+
share passes them to the nearest topic above it that has one.
|
|
129
|
+
- On each weekly limit, the dollars are those of the limit's running week,
|
|
130
|
+
turned into a part of that week by the limit's rate (`limitRates`), beside how
|
|
131
|
+
much of the week is gone (`paceOf`). A limit read before its week turned has
|
|
132
|
+
no rate, and says so.
|
|
133
|
+
- A plan's limit on one model (`rate_limit{model}`, Claude's weekly cap on
|
|
134
|
+
Fable) is a limit of its own, under the model's name: it counts that model's
|
|
135
|
+
requests alone (`billedOn`), at the rate its own reading gives.
|
|
136
|
+
- The last row is the work no share covers, against the part of the week no
|
|
137
|
+
topic was given.
|
|
138
|
+
|
|
139
|
+
The dollars are usage at list price: a plan is a subscription, so they measure
|
|
140
|
+
use and are not cash. Nothing here is stored. Where no topic has a share,
|
|
141
|
+
nothing is read and nothing is printed.
|
|
142
|
+
|
|
143
|
+
## The page
|
|
144
|
+
|
|
145
|
+
`./views` offers the browsing app a `Spend` page in its sidebar (`/?page=spend`,
|
|
146
|
+
which `./routes` also answers at `/spend`, the address `yak serve` prints when
|
|
147
|
+
it starts): each account's plan limits against their pace, what each account ran
|
|
148
|
+
up this week beside the total, then the week's tally beside the week before,
|
|
149
|
+
ranked by dollars, over the list of days. An account is named by its provider
|
|
150
|
+
where the provider keeps one, else by its directory (`.claude-work`). A day's
|
|
151
|
+
row opens to that day's tally. The bars are @yaks/ui's `Meter`.
|
|
152
|
+
|
|
153
|
+
Beside each row's dollars, its **week %** estimates what it cost on a
|
|
154
|
+
subscription: its share of each plan's weekly limit. `rates` measures a plan's
|
|
155
|
+
dollar from its newest weekly reading (`rate_limit`, the percent Claude's
|
|
156
|
+
claude-status and Codex's rollouts report) over the dollars, at list price, its
|
|
157
|
+
requests ran up from the day the week began to the day of the reading. A row
|
|
158
|
+
that billed two plans says each share apart; one paid by the token says so. A
|
|
159
|
+
`call <tool>` or `result <tool>` part links to the calls or results it was made
|
|
160
|
+
of in the span (`partQuery`, @yaks/session/parts).
|
package/_dist/graph.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The graph plugin: the module a server imports at `@yaks/spend/graph`. A
|
|
3
|
+
* request written after its day ended, as when a transcript is read in after
|
|
4
|
+
* the fact, marks its day's row `untallied`, so the duty (./service.ts) tallies
|
|
5
|
+
* that day again without being asked. Today needs no mark: every pass tallies
|
|
6
|
+
* it.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/ import type { Bundle, Plugin } from "@yaks/graph";
|
|
10
|
+
/** The days before `today` the requests in a batch were made on. A batch's
|
|
11
|
+
* stamps ride in bundles of their own, so a request's `created.at` is found by
|
|
12
|
+
* its eid.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { late } from '@yaks/spend/graph'
|
|
16
|
+
* import { equal } from '@yaks/testing'
|
|
17
|
+
* let asked = { entity: { eid: 'a' }, ask: {}, usage: { input_tokens: 1 } }
|
|
18
|
+
* let made = (at: string) => ({ entity: { eid: 'a' }, created: { at } })
|
|
19
|
+
* equal(late([asked, made('2026-10-20T12:00:00Z')], '2026-10-25'), ['2026-10-20'])
|
|
20
|
+
* equal(late([asked, made('2026-10-25T01:00:00Z')], '2026-10-25'), [])
|
|
21
|
+
* ```
|
|
22
|
+
*/ export declare let late: (bundles: Bundle[], today: string) => string[];
|
|
23
|
+
/** Mark each past day a batch adds requests to, inside its transaction, so a
|
|
24
|
+
* day is never read in without being owed a tally. `now` is the clock. */ export declare let untallied: (now?: () => number) => Plugin;
|
|
25
|
+
/** The plugins this package adds to a graph. */ export declare let plugins: () => Plugin[];
|
|
26
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,cAAc,MAAM,EAAE,MAAM,2BAAgC;AAK5D;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,OAAQ,SAAS,UAAU,OAAO,MAAM,KAAG,MAAM,GAW3D;AAED;wEACwE,GACxE,OAAO,YAAI,YAAa,YAAW,MAAM,KAAc,OAerD;AAEF,8CAA8C,GAC9C,OAAO,YAAI,eAAc,SAAyB"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where model tokens go. A duty tallies each UTC day's requests into its
|
|
3
|
+
* `spend` row (./service.ts, ./day.ts); a page and `yak spend show` read the
|
|
4
|
+
* rows. This module is the pure part both sides share: the tally, plan limits
|
|
5
|
+
* and their pace, and the words numbers are said in.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/ export { empty, ENTRIES, type Known, merged, type Plan, ranked, type Rows, type Spend, spendOf, tally } from "./tally.js";
|
|
9
|
+
export { after, billedOn, current, dayOf, type Limit, limitRates, limitsOf, paceOf, rates, span, weekOf } from "./window.js";
|
|
10
|
+
export { dollars, label, percent, tokens } from "./words.js";
|
|
11
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;CAOC,GACD,SACE,KAAK,EACL,OAAO,EACP,KAAK,KAAK,EACV,MAAM,EACN,KAAK,IAAI,EACT,MAAM,EACN,KAAK,IAAI,EACT,KAAK,KAAK,EACV,OAAO,EACP,KAAK,qBACY;AACnB,SACE,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,KAAK,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,EACJ,MAAM,sBACY;AACpB,SAAS,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAoB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/spend`: the Spend page at an address a person can type, and the line
|
|
3
|
+
* `yak serve` prints beside it when it starts listening, so someone who came
|
|
4
|
+
* for the page finds it without knowing the browsing app's `/?page=spend`
|
|
5
|
+
* (./views.ts `destinations`).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/ import type { Route } from "@yaks/api";
|
|
9
|
+
/** The page's address, sent on to the browsing app. */ export declare let routes: () => Route[];
|
|
10
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sources":["../routes.ts"],"names":[],"mappings":"AAAA;;;;;;;CAOC,GACD,cAAc,KAAK,yBAA8B;AAGjD,qDAAqD,GACrD,OAAO,YAAI,cAAa,QAMtB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tally, as a duty: the module a server imports at `@yaks/spend/service`.
|
|
3
|
+
* Every pass tallies today again from its requests (./day.ts), and yesterday
|
|
4
|
+
* too for the first hours of a day, while its last requests are still being
|
|
5
|
+
* read in, and every past day marked `untallied` because requests reached it
|
|
6
|
+
* late, as a transcript read in after the fact does (./graph.ts); then it
|
|
7
|
+
* keeps the Claude plan's newest limits (./budget.ts). A
|
|
8
|
+
* page that shows where the tokens went reads these rows, never the
|
|
9
|
+
* requests, so looking costs nothing.
|
|
10
|
+
*
|
|
11
|
+
* It is a loop because a tally is owed as time passes, not when one write
|
|
12
|
+
* commits: a day of requests is thousands of writes, and tallying after each
|
|
13
|
+
* would cost more than the tally saves.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/ import type { Eid, Graph } from "@yaks/graph";
|
|
17
|
+
/** What a config can set for this duty. */ export type Options = {
|
|
18
|
+
/** how long a pass waits for the next, in milliseconds (default ten
|
|
19
|
+
* minutes) */ every?: number;
|
|
20
|
+
/** where claude-status keeps its readings (default `$CLAUDE_USAGE_DIR` or
|
|
21
|
+
* `~/.cache/claude-usage`) */ usage?: string;
|
|
22
|
+
};
|
|
23
|
+
/** How long a pass waits for the next. */ export declare let EVERY: any;
|
|
24
|
+
/** How often the duty looks for days marked `untallied` between passes, so
|
|
25
|
+
* transcripts read in on a first `yak serve` show within a minute. */ export declare let LOOK: any;
|
|
26
|
+
/** How long into a day yesterday is tallied again. */ export declare let LATE: any;
|
|
27
|
+
/** One pass: today, yesterday while it may still be arriving, the days
|
|
28
|
+
* requests reached late, the limits.
|
|
29
|
+
* Returns the models its tallies met with no price, which are missing from
|
|
30
|
+
* the dollars, not zero in them. */ export declare let pass: (g: Graph, now?: number, o?: Options) => Promise<Eid[]>;
|
|
31
|
+
/** Tally each day marked `untallied`. The mark comes off before the day is
|
|
32
|
+
* read, so a request written while it is tallied marks it again. Returns the
|
|
33
|
+
* models its tallies met with no price. */ export declare let owed: (g: Graph) => Promise<Eid[]>;
|
|
34
|
+
/** Tally, then again every `every`, and the owed days every `LOOK`, until the signal aborts. An already
|
|
35
|
+
* aborted signal is one pass. */ export declare let service: (host: {
|
|
36
|
+
graph: Graph;
|
|
37
|
+
report?: (error: unknown, context?: {
|
|
38
|
+
tags?: Record<string, string>;
|
|
39
|
+
}) => unknown;
|
|
40
|
+
}, options?: Options, signal?: AbortSignal) => Promise<void>;
|
|
41
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sources":["../service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,cAAc,GAAG,EAAE,KAAK,2BAAgC;AAaxD,yCAAyC,GACzC,YAAY;EACV;cACY,GACZ,QAAQ,MAAM;EACd;8BAC4B,GAC5B,QAAQ,MAAM;;AAGhB,wCAAwC,GACxC,OAAO,YAAI,WAAsB;AAEjC;oEACoE,GACpE,OAAO,YAAI,UAAgB;AAE3B,oDAAoD,GACpD,OAAO,YAAI,UAAyB;AAEpC;;;kCAGkC,GAClC,OAAO,YAAI,OACT,GAAG,OACH,MAAK,MAAM,EACX,IAAG,YACF,QAAQ,OAwBV;AAED;;yCAEyC,GACzC,OAAO,YAAI,OAAc,GAAG,UAAQ,QAAQ,OAQ3C;AAED;+BAC+B,GAC/B,OAAO,YAAI,UACT;EACE,OAAO;EACP,UACE,OAAO,OAAO,EACd;IAAY,OAAO,OAAO,MAAM,EAAE,MAAM;QACrC,OAAO;GAEd,UAAS,SACT,SAAQ,gBACP,QAAQ,IAAI,EAwCd"}
|
package/_dist/tally.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A day's model requests, tallied: pure, over the rows a day's read returns
|
|
3
|
+
* (./day.ts). Each request is its entry: `usage`, the `cost` its provider
|
|
4
|
+
* reported or the hook weighed, and the `context_parts` the importer laid out
|
|
5
|
+
* (@yaks/session/parts). The fixed part it carries is spread over the pieces
|
|
6
|
+
* its session's `fixed` names; a request whose context was not recorded is one
|
|
7
|
+
* part, `unrecorded`. Dollars are weighed per part at the model's price, then
|
|
8
|
+
* scaled to what the provider reported where it did. Days add up (`merged`),
|
|
9
|
+
* so a week is its days.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/ import type { Bundle, Eid } from "@yaks/graph";
|
|
13
|
+
import type { Price } from "@yaks/model";
|
|
14
|
+
/** One day's tally, as `spend{…}` holds it. */ export type Spend = {
|
|
15
|
+
day: string;
|
|
16
|
+
requests: number;
|
|
17
|
+
/** [read, write, fresh, generated] */ tokens: number[];
|
|
18
|
+
dollars: number;
|
|
19
|
+
/** by part: [read, write, fresh, generated, dollars] */ parts: Record<string, number[]>;
|
|
20
|
+
/** by session: [tokens, dollars, requests] */ sessions: Record<Eid, number[]>;
|
|
21
|
+
/** by task: [tokens, dollars] */ tasks: Record<Eid, number[]>;
|
|
22
|
+
/** by model: [read, write, fresh, generated, dollars, requests] */ models: Record<Eid, number[]>;
|
|
23
|
+
/** by entry: [tokens, dollars] */ entries: Record<Eid, number[]>;
|
|
24
|
+
/** by the account whose plan the requests billed against: what they ran
|
|
25
|
+
* up on it */ plans: Record<Eid, Plan>;
|
|
26
|
+
/** the models a request was weighed with no price for, and reported no
|
|
27
|
+
* dollars: their dollars are missing, not zero */ unpriced: Eid[];
|
|
28
|
+
};
|
|
29
|
+
/** The rows a tally ranks. */ export type Rows = 'parts' | 'sessions' | 'tasks' | 'models' | 'entries';
|
|
30
|
+
/** What one plan's requests ran up: their dollars, and each row's. */ export type Plan = {
|
|
31
|
+
dollars: number;
|
|
32
|
+
unpriced?: Eid[];
|
|
33
|
+
/** by model, by session: what a limit on one model's requests counts */ metered?: Record<Eid, Record<Eid, number>>;
|
|
34
|
+
} & Record<Rows, Record<string, number>>;
|
|
35
|
+
/** What a tally reads beside its requests. */ export type Known = {
|
|
36
|
+
/** each model's price, by its eid */ prices: Map<Eid, Price>;
|
|
37
|
+
/** each session's fixed part, piece by piece (@yaks/session `fixed`) */ fixed: Map<Eid, Record<string, number>>;
|
|
38
|
+
/** the tasks each session worked on */ tasks: Map<Eid, Eid[]>;
|
|
39
|
+
/** the account whose plan each request billed against, where one did */ plans?: Map<Eid, Eid>;
|
|
40
|
+
};
|
|
41
|
+
/** How many entries a tally names. */ export declare let ENTRIES: number;
|
|
42
|
+
/** An empty day. */ export declare let empty: (day: string) => Spend;
|
|
43
|
+
/**
|
|
44
|
+
* One day's tally of its requests.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { tally } from './tally.ts'
|
|
48
|
+
* import { equal } from '@yaks/testing'
|
|
49
|
+
*
|
|
50
|
+
* let ask = {
|
|
51
|
+
* entity: { eid: 'a' },
|
|
52
|
+
* entry: { session: 's' },
|
|
53
|
+
* ask: { to: 'm' },
|
|
54
|
+
* usage: { input_tokens: 2e6, cached_tokens: 1e6, output_tokens: 0 },
|
|
55
|
+
* context_parts: { parts: { fixed: [1e6, 0, 0, 0], input: [0, 0, 1e6, 0] } },
|
|
56
|
+
* }
|
|
57
|
+
* let t = tally('2026-10-20', [ask], {
|
|
58
|
+
* prices: new Map([['m', { input: 4, cached: 0.2, output: 20 }]]),
|
|
59
|
+
* fixed: new Map([['s', { 'tool Read': 3, skills: 1 }]]),
|
|
60
|
+
* tasks: new Map([['s', ['T-1', 'T-2']]]),
|
|
61
|
+
* plans: new Map([['a', 'claude']]),
|
|
62
|
+
* })
|
|
63
|
+
* equal(t.dollars, 4.2)
|
|
64
|
+
* equal([t.plans.claude.dollars, t.plans.claude.tasks], [4.2, { 'T-1': 2.1, 'T-2': 2.1 }])
|
|
65
|
+
* equal(t.plans.claude.metered, { m: { s: 4.2 } })
|
|
66
|
+
* equal(t.parts, {
|
|
67
|
+
* 'tool Read': [750000, 0, 0, 0, 0.15],
|
|
68
|
+
* skills: [250000, 0, 0, 0, 0.05],
|
|
69
|
+
* input: [0, 0, 1000000, 0, 4],
|
|
70
|
+
* })
|
|
71
|
+
* equal(t.tasks, { 'T-1': [1e6, 2.1], 'T-2': [1e6, 2.1] })
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* A model with no price, whose request reported no dollars, is named as
|
|
75
|
+
* unpriced, on the day and on its plan:
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { tally } from './tally.ts'
|
|
79
|
+
* import { equal } from '@yaks/testing'
|
|
80
|
+
*
|
|
81
|
+
* let ask = {
|
|
82
|
+
* entity: { eid: 'a' },
|
|
83
|
+
* entry: { session: 's' },
|
|
84
|
+
* ask: { to: 'free' },
|
|
85
|
+
* usage: { input_tokens: 10, output_tokens: 5 },
|
|
86
|
+
* }
|
|
87
|
+
* let t = tally('2026-10-20', [ask], {
|
|
88
|
+
* prices: new Map(),
|
|
89
|
+
* fixed: new Map(),
|
|
90
|
+
* tasks: new Map(),
|
|
91
|
+
* plans: new Map([['a', 'codex']]),
|
|
92
|
+
* })
|
|
93
|
+
* equal([t.dollars, t.unpriced, t.plans.codex.unpriced], [0, ['free'], ['free']])
|
|
94
|
+
* ```
|
|
95
|
+
*/ export declare let tally: (day: string, rows: Bundle[], known: Known) => Spend;
|
|
96
|
+
/**
|
|
97
|
+
* Days added up, as one tally named by the first.
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { empty, merged } from './tally.ts'
|
|
101
|
+
* import { equal } from '@yaks/testing'
|
|
102
|
+
*
|
|
103
|
+
* let a = { ...empty('2026-10-20'), requests: 2, dollars: 1, parts: { skills: [1, 0, 0, 0, 1] } }
|
|
104
|
+
* let b = { ...empty('2026-10-21'), requests: 1, dollars: 2, parts: { skills: [2, 0, 0, 0, 2] } }
|
|
105
|
+
* let m = merged([a, b])
|
|
106
|
+
* equal([m.day, m.requests, m.dollars, m.parts], ['2026-10-20', 3, 3, { skills: [3, 0, 0, 0, 3] }])
|
|
107
|
+
* ```
|
|
108
|
+
*/ export declare let merged: (days: Spend[]) => Spend;
|
|
109
|
+
/** A tally's rows, costliest first, by the number at `at`. */ export declare let ranked: (m: Record<string, number[]>, at: number) => [string, number[]][];
|
|
110
|
+
/** The spend a row holds, as a tally. */ export declare let spendOf: (b: Bundle | undefined) => Spend | undefined;
|
|
111
|
+
//# sourceMappingURL=tally.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tally.d.ts","sources":["../tally.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GACD,cAAc,MAAM,EAAQ,GAAG,2BAAgC;AAC/D,cAAoB,KAAK,2BAAuC;AAGhE,6CAA6C,GAC7C,YAAY;EACV,KAAK,MAAM;EACX,UAAU,MAAM;EAChB,oCAAoC,GACpC,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,sDAAsD,GACtD,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B,4CAA4C,GAC5C,UAAU,OAAO,KAAK,MAAM;EAC5B,+BAA+B,GAC/B,OAAO,OAAO,KAAK,MAAM;EACzB,iEAAiE,GACjE,QAAQ,OAAO,KAAK,MAAM;EAC1B,gCAAgC,GAChC,SAAS,OAAO,KAAK,MAAM;EAC3B;cACY,GACZ,OAAO,OAAO,KAAK;EACnB;kDACgD,GAChD,UAAU;;AAGZ,4BAA4B,GAC5B,YAAY,OAAO,UAAU,aAAa,UAAU,WAAW;AAE/D,oEAAoE,GACpE,YAAY;EAER,SAAS,MAAM;EACf,WAAW;EACX,sEAAsE,GACtE,UAAU,OAAO,KAAK,OAAO,KAAK,MAAM;IAExC,OACA,MACA,OAAO,MAAM,EAAE,MAAM;AAKzB,4CAA4C,GAC5C,YAAY;EACV,mCAAmC,GACnC,QAAQ,IAAI,KAAK;EACjB,sEAAsE,GACtE,OAAO,IAAI,KAAK,OAAO,MAAM,EAAE,MAAM;EACrC,qCAAqC,GACrC,OAAO,IAAI,KAAK;EAChB,sEAAsE,GACtE,QAAQ,IAAI,KAAK;;AAGnB,oCAAoC,GACpC,OAAO,YAAI,gBAAY;AAKvB,kBAAkB,GAClB,OAAO,YAAI,QAAS,KAAK,MAAM,KAAG,MAYhC;AAoEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDC,GACD,OAAO,YAAI,QAAS,KAAK,MAAM,EAAE,MAAM,UAAU,OAAO,UAAQ,MA8D/D;AAmDD;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,SAAU,MAAM,YAAU,MAuBpC;AAED,4DAA4D,GAC5D,OAAO,YAAI,SACT,GAAG,OAAO,MAAM,EAAE,MAAM,KACxB,IAAI,MAAM,MACR,MAAM,EAAE,MAAM,MACmD;AAErE,uCAAuC,GACvC,OAAO,YAAI,UAAW,GAAG,SAAS,SAAS,KAAG,QAAQ,SAAS,CAG9D"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools: `spend_show` reports a span of days from their tallies,
|
|
3
|
+
* `spend_tally` tallies days again from the requests the graph holds, and
|
|
4
|
+
* `spend_backfill` measures past requests (@yaks/session, @yaks/spawn
|
|
5
|
+
* `recounted`) first. `shared` reads each topic's share of
|
|
6
|
+
* the week against what its sessions used (./use.ts).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/ import type { Eid, Graph } from "@yaks/graph";
|
|
10
|
+
import type { Runs } from "@yaks/graph/tools";
|
|
11
|
+
import { type Spend } from "./tally.js";
|
|
12
|
+
import { type Use } from "./use.js";
|
|
13
|
+
import { type Limit } from "./window.js";
|
|
14
|
+
export type { Billed, Use } from "./use.js";
|
|
15
|
+
export declare let read: (g: Graph, since?: string, until?: string, now?: number) => Promise<{
|
|
16
|
+
spend: Spend;
|
|
17
|
+
limits: Limit[];
|
|
18
|
+
rate: Map<Eid, number>;
|
|
19
|
+
accounts: Map<Eid, string>;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** Each topic's share of the week against what its sessions, and every
|
|
24
|
+
* session they started, used of each plan's running week: a topic before the
|
|
25
|
+
* topics below it, then the work no share covers ({@link uses}). Read from
|
|
26
|
+
* the tallies at `now`; where no topic has a share, nothing is read. */ export declare let shared: (g: Graph, now?: number) => Promise<Use[]>;
|
|
27
|
+
/** The cost per completed task in each UTC week (Monday to Sunday) from the
|
|
28
|
+
* one `since` falls in to `until`'s: the dollars every tally to `until`
|
|
29
|
+
* charged the tasks completed that week, over those of them charged any, as
|
|
30
|
+
* cash and as usage at list price, never one total. Decisions are not counted.
|
|
31
|
+
* The charge is the tally's `tasks` split, an estimate. */ export declare let perTask: (g: Graph, since: string, until: string) => Promise<string>;
|
|
32
|
+
/** A span's report, as text. */ export declare let report: (g: Graph, o?: {
|
|
33
|
+
since?: string;
|
|
34
|
+
until?: string;
|
|
35
|
+
top?: number;
|
|
36
|
+
now?: number;
|
|
37
|
+
plans?: boolean;
|
|
38
|
+
done?: boolean;
|
|
39
|
+
}) => Promise<string>;
|
|
40
|
+
/** Read in each transcript written since `since` that the graph has not
|
|
41
|
+
* read to its end, measure what was written since then again, then tally
|
|
42
|
+
* each day. What `person` typed is signed with them. */ export declare let backfill: (g: Graph, since: string, now?: number, person?: Eid) => Promise<string>;
|
|
43
|
+
/** Tally each day from `since` to today again from the requests the graph
|
|
44
|
+
* holds, measuring nothing: what a changed price or plan needs to show
|
|
45
|
+
* before the duty's next pass. Says what it tallied. */ export declare let tallied: (g: Graph, since: string, now?: number) => Promise<string>;
|
|
46
|
+
/** The tools this package runs; a transcript read in is signed with the
|
|
47
|
+
* config's `person`. */ export declare let runs: (host?: {
|
|
48
|
+
config?: {
|
|
49
|
+
person?: string;
|
|
50
|
+
};
|
|
51
|
+
}) => Runs;
|
|
52
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,cAAsB,GAAG,EAAE,KAAK,2BAAgC;AAIhE,cAAc,IAAI,iCAAsC;AAIxD,SAA+B,KAAK,KAAK,qBAA6B;AACtE,SAA0B,KAAK,GAAG,mBAAwB;AAC1D,SAKE,KAAK,KAAK,sBAQQ;AAGpB,cAAc,MAAM,EAAE,GAAG,mBAAkB;AAY3C,OAAO,YAAI,OACT,GAAG,OACH,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,MAAK,MAAM,KACV;EAEC,OAAO;EACP,QAAQ;EACR,MAAM,IAAI,KAAK,MAAM;EACrB,UAAU,IAAI,KAAK,MAAM;EACzB,MAAM,MAAM;EACZ,IAAI,MAAM;GAiBb;AAoBD;;;sEAGsE,GACtE,OAAO,YAAI,SACT,GAAG,OACH,MAAK,MAAM,KACV,QAAQ,OAqBV;AAoBD;;;;yDAIyD,GACzD,OAAO,YAAI,UACT,GAAG,OACH,OAAO,MAAM,EACb,OAAO,MAAM,KACZ,QAAQ,MAAM,EA4BhB;AAED,8BAA8B,GAC9B,OAAO,YAAI,SACT,GAAG,OACH;EACE,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,QAAQ,OAAO;EACf,OAAO,OAAO;MAEf,QAAQ,MAAM,EA+FhB;AAED;;sDAEsD,GACtD,OAAO,YAAI,WACT,GAAG,OACH,OAAO,MAAM,EACb,MAAK,MAAM,EACX,SAAS,QACR,QAAQ,MAAM,EAOhB;AAED;;sDAEsD,GACtD,OAAO,YAAI,UACT,GAAG,OACH,OAAO,MAAM,EACb,MAAK,MAAM,KACV,QAAQ,MAAM,EAQhB;AAED;sBACsB,GACtB,OAAO,YAAI,OAAQ;EAAS;IAAW,SAAS,MAAM;;MAAO,KA6B3D"}
|