@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/approval.py
CHANGED
|
@@ -813,7 +813,8 @@ def build_payload(kind: str, ask_index: int = 1, *,
|
|
|
813
813
|
body: str = "", stage: str = "",
|
|
814
814
|
request_id: str = "", file_list: str = "",
|
|
815
815
|
rule: str = "", options=None, multi: bool = False,
|
|
816
|
-
title: str = "", ask_question: str = ""
|
|
816
|
+
title: str = "", ask_question: str = "",
|
|
817
|
+
requester: str = "") -> dict:
|
|
817
818
|
"""浮窗的渲染源。纯函数:同样的入参出同样的 dict。
|
|
818
819
|
|
|
819
820
|
这里不拼字符串 —— 那是 :func:`render_prompt` 给文本通道的事。
|
|
@@ -823,8 +824,8 @@ def build_payload(kind: str, ask_index: int = 1, *,
|
|
|
823
824
|
n = max(1, int(ask_index or 1))
|
|
824
825
|
opts = options_for(kind, n, rule=rule, options=options)
|
|
825
826
|
q = substate_question(kind, stage)
|
|
826
|
-
if kind
|
|
827
|
-
body = render_delete_body(file_list)
|
|
827
|
+
if kind in ("delete", "delete_bulk") and not body:
|
|
828
|
+
body = render_delete_body(file_list, kind=kind)
|
|
828
829
|
# 中间态不给选项:那一步用户该做的是"说一句话",不是"选一项"。
|
|
829
830
|
# 给了也是死数据(前端在 `expect === 'text'` 时根本不渲染选项),
|
|
830
831
|
# 而"载荷里有一份谁也不读的选项表"正是本模块要消灭的那种副本。
|
|
@@ -833,11 +834,17 @@ def build_payload(kind: str, ask_index: int = 1, *,
|
|
|
833
834
|
#: 动态表那一路把每项的说明也带上(浮窗要显示第二行)。
|
|
834
835
|
_desc = {str(r.get("key")): str(r.get("description") or "")
|
|
835
836
|
for r in (options or ()) if isinstance(r, dict)}
|
|
837
|
+
_body = tr(body or _DEFAULT_BODY.get(kind, ""))
|
|
838
|
+
if requester:
|
|
839
|
+
# 谁在申请要写在正文最前面 —— 用户在批一个他自己没有发起过的动作。
|
|
840
|
+
_body = tr("来自子代理的请求,") + _body
|
|
836
841
|
return {
|
|
837
842
|
"request_id": request_id or new_request_id(kind),
|
|
838
843
|
"kind": kind,
|
|
839
844
|
"ask_index": n,
|
|
840
|
-
"body":
|
|
845
|
+
"body": _body,
|
|
846
|
+
#: 空 = 父代理自己发的;非空 = 子代理名(面板据此标注来源)。
|
|
847
|
+
"requester": str(requester or ""),
|
|
841
848
|
#: 提问面板:允许多选(浮窗据此把单选改成多选)。
|
|
842
849
|
"multi": bool(multi),
|
|
843
850
|
# 选项按表里的顺序(升级项永远最后)
|
|
@@ -924,9 +931,13 @@ def compact_file_list(lines, *, total_note: str = "",
|
|
|
924
931
|
return f"{head}\n {more}{total_note}"
|
|
925
932
|
|
|
926
933
|
|
|
927
|
-
def render_delete_body(file_list: str) -> str:
|
|
934
|
+
def render_delete_body(file_list: str, kind: str = "delete") -> str:
|
|
928
935
|
"""删除那条的开场白 —— 带文件列表。
|
|
929
936
|
|
|
937
|
+
*kind* 决定抬头:`delete` 是"想删除以下文件",`delete_bulk` 要顺带说清
|
|
938
|
+
这次为什么还要问(数量超过阈值)。抬头与列表必须由同一处拼出来 ——
|
|
939
|
+
同一份授权在两条通道上长得不一样,是这一族反复踩过的坑。
|
|
940
|
+
|
|
930
941
|
单独一个函数是因为列表也是提示语的一部分:内容无界会把按钮顶出视口,
|
|
931
942
|
而判据是"被审批的文本就是被同意的文本,藏掉尾巴等于让用户同意他读不到
|
|
932
943
|
的东西"。截断策略因此属于渲染层,并且要显式标注省略了多少
|
|
@@ -936,7 +947,7 @@ def render_delete_body(file_list: str) -> str:
|
|
|
936
947
|
换行,而排版是空一行再接选项(`...{file_list}\\n\\n1. 同意`)。
|
|
937
948
|
补上它才能保持这个逐字形状(有断言钉着)。
|
|
938
949
|
"""
|
|
939
|
-
head = tr(
|
|
950
|
+
head = tr(_DEFAULT_BODY.get(kind) or _DEFAULT_BODY["delete"])
|
|
940
951
|
return f"{head}\n{file_list}\n"
|
|
941
952
|
|
|
942
953
|
|
package/core/artifacts.py
CHANGED
|
@@ -183,6 +183,13 @@ def sniff(data: bytes) -> Optional[str]:
|
|
|
183
183
|
return _sniff_av(data)
|
|
184
184
|
|
|
185
185
|
|
|
186
|
+
def ext_for_mime(mime: str) -> str:
|
|
187
|
+
"""mime -> 扩展名(不带点);认不出回空串。
|
|
188
|
+
|
|
189
|
+
唯一来源是 `_EXT_BY_MIME` —— 别在别处再写一张。"""
|
|
190
|
+
return _EXT_BY_MIME.get(str(mime or "").strip().lower(), "").lstrip(".")
|
|
191
|
+
|
|
192
|
+
|
|
186
193
|
def kind_of(mime: str) -> str:
|
|
187
194
|
"""mime -> `image` / `audio` / `video` / `""`(认不出)。"""
|
|
188
195
|
if not mime:
|
package/core/auto_review.py
CHANGED
|
@@ -208,14 +208,32 @@ def outcome_of_tool_result(content) -> Optional[str]:
|
|
|
208
208
|
# 头从 `core.approval` 取(全仓只有那一处拼得出来)。
|
|
209
209
|
# 只有 `rejected` 算数:`cancelled`/`unavailable`/`recused` 都不是"被拒绝"
|
|
210
210
|
# (见 `APPROVAL_OUTCOMES` 那四条各自的语义)。
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
token = body[len(APPROVAL_HEAD):].strip().split("(", 1)[0].strip()
|
|
214
|
-
if token == "rejected":
|
|
215
|
-
return OUTCOME_REJECTED_BY_USER
|
|
211
|
+
if settlement_outcome_of(text) == "rejected":
|
|
212
|
+
return OUTCOME_REJECTED_BY_USER
|
|
216
213
|
return None
|
|
217
214
|
|
|
218
215
|
|
|
216
|
+
def settlement_outcome_of(content) -> str:
|
|
217
|
+
"""回执是"结算过的审批"就返回它的语义 token;不是就回空串。
|
|
218
|
+
|
|
219
|
+
头由 `core.approval.outcome_line` 拼(全仓唯一一处),形状是
|
|
220
|
+
`APPROVAL_HEAD` + `<token>(<白话>)—— <路线>`,外面可能套一层信封或隔离包裹。
|
|
221
|
+
|
|
222
|
+
与 `outcome_of_tool_result` 分工:那个是审计口径(只认"用户拒绝"),
|
|
223
|
+
这一个给事件用 —— 四种语义都要,客户端才能分得开"未采纳 / 未执行 / 被拒绝"。
|
|
224
|
+
"""
|
|
225
|
+
from core.approval import APPROVAL_HEAD, APPROVAL_OUTCOMES
|
|
226
|
+
|
|
227
|
+
text = content_text(content)
|
|
228
|
+
if not isinstance(text, str) or not text.strip():
|
|
229
|
+
return ""
|
|
230
|
+
body = _strip_wrappers(text)
|
|
231
|
+
if not body.startswith(APPROVAL_HEAD):
|
|
232
|
+
return ""
|
|
233
|
+
token = body[len(APPROVAL_HEAD):].strip().split("(", 1)[0].strip()
|
|
234
|
+
return token if token in APPROVAL_OUTCOMES else ""
|
|
235
|
+
|
|
236
|
+
|
|
219
237
|
# 一、声明层(复用已有的声明形状,不新建机制)
|
|
220
238
|
|
|
221
239
|
#: 声明值:这个工具没有与分类器相关的输入,第 ④ 层跳过。
|
package/core/channel_configs.py
CHANGED
|
@@ -44,7 +44,7 @@ __all__ = [
|
|
|
44
44
|
"ChannelConfigError", "PLATFORMS", "MAX_PER_PLATFORM", "MAX_NAME",
|
|
45
45
|
"entries_for", "entry_of", "default_id", "credentials_for",
|
|
46
46
|
"create", "update", "delete", "set_default", "seed_from_legacy",
|
|
47
|
-
"masked_fields", "load",
|
|
47
|
+
"masked_fields", "load", "notice_for",
|
|
48
48
|
]
|
|
49
49
|
|
|
50
50
|
#: 每种平台的字段表。`secret` 里的那几格界面不打码回显、日志里也不打印。
|
|
@@ -56,6 +56,22 @@ PLATFORMS: dict[str, dict] = {
|
|
|
56
56
|
"qq_bot": {"fields": ("app_id", "app_secret"), "secret": ("app_secret",)},
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
#: 接入警告的文案。住在这里而不是界面里 —— 命令行与 TUI 都没有那份界面表,
|
|
60
|
+
#: 而"接群聊有隐私风险"这件事与用哪个前端无关。
|
|
61
|
+
NOTICES: dict[str, str] = {
|
|
62
|
+
"group_unfinished":
|
|
63
|
+
"当前通道的群聊模式还没做完:群里的内容会进模型,也会被群里的人看到,"
|
|
64
|
+
"请先不要接入群聊使用。",
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#: 哪个平台挂哪条警告。微信走扫码、CLI 不需要配置,两者都不挂。
|
|
68
|
+
PLATFORM_NOTICE: dict[str, str] = {
|
|
69
|
+
"feishu": "group_unfinished",
|
|
70
|
+
"dingtalk": "group_unfinished",
|
|
71
|
+
"telegram": "group_unfinished",
|
|
72
|
+
"qq_bot": "group_unfinished",
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
#: 每种平台最多几条。超了拒,不静默丢。
|
|
60
76
|
MAX_PER_PLATFORM = 10
|
|
61
77
|
#: 条目名的长度上限。截断改的是用户起的名,所以超了是拒。
|
|
@@ -138,6 +154,17 @@ def _platform(data: dict, name: str) -> dict:
|
|
|
138
154
|
return p
|
|
139
155
|
|
|
140
156
|
|
|
157
|
+
def notice_for(platform: str) -> dict:
|
|
158
|
+
"""这个平台的接入警告:`{"key": ..., "text": ...}`;没有就空 dict。
|
|
159
|
+
|
|
160
|
+
前端照 `text` 显示、照 `key` 做本地化,两样都不在该前端里另写一份。
|
|
161
|
+
"""
|
|
162
|
+
key = PLATFORM_NOTICE.get(platform, "")
|
|
163
|
+
if not key:
|
|
164
|
+
return {}
|
|
165
|
+
return {"key": key, "text": NOTICES.get(key, "")}
|
|
166
|
+
|
|
167
|
+
|
|
141
168
|
def masked_fields(platform: str, fields: dict) -> dict:
|
|
142
169
|
"""按字段表打码。密钥一律八颗点,其余留头尾各四位。"""
|
|
143
170
|
spec = PLATFORMS.get(platform) or {}
|
|
@@ -171,6 +198,8 @@ def entries_for(platform: str) -> list[dict]:
|
|
|
171
198
|
"is_default": cid == p.get("default"),
|
|
172
199
|
"fields": masked_fields(platform, creds.get(cid) or {}),
|
|
173
200
|
"created_at": entry.get("created_at") or 0,
|
|
201
|
+
# 账本里没写过的(老条目)按平台现推,免得列表少一个标记。
|
|
202
|
+
"notice": str(entry.get("notice") or PLATFORM_NOTICE.get(platform, "")),
|
|
174
203
|
})
|
|
175
204
|
rows.sort(key=lambda r: (not r["is_default"], r["created_at"], r["name"]))
|
|
176
205
|
return rows
|
|
@@ -244,7 +273,8 @@ def create(platform: str, name: str, fields: dict) -> dict:
|
|
|
244
273
|
|
|
245
274
|
cid = new_id()
|
|
246
275
|
now = int(time.time())
|
|
247
|
-
p["entries"][cid] = {"name": name, "created_at": now, "updated_at": now
|
|
276
|
+
p["entries"][cid] = {"name": name, "created_at": now, "updated_at": now,
|
|
277
|
+
"notice": PLATFORM_NOTICE.get(platform, "")}
|
|
248
278
|
if not p.get("default"):
|
|
249
279
|
p["default"] = cid
|
|
250
280
|
creds = _read(_CREDS)
|
|
@@ -287,6 +317,8 @@ def update(cid: str, *, name: str | None = None, fields: dict | None = None) ->
|
|
|
287
317
|
_write(_CREDS, creds)
|
|
288
318
|
|
|
289
319
|
p["entries"][cid]["updated_at"] = int(time.time())
|
|
320
|
+
# 老条目在这里补上标记(写一次就够,读侧还有一层兜底)。
|
|
321
|
+
p["entries"][cid]["notice"] = PLATFORM_NOTICE.get(platform, "")
|
|
290
322
|
_write(_LEDGER, data)
|
|
291
323
|
return {"id": cid, "platform": platform, "name": p["entries"][cid]["name"]}
|
|
292
324
|
|