@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
|
@@ -252,11 +252,11 @@ class FeishuChannel(Channel):
|
|
|
252
252
|
resp = client.im.v1.message.reply(req)
|
|
253
253
|
if _response_ok(resp):
|
|
254
254
|
return True
|
|
255
|
-
print("[feishu]
|
|
255
|
+
print("[feishu] reply rejected (msg_type=%s code=%s %s), sending as normal message"
|
|
256
256
|
% (msg_type, getattr(resp, "code", "?"),
|
|
257
257
|
getattr(resp, "msg", "")))
|
|
258
258
|
except Exception as e: # noqa: BLE001
|
|
259
|
-
print(f"[feishu]
|
|
259
|
+
print(f"[feishu] reply failed ({type(e).__name__}: {e}), sending as normal message")
|
|
260
260
|
|
|
261
261
|
#: 形状即真相(飞书的 id 带前缀:`oc_` 群/会话、`ou_` 用户)
|
|
262
262
|
receive_id_type = ("chat_id" if str(session.session_id).startswith("oc_")
|
|
@@ -272,10 +272,10 @@ class FeishuChannel(Channel):
|
|
|
272
272
|
.build()
|
|
273
273
|
resp = client.im.v1.message.create(req)
|
|
274
274
|
except Exception as e: # noqa: BLE001
|
|
275
|
-
print(f"[feishu] send error
|
|
275
|
+
print(f"[feishu] send error ({type(e).__name__}: {e})")
|
|
276
276
|
return False
|
|
277
277
|
if not _response_ok(resp):
|
|
278
|
-
print("[feishu] send rejected
|
|
278
|
+
print("[feishu] send rejected (msg_type=%s code=%s %s)"
|
|
279
279
|
% (msg_type, getattr(resp, "code", "?"),
|
|
280
280
|
getattr(resp, "msg", "")))
|
|
281
281
|
return False
|
|
@@ -288,21 +288,21 @@ class FeishuChannel(Channel):
|
|
|
288
288
|
"""上传 + 发一条(图片走 `image`,其余走 `file`)。"""
|
|
289
289
|
p = Path(str(file_path or ""))
|
|
290
290
|
if not p.is_file():
|
|
291
|
-
print("[feishu]
|
|
291
|
+
print("[feishu] file to send does not exist: %s" % (file_path or "(empty)"))
|
|
292
292
|
return False
|
|
293
293
|
data = p.read_bytes()
|
|
294
294
|
mime, _ = mimetypes.guess_type(p.name)
|
|
295
295
|
is_image = (mime or "").lower().startswith("image/")
|
|
296
296
|
limit = MAX_IMAGE_BYTES if is_image else MAX_FILE_BYTES
|
|
297
297
|
if len(data) > limit:
|
|
298
|
-
print("[feishu]
|
|
298
|
+
print("[feishu] file too large (%d bytes > %d), not uploaded: %s"
|
|
299
299
|
% (len(data), limit, p.name))
|
|
300
300
|
return False
|
|
301
301
|
name = filename or p.name
|
|
302
302
|
try:
|
|
303
303
|
client = self._get_client()
|
|
304
304
|
except ImportError:
|
|
305
|
-
print("[feishu]
|
|
305
|
+
print("[feishu] lark-oapi not installed, cannot send attachment")
|
|
306
306
|
return False
|
|
307
307
|
try:
|
|
308
308
|
if is_image:
|
|
@@ -315,7 +315,7 @@ class FeishuChannel(Channel):
|
|
|
315
315
|
resp = client.im.v1.image.create(req)
|
|
316
316
|
key = getattr(getattr(resp, "data", None), "image_key", "") or ""
|
|
317
317
|
if not _response_ok(resp) or not key:
|
|
318
|
-
print("[feishu]
|
|
318
|
+
print("[feishu] image upload failed (code=%s %s)"
|
|
319
319
|
% (getattr(resp, "code", "?"), getattr(resp, "msg", "")))
|
|
320
320
|
return False
|
|
321
321
|
return self._post_message(
|
|
@@ -331,7 +331,7 @@ class FeishuChannel(Channel):
|
|
|
331
331
|
resp = client.im.v1.file.create(req)
|
|
332
332
|
key = getattr(getattr(resp, "data", None), "file_key", "") or ""
|
|
333
333
|
if not _response_ok(resp) or not key:
|
|
334
|
-
print("[feishu]
|
|
334
|
+
print("[feishu] file upload failed (code=%s %s)"
|
|
335
335
|
% (getattr(resp, "code", "?"), getattr(resp, "msg", "")))
|
|
336
336
|
return False
|
|
337
337
|
return self._post_message(
|
|
@@ -339,7 +339,7 @@ class FeishuChannel(Channel):
|
|
|
339
339
|
json.dumps({"file_key": key, "file_name": name},
|
|
340
340
|
ensure_ascii=False))
|
|
341
341
|
except Exception as e: # noqa: BLE001
|
|
342
|
-
print(f"[feishu]
|
|
342
|
+
print(f"[feishu] attachment send failed ({type(e).__name__}: {e})")
|
|
343
343
|
return False
|
|
344
344
|
|
|
345
345
|
def _drain_sync(self, session: MessageSession, reply_to: str = "") -> None:
|
|
@@ -351,7 +351,7 @@ class FeishuChannel(Channel):
|
|
|
351
351
|
channel="feishu_channel",
|
|
352
352
|
user_id=session.session_id)
|
|
353
353
|
except Exception as exc: # noqa: BLE001
|
|
354
|
-
print(f"[feishu]
|
|
354
|
+
print(f"[feishu] failed to fetch pending files ({type(exc).__name__}: {exc})")
|
|
355
355
|
return
|
|
356
356
|
for rec in recs:
|
|
357
357
|
ok = self._send_media_sync(session, rec.get("path", ""),
|
|
@@ -407,22 +407,22 @@ class FeishuChannel(Channel):
|
|
|
407
407
|
if not kind:
|
|
408
408
|
continue
|
|
409
409
|
if not message_id:
|
|
410
|
-
print("[feishu]
|
|
410
|
+
print("[feishu] message has no message_id, cannot fetch attachment: %s" % key)
|
|
411
411
|
continue
|
|
412
412
|
try:
|
|
413
413
|
data, real_name = await asyncio.to_thread(
|
|
414
414
|
self._download_resource, message_id, key, kind)
|
|
415
415
|
except Exception as exc: # noqa: BLE001
|
|
416
|
-
print(f"[feishu]
|
|
416
|
+
print(f"[feishu] failed to fetch attachment ({type(exc).__name__}: {exc})")
|
|
417
417
|
continue
|
|
418
418
|
if not data:
|
|
419
419
|
# 空字节不是"一个空文件":它多半是"响应 200 但没有正文"。
|
|
420
420
|
# 以前会落一个 0 字节的文件,下游只能说"附件是空的"。
|
|
421
|
-
print("[feishu]
|
|
421
|
+
print("[feishu] fetched attachment is empty (kind=%s key=%s...)"
|
|
422
422
|
% (kind, str(key)[:8]))
|
|
423
423
|
continue
|
|
424
424
|
if len(data) > feishu_media.MAX_DOWNLOAD_BYTES:
|
|
425
|
-
print("[feishu]
|
|
425
|
+
print("[feishu] attachment too large (%d bytes), not downloaded: %s"
|
|
426
426
|
% (len(data), key))
|
|
427
427
|
continue
|
|
428
428
|
name = getattr(comp, "name", "") or real_name
|
|
@@ -430,12 +430,12 @@ class FeishuChannel(Channel):
|
|
|
430
430
|
path = await asyncio.to_thread(
|
|
431
431
|
self._save_media, data, kind, key, name)
|
|
432
432
|
except Exception as exc: # noqa: BLE001
|
|
433
|
-
print(f"[feishu]
|
|
433
|
+
print(f"[feishu] failed to save attachment ({type(exc).__name__}: {exc})")
|
|
434
434
|
continue
|
|
435
435
|
comp.local_path = str(path)
|
|
436
436
|
if hasattr(comp, "size_bytes"):
|
|
437
437
|
comp.size_bytes = len(data)
|
|
438
|
-
print("[feishu]
|
|
438
|
+
print("[feishu] attachment saved: %s (%d bytes)" % (path.name, len(data)))
|
|
439
439
|
|
|
440
440
|
# ------------------------------------------------------------------
|
|
441
441
|
# Event handling (called from worker thread via _FeishuEventHandler)
|
|
@@ -454,7 +454,7 @@ class FeishuChannel(Channel):
|
|
|
454
454
|
if not self._main_loop or not self._running:
|
|
455
455
|
# 这一条不许静默:通道还没就绪时消息会凭空消失,
|
|
456
456
|
# 看来就像"对方那条消息没发出来"。
|
|
457
|
-
print("[feishu]
|
|
457
|
+
print("[feishu] channel not ready (main_loop/running), message dropped: type=%s"
|
|
458
458
|
% (msg_data.get("message_type") or "?"))
|
|
459
459
|
return
|
|
460
460
|
try:
|
|
@@ -465,7 +465,7 @@ class FeishuChannel(Channel):
|
|
|
465
465
|
# 没有回复、也没有步骤流(症状与"这条消息没收到"一模一样)。
|
|
466
466
|
fut.add_done_callback(_report_future_error)
|
|
467
467
|
except Exception as exc: # noqa: BLE001
|
|
468
|
-
print(f"[feishu]
|
|
468
|
+
print(f"[feishu] failed to dispatch event ({type(exc).__name__}: {exc})")
|
|
469
469
|
|
|
470
470
|
async def _handle(self, msg_data: dict, event_data: dict) -> None:
|
|
471
471
|
"""主循环上的处理:转换 → 取附件 → 提交事件 → 管线。"""
|
|
@@ -480,20 +480,20 @@ class FeishuChannel(Channel):
|
|
|
480
480
|
#: "消息像没收到"这一类只能靠它区分是"没进来"还是"进来后被丢了"。
|
|
481
481
|
#: 带消息号前 8 位 —— "它怎么自己又回了一遍"只能靠它区分
|
|
482
482
|
#: "同一条被重投"(号相同,会被去重闸拦)与"真的又发了一条"(号不同)。
|
|
483
|
-
print("[feishu]
|
|
483
|
+
print("[feishu] message received type=%s chat=%s id=%s keys=%s"
|
|
484
484
|
% (msg_type or "?",
|
|
485
|
-
(str(chat_id)[:10] + "…") if chat_id else "
|
|
486
|
-
(str(msg_id)[:8] + "…") if msg_id else "
|
|
487
|
-
",".join(sorted(feishu_media.content_of(msg_data).keys())) or "
|
|
485
|
+
(str(chat_id)[:10] + "…") if chat_id else "(empty)",
|
|
486
|
+
(str(msg_id)[:8] + "…") if msg_id else "(empty)",
|
|
487
|
+
",".join(sorted(feishu_media.content_of(msg_data).keys())) or "(empty)"))
|
|
488
488
|
|
|
489
489
|
chain = FeishuMessageConverter().to_internal(msg_data)
|
|
490
490
|
if chain.is_empty:
|
|
491
491
|
# `system`(入群/退群等)本来就没有给模型的内容 —— 不打日志。
|
|
492
492
|
if msg_type != "system":
|
|
493
|
-
print("[feishu]
|
|
493
|
+
print("[feishu] message has no usable content (type=%s, content keys=%s)"
|
|
494
494
|
% (msg_type or "?",
|
|
495
495
|
",".join(sorted(feishu_media.content_of(msg_data).keys()))
|
|
496
|
-
or "
|
|
496
|
+
or "(empty)"))
|
|
497
497
|
return
|
|
498
498
|
|
|
499
499
|
await self._resolve_media(chain, msg_id)
|
|
@@ -561,11 +561,11 @@ class FeishuChannel(Channel):
|
|
|
561
561
|
in_thread=in_thread)
|
|
562
562
|
#: 每一次发出都留一行:两行 = 两遍(用户能看到"又回了一遍"这
|
|
563
563
|
#: 件事的现场),零行 = 它压根没发出去。
|
|
564
|
-
print("[feishu]
|
|
565
|
-
% (len(response), "
|
|
566
|
-
(str(message_id)[:8] + "…") if message_id else "
|
|
564
|
+
print("[feishu] reply sent (%d chars, %s, msg=%s)"
|
|
565
|
+
% (len(response), "ok" if ok else "failed",
|
|
566
|
+
(str(message_id)[:8] + "…") if message_id else "(empty)"))
|
|
567
567
|
else:
|
|
568
|
-
print("[feishu]
|
|
568
|
+
print("[feishu] no reply text this turn (not sending)")
|
|
569
569
|
self._drain_sync(event.session, message_id)
|
|
570
570
|
|
|
571
571
|
|
|
@@ -581,7 +581,7 @@ def _report_future_error(fut: Any) -> None:
|
|
|
581
581
|
except Exception: # noqa: BLE001
|
|
582
582
|
return
|
|
583
583
|
if exc is not None:
|
|
584
|
-
print("[feishu]
|
|
584
|
+
print("[feishu] exception while handling message (not entering pipeline): %s: %s"
|
|
585
585
|
% (type(exc).__name__, exc))
|
|
586
586
|
|
|
587
587
|
|
|
@@ -765,7 +765,7 @@ class FeishuMessageConverter:
|
|
|
765
765
|
# `container_id_type` 取值在本机 SDK 里没有依据,不猜,
|
|
766
766
|
# 如实说明 + 打日志(别让它变成"机器人不理我")。
|
|
767
767
|
comps.append(Plain(text="[合并转发的聊天记录](暂不支持展开)"))
|
|
768
|
-
print("[feishu]
|
|
768
|
+
print("[feishu] merged-forward message: expansion not supported")
|
|
769
769
|
|
|
770
770
|
elif msg_type == "system":
|
|
771
771
|
# 入群 / 退群 / 改名 —— 不是给模型的输入。
|
|
@@ -925,12 +925,12 @@ class FeishuMessageConverter:
|
|
|
925
925
|
name=_f["file_name"],
|
|
926
926
|
url=feishu_media.SCHEME + "file/" + _f["file_key"],
|
|
927
927
|
mime_type=_mime_of(_f["file_name"])))
|
|
928
|
-
print("[feishu]
|
|
928
|
+
print("[feishu] attachment in rich-text top-level files: %s" % _f["file_name"])
|
|
929
929
|
|
|
930
930
|
if unknown:
|
|
931
931
|
#: 出声:这条消息照常处理,但那种元素我们没接住 ——
|
|
932
932
|
#: 下一次"模型看不见"的现场,日志里要有这句话当线索。
|
|
933
|
-
print("[feishu] post
|
|
933
|
+
print("[feishu] unknown element tag in post: %s (rest handled normally)"
|
|
934
934
|
% ",".join(sorted(set(unknown))))
|
|
935
935
|
|
|
936
936
|
text = feishu_media.replace_mentions("\n".join(texts), mentions)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
kind: channel
|
|
2
|
-
name: feishu_channel
|
|
3
|
-
version: "0.1.0"
|
|
4
|
-
description: "Feishu (Lark) IM channel via lark-oapi WebSocket long connection. No public IP required."
|
|
5
|
-
|
|
6
|
-
config:
|
|
7
|
-
platform_type: feishu
|
|
8
|
-
support_multimodal: true
|
|
9
|
-
support_streaming: true
|
|
10
|
-
|
|
11
|
-
required_packages:
|
|
12
|
-
- lark-oapi
|
|
1
|
+
kind: channel
|
|
2
|
+
name: feishu_channel
|
|
3
|
+
version: "0.1.0"
|
|
4
|
+
description: "Feishu (Lark) IM channel via lark-oapi WebSocket long connection. No public IP required."
|
|
5
|
+
|
|
6
|
+
config:
|
|
7
|
+
platform_type: feishu
|
|
8
|
+
support_multimodal: true
|
|
9
|
+
support_streaming: true
|
|
10
|
+
|
|
11
|
+
required_packages:
|
|
12
|
+
- lark-oapi
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""QQ 机器人通道(官方 Bot API v2)。"""
|
|
1
|
+
"""QQ 机器人通道(官方 Bot API v2)。"""
|
|
@@ -86,7 +86,7 @@ def _load_credentials() -> dict:
|
|
|
86
86
|
data = json.load(f)
|
|
87
87
|
return data if isinstance(data, dict) else {}
|
|
88
88
|
except (OSError, json.JSONDecodeError) as exc:
|
|
89
|
-
print("[qq_bot]
|
|
89
|
+
print("[qq_bot] failed to read credentials file (%s: %s)" % (type(exc).__name__, exc))
|
|
90
90
|
return {}
|
|
91
91
|
|
|
92
92
|
|
|
@@ -348,7 +348,7 @@ class QQBotChannel(Channel):
|
|
|
348
348
|
try:
|
|
349
349
|
creds = _load_credentials()
|
|
350
350
|
except Exception as exc: # noqa: BLE001
|
|
351
|
-
print("[qq_bot]
|
|
351
|
+
print("[qq_bot] failed to read credentials (%s: %s)" % (type(exc).__name__, exc))
|
|
352
352
|
creds = {}
|
|
353
353
|
self._app_id = str(cfg.get("app_id") or creds.get("app_id")
|
|
354
354
|
or os.environ.get("QQ_BOT_APP_ID") or "")
|
|
@@ -393,7 +393,7 @@ class QQBotChannel(Channel):
|
|
|
393
393
|
self._proxy = self._resolve_proxy()
|
|
394
394
|
if self._proxy:
|
|
395
395
|
from core.net_proxy import redact as _redact
|
|
396
|
-
print("[qq_bot]
|
|
396
|
+
print("[qq_bot] using proxy: %s" % _redact(self._proxy))
|
|
397
397
|
backoff = 2.0
|
|
398
398
|
try:
|
|
399
399
|
proxy = self._proxy or None
|
|
@@ -412,7 +412,7 @@ class QQBotChannel(Channel):
|
|
|
412
412
|
if not self._running:
|
|
413
413
|
break
|
|
414
414
|
self._fail_start("%s: %s" % (type(exc).__name__, exc))
|
|
415
|
-
print("[qq_bot]
|
|
415
|
+
print("[qq_bot] gateway disconnected, reconnecting in %d s" % int(backoff))
|
|
416
416
|
await asyncio.sleep(backoff)
|
|
417
417
|
backoff = min(backoff * 2, 60.0)
|
|
418
418
|
finally:
|
|
@@ -433,7 +433,7 @@ class QQBotChannel(Channel):
|
|
|
433
433
|
component_vars={"msg": message},
|
|
434
434
|
error_tpl="{msg}", error_vars={"msg": message})
|
|
435
435
|
except Exception as exc:
|
|
436
|
-
print("[qq_bot]
|
|
436
|
+
print("[qq_bot] failed to record incident (%s: %s)" % (type(exc).__name__, exc))
|
|
437
437
|
|
|
438
438
|
async def _gateway_once(self, proxy: str | None) -> None:
|
|
439
439
|
"""连一次网关,直到它自己断开或要求重连。"""
|
|
@@ -474,7 +474,7 @@ class QQBotChannel(Channel):
|
|
|
474
474
|
if op == 11:
|
|
475
475
|
continue
|
|
476
476
|
if op == 7:
|
|
477
|
-
print("[qq_bot]
|
|
477
|
+
print("[qq_bot] platform requested reconnect")
|
|
478
478
|
return
|
|
479
479
|
if op == 9:
|
|
480
480
|
self._seq = None
|
|
@@ -548,13 +548,13 @@ class QQBotChannel(Channel):
|
|
|
548
548
|
except asyncio.CancelledError:
|
|
549
549
|
raise
|
|
550
550
|
except Exception as exc:
|
|
551
|
-
print("[qq_bot]
|
|
551
|
+
print("[qq_bot] heartbeat stopped (%s: %s)" % (type(exc).__name__, exc))
|
|
552
552
|
|
|
553
553
|
async def _dispatch(self, event_type: str, data: dict) -> None:
|
|
554
554
|
if event_type == "READY":
|
|
555
555
|
user = data.get("user") or {}
|
|
556
556
|
self._bot_openid = str(user.get("id") or "")
|
|
557
|
-
print("[qq_bot]
|
|
557
|
+
print("[qq_bot] connected (bot id=%s)" % (self._bot_openid or "?"))
|
|
558
558
|
try:
|
|
559
559
|
from core import incidents as _inc
|
|
560
560
|
_inc.resolve("qq_bot_channel", "channel")
|
|
@@ -566,7 +566,7 @@ class QQBotChannel(Channel):
|
|
|
566
566
|
try:
|
|
567
567
|
await self._handle_message(event_type, data)
|
|
568
568
|
except Exception as exc:
|
|
569
|
-
print("[qq_bot]
|
|
569
|
+
print("[qq_bot] error handling message (%s: %s)" % (type(exc).__name__, exc))
|
|
570
570
|
|
|
571
571
|
# 入站
|
|
572
572
|
|
|
@@ -594,7 +594,7 @@ class QQBotChannel(Channel):
|
|
|
594
594
|
if not target_id:
|
|
595
595
|
#: 只打键名,不打值 —— 那些值里是用户的 openid。
|
|
596
596
|
#: 打出来是为了下一次现场能把它补进 `_c2c_openid` 那张表。
|
|
597
|
-
print("[qq_bot]
|
|
597
|
+
print("[qq_bot] event has no reply target, skipped (t=%s, top-level keys=%s)"
|
|
598
598
|
% (event_type, ",".join(sorted(str(k) for k in data))))
|
|
599
599
|
return
|
|
600
600
|
|
|
@@ -614,8 +614,8 @@ class QQBotChannel(Channel):
|
|
|
614
614
|
)
|
|
615
615
|
self._budget.remember(str(session), scope, msg_id)
|
|
616
616
|
|
|
617
|
-
text = chain.content[:80] if chain.content else "[
|
|
618
|
-
print("[qq_bot] %s
|
|
617
|
+
text = chain.content[:80] if chain.content else "[media]"
|
|
618
|
+
print("[qq_bot] %s message received: %s" % (scope, text))
|
|
619
619
|
|
|
620
620
|
message = Message(
|
|
621
621
|
sender_id=sender_id,
|
|
@@ -651,7 +651,7 @@ class QQBotChannel(Channel):
|
|
|
651
651
|
try:
|
|
652
652
|
path = await self._download_one(item, url)
|
|
653
653
|
except Exception as exc:
|
|
654
|
-
print("[qq_bot]
|
|
654
|
+
print("[qq_bot] failed to download attachment (%s: %s)"
|
|
655
655
|
% (type(exc).__name__, exc))
|
|
656
656
|
path = ""
|
|
657
657
|
if path:
|
|
@@ -663,7 +663,7 @@ class QQBotChannel(Channel):
|
|
|
663
663
|
async def _download_one(self, item: dict, url: str) -> str:
|
|
664
664
|
size = int((item or {}).get("size") or 0)
|
|
665
665
|
if size > _MAX_DOWNLOAD_BYTES:
|
|
666
|
-
print("[qq_bot]
|
|
666
|
+
print("[qq_bot] attachment too large (%d bytes), not downloading" % size)
|
|
667
667
|
return ""
|
|
668
668
|
name = str((item or {}).get("filename") or "")
|
|
669
669
|
suffix = Path(name).suffix or ".bin"
|
|
@@ -697,7 +697,7 @@ class QQBotChannel(Channel):
|
|
|
697
697
|
try:
|
|
698
698
|
await self._drain_delivered(session)
|
|
699
699
|
except Exception as exc:
|
|
700
|
-
print("[qq_bot]
|
|
700
|
+
print("[qq_bot] error sending pending delivery files (%s: %s)"
|
|
701
701
|
% (type(exc).__name__, exc))
|
|
702
702
|
|
|
703
703
|
async def _send_text(self, scope: str, target_id: str, text: str,
|
|
@@ -730,10 +730,10 @@ class QQBotChannel(Channel):
|
|
|
730
730
|
if resp.status in (200, 201, 202):
|
|
731
731
|
return True
|
|
732
732
|
status, body = resp.status, await resp.text()
|
|
733
|
-
print("[qq_bot]
|
|
733
|
+
print("[qq_bot] send rejected (%d): %s" % (status, body[:200]))
|
|
734
734
|
return False
|
|
735
735
|
except Exception as exc:
|
|
736
|
-
print("[qq_bot]
|
|
736
|
+
print("[qq_bot] send failed (%s: %s)" % (type(exc).__name__, exc))
|
|
737
737
|
return False
|
|
738
738
|
|
|
739
739
|
async def send(self, session: MessageSession, content: str | MessageChain) -> bool:
|
|
@@ -763,7 +763,7 @@ class QQBotChannel(Channel):
|
|
|
763
763
|
"""
|
|
764
764
|
path = Path(file_path or "")
|
|
765
765
|
if not path.is_file():
|
|
766
|
-
print("[qq_bot]
|
|
766
|
+
print("[qq_bot] file to send does not exist: %s" % file_path)
|
|
767
767
|
return False
|
|
768
768
|
scope = "group" if session.message_type is MessageType.GROUP else "c2c"
|
|
769
769
|
target_id = str(session.session_id)
|
|
@@ -780,16 +780,16 @@ class QQBotChannel(Channel):
|
|
|
780
780
|
proxy=self._proxy or None) as resp:
|
|
781
781
|
if resp.status not in (200, 201, 202):
|
|
782
782
|
status, body = resp.status, await resp.text()
|
|
783
|
-
print("[qq_bot]
|
|
783
|
+
print("[qq_bot] file upload rejected (%d): %s" % (status, body[:200]))
|
|
784
784
|
return False
|
|
785
785
|
info = await resp.json(content_type=None)
|
|
786
786
|
except Exception as exc:
|
|
787
|
-
print("[qq_bot]
|
|
787
|
+
print("[qq_bot] file upload failed (%s: %s)" % (type(exc).__name__, exc))
|
|
788
788
|
return False
|
|
789
789
|
|
|
790
790
|
file_info = str((info or {}).get("file_info") or "")
|
|
791
791
|
if not file_info:
|
|
792
|
-
print("[qq_bot]
|
|
792
|
+
print("[qq_bot] upload succeeded but no file_info, cannot send message")
|
|
793
793
|
return False
|
|
794
794
|
|
|
795
795
|
msg_id, _ = self._budget.last_for(str(session))
|
|
@@ -806,10 +806,10 @@ class QQBotChannel(Channel):
|
|
|
806
806
|
if resp.status in (200, 201, 202):
|
|
807
807
|
return True
|
|
808
808
|
status, body = resp.status, await resp.text()
|
|
809
|
-
print("[qq_bot]
|
|
809
|
+
print("[qq_bot] file message rejected (%d): %s" % (status, body[:200]))
|
|
810
810
|
return False
|
|
811
811
|
except Exception as exc:
|
|
812
|
-
print("[qq_bot]
|
|
812
|
+
print("[qq_bot] file message failed (%s: %s)" % (type(exc).__name__, exc))
|
|
813
813
|
return False
|
|
814
814
|
|
|
815
815
|
async def _drain_delivered(self, session: MessageSession) -> int:
|
|
@@ -827,7 +827,7 @@ class QQBotChannel(Channel):
|
|
|
827
827
|
channel="qq_bot_channel",
|
|
828
828
|
user_id=str(getattr(session, "session_id", "") or ""))
|
|
829
829
|
except Exception as exc:
|
|
830
|
-
print("[qq_bot]
|
|
830
|
+
print("[qq_bot] failed to fetch pending files (%s: %s)" % (type(exc).__name__, exc))
|
|
831
831
|
return 0
|
|
832
832
|
sent = 0
|
|
833
833
|
for rec in recs:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
kind: channel
|
|
2
|
-
name: qq_bot_channel
|
|
3
|
-
description: QQ Bot adapter — official Bot API v2 (WebSocket gateway + REST)
|
|
4
|
-
version: 0.1.0
|
|
1
|
+
kind: channel
|
|
2
|
+
name: qq_bot_channel
|
|
3
|
+
description: QQ Bot adapter — official Bot API v2 (WebSocket gateway + REST)
|
|
4
|
+
version: 0.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""Telegram channel adapter."""
|
|
1
|
+
"""Telegram channel adapter."""
|
|
@@ -333,7 +333,7 @@ class TelegramChannel(Channel):
|
|
|
333
333
|
#: 再处理一遍(去重缓存重启后是空的,拦不住)。
|
|
334
334
|
offset = _load_offset()
|
|
335
335
|
if offset:
|
|
336
|
-
print("[telegram]
|
|
336
|
+
print("[telegram] resuming from last cursor (update_id >= %d)" % offset)
|
|
337
337
|
|
|
338
338
|
while self._running:
|
|
339
339
|
retries = 0
|
|
@@ -386,14 +386,14 @@ class TelegramChannel(Channel):
|
|
|
386
386
|
except Exception: # noqa: BLE001
|
|
387
387
|
chat_id = None
|
|
388
388
|
if chat_id is None or self._bot is None:
|
|
389
|
-
print("[telegram]
|
|
389
|
+
print("[telegram] could not handle message and no chat to reply to -- logging only")
|
|
390
390
|
return
|
|
391
391
|
try:
|
|
392
392
|
await self._bot.send_message(
|
|
393
393
|
chat_id=chat_id,
|
|
394
394
|
text="⚠️ 消息遗失,未接收,需要时请重新发送。")
|
|
395
395
|
except Exception as e: # noqa: BLE001
|
|
396
|
-
print(f"[telegram]
|
|
396
|
+
print(f"[telegram] failed to send lost-message notice: "
|
|
397
397
|
f"{type(e).__name__}: {e}")
|
|
398
398
|
|
|
399
399
|
async def terminate(self) -> None:
|
|
@@ -441,7 +441,7 @@ class TelegramChannel(Channel):
|
|
|
441
441
|
and not tg_media.addressed_to_bot(
|
|
442
442
|
getattr(update, "message", None),
|
|
443
443
|
self._bot_username, self._bot_id)):
|
|
444
|
-
print("[telegram]
|
|
444
|
+
print("[telegram] group message not addressed to me, skipped (chat=%s)"
|
|
445
445
|
% session.session_id)
|
|
446
446
|
return None
|
|
447
447
|
|
|
@@ -493,7 +493,7 @@ class TelegramChannel(Channel):
|
|
|
493
493
|
try:
|
|
494
494
|
await self._drain_delivered(self._make_session(update))
|
|
495
495
|
except Exception as e: # noqa: BLE001
|
|
496
|
-
print(f"[telegram]
|
|
496
|
+
print(f"[telegram] error sending pending delivery files ({type(e).__name__}: {e})")
|
|
497
497
|
|
|
498
498
|
async def send(self, session: MessageSession, content: str | MessageChain) -> bool:
|
|
499
499
|
"""没有 Bot 就是没送达 —— 以前这一支什么都不做、也不出声。
|
|
@@ -505,11 +505,11 @@ class TelegramChannel(Channel):
|
|
|
505
505
|
这条路上,那是文件唯一的出口(同微信 / 飞书 / 钉钉)。
|
|
506
506
|
"""
|
|
507
507
|
if not self._bot:
|
|
508
|
-
print(f"[telegram]
|
|
508
|
+
print(f"[telegram] no Bot instance, not delivered: {session.session_id}")
|
|
509
509
|
return False
|
|
510
510
|
chat_id = _chat_id_of(session)
|
|
511
511
|
if chat_id is None:
|
|
512
|
-
print(f"[telegram]
|
|
512
|
+
print(f"[telegram] chat id is not numeric, cannot send: {session.session_id!r}")
|
|
513
513
|
return False
|
|
514
514
|
text = content if isinstance(content, str) else content.content
|
|
515
515
|
delivered = False
|
|
@@ -528,7 +528,7 @@ class TelegramChannel(Channel):
|
|
|
528
528
|
(用户先看到文件、再看到回答)。判据见 `channels/base.py::send_note`。
|
|
529
529
|
"""
|
|
530
530
|
if not self._bot:
|
|
531
|
-
print(f"[telegram]
|
|
531
|
+
print(f"[telegram] no Bot instance, note not delivered: {session.session_id}")
|
|
532
532
|
return False
|
|
533
533
|
chat_id = _chat_id_of(session)
|
|
534
534
|
if chat_id is None or not str(text or "").strip():
|
|
@@ -571,15 +571,15 @@ class TelegramChannel(Channel):
|
|
|
571
571
|
签名,`deliver_file` 那侧按属性存在认通道。
|
|
572
572
|
"""
|
|
573
573
|
if not self._bot:
|
|
574
|
-
print("[telegram]
|
|
574
|
+
print("[telegram] no Bot instance, cannot send attachment")
|
|
575
575
|
return False
|
|
576
576
|
p = Path(str(file_path or ""))
|
|
577
577
|
if not p.is_file():
|
|
578
|
-
print("[telegram]
|
|
578
|
+
print("[telegram] file to send does not exist: %s" % (file_path or "(empty)"))
|
|
579
579
|
return False
|
|
580
580
|
chat_id = _chat_id_of(session)
|
|
581
581
|
if chat_id is None:
|
|
582
|
-
print(f"[telegram]
|
|
582
|
+
print(f"[telegram] chat id is not numeric, cannot send attachment: {session.session_id!r}")
|
|
583
583
|
return False
|
|
584
584
|
name = filename or p.name
|
|
585
585
|
kind = tg_media.outbound_kind(name)
|
|
@@ -595,9 +595,9 @@ class TelegramChannel(Channel):
|
|
|
595
595
|
self._bot.send_document, chat_id=chat_id,
|
|
596
596
|
document=upload)
|
|
597
597
|
except Exception as exc: # noqa: BLE001
|
|
598
|
-
print(f"[telegram]
|
|
598
|
+
print(f"[telegram] attachment send failed ({type(exc).__name__}: {exc})")
|
|
599
599
|
return False
|
|
600
|
-
print("[telegram]
|
|
600
|
+
print("[telegram] attachment sent: %s (%s)" % (name, kind))
|
|
601
601
|
return True
|
|
602
602
|
|
|
603
603
|
async def _drain_delivered(self, session: MessageSession) -> int:
|
|
@@ -616,7 +616,7 @@ class TelegramChannel(Channel):
|
|
|
616
616
|
channel="telegram_channel",
|
|
617
617
|
user_id=str(getattr(session, "session_id", "") or ""))
|
|
618
618
|
except Exception as exc: # noqa: BLE001
|
|
619
|
-
print(f"[telegram]
|
|
619
|
+
print(f"[telegram] failed to fetch pending files ({type(exc).__name__}: {exc})")
|
|
620
620
|
return 0
|
|
621
621
|
sent = 0
|
|
622
622
|
for rec in recs:
|
|
@@ -653,11 +653,11 @@ class TelegramChannel(Channel):
|
|
|
653
653
|
for item in tg_media.items_of(tg_msg):
|
|
654
654
|
file_id = str(item.get("file_id") or "")
|
|
655
655
|
if not file_id:
|
|
656
|
-
print("[telegram]
|
|
656
|
+
print("[telegram] media has no file_id, skipped (kind=%s)" % item.get("kind"))
|
|
657
657
|
continue
|
|
658
658
|
size = int(item.get("size") or 0)
|
|
659
659
|
if size > tg_media.MAX_DOWNLOAD_BYTES:
|
|
660
|
-
print("[telegram]
|
|
660
|
+
print("[telegram] attachment too large (%d bytes > %d), not downloaded: %s"
|
|
661
661
|
% (size, tg_media.MAX_DOWNLOAD_BYTES, item.get("name")))
|
|
662
662
|
continue
|
|
663
663
|
try:
|
|
@@ -667,10 +667,10 @@ class TelegramChannel(Channel):
|
|
|
667
667
|
tg_media.ext_of(item)))
|
|
668
668
|
await tg_file.download_to_drive(path)
|
|
669
669
|
out.append((item, str(path)))
|
|
670
|
-
print("[telegram]
|
|
670
|
+
print("[telegram] attachment saved: %s (%s, %d bytes)"
|
|
671
671
|
% (path.name, item.get("kind"), size))
|
|
672
672
|
except Exception as exc: # noqa: BLE001
|
|
673
|
-
print(f"[telegram]
|
|
673
|
+
print(f"[telegram] failed to fetch attachment ({type(exc).__name__}: {exc})")
|
|
674
674
|
return out
|
|
675
675
|
|
|
676
676
|
# ------------------------------------------------------------------
|
|
@@ -697,7 +697,7 @@ class TelegramChannel(Channel):
|
|
|
697
697
|
wait = _retry_after_of(exc)
|
|
698
698
|
if wait is None:
|
|
699
699
|
raise
|
|
700
|
-
print("[telegram]
|
|
700
|
+
print("[telegram] rate limited, retrying once in %.0f s" % wait)
|
|
701
701
|
await asyncio.sleep(wait)
|
|
702
702
|
return await fn(*args, **kwargs)
|
|
703
703
|
|
|
@@ -730,7 +730,7 @@ def _load_offset(path: Path | None = None) -> int:
|
|
|
730
730
|
except FileNotFoundError:
|
|
731
731
|
return 0
|
|
732
732
|
except Exception as exc: # noqa: BLE001
|
|
733
|
-
print("[telegram]
|
|
733
|
+
print("[telegram] cannot read cursor, starting from 0 (backlog may replay): %s: %s"
|
|
734
734
|
% (type(exc).__name__, exc))
|
|
735
735
|
return 0
|
|
736
736
|
try:
|
|
@@ -749,7 +749,7 @@ def _save_offset(value: int, path: Path | None = None) -> None:
|
|
|
749
749
|
tmp.replace(p)
|
|
750
750
|
except Exception as exc: # noqa: BLE001
|
|
751
751
|
# 写不进去也要出声:否则下次重启静默重放
|
|
752
|
-
print("[telegram]
|
|
752
|
+
print("[telegram] cannot write cursor (backlog replays on restart): %s: %s"
|
|
753
753
|
% (type(exc).__name__, exc))
|
|
754
754
|
|
|
755
755
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
kind: channel
|
|
2
|
-
name: telegram_channel
|
|
3
|
-
description: Telegram Bot adapter — multi-user messaging via Telegram Bot API
|
|
4
|
-
version: 0.1.0
|
|
1
|
+
kind: channel
|
|
2
|
+
name: telegram_channel
|
|
3
|
+
description: Telegram Bot adapter — multi-user messaging via Telegram Bot API
|
|
4
|
+
version: 0.1.0
|