Skip to content

Commit f08ec0a

Browse files
christian-byrnegithub-actionshuchenlei
authored
[API Node] Add cost indicators on API nodes (#3924)
Co-authored-by: github-actions <[email protected]> Co-authored-by: Chenlei Hu <[email protected]>
1 parent 356886d commit f08ec0a

File tree

19 files changed

+506
-6
lines changed

19 files changed

+506
-6
lines changed

src/composables/node/useNodeBadge.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import _ from 'lodash'
77
import { computed, onMounted, watch } from 'vue'
88

9+
import { useNodePricing } from '@/composables/node/useNodePricing'
910
import { app } from '@/scripts/app'
1011
import { useExtensionStore } from '@/stores/extensionStore'
1112
import { ComfyNodeDefImpl, useNodeDefStore } from '@/stores/nodeDefStore'
@@ -42,9 +43,21 @@ export const useNodeBadge = () => {
4243
) as NodeBadgeMode
4344
)
4445

45-
watch([nodeSourceBadgeMode, nodeIdBadgeMode, nodeLifeCycleBadgeMode], () => {
46-
app.graph?.setDirtyCanvas(true, true)
47-
})
46+
const showApiPricingBadge = computed(() =>
47+
settingStore.get('Comfy.NodeBadge.ShowApiPricing')
48+
)
49+
50+
watch(
51+
[
52+
nodeSourceBadgeMode,
53+
nodeIdBadgeMode,
54+
nodeLifeCycleBadgeMode,
55+
showApiPricingBadge
56+
],
57+
() => {
58+
app.graph?.setDirtyCanvas(true, true)
59+
}
60+
)
4861

4962
const nodeDefStore = useNodeDefStore()
5063
function badgeTextVisible(
@@ -58,6 +71,8 @@ export const useNodeBadge = () => {
5871
}
5972

6073
onMounted(() => {
74+
const nodePricing = useNodePricing()
75+
6176
extensionStore.registerExtension({
6277
name: 'Comfy.NodeBadge',
6378
nodeCreated(node: LGraphNode) {
@@ -95,13 +110,15 @@ export const useNodeBadge = () => {
95110

96111
node.badges.push(() => badge.value)
97112

98-
if (node.constructor.nodeData?.api_node) {
113+
if (node.constructor.nodeData?.api_node && showApiPricingBadge.value) {
114+
const price = nodePricing.getNodeDisplayPrice(node)
115+
// Always add the badge for API nodes, with or without price text
99116
const creditsBadge = computed(() => {
100117
// Use dynamic background color based on the theme
101118
const isLightTheme =
102119
colorPaletteStore.completedActivePalette.light_theme
103120
return new LGraphBadge({
104-
text: '',
121+
text: price,
105122
iconOptions: {
106123
unicode: '\ue96b',
107124
fontFamily: 'PrimeIcons',

0 commit comments

Comments
 (0)