koishi-plugin-chatluna-google-gemini-adapter 1.2.15 → 1.2.16

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/client.d.ts CHANGED
@@ -1,18 +1,17 @@
1
1
  import { Context } from 'koishi';
2
2
  import { PlatformModelAndEmbeddingsClient } from 'koishi-plugin-chatluna/llm-core/platform/client';
3
3
  import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
4
- import { ChatHubBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
4
+ import { ChatLunaBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
5
5
  import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
6
6
  import { Config } from '.';
7
7
  import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
8
- export declare class GeminiClient extends PlatformModelAndEmbeddingsClient {
8
+ export declare class GeminiClient extends PlatformModelAndEmbeddingsClient<ClientConfig> {
9
9
  private _config;
10
+ plugin: ChatLunaPlugin;
10
11
  platform: string;
11
12
  private _requester;
12
- private _models;
13
- constructor(ctx: Context, _config: Config, clientConfig: ClientConfig, plugin: ChatLunaPlugin);
14
- init(): Promise<void>;
13
+ get logger(): import("reggol");
14
+ constructor(ctx: Context, _config: Config, plugin: ChatLunaPlugin);
15
15
  refreshModels(): Promise<ModelInfo[]>;
16
- getModels(): Promise<ModelInfo[]>;
17
- protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
16
+ protected _createModel(model: string): ChatLunaChatModel | ChatLunaBaseEmbeddings;
18
17
  }
package/lib/index.cjs CHANGED
@@ -37,7 +37,7 @@ var require_en_US_schema = __commonJS({
37
37
  // src/index.ts
38
38
  var index_exports = {};
39
39
  __export(index_exports, {
40
- Config: () => Config3,
40
+ Config: () => Config4,
41
41
  apply: () => apply,
42
42
  inject: () => inject,
43
43
  logger: () => logger,
@@ -318,16 +318,14 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
318
318
 
319
319
  // src/requester.ts
320
320
  var GeminiRequester = class extends import_api.ModelRequester {
321
- constructor(_config, _plugin, _pluginConfig) {
322
- super();
323
- this._config = _config;
324
- this._plugin = _plugin;
321
+ constructor(ctx, _configPool, _pluginConfig, _plugin) {
322
+ super(ctx, _configPool, _pluginConfig, _plugin);
325
323
  this._pluginConfig = _pluginConfig;
326
324
  }
327
325
  static {
328
326
  __name(this, "GeminiRequester");
329
327
  }
330
- async *completionStream(params) {
328
+ async *completionStreamInternal(params) {
331
329
  try {
332
330
  let model = params.model;
333
331
  let enabledThinking = null;
@@ -634,7 +632,7 @@ ${groundingContent}`
634
632
  });
635
633
  }
636
634
  _concatUrl(url) {
637
- const apiEndPoint = this._config.apiEndpoint;
635
+ const apiEndPoint = this._config.value.apiEndpoint;
638
636
  let baseURL;
639
637
  if (apiEndPoint.endsWith("/")) {
640
638
  baseURL = new URL(apiEndPoint + url);
@@ -642,31 +640,32 @@ ${groundingContent}`
642
640
  baseURL = new URL(apiEndPoint + "/" + url);
643
641
  }
644
642
  const searchParams = baseURL.searchParams;
645
- searchParams.set("key", this._config.apiKey);
643
+ searchParams.set("key", this._config.value.apiKey);
646
644
  return baseURL.toString();
647
645
  }
648
646
  _buildHeaders() {
649
647
  return {
650
- /* Authorization: `Bearer ${this._config.apiKey}`, */
648
+ /* Authorization: `Bearer ${this._config.value.apiKey}`, */
651
649
  "Content-Type": "application/json"
652
650
  };
653
651
  }
654
- async init() {
655
- }
656
- async dispose() {
652
+ get logger() {
653
+ return logger;
657
654
  }
658
655
  };
659
656
 
660
657
  // src/client.ts
661
658
  var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient {
662
- constructor(ctx, _config, clientConfig, plugin) {
663
- super(ctx, clientConfig);
659
+ constructor(ctx, _config, plugin) {
660
+ super(ctx, plugin.platformConfigPool);
664
661
  this._config = _config;
665
- this.platform = this.config.platform;
662
+ this.plugin = plugin;
663
+ this.platform = this._config.platform;
666
664
  this._requester = new GeminiRequester(
667
- clientConfig,
668
- plugin,
669
- this._config
665
+ ctx,
666
+ plugin.platformConfigPool,
667
+ this._config,
668
+ plugin
670
669
  );
671
670
  }
672
671
  static {
@@ -674,9 +673,8 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
674
673
  }
675
674
  platform = "gemini";
676
675
  _requester;
677
- _models;
678
- async init() {
679
- await this.getModels();
676
+ get logger() {
677
+ return logger;
680
678
  }
681
679
  async refreshModels() {
682
680
  try {
@@ -715,18 +713,8 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
715
713
  throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_INIT_ERROR, e);
716
714
  }
717
715
  }
718
- async getModels() {
719
- if (this._models && Object.keys(this._models).length > 0) {
720
- return Object.values(this._models);
721
- }
722
- const models = await this.refreshModels();
723
- this._models = {};
724
- for (const model of models) {
725
- this._models[model.name] = model;
726
- }
727
- }
728
716
  _createModel(model) {
729
- const info = this._models[model];
717
+ const info = this._modelInfos[model];
730
718
  if (info == null) {
731
719
  throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_NOT_FOUND);
732
720
  }
@@ -773,14 +761,12 @@ function apply(ctx, config) {
773
761
  };
774
762
  });
775
763
  });
776
- plugin.registerClient(
777
- (_, clientConfig) => new GeminiClient(ctx, config, clientConfig, plugin)
778
- );
764
+ plugin.registerClient((ctx2) => new GeminiClient(ctx2, config, plugin));
779
765
  await plugin.initClients();
780
766
  });
781
767
  }
782
768
  __name(apply, "apply");
783
- var Config3 = import_koishi.Schema.intersect([
769
+ var Config4 = import_koishi.Schema.intersect([
784
770
  import_chat.ChatLunaPlugin.Config,
785
771
  import_koishi.Schema.object({
786
772
  platform: import_koishi.Schema.string().default("gemini"),
package/lib/index.mjs CHANGED
@@ -311,16 +311,14 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
311
311
 
312
312
  // src/requester.ts
313
313
  var GeminiRequester = class extends ModelRequester {
314
- constructor(_config, _plugin, _pluginConfig) {
315
- super();
316
- this._config = _config;
317
- this._plugin = _plugin;
314
+ constructor(ctx, _configPool, _pluginConfig, _plugin) {
315
+ super(ctx, _configPool, _pluginConfig, _plugin);
318
316
  this._pluginConfig = _pluginConfig;
319
317
  }
320
318
  static {
321
319
  __name(this, "GeminiRequester");
322
320
  }
323
- async *completionStream(params) {
321
+ async *completionStreamInternal(params) {
324
322
  try {
325
323
  let model = params.model;
326
324
  let enabledThinking = null;
@@ -627,7 +625,7 @@ ${groundingContent}`
627
625
  });
628
626
  }
629
627
  _concatUrl(url) {
630
- const apiEndPoint = this._config.apiEndpoint;
628
+ const apiEndPoint = this._config.value.apiEndpoint;
631
629
  let baseURL;
632
630
  if (apiEndPoint.endsWith("/")) {
633
631
  baseURL = new URL(apiEndPoint + url);
@@ -635,31 +633,32 @@ ${groundingContent}`
635
633
  baseURL = new URL(apiEndPoint + "/" + url);
636
634
  }
637
635
  const searchParams = baseURL.searchParams;
638
- searchParams.set("key", this._config.apiKey);
636
+ searchParams.set("key", this._config.value.apiKey);
639
637
  return baseURL.toString();
640
638
  }
641
639
  _buildHeaders() {
642
640
  return {
643
- /* Authorization: `Bearer ${this._config.apiKey}`, */
641
+ /* Authorization: `Bearer ${this._config.value.apiKey}`, */
644
642
  "Content-Type": "application/json"
645
643
  };
646
644
  }
647
- async init() {
648
- }
649
- async dispose() {
645
+ get logger() {
646
+ return logger;
650
647
  }
651
648
  };
652
649
 
653
650
  // src/client.ts
654
651
  var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
655
- constructor(ctx, _config, clientConfig, plugin) {
656
- super(ctx, clientConfig);
652
+ constructor(ctx, _config, plugin) {
653
+ super(ctx, plugin.platformConfigPool);
657
654
  this._config = _config;
658
- this.platform = this.config.platform;
655
+ this.plugin = plugin;
656
+ this.platform = this._config.platform;
659
657
  this._requester = new GeminiRequester(
660
- clientConfig,
661
- plugin,
662
- this._config
658
+ ctx,
659
+ plugin.platformConfigPool,
660
+ this._config,
661
+ plugin
663
662
  );
664
663
  }
665
664
  static {
@@ -667,9 +666,8 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
667
666
  }
668
667
  platform = "gemini";
669
668
  _requester;
670
- _models;
671
- async init() {
672
- await this.getModels();
669
+ get logger() {
670
+ return logger;
673
671
  }
674
672
  async refreshModels() {
675
673
  try {
@@ -708,18 +706,8 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
708
706
  throw new ChatLunaError2(ChatLunaErrorCode2.MODEL_INIT_ERROR, e);
709
707
  }
710
708
  }
711
- async getModels() {
712
- if (this._models && Object.keys(this._models).length > 0) {
713
- return Object.values(this._models);
714
- }
715
- const models = await this.refreshModels();
716
- this._models = {};
717
- for (const model of models) {
718
- this._models[model.name] = model;
719
- }
720
- }
721
709
  _createModel(model) {
722
- const info = this._models[model];
710
+ const info = this._modelInfos[model];
723
711
  if (info == null) {
724
712
  throw new ChatLunaError2(ChatLunaErrorCode2.MODEL_NOT_FOUND);
725
713
  }
@@ -766,14 +754,12 @@ function apply(ctx, config) {
766
754
  };
767
755
  });
768
756
  });
769
- plugin.registerClient(
770
- (_, clientConfig) => new GeminiClient(ctx, config, clientConfig, plugin)
771
- );
757
+ plugin.registerClient((ctx2) => new GeminiClient(ctx2, config, plugin));
772
758
  await plugin.initClients();
773
759
  });
774
760
  }
775
761
  __name(apply, "apply");
776
- var Config3 = Schema.intersect([
762
+ var Config4 = Schema.intersect([
777
763
  ChatLunaPlugin.Config,
778
764
  Schema.object({
779
765
  platform: Schema.string().default("gemini"),
@@ -806,7 +792,7 @@ var Config3 = Schema.intersect([
806
792
  var inject = ["chatluna"];
807
793
  var name = "chatluna-google-gemini-adapter";
808
794
  export {
809
- Config3 as Config,
795
+ Config4 as Config,
810
796
  apply,
811
797
  inject,
812
798
  logger,
@@ -1,21 +1,19 @@
1
1
  import { ChatGenerationChunk } from '@langchain/core/outputs';
2
2
  import { EmbeddingsRequester, EmbeddingsRequestParams, ModelRequester, ModelRequestParams } from 'koishi-plugin-chatluna/llm-core/platform/api';
3
- import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
3
+ import { ClientConfig, ClientConfigPool } from 'koishi-plugin-chatluna/llm-core/platform/config';
4
4
  import { Config } from '.';
5
5
  import { GeminiModelInfo } from './types';
6
6
  import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
7
+ import { Context } from 'koishi';
7
8
  export declare class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
8
- private _config;
9
- private _plugin;
10
- private _pluginConfig;
11
- constructor(_config: ClientConfig, _plugin: ChatLunaPlugin, _pluginConfig: Config);
12
- completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
9
+ _pluginConfig: Config;
10
+ constructor(ctx: Context, _configPool: ClientConfigPool<ClientConfig>, _pluginConfig: Config, _plugin: ChatLunaPlugin);
11
+ completionStreamInternal(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
13
12
  embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
14
13
  getModels(): Promise<GeminiModelInfo[]>;
15
14
  private _post;
16
15
  private _get;
17
16
  private _concatUrl;
18
17
  private _buildHeaders;
19
- init(): Promise<void>;
20
- dispose(): Promise<void>;
18
+ get logger(): import("reggol");
21
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna-google-gemini-adapter",
3
3
  "description": "google-gemini adapter for chatluna",
4
- "version": "1.2.15",
4
+ "version": "1.2.16",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -64,7 +64,8 @@
64
64
  "dependencies": {
65
65
  "@langchain/core": "^0.3.43",
66
66
  "zod": "^3.25.0-canary.20250211T214501",
67
- "zod-to-json-schema": "^3.24.5"
67
+ "zod-to-json-schema": "^3.24.5",
68
+ "@chatluna/v1-shared-adapter": "^1.0.1"
68
69
  },
69
70
  "devDependencies": {
70
71
  "atsc": "^2.1.0",
@@ -72,7 +73,7 @@
72
73
  },
73
74
  "peerDependencies": {
74
75
  "koishi": "^4.18.7",
75
- "koishi-plugin-chatluna": "^1.3.0-alpha.9"
76
+ "koishi-plugin-chatluna": "^1.3.0-alpha.10"
76
77
  },
77
78
  "koishi": {
78
79
  "description": {