@alfe.ai/openclaw-identity 0.0.8 → 0.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.
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +2 -394
- package/dist/plugin.js +1 -394
- package/dist/plugin2.cjs +451 -0
- package/dist/plugin2.js +446 -0
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const require_plugin = require("./
|
|
2
|
-
module.exports = require_plugin;
|
|
1
|
+
const require_plugin = require("./plugin2.cjs");
|
|
2
|
+
module.exports = require_plugin.plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import plugin from "./
|
|
1
|
+
import { t as plugin } from "./plugin2.js";
|
|
2
2
|
export { plugin as default };
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,394 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let _sinclair_typebox = require("@sinclair/typebox");
|
|
4
|
-
//#region src/plugin.ts
|
|
5
|
-
/**
|
|
6
|
-
* @alfe.ai/openclaw-identity — OpenClaw native plugin
|
|
7
|
-
*
|
|
8
|
-
* HTTP-based identity resolution, permission enforcement, and CRM tools.
|
|
9
|
-
* Installed as part of the core alfe integration on every agent.
|
|
10
|
-
*
|
|
11
|
-
* Hooks:
|
|
12
|
-
* - message_received → resolve sender identity via HTTP, cache, gate access
|
|
13
|
-
* - before_tool_call → enforce permissions from cached policy
|
|
14
|
-
* - after_tool_call → log tool execution audit
|
|
15
|
-
*
|
|
16
|
-
* All data access via AgentApiClient (/agent/identity/* routes).
|
|
17
|
-
* Uses the agent's own API key (from ~/.alfe/config.toml) for authentication.
|
|
18
|
-
*/
|
|
19
|
-
const pkg = (0, require("node:module").createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
|
|
20
|
-
const CACHE_TTL_MS = 6e4;
|
|
21
|
-
const sessionCache = /* @__PURE__ */ new Map();
|
|
22
|
-
function getCached(key) {
|
|
23
|
-
const entry = sessionCache.get(key);
|
|
24
|
-
if (!entry) return null;
|
|
25
|
-
if (Date.now() > entry.expiresAt) {
|
|
26
|
-
sessionCache.delete(key);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return entry.value;
|
|
30
|
-
}
|
|
31
|
-
function setCached(key, value) {
|
|
32
|
-
sessionCache.set(key, {
|
|
33
|
-
value,
|
|
34
|
-
expiresAt: Date.now() + CACHE_TTL_MS
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function ok(data) {
|
|
38
|
-
return {
|
|
39
|
-
content: [{
|
|
40
|
-
type: "text",
|
|
41
|
-
text: JSON.stringify(data)
|
|
42
|
-
}],
|
|
43
|
-
details: data
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function errResult(message) {
|
|
47
|
-
return {
|
|
48
|
-
content: [{
|
|
49
|
-
type: "text",
|
|
50
|
-
text: JSON.stringify({ error: message })
|
|
51
|
-
}],
|
|
52
|
-
details: { error: message }
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function defineTool(def) {
|
|
56
|
-
return {
|
|
57
|
-
name: def.name,
|
|
58
|
-
description: def.description,
|
|
59
|
-
label: def.name,
|
|
60
|
-
parameters: def.parameters,
|
|
61
|
-
execute: async (_toolCallId, params) => {
|
|
62
|
-
try {
|
|
63
|
-
return ok(await def.handler(params));
|
|
64
|
-
} catch (e) {
|
|
65
|
-
return errResult(e.message);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const plugin = {
|
|
71
|
-
id: "@alfe.ai/openclaw-identity",
|
|
72
|
-
name: "Alfe Identity",
|
|
73
|
-
description: "Identity resolution, access gating, and permission enforcement",
|
|
74
|
-
version: pkg.version,
|
|
75
|
-
activate(api) {
|
|
76
|
-
const log = api.logger;
|
|
77
|
-
log.info("Alfe Identity plugin activating...");
|
|
78
|
-
let client;
|
|
79
|
-
try {
|
|
80
|
-
const config = (0, _alfe_ai_config.resolveConfig)();
|
|
81
|
-
client = new _alfe_ai_agent_api_client.AgentApiClient({
|
|
82
|
-
apiKey: config.apiKey,
|
|
83
|
-
apiUrl: config.apiUrl
|
|
84
|
-
});
|
|
85
|
-
} catch (err) {
|
|
86
|
-
log.error(`Identity plugin: failed to resolve config — ${err instanceof Error ? err.message : String(err)}`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
let failureMode = "open";
|
|
90
|
-
client.getIntegrationConfig("alfe").then((alfeConfig) => {
|
|
91
|
-
const mode = alfeConfig.config.identity_failure_mode;
|
|
92
|
-
if (mode === "open" || mode === "closed" || mode === "permissive") failureMode = mode;
|
|
93
|
-
log.info(`Identity failure mode: ${failureMode}`);
|
|
94
|
-
}).catch(() => {
|
|
95
|
-
log.info(`Identity failure mode: ${failureMode} (default — config fetch failed)`);
|
|
96
|
-
});
|
|
97
|
-
const identityToolNames = /* @__PURE__ */ new Set();
|
|
98
|
-
const tools = [
|
|
99
|
-
defineTool({
|
|
100
|
-
name: "who_is_this",
|
|
101
|
-
description: "Look up full identity context by platform and ID — returns profile, notes, tags, platforms, and recent changelog",
|
|
102
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
103
|
-
platform: _sinclair_typebox.Type.String({ description: "Platform name (discord, slack, chat, sms, whatsapp, etc.)" }),
|
|
104
|
-
platformId: _sinclair_typebox.Type.String({ description: "Platform-specific user identifier" })
|
|
105
|
-
}),
|
|
106
|
-
handler: async (params) => {
|
|
107
|
-
const result = await client.resolveIdentity({
|
|
108
|
-
platform: params.platform,
|
|
109
|
-
platformId: params.platformId
|
|
110
|
-
});
|
|
111
|
-
if (!result.identityId) return { found: false };
|
|
112
|
-
return client.getIdentityContext(result.identityId);
|
|
113
|
-
}
|
|
114
|
-
}),
|
|
115
|
-
defineTool({
|
|
116
|
-
name: "lookup_identity",
|
|
117
|
-
description: "Search identities by name, email, phone, tag, or platform. Returns multiple matches.",
|
|
118
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
119
|
-
query: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String({ description: "Text search query" })),
|
|
120
|
-
status: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String()),
|
|
121
|
-
tag: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String()),
|
|
122
|
-
platform: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String())
|
|
123
|
-
}),
|
|
124
|
-
handler: (params) => client.searchIdentities({
|
|
125
|
-
q: params.query,
|
|
126
|
-
status: params.status,
|
|
127
|
-
tag: params.tag,
|
|
128
|
-
platform: params.platform
|
|
129
|
-
})
|
|
130
|
-
}),
|
|
131
|
-
defineTool({
|
|
132
|
-
name: "create_identity",
|
|
133
|
-
description: "Create a new identity record with profile fields",
|
|
134
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
135
|
-
platform: _sinclair_typebox.Type.String(),
|
|
136
|
-
platformId: _sinclair_typebox.Type.String(),
|
|
137
|
-
displayName: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String())
|
|
138
|
-
}),
|
|
139
|
-
handler: (params) => client.resolveIdentity({
|
|
140
|
-
platform: params.platform,
|
|
141
|
-
platformId: params.platformId,
|
|
142
|
-
displayName: params.displayName
|
|
143
|
-
})
|
|
144
|
-
}),
|
|
145
|
-
defineTool({
|
|
146
|
-
name: "merge_identities",
|
|
147
|
-
description: "Merge two identity records — transfers notes, tags, aliases, platforms to survivor",
|
|
148
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
149
|
-
survivorId: _sinclair_typebox.Type.String({ description: "Identity to keep" }),
|
|
150
|
-
mergedId: _sinclair_typebox.Type.String({ description: "Identity to merge into survivor" })
|
|
151
|
-
}),
|
|
152
|
-
handler: (params) => client.mergeIdentities(params.survivorId, {
|
|
153
|
-
mergedId: params.mergedId,
|
|
154
|
-
changedBy: {
|
|
155
|
-
type: "agent",
|
|
156
|
-
id: "plugin"
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
}),
|
|
160
|
-
defineTool({
|
|
161
|
-
name: "unmerge_identities",
|
|
162
|
-
description: "Reverse a merge — restore previously merged identity",
|
|
163
|
-
parameters: _sinclair_typebox.Type.Object({ mergedId: _sinclair_typebox.Type.String({ description: "Identity that was merged (has mergedInto pointer)" }) }),
|
|
164
|
-
handler: (params) => client.unmergeIdentity(params.mergedId, { changedBy: {
|
|
165
|
-
type: "agent",
|
|
166
|
-
id: "plugin"
|
|
167
|
-
} })
|
|
168
|
-
}),
|
|
169
|
-
defineTool({
|
|
170
|
-
name: "link_platform",
|
|
171
|
-
description: "Link a platform identity to an existing identity record",
|
|
172
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
173
|
-
identityId: _sinclair_typebox.Type.String(),
|
|
174
|
-
platform: _sinclair_typebox.Type.String(),
|
|
175
|
-
platformId: _sinclair_typebox.Type.String()
|
|
176
|
-
}),
|
|
177
|
-
handler: (params) => client.resolveIdentity({
|
|
178
|
-
platform: params.platform,
|
|
179
|
-
platformId: params.platformId
|
|
180
|
-
})
|
|
181
|
-
}),
|
|
182
|
-
defineTool({
|
|
183
|
-
name: "add_identity_note",
|
|
184
|
-
description: "Add an observation or note about a contact",
|
|
185
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
186
|
-
identityId: _sinclair_typebox.Type.String(),
|
|
187
|
-
content: _sinclair_typebox.Type.String(),
|
|
188
|
-
category: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String({ description: "observation, preference, relationship, context, or warning" }))
|
|
189
|
-
}),
|
|
190
|
-
handler: (params) => client.addIdentityNote(params.identityId, {
|
|
191
|
-
content: params.content,
|
|
192
|
-
category: params.category,
|
|
193
|
-
changedBy: {
|
|
194
|
-
type: "agent",
|
|
195
|
-
id: "plugin"
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
}),
|
|
199
|
-
defineTool({
|
|
200
|
-
name: "tag_identity",
|
|
201
|
-
description: "Add or remove a tag on an identity",
|
|
202
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
203
|
-
identityId: _sinclair_typebox.Type.String(),
|
|
204
|
-
tag: _sinclair_typebox.Type.String(),
|
|
205
|
-
action: _sinclair_typebox.Type.String({ description: "'add' or 'remove'" })
|
|
206
|
-
}),
|
|
207
|
-
handler: (params) => client.tagIdentity(params.identityId, {
|
|
208
|
-
tag: params.tag,
|
|
209
|
-
action: params.action,
|
|
210
|
-
changedBy: {
|
|
211
|
-
type: "agent",
|
|
212
|
-
id: "plugin"
|
|
213
|
-
}
|
|
214
|
-
})
|
|
215
|
-
}),
|
|
216
|
-
defineTool({
|
|
217
|
-
name: "get_identity_changelog",
|
|
218
|
-
description: "Get full changelog for an identity — all versions, diffs, who changed what",
|
|
219
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
220
|
-
identityId: _sinclair_typebox.Type.String(),
|
|
221
|
-
limit: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.Number())
|
|
222
|
-
}),
|
|
223
|
-
handler: (params) => client.getIdentityChangelog(params.identityId, { limit: params.limit })
|
|
224
|
-
}),
|
|
225
|
-
defineTool({
|
|
226
|
-
name: "rollback_identity",
|
|
227
|
-
description: "Revert an identity to a previous version",
|
|
228
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
229
|
-
identityId: _sinclair_typebox.Type.String(),
|
|
230
|
-
targetVersion: _sinclair_typebox.Type.Number()
|
|
231
|
-
}),
|
|
232
|
-
handler: (params) => client.rollbackIdentity(params.identityId, {
|
|
233
|
-
targetVersion: params.targetVersion,
|
|
234
|
-
changedBy: {
|
|
235
|
-
type: "agent",
|
|
236
|
-
id: "plugin"
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
}),
|
|
240
|
-
defineTool({
|
|
241
|
-
name: "enforce_policy",
|
|
242
|
-
description: "Resolve sender identity and return their tool policy",
|
|
243
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
244
|
-
platform: _sinclair_typebox.Type.String(),
|
|
245
|
-
senderId: _sinclair_typebox.Type.String(),
|
|
246
|
-
channelId: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String())
|
|
247
|
-
}),
|
|
248
|
-
handler: (params) => client.enforcePolicy({
|
|
249
|
-
platform: params.platform,
|
|
250
|
-
senderId: params.senderId,
|
|
251
|
-
channelId: params.channelId
|
|
252
|
-
})
|
|
253
|
-
}),
|
|
254
|
-
defineTool({
|
|
255
|
-
name: "check_permission",
|
|
256
|
-
description: "Check if a specific tool call is allowed for a sender",
|
|
257
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
258
|
-
platform: _sinclair_typebox.Type.String(),
|
|
259
|
-
senderId: _sinclair_typebox.Type.String(),
|
|
260
|
-
toolName: _sinclair_typebox.Type.String()
|
|
261
|
-
}),
|
|
262
|
-
handler: (params) => client.checkToolPermission({
|
|
263
|
-
platform: params.platform,
|
|
264
|
-
senderId: params.senderId,
|
|
265
|
-
toolName: params.toolName
|
|
266
|
-
})
|
|
267
|
-
}),
|
|
268
|
-
defineTool({
|
|
269
|
-
name: "request_identity_verification",
|
|
270
|
-
description: "Send a verification phrase to the claimed identity's phone (SMS) or email. The person must relay the phrase back to confirm they own that identity.",
|
|
271
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
272
|
-
claimedIdentityId: _sinclair_typebox.Type.String({ description: "Identity being claimed" }),
|
|
273
|
-
requestingIdentityId: _sinclair_typebox.Type.String({ description: "Identity of the person making the claim" }),
|
|
274
|
-
requestingPlatform: _sinclair_typebox.Type.String({ description: "Platform the requester is on (discord, slack, chat, etc.)" }),
|
|
275
|
-
requestingPlatformId: _sinclair_typebox.Type.String({ description: "Requester's platform-specific user ID" }),
|
|
276
|
-
preferredChannel: _sinclair_typebox.Type.Optional(_sinclair_typebox.Type.String({ description: "'sms' or 'email'" }))
|
|
277
|
-
}),
|
|
278
|
-
handler: (params) => client.requestIdentityVerification({
|
|
279
|
-
claimedIdentityId: params.claimedIdentityId,
|
|
280
|
-
requestingIdentityId: params.requestingIdentityId,
|
|
281
|
-
requestingPlatform: params.requestingPlatform,
|
|
282
|
-
requestingPlatformId: params.requestingPlatformId,
|
|
283
|
-
preferredChannel: params.preferredChannel
|
|
284
|
-
})
|
|
285
|
-
}),
|
|
286
|
-
defineTool({
|
|
287
|
-
name: "confirm_identity_verification",
|
|
288
|
-
description: "Confirm a verification by providing the three-word phrase. On success, the requesting identity is merged into the claimed identity.",
|
|
289
|
-
parameters: _sinclair_typebox.Type.Object({
|
|
290
|
-
verificationId: _sinclair_typebox.Type.String({ description: "Verification ID returned from request_identity_verification" }),
|
|
291
|
-
phrase: _sinclair_typebox.Type.String({ description: "Three-word phrase the person received via SMS or email" })
|
|
292
|
-
}),
|
|
293
|
-
handler: (params) => client.confirmIdentityVerification({
|
|
294
|
-
verificationId: params.verificationId,
|
|
295
|
-
phrase: params.phrase
|
|
296
|
-
})
|
|
297
|
-
})
|
|
298
|
-
];
|
|
299
|
-
for (const tool of tools) {
|
|
300
|
-
api.registerTool(tool);
|
|
301
|
-
identityToolNames.add(tool.name);
|
|
302
|
-
}
|
|
303
|
-
log.info(`Registered ${String(tools.length)} identity tools`);
|
|
304
|
-
api.on("message_received", async (...args) => {
|
|
305
|
-
const event = args[0];
|
|
306
|
-
const ctx = args[1];
|
|
307
|
-
const platform = ctx.channelId ?? "unknown";
|
|
308
|
-
const senderId = event.from;
|
|
309
|
-
if (!senderId) return;
|
|
310
|
-
const cacheKey = ctx.conversationId ?? `${platform}:${senderId}`;
|
|
311
|
-
const cached = getCached(cacheKey);
|
|
312
|
-
if (cached) {
|
|
313
|
-
if (!cached.accessAllowed) return {
|
|
314
|
-
block: true,
|
|
315
|
-
blockReason: "Identity: access denied for this sender"
|
|
316
|
-
};
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
const resolveResult = await client.resolveIdentity({
|
|
321
|
-
platform,
|
|
322
|
-
platformId: senderId
|
|
323
|
-
});
|
|
324
|
-
setCached(cacheKey, {
|
|
325
|
-
...await client.enforcePolicy({
|
|
326
|
-
platform,
|
|
327
|
-
senderId
|
|
328
|
-
}),
|
|
329
|
-
accessAllowed: resolveResult.accessAllowed
|
|
330
|
-
});
|
|
331
|
-
if (!resolveResult.accessAllowed) return {
|
|
332
|
-
block: true,
|
|
333
|
-
blockReason: "Identity: access denied for this sender"
|
|
334
|
-
};
|
|
335
|
-
log.info(`Identity resolved: ${senderId} → ${resolveResult.identityId ?? "unknown"} (${resolveResult.status})`);
|
|
336
|
-
} catch (e) {
|
|
337
|
-
log.error(`Identity resolution failed for ${senderId}: ${e.message}`);
|
|
338
|
-
if (failureMode === "closed") return {
|
|
339
|
-
block: true,
|
|
340
|
-
blockReason: "Identity: identity service unavailable — access denied (closed mode)"
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}, { priority: 100 });
|
|
344
|
-
api.on("before_tool_call", async (...args) => {
|
|
345
|
-
const event = args[0];
|
|
346
|
-
const ctx = args[1];
|
|
347
|
-
if (identityToolNames.has(event.toolName)) return;
|
|
348
|
-
const sessionKey = ctx.sessionKey;
|
|
349
|
-
if (!sessionKey) return;
|
|
350
|
-
const perms = getCached(sessionKey);
|
|
351
|
-
if (!perms) {
|
|
352
|
-
if (failureMode === "permissive") return;
|
|
353
|
-
return {
|
|
354
|
-
block: true,
|
|
355
|
-
blockReason: "Identity: no identity context established — tool access denied"
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
if (!perms.identified) {
|
|
359
|
-
if (failureMode === "permissive") return;
|
|
360
|
-
return {
|
|
361
|
-
block: true,
|
|
362
|
-
blockReason: "Identity: unknown sender identity — tool access denied"
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
if (perms.deniedTools.includes("*") || perms.deniedTools.includes(event.toolName)) return {
|
|
366
|
-
block: true,
|
|
367
|
-
blockReason: `Identity: tool '${event.toolName}' is denied for your role`
|
|
368
|
-
};
|
|
369
|
-
if (perms.allowedTools.length > 0 && !perms.allowedTools.includes(event.toolName)) return {
|
|
370
|
-
block: true,
|
|
371
|
-
blockReason: `Identity: tool '${event.toolName}' is not in your allowed tools`
|
|
372
|
-
};
|
|
373
|
-
}, { priority: 100 });
|
|
374
|
-
api.on("after_tool_call", async (...args) => {
|
|
375
|
-
const event = args[0];
|
|
376
|
-
const sessionKey = args[1].sessionKey;
|
|
377
|
-
if (!sessionKey) return;
|
|
378
|
-
const perms = getCached(sessionKey);
|
|
379
|
-
if (!perms?.identityId) return;
|
|
380
|
-
try {
|
|
381
|
-
await client.checkToolPermission({
|
|
382
|
-
platform: "tool_audit",
|
|
383
|
-
senderId: perms.identityId,
|
|
384
|
-
toolName: event.toolName
|
|
385
|
-
});
|
|
386
|
-
} catch (e) {
|
|
387
|
-
log.error(`Audit logging failed: ${e.message}`);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
log.info("Alfe Identity plugin activated");
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
//#endregion
|
|
394
|
-
module.exports = plugin;
|
|
1
|
+
const require_plugin = require("./plugin2.cjs");
|
|
2
|
+
module.exports = require_plugin.plugin;
|