openclaw-lark-multi-agent 1.0.7 → 1.0.8
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/dist/feishu-bot.d.ts +1 -0
- package/dist/feishu-bot.js +37 -19
- package/dist/openclaw-client.js +1 -1
- package/dist/paths.js +1 -1
- package/package.json +1 -1
package/dist/feishu-bot.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export declare class FeishuBot {
|
|
|
98
98
|
private runDiscussionTurn;
|
|
99
99
|
private replyMessage;
|
|
100
100
|
private extractBridgeAttachments;
|
|
101
|
+
private pushBridgeAttachment;
|
|
101
102
|
private validateBridgeAttachmentPath;
|
|
102
103
|
private inferFeishuFileType;
|
|
103
104
|
private isImagePath;
|
package/dist/feishu-bot.js
CHANGED
|
@@ -2,14 +2,13 @@ import * as lark from "@larksuiteoapi/node-sdk";
|
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "fs";
|
|
4
4
|
import { basename, extname, resolve } from "path";
|
|
5
|
-
import {
|
|
5
|
+
import { getBridgeAttachmentsDir } from "./paths.js";
|
|
6
6
|
import { buildFeishuCardElements } from "./markdown.js";
|
|
7
7
|
import { discussionManager } from "./discussion-manager.js";
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
const LMA_VERSION = require("../package.json").version;
|
|
10
10
|
const MAX_BOT_STREAK = 10;
|
|
11
11
|
const BRIDGE_ATTACHMENTS_DIR = getBridgeAttachmentsDir();
|
|
12
|
-
const BRIDGE_ATTACHMENT_ALLOWED_ROOTS = getBridgeAttachmentAllowedRoots();
|
|
13
12
|
/**
|
|
14
13
|
* Manages a single Feishu bot instance.
|
|
15
14
|
*
|
|
@@ -762,9 +761,17 @@ export class FeishuBot {
|
|
|
762
761
|
console.warn(`[${this.config.name}] Reply already delivered, skip duplicate for ${chatId.slice(-8)} msgId=${triggerId}`);
|
|
763
762
|
}
|
|
764
763
|
else {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
764
|
+
try {
|
|
765
|
+
await this.enqueueAndDispatchDelivery(chatId, "assistant_visible", this.deliverySourceId("visible", `${(shouldReply ? visibleReply : "").trim()}|${JSON.stringify(parsedReply.attachments)}`), shouldReply ? visibleReply : "", parsedReply.attachments, lastHuman.messageId, `trigger:${triggerId}`);
|
|
766
|
+
if (triggerId)
|
|
767
|
+
this.store.markDeliveredReply(this.config.name, chatId, triggerId, lastHuman.messageId);
|
|
768
|
+
}
|
|
769
|
+
catch (err) {
|
|
770
|
+
// enqueueAndDispatchDelivery already sent a user-visible delivery
|
|
771
|
+
// failure. Do not fall through to the generic provider-error path;
|
|
772
|
+
// that creates a second misleading "bot did not complete" message.
|
|
773
|
+
console.warn(`[${this.config.name}] assistant delivery failed after notification:`, this.errorSummary(err));
|
|
774
|
+
}
|
|
768
775
|
}
|
|
769
776
|
}
|
|
770
777
|
if (isRuntimeFailure && lastHuman.messageId) {
|
|
@@ -1178,29 +1185,39 @@ export class FeishuBot {
|
|
|
1178
1185
|
try {
|
|
1179
1186
|
const parsed = JSON.parse(String(jsonText).trim());
|
|
1180
1187
|
const rawAttachments = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.attachments) ? parsed.attachments : [parsed];
|
|
1181
|
-
for (const item of rawAttachments)
|
|
1182
|
-
|
|
1183
|
-
continue;
|
|
1184
|
-
attachments.push({
|
|
1185
|
-
type: item.type === "image" || item.type === "document" || item.type === "file" ? item.type : undefined,
|
|
1186
|
-
path: item.path,
|
|
1187
|
-
caption: typeof item.caption === "string" ? item.caption : undefined,
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1188
|
+
for (const item of rawAttachments)
|
|
1189
|
+
this.pushBridgeAttachment(attachments, item);
|
|
1190
1190
|
}
|
|
1191
1191
|
catch (err) {
|
|
1192
1192
|
console.warn(`[${this.config.name}] Failed to parse bridge attachment marker:`, err.message);
|
|
1193
1193
|
}
|
|
1194
1194
|
return "";
|
|
1195
|
+
});
|
|
1196
|
+
// Compatibility fallback for agents that use OpenClaw's channel directive
|
|
1197
|
+
// syntax instead of the LMA marker. In Feishu/LMA, leaving MEDIA:<path> in
|
|
1198
|
+
// plain text only shows the path, so parse it into bridge attachments.
|
|
1199
|
+
const mediaDirectivePattern = /^\s*MEDIA:(.+)$/gm;
|
|
1200
|
+
text = text.replace(mediaDirectivePattern, (_match, rawPath) => {
|
|
1201
|
+
const mediaPath = String(rawPath).trim();
|
|
1202
|
+
if (!mediaPath)
|
|
1203
|
+
return "";
|
|
1204
|
+
const cleanPath = mediaPath.replace(/^['\"]|['\"]$/g, "");
|
|
1205
|
+
attachments.push({ type: this.isImagePath(cleanPath) ? "image" : "file", path: cleanPath });
|
|
1206
|
+
return "";
|
|
1195
1207
|
}).trim();
|
|
1196
1208
|
return { text, attachments };
|
|
1197
1209
|
}
|
|
1210
|
+
pushBridgeAttachment(attachments, item) {
|
|
1211
|
+
if (!item || typeof item.path !== "string")
|
|
1212
|
+
return;
|
|
1213
|
+
attachments.push({
|
|
1214
|
+
type: item.type === "image" || item.type === "document" || item.type === "file" ? item.type : undefined,
|
|
1215
|
+
path: item.path,
|
|
1216
|
+
caption: typeof item.caption === "string" ? item.caption : undefined,
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1198
1219
|
validateBridgeAttachmentPath(filePath) {
|
|
1199
1220
|
const resolvedPath = resolve(filePath);
|
|
1200
|
-
const isAllowed = BRIDGE_ATTACHMENT_ALLOWED_ROOTS.some((root) => resolvedPath === root || resolvedPath.startsWith(root + "/"));
|
|
1201
|
-
if (!isAllowed) {
|
|
1202
|
-
throw new Error(`Attachment path outside allowed directories (${BRIDGE_ATTACHMENT_ALLOWED_ROOTS.join(", ")}): ${resolvedPath}`);
|
|
1203
|
-
}
|
|
1204
1221
|
if (!existsSync(resolvedPath))
|
|
1205
1222
|
throw new Error(`Attachment file not found: ${resolvedPath}`);
|
|
1206
1223
|
const stats = statSync(resolvedPath);
|
|
@@ -1634,7 +1651,8 @@ export class FeishuBot {
|
|
|
1634
1651
|
async downloadResource(messageId, fileKey, type) {
|
|
1635
1652
|
const { mkdirSync, writeFileSync } = await import("fs");
|
|
1636
1653
|
const { resolve } = await import("path");
|
|
1637
|
-
const
|
|
1654
|
+
const { getStateDir } = await import("./paths.js");
|
|
1655
|
+
const dir = resolve(getStateDir(), "data", "media");
|
|
1638
1656
|
mkdirSync(dir, { recursive: true });
|
|
1639
1657
|
const resp = await this.client.im.messageResource.get({
|
|
1640
1658
|
path: { message_id: messageId, file_key: fileKey },
|
package/dist/openclaw-client.js
CHANGED
|
@@ -867,7 +867,7 @@ export class OpenClawClient {
|
|
|
867
867
|
return "";
|
|
868
868
|
return `
|
|
869
869
|
|
|
870
|
-
[Bridge attachment capability hint: This is an OpenClaw Lark Multi-Agent bridge session. You cannot send Feishu files/images directly from inside OpenClaw. Do NOT call message, sessions_send, Feishu tools, or proactive send tools for this request. If the user asks you to send an image/file/document to Feishu,
|
|
870
|
+
[Bridge attachment capability hint: This is an OpenClaw Lark Multi-Agent bridge session. You cannot send Feishu files/images directly from inside OpenClaw. Do NOT call message, sessions_send, Feishu tools, or proactive send tools for this request. If the user asks you to send an image/file/document to Feishu, save or copy the real file under ${BRIDGE_ATTACHMENTS_DIR}/, or use an existing real file under the OpenClaw workspace. NEVER use placeholder paths such as /absolute/path, /real/path, /path/to/file, or example paths; the path must be the actual file you created and it must exist. Include this exact marker at the very end of your final reply (do not explain or expose the marker as normal text): <LMA_BRIDGE_ATTACHMENTS>{"attachments":[{"type":"image","path":"${BRIDGE_ATTACHMENTS_DIR}/replace-with-actual-created-file.png","caption":"optional"}]}</LMA_BRIDGE_ATTACHMENTS>. Replace the example path with the actual existing file path before replying. The bridge layer will parse this marker and send the attachment. Use type=image for images; use type=document for Markdown documents (.md) so the bridge creates a Feishu cloud document and sends its link; use type=file for other ordinary files.]`;
|
|
871
871
|
}
|
|
872
872
|
/**
|
|
873
873
|
* Build and send a context catch-up message followed by the actual message.
|
package/dist/paths.js
CHANGED
|
@@ -14,7 +14,7 @@ export function getOpenClawWorkspaceDir() {
|
|
|
14
14
|
return resolve(process.env.OPENCLAW_WORKSPACE_DIR || resolve(homedir(), ".openclaw/workspace"));
|
|
15
15
|
}
|
|
16
16
|
export function getBridgeAttachmentAllowedRoots() {
|
|
17
|
-
const roots = [getBridgeAttachmentsDir(), getOpenClawWorkspaceDir()];
|
|
17
|
+
const roots = [getBridgeAttachmentsDir(), getOpenClawWorkspaceDir(), resolve(getStateDir(), "data", "media")];
|
|
18
18
|
const extra = process.env.OPENCLAW_LARK_MULTI_AGENT_ATTACHMENT_ALLOW_ROOTS || "";
|
|
19
19
|
for (const part of extra.split(",")) {
|
|
20
20
|
const trimmed = part.trim();
|