koishi-plugin-elysia-api-aggregator 0.2.0 → 0.2.1

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/lib/index.cjs CHANGED
@@ -39,7 +39,6 @@ var ModelFetcher = class {
39
39
  __name(this, "ModelFetcher");
40
40
  }
41
41
  async fetchModels(source) {
42
- this.ctx.logger.info(`Fetching models from ${source.name} (${source.platform})`);
43
42
  try {
44
43
  switch (source.platform) {
45
44
  case "openai":
@@ -280,32 +279,18 @@ function apply(ctx, config) {
280
279
  }
281
280
  };
282
281
  async function loadModels() {
283
- if (config.debugMode) {
284
- ctx.logger.info("=== loadModels: Starting to load models ===");
285
- } else {
286
- ctx.logger.info("Loading models...");
287
- }
282
+ const loadStartedAt = Date.now();
283
+ ctx.logger.info("Loading models...");
288
284
  const fetchedModels = [];
289
285
  for (const source of config.autoFetchSources) {
290
286
  if (!source.enabled) continue;
291
- if (config.debugMode) {
292
- ctx.logger.info(`loadModels: Fetching from ${source.name}`);
293
- }
287
+ const sourceStartedAt = Date.now();
294
288
  const sourceModels = await fetcher.fetchModels(source);
295
289
  fetchedModels.push(...sourceModels);
296
- if (config.debugMode) {
297
- ctx.logger.info(`loadModels: Fetched ${sourceModels.length} models from ${source.name}`);
298
- } else {
299
- ctx.logger.info(`Fetched ${sourceModels.length} models from ${source.name}`);
300
- }
301
- }
302
- if (config.debugMode) {
303
- ctx.logger.info(`loadModels: Processing ${config.manualModels.length} manual models`);
290
+ const sourceCostMs = Date.now() - sourceStartedAt;
291
+ ctx.logger.info(`[source] ${source.name}: ${sourceModels.length} models (${sourceCostMs}ms)`);
304
292
  }
305
293
  const manualModels = config.manualModels.map((m) => {
306
- if (config.debugMode) {
307
- ctx.logger.info(`loadModels: Adding manual model ${m.id}`);
308
- }
309
294
  return {
310
295
  id: m.id,
311
296
  name: m.name,
@@ -327,17 +312,9 @@ function apply(ctx, config) {
327
312
  });
328
313
  const allModels = [...fetchedModels, ...manualModels];
329
314
  service.updateModels(allModels);
330
- if (config.debugMode) {
331
- ctx.logger.info(`loadModels: Total models loaded: ${allModels.length}`);
332
- ctx.logger.info(`loadModels: Model IDs: ${allModels.map((m) => m.id).join(", ")}`);
333
- ctx.logger.info(`loadModels: ctx.elysiaApi exists: ${ctx.elysiaApi != null}`);
334
- ctx.logger.info(`loadModels: ctx.elysiaApi.models exists: ${ctx.elysiaApi?.models != null}`);
335
- } else {
336
- ctx.logger.info(`Total models loaded: ${allModels.length}`);
337
- }
338
- if (config.debugMode) {
339
- ctx.logger.info(`loadModels: Emitting elysia-api/models-updated event with ${allModels.length} models`);
340
- }
315
+ const totalCostMs = Date.now() - loadStartedAt;
316
+ ctx.logger.info(`[source] manual: ${manualModels.length} models`);
317
+ ctx.logger.info(`Total models loaded: ${allModels.length} (${totalCostMs}ms)`);
341
318
  ctx.emit("elysia-api/models-updated", [...allModels]);
342
319
  }
343
320
  __name(loadModels, "loadModels");
package/lib/index.mjs CHANGED
@@ -13,7 +13,6 @@ var ModelFetcher = class {
13
13
  __name(this, "ModelFetcher");
14
14
  }
15
15
  async fetchModels(source) {
16
- this.ctx.logger.info(`Fetching models from ${source.name} (${source.platform})`);
17
16
  try {
18
17
  switch (source.platform) {
19
18
  case "openai":
@@ -254,32 +253,18 @@ function apply(ctx, config) {
254
253
  }
255
254
  };
256
255
  async function loadModels() {
257
- if (config.debugMode) {
258
- ctx.logger.info("=== loadModels: Starting to load models ===");
259
- } else {
260
- ctx.logger.info("Loading models...");
261
- }
256
+ const loadStartedAt = Date.now();
257
+ ctx.logger.info("Loading models...");
262
258
  const fetchedModels = [];
263
259
  for (const source of config.autoFetchSources) {
264
260
  if (!source.enabled) continue;
265
- if (config.debugMode) {
266
- ctx.logger.info(`loadModels: Fetching from ${source.name}`);
267
- }
261
+ const sourceStartedAt = Date.now();
268
262
  const sourceModels = await fetcher.fetchModels(source);
269
263
  fetchedModels.push(...sourceModels);
270
- if (config.debugMode) {
271
- ctx.logger.info(`loadModels: Fetched ${sourceModels.length} models from ${source.name}`);
272
- } else {
273
- ctx.logger.info(`Fetched ${sourceModels.length} models from ${source.name}`);
274
- }
275
- }
276
- if (config.debugMode) {
277
- ctx.logger.info(`loadModels: Processing ${config.manualModels.length} manual models`);
264
+ const sourceCostMs = Date.now() - sourceStartedAt;
265
+ ctx.logger.info(`[source] ${source.name}: ${sourceModels.length} models (${sourceCostMs}ms)`);
278
266
  }
279
267
  const manualModels = config.manualModels.map((m) => {
280
- if (config.debugMode) {
281
- ctx.logger.info(`loadModels: Adding manual model ${m.id}`);
282
- }
283
268
  return {
284
269
  id: m.id,
285
270
  name: m.name,
@@ -301,17 +286,9 @@ function apply(ctx, config) {
301
286
  });
302
287
  const allModels = [...fetchedModels, ...manualModels];
303
288
  service.updateModels(allModels);
304
- if (config.debugMode) {
305
- ctx.logger.info(`loadModels: Total models loaded: ${allModels.length}`);
306
- ctx.logger.info(`loadModels: Model IDs: ${allModels.map((m) => m.id).join(", ")}`);
307
- ctx.logger.info(`loadModels: ctx.elysiaApi exists: ${ctx.elysiaApi != null}`);
308
- ctx.logger.info(`loadModels: ctx.elysiaApi.models exists: ${ctx.elysiaApi?.models != null}`);
309
- } else {
310
- ctx.logger.info(`Total models loaded: ${allModels.length}`);
311
- }
312
- if (config.debugMode) {
313
- ctx.logger.info(`loadModels: Emitting elysia-api/models-updated event with ${allModels.length} models`);
314
- }
289
+ const totalCostMs = Date.now() - loadStartedAt;
290
+ ctx.logger.info(`[source] manual: ${manualModels.length} models`);
291
+ ctx.logger.info(`Total models loaded: ${allModels.length} (${totalCostMs}ms)`);
315
292
  ctx.emit("elysia-api/models-updated", [...allModels]);
316
293
  }
317
294
  __name(loadModels, "loadModels");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-elysia-api-aggregator",
3
3
  "description": "Inspired by New-API, the Elysia-API model aggregator plugin allows automatic fetching and manual configuration of available AI models, designed to work with the orchestrator plugin.",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",