@agentvault/agentvault 0.15.2 → 0.16.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.
@@ -1 +1 @@
1
- {"version":3,"file":"openclaw-entry.d.ts","sourceRoot":"","sources":["../src/openclaw-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,KAAK,EACV,iBAAiB,EASlB,MAAM,qBAAqB,CAAC;AAsD7B,gFAAgF;AAChF,eAAO,IAAI,oBAAoB,SAAQ,CAAC;AA6CxC,uEAAuE;AACvE,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAS9C;AAED,qFAAqF;AACrF,iBAAS,yBAAyB,CAChC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAcT;AAED,sFAAsF;AACtF,iBAAS,cAAc,CACrB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAiBR;AAk1BD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,CAAC;;;;;kBAQrD,iBAAiB;;AAJjC,wBAoRE"}
1
+ {"version":3,"file":"openclaw-entry.d.ts","sourceRoot":"","sources":["../src/openclaw-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,KAAK,EACV,iBAAiB,EASlB,MAAM,qBAAqB,CAAC;AAsD7B,gFAAgF;AAChF,eAAO,IAAI,oBAAoB,SAAQ,CAAC;AA+CxC,uEAAuE;AACvE,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAS9C;AAED,qFAAqF;AACrF,iBAAS,yBAAyB,CAChC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAcT;AAED,sFAAsF;AACtF,iBAAS,cAAc,CACrB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAiBR;AA00BD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,CAAC;;;;;kBAQrD,iBAAiB;;AAJjC,wBA8RE"}
@@ -296,32 +296,55 @@ async function handleSendRequest(parsed, channel) {
296
296
  return { status: 400, body: { ok: false, error: "Missing 'text' field" } };
297
297
  }
298
298
  try {
299
+ let target;
299
300
  let a2aTarget = parsed.hub_address ?? parsed.a2a_address ?? parsed.a2aAddress;
300
301
  if (!a2aTarget && parsed.channel_id && typeof parsed.channel_id === "string") {
301
302
  const hubAddr = channel.resolveA2AChannelHub(parsed.channel_id);
302
303
  if (hubAddr) a2aTarget = hubAddr;
303
304
  }
304
- const roomId = (typeof parsed.room_id === "string" ? parsed.room_id : void 0) ?? channel.lastInboundRoomId;
305
305
  if (a2aTarget && typeof a2aTarget === "string") {
306
- await channel.sendToAgent(a2aTarget, text);
307
- } else if (roomId) {
308
- await channel.sendToRoom(roomId, text, {
309
- messageType: parsed.message_type,
310
- priority: parsed.priority,
311
- metadata: parsed.metadata
312
- });
306
+ target = { kind: "a2a", hubAddress: a2aTarget };
307
+ } else if (typeof parsed.room_id === "string") {
308
+ target = { kind: "room", roomId: parsed.room_id };
309
+ } else if (parsed.target === "context") {
310
+ target = { kind: "context" };
313
311
  } else if (parsed.file_path && typeof parsed.file_path === "string") {
314
- await channel.sendWithAttachment(text, parsed.file_path, {
315
- topicId: parsed.topicId
316
- });
312
+ const receipt2 = await channel.deliver(
313
+ { kind: "owner" },
314
+ { type: "attachment", text, filePath: parsed.file_path },
315
+ { topicId: parsed.topicId }
316
+ );
317
+ return {
318
+ status: receipt2.ok ? 200 : 500,
319
+ body: {
320
+ ok: receipt2.ok,
321
+ destination: receipt2.destination,
322
+ ...receipt2.error ? { error: receipt2.error } : {}
323
+ }
324
+ };
317
325
  } else {
318
- await channel.send(text, {
319
- topicId: parsed.topicId,
320
- messageType: parsed.message_type,
321
- metadata: parsed.metadata
322
- });
326
+ target = { kind: "owner" };
323
327
  }
324
- return { status: 200, body: { ok: true } };
328
+ const receipt = await channel.deliver(
329
+ target,
330
+ { type: "text", text },
331
+ {
332
+ topicId: parsed.topicId,
333
+ priority: parsed.priority,
334
+ metadata: {
335
+ ...parsed.metadata,
336
+ ...parsed.message_type ? { message_type: parsed.message_type } : {}
337
+ }
338
+ }
339
+ );
340
+ return {
341
+ status: receipt.ok ? 200 : 500,
342
+ body: {
343
+ ok: receipt.ok,
344
+ destination: receipt.destination,
345
+ ...receipt.error ? { error: receipt.error } : {}
346
+ }
347
+ };
325
348
  } catch (err) {
326
349
  return { status: 500, body: { ok: false, error: String(err) } };
327
350
  }
@@ -338,12 +361,19 @@ async function handleActionRequest(parsed, channel) {
338
361
  detail: parsed.detail,
339
362
  estimated_cost: parsed.estimated_cost
340
363
  };
341
- if (parsed.room_id && typeof parsed.room_id === "string") {
342
- await channel.sendActionConfirmationToRoom(parsed.room_id, confirmation);
343
- } else {
344
- await channel.sendActionConfirmation(confirmation);
345
- }
346
- return { status: 200, body: { ok: true } };
364
+ const target = parsed.room_id && typeof parsed.room_id === "string" ? { kind: "room", roomId: parsed.room_id } : { kind: "owner" };
365
+ const receipt = await channel.deliver(
366
+ target,
367
+ { type: "action_confirmation", confirmation }
368
+ );
369
+ return {
370
+ status: receipt.ok ? 200 : 500,
371
+ body: {
372
+ ok: receipt.ok,
373
+ destination: receipt.destination,
374
+ ...receipt.error ? { error: receipt.error } : {}
375
+ }
376
+ };
347
377
  } catch (err) {
348
378
  return { status: 500, body: { ok: false, error: String(err) } };
349
379
  }
@@ -387,9 +417,49 @@ function handleStatusRequest(channel) {
387
417
  }
388
418
  };
