Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/openmate_core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,11 @@ def m_inbox_collect(self, params: dict) -> dict:
if th["_chat"] not in known or known[th["_chat"]][1] < now - t.avatar_ttl)))
for th in things:
del th["_chat"]
if self.platform.inbox_extra is not None:
try:
things.extend(self.platform.inbox_extra(self))
except Exception as e:
log.warning("the platform Inbox source failed (%s)", type(e).__name__)
if epoch != self.account_epoch():
return {"things": []} # read partly for another account (its rows, its pictures): none of it is handed over
return {"things": things}
Expand Down
4 changes: 4 additions & 0 deletions core/openmate_core/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class Platform:
#: run may answer {"text", "images"} instead, its pictures for the model (modelimages.Pictures), which go only to a
#: hub that takes them (tool_images)
tools: Optional[Callable[[Any], Dict[str, Any]]] = None
#: Platform actions: app → {tool name: (schema, describe(args), do(args, key, as_asked))}.
write_tools: Optional[Callable[[Any], Dict[str, Any]]] = None
#: Additional things for the connector Inbox, using the same wire shape as chat items.
inbox_extra: Optional[Callable[[Any], list]] = None
#: the platform's read tool that fetches a message's pictures and files by its id (Feishu: matefeishu_media). The
#: chat lines models read (the messages tool, /agent's context) name it after each message that has some; ""
#: names nothing (WeChat writes its local paths into the text itself)
Expand Down
21 changes: 17 additions & 4 deletions core/openmate_core/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The connector's tools (reads, no gate) and actions (writes: only after the hub's gate, the phone's confirmation).
"""The connector's read tools and actions (writes after confirmation through the hub).

Names are <connector id>_<what>, so another platform's connector reuses this module with its own prefix.
"""
Expand Down Expand Up @@ -127,12 +127,17 @@ def _rich(app, text: str, names=()) -> bool:
return bool(getattr(app.backend, "can_format", False)) and markup.formatted(text, names)


def _platform_writes(app) -> dict:
extra = getattr(app.platform, "write_tools", None)
return extra(app) if extra is not None else {}


