@wanji_dsh/dsh-sales 0.11.8 → 0.11.10

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.zh.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  DeepSeek Harness 内的销售辅助工作台。插件在左侧菜单注册“销售助手”,主区域展示原生 React 页面。“用销售技能生成”调用当前Flash和WeKnora检索,但不发送微信、不操作付款、开通或上架。复制和编辑由销售掌握。
18
18
 
19
- 公司共享模型开通后,在销售助手页头选择「绑定钉钉」,按页面输入配对码并完成本人授权。经万机企业通讯录验证的成员可直接使用公司 DeepSeek Flash,并在页头查看花名、岗位或解绑。
19
+ 在销售助手页头选择「绑定钉钉」和「使用钉钉登录」,再到浏览器完成授权。登录状态暂时读不到时仍可发起登录,无需填写本人的花名或手机号。经万机企业通讯录验证的成员可使用公司 DeepSeek Flash,并在页头查看花名、岗位或解绑。
20
20
 
21
21
  如需使用自有模型,在万机大脑的模型设置选择已授权的 DeepSeek V4.1 Flash。支持 DSH 内置账号的 `deepseek-account/deepseek-flash` 和已有的 `deepseek-v4.1-flash` 路由,调用时使用各自的原始模型 ID。管理员可在 Host 设置销售插件的 `modelProvider` 和 `model`。微信会话可先同步,未绑定 CRM 的会话也可起草。
22
22
 
@@ -276,6 +276,8 @@ Independent customer materials are opt-in via materialRetrievalEnabled, material
276
276
 
277
277
  新版默认准备公司托管上报,无需在每台电脑填写 Langfuse 地址、配置文件或 Key。完成钉钉企业身份验证,并且公司服务器已启用生产观测策略后,销售助手会采集后续手动及自动起草的客户问题、最终回复、耗时和结果状态。普通 DSH 模型和公司共享模型均可使用。显式 `salesQuestionTracing:false` 停止采集,已有私有配置文件直连方式继续兼容。
278
278
 
279
+ 同一设备的企业观测授权在 Host 内复用 60 秒,并发查询共用一次请求。设备凭据变化、解绑或接口返回 401/403 后刷新授权结果。生产服务器对每次上报继续验证设备身份和观测权限。
280
+
279
281
  事件在本机脱敏后进入有界持久队列;服务端确认写入后才移除。绑定变更不会把旧账号事件上传给新账号;重试复用固定标识。此前未采集的微信历史不会补传。本期问答上报不等同于完整 CRM/录音/画像及模型 token 调用链观测。生产知识库测试功能仍关闭。
280
282
 
281
283
  服务端接收服务、私有凭据和代理发布维护在同级 `wanji_langfuse/services/company-observations`,需要先部署该入口再分发新版插件;只更新本地源码不会让其他电脑立刻生效。
