All plugins

feishu-card2

Feishu/Lark Card JSON 2.0 and CardKit v1 streaming gateway platform adapter (feishu_card2) for Hermes Agent, with typewriter streaming, on-demand collapsible thinking and tool timelines, synchronous approval/clarify/model-picker interactive cards, and budget-aware markdown rollover. Disclosure — opens a background lark-oapi WebSocket listener and persistent HTTPS connections to open.feishu.cn or open.larksuite.com (or a configured domain), reads its FEISHU_CARD2_* credentials through Hermes' secret scope, downloads inbound media and uploads reply attachments, and runs in-process as a platform adapter; no telemetry or self-updating code.

HateYouLittlePlatformv0.1.1Updated 1 hour ago

About

Feishu/Lark Card JSON 2.0 and CardKit v1 streaming gateway platform adapter (feishu_card2) for Hermes Agent, with typewriter streaming, on-demand collapsible thinking and tool timelines, synchronous approval/clarify/model-picker interactive cards, and budget-aware markdown rollover. Disclosure — opens a background lark-oapi WebSocket listener and persistent HTTPS connections to open.feishu.cn or open.larksuite.com (or a configured domain), reads its FEISHU_CARD2_* credentials through Hermes' secret scope, downloads inbound media and uploads reply attachments, and runs in-process as a platform adapter; no telemetry or self-updating code.

hermes-feishu-card2

Independent third-party Feishu / Lark Card JSON 2.0 & CardKit v1 streaming gateway platform plugin for Hermes Agent (Manifest v2, plugin ID feishu-card2, registered platform feishu_card2).

This plugin uses only the public Hermes plugin APIs (register_platform, public register_hook events, gateway.platforms._shared, and gateway.session_context) with zero runtime overrides or patches to Hermes core.

Why feishu-card2 vs. the bundled feishu-platform

  • CardKit v1 native typewriter streaming: Uses POST /open-apis/cardkit/v1/cards, PUT .../content, and PATCH .../settings over a persistent keep-alive httpx.AsyncClient to stream Markdown segments smoothly and write a non-empty config.summary.content on close.
  • On-demand collapsible thinking & tool timeline: Creates the collapsible thinking/tool panel dynamically only when reasoning deltas (on_stream_delta) or tool calls (pre_tool_call / post_tool_call) actually occur, isolated per turn via gateway.session_context.get_session_env and surface.
  • Card JSON 2.0 budget guard & Markdown-aware rollover:
    • Enforces config.width_mode: "fill" (prevents 230099 caused by legacy wide_screen_mode).
    • Converts table #6+ to aligned code blocks to respect Feishu's 5-table card limit (11310).
    • Splits cards cleanly at Markdown boundaries (closing/reopening code fences) before exceeding 28 KB or 180 elements, with fallback to static Card 2.0 or plain text.
  • Rich interactive card callbacks (card.action.trigger): Synchronous (<3 s) card updates for approval prompts, Clarify single/multi-select and free-text forms, paginated model pickers, and custom button/form forwarding with gateway.approval_actor authorization checks.

Quick Install & Setup

# Install from the Hermes Plugin Catalog (once listed)
hermes plugins install feishu-card2

# Or install directly from GitHub
hermes plugins install HateYouLittle/hermes-feishu-card2

# Configure FEISHU_CARD2_* credentials interactively
hermes gateway setup

Note: Disable the built-in feishu platform if you run feishu_card2 with the same Feishu/Lark bot credentials to avoid duplicate WebSocket listeners.

Configuration: language Setting (English-First)

User-facing cards, approval buttons, picker navigation, callback toasts, and hermes gateway setup prompts default to English (en).

To switch all user-facing copy to Simplified Chinese (zh), set:

hermes config set plugins.entries.feishu-card2.settings.language zh

Supported values:

  • en (default; locales such as en-US normalize to en)
  • zh (locales such as zh-CN / zh_CN normalize to zh; unrecognized values fall back to en)

