fix(omp): avoid unsupported calculateCost import
Fix OMP installation by removing the unsupported calculateCost runtime import from pi-ai.
This commit is contained in:
+19
@@ -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
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user