Skip to content

Commit c6b4411

Browse files
dfhfg123Ybqac
andauthored
add mode parameter and add CI to the dev parameter (#181)
* Add dev package workflow (#170) * merge的时候自动发包 * fix * fix * test * Fix/addofffical (#171) * add offical widget * fix * 添加选分支的功能 (#172) * 修复版本号格式问题 (#173) * fix (#174) * 改为commit时间戳 (#176) * fix (#177) * fix * fix (#178) * Fix/remov (#179) * fix * fix * Fix/remov (#180) * fix * fix * fix * fix version * fix (#182) * Fix/weight fetch (#183) * fix * fix --------- Co-authored-by: Ybqac <137890469+Ybqac@users.noreply.github.com>
1 parent 112c7f0 commit c6b4411

5 files changed

Lines changed: 179 additions & 51 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Build and Publish Dev Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'The branch to checkout code from'
8+
required: true
9+
default: 'dev'
10+
pull_request:
11+
types: ['closed']
12+
branches:
13+
- dev
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.inputs.branch }}
17+
cancel-in-progress: true
18+
19+
env:
20+
target_branch: ${{ github.event.inputs.branch || github.event.pull_request.merge_commit_sha }}
21+
branch_name: ${{ github.event.inputs.branch || github.event.pull_request.head.ref || 'dev' }}
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
ref: ${{ env.target_branch }}
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: '20.9.0'
38+
cache: 'npm'
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: '3.10'
44+
45+
- name: Read original version and create dev version
46+
id: version_processing
47+
run: |
48+
# 读取原始版本
49+
ORIGINAL_VERSION=$(cat version.txt)
50+
echo "Original version: $ORIGINAL_VERSION"
51+
52+
# 生成commit 时间戳的 dev 版本号
53+
COMMIT_TS=$(git log -1 --format=%cd --date=format:%Y%m%d%H%M%S HEAD)
54+
DEV_VERSION="${ORIGINAL_VERSION}.dev${COMMIT_TS}"
55+
56+
# 输出环境变量供后续步骤使用
57+
echo "DEV_VERSION=$DEV_VERSION" >> $GITHUB_ENV
58+
echo "Publishing dev version: $DEV_VERSION"
59+
60+
# 写入临时的 version.txt(只在当前工作目录生效)
61+
echo "$DEV_VERSION" > version.txt
62+
63+
- name: Install dependencies
64+
run: |
65+
npm install
66+
67+
- name: Install Python build dependencies
68+
run: |
69+
python -m pip install --upgrade pip
70+
pip install build wheel twine
71+
72+
- name: Build Python package
73+
run: |
74+
npm run build:py
75+
76+
- name: Verify package version
77+
run: |
78+
# 验证打包的版本是否正确
79+
PACKAGE_NAME=$(ls dist/*.whl | head -n1)
80+
echo "Built package: $PACKAGE_NAME"
81+
82+
# 检查包名中是否包含 dev 版本
83+
if [[ $PACKAGE_NAME != *"$DEV_VERSION"* ]]; then
84+
echo "Error: Package version doesn't match expected dev version"
85+
echo "Expected: $DEV_VERSION"
86+
echo "Actual package: $PACKAGE_NAME"
87+
exit 1
88+
fi
89+
90+
- name: Upload to PyPI
91+
env:
92+
TWINE_USERNAME: "__token__"
93+
TWINE_PASSWORD: ${{ secrets.PYPI_KEY }}
94+
run: |
95+
python -m twine upload dist/*.whl

bizyui/js/handle_load_nodes.js

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,79 @@ const BIZYAIR_MODEL_TYPE_KEY = "bizyair_model_type";
99
* @returns {boolean} 如果设置开启则返回 true,否则返回 false
1010
*/
1111
function shouldShowApiPricingBadge() {
12-
try {
13-
const app = document.querySelector("#vue-app").__vue_app__;
14-
const pinia = app.config.globalProperties.$pinia;
15-
const settingStore = pinia._s.get("setting");
16-
const showApiPricing = settingStore.get("Comfy.NodeBadge.ShowApiPricing");
17-
return showApiPricing !== false;
18-
} catch (error) {
19-
// 如果无法获取 store 或出错,默认返回 true(保持原有行为)
12+
2013
return true;
21-
}
14+
2215
}
2316

2417
// 获取node 的模型配置input
2518
export async function applyBadgeToNode(_this, forceRefresh = false) {
26-
const shouldShowBadge = shouldShowApiPricingBadge();
27-
28-
// 如果不是强制刷新,优先从节点属性中恢复模型类型(用于工作流加载场景)
29-
if (!forceRefresh && _this.properties && _this.properties[BIZYAIR_MODEL_TYPE_KEY]) {
30-
const modelType = _this.properties[BIZYAIR_MODEL_TYPE_KEY];
31-
if (shouldShowBadge) {
32-
await addPriceBadgeToNode(_this, modelType);
33-
}
34-
return;
35-
}
19+
const shouldShowBadge = shouldShowApiPricingBadge();
3620

37-
// 为包含model输入的节点添加价格徽章
38-
const hiddenOutput = hasModelInput(_this);
39-
40-
if (hiddenOutput) {
41-
if (!hiddenOutput.type) {
42-
console.error(`[modelPrice] error finding model type`);
43-
return;
44-
}
45-
46-
if (typeof hiddenOutput.type !== "string") {
21+
// 如果不是强制刷新,优先从节点属性中恢复模型类型(用于工作流加载场景)
22+
if (!forceRefresh && _this.properties && _this.properties[BIZYAIR_MODEL_TYPE_KEY]) {
23+
const modelType = _this.properties[BIZYAIR_MODEL_TYPE_KEY];
24+
// if (shouldShowBadge) {
25+
await addPriceBadgeToNode(_this, modelType);
26+
// }
4727
return;
4828
}
4929

50-
// 解析模型类型(传入节点对象以获取用户选择的model)
51-
const modelType = getModelTypeFromHiddenInput(hiddenOutput, _this);
30+
// 为包含model输入的节点添加价格徽章
31+
const hiddenOutput = hasModelInput(_this);
5232

53-
// 将hiddenOutput临时存储在节点上,方便后续使用
54-
_this._bizyairHiddenOutput = hiddenOutput;
33+
if (hiddenOutput) {
34+
if (!hiddenOutput.type) {
35+
console.error(`[modelPrice] error finding model type`);
36+
return;
37+
}
5538

56-
// 将模型类型存储到节点属性中,确保保存工作流时能被序列化
57-
if (!_this.properties) {
58-
_this.properties = {};
59-
}
60-
_this.properties[BIZYAIR_MODEL_TYPE_KEY] = modelType;
39+
if (typeof hiddenOutput.type !== "string") {
40+
return;
41+
}
6142

62-
// 只有在设置开启时才添加badge
63-
if (shouldShowBadge) {
64-
await addPriceBadgeToNode(_this, modelType);
65-
}
43+
// 解析模型类型(传入节点对象以获取用户选择的model)
44+
const modelType = getModelTypeFromHiddenInput(hiddenOutput, _this);
45+
46+
// 将hiddenOutput临时存储在节点上,方便后续使用
47+
_this._bizyairHiddenOutput = hiddenOutput;
48+
49+
// 将模型类型存储到节点属性中,确保保存工作流时能被序列化
50+
if (!_this.properties) {
51+
_this.properties = {};
52+
}
53+
_this.properties[BIZYAIR_MODEL_TYPE_KEY] = modelType;
6654

67-
// 无论是否添加badge,都要删除无用的outputs
68-
_this.outputs = _this.outputs.filter(
69-
(output) => output.name !== hiddenOutput.name
70-
);
55+
// 只有在设置开启时才添加badge
56+
if (shouldShowBadge) {
57+
await addPriceBadgeToNode(_this, modelType);
58+
}
59+
60+
// 无论是否添加badge,都要删除无用的outputs
61+
_this.outputs = _this.outputs.filter(
62+
(output) => output.name !== hiddenOutput.name
63+
);
7164
}
7265
}
7366

7467
// 从hiddenInput中获取模型类型
7568
function getModelTypeFromHiddenInput(hiddenOutput, node){
76-
const modelJson = JSON.parse(hiddenOutput.type);
69+
let modelJson;
70+
try {
71+
modelJson = JSON.parse(hiddenOutput.type);
72+
} catch (e) {
73+
return hiddenOutput.type;
74+
}
75+
// 从 mode widget 获取 key.当 modelJson 包含 "official" 或 "third-party" 键时,才启用 mode 优先逻辑
76+
const isModeMap = modelJson && (modelJson.hasOwnProperty("official") || modelJson.hasOwnProperty("third-party"));
7777

78+
if (isModeMap && node.widgets) {
79+
const modeWidget = node.widgets.find(w => w.name === "mode");
80+
if (modeWidget && modeWidget.value && modelJson[modeWidget.value]) {
81+
return modelJson[modeWidget.value];
82+
}
83+
}
84+
7885
// 从节点的widgets中获取用户选择的model
7986
let selectedModel = null;
8087
const possibleWidgetNames = ["model", "model_name"];
@@ -94,8 +101,14 @@ function getModelTypeFromHiddenInput(hiddenOutput, node){
94101
}
95102

96103
// 如果没找到或key不存在,回退到使用第一个键(兼容旧逻辑)
97-
const modelsList = Object.keys(modelJson);
98-
return modelJson[modelsList[0]];
104+
if (typeof modelJson === 'object' && modelJson !== null) {
105+
const modelsList = Object.keys(modelJson);
106+
if (modelsList.length > 0) {
107+
return modelJson[modelsList[0]];
108+
}
109+
}
110+
// 如果是字符串或者其他情况,直接返回
111+
return hiddenOutput.type;
99112
}
100113

101114
// 自定义节点创建处理函数

bizyui/js/handle_node_configure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ app.registerExtension({
2222
name: 'bizyair.handle.node.configure',
2323
nodeCreated(node, app) {
2424
// 做忽略的widget 这些widget不做获取价格的操作
25-
const ignoreWidgets = ['prompt', 'negative_prompt', 'inputcount']
25+
const ignoreWidgets = ['prompt', 'negative_prompt', 'inputcount', 'mode']
2626
// 在这里可以拿到变化之后的值,并且也可以拿到node,这时候给node切换badge即可
2727
if (node && node.widgets && Array.isArray(node.widgets)) {
2828
if (!hasModelInput(node)) {

bizyui/js/image_upload.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { app } from "../../../scripts/app.js";
2+
import { applyBadgeToNode } from './handle_load_nodes.js'
23
/*
34
BizyAir_Seedream4_5
45
BizyAir_NanoBananaPro
@@ -121,6 +122,25 @@ function initializeDynamicInputs(node) {
121122
}
122123
}
123124
});
125+
// 添加下拉选择 widget
126+
if (
127+
nodeIdentifier === "BizyAir_NanoBananaPro" ||
128+
nodeIdentifier === "BizyAir_NanoBananaProOfficial"
129+
) {
130+
const modeWidget = node.widgets?.find(w => w.name === "mode");
131+
if (modeWidget) {
132+
modeWidget.callback = () => {
133+
applyBadgeToNode(node, true);
134+
};
135+
} else {
136+
node.addWidget("combo", "mode", "official", () => {
137+
applyBadgeToNode(node, true);
138+
}, {
139+
values: ["official", "third-party"],
140+
tooltip: "官方渠道vs第三方渠道",
141+
});
142+
}
143+
}
124144
}
125145

126146
app.registerExtension({

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.95
1+
1.2.97

0 commit comments

Comments
 (0)