dsh-model-think-level 2.4.0 → 2.5.1

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 CHANGED
@@ -20,6 +20,7 @@ DSH 自带的 Models 页只认得它自己目录里的模型。中转站、自
20
20
  - **自定义请求头** — 每个路由可配任意请求头(含 `user-agent`),在 fetch 层按请求重新盖回去;同源冲突、与官方适配器或同类插件的争抢都会被检出。
21
21
  - **请求伪装** — 每个路由可选 Codex / Claude 两种官方 CLI 身份:客户端请求头,以及 Claude 的 Messages 请求体身份段一并补齐;默认关闭,与自定义请求头同一区块。
22
22
  - **生图** — 勾一下「生图」就能把任意模型变成生图模型,对话模型调用原生工具 `generate_image` 出图,支持参考图改图、多图并出、默认参数与超时。
23
+ - **旧话题恢复** — 换过 Azure 资源/中转的上游会拒收旧话题带来的历史项(`item`)。打开后同时识别 `400` 响应体与 `200` 流内 `response.failed` 的这句拒绝,在发送副本的消息上下文里逐级去掉旧资源签发的项(必要时连历史推理一起),再重放这次请求,不删本地历史。
23
24
  - **自动继续** — 会话因为断线、超时、撞上输出上限停住时,替你补一条「继续」,可展开配置等待秒数和最多重试次数。
24
25
  - **余额** — 每个供应商可选配一个只读余额接口,模型页直接显示余额,支持手动刷新。
25
26
 
@@ -101,7 +102,7 @@ dsh plugin add .
101
102
 
102
103
  「请求头」下面是**同一个表单**里的第二个区块:**请求伪装**。默认关闭,按路由保存,可选 **Codex** 或 **Claude**——让该路由的请求以对应厂商官方 CLI 的身份发出,而不是以 SDK 的默认身份。
103
104
 
104
- - 两个区块之间有一条分割线,**取消 / 保存只有一组,放在最下面**:它提交的是整个高级配置(请求头 + 伪装)。伪装是草稿——点选项只是改了表单,按保存才写入;按取消回到已保存的值。
105
+ - 两个区块之间有一条分割线,**取消 / 保存只有一组,放在最下面**:它提交的是整个高级配置(请求头 + 伪装 + 旧话题恢复)。伪装和旧话题恢复都是草稿——点选项只是改了表单,按保存才写入;按取消回到已保存的值。
105
106
 
106
107
  - 存的是插件自己的文件 `<DSH_HOME>/dsh-model-think-level/camouflage.json`,不写进官方供应商档案;换了版本、删了文件就回到关闭。
107
108
  - **Codex**:改 `user-agent` 为 `codex_cli_rs/<版本>`,补 `originator: codex_cli_rs` 和一个稳定的 `x-codex-session-id`;请求体不动。
@@ -192,6 +193,26 @@ dsh plugin add .
192
193
  - 超时或停止会结束插件自己的等待,并向支持取消的依赖传递信号;忽略信号的外部操作或已被上游接受的生图任务不保证撤销,同步解码/文件操作也不能被抢占。热重载只更新后续调用,不替换已经在跑的旧调用。
193
194
  - 从 2.0.3 及更早版本升级:启动时会自动移除旧版「生图 MCP」在 `cordis.patch.yml` 里留下的条目(带 `.bak` 备份),重启后旧的 `dsh-image` MCP 服务不再被拉起。带旧版标记注释的块和没有标记的裸 `- insert:` / `- id: dsh-image-mcp` 条目都能清掉;同一块里还插着别人的插件条目时不动它。
194
195
 
