chatccc 0.2.306 → 0.2.307
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 +1 -1
- package/dist/src/format-message.js +75 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ ChatCCC 把本地 AI 编程工具接入即时通讯软件。你可以在手机
|
|
|
23
23
|
- **微信接入更轻**:不用创建飞书应用,启动后扫码即可在微信私聊里使用。
|
|
24
24
|
- **多 Agent 切换**:`/new` 使用默认 Agent,也可以用 `/new claude`、`/new cursor`、`/new codex`、`/new ccc`、`/new dsh` 指定工具。
|
|
25
25
|
- **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
|
|
26
|
-
-
|
|
26
|
+
- **飞书混合附件不丢失**:同一条富文本中的标题、文字、图片、视频和文件传给 Agent,兼容正文为空但标题和顶层 `files` 有内容的组合消息;保留正文顺序,顶层附件按原顺序补在正文后,并按文件 key 避免与内联附件重复。正文为空时兼容 `content_v2`,无法识别的富文本给出明确提示,不再静默忽略。视频保留原附件下载信息,不把封面误当成原视频。附件信息不完整时会明确提示。视频和文件仍由 Agent 按需下载处理,不代表模型原生支持视频输入。
|
|
27
27
|
|
|
28
28
|
## 飞书和微信的差异
|
|
29
29
|
|
|
@@ -13,7 +13,8 @@ export async function formatMessageContent(message) {
|
|
|
13
13
|
const contentStr = message.content ?? "{}";
|
|
14
14
|
let content;
|
|
15
15
|
try {
|
|
16
|
-
|
|
16
|
+
const parsed = JSON.parse(contentStr);
|
|
17
|
+
content = isPostRecord(parsed) ? parsed : {};
|
|
17
18
|
}
|
|
18
19
|
catch {
|
|
19
20
|
// merge_forward 消息的 content 可能为空字符串,但可通过 message_id 调 API 获取子消息
|
|
@@ -32,7 +33,12 @@ export async function formatMessageContent(message) {
|
|
|
32
33
|
return text.trim();
|
|
33
34
|
}
|
|
34
35
|
if (message.message_type === "post") {
|
|
35
|
-
|
|
36
|
+
const text = await formatPostContentWithAttachments(content, message.message_id);
|
|
37
|
+
if (text)
|
|
38
|
+
return text;
|
|
39
|
+
// Keep unsupported/empty rich posts visible instead of triggering the ingress empty-text drop.
|
|
40
|
+
console.warn(`[${ts()}] [POST] No readable content in rich-text message`);
|
|
41
|
+
return "[富文本消息暂无法解析,请将文字和附件分开发送]";
|
|
36
42
|
}
|
|
37
43
|
if (message.message_type === "image") {
|
|
38
44
|
const imageKey = content.image_key;
|
|
@@ -69,35 +75,73 @@ export async function formatMessageContent(message) {
|
|
|
69
75
|
return contentStr;
|
|
70
76
|
}
|
|
71
77
|
export function formatPostContent(content) {
|
|
72
|
-
const paragraphs = getPostParagraphs(content);
|
|
73
|
-
if (!Array.isArray(paragraphs))
|
|
74
|
-
return "";
|
|
75
78
|
const parts = [];
|
|
76
|
-
for (const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const el = elem;
|
|
81
|
-
if (!el || typeof el !== "object")
|
|
82
|
-
continue;
|
|
83
|
-
const text = formatPostTextElement(el);
|
|
84
|
-
if (text)
|
|
85
|
-
parts.push(text);
|
|
86
|
-
}
|
|
79
|
+
for (const el of getPostElements(content)) {
|
|
80
|
+
const text = formatPostTextElement(el);
|
|
81
|
+
if (text)
|
|
82
|
+
parts.push(text);
|
|
87
83
|
}
|
|
88
84
|
return parts.join("\n").trim();
|
|
89
85
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
function isPostRecord(value) {
|
|
87
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
88
|
+
}
|
|
89
|
+
function getPostPayload(content) {
|
|
90
|
+
const hasFields = (value) => Array.isArray(value.content)
|
|
91
|
+
|| Array.isArray(value.content_v2) || Array.isArray(value.files) || Boolean(attachmentString(value.title));
|
|
92
|
+
if (hasFields(content))
|
|
93
|
+
return content;
|
|
94
94
|
for (const locale of ["zh_cn", "en_us", "ja_jp"]) {
|
|
95
95
|
const localized = content[locale];
|
|
96
|
-
if (localized &&
|
|
97
|
-
return localized
|
|
98
|
-
}
|
|
96
|
+
if (isPostRecord(localized) && hasFields(localized))
|
|
97
|
+
return localized;
|
|
99
98
|
}
|
|
100
|
-
return
|
|
99
|
+
return content;
|
|
100
|
+
}
|
|
101
|
+
/** Both formatters must preserve title-only/file-list posts as well as inline attachments. */
|
|
102
|
+
function getPostElements(content) {
|
|
103
|
+
const post = getPostPayload(content);
|
|
104
|
+
const flatten = (value) => Array.isArray(value)
|
|
105
|
+
? value.flatMap(line => Array.isArray(line) ? line.filter(isPostRecord) : [])
|
|
106
|
+
: [];
|
|
107
|
+
const legacy = flatten(post.content);
|
|
108
|
+
// The API can return both versions; replaying both duplicates text and attachments.
|
|
109
|
+
const elements = legacy.length > 0 ? legacy : flatten(post.content_v2);
|
|
110
|
+
const files = Array.isArray(post.files) ? post.files.filter(isPostRecord) : [];
|
|
111
|
+
const filesByKey = new Map();
|
|
112
|
+
for (const file of files) {
|
|
113
|
+
const key = attachmentString(file.file_key);
|
|
114
|
+
if (key && !filesByKey.has(key))
|
|
115
|
+
filesByKey.set(key, file);
|
|
116
|
+
}
|
|
117
|
+
const seenFileKeys = new Set();
|
|
118
|
+
const result = elements.map(el => {
|
|
119
|
+
if (el.tag !== "file" && el.tag !== "media")
|
|
120
|
+
return el;
|
|
121
|
+
const key = attachmentString(el.file_key);
|
|
122
|
+
if (key)
|
|
123
|
+
seenFileKeys.add(key);
|
|
124
|
+
const metadata = filesByKey.get(key);
|
|
125
|
+
return metadata
|
|
126
|
+
? { ...el, file_name: attachmentString(el.file_name) || attachmentString(metadata.file_name) }
|
|
127
|
+
: el;
|
|
128
|
+
});
|
|
129
|
+
const title = attachmentString(post.title);
|
|
130
|
+
const first = result[0];
|
|
131
|
+
const titleAlreadyInBody = first && (first.tag === "text" || first.tag === "p")
|
|
132
|
+
&& attachmentString(first.text) === title;
|
|
133
|
+
if (title && !titleAlreadyInBody)
|
|
134
|
+
result.unshift({ tag: "text", text: title });
|
|
135
|
+
// Top-level files have no inline position; append in their original order.
|
|
136
|
+
for (const file of files) {
|
|
137
|
+
const key = attachmentString(file.file_key);
|
|
138
|
+
if (key && seenFileKeys.has(key))
|
|
139
|
+
continue;
|
|
140
|
+
if (key)
|
|
141
|
+
seenFileKeys.add(key);
|
|
142
|
+
result.push({ ...file, tag: "file" });
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
101
145
|
}
|
|
102
146
|
function attachmentString(value) {
|
|
103
147
|
return typeof value === "string" ? value.trim() : "";
|
|
@@ -175,24 +219,14 @@ function getPostImageKey(el) {
|
|
|
175
219
|
return undefined;
|
|
176
220
|
}
|
|
177
221
|
async function formatPostContentWithAttachments(content, messageId) {
|
|
178
|
-
const paragraphs = getPostParagraphs(content);
|
|
179
|
-
if (!Array.isArray(paragraphs))
|
|
180
|
-
return "";
|
|
181
222
|
const parts = [];
|
|
182
|
-
for (const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const text = formatPostTextElement(el, messageId);
|
|
190
|
-
if (text)
|
|
191
|
-
parts.push(text);
|
|
192
|
-
const imageKey = getPostImageKey(el);
|
|
193
|
-
if (imageKey) {
|
|
194
|
-
parts.push(await formatPostImageElement(messageId, imageKey));
|
|
195
|
-
}
|
|
223
|
+
for (const el of getPostElements(content)) {
|
|
224
|
+
const text = formatPostTextElement(el, messageId);
|
|
225
|
+
if (text)
|
|
226
|
+
parts.push(text);
|
|
227
|
+
const imageKey = getPostImageKey(el);
|
|
228
|
+
if (imageKey) {
|
|
229
|
+
parts.push(await formatPostImageElement(messageId, imageKey));
|
|
196
230
|
}
|
|
197
231
|
}
|
|
198
232
|
return parts.join("\n").trim();
|