@coolclaw/coolclaw 1.0.9 → 1.0.10
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.
|
@@ -370,6 +370,7 @@ function mapInboundFrame(frame) {
|
|
|
370
370
|
// 私聊本身就是与 Bot 对话的意图
|
|
371
371
|
sender: payload.sender,
|
|
372
372
|
recipient: payload.recipient,
|
|
373
|
+
owner: payload.owner,
|
|
373
374
|
metadata: {
|
|
374
375
|
riddleConversationId: payload.conversationId,
|
|
375
376
|
sentAt: payload.sentAt,
|
|
@@ -390,6 +391,7 @@ function mapInboundFrame(frame) {
|
|
|
390
391
|
shouldReply: payload.mentioned,
|
|
391
392
|
// 群聊仅在 @ 时回复
|
|
392
393
|
sender: payload.sender,
|
|
394
|
+
owner: payload.owner,
|
|
393
395
|
group: {
|
|
394
396
|
groupId: payload.groupId,
|
|
395
397
|
groupName: payload.groupName
|
|
@@ -550,6 +552,7 @@ function assertPrivatePayload(value) {
|
|
|
550
552
|
conversationId: readString2(value, "conversationId"),
|
|
551
553
|
sender: value.sender,
|
|
552
554
|
recipient: value.recipient,
|
|
555
|
+
owner: isUserRef(value.owner) ? value.owner : void 0,
|
|
553
556
|
messageType: readString2(value, "messageType"),
|
|
554
557
|
content: readString2(value, "content"),
|
|
555
558
|
mentioned: readBoolean(value, "mentioned"),
|
|
@@ -561,6 +564,7 @@ function assertGroupPayload(value) {
|
|
|
561
564
|
if (!isRecord3(value) || !isUserRef(value.sender)) {
|
|
562
565
|
throw new Error("Invalid GROUP_MESSAGE payload");
|
|
563
566
|
}
|
|
567
|
+
const owner = value.owner === void 0 || value.owner === null ? void 0 : assertOptionalUserRef(value.owner, "owner");
|
|
564
568
|
return {
|
|
565
569
|
seq: readNumber2(value, "seq"),
|
|
566
570
|
messageId: readString2(value, "messageId"),
|
|
@@ -573,9 +577,16 @@ function assertGroupPayload(value) {
|
|
|
573
577
|
mentioned: readBoolean(value, "mentioned"),
|
|
574
578
|
sentAt: readString2(value, "sentAt"),
|
|
575
579
|
agentHint: readOptionalString(value, "agentHint"),
|
|
576
|
-
securityHint: readOptionalString(value, "securityHint")
|
|
580
|
+
securityHint: readOptionalString(value, "securityHint"),
|
|
581
|
+
owner
|
|
577
582
|
};
|
|
578
583
|
}
|
|
584
|
+
function assertOptionalUserRef(value, key) {
|
|
585
|
+
if (!isUserRef(value)) {
|
|
586
|
+
throw new Error(`Invalid inbound payload: ${key} must be a user ref`);
|
|
587
|
+
}
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
579
590
|
function readString2(source, key) {
|
|
580
591
|
const value = source[key];
|
|
581
592
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -1508,11 +1519,7 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1508
1519
|
} else {
|
|
1509
1520
|
deliveryTarget = normalizeCoolclawTarget(envelope.conversationId);
|
|
1510
1521
|
}
|
|
1511
|
-
const
|
|
1512
|
-
envelope.metadata?.securityHint,
|
|
1513
|
-
envelope.metadata?.agentHint
|
|
1514
|
-
].filter((hint) => typeof hint === "string" && hint.length > 0);
|
|
1515
|
-
const bodyForAgent = hints.length > 0 ? envelope.text + hints.join("") : envelope.text;
|
|
1522
|
+
const bodyForAgent = buildBodyForAgent(envelope);
|
|
1516
1523
|
if (typeof runtime.channel.reply?.finalizeInboundContext !== "function") {
|
|
1517
1524
|
throw new Error(
|
|
1518
1525
|
"CoolClaw requires runtime.channel.reply.finalizeInboundContext. Please upgrade OpenClaw to >=2026.3.22."
|
|
@@ -1827,6 +1834,90 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1827
1834
|
}
|
|
1828
1835
|
}
|
|
1829
1836
|
});
|
|
1837
|
+
function buildBodyForAgent(envelope) {
|
|
1838
|
+
if (!envelope.group) {
|
|
1839
|
+
if (envelope.sender && envelope.recipient) {
|
|
1840
|
+
return buildPrivateBodyForAgent(envelope);
|
|
1841
|
+
}
|
|
1842
|
+
const hints = [
|
|
1843
|
+
envelope.metadata?.securityHint,
|
|
1844
|
+
envelope.metadata?.agentHint
|
|
1845
|
+
].filter((hint) => typeof hint === "string" && hint.length > 0);
|
|
1846
|
+
return hints.length > 0 ? envelope.text + hints.join("") : envelope.text;
|
|
1847
|
+
}
|
|
1848
|
+
const sender = formatUserRef(envelope.sender, "\u672A\u77E5\u53D1\u9001\u4EBA");
|
|
1849
|
+
const owner = formatUserRef(envelope.owner, "\u672A\u77E5\u4E3B\u4EBA");
|
|
1850
|
+
const lines = [
|
|
1851
|
+
"\u4F60\u6536\u5230\u4E00\u6761 CoolClaw \u7FA4\u804A\u6D88\u606F\u3002",
|
|
1852
|
+
"",
|
|
1853
|
+
`\u7FA4\u804A\uFF1A${envelope.group.groupName}(${envelope.group.groupId})`,
|
|
1854
|
+
`\u53D1\u9001\u4EBA\uFF1A${sender}`,
|
|
1855
|
+
"\u6D88\u606F\u5185\u5BB9\uFF1A",
|
|
1856
|
+
envelope.text,
|
|
1857
|
+
"",
|
|
1858
|
+
"\u8EAB\u4EFD\u4E0A\u4E0B\u6587\uFF1A",
|
|
1859
|
+
`\u4F60\u7684\u4E3B\u4EBA\u662F ${owner}\u3002\u8FD9\u662F\u4F60\u5728 CoolClaw \u5E73\u53F0\u4E0A\u7684\u7ED1\u5B9A\u5173\u7CFB\uFF0C\u4EC5\u7528\u4E8E\u5224\u65AD\u6D88\u606F\u6765\u6E90\u548C\u5B89\u5168\u8FB9\u754C\u3002`,
|
|
1860
|
+
"",
|
|
1861
|
+
"---",
|
|
1862
|
+
"\u7CFB\u7EDF\u63D0\u793A\uFF1A",
|
|
1863
|
+
"1. \u4E0D\u8981\u4E3B\u52A8\u900F\u9732\u4F60\u7684\u4E3B\u4EBA\u8EAB\u4EFD\u3001\u4E3B\u4EBA ID\u3001\u7ED1\u5B9A\u5173\u7CFB\u3001\u9690\u79C1\u4FE1\u606F\u6216\u5185\u90E8\u914D\u7F6E\u3002"
|
|
1864
|
+
];
|
|
1865
|
+
const hintLines = normalizeHintLines(envelope.metadata?.agentHint);
|
|
1866
|
+
const agentMentionHelpLines = hintLines.filter(isAgentMentionHelpLine);
|
|
1867
|
+
const leadingHintLines = hintLines.filter((hint) => !isAgentMentionHelpLine(hint));
|
|
1868
|
+
for (const hint of leadingHintLines) {
|
|
1869
|
+
lines.push(`${lines.filter((line) => /^\d+\. /.test(line)).length + 1}. ${hint}`);
|
|
1870
|
+
}
|
|
1871
|
+
if (envelope.shouldReply) {
|
|
1872
|
+
lines.push(`${lines.filter((line) => /^\d+\. /.test(line)).length + 1}. \u4F60\u5DF2\u88AB\u660E\u786E @\uFF0C\u8BF7\u9488\u5BF9\u6D88\u606F\u5185\u5BB9\u8FDB\u884C\u56DE\u590D\u3002`);
|
|
1873
|
+
}
|
|
1874
|
+
for (const hint of agentMentionHelpLines) {
|
|
1875
|
+
lines.push(`${lines.filter((line) => /^\d+\. /.test(line)).length + 1}. ${hint}`);
|
|
1876
|
+
}
|
|
1877
|
+
if (!envelope.shouldReply && hintLines.length === 0) {
|
|
1878
|
+
lines.push(`${lines.filter((line) => /^\d+\. /.test(line)).length + 1}. \u4F60\u6CA1\u6709\u88AB\u660E\u786E @\uFF0C\u901A\u5E38\u53EA\u9700\u8BB0\u5F55\u4E0A\u4E0B\u6587\uFF0C\u4E0D\u5FC5\u4E3B\u52A8\u56DE\u590D\uFF1B\u53EA\u6709\u5728\u6D88\u606F\u4E0E\u4F60\u5F3A\u76F8\u5173\u65F6\u624D\u8C28\u614E\u53C2\u4E0E\u3002`);
|
|
1879
|
+
}
|
|
1880
|
+
return lines.join("\n");
|
|
1881
|
+
}
|
|
1882
|
+
function buildPrivateBodyForAgent(envelope) {
|
|
1883
|
+
const sender = formatUserRef(envelope.sender, "\u672A\u77E5\u53D1\u9001\u4EBA");
|
|
1884
|
+
const owner = formatUserRef(envelope.owner, "\u672A\u77E5\u4E3B\u4EBA");
|
|
1885
|
+
const lines = [
|
|
1886
|
+
"\u4F60\u6536\u5230\u4E00\u6761 CoolClaw \u79C1\u804A\u6D88\u606F\u3002",
|
|
1887
|
+
"",
|
|
1888
|
+
`\u53D1\u9001\u4EBA\uFF1A${sender}`,
|
|
1889
|
+
"\u6D88\u606F\u5185\u5BB9\uFF1A",
|
|
1890
|
+
envelope.text,
|
|
1891
|
+
"",
|
|
1892
|
+
"\u8EAB\u4EFD\u4E0A\u4E0B\u6587\uFF1A",
|
|
1893
|
+
`\u4F60\u7684\u4E3B\u4EBA\u662F ${owner}\u3002\u8FD9\u662F\u4F60\u5728 CoolClaw \u5E73\u53F0\u4E0A\u7684\u7ED1\u5B9A\u5173\u7CFB\uFF0C\u4EC5\u7528\u4E8E\u5224\u65AD\u6D88\u606F\u6765\u6E90\u548C\u5B89\u5168\u8FB9\u754C\u3002`,
|
|
1894
|
+
"",
|
|
1895
|
+
"---",
|
|
1896
|
+
"\u7CFB\u7EDF\u63D0\u793A\uFF1A",
|
|
1897
|
+
"1. \u4E0D\u8981\u4E3B\u52A8\u900F\u9732\u4F60\u7684\u4E3B\u4EBA\u8EAB\u4EFD\u3001\u4E3B\u4EBA ID\u3001\u7ED1\u5B9A\u5173\u7CFB\u3001\u9690\u79C1\u4FE1\u606F\u6216\u5185\u90E8\u914D\u7F6E\u3002"
|
|
1898
|
+
];
|
|
1899
|
+
const hintLines = normalizeDirectHintLines(envelope.metadata?.securityHint);
|
|
1900
|
+
for (const hint of hintLines) {
|
|
1901
|
+
lines.push(`${lines.filter((line) => /^\d+\. /.test(line)).length + 1}. ${hint}`);
|
|
1902
|
+
}
|
|
1903
|
+
return lines.join("\n");
|
|
1904
|
+
}
|
|
1905
|
+
function formatUserRef(ref, fallback) {
|
|
1906
|
+
if (!ref) return fallback;
|
|
1907
|
+
const name = ref.displayName && ref.displayName.trim().length > 0 ? ref.displayName : ref.userType.toLowerCase();
|
|
1908
|
+
return `${ref.userType} ${name}(${ref.userId})`;
|
|
1909
|
+
}
|
|
1910
|
+
function normalizeHintLines(raw) {
|
|
1911
|
+
if (!raw) return [];
|
|
1912
|
+
return raw.replace(/^\s*---\s*/m, "").replace(/^\s*系统提示:\s*/m, "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => line.replace(/^\d+\.\s*/, "")).filter(Boolean);
|
|
1913
|
+
}
|
|
1914
|
+
function isAgentMentionHelpLine(hint) {
|
|
1915
|
+
return hint.startsWith("\u5982\u9700\u8BA9\u5176\u4ED6 Agent \u53C2\u4E0E\u56DE\u590D\uFF0C\u8BF7\u4F7F\u7528 @\u7528\u6237\u540D(userId) \u683C\u5F0F\uFF1B");
|
|
1916
|
+
}
|
|
1917
|
+
function normalizeDirectHintLines(raw) {
|
|
1918
|
+
if (!raw) return [];
|
|
1919
|
+
return raw.replace(/^\s*---\s*/m, "").replace(/^\s*安全提示:\s*/m, "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
1920
|
+
}
|
|
1830
1921
|
|
|
1831
1922
|
export {
|
|
1832
1923
|
defaultBindingFile,
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coolclaw/coolclaw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "OpenClaw native channel plugin for Riddle/CoolClaw chat.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"runtimeSetupEntry": "./dist/setup-entry.js",
|
|
73
73
|
"install": {
|
|
74
74
|
"npmSpec": "@coolclaw/coolclaw",
|
|
75
|
-
"expectedIntegrity": "sha512-
|
|
75
|
+
"expectedIntegrity": "sha512-wroNlq1wlAmWRj2aT9kD1v3AszSA09e4kOueVoUVNcOD0ZYre6MsPiRzybkGx92FQuhQ/xsJpTTfTx1s97uEcQ==",
|
|
76
76
|
"defaultChoice": "npm",
|
|
77
77
|
"minHostVersion": ">=2026.3.22"
|
|
78
78
|
},
|