Show reports as soon as artifacts are ready
Browse files- research/app_artifacts.py +1 -1
- research/app_ui.py +14 -13
- research/fastmcp_server.py +3 -3
- research/research_app.py +17 -9
research/app_artifacts.py
CHANGED
|
@@ -266,7 +266,7 @@ def read_bucket_markdown(
|
|
| 266 |
*,
|
| 267 |
api: HfApi | None = None,
|
| 268 |
) -> str:
|
| 269 |
-
"""Read
|
| 270 |
if auth is None or not auth.token:
|
| 271 |
raise RuntimeError("Caller authentication is required to read the report")
|
| 272 |
|
|
|
|
| 266 |
*,
|
| 267 |
api: HfApi | None = None,
|
| 268 |
) -> str:
|
| 269 |
+
"""Read an available Markdown report with the caller's token."""
|
| 270 |
if auth is None or not auth.token:
|
| 271 |
raise RuntimeError("Caller authentication is required to read the report")
|
| 272 |
|
research/app_ui.py
CHANGED
|
@@ -837,18 +837,19 @@ def build_research_ui(
|
|
| 837 |
css_class="dispatch-report-card-title",
|
| 838 |
)
|
| 839 |
Text(
|
| 840 |
-
"
|
| 841 |
-
"
|
|
|
|
|
|
|
| 842 |
css_class="dispatch-report-card-copy",
|
| 843 |
)
|
| 844 |
Button(
|
| 845 |
-
"Add to chat"
|
|
|
|
| 846 |
variant="outline",
|
| 847 |
css_class="dispatch-report-action",
|
| 848 |
disabled=(
|
| 849 |
-
|
| 850 |
-
| STATE.chat_sent
|
| 851 |
-
| ~STATE.job.markdown_report
|
| 852 |
),
|
| 853 |
onClick=read_report,
|
| 854 |
)
|
|
@@ -864,18 +865,18 @@ def build_research_ui(
|
|
| 864 |
css_class="dispatch-report-card-title",
|
| 865 |
)
|
| 866 |
Text(
|
| 867 |
-
"
|
| 868 |
-
"and
|
|
|
|
|
|
|
| 869 |
css_class="dispatch-report-card-copy",
|
| 870 |
)
|
| 871 |
Button(
|
| 872 |
-
"Open report"
|
|
|
|
| 873 |
variant="outline",
|
| 874 |
css_class="dispatch-report-action",
|
| 875 |
-
disabled=
|
| 876 |
-
(STATE.job.status != "completed")
|
| 877 |
-
| ~STATE.job.html_report_ready
|
| 878 |
-
),
|
| 879 |
onClick=OpenLink(STATE.job.html_report_url),
|
| 880 |
)
|
| 881 |
with If(STATE.job.archive_space_url):
|
|
|
|
| 837 |
css_class="dispatch-report-card-title",
|
| 838 |
)
|
| 839 |
Text(
|
| 840 |
+
"{{ job.markdown_report ? "
|
| 841 |
+
"'Ready to read or continue in chat.' : "
|
| 842 |
+
"'The written report will appear here as soon "
|
| 843 |
+
"as it is ready.' }}",
|
| 844 |
css_class="dispatch-report-card-copy",
|
| 845 |
)
|
| 846 |
Button(
|
| 847 |
+
"{{ job.markdown_report ? 'Add to chat' : "
|
| 848 |
+
"'Preparing Markdown…' }}",
|
| 849 |
variant="outline",
|
| 850 |
css_class="dispatch-report-action",
|
| 851 |
disabled=(
|
| 852 |
+
STATE.chat_sent | ~STATE.job.markdown_report
|
|
|
|
|
|
|
| 853 |
),
|
| 854 |
onClick=read_report,
|
| 855 |
)
|
|
|
|
| 865 |
css_class="dispatch-report-card-title",
|
| 866 |
)
|
| 867 |
Text(
|
| 868 |
+
"{{ job.html_report_ready ? "
|
| 869 |
+
"'Charts, tables and sources — ready to open.' : "
|
| 870 |
+
"'The interactive report is being built from "
|
| 871 |
+
"the research findings.' }}",
|
| 872 |
css_class="dispatch-report-card-copy",
|
| 873 |
)
|
| 874 |
Button(
|
| 875 |
+
"{{ job.html_report_ready ? 'Open report' : "
|
| 876 |
+
"'Building HTML report…' }}",
|
| 877 |
variant="outline",
|
| 878 |
css_class="dispatch-report-action",
|
| 879 |
+
disabled=~STATE.job.html_report_ready,
|
|
|
|
|
|
|
|
|
|
| 880 |
onClick=OpenLink(STATE.job.html_report_url),
|
| 881 |
)
|
| 882 |
with If(STATE.job.archive_space_url):
|
research/fastmcp_server.py
CHANGED
|
@@ -149,8 +149,8 @@ def register_research_app(
|
|
| 149 |
) -> dict[str, str]:
|
| 150 |
auth = request_auth()
|
| 151 |
job = await jobs.get(job_id, owner_id(auth, ctx.session_id))
|
| 152 |
-
if job is None or job.
|
| 153 |
-
raise RuntimeError("Research
|
| 154 |
markdown = await asyncio.to_thread(read_bucket_markdown, job, auth)
|
| 155 |
context_markdown = (
|
| 156 |
f"{markdown.rstrip()}\n\n---\n\n"
|
|
@@ -161,7 +161,7 @@ def register_research_app(
|
|
| 161 |
return {
|
| 162 |
"markdown": context_markdown,
|
| 163 |
"message": (
|
| 164 |
-
"The research report
|
| 165 |
"Please summarize the main findings and include links to the "
|
| 166 |
"source artifacts and generated Markdown and HTML reports."
|
| 167 |
),
|
|
|
|
| 149 |
) -> dict[str, str]:
|
| 150 |
auth = request_auth()
|
| 151 |
job = await jobs.get(job_id, owner_id(auth, ctx.session_id))
|
| 152 |
+
if job is None or not job.markdown_report_uri:
|
| 153 |
+
raise RuntimeError("Research Markdown report is not available yet")
|
| 154 |
markdown = await asyncio.to_thread(read_bucket_markdown, job, auth)
|
| 155 |
context_markdown = (
|
| 156 |
f"{markdown.rstrip()}\n\n---\n\n"
|
|
|
|
| 161 |
return {
|
| 162 |
"markdown": context_markdown,
|
| 163 |
"message": (
|
| 164 |
+
"The research report has been added to context. "
|
| 165 |
"Please summarize the main findings and include links to the "
|
| 166 |
"source artifacts and generated Markdown and HTML reports."
|
| 167 |
),
|
research/research_app.py
CHANGED
|
@@ -11,6 +11,8 @@ from fast_agent import AgentRequest, AppOpenRequest, HarnessAppContext
|
|
| 11 |
from mcp.types import TextContent
|
| 12 |
|
| 13 |
try:
|
|
|
|
|
|
|
| 14 |
from .archive_provisioning import ensure_archive_space
|
| 15 |
from .research_workspace import (
|
| 16 |
ResearchWorkspace,
|
|
@@ -18,6 +20,8 @@ try:
|
|
| 18 |
ensure_workspace,
|
| 19 |
)
|
| 20 |
except ImportError: # loaded as top-level module from the fast-agent home
|
|
|
|
|
|
|
| 21 |
from research.archive_provisioning import ensure_archive_space
|
| 22 |
from research.research_workspace import (
|
| 23 |
ResearchWorkspace,
|
|
@@ -72,15 +76,19 @@ class ResearchHarnessSession:
|
|
| 72 |
workspace_token = current_research_workspace.set(workspace)
|
| 73 |
try:
|
| 74 |
if workspace.bearer_token is None:
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
finally:
|
| 85 |
current_research_workspace.reset(workspace_token)
|
| 86 |
|
|
|
|
| 11 |
from mcp.types import TextContent
|
| 12 |
|
| 13 |
try:
|
| 14 |
+
from .app_jobs import current_research_job
|
| 15 |
+
from .app_observability import capture_markdown_report
|
| 16 |
from .archive_provisioning import ensure_archive_space
|
| 17 |
from .research_workspace import (
|
| 18 |
ResearchWorkspace,
|
|
|
|
| 20 |
ensure_workspace,
|
| 21 |
)
|
| 22 |
except ImportError: # loaded as top-level module from the fast-agent home
|
| 23 |
+
from research.app_jobs import current_research_job
|
| 24 |
+
from research.app_observability import capture_markdown_report
|
| 25 |
from research.archive_provisioning import ensure_archive_space
|
| 26 |
from research.research_workspace import (
|
| 27 |
ResearchWorkspace,
|
|
|
|
| 76 |
workspace_token = current_research_workspace.set(workspace)
|
| 77 |
try:
|
| 78 |
if workspace.bearer_token is None:
|
| 79 |
+
response = await self._session.invoke(forwarded)
|
| 80 |
+
else:
|
| 81 |
+
from fast_agent.mcp.auth.context import request_bearer_token
|
| 82 |
+
|
| 83 |
+
auth_token = request_bearer_token.set(workspace.bearer_token)
|
| 84 |
+
try:
|
| 85 |
+
response = await self._session.invoke(forwarded)
|
| 86 |
+
finally:
|
| 87 |
+
request_bearer_token.reset(auth_token)
|
| 88 |
+
|
| 89 |
+
if job := current_research_job.get():
|
| 90 |
+
await capture_markdown_report(job)
|
| 91 |
+
return response
|
| 92 |
finally:
|
| 93 |
current_research_workspace.reset(workspace_token)
|
| 94 |
|