@guangnao/agent-cli 1.1.4 → 1.1.5
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/README.md +3 -1
- package/dist/cli.js +65 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,9 +26,11 @@ npm i -g @guangnao/agent-cli # 全局安装,得到 gcli 命令(别名 a
|
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
gcli
|
|
29
|
-
# → 选服务商(Guangnao / DeepSeek / OpenAI / Anthropic / Gemini)→ 贴 Key → 自动列模型并选 → 进入交互
|
|
29
|
+
# → 选服务商(Guangnao / DeepSeek / OpenAI / Anthropic / Gemini / Custom)→ 贴 Key → 自动列模型并选 → 进入交互
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
> 选 **Custom** 可接任意自建端点:先选协议(OpenAI 兼容 / Anthropic 兼容)→ 填 baseURL + Key + 模型即可。
|
|
33
|
+
|
|
32
34
|
配置存到 `~/.agentos/config.json`,下次直接进,无需重填。
|
|
33
35
|
|
|
34
36
|
**方式二:环境变量** —— 适合脚本 / CI / 固定配置(**环境变量优先于已保存配置**):
|
package/dist/cli.js
CHANGED
|
@@ -9128,6 +9128,45 @@ var PromptCancelledError = class extends Error {
|
|
|
9128
9128
|
|
|
9129
9129
|
// ../agent-ui/src/prompt/text.ts
|
|
9130
9130
|
init_color();
|
|
9131
|
+
import { createInterface } from "readline";
|
|
9132
|
+
async function textPrompt(question, opts = {}) {
|
|
9133
|
+
const { default: defaultVal, placeholder, validate, transform } = opts;
|
|
9134
|
+
const hint = defaultVal ? c.meta(` [${defaultVal}]`) : placeholder ? c.meta(` (${placeholder})`) : "";
|
|
9135
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
9136
|
+
let _cancelReject;
|
|
9137
|
+
const cancelPromise = new Promise((_, reject) => {
|
|
9138
|
+
_cancelReject = reject;
|
|
9139
|
+
});
|
|
9140
|
+
rl.on("SIGINT", () => {
|
|
9141
|
+
rl.close();
|
|
9142
|
+
process.stdout.write("\n");
|
|
9143
|
+
_cancelReject(new PromptCancelledError());
|
|
9144
|
+
});
|
|
9145
|
+
try {
|
|
9146
|
+
for (; ; ) {
|
|
9147
|
+
const answer = await Promise.race([
|
|
9148
|
+
new Promise((res) => rl.question(`${c.user("?")} ${question}${hint}: `, res)),
|
|
9149
|
+
cancelPromise
|
|
9150
|
+
]);
|
|
9151
|
+
const raw = answer.trim() || (defaultVal ?? "");
|
|
9152
|
+
const value = transform ? transform(raw) : raw;
|
|
9153
|
+
if (validate) {
|
|
9154
|
+
const result = validate(value);
|
|
9155
|
+
if (result !== true) {
|
|
9156
|
+
const msg = typeof result === "string" ? result : "\u8F93\u5165\u65E0\u6548\uFF0C\u8BF7\u91CD\u8BD5";
|
|
9157
|
+
process.stdout.write(` ${c.fail("\u2717")} ${c.dim(msg)}
|
|
9158
|
+
`);
|
|
9159
|
+
continue;
|
|
9160
|
+
}
|
|
9161
|
+
}
|
|
9162
|
+
rl.close();
|
|
9163
|
+
return value;
|
|
9164
|
+
}
|
|
9165
|
+
} catch (e) {
|
|
9166
|
+
rl.close();
|
|
9167
|
+
throw e;
|
|
9168
|
+
}
|
|
9169
|
+
}
|
|
9131
9170
|
|
|
9132
9171
|
// ../agent-ui/src/prompt/select.ts
|
|
9133
9172
|
init_color();
|
|
@@ -9913,7 +9952,7 @@ import { statSync as statSync6, readFileSync as readFileSync14, unlinkSync as un
|
|
|
9913
9952
|
// package.json
|
|
9914
9953
|
var package_default = {
|
|
9915
9954
|
name: "@guangnao/agent-cli",
|
|
9916
|
-
version: "1.1.
|
|
9955
|
+
version: "1.1.5",
|
|
9917
9956
|
description: "AgentOS terminal CLI \u2014 drive a real LLM agent on the microkernel; strongest-UX shell, advanced agent core",
|
|
9918
9957
|
type: "module",
|
|
9919
9958
|
bin: {
|
|
@@ -12063,7 +12102,8 @@ var PROVIDERS = [
|
|
|
12063
12102
|
{ label: "DeepSeek", value: "deepseek", hint: "api.deepseek.com \xB7 cheap & capable" },
|
|
12064
12103
|
{ label: "OpenAI", value: "openai", hint: "api.openai.com" },
|
|
12065
12104
|
{ label: "Anthropic \xB7 Claude", value: "anthropic", hint: "api.anthropic.com" },
|
|
12066
|
-
{ label: "Google \xB7 Gemini", value: "gemini", hint: "generativelanguage.googleapis.com" }
|
|
12105
|
+
{ label: "Google \xB7 Gemini", value: "gemini", hint: "generativelanguage.googleapis.com" },
|
|
12106
|
+
{ label: "Custom", value: "custom", hint: "your own baseURL + key \xB7 OpenAI- or Anthropic-compatible" }
|
|
12067
12107
|
];
|
|
12068
12108
|
var KEY_URL = {
|
|
12069
12109
|
guangnao: "https://guangnao.com",
|
|
@@ -12089,9 +12129,24 @@ ${c.dim(" Connect an LLM provider to begin \u2014 your key is saved to ~/.agent
|
|
|
12089
12129
|
|
|
12090
12130
|
`);
|
|
12091
12131
|
try {
|
|
12092
|
-
const
|
|
12093
|
-
if (
|
|
12094
|
-
|
|
12132
|
+
const choice = await selectPrompt("Provider \u2191\u2193 select \xB7 Enter", { options: PROVIDERS });
|
|
12133
|
+
if (choice == null) return null;
|
|
12134
|
+
let provider2 = choice;
|
|
12135
|
+
let baseUrl2;
|
|
12136
|
+
if (choice === "custom") {
|
|
12137
|
+
const proto = await selectPrompt("Wire protocol \u2191\u2193 select \xB7 Enter", { options: [
|
|
12138
|
+
{ label: "OpenAI-compatible", value: "openai", hint: "POST {baseURL}/chat/completions" },
|
|
12139
|
+
{ label: "Anthropic-compatible", value: "anthropic", hint: "POST {baseURL}/messages" }
|
|
12140
|
+
] });
|
|
12141
|
+
if (proto == null) return null;
|
|
12142
|
+
provider2 = proto;
|
|
12143
|
+
baseUrl2 = (await textPrompt("Base URL", {
|
|
12144
|
+
placeholder: "https://host/v1",
|
|
12145
|
+
transform: (v) => v.trim(),
|
|
12146
|
+
validate: (v) => /^https?:\/\/.+/.test(v.trim()) || "enter a full URL, e.g. https://host/v1"
|
|
12147
|
+
})).trim();
|
|
12148
|
+
}
|
|
12149
|
+
const label2 = choice === "custom" ? `Custom \xB7 ${provider2}` : PROVIDERS.find((p) => p.value === provider2).label;
|
|
12095
12150
|
if (KEY_URL[provider2]) out(`${c.dim(" Get a key at " + KEY_URL[provider2])}
|
|
12096
12151
|
`);
|
|
12097
12152
|
for (; ; ) {
|
|
@@ -12104,7 +12159,7 @@ ${c.dim(" Connect an LLM provider to begin \u2014 your key is saved to ~/.agent
|
|
|
12104
12159
|
const fallback = defaultModel[provider2] ?? "";
|
|
12105
12160
|
let models = [];
|
|
12106
12161
|
try {
|
|
12107
|
-
models = await listModels(provider2, { apiKey: apiKey2, model: fallback });
|
|
12162
|
+
models = await listModels(provider2, { apiKey: apiKey2, model: fallback, baseUrl: baseUrl2 });
|
|
12108
12163
|
} catch {
|
|
12109
12164
|
}
|
|
12110
12165
|
if (!models.length) out(`${c.warning(" Could not list models")} ${c.dim("(unverified key or no catalog \u2014 saving anyway; switch later with /models).")}
|
|
@@ -12119,9 +12174,11 @@ ${c.dim(" Connect an LLM provider to begin \u2014 your key is saved to ~/.agent
|
|
|
12119
12174
|
});
|
|
12120
12175
|
if (sel == null) return null;
|
|
12121
12176
|
model2 = sel;
|
|
12177
|
+
} else if (baseUrl2) {
|
|
12178
|
+
model2 = (await textPrompt("Model name", { transform: (v) => v.trim(), validate: (v) => !!v.trim() || "model name required" })).trim();
|
|
12122
12179
|
}
|
|
12123
|
-
saveConfig({ provider: provider2, apiKey: apiKey2, model: model2 });
|
|
12124
|
-
out(`${c.done(" \u2713 Saved")} ${c.dim("\xB7 " + provider2 + " \xB7 " + model2)}
|
|
12180
|
+
saveConfig({ provider: provider2, apiKey: apiKey2, model: model2, baseUrl: baseUrl2 });
|
|
12181
|
+
out(`${c.done(" \u2713 Saved")} ${c.dim("\xB7 " + provider2 + " \xB7 " + model2 + (baseUrl2 ? " \xB7 " + baseUrl2 : ""))}
|
|
12125
12182
|
|
|
12126
12183
|
`);
|
|
12127
12184
|
return { provider: provider2, apiKey: apiKey2, model: model2 };
|