@aigne/aigne-hub 0.6.4 → 0.6.7
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 +69 -0
- package/lib/{esm/cli-aigne-hub-model.d.ts → cjs/aigne-hub-model.d.ts} +5 -4
- package/lib/cjs/aigne-hub-model.js +86 -0
- package/lib/cjs/index.d.ts +9 -11
- package/lib/cjs/index.js +19 -24
- package/lib/cjs/utils/blocklet.d.ts +1 -0
- package/lib/cjs/utils/blocklet.js +14 -0
- package/lib/cjs/utils/constants.d.ts +3 -0
- package/lib/cjs/utils/constants.js +6 -0
- package/lib/cjs/utils/model.d.ts +16 -0
- package/lib/cjs/utils/model.js +103 -0
- package/lib/dts/{cli-aigne-hub-model.d.ts → aigne-hub-model.d.ts} +5 -4
- package/lib/dts/index.d.ts +9 -11
- package/lib/dts/utils/blocklet.d.ts +1 -0
- package/lib/dts/utils/constants.d.ts +3 -0
- package/lib/dts/utils/model.d.ts +16 -0
- package/lib/{cjs/cli-aigne-hub-model.d.ts → esm/aigne-hub-model.d.ts} +5 -4
- package/lib/esm/aigne-hub-model.js +82 -0
- package/lib/esm/index.d.ts +9 -11
- package/lib/esm/index.js +19 -24
- package/lib/esm/utils/blocklet.d.ts +1 -0
- package/lib/esm/utils/blocklet.js +11 -0
- package/lib/esm/utils/constants.d.ts +3 -0
- package/lib/esm/utils/constants.js +3 -0
- package/lib/esm/utils/model.d.ts +16 -0
- package/lib/esm/{util → utils}/model.js +8 -82
- package/package.json +15 -28
- package/lib/cjs/blocklet-aigne-hub-model.d.ts +0 -23
- package/lib/cjs/blocklet-aigne-hub-model.js +0 -75
- package/lib/cjs/cli-aigne-hub-model.js +0 -65
- package/lib/cjs/util/constants.d.ts +0 -14
- package/lib/cjs/util/constants.js +0 -30
- package/lib/cjs/util/credential.d.ts +0 -24
- package/lib/cjs/util/credential.js +0 -226
- package/lib/cjs/util/crypto.d.ts +0 -4
- package/lib/cjs/util/crypto.js +0 -16
- package/lib/cjs/util/model.d.ts +0 -12
- package/lib/cjs/util/model.js +0 -185
- package/lib/cjs/util/type.d.ts +0 -58
- package/lib/cjs/util/type.js +0 -2
- package/lib/dts/blocklet-aigne-hub-model.d.ts +0 -23
- package/lib/dts/util/constants.d.ts +0 -14
- package/lib/dts/util/credential.d.ts +0 -24
- package/lib/dts/util/crypto.d.ts +0 -4
- package/lib/dts/util/model.d.ts +0 -12
- package/lib/dts/util/type.d.ts +0 -58
- package/lib/esm/blocklet-aigne-hub-model.d.ts +0 -23
- package/lib/esm/blocklet-aigne-hub-model.js +0 -71
- package/lib/esm/cli-aigne-hub-model.js +0 -61
- package/lib/esm/util/constants.d.ts +0 -14
- package/lib/esm/util/constants.js +0 -15
- package/lib/esm/util/credential.d.ts +0 -24
- package/lib/esm/util/credential.js +0 -214
- package/lib/esm/util/crypto.d.ts +0 -4
- package/lib/esm/util/crypto.js +0 -9
- package/lib/esm/util/model.d.ts +0 -12
- package/lib/esm/util/type.d.ts +0 -58
- package/lib/esm/util/type.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.7](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.6...aigne-hub-v0.6.7) (2025-08-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* The following workspace dependencies were updated
|
|
9
|
+
* dependencies
|
|
10
|
+
* @aigne/anthropic bumped to 0.11.7
|
|
11
|
+
* @aigne/bedrock bumped to 0.9.7
|
|
12
|
+
* @aigne/core bumped to 1.54.0
|
|
13
|
+
* @aigne/deepseek bumped to 0.7.25
|
|
14
|
+
* @aigne/doubao bumped to 1.0.19
|
|
15
|
+
* @aigne/gemini bumped to 0.9.7
|
|
16
|
+
* @aigne/ollama bumped to 0.7.25
|
|
17
|
+
* @aigne/open-router bumped to 0.7.25
|
|
18
|
+
* @aigne/openai bumped to 0.12.1
|
|
19
|
+
* @aigne/poe bumped to 1.0.5
|
|
20
|
+
* @aigne/transport bumped to 0.14.5
|
|
21
|
+
* @aigne/xai bumped to 0.7.25
|
|
22
|
+
* devDependencies
|
|
23
|
+
* @aigne/openai bumped to 0.12.1
|
|
24
|
+
* @aigne/test-utils bumped to 0.5.33
|
|
25
|
+
|
|
26
|
+
## [0.6.6](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.5...aigne-hub-v0.6.6) (2025-08-20)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* The following workspace dependencies were updated
|
|
32
|
+
* dependencies
|
|
33
|
+
* @aigne/anthropic bumped to 0.11.6
|
|
34
|
+
* @aigne/bedrock bumped to 0.9.6
|
|
35
|
+
* @aigne/core bumped to 1.53.0
|
|
36
|
+
* @aigne/deepseek bumped to 0.7.24
|
|
37
|
+
* @aigne/doubao bumped to 1.0.18
|
|
38
|
+
* @aigne/gemini bumped to 0.9.6
|
|
39
|
+
* @aigne/ollama bumped to 0.7.24
|
|
40
|
+
* @aigne/open-router bumped to 0.7.24
|
|
41
|
+
* @aigne/openai bumped to 0.12.0
|
|
42
|
+
* @aigne/poe bumped to 1.0.4
|
|
43
|
+
* @aigne/transport bumped to 0.14.4
|
|
44
|
+
* @aigne/xai bumped to 0.7.24
|
|
45
|
+
* devDependencies
|
|
46
|
+
* @aigne/openai bumped to 0.12.0
|
|
47
|
+
* @aigne/test-utils bumped to 0.5.32
|
|
48
|
+
|
|
49
|
+
## [0.6.5](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.4...aigne-hub-v0.6.5) (2025-08-20)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Dependencies
|
|
53
|
+
|
|
54
|
+
* The following workspace dependencies were updated
|
|
55
|
+
* dependencies
|
|
56
|
+
* @aigne/anthropic bumped to 0.11.5
|
|
57
|
+
* @aigne/bedrock bumped to 0.9.5
|
|
58
|
+
* @aigne/core bumped to 1.52.0
|
|
59
|
+
* @aigne/deepseek bumped to 0.7.23
|
|
60
|
+
* @aigne/doubao bumped to 1.0.17
|
|
61
|
+
* @aigne/gemini bumped to 0.9.5
|
|
62
|
+
* @aigne/ollama bumped to 0.7.23
|
|
63
|
+
* @aigne/open-router bumped to 0.7.23
|
|
64
|
+
* @aigne/openai bumped to 0.11.5
|
|
65
|
+
* @aigne/poe bumped to 1.0.3
|
|
66
|
+
* @aigne/transport bumped to 0.14.3
|
|
67
|
+
* @aigne/xai bumped to 0.7.23
|
|
68
|
+
* devDependencies
|
|
69
|
+
* @aigne/openai bumped to 0.11.5
|
|
70
|
+
* @aigne/test-utils bumped to 0.5.31
|
|
71
|
+
|
|
3
72
|
## [0.6.4](https://github.com/AIGNE-io/aigne-framework/compare/aigne-hub-v0.6.3...aigne-hub-v0.6.4) (2025-08-18)
|
|
4
73
|
|
|
5
74
|
|
|
@@ -12,12 +12,13 @@ export interface AIGNEHubChatModelOptions {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
14
14
|
options: AIGNEHubChatModelOptions;
|
|
15
|
-
protected _client?: Promise<BaseClient>;
|
|
16
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
protected _client?: Promise<BaseClient>;
|
|
17
|
+
get client(): Promise<BaseClient>;
|
|
18
|
+
private _credential?;
|
|
19
|
+
get credential(): Promise<{
|
|
19
20
|
url: string;
|
|
20
|
-
apiKey
|
|
21
|
+
apiKey?: string;
|
|
21
22
|
model: string;
|
|
22
23
|
}>;
|
|
23
24
|
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIGNEHubChatModel = void 0;
|
|
4
|
+
const core_1 = require("@aigne/core");
|
|
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");
|
|
7
|
+
const base_client_js_1 = require("@aigne/transport/http-client/base-client.js");
|
|
8
|
+
const ufo_1 = require("ufo");
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const blocklet_js_1 = require("./utils/blocklet.js");
|
|
11
|
+
const constants_js_1 = require("./utils/constants.js");
|
|
12
|
+
const aigneHubChatModelOptionsSchema = zod_1.z.object({
|
|
13
|
+
url: zod_1.z.string().optional(),
|
|
14
|
+
apiKey: zod_1.z.string().optional(),
|
|
15
|
+
model: zod_1.z.string().optional(),
|
|
16
|
+
modelOptions: zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
model: zod_1.z.string().optional(),
|
|
19
|
+
temperature: zod_1.z.number().optional(),
|
|
20
|
+
topP: zod_1.z.number().optional(),
|
|
21
|
+
frequencyPenalty: zod_1.z.number().optional(),
|
|
22
|
+
presencePenalty: zod_1.z.number().optional(),
|
|
23
|
+
parallelToolCalls: zod_1.z.boolean().optional().default(true),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
clientOptions: zod_1.z.object({}).optional(),
|
|
27
|
+
});
|
|
28
|
+
class AIGNEHubChatModel extends core_1.ChatModel {
|
|
29
|
+
options;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
(0, type_utils_js_1.checkArguments)("AIGNEHubChatModel", aigneHubChatModelOptionsSchema, options);
|
|
32
|
+
super();
|
|
33
|
+
this.options = options;
|
|
34
|
+
}
|
|
35
|
+
_client;
|
|
36
|
+
get client() {
|
|
37
|
+
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
38
|
+
const options = { ...this.options, url, apiKey, model };
|
|
39
|
+
return new base_client_js_1.BaseClient(options);
|
|
40
|
+
});
|
|
41
|
+
return this._client;
|
|
42
|
+
}
|
|
43
|
+
_credential;
|
|
44
|
+
get credential() {
|
|
45
|
+
this._credential = (0, blocklet_js_1.getAIGNEHubMountPoint)(this.options.url ||
|
|
46
|
+
process.env.BLOCKLET_AIGNE_API_URL ||
|
|
47
|
+
process.env.AIGNE_HUB_API_URL ||
|
|
48
|
+
constants_js_1.AIGNE_HUB_URL, constants_js_1.AIGNE_HUB_BLOCKLET_DID).then((url) => {
|
|
49
|
+
const path = "/api/v2/chat";
|
|
50
|
+
const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
|
|
51
|
+
let credentialOptions = {};
|
|
52
|
+
try {
|
|
53
|
+
credentialOptions =
|
|
54
|
+
typeof rawCredential === "string" ? JSON.parse(rawCredential) : (rawCredential ?? {});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error(err);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...credentialOptions,
|
|
61
|
+
url: url.endsWith(path) ? url : (0, ufo_1.joinURL)(url, path),
|
|
62
|
+
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
63
|
+
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || constants_js_1.AIGNE_HUB_DEFAULT_MODEL,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
return this._credential;
|
|
67
|
+
}
|
|
68
|
+
async process(input, options) {
|
|
69
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = index_js_1.nodejs.env;
|
|
70
|
+
const clientId = this.options?.clientOptions?.clientId ||
|
|
71
|
+
BLOCKLET_APP_PID ||
|
|
72
|
+
ABT_NODE_DID ||
|
|
73
|
+
`@aigne/aigne-hub:${typeof process !== "undefined" ? index_js_1.nodejs.os.hostname() : "unknown"}`;
|
|
74
|
+
return (await this.client).__invoke(undefined, input, {
|
|
75
|
+
...options,
|
|
76
|
+
fetchOptions: {
|
|
77
|
+
...options.fetchOptions,
|
|
78
|
+
headers: {
|
|
79
|
+
...options.fetchOptions?.headers,
|
|
80
|
+
"x-aigne-hub-client-did": clientId,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.AIGNEHubChatModel = AIGNEHubChatModel;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./util/model.js";
|
|
8
|
-
export * from "./util/type.js";
|
|
1
|
+
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
|
|
2
|
+
import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
|
|
3
|
+
import type { AIGNEHubChatModelOptions } from "./aigne-hub-model.js";
|
|
4
|
+
export * from "./utils/blocklet.js";
|
|
5
|
+
export * from "./utils/constants.js";
|
|
6
|
+
export * from "./utils/model.js";
|
|
9
7
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
10
8
|
options: AIGNEHubChatModelOptions;
|
|
11
|
-
private client;
|
|
12
9
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
13
10
|
constructor(options: AIGNEHubChatModelOptions);
|
|
14
|
-
|
|
11
|
+
protected client: ChatModel;
|
|
12
|
+
get credential(): import("@aigne/core/utils/type-utils.js").PromiseOrValue<{
|
|
15
13
|
url?: string;
|
|
16
14
|
apiKey?: string;
|
|
17
15
|
model?: string;
|
|
18
16
|
}>;
|
|
19
|
-
process(input: ChatModelInput, options:
|
|
17
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
20
18
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -16,38 +16,33 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.AIGNEHubChatModel = void 0;
|
|
18
18
|
const core_1 = require("@aigne/core");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
__exportStar(require("./util/constants.js"), exports);
|
|
24
|
-
__exportStar(require("./util/credential.js"), exports);
|
|
25
|
-
__exportStar(require("./util/crypto.js"), exports);
|
|
26
|
-
__exportStar(require("./util/model.js"), exports);
|
|
27
|
-
__exportStar(require("./util/type.js"), exports);
|
|
19
|
+
const model_js_1 = require("./utils/model.js");
|
|
20
|
+
__exportStar(require("./utils/blocklet.js"), exports);
|
|
21
|
+
__exportStar(require("./utils/constants.js"), exports);
|
|
22
|
+
__exportStar(require("./utils/model.js"), exports);
|
|
28
23
|
class AIGNEHubChatModel extends core_1.ChatModel {
|
|
29
24
|
options;
|
|
30
|
-
client;
|
|
31
25
|
static async load(options) {
|
|
32
|
-
|
|
33
|
-
let url = options.url ?? u;
|
|
34
|
-
if ((process.env.BLOCKLET_AIGNE_API_PROVIDER || "").toLocaleLowerCase().includes("aignehub")) {
|
|
35
|
-
url = await (0, credential_js_1.getAIGNEHubMountPoint)(url);
|
|
36
|
-
}
|
|
37
|
-
return new AIGNEHubChatModel({ ...options, url });
|
|
26
|
+
return new AIGNEHubChatModel(options);
|
|
38
27
|
}
|
|
39
28
|
constructor(options) {
|
|
40
|
-
|
|
29
|
+
const provider = process.env.BLOCKLET_AIGNE_API_PROVIDER || AIGNEHubChatModel.name;
|
|
30
|
+
const { match, all } = (0, model_js_1.findModel)(provider);
|
|
31
|
+
if (!match) {
|
|
32
|
+
const available = all.map((m) => m.name).join(", ");
|
|
33
|
+
throw new Error(`Unsupported model provider: ${provider} ${process.env.BLOCKLET_AIGNE_API_MODEL}. Available providers: ${available}`);
|
|
34
|
+
}
|
|
35
|
+
const client = match.create(options);
|
|
36
|
+
super({ name: client.name });
|
|
41
37
|
this.options = options;
|
|
42
|
-
|
|
43
|
-
const AIGNEHubModel = isBlocklet ? blocklet_aigne_hub_model_js_1.AIGNEHubChatModel : cli_aigne_hub_model_js_1.AIGNEHubChatModel;
|
|
44
|
-
this.client = new AIGNEHubModel(options);
|
|
38
|
+
this.client = client;
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
client;
|
|
41
|
+
get credential() {
|
|
42
|
+
return this.client.credential;
|
|
48
43
|
}
|
|
49
|
-
process(input, options) {
|
|
50
|
-
return this.client.
|
|
44
|
+
async process(input, options) {
|
|
45
|
+
return this.client.invoke(input, options);
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
48
|
exports.AIGNEHubChatModel = AIGNEHubChatModel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAIGNEHubMountPoint(url: string, component: string): Promise<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAIGNEHubMountPoint = getAIGNEHubMountPoint;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
async function getAIGNEHubMountPoint(url, component) {
|
|
6
|
+
const { origin } = new URL(url);
|
|
7
|
+
const BLOCKLET_JSON_PATH = "__blocklet__.js?type=json";
|
|
8
|
+
const blockletInfo = await fetch((0, ufo_1.joinURL)(origin, BLOCKLET_JSON_PATH));
|
|
9
|
+
const blocklet = await blockletInfo.json();
|
|
10
|
+
const comp = (blocklet?.componentMountPoints || []).find((m) => m.did === component);
|
|
11
|
+
if (!comp)
|
|
12
|
+
throw new Error(`Component ${component} not found in blocklet ${url}`);
|
|
13
|
+
return (0, ufo_1.joinURL)(origin, comp.mountPoint);
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIGNE_HUB_DEFAULT_MODEL = exports.AIGNE_HUB_BLOCKLET_DID = exports.AIGNE_HUB_URL = void 0;
|
|
4
|
+
exports.AIGNE_HUB_URL = "https://hub.aigne.io/";
|
|
5
|
+
exports.AIGNE_HUB_BLOCKLET_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
|
|
6
|
+
exports.AIGNE_HUB_DEFAULT_MODEL = "openai/gpt-5-mini";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChatModel, ChatModelOptions } from "@aigne/core";
|
|
2
|
+
export interface LoadableModel {
|
|
3
|
+
name: string | string[];
|
|
4
|
+
apiKeyEnvName?: string | string[];
|
|
5
|
+
create: (options: {
|
|
6
|
+
model?: string;
|
|
7
|
+
modelOptions?: ChatModelOptions;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
}) => ChatModel;
|
|
11
|
+
}
|
|
12
|
+
export declare function availableModels(): LoadableModel[];
|
|
13
|
+
export declare function findModel(provider: string): {
|
|
14
|
+
all: LoadableModel[];
|
|
15
|
+
match: LoadableModel | undefined;
|
|
16
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.availableModels = availableModels;
|
|
4
|
+
exports.findModel = findModel;
|
|
5
|
+
const anthropic_1 = require("@aigne/anthropic");
|
|
6
|
+
const bedrock_1 = require("@aigne/bedrock");
|
|
7
|
+
const deepseek_1 = require("@aigne/deepseek");
|
|
8
|
+
const doubao_1 = require("@aigne/doubao");
|
|
9
|
+
const gemini_1 = require("@aigne/gemini");
|
|
10
|
+
const ollama_1 = require("@aigne/ollama");
|
|
11
|
+
const open_router_1 = require("@aigne/open-router");
|
|
12
|
+
const openai_1 = require("@aigne/openai");
|
|
13
|
+
const poe_1 = require("@aigne/poe");
|
|
14
|
+
const xai_1 = require("@aigne/xai");
|
|
15
|
+
const node_http_handler_1 = require("@smithy/node-http-handler");
|
|
16
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
17
|
+
const aigne_hub_model_js_1 = require("../aigne-hub-model.js");
|
|
18
|
+
function availableModels() {
|
|
19
|
+
const proxy = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
|
|
20
|
+
.map((i) => process.env[i])
|
|
21
|
+
.filter(Boolean)[0];
|
|
22
|
+
const httpAgent = proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
|
|
23
|
+
const clientOptions = {
|
|
24
|
+
fetchOptions: {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
agent: httpAgent,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
name: openai_1.OpenAIChatModel.name,
|
|
32
|
+
apiKeyEnvName: "OPENAI_API_KEY",
|
|
33
|
+
create: (params) => new openai_1.OpenAIChatModel({ ...params, clientOptions }),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: anthropic_1.AnthropicChatModel.name,
|
|
37
|
+
apiKeyEnvName: "ANTHROPIC_API_KEY",
|
|
38
|
+
create: (params) => new anthropic_1.AnthropicChatModel({ ...params, clientOptions }),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: bedrock_1.BedrockChatModel.name,
|
|
42
|
+
apiKeyEnvName: "AWS_ACCESS_KEY_ID",
|
|
43
|
+
create: (params) => new bedrock_1.BedrockChatModel({
|
|
44
|
+
...params,
|
|
45
|
+
clientOptions: {
|
|
46
|
+
requestHandler: node_http_handler_1.NodeHttpHandler.create({ httpAgent, httpsAgent: httpAgent }),
|
|
47
|
+
streamCollector: node_http_handler_1.streamCollector,
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: deepseek_1.DeepSeekChatModel.name,
|
|
53
|
+
apiKeyEnvName: "DEEPSEEK_API_KEY",
|
|
54
|
+
create: (params) => new deepseek_1.DeepSeekChatModel({ ...params, clientOptions }),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: [gemini_1.GeminiChatModel.name, "google"],
|
|
58
|
+
apiKeyEnvName: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
|
|
59
|
+
create: (params) => new gemini_1.GeminiChatModel({ ...params, clientOptions }),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: ollama_1.OllamaChatModel.name,
|
|
63
|
+
apiKeyEnvName: "OLLAMA_API_KEY",
|
|
64
|
+
create: (params) => new ollama_1.OllamaChatModel({ ...params, clientOptions }),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: open_router_1.OpenRouterChatModel.name,
|
|
68
|
+
apiKeyEnvName: "OPEN_ROUTER_API_KEY",
|
|
69
|
+
create: (params) => new open_router_1.OpenRouterChatModel({ ...params, clientOptions }),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: xai_1.XAIChatModel.name,
|
|
73
|
+
apiKeyEnvName: "XAI_API_KEY",
|
|
74
|
+
create: (params) => new xai_1.XAIChatModel({ ...params, clientOptions }),
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: doubao_1.DoubaoChatModel.name,
|
|
78
|
+
apiKeyEnvName: "DOUBAO_API_KEY",
|
|
79
|
+
create: (params) => new doubao_1.DoubaoChatModel({ ...params, clientOptions }),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: poe_1.PoeChatModel.name,
|
|
83
|
+
apiKeyEnvName: "POE_API_KEY",
|
|
84
|
+
create: (params) => new poe_1.PoeChatModel({ ...params, clientOptions }),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: aigne_hub_model_js_1.AIGNEHubChatModel.name,
|
|
88
|
+
apiKeyEnvName: "AIGNE_HUB_API_KEY",
|
|
89
|
+
create: (params) => new aigne_hub_model_js_1.AIGNEHubChatModel({ ...params, clientOptions }),
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
function findModel(provider) {
|
|
94
|
+
provider = provider.toLowerCase().replace(/-/g, "");
|
|
95
|
+
const all = availableModels();
|
|
96
|
+
const match = all.find((m) => {
|
|
97
|
+
if (typeof m.name === "string") {
|
|
98
|
+
return m.name.toLowerCase().includes(provider);
|
|
99
|
+
}
|
|
100
|
+
return m.name.some((n) => n.toLowerCase().includes(provider));
|
|
101
|
+
});
|
|
102
|
+
return { all, match };
|
|
103
|
+
}
|
|
@@ -12,12 +12,13 @@ export interface AIGNEHubChatModelOptions {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
14
14
|
options: AIGNEHubChatModelOptions;
|
|
15
|
-
protected _client?: Promise<BaseClient>;
|
|
16
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
protected _client?: Promise<BaseClient>;
|
|
17
|
+
get client(): Promise<BaseClient>;
|
|
18
|
+
private _credential?;
|
|
19
|
+
get credential(): Promise<{
|
|
19
20
|
url: string;
|
|
20
|
-
apiKey
|
|
21
|
+
apiKey?: string;
|
|
21
22
|
model: string;
|
|
22
23
|
}>;
|
|
23
24
|
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./util/model.js";
|
|
8
|
-
export * from "./util/type.js";
|
|
1
|
+
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
|
|
2
|
+
import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
|
|
3
|
+
import type { AIGNEHubChatModelOptions } from "./aigne-hub-model.js";
|
|
4
|
+
export * from "./utils/blocklet.js";
|
|
5
|
+
export * from "./utils/constants.js";
|
|
6
|
+
export * from "./utils/model.js";
|
|
9
7
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
10
8
|
options: AIGNEHubChatModelOptions;
|
|
11
|
-
private client;
|
|
12
9
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
13
10
|
constructor(options: AIGNEHubChatModelOptions);
|
|
14
|
-
|
|
11
|
+
protected client: ChatModel;
|
|
12
|
+
get credential(): import("@aigne/core/utils/type-utils.js").PromiseOrValue<{
|
|
15
13
|
url?: string;
|
|
16
14
|
apiKey?: string;
|
|
17
15
|
model?: string;
|
|
18
16
|
}>;
|
|
19
|
-
process(input: ChatModelInput, options:
|
|
17
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
20
18
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAIGNEHubMountPoint(url: string, component: string): Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChatModel, ChatModelOptions } from "@aigne/core";
|
|
2
|
+
export interface LoadableModel {
|
|
3
|
+
name: string | string[];
|
|
4
|
+
apiKeyEnvName?: string | string[];
|
|
5
|
+
create: (options: {
|
|
6
|
+
model?: string;
|
|
7
|
+
modelOptions?: ChatModelOptions;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
}) => ChatModel;
|
|
11
|
+
}
|
|
12
|
+
export declare function availableModels(): LoadableModel[];
|
|
13
|
+
export declare function findModel(provider: string): {
|
|
14
|
+
all: LoadableModel[];
|
|
15
|
+
match: LoadableModel | undefined;
|
|
16
|
+
};
|
|
@@ -12,12 +12,13 @@ export interface AIGNEHubChatModelOptions {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
14
14
|
options: AIGNEHubChatModelOptions;
|
|
15
|
-
protected _client?: Promise<BaseClient>;
|
|
16
15
|
constructor(options: AIGNEHubChatModelOptions);
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
protected _client?: Promise<BaseClient>;
|
|
17
|
+
get client(): Promise<BaseClient>;
|
|
18
|
+
private _credential?;
|
|
19
|
+
get credential(): Promise<{
|
|
19
20
|
url: string;
|
|
20
|
-
apiKey
|
|
21
|
+
apiKey?: string;
|
|
21
22
|
model: string;
|
|
22
23
|
}>;
|
|
23
24
|
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ChatModel, } from "@aigne/core";
|
|
2
|
+
import { checkArguments } from "@aigne/core/utils/type-utils.js";
|
|
3
|
+
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
4
|
+
import { BaseClient, } from "@aigne/transport/http-client/base-client.js";
|
|
5
|
+
import { joinURL } from "ufo";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { getAIGNEHubMountPoint } from "./utils/blocklet.js";
|
|
8
|
+
import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_DEFAULT_MODEL, AIGNE_HUB_URL, } from "./utils/constants.js";
|
|
9
|
+
const aigneHubChatModelOptionsSchema = z.object({
|
|
10
|
+
url: z.string().optional(),
|
|
11
|
+
apiKey: z.string().optional(),
|
|
12
|
+
model: z.string().optional(),
|
|
13
|
+
modelOptions: z
|
|
14
|
+
.object({
|
|
15
|
+
model: z.string().optional(),
|
|
16
|
+
temperature: z.number().optional(),
|
|
17
|
+
topP: z.number().optional(),
|
|
18
|
+
frequencyPenalty: z.number().optional(),
|
|
19
|
+
presencePenalty: z.number().optional(),
|
|
20
|
+
parallelToolCalls: z.boolean().optional().default(true),
|
|
21
|
+
})
|
|
22
|
+
.optional(),
|
|
23
|
+
clientOptions: z.object({}).optional(),
|
|
24
|
+
});
|
|
25
|
+
export class AIGNEHubChatModel extends ChatModel {
|
|
26
|
+
options;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
checkArguments("AIGNEHubChatModel", aigneHubChatModelOptionsSchema, options);
|
|
29
|
+
super();
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
_client;
|
|
33
|
+
get client() {
|
|
34
|
+
this._client ??= this.credential.then(({ url, apiKey, model }) => {
|
|
35
|
+
const options = { ...this.options, url, apiKey, model };
|
|
36
|
+
return new BaseClient(options);
|
|
37
|
+
});
|
|
38
|
+
return this._client;
|
|
39
|
+
}
|
|
40
|
+
_credential;
|
|
41
|
+
get credential() {
|
|
42
|
+
this._credential = getAIGNEHubMountPoint(this.options.url ||
|
|
43
|
+
process.env.BLOCKLET_AIGNE_API_URL ||
|
|
44
|
+
process.env.AIGNE_HUB_API_URL ||
|
|
45
|
+
AIGNE_HUB_URL, AIGNE_HUB_BLOCKLET_DID).then((url) => {
|
|
46
|
+
const path = "/api/v2/chat";
|
|
47
|
+
const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
|
|
48
|
+
let credentialOptions = {};
|
|
49
|
+
try {
|
|
50
|
+
credentialOptions =
|
|
51
|
+
typeof rawCredential === "string" ? JSON.parse(rawCredential) : (rawCredential ?? {});
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
console.error(err);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...credentialOptions,
|
|
58
|
+
url: url.endsWith(path) ? url : joinURL(url, path),
|
|
59
|
+
apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
|
|
60
|
+
model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_DEFAULT_MODEL,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return this._credential;
|
|
64
|
+
}
|
|
65
|
+
async process(input, options) {
|
|
66
|
+
const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;
|
|
67
|
+
const clientId = this.options?.clientOptions?.clientId ||
|
|
68
|
+
BLOCKLET_APP_PID ||
|
|
69
|
+
ABT_NODE_DID ||
|
|
70
|
+
`@aigne/aigne-hub:${typeof process !== "undefined" ? nodejs.os.hostname() : "unknown"}`;
|
|
71
|
+
return (await this.client).__invoke(undefined, input, {
|
|
72
|
+
...options,
|
|
73
|
+
fetchOptions: {
|
|
74
|
+
...options.fetchOptions,
|
|
75
|
+
headers: {
|
|
76
|
+
...options.fetchOptions?.headers,
|
|
77
|
+
"x-aigne-hub-client-did": clientId,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./util/model.js";
|
|
8
|
-
export * from "./util/type.js";
|
|
1
|
+
import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelOutput } from "@aigne/core";
|
|
2
|
+
import type { BaseClientInvokeOptions } from "@aigne/transport/http-client/base-client.js";
|
|
3
|
+
import type { AIGNEHubChatModelOptions } from "./aigne-hub-model.js";
|
|
4
|
+
export * from "./utils/blocklet.js";
|
|
5
|
+
export * from "./utils/constants.js";
|
|
6
|
+
export * from "./utils/model.js";
|
|
9
7
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
10
8
|
options: AIGNEHubChatModelOptions;
|
|
11
|
-
private client;
|
|
12
9
|
static load(options: AIGNEHubChatModelOptions): Promise<AIGNEHubChatModel>;
|
|
13
10
|
constructor(options: AIGNEHubChatModelOptions);
|
|
14
|
-
|
|
11
|
+
protected client: ChatModel;
|
|
12
|
+
get credential(): import("@aigne/core/utils/type-utils.js").PromiseOrValue<{
|
|
15
13
|
url?: string;
|
|
16
14
|
apiKey?: string;
|
|
17
15
|
model?: string;
|
|
18
16
|
}>;
|
|
19
|
-
process(input: ChatModelInput, options:
|
|
17
|
+
process(input: ChatModelInput, options: BaseClientInvokeOptions): Promise<AgentProcessResult<ChatModelOutput>>;
|
|
20
18
|
}
|