@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.
@@ -3,8 +3,10 @@ import { setSetupChannelEnabled, WizardCancelledError } from 'openclaw/plugin-sd
3
3
  import { readApiKeyFromEnv } from './credentials/read-env.js';
4
4
  import { writeAgentsAnchor, removeAgentsAnchor } from './binding/agents-anchor.js';
5
5
  import { z } from 'zod';
6
+ import { waitUntilAbort } from 'openclaw/plugin-sdk/channel-lifecycle';
6
7
  import pino from 'pino';
7
8
  import { WebSocket } from 'ws';
9
+ import { dispatchInboundDirectDmWithRuntime } from 'openclaw/plugin-sdk/direct-dm';
8
10
  import { AgentChatClient } from '@agentchatme/agentchat';
9
11
  import { Type } from '@sinclair/typebox';
10
12
 
@@ -1845,7 +1847,7 @@ var CircuitBreaker = class {
1845
1847
  };
1846
1848
 
1847
1849
  // src/version.ts
1848
- var PACKAGE_VERSION = "0.6.13";
1850
+ var PACKAGE_VERSION = "0.6.15";
1849
1851
 
1850
1852
  // src/outbound.ts
1851
1853
  var DEFAULT_RETRY_POLICY = {
@@ -2374,8 +2376,6 @@ function unregisterRuntime(accountId, deadlineMs = Date.now() + 5e3) {
2374
2376
  function getRuntime(accountId) {
2375
2377
  return registry.get(accountId)?.runtime;
2376
2378
  }
2377
-
2378
- // src/binding/inbound-bridge.ts
2379
2379
  function createInboundBridge(deps) {
2380
2380
  return async function onInbound(event) {
2381
2381
  switch (event.kind) {
@@ -2412,8 +2412,8 @@ async function handleMessage(deps, event) {
2412
2412
  if (!body && !event.content.attachmentId && !event.content.data) {
2413
2413
  return;
2414
2414
  }
2415
- const dispatcher = deps.channelRuntime?.reply?.dispatchReplyWithBufferedBlockDispatcher;
2416
- if (typeof dispatcher !== "function") {
2415
+ const channelRuntime = deps.channelRuntime;
2416
+ if (!channelRuntime || typeof channelRuntime.reply?.dispatchReplyWithBufferedBlockDispatcher !== "function") {
2417
2417
  deps.logger.error(
2418
2418
  {
2419
2419
  event: "inbound_dispatch_unavailable",
@@ -2422,50 +2422,90 @@ async function handleMessage(deps, event) {
2422
2422
  conversationKind: event.conversationKind,
2423
2423
  sender: event.sender
2424
2424
  },
2425
- "channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher unavailable \u2014 message NOT dispatched to agent (will be redelivered on next sync)"
2425
+ "channelRuntime unavailable \u2014 message NOT dispatched to agent (will be redelivered on next sync)"
2426
2426
  );
2427
2427
  return;
2428
2428
  }
2429
2429
  const recipientHandle = selfHandle ?? "me";
2430
2430
  const conversationLabel = event.conversationKind === "group" ? `group ${event.conversationId}` : `dm with @${senderHandle}`;
2431
+ const sendReply = async (replyText) => {
2432
+ if (!replyText) return;
2433
+ const target = event.conversationKind === "group" ? { kind: "group", conversationId: event.conversationId } : { kind: "direct", to: senderHandle };
2434
+ await deps.runtime.sendMessage({
2435
+ ...target,
2436
+ type: "text",
2437
+ content: { text: replyText },
2438
+ metadata: { reply_to: event.messageId }
2439
+ });
2440
+ };
2441
+ const deliver2 = async (payload) => {
2442
+ const replyText = payload.text ?? extractText(payload.blocks);
2443
+ await sendReply(replyText);
2444
+ };
2431
2445
  try {
2432
- const sessionKey = event.conversationKind === "group" ? `agentchat:${deps.accountId}:group:${event.conversationId}` : `agentchat:${deps.accountId}:dm:${senderHandle}`;
2433
- await dispatcher({
2434
- cfg: deps.gatewayCfg,
2435
- ctx: {
2436
- Body: body,
2437
- BodyForAgent: body,
2438
- RawBody: body,
2439
- CommandBody: body,
2440
- From: `@${senderHandle}`,
2441
- To: `@${recipientHandle}`,
2442
- SessionKey: sessionKey,
2443
- AccountId: deps.accountId,
2444
- ChatType: event.conversationKind === "group" ? "group" : "direct",
2445
- ConversationLabel: conversationLabel,
2446
- SenderId: senderHandle,
2447
- Provider: "agentchat",
2448
- Surface: "agentchat",
2449
- MessageSid: event.messageId,
2450
- MessageSidFull: event.messageId,
2451
- Timestamp: event.createdAt,
2452
- OriginatingChannel: "agentchat",
2453
- OriginatingTo: `@${recipientHandle}`
2454
- },
2455
- dispatcherOptions: {
2456
- deliver: async (payload) => {
2457
- const replyText = payload.text ?? extractText(payload.blocks);
2458
- if (!replyText) return;
2459
- const target = event.conversationKind === "group" ? { kind: "group", conversationId: event.conversationId } : { kind: "direct", to: senderHandle };
2460
- await deps.runtime.sendMessage({
2461
- ...target,
2462
- type: "text",
2463
- content: { text: replyText },
2464
- metadata: { reply_to: event.messageId }
2465
- });
2446
+ if (event.conversationKind === "direct") {
2447
+ await dispatchInboundDirectDmWithRuntime({
2448
+ cfg: deps.gatewayCfg,
2449
+ runtime: { channel: channelRuntime },
2450
+ channel: "agentchat",
2451
+ channelLabel: "AgentChat",
2452
+ accountId: deps.accountId,
2453
+ peer: { kind: "direct", id: senderHandle },
2454
+ senderId: senderHandle,
2455
+ senderAddress: `@${senderHandle}`,
2456
+ recipientAddress: `@${recipientHandle}`,
2457
+ conversationLabel,
2458
+ rawBody: body,
2459
+ messageId: event.messageId,
2460
+ timestamp: typeof event.createdAt === "number" ? event.createdAt : Date.parse(event.createdAt),
2461
+ provider: "agentchat",
2462
+ surface: "agentchat",
2463
+ deliver: deliver2,
2464
+ onRecordError: (err3) => {
2465
+ deps.logger.error(
2466
+ { err: err3 instanceof Error ? err3.message : String(err3), messageId: event.messageId },
2467
+ "recordInboundSession failed"
2468
+ );
2469
+ },
2470
+ onDispatchError: (err3, info) => {
2471
+ deps.logger.error(
2472
+ {
2473
+ err: err3 instanceof Error ? err3.message : String(err3),
2474
+ messageId: event.messageId,
2475
+ kind: info.kind
2476
+ },
2477
+ "inbound dispatch failed"
2478
+ );
2466
2479
  }
2467
- }
2468
- });
2480
+ });
2481
+ } else {
2482
+ const dispatcher = channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher;
2483
+ const sessionKey = `agentchat:${deps.accountId}:group:${event.conversationId}`;
2484
+ await dispatcher({
2485
+ cfg: deps.gatewayCfg,
2486
+ ctx: {
2487
+ Body: body,
2488
+ BodyForAgent: body,
2489
+ RawBody: body,
2490
+ CommandBody: body,
2491
+ From: `@${senderHandle}`,
2492
+ To: `@${recipientHandle}`,
2493
+ SessionKey: sessionKey,
2494
+ AccountId: deps.accountId,
2495
+ ChatType: "group",
2496
+ ConversationLabel: conversationLabel,
2497
+ SenderId: senderHandle,
2498
+ Provider: "agentchat",
2499
+ Surface: "agentchat",
2500
+ MessageSid: event.messageId,
2501
+ MessageSidFull: event.messageId,
2502
+ Timestamp: event.createdAt,
2503
+ OriginatingChannel: "agentchat",
2504
+ OriginatingTo: `@${recipientHandle}`
2505
+ },
2506
+ dispatcherOptions: { deliver: deliver2 }
2507
+ });
2508
+ }
2469
2509
  } catch (err3) {
2470
2510
  deps.logger.error(
2471
2511
  {
@@ -2604,17 +2644,15 @@ var agentchatGatewayAdapter = {
2604
2644
  gatewayCfg: ctx.cfg,
2605
2645
  selfHandle: account.config.agentHandle
2606
2646
  });
2607
- ctx.abortSignal.addEventListener(
2608
- "abort",
2609
- () => {
2610
- void unregisterRuntime(ctx.accountId, Date.now() + 5e3).catch((err3) => {
2611
- ctx.log?.error?.(
2612
- `[agentchat:${ctx.accountId}] unregisterRuntime failed on abort: ${err3 instanceof Error ? err3.message : String(err3)}`
2613
- );
2614
- });
2615
- },
2616
- { once: true }
2617
- );
2647
+ await waitUntilAbort(ctx.abortSignal, async () => {
2648
+ try {
2649
+ await unregisterRuntime(ctx.accountId, Date.now() + 5e3);
2650
+ } catch (err3) {
2651
+ ctx.log?.error?.(
2652
+ `[agentchat:${ctx.accountId}] unregisterRuntime failed on abort: ${err3 instanceof Error ? err3.message : String(err3)}`
2653
+ );
2654
+ }
2655
+ });
2618
2656
  },
2619
2657
  async stopAccount(ctx) {
2620
2658
  await unregisterRuntime(ctx.accountId, Date.now() + 5e3);