Skip to content

Commit 543c14a

Browse files
committed
fix(cycles): split runtime delivery and registry seams
1 parent 41ab0f7 commit 543c14a

15 files changed

Lines changed: 253 additions & 184 deletions

src/channels/registry.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { getActivePluginChannelRegistry, getActivePluginRegistry } from "../plugins/runtime.js";
1+
import {
2+
getActivePluginChannelRegistryFromState,
3+
getPluginRegistryState,
4+
} from "../plugins/runtime-state.js";
25
import {
36
normalizeOptionalLowercaseString,
47
normalizeOptionalString,
@@ -23,11 +26,11 @@ type RegisteredChannelPluginEntry = {
2326
};
2427

2528
function listRegisteredChannelPluginEntries(): RegisteredChannelPluginEntry[] {
26-
const channelRegistry = getActivePluginChannelRegistry();
29+
const channelRegistry = getActivePluginChannelRegistryFromState();
2730
if (channelRegistry && channelRegistry.channels && channelRegistry.channels.length > 0) {
2831
return channelRegistry.channels;
2932
}
30-
return getActivePluginRegistry()?.channels ?? [];
33+
return getPluginRegistryState()?.activeRegistry?.channels ?? [];
3134
}
3235

3336
function findRegisteredChannelPluginEntry(

src/config/group-policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
normalizeLowercaseStringOrEmpty,
66
normalizeOptionalString,
77
} from "../shared/string-coerce.js";
8-
import type { OpenClawConfig } from "./config.js";
8+
import type { OpenClawConfig } from "./types.openclaw.js";
99
import {
1010
parseToolsBySenderTypedKey,
1111
type GroupToolPolicyBySenderConfig,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { MsgContext } from "../../auto-reply/templating.js";
2+
import type { DeliveryContext } from "../../utils/delivery-context.shared.js";
3+
import type { SessionEntry, GroupKeyResolution } from "./types.js";
4+
5+
export type ReadSessionUpdatedAt = (params: {
6+
storePath: string;
7+
sessionKey: string;
8+
}) => number | undefined;
9+
10+
export type RecordSessionMetaFromInbound = (params: {
11+
storePath: string;
12+
sessionKey: string;
13+
ctx: MsgContext;
14+
groupResolution?: GroupKeyResolution | null;
15+
createIfMissing?: boolean;
16+
}) => Promise<SessionEntry | null>;
17+
18+
export type UpdateLastRoute = (params: {
19+
storePath: string;
20+
sessionKey: string;
21+
channel?: SessionEntry["lastChannel"];
22+
to?: string;
23+
accountId?: string;
24+
threadId?: string | number;
25+
deliveryContext?: DeliveryContext;
26+
ctx?: MsgContext;
27+
groupResolution?: GroupKeyResolution | null;
28+
}) => Promise<SessionEntry>;

src/plugins/runtime-state.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
import type { PluginRegistry } from "./registry.js";
2-
31
export const PLUGIN_REGISTRY_STATE = Symbol.for("openclaw.pluginRegistryState");
42

3+
export type RuntimeTrackedPluginRecord = {
4+
id: string;
5+
status?: string;
6+
format?: string;
7+
};
8+
9+
export type RuntimeTrackedChannelEntry = {
10+
plugin: {
11+
id?: string | null;
12+
meta?: {
13+
aliases?: string[];
14+
markdownCapable?: boolean;
15+
} | null;
16+
};
17+
};
18+
19+
export type RuntimeTrackedPluginRegistry = {
20+
plugins: RuntimeTrackedPluginRecord[];
21+
httpRoutes?: unknown[];
22+
channels?: RuntimeTrackedChannelEntry[];
23+
};
24+
525
export type RegistrySurfaceState = {
6-
registry: PluginRegistry | null;
26+
registry: RuntimeTrackedPluginRegistry | null;
727
pinned: boolean;
828
version: number;
929
};
1030

1131
export type RegistryState = {
12-
activeRegistry: PluginRegistry | null;
32+
activeRegistry: RuntimeTrackedPluginRegistry | null;
1333
activeVersion: number;
1434
httpRoute: RegistrySurfaceState;
1535
channel: RegistrySurfaceState;
@@ -27,7 +47,7 @@ export function getPluginRegistryState(): RegistryState | undefined {
2747
return (globalThis as GlobalRegistryState)[PLUGIN_REGISTRY_STATE];
2848
}
2949

30-
export function getActivePluginChannelRegistryFromState(): PluginRegistry | null {
50+
export function getActivePluginChannelRegistryFromState(): RuntimeTrackedPluginRegistry | null {
3151
const state = getPluginRegistryState();
3252
return state?.channel.registry ?? state?.activeRegistry ?? null;
3353
}

src/plugins/runtime.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
type RegistrySurfaceState,
77
} from "./runtime-state.js";
88

9+
function asPluginRegistry(registry: RegistryState["activeRegistry"]): PluginRegistry | null {
10+
return registry as PluginRegistry | null;
11+
}
12+
913
const state: RegistryState = (() => {
1014
const globalState = globalThis as typeof globalThis & {
1115
[PLUGIN_REGISTRY_STATE]?: RegistryState;
@@ -85,7 +89,7 @@ export function setActivePluginRegistry(
8589
}
8690

8791
export function getActivePluginRegistry(): PluginRegistry | null {
88-
return state.activeRegistry;
92+
return asPluginRegistry(state.activeRegistry);
8993
}
9094

9195
export function getActivePluginRegistryWorkspaceDir(): string | undefined {
@@ -114,7 +118,7 @@ export function releasePinnedPluginHttpRouteRegistry(registry?: PluginRegistry)
114118
}
115119

116120
export function getActivePluginHttpRouteRegistry(): PluginRegistry | null {
117-
return state.httpRoute.registry ?? state.activeRegistry;
121+
return asPluginRegistry(state.httpRoute.registry ?? state.activeRegistry);
118122
}
119123

120124
export function getActivePluginHttpRouteRegistryVersion(): number {
@@ -163,7 +167,7 @@ export function releasePinnedPluginChannelRegistry(registry?: PluginRegistry) {
163167
* When pinned, this returns the startup registry regardless of subsequent
164168
* `setActivePluginRegistry` calls. */
165169
export function getActivePluginChannelRegistry(): PluginRegistry | null {
166-
return state.channel.registry ?? state.activeRegistry;
170+
return asPluginRegistry(state.channel.registry ?? state.activeRegistry);
167171
}
168172

169173
export function getActivePluginChannelRegistryVersion(): number {

src/plugins/runtime/runtime-taskflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
TaskRegistrySummary,
2929
TaskRuntime,
3030
} from "../../tasks/task-registry.types.js";
31-
import { normalizeDeliveryContext } from "../../utils/delivery-context.js";
31+
import { normalizeDeliveryContext } from "../../utils/delivery-context.shared.js";
3232
import type { OpenClawPluginToolContext } from "../tool-types.js";
3333

3434
export type ManagedTaskFlowRecord = TaskFlowRecord & {

src/plugins/runtime/runtime-tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
listTasksForRelatedSessionKeyForOwner,
2121
resolveTaskForLookupTokenForOwner,
2222
} from "../../tasks/task-owner-access.js";
23-
import { normalizeDeliveryContext } from "../../utils/delivery-context.js";
23+
import { normalizeDeliveryContext } from "../../utils/delivery-context.shared.js";
2424
import type { OpenClawPluginToolContext } from "../tool-types.js";
2525
import type { PluginRuntimeTaskFlow } from "./runtime-taskflow.js";
2626
import type {

src/plugins/runtime/types-channel.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ type ReadChannelAllowFromStore =
99
typeof import("../../pairing/pairing-store.js").readChannelAllowFromStore;
1010
type UpsertChannelPairingRequest =
1111
typeof import("../../pairing/pairing-store.js").upsertChannelPairingRequest;
12+
type ReadSessionUpdatedAt = import("../../config/sessions/runtime-types.js").ReadSessionUpdatedAt;
13+
type RecordSessionMetaFromInbound =
14+
import("../../config/sessions/runtime-types.js").RecordSessionMetaFromInbound;
15+
type UpdateLastRoute = import("../../config/sessions/runtime-types.js").UpdateLastRoute;
1216

1317
type ReadChannelAllowFromStoreForAccount = (params: {
1418
channel: Parameters<ReadChannelAllowFromStore>[0];
@@ -105,11 +109,11 @@ export type PluginRuntimeChannel = {
105109
get: typeof import("../../infra/channel-activity.js").getChannelActivity;
106110
};
107111
session: {
108-
resolveStorePath: typeof import("../../config/sessions.js").resolveStorePath;
109-
readSessionUpdatedAt: typeof import("../../config/sessions.js").readSessionUpdatedAt;
110-
recordSessionMetaFromInbound: typeof import("../../config/sessions.js").recordSessionMetaFromInbound;
112+
resolveStorePath: typeof import("../../config/sessions/paths.js").resolveStorePath;
113+
readSessionUpdatedAt: ReadSessionUpdatedAt;
114+
recordSessionMetaFromInbound: RecordSessionMetaFromInbound;
111115
recordInboundSession: typeof import("../../channels/session.js").recordInboundSession;
112-
updateLastRoute: typeof import("../../config/sessions.js").updateLastRoute;
116+
updateLastRoute: UpdateLastRoute;
113117
};
114118
mentions: {
115119
buildMentionRegexes: typeof import("../../auto-reply/reply/mentions.js").buildMentionRegexes;

src/plugins/runtime/types-core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export type PluginRuntimeCore = {
5454
resolveAgentTimeoutMs: typeof import("../../agents/timeout.js").resolveAgentTimeoutMs;
5555
ensureAgentWorkspace: typeof import("../../agents/workspace.js").ensureAgentWorkspace;
5656
session: {
57-
resolveStorePath: typeof import("../../config/sessions.js").resolveStorePath;
58-
loadSessionStore: typeof import("../../config/sessions.js").loadSessionStore;
59-
saveSessionStore: typeof import("../../config/sessions.js").saveSessionStore;
60-
resolveSessionFilePath: typeof import("../../config/sessions.js").resolveSessionFilePath;
57+
resolveStorePath: typeof import("../../config/sessions/paths.js").resolveStorePath;
58+
loadSessionStore: typeof import("../../config/sessions/store-load.js").loadSessionStore;
59+
saveSessionStore: typeof import("../../config/sessions/store.js").saveSessionStore;
60+
resolveSessionFilePath: typeof import("../../config/sessions/paths.js").resolveSessionFilePath;
6161
};
6262
};
6363
system: {

src/plugins/tool-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ToolFsPolicy } from "../agents/tool-fs-policy.js";
22
import type { AnyAgentTool } from "../agents/tools/common.js";
33
import type { OpenClawConfig } from "../config/types.openclaw.js";
44
import type { HookEntry } from "../hooks/types.js";
5-
import type { DeliveryContext } from "../utils/delivery-context.js";
5+
import type { DeliveryContext } from "../utils/delivery-context.shared.js";
66

77
/** Trusted execution context passed to plugin-owned agent tool factories. */
88
export type OpenClawPluginToolContext = {

0 commit comments

Comments
 (0)