feat: install and update through the Geek2API mirror (0.1.2)
Every entry point serves /dsh/latest.json and the release tarballs, synced from GitHub; the version check asks the mirror first through the endpoint pool and installs the mirrored tarball, with GitHub as the fallback. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f4f4ce55b3
commit
1379421095
9 files changed
+171
-18
No files matched your search
+50
-6
@@ -5213,8 +5213,10 @@ function createModelSelectionController({ readPreference, writePreference, isWri
|
||||
* Version self-knowledge for the settings panel.
|
||||
*
|
||||
* The running version comes from this package. The latest version comes from
|
||||
* the GitHub releases of this repository: the newest non-draft release names
|
||||
* the version in its tag and carries the packed tarball as an asset. An
|
||||
* the Geek2API mirror first — every entry point serves `/dsh/latest.json` and
|
||||
* the packed tarballs, synced from GitHub, because GitHub release downloads
|
||||
* are unreachable from mainland networks — and from the GitHub releases of
|
||||
* this repository when no mirror answers. An
|
||||
* in-place update is offered for an install from a release tarball (or the
|
||||
* npm registry), and it installs that exact tarball with the host's own pnpm
|
||||
* — never through `dsh plugin --profile desktop`, which the desktop app
|
||||
@@ -5226,6 +5228,25 @@ const PACKAGE_NAME = "dsh-geek2api";
|
||||
const GITHUB_LATEST_RELEASE_URL = `https://api.github.com/repos/CoderKuo/dsh-geek2api/releases/latest`;
|
||||
/** The tarball asset a release must carry for an in-place update. */
|
||||
const releaseAssetName = (version) => `${PACKAGE_NAME}-${version}.tgz`;
|
||||
/** Where every Geek2API entry point serves the mirrored releases. */
|
||||
const MIRROR_PATH = "/dsh";
|
||||
/**
|
||||
* Normalize the mirror's `latest.json` as served by one entry point.
|
||||
* @param payload - the manifest body.
|
||||
* @param host - the entry point that served it.
|
||||
* @returns `{ version, tarballUrl, releaseUrl }`, or undefined when unusable.
|
||||
*/
|
||||
function parseMirrorManifest(payload, host) {
|
||||
if (payload === null || typeof payload !== "object" || typeof host !== "string") return void 0;
|
||||
const version = typeof payload.version === "string" ? payload.version : void 0;
|
||||
if (parseSemver(version) === void 0 || payload.tarball !== releaseAssetName(version)) return void 0;
|
||||
const releaseUrl = typeof payload.releaseUrl === "string" && /^https:\/\/github\.com\//u.test(payload.releaseUrl) ? payload.releaseUrl : void 0;
|
||||
return {
|
||||
version,
|
||||
tarballUrl: `${host}${MIRROR_PATH}/${payload.tarball}`,
|
||||
...releaseUrl === void 0 ? {} : { releaseUrl }
|
||||
};
|
||||
}
|
||||
const DEFAULT_VERSION_TTL_MS = 5 * 6e4;
|
||||
const DEFAULT_VERSION_TIMEOUT_MS = 1e4;
|
||||
const DEFAULT_UPDATE_TIMEOUT_MS = 18e4;
|
||||
@@ -5444,7 +5465,7 @@ function spawnRunCommand({ command, args, cwd }, { signal, timeoutMs }) {
|
||||
* The running version, the latest registry version, which profile installed
|
||||
* this copy, and registry-spec updates against that profile.
|
||||
*/
|
||||
function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = spawnRunCommand, execPath = process.execPath, argv = process.argv, env = process.env, ownPackageJsonUrl = new URL("../package.json", import.meta.url), releaseUrl = GITHUB_LATEST_RELEASE_URL, now = Date.now, ttlMs = DEFAULT_VERSION_TTL_MS, timeoutMs = DEFAULT_VERSION_TIMEOUT_MS, updateTimeoutMs = DEFAULT_UPDATE_TIMEOUT_MS, settleDelayMs = 250 } = {}) {
|
||||
function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = spawnRunCommand, execPath = process.execPath, argv = process.argv, env = process.env, ownPackageJsonUrl = new URL("../package.json", import.meta.url), releaseUrl = GITHUB_LATEST_RELEASE_URL, hosts, now = Date.now, ttlMs = DEFAULT_VERSION_TTL_MS, timeoutMs = DEFAULT_VERSION_TIMEOUT_MS, updateTimeoutMs = DEFAULT_UPDATE_TIMEOUT_MS, settleDelayMs = 250 } = {}) {
|
||||
if (typeof fetchImpl !== "function") throw new Error("Geek2API plugin manager requires fetch");
|
||||
if (typeof runCommand !== "function") throw new Error("Geek2API plugin manager requires runCommand");
|
||||
const dshHome = typeof env.DSH_HOME === "string" && env.DSH_HOME !== "" ? env.DSH_HOME : join(homedir(), ".dsh");
|
||||
@@ -5453,8 +5474,31 @@ function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = sp
|
||||
execPath
|
||||
});
|
||||
let updating = false;
|
||||
/** The newest release: its version, tarball asset, and page. */
|
||||
const fetchLatest = async (signal) => {
|
||||
/**
|
||||
* The newest release from the mirror, through the entry point the pool
|
||||
* prefers. Undefined when no entry point serves a usable manifest.
|
||||
*/
|
||||
const fetchFromMirror = async (signal) => {
|
||||
if (typeof hosts?.withFailover !== "function") return void 0;
|
||||
try {
|
||||
return await hosts.withFailover(async (host) => {
|
||||
const response = await boundedFetch(`${host}${MIRROR_PATH}/latest.json`, { headers: { Accept: "application/json" } }, {
|
||||
fetchImpl,
|
||||
timeoutMs,
|
||||
signal
|
||||
});
|
||||
if (!response.ok) return void 0;
|
||||
return parseMirrorManifest(await response.json(), host);
|
||||
}, { signal });
|
||||
} catch (error) {
|
||||
if (signal?.aborted) throw error;
|
||||
return;
|
||||
}
|
||||
};
|
||||
/** The newest release: mirror first, then GitHub. */
|
||||
const fetchLatest = async (signal) => await fetchFromMirror(signal) ?? fetchFromGitHub(signal);
|
||||
/** The newest GitHub release: its version, tarball asset, and page. */
|
||||
const fetchFromGitHub = async (signal) => {
|
||||
let response;
|
||||
try {
|
||||
response = await boundedFetch(releaseUrl, { headers: {
|
||||
@@ -7198,7 +7242,7 @@ function apply(ctx, config) {
|
||||
preference: modelPreference,
|
||||
claudeRuntime,
|
||||
claudeCli,
|
||||
pluginManager: createGeek2APIPluginManager(),
|
||||
pluginManager: createGeek2APIPluginManager({ hosts }),
|
||||
search,
|
||||
modelSelection
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user