@wanji_dsh/dsh-sales 0.10.2 → 0.10.4
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 +4 -0
- package/README.zh.md +4 -0
- package/dist/client.js +290 -166
- package/dist/host.js +576 -562
- package/dist/types/agent.d.ts +1 -0
- package/dist/types/open-review.d.ts +2 -0
- package/dist/types/turn-packet.d.ts +1 -0
- package/dist/types/turn-plan.d.ts +2 -1
- package/dist/types/wechat/batch.d.ts +2 -2
- package/dist/wechat-repository-worker.js +22 -11
- package/docs/auto-update.md +1 -1
- package/docs/wechat-sync.md +2 -0
- package/package.json +1 -1
- package/runtime/wechat-manifest.json +1 -1
package/dist/types/agent.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare function buildPrompt(contact: Contact, latest: string, knowledge?
|
|
|
37
37
|
merchant_counterparty: string;
|
|
38
38
|
};
|
|
39
39
|
latest_customer_message: string;
|
|
40
|
+
current_customer_turn: string[];
|
|
40
41
|
sources: Record<string, import("./turn-packet.ts").Evidence>;
|
|
41
42
|
selection_rule: string;
|
|
42
43
|
current_company_facts: {
|
|
@@ -37,6 +37,7 @@ export declare function buildFactReviewPrompt(contact: Contact, latest: string,
|
|
|
37
37
|
merchant_counterparty: string;
|
|
38
38
|
};
|
|
39
39
|
latest_customer_message: string;
|
|
40
|
+
current_customer_turn: string[];
|
|
40
41
|
sources: Record<string, import("./turn-packet.ts").Evidence>;
|
|
41
42
|
selection_rule: string;
|
|
42
43
|
current_company_facts: {
|
|
@@ -188,6 +189,7 @@ export declare function buildConversationReviewPrompt(contact: Contact, latest:
|
|
|
188
189
|
merchant_counterparty: string;
|
|
189
190
|
};
|
|
190
191
|
latest_customer_message: string;
|
|
192
|
+
current_customer_turn: string[];
|
|
191
193
|
sources: Record<string, import("./turn-packet.ts").Evidence>;
|
|
192
194
|
selection_rule: string;
|
|
193
195
|
current_company_facts: {
|
|
@@ -58,6 +58,7 @@ export declare function buildTurnPacket(contact: Contact, latest: string, knowle
|
|
|
58
58
|
merchant_counterparty: string;
|
|
59
59
|
};
|
|
60
60
|
latest_customer_message: string;
|
|
61
|
+
current_customer_turn: string[];
|
|
61
62
|
sources: Record<string, Evidence>;
|
|
62
63
|
selection_rule: string;
|
|
63
64
|
current_company_facts: {
|
|
@@ -15,7 +15,7 @@ export interface TurnPlan {
|
|
|
15
15
|
material_need?: MaterialNeed;
|
|
16
16
|
}
|
|
17
17
|
export declare function buildTurnPlanCorrection(error: unknown): string;
|
|
18
|
-
export declare function parseTurnPlan(text: string, contact: Contact, latest: string, packet?: TurnPacket): TurnPlan;
|
|
18
|
+
export declare function parseTurnPlan(text: string, contact: Contact, latest: string, packet?: TurnPacket, recoverProgress?: boolean): TurnPlan;
|
|
19
19
|
export declare function buildTurnPlanPrompt(contact: Contact, latest: string, contextId?: string, packet?: {
|
|
20
20
|
schemaVersion: "1.0";
|
|
21
21
|
calendar: {
|
|
@@ -33,6 +33,7 @@ export declare function buildTurnPlanPrompt(contact: Contact, latest: string, co
|
|
|
33
33
|
merchant_counterparty: string;
|
|
34
34
|
};
|
|
35
35
|
latest_customer_message: string;
|
|
36
|
+
current_customer_turn: string[];
|
|
36
37
|
sources: Record<string, import("./turn-packet.ts").Evidence>;
|
|
37
38
|
selection_rule: string;
|
|
38
39
|
current_company_facts: {
|
|
@@ -34,8 +34,8 @@ export interface SalesBatchChat {
|
|
|
34
34
|
}
|
|
35
35
|
export interface SalesBatchMedia {
|
|
36
36
|
media_key: string;
|
|
37
|
-
kind: 'image' | 'avatar' | 'voice';
|
|
38
|
-
mime_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'audio/wav';
|
|
37
|
+
kind: 'image' | 'avatar' | 'voice' | 'video';
|
|
38
|
+
mime_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'audio/wav' | 'video/mp4';
|
|
39
39
|
data_base64: string;
|
|
40
40
|
byte_size: number;
|
|
41
41
|
width: number;
|
|
@@ -9,6 +9,7 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
9
9
|
|
|
10
10
|
// src/wechat/batch.ts
|
|
11
11
|
var SALES_BATCH_SCHEMA = "wanji.wechat.batch.v1";
|
|
12
|
+
var MAX_VIDEO_BYTES = 16 * 1024 * 1024;
|
|
12
13
|
var SALES_MESSAGE_KINDS = [
|
|
13
14
|
"text",
|
|
14
15
|
"image",
|
|
@@ -61,28 +62,30 @@ function validateSalesBatch(value) {
|
|
|
61
62
|
throw new Error("Invalid incremental sync envelope");
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
const
|
|
65
|
+
const mediaKinds = /* @__PURE__ */ new Map();
|
|
65
66
|
for (const media of value.media) {
|
|
66
67
|
if (!isRecord(media)) throw new Error("media item must be an object");
|
|
67
68
|
requiredString(media.media_key, "media_key");
|
|
68
|
-
if (
|
|
69
|
-
mediaKeys.add(media.media_key);
|
|
69
|
+
if (mediaKinds.has(media.media_key)) throw new Error("duplicate media_key");
|
|
70
70
|
const isVoice = media.kind === "voice";
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
const isVideo = media.kind === "video";
|
|
72
|
+
if (typeof media.kind !== "string" || !["image", "avatar", "voice", "video"].includes(media.kind)) throw new Error("invalid media kind");
|
|
73
|
+
mediaKinds.set(media.media_key, media.kind);
|
|
74
|
+
if (isVoice ? media.mime_type !== "audio/wav" : isVideo ? media.mime_type !== "video/mp4" : !["image/jpeg", "image/png", "image/gif", "image/webp"].includes(String(media.mime_type))) throw new Error("invalid media MIME type");
|
|
75
|
+
const maxBytes = isVideo ? MAX_VIDEO_BYTES : isVoice ? 10 * 1024 * 1024 : 2 * 1024 * 1024;
|
|
74
76
|
if (!Number.isInteger(media.byte_size) || Number(media.byte_size) < 1 || Number(media.byte_size) > maxBytes) throw new Error("invalid media byte_size");
|
|
75
|
-
if (typeof media.data_base64 !== "string" || media.data_base64.length > Math.ceil(maxBytes / 3) * 4 || !/^
|
|
77
|
+
if (typeof media.data_base64 !== "string" || media.data_base64.length > Math.ceil(maxBytes / 3) * 4 || media.data_base64.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(media.data_base64)) throw new Error("invalid media base64");
|
|
76
78
|
const bytes = atob(media.data_base64);
|
|
77
79
|
if (bytes.length !== media.byte_size) throw new Error("media byte_size does not match data");
|
|
78
80
|
const signature = Array.from(bytes.slice(0, 12), (char) => char.charCodeAt(0));
|
|
79
|
-
const
|
|
81
|
+
const boxSize = isVideo ? signature.slice(0, 4).reduce((size, byte) => size * 256 + byte, 0) : 0;
|
|
82
|
+
const matches = isVoice ? bytes.startsWith("RIFF") && bytes.slice(8, 12) === "WAVE" : isVideo ? bytes.slice(4, 8) === "ftyp" && boxSize >= 16 && boxSize <= bytes.length : media.mime_type === "image/jpeg" ? signature[0] === 255 && signature[1] === 216 : media.mime_type === "image/png" ? bytes.startsWith("\x89PNG\r\n\n") : media.mime_type === "image/gif" ? bytes.startsWith("GIF87a") || bytes.startsWith("GIF89a") : bytes.startsWith("RIFF") && bytes.slice(8, 12) === "WEBP";
|
|
80
83
|
if (!matches) throw new Error("media signature does not match MIME type");
|
|
81
84
|
if (media.kind === "avatar") {
|
|
82
85
|
requiredString(media.owner_wxid, "avatar owner_wxid");
|
|
83
86
|
if (media.observed_at !== void 0 && (typeof media.observed_at !== "string" || !/^\d{4}-\d{2}-\d{2}T/.test(media.observed_at) || !Number.isFinite(Date.parse(media.observed_at)))) throw new Error("invalid avatar observation time");
|
|
84
87
|
}
|
|
85
|
-
if (!Number.isInteger(media.width) || !Number.isInteger(media.height) || (isVoice ? Number(media.width) !== 0 || Number(media.height) !== 0 : Number(media.width) <= 0 || Number(media.height) <= 0)) throw new Error("invalid media dimensions");
|
|
88
|
+
if (!Number.isInteger(media.width) || !Number.isInteger(media.height) || (isVoice || isVideo ? Number(media.width) !== 0 || Number(media.height) !== 0 : Number(media.width) <= 0 || Number(media.height) <= 0)) throw new Error("invalid media dimensions");
|
|
86
89
|
}
|
|
87
90
|
let messageCount = 0;
|
|
88
91
|
const chatKeys = /* @__PURE__ */ new Set();
|
|
@@ -97,7 +100,7 @@ function validateSalesBatch(value) {
|
|
|
97
100
|
const displayName = typeof rawChat.display_name === "string" ? rawChat.display_name.trim() : "";
|
|
98
101
|
rawChat.display_name = displayName || rawChat.chat_key;
|
|
99
102
|
requiredString(rawChat.display_name, `display_name: ${rawChat.chat_key}`);
|
|
100
|
-
if (rawChat.avatar_media_key && !
|
|
103
|
+
if (rawChat.avatar_media_key && !mediaKinds.has(String(rawChat.avatar_media_key))) throw new Error("missing avatar media");
|
|
101
104
|
if (rawChat.avatar_media_key && !value.media.some((m) => m.media_key === rawChat.avatar_media_key && m.kind === "avatar" && m.owner_wxid === rawChat.chat_key)) throw new Error("avatar owner does not match chat");
|
|
102
105
|
if (!Array.isArray(rawChat.messages)) throw new Error(`messages must be an array: ${rawChat.chat_key}`);
|
|
103
106
|
const messageKeys = /* @__PURE__ */ new Set();
|
|
@@ -113,7 +116,10 @@ function validateSalesBatch(value) {
|
|
|
113
116
|
throw new Error("Invalid message source revision");
|
|
114
117
|
}
|
|
115
118
|
if (mediaPatch) requiredString(rawMessage.media_key, "media patch media_key");
|
|
116
|
-
if (rawMessage.media_key && !
|
|
119
|
+
if (rawMessage.media_key && !mediaKinds.has(String(rawMessage.media_key))) throw new Error("missing message media");
|
|
120
|
+
if (rawMessage.media_key && rawMessage.kind === "video" !== (mediaKinds.get(String(rawMessage.media_key)) === "video")) {
|
|
121
|
+
throw new Error("video media does not match message kind");
|
|
122
|
+
}
|
|
117
123
|
requiredString(rawMessage.local_id, `local_id: ${rawMessage.message_key}`);
|
|
118
124
|
requiredString(rawMessage.sort_seq, `sort_seq: ${rawMessage.message_key}`);
|
|
119
125
|
if (!/^\d+$/.test(rawMessage.sort_seq)) throw new Error(`sort_seq must be numeric: ${rawMessage.message_key}`);
|
|
@@ -292,6 +298,7 @@ var WechatRepository = class _WechatRepository {
|
|
|
292
298
|
if (batch.delivery && active !== account) throw Error("WANJI_RESYNC_REQUIRED: media account baseline missing");
|
|
293
299
|
const changed = /* @__PURE__ */ new Set(), replyChanges = /* @__PURE__ */ new Set(), voiceChanges = /* @__PURE__ */ new Map();
|
|
294
300
|
let messages = 0, avatarsUpdated = 0;
|
|
301
|
+
const imageAreas = new Map(batch.delivery ? batch.media.filter((media) => media.kind === "image").map((media) => [media.media_key, media.width * media.height]) : []);
|
|
295
302
|
const trackVoiceChange = (chatId, id) => {
|
|
296
303
|
const voices = voiceChanges.get(chatId) ?? /* @__PURE__ */ new Set();
|
|
297
304
|
voices.add(id);
|
|
@@ -339,6 +346,10 @@ var WechatRepository = class _WechatRepository {
|
|
|
339
346
|
if (old2.kind !== m.kind || old2.direction !== m.direction || old2.source_revision !== m.source_revision) throw Error("WANJI_RESYNC_REQUIRED: media identity mismatch");
|
|
340
347
|
const mediaId2 = hash([source, m.media_key]);
|
|
341
348
|
if (old2.media_id !== mediaId2) {
|
|
349
|
+
if (old2.kind === "image" && old2.media_id) {
|
|
350
|
+
const current = this.row("SELECT json_extract(metadata,'$.width') * json_extract(metadata,'$.height') AS area FROM media WHERE id=?", old2.media_id);
|
|
351
|
+
if ((imageAreas.get(m.media_key) ?? 0) < (current?.area ?? 0)) continue;
|
|
352
|
+
}
|
|
342
353
|
this.db.prepare("UPDATE messages SET media_id=? WHERE id=?").run(mediaId2, old2.id);
|
|
343
354
|
changed.add(chatId);
|
|
344
355
|
if (old2.kind === "voice" && old2.direction === "inbound" && old2.auto_draft_arrival === 1) trackVoiceChange(chatId, old2.id);
|
package/docs/auto-update.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
2. 安装后自动检查,并在空闲时自动安装补丁;无需打开面板或勾选开关。页头「版本与更新」可查看进度;如主动关闭自动安装,该选择会保留到下次启动。
|
|
9
9
|
3. 同一 major/minor 的正式补丁可自动安装,例如 0.10.0 → 0.10.1。跨 minor(0.10 → 0.11)只提示,点「立即更新」后仍要先保存和等待任务结束。
|
|
10
10
|
|
|
11
|
-
Host
|
|
11
|
+
Host 启动后约 5 秒内发起首次检查,运行中约每 30 秒检查一次。发现兼容、未弃用的正式 `latest` 补丁后,同一轮检查就进入空闲安装流程。网络检查连续失败时,分别等待 30 秒、2 分钟,之后最多每 5 分钟重试一次。安装失败的版本可手动重试。退出 DSH 或禁用插件后不运行后台服务。
|
|
12
12
|
|
|
13
13
|
## 检查反馈
|
|
14
14
|
|
package/docs/wechat-sync.md
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
图片和语音进入可见区域及附近时自动加载,无需点击加载按钮;纯媒体消息不显示`[image]`或`[voice]`占位正文。图片点击可打开大图,支持关闭按钮、Esc或点遮罩返回;语音显示微信式声波气泡及解码后的实际秒数,点击播放/暂停,不展示浏览器原生控件。同一时间只播放一条语音,切走消息或页面会停止播放。媒体尚未入库时显示中文状态,新同步版本到达会自动更新;加载失败可重试,切换会话后的迟到结果不会覆盖当前附件。
|
|
18
18
|
|
|
19
|
+
更新 Mac 或 Windows 桌面采集组件后,微信已下载到本机的 MP4 可在文字入库后后台补传,单条上限 16 MiB。视频同步完成后,点「加载视频」即可使用播放器。微信里尚未下载的视频会继续显示同步占位。
|
|
20
|
+
|
|
19
21
|
## Windows与Mac
|
|
20
22
|
|
|
21
23
|
- Windows x64:固定启动器通过UAC启动采集Worker,DSH本身保持普通权限。当前授权会话复用常驻Worker,不每轮提权。授权为不同Windows用户、微信未登录或组件退出时暂停并要求重连。当前读取器最低版本门控4.1.0,验证线4.1.x。
|
package/package.json
CHANGED