196
+ ## 旧话题恢复
197
+
198
+ 同一个供应商如果换过 Azure 资源、换过中转账号池,旧话题的下一条消息可能直接被拒:
199
+
200
+ ```
201
+ The requested item was created under a different Azure OpenAI resource. Use the same resource that created the item to access it.
202
+ ```
203
+
204
+ 旧话题的历史项带着上一个资源签发的标识和加密推理,新资源不认识它们。这是**历史与上游对不上**,不是密钥失效,也不是模型不存在——换密钥、切协议、把话题清空重来都不对症,而且本地那段历史还在,换个入口发出去照样被拒。
205
+
206
+ 「高级配置」里的第三块**旧话题恢复**就是为这一句拒绝准备的,默认关闭,按路由打开:
207
+
208
+ - **认措辞,不认状态码**:这句拒绝可能以 `400` 出现(正文是 JSON,或中转把 400 当 SSE 流发回来),也可能以 `200` 的流内 `response.failed` 出现——流式 Responses 更常见的正是后者。两种都会识别,因为恢复引擎读的是那句精确措辞,而不是 HTTP 门牌。别的错误一律原样透传。
209
+ - **在原消息上下文上降级,逐级放宽**:第一次原样发送;命中后先只去掉重放历史里绑定旧资源的句柄——推理项 `thinkingSignature` 里的 `id`、文本项 `textSignature` 里的 `id`、工具调用 `id` 里的 `itemId` 半段;仍被拒就再停止重放历史推理(本地可见的思考文本不动)。恢复只发生在流还没把任何内容交给调用方之前;已经开始输出的回合不会被重放。
210
+ - **不动你保存的历史**:只改这一次请求的副本。`call_id`、工具调用与结果的配对、正文、顺序、`previous_response_id` 全部保留;`item_reference`、compaction 这类带密文的项不碰。
211
+ - **不牵连密钥与协议**:恢复在同一个候选密钥、同一个地址、模型和协议内完成;历史类失败不会把密钥记进冷却、不算协议失败、不触发自动继续。修不好时不换密钥——每把密钥都到同一个中转池,换只是把同样的失败多试几遍。
212
+ - **代价很小**:只有匹配到那句拒绝时才多读一次错误体(上限 64 KiB / 2 秒),或按需多跑一至两次降级重放;正常请求一个字节都不多看。
213
+
214
+ 打开后仍报同一句错,说明上游还要别的项一起换(例如 compaction 或 `previous_response_id`),插件不会盲删这些密文——换回原资源,或开一个新话题继续。
215
+
195
216
  ## 自动继续
196
217
 
197
218
  会话偶尔会因为断线、超时、输出达到上限停在半路,需要手动回一句「继续」才能跑完。「高级设置」里的**自动继续**默认关闭:点击名称或箭头展开配置,右侧开关控制是否启用。
@@ -201,6 +222,7 @@ dsh plugin add .
201
222
  - **失败后等待多久、最多重试几次可配置**:默认失败后等待 2 秒、连续最多重试 5 次;等待时间可设为 1–3600 秒,重试次数可设为 1–100 次。输入整数后离开输入框或按 Enter 即保存,折叠、关闭开关和刷新页面都保留设置。每次失败后都先等这么久再发送「继续」,给限流留出冷却时间;上游 `Retry-After` 更长时按上游来(最多计入 2 分钟),不会缩短你设置的更长等待。你手动发送任何消息、或模型正常跑完一个回合,计数清零;等待期间手动发送消息或关闭开关会取消待发送的继续。
202
223
  - **只看当前会话、只认亲眼所见的结束**:页面加载时历史里已有的失败不会被补发;切到别的会话后,原会话的失败也不再追发。发送前会再次确认回合确实已结束、你没有正在排队的新消息。
203
224
  - 自动回复以一条普通用户消息(「继续」/ "Continue")出现在对话里,与手打的没有区别;多个标签页同时开着时,同一次中断只会有一个标签页发送。
225
+ - **输入框下方有本会话的控制器**:会话统计栏最右侧(`◔ 10%` 右边)只在自动继续进行中显示一枚胶囊,形如「第 2/5 次 · 21s」并带「停止」;点开可「立即继续 / 停止 / 设置…」。**会话里的操作只作用于本会话**:「停止」结束这条链并让胶囊消失,你在本会话再发一条消息后才会重新接管、且从第 1/5 次重新计数;自动继续正常跑完也会立刻收起,不留常驻条。全局开关与等待/次数/错误类型仍在设置页。详见 [docs/auto-continue-error-policy](docs/auto-continue-error-policy/README.md)。
204
226
 
205
227
  ## 数据文件
206
228
 
@@ -212,6 +234,10 @@ dsh plugin add .
212
234
  | `key-index.json.history/` | 上面那份元数据的自动快照,最多 64 份 |
213
235
  | `key-serves.json` | 自动探测得到的「哪把密钥能服务哪个模型」,只用于排序与提示 |
214
236
  | `ui-order.json` | 供应商与模型的顺序、启用开关,供多机同步;不含任何秘密 |
