mirror of
https://github.com/actionbook/actionbook.git
synced 2026-09-19 03:28:06 +08:00
2db938d519
* chore: align dify plugin manifest and privacy policy * [packages/dify-plugin]refactor: replace hyperbrowser SDK with direct HTTP API Remove hyperbrowser Python SDK dependency and use requests to call Hyperbrowser REST API directly. This eliminates an extra dependency that may not install cleanly in Dify Cloud's serverless runtime. - providers/hyperbrowser.py: HTTP POST/PUT instead of SDK client - pyproject.toml: drop hyperbrowser>=0.1.0 dependency - requirements.txt: add explicit requirements file - tests/test_providers.py: mock requests instead of SDK classes * [packages/dify-plugin]feat: add HTML misroute guard and simplify tool error handling Add utils/http_guard.py to detect when API responses return HTML instead of expected text/JSON — a common symptom of ACTIONBOOK_API_URL pointing to a non-Actionbook endpoint (e.g. Dify app API). - Integrate HTML guard into search_actions, get_action_by_area_id, provider - Simplify verbose error branches into concise messages - Remove debug-level logging from hot paths - Update all related tests with Content-Type headers and new assertions * [packages/dify-plugin]refactor: lazy-load browser deps for serverless compatibility Defer importing playwright and connection_pool until first browser tool invocation. This allows search_actions and get_action_by_area_id to work even when playwright binaries are unavailable (e.g. Dify Cloud serverless runtime). - tools/__init__.py: lazy __getattr__ for browser tool classes - browser_create_session.py: thread-safe lazy pool import - browser_operator.py: lazy import with stub exception fallbacks * [packages/dify-plugin]fix: review fixes — dead code, lazy import, session recovery - Remove unreachable except BaseException blocks in search_actions and get_action_by_area_id (dead code: only re-raised what it caught) - Apply lazy connection_pool import in browser_stop_session, matching browser_create_session and browser_operator pattern for serverless - Preserve provider_name/api_key on session recovery reconnect to prevent remote session leaks when browser_stop_session runs later - Update tests accordingly * [root]chore: use changeset for dify-plugin version bump Revert manual 0.1.1 bump back to 0.1.0 and add a changeset file so CI handles versioning through the standard two-phase flow. Also extend sync-versions.js to run `uv lock` after updating pyproject.toml to keep uv.lock in sync automatically.
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
"""HTTP response guards for common misconfiguration patterns."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def looks_like_html_response(response: Any, body_text: str) -> bool:
|
|
"""Return True when an API call appears to have returned an HTML page."""
|
|
content_type = str((getattr(response, "headers", {}) or {}).get("Content-Type", "")).lower()
|
|
sniff = str(body_text or "").lstrip().lower()
|
|
return (
|
|
"text/html" in content_type
|
|
or sniff.startswith("<!doctype html")
|
|
or sniff.startswith("<html")
|
|
)
|
|
|
|
|
|
def build_html_misroute_message(api_base_url: str, request_url: str) -> str:
|
|
"""Build a concise troubleshooting message for HTML misroute responses."""
|
|
return (
|
|
"Error: Received an HTML page instead of the expected API response.\n"
|
|
f"Request URL: {request_url}\n"
|
|
f"Current ACTIONBOOK_API_URL: {api_base_url}\n\n"
|
|
"Likely cause: ACTIONBOOK_API_URL points to a non-Actionbook endpoint "
|
|
"(commonly Dify app API such as https://api.dify.ai/v1).\n"
|
|
"Fix: set ACTIONBOOK_API_URL to https://api.actionbook.dev."
|
|
)
|