def write_tools(app) -> List[dict]:
c, p = app.cid, app.platform.name
send = {"chat": {"type": "string", "description": "会话 id"},
"text": {"type": "string", "description": _text_words(app)},
"reply_to": {"type": "string", "description": "要回复的消息 id,可选"}}
what = "以我的身份在%s会话(私聊或群)里发一条消息,可以回复某条消息。每次都要我在手机上确认全文和发给谁。" % p
what = "以我的身份在%s会话(私聊或群)里发一条消息,可以回复某条消息。每次都要我在确认卡片上确认全文和发给谁。" % p
if getattr(app.backend, "can_mention", False):
send["at"] = {"type": "array", "items": {"type": "string"}, "maxItems": MENTIONS_MOST,
"description": "要 @ 的人的用户 id(%s_search 或消息里给出),可选。正文里写到的「@名字」会变成真正的 @,"
Expand All @@ -142,10 +147,10 @@ def write_tools(app) -> List[dict]:
what += "话题群和开了话题模式的群里,不给 reply_to 会开一个新话题,给 reply_to 就回复到那条所在的话题。"
return [
{"name": c + "_send", "description": what, "input_schema": _obj(send, ["chat", "text"])},
{"name": c + "_send_dm", "description": "以我的身份私聊一个%s用户(没有私聊会话时先建一个)。每次都要我在手机上确认全文和发给谁。" % p,
{"name": c + "_send_dm", "description": "以我的身份私聊一个%s用户(没有私聊会话时先建一个)。每次都要我在确认卡片上确认全文和发给谁。" % p,
"input_schema": _obj({"user": {"type": "string", "description": "对方的用户 id(%s_search 给出)" % c},
"text": {"type": "string", "description": _text_words(app)}}, ["user", "text"])},
]
] + [schema for schema, _, _ in _platform_writes(app).values()]


def _args(params: dict) -> dict:
Expand Down Expand Up @@ -713,6 +718,10 @@ def describe(app, params: dict) -> dict:
if name == c + "_send_dm":
_, _, visible, summary, _ = _dm_card(app, a)
return {"action": {"name": name, "visible": visible}, "summary": summary}
extra = _platform_writes(app).get(name)
if extra is not None:
visible, summary = extra[1](a)
return {"action": {"name": name, "visible": visible}, "summary": summary}
raise RPCError("没有这个写操作:%s" % name)


Expand Down Expand Up @@ -778,6 +787,10 @@ def send():
return {"text": "已私聊 %s" % who, "message_ref": mid}

return _result(app.send_once(key, name, send))
extra = _platform_writes(app).get(name)
if extra is not None:
known = app.send_known(key)
return _result(known if known is not None else extra[2](a, key, as_asked))
raise RPCError("没有这个写操作:%s" % name)


Expand Down
4 changes: 2 additions & 2 deletions extensions/openmate-feishu/assistant/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ OpenMate 把我的飞书私聊和群消息接进了 Persona,工具都以 `mate
- **查某个会话一段时间的消息、或在会话里找某个词,用 `matefeishu_messages` 的 `since` / `until` / `query`**(例如 `since: "2026-11-12 15:49"`、`until: "2026-11-12 16:15"`、`query: "周报"`),不要自己用 lark-cli 写循环去拉。它会自己往前补读历史;回答末尾有 `before=` 时,带上同样的条件和这个 `before` 接着查。
- **看飞书消息里的图片和文件用 `matefeishu_media`,不要用 lark-cli。** `matefeishu_messages` 和 /agent 的上下文里,带图片或文件的消息写着 `[图片](看图:matefeishu_media message=…)`:把这个 id 给 `matefeishu_media`,它把图片或文件下载到本机临时目录(25 MB 以内)并给出本地路径,图片直接读这个文件就能看。它是只读的,不会弹确认。下载不了时它会说原因(已撤回或过期、超过上限、飞书没登录等),如实转告,不要猜内容。
- **要真正 @ 群里的人或机器人,先用 `matefeishu_members` 查。** 它列出一个群里的人和机器人,带用户 id 和在这个群里显示的准确名字(只读,列表缓存几分钟)。发消息时把查到的 id 填进 `at`,正文里写「@显示名」;只在正文里打「@名字」不会真的提醒到对方,也不要猜同名的人。
- **必须自己用 lark-cli 读飞书时,一条命令只调一次 lark-cli,参数写成字面值。** 不要先把结果存进变量(`ids=$(jq … f)`),再把 `"$ids"` 传给 lark-cli:Persona 认不出这种写法是只读的,会把整条命令发到我手机上让我确认。要用上一步的结果,就把具体的值直接写进下一条命令;过滤输出用 `jq`、`head`、`grep`。
- **发消息一律以我的身份,每一条都要我在手机上确认。** 用 `matefeishu_send`(发到会话、可回复某条消息)或 `matefeishu_send_dm`(私聊某人,用户 id 先用 `matefeishu_search` 查)。确认卡片会写清发给谁、回复哪条和全文,所以要把完整的最终内容放进去,不要分几条试探着发。
- **必须自己用 lark-cli 读飞书时,一条命令只调一次 lark-cli,参数写成字面值。** 不要先把结果存进变量(`ids=$(jq … f)`),再把 `"$ids"` 传给 lark-cli:Persona 认不出这种写法是只读的,会显示整条命令的确认卡片。要用上一步的结果,就把具体的值直接写进下一条命令;过滤输出用 `jq`、`head`、`grep`。
- **发消息一律以我的身份,每一条都要我在确认卡片上确认。** 用 `matefeishu_send`(发到会话、可回复某条消息)或 `matefeishu_send_dm`(私聊某人,用户 id 先用 `matefeishu_search` 查)。确认卡片会写清发给谁、回复哪条和全文,所以要把完整的最终内容放进去,不要分几条试探着发。
- **结果不确定的发送不要重试。** 如果写操作说“结果不确定”或“不会再发”,说明那条消息可能已经发出去了:告诉我去飞书里看一眼,不要换个说法再发一遍。
- **/agent 请求要用回复工具答。** 当一条消息说明这是飞书里的 /agent 请求时,用 `matefeishu_agent_reply` 回复,`request` 必须填说明里给出的那个请求 id,不要用 `matefeishu_send` 代替。回复会以我的名义出现在提问的地方(话题里问的回到话题,也发到群里的同样也发到群里,群聊主界面问的在主界面引用回复),并自动带上 AI 代答标记:只写做完的事和查到的事实,没做的写成建议,不替我答应任何事。
撤回飞书里的请求消息也会停止它触发的 Agent,包括 `@自己` 和自动代答。
Expand Down
72 changes: 55 additions & 17 deletions extensions/openmate-feishu/openmate_feishu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

import logging
import os
from typing import Dict

Expand Down Expand Up @@ -52,13 +53,15 @@ def platform(manifest_path: str = "") -> Platform:
login_hint_scanned="已扫码,请在飞书手机 App 上点“确认登录”",
login_hint_expired="二维码过期了,已换一张新的,请重新扫码",
ui_pages=_agenda_pages,
start_services=_start_meetings,
archive_feeds={"meetings": _archive_meetings},
start_services=_start_services,
archive_feeds={"meetings": _archive_meetings, "mail": _archive_mail},
items_list=_meeting_items,
items_doc_title=_meeting_doc_title,
usage_query=_starkmesh_usage, # the sidebar's usage bars: the StarkMesh pool, from the 中转站 page's read
legacy_blocked_texts=(DLP_BLOCKED_TEXT,), # what told a blocked message before 0.11.29 stored the mark
tools=_read_tools,
write_tools=_write_tools,
inbox_extra=_inbox_extra,
media_tool=CONNECTOR_ID + "_media",
inbox_topics=True,
agent_task_wait=True, # a request whose conversation handed out work stays open until the answer comes
Expand All @@ -76,35 +79,67 @@ def _verify_at(app, chat_id, wanted):


def _read_tools(app):
from .mail import tools as mail_tools
from .media import media_tools
from .meetings import tools as meeting_tools
from .members import members_tools

return {**media_tools(app), **members_tools(app), **meeting_tools(app)}
return {**media_tools(app), **members_tools(app), **meeting_tools(app), **mail_tools(app)}


def _start_meetings(app):
from openmate_core.fixture import FixtureBackend
def _write_tools(app):
from .mail import write_tools

from .meetings import Meetings
from .today import PAGE
return write_tools(app)

def redraw():
if app.peer is not None:
for page in (PAGE, "calendar"):
app.peer.notify("ui.invalidate", {"contribution": page})

meetings = Meetings(app, on_change=redraw)
if app.connector_on and not isinstance(app.backend, FixtureBackend):
meetings.start()
app.meetings = meetings
def _start_services(app):
from openmate_core.fixture import FixtureBackend

from .approvals import Approvals
from .mail import Mail
from .meetings import Meetings
from .today import CARD, PAGE

def redraw(*pages):
def notify():
if app.peer is not None:
for page in pages:
try:
app.peer.notify("ui.invalidate", {"contribution": page})
except Exception:
pass
return notify

for name, service_class, pages in (
("meetings", Meetings, (PAGE, "calendar")),
("approvals", Approvals, (PAGE, CARD)),
("mail", Mail, (PAGE,)),
):
try:
service = service_class(app, on_change=redraw(*pages))
setattr(app, name, service)
if app.connector_on and not isinstance(app.backend, FixtureBackend):
service.start()
except Exception as error:
logging.getLogger("openmate.feishu").warning("could not start %s (%s)", name, type(error).__name__)


def _archive_meetings(app, after, limit):
service = getattr(app, "meetings", None)
return service.archive(after, limit) if service else ([], after, False)


def _archive_mail(app, after, limit):
service = getattr(app, "mail", None)
return service.archive(after, limit) if service else ([], after, False)


def _inbox_extra(app):
service = getattr(app, "mail", None)
return service.inbox() if service else []


def _meeting_items(app, params):
service = getattr(app, "meetings", None)
return service.items(params) if service else {"items": []}
Expand Down Expand Up @@ -137,6 +172,8 @@ def _agenda_pages(app):

shared = agenda.Agenda(app)
meetings = getattr(app, "meetings", None)
approvals = getattr(app, "approvals", None)
mail = getattr(app, "mail", None)
persona = today.PersonaToday(app)
wechat = today.PeerToday(app) # openmate-wechat's chats, when it is installed beside this one
mesh_read = starkmesh.StarkMesh(app)
Expand All @@ -162,8 +199,9 @@ def tell():
return {
agenda.PAGE: agenda.CalendarPage(app, shared, meetings=meetings),
agenda.CARD: agenda.CalendarPage(app, shared, card=True),
today.PAGE: today.TodayPage(app, shared, persona, mesh=mesh, agents=board, wechat=wechat, meetings=meetings),
today.CARD: today.TodayPage(app, shared, persona, card=True, wechat=wechat),
today.PAGE: today.TodayPage(app, shared, persona, mesh=mesh, agents=board, wechat=wechat, meetings=meetings,
approvals=approvals, mail=mail),
today.CARD: today.TodayPage(app, shared, persona, card=True, wechat=wechat, approvals=approvals),
starkmesh.PAGE: mesh, starkmesh.CARD: starkmesh.StarkMeshCard(mesh),
agents.PAGE: agents.AgentsPage(app, board), agents.CARD: agents.AgentsPage(app, board, card=True),
}
Expand Down
Loading
Loading