mslxdff 0.1.199 → 0.1.203
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/package.json +38 -38
- package/plugins/README.md +14 -14
- package/plugins/prefer-model.mjs.example +14 -14
- package/src/anthropic/count-tokens.js +61 -61
- package/src/anthropic/request-body.js +126 -126
- package/src/anthropic/shared.js +18 -18
- package/src/anthropic/sse-aggregate.js +56 -56
- package/src/anthropic/translate.js +287 -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/serial-trial.js +283 -283
- package/src/chat-pipeline/terminal-verdict.js +147 -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 +149 -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/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 +70 -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 +62 -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 -251
- package/src/plugins.js +107 -107
- 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 -165
- package/src/providers/raccoon/credits.js +185 -175
- package/src/providers/raccoon/crypto.js +43 -0
- 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 -87
- 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/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 +83 -83
- package/src/routes/index.js +147 -147
- package/src/routes/messages-route.js +365 -365
- package/src/routes/peers.js +23 -1
- 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/bootstrap.js +8 -0
- 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 -0
- 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/server.js +7 -0
- 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 -72
- 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/upstream.js +53 -1
- package/src/usage/record.js +106 -106
- package/src/usage/report.js +195 -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 -239
- 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
- package/docs/cli_help_mini.md +0 -146
- package/src/providers/AGENTS.md +0 -49
- package/src/routes/AGENTS.md +0 -37
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { defaultStateFile, readState, writeStateImmediate, writeStateDeferred } from "../store.js";
|
|
2
|
-
|
|
3
|
-
export function loadPeers({ file = defaultStateFile() } = {}) {
|
|
4
|
-
const peers = readState(file).peers;
|
|
5
|
-
return Array.isArray(peers) ? peers : [];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function savePeers(peers, { file = defaultStateFile() } = {}) {
|
|
9
|
-
writeStateImmediate(file, { peers });
|
|
10
|
-
return peers;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function loadPeerErrors({ file = defaultStateFile() } = {}) {
|
|
14
|
-
const errors = readState(file).peerErrors;
|
|
15
|
-
return errors && typeof errors === "object" && !Array.isArray(errors) ? errors : {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function savePeerErrors(errors, { file = defaultStateFile() } = {}) {
|
|
19
|
-
writeStateDeferred(file, { peerErrors: errors });
|
|
20
|
-
return errors;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function loadPeerStats({ file = defaultStateFile() } = {}) {
|
|
24
|
-
const stats = readState(file).peerStats;
|
|
25
|
-
return stats && typeof stats === "object" && !Array.isArray(stats) ? stats : {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function savePeerStats(stats, { file = defaultStateFile() } = {}) {
|
|
29
|
-
writeStateDeferred(file, { peerStats: stats });
|
|
30
|
-
return stats;
|
|
31
|
-
}
|
|
1
|
+
import { defaultStateFile, readState, writeStateImmediate, writeStateDeferred } from "../store.js";
|
|
2
|
+
|
|
3
|
+
export function loadPeers({ file = defaultStateFile() } = {}) {
|
|
4
|
+
const peers = readState(file).peers;
|
|
5
|
+
return Array.isArray(peers) ? peers : [];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function savePeers(peers, { file = defaultStateFile() } = {}) {
|
|
9
|
+
writeStateImmediate(file, { peers });
|
|
10
|
+
return peers;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function loadPeerErrors({ file = defaultStateFile() } = {}) {
|
|
14
|
+
const errors = readState(file).peerErrors;
|
|
15
|
+
return errors && typeof errors === "object" && !Array.isArray(errors) ? errors : {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function savePeerErrors(errors, { file = defaultStateFile() } = {}) {
|
|
19
|
+
writeStateDeferred(file, { peerErrors: errors });
|
|
20
|
+
return errors;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function loadPeerStats({ file = defaultStateFile() } = {}) {
|
|
24
|
+
const stats = readState(file).peerStats;
|
|
25
|
+
return stats && typeof stats === "object" && !Array.isArray(stats) ? stats : {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function savePeerStats(stats, { file = defaultStateFile() } = {}) {
|
|
29
|
+
writeStateDeferred(file, { peerStats: stats });
|
|
30
|
+
return stats;
|
|
31
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
-
|
|
3
|
-
export function setPort(port, { file = defaultStateFile() } = {}) {
|
|
4
|
-
writeStateImmediate(file, { port: Number(port) });
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function getPort({ file = defaultStateFile() } = {}) {
|
|
8
|
-
const port = readState(file).port;
|
|
9
|
-
return typeof port === "number" && Number.isInteger(port) && port > 0 ? port : null;
|
|
10
|
-
}
|
|
1
|
+
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
+
|
|
3
|
+
export function setPort(port, { file = defaultStateFile() } = {}) {
|
|
4
|
+
writeStateImmediate(file, { port: Number(port) });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getPort({ file = defaultStateFile() } = {}) {
|
|
8
|
+
const port = readState(file).port;
|
|
9
|
+
return typeof port === "number" && Number.isInteger(port) && port > 0 ? port : null;
|
|
10
|
+
}
|
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
-
export {
|
|
3
|
-
WORKBUDDY_DEFAULT_BASE_URL,
|
|
4
|
-
normalizeBaseUrl,
|
|
5
|
-
normalizeAuths,
|
|
6
|
-
normalizeAllowedModel,
|
|
7
|
-
normalizeEndpointPath,
|
|
8
|
-
defaultModelsPath,
|
|
9
|
-
defaultChatPath,
|
|
10
|
-
providerKeyEnv,
|
|
11
|
-
providerBaseUrlEnv,
|
|
12
|
-
} from "../provider-config.js";
|
|
13
|
-
import {
|
|
14
|
-
normalizeBaseUrl as _normalizeBaseUrl,
|
|
15
|
-
normalizeAuths as _normalizeAuths,
|
|
16
|
-
normalizeAllowedModel as _normalizeAllowedModel,
|
|
17
|
-
normalizeEndpointPath as _normalizeEndpointPath,
|
|
18
|
-
defaultModelsPath as _defaultModelsPath,
|
|
19
|
-
defaultChatPath as _defaultChatPath,
|
|
20
|
-
providerKeyEnv as _providerKeyEnv,
|
|
21
|
-
providerBaseUrlEnv as _providerBaseUrlEnv,
|
|
22
|
-
WORKBUDDY_DEFAULT_BASE_URL as _WORKBUDDY,
|
|
23
|
-
} from "../provider-config.js";
|
|
24
|
-
|
|
25
|
-
// 薄门面:所有 load/save 仍在此,但归一化逻辑已收至 provider-config 单点
|
|
26
|
-
export function loadProviderModelsPath(id, { file = defaultStateFile() } = {}) {
|
|
27
|
-
const cfg = readState(file).providerConfigs?.[id];
|
|
28
|
-
if (cfg && typeof cfg.modelsPath === "string" && cfg.modelsPath.trim()) return _normalizeEndpointPath(cfg.modelsPath);
|
|
29
|
-
return _defaultModelsPath(id);
|
|
30
|
-
}
|
|
31
|
-
export function loadProviderChatPath(id, { file = defaultStateFile() } = {}) {
|
|
32
|
-
const cfg = readState(file).providerConfigs?.[id];
|
|
33
|
-
if (cfg && typeof cfg.chatPath === "string" && cfg.chatPath.trim()) return _normalizeEndpointPath(cfg.chatPath);
|
|
34
|
-
return _defaultChatPath(id);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function loadProviderKeys(id, { file = defaultStateFile() } = {}) {
|
|
38
|
-
const env = (process.env[_providerKeyEnv(id)] || "").trim();
|
|
39
|
-
if (env) return [env];
|
|
40
|
-
const configs = readState(file).providerConfigs;
|
|
41
|
-
const cfg = configs && typeof configs === "object" ? configs[id] : undefined;
|
|
42
|
-
if (cfg && typeof cfg === "object" && Array.isArray(cfg.keys)) {
|
|
43
|
-
const list = [...new Set(cfg.keys.filter((x) => typeof x === "string" && x.trim().length))];
|
|
44
|
-
if (list.length) return list;
|
|
45
|
-
}
|
|
46
|
-
const keys = readState(file).providerKeys;
|
|
47
|
-
const v = keys && typeof keys === "object" ? keys[id] : undefined;
|
|
48
|
-
if (typeof v === "string") return v.trim() ? [v.trim()] : [];
|
|
49
|
-
if (Array.isArray(v)) return [...new Set(v.filter((x) => typeof x === "string" && x.trim().length))];
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
export function loadProviderKey(id, opts = {}) { return loadProviderKeys(id, opts)[0] || ""; }
|
|
53
|
-
// 本节点所有「有 key」的供应商 id(providerConfigs ∪ providerKeys,含 env 覆盖)——
|
|
54
|
-
// 转发时默认借出的候选集合由它枚举;见 src/providers/share-keys.js
|
|
55
|
-
export function listProviderIdsWithKeys({ file = defaultStateFile() } = {}) {
|
|
56
|
-
const st = readState(file);
|
|
57
|
-
const ids = new Set();
|
|
58
|
-
for (const src of [st.providerConfigs, st.providerKeys]) {
|
|
59
|
-
if (src && typeof src === "object" && !Array.isArray(src)) for (const id of Object.keys(src)) ids.add(id);
|
|
60
|
-
}
|
|
61
|
-
return [...ids].filter((id) => loadProviderKeys(id, { file }).length > 0);
|
|
62
|
-
}
|
|
63
|
-
export function saveProviderKeys(id, list, { file = defaultStateFile() } = {}) {
|
|
64
|
-
const keys = { ...(readState(file).providerKeys || {}) };
|
|
65
|
-
const clean = [...new Set((Array.isArray(list) ? list : []).map((k) => String(k || "").trim()).filter(Boolean))];
|
|
66
|
-
if (clean.length) keys[id] = clean; else delete keys[id];
|
|
67
|
-
writeStateImmediate(file, { providerKeys: keys });
|
|
68
|
-
return clean;
|
|
69
|
-
}
|
|
70
|
-
export function saveProviderKey(id, key, opts = {}) {
|
|
71
|
-
const list = [...loadProviderKeys(id, opts)];
|
|
72
|
-
const clean = String(key || "").trim();
|
|
73
|
-
if (clean && !list.includes(clean)) list.push(clean);
|
|
74
|
-
return saveProviderKeys(id, clean ? list : [], opts);
|
|
75
|
-
}
|
|
76
|
-
export function addProviderKey(id, key, opts = {}) { return saveProviderKey(id, key, opts); }
|
|
77
|
-
export function removeProviderKey(id, key, opts = {}) { return removeProviderKeys(id, [key], opts); }
|
|
78
|
-
export function removeProviderKeys(id, targets = [], opts = {}) {
|
|
79
|
-
const set = new Set((Array.isArray(targets) ? targets : [targets]).map((k) => String(k || "").trim()).filter(Boolean));
|
|
80
|
-
const list = loadProviderKeys(id, opts).filter((k) => !set.has(k));
|
|
81
|
-
return saveProviderKeys(id, list, opts);
|
|
82
|
-
}
|
|
83
|
-
export function loadProviderConfigs({ file = defaultStateFile() } = {}) {
|
|
84
|
-
const v = readState(file).providerConfigs;
|
|
85
|
-
if (v && typeof v === "object" && !Array.isArray(v)) return v;
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
88
|
-
export function loadProviderConfig(id, { file = defaultStateFile() } = {}) {
|
|
89
|
-
const envUrl = (process.env[_providerBaseUrlEnv(id)] || "").trim();
|
|
90
|
-
const envKeys = loadProviderKeys(id, { file });
|
|
91
|
-
if (envUrl || (process.env[_providerKeyEnv(id)] || "").trim()) {
|
|
92
|
-
const baseUrl = envUrl || loadProviderConfigs({ file })[id]?.baseUrl || (String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "");
|
|
93
|
-
const cfg = loadProviderConfigs({ file })[id];
|
|
94
|
-
const allowedModels = cfg && Array.isArray(cfg.allowedModels) ? [...new Set(cfg.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
95
|
-
const auths = cfg && Array.isArray(cfg.auths) ? _normalizeAuths(cfg.auths) : [];
|
|
96
|
-
const modelsPath = cfg && typeof cfg.modelsPath === "string" && cfg.modelsPath.trim() ? _normalizeEndpointPath(cfg.modelsPath) : _defaultModelsPath(id);
|
|
97
|
-
const chatPath = cfg && typeof cfg.chatPath === "string" && cfg.chatPath.trim() ? _normalizeEndpointPath(cfg.chatPath) : _defaultChatPath(id);
|
|
98
|
-
if (baseUrl || envKeys.length || allowedModels.length || auths.length) return { baseUrl: _normalizeBaseUrl(baseUrl), keys: envKeys, auths, allowedModels, modelsPath, chatPath };
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
const configs = loadProviderConfigs({ file });
|
|
102
|
-
const cfg = configs[id];
|
|
103
|
-
if (cfg && typeof cfg === "object") {
|
|
104
|
-
return {
|
|
105
|
-
baseUrl: _normalizeBaseUrl(cfg.baseUrl || (String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "")),
|
|
106
|
-
keys: Array.isArray(cfg.keys) ? [...new Set(cfg.keys.filter((x) => typeof x === "string" && x.trim().length))] : [],
|
|
107
|
-
auths: _normalizeAuths(cfg.auths),
|
|
108
|
-
allowedModels: Array.isArray(cfg.allowedModels) ? [...new Set(cfg.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [],
|
|
109
|
-
modelsPath: typeof cfg.modelsPath === "string" && cfg.modelsPath.trim() ? _normalizeEndpointPath(cfg.modelsPath) : _defaultModelsPath(id),
|
|
110
|
-
chatPath: typeof cfg.chatPath === "string" && cfg.chatPath.trim() ? _normalizeEndpointPath(cfg.chatPath) : _defaultChatPath(id),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
const keys = loadProviderKeys(id, { file });
|
|
114
|
-
if (keys.length) return { baseUrl: String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "", keys, auths: [], allowedModels: [], modelsPath: _defaultModelsPath(id), chatPath: _defaultChatPath(id) };
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
export function loadProviderBaseUrl(id, opts = {}) {
|
|
118
|
-
const env = (process.env[_providerBaseUrlEnv(id)] || "").trim();
|
|
119
|
-
if (env) return _normalizeBaseUrl(env);
|
|
120
|
-
const cfg = loadProviderConfigs(opts)[id];
|
|
121
|
-
if (cfg && typeof cfg.baseUrl === "string" && _normalizeBaseUrl(cfg.baseUrl)) return _normalizeBaseUrl(cfg.baseUrl);
|
|
122
|
-
if (String(id || "").toLowerCase() === "workbuddy") return _WORKBUDDY;
|
|
123
|
-
return "";
|
|
124
|
-
}
|
|
125
|
-
export function loadProviderAuths(id, { file = defaultStateFile() } = {}) {
|
|
126
|
-
const cfg = loadProviderConfigs({ file })[id];
|
|
127
|
-
if (cfg && Array.isArray(cfg.auths)) return _normalizeAuths(cfg.auths);
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
export function saveProviderAuths(id, list, { file = defaultStateFile() } = {}) {
|
|
131
|
-
const clean = _normalizeAuths(list);
|
|
132
|
-
const configs = { ...loadProviderConfigs({ file }) };
|
|
133
|
-
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
134
|
-
const baseUrl = _normalizeBaseUrl(cur.baseUrl || loadProviderBaseUrl(id, { file }) || "");
|
|
135
|
-
const keys = Array.isArray(cur.keys) ? [...new Set(cur.keys.filter((x) => typeof x === "string" && x.trim().length))] : loadProviderKeys(id, { file });
|
|
136
|
-
const allowedModels = Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
137
|
-
const modelsPath = typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "";
|
|
138
|
-
const chatPath = typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "";
|
|
139
|
-
if (!baseUrl && !keys.length && !clean.length && !allowedModels.length && !modelsPath && !chatPath) delete configs[id];
|
|
140
|
-
else {
|
|
141
|
-
configs[id] = { baseUrl, keys };
|
|
142
|
-
if (clean.length) configs[id].auths = clean;
|
|
143
|
-
if (allowedModels.length) configs[id].allowedModels = allowedModels;
|
|
144
|
-
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
145
|
-
if (chatPath) configs[id].chatPath = chatPath;
|
|
146
|
-
}
|
|
147
|
-
writeStateImmediate(file, { providerConfigs: configs });
|
|
148
|
-
return clean;
|
|
149
|
-
}
|
|
150
|
-
export function saveProviderBaseUrl(id, baseUrl, { file = defaultStateFile() } = {}) {
|
|
151
|
-
const clean = _normalizeBaseUrl(baseUrl);
|
|
152
|
-
const configs = { ...loadProviderConfigs({ file }) };
|
|
153
|
-
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
154
|
-
const keys = Array.isArray(cur.keys) ? cur.keys : loadProviderKeys(id, { file });
|
|
155
|
-
const auths = _normalizeAuths(cur.auths);
|
|
156
|
-
const allowedModels = Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
157
|
-
const modelsPath = typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "";
|
|
158
|
-
const chatPath = typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "";
|
|
159
|
-
if (!clean && !keys.length && !auths.length && !allowedModels.length && !modelsPath && !chatPath) delete configs[id];
|
|
160
|
-
else {
|
|
161
|
-
configs[id] = { baseUrl: clean, keys };
|
|
162
|
-
if (auths.length) configs[id].auths = auths;
|
|
163
|
-
if (allowedModels.length) configs[id].allowedModels = allowedModels;
|
|
164
|
-
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
165
|
-
if (chatPath) configs[id].chatPath = chatPath;
|
|
166
|
-
}
|
|
167
|
-
writeStateImmediate(file, { providerConfigs: configs });
|
|
168
|
-
return clean;
|
|
169
|
-
}
|
|
170
|
-
export function saveProviderConfig(id, { baseUrl, keys, auths, allowedModels, modelsPath, chatPath }, { file = defaultStateFile() } = {}) {
|
|
171
|
-
const cleanUrl = _normalizeBaseUrl(baseUrl);
|
|
172
|
-
const cleanKeys = [...new Set((Array.isArray(keys) ? keys : []).map((k) => String(k || "").trim()).filter(Boolean))];
|
|
173
|
-
const cleanAuths = auths === undefined ? undefined : _normalizeAuths(auths);
|
|
174
|
-
const cleanAllowed = [...new Set((Array.isArray(allowedModels) ? allowedModels : []).map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
175
|
-
const cleanModelsPath = modelsPath === undefined ? undefined : (String(modelsPath).trim() ? _normalizeEndpointPath(modelsPath) : "");
|
|
176
|
-
const cleanChatPath = chatPath === undefined ? undefined : (String(chatPath).trim() ? _normalizeEndpointPath(chatPath) : "");
|
|
177
|
-
const configs = { ...loadProviderConfigs({ file }) };
|
|
178
|
-
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
179
|
-
const finalAllowed = allowedModels === undefined ? (Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : []) : cleanAllowed;
|
|
180
|
-
const finalAuths = cleanAuths === undefined ? _normalizeAuths(cur.auths) : cleanAuths;
|
|
181
|
-
const finalModelsPath = cleanModelsPath === undefined ? (typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "") : cleanModelsPath;
|
|
182
|
-
const finalChatPath = cleanChatPath === undefined ? (typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "") : cleanChatPath;
|
|
183
|
-
if (!cleanUrl && !cleanKeys.length && !finalAllowed.length && !finalAuths.length && !finalModelsPath && !finalChatPath) delete configs[id];
|
|
184
|
-
else {
|
|
185
|
-
configs[id] = { baseUrl: cleanUrl, keys: cleanKeys };
|
|
186
|
-
// 同 saveProviderAllowedModels:起手不带 allowAnyModels 就会静默丢用户的「允许任意」设置(cline token 轮换每走一次这里就丢一次)
|
|
187
|
-
if (typeof cur.allowAnyModels === "boolean") configs[id].allowAnyModels = cur.allowAnyModels;
|
|
188
|
-
if (finalAuths.length) configs[id].auths = finalAuths;
|
|
189
|
-
if (finalAllowed.length) configs[id].allowedModels = finalAllowed;
|
|
190
|
-
if (finalModelsPath) configs[id].modelsPath = finalModelsPath;
|
|
191
|
-
if (finalChatPath) configs[id].chatPath = finalChatPath;
|
|
192
|
-
}
|
|
193
|
-
const oldKeys = readState(file).providerKeys;
|
|
194
|
-
if (oldKeys && typeof oldKeys === "object" && oldKeys[id] !== undefined) {
|
|
195
|
-
const nextKeys = { ...oldKeys };
|
|
196
|
-
delete nextKeys[id];
|
|
197
|
-
writeStateImmediate(file, { providerKeys: nextKeys, providerConfigs: configs });
|
|
198
|
-
return { baseUrl: cleanUrl, keys: cleanKeys, auths: finalAuths, allowedModels: finalAllowed, modelsPath: finalModelsPath, chatPath: finalChatPath };
|
|
199
|
-
}
|
|
200
|
-
writeStateImmediate(file, { providerConfigs: configs });
|
|
201
|
-
return { baseUrl: cleanUrl, keys: cleanKeys, auths: finalAuths, allowedModels: finalAllowed, modelsPath: finalModelsPath, chatPath: finalChatPath };
|
|
202
|
-
}
|
|
1
|
+
import { defaultStateFile, readState, writeStateImmediate } from "../store.js";
|
|
2
|
+
export {
|
|
3
|
+
WORKBUDDY_DEFAULT_BASE_URL,
|
|
4
|
+
normalizeBaseUrl,
|
|
5
|
+
normalizeAuths,
|
|
6
|
+
normalizeAllowedModel,
|
|
7
|
+
normalizeEndpointPath,
|
|
8
|
+
defaultModelsPath,
|
|
9
|
+
defaultChatPath,
|
|
10
|
+
providerKeyEnv,
|
|
11
|
+
providerBaseUrlEnv,
|
|
12
|
+
} from "../provider-config.js";
|
|
13
|
+
import {
|
|
14
|
+
normalizeBaseUrl as _normalizeBaseUrl,
|
|
15
|
+
normalizeAuths as _normalizeAuths,
|
|
16
|
+
normalizeAllowedModel as _normalizeAllowedModel,
|
|
17
|
+
normalizeEndpointPath as _normalizeEndpointPath,
|
|
18
|
+
defaultModelsPath as _defaultModelsPath,
|
|
19
|
+
defaultChatPath as _defaultChatPath,
|
|
20
|
+
providerKeyEnv as _providerKeyEnv,
|
|
21
|
+
providerBaseUrlEnv as _providerBaseUrlEnv,
|
|
22
|
+
WORKBUDDY_DEFAULT_BASE_URL as _WORKBUDDY,
|
|
23
|
+
} from "../provider-config.js";
|
|
24
|
+
|
|
25
|
+
// 薄门面:所有 load/save 仍在此,但归一化逻辑已收至 provider-config 单点
|
|
26
|
+
export function loadProviderModelsPath(id, { file = defaultStateFile() } = {}) {
|
|
27
|
+
const cfg = readState(file).providerConfigs?.[id];
|
|
28
|
+
if (cfg && typeof cfg.modelsPath === "string" && cfg.modelsPath.trim()) return _normalizeEndpointPath(cfg.modelsPath);
|
|
29
|
+
return _defaultModelsPath(id);
|
|
30
|
+
}
|
|
31
|
+
export function loadProviderChatPath(id, { file = defaultStateFile() } = {}) {
|
|
32
|
+
const cfg = readState(file).providerConfigs?.[id];
|
|
33
|
+
if (cfg && typeof cfg.chatPath === "string" && cfg.chatPath.trim()) return _normalizeEndpointPath(cfg.chatPath);
|
|
34
|
+
return _defaultChatPath(id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function loadProviderKeys(id, { file = defaultStateFile() } = {}) {
|
|
38
|
+
const env = (process.env[_providerKeyEnv(id)] || "").trim();
|
|
39
|
+
if (env) return [env];
|
|
40
|
+
const configs = readState(file).providerConfigs;
|
|
41
|
+
const cfg = configs && typeof configs === "object" ? configs[id] : undefined;
|
|
42
|
+
if (cfg && typeof cfg === "object" && Array.isArray(cfg.keys)) {
|
|
43
|
+
const list = [...new Set(cfg.keys.filter((x) => typeof x === "string" && x.trim().length))];
|
|
44
|
+
if (list.length) return list;
|
|
45
|
+
}
|
|
46
|
+
const keys = readState(file).providerKeys;
|
|
47
|
+
const v = keys && typeof keys === "object" ? keys[id] : undefined;
|
|
48
|
+
if (typeof v === "string") return v.trim() ? [v.trim()] : [];
|
|
49
|
+
if (Array.isArray(v)) return [...new Set(v.filter((x) => typeof x === "string" && x.trim().length))];
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
export function loadProviderKey(id, opts = {}) { return loadProviderKeys(id, opts)[0] || ""; }
|
|
53
|
+
// 本节点所有「有 key」的供应商 id(providerConfigs ∪ providerKeys,含 env 覆盖)——
|
|
54
|
+
// 转发时默认借出的候选集合由它枚举;见 src/providers/share-keys.js
|
|
55
|
+
export function listProviderIdsWithKeys({ file = defaultStateFile() } = {}) {
|
|
56
|
+
const st = readState(file);
|
|
57
|
+
const ids = new Set();
|
|
58
|
+
for (const src of [st.providerConfigs, st.providerKeys]) {
|
|
59
|
+
if (src && typeof src === "object" && !Array.isArray(src)) for (const id of Object.keys(src)) ids.add(id);
|
|
60
|
+
}
|
|
61
|
+
return [...ids].filter((id) => loadProviderKeys(id, { file }).length > 0);
|
|
62
|
+
}
|
|
63
|
+
export function saveProviderKeys(id, list, { file = defaultStateFile() } = {}) {
|
|
64
|
+
const keys = { ...(readState(file).providerKeys || {}) };
|
|
65
|
+
const clean = [...new Set((Array.isArray(list) ? list : []).map((k) => String(k || "").trim()).filter(Boolean))];
|
|
66
|
+
if (clean.length) keys[id] = clean; else delete keys[id];
|
|
67
|
+
writeStateImmediate(file, { providerKeys: keys });
|
|
68
|
+
return clean;
|
|
69
|
+
}
|
|
70
|
+
export function saveProviderKey(id, key, opts = {}) {
|
|
71
|
+
const list = [...loadProviderKeys(id, opts)];
|
|
72
|
+
const clean = String(key || "").trim();
|
|
73
|
+
if (clean && !list.includes(clean)) list.push(clean);
|
|
74
|
+
return saveProviderKeys(id, clean ? list : [], opts);
|
|
75
|
+
}
|
|
76
|
+
export function addProviderKey(id, key, opts = {}) { return saveProviderKey(id, key, opts); }
|
|
77
|
+
export function removeProviderKey(id, key, opts = {}) { return removeProviderKeys(id, [key], opts); }
|
|
78
|
+
export function removeProviderKeys(id, targets = [], opts = {}) {
|
|
79
|
+
const set = new Set((Array.isArray(targets) ? targets : [targets]).map((k) => String(k || "").trim()).filter(Boolean));
|
|
80
|
+
const list = loadProviderKeys(id, opts).filter((k) => !set.has(k));
|
|
81
|
+
return saveProviderKeys(id, list, opts);
|
|
82
|
+
}
|
|
83
|
+
export function loadProviderConfigs({ file = defaultStateFile() } = {}) {
|
|
84
|
+
const v = readState(file).providerConfigs;
|
|
85
|
+
if (v && typeof v === "object" && !Array.isArray(v)) return v;
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
export function loadProviderConfig(id, { file = defaultStateFile() } = {}) {
|
|
89
|
+
const envUrl = (process.env[_providerBaseUrlEnv(id)] || "").trim();
|
|
90
|
+
const envKeys = loadProviderKeys(id, { file });
|
|
91
|
+
if (envUrl || (process.env[_providerKeyEnv(id)] || "").trim()) {
|
|
92
|
+
const baseUrl = envUrl || loadProviderConfigs({ file })[id]?.baseUrl || (String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "");
|
|
93
|
+
const cfg = loadProviderConfigs({ file })[id];
|
|
94
|
+
const allowedModels = cfg && Array.isArray(cfg.allowedModels) ? [...new Set(cfg.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
95
|
+
const auths = cfg && Array.isArray(cfg.auths) ? _normalizeAuths(cfg.auths) : [];
|
|
96
|
+
const modelsPath = cfg && typeof cfg.modelsPath === "string" && cfg.modelsPath.trim() ? _normalizeEndpointPath(cfg.modelsPath) : _defaultModelsPath(id);
|
|
97
|
+
const chatPath = cfg && typeof cfg.chatPath === "string" && cfg.chatPath.trim() ? _normalizeEndpointPath(cfg.chatPath) : _defaultChatPath(id);
|
|
98
|
+
if (baseUrl || envKeys.length || allowedModels.length || auths.length) return { baseUrl: _normalizeBaseUrl(baseUrl), keys: envKeys, auths, allowedModels, modelsPath, chatPath };
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const configs = loadProviderConfigs({ file });
|
|
102
|
+
const cfg = configs[id];
|
|
103
|
+
if (cfg && typeof cfg === "object") {
|
|
104
|
+
return {
|
|
105
|
+
baseUrl: _normalizeBaseUrl(cfg.baseUrl || (String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "")),
|
|
106
|
+
keys: Array.isArray(cfg.keys) ? [...new Set(cfg.keys.filter((x) => typeof x === "string" && x.trim().length))] : [],
|
|
107
|
+
auths: _normalizeAuths(cfg.auths),
|
|
108
|
+
allowedModels: Array.isArray(cfg.allowedModels) ? [...new Set(cfg.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [],
|
|
109
|
+
modelsPath: typeof cfg.modelsPath === "string" && cfg.modelsPath.trim() ? _normalizeEndpointPath(cfg.modelsPath) : _defaultModelsPath(id),
|
|
110
|
+
chatPath: typeof cfg.chatPath === "string" && cfg.chatPath.trim() ? _normalizeEndpointPath(cfg.chatPath) : _defaultChatPath(id),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const keys = loadProviderKeys(id, { file });
|
|
114
|
+
if (keys.length) return { baseUrl: String(id).toLowerCase() === "workbuddy" ? _WORKBUDDY : "", keys, auths: [], allowedModels: [], modelsPath: _defaultModelsPath(id), chatPath: _defaultChatPath(id) };
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
export function loadProviderBaseUrl(id, opts = {}) {
|
|
118
|
+
const env = (process.env[_providerBaseUrlEnv(id)] || "").trim();
|
|
119
|
+
if (env) return _normalizeBaseUrl(env);
|
|
120
|
+
const cfg = loadProviderConfigs(opts)[id];
|
|
121
|
+
if (cfg && typeof cfg.baseUrl === "string" && _normalizeBaseUrl(cfg.baseUrl)) return _normalizeBaseUrl(cfg.baseUrl);
|
|
122
|
+
if (String(id || "").toLowerCase() === "workbuddy") return _WORKBUDDY;
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
export function loadProviderAuths(id, { file = defaultStateFile() } = {}) {
|
|
126
|
+
const cfg = loadProviderConfigs({ file })[id];
|
|
127
|
+
if (cfg && Array.isArray(cfg.auths)) return _normalizeAuths(cfg.auths);
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
export function saveProviderAuths(id, list, { file = defaultStateFile() } = {}) {
|
|
131
|
+
const clean = _normalizeAuths(list);
|
|
132
|
+
const configs = { ...loadProviderConfigs({ file }) };
|
|
133
|
+
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
134
|
+
const baseUrl = _normalizeBaseUrl(cur.baseUrl || loadProviderBaseUrl(id, { file }) || "");
|
|
135
|
+
const keys = Array.isArray(cur.keys) ? [...new Set(cur.keys.filter((x) => typeof x === "string" && x.trim().length))] : loadProviderKeys(id, { file });
|
|
136
|
+
const allowedModels = Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
137
|
+
const modelsPath = typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "";
|
|
138
|
+
const chatPath = typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "";
|
|
139
|
+
if (!baseUrl && !keys.length && !clean.length && !allowedModels.length && !modelsPath && !chatPath) delete configs[id];
|
|
140
|
+
else {
|
|
141
|
+
configs[id] = { baseUrl, keys };
|
|
142
|
+
if (clean.length) configs[id].auths = clean;
|
|
143
|
+
if (allowedModels.length) configs[id].allowedModels = allowedModels;
|
|
144
|
+
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
145
|
+
if (chatPath) configs[id].chatPath = chatPath;
|
|
146
|
+
}
|
|
147
|
+
writeStateImmediate(file, { providerConfigs: configs });
|
|
148
|
+
return clean;
|
|
149
|
+
}
|
|
150
|
+
export function saveProviderBaseUrl(id, baseUrl, { file = defaultStateFile() } = {}) {
|
|
151
|
+
const clean = _normalizeBaseUrl(baseUrl);
|
|
152
|
+
const configs = { ...loadProviderConfigs({ file }) };
|
|
153
|
+
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
154
|
+
const keys = Array.isArray(cur.keys) ? cur.keys : loadProviderKeys(id, { file });
|
|
155
|
+
const auths = _normalizeAuths(cur.auths);
|
|
156
|
+
const allowedModels = Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : [];
|
|
157
|
+
const modelsPath = typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "";
|
|
158
|
+
const chatPath = typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "";
|
|
159
|
+
if (!clean && !keys.length && !auths.length && !allowedModels.length && !modelsPath && !chatPath) delete configs[id];
|
|
160
|
+
else {
|
|
161
|
+
configs[id] = { baseUrl: clean, keys };
|
|
162
|
+
if (auths.length) configs[id].auths = auths;
|
|
163
|
+
if (allowedModels.length) configs[id].allowedModels = allowedModels;
|
|
164
|
+
if (modelsPath) configs[id].modelsPath = modelsPath;
|
|
165
|
+
if (chatPath) configs[id].chatPath = chatPath;
|
|
166
|
+
}
|
|
167
|
+
writeStateImmediate(file, { providerConfigs: configs });
|
|
168
|
+
return clean;
|
|
169
|
+
}
|
|
170
|
+
export function saveProviderConfig(id, { baseUrl, keys, auths, allowedModels, modelsPath, chatPath }, { file = defaultStateFile() } = {}) {
|
|
171
|
+
const cleanUrl = _normalizeBaseUrl(baseUrl);
|
|
172
|
+
const cleanKeys = [...new Set((Array.isArray(keys) ? keys : []).map((k) => String(k || "").trim()).filter(Boolean))];
|
|
173
|
+
const cleanAuths = auths === undefined ? undefined : _normalizeAuths(auths);
|
|
174
|
+
const cleanAllowed = [...new Set((Array.isArray(allowedModels) ? allowedModels : []).map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))];
|
|
175
|
+
const cleanModelsPath = modelsPath === undefined ? undefined : (String(modelsPath).trim() ? _normalizeEndpointPath(modelsPath) : "");
|
|
176
|
+
const cleanChatPath = chatPath === undefined ? undefined : (String(chatPath).trim() ? _normalizeEndpointPath(chatPath) : "");
|
|
177
|
+
const configs = { ...loadProviderConfigs({ file }) };
|
|
178
|
+
const cur = configs[id] && typeof configs[id] === "object" ? configs[id] : {};
|
|
179
|
+
const finalAllowed = allowedModels === undefined ? (Array.isArray(cur.allowedModels) ? [...new Set(cur.allowedModels.map((m) => _normalizeAllowedModel(m, id)).filter(Boolean))] : []) : cleanAllowed;
|
|
180
|
+
const finalAuths = cleanAuths === undefined ? _normalizeAuths(cur.auths) : cleanAuths;
|
|
181
|
+
const finalModelsPath = cleanModelsPath === undefined ? (typeof cur.modelsPath === "string" ? _normalizeEndpointPath(cur.modelsPath) : "") : cleanModelsPath;
|
|
182
|
+
const finalChatPath = cleanChatPath === undefined ? (typeof cur.chatPath === "string" ? _normalizeEndpointPath(cur.chatPath) : "") : cleanChatPath;
|
|
183
|
+
if (!cleanUrl && !cleanKeys.length && !finalAllowed.length && !finalAuths.length && !finalModelsPath && !finalChatPath) delete configs[id];
|
|
184
|
+
else {
|
|
185
|
+
configs[id] = { baseUrl: cleanUrl, keys: cleanKeys };
|
|
186
|
+
// 同 saveProviderAllowedModels:起手不带 allowAnyModels 就会静默丢用户的「允许任意」设置(cline token 轮换每走一次这里就丢一次)
|
|
187
|
+
if (typeof cur.allowAnyModels === "boolean") configs[id].allowAnyModels = cur.allowAnyModels;
|
|
188
|
+
if (finalAuths.length) configs[id].auths = finalAuths;
|
|
189
|
+
if (finalAllowed.length) configs[id].allowedModels = finalAllowed;
|
|
190
|
+
if (finalModelsPath) configs[id].modelsPath = finalModelsPath;
|
|
191
|
+
if (finalChatPath) configs[id].chatPath = finalChatPath;
|
|
192
|
+
}
|
|
193
|
+
const oldKeys = readState(file).providerKeys;
|
|
194
|
+
if (oldKeys && typeof oldKeys === "object" && oldKeys[id] !== undefined) {
|
|
195
|
+
const nextKeys = { ...oldKeys };
|
|
196
|
+
delete nextKeys[id];
|
|
197
|
+
writeStateImmediate(file, { providerKeys: nextKeys, providerConfigs: configs });
|
|
198
|
+
return { baseUrl: cleanUrl, keys: cleanKeys, auths: finalAuths, allowedModels: finalAllowed, modelsPath: finalModelsPath, chatPath: finalChatPath };
|
|
199
|
+
}
|
|
200
|
+
writeStateImmediate(file, { providerConfigs: configs });
|
|
201
|
+
return { baseUrl: cleanUrl, keys: cleanKeys, auths: finalAuths, allowedModels: finalAllowed, modelsPath: finalModelsPath, chatPath: finalChatPath };
|
|
202
|
+
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { readState, writeStateImmediate, defaultStateFile } from "../store.js";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_TZ = "Asia/Shanghai";
|
|
4
|
-
const ENV_KEYS = ["MSLXDFF_TZ", "MSLXDFF_TIMEZONE", "TZ"];
|
|
5
|
-
|
|
6
|
-
function isValidTimezone(tz) {
|
|
7
|
-
try {
|
|
8
|
-
new Intl.DateTimeFormat("en-GB", { timeZone: tz });
|
|
9
|
-
return true;
|
|
10
|
-
} catch { return false; }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getTimezoneEnv() {
|
|
14
|
-
for (const k of ENV_KEYS) {
|
|
15
|
-
const v = String(process.env[k] || "").trim();
|
|
16
|
-
if (v && isValidTimezone(v)) return v;
|
|
17
|
-
}
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function loadTimezone({ file } = {}) {
|
|
22
|
-
const env = getTimezoneEnv();
|
|
23
|
-
if (env) return env;
|
|
24
|
-
try {
|
|
25
|
-
const f = file || defaultStateFile();
|
|
26
|
-
const s = readState(f);
|
|
27
|
-
const v = String(s?.timezone || s?.tz || "").trim();
|
|
28
|
-
if (v && isValidTimezone(v)) return v;
|
|
29
|
-
} catch {}
|
|
30
|
-
return DEFAULT_TZ;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function loadTimezoneState({ file } = {}) {
|
|
34
|
-
try {
|
|
35
|
-
const f = file || defaultStateFile();
|
|
36
|
-
const s = readState(f);
|
|
37
|
-
const v = String(s?.timezone || s?.tz || "").trim();
|
|
38
|
-
if (v && isValidTimezone(v)) return v;
|
|
39
|
-
} catch {}
|
|
40
|
-
return DEFAULT_TZ;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function saveTimezone(tz, { file } = {}) {
|
|
44
|
-
const v = String(tz || "").trim();
|
|
45
|
-
if (!v) throw new Error("timezone 不能为空");
|
|
46
|
-
if (!isValidTimezone(v)) throw new Error(`无效时区: ${v}(示例: Asia/Shanghai, UTC, America/New_York)`);
|
|
47
|
-
const f = file || defaultStateFile();
|
|
48
|
-
const patch = { timezone: v };
|
|
49
|
-
// 兼容旧字段 tz
|
|
50
|
-
const cur = readState(f);
|
|
51
|
-
if (cur?.tz !== undefined) patch.tz = undefined;
|
|
52
|
-
return writeStateImmediate(f, patch);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function clearTimezone({ file } = {}) {
|
|
56
|
-
const f = file || defaultStateFile();
|
|
57
|
-
const cur = readState(f);
|
|
58
|
-
const patch = {};
|
|
59
|
-
if (cur?.timezone !== undefined) patch.timezone = undefined;
|
|
60
|
-
if (cur?.tz !== undefined) patch.tz = undefined;
|
|
61
|
-
if (!Object.keys(patch).length) return cur;
|
|
62
|
-
// 通过写 undefined 触发 merge 覆盖?用直接删后写回
|
|
63
|
-
const next = { ...cur };
|
|
64
|
-
delete next.timezone;
|
|
65
|
-
delete next.tz;
|
|
66
|
-
writeStateImmediate(f, next);
|
|
67
|
-
return next;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { DEFAULT_TZ, isValidTimezone };
|
|
1
|
+
import { readState, writeStateImmediate, defaultStateFile } from "../store.js";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_TZ = "Asia/Shanghai";
|
|
4
|
+
const ENV_KEYS = ["MSLXDFF_TZ", "MSLXDFF_TIMEZONE", "TZ"];
|
|
5
|
+
|
|
6
|
+
function isValidTimezone(tz) {
|
|
7
|
+
try {
|
|
8
|
+
new Intl.DateTimeFormat("en-GB", { timeZone: tz });
|
|
9
|
+
return true;
|
|
10
|
+
} catch { return false; }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getTimezoneEnv() {
|
|
14
|
+
for (const k of ENV_KEYS) {
|
|
15
|
+
const v = String(process.env[k] || "").trim();
|
|
16
|
+
if (v && isValidTimezone(v)) return v;
|
|
17
|
+
}
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function loadTimezone({ file } = {}) {
|
|
22
|
+
const env = getTimezoneEnv();
|
|
23
|
+
if (env) return env;
|
|
24
|
+
try {
|
|
25
|
+
const f = file || defaultStateFile();
|
|
26
|
+
const s = readState(f);
|
|
27
|
+
const v = String(s?.timezone || s?.tz || "").trim();
|
|
28
|
+
if (v && isValidTimezone(v)) return v;
|
|
29
|
+
} catch {}
|
|
30
|
+
return DEFAULT_TZ;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function loadTimezoneState({ file } = {}) {
|
|
34
|
+
try {
|
|
35
|
+
const f = file || defaultStateFile();
|
|
36
|
+
const s = readState(f);
|
|
37
|
+
const v = String(s?.timezone || s?.tz || "").trim();
|
|
38
|
+
if (v && isValidTimezone(v)) return v;
|
|
39
|
+
} catch {}
|
|
40
|
+
return DEFAULT_TZ;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function saveTimezone(tz, { file } = {}) {
|
|
44
|
+
const v = String(tz || "").trim();
|
|
45
|
+
if (!v) throw new Error("timezone 不能为空");
|
|
46
|
+
if (!isValidTimezone(v)) throw new Error(`无效时区: ${v}(示例: Asia/Shanghai, UTC, America/New_York)`);
|
|
47
|
+
const f = file || defaultStateFile();
|
|
48
|
+
const patch = { timezone: v };
|
|
49
|
+
// 兼容旧字段 tz
|
|
50
|
+
const cur = readState(f);
|
|
51
|
+
if (cur?.tz !== undefined) patch.tz = undefined;
|
|
52
|
+
return writeStateImmediate(f, patch);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function clearTimezone({ file } = {}) {
|
|
56
|
+
const f = file || defaultStateFile();
|
|
57
|
+
const cur = readState(f);
|
|
58
|
+
const patch = {};
|
|
59
|
+
if (cur?.timezone !== undefined) patch.timezone = undefined;
|
|
60
|
+
if (cur?.tz !== undefined) patch.tz = undefined;
|
|
61
|
+
if (!Object.keys(patch).length) return cur;
|
|
62
|
+
// 通过写 undefined 触发 merge 覆盖?用直接删后写回
|
|
63
|
+
const next = { ...cur };
|
|
64
|
+
delete next.timezone;
|
|
65
|
+
delete next.tz;
|
|
66
|
+
writeStateImmediate(f, next);
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { DEFAULT_TZ, isValidTimezone };
|