@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 +35 -0
- package/lib/cjs/blocklet-aigne-hub-model.d.ts +13 -10
- package/lib/cjs/blocklet-aigne-hub-model.js +39 -13
- package/lib/cjs/cli-aigne-hub-model.d.ts +11 -4
- package/lib/cjs/cli-aigne-hub-model.js +21 -11
- package/lib/cjs/index.d.ts +7 -3
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/util/constants.d.ts +2 -1
- package/lib/cjs/util/constants.js +2 -1
- package/lib/cjs/util/crypto.js +3 -6
- package/lib/cjs/util/model.js +3 -31
- package/lib/dts/blocklet-aigne-hub-model.d.ts +13 -10
- package/lib/dts/cli-aigne-hub-model.d.ts +11 -4
- package/lib/dts/index.d.ts +7 -3
- package/lib/dts/util/constants.d.ts +2 -1
- package/lib/esm/blocklet-aigne-hub-model.d.ts +13 -10
- package/lib/esm/blocklet-aigne-hub-model.js +37 -11
- package/lib/esm/cli-aigne-hub-model.d.ts +11 -4
- package/lib/esm/cli-aigne-hub-model.js +21 -11
- package/lib/esm/index.d.ts +7 -3
- package/lib/esm/index.js +5 -2
- package/lib/esm/util/constants.d.ts +2 -1
- package/lib/esm/util/constants.js +1 -1
- package/lib/esm/util/crypto.js +3 -3
- package/lib/esm/util/model.js +1 -29
- package/package.json +15 -16
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
|
|
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 {
|
|
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
|
|
8
|
-
|
|
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
|
-
|
|
15
|
-
constructor(options:
|
|
11
|
+
protected _client?: ChatModel;
|
|
12
|
+
constructor(options: AIGNEHubChatModelOptions & {
|
|
16
13
|
apiKey?: string;
|
|
17
14
|
baseURL?: string;
|
|
18
15
|
url?: string;
|
|
19
16
|
});
|
|
20
|
-
|
|
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.
|
|
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
|
|
7
|
+
class AIGNEHubChatModel extends core_1.ChatModel {
|
|
8
8
|
options;
|
|
9
|
-
|
|
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,
|
|
31
|
-
const
|
|
32
|
-
...options,
|
|
33
|
-
|
|
34
|
-
modelOptions: options.modelOptions,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
71
|
+
exports.AIGNEHubChatModel = AIGNEHubChatModel;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type
|
|
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
|
|
12
|
+
export declare class AIGNEHubChatModel extends ChatModel {
|
|
12
13
|
options: AIGNEHubChatModelOptions;
|
|
13
|
-
|
|
14
|
+
protected _client?: BaseClient;
|
|
14
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
15
|
-
|
|
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.
|
|
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
|
|
27
|
+
class AIGNEHubChatModel extends core_1.ChatModel {
|
|
28
28
|
options;
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
...options,
|
|
44
|
+
return {
|
|
38
45
|
url: url.endsWith(path) ? url : (0, ufo_1.joinURL)(url, path),
|
|
39
|
-
|
|
40
|
-
|
|
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.
|
|
58
|
+
exports.AIGNEHubChatModel = AIGNEHubChatModel;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -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:
|
|
10
|
+
options: AIGNEHubChatModelOptions;
|
|
12
11
|
private client;
|
|
13
12
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
14
|
-
constructor(options:
|
|
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.
|
|
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";
|
package/lib/cjs/util/crypto.js
CHANGED
|
@@ -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
|
|
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,
|
|
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,
|
|
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, "/");
|
package/lib/cjs/util/model.js
CHANGED
|
@@ -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
|
|
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:
|
|
86
|
+
name: cli_aigne_hub_model_js_1.AIGNEHubChatModel.name,
|
|
88
87
|
apiKeyEnvName: "AIGNE_HUB_API_KEY",
|
|
89
|
-
create: (params) => new
|
|
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
|
|
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 {
|
|
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
|
|
8
|
-
|
|
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
|
-
|
|
15
|
-
constructor(options:
|
|
11
|
+
protected _client?: ChatModel;
|
|
12
|
+
constructor(options: AIGNEHubChatModelOptions & {
|
|
16
13
|
apiKey?: string;
|
|
17
14
|
baseURL?: string;
|
|
18
15
|
url?: string;
|
|
19
16
|
});
|
|
20
|
-
|
|
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
|
|
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
|
|
12
|
+
export declare class AIGNEHubChatModel extends ChatModel {
|
|
12
13
|
options: AIGNEHubChatModelOptions;
|
|
13
|
-
|
|
14
|
+
protected _client?: BaseClient;
|
|
14
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
15
|
-
|
|
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
|
}
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -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:
|
|
10
|
+
options: AIGNEHubChatModelOptions;
|
|
12
11
|
private client;
|
|
13
12
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
14
|
-
constructor(options:
|
|
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
|
|
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 {
|
|
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
|
|
8
|
-
|
|
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
|
-
|
|
15
|
-
constructor(options:
|
|
11
|
+
protected _client?: ChatModel;
|
|
12
|
+
constructor(options: AIGNEHubChatModelOptions & {
|
|
16
13
|
apiKey?: string;
|
|
17
14
|
baseURL?: string;
|
|
18
15
|
url?: string;
|
|
19
16
|
});
|
|
20
|
-
|
|
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
|
|
4
|
+
export class AIGNEHubChatModel extends ChatModel {
|
|
5
5
|
options;
|
|
6
|
-
|
|
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,
|
|
28
|
-
const
|
|
29
|
-
...options,
|
|
30
|
-
|
|
31
|
-
modelOptions: options.modelOptions,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
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
|
|
12
|
+
export declare class AIGNEHubChatModel extends ChatModel {
|
|
12
13
|
options: AIGNEHubChatModelOptions;
|
|
13
|
-
|
|
14
|
+
protected _client?: BaseClient;
|
|
14
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
15
|
-
|
|
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 {
|
|
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
|
|
24
|
+
export class AIGNEHubChatModel extends ChatModel {
|
|
25
25
|
options;
|
|
26
|
-
|
|
26
|
+
_client;
|
|
27
27
|
constructor(options) {
|
|
28
28
|
checkArguments("AIGNEHubChatModel", aigneHubChatModelOptionsSchema, options);
|
|
29
29
|
super();
|
|
30
30
|
this.options = options;
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
...options,
|
|
41
|
+
return {
|
|
35
42
|
url: url.endsWith(path) ? url : joinURL(url, path),
|
|
36
|
-
|
|
37
|
-
|
|
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
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -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:
|
|
10
|
+
options: AIGNEHubChatModelOptions;
|
|
12
11
|
private client;
|
|
13
12
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
14
|
-
constructor(options:
|
|
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, };
|
package/lib/esm/util/crypto.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
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"));
|
package/lib/esm/util/model.js
CHANGED
|
@@ -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 "../
|
|
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.
|
|
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.
|
|
56
|
-
"@aigne/bedrock": "^0.9.
|
|
57
|
-
"@aigne/core": "^1.
|
|
58
|
-
"@aigne/
|
|
59
|
-
"@aigne/
|
|
60
|
-
"@aigne/gemini": "^0.9.
|
|
61
|
-
"@aigne/
|
|
62
|
-
"@aigne/
|
|
63
|
-
"@aigne/openai": "^0.11.
|
|
64
|
-
"@aigne/platform-helpers": "^0.6.
|
|
65
|
-
"@aigne/
|
|
66
|
-
"@aigne/
|
|
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.
|
|
76
|
-
"@aigne/test-utils": "^0.5.
|
|
74
|
+
"@aigne/openai": "^0.11.2",
|
|
75
|
+
"@aigne/test-utils": "^0.5.28"
|
|
77
76
|
},
|
|
78
77
|
"scripts": {
|
|
79
78
|
"lint": "tsc --noEmit",
|