dsh-crowdtest 0.0.0-stage → 0.2.22
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 +13 -2
- package/cordis.patch.yml +4 -0
- package/icon.png +0 -0
- package/lib/client.js +411 -0
- package/lib/index.js +1194 -0
- package/package.json +77 -4
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 用桌面端参与众测
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
1. 在 DeepSeek Harness「插件」页添加 npm 包 `dsh-crowdtest` 并启用。
|
|
4
|
+
2. 在众测评测页点击「在本机运行」,复制完整命令(含口令和平台地址),在桌面端任意会话中发送。
|
|
5
|
+
3. 插件自动配置模型、下载附件并新建任务会话,在新会话中完成任务。
|
|
6
|
+
4. 每轮结束自动备份。结束前确认输入框上方显示「已同步」,有内容待同步时点击「立即同步」。
|
|
7
|
+
|
|
8
|
+
在「插件」列表点击「刷新」,或打开插件详情页,DSH 会从 npm 检查新版。有新版时,列表显示「可更新」,按 DSH 的更新入口安装。更新检查由 DSH 管理,没有额外的后台定时检查。
|
|
9
|
+
|
|
10
|
+
若之前通过本地安装包安装,先完全退出 DSH,再运行一次官方命令,将安装来源改为 npm,然后重新打开 DSH:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
dsh plugin --profile desktop add dsh-crowdtest@0.2.22 --save-exact --registry https://registry.npmjs.org
|
|
14
|
+
```
|
package/cordis.patch.yml
ADDED
package/icon.png
ADDED
|
Binary file
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "dsh-crowdtest", factory: (require) => {
|
|
2
|
+
var module = { exports: {} }; var exports = module.exports;
|
|
3
|
+
"use strict";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/client/index.tsx
|
|
33
|
+
var index_exports = {};
|
|
34
|
+
__export(index_exports, {
|
|
35
|
+
apply: () => apply,
|
|
36
|
+
inject: () => inject
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var import_react2 = require("react");
|
|
40
|
+
|
|
41
|
+
// src/bridge.ts
|
|
42
|
+
function object(value) {
|
|
43
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("invalid sync payload");
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function parseRequest(value) {
|
|
47
|
+
const request = object(value);
|
|
48
|
+
if (Object.keys(request).length !== 1 || typeof request.sessionId !== "string" || !/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(request.sessionId)) throw new Error("invalid session id");
|
|
49
|
+
return { sessionId: request.sessionId };
|
|
50
|
+
}
|
|
51
|
+
function parseView(value) {
|
|
52
|
+
if (value === null) return null;
|
|
53
|
+
const view = object(value);
|
|
54
|
+
const keys = ["sessionId", "taskId", "runId", "bindingEpoch", "revision", "phase", "uploadedAtMs", "lastSyncedAtMs"];
|
|
55
|
+
if (Object.keys(view).length !== keys.length || keys.some((key) => !Object.hasOwn(view, key))) throw new Error("invalid sync view");
|
|
56
|
+
const { sessionId } = parseRequest({ sessionId: view.sessionId });
|
|
57
|
+
const integer = (value2) => {
|
|
58
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) throw new Error("invalid sync identity");
|
|
59
|
+
return value2;
|
|
60
|
+
};
|
|
61
|
+
const phase = view.phase;
|
|
62
|
+
if (phase !== "checking" && phase !== "synced" && phase !== "dirty" && phase !== "uploading" && phase !== "failed" && phase !== "unknown") throw new Error("invalid sync phase");
|
|
63
|
+
const uploadedAtMs = view.uploadedAtMs;
|
|
64
|
+
if (uploadedAtMs !== null && (typeof uploadedAtMs !== "number" || !Number.isSafeInteger(uploadedAtMs) || uploadedAtMs <= 0)) throw new Error("invalid sync timestamp");
|
|
65
|
+
const lastSyncedAtMs = view.lastSyncedAtMs;
|
|
66
|
+
if (lastSyncedAtMs !== null && (typeof lastSyncedAtMs !== "number" || !Number.isSafeInteger(lastSyncedAtMs) || lastSyncedAtMs <= 0)) throw new Error("invalid sync timestamp");
|
|
67
|
+
return { sessionId, taskId: integer(view.taskId), runId: integer(view.runId), bindingEpoch: integer(view.bindingEpoch), revision: integer(view.revision), phase, uploadedAtMs, lastSyncedAtMs };
|
|
68
|
+
}
|
|
69
|
+
var descriptors = ["inspect", "sync"].map((method) => ({
|
|
70
|
+
id: `dsh-crowdtest#crowdtestSync/${method}`,
|
|
71
|
+
service: "crowdtestSync",
|
|
72
|
+
namespace: "crowdtestSync",
|
|
73
|
+
method,
|
|
74
|
+
invocation: { kind: "direct" },
|
|
75
|
+
parameters: [{ name: "request", wire: "request", source: "json", codec: { mode: "strict", typeSymbol: "SyncRequest", create: () => ({ parse: parseRequest }) } }],
|
|
76
|
+
cancellation: { parameter: "signal" },
|
|
77
|
+
result: { mode: "strict", typeSymbol: "SyncView", create: () => ({ parse: parseView }), decode: parseView }
|
|
78
|
+
}));
|
|
79
|
+
var contribution = { package: "dsh-crowdtest", descriptors };
|
|
80
|
+
|
|
81
|
+
// src/client/sync-source.ts
|
|
82
|
+
function createSyncSource(deps) {
|
|
83
|
+
let snapshot = null;
|
|
84
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
85
|
+
let generation = 0;
|
|
86
|
+
let mutation = 0;
|
|
87
|
+
let authority = null;
|
|
88
|
+
let abort = new AbortController();
|
|
89
|
+
let timer;
|
|
90
|
+
let disposeReset;
|
|
91
|
+
let disposeActivation;
|
|
92
|
+
let pending;
|
|
93
|
+
const publish = (value, authoritative = false) => {
|
|
94
|
+
if (authoritative && authority && value && (value.bindingEpoch < authority.bindingEpoch || value.bindingEpoch === authority.bindingEpoch && value.revision < authority.revision)) return;
|
|
95
|
+
if (authoritative) authority = value;
|
|
96
|
+
snapshot = value;
|
|
97
|
+
for (const listener of listeners) listener();
|
|
98
|
+
};
|
|
99
|
+
const unknown = () => {
|
|
100
|
+
if (snapshot) publish({ ...snapshot, phase: "unknown" });
|
|
101
|
+
};
|
|
102
|
+
const schedule = () => {
|
|
103
|
+
if (!listeners.size) return;
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
timer = setTimeout(() => {
|
|
106
|
+
void read();
|
|
107
|
+
}, deps.pollMs ?? 5e3);
|
|
108
|
+
};
|
|
109
|
+
const read = async () => {
|
|
110
|
+
if (pending || !listeners.size) return;
|
|
111
|
+
if (deps.visible?.() === false) {
|
|
112
|
+
schedule();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const started = generation;
|
|
116
|
+
const startedMutation = mutation;
|
|
117
|
+
const operation = (async () => {
|
|
118
|
+
try {
|
|
119
|
+
const result = await deps.inspect(abort.signal);
|
|
120
|
+
if (started !== generation || startedMutation !== mutation) return;
|
|
121
|
+
if (result.ok && result.value !== void 0) publish(result.value, true);
|
|
122
|
+
else unknown();
|
|
123
|
+
} catch {
|
|
124
|
+
if (started === generation && startedMutation === mutation) unknown();
|
|
125
|
+
}
|
|
126
|
+
})().finally(() => {
|
|
127
|
+
if (pending === operation) pending = void 0;
|
|
128
|
+
if (started === generation) schedule();
|
|
129
|
+
});
|
|
130
|
+
pending = operation;
|
|
131
|
+
await operation;
|
|
132
|
+
};
|
|
133
|
+
const reset = () => {
|
|
134
|
+
generation++;
|
|
135
|
+
abort.abort();
|
|
136
|
+
abort = new AbortController();
|
|
137
|
+
pending = void 0;
|
|
138
|
+
authority = null;
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
if (snapshot) publish({ ...snapshot, phase: "checking" });
|
|
141
|
+
void read();
|
|
142
|
+
};
|
|
143
|
+
const stop = () => {
|
|
144
|
+
generation++;
|
|
145
|
+
abort.abort();
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
disposeReset?.();
|
|
148
|
+
disposeActivation?.();
|
|
149
|
+
pending = void 0;
|
|
150
|
+
snapshot = null;
|
|
151
|
+
authority = null;
|
|
152
|
+
deps.onActive?.(false);
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
getSnapshot: () => snapshot,
|
|
156
|
+
subscribe(listener) {
|
|
157
|
+
listeners.add(listener);
|
|
158
|
+
if (listeners.size === 1) {
|
|
159
|
+
abort = new AbortController();
|
|
160
|
+
deps.onActive?.(true);
|
|
161
|
+
disposeReset = deps.subscribeReset(reset);
|
|
162
|
+
disposeActivation = deps.subscribeActivation?.(reset);
|
|
163
|
+
void read();
|
|
164
|
+
}
|
|
165
|
+
return () => {
|
|
166
|
+
listeners.delete(listener);
|
|
167
|
+
if (!listeners.size) stop();
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
async sync() {
|
|
171
|
+
if (snapshot?.phase === "uploading" || !listeners.size) return;
|
|
172
|
+
const started = generation;
|
|
173
|
+
const startedBinding = snapshot?.bindingEpoch;
|
|
174
|
+
mutation++;
|
|
175
|
+
if (snapshot) publish({ ...snapshot, phase: "uploading" });
|
|
176
|
+
try {
|
|
177
|
+
const result = await deps.sync(abort.signal);
|
|
178
|
+
if (started !== generation) return;
|
|
179
|
+
if (result.ok && result.value !== void 0) {
|
|
180
|
+
if (result.value !== null || snapshot?.bindingEpoch === startedBinding) publish(result.value, true);
|
|
181
|
+
} else if (snapshot && snapshot.bindingEpoch === startedBinding) publish({ ...snapshot, phase: "failed" });
|
|
182
|
+
} catch {
|
|
183
|
+
if (started === generation && snapshot && snapshot.bindingEpoch === startedBinding) publish({ ...snapshot, phase: "failed" });
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
dispose() {
|
|
187
|
+
stop();
|
|
188
|
+
listeners.clear();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/client/sync-dock.tsx
|
|
194
|
+
var import_react = __toESM(require("react"), 1);
|
|
195
|
+
|
|
196
|
+
// src/client/sync-presentation.ts
|
|
197
|
+
var SYNC_PRESENTATION = {
|
|
198
|
+
checking: { label: "\u68C0\u67E5\u4E2D", action: "\u7ACB\u5373\u540C\u6B65", tone: "neutral", busy: false },
|
|
199
|
+
synced: { label: "\u5DF2\u540C\u6B65", action: "\u7ACB\u5373\u540C\u6B65", tone: "success", busy: false },
|
|
200
|
+
dirty: { label: "\u6709\u65B0\u5185\u5BB9\u5F85\u540C\u6B65", action: "\u7ACB\u5373\u540C\u6B65", tone: "pending", busy: false },
|
|
201
|
+
uploading: { label: "\u540C\u6B65\u4E2D", action: "\u540C\u6B65\u4E2D", tone: "pending", busy: true },
|
|
202
|
+
failed: { label: "\u540C\u6B65\u5931\u8D25", action: "\u91CD\u65B0\u540C\u6B65", tone: "warning", busy: false },
|
|
203
|
+
unknown: { label: "\u65E0\u6CD5\u786E\u8BA4", action: "\u91CD\u65B0\u540C\u6B65", tone: "warning", busy: false }
|
|
204
|
+
};
|
|
205
|
+
function formatLastSync(syncedAtMs, nowMs) {
|
|
206
|
+
if (syncedAtMs === null) return "\u5C1A\u672A\u540C\u6B65";
|
|
207
|
+
const elapsedSeconds = Math.max(0, Math.floor((nowMs - syncedAtMs) / 1e3));
|
|
208
|
+
const seconds = elapsedSeconds % 60;
|
|
209
|
+
const minutes = Math.floor(elapsedSeconds / 60) % 60;
|
|
210
|
+
const hours = Math.floor(elapsedSeconds / 3600);
|
|
211
|
+
const age = hours > 0 ? `${hours}h ${minutes}m ${seconds}s` : elapsedSeconds >= 60 ? `${minutes}m ${seconds}s` : `${seconds}s`;
|
|
212
|
+
return `\u4E0A\u6B21\u540C\u6B65 \xB7 ${age} \u524D`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/client/sync-dock.tsx
|
|
216
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
217
|
+
var styles = `
|
|
218
|
+
[data-crowdtest-sync] {
|
|
219
|
+
box-sizing: border-box;
|
|
220
|
+
display: flex;
|
|
221
|
+
flex-wrap: wrap;
|
|
222
|
+
align-items: center;
|
|
223
|
+
gap: 8px 16px;
|
|
224
|
+
width: calc(100% - 2 * var(--dsh-composer-side-clearance, 16px));
|
|
225
|
+
max-width: var(--dsh-composer-card-max-width, 952px);
|
|
226
|
+
margin: 0 auto calc(-1 * var(--dsh-composer-stack-gap, 6px));
|
|
227
|
+
padding: 10px 14px;
|
|
228
|
+
border: 1px solid var(--dsw-alias-border-l2, #dfe2e8);
|
|
229
|
+
border-radius: var(--dsw-radius-panel, 16px) var(--dsw-radius-panel, 16px) 0 0;
|
|
230
|
+
background: color-mix(in srgb, var(--dsw-specific-input-major, #fff) 96%, var(--dsw-alias-label-primary, #25282f) 4%);
|
|
231
|
+
color: var(--dsw-alias-label-primary, #25282f);
|
|
232
|
+
font-family: var(--dsw-font-family, inherit);
|
|
233
|
+
font-size: 12px;
|
|
234
|
+
line-height: 20px;
|
|
235
|
+
}
|
|
236
|
+
[data-crowdtest-sync] .crowdtest-sync-identity {
|
|
237
|
+
display: flex;
|
|
238
|
+
flex: 1 1 auto;
|
|
239
|
+
flex-wrap: wrap;
|
|
240
|
+
align-items: baseline;
|
|
241
|
+
gap: 2px 12px;
|
|
242
|
+
min-width: 0;
|
|
243
|
+
}
|
|
244
|
+
[data-crowdtest-sync] strong { font-size: 13px; font-weight: 600; }
|
|
245
|
+
[data-crowdtest-sync] .crowdtest-sync-meta {
|
|
246
|
+
color: var(--dsw-alias-label-secondary, #666d79);
|
|
247
|
+
overflow-wrap: anywhere;
|
|
248
|
+
}
|
|
249
|
+
[data-crowdtest-sync] .crowdtest-sync-actions {
|
|
250
|
+
display: flex;
|
|
251
|
+
flex-wrap: wrap;
|
|
252
|
+
align-items: center;
|
|
253
|
+
justify-content: flex-end;
|
|
254
|
+
gap: 6px 12px;
|
|
255
|
+
margin-left: auto;
|
|
256
|
+
}
|
|
257
|
+
[data-crowdtest-sync] .crowdtest-sync-age {
|
|
258
|
+
color: var(--dsw-alias-label-tertiary, #858b97);
|
|
259
|
+
font-size: 11px;
|
|
260
|
+
font-variant-numeric: tabular-nums;
|
|
261
|
+
white-space: nowrap;
|
|
262
|
+
}
|
|
263
|
+
[data-crowdtest-sync] .crowdtest-sync-status {
|
|
264
|
+
color: var(--dsw-alias-label-secondary, #666d79);
|
|
265
|
+
white-space: nowrap;
|
|
266
|
+
}
|
|
267
|
+
[data-crowdtest-sync] [data-tone="success"] { color: var(--dsw-alias-state-success-primary, #299866); }
|
|
268
|
+
[data-crowdtest-sync] [data-tone="pending"] { color: var(--dsw-alias-state-business-primary, #3964fe); }
|
|
269
|
+
[data-crowdtest-sync] [data-tone="warning"] { color: var(--dsw-alias-state-warn-label, #ba7429); }
|
|
270
|
+
[data-crowdtest-sync] button {
|
|
271
|
+
min-height: 28px;
|
|
272
|
+
padding: 3px 14px;
|
|
273
|
+
border: 0;
|
|
274
|
+
border-radius: 999px;
|
|
275
|
+
background: color-mix(in srgb, var(--dsw-alias-state-business-primary, #3964fe) 10%, transparent);
|
|
276
|
+
color: var(--dsw-alias-state-business-primary, #3964fe);
|
|
277
|
+
font: inherit;
|
|
278
|
+
font-weight: 500;
|
|
279
|
+
white-space: nowrap;
|
|
280
|
+
cursor: pointer;
|
|
281
|
+
transition: background-color 120ms ease;
|
|
282
|
+
}
|
|
283
|
+
[data-crowdtest-sync] button:hover:not(:disabled) {
|
|
284
|
+
background: color-mix(in srgb, var(--dsw-alias-state-business-primary, #3964fe) 18%, transparent);
|
|
285
|
+
}
|
|
286
|
+
[data-crowdtest-sync] button:focus-visible {
|
|
287
|
+
outline: 2px solid var(--dsw-alias-state-business-primary, #3964fe);
|
|
288
|
+
outline-offset: 2px;
|
|
289
|
+
}
|
|
290
|
+
[data-crowdtest-sync] button:disabled { opacity: .55; cursor: default; }
|
|
291
|
+
[data-slot="conversation.input.dock"]:has([data-crowdtest-sync]) + [data-slot="conversation.composer.bar"] [data-composer-card] {
|
|
292
|
+
border-top-left-radius: 0;
|
|
293
|
+
border-top-right-radius: 0;
|
|
294
|
+
}
|
|
295
|
+
@media (prefers-reduced-motion: reduce) {
|
|
296
|
+
[data-crowdtest-sync] button { transition: none; }
|
|
297
|
+
}
|
|
298
|
+
`;
|
|
299
|
+
function LastSuccessfulSync({ lastSyncedAtMs, uploadedAtMs }) {
|
|
300
|
+
const [nowMs, setNowMs] = import_react.default.useState(Date.now);
|
|
301
|
+
import_react.default.useEffect(() => {
|
|
302
|
+
const timer = setInterval(() => {
|
|
303
|
+
setNowMs(Date.now());
|
|
304
|
+
}, 1e3);
|
|
305
|
+
return () => {
|
|
306
|
+
clearInterval(timer);
|
|
307
|
+
};
|
|
308
|
+
}, []);
|
|
309
|
+
const title = `\u540C\u6B65\u786E\u8BA4\u65F6\u95F4\uFF1A${lastSyncedAtMs === null ? "\u672A\u8BB0\u5F55" : new Date(lastSyncedAtMs).toLocaleString()}
|
|
310
|
+
\u5907\u4EFD\u4E0A\u4F20\u65F6\u95F4\uFF1A${uploadedAtMs === null ? "\u672A\u77E5" : new Date(uploadedAtMs).toLocaleString()}`;
|
|
311
|
+
if (lastSyncedAtMs === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "crowdtest-sync-age", title, children: uploadedAtMs === null ? formatLastSync(null, 0) : "\u5C1A\u65E0\u540C\u6B65\u786E\u8BA4\u8BB0\u5F55" });
|
|
312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("time", { className: "crowdtest-sync-age", dateTime: new Date(lastSyncedAtMs).toISOString(), title, children: formatLastSync(lastSyncedAtMs, nowMs) });
|
|
313
|
+
}
|
|
314
|
+
function CrowdtestDock({ useCrowdtestSync, onSync }) {
|
|
315
|
+
const view = useCrowdtestSync((value) => value);
|
|
316
|
+
return view === null ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BoundCrowdtestDock, { view, onSync }, `${view.sessionId}:${view.taskId}:${view.runId}:${view.bindingEpoch}`);
|
|
317
|
+
}
|
|
318
|
+
function BoundCrowdtestDock({ view, onSync }) {
|
|
319
|
+
const [action, setAction] = import_react.default.useState(null);
|
|
320
|
+
const request = import_react.default.useRef(0);
|
|
321
|
+
import_react.default.useLayoutEffect(() => () => {
|
|
322
|
+
request.current++;
|
|
323
|
+
}, []);
|
|
324
|
+
import_react.default.useLayoutEffect(() => {
|
|
325
|
+
if (view.phase !== "synced" && view.phase !== "uploading") {
|
|
326
|
+
request.current++;
|
|
327
|
+
setAction(null);
|
|
328
|
+
} else if (view.phase === "uploading") {
|
|
329
|
+
setAction((current) => current?.kind === "completed" ? null : current);
|
|
330
|
+
}
|
|
331
|
+
}, [view.phase, view.revision]);
|
|
332
|
+
import_react.default.useLayoutEffect(() => {
|
|
333
|
+
if (action?.kind === "settled" && view.phase === "synced") {
|
|
334
|
+
setAction({ kind: "completed", message: view.uploadedAtMs === action.uploadedAtMs ? "\u5DF2\u662F\u6700\u65B0" : "\u540C\u6B65\u5B8C\u6210" });
|
|
335
|
+
}
|
|
336
|
+
}, [action, view]);
|
|
337
|
+
const presentation = SYNC_PRESENTATION[view.phase];
|
|
338
|
+
const hasSyncHistory = view.lastSyncedAtMs !== null || view.uploadedAtMs !== null;
|
|
339
|
+
const label = view.phase === "dirty" && !hasSyncHistory ? "\u5C1A\u672A\u540C\u6B65" : presentation.label;
|
|
340
|
+
const busy = presentation.busy || action?.kind === "pending";
|
|
341
|
+
const sync = async () => {
|
|
342
|
+
const started = ++request.current;
|
|
343
|
+
const uploadedAtMs = view.uploadedAtMs;
|
|
344
|
+
setAction({ kind: "pending", uploadedAtMs });
|
|
345
|
+
try {
|
|
346
|
+
await onSync();
|
|
347
|
+
if (request.current === started) setAction({ kind: "settled", uploadedAtMs });
|
|
348
|
+
} catch {
|
|
349
|
+
if (request.current === started) setAction(null);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-label": "CrowdTest \u4F1A\u8BDD\u540C\u6B65", "data-crowdtest-sync": "", "data-session-id": view.sessionId, children: [
|
|
353
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: styles }),
|
|
354
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "crowdtest-sync-identity", children: [
|
|
355
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "CrowdTest" }),
|
|
356
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "crowdtest-sync-meta", children: [
|
|
357
|
+
"\u4EFB\u52A1 ",
|
|
358
|
+
view.taskId,
|
|
359
|
+
" \xB7 \u8FD0\u884C\u65F6 ",
|
|
360
|
+
view.runId
|
|
361
|
+
] })
|
|
362
|
+
] }),
|
|
363
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "crowdtest-sync-actions", children: [
|
|
364
|
+
(view.phase !== "dirty" || hasSyncHistory) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastSuccessfulSync, { lastSyncedAtMs: view.lastSyncedAtMs, uploadedAtMs: view.uploadedAtMs }, view.sessionId),
|
|
365
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "crowdtest-sync-status", "data-tone": presentation.tone, role: "status", "aria-live": "polite", children: action?.kind === "completed" && view.phase === "synced" ? action.message : label }),
|
|
366
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: busy, "aria-busy": busy, onClick: () => {
|
|
367
|
+
void sync();
|
|
368
|
+
}, children: busy ? "\u540C\u6B65\u4E2D" : presentation.action })
|
|
369
|
+
] })
|
|
370
|
+
] });
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/client/index.tsx
|
|
374
|
+
var inject = ["slots", "remote", "uiConversation"];
|
|
375
|
+
async function apply(ctx) {
|
|
376
|
+
await ctx.remote.$mount(contribution);
|
|
377
|
+
await ctx.inject(["remote.crowdtestSync"], (scope) => {
|
|
378
|
+
const sources = /* @__PURE__ */ new Set();
|
|
379
|
+
scope.effect(() => () => {
|
|
380
|
+
for (const source of sources) source.dispose();
|
|
381
|
+
sources.clear();
|
|
382
|
+
});
|
|
383
|
+
scope.slots.inject("conversation.input.dock", () => scope.slots.register({
|
|
384
|
+
name: "conversation.input.dock",
|
|
385
|
+
id: "crowdtest-sync",
|
|
386
|
+
order: 20,
|
|
387
|
+
inject: (sessionId) => {
|
|
388
|
+
const source = createSyncSource({
|
|
389
|
+
onActive: (active) => {
|
|
390
|
+
if (active) sources.add(source);
|
|
391
|
+
else sources.delete(source);
|
|
392
|
+
},
|
|
393
|
+
inspect: (signal) => scope.remote.crowdtestSync.inspect({ sessionId }, signal),
|
|
394
|
+
sync: (signal) => scope.remote.crowdtestSync.sync({ sessionId }, signal),
|
|
395
|
+
subscribeReset: (listener) => scope.on("connection/reset", listener),
|
|
396
|
+
visible: () => document.visibilityState !== "hidden",
|
|
397
|
+
subscribeActivation: (listener) => {
|
|
398
|
+
window.addEventListener("focus", listener);
|
|
399
|
+
document.addEventListener("visibilitychange", listener);
|
|
400
|
+
return () => {
|
|
401
|
+
window.removeEventListener("focus", listener);
|
|
402
|
+
document.removeEventListener("visibilitychange", listener);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
return { hooks: { crowdtestSync: source }, onSync: () => source.sync() };
|
|
407
|
+
}
|
|
408
|
+
}, CrowdtestDock));
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return module.exports; } });
|