Security & Behavior Disclosure

  • External network connections: Establishes a background WebSocket long connection (lark-oapi) and persistent HTTPS REST connections (httpx.AsyncClient) to open.feishu.cn (or open.larksuite.com, or a user-configured HTTPS domain) for bot probing, CardKit v1 streaming, IM messaging, interactive callbacks, and inbound/outbound media transfers.
  • Credentials & access control: Reads FEISHU_CARD2_APP_ID, FEISHU_CARD2_APP_SECRET, and optional FEISHU_CARD2_* settings exclusively via Hermes's profile-scoped config/secret helpers (extra_or_secret), never directly from .env files or other tools' credential stores.
  • File & media access: Downloads inbound Feishu images/files/audio into Hermes's temp/media cache directory, uploads explicit MEDIA:/absolute/path/to/file attachments referenced in agent replies, and fetches outbound image URLs through Hermes's SSRF-checked HTTP client (platform_http_client).
  • Telemetry & updates: Zero telemetry or usage reporting; no self-updating code; no runtime monkey-patching of Hermes core.

中文文档

Hermes Agent 的独立第三方 飞书 / Lark Card JSON 2.0 & CardKit v1 流式渠道插件(Manifest v2,插件 ID feishu-card2,注册平台名 feishu_card2)。

本插件完全遵循 Hermes 公开插件 API(plugin_api.json 白名单),无需修改 Hermes 核心源码即可安装启用。


核心特性

  • CardKit v1 原生流式打字机卡片:基于 POST /open-apis/cardkit/v1/cards + PUT .../content + PATCH .../settings,按节流窗口刷新全量分段正文,自动删除占位节点,关闭流式时保证写入 summary.content(防 99992402)。
  • 按需思考与工具折叠面板:默认不渲染空 thinking_panel,仅当实际收到 on_stream_delta(delta_type="reasoning") 或 pre_tool_call / post_tool_call 时动态 POST .../elements 插入折叠面板,并通过 gateway.session_context.get_session_env + surface 严格隔离跨平台串台。
  • Card JSON 2.0 预算保护与自动拆卡:
    • 统一使用 config.width_mode: "fill"(杜绝 wide_screen_mode 引发 230099)。
    • 表格数超过 5 张自动降级第 6 张及以后为对齐代码块(防 11310)。
    • 单卡超 28 KB 或 180 元素 时按 Markdown 边界拆卡(自动闭合/重开代码块 fence 并更新 segment_start_offset),不可恢复时三级降级到静态 Card 2.0 或纯文本。
  • 完整交互卡片(3 秒内同步替换):
    • 高危命令审批(允许一次 / 本会话允许 / 始终允许 / 拒绝)。
    • Clarify 单选、自定义文本追问与多选表单(顶层 form)。
    • 分页模型选择器与通用选项选择器。
    • 自定义 Card 2.0 按钮与 form_value 表单转发(去前导 / 防命令注入,合法使用 open_message_id 锚点)。
  • 多模态与 Cron 独立投递:支持入站图片/富文本/文件/语音下载缓存、SSRF 安全外链图片拉取(platform_http_client)、以及 standalone_send Cron Card 2.0 卡片投递。

模块结构

  • plugin.yaml / pyproject.toml:Manifest v2 声明与依赖上限声明(lark-oapi>=1.6.8,<2)
  • __init__.py:轻量 register(ctx) 入口(无顶层 SDK 重导入)
  • config.py:接入凭据(extra_or_secret)与 config_schema 展示开关分离解析
  • transport.py:lark-oapi 异步 REST 封装、/open-apis/bot/v3/info 探针与后台线程 WebSocket 长连接
  • adapter.py:FeishuCard2Adapter(收发、群 @mention 过滤、话题锚定、原生流式、交互卡片与媒体方法)
  • card_budget.py:Schema 2.0 校验、代码块清洗、5 表格上限降级、28 KB / 180 元素预算与 Markdown-aware 拆卡
  • card_builder.py:流式卡、思考工具折叠块、静态/Cron 卡、审批/Clarify/模型选择器模板
  • card_stream.py:单卡 asyncio.Lock、单调 sequence、10 QPS 令牌桶、分段游标拆卡与错误码自愈
  • turn_registry.py:基于 get_session_env 与 surface 的 Hook ↔ 流式会话隔离关联表
  • card_actions.py:card.action.trigger 3 秒同步响应与 gateway.approval_actor 越权拦截
  • media.py:入站/出站媒体上传下载
  • standalone.py:Cron / hermes send 独立 Card 2.0 投递器
  • setup_wizard.py:hermes gateway setup 交互式配置向导
  • scripts/feishu_smoke.py:离线 Schema 检验(--dry-run)与真实群聊冒烟脚本

