audit-e2w 1.11.2 → 1.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -148
- package/dsh_plugins/audit-e2w/lib/index.js +9 -1
- package/dsh_plugins/audit-e2w/lib/skill.js +3 -2
- package/excel_word/README.md +45 -37
- package/excel_word/qoder_engine.py +10 -11
- package/excel_word/wesync/__init__.py +1 -1
- package/excel_word/wesync/ai/__init__.py +52 -0
- package/excel_word/wesync/ai/actions.py +369 -0
- package/excel_word/wesync/ai/client.py +340 -0
- package/excel_word/wesync/ai/config.py +291 -0
- package/excel_word/wesync/ai/docs.py +177 -0
- package/excel_word/wesync/ai/prompts.py +288 -0
- package/excel_word/wesync/ai/tasks/__init__.py +26 -0
- package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
- package/excel_word/wesync/ai/tasks/combined.py +123 -0
- package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
- package/excel_word/wesync/ai/tasks/headings.py +119 -0
- package/excel_word/wesync/ai/tasks/help_task.py +69 -0
- package/excel_word/wesync/ai/tasks/roles.py +128 -0
- package/excel_word/wesync/align.py +1 -0
- package/excel_word/wesync/api.py +544 -92
- package/excel_word/wesync/backup_history.py +44 -9
- package/excel_word/wesync/cli.py +19 -1
- package/excel_word/wesync/commands/blank_cmd.py +59 -30
- package/excel_word/wesync/commands/bookmark_cmd.py +41 -10
- package/excel_word/wesync/commands/clear_cmd.py +5 -3
- package/excel_word/wesync/commands/export_cmd.py +270 -220
- package/excel_word/wesync/commands/incremental_cmd.py +157 -0
- package/excel_word/wesync/commands/marks_cmd.py +24 -16
- package/excel_word/wesync/commands/placeholders_cmd.py +12 -7
- package/excel_word/wesync/commands/writeback_cmd.py +72 -116
- package/excel_word/wesync/config.py +3 -2
- package/excel_word/wesync/console.py +9 -2
- package/excel_word/wesync/docx_bookmarks.py +12 -5
- package/excel_word/wesync/docx_columns.py +1 -1
- package/excel_word/wesync/docx_marks.py +183 -75
- package/excel_word/wesync/docx_placeholders.py +65 -26
- package/excel_word/wesync/excel_blocks.py +144 -185
- package/excel_word/wesync/excel_export.py +15 -8
- package/excel_word/wesync/excel_marks.py +265 -193
- package/excel_word/wesync/fsops.py +11 -6
- package/excel_word/wesync/gui/__init__.py +21 -2
- package/excel_word/wesync/gui/app.py +243 -29
- package/excel_word/wesync/gui/manual.py +5 -3
- package/excel_word/wesync/gui/pages/__init__.py +53 -4
- package/excel_word/wesync/gui/pages/_page.py +129 -7
- package/excel_word/wesync/gui/pages/ai_page.py +854 -0
- package/excel_word/wesync/gui/pages/batch_page.py +64 -31
- package/excel_word/wesync/gui/pages/blank_page.py +529 -464
- package/excel_word/wesync/gui/pages/bookmark_page.py +97 -37
- package/excel_word/wesync/gui/pages/export_page.py +140 -87
- package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
- package/excel_word/wesync/gui/pages/format_page.py +551 -429
- package/excel_word/wesync/gui/pages/help_page.py +73 -7
- package/excel_word/wesync/gui/pages/history_page.py +167 -144
- package/excel_word/wesync/gui/pages/marks_page.py +210 -177
- package/excel_word/wesync/gui/pages/settings_page.py +450 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +167 -146
- package/excel_word/wesync/gui/runner.py +29 -13
- package/excel_word/wesync/gui/store.py +23 -7
- package/excel_word/wesync/gui/theme.py +220 -49
- package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
- package/excel_word/wesync/gui/widgets/cards.py +124 -5
- package/excel_word/wesync/gui/widgets/chips.py +565 -0
- package/excel_word/wesync/gui/widgets/filebar.py +1 -1
- package/excel_word/wesync/gui/widgets/logpane.py +24 -8
- package/excel_word/wesync/gui/widgets/nav.py +267 -12
- package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
- package/excel_word/wesync/report_format.py +9 -1
- package/excel_word/wesync/settings.py +35 -0
- package/excel_word/wesync/sort_rules.py +75 -26
- package/excel_word/wesync/valuefmt.py +40 -17
- package/package.json +53 -51
- package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
- package/qoder_plugins/audit-toolbox/README.md +159 -156
- package/qoder_plugins/audit-toolbox/catalog.mjs +13 -13
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"""AI 大模型配置卡片:供「全局设置」页使用。
|
|
2
|
+
|
|
3
|
+
独立成组件的原因:
|
|
4
|
+
- 配置项多(服务商/地址/模型/密钥/隐私/超时/字数),塞进设置页会让该文件过长;
|
|
5
|
+
- 配置存 `.wesync_ai.json`,与设置页的 `.wesync_ui.json` 是两份文件,
|
|
6
|
+
所以本卡片自带「保存 AI 配置」按钮,不混用设置页的主保存按钮。
|
|
7
|
+
|
|
8
|
+
边界:只读写配置文件与发一次连通性测试,不碰报告。
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from PySide6.QtCore import Qt
|
|
14
|
+
from PySide6.QtWidgets import (
|
|
15
|
+
QComboBox,
|
|
16
|
+
QFormLayout,
|
|
17
|
+
QFrame,
|
|
18
|
+
QHBoxLayout,
|
|
19
|
+
QLabel,
|
|
20
|
+
QLineEdit,
|
|
21
|
+
QPushButton,
|
|
22
|
+
QVBoxLayout,
|
|
23
|
+
QWidget,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from ... import api
|
|
27
|
+
from .cards import make_card, make_checkbutton
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AiConfigCard(QFrame):
|
|
31
|
+
"""AI 大模型配置卡片;调用方负责把它放进页面布局。"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, ctx, parent=None):
|
|
34
|
+
super().__init__(parent)
|
|
35
|
+
self.ctx = ctx
|
|
36
|
+
self._providers: dict[str, dict] = {}
|
|
37
|
+
self._saved_key_mask = ""
|
|
38
|
+
self._has_key = False
|
|
39
|
+
self._busy_kind: str | None = None
|
|
40
|
+
self._pending: dict = {}
|
|
41
|
+
|
|
42
|
+
card = make_card(self)
|
|
43
|
+
outer = QVBoxLayout(self)
|
|
44
|
+
outer.setContentsMargins(0, 0, 0, 0)
|
|
45
|
+
outer.addWidget(card)
|
|
46
|
+
self._card = card
|
|
47
|
+
|
|
48
|
+
header = QWidget()
|
|
49
|
+
header_layout = QHBoxLayout(header)
|
|
50
|
+
header_layout.setContentsMargins(0, 0, 0, 4)
|
|
51
|
+
title = QLabel("AI 大模型")
|
|
52
|
+
title.setObjectName("SettingTitle")
|
|
53
|
+
header_layout.addWidget(title)
|
|
54
|
+
header_layout.addStretch(1)
|
|
55
|
+
tag = QLabel("可选 · 默认关闭")
|
|
56
|
+
tag.setObjectName("SettingTag")
|
|
57
|
+
header_layout.addWidget(tag)
|
|
58
|
+
card.layout().addWidget(header)
|
|
59
|
+
|
|
60
|
+
self.enabled_switch = make_checkbutton(card, "启用 AI", False)
|
|
61
|
+
self.enabled_switch.toggled.connect(self._refresh_enabled)
|
|
62
|
+
card.layout().addWidget(self.enabled_switch)
|
|
63
|
+
|
|
64
|
+
form = QFormLayout()
|
|
65
|
+
form.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
66
|
+
form.setContentsMargins(0, 4, 0, 0)
|
|
67
|
+
form.setSpacing(8)
|
|
68
|
+
|
|
69
|
+
self.provider_combo = QComboBox()
|
|
70
|
+
self.provider_combo.currentIndexChanged.connect(self._provider_changed)
|
|
71
|
+
form.addRow("服务商", self.provider_combo)
|
|
72
|
+
|
|
73
|
+
self.base_url_edit = QLineEdit()
|
|
74
|
+
self.base_url_edit.setPlaceholderText("例如 https://api.deepseek.com/v1")
|
|
75
|
+
form.addRow("接口地址", self.base_url_edit)
|
|
76
|
+
|
|
77
|
+
self.model_edit = QComboBox()
|
|
78
|
+
self.model_edit.setEditable(True)
|
|
79
|
+
self.model_edit.setInsertPolicy(QComboBox.NoInsert)
|
|
80
|
+
self.model_edit.lineEdit().setPlaceholderText("例如 deepseek-flash 或 qwen3:8b")
|
|
81
|
+
model_row = QWidget()
|
|
82
|
+
model_layout = QHBoxLayout(model_row)
|
|
83
|
+
model_layout.setContentsMargins(0, 0, 0, 0)
|
|
84
|
+
model_layout.setSpacing(8)
|
|
85
|
+
model_layout.addWidget(self.model_edit, 1)
|
|
86
|
+
self.list_models_button = QPushButton("获取模型列表")
|
|
87
|
+
self.list_models_button.setToolTip("向服务商查询当前可用的模型名,避免手填的名字已过期")
|
|
88
|
+
self.list_models_button.clicked.connect(lambda _checked=False: self._fetch_models())
|
|
89
|
+
model_layout.addWidget(self.list_models_button)
|
|
90
|
+
form.addRow("模型名", model_row)
|
|
91
|
+
|
|
92
|
+
self.provider_hint = QLabel()
|
|
93
|
+
self.provider_hint.setObjectName("CardDesc")
|
|
94
|
+
self.provider_hint.setWordWrap(True)
|
|
95
|
+
self.provider_hint.setMinimumWidth(0)
|
|
96
|
+
form.addRow("", self.provider_hint)
|
|
97
|
+
|
|
98
|
+
self.key_edit = QLineEdit()
|
|
99
|
+
self.key_edit.setEchoMode(QLineEdit.Password)
|
|
100
|
+
self.key_edit.setPlaceholderText("留空表示沿用已保存密钥;本机服务可留空")
|
|
101
|
+
form.addRow("API Key", self.key_edit)
|
|
102
|
+
|
|
103
|
+
self.privacy_combo = QComboBox()
|
|
104
|
+
form.addRow("隐私级别", self.privacy_combo)
|
|
105
|
+
|
|
106
|
+
self.timeout_edit = QLineEdit()
|
|
107
|
+
self.timeout_edit.setPlaceholderText("5~600 秒,默认 60")
|
|
108
|
+
self.timeout_edit.setMaximumWidth(180)
|
|
109
|
+
form.addRow("超时秒数", self.timeout_edit)
|
|
110
|
+
|
|
111
|
+
self.limit_edit = QLineEdit()
|
|
112
|
+
self.limit_edit.setPlaceholderText("每个候选最多发送多少字,默认 200")
|
|
113
|
+
self.limit_edit.setMaximumWidth(180)
|
|
114
|
+
form.addRow("上下文字数", self.limit_edit)
|
|
115
|
+
|
|
116
|
+
card.layout().addLayout(form)
|
|
117
|
+
|
|
118
|
+
self.tip_label = QLabel(
|
|
119
|
+
"只发送本地筛出的候选片段(候选标题、表格前段落、附注边界,及前后各最多 200 字),"
|
|
120
|
+
"绝不发送整篇报告、表格单元格或页眉页脚;接口地址填本机服务时数据不出机器。"
|
|
121
|
+
)
|
|
122
|
+
self.tip_label.setObjectName("CardDesc")
|
|
123
|
+
self.tip_label.setWordWrap(True)
|
|
124
|
+
self.tip_label.setMinimumWidth(0)
|
|
125
|
+
card.layout().addWidget(self.tip_label)
|
|
126
|
+
|
|
127
|
+
row = QWidget()
|
|
128
|
+
row_layout = QHBoxLayout(row)
|
|
129
|
+
row_layout.setContentsMargins(0, 4, 0, 0)
|
|
130
|
+
row_layout.setSpacing(10)
|
|
131
|
+
self.test_button = QPushButton("测试连接")
|
|
132
|
+
self.test_button.clicked.connect(lambda _checked=False: self._test())
|
|
133
|
+
row_layout.addWidget(self.test_button)
|
|
134
|
+
self.save_button = QPushButton("保存 AI 配置")
|
|
135
|
+
self.save_button.setObjectName("Primary")
|
|
136
|
+
self.save_button.clicked.connect(lambda _checked=False: self._save())
|
|
137
|
+
row_layout.addWidget(self.save_button)
|
|
138
|
+
self.reload_button = QPushButton("重新读取")
|
|
139
|
+
self.reload_button.clicked.connect(lambda _checked=False: self.reload())
|
|
140
|
+
row_layout.addWidget(self.reload_button)
|
|
141
|
+
self.status_label = QLabel()
|
|
142
|
+
self.status_label.setObjectName("CardDesc")
|
|
143
|
+
self.status_label.setWordWrap(True)
|
|
144
|
+
self.status_label.setMinimumWidth(0)
|
|
145
|
+
row_layout.addWidget(self.status_label, 1)
|
|
146
|
+
card.layout().addWidget(row)
|
|
147
|
+
|
|
148
|
+
self.reload()
|
|
149
|
+
|
|
150
|
+
# ------------------------------------------------------------------ 数据
|
|
151
|
+
|
|
152
|
+
def is_enabled(self) -> bool:
|
|
153
|
+
return self.enabled_switch.isChecked()
|
|
154
|
+
|
|
155
|
+
def reload(self) -> None:
|
|
156
|
+
try:
|
|
157
|
+
data = api.ai_settings()
|
|
158
|
+
except Exception as exc:
|
|
159
|
+
self.status_label.setText(f"读取 AI 配置失败:{exc}")
|
|
160
|
+
self._set_controls(False)
|
|
161
|
+
return
|
|
162
|
+
self._providers = data.get("providers", {})
|
|
163
|
+
config = data.get("config", {})
|
|
164
|
+
self._saved_key_mask = config.get("api_key_mask", "")
|
|
165
|
+
self._has_key = bool(config.get("has_key"))
|
|
166
|
+
|
|
167
|
+
self.provider_combo.blockSignals(True)
|
|
168
|
+
try:
|
|
169
|
+
self.provider_combo.clear()
|
|
170
|
+
for name, item in self._providers.items():
|
|
171
|
+
self.provider_combo.addItem(item.get("label", name), name)
|
|
172
|
+
index = self.provider_combo.findData(config.get("provider"))
|
|
173
|
+
self.provider_combo.setCurrentIndex(index if index >= 0 else 0)
|
|
174
|
+
finally:
|
|
175
|
+
self.provider_combo.blockSignals(False)
|
|
176
|
+
|
|
177
|
+
self.privacy_combo.clear()
|
|
178
|
+
for name, label in (data.get("privacy_levels") or {}).items():
|
|
179
|
+
self.privacy_combo.addItem(label, name)
|
|
180
|
+
index = self.privacy_combo.findData(config.get("privacy_level"))
|
|
181
|
+
self.privacy_combo.setCurrentIndex(index if index >= 0 else 0)
|
|
182
|
+
|
|
183
|
+
self.base_url_edit.setText(str(config.get("base_url", "")))
|
|
184
|
+
self.model_edit.clear()
|
|
185
|
+
self.model_edit.setCurrentText(str(config.get("model", "")))
|
|
186
|
+
self.timeout_edit.setText(str(config.get("timeout_seconds", 60)))
|
|
187
|
+
self.limit_edit.setText(str(config.get("max_context_chars", 200)))
|
|
188
|
+
preset = self._providers.get(config.get("provider"), {})
|
|
189
|
+
hint = preset.get("hint", "")
|
|
190
|
+
self.provider_hint.setText(hint)
|
|
191
|
+
self.provider_hint.setVisible(bool(hint))
|
|
192
|
+
self.enabled_switch.blockSignals(True)
|
|
193
|
+
try:
|
|
194
|
+
self.enabled_switch.setChecked(bool(config.get("enabled")))
|
|
195
|
+
finally:
|
|
196
|
+
self.enabled_switch.blockSignals(False)
|
|
197
|
+
self.key_edit.clear()
|
|
198
|
+
self.key_edit.setPlaceholderText(
|
|
199
|
+
f"已保存:{self._saved_key_mask}(留空表示不修改)" if self._has_key
|
|
200
|
+
else "尚未保存密钥;本机服务可留空"
|
|
201
|
+
)
|
|
202
|
+
self._refresh_enabled()
|
|
203
|
+
|
|
204
|
+
def _refresh_enabled(self, *_args) -> None:
|
|
205
|
+
enabled = self.enabled_switch.isChecked()
|
|
206
|
+
self._set_controls(enabled)
|
|
207
|
+
provider = self._providers.get(self.provider_combo.currentData(), {})
|
|
208
|
+
needs_key = bool(provider.get("needs_key", True))
|
|
209
|
+
self.key_edit.setEnabled(enabled and needs_key)
|
|
210
|
+
self.status_label.setText(
|
|
211
|
+
"AI 已启用;改完请点「保存 AI 配置」。" if enabled
|
|
212
|
+
else "AI 未启用:所有功能与原来完全一致,不会加载 AI 模块、不会联网。"
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def _set_controls(self, enabled: bool) -> None:
|
|
216
|
+
for widget in (
|
|
217
|
+
self.test_button, self.list_models_button, self.provider_combo,
|
|
218
|
+
self.base_url_edit, self.model_edit, self.privacy_combo,
|
|
219
|
+
self.timeout_edit, self.limit_edit,
|
|
220
|
+
):
|
|
221
|
+
widget.setEnabled(enabled)
|
|
222
|
+
|
|
223
|
+
def _provider_changed(self, _index: int) -> None:
|
|
224
|
+
preset = self._providers.get(self.provider_combo.currentData())
|
|
225
|
+
if not preset:
|
|
226
|
+
return
|
|
227
|
+
self.base_url_edit.setText(preset.get("base_url", ""))
|
|
228
|
+
self.model_edit.clear()
|
|
229
|
+
self.model_edit.setCurrentText(preset.get("model", ""))
|
|
230
|
+
hint = preset.get("hint", "")
|
|
231
|
+
self.provider_hint.setText(hint)
|
|
232
|
+
self.provider_hint.setVisible(bool(hint))
|
|
233
|
+
self.key_edit.setEnabled(self.enabled_switch.isChecked() and bool(preset.get("needs_key", True)))
|
|
234
|
+
|
|
235
|
+
def _collect(self) -> dict:
|
|
236
|
+
return {
|
|
237
|
+
"enabled": self.enabled_switch.isChecked(),
|
|
238
|
+
"provider": self.provider_combo.currentData(),
|
|
239
|
+
"base_url": self.base_url_edit.text().strip(),
|
|
240
|
+
"model": self.model_edit.currentText().strip(),
|
|
241
|
+
"privacy_level": self.privacy_combo.currentData(),
|
|
242
|
+
"timeout_seconds": _int_or(self.timeout_edit.text(), 60),
|
|
243
|
+
"max_context_chars": _int_or(self.limit_edit.text(), 200),
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
# ------------------------------------------------------------------ 动作
|
|
247
|
+
|
|
248
|
+
def _run(self, kind: str, title: str, work) -> None:
|
|
249
|
+
self._busy_kind = kind
|
|
250
|
+
self._pending = {}
|
|
251
|
+
|
|
252
|
+
def wrapped() -> int:
|
|
253
|
+
self._pending[kind] = work()
|
|
254
|
+
return 0
|
|
255
|
+
|
|
256
|
+
if not self.ctx.run_steps([(title, wrapped)], on_success=self._done):
|
|
257
|
+
self.status_label.setText("已有任务在执行,请稍候。")
|
|
258
|
+
self._busy_kind = None
|
|
259
|
+
self._set_controls(self.enabled_switch.isChecked())
|
|
260
|
+
|
|
261
|
+
def _done(self, _data=None) -> None:
|
|
262
|
+
kind, self._busy_kind = self._busy_kind, None
|
|
263
|
+
payload = self._pending.get(kind) or {}
|
|
264
|
+
if kind == "models":
|
|
265
|
+
self._render_models(payload)
|
|
266
|
+
elif kind == "test":
|
|
267
|
+
self._render_test(payload)
|
|
268
|
+
self._set_controls(self.enabled_switch.isChecked())
|
|
269
|
+
|
|
270
|
+
def _save(self) -> None:
|
|
271
|
+
typed = self.key_edit.text().strip()
|
|
272
|
+
try:
|
|
273
|
+
api.ai_save_settings(self._collect(), api_key=typed if typed else None)
|
|
274
|
+
except Exception as exc:
|
|
275
|
+
self.ctx.error("保存 AI 配置失败", f"配置未保存。\n\n{exc}")
|
|
276
|
+
return
|
|
277
|
+
self.reload()
|
|
278
|
+
self.status_label.setText("AI 配置已保存到项目内 .wesync_ai.json。")
|
|
279
|
+
self.ctx.log("AI 配置已保存。", "ok")
|
|
280
|
+
# 保存后立刻让「AI 助手」页同步启用状态,避免它停留在旧状态
|
|
281
|
+
page = self.ctx.page("AiPage")
|
|
282
|
+
if page is not None and hasattr(page, "_reload"):
|
|
283
|
+
try:
|
|
284
|
+
page._reload()
|
|
285
|
+
except Exception:
|
|
286
|
+
pass
|
|
287
|
+
|
|
288
|
+
def _fetch_models(self) -> None:
|
|
289
|
+
values = self._collect()
|
|
290
|
+
if not values.get("base_url"):
|
|
291
|
+
self.ctx.error("缺少接口地址", "请先填写接口地址,再获取模型列表。")
|
|
292
|
+
return
|
|
293
|
+
typed = self.key_edit.text().strip()
|
|
294
|
+
self.list_models_button.setEnabled(False)
|
|
295
|
+
self.list_models_button.setText("查询中…")
|
|
296
|
+
|
|
297
|
+
def work():
|
|
298
|
+
from ...ai.config import load_ai_config, save_api_key
|
|
299
|
+
|
|
300
|
+
config = {**load_ai_config(), **values}
|
|
301
|
+
if typed:
|
|
302
|
+
config["api_key_enc"] = save_api_key(typed)
|
|
303
|
+
return api.ai_list_models(config)
|
|
304
|
+
|
|
305
|
+
self._run("models", "获取模型列表", work)
|
|
306
|
+
|
|
307
|
+
def _render_models(self, payload: dict) -> None:
|
|
308
|
+
self.list_models_button.setText("获取模型列表")
|
|
309
|
+
if not payload.get("ok"):
|
|
310
|
+
self.provider_hint.setText(f"获取失败:{payload.get('message', '未知错误')}")
|
|
311
|
+
self.provider_hint.setVisible(True)
|
|
312
|
+
return
|
|
313
|
+
models = payload.get("models") or []
|
|
314
|
+
current = self.model_edit.currentText().strip()
|
|
315
|
+
self.model_edit.blockSignals(True)
|
|
316
|
+
try:
|
|
317
|
+
self.model_edit.clear()
|
|
318
|
+
self.model_edit.addItems(models)
|
|
319
|
+
if current:
|
|
320
|
+
self.model_edit.setCurrentText(current)
|
|
321
|
+
elif models:
|
|
322
|
+
self.model_edit.setCurrentText(models[0])
|
|
323
|
+
finally:
|
|
324
|
+
self.model_edit.blockSignals(False)
|
|
325
|
+
self.provider_hint.setText(f"已获取 {len(models)} 个模型,可从下拉框选择;也可继续手填。")
|
|
326
|
+
self.provider_hint.setVisible(True)
|
|
327
|
+
|
|
328
|
+
def _test(self) -> None:
|
|
329
|
+
values = self._collect()
|
|
330
|
+
typed = self.key_edit.text().strip()
|
|
331
|
+
self.test_button.setEnabled(False)
|
|
332
|
+
self.status_label.setText("正在连接…")
|
|
333
|
+
|
|
334
|
+
def work():
|
|
335
|
+
from ...ai.config import load_ai_config, save_api_key
|
|
336
|
+
|
|
337
|
+
config = {**load_ai_config(), **values}
|
|
338
|
+
if typed:
|
|
339
|
+
config["api_key_enc"] = save_api_key(typed)
|
|
340
|
+
return api.ai_test_connection(config)
|
|
341
|
+
|
|
342
|
+
self._run("test", "测试 AI 连接", work)
|
|
343
|
+
|
|
344
|
+
def _render_test(self, payload: dict) -> None:
|
|
345
|
+
self.test_button.setEnabled(True)
|
|
346
|
+
if payload.get("ok"):
|
|
347
|
+
self.status_label.setText(
|
|
348
|
+
f"连接正常 · {payload.get('model', '')} · {payload.get('elapsed_ms', 0)} 毫秒"
|
|
349
|
+
)
|
|
350
|
+
return
|
|
351
|
+
message = payload.get("message", "未知错误")
|
|
352
|
+
text = f"连接失败:{message}"
|
|
353
|
+
if "模型" in message and ("不存在" in message or "列表" in message):
|
|
354
|
+
text += "\n提示:点「获取模型列表」选一个可用模型,再试一次。"
|
|
355
|
+
self.status_label.setText(text)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _int_or(text: str, default: int) -> int:
|
|
359
|
+
try:
|
|
360
|
+
return int(str(text).strip())
|
|
361
|
+
except (TypeError, ValueError):
|
|
362
|
+
return default
|
|
@@ -1,20 +1,139 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""卡片、选项网格与操作栏组件。"""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from PySide6.
|
|
5
|
+
from PySide6.QtCore import QSize
|
|
6
|
+
from PySide6.QtWidgets import (
|
|
7
|
+
QCheckBox,
|
|
8
|
+
QFrame,
|
|
9
|
+
QGridLayout,
|
|
10
|
+
QHBoxLayout,
|
|
11
|
+
QLabel,
|
|
12
|
+
QPushButton,
|
|
13
|
+
QVBoxLayout,
|
|
14
|
+
QWidget,
|
|
15
|
+
)
|
|
6
16
|
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
class _WrappingActionBar(QWidget):
|
|
19
|
+
def __init__(self, parent=None):
|
|
20
|
+
super().__init__(parent)
|
|
21
|
+
self.buttons: list[QPushButton] = []
|
|
22
|
+
self._layout = QGridLayout(self)
|
|
23
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
24
|
+
self._layout.setSpacing(10)
|
|
25
|
+
|
|
26
|
+
def add_button(self, button: QPushButton) -> None:
|
|
27
|
+
button.setParent(self)
|
|
28
|
+
self.buttons.append(button)
|
|
29
|
+
self._reflow()
|
|
30
|
+
|
|
31
|
+
def minimumSizeHint(self) -> QSize:
|
|
32
|
+
width = max((button.minimumSizeHint().width() for button in self.buttons), default=0)
|
|
33
|
+
return QSize(width, 0)
|
|
34
|
+
|
|
35
|
+
def resizeEvent(self, event) -> None:
|
|
36
|
+
super().resizeEvent(event)
|
|
37
|
+
self._reflow()
|
|
38
|
+
|
|
39
|
+
def _reflow(self) -> None:
|
|
40
|
+
while self._layout.count():
|
|
41
|
+
self._layout.takeAt(self._layout.count() - 1)
|
|
42
|
+
columns = 1
|
|
43
|
+
for candidate in range(1, len(self.buttons) + 1):
|
|
44
|
+
needed = sum(self.buttons[index].sizeHint().width() for index in range(candidate))
|
|
45
|
+
needed += self._layout.spacing() * (candidate - 1)
|
|
46
|
+
if needed <= self.width():
|
|
47
|
+
columns = candidate
|
|
48
|
+
else:
|
|
49
|
+
break
|
|
50
|
+
for index, button in enumerate(self.buttons):
|
|
51
|
+
self._layout.addWidget(button, index // columns, index % columns)
|
|
52
|
+
for column in range(columns):
|
|
53
|
+
self._layout.setColumnStretch(column, 1)
|
|
54
|
+
self.updateGeometry()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def make_card(parent=None, padding: int = 18) -> QFrame:
|
|
9
58
|
card = QFrame(parent)
|
|
10
59
|
card.setObjectName("Card")
|
|
11
60
|
layout = QVBoxLayout(card)
|
|
12
61
|
layout.setContentsMargins(padding, padding, padding, padding)
|
|
13
|
-
layout.setSpacing(
|
|
62
|
+
layout.setSpacing(10)
|
|
14
63
|
return card
|
|
15
64
|
|
|
16
65
|
|
|
17
66
|
def make_checkbutton(parent, text: str, checked: bool = False) -> QCheckBox:
|
|
18
67
|
box = QCheckBox(text, parent)
|
|
19
68
|
box.setChecked(checked)
|
|
20
|
-
return box
|
|
69
|
+
return box
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def make_option_grid(parent=None, columns: int = 3) -> QWidget:
|
|
73
|
+
grid = QWidget(parent)
|
|
74
|
+
layout = QGridLayout(grid)
|
|
75
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
76
|
+
layout.setHorizontalSpacing(10)
|
|
77
|
+
layout.setVerticalSpacing(10)
|
|
78
|
+
for index in range(columns):
|
|
79
|
+
layout.setColumnStretch(index, 1)
|
|
80
|
+
return grid
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def add_option_tile(
|
|
84
|
+
grid: QWidget,
|
|
85
|
+
text: str,
|
|
86
|
+
checked: bool = False,
|
|
87
|
+
*,
|
|
88
|
+
hint: str = "",
|
|
89
|
+
risk: bool = False,
|
|
90
|
+
columns: int = 3,
|
|
91
|
+
) -> QCheckBox:
|
|
92
|
+
tile = QFrame(grid)
|
|
93
|
+
tile.setObjectName("OptionTile")
|
|
94
|
+
layout = QVBoxLayout(tile)
|
|
95
|
+
layout.setContentsMargins(12, 10, 12, 10)
|
|
96
|
+
layout.setSpacing(4)
|
|
97
|
+
box = make_checkbutton(tile, text, checked)
|
|
98
|
+
layout.addWidget(box)
|
|
99
|
+
if hint:
|
|
100
|
+
note = QLabel(hint, tile)
|
|
101
|
+
note.setObjectName("RiskHint" if risk else "OptionHint")
|
|
102
|
+
note.setWordWrap(True)
|
|
103
|
+
note.setMinimumWidth(0)
|
|
104
|
+
layout.addWidget(note)
|
|
105
|
+
target = grid.layout()
|
|
106
|
+
row = (target.count() // columns)
|
|
107
|
+
column = target.count() % columns
|
|
108
|
+
target.addWidget(tile, row, column)
|
|
109
|
+
for index in range(columns):
|
|
110
|
+
target.setColumnStretch(index, 1)
|
|
111
|
+
return box
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def make_action_bar(parent, primary_text: str, on_primary, secondary=(), *, primary_index: int | None = None) -> QWidget:
|
|
115
|
+
wrapping = primary_index is not None
|
|
116
|
+
row = _WrappingActionBar(parent) if wrapping else QWidget(parent)
|
|
117
|
+
layout = row._layout if wrapping else QHBoxLayout(row)
|
|
118
|
+
if not wrapping:
|
|
119
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
120
|
+
layout.setSpacing(10)
|
|
121
|
+
primary = QPushButton(primary_text, row)
|
|
122
|
+
primary.setObjectName("Primary")
|
|
123
|
+
primary.clicked.connect(lambda _checked=False: on_primary())
|
|
124
|
+
secondary_buttons = []
|
|
125
|
+
for text, callback in secondary:
|
|
126
|
+
button = QPushButton(text, row)
|
|
127
|
+
button.clicked.connect(lambda _checked=False, action=callback: action())
|
|
128
|
+
secondary_buttons.append(button)
|
|
129
|
+
if primary_index is None:
|
|
130
|
+
for button in secondary_buttons:
|
|
131
|
+
layout.addWidget(button)
|
|
132
|
+
layout.addStretch(1)
|
|
133
|
+
layout.addWidget(primary)
|
|
134
|
+
else:
|
|
135
|
+
ordered = list(secondary_buttons)
|
|
136
|
+
ordered.insert(primary_index, primary)
|
|
137
|
+
for button in ordered:
|
|
138
|
+
row.add_button(button)
|
|
139
|
+
return row
|