237
+ | `camouflage.json` | 每个路由的请求伪装身份;只记开着的那几条 |
238
+ | `topic-recovery.json` | 每个路由是否启用旧话题恢复;只记开着的那几条 |
239
+
240
+ `camouflage.json` 和 `topic-recovery.json` 只有路由名与开关,没有秘密,也已在包的 `dsh.webdavSync.configFiles` 里声明,启用 dsh-webdav 的「已安装插件」后会随插件配置同步。文件名刻意不带 `history`:同步层把 `history` 段当会话历史,带这个词的文件一律不带走。旧版写下的 `history-compat.json` 不会被丢,第一次读取时自动迁移成 `topic-recovery.json`。
215
241
 
216
242
  `ui-order.json` 的同步规则:页面上的实时状态在 localStorage,插件在后台防抖写这个文件,按「最后写入者胜」与本地状态对齐(文件更新就采纳文件,本地更新就回写文件)。采纳文件里的停用集合时会**写回 localStorage**,所以刷新、重开浏览器之后仍是文件那一份,不会出现「这台机器看着同步好了、一刷新又变回去并把它推回文件」。每次改动拿到严格递增的时间戳,重启后同一毫秒内的多次改动也不会互相覆盖;文件比本页新时立即采纳,本页时间戳不更新时**拒绝写入**(服务器回 409 并把赢得的那份带回来),旧标签页不会把别人的新顺序回滚。页面每分钟、以及切回标签页/窗口获得焦点时重新拉取一次,另一台电脑的改动不用重启就能出现。文件里只有供应商路由、模型 id 和停用名单,不含任何密钥,可以放心交给同步盘。
217
243
 
@@ -1,19 +1,19 @@
1
1
  /**
2
2
  * The advanced-configuration pane of one provider card, assembled.
3
3
  *
4
- * The pane is one form over two sections — the request headers, then how the
5
- * route presents itself — and ends in ONE commit row under both. Splitting the
6
- * sections into two components with two commit rows would have made the pane
7
- * read as two forms and put a 保存 between them, which is exactly the shape
8
- * that was wrong: a Save above the disguise looked like a Save for the headers
9
- * alone, and the section below it looked left out of the form.
4
+ * The pane is one form over three sections — the request headers, how the route
5
+ * presents itself, and whether it recovers old Responses topics — and ends in
6
+ * ONE commit row under all three. Splitting the sections into separate
7
+ * components with separate commit rows would have made the pane read as several
8
+ * forms and put a 保存 between them, which is exactly the shape that was wrong:
9
+ * a Save above a section looked like a Save for the headers alone, and the
10
+ * sections below it looked left out of the form.
10
11
  *
11
- * So this component owns what the sections share: the disguise draft lives
12
- * here, the header editor renders it as {@link CamouflageEditor} through its
13
- * `extras` seat, and the editor's own Save commits both ({@link
14
- * useCamouflage}'s `commit` runs after the header write, before the card
15
- * closes). The disguise therefore only reaches the host on Save; picking a
16
- * preset and pressing 取消 leaves nothing behind.
12
+ * So this component owns what the sections share: the disguise and
13
+ * history-compatibility drafts live here, the header editor renders them as
14
+ * {@link CamouflageEditor} and {@link HistoryCompatEditor} through its `extras`
15
+ * seat, and the editor's own Save commits all of them. A switch clicked and
16
+ * then abandoned with 取消 therefore leaves nothing behind.
17
17
  *
18
18
  * @module dsh-model-think-level/client/AdvancedPane
19
19
  */
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The in-session auto-continue controller.
3
+ *
4
+ * A small chip that lives on the composer's stat line — the row that already
5
+ * carries 「5 轮 · 185 步 · 115 tok/s」 and the context meter — and is inserted
6
+ * right of the context pill. It exists ONLY while a continue chain is running:
7
+ *
8
+ * waiting → `第 2/5 次 · 21s`, countdown, 停止 available
9
+ * sent → `已发送「继续」 第 2/5 次`
10
+ * exhausted → `连续 5 次后停手`, 重置 available
11
+ * idle → nothing at all (the chip unmounts, the slot stays empty)
12
+ *
13
+ * Every action is scoped to the CURRENT session: 「停止」 ends this chain and
14
+ * mutes the session until the user posts again; the global switch and the
15
+ * policy live in the settings pane, which 「设置…」 opens.
16
+ *
17
+ * Mounting is a foreign React root appended to the host's stat line. React owns
18
+ * that line, so a re-render removes unknown children; a MutationObserver plus a
19
+ * slow tick put the slot back (idempotent, and throttled so streaming cannot
20
+ * turn into a render storm).
21
+ *
22
+ * @module dsh-model-think-level/client/AutoContinueController
23
+ */
24
+ import type { AutoContinueRunner } from './injection/auto-continue-run.js';
25
+ type Translate = (key: string, params?: Record<string, unknown>) => string;
26
+ /** What {@link mountAutoContinueController} needs. */
27
+ export interface AutoContinueControllerDeps {
28
+ runner: AutoContinueRunner;
29
+ t: Translate;
30
+ /** Open the settings pane (the auto-continue card lives there). */
31
+ onSettings: () => void;
32
+ }
33
+ /**
34
+ * Mount the chip on the composer stat line and keep it there.
35
+ * @returns a disposer that unmounts the root and stops observing.
36
+ */
37
+ export declare function mountAutoContinueController(deps: AutoContinueControllerDeps): () => void;
38
+ export {};
@@ -31,11 +31,19 @@ export declare function ImageGenCard(props: {
31
31
  }): ReactNode;
