fix(omp): avoid unsupported calculateCost import

Fix OMP installation by removing the unsupported calculateCost runtime import from pi-ai.
This commit is contained in:
Patrick Wozniak
2026-07-05 03:10:02 +02:00
committed by GitHub
parent 0f6fc17816
commit e123e84116
7 changed files with 135 additions and 4 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
* Local cost calculation for Command Code usage.
*
* Mirrors pi-ai's `calculateCost` arithmetic exactly. The provider ships its
* own copy because Oh My Pi's legacy pi-ai shim does not export
* `calculateCost`, which broke extension installation there (issue #24).
* `tests/test-cost.ts` locks this implementation to the pi-ai original.
*/
import type { ModelLike, Usage } from "./types.ts"
export function calculateCommandCodeCost(model: ModelLike, usage: Usage): void {
usage.cost.input = (model.cost.input / 1_000_000) * usage.input
usage.cost.output = (model.cost.output / 1_000_000) * usage.output
usage.cost.cacheRead = (model.cost.cacheRead / 1_000_000) * usage.cacheRead
usage.cost.cacheWrite = (model.cost.cacheWrite / 1_000_000) * usage.cacheWrite
usage.cost.total =
usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite
}
+8
View File
@@ -50,11 +50,19 @@ export interface AssistantMessageLike {
timestamp: number
}
export interface ModelCost {
input: number
output: number
cacheRead: number
cacheWrite: number
}
export interface ModelLike {
id: string
api: unknown
provider: string
maxTokens: number
cost: ModelCost
}
export interface MessageLike {