package/dist/client.js CHANGED
@@ -7505,88 +7505,66 @@ function CompanyIdentityPanel({ rpc, t, disabled }) {
7505
7505
  const request = (0, import_react5.useRef)(void 0);
7506
7506
  const [open, setOpen] = (0, import_react5.useState)(false);
7507
7507
  const [view, setView] = (0, import_react5.useState)();
7508
- const [busy, setBusy] = (0, import_react5.useState)(false);
7509
- const [failed, setFailed] = (0, import_react5.useState)(false);
7508
+ const [busy, setBusy] = (0, import_react5.useState)();
7510
7509
  const [bindFailed, setBindFailed] = (0, import_react5.useState)(false);
7511
- const [alias, setAlias] = (0, import_react5.useState)("");
7512
- const [phone, setPhone] = (0, import_react5.useState)("");
7513
- const perform = (0, import_react5.useCallback)(async (payload) => {
7514
- if (request.current) return;
7510
+ const perform = (0, import_react5.useCallback)(async (operation) => {
7511
+ if (request.current) {
7512
+ if (operation !== "bind" || request.current.operation !== "status") return;
7513
+ request.current.controller.abort();
7514
+ }
7515
7515
  const controller = new AbortController();
7516
- request.current = controller;
7517
- setBusy(true);
7518
- if (payload.operation !== "status") setFailed(false);
7519
- if (payload.operation === "bind") setBindFailed(false);
7516
+ request.current = { operation, controller };
7517
+ setBusy(operation);
7518
+ if (operation === "bind") setBindFailed(false);
7520
7519
  try {
7521
- const res = await rpc.call("/api", COMPANY_IDENTITY_ENDPOINT, payload, controller.signal);
7520
+ const res = await rpc.call("/api", COMPANY_IDENTITY_ENDPOINT, { operation }, controller.signal);
7522
7521
  if (controller.signal.aborted) return;
7523
7522
  if (!res.ok || !res.value || typeof res.value !== "object" || !("status" in res.value)) throw Error("company identity unavailable");
7524
7523
  const identity = res.value;
7525
7524
  setView(identity);
7526
- setFailed(false);
7527
- if (payload.operation === "bind") {
7528
- if (identity.status === "awaiting" && !identity.verificationCode) {
7529
- try {
7530
- window.open(identity.authorizeUrl, "_blank", "noopener,noreferrer");
7531
- } catch {
7532
- }
7525
+ if (operation === "bind" && identity.status === "awaiting" && !identity.verificationCode) {
7526
+ try {
7527
+ window.open(identity.authorizeUrl, "_blank", "noopener,noreferrer");
7528
+ } catch {
7533
7529
  }
7534
- setAlias("");
7535
- setPhone("");
7536
7530
  }
7537
7531
  } catch {
7538
7532
  if (!controller.signal.aborted) {
7539
- if (payload.operation === "bind") setBindFailed(true);
7540
- else {
7541
- setView(void 0);
7542
- setFailed(true);
7543
- }
7533
+ if (operation === "bind") setBindFailed(true);
7534
+ else setView(void 0);
7544
7535
  }
7545
7536
  } finally {
7546
- if (request.current === controller) {
7537
+ if (request.current?.controller === controller) {
7547
7538
  request.current = void 0;
7548
- setBusy(false);
7539
+ setBusy(void 0);
7549
7540
  }
7550
7541
  }
7551
7542
  }, [rpc]);
7552
7543
  (0, import_react5.useEffect)(() => {
7553
- const refresh = () => void perform({ operation: "status" });
7544
+ const refresh = () => void perform("status");
7554
7545
  refresh();
7555
7546
  window.addEventListener("focus", refresh);
7556
7547
  return () => {
7557
7548
  window.removeEventListener("focus", refresh);
7558
- request.current?.abort();
7549
+ request.current?.controller.abort();
7559
7550
  request.current = void 0;
7560
7551
  };
7561
7552
  }, [perform]);
7562
7553
  const awaiting = view?.status === "awaiting";
7563
7554
  (0, import_react5.useEffect)(() => {
7564
7555
  if (!open || !awaiting) return;
7565
- const timer = window.setInterval(() => void perform({ operation: "status" }), 3e3);
7556
+ const timer = window.setInterval(() => void perform("status"), 3e3);
7566
7557
  return () => window.clearInterval(timer);
7567
7558
  }, [open, awaiting, perform]);
7568
7559
  const close = () => {
7569
7560
  setOpen(false);
7570
7561
  setBindFailed(false);
7571
- setAlias("");
7572
- setPhone("");
7573
7562
  trigger.current?.focus();
7574
7563
  };
7575
7564
  const bound = view?.status === "bound" ? view : void 0;
7576
7565
  const label2 = bound ? [bound.alias, bound.position].filter(Boolean).join(" \xB7 ") : t("companyBind");
7577
7566
  const unavailable = !view || view.status === "unavailable";
7578
- const bindable = view?.status === "unbound" || view?.status === "ineligible";
7579
- const connectDisabled = busy || disabled;
7580
- (0, import_react5.useEffect)(() => {
7581
- if (!open || !bindable) return;
7582
- const controller = new AbortController();
7583
- void rpc.call("/api", COMPANY_IDENTITY_ENDPOINT, { operation: "account-phone" }, controller.signal).then((result) => {
7584
- if (controller.signal.aborted || !result.ok || !result.value || typeof result.value !== "object" || !("phone" in result.value)) return;
7585
- const hint = result.value.phone;
7586
- if (typeof hint === "string" && /^1\d{10}$/.test(hint)) setPhone((current) => current || hint);
7587
- }).catch(() => void 0);
7588
- return () => controller.abort();
7589
- }, [rpc, open, bindable]);
7567
+ const connectDisabled = disabled || busy === "bind" || busy === "unbind";
7590
7568
  return /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update ws-company-identity", onKeyDown: (event) => {
7591
7569
  if (open && event.key === "Escape") close();
7592
7570
  } }, /* @__PURE__ */ import_react5.default.createElement(
@@ -7602,33 +7580,17 @@ function CompanyIdentityPanel({ rpc, t, disabled }) {
7602
7580
  if (open) close();
7603
7581
  else {
7604
7582
  setOpen(true);
7605
- void perform({ operation: "status" });
7583
+ void perform("status");
7606
7584
  }
7607
7585
  }
7608
7586
  },
7609
7587
  label2
7610
- ), open && /* @__PURE__ */ import_react5.default.createElement("section", { id, className: "ws-update-card ws-company-identity-card", "aria-label": t("companyIdentity") }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-heading" }, /* @__PURE__ */ import_react5.default.createElement("strong", null, t("companyIdentity")), /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-icon-button", "aria-label": t("updateClose"), onClick: close }, "\xD7")), bound && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("dl", { className: "ws-company-identity-data" }, /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyAlias")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.alias)), bound.position && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyPosition")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.position)), bound.company && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyOrganization")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.company)), bound.department && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyDepartment")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.department))), /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t(bound.modelReady ? "companyModelReady" : "companyModelUnavailable")), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-button", disabled: connectDisabled, onClick: () => void perform({ operation: "unbind" }) }, t("companyUnbind")))), view?.status === "awaiting" && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t("companyAwaiting")), view.verificationCode && /* @__PURE__ */ import_react5.default.createElement("p", null, t("companyPairingCode"), " ", /* @__PURE__ */ import_react5.default.createElement("strong", null, view.verificationCode)), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { className: "ws-button", type: "button", disabled: connectDisabled, onClick: () => void perform({ operation: "unbind" }) }, t("companyCancel")), /* @__PURE__ */ import_react5.default.createElement("a", { className: "ws-button ws-primary", href: view.authorizeUrl, target: "_blank", rel: "noopener noreferrer" }, t("companyVerify")))), bindable && /* @__PURE__ */ import_react5.default.createElement("form", { className: "ws-company-identity-form", onSubmit: (event) => {
7611
- event.preventDefault();
7612
- void perform({ operation: "bind", ...alias.trim() ? { alias: alias.trim() } : {}, ...phone.trim() ? { phone: phone.trim() } : {} });
7613
- } }, /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t(view.status === "ineligible" ? "companyIneligible" : "companyHint")), bindFailed && /* @__PURE__ */ import_react5.default.createElement("p", { role: "alert" }, t("companyBindingFailed")), /* @__PURE__ */ import_react5.default.createElement("label", null, t("companyAliasOptional"), /* @__PURE__ */ import_react5.default.createElement("input", { value: alias, maxLength: 96, onChange: (event) => setAlias(event.target.value) })), /* @__PURE__ */ import_react5.default.createElement("label", null, t("companyPhoneOptional"), /* @__PURE__ */ import_react5.default.createElement(
7614
- "input",
7615
- {
7616
- value: phone,
7617
- type: "tel",
7618
- inputMode: "tel",
7619
- maxLength: 14,
7620
- pattern: "(?:\\+86)?1[0-9]{10}",
7621
- autoComplete: "off",
7622
- onChange: (event) => setPhone(event.target.value)
7623
- }
7624
- )), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { type: "submit", className: "ws-button ws-primary", disabled: connectDisabled }, t("companyContinue")))), unavailable && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t(failed ? "companyRetryHint" : busy ? "companyChecking" : "companyUnavailable")), !busy && /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-button", onClick: () => void perform({ operation: "status" }) }, t("companyRetry"))))));
7588
+ ), open && /* @__PURE__ */ import_react5.default.createElement("section", { id, className: "ws-update-card ws-company-identity-card", "aria-label": t("companyIdentity") }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-heading" }, /* @__PURE__ */ import_react5.default.createElement("strong", null, t("companyIdentity")), /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-icon-button", "aria-label": t("updateClose"), onClick: close }, "\xD7")), bound && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("dl", { className: "ws-company-identity-data" }, /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyAlias")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.alias)), bound.position && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyPosition")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.position)), bound.company && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyOrganization")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.company)), bound.department && /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("dt", null, t("companyDepartment")), /* @__PURE__ */ import_react5.default.createElement("dd", null, bound.department))), /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t(bound.modelReady ? "companyModelReady" : "companyModelUnavailable")), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-button", disabled: disabled || !!busy, onClick: () => void perform("unbind") }, t("companyUnbind")))), view?.status === "awaiting" && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t("companyAwaiting")), view.verificationCode && /* @__PURE__ */ import_react5.default.createElement("p", null, t("companyPairingCode"), " ", /* @__PURE__ */ import_react5.default.createElement("strong", null, view.verificationCode)), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, /* @__PURE__ */ import_react5.default.createElement("button", { className: "ws-button", type: "button", disabled: disabled || !!busy, onClick: () => void perform("unbind") }, t("companyCancel")), /* @__PURE__ */ import_react5.default.createElement("a", { className: "ws-button ws-primary", href: view.authorizeUrl, target: "_blank", rel: "noopener noreferrer" }, t("companyVerify")))), !bound && !awaiting && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement("p", { role: "status" }, t(view?.status === "ineligible" ? "companyIneligible" : unavailable ? busy === "status" ? "companyChecking" : "companyRetryHint" : "companyHint")), bindFailed && /* @__PURE__ */ import_react5.default.createElement("p", { role: "alert" }, t("companyBindingFailed")), /* @__PURE__ */ import_react5.default.createElement("div", { className: "ws-update-actions" }, unavailable && /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-button", disabled: !!busy, onClick: () => void perform("status") }, t("companyRetry")), /* @__PURE__ */ import_react5.default.createElement("button", { type: "button", className: "ws-button ws-primary", disabled: connectDisabled, onClick: () => void perform("bind") }, t("companyContinue"))))));
7625
7589
  }
