@xmanrui/dsh-im 5.2.0 → 5.3.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/docs/client-integration.md +6 -2
- package/lib/client.js +398 -115
- package/lib/index.js +323 -321
- package/package.json +1 -1
- package/plugin-src/client/connection-error.js +2 -1
- package/plugin-src/client/global-settings.js +2 -1
- package/plugin-src/client/i18n.js +8 -0
- package/plugin-src/client/index.js +38 -18
- package/plugin-src/client/plugin-page.js +36 -9
- package/plugin-src/client/sidebar-settings.js +129 -0
- package/plugin-src/client/styles.js +8 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +5 -1
- package/plugin-src/host/channels/feishu/rpc.mjs +5 -1
- package/plugin-src/host/channels/qq/rpc.mjs +5 -1
- package/plugin-src/host/channels/wecom/rpc.mjs +5 -1
- package/plugin-src/host/channels/weixin/rpc.mjs +3 -2
- package/plugin-src/host/channels/whatsapp/rpc.mjs +5 -1
- package/plugin-src/host/index.mjs +7 -0
- package/plugin-src/host/sidebar-settings.mjs +113 -0
- package/src/channels/imessage/imessage-api.mjs +67 -2
- package/src/channels/shared/connection-error.mjs +5 -5
- package/src/channels/shared/diagnostic-details.mjs +15 -1
- package/src/channels/shared/i18n-en/diagnostics.mjs +5 -0
- package/src/channels/shared/qr-encoding-error.mjs +39 -0
- package/src/channels/weixin/connection-error.mjs +1 -0
|
@@ -53,6 +53,67 @@ function appleScriptString(value) {
|
|
|
53
53
|
return JSON.stringify(String(value));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// macOS 26 (Tahoe) stopped populating message.text for received iMessages: the
|
|
57
|
+
// body is only stored in message.attributedBody, an NSArchiver typedstream blob
|
|
58
|
+
// (`streamtyped` + archived NSAttributedString). These constants describe the
|
|
59
|
+
// inline-string run we need to read from that archive.
|
|
60
|
+
const ATTRIBUTED_BODY_STRING_CLASS = Buffer.from('NSString', 'utf8');
|
|
61
|
+
const ATTRIBUTED_BODY_STRING_TAG = 0x2b; // '+': inline NSString payload follows
|
|
62
|
+
// Attachment-only messages carry U+FFFC (object replacement character) instead
|
|
63
|
+
// of text. The channel is text-only, so such runs must keep normalizing to null.
|
|
64
|
+
const OBJECT_REPLACEMENT_CHARACTER = '\ufffc';
|
|
65
|
+
|
|
66
|
+
// Apple NXTypedStream integer encoding: a signed byte is a literal length,
|
|
67
|
+
// 0x81/0x82/0x83 introduce a little-endian 2/4/8-byte length.
|
|
68
|
+
function readTypedStreamLength(buffer, offset) {
|
|
69
|
+
if (offset >= buffer.length) return null;
|
|
70
|
+
const tag = buffer[offset];
|
|
71
|
+
let cursor = offset + 1;
|
|
72
|
+
let length;
|
|
73
|
+
if (tag === 0x81) {
|
|
74
|
+
if (cursor + 2 > buffer.length) return null;
|
|
75
|
+
length = buffer.readInt16LE(cursor);
|
|
76
|
+
cursor += 2;
|
|
77
|
+
} else if (tag === 0x82) {
|
|
78
|
+
if (cursor + 4 > buffer.length) return null;
|
|
79
|
+
length = buffer.readInt32LE(cursor);
|
|
80
|
+
cursor += 4;
|
|
81
|
+
} else if (tag === 0x83) {
|
|
82
|
+
if (cursor + 8 > buffer.length) return null;
|
|
83
|
+
const value = buffer.readBigInt64LE(cursor);
|
|
84
|
+
if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) return null;
|
|
85
|
+
length = Number(value);
|
|
86
|
+
cursor += 8;
|
|
87
|
+
} else {
|
|
88
|
+
length = tag > 0x7f ? tag - 0x100 : tag;
|
|
89
|
+
}
|
|
90
|
+
if (!Number.isInteger(length) || length < 0 || cursor + length > buffer.length) return null;
|
|
91
|
+
return { length, offset: cursor };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Accepts either the hex string selected via hex(m.attributedBody) or the raw blob.
|
|
95
|
+
export function decodeAttributedBodyText(value) {
|
|
96
|
+
const buffer = Buffer.isBuffer(value)
|
|
97
|
+
? value
|
|
98
|
+
: typeof value === 'string' && value.trim() ? Buffer.from(value.trim(), 'hex') : null;
|
|
99
|
+
if (!buffer?.length) return null;
|
|
100
|
+
const marker = buffer.indexOf(ATTRIBUTED_BODY_STRING_CLASS);
|
|
101
|
+
if (marker < 0) return null;
|
|
102
|
+
let tagIndex = marker + ATTRIBUTED_BODY_STRING_CLASS.length;
|
|
103
|
+
while (tagIndex < buffer.length && buffer[tagIndex] !== ATTRIBUTED_BODY_STRING_TAG) tagIndex += 1;
|
|
104
|
+
if (tagIndex >= buffer.length) return null;
|
|
105
|
+
const run = readTypedStreamLength(buffer, tagIndex + 1);
|
|
106
|
+
if (!run || run.length === 0) return null;
|
|
107
|
+
let text;
|
|
108
|
+
try {
|
|
109
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(run.offset, run.offset + run.length));
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const stripped = text.replaceAll(OBJECT_REPLACEMENT_CHARACTER, '').trim();
|
|
114
|
+
return stripped || null;
|
|
115
|
+
}
|
|
116
|
+
|
|
56
117
|
export function normalizeIMessageTarget(value) {
|
|
57
118
|
return normalizeChatGuid(value);
|
|
58
119
|
}
|
|
@@ -62,7 +123,8 @@ export function normalizeIMessage(value, { botId } = {}) {
|
|
|
62
123
|
if (value.serviceName !== undefined && value.serviceName !== 'iMessage') return null;
|
|
63
124
|
const guid = cleanString(value.guid ?? value.id);
|
|
64
125
|
const chatGuid = cleanString(value.chatGuid ?? value.chat_guid);
|
|
65
|
-
const text = cleanString(value.text)
|
|
126
|
+
const text = cleanString(value.text)
|
|
127
|
+
?? decodeAttributedBodyText(value.attributedBodyHex ?? value.attributedBody);
|
|
66
128
|
const sender = cleanString(value.sender ?? value.handle_id);
|
|
67
129
|
if (!guid || !chatGuid || !text || !sender) return null;
|
|
68
130
|
if (text.startsWith(IMESSAGE_BOT_REPLY_PREFIX)) return null;
|
|
@@ -127,7 +189,10 @@ export class MacOSMessagesApi {
|
|
|
127
189
|
const chatFilter = chatGuid ? ` AND c.guid = ${sqlString(normalizeChatGuid(chatGuid))}` : '';
|
|
128
190
|
// Messages delivers self-chat back as an incoming copy. Read that copy once,
|
|
129
191
|
// keeping all outgoing rows excluded, and filter bot replies by their marker.
|
|
192
|
+
// macOS 26 (Tahoe) stores received iMessage bodies only in attributedBody, so
|
|
193
|
+
// accept either text column and decode the blob when text is empty.
|
|
130
194
|
const query = `SELECT m.ROWID AS rowid, m.guid AS guid, m.text AS text,
|
|
195
|
+
hex(m.attributedBody) AS attributedBodyHex,
|
|
131
196
|
h.id AS sender, c.guid AS chatGuid, c.service_name AS serviceName,
|
|
132
197
|
m.is_from_me AS isFromMe,
|
|
133
198
|
datetime((m.date / 1000000000) + 978307200, 'unixepoch') AS receivedAt
|
|
@@ -136,7 +201,7 @@ export class MacOSMessagesApi {
|
|
|
136
201
|
JOIN chat c ON c.ROWID = cmj.chat_id
|
|
137
202
|
LEFT JOIN handle h ON h.ROWID = m.handle_id
|
|
138
203
|
WHERE m.ROWID > ${cursor} AND m.is_from_me = 0
|
|
139
|
-
AND m.text IS NOT NULL AND m.text != ''
|
|
204
|
+
AND ((m.text IS NOT NULL AND m.text != '') OR m.attributedBody IS NOT NULL)
|
|
140
205
|
AND c.service_name = 'iMessage'${chatFilter}
|
|
141
206
|
ORDER BY m.ROWID ASC LIMIT ${boundedLimit};`;
|
|
142
207
|
try {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import packageInfo from '../../../package.json' with { type: 'json' };
|
|
3
|
-
import { normalizeDiagnosticDetails } from './diagnostic-details.mjs';
|
|
3
|
+
import { DIAGNOSTIC_ERROR_TYPES, normalizeDiagnosticDetails } from './diagnostic-details.mjs';
|
|
4
4
|
import { t } from './i18n.mjs';
|
|
5
5
|
|
|
6
6
|
const reported = new WeakMap();
|
|
7
7
|
const lastReport = new WeakMap();
|
|
8
8
|
const stages = new WeakMap();
|
|
9
9
|
const OWNED_REASONS = { 'harness-interaction-timeout': 'timeout', 'harness-response-invalid': 'invalid-response', 'connect-timeout': 'timeout', 'telegram-timeout': 'timeout', 'cli-timeout': 'timeout', 'provider-timeout': 'timeout', 'telegram-response-invalid': 'invalid-response', 'office-protocol-mismatch': 'invalid-response' };
|
|
10
|
-
const STANDARD_NAMES = new Set(['Error', 'TypeError', 'SyntaxError', 'AggregateError', 'DOMException', 'AxiosError', 'TimeoutError', 'AbortError']);
|
|
11
10
|
const KNOWN_MESSAGES = {
|
|
12
11
|
'discord-401': 'Discord Bot Token 无效,请重新填写。',
|
|
13
12
|
'discord-intents': 'Discord Gateway Intents 配置不正确,请检查 Developer Portal 的 Bot 设置。',
|
|
@@ -36,7 +35,7 @@ export function connectionErrorChain(error) {
|
|
|
36
35
|
export function extractConnectionEvidence(error) {
|
|
37
36
|
const { chain, truncated } = connectionErrorChain(error);
|
|
38
37
|
const errors = chain.map(e => ({
|
|
39
|
-
type:
|
|
38
|
+
type: DIAGNOSTIC_ERROR_TYPES.has(e.name) ? e.name : 'Error',
|
|
40
39
|
// Host RPC adapters carry safe diagnostic facts without the original Error graph.
|
|
41
40
|
...normalizeDiagnosticDetails({
|
|
42
41
|
reason: e.details?.reason, reasons: e.details?.reasons,
|
|
@@ -98,9 +97,9 @@ export async function atConnectionStage(stage, operation, resource) {
|
|
|
98
97
|
catch (error) { throw connectionStageError(error, stage, resource); }
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
export function connectionStageError(cause, stage, resource) {
|
|
100
|
+
export function connectionStageError(cause, stage, resource, details = {}) {
|
|
102
101
|
if (!cause || typeof cause !== 'object') cause = new Error('Operation failed');
|
|
103
|
-
if (!stages.has(cause)) stages.set(cause, normalizeDiagnosticDetails({ stage, resource }));
|
|
102
|
+
if (!stages.has(cause)) stages.set(cause, normalizeDiagnosticDetails({ ...details, stage, resource }));
|
|
104
103
|
return cause;
|
|
105
104
|
}
|
|
106
105
|
|
|
@@ -117,6 +116,7 @@ export function diagnosticRpcResult(diagnostics, cause, result, context) {
|
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
export function connectionHint(details) {
|
|
119
|
+
if (details.stage === 'qr.encode') return t('本机二维码图片生成失败,请重试;若持续失败,请复制诊断信息并检查 DSH 运行环境。');
|
|
120
120
|
const r = details.reason;
|
|
121
121
|
if (r === 'multiple-causes') return t('检测到多个底层原因,请展开诊断详情逐项检查。');
|
|
122
122
|
if (['ENOTFOUND', 'EAI_AGAIN'].includes(r)) return t('服务域名解析失败,请检查运行 DSH 的机器的 DNS 和网络设置。');
|
|
@@ -19,6 +19,10 @@ const REASONS = new Set([
|
|
|
19
19
|
'CERT_HAS_EXPIRED', 'CERT_NOT_YET_VALID', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN',
|
|
20
20
|
'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'ERR_TLS_CERT_ALTNAME_INVALID', 'ERR_SSL_WRONG_VERSION_NUMBER',
|
|
21
21
|
'ENOENT', 'EACCES', 'EPERM', 'ENOSPC', 'EROFS', 'ENOTDIR', 'EISDIR', 'EBUSY', 'EIO', 'EXDEV', 'EMFILE', 'ENFILE', 'EEXIST',
|
|
22
|
+
'ERR_INVALID_ARG_TYPE', 'ERR_INVALID_ARG_VALUE', 'ERR_OUT_OF_RANGE', 'ERR_BUFFER_OUT_OF_BOUNDS',
|
|
23
|
+
'ERR_ZLIB_INITIALIZATION_FAILED', 'ERR_STREAM_DESTROYED', 'ERR_STREAM_PREMATURE_CLOSE',
|
|
24
|
+
'Z_STREAM_ERROR', 'Z_DATA_ERROR', 'Z_MEM_ERROR', 'Z_BUF_ERROR', 'Z_VERSION_ERROR',
|
|
25
|
+
'MODULE_NOT_FOUND', 'ERR_MODULE_NOT_FOUND',
|
|
22
26
|
'unknown', 'multiple-causes', 'timeout', 'http-error', 'provider-rejected', 'invalid-response', 'ERR_PROXY_CONNECTION_FAILED', 'ERR_TLS_HANDSHAKE_TIMEOUT', 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR', 'ERR_NETWORK_ACCESS_DENIED', 'AUTHENTICATIONFAILED', 'EAUTH', 'invalid-json', 'invalid-config', 'read-only',
|
|
23
27
|
]);
|
|
24
28
|
const RESOURCES = new Set(['credential-store', 'account-config', 'account-state', 'workspace-config', 'workspace-directory']);
|
|
@@ -30,6 +34,10 @@ const RPC_METHODS = new Set([
|
|
|
30
34
|
const TRANSPORTS = new Set(['host-api', 'http', 'websocket']);
|
|
31
35
|
const SUBMISSION_STATES = new Set(['not-submitted', 'accepted', 'unknown']);
|
|
32
36
|
const CONFIG_FILES = new Set(['config.json', 'workspaces.json']);
|
|
37
|
+
export const DIAGNOSTIC_ERROR_TYPES = new Set([
|
|
38
|
+
'Error', 'TypeError', 'RangeError', 'ReferenceError', 'SyntaxError', 'AggregateError',
|
|
39
|
+
'DOMException', 'AxiosError', 'TimeoutError', 'AbortError',
|
|
40
|
+
]);
|
|
33
41
|
export const CONFIG_ISSUE_LABELS = Object.freeze({
|
|
34
42
|
'expected-object': '应为 JSON 对象。',
|
|
35
43
|
'expected-array': '应为 JSON 数组。',
|
|
@@ -57,6 +65,12 @@ export function normalizeDiagnosticDetails(value) {
|
|
|
57
65
|
if (allowed.has(value[field])) result[field] = value[field];
|
|
58
66
|
}
|
|
59
67
|
if (DIAGNOSTIC_CHANNELS.includes(value.channel)) result.channel = value.channel;
|
|
68
|
+
if (Array.isArray(value.errorTypes)) {
|
|
69
|
+
const errorTypes = [...new Set(value.errorTypes.filter(type => DIAGNOSTIC_ERROR_TYPES.has(type)))];
|
|
70
|
+
if (errorTypes.length) result.errorTypes = errorTypes;
|
|
71
|
+
}
|
|
72
|
+
if (value.qrEncoder === 'qrcode') result.qrEncoder = value.qrEncoder;
|
|
73
|
+
if (value.qrRenderer === 'png') result.qrRenderer = value.qrRenderer;
|
|
60
74
|
if (Array.isArray(value.reasons)) {
|
|
61
75
|
const reasons = [...new Set(value.reasons.filter(v => REASONS.has(v) && !['unknown', 'multiple-causes'].includes(v)))].slice(0, 16);
|
|
62
76
|
if (reasons.length) result.reasons = reasons;
|
|
@@ -68,7 +82,7 @@ export function normalizeDiagnosticDetails(value) {
|
|
|
68
82
|
if (['ilinkai.weixin.qq.com', 'oapi.dingtalk.com', 'api.dingtalk.com', 'api.telegram.org', 'discord.com', 'slack.com', 'open.feishu.cn', 'qyapi.weixin.qq.com'].includes(value.host)) result.host = value.host;
|
|
69
83
|
if (value.dependencies && typeof value.dependencies === 'object') {
|
|
70
84
|
const dependencies = {};
|
|
71
|
-
for (const name of ['dingtalkStream', 'axios', 'httpsProxyAgent', 'agentBase']) {
|
|
85
|
+
for (const name of ['dingtalkStream', 'axios', 'httpsProxyAgent', 'agentBase', 'qrcode', 'pngjs', 'zlib']) {
|
|
72
86
|
const version = value.dependencies[name];
|
|
73
87
|
if (typeof version === 'string' && /^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/.test(version) && version.length <= 80) dependencies[name] = version;
|
|
74
88
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
|
+
'异常类型': 'Exception types',
|
|
3
|
+
'二维码编码器': 'QR encoder',
|
|
4
|
+
'二维码图片格式': 'QR image format',
|
|
5
|
+
'本机二维码图片生成失败,请重试;若持续失败,请复制诊断信息并检查 DSH 运行环境。':
|
|
6
|
+
'The QR-code image could not be generated locally. Retry; if it keeps failing, copy the diagnostics and check the DSH runtime environment.',
|
|
2
7
|
'准备会话': 'Prepare session',
|
|
3
8
|
'准备消息': 'Prepare message',
|
|
4
9
|
'建立交互通道': 'Open interaction channel',
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { connectionStageError, extractConnectionEvidence } from './connection-error.mjs';
|
|
3
|
+
import { normalizeDiagnosticDetails } from './diagnostic-details.mjs';
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
let installedDependencies;
|
|
7
|
+
|
|
8
|
+
function resolvedPackage(name, from) {
|
|
9
|
+
try {
|
|
10
|
+
const path = from.resolve(`${name}/package.json`);
|
|
11
|
+
return { version: from(path)?.version, require: createRequire(path) };
|
|
12
|
+
} catch {
|
|
13
|
+
// Diagnostics must not replace the original encoding failure.
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function dependencies() {
|
|
19
|
+
if (!installedDependencies) {
|
|
20
|
+
const qrcode = resolvedPackage('qrcode', require);
|
|
21
|
+
// Resolve from qrcode so nested installations report the PNG library it uses.
|
|
22
|
+
const pngjs = qrcode && resolvedPackage('pngjs', qrcode.require);
|
|
23
|
+
installedDependencies = Object.freeze(normalizeDiagnosticDetails({ dependencies: {
|
|
24
|
+
qrcode: qrcode?.version, pngjs: pngjs?.version, zlib: process.versions.zlib,
|
|
25
|
+
} }).dependencies ?? {});
|
|
26
|
+
}
|
|
27
|
+
return installedDependencies;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Attach only safe facts; never copy QR contents, exception text or stack traces. */
|
|
31
|
+
export function qrEncodingError(cause) {
|
|
32
|
+
if (cause?.name === 'AbortError') return cause;
|
|
33
|
+
const evidence = extractConnectionEvidence(cause);
|
|
34
|
+
return connectionStageError(new Error('QR encoding failed', { cause }), 'qr.encode', undefined, {
|
|
35
|
+
qrEncoder: 'qrcode', qrRenderer: 'png',
|
|
36
|
+
errorTypes: evidence.errors.map(error => error.type),
|
|
37
|
+
dependencies: dependencies(),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -105,6 +105,7 @@ export function weixinStageError(code, cause, stage) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function hintFor(code, details) {
|
|
108
|
+
if (code === 'qr-encode-failed') return connectionHint(details);
|
|
108
109
|
if (details.rollback === 'failed' || details.rollback === 'unknown') return t('原账号状态尚未确认,请重新读取状态,并反馈诊断信息。');
|
|
109
110
|
if (details.rollback === 'succeeded') return t('操作未完成,已恢复之前的本机状态。请处理上述问题后重试。');
|
|
110
111
|
if (code.startsWith('harness-')) return t('请确认当前 DSH 宿主已就绪,并检查 Harness 与插件实际运行版本及宿主日志。');
|