飞书开放平台准备

  1. 在飞书开放平台(或 Lark)创建企业自建应用,启用机器人能力。
  2. 建议开通应用权限:
    • im:message、im:message:send_as_bot、im:message:readonly、im:message.group_at_msg:readonly、im:message.p2p_msg:readonly
    • im:resource(收发图片/文件/语音)
    • im:chat:readonly(查询群名称/类型)
    • cardkit:card:write、cardkit:card:read(CardKit v1 流式卡片必需)
  3. 在「事件与回调」中选择 使用长连接接收事件(WebSocket):
    • 订阅事件:im.message.receive_v1
    • 订阅回调:card.action.trigger
  4. 发布应用版本使权限与事件订阅生效。

安装与配置

1. 运行交互配置向导

hermes gateway setup

选择 Feishu Card 2.0 (feishu_card2) 后依次输入:

  • FEISHU_CARD2_APP_ID / FEISHU_CARD2_APP_SECRET
  • FEISHU_CARD2_DOMAIN(feishu 或 lark)
  • FEISHU_CARD2_ALLOWED_USERS / FEISHU_CARD2_ALLOW_ALL_USERS / FEISHU_CARD2_GROUP_ALLOWED_CHATS
  • FEISHU_CARD2_HOME_CHANNEL(用于 hermes cron run 与 hermes send --deliver feishu_card2)

2. 调整插件卡片开关(config_schema)

hermes config set plugins.entries.feishu-card2.settings.streaming_enabled true
hermes config set plugins.entries.feishu-card2.settings.show_thinking true
hermes config set plugins.entries.feishu-card2.settings.show_tool_timeline true
hermes config set plugins.entries.feishu-card2.settings.throttle_ms 200
hermes config set plugins.entries.feishu-card2.settings.require_mention_in_group true
hermes config set plugins.entries.feishu-card2.settings.language zh   # 可选:"en"(默认)或 "zh"(简体中文)

若要在思考折叠区中实时接收模型推理增量,请确认宿主配置开启:

hermes config set plugins.stream_reasoning_deltas true

开发测试与冒烟验证

# 插件目录静态规范与公开 API 白名单检查
hermes plugins validate .
hermes plugins doctor . --ci

# 离线单元测试
hermes --run-module unittest discover -s tests -p "test_*.py" -v

# 离线 Schema / 预算 / 拆卡自检(无需凭据)
python scripts/feishu_smoke.py --dry-run

# 真实飞书测试群端到端冒烟
FEISHU_E2E_APP_ID=cli_xxx \
FEISHU_E2E_APP_SECRET=xxx \
FEISHU_E2E_CHAT_ID=oc_xxx \
  python scripts/feishu_smoke.py --scenario all

常见飞书错误码排查

错误码原因说明插件内建处理 / 排查建议
230099Card 2.0 中出现了旧版 1.0 wide_screen_modecard_budget.sanitize_card_schema2 自动清理并强制 width_mode: "fill"
11310单张卡片内 Markdown 表格超过 5 个自动保留前 5 个表格,第 6 个起转为对齐代码块
200860单卡请求体超过 30 KB 平台硬上限按 28 KB 软上限在 Markdown 边界触发分段拆卡(ROLLOVER)
200850CardKit 流式模式超时自动关闭自动尝试 PATCH /settings 重开流式,失败则封存旧卡并新开续答卡
200810应用未开启 cardkit:card:write 或被限流自动降级为静态 Card 2.0 或纯文本发送;请核对开放平台权限
300317并发更新导致 sequence 乱序/重复单卡 asyncio.Lock 串行写 + 冲突自动顺延重试
99992402关流时 summary.content 为空或字段校验失败build_settings_payload 保证始终写入非空摘要
9499DELETE .../elements/:id 缺少请求体 sequencecard_stream._delete_element_safe 强制将 sequence 置于 JSON 请求体
99992354回复锚点传入了非法 reply_to message_idopen_message_id 为空时不设回复锚点,直接走 send_message

README from the reviewed commit b7a0e0e; it updates when the author re-pins.

Developer Mode

Explore built-in Hermes toolsets and actions.

HermesAgent

Developer?

Create a Hermes extension for Desktop or agent workflows.

Developer Section