7626
7590
  var companyIdentityStyles = `
7627
7591
  .ws-company-identity-trigger{display:block;max-width:190px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
7628
- .ws-company-identity-card p,.ws-company-identity-form label,.ws-company-identity-data{font-size:13px;line-height:1.6}
7629
- .ws-company-identity-form,.ws-company-identity-data{display:grid;gap:10px}
7630
- .ws-company-identity-form label{display:grid;gap:4px;color:var(--ws-muted)}
7631
- .ws-company-identity-form input{width:100%;min-width:0;padding:7px 9px;border:1px solid var(--ws-line);border-radius:6px;background:var(--ws-bg);color:inherit}
7592
+ .ws-company-identity-card p,.ws-company-identity-data{font-size:13px;line-height:1.6}
7593
+ .ws-company-identity-data{display:grid;gap:10px}
7632
7594
  .ws-company-identity-card a{text-decoration:none}
7633
7595
  .ws-company-identity-data>div{display:flex;justify-content:space-between;gap:12px}
7634
7596
  .ws-company-identity-data dt{color:var(--ws-muted)}
@@ -10101,7 +10063,7 @@ var knowledgeEn = {
10101
10063
 
10102
10064
  // src/locales.ts
10103
10065
  var zh = {
10104
- companyIdentity: "\u516C\u53F8\u8EAB\u4EFD",
10066
+ companyIdentity: "\u9489\u9489\u767B\u5F55",
10105
10067
  companyBind: "\u7ED1\u5B9A\u9489\u9489",
10106
10068
  companyAlias: "\u82B1\u540D",
10107
10069
  companyPosition: "\u5C97\u4F4D",
@@ -10116,13 +10078,10 @@ var zh = {
10116
10078
  companyVerify: "\u6253\u5F00\u9489\u9489\u767B\u5F55",
10117
10079
  companyHint: "\u4E07\u673A\u4F01\u4E1A\u6210\u5458\u7ED1\u5B9A\u672C\u4EBA\u7684\u9489\u9489\u8D26\u53F7\u540E\uFF0C\u5373\u53EF\u4F7F\u7528\u516C\u53F8\u6A21\u578B\u3002",
10118
10080
  companyIneligible: "\u672A\u80FD\u9A8C\u8BC1\u5F53\u524D\u8D26\u53F7\u7684\u4E07\u673A\u4F01\u4E1A\u6210\u5458\u8EAB\u4EFD\u3002",
10119
- companyAliasOptional: "\u82B1\u540D\uFF08\u9009\u586B\uFF09",
10120
- companyPhoneOptional: "\u624B\u673A\u53F7\uFF08\u9009\u586B\uFF09",
10121
10081
  companyContinue: "\u4F7F\u7528\u9489\u9489\u767B\u5F55",
10122
10082
  companyBindingFailed: "\u672A\u80FD\u53D1\u8D77\u9489\u9489\u767B\u5F55\uFF0C\u8BF7\u91CD\u8BD5\u3002",
10123
- companyRetryHint: "\u6682\u65F6\u65E0\u6CD5\u786E\u8BA4\u516C\u53F8\u8EAB\u4EFD\uFF0C\u8BF7\u91CD\u8BD5\u3002",
10124
- companyChecking: "\u6B63\u5728\u68C0\u67E5\u516C\u53F8\u8EAB\u4EFD\u2026",
10125
- companyUnavailable: "\u516C\u53F8\u8EAB\u4EFD\u670D\u52A1\u5C1A\u672A\u63A5\u5165\u3002",
10083
+ companyRetryHint: "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u9489\u9489\u767B\u5F55\u72B6\u6001\uFF0C\u53EF\u4EE5\u76F4\u63A5\u767B\u5F55\u3002",
10084
+ companyChecking: "\u6B63\u5728\u8BFB\u53D6\u9489\u9489\u767B\u5F55\u72B6\u6001\uFF0C\u4E5F\u53EF\u4EE5\u76F4\u63A5\u767B\u5F55\u3002",
10126
10085
  companyRetry: "\u91CD\u8BD5",
10127
10086
  wxImageActualSize: "\u5B9E\u9645\u5927\u5C0F",
10128
10087
  wxVideoMessage: "\u5FAE\u4FE1\u89C6\u9891",
@@ -10437,7 +10396,7 @@ var zh = {
10437
10396
  contextHint: "\u57FA\u4E8E\u5F53\u524D\u793A\u4F8B\u804A\u5929\u6574\u7406"
10438
10397
  };
10439
10398
  var en = {
10440
- companyIdentity: "Company identity",
10399
+ companyIdentity: "DingTalk sign-in",
10441
10400
  companyBind: "Link DingTalk",
10442
10401
  companyAlias: "Display name",
10443
10402
  companyPosition: "Job title",
@@ -10452,13 +10411,10 @@ var en = {
10452
10411
  companyVerify: "Open DingTalk sign-in",
10453
10412
  companyHint: "Wanji employees can link their own DingTalk account to use the company model.",
10454
10413
  companyIneligible: "We could not verify this account\u2019s Wanji membership.",
10455
- companyAliasOptional: "Display name (optional)",
10456
- companyPhoneOptional: "Mobile number (optional)",
10457
10414
  companyContinue: "Sign in with DingTalk",
10458
10415
  companyBindingFailed: "DingTalk sign-in could not start. Try again.",
10459
- companyRetryHint: "Company identity could not be verified. Try again.",
10460
- companyChecking: "Checking company identity\u2026",
10461
- companyUnavailable: "The company identity service is not connected.",
10416
+ companyRetryHint: "DingTalk status is unavailable. You can sign in directly.",
10417
+ companyChecking: "Checking DingTalk status. You can sign in now.",
10462
10418
  companyRetry: "Try again",
10463
10419
  wxImageActualSize: "Actual size",
10464
10420
  wxVideoMessage: "WeChat video",
package/dist/host.js CHANGED
@@ -15839,7 +15839,7 @@ import { homedir, release } from "node:os";
15839
15839
  import { isAbsolute, join } from "node:path";
15840
15840
 
15841
15841
  // src/update/version.ts
15842
- var RUNNING_VERSION = true ? "0.11.8" : "0.0.0-dev";
15842
+ var RUNNING_VERSION = true ? "0.11.10" : "0.0.0-dev";
15843
15843
 
15844
15844
  // src/diagnostics.ts
15845
15845
  var MAX_FILE_BYTES = 512 * 1024;
@@ -16082,13 +16082,13 @@ async function api(target, keys, path3, body, request2 = fetch) {
16082
16082
  const stage = path3 === "/api/public/health" ? "health" : path3 === "/api/public/projects" ? "projects" : path3 === "/api/public/otel/v1/traces" ? "trace-upload" : "api";
16083
16083
  try {
16084
16084
  response = await diagnosticHttp("langfuse.http." + stage, () => request2(target.baseUrl + path3, { method: body === void 0 ? "GET" : "POST", redirect: "error", signal, headers, ...body === void 0 ? {} : { body: JSON.stringify(body) } }), signal);
16085
- } catch {
16086
- throw new Error("connection-failed");
16085
+ } catch (cause) {
16086
+ throw new Error("connection-failed", { cause: signal.aborted ? signal.reason : cause });
16087
16087
  }
16088
16088
  if (!response.ok) throw Object.assign(new Error(response.status === 401 || response.status === 403 ? "authentication-failed" : "upload-rejected"), { status: response.status });
16089
16089
  if (Number(response.headers.get("content-length")) > 8 * 1024 * 1024) throw new Error("invalid-receipt");
16090
- const value = await response.json().catch(() => {
16091
- throw new Error("invalid-receipt");
16090
+ const value = await response.json().catch((cause) => {
16091
+ throw new Error("invalid-receipt", { cause: signal.aborted ? signal.reason : cause });
16092
16092
  });
16093
16093
  if (value?.rejected > 0 || value?.partialSuccess?.rejectedSpans > 0 || value?.partial_success?.rejected_spans > 0) throw new Error("upload-rejected");
16094
16094
  return value;
@@ -16108,52 +16108,62 @@ async function preflight(target, secrets = keychainCredentials, request2 = fetch
16108
16108
  // src/company/observations.ts
16109
16109
  var endpoint = "https://wanjidazi.com/api/v1/sales-company/observations";
16110
16110
  var credentialRef = "WANJI_DSH_COMPANY_DEVICE_TOKEN";
16111
+ var policyTtlMs = 6e4;
16111
16112
  var COMPANY_OBSERVATION_TARGET = resolveTarget("managed-sales-production", {
16112
16113
  baseUrl: PRODUCTION_LANGFUSE_BASE_URL,
16113
16114
  projectId: PRODUCTION_LANGFUSE_PROJECT_ID,
16114
16115
  credentialsRef: "wanji-langfuse-api-managed-sales-production"
16115
16116
  });
16116
16117
  function createCompanyObservationRelay(store, request2 = fetch) {
16118
+ let current;
16117
16119
  async function credential() {
16118
16120
  const value = await store()?.resolve(credentialRef);
16119
- return value?.source === "file" && /^[A-Za-z0-9_-]{43}$/.test(value.value) ? value.value : void 0;
16120
- }
16121
- const scope2 = (token) => createHash2("sha256").update(token).digest("hex");
16122
- let cached;
16123
- async function deviceScope() {
16124
- const token = await credential();
16125
- if (!token) {
16126
- cached = void 0;
16121
+ if (value?.source !== "file" || !/^[A-Za-z0-9_-]{43}$/.test(value.value)) {
16122
+ current = void 0;
16127
16123
  return;
16128
16124
  }
16129
- let response;
16130
- try {
16131
- response = await request2(endpoint + "/policy", {
16132
- method: "POST",
16133
- redirect: "error",
16134
- credentials: "omit",
16135
- headers: { Authorization: "Bearer " + token },
16136
- signal: AbortSignal.timeout(5e3)
16137
- });
16138
- } catch {
16139
- return cached?.scope === scope2(token) && cached.until > Date.now() ? cached.scope : void 0;
16140
- }
16125
+ const scope2 = createHash2("sha256").update(value.value).digest("hex");
16126
+ if (current?.scope !== scope2) current = { scope: scope2, until: 0 };
16127
+ return { token: value.value, policy: current };
16128
+ }
16129
+ function invalidate(policy) {
16130
+ if (current === policy) current = void 0;
16131
+ }
16132
+ async function loadPolicy(token, state2) {
16133
+ const response = await request2(endpoint + "/policy", {
16134
+ method: "POST",
16135
+ redirect: "error",
16136
+ credentials: "omit",
16137
+ headers: { Authorization: "Bearer " + token },
16138
+ signal: AbortSignal.timeout(5e3)
16139
+ });
16141
16140
  if (!response.ok) {
16141
+ if (response.status === 401 || response.status === 403) invalidate(state2);
16142
16142
  await response.body?.cancel();
16143
- if (response.status >= 500 && cached?.scope === scope2(token) && cached.until > Date.now()) return cached.scope;
16144
- cached = void 0;
16145
16143
  return;
16146
16144
  }
16147
16145
  const policy = await response.json();
16148
- if (policy.enabled === true && policy.project_id === PRODUCTION_LANGFUSE_PROJECT_ID && policy.device_scope === scope2(token)) {
16149
- cached = { scope: scope2(token), until: Date.now() + 6e5 };
16150
- return cached.scope;
16151
- }
16152
- cached = void 0;
16146
+ if (policy?.enabled !== true || policy.project_id !== PRODUCTION_LANGFUSE_PROJECT_ID || policy.device_scope !== state2.scope) return;
16147
+ if (current !== state2 || (await credential())?.policy !== state2 || current !== state2) return;
16148
+ state2.until = performance.now() + policyTtlMs;
16149
+ return state2.scope;
16150
+ }
16151
+ async function deviceScope() {
16152
+ const binding = await credential();
16153
+ if (!binding || current !== binding.policy) return;
16154
+ const { policy, token } = binding;
16155
+ if (policy.until > performance.now()) return policy.scope;
16156
+ policy.pending ??= loadPolicy(token, policy).catch(() => void 0).finally(() => {
16157
+ policy.pending = void 0;
16158
+ });
16159
+ const scope2 = await policy.pending;
16160
+ return current === policy ? scope2 : void 0;
16153
16161
  }
16154
16162
  async function submit(event, signal) {
16155
- const token = await credential();
16156
- if (!token || event.question?.deviceScope !== scope2(token)) throw Error("company-observation-identity-changed");
16163
+ const binding = await credential();
16164
+ if (!binding || current !== binding.policy || event.question?.deviceScope !== binding.policy.scope)
16165
+ throw Error("company-observation-identity-changed");
16166
+ const { token, policy } = binding;
16157
16167
  const response = await request2(endpoint, {
16158
16168
  method: "POST",
16159
16169
  redirect: "error",
@@ -16162,7 +16172,7 @@ function createCompanyObservationRelay(store, request2 = fetch) {
16162
16172
  headers: { Authorization: "Bearer " + token, "Content-Type": "application/json" },
16163
16173
  body: JSON.stringify({
16164
16174
  event_id: event.id,
16165
- device_scope: scope2(token),
16175
+ device_scope: policy.scope,
16166
16176
  session_id: event.question.sessionId,
16167
16177
  source: event.question.source,
16168
16178
  started_at: event.startedAt,
@@ -16172,6 +16182,7 @@ function createCompanyObservationRelay(store, request2 = fetch) {
16172
16182
  })
16173
16183
  });
16174
16184
  if (!response.ok) {
16185
+ if (response.status === 401 || response.status === 403) invalidate(policy);
16175
16186
  await response.body?.cancel();
16176
16187
  throw Error("company-observation-upload-pending");
16177
16188
  }
@@ -37581,14 +37592,15 @@ function serialize(span) {
37581
37592
  return { resource: { attributes: attrs(span.resource.attributes) }, scopeSpans: [{ scope: { name: span.instrumentationScope.name, version: span.instrumentationScope.version }, spans: [{ traceId: c.traceId, spanId: c.spanId, ...span.parentSpanContext ? { parentSpanId: span.parentSpanContext.spanId } : {}, name: span.name, kind: span.kind + 1, startTimeUnixNano: nanos(span.startTime), endTimeUnixNano: nanos(span.endTime), attributes: attrs(span.attributes), status: span.status }] }] };
37582
37593
  }
37583
37594
  async function exportObservation(event, keys, extra2) {
37584
- let failed = false, acknowledged = false;
37595
+ let failure;
37596
+ let acknowledged = false;
37585
37597
  const exporter = {
37586
37598
  export(spans, callback) {
37587
37599
  void api(event.target, keys, "/api/public/otel/v1/traces", { resourceSpans: spans.map(serialize) }).then(() => {
37588
37600
  acknowledged = true;
37589
37601
  callback({ code: import_core10.ExportResultCode.SUCCESS });
37590
37602
  }, (error) => {
37591
- failed = true;
37603
+ failure = error;
37592
37604
  diagnostic("langfuse.trace-receipt", "failed", {}, error);
37593
37605
  callback({ code: import_core10.ExportResultCode.FAILED });
37594
37606
  });
@@ -37648,8 +37660,12 @@ async function exportObservation(event, keys, extra2) {
37648
37660
  span.setAttribute("langfuse.observation.level", "ERROR");
37649
37661
  }
37650
37662
  span.end(new Date(Date.parse(event.startedAt) + event.elapsedMs));
37651
- await provider.forceFlush();
37652
- if (failed || !acknowledged) throw new Error("upload-failed");
37663
+ try {
37664
+ await provider.forceFlush();
37665
+ } catch (cause) {
37666
+ throw new Error("upload-failed", { cause: failure ?? cause });
37667
+ }
37668
+ if (failure || !acknowledged) throw new Error("upload-failed", { cause: failure });
37653
37669
  } finally {
37654
37670
  await provider.shutdown();
37655
37671
  }
@@ -45137,6 +45153,7 @@ function createCompanyConnection({ credentials, settings, fetch: request2 = fetc
45137
45153
  }
45138
45154
  let pending;
45139
45155
  let verified = false;
45156
+ let statusRequests = new AbortController();
45140
45157
  let queue = Promise.resolve();
45141
45158
  function ordered(signal, apply4) {
45142
45159
  const action = queue.then(() => {
@@ -45162,9 +45179,15 @@ function createCompanyConnection({ credentials, settings, fetch: request2 = fetc
45162
45179
  ...hint ? { body: JSON.stringify(hint) } : {}
45163
45180
  }), signal);
45164
45181
  }
45165
- async function revoke(secret, signal) {
45182
+ async function revokeOnServer(secret, signal) {
45166
45183
  const response = await send("unbind", signal, secret);
45167
- if (response.status !== 204) throw Error("company unbind failed");
45184
+ if (response.status !== 204) {
45185
+ await response.body?.cancel();
45186
+ throw Error("company unbind failed");
45187
+ }
45188
+ }
45189
+ async function revoke(secret, signal) {
45190
+ await revokeOnServer(secret, signal);
45168
45191
  pending = void 0;
45169
45192
  verified = false;
45170
45193
  await credentials.unset(CREDENTIAL);
@@ -45172,44 +45195,10 @@ function createCompanyConnection({ credentials, settings, fetch: request2 = fetc
45172
45195
  const identity = {
45173
45196
  authorizeOrigin: COMPANY_ORIGIN,
45174
45197
  canUseSharedModel: () => verified,
45175
- refresh: (signal) => ordered(signal, async () => {
45176
- const secret = await token();
45177
- if (!secret) {
45178
- diagnostic("dingtalk.device-credential", "unavailable");
45179
- verified = false;
45180
- pending = void 0;
45181
- return { status: "unbound" };
45182
- }
45183
- const response = await send("status", signal, secret);
45184
- if (response.status === 401) {
45185
- await credentials.unset(CREDENTIAL);
45186
- verified = false;
45187
- pending = void 0;
45188
- return { status: "unbound" };
45189
- }
45190
- if (!response.ok) throw Error("company status unavailable");
45191
- const value = object5(await response.json());
45192
- if (value?.status === "awaiting") {
45193
- verified = false;
45194
- if (pending) return pending;
45195
- await revoke(secret, signal);
45196
- return { status: "unbound" };
45197
- }
45198
- pending = void 0;
45199
- if (value?.status === "ineligible") {
45200
- verified = false;
45201
- return { status: "ineligible" };
45202
- }
45203
- if (value?.status !== "bound" || typeof value.alias !== "string") throw Error("invalid company profile");
45204
- verified = true;
45205
- if (!ready()) await ensureRoute().then(() => diagnostic("dingtalk.model-route", "ok"), (error) => diagnostic("dingtalk.model-route", "failed", {}, error));
45206
- return {
45207
- status: "bound",
45208
- alias: value.alias,
45209
- ...typeof value.company === "string" ? { company: value.company } : {},
45210
- ...typeof value.position === "string" ? { position: value.position } : {}
45211
- };
45212
- }),
45198
+ refresh: (callerSignal) => {
45199
+ const signal = AbortSignal.any([callerSignal, statusRequests.signal]);
45200
+ return ordered(signal, () => refreshStatus(signal));
45201
+ },
45213
45202
  async transcribeVoice(audio, signal) {
45214
45203
  if (!verified && (await identity.refresh(signal)).status !== "bound") return;
45215
45204
  const secret = await token();
@@ -45233,29 +45222,12 @@ function createCompanyConnection({ credentials, settings, fetch: request2 = fetc
45233
45222
  }
45234
45223
  return readWechatTranscript(response, signal);
45235
45224
  },
45236
- begin: (hint, signal) => ordered(signal, async () => {
45237
- const previous = await token();
45238
- if (previous) await revoke(previous, signal);
45239
- const response = await send("start", signal, void 0, { ...hint, flow: "oauth" });
45240
- if (!response.ok) throw Error("company binding unavailable");
45241
- const value = object5(await response.json());
45242
- if (value?.status !== "awaiting" || typeof value.token !== "string" || !tokenPattern.test(value.token) || typeof value.authorizeUrl !== "string") {
45243
- throw Error("invalid company challenge");
45244
- }
45245
- const url = new URL(value.authorizeUrl);
45246
- const code4 = value.verificationCode;
45247
- const oneClick = isDingTalkLaunchUrl(url) && code4 === void 0;
45248
- const legacy = !url.hash && url.pathname === ROOT + "/device/verify" && url.searchParams.size === 1 && tokenPattern.test(url.searchParams.get("device") ?? "") && typeof code4 === "string" && /^\d{8}$/u.test(code4);
45249
- if (url.origin !== COMPANY_ORIGIN || url.username || url.password || !(oneClick || legacy)) {
45250
- throw Error("invalid company verification URL");
45251
- }
45225
+ begin: (hint, signal) => {
45252
45226
  signal.throwIfAborted();
45253
- await credentials.set(CREDENTIAL, value.token);
45254
- verified = false;
45255
- diagnostic(oneClick ? "dingtalk.oauth-challenge" : "dingtalk.legacy-challenge", "ok");
45256
- pending = { status: "awaiting", authorizeUrl: url.href, ...legacy ? { verificationCode: code4 } : {} };
45257
- return pending;
45258
- }),
45227
+ statusRequests.abort();
45228
+ statusRequests = new AbortController();
45229
+ return ordered(signal, () => beginBinding(hint, signal));
45230
+ },
45259
45231
  unbind: (signal) => ordered(signal, async () => {
45260
45232
  const secret = await token();
45261
45233
  if (secret) await revoke(secret, signal);
@@ -45263,6 +45235,73 @@ function createCompanyConnection({ credentials, settings, fetch: request2 = fetc
45263
45235
  pending = void 0;
45264
45236
  })
45265
45237
  };
45238
+ async function refreshStatus(signal) {
45239
+ const secret = await token();
45240
+ signal.throwIfAborted();
45241
+ if (!secret) {
45242
+ diagnostic("dingtalk.device-credential", "unavailable");
45243
+ verified = false;
45244
+ pending = void 0;
45245
+ return { status: "unbound" };
45246
+ }
45247
+ const response = await send("status", signal, secret);
45248
+ signal.throwIfAborted();
45249
+ if (response.status === 401) {
45250
+ await credentials.unset(CREDENTIAL);
45251
+ verified = false;
45252
+ pending = void 0;
45253
+ return { status: "unbound" };
45254
+ }
45255
+ if (!response.ok) throw Error("company status unavailable");
45256
+ const value = object5(await response.json());
45257
+ signal.throwIfAborted();
45258
+ if (value?.status === "awaiting") {
45259
+ verified = false;
45260
+ if (pending) return pending;
45261
+ await revoke(secret, signal);
45262
+ return { status: "unbound" };
45263
+ }
45264
+ pending = void 0;
45265
+ if (value?.status === "ineligible") {
45266
+ verified = false;
45267
+ return { status: "ineligible" };
45268
+ }
45269
+ if (value?.status !== "bound" || typeof value.alias !== "string") throw Error("invalid company profile");
45270
+ verified = true;
45271
+ if (!ready()) await ensureRoute().then(() => diagnostic("dingtalk.model-route", "ok"), (error) => diagnostic("dingtalk.model-route", "failed", {}, error));
45272
+ return {
45273
+ status: "bound",
45274
+ alias: value.alias,
45275
+ ...typeof value.company === "string" ? { company: value.company } : {},
45276
+ ...typeof value.position === "string" ? { position: value.position } : {}
45277
+ };
45278
+ }
45279
+ async function beginBinding(hint, signal) {
45280
+ const previous = await token();
45281
+ signal.throwIfAborted();
45282
+ const response = await send("start", signal, void 0, { ...hint, flow: "oauth" });
45283
+ if (!response.ok) throw Error("company binding unavailable");
45284
+ const value = object5(await response.json());
45285
+ if (value?.status !== "awaiting" || typeof value.token !== "string" || !tokenPattern.test(value.token) || typeof value.authorizeUrl !== "string") {
45286
+ throw Error("invalid company challenge");
45287
+ }
45288
+ const url = new URL(value.authorizeUrl);
45289
+ const code4 = value.verificationCode;
45290
+ const oneClick = isDingTalkLaunchUrl(url) && code4 === void 0;
45291
+ const legacy = !url.hash && url.pathname === ROOT + "/device/verify" && url.searchParams.size === 1 && tokenPattern.test(url.searchParams.get("device") ?? "") && typeof code4 === "string" && /^\d{8}$/u.test(code4);
45292
+ if (url.origin !== COMPANY_ORIGIN || url.username || url.password || !(oneClick || legacy)) {
45293
+ throw Error("invalid company verification URL");
45294
+ }
45295
+ signal.throwIfAborted();
45296
+ await credentials.set(CREDENTIAL, value.token);
45297
+ verified = false;
45298
+ if (previous && previous !== value.token) {
45299
+ void revokeOnServer(previous, AbortSignal.timeout(3e3)).catch((error) => diagnostic("dingtalk.previous-grant-revoke", "failed", {}, error));
45300
+ }
45301
+ diagnostic(oneClick ? "dingtalk.oauth-challenge" : "dingtalk.legacy-challenge", "ok");
45302
+ pending = { status: "awaiting", authorizeUrl: url.href, ...legacy ? { verificationCode: code4 } : {} };
45303
+ return pending;
45304
+ }
45266
45305
  return { identity, ready };
45267
45306
  }
45268
45307
  function companyConnectionFor(credentials, settings) {
@@ -45312,7 +45351,7 @@ function safeView(identity, service, ready) {
45312
45351
  async function readAccountPhone(account) {
45313
45352
  if (typeof account?.getProfile !== "function") return;
45314
45353
  const result = await account.getProfile({
45315
- version: true ? "0.11.8" : "0.0.0",
45354
+ version: true ? "0.11.10" : "0.0.0",
45316
45355
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
45317
45356
  timezoneOffsetSeconds: -(/* @__PURE__ */ new Date()).getTimezoneOffset() * 60
45318
45357
  });
@@ -107,7 +107,16 @@ python3 plugins/sales-assistant/scripts/verify-dual-evaluation.py --run outputs/
107
107
 
108
108
  三维各为 0–100 的整数,由程序按权重换算总分。高分占比为总分 ≥80 的数量除以有效评分数,低分占比为总分 <60 的数量除以有效评分数。三维缺项、评分错误和普通未出稿单列,0 分是有效结果。已出稿率、检索命中率和业务盲评分别统计。
109
109
 
110
- 线上评估器读取 `output.evaluation` 中的冻结用例、最终正文及可用证据。评测规则只匹配显式带当前口径标记的生产 Langfuse 评测观察。仓库中的 `grade-agent-reply-quality.mts` 在隔离 Host 内复评,`langfuse-reply-quality.mts` 将冻结草稿关联到已核实版本的 Langfuse 样本,并分别读回三维和写入确定的总分。生产 Langfuse 凭据从已配置的项目认证读取。运行档案应保留题目和素材版本、候选构建、历史稿或新出稿状态、模型、分母及逐题记录。
110
+ 线上评估器读取 `output.evaluation` 中的冻结用例、最终正文及可用证据。评测规则匹配当前环境和口径标记。`grade-agent-reply-quality.mts` 在隔离 Host 内复评,`langfuse-reply-quality.mts` 上传冻结草稿、收集三维评分并写入按权重计算的总分。运行档案应保留题目和素材版本、候选构建、出稿状态、模型、分母及逐题记录。
111
+
112
+ 常规评测使用独立 Langfuse 实例,脚本从 `WANJI_SALES_TEST_LANGFUSE_CONFIG` 或默认测试配置读取目标。生产补传使用 `--production-backfill`,同时显式给出题数,偏移量默认从 0 开始。上传与收集均适用,生产收集只查询选中题目的观测评分。生产批次串行,每秒最多开始一题。每题结束后原子保存回执,连续三题超时则保存进度并以非零状态退出。
113
+
114
+ ```sh
115
+ node plugins/sales-assistant/scripts/langfuse-reply-quality.mts upload manifest.json test-receipt.json isolated-run
116
+ node plugins/sales-assistant/scripts/langfuse-reply-quality.mts --production-backfill upload manifest.json prod-receipt.json repair-run 20 0
117
+ ```
118
+
119
+ 中断后使用原回执和运行名重跑指定范围,已成功上传的草稿按稳定身份跳过查重和上传。回执中的 `batch` 标明本次选择的范围,`results` 累积同一次运行已经处理的题目。生产及隔离实例的回执各自绑定其项目和评测规则。
111
120
 
112
121
  ### 销售与产品共识口径
113
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wanji_dsh/dsh-sales",
3
- "version": "0.11.8",
3
+ "version": "0.11.10",
4
4
  "type": "module",
5
5
  "description": "Sales workspace with local Windows/macOS WeChat sync, one-time CRM context, Flash drafts and filtered knowledge.",
6
6
  "engines": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schema": 1,
3
- "version": "0.11.8",
3
+ "version": "0.11.10",
4
4
  "targets": {
5
5
  "win32-x64": {
6
6
  "url": "https://wanjidazi.com/plugins/sales-assistant/runtimes/wanji-wechat-runtime-1.0.3-win32-x64-040c24ad35c875db.tgz",