@moderniser/plugin 0.1.6 → 0.1.8

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,9 +10,6 @@ var stored;
10
10
  function setStoredKey(key) {
11
11
  stored = key;
12
12
  }
13
- function storedKey() {
14
- return stored;
15
- }
16
13
  function authFilePath() {
17
14
  const data = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
18
15
  return join(data, "moderniser", "auth.json");
@@ -192,7 +189,7 @@ var GATEWAY = () => {
192
189
  var PROVIDER_ID = "moderniser";
193
190
  var DEFAULT_MODEL = `${PROVIDER_ID}/emm`;
194
191
  async function call(path, body) {
195
- const key = KEY() ?? storedKey();
192
+ const key = resolveKey();
196
193
  if (!key)
197
194
  return null;
198
195
  try {
@@ -209,8 +206,35 @@ async function call(path, body) {
209
206
  function positiveInt(value) {
210
207
  return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
211
208
  }
209
+ function price(value) {
210
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
211
+ }
212
+ async function companyPrices() {
213
+ const key = resolveKey();
214
+ if (!key)
215
+ return;
216
+ try {
217
+ const res = await fetch(`${API2()}/billing/prices`, {
218
+ headers: { Authorization: `Bearer ${key}`, ...companyHeaders() },
219
+ signal: AbortSignal.timeout(5000)
220
+ });
221
+ if (!res.ok)
222
+ return;
223
+ const body = await res.json();
224
+ const input = price(body.inputUsdPerMtok);
225
+ const output = price(body.outputUsdPerMtok);
226
+ const cache_read = price(body.cachedInputUsdPerMtok);
227
+ const cache_write = price(body.cacheWriteUsdPerMtok);
228
+ if (input === undefined || output === undefined || cache_read === undefined || cache_write === undefined) {
229
+ return;
230
+ }
231
+ return { input, output, cache_read, cache_write };
232
+ } catch {
233
+ return;
234
+ }
235
+ }
212
236
  async function gatewayProduct() {
213
- const key = KEY() ?? storedKey();
237
+ const key = resolveKey();
214
238
  if (!key)
215
239
  return {};
216
240
  try {
@@ -239,8 +263,9 @@ var ModerniserPlugin = async () => {
239
263
  return {
240
264
  config: async (config) => {
241
265
  const modalities = { input: ["text", "image"], output: ["text"] };
242
- const product = await gatewayProduct();
266
+ const [product, prices] = await Promise.all([gatewayProduct(), companyPrices()]);
243
267
  const efforts = (product.efforts ?? ["high"]).filter((effort) => effort !== "default");
268
+ const limit = product.contextWindow !== undefined || product.maxOutputTokens !== undefined ? { context: product.contextWindow ?? 0, output: product.maxOutputTokens ?? 0 } : undefined;
244
269
  const models = {
245
270
  emm: {
246
271
  name: "Enterprise Modernisation Model",
@@ -248,7 +273,8 @@ var ModerniserPlugin = async () => {
248
273
  reasoning: true,
249
274
  modalities,
250
275
  variants: Object.fromEntries(efforts.map((effort) => [effort, { reasoning_effort: effort }])),
251
- ...product.contextWindow && product.maxOutputTokens ? { limit: { context: product.contextWindow, output: product.maxOutputTokens } } : {}
276
+ ...limit ? { limit } : {},
277
+ ...prices ? { cost: prices } : {}
252
278
  }
253
279
  };
254
280
  const key = KEY();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moderniser/plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "Moderniser plugin for opencode: points inference at the gateway, declares the Moderniser remote MCP server, and reports session telemetry",
6
6
  "license": "MIT",