mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-06 06:41:08 +00:00
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import {
|
|
detachPluginConversationBinding,
|
|
getCurrentPluginConversationBinding,
|
|
requestPluginConversationBinding,
|
|
} from "./conversation-binding.js";
|
|
import type { PluginConversationBindingRequestParams } from "./types.js";
|
|
|
|
type RegisteredInteractiveMetadata = {
|
|
pluginId: string;
|
|
pluginName?: string;
|
|
pluginRoot?: string;
|
|
};
|
|
|
|
type PluginBindingConversation = Parameters<
|
|
typeof requestPluginConversationBinding
|
|
>[0]["conversation"];
|
|
|
|
export function createInteractiveConversationBindingHelpers(params: {
|
|
registration: RegisteredInteractiveMetadata;
|
|
senderId?: string;
|
|
conversation: PluginBindingConversation;
|
|
}) {
|
|
const { registration, senderId, conversation } = params;
|
|
const pluginRoot = registration.pluginRoot;
|
|
|
|
return {
|
|
requestConversationBinding: async (binding: PluginConversationBindingRequestParams = {}) => {
|
|
if (!pluginRoot) {
|
|
return {
|
|
status: "error" as const,
|
|
message: "This interaction cannot bind the current conversation.",
|
|
};
|
|
}
|
|
return requestPluginConversationBinding({
|
|
pluginId: registration.pluginId,
|
|
pluginName: registration.pluginName,
|
|
pluginRoot,
|
|
requestedBySenderId: senderId,
|
|
conversation,
|
|
binding,
|
|
});
|
|
},
|
|
detachConversationBinding: async () => {
|
|
if (!pluginRoot) {
|
|
return { removed: false };
|
|
}
|
|
return detachPluginConversationBinding({
|
|
pluginRoot,
|
|
conversation,
|
|
});
|
|
},
|
|
getCurrentConversationBinding: async () => {
|
|
if (!pluginRoot) {
|
|
return null;
|
|
}
|
|
return getCurrentPluginConversationBinding({
|
|
pluginRoot,
|
|
conversation,
|
|
});
|
|
},
|
|
};
|
|
}
|