refactor(channels): centralize runtime binding routes

This commit is contained in:
Peter Steinberger
2026-04-22 23:16:44 +01:00
parent 85d2a9ec1f
commit f88da75ed9
13 changed files with 351 additions and 148 deletions

View File

@@ -1,14 +1,9 @@
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import {
getSessionBindingService,
isPluginOwnedSessionBindingRecord,
resolveConfiguredBindingRoute,
resolveRuntimeConversationBindingRoute,
} from "openclaw/plugin-sdk/conversation-runtime";
import {
deriveLastRoutePolicy,
resolveAgentIdFromSessionKey,
resolveAgentRoute,
} from "openclaw/plugin-sdk/routing";
import { resolveAgentRoute } from "openclaw/plugin-sdk/routing";
import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
import { resolveIMessageInboundConversationId } from "./conversation-id.js";
@@ -49,31 +44,21 @@ export function resolveIMessageConversationRoute(params: {
},
}).route;
const runtimeBinding = getSessionBindingService().resolveByConversation({
channel: "imessage",
accountId: params.accountId,
conversationId,
const runtimeRoute = resolveRuntimeConversationBindingRoute({
route,
conversation: {
channel: "imessage",
accountId: params.accountId,
conversationId,
},
});
const boundSessionKey = runtimeBinding?.targetSessionKey?.trim();
if (!runtimeBinding || !boundSessionKey) {
return route;
}
getSessionBindingService().touch(runtimeBinding.bindingId);
if (isPluginOwnedSessionBindingRecord(runtimeBinding)) {
route = runtimeRoute.route;
if (runtimeRoute.bindingRecord && !runtimeRoute.boundSessionKey) {
logVerbose(`imessage: plugin-bound conversation ${conversationId}`);
return route;
} else if (runtimeRoute.boundSessionKey) {
logVerbose(
`imessage: routed via bound conversation ${conversationId} -> ${runtimeRoute.boundSessionKey}`,
);
}
logVerbose(`imessage: routed via bound conversation ${conversationId} -> ${boundSessionKey}`);
return {
...route,
sessionKey: boundSessionKey,
agentId: resolveAgentIdFromSessionKey(boundSessionKey),
lastRoutePolicy: deriveLastRoutePolicy({
sessionKey: boundSessionKey,
mainSessionKey: route.mainSessionKey,
}),
matchedBy: "binding.channel",
};
return route;
}