@agentchatme/openclaw 0.6.13 → 0.6.14

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