@hfyjq/crannia 1.0.0 → 1.1.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 +45 -45
- package/THIRD-PARTY-FRONTEND.md +5266 -5266
- package/THIRD-PARTY-PYTHON.md +162 -153
- package/THIRD-PARTY.md +316 -316
- package/apps/desktop/quotes.txt +56 -56
- package/bus/core.py +671 -671
- package/bus/loaders/channel_loader.py +64 -64
- package/bus/loaders/skill_md.py +676 -676
- package/bus/skill_state.py +124 -124
- package/channels/cli_channel/manifest.yaml +5 -5
- package/channels/dingtalk_channel/manifest.yaml +12 -12
- package/channels/feishu_channel/manifest.yaml +12 -12
- package/channels/qq_bot_channel/__init__.py +1 -1
- package/channels/qq_bot_channel/handler.py +881 -881
- package/channels/qq_bot_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/__init__.py +1 -1
- package/channels/telegram_channel/handler.py +813 -813
- 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/auth.py +23 -5
- package/channels/wechat_channel/manifest.yaml +5 -5
- package/channels/wechat_channel/media.py +178 -178
- package/config.yaml +2 -2
- package/core/activity.py +3 -0
- package/core/agent_loop.py +390 -55
- package/core/approval.py +17 -6
- package/core/artifacts.py +7 -0
- package/core/auto_review.py +23 -5
- package/core/channel_configs.py +34 -2
- package/core/channel_turns.py +759 -759
- package/core/child_approval.py +150 -0
- package/core/config_requirements.py +205 -0
- package/core/cron/runner.py +118 -6
- package/core/cron/store.py +14 -5
- package/core/cron/tools.py +17 -5
- package/core/endpoint.py +141 -0
- package/core/events.py +23 -0
- package/core/i18n.py +329 -329
- package/core/ice/store.py +191 -191
- package/core/inbound.py +193 -193
- package/core/jobs.py +19 -3
- package/core/last_good.py +150 -150
- package/core/llm_errors.py +227 -227
- package/core/llm_retry.py +230 -230
- package/core/memory/compressor.py +1214 -1214
- package/core/memory/manager.py +14 -0
- package/core/model_configs.py +80 -0
- package/core/pipeline/scheduler.py +2 -2
- package/core/pipeline/stages/agent_loop.py +24 -4
- package/core/pipeline/stages/pre_process.py +58 -7
- package/core/prompt_assembler.py +680 -680
- package/core/rg.py +255 -255
- package/core/security.py +1544 -1544
- package/core/settings_baseline.py +70 -1
- package/core/shell.py +5 -17
- package/core/skill_settings.py +7 -2
- package/core/state_registry.py +19 -0
- package/core/subagent.py +64 -3
- package/core/task_tool.py +1 -1
- package/core/tasks_notify.py +69 -4
- package/core/tiers.py +9 -3
- package/core/tool_outcome.py +108 -0
- package/core/update_tui.py +158 -0
- package/core/version.py +2 -2
- package/core/web_cache.py +152 -0
- package/crannia_tray.py +278 -278
- package/creators/models.json +4 -4
- package/data/settings.example.json +67 -0
- 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 +9 -4
- package/main.py +154 -154
- package/mcpx/manager.py +522 -522
- package/mcpx/servers/__init__.py +22 -22
- package/mcpx/servers/web_search.py +321 -33
- package/package.json +14 -9
- package/providers/anthropic/client.py +772 -772
- package/providers/cost_table.json +3779 -3779
- package/providers/deepseek/client.py +20 -20
- package/providers/deepseek/manifest.yaml +2 -2
- package/providers/factory.py +136 -136
- package/providers/lmstudio/client.py +2 -2
- package/providers/metadata.py +80 -80
- package/providers/model_capabilities.json +6665 -6665
- package/providers/moonshot/client.py +12 -12
- package/providers/ollama/client.py +2 -2
- package/providers/openai/client.py +13 -13
- 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 +144 -144
- package/providers/siliconflow/client.py +2 -2
- package/providers/validation.py +171 -171
- package/providers/window_table.json +8909 -8909
- package/sbom.json +4413 -4296
- 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 +177 -4
- package/skills/file_parser/manifest.yaml +22 -1
- package/skills/github/SKILL.md +32 -32
- package/skills/github/__init__.py +1 -1
- package/skills/github/manifest.yaml +5 -0
- package/skills/mail_parser/SKILL.md +68 -68
- package/skills/mail_parser/__init__.py +1 -1
- package/skills/mail_parser/handler.py +806 -806
- package/skills/mail_parser/manifest.yaml +5 -0
- 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 +430 -430
- package/skills/media_gen/manifest.yaml +93 -88
- package/skills/office_parser/cell_validation.py +127 -127
- package/skills/office_parser/excel_transform.py +936 -936
- package/skills/office_parser/layout_spec.py +243 -243
- 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/align_embed_images.py +575 -575
- package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
- package/skills/office_parser/pptx_export/svg_finalize/embed_icons.py +498 -498
- 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/elements.py +2490 -2490
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/styles.py +656 -656
- 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/media.py +141 -141
- 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 +2909 -2909
- package/tui/crannia.cmd +134 -0
- package/tui/crannia_tui/__init__.py +1 -0
- package/tui/crannia_tui/__main__.py +223 -0
- package/tui/crannia_tui/app.py +1318 -0
- package/tui/crannia_tui/app.tcss +153 -0
- package/tui/crannia_tui/approval.py +85 -0
- package/tui/crannia_tui/backend.py +279 -0
- package/tui/crannia_tui/channel.py +472 -0
- package/tui/crannia_tui/client.py +125 -0
- package/tui/crannia_tui/clipboard.py +62 -0
- package/tui/crannia_tui/commands.py +65 -0
- package/tui/crannia_tui/doctor.py +304 -0
- package/tui/crannia_tui/events.py +84 -0
- package/tui/crannia_tui/headless.py +152 -0
- package/tui/crannia_tui/i18n.py +164 -0
- package/tui/crannia_tui/locales/en.json +263 -0
- package/tui/crannia_tui/outcome.py +62 -0
- package/tui/crannia_tui/paths.py +181 -0
- package/tui/crannia_tui/probe.py +53 -0
- package/tui/crannia_tui/profile.py +169 -0
- package/tui/crannia_tui/render.py +209 -0
- package/tui/crannia_tui/settings.py +134 -0
- package/tui/crannia_tui/setup.py +380 -0
- package/tui/crannia_tui/term.py +116 -0
- package/tui/crannia_tui/ui.py +1236 -0
- package/tui/crannia_tui/update.py +389 -0
- 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 +51 -51
- package/vendor/ripgrep/UNLICENSE.txt +24 -24
- package/vendor/ripgrep/package-source.json +19 -19
- package/web/__main__.py +15 -0
- package/web/server.py +168 -19
- 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
package/core/memory/manager.py
CHANGED
|
@@ -797,6 +797,19 @@ class MemoryManager:
|
|
|
797
797
|
self.short_term.open_thread(channel_key, sid)
|
|
798
798
|
return sid
|
|
799
799
|
|
|
800
|
+
@staticmethod
|
|
801
|
+
def _announce_thread_opened(channel_key: str, storage_id: str) -> None:
|
|
802
|
+
"""名册里多了一条 —— 告诉前端来刷新(`thread.opened`)。
|
|
803
|
+
|
|
804
|
+
不抛:事件流坏了不该影响一段对话的创建。
|
|
805
|
+
"""
|
|
806
|
+
try:
|
|
807
|
+
from core.events import EVT_THREAD_OPENED, get_event_bus
|
|
808
|
+
get_event_bus().emit(EVT_THREAD_OPENED, session_key=channel_key,
|
|
809
|
+
storage_id=storage_id)
|
|
810
|
+
except Exception: # noqa: BLE001
|
|
811
|
+
pass
|
|
812
|
+
|
|
800
813
|
def new_session(
|
|
801
814
|
self, old_session_id: str = "", *, channel_key: str = ""
|
|
802
815
|
) -> Tuple[str, List[Dict]]:
|
|
@@ -889,6 +902,7 @@ class MemoryManager:
|
|
|
889
902
|
if old_session_id:
|
|
890
903
|
self.short_term.end_thread(old_session_id)
|
|
891
904
|
self.short_term.open_thread(channel_key, sid)
|
|
905
|
+
self._announce_thread_opened(channel_key, sid)
|
|
892
906
|
|
|
893
907
|
# 会话级内存态:走唯一登记表
|
|
894
908
|
#
|
package/core/model_configs.py
CHANGED
|
@@ -880,6 +880,86 @@ def _seed_from_config() -> dict | None:
|
|
|
880
880
|
# 给界面/端点的那一份(打码,判据 4)
|
|
881
881
|
# ----------------------------------------------------------------------
|
|
882
882
|
|
|
883
|
+
def card_defaults() -> list[dict]:
|
|
884
|
+
"""每张卡的默认值(首次引导 / 命令行用):id / 名称 / 目录 / 地址 / 默认模型。
|
|
885
|
+
|
|
886
|
+
读 provider 的 `manifest.yaml`,不联网。读不到就给空串 ——
|
|
887
|
+
引导那边会退化成"让用户自己填",而不是拿一张编出来的地址去试。
|
|
888
|
+
"""
|
|
889
|
+
import yaml
|
|
890
|
+
|
|
891
|
+
out: list[dict] = []
|
|
892
|
+
for cid, label, dirname in CARDS:
|
|
893
|
+
base, model = "", ""
|
|
894
|
+
try:
|
|
895
|
+
p = PROVIDERS_DIR / dirname / "manifest.yaml"
|
|
896
|
+
data = yaml.safe_load(p.read_text(encoding="utf-8")) or {}
|
|
897
|
+
cfg = data.get("config") or {}
|
|
898
|
+
base = str(cfg.get("base_url") or "")
|
|
899
|
+
model = str(cfg.get("default_model") or "")
|
|
900
|
+
except Exception: # noqa: BLE001
|
|
901
|
+
pass
|
|
902
|
+
out.append({"id": cid, "label": label, "provider": dirname,
|
|
903
|
+
"base_url": base, "default_model": model})
|
|
904
|
+
return out
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
def classify_probe_error(err: object) -> str:
|
|
908
|
+
"""联通测试失败 -> 该改哪一格的类别。
|
|
909
|
+
|
|
910
|
+
认证 / 余额 / 限流 / 地区 / 内容 / 请求 / 上游异常 / 连不上 / 超时
|
|
911
|
+
直接复用 `providers/base.py` 的那两张判据(全仓唯一一份);
|
|
912
|
+
这里只补它们不管的两类:
|
|
913
|
+
· `model` —— 模型名不对(报文里带 model 字样的 404);
|
|
914
|
+
· `address` —— 地址不对(404 但不像模型名)。
|
|
915
|
+
认不出给 `unknown` —— 不装成"网络问题"。
|
|
916
|
+
"""
|
|
917
|
+
from providers.base import classify_api_error, classify_transport_error
|
|
918
|
+
|
|
919
|
+
kind = classify_transport_error(err)
|
|
920
|
+
if kind:
|
|
921
|
+
return kind
|
|
922
|
+
kind = classify_api_error(err) or ""
|
|
923
|
+
if kind:
|
|
924
|
+
return kind
|
|
925
|
+
text = str(err or "").lower()
|
|
926
|
+
if "model" in text and any(w in text for w in (
|
|
927
|
+
"not found", "not_found", "does not exist", "invalid model",
|
|
928
|
+
"unknown model", "no such model")):
|
|
929
|
+
return "model"
|
|
930
|
+
if "404" in text or "not found" in text:
|
|
931
|
+
return "address"
|
|
932
|
+
return "unknown"
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
def probe(cid: str) -> tuple[bool, str, str]:
|
|
936
|
+
"""拿这条配置真发一次最小请求(首次引导的"联通测试")。
|
|
937
|
+
|
|
938
|
+
与 `preflight` 分工:那条只试装、不联网;这条联网。
|
|
939
|
+
超时由调用方控制(TUI 那边整段子进程有超时,见 `setup.py`)。
|
|
940
|
+
返回 `(通没通, 类别, 一句人话)`;类别是 `classify_probe_error` 的取值,
|
|
941
|
+
通了则为空串。
|
|
942
|
+
"""
|
|
943
|
+
why = preflight(cid)
|
|
944
|
+
if why:
|
|
945
|
+
return False, "install", why
|
|
946
|
+
entry = get(cid)
|
|
947
|
+
if not entry:
|
|
948
|
+
return False, "unknown", "没有这条配置"
|
|
949
|
+
dirname = CARD_PROVIDER.get(str(entry.get("card") or ""))
|
|
950
|
+
if not dirname:
|
|
951
|
+
return False, "install", "这张卡不认识(%r)" % entry.get("card")
|
|
952
|
+
try:
|
|
953
|
+
from bus.loaders.provider_loader import build_provider
|
|
954
|
+
provider, _derived = build_provider(
|
|
955
|
+
PROVIDERS_DIR / dirname, {"model": _model_cfg_of(entry, cid)})
|
|
956
|
+
provider.chat([{"role": "user", "content": "ping"}])
|
|
957
|
+
except Exception as exc: # noqa: BLE001
|
|
958
|
+
return (False, classify_probe_error(exc),
|
|
959
|
+
"%s: %s" % (type(exc).__name__, str(exc)[:300]))
|
|
960
|
+
return True, "", ""
|
|
961
|
+
|
|
962
|
+
|
|
883
963
|
def cards_payload() -> dict:
|
|
884
964
|
"""`GET /api/model-configs` 的载荷。
|
|
885
965
|
|
|
@@ -617,7 +617,7 @@ class PipelineScheduler:
|
|
|
617
617
|
# 冒号就停。
|
|
618
618
|
# 修法不是在这里重新拼 —— 那会变成第二个渲染源。
|
|
619
619
|
body = str(pend.get("body") or "")
|
|
620
|
-
if kind
|
|
620
|
+
if kind in ("delete", "delete_bulk") and not body:
|
|
621
621
|
# 使用工具拼好的列表,不要重新渲染。
|
|
622
622
|
#
|
|
623
623
|
# 在这里重新渲染会产生第二个渲染源,而且没有 >10 的
|
|
@@ -634,7 +634,7 @@ class PipelineScheduler:
|
|
|
634
634
|
names = [os.path.basename(str(p))
|
|
635
635
|
for p in (pend.get("file_paths") or [])]
|
|
636
636
|
file_list = compact_file_list(names)
|
|
637
|
-
body = render_delete_body(file_list)
|
|
637
|
+
body = render_delete_body(file_list, kind=kind)
|
|
638
638
|
return build_payload(
|
|
639
639
|
kind,
|
|
640
640
|
int(pend.get("ask_index")
|
|
@@ -26,8 +26,10 @@ from core.image_input import content_text
|
|
|
26
26
|
from core.approval import ASK_COUNTED_KINDS, new_request_id, outcome_line
|
|
27
27
|
from core.prompt_assembler import assemble_system_prompt, model_name_of
|
|
28
28
|
from core.events import (
|
|
29
|
-
EVT_STEP_END, EVT_STEP_START, EVT_TOOL_NEUTRALIZED,
|
|
29
|
+
EVT_STEP_END, EVT_STEP_START, EVT_TOOL_NEUTRALIZED, emit_settled_tool,
|
|
30
|
+
make_emitter,
|
|
30
31
|
)
|
|
32
|
+
from core import tool_outcome as _tool_outcome
|
|
31
33
|
from core.session_key import session_key_of_ctx
|
|
32
34
|
from core.session_date import date_change_note
|
|
33
35
|
from core.pipeline.stage import Stage, StageContext, register_stage
|
|
@@ -184,21 +186,32 @@ class AgentLoopStage(Stage):
|
|
|
184
186
|
if replay:
|
|
185
187
|
ctx.approval_replay = {}
|
|
186
188
|
_replay_ok = False
|
|
189
|
+
#: 结算类结局(拒绝 / 提问回答)。这两条不走 `replay_pending_call`,
|
|
190
|
+
#: 所以要在这里补一条 `tool.end`——否则客户端那张"待审批"卡
|
|
191
|
+
#: 永远停在那里(它没有别的结束信号)。
|
|
192
|
+
_settled: tuple[str, str, str] | None = None
|
|
187
193
|
try:
|
|
188
194
|
if replay.get("result") is not None:
|
|
189
195
|
# 提问的回答 —— 它不是拒绝,也不重放:
|
|
190
196
|
# 用户那句话就是结果。直接补回那次调用(与 deny 同一套
|
|
191
197
|
# 消息替换机制,但语义不同,键也不同 —— 绝不让"答案"
|
|
192
198
|
# 顶着 `deny` 的名字走)。
|
|
199
|
+
_call_id = str(replay.get("call_id") or "")
|
|
193
200
|
_replay_ok = answer_pending_call(
|
|
194
201
|
ctx.messages,
|
|
195
|
-
call_id=
|
|
202
|
+
call_id=_call_id,
|
|
196
203
|
message=str(replay["result"]))
|
|
204
|
+
_settled = (_call_id, _tool_outcome.OUTCOME_COMPLETED, "")
|
|
197
205
|
elif replay.get("deny"):
|
|
206
|
+
_call_id = str(replay.get("call_id") or "")
|
|
207
|
+
_deny_msg = str(replay["deny"])
|
|
198
208
|
_replay_ok = deny_pending_call(
|
|
199
209
|
ctx.messages,
|
|
200
|
-
call_id=
|
|
201
|
-
message=
|
|
210
|
+
call_id=_call_id,
|
|
211
|
+
message=_deny_msg)
|
|
212
|
+
# 语义只从那一句头认(`outcome_line` 是它唯一的生产者)。
|
|
213
|
+
_so, _sr = _tool_outcome.of_settlement_receipt(_deny_msg)
|
|
214
|
+
_settled = (_call_id, _so, _sr)
|
|
202
215
|
else:
|
|
203
216
|
_replay_ok = replay_pending_call(
|
|
204
217
|
ctx.messages,
|
|
@@ -213,6 +226,13 @@ class AgentLoopStage(Stage):
|
|
|
213
226
|
print(f"[approval] 重放失败(退回旧回执):"
|
|
214
227
|
f"{type(_rp_exc).__name__}: {_rp_exc}")
|
|
215
228
|
_replay_ok = False
|
|
229
|
+
# 结算结论照发:卡片要说的是"用户做了什么决定",
|
|
230
|
+
# 与"那条消息补没补成功"是两件事(补不成时退路会说话)。
|
|
231
|
+
if _settled is not None:
|
|
232
|
+
emit_settled_tool(
|
|
233
|
+
getattr(ctx, "events", None), session_key_of_ctx(ctx),
|
|
234
|
+
call_id=_settled[0], outcome=_settled[1],
|
|
235
|
+
reason=_settled[2])
|
|
216
236
|
# 退路必须保留:补不成时(旧对话 / 消息被压缩掉了),退回
|
|
217
237
|
# 原来那句"请重新提交"的回执 —— 否则就是**用户批了却什么都没
|
|
218
238
|
# 发生**,而这正是这套设计要消灭的静默。
|
|
@@ -631,6 +631,15 @@ class PreProcessStage(Stage):
|
|
|
631
631
|
)
|
|
632
632
|
return ctx
|
|
633
633
|
|
|
634
|
+
def _cmd_config(self, ctx: StageContext, user_input: str) -> StageContext:
|
|
635
|
+
# ---- /config [名字] ----
|
|
636
|
+
# 技能的配置要求与入口(`manifest.yaml` 的 `requires_config`)。
|
|
637
|
+
# 只回话,不派发 —— 与 `/context` 同一条:这是"看一眼"的命令。
|
|
638
|
+
parts = user_input.split(maxsplit=1)
|
|
639
|
+
ctx.metadata["stop"] = True
|
|
640
|
+
ctx.response = _handle_config_command(parts)
|
|
641
|
+
return ctx
|
|
642
|
+
|
|
634
643
|
def _cmd_compact(self, ctx: StageContext, user_input: str) -> StageContext:
|
|
635
644
|
# ---- /compact ----
|
|
636
645
|
pool = ctx.session_pool
|
|
@@ -1244,12 +1253,9 @@ def _handle_effort(parts: list, session_key: str) -> str:
|
|
|
1244
1253
|
from core import tiers
|
|
1245
1254
|
from core.tiers import TIERS, TierUnsupported, level_of
|
|
1246
1255
|
|
|
1247
|
-
def _table(
|
|
1248
|
-
|
|
1249
|
-
for lvl in sorted(TIERS)
|
|
1250
|
-
spec = TIERS[lvl]
|
|
1251
|
-
rows.append(f"{lvl} {spec.name}")
|
|
1252
|
-
return "\n".join(rows)
|
|
1256
|
+
def _table() -> str:
|
|
1257
|
+
# 六档一行排开:这条回执要说的只是"现在是哪档",一档一行会把回复拉成七行。
|
|
1258
|
+
return " - ".join(f"{lvl} {TIERS[lvl].name}" for lvl in sorted(TIERS))
|
|
1253
1259
|
|
|
1254
1260
|
# 读现状(可能读不出来 —— 而上一条 docstring 的 ④ 就是这个意思)
|
|
1255
1261
|
current: int | None = None
|
|
@@ -1262,7 +1268,7 @@ def _handle_effort(parts: list, session_key: str) -> str:
|
|
|
1262
1268
|
_cur = (f"{current} {TIERS[current].name}" if current is not None
|
|
1263
1269
|
else tr("无法识别"))
|
|
1264
1270
|
return (tr("当前档位:%s\n%s\n用 /effort <名称或数字> 切换档位,/effort thinking on|off 开关思考")
|
|
1265
|
-
% (_cur, _table(
|
|
1271
|
+
% (_cur, _table()))
|
|
1266
1272
|
|
|
1267
1273
|
want = parts[1].strip()
|
|
1268
1274
|
|
|
@@ -1723,6 +1729,40 @@ def _handle_context_command(pool, session_key: str, messages) -> str:
|
|
|
1723
1729
|
return "\n".join(lines)
|
|
1724
1730
|
|
|
1725
1731
|
|
|
1732
|
+
def _handle_config_command(parts: list) -> str:
|
|
1733
|
+
"""`/config [名字]`:列出 / 查看技能的配置要求与入口。
|
|
1734
|
+
|
|
1735
|
+
判据只有一份(`core/config_requirements.py`):这里不猜"配没配"。
|
|
1736
|
+
末尾那句提醒是代填(用户明确要求、agent 照办)唯一的固定提示点 ——
|
|
1737
|
+
不拦、不重复,只在用户来查入口时说一次。
|
|
1738
|
+
"""
|
|
1739
|
+
from core import config_requirements as _cr
|
|
1740
|
+
|
|
1741
|
+
tip = tr("填好后提醒:明文凭据会进会话历史,并随每轮发给上游模型。")
|
|
1742
|
+
scope = parts[1].strip() if len(parts) > 1 else ""
|
|
1743
|
+
if not scope:
|
|
1744
|
+
rows = []
|
|
1745
|
+
for skill in _cr.all_skills():
|
|
1746
|
+
for decl in _cr.declared(skill):
|
|
1747
|
+
rows.append((skill, decl, _cr.configured(decl), _cr.where(decl)))
|
|
1748
|
+
if not rows:
|
|
1749
|
+
return tr("没有技能声明需要配置。")
|
|
1750
|
+
lines = [tr("技能配置:")]
|
|
1751
|
+
for skill, decl, ok, place in rows:
|
|
1752
|
+
lines.append("- %s → %s:%s(%s)"
|
|
1753
|
+
% (skill, decl, tr("已配置") if ok else tr("未配置"),
|
|
1754
|
+
place))
|
|
1755
|
+
lines.append(tip)
|
|
1756
|
+
return "\n".join(lines)
|
|
1757
|
+
owners = [s for s in _cr.all_skills() if scope in _cr.declared(s)]
|
|
1758
|
+
if not owners:
|
|
1759
|
+
return trf("没有技能声明需要「{name}」的配置。", scope)
|
|
1760
|
+
ok = _cr.configured(scope)
|
|
1761
|
+
return (trf("「{name}」:{state}({where})", scope,
|
|
1762
|
+
tr("已配置") if ok else tr("未配置"), _cr.where(scope))
|
|
1763
|
+
+ "\n" + tip)
|
|
1764
|
+
|
|
1765
|
+
|
|
1726
1766
|
def _handle_skill_command(parts: list) -> str:
|
|
1727
1767
|
"""处理 /skill list|check|approve|reject|reload。
|
|
1728
1768
|
|
|
@@ -1970,6 +2010,7 @@ _COMMANDS: tuple = (
|
|
|
1970
2010
|
_CommandSpec("/stop", "停止当前这一轮", "_cmd_stop"),
|
|
1971
2011
|
_CommandSpec("/clear", "清空当前上下文,开始新对话", "_cmd_clear"),
|
|
1972
2012
|
_CommandSpec("/compact", "压缩对话记录,释放上下文空间", "_cmd_compact"),
|
|
2013
|
+
_CommandSpec("/config", "查看技能的配置要求与入口", "_cmd_config", MATCH_PREFIX),
|
|
1973
2014
|
_CommandSpec("/context", "查看当前上下文的构成与占用", "_cmd_context"),
|
|
1974
2015
|
_CommandSpec("/skill", "检查与启用技能", "_cmd_skill", MATCH_PREFIX),
|
|
1975
2016
|
# 这一条必须排在 `/mode` 前面(见本表抬头)
|
|
@@ -2505,11 +2546,21 @@ def _answer_ask(kind: str, pend: dict, user_input: str, ctx):
|
|
|
2505
2546
|
# 这是第二种语义(`cancelled`)。不做区分时它看起来与
|
|
2506
2547
|
# "rejected"一模一样(都只是框架说的一句中文),而模型该做的事
|
|
2507
2548
|
# 正好相反:拒绝,停;打断,带着补充重做。
|
|
2549
|
+
_replay = _replay_of(pend) # `_drop_pending` 会清空 pend
|
|
2508
2550
|
_drop_pending(pend)
|
|
2509
2551
|
ctx.user_message = "[系统] " + outcome_line(
|
|
2510
2552
|
"cancelled",
|
|
2511
2553
|
f"用户**打断**了本次审批,并补充:{text}。"
|
|
2512
2554
|
f"请根据这条补充重新判断。**不要**当成已获得授权。")
|
|
2555
|
+
# 这一支不经过 `approval_replay`,所以结算结论要在这里自己发 ——
|
|
2556
|
+
# 否则客户端那张"待审批"卡没有结束信号。
|
|
2557
|
+
from core import tool_outcome as _to
|
|
2558
|
+
from core.events import emit_settled_tool
|
|
2559
|
+
_so, _sr = _to.of_settlement("cancelled")
|
|
2560
|
+
emit_settled_tool(getattr(ctx, "events", None), session_key_of_ctx(ctx),
|
|
2561
|
+
call_id=str(_replay.get("call_id") or ""),
|
|
2562
|
+
name=str(_replay.get("name") or ""),
|
|
2563
|
+
outcome=_so, reason=_sr)
|
|
2513
2564
|
return None
|
|
2514
2565
|
|
|
2515
2566
|
# 非 Web:回一句纠正,挂起状态保持不变
|