@wanji_dsh/dsh-sales 0.9.7 → 0.10.0
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 +8 -4
- package/README.zh.md +8 -4
- package/dist/client.js +374 -97
- package/dist/host.js +1454 -776
- package/dist/types/update/activity.d.ts +28 -0
- package/dist/types/update/coordinator.d.ts +44 -0
- package/dist/types/update/guard.d.ts +3 -0
- package/dist/types/update/integration.d.ts +6 -0
- package/dist/types/update/manager.d.ts +13 -0
- package/dist/types/update/routes.d.ts +6 -0
- package/dist/types/update/state.d.ts +13 -0
- package/dist/types/update/types.d.ts +88 -0
- package/dist/types/update/version.d.ts +1 -0
- package/dist/types/wechat/service.d.ts +4 -0
- package/docs/auto-update.md +41 -0
- package/package.json +3 -2
- package/runtime/wechat-manifest.json +1 -1
package/dist/client.js
CHANGED
|
@@ -37,8 +37,37 @@ __export(client_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(client_exports);
|
|
39
39
|
|
|
40
|
-
// src/
|
|
40
|
+
// src/update/panel.tsx
|
|
41
41
|
var import_react = __toESM(require("react"), 1);
|
|
42
|
+
var labels = { idle: "updateIdle", checking: "updateChecking", available: "updateAvailable", "waiting-idle": "updateWaiting", preparing: "updatePreparing", installing: "updateInstalling", verifying: "updateVerifying", "restart-required": "updateRestart", updated: "updateUpdated", failed: "updateFailed", "recovery-required": "updateRecovery", unsupported: "updateUnsupported", "migration-required": "updateMigration" };
|
|
43
|
+
function updateErrorKey(error) {
|
|
44
|
+
if (["registry-install-required", "manager-api-unavailable", "manager-unavailable", "bundle-not-active"].includes(error)) return;
|
|
45
|
+
if (/STATE_INVALID|RESULT_UNKNOWN|STATE_CHANGED/.test(error)) return "updateStateError";
|
|
46
|
+
if (/WECHAT_COMPONENT|WECHAT_RUNTIME/.test(error)) return "updateRuntime";
|
|
47
|
+
if (/SAVE|WINDOW|PREPAR|BUSY/.test(error)) return "updateSave";
|
|
48
|
+
if (/NETWORK|TIMEOUT|TIMEOUTERROR|ABORTERROR/i.test(error)) return "updateNetwork";
|
|
49
|
+
if (/SERVICE_UNAVAILABLE|offline/i.test(error)) return "updateReconnect";
|
|
50
|
+
return "updateUnknown";
|
|
51
|
+
}
|
|
52
|
+
function UpdatePanel({ client, view, t }) {
|
|
53
|
+
const [open, setOpen] = (0, import_react.useState)(false), id = (0, import_react.useId)();
|
|
54
|
+
const checking = Boolean(view.checking) || view.phase === "checking";
|
|
55
|
+
const busy = view.preparing || checking || ["preparing", "installing", "verifying"].includes(view.phase);
|
|
56
|
+
const unavailable = ["unsupported", "migration-required", "recovery-required", "restart-required"].includes(view.phase);
|
|
57
|
+
const needsSetup = ["unsupported", "migration-required"].includes(view.phase);
|
|
58
|
+
const status = t(checking ? "updateChecking" : view.phase === "idle" && !view.checkedAt ? "updateInitial" : labels[view.phase]);
|
|
59
|
+
const errorKey = view.error ? updateErrorKey(view.error) : void 0;
|
|
60
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "ws-update", onKeyDown: (e) => {
|
|
61
|
+
if (e.key === "Escape") setOpen(false);
|
|
62
|
+
} }, /* @__PURE__ */ import_react.default.createElement("button", { className: "ws-button ws-update-trigger", type: "button", "aria-expanded": open, "aria-controls": id, onClick: () => setOpen((v) => !v) }, /* @__PURE__ */ import_react.default.createElement("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", "aria-hidden": "true" }, /* @__PURE__ */ import_react.default.createElement("path", { d: "M20 7v5h-5M4 17v-5h5M6 7a7 7 0 0 1 12-1l2 2M18 17a7 7 0 0 1-12 1l-2-2" })), t("updateTitle"), view.phase !== "idle" && view.phase !== "updated" && /* @__PURE__ */ import_react.default.createElement("span", { className: "ws-dot", "aria-label": status })), open && /* @__PURE__ */ import_react.default.createElement("section", { id, className: "ws-update-card", "aria-label": t("updateTitle") }, /* @__PURE__ */ import_react.default.createElement("div", { className: "ws-update-heading" }, /* @__PURE__ */ import_react.default.createElement("strong", null, t("updateTitle")), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ws-icon-button", "aria-label": t("updateClose"), onClick: () => setOpen(false) }, "\xD7")), /* @__PURE__ */ import_react.default.createElement("dl", { className: "ws-update-versions" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("dt", null, t("updateCurrent")), /* @__PURE__ */ import_react.default.createElement("dd", null, view.runningVersion || "\u2014")), view.installedVersion && view.installedVersion !== view.runningVersion && /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("dt", null, t("updateInstalled")), /* @__PURE__ */ import_react.default.createElement("dd", null, view.installedVersion)), view.candidate && view.candidate.version !== view.installedVersion && /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("dt", null, t("updateTarget")), /* @__PURE__ */ import_react.default.createElement("dd", null, view.candidate.version))), /* @__PURE__ */ import_react.default.createElement("div", { role: "status", className: "ws-update-status", "aria-live": "polite" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "ws-dot" }), status), errorKey && /* @__PURE__ */ import_react.default.createElement("p", { className: "ws-update-error", role: "status" }, t(errorKey)), !needsSetup && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("label", { className: "ws-update-toggle" }, /* @__PURE__ */ import_react.default.createElement("input", { type: "checkbox", checked: view.automatic, disabled: busy || unavailable, onChange: (e) => void client.action("automatic", e.target.checked) }), /* @__PURE__ */ import_react.default.createElement("span", null, t("updateAutomatic"))), /* @__PURE__ */ import_react.default.createElement("p", { className: "ws-update-policy" }, t("updatePolicy"))), view.checkedAt && !needsSetup && /* @__PURE__ */ import_react.default.createElement("p", { className: "ws-update-policy" }, t("updateChecked"), " ", /* @__PURE__ */ import_react.default.createElement("time", { dateTime: new Date(view.checkedAt).toISOString() }, new Date(view.checkedAt).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", second: "2-digit" }))), /* @__PURE__ */ import_react.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ws-button", disabled: busy || unavailable, "aria-busy": checking, onClick: () => void client.action("check") }, t(checking ? "updateChecking" : unavailable ? "updateCheckUnavailable" : "updateCheck")), view.candidate && !unavailable && /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ws-button ws-primary", disabled: busy, onClick: () => void client.action("install") }, t("updateInstall")))));
|
|
63
|
+
}
|
|
64
|
+
var updateStyles = `
|
|
65
|
+
.ws-update{-webkit-app-region:no-drag}.ws-update-card{position:absolute;right:24px;top:78px;z-index:15;width:340px;max-width:calc(100% - 24px);max-height:calc(100% - 92px);overflow:auto;padding:18px;background:var(--ws-bg);border:1px solid var(--ws-line);border-radius:12px;box-shadow:0 12px 36px #00000018;text-align:left}.ws-update-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}.ws-update-heading strong{font-size:14px}.ws-update-versions{display:grid;gap:8px}.ws-update-versions>div{display:flex;align-items:center;justify-content:space-between}.ws-update-versions dt{color:var(--ws-muted);font-size:12px}.ws-update-versions dd{font-variant-numeric:tabular-nums;font-family:ui-monospace,monospace;font-size:12px}.ws-update-status{display:flex;align-items:baseline;gap:7px;padding:12px 0;line-height:1.6;font-size:12px}.ws-update-status .ws-dot{align-self:center}.ws-update-toggle{display:flex;align-items:center;gap:9px;border-top:1px solid var(--ws-line);padding-top:14px;font-size:12px;cursor:pointer}.ws-update-toggle input{width:16px;height:16px;margin:0;accent-color:var(--ws-accent)}.ws-update-card .ws-update-policy{font-size:11px;color:var(--ws-muted);line-height:1.7;margin-top:7px}.ws-update-card .ws-update-error{font-size:12px;margin-bottom:12px;overflow-wrap:anywhere}.ws-update-actions{display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px;margin-top:18px}.ws-update-freeze{padding:8px 28px;border-top:1px solid var(--ws-line);background:var(--ws-soft);font-size:12px;flex:none}.ws-update-trigger .ws-dot{color:var(--ws-accent)}
|
|
66
|
+
@container(max-width:540px){.ws-header{flex-wrap:wrap}.ws-header-actions{margin-left:auto;gap:8px}.ws-update-card{top:120px;right:12px;max-height:calc(100% - 132px)}}
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
// src/wechat/avatar.tsx
|
|
70
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
42
71
|
|
|
43
72
|
// src/wechat/avatar-cache.ts
|
|
44
73
|
function createAvatarCache(load, decode, now = Date.now, timeoutMs = 15e3) {
|
|
@@ -134,12 +163,12 @@ function cacheFor(client) {
|
|
|
134
163
|
return cache;
|
|
135
164
|
}
|
|
136
165
|
function WechatAvatar({ client, scope, owner, mediaId, fallback, className = "" }) {
|
|
137
|
-
return client ? /* @__PURE__ */
|
|
166
|
+
return client ? /* @__PURE__ */ import_react2.default.createElement(LoadedAvatar, { key: JSON.stringify([scope, owner]), client, identity: JSON.stringify([scope, owner]), mediaId, fallback, className }) : /* @__PURE__ */ import_react2.default.createElement("span", { className: `ws-avatar ${className}` }, fallback);
|
|
138
167
|
}
|
|
139
168
|
function LoadedAvatar({ client, identity, mediaId, fallback, className }) {
|
|
140
|
-
const cache = cacheFor(client), element = (0,
|
|
141
|
-
const url = (0,
|
|
142
|
-
(0,
|
|
169
|
+
const cache = cacheFor(client), element = (0, import_react2.useRef)(null);
|
|
170
|
+
const url = (0, import_react2.useSyncExternalStore)(cache.subscribe, () => cache.peek(identity), () => void 0);
|
|
171
|
+
(0, import_react2.useEffect)(() => {
|
|
143
172
|
if (!mediaId) return;
|
|
144
173
|
let visible = false;
|
|
145
174
|
const refresh = () => {
|
|
@@ -160,11 +189,11 @@ function LoadedAvatar({ client, identity, mediaId, fallback, className }) {
|
|
|
160
189
|
clearInterval(timer);
|
|
161
190
|
};
|
|
162
191
|
}, [cache, identity, mediaId]);
|
|
163
|
-
return /* @__PURE__ */
|
|
192
|
+
return /* @__PURE__ */ import_react2.default.createElement("span", { ref: element, className: `ws-avatar ${className}` }, url ? /* @__PURE__ */ import_react2.default.createElement("img", { className: "ws-avatar-image", src: url, alt: "", draggable: false }) : fallback);
|
|
164
193
|
}
|
|
165
194
|
|
|
166
195
|
// src/wechat/sync-panel.tsx
|
|
167
|
-
var
|
|
196
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
168
197
|
|
|
169
198
|
// src/wechat/types.ts
|
|
170
199
|
var WECHAT_METHOD = "wanji-sales-wechat/request";
|
|
@@ -181,6 +210,7 @@ function createWechatClient(rpc, snapshot, options = {}) {
|
|
|
181
210
|
const answered = /* @__PURE__ */ new Set();
|
|
182
211
|
const automaticAttempts = /* @__PURE__ */ new Set();
|
|
183
212
|
const saves = /* @__PURE__ */ new Map();
|
|
213
|
+
const saveErrors = /* @__PURE__ */ new Map();
|
|
184
214
|
const listeners = /* @__PURE__ */ new Set(), controllers = /* @__PURE__ */ new Set();
|
|
185
215
|
const publish = (patch) => {
|
|
186
216
|
view = { ...view, ...patch };
|
|
@@ -301,19 +331,28 @@ function createWechatClient(rpc, snapshot, options = {}) {
|
|
|
301
331
|
return request("bind", { contactId, binding });
|
|
302
332
|
},
|
|
303
333
|
async save(contactId, state) {
|
|
304
|
-
const e = epoch;
|
|
305
|
-
const next = (saves.get(
|
|
334
|
+
const e = epoch, key = JSON.stringify([workspace, contactId]);
|
|
335
|
+
const next = (saves.get(key) ?? Promise.resolve()).catch(() => {
|
|
306
336
|
}).then(() => {
|
|
307
|
-
if (e !== epoch || disposed)
|
|
337
|
+
if (e !== epoch || disposed) throw Error("WECHAT_SAVE_NOT_CONFIRMED");
|
|
308
338
|
return request("save-state", { contactId, state });
|
|
309
339
|
});
|
|
310
|
-
saves.set(
|
|
340
|
+
saves.set(key, next);
|
|
311
341
|
try {
|
|
312
|
-
|
|
342
|
+
const value = await next;
|
|
343
|
+
saveErrors.delete(key);
|
|
344
|
+
return value;
|
|
345
|
+
} catch (error) {
|
|
346
|
+
saveErrors.set(key, error);
|
|
347
|
+
throw error;
|
|
313
348
|
} finally {
|
|
314
|
-
if (saves.get(
|
|
349
|
+
if (saves.get(key) === next) saves.delete(key);
|
|
315
350
|
}
|
|
316
351
|
},
|
|
352
|
+
async flush() {
|
|
353
|
+
while (saves.size) await Promise.allSettled([...saves.values()]);
|
|
354
|
+
if (saveErrors.size) throw Error("WECHAT_SAVE_NOT_CONFIRMED");
|
|
355
|
+
},
|
|
317
356
|
async handled(contactId) {
|
|
318
357
|
return request("handled", { contactId });
|
|
319
358
|
},
|
|
@@ -344,7 +383,7 @@ function startWechatMediaLoad(mediaId, load, publish) {
|
|
|
344
383
|
}
|
|
345
384
|
|
|
346
385
|
// src/wechat/runtime-panel.tsx
|
|
347
|
-
var
|
|
386
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
348
387
|
var phases = { idle: "wxRuntimeChecking", checking: "wxRuntimeChecking", waiting: "wxRuntimeWaiting", downloading: "wxRuntimeDownloading", verifying: "wxRuntimeVerifying", extracting: "wxRuntimeExtracting", "self-test": "wxRuntimeTesting", ready: "wxRuntimeReady", error: "wxRuntimeFailed", unsupported: "wxRuntimeUnsupported" };
|
|
349
388
|
var errors = { WECHAT_RUNTIME_CHECKSUM: "wxRuntimeChecksum", WECHAT_RUNTIME_COMPONENT: "wxRuntimeInvalid", WECHAT_RUNTIME_ARCHIVE: "wxRuntimeInvalid", WECHAT_RUNTIME_SELF_TEST: "wxRuntimeSelfTest", WECHAT_RUNTIME_MANIFEST: "wxRuntimeInvalid", WECHAT_RUNTIME_URL: "wxRuntimeInvalid", WECHAT_RUNTIME_CACHE: "wxRuntimeCache", WECHAT_RUNTIME_TIMEOUT: "wxRuntimeTimeout", WECHAT_RUNTIME_ABORTED: "wxRuntimeAborted" };
|
|
350
389
|
function runtimePercent(runtime) {
|
|
@@ -354,11 +393,11 @@ function RuntimePanel({ runtime, t, retry, disabled }) {
|
|
|
354
393
|
const failed = runtime.phase === "error", unsupported = runtime.phase === "unsupported", percent = runtimePercent(runtime);
|
|
355
394
|
const number2 = new Intl.NumberFormat(void 0, { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
|
356
395
|
const amount = number2.format(runtime.received / 1e6) + (runtime.total ? " / " + number2.format(runtime.total / 1e6) : "") + " " + t("wxRuntimeMB");
|
|
357
|
-
return /* @__PURE__ */
|
|
396
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { className: "ws-runtime-panel", role: failed ? "alert" : "status" }, /* @__PURE__ */ import_react3.default.createElement("div", { className: "ws-runtime-line" }, /* @__PURE__ */ import_react3.default.createElement("span", null, t(phases[runtime.phase])), !failed && !unsupported && runtime.total && /* @__PURE__ */ import_react3.default.createElement("span", null, amount, percent !== void 0 ? " \xB7 " + percent + "%" : ""), failed && /* @__PURE__ */ import_react3.default.createElement("button", { className: "ws-text-button", disabled, onClick: retry }, t("wxRuntimeRetry"))), failed ? /* @__PURE__ */ import_react3.default.createElement("p", null, t(errors[runtime.errorCode ?? ""] ?? "wxRuntimeNetwork")) : !unsupported && /* @__PURE__ */ import_react3.default.createElement("span", { className: "ws-runtime-track", role: "progressbar", "aria-label": t(phases[runtime.phase]), "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent }, /* @__PURE__ */ import_react3.default.createElement("span", { style: { width: (percent ?? 0) + "%" } })));
|
|
358
397
|
}
|
|
359
398
|
|
|
360
399
|
// src/wechat/message-media.tsx
|
|
361
|
-
var
|
|
400
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
362
401
|
|
|
363
402
|
// src/wechat/voice-playback.ts
|
|
364
403
|
function voiceDurationLabel(seconds) {
|
|
@@ -399,7 +438,7 @@ var VoicePlaybackCoordinator = class {
|
|
|
399
438
|
var voicePlayback = new VoicePlaybackCoordinator();
|
|
400
439
|
|
|
401
440
|
// src/wechat/image-preview.tsx
|
|
402
|
-
var
|
|
441
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
403
442
|
|
|
404
443
|
// src/wechat/image-preview-geometry.ts
|
|
405
444
|
function fitImageScale(width, height, availableWidth, availableHeight) {
|
|
@@ -412,8 +451,8 @@ function clampImageScale(value, fit) {
|
|
|
412
451
|
|
|
413
452
|
// src/wechat/image-preview.tsx
|
|
414
453
|
function ImagePreview({ src, t, onClose, onError, returnFocus }) {
|
|
415
|
-
const dialog = (0,
|
|
416
|
-
const [natural, setNatural] = (0,
|
|
454
|
+
const dialog = (0, import_react4.useRef)(null), canvas = (0, import_react4.useRef)(null), fitted = (0, import_react4.useRef)(true), fit = (0, import_react4.useRef)(1);
|
|
455
|
+
const [natural, setNatural] = (0, import_react4.useState)({ width: 0, height: 0 }), [scale, setScale] = (0, import_react4.useState)(1);
|
|
417
456
|
const fitToCanvas = () => {
|
|
418
457
|
const el = canvas.current;
|
|
419
458
|
if (!el || !natural.width) return;
|
|
@@ -423,7 +462,7 @@ function ImagePreview({ src, t, onClose, onError, returnFocus }) {
|
|
|
423
462
|
el.scrollTo(0, 0);
|
|
424
463
|
}
|
|
425
464
|
};
|
|
426
|
-
(0,
|
|
465
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
427
466
|
const el = dialog.current;
|
|
428
467
|
el?.showModal();
|
|
429
468
|
return () => {
|
|
@@ -431,7 +470,7 @@ function ImagePreview({ src, t, onClose, onError, returnFocus }) {
|
|
|
431
470
|
if (returnFocus.current?.isConnected) returnFocus.current.focus({ preventScroll: true });
|
|
432
471
|
};
|
|
433
472
|
}, []);
|
|
434
|
-
(0,
|
|
473
|
+
(0, import_react4.useLayoutEffect)(() => {
|
|
435
474
|
fitToCanvas();
|
|
436
475
|
if (!canvas.current || typeof ResizeObserver === "undefined") return;
|
|
437
476
|
const observer = new ResizeObserver(fitToCanvas);
|
|
@@ -446,7 +485,7 @@ function ImagePreview({ src, t, onClose, onError, returnFocus }) {
|
|
|
446
485
|
fitted.current = true;
|
|
447
486
|
fitToCanvas();
|
|
448
487
|
};
|
|
449
|
-
return /* @__PURE__ */
|
|
488
|
+
return /* @__PURE__ */ import_react4.default.createElement("dialog", { ref: dialog, className: "ws-image-dialog", "aria-label": t("wxImagePreview"), onCancel: (event) => {
|
|
450
489
|
event.preventDefault();
|
|
451
490
|
onClose();
|
|
452
491
|
}, onClick: (event) => {
|
|
@@ -459,22 +498,22 @@ function ImagePreview({ src, t, onClose, onError, returnFocus }) {
|
|
|
459
498
|
if (event.key === "0") reset();
|
|
460
499
|
else zoom(event.key === "-" ? 1 / 1.25 : 1.25);
|
|
461
500
|
}
|
|
462
|
-
} }, /* @__PURE__ */
|
|
501
|
+
} }, /* @__PURE__ */ import_react4.default.createElement("header", { className: "ws-image-toolbar" }, /* @__PURE__ */ import_react4.default.createElement("strong", null, t("wxImagePreview")), /* @__PURE__ */ import_react4.default.createElement("div", { className: "ws-image-tools" }, /* @__PURE__ */ import_react4.default.createElement("button", { type: "button", disabled: !natural.width || scale <= Math.min(0.1, fit.current), "aria-label": t("wxImageZoomOut"), title: t("wxImageZoomOut"), onClick: () => zoom(1 / 1.25) }, "\u2212"), /* @__PURE__ */ import_react4.default.createElement("span", { className: "ws-image-scale", "aria-live": "polite" }, Math.round(scale * 100), "%"), /* @__PURE__ */ import_react4.default.createElement("button", { type: "button", disabled: !natural.width || scale >= 4, "aria-label": t("wxImageZoomIn"), title: t("wxImageZoomIn"), onClick: () => zoom(1.25) }, "+"), /* @__PURE__ */ import_react4.default.createElement("button", { type: "button", className: "ws-image-fit", disabled: !natural.width, onClick: reset }, t("wxImageFit")), /* @__PURE__ */ import_react4.default.createElement("button", { type: "button", className: "ws-image-close", autoFocus: true, "aria-label": t("wxClosePreview"), title: t("wxClosePreview"), onClick: onClose }, "\xD7"))), /* @__PURE__ */ import_react4.default.createElement("div", { className: "ws-image-canvas", ref: canvas }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "ws-image-stage" }, /* @__PURE__ */ import_react4.default.createElement("img", { src, alt: t("wxImageAlt"), draggable: false, style: natural.width ? { width: natural.width * scale, height: natural.height * scale } : void 0, onLoad: (event) => setNatural({ width: event.currentTarget.naturalWidth, height: event.currentTarget.naturalHeight }), onError }))));
|
|
463
502
|
}
|
|
464
503
|
|
|
465
504
|
// src/wechat/message-media.tsx
|
|
466
505
|
function WechatMessageBody({ message, client, revision: revision2, t }) {
|
|
467
506
|
const attachment = message.kind === "image" || message.kind === "voice" || message.kind === "audio";
|
|
468
507
|
const text = attachment ? /^\[(?:image|图片|(?:voice|audio|语音)(?:\s*\d+(?:\.\d+)?\s*(?:秒|s|["″”]))?)\]$/i.test(message.text?.trim() ?? "") ? "" : message.text : message.text || `[${message.kind}]`;
|
|
469
|
-
return /* @__PURE__ */
|
|
508
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, text && /* @__PURE__ */ import_react5.default.createElement("div", null, text), message.mediaId ? /* @__PURE__ */ import_react5.default.createElement(NativeMedia, { client, mediaId: message.mediaId, kind: message.kind, revision: revision2, t }) : attachment && (message.kind === "image" ? /* @__PURE__ */ import_react5.default.createElement("span", { className: "ws-media-placeholder" }, t("wxImagePending")) : /* @__PURE__ */ import_react5.default.createElement(VoicePlaceholder, { state: "pending", t })));
|
|
470
509
|
}
|
|
471
510
|
function NativeMedia(props) {
|
|
472
|
-
return /* @__PURE__ */
|
|
511
|
+
return /* @__PURE__ */ import_react5.default.createElement(MediaAttachment, { key: props.mediaId, ...props });
|
|
473
512
|
}
|
|
474
513
|
function MediaAttachment({ client, mediaId, kind, revision: revision2, t }) {
|
|
475
|
-
const [result, setResult] = (0,
|
|
476
|
-
const [retry, setRetry] = (0,
|
|
477
|
-
(0,
|
|
514
|
+
const [result, setResult] = (0, import_react5.useState)({ mediaId });
|
|
515
|
+
const [retry, setRetry] = (0, import_react5.useState)(0), element = (0, import_react5.useRef)(null), loaded = (0, import_react5.useRef)(false);
|
|
516
|
+
(0, import_react5.useEffect)(() => {
|
|
478
517
|
if (loaded.current) return;
|
|
479
518
|
let cancel, started = false;
|
|
480
519
|
const load = () => {
|
|
@@ -503,22 +542,22 @@ function MediaAttachment({ client, mediaId, kind, revision: revision2, t }) {
|
|
|
503
542
|
loaded.current = false;
|
|
504
543
|
setResult({ mediaId, error: "decode" });
|
|
505
544
|
};
|
|
506
|
-
return /* @__PURE__ */
|
|
545
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { ref: element, className: "ws-native-media" }, result.url ? result.url.startsWith("data:image/") ? /* @__PURE__ */ import_react5.default.createElement(ImageAttachment, { src: result.url, t, onError: failed }) : /* @__PURE__ */ import_react5.default.createElement(VoiceAttachment, { key: result.url, src: result.url, t, onError: failed }) : result.error ? kind === "voice" || kind === "audio" ? /* @__PURE__ */ import_react5.default.createElement(VoicePlaceholder, { state: "error", t, retry: () => setRetry((value) => value + 1) }) : /* @__PURE__ */ import_react5.default.createElement("span", { role: "status" }, t(kind === "image" ? "wxImageUnavailable" : "wxAudioUnavailable"), " ", /* @__PURE__ */ import_react5.default.createElement("button", { className: "ws-text-button", onClick: () => setRetry((value) => value + 1) }, t("wxMediaRetry"))) : kind === "voice" || kind === "audio" ? /* @__PURE__ */ import_react5.default.createElement(VoicePlaceholder, { state: "loading", t }) : /* @__PURE__ */ import_react5.default.createElement("span", { className: "ws-media-placeholder", role: "status" }, t("wxImageLoading")));
|
|
507
546
|
}
|
|
508
547
|
function ImageAttachment({ src, t, onError }) {
|
|
509
|
-
const [open, setOpen] = (0,
|
|
510
|
-
return /* @__PURE__ */
|
|
548
|
+
const [open, setOpen] = (0, import_react5.useState)(false), trigger = (0, import_react5.useRef)(null);
|
|
549
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("button", { ref: trigger, type: "button", className: "ws-image-trigger", "aria-label": t("wxImagePreview"), "aria-haspopup": "dialog", onClick: () => setOpen(true) }, /* @__PURE__ */ import_react5.default.createElement("img", { src, alt: t("wxImageAlt"), loading: "lazy", decoding: "async", onError })), open && /* @__PURE__ */ import_react5.default.createElement(ImagePreview, { src, t, onClose: () => setOpen(false), onError, returnFocus: trigger }));
|
|
511
550
|
}
|
|
512
551
|
function VoiceWaves() {
|
|
513
|
-
return /* @__PURE__ */
|
|
552
|
+
return /* @__PURE__ */ import_react5.default.createElement("svg", { className: "ws-voice-waves", width: "24", height: "25", viewBox: "0 0 24 25", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", "aria-hidden": "true" }, /* @__PURE__ */ import_react5.default.createElement("path", { d: "M5 11v3" }), /* @__PURE__ */ import_react5.default.createElement("path", { className: "ws-voice-wave-mid", d: "M10 7.5a9 9 0 0 1 0 10" }), /* @__PURE__ */ import_react5.default.createElement("path", { className: "ws-voice-wave-outer", d: "M15 3.5a15 15 0 0 1 0 18" }));
|
|
514
553
|
}
|
|
515
554
|
function VoicePlaceholder({ state, t, retry }) {
|
|
516
|
-
return /* @__PURE__ */
|
|
555
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { className: `ws-voice-placeholder is-${state}`, role: "status", title: t(state === "pending" ? "wxAudioPending" : state === "loading" ? "wxAudioLoading" : "wxAudioUnavailable") }, /* @__PURE__ */ import_react5.default.createElement(VoiceWaves, null), /* @__PURE__ */ import_react5.default.createElement("span", { className: "ws-voice-status" }, /* @__PURE__ */ import_react5.default.createElement("strong", null, t("wxVoiceMessage")), /* @__PURE__ */ import_react5.default.createElement("span", null, t(state === "pending" ? "wxVoicePending" : state === "loading" ? "wxAudioLoading" : "wxAudioUnavailable"))), retry && /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-text-button ws-voice-retry", onClick: retry }, t("wxMediaRetry")));
|
|
517
556
|
}
|
|
518
557
|
function VoiceAttachment({ src, t, onError }) {
|
|
519
|
-
const audio = (0,
|
|
520
|
-
const [playing, setPlaying] = (0,
|
|
521
|
-
(0,
|
|
558
|
+
const audio = (0, import_react5.useRef)(null), alive = (0, import_react5.useRef)(true);
|
|
559
|
+
const [playing, setPlaying] = (0, import_react5.useState)(false), [duration, setDuration] = (0, import_react5.useState)(), [playError, setPlayError] = (0, import_react5.useState)(false);
|
|
560
|
+
(0, import_react5.useEffect)(() => {
|
|
522
561
|
alive.current = true;
|
|
523
562
|
const element = audio.current;
|
|
524
563
|
return () => {
|
|
@@ -537,38 +576,38 @@ function VoiceAttachment({ src, t, onError }) {
|
|
|
537
576
|
}
|
|
538
577
|
};
|
|
539
578
|
const durationLabel = voiceDurationLabel(duration);
|
|
540
|
-
return /* @__PURE__ */
|
|
579
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-voice-message" }, /* @__PURE__ */ import_react5.default.createElement("audio", { ref: audio, hidden: true, preload: "metadata", src, onLoadedMetadata: (event) => setDuration(event.currentTarget.duration), onDurationChange: (event) => setDuration(event.currentTarget.duration), onPlaying: () => setPlaying(true), onPause: () => setPlaying(false), onEnded: (event) => {
|
|
541
580
|
voicePlayback.stop(event.currentTarget);
|
|
542
581
|
setPlaying(false);
|
|
543
|
-
}, onError }), /* @__PURE__ */
|
|
582
|
+
}, onError }), /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: `ws-voice-button${playing ? " is-playing" : ""}`, style: { width: Math.min(240, 112 + (duration && Number.isFinite(duration) ? duration : 0) * 2) }, onClick: () => void toggle(), "aria-label": `${t(playing ? "wxPauseVoice" : "wxPlayVoice")}${durationLabel ? " \xB7 " + durationLabel : ""}`, "aria-pressed": playing }, /* @__PURE__ */ import_react5.default.createElement(VoiceWaves, null), /* @__PURE__ */ import_react5.default.createElement("span", { className: "ws-voice-duration", "aria-hidden": "true" }, durationLabel)), playError && /* @__PURE__ */ import_react5.default.createElement("span", { className: "ws-voice-error", role: "status" }, t("wxVoicePlaybackFailed")));
|
|
544
583
|
}
|
|
545
584
|
|
|
546
585
|
// src/wechat/sync-panel.tsx
|
|
547
586
|
function SyncActivity({ children, compact = false, active = true, percent }) {
|
|
548
|
-
return /* @__PURE__ */
|
|
587
|
+
return /* @__PURE__ */ import_react6.default.createElement("span", { className: `ws-sync-activity${compact ? " is-compact" : ""}`, role: "status" }, compact && (active ? /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-sync-spinner", "aria-hidden": "true" }) : /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-dot", "aria-hidden": "true" })), /* @__PURE__ */ import_react6.default.createElement("span", { className: active ? "ws-sync-shimmer" : void 0 }, children), percent !== void 0 && /* @__PURE__ */ import_react6.default.createElement("strong", { className: "ws-sync-percent" }, percent, "%"), active && /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-sync-dots", "aria-hidden": "true" }, /* @__PURE__ */ import_react6.default.createElement("i", null), /* @__PURE__ */ import_react6.default.createElement("i", null), /* @__PURE__ */ import_react6.default.createElement("i", null)));
|
|
549
588
|
}
|
|
550
589
|
var progressLabels = { preparing: "wxProgressPreparing", collecting: "wxProgressReading", transferring: "wxProgressTransfer", saving: "wxProgressSaving", complete: "wxRoundComplete" };
|
|
551
590
|
function SyncProgressTrack({ progress, active, t }) {
|
|
552
591
|
const percent = wechatProgressPercent({ progress }), label = t(progress ? progressLabels[progress.stage] ?? "wxSyncing" : "wxSyncing");
|
|
553
|
-
return /* @__PURE__ */
|
|
592
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-sync-track", "data-determinate": percent !== void 0, "data-active": active, role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent }, percent !== void 0 && /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-sync-fill", style: { width: percent + "%" } })), progress && /* @__PURE__ */ import_react6.default.createElement("small", { className: "ws-sync-phase" }, label, progress.totalParts !== void 0 && /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, " \xB7 ", t("wxProgressSaved"), " ", progress.completedParts, "/", progress.totalParts, " ", t("wxProgressParts"))));
|
|
554
593
|
}
|
|
555
594
|
function SyncPanel({ client, view, workspaceId, t }) {
|
|
556
|
-
const [answered, setAnswered] = (0,
|
|
595
|
+
const [answered, setAnswered] = (0, import_react6.useState)([]), s = view.status, c = s?.capabilities, consent = s?.consent, key = consent ? consent.requestId + ":" + consent.kind : "";
|
|
557
596
|
const authorize = (approved) => {
|
|
558
597
|
if (!consent) return;
|
|
559
598
|
setAnswered((v) => [...v, key]);
|
|
560
599
|
void client.control("authorize", { requestId: consent.requestId, approved });
|
|
561
600
|
};
|
|
562
|
-
if (s?.runtime && s.runtime.phase !== "ready") return /* @__PURE__ */
|
|
601
|
+
if (s?.runtime && s.runtime.phase !== "ready") return /* @__PURE__ */ import_react6.default.createElement(RuntimePanel, { runtime: s.runtime, t, retry: () => void client.control("runtime-retry"), disabled: !workspaceId });
|
|
563
602
|
const statusText = view.error || s?.message || t(s?.phase === "waiting" ? "wxLive" : s?.phase === "paused" ? "wxPaused" : s?.running ? "wxSyncing" : "wxLoading");
|
|
564
|
-
return /* @__PURE__ */
|
|
603
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", { className: "ws-sync-status" }, /* @__PURE__ */ import_react6.default.createElement("div", { className: "ws-sync-line" }, /* @__PURE__ */ import_react6.default.createElement("span", { className: "ws-dot" }), /* @__PURE__ */ import_react6.default.createElement("span", { role: "status" }, statusText), s?.lastSyncedAt && /* @__PURE__ */ import_react6.default.createElement("time", null, new Date(s.lastSyncedAt).toLocaleTimeString()), canPauseWechat(s) ? /* @__PURE__ */ import_react6.default.createElement("button", { className: "ws-text-button", onClick: () => void client.control("pause") }, t("wxPause")) : (s?.phase === "paused" || s?.phase === "error" || !!view.error) && /* @__PURE__ */ import_react6.default.createElement("button", { className: "ws-text-button", disabled: !workspaceId || !c?.ready || s?.running, onClick: () => void client.control("start", { automatic: true }) }, t("wxRetry"))), c && !c.ready && /* @__PURE__ */ import_react6.default.createElement("p", { role: "status" }, c.limitations.join(" \xB7 ") || t("wxSupported")), !!s?.warnings?.length && /* @__PURE__ */ import_react6.default.createElement("details", null, /* @__PURE__ */ import_react6.default.createElement("summary", null, t("wxPartial")), s.warnings.map((warning, i) => /* @__PURE__ */ import_react6.default.createElement("p", { key: i }, warning))), consent && !answered.includes(key) && /* @__PURE__ */ import_react6.default.createElement("div", { className: "ws-sync-consent", role: "alert" }, /* @__PURE__ */ import_react6.default.createElement("strong", null, t(consent.kind === "restart" ? "wxRestart" : "wxInitialize")), /* @__PURE__ */ import_react6.default.createElement("p", null, consent.message), /* @__PURE__ */ import_react6.default.createElement("button", { className: "ws-button ws-primary", onClick: () => authorize(true) }, t("wxApprove")), /* @__PURE__ */ import_react6.default.createElement("button", { className: "ws-button", onClick: () => authorize(false) }, t("wxCancel"))));
|
|
565
604
|
}
|
|
566
605
|
|
|
567
606
|
// src/wechat/sync-footer.tsx
|
|
568
|
-
var
|
|
607
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
569
608
|
function SyncFooter({ view, t }) {
|
|
570
609
|
const runtime = view.status?.runtime;
|
|
571
|
-
if (runtime && runtime.phase !== "ready") return /* @__PURE__ */
|
|
610
|
+
if (runtime && runtime.phase !== "ready") return /* @__PURE__ */ import_react7.default.createElement("div", { className: "ws-sync-mini", role: "status" }, /* @__PURE__ */ import_react7.default.createElement("span", null, t(runtime.phase === "error" ? "wxRuntimeFailed" : runtime.phase === "unsupported" ? "wxRuntimeUnsupported" : "wxRuntimePreparing")), runtimePercent(runtime) !== void 0 && /* @__PURE__ */ import_react7.default.createElement("strong", { className: "ws-sync-mini-value" }, runtimePercent(runtime), "%"));
|
|
572
611
|
const s = view.status, phase = s?.phase, failed = !!view.error || phase === "error", paused = phase === "paused", authorizing = phase === "authorizing";
|
|
573
612
|
const syncing = isWechatSyncActive(s, view.error), media = !!s?.mediaImporting && !syncing && !failed && !paused && !authorizing;
|
|
574
613
|
const active = syncing || media, p = wechatProgressPercent(s);
|
|
@@ -578,14 +617,14 @@ function SyncFooter({ view, t }) {
|
|
|
578
617
|
const clock = !active && !failed && !paused && !authorizing && date && !Number.isNaN(date.getTime()) ? date.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", hour12: false }) : void 0;
|
|
579
618
|
const parts = s?.progress?.totalParts;
|
|
580
619
|
const detail = [s?.message, p !== void 0 ? p + "%" : "", parts ? `${t("wxProgressSaved")} ${s?.progress?.completedParts}/${parts} ${t("wxProgressParts")}` : "", t("wxLocalHistory")].filter(Boolean).join(" \xB7 ");
|
|
581
|
-
return /* @__PURE__ */
|
|
620
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", { className: "ws-sync-mini", role: "status", title: detail }, active ? /* @__PURE__ */ import_react7.default.createElement("span", { className: "ws-sync-spinner", "aria-hidden": "true" }) : /* @__PURE__ */ import_react7.default.createElement("svg", { width: "13", height: "13", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", "aria-hidden": "true" }, /* @__PURE__ */ import_react7.default.createElement("path", { d: paused ? "M5 3v10M11 3v10" : failed ? "M8 3v6M8 12v1" : authorizing ? "M8 3v5l3 2" : "m3 8 3 3 7-7" })), /* @__PURE__ */ import_react7.default.createElement("span", { className: active ? "ws-sync-shimmer" : void 0 }, t(label)), percent !== void 0 ? /* @__PURE__ */ import_react7.default.createElement("strong", { className: "ws-sync-mini-value" }, percent, "%") : clock && /* @__PURE__ */ import_react7.default.createElement("time", { className: "ws-sync-mini-value", dateTime: s?.lastSyncedAt }, clock), syncing && percent !== void 0 && /* @__PURE__ */ import_react7.default.createElement("span", { className: "ws-sync-mini-track", role: "progressbar", "aria-label": t("wxFooterSyncing"), "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent }, /* @__PURE__ */ import_react7.default.createElement("span", { style: { width: percent + "%" } })));
|
|
582
621
|
}
|
|
583
622
|
|
|
584
623
|
// src/client.tsx
|
|
585
|
-
var
|
|
624
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
586
625
|
|
|
587
626
|
// src/wechat/use-chat-scroll.ts
|
|
588
|
-
var
|
|
627
|
+
var import_react8 = require("react");
|
|
589
628
|
|
|
590
629
|
// src/wechat/reading-position.ts
|
|
591
630
|
var nodes = (el) => Array.from(el.querySelectorAll("[data-message-id]"));
|
|
@@ -610,8 +649,8 @@ function hasNewMessages(position, lastId) {
|
|
|
610
649
|
|
|
611
650
|
// src/wechat/use-chat-scroll.ts
|
|
612
651
|
function useChatScroll(scope, messageKey) {
|
|
613
|
-
const viewport = (0,
|
|
614
|
-
const position = (0,
|
|
652
|
+
const viewport = (0, import_react8.useRef)(null), content = (0, import_react8.useRef)(null);
|
|
653
|
+
const position = (0, import_react8.useRef)(), activeScope = (0, import_react8.useRef)(""), [unseen, setUnseen] = (0, import_react8.useState)(false), [expired, setExpired] = (0, import_react8.useState)(false);
|
|
615
654
|
const capture = () => {
|
|
616
655
|
const el = viewport.current;
|
|
617
656
|
if (!el?.clientHeight) return;
|
|
@@ -639,7 +678,7 @@ function useChatScroll(scope, messageKey) {
|
|
|
639
678
|
} else el.scrollTop = el.scrollHeight;
|
|
640
679
|
capture();
|
|
641
680
|
};
|
|
642
|
-
(0,
|
|
681
|
+
(0, import_react8.useLayoutEffect)(() => {
|
|
643
682
|
if (activeScope.current !== scope) {
|
|
644
683
|
activeScope.current = scope;
|
|
645
684
|
position.current = void 0;
|
|
@@ -648,7 +687,7 @@ function useChatScroll(scope, messageKey) {
|
|
|
648
687
|
}
|
|
649
688
|
restore();
|
|
650
689
|
}, [scope, messageKey]);
|
|
651
|
-
(0,
|
|
690
|
+
(0, import_react8.useLayoutEffect)(() => {
|
|
652
691
|
const el = viewport.current, inner = content.current;
|
|
653
692
|
if (!el || !inner || typeof ResizeObserver === "undefined") return;
|
|
654
693
|
const observer = new ResizeObserver(restore);
|
|
@@ -904,6 +943,134 @@ function reduceSales(state, action) {
|
|
|
904
943
|
}
|
|
905
944
|
}
|
|
906
945
|
|
|
946
|
+
// src/update/types.ts
|
|
947
|
+
var DEFAULT_AUTOMATIC = true;
|
|
948
|
+
|
|
949
|
+
// src/update/client.ts
|
|
950
|
+
function createUpdateClient(rpc, options) {
|
|
951
|
+
let view = { phase: "idle", runningVersion: "", automatic: DEFAULT_AUTOMATIC, preparing: false, checking: false };
|
|
952
|
+
let prepared, disposed = false, timer, polling;
|
|
953
|
+
const listeners = /* @__PURE__ */ new Set(), lifetime = new AbortController();
|
|
954
|
+
const publish = (patch) => {
|
|
955
|
+
if (disposed) return;
|
|
956
|
+
view = { ...view, ...patch };
|
|
957
|
+
for (const f of listeners) f();
|
|
958
|
+
};
|
|
959
|
+
const freeze = (value) => {
|
|
960
|
+
options.freeze(value);
|
|
961
|
+
publish({ preparing: value });
|
|
962
|
+
};
|
|
963
|
+
const call = async (payload, signal = lifetime.signal) => {
|
|
964
|
+
const r = await rpc.call("/api", "wanji-sales-update/request", payload, signal);
|
|
965
|
+
if (!r?.ok || !r.value?.snapshot) throw Error(r?.error?.code ?? "UPDATE_SERVICE_UNAVAILABLE");
|
|
966
|
+
return r.value;
|
|
967
|
+
};
|
|
968
|
+
const heartbeat = () => call({ operation: "heartbeat", clientId: options.id, readiness: { ...options.readiness(), prepared } });
|
|
969
|
+
const poll = () => polling ??= (async () => {
|
|
970
|
+
try {
|
|
971
|
+
let reply = await heartbeat();
|
|
972
|
+
if (disposed) return;
|
|
973
|
+
if (reply.prepareRequestId) {
|
|
974
|
+
freeze(true);
|
|
975
|
+
if (prepared !== reply.prepareRequestId && !options.readiness().busy) {
|
|
976
|
+
await options.flush();
|
|
977
|
+
if (disposed) return;
|
|
978
|
+
const ready = options.readiness();
|
|
979
|
+
if (!ready.busy && !ready.dirty) {
|
|
980
|
+
prepared = reply.prepareRequestId;
|
|
981
|
+
reply = await heartbeat();
|
|
982
|
+
if (disposed) return;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
} else if (["installing", "verifying", "preparing"].includes(reply.snapshot.phase)) freeze(true);
|
|
986
|
+
else {
|
|
987
|
+
prepared = void 0;
|
|
988
|
+
freeze(false);
|
|
989
|
+
}
|
|
990
|
+
publish({ error: void 0, ...reply.snapshot });
|
|
991
|
+
} catch (error) {
|
|
992
|
+
if (!disposed) publish({ error: error instanceof Error ? error.message : "UPDATE_SERVICE_UNAVAILABLE" });
|
|
993
|
+
}
|
|
994
|
+
})().finally(() => {
|
|
995
|
+
polling = void 0;
|
|
996
|
+
});
|
|
997
|
+
const schedule = () => {
|
|
998
|
+
if (!disposed) timer = setTimeout(() => {
|
|
999
|
+
void poll().finally(schedule);
|
|
1000
|
+
}, 3e3);
|
|
1001
|
+
};
|
|
1002
|
+
return {
|
|
1003
|
+
getSnapshot: () => view,
|
|
1004
|
+
subscribe(fn) {
|
|
1005
|
+
listeners.add(fn);
|
|
1006
|
+
return () => {
|
|
1007
|
+
listeners.delete(fn);
|
|
1008
|
+
};
|
|
1009
|
+
},
|
|
1010
|
+
poll,
|
|
1011
|
+
start() {
|
|
1012
|
+
void poll().finally(schedule);
|
|
1013
|
+
},
|
|
1014
|
+
async action(operation, enabled) {
|
|
1015
|
+
if (disposed || operation === "check" && view.checking) return;
|
|
1016
|
+
if (operation === "check") publish({ checking: true, error: void 0 });
|
|
1017
|
+
try {
|
|
1018
|
+
const reply = await call({ operation, ...operation === "automatic" ? { enabled } : {} });
|
|
1019
|
+
publish({ error: void 0, ...reply.snapshot });
|
|
1020
|
+
await poll();
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
publish({ error: error instanceof Error ? error.message : "UPDATE_UNAVAILABLE" });
|
|
1023
|
+
} finally {
|
|
1024
|
+
if (operation === "check") publish({ checking: false });
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
dispose() {
|
|
1028
|
+
if (disposed) return;
|
|
1029
|
+
const ready = options.readiness();
|
|
1030
|
+
if (!ready.busy && !ready.dirty && !view.preparing) void call({ operation: "unregister", clientId: options.id }, AbortSignal.timeout(2e3)).catch(() => {
|
|
1031
|
+
});
|
|
1032
|
+
disposed = true;
|
|
1033
|
+
clearTimeout(timer);
|
|
1034
|
+
lifetime.abort();
|
|
1035
|
+
listeners.clear();
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/update/window.ts
|
|
1041
|
+
var UpdateWindow = class {
|
|
1042
|
+
revision = 0;
|
|
1043
|
+
jobs = 0;
|
|
1044
|
+
edits = /* @__PURE__ */ new Map();
|
|
1045
|
+
formDirty = false;
|
|
1046
|
+
frozen = false;
|
|
1047
|
+
edit(key) {
|
|
1048
|
+
this.edits.set(key, ++this.revision);
|
|
1049
|
+
}
|
|
1050
|
+
form(dirty) {
|
|
1051
|
+
if (dirty || this.formDirty !== dirty) this.revision++;
|
|
1052
|
+
this.formDirty = dirty;
|
|
1053
|
+
}
|
|
1054
|
+
async run(work) {
|
|
1055
|
+
this.jobs++;
|
|
1056
|
+
try {
|
|
1057
|
+
return await work();
|
|
1058
|
+
} finally {
|
|
1059
|
+
this.jobs--;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
async save(key, work) {
|
|
1063
|
+
this.edit(key);
|
|
1064
|
+
const revision2 = this.edits.get(key);
|
|
1065
|
+
const value = await this.run(work);
|
|
1066
|
+
if (this.edits.get(key) === revision2) this.edits.delete(key);
|
|
1067
|
+
return value;
|
|
1068
|
+
}
|
|
1069
|
+
readiness() {
|
|
1070
|
+
return { revision: this.revision, busy: this.jobs > 0, dirty: this.formDirty || this.edits.size > 0 };
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
907
1074
|
// src/journal-client.ts
|
|
908
1075
|
function journalScope(workspaceId, c) {
|
|
909
1076
|
if (c.wechat) throw Error("\u5FAE\u4FE1\u5386\u53F2\u4F7F\u7528\u72EC\u7ACB\u6D88\u606F\u5E93\u3002");
|
|
@@ -958,6 +1125,11 @@ function createJournalClient(rpc) {
|
|
|
958
1125
|
e.queue = task;
|
|
959
1126
|
e.load = task.then(() => e.document);
|
|
960
1127
|
return task;
|
|
1128
|
+
}, async flush() {
|
|
1129
|
+
await Promise.all([...entries.values()].map(async (e) => {
|
|
1130
|
+
await e.load;
|
|
1131
|
+
await e.queue;
|
|
1132
|
+
}));
|
|
961
1133
|
}, dispose() {
|
|
962
1134
|
lifetime.abort();
|
|
963
1135
|
} };
|
|
@@ -1542,6 +1714,76 @@ function createKnowledgeStore(api) {
|
|
|
1542
1714
|
return actions;
|
|
1543
1715
|
}
|
|
1544
1716
|
|
|
1717
|
+
// src/update/locales.ts
|
|
1718
|
+
var updateZh = {
|
|
1719
|
+
updateTitle: "\u7248\u672C\u4E0E\u66F4\u65B0",
|
|
1720
|
+
updateCurrent: "\u6B63\u5728\u4F7F\u7528",
|
|
1721
|
+
updateInstalled: "\u5DF2\u5B89\u88C5",
|
|
1722
|
+
updateTarget: "\u53EF\u7528\u7248\u672C",
|
|
1723
|
+
updateCheck: "\u68C0\u67E5\u66F4\u65B0",
|
|
1724
|
+
updateCheckUnavailable: "\u5728\u7EBF\u68C0\u67E5\u4E0D\u53EF\u7528",
|
|
1725
|
+
updateChecked: "\u4E0A\u6B21\u68C0\u67E5",
|
|
1726
|
+
updateInstall: "\u7ACB\u5373\u66F4\u65B0",
|
|
1727
|
+
updateAutomatic: "\u7A7A\u95F2\u65F6\u81EA\u52A8\u5B89\u88C5\u8865\u4E01\u66F4\u65B0",
|
|
1728
|
+
updatePolicy: "\u9ED8\u8BA4\u81EA\u52A8\u68C0\u67E5\u5E76\u5B89\u88C5\u8865\u4E01\uFF0C\u65E0\u9700\u5F00\u542F\u3002\u8DE8\u5C0F\u7248\u672C\u5347\u7EA7\u9700\u786E\u8BA4\uFF1B\u4E0D\u4F1A\u5F3A\u5236\u91CD\u542F\u3002",
|
|
1729
|
+
updateIdle: "\u5DF2\u5B8C\u6210\u68C0\u67E5\uFF0C\u6682\u65E0\u66F4\u65B0",
|
|
1730
|
+
updateInitial: "\u542F\u52A8\u540E\u81EA\u52A8\u68C0\u67E5\u66F4\u65B0",
|
|
1731
|
+
updateChecking: "\u6B63\u5728\u68C0\u67E5\u65B0\u7248\u672C",
|
|
1732
|
+
updateAvailable: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
1733
|
+
updateWaiting: "\u7B49\u5F85\u6240\u6709\u7A97\u53E3\u4FDD\u5B58\uFF0C\u5E76\u5B8C\u6210\u5F53\u524D\u4EFB\u52A1",
|
|
1734
|
+
updatePreparing: "\u6B63\u5728\u4FDD\u5B58\u5E76\u7B49\u5F85\u5F53\u524D\u4EFB\u52A1\u5B8C\u6210",
|
|
1735
|
+
updateInstalling: "\u6B63\u5728\u5B89\u88C5\u66F4\u65B0",
|
|
1736
|
+
updateVerifying: "\u6B63\u5728\u6838\u9A8C\u66F4\u65B0",
|
|
1737
|
+
updateRestart: "\u5DF2\u5B89\u88C5\uFF0C\u4E0B\u6B21\u91CD\u542F\u5E94\u7528\u751F\u6548",
|
|
1738
|
+
updateUpdated: "\u66F4\u65B0\u5DF2\u751F\u6548",
|
|
1739
|
+
updateFailed: "\u66F4\u65B0\u672A\u5B8C\u6210",
|
|
1740
|
+
updateRecovery: "\u9700\u8981\u4ECE\u300C\u63D2\u4EF6\u300D\u9875\u9762\u68C0\u67E5\u6216\u91CD\u65B0\u5B89\u88C5\u9500\u552E\u52A9\u624B",
|
|
1741
|
+
updateUnsupported: "\u5F53\u524D DSH \u6682\u4E0D\u652F\u6301\u6B64\u66F4\u65B0\u63A5\u53E3\uFF0C\u8BF7\u4F7F\u7528\u300C\u63D2\u4EF6\u300D\u9875\u9762\u66F4\u65B0",
|
|
1742
|
+
updateMigration: "\u5F53\u524D\u672A\u901A\u8FC7 npm \u5305\u540D\u5B89\u88C5\uFF0C\u5728\u7EBF\u68C0\u67E5\u4E0D\u53EF\u7528\u3002\u672C\u5730\u5F00\u53D1\u7248\u968F\u6E90\u7801\u6784\u5EFA\u66F4\u65B0\uFF1B\u6B63\u5F0F\u7248\u8BF7\u4ECE\u300C\u63D2\u4EF6\u300D\u9875\u6309\u5305\u540D @wanji_dsh/dsh-sales \u5B89\u88C5\u3002",
|
|
1743
|
+
updateNetwork: "\u7F51\u7EDC\u8FDE\u63A5\u672A\u5B8C\u6210\uFF0C\u8BF7\u7A0D\u540E\u91CD\u65B0\u68C0\u67E5\u3002",
|
|
1744
|
+
updateSave: "\u6709\u672A\u4FDD\u5B58\u5185\u5BB9\u6216\u672A\u5B8C\u6210\u4EFB\u52A1\u3002\u8BF7\u68C0\u67E5\u5176\u4ED6\u7A97\u53E3\uFF0C\u4FDD\u5B58\u540E\u91CD\u8BD5\u3002",
|
|
1745
|
+
updateUnknown: "\u8BF7\u91CD\u65B0\u8FDE\u63A5\u5E76\u68C0\u67E5\u66F4\u65B0\u3002\u82E5\u4ECD\u5931\u8D25\uFF0C\u53EF\u4ECE\u300C\u63D2\u4EF6\u300D\u9875\u9762\u67E5\u770B\u5B89\u88C5\u7ED3\u679C\u3002",
|
|
1746
|
+
updateStateError: "\u66F4\u65B0\u8BB0\u5F55\u65E0\u6CD5\u6838\u9A8C\uFF0C\u8BF7\u4ECE\u300C\u63D2\u4EF6\u300D\u9875\u9762\u68C0\u67E5\u5B89\u88C5\u72B6\u6001\u3002",
|
|
1747
|
+
updateRuntime: "\u5FAE\u4FE1\u7EC4\u4EF6\u5C1A\u672A\u5C31\u7EEA\uFF0C\u539F\u540C\u6B65\u8BBE\u7F6E\u5DF2\u4FDD\u7559\uFF1B\u7EC4\u4EF6\u51C6\u5907\u597D\u540E\u4F1A\u91CD\u8BD5\u3002",
|
|
1748
|
+
updateReconnect: "\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5\uFF0C\u5F53\u524D\u5185\u5BB9\u4FDD\u7559\u5728\u6B64\u7A97\u53E3",
|
|
1749
|
+
updateFreeze: "\u6B63\u5728\u51C6\u5907\u66F4\u65B0\uFF0C\u6682\u65F6\u65E0\u6CD5\u7F16\u8F91\u3002\u8BF7\u7B49\u5F85\u5F53\u524D\u4EFB\u52A1\u5B8C\u6210\u3002",
|
|
1750
|
+
updateClose: "\u5173\u95ED\u66F4\u65B0\u9762\u677F"
|
|
1751
|
+
};
|
|
1752
|
+
var updateEn = {
|
|
1753
|
+
updateTitle: "Version & updates",
|
|
1754
|
+
updateCurrent: "Running",
|
|
1755
|
+
updateInstalled: "Installed",
|
|
1756
|
+
updateTarget: "Available",
|
|
1757
|
+
updateCheck: "Check for updates",
|
|
1758
|
+
updateCheckUnavailable: "Online check unavailable",
|
|
1759
|
+
updateChecked: "Last checked",
|
|
1760
|
+
updateInstall: "Update now",
|
|
1761
|
+
updateAutomatic: "Install patch updates when idle",
|
|
1762
|
+
updatePolicy: "Checks and installs patches automatically by default; no setup required. Minor upgrades require confirmation. The app never restarts automatically.",
|
|
1763
|
+
updateIdle: "No updates available",
|
|
1764
|
+
updateInitial: "Checks automatically after startup",
|
|
1765
|
+
updateChecking: "Checking for updates",
|
|
1766
|
+
updateAvailable: "An update is available",
|
|
1767
|
+
updateWaiting: "Waiting for all windows to save and finish their tasks",
|
|
1768
|
+
updatePreparing: "Saving and waiting for current tasks",
|
|
1769
|
+
updateInstalling: "Installing update",
|
|
1770
|
+
updateVerifying: "Verifying update",
|
|
1771
|
+
updateRestart: "Installed \xB7 Takes effect after the next app restart",
|
|
1772
|
+
updateUpdated: "Update is active",
|
|
1773
|
+
updateFailed: "Update did not complete",
|
|
1774
|
+
updateRecovery: "Check or reinstall Sales Assistant from the Plugins page",
|
|
1775
|
+
updateUnsupported: "This DSH does not support this update interface. Use the Plugins page.",
|
|
1776
|
+
updateMigration: "Online checks require an npm package installation. Local development builds update from source; install a published release as @wanji_dsh/dsh-sales from the Plugins page.",
|
|
1777
|
+
updateNetwork: "The network request did not complete. Check again later.",
|
|
1778
|
+
updateSave: "Unsaved content or tasks remain. Check other windows, save and retry.",
|
|
1779
|
+
updateUnknown: "Reconnect and check for updates. If this persists, check the result on the Plugins page.",
|
|
1780
|
+
updateStateError: "Update state could not be verified. Check the installation on the Plugins page.",
|
|
1781
|
+
updateRuntime: "WeChat components are not ready. Sync preferences are saved and will be retried.",
|
|
1782
|
+
updateReconnect: "Reconnecting \xB7 Your content remains in this window",
|
|
1783
|
+
updateFreeze: "Preparing an update. Editing is paused while current tasks finish.",
|
|
1784
|
+
updateClose: "Close update panel"
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1545
1787
|
// src/evaluation-locales.ts
|
|
1546
1788
|
var evaluationZh = {
|
|
1547
1789
|
kbEvalDataset: "\u77E5\u8BC6\u5E93\u8BC4\u6D4B\u96C6",
|
|
@@ -1856,6 +2098,7 @@ var knowledgeEn = {
|
|
|
1856
2098
|
|
|
1857
2099
|
// src/locales.ts
|
|
1858
2100
|
var zh = {
|
|
2101
|
+
...updateZh,
|
|
1859
2102
|
wxRuntimeChecking: "\u6B63\u5728\u68C0\u67E5\u672C\u673A\u5FAE\u4FE1\u7EC4\u4EF6",
|
|
1860
2103
|
wxRuntimeWaiting: "\u6B63\u5728\u7B49\u5F85\u7EC4\u4EF6\u51C6\u5907\u5B8C\u6210",
|
|
1861
2104
|
wxRuntimeDownloading: "\u9996\u6B21\u4F7F\u7528\uFF1A\u6B63\u5728\u4E0B\u8F7D\u672C\u673A\u5FAE\u4FE1\u7EC4\u4EF6",
|
|
@@ -2046,6 +2289,7 @@ var zh = {
|
|
|
2046
2289
|
contextHint: "\u57FA\u4E8E\u5F53\u524D\u793A\u4F8B\u804A\u5929\u6574\u7406"
|
|
2047
2290
|
};
|
|
2048
2291
|
var en = {
|
|
2292
|
+
...updateEn,
|
|
2049
2293
|
wxRuntimeChecking: "Checking the local WeChat component",
|
|
2050
2294
|
wxRuntimeWaiting: "Waiting for component preparation",
|
|
2051
2295
|
wxRuntimeDownloading: "First use: downloading the local WeChat component",
|
|
@@ -2239,8 +2483,8 @@ var en = {
|
|
|
2239
2483
|
// src/plan-projection.ts
|
|
2240
2484
|
var steps = { answer: "\u7B54\u590D\u5F53\u524D\u95EE\u9898\uFF0C\u63A5\u5BA2\u6237\u540E\u7EED\u7591\u95EE\u3002", provide_material: "\u63D0\u4F9B\u5BA2\u6237\u672C\u8F6E\u8981\u7684\u8BF4\u660E\u6216\u6750\u6599\uFF1B\u5DF2\u6536\u5230\u7684\u5185\u5BB9\u4E0D\u91CD\u590D\u51C6\u5907\u3002", prepare_confirmation: "\u6309\u5DF2\u786E\u8BA4\u8303\u56F4\u63D0\u4F9B\u786E\u8BA4\u6750\u6599\uFF1B\u672A\u5B9A\u4ED8\u6B3E\u6216\u5F00\u901A\u7EC6\u8282\u5355\u72EC\u8865\uFF0C\u4E0D\u62D6\u4F4F\u5DF2\u5B9A\u6750\u6599\u3002", clarify: "\u53EA\u8865\u95EE\u5F71\u54CD\u5F53\u524D\u5224\u65AD\u7684\u5FC5\u8981\u4FE1\u606F\uFF0C\u4E0D\u91CD\u95EE\u5DF2\u7ECF\u660E\u786E\u7684\u5185\u5BB9\u3002", verify_company: "\u53EA\u6838\u5B9E\u672C\u8F6E\u672A\u5B9A\u7684\u516C\u53F8\u6761\u4EF6\uFF0C\u4FDD\u7559\u5176\u4ED6\u5DF2\u7ECF\u786E\u8BA4\u7684\u6761\u4EF6\u3002", coordinate_demo: "\u534F\u8C03\u5BA2\u6237\u5DF2\u613F\u610F\u4E86\u89E3\u7684\u6F14\u793A\uFF0C\u4E0D\u627F\u8BFA\u672A\u786E\u8BA4\u6863\u671F\u3002", wait: "\u7B49\u5F85\u5BA2\u6237\u7EA6\u5B9A\u7684\u53CD\u9988\uFF0C\u4E0D\u91CD\u590D\u51C6\u5907\u5DF2\u5B8C\u6210\u7684\u5185\u5BB9\u3002", stop: "\u6682\u505C\u4E3B\u52A8\u8054\u7CFB\uFF1B\u5BA2\u6237\u56DE\u6765\u63D0\u51FA\u65B0\u95EE\u9898\u65F6\u518D\u63A5\u8BE5\u95EE\u9898\u3002" };
|
|
2241
2485
|
function projectInternalPlan(plan, latest) {
|
|
2242
|
-
const
|
|
2243
|
-
return { judgment: "\u5F53\u524D\u5904\u7406\uFF1A" +
|
|
2486
|
+
const labels2 = { answer: "\u89E3\u7B54\u5F53\u524D\u95EE\u9898", provide_material: "\u63D0\u4F9B\u5F53\u524D\u6240\u9700\u6750\u6599", prepare_confirmation: "\u51C6\u5907\u5DF2\u5B9A\u8303\u56F4\u7684\u786E\u8BA4\u6750\u6599", clarify: "\u8865\u95EE\u5FC5\u8981\u4FE1\u606F", verify_company: "\u6838\u5B9E\u672C\u8F6E\u516C\u53F8\u6761\u4EF6", coordinate_demo: "\u534F\u8C03\u6F14\u793A", wait: "\u7B49\u5F85\u5BA2\u6237\u53CD\u9988", stop: "\u6682\u505C\u4E3B\u52A8\u8054\u7CFB" };
|
|
2487
|
+
return { judgment: "\u5F53\u524D\u5904\u7406\uFF1A" + labels2[plan.action ?? "answer"] + "\u3002\u5BA2\u6237\u539F\u8BDD\uFF1A\u201C" + latest + "\u201D", next_step: steps[plan.action ?? "answer"] };
|
|
2244
2488
|
}
|
|
2245
2489
|
function bindDeliveryToAction(action, draft) {
|
|
2246
2490
|
if (action === "stop") return { ...draft, no_send: true, wechat: "" };
|
|
@@ -3113,6 +3357,7 @@ function createStore() {
|
|
|
3113
3357
|
};
|
|
3114
3358
|
}
|
|
3115
3359
|
function mountSales(ctx, Page, Icon) {
|
|
3360
|
+
const updates = new UpdateWindow();
|
|
3116
3361
|
const store = createStore();
|
|
3117
3362
|
store.setMode("real");
|
|
3118
3363
|
const wechat = createWechatClient(ctx.connection.rpc, (contacts) => {
|
|
@@ -3131,22 +3376,24 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3131
3376
|
const hydratedWechat = /* @__PURE__ */ new Set();
|
|
3132
3377
|
let journalEpoch = 0;
|
|
3133
3378
|
const journal = createJournalClient(ctx.connection.rpc), scopes = /* @__PURE__ */ new Map(), restores = /* @__PURE__ */ new Map();
|
|
3379
|
+
const draftKey = (id) => JSON.stringify([store.workspace(), store.getSnapshot().mode, id]);
|
|
3134
3380
|
const save = (id) => {
|
|
3135
|
-
const ws = scopes.get(id), c = store.getSnapshot().contacts.find((c2) => c2.id === id);
|
|
3136
|
-
if (ws
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
return;
|
|
3142
|
-
}
|
|
3143
|
-
if (ws && c) void journal.save(ws, c).then(() => {
|
|
3381
|
+
const ws = scopes.get(id), c = store.getSnapshot().contacts.find((c2) => c2.id === id), key = draftKey(id);
|
|
3382
|
+
if (!ws || !c) return;
|
|
3383
|
+
const st = store.getSnapshot(), kind = st.draftKinds[id];
|
|
3384
|
+
const work = () => c.wechat ? wechat.save(id, { sourceVersion: c.wechat.version, draft: st.drafts[id] ?? "", draftKind: kind === "agent" ? "agent" : kind === "edited" ? "edited" : "empty", progress: c.progress }) : journal.save(ws, c);
|
|
3385
|
+
const saveKey = c.wechat ? key : "history:" + key;
|
|
3386
|
+
void updates.save(saveKey, work).then(() => {
|
|
3144
3387
|
if (store.workspace() === ws) store.dispatch({ type: "history-error", id, error: "" });
|
|
3145
3388
|
}, (e) => {
|
|
3146
3389
|
if (store.workspace() === ws) store.dispatch({ type: "history-error", id, error: e.message });
|
|
3147
3390
|
});
|
|
3148
3391
|
};
|
|
3149
3392
|
const loadConversation = async (workspaceId, id) => {
|
|
3393
|
+
if (updates.frozen) return;
|
|
3394
|
+
return updates.run(() => loadConversationInner(workspaceId, id));
|
|
3395
|
+
};
|
|
3396
|
+
const loadConversationInner = async (workspaceId, id) => {
|
|
3150
3397
|
if (!workspaceId) return;
|
|
3151
3398
|
if (store.workspace() && store.workspace() !== workspaceId) cancelWaiting();
|
|
3152
3399
|
store.selectWorkspace(workspaceId);
|
|
@@ -3219,6 +3466,8 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3219
3466
|
});
|
|
3220
3467
|
const pending = /* @__PURE__ */ new Map();
|
|
3221
3468
|
const dispatch = (action) => {
|
|
3469
|
+
if (updates.frozen) return;
|
|
3470
|
+
if ("id" in action && ["edit", "apply-generated", "open-conversation", "record-simulated-message"].includes(action.type)) updates.edit(draftKey(action.id));
|
|
3222
3471
|
const before = "id" in action ? store.getSnapshot().revisions[action.id] : void 0;
|
|
3223
3472
|
store.dispatch(action);
|
|
3224
3473
|
if ((action.type === "open-conversation" || action.type === "record-simulated-message") && store.getSnapshot().revisions[action.id] !== before) {
|
|
@@ -3227,7 +3476,7 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3227
3476
|
}
|
|
3228
3477
|
if ("id" in action) {
|
|
3229
3478
|
const c = store.getSnapshot().contacts.find((c2) => c2.id === action.id);
|
|
3230
|
-
if (action.type === "handled" && c?.wechat) void wechat.handled(action.id).catch((e) => store.dispatch({ type: "history-error", id: action.id, error: e.message }));
|
|
3479
|
+
if (action.type === "handled" && c?.wechat) void updates.save("handled:" + draftKey(action.id), () => wechat.handled(action.id)).catch((e) => store.dispatch({ type: "history-error", id: action.id, error: e.message }));
|
|
3231
3480
|
if (["open-conversation", "record-simulated-message"].includes(action.type) || c?.wechat && ["edit", "apply-generated"].includes(action.type)) save(action.id);
|
|
3232
3481
|
}
|
|
3233
3482
|
};
|
|
@@ -3236,6 +3485,10 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3236
3485
|
pending.clear();
|
|
3237
3486
|
};
|
|
3238
3487
|
const generate = async (workspaceId, id) => {
|
|
3488
|
+
if (updates.frozen) return;
|
|
3489
|
+
return updates.run(() => generateInner(workspaceId, id));
|
|
3490
|
+
};
|
|
3491
|
+
const generateInner = async (workspaceId, id) => {
|
|
3239
3492
|
if (store.workspace() && store.workspace() !== workspaceId) cancelWaiting();
|
|
3240
3493
|
store.selectWorkspace(workspaceId);
|
|
3241
3494
|
const state = store.getSnapshot();
|
|
@@ -3246,7 +3499,7 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3246
3499
|
pending.set(id, controller);
|
|
3247
3500
|
const initialRevision = state.revisions[id] ?? 0;
|
|
3248
3501
|
try {
|
|
3249
|
-
const initialContext = await
|
|
3502
|
+
const initialContext = await loadConversationInner(workspaceId, id);
|
|
3250
3503
|
controller.signal.throwIfAborted();
|
|
3251
3504
|
if (store.workspace() !== workspaceId || (store.getSnapshot().revisions[id] ?? 0) !== initialRevision) return;
|
|
3252
3505
|
store.dispatch({ type: "generation-start", id, requestId });
|
|
@@ -3264,23 +3517,41 @@ function mountSales(ctx, Page, Icon) {
|
|
|
3264
3517
|
if (pending.get(id) === controller) pending.delete(id);
|
|
3265
3518
|
}
|
|
3266
3519
|
};
|
|
3520
|
+
let updateWindowId = crypto.randomUUID();
|
|
3521
|
+
const windowIdentity = /* @__PURE__ */ Symbol.for("wanji.sales.update.window");
|
|
3522
|
+
const windowGlobals = globalThis;
|
|
3523
|
+
updateWindowId = windowGlobals[windowIdentity] ??= updateWindowId;
|
|
3524
|
+
const updater = createUpdateClient(ctx.connection.rpc, { id: updateWindowId, readiness: () => updates.readiness(), flush: async () => {
|
|
3525
|
+
await Promise.all([wechat.flush(), journal.flush()]);
|
|
3526
|
+
}, freeze: (value) => {
|
|
3527
|
+
updates.frozen = value;
|
|
3528
|
+
} });
|
|
3529
|
+
ctx.effect(() => {
|
|
3530
|
+
updater.start();
|
|
3531
|
+
return () => updater.dispose();
|
|
3532
|
+
});
|
|
3267
3533
|
ctx.effect(() => ctx.locale.register(NS, { zh, en, ja: en, es: en, fr: en, de: en, ru: en, pt: en }));
|
|
3268
3534
|
const t = ctx.locale.bind(NS);
|
|
3269
3535
|
ctx.slots.inject("main", () => ctx.slots.register({
|
|
3270
3536
|
name: "main",
|
|
3271
3537
|
key: PANEL_ID,
|
|
3272
3538
|
locale: NS,
|
|
3273
|
-
inject: () => ({ hooks: { sales: store, workspaces, knowledge, wechat }, knowledge: { refresh: knowledge.refresh, setQuery: knowledge.setQuery, setMaxResults: knowledge.setMaxResults, search: knowledge.search, select: knowledge.select, rate: knowledge.rate, runCases: knowledge.runCases, cancel: knowledge.cancel, loadRuns: knowledge.loadRuns, loadRun: knowledge.loadRun, compareRuns: knowledge.compareRuns, labelRequest: knowledge.labelRequest, loadDatasets: knowledge.loadDatasets, selectDataset: knowledge.selectDataset }, wechat, setMode: (mode, workspaceId) => {
|
|
3539
|
+
inject: () => ({ hooks: { sales: store, workspaces, knowledge, wechat, update: updater }, updater, updateFormDirty: (dirty) => updates.form(dirty), knowledge: { refresh: knowledge.refresh, setQuery: knowledge.setQuery, setMaxResults: knowledge.setMaxResults, search: knowledge.search, select: knowledge.select, rate: knowledge.rate, runCases: knowledge.runCases, cancel: knowledge.cancel, loadRuns: knowledge.loadRuns, loadRun: knowledge.loadRun, compareRuns: knowledge.compareRuns, labelRequest: knowledge.labelRequest, loadDatasets: knowledge.loadDatasets, selectDataset: knowledge.selectDataset }, wechat, setMode: (mode, workspaceId) => {
|
|
3540
|
+
if (updates.frozen) return;
|
|
3274
3541
|
cancelWaiting();
|
|
3275
3542
|
store.setMode(mode);
|
|
3276
3543
|
store.selectWorkspace(workspaceId);
|
|
3277
3544
|
wechat.selectWorkspace(mode === "real" ? workspaceId : "");
|
|
3278
3545
|
}, bindWechat: async (workspaceId, id, binding) => {
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3546
|
+
if (updates.frozen) throw Error("\u6B63\u5728\u51C6\u5907\u66F4\u65B0\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002");
|
|
3547
|
+
await updates.run(async () => {
|
|
3548
|
+
const contact = await wechat.bind(id, binding);
|
|
3549
|
+
if (store.workspace() !== workspaceId) return;
|
|
3550
|
+
store.dispatch({ type: "wechat-contact", id, contact });
|
|
3551
|
+
await customerContext.load(workspaceId, contact);
|
|
3552
|
+
});
|
|
3283
3553
|
}, dispatch, generate, loadConversation, refreshWorkspaces, reset: () => {
|
|
3554
|
+
if (updates.frozen) return;
|
|
3284
3555
|
journalEpoch++;
|
|
3285
3556
|
cancelWaiting();
|
|
3286
3557
|
const ws = store.workspace(), contacts = store.getSnapshot().contacts;
|
|
@@ -3401,42 +3672,44 @@ function displayTime(value, detailed = false) {
|
|
|
3401
3672
|
return (date.toDateString() === now.toDateString() ? timeFormats.clock : date.getFullYear() === now.getFullYear() ? timeFormats.date : timeFormats.year).format(date);
|
|
3402
3673
|
}
|
|
3403
3674
|
function Glyph({ name, size = 18 }) {
|
|
3404
|
-
return /* @__PURE__ */
|
|
3675
|
+
return /* @__PURE__ */ import_react9.default.createElement("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" }, /* @__PURE__ */ import_react9.default.createElement("path", { d: paths[name] }));
|
|
3405
3676
|
}
|
|
3406
3677
|
function SalesIcon({ size = 18 }) {
|
|
3407
|
-
return /* @__PURE__ */
|
|
3678
|
+
return /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "chat", size });
|
|
3408
3679
|
}
|
|
3409
3680
|
var EMPTY_CONTACT = { id: "", name: "", initials: "", segment: "", time: "", preview: "", status: "pending", unread: 0, product: "", budget: "", moneyAmounts: [], tags: [], facts: [], messages: [], candidates: [] };
|
|
3410
|
-
function SalesPage({ t, useSales, useWorkspaces, dispatch, generate, loadConversation, refreshWorkspaces, back, wechat, useWechat, setMode, bindWechat }) {
|
|
3681
|
+
function SalesPage({ t, useSales, useWorkspaces, dispatch, generate, loadConversation, refreshWorkspaces, back, wechat, useWechat, setMode, bindWechat, useUpdate, updater, updateFormDirty }) {
|
|
3682
|
+
const update = useUpdate?.((s) => s);
|
|
3683
|
+
const frozen = update?.preparing ?? false;
|
|
3411
3684
|
const state = useSales((snapshot) => snapshot);
|
|
3412
3685
|
const view = useWechat ? useWechat((s) => s) : { messages: [], hasMore: false };
|
|
3413
3686
|
const workspaceState = useWorkspaces((snapshot) => snapshot);
|
|
3414
3687
|
const workspaces = workspaceState.items;
|
|
3415
|
-
(0,
|
|
3688
|
+
(0, import_react9.useEffect)(() => {
|
|
3416
3689
|
void refreshWorkspaces();
|
|
3417
3690
|
}, [refreshWorkspaces]);
|
|
3418
3691
|
const selectedWorkspace = selectSalesWorkspace(workspaces, view.status?.workspaceId);
|
|
3419
|
-
(0,
|
|
3420
|
-
setMode?.("real", selectedWorkspace);
|
|
3421
|
-
}, [selectedWorkspace, setMode]);
|
|
3422
|
-
const [query, setQuery] = (0,
|
|
3423
|
-
const [filter, setFilter] = (0,
|
|
3424
|
-
const [showChat, setShowChat] = (0,
|
|
3425
|
-
const [showProfile, setShowProfile] = (0,
|
|
3426
|
-
const [notice, setNotice] = (0,
|
|
3427
|
-
const [copyResult, setCopyResult] = (0,
|
|
3692
|
+
(0, import_react9.useEffect)(() => {
|
|
3693
|
+
if (!frozen) setMode?.("real", selectedWorkspace);
|
|
3694
|
+
}, [selectedWorkspace, setMode, frozen]);
|
|
3695
|
+
const [query, setQuery] = (0, import_react9.useState)("");
|
|
3696
|
+
const [filter, setFilter] = (0, import_react9.useState)("all");
|
|
3697
|
+
const [showChat, setShowChat] = (0, import_react9.useState)(false);
|
|
3698
|
+
const [showProfile, setShowProfile] = (0, import_react9.useState)(false);
|
|
3699
|
+
const [notice, setNotice] = (0, import_react9.useState)("");
|
|
3700
|
+
const [copyResult, setCopyResult] = (0, import_react9.useState)(null);
|
|
3428
3701
|
const contact = state.contacts.find((c) => c.id === state.selectedId) ?? state.contacts[0] ?? EMPTY_CONTACT;
|
|
3429
|
-
(0,
|
|
3430
|
-
if (contact.id) void loadConversation(selectedWorkspace, contact.id).catch(() => {
|
|
3702
|
+
(0, import_react9.useEffect)(() => {
|
|
3703
|
+
if (!frozen && contact.id) void loadConversation(selectedWorkspace, contact.id).catch(() => {
|
|
3431
3704
|
});
|
|
3432
|
-
}, [loadConversation, selectedWorkspace, contact.id, contact.crm?.conversationId, contact.crm?.customerPhone, contact.crm?.salesName, contact.crm?.salesPhone, contact.wechat?.version]);
|
|
3705
|
+
}, [loadConversation, selectedWorkspace, contact.id, contact.crm?.conversationId, contact.crm?.customerPhone, contact.crm?.salesName, contact.crm?.salesPhone, contact.wechat?.version, frozen]);
|
|
3433
3706
|
const contacts = filterContacts(state, filter, query);
|
|
3434
3707
|
const draft = state.drafts[contact.id] ?? "";
|
|
3435
3708
|
const generation = state.generations[contact.id];
|
|
3436
3709
|
const running = generation?.status === "running";
|
|
3437
3710
|
const shownMessages = contact.wechat ? view.contactId === contact.id ? view.messages : [] : contact.messages;
|
|
3438
3711
|
const reading = useChatScroll(JSON.stringify([selectedWorkspace, contact.wechat?.accountId, contact.id]), JSON.stringify(shownMessages.map((message) => message.id)));
|
|
3439
|
-
(0,
|
|
3712
|
+
(0, import_react9.useEffect)(() => {
|
|
3440
3713
|
if (reading.expired) setNotice(t("wxReadingPositionExpired"));
|
|
3441
3714
|
}, [reading.expired, t]);
|
|
3442
3715
|
const select = (id) => {
|
|
@@ -3458,33 +3731,37 @@ function SalesPage({ t, useSales, useWorkspaces, dispatch, generate, loadConvers
|
|
|
3458
3731
|
const syncProgress = view.status?.phase === "authorizing" ? void 0 : view.status?.progress;
|
|
3459
3732
|
const syncPercent = wechatProgressPercent({ progress: syncProgress });
|
|
3460
3733
|
const syncLabel = view.error ? "wxProgressUnavailable" : view.status?.phase === "error" ? "wxProgressFailed" : view.status?.phase === "paused" ? "wxPaused" : syncActive ? "wxIncremental" : "wxRoundComplete";
|
|
3461
|
-
return /* @__PURE__ */
|
|
3734
|
+
return /* @__PURE__ */ import_react9.default.createElement("section", { className: "ws-page", "aria-label": t("title") }, /* @__PURE__ */ import_react9.default.createElement("style", null, styles + updateStyles), /* @__PURE__ */ import_react9.default.createElement("header", { className: "ws-header" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-heading" }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-brand" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "chat", size: 22 })), /* @__PURE__ */ import_react9.default.createElement("div", null, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-title-line" }, /* @__PURE__ */ import_react9.default.createElement("h1", null, t("title")), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-demo-label" }, t("wxConnected"))), /* @__PURE__ */ import_react9.default.createElement("p", null, t("subtitle")))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-header-actions" }, updater && update && /* @__PURE__ */ import_react9.default.createElement(UpdatePanel, { client: updater, view: update, t }), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-button", onClick: back }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "arrow", size: 15 }), t("back")))), frozen && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status", className: "ws-update-freeze" }, t("updateFreeze")), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-inline-sync" }, wechat && /* @__PURE__ */ import_react9.default.createElement(SyncPanel, { client: wechat, t, view, workspaceId: selectedWorkspace }), !contact.id && workspaceState.error && /* @__PURE__ */ import_react9.default.createElement("span", { role: "status" }, workspaceState.error)), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-body", "data-empty": !contact.id, "data-show-chat": showChat, "data-profile": showProfile }, /* @__PURE__ */ import_react9.default.createElement("aside", { className: "ws-contacts", "aria-label": t("customers") }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-contacts-head" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-section-title" }, /* @__PURE__ */ import_react9.default.createElement("h2", null, t("customers")), /* @__PURE__ */ import_react9.default.createElement("span", null, state.contacts.length)), /* @__PURE__ */ import_react9.default.createElement("label", { className: "ws-search" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "search", size: 15 }), /* @__PURE__ */ import_react9.default.createElement("input", { name: "sales-search", autoComplete: "off", "aria-label": t("search"), placeholder: t("search"), value: query, onChange: (e) => setQuery(e.target.value) })), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-filters", "aria-label": t("customers") }, ["all", "pending", "handled"].map((value) => /* @__PURE__ */ import_react9.default.createElement("button", { key: value, "aria-pressed": filter === value, onClick: () => setFilter(value) }, t(value), /* @__PURE__ */ import_react9.default.createElement("span", null, value === "all" ? state.contacts.length : value === "pending" ? pending : state.contacts.length - pending))))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-contact-list" }, contacts.map((c) => /* @__PURE__ */ import_react9.default.createElement("button", { key: c.id, className: `ws-contact ${c.id === contact.id ? "is-selected" : ""}`, "aria-pressed": c.id === contact.id, onClick: () => select(c.id) }, /* @__PURE__ */ import_react9.default.createElement(WechatAvatar, { client: wechat, scope: JSON.stringify([selectedWorkspace, c.wechat?.accountId]), owner: c.wechat?.chatKey ?? c.id, mediaId: c.wechat?.avatarId, fallback: c.initials }), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-contact-content" }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-contact-line" }, /* @__PURE__ */ import_react9.default.createElement("strong", { title: c.name }, c.name), /* @__PURE__ */ import_react9.default.createElement("time", { dateTime: c.time, title: c.time }, displayTime(c.time))), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-preview" }, c.preview), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-contact-foot" }, c.status === "pending" ? /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-pending-count" }, c.unread || 1) : /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "check", size: 13 }))))), !contacts.length && /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-empty" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "search", size: 26 }), /* @__PURE__ */ import_react9.default.createElement("p", null, t(state.contacts.length ? "noResults" : "wxNoContacts")), state.contacts.length > 0 && /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-text-button", onClick: () => {
|
|
3462
3735
|
setQuery("");
|
|
3463
3736
|
setFilter("all");
|
|
3464
|
-
} }, t("clearSearch")))), /* @__PURE__ */
|
|
3737
|
+
} }, t("clearSearch")))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-sync" }, state.contacts.length > 0 ? /* @__PURE__ */ import_react9.default.createElement(SyncFooter, { view, t }) : /* @__PURE__ */ import_react9.default.createElement("span", null, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-dot" }), t("wxLocalHistory")))), /* @__PURE__ */ import_react9.default.createElement("main", { className: "ws-conversation" }, !contact.id ? /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-conversation-empty" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "chat", size: 34 }), /* @__PURE__ */ import_react9.default.createElement("h2", null, t("wxRealTitle")), /* @__PURE__ */ import_react9.default.createElement("p", null, syncActive || syncPercent !== void 0 ? /* @__PURE__ */ import_react9.default.createElement(SyncActivity, { active: syncActive, percent: syncPercent }, t(syncActive ? "wxSyncingHint" : syncLabel)) : t("wxSelectChat")), (syncActive || syncPercent !== void 0) && /* @__PURE__ */ import_react9.default.createElement(SyncProgressTrack, { progress: syncProgress, active: syncActive, t })) : /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-conversation-head" }, /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-icon-button ws-mobile-back", "aria-label": t("contactsBack"), onClick: () => setShowChat(false) }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "arrow" })), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-person-title" }, /* @__PURE__ */ import_react9.default.createElement("h2", null, contact.name, /* @__PURE__ */ import_react9.default.createElement("span", null, contact.segment)), /* @__PURE__ */ import_react9.default.createElement("p", null, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-dot" }), t("wechat"), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-separator" }, "/"), contact.wechat ? contact.crm ? t("wxBound") : t("wxUnbound") : t("sampleContact"))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-conversation-actions" }, /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-button ws-handle", disabled: frozen || contact.status === "handled", onClick: () => {
|
|
3465
3738
|
dispatch({ type: "handled", id: contact.id });
|
|
3466
3739
|
setNotice(t(contact.wechat ? "wxHandled" : "handledDone"));
|
|
3467
|
-
} }, /* @__PURE__ */
|
|
3740
|
+
} }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "check", size: 15 }), contact.status === "handled" ? t("handled") : t("markHandled")), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-icon-button ws-profile-toggle", "aria-label": showProfile ? t("closeProfile") : t("expand"), onClick: () => setShowProfile((v) => !v) }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "user" })))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-history-wrap" }, /* @__PURE__ */ import_react9.default.createElement("div", { ref: reading.viewport, onScroll: reading.onScroll, className: "ws-messages", role: "region", tabIndex: 0, "aria-label": t("conversation") }, /* @__PURE__ */ import_react9.default.createElement("div", { ref: reading.content }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-date" }, /* @__PURE__ */ import_react9.default.createElement("span", null, contact.wechat ? t("wxHistory") : t("today"))), contact.wechat && wechat && view.contactId === contact.id ? /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, view.hasMore && /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-button ws-earlier", onClick: () => void wechat.messages(contact.id, true).catch((e) => setNotice(e.message)) }, t("wxEarlier")), view.messages.map((m) => /* @__PURE__ */ import_react9.default.createElement("div", { key: m.id, "data-message-id": m.id, className: `ws-message ${m.direction === "outbound" ? "ws-out" : ""}` }, /* @__PURE__ */ import_react9.default.createElement(WechatAvatar, { client: wechat, scope: JSON.stringify([selectedWorkspace, contact.wechat.accountId]), owner: m.direction === "outbound" ? contact.wechat.accountId : contact.wechat.chatKey, mediaId: m.direction === "outbound" ? contact.wechat.selfAvatarId : contact.wechat.avatarId, fallback: m.direction === "outbound" ? t("user") : contact.initials, className: "ws-message-avatar" }), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-message-content" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-message-meta" }, /* @__PURE__ */ import_react9.default.createElement("span", null, m.direction === "inbound" ? contact.name : m.direction === "outbound" ? t("user") : t("wxSystem")), /* @__PURE__ */ import_react9.default.createElement("time", { dateTime: m.sentAt, title: m.sentAt }, displayTime(m.sentAt, true))), /* @__PURE__ */ import_react9.default.createElement("div", { className: `ws-bubble${m.kind === "voice" || m.kind === "audio" ? " ws-voice-bubble" : ""}` }, /* @__PURE__ */ import_react9.default.createElement(WechatMessageBody, { message: m, client: wechat, revision: view.status?.revision, t })))))) : contact.messages.map((message) => /* @__PURE__ */ import_react9.default.createElement("div", { key: message.id, "data-message-id": message.id, className: `ws-message ${message.direction === "out" ? "ws-out" : ""}` }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-avatar ws-message-avatar" }, message.direction === "out" ? t("user") : contact.initials), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-message-content" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-message-meta" }, /* @__PURE__ */ import_react9.default.createElement("span", null, message.direction === "out" ? t("user") : contact.name), /* @__PURE__ */ import_react9.default.createElement("time", null, message.time)), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-bubble" }, message.text)))))), reading.unseen && /* @__PURE__ */ import_react9.default.createElement("button", { type: "button", className: "ws-latest-action", onClick: reading.goToLatest }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-latest-dot", "aria-hidden": "true" }), t("wxNewMessagesLatest"), /* @__PURE__ */ import_react9.default.createElement("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true" }, /* @__PURE__ */ import_react9.default.createElement("path", { d: "m6 9 6 6 6-6" })))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-replies" }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-reply-heading" }, /* @__PURE__ */ import_react9.default.createElement("div", null, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "spark", size: 16 }), /* @__PURE__ */ import_react9.default.createElement("h3", null, t("reply")), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-example-badge" }, t(state.draftKinds[contact.id] === "agent" ? "agentDraft" : state.draftKinds[contact.id] === "edited" ? "editedDraft" : state.draftKinds[contact.id] === "empty" ? "awaitingDraft" : "example"))), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-text-button", disabled: frozen || running || !selectedWorkspace || !!contact.wechat && !contact.messages.some((m) => m.direction === "in" && m.text.trim()), onClick: () => {
|
|
3468
3741
|
setCopyResult(null);
|
|
3469
3742
|
setNotice("");
|
|
3470
3743
|
void generate(selectedWorkspace, contact.id);
|
|
3471
|
-
} }, /* @__PURE__ */
|
|
3744
|
+
} }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "spark", size: 14 }), running ? t("generating") : t("generate"))), workspaceState.error && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, workspaceState.error), state.stale?.[contact.id] && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, t("wxStale")), contact.wechat && !contact.messages.some((m) => m.direction === "in") && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, t("wxNoEvidence")), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-agent-status", role: "status", "aria-live": "polite" }, running ? t("generatingNote") : generation?.status === "error" ? generation.error : generation?.result?.no_send ? t("stopNotice") : ""), contact.customerContext?.state === "unavailable" && contact.customerContext.workspaceId === selectedWorkspace && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, t("customerContextUnavailable")), generation?.result && /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-agent-analysis" }, /* @__PURE__ */ import_react9.default.createElement("strong", null, t("judgment")), /* @__PURE__ */ import_react9.default.createElement("p", null, generation.result.judgment), /* @__PURE__ */ import_react9.default.createElement("strong", null, t("nextStep")), /* @__PURE__ */ import_react9.default.createElement("p", null, generation.result.next_step), !generation.applied && /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement("p", null, t("preservedEdit")), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-button", onClick: () => dispatch({ type: "apply-generated", id: contact.id }) }, t("applyGenerated")))), /* @__PURE__ */ import_react9.default.createElement("label", { className: "ws-editor" }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-sr-only" }, t("draft")), /* @__PURE__ */ import_react9.default.createElement("textarea", { disabled: frozen, name: "sales-draft", "aria-label": t("draft"), value: draft, onChange: (e) => {
|
|
3472
3745
|
dispatch({ type: "edit", id: contact.id, text: e.target.value });
|
|
3473
3746
|
setCopyResult(null);
|
|
3474
|
-
}, placeholder: t("draftHint") })), /* @__PURE__ */
|
|
3747
|
+
}, placeholder: t("draftHint") })), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-editor-footer" }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-draft-note" }, /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-dot" }), t("notSent")), /* @__PURE__ */ import_react9.default.createElement("span", { className: "ws-char-count" }, draft.length, " ", t("chars")), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-button ws-primary", disabled: !draft.trim() || generation?.result?.no_send, onClick: () => {
|
|
3475
3748
|
void copy();
|
|
3476
|
-
} }, /* @__PURE__ */
|
|
3749
|
+
} }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: copyResult?.id === contact.id && copyResult.success ? "check" : "copy", size: 15 }), copyResult?.id === contact.id && copyResult.success ? t("copied") : t("copy"))), state.historyErrors?.[contact.id] && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, state.historyErrors[contact.id]), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-notice", role: "status" }, copyResult?.id === contact.id && !copyResult.success ? t("copyError") : notice)))), contact.id && /* @__PURE__ */ import_react9.default.createElement("aside", { className: "ws-profile", "aria-label": t("profile") }, /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-profile-head" }, /* @__PURE__ */ import_react9.default.createElement("h2", null, t("profile")), /* @__PURE__ */ import_react9.default.createElement("button", { className: "ws-icon-button ws-profile-close", "aria-label": t("closeProfile"), onClick: () => setShowProfile(false) }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "close", size: 17 }))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-profile-person" }, /* @__PURE__ */ import_react9.default.createElement(WechatAvatar, { client: wechat, scope: JSON.stringify([selectedWorkspace, contact.wechat?.accountId]), owner: contact.wechat?.chatKey ?? contact.id, mediaId: contact.wechat?.avatarId, fallback: contact.initials, className: "ws-profile-avatar" }), /* @__PURE__ */ import_react9.default.createElement("h3", null, contact.name), /* @__PURE__ */ import_react9.default.createElement("p", null, contact.segment), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-tags" }, contact.tags.map((tag) => /* @__PURE__ */ import_react9.default.createElement("span", { key: tag }, tag)))), contact.wechat && bindWechat && /* @__PURE__ */ import_react9.default.createElement(CrmForm, { key: contact.id, contact, t, frozen, dirty: updateFormDirty, bind: (binding) => bindWechat(selectedWorkspace, contact.id, binding) }), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-profile-section" }, /* @__PURE__ */ import_react9.default.createElement("h3", null, t("interest")), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-product" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "chat", size: 18 }), /* @__PURE__ */ import_react9.default.createElement("div", null, /* @__PURE__ */ import_react9.default.createElement("strong", null, contact.product), /* @__PURE__ */ import_react9.default.createElement("p", null, contact.wechat ? t("wxContext") : t("contextHint")))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-budget" }, /* @__PURE__ */ import_react9.default.createElement("span", null, t("budget")), /* @__PURE__ */ import_react9.default.createElement("strong", null, contact.budget))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-profile-section" }, /* @__PURE__ */ import_react9.default.createElement("h3", null, t("facts")), /* @__PURE__ */ import_react9.default.createElement("dl", null, contact.facts.map((fact) => /* @__PURE__ */ import_react9.default.createElement("div", { key: fact.label }, /* @__PURE__ */ import_react9.default.createElement("dt", null, fact.label), /* @__PURE__ */ import_react9.default.createElement("dd", null, fact.value))))), /* @__PURE__ */ import_react9.default.createElement("div", { className: "ws-profile-caption" }, /* @__PURE__ */ import_react9.default.createElement(Glyph, { name: "spark", size: 14 }), /* @__PURE__ */ import_react9.default.createElement("span", null, contact.wechat ? t("wxSources") : t("profileNote"))))));
|
|
3477
3750
|
}
|
|
3478
3751
|
var inject = ["slots", "layout", "locale", "connection"];
|
|
3479
3752
|
function apply(ctx) {
|
|
3480
3753
|
mountSales(ctx, SalesPage, SalesIcon);
|
|
3481
3754
|
}
|
|
3482
|
-
function CrmForm({ contact, bind, t }) {
|
|
3483
|
-
const [phone, setPhone] = (0,
|
|
3484
|
-
|
|
3755
|
+
function CrmForm({ contact, bind, t, frozen, dirty }) {
|
|
3756
|
+
const [phone, setPhone] = (0, import_react9.useState)(""), [sales, setSales] = (0, import_react9.useState)(""), [error, setError] = (0, import_react9.useState)("");
|
|
3757
|
+
(0, import_react9.useEffect)(() => {
|
|
3758
|
+
dirty?.(!contact.crm && !!(phone || sales));
|
|
3759
|
+
return () => dirty?.(false);
|
|
3760
|
+
}, [phone, sales, contact.crm, dirty]);
|
|
3761
|
+
return /* @__PURE__ */ import_react9.default.createElement("form", { className: "ws-profile-section", onSubmit: (e) => {
|
|
3485
3762
|
e.preventDefault();
|
|
3486
3763
|
void bind({ conversationId: contact.id, customerPhone: phone.trim(), salesName: sales.trim() }).catch((e2) => setError(e2.message));
|
|
3487
|
-
} }, /* @__PURE__ */
|
|
3764
|
+
} }, /* @__PURE__ */ import_react9.default.createElement("h3", null, t("wxCrmTitle")), contact.crm ? /* @__PURE__ */ import_react9.default.createElement("p", null, t("wxBound"), " ", contact.crm.customerPhone, " \xB7 ", contact.crm.salesName, "\u3002", t("wxCrmImmutable")) : /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null, /* @__PURE__ */ import_react9.default.createElement("p", null, t("wxCrmIntro")), /* @__PURE__ */ import_react9.default.createElement("label", null, t("wxPhone"), /* @__PURE__ */ import_react9.default.createElement("input", { disabled: frozen, required: true, inputMode: "tel", value: phone, onChange: (e) => setPhone(e.target.value) })), /* @__PURE__ */ import_react9.default.createElement("label", null, t("wxSales"), /* @__PURE__ */ import_react9.default.createElement("input", { disabled: frozen, required: true, value: sales, onChange: (e) => setSales(e.target.value) })), /* @__PURE__ */ import_react9.default.createElement("button", { disabled: frozen, className: "ws-button", type: "submit" }, t("wxBind"))), error && /* @__PURE__ */ import_react9.default.createElement("p", { role: "status" }, error));
|
|
3488
3765
|
}
|
|
3489
3766
|
|
|
3490
3767
|
return module.exports;}});
|