Repository navigation
feat: add Agent Reach adapter #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmae97
wants to merge
1
commit into
main
Choose a base branch
from
feat/agent-reach-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from urllib.parse import urlsplit | ||
| from urllib.parse import unquote, urlsplit | ||
|
|
||
| _SCHEMES = { | ||
| "android": "scrcpy", | ||
|
|
@@ -13,11 +13,35 @@ | |
| "appstore": "appstore", | ||
| "ios": "appstore", | ||
| "reddit": "reddit", | ||
| "reach": "agent_reach", | ||
| "baemin": "baemin", | ||
| "apk": "apk", | ||
| "ipa": "ipa", | ||
| "proxy": "proxy_pool", | ||
| } | ||
|
|
||
| # Official Agent Reach base-domain → channel mapping. Exact HTTPS hosts and their | ||
| # subdomains use agent_reach; route_for_target() performs the channel dispatch. | ||
| # Reddit is intentionally absent so its specialized adapter keeps precedence. | ||
| _AGENT_REACH_HOST_CHANNELS = { | ||
| "github.com": "github", | ||
| "youtube.com": "youtube", | ||
| "youtu.be": "youtube", | ||
| "bilibili.com": "bilibili", | ||
| "b23.tv": "bilibili", | ||
| "v2ex.com": "v2ex", | ||
| "twitter.com": "twitter", | ||
| "x.com": "twitter", | ||
| "facebook.com": "facebook", | ||
| "instagram.com": "instagram", | ||
| "xiaohongshu.com": "xiaohongshu", | ||
| "xhslink.com": "xiaohongshu", | ||
| "linkedin.com": "linkedin", | ||
| "zhipin.com": "boss", | ||
| "xueqiu.com": "xueqiu", | ||
| "xiaoyuzhoufm.com": "xiaoyuzhou", | ||
| } | ||
|
|
||
| _FILES = { | ||
| ".har": "har", | ||
| ".apk": "apk", | ||
|
|
@@ -43,20 +67,37 @@ class Target: | |
| is_web: bool | ||
|
|
||
|
|
||
| def _has_control_chars(value: str) -> bool: | ||
| return any(ord(char) < 32 or 127 <= ord(char) <= 159 for char in value) | ||
|
|
||
|
|
||
| def resolve_target(value: str, *, explicit: bool = False) -> Target: | ||
| """Classify without fetching, opening a device, or reading file contents.""" | ||
| if not isinstance(value, str) or not value.strip(): | ||
| raise ValueError("Target must be a non-empty string") | ||
| if _has_control_chars(value): | ||
| raise ValueError("Target contains control characters") | ||
| parsed = urlsplit(value) | ||
| if parsed.scheme == "reach" and _has_control_chars(unquote(value)): | ||
| raise ValueError("Target contains decoded control characters") | ||
| if parsed.scheme in {"http", "https"}: | ||
| if not parsed.hostname or any(ord(char) < 32 for char in value): | ||
| if not parsed.hostname: | ||
| raise ValueError("Invalid HTTP(S) target") | ||
| # Validate the port before choosing a network adapter. | ||
| _ = parsed.port | ||
| port = parsed.port | ||
| if port is not None and not 1 <= port <= 65535: | ||
| raise ValueError("Invalid HTTP(S) port") | ||
| host = parsed.hostname.lower() | ||
| tool = None | ||
| if not explicit and (host == "reddit.com" or host.endswith(".reddit.com")): | ||
| tool = "reddit" | ||
| if not explicit: | ||
| # Specialized adapters take precedence over generic host routing. | ||
| if host == "reddit.com" or host.endswith(".reddit.com"): | ||
| tool = "reddit" | ||
| elif parsed.scheme == "https" and any( | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자동 Agent Reach 선택은 HTTPS에만 적용됩니다. plain HTTP는 기존 ordinary web 경로를 유지하고, Reddit은 계속 전용 |
||
| host == domain or host.endswith(f".{domain}") | ||
| for domain in _AGENT_REACH_HOST_CHANNELS | ||
| ): | ||
| tool = "agent_reach" | ||
| return Target(value, tool, tool is None) | ||
| if parsed.scheme in _SCHEMES: | ||
| return Target(value, _SCHEMES[parsed.scheme], False) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_reach는 구조화된 오류 코드와 retry-after를 자체 보유하므로 공통 재시도 루프에서 제외했습니다. 따라서NEED_LOGIN,RATE_LIMITED,TIMEOUT등에서 같은 호출을 반복하지 않고 원래 종료 사유가 유지됩니다. async 경로에도 동일하게 적용됐습니다.