diff --git a/core/openmate_core/backend.py b/core/openmate_core/backend.py index 4d28d03..67390cd 100644 --- a/core/openmate_core/backend.py +++ b/core/openmate_core/backend.py @@ -85,6 +85,9 @@ class Message: title: str = "" #: User IDs from the service's real @ elements, for live handling only. mention_ids: List[str] = field(default_factory=list) + #: this reading says less than one before may have (a card read without its body, Feishu 2026-12-03): a text the + #: store has already stays; a message new to the store is kept with this one. Not stored. + keep_text: bool = False @dataclass diff --git a/core/openmate_core/store.py b/core/openmate_core/store.py index e119ad0..beb2df1 100644 --- a/core/openmate_core/store.py +++ b/core/openmate_core/store.py @@ -671,7 +671,9 @@ def run(db): "type = CASE WHEN ? != '' THEN ? ELSE type END, blocked = 1 " "WHERE chat_id = ? AND id = ? AND (text != ? OR blocked = 0)", (m.text or "", m.text or "", m.text or "", kind, m.chat_id, m.id, m.text or "")) - elif m.text: + elif m.text and not (m.keep_text and blank is None): + # (a reading that says less than one before keeps the stored text: blank is None here means it + # has one) # a blocked message stays so (a later reading that is not the note, a decode failure's # placeholder, never brings it to the archive); only a recall's notice replaces its note db.execute("UPDATE messages SET text = ?, type = ? WHERE chat_id = ? AND id = ? AND text != ? " diff --git a/extensions/openmate-feishu/openmate_feishu/larkagentx.py b/extensions/openmate-feishu/openmate_feishu/larkagentx.py index 0c3f19b..40d3cd0 100644 --- a/extensions/openmate-feishu/openmate_feishu/larkagentx.py +++ b/extensions/openmate-feishu/openmate_feishu/larkagentx.py @@ -138,6 +138,11 @@ CARDS_REREAD = "messages.PullMessagesByIdsRequest" # a card's message read again as a newer client (newer_api) CARD_REREAD_AGAIN = 600.0 # a card read again with no body is not read again before this long (an edit's push may)… CARD_REREAD_TRIES = 3 # …and at most this often in CARD_ASK_OFF; HTTP errors 3 times in a row: not read again that long +CARD_KEEP = 2000 # cards whose last reading with a body is kept (one read later without it shows that, never less) +CARD_DUE_MOST = 50 # pushed cards (an edit as it goes) left for after their wait, to be read once more then… +CARD_DUE_EVERY = 5.0 # …looked at this often while some are waiting; one that could not be read is tried again +CARD_DUE_AGAIN = 30.0 # this long after… +CARD_DUE_TRIES = 3 # …this many times in all CARDS_ASK_MOST = 50 # cards asked for at once (CARDS_ASK) CARD_HOLES_KEEP = 500 # cards read with no words, waiting to be asked for by their message id CARD_ASK_TRIES = 3 # …asked for at most this often (a failed ask leaves it for the next read) @@ -1095,6 +1100,8 @@ def __init__(self, lx: types.SimpleNamespace, region: str): self._card_asked: Dict[str, float] = {} # pushed card → when it was asked for (CARD_PUSH_AGAIN) self._card_ask_off = 0.0 # time.monotonic() until which cards are not asked for (CARD_ASK_OFF) self._card_reread: Dict[str, Tuple[int, float]] = {} # card → (readings again with no body, the last's time) + self._card_kept: Dict[str, Tuple[str, Tuple[str, ...]]] = {} # card → (its text, its @s) with a body, newest last + self._card_due: Dict[str, tuple] = {} # pushed card skipped in its wait → (its chat, when to read[, tries]) self._card_reread_off = 0.0 # time.monotonic() until which no card is read again (HTTP errors) self._card_reread_refused = 0 self._card_ask_refused = 0 # HTTP errors in a row asking for cards @@ -1202,6 +1209,7 @@ def _set_session(self, auth, client, acct: Account, creds: dict, since: Optional self._person_avatars.clear() self._peers.clear() self._doc_writer = None + self._forget_cards() self._auth, self._client, self._me, self._creds = auth, client, acct, creds self._session_no += 1 self._members.clear() # a sign-in reads every chat's members anew @@ -1347,6 +1355,7 @@ def logout(self) -> None: self._peers.clear() self._members.clear() self._doc_writer = None + self._forget_cards() with self._groups_mu: self._groups, self._groups_join, self._groups_owner, self._groups_at = [], {}, "", 0.0 self._groups_whole_ids = set() @@ -1524,7 +1533,11 @@ def _deliver(self, inbox: "queue.Queue", client, me: Account, on_message, on_rec while True: self._refresh_groups(client, me) # cheap unless due: due ones read in a thread of their own try: - item = inbox.get(timeout=GROUPS_SPACING) + self._cards_due(client, me, on_message) # pushed cards whose wait is over, read as they are now + except Exception as e: + log.info("cards due could not be read (%s)", type(e).__name__) + try: + item = inbox.get(timeout=CARD_DUE_EVERY if self._card_due else GROUPS_SPACING) except queue.Empty: continue if item is None: @@ -2141,6 +2154,16 @@ def _message(self, d: dict, me_id: str, client) -> Optional[Message]: data = dict(data, _extras=extras) text, has_body, card_ats = card_read(data, self._rich_reader, self._known_names(chat_id, me_id)) mentions |= {u for u in card_ats if u == "all" or u.isdigit()} + if has_body: + self._card_keep(msg_id, text, mentions) + else: + # a reading without its body (an edit pushed in its wait, a reading the service gave less) never shows + # less than one before did: the text and @s of the last reading with its body, until a newer one comes + with self._lock: + kept = self._card_kept.get(msg_id) + if kept is not None: + text = kept[0] + mentions |= set(kept[1]) if not has_body: # its content is kept apart: asked for by its message id (_fill_cards) header = data.get("cardHeader") or {} with self._lock: @@ -2310,7 +2333,20 @@ def _position(self, chat_id: str, value, client) -> int: def _rich_reader(self, rich: dict) -> str: return str(self.lx.decoders.extract_rich_text(rich) or "") - def _fill_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = False) -> None: + def _fill_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = False, force: bool = False) -> None: + """_fill_some_cards, then: a card still without its body is marked keep_text (the core keeps a text it has). + force: read again whatever waited before (a pushed card due after its wait, _cards_due).""" + with self._lock: + bodiless = [m for m in msgs if m is not None and m.type == "CARD" and m.id in self._card_holes] + before = {m.id: m.text for m in bodiless} + try: + self._fill_some_cards(client, msgs, me_id, pushed, force) + finally: + for m in bodiless: + if m.text == before[m.id]: # not filled: what it shows is less than a reading with its body + m.keep_text = True + + def _fill_some_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = False, force: bool = False) -> None: """Cards read with no words besides their header (their content is kept apart: a long one, a newer one, as _message noted): asked for by their message ids at once (entities.BatchPullUniversalCardsByBizRequest: the message's universal card entity), and their text, @s and at_me taken from it. One that still says nothing is @@ -2330,6 +2366,8 @@ def _fill_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = Fa for k in [k for k, t in asked.items() if now - t > CARD_PUSH_AGAIN]: del asked[k] if len(self._card_pushes) >= CARD_PUSH_ASKS_PER_MINUTE or m.id in asked: + if m.id in asked and (m.id in self._card_due or len(self._card_due) < CARD_DUE_MOST): + self._card_due[m.id] = (m.chat_id, asked[m.id] + CARD_PUSH_AGAIN) # read then, as it is continue self._card_pushes.append(now) asked[m.id] = now @@ -2337,7 +2375,7 @@ def _fill_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = Fa if not want: return if client is not None: - want = self._reread_cards(client, want, me_id, pushed) + want = self._reread_cards(client, want, me_id, pushed, force) if not want: return with self._lock: @@ -2401,13 +2439,14 @@ def _fill_cards(self, client, msgs: List[Message], me_id: str, pushed: bool = Fa continue m.text = clip_lines(h["head"] + words, CARD_TEXT_MOST) got = set(sorted(u for u in ats if u.isdigit())[:MENTIONS_MOST]) | ({"all"} & set(ats)) + self._card_keep(m.id, m.text, got) if "all" in got: m.at_all = True m.mention_ids = sorted(set(m.mention_ids or []) | (got - {"all"})) if me_id and me_id in got and not m.mine: m.at_me = True - def _reread_cards(self, client, want: list, me_id: str, pushed: bool = False) -> list: + def _reread_cards(self, client, want: list, me_id: str, pushed: bool = False, force: bool = False) -> list: """Cards with no body read again by their message ids as a newer client (newer_api, CARDS_REREAD: one request for them all): Feishu leaves a newer card's content out for the version LarkAgentX names and sends the "upgrade" stand-in instead (seen 2026-12-03: such a card's entity had only its card id, version and that rich @@ -2424,7 +2463,8 @@ def _reread_cards(self, client, want: list, me_id: str, pushed: bool = False) -> del self._card_reread[k] for m, h in want: tries, at = self._card_reread.get(m.id, (0, 0.0)) - if tries and not (pushed and m.edited) and (tries >= CARD_REREAD_TRIES or now - at < CARD_REREAD_AGAIN): + if tries and not force and not (pushed and m.edited) and ( + tries >= CARD_REREAD_TRIES or now - at < CARD_REREAD_AGAIN): left.append((m, h)) else: go.append((m, h)) @@ -2483,6 +2523,69 @@ def _reread_cards(self, client, want: list, me_id: str, pushed: bool = False) -> len(read), len(part)) return left + def _forget_cards(self) -> None: + """Under self._lock: what this session knew of cards (signed out, or another account): none of the next's.""" + self._card_holes.clear() + self._card_pushes.clear() + self._card_asked.clear() + self._card_reread.clear() + self._card_kept.clear() + self._card_due.clear() + self._cards_noted.clear() + self._card_ask_off = self._card_reread_off = 0.0 + self._card_ask_refused = self._card_reread_refused = 0 + + def _card_keep(self, mid: str, text: str, mentions) -> None: + """A card's reading with its body: what a later one without it shows (CARD_KEEP of them, the newest last).""" + with self._lock: + self._card_kept.pop(mid, None) + self._card_kept[mid] = (text, tuple(sorted(mentions))) + while len(self._card_kept) > CARD_KEEP: + del self._card_kept[next(iter(self._card_kept))] + + def _cards_due(self, client, me: Account, on_message) -> None: + """Pushed cards skipped in their wait (an edit as it goes: CARD_PUSH_AGAIN) are read once more when it is + over, as the card is then, and handed to the core again: the last edit's content, not the one before. Off + the connection's loop, from _deliver, at most CARD_DUE_MOST at a time.""" + now = time.monotonic() + with self._lock: + due = [(mid, v) for mid, v in self._card_due.items() if v[1] <= now][:CARD_DUE_MOST] + for mid, _ in due: + del self._card_due[mid] + if not due or client is None: + return + try: + ans = client.api("messages.PullMessagesByIdsRequest", {"messageIds": [mid for mid, _ in due]}) or {} + except Exception as e: + log.info("cards %s could not be read once more (%s)", ",".join(mid for mid, _ in due[:5]), type(e).__name__) + with self._lock: # a few times more, a while apart (CARD_DUE_TRIES) + if not self._still(me): + return # signed out or another account meanwhile: nothing of the one before is kept + for mid, v in due: + tries = (v[2] if len(v) > 2 else 0) + 1 + if tries < CARD_DUE_TRIES and mid not in self._card_due and len(self._card_due) < CARD_DUE_MOST: + self._card_due[mid] = (v[0], now + CARD_DUE_AGAIN, tries) + return + with self._lock: + still = self._still(me) + if not still: + return # signed out or another account meanwhile: its cards are none of the next one's + chats = {mid: v[0] for mid, v in due} + for k, v in ((ans.get("messages") if isinstance(ans, dict) else None) or {}).items(): + mid = _id(v.get("id")) if isinstance(v, dict) else "" + mid = mid or _id(k) + if mid not in chats or str(v.get("status") or "") in ("2", "DELETED"): + continue + try: + d = self._entity_dict(dict(v, id=mid), chat_id=chats[mid]) + msg = self._message(d, me.id, client) if d is not None and d.get("from_id") else None + if msg is None or msg.type != "CARD": + continue + self._fill_cards(client, [msg], me.id, force=True) # read again as it is now, whatever waited before + on_message(msg) + except Exception as e: + log.info("card %s read once more could not be taken (%s)", mid, type(e).__name__) + def _card_reread_noted(self, part, now: float) -> None: """Cards read again with no body (or not read): one more try each, at now (bounded like _card_holes).""" with self._lock: diff --git a/extensions/openmate-feishu/persona-extension.json b/extensions/openmate-feishu/persona-extension.json index be0bd2b..42f4725 100644 --- a/extensions/openmate-feishu/persona-extension.json +++ b/extensions/openmate-feishu/persona-extension.json @@ -2,7 +2,7 @@ "manifest_version": 1, "id": "openmate-feishu", "name": "飞书(OpenMate)", - "version": "0.11.72", + "version": "0.11.73", "description": "把飞书私聊和群消息接进 Persona 的收件箱和知识库,手机确认后以你的身份发消息,支持 /agent。通过你自己安装的 LarkAgentX(非官方网页协议)连接,与飞书官方无关。", "publisher": "NginxL", "homepage": "https://github.com/NginxL/openmate", diff --git a/extensions/openmate-feishu/tests/test_larkagentx.py b/extensions/openmate-feishu/tests/test_larkagentx.py index 915f226..562b9ba 100644 --- a/extensions/openmate-feishu/tests/test_larkagentx.py +++ b/extensions/openmate-feishu/tests/test_larkagentx.py @@ -275,7 +275,7 @@ def test_card_body_and_not_its_buttons(self): {"tag": "markdown", "content": "行%d" % i * 50} for i in range(200)]})}) self.assertLessEqual(len(long.text), larkagentx.CARD_TEXT_MOST) self.assertTrue(long.text.endswith("…")) - bad = self.m(msg_type=14, content_data={"cardHeader": {"title": "审批"}, "jsonCard": "{not json"}) + bad = self.m(msg_id="102", msg_type=14, content_data={"cardHeader": {"title": "审批"}, "jsonCard": "{not json"}) self.assertEqual(bad.text, "审批") def test_calendar_card(self): @@ -3098,7 +3098,7 @@ def test_the_card_itself_before_its_words_for_search(self): card = self.m(msg_type=14, content_data=data, _placement={"card": pack}) self.assertEqual(card.text, ANSWER_TEXT, "block by block, not the flat words with a button's") self.assertTrue(card.at_me, "the entity's attachment says whom it @s") - only = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}, _placement={"card": pack}) + only = self.m(msg_id="102", msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}, _placement={"card": pack}) self.assertEqual(only.text, "示例答复\n▶️ 恢复会话\n终端执行:plain_text", "the flat words when nothing says more") def test_an_entity_is_read_by_hand_when_the_classes_cannot(self): @@ -3298,3 +3298,139 @@ def test_reading_again_is_off_for_a_while_once_refused_three_times(self): self.assertEqual(len([k for k, _ in self.seen if k == larkagentx.CARDS_REREAD]), 3) self.assertIn("reading cards again as a newer client is off for 6 hours (HTTP 400 three times)", "\n".join(logs.output)) + + +class CardKeptTest(Base): + """2026-12-03, 0.11.72 on the real account: a card read again with its content (21:05:50) showed the stand-in all the + same: a later reading of it without its body (an edit pushed in its wait) replaced the text the core had.""" + + def setUp(self): + super().setUp() + self.b = self.signed_in() + + m = MappingTest.m + + def test_a_later_reading_without_the_body_shows_the_last_one_with_it(self): + at = {"at_users": {"ou_example_key": {"id": ME, "name": "示例用户"}}} + whole = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}, "jsonCard": json.dumps(ANSWER)}, + _placement={"card": at}) + self.assertEqual((whole.text, whole.at_me), (ANSWER_TEXT, True)) + bare = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}) + self.assertEqual((bare.text, bare.at_me, bare.mention_ids), (ANSWER_TEXT, True, [ME]), "never less than before") + self.assertIn("101", self.b._card_holes, "still read again for a newer body") + other = self.m(msg_id="102", msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}) + self.assertEqual(other.text, "示例答复", "another card: its own") + + def test_an_edit_pushed_in_its_wait_is_read_once_more_when_it_is_over(self): + import base64 as _b64 + + name = larkagentx.CARDS_REREAD + asked = [] + real = self.b._client.api + version = [inner_card("示例答复", _md(_run("进行中")))] + + def api(kind, data=None, raw=None): + asked.append((kind, dict(getattr(larkagentx._extra_headers, "value", None) or {}))) + if kind == name: + content = {"cardHeader": {"title": "示例答复"}, "jsonCard": json.dumps(version[0])} + return {"messages": {"101": {"id": "101", "type": 14, "fromId": "7050", "chatId": "500", "chatType": 2, + "status": 1, "content": _b64.b64encode(json.dumps(content).encode()).decode()}}} + return real(kind, data, raw) + + self.b._client.api = api + first = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}) + self.b._fill_cards(self.b._client, [first], ME, pushed=True) + self.assertEqual(first.text, "示例答复\n进行中") + version[0] = ANSWER # the bot edits its card: the push of it comes within the wait + edit = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}, _placement={"edited": True}) + self.b._fill_cards(self.b._client, [edit], ME, pushed=True) + self.assertEqual(edit.text, "示例答复\n进行中", "in its wait: the last one with its body") + self.assertIn("101", self.b._card_due) + got = [] + self.b._cards_due(self.b._client, self.b._me, got.append) + self.assertEqual(got, [], "not before its wait is over") + self.b._card_due["101"] = ("500", time.monotonic() - 1) + self.b._card_asked.clear() + self.b._cards_due(self.b._client, self.b._me, got.append) + self.assertEqual([m.text for m in got], [ANSWER_TEXT.replace("@示例用户", "")], "the edited card, read as it is now") + self.assertNotIn("101", self.b._card_due) + + def test_a_card_left_without_its_body_says_so_to_the_core(self): + S.api_answers[larkagentx.CARDS_ASK] = {"bizResults": {}} + self.b._card_reread_off = time.monotonic() + 60 # (reading again is off: nothing fills it) + bare = self.m(msg_type=14, content_data={"cardHeader": {"title": "示例答复"}}) + self.b._fill_cards(self.b._client, [bare], ME) + self.assertTrue(bare.keep_text, "the core keeps a text it has") + whole = self.m(msg_id="102", msg_type=14, content_data={"cardHeader": {"title": "示例答复"}, + "jsonCard": json.dumps(ANSWER)}) + self.b._fill_cards(self.b._client, [whole], ME) + self.assertFalse(whole.keep_text, "a card read with its body replaces what is stored") + + def due_api(self, version, fail=None): + """The service as it is: an old client's reading of a newer card has no body, a newer client's has it.""" + import base64 as _b64 + + real = self.b._client.api + calls = [] + + def api(kind, data=None, raw=None): + newer = bool(getattr(larkagentx._extra_headers, "value", None)) + calls.append((kind, newer)) + if kind == "messages.PullMessagesByIdsRequest": + if fail is not None and not newer: + raise fail + content = {"cardHeader": {"title": "示例答复"}} + if newer: + content["jsonCard"] = json.dumps(version[0]) + return {"messages": {"101": {"id": "101", "type": 14, "fromId": "7050", "chatId": "500", "chatType": 2, + "status": 1, "content": _b64.b64encode(json.dumps(content).encode()).decode()}}} + return real(kind, data, raw) + + self.b._client.api = api + return calls + + def test_a_card_due_is_read_again_as_a_newer_client_whatever_waited(self): + version = [ANSWER] + calls = self.due_api(version) + self.b._card_reread["101"] = (larkagentx.CARD_REREAD_TRIES, time.monotonic()) # its readings spent + self.b._card_ask_off = time.monotonic() + 3600 + self.b._card_due["101"] = ("500", time.monotonic() - 1) + got = [] + self.b._cards_due(self.b._client, self.b._me, got.append) + self.assertEqual([m.text for m in got], [ANSWER_TEXT.replace("@示例用户", "")]) + self.assertIn(("messages.PullMessagesByIdsRequest", True), calls, "read again as a newer client") + + def test_a_card_due_that_could_not_be_read_is_tried_again_a_few_times(self): + self.due_api([ANSWER], fail=OSError("offline")) + for n in range(larkagentx.CARD_DUE_TRIES + 1): + self.b._card_due.setdefault("101", ("500", 0.0)) + if "101" in self.b._card_due: + v = self.b._card_due["101"] + self.b._card_due["101"] = (v[0], time.monotonic() - 1) + tuple(v[2:]) + self.b._cards_due(self.b._client, self.b._me, lambda m: None) + if n < larkagentx.CARD_DUE_TRIES - 1: + self.assertIn("101", self.b._card_due, n) + self.assertGreater(self.b._card_due["101"][1], time.monotonic() + 20, "a while later") + else: + self.assertNotIn("101", self.b._card_due, "given up after a few tries") + break + + def test_signing_out_or_another_account_forgets_what_was_known_of_cards(self): + from openmate_core.backend import Account + + def fill(): + self.b._card_kept["101"] = ("示例答复\\n正文", (ME,)) + self.b._card_due["101"] = ("500", 0.0) + self.b._card_reread["101"] = (1, 0.0) + self.b._card_holes["101"] = {"head": []} + self.b._card_ask_off = self.b._card_reread_off = time.monotonic() + 60 + + fill() + self.b._set_session(self.b._auth, self.b._client, Account(ME, self.b._me.name), {}) + self.assertIn("101", self.b._card_kept, "the same account signed in again keeps them") + self.b._set_session(self.b._auth, self.b._client, Account("7999", "另一个账号"), {}) + self.assertEqual((self.b._card_kept, self.b._card_due, self.b._card_reread, self.b._card_holes), ({}, {}, {}, {})) + self.assertEqual((self.b._card_ask_off, self.b._card_reread_off), (0.0, 0.0)) + fill() + self.b.logout() + self.assertEqual((self.b._card_kept, self.b._card_due), ({}, {})) diff --git a/extensions/openmate-wechat/persona-extension.json b/extensions/openmate-wechat/persona-extension.json index 5ccb7ba..d2e6fbc 100644 --- a/extensions/openmate-wechat/persona-extension.json +++ b/extensions/openmate-wechat/persona-extension.json @@ -2,7 +2,7 @@ "manifest_version": 1, "id": "openmate-wechat", "name": "微信(OpenMate)", - "version": "0.1.66", + "version": "0.1.67", "description": "把微信私聊和群里 @你 的消息接进 Persona 的收件箱和会话页,私聊进知识库;在微信里用 /agent 让 Agent 以你的身份处理和回复,勾选的群里有人 @ 你时自动代答,助手代发的消息都要你在手机上确认。以一台新电脑的身份登录你的微信(非官方协议),与腾讯官方无关。", "publisher": "NginxL", "homepage": "https://github.com/NginxL/openmate", diff --git a/packages/openmate-feishu/0.11.73/openmate-feishu-0.11.73.tar.gz b/packages/openmate-feishu/0.11.73/openmate-feishu-0.11.73.tar.gz new file mode 100644 index 0000000..bc31268 Binary files /dev/null and b/packages/openmate-feishu/0.11.73/openmate-feishu-0.11.73.tar.gz differ diff --git a/packages/openmate-wechat/0.1.67/openmate-wechat-0.1.67.tar.gz b/packages/openmate-wechat/0.1.67/openmate-wechat-0.1.67.tar.gz new file mode 100644 index 0000000..e05ae24 Binary files /dev/null and b/packages/openmate-wechat/0.1.67/openmate-wechat-0.1.67.tar.gz differ diff --git a/persona-extensions.json b/persona-extensions.json index 02cbd41..755807f 100644 --- a/persona-extensions.json +++ b/persona-extensions.json @@ -9,7 +9,7 @@ "manifest_version": 1, "id": "openmate-feishu", "name": "飞书(OpenMate)", - "version": "0.11.72", + "version": "0.11.73", "description": "把飞书私聊和群消息接进 Persona 的收件箱和知识库,手机确认后以你的身份发消息,支持 /agent。通过你自己安装的 LarkAgentX(非官方网页协议)连接,与飞书官方无关。", "publisher": "NginxL", "homepage": "https://github.com/NginxL/openmate", @@ -482,9 +482,9 @@ "icon": "assets/icon.png", "packages": [ { - "url": "packages/openmate-feishu/0.11.72/openmate-feishu-0.11.72.tar.gz", - "sha256": "af4e4a87a0eac0360370566cbbe5422ff2ad98d8b032789e27d7673469a2a00b", - "size": 378264 + "url": "packages/openmate-feishu/0.11.73/openmate-feishu-0.11.73.tar.gz", + "sha256": "ade6d172e567b3308f26f8e01eca9698b5768f8e110d04d3bf45bdb1c37ae9b9", + "size": 379976 } ] }, @@ -493,7 +493,7 @@ "manifest_version": 1, "id": "openmate-wechat", "name": "微信(OpenMate)", - "version": "0.1.66", + "version": "0.1.67", "description": "把微信私聊和群里 @你 的消息接进 Persona 的收件箱和会话页,私聊进知识库;在微信里用 /agent 让 Agent 以你的身份处理和回复,勾选的群里有人 @ 你时自动代答,助手代发的消息都要你在手机上确认。以一台新电脑的身份登录你的微信(非官方协议),与腾讯官方无关。", "publisher": "NginxL", "homepage": "https://github.com/NginxL/openmate", @@ -790,9 +790,9 @@ "icon": "assets/icon.png", "packages": [ { - "url": "packages/openmate-wechat/0.1.66/openmate-wechat-0.1.66.tar.gz", - "sha256": "beace82857f70a846e2f6404d85fe3e4ecdc14183e3b8316e401a7a9b51abda4", - "size": 306344 + "url": "packages/openmate-wechat/0.1.67/openmate-wechat-0.1.67.tar.gz", + "sha256": "eeb58f03d2e6b1e44628e9276dacf413247874e3dfaa507aec67caf97316de95", + "size": 306493 } ] } diff --git a/tests/test_autoreply.py b/tests/test_autoreply.py index 476f394..a680312 100644 --- a/tests/test_autoreply.py +++ b/tests/test_autoreply.py @@ -560,9 +560,11 @@ def test_an_old_run_or_the_account_itself_is_never_at(self): run = running(h, at_me(h)) cur = h.app.store.run_get(run["id"]) self.assertEqual(h.app.agent._asker_at(dict(cur, asker_id=h.world.me.id)), None, "never the account itself") - for k in ("asker_id", "asker_at"): - cur.pop(k, None) - h.app.store.run_put(cur) # a run started before this version + with h.app.agent._lock(run["id"]): # as the runner writes it: its poll never puts back a copy read before + cur = h.app.store.run_get(run["id"]) + for k in ("asker_id", "asker_at"): + cur.pop(k, None) + h.app.store.run_put(cur) # a run started before this version h.tool("agent_reply", request=run["id"], text="接口周五前上线。") self.assertEqual(h.sent()[-1]["mentions"], []) diff --git a/tests/test_autoreply_bots.py b/tests/test_autoreply_bots.py index 9135499..fa55347 100644 --- a/tests/test_autoreply_bots.py +++ b/tests/test_autoreply_bots.py @@ -206,6 +206,27 @@ def test_reading_a_thread_brings_its_replies_no_push_brought(self): h.tool("messages", chat=TEAM, thread=root.id) self.assertEqual(len(h.world.thread_calls), 1, "a thread is read back at most every couple of minutes") + def test_a_reading_that_says_less_keeps_the_stored_text(self): + from openmate_core.backend import Message + + h = make(self) + root = h.world.push(TEAM, "me", "@示例通知机器人 你有哪些能力?") + wait_until(lambda: h.app.store.message(TEAM, root.id), what="the root stored") + + def card(mid, text, keep): + return Message(id=mid, chat_id=TEAM, position=root.position, sender_id=BOT, sender_name="示例通知机器人", + text=text, at=time.time(), type="CARD", root_id=root.id, thread_id=root.id, parent_id=root.id, + keep_text=keep) + + h.app.ingest([card("m_card", "示例答复\n我可以协助你处理测试。", False)], live=False) + h.app.ingest([card("m_card", "[卡片](内容请在飞书里查看)", True)], live=True) + self.assertEqual(h.app.store.message(TEAM, "m_card")["text"], "示例答复\n我可以协助你处理测试。", + "a reading without the card's body never replaces what is stored") + h.app.ingest([card("m_card", "示例答复\n新的正文", False)], live=False) + self.assertEqual(h.app.store.message(TEAM, "m_card")["text"], "示例答复\n新的正文", "a reading with it does") + h.app.ingest([card("m_new", "[卡片](内容请在飞书里查看)", True)], live=False) + self.assertEqual(h.app.store.message(TEAM, "m_new")["text"], "[卡片](内容请在飞书里查看)", "a new one is kept as read") + def test_a_thread_read_back_that_failed_is_tried_again(self): h = make(self) root = h.world.push(TEAM, "me", "@示例通知机器人 你有哪些能力?")