dsh-agent-sdk-bridge 1.1.7 → 1.1.8
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/DEVELOPMENT.md +13 -0
- package/FAQ.md +11 -0
- package/lib/index.js +123 -16
- package/lib/types/adapter.d.ts +21 -2
- package/lib/types/codebuddy.d.ts +1 -1
- package/lib/types/live.d.ts +2 -2
- package/lib/types/minimax.d.ts +7 -0
- package/lib/types/model-cache.d.ts +27 -0
- package/lib/types/models.d.ts +10 -0
- package/package.json +1 -1
- package/src/adapter.ts +63 -8
- package/src/codebuddy-adapter.ts +9 -4
- package/src/codebuddy.ts +2 -2
- package/src/config.ts +1 -1
- package/src/live.ts +2 -2
- package/src/minimax-adapter.ts +5 -2
- package/src/minimax.ts +10 -0
- package/src/model-cache.ts +39 -0
- package/src/models.ts +14 -0
package/DEVELOPMENT.md
CHANGED
|
@@ -45,6 +45,19 @@
|
|
|
45
45
|
仍会丢弃任何非宿主前缀的 tool_use,防止模型臆造工具名。CodeBuddy 会把 MCP server 名里的
|
|
46
46
|
非字母数字字符规范成 `_`(`dsh-host` → `mcp__dsh_host__<tool>`),Qoder CLI 保留连字符,
|
|
47
47
|
因此 `isHostTool()` / `hostToolName()` 同时接受两种拼写。
|
|
48
|
+
- **切换模型读缓存**:`resolveModel` 与 `capture()` 走 `cachedModels()`
|
|
49
|
+
(`src/model-cache.ts`):有快照就先返回快照,刷新在后台跑;只有从未读到过目录时才等待。
|
|
50
|
+
三家的目录获取都很贵(Qoder 冷启动 CLI,最长等于 fetch 超时;CodeBuddy 要启进程;MiniMax
|
|
51
|
+
走 ACP 探测),而宿主在每次切模型、切思考档位时都会重新解析一次,所以以前 TTL 一过期就会
|
|
52
|
+
卡住菜单。三家 catalog 都新增了 `snapshot()`(只读内存,不发网络)供这里使用。
|
|
53
|
+
同步探测(`regionBlocked`、额度)不受影响,它们仍走各自的正常读取。
|
|
54
|
+
- **默认思考档位取最强的一档**:`reasoningInfo()` 的第二个参数是**用户配置**的档位,不再是上游
|
|
55
|
+
声明的 `defaultEffort`;留空时由 `strongestEffort()` 按 `none < minimal < low < medium <
|
|
56
|
+
high < xhigh < max` 取该模型支持的最强档(三家词表不同:Qoder `low|medium|high|max`、
|
|
57
|
+
MiniMax `low|high`、CodeBuddy 由目录声明)。宿主在请求未带档位时会应用我们声明的
|
|
58
|
+
`defaultEffort`(`requested ?? reasoning.defaultEffort`),所以这里选什么,实际就跑什么;
|
|
59
|
+
上游自己的默认值会偏低(CodeBuddy 的 `high` 在可选 `max` 时就不再直接采用)。配置的档位若
|
|
60
|
+
模型不支持,会退回最强档,而不是把这一轮判成 `UNSUPPORTED_REASONING_EFFORT`。
|
|
48
61
|
- **CodeBuddy 模型选择按区域**:`codebuddyGlobalDisabledModels` /
|
|
49
62
|
`codebuddyCnDisabledModels` 与 `codebuddyGlobalModelContextWindows` /
|
|
50
63
|
`codebuddyCnModelContextWindows` 是四个独立字段,`CodeBuddyAdapter` 按 region 读取,
|
package/FAQ.md
CHANGED
|
@@ -101,6 +101,17 @@ SQLite 依赖就在这些脚本里,普通 `npm i -g` 装出来的 `mcode` 一
|
|
|
101
101
|
时使用该区域自己的登录态;要换站请先在原站点点「退出登录」。两个区域的模型开关与上下文窗口
|
|
102
102
|
仍然分别保存,切回已登录的区域会直接恢复选择。
|
|
103
103
|
|
|
104
|
+
**切模型时默认选哪一档思考强度?** 选该模型支持的最强档(有 `max` 就选 `max`,否则取它声明的
|
|
105
|
+
最高档;只有 `low` / `high` 的模型取 `high`)。以前沿用上游自己的默认值,而它常常偏低:
|
|
106
|
+
CodeBuddy 的 `GLM-5.3` 在可选 `max` 时仍声明默认 `high`。在高级设置里填了
|
|
107
|
+
`defaultReasoningEffort` 时以它为准;该档位模型不支持时退回最强档。
|
|
108
|
+
|
|
109
|
+
**切换模型或思考档位时会卡一下?** 宿主每次切换都会重新解析一次模型元数据(档位、上下文窗口、
|
|
110
|
+
读图能力),而这三个 provider 的模型目录都要拉起各自的 CLI 或 ACP 进程才能读到。以前这次解析会
|
|
111
|
+
等待目录刷新,缓存一过期就要等一次完整读取(Qoder 冷启动最久)。现在解析先用上一次成功读到的
|
|
112
|
+
目录立刻返回,刷新在后台进行;只有从未读到过目录的第一次解析才会等待。目录自身的 TTL 与失败
|
|
113
|
+
回退规则不变。
|
|
114
|
+
|
|
104
115
|
**切到 MiniMax 国际站后提示「本机 IP 不在服务区域」?** 这不是登录过期,而是网络位置被拒。
|
|
105
116
|
MiniMax 的边缘节点在收到跨区请求时会返回 `307`,把 `.io` 重定向到 `.minimaxi.com`(反向亦然)。
|
|
106
117
|
两个域名是不同 origin,浏览器/Node 跟随重定向时 `Authorization` 头会被丢弃,于是账号接口变成空的
|
package/lib/index.js
CHANGED
|
@@ -264,8 +264,8 @@ function readLive(value, fallback) {
|
|
|
264
264
|
* Resolve one {@link Live} option that may legitimately be undefined.
|
|
265
265
|
*
|
|
266
266
|
* Separate from {@link readLive} because an option whose "unset" state is
|
|
267
|
-
* itself meaningful (`defaultReasoningEffort`: empty means "
|
|
268
|
-
* has no fallback to apply.
|
|
267
|
+
* itself meaningful (`defaultReasoningEffort`: empty means "use the model's
|
|
268
|
+
* strongest level") has no fallback to apply.
|
|
269
269
|
*
|
|
270
270
|
* @param value - the plain value or thunk, possibly undefined.
|
|
271
271
|
* @returns the option's current value, or undefined when it is unset.
|
|
@@ -668,6 +668,19 @@ var QoderModelCatalog = class {
|
|
|
668
668
|
return officialOnly((this.cached ?? sharedSnapshots.get(this.brand))?.models ?? []);
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
|
+
/**
|
|
672
|
+
* The last successful live list, without fetching.
|
|
673
|
+
*
|
|
674
|
+
* The model picker resolves a route on every switch, and a switch must not
|
|
675
|
+
* wait on a CLI cold start (up to the fetch timeout). Callers that need an
|
|
676
|
+
* immediate answer read this and let {@link liveModels} refresh behind them;
|
|
677
|
+
* `undefined` means nothing has been read yet, which only the first switch
|
|
678
|
+
* has to wait for.
|
|
679
|
+
*/
|
|
680
|
+
snapshot() {
|
|
681
|
+
const cached = this.cached ?? sharedSnapshots.get(this.brand);
|
|
682
|
+
return cached === void 0 ? void 0 : officialOnly(cached.models);
|
|
683
|
+
}
|
|
671
684
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
672
685
|
get error() {
|
|
673
686
|
return this.failure;
|
|
@@ -765,6 +778,41 @@ function withTimeout$2(promise, ms) {
|
|
|
765
778
|
});
|
|
766
779
|
}
|
|
767
780
|
//#endregion
|
|
781
|
+
//#region src/model-cache.ts
|
|
782
|
+
/**
|
|
783
|
+
* Cache-first catalogue reads for the model picker.
|
|
784
|
+
*
|
|
785
|
+
* The harness resolves a route every time the user switches model or reasoning
|
|
786
|
+
* level, and each of the three providers answers that resolution from a
|
|
787
|
+
* catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
|
|
788
|
+
* fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
|
|
789
|
+
* that fetch inside a resolution made the picker freeze for seconds whenever
|
|
790
|
+
* the cache had just expired.
|
|
791
|
+
*
|
|
792
|
+
* So a resolution reads the last successful snapshot when there is one and lets
|
|
793
|
+
* the catalogue refresh behind it; only the very first resolution, where there
|
|
794
|
+
* is nothing to show, waits. A snapshot that is merely stale still describes
|
|
795
|
+
* the same account's models, so answering from it is no less correct than the
|
|
796
|
+
* previous behaviour of answering from a failed fetch's fallback.
|
|
797
|
+
*
|
|
798
|
+
* @module dsh-agent-sdk-bridge/model-cache
|
|
799
|
+
*/
|
|
800
|
+
/**
|
|
801
|
+
* The cached list when one exists, otherwise the awaited fetch.
|
|
802
|
+
*
|
|
803
|
+
* @param snapshot - last successful catalogue, or undefined before the first.
|
|
804
|
+
* @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
|
|
805
|
+
* @returns the entries to resolve against, never empty-by-surprise when a
|
|
806
|
+
* snapshot exists.
|
|
807
|
+
*/
|
|
808
|
+
async function cachedModels(snapshot, fetch) {
|
|
809
|
+
if (snapshot !== void 0 && snapshot.length > 0) {
|
|
810
|
+
fetch().catch(() => void 0);
|
|
811
|
+
return snapshot;
|
|
812
|
+
}
|
|
813
|
+
return fetch();
|
|
814
|
+
}
|
|
815
|
+
//#endregion
|
|
768
816
|
//#region src/tokens.ts
|
|
769
817
|
/**
|
|
770
818
|
* Script-aware text pricing, shared by the input and output estimators.
|
|
@@ -2869,22 +2917,72 @@ const EFFORT_NAMES = {
|
|
|
2869
2917
|
max: "Max"
|
|
2870
2918
|
};
|
|
2871
2919
|
/**
|
|
2920
|
+
* Strength order used to pick a model's starting level.
|
|
2921
|
+
*
|
|
2922
|
+
* The three providers spell their levels differently (Qoder publishes
|
|
2923
|
+
* `low|medium|high|max`, MiniMax `low|high`, CodeBuddy whatever its catalog
|
|
2924
|
+
* declares), so the ranking is by name rather than by position in any one
|
|
2925
|
+
* upstream list. An id outside this table ranks below every known one, which is
|
|
2926
|
+
* what several sources agreeing on an unfamiliar spelling should do.
|
|
2927
|
+
*/
|
|
2928
|
+
const EFFORT_ORDER = [
|
|
2929
|
+
"none",
|
|
2930
|
+
"minimal",
|
|
2931
|
+
"low",
|
|
2932
|
+
"medium",
|
|
2933
|
+
"high",
|
|
2934
|
+
"xhigh",
|
|
2935
|
+
"max"
|
|
2936
|
+
];
|
|
2937
|
+
/**
|
|
2938
|
+
* The strongest level a model offers.
|
|
2939
|
+
*
|
|
2940
|
+
* Switching model or level must start at the most capable setting the route
|
|
2941
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
2942
|
+
* behaviour of following upstream's own default meant some models silently
|
|
2943
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
2944
|
+
* even when `max` is selectable).
|
|
2945
|
+
*
|
|
2946
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
2947
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
2948
|
+
*/
|
|
2949
|
+
function strongestEffort(efforts) {
|
|
2950
|
+
if (efforts.length === 0) return void 0;
|
|
2951
|
+
let best;
|
|
2952
|
+
let bestRank = -1;
|
|
2953
|
+
for (const effort of efforts) {
|
|
2954
|
+
const rank = EFFORT_ORDER.indexOf(effort);
|
|
2955
|
+
if (best === void 0 || rank > bestRank) {
|
|
2956
|
+
best = effort;
|
|
2957
|
+
bestRank = rank;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
return best;
|
|
2961
|
+
}
|
|
2962
|
+
/**
|
|
2872
2963
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
2873
2964
|
* when the model does not support reasoning.
|
|
2965
|
+
*
|
|
2966
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
2967
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
2968
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
2969
|
+
* when the model accepts it.
|
|
2970
|
+
*
|
|
2874
2971
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
2875
|
-
* @param
|
|
2972
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
2876
2973
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
2877
2974
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
2878
2975
|
*/
|
|
2879
|
-
function reasoningInfo(efforts,
|
|
2976
|
+
function reasoningInfo(efforts, configuredEffort, isReasoning) {
|
|
2880
2977
|
if (efforts === void 0 && isReasoning === false) return void 0;
|
|
2881
2978
|
const ids = efforts !== void 0 && efforts.length > 0 ? efforts : DEFAULT_REASONING_EFFORTS;
|
|
2979
|
+
const defaultEffort = configuredEffort !== void 0 && ids.includes(configuredEffort) ? configuredEffort : strongestEffort(ids);
|
|
2882
2980
|
return {
|
|
2883
2981
|
efforts: ids.map((id) => ({
|
|
2884
2982
|
id: ReasoningEffortId(id),
|
|
2885
2983
|
name: EFFORT_NAMES[id] ?? id
|
|
2886
2984
|
})),
|
|
2887
|
-
...defaultEffort
|
|
2985
|
+
...defaultEffort === void 0 ? {} : { defaultEffort: ReasoningEffortId(defaultEffort) }
|
|
2888
2986
|
};
|
|
2889
2987
|
}
|
|
2890
2988
|
/**
|
|
@@ -3078,11 +3176,11 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
3078
3176
|
}
|
|
3079
3177
|
async resolveModel(provider, model, _signal) {
|
|
3080
3178
|
const target = resolveQoderModelId(model, this.modelAliases);
|
|
3081
|
-
const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
|
|
3179
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
|
|
3082
3180
|
if (live !== void 0) {
|
|
3083
3181
|
const vision = live.isVl === true;
|
|
3084
3182
|
this.knownVision.set(target, vision);
|
|
3085
|
-
const reasoning = reasoningInfo(live.efforts,
|
|
3183
|
+
const reasoning = reasoningInfo(live.efforts, this.defaultReasoningEffort, live.isReasoning);
|
|
3086
3184
|
return {
|
|
3087
3185
|
provider,
|
|
3088
3186
|
id: model,
|
|
@@ -3132,7 +3230,7 @@ var QoderAdapter = class extends LlmAdapter {
|
|
|
3132
3230
|
async capture(provider, model, signal) {
|
|
3133
3231
|
const info = await this.resolveModel(provider, model, signal);
|
|
3134
3232
|
const target = resolveQoderModelId(model, this.modelAliases);
|
|
3135
|
-
const live = (await this.catalog.liveModels()).find((entry) => entry.value === target);
|
|
3233
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels())).find((entry) => entry.value === target);
|
|
3136
3234
|
const declared = info.context?.contextWindow;
|
|
3137
3235
|
return {
|
|
3138
3236
|
info,
|
|
@@ -3660,7 +3758,7 @@ var CodeBuddyCatalog = class {
|
|
|
3660
3758
|
* context-budget choice) use this instead of awaiting a refresh.
|
|
3661
3759
|
*/
|
|
3662
3760
|
snapshot(requested) {
|
|
3663
|
-
return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models
|
|
3761
|
+
return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models;
|
|
3664
3762
|
}
|
|
3665
3763
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
3666
3764
|
async models(requested) {
|
|
@@ -4998,7 +5096,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
4998
5096
|
async modelVision(model) {
|
|
4999
5097
|
const target = resolveCodeBuddyModelId(model, this.aliases);
|
|
5000
5098
|
const key = `${this.region}:${target}`;
|
|
5001
|
-
const live = (await this.catalog.
|
|
5099
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
|
|
5002
5100
|
if (live !== void 0) {
|
|
5003
5101
|
this.knownVision.set(key, live.vision);
|
|
5004
5102
|
return live.vision;
|
|
@@ -5085,7 +5183,7 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
5085
5183
|
}
|
|
5086
5184
|
/** The catalog snapshot the adapter last read (empty before the first read). */
|
|
5087
5185
|
models(region) {
|
|
5088
|
-
return this.catalog.snapshot(region);
|
|
5186
|
+
return this.catalog.snapshot(region) ?? [];
|
|
5089
5187
|
}
|
|
5090
5188
|
/** Whether this model lets the user pick a context budget at all. */
|
|
5091
5189
|
supportsContextWindowChoice(id, region = this.region) {
|
|
@@ -5102,10 +5200,10 @@ var CodeBuddyAdapter = class extends LlmAdapter {
|
|
|
5102
5200
|
async resolveModel(provider, model) {
|
|
5103
5201
|
const target = resolveCodeBuddyModelId(model, this.aliases);
|
|
5104
5202
|
const key = `${this.region}:${target}`;
|
|
5105
|
-
const live = (await this.catalog.models()).find((entry) => entry.id === target);
|
|
5203
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models())).find((entry) => entry.id === target);
|
|
5106
5204
|
if (live !== void 0) {
|
|
5107
5205
|
this.knownVision.set(key, live.vision);
|
|
5108
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
5206
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), (live.reasoningEfforts?.length ?? 0) > 0);
|
|
5109
5207
|
return {
|
|
5110
5208
|
provider,
|
|
5111
5209
|
id: model,
|
|
@@ -6646,6 +6744,15 @@ var MinimaxCatalog = class {
|
|
|
6646
6744
|
return cached?.models ?? [];
|
|
6647
6745
|
}
|
|
6648
6746
|
}
|
|
6747
|
+
/**
|
|
6748
|
+
* The last successful list for a region, without probing.
|
|
6749
|
+
*
|
|
6750
|
+
* The picker resolves a route on every switch; awaiting an ACP probe there
|
|
6751
|
+
* cost a process round-trip whenever the TTL had just expired.
|
|
6752
|
+
*/
|
|
6753
|
+
snapshot(requested) {
|
|
6754
|
+
return this.snapshots.get(requested ?? readLive(this.region, "cn"))?.models;
|
|
6755
|
+
}
|
|
6649
6756
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
6650
6757
|
error(requested) {
|
|
6651
6758
|
return this.failures.get(requested ?? readLive(this.region, "cn"));
|
|
@@ -7828,10 +7935,10 @@ var MinimaxAdapter = class extends LlmAdapter {
|
|
|
7828
7935
|
const region = this.region;
|
|
7829
7936
|
const target = resolveMinimaxModelId(model, this.aliases);
|
|
7830
7937
|
const key = `${region}:${target}`;
|
|
7831
|
-
const live = (await this.catalog.models(region)).find((entry) => entry.id === target);
|
|
7938
|
+
const live = (await cachedModels(this.catalog.snapshot(region), () => this.catalog.models(region))).find((entry) => entry.id === target);
|
|
7832
7939
|
if (live !== void 0) {
|
|
7833
7940
|
this.knownVision.set(key, live.vision);
|
|
7834
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
7941
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), live.reasoning);
|
|
7835
7942
|
return {
|
|
7836
7943
|
provider,
|
|
7837
7944
|
id: model,
|
|
@@ -8575,7 +8682,7 @@ const Config$1 = z$1.object({
|
|
|
8575
8682
|
maxSessions: z$1.number().step(1).min(1).max(64).default(8).description("同时保持的内层会话数上限,超出后按最久未使用关闭。每个会话是一个子进程。").volatile(),
|
|
8576
8683
|
modelCacheTtlSeconds: z$1.number().step(1).min(10).max(86400).default(300).description("模型列表缓存时长(秒)。调小可更快看到账号侧变化。").volatile(),
|
|
8577
8684
|
modelAliases: z$1.dict(z$1.string()).default({}).description("额外的模型别名映射:DSH 侧名称 → Qoder 模型 ID。内置 deepseek-v4-* 别名仍然生效。").volatile(),
|
|
8578
|
-
defaultReasoningEffort: z$1.string().default("").description("
|
|
8685
|
+
defaultReasoningEffort: z$1.string().default("").description("默认选用的思考档位;留空则用该模型支持的最强档位。").volatile(),
|
|
8579
8686
|
defaultMaxTokens: z$1.number().step(1).min(1).default(32e3).description("模型未声明输出上限时使用的输出上限。").volatile(),
|
|
8580
8687
|
toolResultTimeoutSeconds: z$1.number().step(1).min(5).max(3600).default(120).description("仅用于未配对 handler 的兜底时限(秒):正常工具调用会等宿主下一次请求携带结果,不按此超时。").volatile(),
|
|
8581
8688
|
catalogFetchTimeoutSeconds: z$1.number().step(1).min(1).max(300).default(20).description("拉取模型列表的时限(秒),超时后回退到内置列表。").volatile(),
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -131,15 +131,34 @@ export declare function cliContextWindow(live: WindowFacts | undefined, declared
|
|
|
131
131
|
* looked like 10%.
|
|
132
132
|
*/
|
|
133
133
|
export declare function resolveDeclaredWindow(live: WindowFacts | undefined, override: number | undefined, remembered: number | undefined, fallback: number): number;
|
|
134
|
+
/**
|
|
135
|
+
* The strongest level a model offers.
|
|
136
|
+
*
|
|
137
|
+
* Switching model or level must start at the most capable setting the route
|
|
138
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
139
|
+
* behaviour of following upstream's own default meant some models silently
|
|
140
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
141
|
+
* even when `max` is selectable).
|
|
142
|
+
*
|
|
143
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
144
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
145
|
+
*/
|
|
146
|
+
export declare function strongestEffort(efforts: readonly string[]): string | undefined;
|
|
134
147
|
/**
|
|
135
148
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
136
149
|
* when the model does not support reasoning.
|
|
150
|
+
*
|
|
151
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
152
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
153
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
154
|
+
* when the model accepts it.
|
|
155
|
+
*
|
|
137
156
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
138
|
-
* @param
|
|
157
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
139
158
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
140
159
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
141
160
|
*/
|
|
142
|
-
export declare function reasoningInfo(efforts: readonly string[] | undefined,
|
|
161
|
+
export declare function reasoningInfo(efforts: readonly string[] | undefined, configuredEffort: string | undefined, isReasoning: boolean | undefined): LlmModelReasoningInfo | undefined;
|
|
143
162
|
/**
|
|
144
163
|
* The Qoder-backed adapter. Session continuity, tool parking, and feed
|
|
145
164
|
* planning live here; chunk synthesis lives in the session's consumer.
|
package/lib/types/codebuddy.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ export declare class CodeBuddyCatalog {
|
|
|
126
126
|
* Callers that must answer synchronously (deciding whether a model exposes a
|
|
127
127
|
* context-budget choice) use this instead of awaiting a refresh.
|
|
128
128
|
*/
|
|
129
|
-
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[];
|
|
129
|
+
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[] | undefined;
|
|
130
130
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
131
131
|
models(requested?: CodeBuddyRegion): Promise<readonly CodeBuddyModel[]>;
|
|
132
132
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
package/lib/types/live.d.ts
CHANGED
|
@@ -41,8 +41,8 @@ export declare function readLive<T>(value: Live<T> | undefined, fallback: T): T;
|
|
|
41
41
|
* Resolve one {@link Live} option that may legitimately be undefined.
|
|
42
42
|
*
|
|
43
43
|
* Separate from {@link readLive} because an option whose "unset" state is
|
|
44
|
-
* itself meaningful (`defaultReasoningEffort`: empty means "
|
|
45
|
-
* has no fallback to apply.
|
|
44
|
+
* itself meaningful (`defaultReasoningEffort`: empty means "use the model's
|
|
45
|
+
* strongest level") has no fallback to apply.
|
|
46
46
|
*
|
|
47
47
|
* @param value - the plain value or thunk, possibly undefined.
|
|
48
48
|
* @returns the option's current value, or undefined when it is unset.
|
package/lib/types/minimax.d.ts
CHANGED
|
@@ -345,6 +345,13 @@ export declare class MinimaxCatalog {
|
|
|
345
345
|
constructor(region: Live<MinimaxRegion>, ttlMs?: Live<number>, timeoutMs?: Live<number>);
|
|
346
346
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
347
347
|
models(requested?: MinimaxRegion): Promise<readonly MinimaxModel[]>;
|
|
348
|
+
/**
|
|
349
|
+
* The last successful list for a region, without probing.
|
|
350
|
+
*
|
|
351
|
+
* The picker resolves a route on every switch; awaiting an ACP probe there
|
|
352
|
+
* cost a process round-trip whenever the TTL had just expired.
|
|
353
|
+
*/
|
|
354
|
+
snapshot(requested?: MinimaxRegion): readonly MinimaxModel[] | undefined;
|
|
348
355
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
349
356
|
error(requested?: MinimaxRegion): string | undefined;
|
|
350
357
|
invalidate(region?: MinimaxRegion): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache-first catalogue reads for the model picker.
|
|
3
|
+
*
|
|
4
|
+
* The harness resolves a route every time the user switches model or reasoning
|
|
5
|
+
* level, and each of the three providers answers that resolution from a
|
|
6
|
+
* catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
|
|
7
|
+
* fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
|
|
8
|
+
* that fetch inside a resolution made the picker freeze for seconds whenever
|
|
9
|
+
* the cache had just expired.
|
|
10
|
+
*
|
|
11
|
+
* So a resolution reads the last successful snapshot when there is one and lets
|
|
12
|
+
* the catalogue refresh behind it; only the very first resolution, where there
|
|
13
|
+
* is nothing to show, waits. A snapshot that is merely stale still describes
|
|
14
|
+
* the same account's models, so answering from it is no less correct than the
|
|
15
|
+
* previous behaviour of answering from a failed fetch's fallback.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-agent-sdk-bridge/model-cache
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The cached list when one exists, otherwise the awaited fetch.
|
|
21
|
+
*
|
|
22
|
+
* @param snapshot - last successful catalogue, or undefined before the first.
|
|
23
|
+
* @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
|
|
24
|
+
* @returns the entries to resolve against, never empty-by-surprise when a
|
|
25
|
+
* snapshot exists.
|
|
26
|
+
*/
|
|
27
|
+
export declare function cachedModels<T>(snapshot: readonly T[] | undefined, fetch: () => Promise<readonly T[]>): Promise<readonly T[]>;
|
package/lib/types/models.d.ts
CHANGED
|
@@ -43,6 +43,16 @@ export declare class QoderModelCatalog {
|
|
|
43
43
|
* settings page cannot disagree about what the account has.
|
|
44
44
|
*/
|
|
45
45
|
liveModels(): Promise<readonly ModelInfo[]>;
|
|
46
|
+
/**
|
|
47
|
+
* The last successful live list, without fetching.
|
|
48
|
+
*
|
|
49
|
+
* The model picker resolves a route on every switch, and a switch must not
|
|
50
|
+
* wait on a CLI cold start (up to the fetch timeout). Callers that need an
|
|
51
|
+
* immediate answer read this and let {@link liveModels} refresh behind them;
|
|
52
|
+
* `undefined` means nothing has been read yet, which only the first switch
|
|
53
|
+
* has to wait for.
|
|
54
|
+
*/
|
|
55
|
+
snapshot(): readonly ModelInfo[] | undefined;
|
|
46
56
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
47
57
|
get error(): string | undefined;
|
|
48
58
|
/**
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-agent-sdk-bridge",
|
|
3
3
|
"displayName": "Agent SDK Bridge",
|
|
4
4
|
"description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.8",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "k1-h2",
|
package/src/adapter.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { ResolvedConfig } from './config.ts'
|
|
|
23
23
|
import type { Live } from './live.ts'
|
|
24
24
|
import { readLive, readLiveOptional } from './live.ts'
|
|
25
25
|
import { DEFAULT_MODEL_CACHE_TTL_MS, DEFAULT_FETCH_TIMEOUT_MS, QoderModelCatalog } from './models.ts'
|
|
26
|
+
import { cachedModels } from './model-cache.ts'
|
|
26
27
|
import { feedImageRefs, feedToText, imageRefText, imageRefs, joinFeeds, renderInitialFeed, renderRefreshed, renderUserTurn } from './render.ts'
|
|
27
28
|
import type { Feed, ImagePathResolver } from './render.ts'
|
|
28
29
|
import { QoderSession, QoderSessionManager, DEFAULT_MAX_SESSIONS } from './session.ts'
|
|
@@ -216,31 +217,77 @@ const EFFORT_NAMES: Readonly<Record<string, string>> = {
|
|
|
216
217
|
max: 'Max',
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Strength order used to pick a model's starting level.
|
|
222
|
+
*
|
|
223
|
+
* The three providers spell their levels differently (Qoder publishes
|
|
224
|
+
* `low|medium|high|max`, MiniMax `low|high`, CodeBuddy whatever its catalog
|
|
225
|
+
* declares), so the ranking is by name rather than by position in any one
|
|
226
|
+
* upstream list. An id outside this table ranks below every known one, which is
|
|
227
|
+
* what several sources agreeing on an unfamiliar spelling should do.
|
|
228
|
+
*/
|
|
229
|
+
const EFFORT_ORDER: readonly string[] = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The strongest level a model offers.
|
|
233
|
+
*
|
|
234
|
+
* Switching model or level must start at the most capable setting the route
|
|
235
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
236
|
+
* behaviour of following upstream's own default meant some models silently
|
|
237
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
238
|
+
* even when `max` is selectable).
|
|
239
|
+
*
|
|
240
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
241
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
242
|
+
*/
|
|
243
|
+
export function strongestEffort(efforts: readonly string[]): string | undefined {
|
|
244
|
+
if (efforts.length === 0) return undefined
|
|
245
|
+
let best: string | undefined
|
|
246
|
+
let bestRank = -1
|
|
247
|
+
for (const effort of efforts) {
|
|
248
|
+
// First occurrence wins a tie, which keeps an upstream-ordered list stable
|
|
249
|
+
// when it repeats a level.
|
|
250
|
+
const rank = EFFORT_ORDER.indexOf(effort)
|
|
251
|
+
if (best === undefined || rank > bestRank) {
|
|
252
|
+
best = effort
|
|
253
|
+
bestRank = rank
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return best
|
|
257
|
+
}
|
|
258
|
+
|
|
219
259
|
/**
|
|
220
260
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
221
261
|
* when the model does not support reasoning.
|
|
262
|
+
*
|
|
263
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
264
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
265
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
266
|
+
* when the model accepts it.
|
|
267
|
+
*
|
|
222
268
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
223
|
-
* @param
|
|
269
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
224
270
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
225
271
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
226
272
|
*/
|
|
227
273
|
export function reasoningInfo(
|
|
228
274
|
efforts: readonly string[] | undefined,
|
|
229
|
-
|
|
275
|
+
configuredEffort: string | undefined,
|
|
230
276
|
isReasoning: boolean | undefined,
|
|
231
277
|
): LlmModelReasoningInfo | undefined {
|
|
232
278
|
if (efforts === undefined && isReasoning === false) return undefined
|
|
233
279
|
const ids = efforts !== undefined && efforts.length > 0
|
|
234
280
|
? efforts
|
|
235
281
|
: DEFAULT_REASONING_EFFORTS
|
|
282
|
+
const defaultEffort = configuredEffort !== undefined && ids.includes(configuredEffort)
|
|
283
|
+
? configuredEffort
|
|
284
|
+
: strongestEffort(ids)
|
|
236
285
|
return {
|
|
237
286
|
efforts: ids.map(id => ({
|
|
238
287
|
id: ReasoningEffortId(id),
|
|
239
288
|
name: EFFORT_NAMES[id] ?? id,
|
|
240
289
|
})),
|
|
241
|
-
...defaultEffort
|
|
242
|
-
? { defaultEffort: ReasoningEffortId(defaultEffort) }
|
|
243
|
-
: {},
|
|
290
|
+
...defaultEffort === undefined ? {} : { defaultEffort: ReasoningEffortId(defaultEffort) },
|
|
244
291
|
}
|
|
245
292
|
}
|
|
246
293
|
|
|
@@ -492,11 +539,16 @@ export class QoderAdapter extends LlmAdapter {
|
|
|
492
539
|
// address to find the metadata, but echo the requested id back: the seam
|
|
493
540
|
// rejects an exact-model result whose id differs from the one asked for.
|
|
494
541
|
const target = resolveQoderModelId(model, this.modelAliases)
|
|
495
|
-
|
|
542
|
+
// The picker resolves on every switch and every level change. Awaiting the
|
|
543
|
+
// CLI catalogue here (a cold start, up to the fetch timeout) froze the menu
|
|
544
|
+
// whenever the cache had just expired, so a snapshot answers immediately and
|
|
545
|
+
// the refresh runs behind it.
|
|
546
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels()))
|
|
547
|
+
.find(entry => entry.value === target)
|
|
496
548
|
if (live !== undefined) {
|
|
497
549
|
const vision = live.isVl === true
|
|
498
550
|
this.knownVision.set(target, vision)
|
|
499
|
-
const reasoning = reasoningInfo(live.efforts,
|
|
551
|
+
const reasoning = reasoningInfo(live.efforts, this.defaultReasoningEffort, live.isReasoning)
|
|
500
552
|
return {
|
|
501
553
|
provider,
|
|
502
554
|
id: model,
|
|
@@ -566,7 +618,10 @@ export class QoderAdapter extends LlmAdapter {
|
|
|
566
618
|
private async capture(provider: string, model: string, signal?: AbortSignal): Promise<CallGeneration> {
|
|
567
619
|
const info = await this.resolveModel(provider, model, signal)
|
|
568
620
|
const target = resolveQoderModelId(model, this.modelAliases)
|
|
569
|
-
|
|
621
|
+
// Same cache-first rule as the resolution above: a dispatch may not stall
|
|
622
|
+
// on a catalogue fetch to learn window facts a snapshot already carries.
|
|
623
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels()))
|
|
624
|
+
.find(entry => entry.value === target)
|
|
570
625
|
const declared = info.context?.contextWindow
|
|
571
626
|
return {
|
|
572
627
|
info,
|
package/src/codebuddy-adapter.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { CodeBuddyRegion } from './brand.ts'
|
|
|
18
18
|
import { codeBuddyColdStream, CodeBuddyAccountReader, CodeBuddyAuth, CodeBuddyCatalog, CodeBuddySessionManager, CODEBUDDY_DEFAULT_CONTEXT_WINDOW, CODEBUDDY_DEFAULT_MAX_TOKENS, CODEBUDDY_CACHE_TTL_MS, CODEBUDDY_FETCH_TIMEOUT_MS } from './codebuddy.ts'
|
|
19
19
|
import type { CodeBuddyModel, CodeBuddyUsageSnapshot } from './codebuddy.ts'
|
|
20
20
|
import { reasoningInfo, planContinuation } from './adapter.ts'
|
|
21
|
+
import { cachedModels } from './model-cache.ts'
|
|
21
22
|
import type { ImageRequestReader } from './adapter.ts'
|
|
22
23
|
import type { Live } from './live.ts'
|
|
23
24
|
import { readLive, readLiveOptional } from './live.ts'
|
|
@@ -199,7 +200,8 @@ export class CodeBuddyAdapter extends LlmAdapter {
|
|
|
199
200
|
private async modelVision(model: string): Promise<boolean> {
|
|
200
201
|
const target = resolveCodeBuddyModelId(model, this.aliases)
|
|
201
202
|
const key = `${this.region}:${target}`
|
|
202
|
-
const live = (await this.catalog.
|
|
203
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models()))
|
|
204
|
+
.find(entry => entry.id === target)
|
|
203
205
|
if (live !== undefined) {
|
|
204
206
|
this.knownVision.set(key, live.vision)
|
|
205
207
|
return live.vision
|
|
@@ -301,7 +303,7 @@ export class CodeBuddyAdapter extends LlmAdapter {
|
|
|
301
303
|
|
|
302
304
|
/** The catalog snapshot the adapter last read (empty before the first read). */
|
|
303
305
|
private models(region: CodeBuddyRegion): readonly CodeBuddyModel[] {
|
|
304
|
-
return this.catalog.snapshot(region)
|
|
306
|
+
return this.catalog.snapshot(region) ?? []
|
|
305
307
|
}
|
|
306
308
|
|
|
307
309
|
/** Whether this model lets the user pick a context budget at all. */
|
|
@@ -321,10 +323,13 @@ export class CodeBuddyAdapter extends LlmAdapter {
|
|
|
321
323
|
override async resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo> {
|
|
322
324
|
const target = resolveCodeBuddyModelId(model, this.aliases)
|
|
323
325
|
const key = `${this.region}:${target}`
|
|
324
|
-
|
|
326
|
+
// Cache first: a model switch must not wait on a catalogue fetch (which
|
|
327
|
+
// boots a CodeBuddy process) just because the TTL has expired.
|
|
328
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.models()))
|
|
329
|
+
.find(entry => entry.id === target)
|
|
325
330
|
if (live !== undefined) {
|
|
326
331
|
this.knownVision.set(key, live.vision)
|
|
327
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
332
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), (live.reasoningEfforts?.length ?? 0) > 0)
|
|
328
333
|
return {
|
|
329
334
|
provider,
|
|
330
335
|
id: model,
|
package/src/codebuddy.ts
CHANGED
|
@@ -352,8 +352,8 @@ export class CodeBuddyCatalog {
|
|
|
352
352
|
* Callers that must answer synchronously (deciding whether a model exposes a
|
|
353
353
|
* context-budget choice) use this instead of awaiting a refresh.
|
|
354
354
|
*/
|
|
355
|
-
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[] {
|
|
356
|
-
return this.snapshots.get(requested ?? readLive(this.region, 'global'))?.models
|
|
355
|
+
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[] | undefined {
|
|
356
|
+
return this.snapshots.get(requested ?? readLive(this.region, 'global'))?.models
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
/** Models for one region; a failed refresh keeps the last good list. */
|
package/src/config.ts
CHANGED
|
@@ -247,7 +247,7 @@ export const Config = z.object({
|
|
|
247
247
|
maxSessions: z.number().step(1).min(1).max(64).default(8).description('同时保持的内层会话数上限,超出后按最久未使用关闭。每个会话是一个子进程。').volatile(),
|
|
248
248
|
modelCacheTtlSeconds: z.number().step(1).min(10).max(86_400).default(300).description('模型列表缓存时长(秒)。调小可更快看到账号侧变化。').volatile(),
|
|
249
249
|
modelAliases: z.dict(z.string()).default({}).description('额外的模型别名映射:DSH 侧名称 → Qoder 模型 ID。内置 deepseek-v4-* 别名仍然生效。').volatile(),
|
|
250
|
-
defaultReasoningEffort: z.string().default('').description('
|
|
250
|
+
defaultReasoningEffort: z.string().default('').description('默认选用的思考档位;留空则用该模型支持的最强档位。').volatile(),
|
|
251
251
|
defaultMaxTokens: z.number().step(1).min(1).default(32_000).description('模型未声明输出上限时使用的输出上限。').volatile(),
|
|
252
252
|
toolResultTimeoutSeconds: z.number().step(1).min(5).max(3_600).default(120).description('仅用于未配对 handler 的兜底时限(秒):正常工具调用会等宿主下一次请求携带结果,不按此超时。').volatile(),
|
|
253
253
|
catalogFetchTimeoutSeconds: z.number().step(1).min(1).max(300).default(20).description('拉取模型列表的时限(秒),超时后回退到内置列表。').volatile(),
|
package/src/live.ts
CHANGED
|
@@ -47,8 +47,8 @@ export function readLive<T>(value: Live<T> | undefined, fallback: T): T {
|
|
|
47
47
|
* Resolve one {@link Live} option that may legitimately be undefined.
|
|
48
48
|
*
|
|
49
49
|
* Separate from {@link readLive} because an option whose "unset" state is
|
|
50
|
-
* itself meaningful (`defaultReasoningEffort`: empty means "
|
|
51
|
-
* has no fallback to apply.
|
|
50
|
+
* itself meaningful (`defaultReasoningEffort`: empty means "use the model's
|
|
51
|
+
* strongest level") has no fallback to apply.
|
|
52
52
|
*
|
|
53
53
|
* @param value - the plain value or thunk, possibly undefined.
|
|
54
54
|
* @returns the option's current value, or undefined when it is unset.
|
package/src/minimax-adapter.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import type { MinimaxModel, MinimaxPromptBlock, MinimaxUsageSnapshot } from './minimax.ts'
|
|
26
26
|
import { resolveMinimaxCli } from './minimax-cli.ts'
|
|
27
27
|
import { reasoningInfo, planContinuation } from './adapter.ts'
|
|
28
|
+
import { cachedModels } from './model-cache.ts'
|
|
28
29
|
import type { ImageRequestReader } from './adapter.ts'
|
|
29
30
|
import type { Live } from './live.ts'
|
|
30
31
|
import { readLive, readLiveOptional } from './live.ts'
|
|
@@ -255,10 +256,12 @@ export class MinimaxAdapter extends LlmAdapter {
|
|
|
255
256
|
const region = this.region
|
|
256
257
|
const target = resolveMinimaxModelId(model, this.aliases)
|
|
257
258
|
const key = `${region}:${target}`
|
|
258
|
-
|
|
259
|
+
// Cache first: resolving a route may not wait on an ACP probe.
|
|
260
|
+
const live = (await cachedModels(this.catalog.snapshot(region), () => this.catalog.models(region)))
|
|
261
|
+
.find(entry => entry.id === target)
|
|
259
262
|
if (live !== undefined) {
|
|
260
263
|
this.knownVision.set(key, live.vision)
|
|
261
|
-
const reasoning = reasoningInfo(live.reasoningEfforts,
|
|
264
|
+
const reasoning = reasoningInfo(live.reasoningEfforts, readLiveOptional(this.options.defaultReasoningEffort), live.reasoning)
|
|
262
265
|
return {
|
|
263
266
|
provider,
|
|
264
267
|
id: model,
|
package/src/minimax.ts
CHANGED
|
@@ -1527,6 +1527,16 @@ export class MinimaxCatalog {
|
|
|
1527
1527
|
}
|
|
1528
1528
|
}
|
|
1529
1529
|
|
|
1530
|
+
/**
|
|
1531
|
+
* The last successful list for a region, without probing.
|
|
1532
|
+
*
|
|
1533
|
+
* The picker resolves a route on every switch; awaiting an ACP probe there
|
|
1534
|
+
* cost a process round-trip whenever the TTL had just expired.
|
|
1535
|
+
*/
|
|
1536
|
+
snapshot(requested?: MinimaxRegion): readonly MinimaxModel[] | undefined {
|
|
1537
|
+
return this.snapshots.get(requested ?? readLive(this.region, 'cn'))?.models
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1530
1540
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
1531
1541
|
error(requested?: MinimaxRegion): string | undefined {
|
|
1532
1542
|
return this.failures.get(requested ?? readLive(this.region, 'cn'))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache-first catalogue reads for the model picker.
|
|
3
|
+
*
|
|
4
|
+
* The harness resolves a route every time the user switches model or reasoning
|
|
5
|
+
* level, and each of the three providers answers that resolution from a
|
|
6
|
+
* catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
|
|
7
|
+
* fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
|
|
8
|
+
* that fetch inside a resolution made the picker freeze for seconds whenever
|
|
9
|
+
* the cache had just expired.
|
|
10
|
+
*
|
|
11
|
+
* So a resolution reads the last successful snapshot when there is one and lets
|
|
12
|
+
* the catalogue refresh behind it; only the very first resolution, where there
|
|
13
|
+
* is nothing to show, waits. A snapshot that is merely stale still describes
|
|
14
|
+
* the same account's models, so answering from it is no less correct than the
|
|
15
|
+
* previous behaviour of answering from a failed fetch's fallback.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-agent-sdk-bridge/model-cache
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The cached list when one exists, otherwise the awaited fetch.
|
|
22
|
+
*
|
|
23
|
+
* @param snapshot - last successful catalogue, or undefined before the first.
|
|
24
|
+
* @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
|
|
25
|
+
* @returns the entries to resolve against, never empty-by-surprise when a
|
|
26
|
+
* snapshot exists.
|
|
27
|
+
*/
|
|
28
|
+
export async function cachedModels<T>(
|
|
29
|
+
snapshot: readonly T[] | undefined,
|
|
30
|
+
fetch: () => Promise<readonly T[]>,
|
|
31
|
+
): Promise<readonly T[]> {
|
|
32
|
+
if (snapshot !== undefined && snapshot.length > 0) {
|
|
33
|
+
// Kick the refresh but do not wait for it: the caller needs an answer now,
|
|
34
|
+
// and a failure here changes nothing because the snapshot stays published.
|
|
35
|
+
void fetch().catch(() => undefined)
|
|
36
|
+
return snapshot
|
|
37
|
+
}
|
|
38
|
+
return fetch()
|
|
39
|
+
}
|
package/src/models.ts
CHANGED
|
@@ -101,6 +101,20 @@ export class QoderModelCatalog {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* The last successful live list, without fetching.
|
|
106
|
+
*
|
|
107
|
+
* The model picker resolves a route on every switch, and a switch must not
|
|
108
|
+
* wait on a CLI cold start (up to the fetch timeout). Callers that need an
|
|
109
|
+
* immediate answer read this and let {@link liveModels} refresh behind them;
|
|
110
|
+
* `undefined` means nothing has been read yet, which only the first switch
|
|
111
|
+
* has to wait for.
|
|
112
|
+
*/
|
|
113
|
+
snapshot(): readonly ModelInfo[] | undefined {
|
|
114
|
+
const cached = this.cached ?? sharedSnapshots.get(this.brand)
|
|
115
|
+
return cached === undefined ? undefined : officialOnly(cached.models)
|
|
116
|
+
}
|
|
117
|
+
|
|
104
118
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
105
119
|
get error(): string | undefined {
|
|
106
120
|
return this.failure
|