agent2agent-cli 0.3.0 → 0.3.1
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/a2a.js +28 -11
- package/package.json +1 -1
package/a2a.js
CHANGED
|
@@ -689,10 +689,19 @@ const SKILL_FILES = [
|
|
|
689
689
|
'rules/cursor.mdc',
|
|
690
690
|
];
|
|
691
691
|
|
|
692
|
-
/**
|
|
692
|
+
/** 下载单个文件到目标(带超时,避免网络挂起;失败抛明确错误) */
|
|
693
693
|
async function downloadTo(relPath, destDir) {
|
|
694
694
|
const url = `${SKILLS_RAW_BASE}/${relPath}`;
|
|
695
|
-
const
|
|
695
|
+
const ctrl = new AbortController();
|
|
696
|
+
const timer = setTimeout(() => ctrl.abort(), 20000); // 20s 超时
|
|
697
|
+
let res;
|
|
698
|
+
try {
|
|
699
|
+
res = await fetch(url, { headers: { 'User-Agent': 'a2a-cli' }, signal: ctrl.signal });
|
|
700
|
+
} catch (e) {
|
|
701
|
+
clearTimeout(timer);
|
|
702
|
+
throw new Error(`连接超时/失败(${SKILLS_RAW_BASE.replace(/^https?:\/\//, '')}),无法访问 GitHub 下载源;可稍后重试,或设置镜像源:A2A_SKILLS_URL=<可访问的镜像地址>`);
|
|
703
|
+
}
|
|
704
|
+
clearTimeout(timer);
|
|
696
705
|
if (!res.ok) throw new Error(`下载失败 ${relPath} (HTTP ${res.status})`);
|
|
697
706
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
698
707
|
const dest = path.join(destDir, ...relPath.split('/'));
|
|
@@ -743,24 +752,31 @@ async function cmdUpdateSkills(opts) {
|
|
|
743
752
|
|
|
744
753
|
console.log(hl('===== a2a update-skills ====='));
|
|
745
754
|
for (const t of targets) console.log(` 将更新: [${t.label}]`);
|
|
755
|
+
|
|
746
756
|
if (!autoYes && process.stdin.isTTY) {
|
|
747
757
|
console.log('');
|
|
748
|
-
process.stdout.write('确认更新?(y/N) ');
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
758
|
+
process.stdout.write(paint(C.dim, '确认更新?(y/N,30 秒无输入自动取消) '));
|
|
759
|
+
const nextLine = createLineReader();
|
|
760
|
+
const ans = await Promise.race([
|
|
761
|
+
nextLine(),
|
|
762
|
+
new Promise((r) => setTimeout(() => r(''), 30000)),
|
|
763
|
+
]);
|
|
764
|
+
if (!/^y/i.test(String(ans || ''))) {
|
|
765
|
+
console.log(paint(C.yellow, '已取消(可用 a2a update-skills --yes 跳过确认)'));
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
754
768
|
} else if (!autoYes && !process.stdin.isTTY) {
|
|
755
769
|
console.log(paint(C.yellow, '(非交互环境:加 --yes 跳过确认)'));
|
|
756
770
|
if (!process.env.A2A_AUTO_UPDATE) return;
|
|
757
771
|
}
|
|
758
772
|
|
|
773
|
+
console.log(paint(C.dim, `下载源: ${SKILLS_RAW_BASE}(网络较慢时可用 A2A_SKILLS_URL 指定镜像)`));
|
|
759
774
|
let okCount = 0;
|
|
760
775
|
for (const t of targets) {
|
|
761
776
|
try {
|
|
762
777
|
if (t.type === 'cursor') {
|
|
763
778
|
// 规则目录:写入 a2a.mdc,删除旧文件名
|
|
779
|
+
process.stdout.write(` ⏳ ${t.label} 下载中...`);
|
|
764
780
|
const dest = await downloadTo('rules/cursor.mdc', t.dir);
|
|
765
781
|
const renamed = path.join(t.dir, 'a2a.mdc');
|
|
766
782
|
fs.renameSync(dest, renamed);
|
|
@@ -768,14 +784,15 @@ async function cmdUpdateSkills(opts) {
|
|
|
768
784
|
const p = path.join(t.dir, old);
|
|
769
785
|
if (fs.existsSync(p)) { try { fs.unlinkSync(p); } catch (e) { /* ignore */ } }
|
|
770
786
|
}
|
|
771
|
-
console.log(
|
|
787
|
+
console.log(`\r ✓ ${t.label} → ${renamed}`);
|
|
772
788
|
} else {
|
|
789
|
+
process.stdout.write(` ⏳ ${t.label} 下载中...`);
|
|
773
790
|
for (const rel of SKILL_FILES) await downloadTo(rel, t.dir);
|
|
774
|
-
console.log(
|
|
791
|
+
console.log(`\r ✓ ${t.label} → ${t.dir}(${SKILL_FILES.length} 个文件)`);
|
|
775
792
|
}
|
|
776
793
|
okCount++;
|
|
777
794
|
} catch (e) {
|
|
778
|
-
console.log(
|
|
795
|
+
console.log(`\r ✗ ${t.label} 更新失败: ${paint(C.red, e.message)}`);
|
|
779
796
|
}
|
|
780
797
|
}
|
|
781
798
|
console.log(hl(`更新完成(成功 ${okCount}/${targets.length})`));
|