@clawling/clawchat-plugin-openclaw 2026.6.30-4 → 2026.7.1
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/src/api-client.js +13 -0
- package/dist/src/config.js +3 -0
- package/dist/src/friend-request-turn.js +73 -0
- package/dist/src/gate-outcome.js +26 -0
- package/dist/src/inbound.js +11 -0
- package/dist/src/permission-result.js +107 -0
- package/dist/src/permissions.js +6 -0
- package/dist/src/runtime.js +103 -0
- package/dist/src/tools.js +43 -10
- package/dist/src/ws-client.js +19 -6
- package/openclaw.plugin.json +2 -0
- package/package.json +1 -1
- package/src/api-client.ts +23 -0
- package/src/api-types.ts +1 -1
- package/src/config.ts +7 -0
- package/src/friend-request-turn.ts +87 -0
- package/src/gate-outcome.ts +44 -0
- package/src/inbound.ts +28 -0
- package/src/permission-result.ts +128 -0
- package/src/permissions.ts +13 -0
- package/src/runtime.ts +114 -0
- package/src/tools.ts +44 -10
- package/src/ws-client.ts +21 -6
package/dist/src/api-client.js
CHANGED
|
@@ -196,6 +196,7 @@ export function createOpenclawClawlingApiClient(opts) {
|
|
|
196
196
|
code,
|
|
197
197
|
status: res.status,
|
|
198
198
|
path,
|
|
199
|
+
...(env.data !== undefined ? { data: env.data } : {}),
|
|
199
200
|
});
|
|
200
201
|
}
|
|
201
202
|
return env.data;
|
|
@@ -516,5 +517,17 @@ export function createOpenclawClawlingApiClient(opts) {
|
|
|
516
517
|
}
|
|
517
518
|
return { authoritative: true, rows };
|
|
518
519
|
},
|
|
520
|
+
async getMyPermissions() {
|
|
521
|
+
const data = await call("GET", "/v1/agents/me/permissions");
|
|
522
|
+
const byOperation = {};
|
|
523
|
+
let momentVisibility = [];
|
|
524
|
+
for (const [k, v] of Object.entries(data ?? {})) {
|
|
525
|
+
if (k === "moment.visibility")
|
|
526
|
+
momentVisibility = v ?? [];
|
|
527
|
+
else
|
|
528
|
+
byOperation[k] = v;
|
|
529
|
+
}
|
|
530
|
+
return { byOperation, momentVisibility };
|
|
531
|
+
},
|
|
519
532
|
};
|
|
520
533
|
}
|
package/dist/src/config.js
CHANGED
|
@@ -81,6 +81,7 @@ export const openclawClawlingConfigSchema = {
|
|
|
81
81
|
forwardThinking: { type: "boolean" },
|
|
82
82
|
forwardToolCalls: { type: "boolean" },
|
|
83
83
|
richInteractions: { type: "boolean" },
|
|
84
|
+
awarenessNote: { type: "boolean" },
|
|
84
85
|
reconnect: {
|
|
85
86
|
type: "object",
|
|
86
87
|
additionalProperties: false,
|
|
@@ -328,6 +329,7 @@ export function resolveOpenclawClawlingAccount(cfg, env = process.env) {
|
|
|
328
329
|
const forwardThinking = typeof channel.forwardThinking === "boolean" ? channel.forwardThinking : true;
|
|
329
330
|
const forwardToolCalls = typeof channel.forwardToolCalls === "boolean" ? channel.forwardToolCalls : false;
|
|
330
331
|
const richInteractions = typeof channel.richInteractions === "boolean" ? channel.richInteractions : false;
|
|
332
|
+
const awarenessNote = typeof channel.awarenessNote === "boolean" ? channel.awarenessNote : false;
|
|
331
333
|
return {
|
|
332
334
|
accountId: DEFAULT_ACCOUNT_ID,
|
|
333
335
|
name: CHANNEL_ID,
|
|
@@ -353,6 +355,7 @@ export function resolveOpenclawClawlingAccount(cfg, env = process.env) {
|
|
|
353
355
|
forwardThinking,
|
|
354
356
|
forwardToolCalls,
|
|
355
357
|
richInteractions,
|
|
358
|
+
awarenessNote,
|
|
356
359
|
allowFrom: [],
|
|
357
360
|
reconnect: readReconnect(channel.reconnect),
|
|
358
361
|
heartbeat: readHeartbeat(channel.heartbeat),
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic reasoning-turn builder for `friend.request` notify.signal events.
|
|
3
|
+
*
|
|
4
|
+
* When the server fires a `friend.request` signal the runtime dispatches one
|
|
5
|
+
* deduped synthetic `message.send` envelope so the agent can reason about the
|
|
6
|
+
* pending request. The prompt text varies by the current "friend.add" permission
|
|
7
|
+
* policy state: a deny policy yields a decline/inform prompt; ask or allow
|
|
8
|
+
* yields a prompt that instructs the agent to review the request via the
|
|
9
|
+
* `clawchat_list_friend_requests` tool.
|
|
10
|
+
*/
|
|
11
|
+
import { EVENT } from "./protocol-types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Returns canned prompt text for a friend-request reasoning turn based on the
|
|
14
|
+
* current "friend.add" permission policy state.
|
|
15
|
+
*
|
|
16
|
+
* - `deny` → inform the agent it should decline; no accept instruction.
|
|
17
|
+
* - `ask` / `allow` → instruct the agent to review the pending request.
|
|
18
|
+
*/
|
|
19
|
+
export function friendRequestPromptFor(state) {
|
|
20
|
+
if (state === "deny") {
|
|
21
|
+
return [
|
|
22
|
+
"A new friend request has arrived.",
|
|
23
|
+
"Your current friend-add policy is set to deny.",
|
|
24
|
+
"Do not add this contact.",
|
|
25
|
+
"You may inform the requester that you cannot add them at this time.",
|
|
26
|
+
].join(" ");
|
|
27
|
+
}
|
|
28
|
+
return [
|
|
29
|
+
"A new friend request has arrived.",
|
|
30
|
+
"Please review the pending request by calling `clawchat_list_friend_requests`",
|
|
31
|
+
"and decide whether to accept it.",
|
|
32
|
+
].join(" ");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a synthetic `message.send` envelope that triggers one agent reasoning
|
|
36
|
+
* turn for a pending friend request. The envelope shape mirrors the
|
|
37
|
+
* activation-bootstrap envelope; it targets the owner's direct conversation so
|
|
38
|
+
* the agent has context about who it is reasoning for.
|
|
39
|
+
*/
|
|
40
|
+
export function buildFriendRequestEnvelope(params) {
|
|
41
|
+
const { account, state, entityId } = params;
|
|
42
|
+
const text = friendRequestPromptFor(state);
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
return {
|
|
45
|
+
version: "2",
|
|
46
|
+
event: EVENT.MESSAGE_SEND,
|
|
47
|
+
trace_id: `clawchat-plugin-openclaw-friend-request-${entityId}-${now}`,
|
|
48
|
+
emitted_at: now,
|
|
49
|
+
chat_id: account.ownerUserId,
|
|
50
|
+
chat_type: "direct",
|
|
51
|
+
to: { id: account.userId, type: "direct" },
|
|
52
|
+
sender: {
|
|
53
|
+
id: "clawchat-friend-request",
|
|
54
|
+
type: "direct",
|
|
55
|
+
nick_name: "ClawChat",
|
|
56
|
+
},
|
|
57
|
+
payload: {
|
|
58
|
+
message_id: `clawchat-plugin-openclaw-friend-request-${entityId}-${now}`,
|
|
59
|
+
message_mode: "normal",
|
|
60
|
+
message: {
|
|
61
|
+
body: { fragments: [{ kind: "text", text }] },
|
|
62
|
+
context: { mentions: [], reply: null },
|
|
63
|
+
streaming: {
|
|
64
|
+
status: "static",
|
|
65
|
+
sequence: 0,
|
|
66
|
+
mutation_policy: "sealed",
|
|
67
|
+
started_at: null,
|
|
68
|
+
completed_at: null,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps backend owner-approval gate codes to structured tool outcomes.
|
|
3
|
+
*
|
|
4
|
+
* Backend gate codes (confirmed live contract):
|
|
5
|
+
* 21001 — pending owner approval (payload: { request_id, operation, expires_at })
|
|
6
|
+
* 21003 — policy forbidden (payload: { operation })
|
|
7
|
+
*
|
|
8
|
+
* Returns null for any other code so callers can fall through to normal handling.
|
|
9
|
+
*/
|
|
10
|
+
export function mapGateOutcome(code, data) {
|
|
11
|
+
if (code === 21001) {
|
|
12
|
+
return {
|
|
13
|
+
status: "pending_owner_approval",
|
|
14
|
+
request_id: typeof data.request_id === "string" ? data.request_id : "",
|
|
15
|
+
operation: typeof data.operation === "string" ? data.operation : "",
|
|
16
|
+
expires_at: typeof data.expires_at === "number" ? data.expires_at : 0,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (code === 21003) {
|
|
20
|
+
return {
|
|
21
|
+
status: "forbidden_by_owner",
|
|
22
|
+
operation: typeof data.operation === "string" ? data.operation : "",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
package/dist/src/inbound.js
CHANGED
|
@@ -115,6 +115,17 @@ export async function dispatchOpenclawClawlingInbound(params) {
|
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
if (sender.id === "system") {
|
|
118
|
+
// Intercept `permission_result` receipts before the generic system-message
|
|
119
|
+
// drop. The discriminator is `payload.metadata.kind === "permission_result"`;
|
|
120
|
+
// all other system messages (group-join notifications, etc.) still drop.
|
|
121
|
+
const rawPayload = envelope.payload;
|
|
122
|
+
const meta = rawPayload.metadata;
|
|
123
|
+
if (params.consumePermissionResult &&
|
|
124
|
+
meta != null &&
|
|
125
|
+
meta.kind === "permission_result") {
|
|
126
|
+
await params.consumePermissionResult(meta);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
118
129
|
log?.info?.(`[${account.accountId}] clawchat-plugin-openclaw skip system message msg=${payload.message_id}`);
|
|
119
130
|
return;
|
|
120
131
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consumer for `permission_result` system-message receipts.
|
|
3
|
+
*
|
|
4
|
+
* When the backend delivers a `permission_result` outcome as a
|
|
5
|
+
* `message.send` system frame (`sender.id="system"`, `payload.metadata.kind
|
|
6
|
+
* ="permission_result"`), this module deduplicates by `request_id` and
|
|
7
|
+
* produces a synthetic context-note turn so the agent can close the loop
|
|
8
|
+
* on the original permission request.
|
|
9
|
+
*
|
|
10
|
+
* Wire shape (authoritative):
|
|
11
|
+
* ```
|
|
12
|
+
* payload.metadata = {
|
|
13
|
+
* kind: "permission_result",
|
|
14
|
+
* operation: "friend.add",
|
|
15
|
+
* outcome: "approved" | "denied" | "expired" | "failed",
|
|
16
|
+
* reason: "owner_allowed" | …,
|
|
17
|
+
* request_id: "prq_…",
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
* The discriminator is `payload.metadata.kind === "permission_result"`.
|
|
21
|
+
*/
|
|
22
|
+
import { EVENT } from "./protocol-types.js";
|
|
23
|
+
// Module-level dedup set — `request_id` values are stable backend identifiers.
|
|
24
|
+
// A duplicate receipt (e.g. from WS replay on reconnect) must not re-trigger
|
|
25
|
+
// an agent turn.
|
|
26
|
+
const _seenRequestIds = new Set();
|
|
27
|
+
/**
|
|
28
|
+
* @internal Test helper — reset the dedup set between isolated test runs.
|
|
29
|
+
* Never call this in production code.
|
|
30
|
+
*/
|
|
31
|
+
export function _resetPermissionResultDedup() {
|
|
32
|
+
_seenRequestIds.clear();
|
|
33
|
+
}
|
|
34
|
+
function buildOutcomeNote(metadata) {
|
|
35
|
+
const { operation, outcome, reason } = metadata;
|
|
36
|
+
const outcomeLabel = outcome === "approved"
|
|
37
|
+
? "approved"
|
|
38
|
+
: outcome === "denied"
|
|
39
|
+
? "denied"
|
|
40
|
+
: outcome === "expired"
|
|
41
|
+
? "expired"
|
|
42
|
+
: "failed";
|
|
43
|
+
const resolution = outcome === "approved"
|
|
44
|
+
? "The requested action has been completed."
|
|
45
|
+
: "No further action was taken.";
|
|
46
|
+
return [
|
|
47
|
+
`Permission request for operation "${operation}" has been ${outcomeLabel}.`,
|
|
48
|
+
`Reason: ${reason}.`,
|
|
49
|
+
resolution,
|
|
50
|
+
].join(" ");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Builds a synthetic `message.send` envelope that delivers a
|
|
54
|
+
* `permission_result` context note to the agent.
|
|
55
|
+
*
|
|
56
|
+
* Mirrors the `buildFriendRequestEnvelope` pattern: a synthetic inbound
|
|
57
|
+
* `message.send` targeting the owner's direct conversation, routed through
|
|
58
|
+
* `handleInboundEnvelope` so the agent can reason about the outcome.
|
|
59
|
+
*/
|
|
60
|
+
export function buildPermissionResultEnvelope(params) {
|
|
61
|
+
const { account, metadata } = params;
|
|
62
|
+
const text = buildOutcomeNote(metadata);
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
return {
|
|
65
|
+
version: "2",
|
|
66
|
+
event: EVENT.MESSAGE_SEND,
|
|
67
|
+
trace_id: `clawchat-plugin-openclaw-permission-result-${metadata.request_id}-${now}`,
|
|
68
|
+
emitted_at: now,
|
|
69
|
+
chat_id: account.ownerUserId,
|
|
70
|
+
chat_type: "direct",
|
|
71
|
+
to: { id: account.userId, type: "direct" },
|
|
72
|
+
sender: {
|
|
73
|
+
id: "clawchat-permission-result",
|
|
74
|
+
type: "direct",
|
|
75
|
+
nick_name: "ClawChat",
|
|
76
|
+
},
|
|
77
|
+
payload: {
|
|
78
|
+
message_id: `clawchat-plugin-openclaw-permission-result-${metadata.request_id}-${now}`,
|
|
79
|
+
message_mode: "normal",
|
|
80
|
+
message: {
|
|
81
|
+
body: { fragments: [{ kind: "text", text }] },
|
|
82
|
+
context: { mentions: [], reply: null },
|
|
83
|
+
streaming: {
|
|
84
|
+
status: "static",
|
|
85
|
+
sequence: 0,
|
|
86
|
+
mutation_policy: "sealed",
|
|
87
|
+
started_at: null,
|
|
88
|
+
completed_at: null,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Handles a `permission_result` receipt. Deduplicates by `request_id`
|
|
96
|
+
* (idempotent — WS replay on reconnect may deliver the same receipt again).
|
|
97
|
+
*
|
|
98
|
+
* Returns a synthetic context-note {@link Envelope} on a fresh receipt so
|
|
99
|
+
* the caller can feed it to `handleInboundEnvelope`; returns `null` when
|
|
100
|
+
* the `request_id` has already been processed.
|
|
101
|
+
*/
|
|
102
|
+
export function handlePermissionResult(metadata, account) {
|
|
103
|
+
if (_seenRequestIds.has(metadata.request_id))
|
|
104
|
+
return null;
|
|
105
|
+
_seenRequestIds.add(metadata.request_id);
|
|
106
|
+
return buildPermissionResultEnvelope({ account, metadata });
|
|
107
|
+
}
|
package/dist/src/runtime.js
CHANGED
|
@@ -28,6 +28,9 @@ import { clearClawChatPromptInjectionForSession, stageClawChatPromptInjection, }
|
|
|
28
28
|
import { createGroupMessageCoalescer } from "./group-message-coalescer.js";
|
|
29
29
|
import { openclawLlmContextDebug } from "./llm-context-debug.js";
|
|
30
30
|
import { GroupSettingsCache } from "./group-settings.js";
|
|
31
|
+
import { PermissionCache } from "./permissions.js";
|
|
32
|
+
import { buildFriendRequestEnvelope } from "./friend-request-turn.js";
|
|
33
|
+
import { handlePermissionResult } from "./permission-result.js";
|
|
31
34
|
const { setRuntime: setOpenclawClawlingRuntime, getRuntime: getOpenclawClawlingRuntime } = createPluginRuntimeStore("clawchat-plugin-openclaw runtime not initialized");
|
|
32
35
|
export { setOpenclawClawlingRuntime, getOpenclawClawlingRuntime };
|
|
33
36
|
const activeClients = new Map();
|
|
@@ -1381,6 +1384,7 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1381
1384
|
context: wsLogContext,
|
|
1382
1385
|
});
|
|
1383
1386
|
const groupSettingsCache = new GroupSettingsCache();
|
|
1387
|
+
const permissionCache = new PermissionCache();
|
|
1384
1388
|
// Findings 2 & 3 — gate group dispatch on the IN-FLIGHT settings pull, not just
|
|
1385
1389
|
// the first one. The pull is fire-and-forget, so replayed/live group messages
|
|
1386
1390
|
// could otherwise enter the governance gate against a stale/empty cache
|
|
@@ -1454,6 +1458,25 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1454
1458
|
}
|
|
1455
1459
|
})();
|
|
1456
1460
|
};
|
|
1461
|
+
// Best-effort pull of the agent's permission policy from the backend.
|
|
1462
|
+
// Called at startup (bypassRefresh: true, mirrors pullGroupSettings startup)
|
|
1463
|
+
// and on every successful (re)connect after hello-ok. On failure, logs and
|
|
1464
|
+
// keeps the stale cache — never throws, never blocks message handling.
|
|
1465
|
+
const pullPermissions = (opts) => {
|
|
1466
|
+
void (async () => {
|
|
1467
|
+
try {
|
|
1468
|
+
const policy = opts?.bypassRefresh
|
|
1469
|
+
? await (conversationApiClient ??= buildConversationApiClient()).getMyPermissions()
|
|
1470
|
+
: await getConversationApiClient().getMyPermissions();
|
|
1471
|
+
permissionCache.set(policy);
|
|
1472
|
+
log?.info?.(`[${accountId}] clawchat-plugin-openclaw permissions pull ok ops=${Object.keys(policy.byOperation).length}`);
|
|
1473
|
+
}
|
|
1474
|
+
catch (err) {
|
|
1475
|
+
log?.error?.(`[${accountId}] clawchat-plugin-openclaw permissions pull failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1476
|
+
// Keep stale cache; never throw.
|
|
1477
|
+
}
|
|
1478
|
+
})();
|
|
1479
|
+
};
|
|
1457
1480
|
const logAuthFailure = (reason) => {
|
|
1458
1481
|
if (authFailureLogged)
|
|
1459
1482
|
return;
|
|
@@ -1585,6 +1608,8 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1585
1608
|
// Re-pull per-group agent settings on every successful (re)connect so the
|
|
1586
1609
|
// cache stays current after a network interruption or token refresh.
|
|
1587
1610
|
pullGroupSettings();
|
|
1611
|
+
// Re-pull permission policy alongside group settings on every (re)connect.
|
|
1612
|
+
pullPermissions();
|
|
1588
1613
|
// §A.1 — arm the proactive refresh timer from the live token's `exp`
|
|
1589
1614
|
// every time a connection becomes ready (re-armed after every refresh via
|
|
1590
1615
|
// the gateway re-enter).
|
|
@@ -1796,6 +1821,10 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1796
1821
|
},
|
|
1797
1822
|
});
|
|
1798
1823
|
};
|
|
1824
|
+
// Debounce flag for lighter-awareness consolidated notes.
|
|
1825
|
+
// A single queueMicrotask coalesces all awareness signals that arrive in
|
|
1826
|
+
// the same synchronous turn into exactly one handleInboundEnvelope call.
|
|
1827
|
+
let pendingAwarenessNote = false;
|
|
1799
1828
|
client.on("notify:signal", (env) => {
|
|
1800
1829
|
// §9.4 reliable system notification. The plugin holds no friend/roster
|
|
1801
1830
|
// cache (friends are fetched on demand via REST tools), so there is nothing
|
|
@@ -1807,10 +1836,15 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1807
1836
|
? env.payload
|
|
1808
1837
|
: undefined;
|
|
1809
1838
|
const type = typeof payload?.type === "string" ? payload.type : "";
|
|
1839
|
+
const entityId = typeof payload?.entity_id === "string" ? payload.entity_id : "";
|
|
1810
1840
|
if (type === "agent.config.changed") {
|
|
1811
1841
|
log?.info?.(`[${accountId}] clawchat-plugin-openclaw agent.config.changed signal received; re-pulling group settings`);
|
|
1812
1842
|
pullGroupSettings();
|
|
1813
1843
|
}
|
|
1844
|
+
else if (type === "agent.permission.changed") {
|
|
1845
|
+
log?.info?.(`[${accountId}] clawchat-plugin-openclaw agent.permission.changed signal received; re-pulling permissions`);
|
|
1846
|
+
pullPermissions();
|
|
1847
|
+
}
|
|
1814
1848
|
else if (type === "clawchat.skill.update.check") {
|
|
1815
1849
|
// Content-free trigger: check the official skill source in code and, if
|
|
1816
1850
|
// there is an update, ask the owner in chat for consent. The atomic
|
|
@@ -1820,6 +1854,62 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
1820
1854
|
log?.error?.(`[${accountId}] clawchat-plugin-openclaw skill-update check failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1821
1855
|
});
|
|
1822
1856
|
}
|
|
1857
|
+
else if (type === "friend.request") {
|
|
1858
|
+
// Dedup is already applied above by notifySignalObserver.observe (the live
|
|
1859
|
+
// frame and its reliable-inbox replay share the same event_id and collapse
|
|
1860
|
+
// to one observation). Build one synthetic reasoning turn so the agent can
|
|
1861
|
+
// act on the pending request; the prompt text varies by policy state.
|
|
1862
|
+
const state = permissionCache.stateOf("friend.add");
|
|
1863
|
+
log?.info?.(`[${accountId}] clawchat-plugin-openclaw friend.request signal received; dispatching reasoning turn entity_id=${entityId} policy=${state}`);
|
|
1864
|
+
void handleInboundEnvelope(buildFriendRequestEnvelope({ account, state, entityId }));
|
|
1865
|
+
}
|
|
1866
|
+
else if (type === "friend.added" ||
|
|
1867
|
+
type === "friend.removed" ||
|
|
1868
|
+
type === "friend.profile_updated" ||
|
|
1869
|
+
type.startsWith("conversation.")) {
|
|
1870
|
+
// Lighter-awareness: log + optional single consolidated note. Never
|
|
1871
|
+
// injects a full reasoning turn per event (unlike friend.request).
|
|
1872
|
+
log?.info?.(`[${accountId}] clawchat-plugin-openclaw ${type} signal received; lighter-awareness handling`);
|
|
1873
|
+
if (account.awarenessNote && !pendingAwarenessNote) {
|
|
1874
|
+
pendingAwarenessNote = true;
|
|
1875
|
+
queueMicrotask(() => {
|
|
1876
|
+
pendingAwarenessNote = false;
|
|
1877
|
+
const now = Date.now();
|
|
1878
|
+
void handleInboundEnvelope({
|
|
1879
|
+
version: "2",
|
|
1880
|
+
event: EVENT.MESSAGE_SEND,
|
|
1881
|
+
trace_id: `clawchat-plugin-openclaw-awareness-${now}`,
|
|
1882
|
+
emitted_at: now,
|
|
1883
|
+
chat_id: account.ownerUserId,
|
|
1884
|
+
chat_type: "direct",
|
|
1885
|
+
to: { id: account.userId, type: "direct" },
|
|
1886
|
+
sender: { id: "clawchat-awareness", type: "direct", nick_name: "ClawChat" },
|
|
1887
|
+
payload: {
|
|
1888
|
+
message_id: `clawchat-plugin-openclaw-awareness-${now}`,
|
|
1889
|
+
message_mode: "normal",
|
|
1890
|
+
message: {
|
|
1891
|
+
body: {
|
|
1892
|
+
fragments: [
|
|
1893
|
+
{
|
|
1894
|
+
kind: "text",
|
|
1895
|
+
text: "ClawChat awareness: your contacts or conversations have been updated.",
|
|
1896
|
+
},
|
|
1897
|
+
],
|
|
1898
|
+
},
|
|
1899
|
+
context: { mentions: [], reply: null },
|
|
1900
|
+
streaming: {
|
|
1901
|
+
status: "static",
|
|
1902
|
+
sequence: 0,
|
|
1903
|
+
mutation_policy: "sealed",
|
|
1904
|
+
started_at: null,
|
|
1905
|
+
completed_at: null,
|
|
1906
|
+
},
|
|
1907
|
+
},
|
|
1908
|
+
},
|
|
1909
|
+
});
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1823
1913
|
}
|
|
1824
1914
|
});
|
|
1825
1915
|
client.on("replay:done", (env) => {
|
|
@@ -2439,6 +2529,16 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
2439
2529
|
account,
|
|
2440
2530
|
log,
|
|
2441
2531
|
consumeOwnerConsent: consumeOwnerSkillConsent,
|
|
2532
|
+
consumePermissionResult: async (metadata) => {
|
|
2533
|
+
// A permission_result receipt closes the loop on an earlier request.
|
|
2534
|
+
// Dedup by request_id; on a fresh receipt feed the synthetic context
|
|
2535
|
+
// note back to the agent so it can react to the outcome.
|
|
2536
|
+
const note = handlePermissionResult(metadata, account);
|
|
2537
|
+
if (note) {
|
|
2538
|
+
log?.info?.(`[${accountId}] clawchat-plugin-openclaw permission_result receipt op=${metadata.operation} outcome=${metadata.outcome} request_id=${metadata.request_id}; dispatching context note`);
|
|
2539
|
+
void handleInboundEnvelope(note);
|
|
2540
|
+
}
|
|
2541
|
+
},
|
|
2442
2542
|
ingest: async (turn) => {
|
|
2443
2543
|
ingestResult = await ingestTurn(turn);
|
|
2444
2544
|
},
|
|
@@ -2525,6 +2625,9 @@ export async function startOpenclawClawlingGateway(params) {
|
|
|
2525
2625
|
// rotating `account.token` out from under the already-constructed WS client.
|
|
2526
2626
|
// Settling this releases the Finding-2 group-dispatch gate.
|
|
2527
2627
|
pullGroupSettings({ bypassRefresh: true });
|
|
2628
|
+
// Initial pull of permission policy at startup (best-effort; errors logged,
|
|
2629
|
+
// stale cache kept). Uses bypassRefresh for the same reason as pullGroupSettings.
|
|
2630
|
+
pullPermissions({ bypassRefresh: true });
|
|
2528
2631
|
// Safety: never strand a held group message if the runtime is torn down while a
|
|
2529
2632
|
// pull is in flight. `waitWithTimeout` already releases group waiters on abort,
|
|
2530
2633
|
// but force the gate open too so any later `wait()` resolves immediately.
|
package/dist/src/tools.js
CHANGED
|
@@ -4,6 +4,7 @@ import { execFile } from "node:child_process";
|
|
|
4
4
|
import { createOpenclawClawlingApiClient } from "./api-client.js";
|
|
5
5
|
import { resolveLivewarePath } from "./liveware-cli.js";
|
|
6
6
|
import { ClawlingApiError, } from "./api-types.js";
|
|
7
|
+
import { mapGateOutcome } from "./gate-outcome.js";
|
|
7
8
|
import { resolveOpenclawClawlingAccount } from "./config.js";
|
|
8
9
|
import { clawChatDbPathForStateDir, getClawChatStore, } from "./storage.js";
|
|
9
10
|
import { sendOpenclawClawlingMentionMessage } from "./outbound.js";
|
|
@@ -272,6 +273,38 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
272
273
|
}
|
|
273
274
|
})();
|
|
274
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Like withClient, but maps gate codes (21001/21003) to structured outcomes
|
|
278
|
+
* via mapGateOutcome so the agent sees a clear pending/forbidden status
|
|
279
|
+
* instead of a generic error. Used for friend and moment mutation tools.
|
|
280
|
+
*/
|
|
281
|
+
function withGatedClient(fn) {
|
|
282
|
+
return (async () => {
|
|
283
|
+
const built = buildClient();
|
|
284
|
+
if (!built.ok)
|
|
285
|
+
return built.error;
|
|
286
|
+
try {
|
|
287
|
+
const data = await fn(built.client);
|
|
288
|
+
return jsonResponse(data);
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
if (err instanceof ClawlingApiError) {
|
|
292
|
+
const code = typeof err.meta?.code === "number" ? err.meta.code : null;
|
|
293
|
+
if (code !== null) {
|
|
294
|
+
const rawData = err.meta?.data;
|
|
295
|
+
const gateData = rawData !== null && rawData !== undefined && typeof rawData === "object"
|
|
296
|
+
? rawData
|
|
297
|
+
: {};
|
|
298
|
+
const outcome = mapGateOutcome(code, gateData);
|
|
299
|
+
if (outcome !== null)
|
|
300
|
+
return jsonResponse(outcome);
|
|
301
|
+
}
|
|
302
|
+
return apiError(err);
|
|
303
|
+
}
|
|
304
|
+
return genericError(err);
|
|
305
|
+
}
|
|
306
|
+
})();
|
|
307
|
+
}
|
|
275
308
|
function workspaceRoot(ctx) {
|
|
276
309
|
const root = typeof ctx.workspaceDir === "string" ? ctx.workspaceDir.trim() : "";
|
|
277
310
|
return root || null;
|
|
@@ -640,7 +673,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
640
673
|
async execute(_callId, params) {
|
|
641
674
|
return await recordClawchatToolCall("clawchat_send_friend_request", params, async () => {
|
|
642
675
|
const p = params;
|
|
643
|
-
return await
|
|
676
|
+
return await withGatedClient((c) => c.sendFriendRequest(p));
|
|
644
677
|
});
|
|
645
678
|
},
|
|
646
679
|
}, { name: "clawchat_send_friend_request" });
|
|
@@ -668,7 +701,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
668
701
|
async execute(_callId, params) {
|
|
669
702
|
return await recordClawchatToolCall("clawchat_accept_friend_request", params, async () => {
|
|
670
703
|
const p = params;
|
|
671
|
-
return await
|
|
704
|
+
return await withGatedClient((c) => c.acceptFriendRequest(p.requestId));
|
|
672
705
|
});
|
|
673
706
|
},
|
|
674
707
|
}, { name: "clawchat_accept_friend_request" });
|
|
@@ -682,7 +715,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
682
715
|
async execute(_callId, params) {
|
|
683
716
|
return await recordClawchatToolCall("clawchat_reject_friend_request", params, async () => {
|
|
684
717
|
const p = params;
|
|
685
|
-
return await
|
|
718
|
+
return await withGatedClient((c) => c.rejectFriendRequest(p.requestId));
|
|
686
719
|
});
|
|
687
720
|
},
|
|
688
721
|
}, { name: "clawchat_reject_friend_request" });
|
|
@@ -696,7 +729,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
696
729
|
async execute(_callId, params) {
|
|
697
730
|
return await recordClawchatToolCall("clawchat_remove_friend", params, async () => {
|
|
698
731
|
const p = params;
|
|
699
|
-
return await
|
|
732
|
+
return await withGatedClient((c) => c.removeFriend(p.friendUserId));
|
|
700
733
|
});
|
|
701
734
|
},
|
|
702
735
|
}, { name: "clawchat_remove_friend" });
|
|
@@ -841,7 +874,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
841
874
|
if (!text && (!images || images.length === 0)) {
|
|
842
875
|
return validationError("clawchat-plugin-openclaw: at least one of text or images is required");
|
|
843
876
|
}
|
|
844
|
-
return await
|
|
877
|
+
return await withGatedClient((c) => c.createMoment({
|
|
845
878
|
...(text !== undefined ? { text } : {}),
|
|
846
879
|
...(images !== undefined ? { images } : {}),
|
|
847
880
|
}));
|
|
@@ -858,7 +891,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
858
891
|
async execute(_callId, params) {
|
|
859
892
|
return await recordClawchatToolCall("clawchat_delete_moment", params, async () => {
|
|
860
893
|
const p = params;
|
|
861
|
-
return await
|
|
894
|
+
return await withGatedClient((c) => c.deleteMoment(p.momentId));
|
|
862
895
|
});
|
|
863
896
|
},
|
|
864
897
|
}, { name: "clawchat_delete_moment" });
|
|
@@ -875,7 +908,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
875
908
|
if (!p.emoji?.trim()) {
|
|
876
909
|
return validationError("clawchat-plugin-openclaw: emoji is required");
|
|
877
910
|
}
|
|
878
|
-
return await
|
|
911
|
+
return await withGatedClient((c) => c.toggleMomentReaction({ momentId: p.momentId, emoji: p.emoji }));
|
|
879
912
|
});
|
|
880
913
|
},
|
|
881
914
|
}, { name: "clawchat_toggle_moment_reaction" });
|
|
@@ -892,7 +925,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
892
925
|
if (!p.text?.trim()) {
|
|
893
926
|
return validationError("clawchat-plugin-openclaw: text is required");
|
|
894
927
|
}
|
|
895
|
-
return await
|
|
928
|
+
return await withGatedClient((c) => c.createMomentComment({ momentId: p.momentId, text: p.text }));
|
|
896
929
|
});
|
|
897
930
|
},
|
|
898
931
|
}, { name: "clawchat_create_moment_comment" });
|
|
@@ -909,7 +942,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
909
942
|
if (!p.text?.trim()) {
|
|
910
943
|
return validationError("clawchat-plugin-openclaw: text is required");
|
|
911
944
|
}
|
|
912
|
-
return await
|
|
945
|
+
return await withGatedClient((c) => c.replyMomentComment({
|
|
913
946
|
momentId: p.momentId,
|
|
914
947
|
replyToCommentId: p.replyToCommentId,
|
|
915
948
|
text: p.text,
|
|
@@ -927,7 +960,7 @@ export function registerOpenclawClawlingTools(api, options = {}) {
|
|
|
927
960
|
async execute(_callId, params) {
|
|
928
961
|
return await recordClawchatToolCall("clawchat_delete_moment_comment", params, async () => {
|
|
929
962
|
const p = params;
|
|
930
|
-
return await
|
|
963
|
+
return await withGatedClient((c) => c.deleteMomentComment({ momentId: p.momentId, commentId: p.commentId }));
|
|
931
964
|
});
|
|
932
965
|
},
|
|
933
966
|
}, { name: "clawchat_delete_moment_comment" });
|
package/dist/src/ws-client.js
CHANGED
|
@@ -84,6 +84,23 @@ export function createWebSocketTransport(WebSocketCtor = globalThis.WebSocket) {
|
|
|
84
84
|
},
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns the capability set advertised in the connect handshake.
|
|
89
|
+
* Exported so tests can assert on the exact fields without a full WS setup.
|
|
90
|
+
*
|
|
91
|
+
* permission_events: forward-compat: advertises readiness for a future native
|
|
92
|
+
* `permission.receipt` wire frame; today the permission-decision receipt is
|
|
93
|
+
* delivered as a system message until msghub emits the native frame.
|
|
94
|
+
*/
|
|
95
|
+
export function buildConnectCapabilities() {
|
|
96
|
+
return {
|
|
97
|
+
multi_device: false,
|
|
98
|
+
device_replay: true,
|
|
99
|
+
chat_meta_events: true,
|
|
100
|
+
notify_signals: true,
|
|
101
|
+
permission_events: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
87
104
|
export class ClawChatClient extends EventEmitter {
|
|
88
105
|
opts;
|
|
89
106
|
currentState = "idle";
|
|
@@ -333,12 +350,8 @@ export class ClawChatClient extends EventEmitter {
|
|
|
333
350
|
// *send* history.transit, which a single-device agent never does, and we
|
|
334
351
|
// do not handle inbound history.transit — advertising it would invite
|
|
335
352
|
// frames we cannot process. This is a deliberate, spec-legal omission.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
device_replay: true,
|
|
339
|
-
chat_meta_events: true,
|
|
340
|
-
notify_signals: true,
|
|
341
|
-
},
|
|
353
|
+
// permission_events: forward-compat; see buildConnectCapabilities().
|
|
354
|
+
capabilities: buildConnectCapabilities(),
|
|
342
355
|
};
|
|
343
356
|
const traceId = this.nextTraceId();
|
|
344
357
|
this.expectedConnectTraceId = traceId;
|
package/openclaw.plugin.json
CHANGED
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
"forwardThinking": { "type": "boolean" },
|
|
108
108
|
"forwardToolCalls": { "type": "boolean" },
|
|
109
109
|
"richInteractions": { "type": "boolean" },
|
|
110
|
+
"awarenessNote": { "type": "boolean" },
|
|
110
111
|
"reconnect": {
|
|
111
112
|
"type": "object",
|
|
112
113
|
"additionalProperties": false,
|
|
@@ -180,6 +181,7 @@
|
|
|
180
181
|
"forwardThinking": { "type": "boolean" },
|
|
181
182
|
"forwardToolCalls": { "type": "boolean" },
|
|
182
183
|
"richInteractions": { "type": "boolean" },
|
|
184
|
+
"awarenessNote": { "type": "boolean" },
|
|
183
185
|
"reconnect": {
|
|
184
186
|
"type": "object",
|
|
185
187
|
"additionalProperties": false,
|