mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:20:44 +00:00
refactor(channels): centralize runtime binding routes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user