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 {
66 handleFeishuMessage ,
@@ -164,6 +164,7 @@ function normalizeFeishuChatType(value: unknown): FeishuChatType | undefined {
164164type RegisterEventHandlersContext = {
165165 cfg : ClawdbotConfig ;
166166 accountId : string ;
167+ channelRuntime : PluginRuntime [ "channel" ] ;
167168 runtime ?: RuntimeEnv ;
168169 chatHistories : Map < string , HistoryEntry [ ] > ;
169170 fireAndForget ?: boolean ;
@@ -266,7 +267,7 @@ function registerEventHandlers(
266267 eventDispatcher : Lark . EventDispatcher ,
267268 context : RegisterEventHandlersContext ,
268269) : void {
269- const { cfg, accountId, runtime, chatHistories, fireAndForget } = context ;
270+ const { cfg, accountId, channelRuntime , runtime, chatHistories, fireAndForget } = context ;
270271 const log = runtime ?. log ?? console . log ;
271272 const error = runtime ?. error ?? console . error ;
272273 const runFeishuHandler = async ( params : { task : ( ) => Promise < void > ; errorMessage : string } ) => {
@@ -286,7 +287,7 @@ function registerEventHandlers(
286287 eventDispatcher . 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(
353354 botOpenId : myBotId ,
354355 botName : botNames . get ( accountId ) ,
355356 runtime,
357+ channelRuntime,
356358 chatHistories,
357359 accountId,
358360 } ) ;
@@ -383,6 +385,7 @@ function registerEventHandlers(
383385 botOpenId : myBotId ,
384386 botName : 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 ) => {
401405 try {
@@ -409,6 +413,7 @@ function registerEventHandlers(
409413 event,
410414 botOpenId : botOpenIds . get ( accountId ) ,
411415 runtime,
416+ channelRuntime,
412417 accountId,
413418 } ) ;
414419 if ( fireAndForget ) {
@@ -432,6 +437,7 @@ export type BotOpenIdSource =
432437export type MonitorSingleAccountParams = {
433438 cfg : ClawdbotConfig ;
434439 account : ResolvedFeishuAccount ;
440+ channelRuntime ?: PluginRuntime [ "channel" ] ;
435441 runtime ?: RuntimeEnv ;
436442 abortSignal ?: AbortSignal ;
437443 botOpenIdSource ?: BotOpenIdSource ;
@@ -473,10 +479,12 @@ export async function monitorSingleAccount(params: MonitorSingleAccountParams):
473479 const eventDispatcher = createEventDispatcher ( account ) ;
474480 const chatHistories = new Map < string , HistoryEntry [ ] > ( ) ;
475481 threadBindingManager = createFeishuThreadBindingManager ( { accountId, cfg } ) ;
482+ const channelRuntime = params . channelRuntime ?? getFeishuRuntime ( ) . channel ;
476483
477484 registerEventHandlers ( eventDispatcher , {
478485 cfg,
479486 accountId,
487+ channelRuntime,
480488 runtime,
481489 chatHistories,
482490 fireAndForget : params . fireAndForget ?? true ,
0 commit comments