32
32
  /**
33
33
  * The 「自动继续」 card: one folded settings entry with a quiet summary.
34
- * The expanded card contains only the two compact controls.
34
+ * The expanded card holds the timing controls and the trigger conditions.
35
35
  */
36
36
  export declare function AutoContinueCard(props: {
37
37
  t: (key: string, params?: Record<string, unknown>) => string;
38
38
  }): ReactNode;
39
+ /**
40
+ * The 「失败详情」 card: the switch that decides whether a failed turn grows the
41
+ * 「查看详情」 seat. Default ON — the seat only ever ADDS information, so the
42
+ * off state is the exception, and the folded body says what it adds.
43
+ */
44
+ export declare function ErrorDetailCard(props: {
45
+ t: (key: string, params?: Record<string, unknown>) => string;
46
+ }): ReactNode;
39
47
  /**
40
48
  * The floating pane. Exported for tests: render it inside a chosen container.
41
49
  */
@@ -137,6 +137,19 @@ interface Draft {
137
137
  }
138
138
  /** The headers dict a draft stores: blank names are dropped. */
139
139
  export declare function headersFromDraft(draft: Draft): Record<string, string>;
140
+ /**
141
+ * Whether a save would store exactly what is already stored.
142
+ *
143
+ * The section's save button commits the pane's other sections too, so it fires
144
+ * on saves that never touch these headers. Telling those apart is what lets
145
+ * {@link HeadersEditor} skip a settings write — and the full document rewrite,
146
+ * revision fence and list reload behind it — instead of repeating it to store
147
+ * the same values.
148
+ * @param stored - the headers the route carries now.
149
+ * @param next - the headers the draft would store.
150
+ * @returns true when both hold the same names and the same values.
151
+ */
152
+ export declare function sameHeaders(stored: Record<string, string> | undefined, next: Record<string, string>): boolean;
140
153
  /**
141
154
  * Render the provider card's request-header section.
142
155
  * @param props - route identity, write seam, copy and the card dismiss seam.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The Responses history-compatibility section of a provider's advanced
3
+ * configuration.
4
+ *
5
+ * It is a SECTION of the advanced pane, like the disguise switch: it renders
6
+ * inside the request-header section's container, below the headers table, and
7
+ * shares the pane's single commit row — a switch clicked and then abandoned
8
+ * with 取消 never reaches the host.
9
+ *
10
+ * The switch exists because a relay may answer a continued conversation with
11
+ * `The requested item was created under a different Azure OpenAI resource`
12
+ * whenever its upstream pool moved the topic to another account. Recovery
13
+ * replays the request with the foreign-looking parts of the history removed,
14
+ * which is why it is opt-in per route: it costs extra upstream calls, and only
15
+ * on a refusal that is worth them.
16
+ *
17
+ * @module dsh-model-think-level/client/HistoryCompatEditor
18
+ */
19
+ import { type ReactNode } from 'react';
20
+ /** The switch's copy, as the host slot hands it down. */
21
+ type Copy = (key: string, params?: Record<string, string | number>) => string;
22
+ /** Everything the switch needs to paint: no reads, no writes. */
23
+ export interface HistoryCompatEditorProps {
24
+ /** Localized copy. */
25
+ t: Copy;
26
+ /** The draft the pane currently holds. */
27
+ value: boolean;
28
+ /** Whether this build's request seams are in place. */
29
+ installed: boolean;
30
+ /** Disable the options (the stored value is still being read). */
31
+ disabled?: boolean;
32
+ /** Report a choice; the pane decides when it is written. */
33
+ onChange: (next: boolean) => void;
34
+ }
35
+ /**
36
+ * Render the history-compatibility switch.
37
+ * @param props - draft value, availability and the change sink.
38
+ * @returns the section.
39
+ */
40
+ export declare function HistoryCompatEditor({ t, value, installed, disabled, onChange }: HistoryCompatEditorProps): ReactNode;
41
+ /** The draft one route's pane holds, plus the two seams the pane drives. */
42
+ export interface HistoryCompatDraft {
43
+ /** The value on screen — the draft, not necessarily the stored one. */
44
+ value: boolean;
45
+ /** The value the host currently has, i.e. what 取消 restores. */
46
+ saved: boolean;
47
+ /** Whether this build's request seams are in place. */
48
+ installed: boolean;
49
+ /** Whether the stored value is still being read. */
50
+ loading: boolean;
51
+ /** Replace the draft. Writes nothing. */
52
+ setValue: (next: boolean) => void;
53
+ /** Restore the stored value (the pane's 取消). */
54
+ reset: () => void;
55
+ /** Write the draft, if it differs from the stored value. */
56
+ commit: () => Promise<void>;
57
+ }
58
+ /**
59
+ * Read, hold and commit one route's history-compatibility switch.
60
+ *
61
+ * The stored value is read once per route and seeds the draft; nothing is
62
+ * written until {@link HistoryCompatDraft.commit} runs.
63
+ * @param route - the provider route this pane edits.
64
+ * @returns the draft and its seams.
65
+ */
66
+ export declare function useHistoryCompat(route: string): HistoryCompatDraft;
67
+ export {};
@@ -9,14 +9,17 @@
9
9
  *
