openclaw-openviking-setup-helper 0.2.10 → 0.2.11
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/install.js +147 -23
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -31,9 +31,11 @@ import { fileURLToPath } from "node:url";
|
|
|
31
31
|
|
|
32
32
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
33
33
|
|
|
34
|
-
let REPO = process.env.REPO || "volcengine/OpenViking";
|
|
35
|
-
// PLUGIN_VERSION takes precedence over BRANCH (legacy)
|
|
36
|
-
|
|
34
|
+
let REPO = process.env.REPO || "volcengine/OpenViking";
|
|
35
|
+
// PLUGIN_VERSION takes precedence over BRANCH (legacy). If omitted, resolve the latest tag from GitHub.
|
|
36
|
+
const pluginVersionEnv = (process.env.PLUGIN_VERSION || process.env.BRANCH || "").trim();
|
|
37
|
+
let PLUGIN_VERSION = pluginVersionEnv;
|
|
38
|
+
let pluginVersionExplicit = Boolean(pluginVersionEnv);
|
|
37
39
|
const NPM_REGISTRY = process.env.NPM_REGISTRY || "https://registry.npmmirror.com";
|
|
38
40
|
const PIP_INDEX_URL = process.env.PIP_INDEX_URL || "https://mirrors.volces.com/pypi/simple/";
|
|
39
41
|
|
|
@@ -148,20 +150,27 @@ for (let i = 0; i < argv.length; i++) {
|
|
|
148
150
|
i += 1;
|
|
149
151
|
continue;
|
|
150
152
|
}
|
|
151
|
-
if (arg.startsWith("--plugin-version=")) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
if (arg.startsWith("--plugin-version=")) {
|
|
154
|
+
const version = arg.slice("--plugin-version=".length).trim();
|
|
155
|
+
if (!version) {
|
|
156
|
+
console.error("--plugin-version requires a value");
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
PLUGIN_VERSION = version;
|
|
160
|
+
pluginVersionExplicit = true;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
155
163
|
if (arg === "--plugin-version") {
|
|
156
164
|
const version = argv[i + 1]?.trim();
|
|
157
165
|
if (!version) {
|
|
158
166
|
console.error("--plugin-version requires a value");
|
|
159
167
|
process.exit(1);
|
|
160
|
-
}
|
|
161
|
-
PLUGIN_VERSION = version;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
}
|
|
169
|
+
PLUGIN_VERSION = version;
|
|
170
|
+
pluginVersionExplicit = true;
|
|
171
|
+
i += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
165
174
|
if (arg.startsWith("--openviking-version=")) {
|
|
166
175
|
openvikingVersion = arg.slice("--openviking-version=".length).trim();
|
|
167
176
|
continue;
|
|
@@ -209,7 +218,7 @@ function printHelp() {
|
|
|
209
218
|
console.log("");
|
|
210
219
|
console.log("Options:");
|
|
211
220
|
console.log(" --github-repo=OWNER/REPO GitHub repository (default: volcengine/OpenViking)");
|
|
212
|
-
console.log(" --plugin-version=TAG Plugin version (Git tag, e.g. v0.2.9, default:
|
|
221
|
+
console.log(" --plugin-version=TAG Plugin version (Git tag, e.g. v0.2.9, default: latest tag)");
|
|
213
222
|
console.log(" --openviking-version=V OpenViking PyPI version (e.g. 0.2.9, default: latest)");
|
|
214
223
|
console.log(" --workdir PATH OpenClaw config directory (default: ~/.openclaw)");
|
|
215
224
|
console.log(" --repo=PATH Use local OpenViking repo at PATH (pip -e + local plugin)");
|
|
@@ -231,7 +240,7 @@ function printHelp() {
|
|
|
231
240
|
console.log(" # Install specific plugin version");
|
|
232
241
|
console.log(" node install.js --plugin-version=v0.2.8");
|
|
233
242
|
console.log("");
|
|
234
|
-
console.log(" # Upgrade only the plugin files");
|
|
243
|
+
console.log(" # Upgrade only the plugin files from main branch");
|
|
235
244
|
console.log(" node install.js --update --plugin-version=main");
|
|
236
245
|
console.log("");
|
|
237
246
|
console.log(" # Roll back the last plugin upgrade");
|
|
@@ -618,8 +627,122 @@ async function testRemoteFile(url) {
|
|
|
618
627
|
return false;
|
|
619
628
|
}
|
|
620
629
|
|
|
621
|
-
|
|
622
|
-
|
|
630
|
+
function compareSemverDesc(a, b) {
|
|
631
|
+
if (versionGte(a, b) && versionGte(b, a)) {
|
|
632
|
+
return 0;
|
|
633
|
+
}
|
|
634
|
+
return versionGte(a, b) ? -1 : 1;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function pickLatestPluginTag(tagNames) {
|
|
638
|
+
const normalized = tagNames
|
|
639
|
+
.map((tag) => String(tag ?? "").trim())
|
|
640
|
+
.filter(Boolean);
|
|
641
|
+
|
|
642
|
+
const semverTags = normalized
|
|
643
|
+
.filter((tag) => isSemverLike(tag))
|
|
644
|
+
.sort(compareSemverDesc);
|
|
645
|
+
|
|
646
|
+
if (semverTags.length > 0) {
|
|
647
|
+
return semverTags[0];
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return normalized[0] || "";
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function parseGitLsRemoteTags(output) {
|
|
654
|
+
return String(output ?? "")
|
|
655
|
+
.split(/\r?\n/)
|
|
656
|
+
.map((line) => {
|
|
657
|
+
const match = line.match(/refs\/tags\/(.+)$/);
|
|
658
|
+
return match?.[1]?.trim() || "";
|
|
659
|
+
})
|
|
660
|
+
.filter(Boolean);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async function resolveDefaultPluginVersion() {
|
|
664
|
+
if (PLUGIN_VERSION) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
info(tr(
|
|
669
|
+
`No plugin version specified; resolving latest tag from ${REPO}...`,
|
|
670
|
+
`未指定插件版本,正在解析 ${REPO} 的最新 tag...`,
|
|
671
|
+
));
|
|
672
|
+
|
|
673
|
+
const failures = [];
|
|
674
|
+
const apiUrl = `https://api.github.com/repos/${REPO}/tags?per_page=100`;
|
|
675
|
+
|
|
676
|
+
try {
|
|
677
|
+
const controller = new AbortController();
|
|
678
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
679
|
+
const response = await fetch(apiUrl, {
|
|
680
|
+
headers: {
|
|
681
|
+
Accept: "application/vnd.github+json",
|
|
682
|
+
"User-Agent": "openviking-setup-helper",
|
|
683
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
684
|
+
},
|
|
685
|
+
signal: controller.signal,
|
|
686
|
+
});
|
|
687
|
+
clearTimeout(timeoutId);
|
|
688
|
+
|
|
689
|
+
if (response.ok) {
|
|
690
|
+
const payload = await response.json().catch(() => null);
|
|
691
|
+
if (Array.isArray(payload)) {
|
|
692
|
+
const latestTag = pickLatestPluginTag(payload.map((item) => item?.name || ""));
|
|
693
|
+
if (latestTag) {
|
|
694
|
+
PLUGIN_VERSION = latestTag;
|
|
695
|
+
info(tr(
|
|
696
|
+
`Resolved default plugin version to latest tag: ${PLUGIN_VERSION}`,
|
|
697
|
+
`已将默认插件版本解析为最新 tag: ${PLUGIN_VERSION}`,
|
|
698
|
+
));
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
} else {
|
|
702
|
+
failures.push("GitHub tags API returned an unexpected payload");
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
failures.push(`GitHub tags API returned HTTP ${response.status}`);
|
|
706
|
+
}
|
|
707
|
+
} catch (error) {
|
|
708
|
+
failures.push(`GitHub tags API failed: ${String(error)}`);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const gitRef = `https://github.com/${REPO}.git`;
|
|
712
|
+
const gitResult = await runCapture("git", ["ls-remote", "--tags", "--refs", gitRef], {
|
|
713
|
+
shell: IS_WIN,
|
|
714
|
+
});
|
|
715
|
+
if (gitResult.code === 0 && gitResult.out) {
|
|
716
|
+
const latestTag = pickLatestPluginTag(parseGitLsRemoteTags(gitResult.out));
|
|
717
|
+
if (latestTag) {
|
|
718
|
+
PLUGIN_VERSION = latestTag;
|
|
719
|
+
info(tr(
|
|
720
|
+
`Resolved default plugin version via git tags: ${PLUGIN_VERSION}`,
|
|
721
|
+
`已通过 git tag 解析默认插件版本: ${PLUGIN_VERSION}`,
|
|
722
|
+
));
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
failures.push("git ls-remote returned no usable tags");
|
|
726
|
+
} else {
|
|
727
|
+
failures.push(`git ls-remote failed${gitResult.err ? `: ${gitResult.err}` : ""}`);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
err(tr(
|
|
731
|
+
`Could not resolve the latest tag for ${REPO}.`,
|
|
732
|
+
`无法解析 ${REPO} 的最新 tag。`,
|
|
733
|
+
));
|
|
734
|
+
console.log(tr(
|
|
735
|
+
"Please rerun with --plugin-version <tag>, or use --plugin-version main to track the branch head explicitly.",
|
|
736
|
+
"请使用 --plugin-version <tag> 重新执行;如果需要显式跟踪分支头,请使用 --plugin-version main。",
|
|
737
|
+
));
|
|
738
|
+
if (failures.length > 0) {
|
|
739
|
+
warn(failures.join(" | "));
|
|
740
|
+
}
|
|
741
|
+
process.exit(1);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// Resolve plugin configuration from manifest or fallback
|
|
745
|
+
async function resolvePluginConfig() {
|
|
623
746
|
const ghRaw = `https://raw.githubusercontent.com/${REPO}/${PLUGIN_VERSION}`;
|
|
624
747
|
|
|
625
748
|
info(tr(`Resolving plugin configuration for version: ${PLUGIN_VERSION}`, `正在解析插件配置,版本: ${PLUGIN_VERSION}`));
|
|
@@ -741,9 +864,9 @@ async function checkOpenClawCompatibility() {
|
|
|
741
864
|
}
|
|
742
865
|
|
|
743
866
|
// If user explicitly requested an old version, pass
|
|
744
|
-
if (
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
867
|
+
if (isSemverLike(PLUGIN_VERSION) && !versionGte(PLUGIN_VERSION, "v0.2.8")) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
747
870
|
|
|
748
871
|
// Check compatibility
|
|
749
872
|
if (!versionGte(ocVersion, resolvedMinOpenclawVersion)) {
|
|
@@ -1949,13 +2072,14 @@ async function main() {
|
|
|
1949
2072
|
await selectWorkdir();
|
|
1950
2073
|
if (rollbackLastUpgrade) {
|
|
1951
2074
|
info(tr("Mode: rollback last plugin upgrade", "模式: 回滚最近一次插件升级"));
|
|
1952
|
-
if (
|
|
1953
|
-
warn("--plugin-version is ignored in --rollback mode.");
|
|
1954
|
-
}
|
|
2075
|
+
if (pluginVersionExplicit) {
|
|
2076
|
+
warn("--plugin-version is ignored in --rollback mode.");
|
|
2077
|
+
}
|
|
1955
2078
|
await rollbackLastUpgradeOperation();
|
|
1956
2079
|
return;
|
|
1957
2080
|
}
|
|
1958
|
-
|
|
2081
|
+
await resolveDefaultPluginVersion();
|
|
2082
|
+
validateRequestedPluginVersion();
|
|
1959
2083
|
info(tr(`Target: ${OPENCLAW_DIR}`, `目标实例: ${OPENCLAW_DIR}`));
|
|
1960
2084
|
info(tr(`Repository: ${REPO}`, `仓库: ${REPO}`));
|
|
1961
2085
|
info(tr(`Plugin version: ${PLUGIN_VERSION}`, `插件版本: ${PLUGIN_VERSION}`));
|