@aigne/aigne-hub 0.6.2 → 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 +30 -0
- package/lib/cjs/blocklet-aigne-hub-model.d.ts +5 -6
- package/lib/cjs/blocklet-aigne-hub-model.js +23 -21
- package/lib/cjs/cli-aigne-hub-model.d.ts +8 -7
- package/lib/cjs/cli-aigne-hub-model.js +14 -9
- package/lib/cjs/index.d.ts +2 -2
- package/lib/dts/blocklet-aigne-hub-model.d.ts +5 -6
- package/lib/dts/cli-aigne-hub-model.d.ts +8 -7
- package/lib/dts/index.d.ts +2 -2
- package/lib/esm/blocklet-aigne-hub-model.d.ts +5 -6
- package/lib/esm/blocklet-aigne-hub-model.js +23 -21
- package/lib/esm/cli-aigne-hub-model.d.ts +8 -7
- package/lib/esm/cli-aigne-hub-model.js +14 -9
- package/lib/esm/index.d.ts +2 -2
- package/package.json +16 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
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
|
+
|
|
3
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)
|
|
4
34
|
|
|
5
35
|
|
|
@@ -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
|
-
|
|
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):
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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,23 +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
|
|
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
|
-
|
|
62
|
-
|
|
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: {
|
|
66
|
-
"x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || process.env.ABT_NODE_DID || "",
|
|
67
|
-
},
|
|
68
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
68
69
|
...options.fetchOptions,
|
|
69
70
|
};
|
|
70
|
-
|
|
71
|
+
const client = await this.client();
|
|
72
|
+
return client.invoke(input, options);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
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
|
-
|
|
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):
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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,14 +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) {
|
|
51
54
|
const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
|
|
52
|
-
const
|
|
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;
|
|
53
57
|
options.fetchOptions = {
|
|
54
58
|
headers: { "x-aigne-hub-client-did": clientId },
|
|
55
59
|
...options.fetchOptions,
|
|
56
60
|
};
|
|
57
|
-
|
|
61
|
+
const client = await this.client();
|
|
62
|
+
return client.__invoke(undefined, input, options);
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
exports.AIGNEHubChatModel = AIGNEHubChatModel;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
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):
|
|
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
|
-
|
|
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):
|
|
22
|
+
}>;
|
|
23
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
23
24
|
}
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
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):
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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,22 +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
|
|
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
|
-
|
|
59
|
-
|
|
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: {
|
|
63
|
-
"x-aigne-hub-client-did": process.env.BLOCKLET_APP_PID || process.env.ABT_NODE_DID || "",
|
|
64
|
-
},
|
|
65
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
65
66
|
...options.fetchOptions,
|
|
66
67
|
};
|
|
67
|
-
|
|
68
|
+
const client = await this.client();
|
|
69
|
+
return client.invoke(input, options);
|
|
68
70
|
}
|
|
69
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
|
-
|
|
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):
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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,13 +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) {
|
|
48
51
|
const { BLOCKLET_APP_PID, ABT_NODE_DID } = process.env;
|
|
49
|
-
const
|
|
52
|
+
const localClientId = `@aigne/aigne-hub:${nodejs.os.hostname()}`;
|
|
53
|
+
const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || localClientId;
|
|
50
54
|
options.fetchOptions = {
|
|
51
55
|
headers: { "x-aigne-hub-client-did": clientId },
|
|
52
56
|
...options.fetchOptions,
|
|
53
57
|
};
|
|
54
|
-
|
|
58
|
+
const client = await this.client();
|
|
59
|
+
return client.__invoke(undefined, input, options);
|
|
55
60
|
}
|
|
56
61
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/aigne-hub",
|
|
3
|
-
"version": "0.6.
|
|
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.
|
|
55
|
-
"@aigne/core": "^1.50.
|
|
56
|
-
"@aigne/
|
|
57
|
-
"@aigne/
|
|
58
|
-
"@aigne/
|
|
59
|
-
"@aigne/
|
|
60
|
-
"@aigne/
|
|
61
|
-
"@aigne/
|
|
62
|
-
"@aigne/
|
|
63
|
-
"@aigne/
|
|
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.
|
|
66
|
-
"@aigne/
|
|
67
|
-
"@aigne/
|
|
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/
|
|
77
|
-
"@aigne/
|
|
76
|
+
"@aigne/openai": "^0.11.3",
|
|
77
|
+
"@aigne/test-utils": "^0.5.29"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"lint": "tsc --noEmit",
|