10
10
  * @module dsh-model-think-level/client/auto-continue-pref
11
11
  */
12
+ import { type AutoContinuePolicy } from './auto-continue-rules.js';
12
13
  /** localStorage key (own namespace, same convention as the slider pref). */
13
14
  export declare const AUTO_CONTINUE_PREF_KEY = "dsh-model-think-level.auto-continue.enabled";
14
- /** Timing and retry limit, independent of the enable switch. */
15
+ /** Timing, retry limit and interruption policy, independent of the enable switch. */
15
16
  export declare const AUTO_CONTINUE_CONFIG_KEY = "dsh-model-think-level.auto-continue.config";
16
17
  /** Bounded, whole-number settings exposed by the advanced-config card. */
17
18
  export interface AutoContinueConfig {
18
19
  readonly waitSeconds: number;
19
20
  readonly maxRetries: number;
21
+ /** Which interruption classes are answered with 「继续」. */
22
+ readonly policy: AutoContinuePolicy;
20
23
  }
21
24
  export declare const AUTO_CONTINUE_WAIT_MIN = 1;
22
25
  export declare const AUTO_CONTINUE_WAIT_MAX = 3600;
@@ -37,7 +40,7 @@ export declare function setAutoContinueEnabled(next: boolean): void;
37
40
  export declare function setAutoContinueConfig(patch: Partial<AutoContinueConfig>): void;
38
41
  /** Apply a value incoming from another tab (the writer already persisted it). */
39
42
  export declare function syncAutoContinueEnabled(next: boolean): void;
40
- export declare function syncAutoContinueConfig(next: AutoContinueConfig): void;
43
+ export declare function syncAutoContinueConfig(next: Partial<AutoContinueConfig>): void;
41
44
  /** Subscribe to enable changes; returns the disposer. */
42
45
  export declare function subscribeAutoContinueEnabled(listener: () => void): () => void;
43
46
  /** Subscribe to timing/retry-limit changes; returns the disposer. */
@@ -60,6 +60,36 @@ export interface LlmFailureLike {
60
60
  readonly status?: unknown;
61
61
  readonly providerRetryAfterMs?: unknown;
62
62
  }
