@wanji_dsh/dsh-sales 0.11.8 → 0.11.9

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
@@ -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/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.9" : "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
  }
@@ -45312,7 +45328,7 @@ function safeView(identity, service, ready) {
45312
45328
  async function readAccountPhone(account) {
45313
45329
  if (typeof account?.getProfile !== "function") return;
45314
45330
  const result = await account.getProfile({
45315
- version: true ? "0.11.8" : "0.0.0",
45331
+ version: true ? "0.11.9" : "0.0.0",
45316
45332
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
45317
45333
  timezoneOffsetSeconds: -(/* @__PURE__ */ new Date()).getTimezoneOffset() * 60
45318
45334
  });
@@ -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.9",
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.9",
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",