389
419
  }
420
+ function handleTargetsRequest(channel) {
421
+ return {
422
+ status: 200,
423
+ body: {
424
+ ok: true,
425
+ targets: channel.listTargets(),
426
+ context: channel.lastInboundRoomId ? { kind: "room", roomId: channel.lastInboundRoomId } : { kind: "owner" }
427
+ }
428
+ };
429
+ }
390
430
 
391
431
  // src/openclaw-entry.ts
392
432
  init_openclaw_compat();
433
+
434
+ // src/types.ts
435
+ function parseTarget(raw) {
436
+ let target = raw;
437
+ if (target.startsWith("agentvault:")) {
438
+ target = target.slice("agentvault:".length);
439
+ }
440
+ if (target.startsWith("agent:")) {
441
+ target = "a2a:" + target.slice("agent:".length);
442
+ }
443
+ if (target === "owner" || target === "default") {
444
+ return { kind: "owner" };
445
+ }
446
+ if (target === "context") {
447
+ return { kind: "context" };
448
+ }
449
+ if (target.startsWith("room:")) {
450
+ const roomId = target.slice("room:".length);
451
+ if (!roomId) throw new Error(`Invalid room target: "${raw}" \u2014 missing room ID`);
452
+ return { kind: "room", roomId };
453
+ }
454
+ if (target.startsWith("a2a:")) {
455
+ const hubAddress = target.slice("a2a:".length);
456
+ if (!hubAddress) throw new Error(`Invalid A2A target: "${raw}" \u2014 missing hub address`);
457
+ return { kind: "a2a", hubAddress };
458
+ }
459
+ throw new Error(`Unrecognized delivery target: "${raw}". Use "owner", "room:<id>", "a2a:<addr>", or "context".`);
460
+ }
461
+
462
+ // src/openclaw-entry.ts
393
463
  var _ocRuntime = null;
394
464
  var _channels = /* @__PURE__ */ new Map();
395
465
  var _messageQueue = [];
@@ -672,12 +742,28 @@ async function handleInbound(params) {
672
742
  } catch {
673
743
  }
674
744
  const core = _ocRuntime;
745
+ let roomName;
746
+ let senderDisplayName;
747
+ if (isRoomMessage && metadata.roomId) {
748
+ roomName = metadata.roomName;
749
+ if (!roomName) {
750
+ const rooms = channel.getRooms?.() ?? [];
751
+ const room = rooms.find((r) => r.roomId === metadata.roomId);
752
+ if (room) {
753
+ roomName = room.name;
754
+ if (metadata.senderDeviceId) {
755
+ const member = room.members?.find((m) => m.deviceId === metadata.senderDeviceId);
756
+ if (member) senderDisplayName = member.displayName;
757
+ }
758
+ }
759
+ }
760
+ }
675
761
  const route = core.channel.routing.resolveAgentRoute({
676
762
  cfg,
677
763
  channel: "agentvault",
678
764
  accountId: account.accountId,
679
765
  peer: {
680
- kind: isA2AMessage ? "a2a" : "direct",
766
+ kind: isA2AMessage ? "a2a" : isRoomMessage ? "group" : "direct",
681
767
  id: isA2AMessage ? `agentvault:a2a:${metadata.fromHubAddress}` : isRoomMessage ? `agentvault:room:${metadata.roomId}` : "agentvault:owner"
682
768
  }
683
769
  });