63
+ /**
64
+ * Failure codes that mean "wait a moment and the same request may succeed":
65
+ * the transient class, mirroring the harness's own retryable set.
66
+ */
67
+ export declare const TRANSIENT_ERROR_CODES: readonly string[];
68
+ /**
69
+ * The other codes the settings card can offer. None of them is retried by
70
+ * default: a fresh 「继续」 re-sends the very request that produced them.
71
+ */
72
+ export declare const OTHER_ERROR_CODES: readonly string[];
73
+ /** Every code the policy can carry, in the settings card's order. */
74
+ export declare const KNOWN_ERROR_CODES: readonly string[];
75
+ /**
76
+ * Which interrupted turns a user wants answered. Stored beside the timing
77
+ * config; fields an old record does not carry fall back to today's
78
+ * behaviour (`max-tokens`, HTTP 408/425/429/5xx, the transient codes), so
79
+ * upgrading never changes what an existing installation retries.
80
+ */
81
+ export interface AutoContinuePolicy {
82
+ /** Continue a turn cut off by the output-token ceiling. */
83
+ readonly maxTokens: boolean;
84
+ /** Continue an `error` whose structured HTTP status is 408/425/429/5xx. */
85
+ readonly httpStatus: boolean;
86
+ /** Per-code decision; only `KNOWN_ERROR_CODES` keys are honoured. */
87
+ readonly codes: Readonly<Record<string, boolean>>;
88
+ }
89
+ /** The behaviour in force when no policy was ever saved. */
90
+ export declare const DEFAULT_AUTO_CONTINUE_POLICY: AutoContinuePolicy;
91
+ /** Validate an untrusted policy record, filling every missing field from the default. */
92
+ export declare function normalizeAutoContinuePolicy(value: unknown): AutoContinuePolicy;
63
93
  /** What the watcher should do with one ended turn. */
