@aigne/aigne-hub 0.3.2 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.0](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.3.2...aigne-hub-v0.4.0) (2025-08-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * support google model and skip check mode when connected to Hub ([#300](https://github.com/AIGNE-io/aigne-framework/issues/300)) ([e992c0f](https://github.com/AIGNE-io/aigne-framework/commit/e992c0f3335a7c512fa807d5b8ad10c9c3bf2351))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/anthropic bumped to 0.10.5
16
+ * @aigne/bedrock bumped to 0.8.9
17
+ * @aigne/core bumped to 1.42.0
18
+ * @aigne/deepseek bumped to 0.7.9
19
+ * @aigne/default-memory bumped to 1.0.9
20
+ * @aigne/gemini bumped to 0.8.9
21
+ * @aigne/ollama bumped to 0.7.9
22
+ * @aigne/open-router bumped to 0.7.9
23
+ * @aigne/openai bumped to 0.10.9
24
+ * @aigne/platform-helpers bumped to 0.5.0
25
+ * @aigne/transport bumped to 0.11.0
26
+ * @aigne/xai bumped to 0.7.9
27
+ * devDependencies
28
+ * @aigne/openai bumped to 0.10.9
29
+ * @aigne/test-utils bumped to 0.5.17
30
+
3
31
  ## [0.3.2](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.3.1...aigne-hub-v0.3.2) (2025-07-31)
4
32
 
5
33
 
@@ -1,9 +1,9 @@
1
- import { type AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import { type BedrockChatModelOptions } from "@aigne/bedrock";
1
+ import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
+ import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
3
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
4
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import { type OpenAIChatModelOptions } from "@aigne/openai";
6
- import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
+ import type { OpenAIChatModelOptions } from "@aigne/openai";
6
+ import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
7
  export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
8
  export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
9
  options: HubChatModelOptions & {
@@ -1,75 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BlockletAIGNEHubChatModel = void 0;
4
- const anthropic_1 = require("@aigne/anthropic");
5
- const bedrock_1 = require("@aigne/bedrock");
6
4
  const core_1 = require("@aigne/core");
7
- const deepseek_1 = require("@aigne/deepseek");
8
- const gemini_1 = require("@aigne/gemini");
9
- const ollama_1 = require("@aigne/ollama");
10
- const open_router_1 = require("@aigne/open-router");
11
- const openai_1 = require("@aigne/openai");
12
- const xai_1 = require("@aigne/xai");
13
- const cli_aigne_hub_model_js_1 = require("./cli-aigne-hub-model.js");
14
- function availableModels() {
15
- return [
16
- {
17
- name: openai_1.OpenAIChatModel.name,
18
- apiKeyEnvName: "OPENAI_API_KEY",
19
- create: (params) => new openai_1.OpenAIChatModel({ ...params }),
20
- },
21
- {
22
- name: anthropic_1.AnthropicChatModel.name,
23
- apiKeyEnvName: "ANTHROPIC_API_KEY",
24
- create: (params) => new anthropic_1.AnthropicChatModel({ ...params }),
25
- },
26
- {
27
- name: bedrock_1.BedrockChatModel.name,
28
- apiKeyEnvName: "AWS_ACCESS_KEY_ID",
29
- create: (params) => new bedrock_1.BedrockChatModel({ ...params }),
30
- },
31
- {
32
- name: deepseek_1.DeepSeekChatModel.name,
33
- apiKeyEnvName: "DEEPSEEK_API_KEY",
34
- create: (params) => new deepseek_1.DeepSeekChatModel({ ...params }),
35
- },
36
- {
37
- name: gemini_1.GeminiChatModel.name,
38
- apiKeyEnvName: "GEMINI_API_KEY",
39
- create: (params) => new gemini_1.GeminiChatModel({ ...params }),
40
- },
41
- {
42
- name: ollama_1.OllamaChatModel.name,
43
- apiKeyEnvName: "OLLAMA_API_KEY",
44
- create: (params) => new ollama_1.OllamaChatModel({ ...params }),
45
- },
46
- {
47
- name: open_router_1.OpenRouterChatModel.name,
48
- apiKeyEnvName: "OPEN_ROUTER_API_KEY",
49
- create: (params) => new open_router_1.OpenRouterChatModel({ ...params }),
50
- },
51
- {
52
- name: xai_1.XAIChatModel.name,
53
- apiKeyEnvName: "XAI_API_KEY",
54
- create: (params) => new xai_1.XAIChatModel({ ...params }),
55
- },
56
- {
57
- name: cli_aigne_hub_model_js_1.CliAIGNEHubChatModel.name,
58
- apiKeyEnvName: "AIGNE_HUB_API_KEY",
59
- create: (params) => new cli_aigne_hub_model_js_1.CliAIGNEHubChatModel({ ...params }),
60
- },
61
- ];
62
- }
5
+ const constants_js_1 = require("./constants.js");
63
6
  class BlockletAIGNEHubChatModel extends core_1.ChatModel {
64
7
  options;
65
8
  client;
66
9
  constructor(options) {
67
10
  super();
68
11
  this.options = options;
69
- const models = availableModels();
12
+ const models = (0, constants_js_1.availableModels)();
70
13
  const PROVIDER = process.env.BLOCKLET_AIGNE_API_PROVIDER?.toLowerCase() ?? "";
71
14
  const provider = PROVIDER.replace(/-/g, "");
72
- const m = models.find((m) => m.name.toLowerCase().includes(provider));
15
+ const m = (0, constants_js_1.findModel)(models, provider);
73
16
  if (!m) {
74
17
  throw new Error(`Unsupported model: ${process.env.BLOCKLET_AIGNE_API_PROVIDER} ${process.env.BLOCKLET_AIGNE_API_MODEL}`);
75
18
  }
@@ -3,7 +3,7 @@ import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
4
  export interface AIGNEHubChatModelOptions {
5
5
  url?: string;
6
- accessKey?: string;
6
+ apiKey?: string;
7
7
  model?: string;
8
8
  modelOptions?: ChatModelOptions;
9
9
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
@@ -10,7 +10,7 @@ const DEFAULT_CHAT_MODEL = "openai/gpt-4o";
10
10
  const DEFAULT_URL = "https://hub.aigne.io/ai-kit/";
11
11
  const aigneHubChatModelOptionsSchema = zod_1.z.object({
12
12
  url: zod_1.z.string().optional(),
13
- accessKey: zod_1.z.string().optional(),
13
+ apiKey: zod_1.z.string().optional(),
14
14
  model: zod_1.z.string().optional(),
15
15
  modelOptions: zod_1.z
16
16
  .object({
@@ -35,7 +35,7 @@ class CliAIGNEHubChatModel extends core_1.ChatModel {
35
35
  ...options,
36
36
  url: (0, ufo_1.joinURL)(options.url || process.env.AIGNE_HUB_API_URL || DEFAULT_URL, "/api/v2/chat"),
37
37
  model: options.model || DEFAULT_CHAT_MODEL,
38
- accessKey: options.accessKey || process.env.AIGNE_HUB_API_KEY,
38
+ apiKey: options.apiKey || process.env.AIGNE_HUB_API_KEY,
39
39
  });
40
40
  }
41
41
  process(input, options) {
@@ -0,0 +1,26 @@
1
+ import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
2
+ export declare function availableModels(): LoadableModel[];
3
+ export interface LoadableModel {
4
+ name: string | string[];
5
+ apiKeyEnvName?: string | string[];
6
+ create: (options: {
7
+ model?: string;
8
+ modelOptions?: ChatModelOptions;
9
+ apiKey?: string;
10
+ url?: string;
11
+ }) => ChatModel;
12
+ }
13
+ export declare function findModel(models: LoadableModel[], provider: string): LoadableModel | undefined;
14
+ type Model = {
15
+ provider?: string | null;
16
+ name?: string | null;
17
+ temperature?: number | null;
18
+ topP?: number | null;
19
+ frequencyPenalty?: number | null;
20
+ presencePenalty?: number | null;
21
+ } | undefined;
22
+ export declare function loadModel(model?: Model, modelOptions?: ChatModelOptions, credential?: {
23
+ apiKey?: string;
24
+ url?: string;
25
+ }): Promise<ChatModel | undefined>;
26
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.availableModels = availableModels;
4
+ exports.findModel = findModel;
5
+ exports.loadModel = loadModel;
6
+ const anthropic_1 = require("@aigne/anthropic");
7
+ const bedrock_1 = require("@aigne/bedrock");
8
+ const deepseek_1 = require("@aigne/deepseek");
9
+ const gemini_1 = require("@aigne/gemini");
10
+ const ollama_1 = require("@aigne/ollama");
11
+ const open_router_1 = require("@aigne/open-router");
12
+ const openai_1 = require("@aigne/openai");
13
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
14
+ const xai_1 = require("@aigne/xai");
15
+ const node_http_handler_1 = require("@smithy/node-http-handler");
16
+ const https_proxy_agent_1 = require("https-proxy-agent");
17
+ const cli_aigne_hub_model_js_1 = require("./cli-aigne-hub-model.js");
18
+ function availableModels() {
19
+ const proxy = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
20
+ .map((i) => process.env[i])
21
+ .filter(Boolean)[0];
22
+ const httpAgent = proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
23
+ const clientOptions = {
24
+ fetchOptions: {
25
+ // @ts-ignore
26
+ agent: httpAgent,
27
+ },
28
+ };
29
+ return [
30
+ {
31
+ name: openai_1.OpenAIChatModel.name,
32
+ apiKeyEnvName: "OPENAI_API_KEY",
33
+ create: (params) => new openai_1.OpenAIChatModel({ ...params, clientOptions }),
34
+ },
35
+ {
36
+ name: anthropic_1.AnthropicChatModel.name,
37
+ apiKeyEnvName: "ANTHROPIC_API_KEY",
38
+ create: (params) => new anthropic_1.AnthropicChatModel({ ...params, clientOptions }),
39
+ },
40
+ {
41
+ name: bedrock_1.BedrockChatModel.name,
42
+ apiKeyEnvName: "AWS_ACCESS_KEY_ID",
43
+ create: (params) => new bedrock_1.BedrockChatModel({
44
+ ...params,
45
+ clientOptions: {
46
+ requestHandler: node_http_handler_1.NodeHttpHandler.create({ httpAgent, httpsAgent: httpAgent }),
47
+ streamCollector: node_http_handler_1.streamCollector,
48
+ },
49
+ }),
50
+ },
51
+ {
52
+ name: deepseek_1.DeepSeekChatModel.name,
53
+ apiKeyEnvName: "DEEPSEEK_API_KEY",
54
+ create: (params) => new deepseek_1.DeepSeekChatModel({ ...params, clientOptions }),
55
+ },
56
+ {
57
+ name: [gemini_1.GeminiChatModel.name, "google"],
58
+ apiKeyEnvName: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
59
+ create: (params) => new gemini_1.GeminiChatModel({ ...params, clientOptions }),
60
+ },
61
+ {
62
+ name: ollama_1.OllamaChatModel.name,
63
+ apiKeyEnvName: "OLLAMA_API_KEY",
64
+ create: (params) => new ollama_1.OllamaChatModel({ ...params, clientOptions }),
65
+ },
66
+ {
67
+ name: open_router_1.OpenRouterChatModel.name,
68
+ apiKeyEnvName: "OPEN_ROUTER_API_KEY",
69
+ create: (params) => new open_router_1.OpenRouterChatModel({ ...params, clientOptions }),
70
+ },
71
+ {
72
+ name: xai_1.XAIChatModel.name,
73
+ apiKeyEnvName: "XAI_API_KEY",
74
+ create: (params) => new xai_1.XAIChatModel({ ...params, clientOptions }),
75
+ },
76
+ {
77
+ name: cli_aigne_hub_model_js_1.CliAIGNEHubChatModel.name,
78
+ apiKeyEnvName: "AIGNE_HUB_API_KEY",
79
+ create: (params) => new cli_aigne_hub_model_js_1.CliAIGNEHubChatModel({ ...params, clientOptions }),
80
+ },
81
+ ];
82
+ }
83
+ function findModel(models, provider) {
84
+ return models.find((m) => {
85
+ if (typeof m.name === "string") {
86
+ return m.name.toLowerCase().includes(provider.toLowerCase());
87
+ }
88
+ return m.name.some((n) => n.toLowerCase().includes(provider.toLowerCase()));
89
+ });
90
+ }
91
+ const { MODEL_PROVIDER, MODEL_NAME } = index_js_1.nodejs.env;
92
+ const DEFAULT_MODEL_PROVIDER = "openai";
93
+ async function loadModel(model, modelOptions, credential) {
94
+ const params = {
95
+ model: MODEL_NAME ?? model?.name ?? undefined,
96
+ temperature: model?.temperature ?? undefined,
97
+ topP: model?.topP ?? undefined,
98
+ frequencyPenalty: model?.frequencyPenalty ?? undefined,
99
+ presencePenalty: model?.presencePenalty ?? undefined,
100
+ };
101
+ const provider = (MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER).replace(/-/g, "");
102
+ const m = findModel(availableModels(), provider);
103
+ if (!m)
104
+ throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
105
+ return m.create({
106
+ ...(credential || {}),
107
+ model: params.model,
108
+ modelOptions: { ...params, ...modelOptions },
109
+ });
110
+ }
@@ -1,6 +1,7 @@
1
1
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
+ export * from "./constants.js";
4
5
  export declare class AIGNEHubChatModel extends ChatModel {
5
6
  options: HubChatModelOptions;
6
7
  private client;
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,24 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.AIGNEHubChatModel = void 0;
4
18
  const core_1 = require("@aigne/core");
5
19
  const blocklet_aigne_hub_model_js_1 = require("./blocklet-aigne-hub-model.js");
6
20
  const cli_aigne_hub_model_js_1 = require("./cli-aigne-hub-model.js");
21
+ __exportStar(require("./constants.js"), exports);
7
22
  class AIGNEHubChatModel extends core_1.ChatModel {
8
23
  options;
9
24
  client;
@@ -1,9 +1,9 @@
1
- import { type AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import { type BedrockChatModelOptions } from "@aigne/bedrock";
1
+ import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
+ import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
3
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
4
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import { type OpenAIChatModelOptions } from "@aigne/openai";
6
- import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
+ import type { OpenAIChatModelOptions } from "@aigne/openai";
6
+ import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
7
  export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
8
  export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
9
  options: HubChatModelOptions & {
@@ -3,7 +3,7 @@ import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
4
  export interface AIGNEHubChatModelOptions {
5
5
  url?: string;
6
- accessKey?: string;
6
+ apiKey?: string;
7
7
  model?: string;
8
8
  modelOptions?: ChatModelOptions;
9
9
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
@@ -0,0 +1,26 @@
1
+ import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
2
+ export declare function availableModels(): LoadableModel[];
3
+ export interface LoadableModel {
4
+ name: string | string[];
5
+ apiKeyEnvName?: string | string[];
6
+ create: (options: {
7
+ model?: string;
8
+ modelOptions?: ChatModelOptions;
9
+ apiKey?: string;
10
+ url?: string;
11
+ }) => ChatModel;
12
+ }
13
+ export declare function findModel(models: LoadableModel[], provider: string): LoadableModel | undefined;
14
+ type Model = {
15
+ provider?: string | null;
16
+ name?: string | null;
17
+ temperature?: number | null;
18
+ topP?: number | null;
19
+ frequencyPenalty?: number | null;
20
+ presencePenalty?: number | null;
21
+ } | undefined;
22
+ export declare function loadModel(model?: Model, modelOptions?: ChatModelOptions, credential?: {
23
+ apiKey?: string;
24
+ url?: string;
25
+ }): Promise<ChatModel | undefined>;
26
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
+ export * from "./constants.js";
4
5
  export declare class AIGNEHubChatModel extends ChatModel {
5
6
  options: HubChatModelOptions;
6
7
  private client;
@@ -1,9 +1,9 @@
1
- import { type AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import { type BedrockChatModelOptions } from "@aigne/bedrock";
1
+ import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
+ import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
3
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
4
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import { type OpenAIChatModelOptions } from "@aigne/openai";
6
- import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
+ import type { OpenAIChatModelOptions } from "@aigne/openai";
6
+ import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
7
  export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
8
  export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
9
  options: HubChatModelOptions & {
@@ -1,62 +1,5 @@
1
- import { AnthropicChatModel } from "@aigne/anthropic";
2
- import { BedrockChatModel } from "@aigne/bedrock";
3
1
  import { ChatModel, } from "@aigne/core";
4
- import { DeepSeekChatModel } from "@aigne/deepseek";
5
- import { GeminiChatModel } from "@aigne/gemini";
6
- import { OllamaChatModel } from "@aigne/ollama";
7
- import { OpenRouterChatModel } from "@aigne/open-router";
8
- import { OpenAIChatModel } from "@aigne/openai";
9
- import { XAIChatModel } from "@aigne/xai";
10
- import { CliAIGNEHubChatModel } from "./cli-aigne-hub-model.js";
11
- function availableModels() {
12
- return [
13
- {
14
- name: OpenAIChatModel.name,
15
- apiKeyEnvName: "OPENAI_API_KEY",
16
- create: (params) => new OpenAIChatModel({ ...params }),
17
- },
18
- {
19
- name: AnthropicChatModel.name,
20
- apiKeyEnvName: "ANTHROPIC_API_KEY",
21
- create: (params) => new AnthropicChatModel({ ...params }),
22
- },
23
- {
24
- name: BedrockChatModel.name,
25
- apiKeyEnvName: "AWS_ACCESS_KEY_ID",
26
- create: (params) => new BedrockChatModel({ ...params }),
27
- },
28
- {
29
- name: DeepSeekChatModel.name,
30
- apiKeyEnvName: "DEEPSEEK_API_KEY",
31
- create: (params) => new DeepSeekChatModel({ ...params }),
32
- },
33
- {
34
- name: GeminiChatModel.name,
35
- apiKeyEnvName: "GEMINI_API_KEY",
36
- create: (params) => new GeminiChatModel({ ...params }),
37
- },
38
- {
39
- name: OllamaChatModel.name,
40
- apiKeyEnvName: "OLLAMA_API_KEY",
41
- create: (params) => new OllamaChatModel({ ...params }),
42
- },
43
- {
44
- name: OpenRouterChatModel.name,
45
- apiKeyEnvName: "OPEN_ROUTER_API_KEY",
46
- create: (params) => new OpenRouterChatModel({ ...params }),
47
- },
48
- {
49
- name: XAIChatModel.name,
50
- apiKeyEnvName: "XAI_API_KEY",
51
- create: (params) => new XAIChatModel({ ...params }),
52
- },
53
- {
54
- name: CliAIGNEHubChatModel.name,
55
- apiKeyEnvName: "AIGNE_HUB_API_KEY",
56
- create: (params) => new CliAIGNEHubChatModel({ ...params }),
57
- },
58
- ];
59
- }
2
+ import { availableModels, findModel } from "./constants.js";
60
3
  export class BlockletAIGNEHubChatModel extends ChatModel {
61
4
  options;
62
5
  client;
@@ -66,7 +9,7 @@ export class BlockletAIGNEHubChatModel extends ChatModel {
66
9
  const models = availableModels();
67
10
  const PROVIDER = process.env.BLOCKLET_AIGNE_API_PROVIDER?.toLowerCase() ?? "";
68
11
  const provider = PROVIDER.replace(/-/g, "");
69
- const m = models.find((m) => m.name.toLowerCase().includes(provider));
12
+ const m = findModel(models, provider);
70
13
  if (!m) {
71
14
  throw new Error(`Unsupported model: ${process.env.BLOCKLET_AIGNE_API_PROVIDER} ${process.env.BLOCKLET_AIGNE_API_MODEL}`);
72
15
  }
@@ -3,7 +3,7 @@ import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
4
  export interface AIGNEHubChatModelOptions {
5
5
  url?: string;
6
- accessKey?: string;
6
+ apiKey?: string;
7
7
  model?: string;
8
8
  modelOptions?: ChatModelOptions;
9
9
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
@@ -7,7 +7,7 @@ const DEFAULT_CHAT_MODEL = "openai/gpt-4o";
7
7
  const DEFAULT_URL = "https://hub.aigne.io/ai-kit/";
8
8
  const aigneHubChatModelOptionsSchema = z.object({
9
9
  url: z.string().optional(),
10
- accessKey: z.string().optional(),
10
+ apiKey: z.string().optional(),
11
11
  model: z.string().optional(),
12
12
  modelOptions: z
13
13
  .object({
@@ -32,7 +32,7 @@ export class CliAIGNEHubChatModel extends ChatModel {
32
32
  ...options,
33
33
  url: joinURL(options.url || process.env.AIGNE_HUB_API_URL || DEFAULT_URL, "/api/v2/chat"),
34
34
  model: options.model || DEFAULT_CHAT_MODEL,
35
- accessKey: options.accessKey || process.env.AIGNE_HUB_API_KEY,
35
+ apiKey: options.apiKey || process.env.AIGNE_HUB_API_KEY,
36
36
  });
37
37
  }
38
38
  process(input, options) {
@@ -0,0 +1,26 @@
1
+ import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
2
+ export declare function availableModels(): LoadableModel[];
3
+ export interface LoadableModel {
4
+ name: string | string[];
5
+ apiKeyEnvName?: string | string[];
6
+ create: (options: {
7
+ model?: string;
8
+ modelOptions?: ChatModelOptions;
9
+ apiKey?: string;
10
+ url?: string;
11
+ }) => ChatModel;
12
+ }
13
+ export declare function findModel(models: LoadableModel[], provider: string): LoadableModel | undefined;
14
+ type Model = {
15
+ provider?: string | null;
16
+ name?: string | null;
17
+ temperature?: number | null;
18
+ topP?: number | null;
19
+ frequencyPenalty?: number | null;
20
+ presencePenalty?: number | null;
21
+ } | undefined;
22
+ export declare function loadModel(model?: Model, modelOptions?: ChatModelOptions, credential?: {
23
+ apiKey?: string;
24
+ url?: string;
25
+ }): Promise<ChatModel | undefined>;
26
+ export {};
@@ -0,0 +1,105 @@
1
+ import { AnthropicChatModel } from "@aigne/anthropic";
2
+ import { BedrockChatModel } from "@aigne/bedrock";
3
+ import { DeepSeekChatModel } from "@aigne/deepseek";
4
+ import { GeminiChatModel } from "@aigne/gemini";
5
+ import { OllamaChatModel } from "@aigne/ollama";
6
+ import { OpenRouterChatModel } from "@aigne/open-router";
7
+ import { OpenAIChatModel } from "@aigne/openai";
8
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
9
+ import { XAIChatModel } from "@aigne/xai";
10
+ import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler";
11
+ import { HttpsProxyAgent } from "https-proxy-agent";
12
+ import { CliAIGNEHubChatModel } from "./cli-aigne-hub-model.js";
13
+ export function availableModels() {
14
+ const proxy = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
15
+ .map((i) => process.env[i])
16
+ .filter(Boolean)[0];
17
+ const httpAgent = proxy ? new HttpsProxyAgent(proxy) : undefined;
18
+ const clientOptions = {
19
+ fetchOptions: {
20
+ // @ts-ignore
21
+ agent: httpAgent,
22
+ },
23
+ };
24
+ return [
25
+ {
26
+ name: OpenAIChatModel.name,
27
+ apiKeyEnvName: "OPENAI_API_KEY",
28
+ create: (params) => new OpenAIChatModel({ ...params, clientOptions }),
29
+ },
30
+ {
31
+ name: AnthropicChatModel.name,
32
+ apiKeyEnvName: "ANTHROPIC_API_KEY",
33
+ create: (params) => new AnthropicChatModel({ ...params, clientOptions }),
34
+ },
35
+ {
36
+ name: BedrockChatModel.name,
37
+ apiKeyEnvName: "AWS_ACCESS_KEY_ID",
38
+ create: (params) => new BedrockChatModel({
39
+ ...params,
40
+ clientOptions: {
41
+ requestHandler: NodeHttpHandler.create({ httpAgent, httpsAgent: httpAgent }),
42
+ streamCollector,
43
+ },
44
+ }),
45
+ },
46
+ {
47
+ name: DeepSeekChatModel.name,
48
+ apiKeyEnvName: "DEEPSEEK_API_KEY",
49
+ create: (params) => new DeepSeekChatModel({ ...params, clientOptions }),
50
+ },
51
+ {
52
+ name: [GeminiChatModel.name, "google"],
53
+ apiKeyEnvName: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
54
+ create: (params) => new GeminiChatModel({ ...params, clientOptions }),
55
+ },
56
+ {
57
+ name: OllamaChatModel.name,
58
+ apiKeyEnvName: "OLLAMA_API_KEY",
59
+ create: (params) => new OllamaChatModel({ ...params, clientOptions }),
60
+ },
61
+ {
62
+ name: OpenRouterChatModel.name,
63
+ apiKeyEnvName: "OPEN_ROUTER_API_KEY",
64
+ create: (params) => new OpenRouterChatModel({ ...params, clientOptions }),
65
+ },
66
+ {
67
+ name: XAIChatModel.name,
68
+ apiKeyEnvName: "XAI_API_KEY",
69
+ create: (params) => new XAIChatModel({ ...params, clientOptions }),
70
+ },
71
+ {
72
+ name: CliAIGNEHubChatModel.name,
73
+ apiKeyEnvName: "AIGNE_HUB_API_KEY",
74
+ create: (params) => new CliAIGNEHubChatModel({ ...params, clientOptions }),
75
+ },
76
+ ];
77
+ }
78
+ export function findModel(models, provider) {
79
+ return models.find((m) => {
80
+ if (typeof m.name === "string") {
81
+ return m.name.toLowerCase().includes(provider.toLowerCase());
82
+ }
83
+ return m.name.some((n) => n.toLowerCase().includes(provider.toLowerCase()));
84
+ });
85
+ }
86
+ const { MODEL_PROVIDER, MODEL_NAME } = nodejs.env;
87
+ const DEFAULT_MODEL_PROVIDER = "openai";
88
+ export async function loadModel(model, modelOptions, credential) {
89
+ const params = {
90
+ model: MODEL_NAME ?? model?.name ?? undefined,
91
+ temperature: model?.temperature ?? undefined,
92
+ topP: model?.topP ?? undefined,
93
+ frequencyPenalty: model?.frequencyPenalty ?? undefined,
94
+ presencePenalty: model?.presencePenalty ?? undefined,
95
+ };
96
+ const provider = (MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER).replace(/-/g, "");
97
+ const m = findModel(availableModels(), provider);
98
+ if (!m)
99
+ throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
100
+ return m.create({
101
+ ...(credential || {}),
102
+ model: params.model,
103
+ modelOptions: { ...params, ...modelOptions },
104
+ });
105
+ }
@@ -1,6 +1,7 @@
1
1
  import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
+ export * from "./constants.js";
4
5
  export declare class AIGNEHubChatModel extends ChatModel {
5
6
  options: HubChatModelOptions;
6
7
  private client;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ChatModel, } from "@aigne/core";
2
2
  import { BlockletAIGNEHubChatModel } from "./blocklet-aigne-hub-model.js";
3
3
  import { CliAIGNEHubChatModel } from "./cli-aigne-hub-model.js";
4
+ export * from "./constants.js";
4
5
  export class AIGNEHubChatModel extends ChatModel {
5
6
  options;
6
7
  client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/aigne-hub",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "AIGNE Hub SDK for integrating with Hub AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,20 +24,36 @@
24
24
  "main": "./lib/cjs/index.js",
25
25
  "module": "./lib/esm/index.js",
26
26
  "types": "./lib/dts/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./lib/esm/index.js",
30
+ "require": "./lib/cjs/index.js",
31
+ "types": "./lib/dts/index.d.ts"
32
+ },
33
+ "./constants": {
34
+ "import": "./lib/esm/constants.js",
35
+ "require": "./lib/cjs/constants.js",
36
+ "types": "./lib/dts/constants.d.ts"
37
+ }
38
+ },
27
39
  "dependencies": {
40
+ "@smithy/node-http-handler": "^4.1.0",
41
+ "https-proxy-agent": "^7.0.6",
42
+ "openai": "^5.8.3",
28
43
  "ufo": "^1.6.1",
29
44
  "zod": "^3.25.67",
30
- "@aigne/anthropic": "^0.10.4",
31
- "@aigne/bedrock": "^0.8.8",
32
- "@aigne/core": "^1.41.0",
33
- "@aigne/deepseek": "^0.7.8",
34
- "@aigne/default-memory": "^1.0.8",
35
- "@aigne/gemini": "^0.8.8",
36
- "@aigne/ollama": "^0.7.8",
37
- "@aigne/transport": "^0.10.8",
38
- "@aigne/openai": "^0.10.8",
39
- "@aigne/open-router": "^0.7.8",
40
- "@aigne/xai": "^0.7.8"
45
+ "@aigne/anthropic": "^0.10.5",
46
+ "@aigne/bedrock": "^0.8.9",
47
+ "@aigne/core": "^1.42.0",
48
+ "@aigne/deepseek": "^0.7.9",
49
+ "@aigne/default-memory": "^1.0.9",
50
+ "@aigne/ollama": "^0.7.9",
51
+ "@aigne/open-router": "^0.7.9",
52
+ "@aigne/openai": "^0.10.9",
53
+ "@aigne/platform-helpers": "^0.5.0",
54
+ "@aigne/gemini": "^0.8.9",
55
+ "@aigne/transport": "^0.11.0",
56
+ "@aigne/xai": "^0.7.9"
41
57
  },
42
58
  "devDependencies": {
43
59
  "@types/bun": "^1.2.18",
@@ -46,8 +62,8 @@
46
62
  "npm-run-all": "^4.1.5",
47
63
  "rimraf": "^6.0.1",
48
64
  "typescript": "^5.8.3",
49
- "@aigne/test-utils": "^0.5.16",
50
- "@aigne/openai": "^0.10.8"
65
+ "@aigne/test-utils": "^0.5.17",
66
+ "@aigne/openai": "^0.10.9"
51
67
  },
52
68
  "scripts": {
53
69
  "lint": "tsc --noEmit",