@aigne/aigne-hub 0.5.0 → 0.5.2

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,40 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.2](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.5.1...aigne-hub-v0.5.2) (2025-08-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **cli:** log only once in loadAIGNE ([#357](https://github.com/AIGNE-io/aigne-framework/issues/357)) ([6e6d968](https://github.com/AIGNE-io/aigne-framework/commit/6e6d96814fbc87f210522ae16daf94c1f84f311a))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/anthropic bumped to 0.11.2
16
+ * @aigne/bedrock bumped to 0.9.2
17
+ * @aigne/core bumped to 1.50.0
18
+ * @aigne/deepseek bumped to 0.7.20
19
+ * @aigne/default-memory bumped to 1.1.2
20
+ * @aigne/gemini bumped to 0.9.2
21
+ * @aigne/ollama bumped to 0.7.20
22
+ * @aigne/open-router bumped to 0.7.20
23
+ * @aigne/openai bumped to 0.11.2
24
+ * @aigne/platform-helpers bumped to 0.6.2
25
+ * @aigne/transport bumped to 0.14.0
26
+ * @aigne/xai bumped to 0.7.20
27
+ * devDependencies
28
+ * @aigne/openai bumped to 0.11.2
29
+ * @aigne/test-utils bumped to 0.5.28
30
+
31
+ ## [0.5.1](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.5.0...aigne-hub-v0.5.1) (2025-08-13)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * resolve circular dependency in aigne-hub ([#355](https://github.com/AIGNE-io/aigne-framework/issues/355)) ([202c1f3](https://github.com/AIGNE-io/aigne-framework/commit/202c1f3acc199f4512580b3c1f73c1dee13e40a5))
37
+
3
38
  ## [0.5.0](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.4.10...aigne-hub-v0.5.0) (2025-08-13)
4
39
 
5
40
 
@@ -1,21 +1,24 @@
1
- import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import type { OpenAIChatModelOptions } from "@aigne/openai";
3
+ import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
6
4
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
- export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
- export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
- options: HubChatModelOptions & {
5
+ export declare class AIGNEHubChatModel extends ChatModel {
6
+ options: AIGNEHubChatModelOptions & {
10
7
  apiKey?: string;
11
8
  baseURL?: string;
12
9
  url?: string;
13
10
  };
14
- private client;
15
- constructor(options: HubChatModelOptions & {
11
+ protected _client?: ChatModel;
12
+ constructor(options: AIGNEHubChatModelOptions & {
16
13
  apiKey?: string;
17
14
  baseURL?: string;
18
15
  url?: string;
19
16
  });
20
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
17
+ get client(): ChatModel | undefined;
18
+ getCredential(): {
19
+ url: string;
20
+ apiKey: any;
21
+ model: string | undefined;
22
+ };
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
24
  }
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlockletAIGNEHubChatModel = void 0;
3
+ exports.AIGNEHubChatModel = void 0;
4
4
  const core_1 = require("@aigne/core");
5
5
  const constants_js_1 = require("./util/constants.js");
6
6
  const model_js_1 = require("./util/model.js");
7
- class BlockletAIGNEHubChatModel extends core_1.ChatModel {
7
+ class AIGNEHubChatModel extends core_1.ChatModel {
8
8
  options;
9
- client;
9
+ _client;
10
10
  constructor(options) {
11
11
  super();
12
12
  this.options = options;
13
+ }
14
+ get client() {
13
15
  const models = (0, model_js_1.availableModels)();
14
16
  const rawProvider = process.env.BLOCKLET_AIGNE_API_PROVIDER ?? "";
15
17
  const providerKey = rawProvider.toLowerCase().replace(/-/g, "");
@@ -27,19 +29,43 @@ class BlockletAIGNEHubChatModel extends core_1.ChatModel {
27
29
  catch (err) {
28
30
  console.error(err);
29
31
  }
30
- const { apiKey, ...extraCredentialOptions } = credentialOptions;
31
- const params = {
32
- ...options,
33
- model: options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
34
- modelOptions: options.modelOptions,
35
- url: options.url || process.env.BLOCKLET_AIGNE_API_URL || constants_js_1.AIGNE_HUB_URL,
36
- apiKey: options.apiKey || apiKey,
37
- ...extraCredentialOptions,
32
+ const { apiKey, url, model } = this.getCredential();
33
+ const options = {
34
+ ...this.options,
35
+ ...credentialOptions,
36
+ modelOptions: this.options.modelOptions,
37
+ model,
38
+ url,
39
+ apiKey,
40
+ };
41
+ this._client ?? modelEntry.create(options);
42
+ return this._client;
43
+ }
44
+ getCredential() {
45
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
46
+ let credentialOptions = {};
47
+ try {
48
+ credentialOptions =
49
+ typeof rawCredential === "string" ? JSON.parse(rawCredential) : (rawCredential ?? {});
50
+ }
51
+ catch (err) {
52
+ console.error(err);
53
+ }
54
+ return {
55
+ url: this.options.url || process.env.BLOCKLET_AIGNE_API_URL || constants_js_1.AIGNE_HUB_URL,
56
+ apiKey: this.options.apiKey || credentialOptions?.apiKey,
57
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
38
58
  };
39
- this.client = modelEntry.create(params);
40
59
  }
41
60
  process(input, options) {
61
+ if (!this.client) {
62
+ throw new Error("Client not initialized");
63
+ }
64
+ options.fetchOptions = {
65
+ headers: { "x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || "" },
66
+ ...options.fetchOptions,
67
+ };
42
68
  return this.client.invoke(input, options);
43
69
  }
44
70
  }
45
- exports.BlockletAIGNEHubChatModel = BlockletAIGNEHubChatModel;
71
+ exports.AIGNEHubChatModel = AIGNEHubChatModel;
@@ -1,6 +1,7 @@
1
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
+ import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
5
  export interface AIGNEHubChatModelOptions {
5
6
  url?: string;
6
7
  apiKey?: string;
@@ -8,9 +9,15 @@ export interface AIGNEHubChatModelOptions {
8
9
  modelOptions?: ChatModelOptions;
9
10
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
10
11
  }
11
- export declare class CliAIGNEHubChatModel extends ChatModel {
12
+ export declare class AIGNEHubChatModel extends ChatModel {
12
13
  options: AIGNEHubChatModelOptions;
13
- private client;
14
+ protected _client?: BaseClient;
14
15
  constructor(options: AIGNEHubChatModelOptions);
15
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
+ get client(): BaseClient;
17
+ getCredential(): {
18
+ url: string;
19
+ apiKey: string | undefined;
20
+ model: string;
21
+ };
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
23
  }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CliAIGNEHubChatModel = void 0;
3
+ exports.AIGNEHubChatModel = void 0;
4
4
  const core_1 = require("@aigne/core");
5
5
  const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
6
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
6
7
  const base_client_js_1 = require("@aigne/transport/http-client/base-client.js");
7
8
  const ufo_1 = require("ufo");
8
9
  const zod_1 = require("zod");
9
10
  const constants_js_1 = require("./util/constants.js");
10
- const DEFAULT_CHAT_MODEL = "openai/gpt-4o";
11
11
  const aigneHubChatModelOptionsSchema = zod_1.z.object({
12
12
  url: zod_1.z.string().optional(),
13
13
  apiKey: zod_1.z.string().optional(),
@@ -24,25 +24,35 @@ const aigneHubChatModelOptionsSchema = zod_1.z.object({
24
24
  .optional(),
25
25
  clientOptions: zod_1.z.object({}).optional(),
26
26
  });
27
- class CliAIGNEHubChatModel extends core_1.ChatModel {
27
+ class AIGNEHubChatModel extends core_1.ChatModel {
28
28
  options;
29
- client;
29
+ _client;
30
30
  constructor(options) {
31
31
  (0, type_utils_js_1.checkArguments)("AIGNEHubChatModel", aigneHubChatModelOptionsSchema, options);
32
32
  super();
33
33
  this.options = options;
34
- const url = options.url || process.env.AIGNE_HUB_API_URL || constants_js_1.AIGNE_HUB_URL;
34
+ }
35
+ get client() {
36
+ const { url, apiKey, model } = this.getCredential();
37
+ const options = { ...this.options, url, apiKey, model };
38
+ this._client ??= new base_client_js_1.BaseClient(options);
39
+ return this._client;
40
+ }
41
+ getCredential() {
42
+ const url = this.options.url || process.env.AIGNE_HUB_API_URL || constants_js_1.AIGNE_HUB_URL;
35
43
  const path = "/api/v2/chat";
36
- const params = {
37
- ...options,
44
+ return {
38
45
  url: url.endsWith(path) ? url : (0, ufo_1.joinURL)(url, path),
39
- model: options.model || DEFAULT_CHAT_MODEL,
40
- apiKey: options.apiKey || process.env.AIGNE_HUB_API_KEY,
46
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY,
47
+ model: this.options.model || constants_js_1.DEFAULT_AIGNE_HUB_MODEL,
41
48
  };
42
- this.client = new base_client_js_1.BaseClient(params);
43
49
  }
44
50
  process(input, options) {
51
+ options.fetchOptions = {
52
+ headers: { "x-aigne-hub-client-did": `@aigne/aigne-hub:${index_js_1.nodejs.os.hostname()}` },
53
+ ...options.fetchOptions,
54
+ };
45
55
  return this.client.__invoke(undefined, input, options);
46
56
  }
47
57
  }
48
- exports.CliAIGNEHubChatModel = CliAIGNEHubChatModel;
58
+ exports.AIGNEHubChatModel = AIGNEHubChatModel;
@@ -1,6 +1,5 @@
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
- import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
3
  import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export * from "./util/constants.js";
6
5
  export * from "./util/credential.js";
@@ -8,9 +7,14 @@ export * from "./util/crypto.js";
8
7
  export * from "./util/model.js";
9
8
  export * from "./util/type.js";
10
9
  export declare class AIGNEHubChatModel extends ChatModel {
11
- options: HubChatModelOptions;
10
+ options: AIGNEHubChatModelOptions;
12
11
  private client;
13
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
14
- constructor(options: HubChatModelOptions);
13
+ constructor(options: AIGNEHubChatModelOptions);
14
+ getCredential(): {
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ };
15
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
20
  }
package/lib/cjs/index.js CHANGED
@@ -40,9 +40,12 @@ class AIGNEHubChatModel extends core_1.ChatModel {
40
40
  super();
41
41
  this.options = options;
42
42
  const isBlocklet = process.env.BLOCKLET_AIGNE_API_URL && process.env.BLOCKLET_AIGNE_API_PROVIDER;
43
- const AIGNEHubModel = isBlocklet ? blocklet_aigne_hub_model_js_1.BlockletAIGNEHubChatModel : cli_aigne_hub_model_js_1.CliAIGNEHubChatModel;
43
+ const AIGNEHubModel = isBlocklet ? blocklet_aigne_hub_model_js_1.AIGNEHubChatModel : cli_aigne_hub_model_js_1.AIGNEHubChatModel;
44
44
  this.client = new AIGNEHubModel(options);
45
45
  }
46
+ getCredential() {
47
+ return this.client.getCredential();
48
+ }
46
49
  process(input, options) {
47
50
  return this.client.process(input, options);
48
51
  }
@@ -4,10 +4,11 @@ declare const ACCESS_KEY_SESSION_API = "/api/access-key/session";
4
4
  declare const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
5
5
  declare const AGENT_HUB_PROVIDER = "aignehub";
6
6
  declare const AIGNE_HUB_URL = "https://hub.aigne.io/";
7
+ declare const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
7
8
  declare const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = "aignehub:openai/gpt-5-mini";
8
9
  declare const DEFAULT_MODEL_PROVIDER = "openai";
9
10
  declare const isTest: string | boolean;
10
11
  declare const TEST_AIGNE_ENV_FILE: string;
11
12
  declare const PROD_AIGNE_ENV_FILE: string;
12
13
  declare const AIGNE_ENV_FILE: string;
13
- export { DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
14
+ export { DEFAULT_AIGNE_HUB_MODEL, DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIGNE_ENV_FILE = exports.PROD_AIGNE_ENV_FILE = exports.TEST_AIGNE_ENV_FILE = exports.AGENT_HUB_PROVIDER = exports.ACCESS_KEY_SESSION_API = exports.ACCESS_KEY_PREFIX = exports.WELLKNOWN_SERVICE_PATH_PREFIX = exports.isTest = exports.AIGNE_HUB_URL = exports.AIGNE_HUB_DID = exports.DEFAULT_MODEL_PROVIDER = exports.DEFAULT_AIGNE_HUB_PROVIDER_MODEL = void 0;
3
+ exports.AIGNE_ENV_FILE = exports.PROD_AIGNE_ENV_FILE = exports.TEST_AIGNE_ENV_FILE = exports.AGENT_HUB_PROVIDER = exports.ACCESS_KEY_SESSION_API = exports.ACCESS_KEY_PREFIX = exports.WELLKNOWN_SERVICE_PATH_PREFIX = exports.isTest = exports.AIGNE_HUB_URL = exports.AIGNE_HUB_DID = exports.DEFAULT_MODEL_PROVIDER = exports.DEFAULT_AIGNE_HUB_PROVIDER_MODEL = exports.DEFAULT_AIGNE_HUB_MODEL = void 0;
4
4
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
5
5
  const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
6
6
  exports.WELLKNOWN_SERVICE_PATH_PREFIX = WELLKNOWN_SERVICE_PATH_PREFIX;
@@ -15,6 +15,7 @@ exports.AGENT_HUB_PROVIDER = AGENT_HUB_PROVIDER;
15
15
  const AIGNE_HUB_URL = "https://hub.aigne.io/";
16
16
  exports.AIGNE_HUB_URL = AIGNE_HUB_URL;
17
17
  const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
18
+ exports.DEFAULT_AIGNE_HUB_MODEL = DEFAULT_AIGNE_HUB_MODEL;
18
19
  const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = `${AGENT_HUB_PROVIDER}:${DEFAULT_AIGNE_HUB_MODEL}`;
19
20
  exports.DEFAULT_AIGNE_HUB_PROVIDER_MODEL = DEFAULT_AIGNE_HUB_PROVIDER_MODEL;
20
21
  const DEFAULT_MODEL_PROVIDER = "openai";
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.decodeEncryptionKey = exports.encodeEncryptionKey = exports.encrypt = exports.decrypt = void 0;
7
- const node_crypto_1 = __importDefault(require("node:crypto"));
4
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
8
5
  const aes_legacy_js_1 = require("@ocap/mcrypto/lib/crypter/aes-legacy.js");
9
6
  const aes = new aes_legacy_js_1.AesCrypter();
10
- const decrypt = (m, s, i) => aes.decrypt(m, node_crypto_1.default.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
7
+ const decrypt = (m, s, i) => aes.decrypt(m, index_js_1.nodejs.crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
11
8
  exports.decrypt = decrypt;
12
- const encrypt = (m, s, i) => aes.encrypt(m, node_crypto_1.default.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
9
+ const encrypt = (m, s, i) => aes.encrypt(m, index_js_1.nodejs.crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
13
10
  exports.encrypt = encrypt;
14
11
  const escapeFn = (str) => str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
15
12
  const unescapeFn = (str) => (str + "===".slice((str.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
@@ -18,10 +18,9 @@ const openai_1 = require("@aigne/openai");
18
18
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
19
19
  const xai_1 = require("@aigne/xai");
20
20
  const node_http_handler_1 = require("@smithy/node-http-handler");
21
- const boxen_1 = __importDefault(require("boxen"));
22
21
  const chalk_1 = __importDefault(require("chalk"));
23
22
  const https_proxy_agent_1 = require("https-proxy-agent");
24
- const index_js_2 = require("../index.js");
23
+ const cli_aigne_hub_model_js_1 = require("../cli-aigne-hub-model.js");
25
24
  const constants_js_1 = require("./constants.js");
26
25
  const credential_js_1 = require("./credential.js");
27
26
  const { MODEL_PROVIDER, MODEL_NAME } = index_js_1.nodejs.env;
@@ -84,9 +83,9 @@ function availableModels() {
84
83
  create: (params) => new xai_1.XAIChatModel({ ...params, clientOptions }),
85
84
  },
86
85
  {
87
- name: index_js_2.AIGNEHubChatModel.name,
86
+ name: cli_aigne_hub_model_js_1.AIGNEHubChatModel.name,
88
87
  apiKeyEnvName: "AIGNE_HUB_API_KEY",
89
- create: (params) => new index_js_2.AIGNEHubChatModel({ ...params, clientOptions }),
88
+ create: (params) => new cli_aigne_hub_model_js_1.AIGNEHubChatModel({ ...params, clientOptions }),
90
89
  },
91
90
  ];
92
91
  }
@@ -152,32 +151,6 @@ function maskApiKey(apiKey) {
152
151
  const end = apiKey.slice(-4);
153
152
  return `${start}${"*".repeat(8)}${end}`;
154
153
  }
155
- let printed = false;
156
- function printChatModelInfoBox({ provider, model, credential, m, }) {
157
- if (printed)
158
- return;
159
- printed = true;
160
- const lines = [
161
- `${chalk_1.default.cyan("Provider")}: ${chalk_1.default.green(provider)}`,
162
- `${chalk_1.default.cyan("Model")}: ${chalk_1.default.green(model)}`,
163
- ];
164
- if (provider.includes(constants_js_1.AGENT_HUB_PROVIDER)) {
165
- lines.push(`${chalk_1.default.cyan("API URL")}: ${chalk_1.default.green(credential?.url || "N/A")}`, `${chalk_1.default.cyan("API Key")}: ${chalk_1.default.green(maskApiKey(credential?.apiKey))}`);
166
- }
167
- else {
168
- const apiKeyEnvName = Array.isArray(m.apiKeyEnvName) ? m.apiKeyEnvName : [m.apiKeyEnvName];
169
- const envKeyName = apiKeyEnvName.find((name) => name && process.env[name]);
170
- if (envKeyName) {
171
- lines.push(`${chalk_1.default.cyan("API Key")}: ${chalk_1.default.green(maskApiKey(process.env[envKeyName]))}`);
172
- }
173
- else {
174
- lines.push(`${chalk_1.default.cyan("API Key")}: ${chalk_1.default.yellow("Not found")}`);
175
- }
176
- }
177
- console.log("\n");
178
- console.log((0, boxen_1.default)(lines.join("\n"), { padding: 1, borderStyle: "classic", borderColor: "cyan" }));
179
- console.log("\n");
180
- }
181
154
  async function loadModel(model, modelOptions, options) {
182
155
  const params = {
183
156
  model: MODEL_NAME ?? model?.name ?? undefined,
@@ -192,7 +165,6 @@ async function loadModel(model, modelOptions, options) {
192
165
  if (!m)
193
166
  throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
194
167
  const credential = await (0, credential_js_1.loadCredential)({ ...options, model: `${provider}:${params.model}` });
195
- printChatModelInfoBox({ provider, model: params.model || "", credential, m });
196
168
  return m.create({
197
169
  ...(credential || {}),
198
170
  model: params.model,
@@ -1,21 +1,24 @@
1
- import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import type { OpenAIChatModelOptions } from "@aigne/openai";
3
+ import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
6
4
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
- export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
- export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
- options: HubChatModelOptions & {
5
+ export declare class AIGNEHubChatModel extends ChatModel {
6
+ options: AIGNEHubChatModelOptions & {
10
7
  apiKey?: string;
11
8
  baseURL?: string;
12
9
  url?: string;
13
10
  };
14
- private client;
15
- constructor(options: HubChatModelOptions & {
11
+ protected _client?: ChatModel;
12
+ constructor(options: AIGNEHubChatModelOptions & {
16
13
  apiKey?: string;
17
14
  baseURL?: string;
18
15
  url?: string;
19
16
  });
20
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
17
+ get client(): ChatModel | undefined;
18
+ getCredential(): {
19
+ url: string;
20
+ apiKey: any;
21
+ model: string | undefined;
22
+ };
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
24
  }
@@ -1,6 +1,7 @@
1
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
+ import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
5
  export interface AIGNEHubChatModelOptions {
5
6
  url?: string;
6
7
  apiKey?: string;
@@ -8,9 +9,15 @@ export interface AIGNEHubChatModelOptions {
8
9
  modelOptions?: ChatModelOptions;
9
10
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
10
11
  }
11
- export declare class CliAIGNEHubChatModel extends ChatModel {
12
+ export declare class AIGNEHubChatModel extends ChatModel {
12
13
  options: AIGNEHubChatModelOptions;
13
- private client;
14
+ protected _client?: BaseClient;
14
15
  constructor(options: AIGNEHubChatModelOptions);
15
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
+ get client(): BaseClient;
17
+ getCredential(): {
18
+ url: string;
19
+ apiKey: string | undefined;
20
+ model: string;
21
+ };
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
23
  }
@@ -1,6 +1,5 @@
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
- import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
3
  import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export * from "./util/constants.js";
6
5
  export * from "./util/credential.js";
@@ -8,9 +7,14 @@ export * from "./util/crypto.js";
8
7
  export * from "./util/model.js";
9
8
  export * from "./util/type.js";
10
9
  export declare class AIGNEHubChatModel extends ChatModel {
11
- options: HubChatModelOptions;
10
+ options: AIGNEHubChatModelOptions;
12
11
  private client;
13
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
14
- constructor(options: HubChatModelOptions);
13
+ constructor(options: AIGNEHubChatModelOptions);
14
+ getCredential(): {
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ };
15
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
20
  }
@@ -4,10 +4,11 @@ declare const ACCESS_KEY_SESSION_API = "/api/access-key/session";
4
4
  declare const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
5
5
  declare const AGENT_HUB_PROVIDER = "aignehub";
6
6
  declare const AIGNE_HUB_URL = "https://hub.aigne.io/";
7
+ declare const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
7
8
  declare const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = "aignehub:openai/gpt-5-mini";
8
9
  declare const DEFAULT_MODEL_PROVIDER = "openai";
9
10
  declare const isTest: string | boolean;
10
11
  declare const TEST_AIGNE_ENV_FILE: string;
11
12
  declare const PROD_AIGNE_ENV_FILE: string;
12
13
  declare const AIGNE_ENV_FILE: string;
13
- export { DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
14
+ export { DEFAULT_AIGNE_HUB_MODEL, DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
@@ -1,21 +1,24 @@
1
- import type { AnthropicChatModelOptions } from "@aigne/anthropic";
2
- import type { BedrockChatModelOptions } from "@aigne/bedrock";
3
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
4
2
  import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
5
- import type { OpenAIChatModelOptions } from "@aigne/openai";
3
+ import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
6
4
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
7
- export type HubChatModelOptions = AIGNEHubChatModelOptions | AnthropicChatModelOptions | BedrockChatModelOptions | OpenAIChatModelOptions;
8
- export declare class BlockletAIGNEHubChatModel extends ChatModel {
9
- options: HubChatModelOptions & {
5
+ export declare class AIGNEHubChatModel extends ChatModel {
6
+ options: AIGNEHubChatModelOptions & {
10
7
  apiKey?: string;
11
8
  baseURL?: string;
12
9
  url?: string;
13
10
  };
14
- private client;
15
- constructor(options: HubChatModelOptions & {
11
+ protected _client?: ChatModel;
12
+ constructor(options: AIGNEHubChatModelOptions & {
16
13
  apiKey?: string;
17
14
  baseURL?: string;
18
15
  url?: string;
19
16
  });
20
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
17
+ get client(): ChatModel | undefined;
18
+ getCredential(): {
19
+ url: string;
20
+ apiKey: any;
21
+ model: string | undefined;
22
+ };
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
24
  }
@@ -1,12 +1,14 @@
1
1
  import { ChatModel, } from "@aigne/core";
2
2
  import { AIGNE_HUB_URL } from "./util/constants.js";
3
3
  import { availableModels, findModel } from "./util/model.js";
4
- export class BlockletAIGNEHubChatModel extends ChatModel {
4
+ export class AIGNEHubChatModel extends ChatModel {
5
5
  options;
6
- client;
6
+ _client;
7
7
  constructor(options) {
8
8
  super();
9
9
  this.options = options;
10
+ }
11
+ get client() {
10
12
  const models = availableModels();
11
13
  const rawProvider = process.env.BLOCKLET_AIGNE_API_PROVIDER ?? "";
12
14
  const providerKey = rawProvider.toLowerCase().replace(/-/g, "");
@@ -24,18 +26,42 @@ export class BlockletAIGNEHubChatModel extends ChatModel {
24
26
  catch (err) {
25
27
  console.error(err);
26
28
  }
27
- const { apiKey, ...extraCredentialOptions } = credentialOptions;
28
- const params = {
29
- ...options,
30
- model: options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
31
- modelOptions: options.modelOptions,
32
- url: options.url || process.env.BLOCKLET_AIGNE_API_URL || AIGNE_HUB_URL,
33
- apiKey: options.apiKey || apiKey,
34
- ...extraCredentialOptions,
29
+ const { apiKey, url, model } = this.getCredential();
30
+ const options = {
31
+ ...this.options,
32
+ ...credentialOptions,
33
+ modelOptions: this.options.modelOptions,
34
+ model,
35
+ url,
36
+ apiKey,
37
+ };
38
+ this._client ?? modelEntry.create(options);
39
+ return this._client;
40
+ }
41
+ getCredential() {
42
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
43
+ let credentialOptions = {};
44
+ try {
45
+ credentialOptions =
46
+ typeof rawCredential === "string" ? JSON.parse(rawCredential) : (rawCredential ?? {});
47
+ }
48
+ catch (err) {
49
+ console.error(err);
50
+ }
51
+ return {
52
+ url: this.options.url || process.env.BLOCKLET_AIGNE_API_URL || AIGNE_HUB_URL,
53
+ apiKey: this.options.apiKey || credentialOptions?.apiKey,
54
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
35
55
  };
36
- this.client = modelEntry.create(params);
37
56
  }
38
57
  process(input, options) {
58
+ if (!this.client) {
59
+ throw new Error("Client not initialized");
60
+ }
61
+ options.fetchOptions = {
62
+ headers: { "x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || "" },
63
+ ...options.fetchOptions,
64
+ };
39
65
  return this.client.invoke(input, options);
40
66
  }
41
67
  }
@@ -1,6 +1,7 @@
1
- import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
+ import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
5
  export interface AIGNEHubChatModelOptions {
5
6
  url?: string;
6
7
  apiKey?: string;
@@ -8,9 +9,15 @@ export interface AIGNEHubChatModelOptions {
8
9
  modelOptions?: ChatModelOptions;
9
10
  clientOptions?: OpenAIChatModelOptions["clientOptions"];
10
11
  }
11
- export declare class CliAIGNEHubChatModel extends ChatModel {
12
+ export declare class AIGNEHubChatModel extends ChatModel {
12
13
  options: AIGNEHubChatModelOptions;
13
- private client;
14
+ protected _client?: BaseClient;
14
15
  constructor(options: AIGNEHubChatModelOptions);
15
- process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
+ get client(): BaseClient;
17
+ getCredential(): {
18
+ url: string;
19
+ apiKey: string | undefined;
20
+ model: string;
21
+ };
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
23
  }
@@ -1,10 +1,10 @@
1
1
  import { ChatModel, } from "@aigne/core";
2
2
  import { checkArguments } from "@aigne/core/utils/type-utils.js";
3
- import { BaseClient } from "@aigne/transport/http-client/base-client.js";
3
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
4
+ import { BaseClient, } from "@aigne/transport/http-client/base-client.js";
4
5
  import { joinURL } from "ufo";
5
6
  import { z } from "zod";
6
- import { AIGNE_HUB_URL } from "./util/constants.js";
7
- const DEFAULT_CHAT_MODEL = "openai/gpt-4o";
7
+ import { AIGNE_HUB_URL, DEFAULT_AIGNE_HUB_MODEL } from "./util/constants.js";
8
8
  const aigneHubChatModelOptionsSchema = z.object({
9
9
  url: z.string().optional(),
10
10
  apiKey: z.string().optional(),
@@ -21,24 +21,34 @@ const aigneHubChatModelOptionsSchema = z.object({
21
21
  .optional(),
22
22
  clientOptions: z.object({}).optional(),
23
23
  });
24
- export class CliAIGNEHubChatModel extends ChatModel {
24
+ export class AIGNEHubChatModel extends ChatModel {
25
25
  options;
26
- client;
26
+ _client;
27
27
  constructor(options) {
28
28
  checkArguments("AIGNEHubChatModel", aigneHubChatModelOptionsSchema, options);
29
29
  super();
30
30
  this.options = options;
31
- const url = options.url || process.env.AIGNE_HUB_API_URL || AIGNE_HUB_URL;
31
+ }
32
+ get client() {
33
+ const { url, apiKey, model } = this.getCredential();
34
+ const options = { ...this.options, url, apiKey, model };
35
+ this._client ??= new BaseClient(options);
36
+ return this._client;
37
+ }
38
+ getCredential() {
39
+ const url = this.options.url || process.env.AIGNE_HUB_API_URL || AIGNE_HUB_URL;
32
40
  const path = "/api/v2/chat";
33
- const params = {
34
- ...options,
41
+ return {
35
42
  url: url.endsWith(path) ? url : joinURL(url, path),
36
- model: options.model || DEFAULT_CHAT_MODEL,
37
- apiKey: options.apiKey || process.env.AIGNE_HUB_API_KEY,
43
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY,
44
+ model: this.options.model || DEFAULT_AIGNE_HUB_MODEL,
38
45
  };
39
- this.client = new BaseClient(params);
40
46
  }
41
47
  process(input, options) {
48
+ options.fetchOptions = {
49
+ headers: { "x-aigne-hub-client-did": `@aigne/aigne-hub:${nodejs.os.hostname()}` },
50
+ ...options.fetchOptions,
51
+ };
42
52
  return this.client.__invoke(undefined, input, options);
43
53
  }
44
54
  }
@@ -1,6 +1,5 @@
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
- import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
4
3
  import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export * from "./util/constants.js";
6
5
  export * from "./util/credential.js";
@@ -8,9 +7,14 @@ export * from "./util/crypto.js";
8
7
  export * from "./util/model.js";
9
8
  export * from "./util/type.js";
10
9
  export declare class AIGNEHubChatModel extends ChatModel {
11
- options: HubChatModelOptions;
10
+ options: AIGNEHubChatModelOptions;
12
11
  private client;
13
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
14
- constructor(options: HubChatModelOptions);
13
+ constructor(options: AIGNEHubChatModelOptions);
14
+ getCredential(): {
15
+ url?: string;
16
+ apiKey?: string;
17
+ model?: string;
18
+ };
15
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
16
20
  }
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ChatModel, } from "@aigne/core";
2
- import { BlockletAIGNEHubChatModel } from "./blocklet-aigne-hub-model.js";
3
- import { CliAIGNEHubChatModel } from "./cli-aigne-hub-model.js";
2
+ import { AIGNEHubChatModel as BlockletAIGNEHubChatModel } from "./blocklet-aigne-hub-model.js";
3
+ import { AIGNEHubChatModel as CliAIGNEHubChatModel, } from "./cli-aigne-hub-model.js";
4
4
  import { AIGNE_HUB_URL } from "./util/constants.js";
5
5
  import { getAIGNEHubMountPoint } from "./util/credential.js";
6
6
  export * from "./util/constants.js";
@@ -26,6 +26,9 @@ export class AIGNEHubChatModel extends ChatModel {
26
26
  const AIGNEHubModel = isBlocklet ? BlockletAIGNEHubChatModel : CliAIGNEHubChatModel;
27
27
  this.client = new AIGNEHubModel(options);
28
28
  }
29
+ getCredential() {
30
+ return this.client.getCredential();
31
+ }
29
32
  process(input, options) {
30
33
  return this.client.process(input, options);
31
34
  }
@@ -4,10 +4,11 @@ declare const ACCESS_KEY_SESSION_API = "/api/access-key/session";
4
4
  declare const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
5
5
  declare const AGENT_HUB_PROVIDER = "aignehub";
6
6
  declare const AIGNE_HUB_URL = "https://hub.aigne.io/";
7
+ declare const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
7
8
  declare const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = "aignehub:openai/gpt-5-mini";
8
9
  declare const DEFAULT_MODEL_PROVIDER = "openai";
9
10
  declare const isTest: string | boolean;
10
11
  declare const TEST_AIGNE_ENV_FILE: string;
11
12
  declare const PROD_AIGNE_ENV_FILE: string;
12
13
  declare const AIGNE_ENV_FILE: string;
13
- export { DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
14
+ export { DEFAULT_AIGNE_HUB_MODEL, DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
@@ -12,4 +12,4 @@ const isTest = process.env.CI || process.env.NODE_ENV === "test";
12
12
  const TEST_AIGNE_ENV_FILE = nodejs.path.join(nodejs.os.homedir(), ".aigne", "test-aigne-hub-connected.yaml");
13
13
  const PROD_AIGNE_ENV_FILE = nodejs.path.join(nodejs.os.homedir(), ".aigne", "aigne-hub-connected.yaml");
14
14
  const AIGNE_ENV_FILE = isTest ? TEST_AIGNE_ENV_FILE : PROD_AIGNE_ENV_FILE;
15
- export { DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
15
+ export { DEFAULT_AIGNE_HUB_MODEL, DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, AIGNE_HUB_DID, AIGNE_HUB_URL, isTest, WELLKNOWN_SERVICE_PATH_PREFIX, ACCESS_KEY_PREFIX, ACCESS_KEY_SESSION_API, AGENT_HUB_PROVIDER, TEST_AIGNE_ENV_FILE, PROD_AIGNE_ENV_FILE, AIGNE_ENV_FILE, };
@@ -1,8 +1,8 @@
1
- import crypto from "node:crypto";
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
2
  import { AesCrypter } from "@ocap/mcrypto/lib/crypter/aes-legacy.js";
3
3
  const aes = new AesCrypter();
4
- export const decrypt = (m, s, i) => aes.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
5
- export const encrypt = (m, s, i) => aes.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
4
+ export const decrypt = (m, s, i) => aes.decrypt(m, nodejs.crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
5
+ export const encrypt = (m, s, i) => aes.encrypt(m, nodejs.crypto.pbkdf2Sync(i, s, 256, 32, "sha512").toString("hex"));
6
6
  const escapeFn = (str) => str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
7
7
  const unescapeFn = (str) => (str + "===".slice((str.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
8
8
  export const encodeEncryptionKey = (key) => escapeFn(Buffer.from(key).toString("base64"));
@@ -8,10 +8,9 @@ import { OpenAIChatModel } from "@aigne/openai";
8
8
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
9
9
  import { XAIChatModel } from "@aigne/xai";
10
10
  import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler";
11
- import boxen from "boxen";
12
11
  import chalk from "chalk";
13
12
  import { HttpsProxyAgent } from "https-proxy-agent";
14
- import { AIGNEHubChatModel } from "../index.js";
13
+ import { AIGNEHubChatModel } from "../cli-aigne-hub-model.js";
15
14
  import { AGENT_HUB_PROVIDER, DEFAULT_AIGNE_HUB_PROVIDER_MODEL, DEFAULT_MODEL_PROVIDER, } from "./constants.js";
16
15
  import { loadCredential } from "./credential.js";
17
16
  const { MODEL_PROVIDER, MODEL_NAME } = nodejs.env;
@@ -140,32 +139,6 @@ export function maskApiKey(apiKey) {
140
139
  const end = apiKey.slice(-4);
141
140
  return `${start}${"*".repeat(8)}${end}`;
142
141
  }
143
- let printed = false;
144
- function printChatModelInfoBox({ provider, model, credential, m, }) {
145
- if (printed)
146
- return;
147
- printed = true;
148
- const lines = [
149
- `${chalk.cyan("Provider")}: ${chalk.green(provider)}`,
150
- `${chalk.cyan("Model")}: ${chalk.green(model)}`,
151
- ];
152
- if (provider.includes(AGENT_HUB_PROVIDER)) {
153
- lines.push(`${chalk.cyan("API URL")}: ${chalk.green(credential?.url || "N/A")}`, `${chalk.cyan("API Key")}: ${chalk.green(maskApiKey(credential?.apiKey))}`);
154
- }
155
- else {
156
- const apiKeyEnvName = Array.isArray(m.apiKeyEnvName) ? m.apiKeyEnvName : [m.apiKeyEnvName];
157
- const envKeyName = apiKeyEnvName.find((name) => name && process.env[name]);
158
- if (envKeyName) {
159
- lines.push(`${chalk.cyan("API Key")}: ${chalk.green(maskApiKey(process.env[envKeyName]))}`);
160
- }
161
- else {
162
- lines.push(`${chalk.cyan("API Key")}: ${chalk.yellow("Not found")}`);
163
- }
164
- }
165
- console.log("\n");
166
- console.log(boxen(lines.join("\n"), { padding: 1, borderStyle: "classic", borderColor: "cyan" }));
167
- console.log("\n");
168
- }
169
142
  export async function loadModel(model, modelOptions, options) {
170
143
  const params = {
171
144
  model: MODEL_NAME ?? model?.name ?? undefined,
@@ -180,7 +153,6 @@ export async function loadModel(model, modelOptions, options) {
180
153
  if (!m)
181
154
  throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
182
155
  const credential = await loadCredential({ ...options, model: `${provider}:${params.model}` });
183
- printChatModelInfoBox({ provider, model: params.model || "", credential, m });
184
156
  return m.create({
185
157
  ...(credential || {}),
186
158
  model: params.model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/aigne-hub",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "AIGNE Hub SDK for integrating with Hub AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,7 +42,6 @@
42
42
  "dependencies": {
43
43
  "@ocap/mcrypto": "^1.21.0",
44
44
  "@smithy/node-http-handler": "^4.1.0",
45
- "boxen": "^8.0.1",
46
45
  "chalk": "^5.4.1",
47
46
  "https-proxy-agent": "^7.0.6",
48
47
  "inquirer": "^12.7.0",
@@ -52,18 +51,18 @@
52
51
  "ufo": "^1.6.1",
53
52
  "yaml": "^2.8.0",
54
53
  "zod": "^3.25.67",
55
- "@aigne/anthropic": "^0.11.1",
56
- "@aigne/bedrock": "^0.9.1",
57
- "@aigne/core": "^1.49.1",
58
- "@aigne/deepseek": "^0.7.19",
59
- "@aigne/default-memory": "^1.1.1",
60
- "@aigne/gemini": "^0.9.1",
61
- "@aigne/open-router": "^0.7.19",
62
- "@aigne/ollama": "^0.7.19",
63
- "@aigne/openai": "^0.11.1",
64
- "@aigne/platform-helpers": "^0.6.1",
65
- "@aigne/xai": "^0.7.19",
66
- "@aigne/transport": "^0.13.1"
54
+ "@aigne/anthropic": "^0.11.2",
55
+ "@aigne/bedrock": "^0.9.2",
56
+ "@aigne/core": "^1.50.0",
57
+ "@aigne/default-memory": "^1.1.2",
58
+ "@aigne/deepseek": "^0.7.20",
59
+ "@aigne/gemini": "^0.9.2",
60
+ "@aigne/ollama": "^0.7.20",
61
+ "@aigne/open-router": "^0.7.20",
62
+ "@aigne/openai": "^0.11.2",
63
+ "@aigne/platform-helpers": "^0.6.2",
64
+ "@aigne/transport": "^0.14.0",
65
+ "@aigne/xai": "^0.7.20"
67
66
  },
68
67
  "devDependencies": {
69
68
  "@types/bun": "^1.2.18",
@@ -72,8 +71,8 @@
72
71
  "npm-run-all": "^4.1.5",
73
72
  "rimraf": "^6.0.1",
74
73
  "typescript": "^5.8.3",
75
- "@aigne/openai": "^0.11.1",
76
- "@aigne/test-utils": "^0.5.27"
74
+ "@aigne/openai": "^0.11.2",
75
+ "@aigne/test-utils": "^0.5.28"
77
76
  },
78
77
  "scripts": {
79
78
  "lint": "tsc --noEmit",