-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix:修正子agent无法正确接收本地图片(参考图)路径的问题 #5579
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
Merged
+495
−13
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b8728cd
fix: 修复5081号PR在子代理执行后台任务时,未正确使用系统配置的流式/非流请求的问题(#5081)
a61995987 746ffd3
feat:为子代理增加远程图片URL参数支持
a61995987 140c014
fix: update description for image_urls parameter in HandoffTool to cl…
Soulter 3d13673
ruff format
Soulter fda9313
Merge branch 'AstrBotDevs:master' into master
a61995987 7a2eefa
Merge branch 'AstrBotDevs:master' into master
a61995987 8a44647
fix:修正子agent无法正确接收本地图片(参考图)路径的问题
a61995987 cb22ac4
fix:增强image_urls接收的鲁棒性
a61995987 d6b5fd1
fix:ruff检查
a61995987 123efc2
fix: harden handoff image_urls preprocessing
zouyonghe 27706d8
fix: refactor handoff image_urls preprocessing flow
zouyonghe 8c02f85
refactor: simplify handoff image_urls data flow
zouyonghe 3023742
fix: filter non-string handoff image_urls entries
zouyonghe c89ce3f
refactor: streamline handoff image url collection
zouyonghe 166fb19
refactor: share handoff image ref validation utilities
zouyonghe 4319c51
refactor: simplify handoff image url processing
zouyonghe ed178e5
refactor: honor prepared handoff image urls contract
zouyonghe 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from collections.abc import Sequence | ||
| from pathlib import Path | ||
| from urllib.parse import unquote, urlparse | ||
|
|
||
| ALLOWED_IMAGE_EXTENSIONS = { | ||
| ".png", | ||
| ".jpg", | ||
| ".jpeg", | ||
| ".gif", | ||
| ".webp", | ||
| ".bmp", | ||
| ".tif", | ||
| ".tiff", | ||
| ".svg", | ||
| ".heic", | ||
| } | ||
|
|
||
|
|
||
| def resolve_file_url_path(image_ref: str) -> str: | ||
| parsed = urlparse(image_ref) | ||
| if parsed.scheme != "file": | ||
| return image_ref | ||
|
|
||
| path = unquote(parsed.path or "") | ||
| netloc = unquote(parsed.netloc or "") | ||
|
|
||
| # Keep support for file://<host>/path and file://<path> forms. | ||
| if netloc and netloc.lower() != "localhost": | ||
| path = f"//{netloc}{path}" if path else netloc | ||
| elif not path and netloc: | ||
| path = netloc | ||
|
|
||
| if os.name == "nt" and len(path) > 2 and path[0] == "/" and path[2] == ":": | ||
| path = path[1:] | ||
|
|
||
| return path or image_ref | ||
|
|
||
|
|
||
| def _is_path_within_roots(path: str, roots: Sequence[str]) -> bool: | ||
| try: | ||
| candidate = Path(path).resolve(strict=False) | ||
| except Exception: | ||
| return False | ||
|
|
||
| for root in roots: | ||
| try: | ||
| root_path = Path(root).resolve(strict=False) | ||
| candidate.relative_to(root_path) | ||
| return True | ||
| except Exception: | ||
| continue | ||
| return False | ||
|
|
||
|
|
||
| def is_supported_image_ref( | ||
| image_ref: str, | ||
| *, | ||
| allow_extensionless_existing_local_file: bool = False, | ||
| extensionless_local_roots: Sequence[str] | None = None, | ||
| ) -> bool: | ||
| if not image_ref: | ||
| return False | ||
|
|
||
| lowered = image_ref.lower() | ||
| if lowered.startswith(("http://", "https://", "base64://")): | ||
| return True | ||
|
|
||
| file_path = ( | ||
| resolve_file_url_path(image_ref) if lowered.startswith("file://") else image_ref | ||
| ) | ||
| ext = os.path.splitext(file_path)[1].lower() | ||
| if ext in ALLOWED_IMAGE_EXTENSIONS: | ||
| return True | ||
| if not allow_extensionless_existing_local_file: | ||
| return False | ||
| if not extensionless_local_roots: | ||
| return False | ||
| # Keep support for extension-less temp files returned by image converters. | ||
| return ( | ||
| ext == "" | ||
| and os.path.exists(file_path) | ||
| and _is_path_within_roots(file_path, extensionless_local_roots) | ||
| ) |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.