{"_id":"@brglng/pi-currency-cost","_rev":"4-7a46579b63cf1b14624835c132444461","name":"@brglng/pi-currency-cost","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.0":{"name":"@brglng/pi-currency-cost","version":"0.1.0","keywords":["pi-package","pi","pi-extension","pi-coding-agent","coding-agent","currency","cost","usd","conversion","exchange-rate"],"author":{"name":"brglng"},"license":"MPL-2.0","_id":"@brglng/pi-currency-cost@0.1.0","maintainers":[{"name":"brglng","email":"brglng@gmail.com"}],"homepage":"https://github.com/brglng/pi-packages/tree/main/packages/pi-currency-cost#readme","bugs":{"url":"https://github.com/brglng/pi-packages/issues"},"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"1a94046dfdaa4c608e866ae53ca48bf64f825513","tarball":"https://registry.npmjs.org/@brglng/pi-currency-cost/-/pi-currency-cost-0.1.0.tgz","fileCount":13,"integrity":"sha512-yEECRQV/30E+UbTz9ky58gnPj7efNzG+94Os6NJqU5zaTPWG2WIj9BtHcH5jl7duY98GDbyJnbgn5zULtbFv5A==","signatures":[{"sig":"MEQCIHwPPAHPMQd0rIBlA+aAaYLclyXdhFLvUGD322uCod0GAiAbJP85U56u6BHA/fCl94icB9SaKNaOdvKftv8KG/jfDw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":72372},"type":"module","engines":{"node":">=22"},"exports":{".":{"types":"./dist/public.d.ts","default":"./src/index.ts"}},"scripts":{"lint":"biome check . && pnpm run lint:md","test":"vitest run","check":"tsc --noEmit","lint:md":"rumdl check *.md","build:types":"rollup -c rollup.dts.config.mjs"},"_npmUser":{"name":"brglng","email":"brglng@gmail.com"},"repository":{"url":"git+https://github.com/brglng/pi-packages.git","type":"git","directory":"packages/pi-currency-cost"},"description":"Convert configured provider/model usage costs to USD for Pi sessions","directories":{},"_nodeVersion":"26.7.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rumdl":"^0.2.10","rollup":"^4.62.2","vitest":"^4.1.8","typescript":"^6.0.3","@types/node":"^22.15.3","@biomejs/biome":"^2.4.16","rollup-plugin-dts":"^6.4.1","@earendil-works/pi-coding-agent":"0.83.0"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.79.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-currency-cost_0.1.0_1787193528366_0.5584870368613304","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@brglng/pi-currency-cost","version":"0.1.1","keywords":["pi-package","pi","pi-extension","pi-coding-agent","coding-agent","currency","cost","usd","conversion","exchange-rate"],"author":{"name":"brglng"},"license":"MPL-2.0","_id":"@brglng/pi-currency-cost@0.1.1","maintainers":[{"name":"brglng","email":"brglng@gmail.com"}],"homepage":"https://github.com/brglng/pi-currency-cost#readme","bugs":{"url":"https://github.com/brglng/pi-currency-cost/issues"},"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"c5524ed0bc973a84d0b201db4e9af0894be5df8c","tarball":"https://registry.npmjs.org/@brglng/pi-currency-cost/-/pi-currency-cost-0.1.1.tgz","fileCount":13,"integrity":"sha512-iCu6HhIPLt+30nmTl8xy284tPJvHgV7neslCLyOFOrqwXLdVk5Zc3n/PftYGIjn0WWvmQIYAn10rr7v9/b4ZEg==","signatures":[{"sig":"MEUCIC9kXp+quYxrPEyLMzAbYbHcrcXvDUGp9VbAUB9HrNYVAiEAuChZ1YlWpDxi3WwpLLEQmI7u4wPOD6ZDH4b44bLS/f8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":72324},"type":"module","engines":{"node":">=22"},"exports":{".":{"types":"./dist/public.d.ts","default":"./src/index.ts"}},"gitHead":"42ea9323ed0fd42429250dd3162cc471d05ce4e9","scripts":{"lint":"biome check . && pnpm run lint:md","test":"vitest run","check":"tsc --noEmit","lint:md":"rumdl check *.md","prepack":"pnpm run build:types","build:types":"rollup -c rollup.dts.config.mjs"},"_npmUser":{"name":"brglng","email":"brglng@gmail.com"},"repository":{"url":"git+https://github.com/brglng/pi-currency-cost.git","type":"git"},"_npmVersion":"11.19.0","description":"Convert configured provider/model usage costs to USD for Pi sessions","directories":{},"_nodeVersion":"26.7.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rumdl":"^0.2.10","rollup":"^4.62.2","vitest":"^4.1.8","typescript":"^6.0.3","@types/node":"^22.15.3","@biomejs/biome":"^2.4.16","rollup-plugin-dts":"^6.4.1","@earendil-works/pi-coding-agent":"0.83.0"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.79.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-currency-cost_0.1.1_1787920807973_0.6359055823369069","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@brglng/pi-currency-cost","version":"0.1.2","keywords":["pi-package","pi","pi-extension","pi-coding-agent","coding-agent","currency","cost","usd","conversion","exchange-rate"],"author":{"name":"brglng"},"license":"MPL-2.0","_id":"@brglng/pi-currency-cost@0.1.2","maintainers":[{"name":"brglng","email":"brglng@gmail.com"}],"homepage":"https://github.com/brglng/pi-currency-cost#readme","bugs":{"url":"https://github.com/brglng/pi-currency-cost/issues"},"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"7b5f7e39481954da59930b1efbc2db0e6adfec26","tarball":"https://registry.npmjs.org/@brglng/pi-currency-cost/-/pi-currency-cost-0.1.2.tgz","fileCount":13,"integrity":"sha512-UNISXV6eO6Y4ftM9F2YMU/Y08BM3zoH0mhyv5uhEwnJKfEWXr2/FR79WWGINIhar58W8q7Za/vh2oKOxfttMSQ==","signatures":[{"sig":"MEUCIEE35CPHElJyD/5iprlGWeHCFAUOOe5BhBdTwm/B8DRWAiEA2leFQaP0AxQgq4voXbyWx4Jk1wQj4/ZQNedNPYk0G40=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQCxzWJpdIJrbXnBr2ayN63T/M6pkwpv7lmxepzp3qtSPQIhALLBXC/fFyS8R1sAcNQD1N6wpSEqwBQg8hTiIlfx7JfG","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":72245},"type":"module","engines":{"node":">=22"},"exports":{".":{"types":"./dist/public.d.ts","default":"./src/index.ts"}},"scripts":{"lint":"biome check . && pnpm run lint:md","test":"vitest run","check":"tsc --noEmit","lint:md":"rumdl check *.md","build:types":"rollup -c rollup.dts.config.mjs"},"_npmUser":{"name":"brglng","email":"brglng@gmail.com"},"repository":{"url":"git+https://github.com/brglng/pi-currency-cost.git","type":"git"},"description":"Convert configured provider/model usage costs to USD for Pi sessions","directories":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rumdl":"^0.2.10","rollup":"^4.62.2","vitest":"^4.1.8","typescript":"^6.0.3","@types/node":"^22.15.3","@biomejs/biome":"^2.4.16","rollup-plugin-dts":"^6.4.1","@earendil-works/pi-coding-agent":"0.83.0"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.79.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-currency-cost_0.1.2_1789989598314_0.788526020994166","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"pi":{"extensions":["./src/index.ts"]},"_id":"@brglng/pi-currency-cost@0.1.3","bugs":{"url":"https://github.com/brglng/pi-currency-cost/issues"},"dist":{"shasum":"60d73a9b410eaed43d451e00d65664c1f292ba5b","tarball":"https://registry.npmjs.org/@brglng/pi-currency-cost/-/pi-currency-cost-0.1.3.tgz","fileCount":13,"integrity":"sha512-Vh+WVF5CFLCa1KmxhmfWWKiklUyVtPv2M+GC+KdlXJBMRFdyVufzSjCebCp9RtHvKbb9w556X/DG6aEU+CGQuA==","signatures":[{"sig":"MEYCIQCD1cye2BMhwWSMwP3+/qHP13khTKcaKv92m9B5IHUugQIhAKY4vaMoXBV1HFWisYyKxugBTP9KNjyHu67pb40PSer+","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGyJaXC5HNgNj34fJaMu+LErZgzsM6ShhQyPGWFczYT8AiEA9AFFnehfKWDCXLLI9oXbXQPyi8mv92rhbAErwehMRK8="}],"unpackedSize":72242},"name":"@brglng/pi-currency-cost","type":"module","author":{"name":"brglng"},"engines":{"node":">=22"},"exports":{".":{"types":"./dist/public.d.ts","default":"./src/index.ts"}},"license":"MPL-2.0","scripts":{"lint":"biome check . && pnpm run lint:md","test":"vitest run","check":"tsc --noEmit","lint:md":"rumdl check *.md","build:types":"rollup -c rollup.dts.config.mjs"},"version":"0.1.3","_npmUser":{"name":"brglng","email":"brglng@gmail.com"},"homepage":"https://github.com/brglng/pi-currency-cost#readme","keywords":["pi-package","pi","pi-extension","pi-coding-agent","coding-agent","currency","cost","usd","conversion","exchange-rate"],"repository":{"url":"git+https://github.com/brglng/pi-currency-cost.git","type":"git"},"description":"Convert configured provider/model usage costs to USD for Pi sessions","directories":{},"maintainers":[{"name":"brglng","email":"brglng@gmail.com"}],"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rumdl":"^0.2.10","rollup":"^4.62.2","vitest":"^4.1.8","typescript":"^6.0.3","@types/node":"^22.15.3","@biomejs/biome":"^2.4.16","rollup-plugin-dts":"^6.4.1","@earendil-works/pi-coding-agent":"0.83.0"},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.79.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-currency-cost_0.1.3_1790654420206_0.13970787306738752"}}},"time":{"created":"2026-08-20T02:38:48.231Z","modified":"2026-09-29T04:00:20.433Z","0.1.0":"2026-08-20T02:38:48.522Z","0.1.1":"2026-08-28T12:40:08.116Z","0.1.2":"2026-09-21T11:19:58.393Z","0.1.3":"2026-09-29T04:00:20.284Z"},"bugs":{"url":"https://github.com/brglng/pi-currency-cost/issues"},"author":{"name":"brglng"},"license":"MPL-2.0","homepage":"https://github.com/brglng/pi-currency-cost#readme","keywords":["pi-package","pi","pi-extension","pi-coding-agent","coding-agent","currency","cost","usd","conversion","exchange-rate"],"repository":{"url":"git+https://github.com/brglng/pi-currency-cost.git","type":"git"},"description":"Convert configured provider/model usage costs to USD for Pi sessions","maintainers":[{"name":"brglng","email":"brglng@gmail.com"}],"readme":"# @brglng/pi-currency-cost\n\n> For a Chinese version, see [README.zh.md](README.zh.md).\n\nA [Pi coding agent](https://pi.dev/) extension that converts configured\nprovider/model usage costs to USD on every finalized assistant message, so\nall costs and totals are shown in a single currency even when your providers\nbill in different currencies.\n\n## Installation\n\n```bash\npi install npm:@brglng/pi-currency-cost\n```\n\n## Configuration\n\nThe extension reads two optional JSON files and merges them, with the project\nfile taking precedence over the global file:\n\n- Global: `~/.pi/agent/extensions/pi-currency-cost/config.json`\n- Project: `<cwd>/.pi/extensions/pi-currency-cost/config.json`\n\n```json\n{\n  \"currencies\": {\n    \"CNY\": { \"usdRate\": 0.147 }\n  },\n  \"providers\": {\n    \"bailian\": { \"currency\": \"CNY\" }\n  },\n  \"rateSource\": { \"type\": \"frankfurter\" }\n}\n```\n\nA ready-to-edit template is provided in\n[`config/config.example.json`](config/config.example.json).\n\n### currencies\n\nAll rates are **USD per one unit of the source currency** (for example, 0.147\nUSD per 1 CNY). Every configured non-USD currency must provide a `usdRate`\n— a positive, finite number — before it can be converted. `usdRate` is the\nonly required field; conversion never happens without it:\n\n```json\n{\n  \"currencies\": {\n    \"CNY\": { \"usdRate\": 0.147 },\n    \"EUR\": { \"usdRate\": 1.083 }\n  }\n}\n```\n\n`usdRate` is the value used for conversion. When a fresh rate is fetched by\nthe extension, it is written back into this same field (along with `updatedAt`).\n\n### providers\n\nOnly the providers listed here are converted; any provider that is not listed\nis left untouched. Each entry names the currency Pi reports that provider's\nusage costs in, with optional per-model overrides on top:\n\n```json\n{\n  \"providers\": {\n    \"bailian\": { \"currency\": \"CNY\" },\n    \"my-gateway\": {\n      \"currency\": \"EUR\",\n      \"models\": {\n        \"euro-model\": { \"currency\": \"EUR\" },\n        \"usd-model\": { \"currency\": \"USD\" }\n      }\n    }\n  }\n}\n```\n\nA provider whose currency is `USD` (and any provider not listed) is left\nuntouched. A model with no override falls back to its provider's currency.\n\n### rateSource\n\nThe default is Frankfurter, a common reference-rate service:\n\n```json\n{\n  \"rateSource\": {\n    \"type\": \"frankfurter\"\n  }\n}\n```\n\nIf you prefer a mainland-China–oriented source, you can use Bank of China\ninstead:\n\n```json\n{\n  \"rateSource\": {\n    \"type\": \"boc\"\n  }\n}\n```\n\nBoth sources use bounded timeouts.\n\n## Commands\n\n- `/currency-cost status` shows the config paths, the active rate source,\n  each currency rate (including its update time), and the provider/model\n  currency mappings.\n- `/currency-cost refresh` fetches current USD rates for every configured\n  non-USD currency and saves them as `usdRate`.\n- `/currency-cost help` lists the available subcommands.\n\n## How conversion works\n\nOn every finalized assistant message, the extension converts the message's\ncost components — input, output, cache reads, and cache writes — from the\nconfigured source currency into USD, and recomputes the total from those\nconverted components. Session totals, status views, and history all end up in\nUSD. A message is converted at most once, so the same cost is never converted\ntwice.\n\nIf a mapped currency has no usable `usdRate`, the message is left in its\noriginal currency and a warning is shown.\n\n## Automatic updates\n\nAt the start of each session, the extension fetches the latest rate for every\nconfigured non-USD currency and saves it back to the same `usdRate` field, so\nconversion always uses the most recent rate the extension can obtain. You can\nalso trigger this manually at any time with `/currency-cost refresh`.\n\n## Network and fallback\n\nRate fetches require network access, which cannot be guaranteed in every\nenvironment. If a rate source is unreachable or times out, the extension does\nnot fail: the configured `usdRate` value is kept and stays in effect, and\nstartup is never blocked.\n\n## Limitations\n\nExchange rates are estimates, and the resulting USD figures may differ from\nwhat your provider actually bills. Pricing also changes over time and varies\nby provider, region, and plan, so treat converted costs as an approximation\nrather than an exact invoice.\n\n## License\n\nMPL-2.0\n","readmeFilename":""}