mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
* lint: turn on type import rules setting up for verbatimModuleSyntax * lint: --fix for type imports
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import type ChatHistoryWidget from '@/components/graph/widgets/ChatHistoryWidget.vue'
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import { useChatHistoryWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useChatHistoryWidget'
|
|
|
|
const CHAT_HISTORY_WIDGET_NAME = '$$node-chat-history'
|
|
|
|
/**
|
|
* Composable for handling node text previews
|
|
*/
|
|
export function useNodeChatHistory(
|
|
options: {
|
|
minHeight?: number
|
|
props?: Omit<InstanceType<typeof ChatHistoryWidget>['$props'], 'widget'>
|
|
} = {}
|
|
) {
|
|
const chatHistoryWidget = useChatHistoryWidget(options)
|
|
|
|
const addChatHistoryWidget = (node: LGraphNode) =>
|
|
chatHistoryWidget(node, {
|
|
name: CHAT_HISTORY_WIDGET_NAME,
|
|
type: 'chatHistory'
|
|
})
|
|
|
|
/**
|
|
* Shows chat history for a node
|
|
* @param node The graph node to show the chat history for
|
|
*/
|
|
function showChatHistory(node: LGraphNode) {
|
|
// First remove any existing widget
|
|
removeChatHistory(node)
|
|
|
|
// Then add the widget with new history
|
|
addChatHistoryWidget(node)
|
|
node.setDirtyCanvas?.(true)
|
|
}
|
|
|
|
/**
|
|
* Removes chat history from a node
|
|
* @param node The graph node to remove the chat history from
|
|
*/
|
|
function removeChatHistory(node: LGraphNode) {
|
|
if (!node.widgets) return
|
|
|
|
const widgetIdx = node.widgets.findIndex(
|
|
(w) => w.name === CHAT_HISTORY_WIDGET_NAME
|
|
)
|
|
|
|
if (widgetIdx > -1) {
|
|
node.widgets[widgetIdx].onRemove?.()
|
|
node.widgets.splice(widgetIdx, 1)
|
|
}
|
|
}
|
|
|
|
return {
|
|
showChatHistory,
|
|
removeChatHistory
|
|
}
|
|
}
|