mslxdff 0.1.203 → 0.1.208
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/README.md +3 -3
- package/bin/mslxdff.js +1 -1
- package/docs/cli_help_mini.md +147 -0
- package/package.json +38 -38
- package/plugins/README.md +14 -14
- package/plugins/prefer-model.mjs.example +14 -14
- package/src/anthropic/canonical-json.js +55 -0
- package/src/anthropic/count-tokens.js +61 -61
- package/src/anthropic/request-body.js +183 -126
- package/src/anthropic/request-shape.js +60 -0
- package/src/anthropic/session-id.js +58 -0
- package/src/anthropic/shared.js +18 -18
- package/src/anthropic/sse-aggregate.js +56 -56
- package/src/anthropic/tool-media.js +75 -0
- package/src/anthropic/translate.js +296 -287
- package/src/anthropic/web-search.js +361 -361
- package/src/api-kind.js +31 -31
- package/src/autostart.js +288 -288
- package/src/bench/probe.js +1 -1
- package/src/bench/runner.js +1 -1
- package/src/bench/via-probe.js +1 -1
- package/src/bench/via.js +144 -144
- package/src/bench/workbuddy-bench.js +1 -1
- package/src/chat/config.js +11 -11
- package/src/chat/cooling.js +81 -81
- package/src/chat/direct.js +58 -58
- package/src/chat/index.js +6 -6
- package/src/chat/spinner.js +38 -38
- package/src/chat/sse.js +69 -69
- package/src/chat/stats.js +247 -247
- package/src/chat/store.js +48 -48
- package/src/chat/tool-handlers.js +67 -67
- package/src/chat/tools.js +1 -1
- package/src/chat/upstream.js +59 -59
- package/src/chat-pipeline/auto-race.js +158 -158
- package/src/chat-pipeline/empty-turn.js +147 -147
- package/src/chat-pipeline/engine.js +17 -17
- package/src/chat-pipeline/index.js +8 -40
- package/src/chat-pipeline/serial-trial.js +279 -283
- package/src/chat-pipeline/terminal-verdict.js +132 -147
- package/src/chooser.js +54 -54
- package/src/claude-desktop/apply.js +101 -101
- package/src/claude-desktop/context1m.js +38 -38
- package/src/claude-desktop/doctor.js +146 -146
- package/src/claude-desktop/slots.js +152 -152
- package/src/cli/bootstrap.js +1 -1
- package/src/cli/commands/claude-desktop.js +284 -284
- package/src/cli/commands/daemon.js +231 -231
- package/src/cli/commands/model/list-live.js +22 -22
- package/src/cli/commands/model/list-providers.js +76 -76
- package/src/cli/commands/model/list-render.js +77 -77
- package/src/cli/commands/model/list-sort.js +52 -52
- package/src/cli/commands/model/list-tty.js +76 -76
- package/src/cli/commands/model/list.js +166 -166
- package/src/cli/commands/model/live-models.js +24 -24
- package/src/cli/commands/model/stats.js +43 -43
- package/src/cli/commands/model/status.js +47 -47
- package/src/cli/commands/model.js +51 -51
- package/src/cli/commands/provider/add.js +108 -108
- package/src/cli/commands/provider/allowlist.js +99 -99
- package/src/cli/commands/provider/cline-free.js +99 -99
- package/src/cli/commands/provider/cline-login.js +218 -218
- package/src/cli/commands/provider/cline-quota.js +65 -65
- package/src/cli/commands/provider/codearts-login.js +45 -45
- package/src/cli/commands/provider/config.js +119 -119
- package/src/cli/commands/provider/globalqwenwork-login.js +126 -126
- package/src/cli/commands/provider/keys-guard.js +50 -50
- package/src/cli/commands/provider/keys.js +161 -161
- package/src/cli/commands/provider/qoder-checkin.js +81 -81
- package/src/cli/commands/provider/qoder-login.js +102 -102
- package/src/cli/commands/provider/raccoon-login.js +180 -180
- package/src/cli/commands/provider/raccoon-password.js +162 -162
- package/src/cli/commands/provider/raccoon-quota.js +109 -109
- package/src/cli/commands/provider/traework-checkin.js +144 -144
- package/src/cli/commands/provider/traework-login.js +164 -164
- package/src/cli/commands/provider/workbuddy-login.js +153 -153
- package/src/cli/commands/provider/zcode-login.js +77 -77
- package/src/cli/commands/provider/zcode-quota.js +55 -55
- package/src/cli/commands/provider.js +1 -1
- package/src/cli/commands/stats.js +158 -149
- package/src/cli/commands/system.js +261 -261
- package/src/cli/commands/timezone.js +47 -47
- package/src/cli/commands/use-group.js +60 -60
- package/src/cli/commands/v6-pool.js +123 -0
- package/src/cli/commands/workbuddy.js +189 -189
- package/src/cli/format.js +141 -141
- package/src/cli/group-helpers.js +70 -70
- package/src/cli/help.js +80 -80
- package/src/cli/index.js +73 -70
- package/src/cli/interactive.js +121 -121
- package/src/cli/join-core.js +99 -99
- package/src/cli/join-wizard.js +175 -175
- package/src/cli/policy.js +136 -136
- package/src/cli/provider-row.js +126 -126
- package/src/cli/util.js +24 -24
- package/src/compat.js +53 -53
- package/src/events.js +38 -38
- package/src/free-lane.js +131 -131
- package/src/free-watcher.js +63 -63
- package/src/groups.js +262 -262
- package/src/logs.js +195 -195
- package/src/metrics.js +71 -62
- package/src/model-capabilities/context-lookup.js +65 -65
- package/src/model-capabilities/merge.js +142 -142
- package/src/model-trace.js +187 -187
- package/src/models.js +1 -1
- package/src/opencode-identity.js +72 -72
- package/src/peers.js +254 -254
- package/src/plugins.js +107 -107
- package/src/providers/AGENTS.md +49 -0
- package/src/providers/base.js +164 -164
- package/src/providers/classify.js +22 -22
- package/src/providers/cline/allowlist-sync.js +93 -93
- package/src/providers/cline/free-catalog.js +71 -71
- package/src/providers/cline/headers.js +37 -37
- package/src/providers/cline/index.js +130 -130
- package/src/providers/cline/models.js +150 -150
- package/src/providers/cline/usage.js +274 -274
- package/src/providers/codearts/auth-pool.js +148 -148
- package/src/providers/codearts/concurrency.js +34 -34
- package/src/providers/codearts/const.js +65 -65
- package/src/providers/codearts/dpop.js +95 -95
- package/src/providers/codearts/index.js +175 -175
- package/src/providers/codearts/login.js +214 -214
- package/src/providers/codearts/models.js +182 -182
- package/src/providers/codearts/sign.js +96 -96
- package/src/providers/codearts/sse.js +204 -204
- package/src/providers/codearts/stream.js +209 -209
- package/src/providers/codearts/sts.js +124 -124
- package/src/providers/codearts.js +1 -1
- package/src/providers/dispatcher.js +146 -146
- package/src/providers/generic.js +156 -156
- package/src/providers/globalqwenwork/account-store.js +141 -141
- package/src/providers/globalqwenwork/constants.js +73 -73
- package/src/providers/globalqwenwork/crypto.js +2 -2
- package/src/providers/globalqwenwork/http.js +2 -2
- package/src/providers/globalqwenwork/index.js +331 -331
- package/src/providers/globalqwenwork/payload.js +147 -147
- package/src/providers/globalqwenwork/rsa.js +2 -2
- package/src/providers/globalqwenwork/sse.js +2 -2
- package/src/providers/globalqwenwork/stream.js +2 -2
- package/src/providers/globalqwenwork.js +1 -1
- package/src/providers/globalworkbuddy/account-store.js +198 -198
- package/src/providers/globalworkbuddy/auth.js +97 -97
- package/src/providers/globalworkbuddy/catalog.js +138 -138
- package/src/providers/globalworkbuddy/constants.js +73 -73
- package/src/providers/globalworkbuddy/device-auth.js +120 -120
- package/src/providers/globalworkbuddy/errors.js +98 -98
- package/src/providers/globalworkbuddy/headers.js +89 -89
- package/src/providers/globalworkbuddy/models.js +96 -96
- package/src/providers/globalworkbuddy/payload.js +80 -80
- package/src/providers/index.js +5 -5
- package/src/providers/model-id.js +172 -172
- package/src/providers/opencode.js +19 -19
- package/src/providers/openrouter.js +31 -31
- package/src/providers/qoder/account-store.js +106 -106
- package/src/providers/qoder/aggregate.js +60 -60
- package/src/providers/qoder/baseprompt.json +591 -591
- package/src/providers/qoder/checkin.js +160 -160
- package/src/providers/qoder/constants.js +44 -44
- package/src/providers/qoder/encode.js +41 -41
- package/src/providers/qoder/fingerprint.js +38 -38
- package/src/providers/qoder/models.js +77 -77
- package/src/providers/qoder/oauth.js +84 -84
- package/src/providers/qoder/payload.js +162 -162
- package/src/providers/qoder/request.js +27 -27
- package/src/providers/qoder/session.js +134 -134
- package/src/providers/qoder/sticky.js +38 -38
- package/src/providers/qoder/stream.js +116 -116
- package/src/providers/qoder.js +1 -1
- package/src/providers/raccoon/account-store.js +216 -216
- package/src/providers/raccoon/auth.js +67 -67
- package/src/providers/raccoon/chat.js +228 -228
- package/src/providers/raccoon/const.js +180 -180
- package/src/providers/raccoon/credits.js +185 -185
- package/src/providers/raccoon/crypto.js +43 -43
- package/src/providers/raccoon/envelope.js +31 -31
- package/src/providers/raccoon/headers.js +45 -45
- package/src/providers/raccoon/index.js +216 -216
- package/src/providers/raccoon/login.js +279 -279
- package/src/providers/raccoon/models.js +160 -160
- package/src/providers/raccoon/password-login.js +102 -102
- package/src/providers/raccoon/qr-codewords.js +115 -115
- package/src/providers/raccoon/qr.js +236 -236
- package/src/providers/raccoon/sse.js +135 -135
- package/src/providers/responses-channel.js +120 -120
- package/src/providers/share-keys.js +53 -53
- package/src/providers/traework/account-store.js +234 -234
- package/src/providers/traework/chat.js +217 -217
- package/src/providers/traework/checkin.js +77 -77
- package/src/providers/traework/constants.js +41 -41
- package/src/providers/traework/errors.js +52 -52
- package/src/providers/traework/headers.js +79 -79
- package/src/providers/traework/index.js +132 -132
- package/src/providers/traework/market-identity.js +116 -116
- package/src/providers/traework/models.js +98 -98
- package/src/providers/traework/payload.js +86 -86
- package/src/providers/traework/sse.js +184 -184
- package/src/providers/traework/token.js +52 -52
- package/src/providers/traework.js +2 -2
- package/src/providers/workbuddy/account-store.js +186 -186
- package/src/providers/workbuddy/auth.js +158 -158
- package/src/providers/workbuddy/balance.js +86 -86
- package/src/providers/workbuddy/cat-travel.js +125 -125
- package/src/providers/workbuddy/checkin.js +75 -75
- package/src/providers/workbuddy/desktop-info.js +78 -78
- package/src/providers/workbuddy/growth-api.js +67 -67
- package/src/providers/workbuddy/growth-plans.js +63 -63
- package/src/providers/workbuddy/growth.js +181 -181
- package/src/providers/workbuddy/index.js +217 -217
- package/src/providers/workbuddy/models.js +126 -126
- package/src/providers/workbuddy/payload.js +141 -141
- package/src/providers/workbuddy/rotation-log.js +83 -83
- package/src/providers/workbuddy/sanitize-tools.js +61 -61
- package/src/providers/workbuddy/sdk-chat.js +26 -26
- package/src/providers/workbuddy-balance.js +78 -78
- package/src/providers/zcode/account-store.js +129 -129
- package/src/providers/zcode/auth.js +28 -28
- package/src/providers/zcode/chat.js +179 -179
- package/src/providers/zcode/const.js +54 -54
- package/src/providers/zcode/context-shape.js +162 -162
- package/src/providers/zcode/headers.js +93 -93
- package/src/providers/zcode/index.js +124 -124
- package/src/providers/zcode/models.js +65 -65
- package/src/providers/zcode/oauth.js +120 -120
- package/src/providers/zcode/quota.js +176 -176
- package/src/providers/zcode/sse.js +196 -196
- package/src/readline-compat.js +25 -25
- package/src/responses/translate.js +311 -311
- package/src/routes/AGENTS.md +37 -0
- package/src/routes/chat/broadband-handler.js +72 -72
- package/src/routes/chat/empty-turn-report.js +31 -31
- package/src/routes/chat/exhausted-handler.js +87 -87
- package/src/routes/chat/hedge-handler.js +130 -130
- package/src/routes/chat/index.js +1 -1
- package/src/routes/chat/local-handler.js +63 -63
- package/src/routes/chat/peer-handler.js +81 -81
- package/src/routes/chat.js +3 -3
- package/src/routes/fallback.js +88 -88
- package/src/routes/groups-relay.js +214 -214
- package/src/routes/groups.js +122 -122
- package/src/routes/helpers.js +93 -83
- package/src/routes/index.js +147 -147
- package/src/routes/messages-route.js +375 -365
- package/src/routes/peers.js +10 -2
- package/src/routes/relay-queue.js +181 -181
- package/src/routes/relay.js +60 -60
- package/src/routes/responses-route.js +213 -213
- package/src/routes/stream-body.js +84 -84
- package/src/routes/stream-hold.js +337 -337
- package/src/routes/stream-scan.js +366 -366
- package/src/routes.js +3 -3
- package/src/runtime/auto-update.js +113 -113
- package/src/runtime/broadband-stream.js +79 -79
- package/src/runtime/broadband.js +103 -103
- package/src/runtime/group-sync.js +81 -81
- package/src/runtime/keep-warm.js +120 -120
- package/src/runtime/lifecycle-forensics.js +116 -116
- package/src/runtime/lifecycle-log.js +87 -87
- package/src/runtime/log-stamp.js +73 -73
- package/src/runtime/proc-info.js +137 -137
- package/src/runtime/qoder-checkin.js +93 -93
- package/src/runtime/raccoon-checkin.js +126 -126
- package/src/runtime/server-lifecycle.js +189 -189
- package/src/runtime/traework-checkin.js +118 -118
- package/src/runtime/workbuddy-checkin.js +120 -120
- package/src/runtime/workbuddy-growth.js +133 -133
- package/src/state/facade.js +58 -58
- package/src/state/memory.js +162 -162
- package/src/state/merge.js +25 -25
- package/src/state/migrations/cline-unify.js +94 -94
- package/src/state/migrations.js +33 -33
- package/src/state/persist.js +42 -42
- package/src/state/provider-config.js +142 -142
- package/src/state/schemas/group.js +31 -31
- package/src/state/schemas/model.js +94 -94
- package/src/state/schemas/peer.js +31 -31
- package/src/state/schemas/port.js +10 -10
- package/src/state/schemas/provider.js +202 -202
- package/src/state/schemas/timezone.js +70 -70
- package/src/state/schemas/token.js +48 -48
- package/src/state/schemas/use-group.js +102 -102
- package/src/state/store.js +176 -176
- package/src/state.js +1 -1
- package/src/sync-claude-desktop.js +234 -234
- package/src/sync-claude.js +152 -152
- package/src/sync-codex.js +116 -116
- package/src/sync-workbuddy.js +158 -158
- package/src/talk-full-redact.js +129 -129
- package/src/talk-full.js +131 -131
- package/src/talk-log.js +257 -257
- package/src/text-tokens.js +52 -52
- package/src/thinking-effort.js +67 -67
- package/src/time.js +106 -106
- package/src/timeline.js +26 -26
- package/src/transport/index.js +1 -1
- package/src/upstream-engine/index.js +74 -74
- package/src/upstream-engine/mode.js +15 -15
- package/src/upstream-engine/sdk/attempt.js +221 -221
- package/src/upstream-engine/sdk/chat.js +28 -28
- package/src/upstream-engine/sdk/convert.js +192 -192
- package/src/upstream-engine/sdk/diagnose.js +62 -62
- package/src/upstream-engine/sdk/dispatch.js +55 -55
- package/src/upstream-engine/sdk/responses.js +176 -176
- package/src/upstream-engine/sdk/sse.js +166 -166
- package/src/upstream-responses.js +305 -305
- package/src/usage/cache-fields.js +58 -0
- package/src/usage/record.js +109 -106
- package/src/usage/report.js +209 -195
- package/src/v6pool/claim.js +157 -157
- package/src/v6pool/config.js +65 -65
- package/src/v6pool/detect.js +130 -130
- package/src/v6pool/index.js +152 -152
- package/src/v6pool/prefix.js +140 -140
- package/src/v6pool/probe.js +40 -40
- package/src/v6pool/report.js +104 -104
- package/src/v6pool/rotate.js +263 -263
- package/src/v6pool/selftest.js +154 -0
- package/src/warp-pool/config.js +74 -74
- package/src/warp-pool/health.js +106 -106
- package/src/warp-pool/identity.js +141 -141
- package/src/warp-pool/index.js +358 -358
- package/src/warp-pool/keys.js +29 -29
- package/src/warp-pool/nodes.js +95 -95
- package/src/warp-pool/ports.js +160 -160
- package/src/warp-pool/register.js +113 -113
- package/src/warp-pool/report.js +232 -232
- package/src/warp-pool/revive.js +168 -168
- package/src/warp-pool/rotate.js +214 -214
- package/src/warp-pool/strategy.js +43 -43
- package/src/warp-pool/verdict.js +69 -69
- package/src/warp-pool/wireproxy.js +162 -162
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { compatFetch, timeoutSignal } from "../../compat.js";
|
|
2
|
-
// WorkBuddy growth 域(/activity/growth/* 与 /v2/activity/growth/*)底层请求。
|
|
3
|
-
// 双域容灾与签到同款;业务失败结构化返回(ok:false + code/msg),不抛异常。
|
|
4
|
-
// 注意:领奖路径 /activity/growth/tasks/{code}/claim 无 /v2 前缀(上游实测形态)。
|
|
5
|
-
|
|
6
|
-
export const GROWTH_BASES = [
|
|
7
|
-
"https://copilot.tencent.com",
|
|
8
|
-
"https://www.codebuddy.cn",
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
export function growthHeaders({ at, uid, domain, enterpriseId }) {
|
|
12
|
-
return {
|
|
13
|
-
Authorization: `Bearer ${at}`,
|
|
14
|
-
"Content-Type": "application/json",
|
|
15
|
-
Accept: "application/json",
|
|
16
|
-
"X-User-Id": uid,
|
|
17
|
-
"X-Domain": domain || "www.codebuddy.cn",
|
|
18
|
-
"X-Product": "SaaS",
|
|
19
|
-
"User-Agent": "CLI/2.115.0 WorkBuddy/2.115.0",
|
|
20
|
-
Origin: "https://www.codebuddy.cn",
|
|
21
|
-
Referer: "https://www.codebuddy.cn/",
|
|
22
|
-
...(enterpriseId ? { "X-Enterprise-Id": enterpriseId } : {}),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function growthRequest({
|
|
27
|
-
uid, at, domain, enterpriseId,
|
|
28
|
-
method = "GET", path, body,
|
|
29
|
-
fetchImpl = compatFetch, timeoutMs = 15000,
|
|
30
|
-
} = {}) {
|
|
31
|
-
const headers = growthHeaders({ at, uid, domain, enterpriseId });
|
|
32
|
-
let last = null;
|
|
33
|
-
for (const base of GROWTH_BASES) {
|
|
34
|
-
const url = base + path;
|
|
35
|
-
let res;
|
|
36
|
-
try {
|
|
37
|
-
res = await fetchImpl(url, {
|
|
38
|
-
method,
|
|
39
|
-
headers,
|
|
40
|
-
...(method.toUpperCase() === "GET" ? {} : { body: JSON.stringify(body ?? {}) }),
|
|
41
|
-
signal: timeoutSignal(timeoutMs),
|
|
42
|
-
});
|
|
43
|
-
} catch (e) {
|
|
44
|
-
last = { ok: false, status: 0, code: null, msg: `网络失败: ${String(e?.message || e).slice(0, 200)}`, data: {}, url };
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
let payload = null;
|
|
48
|
-
try { payload = await res.json(); } catch { payload = null; }
|
|
49
|
-
if (!payload || typeof payload !== "object") {
|
|
50
|
-
last = { ok: false, status: res.status, code: null, msg: `非 JSON 响应 HTTP ${res.status}`, data: {}, url };
|
|
51
|
-
if (res.status === 401 || res.status === 403) return { ...last, needRefresh: true };
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const out = {
|
|
55
|
-
ok: res.status === 200 && payload.code === 0,
|
|
56
|
-
status: res.status,
|
|
57
|
-
code: payload.code,
|
|
58
|
-
msg: payload.msg || "",
|
|
59
|
-
data: payload.data || {},
|
|
60
|
-
url,
|
|
61
|
-
};
|
|
62
|
-
if (out.ok) return out;
|
|
63
|
-
if (res.status === 401 || res.status === 403) return { ...out, needRefresh: true };
|
|
64
|
-
last = out;
|
|
65
|
-
}
|
|
66
|
-
return last || { ok: false, status: 0, code: null, msg: "无可用域", data: {} };
|
|
67
|
-
}
|
|
1
|
+
import { compatFetch, timeoutSignal } from "../../compat.js";
|
|
2
|
+
// WorkBuddy growth 域(/activity/growth/* 与 /v2/activity/growth/*)底层请求。
|
|
3
|
+
// 双域容灾与签到同款;业务失败结构化返回(ok:false + code/msg),不抛异常。
|
|
4
|
+
// 注意:领奖路径 /activity/growth/tasks/{code}/claim 无 /v2 前缀(上游实测形态)。
|
|
5
|
+
|
|
6
|
+
export const GROWTH_BASES = [
|
|
7
|
+
"https://copilot.tencent.com",
|
|
8
|
+
"https://www.codebuddy.cn",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export function growthHeaders({ at, uid, domain, enterpriseId }) {
|
|
12
|
+
return {
|
|
13
|
+
Authorization: `Bearer ${at}`,
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
Accept: "application/json",
|
|
16
|
+
"X-User-Id": uid,
|
|
17
|
+
"X-Domain": domain || "www.codebuddy.cn",
|
|
18
|
+
"X-Product": "SaaS",
|
|
19
|
+
"User-Agent": "CLI/2.115.0 WorkBuddy/2.115.0",
|
|
20
|
+
Origin: "https://www.codebuddy.cn",
|
|
21
|
+
Referer: "https://www.codebuddy.cn/",
|
|
22
|
+
...(enterpriseId ? { "X-Enterprise-Id": enterpriseId } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function growthRequest({
|
|
27
|
+
uid, at, domain, enterpriseId,
|
|
28
|
+
method = "GET", path, body,
|
|
29
|
+
fetchImpl = compatFetch, timeoutMs = 15000,
|
|
30
|
+
} = {}) {
|
|
31
|
+
const headers = growthHeaders({ at, uid, domain, enterpriseId });
|
|
32
|
+
let last = null;
|
|
33
|
+
for (const base of GROWTH_BASES) {
|
|
34
|
+
const url = base + path;
|
|
35
|
+
let res;
|
|
36
|
+
try {
|
|
37
|
+
res = await fetchImpl(url, {
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
...(method.toUpperCase() === "GET" ? {} : { body: JSON.stringify(body ?? {}) }),
|
|
41
|
+
signal: timeoutSignal(timeoutMs),
|
|
42
|
+
});
|
|
43
|
+
} catch (e) {
|
|
44
|
+
last = { ok: false, status: 0, code: null, msg: `网络失败: ${String(e?.message || e).slice(0, 200)}`, data: {}, url };
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
let payload = null;
|
|
48
|
+
try { payload = await res.json(); } catch { payload = null; }
|
|
49
|
+
if (!payload || typeof payload !== "object") {
|
|
50
|
+
last = { ok: false, status: res.status, code: null, msg: `非 JSON 响应 HTTP ${res.status}`, data: {}, url };
|
|
51
|
+
if (res.status === 401 || res.status === 403) return { ...last, needRefresh: true };
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const out = {
|
|
55
|
+
ok: res.status === 200 && payload.code === 0,
|
|
56
|
+
status: res.status,
|
|
57
|
+
code: payload.code,
|
|
58
|
+
msg: payload.msg || "",
|
|
59
|
+
data: payload.data || {},
|
|
60
|
+
url,
|
|
61
|
+
};
|
|
62
|
+
if (out.ok) return out;
|
|
63
|
+
if (res.status === 401 || res.status === 403) return { ...out, needRefresh: true };
|
|
64
|
+
last = out;
|
|
65
|
+
}
|
|
66
|
+
return last || { ok: false, status: 0, code: null, msg: "无可用域", data: {} };
|
|
67
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
// WorkBuddy 成长任务策略表:哪些任务可自动完成 / 用什么事件 / 何时只能人工。
|
|
2
|
-
// 来源:workbuddy2api admin/growth_plans.py 的逐条实测结论(1131 事件枚举 + 客户端机制证据)。
|
|
3
|
-
// 未登记任务默认 MANUAL——宁可漏做,不盲发请求污染上游日志。
|
|
4
|
-
|
|
5
|
-
export const PLAN_LEVELS = { AUTO: "auto", MULTI: "multi", MANUAL: "manual", SKIP: "skip" };
|
|
6
|
-
export const MAX_TIMES = 10;
|
|
7
|
-
|
|
8
|
-
function plan(code, level, eventCodes = [], reason = "", model = "") {
|
|
9
|
-
return {
|
|
10
|
-
code, level, eventCodes, model, reason,
|
|
11
|
-
actionable: (level === PLAN_LEVELS.AUTO || level === PLAN_LEVELS.MULTI) && eventCodes.length > 0,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const TASK_PLANS = {
|
|
16
|
-
// —— 上游实测可自动 ——
|
|
17
|
-
chat_5: plan("chat_5", PLAN_LEVELS.MULTI, ["chat_request_send"], "对话类:带 growthEvent 的对话请求,按 target 次数重复"),
|
|
18
|
-
automation_1: plan("automation_1", PLAN_LEVELS.AUTO, ["automated_task_create_suc"], "自动化任务:创建成功事件"),
|
|
19
|
-
skill_1: plan("skill_1", PLAN_LEVELS.AUTO, ["skill_info"], "尝鲜技能:skill_info 事件"),
|
|
20
|
-
"Model_chat_GLM5.2": plan("Model_chat_GLM5.2", PLAN_LEVELS.AUTO, ["chat_request_send"], "模型体验:必须真实调用 glm-5.2(发事件包无效)", "glm-5.2"),
|
|
21
|
-
// —— 机制上必须客户端(上游枚举 1131 事件未命中)——
|
|
22
|
-
RichMeow_Chat: plan("RichMeow_Chat", PLAN_LEVELS.MANUAL, [], "桌面端对话:上游按客户端类型判定,需真实桌面端"),
|
|
23
|
-
expert_5: plan("expert_5", PLAN_LEVELS.MANUAL, [], "召唤专家:客户端本地专家包下载+激活,非服务端事件"),
|
|
24
|
-
expert_5_paid: plan("expert_5_paid", PLAN_LEVELS.MANUAL, [], "召唤专家(付费版):同上"),
|
|
25
|
-
Expert_team_use_3: plan("Expert_team_use_3", PLAN_LEVELS.MANUAL, [], "召唤专家团:同上"),
|
|
26
|
-
Hp_Appearance: plan("Hp_Appearance", PLAN_LEVELS.MANUAL, [], "和平精英主题:桌面端本地设置状态"),
|
|
27
|
-
create_canvas: plan("create_canvas", PLAN_LEVELS.MANUAL, [], "设计创意模式:需真实创建画布"),
|
|
28
|
-
template_5: plan("template_5", PLAN_LEVELS.MANUAL, ["agent_task_created_with_template"], "使用模板:尝试模板事件未验证,暂按人工"),
|
|
29
|
-
playbook_prompt: plan("playbook_prompt", PLAN_LEVELS.MANUAL, [], "灵感案例:未找到有效事件"),
|
|
30
|
-
Library_read: plan("Library_read", PLAN_LEVELS.MANUAL, [], "资料库:未找到有效事件"),
|
|
31
|
-
Expert_Philanthropy: plan("Expert_Philanthropy", PLAN_LEVELS.MANUAL, [], "公益专家:未找到有效事件"),
|
|
32
|
-
Buddy_App: plan("Buddy_App", PLAN_LEVELS.MANUAL, [], "发现应用:未找到有效事件"),
|
|
33
|
-
Buddy_App_QQ: plan("Buddy_App_QQ", PLAN_LEVELS.MANUAL, [], "企鹅教师助手:未找到有效事件"),
|
|
34
|
-
Expert_lighthouse: plan("Expert_lighthouse", PLAN_LEVELS.MANUAL, [], "腾讯轻量云专家:未找到有效事件"),
|
|
35
|
-
// —— 无收益 ——
|
|
36
|
-
black_cat: plan("black_cat", PLAN_LEVELS.SKIP, [], "夜猫子折扣活动,奖励为 0"),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const DEFAULT_PLAN = plan("", PLAN_LEVELS.MANUAL, [], "未登记的任务类型,需人工确认");
|
|
40
|
-
|
|
41
|
-
export function planFor(code) {
|
|
42
|
-
return TASK_PLANS[code] || DEFAULT_PLAN;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function classifyTask(task = {}) {
|
|
46
|
-
const code = task.task_code || "";
|
|
47
|
-
const p = planFor(code);
|
|
48
|
-
let level = p.level;
|
|
49
|
-
const reward = Number(task.reward_credit || 0);
|
|
50
|
-
if (reward <= 0 && level !== PLAN_LEVELS.SKIP) level = PLAN_LEVELS.SKIP;
|
|
51
|
-
const prog = task.progress || {};
|
|
52
|
-
const target = Number(prog.target);
|
|
53
|
-
const current = Number(prog.current || 0);
|
|
54
|
-
const rawNeed = Number.isInteger(target) && target > current ? target - current : 1;
|
|
55
|
-
return {
|
|
56
|
-
...task,
|
|
57
|
-
level,
|
|
58
|
-
actionable: (level === PLAN_LEVELS.AUTO || level === PLAN_LEVELS.MULTI) && p.eventCodes.length > 0,
|
|
59
|
-
strategy: p.reason,
|
|
60
|
-
model: p.model,
|
|
61
|
-
need_times: Math.max(1, Math.min(rawNeed, MAX_TIMES)),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
1
|
+
// WorkBuddy 成长任务策略表:哪些任务可自动完成 / 用什么事件 / 何时只能人工。
|
|
2
|
+
// 来源:workbuddy2api admin/growth_plans.py 的逐条实测结论(1131 事件枚举 + 客户端机制证据)。
|
|
3
|
+
// 未登记任务默认 MANUAL——宁可漏做,不盲发请求污染上游日志。
|
|
4
|
+
|
|
5
|
+
export const PLAN_LEVELS = { AUTO: "auto", MULTI: "multi", MANUAL: "manual", SKIP: "skip" };
|
|
6
|
+
export const MAX_TIMES = 10;
|
|
7
|
+
|
|
8
|
+
function plan(code, level, eventCodes = [], reason = "", model = "") {
|
|
9
|
+
return {
|
|
10
|
+
code, level, eventCodes, model, reason,
|
|
11
|
+
actionable: (level === PLAN_LEVELS.AUTO || level === PLAN_LEVELS.MULTI) && eventCodes.length > 0,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const TASK_PLANS = {
|
|
16
|
+
// —— 上游实测可自动 ——
|
|
17
|
+
chat_5: plan("chat_5", PLAN_LEVELS.MULTI, ["chat_request_send"], "对话类:带 growthEvent 的对话请求,按 target 次数重复"),
|
|
18
|
+
automation_1: plan("automation_1", PLAN_LEVELS.AUTO, ["automated_task_create_suc"], "自动化任务:创建成功事件"),
|
|
19
|
+
skill_1: plan("skill_1", PLAN_LEVELS.AUTO, ["skill_info"], "尝鲜技能:skill_info 事件"),
|
|
20
|
+
"Model_chat_GLM5.2": plan("Model_chat_GLM5.2", PLAN_LEVELS.AUTO, ["chat_request_send"], "模型体验:必须真实调用 glm-5.2(发事件包无效)", "glm-5.2"),
|
|
21
|
+
// —— 机制上必须客户端(上游枚举 1131 事件未命中)——
|
|
22
|
+
RichMeow_Chat: plan("RichMeow_Chat", PLAN_LEVELS.MANUAL, [], "桌面端对话:上游按客户端类型判定,需真实桌面端"),
|
|
23
|
+
expert_5: plan("expert_5", PLAN_LEVELS.MANUAL, [], "召唤专家:客户端本地专家包下载+激活,非服务端事件"),
|
|
24
|
+
expert_5_paid: plan("expert_5_paid", PLAN_LEVELS.MANUAL, [], "召唤专家(付费版):同上"),
|
|
25
|
+
Expert_team_use_3: plan("Expert_team_use_3", PLAN_LEVELS.MANUAL, [], "召唤专家团:同上"),
|
|
26
|
+
Hp_Appearance: plan("Hp_Appearance", PLAN_LEVELS.MANUAL, [], "和平精英主题:桌面端本地设置状态"),
|
|
27
|
+
create_canvas: plan("create_canvas", PLAN_LEVELS.MANUAL, [], "设计创意模式:需真实创建画布"),
|
|
28
|
+
template_5: plan("template_5", PLAN_LEVELS.MANUAL, ["agent_task_created_with_template"], "使用模板:尝试模板事件未验证,暂按人工"),
|
|
29
|
+
playbook_prompt: plan("playbook_prompt", PLAN_LEVELS.MANUAL, [], "灵感案例:未找到有效事件"),
|
|
30
|
+
Library_read: plan("Library_read", PLAN_LEVELS.MANUAL, [], "资料库:未找到有效事件"),
|
|
31
|
+
Expert_Philanthropy: plan("Expert_Philanthropy", PLAN_LEVELS.MANUAL, [], "公益专家:未找到有效事件"),
|
|
32
|
+
Buddy_App: plan("Buddy_App", PLAN_LEVELS.MANUAL, [], "发现应用:未找到有效事件"),
|
|
33
|
+
Buddy_App_QQ: plan("Buddy_App_QQ", PLAN_LEVELS.MANUAL, [], "企鹅教师助手:未找到有效事件"),
|
|
34
|
+
Expert_lighthouse: plan("Expert_lighthouse", PLAN_LEVELS.MANUAL, [], "腾讯轻量云专家:未找到有效事件"),
|
|
35
|
+
// —— 无收益 ——
|
|
36
|
+
black_cat: plan("black_cat", PLAN_LEVELS.SKIP, [], "夜猫子折扣活动,奖励为 0"),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const DEFAULT_PLAN = plan("", PLAN_LEVELS.MANUAL, [], "未登记的任务类型,需人工确认");
|
|
40
|
+
|
|
41
|
+
export function planFor(code) {
|
|
42
|
+
return TASK_PLANS[code] || DEFAULT_PLAN;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function classifyTask(task = {}) {
|
|
46
|
+
const code = task.task_code || "";
|
|
47
|
+
const p = planFor(code);
|
|
48
|
+
let level = p.level;
|
|
49
|
+
const reward = Number(task.reward_credit || 0);
|
|
50
|
+
if (reward <= 0 && level !== PLAN_LEVELS.SKIP) level = PLAN_LEVELS.SKIP;
|
|
51
|
+
const prog = task.progress || {};
|
|
52
|
+
const target = Number(prog.target);
|
|
53
|
+
const current = Number(prog.current || 0);
|
|
54
|
+
const rawNeed = Number.isInteger(target) && target > current ? target - current : 1;
|
|
55
|
+
return {
|
|
56
|
+
...task,
|
|
57
|
+
level,
|
|
58
|
+
actionable: (level === PLAN_LEVELS.AUTO || level === PLAN_LEVELS.MULTI) && p.eventCodes.length > 0,
|
|
59
|
+
strategy: p.reason,
|
|
60
|
+
model: p.model,
|
|
61
|
+
need_times: Math.max(1, Math.min(rawNeed, MAX_TIMES)),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import { compatFetch, timeoutSignal, uuid } from "../../compat.js";
|
|
2
|
-
import { GROWTH_BASES, growthHeaders, growthRequest } from "./growth-api.js";
|
|
3
|
-
import { PLAN_LEVELS, MAX_TIMES, planFor, classifyTask } from "./growth-plans.js";
|
|
4
|
-
// WorkBuddy 成长计划任务:拉列表 → 参与(accept) → 触发(growthEvent) → 领奖(claim)。
|
|
5
|
-
// 机制(上游实测):进度由请求体 extra_vars.growthEvent 驱动;未 accept 不累计;
|
|
6
|
-
// completed ≠ claimed(要另调领奖)。串行 + 节流是硬要求,同账号禁并行。
|
|
7
|
-
// 策略表(哪些任务可自动 / 用什么事件)见 growth-plans.js。
|
|
8
|
-
|
|
9
|
-
export { PLAN_LEVELS, MAX_TIMES, TASK_PLANS, planFor, classifyTask } from "./growth-plans.js";
|
|
10
|
-
|
|
11
|
-
// 注意:sleep 必须保活事件循环(不能 unref)——CLI 场景下 unref 的定时器
|
|
12
|
-
// 会让 Node 在等待期间判定 event loop 空而提前退出(exit 13 unsettled await)。
|
|
13
|
-
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
14
|
-
|
|
15
|
-
export async function waitFor(fn, { timeoutMs = 8000, intervalMs = 500, sleepFn = defaultSleep } = {}) {
|
|
16
|
-
const deadline = Date.now() + timeoutMs;
|
|
17
|
-
for (;;) {
|
|
18
|
-
let v = false;
|
|
19
|
-
try { v = await fn(); } catch {}
|
|
20
|
-
if (v) return true;
|
|
21
|
-
if (Date.now() >= deadline) return false;
|
|
22
|
-
await sleepFn(intervalMs);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function growthTasks(api = {}) {
|
|
27
|
-
const r = await growthRequest({ ...api, method: "GET", path: "/v2/activity/growth/tasks" });
|
|
28
|
-
return { ...r, tasks: r.ok ? (r.data?.tasks || []) : [] };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function growthAccept(api = {}, codes = []) {
|
|
32
|
-
return growthRequest({ ...api, method: "POST", path: "/v2/activity/growth/tasks/accept", body: { task_codes: [...codes] } });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function growthClaim(api = {}, code) {
|
|
36
|
-
return growthRequest({ ...api, method: "POST", path: `/activity/growth/tasks/${code}/claim` });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 通过带 growthEvent 的模型请求触发进度:正常 200 + 免费模型 + max_tokens=1(成本 0)。
|
|
40
|
-
// 读首块即主动断开,不等待全文。
|
|
41
|
-
export async function fireGrowthEvent(api = {}, { eventCodes = [], model, eventId, timeoutMs = 60000 } = {}) {
|
|
42
|
-
const { uid, at, domain, enterpriseId, fetchImpl = compatFetch } = api;
|
|
43
|
-
const id = eventId || uuid();
|
|
44
|
-
const body = {
|
|
45
|
-
model: model || process.env.MSLXDFF_WORKBUDDY_GROWTH_MODEL || "hy3",
|
|
46
|
-
stream: true,
|
|
47
|
-
max_tokens: 1,
|
|
48
|
-
messages: [{ role: "user", content: "hi" }],
|
|
49
|
-
extra_vars: { growthEvent: JSON.stringify(eventCodes.map((c) => ({ eventCode: c, id }))) },
|
|
50
|
-
};
|
|
51
|
-
let last = { ok: false, status: 0 };
|
|
52
|
-
for (const base of GROWTH_BASES) {
|
|
53
|
-
let res;
|
|
54
|
-
try {
|
|
55
|
-
res = await fetchImpl(`${base}/v2/chat/completions`, {
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: growthHeaders({ at, uid, domain, enterpriseId }),
|
|
58
|
-
body: JSON.stringify(body),
|
|
59
|
-
signal: timeoutSignal(timeoutMs),
|
|
60
|
-
});
|
|
61
|
-
} catch (e) {
|
|
62
|
-
last = { ok: false, status: 0, msg: String(e?.message || e).slice(0, 200) };
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const reader = res.body?.getReader?.();
|
|
67
|
-
if (reader) { await reader.read(); await reader.cancel?.(); }
|
|
68
|
-
} catch {}
|
|
69
|
-
if (res.status === 200) return { ok: true, status: 200 };
|
|
70
|
-
last = { ok: false, status: res.status, msg: `HTTP ${res.status}` };
|
|
71
|
-
}
|
|
72
|
-
return last;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 单账号闭环:拉列表 → 逐任务(accept→等落库→触发×N→等复查) → 统一领奖。
|
|
76
|
-
export async function runGrowthAccount({
|
|
77
|
-
uid, at, domain, enterpriseId,
|
|
78
|
-
codes, model,
|
|
79
|
-
fetchImpl = compatFetch, sleepFn = defaultSleep,
|
|
80
|
-
gaps = {}, onStep = null,
|
|
81
|
-
} = {}) {
|
|
82
|
-
const g = { eventMs: 1200, accountMs: 1000, pollMs: 500, acceptTimeoutMs: 8000, verifyTimeoutMs: 8000, ...gaps };
|
|
83
|
-
const api = { uid, at, domain, enterpriseId, fetchImpl };
|
|
84
|
-
const step = (e) => { try { onStep?.(e); } catch {} };
|
|
85
|
-
const out = { uid, ok: true, tasks: [], credit: 0, energy: 0 };
|
|
86
|
-
|
|
87
|
-
const listed = await growthTasks(api);
|
|
88
|
-
if (!listed.ok) { out.ok = false; out.error = listed.msg || "拉取任务列表失败"; return out; }
|
|
89
|
-
const byCode = new Map(listed.tasks.map((t) => [t.task_code, t]));
|
|
90
|
-
const wanted = Array.isArray(codes) && codes.length ? codes : listed.tasks.map((t) => t.task_code);
|
|
91
|
-
|
|
92
|
-
const latestOf = async (code) => {
|
|
93
|
-
const r = await growthTasks(api);
|
|
94
|
-
return r.ok ? r.tasks.find((t) => t.task_code === code) : undefined;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
for (const code of wanted) {
|
|
98
|
-
const raw = byCode.get(code);
|
|
99
|
-
if (!raw) { out.tasks.push({ task_code: code, ok: false, skipped: "任务不存在" }); continue; }
|
|
100
|
-
const info = classifyTask(raw);
|
|
101
|
-
if (info.accept_status === "claimed") {
|
|
102
|
-
out.tasks.push({ task_code: code, title: info.title, ok: true, skipped: "已领取", status: "claimed" });
|
|
103
|
-
step({ phase: "task", task_code: code, skipped: "已领取" });
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (!info.actionable) {
|
|
107
|
-
out.tasks.push({ task_code: code, title: info.title, ok: false, skipped: info.strategy || "需人工完成", level: info.level });
|
|
108
|
-
step({ phase: "task", task_code: code, skipped: info.strategy });
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (info.accept_status === "not_accepted") {
|
|
112
|
-
const ar = await growthAccept(api, [code]);
|
|
113
|
-
step({ phase: "accept", task_code: code, ok: ar.ok, msg: ar.msg });
|
|
114
|
-
if (ar.ok) {
|
|
115
|
-
await waitFor(async () => {
|
|
116
|
-
const t = await latestOf(code);
|
|
117
|
-
return !!t && !!t.accept_status && t.accept_status !== "not_accepted";
|
|
118
|
-
}, { timeoutMs: g.acceptTimeoutMs, intervalMs: g.pollMs, sleepFn });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
let fired = 0;
|
|
122
|
-
for (let i = 0; i < info.need_times; i++) {
|
|
123
|
-
const r = await fireGrowthEvent(api, { eventCodes: info.eventCodes || planFor(code).eventCodes, model: info.model || model });
|
|
124
|
-
if (r.ok) fired += 1;
|
|
125
|
-
step({ phase: "fire", task_code: code, i: i + 1, times: info.need_times, ok: r.ok, msg: r.msg });
|
|
126
|
-
if (i + 1 < info.need_times) await sleepFn(g.eventMs);
|
|
127
|
-
}
|
|
128
|
-
const base = info.progress?.current ?? 0;
|
|
129
|
-
await waitFor(async () => {
|
|
130
|
-
const t = await latestOf(code);
|
|
131
|
-
if (!t) return false;
|
|
132
|
-
if (t.accept_status === "completed" || t.accept_status === "claimed") return true;
|
|
133
|
-
return Number(t.progress?.current ?? 0) > Number(base);
|
|
134
|
-
}, { timeoutMs: g.verifyTimeoutMs, intervalMs: g.pollMs, sleepFn });
|
|
135
|
-
const latest = (await latestOf(code)) || info;
|
|
136
|
-
const item = {
|
|
137
|
-
task_code: code,
|
|
138
|
-
title: latest.title || info.title || code,
|
|
139
|
-
ok: fired > 0,
|
|
140
|
-
fired,
|
|
141
|
-
times: info.need_times,
|
|
142
|
-
status: latest.accept_status,
|
|
143
|
-
progress: `${latest.progress?.current ?? 0}/${latest.progress?.target ?? "?"}`,
|
|
144
|
-
};
|
|
145
|
-
out.tasks.push(item);
|
|
146
|
-
step({ phase: "task", ...item });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const done = (await growthTasks(api)).tasks.filter((t) => t.accept_status === "completed");
|
|
150
|
-
for (const t of done) {
|
|
151
|
-
const cr = await growthClaim(api, t.task_code);
|
|
152
|
-
const credit = Number(cr.data?.credit || 0);
|
|
153
|
-
const energy = Number(cr.data?.energy || 0);
|
|
154
|
-
if (cr.ok) {
|
|
155
|
-
out.credit += credit;
|
|
156
|
-
out.energy += energy;
|
|
157
|
-
const item = out.tasks.find((x) => x.task_code === t.task_code);
|
|
158
|
-
if (item) { item.status = "claimed"; item.credit = credit; item.energy = energy; item.ok = true; }
|
|
159
|
-
}
|
|
160
|
-
step({ phase: "claim", task_code: t.task_code, ok: cr.ok, credit, energy, msg: cr.msg });
|
|
161
|
-
await sleepFn(g.eventMs);
|
|
162
|
-
}
|
|
163
|
-
if (out.tasks.length && out.tasks.every((t) => !t.ok)) out.ok = false;
|
|
164
|
-
return out;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// 多账号串行(账号间 1s 节流;单账号异常不挡后续)。
|
|
168
|
-
export async function runGrowthAll({ accounts = [], onAccount, ...opts } = {}) {
|
|
169
|
-
const results = [];
|
|
170
|
-
let creditTotal = 0;
|
|
171
|
-
for (const a of accounts) {
|
|
172
|
-
let row;
|
|
173
|
-
try { row = await runGrowthAccount({ ...opts, ...a }); }
|
|
174
|
-
catch (e) { row = { uid: a.uid, ok: false, tasks: [], credit: 0, energy: 0, error: String(e?.message || e).slice(0, 200) }; }
|
|
175
|
-
results.push(row);
|
|
176
|
-
creditTotal += row.credit || 0;
|
|
177
|
-
try { onAccount?.(row); } catch {}
|
|
178
|
-
await (opts.sleepFn || defaultSleep)(opts.gaps?.accountMs ?? 1000);
|
|
179
|
-
}
|
|
180
|
-
return { ok: results.some((r) => r.ok), results, creditTotal };
|
|
181
|
-
}
|
|
1
|
+
import { compatFetch, timeoutSignal, uuid } from "../../compat.js";
|
|
2
|
+
import { GROWTH_BASES, growthHeaders, growthRequest } from "./growth-api.js";
|
|
3
|
+
import { PLAN_LEVELS, MAX_TIMES, planFor, classifyTask } from "./growth-plans.js";
|
|
4
|
+
// WorkBuddy 成长计划任务:拉列表 → 参与(accept) → 触发(growthEvent) → 领奖(claim)。
|
|
5
|
+
// 机制(上游实测):进度由请求体 extra_vars.growthEvent 驱动;未 accept 不累计;
|
|
6
|
+
// completed ≠ claimed(要另调领奖)。串行 + 节流是硬要求,同账号禁并行。
|
|
7
|
+
// 策略表(哪些任务可自动 / 用什么事件)见 growth-plans.js。
|
|
8
|
+
|
|
9
|
+
export { PLAN_LEVELS, MAX_TIMES, TASK_PLANS, planFor, classifyTask } from "./growth-plans.js";
|
|
10
|
+
|
|
11
|
+
// 注意:sleep 必须保活事件循环(不能 unref)——CLI 场景下 unref 的定时器
|
|
12
|
+
// 会让 Node 在等待期间判定 event loop 空而提前退出(exit 13 unsettled await)。
|
|
13
|
+
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
14
|
+
|
|
15
|
+
export async function waitFor(fn, { timeoutMs = 8000, intervalMs = 500, sleepFn = defaultSleep } = {}) {
|
|
16
|
+
const deadline = Date.now() + timeoutMs;
|
|
17
|
+
for (;;) {
|
|
18
|
+
let v = false;
|
|
19
|
+
try { v = await fn(); } catch {}
|
|
20
|
+
if (v) return true;
|
|
21
|
+
if (Date.now() >= deadline) return false;
|
|
22
|
+
await sleepFn(intervalMs);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function growthTasks(api = {}) {
|
|
27
|
+
const r = await growthRequest({ ...api, method: "GET", path: "/v2/activity/growth/tasks" });
|
|
28
|
+
return { ...r, tasks: r.ok ? (r.data?.tasks || []) : [] };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function growthAccept(api = {}, codes = []) {
|
|
32
|
+
return growthRequest({ ...api, method: "POST", path: "/v2/activity/growth/tasks/accept", body: { task_codes: [...codes] } });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function growthClaim(api = {}, code) {
|
|
36
|
+
return growthRequest({ ...api, method: "POST", path: `/activity/growth/tasks/${code}/claim` });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 通过带 growthEvent 的模型请求触发进度:正常 200 + 免费模型 + max_tokens=1(成本 0)。
|
|
40
|
+
// 读首块即主动断开,不等待全文。
|
|
41
|
+
export async function fireGrowthEvent(api = {}, { eventCodes = [], model, eventId, timeoutMs = 60000 } = {}) {
|
|
42
|
+
const { uid, at, domain, enterpriseId, fetchImpl = compatFetch } = api;
|
|
43
|
+
const id = eventId || uuid();
|
|
44
|
+
const body = {
|
|
45
|
+
model: model || process.env.MSLXDFF_WORKBUDDY_GROWTH_MODEL || "hy3",
|
|
46
|
+
stream: true,
|
|
47
|
+
max_tokens: 1,
|
|
48
|
+
messages: [{ role: "user", content: "hi" }],
|
|
49
|
+
extra_vars: { growthEvent: JSON.stringify(eventCodes.map((c) => ({ eventCode: c, id }))) },
|
|
50
|
+
};
|
|
51
|
+
let last = { ok: false, status: 0 };
|
|
52
|
+
for (const base of GROWTH_BASES) {
|
|
53
|
+
let res;
|
|
54
|
+
try {
|
|
55
|
+
res = await fetchImpl(`${base}/v2/chat/completions`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: growthHeaders({ at, uid, domain, enterpriseId }),
|
|
58
|
+
body: JSON.stringify(body),
|
|
59
|
+
signal: timeoutSignal(timeoutMs),
|
|
60
|
+
});
|
|
61
|
+
} catch (e) {
|
|
62
|
+
last = { ok: false, status: 0, msg: String(e?.message || e).slice(0, 200) };
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const reader = res.body?.getReader?.();
|
|
67
|
+
if (reader) { await reader.read(); await reader.cancel?.(); }
|
|
68
|
+
} catch {}
|
|
69
|
+
if (res.status === 200) return { ok: true, status: 200 };
|
|
70
|
+
last = { ok: false, status: res.status, msg: `HTTP ${res.status}` };
|
|
71
|
+
}
|
|
72
|
+
return last;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 单账号闭环:拉列表 → 逐任务(accept→等落库→触发×N→等复查) → 统一领奖。
|
|
76
|
+
export async function runGrowthAccount({
|
|
77
|
+
uid, at, domain, enterpriseId,
|
|
78
|
+
codes, model,
|
|
79
|
+
fetchImpl = compatFetch, sleepFn = defaultSleep,
|
|
80
|
+
gaps = {}, onStep = null,
|
|
81
|
+
} = {}) {
|
|
82
|
+
const g = { eventMs: 1200, accountMs: 1000, pollMs: 500, acceptTimeoutMs: 8000, verifyTimeoutMs: 8000, ...gaps };
|
|
83
|
+
const api = { uid, at, domain, enterpriseId, fetchImpl };
|
|
84
|
+
const step = (e) => { try { onStep?.(e); } catch {} };
|
|
85
|
+
const out = { uid, ok: true, tasks: [], credit: 0, energy: 0 };
|
|
86
|
+
|
|
87
|
+
const listed = await growthTasks(api);
|
|
88
|
+
if (!listed.ok) { out.ok = false; out.error = listed.msg || "拉取任务列表失败"; return out; }
|
|
89
|
+
const byCode = new Map(listed.tasks.map((t) => [t.task_code, t]));
|
|
90
|
+
const wanted = Array.isArray(codes) && codes.length ? codes : listed.tasks.map((t) => t.task_code);
|
|
91
|
+
|
|
92
|
+
const latestOf = async (code) => {
|
|
93
|
+
const r = await growthTasks(api);
|
|
94
|
+
return r.ok ? r.tasks.find((t) => t.task_code === code) : undefined;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
for (const code of wanted) {
|
|
98
|
+
const raw = byCode.get(code);
|
|
99
|
+
if (!raw) { out.tasks.push({ task_code: code, ok: false, skipped: "任务不存在" }); continue; }
|
|
100
|
+
const info = classifyTask(raw);
|
|
101
|
+
if (info.accept_status === "claimed") {
|
|
102
|
+
out.tasks.push({ task_code: code, title: info.title, ok: true, skipped: "已领取", status: "claimed" });
|
|
103
|
+
step({ phase: "task", task_code: code, skipped: "已领取" });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!info.actionable) {
|
|
107
|
+
out.tasks.push({ task_code: code, title: info.title, ok: false, skipped: info.strategy || "需人工完成", level: info.level });
|
|
108
|
+
step({ phase: "task", task_code: code, skipped: info.strategy });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (info.accept_status === "not_accepted") {
|
|
112
|
+
const ar = await growthAccept(api, [code]);
|
|
113
|
+
step({ phase: "accept", task_code: code, ok: ar.ok, msg: ar.msg });
|
|
114
|
+
if (ar.ok) {
|
|
115
|
+
await waitFor(async () => {
|
|
116
|
+
const t = await latestOf(code);
|
|
117
|
+
return !!t && !!t.accept_status && t.accept_status !== "not_accepted";
|
|
118
|
+
}, { timeoutMs: g.acceptTimeoutMs, intervalMs: g.pollMs, sleepFn });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let fired = 0;
|
|
122
|
+
for (let i = 0; i < info.need_times; i++) {
|
|
123
|
+
const r = await fireGrowthEvent(api, { eventCodes: info.eventCodes || planFor(code).eventCodes, model: info.model || model });
|
|
124
|
+
if (r.ok) fired += 1;
|
|
125
|
+
step({ phase: "fire", task_code: code, i: i + 1, times: info.need_times, ok: r.ok, msg: r.msg });
|
|
126
|
+
if (i + 1 < info.need_times) await sleepFn(g.eventMs);
|
|
127
|
+
}
|
|
128
|
+
const base = info.progress?.current ?? 0;
|
|
129
|
+
await waitFor(async () => {
|
|
130
|
+
const t = await latestOf(code);
|
|
131
|
+
if (!t) return false;
|
|
132
|
+
if (t.accept_status === "completed" || t.accept_status === "claimed") return true;
|
|
133
|
+
return Number(t.progress?.current ?? 0) > Number(base);
|
|
134
|
+
}, { timeoutMs: g.verifyTimeoutMs, intervalMs: g.pollMs, sleepFn });
|
|
135
|
+
const latest = (await latestOf(code)) || info;
|
|
136
|
+
const item = {
|
|
137
|
+
task_code: code,
|
|
138
|
+
title: latest.title || info.title || code,
|
|
139
|
+
ok: fired > 0,
|
|
140
|
+
fired,
|
|
141
|
+
times: info.need_times,
|
|
142
|
+
status: latest.accept_status,
|
|
143
|
+
progress: `${latest.progress?.current ?? 0}/${latest.progress?.target ?? "?"}`,
|
|
144
|
+
};
|
|
145
|
+
out.tasks.push(item);
|
|
146
|
+
step({ phase: "task", ...item });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const done = (await growthTasks(api)).tasks.filter((t) => t.accept_status === "completed");
|
|
150
|
+
for (const t of done) {
|
|
151
|
+
const cr = await growthClaim(api, t.task_code);
|
|
152
|
+
const credit = Number(cr.data?.credit || 0);
|
|
153
|
+
const energy = Number(cr.data?.energy || 0);
|
|
154
|
+
if (cr.ok) {
|
|
155
|
+
out.credit += credit;
|
|
156
|
+
out.energy += energy;
|
|
157
|
+
const item = out.tasks.find((x) => x.task_code === t.task_code);
|
|
158
|
+
if (item) { item.status = "claimed"; item.credit = credit; item.energy = energy; item.ok = true; }
|
|
159
|
+
}
|
|
160
|
+
step({ phase: "claim", task_code: t.task_code, ok: cr.ok, credit, energy, msg: cr.msg });
|
|
161
|
+
await sleepFn(g.eventMs);
|
|
162
|
+
}
|
|
163
|
+
if (out.tasks.length && out.tasks.every((t) => !t.ok)) out.ok = false;
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 多账号串行(账号间 1s 节流;单账号异常不挡后续)。
|
|
168
|
+
export async function runGrowthAll({ accounts = [], onAccount, ...opts } = {}) {
|
|
169
|
+
const results = [];
|
|
170
|
+
let creditTotal = 0;
|
|
171
|
+
for (const a of accounts) {
|
|
172
|
+
let row;
|
|
173
|
+
try { row = await runGrowthAccount({ ...opts, ...a }); }
|
|
174
|
+
catch (e) { row = { uid: a.uid, ok: false, tasks: [], credit: 0, energy: 0, error: String(e?.message || e).slice(0, 200) }; }
|
|
175
|
+
results.push(row);
|
|
176
|
+
creditTotal += row.credit || 0;
|
|
177
|
+
try { onAccount?.(row); } catch {}
|
|
178
|
+
await (opts.sleepFn || defaultSleep)(opts.gaps?.accountMs ?? 1000);
|
|
179
|
+
}
|
|
180
|
+
return { ok: results.some((r) => r.ok), results, creditTotal };
|
|
181
|
+
}
|