@agentapprove/openclaw 0.1.0 → 0.1.2
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/index.js +21 -4
- package/openclaw.plugin.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
|
+
import { randomBytes } from "crypto";
|
|
3
4
|
|
|
4
5
|
// src/config.ts
|
|
5
6
|
import { readFileSync, existsSync, statSync } from "fs";
|
|
@@ -100,7 +101,7 @@ function loadConfig(openclawConfig, logger) {
|
|
|
100
101
|
failBehavior,
|
|
101
102
|
privacyTier,
|
|
102
103
|
debug,
|
|
103
|
-
hookVersion: "1.1.
|
|
104
|
+
hookVersion: "1.1.1",
|
|
104
105
|
agentName,
|
|
105
106
|
e2eEnabled,
|
|
106
107
|
e2eUserKey,
|
|
@@ -306,6 +307,18 @@ try {
|
|
|
306
307
|
} catch {
|
|
307
308
|
pluginFilePath = __filename;
|
|
308
309
|
}
|
|
310
|
+
var gatewaySessionId = randomBytes(12).toString("hex");
|
|
311
|
+
function extractSessionIdFromParams(params) {
|
|
312
|
+
if (!params) return void 0;
|
|
313
|
+
const raw = params.sessionId || params.session_id || params.conversationId || params.conversation_id;
|
|
314
|
+
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
315
|
+
return raw.trim();
|
|
316
|
+
}
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
function resolveSessionId(ctx, params) {
|
|
320
|
+
return extractSessionIdFromParams(params) || ctx?.sessionKey || gatewaySessionId;
|
|
321
|
+
}
|
|
309
322
|
function classifyTool(toolName) {
|
|
310
323
|
const lower = toolName.toLowerCase();
|
|
311
324
|
if (lower === "exec" || lower === "process") {
|
|
@@ -381,12 +394,13 @@ function register(api) {
|
|
|
381
394
|
toolInput: event.params,
|
|
382
395
|
agent: config.agentName,
|
|
383
396
|
hookType: "before_tool_call",
|
|
397
|
+
sessionId: resolveSessionId(ctx, event.params),
|
|
384
398
|
cwd: event.params.workdir || void 0,
|
|
385
399
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
386
400
|
};
|
|
387
401
|
try {
|
|
388
402
|
const response = await sendApprovalRequest(request, config, pluginFilePath);
|
|
389
|
-
if (response.decision === "approve") {
|
|
403
|
+
if (response.decision === "approve" || response.decision === "allow") {
|
|
390
404
|
debugLog(`Tool "${event.toolName}" approved${response.reason ? ": " + response.reason : ""}`);
|
|
391
405
|
return void 0;
|
|
392
406
|
}
|
|
@@ -404,13 +418,14 @@ function register(api) {
|
|
|
404
418
|
);
|
|
405
419
|
}
|
|
406
420
|
});
|
|
407
|
-
api.on("after_tool_call", async (event,
|
|
421
|
+
api.on("after_tool_call", async (event, ctx) => {
|
|
408
422
|
const { toolType } = classifyTool(event.toolName);
|
|
409
423
|
void sendEvent({
|
|
410
424
|
toolName: event.toolName,
|
|
411
425
|
toolType,
|
|
412
426
|
agent: config.agentName,
|
|
413
427
|
hookType: "after_tool_call",
|
|
428
|
+
sessionId: resolveSessionId(ctx, event.params),
|
|
414
429
|
status: event.error ? "error" : "success",
|
|
415
430
|
error: event.error,
|
|
416
431
|
durationMs: event.durationMs,
|
|
@@ -425,6 +440,7 @@ function register(api) {
|
|
|
425
440
|
toolType: "command",
|
|
426
441
|
agent: config.agentName,
|
|
427
442
|
hookType: "command_event",
|
|
443
|
+
sessionId: event.sessionKey || gatewaySessionId,
|
|
428
444
|
timestamp: event.timestamp.toISOString(),
|
|
429
445
|
metadata: { sessionKey: event.sessionKey, action: event.action }
|
|
430
446
|
}, config, pluginFilePath);
|
|
@@ -440,6 +456,7 @@ function register(api) {
|
|
|
440
456
|
toolType: "message_event",
|
|
441
457
|
agent: config.agentName,
|
|
442
458
|
hookType: "session_event",
|
|
459
|
+
sessionId: event.sessionKey || gatewaySessionId,
|
|
443
460
|
timestamp: event.timestamp.toISOString(),
|
|
444
461
|
metadata: {
|
|
445
462
|
direction,
|
|
@@ -457,7 +474,7 @@ function register(api) {
|
|
|
457
474
|
api.logger.info("Agent Approve: Registered before_tool_call, after_tool_call, and event monitoring hooks");
|
|
458
475
|
}
|
|
459
476
|
var index_default = {
|
|
460
|
-
id: "
|
|
477
|
+
id: "openclaw",
|
|
461
478
|
name: "Agent Approve",
|
|
462
479
|
description: "Mobile approval for AI agent tool execution",
|
|
463
480
|
register
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "openclaw",
|
|
3
3
|
"name": "Agent Approve",
|
|
4
4
|
"description": "Mobile approval for AI agent tool execution. Approve or deny tool calls from your iPhone and Apple Watch.",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.2",
|
|
6
6
|
"homepage": "https://agentapprove.com",
|
|
7
7
|
"configSchema": {
|
|
8
8
|
"type": "object",
|
package/package.json
CHANGED