chatccc 0.2.301 → 0.2.302
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 +2 -1
- package/dist/src/format-message.js +38 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,8 @@ ChatCCC 把本地 AI 编程工具接入即时通讯软件。你可以在手机
|
|
|
22
22
|
- **飞书体验更完整**:私聊可持续对话,`/new` 创建的一群一会话支持多任务并行,CardKit 卡片可流式更新。
|
|
23
23
|
- **微信接入更轻**:不用创建飞书应用,启动后扫码即可在微信私聊里使用。
|
|
24
24
|
- **多 Agent 切换**:`/new` 使用默认 Agent,也可以用 `/new claude`、`/new cursor`、`/new codex`、`/new ccc`、`/new dsh` 指定工具。
|
|
25
|
-
- **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
|
|
25
|
+
- **群里能跑 git**:`/git status`、`/git pull`、`/git log` 会在当前会话工作目录执行,并把输出发回聊天窗口。
|
|
26
|
+
- **飞书混合附件不丢失**:同一条富文本中的文字、图片、视频和文件按顺序传给 Agent;视频保留原附件下载信息,不把封面误当成原视频。附件信息不完整时会明确提示。视频和文件仍由 Agent 按需下载处理,不代表模型原生支持视频输入。
|
|
26
27
|
|
|
27
28
|
## 飞书和微信的差异
|
|
28
29
|
|
|
@@ -32,7 +32,7 @@ export async function formatMessageContent(message) {
|
|
|
32
32
|
return text.trim();
|
|
33
33
|
}
|
|
34
34
|
if (message.message_type === "post") {
|
|
35
|
-
return
|
|
35
|
+
return formatPostContentWithAttachments(content, message.message_id);
|
|
36
36
|
}
|
|
37
37
|
if (message.message_type === "image") {
|
|
38
38
|
const imageKey = content.image_key;
|
|
@@ -50,20 +50,10 @@ export async function formatMessageContent(message) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
if (message.message_type === "media") {
|
|
53
|
-
|
|
54
|
-
const fileName = content.file_name || "video.mp4";
|
|
55
|
-
const messageId = message.message_id;
|
|
56
|
-
if (!fileKey || !messageId)
|
|
57
|
-
return contentStr;
|
|
58
|
-
return `[视频] message_id=${messageId} file_key=${fileKey} file_name=${fileName}`;
|
|
53
|
+
return formatFileAttachment("media", content, message.message_id);
|
|
59
54
|
}
|
|
60
55
|
if (message.message_type === "file") {
|
|
61
|
-
|
|
62
|
-
const fileName = content.file_name || "download.bin";
|
|
63
|
-
const messageId = message.message_id;
|
|
64
|
-
if (!fileKey || !messageId)
|
|
65
|
-
return contentStr;
|
|
66
|
-
return `[文件] message_id=${messageId} file_key=${fileKey} file_name=${fileName}`;
|
|
56
|
+
return formatFileAttachment("file", content, message.message_id);
|
|
67
57
|
}
|
|
68
58
|
if (message.message_type === "interactive") {
|
|
69
59
|
const raw = JSON.stringify(content);
|
|
@@ -109,8 +99,32 @@ function getPostParagraphs(content) {
|
|
|
109
99
|
}
|
|
110
100
|
return [];
|
|
111
101
|
}
|
|
112
|
-
function
|
|
102
|
+
function attachmentString(value) {
|
|
103
|
+
return typeof value === "string" ? value.trim() : "";
|
|
104
|
+
}
|
|
105
|
+
/** Preserve downloadable resource metadata; a media image_key is only its cover. */
|
|
106
|
+
function formatFileAttachment(type, content, messageId) {
|
|
107
|
+
const fileKey = attachmentString(content.file_key);
|
|
108
|
+
const fileName = attachmentString(content.file_name) || (type === "media" ? "video.mp4" : "download.bin");
|
|
109
|
+
const coverKey = type === "media" ? attachmentString(content.image_key) : "";
|
|
110
|
+
const parts = [type === "media" ? "[视频]" : "[文件]"];
|
|
111
|
+
if (messageId)
|
|
112
|
+
parts.push(`message_id=${messageId}`);
|
|
113
|
+
if (fileKey)
|
|
114
|
+
parts.push(`file_key=${fileKey}`);
|
|
115
|
+
parts.push(`file_name=${fileName}`);
|
|
116
|
+
if (coverKey)
|
|
117
|
+
parts.push(`cover_image_key=${coverKey}`);
|
|
118
|
+
const missing = [!messageId ? "message_id" : "", !fileKey ? "file_key" : ""].filter(Boolean);
|
|
119
|
+
if (missing.length)
|
|
120
|
+
parts.push(`(附件元数据不完整:缺少 ${missing.join("、")},无法下载原附件)`);
|
|
121
|
+
return parts.join(" ");
|
|
122
|
+
}
|
|
123
|
+
function formatPostTextElement(el, messageId) {
|
|
113
124
|
const t = typeof el.text === "string" ? el.text : "";
|
|
125
|
+
if (el.tag === "media" || el.tag === "file") {
|
|
126
|
+
return formatFileAttachment(el.tag, el, messageId);
|
|
127
|
+
}
|
|
114
128
|
// 超链接元素:必须保留 URL,否则 AI 拿不到链接(飞书 post 里链接是独立元素,
|
|
115
129
|
// 不与相邻 text 合并)。文本与 URL 相同时只输出 URL,避免 "url (url)" 冗余。
|
|
116
130
|
if (el.tag === "a") {
|
|
@@ -129,7 +143,7 @@ function formatPostTextElement(el) {
|
|
|
129
143
|
return t;
|
|
130
144
|
}
|
|
131
145
|
// 图片元素由 getPostImageKey 单独处理(可能带 image_key/file_key),此处不重复输出。
|
|
132
|
-
if (el.tag === "img"
|
|
146
|
+
if (el.tag === "img")
|
|
133
147
|
return "";
|
|
134
148
|
// 兜底:飞书可能新增富文本元素类型,而历史上曾因入口重写而整类元素被静默丢弃
|
|
135
149
|
// (见 tag="a" 丢失链接)。未知 tag 不再静默丢弃,尽量透传可读内容并留 warn 日志,
|
|
@@ -140,11 +154,16 @@ function formatPostTextElement(el) {
|
|
|
140
154
|
const fallback = t && href && t !== href
|
|
141
155
|
? `[${t}](${href})`
|
|
142
156
|
: t || href || (userName ? `@${userName}` : "");
|
|
157
|
+
// Unknown attachment types must not be mistaken for images or silently lost.
|
|
158
|
+
const attachment = el.file_key || el.image_key ? `[未知附件] ${JSON.stringify(el)}` : "";
|
|
159
|
+
const readable = [fallback, attachment].filter(Boolean).join("\n");
|
|
143
160
|
console.warn(`[${ts()}] [POST] 未知富文本元素 tag=${tag},` +
|
|
144
|
-
(
|
|
145
|
-
return
|
|
161
|
+
(readable ? `已降级透传:${readable}` : "无可透传内容,已丢弃(请补充分支)"));
|
|
162
|
+
return readable;
|
|
146
163
|
}
|
|
147
164
|
function getPostImageKey(el) {
|
|
165
|
+
if (el.tag !== "img")
|
|
166
|
+
return undefined;
|
|
148
167
|
const imageKey = el.image_key;
|
|
149
168
|
if (typeof imageKey === "string" && imageKey.trim())
|
|
150
169
|
return imageKey;
|
|
@@ -155,7 +174,7 @@ function getPostImageKey(el) {
|
|
|
155
174
|
}
|
|
156
175
|
return undefined;
|
|
157
176
|
}
|
|
158
|
-
async function
|
|
177
|
+
async function formatPostContentWithAttachments(content, messageId) {
|
|
159
178
|
const paragraphs = getPostParagraphs(content);
|
|
160
179
|
if (!Array.isArray(paragraphs))
|
|
161
180
|
return "";
|
|
@@ -167,7 +186,7 @@ async function formatPostContentWithImages(content, messageId) {
|
|
|
167
186
|
const el = elem;
|
|
168
187
|
if (!el || typeof el !== "object")
|
|
169
188
|
continue;
|
|
170
|
-
const text = formatPostTextElement(el);
|
|
189
|
+
const text = formatPostTextElement(el, messageId);
|
|
171
190
|
if (text)
|
|
172
191
|
parts.push(text);
|
|
173
192
|
const imageKey = getPostImageKey(el);
|