@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 +38 -0
- package/lib/cjs/blocklet-aigne-hub-model.d.ts +5 -6
- package/lib/cjs/blocklet-aigne-hub-model.js +23 -19
- package/lib/cjs/cli-aigne-hub-model.d.ts +8 -7
- package/lib/cjs/cli-aigne-hub-model.js +16 -9
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/util/credential.d.ts +1 -1
- package/lib/cjs/util/credential.js +6 -3
- 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/dts/util/credential.d.ts +1 -1
- package/lib/esm/blocklet-aigne-hub-model.d.ts +5 -6
- package/lib/esm/blocklet-aigne-hub-model.js +23 -19
- package/lib/esm/cli-aigne-hub-model.d.ts +8 -7
- package/lib/esm/cli-aigne-hub-model.js +16 -9
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/util/credential.d.ts +1 -1
- package/lib/esm/util/credential.js +6 -3
- package/package.json +16 -16
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
|
-
|
|
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,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
|
|
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: { "x-aigne-hub-client-did":
|
|
68
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
66
69
|
...options.fetchOptions,
|
|
67
70
|
};
|
|
68
|
-
|
|
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
|
-
|
|
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,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":
|
|
58
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
53
59
|
...options.fetchOptions,
|
|
54
60
|
};
|
|
55
|
-
|
|
61
|
+
const client = await this.client();
|
|
62
|
+
return client.__invoke(undefined, input, options);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
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
|
}
|
|
@@ -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:
|
|
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
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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:
|
|
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
|
-
|
|
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,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
|
|
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: { "x-aigne-hub-client-did":
|
|
65
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
63
66
|
...options.fetchOptions,
|
|
64
67
|
};
|
|
65
|
-
|
|
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
|
-
|
|
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,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":
|
|
55
|
+
headers: { "x-aigne-hub-client-did": clientId },
|
|
50
56
|
...options.fetchOptions,
|
|
51
57
|
};
|
|
52
|
-
|
|
58
|
+
const client = await this.client();
|
|
59
|
+
return client.__invoke(undefined, input, options);
|
|
53
60
|
}
|
|
54
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
|
}
|
|
@@ -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:
|
|
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
|
|
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:
|
|
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:
|
|
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.
|
|
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/
|
|
56
|
-
"@aigne/
|
|
57
|
-
"@aigne/
|
|
58
|
-
"@aigne/
|
|
59
|
-
"@aigne/
|
|
60
|
-
"@aigne/
|
|
61
|
-
"@aigne/
|
|
62
|
-
"@aigne/open-router": "^0.7.
|
|
63
|
-
"@aigne/openai": "^0.11.
|
|
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/transport": "^0.14.
|
|
67
|
-
"@aigne/xai": "^0.7.
|
|
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.
|
|
77
|
-
"@aigne/test-utils": "^0.5.
|
|
76
|
+
"@aigne/openai": "^0.11.3",
|
|
77
|
+
"@aigne/test-utils": "^0.5.29"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"lint": "tsc --noEmit",
|