
























11import * as crypto from "node:crypto";
22import type * as Lark from "@larksuiteoapi/node-sdk";
3-import type { ClawdbotConfig, RuntimeEnv, HistoryEntry } from "../runtime-api.js";
3+import type { ClawdbotConfig, PluginRuntime, RuntimeEnv, HistoryEntry } from "../runtime-api.js";
44import { raceWithTimeoutAndAbort } from "./async.js";
55import {
66handleFeishuMessage,
@@ -164,6 +164,7 @@ function normalizeFeishuChatType(value: unknown): FeishuChatType | undefined {
164164type RegisterEventHandlersContext = {
165165cfg: ClawdbotConfig;
166166accountId: string;
167+channelRuntime: PluginRuntime["channel"];
167168runtime?: RuntimeEnv;
168169chatHistories: Map<string, HistoryEntry[]>;
169170fireAndForget?: boolean;
@@ -266,7 +267,7 @@ function registerEventHandlers(
266267eventDispatcher: Lark.EventDispatcher,
267268context: RegisterEventHandlersContext,
268269): void {
269-const { cfg, accountId, runtime, chatHistories, fireAndForget } = context;
270+const { cfg, accountId, channelRuntime, runtime, chatHistories, fireAndForget } = context;
270271const log = runtime?.log ?? console.log;
271272const error = runtime?.error ?? console.error;
272273const runFeishuHandler = async (params: { task: () => Promise<void>; errorMessage: string }) => {
@@ -286,7 +287,7 @@ function registerEventHandlers(
286287eventDispatcher.register({
287288"im.message.receive_v1": createFeishuMessageReceiveHandler({
288289 cfg,
289-core: getFeishuRuntime(),
290+channelRuntime,
290291 accountId,
291292 runtime,
292293 chatHistories,
@@ -353,6 +354,7 @@ function registerEventHandlers(
353354botOpenId: myBotId,
354355botName: botNames.get(accountId),
355356 runtime,
357+ channelRuntime,
356358 chatHistories,
357359 accountId,
358360});
@@ -383,6 +385,7 @@ function registerEventHandlers(
383385botOpenId: myBotId,
384386botName: botNames.get(accountId),
385387 runtime,
388+ channelRuntime,
386389 chatHistories,
387390 accountId,
388391});
@@ -396,6 +399,7 @@ function registerEventHandlers(
396399 runtime,
397400 chatHistories,
398401 fireAndForget,
402+ channelRuntime,
399403}),
400404"card.action.trigger": async (data: unknown) => {
401405try {
@@ -409,6 +413,7 @@ function registerEventHandlers(
409413 event,
410414botOpenId: botOpenIds.get(accountId),
411415 runtime,
416+ channelRuntime,
412417 accountId,
413418});
414419if (fireAndForget) {
@@ -432,6 +437,7 @@ export type BotOpenIdSource =
432437export type MonitorSingleAccountParams = {
433438cfg: ClawdbotConfig;
434439account: ResolvedFeishuAccount;
440+channelRuntime?: PluginRuntime["channel"];
435441runtime?: RuntimeEnv;
436442abortSignal?: AbortSignal;
437443botOpenIdSource?: BotOpenIdSource;
@@ -473,10 +479,12 @@ export async function monitorSingleAccount(params: MonitorSingleAccountParams):
473479const eventDispatcher = createEventDispatcher(account);
474480const chatHistories = new Map<string, HistoryEntry[]>();
475481threadBindingManager = createFeishuThreadBindingManager({ accountId, cfg });
482+const channelRuntime = params.channelRuntime ?? getFeishuRuntime().channel;
476483477484registerEventHandlers(eventDispatcher, {
478485 cfg,
479486 accountId,
487+ channelRuntime,
480488 runtime,
481489 chatHistories,
482490fireAndForget: params.fireAndForget ?? true,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。