CI / test (push) Canceled after 0s
## Summary epic r04 - begin refactor ## Change Type - [x] Cowork feature - [ ] Bug fix - [ ] Core AI contribution - [ ] Test / hardening - [ ] Performance - [ ] Documentation ## Related Work Cowork Task: Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets Core AI Issue: Core Task: Related PR: ## Scope What is intentionally included? What is intentionally NOT included? ## Validation - [ ] Unit tests - [ ] Integration tests - [ ] Manual verification - [ ] Regression check Commands / evidence: ## Security Impact Permission / credential / network / customer data impact: ## Compatibility - [ ] No breaking change - [ ] Breaking change documented ## Reviewer Notes Anything Cowork reviewers should pay attention to. --------- Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com> Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com> Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com> Co-authored-by: Vu Dam Tuan <vudt15@fpt.com> Co-authored-by: Hiep Ha Van <hiephv3@fpt.com> Co-authored-by: Lam Hoang Van <lamhv7@fpt.com> Reviewed-on: #7 Co-authored-by: Duy Le Huu <duylh19@fpt.com>
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
"""Fetch tools - fetch_url, jira_search, jira_get_issue (R05-T02).
|
|
|
|
Moved verbatim out of ``core/tools.py`` (see ``file_tools.py`` for why). The
|
|
network access these three carry is exactly what the ``ToolCapability.NETWORK``
|
|
tag added in R05-T01/domain/tools/tool_registry.py describes.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict
|
|
|
|
from .tool_context import ToolContext
|
|
|
|
|
|
def fetch_url(ctx: ToolContext, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Fetch a URL's text content (web page / online document / SharePoint-
|
|
OneDrive share link) via link_fetch — the same parser task-link attachments
|
|
use. Honors the Sandbox Security Layer's "Block network" policy."""
|
|
url = str(args.get("url", "")).strip()
|
|
if not url:
|
|
return {"ok": False, "output": "fetch_url: 'url' is required."}
|
|
if not url.lower().startswith(("http://", "https://")):
|
|
return {"ok": False, "output": f"fetch_url: not an http(s) URL: {url}"}
|
|
if not ctx.allow_url_fetch:
|
|
return {"ok": False,
|
|
"output": ("fetch_url: URL fetching is turned off in Settings → Security "
|
|
"(\"Allow the agent to fetch URLs\").")}
|
|
# A pasted Jira issue link on the CONNECTED Jira host is read via the
|
|
# authenticated API (so private issues resolve, not a login page). Public
|
|
# links / any other URL fall through to the normal fetcher below.
|
|
from cowork_local.core import jira_tool
|
|
if jira_tool.is_jira_issue_url(ctx.jira, url):
|
|
return {"ok": True, "output": jira_tool.get_issue_by_url(ctx.jira, url)}
|
|
from cowork_local.core.link_fetch import fetch_link_preview
|
|
|
|
return {"ok": True, "output": fetch_link_preview(url)}
|
|
|
|
|
|
def jira_search(ctx: ToolContext, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Tìm issue trên Jira bằng JQL."""
|
|
from cowork_local.core import jira_tool
|
|
|
|
out = jira_tool.search(ctx.jira, str(args.get("jql", "")),
|
|
int(args.get("max_results", 25) or 25))
|
|
return {"ok": not out.lower().startswith(("jira is not configured", "jira search failed")),
|
|
"output": out}
|
|
|
|
|
|
def jira_get_issue(ctx: ToolContext, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Lấy chi tiết một issue Jira theo mã."""
|
|
from cowork_local.core import jira_tool
|
|
|
|
out = jira_tool.get_issue(ctx.jira, str(args.get("key", "")))
|
|
return {"ok": not out.lower().startswith(("jira is not configured", "could not fetch")),
|
|
"output": out}
|
|
|
|
|
|
__all__ = ["fetch_url", "jira_search", "jira_get_issue"]
|