Skip to content

Commit 462d8e3

Browse files
committed
fix(cycles): narrow channel runtime surface
1 parent 26f633b commit 462d8e3

11 files changed

Lines changed: 77 additions & 33 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { GatewayCloseCodes, type GatewayPlugin } from "@buape/carbon/gateway";
1010
import { Routes } from "discord-api-types/v10";
1111
import { CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY } from "openclaw/plugin-sdk/approval-handler-adapter-runtime";
12+
import type { ChannelRuntimeSurface } from "openclaw/plugin-sdk/channel-contract";
1213
import { registerChannelRuntimeContext } from "openclaw/plugin-sdk/channel-runtime-context";
1314
import {
1415
listNativeCommandSpecsForConfig,
@@ -95,7 +96,7 @@ export type MonitorDiscordOpts = {
9596
accountId?: string;
9697
config?: OpenClawConfig;
9798
runtime?: RuntimeEnv;
98-
channelRuntime?: import("openclaw/plugin-sdk/channel-core").PluginRuntime["channel"];
99+
channelRuntime?: ChannelRuntimeSurface;
99100
abortSignal?: AbortSignal;
100101
mediaMaxMb?: number;
101102
historyLimit?: number;

‎extensions/matrix/src/matrix/monitor/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { format } from "node:util";
22
import { CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY } from "openclaw/plugin-sdk/approval-handler-adapter-runtime";
3+
import type { ChannelRuntimeSurface } from "openclaw/plugin-sdk/channel-contract";
34
import { waitUntilAbort } from "openclaw/plugin-sdk/channel-lifecycle";
45
import { registerChannelRuntimeContext } from "openclaw/plugin-sdk/channel-runtime-context";
56
import {
@@ -45,7 +46,7 @@ import { createMatrixMonitorTaskRunner } from "./task-runner.js";
4546

4647
export type MonitorMatrixOpts = {
4748
runtime?: RuntimeEnv;
48-
channelRuntime?: import("openclaw/plugin-sdk/channel-core").PluginRuntime["channel"];
49+
channelRuntime?: ChannelRuntimeSurface;
4950
abortSignal?: AbortSignal;
5051
mediaMaxMb?: number;
5152
initialSyncLimit?: number;

‎extensions/slack/src/monitor/types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PluginRuntime } from "openclaw/plugin-sdk/channel-core";
1+
import type { ChannelRuntimeSurface } from "openclaw/plugin-sdk/channel-contract";
22
import type { OpenClawConfig, SlackSlashCommandConfig } from "openclaw/plugin-sdk/config-runtime";
33
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
44
import type { SlackFile, SlackMessageEvent } from "../types.js";
@@ -10,7 +10,7 @@ export type MonitorSlackOpts = {
1010
mode?: "socket" | "http";
1111
config?: OpenClawConfig;
1212
runtime?: RuntimeEnv;
13-
channelRuntime?: PluginRuntime["channel"];
13+
channelRuntime?: ChannelRuntimeSurface;
1414
abortSignal?: AbortSignal;
1515
mediaMaxMb?: number;
1616
slashCommand?: SlackSlashCommandConfig;

‎extensions/telegram/src/monitor.types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PluginRuntime } from "openclaw/plugin-sdk/channel-core";
1+
import type { ChannelRuntimeSurface } from "openclaw/plugin-sdk/channel-contract";
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
33
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
44

@@ -7,7 +7,7 @@ export type MonitorTelegramOpts = {
77
accountId?: string;
88
config?: OpenClawConfig;
99
runtime?: RuntimeEnv;
10-
channelRuntime?: PluginRuntime["channel"];
10+
channelRuntime?: ChannelRuntimeSurface;
1111
abortSignal?: AbortSignal;
1212
useWebhook?: boolean;
1313
webhookPath?: string;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export type ChannelRuntimeContextKey = {
2+
channelId: string;
3+
accountId?: string | null;
4+
capability: string;
5+
};
6+
7+
export type ChannelRuntimeContextEvent = {
8+
type: "registered" | "unregistered";
9+
key: {
10+
channelId: string;
11+
accountId?: string;
12+
capability: string;
13+
};
14+
context?: unknown;
15+
};
16+
17+
export type ChannelRuntimeContextRegistry = {
18+
register: (
19+
params: ChannelRuntimeContextKey & {
20+
context: unknown;
21+
abortSignal?: AbortSignal;
22+
},
23+
) => { dispose: () => void };
24+
get: <T = unknown>(params: ChannelRuntimeContextKey) => T | undefined;
25+
watch: (params: {
26+
channelId?: string;
27+
accountId?: string | null;
28+
capability?: string;
29+
onEvent: (event: ChannelRuntimeContextEvent) => void;
30+
}) => () => void;
31+
};
32+
33+
/**
34+
* Minimal channel-runtime surface threaded through gateway/setup flows.
35+
*
36+
* Most callers only pass this object through or use `runtimeContexts`.
37+
* Keeping this leaf contract small avoids dragging the full plugin runtime
38+
* graph into generic channel adapter types.
39+
*/
40+
export type ChannelRuntimeSurface = {
41+
runtimeContexts: ChannelRuntimeContextRegistry;
42+
[key: string]: unknown;
43+
};

‎src/channels/plugins/types.adapters.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import type {
1010
PluginApprovalRequest,
1111
PluginApprovalResolved,
1212
} from "../../infra/plugin-approvals.js";
13-
import type { PluginRuntime } from "../../plugins/runtime/types.js";
1413
import type { RuntimeEnv } from "../../runtime.js";
1514
import type { ResolverContext, SecretDefaults } from "../../secrets/runtime-shared.js";
1615
import type { SecretTargetRegistryEntry } from "../../secrets/target-registry-types.js";
1716
import type { ChannelApprovalNativeAdapter } from "./approval-native.types.js";
17+
import type { ChannelRuntimeSurface } from "./channel-runtime-surface.types.js";
1818
import type { ConfigWriteTarget } from "./config-writes.js";
1919
export type {
2020
ChannelOutboundAdapter,
@@ -305,7 +305,7 @@ export type ChannelGatewayContext<ResolvedAccount = unknown> = {
305305
* @since Plugin SDK 2026.2.19
306306
* @see {@link https://docs.openclaw.ai/plugins/developing-plugins | Plugin SDK documentation}
307307
*/
308-
channelRuntime?: PluginRuntime["channel"];
308+
channelRuntime?: ChannelRuntimeSurface;
309309
};
310310

311311
export type ChannelLogoutResult = {

‎src/channels/plugins/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type {
4848
ChannelSetupAdapter,
4949
ChannelStatusAdapter,
5050
} from "./types.adapters.js";
51+
export type { ChannelRuntimeSurface } from "./channel-runtime-surface.types.js";
5152
export type {
5253
ChannelAccountSnapshot,
5354
ChannelAccountState,

‎src/gateway/server-channels.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ChannelRuntimeSurface } from "../channels/plugins/channel-runtime-surface.types.js";
12
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
23
import { type ChannelId, getChannelPlugin, listChannelPlugins } from "../channels/plugins/index.js";
34
import type { ChannelAccountSnapshot } from "../channels/plugins/types.public.js";
@@ -8,7 +9,6 @@ import { createTaskScopedChannelRuntime } from "../infra/channel-runtime-context
89
import { formatErrorMessage } from "../infra/errors.js";
910
import { resetDirectoryCache } from "../infra/outbound/target-resolver.js";
1011
import type { createSubsystemLogger } from "../logging/subsystem.js";
11-
import type { PluginRuntime } from "../plugins/runtime/types.js";
1212
import { resolveAccountEntry, resolveNormalizedAccountEntry } from "../routing/account-lookup.js";
1313
import {
1414
DEFAULT_ACCOUNT_ID,
@@ -125,7 +125,7 @@ type ChannelManagerOptions = {
125125
* @since Plugin SDK 2026.2.19
126126
* @see {@link ChannelGatewayContext.channelRuntime}
127127
*/
128-
channelRuntime?: PluginRuntime["channel"];
128+
channelRuntime?: ChannelRuntimeSurface;
129129
/**
130130
* Lazily resolves optional channel runtime helpers for external channel plugins.
131131
*
@@ -134,7 +134,7 @@ type ChannelManagerOptions = {
134134
* a channel account actually starts. The resolved value must be a real
135135
* `createPluginRuntime().channel` surface.
136136
*/
137-
resolveChannelRuntime?: () => PluginRuntime["channel"];
137+
resolveChannelRuntime?: () => ChannelRuntimeSurface;
138138
};
139139

140140
type StartChannelOptions = {
@@ -252,7 +252,7 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
252252
return next;
253253
};
254254

255-
const getChannelRuntime = (): PluginRuntime["channel"] | undefined => {
255+
const getChannelRuntime = (): ChannelRuntimeSurface | undefined => {
256256
return channelRuntime ?? resolveChannelRuntime?.();
257257
};
258258

@@ -299,7 +299,7 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
299299
let handedOffTask = false;
300300
const log = channelLogs[channelId];
301301
let scopedChannelRuntime: ReturnType<typeof createTaskScopedChannelRuntime> | null = null;
302-
let channelRuntimeForTask: PluginRuntime["channel"] | undefined;
302+
let channelRuntimeForTask: ChannelRuntimeSurface | undefined;
303303
let stopApprovalBootstrap: () => Promise<void> = async () => {};
304304
const stopTaskScopedApprovalRuntime = async () => {
305305
const scopedRuntime = scopedChannelRuntime;

‎src/infra/approval-handler-bootstrap.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { resolveChannelApprovalCapability } from "../channels/plugins/approvals.js";
2+
import type { ChannelRuntimeSurface } from "../channels/plugins/channel-runtime-surface.types.js";
23
import type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
34
import type { OpenClawConfig } from "../config/types.openclaw.js";
45
import { createSubsystemLogger } from "../logging/subsystem.js";
5-
import type { PluginRuntime } from "../plugins/runtime/types.js";
66
import {
77
CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY,
88
createChannelApprovalHandlerFromCapability,
@@ -20,7 +20,7 @@ export async function startChannelApprovalHandlerBootstrap(params: {
2020
plugin: Pick<ChannelPlugin, "id" | "meta" | "approvalCapability">;
2121
cfg: OpenClawConfig;
2222
accountId: string;
23-
channelRuntime?: PluginRuntime["channel"];
23+
channelRuntime?: ChannelRuntimeSurface;
2424
logger?: ReturnType<typeof createSubsystemLogger>;
2525
}): Promise<() => Promise<void>> {
2626
const capability = resolveChannelApprovalCapability(params.plugin);

‎src/infra/channel-runtime-context.ts‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import type { PluginRuntime } from "../plugins/runtime/types.js";
2-
3-
export type ChannelRuntimeContextKey = {
4-
channelId: string;
5-
accountId?: string | null;
6-
capability: string;
7-
};
1+
import type {
2+
ChannelRuntimeContextKey,
3+
ChannelRuntimeSurface,
4+
} from "../channels/plugins/channel-runtime-surface.types.js";
85

96
const NOOP_DISPOSE = () => {};
107

118
function resolveScopedRuntimeContextRegistry(params: {
12-
channelRuntime: PluginRuntime["channel"];
13-
}): PluginRuntime["channel"]["runtimeContexts"] {
9+
channelRuntime: ChannelRuntimeSurface;
10+
}): ChannelRuntimeSurface["runtimeContexts"] {
1411
const runtimeContexts = resolveRuntimeContextRegistry(params);
1512
if (
1613
runtimeContexts &&
@@ -26,14 +23,14 @@ function resolveScopedRuntimeContextRegistry(params: {
2623
}
2724

2825
function resolveRuntimeContextRegistry(params: {
29-
channelRuntime?: PluginRuntime["channel"];
30-
}): PluginRuntime["channel"]["runtimeContexts"] | null {
26+
channelRuntime?: ChannelRuntimeSurface;
27+
}): ChannelRuntimeSurface["runtimeContexts"] | null {
3128
return params.channelRuntime?.runtimeContexts ?? null;
3229
}
3330

3431
export function registerChannelRuntimeContext(
3532
params: ChannelRuntimeContextKey & {
36-
channelRuntime?: PluginRuntime["channel"];
33+
channelRuntime?: ChannelRuntimeSurface;
3734
context: unknown;
3835
abortSignal?: AbortSignal;
3936
},
@@ -53,7 +50,7 @@ export function registerChannelRuntimeContext(
5350

5451
export function getChannelRuntimeContext<T = unknown>(
5552
params: ChannelRuntimeContextKey & {
56-
channelRuntime?: PluginRuntime["channel"];
53+
channelRuntime?: ChannelRuntimeSurface;
5754
},
5855
): T | undefined {
5956
const runtimeContexts = resolveRuntimeContextRegistry(params);
@@ -69,8 +66,8 @@ export function getChannelRuntimeContext<T = unknown>(
6966

7067
export function watchChannelRuntimeContexts(
7168
params: ChannelRuntimeContextKey & {
72-
channelRuntime?: PluginRuntime["channel"];
73-
onEvent: Parameters<PluginRuntime["channel"]["runtimeContexts"]["watch"]>[0]["onEvent"];
69+
channelRuntime?: ChannelRuntimeSurface;
70+
onEvent: Parameters<ChannelRuntimeSurface["runtimeContexts"]["watch"]>[0]["onEvent"];
7471
},
7572
): (() => void) | null {
7673
const runtimeContexts = resolveRuntimeContextRegistry(params);
@@ -86,9 +83,9 @@ export function watchChannelRuntimeContexts(
8683
}
8784

8885
export function createTaskScopedChannelRuntime(params: {
89-
channelRuntime?: PluginRuntime["channel"];
86+
channelRuntime?: ChannelRuntimeSurface;
9087
}): {
91-
channelRuntime?: PluginRuntime["channel"];
88+
channelRuntime?: ChannelRuntimeSurface;
9289
dispose: () => void;
9390
} {
9491
const baseRuntime = params.channelRuntime;
@@ -116,7 +113,7 @@ export function createTaskScopedChannelRuntime(params: {
116113
};
117114
};
118115

119-
const scopedRuntime: PluginRuntime["channel"] = {
116+
const scopedRuntime: ChannelRuntimeSurface = {
120117
...baseRuntime,
121118
runtimeContexts: {
122119
...runtimeContexts,

0 commit comments

Comments
 (0)