@aigne/aigne-hub 0.4.8 → 0.5.0
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 +62 -0
- package/lib/cjs/blocklet-aigne-hub-model.js +4 -3
- package/lib/cjs/cli-aigne-hub-model.js +1 -1
- package/lib/cjs/index.d.ts +5 -1
- package/lib/cjs/index.js +8 -3
- package/lib/cjs/util/constants.d.ts +13 -0
- package/lib/cjs/util/constants.js +29 -0
- package/lib/cjs/util/credential.d.ts +24 -0
- package/lib/cjs/util/credential.js +223 -0
- package/lib/cjs/util/crypto.d.ts +4 -0
- package/lib/cjs/util/crypto.js +19 -0
- package/lib/cjs/util/model.d.ts +12 -0
- package/lib/cjs/util/model.js +201 -0
- package/lib/cjs/util/type.d.ts +58 -0
- package/lib/cjs/util/type.js +2 -0
- package/lib/dts/index.d.ts +5 -1
- package/lib/dts/util/constants.d.ts +13 -0
- package/lib/dts/util/credential.d.ts +24 -0
- package/lib/dts/util/crypto.d.ts +4 -0
- package/lib/dts/util/model.d.ts +12 -0
- package/lib/dts/util/type.d.ts +58 -0
- package/lib/esm/blocklet-aigne-hub-model.js +2 -1
- package/lib/esm/cli-aigne-hub-model.js +1 -1
- package/lib/esm/index.d.ts +5 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/util/constants.d.ts +13 -0
- package/lib/esm/util/constants.js +15 -0
- package/lib/esm/util/credential.d.ts +24 -0
- package/lib/esm/util/credential.js +211 -0
- package/lib/esm/util/crypto.d.ts +4 -0
- package/lib/esm/util/crypto.js +9 -0
- package/lib/esm/util/model.d.ts +12 -0
- package/lib/esm/util/model.js +189 -0
- package/lib/esm/util/type.d.ts +58 -0
- package/lib/esm/util/type.js +1 -0
- package/package.json +22 -15
- package/lib/cjs/constants.d.ts +0 -28
- package/lib/cjs/constants.js +0 -123
- package/lib/dts/constants.d.ts +0 -28
- package/lib/esm/constants.d.ts +0 -28
- package/lib/esm/constants.js +0 -116
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatModelName = exports.parseModelOption = void 0;
|
|
7
|
+
exports.availableModels = availableModels;
|
|
8
|
+
exports.findModel = findModel;
|
|
9
|
+
exports.maskApiKey = maskApiKey;
|
|
10
|
+
exports.loadModel = loadModel;
|
|
11
|
+
const anthropic_1 = require("@aigne/anthropic");
|
|
12
|
+
const bedrock_1 = require("@aigne/bedrock");
|
|
13
|
+
const deepseek_1 = require("@aigne/deepseek");
|
|
14
|
+
const gemini_1 = require("@aigne/gemini");
|
|
15
|
+
const ollama_1 = require("@aigne/ollama");
|
|
16
|
+
const open_router_1 = require("@aigne/open-router");
|
|
17
|
+
const openai_1 = require("@aigne/openai");
|
|
18
|
+
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
19
|
+
const xai_1 = require("@aigne/xai");
|
|
20
|
+
const node_http_handler_1 = require("@smithy/node-http-handler");
|
|
21
|
+
const boxen_1 = __importDefault(require("boxen"));
|
|
22
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
23
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
24
|
+
const index_js_2 = require("../index.js");
|
|
25
|
+
const constants_js_1 = require("./constants.js");
|
|
26
|
+
const credential_js_1 = require("./credential.js");
|
|
27
|
+
const { MODEL_PROVIDER, MODEL_NAME } = index_js_1.nodejs.env;
|
|
28
|
+
function availableModels() {
|
|
29
|
+
const proxy = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"]
|
|
30
|
+
.map((i) => process.env[i])
|
|
31
|
+
.filter(Boolean)[0];
|
|
32
|
+
const httpAgent = proxy ? new https_proxy_agent_1.HttpsProxyAgent(proxy) : undefined;
|
|
33
|
+
const clientOptions = {
|
|
34
|
+
fetchOptions: {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
agent: httpAgent,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
name: openai_1.OpenAIChatModel.name,
|
|
42
|
+
apiKeyEnvName: "OPENAI_API_KEY",
|
|
43
|
+
create: (params) => new openai_1.OpenAIChatModel({ ...params, clientOptions }),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: anthropic_1.AnthropicChatModel.name,
|
|
47
|
+
apiKeyEnvName: "ANTHROPIC_API_KEY",
|
|
48
|
+
create: (params) => new anthropic_1.AnthropicChatModel({ ...params, clientOptions }),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: bedrock_1.BedrockChatModel.name,
|
|
52
|
+
apiKeyEnvName: "AWS_ACCESS_KEY_ID",
|
|
53
|
+
create: (params) => new bedrock_1.BedrockChatModel({
|
|
54
|
+
...params,
|
|
55
|
+
clientOptions: {
|
|
56
|
+
requestHandler: node_http_handler_1.NodeHttpHandler.create({ httpAgent, httpsAgent: httpAgent }),
|
|
57
|
+
streamCollector: node_http_handler_1.streamCollector,
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: deepseek_1.DeepSeekChatModel.name,
|
|
63
|
+
apiKeyEnvName: "DEEPSEEK_API_KEY",
|
|
64
|
+
create: (params) => new deepseek_1.DeepSeekChatModel({ ...params, clientOptions }),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: [gemini_1.GeminiChatModel.name, "google"],
|
|
68
|
+
apiKeyEnvName: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
|
|
69
|
+
create: (params) => new gemini_1.GeminiChatModel({ ...params, clientOptions }),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: ollama_1.OllamaChatModel.name,
|
|
73
|
+
apiKeyEnvName: "OLLAMA_API_KEY",
|
|
74
|
+
create: (params) => new ollama_1.OllamaChatModel({ ...params, clientOptions }),
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: open_router_1.OpenRouterChatModel.name,
|
|
78
|
+
apiKeyEnvName: "OPEN_ROUTER_API_KEY",
|
|
79
|
+
create: (params) => new open_router_1.OpenRouterChatModel({ ...params, clientOptions }),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: xai_1.XAIChatModel.name,
|
|
83
|
+
apiKeyEnvName: "XAI_API_KEY",
|
|
84
|
+
create: (params) => new xai_1.XAIChatModel({ ...params, clientOptions }),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: index_js_2.AIGNEHubChatModel.name,
|
|
88
|
+
apiKeyEnvName: "AIGNE_HUB_API_KEY",
|
|
89
|
+
create: (params) => new index_js_2.AIGNEHubChatModel({ ...params, clientOptions }),
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
function findModel(models, provider) {
|
|
94
|
+
return models.find((m) => {
|
|
95
|
+
if (typeof m.name === "string") {
|
|
96
|
+
return m.name.toLowerCase().includes(provider.toLowerCase());
|
|
97
|
+
}
|
|
98
|
+
return m.name.some((n) => n.toLowerCase().includes(provider.toLowerCase()));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const parseModelOption = (model) => {
|
|
102
|
+
const { provider, name } = (model || process.env.MODEL)?.match(/(?<provider>[^:]*)(:(?<name>(\S+)))?/)?.groups ?? {};
|
|
103
|
+
return { provider, name };
|
|
104
|
+
};
|
|
105
|
+
exports.parseModelOption = parseModelOption;
|
|
106
|
+
const formatModelName = async (model, inquirerPrompt) => {
|
|
107
|
+
const models = availableModels();
|
|
108
|
+
if (!model)
|
|
109
|
+
return constants_js_1.DEFAULT_AIGNE_HUB_PROVIDER_MODEL;
|
|
110
|
+
const { provider, name } = (0, exports.parseModelOption)(model);
|
|
111
|
+
if (!provider) {
|
|
112
|
+
return constants_js_1.DEFAULT_AIGNE_HUB_PROVIDER_MODEL;
|
|
113
|
+
}
|
|
114
|
+
const providerName = provider.replace(/-/g, "");
|
|
115
|
+
if (providerName.includes(constants_js_1.AGENT_HUB_PROVIDER)) {
|
|
116
|
+
return model;
|
|
117
|
+
}
|
|
118
|
+
const m = findModel(models, providerName);
|
|
119
|
+
if (!m)
|
|
120
|
+
throw new Error(`Unsupported model: ${provider} ${name}`);
|
|
121
|
+
const apiKeyEnvName = Array.isArray(m.apiKeyEnvName) ? m.apiKeyEnvName : [m.apiKeyEnvName];
|
|
122
|
+
if (apiKeyEnvName.some((name) => name && process.env[name])) {
|
|
123
|
+
return model;
|
|
124
|
+
}
|
|
125
|
+
const result = await inquirerPrompt({
|
|
126
|
+
type: "list",
|
|
127
|
+
name: "useAigneHub",
|
|
128
|
+
message: `Seems no API Key configured for ${provider}/${name}, select your preferred way to continue:`,
|
|
129
|
+
choices: [
|
|
130
|
+
{
|
|
131
|
+
name: `Connect to AIGNE Hub to use ${name} (Recommended since free credits available)`,
|
|
132
|
+
value: true,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: `Exit and bring my owner API Key by set ${apiKeyEnvName.join(", ")}`,
|
|
136
|
+
value: false,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
default: true,
|
|
140
|
+
});
|
|
141
|
+
if (!result.useAigneHub) {
|
|
142
|
+
console.log(chalk_1.default.yellow(`You can use command "export ${apiKeyEnvName[0]}=xxx" to set API Key in your shell. Or you can set environment variables in .env file.`));
|
|
143
|
+
process.exit(0);
|
|
144
|
+
}
|
|
145
|
+
return `${constants_js_1.AGENT_HUB_PROVIDER}:${provider}/${name}`;
|
|
146
|
+
};
|
|
147
|
+
exports.formatModelName = formatModelName;
|
|
148
|
+
function maskApiKey(apiKey) {
|
|
149
|
+
if (!apiKey || apiKey.length <= 8)
|
|
150
|
+
return apiKey;
|
|
151
|
+
const start = apiKey.slice(0, 4);
|
|
152
|
+
const end = apiKey.slice(-4);
|
|
153
|
+
return `${start}${"*".repeat(8)}${end}`;
|
|
154
|
+
}
|
|
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
|
+
async function loadModel(model, modelOptions, options) {
|
|
182
|
+
const params = {
|
|
183
|
+
model: MODEL_NAME ?? model?.name ?? undefined,
|
|
184
|
+
temperature: model?.temperature ?? undefined,
|
|
185
|
+
topP: model?.topP ?? undefined,
|
|
186
|
+
frequencyPenalty: model?.frequencyPenalty ?? undefined,
|
|
187
|
+
presencePenalty: model?.presencePenalty ?? undefined,
|
|
188
|
+
};
|
|
189
|
+
const provider = (MODEL_PROVIDER ?? model?.provider ?? constants_js_1.DEFAULT_MODEL_PROVIDER).replace(/-/g, "");
|
|
190
|
+
const models = availableModels();
|
|
191
|
+
const m = findModel(models, provider);
|
|
192
|
+
if (!m)
|
|
193
|
+
throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
|
|
194
|
+
const credential = await (0, credential_js_1.loadCredential)({ ...options, model: `${provider}:${params.model}` });
|
|
195
|
+
printChatModelInfoBox({ provider, model: params.model || "", credential, m });
|
|
196
|
+
return m.create({
|
|
197
|
+
...(credential || {}),
|
|
198
|
+
model: params.model,
|
|
199
|
+
modelOptions: { ...params, ...modelOptions },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
|
|
2
|
+
export type Model = {
|
|
3
|
+
provider?: string | null;
|
|
4
|
+
name?: string | null;
|
|
5
|
+
temperature?: number | null;
|
|
6
|
+
topP?: number | null;
|
|
7
|
+
frequencyPenalty?: number | null;
|
|
8
|
+
presencePenalty?: number | null;
|
|
9
|
+
} | undefined;
|
|
10
|
+
type InquirerPromptFn = (prompt: {
|
|
11
|
+
type: string;
|
|
12
|
+
name: string;
|
|
13
|
+
message: string;
|
|
14
|
+
choices: {
|
|
15
|
+
name: string;
|
|
16
|
+
value: any;
|
|
17
|
+
}[];
|
|
18
|
+
default: any;
|
|
19
|
+
}) => Promise<any>;
|
|
20
|
+
export type LoadCredentialOptions = {
|
|
21
|
+
model?: string;
|
|
22
|
+
aigneHubUrl?: string;
|
|
23
|
+
inquirerPromptFn?: InquirerPromptFn;
|
|
24
|
+
};
|
|
25
|
+
export interface LoadableModel {
|
|
26
|
+
name: string | string[];
|
|
27
|
+
apiKeyEnvName?: string | string[];
|
|
28
|
+
create: (options: {
|
|
29
|
+
model?: string;
|
|
30
|
+
modelOptions?: ChatModelOptions;
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
}) => ChatModel;
|
|
34
|
+
}
|
|
35
|
+
export type FetchResult = {
|
|
36
|
+
accessKeyId: string;
|
|
37
|
+
accessKeySecret: string;
|
|
38
|
+
};
|
|
39
|
+
export type BaseWrapSpinner = (_: string, waiting: () => Promise<FetchResult>) => Promise<FetchResult>;
|
|
40
|
+
export interface CreateConnectOptions {
|
|
41
|
+
connectUrl: string;
|
|
42
|
+
openPage?: (url: string) => void;
|
|
43
|
+
fetchInterval?: number;
|
|
44
|
+
retry?: number;
|
|
45
|
+
source?: string;
|
|
46
|
+
connectAction?: string;
|
|
47
|
+
appName?: string;
|
|
48
|
+
appLogo?: string;
|
|
49
|
+
wrapSpinner?: BaseWrapSpinner;
|
|
50
|
+
prettyUrl?: (url: string) => string;
|
|
51
|
+
closeOnSuccess?: boolean;
|
|
52
|
+
intervalFetchConfig?: (options: {
|
|
53
|
+
sessionId: string;
|
|
54
|
+
fetchInterval: number;
|
|
55
|
+
fetchTimeout: number;
|
|
56
|
+
}) => Promise<FetchResult>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatM
|
|
|
2
2
|
import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
|
|
4
4
|
import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
|
|
5
|
-
export * from "./constants.js";
|
|
5
|
+
export * from "./util/constants.js";
|
|
6
|
+
export * from "./util/credential.js";
|
|
7
|
+
export * from "./util/crypto.js";
|
|
8
|
+
export * from "./util/model.js";
|
|
9
|
+
export * from "./util/type.js";
|
|
6
10
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
7
11
|
options: HubChatModelOptions;
|
|
8
12
|
private client;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
2
|
+
declare const ACCESS_KEY_PREFIX = "/api/access-key";
|
|
3
|
+
declare const ACCESS_KEY_SESSION_API = "/api/access-key/session";
|
|
4
|
+
declare const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
|
|
5
|
+
declare const AGENT_HUB_PROVIDER = "aignehub";
|
|
6
|
+
declare const AIGNE_HUB_URL = "https://hub.aigne.io/";
|
|
7
|
+
declare const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = "aignehub:openai/gpt-5-mini";
|
|
8
|
+
declare const DEFAULT_MODEL_PROVIDER = "openai";
|
|
9
|
+
declare const isTest: string | boolean;
|
|
10
|
+
declare const TEST_AIGNE_ENV_FILE: string;
|
|
11
|
+
declare const PROD_AIGNE_ENV_FILE: string;
|
|
12
|
+
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, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CreateConnectOptions, FetchResult, LoadCredentialOptions } from "./type.js";
|
|
2
|
+
export declare const fetchConfigs: ({ connectUrl, sessionId, fetchInterval, fetchTimeout, }: {
|
|
3
|
+
connectUrl: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
fetchInterval: number;
|
|
6
|
+
fetchTimeout: number;
|
|
7
|
+
}) => Promise<any>;
|
|
8
|
+
export declare function createConnect({ connectUrl, openPage, fetchInterval, retry, source, connectAction, wrapSpinner, closeOnSuccess, intervalFetchConfig, appName, appLogo, }: CreateConnectOptions): Promise<FetchResult>;
|
|
9
|
+
export declare function getAIGNEHubMountPoint(url: string): Promise<string>;
|
|
10
|
+
export declare function connectToAIGNEHub(url: string): Promise<{
|
|
11
|
+
apiKey: string;
|
|
12
|
+
url: string;
|
|
13
|
+
} | {
|
|
14
|
+
apiKey: undefined;
|
|
15
|
+
url: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const checkConnectionStatus: (host: string) => Promise<{
|
|
18
|
+
apiKey: any;
|
|
19
|
+
url: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function loadCredential(options?: LoadCredentialOptions): Promise<{
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
} | undefined>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const decrypt: (m: string, s: string, i: string) => string;
|
|
2
|
+
export declare const encrypt: (m: string, s: string, i: string) => string;
|
|
3
|
+
export declare const encodeEncryptionKey: (key: string) => string;
|
|
4
|
+
export declare const decodeEncryptionKey: (str: string) => Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
|
|
2
|
+
import type inquirer from "inquirer";
|
|
3
|
+
import type { LoadableModel, LoadCredentialOptions, Model } from "./type.js";
|
|
4
|
+
export declare function availableModels(): LoadableModel[];
|
|
5
|
+
export declare function findModel(models: LoadableModel[], provider: string): LoadableModel | undefined;
|
|
6
|
+
export declare const parseModelOption: (model?: string) => {
|
|
7
|
+
provider: string | undefined;
|
|
8
|
+
name: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare const formatModelName: (model: string, inquirerPrompt: typeof inquirer.prompt) => Promise<string>;
|
|
11
|
+
export declare function maskApiKey(apiKey?: string): string | undefined;
|
|
12
|
+
export declare function loadModel(model?: Model, modelOptions?: ChatModelOptions, options?: LoadCredentialOptions): Promise<ChatModel | undefined>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ChatModel, ChatModelOptions } from "@aigne/core/agents/chat-model.js";
|
|
2
|
+
export type Model = {
|
|
3
|
+
provider?: string | null;
|
|
4
|
+
name?: string | null;
|
|
5
|
+
temperature?: number | null;
|
|
6
|
+
topP?: number | null;
|
|
7
|
+
frequencyPenalty?: number | null;
|
|
8
|
+
presencePenalty?: number | null;
|
|
9
|
+
} | undefined;
|
|
10
|
+
type InquirerPromptFn = (prompt: {
|
|
11
|
+
type: string;
|
|
12
|
+
name: string;
|
|
13
|
+
message: string;
|
|
14
|
+
choices: {
|
|
15
|
+
name: string;
|
|
16
|
+
value: any;
|
|
17
|
+
}[];
|
|
18
|
+
default: any;
|
|
19
|
+
}) => Promise<any>;
|
|
20
|
+
export type LoadCredentialOptions = {
|
|
21
|
+
model?: string;
|
|
22
|
+
aigneHubUrl?: string;
|
|
23
|
+
inquirerPromptFn?: InquirerPromptFn;
|
|
24
|
+
};
|
|
25
|
+
export interface LoadableModel {
|
|
26
|
+
name: string | string[];
|
|
27
|
+
apiKeyEnvName?: string | string[];
|
|
28
|
+
create: (options: {
|
|
29
|
+
model?: string;
|
|
30
|
+
modelOptions?: ChatModelOptions;
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
}) => ChatModel;
|
|
34
|
+
}
|
|
35
|
+
export type FetchResult = {
|
|
36
|
+
accessKeyId: string;
|
|
37
|
+
accessKeySecret: string;
|
|
38
|
+
};
|
|
39
|
+
export type BaseWrapSpinner = (_: string, waiting: () => Promise<FetchResult>) => Promise<FetchResult>;
|
|
40
|
+
export interface CreateConnectOptions {
|
|
41
|
+
connectUrl: string;
|
|
42
|
+
openPage?: (url: string) => void;
|
|
43
|
+
fetchInterval?: number;
|
|
44
|
+
retry?: number;
|
|
45
|
+
source?: string;
|
|
46
|
+
connectAction?: string;
|
|
47
|
+
appName?: string;
|
|
48
|
+
appLogo?: string;
|
|
49
|
+
wrapSpinner?: BaseWrapSpinner;
|
|
50
|
+
prettyUrl?: (url: string) => string;
|
|
51
|
+
closeOnSuccess?: boolean;
|
|
52
|
+
intervalFetchConfig?: (options: {
|
|
53
|
+
sessionId: string;
|
|
54
|
+
fetchInterval: number;
|
|
55
|
+
fetchTimeout: number;
|
|
56
|
+
}) => Promise<FetchResult>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChatModel, } from "@aigne/core";
|
|
2
|
-
import { AIGNE_HUB_URL
|
|
2
|
+
import { AIGNE_HUB_URL } from "./util/constants.js";
|
|
3
|
+
import { availableModels, findModel } from "./util/model.js";
|
|
3
4
|
export class BlockletAIGNEHubChatModel extends ChatModel {
|
|
4
5
|
options;
|
|
5
6
|
client;
|
|
@@ -3,7 +3,7 @@ import { checkArguments } from "@aigne/core/utils/type-utils.js";
|
|
|
3
3
|
import { BaseClient } from "@aigne/transport/http-client/base-client.js";
|
|
4
4
|
import { joinURL } from "ufo";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { AIGNE_HUB_URL } from "./constants.js";
|
|
6
|
+
import { AIGNE_HUB_URL } from "./util/constants.js";
|
|
7
7
|
const DEFAULT_CHAT_MODEL = "openai/gpt-4o";
|
|
8
8
|
const aigneHubChatModelOptionsSchema = z.object({
|
|
9
9
|
url: z.string().optional(),
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { type AgentInvokeOptions, type AgentProcessResult, ChatModel, type ChatM
|
|
|
2
2
|
import type { PromiseOrValue } from "@aigne/core/utils/type-utils.js";
|
|
3
3
|
import { type HubChatModelOptions } from "./blocklet-aigne-hub-model.js";
|
|
4
4
|
import { type AIGNEHubChatModelOptions } from "./cli-aigne-hub-model.js";
|
|
5
|
-
export * from "./constants.js";
|
|
5
|
+
export * from "./util/constants.js";
|
|
6
|
+
export * from "./util/credential.js";
|
|
7
|
+
export * from "./util/crypto.js";
|
|
8
|
+
export * from "./util/model.js";
|
|
9
|
+
export * from "./util/type.js";
|
|
6
10
|
export declare class AIGNEHubChatModel extends ChatModel {
|
|
7
11
|
options: HubChatModelOptions;
|
|
8
12
|
private client;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { ChatModel, } from "@aigne/core";
|
|
2
2
|
import { BlockletAIGNEHubChatModel } from "./blocklet-aigne-hub-model.js";
|
|
3
3
|
import { CliAIGNEHubChatModel } from "./cli-aigne-hub-model.js";
|
|
4
|
-
import { AIGNE_HUB_URL
|
|
5
|
-
|
|
4
|
+
import { AIGNE_HUB_URL } from "./util/constants.js";
|
|
5
|
+
import { getAIGNEHubMountPoint } from "./util/credential.js";
|
|
6
|
+
export * from "./util/constants.js";
|
|
7
|
+
export * from "./util/credential.js";
|
|
8
|
+
export * from "./util/crypto.js";
|
|
9
|
+
export * from "./util/model.js";
|
|
10
|
+
export * from "./util/type.js";
|
|
6
11
|
export class AIGNEHubChatModel extends ChatModel {
|
|
7
12
|
options;
|
|
8
13
|
client;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
2
|
+
declare const ACCESS_KEY_PREFIX = "/api/access-key";
|
|
3
|
+
declare const ACCESS_KEY_SESSION_API = "/api/access-key/session";
|
|
4
|
+
declare const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
|
|
5
|
+
declare const AGENT_HUB_PROVIDER = "aignehub";
|
|
6
|
+
declare const AIGNE_HUB_URL = "https://hub.aigne.io/";
|
|
7
|
+
declare const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = "aignehub:openai/gpt-5-mini";
|
|
8
|
+
declare const DEFAULT_MODEL_PROVIDER = "openai";
|
|
9
|
+
declare const isTest: string | boolean;
|
|
10
|
+
declare const TEST_AIGNE_ENV_FILE: string;
|
|
11
|
+
declare const PROD_AIGNE_ENV_FILE: string;
|
|
12
|
+
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, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
2
|
+
const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
3
|
+
const ACCESS_KEY_PREFIX = "/api/access-key";
|
|
4
|
+
const ACCESS_KEY_SESSION_API = `${ACCESS_KEY_PREFIX}/session`;
|
|
5
|
+
const AIGNE_HUB_DID = "z8ia3xzq2tMq8CRHfaXj1BTYJyYnEcHbqP8cJ";
|
|
6
|
+
const AGENT_HUB_PROVIDER = "aignehub";
|
|
7
|
+
const AIGNE_HUB_URL = "https://hub.aigne.io/";
|
|
8
|
+
const DEFAULT_AIGNE_HUB_MODEL = "openai/gpt-5-mini";
|
|
9
|
+
const DEFAULT_AIGNE_HUB_PROVIDER_MODEL = `${AGENT_HUB_PROVIDER}:${DEFAULT_AIGNE_HUB_MODEL}`;
|
|
10
|
+
const DEFAULT_MODEL_PROVIDER = "openai";
|
|
11
|
+
const isTest = process.env.CI || process.env.NODE_ENV === "test";
|
|
12
|
+
const TEST_AIGNE_ENV_FILE = nodejs.path.join(nodejs.os.homedir(), ".aigne", "test-aigne-hub-connected.yaml");
|
|
13
|
+
const PROD_AIGNE_ENV_FILE = nodejs.path.join(nodejs.os.homedir(), ".aigne", "aigne-hub-connected.yaml");
|
|
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, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CreateConnectOptions, FetchResult, LoadCredentialOptions } from "./type.js";
|
|
2
|
+
export declare const fetchConfigs: ({ connectUrl, sessionId, fetchInterval, fetchTimeout, }: {
|
|
3
|
+
connectUrl: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
fetchInterval: number;
|
|
6
|
+
fetchTimeout: number;
|
|
7
|
+
}) => Promise<any>;
|
|
8
|
+
export declare function createConnect({ connectUrl, openPage, fetchInterval, retry, source, connectAction, wrapSpinner, closeOnSuccess, intervalFetchConfig, appName, appLogo, }: CreateConnectOptions): Promise<FetchResult>;
|
|
9
|
+
export declare function getAIGNEHubMountPoint(url: string): Promise<string>;
|
|
10
|
+
export declare function connectToAIGNEHub(url: string): Promise<{
|
|
11
|
+
apiKey: string;
|
|
12
|
+
url: string;
|
|
13
|
+
} | {
|
|
14
|
+
apiKey: undefined;
|
|
15
|
+
url: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const checkConnectionStatus: (host: string) => Promise<{
|
|
18
|
+
apiKey: any;
|
|
19
|
+
url: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function loadCredential(options?: LoadCredentialOptions): Promise<{
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
} | undefined>;
|