@dsh-workbench/shared 1.5.2-rc.1 → 1.5.2
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/dist/api/blocker-table.d.ts +11 -3
- package/dist/api/blocker-table.js +88 -49
- package/dist/components/card/CardBoundary.d.ts +17 -4
- package/dist/components/card/CardBoundary.js +55 -12
- package/dist/components/card/CardBoundary.module.css +10 -0
- package/dist/contract/blocker.d.ts +4 -0
- package/dist/contract/blocker.js +25 -12
- package/dist/host/adapters/port-types.d.ts +2 -0
- package/dist/host/supply/preflight.d.ts +16 -1
- package/dist/i18n/en.js +46 -10
- package/dist/i18n/index.d.ts +47 -11
- package/dist/i18n/zh.d.ts +46 -10
- package/dist/i18n/zh.js +46 -10
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/blocker-action.d.ts +1 -0
- package/dist/lib/copy-flash.d.ts +10 -0
- package/dist/lib/copy-flash.js +30 -0
- package/dist/lib/fault-prompt.d.ts +40 -0
- package/dist/lib/fault-prompt.js +44 -0
- package/package.json +1 -1
- package/src/api/__tests__/blocker-table.test.ts +112 -3
- package/src/api/blocker-table.ts +109 -54
- package/src/components/card/CardBoundary.module.css +10 -0
- package/src/components/card/CardBoundary.tsx +83 -12
- package/src/components/card/__tests__/card-boundary.test.tsx +137 -0
- package/src/contract/blocker.ts +31 -12
- package/src/host/adapters/port-types.ts +2 -0
- package/src/host/runtime/__tests__/dsh-compat.test.ts +1 -1
- package/src/host/supply/preflight.ts +18 -2
- package/src/i18n/en.ts +46 -10
- package/src/i18n/zh.ts +46 -10
- package/src/index.ts +2 -0
- package/src/lib/__tests__/copy-flash.test.ts +72 -0
- package/src/lib/blocker-action.ts +1 -0
- package/src/lib/copy-flash.ts +34 -0
- package/src/lib/fault-prompt.ts +90 -0
package/src/api/blocker-table.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { CapabilityPayload } from '../contract/workbench-contract.js';
|
|
|
3
3
|
import type { ApiError } from './workbench-client.js';
|
|
4
4
|
import type { BlockerAction, ModuleBlocker } from '../contract/blocker.js';
|
|
5
5
|
import { DIAG_FALLBACK_CODE, diagSpecOf, isDiagCode } from '../contract/blocker.js';
|
|
6
|
+
import { faultPromptOf, firstLineOf, type PromptFacts } from '../lib/fault-prompt.js';
|
|
6
7
|
import { shortenPath } from '../lib/ui.js';
|
|
7
8
|
|
|
8
9
|
function retryAction(t: Translate): BlockerAction {
|
|
@@ -13,6 +14,40 @@ function copyAction(t: Translate, text: string): BlockerAction {
|
|
|
13
14
|
return { kind: 'copy', label: t('blocker.copy'), text };
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
export interface BlockerAsk {
|
|
18
|
+
readonly screen?: string;
|
|
19
|
+
readonly step?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function askAgentActionOf(t: Translate, facts: PromptFacts): BlockerAction {
|
|
23
|
+
return { kind: 'ask-agent', label: t('askAgent.copy'), prompt: faultPromptOf(facts, t) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function askOf(t: Translate, ask: BlockerAsk | undefined): PromptFacts & { screen: string } {
|
|
27
|
+
return {
|
|
28
|
+
screen: ask?.screen ?? t('askAgent.screen.board'),
|
|
29
|
+
...(ask?.step === undefined ? {} : { step: ask.step }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function cardBlocker(parts: {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly severity: 'block' | 'notice';
|
|
36
|
+
readonly title: string;
|
|
37
|
+
readonly hint: string;
|
|
38
|
+
readonly detail: string | undefined;
|
|
39
|
+
readonly actions: readonly BlockerAction[];
|
|
40
|
+
}): ModuleBlocker {
|
|
41
|
+
const base: ModuleBlocker = {
|
|
42
|
+
id: parts.id,
|
|
43
|
+
severity: parts.severity,
|
|
44
|
+
title: parts.title,
|
|
45
|
+
hint: parts.hint,
|
|
46
|
+
actions: parts.actions,
|
|
47
|
+
};
|
|
48
|
+
return parts.detail === undefined ? base : { ...base, detail: parts.detail };
|
|
49
|
+
}
|
|
50
|
+
|
|
16
51
|
/**
|
|
17
52
|
* 把一条诊断码翻成卡住态:标题取该码自己的文案,不认识的码退回兜底那条。
|
|
18
53
|
* @param code 诊断码(`DIAG_*`);不在注册表里就按兜底码处理。
|
|
@@ -24,15 +59,27 @@ export function blockerOfDiag(
|
|
|
24
59
|
code: string,
|
|
25
60
|
t: Translate,
|
|
26
61
|
detail: string | null = null,
|
|
62
|
+
ask?: BlockerAsk,
|
|
27
63
|
): ModuleBlocker {
|
|
28
|
-
const
|
|
64
|
+
const known = isDiagCode(code);
|
|
65
|
+
const spec = diagSpecOf(known ? code : DIAG_FALLBACK_CODE);
|
|
66
|
+
const title = t(spec?.messageKey ?? 'diag.code.unknownCode');
|
|
67
|
+
const actions: readonly BlockerAction[] = known
|
|
68
|
+
? [retryAction(t)]
|
|
69
|
+
: [
|
|
70
|
+
askAgentActionOf(t, {
|
|
71
|
+
...askOf(t, ask),
|
|
72
|
+
problem: { why: title, issue: code, ...(detail === null ? {} : { reason: firstLineOf(detail) }) },
|
|
73
|
+
}),
|
|
74
|
+
retryAction(t),
|
|
75
|
+
];
|
|
29
76
|
return {
|
|
30
77
|
id: `diag:${spec?.code ?? DIAG_FALLBACK_CODE}`,
|
|
31
78
|
severity: 'block',
|
|
32
|
-
title
|
|
79
|
+
title,
|
|
33
80
|
...(spec?.hintKey === undefined ? {} : { hint: t(spec.hintKey) }),
|
|
34
81
|
...(detail === null ? {} : { detail }),
|
|
35
|
-
actions
|
|
82
|
+
actions,
|
|
36
83
|
};
|
|
37
84
|
}
|
|
38
85
|
|
|
@@ -50,14 +97,16 @@ export function blockerOfError(
|
|
|
50
97
|
path?: string | null;
|
|
51
98
|
platform?: string;
|
|
52
99
|
diagnose?: Readonly<Partial<Record<'exec' | 'login' | 'bridge', string>>>;
|
|
100
|
+
ask?: BlockerAsk;
|
|
53
101
|
} = {},
|
|
54
102
|
): ModuleBlocker {
|
|
55
103
|
if (error === undefined) {
|
|
104
|
+
const title = t('blocker.unknown.title');
|
|
56
105
|
return {
|
|
57
106
|
id: 'unknown',
|
|
58
107
|
severity: 'block',
|
|
59
|
-
title
|
|
60
|
-
actions: [retryAction(t)],
|
|
108
|
+
title,
|
|
109
|
+
actions: [askAgentActionOf(t, { ...askOf(t, context.ask), problem: { why: title } }), retryAction(t)],
|
|
61
110
|
};
|
|
62
111
|
}
|
|
63
112
|
|
|
@@ -137,15 +186,29 @@ export function blockerOfError(
|
|
|
137
186
|
actions: [retryAction(t)],
|
|
138
187
|
};
|
|
139
188
|
|
|
140
|
-
default:
|
|
189
|
+
default: {
|
|
190
|
+
const title = t('blocker.unknown.title');
|
|
141
191
|
return {
|
|
142
192
|
id: error.code,
|
|
143
193
|
severity: 'block',
|
|
144
|
-
title
|
|
194
|
+
title,
|
|
145
195
|
...(error.hint === undefined ? {} : { hint: error.hint }),
|
|
146
196
|
detail: error.detail ?? error.message,
|
|
147
|
-
actions: [
|
|
197
|
+
actions: [
|
|
198
|
+
askAgentActionOf(t, {
|
|
199
|
+
...askOf(t, context.ask),
|
|
200
|
+
problem: {
|
|
201
|
+
why: title,
|
|
202
|
+
issue: error.code,
|
|
203
|
+
...(firstLineOf(error.detail ?? error.message) === undefined
|
|
204
|
+
? {}
|
|
205
|
+
: { reason: firstLineOf(error.detail ?? error.message) }),
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
retryAction(t),
|
|
209
|
+
],
|
|
148
210
|
};
|
|
211
|
+
}
|
|
149
212
|
}
|
|
150
213
|
}
|
|
151
214
|
|
|
@@ -164,20 +227,20 @@ export function blockerOf(parts: {
|
|
|
164
227
|
readonly t: Translate;
|
|
165
228
|
readonly platform?: string | undefined;
|
|
166
229
|
readonly loginUrl?: string | undefined;
|
|
230
|
+
readonly ask?: BlockerAsk | undefined;
|
|
167
231
|
}): ModuleBlocker | undefined {
|
|
168
232
|
if (parts.capability !== undefined) {
|
|
169
|
-
const fromCapability = blockerOfCapability(parts.capability, parts.t);
|
|
233
|
+
const fromCapability = blockerOfCapability(parts.capability, parts.t, parts.ask);
|
|
170
234
|
if (fromCapability !== undefined) return fromCapability;
|
|
171
235
|
}
|
|
172
236
|
if (parts.error === undefined) return undefined;
|
|
173
237
|
const isLogin = parts.error.code === 'auth-required' || parts.error.code === 'auth';
|
|
174
238
|
const helpUrl = parts.error.helpUrl !== undefined || !isLogin ? parts.error.helpUrl : parts.loginUrl;
|
|
175
239
|
const withHelp = helpUrl === undefined ? parts.error : { ...parts.error, helpUrl };
|
|
176
|
-
return blockerOfError(
|
|
177
|
-
|
|
178
|
-
parts.
|
|
179
|
-
|
|
180
|
-
);
|
|
240
|
+
return blockerOfError(withHelp, parts.t, {
|
|
241
|
+
...(parts.platform === undefined ? {} : { platform: parts.platform }),
|
|
242
|
+
...(parts.ask === undefined ? {} : { ask: parts.ask }),
|
|
243
|
+
});
|
|
181
244
|
}
|
|
182
245
|
|
|
183
246
|
/**
|
|
@@ -186,7 +249,11 @@ export function blockerOf(parts: {
|
|
|
186
249
|
* @param t 文案函数,键都在 env.unit.* / blocker.* 下。
|
|
187
250
|
* @returns status 为 'ok' 时给 undefined(没有卡住态),其余状态一律给一张。
|
|
188
251
|
*/
|
|
189
|
-
export function blockerOfCapability(
|
|
252
|
+
export function blockerOfCapability(
|
|
253
|
+
capability: CapabilityPayload,
|
|
254
|
+
t: Translate,
|
|
255
|
+
ask?: BlockerAsk,
|
|
256
|
+
): ModuleBlocker | undefined {
|
|
190
257
|
if (capability.status === 'ok') return undefined;
|
|
191
258
|
|
|
192
259
|
const problem = capability.needs.find((need) => need.status !== 'ok');
|
|
@@ -209,58 +276,46 @@ export function blockerOfCapability(capability: CapabilityPayload, t: Translate)
|
|
|
209
276
|
const detail = problem?.detail ?? capability.detail;
|
|
210
277
|
|
|
211
278
|
if (capability.status === 'failed') {
|
|
212
|
-
|
|
279
|
+
const title = t('env.unit.failed');
|
|
280
|
+
const reason = firstLineOf(capability.detail);
|
|
281
|
+
return cardBlocker({
|
|
213
282
|
id: 'unit-mount-failed',
|
|
214
283
|
severity: 'block',
|
|
215
|
-
title
|
|
284
|
+
title,
|
|
216
285
|
hint: t('env.unit.failedHint'),
|
|
217
|
-
|
|
218
|
-
actions: [
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
hint: t('env.unit.unsupportedHint'),
|
|
228
|
-
...(detail === undefined ? {} : { detail }),
|
|
229
|
-
actions: [retryAction(t)],
|
|
230
|
-
};
|
|
286
|
+
detail: capability.detail,
|
|
287
|
+
actions: [
|
|
288
|
+
askAgentActionOf(t, {
|
|
289
|
+
...askOf(t, ask),
|
|
290
|
+
step: ask?.step ?? capability.unit,
|
|
291
|
+
problem: { why: title, ...(reason === undefined ? {} : { reason }) },
|
|
292
|
+
}),
|
|
293
|
+
retryAction(t),
|
|
294
|
+
],
|
|
295
|
+
});
|
|
231
296
|
}
|
|
232
297
|
|
|
233
|
-
if (capability.status === 'degraded') {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
298
|
+
if (capability.status === 'unsupported' || capability.status === 'degraded') {
|
|
299
|
+
const notice = capability.status === 'degraded';
|
|
300
|
+
return cardBlocker({
|
|
301
|
+
id: notice ? 'unit-degraded' : 'unit-unsupported',
|
|
302
|
+
severity: notice ? 'notice' : 'block',
|
|
303
|
+
title: t(notice ? 'env.unit.degraded' : 'env.unit.unsupported'),
|
|
304
|
+
hint: t(notice ? 'env.unit.degradedHint' : 'env.unit.unsupportedHint'),
|
|
305
|
+
detail,
|
|
240
306
|
actions: [retryAction(t)],
|
|
241
|
-
};
|
|
307
|
+
});
|
|
242
308
|
}
|
|
243
309
|
|
|
244
|
-
if (problem === undefined) {
|
|
245
|
-
return {
|
|
310
|
+
if (problem === undefined || problem.status === 'unchecked') {
|
|
311
|
+
return cardBlocker({
|
|
246
312
|
id: 'unit-unchecked',
|
|
247
313
|
severity: 'notice',
|
|
248
314
|
title: t('env.unit.unchecked'),
|
|
249
315
|
hint: t('env.unit.uncheckedHint'),
|
|
250
|
-
|
|
316
|
+
detail: problem === undefined ? capability.detail : detail,
|
|
251
317
|
actions: [retryAction(t)],
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (problem.status === 'unchecked') {
|
|
256
|
-
return {
|
|
257
|
-
id: 'unit-unchecked',
|
|
258
|
-
severity: 'notice',
|
|
259
|
-
title: t('env.unit.unchecked'),
|
|
260
|
-
hint: t('env.unit.uncheckedHint'),
|
|
261
|
-
...(detail === undefined ? {} : { detail }),
|
|
262
|
-
actions: [retryAction(t)],
|
|
263
|
-
};
|
|
318
|
+
});
|
|
264
319
|
}
|
|
265
320
|
|
|
266
321
|
const kindTitle = `env.need.${problem.kind}.${problem.status}`;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Translate } from '../../lib/dsh-client.js';
|
|
2
2
|
import type { ReactNode } from '../../lib/react.js';
|
|
3
3
|
import { Component, h } from '../../lib/react.js';
|
|
4
|
+
import { CodeBlock, DisclosureRow, IconInfoOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
5
|
+
import { createCopyFlash } from '../../lib/copy-flash.js';
|
|
6
|
+
import { faultPromptOf, firstLineOf } from '../../lib/fault-prompt.js';
|
|
4
7
|
import { Note } from '../feedback/Note.js';
|
|
5
8
|
import { FormActions } from '../form/FormActions.js';
|
|
6
9
|
import styles from './CardBoundary.module.css';
|
|
7
10
|
|
|
11
|
+
const COPIED_MS = 1500;
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* `CardBoundary` 的契约:被守的 unit、重来键与失败回调。
|
|
10
15
|
*/
|
|
@@ -18,10 +23,12 @@ export interface CardBoundaryProps {
|
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
|
-
* `CardBoundary`
|
|
26
|
+
* `CardBoundary` 的状态:这次渲染炸出来的那句话、折叠行是否展开、刚复制过没有。
|
|
22
27
|
*/
|
|
23
28
|
export interface CardBoundaryState {
|
|
24
29
|
readonly reason: string | null;
|
|
30
|
+
readonly detailsOpen: boolean;
|
|
31
|
+
readonly copied: boolean;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
/**
|
|
@@ -34,21 +41,48 @@ export function errorReasonOf(error: unknown): string {
|
|
|
34
41
|
return typeof error === 'string' ? error : JSON.stringify(error) ?? String(error);
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
/**
|
|
45
|
+
* 卡片渲染崩溃时要交给 agent 的那段提示词:位置 + 哪个模块 + 报错首行。
|
|
46
|
+
* @param unit - 出事的 unit id。
|
|
47
|
+
* @param reason - 拦截到的失败原因。
|
|
48
|
+
* @param t - 文案函数,键在 askAgent.* 与 panels.* 下。
|
|
49
|
+
* @returns 可直接粘贴给 agent 的多行提示词。
|
|
50
|
+
*/
|
|
51
|
+
export function cardBrokenPromptOf(unit: string, reason: string, t: Translate): string {
|
|
52
|
+
const cause = firstLineOf(reason);
|
|
53
|
+
return faultPromptOf(
|
|
54
|
+
{
|
|
55
|
+
screen: t('askAgent.screen.board'),
|
|
56
|
+
problem: {
|
|
57
|
+
why: t('panels.cardBroken', { unit }),
|
|
58
|
+
...(cause === undefined ? {} : { reason: cause }),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
t,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stateOf(reason: string | null): CardBoundaryState {
|
|
66
|
+
return { reason, detailsOpen: false, copied: false };
|
|
67
|
+
}
|
|
68
|
+
|
|
37
69
|
/**
|
|
38
70
|
* 卡片级错误边界:一张卡渲染炸了只画一条报错 + 重试,不让整块面板跟着塌。
|
|
39
71
|
* @param props.unit - 出事的 unit id,写进报错文案并作为上报标识。
|
|
40
72
|
* @param props.resetKey - 重来键:它一变(如切了工作区)就自动清掉报错,把卡片重新渲染一遍。
|
|
41
|
-
* @param props.t -
|
|
73
|
+
* @param props.t - 报错那句、重试钮与「复制给 agent」的翻译函数。
|
|
42
74
|
* @param props.onFailure - 失败时把原因报给宿主(面板状态要用);不给就只打一条 console。
|
|
43
|
-
* @param props.fallback -
|
|
75
|
+
* @param props.fallback - 出错时改画这一份;不给就画卡片失败提示、可折叠的原文与两颗按钮。
|
|
44
76
|
* @param props.children - 正常时要渲染的卡片内容。
|
|
45
77
|
* @returns 正常时是 `children`,炸过且还没重来之前是一条报错。
|
|
46
78
|
*/
|
|
47
79
|
export class CardBoundary extends Component<CardBoundaryProps, CardBoundaryState> {
|
|
48
|
-
override state: CardBoundaryState =
|
|
80
|
+
override state: CardBoundaryState = stateOf(null);
|
|
81
|
+
|
|
82
|
+
private readonly flash = createCopyFlash(COPIED_MS);
|
|
49
83
|
|
|
50
84
|
static getDerivedStateFromError(error: unknown): CardBoundaryState {
|
|
51
|
-
return
|
|
85
|
+
return stateOf(errorReasonOf(error));
|
|
52
86
|
}
|
|
53
87
|
|
|
54
88
|
override componentDidCatch(error: unknown): void {
|
|
@@ -59,32 +93,69 @@ export class CardBoundary extends Component<CardBoundaryProps, CardBoundaryState
|
|
|
59
93
|
|
|
60
94
|
override componentDidUpdate(previous: CardBoundaryProps): void {
|
|
61
95
|
if (previous.resetKey !== this.props.resetKey && this.state.reason !== null) {
|
|
62
|
-
this.
|
|
96
|
+
this.reset();
|
|
63
97
|
}
|
|
64
98
|
}
|
|
65
99
|
|
|
66
|
-
|
|
67
|
-
this.
|
|
100
|
+
override componentWillUnmount(): void {
|
|
101
|
+
this.flash.dispose();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private readonly reset = (): void => {
|
|
105
|
+
this.flash.dispose();
|
|
106
|
+
this.setState(stateOf(null));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
private readonly copyPrompt = (): void => {
|
|
110
|
+
const reason = this.state.reason;
|
|
111
|
+
if (reason === null) return;
|
|
112
|
+
this.flash.copy(cardBrokenPromptOf(this.props.unit, reason, this.props.t), (copied) =>
|
|
113
|
+
this.setState({ copied }),
|
|
114
|
+
);
|
|
68
115
|
};
|
|
69
116
|
|
|
70
117
|
override render(): ReactNode {
|
|
71
|
-
const { reason } = this.state;
|
|
118
|
+
const { reason, detailsOpen, copied } = this.state;
|
|
72
119
|
if (reason === null) return this.props.children;
|
|
73
120
|
if (this.props.fallback !== undefined) return this.props.fallback;
|
|
74
121
|
return (
|
|
75
122
|
<Note tone="problem">
|
|
76
123
|
<div className={styles.failure}>
|
|
77
|
-
<span>{this.props.t('panels.cardBroken', { unit: this.props.unit
|
|
124
|
+
<span>{this.props.t('panels.cardBroken', { unit: this.props.unit })}</span>
|
|
125
|
+
{reason === '' ? null : (
|
|
126
|
+
<DisclosureRow
|
|
127
|
+
className={styles.raw}
|
|
128
|
+
icon={<IconInfoOutlineRegular size={14} />}
|
|
129
|
+
title={this.props.t('env.fix.details')}
|
|
130
|
+
open={detailsOpen}
|
|
131
|
+
expandable
|
|
132
|
+
expandOnRowClick
|
|
133
|
+
previewChevron
|
|
134
|
+
onToggle={() => this.setState({ detailsOpen: !detailsOpen })}
|
|
135
|
+
>
|
|
136
|
+
<CodeBlock
|
|
137
|
+
code={reason}
|
|
138
|
+
copyLabel={this.props.t('blocker.copy')}
|
|
139
|
+
copiedLabel={this.props.t('env.copied')}
|
|
140
|
+
/>
|
|
141
|
+
</DisclosureRow>
|
|
142
|
+
)}
|
|
78
143
|
<FormActions
|
|
79
144
|
actions={[
|
|
80
145
|
{
|
|
81
146
|
key: 'retry',
|
|
82
147
|
label: this.props.t('panels.cardRetry'),
|
|
83
|
-
|
|
84
|
-
|
|
148
|
+
onClick: this.reset,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
key: 'ask-agent',
|
|
152
|
+
label: this.props.t('askAgent.copy'),
|
|
153
|
+
kind: 'primary',
|
|
154
|
+
onClick: this.copyPrompt,
|
|
85
155
|
},
|
|
86
156
|
]}
|
|
87
157
|
/>
|
|
158
|
+
{copied ? <p className={styles.hint}>{this.props.t('askAgent.hint')}</p> : null}
|
|
88
159
|
</div>
|
|
89
160
|
</Note>
|
|
90
161
|
);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('../../../lib/react.js', () => {
|
|
4
|
+
class Component<P, S> {
|
|
5
|
+
props: P;
|
|
6
|
+
state: S;
|
|
7
|
+
|
|
8
|
+
constructor(props: P, state: S) {
|
|
9
|
+
this.props = props;
|
|
10
|
+
this.state = state;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setState(patch: Partial<S> | ((current: S) => Partial<S>)): void {
|
|
14
|
+
const next = typeof patch === 'function' ? (patch as (current: S) => Partial<S>)(this.state) : patch;
|
|
15
|
+
this.state = { ...(this.state as object), ...(next as object) } as S;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
h: (type: unknown, props: unknown, ...children: unknown[]) => ({ type, props, children }),
|
|
20
|
+
Component,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
25
|
+
CodeBlock: (props: unknown) => ({ type: 'CodeBlock', props }),
|
|
26
|
+
DisclosureRow: (props: unknown, ...children: unknown[]) => ({ type: 'DisclosureRow', props, children }),
|
|
27
|
+
IconInfoOutlineRegular: (props: unknown) => ({ type: 'icon', props }),
|
|
28
|
+
writeClipboard: vi.fn(async () => true),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
import { writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
32
|
+
import { CardBoundary, cardBrokenPromptOf, type CardBoundaryProps } from '../CardBoundary.js';
|
|
33
|
+
|
|
34
|
+
const t = (key: string, params?: Record<string, unknown>): string =>
|
|
35
|
+
params === undefined ? key : `${key}(${JSON.stringify(params)})`;
|
|
36
|
+
|
|
37
|
+
const CARD = { type: 'card' };
|
|
38
|
+
|
|
39
|
+
interface AnyElement {
|
|
40
|
+
readonly type: unknown;
|
|
41
|
+
readonly props: Record<string, unknown>;
|
|
42
|
+
readonly children: unknown[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function boundary(extra: Partial<CardBoundaryProps> = {}): CardBoundary {
|
|
46
|
+
const one = new CardBoundary({ unit: 'ai-chat', resetKey: 'w1', t, children: CARD as never, ...extra });
|
|
47
|
+
one.state = { reason: 'TypeError: boom\n at PanelBody (client.js:88:12)', detailsOpen: false, copied: false };
|
|
48
|
+
return one;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function renderOf(one: CardBoundary): AnyElement {
|
|
52
|
+
return one.render() as unknown as AnyElement;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function bodyOf(one: CardBoundary): AnyElement {
|
|
56
|
+
return renderOf(one).children[0] as AnyElement;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function actionsOf(one: CardBoundary): readonly { key: string; label: unknown; kind?: string }[] {
|
|
60
|
+
const actions = bodyOf(one).children.find(
|
|
61
|
+
(child) => (child as AnyElement).props?.['actions'] !== undefined,
|
|
62
|
+
) as AnyElement;
|
|
63
|
+
return actions.props['actions'] as readonly { key: string; label: unknown; kind?: string }[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('卡片渲染崩溃:事实 + 折叠原文 + 两个出口', () => {
|
|
67
|
+
it('正常渲染时原样给 children', () => {
|
|
68
|
+
const one = new CardBoundary({ unit: 'ai-chat', resetKey: 'w1', t, children: CARD as never });
|
|
69
|
+
expect(renderOf(one)).toEqual({ type: 'card' });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('★ 标题只留事实:报错原文不进标题句', () => {
|
|
73
|
+
const title = bodyOf(boundary()).children[0] as AnyElement;
|
|
74
|
+
|
|
75
|
+
expect(title.children[0]).toContain('panels.cardBroken');
|
|
76
|
+
expect(title.children[0]).toContain('ai-chat');
|
|
77
|
+
expect(String(title.children[0])).not.toContain('TypeError: boom');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('★ 原文收进折叠行(可复制),不在明面上铺开', () => {
|
|
81
|
+
const fold = bodyOf(boundary()).children.find(
|
|
82
|
+
(child) => (child as AnyElement).props?.['title'] === 'env.fix.details',
|
|
83
|
+
) as AnyElement;
|
|
84
|
+
|
|
85
|
+
expect(fold).toBeDefined();
|
|
86
|
+
const code = (fold.children[0] as AnyElement).props['code'];
|
|
87
|
+
expect(code).toContain('TypeError: boom');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('★ 两颗按钮:重试(次)+ 复制给 agent(主)', () => {
|
|
91
|
+
const actions = actionsOf(boundary());
|
|
92
|
+
|
|
93
|
+
expect(actions.map((action) => action.key)).toEqual(['retry', 'ask-agent']);
|
|
94
|
+
expect(actions[0]?.label).toBe('panels.cardRetry');
|
|
95
|
+
expect(actions[1]?.label).toBe('askAgent.copy');
|
|
96
|
+
expect(actions[1]?.kind).toBe('primary');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('复制成功后出提示;按钮态由外层按 copied 渲染', () => {
|
|
100
|
+
const rendered = JSON.stringify(renderOf(boundary()));
|
|
101
|
+
expect(rendered).not.toContain('askAgent.hint');
|
|
102
|
+
|
|
103
|
+
const one = boundary();
|
|
104
|
+
one.setState({ copied: true });
|
|
105
|
+
expect(JSON.stringify(renderOf(one))).toContain('askAgent.hint');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('★ 复制走的是提示词构造器:位置 + 哪个模块 + 报错首行', async () => {
|
|
109
|
+
const one = boundary();
|
|
110
|
+
(one as unknown as { copyPrompt(): void }).copyPrompt();
|
|
111
|
+
await Promise.resolve();
|
|
112
|
+
|
|
113
|
+
const clipboard = vi.mocked(writeClipboard);
|
|
114
|
+
const prompt = clipboard.mock.calls[0]?.[0] ?? '';
|
|
115
|
+
expect(prompt).toContain('askAgent.prompt.whereOnly');
|
|
116
|
+
expect(prompt).toContain('panels.cardBroken');
|
|
117
|
+
expect(prompt).not.toContain('client.js:88');
|
|
118
|
+
expect(one.state.copied).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('提示词内容', () => {
|
|
123
|
+
it('位置写屏幕名、现象带模块 id、原因只取首行', () => {
|
|
124
|
+
const prompt = cardBrokenPromptOf('ai-chat', 'TypeError: boom\n at PanelBody (client.js:88:12)', t);
|
|
125
|
+
|
|
126
|
+
expect(prompt).toContain('askAgent.prompt.whereOnly');
|
|
127
|
+
expect(prompt).toContain('"screen":"askAgent.screen.board"');
|
|
128
|
+
expect(prompt).toContain('panels.cardBroken');
|
|
129
|
+
expect(prompt).toContain('"reason":"TypeError: boom"');
|
|
130
|
+
expect(prompt).not.toContain('client.js:88');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('空原因不硬写一行', () => {
|
|
134
|
+
const prompt = cardBrokenPromptOf('ai-chat', '', t);
|
|
135
|
+
expect(prompt).not.toContain('askAgent.prompt.reason');
|
|
136
|
+
});
|
|
137
|
+
});
|
package/src/contract/blocker.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type BlockerAction =
|
|
|
9
9
|
readonly inline?: boolean;
|
|
10
10
|
}
|
|
11
11
|
| { readonly kind: 'copy'; readonly label: string; readonly text: string }
|
|
12
|
+
| { readonly kind: 'ask-agent'; readonly label: string; readonly prompt: string }
|
|
12
13
|
| { readonly kind: 'retry'; readonly label: string }
|
|
13
14
|
| {
|
|
14
15
|
readonly kind: 'run-fix';
|
|
@@ -78,6 +79,17 @@ export const DIAG_ACTIONS: readonly DiagActionKind[] = [
|
|
|
78
79
|
|
|
79
80
|
export const DIAG_LEVELS: readonly DiagLevel[] = ['info', 'warn', 'error'];
|
|
80
81
|
|
|
82
|
+
function preflightSpec(code: string, key: string): DiagCodeSpec {
|
|
83
|
+
return {
|
|
84
|
+
code,
|
|
85
|
+
class: 'env',
|
|
86
|
+
area: 'preflight',
|
|
87
|
+
action: 'retry',
|
|
88
|
+
messageKey: `diag.code.${key}`,
|
|
89
|
+
hintKey: `diag.hint.${key}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
81
93
|
export const DIAG_CODES: readonly DiagCodeSpec[] = [
|
|
82
94
|
{
|
|
83
95
|
code: 'READ_FAILED',
|
|
@@ -122,6 +134,11 @@ export const DIAG_CODES: readonly DiagCodeSpec[] = [
|
|
|
122
134
|
action: 'retry',
|
|
123
135
|
messageKey: 'diag.code.supplyInstallFailed',
|
|
124
136
|
},
|
|
137
|
+
preflightSpec('PREFLIGHT_DIY_ROW_BROKEN', 'preflightDiyRowBroken'),
|
|
138
|
+
preflightSpec('PREFLIGHT_DIY_PRESET_MISSING', 'preflightDiyPresetMissing'),
|
|
139
|
+
preflightSpec('PREFLIGHT_BRIDGE_HOLD', 'preflightBridgeHold'),
|
|
140
|
+
preflightSpec('PREFLIGHT_HOST_OLDER', 'preflightHostOlder'),
|
|
141
|
+
preflightSpec('PREFLIGHT_HOST_NEWER', 'preflightHostNewer'),
|
|
125
142
|
{
|
|
126
143
|
code: 'DIAG_BAD_PARAM',
|
|
127
144
|
class: 'user',
|
|
@@ -178,28 +195,30 @@ export function isDiagCode(code: string): boolean {
|
|
|
178
195
|
return BY_CODE.has(code);
|
|
179
196
|
}
|
|
180
197
|
|
|
181
|
-
|
|
198
|
+
const DETAIL_KEYS_STEP: readonly string[] = [
|
|
182
199
|
'action',
|
|
183
200
|
'attempt',
|
|
184
201
|
'cacheAgeMs',
|
|
185
202
|
'count',
|
|
186
203
|
'durationMs',
|
|
187
204
|
'fromVersion',
|
|
188
|
-
'os',
|
|
189
|
-
'path',
|
|
190
205
|
'phase',
|
|
191
|
-
'pid',
|
|
192
|
-
'pkg',
|
|
193
|
-
'reason',
|
|
194
206
|
'requestedCode',
|
|
195
207
|
'route',
|
|
196
|
-
'since',
|
|
197
|
-
'sink',
|
|
198
208
|
'stage',
|
|
199
209
|
'toVersion',
|
|
200
210
|
'truncated',
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
const DETAIL_KEYS_SUBJECT: readonly string[] = ['os', 'path', 'pid', 'pkg', 'reason', 'unit', 'version', 'workspace'];
|
|
214
|
+
|
|
215
|
+
const DETAIL_KEYS_PREFLIGHT: readonly string[] = ['issues', 'rows', 'runtime', 'tier', 'verified'];
|
|
216
|
+
|
|
217
|
+
const DETAIL_KEYS_SINK: readonly string[] = ['since', 'sink', 'wroteBytes'];
|
|
218
|
+
|
|
219
|
+
export const DIAG_DETAIL_KEYS: readonly string[] = [
|
|
220
|
+
...DETAIL_KEYS_STEP,
|
|
221
|
+
...DETAIL_KEYS_SUBJECT,
|
|
222
|
+
...DETAIL_KEYS_PREFLIGHT,
|
|
223
|
+
...DETAIL_KEYS_SINK,
|
|
205
224
|
];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DshHostContext } from '../../api/dsh.js';
|
|
2
|
+
import type { DiagRecorder } from '../runtime/diag-records.js';
|
|
2
3
|
import type { Seam } from '../seam/run.js';
|
|
3
4
|
import type { RuntimeCapabilities, RuntimeProfile } from '../../contract/capabilities.js';
|
|
4
5
|
import type { BrowserCaptureRow } from '../../contract/data.js';
|
|
@@ -176,6 +177,7 @@ export interface ProbePreflightInput {
|
|
|
176
177
|
readonly runtimeLabel?: string | undefined;
|
|
177
178
|
readonly warmReads: () => readonly (readonly string[])[];
|
|
178
179
|
readonly extensionDir?: string | undefined;
|
|
180
|
+
readonly diag?: DiagRecorder | undefined;
|
|
179
181
|
}
|
|
180
182
|
|
|
181
183
|
export interface ProbePort {
|
|
@@ -126,7 +126,7 @@ describe('dsh 版本从 profile 的安装锚点读', () => {
|
|
|
126
126
|
dependencies: { '@deepseek-ai/dsh': '0.2.2-rc.2' },
|
|
127
127
|
},
|
|
128
128
|
});
|
|
129
|
-
expect(dshVersionFrom(anchored)?.from).toContain('@deepseek-ai
|
|
129
|
+
expect(dshVersionFrom(anchored)?.from).toContain(join('@deepseek-ai', 'dsh-app-boot'));
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
it('只有 dsh 清单时读它自己的版本;都读不到就是 undefined', () => {
|