@nijaru/pi-peak-hours 0.0.8 → 0.0.9
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/README.md +1 -1
- package/extensions/index.ts +4 -4
- package/extensions/request-pricing.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ A malformed field falls back to its default rather than disabling the extension;
|
|
|
111
111
|
- **Rate by provider invocation.** Pi providers timestamp each assistant message before preparing and sending its HTTP request. That timestamp selects the multiplier, not completion time or the shared payload hook. With the companion, active state and schedules are captured at request dispatch; without it, foreground fallback uses the configuration at `message_end`.
|
|
112
112
|
- **Scaled once.** Global weak identity guards protect usage and foreground message objects across loaded copies, retries, and returned replacements. Usage observed at dispatch remains handled even when its decision is unchanged (×1 or inactive), so fallback cannot overwrite it after a config change.
|
|
113
113
|
- **Shared ownership.** The client requests usage-only leases for covered available models and the current model, deduplicated by provider. The companion scopes callbacks to the owning session. Retired leases are reacquired on reconciliation; shutdown and SDK disposal remove only this client's leases. Neither catalogs nor unrelated provider slots are replaced.
|
|
114
|
-
- **Only cost moves.** The four cost fields are scaled and
|
|
114
|
+
- **Only cost moves.** The four catalog cost fields are scaled and estimated totals are recomputed from them. Provider-reported billed totals are preserved, including zero. Token counts are untouched, so rate-from-cost derivations stay self-consistent — including pi's cache-miss accounting, which derives its paid and read rates from the same message and scales with it.
|
|
115
115
|
- **Coverage.** Only requests observed by the companion's safe dispatcher receive request-wide correction. Unavailable models, unsupported provider registrations, and usage reported independently by tools can remain uncorrected. Without the companion, coverage is foreground assistant messages only. The default weekday schedule does not encode Chinese public holidays, which DeepSeek treats as off-peak; holiday costs can therefore be overstated.
|
|
116
116
|
|
|
117
117
|
## Stack
|
package/extensions/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* DeepSeek is the clearest example: a 2x multiplier applies during peak windows
|
|
5
5
|
* (01:00-04:00 and 06:00-10:00 UTC, Monday-Friday, as of September 2026) and the
|
|
6
6
|
* off-peak rate is half of it. pi has no notion of time-of-day pricing —
|
|
7
|
-
* `usage.cost`
|
|
7
|
+
* `usage.cost` component estimates use the model's flat rates when usage is
|
|
8
8
|
* finalized — so a session is over- or understated by up to 2x, in whichever
|
|
9
9
|
* direction the recorded rate sits from the billed one.
|
|
10
10
|
*
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
* instead of correcting it.
|
|
47
47
|
* - A message is never scaled twice. Retries and overflow recovery can deliver
|
|
48
48
|
* the same message object again, so adjustments are guarded by identity.
|
|
49
|
-
* -
|
|
50
|
-
*
|
|
49
|
+
* - Scale catalog cost fields and recompute estimated totals; preserve
|
|
50
|
+
* provider-reported billed totals, including zero. Token counts are never
|
|
51
51
|
* modified, so any rate derived from cost/tokens stays self-consistent
|
|
52
52
|
* (cache-miss accounting derives paid and read rates from the same message
|
|
53
53
|
* and scales with it).
|
|
54
54
|
* - Unknown or malformed configuration falls back to the defaults with a
|
|
55
55
|
* warning; no path throws from a message handler.
|
|
56
56
|
*
|
|
57
|
-
*
|
|
57
|
+
* Scheduled rates remain estimates, not invoices: server arrival, Chinese public
|
|
58
58
|
* holidays, and usage outside observed provider requests are not modeled.
|
|
59
59
|
*/
|
|
60
60
|
|
|
@@ -36,7 +36,7 @@ export function applyMultiplier(cost: Usage["cost"], multiplier: number): Usage[
|
|
|
36
36
|
cacheRead: cost.cacheRead * multiplier,
|
|
37
37
|
cacheWrite: cost.cacheWrite * multiplier,
|
|
38
38
|
};
|
|
39
|
-
scaled.total = scaled.input + scaled.output + scaled.cacheRead + scaled.cacheWrite;
|
|
39
|
+
if (cost.totalFromProvider !== true) scaled.total = scaled.input + scaled.output + scaled.cacheRead + scaled.cacheWrite;
|
|
40
40
|
return scaled;
|
|
41
41
|
}
|
|
42
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nijaru/pi-peak-hours",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Correct pi's recorded cost for providers that bill by time of day, with a peak multiplier in the footer status.",
|
|
6
6
|
"keywords": [
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"check": "bun test && oxlint extensions/ tests/ && tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@earendil-works/pi-ai": "1.
|
|
38
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
37
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
38
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
39
39
|
"@types/bun": "latest",
|
|
40
40
|
"oxlint": "latest",
|
|
41
41
|
"typescript": "^6.0.3"
|