@aigne/aigne-hub 0.6.1 → 0.6.3

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,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.3](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.2...aigne-hub-v0.6.3) (2025-08-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **core:** make getCredential async for aigne-hub mount point retrieval ([#372](https://github.com/AIGNE-io/aigne-framework/issues/372)) ([34ce7a6](https://github.com/AIGNE-io/aigne-framework/commit/34ce7a645fa83994d3dfe0f29ca70098cfecac9c))
9
+ * **models:** support custom clientId for aigne-hub adapter ([#373](https://github.com/AIGNE-io/aigne-framework/issues/373)) ([0e46568](https://github.com/AIGNE-io/aigne-framework/commit/0e465683f4b34fb7456e313fa45f0cda50bb08dc))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @aigne/anthropic bumped to 0.11.3
17
+ * @aigne/bedrock bumped to 0.9.3
18
+ * @aigne/core bumped to 1.50.1
19
+ * @aigne/deepseek bumped to 0.7.21
20
+ * @aigne/default-memory bumped to 1.1.3
21
+ * @aigne/doubao bumped to 1.0.15
22
+ * @aigne/gemini bumped to 0.9.3
23
+ * @aigne/ollama bumped to 0.7.21
24
+ * @aigne/open-router bumped to 0.7.21
25
+ * @aigne/openai bumped to 0.11.3
26
+ * @aigne/poe bumped to 1.0.1
27
+ * @aigne/transport bumped to 0.14.1
28
+ * @aigne/xai bumped to 0.7.21
29
+ * devDependencies
30
+ * @aigne/openai bumped to 0.11.3
31
+ * @aigne/test-utils bumped to 0.5.29
32
+
33
+ ## [0.6.2](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.1...aigne-hub-v0.6.2) (2025-08-15)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **cli:** display only the origin URL when linking to hub ([#369](https://github.com/AIGNE-io/aigne-framework/issues/369)) ([b3baf3f](https://github.com/AIGNE-io/aigne-framework/commit/b3baf3f2c98f965d5279dd0dfb282be9f5ffb6c2))
39
+ * **model:** add x-aigne-hub-client-did header for hub model requests ([#371](https://github.com/AIGNE-io/aigne-framework/issues/371)) ([8c29f37](https://github.com/AIGNE-io/aigne-framework/commit/8c29f377d6ef3833723c8ec721a252171026d84d))
40
+
3
41
  ## [0.6.1](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.0...aigne-hub-v0.6.1) (2025-08-15)
4
42
 
5
43
 
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
- import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
3
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export declare class AIGNEHubChatModel extends ChatModel {
@@ -8,17 +7,17 @@ export declare class AIGNEHubChatModel extends ChatModel {
8
7
  baseURL?: string;
9
8
  url?: string;
10
9
  };
11
- protected _client?: ChatModel;
10
+ protected _client?: Promise<ChatModel>;
12
11
  constructor(options: AIGNEHubChatModelOptions & {
13
12
  apiKey?: string;
14
13
  baseURL?: string;
15
14
  url?: string;
16
15
  });
17
- get client(): ChatModel;
18
- getCredential(): {
16
+ client(): Promise<ChatModel>;
17
+ getCredential(): Promise<{
19
18
  url: string;
20
19
  apiKey: any;
21
20
  model: string | undefined;
22
- };
23
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
+ }>;
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
24
23
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AIGNEHubChatModel = void 0;
4
4
  const core_1 = require("@aigne/core");
5
5
  const constants_js_1 = require("./util/constants.js");
6
+ const credential_js_1 = require("./util/credential.js");
6
7
  const model_js_1 = require("./util/model.js");
7
8
  class AIGNEHubChatModel extends core_1.ChatModel {
8
9
  options;
@@ -11,7 +12,7 @@ class AIGNEHubChatModel extends core_1.ChatModel {
11
12
  super();
12
13
  this.options = options;
13
14
  }
14
- get client() {
15
+ async client() {
15
16
  const models = (0, model_js_1.availableModels)();
16
17
  const rawProvider = process.env.BLOCKLET_AIGNE_API_PROVIDER ?? "";
17
18
  const providerKey = rawProvider.toLowerCase().replace(/-/g, "");
@@ -29,19 +30,21 @@ class AIGNEHubChatModel extends core_1.ChatModel {
29
30
  catch (err) {
30
31
  console.error(err);
31
32
  }
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);
33
+ this._client ??= this.getCredential().then((credential) => {
34
+ const { apiKey, url, model } = credential;
35
+ const options = {
36
+ ...this.options,
37
+ ...credentialOptions,
38
+ modelOptions: this.options.modelOptions,
39
+ model,
40
+ url,
41
+ apiKey,
42
+ };
43
+ return modelEntry.create(options);
44
+ });
42
45
  return this._client;
43
46
  }
44
- getCredential() {
47
+ async getCredential() {
45
48
  const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
46
49
  let credentialOptions = {};
47
50
  try {
@@ -51,21 +54,22 @@ class AIGNEHubChatModel extends core_1.ChatModel {
51
54
  catch (err) {
52
55
  console.error(err);
53
56
  }
57
+ const url = await (0, credential_js_1.getAIGNEHubMountPoint)(this.options.url || process.env.BLOCKLET_AIGNE_API_URL || constants_js_1.AIGNE_HUB_URL);
54
58
  return {
55
- url: this.options.url || process.env.BLOCKLET_AIGNE_API_URL || constants_js_1.AIGNE_HUB_URL,
59
+ url,
56
60
  apiKey: this.options.apiKey || credentialOptions?.apiKey,
57
61
  model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
58
62
  };
59
63
  }
60
- process(input, options) {
61
- if (!this.client) {
62
- throw new Error("Client not initialized");
63
- }
64
+ async process(input, options) {
65
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
66
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || "";
64
67
  options.fetchOptions = {
65
- headers: { "x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || "" },
68
+ headers: { "x-aigne-hub-client-did": clientId },
66
69
  ...options.fetchOptions,
67
70
  };
68
- return this.client.invoke(input, options);
71
+ const client = await this.client();
72
+ return client.invoke(input, options);
69
73
  }
70
74
  }
71
75
  exports.AIGNEHubChatModel = AIGNEHubChatModel;
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
- import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
3
  import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
5
4
  export interface AIGNEHubChatModelOptions {
@@ -7,17 +6,19 @@ export interface AIGNEHubChatModelOptions {
7
6
  apiKey?: string;
8
7
  model?: string;
9
8
  modelOptions?: ChatModelOptions;
10
- clientOptions?: OpenAIChatModelOptions["clientOptions"];
9
+ clientOptions?: OpenAIChatModelOptions["clientOptions"] & {
10
+ clientId?: string;
11
+ };
11
12
  }
12
13
  export declare class AIGNEHubChatModel extends ChatModel {
13
14
  options: AIGNEHubChatModelOptions;
14
- protected _client?: BaseClient;
15
+ protected _client?: Promise<BaseClient>;
15
16
  constructor(options: AIGNEHubChatModelOptions);
16
- get client(): BaseClient;
17
- getCredential(): {
17
+ client(): Promise<BaseClient>;
18
+ getCredential(): Promise<{
18
19
  url: string;
19
20
  apiKey: string | undefined;
20
21
  model: string;
21
- };
22
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
22
+ }>;
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
23
24
  }
@@ -8,6 +8,7 @@ const base_client_js_1 = require("@aigne/transport/http-client/base-client.js");
8
8
  const ufo_1 = require("ufo");
9
9
  const zod_1 = require("zod");
10
10
  const constants_js_1 = require("./util/constants.js");
11
+ const credential_js_1 = require("./util/credential.js");
11
12
  const aigneHubChatModelOptionsSchema = zod_1.z.object({
12
13
  url: zod_1.z.string().optional(),
13
14
  apiKey: zod_1.z.string().optional(),
@@ -32,14 +33,16 @@ class AIGNEHubChatModel extends core_1.ChatModel {
32
33
  super();
33
34
  this.options = options;
34
35
  }
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);
36
+ async client() {
37
+ this._client ??= this.getCredential().then((credential) => {
38
+ const { url, apiKey, model } = credential;
39
+ const options = { ...this.options, url, apiKey, model };
40
+ return new base_client_js_1.BaseClient(options);
41
+ });
39
42
  return this._client;
40
43
  }
41
- getCredential() {
42
- const url = this.options.url || process.env.AIGNE_HUB_API_URL || constants_js_1.AIGNE_HUB_URL;
44
+ async getCredential() {
45
+ const url = await (0, credential_js_1.getAIGNEHubMountPoint)(this.options.url || process.env.AIGNE_HUB_API_URL || constants_js_1.AIGNE_HUB_URL);
43
46
  const path = "/api/v2/chat";
44
47
  return {
45
48
  url: url.endsWith(path) ? url : (0, ufo_1.joinURL)(url, path),
@@ -47,12 +50,16 @@ class AIGNEHubChatModel extends core_1.ChatModel {
47
50
  model: this.options.model || constants_js_1.DEFAULT_AIGNE_HUB_MODEL,
48
51
  };
49
52
  }
50
- process(input, options) {
53
+ async process(input, options) {
54
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
55
+ const localClientId = `@aigne/aigne-hub:${index_js_1.nodejs.os.hostname()}`;
56
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || localClientId;
51
57
  options.fetchOptions = {
52
- headers: { "x-aigne-hub-client-did": `@aigne/aigne-hub:${index_js_1.nodejs.os.hostname()}` },
58
+ headers: { "x-aigne-hub-client-did": clientId },
53
59
  ...options.fetchOptions,
54
60
  };
55
- return this.client.__invoke(undefined, input, options);
61
+ const client = await this.client();
62
+ return client.__invoke(undefined, input, options);
56
63
  }
57
64
  }
58
65
  exports.AIGNEHubChatModel = AIGNEHubChatModel;
@@ -11,10 +11,10 @@ export declare class AIGNEHubChatModel extends ChatModel {
11
11
  private client;
12
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
13
13
  constructor(options: AIGNEHubChatModelOptions);
14
- getCredential(): {
14
+ getCredential(): Promise<{
15
15
  url?: string;
16
16
  apiKey?: string;
17
17
  model?: string;
18
- };
18
+ }>;
19
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
20
20
  }
@@ -16,7 +16,7 @@ export declare function connectToAIGNEHub(url: string): Promise<{
16
16
  }>;
17
17
  export declare const checkConnectionStatus: (host: string) => Promise<{
18
18
  apiKey: any;
19
- url: string;
19
+ url: any;
20
20
  }>;
21
21
  export declare function loadCredential(options?: LoadCredentialOptions): Promise<{
22
22
  apiKey?: string;
@@ -84,7 +84,7 @@ async function getAIGNEHubMountPoint(url) {
84
84
  async function connectToAIGNEHub(url) {
85
85
  const { origin, host } = new URL(url);
86
86
  const connectUrl = (0, ufo_1.joinURL)(origin, constants_js_1.WELLKNOWN_SERVICE_PATH_PREFIX);
87
- const urlWithAIGNEHubMountPoint = await getAIGNEHubMountPoint(url);
87
+ const apiUrl = await getAIGNEHubMountPoint(url);
88
88
  try {
89
89
  const openFn = constants_js_1.isTest ? () => { } : open_1.default;
90
90
  const result = await createConnect({
@@ -96,7 +96,7 @@ async function connectToAIGNEHub(url) {
96
96
  });
97
97
  const accessKeyOptions = {
98
98
  apiKey: result.accessKeySecret,
99
- url: urlWithAIGNEHubMountPoint,
99
+ url: apiUrl,
100
100
  };
101
101
  // After redirection, write the AIGNE Hub access token
102
102
  const aigneDir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.homedir(), ".aigne");
@@ -140,7 +140,7 @@ const checkConnectionStatus = async (host) => {
140
140
  }
141
141
  return {
142
142
  apiKey: env.AIGNE_HUB_API_KEY,
143
- url: (0, ufo_1.joinURL)(env.AIGNE_HUB_API_URL),
143
+ url: env.AIGNE_HUB_API_URL,
144
144
  };
145
145
  };
146
146
  exports.checkConnectionStatus = checkConnectionStatus;
@@ -217,6 +217,9 @@ async function loadCredential(options) {
217
217
  }
218
218
  credential = await connectToAIGNEHub(aigneHubUrl);
219
219
  }
220
+ else {
221
+ throw error;
222
+ }
220
223
  }
221
224
  }
222
225
  return credential;
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
- import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
3
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export declare class AIGNEHubChatModel extends ChatModel {
@@ -8,17 +7,17 @@ export declare class AIGNEHubChatModel extends ChatModel {
8
7
  baseURL?: string;
9
8
  url?: string;
10
9
  };
11
- protected _client?: ChatModel;
10
+ protected _client?: Promise<ChatModel>;
12
11
  constructor(options: AIGNEHubChatModelOptions & {
13
12
  apiKey?: string;
14
13
  baseURL?: string;
15
14
  url?: string;
16
15
  });
17
- get client(): ChatModel;
18
- getCredential(): {
16
+ client(): Promise<ChatModel>;
17
+ getCredential(): Promise<{
19
18
  url: string;
20
19
  apiKey: any;
21
20
  model: string | undefined;
22
- };
23
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
+ }>;
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
24
23
  }
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
- import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
3
  import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
5
4
  export interface AIGNEHubChatModelOptions {
@@ -7,17 +6,19 @@ export interface AIGNEHubChatModelOptions {
7
6
  apiKey?: string;
8
7
  model?: string;
9
8
  modelOptions?: ChatModelOptions;
10
- clientOptions?: OpenAIChatModelOptions["clientOptions"];
9
+ clientOptions?: OpenAIChatModelOptions["clientOptions"] & {
10
+ clientId?: string;
11
+ };
11
12
  }
12
13
  export declare class AIGNEHubChatModel extends ChatModel {
13
14
  options: AIGNEHubChatModelOptions;
14
- protected _client?: BaseClient;
15
+ protected _client?: Promise<BaseClient>;
15
16
  constructor(options: AIGNEHubChatModelOptions);
16
- get client(): BaseClient;
17
- getCredential(): {
17
+ client(): Promise<BaseClient>;
18
+ getCredential(): Promise<{
18
19
  url: string;
19
20
  apiKey: string | undefined;
20
21
  model: string;
21
- };
22
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
22
+ }>;
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
23
24
  }
@@ -11,10 +11,10 @@ export declare class AIGNEHubChatModel extends ChatModel {
11
11
  private client;
12
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
13
13
  constructor(options: AIGNEHubChatModelOptions);
14
- getCredential(): {
14
+ getCredential(): Promise<{
15
15
  url?: string;
16
16
  apiKey?: string;
17
17
  model?: string;
18
- };
18
+ }>;
19
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
20
20
  }
@@ -16,7 +16,7 @@ export declare function connectToAIGNEHub(url: string): Promise<{
16
16
  }>;
17
17
  export declare const checkConnectionStatus: (host: string) => Promise<{
18
18
  apiKey: any;
19
- url: string;
19
+ url: any;
20
20
  }>;
21
21
  export declare function loadCredential(options?: LoadCredentialOptions): Promise<{
22
22
  apiKey?: string;
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
2
- import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
4
3
  import type { AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
5
4
  export declare class AIGNEHubChatModel extends ChatModel {
@@ -8,17 +7,17 @@ export declare class AIGNEHubChatModel extends ChatModel {
8
7
  baseURL?: string;
9
8
  url?: string;
10
9
  };
11
- protected _client?: ChatModel;
10
+ protected _client?: Promise<ChatModel>;
12
11
  constructor(options: AIGNEHubChatModelOptions & {
13
12
  apiKey?: string;
14
13
  baseURL?: string;
15
14
  url?: string;
16
15
  });
17
- get client(): ChatModel;
18
- getCredential(): {
16
+ client(): Promise<ChatModel>;
17
+ getCredential(): Promise<{
19
18
  url: string;
20
19
  apiKey: any;
21
20
  model: string | undefined;
22
- };
23
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
21
+ }>;
22
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
24
23
  }
@@ -1,5 +1,6 @@
1
1
  import { ChatModel, } from "@aigne/core";
2
2
  import { AIGNE_HUB_URL } from "./util/constants.js";
3
+ import { getAIGNEHubMountPoint } from "./util/credential.js";
3
4
  import { availableModels, findModel } from "./util/model.js";
4
5
  export class AIGNEHubChatModel extends ChatModel {
5
6
  options;
@@ -8,7 +9,7 @@ export class AIGNEHubChatModel extends ChatModel {
8
9
  super();
9
10
  this.options = options;
10
11
  }
11
- get client() {
12
+ async client() {
12
13
  const models = availableModels();
13
14
  const rawProvider = process.env.BLOCKLET_AIGNE_API_PROVIDER ?? "";
14
15
  const providerKey = rawProvider.toLowerCase().replace(/-/g, "");
@@ -26,19 +27,21 @@ export class AIGNEHubChatModel extends ChatModel {
26
27
  catch (err) {
27
28
  console.error(err);
28
29
  }
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);
30
+ this._client ??= this.getCredential().then((credential) => {
31
+ const { apiKey, url, model } = credential;
32
+ const options = {
33
+ ...this.options,
34
+ ...credentialOptions,
35
+ modelOptions: this.options.modelOptions,
36
+ model,
37
+ url,
38
+ apiKey,
39
+ };
40
+ return modelEntry.create(options);
41
+ });
39
42
  return this._client;
40
43
  }
41
- getCredential() {
44
+ async getCredential() {
42
45
  const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
43
46
  let credentialOptions = {};
44
47
  try {
@@ -48,20 +51,21 @@ export class AIGNEHubChatModel extends ChatModel {
48
51
  catch (err) {
49
52
  console.error(err);
50
53
  }
54
+ const url = await getAIGNEHubMountPoint(this.options.url || process.env.BLOCKLET_AIGNE_API_URL || AIGNE_HUB_URL);
51
55
  return {
52
- url: this.options.url || process.env.BLOCKLET_AIGNE_API_URL || AIGNE_HUB_URL,
56
+ url,
53
57
  apiKey: this.options.apiKey || credentialOptions?.apiKey,
54
58
  model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL,
55
59
  };
56
60
  }
57
- process(input, options) {
58
- if (!this.client) {
59
- throw new Error("Client not initialized");
60
- }
61
+ async process(input, options) {
62
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
63
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || "";
61
64
  options.fetchOptions = {
62
- headers: { "x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || "" },
65
+ headers: { "x-aigne-hub-client-did": clientId },
63
66
  ...options.fetchOptions,
64
67
  };
65
- return this.client.invoke(input, options);
68
+ const client = await this.client();
69
+ return client.invoke(input, options);
66
70
  }
67
71
  }
@@ -1,5 +1,4 @@
1
1
  import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
- import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
2
  import type { OpenAIChatModelOptions } from "@aigne/openai";
4
3
  import { BaseClient, type BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
5
4
  export interface AIGNEHubChatModelOptions {
@@ -7,17 +6,19 @@ export interface AIGNEHubChatModelOptions {
7
6
  apiKey?: string;
8
7
  model?: string;
9
8
  modelOptions?: ChatModelOptions;
10
- clientOptions?: OpenAIChatModelOptions["clientOptions"];
9
+ clientOptions?: OpenAIChatModelOptions["clientOptions"] & {
10
+ clientId?: string;
11
+ };
11
12
  }
12
13
  export declare class AIGNEHubChatModel extends ChatModel {
13
14
  options: AIGNEHubChatModelOptions;
14
- protected _client?: BaseClient;
15
+ protected _client?: Promise<BaseClient>;
15
16
  constructor(options: AIGNEHubChatModelOptions);
16
- get client(): BaseClient;
17
- getCredential(): {
17
+ client(): Promise<BaseClient>;
18
+ getCredential(): Promise<{
18
19
  url: string;
19
20
  apiKey: string | undefined;
20
21
  model: string;
21
- };
22
- process(input: ChatModelInput, options: BaseClientInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
22
+ }>;
23
+ process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
23
24
  }
@@ -5,6 +5,7 @@ import { BaseClient, } from "@aigne/transport/http-client/base-client.js";
5
5
  import { joinURL } from "ufo";
6
6
  import { z } from "zod";
7
7
  import { AIGNE_HUB_URL, DEFAULT_AIGNE_HUB_MODEL } from "./util/constants.js";
8
+ import { getAIGNEHubMountPoint } from "./util/credential.js";
8
9
  const aigneHubChatModelOptionsSchema = z.object({
9
10
  url: z.string().optional(),
10
11
  apiKey: z.string().optional(),
@@ -29,14 +30,16 @@ export class AIGNEHubChatModel extends ChatModel {
29
30
  super();
30
31
  this.options = options;
31
32
  }
32
- get client() {
33
- const { url, apiKey, model } = this.getCredential();
34
- const options = { ...this.options, url, apiKey, model };
35
- this._client ??= new BaseClient(options);
33
+ async client() {
34
+ this._client ??= this.getCredential().then((credential) => {
35
+ const { url, apiKey, model } = credential;
36
+ const options = { ...this.options, url, apiKey, model };
37
+ return new BaseClient(options);
38
+ });
36
39
  return this._client;
37
40
  }
38
- getCredential() {
39
- const url = this.options.url || process.env.AIGNE_HUB_API_URL || AIGNE_HUB_URL;
41
+ async getCredential() {
42
+ const url = await getAIGNEHubMountPoint(this.options.url || process.env.AIGNE_HUB_API_URL || AIGNE_HUB_URL);
40
43
  const path = "/api/v2/chat";
41
44
  return {
42
45
  url: url.endsWith(path) ? url : joinURL(url, path),
@@ -44,11 +47,15 @@ export class AIGNEHubChatModel extends ChatModel {
44
47
  model: this.options.model || DEFAULT_AIGNE_HUB_MODEL,
45
48
  };
46
49
  }
47
- process(input, options) {
50
+ async process(input, options) {
51
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
52
+ const localClientId = `@aigne/aigne-hub:${nodejs.os.hostname()}`;
53
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || localClientId;
48
54
  options.fetchOptions = {
49
- headers: { "x-aigne-hub-client-did": `@aigne/aigne-hub:${nodejs.os.hostname()}` },
55
+ headers: { "x-aigne-hub-client-did": clientId },
50
56
  ...options.fetchOptions,
51
57
  };
52
- return this.client.__invoke(undefined, input, options);
58
+ const client = await this.client();
59
+ return client.__invoke(undefined, input, options);
53
60
  }
54
61
  }
@@ -11,10 +11,10 @@ export declare class AIGNEHubChatModel extends ChatModel {
11
11
  private client;
12
12
  static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
13
13
  constructor(options: AIGNEHubChatModelOptions);
14
- getCredential(): {
14
+ getCredential(): Promise<{
15
15
  url?: string;
16
16
  apiKey?: string;
17
17
  model?: string;
18
- };
18
+ }>;
19
19
  process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
20
20
  }
@@ -16,7 +16,7 @@ export declare function connectToAIGNEHub(url: string): Promise<{
16
16
  }>;
17
17
  export declare const checkConnectionStatus: (host: string) => Promise<{
18
18
  apiKey: any;
19
- url: string;
19
+ url: any;
20
20
  }>;
21
21
  export declare function loadCredential(options?: LoadCredentialOptions): Promise<{
22
22
  apiKey?: string;
@@ -73,7 +73,7 @@ export async function getAIGNEHubMountPoint(url) {
73
73
  export async function connectToAIGNEHub(url) {
74
74
  const { origin, host } = new URL(url);
75
75
  const connectUrl = joinURL(origin, WELLKNOWN_SERVICE_PATH_PREFIX);
76
- const urlWithAIGNEHubMountPoint = await getAIGNEHubMountPoint(url);
76
+ const apiUrl = await getAIGNEHubMountPoint(url);
77
77
  try {
78
78
  const openFn = isTest ? () => { } : open;
79
79
  const result = await createConnect({
@@ -85,7 +85,7 @@ export async function connectToAIGNEHub(url) {
85
85
  });
86
86
  const accessKeyOptions = {
87
87
  apiKey: result.accessKeySecret,
88
- url: urlWithAIGNEHubMountPoint,
88
+ url: apiUrl,
89
89
  };
90
90
  // After redirection, write the AIGNE Hub access token
91
91
  const aigneDir = nodejs.path.join(nodejs.os.homedir(), ".aigne");
@@ -129,7 +129,7 @@ export const checkConnectionStatus = async (host) => {
129
129
  }
130
130
  return {
131
131
  apiKey: env.AIGNE_HUB_API_KEY,
132
- url: joinURL(env.AIGNE_HUB_API_URL),
132
+ url: env.AIGNE_HUB_API_URL,
133
133
  };
134
134
  };
135
135
  export async function loadCredential(options) {
@@ -205,6 +205,9 @@ export async function loadCredential(options) {
205
205
  }
206
206
  credential = await connectToAIGNEHub(aigneHubUrl);
207
207
  }
208
+ else {
209
+ throw error;
210
+ }
208
211
  }
209
212
  }
210
213
  return credential;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/aigne-hub",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "AIGNE Hub SDK for integrating with Hub AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -51,20 +51,20 @@
51
51
  "ufo": "^1.6.1",
52
52
  "yaml": "^2.8.0",
53
53
  "zod": "^3.25.67",
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/doubao": "^1.0.14",
59
- "@aigne/gemini": "^0.9.2",
60
- "@aigne/deepseek": "^0.7.20",
61
- "@aigne/ollama": "^0.7.20",
62
- "@aigne/open-router": "^0.7.20",
63
- "@aigne/openai": "^0.11.2",
54
+ "@aigne/anthropic": "^0.11.3",
55
+ "@aigne/core": "^1.50.1",
56
+ "@aigne/bedrock": "^0.9.3",
57
+ "@aigne/deepseek": "^0.7.21",
58
+ "@aigne/default-memory": "^1.1.3",
59
+ "@aigne/doubao": "^1.0.15",
60
+ "@aigne/ollama": "^0.7.21",
61
+ "@aigne/gemini": "^0.9.3",
62
+ "@aigne/open-router": "^0.7.21",
63
+ "@aigne/openai": "^0.11.3",
64
64
  "@aigne/platform-helpers": "^0.6.2",
65
- "@aigne/poe": "^1.0.0",
66
- "@aigne/transport": "^0.14.0",
67
- "@aigne/xai": "^0.7.20"
65
+ "@aigne/poe": "^1.0.1",
66
+ "@aigne/transport": "^0.14.1",
67
+ "@aigne/xai": "^0.7.21"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/bun": "^1.2.18",
@@ -73,8 +73,8 @@
73
73
  "npm-run-all": "^4.1.5",
74
74
  "rimraf": "^6.0.1",
75
75
  "typescript": "^5.8.3",
76
- "@aigne/openai": "^0.11.2",
77
- "@aigne/test-utils": "^0.5.28"
76
+ "@aigne/openai": "^0.11.3",
77
+ "@aigne/test-utils": "^0.5.29"
78
78
  },
79
79
  "scripts": {
80
80
  "lint": "tsc --noEmit",