64
94
  export type TurnEndClass = {
65
95
  /** Reply 「继续」 automatically. */
@@ -91,6 +121,8 @@ export interface TurnTail {
91
121
  /**
92
122
  * Judge one ended turn.
93
123
  * @param tail - the final `turn/end` plus that turn's events.
124
+ * @param policy - which interruption classes the user wants answered
125
+ * (defaults to the behaviour that shipped before the policy existed).
94
126
  * @returns what the watcher should do.
95
127
  */
96
- export declare function judgeTurnTail(tail: TurnTail): TurnEndClass;
128
+ export declare function judgeTurnTail(tail: TurnTail, policy?: AutoContinuePolicy): TurnEndClass;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The failure-detail preference: whether the chat renders a 「查看详情」 seat on
3
+ * each official failure row. Lives in localStorage beside the other client-side
4
+ * switches (never settings.yaml), and defaults to ON — the whole point of the
5
+ * seat is to stop the client from swallowing the provider's own error.
6
+ *
7
+ * @module dsh-model-think-level/client/error-detail-pref
8
+ */
9
+ /** localStorage key (own namespace, same convention as the slider pref). */
10
+ export declare const ERROR_DETAIL_PREF_KEY = "dsh-model-think-level.error-detail.enabled";
11
+ /** Snapshot the current preference (default ON). */
12
+ export declare function errorDetailEnabled(): boolean;
13
+ /** Save the preference (persisted immediately; a failed write keeps the session value). */
14
+ export declare function setErrorDetailEnabled(next: boolean): void;
15
+ /** Apply a value incoming from another tab (the writer already persisted it). */
16
+ export declare function syncErrorDetailEnabled(next: boolean): void;
17
+ /** Subscribe to enable/disable changes; returns the unsubscribe seam. */
18
+ export declare function subscribeErrorDetailEnabled(listener: () => void): () => void;
@@ -5,11 +5,15 @@
5
5
  * The decision is {@link judgeTurnTail} (auto-continue-rules.ts); this module
6
6
  * owns the OBSERVATION and the GUARDS around it:
7
7
  *
8
- * - Only the CURRENT session is watched, and only LIVE endings: the running
9
- * edge (`running` true → false) must be observed on the attached session
10
- * before anything is evaluated. A page that loads into a session whose
11
- * last turn failed yesterday does nothing — auto-continuing stale
8
+ * - Only the CURRENT session is watched. The one exception is an ending
9
+ * nobody answered: when the watcher first sees a session whose newest
10
+ * turn/end is a continuable failure with no user message or new run after
11
+ * it, that ending is judged once (within a day). A failure the user already
12
+ * moved past, or one older than the window, stays history — replaying old
12
13
  * failures is exactly the mindless behaviour the switch must not have.
14
+ * - A page that loads into a session whose last turn failed yesterday does
15
+ * nothing — auto-continuing stale failures is exactly the mindless
16
+ * behaviour the switch must not have.
13
17
  * - The durable `turn/end` is what is judged, not the running edge, so the
14
18
  * evaluation waits briefly for the settlement to reach the event window.
15
19
  * - Guards at send time: the switch still on, the turn still ended, nothing
@@ -43,6 +47,34 @@ export interface AutoContinueDeps {
43
47
  export interface AutoContinueRunner {
44
48
  /** Stop the poll, detach every listener and cancel every pending send. */
45
49
  dispose: () => void;
50
+ /** What the in-session controller should render right now. */
51
+ status: () => AutoContinueStatus;
52
+ /** Subscribe to status changes; returns the disposer. */
53
+ subscribe: (listener: () => void) => () => void;
54
+ /** Stand down for THIS session: cancel the wait, hide the controller, stay quiet. */
55
+ stop: () => void;
56
+ /** Clear a stood-down chain so the next ending starts again at one. */
57
+ reset: () => void;
58
+ /** Skip the wait and reply now. */
59
+ resumeNow: () => void;
60
+ }
61
+ /**
62
+ * One session's auto-continue chain, as the controller renders it.
63
+ * `idle` is never shown; the chip only exists while a chain is running.
64
+ */
65
+ export interface AutoContinueStatus {
66
+ /** The watched session, undefined while nothing is open. */
67
+ readonly sessionId: string | undefined;
68
+ readonly phase: 'idle' | 'waiting' | 'sent' | 'exhausted';
69
+ /** Automatic replies already sent in THIS chain. */
70
+ readonly consecutive: number;
71
+ readonly maxRetries: number;
72
+ /** Epoch ms the pending reply fires at; 0 when no timer is armed. */
73
+ readonly nextSendAt: number;
74
+ /** The judged interruption, e.g. `RATE_LIMIT` or `max-tokens` (tooltip only). */
75
+ readonly detail: string;
76
+ /** Whether the user stopped this session's chain. */
77
+ readonly muted: boolean;
46
78
  }
47
79
  /**
48
80
  * Build the watcher. The poll runs for the fiber's whole life (memory-only
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The failure-detail seat: re-reads the session's durable events and puts a
3
+ * quiet 「查看详情」 button at the end of each OFFICIAL failure row.
4
+ *
5
+ * Why the seat exists at all: the Chat row for a failed turn is drawn from a
6
+ * projection that deliberately blanks the provider message for `AUTH`
7
+ * (`displayFailure()` in `dsh-client-ui-trajectory` — "safe for Chat"), and the
8
+ * DSH error code is then swapped for a fixed label. The ORIGINAL text is still
9
+ * in the stream this page already holds — `turn/end → data.reason.error.
10
+ * {message, code}` — so nothing here guesses: the popover shows exactly what
11
+ * the provider answered, including the HTTP status and traceId.
12
+ *
13
+ * Two rules keep this neighbouring the official row instead of fighting it:
14
+ * - the button rides the row's message span as a text run (a grid item would
15
+ * be pushed onto a second line by the row's three-column template);
16
+ * - every colour comes from this plugin's `--bre-*` theme vars, so the seat
17
+ * and the popover follow whichever theme the shell is in.
18
+ *
19
+ * @module dsh-model-think-level/client/injection/error-detail
20
+ */
21
+ /** The copy face this module needs (a keyed translator). */
22
+ type Copy = (key: string, params?: Record<string, unknown>) => string;
23
+ /** What this module needs from the plugin context. */
24
+ export interface ErrorDetailContext {
25
+ get?(name: string): unknown;
26
+ }
27
+ /** Dependencies of the seat. */
28
+ export interface ErrorDetailDeps {
29
+ /** The client root context (only `get` is used). */
30
+ ctx: ErrorDetailContext;
31
+ /** The bound translator. */
32
+ t: Copy;
33
+ }
34
+ /** The seat's face. */
35
+ export interface ErrorDetail {
36
+ /** Remove the buttons, the popover and every listener. */
37
+ dispose: () => void;
38
+ }
39
+ /** One failure, reduced to what the popover shows. */
40
+ interface FailureView {
41
+ sessionId: string;
42
+ seq: number;
43
+ /** DSH's own classification (AUTH / QUOTA / RATE_LIMIT / …). */
44
+ code: string;
45
+ /** HTTP status parsed off the provider message, when it carries one. */
46
+ http?: number;
47
+ /** The provider's human message. */
48
+ reason: string;
49
+ /** The provider's machine code (MODEL_ACCESS_DENIED, …). */
50
+ providerCode?: string;
51
+ traceId?: string;
52
+ /** The untouched upstream text. */
53
+ raw: string;
54
+ }
55
+ /**
56
+ * Mask anything key-shaped: this seat shows text the product chose to hide, and
57
+ * the reason it hid it (a provider echoing the credential back) is real.
58
+ * @param text - the upstream message.
59
+ * @returns the message with credential-shaped runs replaced.
60
+ */
61
+ export declare function redact(text: string): string;
62
+ /**
63
+ * Split `403: {"code":…}` into status / payload / readable reason.
64
+ * @param error - the durable `reason.error`.
65
+ * @param sessionId - owning session.
66
+ * @param seq - the `turn/end` sequence.
67
+ * @returns the projected failure.
68
+ */
69
+ export declare function projectFailure(error: {
70
+ message?: unknown;
71
+ code?: unknown;
72
+ }, sessionId: string, seq: number): FailureView;
73
+ /**
74
+ * Build the seat.
75
+ * @param deps - the plugin context and translator.
76
+ * @returns the {@link ErrorDetail} face.
77
+ */
78
+ export declare function createErrorDetail(deps: ErrorDetailDeps): ErrorDetail;
79
+ export {};
@@ -199,6 +199,12 @@ export declare const en: {
199
199
  camouflageSaved: string;
200
200
  camouflageError: string;
201
201
  camouflageUnavailable: string;
202
+ historyCompatTitle: string;
203
+ historyCompatHint: string;
204
+ historyCompatCost: string;
205
+ historyCompatOff: string;
206
+ historyCompatOn: string;
207
+ historyCompatUnavailable: string;
202
208
  headersEmpty: string;
203
209
  headersAdd: string;
204
210
  headersName: string;
@@ -274,6 +280,62 @@ export declare const en: {
274
280
  autoContinueConfigHint: string;
275
281
  autoContinueAria: string;
276
282
  autoContinueMessage: string;
283
+ autoContinueTriggers: string;
284
+ autoContinueRestore: string;
285
+ autoContinueMaxTokens: string;
286
+ autoContinueHttpStatus: string;
287
+ autoContinueErrorTypes: string;
288
+ autoContinueCodesMore: string;
289
+ autoContinueCodesAll: string;
290
+ autoContinueCodesNone: string;
291
+ autoContinueGroupTransient: string;
292
+ autoContinueGroupOther: string;
293
+ autoContinueGroupFlags: string;
294
+ autoContinueWhyMaxTokens: string;
295
+ autoContinueWhyHttpStatus: string;
296
+ autoContinueChipHttp: string;
297
+ autoContinueTagContinue: string;
298
+ autoContinueTagUseless: string;
299
+ autoContinueTagDepends: string;
300
+ autoContinueWhyEMPTY_RESPONSE: string;
301
+ autoContinueWhyRATE_LIMIT: string;
302
+ autoContinueWhySERVER: string;
303
+ autoContinueWhyTIMEOUT: string;
304
+ autoContinueWhyTRANSPORT: string;
305
+ autoContinueWhyPI_AI_ERROR: string;
306
+ autoContinueWhyINVALID_REQUEST: string;
307
+ autoContinueWhyAUTH: string;
308
+ autoContinueWhyLEGACY_CLI_OUTCOME_UNKNOWN: string;
309
+ autoContinueWhyUNSUPPORTED_REASONING_EFFORT: string;
310
+ autoContinueWhyMALFORMED_RESPONSE: string;
311
+ autoContinueWhyUNKNOWN_MODEL: string;
312
+ autoContinueControllerWaiting: string;
313
+ autoContinueControllerSent: string;
314
+ autoContinueControllerExhausted: string;
315
+ autoContinueControllerStop: string;
316
+ autoContinueControllerResume: string;
317
+ autoContinueControllerReset: string;
318
+ autoContinueControllerSettings: string;
319
+ autoContinueControllerAria: string;
320
+ autoContinueControllerDetail: string;
321
+ errorDetailSectionTitle: string;
322
+ errorDetailSummary: string;
323
+ errorDetailHint: string;
324
+ errorDetailAria: string;
325
+ errorDetailButton: string;
326
+ errorDetailTitle: string;
327
+ errorDetailClose: string;
328
+ errorDetailReason: string;
329
+ errorDetailTrace: string;
330
+ errorDetailCode: string;
331
+ errorDetailShown: string;
332
+ errorDetailRaw: string;
333
+ errorDetailCopy: string;
334
+ errorDetailCopied: string;
335
+ errorDetailCopyRaw: string;
336
+ errorDetailSource: string;
337
+ errorDetailUnwrapped: string;
338
+ errorDetailFixedLabel: string;
277
339
  };
278
340
  /** The plugin's locale key union. */
279
341
  export type BreKey = keyof typeof en;