fix(channels): remove retired outbound metadata compatibility (#6169)
* docs(channels): remove expired entry-point migration notice * fix(channels): remove retired outbound metadata compatibility
This commit is contained in:
1 parent
41f2eeb7ba
commit
61fa3aa83c
5 files changed
+43
-33
No files matched your search
@@ -1,8 +1,6 @@
|
||||
# Channel Package Guide
|
||||
|
||||
Use this guide to add a self-contained channel package to the nanobot repository. A channel is part of nanobot when its package lives at `nanobot/channels/<channel>/`; there is no separate external channel-plugin path.
|
||||
|
||||
> **Breaking change:** nanobot no longer discovers the `nanobot.channels` Python entry-point group. Move an entry-point implementation into `nanobot/channels/<channel>/` with a package-owned manifest, runtime, tests, and optional WebUI contribution.
|
||||
Use this guide to add a self-contained channel package to the nanobot repository. Each channel lives at `nanobot/channels/<channel>/` and owns its manifest, runtime, tests, and optional WebUI contribution.
|
||||
|
||||
## How It Works
|
||||
|
||||
@@ -485,7 +483,7 @@ class OutboundMessage:
|
||||
event: object | None # typed runtime/UI event; usually inspect with isinstance()
|
||||
```
|
||||
|
||||
Runtime/UI semantics live on `msg.event`. Plugin-authored outbound messages should use typed events instead of legacy metadata flags such as `_progress`, `_stream_delta`, `_stream_end`, `_reasoning_delta`, `_turn_end`, or `_goal_status`. nanobot still accepts those old flags as a compatibility bridge for existing in-process extensions, but new plugin code should not add fresh dependencies on them.
|
||||
Runtime/UI semantics live on `msg.event`. Use `outbound_message_for_event()` from `nanobot.bus.outbound_events` to build outbound messages with the appropriate typed event. Keep `metadata` for channel routing context, such as message and thread IDs, and optional `OUTBOUND_META_AGENT_UI` payloads.
|
||||
|
||||
## Streaming Support
|
||||
|
||||
@@ -524,7 +522,7 @@ async def send_delta(
|
||||
# delta contains a small chunk of text (a few tokens)
|
||||
```
|
||||
|
||||
Streaming state is passed through keyword-only arguments, not `_stream_delta` or `_stream_end` metadata flags. Use `stream_id` to key any per-stream buffers; fall back to `chat_id` when it is missing.
|
||||
Streaming state is passed through keyword-only arguments. Use `stream_id` to key any per-stream buffers; fall back to `chat_id` when it is missing.
|
||||
|
||||
### Example: Webhook with Streaming
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import httpx
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
from nanobot.bus.outbound_events import ProgressEvent
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.base import BaseChannel
|
||||
from nanobot.config.paths import get_media_dir
|
||||
@@ -529,7 +530,7 @@ class MattermostChannel(BaseChannel):
|
||||
file_ids=(file_ids if i == 0 else None) or None,
|
||||
)
|
||||
|
||||
if not meta.get("_progress") and meta.get("message_id"):
|
||||
if not isinstance(msg.event, ProgressEvent) and meta.get("message_id"):
|
||||
try:
|
||||
await self._remove_reaction(meta["message_id"], self.config.react_emoji)
|
||||
except Exception:
|
||||
@@ -561,9 +562,7 @@ class MattermostChannel(BaseChannel):
|
||||
return
|
||||
|
||||
meta = metadata or {}
|
||||
stream_id = cast(str, stream_id or meta.get("_stream_id") or chat_id)
|
||||
stream_end = stream_end or bool(meta.get("_stream_end"))
|
||||
resuming = resuming or bool(meta.get("_resuming"))
|
||||
stream_id = stream_id or chat_id
|
||||
|
||||
if stream_end:
|
||||
committed = self._stream_committed.get(stream_id, "")
|
||||
@@ -580,7 +579,7 @@ class MattermostChannel(BaseChannel):
|
||||
self._clear_stream_state(stream_id)
|
||||
return
|
||||
|
||||
if final and not meta.get("_progress"):
|
||||
if final:
|
||||
mm_meta = (
|
||||
cast(dict[str, Any], meta.get("mattermost", {}) or {})
|
||||
if isinstance(meta.get("mattermost"), dict)
|
||||
|
||||
@@ -11,6 +11,7 @@ import httpx
|
||||
import pytest
|
||||
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
from nanobot.bus.outbound_events import ProgressEvent
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.channels.mattermost.manifest import SETUP_SPEC
|
||||
from nanobot.channels.mattermost.runtime import (
|
||||
@@ -597,9 +598,21 @@ async def test_send_with_thread_root_id():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_reaction_on_completion():
|
||||
async def test_send_reactions_complete_after_final_reply():
|
||||
channel, fake = _make_channel()
|
||||
channel._self_id = "bot_id"
|
||||
await channel.send(OutboundMessage(
|
||||
channel="mattermost",
|
||||
chat_id="chan_1",
|
||||
content="working",
|
||||
metadata={"message_id": "orig_post_1"},
|
||||
event=ProgressEvent(content="working"),
|
||||
))
|
||||
posts = [c for c in fake.post_calls if c["path"] == "/api/v4/posts"]
|
||||
assert [c["json"]["message"] for c in posts] == ["working"]
|
||||
assert fake.delete_calls == []
|
||||
assert [c for c in fake.post_calls if c["path"] == "/api/v4/reactions"] == []
|
||||
|
||||
msg = OutboundMessage(
|
||||
channel="mattermost",
|
||||
chat_id="chan_1",
|
||||
@@ -610,6 +623,10 @@ async def test_send_reaction_on_completion():
|
||||
reactions = [c for c in fake.post_calls if c["path"] == "/api/v4/reactions"]
|
||||
assert len(reactions) == 1
|
||||
assert reactions[0]["json"]["emoji_name"] == "white_check_mark"
|
||||
assert reactions[0]["json"]["post_id"] == "orig_post_1"
|
||||
assert [c["path"] for c in fake.delete_calls] == [
|
||||
"/api/v4/users/bot_id/posts/orig_post_1/reactions/eyes",
|
||||
]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -618,12 +635,12 @@ async def test_send_reaction_on_completion():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_first_delta_creates_post():
|
||||
async def test_stream_first_delta_buffers_content():
|
||||
channel, fake = _make_channel()
|
||||
channel._self_id = "bot_id"
|
||||
fake.set_post_response("/api/v4/posts", {"id": "stream_post_1"})
|
||||
|
||||
await channel.send_delta("chan_1", "Hello", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", "Hello", stream_id="s1")
|
||||
posts = [c for c in fake.post_calls if c["path"] == "/api/v4/posts"]
|
||||
assert len(posts) == 0
|
||||
assert channel._stream_buffers["s1"] == "Hello"
|
||||
@@ -631,15 +648,15 @@ async def test_stream_first_delta_creates_post():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_subsequent_delta_edits_post():
|
||||
async def test_stream_subsequent_delta_appends_content():
|
||||
channel, fake = _make_channel()
|
||||
channel._self_id = "bot_id"
|
||||
fake.set_post_response("/api/v4/posts", {"id": "stream_post_1"})
|
||||
|
||||
await channel.send_delta("chan_1", "Hello", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", "Hello", stream_id="s1")
|
||||
assert channel._stream_buffers["s1"] == "Hello"
|
||||
|
||||
await channel.send_delta("chan_1", " world", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", " world", stream_id="s1")
|
||||
edits = [c for c in fake.put_calls if c["path"] == "/api/v4/posts/stream_post_1"]
|
||||
assert len(edits) == 0
|
||||
assert channel._stream_buffers["s1"] == "Hello world"
|
||||
@@ -651,21 +668,21 @@ async def test_stream_end_adds_done_emoji():
|
||||
channel._self_id = "bot_id"
|
||||
fake.set_post_response("/api/v4/posts", {"id": "stream_post_1"})
|
||||
|
||||
await channel.send_delta("chan_1", "Hello", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", "", {"_stream_id": "s1", "_stream_end": True})
|
||||
await channel.send_delta("chan_1", "Hello", stream_id="s1")
|
||||
await channel.send_delta("chan_1", "", stream_id="s1", stream_end=True)
|
||||
reactions = [c for c in fake.post_calls if c["path"] == "/api/v4/reactions" and c["json"]["emoji_name"] == "white_check_mark"]
|
||||
assert len(reactions) >= 1
|
||||
assert channel._stream_posts.get("s1") is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_chunk_boundary_finalizes_and_creates_new():
|
||||
async def test_stream_deltas_keep_combined_buffer():
|
||||
channel, fake = _make_channel()
|
||||
channel._self_id = "bot_id"
|
||||
fake.set_post_response("/api/v4/posts", {"id": "post_1"})
|
||||
|
||||
await channel.send_delta("chan_1", "Hello ", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", "world", {"_stream_id": "s1"})
|
||||
await channel.send_delta("chan_1", "Hello ", stream_id="s1")
|
||||
await channel.send_delta("chan_1", "world", stream_id="s1")
|
||||
|
||||
posts = [c for c in fake.post_calls if c["path"] == "/api/v4/posts"]
|
||||
assert len(posts) == 0
|
||||
|
||||
@@ -2129,12 +2129,8 @@ class WeixinChannel(BaseChannel):
|
||||
remaining reply. The manager skips the final ``StreamedResponseEvent``
|
||||
to avoid duplicate delivery. Reasoning deltas are dropped.
|
||||
"""
|
||||
meta = metadata or {}
|
||||
if meta.get("_reasoning_delta") or meta.get("_reasoning"):
|
||||
return
|
||||
is_end = stream_end or bool(meta.get("_stream_end"))
|
||||
buffer_key = stream_id or chat_id
|
||||
if is_end and merge_next:
|
||||
if stream_end and merge_next:
|
||||
if delta:
|
||||
self._stream_buffers.setdefault(buffer_key, []).append(delta)
|
||||
return
|
||||
@@ -2143,7 +2139,7 @@ class WeixinChannel(BaseChannel):
|
||||
# folded into `full` below instead of appended here, so a send retry
|
||||
# recomputes the same `full` from an unchanged buffer rather than
|
||||
# double-counting that delta.
|
||||
if delta and not is_end:
|
||||
if delta and not stream_end:
|
||||
previous_parts = list(self._stream_buffers.get(buffer_key, []))
|
||||
self._stream_buffers.setdefault(buffer_key, []).append(delta)
|
||||
try:
|
||||
@@ -2151,7 +2147,7 @@ class WeixinChannel(BaseChannel):
|
||||
except Exception:
|
||||
self._stream_buffers[buffer_key] = previous_parts
|
||||
raise
|
||||
if not is_end:
|
||||
if not stream_end:
|
||||
return
|
||||
full = ("".join(self._stream_buffers.get(buffer_key, [])) + (delta or "")).strip()
|
||||
if full:
|
||||
|
||||
@@ -2191,8 +2191,8 @@ async def test_stream_end_flushes_buffered_answer() -> None:
|
||||
channel._context_token_at["wx-user"] = time.time()
|
||||
channel._send_text = AsyncMock()
|
||||
|
||||
await channel.send_delta("wx-user", "hello ", {"_stream_delta": True})
|
||||
await channel.send_delta("wx-user", "world", {"_stream_end": True})
|
||||
await channel.send_delta("wx-user", "hello ")
|
||||
await channel.send_delta("wx-user", "world", stream_end=True)
|
||||
|
||||
channel._send_text.assert_awaited_once_with("wx-user", "hello world", "ctx-1")
|
||||
assert "wx-user" not in channel._stream_buffers
|
||||
@@ -2230,14 +2230,14 @@ async def test_stream_end_send_failure_keeps_buffer_for_retry() -> None:
|
||||
channel._context_token_at["wx-user"] = time.time()
|
||||
channel._send_text = AsyncMock(side_effect=RuntimeError("temporary send failure"))
|
||||
|
||||
await channel.send_delta("wx-user", "hello ", {"_stream_delta": True})
|
||||
await channel.send_delta("wx-user", "hello ")
|
||||
with pytest.raises(RuntimeError):
|
||||
await channel.send_delta("wx-user", "world", {"_stream_end": True})
|
||||
await channel.send_delta("wx-user", "world", stream_end=True)
|
||||
|
||||
assert channel._stream_buffers["wx-user"] == ["hello "]
|
||||
|
||||
channel._send_text = AsyncMock()
|
||||
await channel.send_delta("wx-user", "world", {"_stream_end": True})
|
||||
await channel.send_delta("wx-user", "world", stream_end=True)
|
||||
|
||||
channel._send_text.assert_awaited_once_with("wx-user", "hello world", "ctx-1")
|
||||
assert "wx-user" not in channel._stream_buffers
|
||||
|
||||
Reference in new issue
Block a user