@xgjktech/xg_cwork_im 1.10.1 → 1.10.3
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/package.json +1 -1
- package/src/channel.ts +11 -9
- package/src/inbound-media-local.ts +13 -4
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -257,8 +257,7 @@ function buildInboundDisplayText(msgContent: WsMessageContent | undefined, fileI
|
|
|
257
257
|
if (fileItems.length > 0) {
|
|
258
258
|
const lines = fileItems.map((f) => {
|
|
259
259
|
const name = f.name?.trim() || f.fileId || "未命名文件";
|
|
260
|
-
|
|
261
|
-
return mime ? `- \`${name}\` (${mime})` : `- \`${name}\``;
|
|
260
|
+
return `- \`${name}\``;
|
|
262
261
|
});
|
|
263
262
|
const block = `**附件(${fileItems.length})**\n${lines.join("\n")}`;
|
|
264
263
|
rawText = rawText.trim() ? `${rawText.trim()}\n\n${block}` : block;
|
|
@@ -275,6 +274,11 @@ function buildInboundDisplayText(msgContent: WsMessageContent | undefined, fileI
|
|
|
275
274
|
const parsedBlock = `**附件解析内容**\n\n${parsedParts.join("\n\n")}`;
|
|
276
275
|
rawText = `${rawText.trim()}\n\n${parsedBlock}`;
|
|
277
276
|
}
|
|
277
|
+
|
|
278
|
+
const urlGuard =
|
|
279
|
+
"**附件 URL 使用约束**\n" +
|
|
280
|
+
"处理附件时必须逐字原样使用消息中提供的完整 URL;禁止修改、删除或重排任何 query 参数。";
|
|
281
|
+
rawText = `${rawText.trim()}\n\n${urlGuard}`;
|
|
278
282
|
}
|
|
279
283
|
return rawText;
|
|
280
284
|
}
|
|
@@ -297,20 +301,15 @@ function isActuallyMentioned(
|
|
|
297
301
|
|
|
298
302
|
function mediaFieldsFromFileItems(fileItems: MsgFileVO[]): Record<string, unknown> {
|
|
299
303
|
if (fileItems.length === 0) return {};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
);
|
|
303
|
-
// OpenClaw 入站展示与媒体拉取以 MediaPath(s) 为准;[media attached: …] 依赖 Path,仅写 MediaUrl 时该段不出现。
|
|
304
|
-
// 不要同时写 Path 与 Url(同链接会被拼成两段,出现 `url | url`)。
|
|
304
|
+
// 只传 MediaPath(s),不传 MediaType(s)。
|
|
305
|
+
// 预签名 URL 的 query 中常含 response-content-type;若额外给 MediaType,模型/工具更容易“改写 URL”导致签名失效。
|
|
305
306
|
if (fileItems.length === 1) {
|
|
306
307
|
return {
|
|
307
308
|
MediaPath: fileItems[0]!.url,
|
|
308
|
-
MediaType: mimes[0],
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
311
|
return {
|
|
312
312
|
MediaPaths: fileItems.map((f) => f.url),
|
|
313
|
-
MediaTypes: mimes,
|
|
314
313
|
};
|
|
315
314
|
}
|
|
316
315
|
|
|
@@ -693,6 +692,9 @@ export const xgCworkImChannelPlugin: XgImChannelPlugin = {
|
|
|
693
692
|
|
|
694
693
|
const inboundSub = config.inboundMediaWorkspaceSubdir?.trim();
|
|
695
694
|
if (inboundSub && fileItems.length > 0 && normalizeInboundWorkspaceSubdir(inboundSub)) {
|
|
695
|
+
log.info(
|
|
696
|
+
`${logPrefix} [inbound-local] enabled subdir=${inboundSub} sender=${senderId ?? "unknown"} files=${fileItems.length} pathStyle=${config.inboundMediaOpenClawPath ?? "workspaceRelative"} sandboxPrefix=${config.inboundMediaSandboxRootPrefix ?? "(none)"}`,
|
|
697
|
+
);
|
|
696
698
|
fileItems = await saveInboundFilesToWorkspace({
|
|
697
699
|
rt,
|
|
698
700
|
cfg: ctx.cfg,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 时间取写入时的本地时区。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
8
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
11
|
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
@@ -177,6 +177,12 @@ export async function saveInboundFilesToWorkspace(args: {
|
|
|
177
177
|
const maxBytes = resolveMaxAttachmentBytes(config);
|
|
178
178
|
const userSeg = sanitizeUserIdForPath(senderUserId ?? "unknown");
|
|
179
179
|
const relParts = normalized.split("/");
|
|
180
|
+
const pathStyle = config.inboundMediaOpenClawPath ?? "workspaceRelative";
|
|
181
|
+
const sandboxPrefix = config.inboundMediaSandboxRootPrefix?.trim() || "";
|
|
182
|
+
|
|
183
|
+
log?.info?.(
|
|
184
|
+
`[cwork_im:inbound-local] begin files=${fileItems.length} cwd=${process.cwd()} workspaceRoot=${workspaceRoot} subdir=${normalized} user=${userSeg} style=${pathStyle} sandboxPrefix=${sandboxPrefix || "(none)"}`,
|
|
185
|
+
);
|
|
180
186
|
|
|
181
187
|
const out: MsgFileVO[] = [];
|
|
182
188
|
for (const item of fileItems) {
|
|
@@ -192,19 +198,22 @@ export async function saveInboundFilesToWorkspace(args: {
|
|
|
192
198
|
const absPath = path.join(dir, localName);
|
|
193
199
|
|
|
194
200
|
try {
|
|
201
|
+
log?.info?.(
|
|
202
|
+
`[cwork_im:inbound-local] prepare src=${srcUrl.slice(0, 120)} dir=${dir} abs=${absPath}`,
|
|
203
|
+
);
|
|
195
204
|
await mkdir(dir, { recursive: true });
|
|
196
205
|
const { buffer } = await downloadMediaBuffer(srcUrl, maxBytes, log);
|
|
197
206
|
await writeFile(absPath, buffer);
|
|
198
|
-
const pathStyle = config.inboundMediaOpenClawPath ?? "workspaceRelative";
|
|
199
207
|
const mediaRef = openClawMediaRefForSavedFile({
|
|
200
208
|
workspaceRoot,
|
|
201
209
|
absPath,
|
|
202
210
|
style: pathStyle,
|
|
203
|
-
sandboxRootPrefix:
|
|
211
|
+
sandboxRootPrefix: sandboxPrefix,
|
|
204
212
|
log,
|
|
205
213
|
});
|
|
214
|
+
const st = await stat(absPath);
|
|
206
215
|
log?.info?.(
|
|
207
|
-
`[cwork_im:inbound-local] saved ${localName} bytes=${buffer.length} abs=${absPath} openclawRef=${mediaRef
|
|
216
|
+
`[cwork_im:inbound-local] saved ${localName} bytes=${buffer.length} stat.size=${st.size} stat.mtime=${st.mtime.toISOString()} abs=${absPath} openclawRef=${mediaRef}`,
|
|
208
217
|
);
|
|
209
218
|
out.push({
|
|
210
219
|
...item,
|