Skip to content

Commit b519962

Browse files
authored
add price link (#205)
1 parent d45b799 commit b519962

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

bizyui/js/handle_node_configure.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function chainCallback(originalCallback, newCallback) {
1818
}
1919
}
2020

21+
function isImagesInputSlot(slot) {
22+
return slot?.name === 'images' || slot?.localized_name === 'images'
23+
}
24+
2125
app.registerExtension({
2226
name: 'bizyair.handle.node.configure',
2327
nodeCreated(node, app) {
@@ -28,6 +32,28 @@ app.registerExtension({
2832
if (!hasModelInput(node)) {
2933
return
3034
}
35+
36+
if (!node._bizyairPriceConnectionHooked) {
37+
const originalOnConnectionsChange = node.onConnectionsChange
38+
node.onConnectionsChange = chainCallback(
39+
originalOnConnectionsChange,
40+
async function (type, slotIndex, isConnected, linkInfo, ioSlot) {
41+
const inputSlot = this.inputs?.[slotIndex]
42+
if (!isImagesInputSlot(inputSlot)) {
43+
return
44+
}
45+
46+
// 只处理 images 输入槽位本身的连线变化,避免误判 output 变化。
47+
if (ioSlot && ioSlot !== inputSlot) {
48+
return
49+
}
50+
51+
await applyBadgeToNode(node, true)
52+
}
53+
)
54+
node._bizyairPriceConnectionHooked = true
55+
}
56+
3157
// 不仅仅是切换model才会修改模型定价,比如切换输入参数也会修改模型定价
3258
node.widgets.forEach(widget => {
3359
// 对于prompt这种输入频繁的widget 不做获取价格操作

bizyui/js/model_price.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ export function getBadgeConfigByCoinType(coinType, priceText) {
145145
};
146146
}
147147

148+
function getImagesLinkFlag(node) {
149+
if (!node?.inputs || !Array.isArray(node.inputs)) {
150+
return "false";
151+
}
152+
153+
const imagesInput = node.inputs.find(
154+
(input) => input?.name === "images" || input?.localized_name === "images"
155+
);
156+
157+
return imagesInput?.link != null ? "true" : "false";
158+
}
159+
148160
/**
149161
* 为节点添加价格徽章
150162
* @param {Object} node - 节点对象,包含 widgets 和其他节点信息
@@ -167,6 +179,8 @@ export async function addPriceBadgeToNode(node, modelName = "") {
167179
nodeInputs.model = modelName;
168180
}
169181

182+
nodeInputs.images = getImagesLinkFlag(node);
183+
170184
// 获取价格信息
171185
const priceResult = await fetchNodePrice(modelName, nodeInputs);
172186

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.18
1+
1.3.19

0 commit comments

Comments
 (0)