@m1a0rz/agent-identity 0.4.6 → 0.5.0
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/README-cn.md +70 -9
- package/README.md +70 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -25
- package/dist/src/actions/identity-actions.d.ts.map +1 -1
- package/dist/src/actions/identity-actions.js +2 -2
- package/dist/src/commands/identity-commands.d.ts.map +1 -1
- package/dist/src/commands/identity-commands.js +1 -37
- package/dist/src/hooks/before-agent-start.d.ts +11 -3
- package/dist/src/hooks/before-agent-start.d.ts.map +1 -1
- package/dist/src/hooks/before-agent-start.js +12 -11
- package/dist/src/hooks/before-dispatch.d.ts +71 -0
- package/dist/src/hooks/before-dispatch.d.ts.map +1 -0
- package/dist/src/hooks/before-dispatch.js +148 -0
- package/dist/src/hooks/before-tool-call.d.ts +7 -2
- package/dist/src/hooks/before-tool-call.d.ts.map +1 -1
- package/dist/src/hooks/before-tool-call.js +19 -45
- package/dist/src/hooks/llm-input.d.ts.map +1 -1
- package/dist/src/hooks/llm-input.js +0 -3
- package/dist/src/local-server/handlers.d.ts +44 -0
- package/dist/src/local-server/handlers.d.ts.map +1 -0
- package/dist/src/local-server/handlers.js +207 -0
- package/dist/src/local-server/identity-socket.d.ts +18 -0
- package/dist/src/local-server/identity-socket.d.ts.map +1 -0
- package/dist/src/local-server/identity-socket.js +198 -0
- package/dist/src/local-server/peer-check.d.ts +58 -0
- package/dist/src/local-server/peer-check.d.ts.map +1 -0
- package/dist/src/local-server/peer-check.js +206 -0
- package/dist/src/local-server/peercred-linux.d.ts +30 -0
- package/dist/src/local-server/peercred-linux.d.ts.map +1 -0
- package/dist/src/local-server/peercred-linux.js +69 -0
- package/dist/src/risk/llm-risk-check.d.ts +0 -5
- package/dist/src/risk/llm-risk-check.d.ts.map +1 -1
- package/dist/src/risk/llm-risk-check.js +10 -1
- package/dist/src/risk/low-risk-tools.d.ts.map +1 -1
- package/dist/src/risk/low-risk-tools.js +0 -1
- package/dist/src/store/dispatch-feature-flag.d.ts +7 -0
- package/dist/src/store/dispatch-feature-flag.d.ts.map +1 -0
- package/dist/src/store/dispatch-feature-flag.js +36 -0
- package/dist/src/tools/identity-config-suggest.d.ts +1 -1
- package/dist/src/tools/identity-config-suggest.d.ts.map +1 -1
- package/dist/src/tools/identity-config-suggest.js +1 -1
- package/dist/src/tools/identity-config.d.ts +1 -1
- package/dist/src/tools/identity-config.d.ts.map +1 -1
- package/dist/src/tools/identity-config.js +1 -1
- package/dist/src/tools/identity-fetch.d.ts +1 -1
- package/dist/src/tools/identity-fetch.d.ts.map +1 -1
- package/dist/src/tools/identity-fetch.js +1 -2
- package/dist/src/tools/identity-get-role-credentials.d.ts +1 -1
- package/dist/src/tools/identity-get-role-credentials.d.ts.map +1 -1
- package/dist/src/tools/identity-get-role-credentials.js +1 -1
- package/dist/src/tools/identity-get-session-token.d.ts +1 -1
- package/dist/src/tools/identity-get-session-token.d.ts.map +1 -1
- package/dist/src/tools/identity-get-session-token.js +1 -1
- package/dist/src/tools/identity-get-tip-token.d.ts +1 -1
- package/dist/src/tools/identity-get-tip-token.d.ts.map +1 -1
- package/dist/src/tools/identity-get-tip-token.js +1 -1
- package/dist/src/tools/identity-list-credentials.d.ts +1 -1
- package/dist/src/tools/identity-list-credentials.d.ts.map +1 -1
- package/dist/src/tools/identity-list-credentials.js +1 -1
- package/dist/src/tools/identity-list-risk-patterns.d.ts +1 -1
- package/dist/src/tools/identity-list-risk-patterns.d.ts.map +1 -1
- package/dist/src/tools/identity-list-risk-patterns.js +1 -1
- package/dist/src/tools/identity-list-roles.d.ts +1 -1
- package/dist/src/tools/identity-list-roles.d.ts.map +1 -1
- package/dist/src/tools/identity-list-roles.js +1 -1
- package/dist/src/tools/identity-list-tips.d.ts +1 -1
- package/dist/src/tools/identity-list-tips.d.ts.map +1 -1
- package/dist/src/tools/identity-list-tips.js +1 -1
- package/dist/src/tools/identity-login.d.ts +1 -1
- package/dist/src/tools/identity-login.d.ts.map +1 -1
- package/dist/src/tools/identity-login.js +1 -1
- package/dist/src/tools/identity-logout.d.ts +1 -1
- package/dist/src/tools/identity-logout.d.ts.map +1 -1
- package/dist/src/tools/identity-logout.js +1 -1
- package/dist/src/tools/identity-risk-check.d.ts +1 -1
- package/dist/src/tools/identity-risk-check.d.ts.map +1 -1
- package/dist/src/tools/identity-risk-check.js +1 -1
- package/dist/src/tools/identity-set-binding.d.ts +1 -1
- package/dist/src/tools/identity-set-binding.d.ts.map +1 -1
- package/dist/src/tools/identity-set-binding.js +1 -1
- package/dist/src/tools/identity-status.d.ts +1 -1
- package/dist/src/tools/identity-status.d.ts.map +1 -1
- package/dist/src/tools/identity-status.js +1 -1
- package/dist/src/tools/identity-unset-binding.d.ts +1 -1
- package/dist/src/tools/identity-unset-binding.d.ts.map +1 -1
- package/dist/src/tools/identity-unset-binding.js +1 -1
- package/dist/src/tools/identity-whoami.d.ts +1 -1
- package/dist/src/tools/identity-whoami.d.ts.map +1 -1
- package/dist/src/tools/identity-whoami.js +1 -1
- package/dist/src/types.d.ts +22 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/tool-result.d.ts +26 -0
- package/dist/src/utils/tool-result.d.ts.map +1 -0
- package/dist/src/utils/tool-result.js +40 -0
- package/openclaw.plugin.json +15 -0
- package/package.json +9 -6
- package/skills/SKILL.md +3 -8
- package/dist/src/store/tool-approval-store.d.ts +0 -40
- package/dist/src/store/tool-approval-store.d.ts.map +0 -1
- package/dist/src/store/tool-approval-store.js +0 -162
- package/dist/src/tools/identity-approve-tool.d.ts +0 -15
- package/dist/src/tools/identity-approve-tool.d.ts.map +0 -1
- package/dist/src/tools/identity-approve-tool.js +0 -50
- package/dist/src/utils/approval-channel.d.ts +0 -7
- package/dist/src/utils/approval-channel.d.ts.map +0 -1
- package/dist/src/utils/approval-channel.js +0 -28
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* In-memory store for tool approval flow.
|
|
18
|
-
* Pending: awaiting user approval. Approval: recorded for retry-path allow.
|
|
19
|
-
*/
|
|
20
|
-
import { createHash } from "node:crypto";
|
|
21
|
-
const POLL_INTERVAL_MS = 500;
|
|
22
|
-
const pendingByApprovalId = new Map();
|
|
23
|
-
const approvalKeys = new Map(); // key -> expiresAtMs (for retry-path)
|
|
24
|
-
const approvedById = new Map(); // approvalId -> expiresAtMs (for poll-path)
|
|
25
|
-
/**
|
|
26
|
-
* Canonical JSON for stable hashing (sorted keys, no functions).
|
|
27
|
-
*/
|
|
28
|
-
function canonicalJson(obj) {
|
|
29
|
-
if (obj === null || obj === undefined)
|
|
30
|
-
return "null";
|
|
31
|
-
if (typeof obj !== "object")
|
|
32
|
-
return JSON.stringify(obj);
|
|
33
|
-
if (Array.isArray(obj))
|
|
34
|
-
return "[" + obj.map(canonicalJson).join(",") + "]";
|
|
35
|
-
const keys = Object.keys(obj).sort();
|
|
36
|
-
const pairs = keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`);
|
|
37
|
-
return "{" + pairs.join(",") + "}";
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Hash for tool+params, used as approval key and short approval id.
|
|
41
|
-
*/
|
|
42
|
-
export function hashToolParams(toolName, params) {
|
|
43
|
-
const payload = `${toolName}:${canonicalJson(params)}`;
|
|
44
|
-
return createHash("sha256").update(payload, "utf-8").digest("hex");
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Short id for approval messages (first 8 chars of hash).
|
|
48
|
-
*/
|
|
49
|
-
export function shortApprovalId(fullHash) {
|
|
50
|
-
return fullHash.slice(0, 8);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Approval key for hasRecentApproval lookup.
|
|
54
|
-
*/
|
|
55
|
-
function approvalKey(sessionKey, toolName, params) {
|
|
56
|
-
return `${sessionKey}:${hashToolParams(toolName, params)}`;
|
|
57
|
-
}
|
|
58
|
-
export function createPending(params) {
|
|
59
|
-
const { approvalId, sessionKey, toolName, params: p, ttlMs } = params;
|
|
60
|
-
const expiresAtMs = Date.now() + ttlMs;
|
|
61
|
-
pendingByApprovalId.set(approvalId, {
|
|
62
|
-
approvalId,
|
|
63
|
-
sessionKey,
|
|
64
|
-
toolName,
|
|
65
|
-
params: p,
|
|
66
|
-
expiresAtMs,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export function getPending(approvalId) {
|
|
70
|
-
const entry = pendingByApprovalId.get(approvalId);
|
|
71
|
-
if (!entry || Date.now() > entry.expiresAtMs) {
|
|
72
|
-
pendingByApprovalId.delete(approvalId);
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
return entry;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Approve a pending request. Records approval for retry-path and poll-path; removes from pending.
|
|
79
|
-
* When approverSessionKey is provided, verifies it matches the pending entry's sessionKey.
|
|
80
|
-
*/
|
|
81
|
-
export function approve(approvalId, ttlMs, approverSessionKey) {
|
|
82
|
-
const entry = getPending(approvalId);
|
|
83
|
-
if (!entry)
|
|
84
|
-
return false;
|
|
85
|
-
if (approverSessionKey != null &&
|
|
86
|
-
approverSessionKey.trim() !== "" &&
|
|
87
|
-
entry.sessionKey !== approverSessionKey) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
const expiresAtMs = Date.now() + ttlMs;
|
|
91
|
-
pendingByApprovalId.delete(approvalId);
|
|
92
|
-
const key = approvalKey(entry.sessionKey, entry.toolName, entry.params);
|
|
93
|
-
approvalKeys.set(key, expiresAtMs);
|
|
94
|
-
approvedById.set(approvalId, expiresAtMs);
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Reject a pending request. When rejecterSessionKey is provided, verifies it matches.
|
|
99
|
-
*/
|
|
100
|
-
export function reject(approvalId, rejecterSessionKey) {
|
|
101
|
-
const entry = getPending(approvalId);
|
|
102
|
-
if (!entry)
|
|
103
|
-
return false;
|
|
104
|
-
if (rejecterSessionKey != null &&
|
|
105
|
-
rejecterSessionKey.trim() !== "" &&
|
|
106
|
-
entry.sessionKey !== rejecterSessionKey) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
return pendingByApprovalId.delete(approvalId);
|
|
110
|
-
}
|
|
111
|
-
export function hasRecentApproval(sessionKey, toolName, params) {
|
|
112
|
-
const key = approvalKey(sessionKey, toolName, params);
|
|
113
|
-
const expiresAt = approvalKeys.get(key);
|
|
114
|
-
if (!expiresAt || Date.now() > expiresAt) {
|
|
115
|
-
approvalKeys.delete(key);
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
export function consumeApproval(sessionKey, toolName, params) {
|
|
121
|
-
const key = approvalKey(sessionKey, toolName, params);
|
|
122
|
-
const expiresAt = approvalKeys.get(key);
|
|
123
|
-
if (!expiresAt || Date.now() > expiresAt) {
|
|
124
|
-
approvalKeys.delete(key);
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
approvalKeys.delete(key);
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
export function getPendingForSession(sessionKey) {
|
|
131
|
-
const now = Date.now();
|
|
132
|
-
const result = [];
|
|
133
|
-
for (const entry of pendingByApprovalId.values()) {
|
|
134
|
-
if (entry.sessionKey === sessionKey && entry.expiresAtMs > now) {
|
|
135
|
-
result.push(entry);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Poll until approved or timeout.
|
|
142
|
-
*/
|
|
143
|
-
export async function pollForApproval(approvalId, timeoutMs, onCheck) {
|
|
144
|
-
const deadline = Date.now() + timeoutMs;
|
|
145
|
-
while (Date.now() < deadline) {
|
|
146
|
-
onCheck?.();
|
|
147
|
-
if (approvedById.has(approvalId)) {
|
|
148
|
-
const expiresAt = approvedById.get(approvalId);
|
|
149
|
-
if (Date.now() <= expiresAt) {
|
|
150
|
-
approvedById.delete(approvalId);
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
approvedById.delete(approvalId);
|
|
154
|
-
}
|
|
155
|
-
const entry = getPending(approvalId);
|
|
156
|
-
if (!entry) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
160
|
-
}
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* identity_approve_tool: approve a high-risk tool call by approval_id.
|
|
3
|
-
* Used for webchat/TUI flow when user approves via UI then agent retries.
|
|
4
|
-
*/
|
|
5
|
-
import type { PluginToolContext } from "../types.js";
|
|
6
|
-
import { AnyAgentTool } from "openclaw/plugin-sdk";
|
|
7
|
-
export type IdentityApproveToolDeps = {
|
|
8
|
-
approvalTtlMs: number;
|
|
9
|
-
logger?: {
|
|
10
|
-
debug?: (msg: string) => void;
|
|
11
|
-
warn?: (msg: string) => void;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare function createIdentityApproveTool(deps: IdentityApproveToolDeps): (ctx: PluginToolContext) => AnyAgentTool;
|
|
15
|
-
//# sourceMappingURL=identity-approve-tool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity-approve-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/identity-approve-tool.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAK/D,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC1E,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,uBAAuB,IAC7D,KAAK,iBAAiB,KAAG,YAAY,CA8B9C"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { Type } from "@sinclair/typebox";
|
|
17
|
-
import { jsonResult } from "openclaw/plugin-sdk";
|
|
18
|
-
import * as toolApprovalStore from "../store/tool-approval-store.js";
|
|
19
|
-
import { resolveEffectiveSessionKey } from "../store/sender-session-store.js";
|
|
20
|
-
import { logDebug, logWarn } from "../utils/logger.js";
|
|
21
|
-
export function createIdentityApproveTool(deps) {
|
|
22
|
-
return (ctx) => ({
|
|
23
|
-
name: "identity_approve_tool",
|
|
24
|
-
label: "Approve Tool Call",
|
|
25
|
-
description: "Approve a pending high-risk tool call by its approval ID. Must run from same session.",
|
|
26
|
-
parameters: Type.Object({
|
|
27
|
-
approval_id: Type.String({ description: "Approval ID from the pending tool message" }),
|
|
28
|
-
}),
|
|
29
|
-
execute: async (_toolCallId, params) => {
|
|
30
|
-
const approvalId = (params?.approval_id ?? "").trim();
|
|
31
|
-
if (!approvalId) {
|
|
32
|
-
return jsonResult({
|
|
33
|
-
ok: false,
|
|
34
|
-
error: "approval_id is required",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const approverKey = ctx.sessionKey ? resolveEffectiveSessionKey(ctx.sessionKey) : ctx.sessionKey;
|
|
38
|
-
const ok = toolApprovalStore.approve(approvalId, deps.approvalTtlMs, approverKey);
|
|
39
|
-
if (ok) {
|
|
40
|
-
logDebug(deps.logger, `approved tool call ${approvalId}`);
|
|
41
|
-
return jsonResult({ ok: true, message: "Tool call approved" });
|
|
42
|
-
}
|
|
43
|
-
logWarn(deps.logger, `approve failed for ${approvalId} (expired or not found)`);
|
|
44
|
-
return jsonResult({
|
|
45
|
-
ok: false,
|
|
46
|
-
error: "Approval not found or expired. Request a new tool execution.",
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true when sessionKey can be delivered to (sendMessage works).
|
|
3
|
-
* Those sessions use sync approval (poll until user approves).
|
|
4
|
-
* Returns false for webchat/TUI (agent:main:main etc) - use retry flow.
|
|
5
|
-
*/
|
|
6
|
-
export declare function supportsSyncApproval(sessionKey: string | undefined | null): boolean;
|
|
7
|
-
//# sourceMappingURL=approval-channel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"approval-channel.d.ts","sourceRoot":"","sources":["../../../src/utils/approval-channel.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAEnF"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Determine if session supports sync approval (sendMessage + poll).
|
|
18
|
-
* Channel sessions (Feishu, Telegram, etc.) support it; webchat/TUI do not.
|
|
19
|
-
*/
|
|
20
|
-
import { parseSessionKeyToDeliveryTarget } from "./derive-session-key.js";
|
|
21
|
-
/**
|
|
22
|
-
* Returns true when sessionKey can be delivered to (sendMessage works).
|
|
23
|
-
* Those sessions use sync approval (poll until user approves).
|
|
24
|
-
* Returns false for webchat/TUI (agent:main:main etc) - use retry flow.
|
|
25
|
-
*/
|
|
26
|
-
export function supportsSyncApproval(sessionKey) {
|
|
27
|
-
return parseSessionKeyToDeliveryTarget(sessionKey ?? "") !== null;
|
|
28
|
-
}
|