Skip to content

Commit d05e4a4

Browse files
committed
fix(feishu): use full gateway channel runtime
1 parent 0b0edcd commit d05e4a4

15 files changed

Lines changed: 85 additions & 107 deletions

‎extensions/discord/src/monitor/provider.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EventEmitter } from "node:events";
22
import type { ChannelRuntimeSurface } from "openclaw/plugin-sdk/channel-contract";
3+
import { createPluginRuntimeMock } from "openclaw/plugin-sdk/channel-test-helpers";
34
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
45
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
56
import { RateLimitError } from "../internal/discord.js";
@@ -65,6 +66,7 @@ function createTestChannelRuntime(): ChannelRuntimeSurface {
6566
},
6667
};
6768
return {
69+
...createPluginRuntimeMock().channel,
6870
runtimeContexts,
6971
};
7072
}

‎extensions/feishu/src/bot.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ describe("createFeishuMessageReceiveHandler media dedupe", () => {
37043704
});
37053705
const handler = createFeishuMessageReceiveHandler({
37063706
cfg: { channels: { feishu: { dmPolicy: "open" } } } as ClawdbotConfig,
3707-
core,
3707+
channelRuntime: core.channel,
37083708
accountId: "receive-media-dedupe",
37093709
chatHistories: new Map(),
37103710
handleMessage,

‎extensions/feishu/src/bot.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ export async function handleFeishuMessage(params: {
440440
botOpenId?: string;
441441
botName?: string;
442442
runtime?: RuntimeEnv;
443+
channelRuntime?: ReturnType<typeof getFeishuRuntime>["channel"];
443444
chatHistories?: Map<string, HistoryEntry[]>;
444445
accountId?: string;
445446
processingClaimHeld?: boolean;
@@ -450,6 +451,7 @@ export async function handleFeishuMessage(params: {
450451
botOpenId,
451452
botName,
452453
runtime,
454+
channelRuntime,
453455
chatHistories,
454456
accountId,
455457
processingClaimHeld = false,
@@ -709,7 +711,9 @@ export async function handleFeishuMessage(params: {
709711
}
710712

711713
try {
712-
const core = getFeishuRuntime();
714+
const core = {
715+
channel: channelRuntime ?? getFeishuRuntime().channel,
716+
} as ReturnType<typeof getFeishuRuntime>;
713717
const pairing = createChannelPairingController({
714718
core,
715719
channel: "feishu",

‎extensions/feishu/src/card-action.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
isFutureDateTimestampMs,
44
resolveExpiresAtMsFromDurationMs,
55
} from "openclaw/plugin-sdk/number-runtime";
6-
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
6+
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
77
import { resolveFeishuRuntimeAccount } from "./accounts.js";
88
import { handleFeishuMessage, type FeishuMessageEvent } from "./bot.js";
99
import { decodeFeishuCardAction, buildFeishuCardActionTextFallback } from "./card-interaction.js";
@@ -170,6 +170,7 @@ async function dispatchSyntheticCommand(params: {
170170
account: ReturnType<typeof resolveFeishuRuntimeAccount>;
171171
botOpenId?: string;
172172
runtime?: RuntimeEnv;
173+
channelRuntime?: PluginRuntime["channel"];
173174
accountId?: string;
174175
chatType?: "p2p" | "group";
175176
}): Promise<void> {
@@ -184,6 +185,7 @@ async function dispatchSyntheticCommand(params: {
184185
event: buildSyntheticMessageEvent(params.event, params.command, resolvedChatType),
185186
botOpenId: params.botOpenId,
186187
runtime: params.runtime,
188+
channelRuntime: params.channelRuntime,
187189
accountId: params.accountId,
188190
});
189191
}
@@ -342,6 +344,7 @@ export async function handleFeishuCardAction(params: {
342344
event: FeishuCardActionEvent;
343345
botOpenId?: string;
344346
runtime?: RuntimeEnv;
347+
channelRuntime?: PluginRuntime["channel"];
345348
accountId?: string;
346349
}): Promise<void> {
347350
const { cfg, event, runtime, accountId } = params;
@@ -465,6 +468,7 @@ export async function handleFeishuCardAction(params: {
465468
account,
466469
botOpenId: params.botOpenId,
467470
runtime,
471+
channelRuntime: params.channelRuntime,
468472
accountId,
469473
chatType: envelope.c?.t,
470474
});
@@ -495,6 +499,7 @@ export async function handleFeishuCardAction(params: {
495499
account,
496500
botOpenId: params.botOpenId,
497501
runtime,
502+
channelRuntime: params.channelRuntime,
498503
accountId,
499504
});
500505
completeFeishuCardActionToken({ token: event.token, accountId: account.accountId });

‎extensions/feishu/src/channel.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
3131
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
3232
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
3333
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
34+
import type { PluginRuntime } from "../runtime-api.js";
3435
import {
3536
inspectFeishuCredentials,
3637
listEnabledFeishuAccounts,
@@ -1319,6 +1320,9 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
13191320
return monitorFeishuProvider({
13201321
config: ctx.cfg,
13211322
runtime: ctx.runtime,
1323+
// Gateway provides the full channel runtime here; the public SDK type
1324+
// stays context-only for external compatibility.
1325+
channelRuntime: ctx.channelRuntime as PluginRuntime["channel"] | undefined,
13221326
abortSignal: ctx.abortSignal,
13231327
accountId: ctx.accountId,
13241328
});

‎extensions/feishu/src/monitor.account.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as crypto from "node:crypto";
22
import 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";
44
import { raceWithTimeoutAndAbort } from "./async.js";
55
import {
66
handleFeishuMessage,
@@ -164,6 +164,7 @@ function normalizeFeishuChatType(value: unknown): FeishuChatType | undefined {
164164
type 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 =
432437
export 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,

‎extensions/feishu/src/monitor.bot-menu-handler.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isRecord, readStringValue as readString } from "openclaw/plugin-sdk/string-coerce-runtime";
2-
import type { ClawdbotConfig, HistoryEntry, RuntimeEnv } from "../runtime-api.js";
2+
import type { ClawdbotConfig, HistoryEntry, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
33
import { handleFeishuMessage, type FeishuMessageEvent } from "./bot.js";
44
import { maybeHandleFeishuQuickActionMenu } from "./card-ux-launcher.js";
55
import {
@@ -54,6 +54,7 @@ export function createFeishuBotMenuHandler(params: {
5454
cfg: ClawdbotConfig;
5555
accountId: string;
5656
runtime?: RuntimeEnv;
57+
channelRuntime?: PluginRuntime["channel"];
5758
chatHistories: Map<string, HistoryEntry[]>;
5859
fireAndForget?: boolean;
5960
getBotOpenId?: (accountId: string) => string | undefined;
@@ -117,6 +118,7 @@ export function createFeishuBotMenuHandler(params: {
117118
botOpenId: getBotOpenId(accountId),
118119
botName: getBotName(accountId),
119120
runtime,
121+
channelRuntime: params.channelRuntime,
120122
chatHistories,
121123
accountId,
122124
processingClaimHeld: true,

‎extensions/feishu/src/monitor.message-handler.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { FeishuChatType } from "./types.js";
1212

1313
type FeishuMessageReceiveHandlerContext = {
1414
cfg: ClawdbotConfig;
15-
core: PluginRuntime;
15+
channelRuntime: PluginRuntime["channel"];
1616
accountId: string;
1717
runtime?: RuntimeEnv;
1818
chatHistories: Map<string, HistoryEntry[]>;
@@ -23,6 +23,7 @@ type FeishuMessageReceiveHandlerContext = {
2323
botOpenId?: string;
2424
botName?: string;
2525
runtime?: RuntimeEnv;
26+
channelRuntime?: PluginRuntime["channel"];
2627
chatHistories?: Map<string, HistoryEntry[]>;
2728
accountId?: string;
2829
processingClaimHeld?: boolean;
@@ -154,7 +155,7 @@ function resolveFeishuDebounceMentions(params: {
154155

155156
export function createFeishuMessageReceiveHandler({
156157
cfg,
157-
core,
158+
channelRuntime,
158159
accountId,
159160
runtime,
160161
chatHistories,
@@ -168,7 +169,7 @@ export function createFeishuMessageReceiveHandler({
168169
resolveSequentialKey = ({ accountId, event }) =>
169170
`feishu:${accountId}:${event.message.chat_id?.trim() || "unknown"}`,
170171
}: FeishuMessageReceiveHandlerContext): (data: unknown) => Promise<void> {
171-
const inboundDebounceMs = core.channel.debounce.resolveInboundDebounceMs({
172+
const inboundDebounceMs = channelRuntime.debounce.resolveInboundDebounceMs({
172173
cfg,
173174
channel: "feishu",
174175
});
@@ -196,6 +197,7 @@ export function createFeishuMessageReceiveHandler({
196197
botOpenId: getBotOpenId(accountId),
197198
botName: getBotName(accountId),
198199
runtime,
200+
channelRuntime,
199201
chatHistories,
200202
accountId,
201203
processingClaimHeld: true,
@@ -238,7 +240,7 @@ export function createFeishuMessageReceiveHandler({
238240
}
239241
};
240242

241-
const inboundDebouncer = core.channel.debounce.createInboundDebouncer<FeishuMessageEvent>({
243+
const inboundDebouncer = channelRuntime.debounce.createInboundDebouncer<FeishuMessageEvent>({
242244
debounceMs: inboundDebounceMs,
243245
buildKey: (event) => {
244246
const chatId = event.message.chat_id?.trim();
@@ -255,7 +257,7 @@ export function createFeishuMessageReceiveHandler({
255257
return false;
256258
}
257259
const text = resolveDebounceText(event);
258-
return Boolean(text) && !core.channel.commands.isControlCommandMessage(text, cfg);
260+
return Boolean(text) && !channelRuntime.commands.isControlCommandMessage(text, cfg);
259261
},
260262
onFlush: async (entries) => {
261263
const last = entries.at(-1);

‎extensions/feishu/src/monitor.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
1+
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
22
import { listEnabledFeishuAccounts, resolveFeishuRuntimeAccount } from "./accounts.js";
33
import { fetchBotIdentityForMonitor } from "./monitor.startup.js";
44
import {
@@ -11,6 +11,7 @@ import {
1111
export type MonitorFeishuOpts = {
1212
config?: ClawdbotConfig;
1313
runtime?: RuntimeEnv;
14+
channelRuntime?: PluginRuntime["channel"];
1415
abortSignal?: AbortSignal;
1516
accountId?: string;
1617
};
@@ -48,6 +49,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
4849
return monitorSingleAccount({
4950
cfg,
5051
account,
52+
channelRuntime: opts.channelRuntime,
5153
runtime: opts.runtime,
5254
abortSignal: opts.abortSignal,
5355
});
@@ -85,6 +87,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
8587
monitorSingleAccount({
8688
cfg,
8789
account,
90+
channelRuntime: opts.channelRuntime,
8891
runtime: opts.runtime,
8992
abortSignal: opts.abortSignal,
9093
botOpenIdSource: { kind: "prefetched", botOpenId, botName },

‎src/channels/plugins/channel-runtime-surface.types.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ export type ChannelRuntimeContextRegistry = {
3232
};
3333

3434
/**
35-
* Minimal channel-runtime surface threaded through gateway/setup flows.
35+
* Minimal channel-runtime surface exported through the public plugin SDK.
3636
*
37-
* Most callers only pass this object through or use `runtimeContexts`.
38-
* Keeping this leaf contract small avoids dragging the full plugin runtime
39-
* graph into generic channel adapter types.
37+
* Gateway startup supplies the full plugin channel runtime, but external callers
38+
* may still type context-only helpers against this compatibility surface.
4039
*/
4140
export type ChannelRuntimeSurface = {
4241
runtimeContexts: ChannelRuntimeContextRegistry;

0 commit comments

Comments
 (0)