mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-11-27 17:10:00 +08:00
Copy was broken twice over. `langbot.api()` already resolves the unwrapped
payload (PageResponse.ok -> HTTP data -> resp.data.data -> the SDK's
resolve(data.data)), so `item.data.url` was always `undefined` and the page
copied an empty string. `writeText('')` resolves without throwing, so it also
never reached the fallback: the UI said "copied" while the clipboard stayed
empty.
The iframe is worse than assumed. It is a `blob:` document under
`sandbox="allow-scripts allow-forms"`, so its origin is opaque: `location.origin`
is "null", relative asset URLs do not load, and `navigator.clipboard` rejects
with NotAllowedError. `/list` returns relative URLs while `public_base_url` is
empty, so even a correct value would have pasted as an unusable path. URLs are
now made absolute against `location.ancestorOrigins[0]` before either the
clipboard or an `<img src>`, and copy reads `item.url` from the list cache
instead of making a redundant `/item` round trip.
Every other call had the same layer mistake: `res.error` is never set on a
resolved value, because failures reject the promise, so no failure ever
surfaced. All call sites now catch, and an empty URL toasts an error rather
than claiming success.
Verified in a real blob: iframe with the real sandbox: relative url -> absolute
-> clipboard read back byte for byte, and the same URL loads as the preview
(0 `/image` calls). Also passes with `navigator.clipboard` removed, proving the
execCommand tier is what carries it.
The host is untouched now, so this is plugin-only; the `allow-modals` flip is
dropped and the clear confirmation stays in-page.
Co-authored-by: multica-agent <github@multica.ai>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# StickerHub Tool - stable interface for the stable sticker URL
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from langbot_plugin.api.definition.components.tool.tool import Tool
|
|
from langbot_plugin.api.entities.builtin.provider.session import Session
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class GetStickerUrl(Tool):
|
|
"""Return the stable URL for a stored sticker.
|
|
|
|
This is the stable integration contract for other plugins (notably
|
|
HumanTakeover): call ``stickerhub_get_sticker_url`` and use the returned
|
|
string as the image URL. The string is ``None`` when ``public_base_url`` is
|
|
empty, which yields a relative ``/api/v1/plugins/...`` path.
|
|
"""
|
|
|
|
async def call(
|
|
self, params: dict[str, Any], session: Session, query_id: int
|
|
) -> str:
|
|
payload = params or {}
|
|
name = str(payload.get("name") or "").strip()
|
|
if not name:
|
|
return "error: name is required"
|
|
url = await self.plugin.media_url(name)
|
|
if not url:
|
|
return f"error: sticker {name!r} not found"
|
|
return url
|