@seqyuan/annodex 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api/agent/[id]/events/route.ts +94 -0
- package/app/api/agent/[id]/route.ts +83 -0
- package/app/api/agent/new/route.ts +53 -0
- package/app/api/auth/all-providers/route.ts +21 -0
- package/app/api/auth/api-key/[provider]/route.ts +7 -0
- package/app/api/auth/login/[provider]/route.ts +7 -0
- package/app/api/auth/login/route.ts +22 -0
- package/app/api/auth/logout/[provider]/route.ts +7 -0
- package/app/api/auth/providers/route.ts +15 -0
- package/app/api/auth/status/route.ts +6 -0
- package/app/api/default-cwd/route.ts +22 -0
- package/app/api/files/[...path]/route.ts +621 -0
- package/app/api/harness/route.ts +47 -0
- package/app/api/home/route.ts +6 -0
- package/app/api/internal/runtime/route.ts +26 -0
- package/app/api/models/route.ts +67 -0
- package/app/api/models-config/discover/route.ts +42 -0
- package/app/api/models-config/route.ts +152 -0
- package/app/api/models-config/test/route.ts +154 -0
- package/app/api/projects/browse/route.ts +51 -0
- package/app/api/projects/route.ts +83 -0
- package/app/api/reports/[id]/route.ts +108 -0
- package/app/api/search/route.ts +122 -0
- package/app/api/sessions/[id]/context/route.ts +23 -0
- package/app/api/sessions/[id]/route.ts +124 -0
- package/app/api/sessions/new/route.ts +5 -0
- package/app/api/sessions/route.ts +16 -0
- package/app/api/settings/route.ts +51 -0
- package/app/api/skills/install/route.ts +249 -0
- package/app/api/skills/route.ts +161 -0
- package/app/api/skills/search/route.ts +121 -0
- package/app/api/soul/route.ts +47 -0
- package/app/api/version/route.ts +55 -0
- package/app/globals.css +736 -0
- package/app/layout.tsx +40 -0
- package/app/login/page.tsx +133 -0
- package/app/page.tsx +10 -0
- package/components/AppShell.tsx +1058 -0
- package/components/ChatInput.tsx +1103 -0
- package/components/ChatMinimap.tsx +381 -0
- package/components/ChatWindow.tsx +576 -0
- package/components/CodeMirrorEditor.tsx +137 -0
- package/components/ConversationSearch.tsx +369 -0
- package/components/DataTableViewer.tsx +248 -0
- package/components/FileExplorer.tsx +758 -0
- package/components/FileIcons.tsx +241 -0
- package/components/FileViewer.tsx +1273 -0
- package/components/GlobalFileEditor.tsx +98 -0
- package/components/MarkdownRenderer.tsx +331 -0
- package/components/MermaidDiagram.tsx +80 -0
- package/components/MessageView.tsx +1141 -0
- package/components/ModelsConfig.tsx +1991 -0
- package/components/ProjectContext.tsx +252 -0
- package/components/ProjectFolderPicker.tsx +202 -0
- package/components/ProjectsConfig.tsx +288 -0
- package/components/ProviderIcons.tsx +91 -0
- package/components/ReportPanel.tsx +237 -0
- package/components/ResizeHandle.tsx +105 -0
- package/components/SessionSidebar.tsx +1464 -0
- package/components/SettingsDialog.tsx +287 -0
- package/components/SkillsConfig.tsx +1093 -0
- package/components/SubagentPanel.tsx +191 -0
- package/components/TabBar.tsx +115 -0
- package/components/ToolPanel.tsx +131 -0
- package/components/WidgetRenderer.tsx +505 -0
- package/components/viewers/DocumentToolbar.tsx +78 -0
- package/components/viewers/DocxViewer.tsx +97 -0
- package/components/viewers/PdfViewer.tsx +206 -0
- package/components/viewers/PptxViewer.tsx +240 -0
- package/components/viewers/XlsxViewer.tsx +143 -0
- package/hooks/useAgentSession.ts +710 -0
- package/hooks/useAudio.ts +50 -0
- package/hooks/useDragDrop.ts +52 -0
- package/hooks/useResizable.ts +60 -0
- package/hooks/useTheme.ts +85 -0
- package/lib/agent-client.ts +39 -0
- package/lib/annodex-config.ts +556 -0
- package/lib/auth-token.ts +74 -0
- package/lib/auth.ts +90 -0
- package/lib/brand.ts +5 -0
- package/lib/code-theme.ts +32 -0
- package/lib/codex-compat-proxy.ts +1603 -0
- package/lib/codex-home.ts +6 -0
- package/lib/codex-server.ts +796 -0
- package/lib/codex-session.ts +590 -0
- package/lib/codex-usage.ts +213 -0
- package/lib/file-paths.ts +34 -0
- package/lib/model-discovery.ts +379 -0
- package/lib/normalize.ts +30 -0
- package/lib/npx.ts +87 -0
- package/lib/pi-types.ts +49 -0
- package/lib/projects.ts +269 -0
- package/lib/provider-api.ts +88 -0
- package/lib/report-prompt.ts +61 -0
- package/lib/report-store.ts +597 -0
- package/lib/report-update-parser.ts +66 -0
- package/lib/rpc-manager.ts +668 -0
- package/lib/runtime-state.ts +117 -0
- package/lib/session-reader.ts +903 -0
- package/lib/session-runtime.ts +105 -0
- package/lib/subagent-progress.ts +279 -0
- package/lib/types.ts +241 -0
- package/lib/widget-export.ts +318 -0
- package/lib/widget-guidelines.ts +288 -0
- package/lib/widget-prompt.ts +76 -0
- package/lib/widget-utils.ts +523 -0
- package/package.json +23 -18
- package/postcss.config.mjs +8 -0
- package/proxy.ts +64 -0
- package/scripts/postinstall.cjs +25 -0
- package/tsconfig.json +41 -0
- package/.next/BUILD_ID +0 -1
- package/.next/app-path-routes-manifest.json +0 -39
- package/.next/build-manifest.json +0 -20
- package/.next/diagnostics/build-diagnostics.json +0 -6
- package/.next/diagnostics/framework.json +0 -1
- package/.next/export-marker.json +0 -6
- package/.next/images-manifest.json +0 -68
- package/.next/next-minimal-server.js.nft.json +0 -1
- package/.next/next-server.js.nft.json +0 -1
- package/.next/package.json +0 -1
- package/.next/prerender-manifest.json +0 -109
- package/.next/react-loadable-manifest.json +0 -2320
- package/.next/required-server-files.js +0 -343
- package/.next/required-server-files.json +0 -343
- package/.next/routes-manifest.json +0 -286
- package/.next/server/app/_global-error/page.js +0 -32
- package/.next/server/app/_global-error/page.js.nft.json +0 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +0 -1
- package/.next/server/app/_global-error.html +0 -1
- package/.next/server/app/_global-error.meta +0 -16
- package/.next/server/app/_global-error.rsc +0 -14
- package/.next/server/app/_global-error.segments/_full.segment.rsc +0 -14
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +0 -5
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +0 -5
- package/.next/server/app/_global-error.segments/_head.segment.rsc +0 -5
- package/.next/server/app/_global-error.segments/_index.segment.rsc +0 -5
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +0 -1
- package/.next/server/app/_not-found/page.js +0 -2
- package/.next/server/app/_not-found/page.js.nft.json +0 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +0 -1
- package/.next/server/app/_not-found.html +0 -1
- package/.next/server/app/_not-found.meta +0 -16
- package/.next/server/app/_not-found.rsc +0 -18
- package/.next/server/app/_not-found.segments/_full.segment.rsc +0 -18
- package/.next/server/app/_not-found.segments/_head.segment.rsc +0 -6
- package/.next/server/app/_not-found.segments/_index.segment.rsc +0 -5
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +0 -5
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +0 -5
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +0 -4
- package/.next/server/app/api/agent/[id]/events/route.js +0 -3
- package/.next/server/app/api/agent/[id]/events/route.js.nft.json +0 -1
- package/.next/server/app/api/agent/[id]/events/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/agent/[id]/route.js +0 -1
- package/.next/server/app/api/agent/[id]/route.js.nft.json +0 -1
- package/.next/server/app/api/agent/[id]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/agent/new/route.js +0 -1
- package/.next/server/app/api/agent/new/route.js.nft.json +0 -1
- package/.next/server/app/api/agent/new/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/all-providers/route.js +0 -1
- package/.next/server/app/api/auth/all-providers/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/all-providers/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/api-key/[provider]/route.js +0 -1
- package/.next/server/app/api/auth/api-key/[provider]/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/api-key/[provider]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/login/[provider]/route.js +0 -1
- package/.next/server/app/api/auth/login/[provider]/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/login/[provider]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/login/route.js +0 -1
- package/.next/server/app/api/auth/login/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/login/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/logout/[provider]/route.js +0 -1
- package/.next/server/app/api/auth/logout/[provider]/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/logout/[provider]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/providers/route.js +0 -1
- package/.next/server/app/api/auth/providers/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/providers/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/auth/status/route.js +0 -1
- package/.next/server/app/api/auth/status/route.js.nft.json +0 -1
- package/.next/server/app/api/auth/status/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/default-cwd/route.js +0 -1
- package/.next/server/app/api/default-cwd/route.js.nft.json +0 -1
- package/.next/server/app/api/default-cwd/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/files/[...path]/route.js +0 -4
- package/.next/server/app/api/files/[...path]/route.js.nft.json +0 -1
- package/.next/server/app/api/files/[...path]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/harness/route.js +0 -1
- package/.next/server/app/api/harness/route.js.nft.json +0 -1
- package/.next/server/app/api/harness/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/home/route.js +0 -1
- package/.next/server/app/api/home/route.js.nft.json +0 -1
- package/.next/server/app/api/home/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/internal/runtime/route.js +0 -1
- package/.next/server/app/api/internal/runtime/route.js.nft.json +0 -1
- package/.next/server/app/api/internal/runtime/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/models/route.js +0 -1
- package/.next/server/app/api/models/route.js.nft.json +0 -1
- package/.next/server/app/api/models/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/models-config/discover/route.js +0 -1
- package/.next/server/app/api/models-config/discover/route.js.nft.json +0 -1
- package/.next/server/app/api/models-config/discover/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/models-config/route.js +0 -1
- package/.next/server/app/api/models-config/route.js.nft.json +0 -1
- package/.next/server/app/api/models-config/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/models-config/test/route.js +0 -1
- package/.next/server/app/api/models-config/test/route.js.nft.json +0 -1
- package/.next/server/app/api/models-config/test/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/projects/browse/route.js +0 -1
- package/.next/server/app/api/projects/browse/route.js.nft.json +0 -1
- package/.next/server/app/api/projects/browse/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/projects/route.js +0 -1
- package/.next/server/app/api/projects/route.js.nft.json +0 -1
- package/.next/server/app/api/projects/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/reports/[id]/route.js +0 -10
- package/.next/server/app/api/reports/[id]/route.js.nft.json +0 -1
- package/.next/server/app/api/reports/[id]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/search/route.js +0 -1
- package/.next/server/app/api/search/route.js.nft.json +0 -1
- package/.next/server/app/api/search/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/sessions/[id]/context/route.js +0 -1
- package/.next/server/app/api/sessions/[id]/context/route.js.nft.json +0 -1
- package/.next/server/app/api/sessions/[id]/context/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/sessions/[id]/route.js +0 -1
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +0 -1
- package/.next/server/app/api/sessions/[id]/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/sessions/new/route.js +0 -1
- package/.next/server/app/api/sessions/new/route.js.nft.json +0 -1
- package/.next/server/app/api/sessions/new/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/sessions/route.js +0 -1
- package/.next/server/app/api/sessions/route.js.nft.json +0 -1
- package/.next/server/app/api/sessions/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/settings/route.js +0 -1
- package/.next/server/app/api/settings/route.js.nft.json +0 -1
- package/.next/server/app/api/settings/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/skills/install/route.js +0 -5
- package/.next/server/app/api/skills/install/route.js.nft.json +0 -1
- package/.next/server/app/api/skills/install/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/skills/route.js +0 -6
- package/.next/server/app/api/skills/route.js.nft.json +0 -1
- package/.next/server/app/api/skills/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/skills/search/route.js +0 -1
- package/.next/server/app/api/skills/search/route.js.nft.json +0 -1
- package/.next/server/app/api/skills/search/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/soul/route.js +0 -1
- package/.next/server/app/api/soul/route.js.nft.json +0 -1
- package/.next/server/app/api/soul/route_client-reference-manifest.js +0 -1
- package/.next/server/app/api/version/route.js +0 -1
- package/.next/server/app/api/version/route.js.nft.json +0 -1
- package/.next/server/app/api/version/route_client-reference-manifest.js +0 -1
- package/.next/server/app/index.html +0 -1
- package/.next/server/app/index.meta +0 -14
- package/.next/server/app/index.rsc +0 -17
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +0 -6
- package/.next/server/app/index.segments/_full.segment.rsc +0 -17
- package/.next/server/app/index.segments/_head.segment.rsc +0 -6
- package/.next/server/app/index.segments/_index.segment.rsc +0 -5
- package/.next/server/app/index.segments/_tree.segment.rsc +0 -4
- package/.next/server/app/login/page.js +0 -2
- package/.next/server/app/login/page.js.nft.json +0 -1
- package/.next/server/app/login/page_client-reference-manifest.js +0 -1
- package/.next/server/app/login.html +0 -1
- package/.next/server/app/login.meta +0 -15
- package/.next/server/app/login.rsc +0 -22
- package/.next/server/app/login.segments/_full.segment.rsc +0 -22
- package/.next/server/app/login.segments/_head.segment.rsc +0 -6
- package/.next/server/app/login.segments/_index.segment.rsc +0 -5
- package/.next/server/app/login.segments/_tree.segment.rsc +0 -4
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +0 -9
- package/.next/server/app/login.segments/login.segment.rsc +0 -5
- package/.next/server/app/page.js +0 -261
- package/.next/server/app/page.js.nft.json +0 -1
- package/.next/server/app/page_client-reference-manifest.js +0 -1
- package/.next/server/app-paths-manifest.json +0 -39
- package/.next/server/chunks/1048.js +0 -1
- package/.next/server/chunks/1367.js +0 -77
- package/.next/server/chunks/1381.js +0 -1
- package/.next/server/chunks/165.js +0 -1
- package/.next/server/chunks/1681.js +0 -215
- package/.next/server/chunks/1688.js +0 -45
- package/.next/server/chunks/1703.js +0 -79
- package/.next/server/chunks/1712.js +0 -43
- package/.next/server/chunks/1813.js +0 -1
- package/.next/server/chunks/2325.js +0 -80
- package/.next/server/chunks/258.js +0 -1
- package/.next/server/chunks/2671.js +0 -287
- package/.next/server/chunks/2778.js +0 -1
- package/.next/server/chunks/2943.js +0 -1
- package/.next/server/chunks/3031.js +0 -226
- package/.next/server/chunks/3181.js +0 -1
- package/.next/server/chunks/3493.js +0 -1
- package/.next/server/chunks/3672.js +0 -1
- package/.next/server/chunks/3701.js +0 -104
- package/.next/server/chunks/4013.js +0 -1
- package/.next/server/chunks/402.js +0 -2
- package/.next/server/chunks/4035.js +0 -80
- package/.next/server/chunks/4248.js +0 -153
- package/.next/server/chunks/4367.js +0 -1
- package/.next/server/chunks/4406.js +0 -141
- package/.next/server/chunks/4741.js +0 -18
- package/.next/server/chunks/4768.js +0 -1
- package/.next/server/chunks/4858.js +0 -148
- package/.next/server/chunks/4980.js +0 -1
- package/.next/server/chunks/5155.js +0 -5
- package/.next/server/chunks/5293.js +0 -166
- package/.next/server/chunks/5399.js +0 -8
- package/.next/server/chunks/5409.js +0 -1
- package/.next/server/chunks/5797.js +0 -93
- package/.next/server/chunks/5851.js +0 -36
- package/.next/server/chunks/6206.js +0 -1
- package/.next/server/chunks/6296.js +0 -1
- package/.next/server/chunks/63.js +0 -45
- package/.next/server/chunks/6346.js +0 -1
- package/.next/server/chunks/6406.js +0 -23
- package/.next/server/chunks/642.js +0 -1
- package/.next/server/chunks/6429.js +0 -50
- package/.next/server/chunks/6729.js +0 -64
- package/.next/server/chunks/6907.js +0 -115
- package/.next/server/chunks/6980.js +0 -1
- package/.next/server/chunks/7073.js +0 -24
- package/.next/server/chunks/7233.js +0 -24
- package/.next/server/chunks/7307.js +0 -1
- package/.next/server/chunks/7362.js +0 -9
- package/.next/server/chunks/7567.js +0 -29
- package/.next/server/chunks/7765.js +0 -1
- package/.next/server/chunks/7890.js +0 -1
- package/.next/server/chunks/8065.js +0 -1
- package/.next/server/chunks/8238.js +0 -34
- package/.next/server/chunks/8276.js +0 -1
- package/.next/server/chunks/8336.js +0 -1
- package/.next/server/chunks/8477.js +0 -3
- package/.next/server/chunks/8490.js +0 -1
- package/.next/server/chunks/8916.js +0 -1
- package/.next/server/chunks/9280.js +0 -252
- package/.next/server/chunks/9315.js +0 -1
- package/.next/server/chunks/9537.js +0 -90
- package/.next/server/chunks/966.js +0 -1
- package/.next/server/chunks/9818.js +0 -21
- package/.next/server/chunks/static/media/pdf.worker.min.c476e1a0.mjs +0 -6
- package/.next/server/functions-config-manifest.json +0 -16
- package/.next/server/interception-route-rewrite-manifest.js +0 -1
- package/.next/server/middleware-build-manifest.js +0 -1
- package/.next/server/middleware-manifest.json +0 -6
- package/.next/server/middleware-react-loadable-manifest.js +0 -1
- package/.next/server/middleware.js +0 -18
- package/.next/server/middleware.js.nft.json +0 -1
- package/.next/server/next-font-manifest.js +0 -1
- package/.next/server/next-font-manifest.json +0 -1
- package/.next/server/pages/404.html +0 -1
- package/.next/server/pages/500.html +0 -1
- package/.next/server/pages-manifest.json +0 -4
- package/.next/server/prefetch-hints.json +0 -1
- package/.next/server/server-reference-manifest.js +0 -1
- package/.next/server/server-reference-manifest.json +0 -1
- package/.next/server/webpack-runtime.js +0 -1
- package/.next/static/chunks/0b9a0da7.9075af772487e743.js +0 -62
- package/.next/static/chunks/1413.922d232de90c0c41.js +0 -115
- package/.next/static/chunks/1643.467a526a1f24f54d.js +0 -24
- package/.next/static/chunks/1852.5543122f11aa7fed.js +0 -1
- package/.next/static/chunks/1960.b1e26436d7a5f586.js +0 -1
- package/.next/static/chunks/2170a4aa.4213bb2183c9cdf9.js +0 -1
- package/.next/static/chunks/2274.6cd173f80a1405a2.js +0 -21
- package/.next/static/chunks/2419.347fdfe3c170854d.js +0 -166
- package/.next/static/chunks/2619.9aac8983f30c7c8a.js +0 -1
- package/.next/static/chunks/2623.d20fabd8e18197c6.js +0 -287
- package/.next/static/chunks/2729.f5365061a849d659.js +0 -34
- package/.next/static/chunks/2821.934bcf60fbdc28c6.js +0 -1
- package/.next/static/chunks/2918becc.abff2ece1de37bc1.js +0 -153
- package/.next/static/chunks/2947.114e51cb06d1c01a.js +0 -23
- package/.next/static/chunks/3079.4c511fa1144e3adf.js +0 -79
- package/.next/static/chunks/3274.208ca44844cd7d95.js +0 -148
- package/.next/static/chunks/3308.465a94263d04bfea.js +0 -73
- package/.next/static/chunks/3325.e4bfe1ca657f3b5b.js +0 -80
- package/.next/static/chunks/3506.2a7eaa08b9f55337.js +0 -90
- package/.next/static/chunks/363642f4-043c1475ab9af70e.js +0 -1
- package/.next/static/chunks/3794-123fdf632563f469.js +0 -32
- package/.next/static/chunks/3837.a755ccfe6f9c1c1c.js +0 -5
- package/.next/static/chunks/394.91597771688df6d0.js +0 -1
- package/.next/static/chunks/3997.1009c06025691712.js +0 -1
- package/.next/static/chunks/4453.91a357dc43c21745.js +0 -1
- package/.next/static/chunks/4491.44fdf20580ac72bd.js +0 -24
- package/.next/static/chunks/4829.cf1d50e43e6d9db5.js +0 -1
- package/.next/static/chunks/498.fe1d9da9ecad6c36.js +0 -1
- package/.next/static/chunks/4bd1b696-e356ca5ba0218e27.js +0 -1
- package/.next/static/chunks/5019.b5a1a2b8daf17525.js +0 -1
- package/.next/static/chunks/5034.8f16c3fa3ce75411.js +0 -1
- package/.next/static/chunks/5074.d16651da01ec4e02.js +0 -1
- package/.next/static/chunks/51fb665c.0950e1b79671348d.js +0 -45
- package/.next/static/chunks/532.5956ed631aff722b.js +0 -9
- package/.next/static/chunks/5326.69460442bdcd6cd3.js +0 -1
- package/.next/static/chunks/5403.ff110bf5bf600758.js +0 -64
- package/.next/static/chunks/547.902a733488cfe3f7.js +0 -77
- package/.next/static/chunks/5567.540d7fc108ad6ee5.js +0 -215
- package/.next/static/chunks/5590.ef62922166d308b4.js +0 -1
- package/.next/static/chunks/5690.9d6eb1edb1399995.js +0 -1
- package/.next/static/chunks/5749.25faee4a1e55b854.js +0 -226
- package/.next/static/chunks/58bb9007.1ccb6bba34b4c635.js +0 -80
- package/.next/static/chunks/6121.f3f43f1896ea0cd9.js +0 -1
- package/.next/static/chunks/6600.583c88eef37aa524.js +0 -1
- package/.next/static/chunks/6696.a41aec266e657d54.js +0 -141
- package/.next/static/chunks/6922.42148793782d2fe7.js +0 -1
- package/.next/static/chunks/7006.e191611ffc2b9528.js +0 -43
- package/.next/static/chunks/7343.9fbb58204d8ac681.js +0 -1
- package/.next/static/chunks/73972abe.25a4cffa03b2bcef.js +0 -119
- package/.next/static/chunks/7547.58bda8a2aabba0d4.js +0 -93
- package/.next/static/chunks/7648.4ae2f183b4db0353.js +0 -1
- package/.next/static/chunks/7874.8db6929b94cdf697.js +0 -1
- package/.next/static/chunks/7959.1f20a35df316216a.js +0 -104
- package/.next/static/chunks/83.85d62d7fc9850b75.js +0 -29
- package/.next/static/chunks/8436.cab94b59cca0a8ff.js +0 -1
- package/.next/static/chunks/8451.ff6ff72b57dc52e1.js +0 -1
- package/.next/static/chunks/8489.45f22859734f514f.js +0 -36
- package/.next/static/chunks/8568.f85d8b36fc9a9037.js +0 -1
- package/.next/static/chunks/8771-3e14b6810486df1f.js +0 -1
- package/.next/static/chunks/8863.be51033a67436277.js +0 -1
- package/.next/static/chunks/90542734.dc1a2723e4f6affb.js +0 -1
- package/.next/static/chunks/9500.1488aec06ee78127.js +0 -1
- package/.next/static/chunks/9633.155548b5fca6e580.js +0 -1
- package/.next/static/chunks/9779.673004a62d70e36a.js +0 -1
- package/.next/static/chunks/app/_global-error/page-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/_not-found/page-c72daab99269beff.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/events/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/agent/new/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/all-providers/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/api-key/[provider]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/login/[provider]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/login/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/logout/[provider]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/providers/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/auth/status/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/default-cwd/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/files/[...path]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/harness/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/home/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/internal/runtime/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/models/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/models-config/discover/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/models-config/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/models-config/test/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/projects/browse/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/projects/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/reports/[id]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/search/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/context/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/sessions/new/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/sessions/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/settings/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/skills/install/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/skills/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/skills/search/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/soul/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/api/version/route-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/app/layout-be148b7ae915b22a.js +0 -1
- package/.next/static/chunks/app/login/page-ebf0e6de99062783.js +0 -1
- package/.next/static/chunks/app/page-a4bfb7d711561cb3.js +0 -260
- package/.next/static/chunks/d3ac728e.7964f816a1ca64e5.js +0 -1
- package/.next/static/chunks/framework-711ef29bc66f648c.js +0 -1
- package/.next/static/chunks/main-app-45a0f19af99d61b6.js +0 -1
- package/.next/static/chunks/main-f74964b7ae52493e.js +0 -5
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/global-error-9bfa08b9491621f2.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-cc518af6b1ffb191.js +0 -1
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
- package/.next/static/chunks/webpack-fcf4a889ecbd753c.js +0 -1
- package/.next/static/css/45029451a1d7255d.css +0 -3
- package/.next/static/lFCcFmLd1ThQXTFUP6olh/_buildManifest.js +0 -1
- package/.next/static/lFCcFmLd1ThQXTFUP6olh/_ssgManifest.js +0 -1
- package/.next/static/media/15605e25b523335c-s.woff2 +0 -0
- package/.next/static/media/1a3dce5cfb5f7760-s.woff2 +0 -0
- package/.next/static/media/1cdd02902f937a18-s.woff2 +0 -0
- package/.next/static/media/4c4b3b30b6bcb2be-s.woff2 +0 -0
- package/.next/static/media/641a7b8a5800ee0e-s.woff2 +0 -0
- package/.next/static/media/7deddc85b7ffd1dc-s.p.woff2 +0 -0
- package/.next/static/media/ec14413c594b3356-s.p.woff2 +0 -0
- package/.next/static/media/pdf.worker.min.29aaf158.mjs +0 -6
- package/.next/trace +0 -74
- package/.next/trace-build +0 -1
- package/.next/types/app/api/agent/[id]/events/route.ts +0 -351
- package/.next/types/app/api/agent/[id]/route.ts +0 -351
- package/.next/types/app/api/agent/new/route.ts +0 -351
- package/.next/types/app/api/auth/all-providers/route.ts +0 -351
- package/.next/types/app/api/auth/api-key/[provider]/route.ts +0 -351
- package/.next/types/app/api/auth/login/[provider]/route.ts +0 -351
- package/.next/types/app/api/auth/login/route.ts +0 -351
- package/.next/types/app/api/auth/logout/[provider]/route.ts +0 -351
- package/.next/types/app/api/auth/providers/route.ts +0 -351
- package/.next/types/app/api/auth/status/route.ts +0 -351
- package/.next/types/app/api/default-cwd/route.ts +0 -351
- package/.next/types/app/api/files/[...path]/route.ts +0 -351
- package/.next/types/app/api/harness/route.ts +0 -351
- package/.next/types/app/api/home/route.ts +0 -351
- package/.next/types/app/api/internal/runtime/route.ts +0 -351
- package/.next/types/app/api/models/route.ts +0 -351
- package/.next/types/app/api/models-config/discover/route.ts +0 -351
- package/.next/types/app/api/models-config/route.ts +0 -351
- package/.next/types/app/api/models-config/test/route.ts +0 -351
- package/.next/types/app/api/projects/browse/route.ts +0 -351
- package/.next/types/app/api/projects/route.ts +0 -351
- package/.next/types/app/api/reports/[id]/route.ts +0 -351
- package/.next/types/app/api/search/route.ts +0 -351
- package/.next/types/app/api/sessions/[id]/context/route.ts +0 -351
- package/.next/types/app/api/sessions/[id]/route.ts +0 -351
- package/.next/types/app/api/sessions/new/route.ts +0 -351
- package/.next/types/app/api/sessions/route.ts +0 -351
- package/.next/types/app/api/settings/route.ts +0 -351
- package/.next/types/app/api/skills/install/route.ts +0 -351
- package/.next/types/app/api/skills/route.ts +0 -351
- package/.next/types/app/api/skills/search/route.ts +0 -351
- package/.next/types/app/api/soul/route.ts +0 -351
- package/.next/types/app/api/version/route.ts +0 -351
- package/.next/types/app/layout.ts +0 -87
- package/.next/types/app/login/page.ts +0 -87
- package/.next/types/app/page.ts +0 -87
- package/.next/types/package.json +0 -1
- package/.next/types/routes.d.ts +0 -106
- package/.next/types/validator.ts +0 -376
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import type { AgentMessage, SessionContext } from "@/lib/types";
|
|
4
|
+
|
|
5
|
+
// ---- Local getConfigDir (annodex config) ----
|
|
6
|
+
function getAgentDir(): string {
|
|
7
|
+
const homeDir = process.env.HOME ?? process.env.USERPROFILE ?? "/tmp";
|
|
8
|
+
return join(homeDir, ".config", "annodex");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AnalysisReportSource {
|
|
12
|
+
type: "session" | "file";
|
|
13
|
+
id?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
label: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AnalysisReportChange {
|
|
19
|
+
id: string;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
title: string;
|
|
22
|
+
detail: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AnalysisReportSection {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
markdown: string;
|
|
29
|
+
status: "draft" | "verified" | "outdated" | "needs_review";
|
|
30
|
+
updatedAt: string | null;
|
|
31
|
+
sources: AnalysisReportSource[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AnalysisReport {
|
|
35
|
+
schemaVersion: 1;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
cwd: string;
|
|
38
|
+
title: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
markdown: string;
|
|
42
|
+
sections: AnalysisReportSection[];
|
|
43
|
+
sources: AnalysisReportSource[];
|
|
44
|
+
changes: AnalysisReportChange[];
|
|
45
|
+
appliedUpdateKeys?: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AnalysisReportUpdate {
|
|
49
|
+
topic?: string;
|
|
50
|
+
section?: string;
|
|
51
|
+
action?: "append" | "replace";
|
|
52
|
+
status?: AnalysisReportSection["status"];
|
|
53
|
+
markdown?: string;
|
|
54
|
+
sources?: Array<string | AnalysisReportSource>;
|
|
55
|
+
invalidates?: string[];
|
|
56
|
+
note?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const SECTION_DEFS = [
|
|
60
|
+
{ id: "objective", title: "Objective" },
|
|
61
|
+
{ id: "input_data", title: "Input Data" },
|
|
62
|
+
{ id: "methods", title: "Methods" },
|
|
63
|
+
{ id: "quality_control", title: "Quality Control" },
|
|
64
|
+
{ id: "results", title: "Results" },
|
|
65
|
+
{ id: "interpretation", title: "Biological Interpretation" },
|
|
66
|
+
{ id: "outputs", title: "Output Files" },
|
|
67
|
+
{ id: "reproducibility", title: "Reproducibility" },
|
|
68
|
+
] as const;
|
|
69
|
+
|
|
70
|
+
const FILE_PATH_RE = /(?:^|[\s(["'`])((?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+?\.(?:csv|tsv|txt|xlsx|xls|pdf|png|jpg|jpeg|svg|html|htm|r|R|py|ipynb|qmd|md|rds|h5ad|loom|mtx|tsv\.gz|csv\.gz))(?:$|[\s)\]"'`,;:])/g;
|
|
71
|
+
const OUTPUT_DIR_RE = /(?:^|[\s(["'`])((?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+\/)(?=\s*(?:[::-]|[0-9]+|含|共|files?|个文件|PDFs?|PNGs?|CSVs?|TSVs?|输出|output|results?))/gim;
|
|
72
|
+
const METHOD_RE = /\b(seurat|scanpy|single[- ]cell|scrna|qc|quality control|normalize|normalization|pca|umap|tsne|cluster|clustering|resolution|marker|differential expression|deg|go enrichment|kegg|reactome|pathway|cell type|annotation|doublet|batch|integration|harmony|scvi)\b/i;
|
|
73
|
+
const RESULT_RE = /\b(result|found|identified|showed|observed|enriched|upregulated|downregulated|marker|cluster|cell type|figure|plot|table|significant|p\s*[<>=]|fdr|padj|logfc|auc)\b/i;
|
|
74
|
+
const INTERPRET_RE = /\b(suggest|indicate|imply|consistent with|biological|interpret|likely|may reflect|supports|driven by|associated with)\b/i;
|
|
75
|
+
const QC_RE = /\b(qc|quality control|filter|filtered|mitochondrial|percent\.mt|nfeature|ncount|doublet|ambient|low[- ]quality)\b/i;
|
|
76
|
+
const BIO_ANALYSIS_RE = /\b(seurat|scanpy|single[- ]cell|scrna|sc[- ]rna|rna[- ]seq|transcriptom|gene|genes|marker|cell type|cluster|clustering|umap|tsne|pca|qc|mitochondrial|percent\.mt|nfeature|ncount|deg|differential expression|go enrichment|kegg|reactome|pathway|gsea|volcano|heatmap|h5ad|rds|loom|mtx|fastq|bam|vcf|counts?|expression|annotation|doublet|batch|integration|harmony|scvi)\b|生信|单细胞|转录组|基因|表达矩阵|差异表达|富集|通路|聚类|细胞类型|细胞注释|质控|线粒体|标记基因|火山图|热图/i;
|
|
77
|
+
const EMPTY_SECTION_MARKDOWN = new Set([
|
|
78
|
+
"_No curated content yet._",
|
|
79
|
+
"_No analysis objective detected yet._",
|
|
80
|
+
"_No input data paths detected yet._",
|
|
81
|
+
"_No output files detected yet._",
|
|
82
|
+
"_No reproducibility notes detected yet._",
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
function nowIso(): string {
|
|
86
|
+
return new Date().toISOString();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function encodePathSegment(value: string): string {
|
|
90
|
+
return Buffer.from(value).toString("base64url");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getReportPath(sessionId: string): string {
|
|
94
|
+
return join(getAgentDir(), "reports", `${encodePathSegment(sessionId)}.json`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function makeEmptySection(id: string, title: string): AnalysisReportSection {
|
|
98
|
+
return { id, title, markdown: "", status: "draft", updatedAt: null, sources: [] };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeEmptyMarkdown(value: string): string {
|
|
102
|
+
const trimmed = value.trim();
|
|
103
|
+
return EMPTY_SECTION_MARKDOWN.has(trimmed) ? "" : trimmed;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function hasReportSectionContent(sections: AnalysisReportSection[]): boolean {
|
|
107
|
+
return sections.some((section) => normalizeEmptyMarkdown(section.markdown).length > 0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function createEmptyReport(sessionId: string, cwd: string, title?: string): AnalysisReport {
|
|
111
|
+
const timestamp = nowIso();
|
|
112
|
+
const sections = SECTION_DEFS.map((section) => makeEmptySection(section.id, section.title));
|
|
113
|
+
return {
|
|
114
|
+
schemaVersion: 1,
|
|
115
|
+
sessionId,
|
|
116
|
+
cwd,
|
|
117
|
+
title: title || "Analysis Report",
|
|
118
|
+
createdAt: timestamp,
|
|
119
|
+
updatedAt: timestamp,
|
|
120
|
+
markdown: "",
|
|
121
|
+
sections,
|
|
122
|
+
sources: [],
|
|
123
|
+
changes: [],
|
|
124
|
+
appliedUpdateKeys: [],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function readReport(sessionId: string, cwd = "", title?: string): AnalysisReport {
|
|
129
|
+
const filePath = getReportPath(sessionId);
|
|
130
|
+
if (!existsSync(filePath)) return createEmptyReport(sessionId, cwd, title);
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const parsed = JSON.parse(readFileSync(filePath, "utf8")) as Partial<AnalysisReport>;
|
|
134
|
+
const fallback = createEmptyReport(sessionId, cwd, title);
|
|
135
|
+
const existingSections = Array.isArray(parsed.sections) ? parsed.sections : [];
|
|
136
|
+
const sections = SECTION_DEFS.map((def) => {
|
|
137
|
+
const existing = existingSections.find((section) => section?.id === def.id);
|
|
138
|
+
const markdown = normalizeEmptyMarkdown(typeof existing?.markdown === "string" ? existing.markdown : "");
|
|
139
|
+
return {
|
|
140
|
+
...makeEmptySection(def.id, def.title),
|
|
141
|
+
...(existing && typeof existing === "object" ? existing : {}),
|
|
142
|
+
id: def.id,
|
|
143
|
+
title: def.title,
|
|
144
|
+
markdown,
|
|
145
|
+
status: markdown ? (existing?.status ?? "draft") : "draft",
|
|
146
|
+
updatedAt: markdown ? (existing?.updatedAt ?? null) : null,
|
|
147
|
+
sources: markdown && Array.isArray(existing?.sources) ? existing.sources : [],
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
const reportTitle = typeof parsed.title === "string" && parsed.title.trim() ? parsed.title : fallback.title;
|
|
151
|
+
return {
|
|
152
|
+
...fallback,
|
|
153
|
+
...parsed,
|
|
154
|
+
schemaVersion: 1,
|
|
155
|
+
sessionId,
|
|
156
|
+
cwd: typeof parsed.cwd === "string" ? parsed.cwd : cwd,
|
|
157
|
+
title: reportTitle,
|
|
158
|
+
createdAt: typeof parsed.createdAt === "string" ? parsed.createdAt : fallback.createdAt,
|
|
159
|
+
updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : fallback.updatedAt,
|
|
160
|
+
sections,
|
|
161
|
+
markdown: renderReportMarkdown(reportTitle, sections),
|
|
162
|
+
sources: hasReportSectionContent(sections) && Array.isArray(parsed.sources) ? parsed.sources : [],
|
|
163
|
+
changes: hasReportSectionContent(sections) && Array.isArray(parsed.changes) ? parsed.changes : [],
|
|
164
|
+
appliedUpdateKeys: Array.isArray(parsed.appliedUpdateKeys)
|
|
165
|
+
? parsed.appliedUpdateKeys.filter((key): key is string => typeof key === "string")
|
|
166
|
+
: [],
|
|
167
|
+
};
|
|
168
|
+
} catch {
|
|
169
|
+
return createEmptyReport(sessionId, cwd, title);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function stableHash(value: string): string {
|
|
174
|
+
let hash = 2166136261;
|
|
175
|
+
for (let i = 0; i < value.length; i++) {
|
|
176
|
+
hash ^= value.charCodeAt(i);
|
|
177
|
+
hash = Math.imul(hash, 16777619);
|
|
178
|
+
}
|
|
179
|
+
return (hash >>> 0).toString(36);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function writeReport(report: AnalysisReport): AnalysisReport {
|
|
183
|
+
const timestamp = nowIso();
|
|
184
|
+
const next = {
|
|
185
|
+
...report,
|
|
186
|
+
updatedAt: timestamp,
|
|
187
|
+
markdown: renderReportMarkdown(report.title, report.sections),
|
|
188
|
+
};
|
|
189
|
+
const filePath = getReportPath(report.sessionId);
|
|
190
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
191
|
+
const tempPath = `${filePath}.tmp`;
|
|
192
|
+
writeFileSync(tempPath, JSON.stringify(next, null, 2), "utf8");
|
|
193
|
+
renameSync(tempPath, filePath);
|
|
194
|
+
return next;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function cleanText(value: string): string {
|
|
198
|
+
return value.replace(/\s+/g, " ").trim();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function escapeMarkdown(value: string): string {
|
|
202
|
+
return value.replace(/\|/g, "\\|");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function outputKind(filePath: string): string {
|
|
206
|
+
const lower = filePath.toLowerCase();
|
|
207
|
+
if (/\.(png|jpe?g|svg)$/.test(lower)) return "Representative image/figure.";
|
|
208
|
+
if (/\.pdf$/.test(lower)) return "PDF figure or report.";
|
|
209
|
+
if (/\.(csv|tsv|csv\.gz|tsv\.gz|xlsx?|mtx)$/.test(lower)) return "Result table or matrix.";
|
|
210
|
+
if (/\.(r|py|ipynb|qmd|md)$/.test(lower)) return "Analysis script or document.";
|
|
211
|
+
if (/\.(rds|h5ad|loom)$/.test(lower)) return "Analysis object or dataset.";
|
|
212
|
+
if (/\.(html?|svg)$/.test(lower)) return "Browser-renderable output.";
|
|
213
|
+
return "Detected from session output.";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isReportPreviewImage(filePath: string): boolean {
|
|
217
|
+
return /\.(png|jpe?g|svg)$/i.test(filePath);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function markdownImagePath(filePath: string): string {
|
|
221
|
+
return filePath.replace(/\\/g, "/").replace(/([()\s])/g, "\\$1");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function outputLabel(filePath: string): string {
|
|
225
|
+
return filePath.split(/[\\/]/).filter(Boolean).pop() ?? filePath;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function normalizeTopic(value?: string): string {
|
|
229
|
+
return cleanText(value ?? "").slice(0, 120);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function withTopicPrefix(markdown: string, topic?: string): string {
|
|
233
|
+
const trimmed = markdown.trim();
|
|
234
|
+
if (!trimmed) return "";
|
|
235
|
+
const normalizedTopic = normalizeTopic(topic);
|
|
236
|
+
if (!normalizedTopic) return trimmed;
|
|
237
|
+
const topicHeading = `### ${normalizedTopic}`;
|
|
238
|
+
if (trimmed === topicHeading || trimmed.startsWith(`${topicHeading}\n`)) return trimmed;
|
|
239
|
+
return `${topicHeading}\n\n${trimmed}`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function messageText(message: AgentMessage): string {
|
|
243
|
+
const content = message.content;
|
|
244
|
+
if (typeof content === "string") return cleanText(content);
|
|
245
|
+
if (!Array.isArray(content)) return "";
|
|
246
|
+
return cleanText(content
|
|
247
|
+
.map((block) => {
|
|
248
|
+
if (block.type === "text") return block.text;
|
|
249
|
+
if (block.type === "toolCall") return `${block.toolName} ${JSON.stringify(block.input)}`;
|
|
250
|
+
return "";
|
|
251
|
+
})
|
|
252
|
+
.join(" "));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function firstUserText(context: SessionContext): string {
|
|
256
|
+
const first = context.messages.find((message) => message.role === "user");
|
|
257
|
+
return first ? messageText(first).slice(0, 900) : "";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function firstAnalysisUserText(context: SessionContext): string {
|
|
261
|
+
const first = context.messages.find((message) => message.role === "user" && BIO_ANALYSIS_RE.test(messageText(message)));
|
|
262
|
+
return first ? messageText(first).slice(0, 900) : "";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function sessionHasBioAnalysisContent(context: SessionContext): boolean {
|
|
266
|
+
return context.messages.some((message) => BIO_ANALYSIS_RE.test(messageText(message)));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function uniquePush(values: string[], value: string, max: number): void {
|
|
270
|
+
const cleaned = cleanText(value);
|
|
271
|
+
if (!cleaned || values.includes(cleaned)) return;
|
|
272
|
+
values.push(cleaned);
|
|
273
|
+
if (values.length > max) values.length = max;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function extractOutputFiles(context: SessionContext): string[] {
|
|
277
|
+
const files: string[] = [];
|
|
278
|
+
for (const message of context.messages) {
|
|
279
|
+
const text = messageText(message);
|
|
280
|
+
if (!text) continue;
|
|
281
|
+
for (const match of text.matchAll(FILE_PATH_RE)) {
|
|
282
|
+
const filePath = match[1]?.replace(/[.,;:)]+$/, "");
|
|
283
|
+
if (filePath) uniquePush(files, filePath, 30);
|
|
284
|
+
}
|
|
285
|
+
for (const match of text.matchAll(OUTPUT_DIR_RE)) {
|
|
286
|
+
const dirPath = match[1]?.replace(/[.,;:)]+$/, "");
|
|
287
|
+
if (dirPath) uniquePush(files, dirPath, 30);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return files;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function collectSessionSignals(context: SessionContext): {
|
|
294
|
+
methods: string[];
|
|
295
|
+
qc: string[];
|
|
296
|
+
results: string[];
|
|
297
|
+
interpretation: string[];
|
|
298
|
+
reproducibility: string[];
|
|
299
|
+
} {
|
|
300
|
+
const methods: string[] = [];
|
|
301
|
+
const qc: string[] = [];
|
|
302
|
+
const results: string[] = [];
|
|
303
|
+
const interpretation: string[] = [];
|
|
304
|
+
const reproducibility: string[] = [];
|
|
305
|
+
|
|
306
|
+
for (const message of context.messages) {
|
|
307
|
+
const text = messageText(message);
|
|
308
|
+
if (!text || text.length < 12) continue;
|
|
309
|
+
const trimmed = text.length > 500 ? `${text.slice(0, 500).trim()}...` : text;
|
|
310
|
+
|
|
311
|
+
if (message.role === "assistant") {
|
|
312
|
+
if (QC_RE.test(trimmed)) uniquePush(qc, trimmed, 8);
|
|
313
|
+
if (METHOD_RE.test(trimmed)) uniquePush(methods, trimmed, 10);
|
|
314
|
+
if (RESULT_RE.test(trimmed)) uniquePush(results, trimmed, 12);
|
|
315
|
+
if (INTERPRET_RE.test(trimmed)) uniquePush(interpretation, trimmed, 8);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (message.role === "toolResult" && /saved|wrote|created|exported|generated|output|success/i.test(trimmed)) {
|
|
319
|
+
uniquePush(reproducibility, trimmed, 8);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return { methods, qc, results, interpretation, reproducibility };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function bullets(items: string[], empty = "_No curated content yet._"): string {
|
|
327
|
+
if (items.length === 0) return empty;
|
|
328
|
+
return items.map((item) => `- ${item}`).join("\n");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function outputTable(files: string[]): string {
|
|
332
|
+
if (files.length === 0) return "";
|
|
333
|
+
return [
|
|
334
|
+
"| File or Directory | Notes |",
|
|
335
|
+
"| --- | --- |",
|
|
336
|
+
...files.map((file) => `| \`${escapeMarkdown(file)}\` | ${outputKind(file)} |`),
|
|
337
|
+
].join("\n");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function representativeFigures(files: string[], maxFigures = 4): string {
|
|
341
|
+
const figures = files.filter(isReportPreviewImage).slice(0, maxFigures);
|
|
342
|
+
if (figures.length === 0) return "";
|
|
343
|
+
return [
|
|
344
|
+
"#### Representative Figures",
|
|
345
|
+
"",
|
|
346
|
+
...figures.flatMap((file) => {
|
|
347
|
+
const label = outputLabel(file);
|
|
348
|
+
return [
|
|
349
|
+
`})`,
|
|
350
|
+
"",
|
|
351
|
+
`_Figure: ${label}. Representative visual output detected from this analysis topic._`,
|
|
352
|
+
"",
|
|
353
|
+
];
|
|
354
|
+
}),
|
|
355
|
+
].join("\n").trim();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function combineMarkdown(parts: string[]): string {
|
|
359
|
+
return parts.map((part) => part.trim()).filter(Boolean).join("\n\n");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function updateSection(
|
|
363
|
+
report: AnalysisReport,
|
|
364
|
+
id: string,
|
|
365
|
+
markdown: string,
|
|
366
|
+
status: AnalysisReportSection["status"] = "draft",
|
|
367
|
+
sources: AnalysisReportSource[] = []
|
|
368
|
+
): void {
|
|
369
|
+
const section = report.sections.find((item) => item.id === id);
|
|
370
|
+
if (!section) return;
|
|
371
|
+
section.markdown = markdown.trim();
|
|
372
|
+
section.status = status;
|
|
373
|
+
section.updatedAt = nowIso();
|
|
374
|
+
section.sources = sources;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function normalizeSectionId(section?: string): string | null {
|
|
378
|
+
if (!section) return null;
|
|
379
|
+
const normalized = section.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
380
|
+
if (SECTION_DEFS.some((def) => def.id === normalized)) return normalized;
|
|
381
|
+
if (normalized.includes("objective") || normalized.includes("goal")) return "objective";
|
|
382
|
+
if (normalized.includes("input") || normalized.includes("sample") || normalized.includes("data")) return "input_data";
|
|
383
|
+
if (normalized.includes("method") || normalized.includes("parameter") || normalized.includes("workflow")) return "methods";
|
|
384
|
+
if (normalized.includes("qc") || normalized.includes("quality") || normalized.includes("filter")) return "quality_control";
|
|
385
|
+
if (normalized.includes("result") || normalized.includes("marker") || normalized.includes("deg") || normalized.includes("enrichment")) return "results";
|
|
386
|
+
if (normalized.includes("interpret") || normalized.includes("biology") || normalized.includes("biological")) return "interpretation";
|
|
387
|
+
if (normalized.includes("output") || normalized.includes("file") || normalized.includes("figure")) return "outputs";
|
|
388
|
+
if (normalized.includes("reproduc")) return "reproducibility";
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function normalizeSources(sources: AnalysisReportUpdate["sources"]): AnalysisReportSource[] {
|
|
393
|
+
if (!Array.isArray(sources)) return [];
|
|
394
|
+
const normalized: AnalysisReportSource[] = [];
|
|
395
|
+
for (const source of sources) {
|
|
396
|
+
if (typeof source === "string") {
|
|
397
|
+
normalized.push({ type: "file", path: source, label: source });
|
|
398
|
+
} else if (source && typeof source === "object" && typeof source.label === "string") {
|
|
399
|
+
normalized.push({
|
|
400
|
+
type: source.type === "session" ? "session" : "file",
|
|
401
|
+
id: typeof source.id === "string" ? source.id : undefined,
|
|
402
|
+
path: typeof source.path === "string" ? source.path : undefined,
|
|
403
|
+
label: source.label,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return normalized;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function applyReportUpdate(report: AnalysisReport, update: AnalysisReportUpdate, updateKey?: string): AnalysisReport {
|
|
411
|
+
const sectionId = normalizeSectionId(update.section);
|
|
412
|
+
const markdown = typeof update.markdown === "string" ? withTopicPrefix(update.markdown, update.topic) : "";
|
|
413
|
+
if (!sectionId || !markdown) return report;
|
|
414
|
+
const dedupeKey = updateKey ? stableHash(updateKey) : null;
|
|
415
|
+
if (dedupeKey && report.appliedUpdateKeys?.includes(dedupeKey)) return report;
|
|
416
|
+
|
|
417
|
+
const timestamp = nowIso();
|
|
418
|
+
const next: AnalysisReport = {
|
|
419
|
+
...report,
|
|
420
|
+
sections: report.sections.map((section) => ({ ...section, sources: [...section.sources] })),
|
|
421
|
+
sources: [...report.sources],
|
|
422
|
+
changes: [...report.changes],
|
|
423
|
+
appliedUpdateKeys: [...(report.appliedUpdateKeys ?? [])],
|
|
424
|
+
};
|
|
425
|
+
const section = next.sections.find((item) => item.id === sectionId);
|
|
426
|
+
if (!section) return report;
|
|
427
|
+
|
|
428
|
+
section.markdown = update.action === "replace" || !section.markdown.trim()
|
|
429
|
+
? markdown
|
|
430
|
+
: `${section.markdown.trim()}\n\n${markdown}`;
|
|
431
|
+
section.status = update.status ?? "draft";
|
|
432
|
+
section.updatedAt = timestamp;
|
|
433
|
+
const sources = normalizeSources(update.sources);
|
|
434
|
+
section.sources = sources.length > 0 ? sources : section.sources;
|
|
435
|
+
|
|
436
|
+
const invalidates = Array.isArray(update.invalidates) ? update.invalidates.map(normalizeSectionId).filter(Boolean) : [];
|
|
437
|
+
for (const invalidated of invalidates) {
|
|
438
|
+
const invalidatedSection = next.sections.find((item) => item.id === invalidated);
|
|
439
|
+
if (invalidatedSection && invalidatedSection.id !== section.id) {
|
|
440
|
+
invalidatedSection.status = "outdated";
|
|
441
|
+
invalidatedSection.updatedAt = timestamp;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
next.sources = [...next.sources, ...sources].filter((source, index, all) => {
|
|
446
|
+
const key = `${source.type}:${source.id ?? ""}:${source.path ?? ""}:${source.label}`;
|
|
447
|
+
return all.findIndex((candidate) => `${candidate.type}:${candidate.id ?? ""}:${candidate.path ?? ""}:${candidate.label}` === key) === index;
|
|
448
|
+
});
|
|
449
|
+
next.changes = [
|
|
450
|
+
{
|
|
451
|
+
id: `change-${Date.now()}`,
|
|
452
|
+
timestamp,
|
|
453
|
+
title: `Updated ${section.title}`,
|
|
454
|
+
detail: update.note || "Applied a structured analysis report update from the assistant.",
|
|
455
|
+
},
|
|
456
|
+
...next.changes,
|
|
457
|
+
].slice(0, 50);
|
|
458
|
+
if (dedupeKey) {
|
|
459
|
+
next.appliedUpdateKeys = [dedupeKey, ...(next.appliedUpdateKeys ?? [])].slice(0, 500);
|
|
460
|
+
}
|
|
461
|
+
return next;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function generateReportFromSession(input: {
|
|
465
|
+
report: AnalysisReport;
|
|
466
|
+
context: SessionContext;
|
|
467
|
+
sessionTitle?: string;
|
|
468
|
+
topic?: string;
|
|
469
|
+
}): AnalysisReport {
|
|
470
|
+
const report = {
|
|
471
|
+
...input.report,
|
|
472
|
+
title: input.report.title || input.sessionTitle || "Analysis Report",
|
|
473
|
+
sections: input.report.sections.map((section) => ({ ...section, sources: [...section.sources] })),
|
|
474
|
+
sources: [...input.report.sources],
|
|
475
|
+
changes: [...input.report.changes],
|
|
476
|
+
appliedUpdateKeys: [...(input.report.appliedUpdateKeys ?? [])],
|
|
477
|
+
};
|
|
478
|
+
const source: AnalysisReportSource = {
|
|
479
|
+
type: "session",
|
|
480
|
+
id: report.sessionId,
|
|
481
|
+
label: "Current conversation",
|
|
482
|
+
};
|
|
483
|
+
const hasBioContent = sessionHasBioAnalysisContent(input.context);
|
|
484
|
+
if (!hasBioContent) {
|
|
485
|
+
return hasReportSectionContent(report.sections)
|
|
486
|
+
? { ...report, markdown: renderReportMarkdown(report.title, report.sections) }
|
|
487
|
+
: {
|
|
488
|
+
...report,
|
|
489
|
+
sections: SECTION_DEFS.map((section) => makeEmptySection(section.id, section.title)),
|
|
490
|
+
sources: [],
|
|
491
|
+
changes: [],
|
|
492
|
+
markdown: "",
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const objective = firstAnalysisUserText(input.context) || firstUserText(input.context);
|
|
497
|
+
const files = extractOutputFiles(input.context);
|
|
498
|
+
const signals = collectSessionSignals(input.context);
|
|
499
|
+
const topic = input.topic ?? (objective ? cleanText(objective).slice(0, 80) : "");
|
|
500
|
+
const figuresMarkdown = representativeFigures(files);
|
|
501
|
+
const resultsMarkdown = combineMarkdown([
|
|
502
|
+
signals.results.length > 0 ? bullets(signals.results) : "",
|
|
503
|
+
figuresMarkdown,
|
|
504
|
+
]);
|
|
505
|
+
|
|
506
|
+
if (input.topic) {
|
|
507
|
+
let nextReport: AnalysisReport = report;
|
|
508
|
+
const addTopicUpdate = (section: string, markdown: string, sources: AnalysisReportSource[] = []) => {
|
|
509
|
+
const cleaned = markdown.trim();
|
|
510
|
+
if (!cleaned) return;
|
|
511
|
+
nextReport = applyReportUpdate(nextReport, {
|
|
512
|
+
topic,
|
|
513
|
+
section,
|
|
514
|
+
action: "append",
|
|
515
|
+
status: "draft",
|
|
516
|
+
markdown: cleaned,
|
|
517
|
+
sources,
|
|
518
|
+
note: `Added current-topic summary for ${topic}.`,
|
|
519
|
+
}, `${report.sessionId}:${topic}:${section}:${stableHash(cleaned)}`);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
addTopicUpdate("objective", objective ? `- ${objective}` : "", objective ? [source] : []);
|
|
523
|
+
addTopicUpdate("input_data", files.length > 0
|
|
524
|
+
? [
|
|
525
|
+
"Detected data or result paths mentioned in this topic:",
|
|
526
|
+
"",
|
|
527
|
+
outputTable(files.slice(0, 12)),
|
|
528
|
+
].join("\n")
|
|
529
|
+
: "", files.length > 0 ? [source] : []);
|
|
530
|
+
addTopicUpdate("methods", signals.methods.length > 0 ? bullets(signals.methods) : "", signals.methods.length > 0 ? [source] : []);
|
|
531
|
+
addTopicUpdate("quality_control", signals.qc.length > 0 ? bullets(signals.qc) : "", signals.qc.length > 0 ? [source] : []);
|
|
532
|
+
addTopicUpdate("results", resultsMarkdown, resultsMarkdown ? [source] : []);
|
|
533
|
+
addTopicUpdate("interpretation", signals.interpretation.length > 0 ? bullets(signals.interpretation) : "", signals.interpretation.length > 0 ? [source] : []);
|
|
534
|
+
addTopicUpdate("outputs", files.length > 0 ? outputTable(files) : "", files.length > 0 ? [source] : []);
|
|
535
|
+
addTopicUpdate("reproducibility", signals.reproducibility.length > 0 ? bullets(signals.reproducibility) : "", signals.reproducibility.length > 0 ? [source] : []);
|
|
536
|
+
return nextReport;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
updateSection(
|
|
540
|
+
report,
|
|
541
|
+
"objective",
|
|
542
|
+
objective ? withTopicPrefix(`- ${objective}`, topic) : "",
|
|
543
|
+
objective ? "draft" : "draft",
|
|
544
|
+
objective ? [source] : []
|
|
545
|
+
);
|
|
546
|
+
updateSection(
|
|
547
|
+
report,
|
|
548
|
+
"input_data",
|
|
549
|
+
files.length > 0
|
|
550
|
+
? withTopicPrefix([
|
|
551
|
+
"Detected data or result paths mentioned in this session:",
|
|
552
|
+
"",
|
|
553
|
+
outputTable(files.slice(0, 12)),
|
|
554
|
+
].join("\n"), topic)
|
|
555
|
+
: "",
|
|
556
|
+
files.length > 0 ? "draft" : "draft",
|
|
557
|
+
files.length > 0 ? [source] : []
|
|
558
|
+
);
|
|
559
|
+
updateSection(report, "methods", signals.methods.length > 0 ? withTopicPrefix(bullets(signals.methods), topic) : "", signals.methods.length > 0 ? "draft" : "draft", signals.methods.length > 0 ? [source] : []);
|
|
560
|
+
updateSection(report, "quality_control", signals.qc.length > 0 ? withTopicPrefix(bullets(signals.qc), topic) : "", signals.qc.length > 0 ? "draft" : "draft", signals.qc.length > 0 ? [source] : []);
|
|
561
|
+
updateSection(report, "results", resultsMarkdown ? withTopicPrefix(resultsMarkdown, topic) : "", resultsMarkdown ? "draft" : "draft", resultsMarkdown ? [source] : []);
|
|
562
|
+
updateSection(report, "interpretation", signals.interpretation.length > 0 ? withTopicPrefix(bullets(signals.interpretation), topic) : "", signals.interpretation.length > 0 ? "draft" : "draft", signals.interpretation.length > 0 ? [source] : []);
|
|
563
|
+
updateSection(report, "outputs", files.length > 0 ? withTopicPrefix(outputTable(files), topic) : "", files.length > 0 ? "draft" : "draft", files.length > 0 ? [source] : []);
|
|
564
|
+
updateSection(report, "reproducibility", signals.reproducibility.length > 0 ? withTopicPrefix(bullets(signals.reproducibility), topic) : "", signals.reproducibility.length > 0 ? "draft" : "draft", signals.reproducibility.length > 0 ? [source] : []);
|
|
565
|
+
|
|
566
|
+
if (hasReportSectionContent(report.sections)) {
|
|
567
|
+
report.sources = [source];
|
|
568
|
+
report.changes = [
|
|
569
|
+
{
|
|
570
|
+
id: `change-${Date.now()}`,
|
|
571
|
+
timestamp: nowIso(),
|
|
572
|
+
title: "Generated from conversation",
|
|
573
|
+
detail: "Refreshed the analysis report from the current session, keeping only analysis objectives, methods, results, interpretations, outputs, and reproducibility notes.",
|
|
574
|
+
},
|
|
575
|
+
...report.changes,
|
|
576
|
+
].slice(0, 50);
|
|
577
|
+
}
|
|
578
|
+
return report;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export function renderReportMarkdown(title: string, sections: AnalysisReportSection[]): string {
|
|
582
|
+
const contentSections = sections.filter((section) => normalizeEmptyMarkdown(section.markdown).length > 0);
|
|
583
|
+
if (contentSections.length === 0) return "";
|
|
584
|
+
|
|
585
|
+
const body = contentSections.map((section) => {
|
|
586
|
+
const status = section.status === "verified"
|
|
587
|
+
? "verified"
|
|
588
|
+
: section.status === "outdated"
|
|
589
|
+
? "outdated"
|
|
590
|
+
: section.status === "needs_review"
|
|
591
|
+
? "needs review"
|
|
592
|
+
: "draft";
|
|
593
|
+
const content = normalizeEmptyMarkdown(section.markdown);
|
|
594
|
+
return `## ${section.title}\n\n_Status: ${status}_\n\n${content}`;
|
|
595
|
+
});
|
|
596
|
+
return [`# ${title || "Analysis Report"}`, ...body].join("\n\n");
|
|
597
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { AnalysisReportUpdate } from "@/lib/report-store";
|
|
2
|
+
|
|
3
|
+
export interface ParsedReportUpdate {
|
|
4
|
+
update: AnalysisReportUpdate;
|
|
5
|
+
raw: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const REPORT_FENCE_RE = /```(?:analysis-report-update|report-update)\s*\n([\s\S]*?)```/gi;
|
|
9
|
+
|
|
10
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeStatus(value: unknown): AnalysisReportUpdate["status"] | undefined {
|
|
15
|
+
if (value === "draft" || value === "verified" || value === "outdated" || value === "needs_review") return value;
|
|
16
|
+
if (value === "needs review") return "needs_review";
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeAction(value: unknown): AnalysisReportUpdate["action"] | undefined {
|
|
21
|
+
return value === "replace" ? "replace" : value === "append" ? "append" : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function parseUpdate(rawJson: string): AnalysisReportUpdate | null {
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(rawJson) as unknown;
|
|
27
|
+
if (!isRecord(parsed)) return null;
|
|
28
|
+
return {
|
|
29
|
+
topic: typeof parsed.topic === "string" ? parsed.topic : undefined,
|
|
30
|
+
section: typeof parsed.section === "string" ? parsed.section : undefined,
|
|
31
|
+
action: normalizeAction(parsed.action),
|
|
32
|
+
status: normalizeStatus(parsed.status),
|
|
33
|
+
markdown: typeof parsed.markdown === "string" ? parsed.markdown : undefined,
|
|
34
|
+
sources: Array.isArray(parsed.sources) ? parsed.sources as AnalysisReportUpdate["sources"] : undefined,
|
|
35
|
+
invalidates: Array.isArray(parsed.invalidates)
|
|
36
|
+
? parsed.invalidates.filter((item): item is string => typeof item === "string")
|
|
37
|
+
: undefined,
|
|
38
|
+
note: typeof parsed.note === "string" ? parsed.note : undefined,
|
|
39
|
+
};
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parseReportUpdates(content: string): ParsedReportUpdate[] {
|
|
46
|
+
const updates: ParsedReportUpdate[] = [];
|
|
47
|
+
for (const match of content.matchAll(REPORT_FENCE_RE)) {
|
|
48
|
+
const raw = match[0];
|
|
49
|
+
const body = match[1]?.trim() ?? "";
|
|
50
|
+
const update = parseUpdate(body);
|
|
51
|
+
if (update) updates.push({ update, raw });
|
|
52
|
+
}
|
|
53
|
+
return updates;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function stripReportUpdateFences(content: string): string {
|
|
57
|
+
return content
|
|
58
|
+
.replace(REPORT_FENCE_RE, "")
|
|
59
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
60
|
+
.trim();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function hasReportUpdateFence(content: string): boolean {
|
|
64
|
+
REPORT_FENCE_RE.lastIndex = 0;
|
|
65
|
+
return REPORT_FENCE_RE.test(content);
|
|
66
|
+
}
|