@ozaiya/openclaw-channel 0.10.39 → 0.10.40

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.
@@ -33,6 +33,7 @@ import { fetchSocialMediaPost, searchSocialMedia, extractSocialMediaContent } fr
33
33
  import { requestConfirmation, parseActionCallback, resolveConfirmation } from "./actionConfirmation.js";
34
34
  import { createBotEmailTool, emailAddonOf, newMailNotice, watchMailboxes } from "./botEmail.js";
35
35
  import { createBotMcpTool, mcpAddonOf } from "./botMcp.js";
36
+ import { lastChatFromSessionStore } from "./lastChat.js";
36
37
  const DEFAULT_API_BASE_URL = "https://api.ozaiya.com";
37
38
  const DEFAULT_WEBHOOK_PATH = "/ozaiya/webhook";
38
39
  const DEFAULT_ACCOUNT_ID = "default";
@@ -1481,6 +1482,25 @@ async function buildNativeDocumentContext(params) {
1481
1482
  * Non-read-only tools are wrapped to report progress steps to the active
1482
1483
  * dispatch's task progress card (when one exists for this account).
1483
1484
  */
1485
+ /**
1486
+ * The chat a tool works for: the message being answered, else the last one this bot received, else —
1487
+ * a turn started from outside (gateway `agent` call, host watcher) or the first after a restart, when
1488
+ * no inbound message has set the in-memory origin — the bot's newest chat in the session store.
1489
+ */
1490
+ async function currentChatGroupId(account, cfg) {
1491
+ const live = activeDispatches.get(account.accountId)?.groupId ?? accountToOriginGroupId.get(account.accountId);
1492
+ if (live)
1493
+ return live;
1494
+ try {
1495
+ const ch = getOzaiyaRuntime().channel;
1496
+ const route = ch.routing.resolveAgentRoute({ cfg, channel: "ozaiya", accountId: account.accountId, peer: { kind: "group", id: "" } });
1497
+ const storePath = String(ch.session.resolveStorePath(undefined, { agentId: route.agentId }));
1498
+ return lastChatFromSessionStore(await fs.readFile(storePath, "utf8"), account.accountId);
1499
+ }
1500
+ catch {
1501
+ return undefined;
1502
+ }
1503
+ }
1484
1504
  function buildChannelTools(account, cfg) {
1485
1505
  const resolveForGroup = (groupId) => resolveAccountForGroup(cfg, groupId) ?? account;
1486
1506
  const tools = [
@@ -1606,7 +1626,7 @@ function buildChannelTools(account, cfg) {
1606
1626
  execute: async (_toolCallId, rawArgs) => {
1607
1627
  const args = (rawArgs ?? {});
1608
1628
  const dispatch = activeDispatches.get(account.accountId);
1609
- const groupId = dispatch?.groupId ?? accountToOriginGroupId.get(account.accountId);
1629
+ const groupId = await currentChatGroupId(account, cfg);
1610
1630
  if (!groupId) {
1611
1631
  return { content: [{ type: "text", text: "No active task to attach a deliverable to." }] };
1612
1632
  }
@@ -1679,8 +1699,7 @@ function buildChannelTools(account, cfg) {
1679
1699
  },
1680
1700
  execute: async (_toolCallId, rawArgs) => {
1681
1701
  const args = (rawArgs ?? {});
1682
- const dispatch = activeDispatches.get(account.accountId);
1683
- const groupId = dispatch?.groupId ?? accountToOriginGroupId.get(account.accountId);
1702
+ const groupId = await currentChatGroupId(account, cfg);
1684
1703
  if (!groupId) {
1685
1704
  return { content: [{ type: "text", text: "No active chat to send the login request to." }] };
1686
1705
  }