dsh-opendesign-corouter 0.1.10 → 0.1.11
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 +4 -4
- package/lib/client.js +4 -4
- package/lib/device-auth.d.ts +1 -1
- package/lib/empty-turn.d.ts +11 -6
- package/lib/eot-code.d.ts +2 -0
- package/lib/eot-recovery.d.ts +33 -0
- package/lib/index.js +134 -21
- package/lib/index.js.map +4 -4
- package/lib/protocols/errors.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ dsh plugin --profile web add dsh-opendesign-corouter
|
|
|
32
32
|
也可打开 [Actions → CI](https://github.com/KouzakiUmi/dsh-opendesign-corouter/actions/workflows/ci.yml),从成功构建下载 **`dsh-opendesign-corouter-build`** artifact。登录 GitHub 后解压 ZIP,取得 `.tgz` 与 `.sha256`,再安装本地包:
|
|
33
33
|
|
|
34
34
|
```console
|
|
35
|
-
dsh plugin --profile web add /absolute/path/to/dsh-opendesign-corouter-0.1.
|
|
35
|
+
dsh plugin --profile web add /absolute/path/to/dsh-opendesign-corouter-0.1.11.tgz
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
`web` 只是示例,请替换为目标 Profile。Desktop 使用桌面安装器提供的 `dsh` 入口;独立公共 CLI 不能代管保留的 `desktop` Profile。安装后的启用与重载按目标 DSH 的管理流程进行。
|
|
@@ -81,11 +81,11 @@ dsh plugin --profile web add /absolute/path/to/dsh-opendesign-corouter-0.1.10.tg
|
|
|
81
81
|
<img src="docs/previews/theme-light.png" width="1040" alt="连接与登录页,展示桌面优先开关、独立登录按钮和不回填的 API Key 输入框;模拟数据">
|
|
82
82
|
</picture>
|
|
83
83
|
|
|
84
|
-
### DeepSeek V4.1 Flash
|
|
84
|
+
### DeepSeek V4.1 Flash 异常结束检测
|
|
85
85
|
|
|
86
|
-
独立开关,默认开启。参考 [dsh-empty-turn-guard](https://github.com/FYTXY/dsh-empty-turn-guard)
|
|
86
|
+
独立开关,默认开启。参考 [dsh-empty-turn-guard](https://github.com/FYTXY/dsh-empty-turn-guard),在工具对话中将“stop 且没有工具调用、回答为空或只剩协议残渣”以及短操作前言、简短进度后说明下一步但没有工具调用的情况标成异常 EOT。文字识别属于启发式判断,可能漏检或误判。
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
检测到异常 EOT 后,在同一 Agent 步骤内持续重试,直到成功或取消,**没有次数上限,重复请求可能额外消耗额度**。其他错误仍遵循 DSH 的原有重试策略。附加监控仅用于 DeepSeek V4.1 Flash 的工具对话;未收到流终态且工具调用尚未开始时,按可重试的传输中断处理。
|
|
89
89
|
|
|
90
90
|
## 使用前先知道
|
|
91
91
|
|
package/lib/client.js
CHANGED
|
@@ -21224,13 +21224,13 @@ function Advanced({ status, formSnapshot, setFormField, pendingField }) {
|
|
|
21224
21224
|
h(
|
|
21225
21225
|
"section",
|
|
21226
21226
|
{ className: "odc-card" },
|
|
21227
|
-
h("h3", null, "\
|
|
21228
|
-
h("p", { className: "odc-hint" }, "\u68C0\u6D4B DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\u4E2D\u7684\u7A7A\u56DE\u7B54\
|
|
21227
|
+
h("h3", null, "\u5F02\u5E38\u7ED3\u675F\u76D1\u63A7"),
|
|
21228
|
+
h("p", { className: "odc-hint" }, "\u68C0\u6D4B DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\u4E2D\u7684\u7A7A\u56DE\u7B54\u3001\u534F\u8BAE\u6807\u8BB0\u6B8B\u7559\u6216\u8BF4\u660E\u4E0B\u4E00\u6B65\u540E\u672A\u6267\u884C\u7684\u63D0\u524D\u7ED3\u675F\u3002\u6587\u5B57\u8BC6\u522B\u53EF\u80FD\u8BEF\u5224\u3002"),
|
|
21229
21229
|
h("div", { style: { marginTop: 14 } }, h(Switch, {
|
|
21230
21230
|
checked: formSnapshot.value?.emptyTurnGuard ?? status?.config.emptyTurnGuard ?? true,
|
|
21231
21231
|
disabled: !writable || pendingField.includes("emptyTurnGuard"),
|
|
21232
|
-
label: "\u542F\u7528\
|
|
21233
|
-
hint: `\u5DF2\u68C0\u6D4B\u5230 ${status?.guardedTurns ?? "\u2014"} \u6B21\
|
|
21232
|
+
label: "\u542F\u7528\u5F02\u5E38\u7ED3\u675F\u76D1\u63A7",
|
|
21233
|
+
hint: `\u5DF2\u68C0\u6D4B\u5230 ${status?.guardedTurns ?? "\u2014"} \u6B21\u5F02\u5E38\u56DE\u7B54\u3002\u547D\u4E2D\u540E\u6301\u7EED\u91CD\u8BD5\uFF0C\u76F4\u5230\u6210\u529F\u6216\u53D6\u6D88\uFF1B\u53EF\u80FD\u989D\u5916\u6D88\u8017\u989D\u5EA6\u3002`,
|
|
21234
21234
|
onChange: (checked) => {
|
|
21235
21235
|
void setFormField("emptyTurnGuard", checked);
|
|
21236
21236
|
}
|
package/lib/device-auth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface DeviceTokens {
|
|
|
3
3
|
runtimeKey: string;
|
|
4
4
|
}
|
|
5
5
|
export declare const DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
|
|
6
|
-
export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.
|
|
6
|
+
export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.11";
|
|
7
7
|
export declare const DEVICE_REQUEST_TIMEOUT_MS = 20000;
|
|
8
8
|
/** One bounded launch step of the temporary activation window. */
|
|
9
9
|
export declare const DEVICE_OPEN_TIMEOUT_MS = 30000;
|
package/lib/empty-turn.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FinishReason, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
2
2
|
/** Failure message a rewritten empty turn carries. */
|
|
3
|
-
export declare const EMPTY_TURN_MESSAGE = "OpenDesign\uFF1A\u6A21\u578B\
|
|
3
|
+
export declare const EMPTY_TURN_MESSAGE = "OpenDesign\uFF1A\u6A21\u578B\u672A\u4EA7\u751F\u53EF\u7528\u56DE\u7B54\u6216\u6709\u6548\u5DE5\u5177\u8C03\u7528";
|
|
4
|
+
export declare const INCOMPLETE_TURN_MESSAGE = "OpenDesign\uFF1A\u6A21\u578B\u505C\u5728\u64CD\u4F5C\u8BF4\u660E\uFF0C\u672A\u7EE7\u7EED\u53D1\u8D77\u5DE5\u5177\u8C03\u7528";
|
|
4
5
|
/**
|
|
5
6
|
* Remove protocol residue from one assembled channel.
|
|
6
7
|
* @param text - concatenated text or reasoning content.
|
|
@@ -13,6 +14,8 @@ export declare function stripProtocolResidue(text: string): string;
|
|
|
13
14
|
* @returns true for absent, blank, or residue-only content.
|
|
14
15
|
*/
|
|
15
16
|
export declare function isResidueOnly(text: string | undefined): boolean;
|
|
17
|
+
/** Recognize a short action promise, optionally after a concise progress update. */
|
|
18
|
+
export declare function isPendingActionTurn(text: string | undefined): boolean;
|
|
16
19
|
/** Stream facts one attempt produced, as the adapter accumulated them. */
|
|
17
20
|
export interface EmptyTurnInput {
|
|
18
21
|
/** Whether any tool-call block was opened or streamed during this attempt. */
|
|
@@ -29,6 +32,8 @@ export interface EmptyTurnEvidence {
|
|
|
29
32
|
readonly reasoningLength: number;
|
|
30
33
|
/** True when the visible text channel is empty once protocol residue is removed. */
|
|
31
34
|
readonly markupOnly: boolean;
|
|
35
|
+
/** True for a narrowly recognized pending-action statement. */
|
|
36
|
+
readonly pendingAction: boolean;
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
39
|
* Whether this finish is the empty turn the guard exists for.
|
|
@@ -47,8 +52,8 @@ export interface EmptyTurnOptions {
|
|
|
47
52
|
/**
|
|
48
53
|
* Monitor switch, read per request by the caller. `false` makes every
|
|
49
54
|
* {@link EmptyTurnTracker.resolve} a no-op, which is how a paid route keeps its untouched
|
|
50
|
-
* behaviour. It never suppresses the
|
|
51
|
-
*
|
|
55
|
+
* behaviour. It never suppresses the protocol reader's own `count === 0` → `EMPTY_RESPONSE`
|
|
56
|
+
* path, which stays in force either way.
|
|
52
57
|
*/
|
|
53
58
|
readonly enabled?: boolean;
|
|
54
59
|
/**
|
|
@@ -85,11 +90,11 @@ export declare class EmptyTurnTracker {
|
|
|
85
90
|
*/
|
|
86
91
|
inspect(): EmptyTurnEvidence;
|
|
87
92
|
/**
|
|
88
|
-
|
|
93
|
+
* Rewrite an eligible finish into the scoped EOT failure.
|
|
89
94
|
*
|
|
90
95
|
* The reason object is returned unchanged (same reference) whenever the monitor is off, the
|
|
91
|
-
* finish is not `stop`, a tool call was observed, or the visible text
|
|
92
|
-
* This method only decides and rewrites
|
|
96
|
+
* finish is not `stop`, a tool call was observed, or the visible text is a substantive answer.
|
|
97
|
+
* This method only decides and rewrites; scoped recovery runs at the host's request-error boundary.
|
|
93
98
|
* @param reason - the finish reason the adapter is about to yield.
|
|
94
99
|
* @returns a retryable `error` reason, or the given reason untouched.
|
|
95
100
|
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { LlmFailure } from '@deepseek-ai/dsh-llm';
|
|
3
|
+
type RecoveryAction = {
|
|
4
|
+
kind: 'retry';
|
|
5
|
+
} | undefined;
|
|
6
|
+
interface RetrySession {
|
|
7
|
+
append(type: 'llm/retry' | 'llm/retry-started', data: Record<string, unknown>): unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface RecoveryPayload {
|
|
10
|
+
agent: {
|
|
11
|
+
session: RetrySession;
|
|
12
|
+
};
|
|
13
|
+
turn: number;
|
|
14
|
+
step: number;
|
|
15
|
+
provider: string;
|
|
16
|
+
failure: LlmFailure;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
type RecoveryNext = () => Promise<RecoveryAction>;
|
|
20
|
+
type RecoveryListener = (payload: RecoveryPayload, next: RecoveryNext) => Promise<RecoveryAction>;
|
|
21
|
+
declare function cancellableDelay(delay: number, signal: AbortSignal): Promise<boolean>;
|
|
22
|
+
/** Own only the plugin-specific EOT failure; other errors continue down the host waterfall. */
|
|
23
|
+
export declare class EotRecovery {
|
|
24
|
+
#private;
|
|
25
|
+
readonly enabled: () => boolean;
|
|
26
|
+
readonly wait: typeof cancellableDelay;
|
|
27
|
+
constructor(enabled: () => boolean, wait?: typeof cancellableDelay);
|
|
28
|
+
readonly handle: RecoveryListener;
|
|
29
|
+
dispose(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Register against the host's documented scoped recovery waterfall. */
|
|
32
|
+
export declare function installEotRecovery(ctx: Context, enabled: () => boolean): void;
|
|
33
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,7 @@ var __privateSet = (obj, member2, value, setter) => (__accessCheck(obj, member2,
|
|
|
48
48
|
var __privateMethod = (obj, member2, method) => (__accessCheck(obj, member2, "access private method"), method);
|
|
49
49
|
|
|
50
50
|
// src/index.ts
|
|
51
|
-
import { randomUUID as
|
|
51
|
+
import { randomUUID as randomUUID3, createHash } from "node:crypto";
|
|
52
52
|
import { credentialKey, credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
53
53
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
54
54
|
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
@@ -327,7 +327,7 @@ var Config = Schema.object({
|
|
|
327
327
|
apiProtocol: Schema.union(API_PROTOCOL_IDS).default("chat-completions").description("\u7F51\u5173\u652F\u6301\u7684\u63A8\u7406\u534F\u8BAE\uFF1B\u6A21\u578B\u76EE\u5F55\u901A\u8FC7\u8BE5\u7F51\u5173\u7684\u517C\u5BB9\u63A5\u53E3\u8BFB\u53D6").volatile(),
|
|
328
328
|
modelSettings: Schema.transform(Schema.dict(Schema.any()), serializableTransform(parseModelSettingsMap)).default({}).description("\u9010\u6A21\u578B\u542F\u7528\u72B6\u6001\u548C\u8BF7\u6C42\u53C2\u6570").volatile(),
|
|
329
329
|
useDesktopCredential: Schema.boolean().default(true).description("\u4F18\u5148\u8BFB\u53D6 OpenDesign \u684C\u9762\u7AEF\u767B\u5F55\u6001\u67E5\u8BE2\u989D\u5EA6").volatile(),
|
|
330
|
-
emptyTurnGuard: Schema.boolean().default(true).description("\u68C0\u6D4B DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\u7684\u7A7A\u56DE\u7B54\uFF1B\
|
|
330
|
+
emptyTurnGuard: Schema.boolean().default(true).description("\u68C0\u6D4B DeepSeek V4.1 Flash \u5DE5\u5177\u5BF9\u8BDD\u7684\u7A7A\u56DE\u7B54\u548C\u5F02\u5E38\u7ED3\u675F\uFF1B\u6301\u7EED\u91CD\u8BD5\u76F4\u5230\u6210\u529F\u6216\u53D6\u6D88\uFF0C\u53EF\u80FD\u8BEF\u5224\u5E76\u989D\u5916\u6D88\u8017\u989D\u5EA6").volatile(),
|
|
331
331
|
quotaRefreshSeconds: Schema.natural().min(5).max(3600).default(60).description("\u989D\u5EA6\u81EA\u52A8\u5237\u65B0\u95F4\u9694\uFF08\u79D2\uFF09").volatile(),
|
|
332
332
|
requestTimeoutMs: Schema.natural().min(1e3).max(36e5).default(18e5).description("\u63A8\u7406\u8BF7\u6C42\u603B\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09").volatile(),
|
|
333
333
|
streamIdleTimeoutMs: Schema.natural().min(1e3).max(18e5).default(3e5).description("\u6D41\u5F0F\u54CD\u5E94\u65E0\u6570\u636E\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09").volatile()
|
|
@@ -495,6 +495,11 @@ import {
|
|
|
495
495
|
isContextWindowExceededError,
|
|
496
496
|
isQuotaExceededError
|
|
497
497
|
} from "@deepseek-ai/dsh-llm";
|
|
498
|
+
var PrematureEndError = class extends LlmError2 {
|
|
499
|
+
constructor(message) {
|
|
500
|
+
super(message, "INVALID_RESPONSE");
|
|
501
|
+
}
|
|
502
|
+
};
|
|
498
503
|
var MESSAGES = {
|
|
499
504
|
[CONTEXT_WINDOW_EXCEEDED_CODE]: "OpenDesign\uFF1A\u8BF7\u6C42\u8D85\u51FA\u6A21\u578B\u4E0A\u4E0B\u6587\u957F\u5EA6\uFF0C\u8BF7\u7F29\u77ED\u8F93\u5165\u540E\u91CD\u8BD5",
|
|
500
505
|
[ACCOUNT_QUOTA_EXCEEDED_CODE]: "OpenDesign\uFF1A\u5957\u9910\u6216\u8D26\u6237\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u68C0\u67E5\u5957\u9910\u989D\u5EA6\u540E\u91CD\u8BD5",
|
|
@@ -817,7 +822,7 @@ async function* consumeSse(body, signal, idleMs) {
|
|
|
817
822
|
if (done) break;
|
|
818
823
|
}
|
|
819
824
|
signal.throwIfAborted();
|
|
820
|
-
if (!finish) throw new
|
|
825
|
+
if (!finish) throw new PrematureEndError("OpenDesign\uFF1A\u54CD\u5E94\u6D41\u63D0\u524D\u4E2D\u65AD\uFF0C\u672A\u6536\u5230\u7ED3\u675F\u539F\u56E0");
|
|
821
826
|
if (!count2) throw new LlmError4("OpenDesign\uFF1A\u6A21\u578B\u8FD4\u56DE\u7A7A\u54CD\u5E94", "EMPTY_RESPONSE");
|
|
822
827
|
if (finish.kind === "tool-calls" && !sawTool) throw new LlmError4("OpenDesign\uFF1A\u54CD\u5E94\u58F0\u660E\u5DE5\u5177\u8C03\u7528\uFF0C\u4F46\u672A\u8FD4\u56DE\u4EFB\u4F55\u5DE5\u5177\u5757", "INVALID_RESPONSE");
|
|
823
828
|
if (usage) yield { type: "usage", usage };
|
|
@@ -825,11 +830,22 @@ async function* consumeSse(body, signal, idleMs) {
|
|
|
825
830
|
}
|
|
826
831
|
|
|
827
832
|
// src/empty-turn.ts
|
|
828
|
-
import
|
|
829
|
-
|
|
833
|
+
import "@deepseek-ai/dsh-llm";
|
|
834
|
+
|
|
835
|
+
// src/eot-code.ts
|
|
836
|
+
var OPENDESIGN_EOT = "OPENDESIGN_EOT";
|
|
837
|
+
|
|
838
|
+
// src/empty-turn.ts
|
|
839
|
+
var EMPTY_TURN_MESSAGE = "OpenDesign\uFF1A\u6A21\u578B\u672A\u4EA7\u751F\u53EF\u7528\u56DE\u7B54\u6216\u6709\u6548\u5DE5\u5177\u8C03\u7528";
|
|
840
|
+
var INCOMPLETE_TURN_MESSAGE = "OpenDesign\uFF1A\u6A21\u578B\u505C\u5728\u64CD\u4F5C\u8BF4\u660E\uFF0C\u672A\u7EE7\u7EED\u53D1\u8D77\u5DE5\u5177\u8C03\u7528";
|
|
830
841
|
var RESIDUE_PATTERNS = [
|
|
842
|
+
/<\s*rea:tool_calls\s*>[\s\S]*?(?:<\s*\/\s*rea:tool_calls\s*>|$)/giu,
|
|
843
|
+
/<\s*rea:tool(?:\s+[^>]*)?>[\s\S]*?(?:<\s*\/\s*rea:tool\s*>|$)/giu,
|
|
844
|
+
/<\s*rea:parameter(?:\s+[^>]*)?>[\s\S]*?(?:<\s*\/\s*rea:parameter\s*>|$)/giu,
|
|
845
|
+
/<\s*||DSML||\s*calls(?:\s+[^>]*)?>[\s\S]*?(?:<\s*\/\s*||DSML||\s*calls\s*>|$)/gu,
|
|
831
846
|
/<\s*\/?\s*||DSML||[^>]*>/gu,
|
|
832
|
-
/||DSML
|
|
847
|
+
/||DSML||\s*(?:calls|invoke|parameter)(?:\s+[^>\n]*)?>/giu,
|
|
848
|
+
/||DSML||(?:\s*(?:calls|invoke|parameter))?\s*$/giu,
|
|
833
849
|
/<\s*\/?\s*thinking\s*>/giu,
|
|
834
850
|
/<\s*\/?\s*rea:tool_calls\s*>/giu,
|
|
835
851
|
/<\s*\/?\s*返璞归真\s*>/gu
|
|
@@ -844,6 +860,20 @@ function stripProtocolResidue(text2) {
|
|
|
844
860
|
function isResidueOnly(text2) {
|
|
845
861
|
return text2 === void 0 || stripProtocolResidue(text2) === "";
|
|
846
862
|
}
|
|
863
|
+
var ACTION_PREAMBLE_ZH = /^(?:(?:好的?|明白|收到)[,,。]\s*)?(?:让我|我需要|我(?:先|再|将|会|来|要|这就|马上)|先|现在|接下来(?:我)?(?:将|会)?)(?:先|再|去|来|马上)?(?:看一看|看看|看下|查看|检查|核对|核验|核查|对照|比对|确认|验证|验收|测试|读取|读|打开|搜索|查找|定位|分析|排查|审查|检索|查询|运行|执行|修改|修复|调整|更新|编写|梳理|对比|比较)(?!了|过|到|出|完)[^,,。!?!?\n;;::]{1,100}[。!!…]?$/u;
|
|
864
|
+
var ACTION_PREAMBLE_EN = /^(?:(?:okay|sure|now)[,.]?\s+)?(?:let me|i(?:'ll| will)|i(?:'m| am) going to)\s+(?:check|inspect|review|verify|read|open|search|find|locate|analy[sz]e|test|run|execute|edit|fix|update|compare)\s+[^.!?,;:\n]{1,100}(?:\.{1,3}|!|…)?$/iu;
|
|
865
|
+
var FOLLOWUP_ACTION_ZH = /^(?:现在|接下来|下一步|随后|接着)(?:我)?(?:先|再|将|会|准备|重新)?(?:看一看|看看|看下|查看|检查|核对|核验|核查|对照|比对|确认|验证|验收|测试|读取|读|打开|搜索|查找|定位|分析|排查|审查|检索|查询|运行|执行|修改|修复|调整|更新|编写|梳理|对比|比较)(?!了|过|到|出|完|结果)[^。!?!?\n;;::]{1,100}[。!!…]?$/u;
|
|
866
|
+
var COMPLETED_ACTION_ZH = /(?:发现|结果(?:是|为|显示)|显示|得出|证明|确认了|已经完成|已完成|通过|没有问题|无误|正常)/u;
|
|
867
|
+
function isPendingActionTurn(text2) {
|
|
868
|
+
if (text2 === void 0) return false;
|
|
869
|
+
const content2 = stripProtocolResidue(text2);
|
|
870
|
+
if (ACTION_PREAMBLE_ZH.test(content2) || ACTION_PREAMBLE_EN.test(content2)) return true;
|
|
871
|
+
if (content2.length > 200 || /[\n`]/u.test(content2)) return false;
|
|
872
|
+
const sentences = content2.split(/(?<=[。!?])\s*/u).filter(Boolean);
|
|
873
|
+
if (sentences.length < 2 || sentences.length > 3) return false;
|
|
874
|
+
const last = sentences.at(-1) ?? "";
|
|
875
|
+
return FOLLOWUP_ACTION_ZH.test(last) && !COMPLETED_ACTION_ZH.test(last);
|
|
876
|
+
}
|
|
847
877
|
function isMarkupOnlyStop(reason, input) {
|
|
848
878
|
return reason.kind === "stop" && !input.sawToolCall && isResidueOnly(input.text);
|
|
849
879
|
}
|
|
@@ -912,24 +942,28 @@ var EmptyTurnTracker = class {
|
|
|
912
942
|
sawToolCall: this.#sawToolCall,
|
|
913
943
|
textLength: text2.length,
|
|
914
944
|
reasoningLength: reasoning.length,
|
|
915
|
-
markupOnly: isResidueOnly(text2)
|
|
945
|
+
markupOnly: isResidueOnly(text2),
|
|
946
|
+
pendingAction: isPendingActionTurn(text2)
|
|
916
947
|
};
|
|
917
948
|
}
|
|
918
949
|
/**
|
|
919
|
-
|
|
950
|
+
* Rewrite an eligible finish into the scoped EOT failure.
|
|
920
951
|
*
|
|
921
952
|
* The reason object is returned unchanged (same reference) whenever the monitor is off, the
|
|
922
|
-
* finish is not `stop`, a tool call was observed, or the visible text
|
|
923
|
-
* This method only decides and rewrites
|
|
953
|
+
* finish is not `stop`, a tool call was observed, or the visible text is a substantive answer.
|
|
954
|
+
* This method only decides and rewrites; scoped recovery runs at the host's request-error boundary.
|
|
924
955
|
* @param reason - the finish reason the adapter is about to yield.
|
|
925
956
|
* @returns a retryable `error` reason, or the given reason untouched.
|
|
926
957
|
*/
|
|
927
958
|
resolve(reason) {
|
|
928
|
-
|
|
959
|
+
const text2 = this.#text();
|
|
960
|
+
const markupOnly = isMarkupOnlyStop(reason, { sawToolCall: this.#sawToolCall, text: text2 });
|
|
961
|
+
const pendingAction = reason.kind === "stop" && !this.#sawToolCall && isPendingActionTurn(text2);
|
|
962
|
+
if (!this.#enabled || !markupOnly && !pendingAction) {
|
|
929
963
|
return reason;
|
|
930
964
|
}
|
|
931
965
|
this.#notify();
|
|
932
|
-
return { kind: "error", failure: { code:
|
|
966
|
+
return { kind: "error", failure: { code: OPENDESIGN_EOT, message: pendingAction ? INCOMPLETE_TURN_MESSAGE : EMPTY_TURN_MESSAGE } };
|
|
933
967
|
}
|
|
934
968
|
/** Report one rewrite to the telemetry hook; monitoring must never break the stream. */
|
|
935
969
|
#notify() {
|
|
@@ -1356,7 +1390,7 @@ async function* streamMessages(body, signal, idleMs) {
|
|
|
1356
1390
|
if (finish) break;
|
|
1357
1391
|
}
|
|
1358
1392
|
signal.throwIfAborted();
|
|
1359
|
-
if (!finish) throw new
|
|
1393
|
+
if (!finish) throw new PrematureEndError("OpenDesign\uFF1A\u54CD\u5E94\u6D41\u63D0\u524D\u4E2D\u65AD\uFF0C\u672A\u6536\u5230\u7ED3\u675F\u4E8B\u4EF6");
|
|
1360
1394
|
}
|
|
1361
1395
|
var messages = {
|
|
1362
1396
|
id: "messages",
|
|
@@ -1705,7 +1739,7 @@ async function* streamResponses(body, signal, idleMs) {
|
|
|
1705
1739
|
if (finish) break;
|
|
1706
1740
|
}
|
|
1707
1741
|
signal.throwIfAborted();
|
|
1708
|
-
if (!finish) throw new
|
|
1742
|
+
if (!finish) throw new PrematureEndError("OpenDesign\uFF1A\u54CD\u5E94\u6D41\u63D0\u524D\u4E2D\u65AD\uFF0C\u672A\u6536\u5230\u7ED3\u675F\u4E8B\u4EF6");
|
|
1709
1743
|
}
|
|
1710
1744
|
var responses = {
|
|
1711
1745
|
id: "responses",
|
|
@@ -1883,9 +1917,18 @@ var CoRouterAdapter = class extends LlmAdapter {
|
|
|
1883
1917
|
}
|
|
1884
1918
|
throw gatewayError(response.status, error);
|
|
1885
1919
|
}
|
|
1886
|
-
if (!response.body) throw new LlmError10("CoRouter \u8FD4\u56DE\u7A7A\u54CD\u5E94", "EMPTY_RESPONSE");
|
|
1887
1920
|
const monitor = row.group === "plan" && row.id === "deepseek-v4.1-flash" && config.emptyTurnGuard && Boolean(options.tools?.length);
|
|
1888
|
-
const
|
|
1921
|
+
const reportEmptyTurn = () => {
|
|
1922
|
+
try {
|
|
1923
|
+
this.options.onEmptyTurn?.();
|
|
1924
|
+
} catch {
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
if (!response.body) {
|
|
1928
|
+
if (monitor) reportEmptyTurn();
|
|
1929
|
+
throw new LlmError10("CoRouter \u8FD4\u56DE\u7A7A\u54CD\u5E94", monitor ? OPENDESIGN_EOT : "EMPTY_RESPONSE");
|
|
1930
|
+
}
|
|
1931
|
+
const tracker = new EmptyTurnTracker({ enabled: monitor, onEmptyTurn: reportEmptyTurn });
|
|
1889
1932
|
try {
|
|
1890
1933
|
for await (const chunk of protocol.stream(response.body, signal, config.streamIdleTimeoutMs)) {
|
|
1891
1934
|
tracker.observe(chunk);
|
|
@@ -1895,12 +1938,81 @@ var CoRouterAdapter = class extends LlmAdapter {
|
|
|
1895
1938
|
} catch (error) {
|
|
1896
1939
|
if (options.signal?.aborted || this.#lifetime.signal.aborted) signal.throwIfAborted();
|
|
1897
1940
|
if (signal.aborted) throw new LlmError10("CoRouter \u8BF7\u6C42\u8D85\u8FC7\u603B\u8D85\u65F6", "TIMEOUT");
|
|
1941
|
+
if (monitor && !tracker.sawToolCall && error instanceof PrematureEndError) throw new LlmError10(error.message, "TRANSPORT");
|
|
1942
|
+
if (monitor && !tracker.sawToolCall && error instanceof LlmError10 && error.code === "EMPTY_RESPONSE") {
|
|
1943
|
+
reportEmptyTurn();
|
|
1944
|
+
throw new LlmError10(error.message, OPENDESIGN_EOT);
|
|
1945
|
+
}
|
|
1898
1946
|
if (error instanceof LlmError10) throw error;
|
|
1899
1947
|
throw new LlmError10("CoRouter \u54CD\u5E94\u6D41\u8FDE\u63A5\u4E2D\u65AD", "SERVER");
|
|
1900
1948
|
}
|
|
1901
1949
|
}
|
|
1902
1950
|
};
|
|
1903
1951
|
|
|
1952
|
+
// src/eot-recovery.ts
|
|
1953
|
+
import { randomUUID } from "node:crypto";
|
|
1954
|
+
var POLICY_KEY = "opendesign-eot-unbounded-v1";
|
|
1955
|
+
var INITIAL_DELAY_MS = 500;
|
|
1956
|
+
var MAX_DELAY_MS = 1e4;
|
|
1957
|
+
function cancellableDelay(delay, signal) {
|
|
1958
|
+
if (signal.aborted) return Promise.resolve(false);
|
|
1959
|
+
return new Promise((resolve) => {
|
|
1960
|
+
const timer = setTimeout(() => {
|
|
1961
|
+
signal.removeEventListener("abort", onAbort);
|
|
1962
|
+
resolve(true);
|
|
1963
|
+
}, delay);
|
|
1964
|
+
const onAbort = () => {
|
|
1965
|
+
clearTimeout(timer);
|
|
1966
|
+
resolve(false);
|
|
1967
|
+
};
|
|
1968
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
var EotRecovery = class {
|
|
1972
|
+
constructor(enabled, wait = cancellableDelay) {
|
|
1973
|
+
this.enabled = enabled;
|
|
1974
|
+
this.wait = wait;
|
|
1975
|
+
}
|
|
1976
|
+
enabled;
|
|
1977
|
+
wait;
|
|
1978
|
+
#lifetime = new AbortController();
|
|
1979
|
+
#states = /* @__PURE__ */ new WeakMap();
|
|
1980
|
+
#active = /* @__PURE__ */ new Set();
|
|
1981
|
+
handle = (payload, next) => {
|
|
1982
|
+
if (payload.provider !== PLAN_PROVIDER || payload.failure.code !== OPENDESIGN_EOT || !this.enabled()) return next();
|
|
1983
|
+
if (payload.signal.aborted || this.#lifetime.signal.aborted) return Promise.resolve(void 0);
|
|
1984
|
+
const operation = this.#recover(payload);
|
|
1985
|
+
const tracked = operation.finally(() => this.#active.delete(tracked));
|
|
1986
|
+
this.#active.add(tracked);
|
|
1987
|
+
return tracked;
|
|
1988
|
+
};
|
|
1989
|
+
async #recover({ agent, turn, step, provider, failure, signal }) {
|
|
1990
|
+
const fused = AbortSignal.any([signal, this.#lifetime.signal]);
|
|
1991
|
+
if (fused.aborted) return;
|
|
1992
|
+
const previous = this.#states.get(agent);
|
|
1993
|
+
const state = previous?.turn === turn && previous.step === step ? { ...previous, retry: previous.retry + 1 } : { turn, step, retryId: randomUUID(), retry: 1 };
|
|
1994
|
+
this.#states.set(agent, state);
|
|
1995
|
+
const delayMs = Math.min(INITIAL_DELAY_MS * 2 ** Math.min(state.retry - 1, 8), MAX_DELAY_MS);
|
|
1996
|
+
agent.session.append("llm/retry", { retryId: state.retryId, turn, step, provider, mode: "always", policyKey: POLICY_KEY, retry: state.retry, delayMs, failure });
|
|
1997
|
+
if (!await this.wait(delayMs, fused) || fused.aborted || !this.enabled()) return;
|
|
1998
|
+
agent.session.append("llm/retry-started", { retryId: state.retryId, turn, step, retry: state.retry });
|
|
1999
|
+
return { kind: "retry" };
|
|
2000
|
+
}
|
|
2001
|
+
async dispose() {
|
|
2002
|
+
this.#lifetime.abort(new Error("EOT recovery disposed"));
|
|
2003
|
+
await Promise.allSettled([...this.#active]);
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
function installEotRecovery(ctx, enabled) {
|
|
2007
|
+
const recovery = new EotRecovery(enabled);
|
|
2008
|
+
const events = ctx;
|
|
2009
|
+
const remove = events.on("agent/request-error", recovery.handle, { prepend: true });
|
|
2010
|
+
ctx.effect(() => async () => {
|
|
2011
|
+
remove();
|
|
2012
|
+
await recovery.dispose();
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
|
|
1904
2016
|
// src/model-discovery.ts
|
|
1905
2017
|
import { attributionHeaders as attributionHeaders2 } from "@deepseek-ai/dsh-llm";
|
|
1906
2018
|
var DISCOVERY_TIMEOUT_MS = 2e4;
|
|
@@ -2535,11 +2647,11 @@ async function resolveSession(deps = {}) {
|
|
|
2535
2647
|
}
|
|
2536
2648
|
|
|
2537
2649
|
// src/login.ts
|
|
2538
|
-
import { randomUUID } from "node:crypto";
|
|
2650
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
2539
2651
|
|
|
2540
2652
|
// src/device-auth.ts
|
|
2541
2653
|
var DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
|
|
2542
|
-
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.
|
|
2654
|
+
var DEVICE_AUTH_PLUGIN_VERSION = "0.1.11";
|
|
2543
2655
|
var DEVICE_REQUEST_TIMEOUT_MS = 2e4;
|
|
2544
2656
|
var DEVICE_RESPONSE_MAX_BYTES = 65536;
|
|
2545
2657
|
var DEVICE_POLL_MIN_MS = 1e3;
|
|
@@ -2773,7 +2885,7 @@ var ConsoleLogin = class {
|
|
|
2773
2885
|
const requested = this.options.timeoutMs;
|
|
2774
2886
|
const timeoutMs = typeof requested === "number" && Number.isFinite(requested) && requested > 0 ? Math.min(MAX_TIMEOUT_MS, requested) : MAX_TIMEOUT_MS;
|
|
2775
2887
|
const job = {
|
|
2776
|
-
id:
|
|
2888
|
+
id: randomUUID2(),
|
|
2777
2889
|
controller: new AbortController(),
|
|
2778
2890
|
deadline: started + timeoutMs,
|
|
2779
2891
|
status: { jobId: null, state: "launching", startedAt: new Date(started).toISOString(), message: "\u6B63\u5728\u7533\u8BF7\u5B98\u65B9\u8BBE\u5907\u6388\u6743\u7801" },
|
|
@@ -3727,7 +3839,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
3727
3839
|
__publicField(this, "_login");
|
|
3728
3840
|
__publicField(this, "_activation");
|
|
3729
3841
|
__publicField(this, "_lifetime", new AbortController());
|
|
3730
|
-
__publicField(this, "_revision",
|
|
3842
|
+
__publicField(this, "_revision", randomUUID3());
|
|
3731
3843
|
__publicField(this, "_fingerprint", "");
|
|
3732
3844
|
__publicField(this, "_quota", unreadQuota());
|
|
3733
3845
|
__publicField(this, "_quotaAt", 0);
|
|
@@ -3836,7 +3948,7 @@ var OpenDesignCoRouterService = class extends (_a = TypertRemoteService, _status
|
|
|
3836
3948
|
const fingerprint = hash(state);
|
|
3837
3949
|
if (fingerprint !== this._fingerprint) {
|
|
3838
3950
|
this._fingerprint = fingerprint;
|
|
3839
|
-
this._revision =
|
|
3951
|
+
this._revision = randomUUID3();
|
|
3840
3952
|
}
|
|
3841
3953
|
return state;
|
|
3842
3954
|
}
|
|
@@ -4105,6 +4217,7 @@ __decoratorMetadata(_init, OpenDesignCoRouterService);
|
|
|
4105
4217
|
function apply(ctx, config) {
|
|
4106
4218
|
const current = () => readConfig(config);
|
|
4107
4219
|
current();
|
|
4220
|
+
installEotRecovery(ctx, () => current().emptyTurnGuard);
|
|
4108
4221
|
ctx.inject(["settings"], (scope) => scope.effect(() => scope.settings.configure({ auto: false }, ctx.fiber)));
|
|
4109
4222
|
let modelsChanged = () => {
|
|
4110
4223
|
};
|