@agentvault/agentvault 0.15.3 → 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;AAo2BD,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 = [];
@@ -772,24 +842,26 @@ async function handleInbound(params) {
772
842
  replyCount++;
773
843
  totalReplyChars += text.length;
774
844
  if (!firstReplyTime) firstReplyTime = replyStart;
845
+ let replyTarget;
775
846
  if (isA2AMessage) {
776
847
  if (!_a2aCanReply(metadata.a2aChannelId)) {
777
848
  console.warn(`[AgentVault] A2A reply suppressed (rate limit) for channel ${metadata.a2aChannelId?.slice(0, 8)}...`);
778
849
  return;
779
850
  }
780
- await channel.sendToAgent(metadata.fromHubAddress, text, {
781
- parentSpanId: inferenceSpanId
782
- });
783
- _a2aRecordReply(metadata.a2aChannelId);
851
+ replyTarget = { kind: "a2a", hubAddress: metadata.fromHubAddress };
784
852
  } else if (isRoomMessage) {
785
- await channel.sendToRoom(metadata.roomId, text, {
786
- metadata: { content_length: text.length }
787
- });
853
+ replyTarget = { kind: "room", roomId: metadata.roomId };
788
854
  } else {
789
- await channel.send(text, {
790
- conversationId: metadata.conversationId,
791
- topicId: metadata.topicId
792
- });
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);
793
865
  }
794
866
  const replyEnd = Date.now();
795
867
  replySpans.push({ startTime: replyStart, endTime: replyEnd, chars: text.length, index: replyCount });
@@ -1150,50 +1222,28 @@ var agentVaultPlugin = {
1150
1222
  // Register valid send targets so OpenClaw's `message` tool can route
1151
1223
  // proactive (agent-initiated) sends — not just replies to inbound messages.
1152
1224
  targets: _outboundTargets,
1153
- sendText: async ({ to, text, accountId }) => {
1225
+ sendText: async ({ to: rawTo, text, accountId }) => {
1154
1226
  const resolvedId = accountId ?? "default";
1155
1227
  const ch = _channels.get(resolvedId);
1156
1228
  if (!ch) return { ok: false, error: "AgentVault channel not connected" };
1157
1229
  try {
1158
- const wasReady = ch.state === "ready";
1159
- if (to.startsWith("a2a:")) {
1160
- await ch.sendToAgent(to.slice(4), text);
1161
- } else if (to.startsWith("room:")) {
1162
- await ch.sendToRoom(to.slice(5), text);
1163
- } else {
1164
- const roomId = ch.lastInboundRoomId;
1165
- if (roomId) {
1166
- await ch.sendToRoom(roomId, text);
1167
- } else {
1168
- await ch.send(text);
1169
- }
1170
- }
1171
- 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 };
1172
1233
  } catch (err) {
1173
1234
  return { ok: false, error: String(err) };
1174
1235
  }
1175
1236
  },
1176
- sendMedia: async ({ to, text, mediaUrl, accountId }) => {
1237
+ sendMedia: async ({ to: rawTo, text, mediaUrl, accountId }) => {
1177
1238
  const resolvedId = accountId ?? "default";
1178
1239
  const ch = _channels.get(resolvedId);
1179
1240
  if (!ch) return { ok: false, error: "AgentVault channel not connected" };
1180
1241
  try {
1181
1242
  const message = text ? `${text}
1182
1243
  ${mediaUrl}` : mediaUrl;
1183
- const wasReady = ch.state === "ready";
1184
- if (to.startsWith("a2a:")) {
1185
- await ch.sendToAgent(to.slice(4), message);
1186
- } else if (to.startsWith("room:")) {
1187
- await ch.sendToRoom(to.slice(5), message);
1188
- } else {
1189
- const roomId = ch.lastInboundRoomId;
1190
- if (roomId) {
1191
- await ch.sendToRoom(roomId, message);
1192
- } else {
1193
- await ch.send(message);
1194
- }
1195
- }
1196
- 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 };
1197
1247
  } catch (err) {
1198
1248
  return { ok: false, error: String(err) };
1199
1249
  }
@@ -1210,20 +1260,15 @@ ${mediaUrl}` : mediaUrl;
1210
1260
  });
1211
1261
  const text = (payload.text ?? "").trim();
1212
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
+ }
1213
1270
  const _send = async (msg) => {
1214
- const target = ctx.to;
1215
- if (target && typeof target === "string" && target.startsWith("a2a:")) {
1216
- await ch.sendToAgent(target.slice(4), msg);
1217
- } else if (target && typeof target === "string" && target.startsWith("room:")) {
1218
- await ch.sendToRoom(target.slice(5), msg);
1219
- } else {
1220
- const roomId = ch.lastInboundRoomId;
1221
- if (roomId) {
1222
- await ch.sendToRoom(roomId, msg);
1223
- } else {
1224
- await ch.send(msg);
1225
- }
1226
- }
1271
+ await ch.deliver(target, { type: "text", text: msg });
1227
1272
  };
1228
1273
  if (text) {
1229
1274
  await _send(text);
@@ -1344,6 +1389,16 @@ var openclaw_entry_default = {
1344
1389
  return { status: result.status, body: result.body };
1345
1390
  }
1346
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
+ });
1347
1402
  isUsingManagedRoutes = true;
1348
1403
  } catch {
1349
1404
  }