Files
openclaw/extensions/discord/subagent-hooks-api.ts
Peter Steinberger 3fc0df953c refactor(agents): bind subagent threads in core (#88416)
Move subagent thread binding ownership into core so session-mode spawns prepare channel bindings before launching the child agent. Deprecate the legacy subagent_spawning SDK hook in code, compatibility metadata, diagnostics, and plugin docs; plugin authors should observe subagent_spawned instead.

Verification:
- node scripts/run-vitest.mjs src/agents/sessions-spawn-hooks.test.ts src/agents/subagent-spawn.thread-binding.test.ts src/agents/subagent-spawn.workspace.test.ts src/agents/subagent-spawn.mode-session-diagnostics.test.ts
- node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
- git diff --check
- .agents/skills/autoreview/scripts/autoreview --mode local
- CI run 26693808952 green, including checks-node-agentic-agents-core and checks-node-agentic-plugin-sdk
2026-05-30 21:19:09 +01:00

24 lines
1017 B
TypeScript

import type { OpenClawPluginApi } from "openclaw/plugin-sdk/channel-entry-contract";
type DiscordSubagentHooksModule = typeof import("./src/subagent-hooks.js");
let discordSubagentHooksPromise: Promise<DiscordSubagentHooksModule> | null = null;
function loadDiscordSubagentHooksModule() {
discordSubagentHooksPromise ??= import("./src/subagent-hooks.js");
return discordSubagentHooksPromise;
}
// Subagent hooks live behind a dedicated barrel so the bundled entry can
// register one stable hook wiring path while keeping the handler module lazy.
export function registerDiscordSubagentHooks(api: OpenClawPluginApi): void {
api.on("subagent_ended", async (event) => {
const { handleDiscordSubagentEnded } = await loadDiscordSubagentHooksModule();
handleDiscordSubagentEnded(event);
});
api.on("subagent_delivery_target", async (event) => {
const { handleDiscordSubagentDeliveryTarget } = await loadDiscordSubagentHooksModule();
return handleDiscordSubagentDeliveryTarget(event);
});
}