@agentchatme/openclaw 0.6.13 → 0.6.15

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.
@@ -7,8 +7,10 @@ var setup = require('openclaw/plugin-sdk/setup');
7
7
  var readEnv_js = require('./credentials/read-env.cjs');
8
8
  var agentsAnchor_js = require('./binding/agents-anchor.cjs');
9
9
  var zod = require('zod');
10
+ var channelLifecycle = require('openclaw/plugin-sdk/channel-lifecycle');
10
11
  var pino = require('pino');
11
12
  var ws = require('ws');
13
+ var directDm = require('openclaw/plugin-sdk/direct-dm');
12
14
  var agentchat = require('@agentchatme/agentchat');
13
15
  var typebox = require('@sinclair/typebox');
14
16
 
@@ -1853,7 +1855,7 @@ var CircuitBreaker = class {
1853
1855
  };
1854
1856
 
1855
1857
  // src/version.ts
1856
- var PACKAGE_VERSION = "0.6.13";
1858
+ var PACKAGE_VERSION = "0.6.15";
1857
1859
 
1858
1860
  // src/outbound.ts
1859
1861
  var DEFAULT_RETRY_POLICY = {
@@ -2382,8 +2384,6 @@ function unregisterRuntime(accountId, deadlineMs = Date.now() + 5e3) {
2382
2384
  function getRuntime(accountId) {
2383
2385
  return registry.get(accountId)?.runtime;
2384
2386
  }
2385
-
2386
- // src/binding/inbound-bridge.ts
2387
2387
  function createInboundBridge(deps) {
2388
2388
  return async function onInbound(event) {
2389
2389
  switch (event.kind) {
@@ -2420,8 +2420,8 @@ async function handleMessage(deps, event) {
2420
2420
  if (!body && !event.content.attachmentId && !event.content.data) {
2421
2421
  return;
2422
2422
  }
2423
- const dispatcher = deps.channelRuntime?.reply?.dispatchReplyWithBufferedBlockDispatcher;
2424
- if (typeof dispatcher !== "function") {
2423
+ const channelRuntime = deps.channelRuntime;
2424
+ if (!channelRuntime || typeof channelRuntime.reply?.dispatchReplyWithBufferedBlockDispatcher !== "function") {
2425
2425
  deps.logger.error(
2426
2426
  {
2427
2427
  event: "inbound_dispatch_unavailable",
@@ -2430,50 +2430,90 @@ async function handleMessage(deps, event) {
2430
2430
  conversationKind: event.conversationKind,
2431
2431
  sender: event.sender
2432
2432
  },
2433
- "channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher unavailable \u2014 message NOT dispatched to agent (will be redelivered on next sync)"
2433
+ "channelRuntime unavailable \u2014 message NOT dispatched to agent (will be redelivered on next sync)"
2434
2434
  );
2435
2435
  return;
2436
2436
  }
2437
2437
  const recipientHandle = selfHandle ?? "me";
2438
2438
  const conversationLabel = event.conversationKind === "group" ? `group ${event.conversationId}` : `dm with @${senderHandle}`;
2439
+ const sendReply = async (replyText) => {
2440
+ if (!replyText) return;
2441
+ const target = event.conversationKind === "group" ? { kind: "group", conversationId: event.conversationId } : { kind: "direct", to: senderHandle };
2442
+ await deps.runtime.sendMessage({
2443
+ ...target,
2444
+ type: "text",
2445
+ content: { text: replyText },
2446
+ metadata: { reply_to: event.messageId }
2447
+ });
2448
+ };
2449
+ const deliver2 = async (payload) => {
2450
+ const replyText = payload.text ?? extractText(payload.blocks);
2451
+ await sendReply(replyText);
2452
+ };
2439
2453
  try {
2440
- const sessionKey = event.conversationKind === "group" ? `agentchat:${deps.accountId}:group:${event.conversationId}` : `agentchat:${deps.accountId}:dm:${senderHandle}`;
2441
- await dispatcher({
2442
- cfg: deps.gatewayCfg,
2443
- ctx: {
2444
- Body: body,
2445
- BodyForAgent: body,
2446
- RawBody: body,
2447
- CommandBody: body,
2448
- From: `@${senderHandle}`,
2449
- To: `@${recipientHandle}`,
2450
- SessionKey: sessionKey,
2451
- AccountId: deps.accountId,
2452
- ChatType: event.conversationKind === "group" ? "group" : "direct",
2453
- ConversationLabel: conversationLabel,
2454
- SenderId: senderHandle,
2455
- Provider: "agentchat",
2456
- Surface: "agentchat",
2457
- MessageSid: event.messageId,
2458
- MessageSidFull: event.messageId,
2459
- Timestamp: event.createdAt,
2460
- OriginatingChannel: "agentchat",
2461
- OriginatingTo: `@${recipientHandle}`
2462
- },
2463
- dispatcherOptions: {
2464
- deliver: async (payload) => {
2465
- const replyText = payload.text ?? extractText(payload.blocks);
2466
- if (!replyText) return;
2467
- const target = event.conversationKind === "group" ? { kind: "group", conversationId: event.conversationId } : { kind: "direct", to: senderHandle };
2468
- await deps.runtime.sendMessage({
2469
- ...target,
2470
- type: "text",
2471
- content: { text: replyText },
2472
- metadata: { reply_to: event.messageId }
2473
- });
2454
+ if (event.conversationKind === "direct") {
2455
+ await directDm.dispatchInboundDirectDmWithRuntime({
2456
+ cfg: deps.gatewayCfg,
2457
+ runtime: { channel: channelRuntime },
2458
+ channel: "agentchat",
2459
+ channelLabel: "AgentChat",
2460
+ accountId: deps.accountId,
2461
+ peer: { kind: "direct", id: senderHandle },
2462
+ senderId: senderHandle,
2463
+ senderAddress: `@${senderHandle}`,
2464
+ recipientAddress: `@${recipientHandle}`,
2465
+ conversationLabel,
2466
+ rawBody: body,
2467
+ messageId: event.messageId,
2468
+ timestamp: typeof event.createdAt === "number" ? event.createdAt : Date.parse(event.createdAt),
2469
+ provider: "agentchat",
2470
+ surface: "agentchat",
2471
+ deliver: deliver2,
2472
+ onRecordError: (err3) => {
2473
+ deps.logger.error(
2474
+ { err: err3 instanceof Error ? err3.message : String(err3), messageId: event.messageId },
2475
+ "recordInboundSession failed"
2476
+ );
2477
+ },
2478
+ onDispatchError: (err3, info) => {
2479
+ deps.logger.error(
2480
+ {
2481
+ err: err3 instanceof Error ? err3.message : String(err3),
2482
+ messageId: event.messageId,
2483
+ kind: info.kind
2484
+ },
2485
+ "inbound dispatch failed"
2486
+ );
2474
2487
  }
2475
- }
2476
- });
2488
+ });
2489
+ } else {
2490
+ const dispatcher = channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher;
2491
+ const sessionKey = `agentchat:${deps.accountId}:group:${event.conversationId}`;
2492
+ await dispatcher({
2493
+ cfg: deps.gatewayCfg,
2494
+ ctx: {
2495
+ Body: body,
2496
+ BodyForAgent: body,
2497
+ RawBody: body,
2498
+ CommandBody: body,
2499
+ From: `@${senderHandle}`,
2500
+ To: `@${recipientHandle}`,
2501
+ SessionKey: sessionKey,
2502
+ AccountId: deps.accountId,
2503
+ ChatType: "group",
2504
+ ConversationLabel: conversationLabel,
2505
+ SenderId: senderHandle,
2506
+ Provider: "agentchat",
2507
+ Surface: "agentchat",
2508
+ MessageSid: event.messageId,
2509
+ MessageSidFull: event.messageId,
2510
+ Timestamp: event.createdAt,
2511
+ OriginatingChannel: "agentchat",
2512
+ OriginatingTo: `@${recipientHandle}`
2513
+ },
2514
+ dispatcherOptions: { deliver: deliver2 }
2515
+ });
2516
+ }
2477
2517
  } catch (err3) {
2478
2518
  deps.logger.error(
2479
2519
  {
@@ -2612,17 +2652,15 @@ var agentchatGatewayAdapter = {
2612
2652
  gatewayCfg: ctx.cfg,
2613
2653
  selfHandle: account.config.agentHandle
2614
2654
  });
2615
- ctx.abortSignal.addEventListener(
2616
- "abort",
2617
- () => {
2618
- void unregisterRuntime(ctx.accountId, Date.now() + 5e3).catch((err3) => {
2619
- ctx.log?.error?.(
2620
- `[agentchat:${ctx.accountId}] unregisterRuntime failed on abort: ${err3 instanceof Error ? err3.message : String(err3)}`
2621
- );
2622
- });
2623
- },
2624
- { once: true }
2625
- );
2655
+ await channelLifecycle.waitUntilAbort(ctx.abortSignal, async () => {
2656
+ try {
2657
+ await unregisterRuntime(ctx.accountId, Date.now() + 5e3);
2658
+ } catch (err3) {
2659
+ ctx.log?.error?.(
2660
+ `[agentchat:${ctx.accountId}] unregisterRuntime failed on abort: ${err3 instanceof Error ? err3.message : String(err3)}`
2661
+ );
2662
+ }
2663
+ });
2626
2664
  },
2627
2665
  async stopAccount(ctx) {
2628
2666
  await unregisterRuntime(ctx.accountId, Date.now() + 5e3);