heybash-xdpool 1.0.3 → 1.0.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/CHANGELOG.md +10 -0
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/client.js +47 -62
- package/lib/index.js +3 -3
- package/package.json +5 -2
- package/tools/sync-npmmirror.mjs +145 -0
- package/vendor/channel-pack/pack.js +8 -1
- package/vendor/channel-pack/pool-model-dedupe.js +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Heybash
|
|
2
2
|
|
|
3
|
+
## 1.0.5 — 积分浮层定位修复
|
|
4
|
+
|
|
5
|
+
- 修复输入框积分浮层在部分宿主布局和缩放环境下偏离按钮;窗口尺寸或滚动变化时保持位置并避免越界。
|
|
6
|
+
- 优化发布后国内镜像的查询与重试,减少缓存引起的重复同步。
|
|
7
|
+
|
|
8
|
+
## 1.0.4 — WorkBuddy 模型去重与镜像同步
|
|
9
|
+
|
|
10
|
+
- 模型选择器统一使用 WorkBuddy 地区名称;同一区域的渠道模型与账号池模型重复时只显示一份,保留历史渠道调用。
|
|
11
|
+
- 正式发布后检查并同步国内 npm 镜像,降低团队成员看不到新版本的情况。
|
|
12
|
+
|
|
3
13
|
## 1.0.3 — 路由上下文与模型显示修复
|
|
4
14
|
|
|
5
15
|
- 路由链按各渠道声明的实际上下文窗口计算安全下限;渠道未声明或数据无效时继续采用保守值,避免不必要的频繁压缩。
|
package/README.en.md
CHANGED
|
@@ -112,7 +112,7 @@ After editing source, rebuild and update the installed plugin, then fully quit a
|
|
|
112
112
|
|
|
113
113
|
The package does not run a dependency-linking script during installation. DeepSeek Harness normally supplies the shared dependencies; if a particular environment cannot resolve them, run `node scripts/link-host-peers.mjs` manually from the installed package to troubleshoot.
|
|
114
114
|
|
|
115
|
-
The account pools appear as **
|
|
115
|
+
The account pools appear as **WorkBuddy 国内版** and **WorkBuddy 国际版**; the optional free-model group is **Heybash · 免费模型**. Channel models already offered by the same regional pool are shown once; existing channel routes remain available to saved conversations.
|
|
116
116
|
|
|
117
117
|
## Upgrading from an older version
|
|
118
118
|
|
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ dsh plugin --profile desktop add "file:/你的项目路径/dsh-xdpool-fork"
|
|
|
115
115
|
|
|
116
116
|
安装包不自动执行依赖链接脚本。通常由 DeepSeek Harness 提供插件所需的共享依赖;如特殊环境出现依赖无法解析,可手动运行安装目录下的 `node scripts/link-host-peers.mjs` 进行排查。
|
|
117
117
|
|
|
118
|
-
模型选择器中的账号池分别显示为 **
|
|
118
|
+
模型选择器中的账号池分别显示为 **WorkBuddy 国内版**、**WorkBuddy 国际版**,免费模型分组显示为 **Heybash · 免费模型**。同一区域中与账号池重复的渠道模型只展示一次,原有渠道标识仍可用于已有会话。
|
|
119
119
|
|
|
120
120
|
## 从旧版升级
|
|
121
121
|
|
package/lib/client.js
CHANGED
|
@@ -6,6 +6,7 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
let react = require("react");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
let react_dom = require("react-dom");
|
|
9
10
|
// src/client/sidebar-row.ts
|
|
10
11
|
/**
|
|
11
12
|
* The `sidebarRow` switch, read and written from one place.
|
|
@@ -1797,8 +1798,8 @@ window.__ModuleLoader__.load({
|
|
|
1797
1798
|
.dsm-xdpool-dot:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:3px}
|
|
1798
1799
|
/* Measured coordinates, not flow: the composer sits at the bottom of the viewport, so a
|
|
1799
1800
|
panel laid out downward would be clipped. */
|
|
1800
|
-
.dsm-xdpool-dotpanel{position:fixed;z-index:80;width:max-content;min-width:172px;max-width:min(280px,calc(100vw -
|
|
1801
|
-
@keyframes dsm-xdpool-dotpanel-in{from{opacity:0
|
|
1801
|
+
.dsm-xdpool-dotpanel{position:fixed;z-index:80;box-sizing:border-box;width:max-content;min-width:min(172px,calc(100vw - 16px));max-width:min(280px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow-y:auto;display:flex;flex-direction:column;gap:7px;padding:10px 12px 11px;border-radius:14px;border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2,#ffffff1f) 92%, transparent);background:var(--dsw-alias-bg-layer-2,#1c1e22);box-shadow:0 18px 48px rgb(0 0 0 / 44%),0 3px 10px rgb(0 0 0 / 24%),inset 0 1px 0 rgb(255 255 255 / 7%);animation:dsm-xdpool-dotpanel-in .16s cubic-bezier(.16,1,.3,1)}
|
|
1802
|
+
@keyframes dsm-xdpool-dotpanel-in{from{opacity:0}to{opacity:1}}
|
|
1802
1803
|
.dsm-xdpool-dotpanel-head{display:flex;align-items:center;gap:8px;min-width:0}
|
|
1803
1804
|
.dsm-xdpool-dotpanel-channel{font-size:12.5px;font-weight:600;letter-spacing:.01em;color:var(--dsw-alias-label-primary,#e8eaf0);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
|
|
1804
1805
|
.dsm-xdpool-dotpanel-chip{margin-left:auto;padding:1px 8px;border-radius:999px;font-size:10px;line-height:16px;font-weight:500}
|
|
@@ -13294,7 +13295,7 @@ window.__ModuleLoader__.load({
|
|
|
13294
13295
|
}
|
|
13295
13296
|
// src/version.ts
|
|
13296
13297
|
/** Version embedded in the browser bundle at build time from the package manifest. */
|
|
13297
|
-
const POOL_VERSION = "1.0.
|
|
13298
|
+
const POOL_VERSION = "1.0.5";
|
|
13298
13299
|
// src/client/PoolCard.tsx
|
|
13299
13300
|
/**
|
|
13300
13301
|
* Heybash card contributed to DSH Plugin configuration.
|
|
@@ -15821,6 +15822,19 @@ window.__ModuleLoader__.load({
|
|
|
15821
15822
|
*
|
|
15822
15823
|
* @module dsh-xdpool/client/credit-strip
|
|
15823
15824
|
*/
|
|
15825
|
+
// src/client/credit-position.ts
|
|
15826
|
+
/** Position a measured panel above its trigger, flipping and clamping at viewport edges. */
|
|
15827
|
+
function creditPanelPosition(anchor, panel, viewport) {
|
|
15828
|
+
const margin = 8;
|
|
15829
|
+
const left = Math.min(Math.max(margin, anchor.left + anchor.width / 2 - panel.width / 2), Math.max(margin, viewport.width - panel.width - margin));
|
|
15830
|
+
const above = anchor.top - panel.height - margin;
|
|
15831
|
+
const below = anchor.bottom + margin;
|
|
15832
|
+
const preferAbove = above >= margin || anchor.top >= viewport.height - anchor.bottom;
|
|
15833
|
+
return {
|
|
15834
|
+
top: Math.min(Math.max(margin, preferAbove ? above : below), Math.max(margin, viewport.height - panel.height - margin)),
|
|
15835
|
+
left
|
|
15836
|
+
};
|
|
15837
|
+
}
|
|
15824
15838
|
// src/client/nav-icon.ts
|
|
15825
15839
|
/**
|
|
15826
15840
|
* Nav glyph for the Heybash settings page.
|
|
@@ -15913,10 +15927,8 @@ window.__ModuleLoader__.load({
|
|
|
15913
15927
|
*
|
|
15914
15928
|
* POSITIONING AND DISMISSAL ARE DONE HERE
|
|
15915
15929
|
*
|
|
15916
|
-
* The
|
|
15917
|
-
*
|
|
15918
|
-
* Escape. That is the same contract the host's meters use, implemented locally rather
|
|
15919
|
-
* than depending on a module this bundle cannot import.
|
|
15930
|
+
* The panel is portaled to the document body so transformed or clipping composer
|
|
15931
|
+
* ancestors cannot change the coordinate system of its fixed position.
|
|
15920
15932
|
*
|
|
15921
15933
|
* @module dsh-xdpool/client/CreditDot
|
|
15922
15934
|
*/
|
|
@@ -16154,69 +16166,42 @@ window.__ModuleLoader__.load({
|
|
|
16154
16166
|
observer.disconnect();
|
|
16155
16167
|
};
|
|
16156
16168
|
}, []);
|
|
16157
|
-
/**
|
|
16158
|
-
* Place the panel above the dot.
|
|
16159
|
-
*
|
|
16160
|
-
* Measured rather than CSS-anchored because the composer row can be at the bottom of
|
|
16161
|
-
* the viewport, and a panel that opens downward would be clipped by it. `side: top`
|
|
16162
|
-
* with a viewport clamp is the same rule the host's own meters follow.
|
|
16163
|
-
*/
|
|
16169
|
+
/** Keep body-relative panel and viewport-relative anchor in the same coordinate space. */
|
|
16164
16170
|
(0, react.useLayoutEffect)(() => {
|
|
16165
16171
|
if (!open) {
|
|
16166
16172
|
setPos(void 0);
|
|
16167
16173
|
return;
|
|
16168
16174
|
}
|
|
16169
16175
|
const anchor = anchorRef.current;
|
|
16170
|
-
if (anchor === null) return;
|
|
16171
|
-
const box = anchor.getBoundingClientRect();
|
|
16172
|
-
/**
|
|
16173
|
-
* The panel sizes to its content (`width: max-content`), so its width can only be
|
|
16174
|
-
* read AFTER it has rendered. A hard-coded number here was what made a short line of
|
|
16175
|
-
* text sit in a 300px box: the width came from this layout maths rather than from
|
|
16176
|
-
* what the text needed. Measuring the element keeps the two in step.
|
|
16177
|
-
*
|
|
16178
|
-
* Falling back to 200 when the ref is not attached yet (first frame) is safe: the
|
|
16179
|
-
* effect re-runs on `open`, and the panel is `visibility: hidden` until `pos` exists.
|
|
16180
|
-
*/
|
|
16181
|
-
const width = panelRef.current?.offsetWidth ?? 200;
|
|
16182
|
-
const margin = 8;
|
|
16183
|
-
const left = Math.min(Math.max(margin, box.left + box.width / 2 - width / 2), Math.max(margin, window.innerWidth - width - margin));
|
|
16184
|
-
const panelHeight = panelRef.current?.offsetHeight ?? 240;
|
|
16185
|
-
const above = box.top - panelHeight - 8;
|
|
16186
|
-
const top = above >= margin ? above : box.bottom + 8;
|
|
16187
|
-
setPos({
|
|
16188
|
-
top,
|
|
16189
|
-
left
|
|
16190
|
-
});
|
|
16191
|
-
}, [open]);
|
|
16192
|
-
/**
|
|
16193
|
-
* Re-measure once the panel has painted.
|
|
16194
|
-
*
|
|
16195
|
-
* `width: max-content` means the first pass measures a zero-width element: the panel is
|
|
16196
|
-
* attached but `pos` is still undefined, so it is laid out at its min-width. Re-running
|
|
16197
|
-
* after the content exists is what makes the width follow the text rather than the
|
|
16198
|
-
* placeholder. Keyed on the model and the channel so a longer name (a real possibility
|
|
16199
|
-
* with a `· 14,031` suffix) triggers a fresh measurement.
|
|
16200
|
-
*/
|
|
16201
|
-
(0, react.useLayoutEffect)(() => {
|
|
16202
|
-
if (!open) return;
|
|
16203
|
-
const anchor = anchorRef.current;
|
|
16204
16176
|
const panel = panelRef.current;
|
|
16205
16177
|
if (anchor === null || panel === null) return;
|
|
16206
|
-
|
|
16207
|
-
const
|
|
16208
|
-
|
|
16209
|
-
|
|
16210
|
-
|
|
16211
|
-
|
|
16212
|
-
|
|
16213
|
-
|
|
16214
|
-
if (current.top === top && current.left === left) return current;
|
|
16215
|
-
return {
|
|
16178
|
+
let frame;
|
|
16179
|
+
const update = () => {
|
|
16180
|
+
frame = void 0;
|
|
16181
|
+
const { left, top } = creditPanelPosition(anchor.getBoundingClientRect(), panel.getBoundingClientRect(), {
|
|
16182
|
+
width: window.innerWidth,
|
|
16183
|
+
height: window.innerHeight
|
|
16184
|
+
});
|
|
16185
|
+
setPos((current) => current?.top === top && current.left === left ? current : {
|
|
16216
16186
|
top,
|
|
16217
16187
|
left
|
|
16218
|
-
};
|
|
16219
|
-
}
|
|
16188
|
+
});
|
|
16189
|
+
};
|
|
16190
|
+
const schedule = () => {
|
|
16191
|
+
if (frame === void 0) frame = window.requestAnimationFrame(update);
|
|
16192
|
+
};
|
|
16193
|
+
update();
|
|
16194
|
+
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(schedule);
|
|
16195
|
+
observer?.observe(anchor);
|
|
16196
|
+
observer?.observe(panel);
|
|
16197
|
+
window.addEventListener("resize", schedule);
|
|
16198
|
+
window.addEventListener("scroll", schedule, true);
|
|
16199
|
+
return () => {
|
|
16200
|
+
observer?.disconnect();
|
|
16201
|
+
window.removeEventListener("resize", schedule);
|
|
16202
|
+
window.removeEventListener("scroll", schedule, true);
|
|
16203
|
+
if (frame !== void 0) window.cancelAnimationFrame(frame);
|
|
16204
|
+
};
|
|
16220
16205
|
}, [
|
|
16221
16206
|
open,
|
|
16222
16207
|
snapshot?.model,
|
|
@@ -16290,7 +16275,7 @@ window.__ModuleLoader__.load({
|
|
|
16290
16275
|
"aria-hidden": "true"
|
|
16291
16276
|
})
|
|
16292
16277
|
}),
|
|
16293
|
-
!open ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
16278
|
+
!open || typeof document === "undefined" ? null : (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
16294
16279
|
ref: panelRef,
|
|
16295
16280
|
className: "dsm-xdpool-dotpanel",
|
|
16296
16281
|
role: "dialog",
|
|
@@ -16358,7 +16343,7 @@ window.__ModuleLoader__.load({
|
|
|
16358
16343
|
})
|
|
16359
16344
|
}) : null
|
|
16360
16345
|
] })]
|
|
16361
|
-
})
|
|
16346
|
+
}), document.body)
|
|
16362
16347
|
]
|
|
16363
16348
|
});
|
|
16364
16349
|
}
|
package/lib/index.js
CHANGED
|
@@ -13232,14 +13232,14 @@ const POOL_PROVIDER_BY_REGION = {
|
|
|
13232
13232
|
/**
|
|
13233
13233
|
* Display name each region registers under, so the picker can group them.
|
|
13234
13234
|
*
|
|
13235
|
-
* The regional suffix distinguishes the two
|
|
13235
|
+
* The regional suffix distinguishes the two WorkBuddy account pools.
|
|
13236
13236
|
*
|
|
13237
13237
|
* Display name only. The provider ids above are what the host matches on when it
|
|
13238
13238
|
* persists a selection, so renaming a group must never touch them.
|
|
13239
13239
|
*/
|
|
13240
13240
|
const POOL_NAME_BY_REGION = {
|
|
13241
|
-
cn: "
|
|
13242
|
-
global: "
|
|
13241
|
+
cn: "WorkBuddy 国内版",
|
|
13242
|
+
global: "WorkBuddy 国际版"
|
|
13243
13243
|
};
|
|
13244
13244
|
/** Provider idle ceiling while one stream read is outstanding. */
|
|
13245
13245
|
const WORKBUDDY_STREAM_IDLE_TIMEOUT_MS = 3e5;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "heybash-xdpool",
|
|
3
3
|
"displayName": "Heybash",
|
|
4
4
|
"description": "Heybash model pool for DeepSeek Harness: account rotation, provider aggregation, routing chains, usage insights and a local OpenAI-compatible gateway.",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.5",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Heybash",
|
|
8
8
|
"contributors": [
|
|
@@ -55,11 +55,13 @@
|
|
|
55
55
|
"README.en.md",
|
|
56
56
|
"CHANGELOG.md",
|
|
57
57
|
"LICENSE",
|
|
58
|
-
"scripts"
|
|
58
|
+
"scripts",
|
|
59
|
+
"tools/sync-npmmirror.mjs"
|
|
59
60
|
],
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build": "tsdown",
|
|
62
63
|
"prepublishOnly": "tsdown",
|
|
64
|
+
"postpublish": "node tools/sync-npmmirror.mjs --published",
|
|
63
65
|
"test": "vitest run",
|
|
64
66
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
65
67
|
"typecheck:client": "tsc -p tsconfig.client.json --noEmit"
|
|
@@ -99,6 +101,7 @@
|
|
|
99
101
|
"@types/react": "~18.3.31",
|
|
100
102
|
"@types/react-dom": "~18.3.0",
|
|
101
103
|
"react": "^18.2.0",
|
|
104
|
+
"react-dom": "^18.3.1",
|
|
102
105
|
"tsdown": "^0.23.0",
|
|
103
106
|
"typescript": "^7.0.2",
|
|
104
107
|
"vite": "8.3.0",
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Synchronize the public package after npm has made the requested version available. */
|
|
3
|
+
import { pathToFileURL } from 'node:url'
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
|
|
6
|
+
const NAME = 'heybash-xdpool'
|
|
7
|
+
const NPM = `https://registry.npmjs.org/${NAME}`
|
|
8
|
+
const MIRROR = `https://registry.npmmirror.com/${NAME}`
|
|
9
|
+
const SYNC = `https://registry.npmmirror.com/-/package/${NAME}/syncs`
|
|
10
|
+
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u
|
|
11
|
+
const TASK_ID = /^[0-9A-Za-z_-]+$/u
|
|
12
|
+
const MAX_TARBALL_BYTES = 64 * 1024 * 1024
|
|
13
|
+
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))
|
|
14
|
+
|
|
15
|
+
async function request(fetchImpl, url, init = {}) {
|
|
16
|
+
const response = await fetchImpl(url, {
|
|
17
|
+
...init,
|
|
18
|
+
signal: AbortSignal.timeout(15_000),
|
|
19
|
+
})
|
|
20
|
+
if (!response.ok) throw new Error(`${init.method ?? 'GET'} ${new URL(url).hostname}: HTTP ${response.status}`)
|
|
21
|
+
return response
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function retry(label, action, { attempts, intervalMs, sleep, log }) {
|
|
25
|
+
let lastError
|
|
26
|
+
for (let i = 0; i < attempts; i++) {
|
|
27
|
+
try { return await action() } catch (error) {
|
|
28
|
+
lastError = error
|
|
29
|
+
log(`${label} (${i + 1}/${attempts}): ${error instanceof Error ? error.message : String(error)}`)
|
|
30
|
+
if (error?.terminal === true) throw error
|
|
31
|
+
if (i + 1 < attempts) await sleep(intervalMs)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`${label} failed after ${attempts} attempts: ${lastError instanceof Error ? lastError.message : String(lastError)}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Poll the real public registry endpoints without credentials. A matching
|
|
39
|
+
* version, checksum, latest tag and reachable tarball are all required before
|
|
40
|
+
* reporting success. `version` absent means the current official latest.
|
|
41
|
+
*/
|
|
42
|
+
export async function syncMirror({
|
|
43
|
+
version, fetchImpl = fetch, sleep = delay, log = console.log,
|
|
44
|
+
attempts = 24, officialAttempts = attempts * 2, intervalMs = 10_000, syncAttempts = 3,
|
|
45
|
+
} = {}) {
|
|
46
|
+
if (version !== undefined && !VERSION.test(version)) throw new Error('Invalid target version')
|
|
47
|
+
const options = { attempts, intervalMs, sleep, log }
|
|
48
|
+
// Match npm/pnpm's metadata representation. The mirror can cache its
|
|
49
|
+
// generic */* representation separately from the package-manager response.
|
|
50
|
+
const read = async (url) => (await request(fetchImpl, url, {
|
|
51
|
+
headers: { accept: 'application/json' },
|
|
52
|
+
})).json()
|
|
53
|
+
const official = await retry('Waiting for npm', async () => {
|
|
54
|
+
const data = await read(NPM)
|
|
55
|
+
const target = version ?? data['dist-tags']?.latest
|
|
56
|
+
if (typeof target !== 'string' || !VERSION.test(target)) throw new Error('npm has no valid target version')
|
|
57
|
+
const checksum = data.versions?.[target]?.dist?.shasum
|
|
58
|
+
if (typeof checksum !== 'string' || !/^[a-f0-9]{40}$/u.test(checksum)) throw new Error(`npm ${target} is not yet available with a checksum`)
|
|
59
|
+
return { target, checksum, latest: data['dist-tags']?.latest }
|
|
60
|
+
}, { ...options, attempts: officialAttempts })
|
|
61
|
+
log(`npm target ${official.target}; latest ${official.latest}`)
|
|
62
|
+
|
|
63
|
+
const verify = async (download = false) => {
|
|
64
|
+
const mirror = await read(MIRROR)
|
|
65
|
+
if (mirror.versions?.[official.target]?.dist?.shasum !== official.checksum) throw new Error(`mirror ${official.target} is missing or has a different checksum`)
|
|
66
|
+
if (official.latest === official.target && mirror['dist-tags']?.latest !== official.target) throw new Error(`mirror latest is not ${official.target}`)
|
|
67
|
+
const tarball = mirror.versions[official.target].dist.tarball
|
|
68
|
+
const expected = `https://registry.npmmirror.com/${NAME}/-/${NAME}-${official.target}.tgz`
|
|
69
|
+
if (tarball !== expected) throw new Error('mirror returned an unexpected tarball URL')
|
|
70
|
+
const artifact = await request(fetchImpl, tarball, { method: download ? 'GET' : 'HEAD' })
|
|
71
|
+
if (download) {
|
|
72
|
+
if (artifact.body === null) throw new Error('mirror tarball has no body')
|
|
73
|
+
const digest = createHash('sha1')
|
|
74
|
+
let bytes = 0
|
|
75
|
+
for await (const chunk of artifact.body) {
|
|
76
|
+
bytes += chunk.length
|
|
77
|
+
if (bytes > MAX_TARBALL_BYTES) throw new Error('mirror tarball exceeds size limit')
|
|
78
|
+
digest.update(chunk)
|
|
79
|
+
}
|
|
80
|
+
if (digest.digest('hex') !== official.checksum) throw new Error('mirror tarball checksum does not match npm')
|
|
81
|
+
}
|
|
82
|
+
return official.target
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const target = await verify()
|
|
87
|
+
log(`Mirror already serves ${target} with the correct checksum`)
|
|
88
|
+
return { version: target, synced: false }
|
|
89
|
+
} catch (error) {
|
|
90
|
+
log(`Mirror needs synchronization: ${error instanceof Error ? error.message : String(error)}`)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let lastError
|
|
94
|
+
for (let attempt = 0; attempt < syncAttempts; attempt++) {
|
|
95
|
+
try {
|
|
96
|
+
const task = await (await request(fetchImpl, SYNC, {
|
|
97
|
+
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
98
|
+
body: JSON.stringify({ skipDependencies: true }),
|
|
99
|
+
})).json()
|
|
100
|
+
if (task.ok !== true || typeof task.id !== 'string' || !TASK_ID.test(task.id)) throw new Error('mirror did not return a valid sync task')
|
|
101
|
+
log(`Mirror synchronization task ${task.id}`)
|
|
102
|
+
await retry('Waiting for mirror synchronization', async () => {
|
|
103
|
+
const status = await read(`${SYNC}/${task.id}`)
|
|
104
|
+
if (status.state === 'success') return
|
|
105
|
+
if (status.state === 'failed' || status.state === 'fail') {
|
|
106
|
+
throw Object.assign(new Error(`sync task ${status.state}`), { terminal: true })
|
|
107
|
+
}
|
|
108
|
+
throw new Error(`sync task ${String(status.state)}`)
|
|
109
|
+
}, options)
|
|
110
|
+
const target = await retry('Waiting for mirror availability', () => verify(true), options)
|
|
111
|
+
log(`Mirror serves ${target} with the correct checksum`)
|
|
112
|
+
return { version: target, synced: true }
|
|
113
|
+
} catch (error) {
|
|
114
|
+
lastError = error
|
|
115
|
+
log(`Mirror synchronization attempt ${attempt + 1}/${syncAttempts} failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
116
|
+
// A sync task can fail or time out after another worker already updated
|
|
117
|
+
// the mirror. Verify the artifact before submitting a redundant task.
|
|
118
|
+
try {
|
|
119
|
+
const target = await verify(true)
|
|
120
|
+
log(`Mirror serves ${target} with the correct checksum`)
|
|
121
|
+
return { version: target, synced: true }
|
|
122
|
+
} catch {
|
|
123
|
+
// Still unavailable: proceed with the bounded retry below.
|
|
124
|
+
}
|
|
125
|
+
if (attempt + 1 < syncAttempts) await sleep(intervalMs)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`Mirror synchronization failed: ${lastError instanceof Error ? lastError.message : String(lastError)}`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
132
|
+
const args = process.argv.slice(2)
|
|
133
|
+
const published = args.length === 1 && args[0] === '--published'
|
|
134
|
+
const publishedVersion = published ? process.env.npm_package_version : undefined
|
|
135
|
+
if ((published && (publishedVersion === undefined || !VERSION.test(publishedVersion)))
|
|
136
|
+
|| (!published && args.length !== 0 && (args.length !== 2 || args[0] !== '--version'))) {
|
|
137
|
+
console.error('Usage: node tools/sync-npmmirror.mjs [--version X.Y.Z | --published (npm lifecycle only)]')
|
|
138
|
+
process.exitCode = 2
|
|
139
|
+
} else {
|
|
140
|
+
syncMirror(published ? { version: publishedVersion } : args.length === 2 ? { version: args[1] } : {}).catch(error => {
|
|
141
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
142
|
+
process.exitCode = 1
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// Generated by scripts/build-channel-pack.mjs —
|
|
1
|
+
// Generated by scripts/build-channel-pack.mjs — local compatibility patches are marked below.
|
|
2
|
+
import { withoutPoolDuplicates } from './pool-model-dedupe.js';
|
|
2
3
|
// Source: vendor/channel-pack/src (the absorbed free-channel pack; see NOTICE.md).
|
|
3
4
|
import { createRequire as __ofmCreateRequire } from 'node:module'
|
|
4
5
|
const require = __ofmCreateRequire(import.meta.url)
|
|
@@ -36226,6 +36227,12 @@ function positiveMaxTokens(value) {
|
|
|
36226
36227
|
function registerBuddyLlm(ctx, options) {
|
|
36227
36228
|
const product = options.product ?? CODEBUDDY;
|
|
36228
36229
|
const adapter = new BuddyAdapter(options);
|
|
36230
|
+
// [patch:workbuddy-picker-dedupe] Keep the historical provider callable while
|
|
36231
|
+
// hiding entries already listed by this region's WorkBuddy pool in the picker.
|
|
36232
|
+
const listChannelModels = adapter.listModels.bind(adapter);
|
|
36233
|
+
adapter.listModels = async (provider) => withoutPoolDuplicates(
|
|
36234
|
+
await listChannelModels(provider), product.id, (poolProvider) => ctx.llm.listModels(poolProvider)
|
|
36235
|
+
);
|
|
36229
36236
|
registerAdapterIdempotent(ctx.llm, [product.id], adapter);
|
|
36230
36237
|
return adapter;
|
|
36231
36238
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Hide only model IDs also offered by the corresponding WorkBuddy pool.
|
|
2
|
+
* The channel adapter itself stays registered so previously saved routes work.
|
|
3
|
+
* If the pool is unavailable, keep the original channel catalog intact.
|
|
4
|
+
*/
|
|
5
|
+
export async function withoutPoolDuplicates(rows, provider, listModels) {
|
|
6
|
+
const poolProvider = provider === 'buddy' ? 'xdpool'
|
|
7
|
+
: provider === 'workbuddy' ? 'xdpool-global' : undefined
|
|
8
|
+
if (poolProvider === undefined) return rows
|
|
9
|
+
try {
|
|
10
|
+
const poolRows = await listModels(poolProvider)
|
|
11
|
+
const ids = new Set(poolRows.map(row => row.id))
|
|
12
|
+
return rows.filter(row => !ids.has(row.id))
|
|
13
|
+
} catch {
|
|
14
|
+
return rows
|
|
15
|
+
}
|
|
16
|
+
}
|