@hfyjq/crannia 1.1.2 → 1.2.0
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/LICENSE +201 -201
- package/NOTICE +48 -45
- package/README.md +1 -1
- package/THIRD-PARTY-FRONTEND.md +5266 -5266
- package/THIRD-PARTY-PYTHON-linux.md +174 -0
- package/THIRD-PARTY-PYTHON.md +176 -162
- package/THIRD-PARTY.md +323 -316
- package/apps/desktop/quotes.txt +56 -56
- package/bus/core.py +677 -671
- package/bus/loaders/channel_loader.py +64 -64
- package/bus/loaders/provider_loader.py +4 -7
- package/bus/loaders/skill_loader.py +46 -27
- package/bus/loaders/skill_md.py +9 -9
- package/bus/mcp_disabled.py +4 -6
- package/bus/quarantine.py +10 -13
- package/bus/registry.py +2315 -2284
- package/bus/skill_state.py +124 -124
- package/channels/cli_channel/handler.py +3 -3
- package/channels/cli_channel/manifest.yaml +5 -5
- package/channels/dingtalk_channel/handler.py +32 -32
- package/channels/dingtalk_channel/manifest.yaml +12 -12
- package/channels/feishu_channel/handler.py +33 -33
- package/channels/feishu_channel/manifest.yaml +12 -12
- package/channels/qq_bot_channel/__init__.py +1 -1
- package/channels/qq_bot_channel/handler.py +24 -24
- package/channels/qq_bot_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/__init__.py +1 -1
- package/channels/telegram_channel/handler.py +21 -21
- package/channels/telegram_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/media.py +231 -231
- package/channels/textfmt.py +58 -58
- package/channels/wechat_channel/__init__.py +1 -1
- package/channels/wechat_channel/converter.py +1 -1
- package/channels/wechat_channel/handler.py +8 -8
- package/channels/wechat_channel/manifest.yaml +5 -5
- package/channels/wechat_channel/media.py +178 -178
- package/core/activity.py +753 -709
- package/core/agent_loop.py +7673 -7522
- package/core/allowlist.py +2 -3
- package/core/approval.py +34 -24
- package/core/approval_timeout.py +256 -228
- package/core/artifacts.py +3 -3
- package/core/attachment_gc.py +21 -0
- package/core/auto_review.py +2 -2
- package/core/browser/cdp.py +5 -2
- package/core/browser/discover.py +55 -19
- package/core/browser/session.py +4 -4
- package/core/cache_break_detector.py +97 -0
- package/core/cache_breakpoints.py +103 -0
- package/core/cache_policies.py +255 -0
- package/core/cancellation.py +3 -3
- package/core/channel_configs.py +3 -3
- package/core/channel_turns.py +13 -13
- package/core/child_approval.py +2 -3
- package/core/code_intel.py +11 -11
- package/core/command_policy.py +13 -7
- package/core/computer/annotate.py +231 -11
- package/core/computer/capture.py +140 -1
- package/core/computer/guard.py +7 -4
- package/core/computer/input.py +452 -26
- package/core/computer/session.py +563 -381
- package/core/computer/tools.py +2170 -928
- package/core/computer/uia.py +100 -1
- package/core/computer/watch.py +1 -1
- package/core/computer/win32.py +302 -7
- package/core/config_requirements.py +205 -205
- package/core/cron/runner.py +4 -4
- package/core/daily_log.py +2 -2
- package/core/dedup.py +2 -2
- package/core/egress_channels.py +326 -0
- package/core/egress_gate.py +96 -8
- package/core/egress_preapproved.py +59 -3
- package/core/endpoint.py +141 -141
- package/core/events.py +17 -8
- package/core/extension.py +2 -2
- package/core/file_history.py +10 -10
- package/core/file_tools.py +3 -3
- package/core/github_config.py +1 -1
- package/core/group_digest.py +3 -4
- package/core/group_minutes.py +5 -5
- package/core/group_reply.py +24 -0
- package/core/groups.py +5 -9
- package/core/hooks.py +15 -15
- package/core/i18n.py +2 -2
- package/core/ice/canary.py +3 -3
- package/core/ice/net_heuristics.py +2 -2
- package/core/im_routing.py +2 -2
- package/core/image_input.py +183 -43
- package/core/inbound.py +3 -3
- package/core/jobs.py +6 -6
- package/core/last_good.py +150 -150
- package/core/leaf_md.py +3 -3
- package/core/llm_errors.py +36 -27
- package/core/mail_config.py +2 -2
- package/core/memory/compressor.py +8 -8
- package/core/memory/manager.py +30 -45
- package/core/memory/session_memory.py +1 -2
- package/core/memory/short_term.py +4 -4
- package/core/memory_extract.py +1 -1
- package/core/memory_organize.py +8 -8
- package/core/memory_store.py +7 -9
- package/core/memory_transfer.py +2 -2
- package/core/model_capabilities.py +2 -2
- package/core/model_configs.py +219 -68
- package/core/model_profiles.py +333 -0
- package/core/modes.py +12 -11
- package/core/net_proxy.py +3 -3
- package/core/pipeline/scheduler.py +48 -43
- package/core/pipeline/stage.py +3 -0
- package/core/pipeline/stages/agent_loop.py +36 -15
- package/core/pipeline/stages/group_reply.py +22 -20
- package/core/pipeline/stages/post_process.py +7 -7
- package/core/pipeline/stages/pre_process.py +360 -68
- package/core/prompt_assembler.py +13 -4
- package/core/recycle.py +227 -16
- package/core/response_language.py +1 -1
- package/core/retention.py +2 -2
- package/core/rg.py +4 -3
- package/core/security.py +26 -8
- package/core/services.py +8 -8
- package/core/session_model.py +3 -5
- package/core/session_pool.py +35 -5
- package/core/session_recap.py +40 -3
- package/core/session_workspace.py +2 -3
- package/core/settings_baseline.py +2 -2
- package/core/settings_transfer.py +25 -1
- package/core/shell.py +52 -20
- package/core/side_call.py +3 -3
- package/core/skill_config.py +164 -0
- package/core/skill_factory.py +2 -2
- package/core/skill_guidance.py +2 -4
- package/core/skill_index.py +3 -4
- package/core/skill_settings.py +1 -1
- package/core/skill_sources.py +7 -7
- package/core/ssh_config.py +129 -0
- package/core/state_registry.py +67 -5
- package/core/subagent.py +28 -5
- package/core/subagent_defs.py +3 -3
- package/core/summarizer.py +4 -5
- package/core/tasks_notify.py +6 -6
- package/core/tiers.py +2 -2
- package/core/todos.py +1 -1
- package/core/token_calibrator.py +1 -4
- package/core/tool_outcome.py +108 -108
- package/core/touched_files.py +1 -1
- package/core/trace.py +12 -3
- package/core/unlock.py +4 -4
- package/core/update_tui.py +184 -158
- package/core/updater.py +5 -3
- package/core/version.py +14 -14
- package/core/vision_budget.py +235 -0
- package/core/web_cache.py +152 -152
- package/core/web_request.py +474 -0
- package/core/window_estimate.py +1 -1
- package/core/workspace.py +56 -26
- package/crannia_tray.py +278 -278
- package/licenses/GPL-3.0.txt +619 -619
- package/licenses/LGPL-2.1.txt +502 -502
- package/licenses/LGPL-3.0.txt +165 -165
- package/licenses/MIT-chat-on-wechat.txt +18 -18
- package/licenses/MIT-deepseek-harness.txt +21 -21
- package/licenses/Molio-LICENSE.txt +44 -44
- package/locales/en.json +1876 -1755
- package/main.py +154 -154
- package/mcpx/client.py +12 -1
- package/mcpx/manager.py +530 -522
- package/mcpx/servers/web_search.py +5 -13
- package/package.json +15 -23
- package/providers/anthropic/client.py +35 -33
- package/providers/base.py +13 -13
- package/providers/cache_policies.json +294 -0
- package/providers/cost_table.json +3779 -3779
- package/providers/lmstudio/client.py +2 -2
- package/providers/model_capabilities.json +6665 -6665
- package/providers/model_profiles.json +629 -0
- package/providers/ollama/client.py +2 -2
- package/providers/openai_compat.py +37 -16
- package/providers/openrouter/client.py +2 -2
- package/providers/qwen/__init__.py +1 -1
- package/providers/qwen/client.py +2 -2
- package/providers/qwen/manifest.yaml +16 -16
- package/providers/rate_limiter.py +2 -2
- package/providers/siliconflow/client.py +2 -2
- package/providers/validation.py +171 -171
- package/providers/vision_profiles.json +89 -0
- package/providers/window_table.json +8909 -8909
- package/requirements.txt +59 -51
- package/sbom-linux-x64.json +4580 -0
- package/sbom.json +4600 -4413
- package/skills/diagram/SKILL.md +47 -0
- package/skills/diagram/__init__.py +1 -0
- package/skills/diagram/handler.py +294 -0
- package/skills/diagram/layout.py +174 -0
- package/skills/diagram/manifest.yaml +106 -0
- package/skills/diagram/mermaid.py +170 -0
- package/skills/diagram/svg.py +223 -0
- package/skills/entertainment/SKILL.md +35 -35
- package/skills/entertainment/__init__.py +1 -1
- package/skills/entertainment/handler.py +91 -91
- package/skills/entertainment/manifest.yaml +26 -26
- package/skills/file_parser/GUIDANCE.md +10 -10
- package/skills/file_parser/handler.py +33 -11
- package/skills/github/SKILL.md +32 -32
- package/skills/github/__init__.py +1 -1
- package/skills/mail_parser/SKILL.md +68 -68
- package/skills/mail_parser/__init__.py +1 -1
- package/skills/mail_parser/handler.py +1 -1
- package/skills/media_gen/GUIDANCE.md +19 -19
- package/skills/media_gen/SKILL.md +43 -43
- package/skills/media_gen/__init__.py +1 -1
- package/skills/media_gen/handler.py +1 -1
- package/skills/media_gen/manifest.yaml +93 -93
- package/skills/netops/SKILL.md +45 -0
- package/skills/netops/__init__.py +1 -0
- package/skills/netops/handler.py +418 -0
- package/skills/netops/manifest.yaml +118 -0
- package/skills/office_parser/_excel_io.py +3 -3
- package/skills/office_parser/handler.py +2 -2
- package/skills/office_parser/ppt_tools.py +1 -1
- package/skills/office_parser/pptx_export/console_encoding.py +27 -27
- package/skills/office_parser/pptx_export/resource_paths.py +88 -88
- package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
- package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
- package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
- package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
- package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
- package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
- package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/utils.py +40 -21
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
- package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
- package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
- package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
- package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
- package/skills/office_parser/references/layout_library.md +816 -816
- package/skills/office_parser/references/ppt-master/LICENSE +21 -21
- package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
- package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
- package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
- package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
- package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
- package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
- package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
- package/skills/office_parser/references/spec_lock.md +235 -235
- package/skills/office_parser/soffice.py +68 -68
- package/skills/office_parser/word_tools.py +3 -3
- package/skills/ssh/SKILL.md +81 -0
- package/skills/ssh/__init__.py +1 -0
- package/skills/ssh/handler.py +609 -0
- package/skills/ssh/manifest.yaml +182 -0
- package/tui/crannia.cmd +134 -134
- package/tui/crannia.sh +82 -0
- package/tui/crannia_tui/__init__.py +1 -1
- package/tui/crannia_tui/app.py +240 -17
- package/tui/crannia_tui/app.tcss +21 -0
- package/tui/crannia_tui/clipboard.py +78 -10
- package/tui/crannia_tui/commands.py +37 -0
- package/tui/crannia_tui/events.py +6 -0
- package/tui/crannia_tui/i18n.py +164 -164
- package/tui/crannia_tui/locales/en.json +31 -6
- package/tui/crannia_tui/paths.py +4 -1
- package/tui/crannia_tui/profile.py +178 -169
- package/tui/crannia_tui/settings.py +134 -134
- package/tui/crannia_tui/setup.py +44 -5
- package/tui/crannia_tui/ui.py +156 -16
- package/tui/crannia_tui/update.py +393 -389
- package/vendor/ripgrep/COPYING.txt +3 -3
- package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
- package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
- package/vendor/ripgrep/README.md +30 -14
- package/vendor/ripgrep/UNLICENSE.txt +24 -24
- package/vendor/ripgrep/linux-x64/rg +0 -0
- package/vendor/ripgrep/package-source.json +15 -16
- package/web/__main__.py +12 -15
- package/web/server.py +8481 -8594
- package/web/static/img/channel-telegram.svg +1 -1
- package/web/static/img/channel-wechat.svg +1 -1
- package/web/templates/logs.html +49 -49
- package/web/templates/models.html +46 -46
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"""模型能力差异表 —— 能不能调工具、参数禁区、思考预算、wire 兼容位。
|
|
2
|
+
|
|
3
|
+
## 它不管什么
|
|
4
|
+
|
|
5
|
+
上下文窗口与单次输出上限仍由 `window_estimate.py` 决议,缓存与图预算各有自己的表。
|
|
6
|
+
这里只装"同一家 provider 下不同模型不一样、而代码不该写 if 判断"的那些格
|
|
7
|
+
(抄成熟平台的做法:一字段一能力、静态表 + 显式覆盖 + 回落)。
|
|
8
|
+
|
|
9
|
+
## 回落顺序
|
|
10
|
+
|
|
11
|
+
模型名(最长优先的包含匹配)→ provider 的 `_default` → 全局 `_default`。
|
|
12
|
+
`unknown` 是有意义的取值:它表示"查不到",不等于 `false`。
|
|
13
|
+
调用方遇到 `unknown` 必须走 `on_unsupported` 里那条路线,不许当 False 直接用。
|
|
14
|
+
|
|
15
|
+
## 不写回
|
|
16
|
+
|
|
17
|
+
没有"从 usage / 错误反推然后写回表里"的逻辑:
|
|
18
|
+
静态表由生成脚本或人工维护,运行时只做一次性自适应。
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
import threading
|
|
25
|
+
from dataclasses import dataclass, field
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
_LOCK = threading.RLock()
|
|
29
|
+
#: 路径 -> (mtime, 解析后的 dict)。模块级可变,登记在 core/state_registry.py。
|
|
30
|
+
_CACHE: dict[str, tuple[float, dict]] = {}
|
|
31
|
+
|
|
32
|
+
#: 字段类型:真布尔、未知、缺省。字符串形式的 true/false 一律不认(防手滑)。
|
|
33
|
+
_UNKNOWN = object()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _table_path() -> Path:
|
|
37
|
+
from core import paths
|
|
38
|
+
return Path(paths.asset_dir("providers")) / "model_profiles.json"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _read_table() -> dict:
|
|
42
|
+
try:
|
|
43
|
+
mtime = _table_path().stat().st_mtime
|
|
44
|
+
except Exception: # noqa: BLE001
|
|
45
|
+
return {}
|
|
46
|
+
with _LOCK:
|
|
47
|
+
hit = _CACHE.get(str(_table_path()))
|
|
48
|
+
if hit is not None and hit[0] == mtime:
|
|
49
|
+
return hit[1]
|
|
50
|
+
try:
|
|
51
|
+
data = json.loads(_table_path().read_text(encoding="utf-8"))
|
|
52
|
+
except Exception: # noqa: BLE001
|
|
53
|
+
with _LOCK:
|
|
54
|
+
hit = _CACHE.get(str(_table_path()))
|
|
55
|
+
return hit[1] if hit is not None else {}
|
|
56
|
+
if not isinstance(data, dict):
|
|
57
|
+
return {}
|
|
58
|
+
with _LOCK:
|
|
59
|
+
_CACHE[str(_table_path())] = (mtime, data)
|
|
60
|
+
return data
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _tri(value) -> bool | None:
|
|
64
|
+
"""表里的一格:True / False / None(unknown)。不把字符串当布尔。"""
|
|
65
|
+
if value is True:
|
|
66
|
+
return True
|
|
67
|
+
if value is False:
|
|
68
|
+
return False
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _text(value, default: str = "") -> str:
|
|
73
|
+
return str(value) if isinstance(value, str) and value else default
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _bounded_int(value, default: int = 0, high: int = 10_000_000) -> int:
|
|
77
|
+
try:
|
|
78
|
+
n = int(value)
|
|
79
|
+
except (TypeError, ValueError):
|
|
80
|
+
return default
|
|
81
|
+
return n if 0 <= n <= high else default
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _merge(base: dict, override: dict) -> dict:
|
|
85
|
+
"""逐字段覆盖:dict 递归合并,其它类型直接替换。"""
|
|
86
|
+
out = dict(base)
|
|
87
|
+
for key, value in (override or {}).items():
|
|
88
|
+
if isinstance(value, dict) and isinstance(out.get(key), dict):
|
|
89
|
+
out[key] = _merge(out[key], value)
|
|
90
|
+
else:
|
|
91
|
+
out[key] = value
|
|
92
|
+
return out
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(frozen=True)
|
|
96
|
+
class ModelProfile:
|
|
97
|
+
"""一个 (provider, model) 的能力画像。字段与表一一对应。"""
|
|
98
|
+
|
|
99
|
+
provider: str
|
|
100
|
+
model: str
|
|
101
|
+
tool_call: bool | None
|
|
102
|
+
parallel_tool_call: bool | None
|
|
103
|
+
response_schema: bool | None
|
|
104
|
+
system_message: bool | None
|
|
105
|
+
thinking: dict
|
|
106
|
+
parameters: dict
|
|
107
|
+
compat: dict
|
|
108
|
+
aliases: tuple[str, ...]
|
|
109
|
+
deprecated: bool
|
|
110
|
+
status: str
|
|
111
|
+
on_unsupported: dict
|
|
112
|
+
source: str
|
|
113
|
+
matched: str = ""
|
|
114
|
+
|
|
115
|
+
def can(self, key: str) -> bool | None:
|
|
116
|
+
"""某一能力:True / False / None(查不到)。"""
|
|
117
|
+
return _tri(getattr(self, key, None))
|
|
118
|
+
|
|
119
|
+
def parameter(self, name: str) -> bool | None:
|
|
120
|
+
return _tri(self.parameters.get(name))
|
|
121
|
+
|
|
122
|
+
def compat_of(self, name: str) -> str:
|
|
123
|
+
return _text(self.compat.get(name))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def resolve(provider: str = "", model: str = "") -> ModelProfile:
|
|
127
|
+
"""按模型 → provider 默认 → 全局默认取一份能力画像。不抛异常。"""
|
|
128
|
+
table = _read_table()
|
|
129
|
+
global_default = table.get("_default")
|
|
130
|
+
if not isinstance(global_default, dict):
|
|
131
|
+
global_default = {}
|
|
132
|
+
|
|
133
|
+
prov = str(provider or "")
|
|
134
|
+
model = str(model or "")
|
|
135
|
+
providers = table.get("providers")
|
|
136
|
+
provider_row = providers.get(prov) if isinstance(providers, dict) else None
|
|
137
|
+
if not isinstance(provider_row, dict):
|
|
138
|
+
provider_row = {}
|
|
139
|
+
|
|
140
|
+
# 模型级匹配:先精确,再按名字长度降序做包含匹配。长的快照名先命中。
|
|
141
|
+
model_row: dict = {}
|
|
142
|
+
matched = ""
|
|
143
|
+
models = provider_row.get("models")
|
|
144
|
+
if isinstance(models, dict) and model:
|
|
145
|
+
keys = sorted((str(k) for k in models), key=len, reverse=True)
|
|
146
|
+
low = model.lower()
|
|
147
|
+
exact = next((k for k in keys if k.lower() == low), "")
|
|
148
|
+
hit = exact or next((k for k in keys if k.lower() in low), "")
|
|
149
|
+
if hit and isinstance(models[hit], dict):
|
|
150
|
+
model_row = models[hit]
|
|
151
|
+
matched = hit
|
|
152
|
+
|
|
153
|
+
provider_default = provider_row.get("_default")
|
|
154
|
+
if not isinstance(provider_default, dict):
|
|
155
|
+
provider_default = {}
|
|
156
|
+
|
|
157
|
+
row = _merge(_merge(_merge(global_default, provider_default), model_row), {})
|
|
158
|
+
thinking = row.get("thinking")
|
|
159
|
+
parameters = row.get("parameters")
|
|
160
|
+
compat = row.get("compat")
|
|
161
|
+
on_unsupported = row.get("on_unsupported")
|
|
162
|
+
|
|
163
|
+
return ModelProfile(
|
|
164
|
+
provider=prov,
|
|
165
|
+
model=model,
|
|
166
|
+
tool_call=_tri(row.get("tool_call")),
|
|
167
|
+
parallel_tool_call=_tri(row.get("parallel_tool_call")),
|
|
168
|
+
response_schema=_tri(row.get("response_schema")),
|
|
169
|
+
system_message=_tri(row.get("system_message")),
|
|
170
|
+
thinking=thinking if isinstance(thinking, dict) else {},
|
|
171
|
+
parameters=parameters if isinstance(parameters, dict) else {},
|
|
172
|
+
compat=compat if isinstance(compat, dict) else {},
|
|
173
|
+
aliases=tuple(str(a) for a in row.get("aliases", ()) if isinstance(a, str)),
|
|
174
|
+
deprecated=row.get("deprecated") is True,
|
|
175
|
+
status=_text(row.get("status"), "unknown"),
|
|
176
|
+
on_unsupported=on_unsupported if isinstance(on_unsupported, dict) else {},
|
|
177
|
+
source="providers/model_profiles.json",
|
|
178
|
+
matched=matched,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def reset_cache() -> None:
|
|
183
|
+
"""只给测试用:表被改写后强制重读。"""
|
|
184
|
+
with _LOCK:
|
|
185
|
+
_CACHE.clear()
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# --- 消费点:画像要真的影响请求,不能只躺在表里 -------------------------
|
|
189
|
+
|
|
190
|
+
def accepts_tools(provider: str, model: str) -> bool:
|
|
191
|
+
"""能不能给这一家发工具表。
|
|
192
|
+
|
|
193
|
+
只有画像明确说 false 才不发。查不到(unknown)时照旧发 ——
|
|
194
|
+
用户自建的中转 / 自定义模型大多不支持能力查询,一上来就清空工具表
|
|
195
|
+
等于把今天能用的模型全弄坏。
|
|
196
|
+
|
|
197
|
+
`on_unsupported.tool_call=error` 管的是另一件事:模型报出一个没下发给它
|
|
198
|
+
的工具名时执行侧要拒绝,而不是"不发工具"。那道闸在执行侧,不在这里。
|
|
199
|
+
"""
|
|
200
|
+
got = resolve(provider, model).can("tool_call")
|
|
201
|
+
return True if got is None else got
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def rejects_unknown_tool(provider: str, model: str) -> bool:
|
|
205
|
+
"""幻觉出一个没下发给它的工具名时,要不要拒绝执行。
|
|
206
|
+
|
|
207
|
+
接管类工具在能力未知时也拒绝(表里的默认策略是 error);
|
|
208
|
+
这是执行侧的闸,与"发不发工具表"分开。
|
|
209
|
+
"""
|
|
210
|
+
profile = resolve(provider, model)
|
|
211
|
+
if profile.can("tool_call") is False:
|
|
212
|
+
return True
|
|
213
|
+
return profile.on_unsupported.get("tool_call") == "error"
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def accepts_parameter(provider: str, model: str, name: str) -> bool:
|
|
217
|
+
"""某个采样参数该不该发。没写就按 on_unsupported.parameter 处理。"""
|
|
218
|
+
profile = resolve(provider, model)
|
|
219
|
+
got = profile.parameter(name)
|
|
220
|
+
if got is not None:
|
|
221
|
+
return got
|
|
222
|
+
return profile.on_unsupported.get("parameter") != "drop"
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def wire_field(provider: str, model: str, field: str, fallback: str = "") -> str:
|
|
226
|
+
"""按画像取 wire 字段名(reasoning_field / max_tokens_field / cache_format)。"""
|
|
227
|
+
got = resolve(provider, model).compat_of(field)
|
|
228
|
+
return got or fallback
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def reports_finish_reason(provider: str, model: str) -> bool:
|
|
232
|
+
"""这一家会不会在响应里给结束信号。
|
|
233
|
+
|
|
234
|
+
只有明确会报的才把"没收到结束信号"当半截流 —— 对不报的那批,
|
|
235
|
+
"读不到"就是读不到,不是断(读不到 ≠ 0 的同族判据)。
|
|
236
|
+
"""
|
|
237
|
+
value = resolve(provider, model).compat.get("reports_finish_reason")
|
|
238
|
+
return value is True
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def filter_request_params(params: dict, provider: str, model: str) -> dict:
|
|
242
|
+
"""按画像删掉目标模型禁发的采样参数,修正输出上限的字段名。
|
|
243
|
+
|
|
244
|
+
只删不改:画像说禁的参数一律不发(发了不生效或 400 的都有),
|
|
245
|
+
画像没表态的保持原样。max_tokens 字段名只在画像明确给出另一个名字时换,
|
|
246
|
+
不靠模型名猜 —— 猜错比不发更糟。
|
|
247
|
+
"""
|
|
248
|
+
out = dict(params)
|
|
249
|
+
profile = resolve(provider, model)
|
|
250
|
+
for key in ("temperature", "top_p", "top_k", "frequency_penalty",
|
|
251
|
+
"presence_penalty", "stop", "stop_sequences"):
|
|
252
|
+
if key in out and profile.parameter(key) is False:
|
|
253
|
+
out.pop(key)
|
|
254
|
+
field = profile.compat_of("max_tokens_field")
|
|
255
|
+
if field and field != "max_tokens" and "max_tokens" in out:
|
|
256
|
+
out[field] = out.pop("max_tokens")
|
|
257
|
+
return out
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def sanitize_for_wire(messages: list[dict], provider: str, model: str) -> list[dict]:
|
|
261
|
+
"""按目标模型清洗历史副本,只改副本、不动调用方那份(它还要落库)。
|
|
262
|
+
|
|
263
|
+
三件事,都是跨模型切换会踩到的:
|
|
264
|
+
|
|
265
|
+
- 目标不收思考字段时剥掉 assistant 的 `reasoning_content`。
|
|
266
|
+
上一家的思考留在库里是对的(那是当时的记录),发给不认它的下一家才是错。
|
|
267
|
+
- 空的 assistant 补一个空格。严格网关拒空 content,而这一位有时还要
|
|
268
|
+
用来对齐 thinking 签名,填空串比整条删掉安全。
|
|
269
|
+
- tool 调用后面缺结果时补一条可见的错误结果,避免悬空的 tool_use
|
|
270
|
+
让上游 400。
|
|
271
|
+
|
|
272
|
+
幂等:同一份输入跑两次结果相同;没有需要改的地方就原样返回入参。
|
|
273
|
+
"""
|
|
274
|
+
profile = resolve(provider, model)
|
|
275
|
+
# 历史里的字段名固定叫 `reasoning_content`(我们写入时就是这个名字)。
|
|
276
|
+
# 只有当目标模型也认这个名字时才留着;改成别的名字或根本不收时剥掉 ——
|
|
277
|
+
# 改写字段名等于把上一家的思考当成这一家的思考,那是伪造。
|
|
278
|
+
keep_reasoning = profile.compat_of("reasoning_field") == "reasoning_content"
|
|
279
|
+
out: list[dict] | None = None
|
|
280
|
+
|
|
281
|
+
def _writable() -> list[dict]:
|
|
282
|
+
nonlocal out
|
|
283
|
+
if out is None:
|
|
284
|
+
# 必须与原列表等长:下面按原下标回写,过滤掉非 dict 元素会让
|
|
285
|
+
# 下标整体前移,改到错误的条目上(坏历史里真的会这样)。
|
|
286
|
+
out = [dict(m) if isinstance(m, dict) else m for m in messages]
|
|
287
|
+
return out
|
|
288
|
+
|
|
289
|
+
for i, msg in enumerate(messages):
|
|
290
|
+
if not isinstance(msg, dict):
|
|
291
|
+
continue
|
|
292
|
+
role = msg.get("role")
|
|
293
|
+
if role == "assistant" and not keep_reasoning and "reasoning_content" in msg:
|
|
294
|
+
_writable()[i].pop("reasoning_content", None)
|
|
295
|
+
if role == "assistant":
|
|
296
|
+
content = msg.get("content")
|
|
297
|
+
if content == "" or content == []:
|
|
298
|
+
_writable()[i]["content"] = " "
|
|
299
|
+
|
|
300
|
+
# 悬空 tool_use:assistant 报了调用、后面却没有对应 tool 结果。
|
|
301
|
+
# 只在本副本里补;落库那份保持原样,便于事后看出是哪一轮漏了。
|
|
302
|
+
# 记下每条挂起调用由哪条 assistant 声明 —— 占位结果必须紧跟在它后面
|
|
303
|
+
# (OpenAI 兼容与 Anthropic 都要求 tool 结果直接跟随那个 tool_call 轮;
|
|
304
|
+
# 一律追加到列表末尾在"后面还有别的消息"时会被上游拒)。
|
|
305
|
+
pending: dict[str, int] = {}
|
|
306
|
+
for i, msg in enumerate(messages):
|
|
307
|
+
if not isinstance(msg, dict):
|
|
308
|
+
continue
|
|
309
|
+
role = msg.get("role")
|
|
310
|
+
if role == "assistant":
|
|
311
|
+
calls = msg.get("tool_calls")
|
|
312
|
+
if isinstance(calls, (list, tuple)):
|
|
313
|
+
for tc in calls:
|
|
314
|
+
if isinstance(tc, dict) and tc.get("id"):
|
|
315
|
+
pending[str(tc["id"])] = i
|
|
316
|
+
elif role == "tool":
|
|
317
|
+
cid = msg.get("tool_call_id")
|
|
318
|
+
if cid:
|
|
319
|
+
pending.pop(str(cid), None)
|
|
320
|
+
if pending:
|
|
321
|
+
target = _writable()
|
|
322
|
+
by_msg: dict[int, list[str]] = {}
|
|
323
|
+
for cid, idx in pending.items():
|
|
324
|
+
by_msg.setdefault(idx, []).append(cid)
|
|
325
|
+
# 从后往前插:同一轮的多条按 id 排序,用切片一次插入保持顺序。
|
|
326
|
+
for idx in sorted(by_msg, reverse=True):
|
|
327
|
+
block = [{"role": "tool", "tool_call_id": cid,
|
|
328
|
+
"content": "(这一条工具结果在会话里缺失,已补占位)"}
|
|
329
|
+
for cid in sorted(by_msg[idx])]
|
|
330
|
+
target[idx + 1:idx + 1] = block
|
|
331
|
+
out = target
|
|
332
|
+
|
|
333
|
+
return out if out is not None else list(messages)
|
package/core/modes.py
CHANGED
|
@@ -208,15 +208,14 @@ def configured_mode() -> str:
|
|
|
208
208
|
# 判据与设置页那条 400 同源(`is_default_allowed`)——
|
|
209
209
|
# 两处各写一份"哪些能当默认",迟早分叉。
|
|
210
210
|
if not is_default_allowed(key):
|
|
211
|
-
print("[mode]
|
|
212
|
-
|
|
213
|
-
DEFAULT_MODE))
|
|
211
|
+
print("[mode] configured %s=%r not allowed as default - running %s this round"
|
|
212
|
+
% (SETTING_KEY, value, DEFAULT_MODE))
|
|
214
213
|
return DEFAULT_MODE
|
|
215
214
|
return key
|
|
216
215
|
except ModeUnsupported:
|
|
217
216
|
# 值不认识 —— 这是"读到了但做不到"的设置层版本。不抛:
|
|
218
217
|
# 一条坏设置不该让整轮对话失败(与档位那条不同,见上面 docstring)。
|
|
219
|
-
print("[mode]
|
|
218
|
+
print("[mode] configured %s=%r unknown - running %s this round"
|
|
220
219
|
% (SETTING_KEY, value, DEFAULT_MODE))
|
|
221
220
|
return DEFAULT_MODE
|
|
222
221
|
|
|
@@ -255,7 +254,7 @@ def current_mode(session_id: str = "") -> str:
|
|
|
255
254
|
if mode is None:
|
|
256
255
|
mode = configured_mode()
|
|
257
256
|
_frozen[key] = mode
|
|
258
|
-
print("[mode]
|
|
257
|
+
print("[mode] interaction mode = %s (%s) - frozen for this session"
|
|
259
258
|
% (mode, MODE_NAMES.get(mode, mode)))
|
|
260
259
|
return mode
|
|
261
260
|
|
|
@@ -289,7 +288,7 @@ def set_mode(session_id: str, key: str) -> str:
|
|
|
289
288
|
if not is_implemented(key):
|
|
290
289
|
raise ModeUnsupported(
|
|
291
290
|
tr("「%s」这一档暂不可用,其他档位不受影响。")
|
|
292
|
-
% MODE_NAMES.get(key, key))
|
|
291
|
+
% tr(MODE_NAMES.get(key, key)))
|
|
293
292
|
sid = session_id or ""
|
|
294
293
|
# 群聊只有自动这一档。
|
|
295
294
|
# `auto` 本身是幂等的 —— 返回一句实话,不报错(免得"设成它已经在的那个"也崩)。
|
|
@@ -297,7 +296,7 @@ def set_mode(session_id: str, key: str) -> str:
|
|
|
297
296
|
if key != "auto":
|
|
298
297
|
raise ModeUnsupported(
|
|
299
298
|
tr("群聊固定为「自动」模式,不能切到「%s」。")
|
|
300
|
-
% MODE_NAMES.get(key, key))
|
|
299
|
+
% tr(MODE_NAMES.get(key, key)))
|
|
301
300
|
return tr("群聊固定为「自动」模式,无需切换。")
|
|
302
301
|
with _freeze_lock:
|
|
303
302
|
before = _frozen.get(sid)
|
|
@@ -310,9 +309,9 @@ def set_mode(session_id: str, key: str) -> str:
|
|
|
310
309
|
try:
|
|
311
310
|
from core.computer import session as _computer_session
|
|
312
311
|
if _computer_session.disable_for_session(sid, "mode=%s" % key):
|
|
313
|
-
print("[computer]
|
|
312
|
+
print("[computer] mode switched to %s => takeover stopped" % key)
|
|
314
313
|
except Exception as exc: # noqa: BLE001
|
|
315
|
-
print("[computer]
|
|
314
|
+
print("[computer] stop takeover failed (mode switch continues): %s: %s"
|
|
316
315
|
% (type(exc).__name__, exc))
|
|
317
316
|
# 进入 `plan` 时记下从哪来(记下进入之前的那一档)。
|
|
318
317
|
#
|
|
@@ -330,11 +329,13 @@ def set_mode(session_id: str, key: str) -> str:
|
|
|
330
329
|
from core.plan import remember_previous_mode
|
|
331
330
|
remember_previous_mode(sid, before or configured_mode())
|
|
332
331
|
except Exception as exc: # noqa: BLE001
|
|
333
|
-
print("[mode]
|
|
332
|
+
print("[mode] remember previous_mode failed (falls back to default on exit): %s" % exc)
|
|
334
333
|
if key == "full_access":
|
|
335
334
|
return (tr("已切到「完全权限」。本次对话内审批不再询问;出网命令和受保护路径仍会拦截,批量删除仍会确认一次。"))
|
|
335
|
+
#: 括号里的模式名也要过一遍 `tr` —— 整句翻译了、参数还是中文,
|
|
336
|
+
#: 英文界面里就成了「Switched to '手动'」。
|
|
336
337
|
return (tr("已切到「%s」,只对当前对话生效,下一条消息起算。")
|
|
337
|
-
% MODE_NAMES.get(key, key))
|
|
338
|
+
% tr(MODE_NAMES.get(key, key)))
|
|
338
339
|
|
|
339
340
|
|
|
340
341
|
def reset_mode_cache(session_id: Optional[str] = None) -> None:
|
package/core/net_proxy.py
CHANGED
|
@@ -406,9 +406,9 @@ def warn_if_socks_unsupported() -> None:
|
|
|
406
406
|
只提醒一次(每次出网都打一行就是噪声)。
|
|
407
407
|
"""
|
|
408
408
|
if _socks_env_without_pysocks():
|
|
409
|
-
print("[net_proxy]
|
|
410
|
-
"requests
|
|
411
|
-
"
|
|
409
|
+
print("[net_proxy] environment specifies a SOCKS proxy but PySocks is not installed => "
|
|
410
|
+
"requests calls will fail with Missing dependencies for SOCKS support. "
|
|
411
|
+
"Install it: pip install PySocks (or use an http:// proxy address).")
|
|
412
412
|
|
|
413
413
|
|
|
414
414
|
def requests_proxies() -> dict | None:
|