mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-12-01 11:37:48 +08:00
* feat(agent): add cross-platform interactive card tool * fix(agent): create pipelines with selected runner defaults * fix(agent): enable reliable cross-platform card interactions * feat(dingtalk): deliver A2UI cards and restore agent replies * Fix DingTalk A2UI form submissions and agent replies * Restore LangBot branding on DingTalk A2UI cards * Use compatible Markdown link in DingTalk A2UI branding * Place LangBot branding above DingTalk card content * Stream DingTalk replies without a source message * Move DingTalk branding into compact card footer * fix(wecombot): handle native select card callbacks * fix(wecombot): stream replies after HITL cards * fix(dingtalk): show submitted HITL choices in cards * fix(lark): stream replies after HITL submissions * fix(plugins): refresh LocalAgent source hashes * fix(dify): merge HITL resume streaming into in-tree plugin * feat(interactions): resume runner in place after card submission * fix(interactions): respect live adapter APIs and preserve deadlines * fix(ci): lock blocking interaction SDK for dependent checks * test(runner): keep legacy SDK probe importable * fix(interactions): align adapter manifests and close timed-out streams * fix(agent): avoid duplicate replies and enable LocalAgent cards * chore(plugins): sync LocalAgent catalog version * refactor(agent): unify blocking interaction callbacks and adapters * chore(deps): pin blocking interaction SDK revision * test(agent): remove obsolete async fixture mark * test(interaction): update legacy admission assertions * fix(qqofficial): keep card callbacks responsive * fix(runner): keep blocking card interactions alive * ci(plugins): expect SDK 0.7.20 in Runner workflows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> * ci(plugins): test coding Runners against SDK 0.7.20 Claude Code and Codex now call ctx.request_interaction, first released in 0.7.20. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> * fix(discord): deliver guild interaction cards to the originating channel Pipeline group conversations are keyed by guild id, so send_interaction targeted the guild and Discord returned Unknown Channel. Resolve the channel from the message being answered, edit cards in that channel, and report the card's conversation on callbacks so the Host scope check matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: RockChinQ <rockchinq@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
174 lines
6.3 KiB
Python
174 lines
6.3 KiB
Python
"""Real SDK b5, local fixtures only; no vendor accounts or live claims."""
|
|
|
|
import asyncio
|
|
import importlib.util
|
|
import inspect
|
|
import os
|
|
import sys
|
|
from contextlib import contextmanager
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
from langbot_plugin.api.entities.builtin.runner import (
|
|
ActorContext,
|
|
AgentEventContext,
|
|
AgentInput,
|
|
AgentResources,
|
|
AgentRuntimeContext,
|
|
AgentTrigger,
|
|
ConversationContext,
|
|
DeliveryContext,
|
|
RunnerContext,
|
|
)
|
|
from langbot_plugin.api.proxies.invocation import bind_invocation
|
|
|
|
ROOT = Path(os.environ.get("HTTP_RUNNER_SOURCE_ROOT", Path(__file__).resolve().parents[1]))
|
|
GATEWAYS = ["coze", "dashscope", "dify", "langflow", "n8n"]
|
|
IDENTITIES = ["coze", "dify", "n8n", "tbox", "weknora"]
|
|
IDENTITY_ERRORS = {
|
|
"coze": ("CozeConfigError", "AsyncCozeClient"),
|
|
"dify": ("DifyConfigError", "AsyncDifyClient"),
|
|
"n8n": ("N8nConfigError", "AsyncN8nClient"),
|
|
"tbox": ("TboxConfigError", "AsyncTboxClient"),
|
|
"weknora": ("WeKnoraConfigError", "AsyncWeKnoraClient"),
|
|
}
|
|
|
|
|
|
@contextmanager
|
|
def load(name):
|
|
saved = {k: v for k, v in sys.modules.items() if k == "pkg" or k.startswith("pkg.")}
|
|
for k in saved:
|
|
del sys.modules[k]
|
|
path = ROOT / (name + "-agent")
|
|
sys.path.insert(0, str(path))
|
|
key = "cert_" + name
|
|
try:
|
|
spec = importlib.util.spec_from_file_location(key, path / "components/runner/default.py")
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[key] = module
|
|
spec.loader.exec_module(module)
|
|
yield module, module.DefaultRunner()
|
|
finally:
|
|
sys.path.remove(str(path))
|
|
sys.modules.pop(key, None)
|
|
for k in list(sys.modules):
|
|
if k == "pkg" or k.startswith("pkg."):
|
|
del sys.modules[k]
|
|
sys.modules.update(saved)
|
|
|
|
|
|
def context(workspace="A", *, actor=True):
|
|
return RunnerContext(
|
|
run_id="fixture",
|
|
trigger=AgentTrigger(type="message.received"),
|
|
event=AgentEventContext(event_id="event", event_type="message.received", source="fixture"),
|
|
input=AgentInput(text="hello"),
|
|
delivery=DeliveryContext(surface="fixture"),
|
|
resources=AgentResources(),
|
|
runtime=AgentRuntimeContext(),
|
|
actor=ActorContext(actor_type="user", actor_id="same-actor") if actor else None,
|
|
conversation=ConversationContext(conversation_id="same-conversation", workspace_id=workspace),
|
|
)
|
|
|
|
|
|
def identity(runner, ctx):
|
|
return (getattr(runner, "_get_user_tag", None) or runner._get_user_id)(ctx)
|
|
|
|
|
|
async def collect(generator):
|
|
return [result async for result in generator]
|
|
|
|
|
|
@contextmanager
|
|
def gateway_invocation(runner):
|
|
# Registration must be owned by the same revocable authority as a real run.
|
|
with bind_invocation(runner._plugin_runtime_handler):
|
|
yield
|
|
|
|
|
|
@pytest.mark.parametrize("name", IDENTITIES)
|
|
def test_workspace_identity_collision(name):
|
|
with load(name) as (_, runner):
|
|
a, b = context("A"), context("B")
|
|
a.config["workspace_id"] = b.config["workspace_id"] = "forged"
|
|
assert identity(runner, a) != identity(runner, b)
|
|
assert identity(runner, a) == identity(runner, context("A"))
|
|
|
|
|
|
@pytest.mark.parametrize("name", IDENTITIES)
|
|
def test_connection_binding_overrides_claimed_workspace(name):
|
|
with load(name) as (_, a), load(name) as (_, b):
|
|
a._plugin_runtime_handler = SimpleNamespace(
|
|
bound_action_context=SimpleNamespace(instance_uuid="i", workspace_uuid="A", installation_uuid="install-a")
|
|
)
|
|
b._plugin_runtime_handler = SimpleNamespace(
|
|
bound_action_context=SimpleNamespace(instance_uuid="i", workspace_uuid="B", installation_uuid="install-b")
|
|
)
|
|
assert identity(a, context(None)) != identity(b, context(None))
|
|
|
|
|
|
@pytest.mark.parametrize("name", IDENTITIES)
|
|
def test_sender_without_host_actor_is_refused_before_any_upstream_call(name, monkeypatch):
|
|
error_name, client_name = IDENTITY_ERRORS[name]
|
|
with load(name) as (module, runner):
|
|
error_cls = getattr(module, error_name)
|
|
|
|
with pytest.raises(error_cls) as refused:
|
|
identity(runner, context(actor=False))
|
|
assert refused.value.code == f"{name}.identity_unavailable"
|
|
|
|
built = []
|
|
|
|
class RecordingClient:
|
|
def __init__(self, *args, **kwargs):
|
|
built.append((args, kwargs))
|
|
raise AssertionError("upstream client must not be built without a trusted Host actor")
|
|
|
|
monkeypatch.setattr(module, client_name, RecordingClient)
|
|
results = asyncio.run(collect(runner.run(context(actor=False))))
|
|
assert [getattr(result.type, "value", str(result.type)) for result in results] == ["run.failed"]
|
|
assert results[0].data["code"] == f"{name}.identity_unavailable"
|
|
assert built == []
|
|
|
|
|
|
@pytest.mark.parametrize("name", GATEWAYS)
|
|
def test_gateway_overlap_has_independent_timeout_and_tokens(name):
|
|
async def run(runner):
|
|
runner.get_run_api = lambda ctx: SimpleNamespace()
|
|
|
|
async def create(timeout):
|
|
value = runner._create_asset_gateway_registration(
|
|
context(),
|
|
{
|
|
"asset_gateway_host": "127.0.0.1",
|
|
"asset_gateway_port": 0,
|
|
"asset_gateway_request_timeout": timeout,
|
|
"asset_gateway_token_ttl": 60,
|
|
},
|
|
)
|
|
return await value if inspect.isawaitable(value) else value
|
|
|
|
a = await create(0.5)
|
|
b = None
|
|
try:
|
|
b = await create(1.5)
|
|
assert a.gateway is not b.gateway
|
|
assert a.gateway.request_timeout == 0.5
|
|
assert b.gateway.request_timeout == 1.5
|
|
assert a.token != b.token
|
|
assert a.gateway._registration_for_token(b.token) is None
|
|
finally:
|
|
for registration in [a, b]:
|
|
if registration:
|
|
value = registration.stop()
|
|
if inspect.isawaitable(value):
|
|
await value
|
|
# Historical SDK singleton needs explicit cleanup in RED.
|
|
if registration.gateway.__class__.__module__.startswith("langbot_plugin"):
|
|
registration.gateway.stop()
|
|
|
|
with load(name) as (_, runner):
|
|
with gateway_invocation(runner):
|
|
asyncio.run(run(runner))
|