@moderniser/plugin 0.1.6 → 0.1.7
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/dist/index.js +36 -7
- 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 =
|
|
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 =
|
|
237
|
+
const key = resolveKey();
|
|
214
238
|
if (!key)
|
|
215
239
|
return {};
|
|
216
240
|
try {
|
|
@@ -239,8 +263,12 @@ 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 = {
|
|
269
|
+
...product.contextWindow ? { context: product.contextWindow } : {},
|
|
270
|
+
...product.maxOutputTokens ? { output: product.maxOutputTokens } : {}
|
|
271
|
+
};
|
|
244
272
|
const models = {
|
|
245
273
|
emm: {
|
|
246
274
|
name: "Enterprise Modernisation Model",
|
|
@@ -248,7 +276,8 @@ var ModerniserPlugin = async () => {
|
|
|
248
276
|
reasoning: true,
|
|
249
277
|
modalities,
|
|
250
278
|
variants: Object.fromEntries(efforts.map((effort) => [effort, { reasoning_effort: effort }])),
|
|
251
|
-
...
|
|
279
|
+
...Object.keys(limit).length ? { limit } : {},
|
|
280
|
+
...prices ? { cost: prices } : {}
|
|
252
281
|
}
|
|
253
282
|
};
|
|
254
283
|
const key = KEY();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moderniser/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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",
|