@@ -691,7 +777,7 @@ async function handleInbound(params) {
691
777
  });
692
778
  const body = core.channel.reply.formatAgentEnvelope({
693
779
  channel: "AgentVault",
694
- from: isA2AMessage ? `Agent (${metadata.fromHubAddress})` : isRoomMessage ? "Room" : "Owner",
780
+ from: isA2AMessage ? `Agent (${metadata.fromHubAddress})` : isRoomMessage ? senderDisplayName ?? "Room Member" : "Owner",
695
781
  timestamp: new Date(metadata.timestamp).getTime(),
696
782
  previousTimestamp,
697
783
  envelope: envelopeOptions,
@@ -716,9 +802,9 @@ async function handleInbound(params) {
716
802
  SessionKey: route.sessionKey,
717
803
  AccountId: account.accountId,
718
804
  ChatType: isA2AMessage ? "a2a" : isRoomMessage ? "room" : "direct",
719
- ConversationLabel: isA2AMessage ? `A2A: ${metadata.fromHubAddress}` : isRoomMessage ? "AgentVault Room" : "AgentVault",
720
- SenderName: isA2AMessage ? metadata.fromHubAddress : isRoomMessage ? "Room" : "Owner",
721
- SenderId: isA2AMessage ? `a2a:${metadata.fromHubAddress}` : isRoomMessage ? `agentvault:room:${metadata.roomId}` : "agentvault:owner",
805
+ ConversationLabel: isA2AMessage ? `A2A: ${metadata.fromHubAddress}` : isRoomMessage ? roomName ?? "AgentVault Room" : "AgentVault",
806
+ SenderName: isA2AMessage ? metadata.fromHubAddress : isRoomMessage ? senderDisplayName ?? "Room Member" : "Owner",
807
+ SenderId: isA2AMessage ? `a2a:${metadata.fromHubAddress}` : isRoomMessage ? `agentvault:room:${metadata.senderDeviceId ?? metadata.roomId}` : "agentvault:owner",
722
808
  Provider: "agentvault",
723
809
  Surface: "agentvault",
724
810
  MessageSid: metadata.messageId,
@@ -756,24 +842,26 @@ async function handleInbound(params) {
756
842
  replyCount++;
757
843
  totalReplyChars += text.length;
758
844
  if (!firstReplyTime) firstReplyTime = replyStart;
845
+ let replyTarget;
759
846
  if (isA2AMessage) {
760
847
  if (!_a2aCanReply(metadata.a2aChannelId)) {
761
848
  console.warn(`[AgentVault] A2A reply suppressed (rate limit) for channel ${metadata.a2aChannelId?.slice(0, 8)}...`);
762
849
  return;
763
850
  }
764
- await channel.sendToAgent(metadata.fromHubAddress, text, {
765
- parentSpanId: inferenceSpanId
766
- });
767
- _a2aRecordReply(metadata.a2aChannelId);
851
+ replyTarget = { kind: "a2a", hubAddress: metadata.fromHubAddress };
768
852
  } else if (isRoomMessage) {
769
- await channel.sendToRoom(metadata.roomId, text, {
770
- metadata: { content_length: text.length }
771
- });
853
+ replyTarget = { kind: "room", roomId: metadata.roomId };
772
854
  } else {
773
- await channel.send(text, {
774
- conversationId: metadata.conversationId,
775
- topicId: metadata.topicId
776
- });
855
+ replyTarget = { kind: "owner" };
856
+ }
857
+ await channel.deliver(replyTarget, { type: "text", text }, {
858
+ conversationId: metadata.conversationId,
859
+ topicId: metadata.topicId,
860
+ parentSpanId: inferenceSpanId,
861
+ metadata: isRoomMessage ? { content_length: text.length } : void 0
862
+ });
863
+ if (isA2AMessage) {
864
+ _a2aRecordReply(metadata.a2aChannelId);
777
865
  }
778
866
  const replyEnd = Date.now();
779
867
  replySpans.push({ startTime: replyStart, endTime: replyEnd, chars: text.length, index: replyCount });
@@ -1134,50 +1222,28 @@ var agentVaultPlugin = {
1134
1222
  // Register valid send targets so OpenClaw's `message` tool can route
1135
1223
  // proactive (agent-initiated) sends — not just replies to inbound messages.
1136
1224
  targets: _outboundTargets,
1137
- sendText: async ({ to, text, accountId }) => {
1225
+ sendText: async ({ to: rawTo, text, accountId }) => {
1138
1226
  const resolvedId = accountId ?? "default";
1139
1227
  const ch = _channels.get(resolvedId);
1140
1228
  if (!ch) return { ok: false, error: "AgentVault channel not connected" };
1141
1229
  try {
1142
- const wasReady = ch.state === "ready";
1143
- if (to.startsWith("a2a:")) {
1144
- await ch.sendToAgent(to.slice(4), text);
1145
- } else if (to.startsWith("room:")) {
1146
- await ch.sendToRoom(to.slice(5), text);
1147
- } else {
1148
- const roomId = ch.lastInboundRoomId;
1149
- if (roomId) {
1150
- await ch.sendToRoom(roomId, text);
1151
- } else {
1152
- await ch.send(text);
1153
- }
1154
- }
1155
- return { ok: true, queued: !wasReady };
1230
+ const target = parseTarget(rawTo);
1231
+ const receipt = await ch.deliver(target, { type: "text", text });
1232
+ return { ok: receipt.ok, queued: receipt.queued, error: receipt.error };
1156
1233
  } catch (err) {
1157
1234
  return { ok: false, error: String(err) };
1158
1235
  }
1159
1236
  },
1160
- sendMedia: async ({ to, text, mediaUrl, accountId }) => {
1237
+ sendMedia: async ({ to: rawTo, text, mediaUrl, accountId }) => {
1161
1238
  const resolvedId = accountId ?? "default";
1162
1239
  const ch = _channels.get(resolvedId);
1163
1240
  if (!ch) return { ok: false, error: "AgentVault channel not connected" };
1164
1241
  try {
1165
1242
  const message = text ? `${text}
1166
1243
  ${mediaUrl}` : mediaUrl;
1167
- const wasReady = ch.state === "ready";
1168
- if (to.startsWith("a2a:")) {
1169
- await ch.sendToAgent(to.slice(4), message);
1170
- } else if (to.startsWith("room:")) {
1171
- await ch.sendToRoom(to.slice(5), message);
1172
- } else {
1173
- const roomId = ch.lastInboundRoomId;
1174
- if (roomId) {
1175
- await ch.sendToRoom(roomId, message);
1176
- } else {
1177
- await ch.send(message);
1178
- }
1179
- }
1180
- return { ok: true, queued: !wasReady };
1244
+ const target = parseTarget(rawTo);
1245
+ const receipt = await ch.deliver(target, { type: "text", text: message });
1246
+ return { ok: receipt.ok, queued: receipt.queued, error: receipt.error };
1181
1247
  } catch (err) {
1182
1248
  return { ok: false, error: String(err) };
1183
1249
  }
@@ -1194,20 +1260,15 @@ ${mediaUrl}` : mediaUrl;
1194
1260
  });
1195
1261
  const text = (payload.text ?? "").trim();
1196
1262
  if (!text && !payload.mediaUrls?.length) return { ok: true };
1263
+ const rawTarget = ctx.to;
1264
+ let target;
1265
+ if (rawTarget && typeof rawTarget === "string") {
1266
+ target = parseTarget(rawTarget);
1267
+ } else {
1268
+ target = { kind: "owner" };
1269
+ }
1197
1270
  const _send = async (msg) => {
1198
- const target = ctx.to;
1199
- if (target && typeof target === "string" && target.startsWith("a2a:")) {
1200
- await ch.sendToAgent(target.slice(4), msg);
1201
- } else if (target && typeof target === "string" && target.startsWith("room:")) {
1202
- await ch.sendToRoom(target.slice(5), msg);
1203
- } else {
1204
- const roomId = ch.lastInboundRoomId;
1205
- if (roomId) {
1206
- await ch.sendToRoom(roomId, msg);
1207
- } else {
1208
- await ch.send(msg);
1209
- }
1210
- }
1271
+ await ch.deliver(target, { type: "text", text: msg });
1211
1272
  };
1212
1273
  if (text) {
1213
1274
  await _send(text);
@@ -1328,6 +1389,16 @@ var openclaw_entry_default = {
1328
1389
  return { status: result.status, body: result.body };
1329
1390
  }
1330
1391
  });
1392
+ api.registerHttpRoute({
1393
+ path: "/agentvault/targets",
1394
+ method: "GET",
1395
+ handler: async () => {
1396
+ const ch = _channels.values().next().value;
1397
+ if (!ch) return { status: 503, body: { ok: false, error: "Channel not started" } };
1398
+ const result = handleTargetsRequest(ch);
1399
+ return { status: result.status, body: result.body };
1400
+ }
1401
+ });
1331
1402
  isUsingManagedRoutes = true;
1332
1403
  } catch {
1333
1404
  }