bfi-cli 0.1.98 → 0.1.99
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/dist/cli.mjs +65 -12
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -866,7 +866,12 @@ var SkillHubAPI = class {
|
|
|
866
866
|
try {
|
|
867
867
|
const parsed = JSON.parse(data);
|
|
868
868
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) resolve(parsed);
|
|
869
|
-
else
|
|
869
|
+
else {
|
|
870
|
+
const error = new Error(parsed.msg || parsed.message || `HTTP ${res.statusCode}`);
|
|
871
|
+
error.status = res.statusCode;
|
|
872
|
+
error.body = parsed;
|
|
873
|
+
reject(error);
|
|
874
|
+
}
|
|
870
875
|
} catch {
|
|
871
876
|
reject(new Error(data || `HTTP ${res.statusCode}`));
|
|
872
877
|
}
|
|
@@ -5783,12 +5788,8 @@ function fail(message) {
|
|
|
5783
5788
|
}
|
|
5784
5789
|
var UseCommandError = class extends Error {};
|
|
5785
5790
|
async function runLogin(args, globalOpts) {
|
|
5786
|
-
const token = getOptionValue$3(args, "--token");
|
|
5791
|
+
const token = getOptionValue$3(args, "--token") || await promptForToken();
|
|
5787
5792
|
const { registry } = resolveConfig(globalOpts);
|
|
5788
|
-
if (!token) {
|
|
5789
|
-
console.error("用法:bfi auth login --token <token>");
|
|
5790
|
-
process.exit(1);
|
|
5791
|
-
}
|
|
5792
5793
|
const api = new SkillHubAPI(registry, token);
|
|
5793
5794
|
try {
|
|
5794
5795
|
const response = await api.whoami();
|
|
@@ -5821,7 +5822,7 @@ async function runLogout() {
|
|
|
5821
5822
|
async function runWhoami(globalOpts) {
|
|
5822
5823
|
const { registry, token } = resolveConfig(globalOpts);
|
|
5823
5824
|
if (!token) {
|
|
5824
|
-
console.error("未认证。运行:bfi auth login
|
|
5825
|
+
console.error("未认证。运行:bfi auth login(在隐藏提示中输入 Token)");
|
|
5825
5826
|
process.exit(1);
|
|
5826
5827
|
}
|
|
5827
5828
|
const response = await new SkillHubAPI(registry, token).whoami();
|
|
@@ -5862,6 +5863,47 @@ async function runWhoami(globalOpts) {
|
|
|
5862
5863
|
}
|
|
5863
5864
|
console.log();
|
|
5864
5865
|
}
|
|
5866
|
+
function promptForToken() {
|
|
5867
|
+
const input = process.stdin;
|
|
5868
|
+
if (!input.isTTY || typeof input.setRawMode !== "function") throw new Error("请在交互式终端运行 `bfi auth login`,Token 将以隐藏方式输入。");
|
|
5869
|
+
process.stderr.write("请输入 SkillHub Token(输入内容隐藏): ");
|
|
5870
|
+
return new Promise((resolve, reject) => {
|
|
5871
|
+
let token = "";
|
|
5872
|
+
let finished = false;
|
|
5873
|
+
const wasRaw = input.isRaw;
|
|
5874
|
+
const cleanup = () => {
|
|
5875
|
+
if (finished) return;
|
|
5876
|
+
finished = true;
|
|
5877
|
+
input.off("data", onData);
|
|
5878
|
+
input.setRawMode(Boolean(wasRaw));
|
|
5879
|
+
input.pause();
|
|
5880
|
+
process.stderr.write("\n");
|
|
5881
|
+
};
|
|
5882
|
+
const onData = (chunk) => {
|
|
5883
|
+
for (const character of chunk.toString("utf8")) {
|
|
5884
|
+
const code = character.charCodeAt(0);
|
|
5885
|
+
if (code === 3 || code === 4) {
|
|
5886
|
+
cleanup();
|
|
5887
|
+
reject(/* @__PURE__ */ new Error("登录已取消。"));
|
|
5888
|
+
return;
|
|
5889
|
+
}
|
|
5890
|
+
if (character === "\r" || character === "\n") {
|
|
5891
|
+
cleanup();
|
|
5892
|
+
const value = token.trim();
|
|
5893
|
+
if (value) resolve(value);
|
|
5894
|
+
else reject(/* @__PURE__ */ new Error("Token 不能为空。"));
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
if (code === 8 || code === 127) token = token.slice(0, -1);
|
|
5898
|
+
else if (code >= 32 && code <= 126) token += character;
|
|
5899
|
+
}
|
|
5900
|
+
};
|
|
5901
|
+
input.setRawMode(true);
|
|
5902
|
+
input.setEncoding("utf8");
|
|
5903
|
+
input.resume();
|
|
5904
|
+
input.on("data", onData);
|
|
5905
|
+
});
|
|
5906
|
+
}
|
|
5865
5907
|
function getOptionValue$3(args, flag) {
|
|
5866
5908
|
const idx = args.indexOf(flag);
|
|
5867
5909
|
return idx !== -1 && args[idx + 1] ? args[idx + 1] : void 0;
|
|
@@ -6541,7 +6583,7 @@ async function publishFromDir(positionalArgs, api, namespace, visibility) {
|
|
|
6541
6583
|
if (res.slug) console.log(` ${BOLD$2}Slug:${RESET$4} ${TEXT$3}${res.slug}${RESET$4}`);
|
|
6542
6584
|
if (res.url) console.log(` ${BOLD$2}URL:${RESET$4} ${TEXT$3}${res.url}${RESET$4}`);
|
|
6543
6585
|
} catch (error) {
|
|
6544
|
-
|
|
6586
|
+
printPublishFailure(error, api.registry);
|
|
6545
6587
|
process.exit(1);
|
|
6546
6588
|
}
|
|
6547
6589
|
console.log();
|
|
@@ -6585,7 +6627,7 @@ async function publishFromZip(positionalArgs, api, namespace, visibility) {
|
|
|
6585
6627
|
if (res.slug) console.log(` ${BOLD$2}Slug:${RESET$4} ${TEXT$3}${res.slug}${RESET$4}`);
|
|
6586
6628
|
if (res.url) console.log(` ${BOLD$2}URL:${RESET$4} ${TEXT$3}${res.url}${RESET$4}`);
|
|
6587
6629
|
} catch (error) {
|
|
6588
|
-
if (error.message && !error.message.includes("Publish failed"))
|
|
6630
|
+
if (error.message && !error.message.includes("Publish failed")) printPublishFailure(error, api.registry);
|
|
6589
6631
|
process.exit(1);
|
|
6590
6632
|
} finally {
|
|
6591
6633
|
try {
|
|
@@ -6695,7 +6737,7 @@ async function publishFromGit(positionalArgs, api, namespace, visibility, yes, b
|
|
|
6695
6737
|
console.log(` ${GREEN$3}✓ 已发布:${namespace}--${res.slug || skill.name}${RESET$4}`);
|
|
6696
6738
|
successCount++;
|
|
6697
6739
|
} catch (error) {
|
|
6698
|
-
|
|
6740
|
+
printPublishFailure(error, api.registry, `✗ ${skill.name}:`);
|
|
6699
6741
|
}
|
|
6700
6742
|
}
|
|
6701
6743
|
console.log(`\n${GREEN$3}发布完成:${successCount}/${selectedSkills.length} 个技能${RESET$4}`);
|
|
@@ -6704,6 +6746,17 @@ async function publishFromGit(positionalArgs, api, namespace, visibility, yes, b
|
|
|
6704
6746
|
await cleanupTempDir(tmpDir);
|
|
6705
6747
|
} catch {}
|
|
6706
6748
|
}
|
|
6749
|
+
function printPublishFailure(error, registry, label = "发布失败:") {
|
|
6750
|
+
const requiredScope = error?.body?.data?.requiredScope;
|
|
6751
|
+
if (error?.status === 403 && typeof requiredScope === "string" && requiredScope) {
|
|
6752
|
+
const settingsUrl = `${registry}/dashboard/tokens`;
|
|
6753
|
+
console.error(` ${RED$2}${label}当前 API Token 缺少「${requiredScope}」权限。${RESET$4}`);
|
|
6754
|
+
console.error(` ${DIM$4}修复:打开 ${settingsUrl} 新建 Token 并勾选「技能发布」,${RESET$4}`);
|
|
6755
|
+
console.error(` ${DIM$4}然后执行 bfi auth login --token <新 Token> 后重试。${RESET$4}`);
|
|
6756
|
+
return;
|
|
6757
|
+
}
|
|
6758
|
+
console.error(` ${RED$2}${label}${error.message}${RESET$4}`);
|
|
6759
|
+
}
|
|
6707
6760
|
function getOptionValue$1(args, flag) {
|
|
6708
6761
|
const idx = args.indexOf(flag);
|
|
6709
6762
|
return idx !== -1 && idx < args.length - 1 ? args[idx + 1] : void 0;
|
|
@@ -9719,7 +9772,7 @@ ${BOLD}bfi — 用友大业财BFI统一命令行工具${RESET}
|
|
|
9719
9772
|
${BOLD}Usage:${RESET} bfi <command> [options]
|
|
9720
9773
|
|
|
9721
9774
|
${BOLD}━━━ 认证 ━━━${RESET}
|
|
9722
|
-
auth login --token <token>
|
|
9775
|
+
auth login [--token <token>] 登录 SkillHub(不带参数时隐藏输入 Token)
|
|
9723
9776
|
auth logout 登出
|
|
9724
9777
|
auth whoami 查看当前用户
|
|
9725
9778
|
|
|
@@ -9794,7 +9847,7 @@ ${BOLD}━━━ 技能引用格式 ━━━${RESET}
|
|
|
9794
9847
|
owner/repo 从 GitHub 安装
|
|
9795
9848
|
|
|
9796
9849
|
${BOLD}━━━ 示例 ━━━${RESET}
|
|
9797
|
-
${DIM}$ bfi auth login
|
|
9850
|
+
${DIM}$ bfi auth login${RESET}
|
|
9798
9851
|
${DIM}$ bfi skills search react${RESET}
|
|
9799
9852
|
${DIM}$ bfi skills add @myteam/db-explore${RESET}
|
|
9800
9853
|
${DIM}$ bfi skills add vercel-labs/agent-skills --skill pr-review${RESET}
|